From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28909 invoked by alias); 8 Mar 2010 11:56:11 -0000 Received: (qmail 28882 invoked by uid 22791); 8 Mar 2010 11:56:09 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 08 Mar 2010 11:56:05 +0000 Received: (qmail 7752 invoked from network); 8 Mar 2010 11:56:03 -0000 Received: from unknown (HELO orlando.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 8 Mar 2010 11:56:03 -0000 From: Pedro Alves To: Joel Brobecker Subject: Re: Automatically replace shared library extensions on Symbian Date: Mon, 08 Mar 2010 11:56:00 -0000 User-Agent: KMail/1.12.2 (Linux/2.6.31-19-generic; KDE/4.3.2; x86_64; ; ) Cc: gdb-patches@sourceware.org, Daniel Jacobowitz References: <201003051846.23406.pedro@codesourcery.com> <20100308045415.GB3081@adacore.com> In-Reply-To: <20100308045415.GB3081@adacore.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201003081156.00117.pedro@codesourcery.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-03/txt/msg00304.txt.bz2 On Monday 08 March 2010 04:54:15, Joel Brobecker wrote: > > +# If non-empty, this is a file extension that will be opened in place > > +# of the file extension reported by the shared library list. > > +v:const char *:solib_symbols_extension:::::::pstring (gdbarch->solib_symbols_extension) > > Would you mind expanding the commend above to explain that Symbian OS > is one example where this can be useful, and why? Basically, the current > description is a bit short, and I also found the paragraph describing > what happens on Symbian to be very interesting and useful... I sure don't. > Another option for preserving the description of what happens on Symbian OS > is to provide it at the location where you call set_solib_symbols_extension, > but it might be more difficult for someone working on a different architecture > having the same problem and looking for the gdbarch method that would allow > him to solve his problem? How about this? I extended the comment a bit in gdbarch.sh, avoiding too much target speficic info there, and described better the symbian specific case at the callback's call site. +# If non-empty, this is a file extension that will be opened in place +# of the file extension reported by the shared library list. +# +# This is most useful for toolchains that use a post-linker tool, +# where the names of the files ran on the target differ in extension +# compared to the names of the files GDB should load for debug info. +v:const char *:solib_symbols_extension:::::::pstring (gdbarch->solib_symbols_extension) + /* On this target, the toolchain outputs ELF files, with `sym' for + filename extension (e.g., `FOO.sym'); these are post-linker + processed into PE-ish DLLs (e.g., `FOO.dll'), and its these that + are actually copied to and ran on the target. Naturally, when + listing shared libraries, Symbian stubs report the DLL filenames. + Setting this makes it so that GDB automatically looks for the + corresponding ELF files on the host's filesystem. */ + set_gdbarch_solib_symbols_extension (gdbarch, "sym"); I think the mention of the post-linker in gdbarch.sh should be enough to ring a bell to someone looking for something like this. -- Pedro Alves 2010-03-08 Daniel Jacobowitz Pedro Alves gdb/ * solib.c (solib_find): Replace extension if solib_symbols_extension set in the target gdbarch. * arm-symbian-tdep.c (arm_symbian_init_abi): Set solib_symbols_extension to "sym". * gdbarch.sh (solib_symbols_extension): New variable. (pstring): New function. * gdbarch.h, gdbarch.c: Regenerate. --- gdb/arm-symbian-tdep.c | 9 +++++++++ gdb/gdbarch.c | 29 +++++++++++++++++++++++++++++ gdb/gdbarch.h | 10 ++++++++++ gdb/gdbarch.sh | 16 ++++++++++++++++ gdb/solib.c | 24 ++++++++++++++++++++++++ 5 files changed, 88 insertions(+) Index: src/gdb/solib.c =================================================================== --- src.orig/gdb/solib.c 2010-03-05 19:24:51.000000000 +0000 +++ src/gdb/solib.c 2010-03-08 11:14:56.000000000 +0000 @@ -150,6 +150,30 @@ solib_find (char *in_pathname, int *fd) int found_file = -1; char *temp_pathname = NULL; int gdb_sysroot_is_empty; + const char *solib_symbols_extension + = gdbarch_solib_symbols_extension (target_gdbarch); + + /* If solib_symbols_extension is set, replace the file's + extension. */ + if (solib_symbols_extension) + { + char *p = in_pathname + strlen (in_pathname); + while (p > in_pathname && *p != '.') + p--; + + if (*p == '.') + { + char *new_pathname; + + new_pathname = alloca (p - in_pathname + 1 + + strlen (solib_symbols_extension) + 1); + memcpy (new_pathname, in_pathname, p - in_pathname + 1); + strcpy (new_pathname + (p - in_pathname) + 1, + solib_symbols_extension); + + in_pathname = new_pathname; + } + } gdb_sysroot_is_empty = (gdb_sysroot == NULL || *gdb_sysroot == 0); Index: src/gdb/arm-symbian-tdep.c =================================================================== --- src.orig/gdb/arm-symbian-tdep.c 2010-03-05 19:24:51.000000000 +0000 +++ src/gdb/arm-symbian-tdep.c 2010-03-08 11:43:17.000000000 +0000 @@ -69,6 +69,15 @@ arm_symbian_init_abi (struct gdbarch_inf /* Shared library handling. */ set_gdbarch_skip_trampoline_code (gdbarch, arm_symbian_skip_trampoline_code); + /* On this target, the toolchain outputs ELF files, with `sym' for + filename extension (e.g., `FOO.sym'); these are post-linker + processed into PE-ish DLLs (e.g., `FOO.dll'), and its these that + are actually copied to and ran on the target. Naturally, when + listing shared libraries, Symbian stubs report the DLL filenames. + Setting this makes it so that GDB automatically looks for the + corresponding ELF files on the host's filesystem. */ + set_gdbarch_solib_symbols_extension (gdbarch, "sym"); + set_solib_ops (gdbarch, &solib_target_so_ops); } Index: src/gdb/gdbarch.sh =================================================================== --- src.orig/gdb/gdbarch.sh 2010-03-08 00:55:44.000000000 +0000 +++ src/gdb/gdbarch.sh 2010-03-08 11:46:24.000000000 +0000 @@ -774,6 +774,14 @@ v:const char *:qsupported:::0:0::0:gdbar f:const char *:auto_charset:void::default_auto_charset:default_auto_charset::0 # Return the "auto" target wide charset. f:const char *:auto_wide_charset:void::default_auto_wide_charset:default_auto_wide_charset::0 + +# If non-empty, this is a file extension that will be opened in place +# of the file extension reported by the shared library list. +# +# This is most useful for toolchains that use a post-linker tool, +# where the names of the files ran on the target differ in extension +# compared to the names of the files GDB should load for debug info. +v:const char *:solib_symbols_extension:::::::pstring (gdbarch->solib_symbols_extension) EOF } @@ -1245,6 +1253,14 @@ pformat (const struct floatformat **form return format[0]->name; } +static const char * +pstring (const char *string) +{ + if (string == NULL) + return "(null)"; + return string; +} + EOF # gdbarch open the gdbarch object Index: src/gdb/gdbarch.c =================================================================== --- src.orig/gdb/gdbarch.c 2010-03-08 00:55:44.000000000 +0000 +++ src/gdb/gdbarch.c 2010-03-08 11:47:03.000000000 +0000 @@ -77,6 +77,14 @@ pformat (const struct floatformat **form return format[0]->name; } +static const char * +pstring (const char *string) +{ + if (string == NULL) + return "(null)"; + return string; +} + /* Maintain the struct gdbarch object */ @@ -255,6 +263,7 @@ struct gdbarch const char * qsupported; gdbarch_auto_charset_ftype *auto_charset; gdbarch_auto_wide_charset_ftype *auto_wide_charset; + const char * solib_symbols_extension; }; @@ -401,6 +410,7 @@ struct gdbarch startup_gdbarch = 0, /* qsupported */ default_auto_charset, /* auto_charset */ default_auto_wide_charset, /* auto_wide_charset */ + 0, /* solib_symbols_extension */ /* startup_gdbarch() */ }; @@ -1148,6 +1158,9 @@ gdbarch_dump (struct gdbarch *gdbarch, s "gdbarch_dump: sofun_address_maybe_missing = %s\n", plongest (gdbarch->sofun_address_maybe_missing)); fprintf_unfiltered (file, + "gdbarch_dump: solib_symbols_extension = %s\n", + pstring (gdbarch->solib_symbols_extension)); + fprintf_unfiltered (file, "gdbarch_dump: sp_regnum = %s\n", plongest (gdbarch->sp_regnum)); fprintf_unfiltered (file, @@ -3647,6 +3660,22 @@ set_gdbarch_auto_wide_charset (struct gd gdbarch->auto_wide_charset = auto_wide_charset; } +const char * +gdbarch_solib_symbols_extension (struct gdbarch *gdbarch) +{ + gdb_assert (gdbarch != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_solib_symbols_extension called\n"); + return gdbarch->solib_symbols_extension; +} + +void +set_gdbarch_solib_symbols_extension (struct gdbarch *gdbarch, + const char * solib_symbols_extension) +{ + gdbarch->solib_symbols_extension = solib_symbols_extension; +} + /* Keep a registry of per-architecture data-pointers required by GDB modules. */ Index: src/gdb/gdbarch.h =================================================================== --- src.orig/gdb/gdbarch.h 2010-03-08 00:55:44.000000000 +0000 +++ src/gdb/gdbarch.h 2010-03-08 11:46:59.000000000 +0000 @@ -940,6 +940,16 @@ typedef const char * (gdbarch_auto_wide_ extern const char * gdbarch_auto_wide_charset (struct gdbarch *gdbarch); extern void set_gdbarch_auto_wide_charset (struct gdbarch *gdbarch, gdbarch_auto_wide_charset_ftype *auto_wide_charset); +/* If non-empty, this is a file extension that will be opened in place + of the file extension reported by the shared library list. + + This is most useful for toolchains that use a post-linker tool, + where the names of the files ran on the target differ in extension + compared to the names of the files GDB should load for debug info. */ + +extern const char * gdbarch_solib_symbols_extension (struct gdbarch *gdbarch); +extern void set_gdbarch_solib_symbols_extension (struct gdbarch *gdbarch, const char * solib_symbols_extension); + /* Definition for an unknown syscall, used basically in error-cases. */ #define UNKNOWN_SYSCALL (-1)