* linkmap from PT_DYNAMIC
@ 2008-10-16 20:57 Aleksandar Ristovski
2008-10-17 15:22 ` Ulrich Weigand
0 siblings, 1 reply; 3+ messages in thread
From: Aleksandar Ristovski @ 2008-10-16 20:57 UTC (permalink / raw)
To: gdb
[-- 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)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: linkmap from PT_DYNAMIC
2008-10-16 20:57 linkmap from PT_DYNAMIC Aleksandar Ristovski
@ 2008-10-17 15:22 ` Ulrich Weigand
2008-10-17 15:31 ` Aleksandar Ristovski
0 siblings, 1 reply; 3+ messages in thread
From: Ulrich Weigand @ 2008-10-17 15:22 UTC (permalink / raw)
To: Aleksandar Ristovski; +Cc: gdb
Aleksandar Ristovski wrote:
> 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.
Well, the scan_dyntag_auxv routine I added already does
attempt to access PT_DYNAMIC if there is no .dynamic
section. In fact, it should work even if you do not
have any executable file at all, as it directly reads
the program headers from the target.
Is there some reason why this doesn't work for you?
Bye,
Ulrich
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: linkmap from PT_DYNAMIC
2008-10-17 15:22 ` Ulrich Weigand
@ 2008-10-17 15:31 ` Aleksandar Ristovski
0 siblings, 0 replies; 3+ messages in thread
From: Aleksandar Ristovski @ 2008-10-17 15:31 UTC (permalink / raw)
To: gdb
Ulrich Weigand wrote:
> Well, the scan_dyntag_auxv routine I added already does
> attempt to access PT_DYNAMIC if there is no .dynamic
> section. In fact, it should work even if you do not
> have any executable file at all, as it directly reads
> the program headers from the target.
>
> Is there some reason why this doesn't work for you?
Actually I don't know if it will work, I implemented this on
6.7 code and then applied to sources from head gdb. I missed
your auxv patch. I will check it out.
Thanks for the info,
Aleksandar
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-10-17 15:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-16 20:57 linkmap from PT_DYNAMIC Aleksandar Ristovski
2008-10-17 15:22 ` Ulrich Weigand
2008-10-17 15:31 ` Aleksandar Ristovski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox