From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28035 invoked by alias); 10 Sep 2012 22:13:13 -0000 Received: (qmail 28020 invoked by uid 22791); 10 Sep 2012 22:13:11 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,RCVD_IN_HOSTKARMA_NO,TW_BJ X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 10 Sep 2012 22:12:46 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 33CA01C7943; Mon, 10 Sep 2012 18:12:46 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id xFvMaUiAPK5W; Mon, 10 Sep 2012 18:12:46 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id CD87F1C793B; Mon, 10 Sep 2012 18:12:45 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 45BE314561A; Mon, 10 Sep 2012 15:12:42 -0700 (PDT) Date: Mon, 10 Sep 2012 22:13:00 -0000 From: Joel Brobecker To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: RFC: printing pointers to global (data) variable on Windows... Message-ID: <20120910221242.GB3081@adacore.com> References: <20120816152255.GA2836@adacore.com> <87zk5umwj3.fsf@fleche.redhat.com> <20120816224524.GC2798@adacore.com> <87628hmwbr.fsf@fleche.redhat.com> <20120817231554.GF2798@adacore.com> <87r4r1h2u4.fsf@fleche.redhat.com> <20120821153627.GS2798@adacore.com> <20120905144406.GC2853@adacore.com> <87fw6pd7c4.fsf@fleche.redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="WIyZ46R2i8wDzkSu" Content-Disposition: inline In-Reply-To: <87fw6pd7c4.fsf@fleche.redhat.com> User-Agent: Mutt/1.5.20 (2009-06-14) 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: 2012-09/txt/msg00145.txt.bz2 --WIyZ46R2i8wDzkSu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1779 > Joel> @@ -1233,7 +1235,7 @@ install_minimal_symbols (struct objfile *objfile) > Joel> SYMBOL_VALUE_ADDRESS (&msymbols[mcount]) = 0; > Joel> MSYMBOL_TARGET_FLAG_1 (&msymbols[mcount]) = 0; > Joel> MSYMBOL_TARGET_FLAG_2 (&msymbols[mcount]) = 0; > Joel> - MSYMBOL_SIZE (&msymbols[mcount]) = 0; > Joel> + SET_MSYMBOL_SIZE (&msymbols[mcount], 0); > > I tend to think this hunk should not use SET_MSYMBOL_SIZE. > Maybe it even ought to use memset instead of what it currently does. > > Or, if SET_MSYMBOL_SIZE is correct here, a comment would be helpful. Intuitively, I do not think that it really matters. But I prefer the idea of memset-ting the whole object to zero, and it's actually something I have been wanting to do anyways. So here are two patches. The first one just adjusts install_minimal_symbols to use memset instead of the various macros. gdb/ChangeLog: * minsyms.c (install_minimal_symbols): Use memset to fill entire minimal_symbol struct object, rather than setting some of its fields one by one. And the second is the initial patch, adjusted to the first one. gdb/ChangeLog: * symtab.h (struct minimal_symbol) [has_size]: New field. (MSYMBOL_SIZE): Adjust to forbid macro from being used as lvalue. (SET_MSYMBOL_SIZE, MSYMBOL_HAS_SIZE): New macros. * printcmd.c (build_address_symbolic): Only filter out zero-sized minimal symbols if the symbol's size is actually known. * minsyms.c (prim_record_minimal_symbol_full): Adjust setting of msymbol's size field. Add comment. * elfread.c (elf_symtab_read, elf_rel_plt_read): Use SET_MSYMBOL_SIZE to set the minimal symbol size. Tested on x86_64-linux. OK to apply? Thanks! -- Joel --WIyZ46R2i8wDzkSu Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-install_minimal_symbols-use-memset-instead-of-settin.patch" Content-length: 1441 >From 258f4f2dfdf021acb91bffd1f0ac95ebbaa7fbe6 Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Mon, 10 Sep 2012 16:31:28 -0400 Subject: [PATCH 1/2] install_minimal_symbols: use memset instead of setting each field. gdb/ChangeLog: * minsyms.c (install_minimal_symbols): Use memset to fill entire minimal_symbol struct object, rather than setting some of its fields one by one. --- gdb/minsyms.c | 8 +------- 1 files changed, 1 insertions(+), 7 deletions(-) diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 1070fff..b6df4ea 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -1229,13 +1229,7 @@ install_minimal_symbols (struct objfile *objfile) symbol count does *not* include this null symbol, which is why it is indexed by mcount and not mcount-1. */ - SYMBOL_LINKAGE_NAME (&msymbols[mcount]) = NULL; - SYMBOL_VALUE_ADDRESS (&msymbols[mcount]) = 0; - MSYMBOL_TARGET_FLAG_1 (&msymbols[mcount]) = 0; - MSYMBOL_TARGET_FLAG_2 (&msymbols[mcount]) = 0; - MSYMBOL_SIZE (&msymbols[mcount]) = 0; - MSYMBOL_TYPE (&msymbols[mcount]) = mst_unknown; - SYMBOL_SET_LANGUAGE (&msymbols[mcount], language_unknown); + memset (&msymbols[mcount], 0, sizeof (struct minimal_symbol)); /* Attach the minimal symbol table to the specified objfile. The strings themselves are also located in the objfile_obstack -- 1.7.0.4 --WIyZ46R2i8wDzkSu Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0002-Name-of-symbol-missing-when-printing-global-variable.patch" Content-length: 4755 >From 0da12186cb6f455a43f8937cb2b5dfcc39c2953c Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Wed, 22 Aug 2012 20:29:13 +0200 Subject: [PATCH 2/2] Name of symbol missing when printing global variable's address The build_address_symbolic funnction filters out data symbols if their size is set to zero. But the problem is that the COFF symbol table (for instance) does not provide any size information, leaving the size to its default value of zero, thus always triggering the filter. This shows up when trying to print the address of a global variable when debugging a Windows executable, for instance. gdb/ChangeLog: * symtab.h (struct minimal_symbol) [has_size]: New field. (MSYMBOL_SIZE): Adjust to forbid macro from being used as lvalue. (SET_MSYMBOL_SIZE, MSYMBOL_HAS_SIZE): New macros. * printcmd.c (build_address_symbolic): Only filter out zero-sized minimal symbols if the symbol's size is actually known. * minsyms.c (prim_record_minimal_symbol_full): Adjust setting of msymbol's size field. Add comment. * elfread.c (elf_symtab_read, elf_rel_plt_read): Use SET_MSYMBOL_SIZE to set the minimal symbol size. --- gdb/elfread.c | 6 +++--- gdb/minsyms.c | 4 +++- gdb/printcmd.c | 1 + gdb/symtab.h | 14 +++++++++++++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/gdb/elfread.c b/gdb/elfread.c index f3967d7..516cbd0 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -570,7 +570,7 @@ elf_symtab_read (struct objfile *objfile, int type, elf_sym = (elf_symbol_type *) sym->udata.p; if (elf_sym) - MSYMBOL_SIZE(msym) = elf_sym->internal_elf_sym.st_size; + SET_MSYMBOL_SIZE (msym, elf_sym->internal_elf_sym.st_size); msym->filename = filesymname; gdbarch_elf_make_msymbol_special (gdbarch, sym, msym); @@ -594,7 +594,7 @@ elf_symtab_read (struct objfile *objfile, int type, sym->section, objfile); if (mtramp) { - MSYMBOL_SIZE (mtramp) = MSYMBOL_SIZE (msym); + SET_MSYMBOL_SIZE (mtramp, MSYMBOL_SIZE (msym)); mtramp->created_by_gdb = 1; mtramp->filename = filesymname; gdbarch_elf_make_msymbol_special (gdbarch, sym, mtramp); @@ -689,7 +689,7 @@ elf_rel_plt_read (struct objfile *objfile, asymbol **dyn_symbol_table) 1, address, mst_slot_got_plt, got_plt, objfile); if (msym) - MSYMBOL_SIZE (msym) = ptr_size; + SET_MSYMBOL_SIZE (msym, ptr_size); } do_cleanups (back_to); diff --git a/gdb/minsyms.c b/gdb/minsyms.c index b6df4ea..a3a376c 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -937,7 +937,9 @@ prim_record_minimal_symbol_full (const char *name, int name_len, int copy_name, MSYMBOL_TYPE (msymbol) = ms_type; MSYMBOL_TARGET_FLAG_1 (msymbol) = 0; MSYMBOL_TARGET_FLAG_2 (msymbol) = 0; - MSYMBOL_SIZE (msymbol) = 0; + /* Do not use the SET_MSYMBOL_SIZE macro to initialize the size, + as it would also set the has_size flag. */ + msymbol->size = 0; /* The hash pointers must be cleared! If they're not, add_minsym_to_hash_table will NOT add this msymbol to the hash table. */ diff --git a/gdb/printcmd.c b/gdb/printcmd.c index d5b5b63..9e8cd65 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -680,6 +680,7 @@ build_address_symbolic (struct gdbarch *gdbarch, } if (msymbol != NULL + && MSYMBOL_HAS_SIZE (msymbol) && MSYMBOL_SIZE (msymbol) == 0 && MSYMBOL_TYPE (msymbol) != mst_text && MSYMBOL_TYPE (msymbol) != mst_text_gnu_ifunc diff --git a/gdb/symtab.h b/gdb/symtab.h index 76120a3..041d8cf 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -348,6 +348,11 @@ struct minimal_symbol unsigned int target_flag_1 : 1; unsigned int target_flag_2 : 1; + /* Nonzero iff the size of the minimal symbol has been set. + Symbol size information can sometimes not be determined, because + the object file format may not carry that piece of information. */ + unsigned int has_size : 1; + /* Minimal symbols with the same hash key are kept on a linked list. This is the link. */ @@ -361,7 +366,14 @@ struct minimal_symbol #define MSYMBOL_TARGET_FLAG_1(msymbol) (msymbol)->target_flag_1 #define MSYMBOL_TARGET_FLAG_2(msymbol) (msymbol)->target_flag_2 -#define MSYMBOL_SIZE(msymbol) (msymbol)->size +#define MSYMBOL_SIZE(msymbol) ((msymbol)->size + 0) +#define SET_MSYMBOL_SIZE(msymbol, sz) \ + do \ + { \ + (msymbol)->size = sz; \ + (msymbol)->has_size = 1; \ + } while (0) +#define MSYMBOL_HAS_SIZE(msymbol) ((msymbol)->has_size + 0) #define MSYMBOL_TYPE(msymbol) (msymbol)->type #include "minsyms.h" -- 1.7.0.4 --WIyZ46R2i8wDzkSu--