diff options
author | Carl Love <cel@us.ibm.com> | 2023-01-13 17:59:33 -0500 |
---|---|---|
committer | Carl Love <cel@us.ibm.com> | 2023-01-17 11:39:42 -0500 |
commit | 92e07580db6a5572573d5177ca23933064158f89 (patch) | |
tree | 3b6e814c5360a226f3f57d0a0f4fa23f69f0b197 /gdb/testsuite/gdb.reverse | |
parent | b22548ddb30bfb167708e82d3bb932461c1b703a (diff) | |
download | gdb-92e07580db6a5572573d5177ca23933064158f89.zip gdb-92e07580db6a5572573d5177ca23933064158f89.tar.gz gdb-92e07580db6a5572573d5177ca23933064158f89.tar.bz2 |
PowerPC: fix for gdb.reverse/finish-precsave.exp and gdb.reverse/finish-reverse.exp
PR record/29927 - reverse-finish requires two reverse next instructions to
reach previous source line
PowerPC uses two entry points called the local entry point (LEP) and the
global entry point (GEP). Normally the LEP is used when calling a
function. However, if the table of contents (TOC) value in register 2 is
not valid the GEP is called to setup the TOC before execution continues at
the LEP. When executing in reverse, the function finish_backward sets the
break point at the alternate entry point (GEP). However if the forward
execution enters via the normal entry point (LEP), the reverse execution
never sees the break point at the GEP of the function. Reverse execution
continues until the next break point is encountered or the end of the
recorded log is reached causing gdb to stop at the wrong place.
This patch adds a new address to struct execution_control_state to hold the
address of the alternate function start address, known as the GEP on
PowerPC. The finish_backwards function is updated. If the stopping point
is between the two entry points (the LEP and GEP on PowerPC), the stepping
range is set to execute back to the alternate entry point (GEP on PowerPC).
Otherwise, a breakpoint is inserted at the normal entry point (LEP on
PowerPC).
Function process_event_stop_test checks uses a stepping range to stop
execution in the caller at the first instruction of the source code line.
Note, on systems that only support one entry point, the address of the two
entry points are the same.
Test finish-reverse-next.exp is updated to include tests for the
reverse-finish command when the function is entered via the normal entry
point (i.e. the LEP) and the alternate entry point (i.e. the GEP).
The patch has been tested on X86 and PowerPC with no regressions.
Diffstat (limited to 'gdb/testsuite/gdb.reverse')
-rw-r--r-- | gdb/testsuite/gdb.reverse/finish-reverse-next.c | 39 | ||||
-rw-r--r-- | gdb/testsuite/gdb.reverse/finish-reverse-next.exp | 96 |
2 files changed, 120 insertions, 15 deletions
diff --git a/gdb/testsuite/gdb.reverse/finish-reverse-next.c b/gdb/testsuite/gdb.reverse/finish-reverse-next.c index f90ecbb..0347906 100644 --- a/gdb/testsuite/gdb.reverse/finish-reverse-next.c +++ b/gdb/testsuite/gdb.reverse/finish-reverse-next.c @@ -24,11 +24,37 @@ This test verifies the fix for gdb bugzilla: https://sourceware.org/bugzilla/show_bug.cgi?id=29927 -*/ + + PowerPC supports two entry points to a function. The normal entry point + is called the local entry point (LEP). The alternat entry point is called + the global entry point (GEP). The GEP is only used if the table of + contents (TOC) value stored in register r2 needs to be setup prior to + execution starting at the LEP. A function call via a function pointer + will entry via the GEP. A normal function call will enter via the LEP. + + This test has been expanded to include tests to verify the reverse-finish + command works properly if the function is called via the GEP. The original + test only verified the reverse-finish command for a normal call that used + the LEP. */ int function1 (int a, int b) // FUNCTION1 { + /* The assembly code for this function when compiled for PowerPC is as + follows: + + 0000000010000758 <function1>: + 10000758: 02 10 40 3c lis r2,4098 <- GEP + 1000075c: 00 7f 42 38 addi r2,r2,32512 + 10000760: a6 02 08 7c mflr r0 <- LEP + 10000764: 10 00 01 f8 std r0,16(r1) + .... + + When the function is called on PowerPC with function1 (a, b) the call + enters at the Local Entry Point (LEP). When the function is called via + a function pointer, the Global Entry Point (GEP) for function1 is used. + The GEP sets up register 2 before reaching the LEP. + */ int ret = 0; ret = a + b; @@ -39,10 +65,19 @@ int main(int argc, char* argv[]) { int a, b; + int (*funp) (int, int) = &function1; + + /* Call function via Local Entry Point (LEP). */ a = 1; b = 5; - function1 (a, b); // CALL FUNCTION + function1 (a, b); // CALL VIA LEP + + /* Call function via Global Entry Point (GEP). */ + a = 10; + b = 50; + + funp (a, b); // CALL VIA GEP return 0; } diff --git a/gdb/testsuite/gdb.reverse/finish-reverse-next.exp b/gdb/testsuite/gdb.reverse/finish-reverse-next.exp index 63305c1..a9c895d 100644 --- a/gdb/testsuite/gdb.reverse/finish-reverse-next.exp +++ b/gdb/testsuite/gdb.reverse/finish-reverse-next.exp @@ -31,6 +31,16 @@ # This test verifies the fix for gdb bugzilla: # https://sourceware.org/bugzilla/show_bug.cgi?id=29927 +# PowerPC supports two entry points to a function. The normal entry point +# is called the local entry point (LEP). The alternat entry point is called +# the global entry point (GEP). A function call via a function pointer +# will entry via the GEP. A normal function call will enter via the LEP. +# +# This test has been expanded to include tests to verify the reverse-finish +# command works properly if the function is called via the GEP. The original +# test only verified the reverse-finish command for a normal call that used +# the LEP. + if ![supports_reverse] { return } @@ -50,30 +60,30 @@ if [supports_process_record] { } -### TEST 1: reverse finish from the entry point instruction in -### function1. +### TEST 1: reverse finish from the entry point instruction (LEP) in +### function1 when called using the normal entry point (LEP). # Set breakpoint at call to function1 in main. -set bp_FUNCTION [gdb_get_line_number "CALL FUNCTION" $srcfile] -gdb_breakpoint $srcfile:$bp_FUNCTION temporary +set bp_LEP_test [gdb_get_line_number "CALL VIA LEP" $srcfile] +gdb_breakpoint $srcfile:$bp_LEP_test temporary # Continue to break point at function1 call in main. gdb_continue_to_breakpoint \ "stopped at function1 entry point instruction to stepi into function" \ - ".*$srcfile:$bp_FUNCTION\r\n.*" + ".*$srcfile:$bp_LEP_test\r\n.*" # stepi until we see "{" indicating we entered function1 -repeat_cmd_until "stepi" "CALL FUNCTION" "{" "stepi into function1 call" +repeat_cmd_until "stepi" "CALL VIA LEP" "{" "stepi into function1 call" -gdb_test "reverse-finish" ".*function1 \\(a, b\\); // CALL FUNCTION.*" \ - "reverse-finish function1 " +gdb_test "reverse-finish" ".*function1 \\(a, b\\); // CALL VIA LEP.*" \ + "reverse-finish function1 LEP call from LEP " # Check to make sure we stopped at the first instruction in the source code # line. It should only take one reverse next command to get to the previous # source line. If GDB stops at the last instruction in the source code line # it will take two reverse next instructions to get to the previous source # line. -gdb_test "reverse-next" ".*b = 5;.*" "reverse next at b = 5, call from function" +gdb_test "reverse-next" ".*b = 5;.*" "reverse next at b = 5, call from LEP" # Clear the recorded log. gdb_test "record stop" "Process record is stopped.*" \ @@ -84,21 +94,81 @@ gdb_test_no_output "record" "turn on process record for test2" ### TEST 2: reverse finish from the body of function1. # Set breakpoint at call to function1 in main. -gdb_breakpoint $srcfile:$bp_FUNCTION temporary +gdb_breakpoint $srcfile:$bp_LEP_test temporary # Continue to break point at function1 call in main. gdb_continue_to_breakpoint \ "at function1 entry point instruction to step to body of function" \ - ".*$srcfile:$bp_FUNCTION\r\n.*" + ".*$srcfile:$bp_LEP_test\r\n.*" # do a step instruction to get to the body of the function gdb_test "step" ".*int ret = 0;.*" "step test 1" -gdb_test "reverse-finish" ".*function1 \\(a, b\\); // CALL FUNCTION.*" \ - "reverse-finish function1 call from function body" +gdb_test "reverse-finish" ".*function1 \\(a, b\\); // CALL VIA LEP.*" \ + "reverse-finish function1 LEP call from function body" # Check to make sure we stopped at the first instruction in the source code # line. It should only take one reverse next command to get to the previous # source line. gdb_test "reverse-next" ".*b = 5;.*" \ "reverse next at b = 5, from function body" + +# Turn off record to clear logs and turn on again +gdb_test "record stop" "Process record is stopped.*" \ + "turn off process record for test2" +gdb_test_no_output "record" "turn on process record for test3" + + +### TEST 3: reverse finish from the alternate entry point instruction (GEP) in +### function1 when called using the alternate entry point (GEP). + +# Set breakpoint at call to funp in main. +set bp_GEP_test [gdb_get_line_number "CALL VIA GEP" $srcfile] +gdb_breakpoint $srcfile:$bp_GEP_test temporary + +# Continue to break point at funp call in main. +gdb_continue_to_breakpoint \ + "stopped at function1 entry point instruction to stepi into funp" \ + ".*$srcfile:$bp_GEP_test\r\n.*" + +# stepi until we see "{" indicating we entered function. +repeat_cmd_until "stepi" "CALL VIA GEP" "{" "stepi into funp call" + +gdb_test "reverse-finish" ".*funp \\(a, b\\);.*" \ + "function1 GEP call call from GEP" + +# Check to make sure we stopped at the first instruction in the source code +# line. It should only take one reverse next command to get to the previous +# source line. If GDB stops at the last instruction in the source code line +# it will take two reverse next instructions to get to the previous source +# line. +gdb_test "reverse-next" ".*b = 50;.*" "reverse next at b = 50, call from GEP" + +# Turn off record to clear logs and turn on again +gdb_test "record stop" "Process record is stopped.*" \ + "turn off process record for test3" +gdb_test_no_output "record" "turn on process record for test4" + + +### TEST 4: reverse finish from the body of function 1 when calling using the +### alternate entrypoint (GEP). +gdb_breakpoint $srcfile:$bp_GEP_test temporary + +# Continue to break point at funp call. +gdb_continue_to_breakpoint \ + "at function1 entry point instruction to step to body of funp call" \ + ".*$srcfile:$bp_GEP_test\r\n.*" + +# Step into body of funp, called via GEP. +gdb_test "step" ".*int ret = 0;.*" "step test 2" + +gdb_test "reverse-finish" ".*funp \\(a, b\\);.*" \ + "reverse-finish function1 GEP call, from function body " + +# Check to make sure we stopped at the first instruction in the source code +# line. It should only take one reverse next command to get to the previous +# source line. If GDB stops at the last instruction in the source code line +# it will take two reverse next instructions to get to the previous source +# line. +gdb_test "reverse-next" ".*b = 50;.*" \ + "reverse next at b = 50 from function body" |