Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Thomas Schwinge <thomas_schwinge@mentor.com>
To: gdb-patches@sourceware.org
Cc: Kevin Buettner <kevinb@redhat.com>
Subject: [SH] gdb.asm/asm-source.exp
Date: Thu, 22 Mar 2012 17:40:00 -0000	[thread overview]
Message-ID: <87ty1gedqk.fsf@schwinge.name> (raw)

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

Hi!

On SH, gdb.asm/asm-source.exp currently fails to build as follows:

    Executing on host: sh-linux-gnu-as [...]/gdb/testsuite/gdb.asm/asmsrc1.s -I[...]/gdb/testsuite/gdb.asm -I[...]/gdb.d/gdb.asm -gdwarf2 -o asmsrc1.o    (timeout = 3600)
    [GDB]/gdb/testsuite/gdb.asm/asmsrc1.s: Assembler messages:
    [GDB]/gdb/testsuite/gdb.asm/asmsrc1.s: Error: .size expression for _start does not evaluate to a constant
    [GDB]/gdb/testsuite/gdb.asm/asmsrc1.s: Error: .size expression for main does not evaluate to a constant
    [GDB]/gdb/testsuite/gdb.asm/asmsrc1.s: Error: .size expression for foo3 does not evaluate to a constant
    [GDB]/gdb/testsuite/gdb.asm/asmsrc1.s: Error: .size expression for exit does not evaluate to a constant
    [GDB]/gdb/testsuite/gdb.asm/asmsrc1.s: Error: .size expression for foostatic does not evaluate to a constant
    assembler exited with status 1

This comes from gdb.asm/sh.inc:

    31		comment "subroutine end"
    32		.purgem gdbasm_end
    33		.macro gdbasm_end name
    34		.size   \name, .-_foo1
    35		.align	1
    36		.endm

The _foo1 symbol doesn't exist anywhere (and it never has, in gdb.asm's
lifetime).  This is easily fixed, and makes the tests PASS for sh-elf.
(As this code has never been touched since its initial commit in 2003, I
wonder for how long this has been broken -- probably ever since?  Or what
were earlier assembler versions able to make out of that?)

gdb/testsuite/

	* gdb.asm/sh.inc (gdbasm_end) <.size>: Refer to the function's name.

Index: gdb.asm/sh.inc
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.asm/sh.inc,v
retrieving revision 1.2
diff -u -p -r1.2 sh.inc
--- gdb.asm/sh.inc	7 Mar 2005 21:16:50 -0000	1.2
+++ gdb.asm/sh.inc	22 Mar 2012 17:27:40 -0000
@@ -31,7 +31,7 @@
 	comment "subroutine end"
 	.purgem gdbasm_end
 	.macro gdbasm_end name
-	.size   \name, .-_foo1
+	.size   \name, . - \name
 	.align	1
 	.endm
 


However, that is not enough to make the executable runnable on
sh-linux-gnu: it chokes due to the stack pointer setup in gdbasm_startup.
There are several ways to address this (see ``diff -u m32r.inc
m32r-linux.inc'' for one example); I chose to generalize the code as
follows:

gdb/testsuite/

	* gdb.asm/sh.inc (gdbasm_startup): Only set up the stack pointer if the
	symbol _stack is defined.  Get rid of a hard-coded constant for _stack.

Index: gdb.asm/sh.inc
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.asm/sh.inc,v
retrieving revision 1.2
diff -u -p -r1.2 sh.inc
--- gdb.asm/sh.inc	7 Mar 2005 21:16:50 -0000	1.2
+++ gdb.asm/sh.inc	22 Mar 2012 17:27:40 -0000
@@ -65,13 +65,19 @@
 
 	comment "crt0 startup"
 	.macro gdbasm_startup
-	mov.l	.stackaddr,r15
+	comment "If there is a _stack symbol, use it for setting up the stack"
+	comment "pointer.  In hosted mode (when there is no _stack symbol),"
+	comment "the operating system will have initialized it already."
+	mov.l	.stackaddr, r0
+	tst	r0, r0
+	bt	.afterstackaddr
+	mov	r0, r15
 	bra	.afterstackaddr
 	nop
-	nop
 	.align 2
 .stackaddr:
-	.long	196608		! 0x30000
+	.weak	_stack
+	.long	_stack
 	.align	1
 .afterstackaddr:
 	.endm


Now the tests all PASS for both sh-linux-gnu and sh-elf:

    PASS: gdb.asm/asm-source.exp: f at main
    PASS: gdb.asm/asm-source.exp: next over macro
    PASS: gdb.asm/asm-source.exp: step into foo2
    PASS: gdb.asm/asm-source.exp: info target
    PASS: gdb.asm/asm-source.exp: info symbol
    PASS: gdb.asm/asm-source.exp: list
    PASS: gdb.asm/asm-source.exp: search
    PASS: gdb.asm/asm-source.exp: f in foo2
    PASS: gdb.asm/asm-source.exp: n in foo2
    PASS: gdb.asm/asm-source.exp: bt ALL in foo2
    PASS: gdb.asm/asm-source.exp: bt 2 in foo2
    PASS: gdb.asm/asm-source.exp: s 2
    PASS: gdb.asm/asm-source.exp: n 2
    PASS: gdb.asm/asm-source.exp: bt 3 in foo3
    PASS: gdb.asm/asm-source.exp: info source asmsrc1.s
    PASS: gdb.asm/asm-source.exp: finish from foo3
    PASS: gdb.asm/asm-source.exp: info source asmsrc2.s
    PASS: gdb.asm/asm-source.exp: info sources
    PASS: gdb.asm/asm-source.exp: info line
    PASS: gdb.asm/asm-source.exp: next over foo3
    PASS: gdb.asm/asm-source.exp: return from foo2
    PASS: gdb.asm/asm-source.exp: look at global variable
    PASS: gdb.asm/asm-source.exp: x/i &globalvar
    PASS: gdb.asm/asm-source.exp: disassem &globalvar, &globalvar+1
    PASS: gdb.asm/asm-source.exp: look at static variable
    PASS: gdb.asm/asm-source.exp: x/i &staticvar
    PASS: gdb.asm/asm-source.exp: disassem &staticvar, &staticvar+1
    PASS: gdb.asm/asm-source.exp: look at static function


OK to commit both patches?


Grüße,
 Thomas

[-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --]

             reply	other threads:[~2012-03-22 17:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-22 17:40 Thomas Schwinge [this message]
2012-03-23  3:56 ` Kevin Buettner

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=87ty1gedqk.fsf@schwinge.name \
    --to=thomas_schwinge@mentor.com \
    --cc=gdb-patches@sourceware.org \
    --cc=kevinb@redhat.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