Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Automatically replace shared library extensions on Symbian
@ 2010-03-05 18:46 Pedro Alves
  2010-03-08  4:54 ` Joel Brobecker
  0 siblings, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2010-03-05 18:46 UTC (permalink / raw)
  To: gdb-patches, Daniel Jacobowitz

SymbianOS' debug info files are elf files.  These are post-linker
processed into PE-ish dlls, and its these that are actually ran
on the target, so symbian stubs report dll filenames as loaded
to GDB.  This patch makes it so that GDB automatically finds
the symbol files on the host's filesystem, as they'll be called
FOO.sym, not FOO.dll.

In course of preparing this for upstream, I've made it a
gdbarch setting, so that a multi-arch gdb doesn't do the
replacing for other archs not symbian.  I've resisted
making this tweakable via a user visible setting, as we
did't find a need for it yet, thought I could see that
possibly being useful to other post-linker processed
targets.  Something that can always be added on top, I
think.

What do you think of this?

-- 
Pedro Alves

2010-03-05  Daniel Jacobowitz  <dan@codesourcery.com>
	   Pedro Alves  <pedro@codesourcery.com>

	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 |    1 +
 gdb/gdbarch.c          |   29 +++++++++++++++++++++++++++++
 gdb/gdbarch.h          |    6 ++++++
 gdb/gdbarch.sh         |   12 ++++++++++++
 gdb/solib.c            |   24 ++++++++++++++++++++++++
 5 files changed, 72 insertions(+)

Index: src/gdb/solib.c
===================================================================
--- src.orig/gdb/solib.c	2010-03-05 18:00:39.000000000 +0000
+++ src/gdb/solib.c	2010-03-05 18:05:44.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 18:00:39.000000000 +0000
+++ src/gdb/arm-symbian-tdep.c	2010-03-05 18:00:53.000000000 +0000
@@ -68,6 +68,7 @@ arm_symbian_init_abi (struct gdbarch_inf
 
   /* Shared library handling.  */
   set_gdbarch_skip_trampoline_code (gdbarch, arm_symbian_skip_trampoline_code);
+  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-05 18:00:39.000000000 +0000
+++ src/gdb/gdbarch.sh	2010-03-05 18:00:53.000000000 +0000
@@ -769,6 +769,10 @@ m:int:fast_tracepoint_valid_at:CORE_ADDR
 
 # Not NULL if a target has additonal field for qSupported.
 v:const char *:qsupported:::0:0::0:gdbarch->qsupported
+
+# 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)
 EOF
 }
 
@@ -1240,6 +1244,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-05 18:00:39.000000000 +0000
+++ src/gdb/gdbarch.c	2010-03-05 18:00:53.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 */
 
@@ -253,6 +261,7 @@ struct gdbarch
   gdbarch_has_shared_address_space_ftype *has_shared_address_space;
   gdbarch_fast_tracepoint_valid_at_ftype *fast_tracepoint_valid_at;
   const char * qsupported;
+  const char * solib_symbols_extension;
 };
 
 
@@ -397,6 +406,7 @@ struct gdbarch startup_gdbarch =
   default_has_shared_address_space,  /* has_shared_address_space */
   default_fast_tracepoint_valid_at,  /* fast_tracepoint_valid_at */
   0,  /* qsupported */
+  0,  /* solib_symbols_extension */
   /* startup_gdbarch() */
 };
 
@@ -1134,6 +1144,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,
@@ -3599,6 +3612,22 @@ set_gdbarch_qsupported (struct gdbarch *
   gdbarch->qsupported = qsupported;
 }
 
+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-05 18:00:39.000000000 +0000
+++ src/gdb/gdbarch.h	2010-03-05 18:00:53.000000000 +0000
@@ -928,6 +928,12 @@ extern void set_gdbarch_fast_tracepoint_
 extern const char * gdbarch_qsupported (struct gdbarch *gdbarch);
 extern void set_gdbarch_qsupported (struct gdbarch *gdbarch, const char * qsupported);
 
+/* If non-empty, this is a file extension that will be opened in place
+   of the file extension reported by the shared library list. */
+
+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)
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Automatically replace shared library extensions on Symbian
  2010-03-05 18:46 Automatically replace shared library extensions on Symbian Pedro Alves
@ 2010-03-08  4:54 ` Joel Brobecker
  2010-03-08 11:56   ` Pedro Alves
  0 siblings, 1 reply; 5+ messages in thread
From: Joel Brobecker @ 2010-03-08  4:54 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Daniel Jacobowitz

> What do you think of this?

A gdbarch setting sounds indeed better to me, as the debugger is then
doing the right thing automatically.

> 2010-03-05  Daniel Jacobowitz  <dan@codesourcery.com>
> 	   Pedro Alves  <pedro@codesourcery.com>
> 
> 	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.

No real comment on the code, except maybe:

> +
> +# 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...

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?

-- 
Joel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Automatically replace shared library extensions on Symbian
  2010-03-08  4:54 ` Joel Brobecker
@ 2010-03-08 11:56   ` Pedro Alves
  2010-03-08 18:29     ` Joel Brobecker
  0 siblings, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2010-03-08 11:56 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches, Daniel Jacobowitz

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  <dan@codesourcery.com>
	    Pedro Alves  <pedro@codesourcery.com>

	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)
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Automatically replace shared library extensions on Symbian
  2010-03-08 11:56   ` Pedro Alves
@ 2010-03-08 18:29     ` Joel Brobecker
  2010-03-08 19:31       ` Pedro Alves
  0 siblings, 1 reply; 5+ messages in thread
From: Joel Brobecker @ 2010-03-08 18:29 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Daniel Jacobowitz

> 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.  

Looks GREAT! :)

Thank you adding them.  Just three little nits I noticed...

>  +# 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
                                   ^^^ run (to run, ran, run)
>  +# 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
                                                           ^^^ it's
>  +     are actually copied to and ran on the target.  Naturally, when
                                    ^^^ run
>  +     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.  */


-- 
Joel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Automatically replace shared library extensions on Symbian
  2010-03-08 18:29     ` Joel Brobecker
@ 2010-03-08 19:31       ` Pedro Alves
  0 siblings, 0 replies; 5+ messages in thread
From: Pedro Alves @ 2010-03-08 19:31 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches, Daniel Jacobowitz

On Monday 08 March 2010 18:28:40, 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.
> >  +#
> >  +# 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
>                                    ^^^ run (to run, ran, run)
> >  +# 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
>                                                            ^^^ it's
> >  +     are actually copied to and ran on the target.  Naturally, when
>                                     ^^^ run
> >  +     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.  */

Thanks Joel, for the review and for pointing these out.  I've fixed
these and applied the patch, as below.

-- 
Pedro Alves

2010-03-08  Daniel Jacobowitz  <dan@codesourcery.com>
	    Pedro Alves  <pedro@codesourcery.com>

	gdb/
	* solib.c (solib_find): Replace extension if
	solib_symbols_extension is 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 19:19:57.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 it's these that
+     are actually copied to and run 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 19:20:10.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 run 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 19:20:48.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 run 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)
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-03-08 19:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-05 18:46 Automatically replace shared library extensions on Symbian Pedro Alves
2010-03-08  4:54 ` Joel Brobecker
2010-03-08 11:56   ` Pedro Alves
2010-03-08 18:29     ` Joel Brobecker
2010-03-08 19:31       ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox