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