Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Elena Zannoni <ezannoni@redhat.com>
To: carlton@kealia.com, gdb-patches@sources.redhat.com
Subject: [PATCH] fix lookup_symbol foobar
Date: Thu, 07 Aug 2003 16:21:00 -0000	[thread overview]
Message-ID: <16178.32321.697363.540270@localhost.redhat.com> (raw)


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;


             reply	other threads:[~2003-08-07 16:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-07 16:21 Elena Zannoni [this message]
2003-08-07 18:19 ` David Carlton
2003-08-08 14:06 ` Elena Zannoni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16178.32321.697363.540270@localhost.redhat.com \
    --to=ezannoni@redhat.com \
    --cc=carlton@kealia.com \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox