diff options
author | Alan Modra <amodra@gmail.com> | 2021-09-17 09:21:21 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2021-09-18 08:20:11 +0930 |
commit | ef9768e37e34bec50aa8cbb0ce25708b06f09255 (patch) | |
tree | d614a1afd069ab15693dddfebcda02524b326290 /gas/dwarf2dbg.c | |
parent | 51298b330327a568358da069d9808f51c6cb1672 (diff) | |
download | gdb-ef9768e37e34bec50aa8cbb0ce25708b06f09255.zip gdb-ef9768e37e34bec50aa8cbb0ce25708b06f09255.tar.gz gdb-ef9768e37e34bec50aa8cbb0ce25708b06f09255.tar.bz2 |
PR28149 part 2, purge generated line info
Mixing compiler generated line info with gas generated line info is
generally just confusing. Also .loc directives with non-zero view
fields might reference a previous .loc. It becomes a little more
tricky to locate that previous .loc if there might be gas generated
line info present too. Mind you, we turn off gas generation of line
info on seeing compiler generated line info, so any reference back
won't hit gas generated line info. At least, if the view info is
sane. Unfortunately, gas needs to handle mangled source.
PR 28149
* dwarf2dbg.c (purge_generated_debug): New function.
(dwarf2_directive_filename): Call the above.
(out_debug_line): Don't segfault after purging.
* testsuite/gas/i386/dwarf2-line-4.d: Update expected output.
* testsuite/gas/i386/dwarf4-line-1.d: Likewise.
* testsuite/gas/i386/dwarf5-line-1.d: Likewise.
* testsuite/gas/i386/dwarf5-line-2.d: Likewise.
Diffstat (limited to 'gas/dwarf2dbg.c')
-rw-r--r-- | gas/dwarf2dbg.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c index c6303ba..1250fce 100644 --- a/gas/dwarf2dbg.c +++ b/gas/dwarf2dbg.c @@ -782,6 +782,32 @@ do_allocate_filenum (struct line_entry *e) while (e); } +/* Remove any generated line entries. These don't live comfortably + with compiler generated line info. */ + +static void +purge_generated_debug (void) +{ + struct line_seg *s; + + for (s = all_segs; s; s = s->next) + { + struct line_subseg *lss = s->head; + struct line_entry *e, *next; + + for (e = lss->head; e; e = next) + { + know (e->loc.filenum == -1u); + next = e->next; + free (e); + } + + lss->head = NULL; + lss->ptail = &lss->head; + lss->pmove_tail = &lss->head; + } +} + /* Allocate slot NUM in the .debug_line file table to FILENAME. If DIRNAME is not NULL or there is a directory component to FILENAME then this will be stored in the directory table, if not already present. @@ -1146,6 +1172,8 @@ dwarf2_directive_filename (void) /* A .file directive implies compiler generated debug information is being supplied. Turn off gas generated debug info. */ + if (debug_type == DEBUG_DWARF2) + purge_generated_debug (); debug_type = DEBUG_NONE; if (num != (unsigned int) num @@ -2414,7 +2442,7 @@ out_debug_line (segT line_seg) for (s = all_segs; s; s = s->next) /* Paranoia - this check should have already have been handled in dwarf2_gen_line_info_1(). */ - if (SEG_NORMAL (s->seg)) + if (s->head->head && SEG_NORMAL (s->seg)) process_entries (s->seg, s->head->head); if (flag_dwarf_sections) |