public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Bruno Larsen <blarsen@redhat.com>,
	Andrew Burgess <aburgess@redhat.com>,
	Luis Machado <luis.machado@arm.com>
Subject: Re: [PATCH 1/4] [gdb/testsuite] Simplify gdb.base/unwind-on-each-insn.exp
Date: Mon, 23 Jan 2023 10:36:43 +0100	[thread overview]
Message-ID: <2029a6f2-5c42-3122-a0da-75b961d78cac@suse.de> (raw)
In-Reply-To: <20230119104618.15503-2-tdevries@suse.de>

[-- Attachment #1: Type: text/plain, Size: 890 bytes --]

On 1/19/23 11:46, Tom de Vries via Gdb-patches wrote:
> In test-case gdb.base/unwind-on-each-insn.exp, we try to determine the last
> insn in function foo.
> 
> This in it self is fragile, as demonstrated by commit 91836f41e20 ("Powerpc
> fix for gdb.base/unwind-on-each-insn.exp").
> 
> But the purpose of finding the last insn is to stop stepping in foo when
> arriving at that last insn.
> 
> There is however no guarantee that:
> - the last insn is actually executed, nor
> - that the last insn is executed last, nor
> - that the last insn is executed once.
> 
> Fix this by simplying the test-case to continue stepping till stepping out of
> foo.
> 

I re-read the commit log, found it not clear enough, and decided to make 
the difference between:
- last disassembled insn, and
- last insn executed before returning to main.
a bit more explicit.

Committed as attached.

Thanks,
- Tom

[-- Attachment #2: 0001-gdb-testsuite-Simplify-gdb.base-unwind-on-each-insn..patch --]
[-- Type: text/x-patch, Size: 3659 bytes --]

From 767e15c09b474e0de3d9323918706cef6a5a8466 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Wed, 18 Jan 2023 14:12:41 +0100
Subject: [pushed] [gdb/testsuite] Simplify gdb.base/unwind-on-each-insn.exp

In test-case gdb.base/unwind-on-each-insn.exp, we try to determine the last
disassembled insn in function foo.

This in it self is fragile, as demonstrated by commit 91836f41e20 ("Powerpc
fix for gdb.base/unwind-on-each-insn.exp").

The use of the last disassembled insn in the test-case is to stop stepping in
foo once reaching it.

However, the intent is to stop stepping just before returning to main.

There is no guarantee that the last disassembled insn:
- is actually executed
- is executed just before returning to main
- is executed only once.

Fix this by simplying the test-case to continue stepping till stepping out of
foo.

Tested on x86_64-linux.
---
 .../gdb.base/unwind-on-each-insn.exp          | 62 ++++---------------
 1 file changed, 11 insertions(+), 51 deletions(-)

diff --git a/gdb/testsuite/gdb.base/unwind-on-each-insn.exp b/gdb/testsuite/gdb.base/unwind-on-each-insn.exp
index c8748d5ae14..5e822effaf1 100644
--- a/gdb/testsuite/gdb.base/unwind-on-each-insn.exp
+++ b/gdb/testsuite/gdb.base/unwind-on-each-insn.exp
@@ -73,51 +73,6 @@ set main_fid [get_fid]
 gdb_breakpoint "*foo"
 gdb_continue_to_breakpoint "enter foo"
 
-# Figure out the range of addresses covered by this function.
-set last_addr_in_foo ""
-
-# The disassembly of foo on PowerPC looks like:
-#     Dump of assembler code for function foo:
-#  => 0x00000000100006dc <+0>:     std     r31,-8(r1)
-#     0x00000000100006e0 <+4>:     stdu    r1,-48(r1)
-#     0x00000000100006e4 <+8>:     mr      r31,r1
-#     0x00000000100006e8 <+12>:    nop
-#     0x00000000100006ec <+16>:    addi    r1,r31,48
-#     0x00000000100006f0 <+20>:    ld      r31,-8(r1)
-#     0x00000000100006f4 <+24>:    blr
-#     0x00000000100006f8 <+28>:    .long 0x0
-#     0x00000000100006fc <+32>:    .long 0x0
-#     0x0000000010000700 <+36>:    .long 0x1000180
-#     End of assembler dump.
-#
-# The last instruction in function foo is blr.  Need to ignore the .long
-# entries following the blr instruction.
-
-gdb_test_multiple "disassemble foo" "" {
-    -re "^disassemble foo\r\n" {
-	exp_continue
-    }
-
-    -re "^Dump of assembler code for function foo:\r\n" {
-	exp_continue
-    }
-
-    -re "^...($hex) \[<>+0-9:\s\t\]*\.long\[\s\t\]*\[^\r\n\]*\r\n" {
-	exp_continue
-    }
-
-    -re "^...($hex) \[^\r\n\]+\r\n" {
-	set last_addr_in_foo $expect_out(1,string)
-	exp_continue
-    }
-
-    -wrap -re "^End of assembler dump\\." {
-	gdb_assert { ![string equal $last_addr_in_foo ""] } \
-	    "found some addresses in foo"
-	pass $gdb_test_name
-    }
-}
-
 # Record the current stack-pointer, and the frame base address.
 lassign [get_sp_and_fba "in foo"] foo_sp foo_fba
 set foo_fid [get_fid]
@@ -158,11 +113,6 @@ for { set i_count 1 } { true } { incr i_count } {
 	# Move back to the inner most frame.
 	gdb_test "frame 0" ".*"
 
-	set pc [get_hexadecimal_valueof "\$pc" "*UNKNOWN*"]
-	if { $pc == $last_addr_in_foo } {
-	    break
-	}
-
 	if { $i_count > 100 } {
 	    # We expect a handful of instructions, if we reach 100,
 	    # something is going wrong.  Avoid an infinite loop.
@@ -170,6 +120,16 @@ for { set i_count 1 } { true } { incr i_count } {
 	    break
 	}
 
-	gdb_test "stepi" ".*"
+	set in_foo 0
+	gdb_test_multiple "stepi" "" {
+	    -re -wrap "$hex in foo \\(\\)" {
+		set in_foo 1
+	    }
+	    -re -wrap "" {}
+	}
+
+	if { ! $in_foo } {
+	    break
+	}
     }
 }

base-commit: bc0c6793fb45b491c6324614298a2880a34d3966
-- 
2.35.3


  reply	other threads:[~2023-01-23  9:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-19 10:46 [PATCH 0/4] [gdb] Test-case gdb.base/unwind-on-each-insn.exp improvements Tom de Vries
2023-01-19 10:46 ` [PATCH 1/4] [gdb/testsuite] Simplify gdb.base/unwind-on-each-insn.exp Tom de Vries
2023-01-23  9:36   ` Tom de Vries [this message]
2023-01-19 10:46 ` [PATCH 2/4] [gdb/testsuite] Improve gdb.base/unwind-on-each-insn.exp Tom de Vries
2023-01-23  9:55   ` Luis Machado
2023-01-19 10:46 ` [PATCH 3/4] [gdb/tdep, aarch64] Fix frame address of last insn in leaf function Tom de Vries
2023-01-20 10:25   ` Tom de Vries
2023-01-23 10:07   ` Luis Machado
2023-01-23 11:59     ` Tom de Vries
2023-01-23 12:09       ` Luis Machado
2023-01-19 10:46 ` [PATCH 4/4] [gdb/testsuite] Analyze non-leaf fn in gdb.base/unwind-on-each-insn.exp Tom de Vries
2023-01-23 10:18   ` Luis Machado
2023-01-25 12:32 ` [PATCH 0/4] [gdb] Test-case gdb.base/unwind-on-each-insn.exp improvements Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2029a6f2-5c42-3122-a0da-75b961d78cac@suse.de \
    --to=tdevries@suse.de \
    --cc=aburgess@redhat.com \
    --cc=blarsen@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=luis.machado@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).