Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Fix ptype problem printing typedefs defined differently in different compilation units
@ 2006-01-03 20:17 Fred Fish
  2006-01-03 23:15 ` Jim Blandy
  0 siblings, 1 reply; 38+ messages in thread
From: Fred Fish @ 2006-01-03 20:17 UTC (permalink / raw)
  To: gdb-patches; +Cc: fnf

[-- Attachment #1: Type: text/plain, Size: 837 bytes --]

When examining an executable (but not running it) if you have a
typedef in two different compilation units, with the same name but
different types, the ptype command will print the type for the first
one it finds in a scan of all the loaded symtabs, regardless of any
source context you may have selected.

Of course the wisdom of having writing this sort of code in the first
place is somewhat suspect...  :-)

Attached is a patch that adds a test to the ptype.exp test for this
case, by alternately listing functions from different compilation
units (thus setting gdb's idea of the current source context) and
verifying that ptype prints the type correctly based on the context.

The patch also adds a proposed fix for the problem, which is to look
in the current source symtab for the name, before scanning all the
symtabs.

-Fred




[-- Attachment #2: symtab.patch2 --]
[-- Type: text/x-diff, Size: 7183 bytes --]

Gdb ChangeLog entry:

 2006-01-03  Fred Fish  <fnf@specifix.com>
 
 	* symtab.c (lookup_symbol_aux_symtab): Add declaration and
 	definition of function to look up name in a specific symtab.
 	(lookup_symbol_aux): Add cursal variable and code to set it.
 	Call lookup_symbol_aux_symtab with current source symtab.
 	
Gdb testsuite ChangeLog entry:

 2006-01-03  Fred Fish  <fnf@specifix.com>

	* gdb.base/ptype.c (foo): Add typedef.
	(intfoo): Add function.
	* gdb.base/ptype1.c: New file.
	* gdb.base/ptype.exp: Handle compilation and linking with two
	source files.  Test that proper type for "foo" is found based
	on source context rather than first match found in symtabs.

Index: symtab.c
===================================================================
RCS file: /cvsroots/latest/src/gdb/gdb/symtab.c,v
retrieving revision 1.1.1.2
diff -c -p -r1.1.1.2 symtab.c
*** symtab.c	30 Dec 2005 18:53:03 -0000	1.1.1.2
--- symtab.c	3 Jan 2006 18:04:01 -0000
*************** struct symbol *lookup_symbol_aux_local (
*** 94,99 ****
--- 94,107 ----
  					struct symtab **symtab);
  
  static
+ struct symbol *lookup_symbol_aux_symtab (struct symtab *s,
+ 					 int block_index,
+ 					 const char *name,
+ 					 const char *linkage_name,
+ 					 const domain_enum domain,
+ 					 struct symtab **symtab);
+ 
+ static
  struct symbol *lookup_symbol_aux_symtabs (int block_index,
  					  const char *name,
  					  const char *linkage_name,
*************** lookup_symbol_aux (const char *name, con
*** 1079,1084 ****
--- 1087,1093 ----
  		   int *is_a_field_of_this, struct symtab **symtab)
  {
    struct symbol *sym;
+   struct symtab_and_line cursal;
  
    /* Make sure we do something sensible with is_a_field_of_this, since
       the callers that set this parameter to some non-null value will
*************** lookup_symbol_aux (const char *name, con
*** 1122,1127 ****
--- 1131,1144 ----
    if (sym != NULL)
      return sym;
  
+   /* Check the symtab associated with the current source line. */
+ 
+   cursal = get_current_source_symtab_and_line ();
+   sym = lookup_symbol_aux_symtab (cursal.symtab, STATIC_BLOCK, name,
+ 				  linkage_name, domain, symtab);
+   if (sym != NULL)
+     return sym;
+ 
    /* Now search all static file-level symbols.  Not strictly correct,
       but more useful than an error.  Do the symtabs first, then check
       the psymtabs.  If a psymtab indicates the existence of the
*************** lookup_symbol_aux_block (const char *nam
*** 1215,1220 ****
--- 1232,1269 ----
    return NULL;
  }
  
+ /* Check to see if the symbol is defined in a specific symtab.
+    BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
+    depending on whether or not we want to search global symbols or
+    static symbols.  */
+ 
+ static struct symbol *
+ lookup_symbol_aux_symtab (struct symtab *s, int block_index,
+ 			  const char *name, const char *linkage_name,
+ 			  const domain_enum domain,
+ 			  struct symtab **symtab)
+ {
+   struct symbol *sym;
+   struct blockvector *bv;
+   const struct block *block;
+ 
+   if (s != NULL)
+     {
+       bv = BLOCKVECTOR (s);
+       block = BLOCKVECTOR_BLOCK (bv, block_index);
+       sym = lookup_block_symbol (block, name, linkage_name, domain);
+       if (sym)
+ 	{
+ 	  block_found = block;
+ 	  if (symtab != NULL)
+ 	    *symtab = s;
+ 	  return fixup_symbol_section (sym, s->objfile);
+ 	}
+     }
+ 
+   return NULL;
+ }
+ 
  /* Check to see if the symbol is defined in one of the symtabs.
     BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
     depending on whether or not we want to search global symbols or
Index: testsuite/gdb.base/ptype.c
===================================================================
RCS file: /cvsroots/latest/src/gdb/gdb/testsuite/gdb.base/ptype.c,v
retrieving revision 1.1.1.1
diff -c -p -r1.1.1.1 ptype.c
*** testsuite/gdb.base/ptype.c	8 Oct 2005 19:36:19 -0000	1.1.1.1
--- testsuite/gdb.base/ptype.c	3 Jan 2006 05:17:21 -0000
*************** func_type v_func_type;
*** 259,264 ****
--- 259,273 ----
  
  /***********/
  
+ typedef int foo;
+ 
+ foo intfoo (afoo)
+ {
+   return (afoo * 2);
+ }
+ 
+ /***********/
+ 
  int main ()
  {
    /* Ensure that malloc is a pointer type; avoid use of "void" and any include files. */
Index: testsuite/gdb.base/ptype.exp
===================================================================
RCS file: /cvsroots/latest/src/gdb/gdb/testsuite/gdb.base/ptype.exp,v
retrieving revision 1.1.1.1
diff -c -p -r1.1.1.1 ptype.exp
*** testsuite/gdb.base/ptype.exp	8 Oct 2005 19:36:19 -0000	1.1.1.1
--- testsuite/gdb.base/ptype.exp	3 Jan 2006 05:29:40 -0000
*************** set prms_id 0
*** 31,39 ****
  set bug_id 0
  
  set testfile "ptype"
! set srcfile ${testfile}.c
  set binfile ${objdir}/${subdir}/${testfile}
! if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
       gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
  }
  
--- 31,47 ----
  set bug_id 0
  
  set testfile "ptype"
! set srcfile0 ${testfile}.c
! set srcfile1 ${testfile}1.c
  set binfile ${objdir}/${subdir}/${testfile}
! 
! if  { [gdb_compile "${srcdir}/${subdir}/${srcfile0}" "${binfile}0.o" object {debug}] != "" } {
!      gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
! }
! if  { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug}] != "" } {
!      gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
! }
! if  { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug}] != "" } {
       gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
  }
  
*************** ptype_maybe_prototyped "ffptr" "int (*(*
*** 574,579 ****
--- 582,599 ----
  ptype_maybe_prototyped "fffptr" "int (*(*(*)(char))(short int))(long int)" \
                                  "int (*(*(*)())())()"
  
+ # Test printing type of typedefs in different scopes, with same name
+ # but different type.
+ 
+ gdb_test "list intfoo" ""
+ gdb_test "ptype foo" "type = int" "ptype foo typedef after first list of intfoo"
+ gdb_test "list charfoo" ""
+ gdb_test "ptype foo" "type = char" "ptype foo typedef after first list of charfoo"
+ gdb_test "list intfoo" ""
+ gdb_test "ptype foo" "type = int" "ptype foo typedef after second list of intfoo"
+ gdb_test "list charfoo" ""
+ gdb_test "ptype foo" "type = char" "ptype foo typedef after second list of charfoo"
+ 
  # Test printing type of string constants and array constants, but
  # requires a running process.  These call malloc, and can take a long
  # time to execute over a slow serial link, so increase the timeout.
Index: testsuite/gdb.base/ptype1.c
===================================================================
RCS file: testsuite/gdb.base/ptype1.c
diff -N testsuite/gdb.base/ptype1.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/gdb.base/ptype1.c	3 Jan 2006 05:31:00 -0000
***************
*** 0 ****
--- 1,6 ----
+ typedef char foo;
+ 
+ foo charfoo (afoo)
+ {
+   return (afoo * 2);
+ }

^ permalink raw reply	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2006-05-17 19:03 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-03 20:17 [PATCH] Fix ptype problem printing typedefs defined differently in different compilation units Fred Fish
2006-01-03 23:15 ` Jim Blandy
2006-01-04  2:46   ` Fred Fish
2006-01-04  3:45     ` Jim Blandy
2006-01-04 11:15       ` Fred Fish
2006-01-04 21:04       ` Fred Fish
2006-01-05  0:21         ` Jim Blandy
2006-01-05  0:26         ` Jim Blandy
2006-01-05  0:54           ` Daniel Jacobowitz
2006-01-05  4:47             ` Jim Blandy
2006-01-15 18:48         ` Daniel Jacobowitz
2006-01-16  4:22           ` Jim Blandy
2006-01-23 15:27             ` Fred Fish
2006-01-23 16:12               ` Daniel Jacobowitz
2006-01-23 16:43                 ` Fred Fish
2006-01-23 19:17                   ` Jim Blandy
2006-01-23 19:35                     ` Fred Fish
2006-01-23 20:45                       ` Jim Blandy
2006-02-11  0:39                         ` Fred Fish
2006-02-11 18:35                           ` Daniel Jacobowitz
2006-02-11 19:08                             ` Eli Zaretskii
2006-02-11 20:13                               ` Daniel Jacobowitz
2006-02-11 20:01                             ` Fred Fish
2006-02-11 20:21                               ` Daniel Jacobowitz
2006-02-12 18:49                                 ` Fred Fish
2006-02-14 14:11                                   ` Daniel Jacobowitz
2006-02-14 18:47                                     ` Fred Fish
2006-02-17  0:17                                     ` Fred Fish
2006-02-17  9:15                                       ` Eli Zaretskii
2006-02-17 13:36                                         ` Fred Fish
2006-02-17 20:32                                         ` Fred Fish
2006-02-18  9:27                                           ` Eli Zaretskii
2006-02-18 22:19                                       ` Daniel Jacobowitz
2006-02-20 15:47                                       ` Fred Fish
2006-02-20 16:23                                         ` Daniel Jacobowitz
2006-05-17 19:04                                           ` Fred Fish
2006-02-11  0:39                         ` Fred Fish
2006-01-24 15:23                     ` [commit] " Fred Fish

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox