diff options
author | Tom de Vries <tdevries@suse.de> | 2020-10-17 00:10:31 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2020-10-17 00:10:31 +0200 |
commit | 520596f2eb7430dca76d887dc6c39698654af728 (patch) | |
tree | e3e7b3f484c9331a722f76bf43ba14b70f47236a /gdb/source.c | |
parent | d1c8a76d05e3224449cb3849f42e26db6b0eabfe (diff) | |
download | gdb-520596f2eb7430dca76d887dc6c39698654af728.zip gdb-520596f2eb7430dca76d887dc6c39698654af728.tar.gz gdb-520596f2eb7430dca76d887dc6c39698654af728.tar.bz2 |
[gdb/symtab] Handle setting line bp without debug line info
When setting a breakpoint on a line in an executable without debug line info,
we run into an abort.
The problem occurs when calling set_default_source_symtab_and_line, which
calls select_source_symtab (0), which is where we try to find the line number
for main:
...
/* Make the default place to list be the function `main'
if one exists. */
block_symbol bsym = lookup_symbol (main_name (), 0, VAR_DOMAIN, 0);
if (bsym.symbol != nullptr && SYMBOL_CLASS (bsym.symbol) == LOC_BLOCK)
{
symtab_and_line sal = find_function_start_sal (bsym.symbol, true);
loc->set (sal.symtab, std::max (sal.line - (lines_to_list - 1), 1));
return;
}
...
However, due to the missing debug line info, find_function_start_sal returns a
sal with sal.symtab == 0:
...
(gdb) p /x sal
$2 = {pspace = 0x1a4a7f0, symtab = 0x0, symbol = 0x1d9e480, section = 0x1d5b398,
msymbol = 0x0, line = 0x0, pc = 0x4004ab, end = 0x0, explicit_pc = 0x0,
explicit_line = 0x0, is_stmt = 0x0, prob = 0x0, objfile = 0x0}
...
which eventually causes an segfault in create_sals_line_offset because
self->default_symtab->filename is accessed while self->default_symtab == NULL.
Fix this by handling sal.symtab == NULL in select_source_symtab.
Tested on x86_64-linux.
gdb/ChangeLog:
2020-10-17 Tom de Vries <tdevries@suse.de>
PR symtab/26317
* source.c (select_source_symtab): Handling sal.symtab == NULL for
symbol main.
gdb/testsuite/ChangeLog:
2020-10-17 Tom de Vries <tdevries@suse.de>
PR symtab/26317
* gdb.dwarf2/dw2-main-no-line-number.exp: New file.
Diffstat (limited to 'gdb/source.c')
-rw-r--r-- | gdb/source.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/gdb/source.c b/gdb/source.c index a73a31f..779efa4 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -306,7 +306,12 @@ select_source_symtab (struct symtab *s) if (bsym.symbol != nullptr && SYMBOL_CLASS (bsym.symbol) == LOC_BLOCK) { symtab_and_line sal = find_function_start_sal (bsym.symbol, true); - loc->set (sal.symtab, std::max (sal.line - (lines_to_list - 1), 1)); + if (sal.symtab == NULL) + /* We couldn't find the location of `main', possibly due to missing + line number info, fall back to line 1 in the corresponding file. */ + loc->set (symbol_symtab (bsym.symbol), 1); + else + loc->set (sal.symtab, std::max (sal.line - (lines_to_list - 1), 1)); return; } |