From 52469d7673d716a4811c8ccec8cc8ef605992b31 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 12 Nov 2019 18:20:32 -0700 Subject: [PATCH] Reimplement tui_get_begin_asm_address tui_get_begin_asm_address looks for the inferior's "main" to display it. I think this is incorrect in two ways. First, it should probably instead use the user's most recent source context, if one has been set. Second, it uses a hard-coded list of "main" names, but gdb already has a better approach to handling this. This patch fixes both of these problems. gdb/ChangeLog 2019-12-20 Tom Tromey * tui/tui-disasm.c (tui_get_begin_asm_address): Use get_current_source_symtab_and_line, and main_name. Change-Id: I77dc13d49148e8dec5aa3eeb357ce3968a68d0bd --- gdb/ChangeLog | 5 +++++ gdb/tui/tui-disasm.c | 29 ++++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f5d667e78ce..e4715362c06 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2019-12-20 Tom Tromey + + * tui/tui-disasm.c (tui_get_begin_asm_address): Use + get_current_source_symtab_and_line, and main_name. + 2019-12-20 Tom Tromey * tui/tui.c (tui_show_source): Update. diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index 376343be661..d8f2d386892 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -258,25 +258,28 @@ tui_get_begin_asm_address (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p) { struct tui_locator_window *locator; struct gdbarch *gdbarch = get_current_arch (); - CORE_ADDR addr; + CORE_ADDR addr = 0; locator = tui_locator_win_info_ptr (); if (locator->addr == 0) { - struct bound_minimal_symbol main_symbol; + if (have_full_symbols () || have_partial_symbols ()) + { + set_default_source_symtab_and_line (); + struct symtab_and_line sal = get_current_source_symtab_and_line (); - /* Find address of the start of program. - Note: this should be language specific. */ - main_symbol = lookup_minimal_symbol ("main", NULL, NULL); - if (main_symbol.minsym == 0) - main_symbol = lookup_minimal_symbol ("MAIN", NULL, NULL); - if (main_symbol.minsym == 0) - main_symbol = lookup_minimal_symbol ("_start", NULL, NULL); - if (main_symbol.minsym) - addr = BMSYMBOL_VALUE_ADDRESS (main_symbol); - else - addr = 0; + if (sal.symtab != nullptr) + find_line_pc (sal.symtab, sal.line, &addr); + } + + if (addr == 0) + { + struct bound_minimal_symbol main_symbol + = lookup_minimal_symbol (main_name (), nullptr, nullptr); + if (main_symbol.minsym != nullptr) + addr = BMSYMBOL_VALUE_ADDRESS (main_symbol); + } } else /* The target is executing. */ {