External debug symbols

Alexander Larsson alexl@redhat.com
Tue Aug 20 12:50:00 GMT 2002


Hi

I've been experimenting some with removing debug information from binaries 
and placing it in a separate file, and then having gdb automatically load 
these if availible. (The goal here is to package debug information in 
separate packages that can be on-demand downloaded and installed.)

I have written a libelf based application that takes an elf file, splits 
out debug information to a separate file, strips the original file and 
adds a ".debuglink" section to the stripped file. This section contains 
the basename of the filename of the debug file and a crc32 checksum of it.

I've also written an "unstrip" application that puts together the original 
ELF file from the stripped one and the debug file (and some extra 
information I put in a section of the debug file). This produces a bitwise 
identical file to the original.

My next step is to make gdb automatically follow ".debuglink" sections so 
that i don't have to use the unstrip application. Attached to this mail is 
a patch that implements a "badhack" which seems to almost work. In order 
for it to work I had to add all the original section headers to the debug 
file (but SHT_NOBITS, so they take no space). It seems to work for the 
main binary, but setting breakpoints in libraries doesn't work. I think it 
gets the base address wrong or something.

What are your opinions about this solution? Has anything like this been 
done or tought of before? I'm pretty scared of the gdb codebase (looked at 
it for the first time today), so my solution is probably both buggy and 
generally wrong, tips of other ways to do this are appreciated.

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl@redhat.com    alla@lysator.liu.se 
He's a benighted Jewish romance novelist plagued by the memory of his family's 
brutal murder. She's a time-travelling Bolivian traffic cop with only herself 
to blame. They fight crime! 
-------------- next part --------------
diff -ur gdb-5.2.1/gdb/objfiles.c gdb-5.2.1.separate_debug_symbols/gdb/objfiles.c
--- gdb-5.2.1/gdb/objfiles.c	Thu Dec  6 21:59:11 2001
+++ gdb-5.2.1.separate_debug_symbols/gdb/objfiles.c	Tue Aug 20 15:32:15 2002
@@ -397,6 +397,11 @@
 void
 free_objfile (struct objfile *objfile)
 {
+  if (objfile->separate_debug_objfile)
+    {
+      free_objfile (objfile->separate_debug_objfile);
+    }
+  
   /* First do any symbol file specific actions required when we are
      finished with a particular symbol file.  Note that if the objfile
      is using reusable symbol information (via mmalloc) then each of
Only in gdb-5.2.1.separate_debug_symbols/gdb: objfiles.c~
diff -ur gdb-5.2.1/gdb/objfiles.h gdb-5.2.1.separate_debug_symbols/gdb/objfiles.h
--- gdb-5.2.1/gdb/objfiles.h	Sat Jun 29 00:05:47 2002
+++ gdb-5.2.1.separate_debug_symbols/gdb/objfiles.h	Tue Aug 20 15:15:56 2002
@@ -409,6 +409,8 @@
     ExportEntry *export_list;
     int export_list_size;
 
+    struct objfile *separate_debug_objfile;
+    
     /* Place to stash various statistics about this objfile */
       OBJSTATS;
   };
diff -ur gdb-5.2.1/gdb/symfile.c gdb-5.2.1.separate_debug_symbols/gdb/symfile.c
--- gdb-5.2.1/gdb/symfile.c	Sat Jun 22 18:49:33 2002
+++ gdb-5.2.1.separate_debug_symbols/gdb/symfile.c	Tue Aug 20 16:15:33 2002
@@ -837,6 +837,7 @@
   struct objfile *objfile;
   struct partial_symtab *psymtab;
   bfd *abfd;
+  asection *sect = NULL;
 
   /* Open a bfd for the file, and give user a chance to burp if we'd be
      interactively wiping out any existing symbols.  */
@@ -926,6 +927,42 @@
   if (target_new_objfile_hook)
     target_new_objfile_hook (objfile);
 
+  
+  sect = bfd_get_section_by_name (objfile->obfd, ".debuglink");
+  if (sect)
+    {
+      bfd_size_type size = bfd_section_size (objfile->obfd, sect);
+      char *debuglink;
+      char *dir;
+      char *debugfile;
+      char *name_copy;
+      char *p;
+      
+      debuglink = alloca (size);
+      bfd_get_section_contents (objfile->obfd, sect, debuglink,
+				(file_ptr)0, (bfd_size_type)size);
+
+      dir = xstrdup (name);
+      p = strrchr (dir, '/');
+      if (p != NULL)
+	{
+	  *(p+1) = 0;
+	  
+	  debugfile = alloca ( strlen (dir) + strlen (debuglink) + 1);
+	  strcpy (debugfile, dir);
+	  strcat (debugfile, debuglink);
+	}
+      else
+	{
+	  debugfile = alloca ( strlen (debuglink) + 1);
+	  strcpy (debugfile, debuglink);
+	}
+      xfree (dir);
+      
+      printf_filtered ("loading separate debug info from '%s'\n", debugfile);
+      objfile->separate_debug_objfile = symbol_file_add (debugfile, from_tty, addrs, 0, flags);
+    }
+  
   return (objfile);
 }
 


More information about the Gdb mailing list