*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / symtab.c
CommitLineData
c906108c 1/* Symbol table lookup for the GNU debugger, GDB.
8926118c 2
6aba47ca
DJ
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007
083ae935 5 Free Software 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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
c5aa993b 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 19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
21
22#include "defs.h"
23#include "symtab.h"
24#include "gdbtypes.h"
25#include "gdbcore.h"
26#include "frame.h"
27#include "target.h"
28#include "value.h"
29#include "symfile.h"
30#include "objfiles.h"
31#include "gdbcmd.h"
32#include "call-cmds.h"
88987551 33#include "gdb_regex.h"
c906108c
SS
34#include "expression.h"
35#include "language.h"
36#include "demangle.h"
37#include "inferior.h"
c5f0f3d0 38#include "linespec.h"
0378c332 39#include "source.h"
a7fdf62f 40#include "filenames.h" /* for FILENAME_CMP */
1bae87b9 41#include "objc-lang.h"
1f8173e6 42#include "ada-lang.h"
c906108c 43
2de7ced7
DJ
44#include "hashtab.h"
45
04ea0df1 46#include "gdb_obstack.h"
fe898f56 47#include "block.h"
de4f826b 48#include "dictionary.h"
c906108c
SS
49
50#include <sys/types.h>
51#include <fcntl.h>
52#include "gdb_string.h"
53#include "gdb_stat.h"
54#include <ctype.h>
015a42b4 55#include "cp-abi.h"
ea53e89f 56#include "observer.h"
94277a38 57#include "gdb_assert.h"
3a40aaa0 58#include "solist.h"
c906108c 59
c906108c
SS
60/* Prototypes for local functions */
61
a14ed312 62static void completion_list_add_name (char *, char *, int, char *, char *);
c906108c 63
a14ed312 64static void rbreak_command (char *, int);
c906108c 65
a14ed312 66static void types_info (char *, int);
c906108c 67
a14ed312 68static void functions_info (char *, int);
c906108c 69
a14ed312 70static void variables_info (char *, int);
c906108c 71
a14ed312 72static void sources_info (char *, int);
c906108c 73
d092d1a2 74static void output_source_filename (const char *, int *);
c906108c 75
a14ed312 76static int find_line_common (struct linetable *, int, int *);
c906108c 77
50641945
FN
78/* This one is used by linespec.c */
79
80char *operator_chars (char *p, char **end);
81
3121eff0 82static struct symbol *lookup_symbol_aux (const char *name,
5ad1c190 83 const char *linkage_name,
3121eff0 84 const struct block *block,
176620f1 85 const domain_enum domain,
53c5240f 86 enum language language,
3121eff0
DJ
87 int *is_a_field_of_this,
88 struct symtab **symtab);
fba7f19c 89
e4051eeb
DC
90static
91struct symbol *lookup_symbol_aux_local (const char *name,
5ad1c190 92 const char *linkage_name,
e4051eeb 93 const struct block *block,
176620f1 94 const domain_enum domain,
89a9d1b1 95 struct symtab **symtab);
8155455b
DC
96
97static
98struct symbol *lookup_symbol_aux_symtabs (int block_index,
99 const char *name,
5ad1c190 100 const char *linkage_name,
176620f1 101 const domain_enum domain,
8155455b
DC
102 struct symtab **symtab);
103
104static
105struct symbol *lookup_symbol_aux_psymtabs (int block_index,
106 const char *name,
5ad1c190 107 const char *linkage_name,
176620f1 108 const domain_enum domain,
8155455b 109 struct symtab **symtab);
fba7f19c 110
a14ed312 111static void fixup_section (struct general_symbol_info *, struct objfile *);
c906108c 112
a14ed312 113static int file_matches (char *, char **, int);
c906108c 114
176620f1 115static void print_symbol_info (domain_enum,
a14ed312 116 struct symtab *, struct symbol *, int, char *);
c906108c 117
a14ed312 118static void print_msymbol_info (struct minimal_symbol *);
c906108c 119
176620f1 120static void symtab_symbol_info (char *, domain_enum, int);
c906108c 121
a14ed312 122void _initialize_symtab (void);
c906108c
SS
123
124/* */
125
126/* The single non-language-specific builtin type */
127struct type *builtin_type_error;
128
129/* Block in which the most recently searched-for symbol was found.
130 Might be better to make this a parameter to lookup_symbol and
131 value_of_this. */
132
133const struct block *block_found;
134
c906108c
SS
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 141{
52f0bd74
AC
142 struct symtab *s;
143 struct partial_symtab *ps;
144 struct objfile *objfile;
58d370e0 145 char *real_path = NULL;
f079a2e5 146 char *full_path = NULL;
58d370e0
TT
147
148 /* Here we are interested in canonicalizing an absolute path, not
149 absolutizing a relative path. */
150 if (IS_ABSOLUTE_PATH (name))
f079a2e5
JB
151 {
152 full_path = xfullpath (name);
153 make_cleanup (xfree, full_path);
154 real_path = gdb_realpath (name);
155 make_cleanup (xfree, real_path);
156 }
c906108c 157
c5aa993b 158got_symtab:
c906108c
SS
159
160 /* First, search for an exact match */
161
162 ALL_SYMTABS (objfile, s)
58d370e0 163 {
a7fdf62f 164 if (FILENAME_CMP (name, s->filename) == 0)
58d370e0 165 {
58d370e0
TT
166 return s;
167 }
f079a2e5 168
58d370e0
TT
169 /* If the user gave us an absolute path, try to find the file in
170 this symtab and use its absolute path. */
f079a2e5
JB
171
172 if (full_path != NULL)
173 {
09bcec80
BR
174 const char *fp = symtab_to_fullname (s);
175 if (fp != NULL && FILENAME_CMP (full_path, fp) == 0)
176 {
177 return s;
178 }
f079a2e5
JB
179 }
180
58d370e0
TT
181 if (real_path != NULL)
182 {
09bcec80
BR
183 char *fullname = symtab_to_fullname (s);
184 if (fullname != NULL)
185 {
186 char *rp = gdb_realpath (fullname);
187 make_cleanup (xfree, rp);
188 if (FILENAME_CMP (real_path, rp) == 0)
189 {
190 return s;
191 }
192 }
58d370e0
TT
193 }
194 }
195
c906108c
SS
196 /* Now, search for a matching tail (only if name doesn't have any dirs) */
197
caadab2c 198 if (lbasename (name) == name)
c906108c 199 ALL_SYMTABS (objfile, s)
c5aa993b 200 {
31889e00 201 if (FILENAME_CMP (lbasename (s->filename), name) == 0)
c5aa993b
JM
202 return s;
203 }
c906108c
SS
204
205 /* Same search rules as above apply here, but now we look thru the
206 psymtabs. */
207
208 ps = lookup_partial_symtab (name);
209 if (!ps)
210 return (NULL);
211
c5aa993b 212 if (ps->readin)
8a3fe4f8 213 error (_("Internal: readin %s pst for `%s' found when no symtab found."),
c5aa993b 214 ps->filename, name);
c906108c
SS
215
216 s = PSYMTAB_TO_SYMTAB (ps);
217
218 if (s)
219 return s;
220
221 /* At this point, we have located the psymtab for this file, but
222 the conversion to a symtab has failed. This usually happens
223 when we are looking up an include file. In this case,
224 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
225 been created. So, we need to run through the symtabs again in
226 order to find the file.
227 XXX - This is a crock, and should be fixed inside of the the
228 symbol parsing routines. */
229 goto got_symtab;
230}
231
c906108c
SS
232/* Lookup the partial symbol table of a source file named NAME.
233 *If* there is no '/' in the name, a match after a '/'
234 in the psymtab filename will also work. */
235
236struct partial_symtab *
1f8cc6db 237lookup_partial_symtab (const char *name)
c906108c 238{
52f0bd74
AC
239 struct partial_symtab *pst;
240 struct objfile *objfile;
f079a2e5 241 char *full_path = NULL;
58d370e0
TT
242 char *real_path = NULL;
243
244 /* Here we are interested in canonicalizing an absolute path, not
245 absolutizing a relative path. */
246 if (IS_ABSOLUTE_PATH (name))
f079a2e5
JB
247 {
248 full_path = xfullpath (name);
249 make_cleanup (xfree, full_path);
250 real_path = gdb_realpath (name);
251 make_cleanup (xfree, real_path);
252 }
c5aa993b 253
c906108c 254 ALL_PSYMTABS (objfile, pst)
c5aa993b 255 {
a7fdf62f 256 if (FILENAME_CMP (name, pst->filename) == 0)
c5aa993b
JM
257 {
258 return (pst);
259 }
f079a2e5 260
58d370e0
TT
261 /* If the user gave us an absolute path, try to find the file in
262 this symtab and use its absolute path. */
f079a2e5 263 if (full_path != NULL)
58d370e0 264 {
d9c8471e 265 psymtab_to_fullname (pst);
58d370e0 266 if (pst->fullname != NULL
f079a2e5 267 && FILENAME_CMP (full_path, pst->fullname) == 0)
58d370e0 268 {
58d370e0
TT
269 return pst;
270 }
271 }
c906108c 272
f079a2e5
JB
273 if (real_path != NULL)
274 {
275 char *rp = NULL;
d9c8471e 276 psymtab_to_fullname (pst);
f079a2e5
JB
277 if (pst->fullname != NULL)
278 {
279 rp = gdb_realpath (pst->fullname);
280 make_cleanup (xfree, rp);
281 }
282 if (rp != NULL && FILENAME_CMP (real_path, rp) == 0)
283 {
284 return pst;
285 }
286 }
287 }
58d370e0 288
c906108c
SS
289 /* Now, search for a matching tail (only if name doesn't have any dirs) */
290
caadab2c 291 if (lbasename (name) == name)
c906108c 292 ALL_PSYMTABS (objfile, pst)
c5aa993b 293 {
31889e00 294 if (FILENAME_CMP (lbasename (pst->filename), name) == 0)
c5aa993b
JM
295 return (pst);
296 }
c906108c
SS
297
298 return (NULL);
299}
300\f
301/* Mangle a GDB method stub type. This actually reassembles the pieces of the
302 full method name, which consist of the class name (from T), the unadorned
303 method name from METHOD_ID, and the signature for the specific overload,
304 specified by SIGNATURE_ID. Note that this function is g++ specific. */
305
306char *
fba45db2 307gdb_mangle_name (struct type *type, int method_id, int signature_id)
c906108c
SS
308{
309 int mangled_name_len;
310 char *mangled_name;
311 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
312 struct fn_field *method = &f[signature_id];
313 char *field_name = TYPE_FN_FIELDLIST_NAME (type, method_id);
314 char *physname = TYPE_FN_FIELD_PHYSNAME (f, signature_id);
315 char *newname = type_name_no_tag (type);
316
317 /* Does the form of physname indicate that it is the full mangled name
318 of a constructor (not just the args)? */
319 int is_full_physname_constructor;
320
321 int is_constructor;
015a42b4 322 int is_destructor = is_destructor_name (physname);
c906108c
SS
323 /* Need a new type prefix. */
324 char *const_prefix = method->is_const ? "C" : "";
325 char *volatile_prefix = method->is_volatile ? "V" : "";
326 char buf[20];
327 int len = (newname == NULL ? 0 : strlen (newname));
328
43630227
PS
329 /* Nothing to do if physname already contains a fully mangled v3 abi name
330 or an operator name. */
331 if ((physname[0] == '_' && physname[1] == 'Z')
332 || is_operator_name (field_name))
235d1e03
EZ
333 return xstrdup (physname);
334
015a42b4 335 is_full_physname_constructor = is_constructor_name (physname);
c906108c
SS
336
337 is_constructor =
6314a349 338 is_full_physname_constructor || (newname && strcmp (field_name, newname) == 0);
c906108c
SS
339
340 if (!is_destructor)
c5aa993b 341 is_destructor = (strncmp (physname, "__dt", 4) == 0);
c906108c
SS
342
343 if (is_destructor || is_full_physname_constructor)
344 {
c5aa993b
JM
345 mangled_name = (char *) xmalloc (strlen (physname) + 1);
346 strcpy (mangled_name, physname);
c906108c
SS
347 return mangled_name;
348 }
349
350 if (len == 0)
351 {
352 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
353 }
354 else if (physname[0] == 't' || physname[0] == 'Q')
355 {
356 /* The physname for template and qualified methods already includes
c5aa993b 357 the class name. */
c906108c
SS
358 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
359 newname = NULL;
360 len = 0;
361 }
362 else
363 {
364 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
365 }
366 mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
235d1e03 367 + strlen (buf) + len + strlen (physname) + 1);
c906108c 368
c906108c 369 {
c5aa993b 370 mangled_name = (char *) xmalloc (mangled_name_len);
c906108c
SS
371 if (is_constructor)
372 mangled_name[0] = '\0';
373 else
374 strcpy (mangled_name, field_name);
375 }
376 strcat (mangled_name, buf);
377 /* If the class doesn't have a name, i.e. newname NULL, then we just
378 mangle it using 0 for the length of the class. Thus it gets mangled
c5aa993b 379 as something starting with `::' rather than `classname::'. */
c906108c
SS
380 if (newname != NULL)
381 strcat (mangled_name, newname);
382
383 strcat (mangled_name, physname);
384 return (mangled_name);
385}
12af6855
JB
386
387\f
89aad1f9
EZ
388/* Initialize the language dependent portion of a symbol
389 depending upon the language for the symbol. */
390void
391symbol_init_language_specific (struct general_symbol_info *gsymbol,
392 enum language language)
393{
394 gsymbol->language = language;
395 if (gsymbol->language == language_cplus
5784d15e
AF
396 || gsymbol->language == language_java
397 || gsymbol->language == language_objc)
89aad1f9
EZ
398 {
399 gsymbol->language_specific.cplus_specific.demangled_name = NULL;
400 }
89aad1f9
EZ
401 else
402 {
403 memset (&gsymbol->language_specific, 0,
404 sizeof (gsymbol->language_specific));
405 }
406}
407
2de7ced7
DJ
408/* Functions to initialize a symbol's mangled name. */
409
410/* Create the hash table used for demangled names. Each hash entry is
411 a pair of strings; one for the mangled name and one for the demangled
412 name. The entry is hashed via just the mangled name. */
413
414static void
415create_demangled_names_hash (struct objfile *objfile)
416{
417 /* Choose 256 as the starting size of the hash table, somewhat arbitrarily.
418 The hash table code will round this up to the next prime number.
419 Choosing a much larger table size wastes memory, and saves only about
420 1% in symbol reading. */
421
aa2ee5f6 422 objfile->demangled_names_hash = htab_create_alloc
2de7ced7 423 (256, htab_hash_string, (int (*) (const void *, const void *)) streq,
aa2ee5f6 424 NULL, xcalloc, xfree);
2de7ced7 425}
12af6855 426
2de7ced7 427/* Try to determine the demangled name for a symbol, based on the
12af6855
JB
428 language of that symbol. If the language is set to language_auto,
429 it will attempt to find any demangling algorithm that works and
2de7ced7
DJ
430 then set the language appropriately. The returned name is allocated
431 by the demangler and should be xfree'd. */
12af6855 432
2de7ced7
DJ
433static char *
434symbol_find_demangled_name (struct general_symbol_info *gsymbol,
435 const char *mangled)
12af6855 436{
12af6855
JB
437 char *demangled = NULL;
438
439 if (gsymbol->language == language_unknown)
440 gsymbol->language = language_auto;
1bae87b9
AF
441
442 if (gsymbol->language == language_objc
443 || gsymbol->language == language_auto)
444 {
445 demangled =
446 objc_demangle (mangled, 0);
447 if (demangled != NULL)
448 {
449 gsymbol->language = language_objc;
450 return demangled;
451 }
452 }
12af6855
JB
453 if (gsymbol->language == language_cplus
454 || gsymbol->language == language_auto)
455 {
456 demangled =
2de7ced7 457 cplus_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
12af6855 458 if (demangled != NULL)
2de7ced7
DJ
459 {
460 gsymbol->language = language_cplus;
461 return demangled;
462 }
12af6855
JB
463 }
464 if (gsymbol->language == language_java)
465 {
466 demangled =
2de7ced7 467 cplus_demangle (mangled,
12af6855
JB
468 DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA);
469 if (demangled != NULL)
2de7ced7
DJ
470 {
471 gsymbol->language = language_java;
472 return demangled;
473 }
474 }
475 return NULL;
476}
477
980cae7a
DC
478/* Set both the mangled and demangled (if any) names for GSYMBOL based
479 on LINKAGE_NAME and LEN. The hash table corresponding to OBJFILE
4a146b47 480 is used, and the memory comes from that objfile's objfile_obstack.
980cae7a
DC
481 LINKAGE_NAME is copied, so the pointer can be discarded after
482 calling this function. */
2de7ced7 483
d2a52b27
DC
484/* We have to be careful when dealing with Java names: when we run
485 into a Java minimal symbol, we don't know it's a Java symbol, so it
486 gets demangled as a C++ name. This is unfortunate, but there's not
487 much we can do about it: but when demangling partial symbols and
488 regular symbols, we'd better not reuse the wrong demangled name.
489 (See PR gdb/1039.) We solve this by putting a distinctive prefix
490 on Java names when storing them in the hash table. */
491
492/* FIXME: carlton/2003-03-13: This is an unfortunate situation. I
493 don't mind the Java prefix so much: different languages have
494 different demangling requirements, so it's only natural that we
495 need to keep language data around in our demangling cache. But
496 it's not good that the minimal symbol has the wrong demangled name.
497 Unfortunately, I can't think of any easy solution to that
498 problem. */
499
500#define JAVA_PREFIX "##JAVA$$"
501#define JAVA_PREFIX_LEN 8
502
2de7ced7
DJ
503void
504symbol_set_names (struct general_symbol_info *gsymbol,
980cae7a 505 const char *linkage_name, int len, struct objfile *objfile)
2de7ced7
DJ
506{
507 char **slot;
980cae7a
DC
508 /* A 0-terminated copy of the linkage name. */
509 const char *linkage_name_copy;
d2a52b27
DC
510 /* A copy of the linkage name that might have a special Java prefix
511 added to it, for use when looking names up in the hash table. */
512 const char *lookup_name;
513 /* The length of lookup_name. */
514 int lookup_len;
2de7ced7
DJ
515
516 if (objfile->demangled_names_hash == NULL)
517 create_demangled_names_hash (objfile);
518
980cae7a
DC
519 /* The stabs reader generally provides names that are not
520 NUL-terminated; most of the other readers don't do this, so we
d2a52b27
DC
521 can just use the given copy, unless we're in the Java case. */
522 if (gsymbol->language == language_java)
523 {
524 char *alloc_name;
525 lookup_len = len + JAVA_PREFIX_LEN;
526
527 alloc_name = alloca (lookup_len + 1);
528 memcpy (alloc_name, JAVA_PREFIX, JAVA_PREFIX_LEN);
529 memcpy (alloc_name + JAVA_PREFIX_LEN, linkage_name, len);
530 alloc_name[lookup_len] = '\0';
531
532 lookup_name = alloc_name;
533 linkage_name_copy = alloc_name + JAVA_PREFIX_LEN;
534 }
535 else if (linkage_name[len] != '\0')
2de7ced7 536 {
980cae7a 537 char *alloc_name;
d2a52b27 538 lookup_len = len;
980cae7a 539
d2a52b27 540 alloc_name = alloca (lookup_len + 1);
980cae7a 541 memcpy (alloc_name, linkage_name, len);
d2a52b27 542 alloc_name[lookup_len] = '\0';
980cae7a 543
d2a52b27 544 lookup_name = alloc_name;
980cae7a 545 linkage_name_copy = alloc_name;
2de7ced7
DJ
546 }
547 else
980cae7a 548 {
d2a52b27
DC
549 lookup_len = len;
550 lookup_name = linkage_name;
980cae7a
DC
551 linkage_name_copy = linkage_name;
552 }
2de7ced7 553
980cae7a 554 slot = (char **) htab_find_slot (objfile->demangled_names_hash,
d2a52b27 555 lookup_name, INSERT);
2de7ced7
DJ
556
557 /* If this name is not in the hash table, add it. */
558 if (*slot == NULL)
559 {
980cae7a
DC
560 char *demangled_name = symbol_find_demangled_name (gsymbol,
561 linkage_name_copy);
2de7ced7
DJ
562 int demangled_len = demangled_name ? strlen (demangled_name) : 0;
563
564 /* If there is a demangled name, place it right after the mangled name.
565 Otherwise, just place a second zero byte after the end of the mangled
566 name. */
4a146b47 567 *slot = obstack_alloc (&objfile->objfile_obstack,
d2a52b27
DC
568 lookup_len + demangled_len + 2);
569 memcpy (*slot, lookup_name, lookup_len + 1);
980cae7a 570 if (demangled_name != NULL)
2de7ced7 571 {
d2a52b27 572 memcpy (*slot + lookup_len + 1, demangled_name, demangled_len + 1);
2de7ced7
DJ
573 xfree (demangled_name);
574 }
575 else
d2a52b27 576 (*slot)[lookup_len + 1] = '\0';
2de7ced7
DJ
577 }
578
d2a52b27
DC
579 gsymbol->name = *slot + lookup_len - len;
580 if ((*slot)[lookup_len + 1] != '\0')
2de7ced7 581 gsymbol->language_specific.cplus_specific.demangled_name
d2a52b27 582 = &(*slot)[lookup_len + 1];
2de7ced7
DJ
583 else
584 gsymbol->language_specific.cplus_specific.demangled_name = NULL;
585}
586
587/* Initialize the demangled name of GSYMBOL if possible. Any required space
588 to store the name is obtained from the specified obstack. The function
589 symbol_set_names, above, should be used instead where possible for more
590 efficient memory usage. */
591
592void
593symbol_init_demangled_name (struct general_symbol_info *gsymbol,
594 struct obstack *obstack)
595{
596 char *mangled = gsymbol->name;
597 char *demangled = NULL;
598
599 demangled = symbol_find_demangled_name (gsymbol, mangled);
600 if (gsymbol->language == language_cplus
1bae87b9
AF
601 || gsymbol->language == language_java
602 || gsymbol->language == language_objc)
2de7ced7
DJ
603 {
604 if (demangled)
605 {
606 gsymbol->language_specific.cplus_specific.demangled_name
607 = obsavestring (demangled, strlen (demangled), obstack);
608 xfree (demangled);
609 }
12af6855 610 else
2de7ced7
DJ
611 gsymbol->language_specific.cplus_specific.demangled_name = NULL;
612 }
613 else
614 {
615 /* Unknown language; just clean up quietly. */
616 if (demangled)
617 xfree (demangled);
12af6855 618 }
12af6855
JB
619}
620
22abf04a
DC
621/* Return the source code name of a symbol. In languages where
622 demangling is necessary, this is the demangled name. */
623
624char *
625symbol_natural_name (const struct general_symbol_info *gsymbol)
626{
1f8173e6 627 switch (gsymbol->language)
22abf04a 628 {
1f8173e6
PH
629 case language_cplus:
630 case language_java:
631 case language_objc:
632 if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
633 return gsymbol->language_specific.cplus_specific.demangled_name;
634 break;
635 case language_ada:
636 if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
637 return gsymbol->language_specific.cplus_specific.demangled_name;
638 else
639 return ada_decode_symbol (gsymbol);
640 break;
641 default:
642 break;
22abf04a 643 }
1f8173e6 644 return gsymbol->name;
22abf04a
DC
645}
646
9cc0d196
EZ
647/* Return the demangled name for a symbol based on the language for
648 that symbol. If no demangled name exists, return NULL. */
649char *
650symbol_demangled_name (struct general_symbol_info *gsymbol)
651{
1f8173e6
PH
652 switch (gsymbol->language)
653 {
654 case language_cplus:
655 case language_java:
656 case language_objc:
657 if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
658 return gsymbol->language_specific.cplus_specific.demangled_name;
659 break;
660 case language_ada:
661 if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
662 return gsymbol->language_specific.cplus_specific.demangled_name;
663 else
664 return ada_decode_symbol (gsymbol);
665 break;
666 default:
667 break;
668 }
669 return NULL;
9cc0d196 670}
fe39c653 671
4725b721
PH
672/* Return the search name of a symbol---generally the demangled or
673 linkage name of the symbol, depending on how it will be searched for.
674 If there is no distinct demangled name, then returns the same value
675 (same pointer) as SYMBOL_LINKAGE_NAME. */
fc062ac6
JB
676char *
677symbol_search_name (const struct general_symbol_info *gsymbol)
678{
1f8173e6
PH
679 if (gsymbol->language == language_ada)
680 return gsymbol->name;
681 else
682 return symbol_natural_name (gsymbol);
4725b721
PH
683}
684
fe39c653
EZ
685/* Initialize the structure fields to zero values. */
686void
687init_sal (struct symtab_and_line *sal)
688{
689 sal->symtab = 0;
690 sal->section = 0;
691 sal->line = 0;
692 sal->pc = 0;
693 sal->end = 0;
ed0616c6
VP
694 sal->explicit_pc = 0;
695 sal->explicit_line = 0;
fe39c653 696}
c906108c
SS
697\f
698
94277a38
DJ
699/* Return 1 if the two sections are the same, or if they could
700 plausibly be copies of each other, one in an original object
701 file and another in a separated debug file. */
702
703int
704matching_bfd_sections (asection *first, asection *second)
705{
706 struct objfile *obj;
707
708 /* If they're the same section, then they match. */
709 if (first == second)
710 return 1;
711
712 /* If either is NULL, give up. */
713 if (first == NULL || second == NULL)
714 return 0;
715
716 /* This doesn't apply to absolute symbols. */
717 if (first->owner == NULL || second->owner == NULL)
718 return 0;
719
720 /* If they're in the same object file, they must be different sections. */
721 if (first->owner == second->owner)
722 return 0;
723
724 /* Check whether the two sections are potentially corresponding. They must
725 have the same size, address, and name. We can't compare section indexes,
726 which would be more reliable, because some sections may have been
727 stripped. */
728 if (bfd_get_section_size (first) != bfd_get_section_size (second))
729 return 0;
730
818f79f6 731 /* In-memory addresses may start at a different offset, relativize them. */
94277a38 732 if (bfd_get_section_vma (first->owner, first)
818f79f6
DJ
733 - bfd_get_start_address (first->owner)
734 != bfd_get_section_vma (second->owner, second)
735 - bfd_get_start_address (second->owner))
94277a38
DJ
736 return 0;
737
738 if (bfd_get_section_name (first->owner, first) == NULL
739 || bfd_get_section_name (second->owner, second) == NULL
740 || strcmp (bfd_get_section_name (first->owner, first),
741 bfd_get_section_name (second->owner, second)) != 0)
742 return 0;
743
744 /* Otherwise check that they are in corresponding objfiles. */
745
746 ALL_OBJFILES (obj)
747 if (obj->obfd == first->owner)
748 break;
749 gdb_assert (obj != NULL);
750
751 if (obj->separate_debug_objfile != NULL
752 && obj->separate_debug_objfile->obfd == second->owner)
753 return 1;
754 if (obj->separate_debug_objfile_backlink != NULL
755 && obj->separate_debug_objfile_backlink->obfd == second->owner)
756 return 1;
757
758 return 0;
759}
c5aa993b 760
ccefbec3
EZ
761/* Find which partial symtab contains PC and SECTION. Return 0 if
762 none. We return the psymtab that contains a symbol whose address
763 exactly matches PC, or, if we cannot find an exact match, the
764 psymtab that contains a symbol whose address is closest to PC. */
c906108c 765struct partial_symtab *
fba45db2 766find_pc_sect_psymtab (CORE_ADDR pc, asection *section)
c906108c 767{
52f0bd74
AC
768 struct partial_symtab *pst;
769 struct objfile *objfile;
8a48e967
DJ
770 struct minimal_symbol *msymbol;
771
772 /* If we know that this is not a text address, return failure. This is
773 necessary because we loop based on texthigh and textlow, which do
774 not include the data ranges. */
775 msymbol = lookup_minimal_symbol_by_pc_section (pc, section);
776 if (msymbol
777 && (msymbol->type == mst_data
778 || msymbol->type == mst_bss
779 || msymbol->type == mst_abs
780 || msymbol->type == mst_file_data
781 || msymbol->type == mst_file_bss))
782 return NULL;
c906108c
SS
783
784 ALL_PSYMTABS (objfile, pst)
c5aa993b 785 {
c5aa993b 786 if (pc >= pst->textlow && pc < pst->texthigh)
c5aa993b 787 {
c5aa993b 788 struct partial_symtab *tpst;
ccefbec3 789 struct partial_symtab *best_pst = pst;
d1c79ecd 790 CORE_ADDR best_addr = pst->textlow;
c5aa993b
JM
791
792 /* An objfile that has its functions reordered might have
793 many partial symbol tables containing the PC, but
794 we want the partial symbol table that contains the
795 function containing the PC. */
796 if (!(objfile->flags & OBJF_REORDERED) &&
797 section == 0) /* can't validate section this way */
798 return (pst);
799
c5aa993b
JM
800 if (msymbol == NULL)
801 return (pst);
802
ccefbec3
EZ
803 /* The code range of partial symtabs sometimes overlap, so, in
804 the loop below, we need to check all partial symtabs and
805 find the one that fits better for the given PC address. We
806 select the partial symtab that contains a symbol whose
807 address is closest to the PC address. By closest we mean
808 that find_pc_sect_symbol returns the symbol with address
809 that is closest and still less than the given PC. */
c5aa993b
JM
810 for (tpst = pst; tpst != NULL; tpst = tpst->next)
811 {
c5aa993b 812 if (pc >= tpst->textlow && pc < tpst->texthigh)
c5aa993b
JM
813 {
814 struct partial_symbol *p;
d1c79ecd 815 CORE_ADDR this_addr;
c906108c 816
d1c79ecd
DJ
817 /* NOTE: This assumes that every psymbol has a
818 corresponding msymbol, which is not necessarily
819 true; the debug info might be much richer than the
820 object's symbol table. */
c5aa993b
JM
821 p = find_pc_sect_psymbol (tpst, pc, section);
822 if (p != NULL
823 && SYMBOL_VALUE_ADDRESS (p)
824 == SYMBOL_VALUE_ADDRESS (msymbol))
825 return (tpst);
d1c79ecd
DJ
826
827 /* Also accept the textlow value of a psymtab as a
828 "symbol", to provide some support for partial
829 symbol tables with line information but no debug
830 symbols (e.g. those produced by an assembler). */
ccefbec3 831 if (p != NULL)
d1c79ecd
DJ
832 this_addr = SYMBOL_VALUE_ADDRESS (p);
833 else
834 this_addr = tpst->textlow;
835
836 /* Check whether it is closer than our current
837 BEST_ADDR. Since this symbol address is
838 necessarily lower or equal to PC, the symbol closer
839 to PC is the symbol which address is the highest.
840 This way we return the psymtab which contains such
841 best match symbol. This can help in cases where the
842 symbol information/debuginfo is not complete, like
843 for instance on IRIX6 with gcc, where no debug info
844 is emitted for statics. (See also the nodebug.exp
845 testcase.) */
846 if (this_addr > best_addr)
ccefbec3 847 {
d1c79ecd
DJ
848 best_addr = this_addr;
849 best_pst = tpst;
ccefbec3 850 }
c5aa993b
JM
851 }
852 }
ccefbec3 853 return (best_pst);
c5aa993b
JM
854 }
855 }
c906108c
SS
856 return (NULL);
857}
858
859/* Find which partial symtab contains PC. Return 0 if none.
860 Backward compatibility, no section */
861
862struct partial_symtab *
fba45db2 863find_pc_psymtab (CORE_ADDR pc)
c906108c
SS
864{
865 return find_pc_sect_psymtab (pc, find_pc_mapped_section (pc));
866}
867
868/* Find which partial symbol within a psymtab matches PC and SECTION.
869 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
870
871struct partial_symbol *
fba45db2
KB
872find_pc_sect_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc,
873 asection *section)
c906108c
SS
874{
875 struct partial_symbol *best = NULL, *p, **pp;
876 CORE_ADDR best_pc;
c5aa993b 877
c906108c
SS
878 if (!psymtab)
879 psymtab = find_pc_sect_psymtab (pc, section);
880 if (!psymtab)
881 return 0;
882
883 /* Cope with programs that start at address 0 */
884 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
885
886 /* Search the global symbols as well as the static symbols, so that
887 find_pc_partial_function doesn't use a minimal symbol and thus
888 cache a bad endaddr. */
889 for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
c5aa993b
JM
890 (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
891 < psymtab->n_global_syms);
c906108c
SS
892 pp++)
893 {
894 p = *pp;
176620f1 895 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
c906108c
SS
896 && SYMBOL_CLASS (p) == LOC_BLOCK
897 && pc >= SYMBOL_VALUE_ADDRESS (p)
898 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
899 || (psymtab->textlow == 0
900 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
901 {
c5aa993b 902 if (section) /* match on a specific section */
c906108c
SS
903 {
904 fixup_psymbol_section (p, psymtab->objfile);
94277a38 905 if (!matching_bfd_sections (SYMBOL_BFD_SECTION (p), section))
c906108c
SS
906 continue;
907 }
908 best_pc = SYMBOL_VALUE_ADDRESS (p);
909 best = p;
910 }
911 }
912
913 for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
c5aa993b
JM
914 (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
915 < psymtab->n_static_syms);
c906108c
SS
916 pp++)
917 {
918 p = *pp;
176620f1 919 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
c906108c
SS
920 && SYMBOL_CLASS (p) == LOC_BLOCK
921 && pc >= SYMBOL_VALUE_ADDRESS (p)
922 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
c5aa993b 923 || (psymtab->textlow == 0
c906108c
SS
924 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
925 {
c5aa993b 926 if (section) /* match on a specific section */
c906108c
SS
927 {
928 fixup_psymbol_section (p, psymtab->objfile);
94277a38 929 if (!matching_bfd_sections (SYMBOL_BFD_SECTION (p), section))
c906108c
SS
930 continue;
931 }
932 best_pc = SYMBOL_VALUE_ADDRESS (p);
933 best = p;
934 }
935 }
936
937 return best;
938}
939
940/* Find which partial symbol within a psymtab matches PC. Return 0 if none.
941 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
942
943struct partial_symbol *
fba45db2 944find_pc_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc)
c906108c
SS
945{
946 return find_pc_sect_psymbol (psymtab, pc, find_pc_mapped_section (pc));
947}
948\f
949/* Debug symbols usually don't have section information. We need to dig that
950 out of the minimal symbols and stash that in the debug symbol. */
951
952static void
fba45db2 953fixup_section (struct general_symbol_info *ginfo, struct objfile *objfile)
c906108c
SS
954{
955 struct minimal_symbol *msym;
956 msym = lookup_minimal_symbol (ginfo->name, NULL, objfile);
957
958 if (msym)
7a78d0ee
KB
959 {
960 ginfo->bfd_section = SYMBOL_BFD_SECTION (msym);
961 ginfo->section = SYMBOL_SECTION (msym);
962 }
19e2d14b
KB
963 else if (objfile)
964 {
965 /* Static, function-local variables do appear in the linker
966 (minimal) symbols, but are frequently given names that won't
967 be found via lookup_minimal_symbol(). E.g., it has been
968 observed in frv-uclinux (ELF) executables that a static,
969 function-local variable named "foo" might appear in the
970 linker symbols as "foo.6" or "foo.3". Thus, there is no
971 point in attempting to extend the lookup-by-name mechanism to
972 handle this case due to the fact that there can be multiple
973 names.
974
975 So, instead, search the section table when lookup by name has
976 failed. The ``addr'' and ``endaddr'' fields may have already
977 been relocated. If so, the relocation offset (i.e. the
978 ANOFFSET value) needs to be subtracted from these values when
979 performing the comparison. We unconditionally subtract it,
980 because, when no relocation has been performed, the ANOFFSET
981 value will simply be zero.
982
983 The address of the symbol whose section we're fixing up HAS
984 NOT BEEN adjusted (relocated) yet. It can't have been since
985 the section isn't yet known and knowing the section is
986 necessary in order to add the correct relocation value. In
987 other words, we wouldn't even be in this function (attempting
988 to compute the section) if it were already known.
989
990 Note that it is possible to search the minimal symbols
991 (subtracting the relocation value if necessary) to find the
992 matching minimal symbol, but this is overkill and much less
993 efficient. It is not necessary to find the matching minimal
994 symbol, only its section.
995
996 Note that this technique (of doing a section table search)
997 can fail when unrelocated section addresses overlap. For
998 this reason, we still attempt a lookup by name prior to doing
999 a search of the section table. */
1000
1001 CORE_ADDR addr;
1002 struct obj_section *s;
1003
1004 addr = ginfo->value.address;
1005
1006 ALL_OBJFILE_OSECTIONS (objfile, s)
1007 {
1008 int idx = s->the_bfd_section->index;
1009 CORE_ADDR offset = ANOFFSET (objfile->section_offsets, idx);
1010
1011 if (s->addr - offset <= addr && addr < s->endaddr - offset)
1012 {
1013 ginfo->bfd_section = s->the_bfd_section;
1014 ginfo->section = idx;
1015 return;
1016 }
1017 }
1018 }
c906108c
SS
1019}
1020
1021struct symbol *
fba45db2 1022fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
c906108c
SS
1023{
1024 if (!sym)
1025 return NULL;
1026
1027 if (SYMBOL_BFD_SECTION (sym))
1028 return sym;
1029
1030 fixup_section (&sym->ginfo, objfile);
1031
1032 return sym;
1033}
1034
7a78d0ee 1035struct partial_symbol *
fba45db2 1036fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
c906108c
SS
1037{
1038 if (!psym)
1039 return NULL;
1040
1041 if (SYMBOL_BFD_SECTION (psym))
1042 return psym;
1043
1044 fixup_section (&psym->ginfo, objfile);
1045
1046 return psym;
1047}
1048
1049/* Find the definition for a specified symbol name NAME
176620f1 1050 in domain DOMAIN, visible from lexical block BLOCK.
c906108c
SS
1051 Returns the struct symbol pointer, or zero if no symbol is found.
1052 If SYMTAB is non-NULL, store the symbol table in which the
1053 symbol was found there, or NULL if not found.
1054 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
1055 NAME is a field of the current implied argument `this'. If so set
1056 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
1057 BLOCK_FOUND is set to the block in which NAME is found (in the case of
1058 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
1059
1060/* This function has a bunch of loops in it and it would seem to be
1061 attractive to put in some QUIT's (though I'm not really sure
1062 whether it can run long enough to be really important). But there
1063 are a few calls for which it would appear to be bad news to quit
7ca9f392
AC
1064 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c. (Note
1065 that there is C++ code below which can error(), but that probably
1066 doesn't affect these calls since they are looking for a known
1067 variable and thus can probably assume it will never hit the C++
1068 code). */
c906108c
SS
1069
1070struct symbol *
53c5240f
PA
1071lookup_symbol_in_language (const char *name, const struct block *block,
1072 const domain_enum domain, enum language lang,
1073 int *is_a_field_of_this,
1074 struct symtab **symtab)
c906108c 1075{
729051e6
DJ
1076 char *demangled_name = NULL;
1077 const char *modified_name = NULL;
3121eff0 1078 const char *mangled_name = NULL;
fba7f19c
EZ
1079 int needtofreename = 0;
1080 struct symbol *returnval;
c906108c 1081
729051e6
DJ
1082 modified_name = name;
1083
987504bb 1084 /* If we are using C++ or Java, demangle the name before doing a lookup, so
729051e6 1085 we can always binary search. */
53c5240f 1086 if (lang == language_cplus)
729051e6
DJ
1087 {
1088 demangled_name = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS);
1089 if (demangled_name)
1090 {
1091 mangled_name = name;
1092 modified_name = demangled_name;
1093 needtofreename = 1;
1094 }
1095 }
53c5240f 1096 else if (lang == language_java)
987504bb
JJ
1097 {
1098 demangled_name = cplus_demangle (name,
1099 DMGL_ANSI | DMGL_PARAMS | DMGL_JAVA);
1100 if (demangled_name)
1101 {
1102 mangled_name = name;
1103 modified_name = demangled_name;
1104 needtofreename = 1;
1105 }
1106 }
729051e6 1107
63872f9d
JG
1108 if (case_sensitivity == case_sensitive_off)
1109 {
1110 char *copy;
1111 int len, i;
1112
1113 len = strlen (name);
1114 copy = (char *) alloca (len + 1);
1115 for (i= 0; i < len; i++)
1116 copy[i] = tolower (name[i]);
1117 copy[len] = 0;
fba7f19c 1118 modified_name = copy;
63872f9d 1119 }
fba7f19c 1120
3121eff0 1121 returnval = lookup_symbol_aux (modified_name, mangled_name, block,
53c5240f
PA
1122 domain, lang,
1123 is_a_field_of_this, symtab);
fba7f19c 1124 if (needtofreename)
729051e6 1125 xfree (demangled_name);
fba7f19c 1126
cb1df416
DJ
1127 /* Override the returned symtab with the symbol's specific one. */
1128 if (returnval != NULL && symtab != NULL)
1129 *symtab = SYMBOL_SYMTAB (returnval);
1130
fba7f19c
EZ
1131 return returnval;
1132}
1133
53c5240f
PA
1134/* Behave like lookup_symbol_in_language, but performed with the
1135 current language. */
1136
1137struct symbol *
1138lookup_symbol (const char *name, const struct block *block,
1139 domain_enum domain, int *is_a_field_of_this,
1140 struct symtab **symtab)
1141{
1142 return lookup_symbol_in_language (name, block, domain,
1143 current_language->la_language,
1144 is_a_field_of_this, symtab);
1145}
1146
1147/* Behave like lookup_symbol except that NAME is the natural name
5ad1c190
DC
1148 of the symbol that we're looking for and, if LINKAGE_NAME is
1149 non-NULL, ensure that the symbol's linkage name matches as
1150 well. */
1151
fba7f19c 1152static struct symbol *
5ad1c190 1153lookup_symbol_aux (const char *name, const char *linkage_name,
176620f1 1154 const struct block *block, const domain_enum domain,
53c5240f 1155 enum language language,
3121eff0 1156 int *is_a_field_of_this, struct symtab **symtab)
fba7f19c 1157{
8155455b 1158 struct symbol *sym;
53c5240f 1159 const struct language_defn *langdef;
406bc4de 1160
9a146a11
EZ
1161 /* Make sure we do something sensible with is_a_field_of_this, since
1162 the callers that set this parameter to some non-null value will
1163 certainly use it later and expect it to be either 0 or 1.
1164 If we don't set it, the contents of is_a_field_of_this are
1165 undefined. */
1166 if (is_a_field_of_this != NULL)
1167 *is_a_field_of_this = 0;
1168
e4051eeb
DC
1169 /* Search specified block and its superiors. Don't search
1170 STATIC_BLOCK or GLOBAL_BLOCK. */
c906108c 1171
5ad1c190 1172 sym = lookup_symbol_aux_local (name, linkage_name, block, domain,
89a9d1b1 1173 symtab);
8155455b
DC
1174 if (sym != NULL)
1175 return sym;
c906108c 1176
53c5240f
PA
1177 /* If requested to do so by the caller and if appropriate for LANGUAGE,
1178 check to see if NAME is a field of `this'. */
1179
1180 langdef = language_def (language);
5f9a71c3 1181
53c5240f 1182 if (langdef->la_value_of_this != NULL
5f9a71c3 1183 && is_a_field_of_this != NULL)
c906108c 1184 {
53c5240f 1185 struct value *v = langdef->la_value_of_this (0);
c5aa993b 1186
c906108c
SS
1187 if (v && check_field (v, name))
1188 {
1189 *is_a_field_of_this = 1;
1190 if (symtab != NULL)
1191 *symtab = NULL;
1192 return NULL;
1193 }
1194 }
1195
53c5240f 1196 /* Now do whatever is appropriate for LANGUAGE to look
5f9a71c3 1197 up static and global variables. */
c906108c 1198
53c5240f
PA
1199 sym = langdef->la_lookup_symbol_nonlocal (name, linkage_name,
1200 block, domain, symtab);
8155455b
DC
1201 if (sym != NULL)
1202 return sym;
c906108c 1203
8155455b
DC
1204 /* Now search all static file-level symbols. Not strictly correct,
1205 but more useful than an error. Do the symtabs first, then check
1206 the psymtabs. If a psymtab indicates the existence of the
1207 desired name as a file-level static, then do psymtab-to-symtab
c906108c
SS
1208 conversion on the fly and return the found symbol. */
1209
5ad1c190 1210 sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, linkage_name,
176620f1 1211 domain, symtab);
8155455b
DC
1212 if (sym != NULL)
1213 return sym;
1214
5ad1c190 1215 sym = lookup_symbol_aux_psymtabs (STATIC_BLOCK, name, linkage_name,
176620f1 1216 domain, symtab);
8155455b
DC
1217 if (sym != NULL)
1218 return sym;
c906108c 1219
c906108c
SS
1220 if (symtab != NULL)
1221 *symtab = NULL;
8155455b 1222 return NULL;
c906108c 1223}
8155455b 1224
e4051eeb 1225/* Check to see if the symbol is defined in BLOCK or its superiors.
89a9d1b1 1226 Don't search STATIC_BLOCK or GLOBAL_BLOCK. */
8155455b
DC
1227
1228static struct symbol *
5ad1c190 1229lookup_symbol_aux_local (const char *name, const char *linkage_name,
8155455b 1230 const struct block *block,
176620f1 1231 const domain_enum domain,
89a9d1b1 1232 struct symtab **symtab)
8155455b
DC
1233{
1234 struct symbol *sym;
89a9d1b1
DC
1235 const struct block *static_block = block_static_block (block);
1236
e4051eeb
DC
1237 /* Check if either no block is specified or it's a global block. */
1238
89a9d1b1
DC
1239 if (static_block == NULL)
1240 return NULL;
e4051eeb 1241
89a9d1b1 1242 while (block != static_block)
f61e8913 1243 {
5ad1c190 1244 sym = lookup_symbol_aux_block (name, linkage_name, block, domain,
f61e8913
DC
1245 symtab);
1246 if (sym != NULL)
1247 return sym;
1248 block = BLOCK_SUPERBLOCK (block);
1249 }
1250
89a9d1b1 1251 /* We've reached the static block without finding a result. */
e4051eeb 1252
f61e8913
DC
1253 return NULL;
1254}
1255
3a40aaa0
UW
1256/* Look up OBJFILE to BLOCK. */
1257
1258static struct objfile *
1259lookup_objfile_from_block (const struct block *block)
1260{
1261 struct objfile *obj;
1262 struct symtab *s;
1263
1264 if (block == NULL)
1265 return NULL;
1266
1267 block = block_global_block (block);
1268 /* Go through SYMTABS. */
1269 ALL_SYMTABS (obj, s)
1270 if (block == BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK))
1271 return obj;
1272
1273 return NULL;
1274}
1275
f61e8913
DC
1276/* Look up a symbol in a block; if found, locate its symtab, fixup the
1277 symbol, and set block_found appropriately. */
1278
5f9a71c3 1279struct symbol *
5ad1c190 1280lookup_symbol_aux_block (const char *name, const char *linkage_name,
f61e8913 1281 const struct block *block,
176620f1 1282 const domain_enum domain,
f61e8913
DC
1283 struct symtab **symtab)
1284{
1285 struct symbol *sym;
8155455b
DC
1286 struct objfile *objfile = NULL;
1287 struct blockvector *bv;
1288 struct block *b;
1289 struct symtab *s = NULL;
f61e8913 1290
5ad1c190 1291 sym = lookup_block_symbol (block, name, linkage_name, domain);
f61e8913 1292 if (sym)
8155455b 1293 {
f61e8913
DC
1294 block_found = block;
1295 if (symtab != NULL)
8155455b 1296 {
f61e8913
DC
1297 /* Search the list of symtabs for one which contains the
1298 address of the start of this block. */
11309657 1299 ALL_PRIMARY_SYMTABS (objfile, s)
8155455b 1300 {
f61e8913
DC
1301 bv = BLOCKVECTOR (s);
1302 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1303 if (BLOCK_START (b) <= BLOCK_START (block)
1304 && BLOCK_END (b) > BLOCK_START (block))
1305 goto found;
8155455b 1306 }
f61e8913
DC
1307 found:
1308 *symtab = s;
8155455b 1309 }
f61e8913
DC
1310
1311 return fixup_symbol_section (sym, objfile);
8155455b
DC
1312 }
1313
1314 return NULL;
1315}
1316
3a40aaa0
UW
1317/* Check all global symbols in OBJFILE in symtabs and
1318 psymtabs. */
1319
1320struct symbol *
1321lookup_global_symbol_from_objfile (const struct objfile *objfile,
1322 const char *name,
1323 const char *linkage_name,
1324 const domain_enum domain,
1325 struct symtab **symtab)
1326{
1327 struct symbol *sym;
1328 struct blockvector *bv;
1329 const struct block *block;
1330 struct symtab *s;
1331 struct partial_symtab *ps;
1332
1333 /* Go through symtabs. */
1334 ALL_OBJFILE_SYMTABS (objfile, s)
1335 {
1336 bv = BLOCKVECTOR (s);
1337 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1338 sym = lookup_block_symbol (block, name, linkage_name, domain);
1339 if (sym)
1340 {
1341 block_found = block;
1342 if (symtab != NULL)
1343 *symtab = s;
1344 return fixup_symbol_section (sym, (struct objfile *)objfile);
1345 }
1346 }
1347
1348 /* Now go through psymtabs. */
1349 ALL_OBJFILE_PSYMTABS (objfile, ps)
1350 {
1351 if (!ps->readin
1352 && lookup_partial_symbol (ps, name, linkage_name,
1353 1, domain))
1354 {
1355 s = PSYMTAB_TO_SYMTAB (ps);
1356 bv = BLOCKVECTOR (s);
1357 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1358 sym = lookup_block_symbol (block, name, linkage_name, domain);
1359 if (symtab != NULL)
1360 *symtab = s;
1361 return fixup_symbol_section (sym, (struct objfile *)objfile);
1362 }
1363 }
1364
1365 return NULL;
1366}
1367
8155455b
DC
1368/* Check to see if the symbol is defined in one of the symtabs.
1369 BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
1370 depending on whether or not we want to search global symbols or
1371 static symbols. */
1372
1373static struct symbol *
1374lookup_symbol_aux_symtabs (int block_index,
5ad1c190 1375 const char *name, const char *linkage_name,
176620f1 1376 const domain_enum domain,
8155455b
DC
1377 struct symtab **symtab)
1378{
1379 struct symbol *sym;
1380 struct objfile *objfile;
1381 struct blockvector *bv;
1382 const struct block *block;
1383 struct symtab *s;
1384
11309657 1385 ALL_PRIMARY_SYMTABS (objfile, s)
8155455b
DC
1386 {
1387 bv = BLOCKVECTOR (s);
1388 block = BLOCKVECTOR_BLOCK (bv, block_index);
5ad1c190 1389 sym = lookup_block_symbol (block, name, linkage_name, domain);
8155455b
DC
1390 if (sym)
1391 {
1392 block_found = block;
1393 if (symtab != NULL)
1394 *symtab = s;
1395 return fixup_symbol_section (sym, objfile);
1396 }
1397 }
1398
1399 return NULL;
1400}
1401
1402/* Check to see if the symbol is defined in one of the partial
1403 symtabs. BLOCK_INDEX should be either GLOBAL_BLOCK or
1404 STATIC_BLOCK, depending on whether or not we want to search global
1405 symbols or static symbols. */
1406
1407static struct symbol *
1408lookup_symbol_aux_psymtabs (int block_index, const char *name,
5ad1c190 1409 const char *linkage_name,
176620f1 1410 const domain_enum domain,
8155455b
DC
1411 struct symtab **symtab)
1412{
1413 struct symbol *sym;
1414 struct objfile *objfile;
1415 struct blockvector *bv;
1416 const struct block *block;
1417 struct partial_symtab *ps;
1418 struct symtab *s;
1419 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
1420
1421 ALL_PSYMTABS (objfile, ps)
1422 {
1423 if (!ps->readin
5ad1c190 1424 && lookup_partial_symbol (ps, name, linkage_name,
176620f1 1425 psymtab_index, domain))
8155455b
DC
1426 {
1427 s = PSYMTAB_TO_SYMTAB (ps);
1428 bv = BLOCKVECTOR (s);
1429 block = BLOCKVECTOR_BLOCK (bv, block_index);
5ad1c190 1430 sym = lookup_block_symbol (block, name, linkage_name, domain);
8155455b
DC
1431 if (!sym)
1432 {
1433 /* This shouldn't be necessary, but as a last resort try
1434 looking in the statics even though the psymtab claimed
1435 the symbol was global, or vice-versa. It's possible
1436 that the psymtab gets it wrong in some cases. */
1437
1438 /* FIXME: carlton/2002-09-30: Should we really do that?
1439 If that happens, isn't it likely to be a GDB error, in
1440 which case we should fix the GDB error rather than
1441 silently dealing with it here? So I'd vote for
1442 removing the check for the symbol in the other
1443 block. */
1444 block = BLOCKVECTOR_BLOCK (bv,
1445 block_index == GLOBAL_BLOCK ?
1446 STATIC_BLOCK : GLOBAL_BLOCK);
5ad1c190 1447 sym = lookup_block_symbol (block, name, linkage_name, domain);
8155455b 1448 if (!sym)
8a3fe4f8 1449 error (_("Internal: %s symbol `%s' found in %s psymtab but not in symtab.\n%s may be an inlined function, or may be a template function\n(if a template, try specifying an instantiation: %s<type>)."),
8155455b
DC
1450 block_index == GLOBAL_BLOCK ? "global" : "static",
1451 name, ps->filename, name, name);
1452 }
1453 if (symtab != NULL)
1454 *symtab = s;
1455 return fixup_symbol_section (sym, objfile);
1456 }
1457 }
1458
1459 return NULL;
1460}
1461
5f9a71c3
DC
1462/* A default version of lookup_symbol_nonlocal for use by languages
1463 that can't think of anything better to do. This implements the C
1464 lookup rules. */
1465
1466struct symbol *
1467basic_lookup_symbol_nonlocal (const char *name,
1468 const char *linkage_name,
1469 const struct block *block,
1470 const domain_enum domain,
1471 struct symtab **symtab)
1472{
1473 struct symbol *sym;
1474
1475 /* NOTE: carlton/2003-05-19: The comments below were written when
1476 this (or what turned into this) was part of lookup_symbol_aux;
1477 I'm much less worried about these questions now, since these
1478 decisions have turned out well, but I leave these comments here
1479 for posterity. */
1480
1481 /* NOTE: carlton/2002-12-05: There is a question as to whether or
1482 not it would be appropriate to search the current global block
1483 here as well. (That's what this code used to do before the
1484 is_a_field_of_this check was moved up.) On the one hand, it's
1485 redundant with the lookup_symbol_aux_symtabs search that happens
1486 next. On the other hand, if decode_line_1 is passed an argument
1487 like filename:var, then the user presumably wants 'var' to be
1488 searched for in filename. On the third hand, there shouldn't be
1489 multiple global variables all of which are named 'var', and it's
1490 not like decode_line_1 has ever restricted its search to only
1491 global variables in a single filename. All in all, only
1492 searching the static block here seems best: it's correct and it's
1493 cleanest. */
1494
1495 /* NOTE: carlton/2002-12-05: There's also a possible performance
1496 issue here: if you usually search for global symbols in the
1497 current file, then it would be slightly better to search the
1498 current global block before searching all the symtabs. But there
1499 are other factors that have a much greater effect on performance
1500 than that one, so I don't think we should worry about that for
1501 now. */
1502
1503 sym = lookup_symbol_static (name, linkage_name, block, domain, symtab);
1504 if (sym != NULL)
1505 return sym;
1506
3a40aaa0 1507 return lookup_symbol_global (name, linkage_name, block, domain, symtab);
5f9a71c3
DC
1508}
1509
1510/* Lookup a symbol in the static block associated to BLOCK, if there
1511 is one; do nothing if BLOCK is NULL or a global block. */
1512
1513struct symbol *
1514lookup_symbol_static (const char *name,
1515 const char *linkage_name,
1516 const struct block *block,
1517 const domain_enum domain,
1518 struct symtab **symtab)
1519{
1520 const struct block *static_block = block_static_block (block);
1521
1522 if (static_block != NULL)
1523 return lookup_symbol_aux_block (name, linkage_name, static_block,
1524 domain, symtab);
1525 else
1526 return NULL;
1527}
1528
1529/* Lookup a symbol in all files' global blocks (searching psymtabs if
1530 necessary). */
1531
1532struct symbol *
1533lookup_symbol_global (const char *name,
1534 const char *linkage_name,
3a40aaa0 1535 const struct block *block,
5f9a71c3
DC
1536 const domain_enum domain,
1537 struct symtab **symtab)
1538{
3a40aaa0
UW
1539 struct symbol *sym = NULL;
1540 struct objfile *objfile = NULL;
1541
1542 /* Call library-specific lookup procedure. */
1543 objfile = lookup_objfile_from_block (block);
1544 if (objfile != NULL)
1545 sym = solib_global_lookup (objfile, name, linkage_name, domain, symtab);
1546 if (sym != NULL)
1547 return sym;
5f9a71c3
DC
1548
1549 sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, linkage_name,
1550 domain, symtab);
1551 if (sym != NULL)
1552 return sym;
1553
1554 return lookup_symbol_aux_psymtabs (GLOBAL_BLOCK, name, linkage_name,
1555 domain, symtab);
1556}
1557
3d4e8fd2
DC
1558/* Look, in partial_symtab PST, for symbol whose natural name is NAME.
1559 If LINKAGE_NAME is non-NULL, check in addition that the symbol's
1560 linkage name matches it. Check the global symbols if GLOBAL, the
1561 static symbols if not */
c906108c 1562
b6429628 1563struct partial_symbol *
3d4e8fd2
DC
1564lookup_partial_symbol (struct partial_symtab *pst, const char *name,
1565 const char *linkage_name, int global,
176620f1 1566 domain_enum domain)
c906108c 1567{
357e46e7 1568 struct partial_symbol *temp;
c906108c 1569 struct partial_symbol **start, **psym;
38d49aff 1570 struct partial_symbol **top, **real_top, **bottom, **center;
c906108c
SS
1571 int length = (global ? pst->n_global_syms : pst->n_static_syms);
1572 int do_linear_search = 1;
357e46e7 1573
c906108c
SS
1574 if (length == 0)
1575 {
1576 return (NULL);
1577 }
c906108c
SS
1578 start = (global ?
1579 pst->objfile->global_psymbols.list + pst->globals_offset :
c5aa993b 1580 pst->objfile->static_psymbols.list + pst->statics_offset);
357e46e7 1581
c5aa993b 1582 if (global) /* This means we can use a binary search. */
c906108c
SS
1583 {
1584 do_linear_search = 0;
1585
1586 /* Binary search. This search is guaranteed to end with center
0fe19209
DC
1587 pointing at the earliest partial symbol whose name might be
1588 correct. At that point *all* partial symbols with an
1589 appropriate name will be checked against the correct
176620f1 1590 domain. */
c906108c
SS
1591
1592 bottom = start;
1593 top = start + length - 1;
38d49aff 1594 real_top = top;
c906108c
SS
1595 while (top > bottom)
1596 {
1597 center = bottom + (top - bottom) / 2;
1598 if (!(center < top))
e2e0b3e5 1599 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
c906108c 1600 if (!do_linear_search
357e46e7 1601 && (SYMBOL_LANGUAGE (*center) == language_java))
c906108c
SS
1602 {
1603 do_linear_search = 1;
1604 }
4725b721 1605 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center), name) >= 0)
c906108c
SS
1606 {
1607 top = center;
1608 }
1609 else
1610 {
1611 bottom = center + 1;
1612 }
1613 }
1614 if (!(top == bottom))
e2e0b3e5 1615 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
357e46e7 1616
3d4e8fd2
DC
1617 while (top <= real_top
1618 && (linkage_name != NULL
1619 ? strcmp (SYMBOL_LINKAGE_NAME (*top), linkage_name) == 0
4725b721 1620 : SYMBOL_MATCHES_SEARCH_NAME (*top,name)))
c906108c 1621 {
176620f1 1622 if (SYMBOL_DOMAIN (*top) == domain)
c906108c 1623 {
357e46e7 1624 return (*top);
c906108c 1625 }
c5aa993b 1626 top++;
c906108c
SS
1627 }
1628 }
1629
1630 /* Can't use a binary search or else we found during the binary search that
1631 we should also do a linear search. */
1632
1633 if (do_linear_search)
357e46e7 1634 {
c906108c
SS
1635 for (psym = start; psym < start + length; psym++)
1636 {
176620f1 1637 if (domain == SYMBOL_DOMAIN (*psym))
c906108c 1638 {
3d4e8fd2
DC
1639 if (linkage_name != NULL
1640 ? strcmp (SYMBOL_LINKAGE_NAME (*psym), linkage_name) == 0
4725b721 1641 : SYMBOL_MATCHES_SEARCH_NAME (*psym, name))
c906108c
SS
1642 {
1643 return (*psym);
1644 }
1645 }
1646 }
1647 }
1648
1649 return (NULL);
1650}
1651
176620f1 1652/* Look up a type named NAME in the struct_domain. The type returned
b368761e
DC
1653 must not be opaque -- i.e., must have at least one field
1654 defined. */
c906108c 1655
b368761e
DC
1656struct type *
1657lookup_transparent_type (const char *name)
1658{
1659 return current_language->la_lookup_transparent_type (name);
1660}
c906108c 1661
b368761e
DC
1662/* The standard implementation of lookup_transparent_type. This code
1663 was modeled on lookup_symbol -- the parts not relevant to looking
1664 up types were just left out. In particular it's assumed here that
1665 types are available in struct_domain and only at file-static or
1666 global blocks. */
c906108c
SS
1667
1668struct type *
b368761e 1669basic_lookup_transparent_type (const char *name)
c906108c 1670{
52f0bd74
AC
1671 struct symbol *sym;
1672 struct symtab *s = NULL;
1673 struct partial_symtab *ps;
c906108c 1674 struct blockvector *bv;
52f0bd74
AC
1675 struct objfile *objfile;
1676 struct block *block;
c906108c
SS
1677
1678 /* Now search all the global symbols. Do the symtab's first, then
1679 check the psymtab's. If a psymtab indicates the existence
1680 of the desired name as a global, then do psymtab-to-symtab
1681 conversion on the fly and return the found symbol. */
c5aa993b 1682
11309657 1683 ALL_PRIMARY_SYMTABS (objfile, s)
c5aa993b
JM
1684 {
1685 bv = BLOCKVECTOR (s);
1686 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
176620f1 1687 sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
c5aa993b
JM
1688 if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1689 {
1690 return SYMBOL_TYPE (sym);
1691 }
1692 }
c906108c
SS
1693
1694 ALL_PSYMTABS (objfile, ps)
c5aa993b 1695 {
3d4e8fd2 1696 if (!ps->readin && lookup_partial_symbol (ps, name, NULL,
176620f1 1697 1, STRUCT_DOMAIN))
c5aa993b
JM
1698 {
1699 s = PSYMTAB_TO_SYMTAB (ps);
1700 bv = BLOCKVECTOR (s);
1701 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
176620f1 1702 sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
c5aa993b
JM
1703 if (!sym)
1704 {
1705 /* This shouldn't be necessary, but as a last resort
1706 * try looking in the statics even though the psymtab
1707 * claimed the symbol was global. It's possible that
1708 * the psymtab gets it wrong in some cases.
1709 */
1710 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
176620f1 1711 sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
c5aa993b 1712 if (!sym)
8a3fe4f8 1713 error (_("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
c906108c 1714%s may be an inlined function, or may be a template function\n\
8a3fe4f8 1715(if a template, try specifying an instantiation: %s<type>)."),
c5aa993b
JM
1716 name, ps->filename, name, name);
1717 }
1718 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1719 return SYMBOL_TYPE (sym);
1720 }
1721 }
c906108c
SS
1722
1723 /* Now search the static file-level symbols.
1724 Not strictly correct, but more useful than an error.
1725 Do the symtab's first, then
1726 check the psymtab's. If a psymtab indicates the existence
1727 of the desired name as a file-level static, then do psymtab-to-symtab
1728 conversion on the fly and return the found symbol.
1729 */
1730
11309657 1731 ALL_PRIMARY_SYMTABS (objfile, s)
c5aa993b
JM
1732 {
1733 bv = BLOCKVECTOR (s);
1734 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
176620f1 1735 sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
c5aa993b
JM
1736 if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1737 {
1738 return SYMBOL_TYPE (sym);
1739 }
1740 }
c906108c
SS
1741
1742 ALL_PSYMTABS (objfile, ps)
c5aa993b 1743 {
176620f1 1744 if (!ps->readin && lookup_partial_symbol (ps, name, NULL, 0, STRUCT_DOMAIN))
c5aa993b
JM
1745 {
1746 s = PSYMTAB_TO_SYMTAB (ps);
1747 bv = BLOCKVECTOR (s);
1748 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
176620f1 1749 sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
c5aa993b
JM
1750 if (!sym)
1751 {
1752 /* This shouldn't be necessary, but as a last resort
1753 * try looking in the globals even though the psymtab
1754 * claimed the symbol was static. It's possible that
1755 * the psymtab gets it wrong in some cases.
1756 */
1757 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
176620f1 1758 sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
c5aa993b 1759 if (!sym)
8a3fe4f8 1760 error (_("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
c906108c 1761%s may be an inlined function, or may be a template function\n\
8a3fe4f8 1762(if a template, try specifying an instantiation: %s<type>)."),
c5aa993b
JM
1763 name, ps->filename, name, name);
1764 }
1765 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1766 return SYMBOL_TYPE (sym);
1767 }
1768 }
c906108c
SS
1769 return (struct type *) 0;
1770}
1771
1772
1773/* Find the psymtab containing main(). */
1774/* FIXME: What about languages without main() or specially linked
1775 executables that have no main() ? */
1776
1777struct partial_symtab *
fba45db2 1778find_main_psymtab (void)
c906108c 1779{
52f0bd74
AC
1780 struct partial_symtab *pst;
1781 struct objfile *objfile;
c906108c
SS
1782
1783 ALL_PSYMTABS (objfile, pst)
c5aa993b 1784 {
176620f1 1785 if (lookup_partial_symbol (pst, main_name (), NULL, 1, VAR_DOMAIN))
c5aa993b
JM
1786 {
1787 return (pst);
1788 }
1789 }
c906108c
SS
1790 return (NULL);
1791}
1792
176620f1 1793/* Search BLOCK for symbol NAME in DOMAIN.
c906108c
SS
1794
1795 Note that if NAME is the demangled form of a C++ symbol, we will fail
1796 to find a match during the binary search of the non-encoded names, but
1797 for now we don't worry about the slight inefficiency of looking for
1798 a match we'll never find, since it will go pretty quick. Once the
1799 binary search terminates, we drop through and do a straight linear
1bae87b9
AF
1800 search on the symbols. Each symbol which is marked as being a ObjC/C++
1801 symbol (language_cplus or language_objc set) has both the encoded and
1802 non-encoded names tested for a match.
3121eff0 1803
5ad1c190 1804 If LINKAGE_NAME is non-NULL, verify that any symbol we find has this
3121eff0
DJ
1805 particular mangled name.
1806*/
c906108c
SS
1807
1808struct symbol *
aa1ee363 1809lookup_block_symbol (const struct block *block, const char *name,
5ad1c190 1810 const char *linkage_name,
176620f1 1811 const domain_enum domain)
c906108c 1812{
de4f826b
DC
1813 struct dict_iterator iter;
1814 struct symbol *sym;
c906108c 1815
de4f826b 1816 if (!BLOCK_FUNCTION (block))
261397f8 1817 {
de4f826b
DC
1818 for (sym = dict_iter_name_first (BLOCK_DICT (block), name, &iter);
1819 sym != NULL;
1820 sym = dict_iter_name_next (name, &iter))
261397f8 1821 {
de4f826b
DC
1822 if (SYMBOL_DOMAIN (sym) == domain
1823 && (linkage_name != NULL
1824 ? strcmp (SYMBOL_LINKAGE_NAME (sym), linkage_name) == 0 : 1))
261397f8
DJ
1825 return sym;
1826 }
1827 return NULL;
1828 }
526e70c0 1829 else
c906108c 1830 {
526e70c0
DC
1831 /* Note that parameter symbols do not always show up last in the
1832 list; this loop makes sure to take anything else other than
1833 parameter symbols first; it only uses parameter symbols as a
1834 last resort. Note that this only takes up extra computation
1835 time on a match. */
de4f826b
DC
1836
1837 struct symbol *sym_found = NULL;
1838
1839 for (sym = dict_iter_name_first (BLOCK_DICT (block), name, &iter);
1840 sym != NULL;
1841 sym = dict_iter_name_next (name, &iter))
c906108c 1842 {
176620f1 1843 if (SYMBOL_DOMAIN (sym) == domain
de4f826b
DC
1844 && (linkage_name != NULL
1845 ? strcmp (SYMBOL_LINKAGE_NAME (sym), linkage_name) == 0 : 1))
c906108c 1846 {
c906108c
SS
1847 sym_found = sym;
1848 if (SYMBOL_CLASS (sym) != LOC_ARG &&
1849 SYMBOL_CLASS (sym) != LOC_LOCAL_ARG &&
1850 SYMBOL_CLASS (sym) != LOC_REF_ARG &&
1851 SYMBOL_CLASS (sym) != LOC_REGPARM &&
1852 SYMBOL_CLASS (sym) != LOC_REGPARM_ADDR &&
4c2df51b
DJ
1853 SYMBOL_CLASS (sym) != LOC_BASEREG_ARG &&
1854 SYMBOL_CLASS (sym) != LOC_COMPUTED_ARG)
c906108c
SS
1855 {
1856 break;
1857 }
1858 }
c906108c 1859 }
de4f826b 1860 return (sym_found); /* Will be NULL if not found. */
c906108c 1861 }
c906108c
SS
1862}
1863
c906108c
SS
1864/* Find the symtab associated with PC and SECTION. Look through the
1865 psymtabs and read in another symtab if necessary. */
1866
1867struct symtab *
fba45db2 1868find_pc_sect_symtab (CORE_ADDR pc, asection *section)
c906108c 1869{
52f0bd74 1870 struct block *b;
c906108c 1871 struct blockvector *bv;
52f0bd74
AC
1872 struct symtab *s = NULL;
1873 struct symtab *best_s = NULL;
1874 struct partial_symtab *ps;
1875 struct objfile *objfile;
c906108c 1876 CORE_ADDR distance = 0;
8a48e967
DJ
1877 struct minimal_symbol *msymbol;
1878
1879 /* If we know that this is not a text address, return failure. This is
1880 necessary because we loop based on the block's high and low code
1881 addresses, which do not include the data ranges, and because
1882 we call find_pc_sect_psymtab which has a similar restriction based
1883 on the partial_symtab's texthigh and textlow. */
1884 msymbol = lookup_minimal_symbol_by_pc_section (pc, section);
1885 if (msymbol
1886 && (msymbol->type == mst_data
1887 || msymbol->type == mst_bss
1888 || msymbol->type == mst_abs
1889 || msymbol->type == mst_file_data
1890 || msymbol->type == mst_file_bss))
1891 return NULL;
c906108c
SS
1892
1893 /* Search all symtabs for the one whose file contains our address, and which
1894 is the smallest of all the ones containing the address. This is designed
1895 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1896 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1897 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1898
1899 This happens for native ecoff format, where code from included files
1900 gets its own symtab. The symtab for the included file should have
1901 been read in already via the dependency mechanism.
1902 It might be swifter to create several symtabs with the same name
1903 like xcoff does (I'm not sure).
1904
1905 It also happens for objfiles that have their functions reordered.
1906 For these, the symtab we are looking for is not necessarily read in. */
1907
11309657 1908 ALL_PRIMARY_SYMTABS (objfile, s)
c5aa993b
JM
1909 {
1910 bv = BLOCKVECTOR (s);
1911 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
c906108c 1912
c5aa993b 1913 if (BLOCK_START (b) <= pc
c5aa993b 1914 && BLOCK_END (b) > pc
c5aa993b
JM
1915 && (distance == 0
1916 || BLOCK_END (b) - BLOCK_START (b) < distance))
1917 {
1918 /* For an objfile that has its functions reordered,
1919 find_pc_psymtab will find the proper partial symbol table
1920 and we simply return its corresponding symtab. */
1921 /* In order to better support objfiles that contain both
1922 stabs and coff debugging info, we continue on if a psymtab
1923 can't be found. */
1924 if ((objfile->flags & OBJF_REORDERED) && objfile->psymtabs)
1925 {
1926 ps = find_pc_sect_psymtab (pc, section);
1927 if (ps)
1928 return PSYMTAB_TO_SYMTAB (ps);
1929 }
1930 if (section != 0)
1931 {
de4f826b 1932 struct dict_iterator iter;
261397f8 1933 struct symbol *sym = NULL;
c906108c 1934
de4f826b 1935 ALL_BLOCK_SYMBOLS (b, iter, sym)
c5aa993b 1936 {
261397f8 1937 fixup_symbol_section (sym, objfile);
94277a38 1938 if (matching_bfd_sections (SYMBOL_BFD_SECTION (sym), section))
c5aa993b
JM
1939 break;
1940 }
de4f826b 1941 if (sym == NULL)
c5aa993b
JM
1942 continue; /* no symbol in this symtab matches section */
1943 }
1944 distance = BLOCK_END (b) - BLOCK_START (b);
1945 best_s = s;
1946 }
1947 }
c906108c
SS
1948
1949 if (best_s != NULL)
c5aa993b 1950 return (best_s);
c906108c
SS
1951
1952 s = NULL;
1953 ps = find_pc_sect_psymtab (pc, section);
1954 if (ps)
1955 {
1956 if (ps->readin)
1957 /* Might want to error() here (in case symtab is corrupt and
1958 will cause a core dump), but maybe we can successfully
1959 continue, so let's not. */
8a3fe4f8
AC
1960 warning (_("\
1961(Internal error: pc 0x%s in read in psymtab, but not in symtab.)\n"),
d730266b 1962 paddr_nz (pc));
c906108c
SS
1963 s = PSYMTAB_TO_SYMTAB (ps);
1964 }
1965 return (s);
1966}
1967
1968/* Find the symtab associated with PC. Look through the psymtabs and
1969 read in another symtab if necessary. Backward compatibility, no section */
1970
1971struct symtab *
fba45db2 1972find_pc_symtab (CORE_ADDR pc)
c906108c
SS
1973{
1974 return find_pc_sect_symtab (pc, find_pc_mapped_section (pc));
1975}
c906108c 1976\f
c5aa993b 1977
7e73cedf 1978/* Find the source file and line number for a given PC value and SECTION.
c906108c
SS
1979 Return a structure containing a symtab pointer, a line number,
1980 and a pc range for the entire source line.
1981 The value's .pc field is NOT the specified pc.
1982 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1983 use the line that ends there. Otherwise, in that case, the line
1984 that begins there is used. */
1985
1986/* The big complication here is that a line may start in one file, and end just
1987 before the start of another file. This usually occurs when you #include
1988 code in the middle of a subroutine. To properly find the end of a line's PC
1989 range, we must search all symtabs associated with this compilation unit, and
1990 find the one whose first PC is closer than that of the next line in this
1991 symtab. */
1992
1993/* If it's worth the effort, we could be using a binary search. */
1994
1995struct symtab_and_line
198beae2 1996find_pc_sect_line (CORE_ADDR pc, struct bfd_section *section, int notcurrent)
c906108c
SS
1997{
1998 struct symtab *s;
52f0bd74
AC
1999 struct linetable *l;
2000 int len;
2001 int i;
2002 struct linetable_entry *item;
c906108c
SS
2003 struct symtab_and_line val;
2004 struct blockvector *bv;
2005 struct minimal_symbol *msymbol;
2006 struct minimal_symbol *mfunsym;
2007
2008 /* Info on best line seen so far, and where it starts, and its file. */
2009
2010 struct linetable_entry *best = NULL;
2011 CORE_ADDR best_end = 0;
2012 struct symtab *best_symtab = 0;
2013
2014 /* Store here the first line number
2015 of a file which contains the line at the smallest pc after PC.
2016 If we don't find a line whose range contains PC,
2017 we will use a line one less than this,
2018 with a range from the start of that file to the first line's pc. */
2019 struct linetable_entry *alt = NULL;
2020 struct symtab *alt_symtab = 0;
2021
2022 /* Info on best line seen in this file. */
2023
2024 struct linetable_entry *prev;
2025
2026 /* If this pc is not from the current frame,
2027 it is the address of the end of a call instruction.
2028 Quite likely that is the start of the following statement.
2029 But what we want is the statement containing the instruction.
2030 Fudge the pc to make sure we get that. */
2031
fe39c653 2032 init_sal (&val); /* initialize to zeroes */
c906108c 2033
b77b1eb7
JB
2034 /* It's tempting to assume that, if we can't find debugging info for
2035 any function enclosing PC, that we shouldn't search for line
2036 number info, either. However, GAS can emit line number info for
2037 assembly files --- very helpful when debugging hand-written
2038 assembly code. In such a case, we'd have no debug info for the
2039 function, but we would have line info. */
648f4f79 2040
c906108c
SS
2041 if (notcurrent)
2042 pc -= 1;
2043
c5aa993b 2044 /* elz: added this because this function returned the wrong
c906108c
SS
2045 information if the pc belongs to a stub (import/export)
2046 to call a shlib function. This stub would be anywhere between
2047 two functions in the target, and the line info was erroneously
2048 taken to be the one of the line before the pc.
c5aa993b 2049 */
c906108c 2050 /* RT: Further explanation:
c5aa993b 2051
c906108c
SS
2052 * We have stubs (trampolines) inserted between procedures.
2053 *
2054 * Example: "shr1" exists in a shared library, and a "shr1" stub also
2055 * exists in the main image.
2056 *
2057 * In the minimal symbol table, we have a bunch of symbols
2058 * sorted by start address. The stubs are marked as "trampoline",
2059 * the others appear as text. E.g.:
2060 *
2061 * Minimal symbol table for main image
2062 * main: code for main (text symbol)
2063 * shr1: stub (trampoline symbol)
2064 * foo: code for foo (text symbol)
2065 * ...
2066 * Minimal symbol table for "shr1" image:
2067 * ...
2068 * shr1: code for shr1 (text symbol)
2069 * ...
2070 *
2071 * So the code below is trying to detect if we are in the stub
2072 * ("shr1" stub), and if so, find the real code ("shr1" trampoline),
2073 * and if found, do the symbolization from the real-code address
2074 * rather than the stub address.
2075 *
2076 * Assumptions being made about the minimal symbol table:
2077 * 1. lookup_minimal_symbol_by_pc() will return a trampoline only
2078 * if we're really in the trampoline. If we're beyond it (say
2079 * we're in "foo" in the above example), it'll have a closer
2080 * symbol (the "foo" text symbol for example) and will not
2081 * return the trampoline.
2082 * 2. lookup_minimal_symbol_text() will find a real text symbol
2083 * corresponding to the trampoline, and whose address will
2084 * be different than the trampoline address. I put in a sanity
2085 * check for the address being the same, to avoid an
2086 * infinite recursion.
2087 */
c5aa993b
JM
2088 msymbol = lookup_minimal_symbol_by_pc (pc);
2089 if (msymbol != NULL)
c906108c 2090 if (MSYMBOL_TYPE (msymbol) == mst_solib_trampoline)
c5aa993b 2091 {
2335f48e 2092 mfunsym = lookup_minimal_symbol_text (SYMBOL_LINKAGE_NAME (msymbol),
5520a790 2093 NULL);
c5aa993b
JM
2094 if (mfunsym == NULL)
2095 /* I eliminated this warning since it is coming out
2096 * in the following situation:
2097 * gdb shmain // test program with shared libraries
2098 * (gdb) break shr1 // function in shared lib
2099 * Warning: In stub for ...
2100 * In the above situation, the shared lib is not loaded yet,
2101 * so of course we can't find the real func/line info,
2102 * but the "break" still works, and the warning is annoying.
2103 * So I commented out the warning. RT */
2335f48e 2104 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_LINKAGE_NAME (msymbol)) */ ;
c5aa993b
JM
2105 /* fall through */
2106 else if (SYMBOL_VALUE (mfunsym) == SYMBOL_VALUE (msymbol))
2107 /* Avoid infinite recursion */
2108 /* See above comment about why warning is commented out */
2335f48e 2109 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_LINKAGE_NAME (msymbol)) */ ;
c5aa993b
JM
2110 /* fall through */
2111 else
2112 return find_pc_line (SYMBOL_VALUE (mfunsym), 0);
2113 }
c906108c
SS
2114
2115
2116 s = find_pc_sect_symtab (pc, section);
2117 if (!s)
2118 {
2119 /* if no symbol information, return previous pc */
2120 if (notcurrent)
2121 pc++;
2122 val.pc = pc;
2123 return val;
2124 }
2125
2126 bv = BLOCKVECTOR (s);
2127
2128 /* Look at all the symtabs that share this blockvector.
2129 They all have the same apriori range, that we found was right;
2130 but they have different line tables. */
2131
2132 for (; s && BLOCKVECTOR (s) == bv; s = s->next)
2133 {
2134 /* Find the best line in this symtab. */
2135 l = LINETABLE (s);
2136 if (!l)
c5aa993b 2137 continue;
c906108c
SS
2138 len = l->nitems;
2139 if (len <= 0)
2140 {
2141 /* I think len can be zero if the symtab lacks line numbers
2142 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
2143 I'm not sure which, and maybe it depends on the symbol
2144 reader). */
2145 continue;
2146 }
2147
2148 prev = NULL;
2149 item = l->item; /* Get first line info */
2150
2151 /* Is this file's first line closer than the first lines of other files?
c5aa993b 2152 If so, record this file, and its first line, as best alternate. */
c906108c
SS
2153 if (item->pc > pc && (!alt || item->pc < alt->pc))
2154 {
2155 alt = item;
2156 alt_symtab = s;
2157 }
2158
2159 for (i = 0; i < len; i++, item++)
2160 {
2161 /* Leave prev pointing to the linetable entry for the last line
2162 that started at or before PC. */
2163 if (item->pc > pc)
2164 break;
2165
2166 prev = item;
2167 }
2168
2169 /* At this point, prev points at the line whose start addr is <= pc, and
c5aa993b
JM
2170 item points at the next line. If we ran off the end of the linetable
2171 (pc >= start of the last line), then prev == item. If pc < start of
2172 the first line, prev will not be set. */
c906108c
SS
2173
2174 /* Is this file's best line closer than the best in the other files?
083ae935
DJ
2175 If so, record this file, and its best line, as best so far. Don't
2176 save prev if it represents the end of a function (i.e. line number
2177 0) instead of a real line. */
c906108c 2178
083ae935 2179 if (prev && prev->line && (!best || prev->pc > best->pc))
c906108c
SS
2180 {
2181 best = prev;
2182 best_symtab = s;
25d53da1
KB
2183
2184 /* Discard BEST_END if it's before the PC of the current BEST. */
2185 if (best_end <= best->pc)
2186 best_end = 0;
c906108c 2187 }
25d53da1
KB
2188
2189 /* If another line (denoted by ITEM) is in the linetable and its
2190 PC is after BEST's PC, but before the current BEST_END, then
2191 use ITEM's PC as the new best_end. */
2192 if (best && i < len && item->pc > best->pc
2193 && (best_end == 0 || best_end > item->pc))
2194 best_end = item->pc;
c906108c
SS
2195 }
2196
2197 if (!best_symtab)
2198 {
e86e87f7
DJ
2199 /* If we didn't find any line number info, just return zeros.
2200 We used to return alt->line - 1 here, but that could be
2201 anywhere; if we don't have line number info for this PC,
2202 don't make some up. */
2203 val.pc = pc;
c906108c 2204 }
e8717518
FF
2205 else if (best->line == 0)
2206 {
2207 /* If our best fit is in a range of PC's for which no line
2208 number info is available (line number is zero) then we didn't
2209 find any valid line information. */
2210 val.pc = pc;
2211 }
c906108c
SS
2212 else
2213 {
2214 val.symtab = best_symtab;
2215 val.line = best->line;
2216 val.pc = best->pc;
2217 if (best_end && (!alt || best_end < alt->pc))
2218 val.end = best_end;
2219 else if (alt)
2220 val.end = alt->pc;
2221 else
2222 val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
2223 }
2224 val.section = section;
2225 return val;
2226}
2227
2228/* Backward compatibility (no section) */
2229
2230struct symtab_and_line
fba45db2 2231find_pc_line (CORE_ADDR pc, int notcurrent)
c906108c 2232{
c5aa993b 2233 asection *section;
c906108c
SS
2234
2235 section = find_pc_overlay (pc);
2236 if (pc_in_unmapped_range (pc, section))
2237 pc = overlay_mapped_address (pc, section);
2238 return find_pc_sect_line (pc, section, notcurrent);
2239}
c906108c 2240\f
c906108c
SS
2241/* Find line number LINE in any symtab whose name is the same as
2242 SYMTAB.
2243
2244 If found, return the symtab that contains the linetable in which it was
2245 found, set *INDEX to the index in the linetable of the best entry
2246 found, and set *EXACT_MATCH nonzero if the value returned is an
2247 exact match.
2248
2249 If not found, return NULL. */
2250
50641945 2251struct symtab *
fba45db2 2252find_line_symtab (struct symtab *symtab, int line, int *index, int *exact_match)
c906108c
SS
2253{
2254 int exact;
2255
2256 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
2257 so far seen. */
2258
2259 int best_index;
2260 struct linetable *best_linetable;
2261 struct symtab *best_symtab;
2262
2263 /* First try looking it up in the given symtab. */
2264 best_linetable = LINETABLE (symtab);
2265 best_symtab = symtab;
2266 best_index = find_line_common (best_linetable, line, &exact);
2267 if (best_index < 0 || !exact)
2268 {
2269 /* Didn't find an exact match. So we better keep looking for
c5aa993b
JM
2270 another symtab with the same name. In the case of xcoff,
2271 multiple csects for one source file (produced by IBM's FORTRAN
2272 compiler) produce multiple symtabs (this is unavoidable
2273 assuming csects can be at arbitrary places in memory and that
2274 the GLOBAL_BLOCK of a symtab has a begin and end address). */
c906108c
SS
2275
2276 /* BEST is the smallest linenumber > LINE so far seen,
c5aa993b
JM
2277 or 0 if none has been seen so far.
2278 BEST_INDEX and BEST_LINETABLE identify the item for it. */
c906108c
SS
2279 int best;
2280
2281 struct objfile *objfile;
2282 struct symtab *s;
2283
2284 if (best_index >= 0)
2285 best = best_linetable->item[best_index].line;
2286 else
2287 best = 0;
2288
2289 ALL_SYMTABS (objfile, s)
c5aa993b
JM
2290 {
2291 struct linetable *l;
2292 int ind;
c906108c 2293
6314a349 2294 if (strcmp (symtab->filename, s->filename) != 0)
c5aa993b
JM
2295 continue;
2296 l = LINETABLE (s);
2297 ind = find_line_common (l, line, &exact);
2298 if (ind >= 0)
2299 {
2300 if (exact)
2301 {
2302 best_index = ind;
2303 best_linetable = l;
2304 best_symtab = s;
2305 goto done;
2306 }
2307 if (best == 0 || l->item[ind].line < best)
2308 {
2309 best = l->item[ind].line;
2310 best_index = ind;
2311 best_linetable = l;
2312 best_symtab = s;
2313 }
2314 }
2315 }
c906108c 2316 }
c5aa993b 2317done:
c906108c
SS
2318 if (best_index < 0)
2319 return NULL;
2320
2321 if (index)
2322 *index = best_index;
2323 if (exact_match)
2324 *exact_match = exact;
2325
2326 return best_symtab;
2327}
2328\f
2329/* Set the PC value for a given source file and line number and return true.
2330 Returns zero for invalid line number (and sets the PC to 0).
2331 The source file is specified with a struct symtab. */
2332
2333int
fba45db2 2334find_line_pc (struct symtab *symtab, int line, CORE_ADDR *pc)
c906108c
SS
2335{
2336 struct linetable *l;
2337 int ind;
2338
2339 *pc = 0;
2340 if (symtab == 0)
2341 return 0;
2342
2343 symtab = find_line_symtab (symtab, line, &ind, NULL);
2344 if (symtab != NULL)
2345 {
2346 l = LINETABLE (symtab);
2347 *pc = l->item[ind].pc;
2348 return 1;
2349 }
2350 else
2351 return 0;
2352}
2353
2354/* Find the range of pc values in a line.
2355 Store the starting pc of the line into *STARTPTR
2356 and the ending pc (start of next line) into *ENDPTR.
2357 Returns 1 to indicate success.
2358 Returns 0 if could not find the specified line. */
2359
2360int
fba45db2
KB
2361find_line_pc_range (struct symtab_and_line sal, CORE_ADDR *startptr,
2362 CORE_ADDR *endptr)
c906108c
SS
2363{
2364 CORE_ADDR startaddr;
2365 struct symtab_and_line found_sal;
2366
2367 startaddr = sal.pc;
c5aa993b 2368 if (startaddr == 0 && !find_line_pc (sal.symtab, sal.line, &startaddr))
c906108c
SS
2369 return 0;
2370
2371 /* This whole function is based on address. For example, if line 10 has
2372 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
2373 "info line *0x123" should say the line goes from 0x100 to 0x200
2374 and "info line *0x355" should say the line goes from 0x300 to 0x400.
2375 This also insures that we never give a range like "starts at 0x134
2376 and ends at 0x12c". */
2377
2378 found_sal = find_pc_sect_line (startaddr, sal.section, 0);
2379 if (found_sal.line != sal.line)
2380 {
2381 /* The specified line (sal) has zero bytes. */
2382 *startptr = found_sal.pc;
2383 *endptr = found_sal.pc;
2384 }
2385 else
2386 {
2387 *startptr = found_sal.pc;
2388 *endptr = found_sal.end;
2389 }
2390 return 1;
2391}
2392
2393/* Given a line table and a line number, return the index into the line
2394 table for the pc of the nearest line whose number is >= the specified one.
2395 Return -1 if none is found. The value is >= 0 if it is an index.
2396
2397 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
2398
2399static int
aa1ee363 2400find_line_common (struct linetable *l, int lineno,
fba45db2 2401 int *exact_match)
c906108c 2402{
52f0bd74
AC
2403 int i;
2404 int len;
c906108c
SS
2405
2406 /* BEST is the smallest linenumber > LINENO so far seen,
2407 or 0 if none has been seen so far.
2408 BEST_INDEX identifies the item for it. */
2409
2410 int best_index = -1;
2411 int best = 0;
2412
2413 if (lineno <= 0)
2414 return -1;
2415 if (l == 0)
2416 return -1;
2417
2418 len = l->nitems;
2419 for (i = 0; i < len; i++)
2420 {
aa1ee363 2421 struct linetable_entry *item = &(l->item[i]);
c906108c
SS
2422
2423 if (item->line == lineno)
2424 {
2425 /* Return the first (lowest address) entry which matches. */
2426 *exact_match = 1;
2427 return i;
2428 }
2429
2430 if (item->line > lineno && (best == 0 || item->line < best))
2431 {
2432 best = item->line;
2433 best_index = i;
2434 }
2435 }
2436
2437 /* If we got here, we didn't get an exact match. */
2438
2439 *exact_match = 0;
2440 return best_index;
2441}
2442
2443int
fba45db2 2444find_pc_line_pc_range (CORE_ADDR pc, CORE_ADDR *startptr, CORE_ADDR *endptr)
c906108c
SS
2445{
2446 struct symtab_and_line sal;
2447 sal = find_pc_line (pc, 0);
2448 *startptr = sal.pc;
2449 *endptr = sal.end;
2450 return sal.symtab != 0;
2451}
2452
2453/* Given a function symbol SYM, find the symtab and line for the start
2454 of the function.
2455 If the argument FUNFIRSTLINE is nonzero, we want the first line
2456 of real code inside the function. */
2457
50641945 2458struct symtab_and_line
fba45db2 2459find_function_start_sal (struct symbol *sym, int funfirstline)
c906108c
SS
2460{
2461 CORE_ADDR pc;
2462 struct symtab_and_line sal;
2463
2464 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
2465 fixup_symbol_section (sym, NULL);
2466 if (funfirstline)
c5aa993b 2467 { /* skip "first line" of function (which is actually its prologue) */
c906108c
SS
2468 asection *section = SYMBOL_BFD_SECTION (sym);
2469 /* If function is in an unmapped overlay, use its unmapped LMA
a433963d
UW
2470 address, so that gdbarch_skip_prologue has something unique to work
2471 on */
c906108c
SS
2472 if (section_is_overlay (section) &&
2473 !section_is_mapped (section))
2474 pc = overlay_unmapped_address (pc, section);
2475
cbf3b44a 2476 pc += gdbarch_deprecated_function_start_offset (current_gdbarch);
a433963d 2477 pc = gdbarch_skip_prologue (current_gdbarch, pc);
c906108c
SS
2478
2479 /* For overlays, map pc back into its mapped VMA range */
2480 pc = overlay_mapped_address (pc, section);
2481 }
2482 sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
2483
a433963d 2484 /* Check if gdbarch_skip_prologue left us in mid-line, and the next
c906108c
SS
2485 line is still part of the same function. */
2486 if (sal.pc != pc
2487 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= sal.end
2488 && sal.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym)))
2489 {
2490 /* First pc of next line */
2491 pc = sal.end;
2492 /* Recalculate the line number (might not be N+1). */
2493 sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
2494 }
2495 sal.pc = pc;
c906108c
SS
2496
2497 return sal;
2498}
50641945 2499
c906108c
SS
2500/* If P is of the form "operator[ \t]+..." where `...' is
2501 some legitimate operator text, return a pointer to the
2502 beginning of the substring of the operator text.
2503 Otherwise, return "". */
2504char *
fba45db2 2505operator_chars (char *p, char **end)
c906108c
SS
2506{
2507 *end = "";
2508 if (strncmp (p, "operator", 8))
2509 return *end;
2510 p += 8;
2511
2512 /* Don't get faked out by `operator' being part of a longer
2513 identifier. */
c5aa993b 2514 if (isalpha (*p) || *p == '_' || *p == '$' || *p == '\0')
c906108c
SS
2515 return *end;
2516
2517 /* Allow some whitespace between `operator' and the operator symbol. */
2518 while (*p == ' ' || *p == '\t')
2519 p++;
2520
2521 /* Recognize 'operator TYPENAME'. */
2522
c5aa993b 2523 if (isalpha (*p) || *p == '_' || *p == '$')
c906108c 2524 {
aa1ee363 2525 char *q = p + 1;
c5aa993b 2526 while (isalnum (*q) || *q == '_' || *q == '$')
c906108c
SS
2527 q++;
2528 *end = q;
2529 return p;
2530 }
2531
53e8ad3d
MS
2532 while (*p)
2533 switch (*p)
2534 {
2535 case '\\': /* regexp quoting */
2536 if (p[1] == '*')
2537 {
2538 if (p[2] == '=') /* 'operator\*=' */
2539 *end = p + 3;
2540 else /* 'operator\*' */
2541 *end = p + 2;
2542 return p;
2543 }
2544 else if (p[1] == '[')
2545 {
2546 if (p[2] == ']')
8a3fe4f8 2547 error (_("mismatched quoting on brackets, try 'operator\\[\\]'"));
53e8ad3d
MS
2548 else if (p[2] == '\\' && p[3] == ']')
2549 {
2550 *end = p + 4; /* 'operator\[\]' */
2551 return p;
2552 }
2553 else
8a3fe4f8 2554 error (_("nothing is allowed between '[' and ']'"));
53e8ad3d
MS
2555 }
2556 else
2557 {
2558 /* Gratuitous qoute: skip it and move on. */
2559 p++;
2560 continue;
2561 }
2562 break;
2563 case '!':
2564 case '=':
2565 case '*':
2566 case '/':
2567 case '%':
2568 case '^':
2569 if (p[1] == '=')
2570 *end = p + 2;
2571 else
2572 *end = p + 1;
2573 return p;
2574 case '<':
2575 case '>':
2576 case '+':
2577 case '-':
2578 case '&':
2579 case '|':
2580 if (p[0] == '-' && p[1] == '>')
2581 {
2582 /* Struct pointer member operator 'operator->'. */
2583 if (p[2] == '*')
2584 {
2585 *end = p + 3; /* 'operator->*' */
2586 return p;
2587 }
2588 else if (p[2] == '\\')
2589 {
2590 *end = p + 4; /* Hopefully 'operator->\*' */
2591 return p;
2592 }
2593 else
2594 {
2595 *end = p + 2; /* 'operator->' */
2596 return p;
2597 }
2598 }
2599 if (p[1] == '=' || p[1] == p[0])
2600 *end = p + 2;
2601 else
2602 *end = p + 1;
2603 return p;
2604 case '~':
2605 case ',':
c5aa993b 2606 *end = p + 1;
53e8ad3d
MS
2607 return p;
2608 case '(':
2609 if (p[1] != ')')
8a3fe4f8 2610 error (_("`operator ()' must be specified without whitespace in `()'"));
c5aa993b 2611 *end = p + 2;
53e8ad3d
MS
2612 return p;
2613 case '?':
2614 if (p[1] != ':')
8a3fe4f8 2615 error (_("`operator ?:' must be specified without whitespace in `?:'"));
53e8ad3d
MS
2616 *end = p + 2;
2617 return p;
2618 case '[':
2619 if (p[1] != ']')
8a3fe4f8 2620 error (_("`operator []' must be specified without whitespace in `[]'"));
53e8ad3d
MS
2621 *end = p + 2;
2622 return p;
2623 default:
8a3fe4f8 2624 error (_("`operator %s' not supported"), p);
53e8ad3d
MS
2625 break;
2626 }
2627
c906108c
SS
2628 *end = "";
2629 return *end;
2630}
c906108c 2631\f
c5aa993b 2632
c94fdfd0
EZ
2633/* If FILE is not already in the table of files, return zero;
2634 otherwise return non-zero. Optionally add FILE to the table if ADD
2635 is non-zero. If *FIRST is non-zero, forget the old table
2636 contents. */
2637static int
2638filename_seen (const char *file, int add, int *first)
c906108c 2639{
c94fdfd0
EZ
2640 /* Table of files seen so far. */
2641 static const char **tab = NULL;
c906108c
SS
2642 /* Allocated size of tab in elements.
2643 Start with one 256-byte block (when using GNU malloc.c).
2644 24 is the malloc overhead when range checking is in effect. */
2645 static int tab_alloc_size = (256 - 24) / sizeof (char *);
2646 /* Current size of tab in elements. */
2647 static int tab_cur_size;
c94fdfd0 2648 const char **p;
c906108c
SS
2649
2650 if (*first)
2651 {
2652 if (tab == NULL)
c94fdfd0 2653 tab = (const char **) xmalloc (tab_alloc_size * sizeof (*tab));
c906108c
SS
2654 tab_cur_size = 0;
2655 }
2656
c94fdfd0 2657 /* Is FILE in tab? */
c906108c 2658 for (p = tab; p < tab + tab_cur_size; p++)
c94fdfd0
EZ
2659 if (strcmp (*p, file) == 0)
2660 return 1;
2661
2662 /* No; maybe add it to tab. */
2663 if (add)
c906108c 2664 {
c94fdfd0
EZ
2665 if (tab_cur_size == tab_alloc_size)
2666 {
2667 tab_alloc_size *= 2;
2668 tab = (const char **) xrealloc ((char *) tab,
2669 tab_alloc_size * sizeof (*tab));
2670 }
2671 tab[tab_cur_size++] = file;
c906108c 2672 }
c906108c 2673
c94fdfd0
EZ
2674 return 0;
2675}
2676
2677/* Slave routine for sources_info. Force line breaks at ,'s.
2678 NAME is the name to print and *FIRST is nonzero if this is the first
2679 name printed. Set *FIRST to zero. */
2680static void
d092d1a2 2681output_source_filename (const char *name, int *first)
c94fdfd0
EZ
2682{
2683 /* Since a single source file can result in several partial symbol
2684 tables, we need to avoid printing it more than once. Note: if
2685 some of the psymtabs are read in and some are not, it gets
2686 printed both under "Source files for which symbols have been
2687 read" and "Source files for which symbols will be read in on
2688 demand". I consider this a reasonable way to deal with the
2689 situation. I'm not sure whether this can also happen for
2690 symtabs; it doesn't hurt to check. */
2691
2692 /* Was NAME already seen? */
2693 if (filename_seen (name, 1, first))
2694 {
2695 /* Yes; don't print it again. */
2696 return;
2697 }
2698 /* No; print it and reset *FIRST. */
c906108c
SS
2699 if (*first)
2700 {
2701 *first = 0;
2702 }
2703 else
2704 {
2705 printf_filtered (", ");
2706 }
2707
2708 wrap_here ("");
2709 fputs_filtered (name, gdb_stdout);
c5aa993b 2710}
c906108c
SS
2711
2712static void
fba45db2 2713sources_info (char *ignore, int from_tty)
c906108c 2714{
52f0bd74
AC
2715 struct symtab *s;
2716 struct partial_symtab *ps;
2717 struct objfile *objfile;
c906108c 2718 int first;
c5aa993b 2719
c906108c
SS
2720 if (!have_full_symbols () && !have_partial_symbols ())
2721 {
8a3fe4f8 2722 error (_("No symbol table is loaded. Use the \"file\" command."));
c906108c 2723 }
c5aa993b 2724
c906108c
SS
2725 printf_filtered ("Source files for which symbols have been read in:\n\n");
2726
2727 first = 1;
2728 ALL_SYMTABS (objfile, s)
c5aa993b 2729 {
d092d1a2
DJ
2730 const char *fullname = symtab_to_fullname (s);
2731 output_source_filename (fullname ? fullname : s->filename, &first);
c5aa993b 2732 }
c906108c 2733 printf_filtered ("\n\n");
c5aa993b 2734
c906108c
SS
2735 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2736
2737 first = 1;
2738 ALL_PSYMTABS (objfile, ps)
c5aa993b
JM
2739 {
2740 if (!ps->readin)
2741 {
d092d1a2
DJ
2742 const char *fullname = psymtab_to_fullname (ps);
2743 output_source_filename (fullname ? fullname : ps->filename, &first);
c5aa993b
JM
2744 }
2745 }
c906108c
SS
2746 printf_filtered ("\n");
2747}
2748
2749static int
fd118b61 2750file_matches (char *file, char *files[], int nfiles)
c906108c
SS
2751{
2752 int i;
2753
2754 if (file != NULL && nfiles != 0)
2755 {
2756 for (i = 0; i < nfiles; i++)
c5aa993b 2757 {
31889e00 2758 if (strcmp (files[i], lbasename (file)) == 0)
c5aa993b
JM
2759 return 1;
2760 }
c906108c
SS
2761 }
2762 else if (nfiles == 0)
2763 return 1;
2764 return 0;
2765}
2766
2767/* Free any memory associated with a search. */
2768void
fba45db2 2769free_search_symbols (struct symbol_search *symbols)
c906108c
SS
2770{
2771 struct symbol_search *p;
2772 struct symbol_search *next;
2773
2774 for (p = symbols; p != NULL; p = next)
2775 {
2776 next = p->next;
b8c9b27d 2777 xfree (p);
c906108c
SS
2778 }
2779}
2780
5bd98722
AC
2781static void
2782do_free_search_symbols_cleanup (void *symbols)
2783{
2784 free_search_symbols (symbols);
2785}
2786
2787struct cleanup *
2788make_cleanup_free_search_symbols (struct symbol_search *symbols)
2789{
2790 return make_cleanup (do_free_search_symbols_cleanup, symbols);
2791}
2792
434d2d4f
DJ
2793/* Helper function for sort_search_symbols and qsort. Can only
2794 sort symbols, not minimal symbols. */
2795static int
2796compare_search_syms (const void *sa, const void *sb)
2797{
2798 struct symbol_search **sym_a = (struct symbol_search **) sa;
2799 struct symbol_search **sym_b = (struct symbol_search **) sb;
2800
de5ad195
DC
2801 return strcmp (SYMBOL_PRINT_NAME ((*sym_a)->symbol),
2802 SYMBOL_PRINT_NAME ((*sym_b)->symbol));
434d2d4f
DJ
2803}
2804
2805/* Sort the ``nfound'' symbols in the list after prevtail. Leave
2806 prevtail where it is, but update its next pointer to point to
2807 the first of the sorted symbols. */
2808static struct symbol_search *
2809sort_search_symbols (struct symbol_search *prevtail, int nfound)
2810{
2811 struct symbol_search **symbols, *symp, *old_next;
2812 int i;
2813
2814 symbols = (struct symbol_search **) xmalloc (sizeof (struct symbol_search *)
2815 * nfound);
2816 symp = prevtail->next;
2817 for (i = 0; i < nfound; i++)
2818 {
2819 symbols[i] = symp;
2820 symp = symp->next;
2821 }
2822 /* Generally NULL. */
2823 old_next = symp;
2824
2825 qsort (symbols, nfound, sizeof (struct symbol_search *),
2826 compare_search_syms);
2827
2828 symp = prevtail;
2829 for (i = 0; i < nfound; i++)
2830 {
2831 symp->next = symbols[i];
2832 symp = symp->next;
2833 }
2834 symp->next = old_next;
2835
8ed32cc0 2836 xfree (symbols);
434d2d4f
DJ
2837 return symp;
2838}
5bd98722 2839
c906108c
SS
2840/* Search the symbol table for matches to the regular expression REGEXP,
2841 returning the results in *MATCHES.
2842
2843 Only symbols of KIND are searched:
176620f1
EZ
2844 FUNCTIONS_DOMAIN - search all functions
2845 TYPES_DOMAIN - search all type names
2846 METHODS_DOMAIN - search all methods NOT IMPLEMENTED
2847 VARIABLES_DOMAIN - search all symbols, excluding functions, type names,
c5aa993b 2848 and constants (enums)
c906108c
SS
2849
2850 free_search_symbols should be called when *MATCHES is no longer needed.
434d2d4f
DJ
2851
2852 The results are sorted locally; each symtab's global and static blocks are
2853 separately alphabetized.
c5aa993b 2854 */
c906108c 2855void
176620f1 2856search_symbols (char *regexp, domain_enum kind, int nfiles, char *files[],
fd118b61 2857 struct symbol_search **matches)
c906108c 2858{
52f0bd74
AC
2859 struct symtab *s;
2860 struct partial_symtab *ps;
2861 struct blockvector *bv;
52f0bd74
AC
2862 struct block *b;
2863 int i = 0;
de4f826b 2864 struct dict_iterator iter;
52f0bd74 2865 struct symbol *sym;
c906108c
SS
2866 struct partial_symbol **psym;
2867 struct objfile *objfile;
2868 struct minimal_symbol *msymbol;
2869 char *val;
2870 int found_misc = 0;
2871 static enum minimal_symbol_type types[]
c5aa993b
JM
2872 =
2873 {mst_data, mst_text, mst_abs, mst_unknown};
c906108c 2874 static enum minimal_symbol_type types2[]
c5aa993b
JM
2875 =
2876 {mst_bss, mst_file_text, mst_abs, mst_unknown};
c906108c 2877 static enum minimal_symbol_type types3[]
c5aa993b
JM
2878 =
2879 {mst_file_data, mst_solib_trampoline, mst_abs, mst_unknown};
c906108c 2880 static enum minimal_symbol_type types4[]
c5aa993b
JM
2881 =
2882 {mst_file_bss, mst_text, mst_abs, mst_unknown};
c906108c
SS
2883 enum minimal_symbol_type ourtype;
2884 enum minimal_symbol_type ourtype2;
2885 enum minimal_symbol_type ourtype3;
2886 enum minimal_symbol_type ourtype4;
2887 struct symbol_search *sr;
2888 struct symbol_search *psr;
2889 struct symbol_search *tail;
2890 struct cleanup *old_chain = NULL;
2891
176620f1 2892 if (kind < VARIABLES_DOMAIN)
8a3fe4f8 2893 error (_("must search on specific domain"));
c906108c 2894
176620f1
EZ
2895 ourtype = types[(int) (kind - VARIABLES_DOMAIN)];
2896 ourtype2 = types2[(int) (kind - VARIABLES_DOMAIN)];
2897 ourtype3 = types3[(int) (kind - VARIABLES_DOMAIN)];
2898 ourtype4 = types4[(int) (kind - VARIABLES_DOMAIN)];
c906108c
SS
2899
2900 sr = *matches = NULL;
2901 tail = NULL;
2902
2903 if (regexp != NULL)
2904 {
2905 /* Make sure spacing is right for C++ operators.
2906 This is just a courtesy to make the matching less sensitive
2907 to how many spaces the user leaves between 'operator'
2908 and <TYPENAME> or <OPERATOR>. */
2909 char *opend;
2910 char *opname = operator_chars (regexp, &opend);
2911 if (*opname)
c5aa993b
JM
2912 {
2913 int fix = -1; /* -1 means ok; otherwise number of spaces needed. */
2914 if (isalpha (*opname) || *opname == '_' || *opname == '$')
2915 {
2916 /* There should 1 space between 'operator' and 'TYPENAME'. */
2917 if (opname[-1] != ' ' || opname[-2] == ' ')
2918 fix = 1;
2919 }
2920 else
2921 {
2922 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2923 if (opname[-1] == ' ')
2924 fix = 0;
2925 }
2926 /* If wrong number of spaces, fix it. */
2927 if (fix >= 0)
2928 {
045f55a6 2929 char *tmp = (char *) alloca (8 + fix + strlen (opname) + 1);
c5aa993b
JM
2930 sprintf (tmp, "operator%.*s%s", fix, " ", opname);
2931 regexp = tmp;
2932 }
2933 }
2934
c906108c 2935 if (0 != (val = re_comp (regexp)))
8a3fe4f8 2936 error (_("Invalid regexp (%s): %s"), val, regexp);
c906108c
SS
2937 }
2938
2939 /* Search through the partial symtabs *first* for all symbols
2940 matching the regexp. That way we don't have to reproduce all of
2941 the machinery below. */
2942
2943 ALL_PSYMTABS (objfile, ps)
c5aa993b
JM
2944 {
2945 struct partial_symbol **bound, **gbound, **sbound;
2946 int keep_going = 1;
2947
2948 if (ps->readin)
2949 continue;
2950
2951 gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms;
2952 sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms;
2953 bound = gbound;
2954
2955 /* Go through all of the symbols stored in a partial
2956 symtab in one loop. */
2957 psym = objfile->global_psymbols.list + ps->globals_offset;
2958 while (keep_going)
2959 {
2960 if (psym >= bound)
2961 {
2962 if (bound == gbound && ps->n_static_syms != 0)
2963 {
2964 psym = objfile->static_psymbols.list + ps->statics_offset;
2965 bound = sbound;
2966 }
2967 else
2968 keep_going = 0;
2969 continue;
2970 }
2971 else
2972 {
2973 QUIT;
2974
2975 /* If it would match (logic taken from loop below)
cb1df416
DJ
2976 load the file and go on to the next one. We check the
2977 filename here, but that's a bit bogus: we don't know
2978 what file it really comes from until we have full
2979 symtabs. The symbol might be in a header file included by
2980 this psymtab. This only affects Insight. */
c5aa993b 2981 if (file_matches (ps->filename, files, nfiles)
25120b0d
DC
2982 && ((regexp == NULL
2983 || re_exec (SYMBOL_NATURAL_NAME (*psym)) != 0)
176620f1 2984 && ((kind == VARIABLES_DOMAIN && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
c5aa993b 2985 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
176620f1
EZ
2986 || (kind == FUNCTIONS_DOMAIN && SYMBOL_CLASS (*psym) == LOC_BLOCK)
2987 || (kind == TYPES_DOMAIN && SYMBOL_CLASS (*psym) == LOC_TYPEDEF)
2988 || (kind == METHODS_DOMAIN && SYMBOL_CLASS (*psym) == LOC_BLOCK))))
c5aa993b
JM
2989 {
2990 PSYMTAB_TO_SYMTAB (ps);
2991 keep_going = 0;
2992 }
2993 }
2994 psym++;
2995 }
2996 }
c906108c
SS
2997
2998 /* Here, we search through the minimal symbol tables for functions
2999 and variables that match, and force their symbols to be read.
3000 This is in particular necessary for demangled variable names,
3001 which are no longer put into the partial symbol tables.
3002 The symbol will then be found during the scan of symtabs below.
3003
3004 For functions, find_pc_symtab should succeed if we have debug info
3005 for the function, for variables we have to call lookup_symbol
3006 to determine if the variable has debug info.
3007 If the lookup fails, set found_misc so that we will rescan to print
3008 any matching symbols without debug info.
c5aa993b 3009 */
c906108c 3010
176620f1 3011 if (nfiles == 0 && (kind == VARIABLES_DOMAIN || kind == FUNCTIONS_DOMAIN))
c906108c
SS
3012 {
3013 ALL_MSYMBOLS (objfile, msymbol)
c5aa993b
JM
3014 {
3015 if (MSYMBOL_TYPE (msymbol) == ourtype ||
3016 MSYMBOL_TYPE (msymbol) == ourtype2 ||
3017 MSYMBOL_TYPE (msymbol) == ourtype3 ||
3018 MSYMBOL_TYPE (msymbol) == ourtype4)
3019 {
25120b0d
DC
3020 if (regexp == NULL
3021 || re_exec (SYMBOL_NATURAL_NAME (msymbol)) != 0)
c5aa993b
JM
3022 {
3023 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)))
3024 {
b1262a02
DC
3025 /* FIXME: carlton/2003-02-04: Given that the
3026 semantics of lookup_symbol keeps on changing
3027 slightly, it would be a nice idea if we had a
3028 function lookup_symbol_minsym that found the
3029 symbol associated to a given minimal symbol (if
3030 any). */
176620f1 3031 if (kind == FUNCTIONS_DOMAIN
2335f48e 3032 || lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol),
b1262a02 3033 (struct block *) NULL,
176620f1 3034 VAR_DOMAIN,
53c5240f
PA
3035 0, (struct symtab **) NULL)
3036 == NULL)
b1262a02 3037 found_misc = 1;
c5aa993b
JM
3038 }
3039 }
3040 }
3041 }
c906108c
SS
3042 }
3043
11309657 3044 ALL_PRIMARY_SYMTABS (objfile, s)
c5aa993b
JM
3045 {
3046 bv = BLOCKVECTOR (s);
c5aa993b
JM
3047 for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
3048 {
434d2d4f
DJ
3049 struct symbol_search *prevtail = tail;
3050 int nfound = 0;
c5aa993b 3051 b = BLOCKVECTOR_BLOCK (bv, i);
de4f826b 3052 ALL_BLOCK_SYMBOLS (b, iter, sym)
c5aa993b 3053 {
cb1df416 3054 struct symtab *real_symtab = SYMBOL_SYMTAB (sym);
c5aa993b 3055 QUIT;
cb1df416
DJ
3056
3057 if (file_matches (real_symtab->filename, files, nfiles)
25120b0d
DC
3058 && ((regexp == NULL
3059 || re_exec (SYMBOL_NATURAL_NAME (sym)) != 0)
176620f1 3060 && ((kind == VARIABLES_DOMAIN && SYMBOL_CLASS (sym) != LOC_TYPEDEF
c5aa993b
JM
3061 && SYMBOL_CLASS (sym) != LOC_BLOCK
3062 && SYMBOL_CLASS (sym) != LOC_CONST)
176620f1
EZ
3063 || (kind == FUNCTIONS_DOMAIN && SYMBOL_CLASS (sym) == LOC_BLOCK)
3064 || (kind == TYPES_DOMAIN && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
3065 || (kind == METHODS_DOMAIN && SYMBOL_CLASS (sym) == LOC_BLOCK))))
c5aa993b
JM
3066 {
3067 /* match */
3068 psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search));
3069 psr->block = i;
cb1df416 3070 psr->symtab = real_symtab;
c5aa993b
JM
3071 psr->symbol = sym;
3072 psr->msymbol = NULL;
3073 psr->next = NULL;
3074 if (tail == NULL)
434d2d4f 3075 sr = psr;
c5aa993b
JM
3076 else
3077 tail->next = psr;
3078 tail = psr;
434d2d4f
DJ
3079 nfound ++;
3080 }
3081 }
3082 if (nfound > 0)
3083 {
3084 if (prevtail == NULL)
3085 {
3086 struct symbol_search dummy;
3087
3088 dummy.next = sr;
3089 tail = sort_search_symbols (&dummy, nfound);
3090 sr = dummy.next;
3091
3092 old_chain = make_cleanup_free_search_symbols (sr);
c5aa993b 3093 }
434d2d4f
DJ
3094 else
3095 tail = sort_search_symbols (prevtail, nfound);
c5aa993b
JM
3096 }
3097 }
c5aa993b 3098 }
c906108c
SS
3099
3100 /* If there are no eyes, avoid all contact. I mean, if there are
3101 no debug symbols, then print directly from the msymbol_vector. */
3102
176620f1 3103 if (found_misc || kind != FUNCTIONS_DOMAIN)
c906108c
SS
3104 {
3105 ALL_MSYMBOLS (objfile, msymbol)
c5aa993b
JM
3106 {
3107 if (MSYMBOL_TYPE (msymbol) == ourtype ||
3108 MSYMBOL_TYPE (msymbol) == ourtype2 ||
3109 MSYMBOL_TYPE (msymbol) == ourtype3 ||
3110 MSYMBOL_TYPE (msymbol) == ourtype4)
3111 {
25120b0d
DC
3112 if (regexp == NULL
3113 || re_exec (SYMBOL_NATURAL_NAME (msymbol)) != 0)
c5aa993b
JM
3114 {
3115 /* Functions: Look up by address. */
176620f1 3116 if (kind != FUNCTIONS_DOMAIN ||
c5aa993b
JM
3117 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol))))
3118 {
3119 /* Variables/Absolutes: Look up by name */
2335f48e 3120 if (lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol),
176620f1 3121 (struct block *) NULL, VAR_DOMAIN,
c5aa993b
JM
3122 0, (struct symtab **) NULL) == NULL)
3123 {
3124 /* match */
3125 psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search));
3126 psr->block = i;
3127 psr->msymbol = msymbol;
3128 psr->symtab = NULL;
3129 psr->symbol = NULL;
3130 psr->next = NULL;
3131 if (tail == NULL)
3132 {
3133 sr = psr;
5bd98722 3134 old_chain = make_cleanup_free_search_symbols (sr);
c5aa993b
JM
3135 }
3136 else
3137 tail->next = psr;
3138 tail = psr;
3139 }
3140 }
3141 }
3142 }
3143 }
c906108c
SS
3144 }
3145
3146 *matches = sr;
3147 if (sr != NULL)
3148 discard_cleanups (old_chain);
3149}
3150
3151/* Helper function for symtab_symbol_info, this function uses
3152 the data returned from search_symbols() to print information
3153 regarding the match to gdb_stdout.
c5aa993b 3154 */
c906108c 3155static void
176620f1 3156print_symbol_info (domain_enum kind, struct symtab *s, struct symbol *sym,
fba45db2 3157 int block, char *last)
c906108c
SS
3158{
3159 if (last == NULL || strcmp (last, s->filename) != 0)
3160 {
3161 fputs_filtered ("\nFile ", gdb_stdout);
3162 fputs_filtered (s->filename, gdb_stdout);
3163 fputs_filtered (":\n", gdb_stdout);
3164 }
3165
176620f1 3166 if (kind != TYPES_DOMAIN && block == STATIC_BLOCK)
c906108c 3167 printf_filtered ("static ");
c5aa993b 3168
c906108c 3169 /* Typedef that is not a C++ class */
176620f1
EZ
3170 if (kind == TYPES_DOMAIN
3171 && SYMBOL_DOMAIN (sym) != STRUCT_DOMAIN)
a5238fbc 3172 typedef_print (SYMBOL_TYPE (sym), sym, gdb_stdout);
c906108c 3173 /* variable, func, or typedef-that-is-c++-class */
176620f1
EZ
3174 else if (kind < TYPES_DOMAIN ||
3175 (kind == TYPES_DOMAIN &&
3176 SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN))
c906108c
SS
3177 {
3178 type_print (SYMBOL_TYPE (sym),
c5aa993b 3179 (SYMBOL_CLASS (sym) == LOC_TYPEDEF
de5ad195 3180 ? "" : SYMBOL_PRINT_NAME (sym)),
c5aa993b 3181 gdb_stdout, 0);
c906108c
SS
3182
3183 printf_filtered (";\n");
3184 }
c906108c
SS
3185}
3186
3187/* This help function for symtab_symbol_info() prints information
3188 for non-debugging symbols to gdb_stdout.
c5aa993b 3189 */
c906108c 3190static void
fba45db2 3191print_msymbol_info (struct minimal_symbol *msymbol)
c906108c 3192{
3ac4495a
MS
3193 char *tmp;
3194
17a912b6 3195 if (gdbarch_addr_bit (current_gdbarch) <= 32)
bb599908
PH
3196 tmp = hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol)
3197 & (CORE_ADDR) 0xffffffff,
3198 8);
3ac4495a 3199 else
bb599908
PH
3200 tmp = hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol),
3201 16);
3ac4495a 3202 printf_filtered ("%s %s\n",
de5ad195 3203 tmp, SYMBOL_PRINT_NAME (msymbol));
c906108c
SS
3204}
3205
3206/* This is the guts of the commands "info functions", "info types", and
3207 "info variables". It calls search_symbols to find all matches and then
3208 print_[m]symbol_info to print out some useful information about the
3209 matches.
c5aa993b 3210 */
c906108c 3211static void
176620f1 3212symtab_symbol_info (char *regexp, domain_enum kind, int from_tty)
c906108c
SS
3213{
3214 static char *classnames[]
c5aa993b
JM
3215 =
3216 {"variable", "function", "type", "method"};
c906108c
SS
3217 struct symbol_search *symbols;
3218 struct symbol_search *p;
3219 struct cleanup *old_chain;
3220 char *last_filename = NULL;
3221 int first = 1;
3222
3223 /* must make sure that if we're interrupted, symbols gets freed */
3224 search_symbols (regexp, kind, 0, (char **) NULL, &symbols);
5bd98722 3225 old_chain = make_cleanup_free_search_symbols (symbols);
c906108c
SS
3226
3227 printf_filtered (regexp
c5aa993b
JM
3228 ? "All %ss matching regular expression \"%s\":\n"
3229 : "All defined %ss:\n",
176620f1 3230 classnames[(int) (kind - VARIABLES_DOMAIN)], regexp);
c906108c
SS
3231
3232 for (p = symbols; p != NULL; p = p->next)
3233 {
3234 QUIT;
3235
3236 if (p->msymbol != NULL)
c5aa993b
JM
3237 {
3238 if (first)
3239 {
3240 printf_filtered ("\nNon-debugging symbols:\n");
3241 first = 0;
3242 }
3243 print_msymbol_info (p->msymbol);
3244 }
c906108c 3245 else
c5aa993b
JM
3246 {
3247 print_symbol_info (kind,
3248 p->symtab,
3249 p->symbol,
3250 p->block,
3251 last_filename);
3252 last_filename = p->symtab->filename;
3253 }
c906108c
SS
3254 }
3255
3256 do_cleanups (old_chain);
3257}
3258
3259static void
fba45db2 3260variables_info (char *regexp, int from_tty)
c906108c 3261{
176620f1 3262 symtab_symbol_info (regexp, VARIABLES_DOMAIN, from_tty);
c906108c
SS
3263}
3264
3265static void
fba45db2 3266functions_info (char *regexp, int from_tty)
c906108c 3267{
176620f1 3268 symtab_symbol_info (regexp, FUNCTIONS_DOMAIN, from_tty);
c906108c
SS
3269}
3270
357e46e7 3271
c906108c 3272static void
fba45db2 3273types_info (char *regexp, int from_tty)
c906108c 3274{
176620f1 3275 symtab_symbol_info (regexp, TYPES_DOMAIN, from_tty);
c906108c
SS
3276}
3277
c906108c 3278/* Breakpoint all functions matching regular expression. */
8926118c 3279
8b93c638 3280void
fba45db2 3281rbreak_command_wrapper (char *regexp, int from_tty)
8b93c638
JM
3282{
3283 rbreak_command (regexp, from_tty);
3284}
8926118c 3285
c906108c 3286static void
fba45db2 3287rbreak_command (char *regexp, int from_tty)
c906108c
SS
3288{
3289 struct symbol_search *ss;
3290 struct symbol_search *p;
3291 struct cleanup *old_chain;
3292
176620f1 3293 search_symbols (regexp, FUNCTIONS_DOMAIN, 0, (char **) NULL, &ss);
5bd98722 3294 old_chain = make_cleanup_free_search_symbols (ss);
c906108c
SS
3295
3296 for (p = ss; p != NULL; p = p->next)
3297 {
3298 if (p->msymbol == NULL)
c5aa993b 3299 {
2335f48e
DC
3300 char *string = alloca (strlen (p->symtab->filename)
3301 + strlen (SYMBOL_LINKAGE_NAME (p->symbol))
3302 + 4);
c5aa993b
JM
3303 strcpy (string, p->symtab->filename);
3304 strcat (string, ":'");
2335f48e 3305 strcat (string, SYMBOL_LINKAGE_NAME (p->symbol));
c5aa993b
JM
3306 strcat (string, "'");
3307 break_command (string, from_tty);
176620f1 3308 print_symbol_info (FUNCTIONS_DOMAIN,
c5aa993b
JM
3309 p->symtab,
3310 p->symbol,
3311 p->block,
3312 p->symtab->filename);
3313 }
c906108c 3314 else
c5aa993b 3315 {
2335f48e 3316 break_command (SYMBOL_LINKAGE_NAME (p->msymbol), from_tty);
c5aa993b 3317 printf_filtered ("<function, no debug info> %s;\n",
de5ad195 3318 SYMBOL_PRINT_NAME (p->msymbol));
c5aa993b 3319 }
c906108c
SS
3320 }
3321
3322 do_cleanups (old_chain);
3323}
c906108c 3324\f
c5aa993b 3325
c906108c
SS
3326/* Helper routine for make_symbol_completion_list. */
3327
3328static int return_val_size;
3329static int return_val_index;
3330static char **return_val;
3331
3332#define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
c906108c 3333 completion_list_add_name \
2335f48e 3334 (SYMBOL_NATURAL_NAME (symbol), (sym_text), (len), (text), (word))
c906108c
SS
3335
3336/* Test to see if the symbol specified by SYMNAME (which is already
c5aa993b
JM
3337 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3338 characters. If so, add it to the current completion list. */
c906108c
SS
3339
3340static void
fba45db2
KB
3341completion_list_add_name (char *symname, char *sym_text, int sym_text_len,
3342 char *text, char *word)
c906108c
SS
3343{
3344 int newsize;
3345 int i;
3346
3347 /* clip symbols that cannot match */
3348
3349 if (strncmp (symname, sym_text, sym_text_len) != 0)
3350 {
3351 return;
3352 }
3353
c906108c
SS
3354 /* We have a match for a completion, so add SYMNAME to the current list
3355 of matches. Note that the name is moved to freshly malloc'd space. */
3356
3357 {
3358 char *new;
3359 if (word == sym_text)
3360 {
3361 new = xmalloc (strlen (symname) + 5);
3362 strcpy (new, symname);
3363 }
3364 else if (word > sym_text)
3365 {
3366 /* Return some portion of symname. */
3367 new = xmalloc (strlen (symname) + 5);
3368 strcpy (new, symname + (word - sym_text));
3369 }
3370 else
3371 {
3372 /* Return some of SYM_TEXT plus symname. */
3373 new = xmalloc (strlen (symname) + (sym_text - word) + 5);
3374 strncpy (new, word, sym_text - word);
3375 new[sym_text - word] = '\0';
3376 strcat (new, symname);
3377 }
3378
c906108c
SS
3379 if (return_val_index + 3 > return_val_size)
3380 {
3381 newsize = (return_val_size *= 2) * sizeof (char *);
3382 return_val = (char **) xrealloc ((char *) return_val, newsize);
3383 }
3384 return_val[return_val_index++] = new;
3385 return_val[return_val_index] = NULL;
3386 }
3387}
3388
69636828
AF
3389/* ObjC: In case we are completing on a selector, look as the msymbol
3390 again and feed all the selectors into the mill. */
3391
3392static void
3393completion_list_objc_symbol (struct minimal_symbol *msymbol, char *sym_text,
3394 int sym_text_len, char *text, char *word)
3395{
3396 static char *tmp = NULL;
3397 static unsigned int tmplen = 0;
3398
3399 char *method, *category, *selector;
3400 char *tmp2 = NULL;
3401
3402 method = SYMBOL_NATURAL_NAME (msymbol);
3403
3404 /* Is it a method? */
3405 if ((method[0] != '-') && (method[0] != '+'))
3406 return;
3407
3408 if (sym_text[0] == '[')
3409 /* Complete on shortened method method. */
3410 completion_list_add_name (method + 1, sym_text, sym_text_len, text, word);
3411
3412 while ((strlen (method) + 1) >= tmplen)
3413 {
3414 if (tmplen == 0)
3415 tmplen = 1024;
3416 else
3417 tmplen *= 2;
3418 tmp = xrealloc (tmp, tmplen);
3419 }
3420 selector = strchr (method, ' ');
3421 if (selector != NULL)
3422 selector++;
3423
3424 category = strchr (method, '(');
3425
3426 if ((category != NULL) && (selector != NULL))
3427 {
3428 memcpy (tmp, method, (category - method));
3429 tmp[category - method] = ' ';
3430 memcpy (tmp + (category - method) + 1, selector, strlen (selector) + 1);
3431 completion_list_add_name (tmp, sym_text, sym_text_len, text, word);
3432 if (sym_text[0] == '[')
3433 completion_list_add_name (tmp + 1, sym_text, sym_text_len, text, word);
3434 }
3435
3436 if (selector != NULL)
3437 {
3438 /* Complete on selector only. */
3439 strcpy (tmp, selector);
3440 tmp2 = strchr (tmp, ']');
3441 if (tmp2 != NULL)
3442 *tmp2 = '\0';
3443
3444 completion_list_add_name (tmp, sym_text, sym_text_len, text, word);
3445 }
3446}
3447
3448/* Break the non-quoted text based on the characters which are in
3449 symbols. FIXME: This should probably be language-specific. */
3450
3451static char *
3452language_search_unquoted_string (char *text, char *p)
3453{
3454 for (; p > text; --p)
3455 {
3456 if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
3457 continue;
3458 else
3459 {
3460 if ((current_language->la_language == language_objc))
3461 {
3462 if (p[-1] == ':') /* might be part of a method name */
3463 continue;
3464 else if (p[-1] == '[' && (p[-2] == '-' || p[-2] == '+'))
3465 p -= 2; /* beginning of a method name */
3466 else if (p[-1] == ' ' || p[-1] == '(' || p[-1] == ')')
3467 { /* might be part of a method name */
3468 char *t = p;
3469
3470 /* Seeing a ' ' or a '(' is not conclusive evidence
3471 that we are in the middle of a method name. However,
3472 finding "-[" or "+[" should be pretty un-ambiguous.
3473 Unfortunately we have to find it now to decide. */
3474
3475 while (t > text)
3476 if (isalnum (t[-1]) || t[-1] == '_' ||
3477 t[-1] == ' ' || t[-1] == ':' ||
3478 t[-1] == '(' || t[-1] == ')')
3479 --t;
3480 else
3481 break;
3482
3483 if (t[-1] == '[' && (t[-2] == '-' || t[-2] == '+'))
3484 p = t - 2; /* method name detected */
3485 /* else we leave with p unchanged */
3486 }
3487 }
3488 break;
3489 }
3490 }
3491 return p;
3492}
3493
3494
c94fdfd0
EZ
3495/* Return a NULL terminated array of all symbols (regardless of class)
3496 which begin by matching TEXT. If the answer is no symbols, then
3497 the return value is an array which contains only a NULL pointer.
c906108c
SS
3498
3499 Problem: All of the symbols have to be copied because readline frees them.
3500 I'm not going to worry about this; hopefully there won't be that many. */
3501
3502char **
fba45db2 3503make_symbol_completion_list (char *text, char *word)
c906108c 3504{
de4f826b
DC
3505 struct symbol *sym;
3506 struct symtab *s;
3507 struct partial_symtab *ps;
3508 struct minimal_symbol *msymbol;
3509 struct objfile *objfile;
3510 struct block *b, *surrounding_static_block = 0;
3511 struct dict_iterator iter;
3512 int j;
c906108c
SS
3513 struct partial_symbol **psym;
3514 /* The symbol we are completing on. Points in same buffer as text. */
3515 char *sym_text;
3516 /* Length of sym_text. */
3517 int sym_text_len;
3518
3519 /* Now look for the symbol we are supposed to complete on.
3520 FIXME: This should be language-specific. */
3521 {
3522 char *p;
3523 char quote_found;
3524 char *quote_pos = NULL;
3525
3526 /* First see if this is a quoted string. */
3527 quote_found = '\0';
3528 for (p = text; *p != '\0'; ++p)
3529 {
3530 if (quote_found != '\0')
3531 {
3532 if (*p == quote_found)
3533 /* Found close quote. */
3534 quote_found = '\0';
3535 else if (*p == '\\' && p[1] == quote_found)
3536 /* A backslash followed by the quote character
c5aa993b 3537 doesn't end the string. */
c906108c
SS
3538 ++p;
3539 }
3540 else if (*p == '\'' || *p == '"')
3541 {
3542 quote_found = *p;
3543 quote_pos = p;
3544 }
3545 }
3546 if (quote_found == '\'')
3547 /* A string within single quotes can be a symbol, so complete on it. */
3548 sym_text = quote_pos + 1;
3549 else if (quote_found == '"')
3550 /* A double-quoted string is never a symbol, nor does it make sense
c5aa993b 3551 to complete it any other way. */
c94fdfd0
EZ
3552 {
3553 return_val = (char **) xmalloc (sizeof (char *));
3554 return_val[0] = NULL;
3555 return return_val;
3556 }
c906108c
SS
3557 else
3558 {
3559 /* It is not a quoted string. Break it based on the characters
3560 which are in symbols. */
3561 while (p > text)
3562 {
3563 if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
3564 --p;
3565 else
3566 break;
3567 }
3568 sym_text = p;
3569 }
3570 }
3571
3572 sym_text_len = strlen (sym_text);
3573
3574 return_val_size = 100;
3575 return_val_index = 0;
3576 return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
3577 return_val[0] = NULL;
3578
3579 /* Look through the partial symtabs for all symbols which begin
3580 by matching SYM_TEXT. Add each one that you find to the list. */
3581
3582 ALL_PSYMTABS (objfile, ps)
c5aa993b
JM
3583 {
3584 /* If the psymtab's been read in we'll get it when we search
3585 through the blockvector. */
3586 if (ps->readin)
3587 continue;
3588
3589 for (psym = objfile->global_psymbols.list + ps->globals_offset;
3590 psym < (objfile->global_psymbols.list + ps->globals_offset
3591 + ps->n_global_syms);
3592 psym++)
3593 {
3594 /* If interrupted, then quit. */
3595 QUIT;
3596 COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
3597 }
3598
3599 for (psym = objfile->static_psymbols.list + ps->statics_offset;
3600 psym < (objfile->static_psymbols.list + ps->statics_offset
3601 + ps->n_static_syms);
3602 psym++)
3603 {
3604 QUIT;
3605 COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
3606 }
3607 }
c906108c
SS
3608
3609 /* At this point scan through the misc symbol vectors and add each
3610 symbol you find to the list. Eventually we want to ignore
3611 anything that isn't a text symbol (everything else will be
3612 handled by the psymtab code above). */
3613
3614 ALL_MSYMBOLS (objfile, msymbol)
c5aa993b
JM
3615 {
3616 QUIT;
3617 COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, word);
69636828
AF
3618
3619 completion_list_objc_symbol (msymbol, sym_text, sym_text_len, text, word);
c5aa993b 3620 }
c906108c
SS
3621
3622 /* Search upwards from currently selected frame (so that we can
3623 complete on local vars. */
3624
ae767bfb 3625 for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
c906108c
SS
3626 {
3627 if (!BLOCK_SUPERBLOCK (b))
3628 {
c5aa993b 3629 surrounding_static_block = b; /* For elmin of dups */
c906108c 3630 }
c5aa993b 3631
c906108c 3632 /* Also catch fields of types defined in this places which match our
c5aa993b 3633 text string. Only complete on types visible from current context. */
c906108c 3634
de4f826b 3635 ALL_BLOCK_SYMBOLS (b, iter, sym)
c906108c 3636 {
69636828 3637 QUIT;
c906108c
SS
3638 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3639 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
3640 {
3641 struct type *t = SYMBOL_TYPE (sym);
3642 enum type_code c = TYPE_CODE (t);
3643
3644 if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
3645 {
3646 for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
3647 {
3648 if (TYPE_FIELD_NAME (t, j))
3649 {
3650 completion_list_add_name (TYPE_FIELD_NAME (t, j),
c5aa993b 3651 sym_text, sym_text_len, text, word);
c906108c
SS
3652 }
3653 }
3654 }
3655 }
3656 }
3657 }
3658
3659 /* Go through the symtabs and check the externs and statics for
3660 symbols which match. */
3661
11309657 3662 ALL_PRIMARY_SYMTABS (objfile, s)
c5aa993b
JM
3663 {
3664 QUIT;
3665 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
de4f826b 3666 ALL_BLOCK_SYMBOLS (b, iter, sym)
c5aa993b 3667 {
c5aa993b
JM
3668 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3669 }
3670 }
c906108c 3671
11309657 3672 ALL_PRIMARY_SYMTABS (objfile, s)
c5aa993b
JM
3673 {
3674 QUIT;
3675 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
3676 /* Don't do this block twice. */
3677 if (b == surrounding_static_block)
3678 continue;
de4f826b 3679 ALL_BLOCK_SYMBOLS (b, iter, sym)
c5aa993b 3680 {
c5aa993b
JM
3681 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3682 }
3683 }
c906108c
SS
3684
3685 return (return_val);
3686}
3687
c94fdfd0
EZ
3688/* Like make_symbol_completion_list, but returns a list of symbols
3689 defined in a source file FILE. */
3690
3691char **
3692make_file_symbol_completion_list (char *text, char *word, char *srcfile)
3693{
52f0bd74
AC
3694 struct symbol *sym;
3695 struct symtab *s;
3696 struct block *b;
de4f826b 3697 struct dict_iterator iter;
c94fdfd0
EZ
3698 /* The symbol we are completing on. Points in same buffer as text. */
3699 char *sym_text;
3700 /* Length of sym_text. */
3701 int sym_text_len;
3702
3703 /* Now look for the symbol we are supposed to complete on.
3704 FIXME: This should be language-specific. */
3705 {
3706 char *p;
3707 char quote_found;
3708 char *quote_pos = NULL;
3709
3710 /* First see if this is a quoted string. */
3711 quote_found = '\0';
3712 for (p = text; *p != '\0'; ++p)
3713 {
3714 if (quote_found != '\0')
3715 {
3716 if (*p == quote_found)
3717 /* Found close quote. */
3718 quote_found = '\0';
3719 else if (*p == '\\' && p[1] == quote_found)
3720 /* A backslash followed by the quote character
3721 doesn't end the string. */
3722 ++p;
3723 }
3724 else if (*p == '\'' || *p == '"')
3725 {
3726 quote_found = *p;
3727 quote_pos = p;
3728 }
3729 }
3730 if (quote_found == '\'')
3731 /* A string within single quotes can be a symbol, so complete on it. */
3732 sym_text = quote_pos + 1;
3733 else if (quote_found == '"')
3734 /* A double-quoted string is never a symbol, nor does it make sense
3735 to complete it any other way. */
3736 {
3737 return_val = (char **) xmalloc (sizeof (char *));
3738 return_val[0] = NULL;
3739 return return_val;
3740 }
3741 else
3742 {
69636828
AF
3743 /* Not a quoted string. */
3744 sym_text = language_search_unquoted_string (text, p);
c94fdfd0
EZ
3745 }
3746 }
3747
3748 sym_text_len = strlen (sym_text);
3749
3750 return_val_size = 10;
3751 return_val_index = 0;
3752 return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
3753 return_val[0] = NULL;
3754
3755 /* Find the symtab for SRCFILE (this loads it if it was not yet read
3756 in). */
3757 s = lookup_symtab (srcfile);
3758 if (s == NULL)
3759 {
3760 /* Maybe they typed the file with leading directories, while the
3761 symbol tables record only its basename. */
31889e00 3762 const char *tail = lbasename (srcfile);
c94fdfd0
EZ
3763
3764 if (tail > srcfile)
3765 s = lookup_symtab (tail);
3766 }
3767
3768 /* If we have no symtab for that file, return an empty list. */
3769 if (s == NULL)
3770 return (return_val);
3771
3772 /* Go through this symtab and check the externs and statics for
3773 symbols which match. */
3774
3775 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
de4f826b 3776 ALL_BLOCK_SYMBOLS (b, iter, sym)
c94fdfd0 3777 {
c94fdfd0
EZ
3778 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3779 }
3780
3781 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
de4f826b 3782 ALL_BLOCK_SYMBOLS (b, iter, sym)
c94fdfd0 3783 {
c94fdfd0
EZ
3784 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3785 }
3786
3787 return (return_val);
3788}
3789
3790/* A helper function for make_source_files_completion_list. It adds
3791 another file name to a list of possible completions, growing the
3792 list as necessary. */
3793
3794static void
3795add_filename_to_list (const char *fname, char *text, char *word,
3796 char ***list, int *list_used, int *list_alloced)
3797{
3798 char *new;
3799 size_t fnlen = strlen (fname);
3800
3801 if (*list_used + 1 >= *list_alloced)
3802 {
3803 *list_alloced *= 2;
3804 *list = (char **) xrealloc ((char *) *list,
3805 *list_alloced * sizeof (char *));
3806 }
3807
3808 if (word == text)
3809 {
3810 /* Return exactly fname. */
3811 new = xmalloc (fnlen + 5);
3812 strcpy (new, fname);
3813 }
3814 else if (word > text)
3815 {
3816 /* Return some portion of fname. */
3817 new = xmalloc (fnlen + 5);
3818 strcpy (new, fname + (word - text));
3819 }
3820 else
3821 {
3822 /* Return some of TEXT plus fname. */
3823 new = xmalloc (fnlen + (text - word) + 5);
3824 strncpy (new, word, text - word);
3825 new[text - word] = '\0';
3826 strcat (new, fname);
3827 }
3828 (*list)[*list_used] = new;
3829 (*list)[++*list_used] = NULL;
3830}
3831
3832static int
3833not_interesting_fname (const char *fname)
3834{
3835 static const char *illegal_aliens[] = {
3836 "_globals_", /* inserted by coff_symtab_read */
3837 NULL
3838 };
3839 int i;
3840
3841 for (i = 0; illegal_aliens[i]; i++)
3842 {
3843 if (strcmp (fname, illegal_aliens[i]) == 0)
3844 return 1;
3845 }
3846 return 0;
3847}
3848
3849/* Return a NULL terminated array of all source files whose names
3850 begin with matching TEXT. The file names are looked up in the
3851 symbol tables of this program. If the answer is no matchess, then
3852 the return value is an array which contains only a NULL pointer. */
3853
3854char **
3855make_source_files_completion_list (char *text, char *word)
3856{
52f0bd74
AC
3857 struct symtab *s;
3858 struct partial_symtab *ps;
3859 struct objfile *objfile;
c94fdfd0
EZ
3860 int first = 1;
3861 int list_alloced = 1;
3862 int list_used = 0;
3863 size_t text_len = strlen (text);
3864 char **list = (char **) xmalloc (list_alloced * sizeof (char *));
31889e00 3865 const char *base_name;
c94fdfd0
EZ
3866
3867 list[0] = NULL;
3868
3869 if (!have_full_symbols () && !have_partial_symbols ())
3870 return list;
3871
3872 ALL_SYMTABS (objfile, s)
3873 {
3874 if (not_interesting_fname (s->filename))
3875 continue;
3876 if (!filename_seen (s->filename, 1, &first)
3877#if HAVE_DOS_BASED_FILE_SYSTEM
3878 && strncasecmp (s->filename, text, text_len) == 0
3879#else
3880 && strncmp (s->filename, text, text_len) == 0
3881#endif
3882 )
3883 {
3884 /* This file matches for a completion; add it to the current
3885 list of matches. */
3886 add_filename_to_list (s->filename, text, word,
3887 &list, &list_used, &list_alloced);
3888 }
3889 else
3890 {
3891 /* NOTE: We allow the user to type a base name when the
3892 debug info records leading directories, but not the other
3893 way around. This is what subroutines of breakpoint
3894 command do when they parse file names. */
31889e00 3895 base_name = lbasename (s->filename);
c94fdfd0
EZ
3896 if (base_name != s->filename
3897 && !filename_seen (base_name, 1, &first)
3898#if HAVE_DOS_BASED_FILE_SYSTEM
3899 && strncasecmp (base_name, text, text_len) == 0
3900#else
3901 && strncmp (base_name, text, text_len) == 0
3902#endif
3903 )
3904 add_filename_to_list (base_name, text, word,
3905 &list, &list_used, &list_alloced);
3906 }
3907 }
3908
3909 ALL_PSYMTABS (objfile, ps)
3910 {
3911 if (not_interesting_fname (ps->filename))
3912 continue;
3913 if (!ps->readin)
3914 {
3915 if (!filename_seen (ps->filename, 1, &first)
3916#if HAVE_DOS_BASED_FILE_SYSTEM
3917 && strncasecmp (ps->filename, text, text_len) == 0
3918#else
3919 && strncmp (ps->filename, text, text_len) == 0
3920#endif
3921 )
3922 {
3923 /* This file matches for a completion; add it to the
3924 current list of matches. */
3925 add_filename_to_list (ps->filename, text, word,
3926 &list, &list_used, &list_alloced);
3927
3928 }
3929 else
3930 {
31889e00 3931 base_name = lbasename (ps->filename);
c94fdfd0
EZ
3932 if (base_name != ps->filename
3933 && !filename_seen (base_name, 1, &first)
3934#if HAVE_DOS_BASED_FILE_SYSTEM
3935 && strncasecmp (base_name, text, text_len) == 0
3936#else
3937 && strncmp (base_name, text, text_len) == 0
3938#endif
3939 )
3940 add_filename_to_list (base_name, text, word,
3941 &list, &list_used, &list_alloced);
3942 }
3943 }
3944 }
3945
3946 return list;
3947}
3948
c906108c
SS
3949/* Determine if PC is in the prologue of a function. The prologue is the area
3950 between the first instruction of a function, and the first executable line.
3951 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3952
3953 If non-zero, func_start is where we think the prologue starts, possibly
3954 by previous examination of symbol table information.
3955 */
3956
3957int
fba45db2 3958in_prologue (CORE_ADDR pc, CORE_ADDR func_start)
c906108c
SS
3959{
3960 struct symtab_and_line sal;
3961 CORE_ADDR func_addr, func_end;
3962
54cf9c03
EZ
3963 /* We have several sources of information we can consult to figure
3964 this out.
3965 - Compilers usually emit line number info that marks the prologue
3966 as its own "source line". So the ending address of that "line"
3967 is the end of the prologue. If available, this is the most
3968 reliable method.
3969 - The minimal symbols and partial symbols, which can usually tell
3970 us the starting and ending addresses of a function.
3971 - If we know the function's start address, we can call the
a433963d 3972 architecture-defined gdbarch_skip_prologue function to analyze the
54cf9c03
EZ
3973 instruction stream and guess where the prologue ends.
3974 - Our `func_start' argument; if non-zero, this is the caller's
3975 best guess as to the function's entry point. At the time of
3976 this writing, handle_inferior_event doesn't get this right, so
3977 it should be our last resort. */
3978
3979 /* Consult the partial symbol table, to find which function
3980 the PC is in. */
3981 if (! find_pc_partial_function (pc, NULL, &func_addr, &func_end))
3982 {
3983 CORE_ADDR prologue_end;
c906108c 3984
54cf9c03
EZ
3985 /* We don't even have minsym information, so fall back to using
3986 func_start, if given. */
3987 if (! func_start)
3988 return 1; /* We *might* be in a prologue. */
c906108c 3989
a433963d 3990 prologue_end = gdbarch_skip_prologue (current_gdbarch, func_start);
c906108c 3991
54cf9c03
EZ
3992 return func_start <= pc && pc < prologue_end;
3993 }
c906108c 3994
54cf9c03
EZ
3995 /* If we have line number information for the function, that's
3996 usually pretty reliable. */
3997 sal = find_pc_line (func_addr, 0);
c906108c 3998
54cf9c03
EZ
3999 /* Now sal describes the source line at the function's entry point,
4000 which (by convention) is the prologue. The end of that "line",
4001 sal.end, is the end of the prologue.
4002
4003 Note that, for functions whose source code is all on a single
4004 line, the line number information doesn't always end up this way.
4005 So we must verify that our purported end-of-prologue address is
4006 *within* the function, not at its start or end. */
4007 if (sal.line == 0
4008 || sal.end <= func_addr
4009 || func_end <= sal.end)
4010 {
4011 /* We don't have any good line number info, so use the minsym
4012 information, together with the architecture-specific prologue
4013 scanning code. */
a433963d
UW
4014 CORE_ADDR prologue_end = gdbarch_skip_prologue
4015 (current_gdbarch, func_addr);
c906108c 4016
54cf9c03
EZ
4017 return func_addr <= pc && pc < prologue_end;
4018 }
c906108c 4019
54cf9c03
EZ
4020 /* We have line number info, and it looks good. */
4021 return func_addr <= pc && pc < sal.end;
c906108c
SS
4022}
4023
634aa483
AC
4024/* Given PC at the function's start address, attempt to find the
4025 prologue end using SAL information. Return zero if the skip fails.
4026
4027 A non-optimized prologue traditionally has one SAL for the function
4028 and a second for the function body. A single line function has
4029 them both pointing at the same line.
4030
4031 An optimized prologue is similar but the prologue may contain
4032 instructions (SALs) from the instruction body. Need to skip those
4033 while not getting into the function body.
4034
4035 The functions end point and an increasing SAL line are used as
4036 indicators of the prologue's endpoint.
4037
4038 This code is based on the function refine_prologue_limit (versions
4039 found in both ia64 and ppc). */
4040
4041CORE_ADDR
4042skip_prologue_using_sal (CORE_ADDR func_addr)
4043{
4044 struct symtab_and_line prologue_sal;
4045 CORE_ADDR start_pc;
4046 CORE_ADDR end_pc;
4047
4048 /* Get an initial range for the function. */
4049 find_pc_partial_function (func_addr, NULL, &start_pc, &end_pc);
cbf3b44a 4050 start_pc += gdbarch_deprecated_function_start_offset (current_gdbarch);
634aa483
AC
4051
4052 prologue_sal = find_pc_line (start_pc, 0);
4053 if (prologue_sal.line != 0)
4054 {
576c2025
FF
4055 /* If there is only one sal that covers the entire function,
4056 then it is probably a single line function, like
4057 "foo(){}". */
91934273 4058 if (prologue_sal.end >= end_pc)
4e463ff5 4059 return 0;
634aa483
AC
4060 while (prologue_sal.end < end_pc)
4061 {
4062 struct symtab_and_line sal;
4063
4064 sal = find_pc_line (prologue_sal.end, 0);
4065 if (sal.line == 0)
4066 break;
4067 /* Assume that a consecutive SAL for the same (or larger)
4068 line mark the prologue -> body transition. */
4069 if (sal.line >= prologue_sal.line)
4070 break;
4071 /* The case in which compiler's optimizer/scheduler has
4072 moved instructions into the prologue. We look ahead in
4073 the function looking for address ranges whose
4074 corresponding line number is less the first one that we
4075 found for the function. This is more conservative then
4076 refine_prologue_limit which scans a large number of SALs
4077 looking for any in the prologue */
4078 prologue_sal = sal;
4079 }
4080 }
4081 return prologue_sal.end;
4082}
c906108c 4083\f
50641945
FN
4084struct symtabs_and_lines
4085decode_line_spec (char *string, int funfirstline)
4086{
4087 struct symtabs_and_lines sals;
0378c332
FN
4088 struct symtab_and_line cursal;
4089
50641945 4090 if (string == 0)
8a3fe4f8 4091 error (_("Empty line specification."));
0378c332
FN
4092
4093 /* We use whatever is set as the current source line. We do not try
4094 and get a default or it will recursively call us! */
4095 cursal = get_current_source_symtab_and_line ();
4096
50641945 4097 sals = decode_line_1 (&string, funfirstline,
0378c332 4098 cursal.symtab, cursal.line,
bffe1ece 4099 (char ***) NULL, NULL);
0378c332 4100
50641945 4101 if (*string)
8a3fe4f8 4102 error (_("Junk at end of line specification: %s"), string);
50641945
FN
4103 return sals;
4104}
c5aa993b 4105
51cc5b07
AC
4106/* Track MAIN */
4107static char *name_of_main;
4108
4109void
4110set_main_name (const char *name)
4111{
4112 if (name_of_main != NULL)
4113 {
4114 xfree (name_of_main);
4115 name_of_main = NULL;
4116 }
4117 if (name != NULL)
4118 {
4119 name_of_main = xstrdup (name);
4120 }
4121}
4122
ea53e89f
JB
4123/* Deduce the name of the main procedure, and set NAME_OF_MAIN
4124 accordingly. */
4125
4126static void
4127find_main_name (void)
4128{
4129 char *new_main_name;
4130
4131 /* Try to see if the main procedure is in Ada. */
4132 /* FIXME: brobecker/2005-03-07: Another way of doing this would
4133 be to add a new method in the language vector, and call this
4134 method for each language until one of them returns a non-empty
4135 name. This would allow us to remove this hard-coded call to
4136 an Ada function. It is not clear that this is a better approach
4137 at this point, because all methods need to be written in a way
4138 such that false positives never be returned. For instance, it is
4139 important that a method does not return a wrong name for the main
4140 procedure if the main procedure is actually written in a different
4141 language. It is easy to guaranty this with Ada, since we use a
4142 special symbol generated only when the main in Ada to find the name
4143 of the main procedure. It is difficult however to see how this can
4144 be guarantied for languages such as C, for instance. This suggests
4145 that order of call for these methods becomes important, which means
4146 a more complicated approach. */
4147 new_main_name = ada_main_name ();
4148 if (new_main_name != NULL)
4149 {
4150 set_main_name (new_main_name);
4151 return;
4152 }
4153
4154 /* The languages above didn't identify the name of the main procedure.
4155 Fallback to "main". */
4156 set_main_name ("main");
4157}
4158
51cc5b07
AC
4159char *
4160main_name (void)
4161{
ea53e89f
JB
4162 if (name_of_main == NULL)
4163 find_main_name ();
4164
4165 return name_of_main;
51cc5b07
AC
4166}
4167
ea53e89f
JB
4168/* Handle ``executable_changed'' events for the symtab module. */
4169
4170static void
4171symtab_observer_executable_changed (void *unused)
4172{
4173 /* NAME_OF_MAIN may no longer be the same, so reset it for now. */
4174 set_main_name (NULL);
4175}
51cc5b07 4176
ed0616c6
VP
4177/* Helper to expand_line_sal below. Appends new sal to SAL,
4178 initializing it from SYMTAB, LINENO and PC. */
4179static void
4180append_expanded_sal (struct symtabs_and_lines *sal,
4181 struct symtab *symtab,
4182 int lineno, CORE_ADDR pc)
4183{
4184 CORE_ADDR func_addr, func_end;
4185
4186 sal->sals = xrealloc (sal->sals,
4187 sizeof (sal->sals[0])
4188 * (sal->nelts + 1));
4189 init_sal (sal->sals + sal->nelts);
4190 sal->sals[sal->nelts].symtab = symtab;
4191 sal->sals[sal->nelts].section = NULL;
4192 sal->sals[sal->nelts].end = 0;
4193 sal->sals[sal->nelts].line = lineno;
4194 sal->sals[sal->nelts].pc = pc;
4195 ++sal->nelts;
4196}
4197
4198/* Compute a set of all sals in
4199 the entire program that correspond to same file
4200 and line as SAL and return those. If there
4201 are several sals that belong to the same block,
4202 only one sal for the block is included in results. */
4203
4204struct symtabs_and_lines
4205expand_line_sal (struct symtab_and_line sal)
4206{
4207 struct symtabs_and_lines ret, this_line;
4208 int i, j;
4209 struct objfile *objfile;
4210 struct partial_symtab *psymtab;
4211 struct symtab *symtab;
4212 int lineno;
4213 int deleted = 0;
4214 struct block **blocks = NULL;
4215 int *filter;
4216
4217 ret.nelts = 0;
4218 ret.sals = NULL;
4219
4220 if (sal.symtab == NULL || sal.line == 0 || sal.pc != 0)
4221 {
4222 ret.sals = xmalloc (sizeof (struct symtab_and_line));
4223 ret.sals[0] = sal;
4224 ret.nelts = 1;
4225 return ret;
4226 }
4227 else
4228 {
4229 struct linetable_entry *best_item = 0;
4230 struct symtab *best_symtab = 0;
4231 int exact = 0;
4232
4233 lineno = sal.line;
4234
4235 /* We meed to find all symtabs for a file which name
4236 is described by sal. We cannot just directly
4237 iterate over symtabs, since a symtab might not be
4238 yet created. We also cannot iterate over psymtabs,
4239 calling PSYMTAB_TO_SYMTAB and working on that symtab,
4240 since PSYMTAB_TO_SYMTAB will return NULL for psymtab
4241 corresponding to an included file. Therefore, we do
4242 first pass over psymtabs, reading in those with
4243 the right name. Then, we iterate over symtabs, knowing
4244 that all symtabs we're interested in are loaded. */
4245
4246 ALL_PSYMTABS (objfile, psymtab)
4247 {
4248 if (strcmp (sal.symtab->filename,
4249 psymtab->filename) == 0)
4250 PSYMTAB_TO_SYMTAB (psymtab);
4251 }
4252
4253
4254 /* For each symtab, we add all pcs to ret.sals. I'm actually
4255 not sure what to do if we have exact match in one symtab,
4256 and non-exact match on another symtab.
4257 */
4258 ALL_SYMTABS (objfile, symtab)
4259 {
4260 if (strcmp (sal.symtab->filename,
4261 symtab->filename) == 0)
4262 {
4263 struct linetable *l;
4264 int len;
4265 l = LINETABLE (symtab);
4266 if (!l)
4267 continue;
4268 len = l->nitems;
4269
4270 for (j = 0; j < len; j++)
4271 {
4272 struct linetable_entry *item = &(l->item[j]);
4273
4274 if (item->line == lineno)
4275 {
4276 exact = 1;
4277 append_expanded_sal (&ret, symtab, lineno, item->pc);
4278 }
4279 else if (!exact && item->line > lineno
4280 && (best_item == NULL || item->line < best_item->line))
4281
4282 {
4283 best_item = item;
4284 best_symtab = symtab;
4285 }
4286 }
4287 }
4288 }
4289 if (!exact && best_item)
4290 append_expanded_sal (&ret, best_symtab, lineno, best_item->pc);
4291 }
4292
4293 /* For optimized code, compiler can scatter one source line accross
4294 disjoint ranges of PC values, even when no duplicate functions
4295 or inline functions are involved. For example, 'for (;;)' inside
4296 non-template non-inline non-ctor-or-dtor function can result
4297 in two PC ranges. In this case, we don't want to set breakpoint
4298 on first PC of each range. To filter such cases, we use containing
4299 blocks -- for each PC found above we see if there are other PCs
4300 that are in the same block. If yes, the other PCs are filtered out. */
4301
4302 filter = xmalloc (ret.nelts * sizeof (int));
4303 blocks = xmalloc (ret.nelts * sizeof (struct block *));
4304 for (i = 0; i < ret.nelts; ++i)
4305 {
4306 filter[i] = 1;
4307 blocks[i] = block_for_pc (ret.sals[i].pc);
4308 }
4309
4310 for (i = 0; i < ret.nelts; ++i)
4311 if (blocks[i] != NULL)
4312 for (j = i+1; j < ret.nelts; ++j)
4313 if (blocks[j] == blocks[i])
4314 {
4315 filter[j] = 0;
4316 ++deleted;
4317 break;
4318 }
4319
4320 {
4321 struct symtab_and_line *final =
4322 xmalloc (sizeof (struct symtab_and_line) * (ret.nelts-deleted));
4323
4324 for (i = 0, j = 0; i < ret.nelts; ++i)
4325 if (filter[i])
4326 final[j++] = ret.sals[i];
4327
4328 ret.nelts -= deleted;
4329 xfree (ret.sals);
4330 ret.sals = final;
4331 }
4332
4333 return ret;
4334}
4335
4336
c906108c 4337void
fba45db2 4338_initialize_symtab (void)
c906108c 4339{
1bedd215
AC
4340 add_info ("variables", variables_info, _("\
4341All global and static variable names, or those matching REGEXP."));
c906108c 4342 if (dbx_commands)
1bedd215
AC
4343 add_com ("whereis", class_info, variables_info, _("\
4344All global and static variable names, or those matching REGEXP."));
c906108c
SS
4345
4346 add_info ("functions", functions_info,
1bedd215 4347 _("All function names, or those matching REGEXP."));
c906108c 4348
357e46e7 4349
c906108c
SS
4350 /* FIXME: This command has at least the following problems:
4351 1. It prints builtin types (in a very strange and confusing fashion).
4352 2. It doesn't print right, e.g. with
c5aa993b
JM
4353 typedef struct foo *FOO
4354 type_print prints "FOO" when we want to make it (in this situation)
4355 print "struct foo *".
c906108c
SS
4356 I also think "ptype" or "whatis" is more likely to be useful (but if
4357 there is much disagreement "info types" can be fixed). */
4358 add_info ("types", types_info,
1bedd215 4359 _("All type names, or those matching REGEXP."));
c906108c 4360
c906108c 4361 add_info ("sources", sources_info,
1bedd215 4362 _("Source files in the program."));
c906108c
SS
4363
4364 add_com ("rbreak", class_breakpoint, rbreak_command,
1bedd215 4365 _("Set a breakpoint for all functions matching REGEXP."));
c906108c
SS
4366
4367 if (xdb_commands)
4368 {
1bedd215
AC
4369 add_com ("lf", class_info, sources_info,
4370 _("Source files in the program"));
4371 add_com ("lg", class_info, variables_info, _("\
4372All global and static variable names, or those matching REGEXP."));
c906108c
SS
4373 }
4374
4375 /* Initialize the one built-in type that isn't language dependent... */
4376 builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0,
4377 "<unknown type>", (struct objfile *) NULL);
ea53e89f
JB
4378
4379 observer_attach_executable_changed (symtab_observer_executable_changed);
c906108c 4380}
This page took 1.01443 seconds and 4 git commands to generate.