testsuite: Define and use gdb_target_symbol_prefix_flags_asm
Commit Message
Some of the source code for the test cases in the GDB testsuite
reside in .S files containing assembly code. These files typically
define a symbol - such as main - which may, depending on the target,
require a prefix such as underscore.
For example, gdb.dwarf2/dw-compdir-oldgcc.S defines the symbol main:
main: .globl main
Some targets, such as rx-elf, require main to have an underscore
prefix. (If it doesn't, a linker error results due to not being able
to find _main required by crt0.o.) So, instead, the above should look
like this for rx-elf and other targets with this same requirement:
_main: .globl _main
This patch defines a new tcl proc in lib/gdb named
gdb_target_symbol_prefix_flags_asm. This proc returns a string
which will - assuming everything else is wired up correctly - cause
-DSYMBOL_PREFIX=_ to be passed on the command line to the compiler.
The test cases are augmented with a macro definition for SYMBOL
as follows:
#define CONCAT1(a, b) CONCAT2(a, b)
#define CONCAT2(a, b) a ## b
#ifdef SYMBOL_PREFIX
# define SYMBOL(str) CONCAT1(SYMBOL_PREFIX, str)
#else
# define SYMBOL(str) str
#endif
Symbols, such as main shown in the example earlier are then wrapped
with SYMBOL like this:
SYMBOL(main): .globl SYMBOL(main)
The net effect will be to add a prefix for those targets which need
it and add no prefix for those targets which do not.
It should be noted that there was already a proc in lib/gdb.exp
called gdb_target_symbol_prefix_flags. It still exists, but has
been rewritten in terms of gdb_target_symbol_prefix_flags_asm.
That proc used to explicitly list targets which were known to
require an underscore prefix. This is no longer done; the recently
added proc, gdb_target_symbol_prefix, is now invoked to dynamically
discover whether or not a prefix is required for that particular
target.
The difference between gdb_target_symbol_prefix_flags_asm
and gdb_target_symbol_prefix_flags is that the former returns
a bare prefix while the latter returns the prefix enclosed in
double quotes. I.e. assuming that the discovered prefix is
underscore, gdb_target_symbol_prefix_flags_asm returns:
additional_flags=-DSYMBOL_PREFIX=_
while gdb_target_symbol_prefix_flags returns:
additional_flags=-DSYMBOL_PREFIX="_"
The double-quoted version is not suitable for using with .S files
containing assembly code; there is no way to strip the double quotes
using C preprocessor constructs.
It would be possible to use the bare (non double quoted) version in
C source code. However, the supporting macros become more complicated
and therefore more difficult to maintain.
gdb/testsuite/ChangeLog:
* lib/gdb (gdb_target_symbol_prefix_flags_asm): New proc.
(gdb_target_symbol_prefix_flags): Define in terms of _asm
version.
* gdb.arch/i386-float.exp, gdb.arch/i386-permbkpt.exp,
gdb.dwarf2/dw2-canonicalize-type.exp,
gdb.dwarf2/dw2-compdir-oldgcc.exp, gdb.dwarf2/dw2-minsym-in-cu.exp,
gdb.dwarf2/dw2-op-stack-value.exp, gdb.dwarf2/dw2-unresolved.exp,
gdb.dwarf2/fission-reread.exp, gdb.dwarf2/pr13961.exp: Use flags
provided by gdb_target_symbol_prefix_flags_asm.
* gdb.dwarf2/dw2-canonicalize-type.S, gdb.dwarf2/dw2-compdir-oldgcc.S,
testsuite/gdb.dwarf2/dw2-minsym-in-cu.S,
testsuite/gdb.dwarf2/dw2-unresolved-main.c,
testsuite/gdb.dwarf2/dw2-unresolved.S, gdb.dwarf2/fission-reread.S,
gdb.dwarf2/pr13961.S: Define and use SYMBOL macro (and supporting
macros where needed). Use this macro for symbols which require
the prefix provided by SYMBOL_PREFIX.
---
gdb/testsuite/gdb.arch/i386-float.exp | 2 +-
gdb/testsuite/gdb.arch/i386-permbkpt.exp | 2 +-
gdb/testsuite/gdb.dwarf2/dw2-canonicalize-type.S | 17 ++++++--
gdb/testsuite/gdb.dwarf2/dw2-canonicalize-type.exp | 6 ++-
gdb/testsuite/gdb.dwarf2/dw2-compdir-oldgcc.S | 11 ++++-
gdb/testsuite/gdb.dwarf2/dw2-compdir-oldgcc.exp | 6 ++-
gdb/testsuite/gdb.dwarf2/dw2-minsym-in-cu.S | 17 ++++++--
gdb/testsuite/gdb.dwarf2/dw2-minsym-in-cu.exp | 6 ++-
gdb/testsuite/gdb.dwarf2/dw2-op-stack-value.exp | 3 ++
gdb/testsuite/gdb.dwarf2/dw2-unresolved-main.c | 22 ++++++++--
gdb/testsuite/gdb.dwarf2/dw2-unresolved.S | 21 +++++++---
gdb/testsuite/gdb.dwarf2/dw2-unresolved.exp | 7 +++-
gdb/testsuite/gdb.dwarf2/fission-reread.S | 27 ++++++++----
gdb/testsuite/gdb.dwarf2/fission-reread.exp | 6 ++-
gdb/testsuite/gdb.dwarf2/pr13961.S | 17 ++++++--
gdb/testsuite/gdb.dwarf2/pr13961.exp | 6 ++-
gdb/testsuite/lib/gdb.exp | 49 +++++++++++++++++-----
17 files changed, 174 insertions(+), 51 deletions(-)
Comments
On 11/06/2015 05:28 AM, Kevin Buettner wrote:
> +# It's possible to use this version (_asm) for C/C++ source files too,
> +# but a string is usually required in such files; providing a version
> +# (no _asm) which encloses the prefix with double quotes makes it
> +# somewhat easier to define the supporting macros in the test case.
> +
> +proc gdb_target_symbol_prefix_flags_asm {} {
> + set prefix [gdb_target_symbol_prefix]
> + if {$prefix ne ""} {
> + return "additional_flags=-DSYMBOL_PREFIX=$prefix"
> } else {
> - return ""
> + return "";
> }
> }
>
> +# gdb_target_symbol_prefix_flags returns the same string as
> +# gdb_target_symbol_prefix_flags_asm, above, but with the prefix
> +# enclosed in double quotes if there is a prefix.
> +#
> +# See the comment for gdb_target_symbol_prefix_flags_asm for an
> +# extended discussion.
> +
> +proc gdb_target_symbol_prefix_flags {} {
> + set flags [gdb_target_symbol_prefix_flags_asm]
> + regsub {(DSYMBOL_PREFIX=)(.*)$} $flags {\1"\2"} flags
> + return flags
Hmm, I think it'd end up simpler/less magic to remove the
indirection through gdb_target_symbol_prefix_flags_asm after all.
It's about the same number of worker lines, but no magic regex.
Like:
proc gdb_target_symbol_prefix_flags_asm {} {
set prefix [gdb_target_symbol_prefix]
if {$prefix ne ""} {
return "additional_flags=-DSYMBOL_PREFIX=\"$prefix\""
}
return ""
}
WDYT?
Otherwise LGTM.
Thanks,
Pedro Alves
On Fri, 06 Nov 2015 09:42:53 +0000
Pedro Alves <palves@redhat.com> wrote:
> On 11/06/2015 05:28 AM, Kevin Buettner wrote:
>
> > +proc gdb_target_symbol_prefix_flags {} {
> > + set flags [gdb_target_symbol_prefix_flags_asm]
> > + regsub {(DSYMBOL_PREFIX=)(.*)$} $flags {\1"\2"} flags
> > + return flags
>
> Hmm, I think it'd end up simpler/less magic to remove the
> indirection through gdb_target_symbol_prefix_flags_asm after all.
> It's about the same number of worker lines, but no magic regex.
> Like:
>
> proc gdb_target_symbol_prefix_flags_asm {} {
> set prefix [gdb_target_symbol_prefix]
> if {$prefix ne ""} {
> return "additional_flags=-DSYMBOL_PREFIX=\"$prefix\""
> }
> return ""
> }
>
> WDYT?
I think you're right.
I'll make that change later on today and then push it.
Thanks again for your help with this.
Kevin
On Fri, 6 Nov 2015 06:25:18 -0700
Kevin Buettner <kevinb@redhat.com> wrote:
> On Fri, 06 Nov 2015 09:42:53 +0000
> Pedro Alves <palves@redhat.com> wrote:
>
> > On 11/06/2015 05:28 AM, Kevin Buettner wrote:
> >
> > > +proc gdb_target_symbol_prefix_flags {} {
> > > + set flags [gdb_target_symbol_prefix_flags_asm]
> > > + regsub {(DSYMBOL_PREFIX=)(.*)$} $flags {\1"\2"} flags
> > > + return flags
> >
> > Hmm, I think it'd end up simpler/less magic to remove the
> > indirection through gdb_target_symbol_prefix_flags_asm after all.
> > It's about the same number of worker lines, but no magic regex.
> > Like:
> >
> > proc gdb_target_symbol_prefix_flags_asm {} {
> > set prefix [gdb_target_symbol_prefix]
> > if {$prefix ne ""} {
> > return "additional_flags=-DSYMBOL_PREFIX=\"$prefix\""
> > }
> > return ""
> > }
> >
> > WDYT?
>
> I think you're right.
>
> I'll make that change later on today and then push it.
I've pushed this change.
Kevin
@@ -26,7 +26,7 @@ if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then {
standard_testfile .S
# some targets have leading underscores on assembly symbols.
-set additional_flags [gdb_target_symbol_prefix_flags]
+set additional_flags [gdb_target_symbol_prefix_flags_asm]
if { [prepare_for_testing break.exp $testfile $srcfile [list debug $additional_flags]] } {
return -1
@@ -26,7 +26,7 @@ if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then {
standard_testfile .S
# some targets have leading underscores on assembly symbols.
-set additional_flags [gdb_target_symbol_prefix_flags]
+set additional_flags [gdb_target_symbol_prefix_flags_asm]
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug $additional_flags]] != "" } {
untested i386-permbkpt.exp
@@ -13,9 +13,18 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#define CONCAT1(a, b) CONCAT2(a, b)
+#define CONCAT2(a, b) a ## b
+
+#ifdef SYMBOL_PREFIX
+# define SYMBOL(str) CONCAT1(SYMBOL_PREFIX, str)
+#else
+# define SYMBOL(str) str
+#endif
+
.text
- .globl main
-main:
+ .globl SYMBOL(main)
+SYMBOL(main):
.4byte 0
.Lmain_end:
.section .debug_info
@@ -29,12 +38,12 @@ debug_start:
.ascii "GNU C 4.4.3\0" /* DW_AT_producer */
.byte 0x4 /* DW_AT_language = DW_LANG_C_plus_plus */
.ascii "1.c\0" /* DW_AT_name */
- .4byte main /* DW_AT_low_pc */
+ .4byte SYMBOL(main) /* DW_AT_low_pc */
.4byte .Lmain_end /* DW_AT_high_pc */
.uleb128 0x4 /* (DIE (0x3c) DW_TAG_subprogram) */
.ascii "f\0" /* DW_AT_name */
/* Value 0 would require has_section_at_zero != 0 (which is true, though). */
- .4byte main /* DW_AT_low_pc */
+ .4byte SYMBOL(main) /* DW_AT_low_pc */
.4byte .Lmain_end /* DW_AT_high_pc */
.byte 0x1 /* DW_AT_prototyped */
@@ -19,10 +19,14 @@ if {![dwarf2_support]} {
return 0
}
+# Some targets have leading underscores on assembly symbols.
+set additional_flags [gdb_target_symbol_prefix_flags_asm]
+
standard_testfile .S
set executable ${testfile}
-if [prepare_for_testing $testfile.exp $testfile $srcfile {nodebug}] {
+if [prepare_for_testing $testfile.exp $testfile $srcfile \
+ [list nodebug $additional_flags]] {
return -1
}
@@ -15,8 +15,17 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#define CONCAT1(a, b) CONCAT2(a, b)
+#define CONCAT2(a, b) a ## b
+
+#ifdef SYMBOL_PREFIX
+# define SYMBOL(str) CONCAT1(SYMBOL_PREFIX, str)
+#else
+# define SYMBOL(str) str
+#endif
+
.text
-main: .globl main
+SYMBOL(main): .globl SYMBOL(main)
gcc42: .globl gcc42
.Lgcc42_procstart:
@@ -19,8 +19,12 @@ if {![dwarf2_support]} {
return 0
}
+# Some targets have leading underscores on assembly symbols.
+set additional_flags [gdb_target_symbol_prefix_flags_asm]
+
standard_testfile .S
-if {[prepare_for_testing $testfile.exp $testfile $srcfile]} {
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+ $additional_flags]} {
return -1
}
@@ -15,16 +15,25 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#define CONCAT1(a, b) CONCAT2(a, b)
+#define CONCAT2(a, b) a ## b
+
+#ifdef SYMBOL_PREFIX
+# define SYMBOL(str) CONCAT1(SYMBOL_PREFIX, str)
+#else
+# define SYMBOL(str) str
+#endif
+
.text
.Lbegin_text1:
- .globl main
- .type main, %function
-main:
+ .globl SYMBOL(main)
+ .type SYMBOL(main), %function
+SYMBOL(main):
.Lbegin_main:
.int 0
.Lend_main:
- .size main, .-main
+ .size SYMBOL(main), .-SYMBOL(main)
.globl func2
.type func2, %function
@@ -21,9 +21,13 @@ if {![dwarf2_support]} {
# This testfile has reproducibility only with cc-with-index.sh.
+# Some targets have leading underscores on assembly symbols.
+set additional_flags [gdb_target_symbol_prefix_flags_asm]
+
standard_testfile .S
-if [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] {
+if [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+ ${additional_flags}] {
return -1
}
@@ -19,6 +19,9 @@ if {![dwarf2_support]} {
return 0
}
+# Some targets have leading underscores on assembly symbols.
+set additional_flags [gdb_target_symbol_prefix_flags_asm]
+
standard_testfile .S
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" $binfile \
@@ -17,6 +17,20 @@
#include <stdlib.h>
+#define CONCAT1(a, b) CONCAT2(a, b)
+#define CONCAT2(a, b) a ## b
+
+#ifdef SYMBOL_PREFIX
+# define SYMBOL1(str) CONCAT1(SYMBOL_PREFIX, str)
+#else
+# define SYMBOL1(str) str
+#endif
+
+#define STR1(s) #s
+#define STR(s) STR1(s)
+
+#define SYMBOL(str) STR(SYMBOL1(str))
+
asm (".globl cu_text_start");
asm ("cu_text_start:");
@@ -31,12 +45,12 @@ main (void)
extern unsigned char var;
/* Do not rely on the `extern' DIE output by GCC (GCC PR debug/39563). */
-asm (".globl extern_block_start");
-asm ("extern_block_start:");
+asm (".globl " SYMBOL(extern_block_start));
+asm (SYMBOL(extern_block_start) ":");
if (var != 2)
abort ();
-asm (".globl extern_block_end");
-asm ("extern_block_end:");
+asm (".globl " SYMBOL(extern_block_end));
+asm (SYMBOL(extern_block_end) ":");
}
return 0;
@@ -15,15 +15,24 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#define CONCAT1(a, b) CONCAT2(a, b)
+#define CONCAT2(a, b) a ## b
+
+#ifdef SYMBOL_PREFIX
+# define SYMBOL(str) CONCAT1(SYMBOL_PREFIX, str)
+#else
+# define SYMBOL(str) str
+#endif
+
.data
/* VAR1 is wrong here, in the real inferior it is located on stack. As both
places are never modified and they are initialized to the same value it
makes no difference. Ensure the name clash for "var". */
-var1: .byte 1
+SYMBOL(var1): .byte 1
- .globl var
-var: .byte 2
+ .globl SYMBOL(var)
+SYMBOL(var): .byte 2
/* Debug information */
@@ -64,12 +73,12 @@ var: .byte 2
.byte 2f - 1f /* DW_AT_location */
1: .byte 3 /* DW_OP_addr */
/* See VAR1 definition why this DIE is not correct. */
- .4byte var1 /* <addr> */
+ .4byte SYMBOL(var1) /* <addr> */
2: .4byte .Ltype_uchar-.Lcu1_begin /* DW_AT_type */
.uleb128 6 /* Abbrev: DW_TAG_lexical_block */
- .4byte extern_block_start /* DW_AT_low_pc */
- .4byte extern_block_end /* DW_AT_high_pc */
+ .4byte SYMBOL(extern_block_start) /* DW_AT_low_pc */
+ .4byte SYMBOL(extern_block_end) /* DW_AT_high_pc */
.uleb128 5 /* Abbrev: DW_TAG_variable (extern) */
.ascii "var\0" /* DW_AT_name */
@@ -19,7 +19,12 @@ if {![dwarf2_support]} {
return 0
}
-if { [prepare_for_testing dw2-unresolved.exp "dw2-unresolved" {dw2-unresolved-main.c dw2-unresolved.S} {nodebug}] } {
+# Some targets have leading underscores on assembly symbols.
+set additional_flags [gdb_target_symbol_prefix_flags_asm]
+
+if { [prepare_for_testing dw2-unresolved.exp "dw2-unresolved" \
+ {dw2-unresolved-main.c dw2-unresolved.S} \
+ [list nodebug $additional_flags]] } {
return -1
}
@@ -38,27 +38,36 @@
further hand-edited to support that.
*/
+#define CONCAT1(a, b) CONCAT2(a, b)
+#define CONCAT2(a, b) a ## b
+
+#ifdef SYMBOL_PREFIX
+# define SYMBOL(str) CONCAT1(SYMBOL_PREFIX, str)
+#else
+# define SYMBOL(str) str
+#endif
+
.file "fission-reread.cc"
- .globl baz
+ .globl SYMBOL(baz)
.data /* Previously this used .bss, but it's not portable. */
.align 4
- .type baz, %object
- .size baz, 4
-baz:
+ .type SYMBOL(baz), %object
+ .size SYMBOL(baz), 4
+SYMBOL(baz):
.zero 4
.text
.Ltext0:
- .globl main
- .type main, %function
-main:
+ .globl SYMBOL(main)
+ .type SYMBOL(main), %function
+SYMBOL(main):
.LFB0:
.file 1 "fission-reread.cc"
.loc 1 11 0
.4byte 0
.LFE0:
- .size main, .-main
+ .size SYMBOL(main), .-SYMBOL(main)
.Letext0:
.section .debug_types.dwo
@@ -450,4 +459,4 @@ main:
.section .debug_addr
.Ldebug_addr0:
.4byte .LFB0 /* DW_AT_low_pc */
- .4byte baz /* DW_AT_location */
+ .4byte SYMBOL(baz) /* DW_AT_location */
@@ -25,10 +25,14 @@ if ![dwarf2_support] {
return 0
}
+# Some targets have leading underscores on assembly symbols.
+set additional_flags [gdb_target_symbol_prefix_flags_asm]
+
standard_testfile .S
if [build_executable_from_fission_assembler \
- "$testfile.exp" "$binfile" "$srcfile" {nodebug}] {
+ "$testfile.exp" "$binfile" "$srcfile" \
+ [list nodebug $additional_flags]] {
return -1
}
@@ -37,6 +37,15 @@
further hand-edited to support that.
*/
+#define CONCAT1(a, b) CONCAT2(a, b)
+#define CONCAT2(a, b) a ## b
+
+#ifdef SYMBOL_PREFIX
+# define SYMBOL(str) CONCAT1(SYMBOL_PREFIX, str)
+#else
+# define SYMBOL(str) str
+#endif
+
.file "pr13961.cc"
.globl baz
@@ -55,13 +64,13 @@ baz:
.text
.Ltext0:
- .globl main
- .type main, %function
-main:
+ .globl SYMBOL(main)
+ .type SYMBOL(main), %function
+SYMBOL(main):
.LFB0:
.4byte 0
.LFE0:
- .size main, .-main
+ .size SYMBOL(main), .-SYMBOL(main)
.Letext0:
.section .debug_types,"",%progbits
@@ -22,9 +22,13 @@ if {![dwarf2_support]} {
return 0
}
+# Some targets have leading underscores on assembly symbols.
+set additional_flags [gdb_target_symbol_prefix_flags_asm]
+
standard_testfile .S
-if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] == -1 } {
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+ ${additional_flags}] == -1 } {
return -1
}
@@ -5571,21 +5571,48 @@ proc gdb_target_symbol { symbol } {
return "${prefix}${symbol}"
}
-# gdb_target_symbol_prefix_flags returns a string that can be added
-# to gdb_compile options to define SYMBOL_PREFIX macro value
-# symbol_prefix_flags returns a string that can be added
-# for targets that use underscore as symbol prefix.
-# TODO: find out automatically if the target needs this.
-
-proc gdb_target_symbol_prefix_flags {} {
- if { [istarget "i?86-*-cygwin*"] || [istarget "i?86-*-mingw*"]
- || [istarget "*-*-msdosdjgpp*"] || [istarget "*-*-go32*"] } {
- return "additional_flags=-DSYMBOL_PREFIX=\"_\""
+# gdb_target_symbol_prefix_flags_asm returns a string that can be
+# added to gdb_compile options to define the C-preprocessor macro
+# SYMBOL_PREFIX with a value that can be prepended to symbols
+# for targets which require a prefix, such as underscore.
+#
+# This version (_asm) defines the prefix without double quotes
+# surrounding the prefix. It is used to define the macro
+# SYMBOL_PREFIX for assembly language files. Another version, below,
+# is used for symbols in inline assembler in C/C++ files.
+#
+# The lack of quotes in this version (_asm) makes it possible to
+# define supporting macros in the .S file. (The version which
+# uses quotes for the prefix won't work for such files since it's
+# impossible to define a quote-stripping macro in C.)
+#
+# It's possible to use this version (_asm) for C/C++ source files too,
+# but a string is usually required in such files; providing a version
+# (no _asm) which encloses the prefix with double quotes makes it
+# somewhat easier to define the supporting macros in the test case.
+
+proc gdb_target_symbol_prefix_flags_asm {} {
+ set prefix [gdb_target_symbol_prefix]
+ if {$prefix ne ""} {
+ return "additional_flags=-DSYMBOL_PREFIX=$prefix"
} else {
- return ""
+ return "";
}
}
+# gdb_target_symbol_prefix_flags returns the same string as
+# gdb_target_symbol_prefix_flags_asm, above, but with the prefix
+# enclosed in double quotes if there is a prefix.
+#
+# See the comment for gdb_target_symbol_prefix_flags_asm for an
+# extended discussion.
+
+proc gdb_target_symbol_prefix_flags {} {
+ set flags [gdb_target_symbol_prefix_flags_asm]
+ regsub {(DSYMBOL_PREFIX=)(.*)$} $flags {\1"\2"} flags
+ return flags
+}
+
# A wrapper for 'remote_exec host' that passes or fails a test.
# Returns 0 if all went well, nonzero on failure.
# TEST is the name of the test, other arguments are as for remote_exec.