Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] fix lookup_symbol foobar
@ 2003-08-07 16:21 Elena Zannoni
  2003-08-07 18:19 ` David Carlton
  2003-08-08 14:06 ` Elena Zannoni
  0 siblings, 2 replies; 3+ messages in thread
From: Elena Zannoni @ 2003-08-07 16:21 UTC (permalink / raw)
  To: carlton, gdb-patches


This is an interesting buglet:

[ezannoni@tomago gdb]$ cat ~/buglet.c
int a = 5;
int main (void)
{
  int sum = 0;
  printf ("hello\n");
  while ( a > 0)
  {
    sum += a;
    a--;
  }
  printf ("sum is %d\n", sum);
  printf ("bye\n");
  return 0;
}


[ezannoni@tomago gdb]$ gdb ~/buglet
GNU gdb Red Hat Linux (5.3.90-0.20030710.2rh)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
Setting up the environment for debugging gdb.
.gdbinit:5: Error in sourced command file:
Function "internal_error" not defined.
(gdb) l 
1	int a = 5;
2	int main (void)
3	{
4	  int sum = 0;
5	  printf ("hello\n");
6	  while ( a > 0)
7	  {
8	    sum += a;
9	    a--;
10	  }
(gdb) p a
$1 = 5
(gdb) p sum
No symbol "sum" in current context.
(gdb) ptype a
type = int
(gdb) ptype sum
No symbol "sum" in current context.
(gdb) info addr a
Symbol "a" is static storage at address 0x80494b4.
(gdb) info addr sum
Symbol "sum" is a field of the local class variable `this'

Whoops. 

This is because lookup_symbol in address_info() returns null, and also
doesn't initialize *is_a_field_of_this to anything.

I suspect a similar situation can happen in any of the callers of
lookup_symbol that set the is_a_field_of_this to a non-null value.

David, you are the one that played around with all this, looks ok to
you?

elena


2003-08-07  Elena Zannoni  <ezannoni@redhat.com>

	* symtab.c (lookup_symbol_aux): Make sure that is_a_field_of_this
	contains something meaningful at all times.



diff -u -p -r1.113 symtab.c
--- symtab.c	12 Jun 2003 15:52:08 -0000	1.113
+++ symtab.c	7 Aug 2003 15:33:08 -0000
@@ -945,6 +945,14 @@ lookup_symbol_aux (const char *name, con
 {
   struct symbol *sym;
 
+  /* 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
+     certainly use it later and expect it to be either 0 or 1.
+     If we don't set it, the contents of is_a_field_of_this are
+     undefined.  */
+  if (is_a_field_of_this != NULL)
+    *is_a_field_of_this = 0;
+
   /* Search specified block and its superiors.  Don't search
      STATIC_BLOCK or GLOBAL_BLOCK.  */
 
@@ -961,7 +969,6 @@ lookup_symbol_aux (const char *name, con
     {
       struct value *v = current_language->la_value_of_this (0);
 
-      *is_a_field_of_this = 0;
       if (v && check_field (v, name))
 	{
 	  *is_a_field_of_this = 1;


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

* Re: [PATCH] fix lookup_symbol foobar
  2003-08-07 16:21 [PATCH] fix lookup_symbol foobar Elena Zannoni
@ 2003-08-07 18:19 ` David Carlton
  2003-08-08 14:06 ` Elena Zannoni
  1 sibling, 0 replies; 3+ messages in thread
From: David Carlton @ 2003-08-07 18:19 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: gdb-patches

On Thu, 7 Aug 2003 12:28:49 -0400, Elena Zannoni <ezannoni@redhat.com> said:

> David, you are the one that played around with all this, looks ok to
> you?

Yes, looks good.

David Carlton
carlton@kealia.com


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

* Re: [PATCH] fix lookup_symbol foobar
  2003-08-07 16:21 [PATCH] fix lookup_symbol foobar Elena Zannoni
  2003-08-07 18:19 ` David Carlton
@ 2003-08-08 14:06 ` Elena Zannoni
  1 sibling, 0 replies; 3+ messages in thread
From: Elena Zannoni @ 2003-08-08 14:06 UTC (permalink / raw)
  To: gdb-patches


Committed mainline & branch

elena



Elena Zannoni writes:
 > 
 > This is an interesting buglet:
 > 
 > [ezannoni@tomago gdb]$ cat ~/buglet.c
 > int a = 5;
 > int main (void)
 > {
 >   int sum = 0;
 >   printf ("hello\n");
 >   while ( a > 0)
 >   {
 >     sum += a;
 >     a--;
 >   }
 >   printf ("sum is %d\n", sum);
 >   printf ("bye\n");
 >   return 0;
 > }
 > 
 > 
 > [ezannoni@tomago gdb]$ gdb ~/buglet
 > GNU gdb Red Hat Linux (5.3.90-0.20030710.2rh)
 > Copyright 2003 Free Software Foundation, Inc.
 > GDB is free software, covered by the GNU General Public License, and you are
 > welcome to change it and/or distribute copies of it under certain conditions.
 > Type "show copying" to see the conditions.
 > There is absolutely no warranty for GDB.  Type "show warranty" for details.
 > This GDB was configured as "i386-redhat-linux-gnu"...
 > Setting up the environment for debugging gdb.
 > .gdbinit:5: Error in sourced command file:
 > Function "internal_error" not defined.
 > (gdb) l 
 > 1	int a = 5;
 > 2	int main (void)
 > 3	{
 > 4	  int sum = 0;
 > 5	  printf ("hello\n");
 > 6	  while ( a > 0)
 > 7	  {
 > 8	    sum += a;
 > 9	    a--;
 > 10	  }
 > (gdb) p a
 > $1 = 5
 > (gdb) p sum
 > No symbol "sum" in current context.
 > (gdb) ptype a
 > type = int
 > (gdb) ptype sum
 > No symbol "sum" in current context.
 > (gdb) info addr a
 > Symbol "a" is static storage at address 0x80494b4.
 > (gdb) info addr sum
 > Symbol "sum" is a field of the local class variable `this'
 > 
 > Whoops. 
 > 
 > This is because lookup_symbol in address_info() returns null, and also
 > doesn't initialize *is_a_field_of_this to anything.
 > 
 > I suspect a similar situation can happen in any of the callers of
 > lookup_symbol that set the is_a_field_of_this to a non-null value.
 > 
 > David, you are the one that played around with all this, looks ok to
 > you?
 > 
 > elena
 > 
 > 
 > 2003-08-07  Elena Zannoni  <ezannoni@redhat.com>
 > 
 > 	* symtab.c (lookup_symbol_aux): Make sure that is_a_field_of_this
 > 	contains something meaningful at all times.
 > 
 > 
 > 
 > diff -u -p -r1.113 symtab.c
 > --- symtab.c	12 Jun 2003 15:52:08 -0000	1.113
 > +++ symtab.c	7 Aug 2003 15:33:08 -0000
 > @@ -945,6 +945,14 @@ lookup_symbol_aux (const char *name, con
 >  {
 >    struct symbol *sym;
 >  
 > +  /* 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
 > +     certainly use it later and expect it to be either 0 or 1.
 > +     If we don't set it, the contents of is_a_field_of_this are
 > +     undefined.  */
 > +  if (is_a_field_of_this != NULL)
 > +    *is_a_field_of_this = 0;
 > +
 >    /* Search specified block and its superiors.  Don't search
 >       STATIC_BLOCK or GLOBAL_BLOCK.  */
 >  
 > @@ -961,7 +969,6 @@ lookup_symbol_aux (const char *name, con
 >      {
 >        struct value *v = current_language->la_value_of_this (0);
 >  
 > -      *is_a_field_of_this = 0;
 >        if (v && check_field (v, name))
 >  	{
 >  	  *is_a_field_of_this = 1;


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

end of thread, other threads:[~2003-08-08 14:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-07 16:21 [PATCH] fix lookup_symbol foobar Elena Zannoni
2003-08-07 18:19 ` David Carlton
2003-08-08 14:06 ` Elena Zannoni

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