Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: gdb-patches@sourceware.org
Subject: [patch] testsuite: Fix x32, introduce is_amd64_regs_target  [Re: [obv] testsuite: gdb.trace/*: Use is_lp64_target]
Date: Sun, 28 Aug 2011 20:07:00 -0000	[thread overview]
Message-ID: <20110828200640.GA10351@host1.jankratochvil.net> (raw)
In-Reply-To: <CAMe9rOpqQySk0Jdhgp9NPq6QAaa-nobrD1DBNuyHzXtNEcuZcQ@mail.gmail.com>

On Fri, 26 Aug 2011 15:48:33 +0200, H.J. Lu wrote:
> That is wrong for x32. X32 isn't LP64, but has 64bit registers.

x32 uses triple x86_64-x32-linux* which matches x86_64-*-*.

x32 was already broken as [is_x86_like_target] expects i386 instructions and
registers:
	is_lp64_target=0
	is_ilp32_target=1
	is_x86_like_target=1

Fixed testsuite now reports for x32:
	is_lp64_target=0
	is_ilp32_target=1
	is_x86_like_target=0
	is_amd64_regs_target=1

For normal -m64 the behavior is not changed:
	is_lp64_target=1
	is_ilp32_target=0
	is_x86_like_target=0
	is_amd64_regs_target=1

and neither changed for -m32:
	is_lp64_target=0
	is_ilp32_target=1
	is_x86_like_target=1
	is_amd64_regs_target=0

Still even after these fixes I see various problems of x32 GDB but that is sure
outside of the scope of this patch.

I will check it in if no comments appear.  No regressions on
{x86_64,x86_64-m32,i686}-fedora16pre-linux-gnu.


Thanks,
Jan


gdb/testsuite/
2011-08-28  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix compatibility with x32 arch.
	* testsuite/gdb.dwarf2/typeddwarf.exp: Check also is_lp64_target.
	* testsuite/gdb.trace/backtrace.exp: Use is_amd64_regs_target and
	is_x86_like_target.
	* testsuite/gdb.trace/collection.exp: Likewise.
	* testsuite/gdb.trace/report.exp: Likewise.
	* testsuite/gdb.trace/unavailable.exp: Likewise.
	* testsuite/gdb.trace/while-dyn.exp: Likewise.
	* testsuite/lib/gdb.exp (is_amd64_regs_target): New function.
	(is_x86_like_target): Check also is_amd64_regs_target.

--- a/gdb/testsuite/gdb.dwarf2/typeddwarf.exp
+++ b/gdb/testsuite/gdb.dwarf2/typeddwarf.exp
@@ -22,10 +22,10 @@ if ![dwarf2_support] {
     return 0  
 }
 
-# This test can only be run on x86 and amd64 targets.
+# This test can only be run on x86 and amd64 targets (and not x32).
 if { [is_x86_like_target] } {
     set sfile ${test}.S
-} elseif {[istarget "x86_64-*-*"]} {
+} elseif {[istarget "x86_64-*-*"] && [is_lp64_target]} {
     set sfile ${test}-amd64.S
 } else {
     return 0
--- a/gdb/testsuite/gdb.trace/backtrace.exp
+++ b/gdb/testsuite/gdb.trace/backtrace.exp
@@ -150,10 +150,10 @@ gdb_trace_setactions "8.6: setup TP to collect regs, args, and locals" \
 	"$tdp4" \
 	"collect \$regs, \$args, \$locs" "^$"
 
-if {([istarget "x86_64-*"] || [istarget "i?86-*"]) && [is_lp64_target]} then {
+if [is_amd64_regs_target] {
     set fpreg "\$rbp"
     set spreg "\$rsp"
-} elseif {[istarget "x86_64-*"] || [istarget "i?86-*"]} then {
+} elseif [is_x86_like_target] {
     set fpreg "\$ebp"
     set spreg "\$esp"
 } else {
--- a/gdb/testsuite/gdb.trace/collection.exp
+++ b/gdb/testsuite/gdb.trace/collection.exp
@@ -45,11 +45,11 @@ if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
 set ws "\[\r\n\t \]+"
 set cr "\[\r\n\]+"
 
-if {([istarget "x86_64-*"] || [istarget "i?86-*"]) && [is_lp64_target]} then {
+if [is_amd64_regs_target] {
     set fpreg "rbp"
     set spreg "rsp"
     set pcreg "rip"
-} elseif {[istarget "x86_64-*"] || [istarget "i?86-*"]} then {
+} elseif [is_x86_like_target] {
     set fpreg "ebp"
     set spreg "esp"
     set pcreg "eip"
--- a/gdb/testsuite/gdb.trace/report.exp
+++ b/gdb/testsuite/gdb.trace/report.exp
@@ -159,11 +159,11 @@ gdb_trace_setactions "9.x: setup TP to collect locals" \
 	"$tdp4" \
 	"collect \$locs" "^$"
 
-if {([istarget "x86_64-*"] || [istarget "i?86-*"]) && [is_lp64_target]} then {
+if [is_amd64_regs_target] {
     set fpreg "rbp"
     set spreg "rsp"
     set pcreg "rip"
-} elseif {[istarget "x86_64-*"] || [istarget "i?86-*"]} then {
+} elseif [is_x86_like_target] {
     set fpreg "ebp"
     set spreg "esp"
     set pcreg "eip"
--- a/gdb/testsuite/gdb.trace/unavailable.exp
+++ b/gdb/testsuite/gdb.trace/unavailable.exp
@@ -30,11 +30,11 @@ if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
 set ws "\[\r\n\t \]+"
 set cr "\[\r\n\]+"
 
-if {([istarget "x86_64-*"] || [istarget "i?86-*"]) && [is_lp64_target]} then {
+if [is_amd64_regs_target] {
     set fpreg "rbp"
     set spreg "rsp"
     set pcreg "rip"
-} elseif {[istarget "x86_64-*"] || [istarget "i?86-*"]} then {
+} elseif [is_x86_like_target] {
     set fpreg "ebp"
     set spreg "esp"
     set pcreg "eip"
@@ -295,12 +295,12 @@ proc gdb_unavailable_registers_test { } {
 
     # Test reading uncollected pseudo-registers.  The set of which
     # depends on target.
-    if {$pcreg == "rip"} then {
+    if [is_amd64_regs_target] {
 	# Check the raw register first.
 	test_register_unavailable "\$rax"
 	test_register_unavailable "\$eax"
 	test_register_unavailable "\$ax"
-    } elseif {$pcreg == "eip"} then {
+    } elseif [is_x86_like_target] {
 	# Check the raw register first.
 	test_register_unavailable "\$eax"
 	test_register_unavailable "\$ax"
--- a/gdb/testsuite/gdb.trace/while-dyn.exp
+++ b/gdb/testsuite/gdb.trace/while-dyn.exp
@@ -52,9 +52,9 @@ if { ![gdb_target_supports_trace] } then {
 # test while-stepping dynamically (live target)
 #
 
-if {([istarget "x86_64-*"] || [istarget "i?86-*"]) && [is_lp64_target]} then {
+if [is_amd64_regs_target] {
     set fpreg "\$rbp"
-} elseif {[istarget "x86_64-*"] || [istarget "i?86-*"]} then {
+} elseif [is_x86_like_target] {
     set fpreg "\$ebp"
 } else {
     set fpreg "\$fp"
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -1604,6 +1604,50 @@ proc is_lp64_target {} {
     return [set is_lp64_target_saved($board) 1]
 }
 
+# Return 1 if target has x86_64 registers - either amd64 or x32.
+# x32 target triple is x86_64-x32-* which is a subset of x86_64-*-*.
+# This cannot be decided simply from looking at the target string,
+# as it might depend on externally passed compiler options like -mx32.
+proc is_amd64_regs_target {} {
+    global is_amd64_regs_target_saved
+
+    if {![istarget "x86_64-*-*"]} {
+	return 0
+    }
+
+    # Use the cached value, if it exists.  Cache value per "board" to handle
+    # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
+    set me "is_amd64_regs_target"
+    set board [target_info name]
+    if [info exists is_amd64_regs_target_saved($board)] {
+        verbose "$me:  returning saved $is_amd64_regs_target_saved($board)" 2
+        return $is_amd64_regs_target_saved($board)
+    }
+
+    set src reg64[pid].s
+    set obj reg64[pid].o
+
+    set f [open $src "w"]
+    foreach reg \
+            {rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15} {
+	puts $f "\tincq %$reg"
+    }
+    close $f
+
+    verbose "$me:  compiling testfile $src" 2
+    set lines [gdb_compile $src $obj object {quiet}]
+    file delete $src
+    file delete $obj
+
+    if ![string match "" $lines] then {
+        verbose "$me:  testfile compilation failed, returning 0" 2
+        return [set is_amd64_regs_target_saved($board) 0]
+    }
+
+    verbose "$me:  returning 1" 2
+    return [set is_amd64_regs_target_saved($board) 1]
+}
+
 # Return 1 if this target is an x86 or x86-64 with -m32.
 proc is_x86_like_target {} {
     if {[istarget i?86-*]} {
@@ -1612,7 +1656,7 @@ proc is_x86_like_target {} {
     if {![istarget "x86_64-*-*"]} {
 	return 0
     }
-    return [is_ilp32_target]
+    return [expr [is_ilp32_target] && ![is_amd64_regs_target]]
 }
 
 # Return 1 if displaced stepping is supported on target, otherwise, return 0.


  parent reply	other threads:[~2011-08-28 20:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-26  9:26 [obv] testsuite: gdb.trace/*: Use is_lp64_target Jan Kratochvil
2011-08-26 13:48 ` H.J. Lu
2011-08-26 15:37   ` Jan Kratochvil
2011-08-26 15:59     ` H.J. Lu
2011-08-28 20:07   ` Jan Kratochvil [this message]
2011-08-28 21:06     ` [patch] testsuite: Fix x32, introduce is_amd64_regs_target [Re: [obv] testsuite: gdb.trace/*: Use is_lp64_target] Mark Kettenis
2011-09-08 15:38       ` [patch] testsuite: Fix x32, introduce is_amd64_regs_target Jan Kratochvil
2011-09-08 15:57         ` Pedro Alves
2011-09-08 17:47           ` Jan Kratochvil
2011-09-08 18:22             ` Mark Kettenis
2011-09-08 16:01         ` Mark Kettenis
2011-09-08 17:16         ` H.J. Lu
2011-08-28 21:19     ` [patch] testsuite: Fix x32, introduce is_amd64_regs_target [Re: [obv] testsuite: gdb.trace/*: Use is_lp64_target] Jan Kratochvil

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=20110828200640.GA10351@host1.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=hjl.tools@gmail.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