From: Aleksandar Ristovski <aristovski@qnx.com>
To: gdb@sources.redhat.com
Subject: linkmap from PT_DYNAMIC
Date: Thu, 16 Oct 2008 20:57:00 -0000 [thread overview]
Message-ID: <gd89q1$k3h$1@ger.gmane.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 702 bytes --]
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
[-- Attachment #2: solib-svr4.c-lmfromPT_DYNAMIC.20081016.diff --]
[-- Type: text/x-patch, Size: 2664 bytes --]
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)
next reply other threads:[~2008-10-16 20:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-16 20:57 Aleksandar Ristovski [this message]
2008-10-17 15:22 ` Ulrich Weigand
2008-10-17 15:31 ` Aleksandar Ristovski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='gd89q1$k3h$1@ger.gmane.org' \
--to=aristovski@qnx.com \
--cc=gdb@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox