[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.
This commit is contained in:
parent
d1c8a76d05
commit
520596f2eb
4 changed files with 85 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue