binutils-gdb/gdb/testsuite/gdb.reverse
Markus Metzger 1d509aa625 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.
2018-04-13 10:44:47 +02:00
..
amd64-tailcall-reverse.S Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
amd64-tailcall-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
amd64-tailcall-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
break-precsave.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
break-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
break-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
consecutive-precsave.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
consecutive-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
consecutive-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
finish-precsave.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
finish-reverse-bkpt.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
finish-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
finish-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
fstatat-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
fstatat-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
getresuid-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
getresuid-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
i386-precsave.exp Make tests expect [ \t]+ pattern instead of \t for "info reg" command 2018-01-19 09:05:51 +03:00
i386-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
i386-reverse.exp Make tests expect [ \t]+ pattern instead of \t for "info reg" command 2018-01-19 09:05:51 +03:00
i386-sse-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
i386-sse-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
i387-env-reverse.c
i387-env-reverse.exp Make tests expect [ \t]+ pattern instead of \t for "info reg" command 2018-01-19 09:05:51 +03:00
i387-stack-reverse.c
i387-stack-reverse.exp Make tests expect [ \t]+ pattern instead of \t for "info reg" command 2018-01-19 09:05:51 +03:00
insn-reverse-aarch64.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
insn-reverse-arm.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
insn-reverse-x86.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
insn-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
insn-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
machinestate-precsave.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
machinestate.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
machinestate.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
ms1.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
next-reverse-bkpt-over-sr.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
pipe-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
pipe-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
readv-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
readv-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
recvmsg-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
recvmsg-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
rerun-prec.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
rerun-prec.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
s390-mvcle.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
s390-mvcle.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
shr.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
shr1.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
shr2.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
sigall-precsave.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
sigall-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
sigall-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
singlejmp-reverse-nodebug.S Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
singlejmp-reverse-nodebug.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
singlejmp-reverse.S Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
singlejmp-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
singlejmp-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
solib-precsave.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
solib-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
solib-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
step-indirect-call-thunk.c infrun: step through indirect branch thunks 2018-04-13 10:44:47 +02:00
step-indirect-call-thunk.exp infrun: step through indirect branch thunks 2018-04-13 10:44:47 +02:00
step-precsave.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
step-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
step-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
time-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
time-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
until-precsave.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
until-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
until-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
ur1.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
waitpid-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
waitpid-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
watch-precsave.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
watch-reverse.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
watch-reverse.exp Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00