From 8cbdb9476441c3ef36921a9064af91b26c4a1fb8 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Fri, 24 Jun 2022 13:01:08 -0300 Subject: [PATCH 1/2] Add debug info fix --- gcc/dwarf2out.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- gcc/flags.h | 4 ++++ gcc/toplev.c | 5 +++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 03555d57..5e5e094e 100755 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -232,6 +232,10 @@ static unsigned reg_number (rtx); #define FDE_AFTER_SIZE_LABEL "LSFDE" #define FDE_END_LABEL "LEFDE" #define FDE_LENGTH_LABEL "LLFDE" +#define LINE_NUMBER_BEGIN_LABEL "LSLT" +#define LINE_NUMBER_END_LABEL "LELT" +#define LN_PROLOG_AS_LABEL "LASLTP" +#define LN_PROLOG_END_LABEL "LELTP" /* Definitions of defaults for various types of primitive assembly language output operations. These may be overridden from within the tm.h file, @@ -3697,6 +3701,14 @@ output_abbrev_section () fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP); } + + if (flag_legacy_debug_info) + { + /* We need to properly terminate the abbrev table for this + compilation unit, as per the standard, and not rely on + workarounds in e.g. gdb. */ + fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP); + } } /* Output location description stack opcode's operands (if any). */ @@ -4301,6 +4313,7 @@ output_aranges () static void output_line_info () { + char l1[20], l2[20], p1[20], p2[20]; char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; register unsigned opc; @@ -4313,22 +4326,44 @@ output_line_info () register unsigned long current_file; register unsigned long function; - ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ()); + ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0); + ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0); + ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0); + ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0); + + if (flag_legacy_debug_info) + ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ()); + else + ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1); + if (flag_debug_asm) fprintf (asm_out_file, "\t%s Length of Source Line Info.", ASM_COMMENT_START); fputc ('\n', asm_out_file); + + if (!flag_legacy_debug_info) + ASM_OUTPUT_LABEL(asm_out_file, l1); + ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); if (flag_debug_asm) fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); fputc ('\n', asm_out_file); - ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ()); + + if (flag_legacy_debug_info) + ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ()); + else + ASM_OUTPUT_DWARF_DELTA (asm_out_file, p2, p1); + if (flag_debug_asm) fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START); fputc ('\n', asm_out_file); + + if (!flag_legacy_debug_info) + ASM_OUTPUT_LABEL(asm_out_file, p1); + ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH); if (flag_debug_asm) fprintf (asm_out_file, "\t%s Minimum Instruction Length", @@ -4423,6 +4458,9 @@ output_line_info () ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); fputc ('\n', asm_out_file); + if (!flag_legacy_debug_info) + ASM_OUTPUT_LABEL (asm_out_file, p2); + /* Set the address register to the first location in the text section */ ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); if (flag_debug_asm) @@ -4738,6 +4776,10 @@ output_line_info () fputc ('\n', asm_out_file); } } + + if (!flag_legacy_debug_info) + /* Output the marker for the end of the line number info. */ + ASM_OUTPUT_LABEL (asm_out_file, l2); } /* Given a pointer to a BLOCK node return non-zero if (and only if) the node diff --git a/gcc/flags.h b/gcc/flags.h index 754096f7..cf2931ff 100755 --- a/gcc/flags.h +++ b/gcc/flags.h @@ -450,3 +450,7 @@ extern enum graph_dump_types graph_dump_format; /* Nonzero if ASM output should use hex instead of decimal. */ extern int flag_hex_asm; + +/* Nonzero if generated DWARF debug info should match (buggy) original + GCC 2.95.x behavior. */ +extern int flag_legacy_debug_info; diff --git a/gcc/toplev.c b/gcc/toplev.c index e80ed20c..b748a1a5 100755 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -585,6 +585,9 @@ int flag_instrument_function_entry_exit = 0; /* Use hex instead of decimal in ASM output. */ int flag_hex_asm = 0; +/* Use old (buggy) DWARF line info generator. */ +int flag_legacy_debug_info = 0; + typedef struct { char *string; @@ -724,6 +727,8 @@ lang_independent_options f_options[] = "Instrument function entry/exit with profiling calls"}, {"hex-asm", &flag_hex_asm, 1, "Use hex instead of decimal in assembly output"}, + {"legacy-debug-line-info", &flag_legacy_debug_info, 1, + "Generate old (buggy) DWARF line info"}, }; #define NUM_ELEM(a) (sizeof (a) / sizeof ((a)[0])) From b789eb6d9b9a90f419358a78370c0cbfd3cb9636 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Fri, 24 Jun 2022 13:03:44 -0300 Subject: [PATCH 2/2] Tweak fix --- gcc/toplev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/toplev.c b/gcc/toplev.c index b748a1a5..093dfbd7 100755 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -727,8 +727,8 @@ lang_independent_options f_options[] = "Instrument function entry/exit with profiling calls"}, {"hex-asm", &flag_hex_asm, 1, "Use hex instead of decimal in assembly output"}, - {"legacy-debug-line-info", &flag_legacy_debug_info, 1, - "Generate old (buggy) DWARF line info"}, + {"legacy-debug-info", &flag_legacy_debug_info, 1, + "Generate old (buggy) DWARF info"}, }; #define NUM_ELEM(a) (sizeof (a) / sizeof ((a)[0]))