This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

linkmap from PT_DYNAMIC


Hello,

Currently GDB will scan dyntags from dynamic section only (solib-svr4.c:scan_dyntag). However, if the section header does not exist (for example it has been stripped away) then gdb gives up, even though the section will be present in the form of dynamic segment.

When examining core files when having only a stripped executable (stripped in such a way that it does not contain section headers), gdb will not be able to do much.

The attached patch will resort to using PT_DYNAMIC to get dynamic section and scan dyntag. The patch will only change default (current) behaviour if bfd_get_section_by_name returns NULL.

Any thoughts?

Thanks,

Aleksandar Ristovski
QNX Software Systems

Index: gdb/solib-svr4.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-svr4.c,v
retrieving revision 1.94
diff -u -p -r1.94 solib-svr4.c
--- gdb/solib-svr4.c	22 Sep 2008 15:20:08 -0000	1.94
+++ gdb/solib-svr4.c	16 Oct 2008 20:49:05 -0000
@@ -534,16 +534,55 @@ scan_dyntag (int dyntag, bfd *abfd, CORE
   /* Find the start address of the .dynamic section.  */
   sect = bfd_get_section_by_name (abfd, ".dynamic");
   if (sect == NULL)
-    return 0;
-  dyn_addr = bfd_section_vma (abfd, sect);
+    {
+      /* We do not give up here. We want to see if the bfd has elf info.
+	 Chances are, they do and in that case we can use PT_DYNAMIC segment
+	 header to get to the section address.
+	 Some NTO architectures will strip sections info altogether but
+	 PT_DYNAMIC will be there, if the executable is a dynamic exe.  */
+      if (abfd->tdata.elf_obj_data != NULL
+	  && abfd->tdata.elf_obj_data->phdr != NULL)
+	{
+	  /* We calculate everything needed for looping through
+	     dyntags.  */
 
-  /* Read in .dynamic from the BFD.  We will get the actual value
-     from memory later.  */
-  sect_size = bfd_section_size (abfd, sect);
-  buf = bufstart = alloca (sect_size);
-  if (!bfd_get_section_contents (abfd, sect,
-				 buf, 0, sect_size))
-    return 0;
+	  unsigned int index = 0;
+
+	  while (abfd->tdata.elf_obj_data->phdr[index].p_type != PT_NULL
+		 && abfd->tdata.elf_obj_data->phdr[index].p_type != PT_DYNAMIC)
+	    index++;
+
+	  if (abfd->tdata.elf_obj_data->phdr[index].p_type != PT_DYNAMIC)
+	    return 0;
+
+	  /* Setup sect_size, needed below.  */
+	  sect_size = arch_size * 10; /* Arbitrary size. We assume
+					 there will be at most 10 entries.
+					 The code below will check for
+					 DT_NULL anyway.  */
+	  dyn_addr = abfd->tdata.elf_obj_data->phdr[index].p_vaddr; 
+	  buf = bufstart = alloca (sect_size);
+	  /* Read this from memory as oposed to reading section contents
+	     from file. */
+	  if (target_read_memory (dyn_addr, buf, sect_size) != 0)
+	    return 0;
+	}
+      else
+	return 0;
+    }
+  else
+    {
+      /* There is .dynamic section, let default code take care of it. */
+      dyn_addr = bfd_section_vma (abfd, sect);
+
+      /* Read in .dynamic from the BFD.  We will get the actual value
+	 from memory later.  */
+      sect_size = bfd_section_size (abfd, sect);
+      buf = bufstart = alloca (sect_size);
+      if (!bfd_get_section_contents (abfd, sect,
+				     buf, 0, sect_size))
+	return 0;
+    }
 
   /* Iterate over BUF and scan for DYNTAG.  If found, set PTR and return.  */
   step = (arch_size == 32) ? sizeof (Elf32_External_Dyn)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]