Fix gdb.arch/amd64-invalid-stack-*.exp failures

Message ID 20180827133803.3473-1-jan.vrany@fit.cvut.cz
State New
Headers show
Series
  • Fix gdb.arch/amd64-invalid-stack-*.exp failures
Related show

Commit Message

Jan Vrany Aug. 27, 2018, 1:38 p.m.
Commit 6d52907e226a (MI: Print frame architecture when printing frames
on an MI channel) broke amd64-invalid-stack-middle.exp and
amd64-invalid-stack-middle.exp because regexps were not updated.

Fix it by updating regexps to accommodate new "arch" field.

gdb/testsuite/Changelog:
2018-08-27  Jan Vrany  <jan.vrany@fit.cvut.cz>

	* gdb.arch/amd64-invalid-stack-middle.exp: Update regexp to
	accommodate new "arch" field in frame output.
	* gdb.arch/amd64-invalid-stack-top.exp: Likewise.
---
 gdb/testsuite/ChangeLog                               | 6 ++++++
 gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp | 4 ++--
 gdb/testsuite/gdb.arch/amd64-invalid-stack-top.exp    | 4 ++--
 3 files changed, 10 insertions(+), 4 deletions(-)

-- 
2.18.0

Comments

Simon Marchi Aug. 27, 2018, 3:26 p.m. | #1
On 2018-08-27 09:38 AM, Jan Vrany wrote:
> Commit 6d52907e226a (MI: Print frame architecture when printing frames

> on an MI channel) broke amd64-invalid-stack-middle.exp and

> amd64-invalid-stack-middle.exp because regexps were not updated.

> 

> Fix it by updating regexps to accommodate new "arch" field.


In the other thread, you mentioned not being able to run the -middle.exp test
because of:

  gdb compile failed, /usr/bin/ld: /home/jv/Projects/gdb/users_jv_patches/gdb/testsuite/outputs/gdb.arch/amd64-invalid-stack-middle/amd64-invalid-stack-middle0.o: relocation R_X86_64_32 against
  `.rodata' can not be used when making a PIE object; recompile with -fPIC

That's probably because you have a "recent" toolchain that tries to build PIE executables
by default.  However, the assembly file has been generated without the position-independent
code switch (-fPIC), so it includes code that can't end up in a position-independent
executable.

I see 3 solutions:

1. Re-generate the file using the command in amd64-invalid-stack-middle.S, but with
   -fPIC.  That's a bit risky, because we need to make sure the new compiler emits
   code that would trigger the same bug the test has been written for.
2. Manually change amd64-invalid-stack-middle.S to remove things relying on .rodata.
   That may be a bit tedious and risky too.
3. Add the -no-pie linker switch to force generating position-dependent executables.

Solution #3 is easy and safe, so I would lean towards that, it's a one-liner:

diff --git a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
index c00bfa10bd1b..b17eea59edc2 100644
--- a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
+++ b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
@@ -27,7 +27,7 @@
 # run twice, and we restart gdb before testing each different command to
 # ensure that nothing is being cached.

-set opts {}
+set opts {ldflags=-no-pie}
 standard_testfile .S

 if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {


---

With that, you should be able to run the test and confirm your patch works.
It does fix the failures when I run it locally, and the patch LGTM.

If you want to make a proper patch to add the -no-pie flag, you are welcome
to.

Thanks,

Simon
Jan Vrany Aug. 27, 2018, 9:05 p.m. | #2
On Mon, 2018-08-27 at 11:26 -0400, Simon Marchi wrote:
> On 2018-08-27 09:38 AM, Jan Vrany wrote:

> > Commit 6d52907e226a (MI: Print frame architecture when printing frames

> > on an MI channel) broke amd64-invalid-stack-middle.exp and

> > amd64-invalid-stack-middle.exp because regexps were not updated.

> > 

> > Fix it by updating regexps to accommodate new "arch" field.

> 

> In the other thread, you mentioned not being able to run the -middle.exp test

> because of:

> 

>   gdb compile failed, /usr/bin/ld: /home/jv/Projects/gdb/users_jv_patches/gdb/testsuite/outputs/gdb.arch/amd64-invalid-stack-middle/amd64-invalid-stack-middle0.o: relocation R_X86_64_32 against

>   `.rodata' can not be used when making a PIE object; recompile with -fPIC

> 

> That's probably because you have a "recent" toolchain that tries to build PIE executables

> by default.  However, the assembly file has been generated without the position-independent

> code switch (-fPIC), so it includes code that can't end up in a position-independent

> executable.

> 

> I see 3 solutions:

> 

> 1. Re-generate the file using the command in amd64-invalid-stack-middle.S, but with

>    -fPIC.  That's a bit risky, because we need to make sure the new compiler emits

>    code that would trigger the same bug the test has been written for.

> 2. Manually change amd64-invalid-stack-middle.S to remove things relying on .rodata.

>    That may be a bit tedious and risky too.

> 3. Add the -no-pie linker switch to force generating position-dependent executables.

> 

> Solution #3 is easy and safe, so I would lean towards that, it's a one-liner:

> 

> diff --git a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp

> index c00bfa10bd1b..b17eea59edc2 100644

> --- a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp

> +++ b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp

> @@ -27,7 +27,7 @@

>  # run twice, and we restart gdb before testing each different command to

>  # ensure that nothing is being cached.

> 

> -set opts {}

> +set opts {ldflags=-no-pie}

>  standard_testfile .S

> 

>  if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {

> 

> 

> ---

> 

> With that, you should be able to run the test and confirm your patch works.


Yes, with you patch amd64-invalid-stack-middle.exp passes here. Thanks!
 
> It does fix the failures when I run it locally, and the patch LGTM.

> 

> If you want to make a proper patch to add the -no-pie flag, you are welcome

> to.


I'll do tomorrow. 

Thanks, Jan

> 

> Thanks,

> 

> Simon

Patch

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 6b5275a4cb..1bc057494d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@ 
+2018-08-27  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.arch/amd64-invalid-stack-middle.exp: Update regexp to
+	accommodate new "arch" field in frame output.
+	* gdb.arch/amd64-invalid-stack-top.exp: Likewise.
+
 2018-08-23  Kevin Buettner  <kevinb@redhat.com>
 
 	* gdb.dwarf2/dw2-ranges-func.c: New file.
diff --git a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
index c00bfa10bd..ca494b9551 100644
--- a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
+++ b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
@@ -70,9 +70,9 @@  if ![runto breakpt] {
 }
 
 gdb_test "interpreter-exec mi \"-stack-list-frames\"" \
-    "\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"breakpt\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\"\},frame=\{level=\"1\",addr=\"$hex\",func=\"func5\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\"\},frame=\{level=\"2\",addr=\"$hex\",func=\"func4\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\"\},frame=\{level=\"3\",addr=\"$hex\",func=\"func3\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\"\}\\\]" \
+    "\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"breakpt\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\",arch=\"i386:x86-64\"\},frame=\{level=\"1\",addr=\"$hex\",func=\"func5\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\",arch=\"i386:x86-64\"\},frame=\{level=\"2\",addr=\"$hex\",func=\"func4\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\",arch=\"i386:x86-64\"\},frame=\{level=\"3\",addr=\"$hex\",func=\"func3\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\",arch=\"i386:x86-64\"\}\\\]" \
     "check mi -stack-list-frames command, first time"
 
 gdb_test "interpreter-exec mi \"-stack-list-frames\"" \
-    "\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"breakpt\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\"\},frame=\{level=\"1\",addr=\"$hex\",func=\"func5\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\"\},frame=\{level=\"2\",addr=\"$hex\",func=\"func4\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\"\},frame=\{level=\"3\",addr=\"$hex\",func=\"func3\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\"\}\\\]" \
+    "\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"breakpt\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\",arch=\"i386:x86-64\"\},frame=\{level=\"1\",addr=\"$hex\",func=\"func5\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\",arch=\"i386:x86-64\"\},frame=\{level=\"2\",addr=\"$hex\",func=\"func4\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\",arch=\"i386:x86-64\"\},frame=\{level=\"3\",addr=\"$hex\",func=\"func3\",file=\"\[^\"\]+\",fullname=\"\[^\"\]+\",line=\"${decimal}\",arch=\"i386:x86-64\"\}\\\]" \
     "check mi -stack-list-frames command, second time"
diff --git a/gdb/testsuite/gdb.arch/amd64-invalid-stack-top.exp b/gdb/testsuite/gdb.arch/amd64-invalid-stack-top.exp
index 64bcfe0099..8cbc8ddbb7 100644
--- a/gdb/testsuite/gdb.arch/amd64-invalid-stack-top.exp
+++ b/gdb/testsuite/gdb.arch/amd64-invalid-stack-top.exp
@@ -72,9 +72,9 @@  if ![runto breakpt] {
 }
 
 gdb_test "interpreter-exec mi \"-stack-list-frames\"" \
-    "\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"func2\"\}\\\]" \
+    "\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"func2\",arch=\"i386:x86-64\"\}\\\]" \
     "check mi -stack-list-frames command, first time"
 
 gdb_test "interpreter-exec mi \"-stack-list-frames\"" \
-    "\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"func2\"\}\\\]" \
+    "\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"func2\",arch=\"i386:x86-64\"\}\\\]" \
     "check mi -stack-list-frames command, second time"