From patchwork Wed Jan 11 18:27:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Love X-Patchwork-Id: 62959 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 945AA3858C31 for ; Wed, 11 Jan 2023 18:28:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 945AA3858C31 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673461717; bh=uZMQcmZ9DvRduh6PYYnn81kfAraSdvvGCAeGgDxNXyk=; h=Subject:To:Cc:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=pI/p3tvrJkBcF1KAOr6C4Twf+2BpiwVBFuPtWwJ4Xn4+rj2hnBgcTIB4YUXKaPk8x Er3EHxGRyZAJ9VMf8DC1DGe3gmE9T+xyr0PWfH7ZwIah9xl95kDO3RxXaNDPUsX6QR l65InXz4KDVnsKobSxem0Scun6IGPARfu7QMOnlA= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 67976385840D for ; Wed, 11 Jan 2023 18:27:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 67976385840D Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30BIBXjc029675 for ; Wed, 11 Jan 2023 18:27:45 GMT Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3n20dwkj0t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 11 Jan 2023 18:27:45 +0000 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 30BHYpiL013176 for ; Wed, 11 Jan 2023 18:27:44 GMT Received: from smtprelay04.dal12v.mail.ibm.com ([9.208.130.102]) by ppma03wdc.us.ibm.com (PPS) with ESMTPS id 3n1k93mk1j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 11 Jan 2023 18:27:43 +0000 Received: from smtpav04.wdc07v.mail.ibm.com (smtpav04.wdc07v.mail.ibm.com [10.39.53.231]) by smtprelay04.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 30BIRht56619828 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Jan 2023 18:27:43 GMT Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D87F75805E; Wed, 11 Jan 2023 18:27:42 +0000 (GMT) Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 50CF858045; Wed, 11 Jan 2023 18:27:42 +0000 (GMT) Received: from li-e362e14c-2378-11b2-a85c-87d605f3c641.ibm.com (unknown [9.163.12.142]) by smtpav04.wdc07v.mail.ibm.com (Postfix) with ESMTP; Wed, 11 Jan 2023 18:27:42 +0000 (GMT) Message-ID: <3e3c9c40f07ab01c79fe10915e76ffa187c42ad9.camel@us.ibm.com> Subject: [PATCH 1/2] fix for gdb.reverse/finish-precsave.exp and gdb.reverse/finish-reverse.exp To: Ulrich Weigand , "will_schmidt@vnet.ibm.com" , gdb-patches@sourceware.org Cc: cel@us.ibm.com Date: Wed, 11 Jan 2023 10:27:41 -0800 In-Reply-To: <1d9b21914354bef6a290ac30673741e722e11757.camel@de.ibm.com> References: <8bce850fa1e03e798506dc170d9b57f52034a18a.camel@us.ibm.com> <86c5e9c47945894f21b1d8bf6089c730a9f0e1a5.camel@de.ibm.com> <5f9047b9582403561d7cce998cab9184167366a1.camel@de.ibm.com> <5b50668cbe882c57b8c0e9dcf5be0a253713c4c6.camel@us.ibm.com> <51c4bfc82ac72e475e10577dc60e4d75fa48767e.camel@de.ibm.com> <3ea97a8aa9cccb39299adde682f92055d1986ab3.camel@us.ibm.com> <53878e37c6e57de1d04d9c9960c5d0a74324ee6e.camel@us.ibm.com> <50474aa92ba82eff05cdc8f49001eae56be29670.camel@us.ibm.com> <89331c26795e3f7743e1e068dce43b3c2dd53008.camel@us.ibm.com> <071f24ecf9b3a2bbbe8fee7db77492eb55c5f3ff.camel@us.ibm.com> <1d9b21914354bef6a290ac30673741e722e11757.camel@de.ibm.com> X-Mailer: Evolution 3.28.5 (3.28.5-18.el8) X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: jrqR5KoDLCD5hZhD_6RXwL5oL625oZ2P X-Proofpoint-GUID: jrqR5KoDLCD5hZhD_6RXwL5oL625oZ2P X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-11_07,2023-01-11_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 mlxscore=0 spamscore=0 suspectscore=0 bulkscore=0 impostorscore=0 clxscore=1015 malwarescore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301110132 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Carl Love via Gdb-patches From: Carl Love Reply-To: Carl Love Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" GDB maintainers: This patch fixes the issues with the reverse-finish command on X86. The reverse-finish command now correctly stops at the first instruction in the source code line of the caller. It now only requires a single reverse-step or reverse-next instruction to get back to the previous source code line. It also adds a new testcase, gdb.reverse/finish-reverse-next.exp, and updates several existing testcases. Please let me know if you have any comments on the patch. Thanks. Carl -------------------------------------------------------------- X86: reverse-finish fix Currently on X86, when executing the finish command in reverse, gdb does a single step from the first instruction in the callee to get back to the caller. GDB stops on the last instruction in the source code line where the call was made. When stopped at the last instruction of the source code line, a reverse next or step command will stop at the first instruction of the same source code line thus requiring two step/next commands to reach the previous source code line. It should only require one step/next command to reach the previous source code line. By contrast, a reverse next or step command from the first line in a function stops at the first instruction in the source code line where the call was made. This patch fixes the reverse finish command so it will stop at the first instruction of the source line where the function call was made. The behavior on X86 for the reverse-finish command now matches doing a reverse-next from the beginning of the function. The proceed_to_finish flag in struct thread_control_state is no longer used. This patch removes the declaration, initialization and setting of the flag. This patch requires a number of regression tests to be updated. Test gdb.mi/mi-reverse.exp no longer needs to execute two steps to get to the previous line. The gdb output for tests gdb.reverse/until-precsave.exp and gdb.reverse/until-reverse.exp changed slightly. The expected result in tests gdb.reverse/amd64-ailcall-reverse.exp and gdb.reverse/singlejmp-reverse.exp are updated to the correct expected result. This patch adds a new test gdb.reverse/finish-reverse-next.exp to test the reverse-finish command when returning from the entry point and from the body of the function. The step_until proceedure in test gdb.reverse/step-indirect-call-thunk.exp was moved to lib/gdb.exp and renamed cmd_until. The patch has been tested on X86 and PowerPC to verify no additional regression failures occured. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29927 Reviewed-By: Bruno Larsen Tested-By: Bruno Larsen --- gdb/gdbthread.h | 4 - gdb/infcall.c | 3 - gdb/infcmd.c | 32 +++--- gdb/infrun.c | 41 +++---- gdb/testsuite/gdb.mi/mi-reverse.exp | 9 +- .../gdb.reverse/amd64-tailcall-reverse.exp | 5 +- .../gdb.reverse/finish-reverse-next.c | 48 ++++++++ .../gdb.reverse/finish-reverse-next.exp | 108 ++++++++++++++++++ gdb/testsuite/gdb.reverse/finish-reverse.exp | 5 + .../gdb.reverse/singlejmp-reverse.exp | 5 +- .../gdb.reverse/step-indirect-call-thunk.exp | 49 ++------ gdb/testsuite/gdb.reverse/until-precsave.exp | 2 +- gdb/testsuite/gdb.reverse/until-reverse.exp | 2 +- gdb/testsuite/lib/gdb.exp | 33 ++++++ 14 files changed, 240 insertions(+), 106 deletions(-) create mode 100644 gdb/testsuite/gdb.reverse/finish-reverse-next.c create mode 100644 gdb/testsuite/gdb.reverse/finish-reverse-next.exp diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index 11d69fceab0..e4edff2d621 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -150,10 +150,6 @@ struct thread_control_state the finished single step. */ int trap_expected = 0; - /* Nonzero if the thread is being proceeded for a "finish" command - or a similar situation when return value should be printed. */ - int proceed_to_finish = 0; - /* Nonzero if the thread is being proceeded for an inferior function call. */ int in_infcall = 0; diff --git a/gdb/infcall.c b/gdb/infcall.c index e09904f9a35..116605c43ef 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -625,9 +625,6 @@ run_inferior_call (std::unique_ptr sm, disable_watchpoints_before_interactive_call_start (); - /* We want to print return value, please... */ - call_thread->control.proceed_to_finish = 1; - try { /* Infcalls run synchronously, in the foreground. */ diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 0497ad05091..9c42efeae8d 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -1721,19 +1721,10 @@ finish_backward (struct finish_command_fsm *sm) sal = find_pc_line (func_addr, 0); - tp->control.proceed_to_finish = 1; - /* Special case: if we're sitting at the function entry point, - then all we need to do is take a reverse singlestep. We - don't need to set a breakpoint, and indeed it would do us - no good to do so. - - Note that this can only happen at frame #0, since there's - no way that a function up the stack can have a return address - that's equal to its entry point. */ + frame_info_ptr frame = get_selected_frame (nullptr); if (sal.pc != pc) { - frame_info_ptr frame = get_selected_frame (nullptr); struct gdbarch *gdbarch = get_frame_arch (frame); /* Set a step-resume at the function's entry point. Once that's @@ -1743,16 +1734,22 @@ finish_backward (struct finish_command_fsm *sm) sr_sal.pspace = get_frame_program_space (frame); insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id); - - proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); } else { - /* We're almost there -- we just need to back up by one more - single-step. */ - tp->control.step_range_start = tp->control.step_range_end = 1; - proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); + /* We are exactly at the function entry point. Note that this + can only happen at frame #0. + + When setting a step range, need to call set_step_info + to setup the current_line/symtab fields as well. */ + set_step_info (tp, frame, find_pc_line (pc, 0)); + + /* Return using a step range so we will keep stepping back + to the first instruction in the source code line. */ + tp->control.step_range_start = sal.pc; + tp->control.step_range_end = sal.pc; } + proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); } /* finish_forward -- helper function for finish_command. FRAME is the @@ -1778,9 +1775,6 @@ finish_forward (struct finish_command_fsm *sm, frame_info_ptr frame) set_longjmp_breakpoint (tp, frame_id); - /* We want to print return value, please... */ - tp->control.proceed_to_finish = 1; - proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); } diff --git a/gdb/infrun.c b/gdb/infrun.c index 181d961d80d..8ed538ea9ec 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -2748,8 +2748,6 @@ clear_proceed_status_thread (struct thread_info *tp) tp->control.stop_step = 0; - tp->control.proceed_to_finish = 0; - tp->control.stepping_command = 0; /* Discard any remaining commands or status from previous stop. */ @@ -6737,31 +6735,28 @@ process_event_stop_test (struct execution_control_state *ecs) case BPSTAT_WHAT_STEP_RESUME: infrun_debug_printf ("BPSTAT_WHAT_STEP_RESUME"); - delete_step_resume_breakpoint (ecs->event_thread); - if (ecs->event_thread->control.proceed_to_finish - && execution_direction == EXEC_REVERSE) + fill_in_stop_func (gdbarch, ecs); + + if (execution_direction == EXEC_REVERSE + && ecs->event_thread->stop_pc () == ecs->stop_func_start) { struct thread_info *tp = ecs->event_thread; + stop_pc_sal = find_pc_line (ecs->event_thread->stop_pc (), 0); - /* We are finishing a function in reverse, and just hit the - step-resume breakpoint at the start address of the - function, and we're almost there -- just need to back up - by one more single-step, which should take us back to the - function call. */ - tp->control.step_range_start = tp->control.step_range_end = 1; - keep_going (ecs); - return; - } - fill_in_stop_func (gdbarch, ecs); - if (ecs->event_thread->stop_pc () == ecs->stop_func_start - && execution_direction == EXEC_REVERSE) - { - /* We are stepping over a function call in reverse, and just - hit the step-resume breakpoint at the start address of - the function. Go back to single-stepping, which should - take us back to the function call. */ - ecs->event_thread->stepping_over_breakpoint = 1; + /* When setting a step range, need to call set_step_info + to setup the current_line/symtab fields as well. */ + set_step_info (tp, frame, stop_pc_sal); + + /* We are finishing a function in reverse or stepping over a function + call in reverse, and just hit the step-resume breakpoint at the + start address of the function, and we're almost there -- just need + to back up to the function call. + + Return using a step range so we will keep stepping back to the + first instruction in the source code line. */ + tp->control.step_range_start = ecs->stop_func_start; + tp->control.step_range_end = ecs->stop_func_start; keep_going (ecs); return; } diff --git a/gdb/testsuite/gdb.mi/mi-reverse.exp b/gdb/testsuite/gdb.mi/mi-reverse.exp index d631beb17c8..30635ab1754 100644 --- a/gdb/testsuite/gdb.mi/mi-reverse.exp +++ b/gdb/testsuite/gdb.mi/mi-reverse.exp @@ -97,15 +97,10 @@ proc test_controlled_execution_reverse {} { "basics.c" $line_main_callme_1 "" \ "reverse finish from callme" - # Test exec-reverse-next - # It takes two steps to get back to the previous line, - # as the first step moves us to the start of the current line, - # and the one after that moves back to the previous line. - - mi_execute_to "exec-next --reverse 2" \ + mi_execute_to "exec-next --reverse" \ "end-stepping-range" "main" "" \ "basics.c" $line_main_hello "" \ - "reverse next to get over the call to do_nothing" + "reverse next to get over the call to do_nothing" # Test exec-reverse-step diff --git a/gdb/testsuite/gdb.reverse/amd64-tailcall-reverse.exp b/gdb/testsuite/gdb.reverse/amd64-tailcall-reverse.exp index 52a87faabf7..9964b4f8e4b 100644 --- a/gdb/testsuite/gdb.reverse/amd64-tailcall-reverse.exp +++ b/gdb/testsuite/gdb.reverse/amd64-tailcall-reverse.exp @@ -44,6 +44,5 @@ if [supports_process_record] { gdb_test "next" {f \(\);} "next to f" gdb_test "next" {v = 3;} "next to v = 3" -# FAIL was: -# 29 g (); -gdb_test "reverse-next" {f \(\);} +# Reverse step back into f (). Puts us at call to g () in function f (). +gdb_test "reverse-next" {g \(\);} diff --git a/gdb/testsuite/gdb.reverse/finish-reverse-next.c b/gdb/testsuite/gdb.reverse/finish-reverse-next.c new file mode 100644 index 00000000000..42e41b5a2e0 --- /dev/null +++ b/gdb/testsuite/gdb.reverse/finish-reverse-next.c @@ -0,0 +1,48 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2012-2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* The reverse finish command should return from a function and stop on + the first instruction of the source line where the function call is made. + Specifically, the behavior should match doing a reverse next from the + first instruction in the function. GDB should only require one reverse + step or next statement to reach the previous source code line. + + This test verifies the fix for gdb bugzilla: + + https://sourceware.org/bugzilla/show_bug.cgi?id=29927 +*/ + +int +function1 (int a, int b) // FUNCTION1 +{ + int ret = 0; + + ret = a + b; + return ret; +} + +int +main(int argc, char* argv[]) +{ + int a, b; + + a = 1; + b = 5; + + function1 (a, b); // CALL FUNCTION + return 0; +} diff --git a/gdb/testsuite/gdb.reverse/finish-reverse-next.exp b/gdb/testsuite/gdb.reverse/finish-reverse-next.exp new file mode 100644 index 00000000000..7880de10ffc --- /dev/null +++ b/gdb/testsuite/gdb.reverse/finish-reverse-next.exp @@ -0,0 +1,108 @@ +# Copyright 2008-2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# This file is part of the GDB testsuite. It tests reverse stepping. +# Lots of code borrowed from "step-test.exp". + +# The reverse finish command should return from a function and stop on +# the first instruction of the source line where the function call is made. +# Specifically, the behavior should match doing a reverse next from the +# first instruction in the function. GDB should only take one reverse step +# or next statement to reach the previous source code line. + +# This testcase verifies the reverse-finish command stops at the first +# instruction in the source code line where the function was called. There +# are two scenarios that must be checked: +# 1) gdb is at the entry point instruction for the function +# 2) gdb is in the body of the function. + +# This test verifies the fix for gdb bugzilla: +# https://sourceware.org/bugzilla/show_bug.cgi?id=29927 + +if ![supports_reverse] { + return +} + +standard_testfile + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { + return -1 +} + +runto_main +set target_remote [gdb_is_target_remote] + +if [supports_process_record] { + # Activate process record/replay. + gdb_test_no_output "record" "turn on process record for test1" +} + + +### TEST 1: reverse finish from the entry point instruction in +### function1. + +# Set breakpoint at call to function1 in main. +set FUNCTION_test [gdb_get_line_number "CALL FUNCTION" $srcfile] +gdb_test "break $srcfile:$FUNCTION_test" "Breakpoint $decimal at .*" \ + "set breakpoint on function1 call to stepi into function" + +# Continue to break point at function1 call in main. +gdb_test "continue" "Breakpoint $decimal,.*function1 \\(a, b\\).*" \ + "stopped at function1 entry point instruction to stepi into function" + +# stepi until we see "{" indicating we entered function1 +cmd_until "stepi" "CALL FUNCTION" "{" "stepi into function1 call" + +delete_breakpoints + +gdb_test "reverse-finish" ".*function1 \\(a, b\\); // CALL FUNCTION.*" \ + "reverse-finish function1 " + +# 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" + +# Clear the recorded log. +gdb_test "record stop" "Process record is stopped.*" \ + "turn off process record for test1" +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_test "break $srcfile:$FUNCTION_test" "Breakpoint $decimal at .*" \ + "set breakpoint on function1 call to step into body of function" + +# Continue to break point at function1 call in main. +gdb_test "continue" "Breakpoint $decimal,.*function1 \\(a, b\\).*" \ + "stopped at function1 entry point instruction to step to body of function" + +delete_breakpoints + +# 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" + +# 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" diff --git a/gdb/testsuite/gdb.reverse/finish-reverse.exp b/gdb/testsuite/gdb.reverse/finish-reverse.exp index 01ba309420c..a05cb81892a 100644 --- a/gdb/testsuite/gdb.reverse/finish-reverse.exp +++ b/gdb/testsuite/gdb.reverse/finish-reverse.exp @@ -16,6 +16,11 @@ # This file is part of the GDB testsuite. It tests 'finish' with # reverse debugging. +# This test verifies the fix for gdb bugzilla: + +# https://sourceware.org/bugzilla/show_bug.cgi?id=29927 + + if ![supports_reverse] { return } diff --git a/gdb/testsuite/gdb.reverse/singlejmp-reverse.exp b/gdb/testsuite/gdb.reverse/singlejmp-reverse.exp index 1ca7c2ce559..eb03051625a 100644 --- a/gdb/testsuite/gdb.reverse/singlejmp-reverse.exp +++ b/gdb/testsuite/gdb.reverse/singlejmp-reverse.exp @@ -56,7 +56,4 @@ gdb_test "next" {v = 3;} "next to v = 3" # { gdb_test "reverse-step" {nodebug \(\);} -# FAIL was: -# No more reverse-execution history. -# { -gdb_test "reverse-next" {f \(\);} +gdb_test "reverse-next" {g \(\);} diff --git a/gdb/testsuite/gdb.reverse/step-indirect-call-thunk.exp b/gdb/testsuite/gdb.reverse/step-indirect-call-thunk.exp index ad637899e5b..1928cdda217 100644 --- a/gdb/testsuite/gdb.reverse/step-indirect-call-thunk.exp +++ b/gdb/testsuite/gdb.reverse/step-indirect-call-thunk.exp @@ -39,39 +39,6 @@ if { ![runto_main] } { return -1 } -# Do repeated stepping COMMANDs in order to reach TARGET from CURRENT -# -# COMMAND is a stepping command -# CURRENT is a string matching the current location -# TARGET is a string matching the target location -# TEST is the test name -# -# The function issues repeated COMMANDs as long as the location matches -# CURRENT up to a maximum of 100 steps. -# -# TEST passes if the resulting location matches TARGET and fails -# otherwise. -# -proc step_until { command current target test } { - global gdb_prompt - - set count 0 - gdb_test_multiple "$command" "$test" { - -re "$current.*$gdb_prompt $" { - incr count - if { $count < 100 } { - send_gdb "$command\n" - exp_continue - } else { - fail "$test" - } - } - -re "$target.*$gdb_prompt $" { - pass "$test" - } - } -} - gdb_test_no_output "record" gdb_test "next" ".*" "record trace" @@ -91,20 +58,20 @@ gdb_test "reverse-next" "apply\.2.*" \ "reverse-step through thunks and over inc" # We can use instruction stepping to step into thunks. -step_until "stepi" "apply\.2" "indirect_thunk" "stepi into call thunk" -step_until "stepi" "indirect_thunk" "inc" \ +cmd_until "stepi" "apply\.2" "indirect_thunk" "stepi into call thunk" +cmd_until "stepi" "indirect_thunk" "inc" \ "stepi out of call thunk into inc" set alphanum_re "\[a-zA-Z0-9\]" set pic_thunk_re "__$alphanum_re*\\.get_pc_thunk\\.$alphanum_re* \\(\\)" -step_until "stepi" "(inc|$pic_thunk_re)" "return_thunk" "stepi into return thunk" -step_until "stepi" "return_thunk" "apply" \ +cmd_until "stepi" "(inc|$pic_thunk_re)" "return_thunk" "stepi into return thunk" +cmd_until "stepi" "return_thunk" "apply" \ "stepi out of return thunk back into apply" -step_until "reverse-stepi" "apply" "return_thunk" \ +cmd_until "reverse-stepi" "apply" "return_thunk" \ "reverse-stepi into return thunk" -step_until "reverse-stepi" "return_thunk" "inc" \ +cmd_until "reverse-stepi" "return_thunk" "inc" \ "reverse-stepi out of return thunk into inc" -step_until "reverse-stepi" "(inc|$pic_thunk_re)" "indirect_thunk" \ +cmd_until "reverse-stepi" "(inc|$pic_thunk_re)" "indirect_thunk" \ "reverse-stepi into call thunk" -step_until "reverse-stepi" "indirect_thunk" "apply" \ +cmd_until "reverse-stepi" "indirect_thunk" "apply" \ "reverse-stepi out of call thunk into apply" diff --git a/gdb/testsuite/gdb.reverse/until-precsave.exp b/gdb/testsuite/gdb.reverse/until-precsave.exp index 0c2d7537cd6..777aec94ac1 100644 --- a/gdb/testsuite/gdb.reverse/until-precsave.exp +++ b/gdb/testsuite/gdb.reverse/until-precsave.exp @@ -142,7 +142,7 @@ gdb_test "advance marker2" \ # Finish out to main scope (backward) gdb_test "finish" \ - " in main .*$srcfile:$bp_location20.*" \ + "main .*$srcfile:$bp_location20.*" \ "reverse-finish from marker2" # Advance backward to last line of factorial (outer invocation) diff --git a/gdb/testsuite/gdb.reverse/until-reverse.exp b/gdb/testsuite/gdb.reverse/until-reverse.exp index 23fc881dbf2..3a05953329f 100644 --- a/gdb/testsuite/gdb.reverse/until-reverse.exp +++ b/gdb/testsuite/gdb.reverse/until-reverse.exp @@ -113,7 +113,7 @@ gdb_test "advance marker2" \ # Finish out to main scope (backward) gdb_test "finish" \ - " in main .*$srcfile:$bp_location20.*" \ + "main .*$srcfile:$bp_location20.*" \ "reverse-finish from marker2" # Advance backward to last line of factorial (outer invocation) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index c41d4698d66..25f42eb5510 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -9301,6 +9301,39 @@ proc gdb_step_until { regexp {test_name ""} {max_steps 10} } { } } +# Do repeated stepping COMMANDs in order to reach TARGET from CURRENT +# +# COMMAND is a stepping command +# CURRENT is a string matching the current location +# TARGET is a string matching the target location +# TEST is the test name +# +# The function issues repeated COMMANDs as long as the location matches +# CURRENT up to a maximum of 100 steps. +# +# TEST passes if the resulting location matches TARGET and fails +# otherwise. + +proc cmd_until { command current target test } { + global gdb_prompt + + set count 0 + gdb_test_multiple "$command" "$test" { + -re "$current.*$gdb_prompt $" { + incr count + if { $count < 100 } { + send_gdb "$command\n" + exp_continue + } else { + fail "$test" + } + } + -re "$target.*$gdb_prompt $" { + pass "$test" + } + } +} + # Check if the compiler emits epilogue information associated # with the closing brace or with the last statement line. # From patchwork Wed Jan 11 18:27:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Love X-Patchwork-Id: 62958 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A889A3857007 for ; Wed, 11 Jan 2023 18:28:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A889A3857007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673461697; bh=txwG527Ydfrm22UIiurUxRz6mNKdZLwkf7wiyivQOQE=; h=Subject:To:Cc:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Y56/g/1xh+t9s1RBNeD5bPvdRNcEQ1ZOLFmvkGBeB1UZgKS4+5vp/Fa4Irq2npstu TLkFe7FiW3DoHAsd1NW9OD+2lmcVqSIfrfsPesD1M6KK5qlQFPYWfPAcSHrpGHe0ar rmtU1XGCZsUNwFeO9UMBOwg1awf305nW6FE7iAeY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 496AE3858C66 for ; Wed, 11 Jan 2023 18:27:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 496AE3858C66 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30BIF1C8026856 for ; Wed, 11 Jan 2023 18:27:49 GMT Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3n227qr7xp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 11 Jan 2023 18:27:49 +0000 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 30BH1PsL019903 for ; Wed, 11 Jan 2023 18:27:48 GMT Received: from smtprelay04.dal12v.mail.ibm.com ([9.208.130.102]) by ppma02dal.us.ibm.com (PPS) with ESMTPS id 3n1k83wqm0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 11 Jan 2023 18:27:48 +0000 Received: from smtpav02.dal12v.mail.ibm.com (smtpav02.dal12v.mail.ibm.com [10.241.53.101]) by smtprelay04.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 30BIRlrt50725328 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Jan 2023 18:27:47 GMT Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 24C445805F; Wed, 11 Jan 2023 18:27:47 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B41B55805C; Wed, 11 Jan 2023 18:27:46 +0000 (GMT) Received: from li-e362e14c-2378-11b2-a85c-87d605f3c641.ibm.com (unknown [9.163.12.142]) by smtpav02.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 11 Jan 2023 18:27:46 +0000 (GMT) Message-ID: Subject: [PATCH 2/2] fix for gdb.reverse/finish-precsave.exp and gdb.reverse/finish-reverse.exp To: Ulrich Weigand , "will_schmidt@vnet.ibm.com" , gdb-patches@sourceware.org Cc: cel@us.ibm.com Date: Wed, 11 Jan 2023 10:27:46 -0800 In-Reply-To: <1d9b21914354bef6a290ac30673741e722e11757.camel@de.ibm.com> References: <8bce850fa1e03e798506dc170d9b57f52034a18a.camel@us.ibm.com> <86c5e9c47945894f21b1d8bf6089c730a9f0e1a5.camel@de.ibm.com> <5f9047b9582403561d7cce998cab9184167366a1.camel@de.ibm.com> <5b50668cbe882c57b8c0e9dcf5be0a253713c4c6.camel@us.ibm.com> <51c4bfc82ac72e475e10577dc60e4d75fa48767e.camel@de.ibm.com> <3ea97a8aa9cccb39299adde682f92055d1986ab3.camel@us.ibm.com> <53878e37c6e57de1d04d9c9960c5d0a74324ee6e.camel@us.ibm.com> <50474aa92ba82eff05cdc8f49001eae56be29670.camel@us.ibm.com> <89331c26795e3f7743e1e068dce43b3c2dd53008.camel@us.ibm.com> <071f24ecf9b3a2bbbe8fee7db77492eb55c5f3ff.camel@us.ibm.com> <1d9b21914354bef6a290ac30673741e722e11757.camel@de.ibm.com> X-Mailer: Evolution 3.28.5 (3.28.5-18.el8) X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 0Tt2E1IjnsarUh1N9cI1e1VnPaCWIJNP X-Proofpoint-ORIG-GUID: 0Tt2E1IjnsarUh1N9cI1e1VnPaCWIJNP X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-11_08,2023-01-11_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 impostorscore=0 lowpriorityscore=0 adultscore=0 mlxscore=0 spamscore=0 malwarescore=0 clxscore=1015 suspectscore=0 priorityscore=1501 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301110132 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Carl Love via Gdb-patches From: Carl Love Reply-To: Carl Love Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" GDB maintainers: This patch fixes the issues with the reverse-finish command on PowerPC. The reverse-finish command now correctly stops at the first instruction in the source code line of the caller. The patch adds tests for calling a function via the GEP to the new test gdb.reverse/finish-reverse-next.exp. Please let me know if you have any comments on the patch. Thanks. Carl -------------------------------------------------------------- PowerPC: fix for gdb.reverse/finish-precsave.exp and gdb.reverse/finish-reverse.exp 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 3 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. --- gdb/infcmd.c | 41 ++++--- gdb/infrun.c | 21 +++- .../gdb.reverse/finish-reverse-next.c | 41 ++++++- .../gdb.reverse/finish-reverse-next.exp | 107 +++++++++++++++--- 4 files changed, 175 insertions(+), 35 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 9c42efeae8d..8c30af448ce 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -1722,22 +1722,28 @@ finish_backward (struct finish_command_fsm *sm) sal = find_pc_line (func_addr, 0); frame_info_ptr frame = get_selected_frame (nullptr); + struct gdbarch *gdbarch = get_frame_arch (frame); + CORE_ADDR alt_entry_point = sal.pc; + CORE_ADDR entry_point = alt_entry_point; - if (sal.pc != pc) + if (gdbarch_skip_entrypoint_p (gdbarch)) { - struct gdbarch *gdbarch = get_frame_arch (frame); + /* Some architectures, like PowerPC use local and global entry + points. There is only one Entry Point (GEP = LEP) for other + architectures. The GEP is an alternate entry point that is used + setup the table of contents (TOC) in register r2 before execution + continues at the LEP. The LEP is the normal entry point. + The value of entry_point was initialized to the alternate entry + point (GEP). It will be adjusted if the normal entry point + (LEP) was used. */ + entry_point = gdbarch_skip_entrypoint (gdbarch, entry_point); - /* Set a step-resume at the function's entry point. Once that's - hit, we'll do one more step backwards. */ - symtab_and_line sr_sal; - sr_sal.pc = sal.pc; - sr_sal.pspace = get_frame_program_space (frame); - insert_step_resume_breakpoint_at_sal (gdbarch, - sr_sal, null_frame_id); } - else + + if (alt_entry_point <= pc && pc <= entry_point) { - /* We are exactly at the function entry point. Note that this + /* We are exactly at the function entry point, or between the entry + point on platforms that have two (like PowerPC). Note that this can only happen at frame #0. When setting a step range, need to call set_step_info @@ -1746,8 +1752,17 @@ finish_backward (struct finish_command_fsm *sm) /* Return using a step range so we will keep stepping back to the first instruction in the source code line. */ - tp->control.step_range_start = sal.pc; - tp->control.step_range_end = sal.pc; + tp->control.step_range_start = alt_entry_point; + tp->control.step_range_end = alt_entry_point; + } + else + { + symtab_and_line sr_sal; + /* Set a step-resume at the function's entry point. */ + sr_sal.pc = entry_point; + sr_sal.pspace = get_frame_program_space (frame); + insert_step_resume_breakpoint_at_sal (gdbarch, + sr_sal, null_frame_id); } proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); } diff --git a/gdb/infrun.c b/gdb/infrun.c index 8ed538ea9ec..89423556ec0 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -1868,6 +1868,7 @@ struct execution_control_state struct target_waitstatus ws; int stop_func_filled_in = 0; + CORE_ADDR stop_func_alt_start = 0; CORE_ADDR stop_func_start = 0; CORE_ADDR stop_func_end = 0; const char *stop_func_name = nullptr; @@ -4663,6 +4664,14 @@ fill_in_stop_func (struct gdbarch *gdbarch, &block); ecs->stop_func_name = gsi == nullptr ? nullptr : gsi->print_name (); + /* PowerPC functions have a Local Entry Point and a Global Entry + Point. There is only one Entry Point (GEP = LEP) for other + architectures. The GEP is an alternate entry point that is used + setup the table of contents (TOC) in register r2 before execution + continues at the LEP. Save the alternate entry point address for + use later. */ + ecs->stop_func_alt_start = ecs->stop_func_start; + /* The call to find_pc_partial_function, above, will set stop_func_start and stop_func_end to the start and end of the range containing the stop pc. If this range @@ -4679,6 +4688,9 @@ fill_in_stop_func (struct gdbarch *gdbarch, += gdbarch_deprecated_function_start_offset (gdbarch); if (gdbarch_skip_entrypoint_p (gdbarch)) + /* The PowerPC architecture uses two entry points. Stop at the + regular entry point (LEP on PowerPC) initially. Will setup a + breakpoint for the alternate entry point (GEP) later. */ ecs->stop_func_start = gdbarch_skip_entrypoint (gdbarch, ecs->stop_func_start); } @@ -6738,8 +6750,7 @@ process_event_stop_test (struct execution_control_state *ecs) delete_step_resume_breakpoint (ecs->event_thread); fill_in_stop_func (gdbarch, ecs); - if (execution_direction == EXEC_REVERSE - && ecs->event_thread->stop_pc () == ecs->stop_func_start) + if (execution_direction == EXEC_REVERSE) { struct thread_info *tp = ecs->event_thread; stop_pc_sal = find_pc_line (ecs->event_thread->stop_pc (), 0); @@ -6755,7 +6766,7 @@ process_event_stop_test (struct execution_control_state *ecs) Return using a step range so we will keep stepping back to the first instruction in the source code line. */ - tp->control.step_range_start = ecs->stop_func_start; + tp->control.step_range_start = ecs->stop_func_alt_start; tp->control.step_range_end = ecs->stop_func_start; keep_going (ecs); return; @@ -6892,8 +6903,10 @@ process_event_stop_test (struct execution_control_state *ecs) (unless it's the function entry point, in which case keep going back to the call point). */ CORE_ADDR stop_pc = ecs->event_thread->stop_pc (); + if (stop_pc == ecs->event_thread->control.step_range_start - && stop_pc != ecs->stop_func_start + && (stop_pc < ecs->stop_func_alt_start + || stop_pc > ecs->stop_func_start) && execution_direction == EXEC_REVERSE) end_stepping_range (ecs); else diff --git a/gdb/testsuite/gdb.reverse/finish-reverse-next.c b/gdb/testsuite/gdb.reverse/finish-reverse-next.c index 42e41b5a2e0..55f81d2bc01 100644 --- a/gdb/testsuite/gdb.reverse/finish-reverse-next.c +++ b/gdb/testsuite/gdb.reverse/finish-reverse-next.c @@ -1,4 +1,4 @@ -/* This testcase is part of GDB, the GNU debugger. +j/* This testcase is part of GDB, the GNU debugger. Copyright 2012-2022 Free Software Foundation, Inc. @@ -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 : + 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 7880de10ffc..fbc024b48b9 100644 --- a/gdb/testsuite/gdb.reverse/finish-reverse-next.exp +++ b/gdb/testsuite/gdb.reverse/finish-reverse-next.exp @@ -31,6 +31,18 @@ # 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. + if ![supports_reverse] { return } @@ -50,32 +62,32 @@ 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 FUNCTION_test [gdb_get_line_number "CALL FUNCTION" $srcfile] -gdb_test "break $srcfile:$FUNCTION_test" "Breakpoint $decimal at .*" \ - "set breakpoint on function1 call to stepi into function" +set LEP_test [gdb_get_line_number "CALL VIA LEP" $srcfile] +gdb_test "break $srcfile:$LEP_test" "Breakpoint $decimal at .*" \ + "set breakpoint on function1 LEP call to stepi into function" # Continue to break point at function1 call in main. gdb_test "continue" "Breakpoint $decimal,.*function1 \\(a, b\\).*" \ "stopped at function1 entry point instruction to stepi into function" # stepi until we see "{" indicating we entered function1 -cmd_until "stepi" "CALL FUNCTION" "{" "stepi into function1 call" +cmd_until "stepi" "CALL VIA LEP" "{" "stepi into function1 call" delete_breakpoints -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.*" \ @@ -83,26 +95,91 @@ gdb_test "record stop" "Process record is stopped.*" \ gdb_test_no_output "record" "turn on process record for test2" -### TEST 2: reverse finish from the body of function1. +### TEST 2: reverse finish from the body of function1 when called using the +### normal entry point (LEP). # Set breakpoint at call to function1 in main. -gdb_test "break $srcfile:$FUNCTION_test" "Breakpoint $decimal at .*" \ - "set breakpoint on function1 call to step into body of function" +gdb_test "break $srcfile:$LEP_test" "Breakpoint $decimal at .*" \ + "set breakpoint on function1 LEP call to step into body of function" # Continue to break point at function1 call in main. gdb_test "continue" "Breakpoint $decimal,.*function1 \\(a, b\\).*" \ - "stopped at function1 entry point instruction to step to body of function" + "stopped at function1 entry point instruction to step body of function" delete_breakpoints # 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 GEP_test [gdb_get_line_number "CALL VIA GEP" $srcfile] +gdb_test "break $srcfile:$GEP_test" "Breakpoint $decimal at .*" \ + "set breakpoint on function1 GEP call to stepi into function" + +# Continue to break point at funp call in main. +gdb_test "continue" "Breakpoint $decimal.*funp \\(a, b\\).*" \ + "stopped at funp entry point instruction" + +# stepi until we see "{" indicating we entered function. +cmd_until "stepi" "CALL VIA GEP" "{" "stepi into funp call" + +delete_breakpoints + +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_test "break $srcfile:$GEP_test" "Breakpoint $decimal at .*" \ + "set breakpoint on funp GEP call to step into body of function" + +# Continue to break point at funp call. +gdb_test "continue" "Breakpoint $decimal,.*funp \\(a, b\\).*" \ + "stopped at funp call" + +# Step into body of funp, called via GEP. +gdb_test "step" ".*int ret = 0;.*" "step test 2" + +delete_breakpoints + +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"