This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] gdb.dwarf2: Define and use gdb_target_symbol_prefix for symbol prefixes
- From: Pedro Alves <palves at redhat dot com>
- To: Kevin Buettner <kevinb at redhat dot com>, gdb-patches at sourceware dot org
- Date: Thu, 05 Nov 2015 10:46:33 +0000
- Subject: Re: [PATCH] gdb.dwarf2: Define and use gdb_target_symbol_prefix for symbol prefixes
- Authentication-results: sourceware.org; auth=none
- References: <20151029212509 dot 438b5642 at pinnacle dot lan> <20151029222505 dot 3bb590b9 at pinnacle dot lan> <56335065 dot 1060100 at redhat dot com> <20151104233946 dot 51336127 at pinnacle dot lan>
On 11/05/2015 06:39 AM, Kevin Buettner wrote:
> On Fri, 30 Oct 2015 11:11:33 +0000
> Pedro Alves <palves@redhat.com> wrote:
> But for a .S file, we need to do something like this (as shown in
> gdb.arch/i386-float.S):
>
> #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 SYMBOL(main)
> SYMBOL(main):
>
> I don't understand the reason for both CONCAT1 and CONCAT2,
You need two levels in order to first expand SYMBOL_PREFIX, and
then concat the result. Otherwise SYMBOL(main) expands to
literally "SYMBOL_PREFIXmain" (minus quotes).
> It seems to me that the way to fix this is to make
> gdb_target_symbol_prefix_flags return an unquoted prefix. I.e.
> it should return:
>
> additional_flags=-DSYMBOL_PREFIX=_
>
> instead of:
>
> additional_flags=-DSYMBOL_PREFIX="_"
Yup.
>
> Then, within C files, SYMBOL is defined as follows:
>
> #ifdef SYMBOL_PREFIX
> #define SYMBOL(str) #SYMBOL_PREFIX #str
> #else
> #define SYMBOL(str) #str
> #endif
>
> Note that this is the same as before, except that I added a # to
> the front of SYMBOL_PREFIX. It's possible that this won't work -
It wont. # can only be used with a macro parameter.
> we might end up with "SYMBOL_PREFIX" instead of "_" for the prefix.
> If that's the case, then some layering is needed, perhaps something
> like this:
>
> #define STRCAT1(a,b) #a #b
> #ifdef SYMBOL_PREFIX
> #define SYMBOL(str) STRCAT1(SYMBOL_PREFIX,str)
> #else
> #define SYMBOL(str) #str
> #endif
>
That still needs double expansion.
> I'm willing to make these changes, but I want to first be sure that
> I'm not missing an easier fix.
IMO, it's clearer to separate the concerns -- concatenation
and final stringification.
Start with the usual concatenation:
#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
Then add a stringification layer:
#define STR1(s) #s
#define STR(s) STR1(s)
#define SYMBOL(str) STR(SYMBOL1(str))
This way you have these expansions:
SYMBOL1(main) -> _main
SYMBOL(main) -> "_main"
Thanks,
Pedro Alves