1*65860Sbostic /* Symbol table lookup for the GNU debugger, GDB.
2*65860Sbostic Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
3*65860Sbostic Free Software Foundation, Inc.
4*65860Sbostic
5*65860Sbostic This file is part of GDB.
6*65860Sbostic
7*65860Sbostic This program is free software; you can redistribute it and/or modify
8*65860Sbostic it under the terms of the GNU General Public License as published by
9*65860Sbostic the Free Software Foundation; either version 2 of the License, or
10*65860Sbostic (at your option) any later version.
11*65860Sbostic
12*65860Sbostic This program is distributed in the hope that it will be useful,
13*65860Sbostic but WITHOUT ANY WARRANTY; without even the implied warranty of
14*65860Sbostic MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*65860Sbostic GNU General Public License for more details.
16*65860Sbostic
17*65860Sbostic You should have received a copy of the GNU General Public License
18*65860Sbostic along with this program; if not, write to the Free Software
19*65860Sbostic Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20*65860Sbostic
21*65860Sbostic #include "defs.h"
22*65860Sbostic #include "symtab.h"
23*65860Sbostic #include "gdbtypes.h"
24*65860Sbostic #include "gdbcore.h"
25*65860Sbostic #include "frame.h"
26*65860Sbostic #include "target.h"
27*65860Sbostic #include "value.h"
28*65860Sbostic #include "symfile.h"
29*65860Sbostic #include "objfiles.h"
30*65860Sbostic #include "gdbcmd.h"
31*65860Sbostic #include "call-cmds.h"
32*65860Sbostic #include "regex.h"
33*65860Sbostic #include "expression.h"
34*65860Sbostic #include "language.h"
35*65860Sbostic #include "demangle.h"
36*65860Sbostic
37*65860Sbostic #include <obstack.h>
38*65860Sbostic #include <assert.h>
39*65860Sbostic
40*65860Sbostic #include <sys/types.h>
41*65860Sbostic #include <fcntl.h>
42*65860Sbostic #include <string.h>
43*65860Sbostic #include <sys/stat.h>
44*65860Sbostic #include <ctype.h>
45*65860Sbostic
46*65860Sbostic /* Prototypes for local functions */
47*65860Sbostic
48*65860Sbostic static char *
49*65860Sbostic expensive_mangler PARAMS ((const char *));
50*65860Sbostic
51*65860Sbostic extern int
52*65860Sbostic find_methods PARAMS ((struct type *, char *, char **, struct symbol **));
53*65860Sbostic
54*65860Sbostic static void
55*65860Sbostic completion_list_add_symbol PARAMS ((char *, char *, int));
56*65860Sbostic
57*65860Sbostic static struct symtabs_and_lines
58*65860Sbostic decode_line_2 PARAMS ((struct symbol *[], int, int));
59*65860Sbostic
60*65860Sbostic static void
61*65860Sbostic rbreak_command PARAMS ((char *, int));
62*65860Sbostic
63*65860Sbostic static void
64*65860Sbostic types_info PARAMS ((char *, int));
65*65860Sbostic
66*65860Sbostic static void
67*65860Sbostic functions_info PARAMS ((char *, int));
68*65860Sbostic
69*65860Sbostic static void
70*65860Sbostic variables_info PARAMS ((char *, int));
71*65860Sbostic
72*65860Sbostic static void
73*65860Sbostic sources_info PARAMS ((char *, int));
74*65860Sbostic
75*65860Sbostic static void
76*65860Sbostic list_symbols PARAMS ((char *, int, int));
77*65860Sbostic
78*65860Sbostic static void
79*65860Sbostic output_source_filename PARAMS ((char *, int *));
80*65860Sbostic
81*65860Sbostic static char *
82*65860Sbostic operator_chars PARAMS ((char *, char **));
83*65860Sbostic
84*65860Sbostic static int
85*65860Sbostic find_line_common PARAMS ((struct linetable *, int, int *));
86*65860Sbostic
87*65860Sbostic static struct partial_symbol *
88*65860Sbostic lookup_partial_symbol PARAMS ((struct partial_symtab *, const char *,
89*65860Sbostic int, enum namespace));
90*65860Sbostic
91*65860Sbostic static struct partial_symbol *
92*65860Sbostic lookup_demangled_partial_symbol PARAMS ((const struct partial_symtab *,
93*65860Sbostic const char *));
94*65860Sbostic
95*65860Sbostic static struct symbol *
96*65860Sbostic lookup_demangled_block_symbol PARAMS ((const struct block *, const char *));
97*65860Sbostic
98*65860Sbostic static struct symtab *
99*65860Sbostic lookup_symtab_1 PARAMS ((char *));
100*65860Sbostic
101*65860Sbostic /* */
102*65860Sbostic
103*65860Sbostic /* The single non-language-specific builtin type */
104*65860Sbostic struct type *builtin_type_error;
105*65860Sbostic
106*65860Sbostic /* Block in which the most recently searched-for symbol was found.
107*65860Sbostic Might be better to make this a parameter to lookup_symbol and
108*65860Sbostic value_of_this. */
109*65860Sbostic
110*65860Sbostic const struct block *block_found;
111*65860Sbostic
112*65860Sbostic char no_symtab_msg[] = "No symbol table is loaded. Use the \"file\" command.";
113*65860Sbostic
114*65860Sbostic /* While the C++ support is still in flux, issue a possibly helpful hint on
115*65860Sbostic using the new command completion feature on single quoted demangled C++
116*65860Sbostic symbols. Remove when loose ends are cleaned up. FIXME -fnf */
117*65860Sbostic
118*65860Sbostic void
cplusplus_hint(name)119*65860Sbostic cplusplus_hint (name)
120*65860Sbostic char *name;
121*65860Sbostic {
122*65860Sbostic printf ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name, name);
123*65860Sbostic printf ("(Note leading single quote.)\n");
124*65860Sbostic }
125*65860Sbostic
126*65860Sbostic /* Check for a symtab of a specific name; first in symtabs, then in
127*65860Sbostic psymtabs. *If* there is no '/' in the name, a match after a '/'
128*65860Sbostic in the symtab filename will also work. */
129*65860Sbostic
130*65860Sbostic static struct symtab *
lookup_symtab_1(name)131*65860Sbostic lookup_symtab_1 (name)
132*65860Sbostic char *name;
133*65860Sbostic {
134*65860Sbostic register struct symtab *s;
135*65860Sbostic register struct partial_symtab *ps;
136*65860Sbostic register char *slash;
137*65860Sbostic register struct objfile *objfile;
138*65860Sbostic
139*65860Sbostic got_symtab:
140*65860Sbostic
141*65860Sbostic /* First, search for an exact match */
142*65860Sbostic
143*65860Sbostic ALL_SYMTABS (objfile, s)
144*65860Sbostic if (strcmp (name, s->filename) == 0)
145*65860Sbostic return s;
146*65860Sbostic
147*65860Sbostic slash = strchr (name, '/');
148*65860Sbostic
149*65860Sbostic /* Now, search for a matching tail (only if name doesn't have any dirs) */
150*65860Sbostic
151*65860Sbostic if (!slash)
152*65860Sbostic ALL_SYMTABS (objfile, s)
153*65860Sbostic {
154*65860Sbostic char *p = s -> filename;
155*65860Sbostic char *tail = strrchr (p, '/');
156*65860Sbostic
157*65860Sbostic if (tail)
158*65860Sbostic p = tail + 1;
159*65860Sbostic
160*65860Sbostic if (strcmp (p, name) == 0)
161*65860Sbostic return s;
162*65860Sbostic }
163*65860Sbostic
164*65860Sbostic /* Same search rules as above apply here, but now we look thru the
165*65860Sbostic psymtabs. */
166*65860Sbostic
167*65860Sbostic ALL_PSYMTABS (objfile, ps)
168*65860Sbostic if (strcmp (name, ps -> filename) == 0)
169*65860Sbostic goto got_psymtab;
170*65860Sbostic
171*65860Sbostic if (!slash)
172*65860Sbostic ALL_PSYMTABS (objfile, ps)
173*65860Sbostic {
174*65860Sbostic char *p = ps -> filename;
175*65860Sbostic char *tail = strrchr (p, '/');
176*65860Sbostic
177*65860Sbostic if (tail)
178*65860Sbostic p = tail + 1;
179*65860Sbostic
180*65860Sbostic if (strcmp (p, name) == 0)
181*65860Sbostic goto got_psymtab;
182*65860Sbostic }
183*65860Sbostic
184*65860Sbostic return (NULL);
185*65860Sbostic
186*65860Sbostic got_psymtab:
187*65860Sbostic
188*65860Sbostic if (ps -> readin)
189*65860Sbostic error ("Internal: readin %s pst for `%s' found when no symtab found.",
190*65860Sbostic ps -> filename, name);
191*65860Sbostic
192*65860Sbostic s = PSYMTAB_TO_SYMTAB (ps);
193*65860Sbostic
194*65860Sbostic if (s)
195*65860Sbostic return s;
196*65860Sbostic
197*65860Sbostic /* At this point, we have located the psymtab for this file, but
198*65860Sbostic the conversion to a symtab has failed. This usually happens
199*65860Sbostic when we are looking up an include file. In this case,
200*65860Sbostic PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
201*65860Sbostic been created. So, we need to run through the symtabs again in
202*65860Sbostic order to find the file.
203*65860Sbostic XXX - This is a crock, and should be fixed inside of the the
204*65860Sbostic symbol parsing routines. */
205*65860Sbostic goto got_symtab;
206*65860Sbostic }
207*65860Sbostic
208*65860Sbostic /* Lookup the symbol table of a source file named NAME. Try a couple
209*65860Sbostic of variations if the first lookup doesn't work. */
210*65860Sbostic
211*65860Sbostic struct symtab *
lookup_symtab(name)212*65860Sbostic lookup_symtab (name)
213*65860Sbostic char *name;
214*65860Sbostic {
215*65860Sbostic register struct symtab *s;
216*65860Sbostic register char *copy;
217*65860Sbostic
218*65860Sbostic s = lookup_symtab_1 (name);
219*65860Sbostic if (s) return s;
220*65860Sbostic
221*65860Sbostic /* If name not found as specified, see if adding ".c" helps. */
222*65860Sbostic
223*65860Sbostic copy = (char *) alloca (strlen (name) + 3);
224*65860Sbostic strcpy (copy, name);
225*65860Sbostic strcat (copy, ".c");
226*65860Sbostic s = lookup_symtab_1 (copy);
227*65860Sbostic if (s) return s;
228*65860Sbostic
229*65860Sbostic /* We didn't find anything; die. */
230*65860Sbostic return 0;
231*65860Sbostic }
232*65860Sbostic
233*65860Sbostic /* Lookup the partial symbol table of a source file named NAME. This
234*65860Sbostic only returns true on an exact match (ie. this semantics are
235*65860Sbostic different from lookup_symtab. */
236*65860Sbostic
237*65860Sbostic struct partial_symtab *
lookup_partial_symtab(name)238*65860Sbostic lookup_partial_symtab (name)
239*65860Sbostic char *name;
240*65860Sbostic {
241*65860Sbostic register struct partial_symtab *pst;
242*65860Sbostic register struct objfile *objfile;
243*65860Sbostic
244*65860Sbostic ALL_PSYMTABS (objfile, pst)
245*65860Sbostic {
246*65860Sbostic if (strcmp (name, pst -> filename) == 0)
247*65860Sbostic {
248*65860Sbostic return (pst);
249*65860Sbostic }
250*65860Sbostic }
251*65860Sbostic return (NULL);
252*65860Sbostic }
253*65860Sbostic
254*65860Sbostic /* Demangle a GDB method stub type. */
255*65860Sbostic char *
gdb_mangle_name(type,i,j)256*65860Sbostic gdb_mangle_name (type, i, j)
257*65860Sbostic struct type *type;
258*65860Sbostic int i, j;
259*65860Sbostic {
260*65860Sbostic int mangled_name_len;
261*65860Sbostic char *mangled_name;
262*65860Sbostic struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
263*65860Sbostic struct fn_field *method = &f[j];
264*65860Sbostic char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
265*65860Sbostic char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
266*65860Sbostic char *newname = type_name_no_tag (type);
267*65860Sbostic int is_constructor = strcmp(field_name, newname) == 0;
268*65860Sbostic int is_destructor = is_constructor && physname[0] == '_'
269*65860Sbostic && physname[1] == CPLUS_MARKER && physname[2] == '_';
270*65860Sbostic /* Need a new type prefix. */
271*65860Sbostic char *const_prefix = method->is_const ? "C" : "";
272*65860Sbostic char *volatile_prefix = method->is_volatile ? "V" : "";
273*65860Sbostic char buf[20];
274*65860Sbostic #ifndef GCC_MANGLE_BUG
275*65860Sbostic int len = strlen (newname);
276*65860Sbostic
277*65860Sbostic if (is_destructor)
278*65860Sbostic {
279*65860Sbostic mangled_name = (char*) xmalloc(strlen(physname)+1);
280*65860Sbostic strcpy(mangled_name, physname);
281*65860Sbostic return mangled_name;
282*65860Sbostic }
283*65860Sbostic
284*65860Sbostic sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
285*65860Sbostic mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
286*65860Sbostic + strlen (buf) + len
287*65860Sbostic + strlen (physname)
288*65860Sbostic + 1);
289*65860Sbostic
290*65860Sbostic /* Only needed for GNU-mangled names. ANSI-mangled names
291*65860Sbostic work with the normal mechanisms. */
292*65860Sbostic if (OPNAME_PREFIX_P (field_name))
293*65860Sbostic {
294*65860Sbostic char *opname = cplus_mangle_opname (field_name + 3, 0);
295*65860Sbostic if (opname == NULL)
296*65860Sbostic error ("No mangling for \"%s\"", field_name);
297*65860Sbostic mangled_name_len += strlen (opname);
298*65860Sbostic mangled_name = (char *)xmalloc (mangled_name_len);
299*65860Sbostic
300*65860Sbostic strncpy (mangled_name, field_name, 3);
301*65860Sbostic mangled_name[3] = '\0';
302*65860Sbostic strcat (mangled_name, opname);
303*65860Sbostic }
304*65860Sbostic else
305*65860Sbostic {
306*65860Sbostic mangled_name = (char *)xmalloc (mangled_name_len);
307*65860Sbostic if (is_constructor)
308*65860Sbostic mangled_name[0] = '\0';
309*65860Sbostic else
310*65860Sbostic strcpy (mangled_name, field_name);
311*65860Sbostic }
312*65860Sbostic strcat (mangled_name, buf);
313*65860Sbostic strcat (mangled_name, newname);
314*65860Sbostic #else
315*65860Sbostic char *opname;
316*65860Sbostic
317*65860Sbostic if (is_constructor)
318*65860Sbostic {
319*65860Sbostic buf[0] = '\0';
320*65860Sbostic }
321*65860Sbostic else
322*65860Sbostic {
323*65860Sbostic sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
324*65860Sbostic }
325*65860Sbostic
326*65860Sbostic mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
327*65860Sbostic + strlen (buf) + strlen (physname) + 1);
328*65860Sbostic
329*65860Sbostic /* Only needed for GNU-mangled names. ANSI-mangled names
330*65860Sbostic work with the normal mechanisms. */
331*65860Sbostic if (OPNAME_PREFIX_P (field_name))
332*65860Sbostic {
333*65860Sbostic opname = cplus_mangle_opname (field_name + 3, 0);
334*65860Sbostic if (opname == NULL)
335*65860Sbostic {
336*65860Sbostic error ("No mangling for \"%s\"", field_name);
337*65860Sbostic }
338*65860Sbostic mangled_name_len += strlen (opname);
339*65860Sbostic mangled_name = (char *) xmalloc (mangled_name_len);
340*65860Sbostic
341*65860Sbostic strncpy (mangled_name, field_name, 3);
342*65860Sbostic strcpy (mangled_name + 3, opname);
343*65860Sbostic }
344*65860Sbostic else
345*65860Sbostic {
346*65860Sbostic mangled_name = (char *) xmalloc (mangled_name_len);
347*65860Sbostic if (is_constructor)
348*65860Sbostic {
349*65860Sbostic mangled_name[0] = '\0';
350*65860Sbostic }
351*65860Sbostic else
352*65860Sbostic {
353*65860Sbostic strcpy (mangled_name, field_name);
354*65860Sbostic }
355*65860Sbostic }
356*65860Sbostic strcat (mangled_name, buf);
357*65860Sbostic
358*65860Sbostic #endif
359*65860Sbostic strcat (mangled_name, physname);
360*65860Sbostic return (mangled_name);
361*65860Sbostic }
362*65860Sbostic
363*65860Sbostic
364*65860Sbostic /* Find which partial symtab on contains PC. Return 0 if none. */
365*65860Sbostic
366*65860Sbostic struct partial_symtab *
find_pc_psymtab(pc)367*65860Sbostic find_pc_psymtab (pc)
368*65860Sbostic register CORE_ADDR pc;
369*65860Sbostic {
370*65860Sbostic register struct partial_symtab *pst;
371*65860Sbostic register struct objfile *objfile;
372*65860Sbostic
373*65860Sbostic ALL_PSYMTABS (objfile, pst)
374*65860Sbostic {
375*65860Sbostic if (pc >= pst -> textlow && pc < pst -> texthigh)
376*65860Sbostic {
377*65860Sbostic return (pst);
378*65860Sbostic }
379*65860Sbostic }
380*65860Sbostic return (NULL);
381*65860Sbostic }
382*65860Sbostic
383*65860Sbostic /* Find which partial symbol within a psymtab contains PC. Return 0
384*65860Sbostic if none. Check all psymtabs if PSYMTAB is 0. */
385*65860Sbostic struct partial_symbol *
find_pc_psymbol(psymtab,pc)386*65860Sbostic find_pc_psymbol (psymtab, pc)
387*65860Sbostic struct partial_symtab *psymtab;
388*65860Sbostic CORE_ADDR pc;
389*65860Sbostic {
390*65860Sbostic struct partial_symbol *best, *p;
391*65860Sbostic CORE_ADDR best_pc;
392*65860Sbostic
393*65860Sbostic if (!psymtab)
394*65860Sbostic psymtab = find_pc_psymtab (pc);
395*65860Sbostic if (!psymtab)
396*65860Sbostic return 0;
397*65860Sbostic
398*65860Sbostic best_pc = psymtab->textlow - 1;
399*65860Sbostic
400*65860Sbostic for (p = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
401*65860Sbostic (p - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
402*65860Sbostic < psymtab->n_static_syms);
403*65860Sbostic p++)
404*65860Sbostic if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
405*65860Sbostic && SYMBOL_CLASS (p) == LOC_BLOCK
406*65860Sbostic && pc >= SYMBOL_VALUE_ADDRESS (p)
407*65860Sbostic && SYMBOL_VALUE_ADDRESS (p) > best_pc)
408*65860Sbostic {
409*65860Sbostic best_pc = SYMBOL_VALUE_ADDRESS (p);
410*65860Sbostic best = p;
411*65860Sbostic }
412*65860Sbostic if (best_pc == psymtab->textlow - 1)
413*65860Sbostic return 0;
414*65860Sbostic return best;
415*65860Sbostic }
416*65860Sbostic
417*65860Sbostic
418*65860Sbostic /* Find the definition for a specified symbol name NAME
419*65860Sbostic in namespace NAMESPACE, visible from lexical block BLOCK.
420*65860Sbostic Returns the struct symbol pointer, or zero if no symbol is found.
421*65860Sbostic If SYMTAB is non-NULL, store the symbol table in which the
422*65860Sbostic symbol was found there, or NULL if not found.
423*65860Sbostic C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
424*65860Sbostic NAME is a field of the current implied argument `this'. If so set
425*65860Sbostic *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
426*65860Sbostic BLOCK_FOUND is set to the block in which NAME is found (in the case of
427*65860Sbostic a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
428*65860Sbostic
429*65860Sbostic struct symbol *
lookup_symbol(name,block,namespace,is_a_field_of_this,symtab)430*65860Sbostic lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
431*65860Sbostic const char *name;
432*65860Sbostic register const struct block *block;
433*65860Sbostic const enum namespace namespace;
434*65860Sbostic int *is_a_field_of_this;
435*65860Sbostic struct symtab **symtab;
436*65860Sbostic {
437*65860Sbostic register struct symbol *sym;
438*65860Sbostic register struct symtab *s;
439*65860Sbostic register struct partial_symtab *ps;
440*65860Sbostic struct blockvector *bv;
441*65860Sbostic register struct objfile *objfile;
442*65860Sbostic register struct block *b;
443*65860Sbostic register struct minimal_symbol *msymbol;
444*65860Sbostic char *temp;
445*65860Sbostic extern char *gdb_completer_word_break_characters;
446*65860Sbostic
447*65860Sbostic /* If NAME contains any characters from gdb_completer_word_break_characters
448*65860Sbostic then it is probably from a quoted name string. So check to see if it
449*65860Sbostic has a C++ mangled equivalent, and if so, use the mangled equivalent. */
450*65860Sbostic
451*65860Sbostic if (strpbrk (name, gdb_completer_word_break_characters) != NULL)
452*65860Sbostic {
453*65860Sbostic if ((temp = expensive_mangler (name)) != NULL)
454*65860Sbostic {
455*65860Sbostic name = temp;
456*65860Sbostic }
457*65860Sbostic }
458*65860Sbostic
459*65860Sbostic /* Search specified block and its superiors. */
460*65860Sbostic
461*65860Sbostic while (block != 0)
462*65860Sbostic {
463*65860Sbostic sym = lookup_block_symbol (block, name, namespace);
464*65860Sbostic if (sym)
465*65860Sbostic {
466*65860Sbostic block_found = block;
467*65860Sbostic if (symtab != NULL)
468*65860Sbostic {
469*65860Sbostic /* Search the list of symtabs for one which contains the
470*65860Sbostic address of the start of this block. */
471*65860Sbostic ALL_SYMTABS (objfile, s)
472*65860Sbostic {
473*65860Sbostic bv = BLOCKVECTOR (s);
474*65860Sbostic b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
475*65860Sbostic if (BLOCK_START (b) <= BLOCK_START (block)
476*65860Sbostic && BLOCK_END (b) > BLOCK_START (block))
477*65860Sbostic goto found;
478*65860Sbostic }
479*65860Sbostic found:
480*65860Sbostic *symtab = s;
481*65860Sbostic }
482*65860Sbostic
483*65860Sbostic return (sym);
484*65860Sbostic }
485*65860Sbostic block = BLOCK_SUPERBLOCK (block);
486*65860Sbostic }
487*65860Sbostic
488*65860Sbostic /* But that doesn't do any demangling for the STATIC_BLOCK.
489*65860Sbostic I'm not sure whether demangling is needed in the case of
490*65860Sbostic nested function in inner blocks; if so this needs to be changed.
491*65860Sbostic
492*65860Sbostic Don't need to mess with the psymtabs; if we have a block,
493*65860Sbostic that file is read in. If we don't, then we deal later with
494*65860Sbostic all the psymtab stuff that needs checking. */
495*65860Sbostic if (namespace == VAR_NAMESPACE && block != NULL)
496*65860Sbostic {
497*65860Sbostic struct block *b;
498*65860Sbostic /* Find the right symtab. */
499*65860Sbostic ALL_SYMTABS (objfile, s)
500*65860Sbostic {
501*65860Sbostic bv = BLOCKVECTOR (s);
502*65860Sbostic b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
503*65860Sbostic if (BLOCK_START (b) <= BLOCK_START (block)
504*65860Sbostic && BLOCK_END (b) > BLOCK_START (block))
505*65860Sbostic {
506*65860Sbostic sym = lookup_demangled_block_symbol (b, name);
507*65860Sbostic if (sym)
508*65860Sbostic {
509*65860Sbostic block_found = b;
510*65860Sbostic if (symtab != NULL)
511*65860Sbostic *symtab = s;
512*65860Sbostic return sym;
513*65860Sbostic }
514*65860Sbostic }
515*65860Sbostic }
516*65860Sbostic }
517*65860Sbostic
518*65860Sbostic
519*65860Sbostic /* C++: If requested to do so by the caller,
520*65860Sbostic check to see if NAME is a field of `this'. */
521*65860Sbostic if (is_a_field_of_this)
522*65860Sbostic {
523*65860Sbostic struct value *v = value_of_this (0);
524*65860Sbostic
525*65860Sbostic *is_a_field_of_this = 0;
526*65860Sbostic if (v && check_field (v, name))
527*65860Sbostic {
528*65860Sbostic *is_a_field_of_this = 1;
529*65860Sbostic if (symtab != NULL)
530*65860Sbostic *symtab = NULL;
531*65860Sbostic return 0;
532*65860Sbostic }
533*65860Sbostic }
534*65860Sbostic
535*65860Sbostic /* Now search all global blocks. Do the symtab's first, then
536*65860Sbostic check the psymtab's */
537*65860Sbostic
538*65860Sbostic ALL_SYMTABS (objfile, s)
539*65860Sbostic {
540*65860Sbostic bv = BLOCKVECTOR (s);
541*65860Sbostic block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
542*65860Sbostic sym = lookup_block_symbol (block, name, namespace);
543*65860Sbostic if (sym)
544*65860Sbostic {
545*65860Sbostic block_found = block;
546*65860Sbostic if (symtab != NULL)
547*65860Sbostic *symtab = s;
548*65860Sbostic return sym;
549*65860Sbostic }
550*65860Sbostic }
551*65860Sbostic
552*65860Sbostic /* Check for the possibility of the symbol being a global function
553*65860Sbostic that is stored in one of the minimal symbol tables. Eventually, all
554*65860Sbostic global symbols might be resolved in this way. */
555*65860Sbostic
556*65860Sbostic if (namespace == VAR_NAMESPACE)
557*65860Sbostic {
558*65860Sbostic msymbol = lookup_minimal_symbol (name, (struct objfile *) NULL);
559*65860Sbostic
560*65860Sbostic if (msymbol == NULL)
561*65860Sbostic {
562*65860Sbostic /* Test each minimal symbol to see if the minimal symbol's name
563*65860Sbostic is a C++ mangled name that matches a user visible name. */
564*65860Sbostic
565*65860Sbostic char *demangled;
566*65860Sbostic
567*65860Sbostic ALL_MSYMBOLS (objfile, msymbol)
568*65860Sbostic {
569*65860Sbostic demangled = demangle_and_match (msymbol -> name, name,
570*65860Sbostic DMGL_PARAMS | DMGL_ANSI);
571*65860Sbostic if (demangled != NULL)
572*65860Sbostic {
573*65860Sbostic free (demangled);
574*65860Sbostic goto found_msym;
575*65860Sbostic }
576*65860Sbostic }
577*65860Sbostic msymbol = NULL; /* Not found */
578*65860Sbostic }
579*65860Sbostic
580*65860Sbostic found_msym:
581*65860Sbostic if (msymbol != NULL)
582*65860Sbostic {
583*65860Sbostic s = find_pc_symtab (msymbol -> address);
584*65860Sbostic /* If S is NULL, there are no debug symbols for this file.
585*65860Sbostic Skip this stuff and check for matching static symbols below. */
586*65860Sbostic if (s != NULL)
587*65860Sbostic {
588*65860Sbostic bv = BLOCKVECTOR (s);
589*65860Sbostic block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
590*65860Sbostic sym = lookup_block_symbol (block, msymbol -> name, namespace);
591*65860Sbostic /* We kept static functions in minimal symbol table as well as
592*65860Sbostic in static scope. We want to find them in the symbol table. */
593*65860Sbostic if (!sym) {
594*65860Sbostic block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
595*65860Sbostic sym = lookup_block_symbol (block, msymbol -> name,
596*65860Sbostic namespace);
597*65860Sbostic }
598*65860Sbostic
599*65860Sbostic /* sym == 0 if symbol was found in the minimal symbol table
600*65860Sbostic but not in the symtab.
601*65860Sbostic Return 0 to use the msymbol definition of "foo_".
602*65860Sbostic
603*65860Sbostic This happens for Fortran "foo_" symbols,
604*65860Sbostic which are "foo" in the symtab.
605*65860Sbostic
606*65860Sbostic This can also happen if "asm" is used to make a
607*65860Sbostic regular symbol but not a debugging symbol, e.g.
608*65860Sbostic asm(".globl _main");
609*65860Sbostic asm("_main:");
610*65860Sbostic */
611*65860Sbostic
612*65860Sbostic if (symtab != NULL)
613*65860Sbostic *symtab = s;
614*65860Sbostic return sym;
615*65860Sbostic }
616*65860Sbostic }
617*65860Sbostic }
618*65860Sbostic
619*65860Sbostic ALL_PSYMTABS (objfile, ps)
620*65860Sbostic {
621*65860Sbostic if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
622*65860Sbostic {
623*65860Sbostic s = PSYMTAB_TO_SYMTAB(ps);
624*65860Sbostic bv = BLOCKVECTOR (s);
625*65860Sbostic block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
626*65860Sbostic sym = lookup_block_symbol (block, name, namespace);
627*65860Sbostic if (!sym)
628*65860Sbostic error ("Internal: global symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);
629*65860Sbostic if (symtab != NULL)
630*65860Sbostic *symtab = s;
631*65860Sbostic return sym;
632*65860Sbostic }
633*65860Sbostic }
634*65860Sbostic
635*65860Sbostic /* Now search all per-file blocks.
636*65860Sbostic Not strictly correct, but more useful than an error.
637*65860Sbostic Do the symtabs first, then check the psymtabs */
638*65860Sbostic
639*65860Sbostic ALL_SYMTABS (objfile, s)
640*65860Sbostic {
641*65860Sbostic bv = BLOCKVECTOR (s);
642*65860Sbostic block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
643*65860Sbostic sym = lookup_block_symbol (block, name, namespace);
644*65860Sbostic if (sym)
645*65860Sbostic {
646*65860Sbostic block_found = block;
647*65860Sbostic if (symtab != NULL)
648*65860Sbostic *symtab = s;
649*65860Sbostic return sym;
650*65860Sbostic }
651*65860Sbostic }
652*65860Sbostic
653*65860Sbostic ALL_PSYMTABS (objfile, ps)
654*65860Sbostic {
655*65860Sbostic if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
656*65860Sbostic {
657*65860Sbostic s = PSYMTAB_TO_SYMTAB(ps);
658*65860Sbostic bv = BLOCKVECTOR (s);
659*65860Sbostic block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
660*65860Sbostic sym = lookup_block_symbol (block, name, namespace);
661*65860Sbostic if (!sym)
662*65860Sbostic error ("Internal: static symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);
663*65860Sbostic if (symtab != NULL)
664*65860Sbostic *symtab = s;
665*65860Sbostic return sym;
666*65860Sbostic }
667*65860Sbostic }
668*65860Sbostic
669*65860Sbostic /* Now search all per-file blocks for static mangled symbols.
670*65860Sbostic Do the symtabs first, then check the psymtabs. */
671*65860Sbostic
672*65860Sbostic if (namespace == VAR_NAMESPACE)
673*65860Sbostic {
674*65860Sbostic ALL_SYMTABS (objfile, s)
675*65860Sbostic {
676*65860Sbostic bv = BLOCKVECTOR (s);
677*65860Sbostic block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
678*65860Sbostic sym = lookup_demangled_block_symbol (block, name);
679*65860Sbostic if (sym)
680*65860Sbostic {
681*65860Sbostic block_found = block;
682*65860Sbostic if (symtab != NULL)
683*65860Sbostic *symtab = s;
684*65860Sbostic return sym;
685*65860Sbostic }
686*65860Sbostic }
687*65860Sbostic
688*65860Sbostic ALL_PSYMTABS (objfile, ps)
689*65860Sbostic {
690*65860Sbostic if (!ps->readin && lookup_demangled_partial_symbol (ps, name))
691*65860Sbostic {
692*65860Sbostic s = PSYMTAB_TO_SYMTAB(ps);
693*65860Sbostic bv = BLOCKVECTOR (s);
694*65860Sbostic block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
695*65860Sbostic sym = lookup_demangled_block_symbol (block, name);
696*65860Sbostic if (!sym)
697*65860Sbostic error ("Internal: mangled static symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);
698*65860Sbostic if (symtab != NULL)
699*65860Sbostic *symtab = s;
700*65860Sbostic return sym;
701*65860Sbostic }
702*65860Sbostic }
703*65860Sbostic }
704*65860Sbostic
705*65860Sbostic if (symtab != NULL)
706*65860Sbostic *symtab = NULL;
707*65860Sbostic return 0;
708*65860Sbostic }
709*65860Sbostic
710*65860Sbostic /* Look for a static demangled symbol in block BLOCK. */
711*65860Sbostic
712*65860Sbostic static struct symbol *
lookup_demangled_block_symbol(block,name)713*65860Sbostic lookup_demangled_block_symbol (block, name)
714*65860Sbostic register const struct block *block;
715*65860Sbostic const char *name;
716*65860Sbostic {
717*65860Sbostic register int bot, top;
718*65860Sbostic register struct symbol *sym;
719*65860Sbostic char *demangled;
720*65860Sbostic
721*65860Sbostic bot = 0;
722*65860Sbostic top = BLOCK_NSYMS (block);
723*65860Sbostic
724*65860Sbostic while (bot < top)
725*65860Sbostic {
726*65860Sbostic sym = BLOCK_SYM (block, bot);
727*65860Sbostic if (SYMBOL_NAMESPACE (sym) == VAR_NAMESPACE)
728*65860Sbostic {
729*65860Sbostic demangled = demangle_and_match (SYMBOL_NAME (sym), name,
730*65860Sbostic DMGL_PARAMS | DMGL_ANSI);
731*65860Sbostic if (demangled != NULL)
732*65860Sbostic {
733*65860Sbostic free (demangled);
734*65860Sbostic return (sym);
735*65860Sbostic }
736*65860Sbostic }
737*65860Sbostic bot++;
738*65860Sbostic }
739*65860Sbostic
740*65860Sbostic return (NULL);
741*65860Sbostic }
742*65860Sbostic
743*65860Sbostic /* Look, in partial_symtab PST, for static mangled symbol NAME. */
744*65860Sbostic
745*65860Sbostic static struct partial_symbol *
lookup_demangled_partial_symbol(pst,name)746*65860Sbostic lookup_demangled_partial_symbol (pst, name)
747*65860Sbostic const struct partial_symtab *pst;
748*65860Sbostic const char *name;
749*65860Sbostic {
750*65860Sbostic struct partial_symbol *start, *psym;
751*65860Sbostic int length = pst->n_static_syms;
752*65860Sbostic char *demangled;
753*65860Sbostic
754*65860Sbostic if (!length)
755*65860Sbostic return (struct partial_symbol *) 0;
756*65860Sbostic
757*65860Sbostic start = pst->objfile->static_psymbols.list + pst->statics_offset;
758*65860Sbostic for (psym = start; psym < start + length; psym++)
759*65860Sbostic {
760*65860Sbostic if (SYMBOL_NAMESPACE (psym) == VAR_NAMESPACE)
761*65860Sbostic {
762*65860Sbostic demangled = demangle_and_match (SYMBOL_NAME (psym), name,
763*65860Sbostic DMGL_PARAMS | DMGL_ANSI);
764*65860Sbostic if (demangled != NULL)
765*65860Sbostic {
766*65860Sbostic free (demangled);
767*65860Sbostic return (psym);
768*65860Sbostic }
769*65860Sbostic }
770*65860Sbostic }
771*65860Sbostic
772*65860Sbostic return (NULL);
773*65860Sbostic }
774*65860Sbostic
775*65860Sbostic /* Look, in partial_symtab PST, for symbol NAME. Check the global
776*65860Sbostic symbols if GLOBAL, the static symbols if not */
777*65860Sbostic
778*65860Sbostic static struct partial_symbol *
lookup_partial_symbol(pst,name,global,namespace)779*65860Sbostic lookup_partial_symbol (pst, name, global, namespace)
780*65860Sbostic struct partial_symtab *pst;
781*65860Sbostic const char *name;
782*65860Sbostic int global;
783*65860Sbostic enum namespace namespace;
784*65860Sbostic {
785*65860Sbostic struct partial_symbol *start, *psym;
786*65860Sbostic int length = (global ? pst->n_global_syms : pst->n_static_syms);
787*65860Sbostic
788*65860Sbostic if (!length)
789*65860Sbostic return (struct partial_symbol *) 0;
790*65860Sbostic
791*65860Sbostic start = (global ?
792*65860Sbostic pst->objfile->global_psymbols.list + pst->globals_offset :
793*65860Sbostic pst->objfile->static_psymbols.list + pst->statics_offset );
794*65860Sbostic
795*65860Sbostic if (global) /* This means we can use a binary */
796*65860Sbostic /* search. */
797*65860Sbostic {
798*65860Sbostic struct partial_symbol *top, *bottom, *center;
799*65860Sbostic
800*65860Sbostic /* Binary search. This search is guaranteed to end with center
801*65860Sbostic pointing at the earliest partial symbol with the correct
802*65860Sbostic name. At that point *all* partial symbols with that name
803*65860Sbostic will be checked against the correct namespace. */
804*65860Sbostic bottom = start;
805*65860Sbostic top = start + length - 1;
806*65860Sbostic while (top > bottom)
807*65860Sbostic {
808*65860Sbostic center = bottom + (top - bottom) / 2;
809*65860Sbostic
810*65860Sbostic assert (center < top);
811*65860Sbostic
812*65860Sbostic if (strcmp (SYMBOL_NAME (center), name) >= 0)
813*65860Sbostic top = center;
814*65860Sbostic else
815*65860Sbostic bottom = center + 1;
816*65860Sbostic }
817*65860Sbostic assert (top == bottom);
818*65860Sbostic
819*65860Sbostic while (!strcmp (SYMBOL_NAME (top), name))
820*65860Sbostic {
821*65860Sbostic if (SYMBOL_NAMESPACE (top) == namespace)
822*65860Sbostic return top;
823*65860Sbostic top ++;
824*65860Sbostic }
825*65860Sbostic }
826*65860Sbostic else
827*65860Sbostic {
828*65860Sbostic /* Can't use a binary search */
829*65860Sbostic for (psym = start; psym < start + length; psym++)
830*65860Sbostic if (namespace == SYMBOL_NAMESPACE (psym)
831*65860Sbostic && !strcmp (name, SYMBOL_NAME (psym)))
832*65860Sbostic return psym;
833*65860Sbostic }
834*65860Sbostic
835*65860Sbostic return (struct partial_symbol *) 0;
836*65860Sbostic }
837*65860Sbostic
838*65860Sbostic /* Find the psymtab containing main(). */
839*65860Sbostic /* FIXME: What about languages without main() or specially linked
840*65860Sbostic executables that have no main() ? */
841*65860Sbostic
842*65860Sbostic struct partial_symtab *
find_main_psymtab()843*65860Sbostic find_main_psymtab ()
844*65860Sbostic {
845*65860Sbostic register struct partial_symtab *pst;
846*65860Sbostic register struct objfile *objfile;
847*65860Sbostic
848*65860Sbostic ALL_PSYMTABS (objfile, pst)
849*65860Sbostic {
850*65860Sbostic if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE))
851*65860Sbostic {
852*65860Sbostic return (pst);
853*65860Sbostic }
854*65860Sbostic }
855*65860Sbostic return (NULL);
856*65860Sbostic }
857*65860Sbostic
858*65860Sbostic /* Look for a symbol in block BLOCK. */
859*65860Sbostic
860*65860Sbostic struct symbol *
lookup_block_symbol(block,name,namespace)861*65860Sbostic lookup_block_symbol (block, name, namespace)
862*65860Sbostic register const struct block *block;
863*65860Sbostic const char *name;
864*65860Sbostic const enum namespace namespace;
865*65860Sbostic {
866*65860Sbostic register int bot, top, inc;
867*65860Sbostic register struct symbol *sym, *parameter_sym;
868*65860Sbostic
869*65860Sbostic top = BLOCK_NSYMS (block);
870*65860Sbostic bot = 0;
871*65860Sbostic
872*65860Sbostic /* If the blocks's symbols were sorted, start with a binary search. */
873*65860Sbostic
874*65860Sbostic if (BLOCK_SHOULD_SORT (block))
875*65860Sbostic {
876*65860Sbostic /* First, advance BOT to not far before
877*65860Sbostic the first symbol whose name is NAME. */
878*65860Sbostic
879*65860Sbostic while (1)
880*65860Sbostic {
881*65860Sbostic inc = (top - bot + 1);
882*65860Sbostic /* No need to keep binary searching for the last few bits worth. */
883*65860Sbostic if (inc < 4)
884*65860Sbostic break;
885*65860Sbostic inc = (inc >> 1) + bot;
886*65860Sbostic sym = BLOCK_SYM (block, inc);
887*65860Sbostic if (SYMBOL_NAME (sym)[0] < name[0])
888*65860Sbostic bot = inc;
889*65860Sbostic else if (SYMBOL_NAME (sym)[0] > name[0])
890*65860Sbostic top = inc;
891*65860Sbostic else if (strcmp (SYMBOL_NAME (sym), name) < 0)
892*65860Sbostic bot = inc;
893*65860Sbostic else
894*65860Sbostic top = inc;
895*65860Sbostic }
896*65860Sbostic
897*65860Sbostic /* Now scan forward until we run out of symbols,
898*65860Sbostic find one whose name is greater than NAME,
899*65860Sbostic or find one we want.
900*65860Sbostic If there is more than one symbol with the right name and namespace,
901*65860Sbostic we return the first one. dbxread.c is careful to make sure
902*65860Sbostic that if one is a register then it comes first. */
903*65860Sbostic
904*65860Sbostic top = BLOCK_NSYMS (block);
905*65860Sbostic while (bot < top)
906*65860Sbostic {
907*65860Sbostic sym = BLOCK_SYM (block, bot);
908*65860Sbostic inc = SYMBOL_NAME (sym)[0] - name[0];
909*65860Sbostic if (inc == 0)
910*65860Sbostic inc = strcmp (SYMBOL_NAME (sym), name);
911*65860Sbostic if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
912*65860Sbostic return sym;
913*65860Sbostic if (inc > 0)
914*65860Sbostic return 0;
915*65860Sbostic bot++;
916*65860Sbostic }
917*65860Sbostic return 0;
918*65860Sbostic }
919*65860Sbostic
920*65860Sbostic /* Here if block isn't sorted.
921*65860Sbostic This loop is equivalent to the loop above,
922*65860Sbostic but hacked greatly for speed.
923*65860Sbostic
924*65860Sbostic Note that parameter symbols do not always show up last in the
925*65860Sbostic list; this loop makes sure to take anything else other than
926*65860Sbostic parameter symbols first; it only uses parameter symbols as a
927*65860Sbostic last resort. Note that this only takes up extra computation
928*65860Sbostic time on a match. */
929*65860Sbostic
930*65860Sbostic parameter_sym = (struct symbol *) 0;
931*65860Sbostic top = BLOCK_NSYMS (block);
932*65860Sbostic inc = name[0];
933*65860Sbostic while (bot < top)
934*65860Sbostic {
935*65860Sbostic sym = BLOCK_SYM (block, bot);
936*65860Sbostic if (SYMBOL_NAME (sym)[0] == inc
937*65860Sbostic && !strcmp (SYMBOL_NAME (sym), name)
938*65860Sbostic && SYMBOL_NAMESPACE (sym) == namespace)
939*65860Sbostic {
940*65860Sbostic if (SYMBOL_CLASS (sym) == LOC_ARG
941*65860Sbostic || SYMBOL_CLASS (sym) == LOC_LOCAL_ARG
942*65860Sbostic || SYMBOL_CLASS (sym) == LOC_REF_ARG
943*65860Sbostic || SYMBOL_CLASS (sym) == LOC_REGPARM)
944*65860Sbostic parameter_sym = sym;
945*65860Sbostic else
946*65860Sbostic return sym;
947*65860Sbostic }
948*65860Sbostic bot++;
949*65860Sbostic }
950*65860Sbostic return parameter_sym; /* Will be 0 if not found. */
951*65860Sbostic }
952*65860Sbostic
953*65860Sbostic /* Return the symbol for the function which contains a specified
954*65860Sbostic lexical block, described by a struct block BL. */
955*65860Sbostic
956*65860Sbostic struct symbol *
block_function(bl)957*65860Sbostic block_function (bl)
958*65860Sbostic struct block *bl;
959*65860Sbostic {
960*65860Sbostic while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
961*65860Sbostic bl = BLOCK_SUPERBLOCK (bl);
962*65860Sbostic
963*65860Sbostic return BLOCK_FUNCTION (bl);
964*65860Sbostic }
965*65860Sbostic
966*65860Sbostic /* Subroutine of find_pc_line */
967*65860Sbostic
968*65860Sbostic struct symtab *
find_pc_symtab(pc)969*65860Sbostic find_pc_symtab (pc)
970*65860Sbostic register CORE_ADDR pc;
971*65860Sbostic {
972*65860Sbostic register struct block *b;
973*65860Sbostic struct blockvector *bv;
974*65860Sbostic register struct symtab *s = 0;
975*65860Sbostic register struct partial_symtab *ps;
976*65860Sbostic register struct objfile *objfile;
977*65860Sbostic
978*65860Sbostic /* Search all symtabs for one whose file contains our pc */
979*65860Sbostic
980*65860Sbostic ALL_SYMTABS (objfile, s)
981*65860Sbostic {
982*65860Sbostic bv = BLOCKVECTOR (s);
983*65860Sbostic b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
984*65860Sbostic if (BLOCK_START (b) <= pc
985*65860Sbostic && BLOCK_END (b) > pc)
986*65860Sbostic goto found;
987*65860Sbostic }
988*65860Sbostic
989*65860Sbostic if (!s)
990*65860Sbostic {
991*65860Sbostic ps = find_pc_psymtab (pc);
992*65860Sbostic if (ps && ps->readin)
993*65860Sbostic {
994*65860Sbostic printf_filtered ("(Internal error: pc 0x%x in read in psymtab, but not in symtab.)\n", pc);
995*65860Sbostic }
996*65860Sbostic if (ps)
997*65860Sbostic {
998*65860Sbostic s = PSYMTAB_TO_SYMTAB (ps);
999*65860Sbostic }
1000*65860Sbostic }
1001*65860Sbostic
1002*65860Sbostic found:
1003*65860Sbostic return (s);
1004*65860Sbostic }
1005*65860Sbostic
1006*65860Sbostic /* Find the source file and line number for a given PC value.
1007*65860Sbostic Return a structure containing a symtab pointer, a line number,
1008*65860Sbostic and a pc range for the entire source line.
1009*65860Sbostic The value's .pc field is NOT the specified pc.
1010*65860Sbostic NOTCURRENT nonzero means, if specified pc is on a line boundary,
1011*65860Sbostic use the line that ends there. Otherwise, in that case, the line
1012*65860Sbostic that begins there is used. */
1013*65860Sbostic
1014*65860Sbostic struct symtab_and_line
find_pc_line(pc,notcurrent)1015*65860Sbostic find_pc_line (pc, notcurrent)
1016*65860Sbostic CORE_ADDR pc;
1017*65860Sbostic int notcurrent;
1018*65860Sbostic {
1019*65860Sbostic struct symtab *s;
1020*65860Sbostic register struct linetable *l;
1021*65860Sbostic register int len;
1022*65860Sbostic register int i;
1023*65860Sbostic register struct linetable_entry *item;
1024*65860Sbostic struct symtab_and_line val;
1025*65860Sbostic struct blockvector *bv;
1026*65860Sbostic
1027*65860Sbostic /* Info on best line seen so far, and where it starts, and its file. */
1028*65860Sbostic
1029*65860Sbostic int best_line = 0;
1030*65860Sbostic CORE_ADDR best_pc = 0;
1031*65860Sbostic CORE_ADDR best_end = 0;
1032*65860Sbostic struct symtab *best_symtab = 0;
1033*65860Sbostic
1034*65860Sbostic /* Store here the first line number
1035*65860Sbostic of a file which contains the line at the smallest pc after PC.
1036*65860Sbostic If we don't find a line whose range contains PC,
1037*65860Sbostic we will use a line one less than this,
1038*65860Sbostic with a range from the start of that file to the first line's pc. */
1039*65860Sbostic int alt_line = 0;
1040*65860Sbostic CORE_ADDR alt_pc = 0;
1041*65860Sbostic struct symtab *alt_symtab = 0;
1042*65860Sbostic
1043*65860Sbostic /* Info on best line seen in this file. */
1044*65860Sbostic
1045*65860Sbostic int prev_line;
1046*65860Sbostic CORE_ADDR prev_pc;
1047*65860Sbostic
1048*65860Sbostic /* Info on first line of this file. */
1049*65860Sbostic
1050*65860Sbostic int first_line;
1051*65860Sbostic CORE_ADDR first_pc;
1052*65860Sbostic
1053*65860Sbostic /* If this pc is not from the current frame,
1054*65860Sbostic it is the address of the end of a call instruction.
1055*65860Sbostic Quite likely that is the start of the following statement.
1056*65860Sbostic But what we want is the statement containing the instruction.
1057*65860Sbostic Fudge the pc to make sure we get that. */
1058*65860Sbostic
1059*65860Sbostic if (notcurrent) pc -= 1;
1060*65860Sbostic
1061*65860Sbostic s = find_pc_symtab (pc);
1062*65860Sbostic if (s == 0)
1063*65860Sbostic {
1064*65860Sbostic val.symtab = 0;
1065*65860Sbostic val.line = 0;
1066*65860Sbostic val.pc = pc;
1067*65860Sbostic val.end = 0;
1068*65860Sbostic return val;
1069*65860Sbostic }
1070*65860Sbostic
1071*65860Sbostic bv = BLOCKVECTOR (s);
1072*65860Sbostic
1073*65860Sbostic /* Look at all the symtabs that share this blockvector.
1074*65860Sbostic They all have the same apriori range, that we found was right;
1075*65860Sbostic but they have different line tables. */
1076*65860Sbostic
1077*65860Sbostic for (; s && BLOCKVECTOR (s) == bv; s = s->next)
1078*65860Sbostic {
1079*65860Sbostic /* Find the best line in this symtab. */
1080*65860Sbostic l = LINETABLE (s);
1081*65860Sbostic if (!l)
1082*65860Sbostic continue;
1083*65860Sbostic len = l->nitems;
1084*65860Sbostic prev_line = -1;
1085*65860Sbostic first_line = -1;
1086*65860Sbostic for (i = 0; i < len; i++)
1087*65860Sbostic {
1088*65860Sbostic item = &(l->item[i]);
1089*65860Sbostic
1090*65860Sbostic if (first_line < 0)
1091*65860Sbostic {
1092*65860Sbostic first_line = item->line;
1093*65860Sbostic first_pc = item->pc;
1094*65860Sbostic }
1095*65860Sbostic /* Return the last line that did not start after PC. */
1096*65860Sbostic if (pc >= item->pc)
1097*65860Sbostic {
1098*65860Sbostic prev_line = item->line;
1099*65860Sbostic prev_pc = item->pc;
1100*65860Sbostic }
1101*65860Sbostic else
1102*65860Sbostic break;
1103*65860Sbostic }
1104*65860Sbostic
1105*65860Sbostic /* Is this file's best line closer than the best in the other files?
1106*65860Sbostic If so, record this file, and its best line, as best so far. */
1107*65860Sbostic if (prev_line >= 0 && prev_pc > best_pc)
1108*65860Sbostic {
1109*65860Sbostic best_pc = prev_pc;
1110*65860Sbostic best_line = prev_line;
1111*65860Sbostic best_symtab = s;
1112*65860Sbostic /* If another line is in the linetable, and its PC is closer
1113*65860Sbostic than the best_end we currently have, take it as best_end. */
1114*65860Sbostic if (i < len && (best_end == 0 || best_end > item->pc))
1115*65860Sbostic best_end = item->pc;
1116*65860Sbostic }
1117*65860Sbostic /* Is this file's first line closer than the first lines of other files?
1118*65860Sbostic If so, record this file, and its first line, as best alternate. */
1119*65860Sbostic if (first_line >= 0 && first_pc > pc
1120*65860Sbostic && (alt_pc == 0 || first_pc < alt_pc))
1121*65860Sbostic {
1122*65860Sbostic alt_pc = first_pc;
1123*65860Sbostic alt_line = first_line;
1124*65860Sbostic alt_symtab = s;
1125*65860Sbostic }
1126*65860Sbostic }
1127*65860Sbostic if (best_symtab == 0)
1128*65860Sbostic {
1129*65860Sbostic val.symtab = alt_symtab;
1130*65860Sbostic val.line = alt_line - 1;
1131*65860Sbostic val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1132*65860Sbostic val.end = alt_pc;
1133*65860Sbostic }
1134*65860Sbostic else
1135*65860Sbostic {
1136*65860Sbostic val.symtab = best_symtab;
1137*65860Sbostic val.line = best_line;
1138*65860Sbostic val.pc = best_pc;
1139*65860Sbostic if (best_end && (alt_pc == 0 || best_end < alt_pc))
1140*65860Sbostic val.end = best_end;
1141*65860Sbostic else if (alt_pc)
1142*65860Sbostic val.end = alt_pc;
1143*65860Sbostic else
1144*65860Sbostic val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1145*65860Sbostic }
1146*65860Sbostic return val;
1147*65860Sbostic }
1148*65860Sbostic
1149*65860Sbostic /* Find the PC value for a given source file and line number.
1150*65860Sbostic Returns zero for invalid line number.
1151*65860Sbostic The source file is specified with a struct symtab. */
1152*65860Sbostic
1153*65860Sbostic CORE_ADDR
find_line_pc(symtab,line)1154*65860Sbostic find_line_pc (symtab, line)
1155*65860Sbostic struct symtab *symtab;
1156*65860Sbostic int line;
1157*65860Sbostic {
1158*65860Sbostic register struct linetable *l;
1159*65860Sbostic register int ind;
1160*65860Sbostic int dummy;
1161*65860Sbostic
1162*65860Sbostic if (symtab == 0)
1163*65860Sbostic return 0;
1164*65860Sbostic l = LINETABLE (symtab);
1165*65860Sbostic ind = find_line_common(l, line, &dummy);
1166*65860Sbostic return (ind >= 0) ? l->item[ind].pc : 0;
1167*65860Sbostic }
1168*65860Sbostic
1169*65860Sbostic /* Find the range of pc values in a line.
1170*65860Sbostic Store the starting pc of the line into *STARTPTR
1171*65860Sbostic and the ending pc (start of next line) into *ENDPTR.
1172*65860Sbostic Returns 1 to indicate success.
1173*65860Sbostic Returns 0 if could not find the specified line. */
1174*65860Sbostic
1175*65860Sbostic int
find_line_pc_range(symtab,thisline,startptr,endptr)1176*65860Sbostic find_line_pc_range (symtab, thisline, startptr, endptr)
1177*65860Sbostic struct symtab *symtab;
1178*65860Sbostic int thisline;
1179*65860Sbostic CORE_ADDR *startptr, *endptr;
1180*65860Sbostic {
1181*65860Sbostic register struct linetable *l;
1182*65860Sbostic register int ind;
1183*65860Sbostic int exact_match; /* did we get an exact linenumber match */
1184*65860Sbostic
1185*65860Sbostic if (symtab == 0)
1186*65860Sbostic return 0;
1187*65860Sbostic
1188*65860Sbostic l = LINETABLE (symtab);
1189*65860Sbostic ind = find_line_common (l, thisline, &exact_match);
1190*65860Sbostic if (ind >= 0)
1191*65860Sbostic {
1192*65860Sbostic *startptr = l->item[ind].pc;
1193*65860Sbostic /* If we have not seen an entry for the specified line,
1194*65860Sbostic assume that means the specified line has zero bytes. */
1195*65860Sbostic if (!exact_match || ind == l->nitems-1)
1196*65860Sbostic *endptr = *startptr;
1197*65860Sbostic else
1198*65860Sbostic /* Perhaps the following entry is for the following line.
1199*65860Sbostic It's worth a try. */
1200*65860Sbostic if (ind+1 < l->nitems
1201*65860Sbostic && l->item[ind+1].line == thisline + 1)
1202*65860Sbostic *endptr = l->item[ind+1].pc;
1203*65860Sbostic else
1204*65860Sbostic *endptr = find_line_pc (symtab, thisline+1);
1205*65860Sbostic return 1;
1206*65860Sbostic }
1207*65860Sbostic
1208*65860Sbostic return 0;
1209*65860Sbostic }
1210*65860Sbostic
1211*65860Sbostic /* Given a line table and a line number, return the index into the line
1212*65860Sbostic table for the pc of the nearest line whose number is >= the specified one.
1213*65860Sbostic Return -1 if none is found. The value is >= 0 if it is an index.
1214*65860Sbostic
1215*65860Sbostic Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1216*65860Sbostic
1217*65860Sbostic static int
find_line_common(l,lineno,exact_match)1218*65860Sbostic find_line_common (l, lineno, exact_match)
1219*65860Sbostic register struct linetable *l;
1220*65860Sbostic register int lineno;
1221*65860Sbostic int *exact_match;
1222*65860Sbostic {
1223*65860Sbostic register int i;
1224*65860Sbostic register int len;
1225*65860Sbostic
1226*65860Sbostic /* BEST is the smallest linenumber > LINENO so far seen,
1227*65860Sbostic or 0 if none has been seen so far.
1228*65860Sbostic BEST_INDEX identifies the item for it. */
1229*65860Sbostic
1230*65860Sbostic int best_index = -1;
1231*65860Sbostic int best = 0;
1232*65860Sbostic
1233*65860Sbostic if (lineno <= 0)
1234*65860Sbostic return -1;
1235*65860Sbostic if (l == 0)
1236*65860Sbostic return -1;
1237*65860Sbostic
1238*65860Sbostic len = l->nitems;
1239*65860Sbostic for (i = 0; i < len; i++)
1240*65860Sbostic {
1241*65860Sbostic register struct linetable_entry *item = &(l->item[i]);
1242*65860Sbostic
1243*65860Sbostic if (item->line == lineno)
1244*65860Sbostic {
1245*65860Sbostic *exact_match = 1;
1246*65860Sbostic return i;
1247*65860Sbostic }
1248*65860Sbostic
1249*65860Sbostic if (item->line > lineno && (best == 0 || item->line < best))
1250*65860Sbostic {
1251*65860Sbostic best = item->line;
1252*65860Sbostic best_index = i;
1253*65860Sbostic }
1254*65860Sbostic }
1255*65860Sbostic
1256*65860Sbostic /* If we got here, we didn't get an exact match. */
1257*65860Sbostic
1258*65860Sbostic *exact_match = 0;
1259*65860Sbostic return best_index;
1260*65860Sbostic }
1261*65860Sbostic
1262*65860Sbostic int
find_pc_line_pc_range(pc,startptr,endptr)1263*65860Sbostic find_pc_line_pc_range (pc, startptr, endptr)
1264*65860Sbostic CORE_ADDR pc;
1265*65860Sbostic CORE_ADDR *startptr, *endptr;
1266*65860Sbostic {
1267*65860Sbostic struct symtab_and_line sal;
1268*65860Sbostic sal = find_pc_line (pc, 0);
1269*65860Sbostic *startptr = sal.pc;
1270*65860Sbostic *endptr = sal.end;
1271*65860Sbostic return sal.symtab != 0;
1272*65860Sbostic }
1273*65860Sbostic
1274*65860Sbostic /* If P is of the form "operator[ \t]+..." where `...' is
1275*65860Sbostic some legitimate operator text, return a pointer to the
1276*65860Sbostic beginning of the substring of the operator text.
1277*65860Sbostic Otherwise, return "". */
1278*65860Sbostic static char *
operator_chars(p,end)1279*65860Sbostic operator_chars (p, end)
1280*65860Sbostic char *p;
1281*65860Sbostic char **end;
1282*65860Sbostic {
1283*65860Sbostic *end = "";
1284*65860Sbostic if (strncmp (p, "operator", 8))
1285*65860Sbostic return *end;
1286*65860Sbostic p += 8;
1287*65860Sbostic
1288*65860Sbostic /* Don't get faked out by `operator' being part of a longer
1289*65860Sbostic identifier. */
1290*65860Sbostic if (isalpha(*p) || *p == '_' || *p == '$' || *p == '\0')
1291*65860Sbostic return *end;
1292*65860Sbostic
1293*65860Sbostic /* Allow some whitespace between `operator' and the operator symbol. */
1294*65860Sbostic while (*p == ' ' || *p == '\t')
1295*65860Sbostic p++;
1296*65860Sbostic
1297*65860Sbostic /* Recognize 'operator TYPENAME'. */
1298*65860Sbostic
1299*65860Sbostic if (isalpha(*p) || *p == '_' || *p == '$')
1300*65860Sbostic {
1301*65860Sbostic register char *q = p+1;
1302*65860Sbostic while (isalnum(*q) || *q == '_' || *q == '$')
1303*65860Sbostic q++;
1304*65860Sbostic *end = q;
1305*65860Sbostic return p;
1306*65860Sbostic }
1307*65860Sbostic
1308*65860Sbostic switch (*p)
1309*65860Sbostic {
1310*65860Sbostic case '!':
1311*65860Sbostic case '=':
1312*65860Sbostic case '*':
1313*65860Sbostic case '/':
1314*65860Sbostic case '%':
1315*65860Sbostic case '^':
1316*65860Sbostic if (p[1] == '=')
1317*65860Sbostic *end = p+2;
1318*65860Sbostic else
1319*65860Sbostic *end = p+1;
1320*65860Sbostic return p;
1321*65860Sbostic case '<':
1322*65860Sbostic case '>':
1323*65860Sbostic case '+':
1324*65860Sbostic case '-':
1325*65860Sbostic case '&':
1326*65860Sbostic case '|':
1327*65860Sbostic if (p[1] == '=' || p[1] == p[0])
1328*65860Sbostic *end = p+2;
1329*65860Sbostic else
1330*65860Sbostic *end = p+1;
1331*65860Sbostic return p;
1332*65860Sbostic case '~':
1333*65860Sbostic case ',':
1334*65860Sbostic *end = p+1;
1335*65860Sbostic return p;
1336*65860Sbostic case '(':
1337*65860Sbostic if (p[1] != ')')
1338*65860Sbostic error ("`operator ()' must be specified without whitespace in `()'");
1339*65860Sbostic *end = p+2;
1340*65860Sbostic return p;
1341*65860Sbostic case '?':
1342*65860Sbostic if (p[1] != ':')
1343*65860Sbostic error ("`operator ?:' must be specified without whitespace in `?:'");
1344*65860Sbostic *end = p+2;
1345*65860Sbostic return p;
1346*65860Sbostic case '[':
1347*65860Sbostic if (p[1] != ']')
1348*65860Sbostic error ("`operator []' must be specified without whitespace in `[]'");
1349*65860Sbostic *end = p+2;
1350*65860Sbostic return p;
1351*65860Sbostic default:
1352*65860Sbostic error ("`operator %s' not supported", p);
1353*65860Sbostic break;
1354*65860Sbostic }
1355*65860Sbostic *end = "";
1356*65860Sbostic return *end;
1357*65860Sbostic }
1358*65860Sbostic
1359*65860Sbostic /* Recursive helper function for decode_line_1.
1360*65860Sbostic * Look for methods named NAME in type T.
1361*65860Sbostic * Return number of matches.
1362*65860Sbostic * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1363*65860Sbostic * These allocations seem to define "big enough":
1364*65860Sbostic * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1365*65860Sbostic * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1366*65860Sbostic */
1367*65860Sbostic
1368*65860Sbostic int
find_methods(t,name,physnames,sym_arr)1369*65860Sbostic find_methods (t, name, physnames, sym_arr)
1370*65860Sbostic struct type *t;
1371*65860Sbostic char *name;
1372*65860Sbostic char **physnames;
1373*65860Sbostic struct symbol **sym_arr;
1374*65860Sbostic {
1375*65860Sbostic int i1 = 0;
1376*65860Sbostic int ibase;
1377*65860Sbostic struct symbol *sym_class;
1378*65860Sbostic char *class_name = type_name_no_tag (t);
1379*65860Sbostic /* Ignore this class if it doesn't have a name.
1380*65860Sbostic This prevents core dumps, but is just a workaround
1381*65860Sbostic because we might not find the function in
1382*65860Sbostic certain cases, such as
1383*65860Sbostic struct D {virtual int f();}
1384*65860Sbostic struct C : D {virtual int g();}
1385*65860Sbostic (in this case g++ 1.35.1- does not put out a name
1386*65860Sbostic for D as such, it defines type 19 (for example) in
1387*65860Sbostic the same stab as C, and then does a
1388*65860Sbostic .stabs "D:T19" and a .stabs "D:t19".
1389*65860Sbostic Thus
1390*65860Sbostic "break C::f" should not be looking for field f in
1391*65860Sbostic the class named D,
1392*65860Sbostic but just for the field f in the baseclasses of C
1393*65860Sbostic (no matter what their names).
1394*65860Sbostic
1395*65860Sbostic However, I don't know how to replace the code below
1396*65860Sbostic that depends on knowing the name of D. */
1397*65860Sbostic if (class_name
1398*65860Sbostic && (sym_class = lookup_symbol (class_name,
1399*65860Sbostic (struct block *)NULL,
1400*65860Sbostic STRUCT_NAMESPACE,
1401*65860Sbostic (int *)NULL,
1402*65860Sbostic (struct symtab **)NULL)))
1403*65860Sbostic {
1404*65860Sbostic int method_counter;
1405*65860Sbostic t = SYMBOL_TYPE (sym_class);
1406*65860Sbostic for (method_counter = TYPE_NFN_FIELDS (t) - 1;
1407*65860Sbostic method_counter >= 0;
1408*65860Sbostic --method_counter)
1409*65860Sbostic {
1410*65860Sbostic int field_counter;
1411*65860Sbostic struct fn_field *f = TYPE_FN_FIELDLIST1 (t, method_counter);
1412*65860Sbostic
1413*65860Sbostic char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
1414*65860Sbostic if (!strcmp (name, method_name))
1415*65860Sbostic /* Find all the fields with that name. */
1416*65860Sbostic for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
1417*65860Sbostic field_counter >= 0;
1418*65860Sbostic --field_counter)
1419*65860Sbostic {
1420*65860Sbostic char *phys_name;
1421*65860Sbostic if (TYPE_FN_FIELD_STUB (f, field_counter))
1422*65860Sbostic check_stub_method (t, method_counter, field_counter);
1423*65860Sbostic phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
1424*65860Sbostic physnames[i1] = (char*) alloca (strlen (phys_name) + 1);
1425*65860Sbostic strcpy (physnames[i1], phys_name);
1426*65860Sbostic sym_arr[i1] = lookup_symbol (phys_name,
1427*65860Sbostic SYMBOL_BLOCK_VALUE (sym_class),
1428*65860Sbostic VAR_NAMESPACE,
1429*65860Sbostic (int *) NULL,
1430*65860Sbostic (struct symtab **) NULL);
1431*65860Sbostic if (sym_arr[i1]) i1++;
1432*65860Sbostic else
1433*65860Sbostic {
1434*65860Sbostic fputs_filtered("(Cannot find method ", stdout);
1435*65860Sbostic fputs_demangled(phys_name, stdout, DMGL_PARAMS);
1436*65860Sbostic fputs_filtered(" - possibly inlined.)\n", stdout);
1437*65860Sbostic }
1438*65860Sbostic }
1439*65860Sbostic }
1440*65860Sbostic }
1441*65860Sbostic /* Only search baseclasses if there is no match yet,
1442*65860Sbostic * since names in derived classes override those in baseclasses.
1443*65860Sbostic */
1444*65860Sbostic if (i1)
1445*65860Sbostic return i1;
1446*65860Sbostic for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
1447*65860Sbostic i1 += find_methods(TYPE_BASECLASS(t, ibase), name,
1448*65860Sbostic physnames + i1, sym_arr + i1);
1449*65860Sbostic return i1;
1450*65860Sbostic }
1451*65860Sbostic
1452*65860Sbostic /* Parse a string that specifies a line number.
1453*65860Sbostic Pass the address of a char * variable; that variable will be
1454*65860Sbostic advanced over the characters actually parsed.
1455*65860Sbostic
1456*65860Sbostic The string can be:
1457*65860Sbostic
1458*65860Sbostic LINENUM -- that line number in current file. PC returned is 0.
1459*65860Sbostic FILE:LINENUM -- that line in that file. PC returned is 0.
1460*65860Sbostic FUNCTION -- line number of openbrace of that function.
1461*65860Sbostic PC returned is the start of the function.
1462*65860Sbostic VARIABLE -- line number of definition of that variable.
1463*65860Sbostic PC returned is 0.
1464*65860Sbostic FILE:FUNCTION -- likewise, but prefer functions in that file.
1465*65860Sbostic *EXPR -- line in which address EXPR appears.
1466*65860Sbostic
1467*65860Sbostic FUNCTION may be an undebuggable function found in minimal symbol table.
1468*65860Sbostic
1469*65860Sbostic If the argument FUNFIRSTLINE is nonzero, we want the first line
1470*65860Sbostic of real code inside a function when a function is specified.
1471*65860Sbostic
1472*65860Sbostic DEFAULT_SYMTAB specifies the file to use if none is specified.
1473*65860Sbostic It defaults to current_source_symtab.
1474*65860Sbostic DEFAULT_LINE specifies the line number to use for relative
1475*65860Sbostic line numbers (that start with signs). Defaults to current_source_line.
1476*65860Sbostic
1477*65860Sbostic Note that it is possible to return zero for the symtab
1478*65860Sbostic if no file is validly specified. Callers must check that.
1479*65860Sbostic Also, the line number returned may be invalid. */
1480*65860Sbostic
1481*65860Sbostic struct symtabs_and_lines
decode_line_1(argptr,funfirstline,default_symtab,default_line)1482*65860Sbostic decode_line_1 (argptr, funfirstline, default_symtab, default_line)
1483*65860Sbostic char **argptr;
1484*65860Sbostic int funfirstline;
1485*65860Sbostic struct symtab *default_symtab;
1486*65860Sbostic int default_line;
1487*65860Sbostic {
1488*65860Sbostic struct symtabs_and_lines values;
1489*65860Sbostic #ifdef HPPA_COMPILER_BUG
1490*65860Sbostic /* FIXME: The native HP 9000/700 compiler has a bug which appears
1491*65860Sbostic when optimizing this file with target i960-vxworks. I haven't
1492*65860Sbostic been able to construct a simple test case. The problem is that
1493*65860Sbostic in the second call to SKIP_PROLOGUE below, the compiler somehow
1494*65860Sbostic does not realize that the statement val = find_pc_line (...) will
1495*65860Sbostic change the values of the fields of val. It extracts the elements
1496*65860Sbostic into registers at the top of the block, and does not update the
1497*65860Sbostic registers after the call to find_pc_line. You can check this by
1498*65860Sbostic inserting a printf at the end of find_pc_line to show what values
1499*65860Sbostic it is returning for val.pc and val.end and another printf after
1500*65860Sbostic the call to see what values the function actually got (remember,
1501*65860Sbostic this is compiling with cc -O, with this patch removed). You can
1502*65860Sbostic also examine the assembly listing: search for the second call to
1503*65860Sbostic skip_prologue; the LDO statement before the next call to
1504*65860Sbostic find_pc_line loads the address of the structure which
1505*65860Sbostic find_pc_line will return; if there is a LDW just before the LDO,
1506*65860Sbostic which fetches an element of the structure, then the compiler
1507*65860Sbostic still has the bug.
1508*65860Sbostic
1509*65860Sbostic Setting val to volatile avoids the problem. We must undef
1510*65860Sbostic volatile, because the HPPA native compiler does not define
1511*65860Sbostic __STDC__, although it does understand volatile, and so volatile
1512*65860Sbostic will have been defined away in defs.h. */
1513*65860Sbostic #undef volatile
1514*65860Sbostic volatile struct symtab_and_line val;
1515*65860Sbostic #define volatile /*nothing*/
1516*65860Sbostic #else
1517*65860Sbostic struct symtab_and_line val;
1518*65860Sbostic #endif
1519*65860Sbostic register char *p, *p1;
1520*65860Sbostic char *q, *q1;
1521*65860Sbostic register struct symtab *s;
1522*65860Sbostic
1523*65860Sbostic register struct symbol *sym;
1524*65860Sbostic /* The symtab that SYM was found in. */
1525*65860Sbostic struct symtab *sym_symtab;
1526*65860Sbostic
1527*65860Sbostic register CORE_ADDR pc;
1528*65860Sbostic register struct minimal_symbol *msymbol;
1529*65860Sbostic char *copy;
1530*65860Sbostic struct symbol *sym_class;
1531*65860Sbostic int i1;
1532*65860Sbostic int is_quoted;
1533*65860Sbostic struct symbol **sym_arr;
1534*65860Sbostic struct type *t;
1535*65860Sbostic char **physnames;
1536*65860Sbostic char *saved_arg = *argptr;
1537*65860Sbostic extern char *gdb_completer_quote_characters;
1538*65860Sbostic
1539*65860Sbostic /* Defaults have defaults. */
1540*65860Sbostic
1541*65860Sbostic if (default_symtab == 0)
1542*65860Sbostic {
1543*65860Sbostic default_symtab = current_source_symtab;
1544*65860Sbostic default_line = current_source_line;
1545*65860Sbostic }
1546*65860Sbostic
1547*65860Sbostic /* See if arg is *PC */
1548*65860Sbostic
1549*65860Sbostic if (**argptr == '*')
1550*65860Sbostic {
1551*65860Sbostic if (**argptr == '*')
1552*65860Sbostic {
1553*65860Sbostic (*argptr)++;
1554*65860Sbostic }
1555*65860Sbostic pc = parse_and_eval_address_1 (argptr);
1556*65860Sbostic values.sals = (struct symtab_and_line *)
1557*65860Sbostic xmalloc (sizeof (struct symtab_and_line));
1558*65860Sbostic values.nelts = 1;
1559*65860Sbostic values.sals[0] = find_pc_line (pc, 0);
1560*65860Sbostic values.sals[0].pc = pc;
1561*65860Sbostic return values;
1562*65860Sbostic }
1563*65860Sbostic
1564*65860Sbostic /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1565*65860Sbostic
1566*65860Sbostic s = NULL;
1567*65860Sbostic is_quoted = (strchr (gdb_completer_quote_characters, **argptr) != NULL);
1568*65860Sbostic
1569*65860Sbostic for (p = *argptr; *p; p++)
1570*65860Sbostic {
1571*65860Sbostic if (p[0] == ':' || p[0] == ' ' || p[0] == '\t')
1572*65860Sbostic break;
1573*65860Sbostic }
1574*65860Sbostic while (p[0] == ' ' || p[0] == '\t') p++;
1575*65860Sbostic
1576*65860Sbostic if ((p[0] == ':') && !is_quoted)
1577*65860Sbostic {
1578*65860Sbostic
1579*65860Sbostic /* C++ */
1580*65860Sbostic if (p[1] ==':')
1581*65860Sbostic {
1582*65860Sbostic /* Extract the class name. */
1583*65860Sbostic p1 = p;
1584*65860Sbostic while (p != *argptr && p[-1] == ' ') --p;
1585*65860Sbostic copy = (char *) alloca (p - *argptr + 1);
1586*65860Sbostic memcpy (copy, *argptr, p - *argptr);
1587*65860Sbostic copy[p - *argptr] = 0;
1588*65860Sbostic
1589*65860Sbostic /* Discard the class name from the arg. */
1590*65860Sbostic p = p1 + 2;
1591*65860Sbostic while (*p == ' ' || *p == '\t') p++;
1592*65860Sbostic *argptr = p;
1593*65860Sbostic
1594*65860Sbostic sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0,
1595*65860Sbostic (struct symtab **)NULL);
1596*65860Sbostic
1597*65860Sbostic if (sym_class &&
1598*65860Sbostic ( TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_STRUCT
1599*65860Sbostic || TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_UNION))
1600*65860Sbostic {
1601*65860Sbostic /* Arg token is not digits => try it as a function name
1602*65860Sbostic Find the next token (everything up to end or next whitespace). */
1603*65860Sbostic p = *argptr;
1604*65860Sbostic while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p !=':') p++;
1605*65860Sbostic q = operator_chars (*argptr, &q1);
1606*65860Sbostic
1607*65860Sbostic if (q1 - q)
1608*65860Sbostic {
1609*65860Sbostic char *opname;
1610*65860Sbostic char *tmp = alloca (q1 - q + 1);
1611*65860Sbostic memcpy (tmp, q, q1 - q);
1612*65860Sbostic tmp[q1 - q] = '\0';
1613*65860Sbostic opname = cplus_mangle_opname (tmp, DMGL_ANSI);
1614*65860Sbostic if (opname == NULL)
1615*65860Sbostic {
1616*65860Sbostic warning ("no mangling for \"%s\"", tmp);
1617*65860Sbostic cplusplus_hint (saved_arg);
1618*65860Sbostic return_to_top_level ();
1619*65860Sbostic }
1620*65860Sbostic copy = (char*) alloca (3 + strlen(opname));
1621*65860Sbostic sprintf (copy, "__%s", opname);
1622*65860Sbostic p = q1;
1623*65860Sbostic }
1624*65860Sbostic else
1625*65860Sbostic {
1626*65860Sbostic copy = (char *) alloca (p - *argptr + 1 + (q1 - q));
1627*65860Sbostic memcpy (copy, *argptr, p - *argptr);
1628*65860Sbostic copy[p - *argptr] = '\0';
1629*65860Sbostic }
1630*65860Sbostic
1631*65860Sbostic /* no line number may be specified */
1632*65860Sbostic while (*p == ' ' || *p == '\t') p++;
1633*65860Sbostic *argptr = p;
1634*65860Sbostic
1635*65860Sbostic sym = 0;
1636*65860Sbostic i1 = 0; /* counter for the symbol array */
1637*65860Sbostic t = SYMBOL_TYPE (sym_class);
1638*65860Sbostic sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1639*65860Sbostic physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1640*65860Sbostic
1641*65860Sbostic if (destructor_name_p (copy, t))
1642*65860Sbostic {
1643*65860Sbostic /* destructors are a special case. */
1644*65860Sbostic struct fn_field *f = TYPE_FN_FIELDLIST1 (t, 0);
1645*65860Sbostic int len = TYPE_FN_FIELDLIST_LENGTH (t, 0) - 1;
1646*65860Sbostic char *phys_name = TYPE_FN_FIELD_PHYSNAME (f, len);
1647*65860Sbostic physnames[i1] = (char *)alloca (strlen (phys_name) + 1);
1648*65860Sbostic strcpy (physnames[i1], phys_name);
1649*65860Sbostic sym_arr[i1] =
1650*65860Sbostic lookup_symbol (phys_name, SYMBOL_BLOCK_VALUE (sym_class),
1651*65860Sbostic VAR_NAMESPACE, 0, (struct symtab **)NULL);
1652*65860Sbostic if (sym_arr[i1]) i1++;
1653*65860Sbostic }
1654*65860Sbostic else
1655*65860Sbostic i1 = find_methods (t, copy, physnames, sym_arr);
1656*65860Sbostic if (i1 == 1)
1657*65860Sbostic {
1658*65860Sbostic /* There is exactly one field with that name. */
1659*65860Sbostic sym = sym_arr[0];
1660*65860Sbostic
1661*65860Sbostic if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1662*65860Sbostic {
1663*65860Sbostic /* Arg is the name of a function */
1664*65860Sbostic pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
1665*65860Sbostic if (funfirstline)
1666*65860Sbostic SKIP_PROLOGUE (pc);
1667*65860Sbostic values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
1668*65860Sbostic values.nelts = 1;
1669*65860Sbostic values.sals[0] = find_pc_line (pc, 0);
1670*65860Sbostic values.sals[0].pc = (values.sals[0].end && values.sals[0].pc != pc) ? values.sals[0].end : pc;
1671*65860Sbostic }
1672*65860Sbostic else
1673*65860Sbostic {
1674*65860Sbostic values.nelts = 0;
1675*65860Sbostic }
1676*65860Sbostic return values;
1677*65860Sbostic }
1678*65860Sbostic if (i1 > 0)
1679*65860Sbostic {
1680*65860Sbostic /* There is more than one field with that name
1681*65860Sbostic (overloaded). Ask the user which one to use. */
1682*65860Sbostic return decode_line_2 (sym_arr, i1, funfirstline);
1683*65860Sbostic }
1684*65860Sbostic else
1685*65860Sbostic {
1686*65860Sbostic char *tmp;
1687*65860Sbostic
1688*65860Sbostic if (OPNAME_PREFIX_P (copy))
1689*65860Sbostic {
1690*65860Sbostic tmp = (char *)alloca (strlen (copy+3) + 9);
1691*65860Sbostic strcpy (tmp, "operator ");
1692*65860Sbostic strcat (tmp, copy+3);
1693*65860Sbostic }
1694*65860Sbostic else
1695*65860Sbostic tmp = copy;
1696*65860Sbostic if (tmp[0] == '~')
1697*65860Sbostic warning ("the class `%s' does not have destructor defined",
1698*65860Sbostic sym_class->name);
1699*65860Sbostic else
1700*65860Sbostic warning ("the class %s does not have any method named %s",
1701*65860Sbostic sym_class->name, tmp);
1702*65860Sbostic cplusplus_hint (saved_arg);
1703*65860Sbostic return_to_top_level ();
1704*65860Sbostic }
1705*65860Sbostic }
1706*65860Sbostic else
1707*65860Sbostic {
1708*65860Sbostic /* The quotes are important if copy is empty. */
1709*65860Sbostic warning ("can't find class, struct, or union named \"%s\"",
1710*65860Sbostic copy);
1711*65860Sbostic cplusplus_hint (saved_arg);
1712*65860Sbostic return_to_top_level ();
1713*65860Sbostic }
1714*65860Sbostic }
1715*65860Sbostic /* end of C++ */
1716*65860Sbostic
1717*65860Sbostic
1718*65860Sbostic /* Extract the file name. */
1719*65860Sbostic p1 = p;
1720*65860Sbostic while (p != *argptr && p[-1] == ' ') --p;
1721*65860Sbostic copy = (char *) alloca (p - *argptr + 1);
1722*65860Sbostic memcpy (copy, *argptr, p - *argptr);
1723*65860Sbostic copy[p - *argptr] = 0;
1724*65860Sbostic
1725*65860Sbostic /* Find that file's data. */
1726*65860Sbostic s = lookup_symtab (copy);
1727*65860Sbostic if (s == 0)
1728*65860Sbostic {
1729*65860Sbostic if (!have_full_symbols () && !have_partial_symbols ())
1730*65860Sbostic error (no_symtab_msg);
1731*65860Sbostic error ("No source file named %s.", copy);
1732*65860Sbostic }
1733*65860Sbostic
1734*65860Sbostic /* Discard the file name from the arg. */
1735*65860Sbostic p = p1 + 1;
1736*65860Sbostic while (*p == ' ' || *p == '\t') p++;
1737*65860Sbostic *argptr = p;
1738*65860Sbostic }
1739*65860Sbostic
1740*65860Sbostic /* S is specified file's symtab, or 0 if no file specified.
1741*65860Sbostic arg no longer contains the file name. */
1742*65860Sbostic
1743*65860Sbostic /* Check whether arg is all digits (and sign) */
1744*65860Sbostic
1745*65860Sbostic p = *argptr;
1746*65860Sbostic if (*p == '-' || *p == '+') p++;
1747*65860Sbostic while (*p >= '0' && *p <= '9')
1748*65860Sbostic p++;
1749*65860Sbostic
1750*65860Sbostic if (p != *argptr && (*p == 0 || *p == ' ' || *p == '\t' || *p == ','))
1751*65860Sbostic {
1752*65860Sbostic /* We found a token consisting of all digits -- at least one digit. */
1753*65860Sbostic enum sign {none, plus, minus} sign = none;
1754*65860Sbostic
1755*65860Sbostic /* This is where we need to make sure that we have good defaults.
1756*65860Sbostic We must guarantee that this section of code is never executed
1757*65860Sbostic when we are called with just a function name, since
1758*65860Sbostic select_source_symtab calls us with such an argument */
1759*65860Sbostic
1760*65860Sbostic if (s == 0 && default_symtab == 0)
1761*65860Sbostic {
1762*65860Sbostic select_source_symtab (0);
1763*65860Sbostic default_symtab = current_source_symtab;
1764*65860Sbostic default_line = current_source_line;
1765*65860Sbostic }
1766*65860Sbostic
1767*65860Sbostic if (**argptr == '+')
1768*65860Sbostic sign = plus, (*argptr)++;
1769*65860Sbostic else if (**argptr == '-')
1770*65860Sbostic sign = minus, (*argptr)++;
1771*65860Sbostic val.line = atoi (*argptr);
1772*65860Sbostic switch (sign)
1773*65860Sbostic {
1774*65860Sbostic case plus:
1775*65860Sbostic if (p == *argptr)
1776*65860Sbostic val.line = 5;
1777*65860Sbostic if (s == 0)
1778*65860Sbostic val.line = default_line + val.line;
1779*65860Sbostic break;
1780*65860Sbostic case minus:
1781*65860Sbostic if (p == *argptr)
1782*65860Sbostic val.line = 15;
1783*65860Sbostic if (s == 0)
1784*65860Sbostic val.line = default_line - val.line;
1785*65860Sbostic else
1786*65860Sbostic val.line = 1;
1787*65860Sbostic break;
1788*65860Sbostic case none:
1789*65860Sbostic break; /* No need to adjust val.line. */
1790*65860Sbostic }
1791*65860Sbostic
1792*65860Sbostic while (*p == ' ' || *p == '\t') p++;
1793*65860Sbostic *argptr = p;
1794*65860Sbostic if (s == 0)
1795*65860Sbostic s = default_symtab;
1796*65860Sbostic val.symtab = s;
1797*65860Sbostic val.pc = 0;
1798*65860Sbostic values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
1799*65860Sbostic values.sals[0] = val;
1800*65860Sbostic values.nelts = 1;
1801*65860Sbostic return values;
1802*65860Sbostic }
1803*65860Sbostic
1804*65860Sbostic /* Arg token is not digits => try it as a variable name
1805*65860Sbostic Find the next token (everything up to end or next whitespace). */
1806*65860Sbostic
1807*65860Sbostic p = skip_quoted (*argptr);
1808*65860Sbostic copy = (char *) alloca (p - *argptr + 1);
1809*65860Sbostic memcpy (copy, *argptr, p - *argptr);
1810*65860Sbostic copy[p - *argptr] = '\0';
1811*65860Sbostic if ((copy[0] == copy [p - *argptr - 1])
1812*65860Sbostic && strchr (gdb_completer_quote_characters, copy[0]) != NULL)
1813*65860Sbostic {
1814*65860Sbostic char *temp;
1815*65860Sbostic copy [p - *argptr - 1] = '\0';
1816*65860Sbostic copy++;
1817*65860Sbostic if ((temp = expensive_mangler (copy)) != NULL)
1818*65860Sbostic {
1819*65860Sbostic copy = temp;
1820*65860Sbostic }
1821*65860Sbostic }
1822*65860Sbostic while (*p == ' ' || *p == '\t') p++;
1823*65860Sbostic *argptr = p;
1824*65860Sbostic
1825*65860Sbostic /* Look up that token as a variable.
1826*65860Sbostic If file specified, use that file's per-file block to start with. */
1827*65860Sbostic
1828*65860Sbostic sym = lookup_symbol (copy,
1829*65860Sbostic (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
1830*65860Sbostic : get_selected_block ()),
1831*65860Sbostic VAR_NAMESPACE, 0, &sym_symtab);
1832*65860Sbostic
1833*65860Sbostic if (sym != NULL)
1834*65860Sbostic {
1835*65860Sbostic if (SYMBOL_CLASS (sym) == LOC_BLOCK)
1836*65860Sbostic {
1837*65860Sbostic /* Arg is the name of a function */
1838*65860Sbostic pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
1839*65860Sbostic if (funfirstline)
1840*65860Sbostic SKIP_PROLOGUE (pc);
1841*65860Sbostic val = find_pc_line (pc, 0);
1842*65860Sbostic #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1843*65860Sbostic /* Convex: no need to suppress code on first line, if any */
1844*65860Sbostic val.pc = pc;
1845*65860Sbostic #else
1846*65860Sbostic /* If SKIP_PROLOGUE left us in mid-line, and the next line is still
1847*65860Sbostic part of the same function:
1848*65860Sbostic advance to next line,
1849*65860Sbostic recalculate its line number (might not be N+1). */
1850*65860Sbostic if (val.pc != pc && val.end &&
1851*65860Sbostic lookup_minimal_symbol_by_pc (pc) == lookup_minimal_symbol_by_pc (val.end)) {
1852*65860Sbostic pc = val.end; /* First pc of next line */
1853*65860Sbostic val = find_pc_line (pc, 0);
1854*65860Sbostic }
1855*65860Sbostic val.pc = pc;
1856*65860Sbostic #endif
1857*65860Sbostic values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
1858*65860Sbostic values.sals[0] = val;
1859*65860Sbostic values.nelts = 1;
1860*65860Sbostic
1861*65860Sbostic /* I think this is always the same as the line that
1862*65860Sbostic we calculate above, but the general principle is
1863*65860Sbostic "trust the symbols more than stuff like
1864*65860Sbostic SKIP_PROLOGUE". */
1865*65860Sbostic if (SYMBOL_LINE (sym) != 0)
1866*65860Sbostic values.sals[0].line = SYMBOL_LINE (sym);
1867*65860Sbostic
1868*65860Sbostic return values;
1869*65860Sbostic }
1870*65860Sbostic else if (SYMBOL_LINE (sym) != 0)
1871*65860Sbostic {
1872*65860Sbostic /* We know its line number. */
1873*65860Sbostic values.sals = (struct symtab_and_line *)
1874*65860Sbostic xmalloc (sizeof (struct symtab_and_line));
1875*65860Sbostic values.nelts = 1;
1876*65860Sbostic memset (&values.sals[0], 0, sizeof (values.sals[0]));
1877*65860Sbostic values.sals[0].symtab = sym_symtab;
1878*65860Sbostic values.sals[0].line = SYMBOL_LINE (sym);
1879*65860Sbostic return values;
1880*65860Sbostic }
1881*65860Sbostic else
1882*65860Sbostic /* This can happen if it is compiled with a compiler which doesn't
1883*65860Sbostic put out line numbers for variables. */
1884*65860Sbostic error ("Line number not known for symbol \"%s\"", copy);
1885*65860Sbostic }
1886*65860Sbostic
1887*65860Sbostic msymbol = lookup_minimal_symbol (copy, (struct objfile *) NULL);
1888*65860Sbostic if (msymbol != NULL)
1889*65860Sbostic {
1890*65860Sbostic val.symtab = 0;
1891*65860Sbostic val.line = 0;
1892*65860Sbostic val.pc = msymbol -> address + FUNCTION_START_OFFSET;
1893*65860Sbostic if (funfirstline)
1894*65860Sbostic SKIP_PROLOGUE (val.pc);
1895*65860Sbostic values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
1896*65860Sbostic values.sals[0] = val;
1897*65860Sbostic values.nelts = 1;
1898*65860Sbostic return values;
1899*65860Sbostic }
1900*65860Sbostic
1901*65860Sbostic if (!have_full_symbols () &&
1902*65860Sbostic !have_partial_symbols () && !have_minimal_symbols ())
1903*65860Sbostic error (no_symtab_msg);
1904*65860Sbostic
1905*65860Sbostic error ("Function \"%s\" not defined.", copy);
1906*65860Sbostic return values; /* for lint */
1907*65860Sbostic }
1908*65860Sbostic
1909*65860Sbostic struct symtabs_and_lines
decode_line_spec(string,funfirstline)1910*65860Sbostic decode_line_spec (string, funfirstline)
1911*65860Sbostic char *string;
1912*65860Sbostic int funfirstline;
1913*65860Sbostic {
1914*65860Sbostic struct symtabs_and_lines sals;
1915*65860Sbostic if (string == 0)
1916*65860Sbostic error ("Empty line specification.");
1917*65860Sbostic sals = decode_line_1 (&string, funfirstline,
1918*65860Sbostic current_source_symtab, current_source_line);
1919*65860Sbostic if (*string)
1920*65860Sbostic error ("Junk at end of line specification: %s", string);
1921*65860Sbostic return sals;
1922*65860Sbostic }
1923*65860Sbostic
1924*65860Sbostic /* Given a list of NELTS symbols in sym_arr (with corresponding
1925*65860Sbostic mangled names in physnames), return a list of lines to operate on
1926*65860Sbostic (ask user if necessary). */
1927*65860Sbostic static struct symtabs_and_lines
decode_line_2(sym_arr,nelts,funfirstline)1928*65860Sbostic decode_line_2 (sym_arr, nelts, funfirstline)
1929*65860Sbostic struct symbol *sym_arr[];
1930*65860Sbostic int nelts;
1931*65860Sbostic int funfirstline;
1932*65860Sbostic {
1933*65860Sbostic struct symtabs_and_lines values, return_values;
1934*65860Sbostic register CORE_ADDR pc;
1935*65860Sbostic char *args, *arg1;
1936*65860Sbostic int i;
1937*65860Sbostic char *prompt;
1938*65860Sbostic char *demangled;
1939*65860Sbostic
1940*65860Sbostic values.sals = (struct symtab_and_line *) alloca (nelts * sizeof(struct symtab_and_line));
1941*65860Sbostic return_values.sals = (struct symtab_and_line *) xmalloc (nelts * sizeof(struct symtab_and_line));
1942*65860Sbostic
1943*65860Sbostic i = 0;
1944*65860Sbostic printf("[0] cancel\n[1] all\n");
1945*65860Sbostic while (i < nelts)
1946*65860Sbostic {
1947*65860Sbostic if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK)
1948*65860Sbostic {
1949*65860Sbostic /* Arg is the name of a function */
1950*65860Sbostic pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr[i]))
1951*65860Sbostic + FUNCTION_START_OFFSET;
1952*65860Sbostic if (funfirstline)
1953*65860Sbostic SKIP_PROLOGUE (pc);
1954*65860Sbostic values.sals[i] = find_pc_line (pc, 0);
1955*65860Sbostic values.sals[i].pc = (values.sals[i].end && values.sals[i].pc != pc) ?
1956*65860Sbostic values.sals[i].end : pc;
1957*65860Sbostic demangled = cplus_demangle (SYMBOL_NAME (sym_arr[i]),
1958*65860Sbostic DMGL_PARAMS | DMGL_ANSI);
1959*65860Sbostic printf("[%d] %s at %s:%d\n", (i+2),
1960*65860Sbostic demangled ? demangled : SYMBOL_NAME (sym_arr[i]),
1961*65860Sbostic values.sals[i].symtab->filename, values.sals[i].line);
1962*65860Sbostic if (demangled != NULL)
1963*65860Sbostic {
1964*65860Sbostic free (demangled);
1965*65860Sbostic }
1966*65860Sbostic }
1967*65860Sbostic else printf ("?HERE\n");
1968*65860Sbostic i++;
1969*65860Sbostic }
1970*65860Sbostic
1971*65860Sbostic if ((prompt = getenv ("PS2")) == NULL)
1972*65860Sbostic {
1973*65860Sbostic prompt = ">";
1974*65860Sbostic }
1975*65860Sbostic printf("%s ",prompt);
1976*65860Sbostic fflush(stdout);
1977*65860Sbostic
1978*65860Sbostic args = command_line_input ((char *) NULL, 0);
1979*65860Sbostic
1980*65860Sbostic if (args == 0)
1981*65860Sbostic error_no_arg ("one or more choice numbers");
1982*65860Sbostic
1983*65860Sbostic i = 0;
1984*65860Sbostic while (*args)
1985*65860Sbostic {
1986*65860Sbostic int num;
1987*65860Sbostic
1988*65860Sbostic arg1 = args;
1989*65860Sbostic while (*arg1 >= '0' && *arg1 <= '9') arg1++;
1990*65860Sbostic if (*arg1 && *arg1 != ' ' && *arg1 != '\t')
1991*65860Sbostic error ("Arguments must be choice numbers.");
1992*65860Sbostic
1993*65860Sbostic num = atoi (args);
1994*65860Sbostic
1995*65860Sbostic if (num == 0)
1996*65860Sbostic error ("cancelled");
1997*65860Sbostic else if (num == 1)
1998*65860Sbostic {
1999*65860Sbostic memcpy (return_values.sals, values.sals,
2000*65860Sbostic (nelts * sizeof(struct symtab_and_line)));
2001*65860Sbostic return_values.nelts = nelts;
2002*65860Sbostic return return_values;
2003*65860Sbostic }
2004*65860Sbostic
2005*65860Sbostic if (num > nelts + 2)
2006*65860Sbostic {
2007*65860Sbostic printf ("No choice number %d.\n", num);
2008*65860Sbostic }
2009*65860Sbostic else
2010*65860Sbostic {
2011*65860Sbostic num -= 2;
2012*65860Sbostic if (values.sals[num].pc)
2013*65860Sbostic {
2014*65860Sbostic return_values.sals[i++] = values.sals[num];
2015*65860Sbostic values.sals[num].pc = 0;
2016*65860Sbostic }
2017*65860Sbostic else
2018*65860Sbostic {
2019*65860Sbostic printf ("duplicate request for %d ignored.\n", num);
2020*65860Sbostic }
2021*65860Sbostic }
2022*65860Sbostic
2023*65860Sbostic args = arg1;
2024*65860Sbostic while (*args == ' ' || *args == '\t') args++;
2025*65860Sbostic }
2026*65860Sbostic return_values.nelts = i;
2027*65860Sbostic return return_values;
2028*65860Sbostic }
2029*65860Sbostic
2030*65860Sbostic
2031*65860Sbostic /* Slave routine for sources_info. Force line breaks at ,'s.
2032*65860Sbostic NAME is the name to print and *FIRST is nonzero if this is the first
2033*65860Sbostic name printed. Set *FIRST to zero. */
2034*65860Sbostic static void
output_source_filename(name,first)2035*65860Sbostic output_source_filename (name, first)
2036*65860Sbostic char *name;
2037*65860Sbostic int *first;
2038*65860Sbostic {
2039*65860Sbostic /* Table of files printed so far. Since a single source file can
2040*65860Sbostic result in several partial symbol tables, we need to avoid printing
2041*65860Sbostic it more than once. Note: if some of the psymtabs are read in and
2042*65860Sbostic some are not, it gets printed both under "Source files for which
2043*65860Sbostic symbols have been read" and "Source files for which symbols will
2044*65860Sbostic be read in on demand". I consider this a reasonable way to deal
2045*65860Sbostic with the situation. I'm not sure whether this can also happen for
2046*65860Sbostic symtabs; it doesn't hurt to check. */
2047*65860Sbostic static char **tab = NULL;
2048*65860Sbostic /* Allocated size of tab in elements.
2049*65860Sbostic Start with one 256-byte block (when using GNU malloc.c).
2050*65860Sbostic 24 is the malloc overhead when range checking is in effect. */
2051*65860Sbostic static int tab_alloc_size = (256 - 24) / sizeof (char *);
2052*65860Sbostic /* Current size of tab in elements. */
2053*65860Sbostic static int tab_cur_size;
2054*65860Sbostic
2055*65860Sbostic char **p;
2056*65860Sbostic
2057*65860Sbostic if (*first)
2058*65860Sbostic {
2059*65860Sbostic if (tab == NULL)
2060*65860Sbostic tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab));
2061*65860Sbostic tab_cur_size = 0;
2062*65860Sbostic }
2063*65860Sbostic
2064*65860Sbostic /* Is NAME in tab? */
2065*65860Sbostic for (p = tab; p < tab + tab_cur_size; p++)
2066*65860Sbostic if (strcmp (*p, name) == 0)
2067*65860Sbostic /* Yes; don't print it again. */
2068*65860Sbostic return;
2069*65860Sbostic /* No; add it to tab. */
2070*65860Sbostic if (tab_cur_size == tab_alloc_size)
2071*65860Sbostic {
2072*65860Sbostic tab_alloc_size *= 2;
2073*65860Sbostic tab = (char **) xrealloc ((char *) tab, tab_alloc_size * sizeof (*tab));
2074*65860Sbostic }
2075*65860Sbostic tab[tab_cur_size++] = name;
2076*65860Sbostic
2077*65860Sbostic if (*first)
2078*65860Sbostic {
2079*65860Sbostic *first = 0;
2080*65860Sbostic }
2081*65860Sbostic else
2082*65860Sbostic {
2083*65860Sbostic printf_filtered (", ");
2084*65860Sbostic }
2085*65860Sbostic
2086*65860Sbostic wrap_here ("");
2087*65860Sbostic fputs_filtered (name, stdout);
2088*65860Sbostic }
2089*65860Sbostic
2090*65860Sbostic static void
sources_info(ignore,from_tty)2091*65860Sbostic sources_info (ignore, from_tty)
2092*65860Sbostic char *ignore;
2093*65860Sbostic int from_tty;
2094*65860Sbostic {
2095*65860Sbostic register struct symtab *s;
2096*65860Sbostic register struct partial_symtab *ps;
2097*65860Sbostic register struct objfile *objfile;
2098*65860Sbostic int first;
2099*65860Sbostic
2100*65860Sbostic if (!have_full_symbols () && !have_partial_symbols ())
2101*65860Sbostic {
2102*65860Sbostic error (no_symtab_msg);
2103*65860Sbostic }
2104*65860Sbostic
2105*65860Sbostic printf_filtered ("Source files for which symbols have been read in:\n\n");
2106*65860Sbostic
2107*65860Sbostic first = 1;
2108*65860Sbostic ALL_SYMTABS (objfile, s)
2109*65860Sbostic {
2110*65860Sbostic output_source_filename (s -> filename, &first);
2111*65860Sbostic }
2112*65860Sbostic printf_filtered ("\n\n");
2113*65860Sbostic
2114*65860Sbostic printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2115*65860Sbostic
2116*65860Sbostic first = 1;
2117*65860Sbostic ALL_PSYMTABS (objfile, ps)
2118*65860Sbostic {
2119*65860Sbostic if (!ps->readin)
2120*65860Sbostic {
2121*65860Sbostic output_source_filename (ps -> filename, &first);
2122*65860Sbostic }
2123*65860Sbostic }
2124*65860Sbostic printf_filtered ("\n");
2125*65860Sbostic }
2126*65860Sbostic
2127*65860Sbostic static int
name_match(name)2128*65860Sbostic name_match (name)
2129*65860Sbostic char *name;
2130*65860Sbostic {
2131*65860Sbostic char *demangled = cplus_demangle (name, DMGL_ANSI);
2132*65860Sbostic if (demangled != NULL)
2133*65860Sbostic {
2134*65860Sbostic int cond = re_exec (demangled);
2135*65860Sbostic free (demangled);
2136*65860Sbostic return (cond);
2137*65860Sbostic }
2138*65860Sbostic return (re_exec (name));
2139*65860Sbostic }
2140*65860Sbostic #define NAME_MATCH(NAME) name_match(NAME)
2141*65860Sbostic
2142*65860Sbostic /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2143*65860Sbostic If CLASS is zero, list all symbols except functions, type names, and
2144*65860Sbostic constants (enums).
2145*65860Sbostic If CLASS is 1, list only functions.
2146*65860Sbostic If CLASS is 2, list only type names.
2147*65860Sbostic If CLASS is 3, list only method names.
2148*65860Sbostic
2149*65860Sbostic BPT is non-zero if we should set a breakpoint at the functions
2150*65860Sbostic we find. */
2151*65860Sbostic
2152*65860Sbostic static void
list_symbols(regexp,class,bpt)2153*65860Sbostic list_symbols (regexp, class, bpt)
2154*65860Sbostic char *regexp;
2155*65860Sbostic int class;
2156*65860Sbostic int bpt;
2157*65860Sbostic {
2158*65860Sbostic register struct symtab *s;
2159*65860Sbostic register struct partial_symtab *ps;
2160*65860Sbostic register struct blockvector *bv;
2161*65860Sbostic struct blockvector *prev_bv = 0;
2162*65860Sbostic register struct block *b;
2163*65860Sbostic register int i, j;
2164*65860Sbostic register struct symbol *sym;
2165*65860Sbostic struct partial_symbol *psym;
2166*65860Sbostic struct objfile *objfile;
2167*65860Sbostic struct minimal_symbol *msymbol;
2168*65860Sbostic char *val;
2169*65860Sbostic static char *classnames[]
2170*65860Sbostic = {"variable", "function", "type", "method"};
2171*65860Sbostic int found_in_file = 0;
2172*65860Sbostic int found_misc = 0;
2173*65860Sbostic static enum minimal_symbol_type types[]
2174*65860Sbostic = {mst_data, mst_text, mst_abs, mst_unknown};
2175*65860Sbostic static enum minimal_symbol_type types2[]
2176*65860Sbostic = {mst_bss, mst_text, mst_abs, mst_unknown};
2177*65860Sbostic enum minimal_symbol_type ourtype = types[class];
2178*65860Sbostic enum minimal_symbol_type ourtype2 = types2[class];
2179*65860Sbostic
2180*65860Sbostic if (regexp)
2181*65860Sbostic {
2182*65860Sbostic /* Make sure spacing is right for C++ operators.
2183*65860Sbostic This is just a courtesy to make the matching less sensitive
2184*65860Sbostic to how many spaces the user leaves between 'operator'
2185*65860Sbostic and <TYPENAME> or <OPERATOR>. */
2186*65860Sbostic char *opend;
2187*65860Sbostic char *opname = operator_chars (regexp, &opend);
2188*65860Sbostic if (*opname)
2189*65860Sbostic {
2190*65860Sbostic int fix = -1; /* -1 means ok; otherwise number of spaces needed. */
2191*65860Sbostic if (isalpha(*opname) || *opname == '_' || *opname == '$')
2192*65860Sbostic {
2193*65860Sbostic /* There should 1 space between 'operator' and 'TYPENAME'. */
2194*65860Sbostic if (opname[-1] != ' ' || opname[-2] == ' ')
2195*65860Sbostic fix = 1;
2196*65860Sbostic }
2197*65860Sbostic else
2198*65860Sbostic {
2199*65860Sbostic /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2200*65860Sbostic if (opname[-1] == ' ')
2201*65860Sbostic fix = 0;
2202*65860Sbostic }
2203*65860Sbostic /* If wrong number of spaces, fix it. */
2204*65860Sbostic if (fix >= 0)
2205*65860Sbostic {
2206*65860Sbostic char *tmp = (char*) alloca(opend-opname+10);
2207*65860Sbostic sprintf(tmp, "operator%.*s%s", fix, " ", opname);
2208*65860Sbostic regexp = tmp;
2209*65860Sbostic }
2210*65860Sbostic }
2211*65860Sbostic
2212*65860Sbostic if (0 != (val = re_comp (regexp)))
2213*65860Sbostic error ("Invalid regexp (%s): %s", val, regexp);
2214*65860Sbostic }
2215*65860Sbostic
2216*65860Sbostic /* Search through the partial symtabs *first* for all symbols
2217*65860Sbostic matching the regexp. That way we don't have to reproduce all of
2218*65860Sbostic the machinery below. */
2219*65860Sbostic
2220*65860Sbostic ALL_PSYMTABS (objfile, ps)
2221*65860Sbostic {
2222*65860Sbostic struct partial_symbol *bound, *gbound, *sbound;
2223*65860Sbostic int keep_going = 1;
2224*65860Sbostic
2225*65860Sbostic if (ps->readin) continue;
2226*65860Sbostic
2227*65860Sbostic gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms;
2228*65860Sbostic sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms;
2229*65860Sbostic bound = gbound;
2230*65860Sbostic
2231*65860Sbostic /* Go through all of the symbols stored in a partial
2232*65860Sbostic symtab in one loop. */
2233*65860Sbostic psym = objfile->global_psymbols.list + ps->globals_offset;
2234*65860Sbostic while (keep_going)
2235*65860Sbostic {
2236*65860Sbostic if (psym >= bound)
2237*65860Sbostic {
2238*65860Sbostic if (bound == gbound && ps->n_static_syms != 0)
2239*65860Sbostic {
2240*65860Sbostic psym = objfile->static_psymbols.list + ps->statics_offset;
2241*65860Sbostic bound = sbound;
2242*65860Sbostic }
2243*65860Sbostic else
2244*65860Sbostic keep_going = 0;
2245*65860Sbostic continue;
2246*65860Sbostic }
2247*65860Sbostic else
2248*65860Sbostic {
2249*65860Sbostic QUIT;
2250*65860Sbostic
2251*65860Sbostic /* If it would match (logic taken from loop below)
2252*65860Sbostic load the file and go on to the next one */
2253*65860Sbostic if ((regexp == 0 || NAME_MATCH (SYMBOL_NAME (psym)))
2254*65860Sbostic && ((class == 0 && SYMBOL_CLASS (psym) != LOC_TYPEDEF
2255*65860Sbostic && SYMBOL_CLASS (psym) != LOC_BLOCK)
2256*65860Sbostic || (class == 1 && SYMBOL_CLASS (psym) == LOC_BLOCK)
2257*65860Sbostic || (class == 2 && SYMBOL_CLASS (psym) == LOC_TYPEDEF)
2258*65860Sbostic || (class == 3 && SYMBOL_CLASS (psym) == LOC_BLOCK)))
2259*65860Sbostic {
2260*65860Sbostic PSYMTAB_TO_SYMTAB(ps);
2261*65860Sbostic keep_going = 0;
2262*65860Sbostic }
2263*65860Sbostic }
2264*65860Sbostic psym++;
2265*65860Sbostic }
2266*65860Sbostic }
2267*65860Sbostic
2268*65860Sbostic /* Here, we search through the minimal symbol tables for functions that
2269*65860Sbostic match, and call find_pc_symtab on them to force their symbols to
2270*65860Sbostic be read. The symbol will then be found during the scan of symtabs
2271*65860Sbostic below. If find_pc_symtab fails, set found_misc so that we will
2272*65860Sbostic rescan to print any matching symbols without debug info. */
2273*65860Sbostic
2274*65860Sbostic if (class == 1)
2275*65860Sbostic {
2276*65860Sbostic ALL_MSYMBOLS (objfile, msymbol)
2277*65860Sbostic {
2278*65860Sbostic if (msymbol -> type == ourtype || msymbol -> type == ourtype2)
2279*65860Sbostic {
2280*65860Sbostic if (regexp == 0 || NAME_MATCH (msymbol -> name))
2281*65860Sbostic {
2282*65860Sbostic if (0 == find_pc_symtab (msymbol -> address))
2283*65860Sbostic {
2284*65860Sbostic found_misc = 1;
2285*65860Sbostic }
2286*65860Sbostic }
2287*65860Sbostic }
2288*65860Sbostic }
2289*65860Sbostic }
2290*65860Sbostic
2291*65860Sbostic /* Printout here so as to get after the "Reading in symbols"
2292*65860Sbostic messages which will be generated above. */
2293*65860Sbostic if (!bpt)
2294*65860Sbostic printf_filtered (regexp
2295*65860Sbostic ? "All %ss matching regular expression \"%s\":\n"
2296*65860Sbostic : "All defined %ss:\n",
2297*65860Sbostic classnames[class],
2298*65860Sbostic regexp);
2299*65860Sbostic
2300*65860Sbostic ALL_SYMTABS (objfile, s)
2301*65860Sbostic {
2302*65860Sbostic found_in_file = 0;
2303*65860Sbostic bv = BLOCKVECTOR (s);
2304*65860Sbostic /* Often many files share a blockvector.
2305*65860Sbostic Scan each blockvector only once so that
2306*65860Sbostic we don't get every symbol many times.
2307*65860Sbostic It happens that the first symtab in the list
2308*65860Sbostic for any given blockvector is the main file. */
2309*65860Sbostic if (bv != prev_bv)
2310*65860Sbostic for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
2311*65860Sbostic {
2312*65860Sbostic b = BLOCKVECTOR_BLOCK (bv, i);
2313*65860Sbostic /* Skip the sort if this block is always sorted. */
2314*65860Sbostic if (!BLOCK_SHOULD_SORT (b))
2315*65860Sbostic sort_block_syms (b);
2316*65860Sbostic for (j = 0; j < BLOCK_NSYMS (b); j++)
2317*65860Sbostic {
2318*65860Sbostic QUIT;
2319*65860Sbostic sym = BLOCK_SYM (b, j);
2320*65860Sbostic if ((regexp == 0 || NAME_MATCH (SYMBOL_NAME (sym)))
2321*65860Sbostic && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
2322*65860Sbostic && SYMBOL_CLASS (sym) != LOC_BLOCK
2323*65860Sbostic && SYMBOL_CLASS (sym) != LOC_CONST)
2324*65860Sbostic || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
2325*65860Sbostic || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2326*65860Sbostic || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))
2327*65860Sbostic {
2328*65860Sbostic if (bpt)
2329*65860Sbostic {
2330*65860Sbostic /* Set a breakpoint here, if it's a function */
2331*65860Sbostic if (class == 1)
2332*65860Sbostic break_command (SYMBOL_NAME(sym), 0);
2333*65860Sbostic }
2334*65860Sbostic else if (!found_in_file)
2335*65860Sbostic {
2336*65860Sbostic fputs_filtered ("\nFile ", stdout);
2337*65860Sbostic fputs_filtered (s->filename, stdout);
2338*65860Sbostic fputs_filtered (":\n", stdout);
2339*65860Sbostic }
2340*65860Sbostic found_in_file = 1;
2341*65860Sbostic
2342*65860Sbostic if (class != 2 && i == STATIC_BLOCK)
2343*65860Sbostic printf_filtered ("static ");
2344*65860Sbostic
2345*65860Sbostic /* Typedef that is not a C++ class */
2346*65860Sbostic if (class == 2
2347*65860Sbostic && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
2348*65860Sbostic typedef_print (SYMBOL_TYPE(sym), sym, stdout);
2349*65860Sbostic /* variable, func, or typedef-that-is-c++-class */
2350*65860Sbostic else if (class < 2 ||
2351*65860Sbostic (class == 2 &&
2352*65860Sbostic SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE))
2353*65860Sbostic {
2354*65860Sbostic type_print (SYMBOL_TYPE (sym),
2355*65860Sbostic (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2356*65860Sbostic ? "" : SYMBOL_NAME (sym)),
2357*65860Sbostic stdout, 0);
2358*65860Sbostic
2359*65860Sbostic printf_filtered (";\n");
2360*65860Sbostic }
2361*65860Sbostic else
2362*65860Sbostic {
2363*65860Sbostic # if 0
2364*65860Sbostic /* FIXME, why is this zapped out? */
2365*65860Sbostic char buf[1024];
2366*65860Sbostic type_print_base (TYPE_FN_FIELD_TYPE(t, i), stdout, 0, 0);
2367*65860Sbostic type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), stdout, 0);
2368*65860Sbostic sprintf (buf, " %s::", type_name_no_tag (t));
2369*65860Sbostic type_print_method_args (TYPE_FN_FIELD_ARGS (t, i), buf, name, stdout);
2370*65860Sbostic # endif
2371*65860Sbostic }
2372*65860Sbostic }
2373*65860Sbostic }
2374*65860Sbostic }
2375*65860Sbostic prev_bv = bv;
2376*65860Sbostic }
2377*65860Sbostic
2378*65860Sbostic /* If there are no eyes, avoid all contact. I mean, if there are
2379*65860Sbostic no debug symbols, then print directly from the msymbol_vector. */
2380*65860Sbostic
2381*65860Sbostic if (found_misc || class != 1)
2382*65860Sbostic {
2383*65860Sbostic found_in_file = 0;
2384*65860Sbostic ALL_MSYMBOLS (objfile, msymbol)
2385*65860Sbostic {
2386*65860Sbostic if (msymbol -> type == ourtype || msymbol -> type == ourtype2)
2387*65860Sbostic {
2388*65860Sbostic if (regexp == 0 || NAME_MATCH (msymbol -> name))
2389*65860Sbostic {
2390*65860Sbostic /* Functions: Look up by address. */
2391*65860Sbostic if (class != 1 ||
2392*65860Sbostic (0 == find_pc_symtab (msymbol -> address)))
2393*65860Sbostic {
2394*65860Sbostic /* Variables/Absolutes: Look up by name */
2395*65860Sbostic if (lookup_symbol (msymbol -> name,
2396*65860Sbostic (struct block *) 0, VAR_NAMESPACE, 0,
2397*65860Sbostic (struct symtab **) 0) == NULL)
2398*65860Sbostic {
2399*65860Sbostic if (!found_in_file)
2400*65860Sbostic {
2401*65860Sbostic printf_filtered ("\nNon-debugging symbols:\n");
2402*65860Sbostic found_in_file = 1;
2403*65860Sbostic }
2404*65860Sbostic printf_filtered (" %08x %s\n",
2405*65860Sbostic msymbol -> address,
2406*65860Sbostic msymbol -> name);
2407*65860Sbostic }
2408*65860Sbostic }
2409*65860Sbostic }
2410*65860Sbostic }
2411*65860Sbostic }
2412*65860Sbostic }
2413*65860Sbostic }
2414*65860Sbostic
2415*65860Sbostic static void
variables_info(regexp,from_tty)2416*65860Sbostic variables_info (regexp, from_tty)
2417*65860Sbostic char *regexp;
2418*65860Sbostic int from_tty;
2419*65860Sbostic {
2420*65860Sbostic list_symbols (regexp, 0, 0);
2421*65860Sbostic }
2422*65860Sbostic
2423*65860Sbostic static void
functions_info(regexp,from_tty)2424*65860Sbostic functions_info (regexp, from_tty)
2425*65860Sbostic char *regexp;
2426*65860Sbostic int from_tty;
2427*65860Sbostic {
2428*65860Sbostic list_symbols (regexp, 1, 0);
2429*65860Sbostic }
2430*65860Sbostic
2431*65860Sbostic static void
types_info(regexp,from_tty)2432*65860Sbostic types_info (regexp, from_tty)
2433*65860Sbostic char *regexp;
2434*65860Sbostic int from_tty;
2435*65860Sbostic {
2436*65860Sbostic list_symbols (regexp, 2, 0);
2437*65860Sbostic }
2438*65860Sbostic
2439*65860Sbostic #if 0
2440*65860Sbostic /* Tiemann says: "info methods was never implemented." */
2441*65860Sbostic static void
2442*65860Sbostic methods_info (regexp)
2443*65860Sbostic char *regexp;
2444*65860Sbostic {
2445*65860Sbostic list_symbols (regexp, 3, 0);
2446*65860Sbostic }
2447*65860Sbostic #endif /* 0 */
2448*65860Sbostic
2449*65860Sbostic /* Breakpoint all functions matching regular expression. */
2450*65860Sbostic static void
rbreak_command(regexp,from_tty)2451*65860Sbostic rbreak_command (regexp, from_tty)
2452*65860Sbostic char *regexp;
2453*65860Sbostic int from_tty;
2454*65860Sbostic {
2455*65860Sbostic list_symbols (regexp, 1, 1);
2456*65860Sbostic }
2457*65860Sbostic
2458*65860Sbostic
2459*65860Sbostic /* Return Nonzero if block a is lexically nested within block b,
2460*65860Sbostic or if a and b have the same pc range.
2461*65860Sbostic Return zero otherwise. */
2462*65860Sbostic int
contained_in(a,b)2463*65860Sbostic contained_in (a, b)
2464*65860Sbostic struct block *a, *b;
2465*65860Sbostic {
2466*65860Sbostic if (!a || !b)
2467*65860Sbostic return 0;
2468*65860Sbostic return BLOCK_START (a) >= BLOCK_START (b)
2469*65860Sbostic && BLOCK_END (a) <= BLOCK_END (b);
2470*65860Sbostic }
2471*65860Sbostic
2472*65860Sbostic
2473*65860Sbostic /* Helper routine for make_symbol_completion_list. */
2474*65860Sbostic
2475*65860Sbostic static int return_val_size;
2476*65860Sbostic static int return_val_index;
2477*65860Sbostic static char **return_val;
2478*65860Sbostic
2479*65860Sbostic static void
completion_list_add_name(name)2480*65860Sbostic completion_list_add_name(name)
2481*65860Sbostic char *name;
2482*65860Sbostic {
2483*65860Sbostic if (return_val_index + 3 > return_val_size)
2484*65860Sbostic return_val = (char **) xrealloc ((char *) return_val,
2485*65860Sbostic (return_val_size *= 2) * sizeof (char *));
2486*65860Sbostic
2487*65860Sbostic return_val[return_val_index] = name;
2488*65860Sbostic return_val[++return_val_index] = (char *)NULL;
2489*65860Sbostic }
2490*65860Sbostic
2491*65860Sbostic static void
completion_list_check_symbol(symname,text,text_len)2492*65860Sbostic completion_list_check_symbol (symname, text, text_len)
2493*65860Sbostic char *symname;
2494*65860Sbostic char *text;
2495*65860Sbostic int text_len;
2496*65860Sbostic {
2497*65860Sbostic register char *cp;
2498*65860Sbostic
2499*65860Sbostic if ((cp = cplus_demangle(symname, -1)) != NULL)
2500*65860Sbostic {
2501*65860Sbostic if (strncmp(cp, text, text_len) == 0 && strncmp(symname, "_vt$", 4))
2502*65860Sbostic completion_list_add_name(cp);
2503*65860Sbostic else
2504*65860Sbostic free(cp);
2505*65860Sbostic }
2506*65860Sbostic else if ((strncmp (symname, text, text_len) == 0))
2507*65860Sbostic {
2508*65860Sbostic cp = (char *)xmalloc (1 + strlen (symname));
2509*65860Sbostic strcpy(cp, symname);
2510*65860Sbostic completion_list_add_name(cp);
2511*65860Sbostic }
2512*65860Sbostic }
2513*65860Sbostic
2514*65860Sbostic /* Return a NULL terminated array of all symbols (regardless of class) which
2515*65860Sbostic begin by matching TEXT. If the answer is no symbols, then the return value
2516*65860Sbostic is an array which contains only a NULL pointer.
2517*65860Sbostic
2518*65860Sbostic Problem: All of the symbols have to be copied because readline frees them.
2519*65860Sbostic I'm not going to worry about this; hopefully there won't be that many. */
2520*65860Sbostic
2521*65860Sbostic char **
make_completion_list(text,wantclass)2522*65860Sbostic make_completion_list (text, wantclass)
2523*65860Sbostic char *text;
2524*65860Sbostic enum address_class wantclass;
2525*65860Sbostic {
2526*65860Sbostic register struct symbol *sym;
2527*65860Sbostic register struct symtab *s;
2528*65860Sbostic register struct partial_symtab *ps;
2529*65860Sbostic register struct minimal_symbol *msymbol;
2530*65860Sbostic register struct objfile *objfile;
2531*65860Sbostic register struct block *b, *surrounding_static_block = 0;
2532*65860Sbostic register int i, j;
2533*65860Sbostic int text_len;
2534*65860Sbostic struct partial_symbol *psym;
2535*65860Sbostic
2536*65860Sbostic text_len = strlen (text);
2537*65860Sbostic return_val_size = 100;
2538*65860Sbostic return_val_index = 0;
2539*65860Sbostic return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
2540*65860Sbostic return_val[0] = NULL;
2541*65860Sbostic
2542*65860Sbostic /* Look through the partial symtabs for all symbols which begin
2543*65860Sbostic by matching TEXT. Add each one that you find to the list. */
2544*65860Sbostic
2545*65860Sbostic ALL_PSYMTABS (objfile, ps)
2546*65860Sbostic {
2547*65860Sbostic /* If the psymtab's been read in we'll get it when we search
2548*65860Sbostic through the blockvector. */
2549*65860Sbostic if (ps->readin) continue;
2550*65860Sbostic
2551*65860Sbostic for (psym = objfile->global_psymbols.list + ps->globals_offset;
2552*65860Sbostic psym < (objfile->global_psymbols.list + ps->globals_offset
2553*65860Sbostic + ps->n_global_syms);
2554*65860Sbostic psym++)
2555*65860Sbostic {
2556*65860Sbostic /* If interrupted, then quit. */
2557*65860Sbostic QUIT;
2558*65860Sbostic if (wantclass && wantclass != SYMBOL_CLASS (psym))
2559*65860Sbostic continue;
2560*65860Sbostic completion_list_check_symbol (SYMBOL_NAME (psym), text, text_len);
2561*65860Sbostic }
2562*65860Sbostic
2563*65860Sbostic for (psym = objfile->static_psymbols.list + ps->statics_offset;
2564*65860Sbostic psym < (objfile->static_psymbols.list + ps->statics_offset
2565*65860Sbostic + ps->n_static_syms);
2566*65860Sbostic psym++)
2567*65860Sbostic {
2568*65860Sbostic QUIT;
2569*65860Sbostic if (wantclass && wantclass != SYMBOL_CLASS (psym))
2570*65860Sbostic continue;
2571*65860Sbostic completion_list_check_symbol (SYMBOL_NAME (psym), text, text_len);
2572*65860Sbostic }
2573*65860Sbostic }
2574*65860Sbostic
2575*65860Sbostic /* At this point scan through the misc symbol vectors and add each
2576*65860Sbostic symbol you find to the list. Eventually we want to ignore
2577*65860Sbostic anything that isn't a text symbol (everything else will be
2578*65860Sbostic handled by the psymtab code above). */
2579*65860Sbostic
2580*65860Sbostic ALL_MSYMBOLS (objfile, msymbol)
2581*65860Sbostic {
2582*65860Sbostic QUIT;
2583*65860Sbostic completion_list_check_symbol (msymbol -> name, text, text_len);
2584*65860Sbostic }
2585*65860Sbostic
2586*65860Sbostic /* Search upwards from currently selected frame (so that we can
2587*65860Sbostic complete on local vars. */
2588*65860Sbostic
2589*65860Sbostic for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
2590*65860Sbostic {
2591*65860Sbostic if (!BLOCK_SUPERBLOCK (b))
2592*65860Sbostic {
2593*65860Sbostic surrounding_static_block = b; /* For elmin of dups */
2594*65860Sbostic }
2595*65860Sbostic
2596*65860Sbostic /* Also catch fields of types defined in this places which match our
2597*65860Sbostic text string. Only complete on types visible from current context. */
2598*65860Sbostic
2599*65860Sbostic for (i = 0; i < BLOCK_NSYMS (b); i++)
2600*65860Sbostic {
2601*65860Sbostic sym = BLOCK_SYM (b, i);
2602*65860Sbostic if (wantclass && wantclass != SYMBOL_CLASS (sym))
2603*65860Sbostic continue;
2604*65860Sbostic completion_list_check_symbol (SYMBOL_NAME (sym), text, text_len);
2605*65860Sbostic if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2606*65860Sbostic {
2607*65860Sbostic struct type *t = SYMBOL_TYPE (sym);
2608*65860Sbostic enum type_code c = TYPE_CODE (t);
2609*65860Sbostic
2610*65860Sbostic if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
2611*65860Sbostic {
2612*65860Sbostic for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
2613*65860Sbostic {
2614*65860Sbostic if (TYPE_FIELD_NAME (t, j))
2615*65860Sbostic {
2616*65860Sbostic completion_list_check_symbol (TYPE_FIELD_NAME (t, j),
2617*65860Sbostic text, text_len);
2618*65860Sbostic }
2619*65860Sbostic }
2620*65860Sbostic }
2621*65860Sbostic }
2622*65860Sbostic }
2623*65860Sbostic }
2624*65860Sbostic
2625*65860Sbostic /* Go through the symtabs and check the externs and statics for
2626*65860Sbostic symbols which match. */
2627*65860Sbostic
2628*65860Sbostic ALL_SYMTABS (objfile, s)
2629*65860Sbostic {
2630*65860Sbostic QUIT;
2631*65860Sbostic b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
2632*65860Sbostic for (i = 0; i < BLOCK_NSYMS (b); i++)
2633*65860Sbostic {
2634*65860Sbostic sym = BLOCK_SYM (b, i);
2635*65860Sbostic if (wantclass && wantclass != SYMBOL_CLASS (sym))
2636*65860Sbostic continue;
2637*65860Sbostic completion_list_check_symbol (SYMBOL_NAME (sym), text, text_len);
2638*65860Sbostic }
2639*65860Sbostic }
2640*65860Sbostic
2641*65860Sbostic ALL_SYMTABS (objfile, s)
2642*65860Sbostic {
2643*65860Sbostic QUIT;
2644*65860Sbostic b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
2645*65860Sbostic /* Don't do this block twice. */
2646*65860Sbostic if (b == surrounding_static_block) continue;
2647*65860Sbostic for (i = 0; i < BLOCK_NSYMS (b); i++)
2648*65860Sbostic {
2649*65860Sbostic sym = BLOCK_SYM (b, i);
2650*65860Sbostic if (wantclass && wantclass != SYMBOL_CLASS (sym))
2651*65860Sbostic continue;
2652*65860Sbostic completion_list_check_symbol (SYMBOL_NAME (sym), text, text_len);
2653*65860Sbostic }
2654*65860Sbostic }
2655*65860Sbostic
2656*65860Sbostic return (return_val);
2657*65860Sbostic }
2658*65860Sbostic
2659*65860Sbostic char **
make_function_completion_list(text)2660*65860Sbostic make_function_completion_list (text)
2661*65860Sbostic char *text;
2662*65860Sbostic {
2663*65860Sbostic return (make_completion_list(text, LOC_BLOCK));
2664*65860Sbostic }
2665*65860Sbostic
2666*65860Sbostic char **
make_symbol_completion_list(text)2667*65860Sbostic make_symbol_completion_list (text)
2668*65860Sbostic char *text;
2669*65860Sbostic {
2670*65860Sbostic return (make_completion_list(text, 0));
2671*65860Sbostic }
2672*65860Sbostic
2673*65860Sbostic /* Find a mangled symbol that corresponds to LOOKFOR using brute force.
2674*65860Sbostic Basically we go munging through available symbols, demangling each one,
2675*65860Sbostic looking for a match on the demangled result. */
2676*65860Sbostic
2677*65860Sbostic static char *
expensive_mangler(lookfor)2678*65860Sbostic expensive_mangler (lookfor)
2679*65860Sbostic const char *lookfor;
2680*65860Sbostic {
2681*65860Sbostic register struct symbol *sym;
2682*65860Sbostic register struct symtab *s;
2683*65860Sbostic register struct partial_symtab *ps;
2684*65860Sbostic register struct minimal_symbol *msymbol;
2685*65860Sbostic register struct objfile *objfile;
2686*65860Sbostic register struct block *b, *surrounding_static_block = 0;
2687*65860Sbostic register int i, j;
2688*65860Sbostic struct partial_symbol *psym;
2689*65860Sbostic char *demangled;
2690*65860Sbostic
2691*65860Sbostic /* Look through the partial symtabs for a symbol that matches */
2692*65860Sbostic
2693*65860Sbostic ALL_PSYMTABS (objfile, ps)
2694*65860Sbostic {
2695*65860Sbostic /* If the psymtab's been read in we'll get it when we search
2696*65860Sbostic through the blockvector. */
2697*65860Sbostic if (ps->readin) continue;
2698*65860Sbostic
2699*65860Sbostic for (psym = objfile->global_psymbols.list + ps->globals_offset;
2700*65860Sbostic psym < (objfile->global_psymbols.list + ps->globals_offset
2701*65860Sbostic + ps->n_global_syms);
2702*65860Sbostic psym++)
2703*65860Sbostic {
2704*65860Sbostic QUIT; /* If interrupted, then quit. */
2705*65860Sbostic demangled = demangle_and_match (SYMBOL_NAME (psym), lookfor,
2706*65860Sbostic DMGL_PARAMS | DMGL_ANSI);
2707*65860Sbostic if (demangled != NULL)
2708*65860Sbostic {
2709*65860Sbostic free (demangled);
2710*65860Sbostic return (SYMBOL_NAME (psym));
2711*65860Sbostic }
2712*65860Sbostic }
2713*65860Sbostic
2714*65860Sbostic for (psym = objfile->static_psymbols.list + ps->statics_offset;
2715*65860Sbostic psym < (objfile->static_psymbols.list + ps->statics_offset
2716*65860Sbostic + ps->n_static_syms);
2717*65860Sbostic psym++)
2718*65860Sbostic {
2719*65860Sbostic QUIT;
2720*65860Sbostic demangled = demangle_and_match (SYMBOL_NAME (psym), lookfor,
2721*65860Sbostic DMGL_PARAMS | DMGL_ANSI);
2722*65860Sbostic if (demangled != NULL)
2723*65860Sbostic {
2724*65860Sbostic free (demangled);
2725*65860Sbostic return (SYMBOL_NAME (psym));
2726*65860Sbostic }
2727*65860Sbostic }
2728*65860Sbostic }
2729*65860Sbostic
2730*65860Sbostic /* Scan through the misc symbol vectors looking for a match. */
2731*65860Sbostic
2732*65860Sbostic ALL_MSYMBOLS (objfile, msymbol)
2733*65860Sbostic {
2734*65860Sbostic QUIT;
2735*65860Sbostic demangled = demangle_and_match (msymbol -> name, lookfor,
2736*65860Sbostic DMGL_PARAMS | DMGL_ANSI);
2737*65860Sbostic if (demangled != NULL)
2738*65860Sbostic {
2739*65860Sbostic free (demangled);
2740*65860Sbostic return (msymbol -> name);
2741*65860Sbostic }
2742*65860Sbostic }
2743*65860Sbostic
2744*65860Sbostic /* Search upwards from currently selected frame looking for a match */
2745*65860Sbostic
2746*65860Sbostic for (b = get_selected_block (); b; b = BLOCK_SUPERBLOCK (b))
2747*65860Sbostic {
2748*65860Sbostic if (!BLOCK_SUPERBLOCK (b))
2749*65860Sbostic surrounding_static_block = b; /* For elmin of dups */
2750*65860Sbostic
2751*65860Sbostic /* Also catch fields of types defined in this places which
2752*65860Sbostic match our text string. Only complete on types visible
2753*65860Sbostic from current context. */
2754*65860Sbostic for (i = 0; i < BLOCK_NSYMS (b); i++)
2755*65860Sbostic {
2756*65860Sbostic sym = BLOCK_SYM (b, i);
2757*65860Sbostic demangled = demangle_and_match (SYMBOL_NAME (sym), lookfor,
2758*65860Sbostic DMGL_PARAMS | DMGL_ANSI);
2759*65860Sbostic if (demangled != NULL)
2760*65860Sbostic {
2761*65860Sbostic free (demangled);
2762*65860Sbostic return (SYMBOL_NAME (sym));
2763*65860Sbostic }
2764*65860Sbostic if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2765*65860Sbostic {
2766*65860Sbostic struct type *t = SYMBOL_TYPE (sym);
2767*65860Sbostic enum type_code c = TYPE_CODE (t);
2768*65860Sbostic
2769*65860Sbostic if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
2770*65860Sbostic {
2771*65860Sbostic for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
2772*65860Sbostic {
2773*65860Sbostic if (TYPE_FIELD_NAME (t, j))
2774*65860Sbostic {
2775*65860Sbostic demangled =
2776*65860Sbostic demangle_and_match (TYPE_FIELD_NAME (t, j),
2777*65860Sbostic lookfor,
2778*65860Sbostic DMGL_PARAMS | DMGL_ANSI);
2779*65860Sbostic if (demangled != NULL)
2780*65860Sbostic {
2781*65860Sbostic free (demangled);
2782*65860Sbostic return (TYPE_FIELD_NAME (t, j));
2783*65860Sbostic }
2784*65860Sbostic }
2785*65860Sbostic }
2786*65860Sbostic }
2787*65860Sbostic }
2788*65860Sbostic }
2789*65860Sbostic }
2790*65860Sbostic
2791*65860Sbostic /* Go through the symtabs and check the externs and statics for
2792*65860Sbostic symbols which match. */
2793*65860Sbostic
2794*65860Sbostic ALL_SYMTABS (objfile, s)
2795*65860Sbostic {
2796*65860Sbostic QUIT;
2797*65860Sbostic b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
2798*65860Sbostic for (i = 0; i < BLOCK_NSYMS (b); i++)
2799*65860Sbostic {
2800*65860Sbostic sym = BLOCK_SYM (b, i);
2801*65860Sbostic demangled = demangle_and_match (SYMBOL_NAME (sym), lookfor,
2802*65860Sbostic DMGL_PARAMS | DMGL_ANSI);
2803*65860Sbostic if (demangled != NULL)
2804*65860Sbostic {
2805*65860Sbostic free (demangled);
2806*65860Sbostic return (SYMBOL_NAME (sym));
2807*65860Sbostic }
2808*65860Sbostic }
2809*65860Sbostic }
2810*65860Sbostic
2811*65860Sbostic ALL_SYMTABS (objfile, s)
2812*65860Sbostic {
2813*65860Sbostic QUIT;
2814*65860Sbostic b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
2815*65860Sbostic /* Don't do this block twice. */
2816*65860Sbostic if (b == surrounding_static_block) continue;
2817*65860Sbostic for (i = 0; i < BLOCK_NSYMS (b); i++)
2818*65860Sbostic {
2819*65860Sbostic sym = BLOCK_SYM (b, i);
2820*65860Sbostic demangled = demangle_and_match (SYMBOL_NAME (sym), lookfor,
2821*65860Sbostic DMGL_PARAMS | DMGL_ANSI);
2822*65860Sbostic if (demangled != NULL)
2823*65860Sbostic {
2824*65860Sbostic free (demangled);
2825*65860Sbostic return (SYMBOL_NAME (sym));
2826*65860Sbostic }
2827*65860Sbostic }
2828*65860Sbostic }
2829*65860Sbostic
2830*65860Sbostic return (NULL);
2831*65860Sbostic }
2832*65860Sbostic
2833*65860Sbostic #if 0
2834*65860Sbostic /* Add the type of the symbol sym to the type of the current
2835*65860Sbostic function whose block we are in (assumed). The type of
2836*65860Sbostic this current function is contained in *TYPE.
2837*65860Sbostic
2838*65860Sbostic This basically works as follows: When we find a function
2839*65860Sbostic symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
2840*65860Sbostic a pointer to its type in the global in_function_type. Every
2841*65860Sbostic time we come across a parameter symbol ('p' in its name), then
2842*65860Sbostic this procedure adds the name and type of that parameter
2843*65860Sbostic to the function type pointed to by *TYPE. (Which should correspond
2844*65860Sbostic to in_function_type if it was called correctly).
2845*65860Sbostic
2846*65860Sbostic Note that since we are modifying a type, the result of
2847*65860Sbostic lookup_function_type() should be memcpy()ed before calling
2848*65860Sbostic this. When not in strict typing mode, the expression
2849*65860Sbostic evaluator can choose to ignore this.
2850*65860Sbostic
2851*65860Sbostic Assumption: All of a function's parameter symbols will
2852*65860Sbostic appear before another function symbol is found. The parameters
2853*65860Sbostic appear in the same order in the argument list as they do in the
2854*65860Sbostic symbol table. */
2855*65860Sbostic
2856*65860Sbostic void
2857*65860Sbostic add_param_to_type (type,sym)
2858*65860Sbostic struct type **type;
2859*65860Sbostic struct symbol *sym;
2860*65860Sbostic {
2861*65860Sbostic int num = ++(TYPE_NFIELDS(*type));
2862*65860Sbostic
2863*65860Sbostic if(TYPE_NFIELDS(*type)-1)
2864*65860Sbostic TYPE_FIELDS(*type) = (struct field *)
2865*65860Sbostic (*current_objfile->xrealloc) ((char *)(TYPE_FIELDS(*type)),
2866*65860Sbostic num*sizeof(struct field));
2867*65860Sbostic else
2868*65860Sbostic TYPE_FIELDS(*type) = (struct field *)
2869*65860Sbostic (*current_objfile->xmalloc) (num*sizeof(struct field));
2870*65860Sbostic
2871*65860Sbostic TYPE_FIELD_BITPOS(*type,num-1) = num-1;
2872*65860Sbostic TYPE_FIELD_BITSIZE(*type,num-1) = 0;
2873*65860Sbostic TYPE_FIELD_TYPE(*type,num-1) = SYMBOL_TYPE(sym);
2874*65860Sbostic TYPE_FIELD_NAME(*type,num-1) = SYMBOL_NAME(sym);
2875*65860Sbostic }
2876*65860Sbostic #endif
2877*65860Sbostic
2878*65860Sbostic void
_initialize_symtab()2879*65860Sbostic _initialize_symtab ()
2880*65860Sbostic {
2881*65860Sbostic add_info ("variables", variables_info,
2882*65860Sbostic "All global and static variable names, or those matching REGEXP.");
2883*65860Sbostic add_info ("functions", functions_info,
2884*65860Sbostic "All function names, or those matching REGEXP.");
2885*65860Sbostic
2886*65860Sbostic /* FIXME: This command has at least the following problems:
2887*65860Sbostic 1. It prints builtin types (in a very strange and confusing fashion).
2888*65860Sbostic 2. It doesn't print right, e.g. with
2889*65860Sbostic typedef struct foo *FOO
2890*65860Sbostic type_print prints "FOO" when we want to make it (in this situation)
2891*65860Sbostic print "struct foo *".
2892*65860Sbostic I also think "ptype" or "whatis" is more likely to be useful (but if
2893*65860Sbostic there is much disagreement "info types" can be fixed). */
2894*65860Sbostic add_info ("types", types_info,
2895*65860Sbostic "All type names, or those matching REGEXP.");
2896*65860Sbostic
2897*65860Sbostic #if 0
2898*65860Sbostic add_info ("methods", methods_info,
2899*65860Sbostic "All method names, or those matching REGEXP::REGEXP.\n\
2900*65860Sbostic If the class qualifier is omitted, it is assumed to be the current scope.\n\
2901*65860Sbostic If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
2902*65860Sbostic are listed.");
2903*65860Sbostic #endif
2904*65860Sbostic add_info ("sources", sources_info,
2905*65860Sbostic "Source files in the program.");
2906*65860Sbostic
2907*65860Sbostic add_com ("rbreak", no_class, rbreak_command,
2908*65860Sbostic "Set a breakpoint for all functions matching REGEXP.");
2909*65860Sbostic
2910*65860Sbostic /* Initialize the one built-in type that isn't language dependent... */
2911*65860Sbostic builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0,
2912*65860Sbostic "<unknown type>", (struct objfile *) NULL);
2913*65860Sbostic }
2914