* [PATCH] Further extend "maint info sections" cmd with ALLOBJ
@ 2001-12-20 14:35 Michael Snyder
2001-12-21 2:55 ` Pierre Muller
0 siblings, 1 reply; 6+ messages in thread
From: Michael Snyder @ 2001-12-20 14:35 UTC (permalink / raw)
To: gdb-patches
As a further extension, the "maint info sections" command
will now accept an argument "ALLOBJ" to iterate over all
known object files (which includes shared libraries.
You can now do (for instance):
(gdb) maint info sect .bss ALLOBJ
to see info on the .bss sections of all loaded object files.
2001-12-20 Michael Snyder <msnyder@redhat.com>
* maint.c (maintenance_info_sections): Accept new argument
'ALLOBJ', iterate over all object files.
(print_section_table): Delete. Replaced by:
(print_section_info): New function.
(print_bfd_section_info): New function.
(print_objfile_section_info): New function.
(_initialize_maint_commands): Add help for new features.
Index: maint.c
===================================================================
RCS file: /cvs/src/src/gdb/maint.c,v
retrieving revision 1.17
diff -p -r1.17 maint.c
*** maint.c 2001/12/20 21:03:03 1.17
--- maint.c 2001/12/20 22:27:53
*************** print_bfd_flags (flagword flags)
*** 259,293 ****
}
static void
! print_section_table (bfd *abfd, asection *asect, void *arg)
! {
! flagword flags;
! char *string = arg;
! flags = bfd_get_section_flags (abfd, asect);
if (string == NULL || *string == '\0' ||
! strstr (string, bfd_get_section_name (abfd, asect)) ||
match_bfd_flags (string, flags))
{
! /* FIXME-32x64: Need print_address_numeric with field width. */
! printf_filtered (" %s",
! local_hex_string_custom
! ((unsigned long) bfd_section_vma (abfd, asect),
! "08l"));
! printf_filtered ("->%s",
! local_hex_string_custom
! ((unsigned long) (bfd_section_vma (abfd, asect)
! + bfd_section_size (abfd, asect)),
! "08l"));
! printf_filtered (" at %s",
! local_hex_string_custom
! ((unsigned long) asect->filepos, "08l"));
! printf_filtered (": %s", bfd_section_name (abfd, asect));
!
! print_bfd_flags (flags);
!
! printf_filtered ("\n");
}
}
--- 259,312 ----
}
static void
! print_section_info (const char *name, flagword flags,
! CORE_ADDR addr, CORE_ADDR endaddr,
! unsigned long filepos)
! {
! /* FIXME-32x64: Need print_address_numeric with field width. */
! printf_filtered (" 0x%s", paddr (addr));
! printf_filtered ("->0x%s", paddr (endaddr));
! printf_filtered (" at 0x%s",
! local_hex_string_custom ((unsigned long) filepos, "08l"));
! printf_filtered (": %s", name);
! print_bfd_flags (flags);
! printf_filtered ("\n");
! }
!
! static void
! print_bfd_section_info (bfd *abfd,
! asection *asect,
! void *arg)
! {
! flagword flags = bfd_get_section_flags (abfd, asect);
! const char *name = bfd_section_name (abfd, asect);
!
! if (arg == NULL || *((char *) arg) == '\0' ||
! strstr ((char *) arg, name) ||
! match_bfd_flags ((char *) arg, flags))
! {
! CORE_ADDR addr, endaddr;
! addr = bfd_section_vma (abfd, asect);
! endaddr = addr + bfd_section_size (abfd, asect);
! print_section_info (name, flags, addr, endaddr, asect->filepos);
! }
! }
!
! static void
! print_objfile_section_info (bfd *abfd,
! struct obj_section *asect,
! char *string)
! {
! flagword flags = bfd_get_section_flags (abfd, asect->the_bfd_section);
! const char *name = bfd_section_name (abfd, asect->the_bfd_section);
if (string == NULL || *string == '\0' ||
! strstr (string, name) ||
match_bfd_flags (string, flags))
{
! print_section_info (name, flags, asect->addr, asect->endaddr,
! asect->the_bfd_section->filepos);
}
}
*************** maintenance_info_sections (char *arg, in
*** 301,307 ****
printf_filtered (" `%s', ", bfd_get_filename (exec_bfd));
wrap_here (" ");
printf_filtered ("file type %s.\n", bfd_get_target (exec_bfd));
! bfd_map_over_sections (exec_bfd, print_section_table, arg);
}
if (core_bfd)
--- 320,349 ----
printf_filtered (" `%s', ", bfd_get_filename (exec_bfd));
wrap_here (" ");
printf_filtered ("file type %s.\n", bfd_get_target (exec_bfd));
! if (arg && *arg && strstr (arg, "ALLOBJ"))
! {
! struct objfile *ofile;
! struct obj_section *osect;
!
! /* Only this function cares about the 'ALLOBJ' argument;
! if 'ALLOBJ' is the only argument, discard it rather than
! passing it down to print_objfile_section_info (which
! wouldn't know how to handle it). */
! if (strcmp (arg, "ALLOBJ") == 0)
! arg = NULL;
!
! ALL_OBJFILES (ofile)
! {
! printf_filtered (" Object file: %s\n",
! bfd_get_filename (ofile->obfd));
! ALL_OBJFILE_OSECTIONS (ofile, osect)
! {
! print_objfile_section_info (ofile->obfd, osect, arg);
! }
! }
! }
! else
! bfd_map_over_sections (exec_bfd, print_bfd_section_info, arg);
}
if (core_bfd)
*************** maintenance_info_sections (char *arg, in
*** 310,316 ****
printf_filtered (" `%s', ", bfd_get_filename (core_bfd));
wrap_here (" ");
printf_filtered ("file type %s.\n", bfd_get_target (core_bfd));
! bfd_map_over_sections (core_bfd, print_section_table, arg);
}
}
--- 352,358 ----
printf_filtered (" `%s', ", bfd_get_filename (core_bfd));
wrap_here (" ");
printf_filtered ("file type %s.\n", bfd_get_target (core_bfd));
! bfd_map_over_sections (core_bfd, print_bfd_section_info, arg);
}
}
*************** to test internal functions such as the C
*** 580,586 ****
add_alias_cmd ("i", "info", class_maintenance, 1, &maintenancelist);
add_cmd ("sections", class_maintenance, maintenance_info_sections,
! "List the BFD sections of the exec and core files.",
&maintenanceinfolist);
add_prefix_cmd ("print", class_maintenance, maintenance_print_command,
--- 622,636 ----
add_alias_cmd ("i", "info", class_maintenance, 1, &maintenancelist);
add_cmd ("sections", class_maintenance, maintenance_info_sections,
! "List the BFD sections of the exec and core files. \n
! Arguments may be any combination of:\n\
! [one or more section names]\n\
! ALLOC LOAD RELOC READONLY CODE DATA ROM CONSTRUCTOR\n\
! HAS_CONTENTS NEVER_LOAD COFF_SHARED_LIBRARY IS_COMMON\n\
! Sections matching any argument will be listed (no argument\n\
! implies all sections). In addition, the special argument\n\
! ALLOBJ\n\
! lists all sections from all object files, including shared libraries.",
&maintenanceinfolist);
add_prefix_cmd ("print", class_maintenance, maintenance_print_command,
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Further extend "maint info sections" cmd with ALLOBJ
2001-12-20 14:35 [PATCH] Further extend "maint info sections" cmd with ALLOBJ Michael Snyder
@ 2001-12-21 2:55 ` Pierre Muller
2001-12-21 4:32 ` Pierre Muller
2001-12-21 8:51 ` Michael Snyder
0 siblings, 2 replies; 6+ messages in thread
From: Pierre Muller @ 2001-12-21 2:55 UTC (permalink / raw)
To: Michael Snyder, gdb-patches
At 23:30 20/12/2001 , Michael Snyder a écrit:
>As a further extension, the "maint info sections" command
>will now accept an argument "ALLOBJ" to iterate over all
>known object files (which includes shared libraries.
>You can now do (for instance):
>
> (gdb) maint info sect .bss ALLOBJ
>
>to see info on the .bss sections of all loaded object files.
Great job!
Just a little remark, I would have expected that I get the same output
for the main executable in
"maint info sect"
and
"maint info sect ALLOBJ"
but when I tried it out on a freshly compiled GDB,
the seciond command didn't should
the .stab and .stabstr sections that were shown for the first command.
This is intentional?
Pierre Muller
Institut Charles Sadron
6,rue Boussingault
F 67083 STRASBOURG CEDEX (France)
mailto:muller@ics.u-strasbg.fr
Phone : (33)-3-88-41-40-07 Fax : (33)-3-88-41-40-99
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Further extend "maint info sections" cmd with ALLOBJ
2001-12-21 2:55 ` Pierre Muller
@ 2001-12-21 4:32 ` Pierre Muller
2001-12-21 8:58 ` Michael Snyder
2001-12-21 9:36 ` Michael Snyder
2001-12-21 8:51 ` Michael Snyder
1 sibling, 2 replies; 6+ messages in thread
From: Pierre Muller @ 2001-12-21 4:32 UTC (permalink / raw)
To: Michael Snyder, gdb-patches
At 11:53 21/12/2001 , Pierre Muller a écrit:
>At 23:30 20/12/2001 , Michael Snyder a écrit:
>
> >As a further extension, the "maint info sections" command
> >will now accept an argument "ALLOBJ" to iterate over all
> >known object files (which includes shared libraries.
> >You can now do (for instance):
> >
> > (gdb) maint info sect .bss ALLOBJ
> >
> >to see info on the .bss sections of all loaded object files.
>
>Great job!
>
> Just a little remark, I would have expected that I get the same output
>for the main executable in
>
>"maint info sect"
>and
>"maint info sect ALLOBJ"
>but when I tried it out on a freshly compiled GDB,
>the seciond command didn't should
>the .stab and .stabstr sections that were shown for the first command.
>
>This is intentional?
The problem might be quite general :
maint info sect NEVER_LOAD
gives the same output than
maint info sect HAS_CONTENT
Debugging a little more lead me to find out that
the reason of that bug is simply that
NEVER_LOAD contains LOAD,
ans strstr function returns thus true for strstr(string, "LOAD")
if string is "NEVER_LOAD"
I don't know the best way to solve this
especially as someone could ask for both
LOAD and NEVER_LOAD flags at the same time.
(maybe adding a space a start of args and looking for ' LOAD' with a leading space).
Anyhow the current code also accepts thingss like NOCODE for CODE section
which is quite strange...)
To come back to the problem about .stab section,
the problem is related to the fact that
ALL_OBJFILE_OSECTIONS
is defined as
#define ALL_OBJFILE_OSECTIONS(objfile, osect) \
for (osect = objfile->sections; osect < objfile->sections_end; osect++)
whereas the case without ALLOBJ is handled by a call to
bfd_map_over_sections () function which does iterate in a different way:
for (sect = abfd->sections; sect != NULL; i++, sect = sect->next)
Wouldn't it be better to use the same bfd_map_over_sections ()
function in the ALLOBJ case?
Pierre Muller
Institut Charles Sadron
6,rue Boussingault
F 67083 STRASBOURG CEDEX (France)
mailto:muller@ics.u-strasbg.fr
Phone : (33)-3-88-41-40-07 Fax : (33)-3-88-41-40-99
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Further extend "maint info sections" cmd with ALLOBJ
2001-12-21 2:55 ` Pierre Muller
2001-12-21 4:32 ` Pierre Muller
@ 2001-12-21 8:51 ` Michael Snyder
1 sibling, 0 replies; 6+ messages in thread
From: Michael Snyder @ 2001-12-21 8:51 UTC (permalink / raw)
To: Pierre Muller; +Cc: Michael Snyder, gdb-patches
Pierre Muller wrote:
>
> At 23:30 20/12/2001 , Michael Snyder a écrit:
>
> >As a further extension, the "maint info sections" command
> >will now accept an argument "ALLOBJ" to iterate over all
> >known object files (which includes shared libraries.
> >You can now do (for instance):
> >
> > (gdb) maint info sect .bss ALLOBJ
> >
> >to see info on the .bss sections of all loaded object files.
>
> Great job!
>
> Just a little remark, I would have expected that I get the same output
> for the main executable in
>
> "maint info sect"
> and
> "maint info sect ALLOBJ"
> but when I tried it out on a freshly compiled GDB,
> the seciond command didn't should
> the .stab and .stabstr sections that were shown for the first command.
>
> This is intentional?
Hmm! No. And I hadn't noticed it, thanks for pointing it out.
What's happening is, to do the ALLOBJ version, I use the
section table in the objfile struct rather than the section
list in the bfd. I do that because I want the relocated
addresses of the shared libraries, not the raw addresses
that are in the bfd section table. What I did not notice
is that the .stabs sections are (apparently) omitted from
the objfile section table. I suppose it's likely that the
dwarf debugging sections are too.
Well, fortunately I did not change the behavior of the
original form of the command. I'll mull this over, and
if I can think of a way to bring the new form into
compliance, I will. Otherwise we may just have to
document the short-coming.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Further extend "maint info sections" cmd with ALLOBJ
2001-12-21 4:32 ` Pierre Muller
@ 2001-12-21 8:58 ` Michael Snyder
2001-12-21 9:36 ` Michael Snyder
1 sibling, 0 replies; 6+ messages in thread
From: Michael Snyder @ 2001-12-21 8:58 UTC (permalink / raw)
To: Pierre Muller; +Cc: Michael Snyder, gdb-patches
Pierre Muller wrote:
>
> At 11:53 21/12/2001 , Pierre Muller a écrit:
> >At 23:30 20/12/2001 , Michael Snyder a écrit:
> >
> > >As a further extension, the "maint info sections" command
> > >will now accept an argument "ALLOBJ" to iterate over all
> > >known object files (which includes shared libraries.
> > >You can now do (for instance):
> > >
> > > (gdb) maint info sect .bss ALLOBJ
> > >
> > >to see info on the .bss sections of all loaded object files.
> >
> >Great job!
> >
> > Just a little remark, I would have expected that I get the same output
> >for the main executable in
> >
> >"maint info sect"
> >and
> >"maint info sect ALLOBJ"
> >but when I tried it out on a freshly compiled GDB,
> >the seciond command didn't should
> >the .stab and .stabstr sections that were shown for the first command.
> >
> >This is intentional?
>
> The problem might be quite general :
>
> maint info sect NEVER_LOAD
> gives the same output than
> maint info sect HAS_CONTENT
>
> Debugging a little more lead me to find out that
> the reason of that bug is simply that
> NEVER_LOAD contains LOAD,
> ans strstr function returns thus true for strstr(string, "LOAD")
> if string is "NEVER_LOAD"
Oops! ;-(
> I don't know the best way to solve this
> especially as someone could ask for both
> LOAD and NEVER_LOAD flags at the same time.
> (maybe adding a space a start of args and looking for ' LOAD' with a leading space).
Wouldn't work if "LOAD" was the only argument.
> Anyhow the current code also accepts thingss like NOCODE for CODE section
> which is quite strange...)
Maybe I'll have to check for these specific cases.
I should have known that parsing wasn't this easy.
> To come back to the problem about .stab section,
> the problem is related to the fact that
> ALL_OBJFILE_OSECTIONS
> is defined as
> #define ALL_OBJFILE_OSECTIONS(objfile, osect) \
> for (osect = objfile->sections; osect < objfile->sections_end; osect++)
>
> whereas the case without ALLOBJ is handled by a call to
> bfd_map_over_sections () function which does iterate in a different way:
> for (sect = abfd->sections; sect != NULL; i++, sect = sect->next)
>
> Wouldn't it be better to use the same bfd_map_over_sections ()
> function in the ALLOBJ case?
The problem is that ALLOBJ includes shared libraries, and
I wanted to print the relocated addresses for those, not the
raw addresses that are in the BFD section table. I did not
see a way to get back from the bfd section to the objfile
section, so I felt I had to start from the objfile section
in the first place.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Further extend "maint info sections" cmd with ALLOBJ
2001-12-21 4:32 ` Pierre Muller
2001-12-21 8:58 ` Michael Snyder
@ 2001-12-21 9:36 ` Michael Snyder
1 sibling, 0 replies; 6+ messages in thread
From: Michael Snyder @ 2001-12-21 9:36 UTC (permalink / raw)
To: Pierre Muller; +Cc: Michael Snyder, gdb-patches
Pierre Muller wrote:
> The problem might be quite general :
>
> maint info sect NEVER_LOAD
> gives the same output than
> maint info sect HAS_CONTENT
>
> Debugging a little more lead me to find out that
> the reason of that bug is simply that
> NEVER_LOAD contains LOAD,
> ans strstr function returns thus true for strstr(string, "LOAD")
> if string is "NEVER_LOAD"
OK, I've added a slightly more intelligent lexer/tokenizer.
Patch attached below (or just update). Please try it now.
2001-12-21 Michael Snyder <msnyder@redhat.com>
* maint.c (match_substring): New function. Tokenizer for
'maintenance info sections' command arguments.
(match_bfd_flag): Use match_substring.
(print_bfd_section_info): Use match_substring.
(print_objfile_section_info): Use match_substring.
(maintenance_info_sections): Use match_substring.
Index: maint.c
===================================================================
RCS file: /cvs/src/src/gdb/maint.c,v
retrieving revision 1.18
diff -p -r1.18 maint.c
*** maint.c 2001/12/20 22:31:24 1.18
--- maint.c 2001/12/21 17:25:24
*************** maintenance_info_command (char *arg, int
*** 186,229 ****
help_list (maintenanceinfolist, "maintenance info ", -1,
gdb_stdout);
}
static int
match_bfd_flags (char *string, flagword flags)
{
if (flags & SEC_ALLOC)
! if (strstr (string, "ALLOC"))
return 1;
if (flags & SEC_LOAD)
! if (strstr (string, "LOAD"))
return 1;
if (flags & SEC_RELOC)
! if (strstr (string, "RELOC"))
return 1;
if (flags & SEC_READONLY)
! if (strstr (string, "READONLY"))
return 1;
if (flags & SEC_CODE)
! if (strstr (string, "CODE"))
return 1;
if (flags & SEC_DATA)
! if (strstr (string, "DATA"))
return 1;
if (flags & SEC_ROM)
! if (strstr (string, "ROM"))
return 1;
if (flags & SEC_CONSTRUCTOR)
! if (strstr (string, "CONSTRUCTOR"))
return 1;
if (flags & SEC_HAS_CONTENTS)
! if (strstr (string, "HAS_CONTENTS"))
return 1;
if (flags & SEC_NEVER_LOAD)
! if (strstr (string, "NEVER_LOAD"))
return 1;
if (flags & SEC_COFF_SHARED_LIBRARY)
! if (strstr (string, "COFF_SHARED_LIBRARY"))
return 1;
if (flags & SEC_IS_COMMON)
! if (strstr (string, "IS_COMMON"))
return 1;
return 0;
--- 186,259 ----
help_list (maintenanceinfolist, "maintenance info ", -1,
gdb_stdout);
}
+ /* Mini tokenizing lexer for 'maint info sections' command. */
+
+ static int
+ match_substring (char *string, char *substr)
+ {
+ int substr_len = strlen(substr);
+ char *tok;
+
+ while ((tok = strstr (string, substr)) != NULL)
+ {
+ /* Got a partial match. Is it a whole word? */
+ if (tok == string ||
+ tok[-1] == ' ' ||
+ tok[-1] == '\t')
+ {
+ /* Token is delimited at the front... */
+ if (tok[substr_len] == ' ' ||
+ tok[substr_len] == '\t' ||
+ tok[substr_len] == '\0')
+ {
+ /* Token is delimited at the rear. Got a whole-word match.
*/
+ return 1;
+ }
+ }
+ /* Token didn't match as a whole word. Advance and try again.
*/
+ string = tok + 1;
+ }
+ return 0;
+ }
+
static int
match_bfd_flags (char *string, flagword flags)
{
if (flags & SEC_ALLOC)
! if (match_substring (string, "ALLOC"))
return 1;
if (flags & SEC_LOAD)
! if (match_substring (string, "LOAD"))
return 1;
if (flags & SEC_RELOC)
! if (match_substring (string, "RELOC"))
return 1;
if (flags & SEC_READONLY)
! if (match_substring (string, "READONLY"))
return 1;
if (flags & SEC_CODE)
! if (match_substring (string, "CODE"))
return 1;
if (flags & SEC_DATA)
! if (match_substring (string, "DATA"))
return 1;
if (flags & SEC_ROM)
! if (match_substring (string, "ROM"))
return 1;
if (flags & SEC_CONSTRUCTOR)
! if (match_substring (string, "CONSTRUCTOR"))
return 1;
if (flags & SEC_HAS_CONTENTS)
! if (match_substring (string, "HAS_CONTENTS"))
return 1;
if (flags & SEC_NEVER_LOAD)
! if (match_substring (string, "NEVER_LOAD"))
return 1;
if (flags & SEC_COFF_SHARED_LIBRARY)
! if (match_substring (string, "COFF_SHARED_LIBRARY"))
return 1;
if (flags & SEC_IS_COMMON)
! if (match_substring (string, "IS_COMMON"))
return 1;
return 0;
*************** print_bfd_section_info (bfd *abfd,
*** 282,288 ****
const char *name = bfd_section_name (abfd, asect);
if (arg == NULL || *((char *) arg) == '\0' ||
! strstr ((char *) arg, name) ||
match_bfd_flags ((char *) arg, flags))
{
CORE_ADDR addr, endaddr;
--- 312,318 ----
const char *name = bfd_section_name (abfd, asect);
if (arg == NULL || *((char *) arg) == '\0' ||
! match_substring ((char *) arg, name) ||
match_bfd_flags ((char *) arg, flags))
{
CORE_ADDR addr, endaddr;
*************** print_objfile_section_info (bfd *abfd,
*** 302,308 ****
const char *name = bfd_section_name (abfd, asect->the_bfd_section);
if (string == NULL || *string == '\0' ||
! strstr (string, name) ||
match_bfd_flags (string, flags))
{
print_section_info (name, flags, asect->addr, asect->endaddr,
--- 332,338 ----
const char *name = bfd_section_name (abfd, asect->the_bfd_section);
if (string == NULL || *string == '\0' ||
! match_substring (string, name) ||
match_bfd_flags (string, flags))
{
print_section_info (name, flags, asect->addr, asect->endaddr,
*************** maintenance_info_sections (char *arg, in
*** 320,326 ****
printf_filtered (" `%s', ", bfd_get_filename (exec_bfd));
wrap_here (" ");
printf_filtered ("file type %s.\n", bfd_get_target (exec_bfd));
! if (arg && *arg && strstr (arg, "ALLOBJ"))
{
struct objfile *ofile;
struct obj_section *osect;
--- 350,356 ----
printf_filtered (" `%s', ", bfd_get_filename (exec_bfd));
wrap_here (" ");
printf_filtered ("file type %s.\n", bfd_get_target (exec_bfd));
! if (arg && *arg && match_substring (arg, "ALLOBJ"))
{
struct objfile *ofile;
struct obj_section *osect;
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2001-12-21 17:36 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-20 14:35 [PATCH] Further extend "maint info sections" cmd with ALLOBJ Michael Snyder
2001-12-21 2:55 ` Pierre Muller
2001-12-21 4:32 ` Pierre Muller
2001-12-21 8:58 ` Michael Snyder
2001-12-21 9:36 ` Michael Snyder
2001-12-21 8:51 ` Michael Snyder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox