Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 2/2] Fix gdb.mi/mi-stack.exp when gcc generates a stack protector
Date: Sat, 16 Dec 2017 14:57:00 -0000	[thread overview]
Message-ID: <20171216145651.13936-2-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20171216145651.13936-1-simon.marchi@polymtl.ca>

I see some failures in the gdb.mi/mi-stack.exp test.  The test runs to
the callee4 function:

  int callee4 (void)
  {
    int A=1;
    int B=2;
    int C;
    int D[3] = {0, 1, 2};

    C = A + B;
    return 0;
  }

and expects to be stopped at the A=1 line.  However, when gcc generates
some stack protection code, it will stop at the { instead, as shown by
this disassembly (after I did "break callee4" and "run"):

  (gdb) disassemble /s
  Dump of assembler code for function callee4:
  /home/simark/src/binutils-gdb/gdb/testsuite/gdb.mi/mi-stack.c:
  26	{
     0x00005555555546ca <+0>:	push   %rbp
     0x00005555555546cb <+1>:	mov    %rsp,%rbp
     0x00005555555546ce <+4>:	sub    $0x20,%rsp
  => 0x00005555555546d2 <+8>:	mov    %fs:0x28,%rax
     0x00005555555546db <+17>:	mov    %rax,-0x8(%rbp)
     0x00005555555546df <+21>:	xor    %eax,%eax

  27	  int A=1; /* callee4 begin */
     0x00005555555546e1 <+23>:	movl   $0x1,-0x20(%rbp)

  28	  int B=2;
     0x00005555555546e8 <+30>:	movl   $0x2,-0x1c(%rbp)

The rest of the test relies on execution stopping on the A=1, so many things
fail after that.  This patch uses mi_continue_to_line instead, to stop at the
A=1 line precisely.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-stack.exp (test_stack_frame_listing): Use
	mi_continue_to_line.
	* gdb.mi/mi-stack.exp (callee4): Add comment.
---
 gdb/testsuite/gdb.mi/mi-stack.c   | 2 +-
 gdb/testsuite/gdb.mi/mi-stack.exp | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gdb/testsuite/gdb.mi/mi-stack.c b/gdb/testsuite/gdb.mi/mi-stack.c
index 30dce8b9f6..dc239f0e7b 100644
--- a/gdb/testsuite/gdb.mi/mi-stack.c
+++ b/gdb/testsuite/gdb.mi/mi-stack.c
@@ -24,7 +24,7 @@
 
 int callee4 (void)
 {
-  int A=1;
+  int A=1; /* callee4 begin */
   int B=2;
   int C;
   int D[3] = {0, 1, 2};
diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
index cd7c6d4c38..b88032c73e 100644
--- a/gdb/testsuite/gdb.mi/mi-stack.exp
+++ b/gdb/testsuite/gdb.mi/mi-stack.exp
@@ -46,8 +46,8 @@ proc test_stack_frame_listing {} {
     global mi_gdb_prompt
     global hex fullname_syntax srcfile
 
-    set line_callee4_head [gdb_get_line_number "callee4 ("]
-    set line_callee4_body [expr $line_callee4_head + 2]
+    set callee4_begin [gdb_get_line_number "callee4 begin"]
+    mi_continue_to_line $callee4_begin "continue to callee4 begin"
 
     # Obtain a stack trace
     # Tests:
@@ -56,7 +56,7 @@ proc test_stack_frame_listing {} {
     # -stack-list-frames 1 3
     # -stack-info-frame
     mi_gdb_test "231-stack-list-frames" \
-	"231\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"callee4\",file=\".*${srcfile}\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$line_callee4_body\"\},frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\},frame=\{level=\"2\",addr=\"$hex\",func=\"callee2\",.*\},frame=\{level=\"3\",addr=\"$hex\",func=\"callee1\",.*\},frame=\{level=\"4\",addr=\"$hex\",func=\"main\",.*\}\\\]" \
+	"231\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"callee4\",file=\".*${srcfile}\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$callee4_begin\"\},frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\},frame=\{level=\"2\",addr=\"$hex\",func=\"callee2\",.*\},frame=\{level=\"3\",addr=\"$hex\",func=\"callee1\",.*\},frame=\{level=\"4\",addr=\"$hex\",func=\"main\",.*\}\\\]" \
 	"stack frame listing"
     mi_gdb_test "232-stack-list-frames 1 1" \
 	"232\\^done,stack=\\\[frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\}\\\]" \
@@ -70,7 +70,7 @@ proc test_stack_frame_listing {} {
 	"stack frame listing wrong"
 
     mi_gdb_test "235-stack-info-frame" \
-	"235\\^done,frame=\{level=\"0\",addr=\"$hex\",func=\"callee4\",file=\".*${srcfile}\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$line_callee4_body\"\}" \
+	"235\\^done,frame=\{level=\"0\",addr=\"$hex\",func=\"callee4\",file=\".*${srcfile}\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$callee4_begin\"\}" \
 	"selected frame listing"
 
     mi_gdb_test "236-stack-list-frames 1 300" \
-- 
2.15.1


  reply	other threads:[~2017-12-16 14:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-16 14:57 [PATCH 1/2] Fix indentation in gdb.mi/mi-stack.exp Simon Marchi
2017-12-16 14:57 ` Simon Marchi [this message]
2018-01-02 10:38   ` [PATCH 2/2] Fix gdb.mi/mi-stack.exp when gcc generates a stack protector Yao Qi
2018-01-02 18:14     ` Simon Marchi
2018-01-03 21:53       ` Yao Qi
2018-01-03 22:39         ` Simon Marchi
2018-01-04 20:10           ` Simon Marchi
2018-04-07 18:14         ` Simon Marchi

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=20171216145651.13936-2-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    /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