[patch 12/15] PIE: Support loading PIEs from core files

Jan Kratochvil jan.kratochvil@redhat.com
Thu Jan 14 21:09:00 GMT 2010


On Sat, 09 Jan 2010 00:52:06 +0100, Tom Tromey wrote:
> Having the debug files be objfiles in their own right seems strange to
> me.  Is there a situation where they are used "directly", instead of
> being used as extra data for their parent objfile?

That's a nice idea for some cleanup patch.  The symbol resource should not be
the object directly representing an on-disk file.


> Jan> gdb/
> Jan> 	* solib-svr4.c (scan_dyntag): Remove variable dyn_addr.  New variable
> Jan> 	target_section.  Find SECT in current_target_sections, gdb_assert it.
> Jan> 	(elf_lookup_lib_symbol): Pass the binary file if given symfile_objfile.
> Jan> 	New variable abfd.
> Jan> 	* symtab.c (lookup_objfile_from_block): Return the binary file instead
> Jan> 	of separate debug info file.
> Jan> gdb/testsuite/
> Jan> 	* gdb.base/break-interp.exp (test_core): New proc.
> Jan> 	(test_ld): Call it.
> 
> This ok.  Thanks.

Checked-in.


Thanks,
Jan


http://sourceware.org/ml/gdb-cvs/2010-01/msg00123.html

--- src/gdb/ChangeLog	2010/01/14 21:01:24	1.11248
+++ src/gdb/ChangeLog	2010/01/14 21:09:04	1.11249
@@ -1,5 +1,14 @@
 2010-01-14  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
+	* solib-svr4.c (scan_dyntag): Remove variable dyn_addr.  New variable
+	target_section.  Find SECT in current_target_sections, gdb_assert it.
+	(elf_lookup_lib_symbol): Pass the binary file if given symfile_objfile.
+	New variable abfd.
+	* symtab.c (lookup_objfile_from_block): Return the binary file instead
+	of separate debug info file.
+
+2010-01-14  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
 	Support PIEs with no symfile_objfile.
 	* exec.c (print_section_info <abfd == exec_bfd>): Relocate Entry point.
 	* solib-svr4.c (svr4_relocate_main_executable <exec_bfd>): New block.
--- src/gdb/solib-svr4.c	2010/01/14 21:01:24	1.112
+++ src/gdb/solib-svr4.c	2010/01/14 21:09:04	1.113
@@ -568,11 +568,12 @@
 {
   int arch_size, step, sect_size;
   long dyn_tag;
-  CORE_ADDR dyn_ptr, dyn_addr;
+  CORE_ADDR dyn_ptr;
   gdb_byte *bufend, *bufstart, *buf;
   Elf32_External_Dyn *x_dynp_32;
   Elf64_External_Dyn *x_dynp_64;
   struct bfd_section *sect;
+  struct target_section *target_section;
 
   if (abfd == NULL)
     return 0;
@@ -588,7 +589,13 @@
   sect = bfd_get_section_by_name (abfd, ".dynamic");
   if (sect == NULL)
     return 0;
-  dyn_addr = bfd_section_vma (abfd, sect);
+
+  for (target_section = current_target_sections->sections;
+       target_section < current_target_sections->sections_end;
+       target_section++)
+    if (sect == target_section->the_bfd_section)
+      break;
+  gdb_assert (target_section < current_target_sections->sections_end);
 
   /* Read in .dynamic from the BFD.  We will get the actual value
      from memory later.  */
@@ -630,7 +637,7 @@
 	     CORE_ADDR ptr_addr;
 
 	     ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
-	     ptr_addr = dyn_addr + (buf - bufstart) + arch_size / 8;
+	     ptr_addr = target_section->addr + (buf - bufstart) + arch_size / 8;
 	     if (target_read_memory (ptr_addr, ptr_buf, arch_size / 8) == 0)
 	       dyn_ptr = extract_typed_address (ptr_buf, ptr_type);
 	     *ptr = dyn_ptr;
@@ -1951,8 +1958,19 @@
 		       const char *linkage_name,
 		       const domain_enum domain)
 {
-  if (objfile->obfd == NULL
-     || scan_dyntag (DT_SYMBOLIC, objfile->obfd, NULL) != 1)
+  bfd *abfd;
+
+  if (objfile == symfile_objfile)
+    abfd = exec_bfd;
+  else
+    {
+      /* OBJFILE should have been passed as the non-debug one.  */
+      gdb_assert (objfile->separate_debug_objfile_backlink == NULL);
+
+      abfd = objfile->obfd;
+    }
+
+  if (abfd == NULL || scan_dyntag (DT_SYMBOLIC, abfd, NULL) != 1)
     return NULL;
 
   return lookup_global_symbol_from_objfile
--- src/gdb/symtab.c	2010/01/06 10:11:04	1.222
+++ src/gdb/symtab.c	2010/01/14 21:09:04	1.223
@@ -1470,7 +1470,12 @@
   /* Go through SYMTABS.  */
   ALL_SYMTABS (obj, s)
     if (block == BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK))
-      return obj;
+      {
+	if (obj->separate_debug_objfile_backlink)
+	  obj = obj->separate_debug_objfile_backlink;
+
+	return obj;
+      }
 
   return NULL;
 }
--- src/gdb/testsuite/ChangeLog	2010/01/14 21:04:52	1.2085
+++ src/gdb/testsuite/ChangeLog	2010/01/14 21:09:04	1.2086
@@ -1,5 +1,10 @@
 2010-01-14  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
+	* gdb.base/break-interp.exp (test_core): New proc.
+	(test_ld): Call it.
+
+2010-01-14  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
 	* gdb.base/break-interp-main.c, gdb.base/break-interp-lib.c: New.
 	* gdb.base/break-interp.exp: Exit on skip_shlib_tests.  Change $srcfile.
 	New variables $binfile_lib and $srcfile_lib.  Call get_compiler_info
--- src/gdb/testsuite/gdb.base/break-interp.exp	2010/01/14 21:04:53	1.3
+++ src/gdb/testsuite/gdb.base/break-interp.exp	2010/01/14 21:09:05	1.4
@@ -237,6 +237,27 @@
     }
 }
 
+proc test_core {file} {
+    global srcdir subdir gdb_prompt
+
+    set corefile [core_find $file]
+    if {$corefile == ""} {
+	return
+    }
+
+    gdb_exit
+    gdb_start
+    # Clear it to never find any separate debug infos in $debug_root.
+    gdb_test "set debug-file-directory" "" "set debug-file-directory for core"
+    gdb_reinitialize_dir $srcdir/$subdir
+    gdb_load $file
+
+    # Do not check the binary filename as it may be truncated.
+    gdb_test "core-file $corefile" "Core was generated by .*\r\n#0 .*" "core loaded"
+
+    gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "core main bt"
+}
+
 proc test_ld {file ifmain trynosym} {
     global srcdir subdir gdb_prompt
 
@@ -259,6 +280,8 @@
 	reach "libfunc" continue
 
 	gdb_test "bt" "#0 +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#1 +\[^\r\n\]*\\mmain\\M.*" "main bt"
+
+	test_core $file
     }
 
     if !$trynosym {



More information about the Gdb-patches mailing list