1# Debugging libgccjit23Sometimes, libgccjit will crash and output an error like this:45```6during RTL pass: expand7libgccjit.so: error: in expmed_mode_index, at expmed.h:24980x7f0da2e61a35 expmed_mode_index9 ../../../gcc/gcc/expmed.h:249100x7f0da2e61aa4 expmed_op_cost_ptr11 ../../../gcc/gcc/expmed.h:271120x7f0da2e620dc sdiv_cost_ptr13 ../../../gcc/gcc/expmed.h:540140x7f0da2e62129 sdiv_cost15 ../../../gcc/gcc/expmed.h:558160x7f0da2e73c12 expand_divmod(int, tree_code, machine_mode, rtx_def*, rtx_def*, rtx_def*, int)17 ../../../gcc/gcc/expmed.c:4335180x7f0da2ea1423 expand_expr_real_2(separate_ops*, rtx_def*, machine_mode, expand_modifier)19 ../../../gcc/gcc/expr.c:9240200x7f0da2cd1a1e expand_gimple_stmt_121 ../../../gcc/gcc/cfgexpand.c:3796220x7f0da2cd1c30 expand_gimple_stmt23 ../../../gcc/gcc/cfgexpand.c:3857240x7f0da2cd90a9 expand_gimple_basic_block25 ../../../gcc/gcc/cfgexpand.c:5898260x7f0da2cdade8 execute27 ../../../gcc/gcc/cfgexpand.c:658228```2930To see the code which causes this error, call the following function:3132```c33gcc_jit_context_dump_to_file(ctxt, "/tmp/output.c", 1 /* update_locations */)34```3536This will create a C-like file and add the locations into the IR pointing to this C file.37Then, rerun the program and it will output the location in the second line:3839```40libgccjit.so: /tmp/something.c:61322:0: error: in expmed_mode_index, at expmed.h:24941```4243Or add a breakpoint to `add_error` in gdb and print the line number using:4445```46p loc->m_line47p loc->m_filename->m_buffer48```4950To print a debug representation of a tree:5152```c53debug_tree(expr);54```5556(defined in print-tree.h)5758To print a debug representation of a gimple struct:5960```c61debug_gimple_stmt(gimple_struct)62```6364To get the `rustc` command to run in `gdb`, add the `--verbose` flag to `cargo build`.6566To have the correct file paths in `gdb` instead of `/usr/src/debug/gcc/libstdc++-v3/libsupc++/eh_personality.cc`:6768Maybe by calling the following at the beginning of gdb:6970```71set substitute-path /usr/src/debug/gcc /path/to/gcc-repo/gcc72```7374FIXME(antoyo): but that's not what I remember I was doing.
Findings
✓ No findings reported for this file.