aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbarch.c
diff options
context:
space:
mode:
authorMarkus Metzger <markus.t.metzger@intel.com>2018-02-14 14:30:57 +0100
committerMarkus Metzger <markus.t.metzger@intel.com>2018-04-13 10:44:47 +0200
commit1d509aa625f891e20b37b8cee4659771e87b1ba4 (patch)
treefe552af320ac898cabcfaa37c709e324b3c96b25 /gdb/gdbarch.c
parent7a2711e437c50041c0a83761a90ea5e6c9ad8b98 (diff)
downloadfsf-binutils-gdb-1d509aa625f891e20b37b8cee4659771e87b1ba4.zip
fsf-binutils-gdb-1d509aa625f891e20b37b8cee4659771e87b1ba4.tar.gz
fsf-binutils-gdb-1d509aa625f891e20b37b8cee4659771e87b1ba4.tar.bz2
infrun: step through indirect branch thunks
With version 7.3 GCC supports new options -mindirect-branch=<choice> -mfunction-return=<choice> The choices are: keep behaves as before thunk jumps through a thunk thunk-external jumps through an external thunk thunk-inline jumps through an inlined thunk For thunk and thunk-external, GDB would, on a call to the thunk, step into the thunk and then resume to its caller assuming that this is an undebuggable function. On a return thunk, GDB would stop inside the thunk. Make GDB step through such thunks instead. Before: Temporary breakpoint 1, main () at gdb.base/step-indirect-call-thunk.c:37 37 x = apply (inc, 41); (gdb) s apply (op=0x80483e6 <inc>, x=41) at gdb.base/step-indirect-call-thunk.c:29 29 return op (x); (gdb) 30 } After: Temporary breakpoint 1, main () at gdb.base/step-indirect-call-thunk.c:37 37 x = apply (inc, 41); (gdb) s apply (op=0x80483e6 <inc>, x=41) at gdb.base/step-indirect-call-thunk.c:29 29 return op (x); (gdb) inc (x=41) at gdb.base/step-indirect-call-thunk.c:23 23 return x + 1; This is independent of the step-mode. In order to step into the thunk, you would need to use stepi. When stepping over an indirect call thunk, GDB would first step through the thunk, then recognize that it stepped into a sub-routine and resume to the caller (of the thunk). Not sure whether this is worth optimizing. Thunk detection is implemented via gdbarch. I implemented the methods for IA. Other architectures may run into unexpected fails. The tests assume a fixed number of instruction steps to reach a thunk. This depends on the compiler as well as the architecture. They may need adjustments when we add support for more architectures. Or we can simply drop those tests that cover being able to step into thunks using instruction stepping. When using an older GCC, the tests will fail to build and will be reported as untested: Running .../gdb.base/step-indirect-call-thunk.exp ... gdb compile failed, \ gcc: error: unrecognized command line option '-mindirect-branch=thunk' gcc: error: unrecognized command line option '-mfunction-return=thunk' === gdb Summary === # of untested testcases 1 gdb/ * infrun.c (process_event_stop_test): Call gdbarch_in_indirect_branch_thunk. * gdbarch.sh (in_indirect_branch_thunk): New. * gdbarch.c: Regenerated. * gdbarch.h: Regenerated. * x86-tdep.h: New. * x86-tdep.c: New. * Makefile.in (ALL_TARGET_OBS): Add x86-tdep.o. (HFILES_NO_SRCDIR): Add x86-tdep.h. (ALLDEPFILES): Add x86-tdep.c. * arch-utils.h (default_in_indirect_branch_thunk): New. * arch-utils.c (default_in_indirect_branch_thunk): New. * i386-tdep: Include x86-tdep.h. (i386_in_indirect_branch_thunk): New. (i386_elf_init_abi): Set in_indirect_branch_thunk gdbarch function. * amd64-tdep: Include x86-tdep.h. (amd64_in_indirect_branch_thunk): New. (amd64_init_abi): Set in_indirect_branch_thunk gdbarch function. testsuite/ * gdb.base/step-indirect-call-thunk.exp: New. * gdb.base/step-indirect-call-thunk.c: New. * gdb.reverse/step-indirect-call-thunk.exp: New. * gdb.reverse/step-indirect-call-thunk.c: New.
Diffstat (limited to 'gdb/gdbarch.c')
-rw-r--r--gdb/gdbarch.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index ddafe25..1359c2f 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -266,6 +266,7 @@ struct gdbarch
gdbarch_skip_trampoline_code_ftype *skip_trampoline_code;
gdbarch_skip_solib_resolver_ftype *skip_solib_resolver;
gdbarch_in_solib_return_trampoline_ftype *in_solib_return_trampoline;
+ gdbarch_in_indirect_branch_thunk_ftype *in_indirect_branch_thunk;
gdbarch_stack_frame_destroyed_p_ftype *stack_frame_destroyed_p;
gdbarch_elf_make_msymbol_special_ftype *elf_make_msymbol_special;
gdbarch_coff_make_msymbol_special_ftype *coff_make_msymbol_special;
@@ -433,6 +434,7 @@ gdbarch_alloc (const struct gdbarch_info *info,
gdbarch->skip_trampoline_code = generic_skip_trampoline_code;
gdbarch->skip_solib_resolver = generic_skip_solib_resolver;
gdbarch->in_solib_return_trampoline = generic_in_solib_return_trampoline;
+ gdbarch->in_indirect_branch_thunk = default_in_indirect_branch_thunk;
gdbarch->stack_frame_destroyed_p = generic_stack_frame_destroyed_p;
gdbarch->coff_make_msymbol_special = default_coff_make_msymbol_special;
gdbarch->make_symbol_special = default_make_symbol_special;
@@ -627,6 +629,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of skip_trampoline_code, invalid_p == 0 */
/* Skip verify of skip_solib_resolver, invalid_p == 0 */
/* Skip verify of in_solib_return_trampoline, invalid_p == 0 */
+ /* Skip verify of in_indirect_branch_thunk, invalid_p == 0 */
/* Skip verify of stack_frame_destroyed_p, invalid_p == 0 */
/* Skip verify of elf_make_msymbol_special, has predicate. */
/* Skip verify of coff_make_msymbol_special, invalid_p == 0 */
@@ -1103,6 +1106,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
"gdbarch_dump: have_nonsteppable_watchpoint = %s\n",
plongest (gdbarch->have_nonsteppable_watchpoint));
fprintf_unfiltered (file,
+ "gdbarch_dump: in_indirect_branch_thunk = <%s>\n",
+ host_address_to_string (gdbarch->in_indirect_branch_thunk));
+ fprintf_unfiltered (file,
"gdbarch_dump: in_solib_return_trampoline = <%s>\n",
host_address_to_string (gdbarch->in_solib_return_trampoline));
fprintf_unfiltered (file,
@@ -3353,6 +3359,23 @@ set_gdbarch_in_solib_return_trampoline (struct gdbarch *gdbarch,
gdbarch->in_solib_return_trampoline = in_solib_return_trampoline;
}
+bool
+gdbarch_in_indirect_branch_thunk (struct gdbarch *gdbarch, CORE_ADDR pc)
+{
+ gdb_assert (gdbarch != NULL);
+ gdb_assert (gdbarch->in_indirect_branch_thunk != NULL);
+ if (gdbarch_debug >= 2)
+ fprintf_unfiltered (gdb_stdlog, "gdbarch_in_indirect_branch_thunk called\n");
+ return gdbarch->in_indirect_branch_thunk (gdbarch, pc);
+}
+
+void
+set_gdbarch_in_indirect_branch_thunk (struct gdbarch *gdbarch,
+ gdbarch_in_indirect_branch_thunk_ftype in_indirect_branch_thunk)
+{
+ gdbarch->in_indirect_branch_thunk = in_indirect_branch_thunk;
+}
+
int
gdbarch_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR addr)
{