(_bfd_elf_link_hash_table_init): Initialize dynlocal.
[deliverable/binutils-gdb.git] / gdb / symtab.c
CommitLineData
c906108c
SS
1/* Symbol table lookup for the GNU debugger, GDB.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 1998
c5aa993b 3 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b
JM
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
c906108c
SS
21
22#include "defs.h"
23#include "symtab.h"
24#include "gdbtypes.h"
25#include "gdbcore.h"
26#include "frame.h"
27#include "target.h"
28#include "value.h"
29#include "symfile.h"
30#include "objfiles.h"
31#include "gdbcmd.h"
32#include "call-cmds.h"
88987551 33#include "gdb_regex.h"
c906108c
SS
34#include "expression.h"
35#include "language.h"
36#include "demangle.h"
37#include "inferior.h"
38
39#include "obstack.h"
40
41#include <sys/types.h>
42#include <fcntl.h>
43#include "gdb_string.h"
44#include "gdb_stat.h"
45#include <ctype.h>
46
47/* Prototype for one function in parser-defs.h,
48 instead of including that entire file. */
49
a14ed312 50extern char *find_template_name_end (char *);
c906108c
SS
51
52/* Prototypes for local functions */
53
a14ed312 54static int find_methods (struct type *, char *, struct symbol **);
c906108c 55
a14ed312 56static void completion_list_add_name (char *, char *, int, char *, char *);
c906108c 57
a14ed312
KB
58static void build_canonical_line_spec (struct symtab_and_line *,
59 char *, char ***);
c906108c 60
a14ed312
KB
61static struct symtabs_and_lines decode_line_2 (struct symbol *[],
62 int, int, char ***);
c906108c 63
a14ed312 64static void rbreak_command (char *, int);
c906108c 65
a14ed312 66static void types_info (char *, int);
c906108c 67
a14ed312 68static void functions_info (char *, int);
c906108c 69
a14ed312 70static void variables_info (char *, int);
c906108c 71
a14ed312 72static void sources_info (char *, int);
c906108c 73
a14ed312 74static void output_source_filename (char *, int *);
c906108c 75
a14ed312 76char *operator_chars (char *, char **);
c906108c 77
a14ed312 78static int find_line_common (struct linetable *, int, int *);
c906108c 79
c5aa993b
JM
80static struct partial_symbol *lookup_partial_symbol PARAMS
81 ((struct partial_symtab *, const char *,
82 int, namespace_enum));
c906108c 83
a14ed312
KB
84static struct partial_symbol *fixup_psymbol_section (struct
85 partial_symbol *,
86 struct objfile *);
c906108c 87
a14ed312 88static struct symtab *lookup_symtab_1 (char *);
c906108c 89
a14ed312 90static void cplusplus_hint (char *);
c906108c 91
a14ed312 92static struct symbol *find_active_alias (struct symbol *sym, CORE_ADDR addr);
c906108c
SS
93
94/* This flag is used in hppa-tdep.c, and set in hp-symtab-read.c */
95/* Signals the presence of objects compiled by HP compilers */
96int hp_som_som_object_present = 0;
97
a14ed312 98static void fixup_section (struct general_symbol_info *, struct objfile *);
c906108c 99
a14ed312 100static int file_matches (char *, char **, int);
c906108c 101
a14ed312
KB
102static void print_symbol_info (namespace_enum,
103 struct symtab *, struct symbol *, int, char *);
c906108c 104
a14ed312 105static void print_msymbol_info (struct minimal_symbol *);
c906108c 106
a14ed312 107static void symtab_symbol_info (char *, namespace_enum, int);
c906108c 108
a14ed312 109static void overload_list_add_symbol (struct symbol *sym, char *oload_name);
392a587b 110
a14ed312 111void _initialize_symtab (void);
c906108c
SS
112
113/* */
114
115/* The single non-language-specific builtin type */
116struct type *builtin_type_error;
117
118/* Block in which the most recently searched-for symbol was found.
119 Might be better to make this a parameter to lookup_symbol and
120 value_of_this. */
121
122const struct block *block_found;
123
124char no_symtab_msg[] = "No symbol table is loaded. Use the \"file\" command.";
125
126/* While the C++ support is still in flux, issue a possibly helpful hint on
127 using the new command completion feature on single quoted demangled C++
128 symbols. Remove when loose ends are cleaned up. FIXME -fnf */
129
130static void
131cplusplus_hint (name)
132 char *name;
133{
134 while (*name == '\'')
135 name++;
136 printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name, name);
137 printf_filtered ("(Note leading single quote.)\n");
138}
139
140/* Check for a symtab of a specific name; first in symtabs, then in
141 psymtabs. *If* there is no '/' in the name, a match after a '/'
142 in the symtab filename will also work. */
143
144static struct symtab *
145lookup_symtab_1 (name)
146 char *name;
147{
148 register struct symtab *s;
149 register struct partial_symtab *ps;
150 register char *slash;
151 register struct objfile *objfile;
152
c5aa993b 153got_symtab:
c906108c
SS
154
155 /* First, search for an exact match */
156
157 ALL_SYMTABS (objfile, s)
158 if (STREQ (name, s->filename))
c5aa993b 159 return s;
c906108c
SS
160
161 slash = strchr (name, '/');
162
163 /* Now, search for a matching tail (only if name doesn't have any dirs) */
164
165 if (!slash)
166 ALL_SYMTABS (objfile, s)
c5aa993b
JM
167 {
168 char *p = s->filename;
169 char *tail = strrchr (p, '/');
c906108c 170
c5aa993b
JM
171 if (tail)
172 p = tail + 1;
c906108c 173
c5aa993b
JM
174 if (STREQ (p, name))
175 return s;
176 }
c906108c
SS
177
178 /* Same search rules as above apply here, but now we look thru the
179 psymtabs. */
180
181 ps = lookup_partial_symtab (name);
182 if (!ps)
183 return (NULL);
184
c5aa993b 185 if (ps->readin)
c906108c 186 error ("Internal: readin %s pst for `%s' found when no symtab found.",
c5aa993b 187 ps->filename, name);
c906108c
SS
188
189 s = PSYMTAB_TO_SYMTAB (ps);
190
191 if (s)
192 return s;
193
194 /* At this point, we have located the psymtab for this file, but
195 the conversion to a symtab has failed. This usually happens
196 when we are looking up an include file. In this case,
197 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
198 been created. So, we need to run through the symtabs again in
199 order to find the file.
200 XXX - This is a crock, and should be fixed inside of the the
201 symbol parsing routines. */
202 goto got_symtab;
203}
204
205/* Lookup the symbol table of a source file named NAME. Try a couple
206 of variations if the first lookup doesn't work. */
207
208struct symtab *
209lookup_symtab (name)
210 char *name;
211{
212 register struct symtab *s;
213#if 0
214 register char *copy;
215#endif
216
217 s = lookup_symtab_1 (name);
c5aa993b
JM
218 if (s)
219 return s;
c906108c
SS
220
221#if 0
222 /* This screws c-exp.y:yylex if there is both a type "tree" and a symtab
223 "tree.c". */
224
225 /* If name not found as specified, see if adding ".c" helps. */
226 /* Why is this? Is it just a user convenience? (If so, it's pretty
227 questionable in the presence of C++, FORTRAN, etc.). It's not in
228 the GDB manual. */
229
230 copy = (char *) alloca (strlen (name) + 3);
231 strcpy (copy, name);
232 strcat (copy, ".c");
233 s = lookup_symtab_1 (copy);
c5aa993b
JM
234 if (s)
235 return s;
c906108c
SS
236#endif /* 0 */
237
238 /* We didn't find anything; die. */
239 return 0;
240}
241
242/* Lookup the partial symbol table of a source file named NAME.
243 *If* there is no '/' in the name, a match after a '/'
244 in the psymtab filename will also work. */
245
246struct partial_symtab *
247lookup_partial_symtab (name)
c5aa993b 248 char *name;
c906108c
SS
249{
250 register struct partial_symtab *pst;
251 register struct objfile *objfile;
c5aa993b 252
c906108c 253 ALL_PSYMTABS (objfile, pst)
c5aa993b
JM
254 {
255 if (STREQ (name, pst->filename))
256 {
257 return (pst);
258 }
259 }
c906108c
SS
260
261 /* Now, search for a matching tail (only if name doesn't have any dirs) */
262
263 if (!strchr (name, '/'))
264 ALL_PSYMTABS (objfile, pst)
c5aa993b
JM
265 {
266 char *p = pst->filename;
267 char *tail = strrchr (p, '/');
c906108c 268
c5aa993b
JM
269 if (tail)
270 p = tail + 1;
c906108c 271
c5aa993b
JM
272 if (STREQ (p, name))
273 return (pst);
274 }
c906108c
SS
275
276 return (NULL);
277}
278\f
279/* Mangle a GDB method stub type. This actually reassembles the pieces of the
280 full method name, which consist of the class name (from T), the unadorned
281 method name from METHOD_ID, and the signature for the specific overload,
282 specified by SIGNATURE_ID. Note that this function is g++ specific. */
283
284char *
285gdb_mangle_name (type, method_id, signature_id)
286 struct type *type;
287 int method_id, signature_id;
288{
289 int mangled_name_len;
290 char *mangled_name;
291 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
292 struct fn_field *method = &f[signature_id];
293 char *field_name = TYPE_FN_FIELDLIST_NAME (type, method_id);
294 char *physname = TYPE_FN_FIELD_PHYSNAME (f, signature_id);
295 char *newname = type_name_no_tag (type);
296
297 /* Does the form of physname indicate that it is the full mangled name
298 of a constructor (not just the args)? */
299 int is_full_physname_constructor;
300
301 int is_constructor;
302 int is_destructor = DESTRUCTOR_PREFIX_P (physname);
303 /* Need a new type prefix. */
304 char *const_prefix = method->is_const ? "C" : "";
305 char *volatile_prefix = method->is_volatile ? "V" : "";
306 char buf[20];
307 int len = (newname == NULL ? 0 : strlen (newname));
308
c5aa993b
JM
309 is_full_physname_constructor =
310 ((physname[0] == '_' && physname[1] == '_' &&
311 (isdigit (physname[2]) || physname[2] == 'Q' || physname[2] == 't'))
312 || (strncmp (physname, "__ct", 4) == 0));
c906108c
SS
313
314 is_constructor =
c5aa993b 315 is_full_physname_constructor || (newname && STREQ (field_name, newname));
c906108c
SS
316
317 if (!is_destructor)
c5aa993b 318 is_destructor = (strncmp (physname, "__dt", 4) == 0);
c906108c
SS
319
320 if (is_destructor || is_full_physname_constructor)
321 {
c5aa993b
JM
322 mangled_name = (char *) xmalloc (strlen (physname) + 1);
323 strcpy (mangled_name, physname);
c906108c
SS
324 return mangled_name;
325 }
326
327 if (len == 0)
328 {
329 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
330 }
331 else if (physname[0] == 't' || physname[0] == 'Q')
332 {
333 /* The physname for template and qualified methods already includes
c5aa993b 334 the class name. */
c906108c
SS
335 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
336 newname = NULL;
337 len = 0;
338 }
339 else
340 {
341 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
342 }
343 mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
c5aa993b
JM
344 + strlen (buf) + len
345 + strlen (physname)
346 + 1);
c906108c
SS
347
348 /* Only needed for GNU-mangled names. ANSI-mangled names
349 work with the normal mechanisms. */
350 if (OPNAME_PREFIX_P (field_name))
351 {
352 const char *opname = cplus_mangle_opname (field_name + 3, 0);
353 if (opname == NULL)
354 error ("No mangling for \"%s\"", field_name);
355 mangled_name_len += strlen (opname);
c5aa993b 356 mangled_name = (char *) xmalloc (mangled_name_len);
c906108c
SS
357
358 strncpy (mangled_name, field_name, 3);
359 mangled_name[3] = '\0';
360 strcat (mangled_name, opname);
361 }
362 else
363 {
c5aa993b 364 mangled_name = (char *) xmalloc (mangled_name_len);
c906108c
SS
365 if (is_constructor)
366 mangled_name[0] = '\0';
367 else
368 strcpy (mangled_name, field_name);
369 }
370 strcat (mangled_name, buf);
371 /* If the class doesn't have a name, i.e. newname NULL, then we just
372 mangle it using 0 for the length of the class. Thus it gets mangled
c5aa993b 373 as something starting with `::' rather than `classname::'. */
c906108c
SS
374 if (newname != NULL)
375 strcat (mangled_name, newname);
376
377 strcat (mangled_name, physname);
378 return (mangled_name);
379}
c906108c
SS
380\f
381
c5aa993b 382
c906108c
SS
383/* Find which partial symtab on contains PC and SECTION. Return 0 if none. */
384
385struct partial_symtab *
386find_pc_sect_psymtab (pc, section)
387 CORE_ADDR pc;
388 asection *section;
389{
390 register struct partial_symtab *pst;
391 register struct objfile *objfile;
392
393 ALL_PSYMTABS (objfile, pst)
c5aa993b 394 {
c5aa993b 395 if (pc >= pst->textlow && pc < pst->texthigh)
c5aa993b
JM
396 {
397 struct minimal_symbol *msymbol;
398 struct partial_symtab *tpst;
399
400 /* An objfile that has its functions reordered might have
401 many partial symbol tables containing the PC, but
402 we want the partial symbol table that contains the
403 function containing the PC. */
404 if (!(objfile->flags & OBJF_REORDERED) &&
405 section == 0) /* can't validate section this way */
406 return (pst);
407
408 msymbol = lookup_minimal_symbol_by_pc_section (pc, section);
409 if (msymbol == NULL)
410 return (pst);
411
412 for (tpst = pst; tpst != NULL; tpst = tpst->next)
413 {
c5aa993b 414 if (pc >= tpst->textlow && pc < tpst->texthigh)
c5aa993b
JM
415 {
416 struct partial_symbol *p;
c906108c 417
c5aa993b
JM
418 p = find_pc_sect_psymbol (tpst, pc, section);
419 if (p != NULL
420 && SYMBOL_VALUE_ADDRESS (p)
421 == SYMBOL_VALUE_ADDRESS (msymbol))
422 return (tpst);
423 }
424 }
425 return (pst);
426 }
427 }
c906108c
SS
428 return (NULL);
429}
430
431/* Find which partial symtab contains PC. Return 0 if none.
432 Backward compatibility, no section */
433
434struct partial_symtab *
435find_pc_psymtab (pc)
436 CORE_ADDR pc;
437{
438 return find_pc_sect_psymtab (pc, find_pc_mapped_section (pc));
439}
440
441/* Find which partial symbol within a psymtab matches PC and SECTION.
442 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
443
444struct partial_symbol *
445find_pc_sect_psymbol (psymtab, pc, section)
446 struct partial_symtab *psymtab;
447 CORE_ADDR pc;
448 asection *section;
449{
450 struct partial_symbol *best = NULL, *p, **pp;
451 CORE_ADDR best_pc;
c5aa993b 452
c906108c
SS
453 if (!psymtab)
454 psymtab = find_pc_sect_psymtab (pc, section);
455 if (!psymtab)
456 return 0;
457
458 /* Cope with programs that start at address 0 */
459 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
460
461 /* Search the global symbols as well as the static symbols, so that
462 find_pc_partial_function doesn't use a minimal symbol and thus
463 cache a bad endaddr. */
464 for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
c5aa993b
JM
465 (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
466 < psymtab->n_global_syms);
c906108c
SS
467 pp++)
468 {
469 p = *pp;
470 if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
471 && SYMBOL_CLASS (p) == LOC_BLOCK
472 && pc >= SYMBOL_VALUE_ADDRESS (p)
473 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
474 || (psymtab->textlow == 0
475 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
476 {
c5aa993b 477 if (section) /* match on a specific section */
c906108c
SS
478 {
479 fixup_psymbol_section (p, psymtab->objfile);
480 if (SYMBOL_BFD_SECTION (p) != section)
481 continue;
482 }
483 best_pc = SYMBOL_VALUE_ADDRESS (p);
484 best = p;
485 }
486 }
487
488 for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
c5aa993b
JM
489 (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
490 < psymtab->n_static_syms);
c906108c
SS
491 pp++)
492 {
493 p = *pp;
494 if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
495 && SYMBOL_CLASS (p) == LOC_BLOCK
496 && pc >= SYMBOL_VALUE_ADDRESS (p)
497 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
c5aa993b 498 || (psymtab->textlow == 0
c906108c
SS
499 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
500 {
c5aa993b 501 if (section) /* match on a specific section */
c906108c
SS
502 {
503 fixup_psymbol_section (p, psymtab->objfile);
504 if (SYMBOL_BFD_SECTION (p) != section)
505 continue;
506 }
507 best_pc = SYMBOL_VALUE_ADDRESS (p);
508 best = p;
509 }
510 }
511
512 return best;
513}
514
515/* Find which partial symbol within a psymtab matches PC. Return 0 if none.
516 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
517
518struct partial_symbol *
519find_pc_psymbol (psymtab, pc)
520 struct partial_symtab *psymtab;
521 CORE_ADDR pc;
522{
523 return find_pc_sect_psymbol (psymtab, pc, find_pc_mapped_section (pc));
524}
525\f
526/* Debug symbols usually don't have section information. We need to dig that
527 out of the minimal symbols and stash that in the debug symbol. */
528
529static void
530fixup_section (ginfo, objfile)
531 struct general_symbol_info *ginfo;
532 struct objfile *objfile;
533{
534 struct minimal_symbol *msym;
535 msym = lookup_minimal_symbol (ginfo->name, NULL, objfile);
536
537 if (msym)
538 ginfo->bfd_section = SYMBOL_BFD_SECTION (msym);
539}
540
541struct symbol *
542fixup_symbol_section (sym, objfile)
543 struct symbol *sym;
544 struct objfile *objfile;
545{
546 if (!sym)
547 return NULL;
548
549 if (SYMBOL_BFD_SECTION (sym))
550 return sym;
551
552 fixup_section (&sym->ginfo, objfile);
553
554 return sym;
555}
556
557static struct partial_symbol *
558fixup_psymbol_section (psym, objfile)
559 struct partial_symbol *psym;
560 struct objfile *objfile;
561{
562 if (!psym)
563 return NULL;
564
565 if (SYMBOL_BFD_SECTION (psym))
566 return psym;
567
568 fixup_section (&psym->ginfo, objfile);
569
570 return psym;
571}
572
573/* Find the definition for a specified symbol name NAME
574 in namespace NAMESPACE, visible from lexical block BLOCK.
575 Returns the struct symbol pointer, or zero if no symbol is found.
576 If SYMTAB is non-NULL, store the symbol table in which the
577 symbol was found there, or NULL if not found.
578 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
579 NAME is a field of the current implied argument `this'. If so set
580 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
581 BLOCK_FOUND is set to the block in which NAME is found (in the case of
582 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
583
584/* This function has a bunch of loops in it and it would seem to be
585 attractive to put in some QUIT's (though I'm not really sure
586 whether it can run long enough to be really important). But there
587 are a few calls for which it would appear to be bad news to quit
588 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and
589 nindy_frame_chain_valid in nindy-tdep.c. (Note that there is C++
590 code below which can error(), but that probably doesn't affect
591 these calls since they are looking for a known variable and thus
592 can probably assume it will never hit the C++ code). */
593
594struct symbol *
595lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
596 const char *name;
597 register const struct block *block;
598 const namespace_enum namespace;
599 int *is_a_field_of_this;
600 struct symtab **symtab;
601{
602 register struct symbol *sym;
603 register struct symtab *s = NULL;
604 register struct partial_symtab *ps;
605 struct blockvector *bv;
606 register struct objfile *objfile = NULL;
607 register struct block *b;
608 register struct minimal_symbol *msymbol;
609
610 /* Search specified block and its superiors. */
611
612 while (block != 0)
613 {
614 sym = lookup_block_symbol (block, name, namespace);
c5aa993b 615 if (sym)
c906108c
SS
616 {
617 block_found = block;
618 if (symtab != NULL)
619 {
620 /* Search the list of symtabs for one which contains the
c5aa993b 621 address of the start of this block. */
c906108c 622 ALL_SYMTABS (objfile, s)
c5aa993b
JM
623 {
624 bv = BLOCKVECTOR (s);
625 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
626 if (BLOCK_START (b) <= BLOCK_START (block)
627 && BLOCK_END (b) > BLOCK_START (block))
628 goto found;
629 }
630 found:
c906108c
SS
631 *symtab = s;
632 }
633
634 return fixup_symbol_section (sym, objfile);
635 }
636 block = BLOCK_SUPERBLOCK (block);
637 }
638
639 /* FIXME: this code is never executed--block is always NULL at this
640 point. What is it trying to do, anyway? We already should have
641 checked the STATIC_BLOCK above (it is the superblock of top-level
642 blocks). Why is VAR_NAMESPACE special-cased? */
643 /* Don't need to mess with the psymtabs; if we have a block,
644 that file is read in. If we don't, then we deal later with
645 all the psymtab stuff that needs checking. */
646 /* Note (RT): The following never-executed code looks unnecessary to me also.
647 * If we change the code to use the original (passed-in)
648 * value of 'block', we could cause it to execute, but then what
649 * would it do? The STATIC_BLOCK of the symtab containing the passed-in
650 * 'block' was already searched by the above code. And the STATIC_BLOCK's
651 * of *other* symtabs (those files not containing 'block' lexically)
652 * should not contain 'block' address-wise. So we wouldn't expect this
653 * code to find any 'sym''s that were not found above. I vote for
654 * deleting the following paragraph of code.
655 */
656 if (namespace == VAR_NAMESPACE && block != NULL)
657 {
658 struct block *b;
659 /* Find the right symtab. */
660 ALL_SYMTABS (objfile, s)
c5aa993b
JM
661 {
662 bv = BLOCKVECTOR (s);
663 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
664 if (BLOCK_START (b) <= BLOCK_START (block)
665 && BLOCK_END (b) > BLOCK_START (block))
666 {
667 sym = lookup_block_symbol (b, name, VAR_NAMESPACE);
668 if (sym)
669 {
670 block_found = b;
671 if (symtab != NULL)
672 *symtab = s;
673 return fixup_symbol_section (sym, objfile);
674 }
675 }
676 }
c906108c
SS
677 }
678
679
680 /* C++: If requested to do so by the caller,
681 check to see if NAME is a field of `this'. */
682 if (is_a_field_of_this)
683 {
684 struct value *v = value_of_this (0);
c5aa993b 685
c906108c
SS
686 *is_a_field_of_this = 0;
687 if (v && check_field (v, name))
688 {
689 *is_a_field_of_this = 1;
690 if (symtab != NULL)
691 *symtab = NULL;
692 return NULL;
693 }
694 }
695
696 /* Now search all global blocks. Do the symtab's first, then
697 check the psymtab's. If a psymtab indicates the existence
698 of the desired name as a global, then do psymtab-to-symtab
699 conversion on the fly and return the found symbol. */
c5aa993b 700
c906108c 701 ALL_SYMTABS (objfile, s)
c5aa993b
JM
702 {
703 bv = BLOCKVECTOR (s);
704 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
705 sym = lookup_block_symbol (block, name, namespace);
706 if (sym)
707 {
708 block_found = block;
709 if (symtab != NULL)
710 *symtab = s;
711 return fixup_symbol_section (sym, objfile);
712 }
713 }
c906108c
SS
714
715#ifndef HPUXHPPA
716
717 /* Check for the possibility of the symbol being a function or
718 a mangled variable that is stored in one of the minimal symbol tables.
719 Eventually, all global symbols might be resolved in this way. */
c5aa993b 720
c906108c
SS
721 if (namespace == VAR_NAMESPACE)
722 {
723 msymbol = lookup_minimal_symbol (name, NULL, NULL);
724 if (msymbol != NULL)
725 {
726 s = find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol),
c5aa993b 727 SYMBOL_BFD_SECTION (msymbol));
c906108c
SS
728 if (s != NULL)
729 {
730 /* This is a function which has a symtab for its address. */
731 bv = BLOCKVECTOR (s);
732 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
733 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
734 namespace);
c5aa993b
JM
735 /* We kept static functions in minimal symbol table as well as
736 in static scope. We want to find them in the symbol table. */
737 if (!sym)
738 {
c906108c
SS
739 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
740 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
741 namespace);
742 }
743
744 /* sym == 0 if symbol was found in the minimal symbol table
c5aa993b
JM
745 but not in the symtab.
746 Return 0 to use the msymbol definition of "foo_".
c906108c 747
c5aa993b
JM
748 This happens for Fortran "foo_" symbols,
749 which are "foo" in the symtab.
c906108c 750
c5aa993b
JM
751 This can also happen if "asm" is used to make a
752 regular symbol but not a debugging symbol, e.g.
753 asm(".globl _main");
754 asm("_main:");
755 */
c906108c
SS
756
757 if (symtab != NULL)
758 *symtab = s;
759 return fixup_symbol_section (sym, objfile);
760 }
761 else if (MSYMBOL_TYPE (msymbol) != mst_text
762 && MSYMBOL_TYPE (msymbol) != mst_file_text
763 && !STREQ (name, SYMBOL_NAME (msymbol)))
764 {
765 /* This is a mangled variable, look it up by its
c5aa993b
JM
766 mangled name. */
767 return lookup_symbol (SYMBOL_NAME (msymbol), block,
c906108c
SS
768 namespace, is_a_field_of_this, symtab);
769 }
770 /* There are no debug symbols for this file, or we are looking
771 for an unmangled variable.
772 Try to find a matching static symbol below. */
773 }
774 }
c5aa993b 775
c906108c
SS
776#endif
777
778 ALL_PSYMTABS (objfile, ps)
c5aa993b
JM
779 {
780 if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
781 {
782 s = PSYMTAB_TO_SYMTAB (ps);
783 bv = BLOCKVECTOR (s);
784 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
785 sym = lookup_block_symbol (block, name, namespace);
786 if (!sym)
787 {
788 /* This shouldn't be necessary, but as a last resort
789 * try looking in the statics even though the psymtab
790 * claimed the symbol was global. It's possible that
791 * the psymtab gets it wrong in some cases.
792 */
793 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
794 sym = lookup_block_symbol (block, name, namespace);
795 if (!sym)
796 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
c906108c
SS
797%s may be an inlined function, or may be a template function\n\
798(if a template, try specifying an instantiation: %s<type>).",
c5aa993b
JM
799 name, ps->filename, name, name);
800 }
801 if (symtab != NULL)
802 *symtab = s;
803 return fixup_symbol_section (sym, objfile);
804 }
805 }
c906108c
SS
806
807 /* Now search all static file-level symbols.
808 Not strictly correct, but more useful than an error.
809 Do the symtabs first, then check the psymtabs.
810 If a psymtab indicates the existence
811 of the desired name as a file-level static, then do psymtab-to-symtab
812 conversion on the fly and return the found symbol. */
813
814 ALL_SYMTABS (objfile, s)
c5aa993b
JM
815 {
816 bv = BLOCKVECTOR (s);
817 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
818 sym = lookup_block_symbol (block, name, namespace);
819 if (sym)
820 {
821 block_found = block;
822 if (symtab != NULL)
823 *symtab = s;
824 return fixup_symbol_section (sym, objfile);
825 }
826 }
c906108c
SS
827
828 ALL_PSYMTABS (objfile, ps)
c5aa993b
JM
829 {
830 if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
831 {
832 s = PSYMTAB_TO_SYMTAB (ps);
833 bv = BLOCKVECTOR (s);
834 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
835 sym = lookup_block_symbol (block, name, namespace);
836 if (!sym)
837 {
838 /* This shouldn't be necessary, but as a last resort
839 * try looking in the globals even though the psymtab
840 * claimed the symbol was static. It's possible that
841 * the psymtab gets it wrong in some cases.
842 */
843 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
844 sym = lookup_block_symbol (block, name, namespace);
845 if (!sym)
846 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
c906108c
SS
847%s may be an inlined function, or may be a template function\n\
848(if a template, try specifying an instantiation: %s<type>).",
c5aa993b
JM
849 name, ps->filename, name, name);
850 }
851 if (symtab != NULL)
852 *symtab = s;
853 return fixup_symbol_section (sym, objfile);
854 }
855 }
c906108c
SS
856
857#ifdef HPUXHPPA
858
859 /* Check for the possibility of the symbol being a function or
860 a global variable that is stored in one of the minimal symbol tables.
861 The "minimal symbol table" is built from linker-supplied info.
862
863 RT: I moved this check to last, after the complete search of
864 the global (p)symtab's and static (p)symtab's. For HP-generated
865 symbol tables, this check was causing a premature exit from
866 lookup_symbol with NULL return, and thus messing up symbol lookups
867 of things like "c::f". It seems to me a check of the minimal
868 symbol table ought to be a last resort in any case. I'm vaguely
869 worried about the comment below which talks about FORTRAN routines "foo_"
870 though... is it saying we need to do the "minsym" check before
871 the static check in this case?
872 */
c5aa993b 873
c906108c
SS
874 if (namespace == VAR_NAMESPACE)
875 {
876 msymbol = lookup_minimal_symbol (name, NULL, NULL);
877 if (msymbol != NULL)
878 {
c5aa993b
JM
879 /* OK, we found a minimal symbol in spite of not
880 * finding any symbol. There are various possible
881 * explanations for this. One possibility is the symbol
882 * exists in code not compiled -g. Another possibility
883 * is that the 'psymtab' isn't doing its job.
884 * A third possibility, related to #2, is that we were confused
885 * by name-mangling. For instance, maybe the psymtab isn't
886 * doing its job because it only know about demangled
887 * names, but we were given a mangled name...
888 */
889
890 /* We first use the address in the msymbol to try to
891 * locate the appropriate symtab. Note that find_pc_symtab()
892 * has a side-effect of doing psymtab-to-symtab expansion,
893 * for the found symtab.
894 */
c906108c
SS
895 s = find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol));
896 if (s != NULL)
897 {
898 bv = BLOCKVECTOR (s);
899 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
900 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
901 namespace);
c5aa993b
JM
902 /* We kept static functions in minimal symbol table as well as
903 in static scope. We want to find them in the symbol table. */
904 if (!sym)
905 {
c906108c
SS
906 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
907 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
908 namespace);
909 }
c5aa993b
JM
910 /* If we found one, return it */
911 if (sym)
912 {
913 if (symtab != NULL)
914 *symtab = s;
915 return sym;
916 }
c906108c
SS
917
918 /* If we get here with sym == 0, the symbol was
c5aa993b
JM
919 found in the minimal symbol table
920 but not in the symtab.
921 Fall through and return 0 to use the msymbol
922 definition of "foo_".
923 (Note that outer code generally follows up a call
924 to this routine with a call to lookup_minimal_symbol(),
925 so a 0 return means we'll just flow into that other routine).
926
927 This happens for Fortran "foo_" symbols,
928 which are "foo" in the symtab.
929
930 This can also happen if "asm" is used to make a
931 regular symbol but not a debugging symbol, e.g.
932 asm(".globl _main");
933 asm("_main:");
934 */
c906108c
SS
935 }
936
c5aa993b
JM
937 /* If the lookup-by-address fails, try repeating the
938 * entire lookup process with the symbol name from
939 * the msymbol (if different from the original symbol name).
940 */
c906108c
SS
941 else if (MSYMBOL_TYPE (msymbol) != mst_text
942 && MSYMBOL_TYPE (msymbol) != mst_file_text
943 && !STREQ (name, SYMBOL_NAME (msymbol)))
944 {
945 return lookup_symbol (SYMBOL_NAME (msymbol), block,
946 namespace, is_a_field_of_this, symtab);
947 }
948 }
949 }
950
951#endif
952
953 if (symtab != NULL)
954 *symtab = NULL;
955 return 0;
956}
957
958/* Look, in partial_symtab PST, for symbol NAME. Check the global
959 symbols if GLOBAL, the static symbols if not */
960
961static struct partial_symbol *
962lookup_partial_symbol (pst, name, global, namespace)
963 struct partial_symtab *pst;
964 const char *name;
965 int global;
966 namespace_enum namespace;
967{
968 struct partial_symbol **start, **psym;
969 struct partial_symbol **top, **bottom, **center;
970 int length = (global ? pst->n_global_syms : pst->n_static_syms);
971 int do_linear_search = 1;
972
973 if (length == 0)
974 {
975 return (NULL);
976 }
c5aa993b 977
c906108c
SS
978 start = (global ?
979 pst->objfile->global_psymbols.list + pst->globals_offset :
c5aa993b 980 pst->objfile->static_psymbols.list + pst->statics_offset);
c906108c 981
c5aa993b 982 if (global) /* This means we can use a binary search. */
c906108c
SS
983 {
984 do_linear_search = 0;
985
986 /* Binary search. This search is guaranteed to end with center
987 pointing at the earliest partial symbol with the correct
c5aa993b
JM
988 name. At that point *all* partial symbols with that name
989 will be checked against the correct namespace. */
c906108c
SS
990
991 bottom = start;
992 top = start + length - 1;
993 while (top > bottom)
994 {
995 center = bottom + (top - bottom) / 2;
996 if (!(center < top))
997 abort ();
998 if (!do_linear_search
999 && (SYMBOL_LANGUAGE (*center) == language_cplus
1000 || SYMBOL_LANGUAGE (*center) == language_java
c5aa993b 1001 ))
c906108c
SS
1002 {
1003 do_linear_search = 1;
1004 }
1005 if (STRCMP (SYMBOL_NAME (*center), name) >= 0)
1006 {
1007 top = center;
1008 }
1009 else
1010 {
1011 bottom = center + 1;
1012 }
1013 }
1014 if (!(top == bottom))
1015 abort ();
1016 while (STREQ (SYMBOL_NAME (*top), name))
1017 {
1018 if (SYMBOL_NAMESPACE (*top) == namespace)
1019 {
1020 return (*top);
1021 }
c5aa993b 1022 top++;
c906108c
SS
1023 }
1024 }
1025
1026 /* Can't use a binary search or else we found during the binary search that
1027 we should also do a linear search. */
1028
1029 if (do_linear_search)
1030 {
1031 for (psym = start; psym < start + length; psym++)
1032 {
1033 if (namespace == SYMBOL_NAMESPACE (*psym))
1034 {
1035 if (SYMBOL_MATCHES_NAME (*psym, name))
1036 {
1037 return (*psym);
1038 }
1039 }
1040 }
1041 }
1042
1043 return (NULL);
1044}
1045
1046/* Look up a type named NAME in the struct_namespace. The type returned
1047 must not be opaque -- i.e., must have at least one field defined
1048
1049 This code was modelled on lookup_symbol -- the parts not relevant to looking
1050 up types were just left out. In particular it's assumed here that types
1051 are available in struct_namespace and only at file-static or global blocks. */
1052
1053
1054struct type *
1055lookup_transparent_type (name)
1056 const char *name;
1057{
1058 register struct symbol *sym;
1059 register struct symtab *s = NULL;
1060 register struct partial_symtab *ps;
1061 struct blockvector *bv;
1062 register struct objfile *objfile;
1063 register struct block *block;
c906108c
SS
1064
1065 /* Now search all the global symbols. Do the symtab's first, then
1066 check the psymtab's. If a psymtab indicates the existence
1067 of the desired name as a global, then do psymtab-to-symtab
1068 conversion on the fly and return the found symbol. */
c5aa993b 1069
c906108c 1070 ALL_SYMTABS (objfile, s)
c5aa993b
JM
1071 {
1072 bv = BLOCKVECTOR (s);
1073 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1074 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1075 if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1076 {
1077 return SYMBOL_TYPE (sym);
1078 }
1079 }
c906108c
SS
1080
1081 ALL_PSYMTABS (objfile, ps)
c5aa993b
JM
1082 {
1083 if (!ps->readin && lookup_partial_symbol (ps, name, 1, STRUCT_NAMESPACE))
1084 {
1085 s = PSYMTAB_TO_SYMTAB (ps);
1086 bv = BLOCKVECTOR (s);
1087 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1088 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1089 if (!sym)
1090 {
1091 /* This shouldn't be necessary, but as a last resort
1092 * try looking in the statics even though the psymtab
1093 * claimed the symbol was global. It's possible that
1094 * the psymtab gets it wrong in some cases.
1095 */
1096 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1097 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1098 if (!sym)
1099 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
c906108c
SS
1100%s may be an inlined function, or may be a template function\n\
1101(if a template, try specifying an instantiation: %s<type>).",
c5aa993b
JM
1102 name, ps->filename, name, name);
1103 }
1104 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1105 return SYMBOL_TYPE (sym);
1106 }
1107 }
c906108c
SS
1108
1109 /* Now search the static file-level symbols.
1110 Not strictly correct, but more useful than an error.
1111 Do the symtab's first, then
1112 check the psymtab's. If a psymtab indicates the existence
1113 of the desired name as a file-level static, then do psymtab-to-symtab
1114 conversion on the fly and return the found symbol.
1115 */
1116
1117 ALL_SYMTABS (objfile, s)
c5aa993b
JM
1118 {
1119 bv = BLOCKVECTOR (s);
1120 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1121 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1122 if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1123 {
1124 return SYMBOL_TYPE (sym);
1125 }
1126 }
c906108c
SS
1127
1128 ALL_PSYMTABS (objfile, ps)
c5aa993b
JM
1129 {
1130 if (!ps->readin && lookup_partial_symbol (ps, name, 0, STRUCT_NAMESPACE))
1131 {
1132 s = PSYMTAB_TO_SYMTAB (ps);
1133 bv = BLOCKVECTOR (s);
1134 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1135 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1136 if (!sym)
1137 {
1138 /* This shouldn't be necessary, but as a last resort
1139 * try looking in the globals even though the psymtab
1140 * claimed the symbol was static. It's possible that
1141 * the psymtab gets it wrong in some cases.
1142 */
1143 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1144 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1145 if (!sym)
1146 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
c906108c
SS
1147%s may be an inlined function, or may be a template function\n\
1148(if a template, try specifying an instantiation: %s<type>).",
c5aa993b
JM
1149 name, ps->filename, name, name);
1150 }
1151 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1152 return SYMBOL_TYPE (sym);
1153 }
1154 }
c906108c
SS
1155 return (struct type *) 0;
1156}
1157
1158
1159/* Find the psymtab containing main(). */
1160/* FIXME: What about languages without main() or specially linked
1161 executables that have no main() ? */
1162
1163struct partial_symtab *
1164find_main_psymtab ()
1165{
1166 register struct partial_symtab *pst;
1167 register struct objfile *objfile;
1168
1169 ALL_PSYMTABS (objfile, pst)
c5aa993b
JM
1170 {
1171 if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE))
1172 {
1173 return (pst);
1174 }
1175 }
c906108c
SS
1176 return (NULL);
1177}
1178
1179/* Search BLOCK for symbol NAME in NAMESPACE.
1180
1181 Note that if NAME is the demangled form of a C++ symbol, we will fail
1182 to find a match during the binary search of the non-encoded names, but
1183 for now we don't worry about the slight inefficiency of looking for
1184 a match we'll never find, since it will go pretty quick. Once the
1185 binary search terminates, we drop through and do a straight linear
1186 search on the symbols. Each symbol which is marked as being a C++
1187 symbol (language_cplus set) has both the encoded and non-encoded names
1188 tested for a match. */
1189
1190struct symbol *
1191lookup_block_symbol (block, name, namespace)
1192 register const struct block *block;
1193 const char *name;
1194 const namespace_enum namespace;
1195{
1196 register int bot, top, inc;
1197 register struct symbol *sym;
1198 register struct symbol *sym_found = NULL;
1199 register int do_linear_search = 1;
1200
1201 /* If the blocks's symbols were sorted, start with a binary search. */
1202
1203 if (BLOCK_SHOULD_SORT (block))
1204 {
1205 /* Reset the linear search flag so if the binary search fails, we
c5aa993b
JM
1206 won't do the linear search once unless we find some reason to
1207 do so, such as finding a C++ symbol during the binary search.
1208 Note that for C++ modules, ALL the symbols in a block should
1209 end up marked as C++ symbols. */
c906108c
SS
1210
1211 do_linear_search = 0;
1212 top = BLOCK_NSYMS (block);
1213 bot = 0;
1214
1215 /* Advance BOT to not far before the first symbol whose name is NAME. */
1216
1217 while (1)
1218 {
1219 inc = (top - bot + 1);
1220 /* No need to keep binary searching for the last few bits worth. */
1221 if (inc < 4)
1222 {
1223 break;
1224 }
1225 inc = (inc >> 1) + bot;
1226 sym = BLOCK_SYM (block, inc);
1227 if (!do_linear_search
1228 && (SYMBOL_LANGUAGE (sym) == language_cplus
1229 || SYMBOL_LANGUAGE (sym) == language_java
c5aa993b 1230 ))
c906108c
SS
1231 {
1232 do_linear_search = 1;
1233 }
1234 if (SYMBOL_NAME (sym)[0] < name[0])
1235 {
1236 bot = inc;
1237 }
1238 else if (SYMBOL_NAME (sym)[0] > name[0])
1239 {
1240 top = inc;
1241 }
1242 else if (STRCMP (SYMBOL_NAME (sym), name) < 0)
1243 {
1244 bot = inc;
1245 }
1246 else
1247 {
1248 top = inc;
1249 }
1250 }
1251
1252 /* Now scan forward until we run out of symbols, find one whose
c5aa993b
JM
1253 name is greater than NAME, or find one we want. If there is
1254 more than one symbol with the right name and namespace, we
1255 return the first one; I believe it is now impossible for us
1256 to encounter two symbols with the same name and namespace
1257 here, because blocks containing argument symbols are no
1258 longer sorted. */
c906108c
SS
1259
1260 top = BLOCK_NSYMS (block);
1261 while (bot < top)
1262 {
1263 sym = BLOCK_SYM (block, bot);
1264 inc = SYMBOL_NAME (sym)[0] - name[0];
1265 if (inc == 0)
1266 {
1267 inc = STRCMP (SYMBOL_NAME (sym), name);
1268 }
1269 if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
1270 {
1271 return (sym);
1272 }
1273 if (inc > 0)
1274 {
1275 break;
1276 }
1277 bot++;
1278 }
1279 }
1280
1281 /* Here if block isn't sorted, or we fail to find a match during the
1282 binary search above. If during the binary search above, we find a
1283 symbol which is a C++ symbol, then we have re-enabled the linear
1284 search flag which was reset when starting the binary search.
1285
1286 This loop is equivalent to the loop above, but hacked greatly for speed.
1287
1288 Note that parameter symbols do not always show up last in the
1289 list; this loop makes sure to take anything else other than
1290 parameter symbols first; it only uses parameter symbols as a
1291 last resort. Note that this only takes up extra computation
1292 time on a match. */
1293
1294 if (do_linear_search)
1295 {
1296 top = BLOCK_NSYMS (block);
1297 bot = 0;
1298 while (bot < top)
1299 {
1300 sym = BLOCK_SYM (block, bot);
1301 if (SYMBOL_NAMESPACE (sym) == namespace &&
1302 SYMBOL_MATCHES_NAME (sym, name))
1303 {
1304 /* If SYM has aliases, then use any alias that is active
c5aa993b
JM
1305 at the current PC. If no alias is active at the current
1306 PC, then use the main symbol.
c906108c 1307
c5aa993b 1308 ?!? Is checking the current pc correct? Is this routine
a0b3c4fd
JM
1309 ever called to look up a symbol from another context?
1310
1311 FIXME: No, it's not correct. If someone sets a
1312 conditional breakpoint at an address, then the
1313 breakpoint's `struct expression' should refer to the
1314 `struct symbol' appropriate for the breakpoint's
1315 address, which may not be the PC.
1316
1317 Even if it were never called from another context,
1318 it's totally bizarre for lookup_symbol's behavior to
1319 depend on the value of the inferior's current PC. We
1320 should pass in the appropriate PC as well as the
1321 block. The interface to lookup_symbol should change
1322 to require the caller to provide a PC. */
1323
c5aa993b
JM
1324 if (SYMBOL_ALIASES (sym))
1325 sym = find_active_alias (sym, read_pc ());
c906108c
SS
1326
1327 sym_found = sym;
1328 if (SYMBOL_CLASS (sym) != LOC_ARG &&
1329 SYMBOL_CLASS (sym) != LOC_LOCAL_ARG &&
1330 SYMBOL_CLASS (sym) != LOC_REF_ARG &&
1331 SYMBOL_CLASS (sym) != LOC_REGPARM &&
1332 SYMBOL_CLASS (sym) != LOC_REGPARM_ADDR &&
1333 SYMBOL_CLASS (sym) != LOC_BASEREG_ARG)
1334 {
1335 break;
1336 }
1337 }
1338 bot++;
1339 }
1340 }
1341 return (sym_found); /* Will be NULL if not found. */
1342}
1343
1344/* Given a main symbol SYM and ADDR, search through the alias
1345 list to determine if an alias is active at ADDR and return
1346 the active alias.
1347
1348 If no alias is active, then return SYM. */
1349
1350static struct symbol *
1351find_active_alias (sym, addr)
c5aa993b
JM
1352 struct symbol *sym;
1353 CORE_ADDR addr;
c906108c
SS
1354{
1355 struct range_list *r;
1356 struct alias_list *aliases;
1357
1358 /* If we have aliases, check them first. */
1359 aliases = SYMBOL_ALIASES (sym);
1360
1361 while (aliases)
1362 {
1363 if (!SYMBOL_RANGES (aliases->sym))
c5aa993b 1364 return aliases->sym;
c906108c
SS
1365 for (r = SYMBOL_RANGES (aliases->sym); r; r = r->next)
1366 {
1367 if (r->start <= addr && r->end > addr)
1368 return aliases->sym;
1369 }
1370 aliases = aliases->next;
1371 }
1372
1373 /* Nothing found, return the main symbol. */
1374 return sym;
1375}
c906108c 1376\f
c5aa993b 1377
c906108c
SS
1378/* Return the symbol for the function which contains a specified
1379 lexical block, described by a struct block BL. */
1380
1381struct symbol *
1382block_function (bl)
1383 struct block *bl;
1384{
1385 while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
1386 bl = BLOCK_SUPERBLOCK (bl);
1387
1388 return BLOCK_FUNCTION (bl);
1389}
1390
1391/* Find the symtab associated with PC and SECTION. Look through the
1392 psymtabs and read in another symtab if necessary. */
1393
1394struct symtab *
1395find_pc_sect_symtab (pc, section)
1396 CORE_ADDR pc;
1397 asection *section;
1398{
1399 register struct block *b;
1400 struct blockvector *bv;
1401 register struct symtab *s = NULL;
1402 register struct symtab *best_s = NULL;
1403 register struct partial_symtab *ps;
1404 register struct objfile *objfile;
1405 CORE_ADDR distance = 0;
1406
1407 /* Search all symtabs for the one whose file contains our address, and which
1408 is the smallest of all the ones containing the address. This is designed
1409 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1410 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1411 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1412
1413 This happens for native ecoff format, where code from included files
1414 gets its own symtab. The symtab for the included file should have
1415 been read in already via the dependency mechanism.
1416 It might be swifter to create several symtabs with the same name
1417 like xcoff does (I'm not sure).
1418
1419 It also happens for objfiles that have their functions reordered.
1420 For these, the symtab we are looking for is not necessarily read in. */
1421
1422 ALL_SYMTABS (objfile, s)
c5aa993b
JM
1423 {
1424 bv = BLOCKVECTOR (s);
1425 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
c906108c 1426
c5aa993b 1427 if (BLOCK_START (b) <= pc
c5aa993b 1428 && BLOCK_END (b) > pc
c5aa993b
JM
1429 && (distance == 0
1430 || BLOCK_END (b) - BLOCK_START (b) < distance))
1431 {
1432 /* For an objfile that has its functions reordered,
1433 find_pc_psymtab will find the proper partial symbol table
1434 and we simply return its corresponding symtab. */
1435 /* In order to better support objfiles that contain both
1436 stabs and coff debugging info, we continue on if a psymtab
1437 can't be found. */
1438 if ((objfile->flags & OBJF_REORDERED) && objfile->psymtabs)
1439 {
1440 ps = find_pc_sect_psymtab (pc, section);
1441 if (ps)
1442 return PSYMTAB_TO_SYMTAB (ps);
1443 }
1444 if (section != 0)
1445 {
1446 int i;
c906108c 1447
c5aa993b
JM
1448 for (i = 0; i < b->nsyms; i++)
1449 {
1450 fixup_symbol_section (b->sym[i], objfile);
1451 if (section == SYMBOL_BFD_SECTION (b->sym[i]))
1452 break;
1453 }
1454 if (i >= b->nsyms)
1455 continue; /* no symbol in this symtab matches section */
1456 }
1457 distance = BLOCK_END (b) - BLOCK_START (b);
1458 best_s = s;
1459 }
1460 }
c906108c
SS
1461
1462 if (best_s != NULL)
c5aa993b 1463 return (best_s);
c906108c
SS
1464
1465 s = NULL;
1466 ps = find_pc_sect_psymtab (pc, section);
1467 if (ps)
1468 {
1469 if (ps->readin)
1470 /* Might want to error() here (in case symtab is corrupt and
1471 will cause a core dump), but maybe we can successfully
1472 continue, so let's not. */
1473 /* FIXME-32x64: assumes pc fits in a long */
1474 warning ("\
1475(Internal error: pc 0x%lx in read in psymtab, but not in symtab.)\n",
c5aa993b 1476 (unsigned long) pc);
c906108c
SS
1477 s = PSYMTAB_TO_SYMTAB (ps);
1478 }
1479 return (s);
1480}
1481
1482/* Find the symtab associated with PC. Look through the psymtabs and
1483 read in another symtab if necessary. Backward compatibility, no section */
1484
1485struct symtab *
1486find_pc_symtab (pc)
1487 CORE_ADDR pc;
1488{
1489 return find_pc_sect_symtab (pc, find_pc_mapped_section (pc));
1490}
c906108c 1491\f
c5aa993b 1492
c906108c
SS
1493#if 0
1494
1495/* Find the closest symbol value (of any sort -- function or variable)
1496 for a given address value. Slow but complete. (currently unused,
1497 mainly because it is too slow. We could fix it if each symtab and
1498 psymtab had contained in it the addresses ranges of each of its
1499 sections, which also would be required to make things like "info
1500 line *0x2345" cause psymtabs to be converted to symtabs). */
1501
1502struct symbol *
1503find_addr_symbol (addr, symtabp, symaddrp)
1504 CORE_ADDR addr;
1505 struct symtab **symtabp;
1506 CORE_ADDR *symaddrp;
1507{
1508 struct symtab *symtab, *best_symtab;
1509 struct objfile *objfile;
1510 register int bot, top;
1511 register struct symbol *sym;
1512 register CORE_ADDR sym_addr;
1513 struct block *block;
1514 int blocknum;
1515
1516 /* Info on best symbol seen so far */
1517
1518 register CORE_ADDR best_sym_addr = 0;
1519 struct symbol *best_sym = 0;
1520
1521 /* FIXME -- we should pull in all the psymtabs, too! */
1522 ALL_SYMTABS (objfile, symtab)
c5aa993b
JM
1523 {
1524 /* Search the global and static blocks in this symtab for
1525 the closest symbol-address to the desired address. */
c906108c 1526
c5aa993b
JM
1527 for (blocknum = GLOBAL_BLOCK; blocknum <= STATIC_BLOCK; blocknum++)
1528 {
1529 QUIT;
1530 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), blocknum);
1531 top = BLOCK_NSYMS (block);
1532 for (bot = 0; bot < top; bot++)
1533 {
1534 sym = BLOCK_SYM (block, bot);
1535 switch (SYMBOL_CLASS (sym))
1536 {
1537 case LOC_STATIC:
1538 case LOC_LABEL:
1539 sym_addr = SYMBOL_VALUE_ADDRESS (sym);
1540 break;
1541
1542 case LOC_INDIRECT:
1543 sym_addr = SYMBOL_VALUE_ADDRESS (sym);
1544 /* An indirect symbol really lives at *sym_addr,
1545 * so an indirection needs to be done.
1546 * However, I am leaving this commented out because it's
1547 * expensive, and it's possible that symbolization
1548 * could be done without an active process (in
1549 * case this read_memory will fail). RT
1550 sym_addr = read_memory_unsigned_integer
1551 (sym_addr, TARGET_PTR_BIT / TARGET_CHAR_BIT);
1552 */
1553 break;
c906108c 1554
c5aa993b
JM
1555 case LOC_BLOCK:
1556 sym_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1557 break;
c906108c 1558
c5aa993b
JM
1559 default:
1560 continue;
1561 }
c906108c 1562
c5aa993b
JM
1563 if (sym_addr <= addr)
1564 if (sym_addr > best_sym_addr)
1565 {
1566 /* Quit if we found an exact match. */
1567 best_sym = sym;
1568 best_sym_addr = sym_addr;
1569 best_symtab = symtab;
1570 if (sym_addr == addr)
1571 goto done;
1572 }
1573 }
1574 }
1575 }
c906108c 1576
c5aa993b 1577done:
c906108c
SS
1578 if (symtabp)
1579 *symtabp = best_symtab;
1580 if (symaddrp)
1581 *symaddrp = best_sym_addr;
1582 return best_sym;
1583}
1584#endif /* 0 */
1585
1586/* Find the source file and line number for a given PC value and section.
1587 Return a structure containing a symtab pointer, a line number,
1588 and a pc range for the entire source line.
1589 The value's .pc field is NOT the specified pc.
1590 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1591 use the line that ends there. Otherwise, in that case, the line
1592 that begins there is used. */
1593
1594/* The big complication here is that a line may start in one file, and end just
1595 before the start of another file. This usually occurs when you #include
1596 code in the middle of a subroutine. To properly find the end of a line's PC
1597 range, we must search all symtabs associated with this compilation unit, and
1598 find the one whose first PC is closer than that of the next line in this
1599 symtab. */
1600
1601/* If it's worth the effort, we could be using a binary search. */
1602
1603struct symtab_and_line
1604find_pc_sect_line (pc, section, notcurrent)
1605 CORE_ADDR pc;
1606 struct sec *section;
1607 int notcurrent;
1608{
1609 struct symtab *s;
1610 register struct linetable *l;
1611 register int len;
1612 register int i;
1613 register struct linetable_entry *item;
1614 struct symtab_and_line val;
1615 struct blockvector *bv;
1616 struct minimal_symbol *msymbol;
1617 struct minimal_symbol *mfunsym;
1618
1619 /* Info on best line seen so far, and where it starts, and its file. */
1620
1621 struct linetable_entry *best = NULL;
1622 CORE_ADDR best_end = 0;
1623 struct symtab *best_symtab = 0;
1624
1625 /* Store here the first line number
1626 of a file which contains the line at the smallest pc after PC.
1627 If we don't find a line whose range contains PC,
1628 we will use a line one less than this,
1629 with a range from the start of that file to the first line's pc. */
1630 struct linetable_entry *alt = NULL;
1631 struct symtab *alt_symtab = 0;
1632
1633 /* Info on best line seen in this file. */
1634
1635 struct linetable_entry *prev;
1636
1637 /* If this pc is not from the current frame,
1638 it is the address of the end of a call instruction.
1639 Quite likely that is the start of the following statement.
1640 But what we want is the statement containing the instruction.
1641 Fudge the pc to make sure we get that. */
1642
c5aa993b 1643 INIT_SAL (&val); /* initialize to zeroes */
c906108c
SS
1644
1645 if (notcurrent)
1646 pc -= 1;
1647
c5aa993b 1648 /* elz: added this because this function returned the wrong
c906108c
SS
1649 information if the pc belongs to a stub (import/export)
1650 to call a shlib function. This stub would be anywhere between
1651 two functions in the target, and the line info was erroneously
1652 taken to be the one of the line before the pc.
c5aa993b 1653 */
c906108c 1654 /* RT: Further explanation:
c5aa993b 1655
c906108c
SS
1656 * We have stubs (trampolines) inserted between procedures.
1657 *
1658 * Example: "shr1" exists in a shared library, and a "shr1" stub also
1659 * exists in the main image.
1660 *
1661 * In the minimal symbol table, we have a bunch of symbols
1662 * sorted by start address. The stubs are marked as "trampoline",
1663 * the others appear as text. E.g.:
1664 *
1665 * Minimal symbol table for main image
1666 * main: code for main (text symbol)
1667 * shr1: stub (trampoline symbol)
1668 * foo: code for foo (text symbol)
1669 * ...
1670 * Minimal symbol table for "shr1" image:
1671 * ...
1672 * shr1: code for shr1 (text symbol)
1673 * ...
1674 *
1675 * So the code below is trying to detect if we are in the stub
1676 * ("shr1" stub), and if so, find the real code ("shr1" trampoline),
1677 * and if found, do the symbolization from the real-code address
1678 * rather than the stub address.
1679 *
1680 * Assumptions being made about the minimal symbol table:
1681 * 1. lookup_minimal_symbol_by_pc() will return a trampoline only
1682 * if we're really in the trampoline. If we're beyond it (say
1683 * we're in "foo" in the above example), it'll have a closer
1684 * symbol (the "foo" text symbol for example) and will not
1685 * return the trampoline.
1686 * 2. lookup_minimal_symbol_text() will find a real text symbol
1687 * corresponding to the trampoline, and whose address will
1688 * be different than the trampoline address. I put in a sanity
1689 * check for the address being the same, to avoid an
1690 * infinite recursion.
1691 */
c5aa993b
JM
1692 msymbol = lookup_minimal_symbol_by_pc (pc);
1693 if (msymbol != NULL)
c906108c 1694 if (MSYMBOL_TYPE (msymbol) == mst_solib_trampoline)
c5aa993b
JM
1695 {
1696 mfunsym = lookup_minimal_symbol_text (SYMBOL_NAME (msymbol), NULL, NULL);
1697 if (mfunsym == NULL)
1698 /* I eliminated this warning since it is coming out
1699 * in the following situation:
1700 * gdb shmain // test program with shared libraries
1701 * (gdb) break shr1 // function in shared lib
1702 * Warning: In stub for ...
1703 * In the above situation, the shared lib is not loaded yet,
1704 * so of course we can't find the real func/line info,
1705 * but the "break" still works, and the warning is annoying.
1706 * So I commented out the warning. RT */
1707 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */ ;
1708 /* fall through */
1709 else if (SYMBOL_VALUE (mfunsym) == SYMBOL_VALUE (msymbol))
1710 /* Avoid infinite recursion */
1711 /* See above comment about why warning is commented out */
1712 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */ ;
1713 /* fall through */
1714 else
1715 return find_pc_line (SYMBOL_VALUE (mfunsym), 0);
1716 }
c906108c
SS
1717
1718
1719 s = find_pc_sect_symtab (pc, section);
1720 if (!s)
1721 {
1722 /* if no symbol information, return previous pc */
1723 if (notcurrent)
1724 pc++;
1725 val.pc = pc;
1726 return val;
1727 }
1728
1729 bv = BLOCKVECTOR (s);
1730
1731 /* Look at all the symtabs that share this blockvector.
1732 They all have the same apriori range, that we found was right;
1733 but they have different line tables. */
1734
1735 for (; s && BLOCKVECTOR (s) == bv; s = s->next)
1736 {
1737 /* Find the best line in this symtab. */
1738 l = LINETABLE (s);
1739 if (!l)
c5aa993b 1740 continue;
c906108c
SS
1741 len = l->nitems;
1742 if (len <= 0)
1743 {
1744 /* I think len can be zero if the symtab lacks line numbers
1745 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
1746 I'm not sure which, and maybe it depends on the symbol
1747 reader). */
1748 continue;
1749 }
1750
1751 prev = NULL;
1752 item = l->item; /* Get first line info */
1753
1754 /* Is this file's first line closer than the first lines of other files?
c5aa993b 1755 If so, record this file, and its first line, as best alternate. */
c906108c
SS
1756 if (item->pc > pc && (!alt || item->pc < alt->pc))
1757 {
1758 alt = item;
1759 alt_symtab = s;
1760 }
1761
1762 for (i = 0; i < len; i++, item++)
1763 {
1764 /* Leave prev pointing to the linetable entry for the last line
1765 that started at or before PC. */
1766 if (item->pc > pc)
1767 break;
1768
1769 prev = item;
1770 }
1771
1772 /* At this point, prev points at the line whose start addr is <= pc, and
c5aa993b
JM
1773 item points at the next line. If we ran off the end of the linetable
1774 (pc >= start of the last line), then prev == item. If pc < start of
1775 the first line, prev will not be set. */
c906108c
SS
1776
1777 /* Is this file's best line closer than the best in the other files?
c5aa993b 1778 If so, record this file, and its best line, as best so far. */
c906108c
SS
1779
1780 if (prev && (!best || prev->pc > best->pc))
1781 {
1782 best = prev;
1783 best_symtab = s;
1784 /* If another line is in the linetable, and its PC is closer
1785 than the best_end we currently have, take it as best_end. */
1786 if (i < len && (best_end == 0 || best_end > item->pc))
1787 best_end = item->pc;
1788 }
1789 }
1790
1791 if (!best_symtab)
1792 {
1793 if (!alt_symtab)
1794 { /* If we didn't find any line # info, just
1795 return zeros. */
1796 val.pc = pc;
1797 }
1798 else
1799 {
1800 val.symtab = alt_symtab;
1801 val.line = alt->line - 1;
1802
1803 /* Don't return line 0, that means that we didn't find the line. */
c5aa993b
JM
1804 if (val.line == 0)
1805 ++val.line;
c906108c
SS
1806
1807 val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1808 val.end = alt->pc;
1809 }
1810 }
1811 else
1812 {
1813 val.symtab = best_symtab;
1814 val.line = best->line;
1815 val.pc = best->pc;
1816 if (best_end && (!alt || best_end < alt->pc))
1817 val.end = best_end;
1818 else if (alt)
1819 val.end = alt->pc;
1820 else
1821 val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1822 }
1823 val.section = section;
1824 return val;
1825}
1826
1827/* Backward compatibility (no section) */
1828
1829struct symtab_and_line
1830find_pc_line (pc, notcurrent)
1831 CORE_ADDR pc;
1832 int notcurrent;
1833{
c5aa993b 1834 asection *section;
c906108c
SS
1835
1836 section = find_pc_overlay (pc);
1837 if (pc_in_unmapped_range (pc, section))
1838 pc = overlay_mapped_address (pc, section);
1839 return find_pc_sect_line (pc, section, notcurrent);
1840}
c906108c 1841\f
c5aa993b 1842
a14ed312 1843static struct symtab *find_line_symtab (struct symtab *, int, int *, int *);
c906108c
SS
1844
1845/* Find line number LINE in any symtab whose name is the same as
1846 SYMTAB.
1847
1848 If found, return the symtab that contains the linetable in which it was
1849 found, set *INDEX to the index in the linetable of the best entry
1850 found, and set *EXACT_MATCH nonzero if the value returned is an
1851 exact match.
1852
1853 If not found, return NULL. */
1854
c5aa993b 1855static struct symtab *
c906108c
SS
1856find_line_symtab (symtab, line, index, exact_match)
1857 struct symtab *symtab;
1858 int line;
1859 int *index;
1860 int *exact_match;
1861{
1862 int exact;
1863
1864 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
1865 so far seen. */
1866
1867 int best_index;
1868 struct linetable *best_linetable;
1869 struct symtab *best_symtab;
1870
1871 /* First try looking it up in the given symtab. */
1872 best_linetable = LINETABLE (symtab);
1873 best_symtab = symtab;
1874 best_index = find_line_common (best_linetable, line, &exact);
1875 if (best_index < 0 || !exact)
1876 {
1877 /* Didn't find an exact match. So we better keep looking for
c5aa993b
JM
1878 another symtab with the same name. In the case of xcoff,
1879 multiple csects for one source file (produced by IBM's FORTRAN
1880 compiler) produce multiple symtabs (this is unavoidable
1881 assuming csects can be at arbitrary places in memory and that
1882 the GLOBAL_BLOCK of a symtab has a begin and end address). */
c906108c
SS
1883
1884 /* BEST is the smallest linenumber > LINE so far seen,
c5aa993b
JM
1885 or 0 if none has been seen so far.
1886 BEST_INDEX and BEST_LINETABLE identify the item for it. */
c906108c
SS
1887 int best;
1888
1889 struct objfile *objfile;
1890 struct symtab *s;
1891
1892 if (best_index >= 0)
1893 best = best_linetable->item[best_index].line;
1894 else
1895 best = 0;
1896
1897 ALL_SYMTABS (objfile, s)
c5aa993b
JM
1898 {
1899 struct linetable *l;
1900 int ind;
c906108c 1901
c5aa993b
JM
1902 if (!STREQ (symtab->filename, s->filename))
1903 continue;
1904 l = LINETABLE (s);
1905 ind = find_line_common (l, line, &exact);
1906 if (ind >= 0)
1907 {
1908 if (exact)
1909 {
1910 best_index = ind;
1911 best_linetable = l;
1912 best_symtab = s;
1913 goto done;
1914 }
1915 if (best == 0 || l->item[ind].line < best)
1916 {
1917 best = l->item[ind].line;
1918 best_index = ind;
1919 best_linetable = l;
1920 best_symtab = s;
1921 }
1922 }
1923 }
c906108c 1924 }
c5aa993b 1925done:
c906108c
SS
1926 if (best_index < 0)
1927 return NULL;
1928
1929 if (index)
1930 *index = best_index;
1931 if (exact_match)
1932 *exact_match = exact;
1933
1934 return best_symtab;
1935}
1936\f
1937/* Set the PC value for a given source file and line number and return true.
1938 Returns zero for invalid line number (and sets the PC to 0).
1939 The source file is specified with a struct symtab. */
1940
1941int
1942find_line_pc (symtab, line, pc)
1943 struct symtab *symtab;
1944 int line;
1945 CORE_ADDR *pc;
1946{
1947 struct linetable *l;
1948 int ind;
1949
1950 *pc = 0;
1951 if (symtab == 0)
1952 return 0;
1953
1954 symtab = find_line_symtab (symtab, line, &ind, NULL);
1955 if (symtab != NULL)
1956 {
1957 l = LINETABLE (symtab);
1958 *pc = l->item[ind].pc;
1959 return 1;
1960 }
1961 else
1962 return 0;
1963}
1964
1965/* Find the range of pc values in a line.
1966 Store the starting pc of the line into *STARTPTR
1967 and the ending pc (start of next line) into *ENDPTR.
1968 Returns 1 to indicate success.
1969 Returns 0 if could not find the specified line. */
1970
1971int
1972find_line_pc_range (sal, startptr, endptr)
1973 struct symtab_and_line sal;
1974 CORE_ADDR *startptr, *endptr;
1975{
1976 CORE_ADDR startaddr;
1977 struct symtab_and_line found_sal;
1978
1979 startaddr = sal.pc;
c5aa993b 1980 if (startaddr == 0 && !find_line_pc (sal.symtab, sal.line, &startaddr))
c906108c
SS
1981 return 0;
1982
1983 /* This whole function is based on address. For example, if line 10 has
1984 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
1985 "info line *0x123" should say the line goes from 0x100 to 0x200
1986 and "info line *0x355" should say the line goes from 0x300 to 0x400.
1987 This also insures that we never give a range like "starts at 0x134
1988 and ends at 0x12c". */
1989
1990 found_sal = find_pc_sect_line (startaddr, sal.section, 0);
1991 if (found_sal.line != sal.line)
1992 {
1993 /* The specified line (sal) has zero bytes. */
1994 *startptr = found_sal.pc;
1995 *endptr = found_sal.pc;
1996 }
1997 else
1998 {
1999 *startptr = found_sal.pc;
2000 *endptr = found_sal.end;
2001 }
2002 return 1;
2003}
2004
2005/* Given a line table and a line number, return the index into the line
2006 table for the pc of the nearest line whose number is >= the specified one.
2007 Return -1 if none is found. The value is >= 0 if it is an index.
2008
2009 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
2010
2011static int
2012find_line_common (l, lineno, exact_match)
2013 register struct linetable *l;
2014 register int lineno;
2015 int *exact_match;
2016{
2017 register int i;
2018 register int len;
2019
2020 /* BEST is the smallest linenumber > LINENO so far seen,
2021 or 0 if none has been seen so far.
2022 BEST_INDEX identifies the item for it. */
2023
2024 int best_index = -1;
2025 int best = 0;
2026
2027 if (lineno <= 0)
2028 return -1;
2029 if (l == 0)
2030 return -1;
2031
2032 len = l->nitems;
2033 for (i = 0; i < len; i++)
2034 {
2035 register struct linetable_entry *item = &(l->item[i]);
2036
2037 if (item->line == lineno)
2038 {
2039 /* Return the first (lowest address) entry which matches. */
2040 *exact_match = 1;
2041 return i;
2042 }
2043
2044 if (item->line > lineno && (best == 0 || item->line < best))
2045 {
2046 best = item->line;
2047 best_index = i;
2048 }
2049 }
2050
2051 /* If we got here, we didn't get an exact match. */
2052
2053 *exact_match = 0;
2054 return best_index;
2055}
2056
2057int
2058find_pc_line_pc_range (pc, startptr, endptr)
2059 CORE_ADDR pc;
2060 CORE_ADDR *startptr, *endptr;
2061{
2062 struct symtab_and_line sal;
2063 sal = find_pc_line (pc, 0);
2064 *startptr = sal.pc;
2065 *endptr = sal.end;
2066 return sal.symtab != 0;
2067}
2068
2069/* Given a function symbol SYM, find the symtab and line for the start
2070 of the function.
2071 If the argument FUNFIRSTLINE is nonzero, we want the first line
2072 of real code inside the function. */
2073
2074static struct symtab_and_line
a14ed312 2075find_function_start_sal (struct symbol *sym, int);
c906108c
SS
2076
2077static struct symtab_and_line
2078find_function_start_sal (sym, funfirstline)
2079 struct symbol *sym;
2080 int funfirstline;
2081{
2082 CORE_ADDR pc;
2083 struct symtab_and_line sal;
2084
2085 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
2086 fixup_symbol_section (sym, NULL);
2087 if (funfirstline)
c5aa993b 2088 { /* skip "first line" of function (which is actually its prologue) */
c906108c
SS
2089 asection *section = SYMBOL_BFD_SECTION (sym);
2090 /* If function is in an unmapped overlay, use its unmapped LMA
c5aa993b 2091 address, so that SKIP_PROLOGUE has something unique to work on */
c906108c
SS
2092 if (section_is_overlay (section) &&
2093 !section_is_mapped (section))
2094 pc = overlay_unmapped_address (pc, section);
2095
2096 pc += FUNCTION_START_OFFSET;
b83266a0 2097 pc = SKIP_PROLOGUE (pc);
c906108c
SS
2098
2099 /* For overlays, map pc back into its mapped VMA range */
2100 pc = overlay_mapped_address (pc, section);
2101 }
2102 sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
2103
2104#ifdef PROLOGUE_FIRSTLINE_OVERLAP
2105 /* Convex: no need to suppress code on first line, if any */
2106 sal.pc = pc;
2107#else
2108 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
2109 line is still part of the same function. */
2110 if (sal.pc != pc
2111 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= sal.end
2112 && sal.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym)))
2113 {
2114 /* First pc of next line */
2115 pc = sal.end;
2116 /* Recalculate the line number (might not be N+1). */
2117 sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
2118 }
2119 sal.pc = pc;
2120#endif
2121
2122 return sal;
2123}
2124\f
2125/* If P is of the form "operator[ \t]+..." where `...' is
2126 some legitimate operator text, return a pointer to the
2127 beginning of the substring of the operator text.
2128 Otherwise, return "". */
2129char *
2130operator_chars (p, end)
2131 char *p;
2132 char **end;
2133{
2134 *end = "";
2135 if (strncmp (p, "operator", 8))
2136 return *end;
2137 p += 8;
2138
2139 /* Don't get faked out by `operator' being part of a longer
2140 identifier. */
c5aa993b 2141 if (isalpha (*p) || *p == '_' || *p == '$' || *p == '\0')
c906108c
SS
2142 return *end;
2143
2144 /* Allow some whitespace between `operator' and the operator symbol. */
2145 while (*p == ' ' || *p == '\t')
2146 p++;
2147
2148 /* Recognize 'operator TYPENAME'. */
2149
c5aa993b 2150 if (isalpha (*p) || *p == '_' || *p == '$')
c906108c 2151 {
c5aa993b
JM
2152 register char *q = p + 1;
2153 while (isalnum (*q) || *q == '_' || *q == '$')
c906108c
SS
2154 q++;
2155 *end = q;
2156 return p;
2157 }
2158
2159 switch (*p)
2160 {
2161 case '!':
2162 case '=':
2163 case '*':
2164 case '/':
2165 case '%':
2166 case '^':
2167 if (p[1] == '=')
c5aa993b 2168 *end = p + 2;
c906108c 2169 else
c5aa993b 2170 *end = p + 1;
c906108c
SS
2171 return p;
2172 case '<':
2173 case '>':
2174 case '+':
2175 case '-':
2176 case '&':
2177 case '|':
2178 if (p[1] == '=' || p[1] == p[0])
c5aa993b 2179 *end = p + 2;
c906108c 2180 else
c5aa993b 2181 *end = p + 1;
c906108c
SS
2182 return p;
2183 case '~':
2184 case ',':
c5aa993b 2185 *end = p + 1;
c906108c
SS
2186 return p;
2187 case '(':
2188 if (p[1] != ')')
2189 error ("`operator ()' must be specified without whitespace in `()'");
c5aa993b 2190 *end = p + 2;
c906108c
SS
2191 return p;
2192 case '?':
2193 if (p[1] != ':')
2194 error ("`operator ?:' must be specified without whitespace in `?:'");
c5aa993b 2195 *end = p + 2;
c906108c
SS
2196 return p;
2197 case '[':
2198 if (p[1] != ']')
2199 error ("`operator []' must be specified without whitespace in `[]'");
c5aa993b 2200 *end = p + 2;
c906108c
SS
2201 return p;
2202 default:
2203 error ("`operator %s' not supported", p);
2204 break;
2205 }
2206 *end = "";
2207 return *end;
2208}
2209
2210/* Return the number of methods described for TYPE, including the
2211 methods from types it derives from. This can't be done in the symbol
2212 reader because the type of the baseclass might still be stubbed
2213 when the definition of the derived class is parsed. */
2214
a14ed312 2215static int total_number_of_methods (struct type *type);
c906108c
SS
2216
2217static int
2218total_number_of_methods (type)
2219 struct type *type;
2220{
2221 int n;
2222 int count;
2223
2224 CHECK_TYPEDEF (type);
2225 if (TYPE_CPLUS_SPECIFIC (type) == NULL)
2226 return 0;
2227 count = TYPE_NFN_FIELDS_TOTAL (type);
2228
2229 for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
2230 count += total_number_of_methods (TYPE_BASECLASS (type, n));
2231
2232 return count;
2233}
2234
2235/* Recursive helper function for decode_line_1.
2236 Look for methods named NAME in type T.
2237 Return number of matches.
2238 Put matches in SYM_ARR, which should have been allocated with
2239 a size of total_number_of_methods (T) * sizeof (struct symbol *).
2240 Note that this function is g++ specific. */
2241
2242static int
2243find_methods (t, name, sym_arr)
2244 struct type *t;
2245 char *name;
2246 struct symbol **sym_arr;
2247{
2248 int i1 = 0;
2249 int ibase;
2250 struct symbol *sym_class;
2251 char *class_name = type_name_no_tag (t);
2252
2253 /* Ignore this class if it doesn't have a name. This is ugly, but
2254 unless we figure out how to get the physname without the name of
2255 the class, then the loop can't do any good. */
2256 if (class_name
2257 && (sym_class = lookup_symbol (class_name,
c5aa993b 2258 (struct block *) NULL,
c906108c 2259 STRUCT_NAMESPACE,
c5aa993b
JM
2260 (int *) NULL,
2261 (struct symtab **) NULL)))
c906108c
SS
2262 {
2263 int method_counter;
2264
2265 /* FIXME: Shouldn't this just be CHECK_TYPEDEF (t)? */
2266 t = SYMBOL_TYPE (sym_class);
2267
2268 /* Loop over each method name. At this level, all overloads of a name
c5aa993b
JM
2269 are counted as a single name. There is an inner loop which loops over
2270 each overload. */
c906108c
SS
2271
2272 for (method_counter = TYPE_NFN_FIELDS (t) - 1;
2273 method_counter >= 0;
2274 --method_counter)
2275 {
2276 int field_counter;
2277 char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
2278 char dem_opname[64];
2279
c5aa993b 2280 if (strncmp (method_name, "__", 2) == 0 ||
c906108c
SS
2281 strncmp (method_name, "op", 2) == 0 ||
2282 strncmp (method_name, "type", 4) == 0)
c5aa993b 2283 {
c906108c 2284 if (cplus_demangle_opname (method_name, dem_opname, DMGL_ANSI))
c5aa993b 2285 method_name = dem_opname;
c906108c 2286 else if (cplus_demangle_opname (method_name, dem_opname, 0))
c5aa993b
JM
2287 method_name = dem_opname;
2288 }
c906108c
SS
2289
2290 if (STREQ (name, method_name))
2291 /* Find all the overloaded methods with that name. */
2292 for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
2293 field_counter >= 0;
2294 --field_counter)
2295 {
2296 struct fn_field *f;
2297 char *phys_name;
2298
2299 f = TYPE_FN_FIELDLIST1 (t, method_counter);
2300
2301 if (TYPE_FN_FIELD_STUB (f, field_counter))
2302 {
2303 char *tmp_name;
2304
2305 tmp_name = gdb_mangle_name (t,
c5aa993b
JM
2306 method_counter,
2307 field_counter);
c906108c
SS
2308 phys_name = alloca (strlen (tmp_name) + 1);
2309 strcpy (phys_name, tmp_name);
2310 free (tmp_name);
2311 }
2312 else
2313 phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
2314
2315 /* Destructor is handled by caller, dont add it to the list */
2316 if (DESTRUCTOR_PREFIX_P (phys_name))
2317 continue;
2318
2319 sym_arr[i1] = lookup_symbol (phys_name,
2320 NULL, VAR_NAMESPACE,
2321 (int *) NULL,
2322 (struct symtab **) NULL);
2323 if (sym_arr[i1])
2324 i1++;
2325 else
2326 {
2327 /* This error message gets printed, but the method
2328 still seems to be found
2329 fputs_filtered("(Cannot find method ", gdb_stdout);
2330 fprintf_symbol_filtered (gdb_stdout, phys_name,
2331 language_cplus,
2332 DMGL_PARAMS | DMGL_ANSI);
2333 fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
c5aa993b 2334 */
c906108c
SS
2335 }
2336 }
2337 }
2338 }
2339
2340 /* Only search baseclasses if there is no match yet, since names in
2341 derived classes override those in baseclasses.
2342
2343 FIXME: The above is not true; it is only true of member functions
2344 if they have the same number of arguments (??? - section 13.1 of the
2345 ARM says the function members are not in the same scope but doesn't
2346 really spell out the rules in a way I understand. In any case, if
2347 the number of arguments differ this is a case in which we can overload
2348 rather than hiding without any problem, and gcc 2.4.5 does overload
2349 rather than hiding in this case). */
2350
2351 if (i1 == 0)
2352 for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
2353 i1 += find_methods (TYPE_BASECLASS (t, ibase), name, sym_arr + i1);
2354
2355 return i1;
2356}
2357
2358/* Helper function for decode_line_1.
2359 Build a canonical line spec in CANONICAL if it is non-NULL and if
2360 the SAL has a symtab.
2361 If SYMNAME is non-NULL the canonical line spec is `filename:symname'.
2362 If SYMNAME is NULL the line number from SAL is used and the canonical
2363 line spec is `filename:linenum'. */
2364
2365static void
2366build_canonical_line_spec (sal, symname, canonical)
2367 struct symtab_and_line *sal;
2368 char *symname;
2369 char ***canonical;
2370{
2371 char **canonical_arr;
2372 char *canonical_name;
2373 char *filename;
2374 struct symtab *s = sal->symtab;
2375
c5aa993b
JM
2376 if (s == (struct symtab *) NULL
2377 || s->filename == (char *) NULL
2378 || canonical == (char ***) NULL)
c906108c 2379 return;
c5aa993b 2380
c906108c
SS
2381 canonical_arr = (char **) xmalloc (sizeof (char *));
2382 *canonical = canonical_arr;
2383
2384 filename = s->filename;
2385 if (symname != NULL)
2386 {
2387 canonical_name = xmalloc (strlen (filename) + strlen (symname) + 2);
2388 sprintf (canonical_name, "%s:%s", filename, symname);
2389 }
2390 else
2391 {
2392 canonical_name = xmalloc (strlen (filename) + 30);
2393 sprintf (canonical_name, "%s:%d", filename, sal->line);
2394 }
2395 canonical_arr[0] = canonical_name;
2396}
2397
da59e081
JM
2398
2399
2400/* Find an instance of the character C in the string S that is outside
2401 of all parenthesis pairs, single-quoted strings, and double-quoted
2402 strings. */
2403static char *
2404find_toplevel_char (char *s, char c)
2405{
2406 int quoted = 0; /* zero if we're not in quotes;
2407 '"' if we're in a double-quoted string;
2408 '\'' if we're in a single-quoted string. */
2409 int depth = 0; /* number of unclosed parens we've seen */
2410 char *scan;
2411
2412 for (scan = s; *scan; scan++)
2413 {
2414 if (quoted)
2415 {
2416 if (*scan == quoted)
2417 quoted = 0;
2418 else if (*scan == '\\' && *(scan + 1))
2419 scan++;
2420 }
2421 else if (*scan == c && ! quoted && depth == 0)
2422 return scan;
2423 else if (*scan == '"' || *scan == '\'')
2424 quoted = *scan;
2425 else if (*scan == '(')
2426 depth++;
2427 else if (*scan == ')' && depth > 0)
2428 depth--;
2429 }
2430
2431 return 0;
2432}
2433
2434
c906108c
SS
2435/* Parse a string that specifies a line number.
2436 Pass the address of a char * variable; that variable will be
2437 advanced over the characters actually parsed.
2438
2439 The string can be:
2440
2441 LINENUM -- that line number in current file. PC returned is 0.
2442 FILE:LINENUM -- that line in that file. PC returned is 0.
2443 FUNCTION -- line number of openbrace of that function.
c5aa993b 2444 PC returned is the start of the function.
c906108c 2445 VARIABLE -- line number of definition of that variable.
c5aa993b 2446 PC returned is 0.
c906108c
SS
2447 FILE:FUNCTION -- likewise, but prefer functions in that file.
2448 *EXPR -- line in which address EXPR appears.
2449
085dd6e6
JM
2450 This may all be followed by an "if EXPR", which we ignore.
2451
c906108c
SS
2452 FUNCTION may be an undebuggable function found in minimal symbol table.
2453
2454 If the argument FUNFIRSTLINE is nonzero, we want the first line
2455 of real code inside a function when a function is specified, and it is
2456 not OK to specify a variable or type to get its line number.
2457
2458 DEFAULT_SYMTAB specifies the file to use if none is specified.
2459 It defaults to current_source_symtab.
2460 DEFAULT_LINE specifies the line number to use for relative
2461 line numbers (that start with signs). Defaults to current_source_line.
2462 If CANONICAL is non-NULL, store an array of strings containing the canonical
2463 line specs there if necessary. Currently overloaded member functions and
2464 line numbers or static functions without a filename yield a canonical
2465 line spec. The array and the line spec strings are allocated on the heap,
2466 it is the callers responsibility to free them.
2467
2468 Note that it is possible to return zero for the symtab
2469 if no file is validly specified. Callers must check that.
2470 Also, the line number returned may be invalid. */
2471
2472/* We allow single quotes in various places. This is a hideous
2473 kludge, which exists because the completer can't yet deal with the
2474 lack of single quotes. FIXME: write a linespec_completer which we
2475 can use as appropriate instead of make_symbol_completion_list. */
2476
2477struct symtabs_and_lines
2478decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
2479 char **argptr;
2480 int funfirstline;
2481 struct symtab *default_symtab;
2482 int default_line;
2483 char ***canonical;
2484{
2485 struct symtabs_and_lines values;
2486#ifdef HPPA_COMPILER_BUG
2487 /* FIXME: The native HP 9000/700 compiler has a bug which appears
2488 when optimizing this file with target i960-vxworks. I haven't
2489 been able to construct a simple test case. The problem is that
2490 in the second call to SKIP_PROLOGUE below, the compiler somehow
2491 does not realize that the statement val = find_pc_line (...) will
2492 change the values of the fields of val. It extracts the elements
2493 into registers at the top of the block, and does not update the
2494 registers after the call to find_pc_line. You can check this by
2495 inserting a printf at the end of find_pc_line to show what values
2496 it is returning for val.pc and val.end and another printf after
2497 the call to see what values the function actually got (remember,
2498 this is compiling with cc -O, with this patch removed). You can
2499 also examine the assembly listing: search for the second call to
2500 skip_prologue; the LDO statement before the next call to
2501 find_pc_line loads the address of the structure which
2502 find_pc_line will return; if there is a LDW just before the LDO,
2503 which fetches an element of the structure, then the compiler
2504 still has the bug.
2505
2506 Setting val to volatile avoids the problem. We must undef
2507 volatile, because the HPPA native compiler does not define
2508 __STDC__, although it does understand volatile, and so volatile
2509 will have been defined away in defs.h. */
2510#undef volatile
2511 volatile struct symtab_and_line val;
c5aa993b 2512#define volatile /*nothing */
c906108c
SS
2513#else
2514 struct symtab_and_line val;
2515#endif
2516 register char *p, *p1;
2517 char *q, *pp, *ii, *p2;
2518#if 0
2519 char *q1;
2520#endif
2521 register struct symtab *s;
2522
2523 register struct symbol *sym;
2524 /* The symtab that SYM was found in. */
2525 struct symtab *sym_symtab;
2526
2527 register CORE_ADDR pc;
2528 register struct minimal_symbol *msymbol;
2529 char *copy;
2530 struct symbol *sym_class;
2531 int i1;
2532 int is_quoted;
cce74817 2533 int is_quote_enclosed;
c5aa993b 2534 int has_parens;
c906108c 2535 int has_if = 0;
cce74817 2536 int has_comma = 0;
c906108c
SS
2537 struct symbol **sym_arr;
2538 struct type *t;
2539 char *saved_arg = *argptr;
2540 extern char *gdb_completer_quote_characters;
c5aa993b
JM
2541
2542 INIT_SAL (&val); /* initialize to zeroes */
c906108c
SS
2543
2544 /* Defaults have defaults. */
2545
2546 if (default_symtab == 0)
2547 {
2548 default_symtab = current_source_symtab;
2549 default_line = current_source_line;
2550 }
2551
2552 /* See if arg is *PC */
2553
2554 if (**argptr == '*')
2555 {
2556 (*argptr)++;
2557 pc = parse_and_eval_address_1 (argptr);
2558
2559 values.sals = (struct symtab_and_line *)
2560 xmalloc (sizeof (struct symtab_and_line));
2561
2562 values.nelts = 1;
2563 values.sals[0] = find_pc_line (pc, 0);
2564 values.sals[0].pc = pc;
2565 values.sals[0].section = find_pc_overlay (pc);
2566
2567 return values;
2568 }
2569
2570 /* 'has_if' is for the syntax:
2571 * (gdb) break foo if (a==b)
2572 */
c5aa993b
JM
2573 if ((ii = strstr (*argptr, " if ")) != NULL ||
2574 (ii = strstr (*argptr, "\tif ")) != NULL ||
2575 (ii = strstr (*argptr, " if\t")) != NULL ||
2576 (ii = strstr (*argptr, "\tif\t")) != NULL ||
2577 (ii = strstr (*argptr, " if(")) != NULL ||
2578 (ii = strstr (*argptr, "\tif( ")) != NULL)
c906108c
SS
2579 has_if = 1;
2580 /* Temporarily zap out "if (condition)" to not
2581 * confuse the parenthesis-checking code below.
2582 * This is undone below. Do not change ii!!
2583 */
c5aa993b
JM
2584 if (has_if)
2585 {
2586 *ii = '\0';
2587 }
c906108c
SS
2588
2589 /* Set various flags.
2590 * 'has_parens' is important for overload checking, where
2591 * we allow things like:
2592 * (gdb) break c::f(int)
2593 */
2594
2595 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
2596
2597 is_quoted = (**argptr
2598 && strchr (gdb_completer_quote_characters, **argptr) != NULL);
2599
2600 has_parens = ((pp = strchr (*argptr, '(')) != NULL
c2c6d25f 2601 && (pp = strrchr (pp, ')')) != NULL);
c906108c
SS
2602
2603 /* Now that we're safely past the has_parens check,
2604 * put back " if (condition)" so outer layers can see it
2605 */
2606 if (has_if)
2607 *ii = ' ';
2608
cce74817
JM
2609 /* Maybe we were called with a line range FILENAME:LINENUM,FILENAME:LINENUM
2610 and we must isolate the first half. Outer layers will call again later
da59e081
JM
2611 for the second half.
2612
2613 Don't count commas that appear in argument lists of overloaded
2614 functions, or in quoted strings. It's stupid to go to this much
2615 trouble when the rest of the function is such an obvious roach hotel. */
2616 ii = find_toplevel_char (*argptr, ',');
2617 has_comma = (ii != 0);
2618
cce74817
JM
2619 /* Temporarily zap out second half to not
2620 * confuse the code below.
2621 * This is undone below. Do not change ii!!
2622 */
c5aa993b
JM
2623 if (has_comma)
2624 {
2625 *ii = '\0';
2626 }
cce74817 2627
c906108c
SS
2628 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
2629 /* May also be CLASS::MEMBER, or NAMESPACE::NAME */
2630 /* Look for ':', but ignore inside of <> */
2631
2632 s = NULL;
cce74817
JM
2633 p = *argptr;
2634 if (p[0] == '"')
2635 {
2636 is_quote_enclosed = 1;
2637 p++;
2638 }
2639 else
c5aa993b
JM
2640 is_quote_enclosed = 0;
2641 for (; *p; p++)
c906108c 2642 {
c5aa993b 2643 if (p[0] == '<')
c906108c 2644 {
c5aa993b
JM
2645 char *temp_end = find_template_name_end (p);
2646 if (!temp_end)
2647 error ("malformed template specification in command");
2648 p = temp_end;
c906108c 2649 }
cce74817
JM
2650 /* Check for the end of the first half of the linespec. End of line,
2651 a tab, a double colon or the last single colon, or a space. But
2652 if enclosed in double quotes we do not break on enclosed spaces */
2653 if (!*p
c5aa993b
JM
2654 || p[0] == '\t'
2655 || ((p[0] == ':')
2656 && ((p[1] == ':') || (strchr (p + 1, ':') == NULL)))
2657 || ((p[0] == ' ') && !is_quote_enclosed))
2658 break;
2659 if (p[0] == '.' && strchr (p, ':') == NULL) /* Java qualified method. */
c906108c
SS
2660 {
2661 /* Find the *last* '.', since the others are package qualifiers. */
c5aa993b 2662 for (p1 = p; *p1; p1++)
c906108c
SS
2663 {
2664 if (*p1 == '.')
2665 p = p1;
2666 }
2667 break;
2668 }
2669 }
c5aa993b
JM
2670 while (p[0] == ' ' || p[0] == '\t')
2671 p++;
da59e081 2672
cce74817 2673 /* if the closing double quote was left at the end, remove it */
da59e081
JM
2674 if (is_quote_enclosed)
2675 {
2676 char *closing_quote = strchr (p, '"');
2677 if (closing_quote && closing_quote[1] == '\0')
2678 *closing_quote = '\0';
2679 }
cce74817
JM
2680
2681 /* Now that we've safely parsed the first half,
2682 * put back ',' so outer layers can see it
2683 */
2684 if (has_comma)
2685 *ii = ',';
c906108c
SS
2686
2687 if ((p[0] == ':' || p[0] == '.') && !has_parens)
2688 {
2689 /* C++ */
2690 /* ... or Java */
c5aa993b
JM
2691 if (is_quoted)
2692 *argptr = *argptr + 1;
2693 if (p[0] == '.' || p[1] == ':')
c906108c 2694 {
c5aa993b
JM
2695 char *saved_arg2 = *argptr;
2696 char *temp_end;
2697 /* First check for "global" namespace specification,
2698 of the form "::foo". If found, skip over the colons
2699 and jump to normal symbol processing */
2700 if ((*argptr == p) || (p[-1] == ' ') || (p[-1] == '\t'))
2701 saved_arg2 += 2;
2702
2703 /* We have what looks like a class or namespace
2704 scope specification (A::B), possibly with many
2705 levels of namespaces or classes (A::B::C::D).
2706
2707 Some versions of the HP ANSI C++ compiler (as also possibly
2708 other compilers) generate class/function/member names with
2709 embedded double-colons if they are inside namespaces. To
2710 handle this, we loop a few times, considering larger and
2711 larger prefixes of the string as though they were single
2712 symbols. So, if the initially supplied string is
2713 A::B::C::D::foo, we have to look up "A", then "A::B",
2714 then "A::B::C", then "A::B::C::D", and finally
2715 "A::B::C::D::foo" as single, monolithic symbols, because
2716 A, B, C or D may be namespaces.
2717
2718 Note that namespaces can nest only inside other
2719 namespaces, and not inside classes. So we need only
2720 consider *prefixes* of the string; there is no need to look up
2721 "B::C" separately as a symbol in the previous example. */
2722
2723 p2 = p; /* save for restart */
2724 while (1)
2725 {
2726 /* Extract the class name. */
2727 p1 = p;
2728 while (p != *argptr && p[-1] == ' ')
2729 --p;
2730 copy = (char *) alloca (p - *argptr + 1);
2731 memcpy (copy, *argptr, p - *argptr);
2732 copy[p - *argptr] = 0;
2733
2734 /* Discard the class name from the arg. */
2735 p = p1 + (p1[0] == ':' ? 2 : 1);
2736 while (*p == ' ' || *p == '\t')
2737 p++;
2738 *argptr = p;
2739
2740 sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0,
2741 (struct symtab **) NULL);
2742
2743 if (sym_class &&
2744 (t = check_typedef (SYMBOL_TYPE (sym_class)),
2745 (TYPE_CODE (t) == TYPE_CODE_STRUCT
2746 || TYPE_CODE (t) == TYPE_CODE_UNION)))
c906108c 2747 {
c5aa993b
JM
2748 /* Arg token is not digits => try it as a function name
2749 Find the next token(everything up to end or next blank). */
2750 if (**argptr
2751 && strchr (gdb_completer_quote_characters, **argptr) != NULL)
2752 {
2753 p = skip_quoted (*argptr);
2754 *argptr = *argptr + 1;
2755 }
2756 else
2757 {
2758 p = *argptr;
2759 while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p != ':')
2760 p++;
2761 }
2762/*
2763 q = operator_chars (*argptr, &q1);
2764 if (q1 - q)
2765 {
2766 char *opname;
2767 char *tmp = alloca (q1 - q + 1);
2768 memcpy (tmp, q, q1 - q);
2769 tmp[q1 - q] = '\0';
2770 opname = cplus_mangle_opname (tmp, DMGL_ANSI);
2771 if (opname == NULL)
2772 {
2773 error_begin ();
2774 printf_filtered ("no mangling for \"%s\"\n", tmp);
2775 cplusplus_hint (saved_arg);
2776 return_to_top_level (RETURN_ERROR);
2777 }
2778 copy = (char*) alloca (3 + strlen(opname));
2779 sprintf (copy, "__%s", opname);
2780 p = q1;
2781 }
2782 else
2783 */
2784 {
2785 copy = (char *) alloca (p - *argptr + 1);
2786 memcpy (copy, *argptr, p - *argptr);
2787 copy[p - *argptr] = '\0';
2788 if (p != *argptr
2789 && copy[p - *argptr - 1]
2790 && strchr (gdb_completer_quote_characters,
2791 copy[p - *argptr - 1]) != NULL)
2792 copy[p - *argptr - 1] = '\0';
2793 }
2794
2795 /* no line number may be specified */
2796 while (*p == ' ' || *p == '\t')
2797 p++;
2798 *argptr = p;
2799
2800 sym = 0;
2801 i1 = 0; /* counter for the symbol array */
2802 sym_arr = (struct symbol **) alloca (total_number_of_methods (t)
2803 * sizeof (struct symbol *));
2804
2805 if (destructor_name_p (copy, t))
c906108c 2806 {
c5aa993b
JM
2807 /* Destructors are a special case. */
2808 int m_index, f_index;
2809
2810 if (get_destructor_fn_field (t, &m_index, &f_index))
2811 {
2812 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, m_index);
2813
2814 sym_arr[i1] =
2815 lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, f_index),
2816 NULL, VAR_NAMESPACE, (int *) NULL,
2817 (struct symtab **) NULL);
2818 if (sym_arr[i1])
2819 i1++;
2820 }
2821 }
2822 else
2823 i1 = find_methods (t, copy, sym_arr);
2824 if (i1 == 1)
2825 {
2826 /* There is exactly one field with that name. */
2827 sym = sym_arr[0];
2828
2829 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
2830 {
2831 values.sals = (struct symtab_and_line *)
2832 xmalloc (sizeof (struct symtab_and_line));
2833 values.nelts = 1;
2834 values.sals[0] = find_function_start_sal (sym,
2835 funfirstline);
2836 }
2837 else
2838 {
2839 values.nelts = 0;
2840 }
2841 return values;
2842 }
2843 if (i1 > 0)
2844 {
2845 /* There is more than one field with that name
2846 (overloaded). Ask the user which one to use. */
2847 return decode_line_2 (sym_arr, i1, funfirstline, canonical);
2848 }
2849 else
2850 {
2851 char *tmp;
2852
2853 if (OPNAME_PREFIX_P (copy))
2854 {
2855 tmp = (char *) alloca (strlen (copy + 3) + 9);
2856 strcpy (tmp, "operator ");
2857 strcat (tmp, copy + 3);
2858 }
2859 else
2860 tmp = copy;
c906108c 2861 error_begin ();
c5aa993b
JM
2862 if (tmp[0] == '~')
2863 printf_filtered
2864 ("the class `%s' does not have destructor defined\n",
2865 SYMBOL_SOURCE_NAME (sym_class));
2866 else
2867 printf_filtered
2868 ("the class %s does not have any method named %s\n",
2869 SYMBOL_SOURCE_NAME (sym_class), tmp);
c906108c
SS
2870 cplusplus_hint (saved_arg);
2871 return_to_top_level (RETURN_ERROR);
2872 }
c906108c 2873 }
c5aa993b
JM
2874
2875 /* Move pointer up to next possible class/namespace token */
2876 p = p2 + 1; /* restart with old value +1 */
2877 /* Move pointer ahead to next double-colon */
2878 while (*p && (p[0] != ' ') && (p[0] != '\t') && (p[0] != '\''))
2879 {
2880 if (p[0] == '<')
2881 {
2882 temp_end = find_template_name_end (p);
2883 if (!temp_end)
2884 error ("malformed template specification in command");
2885 p = temp_end;
2886 }
2887 else if ((p[0] == ':') && (p[1] == ':'))
2888 break; /* found double-colon */
2889 else
2890 p++;
2891 }
2892
2893 if (*p != ':')
2894 break; /* out of the while (1) */
2895
2896 p2 = p; /* save restart for next time around */
2897 *argptr = saved_arg2; /* restore argptr */
2898 } /* while (1) */
2899
2900 /* Last chance attempt -- check entire name as a symbol */
2901 /* Use "copy" in preparation for jumping out of this block,
2902 to be consistent with usage following the jump target */
2903 copy = (char *) alloca (p - saved_arg2 + 1);
2904 memcpy (copy, saved_arg2, p - saved_arg2);
2905 /* Note: if is_quoted should be true, we snuff out quote here anyway */
2906 copy[p - saved_arg2] = '\000';
2907 /* Set argptr to skip over the name */
2908 *argptr = (*p == '\'') ? p + 1 : p;
2909 /* Look up entire name */
2910 sym = lookup_symbol (copy, 0, VAR_NAMESPACE, 0, &sym_symtab);
2911 s = (struct symtab *) 0;
2912 /* Prepare to jump: restore the " if (condition)" so outer layers see it */
2913 /* Symbol was found --> jump to normal symbol processing.
2914 Code following "symbol_found" expects "copy" to have the
2915 symbol name, "sym" to have the symbol pointer, "s" to be
2916 a specified file's symtab, and sym_symtab to be the symbol's
2917 symtab. */
2918 /* By jumping there we avoid falling through the FILE:LINE and
2919 FILE:FUNC processing stuff below */
2920 if (sym)
2921 goto symbol_found;
2922
2923 /* Couldn't find any interpretation as classes/namespaces, so give up */
2924 error_begin ();
2925 /* The quotes are important if copy is empty. */
2926 printf_filtered
2927 ("Can't find member of namespace, class, struct, or union named \"%s\"\n", copy);
2928 cplusplus_hint (saved_arg);
2929 return_to_top_level (RETURN_ERROR);
2930 }
c906108c
SS
2931 /* end of C++ */
2932
2933
2934 /* Extract the file name. */
2935 p1 = p;
c5aa993b
JM
2936 while (p != *argptr && p[-1] == ' ')
2937 --p;
2938 if ((*p == '"') && is_quote_enclosed)
2939 --p;
c906108c 2940 copy = (char *) alloca (p - *argptr + 1);
cce74817 2941 if ((**argptr == '"') && is_quote_enclosed)
c5aa993b
JM
2942 {
2943 memcpy (copy, *argptr + 1, p - *argptr - 1);
2944 /* It may have the ending quote right after the file name */
2945 if (copy[p - *argptr - 2] == '"')
2946 copy[p - *argptr - 2] = 0;
2947 else
2948 copy[p - *argptr - 1] = 0;
2949 }
cce74817 2950 else
c5aa993b
JM
2951 {
2952 memcpy (copy, *argptr, p - *argptr);
2953 copy[p - *argptr] = 0;
2954 }
c906108c
SS
2955
2956 /* Find that file's data. */
2957 s = lookup_symtab (copy);
2958 if (s == 0)
2959 {
2960 if (!have_full_symbols () && !have_partial_symbols ())
2961 error (no_symtab_msg);
2962 error ("No source file named %s.", copy);
2963 }
2964
2965 /* Discard the file name from the arg. */
2966 p = p1 + 1;
c5aa993b
JM
2967 while (*p == ' ' || *p == '\t')
2968 p++;
c906108c
SS
2969 *argptr = p;
2970 }
7a292a7a
SS
2971#if 0
2972 /* No one really seems to know why this was added. It certainly
2973 breaks the command line, though, whenever the passed
2974 name is of the form ClassName::Method. This bit of code
2975 singles out the class name, and if funfirstline is set (for
2976 example, you are setting a breakpoint at this function),
2977 you get an error. This did not occur with earlier
2978 verions, so I am ifdef'ing this out. 3/29/99 */
c5aa993b
JM
2979 else
2980 {
2981 /* Check if what we have till now is a symbol name */
2982
2983 /* We may be looking at a template instantiation such
2984 as "foo<int>". Check here whether we know about it,
2985 instead of falling through to the code below which
2986 handles ordinary function names, because that code
2987 doesn't like seeing '<' and '>' in a name -- the
2988 skip_quoted call doesn't go past them. So see if we
2989 can figure it out right now. */
2990
2991 copy = (char *) alloca (p - *argptr + 1);
2992 memcpy (copy, *argptr, p - *argptr);
2993 copy[p - *argptr] = '\000';
2994 sym = lookup_symbol (copy, 0, VAR_NAMESPACE, 0, &sym_symtab);
2995 if (sym)
2996 {
2997 /* Yes, we have a symbol; jump to symbol processing */
2998 /* Code after symbol_found expects S, SYM_SYMTAB, SYM,
2999 and COPY to be set correctly */
3000 *argptr = (*p == '\'') ? p + 1 : p;
3001 s = (struct symtab *) 0;
3002 goto symbol_found;
3003 }
3004 /* Otherwise fall out from here and go to file/line spec
3005 processing, etc. */
c906108c 3006 }
7a292a7a 3007#endif
c906108c
SS
3008
3009 /* S is specified file's symtab, or 0 if no file specified.
3010 arg no longer contains the file name. */
3011
3012 /* Check whether arg is all digits (and sign) */
3013
3014 q = *argptr;
c5aa993b
JM
3015 if (*q == '-' || *q == '+')
3016 q++;
c906108c
SS
3017 while (*q >= '0' && *q <= '9')
3018 q++;
3019
3020 if (q != *argptr && (*q == 0 || *q == ' ' || *q == '\t' || *q == ','))
3021 {
3022 /* We found a token consisting of all digits -- at least one digit. */
c5aa993b
JM
3023 enum sign
3024 {
3025 none, plus, minus
3026 }
3027 sign = none;
c906108c
SS
3028
3029 /* We might need a canonical line spec if no file was specified. */
3030 int need_canonical = (s == 0) ? 1 : 0;
3031
3032 /* This is where we need to make sure that we have good defaults.
c5aa993b
JM
3033 We must guarantee that this section of code is never executed
3034 when we are called with just a function name, since
3035 select_source_symtab calls us with such an argument */
c906108c
SS
3036
3037 if (s == 0 && default_symtab == 0)
3038 {
3039 select_source_symtab (0);
3040 default_symtab = current_source_symtab;
3041 default_line = current_source_line;
3042 }
3043
3044 if (**argptr == '+')
3045 sign = plus, (*argptr)++;
3046 else if (**argptr == '-')
3047 sign = minus, (*argptr)++;
3048 val.line = atoi (*argptr);
3049 switch (sign)
3050 {
3051 case plus:
3052 if (q == *argptr)
3053 val.line = 5;
3054 if (s == 0)
3055 val.line = default_line + val.line;
3056 break;
3057 case minus:
3058 if (q == *argptr)
3059 val.line = 15;
3060 if (s == 0)
3061 val.line = default_line - val.line;
3062 else
3063 val.line = 1;
3064 break;
3065 case none:
c5aa993b 3066 break; /* No need to adjust val.line. */
c906108c
SS
3067 }
3068
c5aa993b
JM
3069 while (*q == ' ' || *q == '\t')
3070 q++;
c906108c
SS
3071 *argptr = q;
3072 if (s == 0)
3073 s = default_symtab;
3074
3075 /* It is possible that this source file has more than one symtab,
c5aa993b
JM
3076 and that the new line number specification has moved us from the
3077 default (in s) to a new one. */
c906108c
SS
3078 val.symtab = find_line_symtab (s, val.line, NULL, NULL);
3079 if (val.symtab == 0)
3080 val.symtab = s;
c5aa993b 3081
c906108c
SS
3082 val.pc = 0;
3083 values.sals = (struct symtab_and_line *)
3084 xmalloc (sizeof (struct symtab_and_line));
3085 values.sals[0] = val;
3086 values.nelts = 1;
3087 if (need_canonical)
3088 build_canonical_line_spec (values.sals, NULL, canonical);
3089 return values;
3090 }
3091
3092 /* Arg token is not digits => try it as a variable name
3093 Find the next token (everything up to end or next whitespace). */
3094
3095 if (**argptr == '$') /* May be a convenience variable */
c5aa993b 3096 p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1)); /* One or two $ chars possible */
c906108c
SS
3097 else if (is_quoted)
3098 {
3099 p = skip_quoted (*argptr);
3100 if (p[-1] != '\'')
c5aa993b 3101 error ("Unmatched single quote.");
c906108c
SS
3102 }
3103 else if (has_parens)
3104 {
c5aa993b 3105 p = pp + 1;
c906108c 3106 }
c5aa993b 3107 else
c906108c 3108 {
c5aa993b 3109 p = skip_quoted (*argptr);
c906108c
SS
3110 }
3111
da59e081
JM
3112 if (is_quote_enclosed && **argptr == '"')
3113 (*argptr)++;
3114
c906108c
SS
3115 copy = (char *) alloca (p - *argptr + 1);
3116 memcpy (copy, *argptr, p - *argptr);
3117 copy[p - *argptr] = '\0';
3118 if (p != *argptr
3119 && copy[0]
c5aa993b 3120 && copy[0] == copy[p - *argptr - 1]
c906108c
SS
3121 && strchr (gdb_completer_quote_characters, copy[0]) != NULL)
3122 {
c5aa993b 3123 copy[p - *argptr - 1] = '\0';
c906108c
SS
3124 copy++;
3125 }
c5aa993b
JM
3126 while (*p == ' ' || *p == '\t')
3127 p++;
c906108c
SS
3128 *argptr = p;
3129
3130 /* If it starts with $: may be a legitimate variable or routine name
3131 (e.g. HP-UX millicode routines such as $$dyncall), or it may
c5aa993b 3132 be history value, or it may be a convenience variable */
c906108c
SS
3133
3134 if (*copy == '$')
3135 {
3136 value_ptr valx;
3137 int index = 0;
3138 int need_canonical = 0;
3139
3140 p = (copy[1] == '$') ? copy + 2 : copy + 1;
3141 while (*p >= '0' && *p <= '9')
c5aa993b
JM
3142 p++;
3143 if (!*p) /* reached end of token without hitting non-digit */
3144 {
3145 /* We have a value history reference */
3146 sscanf ((copy[1] == '$') ? copy + 2 : copy + 1, "%d", &index);
3147 valx = access_value_history ((copy[1] == '$') ? -index : index);
3148 if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT)
3149 error ("History values used in line specs must have integer values.");
3150 }
3151 else
3152 {
3153 /* Not all digits -- may be user variable/function or a
3154 convenience variable */
3155
3156 /* Look up entire name as a symbol first */
3157 sym = lookup_symbol (copy, 0, VAR_NAMESPACE, 0, &sym_symtab);
3158 s = (struct symtab *) 0;
3159 need_canonical = 1;
3160 /* Symbol was found --> jump to normal symbol processing.
3161 Code following "symbol_found" expects "copy" to have the
3162 symbol name, "sym" to have the symbol pointer, "s" to be
3163 a specified file's symtab, and sym_symtab to be the symbol's
3164 symtab. */
3165 if (sym)
3166 goto symbol_found;
3167
3168 /* If symbol was not found, look in minimal symbol tables */
3169 msymbol = lookup_minimal_symbol (copy, 0, 0);
3170 /* Min symbol was found --> jump to minsym processing. */
3171 if (msymbol)
3172 goto minimal_symbol_found;
3173
3174 /* Not a user variable or function -- must be convenience variable */
3175 need_canonical = (s == 0) ? 1 : 0;
3176 valx = value_of_internalvar (lookup_internalvar (copy + 1));
3177 if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT)
3178 error ("Convenience variables used in line specs must have integer values.");
3179 }
3180
3181 /* Either history value or convenience value from above, in valx */
c906108c
SS
3182 val.symtab = s ? s : default_symtab;
3183 val.line = value_as_long (valx);
3184 val.pc = 0;
3185
c5aa993b 3186 values.sals = (struct symtab_and_line *) xmalloc (sizeof val);
c906108c
SS
3187 values.sals[0] = val;
3188 values.nelts = 1;
3189
3190 if (need_canonical)
3191 build_canonical_line_spec (values.sals, NULL, canonical);
3192
3193 return values;
3194 }
3195
3196
3197 /* Look up that token as a variable.
3198 If file specified, use that file's per-file block to start with. */
3199
3200 sym = lookup_symbol (copy,
3201 (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
3202 : get_selected_block ()),
3203 VAR_NAMESPACE, 0, &sym_symtab);
c5aa993b
JM
3204
3205symbol_found: /* We also jump here from inside the C++ class/namespace
3206 code on finding a symbol of the form "A::B::C" */
c906108c
SS
3207
3208 if (sym != NULL)
3209 {
3210 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
3211 {
3212 /* Arg is the name of a function */
3213 values.sals = (struct symtab_and_line *)
3214 xmalloc (sizeof (struct symtab_and_line));
3215 values.sals[0] = find_function_start_sal (sym, funfirstline);
3216 values.nelts = 1;
3217
3218 /* Don't use the SYMBOL_LINE; if used at all it points to
3219 the line containing the parameters or thereabouts, not
3220 the first line of code. */
3221
3222 /* We might need a canonical line spec if it is a static
3223 function. */
3224 if (s == 0)
3225 {
3226 struct blockvector *bv = BLOCKVECTOR (sym_symtab);
3227 struct block *b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
3228 if (lookup_block_symbol (b, copy, VAR_NAMESPACE) != NULL)
3229 build_canonical_line_spec (values.sals, copy, canonical);
3230 }
3231 return values;
3232 }
3233 else
3234 {
3235 if (funfirstline)
3236 error ("\"%s\" is not a function", copy);
3237 else if (SYMBOL_LINE (sym) != 0)
3238 {
3239 /* We know its line number. */
3240 values.sals = (struct symtab_and_line *)
3241 xmalloc (sizeof (struct symtab_and_line));
3242 values.nelts = 1;
3243 memset (&values.sals[0], 0, sizeof (values.sals[0]));
3244 values.sals[0].symtab = sym_symtab;
3245 values.sals[0].line = SYMBOL_LINE (sym);
3246 return values;
3247 }
3248 else
3249 /* This can happen if it is compiled with a compiler which doesn't
3250 put out line numbers for variables. */
3251 /* FIXME: Shouldn't we just set .line and .symtab to zero
3252 and return? For example, "info line foo" could print
3253 the address. */
3254 error ("Line number not known for symbol \"%s\"", copy);
3255 }
3256 }
3257
3258 msymbol = lookup_minimal_symbol (copy, NULL, NULL);
3259
c5aa993b
JM
3260minimal_symbol_found: /* We also jump here from the case for variables
3261 that begin with '$' */
3262
c906108c
SS
3263 if (msymbol != NULL)
3264 {
3265 values.sals = (struct symtab_and_line *)
3266 xmalloc (sizeof (struct symtab_and_line));
c5aa993b
JM
3267 values.sals[0] = find_pc_sect_line (SYMBOL_VALUE_ADDRESS (msymbol),
3268 (struct sec *) 0, 0);
c906108c
SS
3269 values.sals[0].section = SYMBOL_BFD_SECTION (msymbol);
3270 if (funfirstline)
3271 {
3272 values.sals[0].pc += FUNCTION_START_OFFSET;
b83266a0 3273 values.sals[0].pc = SKIP_PROLOGUE (values.sals[0].pc);
c906108c
SS
3274 }
3275 values.nelts = 1;
3276 return values;
3277 }
3278
3279 if (!have_full_symbols () &&
3280 !have_partial_symbols () && !have_minimal_symbols ())
3281 error (no_symtab_msg);
3282
3283 error ("Function \"%s\" not defined.", copy);
c5aa993b 3284 return values; /* for lint */
c906108c
SS
3285}
3286
3287struct symtabs_and_lines
3288decode_line_spec (string, funfirstline)
3289 char *string;
3290 int funfirstline;
3291{
3292 struct symtabs_and_lines sals;
3293 if (string == 0)
3294 error ("Empty line specification.");
3295 sals = decode_line_1 (&string, funfirstline,
3296 current_source_symtab, current_source_line,
c5aa993b 3297 (char ***) NULL);
c906108c
SS
3298 if (*string)
3299 error ("Junk at end of line specification: %s", string);
3300 return sals;
3301}
3302
3303/* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
3304 operate on (ask user if necessary).
3305 If CANONICAL is non-NULL return a corresponding array of mangled names
3306 as canonical line specs there. */
3307
3308static struct symtabs_and_lines
3309decode_line_2 (sym_arr, nelts, funfirstline, canonical)
3310 struct symbol *sym_arr[];
3311 int nelts;
3312 int funfirstline;
3313 char ***canonical;
3314{
3315 struct symtabs_and_lines values, return_values;
3316 char *args, *arg1;
3317 int i;
3318 char *prompt;
3319 char *symname;
3320 struct cleanup *old_chain;
c5aa993b 3321 char **canonical_arr = (char **) NULL;
c906108c 3322
c5aa993b
JM
3323 values.sals = (struct symtab_and_line *)
3324 alloca (nelts * sizeof (struct symtab_and_line));
3325 return_values.sals = (struct symtab_and_line *)
3326 xmalloc (nelts * sizeof (struct symtab_and_line));
c906108c
SS
3327 old_chain = make_cleanup (free, return_values.sals);
3328
3329 if (canonical)
3330 {
3331 canonical_arr = (char **) xmalloc (nelts * sizeof (char *));
3332 make_cleanup (free, canonical_arr);
3333 memset (canonical_arr, 0, nelts * sizeof (char *));
3334 *canonical = canonical_arr;
3335 }
3336
3337 i = 0;
c5aa993b 3338 printf_unfiltered ("[0] cancel\n[1] all\n");
c906108c
SS
3339 while (i < nelts)
3340 {
3341 INIT_SAL (&return_values.sals[i]); /* initialize to zeroes */
3342 INIT_SAL (&values.sals[i]);
3343 if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK)
3344 {
3345 values.sals[i] = find_function_start_sal (sym_arr[i], funfirstline);
3346 printf_unfiltered ("[%d] %s at %s:%d\n",
c5aa993b 3347 (i + 2),
c906108c
SS
3348 SYMBOL_SOURCE_NAME (sym_arr[i]),
3349 values.sals[i].symtab->filename,
3350 values.sals[i].line);
3351 }
3352 else
3353 printf_unfiltered ("?HERE\n");
3354 i++;
3355 }
c5aa993b 3356
c906108c
SS
3357 if ((prompt = getenv ("PS2")) == NULL)
3358 {
3359 prompt = "> ";
3360 }
3361 args = command_line_input (prompt, 0, "overload-choice");
c5aa993b 3362
c906108c
SS
3363 if (args == 0 || *args == 0)
3364 error_no_arg ("one or more choice numbers");
3365
3366 i = 0;
3367 while (*args)
3368 {
3369 int num;
3370
3371 arg1 = args;
c5aa993b
JM
3372 while (*arg1 >= '0' && *arg1 <= '9')
3373 arg1++;
c906108c
SS
3374 if (*arg1 && *arg1 != ' ' && *arg1 != '\t')
3375 error ("Arguments must be choice numbers.");
3376
3377 num = atoi (args);
3378
3379 if (num == 0)
3380 error ("cancelled");
3381 else if (num == 1)
3382 {
3383 if (canonical_arr)
3384 {
3385 for (i = 0; i < nelts; i++)
3386 {
c5aa993b 3387 if (canonical_arr[i] == NULL)
c906108c
SS
3388 {
3389 symname = SYMBOL_NAME (sym_arr[i]);
c5aa993b 3390 canonical_arr[i] = savestring (symname, strlen (symname));
c906108c
SS
3391 }
3392 }
3393 }
3394 memcpy (return_values.sals, values.sals,
c5aa993b 3395 (nelts * sizeof (struct symtab_and_line)));
c906108c
SS
3396 return_values.nelts = nelts;
3397 discard_cleanups (old_chain);
3398 return return_values;
3399 }
3400
3401 if (num >= nelts + 2)
3402 {
3403 printf_unfiltered ("No choice number %d.\n", num);
3404 }
3405 else
3406 {
3407 num -= 2;
3408 if (values.sals[num].pc)
3409 {
3410 if (canonical_arr)
3411 {
3412 symname = SYMBOL_NAME (sym_arr[num]);
3413 make_cleanup (free, symname);
3414 canonical_arr[i] = savestring (symname, strlen (symname));
3415 }
3416 return_values.sals[i++] = values.sals[num];
3417 values.sals[num].pc = 0;
3418 }
3419 else
3420 {
3421 printf_unfiltered ("duplicate request for %d ignored.\n", num);
3422 }
3423 }
3424
3425 args = arg1;
c5aa993b
JM
3426 while (*args == ' ' || *args == '\t')
3427 args++;
c906108c
SS
3428 }
3429 return_values.nelts = i;
3430 discard_cleanups (old_chain);
3431 return return_values;
3432}
c906108c 3433\f
c5aa993b 3434
c906108c
SS
3435/* Slave routine for sources_info. Force line breaks at ,'s.
3436 NAME is the name to print and *FIRST is nonzero if this is the first
3437 name printed. Set *FIRST to zero. */
3438static void
3439output_source_filename (name, first)
3440 char *name;
3441 int *first;
3442{
3443 /* Table of files printed so far. Since a single source file can
3444 result in several partial symbol tables, we need to avoid printing
3445 it more than once. Note: if some of the psymtabs are read in and
3446 some are not, it gets printed both under "Source files for which
3447 symbols have been read" and "Source files for which symbols will
3448 be read in on demand". I consider this a reasonable way to deal
3449 with the situation. I'm not sure whether this can also happen for
3450 symtabs; it doesn't hurt to check. */
3451 static char **tab = NULL;
3452 /* Allocated size of tab in elements.
3453 Start with one 256-byte block (when using GNU malloc.c).
3454 24 is the malloc overhead when range checking is in effect. */
3455 static int tab_alloc_size = (256 - 24) / sizeof (char *);
3456 /* Current size of tab in elements. */
3457 static int tab_cur_size;
3458
3459 char **p;
3460
3461 if (*first)
3462 {
3463 if (tab == NULL)
3464 tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab));
3465 tab_cur_size = 0;
3466 }
3467
3468 /* Is NAME in tab? */
3469 for (p = tab; p < tab + tab_cur_size; p++)
3470 if (STREQ (*p, name))
3471 /* Yes; don't print it again. */
3472 return;
3473 /* No; add it to tab. */
3474 if (tab_cur_size == tab_alloc_size)
3475 {
3476 tab_alloc_size *= 2;
3477 tab = (char **) xrealloc ((char *) tab, tab_alloc_size * sizeof (*tab));
3478 }
3479 tab[tab_cur_size++] = name;
3480
3481 if (*first)
3482 {
3483 *first = 0;
3484 }
3485 else
3486 {
3487 printf_filtered (", ");
3488 }
3489
3490 wrap_here ("");
3491 fputs_filtered (name, gdb_stdout);
c5aa993b 3492}
c906108c
SS
3493
3494static void
3495sources_info (ignore, from_tty)
3496 char *ignore;
3497 int from_tty;
3498{
3499 register struct symtab *s;
3500 register struct partial_symtab *ps;
3501 register struct objfile *objfile;
3502 int first;
c5aa993b 3503
c906108c
SS
3504 if (!have_full_symbols () && !have_partial_symbols ())
3505 {
3506 error (no_symtab_msg);
3507 }
c5aa993b 3508
c906108c
SS
3509 printf_filtered ("Source files for which symbols have been read in:\n\n");
3510
3511 first = 1;
3512 ALL_SYMTABS (objfile, s)
c5aa993b
JM
3513 {
3514 output_source_filename (s->filename, &first);
3515 }
c906108c 3516 printf_filtered ("\n\n");
c5aa993b 3517
c906108c
SS
3518 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
3519
3520 first = 1;
3521 ALL_PSYMTABS (objfile, ps)
c5aa993b
JM
3522 {
3523 if (!ps->readin)
3524 {
3525 output_source_filename (ps->filename, &first);
3526 }
3527 }
c906108c
SS
3528 printf_filtered ("\n");
3529}
3530
3531static int
3532file_matches (file, files, nfiles)
3533 char *file;
3534 char *files[];
3535 int nfiles;
3536{
3537 int i;
3538
3539 if (file != NULL && nfiles != 0)
3540 {
3541 for (i = 0; i < nfiles; i++)
c5aa993b
JM
3542 {
3543 if (strcmp (files[i], basename (file)) == 0)
3544 return 1;
3545 }
c906108c
SS
3546 }
3547 else if (nfiles == 0)
3548 return 1;
3549 return 0;
3550}
3551
3552/* Free any memory associated with a search. */
3553void
3554free_search_symbols (symbols)
3555 struct symbol_search *symbols;
3556{
3557 struct symbol_search *p;
3558 struct symbol_search *next;
3559
3560 for (p = symbols; p != NULL; p = next)
3561 {
3562 next = p->next;
3563 free (p);
3564 }
3565}
3566
3567/* Search the symbol table for matches to the regular expression REGEXP,
3568 returning the results in *MATCHES.
3569
3570 Only symbols of KIND are searched:
c5aa993b
JM
3571 FUNCTIONS_NAMESPACE - search all functions
3572 TYPES_NAMESPACE - search all type names
3573 METHODS_NAMESPACE - search all methods NOT IMPLEMENTED
3574 VARIABLES_NAMESPACE - search all symbols, excluding functions, type names,
3575 and constants (enums)
c906108c
SS
3576
3577 free_search_symbols should be called when *MATCHES is no longer needed.
c5aa993b 3578 */
c906108c
SS
3579void
3580search_symbols (regexp, kind, nfiles, files, matches)
3581 char *regexp;
3582 namespace_enum kind;
3583 int nfiles;
3584 char *files[];
3585 struct symbol_search **matches;
c5aa993b 3586
c906108c
SS
3587{
3588 register struct symtab *s;
3589 register struct partial_symtab *ps;
3590 register struct blockvector *bv;
3591 struct blockvector *prev_bv = 0;
3592 register struct block *b;
3593 register int i = 0;
3594 register int j;
3595 register struct symbol *sym;
3596 struct partial_symbol **psym;
3597 struct objfile *objfile;
3598 struct minimal_symbol *msymbol;
3599 char *val;
3600 int found_misc = 0;
3601 static enum minimal_symbol_type types[]
c5aa993b
JM
3602 =
3603 {mst_data, mst_text, mst_abs, mst_unknown};
c906108c 3604 static enum minimal_symbol_type types2[]
c5aa993b
JM
3605 =
3606 {mst_bss, mst_file_text, mst_abs, mst_unknown};
c906108c 3607 static enum minimal_symbol_type types3[]
c5aa993b
JM
3608 =
3609 {mst_file_data, mst_solib_trampoline, mst_abs, mst_unknown};
c906108c 3610 static enum minimal_symbol_type types4[]
c5aa993b
JM
3611 =
3612 {mst_file_bss, mst_text, mst_abs, mst_unknown};
c906108c
SS
3613 enum minimal_symbol_type ourtype;
3614 enum minimal_symbol_type ourtype2;
3615 enum minimal_symbol_type ourtype3;
3616 enum minimal_symbol_type ourtype4;
3617 struct symbol_search *sr;
3618 struct symbol_search *psr;
3619 struct symbol_search *tail;
3620 struct cleanup *old_chain = NULL;
3621
3622 if (kind < LABEL_NAMESPACE)
3623 error ("must search on specific namespace");
3624
3625 ourtype = types[(int) (kind - LABEL_NAMESPACE)];
3626 ourtype2 = types2[(int) (kind - LABEL_NAMESPACE)];
3627 ourtype3 = types3[(int) (kind - LABEL_NAMESPACE)];
3628 ourtype4 = types4[(int) (kind - LABEL_NAMESPACE)];
3629
3630 sr = *matches = NULL;
3631 tail = NULL;
3632
3633 if (regexp != NULL)
3634 {
3635 /* Make sure spacing is right for C++ operators.
3636 This is just a courtesy to make the matching less sensitive
3637 to how many spaces the user leaves between 'operator'
3638 and <TYPENAME> or <OPERATOR>. */
3639 char *opend;
3640 char *opname = operator_chars (regexp, &opend);
3641 if (*opname)
c5aa993b
JM
3642 {
3643 int fix = -1; /* -1 means ok; otherwise number of spaces needed. */
3644 if (isalpha (*opname) || *opname == '_' || *opname == '$')
3645 {
3646 /* There should 1 space between 'operator' and 'TYPENAME'. */
3647 if (opname[-1] != ' ' || opname[-2] == ' ')
3648 fix = 1;
3649 }
3650 else
3651 {
3652 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
3653 if (opname[-1] == ' ')
3654 fix = 0;
3655 }
3656 /* If wrong number of spaces, fix it. */
3657 if (fix >= 0)
3658 {
3659 char *tmp = (char *) alloca (opend - opname + 10);
3660 sprintf (tmp, "operator%.*s%s", fix, " ", opname);
3661 regexp = tmp;
3662 }
3663 }
3664
c906108c 3665 if (0 != (val = re_comp (regexp)))
c5aa993b 3666 error ("Invalid regexp (%s): %s", val, regexp);
c906108c
SS
3667 }
3668
3669 /* Search through the partial symtabs *first* for all symbols
3670 matching the regexp. That way we don't have to reproduce all of
3671 the machinery below. */
3672
3673 ALL_PSYMTABS (objfile, ps)
c5aa993b
JM
3674 {
3675 struct partial_symbol **bound, **gbound, **sbound;
3676 int keep_going = 1;
3677
3678 if (ps->readin)
3679 continue;
3680
3681 gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms;
3682 sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms;
3683 bound = gbound;
3684
3685 /* Go through all of the symbols stored in a partial
3686 symtab in one loop. */
3687 psym = objfile->global_psymbols.list + ps->globals_offset;
3688 while (keep_going)
3689 {
3690 if (psym >= bound)
3691 {
3692 if (bound == gbound && ps->n_static_syms != 0)
3693 {
3694 psym = objfile->static_psymbols.list + ps->statics_offset;
3695 bound = sbound;
3696 }
3697 else
3698 keep_going = 0;
3699 continue;
3700 }
3701 else
3702 {
3703 QUIT;
3704
3705 /* If it would match (logic taken from loop below)
3706 load the file and go on to the next one */
3707 if (file_matches (ps->filename, files, nfiles)
3708 && ((regexp == NULL || SYMBOL_MATCHES_REGEXP (*psym))
3709 && ((kind == VARIABLES_NAMESPACE && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
3710 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
3711 || (kind == FUNCTIONS_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_BLOCK)
3712 || (kind == TYPES_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_TYPEDEF)
3713 || (kind == METHODS_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_BLOCK))))
3714 {
3715 PSYMTAB_TO_SYMTAB (ps);
3716 keep_going = 0;
3717 }
3718 }
3719 psym++;
3720 }
3721 }
c906108c
SS
3722
3723 /* Here, we search through the minimal symbol tables for functions
3724 and variables that match, and force their symbols to be read.
3725 This is in particular necessary for demangled variable names,
3726 which are no longer put into the partial symbol tables.
3727 The symbol will then be found during the scan of symtabs below.
3728
3729 For functions, find_pc_symtab should succeed if we have debug info
3730 for the function, for variables we have to call lookup_symbol
3731 to determine if the variable has debug info.
3732 If the lookup fails, set found_misc so that we will rescan to print
3733 any matching symbols without debug info.
c5aa993b 3734 */
c906108c
SS
3735
3736 if (nfiles == 0 && (kind == VARIABLES_NAMESPACE || kind == FUNCTIONS_NAMESPACE))
3737 {
3738 ALL_MSYMBOLS (objfile, msymbol)
c5aa993b
JM
3739 {
3740 if (MSYMBOL_TYPE (msymbol) == ourtype ||
3741 MSYMBOL_TYPE (msymbol) == ourtype2 ||
3742 MSYMBOL_TYPE (msymbol) == ourtype3 ||
3743 MSYMBOL_TYPE (msymbol) == ourtype4)
3744 {
3745 if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
3746 {
3747 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)))
3748 {
3749 if (kind == FUNCTIONS_NAMESPACE
3750 || lookup_symbol (SYMBOL_NAME (msymbol),
3751 (struct block *) NULL,
3752 VAR_NAMESPACE,
3753 0, (struct symtab **) NULL) == NULL)
3754 found_misc = 1;
3755 }
3756 }
3757 }
3758 }
c906108c
SS
3759 }
3760
3761 ALL_SYMTABS (objfile, s)
c5aa993b
JM
3762 {
3763 bv = BLOCKVECTOR (s);
3764 /* Often many files share a blockvector.
3765 Scan each blockvector only once so that
3766 we don't get every symbol many times.
3767 It happens that the first symtab in the list
3768 for any given blockvector is the main file. */
3769 if (bv != prev_bv)
3770 for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
3771 {
3772 b = BLOCKVECTOR_BLOCK (bv, i);
3773 /* Skip the sort if this block is always sorted. */
3774 if (!BLOCK_SHOULD_SORT (b))
3775 sort_block_syms (b);
3776 for (j = 0; j < BLOCK_NSYMS (b); j++)
3777 {
3778 QUIT;
3779 sym = BLOCK_SYM (b, j);
3780 if (file_matches (s->filename, files, nfiles)
3781 && ((regexp == NULL || SYMBOL_MATCHES_REGEXP (sym))
3782 && ((kind == VARIABLES_NAMESPACE && SYMBOL_CLASS (sym) != LOC_TYPEDEF
3783 && SYMBOL_CLASS (sym) != LOC_BLOCK
3784 && SYMBOL_CLASS (sym) != LOC_CONST)
3785 || (kind == FUNCTIONS_NAMESPACE && SYMBOL_CLASS (sym) == LOC_BLOCK)
3786 || (kind == TYPES_NAMESPACE && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
3787 || (kind == METHODS_NAMESPACE && SYMBOL_CLASS (sym) == LOC_BLOCK))))
3788 {
3789 /* match */
3790 psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search));
3791 psr->block = i;
3792 psr->symtab = s;
3793 psr->symbol = sym;
3794 psr->msymbol = NULL;
3795 psr->next = NULL;
3796 if (tail == NULL)
3797 {
3798 sr = psr;
3799 old_chain = make_cleanup ((make_cleanup_func)
3800 free_search_symbols, sr);
3801 }
3802 else
3803 tail->next = psr;
3804 tail = psr;
3805 }
3806 }
3807 }
3808 prev_bv = bv;
3809 }
c906108c
SS
3810
3811 /* If there are no eyes, avoid all contact. I mean, if there are
3812 no debug symbols, then print directly from the msymbol_vector. */
3813
3814 if (found_misc || kind != FUNCTIONS_NAMESPACE)
3815 {
3816 ALL_MSYMBOLS (objfile, msymbol)
c5aa993b
JM
3817 {
3818 if (MSYMBOL_TYPE (msymbol) == ourtype ||
3819 MSYMBOL_TYPE (msymbol) == ourtype2 ||
3820 MSYMBOL_TYPE (msymbol) == ourtype3 ||
3821 MSYMBOL_TYPE (msymbol) == ourtype4)
3822 {
3823 if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
3824 {
3825 /* Functions: Look up by address. */
3826 if (kind != FUNCTIONS_NAMESPACE ||
3827 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol))))
3828 {
3829 /* Variables/Absolutes: Look up by name */
3830 if (lookup_symbol (SYMBOL_NAME (msymbol),
3831 (struct block *) NULL, VAR_NAMESPACE,
3832 0, (struct symtab **) NULL) == NULL)
3833 {
3834 /* match */
3835 psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search));
3836 psr->block = i;
3837 psr->msymbol = msymbol;
3838 psr->symtab = NULL;
3839 psr->symbol = NULL;
3840 psr->next = NULL;
3841 if (tail == NULL)
3842 {
3843 sr = psr;
3844 old_chain = make_cleanup ((make_cleanup_func)
3845 free_search_symbols, &sr);
3846 }
3847 else
3848 tail->next = psr;
3849 tail = psr;
3850 }
3851 }
3852 }
3853 }
3854 }
c906108c
SS
3855 }
3856
3857 *matches = sr;
3858 if (sr != NULL)
3859 discard_cleanups (old_chain);
3860}
3861
3862/* Helper function for symtab_symbol_info, this function uses
3863 the data returned from search_symbols() to print information
3864 regarding the match to gdb_stdout.
c5aa993b 3865 */
c906108c
SS
3866static void
3867print_symbol_info (kind, s, sym, block, last)
3868 namespace_enum kind;
3869 struct symtab *s;
3870 struct symbol *sym;
3871 int block;
3872 char *last;
3873{
3874 if (last == NULL || strcmp (last, s->filename) != 0)
3875 {
3876 fputs_filtered ("\nFile ", gdb_stdout);
3877 fputs_filtered (s->filename, gdb_stdout);
3878 fputs_filtered (":\n", gdb_stdout);
3879 }
3880
3881 if (kind != TYPES_NAMESPACE && block == STATIC_BLOCK)
3882 printf_filtered ("static ");
c5aa993b 3883
c906108c
SS
3884 /* Typedef that is not a C++ class */
3885 if (kind == TYPES_NAMESPACE
3886 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
c5aa993b 3887 c_typedef_print (SYMBOL_TYPE (sym), sym, gdb_stdout);
c906108c 3888 /* variable, func, or typedef-that-is-c++-class */
c5aa993b
JM
3889 else if (kind < TYPES_NAMESPACE ||
3890 (kind == TYPES_NAMESPACE &&
3891 SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE))
c906108c
SS
3892 {
3893 type_print (SYMBOL_TYPE (sym),
c5aa993b
JM
3894 (SYMBOL_CLASS (sym) == LOC_TYPEDEF
3895 ? "" : SYMBOL_SOURCE_NAME (sym)),
3896 gdb_stdout, 0);
c906108c
SS
3897
3898 printf_filtered (";\n");
3899 }
3900 else
3901 {
c5aa993b 3902#if 0
c906108c
SS
3903 /* Tiemann says: "info methods was never implemented." */
3904 char *demangled_name;
c5aa993b
JM
3905 c_type_print_base (TYPE_FN_FIELD_TYPE (t, block),
3906 gdb_stdout, 0, 0);
3907 c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (t, block),
3908 gdb_stdout, 0);
c906108c 3909 if (TYPE_FN_FIELD_STUB (t, block))
c5aa993b 3910 check_stub_method (TYPE_DOMAIN_TYPE (type), j, block);
c906108c 3911 demangled_name =
c5aa993b
JM
3912 cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t, block),
3913 DMGL_ANSI | DMGL_PARAMS);
c906108c 3914 if (demangled_name == NULL)
c5aa993b
JM
3915 fprintf_filtered (stream, "<badly mangled name %s>",
3916 TYPE_FN_FIELD_PHYSNAME (t, block));
c906108c 3917 else
c5aa993b
JM
3918 {
3919 fputs_filtered (demangled_name, stream);
3920 free (demangled_name);
3921 }
3922#endif
c906108c
SS
3923 }
3924}
3925
3926/* This help function for symtab_symbol_info() prints information
3927 for non-debugging symbols to gdb_stdout.
c5aa993b 3928 */
c906108c
SS
3929static void
3930print_msymbol_info (msymbol)
3931 struct minimal_symbol *msymbol;
3932{
3933 printf_filtered (" %08lx %s\n",
c5aa993b
JM
3934 (unsigned long) SYMBOL_VALUE_ADDRESS (msymbol),
3935 SYMBOL_SOURCE_NAME (msymbol));
c906108c
SS
3936}
3937
3938/* This is the guts of the commands "info functions", "info types", and
3939 "info variables". It calls search_symbols to find all matches and then
3940 print_[m]symbol_info to print out some useful information about the
3941 matches.
c5aa993b 3942 */
c906108c
SS
3943static void
3944symtab_symbol_info (regexp, kind, from_tty)
3945 char *regexp;
3946 namespace_enum kind;
c5aa993b 3947 int from_tty;
c906108c
SS
3948{
3949 static char *classnames[]
c5aa993b
JM
3950 =
3951 {"variable", "function", "type", "method"};
c906108c
SS
3952 struct symbol_search *symbols;
3953 struct symbol_search *p;
3954 struct cleanup *old_chain;
3955 char *last_filename = NULL;
3956 int first = 1;
3957
3958 /* must make sure that if we're interrupted, symbols gets freed */
3959 search_symbols (regexp, kind, 0, (char **) NULL, &symbols);
3960 old_chain = make_cleanup ((make_cleanup_func) free_search_symbols, symbols);
3961
3962 printf_filtered (regexp
c5aa993b
JM
3963 ? "All %ss matching regular expression \"%s\":\n"
3964 : "All defined %ss:\n",
3965 classnames[(int) (kind - LABEL_NAMESPACE - 1)], regexp);
c906108c
SS
3966
3967 for (p = symbols; p != NULL; p = p->next)
3968 {
3969 QUIT;
3970
3971 if (p->msymbol != NULL)
c5aa993b
JM
3972 {
3973 if (first)
3974 {
3975 printf_filtered ("\nNon-debugging symbols:\n");
3976 first = 0;
3977 }
3978 print_msymbol_info (p->msymbol);
3979 }
c906108c 3980 else
c5aa993b
JM
3981 {
3982 print_symbol_info (kind,
3983 p->symtab,
3984 p->symbol,
3985 p->block,
3986 last_filename);
3987 last_filename = p->symtab->filename;
3988 }
c906108c
SS
3989 }
3990
3991 do_cleanups (old_chain);
3992}
3993
3994static void
3995variables_info (regexp, from_tty)
3996 char *regexp;
3997 int from_tty;
3998{
3999 symtab_symbol_info (regexp, VARIABLES_NAMESPACE, from_tty);
4000}
4001
4002static void
4003functions_info (regexp, from_tty)
4004 char *regexp;
4005 int from_tty;
4006{
4007 symtab_symbol_info (regexp, FUNCTIONS_NAMESPACE, from_tty);
4008}
4009
4010static void
4011types_info (regexp, from_tty)
4012 char *regexp;
4013 int from_tty;
4014{
4015 symtab_symbol_info (regexp, TYPES_NAMESPACE, from_tty);
4016}
4017
4018#if 0
4019/* Tiemann says: "info methods was never implemented." */
4020static void
4021methods_info (regexp)
4022 char *regexp;
4023{
4024 symtab_symbol_info (regexp, METHODS_NAMESPACE, 0, from_tty);
4025}
4026#endif /* 0 */
4027
4028/* Breakpoint all functions matching regular expression. */
8b93c638
JM
4029#ifdef UI_OUT
4030void
4031rbreak_command_wrapper (regexp, from_tty)
4032 char *regexp;
4033 int from_tty;
4034{
4035 rbreak_command (regexp, from_tty);
4036}
4037#endif
c906108c
SS
4038static void
4039rbreak_command (regexp, from_tty)
4040 char *regexp;
4041 int from_tty;
4042{
4043 struct symbol_search *ss;
4044 struct symbol_search *p;
4045 struct cleanup *old_chain;
4046
4047 search_symbols (regexp, FUNCTIONS_NAMESPACE, 0, (char **) NULL, &ss);
4048 old_chain = make_cleanup ((make_cleanup_func) free_search_symbols, ss);
4049
4050 for (p = ss; p != NULL; p = p->next)
4051 {
4052 if (p->msymbol == NULL)
c5aa993b
JM
4053 {
4054 char *string = (char *) alloca (strlen (p->symtab->filename)
4055 + strlen (SYMBOL_NAME (p->symbol))
4056 + 4);
4057 strcpy (string, p->symtab->filename);
4058 strcat (string, ":'");
4059 strcat (string, SYMBOL_NAME (p->symbol));
4060 strcat (string, "'");
4061 break_command (string, from_tty);
4062 print_symbol_info (FUNCTIONS_NAMESPACE,
4063 p->symtab,
4064 p->symbol,
4065 p->block,
4066 p->symtab->filename);
4067 }
c906108c 4068 else
c5aa993b
JM
4069 {
4070 break_command (SYMBOL_NAME (p->msymbol), from_tty);
4071 printf_filtered ("<function, no debug info> %s;\n",
4072 SYMBOL_SOURCE_NAME (p->msymbol));
4073 }
c906108c
SS
4074 }
4075
4076 do_cleanups (old_chain);
4077}
c906108c 4078\f
c5aa993b 4079
c906108c
SS
4080/* Return Nonzero if block a is lexically nested within block b,
4081 or if a and b have the same pc range.
4082 Return zero otherwise. */
4083int
4084contained_in (a, b)
4085 struct block *a, *b;
4086{
4087 if (!a || !b)
4088 return 0;
4089 return BLOCK_START (a) >= BLOCK_START (b)
c5aa993b 4090 && BLOCK_END (a) <= BLOCK_END (b);
c906108c 4091}
c906108c 4092\f
c5aa993b 4093
c906108c
SS
4094/* Helper routine for make_symbol_completion_list. */
4095
4096static int return_val_size;
4097static int return_val_index;
4098static char **return_val;
4099
4100#define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
4101 do { \
4102 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \
4103 /* Put only the mangled name on the list. */ \
4104 /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \
4105 /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \
4106 completion_list_add_name \
4107 (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \
4108 else \
4109 completion_list_add_name \
4110 (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \
4111 } while (0)
4112
4113/* Test to see if the symbol specified by SYMNAME (which is already
c5aa993b
JM
4114 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
4115 characters. If so, add it to the current completion list. */
c906108c
SS
4116
4117static void
4118completion_list_add_name (symname, sym_text, sym_text_len, text, word)
4119 char *symname;
4120 char *sym_text;
4121 int sym_text_len;
4122 char *text;
4123 char *word;
4124{
4125 int newsize;
4126 int i;
4127
4128 /* clip symbols that cannot match */
4129
4130 if (strncmp (symname, sym_text, sym_text_len) != 0)
4131 {
4132 return;
4133 }
4134
4135 /* Clip any symbol names that we've already considered. (This is a
4136 time optimization) */
4137
4138 for (i = 0; i < return_val_index; ++i)
4139 {
4140 if (STREQ (symname, return_val[i]))
4141 {
4142 return;
4143 }
4144 }
c5aa993b 4145
c906108c
SS
4146 /* We have a match for a completion, so add SYMNAME to the current list
4147 of matches. Note that the name is moved to freshly malloc'd space. */
4148
4149 {
4150 char *new;
4151 if (word == sym_text)
4152 {
4153 new = xmalloc (strlen (symname) + 5);
4154 strcpy (new, symname);
4155 }
4156 else if (word > sym_text)
4157 {
4158 /* Return some portion of symname. */
4159 new = xmalloc (strlen (symname) + 5);
4160 strcpy (new, symname + (word - sym_text));
4161 }
4162 else
4163 {
4164 /* Return some of SYM_TEXT plus symname. */
4165 new = xmalloc (strlen (symname) + (sym_text - word) + 5);
4166 strncpy (new, word, sym_text - word);
4167 new[sym_text - word] = '\0';
4168 strcat (new, symname);
4169 }
4170
4171 /* Recheck for duplicates if we intend to add a modified symbol. */
4172 if (word != sym_text)
4173 {
4174 for (i = 0; i < return_val_index; ++i)
4175 {
4176 if (STREQ (new, return_val[i]))
4177 {
4178 free (new);
4179 return;
4180 }
4181 }
4182 }
4183
4184 if (return_val_index + 3 > return_val_size)
4185 {
4186 newsize = (return_val_size *= 2) * sizeof (char *);
4187 return_val = (char **) xrealloc ((char *) return_val, newsize);
4188 }
4189 return_val[return_val_index++] = new;
4190 return_val[return_val_index] = NULL;
4191 }
4192}
4193
4194/* Return a NULL terminated array of all symbols (regardless of class) which
4195 begin by matching TEXT. If the answer is no symbols, then the return value
4196 is an array which contains only a NULL pointer.
4197
4198 Problem: All of the symbols have to be copied because readline frees them.
4199 I'm not going to worry about this; hopefully there won't be that many. */
4200
4201char **
4202make_symbol_completion_list (text, word)
4203 char *text;
4204 char *word;
4205{
4206 register struct symbol *sym;
4207 register struct symtab *s;
4208 register struct partial_symtab *ps;
4209 register struct minimal_symbol *msymbol;
4210 register struct objfile *objfile;
4211 register struct block *b, *surrounding_static_block = 0;
4212 register int i, j;
4213 struct partial_symbol **psym;
4214 /* The symbol we are completing on. Points in same buffer as text. */
4215 char *sym_text;
4216 /* Length of sym_text. */
4217 int sym_text_len;
4218
4219 /* Now look for the symbol we are supposed to complete on.
4220 FIXME: This should be language-specific. */
4221 {
4222 char *p;
4223 char quote_found;
4224 char *quote_pos = NULL;
4225
4226 /* First see if this is a quoted string. */
4227 quote_found = '\0';
4228 for (p = text; *p != '\0'; ++p)
4229 {
4230 if (quote_found != '\0')
4231 {
4232 if (*p == quote_found)
4233 /* Found close quote. */
4234 quote_found = '\0';
4235 else if (*p == '\\' && p[1] == quote_found)
4236 /* A backslash followed by the quote character
c5aa993b 4237 doesn't end the string. */
c906108c
SS
4238 ++p;
4239 }
4240 else if (*p == '\'' || *p == '"')
4241 {
4242 quote_found = *p;
4243 quote_pos = p;
4244 }
4245 }
4246 if (quote_found == '\'')
4247 /* A string within single quotes can be a symbol, so complete on it. */
4248 sym_text = quote_pos + 1;
4249 else if (quote_found == '"')
4250 /* A double-quoted string is never a symbol, nor does it make sense
c5aa993b 4251 to complete it any other way. */
c906108c
SS
4252 return NULL;
4253 else
4254 {
4255 /* It is not a quoted string. Break it based on the characters
4256 which are in symbols. */
4257 while (p > text)
4258 {
4259 if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
4260 --p;
4261 else
4262 break;
4263 }
4264 sym_text = p;
4265 }
4266 }
4267
4268 sym_text_len = strlen (sym_text);
4269
4270 return_val_size = 100;
4271 return_val_index = 0;
4272 return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
4273 return_val[0] = NULL;
4274
4275 /* Look through the partial symtabs for all symbols which begin
4276 by matching SYM_TEXT. Add each one that you find to the list. */
4277
4278 ALL_PSYMTABS (objfile, ps)
c5aa993b
JM
4279 {
4280 /* If the psymtab's been read in we'll get it when we search
4281 through the blockvector. */
4282 if (ps->readin)
4283 continue;
4284
4285 for (psym = objfile->global_psymbols.list + ps->globals_offset;
4286 psym < (objfile->global_psymbols.list + ps->globals_offset
4287 + ps->n_global_syms);
4288 psym++)
4289 {
4290 /* If interrupted, then quit. */
4291 QUIT;
4292 COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
4293 }
4294
4295 for (psym = objfile->static_psymbols.list + ps->statics_offset;
4296 psym < (objfile->static_psymbols.list + ps->statics_offset
4297 + ps->n_static_syms);
4298 psym++)
4299 {
4300 QUIT;
4301 COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
4302 }
4303 }
c906108c
SS
4304
4305 /* At this point scan through the misc symbol vectors and add each
4306 symbol you find to the list. Eventually we want to ignore
4307 anything that isn't a text symbol (everything else will be
4308 handled by the psymtab code above). */
4309
4310 ALL_MSYMBOLS (objfile, msymbol)
c5aa993b
JM
4311 {
4312 QUIT;
4313 COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, word);
4314 }
c906108c
SS
4315
4316 /* Search upwards from currently selected frame (so that we can
4317 complete on local vars. */
4318
4319 for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
4320 {
4321 if (!BLOCK_SUPERBLOCK (b))
4322 {
c5aa993b 4323 surrounding_static_block = b; /* For elmin of dups */
c906108c 4324 }
c5aa993b 4325
c906108c 4326 /* Also catch fields of types defined in this places which match our
c5aa993b 4327 text string. Only complete on types visible from current context. */
c906108c
SS
4328
4329 for (i = 0; i < BLOCK_NSYMS (b); i++)
4330 {
4331 sym = BLOCK_SYM (b, i);
4332 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
4333 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
4334 {
4335 struct type *t = SYMBOL_TYPE (sym);
4336 enum type_code c = TYPE_CODE (t);
4337
4338 if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
4339 {
4340 for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
4341 {
4342 if (TYPE_FIELD_NAME (t, j))
4343 {
4344 completion_list_add_name (TYPE_FIELD_NAME (t, j),
c5aa993b 4345 sym_text, sym_text_len, text, word);
c906108c
SS
4346 }
4347 }
4348 }
4349 }
4350 }
4351 }
4352
4353 /* Go through the symtabs and check the externs and statics for
4354 symbols which match. */
4355
4356 ALL_SYMTABS (objfile, s)
c5aa993b
JM
4357 {
4358 QUIT;
4359 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
4360 for (i = 0; i < BLOCK_NSYMS (b); i++)
4361 {
4362 sym = BLOCK_SYM (b, i);
4363 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
4364 }
4365 }
c906108c
SS
4366
4367 ALL_SYMTABS (objfile, s)
c5aa993b
JM
4368 {
4369 QUIT;
4370 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
4371 /* Don't do this block twice. */
4372 if (b == surrounding_static_block)
4373 continue;
4374 for (i = 0; i < BLOCK_NSYMS (b); i++)
4375 {
4376 sym = BLOCK_SYM (b, i);
4377 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
4378 }
4379 }
c906108c
SS
4380
4381 return (return_val);
4382}
4383
4384/* Determine if PC is in the prologue of a function. The prologue is the area
4385 between the first instruction of a function, and the first executable line.
4386 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
4387
4388 If non-zero, func_start is where we think the prologue starts, possibly
4389 by previous examination of symbol table information.
4390 */
4391
4392int
4393in_prologue (pc, func_start)
4394 CORE_ADDR pc;
4395 CORE_ADDR func_start;
4396{
4397 struct symtab_and_line sal;
4398 CORE_ADDR func_addr, func_end;
4399
54cf9c03
EZ
4400 /* We have several sources of information we can consult to figure
4401 this out.
4402 - Compilers usually emit line number info that marks the prologue
4403 as its own "source line". So the ending address of that "line"
4404 is the end of the prologue. If available, this is the most
4405 reliable method.
4406 - The minimal symbols and partial symbols, which can usually tell
4407 us the starting and ending addresses of a function.
4408 - If we know the function's start address, we can call the
4409 architecture-defined SKIP_PROLOGUE function to analyze the
4410 instruction stream and guess where the prologue ends.
4411 - Our `func_start' argument; if non-zero, this is the caller's
4412 best guess as to the function's entry point. At the time of
4413 this writing, handle_inferior_event doesn't get this right, so
4414 it should be our last resort. */
4415
4416 /* Consult the partial symbol table, to find which function
4417 the PC is in. */
4418 if (! find_pc_partial_function (pc, NULL, &func_addr, &func_end))
4419 {
4420 CORE_ADDR prologue_end;
c906108c 4421
54cf9c03
EZ
4422 /* We don't even have minsym information, so fall back to using
4423 func_start, if given. */
4424 if (! func_start)
4425 return 1; /* We *might* be in a prologue. */
c906108c 4426
54cf9c03 4427 prologue_end = SKIP_PROLOGUE (func_start);
c906108c 4428
54cf9c03
EZ
4429 return func_start <= pc && pc < prologue_end;
4430 }
c906108c 4431
54cf9c03
EZ
4432 /* If we have line number information for the function, that's
4433 usually pretty reliable. */
4434 sal = find_pc_line (func_addr, 0);
c906108c 4435
54cf9c03
EZ
4436 /* Now sal describes the source line at the function's entry point,
4437 which (by convention) is the prologue. The end of that "line",
4438 sal.end, is the end of the prologue.
4439
4440 Note that, for functions whose source code is all on a single
4441 line, the line number information doesn't always end up this way.
4442 So we must verify that our purported end-of-prologue address is
4443 *within* the function, not at its start or end. */
4444 if (sal.line == 0
4445 || sal.end <= func_addr
4446 || func_end <= sal.end)
4447 {
4448 /* We don't have any good line number info, so use the minsym
4449 information, together with the architecture-specific prologue
4450 scanning code. */
4451 CORE_ADDR prologue_end = SKIP_PROLOGUE (func_addr);
c906108c 4452
54cf9c03
EZ
4453 return func_addr <= pc && pc < prologue_end;
4454 }
c906108c 4455
54cf9c03
EZ
4456 /* We have line number info, and it looks good. */
4457 return func_addr <= pc && pc < sal.end;
c906108c
SS
4458}
4459
4460
4461/* Begin overload resolution functions */
4462/* Helper routine for make_symbol_completion_list. */
4463
4464static int sym_return_val_size;
4465static int sym_return_val_index;
4466static struct symbol **sym_return_val;
4467
4468/* Test to see if the symbol specified by SYMNAME (which is already
c5aa993b
JM
4469 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
4470 characters. If so, add it to the current completion list. */
c906108c
SS
4471
4472static void
4473overload_list_add_symbol (sym, oload_name)
c5aa993b
JM
4474 struct symbol *sym;
4475 char *oload_name;
c906108c
SS
4476{
4477 int newsize;
4478 int i;
4479
4480 /* Get the demangled name without parameters */
c5aa993b 4481 char *sym_name = cplus_demangle (SYMBOL_NAME (sym), DMGL_ARM | DMGL_ANSI);
c906108c
SS
4482 if (!sym_name)
4483 {
4484 sym_name = (char *) xmalloc (strlen (SYMBOL_NAME (sym)) + 1);
4485 strcpy (sym_name, SYMBOL_NAME (sym));
4486 }
4487
4488 /* skip symbols that cannot match */
4489 if (strcmp (sym_name, oload_name) != 0)
917317f4
JM
4490 {
4491 free (sym_name);
4492 return;
4493 }
c906108c
SS
4494
4495 /* If there is no type information, we can't do anything, so skip */
4496 if (SYMBOL_TYPE (sym) == NULL)
4497 return;
4498
4499 /* skip any symbols that we've already considered. */
4500 for (i = 0; i < sym_return_val_index; ++i)
4501 if (!strcmp (SYMBOL_NAME (sym), SYMBOL_NAME (sym_return_val[i])))
4502 return;
4503
4504 /* We have a match for an overload instance, so add SYM to the current list
4505 * of overload instances */
4506 if (sym_return_val_index + 3 > sym_return_val_size)
4507 {
4508 newsize = (sym_return_val_size *= 2) * sizeof (struct symbol *);
4509 sym_return_val = (struct symbol **) xrealloc ((char *) sym_return_val, newsize);
4510 }
4511 sym_return_val[sym_return_val_index++] = sym;
4512 sym_return_val[sym_return_val_index] = NULL;
c5aa993b 4513
c906108c
SS
4514 free (sym_name);
4515}
4516
4517/* Return a null-terminated list of pointers to function symbols that
4518 * match name of the supplied symbol FSYM.
4519 * This is used in finding all overloaded instances of a function name.
4520 * This has been modified from make_symbol_completion_list. */
4521
4522
4523struct symbol **
4524make_symbol_overload_list (fsym)
c5aa993b 4525 struct symbol *fsym;
c906108c
SS
4526{
4527 register struct symbol *sym;
4528 register struct symtab *s;
4529 register struct partial_symtab *ps;
c906108c
SS
4530 register struct objfile *objfile;
4531 register struct block *b, *surrounding_static_block = 0;
d4f3574e 4532 register int i;
c906108c
SS
4533 /* The name we are completing on. */
4534 char *oload_name = NULL;
4535 /* Length of name. */
4536 int oload_name_len = 0;
4537
4538 /* Look for the symbol we are supposed to complete on.
4539 * FIXME: This should be language-specific. */
4540
4541 oload_name = cplus_demangle (SYMBOL_NAME (fsym), DMGL_ARM | DMGL_ANSI);
4542 if (!oload_name)
4543 {
4544 oload_name = (char *) xmalloc (strlen (SYMBOL_NAME (fsym)) + 1);
4545 strcpy (oload_name, SYMBOL_NAME (fsym));
4546 }
4547 oload_name_len = strlen (oload_name);
4548
4549 sym_return_val_size = 100;
4550 sym_return_val_index = 0;
4551 sym_return_val = (struct symbol **) xmalloc ((sym_return_val_size + 1) * sizeof (struct symbol *));
4552 sym_return_val[0] = NULL;
4553
4554 /* Look through the partial symtabs for all symbols which begin
917317f4 4555 by matching OLOAD_NAME. Make sure we read that symbol table in. */
c906108c
SS
4556
4557 ALL_PSYMTABS (objfile, ps)
c5aa993b 4558 {
d4f3574e
SS
4559 struct partial_symbol **psym;
4560
c5aa993b
JM
4561 /* If the psymtab's been read in we'll get it when we search
4562 through the blockvector. */
4563 if (ps->readin)
4564 continue;
4565
4566 for (psym = objfile->global_psymbols.list + ps->globals_offset;
4567 psym < (objfile->global_psymbols.list + ps->globals_offset
4568 + ps->n_global_syms);
4569 psym++)
4570 {
4571 /* If interrupted, then quit. */
4572 QUIT;
917317f4
JM
4573 /* This will cause the symbol table to be read if it has not yet been */
4574 s = PSYMTAB_TO_SYMTAB (ps);
c5aa993b
JM
4575 }
4576
4577 for (psym = objfile->static_psymbols.list + ps->statics_offset;
4578 psym < (objfile->static_psymbols.list + ps->statics_offset
4579 + ps->n_static_syms);
4580 psym++)
4581 {
4582 QUIT;
917317f4
JM
4583 /* This will cause the symbol table to be read if it has not yet been */
4584 s = PSYMTAB_TO_SYMTAB (ps);
c5aa993b
JM
4585 }
4586 }
c906108c 4587
c906108c
SS
4588 /* Search upwards from currently selected frame (so that we can
4589 complete on local vars. */
4590
4591 for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
4592 {
4593 if (!BLOCK_SUPERBLOCK (b))
4594 {
c5aa993b 4595 surrounding_static_block = b; /* For elimination of dups */
c906108c 4596 }
c5aa993b 4597
c906108c 4598 /* Also catch fields of types defined in this places which match our
c5aa993b 4599 text string. Only complete on types visible from current context. */
c906108c
SS
4600
4601 for (i = 0; i < BLOCK_NSYMS (b); i++)
4602 {
4603 sym = BLOCK_SYM (b, i);
4604 overload_list_add_symbol (sym, oload_name);
4605 }
4606 }
4607
4608 /* Go through the symtabs and check the externs and statics for
4609 symbols which match. */
4610
4611 ALL_SYMTABS (objfile, s)
c5aa993b
JM
4612 {
4613 QUIT;
4614 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
4615 for (i = 0; i < BLOCK_NSYMS (b); i++)
4616 {
4617 sym = BLOCK_SYM (b, i);
4618 overload_list_add_symbol (sym, oload_name);
4619 }
4620 }
c906108c
SS
4621
4622 ALL_SYMTABS (objfile, s)
c5aa993b
JM
4623 {
4624 QUIT;
4625 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
4626 /* Don't do this block twice. */
4627 if (b == surrounding_static_block)
4628 continue;
4629 for (i = 0; i < BLOCK_NSYMS (b); i++)
4630 {
4631 sym = BLOCK_SYM (b, i);
4632 overload_list_add_symbol (sym, oload_name);
4633 }
4634 }
c906108c
SS
4635
4636 free (oload_name);
4637
4638 return (sym_return_val);
4639}
4640
4641/* End of overload resolution functions */
c906108c 4642\f
c5aa993b 4643
c906108c
SS
4644void
4645_initialize_symtab ()
4646{
4647 add_info ("variables", variables_info,
c5aa993b 4648 "All global and static variable names, or those matching REGEXP.");
c906108c 4649 if (dbx_commands)
c5aa993b
JM
4650 add_com ("whereis", class_info, variables_info,
4651 "All global and static variable names, or those matching REGEXP.");
c906108c
SS
4652
4653 add_info ("functions", functions_info,
4654 "All function names, or those matching REGEXP.");
4655
4656 /* FIXME: This command has at least the following problems:
4657 1. It prints builtin types (in a very strange and confusing fashion).
4658 2. It doesn't print right, e.g. with
c5aa993b
JM
4659 typedef struct foo *FOO
4660 type_print prints "FOO" when we want to make it (in this situation)
4661 print "struct foo *".
c906108c
SS
4662 I also think "ptype" or "whatis" is more likely to be useful (but if
4663 there is much disagreement "info types" can be fixed). */
4664 add_info ("types", types_info,
4665 "All type names, or those matching REGEXP.");
4666
4667#if 0
4668 add_info ("methods", methods_info,
4669 "All method names, or those matching REGEXP::REGEXP.\n\
4670If the class qualifier is omitted, it is assumed to be the current scope.\n\
4671If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
4672are listed.");
4673#endif
4674 add_info ("sources", sources_info,
4675 "Source files in the program.");
4676
4677 add_com ("rbreak", class_breakpoint, rbreak_command,
c5aa993b 4678 "Set a breakpoint for all functions matching REGEXP.");
c906108c
SS
4679
4680 if (xdb_commands)
4681 {
4682 add_com ("lf", class_info, sources_info, "Source files in the program");
4683 add_com ("lg", class_info, variables_info,
c5aa993b 4684 "All global and static variable names, or those matching REGEXP.");
c906108c
SS
4685 }
4686
4687 /* Initialize the one built-in type that isn't language dependent... */
4688 builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0,
4689 "<unknown type>", (struct objfile *) NULL);
4690}
This page took 0.290638 seconds and 4 git commands to generate.