diff options
author | Kevin Buettner <kevinb@redhat.com> | 2019-07-03 17:35:21 -0700 |
---|---|---|
committer | Kevin Buettner <kevinb@redhat.com> | 2019-07-27 13:28:56 -0700 |
commit | 2dc80cf8a5799120fd4e00199688f721e7de2a62 (patch) | |
tree | 072f408b268c8d838bcac8f82b37e1aa215758ed /gdb/disasm.c | |
parent | 567238c956c4e5530bd143bfae9393c7ae5524cd (diff) | |
download | gdb-2dc80cf8a5799120fd4e00199688f721e7de2a62.zip gdb-2dc80cf8a5799120fd4e00199688f721e7de2a62.tar.gz gdb-2dc80cf8a5799120fd4e00199688f721e7de2a62.tar.bz2 |
Restrict use of minsym names when printing addresses in disassembled code
build_address_symbolic contains some code which causes it to
prefer the minsym over the the function symbol in certain cases.
The cases where this occurs are the same as the "certain pathological
cases" that used to exist in find_frame_funname().
This commit largely disables that code; it will only prefer the
minsym when the address of minsym is identical to that of the address
under consideration AND the function address for the symbtab sym is
not the same as the address under consideration.
So, without this change, when using the dw2-ranges-func-lo-cold
executable from the gdb.dwarf2/dw2-ranges-func.exp test, GDB exhibits
the following behavior:
(gdb) x/5i foo_cold
0x40110d <foo+4294967277>: push %rbp
0x40110e <foo+4294967278>: mov %rsp,%rbp
0x401111 <foo+4294967281>: callq 0x401106 <baz>
0x401116 <foo+4294967286>: nop
0x401117 <foo+4294967287>: pop %rbp
On the other hand, still without this change, using the
dw2-ranges-func-hi-cold executable from the same test, GDB
does this instead:
(gdb) x/5i foo_cold
0x401128 <foo_cold>: push %rbp
0x401129 <foo_cold+1>: mov %rsp,%rbp
0x40112c <foo_cold+4>: callq 0x401134 <baz>
0x401131 <foo_cold+9>: nop
0x401132 <foo_cold+10>: pop %rbp
This is inconsistent behavior. When foo_cold is at a lower
address than the function's entry point, the symtab symbol (foo)
is displayed along with a large positive offset which would wrap
around the address space if the address space were only 32 bits wide.
(A later patch fixes this problem by displaying negative offsets.)
This commit makes the behavior uniform for both the "lo-cold" and
"hi-cold" cases:
lo-cold:
(gdb) x/5i foo_cold
0x40110d <foo_cold>: push %rbp
0x40110e <foo-18>: mov %rsp,%rbp
0x401111 <foo-15>: callq 0x401106 <baz>
0x401116 <foo-10>: nop
0x401117 <foo-9>: pop %rbp
hi-cold:
(gdb) x/5i foo_cold
0x401128 <foo_cold>: push %rbp
0x401129 <foo+35>: mov %rsp,%rbp
0x40112c <foo+38>: callq 0x401134 <baz>
0x401131 <foo+43>: nop
0x401132 <foo+44>: pop %rbp
In both cases, the symbol shown for the address at which foo_cold
resides is shown as <foo_cold>. Subsequent offsets are shown as
either negative or positive offsets from the entry pc for foo.
When disassembling a function, care must be taken to NOT display
<+0> as the offset for the second range. For this reason, I found
it necessary to add the "prefer_sym_over_minsym" parameter to
build_address_symbolic. The type of this flag is a bool; do_demangle
ought to be a bool also, so I made this change at the same time.
gdb/ChangeLog:
* valprint.h (build_address_symbolic): Add "prefer_sym_over_minsym"
parameter. Change type of "do_demangle" to bool.
* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn):
Pass suitable "prefer_sym_over_minsym" flag to
build_address_symbolic(). Don't output "+" for negative offsets.
* printcmd.c (print_address_symbolic): Update invocation of
build_address_symbolic to include a "prefer_sym_over_minsym"
flag.
(build_address_symbolic): Add "prefer_sym_over_minsym" parameter.
Restrict cases in which use of minimal symbol is preferred to that
of a found symbol. Update comments.
Diffstat (limited to 'gdb/disasm.c')
-rw-r--r-- | gdb/disasm.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/gdb/disasm.c b/gdb/disasm.c index e2b4fd639..0d4c973 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -237,16 +237,20 @@ gdb_pretty_print_disassembler::pretty_print_insn (struct ui_out *uiout, uiout->field_core_addr ("address", gdbarch, pc); std::string name, filename; - if (!build_address_symbolic (gdbarch, pc, 0, &name, &offset, &filename, - &line, &unmapped)) + bool omit_fname = ((flags & DISASSEMBLY_OMIT_FNAME) != 0); + if (!build_address_symbolic (gdbarch, pc, false, omit_fname, &name, + &offset, &filename, &line, &unmapped)) { /* We don't care now about line, filename and unmapped. But we might in the future. */ uiout->text (" <"); - if ((flags & DISASSEMBLY_OMIT_FNAME) == 0) + if (!omit_fname) uiout->field_string ("func-name", name.c_str (), ui_out_style_kind::FUNCTION); - uiout->text ("+"); + /* For negative offsets, avoid displaying them as +-N; the sign of + the offset takes the place of the "+" here. */ + if (offset >= 0) + uiout->text ("+"); uiout->field_signed ("offset", offset); uiout->text (">:\t"); } |