* bfd client access to PT_NOTE program segment
@ 1999-09-20 20:54 fnf
1999-09-22 20:04 ` bfd client access to PT_NOTE program segment (patch included) fnf
0 siblings, 1 reply; 3+ messages in thread
From: fnf @ 1999-09-20 20:54 UTC (permalink / raw)
To: binutils; +Cc: fnf
I've been looking for an easy way for a bfd client such as gdb to
identify which program segment in an ELF format core file is the
PT_NOTE section.
One somewhat obvious way is to change the synthetic segment names that
BFD generates to something more meaningful than "segmentN" and then
select the BFD section based on the name. The following patch to
elf.c (non context, for discussion purposes only) seems to do the job:
1403c1406,1417
< sprintf (namebuf, split ? "segment%da" : "segment%d", index);
---
> switch (hdr->p_type)
> {
> case PT_NULL: s = "null"; break;
> case PT_LOAD: s = "load"; break;
> case PT_DYNAMIC: s = "dynamic"; break;
> case PT_INTERP: s = "interp"; break;
> case PT_NOTE: s = "note"; break;
> case PT_SHLIB: s = "shlib"; break;
> case PT_PHDR: s = "phdr"; break;
> default: s = "segment"; break;
> }
> sprintf (namebuf, "%s%d%s", s, index, split ? "a" : "");
1434c1448
< sprintf (namebuf, "segment%db", index);
---
> sprintf (namebuf, "%s%d%b", s, index);
Then objdump produces (abbreviated) something like:
0 note0 000004fc 00000000 00000000 00000174 2**0
1 .reg/2632 00000044 00000000 00000000 000001cc 2**2
2 .reg 00000044 00000000 00000000 000001cc 2**2
3 load1 00000000 08048000 00000000 00001000 2**0
4 load2 00001000 08049000 00000000 00001000 2**0
5 load3 00000000 40000000 00000000 00002000 2**0
6 load4 00001000 40012000 00000000 00002000 2**0
7 load5 00001000 40013000 00000000 00003000 2**0
8 load6 00000000 4001a000 00000000 00004000 2**0
9 load7 00005000 40100000 00000000 00004000 2**0
10 load8 00003000 40105000 00000000 00009000 2**0
11 load9 00002000 bfffe000 00000000 0000c000 2**0
Comments about the idea of trying to generate more meaningful
BFD section names? Of using them in a BFD client? Any better
suggestions for identifying the PT_NOTE segment?
-Fred
^ permalink raw reply [flat|nested] 3+ messages in thread
* bfd client access to PT_NOTE program segment (patch included)
1999-09-20 20:54 bfd client access to PT_NOTE program segment fnf
@ 1999-09-22 20:04 ` fnf
1999-09-24 10:09 ` Richard Henderson
0 siblings, 1 reply; 3+ messages in thread
From: fnf @ 1999-09-22 20:04 UTC (permalink / raw)
To: binutils; +Cc: fnf
I didn't get any feedback, pro or con, to my previous email, so
I assume there are no real objections to making this change.
Would someone with access to the repository please apply this
patch? It won't hurt my feelings if you see a need to tweak
it slightly for some reason. :-)
-Fred
===================================================================
1999-09-22 Fred Fish <fnf@cygnus.com>
* elf.c (bfd_section_from_phdr): Add typename variable. Use p_type
to initialize it to something meaningful. Then use it to generate
more useful segment names.
Index: elf.c
===================================================================
RCS file: /cvs/binutils/binutils/bfd/elf.c,v
retrieving revision 1.16
diff -c -p -r1.16 elf.c
*** elf.c 1999/09/04 17:07:46 1.16
--- elf.c 1999/09/23 02:57:39
*************** bfd_section_from_phdr (abfd, hdr, index)
*** 1394,1406 ****
{
asection *newsect;
char *name;
char namebuf[64];
int split;
split = ((hdr->p_memsz > 0)
&& (hdr->p_filesz > 0)
&& (hdr->p_memsz > hdr->p_filesz));
! sprintf (namebuf, split ? "segment%da" : "segment%d", index);
name = bfd_alloc (abfd, strlen (namebuf) + 1);
if (!name)
return false;
--- 1394,1418 ----
{
asection *newsect;
char *name;
+ char *typename;
char namebuf[64];
int split;
split = ((hdr->p_memsz > 0)
&& (hdr->p_filesz > 0)
&& (hdr->p_memsz > hdr->p_filesz));
! switch (hdr->p_type)
! {
! case PT_NULL: typename = "null"; break;
! case PT_LOAD: typename = "load"; break;
! case PT_DYNAMIC: typename = "dynamic"; break;
! case PT_INTERP: typename = "interp"; break;
! case PT_NOTE: typename = "note"; break;
! case PT_SHLIB: typename = "shlib"; break;
! case PT_PHDR: typename = "phdr"; break;
! default: typename = "segment"; break;
! }
! sprintf (namebuf, "%s%d%s", typename, index, split ? "a" : "");
name = bfd_alloc (abfd, strlen (namebuf) + 1);
if (!name)
return false;
*************** bfd_section_from_phdr (abfd, hdr, index)
*** 1431,1437 ****
if (split)
{
! sprintf (namebuf, "segment%db", index);
name = bfd_alloc (abfd, strlen (namebuf) + 1);
if (!name)
return false;
--- 1443,1449 ----
if (split)
{
! sprintf (namebuf, "%s%db", typename, index);
name = bfd_alloc (abfd, strlen (namebuf) + 1);
if (!name)
return false;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: bfd client access to PT_NOTE program segment (patch included)
1999-09-22 20:04 ` bfd client access to PT_NOTE program segment (patch included) fnf
@ 1999-09-24 10:09 ` Richard Henderson
0 siblings, 0 replies; 3+ messages in thread
From: Richard Henderson @ 1999-09-24 10:09 UTC (permalink / raw)
To: fnf; +Cc: binutils, fnf
On Wed, Sep 22, 1999 at 08:10:10PM -0700, fnf@www.ninemoons.com wrote:
> 1999-09-22 Fred Fish <fnf@cygnus.com>
>
> * elf.c (bfd_section_from_phdr): Add typename variable. Use p_type
> to initialize it to something meaningful. Then use it to generate
> more useful segment names.
Applied.
r~
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1999-09-24 10:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-20 20:54 bfd client access to PT_NOTE program segment fnf
1999-09-22 20:04 ` bfd client access to PT_NOTE program segment (patch included) fnf
1999-09-24 10:09 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).