Thomas Koenig via Fortran <fort...@gcc.gnu.org> wrote:
Hello world, I have struggled with debugging the GENERIC generated by the Fortran front end because it is only possible to look at the code via -fdump-tree-original, but it is not possible to inspect the values; additionally, the D.3456 form makes it hard to read which variable is which. This patch adds a flag which gives all variables generated by Fortran a name and makes them visible to debuggers. As an example, compiler-generated variables now look like this (for a "Hello, world" program): { struct __st_parameter_dt dt_parm:0; dt_parm:0.common.filename = &"hello.f90"[1]{lb: 1 sz: 1}; dt_parm:0.common.line = 2; dt_parm:0.common.flags = 128; dt_parm:0.common.unit = 6; _gfortran_st_write (&dt_parm:0); _gfortran_transfer_character_write (&dt_parm:0, &"Hello, world"[1]{lb: 1 sz: 1}, 12); _gfortran_st_write_done (&dt_parm:0); } Note the colon in the variable name, which I chose because it is not in the user's namespace, and gdb does not choke on it.
If it’s part of a symbol used by the rest of the toolchain (assembler, linker debugger) then it’s also important to note that some OS/tool pairs might be more constrained than the one you’ve tested. In particular, some assemblers will not accept all characters in an identifier.
In order to inspect the variables, you usually have to step a bit through the generated assembly code, but you can then print the values, manipulate them etc (and sometimes also hit an internal error in gdb).
--- a/gcc/fortran/trans.c +++ b/gcc/fortran/trans.c @@ -73,6 +73,40 @@ gfc_advance_chain (tree t, int n) return t;
+ /* We want debug info for it. */ + DECL_IGNORED_P (t) = 0; + /* It should not be nameless. */ + DECL_NAMELESS (t) = 0;
tree @@ -80,6 +114,9 @@ gfc_create_var_np (tree type, const char *prefix) { tree t; + if (flag_debug_aux_vars) + return create_var_debug_raw (type, prefix); + t = create_tmp_var_raw (type, prefix);
You could take advantage of the understanding of assembler identifier rules built into create_var_debug_raw() .. perhaps (totally untested)…. if (flag_debug_aux_vars) prefix = prefix ? prefix : “gfc”; t = create_tmp_var_raw (type, prefix); if (flag_debug_aux_vars) { /* We want debug info for it. */ DECL_IGNORED_P (t) = false; /* It should not be nameless. */ DECL_NAMELESS (t) = false; } return t; … or doens’t this approach work for some reason? cheers Iain