Hi! The GDB folks expressed interest in handling column information in debug info, apparently clang emits it, but gcc does not.
I know we are late in the release cycle, so I'm not suggesting to turn this on by default, but the following patch at least allows users to request it through -gcolumn-info, so that GDB can be adjusted to consume it and later on (GCC 8 or 9) we could perhaps switch the default. This patch handles just emitting DW_AT_decl_column and DW_AT_call_column if requested (-gcolumn-info) and non-zero (i.e. the middle-end knows the columns). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-02-17 Jakub Jelinek <ja...@redhat.com> * common.opt (gno-column-info, gcolumn-info): New options. * dwarf2out.c (dwarf2_lineno_debug_hooks): Formatting fix. (check_die): Also test for multiple DW_AT_decl_column attributes. (add_src_coords_attributes, dwarf2out_imported_module_or_decl_1): Add DW_AT_decl_column if requested. (gen_subprogram_die): Compare and/or add also DW_AT_decl_column if requested. (gen_variable_die): Likewise. (add_call_src_coords_attributes): Add DW_AT_call_column if requested. * doc/invoke.texi (-gcolumn-info, -gno-column-info): Document. --- gcc/common.opt.jj 2017-02-01 16:41:45.000000000 +0100 +++ gcc/common.opt 2017-02-17 11:47:14.233098170 +0100 @@ -2805,6 +2805,14 @@ gcoff Common Driver JoinedOrMissing Negative(gdwarf) Generate debug information in COFF format. +gno-column-info +Common Driver RejectNegative Var(debug_column_info,0) Init(0) +Don't record DW_AT_decl_column and DW_AT_call_column in DWARF. + +gcolumn-info +Common Driver RejectNegative Var(debug_column_info,1) +Record DW_AT_decl_column and DW_AT_call_column in DWARF. + gdwarf Common Driver JoinedOrMissing Negative(gdwarf-) Generate debug information in default version of DWARF format. --- gcc/dwarf2out.c.jj 2017-02-09 23:01:46.000000000 +0100 +++ gcc/dwarf2out.c 2017-02-17 11:56:13.471834354 +0100 @@ -2732,7 +2732,7 @@ const struct gcc_debug_hooks dwarf2_line debug_nothing_int_int, /* begin_block */ debug_nothing_int_int, /* end_block */ debug_true_const_tree, /* ignore_block */ - dwarf2out_source_line, /* source_line */ + dwarf2out_source_line, /* source_line */ debug_nothing_int_charstar, /* begin_prologue */ debug_nothing_int_charstar, /* end_prologue */ debug_nothing_int_charstar, /* begin_epilogue */ @@ -6109,7 +6109,7 @@ check_die (dw_die_ref die) dw_attr_node *a; bool inline_found = false; int n_location = 0, n_low_pc = 0, n_high_pc = 0, n_artificial = 0; - int n_decl_line = 0, n_decl_file = 0; + int n_decl_line = 0, n_decl_column = 0, n_decl_file = 0; FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a) { switch (a->dw_attr) @@ -6130,6 +6130,9 @@ check_die (dw_die_ref die) case DW_AT_artificial: ++n_artificial; break; + case DW_AT_decl_column: + ++n_decl_column; + break; case DW_AT_decl_line: ++n_decl_line; break; @@ -6141,7 +6144,7 @@ check_die (dw_die_ref die) } } if (n_location > 1 || n_low_pc > 1 || n_high_pc > 1 || n_artificial > 1 - || n_decl_line > 1 || n_decl_file > 1) + || n_decl_column > 1 || n_decl_line > 1 || n_decl_file > 1) { fprintf (stderr, "Duplicate attributes in DIE:\n"); debug_dwarf_die (die); @@ -20190,6 +20193,8 @@ add_src_coords_attributes (dw_die_ref di s = expand_location (DECL_SOURCE_LOCATION (decl)); add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file)); add_AT_unsigned (die, DW_AT_decl_line, s.line); + if (debug_column_info && s.column) + add_AT_unsigned (die, DW_AT_decl_column, s.column); } /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */ @@ -21936,7 +21941,11 @@ gen_subprogram_die (tree decl, dw_die_re && (DECL_ARTIFICIAL (decl) || (get_AT_file (old_die, DW_AT_decl_file) == file_index && (get_AT_unsigned (old_die, DW_AT_decl_line) - == (unsigned) s.line)))) + == (unsigned) s.line) + && (!debug_column_info + || s.column == 0 + || (get_AT_unsigned (old_die, DW_AT_decl_column) + == (unsigned) s.column))))) { subr_die = old_die; @@ -21963,10 +21972,15 @@ gen_subprogram_die (tree decl, dw_die_re add_AT_file (subr_die, DW_AT_decl_file, file_index); if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line) add_AT_unsigned (subr_die, DW_AT_decl_line, s.line); + if (debug_column_info + && s.column + && (get_AT_unsigned (old_die, DW_AT_decl_column) + != (unsigned) s.column)) + add_AT_unsigned (subr_die, DW_AT_decl_column, s.column); /* If the prototype had an 'auto' or 'decltype(auto)' return type, emit the real type on the definition die. */ - if (is_cxx() && debug_info_level > DINFO_LEVEL_TERSE) + if (is_cxx () && debug_info_level > DINFO_LEVEL_TERSE) { dw_die_ref die = get_AT_ref (old_die, DW_AT_type); if (die == auto_die || die == decltype_auto_die) @@ -22838,6 +22852,12 @@ gen_variable_die (tree decl, tree origin if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line) add_AT_unsigned (var_die, DW_AT_decl_line, s.line); + if (debug_column_info + && s.column + && (get_AT_unsigned (old_die, DW_AT_decl_column) + != (unsigned) s.column)) + add_AT_unsigned (var_die, DW_AT_decl_column, s.column); + if (old_die->die_tag == DW_TAG_member) add_linkage_name (var_die, decl); } @@ -23011,6 +23031,8 @@ add_call_src_coords_attributes (tree stm { add_AT_file (die, DW_AT_call_file, lookup_filename (s.file)); add_AT_unsigned (die, DW_AT_call_line, s.line); + if (debug_column_info && s.column) + add_AT_unsigned (die, DW_AT_call_column, s.column); } } @@ -25547,6 +25569,8 @@ dwarf2out_imported_module_or_decl_1 (tre add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file)); add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line); + if (debug_column_info && xloc.column) + add_AT_unsigned (imported_die, DW_AT_decl_column, xloc.column); if (name) add_AT_string (imported_die, DW_AT_name, IDENTIFIER_POINTER (name)); @@ -27959,7 +27983,9 @@ move_linkage_attr (dw_die_ref die) { dw_attr_node *prev = &(*die->die_attr)[ix - 1]; - if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name) + if (prev->dw_attr == DW_AT_decl_line + || prev->dw_attr == DW_AT_decl_column + || prev->dw_attr == DW_AT_name) break; } --- gcc/doc/invoke.texi.jj 2017-02-17 11:31:38.000000000 +0100 +++ gcc/doc/invoke.texi 2017-02-17 12:10:46.805110128 +0100 @@ -338,6 +338,7 @@ Objective-C and Objective-C++ Dialects}. @gccoptlist{-g -g@var{level} -gcoff -gdwarf -gdwarf-@var{version} @gol -ggdb -grecord-gcc-switches -gno-record-gcc-switches @gol -gstabs -gstabs+ -gstrict-dwarf -gno-strict-dwarf @gol +-gcolumn-info -gno-column-info @gol -gvms -gxcoff -gxcoff+ -gz@r{[}=@var{type}@r{]} @gol -fdebug-prefix-map=@var{old}=@var{new} -fdebug-types-section @gol -feliminate-dwarf2-dups -fno-eliminate-unused-debug-types @gol @@ -6822,6 +6823,14 @@ DWARF extensions from later standard ver Allow using extensions of later DWARF standard version than selected with @option{-gdwarf-@var{version}}. +@item -gcolumn-info +@item -gno-column-info +@opindex gcolumn-info +@opindex gno-column-info +Emit location column information into DWARF debugging information, rather +than just file and line. +This option is disabled by default. + @item -gz@r{[}=@var{type}@r{]} @opindex gz Produce compressed debug sections in DWARF format, if that is supported. Jakub