File: debug.wiki

package info (click to toggle)
js-of-ocaml 5.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,020 kB
  • sloc: ml: 91,250; javascript: 57,289; ansic: 315; makefile: 271; lisp: 23; sh: 6; perl: 4
file content (27 lines) | stat: -rw-r--r-- 1,356 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
= How to debug an OCaml program compiled to JavaScript.

== Use the right compiler flags
=== OCaml flags
Make sure to use "-g" flags when compiling and linking ocaml bytecode.
Js_of_ocaml will attempt to preserve variable names.

=== Js_of_ocaml flags
  * [--pretty]    - format the generated JavaScript in a readable way and try to keep OCaml variable names.
  * [--no-inline]  - prevent function inlining.
  * [--debug-info] - annotate the JavaScript file with locations from the OCaml sources.
  * [--source-map] - enable source-map support

== Breakpoint
One can set breakpoints using developers tools (see https://developer.chrome.com/devtools/docs/javascript-debugging).
Alternatively, one can set breakpoints programmatically by calling {{{Js.debugger ()}}}. Note that
browsers will only stop at breakpoints when developers tools are in use.

== Source map
Source map is used to map the generated JavaScript code to original sources.
After compiling with sourcemap enabled, using developers tools, one can set breakpoints,
step through the code, and inspect variable directly in OCaml sources.

== About Chrome DevTools
Useful setting Chrome DevTools:
* Display variable values inline while debugging
* Resolve variable names (hidden DevTools Experiments, see http://islegend.com/development/how-to-enable-devtools-experiments-within-google-chrome)