This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [PATCH] fix lookup_symbol foobar
- From: Elena Zannoni <ezannoni at redhat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Fri, 8 Aug 2003 10:14:30 -0400
- Subject: Re: [PATCH] fix lookup_symbol foobar
- References: <16178.32321.697363.540270@localhost.redhat.com>
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;