diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9892990e5f..e2e02a67b2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -192,20 +192,25 @@ which tests have failed and then fix them by making more changes. Just use run with your updated code. Use `hub ci-status --verbose` to monitor their status. -## Flags +## Compiler flags, useful while debugging the compiler itself: V allows you to pass custom flags using `-d my_flag` that can then be checked at compile time (see the documentation about [compile-time if](https://github.com/vlang/v/blob/master/doc/docs.md#compile-time-if)). -There are numerous flags that can be passed when building the compiler -with `v self` or when creating a copy of the compiler, that will help -you when debugging. -Beware that the flags must be passed when building the compiler, -not the program, so do for example: `v -d time_parsing cmd/v` or -`v -d trace_checker self`. -Some flags can make the compiler very verbose, so it is recommended -to create a copy of the compiler rather than replacing it with `v self`. +Since the compiler is *also* an ordinary V program, there are numerous flags that can be +passed when building the compiler itself with `v self`, or when creating a copy of the +compiler, that will help you when debugging the compiler. + +Note: beware that the flags below must be passed, when building the compiler, *not the program*, +so do for example: +`./v -o w -d time_parsing cmd/v` +or +`./v -o w -d trace_checker self` +... then use `./w file.v`, instead of `./v file.v`, to compile your program. + +Note: some of the flags can make the compiler *very verbose*, so it is recommended to create +a copy of the compiler rather than replacing it with `v self`. | Flag | Usage | |-----------------------------------|---------------------------------------------------------------------------------------------------------------------| @@ -216,12 +221,21 @@ to create a copy of the compiler rather than replacing it with `v self`. | `print_vweb_template_expansions` | Prints vweb compiled HTML files | | `time_checking` | Prints the time spent checking files and other related information | | `time_parsing` | Prints the time spent parsing files and other related information | +| | | +| `trace_parser` | Prints details about parsed statements and expressions. Very verbose. Use it for panics in the parser. | +| `trace_ccoptions` | Prints options passed down to the C compiler | +| | | +| `trace_checker` | Prints details about the statements being checked. Very verbose. Use it for panics in the checker. | +| | | +| `trace_gen` | Prints all the strings written to the generated C file. Very verbose. | +| `trace_cgen_stmt` | Prints details about the statements that are being processed by cgen. | +| | Use it for panics in cgen, to see the closest input V source line, that caused the panic. | +| | Note: you need `v -no-parallel -d trace_cgen_stmt -o w cmd/v` to make sense of the output of that, | +| | otherwise by default cgen uses several threads, and the lines that are printed are out of order. | +| | | | `trace_autofree` | Prints details about how/when -autofree puts free() calls | | `trace_autostr` | Prints details about `.str()` method auto-generated by the compiler during C generation | -| `trace_ccoptions` | Prints options passed down to the C compiler | -| `trace_checker` | Prints details about the statements being checked | -| `trace_gen` | Prints strings written to the generated C file. Beware, this flag is very verbose | -| `trace_parser` | Prints details about parsed statements and expressions | +| | | | `trace_thirdparty_obj_files` | Prints details about built thirdparty obj files | | `trace_usecache` | Prints details when -usecache is used | | `trace_embed_file` | Prints details when $embed_file is used | diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 6383721ebf..db3eac6985 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -2006,6 +2006,14 @@ fn (mut g Gen) write_v_source_line_info(pos token.Pos) { } fn (mut g Gen) stmt(node ast.Stmt) { + $if trace_cgen_stmt ? { + ntype := typeof(node).replace('v.ast.', '') + if g.file == unsafe { nil } { + eprintln('cgen: | pos: ${node.pos.line_str():-39} | node: ${ntype} | ${node}') + } else { + eprintln('cgen: ${g.file.path:-30} | pos: ${node.pos.line_str():-39} | node: ${ntype} | ${node}') + } + } g.inside_call = false if !g.skip_stmt_pos { g.set_current_pos_as_last_stmt_pos()