Tweak.
[deliverable/binutils-gdb.git] / gdb / symtab.c
CommitLineData
bd5635a1 1/* Symbol table lookup for the GNU debugger, GDB.
07422705 2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 1997
87041845 3 Free Software Foundation, Inc.
bd5635a1
RP
4
5This file is part of GDB.
6
997a978c 7This program is free software; you can redistribute it and/or modify
bd5635a1 8it under the terms of the GNU General Public License as published by
997a978c
JG
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
bd5635a1 11
997a978c 12This program is distributed in the hope that it will be useful,
bd5635a1
RP
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
997a978c 18along with this program; if not, write to the Free Software
f21c9aec 19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
bd5635a1 20
bd5635a1
RP
21#include "defs.h"
22#include "symtab.h"
cba0d141 23#include "gdbtypes.h"
bd5635a1
RP
24#include "gdbcore.h"
25#include "frame.h"
26#include "target.h"
27#include "value.h"
28#include "symfile.h"
35a25840 29#include "objfiles.h"
bd5635a1 30#include "gdbcmd.h"
35a25840 31#include "call-cmds.h"
811f1bdc 32#include "gnu-regex.h"
cba0d141 33#include "expression.h"
997a978c 34#include "language.h"
f70be3e4 35#include "demangle.h"
1a490ebc 36#include "inferior.h"
bd5635a1 37
1750a5ef 38#include "obstack.h"
bd5635a1
RP
39
40#include <sys/types.h>
41#include <fcntl.h>
2b576293
C
42#include "gdb_string.h"
43#include "gdb_stat.h"
2cd99985 44#include <ctype.h>
bd5635a1 45
cba0d141 46/* Prototypes for local functions */
bd5635a1 47
7f6cb62e 48static int
2e4964ad 49find_methods PARAMS ((struct type *, char *, struct symbol **));
cba0d141
JG
50
51static void
f1ed4330 52completion_list_add_name PARAMS ((char *, char *, int, char *, char *));
cba0d141 53
6f87ec4a
PS
54static void
55build_canonical_line_spec PARAMS ((struct symtab_and_line *, char *, char ***));
56
cba0d141 57static struct symtabs_and_lines
6f87ec4a 58decode_line_2 PARAMS ((struct symbol *[], int, int, char ***));
cba0d141
JG
59
60static void
35a25840 61rbreak_command PARAMS ((char *, int));
cba0d141
JG
62
63static void
35a25840 64types_info PARAMS ((char *, int));
cba0d141
JG
65
66static void
35a25840 67functions_info PARAMS ((char *, int));
cba0d141
JG
68
69static void
35a25840 70variables_info PARAMS ((char *, int));
cba0d141
JG
71
72static void
35a25840 73sources_info PARAMS ((char *, int));
cba0d141 74
cba0d141
JG
75static void
76output_source_filename PARAMS ((char *, int *));
77
a46d92a7 78char *
cba0d141
JG
79operator_chars PARAMS ((char *, char **));
80
018ab14f 81static int find_line_common PARAMS ((struct linetable *, int, int *));
cba0d141
JG
82
83static struct partial_symbol *
84lookup_partial_symbol PARAMS ((struct partial_symtab *, const char *,
1750a5ef 85 int, namespace_enum));
cba0d141 86
79f15b12
DE
87static struct partial_symbol *
88fixup_psymbol_section PARAMS ((struct partial_symbol *, struct objfile *));
89
cba0d141
JG
90static struct symtab *
91lookup_symtab_1 PARAMS ((char *));
92
b607efe7
FF
93static void
94cplusplus_hint PARAMS ((char *));
95
e21fb2ae
MS
96static struct symbol *
97find_active_alias PARAMS ((struct symbol *sym, CORE_ADDR addr));
98
cba0d141 99/* */
bd5635a1 100
997a978c 101/* The single non-language-specific builtin type */
bd5635a1
RP
102struct type *builtin_type_error;
103
104/* Block in which the most recently searched-for symbol was found.
105 Might be better to make this a parameter to lookup_symbol and
106 value_of_this. */
cba0d141
JG
107
108const struct block *block_found;
bd5635a1
RP
109
110char no_symtab_msg[] = "No symbol table is loaded. Use the \"file\" command.";
111
f70be3e4
JG
112/* While the C++ support is still in flux, issue a possibly helpful hint on
113 using the new command completion feature on single quoted demangled C++
114 symbols. Remove when loose ends are cleaned up. FIXME -fnf */
115
b607efe7 116static void
f70be3e4
JG
117cplusplus_hint (name)
118 char *name;
119{
9b041f69
PS
120 while (*name == '\'')
121 name++;
1c95d7ab
JK
122 printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name, name);
123 printf_filtered ("(Note leading single quote.)\n");
f70be3e4
JG
124}
125
bd5635a1
RP
126/* Check for a symtab of a specific name; first in symtabs, then in
127 psymtabs. *If* there is no '/' in the name, a match after a '/'
128 in the symtab filename will also work. */
129
130static struct symtab *
131lookup_symtab_1 (name)
132 char *name;
133{
134 register struct symtab *s;
135 register struct partial_symtab *ps;
35a25840 136 register char *slash;
cba0d141 137 register struct objfile *objfile;
bd5635a1 138
784fd92b 139 got_symtab:
35a25840 140
784fd92b
SG
141 /* First, search for an exact match */
142
143 ALL_SYMTABS (objfile, s)
2e4964ad 144 if (STREQ (name, s->filename))
784fd92b 145 return s;
35a25840
SG
146
147 slash = strchr (name, '/');
784fd92b
SG
148
149 /* Now, search for a matching tail (only if name doesn't have any dirs) */
35a25840 150
bd5635a1 151 if (!slash)
784fd92b
SG
152 ALL_SYMTABS (objfile, s)
153 {
154 char *p = s -> filename;
155 char *tail = strrchr (p, '/');
156
157 if (tail)
158 p = tail + 1;
159
2e4964ad 160 if (STREQ (p, name))
784fd92b
SG
161 return s;
162 }
163
164 /* Same search rules as above apply here, but now we look thru the
165 psymtabs. */
166
ad0a2521
JK
167 ps = lookup_partial_symtab (name);
168 if (!ps)
169 return (NULL);
784fd92b
SG
170
171 if (ps -> readin)
35fcebce
PB
172 error ("Internal: readin %s pst for `%s' found when no symtab found.",
173 ps -> filename, name);
784fd92b
SG
174
175 s = PSYMTAB_TO_SYMTAB (ps);
176
177 if (s)
178 return s;
179
180 /* At this point, we have located the psymtab for this file, but
181 the conversion to a symtab has failed. This usually happens
182 when we are looking up an include file. In this case,
183 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
184 been created. So, we need to run through the symtabs again in
185 order to find the file.
186 XXX - This is a crock, and should be fixed inside of the the
187 symbol parsing routines. */
188 goto got_symtab;
bd5635a1
RP
189}
190
191/* Lookup the symbol table of a source file named NAME. Try a couple
192 of variations if the first lookup doesn't work. */
193
194struct symtab *
195lookup_symtab (name)
196 char *name;
197{
198 register struct symtab *s;
1c95d7ab 199#if 0
bd5635a1 200 register char *copy;
1c95d7ab 201#endif
bd5635a1
RP
202
203 s = lookup_symtab_1 (name);
204 if (s) return s;
205
d8a66e60
JK
206#if 0
207 /* This screws c-exp.y:yylex if there is both a type "tree" and a symtab
208 "tree.c". */
209
bd5635a1 210 /* If name not found as specified, see if adding ".c" helps. */
ad0a2521
JK
211 /* Why is this? Is it just a user convenience? (If so, it's pretty
212 questionable in the presence of C++, FORTRAN, etc.). It's not in
213 the GDB manual. */
bd5635a1
RP
214
215 copy = (char *) alloca (strlen (name) + 3);
216 strcpy (copy, name);
217 strcat (copy, ".c");
218 s = lookup_symtab_1 (copy);
219 if (s) return s;
d8a66e60 220#endif /* 0 */
bd5635a1
RP
221
222 /* We didn't find anything; die. */
223 return 0;
224}
225
ad0a2521
JK
226/* Lookup the partial symbol table of a source file named NAME.
227 *If* there is no '/' in the name, a match after a '/'
228 in the psymtab filename will also work. */
bd5635a1
RP
229
230struct partial_symtab *
231lookup_partial_symtab (name)
232char *name;
233{
cba0d141
JG
234 register struct partial_symtab *pst;
235 register struct objfile *objfile;
bd5635a1 236
35a25840 237 ALL_PSYMTABS (objfile, pst)
bd5635a1 238 {
2e4964ad 239 if (STREQ (name, pst -> filename))
bd5635a1 240 {
35a25840 241 return (pst);
bd5635a1 242 }
35a25840 243 }
ad0a2521
JK
244
245 /* Now, search for a matching tail (only if name doesn't have any dirs) */
246
247 if (!strchr (name, '/'))
248 ALL_PSYMTABS (objfile, pst)
249 {
250 char *p = pst -> filename;
251 char *tail = strrchr (p, '/');
252
253 if (tail)
254 p = tail + 1;
255
256 if (STREQ (p, name))
257 return (pst);
258 }
259
cba0d141 260 return (NULL);
bd5635a1 261}
cba0d141 262\f
7f6cb62e
KS
263/* Mangle a GDB method stub type. This actually reassembles the pieces of the
264 full method name, which consist of the class name (from T), the unadorned
265 method name from METHOD_ID, and the signature for the specific overload,
266 specified by SIGNATURE_ID. Note that this function is g++ specific. */
0b28c260 267
bd5635a1 268char *
7f6cb62e 269gdb_mangle_name (type, method_id, signature_id)
bd5635a1 270 struct type *type;
7f6cb62e 271 int method_id, signature_id;
bd5635a1 272{
bcccec8c
PB
273 int mangled_name_len;
274 char *mangled_name;
7f6cb62e
KS
275 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
276 struct fn_field *method = &f[signature_id];
277 char *field_name = TYPE_FN_FIELDLIST_NAME (type, method_id);
278 char *physname = TYPE_FN_FIELD_PHYSNAME (f, signature_id);
35fcebce 279 char *newname = type_name_no_tag (type);
d47a7f52
JK
280
281 /* Does the form of physname indicate that it is the full mangled name
282 of a constructor (not just the args)? */
283 int is_full_physname_constructor;
284
ad0a2521 285 int is_constructor;
2d575e6f 286 int is_destructor = DESTRUCTOR_PREFIX_P (physname);
bcccec8c 287 /* Need a new type prefix. */
bcccec8c
PB
288 char *const_prefix = method->is_const ? "C" : "";
289 char *volatile_prefix = method->is_volatile ? "V" : "";
bcccec8c 290 char buf[20];
ad0a2521 291 int len = (newname == NULL ? 0 : strlen (newname));
ad0a2521 292
d47a7f52
JK
293 is_full_physname_constructor =
294 ((physname[0]=='_' && physname[1]=='_' &&
295 (isdigit(physname[2]) || physname[2]=='Q' || physname[2]=='t'))
296 || (strncmp(physname, "__ct", 4) == 0));
297
298 is_constructor =
299 is_full_physname_constructor || (newname && STREQ(field_name, newname));
300
ad0a2521
JK
301 if (!is_destructor)
302 is_destructor = (strncmp(physname, "__dt", 4) == 0);
35fcebce 303
d47a7f52 304 if (is_destructor || is_full_physname_constructor)
35fcebce
PB
305 {
306 mangled_name = (char*) xmalloc(strlen(physname)+1);
307 strcpy(mangled_name, physname);
308 return mangled_name;
309 }
310
ad0a2521
JK
311 if (len == 0)
312 {
313 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
ad0a2521 314 }
27f1958c 315 else if (physname[0] == 't' || physname[0] == 'Q')
76212295 316 {
27f1958c
PS
317 /* The physname for template and qualified methods already includes
318 the class name. */
76212295
PS
319 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
320 newname = NULL;
321 len = 0;
322 }
ad0a2521
JK
323 else
324 {
325 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
326 }
35fcebce
PB
327 mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
328 + strlen (buf) + len
329 + strlen (physname)
330 + 1);
331
332 /* Only needed for GNU-mangled names. ANSI-mangled names
333 work with the normal mechanisms. */
334 if (OPNAME_PREFIX_P (field_name))
335 {
b607efe7 336 const char *opname = cplus_mangle_opname (field_name + 3, 0);
35fcebce
PB
337 if (opname == NULL)
338 error ("No mangling for \"%s\"", field_name);
339 mangled_name_len += strlen (opname);
340 mangled_name = (char *)xmalloc (mangled_name_len);
341
342 strncpy (mangled_name, field_name, 3);
343 mangled_name[3] = '\0';
344 strcat (mangled_name, opname);
345 }
346 else
347 {
348 mangled_name = (char *)xmalloc (mangled_name_len);
349 if (is_constructor)
350 mangled_name[0] = '\0';
351 else
352 strcpy (mangled_name, field_name);
353 }
354 strcat (mangled_name, buf);
018ab14f
PS
355 /* If the class doesn't have a name, i.e. newname NULL, then we just
356 mangle it using 0 for the length of the class. Thus it gets mangled
2d575e6f 357 as something starting with `::' rather than `classname::'. */
018ab14f
PS
358 if (newname != NULL)
359 strcat (mangled_name, newname);
2d575e6f 360
35fcebce 361 strcat (mangled_name, physname);
8050a57b 362 return (mangled_name);
bd5635a1
RP
363}
364
cba0d141 365\f
211b564e 366
211b564e 367/* Find which partial symtab on contains PC and SECTION. Return 0 if none. */
f1d77e90 368
cba0d141 369struct partial_symtab *
211b564e
PS
370find_pc_sect_psymtab (pc, section)
371 CORE_ADDR pc;
372 asection *section;
d96b54ea 373{
cba0d141
JG
374 register struct partial_symtab *pst;
375 register struct objfile *objfile;
d96b54ea 376
35a25840 377 ALL_PSYMTABS (objfile, pst)
bd5635a1 378 {
c1878f87 379 if (pc >= pst->textlow && pc < pst->texthigh)
76212295
PS
380 {
381 struct minimal_symbol *msymbol;
382 struct partial_symtab *tpst;
383
384 /* An objfile that has its functions reordered might have
385 many partial symbol tables containing the PC, but
386 we want the partial symbol table that contains the
387 function containing the PC. */
211b564e
PS
388 if (!(objfile->flags & OBJF_REORDERED) &&
389 section == 0) /* can't validate section this way */
76212295
PS
390 return (pst);
391
211b564e 392 msymbol = lookup_minimal_symbol_by_pc_section (pc, section);
76212295
PS
393 if (msymbol == NULL)
394 return (pst);
395
396 for (tpst = pst; tpst != NULL; tpst = tpst->next)
397 {
398 if (pc >= tpst->textlow && pc < tpst->texthigh)
399 {
400 struct partial_symbol *p;
401
211b564e 402 p = find_pc_sect_psymbol (tpst, pc, section);
76212295
PS
403 if (p != NULL
404 && SYMBOL_VALUE_ADDRESS(p)
405 == SYMBOL_VALUE_ADDRESS (msymbol))
406 return (tpst);
407 }
408 }
409 return (pst);
410 }
bd5635a1 411 }
cba0d141 412 return (NULL);
bd5635a1
RP
413}
414
211b564e
PS
415/* Find which partial symtab contains PC. Return 0 if none.
416 Backward compatibility, no section */
417
418struct partial_symtab *
419find_pc_psymtab (pc)
420 CORE_ADDR pc;
421{
422 return find_pc_sect_psymtab (pc, find_pc_mapped_section (pc));
423}
424
425/* Find which partial symbol within a psymtab matches PC and SECTION.
426 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
427
bd5635a1 428struct partial_symbol *
211b564e 429find_pc_sect_psymbol (psymtab, pc, section)
bd5635a1
RP
430 struct partial_symtab *psymtab;
431 CORE_ADDR pc;
211b564e 432 asection *section;
bd5635a1 433{
b607efe7 434 struct partial_symbol *best = NULL, *p, **pp;
bd5635a1
RP
435 CORE_ADDR best_pc;
436
437 if (!psymtab)
211b564e 438 psymtab = find_pc_sect_psymtab (pc, section);
bd5635a1
RP
439 if (!psymtab)
440 return 0;
441
442 best_pc = psymtab->textlow - 1;
443
d8a66e60
JK
444 /* Search the global symbols as well as the static symbols, so that
445 find_pc_partial_function doesn't use a minimal symbol and thus
446 cache a bad endaddr. */
b607efe7
FF
447 for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
448 (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
d8a66e60 449 < psymtab->n_global_syms);
b607efe7
FF
450 pp++)
451 {
452 p = *pp;
453 if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
454 && SYMBOL_CLASS (p) == LOC_BLOCK
455 && pc >= SYMBOL_VALUE_ADDRESS (p)
456 && SYMBOL_VALUE_ADDRESS (p) > best_pc)
457 {
211b564e
PS
458 if (section) /* match on a specific section */
459 {
460 fixup_psymbol_section (p, psymtab->objfile);
461 if (SYMBOL_BFD_SECTION (p) != section)
462 continue;
463 }
b607efe7
FF
464 best_pc = SYMBOL_VALUE_ADDRESS (p);
465 best = p;
466 }
467 }
468 for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
469 (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
bd5635a1 470 < psymtab->n_static_syms);
b607efe7
FF
471 pp++)
472 {
473 p = *pp;
474 if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
475 && SYMBOL_CLASS (p) == LOC_BLOCK
476 && pc >= SYMBOL_VALUE_ADDRESS (p)
477 && SYMBOL_VALUE_ADDRESS (p) > best_pc)
478 {
211b564e
PS
479 if (section) /* match on a specific section */
480 {
481 fixup_psymbol_section (p, psymtab->objfile);
482 if (SYMBOL_BFD_SECTION (p) != section)
483 continue;
484 }
b607efe7
FF
485 best_pc = SYMBOL_VALUE_ADDRESS (p);
486 best = p;
487 }
488 }
bd5635a1
RP
489 if (best_pc == psymtab->textlow - 1)
490 return 0;
491 return best;
492}
493
211b564e
PS
494/* Find which partial symbol within a psymtab matches PC. Return 0 if none.
495 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
496
497struct partial_symbol *
498find_pc_psymbol (psymtab, pc)
499 struct partial_symtab *psymtab;
500 CORE_ADDR pc;
501{
502 return find_pc_sect_psymbol (psymtab, pc, find_pc_mapped_section (pc));
503}
504\f
4c681116
SG
505/* Debug symbols usually don't have section information. We need to dig that
506 out of the minimal symbols and stash that in the debug symbol. */
507
211b564e
PS
508static void
509fixup_section (ginfo, objfile)
510 struct general_symbol_info *ginfo;
511 struct objfile *objfile;
512{
513 struct minimal_symbol *msym;
514 msym = lookup_minimal_symbol (ginfo->name, NULL, objfile);
515
516 if (msym)
517 ginfo->bfd_section = SYMBOL_BFD_SECTION (msym);
518}
519
520struct symbol *
4c681116
SG
521fixup_symbol_section (sym, objfile)
522 struct symbol *sym;
523 struct objfile *objfile;
524{
07422705
PS
525 if (!sym)
526 return NULL;
527
4c681116
SG
528 if (SYMBOL_BFD_SECTION (sym))
529 return sym;
530
211b564e 531 fixup_section (&sym->ginfo, objfile);
4c681116
SG
532
533 return sym;
534}
535
79f15b12 536static struct partial_symbol *
211b564e
PS
537fixup_psymbol_section (psym, objfile)
538 struct partial_symbol *psym;
539 struct objfile *objfile;
540{
211b564e
PS
541 if (!psym)
542 return NULL;
543
544 if (SYMBOL_BFD_SECTION (psym))
545 return psym;
546
547 fixup_section (&psym->ginfo, objfile);
548
549 return psym;
550}
551
bd5635a1
RP
552/* Find the definition for a specified symbol name NAME
553 in namespace NAMESPACE, visible from lexical block BLOCK.
554 Returns the struct symbol pointer, or zero if no symbol is found.
555 If SYMTAB is non-NULL, store the symbol table in which the
556 symbol was found there, or NULL if not found.
557 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
558 NAME is a field of the current implied argument `this'. If so set
559 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
560 BLOCK_FOUND is set to the block in which NAME is found (in the case of
561 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
562
87041845
JK
563/* This function has a bunch of loops in it and it would seem to be
564 attractive to put in some QUIT's (though I'm not really sure
565 whether it can run long enough to be really important). But there
566 are a few calls for which it would appear to be bad news to quit
567 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and
568 nindy_frame_chain_valid in nindy-tdep.c. (Note that there is C++
569 code below which can error(), but that probably doesn't affect
570 these calls since they are looking for a known variable and thus
571 can probably assume it will never hit the C++ code). */
572
bd5635a1
RP
573struct symbol *
574lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
cba0d141
JG
575 const char *name;
576 register const struct block *block;
1750a5ef 577 const namespace_enum namespace;
bd5635a1
RP
578 int *is_a_field_of_this;
579 struct symtab **symtab;
580{
581 register struct symbol *sym;
01d3fdba 582 register struct symtab *s = NULL;
bd5635a1
RP
583 register struct partial_symtab *ps;
584 struct blockvector *bv;
4c681116 585 register struct objfile *objfile = NULL;
cba0d141 586 register struct block *b;
cba0d141 587 register struct minimal_symbol *msymbol;
f70be3e4 588
bd5635a1
RP
589 /* Search specified block and its superiors. */
590
591 while (block != 0)
592 {
593 sym = lookup_block_symbol (block, name, namespace);
594 if (sym)
595 {
596 block_found = block;
597 if (symtab != NULL)
598 {
599 /* Search the list of symtabs for one which contains the
600 address of the start of this block. */
35a25840 601 ALL_SYMTABS (objfile, s)
bd5635a1 602 {
35a25840
SG
603 bv = BLOCKVECTOR (s);
604 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
605 if (BLOCK_START (b) <= BLOCK_START (block)
606 && BLOCK_END (b) > BLOCK_START (block))
607 goto found;
bd5635a1 608 }
35a25840 609found:
bd5635a1
RP
610 *symtab = s;
611 }
612
4c681116 613 return fixup_symbol_section (sym, objfile);
bd5635a1
RP
614 }
615 block = BLOCK_SUPERBLOCK (block);
616 }
617
0b28c260
JK
618 /* FIXME: this code is never executed--block is always NULL at this
619 point. What is it trying to do, anyway? We already should have
620 checked the STATIC_BLOCK above (it is the superblock of top-level
621 blocks). Why is VAR_NAMESPACE special-cased? */
2e4964ad 622 /* Don't need to mess with the psymtabs; if we have a block,
b039ac3a
JK
623 that file is read in. If we don't, then we deal later with
624 all the psymtab stuff that needs checking. */
625 if (namespace == VAR_NAMESPACE && block != NULL)
626 {
627 struct block *b;
628 /* Find the right symtab. */
35a25840 629 ALL_SYMTABS (objfile, s)
b039ac3a 630 {
35a25840
SG
631 bv = BLOCKVECTOR (s);
632 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
633 if (BLOCK_START (b) <= BLOCK_START (block)
634 && BLOCK_END (b) > BLOCK_START (block))
b039ac3a 635 {
2e4964ad 636 sym = lookup_block_symbol (b, name, VAR_NAMESPACE);
35a25840 637 if (sym)
b039ac3a 638 {
35a25840
SG
639 block_found = b;
640 if (symtab != NULL)
641 *symtab = s;
4c681116 642 return fixup_symbol_section (sym, objfile);
b039ac3a
JK
643 }
644 }
645 }
646 }
647
648
bd5635a1
RP
649 /* C++: If requested to do so by the caller,
650 check to see if NAME is a field of `this'. */
651 if (is_a_field_of_this)
652 {
653 struct value *v = value_of_this (0);
654
655 *is_a_field_of_this = 0;
656 if (v && check_field (v, name))
657 {
658 *is_a_field_of_this = 1;
659 if (symtab != NULL)
660 *symtab = NULL;
4c681116 661 return NULL;
bd5635a1
RP
662 }
663 }
664
665 /* Now search all global blocks. Do the symtab's first, then
666 check the psymtab's */
cba0d141 667
35a25840 668 ALL_SYMTABS (objfile, s)
bd5635a1 669 {
35a25840
SG
670 bv = BLOCKVECTOR (s);
671 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
672 sym = lookup_block_symbol (block, name, namespace);
673 if (sym)
bd5635a1 674 {
35a25840
SG
675 block_found = block;
676 if (symtab != NULL)
677 *symtab = s;
4c681116 678 return fixup_symbol_section (sym, objfile);
bd5635a1
RP
679 }
680 }
681
76212295
PS
682 /* Check for the possibility of the symbol being a function or
683 a mangled variable that is stored in one of the minimal symbol tables.
684 Eventually, all global symbols might be resolved in this way. */
bd5635a1
RP
685
686 if (namespace == VAR_NAMESPACE)
687 {
2b576293 688 msymbol = lookup_minimal_symbol (name, NULL, NULL);
f70be3e4 689 if (msymbol != NULL)
bd5635a1 690 {
211b564e
PS
691 s = find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol),
692 SYMBOL_BFD_SECTION (msymbol));
318bf84f 693 if (s != NULL)
bd5635a1 694 {
76212295 695 /* This is a function which has a symtab for its address. */
bd5635a1 696 bv = BLOCKVECTOR (s);
3ba6a043 697 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
2e4964ad
FF
698 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
699 namespace);
318bf84f 700 /* We kept static functions in minimal symbol table as well as
818de002 701 in static scope. We want to find them in the symbol table. */
818de002
PB
702 if (!sym) {
703 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
2e4964ad 704 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
318bf84f 705 namespace);
818de002 706 }
818de002 707
cba0d141 708 /* sym == 0 if symbol was found in the minimal symbol table
bd5635a1 709 but not in the symtab.
cba0d141 710 Return 0 to use the msymbol definition of "foo_".
bd5635a1
RP
711
712 This happens for Fortran "foo_" symbols,
713 which are "foo" in the symtab.
714
715 This can also happen if "asm" is used to make a
716 regular symbol but not a debugging symbol, e.g.
717 asm(".globl _main");
718 asm("_main:");
719 */
720
721 if (symtab != NULL)
722 *symtab = s;
4c681116 723 return fixup_symbol_section (sym, objfile);
bd5635a1 724 }
76212295
PS
725 else if (MSYMBOL_TYPE (msymbol) != mst_text
726 && MSYMBOL_TYPE (msymbol) != mst_file_text
727 && !STREQ (name, SYMBOL_NAME (msymbol)))
728 {
729 /* This is a mangled variable, look it up by its
730 mangled name. */
211b564e
PS
731 return lookup_symbol (SYMBOL_NAME (msymbol), block,
732 namespace, is_a_field_of_this, symtab);
76212295
PS
733 }
734 /* There are no debug symbols for this file, or we are looking
735 for an unmangled variable.
736 Try to find a matching static symbol below. */
bd5635a1
RP
737 }
738 }
739
35a25840 740 ALL_PSYMTABS (objfile, ps)
cba0d141 741 {
35a25840 742 if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
cba0d141 743 {
35a25840
SG
744 s = PSYMTAB_TO_SYMTAB(ps);
745 bv = BLOCKVECTOR (s);
746 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
747 sym = lookup_block_symbol (block, name, namespace);
748 if (!sym)
35fcebce 749 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);
35a25840
SG
750 if (symtab != NULL)
751 *symtab = s;
4c681116 752 return fixup_symbol_section (sym, objfile);
cba0d141
JG
753 }
754 }
bd5635a1
RP
755
756 /* Now search all per-file blocks.
757 Not strictly correct, but more useful than an error.
758 Do the symtabs first, then check the psymtabs */
759
35a25840 760 ALL_SYMTABS (objfile, s)
bd5635a1 761 {
35a25840
SG
762 bv = BLOCKVECTOR (s);
763 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
764 sym = lookup_block_symbol (block, name, namespace);
765 if (sym)
bd5635a1 766 {
35a25840
SG
767 block_found = block;
768 if (symtab != NULL)
769 *symtab = s;
4c681116 770 return fixup_symbol_section (sym, objfile);
35a25840
SG
771 }
772 }
773
774 ALL_PSYMTABS (objfile, ps)
775 {
776 if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
777 {
778 s = PSYMTAB_TO_SYMTAB(ps);
cba0d141
JG
779 bv = BLOCKVECTOR (s);
780 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
781 sym = lookup_block_symbol (block, name, namespace);
35a25840 782 if (!sym)
35fcebce 783 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);
35a25840
SG
784 if (symtab != NULL)
785 *symtab = s;
4c681116 786 return fixup_symbol_section (sym, objfile);
35a25840
SG
787 }
788 }
789
bd5635a1
RP
790 if (symtab != NULL)
791 *symtab = NULL;
792 return 0;
793}
794
795/* Look, in partial_symtab PST, for symbol NAME. Check the global
796 symbols if GLOBAL, the static symbols if not */
797
798static struct partial_symbol *
799lookup_partial_symbol (pst, name, global, namespace)
800 struct partial_symtab *pst;
cba0d141 801 const char *name;
bd5635a1 802 int global;
1750a5ef 803 namespace_enum namespace;
bd5635a1 804{
b607efe7
FF
805 struct partial_symbol **start, **psym;
806 struct partial_symbol **top, **bottom, **center;
bd5635a1 807 int length = (global ? pst->n_global_syms : pst->n_static_syms);
2e4964ad 808 int do_linear_search = 1;
bd5635a1 809
2e4964ad
FF
810 if (length == 0)
811 {
812 return (NULL);
813 }
bd5635a1
RP
814
815 start = (global ?
cba0d141
JG
816 pst->objfile->global_psymbols.list + pst->globals_offset :
817 pst->objfile->static_psymbols.list + pst->statics_offset );
bd5635a1 818
2e4964ad 819 if (global) /* This means we can use a binary search. */
bd5635a1 820 {
2e4964ad 821 do_linear_search = 0;
bd5635a1
RP
822
823 /* Binary search. This search is guaranteed to end with center
824 pointing at the earliest partial symbol with the correct
825 name. At that point *all* partial symbols with that name
826 will be checked against the correct namespace. */
2e4964ad 827
bd5635a1
RP
828 bottom = start;
829 top = start + length - 1;
830 while (top > bottom)
831 {
832 center = bottom + (top - bottom) / 2;
76212295
PS
833 if (!(center < top))
834 abort ();
7f6cb62e
KS
835 if (!do_linear_search
836 && (SYMBOL_LANGUAGE (*center) == language_cplus
837/* start-sanitize-java */
838 || SYMBOL_LANGUAGE (*center) == language_java
839/* end-sanitize-java */
840 ))
2e4964ad
FF
841 {
842 do_linear_search = 1;
843 }
b607efe7 844 if (STRCMP (SYMBOL_NAME (*center), name) >= 0)
2e4964ad
FF
845 {
846 top = center;
847 }
bd5635a1 848 else
2e4964ad
FF
849 {
850 bottom = center + 1;
851 }
bd5635a1 852 }
76212295
PS
853 if (!(top == bottom))
854 abort ();
b607efe7 855 while (STREQ (SYMBOL_NAME (*top), name))
bd5635a1 856 {
b607efe7 857 if (SYMBOL_NAMESPACE (*top) == namespace)
2e4964ad 858 {
b607efe7 859 return (*top);
2e4964ad 860 }
bd5635a1
RP
861 top ++;
862 }
863 }
2e4964ad
FF
864
865 /* Can't use a binary search or else we found during the binary search that
866 we should also do a linear search. */
867
868 if (do_linear_search)
bd5635a1 869 {
bd5635a1 870 for (psym = start; psym < start + length; psym++)
2e4964ad 871 {
b607efe7 872 if (namespace == SYMBOL_NAMESPACE (*psym))
2e4964ad 873 {
b607efe7 874 if (SYMBOL_MATCHES_NAME (*psym, name))
2e4964ad 875 {
b607efe7 876 return (*psym);
2e4964ad
FF
877 }
878 }
879 }
bd5635a1
RP
880 }
881
2e4964ad 882 return (NULL);
bd5635a1
RP
883}
884
0e2a896c 885/* Find the psymtab containing main(). */
c1878f87
SG
886/* FIXME: What about languages without main() or specially linked
887 executables that have no main() ? */
0e2a896c
PB
888
889struct partial_symtab *
890find_main_psymtab ()
891{
892 register struct partial_symtab *pst;
cba0d141
JG
893 register struct objfile *objfile;
894
35a25840 895 ALL_PSYMTABS (objfile, pst)
cba0d141 896 {
35a25840 897 if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE))
cba0d141 898 {
35a25840 899 return (pst);
cba0d141
JG
900 }
901 }
902 return (NULL);
0e2a896c
PB
903}
904
2e4964ad
FF
905/* Search BLOCK for symbol NAME in NAMESPACE.
906
907 Note that if NAME is the demangled form of a C++ symbol, we will fail
908 to find a match during the binary search of the non-encoded names, but
909 for now we don't worry about the slight inefficiency of looking for
910 a match we'll never find, since it will go pretty quick. Once the
911 binary search terminates, we drop through and do a straight linear
912 search on the symbols. Each symbol which is marked as being a C++
913 symbol (language_cplus set) has both the encoded and non-encoded names
914 tested for a match. */
bd5635a1
RP
915
916struct symbol *
917lookup_block_symbol (block, name, namespace)
cba0d141
JG
918 register const struct block *block;
919 const char *name;
1750a5ef 920 const namespace_enum namespace;
bd5635a1
RP
921{
922 register int bot, top, inc;
2e4964ad
FF
923 register struct symbol *sym;
924 register struct symbol *sym_found = NULL;
925 register int do_linear_search = 1;
bd5635a1
RP
926
927 /* If the blocks's symbols were sorted, start with a binary search. */
928
929 if (BLOCK_SHOULD_SORT (block))
930 {
2e4964ad
FF
931 /* Reset the linear search flag so if the binary search fails, we
932 won't do the linear search once unless we find some reason to
933 do so, such as finding a C++ symbol during the binary search.
934 Note that for C++ modules, ALL the symbols in a block should
935 end up marked as C++ symbols. */
936
937 do_linear_search = 0;
938 top = BLOCK_NSYMS (block);
939 bot = 0;
940
941 /* Advance BOT to not far before the first symbol whose name is NAME. */
bd5635a1
RP
942
943 while (1)
944 {
945 inc = (top - bot + 1);
946 /* No need to keep binary searching for the last few bits worth. */
947 if (inc < 4)
2e4964ad
FF
948 {
949 break;
950 }
bd5635a1
RP
951 inc = (inc >> 1) + bot;
952 sym = BLOCK_SYM (block, inc);
7f6cb62e
KS
953 if (!do_linear_search
954 && (SYMBOL_LANGUAGE (sym) == language_cplus
955/* start-sanitize-java */
956 || SYMBOL_LANGUAGE (sym) == language_java
957/* end-sanitize-java */
958 ))
2e4964ad
FF
959 {
960 do_linear_search = 1;
961 }
bd5635a1 962 if (SYMBOL_NAME (sym)[0] < name[0])
2e4964ad
FF
963 {
964 bot = inc;
965 }
bd5635a1 966 else if (SYMBOL_NAME (sym)[0] > name[0])
2e4964ad
FF
967 {
968 top = inc;
969 }
970 else if (STRCMP (SYMBOL_NAME (sym), name) < 0)
971 {
972 bot = inc;
973 }
bd5635a1 974 else
2e4964ad
FF
975 {
976 top = inc;
977 }
bd5635a1
RP
978 }
979
f1ed4330
JK
980 /* Now scan forward until we run out of symbols, find one whose
981 name is greater than NAME, or find one we want. If there is
982 more than one symbol with the right name and namespace, we
983 return the first one; I believe it is now impossible for us
984 to encounter two symbols with the same name and namespace
985 here, because blocks containing argument symbols are no
986 longer sorted. */
bd5635a1
RP
987
988 top = BLOCK_NSYMS (block);
989 while (bot < top)
990 {
991 sym = BLOCK_SYM (block, bot);
992 inc = SYMBOL_NAME (sym)[0] - name[0];
993 if (inc == 0)
2e4964ad
FF
994 {
995 inc = STRCMP (SYMBOL_NAME (sym), name);
996 }
bd5635a1 997 if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
2e4964ad
FF
998 {
999 return (sym);
1000 }
bd5635a1 1001 if (inc > 0)
2e4964ad
FF
1002 {
1003 break;
1004 }
bd5635a1
RP
1005 bot++;
1006 }
bd5635a1
RP
1007 }
1008
2e4964ad
FF
1009 /* Here if block isn't sorted, or we fail to find a match during the
1010 binary search above. If during the binary search above, we find a
1011 symbol which is a C++ symbol, then we have re-enabled the linear
1012 search flag which was reset when starting the binary search.
1013
1014 This loop is equivalent to the loop above, but hacked greatly for speed.
bd5635a1
RP
1015
1016 Note that parameter symbols do not always show up last in the
1017 list; this loop makes sure to take anything else other than
1018 parameter symbols first; it only uses parameter symbols as a
1019 last resort. Note that this only takes up extra computation
1020 time on a match. */
1021
2e4964ad 1022 if (do_linear_search)
bd5635a1 1023 {
2e4964ad
FF
1024 top = BLOCK_NSYMS (block);
1025 bot = 0;
1026 while (bot < top)
bd5635a1 1027 {
2e4964ad
FF
1028 sym = BLOCK_SYM (block, bot);
1029 if (SYMBOL_NAMESPACE (sym) == namespace &&
1030 SYMBOL_MATCHES_NAME (sym, name))
1031 {
a259afcc
JL
1032 /* If SYM has aliases, then use any alias that is active
1033 at the current PC. If no alias is active at the current
1034 PC, then use the main symbol.
1035
1036 ?!? Is checking the current pc correct? Is this routine
1037 ever called to look up a symbol from another context? */
d719efc6 1038 if (SYMBOL_ALIASES (sym))
e21fb2ae 1039 sym = find_active_alias (sym, read_pc ());
d719efc6 1040
2e4964ad
FF
1041 sym_found = sym;
1042 if (SYMBOL_CLASS (sym) != LOC_ARG &&
1043 SYMBOL_CLASS (sym) != LOC_LOCAL_ARG &&
1044 SYMBOL_CLASS (sym) != LOC_REF_ARG &&
f1ed4330 1045 SYMBOL_CLASS (sym) != LOC_REGPARM &&
a1c8d76e
JK
1046 SYMBOL_CLASS (sym) != LOC_REGPARM_ADDR &&
1047 SYMBOL_CLASS (sym) != LOC_BASEREG_ARG)
2e4964ad
FF
1048 {
1049 break;
1050 }
1051 }
1052 bot++;
bd5635a1 1053 }
bd5635a1 1054 }
2e4964ad 1055 return (sym_found); /* Will be NULL if not found. */
bd5635a1 1056}
2e4964ad 1057
e21fb2ae
MS
1058/* Given a main symbol SYM and ADDR, search through the alias
1059 list to determine if an alias is active at ADDR and return
1060 the active alias.
1061
1062 If no alias is active, then return SYM. */
1063
1064static struct symbol *
1065find_active_alias (sym, addr)
1066 struct symbol *sym;
1067 CORE_ADDR addr;
1068{
1069 struct range_list *r;
1070 struct alias_list *aliases;
1071
1072 /* If we have aliases, check them first. */
1073 aliases = SYMBOL_ALIASES (sym);
1074
1075 while (aliases)
1076 {
1077 if (!SYMBOL_RANGES (aliases->sym))
1078 return aliases->sym;
1079 for (r = SYMBOL_RANGES (aliases->sym); r; r = r->next)
1080 {
1081 if (r->start <= addr && r->end > addr)
1082 return aliases->sym;
1083 }
1084 aliases = aliases->next;
1085 }
1086
1087 /* Nothing found, return the main symbol. */
1088 return sym;
1089}
1090
bd5635a1
RP
1091\f
1092/* Return the symbol for the function which contains a specified
1093 lexical block, described by a struct block BL. */
1094
1095struct symbol *
1096block_function (bl)
1097 struct block *bl;
1098{
1099 while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
1100 bl = BLOCK_SUPERBLOCK (bl);
1101
1102 return BLOCK_FUNCTION (bl);
1103}
1104
211b564e
PS
1105/* Find the symtab associated with PC and SECTION. Look through the
1106 psymtabs and read in another symtab if necessary. */
bd5635a1
RP
1107
1108struct symtab *
211b564e
PS
1109find_pc_sect_symtab (pc, section)
1110 CORE_ADDR pc;
1111 asection *section;
bd5635a1
RP
1112{
1113 register struct block *b;
1114 struct blockvector *bv;
45a655b0 1115 register struct symtab *s = NULL;
ca6a826d 1116 register struct symtab *best_s = NULL;
bd5635a1 1117 register struct partial_symtab *ps;
cba0d141 1118 register struct objfile *objfile;
40b647e9 1119 CORE_ADDR distance = 0;
bd5635a1 1120
018ab14f
PS
1121 /* Search all symtabs for the one whose file contains our address, and which
1122 is the smallest of all the ones containing the address. This is designed
1123 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1124 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1125 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
76212295
PS
1126
1127 This happens for native ecoff format, where code from included files
1128 gets its own symtab. The symtab for the included file should have
1129 been read in already via the dependency mechanism.
1130 It might be swifter to create several symtabs with the same name
1131 like xcoff does (I'm not sure).
1132
1133 It also happens for objfiles that have their functions reordered.
1134 For these, the symtab we are looking for is not necessarily read in. */
bd5635a1 1135
35a25840 1136 ALL_SYMTABS (objfile, s)
bd5635a1 1137 {
35a25840
SG
1138 bv = BLOCKVECTOR (s);
1139 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1140 if (BLOCK_START (b) <= pc
ca6a826d
PS
1141 && BLOCK_END (b) > pc
1142 && (distance == 0
1143 || BLOCK_END (b) - BLOCK_START (b) < distance))
1144 {
76212295
PS
1145 /* For an objfile that has its functions reordered,
1146 find_pc_psymtab will find the proper partial symbol table
1147 and we simply return its corresponding symtab. */
211b564e
PS
1148 /* In order to better support objfiles that contain both
1149 stabs and coff debugging info, we continue on if a psymtab
1150 can't be found. */
b607efe7 1151 if ((objfile->flags & OBJF_REORDERED) && objfile->psymtabs)
76212295 1152 {
211b564e 1153 ps = find_pc_sect_psymtab (pc, section);
76212295 1154 if (ps)
211b564e
PS
1155 return PSYMTAB_TO_SYMTAB (ps);
1156 }
1157 if (section != 0)
1158 {
1159 int i;
1160
1161 for (i = 0; i < b->nsyms; i++)
1162 {
1163 fixup_symbol_section (b->sym[i], objfile);
1164 if (section == SYMBOL_BFD_SECTION (b->sym[i]))
1165 break;
1166 }
1167 if (i >= b->nsyms)
1168 continue; /* no symbol in this symtab matches section */
76212295 1169 }
ca6a826d
PS
1170 distance = BLOCK_END (b) - BLOCK_START (b);
1171 best_s = s;
1172 }
bd5635a1
RP
1173 }
1174
ca6a826d
PS
1175 if (best_s != NULL)
1176 return(best_s);
1177
45a655b0 1178 s = NULL;
211b564e 1179 ps = find_pc_sect_psymtab (pc, section);
c1878f87 1180 if (ps)
bd5635a1 1181 {
c1878f87 1182 if (ps->readin)
ac82e9a5
JK
1183 /* Might want to error() here (in case symtab is corrupt and
1184 will cause a core dump), but maybe we can successfully
1185 continue, so let's not. */
e3d6ec4a 1186 /* FIXME-32x64: assumes pc fits in a long */
ac82e9a5 1187 warning ("\
5573d7d4
JK
1188(Internal error: pc 0x%lx in read in psymtab, but not in symtab.)\n",
1189 (unsigned long) pc);
c1878f87 1190 s = PSYMTAB_TO_SYMTAB (ps);
bd5635a1 1191 }
45a655b0 1192 return (s);
bd5635a1 1193}
211b564e
PS
1194
1195/* Find the symtab associated with PC. Look through the psymtabs and
1196 read in another symtab if necessary. Backward compatibility, no section */
1197
1198struct symtab *
1199find_pc_symtab (pc)
1200 CORE_ADDR pc;
1201{
1202 return find_pc_sect_symtab (pc, find_pc_mapped_section (pc));
1203}
1204
e0ea0fbd 1205\f
a0cf4681
JK
1206#if 0
1207
e0ea0fbd 1208/* Find the closest symbol value (of any sort -- function or variable)
a0cf4681
JK
1209 for a given address value. Slow but complete. (currently unused,
1210 mainly because it is too slow. We could fix it if each symtab and
1211 psymtab had contained in it the addresses ranges of each of its
1212 sections, which also would be required to make things like "info
1213 line *0x2345" cause psymtabs to be converted to symtabs). */
e0ea0fbd
JG
1214
1215struct symbol *
87041845 1216find_addr_symbol (addr, symtabp, symaddrp)
e0ea0fbd 1217 CORE_ADDR addr;
87041845
JK
1218 struct symtab **symtabp;
1219 CORE_ADDR *symaddrp;
e0ea0fbd 1220{
87041845 1221 struct symtab *symtab, *best_symtab;
e0ea0fbd
JG
1222 struct objfile *objfile;
1223 register int bot, top;
1224 register struct symbol *sym;
1225 register CORE_ADDR sym_addr;
1226 struct block *block;
1227 int blocknum;
1228
1229 /* Info on best symbol seen so far */
1230
1231 register CORE_ADDR best_sym_addr = 0;
1232 struct symbol *best_sym = 0;
1233
1234 /* FIXME -- we should pull in all the psymtabs, too! */
1235 ALL_SYMTABS (objfile, symtab)
1236 {
1237 /* Search the global and static blocks in this symtab for
1238 the closest symbol-address to the desired address. */
1239
1240 for (blocknum = GLOBAL_BLOCK; blocknum <= STATIC_BLOCK; blocknum++)
1241 {
1242 QUIT;
1243 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), blocknum);
1244 top = BLOCK_NSYMS (block);
1245 for (bot = 0; bot < top; bot++)
1246 {
1247 sym = BLOCK_SYM (block, bot);
1248 switch (SYMBOL_CLASS (sym))
1249 {
1250 case LOC_STATIC:
1251 case LOC_LABEL:
1252 sym_addr = SYMBOL_VALUE_ADDRESS (sym);
1253 break;
1254
1255 case LOC_BLOCK:
1256 sym_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1257 break;
1258
1259 default:
1260 continue;
1261 }
1262
1263 if (sym_addr <= addr)
1264 if (sym_addr > best_sym_addr)
1265 {
1266 /* Quit if we found an exact match. */
e0ea0fbd
JG
1267 best_sym = sym;
1268 best_sym_addr = sym_addr;
87041845
JK
1269 best_symtab = symtab;
1270 if (sym_addr == addr)
1271 goto done;
e0ea0fbd
JG
1272 }
1273 }
1274 }
1275 }
87041845
JK
1276
1277 done:
1278 if (symtabp)
1279 *symtabp = best_symtab;
1280 if (symaddrp)
1281 *symaddrp = best_sym_addr;
e0ea0fbd
JG
1282 return best_sym;
1283}
a0cf4681 1284#endif /* 0 */
bd5635a1 1285
211b564e 1286/* Find the source file and line number for a given PC value and section.
bd5635a1
RP
1287 Return a structure containing a symtab pointer, a line number,
1288 and a pc range for the entire source line.
1289 The value's .pc field is NOT the specified pc.
1290 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1291 use the line that ends there. Otherwise, in that case, the line
1292 that begins there is used. */
1293
b638ca91
SG
1294/* The big complication here is that a line may start in one file, and end just
1295 before the start of another file. This usually occurs when you #include
1296 code in the middle of a subroutine. To properly find the end of a line's PC
1297 range, we must search all symtabs associated with this compilation unit, and
1298 find the one whose first PC is closer than that of the next line in this
01d3fdba 1299 symtab. */
b638ca91 1300
d34d6f75
JK
1301/* If it's worth the effort, we could be using a binary search. */
1302
bd5635a1 1303struct symtab_and_line
211b564e 1304find_pc_sect_line (pc, section, notcurrent)
bd5635a1 1305 CORE_ADDR pc;
211b564e 1306 struct sec *section;
bd5635a1
RP
1307 int notcurrent;
1308{
1309 struct symtab *s;
1310 register struct linetable *l;
1311 register int len;
1312 register int i;
b638ca91 1313 register struct linetable_entry *item;
bd5635a1
RP
1314 struct symtab_and_line val;
1315 struct blockvector *bv;
1316
1317 /* Info on best line seen so far, and where it starts, and its file. */
1318
b638ca91 1319 struct linetable_entry *best = NULL;
bd5635a1
RP
1320 CORE_ADDR best_end = 0;
1321 struct symtab *best_symtab = 0;
1322
1323 /* Store here the first line number
1324 of a file which contains the line at the smallest pc after PC.
1325 If we don't find a line whose range contains PC,
1326 we will use a line one less than this,
1327 with a range from the start of that file to the first line's pc. */
b638ca91 1328 struct linetable_entry *alt = NULL;
bd5635a1
RP
1329 struct symtab *alt_symtab = 0;
1330
1331 /* Info on best line seen in this file. */
1332
b638ca91 1333 struct linetable_entry *prev;
bd5635a1
RP
1334
1335 /* If this pc is not from the current frame,
1336 it is the address of the end of a call instruction.
1337 Quite likely that is the start of the following statement.
1338 But what we want is the statement containing the instruction.
1339 Fudge the pc to make sure we get that. */
1340
07422705
PS
1341 INIT_SAL (&val); /* initialize to zeroes */
1342
211b564e 1343 if (notcurrent)
07422705 1344 pc -= 1;
bd5635a1 1345
211b564e 1346 s = find_pc_sect_symtab (pc, section);
c1878f87 1347 if (!s)
bd5635a1 1348 {
79f15b12
DE
1349 /* if no symbol information, return previous pc */
1350 if (notcurrent)
1351 pc++;
bd5635a1 1352 val.pc = pc;
bd5635a1
RP
1353 return val;
1354 }
1355
1356 bv = BLOCKVECTOR (s);
1357
1358 /* Look at all the symtabs that share this blockvector.
1359 They all have the same apriori range, that we found was right;
1360 but they have different line tables. */
1361
1362 for (; s && BLOCKVECTOR (s) == bv; s = s->next)
1363 {
1364 /* Find the best line in this symtab. */
1365 l = LINETABLE (s);
4137c5fc
JG
1366 if (!l)
1367 continue;
bd5635a1 1368 len = l->nitems;
01d3fdba 1369 if (len <= 0)
c1878f87 1370 {
01d3fdba
JK
1371 /* I think len can be zero if the symtab lacks line numbers
1372 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
1373 I'm not sure which, and maybe it depends on the symbol
1374 reader). */
c1878f87
SG
1375 continue;
1376 }
1377
b638ca91
SG
1378 prev = NULL;
1379 item = l->item; /* Get first line info */
c1878f87
SG
1380
1381 /* Is this file's first line closer than the first lines of other files?
1382 If so, record this file, and its first line, as best alternate. */
b638ca91 1383 if (item->pc > pc && (!alt || item->pc < alt->pc))
c1878f87
SG
1384 {
1385 alt = item;
1386 alt_symtab = s;
1387 }
1388
b638ca91 1389 for (i = 0; i < len; i++, item++)
bd5635a1 1390 {
b607efe7
FF
1391 /* Leave prev pointing to the linetable entry for the last line
1392 that started at or before PC. */
b638ca91 1393 if (item->pc > pc)
bd5635a1 1394 break;
c1878f87
SG
1395
1396 prev = item;
bd5635a1
RP
1397 }
1398
c1878f87
SG
1399 /* At this point, prev points at the line whose start addr is <= pc, and
1400 item points at the next line. If we ran off the end of the linetable
1401 (pc >= start of the last line), then prev == item. If pc < start of
1402 the first line, prev will not be set. */
1403
bd5635a1
RP
1404 /* Is this file's best line closer than the best in the other files?
1405 If so, record this file, and its best line, as best so far. */
c1878f87 1406
b638ca91 1407 if (prev && (!best || prev->pc > best->pc))
bd5635a1 1408 {
c1878f87 1409 best = prev;
bd5635a1 1410 best_symtab = s;
cba0d141
JG
1411 /* If another line is in the linetable, and its PC is closer
1412 than the best_end we currently have, take it as best_end. */
b638ca91
SG
1413 if (i < len && (best_end == 0 || best_end > item->pc))
1414 best_end = item->pc;
bd5635a1
RP
1415 }
1416 }
c1878f87
SG
1417
1418 if (!best_symtab)
bd5635a1 1419 {
c1878f87
SG
1420 if (!alt_symtab)
1421 { /* If we didn't find any line # info, just
07422705 1422 return zeros. */
c1878f87 1423 val.pc = pc;
c1878f87
SG
1424 }
1425 else
1426 {
1427 val.symtab = alt_symtab;
b638ca91 1428 val.line = alt->line - 1;
2b576293
C
1429
1430 /* Don't return line 0, that means that we didn't find the line. */
1431 if (val.line == 0) ++val.line;
1432
c1878f87 1433 val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
b638ca91 1434 val.end = alt->pc;
c1878f87 1435 }
bd5635a1
RP
1436 }
1437 else
1438 {
1439 val.symtab = best_symtab;
b638ca91
SG
1440 val.line = best->line;
1441 val.pc = best->pc;
1442 if (best_end && (!alt || best_end < alt->pc))
cba0d141 1443 val.end = best_end;
a8a69e63 1444 else if (alt)
b638ca91 1445 val.end = alt->pc;
cba0d141
JG
1446 else
1447 val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
bd5635a1 1448 }
211b564e 1449 val.section = section;
bd5635a1
RP
1450 return val;
1451}
211b564e
PS
1452
1453/* Backward compatibility (no section) */
1454
1455struct symtab_and_line
1456find_pc_line (pc, notcurrent)
1457 CORE_ADDR pc;
1458 int notcurrent;
1459{
1460 asection *section;
1461
1462 section = find_pc_overlay (pc);
1463 if (pc_in_unmapped_range (pc, section))
1464 pc = overlay_mapped_address (pc, section);
1465 return find_pc_sect_line (pc, section, notcurrent);
1466}
1467
bd5635a1 1468\f
018ab14f
PS
1469static int find_line_symtab PARAMS ((struct symtab *, int, struct linetable **,
1470 int *, int *));
1471
1472/* Find line number LINE in any symtab whose name is the same as
1473 SYMTAB.
1474
1475 If found, return 1, set *LINETABLE to the linetable in which it was
1476 found, set *INDEX to the index in the linetable of the best entry
1477 found, and set *EXACT_MATCH nonzero if the value returned is an
1478 exact match.
1479
1480 If not found, return 0. */
1481
1482static int
1483find_line_symtab (symtab, line, linetable, index, exact_match)
1484 struct symtab *symtab;
1485 int line;
1486 struct linetable **linetable;
1487 int *index;
1488 int *exact_match;
1489{
1490 int exact;
1491
1492 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
1493 so far seen. */
1494
1495 int best_index;
1496 struct linetable *best_linetable;
1497
1498 /* First try looking it up in the given symtab. */
1499 best_linetable = LINETABLE (symtab);
1500 best_index = find_line_common (best_linetable, line, &exact);
1501 if (best_index < 0 || !exact)
1502 {
1503 /* Didn't find an exact match. So we better keep looking for
1504 another symtab with the same name. In the case of xcoff,
1505 multiple csects for one source file (produced by IBM's FORTRAN
1506 compiler) produce multiple symtabs (this is unavoidable
1507 assuming csects can be at arbitrary places in memory and that
1508 the GLOBAL_BLOCK of a symtab has a begin and end address). */
1509
1510 /* BEST is the smallest linenumber > LINE so far seen,
1511 or 0 if none has been seen so far.
1512 BEST_INDEX and BEST_LINETABLE identify the item for it. */
1513 int best;
1514
1515 struct objfile *objfile;
1516 struct symtab *s;
1517
1518 if (best_index >= 0)
1519 best = best_linetable->item[best_index].line;
1520 else
1521 best = 0;
1522
1523 ALL_SYMTABS (objfile, s)
1524 {
1525 struct linetable *l;
1526 int ind;
1527
1528 if (!STREQ (symtab->filename, s->filename))
1529 continue;
1530 l = LINETABLE (s);
1531 ind = find_line_common (l, line, &exact);
1532 if (ind >= 0)
1533 {
1534 if (exact)
1535 {
1536 best_index = ind;
1537 best_linetable = l;
1538 goto done;
1539 }
1540 if (best == 0 || l->item[ind].line < best)
1541 {
1542 best = l->item[ind].line;
1543 best_index = ind;
1544 best_linetable = l;
1545 }
1546 }
1547 }
1548 }
1549 done:
1550 if (best_index < 0)
1551 return 0;
1552
1553 if (index)
1554 *index = best_index;
1555 if (linetable)
1556 *linetable = best_linetable;
1557 if (exact_match)
1558 *exact_match = exact;
1559 return 1;
1560}
1561\f
7f6cb62e
KS
1562/* Set the PC value for a given source file and line number and return true.
1563 Returns zero for invalid line number (and sets the PC to 0).
bd5635a1
RP
1564 The source file is specified with a struct symtab. */
1565
7f6cb62e
KS
1566int
1567find_line_pc (symtab, line, pc)
bd5635a1
RP
1568 struct symtab *symtab;
1569 int line;
7f6cb62e 1570 CORE_ADDR *pc;
bd5635a1 1571{
018ab14f
PS
1572 struct linetable *l;
1573 int ind;
bd5635a1 1574
7f6cb62e 1575 *pc = 0;
bd5635a1
RP
1576 if (symtab == 0)
1577 return 0;
7f6cb62e 1578
018ab14f 1579 if (find_line_symtab (symtab, line, &l, &ind, NULL))
7f6cb62e
KS
1580 {
1581 *pc = l->item[ind].pc;
1582 return 1;
1583 }
018ab14f
PS
1584 else
1585 return 0;
bd5635a1
RP
1586}
1587
1588/* Find the range of pc values in a line.
1589 Store the starting pc of the line into *STARTPTR
1590 and the ending pc (start of next line) into *ENDPTR.
1591 Returns 1 to indicate success.
1592 Returns 0 if could not find the specified line. */
1593
1594int
b86a1b3b
JK
1595find_line_pc_range (sal, startptr, endptr)
1596 struct symtab_and_line sal;
bd5635a1
RP
1597 CORE_ADDR *startptr, *endptr;
1598{
b86a1b3b
JK
1599 CORE_ADDR startaddr;
1600 struct symtab_and_line found_sal;
bd5635a1 1601
b86a1b3b 1602 startaddr = sal.pc;
7f6cb62e 1603 if (startaddr==0 && !find_line_pc (sal.symtab, sal.line, &startaddr))
bd5635a1
RP
1604 return 0;
1605
b86a1b3b
JK
1606 /* This whole function is based on address. For example, if line 10 has
1607 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
1608 "info line *0x123" should say the line goes from 0x100 to 0x200
1609 and "info line *0x355" should say the line goes from 0x300 to 0x400.
1610 This also insures that we never give a range like "starts at 0x134
1611 and ends at 0x12c". */
1612
211b564e 1613 found_sal = find_pc_sect_line (startaddr, sal.section, 0);
b86a1b3b 1614 if (found_sal.line != sal.line)
bd5635a1 1615 {
b86a1b3b
JK
1616 /* The specified line (sal) has zero bytes. */
1617 *startptr = found_sal.pc;
1618 *endptr = found_sal.pc;
bd5635a1 1619 }
b86a1b3b
JK
1620 else
1621 {
1622 *startptr = found_sal.pc;
1623 *endptr = found_sal.end;
1624 }
1625 return 1;
bd5635a1
RP
1626}
1627
1628/* Given a line table and a line number, return the index into the line
1629 table for the pc of the nearest line whose number is >= the specified one.
b203fc18 1630 Return -1 if none is found. The value is >= 0 if it is an index.
bd5635a1
RP
1631
1632 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1633
1634static int
1635find_line_common (l, lineno, exact_match)
1636 register struct linetable *l;
1637 register int lineno;
1638 int *exact_match;
1639{
1640 register int i;
1641 register int len;
1642
1643 /* BEST is the smallest linenumber > LINENO so far seen,
1644 or 0 if none has been seen so far.
1645 BEST_INDEX identifies the item for it. */
1646
b203fc18 1647 int best_index = -1;
bd5635a1
RP
1648 int best = 0;
1649
1650 if (lineno <= 0)
b203fc18 1651 return -1;
4137c5fc
JG
1652 if (l == 0)
1653 return -1;
bd5635a1
RP
1654
1655 len = l->nitems;
1656 for (i = 0; i < len; i++)
1657 {
1658 register struct linetable_entry *item = &(l->item[i]);
1659
1660 if (item->line == lineno)
1661 {
d34d6f75 1662 /* Return the first (lowest address) entry which matches. */
bd5635a1
RP
1663 *exact_match = 1;
1664 return i;
1665 }
1666
1667 if (item->line > lineno && (best == 0 || item->line < best))
1668 {
1669 best = item->line;
1670 best_index = i;
1671 }
1672 }
1673
1674 /* If we got here, we didn't get an exact match. */
1675
1676 *exact_match = 0;
1677 return best_index;
1678}
1679
1680int
1681find_pc_line_pc_range (pc, startptr, endptr)
1682 CORE_ADDR pc;
1683 CORE_ADDR *startptr, *endptr;
1684{
1685 struct symtab_and_line sal;
1686 sal = find_pc_line (pc, 0);
1687 *startptr = sal.pc;
1688 *endptr = sal.end;
1689 return sal.symtab != 0;
1690}
76212295
PS
1691
1692/* Given a function symbol SYM, find the symtab and line for the start
1693 of the function.
1694 If the argument FUNFIRSTLINE is nonzero, we want the first line
1695 of real code inside the function. */
1696
1697static struct symtab_and_line
1698find_function_start_sal PARAMS ((struct symbol *sym, int));
1699
1700static struct symtab_and_line
1701find_function_start_sal (sym, funfirstline)
1702 struct symbol *sym;
1703 int funfirstline;
1704{
1705 CORE_ADDR pc;
1706 struct symtab_and_line sal;
1707
1708 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
211b564e 1709 fixup_symbol_section (sym, NULL);
76212295 1710 if (funfirstline)
211b564e
PS
1711 { /* skip "first line" of function (which is actually its prologue) */
1712 asection *section = SYMBOL_BFD_SECTION (sym);
1713 /* If function is in an unmapped overlay, use its unmapped LMA
1714 address, so that SKIP_PROLOGUE has something unique to work on */
1715 if (section_is_overlay (section) &&
1716 !section_is_mapped (section))
1717 pc = overlay_unmapped_address (pc, section);
1718
76212295
PS
1719 pc += FUNCTION_START_OFFSET;
1720 SKIP_PROLOGUE (pc);
211b564e
PS
1721
1722 /* For overlays, map pc back into its mapped VMA range */
1723 pc = overlay_mapped_address (pc, section);
76212295 1724 }
211b564e 1725 sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
76212295
PS
1726
1727#ifdef PROLOGUE_FIRSTLINE_OVERLAP
1728 /* Convex: no need to suppress code on first line, if any */
1729 sal.pc = pc;
1730#else
1731 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
1732 line is still part of the same function. */
1733 if (sal.pc != pc
1734 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= sal.end
1735 && sal.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym)))
1736 {
1737 /* First pc of next line */
1738 pc = sal.end;
1739 /* Recalculate the line number (might not be N+1). */
211b564e 1740 sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
76212295
PS
1741 }
1742 sal.pc = pc;
1743#endif
1744
1745 return sal;
1746}
bd5635a1 1747\f
d96b54ea
JK
1748/* If P is of the form "operator[ \t]+..." where `...' is
1749 some legitimate operator text, return a pointer to the
1750 beginning of the substring of the operator text.
1751 Otherwise, return "". */
a46d92a7 1752char *
d96b54ea
JK
1753operator_chars (p, end)
1754 char *p;
1755 char **end;
1756{
1757 *end = "";
1758 if (strncmp (p, "operator", 8))
1759 return *end;
1760 p += 8;
1761
1762 /* Don't get faked out by `operator' being part of a longer
1763 identifier. */
2cd99985 1764 if (isalpha(*p) || *p == '_' || *p == '$' || *p == '\0')
d96b54ea
JK
1765 return *end;
1766
1767 /* Allow some whitespace between `operator' and the operator symbol. */
1768 while (*p == ' ' || *p == '\t')
1769 p++;
1770
2cd99985
PB
1771 /* Recognize 'operator TYPENAME'. */
1772
1773 if (isalpha(*p) || *p == '_' || *p == '$')
1774 {
1775 register char *q = p+1;
1776 while (isalnum(*q) || *q == '_' || *q == '$')
1777 q++;
1778 *end = q;
1779 return p;
1780 }
1781
d96b54ea
JK
1782 switch (*p)
1783 {
1784 case '!':
1785 case '=':
1786 case '*':
1787 case '/':
1788 case '%':
1789 case '^':
1790 if (p[1] == '=')
1791 *end = p+2;
1792 else
1793 *end = p+1;
1794 return p;
1795 case '<':
1796 case '>':
1797 case '+':
1798 case '-':
1799 case '&':
1800 case '|':
1801 if (p[1] == '=' || p[1] == p[0])
1802 *end = p+2;
1803 else
1804 *end = p+1;
1805 return p;
1806 case '~':
1807 case ',':
1808 *end = p+1;
1809 return p;
1810 case '(':
1811 if (p[1] != ')')
1812 error ("`operator ()' must be specified without whitespace in `()'");
1813 *end = p+2;
1814 return p;
1815 case '?':
1816 if (p[1] != ':')
1817 error ("`operator ?:' must be specified without whitespace in `?:'");
1818 *end = p+2;
1819 return p;
1820 case '[':
1821 if (p[1] != ']')
1822 error ("`operator []' must be specified without whitespace in `[]'");
1823 *end = p+2;
1824 return p;
1825 default:
1826 error ("`operator %s' not supported", p);
1827 break;
1828 }
1829 *end = "";
1830 return *end;
1831}
1832
2b576293
C
1833/* Return the number of methods described for TYPE, including the
1834 methods from types it derives from. This can't be done in the symbol
1835 reader because the type of the baseclass might still be stubbed
1836 when the definition of the derived class is parsed. */
1837
1838static int total_number_of_methods PARAMS ((struct type *type));
1839
1840static int
1841total_number_of_methods (type)
1842 struct type *type;
1843{
1844 int n;
1845 int count;
1846
940d5967 1847 CHECK_TYPEDEF (type);
211b564e
PS
1848 if (TYPE_CPLUS_SPECIFIC (type) == NULL)
1849 return 0;
2b576293
C
1850 count = TYPE_NFN_FIELDS_TOTAL (type);
1851
1852 for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
1853 count += total_number_of_methods (TYPE_BASECLASS (type, n));
1854
1855 return count;
1856}
1857
bd5635a1 1858/* Recursive helper function for decode_line_1.
2b576293
C
1859 Look for methods named NAME in type T.
1860 Return number of matches.
1861 Put matches in SYM_ARR, which should have been allocated with
1862 a size of total_number_of_methods (T) * sizeof (struct symbol *).
1863 Note that this function is g++ specific. */
bd5635a1 1864
7f6cb62e 1865static int
2e4964ad 1866find_methods (t, name, sym_arr)
bd5635a1
RP
1867 struct type *t;
1868 char *name;
bd5635a1
RP
1869 struct symbol **sym_arr;
1870{
1871 int i1 = 0;
1872 int ibase;
1873 struct symbol *sym_class;
1874 char *class_name = type_name_no_tag (t);
7f6cb62e 1875
d34d6f75
JK
1876 /* Ignore this class if it doesn't have a name. This is ugly, but
1877 unless we figure out how to get the physname without the name of
1878 the class, then the loop can't do any good. */
bd5635a1
RP
1879 if (class_name
1880 && (sym_class = lookup_symbol (class_name,
1881 (struct block *)NULL,
1882 STRUCT_NAMESPACE,
1883 (int *)NULL,
1884 (struct symtab **)NULL)))
1885 {
1886 int method_counter;
7f6cb62e 1887
940d5967 1888 /* FIXME: Shouldn't this just be CHECK_TYPEDEF (t)? */
bd5635a1 1889 t = SYMBOL_TYPE (sym_class);
7f6cb62e
KS
1890
1891 /* Loop over each method name. At this level, all overloads of a name
1892 are counted as a single name. There is an inner loop which loops over
1893 each overload. */
1894
bd5635a1
RP
1895 for (method_counter = TYPE_NFN_FIELDS (t) - 1;
1896 method_counter >= 0;
1897 --method_counter)
1898 {
1899 int field_counter;
bd5635a1 1900 char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
d0cde99c
PS
1901 char dem_opname[64];
1902
7f6cb62e
KS
1903 if (strncmp (method_name, "__", 2) == 0 ||
1904 strncmp (method_name, "op", 2) == 0 ||
1905 strncmp (method_name, "type", 4) == 0)
1906 if (cplus_demangle_opname (method_name, dem_opname, DMGL_ANSI))
1907 method_name = dem_opname;
1908 else if (cplus_demangle_opname (method_name, dem_opname, 0))
1909 method_name = dem_opname;
1910
2e4964ad 1911 if (STREQ (name, method_name))
7f6cb62e 1912 /* Find all the overloaded methods with that name. */
bd5635a1
RP
1913 for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
1914 field_counter >= 0;
1915 --field_counter)
1916 {
7f6cb62e 1917 struct fn_field *f;
bd5635a1 1918 char *phys_name;
7f6cb62e
KS
1919
1920 f = TYPE_FN_FIELDLIST1 (t, method_counter);
1921
7e258d18 1922 if (TYPE_FN_FIELD_STUB (f, field_counter))
7f6cb62e
KS
1923 {
1924 char *tmp_name;
1925
1926 tmp_name = gdb_mangle_name (t,
1927 method_counter,
1928 field_counter);
1929 phys_name = alloca (strlen (tmp_name) + 1);
1930 strcpy (phys_name, tmp_name);
1931 free (tmp_name);
1932 }
1933 else
1934 phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
1935
ca6a826d
PS
1936 /* Destructor is handled by caller, dont add it to the list */
1937 if (DESTRUCTOR_PREFIX_P (phys_name))
1938 continue;
d34d6f75 1939
bd5635a1 1940 sym_arr[i1] = lookup_symbol (phys_name,
a46d92a7 1941 NULL, VAR_NAMESPACE,
bd5635a1
RP
1942 (int *) NULL,
1943 (struct symtab **) NULL);
a46d92a7
PS
1944 if (sym_arr[i1])
1945 i1++;
2cd99985
PB
1946 else
1947 {
7f6cb62e
KS
1948 /* This error message gets printed, but the method
1949 still seems to be found
1950 fputs_filtered("(Cannot find method ", gdb_stdout);
1951 fprintf_symbol_filtered (gdb_stdout, phys_name,
1952 language_cplus,
1953 DMGL_PARAMS | DMGL_ANSI);
1954 fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
1955 */
2cd99985 1956 }
bd5635a1
RP
1957 }
1958 }
1959 }
d34d6f75
JK
1960
1961 /* Only search baseclasses if there is no match yet, since names in
1962 derived classes override those in baseclasses.
1963
1964 FIXME: The above is not true; it is only true of member functions
1965 if they have the same number of arguments (??? - section 13.1 of the
1966 ARM says the function members are not in the same scope but doesn't
1967 really spell out the rules in a way I understand. In any case, if
1968 the number of arguments differ this is a case in which we can overload
1969 rather than hiding without any problem, and gcc 2.4.5 does overload
1970 rather than hiding in this case). */
1971
7f6cb62e
KS
1972 if (i1 == 0)
1973 for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
1974 i1 += find_methods (TYPE_BASECLASS (t, ibase), name, sym_arr + i1);
1975
bd5635a1
RP
1976 return i1;
1977}
1978
6f87ec4a
PS
1979/* Helper function for decode_line_1.
1980 Build a canonical line spec in CANONICAL if it is non-NULL and if
1981 the SAL has a symtab.
1982 If SYMNAME is non-NULL the canonical line spec is `filename:symname'.
1983 If SYMNAME is NULL the line number from SAL is used and the canonical
1984 line spec is `filename:linenum'. */
1985
1986static void
1987build_canonical_line_spec (sal, symname, canonical)
1988 struct symtab_and_line *sal;
1989 char *symname;
1990 char ***canonical;
1991{
1992 char **canonical_arr;
1993 char *canonical_name;
1994 char *filename;
1995 struct symtab *s = sal->symtab;
1996
1997 if (s == (struct symtab *)NULL
1998 || s->filename == (char *)NULL
1999 || canonical == (char ***)NULL)
2000 return;
2001
2002 canonical_arr = (char **) xmalloc (sizeof (char *));
2003 *canonical = canonical_arr;
2004
2005 filename = s->filename;
2006 if (symname != NULL)
2007 {
2008 canonical_name = xmalloc (strlen (filename) + strlen (symname) + 2);
2009 sprintf (canonical_name, "%s:%s", filename, symname);
2010 }
2011 else
2012 {
2013 canonical_name = xmalloc (strlen (filename) + 30);
2014 sprintf (canonical_name, "%s:%d", filename, sal->line);
2015 }
2016 canonical_arr[0] = canonical_name;
2017}
2018
bd5635a1
RP
2019/* Parse a string that specifies a line number.
2020 Pass the address of a char * variable; that variable will be
2021 advanced over the characters actually parsed.
2022
2023 The string can be:
2024
2025 LINENUM -- that line number in current file. PC returned is 0.
2026 FILE:LINENUM -- that line in that file. PC returned is 0.
2027 FUNCTION -- line number of openbrace of that function.
2028 PC returned is the start of the function.
2029 VARIABLE -- line number of definition of that variable.
2030 PC returned is 0.
2031 FILE:FUNCTION -- likewise, but prefer functions in that file.
2032 *EXPR -- line in which address EXPR appears.
2033
cba0d141 2034 FUNCTION may be an undebuggable function found in minimal symbol table.
bd5635a1
RP
2035
2036 If the argument FUNFIRSTLINE is nonzero, we want the first line
76212295
PS
2037 of real code inside a function when a function is specified, and it is
2038 not OK to specify a variable or type to get its line number.
bd5635a1
RP
2039
2040 DEFAULT_SYMTAB specifies the file to use if none is specified.
2041 It defaults to current_source_symtab.
2042 DEFAULT_LINE specifies the line number to use for relative
2043 line numbers (that start with signs). Defaults to current_source_line.
6f87ec4a
PS
2044 If CANONICAL is non-NULL, store an array of strings containing the canonical
2045 line specs there if necessary. Currently overloaded member functions and
2046 line numbers or static functions without a filename yield a canonical
2047 line spec. The array and the line spec strings are allocated on the heap,
2048 it is the callers responsibility to free them.
bd5635a1
RP
2049
2050 Note that it is possible to return zero for the symtab
2051 if no file is validly specified. Callers must check that.
2052 Also, the line number returned may be invalid. */
2053
dbdf5a2a
JK
2054/* We allow single quotes in various places. This is a hideous
2055 kludge, which exists because the completer can't yet deal with the
2056 lack of single quotes. FIXME: write a linespec_completer which we
2057 can use as appropriate instead of make_symbol_completion_list. */
2058
bd5635a1 2059struct symtabs_and_lines
6f87ec4a 2060decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
bd5635a1
RP
2061 char **argptr;
2062 int funfirstline;
2063 struct symtab *default_symtab;
2064 int default_line;
6f87ec4a 2065 char ***canonical;
bd5635a1 2066{
bd5635a1 2067 struct symtabs_and_lines values;
c1878f87
SG
2068#ifdef HPPA_COMPILER_BUG
2069 /* FIXME: The native HP 9000/700 compiler has a bug which appears
2070 when optimizing this file with target i960-vxworks. I haven't
2071 been able to construct a simple test case. The problem is that
2072 in the second call to SKIP_PROLOGUE below, the compiler somehow
2073 does not realize that the statement val = find_pc_line (...) will
2074 change the values of the fields of val. It extracts the elements
2075 into registers at the top of the block, and does not update the
2076 registers after the call to find_pc_line. You can check this by
2077 inserting a printf at the end of find_pc_line to show what values
2078 it is returning for val.pc and val.end and another printf after
2079 the call to see what values the function actually got (remember,
2080 this is compiling with cc -O, with this patch removed). You can
2081 also examine the assembly listing: search for the second call to
2082 skip_prologue; the LDO statement before the next call to
2083 find_pc_line loads the address of the structure which
2084 find_pc_line will return; if there is a LDW just before the LDO,
2085 which fetches an element of the structure, then the compiler
2086 still has the bug.
2087
2088 Setting val to volatile avoids the problem. We must undef
2089 volatile, because the HPPA native compiler does not define
2090 __STDC__, although it does understand volatile, and so volatile
2091 will have been defined away in defs.h. */
2092#undef volatile
2093 volatile struct symtab_and_line val;
2094#define volatile /*nothing*/
2095#else
bd5635a1 2096 struct symtab_and_line val;
c1878f87 2097#endif
bd5635a1 2098 register char *p, *p1;
1c95d7ab 2099 char *q, *pp;
bd5635a1
RP
2100 register struct symtab *s;
2101
2102 register struct symbol *sym;
2103 /* The symtab that SYM was found in. */
2104 struct symtab *sym_symtab;
2105
2106 register CORE_ADDR pc;
cba0d141 2107 register struct minimal_symbol *msymbol;
bd5635a1 2108 char *copy;
7e6deb7a 2109 int is_quoted, has_parens;
f70be3e4
JG
2110 char *saved_arg = *argptr;
2111 extern char *gdb_completer_quote_characters;
bd5635a1 2112
07422705
PS
2113 INIT_SAL (&val); /* initialize to zeroes */
2114
bd5635a1
RP
2115 /* Defaults have defaults. */
2116
2117 if (default_symtab == 0)
2118 {
2119 default_symtab = current_source_symtab;
2120 default_line = current_source_line;
2121 }
2122
8050a57b 2123 /* See if arg is *PC */
bd5635a1 2124
8050a57b 2125 if (**argptr == '*')
f70be3e4 2126 {
76212295 2127 (*argptr)++;
bd5635a1 2128 pc = parse_and_eval_address_1 (argptr);
7f6cb62e 2129
bd5635a1
RP
2130 values.sals = (struct symtab_and_line *)
2131 xmalloc (sizeof (struct symtab_and_line));
7f6cb62e 2132
bd5635a1
RP
2133 values.nelts = 1;
2134 values.sals[0] = find_pc_line (pc, 0);
7f6cb62e
KS
2135 values.sals[0].pc = pc;
2136 values.sals[0].section = find_pc_overlay (pc);
2137
bd5635a1
RP
2138 return values;
2139 }
2140
2141 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
2142
8050a57b 2143 s = NULL;
9b041f69
PS
2144 is_quoted = (**argptr
2145 && strchr (gdb_completer_quote_characters, **argptr) != NULL);
2146 has_parens = ((pp = strchr (*argptr, '(')) != NULL
2147 && (pp = strchr (pp, ')')) != NULL);
bd5635a1
RP
2148
2149 for (p = *argptr; *p; p++)
2150 {
7e6deb7a
KH
2151 if (p[0] == '<')
2152 {
76212295 2153 while(++p && *p != '>');
7e6deb7a
KH
2154 if (!p)
2155 {
a0cf4681 2156 error ("non-matching '<' and '>' in command");
7e6deb7a
KH
2157 }
2158 }
bd5635a1
RP
2159 if (p[0] == ':' || p[0] == ' ' || p[0] == '\t')
2160 break;
7f6cb62e 2161 /* start-sanitize-java */
d719efc6
DP
2162 if (p[0] == '.' && strchr (p, ':') == NULL) /* Java qualified method. */
2163 {
2164 /* Find the *last* '.', since the others are package qualifiers. */
2165 for (p1 = p; *p1; p1++)
2166 {
2167 if (*p1 == '.')
2168 p = p1;
2169 }
2170 break;
2171 }
7f6cb62e 2172 /* end-sanitize-java */
bd5635a1
RP
2173 }
2174 while (p[0] == ' ' || p[0] == '\t') p++;
2175
d719efc6 2176 if ((p[0] == ':' || p[0] == '.') && !has_parens)
bd5635a1 2177 {
7f6cb62e
KS
2178 /* C++ */
2179 /* start-sanitize-java */
2180 /* ... or Java */
2181 /* end-sanitize-java */
7e6deb7a 2182 if (is_quoted) *argptr = *argptr+1;
d719efc6 2183 if (p[0] == '.' || p[1] ==':')
bd5635a1 2184 {
7f6cb62e
KS
2185 struct symbol *sym_class;
2186
bd5635a1
RP
2187 /* Extract the class name. */
2188 p1 = p;
2189 while (p != *argptr && p[-1] == ' ') --p;
2190 copy = (char *) alloca (p - *argptr + 1);
4ed3a9ea 2191 memcpy (copy, *argptr, p - *argptr);
bd5635a1
RP
2192 copy[p - *argptr] = 0;
2193
2194 /* Discard the class name from the arg. */
d719efc6 2195 p = p1 + (p1[0] == ':' ? 2 : 1);
bd5635a1
RP
2196 while (*p == ' ' || *p == '\t') p++;
2197 *argptr = p;
2198
2199 sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0,
2200 (struct symtab **)NULL);
2201
2202 if (sym_class &&
7f6cb62e
KS
2203 (TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_STRUCT
2204 || TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_UNION))
bd5635a1 2205 {
7f6cb62e
KS
2206 struct symbol **sym_arr;
2207 struct type *t;
2208 int i1;
2209
2210 t = check_typedef (SYMBOL_TYPE (sym_class));
2211
bd5635a1 2212 /* Arg token is not digits => try it as a function name
d0cde99c 2213 Find the next token(everything up to end or next blank). */
9b041f69
PS
2214 if (**argptr
2215 && strchr (gdb_completer_quote_characters, **argptr) != NULL)
d0cde99c
PS
2216 {
2217 p = skip_quoted(*argptr);
2218 *argptr = *argptr + 1;
2219 }
2220 else
2221 {
2222 p = *argptr;
2223 while (*p && *p!=' ' && *p!='\t' && *p!=',' && *p!=':') p++;
2224 }
2225/*
d96b54ea 2226 q = operator_chars (*argptr, &q1);
d96b54ea
JK
2227 if (q1 - q)
2228 {
2cd99985
PB
2229 char *opname;
2230 char *tmp = alloca (q1 - q + 1);
2231 memcpy (tmp, q, q1 - q);
2232 tmp[q1 - q] = '\0';
8050a57b 2233 opname = cplus_mangle_opname (tmp, DMGL_ANSI);
2cd99985 2234 if (opname == NULL)
f70be3e4 2235 {
a0cf4681 2236 error_begin ();
1c95d7ab 2237 printf_filtered ("no mangling for \"%s\"\n", tmp);
f70be3e4 2238 cplusplus_hint (saved_arg);
f1ed4330 2239 return_to_top_level (RETURN_ERROR);
f70be3e4 2240 }
2cd99985
PB
2241 copy = (char*) alloca (3 + strlen(opname));
2242 sprintf (copy, "__%s", opname);
d96b54ea
JK
2243 p = q1;
2244 }
2245 else
d0cde99c 2246*/
d96b54ea 2247 {
d0cde99c 2248 copy = (char *) alloca (p - *argptr + 1 );
4ed3a9ea 2249 memcpy (copy, *argptr, p - *argptr);
d96b54ea 2250 copy[p - *argptr] = '\0';
9b041f69
PS
2251 if (p != *argptr
2252 && copy[p - *argptr - 1]
2253 && strchr (gdb_completer_quote_characters,
2254 copy[p - *argptr - 1]) != NULL)
2255 copy[p - *argptr - 1] = '\0';
d96b54ea 2256 }
bd5635a1
RP
2257
2258 /* no line number may be specified */
2259 while (*p == ' ' || *p == '\t') p++;
2260 *argptr = p;
2261
2262 sym = 0;
2263 i1 = 0; /* counter for the symbol array */
2b576293
C
2264 sym_arr = (struct symbol **) alloca(total_number_of_methods (t)
2265 * sizeof(struct symbol *));
bd5635a1 2266
a46d92a7 2267 if (destructor_name_p (copy, t))
bd5635a1 2268 {
a46d92a7
PS
2269 /* Destructors are a special case. */
2270 int m_index, f_index;
2271
2272 if (get_destructor_fn_field (t, &m_index, &f_index))
ca6a826d 2273 {
a46d92a7
PS
2274 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, m_index);
2275
2276 sym_arr[i1] =
2277 lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, f_index),
2278 NULL, VAR_NAMESPACE, (int *) NULL,
2279 (struct symtab **)NULL);
2280 if (sym_arr[i1])
2281 i1++;
ca6a826d 2282 }
bd5635a1
RP
2283 }
2284 else
2e4964ad 2285 i1 = find_methods (t, copy, sym_arr);
bd5635a1
RP
2286 if (i1 == 1)
2287 {
2288 /* There is exactly one field with that name. */
2289 sym = sym_arr[0];
2290
2291 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
2292 {
211b564e
PS
2293 values.sals = (struct symtab_and_line *)
2294 xmalloc (sizeof (struct symtab_and_line));
bd5635a1 2295 values.nelts = 1;
76212295
PS
2296 values.sals[0] = find_function_start_sal (sym,
2297 funfirstline);
bd5635a1
RP
2298 }
2299 else
2300 {
2301 values.nelts = 0;
2302 }
2303 return values;
2304 }
2305 if (i1 > 0)
2306 {
2307 /* There is more than one field with that name
2308 (overloaded). Ask the user which one to use. */
6f87ec4a 2309 return decode_line_2 (sym_arr, i1, funfirstline, canonical);
bd5635a1
RP
2310 }
2311 else
d96b54ea
JK
2312 {
2313 char *tmp;
2314
2315 if (OPNAME_PREFIX_P (copy))
2316 {
2317 tmp = (char *)alloca (strlen (copy+3) + 9);
2318 strcpy (tmp, "operator ");
2319 strcat (tmp, copy+3);
2320 }
2321 else
2322 tmp = copy;
a0cf4681 2323 error_begin ();
0e2a896c 2324 if (tmp[0] == '~')
1c95d7ab 2325 printf_filtered
a0cf4681
JK
2326 ("the class `%s' does not have destructor defined\n",
2327 SYMBOL_SOURCE_NAME(sym_class));
0e2a896c 2328 else
1c95d7ab 2329 printf_filtered
a0cf4681
JK
2330 ("the class %s does not have any method named %s\n",
2331 SYMBOL_SOURCE_NAME(sym_class), tmp);
f70be3e4 2332 cplusplus_hint (saved_arg);
f1ed4330 2333 return_to_top_level (RETURN_ERROR);
d96b54ea 2334 }
bd5635a1
RP
2335 }
2336 else
f70be3e4 2337 {
a0cf4681 2338 error_begin ();
f70be3e4 2339 /* The quotes are important if copy is empty. */
1c95d7ab 2340 printf_filtered
a0cf4681 2341 ("can't find class, struct, or union named \"%s\"\n", copy);
f70be3e4 2342 cplusplus_hint (saved_arg);
f1ed4330 2343 return_to_top_level (RETURN_ERROR);
f70be3e4 2344 }
bd5635a1
RP
2345 }
2346 /* end of C++ */
2347
2348
2349 /* Extract the file name. */
2350 p1 = p;
2351 while (p != *argptr && p[-1] == ' ') --p;
58050209 2352 copy = (char *) alloca (p - *argptr + 1);
4ed3a9ea 2353 memcpy (copy, *argptr, p - *argptr);
58050209 2354 copy[p - *argptr] = 0;
bd5635a1
RP
2355
2356 /* Find that file's data. */
2357 s = lookup_symtab (copy);
2358 if (s == 0)
2359 {
cba0d141 2360 if (!have_full_symbols () && !have_partial_symbols ())
bd5635a1
RP
2361 error (no_symtab_msg);
2362 error ("No source file named %s.", copy);
2363 }
2364
2365 /* Discard the file name from the arg. */
2366 p = p1 + 1;
2367 while (*p == ' ' || *p == '\t') p++;
2368 *argptr = p;
2369 }
2370
2371 /* S is specified file's symtab, or 0 if no file specified.
2372 arg no longer contains the file name. */
2373
2374 /* Check whether arg is all digits (and sign) */
2375
d0cde99c
PS
2376 q = *argptr;
2377 if (*q == '-' || *q == '+') q++;
2378 while (*q >= '0' && *q <= '9')
2379 q++;
bd5635a1 2380
d0cde99c 2381 if (q != *argptr && (*q == 0 || *q == ' ' || *q == '\t' || *q == ','))
bd5635a1
RP
2382 {
2383 /* We found a token consisting of all digits -- at least one digit. */
2384 enum sign {none, plus, minus} sign = none;
2385
6f87ec4a
PS
2386 /* We might need a canonical line spec if no file was specified. */
2387 int need_canonical = (s == 0) ? 1 : 0;
2388
bd5635a1
RP
2389 /* This is where we need to make sure that we have good defaults.
2390 We must guarantee that this section of code is never executed
2391 when we are called with just a function name, since
2392 select_source_symtab calls us with such an argument */
2393
2394 if (s == 0 && default_symtab == 0)
2395 {
bd5635a1
RP
2396 select_source_symtab (0);
2397 default_symtab = current_source_symtab;
2398 default_line = current_source_line;
2399 }
2400
2401 if (**argptr == '+')
2402 sign = plus, (*argptr)++;
2403 else if (**argptr == '-')
2404 sign = minus, (*argptr)++;
2405 val.line = atoi (*argptr);
2406 switch (sign)
2407 {
2408 case plus:
d0cde99c 2409 if (q == *argptr)
bd5635a1
RP
2410 val.line = 5;
2411 if (s == 0)
2412 val.line = default_line + val.line;
2413 break;
2414 case minus:
d0cde99c 2415 if (q == *argptr)
bd5635a1
RP
2416 val.line = 15;
2417 if (s == 0)
2418 val.line = default_line - val.line;
2419 else
2420 val.line = 1;
2421 break;
2422 case none:
2423 break; /* No need to adjust val.line. */
2424 }
2425
d0cde99c
PS
2426 while (*q == ' ' || *q == '\t') q++;
2427 *argptr = q;
bd5635a1
RP
2428 if (s == 0)
2429 s = default_symtab;
2430 val.symtab = s;
2431 val.pc = 0;
211b564e
PS
2432 values.sals = (struct symtab_and_line *)
2433 xmalloc (sizeof (struct symtab_and_line));
bd5635a1
RP
2434 values.sals[0] = val;
2435 values.nelts = 1;
6f87ec4a
PS
2436 if (need_canonical)
2437 build_canonical_line_spec (values.sals, NULL, canonical);
bd5635a1
RP
2438 return values;
2439 }
2440
2441 /* Arg token is not digits => try it as a variable name
2442 Find the next token (everything up to end or next whitespace). */
2cd99985 2443
2b576293
C
2444 if (**argptr == '$') /* Convenience variable */
2445 p = skip_quoted (*argptr + 1);
2446 else if (is_quoted)
7e6deb7a
KH
2447 {
2448 p = skip_quoted (*argptr);
2449 if (p[-1] != '\'')
2450 error ("Unmatched single quote.");
2451 }
2452 else if (has_parens)
2453 {
2454 p = pp+1;
2455 }
d0cde99c
PS
2456 else
2457 {
2458 p = skip_quoted(*argptr);
2459 }
2460
bd5635a1 2461 copy = (char *) alloca (p - *argptr + 1);
4ed3a9ea 2462 memcpy (copy, *argptr, p - *argptr);
f70be3e4 2463 copy[p - *argptr] = '\0';
e3d6ec4a 2464 if (p != *argptr
9b041f69
PS
2465 && copy[0]
2466 && copy[0] == copy [p - *argptr - 1]
f70be3e4
JG
2467 && strchr (gdb_completer_quote_characters, copy[0]) != NULL)
2468 {
f70be3e4
JG
2469 copy [p - *argptr - 1] = '\0';
2470 copy++;
f70be3e4 2471 }
bd5635a1
RP
2472 while (*p == ' ' || *p == '\t') p++;
2473 *argptr = p;
2474
2b576293
C
2475 /* See if it's a convenience variable */
2476
2477 if (*copy == '$')
2478 {
2479 value_ptr valx;
2480 int need_canonical = (s == 0) ? 1 : 0;
2481
2482 valx = value_of_internalvar (lookup_internalvar (copy + 1));
2483 if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT)
2484 error ("Convenience variables used in line specs must have integer values.");
2485
2486 val.symtab = s ? s : default_symtab;
2487 val.line = value_as_long (valx);
2488 val.pc = 0;
2489
2490 values.sals = (struct symtab_and_line *)xmalloc (sizeof val);
2491 values.sals[0] = val;
2492 values.nelts = 1;
2493
2494 if (need_canonical)
2495 build_canonical_line_spec (values.sals, NULL, canonical);
2496
2497 return values;
2498 }
2499
2500
bd5635a1
RP
2501 /* Look up that token as a variable.
2502 If file specified, use that file's per-file block to start with. */
2503
2504 sym = lookup_symbol (copy,
3ba6a043 2505 (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
bd5635a1
RP
2506 : get_selected_block ()),
2507 VAR_NAMESPACE, 0, &sym_symtab);
2508
2509 if (sym != NULL)
2510 {
2511 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
2512 {
2513 /* Arg is the name of a function */
211b564e
PS
2514 values.sals = (struct symtab_and_line *)
2515 xmalloc (sizeof (struct symtab_and_line));
76212295 2516 values.sals[0] = find_function_start_sal (sym, funfirstline);
bd5635a1 2517 values.nelts = 1;
ad0a2521
JK
2518
2519 /* Don't use the SYMBOL_LINE; if used at all it points to
2520 the line containing the parameters or thereabouts, not
2521 the first line of code. */
2522
2523 /* We might need a canonical line spec if it is a static
2524 function. */
6f87ec4a
PS
2525 if (s == 0)
2526 {
2527 struct blockvector *bv = BLOCKVECTOR (sym_symtab);
2528 struct block *b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
2529 if (lookup_block_symbol (b, copy, VAR_NAMESPACE) != NULL)
2530 build_canonical_line_spec (values.sals, copy, canonical);
2531 }
bd5635a1
RP
2532 return values;
2533 }
76212295 2534 else
bd5635a1 2535 {
76212295
PS
2536 if (funfirstline)
2537 error ("\"%s\" is not a function", copy);
2538 else if (SYMBOL_LINE (sym) != 0)
2539 {
2540 /* We know its line number. */
2541 values.sals = (struct symtab_and_line *)
2542 xmalloc (sizeof (struct symtab_and_line));
2543 values.nelts = 1;
2544 memset (&values.sals[0], 0, sizeof (values.sals[0]));
2545 values.sals[0].symtab = sym_symtab;
2546 values.sals[0].line = SYMBOL_LINE (sym);
2547 return values;
2548 }
2549 else
2550 /* This can happen if it is compiled with a compiler which doesn't
2551 put out line numbers for variables. */
2552 /* FIXME: Shouldn't we just set .line and .symtab to zero
2553 and return? For example, "info line foo" could print
2554 the address. */
2555 error ("Line number not known for symbol \"%s\"", copy);
bd5635a1 2556 }
bd5635a1
RP
2557 }
2558
2b576293 2559 msymbol = lookup_minimal_symbol (copy, NULL, NULL);
cba0d141 2560 if (msymbol != NULL)
bd5635a1 2561 {
211b564e
PS
2562 val.pc = SYMBOL_VALUE_ADDRESS (msymbol);
2563 val.section = SYMBOL_BFD_SECTION (msymbol);
bd5635a1 2564 if (funfirstline)
2cacd1e3
PS
2565 {
2566 val.pc += FUNCTION_START_OFFSET;
2567 SKIP_PROLOGUE (val.pc);
2568 }
07422705
PS
2569 values.sals = (struct symtab_and_line *)
2570 xmalloc (sizeof (struct symtab_and_line));
bd5635a1
RP
2571 values.sals[0] = val;
2572 values.nelts = 1;
2573 return values;
2574 }
2575
cba0d141
JG
2576 if (!have_full_symbols () &&
2577 !have_partial_symbols () && !have_minimal_symbols ())
997a978c
JG
2578 error (no_symtab_msg);
2579
f70be3e4 2580 error ("Function \"%s\" not defined.", copy);
bd5635a1
RP
2581 return values; /* for lint */
2582}
2583
2584struct symtabs_and_lines
2585decode_line_spec (string, funfirstline)
2586 char *string;
2587 int funfirstline;
2588{
2589 struct symtabs_and_lines sals;
2590 if (string == 0)
2591 error ("Empty line specification.");
2592 sals = decode_line_1 (&string, funfirstline,
6f87ec4a
PS
2593 current_source_symtab, current_source_line,
2594 (char ***)NULL);
bd5635a1
RP
2595 if (*string)
2596 error ("Junk at end of line specification: %s", string);
2597 return sals;
2598}
2599
6f87ec4a
PS
2600/* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
2601 operate on (ask user if necessary).
2602 If CANONICAL is non-NULL return a corresponding array of mangled names
2603 as canonical line specs there. */
2e4964ad 2604
cba0d141 2605static struct symtabs_and_lines
6f87ec4a 2606decode_line_2 (sym_arr, nelts, funfirstline, canonical)
bd5635a1
RP
2607 struct symbol *sym_arr[];
2608 int nelts;
2609 int funfirstline;
6f87ec4a 2610 char ***canonical;
bd5635a1 2611{
bd5635a1 2612 struct symtabs_and_lines values, return_values;
cba0d141 2613 char *args, *arg1;
bd5635a1
RP
2614 int i;
2615 char *prompt;
2e4964ad 2616 char *symname;
6f87ec4a
PS
2617 struct cleanup *old_chain;
2618 char **canonical_arr = (char **)NULL;
bd5635a1 2619
211b564e
PS
2620 values.sals = (struct symtab_and_line *)
2621 alloca (nelts * sizeof(struct symtab_and_line));
2622 return_values.sals = (struct symtab_and_line *)
2623 xmalloc (nelts * sizeof(struct symtab_and_line));
6f87ec4a
PS
2624 old_chain = make_cleanup (free, return_values.sals);
2625
2626 if (canonical)
2627 {
2628 canonical_arr = (char **) xmalloc (nelts * sizeof (char *));
2629 make_cleanup (free, canonical_arr);
2630 memset (canonical_arr, 0, nelts * sizeof (char *));
2631 *canonical = canonical_arr;
2632 }
bd5635a1
RP
2633
2634 i = 0;
199b2450 2635 printf_unfiltered("[0] cancel\n[1] all\n");
bd5635a1
RP
2636 while (i < nelts)
2637 {
07422705
PS
2638 INIT_SAL (&return_values.sals[i]); /* initialize to zeroes */
2639 INIT_SAL (&values.sals[i]);
bd5635a1
RP
2640 if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK)
2641 {
76212295
PS
2642 values.sals[i] = find_function_start_sal (sym_arr[i], funfirstline);
2643 printf_unfiltered ("[%d] %s at %s:%d\n",
2644 (i+2),
2645 SYMBOL_SOURCE_NAME (sym_arr[i]),
2646 values.sals[i].symtab->filename,
2647 values.sals[i].line);
bd5635a1 2648 }
76212295
PS
2649 else
2650 printf_unfiltered ("?HERE\n");
bd5635a1
RP
2651 i++;
2652 }
2653
2654 if ((prompt = getenv ("PS2")) == NULL)
2655 {
2656 prompt = ">";
2657 }
199b2450
TL
2658 printf_unfiltered("%s ",prompt);
2659 gdb_flush(gdb_stdout);
bd5635a1 2660
a0cf4681 2661 args = command_line_input ((char *) NULL, 0, "overload-choice");
bd5635a1 2662
6f87ec4a 2663 if (args == 0 || *args == 0)
bd5635a1
RP
2664 error_no_arg ("one or more choice numbers");
2665
2666 i = 0;
2667 while (*args)
2668 {
2669 int num;
2670
2671 arg1 = args;
2672 while (*arg1 >= '0' && *arg1 <= '9') arg1++;
2673 if (*arg1 && *arg1 != ' ' && *arg1 != '\t')
2674 error ("Arguments must be choice numbers.");
2675
2676 num = atoi (args);
2677
2678 if (num == 0)
2679 error ("cancelled");
2680 else if (num == 1)
2681 {
6f87ec4a
PS
2682 if (canonical_arr)
2683 {
2684 for (i = 0; i < nelts; i++)
2685 {
2686 if (canonical_arr[i] == NULL)
2687 {
2688 symname = SYMBOL_NAME (sym_arr[i]);
2689 canonical_arr[i] = savestring (symname, strlen (symname));
2690 }
2691 }
2692 }
4ed3a9ea
FF
2693 memcpy (return_values.sals, values.sals,
2694 (nelts * sizeof(struct symtab_and_line)));
bd5635a1 2695 return_values.nelts = nelts;
6f87ec4a 2696 discard_cleanups (old_chain);
bd5635a1
RP
2697 return return_values;
2698 }
2699
07422705 2700 if (num >= nelts + 2)
bd5635a1 2701 {
199b2450 2702 printf_unfiltered ("No choice number %d.\n", num);
bd5635a1
RP
2703 }
2704 else
2705 {
2706 num -= 2;
2707 if (values.sals[num].pc)
2708 {
6f87ec4a
PS
2709 if (canonical_arr)
2710 {
2711 symname = SYMBOL_NAME (sym_arr[num]);
2712 make_cleanup (free, symname);
2713 canonical_arr[i] = savestring (symname, strlen (symname));
2714 }
bd5635a1
RP
2715 return_values.sals[i++] = values.sals[num];
2716 values.sals[num].pc = 0;
2717 }
2718 else
2719 {
199b2450 2720 printf_unfiltered ("duplicate request for %d ignored.\n", num);
bd5635a1
RP
2721 }
2722 }
2723
2724 args = arg1;
2725 while (*args == ' ' || *args == '\t') args++;
2726 }
2727 return_values.nelts = i;
6f87ec4a 2728 discard_cleanups (old_chain);
bd5635a1
RP
2729 return return_values;
2730}
2731
bd5635a1
RP
2732\f
2733/* Slave routine for sources_info. Force line breaks at ,'s.
2734 NAME is the name to print and *FIRST is nonzero if this is the first
2735 name printed. Set *FIRST to zero. */
2736static void
2737output_source_filename (name, first)
2738 char *name;
2739 int *first;
2740{
bd5635a1
RP
2741 /* Table of files printed so far. Since a single source file can
2742 result in several partial symbol tables, we need to avoid printing
2743 it more than once. Note: if some of the psymtabs are read in and
2744 some are not, it gets printed both under "Source files for which
2745 symbols have been read" and "Source files for which symbols will
2746 be read in on demand". I consider this a reasonable way to deal
2747 with the situation. I'm not sure whether this can also happen for
2748 symtabs; it doesn't hurt to check. */
2749 static char **tab = NULL;
2750 /* Allocated size of tab in elements.
2751 Start with one 256-byte block (when using GNU malloc.c).
2752 24 is the malloc overhead when range checking is in effect. */
2753 static int tab_alloc_size = (256 - 24) / sizeof (char *);
2754 /* Current size of tab in elements. */
2755 static int tab_cur_size;
2756
2757 char **p;
2758
2759 if (*first)
2760 {
2761 if (tab == NULL)
2762 tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab));
2763 tab_cur_size = 0;
2764 }
2765
2766 /* Is NAME in tab? */
2767 for (p = tab; p < tab + tab_cur_size; p++)
2e4964ad 2768 if (STREQ (*p, name))
bd5635a1
RP
2769 /* Yes; don't print it again. */
2770 return;
2771 /* No; add it to tab. */
2772 if (tab_cur_size == tab_alloc_size)
2773 {
2774 tab_alloc_size *= 2;
cba0d141 2775 tab = (char **) xrealloc ((char *) tab, tab_alloc_size * sizeof (*tab));
bd5635a1
RP
2776 }
2777 tab[tab_cur_size++] = name;
2778
2779 if (*first)
2780 {
bd5635a1
RP
2781 *first = 0;
2782 }
2783 else
2784 {
f70be3e4 2785 printf_filtered (", ");
bd5635a1
RP
2786 }
2787
f70be3e4 2788 wrap_here ("");
199b2450 2789 fputs_filtered (name, gdb_stdout);
bd5635a1
RP
2790}
2791
2792static void
35a25840
SG
2793sources_info (ignore, from_tty)
2794 char *ignore;
2795 int from_tty;
bd5635a1
RP
2796{
2797 register struct symtab *s;
2798 register struct partial_symtab *ps;
cba0d141 2799 register struct objfile *objfile;
bd5635a1
RP
2800 int first;
2801
cba0d141 2802 if (!have_full_symbols () && !have_partial_symbols ())
bd5635a1 2803 {
3053b9f2 2804 error (no_symtab_msg);
bd5635a1
RP
2805 }
2806
2807 printf_filtered ("Source files for which symbols have been read in:\n\n");
2808
2809 first = 1;
35a25840 2810 ALL_SYMTABS (objfile, s)
cba0d141 2811 {
35a25840 2812 output_source_filename (s -> filename, &first);
cba0d141 2813 }
bd5635a1
RP
2814 printf_filtered ("\n\n");
2815
2816 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2817
2818 first = 1;
35a25840 2819 ALL_PSYMTABS (objfile, ps)
cba0d141 2820 {
35a25840 2821 if (!ps->readin)
cba0d141 2822 {
35a25840 2823 output_source_filename (ps -> filename, &first);
cba0d141
JG
2824 }
2825 }
bd5635a1
RP
2826 printf_filtered ("\n");
2827}
2828
7f6cb62e
KS
2829static int
2830file_matches (file, files, nfiles)
2831 char *file;
2832 char *files[];
2833 int nfiles;
2834{
2835 int i;
2836
2837 if (file != NULL && nfiles != 0)
2838 {
2839 for (i = 0; i < nfiles; i++)
2840 {
2841 if (strcmp (files[i], basename (file)) == 0)
2842 return 1;
2843 }
2844 }
2845 else if (nfiles == 0)
2846 return 1;
2847 return 0;
2848}
2849
2850/* Free any memory associated with a search. */
2851void
2852free_search_symbols (symbols)
2853 struct symbol_search *symbols;
2854{
2855 struct symbol_search *p;
2856 struct symbol_search *next;
2857
2858 for (p = symbols; p != NULL; p = next)
2859 {
2860 next = p->next;
2861 free (p);
2862 }
2863}
2864
2865/* Search the symbol table for matches to the regular expression REGEXP,
2866 returning the results in *MATCHES.
bd5635a1 2867
7f6cb62e
KS
2868 Only symbols of KIND are searched:
2869 FUNCTIONS_NAMESPACE - search all functions
2870 TYPES_NAMESPACE - search all type names
2871 METHODS_NAMESPACE - search all methods NOT IMPLEMENTED
2872 VARIABLES_NAMESPACE - search all symbols, excluding functions, type names,
2873 and constants (enums)
bd5635a1 2874
7f6cb62e
KS
2875 free_search_symbols should be called when *MATCHES is no longer needed.
2876*/
2877void
2878search_symbols (regexp, kind, nfiles, files, matches)
bd5635a1 2879 char *regexp;
7f6cb62e
KS
2880 namespace_enum kind;
2881 int nfiles;
2882 char *files[];
2883 struct symbol_search **matches;
2884
bd5635a1
RP
2885{
2886 register struct symtab *s;
2887 register struct partial_symtab *ps;
2888 register struct blockvector *bv;
2889 struct blockvector *prev_bv = 0;
2890 register struct block *b;
2891 register int i, j;
2892 register struct symbol *sym;
b607efe7 2893 struct partial_symbol **psym;
cba0d141
JG
2894 struct objfile *objfile;
2895 struct minimal_symbol *msymbol;
35a25840 2896 char *val;
997a978c 2897 int found_misc = 0;
cba0d141
JG
2898 static enum minimal_symbol_type types[]
2899 = {mst_data, mst_text, mst_abs, mst_unknown};
2900 static enum minimal_symbol_type types2[]
ae6d035d
PS
2901 = {mst_bss, mst_file_text, mst_abs, mst_unknown};
2902 static enum minimal_symbol_type types3[]
2903 = {mst_file_data, mst_solib_trampoline, mst_abs, mst_unknown};
2904 static enum minimal_symbol_type types4[]
2905 = {mst_file_bss, mst_text, mst_abs, mst_unknown};
7f6cb62e
KS
2906 enum minimal_symbol_type ourtype;
2907 enum minimal_symbol_type ourtype2;
2908 enum minimal_symbol_type ourtype3;
2909 enum minimal_symbol_type ourtype4;
2910 struct symbol_search *sr;
2911 struct symbol_search *psr;
2912 struct symbol_search *tail;
2913 struct cleanup *old_chain = NULL;
2914
2915 if (kind < LABEL_NAMESPACE)
2916 error ("must search on specific namespace");
2917
2918 ourtype = types[(int) (kind - LABEL_NAMESPACE)];
2919 ourtype2 = types2[(int) (kind - LABEL_NAMESPACE)];
2920 ourtype3 = types3[(int) (kind - LABEL_NAMESPACE)];
2921 ourtype4 = types4[(int) (kind - LABEL_NAMESPACE)];
2922
2923 sr = *matches = NULL;
2924 tail = NULL;
bd5635a1 2925
2e4964ad 2926 if (regexp != NULL)
2cd99985
PB
2927 {
2928 /* Make sure spacing is right for C++ operators.
7f6cb62e
KS
2929 This is just a courtesy to make the matching less sensitive
2930 to how many spaces the user leaves between 'operator'
2931 and <TYPENAME> or <OPERATOR>. */
2cd99985
PB
2932 char *opend;
2933 char *opname = operator_chars (regexp, &opend);
2934 if (*opname)
7f6cb62e 2935 {
2cd99985 2936 int fix = -1; /* -1 means ok; otherwise number of spaces needed. */
7f6cb62e
KS
2937 if (isalpha(*opname) || *opname == '_' || *opname == '$')
2938 {
2939 /* There should 1 space between 'operator' and 'TYPENAME'. */
2940 if (opname[-1] != ' ' || opname[-2] == ' ')
2941 fix = 1;
2942 }
2943 else
2944 {
2945 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2946 if (opname[-1] == ' ')
2947 fix = 0;
2948 }
2949 /* If wrong number of spaces, fix it. */
2950 if (fix >= 0)
2951 {
2952 char *tmp = (char*) alloca(opend-opname+10);
2953 sprintf(tmp, "operator%.*s%s", fix, " ", opname);
2954 regexp = tmp;
2955 }
2cd99985
PB
2956 }
2957
2958 if (0 != (val = re_comp (regexp)))
7f6cb62e 2959 error ("Invalid regexp (%s): %s", val, regexp);
2cd99985 2960 }
bd5635a1 2961
cba0d141 2962 /* Search through the partial symtabs *first* for all symbols
bd5635a1
RP
2963 matching the regexp. That way we don't have to reproduce all of
2964 the machinery below. */
bd5635a1 2965
35a25840 2966 ALL_PSYMTABS (objfile, ps)
cba0d141 2967 {
b607efe7 2968 struct partial_symbol **bound, **gbound, **sbound;
35a25840 2969 int keep_going = 1;
7f6cb62e 2970
35a25840 2971 if (ps->readin) continue;
7f6cb62e 2972
35a25840
SG
2973 gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms;
2974 sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms;
2975 bound = gbound;
2976
2977 /* Go through all of the symbols stored in a partial
7f6cb62e 2978 symtab in one loop. */
35a25840
SG
2979 psym = objfile->global_psymbols.list + ps->globals_offset;
2980 while (keep_going)
7f6cb62e
KS
2981 {
2982 if (psym >= bound)
2983 {
2984 if (bound == gbound && ps->n_static_syms != 0)
2985 {
2986 psym = objfile->static_psymbols.list + ps->statics_offset;
2987 bound = sbound;
2988 }
2989 else
2990 keep_going = 0;
2991 continue;
2992 }
2993 else
2994 {
2995 QUIT;
2996
2997 /* If it would match (logic taken from loop below)
2998 load the file and go on to the next one */
2999 if (file_matches (ps->filename, files, nfiles)
3000 && ((regexp == NULL || SYMBOL_MATCHES_REGEXP (*psym))
3001 && ((kind == VARIABLES_NAMESPACE && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
3002 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
3003 || (kind == FUNCTIONS_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_BLOCK)
3004 || (kind == TYPES_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_TYPEDEF)
3005 || (kind == METHODS_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_BLOCK))))
3006 {
3007 PSYMTAB_TO_SYMTAB(ps);
3008 keep_going = 0;
3009 }
3010 }
3011 psym++;
3012 }
bd5635a1
RP
3013 }
3014
76212295
PS
3015 /* Here, we search through the minimal symbol tables for functions
3016 and variables that match, and force their symbols to be read.
3017 This is in particular necessary for demangled variable names,
3018 which are no longer put into the partial symbol tables.
3019 The symbol will then be found during the scan of symtabs below.
3020
3021 For functions, find_pc_symtab should succeed if we have debug info
3022 for the function, for variables we have to call lookup_symbol
3023 to determine if the variable has debug info.
3024 If the lookup fails, set found_misc so that we will rescan to print
3025 any matching symbols without debug info.
3026 */
997a978c 3027
7f6cb62e 3028 if (nfiles == 0 && (kind == VARIABLES_NAMESPACE || kind == FUNCTIONS_NAMESPACE))
cba0d141 3029 {
35a25840 3030 ALL_MSYMBOLS (objfile, msymbol)
7f6cb62e
KS
3031 {
3032 if (MSYMBOL_TYPE (msymbol) == ourtype ||
3033 MSYMBOL_TYPE (msymbol) == ourtype2 ||
3034 MSYMBOL_TYPE (msymbol) == ourtype3 ||
3035 MSYMBOL_TYPE (msymbol) == ourtype4)
3036 {
3037 if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
3038 {
3039 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)))
3040 {
3041 if (kind == FUNCTIONS_NAMESPACE
3042 || lookup_symbol (SYMBOL_NAME (msymbol),
3043 (struct block *) NULL,
3044 VAR_NAMESPACE,
3045 0, (struct symtab **) NULL) == NULL)
3046 found_misc = 1;
3047 }
3048 }
3049 }
3050 }
bd5635a1
RP
3051 }
3052
35a25840 3053 ALL_SYMTABS (objfile, s)
bd5635a1 3054 {
35a25840
SG
3055 bv = BLOCKVECTOR (s);
3056 /* Often many files share a blockvector.
7f6cb62e
KS
3057 Scan each blockvector only once so that
3058 we don't get every symbol many times.
3059 It happens that the first symtab in the list
3060 for any given blockvector is the main file. */
35a25840 3061 if (bv != prev_bv)
7f6cb62e
KS
3062 for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
3063 {
3064 b = BLOCKVECTOR_BLOCK (bv, i);
3065 /* Skip the sort if this block is always sorted. */
3066 if (!BLOCK_SHOULD_SORT (b))
3067 sort_block_syms (b);
3068 for (j = 0; j < BLOCK_NSYMS (b); j++)
3069 {
3070 QUIT;
3071 sym = BLOCK_SYM (b, j);
3072 if (file_matches (s->filename, files, nfiles)
3073 && ((regexp == NULL || SYMBOL_MATCHES_REGEXP (sym))
3074 && ((kind == VARIABLES_NAMESPACE && SYMBOL_CLASS (sym) != LOC_TYPEDEF
3075 && SYMBOL_CLASS (sym) != LOC_BLOCK
3076 && SYMBOL_CLASS (sym) != LOC_CONST)
3077 || (kind == FUNCTIONS_NAMESPACE && SYMBOL_CLASS (sym) == LOC_BLOCK)
3078 || (kind == TYPES_NAMESPACE && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
3079 || (kind == METHODS_NAMESPACE && SYMBOL_CLASS (sym) == LOC_BLOCK))))
3080 {
3081 /* match */
3082 psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search));
3083 psr->block = i;
3084 psr->symtab = s;
3085 psr->symbol = sym;
3086 psr->msymbol = NULL;
3087 psr->next = NULL;
3088 if (tail == NULL)
3089 {
3090 sr = psr;
3091 old_chain = make_cleanup (free_search_symbols, sr);
3092 }
3093 else
3094 tail->next = psr;
3095 tail = psr;
3096 }
3097 }
3098 }
35a25840 3099 prev_bv = bv;
bd5635a1 3100 }
997a978c 3101
997a978c 3102 /* If there are no eyes, avoid all contact. I mean, if there are
cba0d141
JG
3103 no debug symbols, then print directly from the msymbol_vector. */
3104
7f6cb62e 3105 if (found_misc || kind != FUNCTIONS_NAMESPACE)
cba0d141 3106 {
35a25840 3107 ALL_MSYMBOLS (objfile, msymbol)
7f6cb62e
KS
3108 {
3109 if (MSYMBOL_TYPE (msymbol) == ourtype ||
3110 MSYMBOL_TYPE (msymbol) == ourtype2 ||
3111 MSYMBOL_TYPE (msymbol) == ourtype3 ||
3112 MSYMBOL_TYPE (msymbol) == ourtype4)
3113 {
3114 if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
3115 {
3116 /* Functions: Look up by address. */
3117 if (kind != FUNCTIONS_NAMESPACE ||
3118 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol))))
3119 {
3120 /* Variables/Absolutes: Look up by name */
3121 if (lookup_symbol (SYMBOL_NAME (msymbol),
3122 (struct block *) NULL, VAR_NAMESPACE,
3123 0, (struct symtab **) NULL) == NULL)
3124 {
3125 /* match */
3126 psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search));
3127 psr->block = i;
3128 psr->msymbol = msymbol;
3129 psr->symtab = NULL;
3130 psr->symbol = NULL;
3131 psr->next = NULL;
3132 if (tail == NULL)
f21c9aec 3133 {
7f6cb62e
KS
3134 sr = psr;
3135 old_chain = make_cleanup (free_search_symbols, &sr);
f21c9aec 3136 }
7f6cb62e
KS
3137 else
3138 tail->next = psr;
3139 tail = psr;
3140 }
3141 }
3142 }
3143 }
3144 }
997a978c 3145 }
7f6cb62e
KS
3146
3147 *matches = sr;
3148 if (sr != NULL)
3149 discard_cleanups (old_chain);
3150}
3151
3152/* Helper function for symtab_symbol_info, this function uses
3153 the data returned from search_symbols() to print information
3154 regarding the match to gdb_stdout.
3155*/
3156static int
3157print_symbol_info (kind, s, sym, block, last)
3158 namespace_enum kind;
3159 struct symtab *s;
3160 struct symbol *sym;
3161 int block;
3162 char *last;
3163{
3164 if (last == NULL || strcmp (last, s->filename) != 0)
3165 {
3166 fputs_filtered ("\nFile ", gdb_stdout);
3167 fputs_filtered (s->filename, gdb_stdout);
3168 fputs_filtered (":\n", gdb_stdout);
3169 }
3170
3171 if (kind != TYPES_NAMESPACE && block == STATIC_BLOCK)
3172 printf_filtered ("static ");
3173
3174 /* Typedef that is not a C++ class */
3175 if (kind == TYPES_NAMESPACE
3176 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
3177 c_typedef_print (SYMBOL_TYPE(sym), sym, gdb_stdout);
3178 /* variable, func, or typedef-that-is-c++-class */
3179 else if (kind < TYPES_NAMESPACE ||
3180 (kind == TYPES_NAMESPACE &&
3181 SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE))
3182 {
3183 type_print (SYMBOL_TYPE (sym),
3184 (SYMBOL_CLASS (sym) == LOC_TYPEDEF
3185 ? "" : SYMBOL_SOURCE_NAME (sym)),
3186 gdb_stdout, 0);
3187
3188 printf_filtered (";\n");
3189 }
3190 else
3191 {
3192# if 0
3193 /* Tiemann says: "info methods was never implemented." */
3194 char *demangled_name;
3195 c_type_print_base (TYPE_FN_FIELD_TYPE(t, block),
3196 gdb_stdout, 0, 0);
3197 c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, block),
3198 gdb_stdout, 0);
3199 if (TYPE_FN_FIELD_STUB (t, block))
3200 check_stub_method (TYPE_DOMAIN_TYPE (type), j, block);
3201 demangled_name =
3202 cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t, block),
3203 DMGL_ANSI | DMGL_PARAMS);
3204 if (demangled_name == NULL)
3205 fprintf_filtered (stream, "<badly mangled name %s>",
3206 TYPE_FN_FIELD_PHYSNAME (t, block));
3207 else
3208 {
3209 fputs_filtered (demangled_name, stream);
3210 free (demangled_name);
3211 }
3212# endif
3213 }
3214}
3215
3216/* This help function for symtab_symbol_info() prints information
3217 for non-debugging symbols to gdb_stdout.
3218*/
3219static void
3220print_msymbol_info (msymbol)
3221 struct minimal_symbol *msymbol;
3222{
3223 printf_filtered (" %08lx %s\n",
3224 (unsigned long) SYMBOL_VALUE_ADDRESS (msymbol),
3225 SYMBOL_SOURCE_NAME (msymbol));
3226}
3227
3228/* This is the guts of the commands "info functions", "info types", and
3229 "info variables". It calls search_symbols to find all matches and then
3230 print_[m]symbol_info to print out some useful information about the
3231 matches.
3232*/
3233static void
3234symtab_symbol_info (regexp, kind, from_tty)
3235 char *regexp;
3236 namespace_enum kind;
3237 int from_tty;
3238{
3239 static char *classnames[]
3240 = {"variable", "function", "type", "method"};
3241 struct symbol_search *symbols;
3242 struct symbol_search *p;
3243 struct cleanup *old_chain;
3244 char *last_filename = NULL;
3245 int first = 1;
3246
3247 /* must make sure that if we're interrupted, symbols gets freed */
3248 search_symbols (regexp, kind, 0, (char **) NULL, &symbols);
3249 old_chain = make_cleanup (free_search_symbols, symbols);
3250
3251 printf_filtered (regexp
3252 ? "All %ss matching regular expression \"%s\":\n"
3253 : "All defined %ss:\n",
3254 classnames[(int) (kind - LABEL_NAMESPACE - 1)], regexp);
3255
3256 for (p = symbols; p != NULL; p = p->next)
3257 {
3258 QUIT;
3259
3260 if (p->msymbol != NULL)
3261 {
3262 if (first)
3263 {
3264 printf_filtered ("\nNon-debugging symbols:\n");
3265 first = 0;
3266 }
3267 print_msymbol_info (p->msymbol);
3268 }
3269 else
3270 {
3271 print_symbol_info (kind,
3272 p->symtab,
3273 p->symbol,
3274 p->block,
3275 last_filename);
3276 last_filename = p->symtab->filename;
3277 }
3278 }
3279
3280 do_cleanups (old_chain);
bd5635a1
RP
3281}
3282
3283static void
35a25840 3284variables_info (regexp, from_tty)
bd5635a1 3285 char *regexp;
35a25840 3286 int from_tty;
bd5635a1 3287{
7f6cb62e 3288 symtab_symbol_info (regexp, VARIABLES_NAMESPACE, from_tty);
bd5635a1
RP
3289}
3290
3291static void
35a25840 3292functions_info (regexp, from_tty)
bd5635a1 3293 char *regexp;
35a25840 3294 int from_tty;
bd5635a1 3295{
7f6cb62e 3296 symtab_symbol_info (regexp, FUNCTIONS_NAMESPACE, from_tty);
bd5635a1
RP
3297}
3298
bd5635a1 3299static void
35a25840 3300types_info (regexp, from_tty)
bd5635a1 3301 char *regexp;
35a25840 3302 int from_tty;
bd5635a1 3303{
7f6cb62e 3304 symtab_symbol_info (regexp, TYPES_NAMESPACE, from_tty);
bd5635a1 3305}
bd5635a1
RP
3306
3307#if 0
3308/* Tiemann says: "info methods was never implemented." */
3309static void
3310methods_info (regexp)
3311 char *regexp;
3312{
7f6cb62e 3313 symtab_symbol_info (regexp, METHODS_NAMESPACE, 0, from_tty);
bd5635a1
RP
3314}
3315#endif /* 0 */
3316
3317/* Breakpoint all functions matching regular expression. */
3318static void
35a25840 3319rbreak_command (regexp, from_tty)
bd5635a1 3320 char *regexp;
35a25840 3321 int from_tty;
bd5635a1 3322{
7f6cb62e
KS
3323 struct symbol_search *ss;
3324 struct symbol_search *p;
3325 struct cleanup *old_chain;
3326
3327 search_symbols (regexp, FUNCTIONS_NAMESPACE, 0, (char **) NULL, &ss);
3328 old_chain = make_cleanup (free_search_symbols, ss);
3329
3330 for (p = ss; p != NULL; p = p->next)
3331 {
3332 if (p->msymbol == NULL)
3333 {
3334 char *string = (char *) alloca (strlen (p->symtab->filename)
3335 + strlen (SYMBOL_NAME (p->symbol))
3336 + 4);
3337 strcpy (string, p->symtab->filename);
3338 strcat (string, ":'");
3339 strcat (string, SYMBOL_NAME (p->symbol));
3340 strcat (string, "'");
3341 break_command (string, from_tty);
3342 print_symbol_info (FUNCTIONS_NAMESPACE,
3343 p->symtab,
3344 p->symbol,
3345 p->block,
3346 p->symtab->filename);
3347 }
3348 else
3349 {
3350 break_command (SYMBOL_NAME (p->msymbol), from_tty);
3351 printf_filtered ("<function, no debug info> %s;\n",
3352 SYMBOL_SOURCE_NAME (p->msymbol));
3353 }
3354 }
3355
3356 do_cleanups (old_chain);
bd5635a1 3357}
bd5635a1 3358
7f6cb62e 3359\f
bd5635a1
RP
3360/* Return Nonzero if block a is lexically nested within block b,
3361 or if a and b have the same pc range.
3362 Return zero otherwise. */
3363int
3364contained_in (a, b)
3365 struct block *a, *b;
3366{
3367 if (!a || !b)
3368 return 0;
3369 return BLOCK_START (a) >= BLOCK_START (b)
3370 && BLOCK_END (a) <= BLOCK_END (b);
3371}
3372
3373\f
3374/* Helper routine for make_symbol_completion_list. */
3375
f70be3e4
JG
3376static int return_val_size;
3377static int return_val_index;
3378static char **return_val;
3379
f1ed4330 3380#define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
2e4964ad 3381 do { \
f1ed4330 3382 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \
67a64bec
JK
3383 /* Put only the mangled name on the list. */ \
3384 /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \
3385 /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \
f1ed4330
JK
3386 completion_list_add_name \
3387 (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \
67a64bec
JK
3388 else \
3389 completion_list_add_name \
3390 (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \
2e4964ad
FF
3391 } while (0)
3392
3393/* Test to see if the symbol specified by SYMNAME (which is already
f1ed4330 3394 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
2e4964ad 3395 characters. If so, add it to the current completion list. */
bd5635a1 3396
cba0d141 3397static void
f1ed4330 3398completion_list_add_name (symname, sym_text, sym_text_len, text, word)
bd5635a1 3399 char *symname;
f1ed4330
JK
3400 char *sym_text;
3401 int sym_text_len;
f70be3e4 3402 char *text;
f1ed4330 3403 char *word;
bd5635a1 3404{
f70be3e4 3405 int newsize;
8005788c
RP
3406 int i;
3407
3408 /* clip symbols that cannot match */
3409
f1ed4330 3410 if (strncmp (symname, sym_text, sym_text_len) != 0)
2e4964ad 3411 {
8005788c
RP
3412 return;
3413 }
f70be3e4 3414
2e4964ad
FF
3415 /* Clip any symbol names that we've already considered. (This is a
3416 time optimization) */
8005788c 3417
2e4964ad
FF
3418 for (i = 0; i < return_val_index; ++i)
3419 {
3420 if (STREQ (symname, return_val[i]))
3421 {
3422 return;
3423 }
f70be3e4 3424 }
2e4964ad
FF
3425
3426 /* We have a match for a completion, so add SYMNAME to the current list
3427 of matches. Note that the name is moved to freshly malloc'd space. */
f70be3e4 3428
f1ed4330
JK
3429 {
3430 char *new;
3431 if (word == sym_text)
3432 {
3433 new = xmalloc (strlen (symname) + 5);
3434 strcpy (new, symname);
3435 }
3436 else if (word > sym_text)
3437 {
3438 /* Return some portion of symname. */
3439 new = xmalloc (strlen (symname) + 5);
3440 strcpy (new, symname + (word - sym_text));
3441 }
3442 else
3443 {
3444 /* Return some of SYM_TEXT plus symname. */
3445 new = xmalloc (strlen (symname) + (sym_text - word) + 5);
3446 strncpy (new, word, sym_text - word);
3447 new[sym_text - word] = '\0';
3448 strcat (new, symname);
3449 }
3450
2b576293
C
3451 /* Recheck for duplicates if we intend to add a modified symbol. */
3452 if (word != sym_text)
3453 {
3454 for (i = 0; i < return_val_index; ++i)
3455 {
3456 if (STREQ (new, return_val[i]))
3457 {
3458 free (new);
3459 return;
3460 }
3461 }
3462 }
3463
f1ed4330
JK
3464 if (return_val_index + 3 > return_val_size)
3465 {
3466 newsize = (return_val_size *= 2) * sizeof (char *);
3467 return_val = (char **) xrealloc ((char *) return_val, newsize);
3468 }
3469 return_val[return_val_index++] = new;
3470 return_val[return_val_index] = NULL;
3471 }
bd5635a1
RP
3472}
3473
3474/* Return a NULL terminated array of all symbols (regardless of class) which
3475 begin by matching TEXT. If the answer is no symbols, then the return value
3476 is an array which contains only a NULL pointer.
3477
f70be3e4
JG
3478 Problem: All of the symbols have to be copied because readline frees them.
3479 I'm not going to worry about this; hopefully there won't be that many. */
bd5635a1
RP
3480
3481char **
f1ed4330
JK
3482make_symbol_completion_list (text, word)
3483 char *text;
3484 char *word;
bd5635a1 3485{
f70be3e4 3486 register struct symbol *sym;
bd5635a1
RP
3487 register struct symtab *s;
3488 register struct partial_symtab *ps;
cba0d141
JG
3489 register struct minimal_symbol *msymbol;
3490 register struct objfile *objfile;
bd5635a1 3491 register struct block *b, *surrounding_static_block = 0;
bd5635a1 3492 register int i, j;
b607efe7 3493 struct partial_symbol **psym;
f1ed4330
JK
3494 /* The symbol we are completing on. Points in same buffer as text. */
3495 char *sym_text;
3496 /* Length of sym_text. */
3497 int sym_text_len;
3498
3499 /* Now look for the symbol we are supposed to complete on.
3500 FIXME: This should be language-specific. */
3501 {
3502 char *p;
3503 char quote_found;
01d3fdba 3504 char *quote_pos = NULL;
f1ed4330
JK
3505
3506 /* First see if this is a quoted string. */
3507 quote_found = '\0';
3508 for (p = text; *p != '\0'; ++p)
3509 {
3510 if (quote_found != '\0')
3511 {
3512 if (*p == quote_found)
3513 /* Found close quote. */
3514 quote_found = '\0';
3515 else if (*p == '\\' && p[1] == quote_found)
3516 /* A backslash followed by the quote character
3517 doesn't end the string. */
3518 ++p;
3519 }
3520 else if (*p == '\'' || *p == '"')
3521 {
3522 quote_found = *p;
3523 quote_pos = p;
3524 }
3525 }
3526 if (quote_found == '\'')
3527 /* A string within single quotes can be a symbol, so complete on it. */
3528 sym_text = quote_pos + 1;
3529 else if (quote_found == '"')
3530 /* A double-quoted string is never a symbol, nor does it make sense
3531 to complete it any other way. */
3532 return NULL;
3533 else
3534 {
3535 /* It is not a quoted string. Break it based on the characters
3536 which are in symbols. */
3537 while (p > text)
3538 {
3539 if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
3540 --p;
3541 else
3542 break;
3543 }
3544 sym_text = p;
3545 }
3546 }
3547
3548 sym_text_len = strlen (sym_text);
bd5635a1 3549
bd5635a1
RP
3550 return_val_size = 100;
3551 return_val_index = 0;
f70be3e4
JG
3552 return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
3553 return_val[0] = NULL;
bd5635a1
RP
3554
3555 /* Look through the partial symtabs for all symbols which begin
f1ed4330 3556 by matching SYM_TEXT. Add each one that you find to the list. */
bd5635a1 3557
35a25840 3558 ALL_PSYMTABS (objfile, ps)
bd5635a1 3559 {
35a25840
SG
3560 /* If the psymtab's been read in we'll get it when we search
3561 through the blockvector. */
3562 if (ps->readin) continue;
3563
3564 for (psym = objfile->global_psymbols.list + ps->globals_offset;
3565 psym < (objfile->global_psymbols.list + ps->globals_offset
3566 + ps->n_global_syms);
3567 psym++)
bd5635a1 3568 {
f70be3e4
JG
3569 /* If interrupted, then quit. */
3570 QUIT;
b607efe7 3571 COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
35a25840
SG
3572 }
3573
3574 for (psym = objfile->static_psymbols.list + ps->statics_offset;
3575 psym < (objfile->static_psymbols.list + ps->statics_offset
3576 + ps->n_static_syms);
3577 psym++)
3578 {
3579 QUIT;
b607efe7 3580 COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
bd5635a1
RP
3581 }
3582 }
3583
cba0d141 3584 /* At this point scan through the misc symbol vectors and add each
bd5635a1
RP
3585 symbol you find to the list. Eventually we want to ignore
3586 anything that isn't a text symbol (everything else will be
3587 handled by the psymtab code above). */
3588
35a25840 3589 ALL_MSYMBOLS (objfile, msymbol)
cba0d141 3590 {
f70be3e4 3591 QUIT;
f1ed4330 3592 COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, word);
cba0d141 3593 }
bd5635a1
RP
3594
3595 /* Search upwards from currently selected frame (so that we can
3596 complete on local vars. */
f70be3e4
JG
3597
3598 for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
3599 {
3600 if (!BLOCK_SUPERBLOCK (b))
3601 {
3602 surrounding_static_block = b; /* For elmin of dups */
3603 }
3604
3605 /* Also catch fields of types defined in this places which match our
3606 text string. Only complete on types visible from current context. */
3607
3608 for (i = 0; i < BLOCK_NSYMS (b); i++)
3609 {
3610 sym = BLOCK_SYM (b, i);
f1ed4330 3611 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
f70be3e4
JG
3612 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
3613 {
3614 struct type *t = SYMBOL_TYPE (sym);
3615 enum type_code c = TYPE_CODE (t);
3616
3617 if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
3618 {
3619 for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
3620 {
3621 if (TYPE_FIELD_NAME (t, j))
3622 {
2e4964ad 3623 completion_list_add_name (TYPE_FIELD_NAME (t, j),
f1ed4330 3624 sym_text, sym_text_len, text, word);
f70be3e4
JG
3625 }
3626 }
3627 }
3628 }
3629 }
3630 }
3631
3632 /* Go through the symtabs and check the externs and statics for
3633 symbols which match. */
3634
3635 ALL_SYMTABS (objfile, s)
3636 {
3637 QUIT;
3638 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
3639 for (i = 0; i < BLOCK_NSYMS (b); i++)
3640 {
3641 sym = BLOCK_SYM (b, i);
f1ed4330 3642 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
f70be3e4
JG
3643 }
3644 }
3645
3646 ALL_SYMTABS (objfile, s)
3647 {
3648 QUIT;
3649 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
3650 /* Don't do this block twice. */
3651 if (b == surrounding_static_block) continue;
3652 for (i = 0; i < BLOCK_NSYMS (b); i++)
3653 {
3654 sym = BLOCK_SYM (b, i);
f1ed4330 3655 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
f70be3e4
JG
3656 }
3657 }
3658
3659 return (return_val);
3660}
3661
3f687c78
SG
3662/* Determine if PC is in the prologue of a function. The prologue is the area
3663 between the first instruction of a function, and the first executable line.
3664 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
9b041f69 3665
211b564e 3666 If non-zero, func_start is where we think the prologue starts, possibly
9b041f69 3667 by previous examination of symbol table information.
3f687c78
SG
3668 */
3669
3670int
3671in_prologue (pc, func_start)
3672 CORE_ADDR pc;
3673 CORE_ADDR func_start;
3674{
3675 struct symtab_and_line sal;
3676 CORE_ADDR func_addr, func_end;
3677
3678 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
3679 goto nosyms; /* Might be in prologue */
3680
3681 sal = find_pc_line (func_addr, 0);
3682
3683 if (sal.line == 0)
3684 goto nosyms;
3685
3686 if (sal.end > func_addr
3687 && sal.end <= func_end) /* Is prologue in function? */
3688 return pc < sal.end; /* Yes, is pc in prologue? */
3689
3690 /* The line after the prologue seems to be outside the function. In this
3691 case, tell the caller to find the prologue the hard way. */
3692
3693 return 1;
3694
3695/* Come here when symtabs don't contain line # info. In this case, it is
3696 likely that the user has stepped into a library function w/o symbols, or
3697 is doing a stepi/nexti through code without symbols. */
3698
3699 nosyms:
3700
9b041f69
PS
3701/* If func_start is zero (meaning unknown) then we don't know whether pc is
3702 in the prologue or not. I.E. it might be. */
3703
3704 if (!func_start) return 1;
3705
3f687c78
SG
3706/* We need to call the target-specific prologue skipping functions with the
3707 function's start address because PC may be pointing at an instruction that
3708 could be mistakenly considered part of the prologue. */
3709
3710 SKIP_PROLOGUE (func_start);
3711
3712 return pc < func_start;
3713}
3714
997a978c 3715\f
bd5635a1
RP
3716void
3717_initialize_symtab ()
3718{
3719 add_info ("variables", variables_info,
3720 "All global and static variable names, or those matching REGEXP.");
3721 add_info ("functions", functions_info,
3722 "All function names, or those matching REGEXP.");
3ba6a043
JG
3723
3724 /* FIXME: This command has at least the following problems:
bd5635a1
RP
3725 1. It prints builtin types (in a very strange and confusing fashion).
3726 2. It doesn't print right, e.g. with
3727 typedef struct foo *FOO
3728 type_print prints "FOO" when we want to make it (in this situation)
3729 print "struct foo *".
3730 I also think "ptype" or "whatis" is more likely to be useful (but if
3731 there is much disagreement "info types" can be fixed). */
3732 add_info ("types", types_info,
a0a6174a 3733 "All type names, or those matching REGEXP.");
3ba6a043 3734
bd5635a1
RP
3735#if 0
3736 add_info ("methods", methods_info,
3737 "All method names, or those matching REGEXP::REGEXP.\n\
50e0dc41 3738If the class qualifier is omitted, it is assumed to be the current scope.\n\
cba0d141 3739If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
bd5635a1
RP
3740are listed.");
3741#endif
3742 add_info ("sources", sources_info,
3743 "Source files in the program.");
3744
e21fb2ae 3745 add_com ("rbreak", class_breakpoint, rbreak_command,
bd5635a1
RP
3746 "Set a breakpoint for all functions matching REGEXP.");
3747
997a978c 3748 /* Initialize the one built-in type that isn't language dependent... */
cba0d141
JG
3749 builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0,
3750 "<unknown type>", (struct objfile *) NULL);
bd5635a1 3751}
This page took 0.61211 seconds and 4 git commands to generate.