* symtab.c (lookup_symbol): Need to check if msymbol->name is

NULL, as ALL_MSYMBOLS will never return a NULL msymbol pointer.
This prevents a crash when trying to lookup the value of a
non-existent symbol.
This commit is contained in:
Stu Grossman 1992-04-22 17:01:22 +00:00
parent 4ace50a510
commit 35a258406b
2 changed files with 365 additions and 442 deletions

View File

@ -1,3 +1,10 @@
Wed Apr 22 09:55:42 1992 Stu Grossman (grossman at cygnus.com)
* symtab.c (lookup_symbol): Need to check if msymbol->name is
NULL, as ALL_MSYMBOLS will never return a NULL msymbol pointer.
This prevents a crash when trying to lookup the value of a
non-existent symbol.
Wed Apr 22 09:42:15 1992 Fred Fish (fnf@cygnus.com)
* signame.c, signame.h: Remove, replaced by strsignal.c in
@ -142,6 +149,12 @@ Tue Apr 14 22:33:55 1992 Fred Fish (fnf@cygnus.com)
for now removed unsigned_type_table, signed_type_table, and
float_type_table.
Tue Apr 14 14:30:46 1992 Stu Grossman (grossman at cygnus.com)
* remote-vx.c, vx-share/xdr_ptrace.c, vx-share/xdr_ptrace.h,
vx-share/xdr_rdb.h: Update for new remote protocol under VxWorks
5.0.2.
Mon Apr 13 20:59:21 1992 Fred Fish (fnf@cygnus.com)
* dwarfread.c (target_to_host): New function similar to previous

View File

@ -1,5 +1,6 @@
/* Symbol table lookup for the GNU debugger, GDB.
Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
Free Software Foundation, Inc.
This file is part of GDB.
@ -25,7 +26,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "target.h"
#include "value.h"
#include "symfile.h"
#include "objfiles.h"
#include "gdbcmd.h"
#include "call-cmds.h"
#include "regex.h"
#include "expression.h"
#include "language.h"
@ -51,23 +54,23 @@ static struct symtabs_and_lines
decode_line_2 PARAMS ((struct symbol *[], int, int));
static void
rbreak_command PARAMS ((char *));
rbreak_command PARAMS ((char *, int));
static void
types_info PARAMS ((char *));
types_info PARAMS ((char *, int));
static void
functions_info PARAMS ((char *));
functions_info PARAMS ((char *, int));
static void
variables_info PARAMS ((char *));
variables_info PARAMS ((char *, int));
static void
sources_info PARAMS ((char *, int));
static void
list_symbols PARAMS ((char *, int, int));
static void
sources_info PARAMS ((void));
static void
output_source_filename PARAMS ((char *, int *));
@ -114,24 +117,19 @@ lookup_symtab_1 (name)
{
register struct symtab *s;
register struct partial_symtab *ps;
register char *slash = strchr (name, '/');
register int len = strlen (name);
register char *slash;
register int len;
register struct objfile *objfile;
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (s = objfile -> symtabs; s != NULL; s = s -> next)
ALL_SYMTABS (objfile, s)
{
if (strcmp (name, s->filename) == 0)
{
return (s);
}
}
}
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (ps = objfile -> psymtabs; ps != NULL; ps = ps->next)
ALL_PSYMTABS (objfile, ps)
{
if (strcmp (name, ps -> filename) == 0)
{
@ -142,30 +140,30 @@ lookup_symtab_1 (name)
return (PSYMTAB_TO_SYMTAB (ps));
}
}
}
slash = strchr (name, '/');
len = strlen (name);
if (!slash)
{
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (s = objfile -> symtabs; s != NULL; s = s -> next)
ALL_SYMTABS (objfile, s)
{
int l = strlen (s->filename);
if (s->filename[l - len -1] == '/'
if (l > len
&& s->filename[l - len -1] == '/'
&& (strcmp (s->filename + l - len, name) == 0))
{
return (s);
}
}
}
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (ps = objfile -> psymtabs; ps != NULL; ps = ps -> next)
ALL_PSYMTABS (objfile, ps)
{
int l = strlen (ps -> filename);
if (ps -> filename[l - len - 1] == '/'
if (l > len
&& ps -> filename[l - len - 1] == '/'
&& (strcmp (ps->filename + l - len, name) == 0))
{
if (ps -> readin)
@ -176,7 +174,6 @@ lookup_symtab_1 (name)
}
}
}
}
return (NULL);
}
@ -216,16 +213,13 @@ char *name;
register struct partial_symtab *pst;
register struct objfile *objfile;
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (pst = objfile -> psymtabs; pst != NULL; pst = pst -> next)
ALL_PSYMTABS (objfile, pst)
{
if (strcmp (name, pst -> filename) == 0)
{
return (pst);
}
}
}
return (NULL);
}
@ -294,16 +288,13 @@ find_pc_psymtab (pc)
register struct partial_symtab *pst;
register struct objfile *objfile;
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (pst = objfile -> psymtabs; pst != NULL; pst = pst -> next)
ALL_PSYMTABS (objfile, pst)
{
if (pc >= pst -> textlow && pc < pst -> texthigh)
{
return (pst);
}
}
}
return (NULL);
}
@ -342,40 +333,6 @@ find_pc_psymbol (psymtab, pc)
}
/* Function called via iterate_over_msymbols() that tests a minimal symbol
to see if the minimal symbol's name is a C++ mangled name that matches
a user visible name. The user visible name (pname) is passed as arg1
and the number of leading characters that must match in both the mangled
name and the user name (matchcount) is passed as arg2. Returns a pointer
to the minimal symbol if it matches, NULL otherwise. */
static PTR
cplus_mangled_symbol (objfile, msymbol, arg1, arg2, arg3)
struct objfile *objfile;
struct minimal_symbol *msymbol;
PTR arg1;
PTR arg2;
PTR arg3;
{
char *pname = (char *) arg1;
int matchcount = (int) arg2;
char *demangled;
struct minimal_symbol *foundit = NULL;
if (strncmp (msymbol -> name, pname, matchcount) == 0)
{
if ((demangled = cplus_demangle (msymbol -> name, -1)) != NULL)
{
if (strcmp (demangled, pname) == 0)
{
foundit = msymbol;
}
free (demangled);
}
}
return ((PTR) foundit);
}
/* Find the definition for a specified symbol name NAME
in namespace NAMESPACE, visible from lexical block BLOCK.
Returns the struct symbol pointer, or zero if no symbol is found.
@ -401,7 +358,6 @@ lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
struct blockvector *bv;
register struct objfile *objfile;
register struct block *b;
register int found;
register struct minimal_symbol *msymbol;
/* Search specified block and its superiors. */
@ -416,22 +372,15 @@ lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
{
/* Search the list of symtabs for one which contains the
address of the start of this block. */
for (found = 0, objfile = object_files;
!found && objfile != NULL;
objfile = objfile -> next)
{
for (s = objfile -> symtabs; s != NULL; s = s -> next)
ALL_SYMTABS (objfile, s)
{
bv = BLOCKVECTOR (s);
b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
if (BLOCK_START (b) <= BLOCK_START (block)
&& BLOCK_END (b) > BLOCK_START (block))
{
found++;
break;
}
}
goto found;
}
found:
*symtab = s;
}
@ -451,9 +400,7 @@ lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
{
struct block *b;
/* Find the right symtab. */
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (s = objfile -> symtabs; s != NULL; s = s -> next)
ALL_SYMTABS (objfile, s)
{
bv = BLOCKVECTOR (s);
b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
@ -471,7 +418,6 @@ lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
}
}
}
}
/* C++: If requested to do so by the caller,
@ -493,9 +439,7 @@ lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
/* Now search all global blocks. Do the symtab's first, then
check the psymtab's */
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (s = objfile -> symtabs; s != NULL; s = s -> next)
ALL_SYMTABS (objfile, s)
{
bv = BLOCKVECTOR (s);
block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
@ -508,7 +452,6 @@ lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
return sym;
}
}
}
/* Check for the possibility of the symbol being a global function
that is stored in one of the minimal symbol tables. Eventually, all
@ -517,14 +460,35 @@ lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
if (namespace == VAR_NAMESPACE)
{
msymbol = lookup_minimal_symbol (name, (struct objfile *) NULL);
if (msymbol == NULL)
{
/* Look for a mangled C++ name for NAME. */
msymbol = (struct minimal_symbol *)
iterate_over_msymbols (cplus_mangled_symbol, (PTR) name,
(PTR) strlen (name), (PTR) NULL);
/* Test each minimal symbol to see if the minimal symbol's name
is a C++ mangled name that matches a user visible name. */
int matchcount = strlen (name);
char *demangled;
ALL_MSYMBOLS (objfile, msymbol)
{
if (strncmp (msymbol -> name, name, matchcount) == 0)
{
demangled = cplus_demangle (msymbol -> name, -1);
if (demangled != NULL)
{
if (strcmp (demangled, name) == 0)
{
free (demangled);
goto found_msym;
}
if (msymbol != NULL)
free (demangled);
}
}
}
}
found_msym:
if (msymbol != NULL && msymbol -> name != NULL)
{
s = find_pc_symtab (msymbol -> address);
/* If S is NULL, there are no debug symbols for this file.
@ -562,9 +526,7 @@ lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
}
}
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (ps = objfile -> psymtabs; ps != NULL; ps = ps->next)
ALL_PSYMTABS (objfile, ps)
{
if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
{
@ -579,15 +541,12 @@ lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
return sym;
}
}
}
/* Now search all per-file blocks.
Not strictly correct, but more useful than an error.
Do the symtabs first, then check the psymtabs */
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (s = objfile -> symtabs; s != NULL; s = s -> next)
ALL_SYMTABS (objfile, s)
{
bv = BLOCKVECTOR (s);
block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
@ -600,11 +559,8 @@ lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
return sym;
}
}
}
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (ps = objfile -> psymtabs; ps != NULL; ps = ps -> next)
ALL_PSYMTABS (objfile, ps)
{
if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
{
@ -619,16 +575,13 @@ lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
return sym;
}
}
}
/* Now search all per-file blocks for static mangled symbols.
Do the symtabs first, then check the psymtabs. */
if (namespace == VAR_NAMESPACE)
{
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (s = objfile -> symtabs; s != NULL; s = s -> next)
ALL_SYMTABS (objfile, s)
{
bv = BLOCKVECTOR (s);
block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
@ -641,11 +594,8 @@ lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
return sym;
}
}
}
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (ps = objfile -> psymtabs; ps != NULL; ps = ps -> next)
ALL_PSYMTABS (objfile, ps)
{
if (!ps->readin && lookup_demangled_partial_symbol (ps, name))
{
@ -661,7 +611,6 @@ lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
}
}
}
}
if (symtab != NULL)
*symtab = NULL;
@ -808,16 +757,13 @@ find_main_psymtab ()
register struct partial_symtab *pst;
register struct objfile *objfile;
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (pst = objfile -> psymtabs; pst; pst = pst->next)
ALL_PSYMTABS (objfile, pst)
{
if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE))
{
return (pst);
}
}
}
return (NULL);
}
@ -940,25 +886,16 @@ find_pc_symtab (pc)
register struct symtab *s = 0;
register struct partial_symtab *ps;
register struct objfile *objfile;
register int found;
/* Search all symtabs for one whose file contains our pc */
for (found = 0, objfile = object_files;
!found && objfile != NULL;
objfile = objfile -> next)
{
for (s = objfile -> symtabs; s != NULL; s = s -> next)
ALL_SYMTABS (objfile, s)
{
bv = BLOCKVECTOR (s);
b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
if (BLOCK_START (b) <= pc
&& BLOCK_END (b) > pc)
{
found++;
break;
}
}
goto found;
}
if (!s)
@ -974,6 +911,7 @@ find_pc_symtab (pc)
}
}
found:
return (s);
}
@ -2009,7 +1947,9 @@ output_source_filename (name, first)
}
static void
sources_info ()
sources_info (ignore, from_tty)
char *ignore;
int from_tty;
{
register struct symtab *s;
register struct partial_symtab *ps;
@ -2024,28 +1964,22 @@ sources_info ()
printf_filtered ("Source files for which symbols have been read in:\n\n");
first = 1;
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (s = objfile -> symtabs; s != NULL; s = s -> next)
ALL_SYMTABS (objfile, s)
{
output_source_filename (s -> filename, &first);
}
}
printf_filtered ("\n\n");
printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
first = 1;
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (ps = objfile -> psymtabs; ps != NULL; ps = ps -> next)
ALL_PSYMTABS (objfile, ps)
{
if (!ps->readin)
{
output_source_filename (ps -> filename, &first);
}
}
}
printf_filtered ("\n");
}
@ -2089,8 +2023,7 @@ list_symbols (regexp, class, bpt)
struct partial_symbol *psym;
struct objfile *objfile;
struct minimal_symbol *msymbol;
char *val, *q2;
/* char *mangled;*/
char *val;
static char *classnames[]
= {"variable", "function", "type", "method"};
int found_in_file = 0;
@ -2102,7 +2035,6 @@ list_symbols (regexp, class, bpt)
enum minimal_symbol_type ourtype = types[class];
enum minimal_symbol_type ourtype2 = types2[class];
if (regexp)
{
/* Make sure spacing is right for C++ operators.
@ -2143,9 +2075,7 @@ list_symbols (regexp, class, bpt)
matching the regexp. That way we don't have to reproduce all of
the machinery below. */
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (ps = objfile -> psymtabs; ps != NULL; ps = ps -> next)
ALL_PSYMTABS (objfile, ps)
{
struct partial_symbol *bound, *gbound, *sbound;
int keep_going = 1;
@ -2192,7 +2122,6 @@ list_symbols (regexp, class, bpt)
psym++;
}
}
}
/* Here, we search through the minimal symbol tables for functions that
match, and call find_pc_symtab on them to force their symbols to
@ -2202,10 +2131,7 @@ list_symbols (regexp, class, bpt)
if (class == 1)
{
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (msymbol = objfile -> msymbols;
msymbol -> name != NULL; msymbol++)
ALL_MSYMBOLS (objfile, msymbol)
{
if (msymbol -> type == ourtype || msymbol -> type == ourtype2)
{
@ -2219,7 +2145,6 @@ list_symbols (regexp, class, bpt)
}
}
}
}
/* Printout here so as to get after the "Reading in symbols"
messages which will be generated above. */
@ -2230,9 +2155,7 @@ list_symbols (regexp, class, bpt)
classnames[class],
regexp);
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (s = objfile -> symtabs; s != NULL; s = s -> next)
ALL_SYMTABS (objfile, s)
{
found_in_file = 0;
bv = BLOCKVECTOR (s);
@ -2295,6 +2218,7 @@ list_symbols (regexp, class, bpt)
else
{
# if 0
/* FIXME, why is this zapped out? */
char buf[1024];
type_print_base (TYPE_FN_FIELD_TYPE(t, i), stdout, 0, 0);
type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), stdout, 0);
@ -2307,7 +2231,6 @@ list_symbols (regexp, class, bpt)
}
prev_bv = bv;
}
}
/* If there are no eyes, avoid all contact. I mean, if there are
no debug symbols, then print directly from the msymbol_vector. */
@ -2315,10 +2238,7 @@ list_symbols (regexp, class, bpt)
if (found_misc || class != 1)
{
found_in_file = 0;
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (msymbol = objfile -> msymbols;
msymbol -> name != NULL; msymbol++)
ALL_MSYMBOLS (objfile, msymbol)
{
if (msymbol -> type == ourtype || msymbol -> type == ourtype2)
{
@ -2348,25 +2268,27 @@ list_symbols (regexp, class, bpt)
}
}
}
}
static void
variables_info (regexp)
variables_info (regexp, from_tty)
char *regexp;
int from_tty;
{
list_symbols (regexp, 0, 0);
}
static void
functions_info (regexp)
functions_info (regexp, from_tty)
char *regexp;
int from_tty;
{
list_symbols (regexp, 1, 0);
}
static void
types_info (regexp)
types_info (regexp, from_tty)
char *regexp;
int from_tty;
{
list_symbols (regexp, 2, 0);
}
@ -2383,8 +2305,9 @@ methods_info (regexp)
/* Breakpoint all functions matching regular expression. */
static void
rbreak_command (regexp)
rbreak_command (regexp, from_tty)
char *regexp;
int from_tty;
{
list_symbols (regexp, 1, 1);
}
@ -2455,9 +2378,7 @@ make_symbol_completion_list (text)
/* Look through the partial symtabs for all symbols which begin
by matching TEXT. Add each one that you find to the list. */
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (ps = objfile -> psymtabs; ps != NULL; ps = ps -> next)
ALL_PSYMTABS (objfile, ps)
{
/* If the psymtab's been read in we'll get it when we search
through the blockvector. */
@ -2483,24 +2404,19 @@ make_symbol_completion_list (text)
completion_list_add_symbol (SYMBOL_NAME (psym));
}
}
}
/* At this point scan through the misc symbol vectors and add each
symbol you find to the list. Eventually we want to ignore
anything that isn't a text symbol (everything else will be
handled by the psymtab code above). */
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (msymbol = objfile -> msymbols;
msymbol ->name != NULL; msymbol++)
ALL_MSYMBOLS (objfile, msymbol)
{
if (strncmp (text, msymbol -> name, text_len) == 0)
{
completion_list_add_symbol (msymbol -> name);
}
}
}
/* Search upwards from currently selected frame (so that we can
complete on local vars. */
@ -2536,9 +2452,7 @@ make_symbol_completion_list (text)
/* Go through the symtabs and check the externs and statics for
symbols which match. */
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (s = objfile ->symtabs; s != NULL; s = s -> next)
ALL_SYMTABS (objfile, s)
{
b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
@ -2546,11 +2460,8 @@ make_symbol_completion_list (text)
if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len))
completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i)));
}
}
for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
{
for (s = objfile -> symtabs; s != NULL; s = s -> next)
ALL_SYMTABS (objfile, s)
{
b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
@ -2561,7 +2472,6 @@ make_symbol_completion_list (text)
if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len))
completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i)));
}
}
return (return_val);
}