From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22259 invoked by alias); 17 Nov 2008 23:36:58 -0000 Received: (qmail 22122 invoked by uid 22791); 17 Nov 2008 23:36:56 -0000 X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.45.13) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 17 Nov 2008 23:36:21 +0000 Received: from wpaz17.hot.corp.google.com (wpaz17.hot.corp.google.com [172.24.198.81]) by smtp-out.google.com with ESMTP id mAHNaIX4029287 for ; Mon, 17 Nov 2008 15:36:18 -0800 Received: from wa-out-1112.google.com (wahj5.prod.google.com [10.114.236.5]) by wpaz17.hot.corp.google.com with ESMTP id mAHNaGqk007558 for ; Mon, 17 Nov 2008 15:36:17 -0800 Received: by wa-out-1112.google.com with SMTP id j5so1750681wah.4 for ; Mon, 17 Nov 2008 15:36:16 -0800 (PST) MIME-Version: 1.0 Received: by 10.114.147.1 with SMTP id u1mr2816310wad.115.1226964976494; Mon, 17 Nov 2008 15:36:16 -0800 (PST) In-Reply-To: <20081117193531.GA17547@caradoc.them.org> References: <20081114204617.A4A533A6B15@localhost> <491DF12A.5090903@vmware.com> <8ac60eac0811141406h4bb126c0sbd898e7d612f46dd@mail.gmail.com> <491E08BF.2050609@vmware.com> <8ac60eac0811150842x78206050t435c6f8c89ddc8ae@mail.gmail.com> <8ac60eac0811151022w13df6899v13bb321ee08aae09@mail.gmail.com> <20081115190118.GL12802@adacore.com> <8ac60eac0811171112x5b555146lefb27f36e773ac25@mail.gmail.com> <20081117193531.GA17547@caradoc.them.org> Date: Tue, 18 Nov 2008 16:07:00 -0000 Message-ID: <8ac60eac0811171536m1ac412f0k934c5acd5a1cc1f4@mail.gmail.com> Subject: Re: [RFA] [patch] 'info symbol' to print more info From: Paul Pluzhnikov To: Paul Pluzhnikov , Joel Brobecker , Eli Zaretskii , msnyder@vmware.com, gdb-patches@sourceware.org Content-Type: multipart/mixed; boundary=0016364c5baf93673f045beb0b6a X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-11/txt/msg00455.txt.bz2 --0016364c5baf93673f045beb0b6a Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-length: 775 On Mon, Nov 17, 2008 at 11:35 AM, Daniel Jacobowitz wrote: > This discussion seems to have wandered far afield from Paul's > reasonable patch :-( So here is another attempt. I did warn it would be ugly :( -- Paul Pluzhnikov 2008-11-17 Paul Pluzhnikov * objfiles.h: New MULTI_OBJFILE_P macro. * printcmd.c (sym_info): Print object name. * maint.c (maintenance_translate_address): Likewise. doc/ChangeLog 2008-11-17 Paul Pluzhnikov * gdb.texinfo (Symbols): Mention printing containing image name in "info symbol". (Maint translate-address): Likewise. testsuite/ChangeLog 2008-11-17 Paul Pluzhnikov * gdb.base/sepsymtab.exp: Update for new 'info sym' format. --0016364c5baf93673f045beb0b6a Content-Type: text/plain; name="gdb-info-sym-20081117.txt" Content-Disposition: attachment; filename="gdb-info-sym-20081117.txt" Content-Transfer-Encoding: 7bit X-Attachment-Id: f_fnnr6obu1 Content-length: 7104 Index: maint.c =================================================================== RCS file: /cvs/src/src/gdb/maint.c,v retrieving revision 1.68 diff -u -p -u -r1.68 maint.c --- maint.c 30 Oct 2008 20:35:30 -0000 1.68 +++ maint.c 17 Nov 2008 23:09:50 -0000 @@ -35,6 +35,7 @@ #include "symfile.h" #include "objfiles.h" #include "value.h" +#include "gdb_assert.h" #include "cli/cli-decode.h" @@ -484,9 +485,32 @@ maintenance_translate_address (char *arg sym = lookup_minimal_symbol_by_pc (address); if (sym) - printf_filtered ("%s+%s\n", - SYMBOL_PRINT_NAME (sym), - pulongest (address - SYMBOL_VALUE_ADDRESS (sym))); + { + const char *symbol_name = SYMBOL_PRINT_NAME (sym); + const char *symbol_offset = pulongest (address - SYMBOL_VALUE_ADDRESS (sym)); + + sect = SYMBOL_OBJ_SECTION(sym); + if (sect != NULL) + { + const char *section_name; + const char *obj_name; + + gdb_assert (sect->the_bfd_section && sect->the_bfd_section->name); + section_name = sect->the_bfd_section->name; + + gdb_assert (sect->objfile && sect->objfile->name); + obj_name = sect->objfile->name; + + if (MULTI_OBJFILE_P ()) + printf_filtered (_("%s + %s in section %s of %s\n"), + symbol_name, symbol_offset, section_name, obj_name); + else + printf_filtered (_("%s + %s in section %s\n"), + symbol_name, symbol_offset, section_name); + } + else + printf_filtered (_("%s + %s\n"), symbol_name, symbol_offset); + } else if (sect) printf_filtered (_("no symbol at %s:0x%s\n"), sect->the_bfd_section->name, paddr (address)); Index: objfiles.h =================================================================== RCS file: /cvs/src/src/gdb/objfiles.h,v retrieving revision 1.56 diff -u -p -u -r1.56 objfiles.h --- objfiles.h 1 Oct 2008 17:21:06 -0000 1.56 +++ objfiles.h 17 Nov 2008 23:09:50 -0000 @@ -583,4 +583,8 @@ extern void *objfile_data (struct objfil uninitialized section index. */ #define SECT_OFF_BSS(objfile) (objfile)->sect_index_bss +/* Answer whether there is more than one object file loaded. */ + +#define MULTI_OBJFILE_P() (object_files && object_files->next) + #endif /* !defined (OBJFILES_H) */ Index: printcmd.c =================================================================== RCS file: /cvs/src/src/gdb/printcmd.c,v retrieving revision 1.136 diff -u -p -u -r1.136 printcmd.c --- printcmd.c 13 Nov 2008 22:26:15 -0000 1.136 +++ printcmd.c 17 Nov 2008 23:09:50 -0000 @@ -1012,21 +1012,51 @@ sym_info (char *arg, int from_tty) && sect_addr < obj_section_endaddr (osect) && (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, osect))) { + const char *obj_name, *mapped, *sec_name, *msym_name; + matches = 1; offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol); - if (offset) - printf_filtered ("%s + %u in ", - SYMBOL_PRINT_NAME (msymbol), offset); + mapped = section_is_mapped (osect) ? "mapped" : "unmapped"; + sec_name = osect->the_bfd_section->name; + msym_name = SYMBOL_PRINT_NAME (msymbol); + + gdb_assert (osect->objfile && osect->objfile->name); + obj_name = osect->objfile->name; + + if (MULTI_OBJFILE_P ()) + if (pc_in_unmapped_range (addr, osect)) + if (section_is_overlay (osect)) + printf_filtered (_("%s + %u in load address range of " + "%s overlay section %s of %s\n"), + msym_name, offset, + mapped, sec_name, obj_name); + else + printf_filtered (_("%s + %u in load address range of " + "section %s of %s\n"), + msym_name, offset, sec_name, obj_name); + else + if (section_is_overlay (osect)) + printf_filtered (_("%s + %u in %s overlay section %s of %s\n"), + msym_name, offset, mapped, sec_name, obj_name); + else + printf_filtered (_("%s + %u in section %s of %s\n"), + msym_name, offset, sec_name, obj_name); else - printf_filtered ("%s in ", - SYMBOL_PRINT_NAME (msymbol)); - if (pc_in_unmapped_range (addr, osect)) - printf_filtered (_("load address range of ")); - if (section_is_overlay (osect)) - printf_filtered (_("%s overlay "), - section_is_mapped (osect) ? "mapped" : "unmapped"); - printf_filtered (_("section %s"), osect->the_bfd_section->name); - printf_filtered ("\n"); + if (pc_in_unmapped_range (addr, osect)) + if (section_is_overlay (osect)) + printf_filtered (_("%s + %u in load address range of %s overlay " + "section %s\n"), + msym_name, offset, mapped, sec_name); + else + printf_filtered (_("%s + %u in load address range of section %s\n"), + msym_name, offset, sec_name); + else + if (section_is_overlay (osect)) + printf_filtered (_("%s + %u in %s overlay section %s\n"), + msym_name, offset, mapped, sec_name); + else + printf_filtered (_("%s + %u in section %s\n"), + msym_name, offset, sec_name); } } if (matches == 0) Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.533 diff -u -p -u -r1.533 gdb.texinfo --- doc/gdb.texinfo 17 Nov 2008 16:43:33 -0000 1.533 +++ doc/gdb.texinfo 17 Nov 2008 23:09:51 -0000 @@ -11866,6 +11866,16 @@ _initialize_vx + 396 in section .text This is the opposite of the @code{info address} command. You can use it to find out the name of a variable or a function given its address. +For dynamically linked executables, the name of executable or shared +library containing the symbol is also printed: + +@smallexample +(@value{GDBP}) info symbol 0x400225 +_start + 5 in section .text of /tmp/a.out +(@value{GDBP}) info symbol 0x2aaaac2811cf +__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6 +@end smallexample + @kindex whatis @item whatis [@var{arg}] Print the data type of @var{arg}, which can be either an expression or @@ -24621,6 +24631,10 @@ the symbol's location to the specified a the @code{info address} command (@pxref{Symbols}), except that this command also allows to find symbols in other sections. +If section was not specified, the section in which the symbol was found +is also printed. For dynamically linked executables, the name of +executable or shared library containing the symbol is printed as well. + @end table The following command is useful for non-interactive invocations of Index: testsuite/gdb.base/sepsymtab.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/sepsymtab.exp,v retrieving revision 1.5 diff -u -p -u -r1.5 sepsymtab.exp --- testsuite/gdb.base/sepsymtab.exp 1 Jan 2008 22:53:19 -0000 1.5 +++ testsuite/gdb.base/sepsymtab.exp 17 Nov 2008 23:33:07 -0000 @@ -45,7 +45,7 @@ gdb_load ${binfile} set command "info sym main" set command_regex [string_to_regexp $command] gdb_test_multiple "$command" "$command" { - -re "^${command_regex}\[\r\n\]+main in section \[^\r\n\]+\[\r\n\]+$gdb_prompt \$" { + -re "^${command_regex}\[\r\n\]+main \\+ 0 in section \[^\r\n\]+\[\r\n\]+$gdb_prompt \$" { pass "$command" } } --0016364c5baf93673f045beb0b6a--