1
/* Symbol table lookup for the GNU debugger, GDB.
3
Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
5
Free Software Foundation, Inc.
6
Portions Copyright (C) 2001, 2002 Mission Critical Linux, Inc.
7
Copyright (c) 2002, 2003, 2004, 2005, 2007 Red Hat, Inc. All rights reserved.
9
This file is part of GDB.
11
This program is free software; you can redistribute it and/or modify
12
it under the terms of the GNU General Public License as published by
13
the Free Software Foundation; either version 2 of the License, or
14
(at your option) any later version.
16
This program is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
GNU General Public License for more details.
21
You should have received a copy of the GNU General Public License
22
along with this program; if not, write to the Free Software
23
Foundation, Inc., 59 Temple Place - Suite 330,
24
Boston, MA 02111-1307, USA. */
36
#include "call-cmds.h"
37
#include "gdb_regex.h"
38
#include "expression.h"
44
#include "filenames.h" /* for FILENAME_CMP */
45
#include "objc-lang.h"
49
#include "gdb_obstack.h"
51
#include "dictionary.h"
53
#include <sys/types.h>
55
#include "gdb_string.h"
60
/* Prototypes for local functions */
62
static void completion_list_add_name (char *, char *, int, char *, char *);
64
static void rbreak_command (char *, int);
66
static void types_info (char *, int);
68
static void functions_info (char *, int);
70
static void variables_info (char *, int);
72
static void sources_info (char *, int);
74
static void output_source_filename (char *, int *);
76
static int find_line_common (struct linetable *, int, int *);
78
/* This one is used by linespec.c */
80
char *operator_chars (char *p, char **end);
82
static struct symbol *lookup_symbol_aux (const char *name,
83
const char *linkage_name,
84
const struct block *block,
85
const domain_enum domain,
86
int *is_a_field_of_this,
87
struct symtab **symtab);
90
struct symbol *lookup_symbol_aux_local (const char *name,
91
const char *linkage_name,
92
const struct block *block,
93
const domain_enum domain,
94
struct symtab **symtab);
97
struct symbol *lookup_symbol_aux_symtabs (int block_index,
99
const char *linkage_name,
100
const domain_enum domain,
101
struct symtab **symtab);
104
struct symbol *lookup_symbol_aux_psymtabs (int block_index,
106
const char *linkage_name,
107
const domain_enum domain,
108
struct symtab **symtab);
112
struct symbol *lookup_symbol_aux_minsyms (const char *name,
113
const char *linkage_name,
114
const domain_enum domain,
115
int *is_a_field_of_this,
116
struct symtab **symtab);
119
/* This flag is used in hppa-tdep.c, and set in hp-symtab-read.c */
120
/* Signals the presence of objects compiled by HP compilers */
121
int hp_som_som_object_present = 0;
123
static void fixup_section (struct general_symbol_info *, struct objfile *);
125
static int file_matches (char *, char **, int);
127
static void print_symbol_info (domain_enum,
128
struct symtab *, struct symbol *, int, char *);
130
static void print_msymbol_info (struct minimal_symbol *);
132
static void symtab_symbol_info (char *, domain_enum, int);
134
void _initialize_symtab (void);
138
/* The single non-language-specific builtin type */
139
struct type *builtin_type_error;
141
/* Block in which the most recently searched-for symbol was found.
142
Might be better to make this a parameter to lookup_symbol and
145
const struct block *block_found;
147
/* Check for a symtab of a specific name; first in symtabs, then in
148
psymtabs. *If* there is no '/' in the name, a match after a '/'
149
in the symtab filename will also work. */
152
lookup_symtab (const char *name)
155
struct partial_symtab *ps;
156
struct objfile *objfile;
157
char *real_path = NULL;
158
char *full_path = NULL;
160
/* Here we are interested in canonicalizing an absolute path, not
161
absolutizing a relative path. */
162
if (IS_ABSOLUTE_PATH (name))
164
full_path = xfullpath (name);
165
make_cleanup (xfree, full_path);
166
real_path = gdb_realpath (name);
167
make_cleanup (xfree, real_path);
172
/* First, search for an exact match */
174
ALL_SYMTABS (objfile, s)
176
if (FILENAME_CMP (name, s->filename) == 0)
181
/* If the user gave us an absolute path, try to find the file in
182
this symtab and use its absolute path. */
184
if (full_path != NULL)
186
const char *fp = symtab_to_filename (s);
187
if (FILENAME_CMP (full_path, fp) == 0)
193
if (real_path != NULL)
195
char *rp = gdb_realpath (symtab_to_filename (s));
196
make_cleanup (xfree, rp);
197
if (FILENAME_CMP (real_path, rp) == 0)
204
/* Now, search for a matching tail (only if name doesn't have any dirs) */
206
if (lbasename (name) == name)
207
ALL_SYMTABS (objfile, s)
209
if (FILENAME_CMP (lbasename (s->filename), name) == 0)
213
/* Same search rules as above apply here, but now we look thru the
216
ps = lookup_partial_symtab (name);
221
error ("Internal: readin %s pst for `%s' found when no symtab found.",
224
s = PSYMTAB_TO_SYMTAB (ps);
229
/* At this point, we have located the psymtab for this file, but
230
the conversion to a symtab has failed. This usually happens
231
when we are looking up an include file. In this case,
232
PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
233
been created. So, we need to run through the symtabs again in
234
order to find the file.
235
XXX - This is a crock, and should be fixed inside of the the
236
symbol parsing routines. */
240
/* Lookup the partial symbol table of a source file named NAME.
241
*If* there is no '/' in the name, a match after a '/'
242
in the psymtab filename will also work. */
244
struct partial_symtab *
245
lookup_partial_symtab (const char *name)
247
struct partial_symtab *pst;
248
struct objfile *objfile;
249
char *full_path = NULL;
250
char *real_path = NULL;
252
/* Here we are interested in canonicalizing an absolute path, not
253
absolutizing a relative path. */
254
if (IS_ABSOLUTE_PATH (name))
256
full_path = xfullpath (name);
257
make_cleanup (xfree, full_path);
258
real_path = gdb_realpath (name);
259
make_cleanup (xfree, real_path);
262
ALL_PSYMTABS (objfile, pst)
264
if (FILENAME_CMP (name, pst->filename) == 0)
269
/* If the user gave us an absolute path, try to find the file in
270
this symtab and use its absolute path. */
271
if (full_path != NULL)
273
if (pst->fullname == NULL)
274
source_full_path_of (pst->filename, &pst->fullname);
275
if (pst->fullname != NULL
276
&& FILENAME_CMP (full_path, pst->fullname) == 0)
282
if (real_path != NULL)
285
if (pst->fullname == NULL)
286
source_full_path_of (pst->filename, &pst->fullname);
287
if (pst->fullname != NULL)
289
rp = gdb_realpath (pst->fullname);
290
make_cleanup (xfree, rp);
292
if (rp != NULL && FILENAME_CMP (real_path, rp) == 0)
299
/* Now, search for a matching tail (only if name doesn't have any dirs) */
301
if (lbasename (name) == name)
302
ALL_PSYMTABS (objfile, pst)
304
if (FILENAME_CMP (lbasename (pst->filename), name) == 0)
311
/* Mangle a GDB method stub type. This actually reassembles the pieces of the
312
full method name, which consist of the class name (from T), the unadorned
313
method name from METHOD_ID, and the signature for the specific overload,
314
specified by SIGNATURE_ID. Note that this function is g++ specific. */
317
gdb_mangle_name (struct type *type, int method_id, int signature_id)
319
int mangled_name_len;
321
struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
322
struct fn_field *method = &f[signature_id];
323
char *field_name = TYPE_FN_FIELDLIST_NAME (type, method_id);
324
char *physname = TYPE_FN_FIELD_PHYSNAME (f, signature_id);
325
char *newname = type_name_no_tag (type);
327
/* Does the form of physname indicate that it is the full mangled name
328
of a constructor (not just the args)? */
329
int is_full_physname_constructor;
332
int is_destructor = is_destructor_name (physname);
333
/* Need a new type prefix. */
334
char *const_prefix = method->is_const ? "C" : "";
335
char *volatile_prefix = method->is_volatile ? "V" : "";
337
int len = (newname == NULL ? 0 : strlen (newname));
339
/* Nothing to do if physname already contains a fully mangled v3 abi name
340
or an operator name. */
341
if ((physname[0] == '_' && physname[1] == 'Z')
342
|| is_operator_name (field_name))
343
return xstrdup (physname);
345
is_full_physname_constructor = is_constructor_name (physname);
348
is_full_physname_constructor || (newname && strcmp (field_name, newname) == 0);
351
is_destructor = (strncmp (physname, "__dt", 4) == 0);
353
if (is_destructor || is_full_physname_constructor)
355
mangled_name = (char *) xmalloc (strlen (physname) + 1);
356
strcpy (mangled_name, physname);
362
sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
364
else if (physname[0] == 't' || physname[0] == 'Q')
366
/* The physname for template and qualified methods already includes
368
sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
374
sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
376
mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
377
+ strlen (buf) + len + strlen (physname) + 1);
380
mangled_name = (char *) xmalloc (mangled_name_len);
382
mangled_name[0] = '\0';
384
strcpy (mangled_name, field_name);
386
strcat (mangled_name, buf);
387
/* If the class doesn't have a name, i.e. newname NULL, then we just
388
mangle it using 0 for the length of the class. Thus it gets mangled
389
as something starting with `::' rather than `classname::'. */
391
strcat (mangled_name, newname);
393
strcat (mangled_name, physname);
394
return (mangled_name);
398
/* Initialize the language dependent portion of a symbol
399
depending upon the language for the symbol. */
401
symbol_init_language_specific (struct general_symbol_info *gsymbol,
402
enum language language)
404
gsymbol->language = language;
405
if (gsymbol->language == language_cplus
406
|| gsymbol->language == language_java
407
|| gsymbol->language == language_objc)
409
gsymbol->language_specific.cplus_specific.demangled_name = NULL;
413
memset (&gsymbol->language_specific, 0,
414
sizeof (gsymbol->language_specific));
418
/* Functions to initialize a symbol's mangled name. */
420
/* Create the hash table used for demangled names. Each hash entry is
421
a pair of strings; one for the mangled name and one for the demangled
422
name. The entry is hashed via just the mangled name. */
425
create_demangled_names_hash (struct objfile *objfile)
427
/* Choose 256 as the starting size of the hash table, somewhat arbitrarily.
428
The hash table code will round this up to the next prime number.
429
Choosing a much larger table size wastes memory, and saves only about
430
1% in symbol reading. */
432
objfile->demangled_names_hash = htab_create_alloc_ex
433
(256, htab_hash_string, (int (*) (const void *, const void *)) streq,
434
NULL, objfile->md, xmcalloc, xmfree);
437
/* Try to determine the demangled name for a symbol, based on the
438
language of that symbol. If the language is set to language_auto,
439
it will attempt to find any demangling algorithm that works and
440
then set the language appropriately. The returned name is allocated
441
by the demangler and should be xfree'd. */
444
symbol_find_demangled_name (struct general_symbol_info *gsymbol,
447
char *demangled = NULL;
449
if (gsymbol->language == language_unknown)
450
gsymbol->language = language_auto;
452
if (gsymbol->language == language_objc
453
|| gsymbol->language == language_auto)
456
objc_demangle (mangled, 0);
457
if (demangled != NULL)
459
gsymbol->language = language_objc;
463
if (gsymbol->language == language_cplus
464
|| gsymbol->language == language_auto)
467
cplus_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
468
if (demangled != NULL)
470
gsymbol->language = language_cplus;
474
if (gsymbol->language == language_java)
477
cplus_demangle (mangled,
478
DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA);
479
if (demangled != NULL)
481
gsymbol->language = language_java;
488
/* Set both the mangled and demangled (if any) names for GSYMBOL based
489
on LINKAGE_NAME and LEN. The hash table corresponding to OBJFILE
490
is used, and the memory comes from that objfile's objfile_obstack.
491
LINKAGE_NAME is copied, so the pointer can be discarded after
492
calling this function. */
494
/* We have to be careful when dealing with Java names: when we run
495
into a Java minimal symbol, we don't know it's a Java symbol, so it
496
gets demangled as a C++ name. This is unfortunate, but there's not
497
much we can do about it: but when demangling partial symbols and
498
regular symbols, we'd better not reuse the wrong demangled name.
499
(See PR gdb/1039.) We solve this by putting a distinctive prefix
500
on Java names when storing them in the hash table. */
502
/* FIXME: carlton/2003-03-13: This is an unfortunate situation. I
503
don't mind the Java prefix so much: different languages have
504
different demangling requirements, so it's only natural that we
505
need to keep language data around in our demangling cache. But
506
it's not good that the minimal symbol has the wrong demangled name.
507
Unfortunately, I can't think of any easy solution to that
510
#define JAVA_PREFIX "##JAVA$$"
511
#define JAVA_PREFIX_LEN 8
514
symbol_set_names (struct general_symbol_info *gsymbol,
515
const char *linkage_name, int len, struct objfile *objfile)
518
/* A 0-terminated copy of the linkage name. */
519
const char *linkage_name_copy;
520
/* A copy of the linkage name that might have a special Java prefix
521
added to it, for use when looking names up in the hash table. */
522
const char *lookup_name;
523
/* The length of lookup_name. */
526
if (objfile->demangled_names_hash == NULL)
527
create_demangled_names_hash (objfile);
529
/* The stabs reader generally provides names that are not
530
NUL-terminated; most of the other readers don't do this, so we
531
can just use the given copy, unless we're in the Java case. */
532
if (gsymbol->language == language_java)
535
lookup_len = len + JAVA_PREFIX_LEN;
537
alloc_name = alloca (lookup_len + 1);
538
memcpy (alloc_name, JAVA_PREFIX, JAVA_PREFIX_LEN);
539
memcpy (alloc_name + JAVA_PREFIX_LEN, linkage_name, len);
540
alloc_name[lookup_len] = '\0';
542
lookup_name = alloc_name;
543
linkage_name_copy = alloc_name + JAVA_PREFIX_LEN;
545
else if (linkage_name[len] != '\0')
550
alloc_name = alloca (lookup_len + 1);
551
memcpy (alloc_name, linkage_name, len);
552
alloc_name[lookup_len] = '\0';
554
lookup_name = alloc_name;
555
linkage_name_copy = alloc_name;
560
lookup_name = linkage_name;
561
linkage_name_copy = linkage_name;
564
slot = (char **) htab_find_slot (objfile->demangled_names_hash,
565
lookup_name, INSERT);
567
/* If this name is not in the hash table, add it. */
570
char *demangled_name = symbol_find_demangled_name (gsymbol,
572
int demangled_len = demangled_name ? strlen (demangled_name) : 0;
574
/* If there is a demangled name, place it right after the mangled name.
575
Otherwise, just place a second zero byte after the end of the mangled
577
*slot = obstack_alloc (&objfile->objfile_obstack,
578
lookup_len + demangled_len + 2);
579
memcpy (*slot, lookup_name, lookup_len + 1);
580
if (demangled_name != NULL)
582
memcpy (*slot + lookup_len + 1, demangled_name, demangled_len + 1);
583
xfree (demangled_name);
586
(*slot)[lookup_len + 1] = '\0';
589
gsymbol->name = *slot + lookup_len - len;
590
if ((*slot)[lookup_len + 1] != '\0')
591
gsymbol->language_specific.cplus_specific.demangled_name
592
= &(*slot)[lookup_len + 1];
594
gsymbol->language_specific.cplus_specific.demangled_name = NULL;
597
/* Initialize the demangled name of GSYMBOL if possible. Any required space
598
to store the name is obtained from the specified obstack. The function
599
symbol_set_names, above, should be used instead where possible for more
600
efficient memory usage. */
603
symbol_init_demangled_name (struct general_symbol_info *gsymbol,
604
struct obstack *obstack)
606
char *mangled = gsymbol->name;
607
char *demangled = NULL;
609
demangled = symbol_find_demangled_name (gsymbol, mangled);
610
if (gsymbol->language == language_cplus
611
|| gsymbol->language == language_java
612
|| gsymbol->language == language_objc)
616
gsymbol->language_specific.cplus_specific.demangled_name
617
= obsavestring (demangled, strlen (demangled), obstack);
621
gsymbol->language_specific.cplus_specific.demangled_name = NULL;
625
/* Unknown language; just clean up quietly. */
631
/* Return the source code name of a symbol. In languages where
632
demangling is necessary, this is the demangled name. */
635
symbol_natural_name (const struct general_symbol_info *gsymbol)
637
if ((gsymbol->language == language_cplus
638
|| gsymbol->language == language_java
639
|| gsymbol->language == language_objc)
640
&& (gsymbol->language_specific.cplus_specific.demangled_name != NULL))
642
return gsymbol->language_specific.cplus_specific.demangled_name;
646
return gsymbol->name;
650
/* Return the demangled name for a symbol based on the language for
651
that symbol. If no demangled name exists, return NULL. */
653
symbol_demangled_name (struct general_symbol_info *gsymbol)
655
if (gsymbol->language == language_cplus
656
|| gsymbol->language == language_java
657
|| gsymbol->language == language_objc)
658
return gsymbol->language_specific.cplus_specific.demangled_name;
664
/* Initialize the structure fields to zero values. */
666
init_sal (struct symtab_and_line *sal)
677
/* Find which partial symtab contains PC and SECTION. Return 0 if
678
none. We return the psymtab that contains a symbol whose address
679
exactly matches PC, or, if we cannot find an exact match, the
680
psymtab that contains a symbol whose address is closest to PC. */
681
struct partial_symtab *
682
find_pc_sect_psymtab (CORE_ADDR pc, asection *section)
684
struct partial_symtab *pst;
685
struct objfile *objfile;
686
struct minimal_symbol *msymbol;
688
/* If we know that this is not a text address, return failure. This is
689
necessary because we loop based on texthigh and textlow, which do
690
not include the data ranges. */
691
msymbol = lookup_minimal_symbol_by_pc_section (pc, section);
693
&& (msymbol->type == mst_data
694
|| msymbol->type == mst_bss
695
|| msymbol->type == mst_abs
696
|| msymbol->type == mst_file_data
697
|| msymbol->type == mst_file_bss))
700
ALL_PSYMTABS (objfile, pst)
702
if (pc >= pst->textlow && pc < pst->texthigh)
704
struct partial_symtab *tpst;
705
struct partial_symtab *best_pst = pst;
706
struct partial_symbol *best_psym = NULL;
708
/* An objfile that has its functions reordered might have
709
many partial symbol tables containing the PC, but
710
we want the partial symbol table that contains the
711
function containing the PC. */
712
if (!(objfile->flags & OBJF_REORDERED) &&
713
section == 0) /* can't validate section this way */
719
/* The code range of partial symtabs sometimes overlap, so, in
720
the loop below, we need to check all partial symtabs and
721
find the one that fits better for the given PC address. We
722
select the partial symtab that contains a symbol whose
723
address is closest to the PC address. By closest we mean
724
that find_pc_sect_symbol returns the symbol with address
725
that is closest and still less than the given PC. */
726
for (tpst = pst; tpst != NULL; tpst = tpst->next)
728
if (pc >= tpst->textlow && pc < tpst->texthigh)
730
struct partial_symbol *p;
732
p = find_pc_sect_psymbol (tpst, pc, section);
734
&& SYMBOL_VALUE_ADDRESS (p)
735
== SYMBOL_VALUE_ADDRESS (msymbol))
739
/* We found a symbol in this partial symtab which
740
matches (or is closest to) PC, check whether it
741
is closer than our current BEST_PSYM. Since
742
this symbol address is necessarily lower or
743
equal to PC, the symbol closer to PC is the
744
symbol which address is the highest. */
745
/* This way we return the psymtab which contains
746
such best match symbol. This can help in cases
747
where the symbol information/debuginfo is not
748
complete, like for instance on IRIX6 with gcc,
749
where no debug info is emitted for
750
statics. (See also the nodebug.exp
752
if (best_psym == NULL
753
|| SYMBOL_VALUE_ADDRESS (p)
754
> SYMBOL_VALUE_ADDRESS (best_psym))
769
/* Find which partial symtab contains PC. Return 0 if none.
770
Backward compatibility, no section */
772
struct partial_symtab *
773
find_pc_psymtab (CORE_ADDR pc)
775
return find_pc_sect_psymtab (pc, find_pc_mapped_section (pc));
778
/* Find which partial symbol within a psymtab matches PC and SECTION.
779
Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
781
struct partial_symbol *
782
find_pc_sect_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc,
785
struct partial_symbol *best = NULL, *p, **pp;
789
psymtab = find_pc_sect_psymtab (pc, section);
793
/* Cope with programs that start at address 0 */
794
best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
796
/* Search the global symbols as well as the static symbols, so that
797
find_pc_partial_function doesn't use a minimal symbol and thus
798
cache a bad endaddr. */
799
for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
800
(pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
801
< psymtab->n_global_syms);
805
if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
806
&& SYMBOL_CLASS (p) == LOC_BLOCK
807
&& pc >= SYMBOL_VALUE_ADDRESS (p)
808
&& (SYMBOL_VALUE_ADDRESS (p) > best_pc
809
|| (psymtab->textlow == 0
810
&& best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
812
if (section) /* match on a specific section */
814
fixup_psymbol_section (p, psymtab->objfile);
815
if (SYMBOL_BFD_SECTION (p) != section)
818
best_pc = SYMBOL_VALUE_ADDRESS (p);
823
for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
824
(pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
825
< psymtab->n_static_syms);
829
if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
830
&& SYMBOL_CLASS (p) == LOC_BLOCK
831
&& pc >= SYMBOL_VALUE_ADDRESS (p)
832
&& (SYMBOL_VALUE_ADDRESS (p) > best_pc
833
|| (psymtab->textlow == 0
834
&& best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
836
if (section) /* match on a specific section */
838
fixup_psymbol_section (p, psymtab->objfile);
839
if (SYMBOL_BFD_SECTION (p) != section)
842
best_pc = SYMBOL_VALUE_ADDRESS (p);
850
/* Find which partial symbol within a psymtab matches PC. Return 0 if none.
851
Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
853
struct partial_symbol *
854
find_pc_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc)
856
return find_pc_sect_psymbol (psymtab, pc, find_pc_mapped_section (pc));
859
/* Debug symbols usually don't have section information. We need to dig that
860
out of the minimal symbols and stash that in the debug symbol. */
863
fixup_section (struct general_symbol_info *ginfo, struct objfile *objfile)
865
struct minimal_symbol *msym;
866
msym = lookup_minimal_symbol (ginfo->name, NULL, objfile);
870
ginfo->bfd_section = SYMBOL_BFD_SECTION (msym);
871
ginfo->section = SYMBOL_SECTION (msym);
876
fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
881
if (SYMBOL_BFD_SECTION (sym))
884
fixup_section (&sym->ginfo, objfile);
889
struct partial_symbol *
890
fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
895
if (SYMBOL_BFD_SECTION (psym))
898
fixup_section (&psym->ginfo, objfile);
903
/* Find the definition for a specified symbol name NAME
904
in domain DOMAIN, visible from lexical block BLOCK.
905
Returns the struct symbol pointer, or zero if no symbol is found.
906
If SYMTAB is non-NULL, store the symbol table in which the
907
symbol was found there, or NULL if not found.
908
C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
909
NAME is a field of the current implied argument `this'. If so set
910
*IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
911
BLOCK_FOUND is set to the block in which NAME is found (in the case of
912
a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
914
/* This function has a bunch of loops in it and it would seem to be
915
attractive to put in some QUIT's (though I'm not really sure
916
whether it can run long enough to be really important). But there
917
are a few calls for which it would appear to be bad news to quit
918
out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c. (Note
919
that there is C++ code below which can error(), but that probably
920
doesn't affect these calls since they are looking for a known
921
variable and thus can probably assume it will never hit the C++
924
static void gdb_bait_and_switch(char *, struct symbol *);
927
lookup_symbol (const char *name, const struct block *block,
928
const domain_enum domain, int *is_a_field_of_this,
929
struct symtab **symtab)
931
char *demangled_name = NULL;
932
const char *modified_name = NULL;
933
const char *mangled_name = NULL;
934
int needtofreename = 0;
935
struct symbol *returnval;
937
modified_name = name;
939
/* If we are using C++ language, demangle the name before doing a lookup, so
940
we can always binary search. */
941
if (current_language->la_language == language_cplus)
943
demangled_name = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS);
947
modified_name = demangled_name;
952
if (case_sensitivity == case_sensitive_off)
958
copy = (char *) alloca (len + 1);
959
for (i= 0; i < len; i++)
960
copy[i] = tolower (name[i]);
962
modified_name = copy;
965
returnval = lookup_symbol_aux (modified_name, mangled_name, block,
966
domain, is_a_field_of_this, symtab);
968
xfree (demangled_name);
971
if (returnval && (domain == VAR_DOMAIN)) {
972
gdb_bait_and_switch((char *)modified_name, returnval);
979
/* Behave like lookup_symbol_aux except that NAME is the natural name
980
of the symbol that we're looking for and, if LINKAGE_NAME is
981
non-NULL, ensure that the symbol's linkage name matches as
984
static struct symbol *
985
lookup_symbol_aux (const char *name, const char *linkage_name,
986
const struct block *block, const domain_enum domain,
987
int *is_a_field_of_this, struct symtab **symtab)
991
/* Make sure we do something sensible with is_a_field_of_this, since
992
the callers that set this parameter to some non-null value will
993
certainly use it later and expect it to be either 0 or 1.
994
If we don't set it, the contents of is_a_field_of_this are
996
if (is_a_field_of_this != NULL)
997
*is_a_field_of_this = 0;
999
/* Search specified block and its superiors. Don't search
1000
STATIC_BLOCK or GLOBAL_BLOCK. */
1002
sym = lookup_symbol_aux_local (name, linkage_name, block, domain,
1007
/* If requested to do so by the caller and if appropriate for the
1008
current language, check to see if NAME is a field of `this'. */
1010
if (current_language->la_value_of_this != NULL
1011
&& is_a_field_of_this != NULL)
1013
struct value *v = current_language->la_value_of_this (0);
1015
if (v && check_field (v, name))
1017
*is_a_field_of_this = 1;
1024
/* Now do whatever is appropriate for the current language to look
1025
up static and global variables. */
1027
sym = current_language->la_lookup_symbol_nonlocal (name, linkage_name,
1033
/* Now search all static file-level symbols. Not strictly correct,
1034
but more useful than an error. Do the symtabs first, then check
1035
the psymtabs. If a psymtab indicates the existence of the
1036
desired name as a file-level static, then do psymtab-to-symtab
1037
conversion on the fly and return the found symbol. */
1039
sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, linkage_name,
1044
sym = lookup_symbol_aux_psymtabs (STATIC_BLOCK, name, linkage_name,
1054
/* Check to see if the symbol is defined in BLOCK or its superiors.
1055
Don't search STATIC_BLOCK or GLOBAL_BLOCK. */
1057
static struct symbol *
1058
lookup_symbol_aux_local (const char *name, const char *linkage_name,
1059
const struct block *block,
1060
const domain_enum domain,
1061
struct symtab **symtab)
1064
const struct block *static_block = block_static_block (block);
1066
/* Check if either no block is specified or it's a global block. */
1068
if (static_block == NULL)
1071
while (block != static_block)
1073
sym = lookup_symbol_aux_block (name, linkage_name, block, domain,
1077
block = BLOCK_SUPERBLOCK (block);
1080
/* We've reached the static block without finding a result. */
1085
/* Look up a symbol in a block; if found, locate its symtab, fixup the
1086
symbol, and set block_found appropriately. */
1089
lookup_symbol_aux_block (const char *name, const char *linkage_name,
1090
const struct block *block,
1091
const domain_enum domain,
1092
struct symtab **symtab)
1095
struct objfile *objfile = NULL;
1096
struct blockvector *bv;
1098
struct symtab *s = NULL;
1100
sym = lookup_block_symbol (block, name, linkage_name, domain);
1103
block_found = block;
1106
/* Search the list of symtabs for one which contains the
1107
address of the start of this block. */
1108
ALL_SYMTABS (objfile, s)
1110
bv = BLOCKVECTOR (s);
1111
b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1112
if (BLOCK_START (b) <= BLOCK_START (block)
1113
&& BLOCK_END (b) > BLOCK_START (block))
1120
return fixup_symbol_section (sym, objfile);
1126
/* Check to see if the symbol is defined in one of the symtabs.
1127
BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
1128
depending on whether or not we want to search global symbols or
1131
static struct symbol *
1132
lookup_symbol_aux_symtabs (int block_index,
1133
const char *name, const char *linkage_name,
1134
const domain_enum domain,
1135
struct symtab **symtab)
1138
struct objfile *objfile;
1139
struct blockvector *bv;
1140
const struct block *block;
1143
ALL_SYMTABS (objfile, s)
1145
bv = BLOCKVECTOR (s);
1146
block = BLOCKVECTOR_BLOCK (bv, block_index);
1147
sym = lookup_block_symbol (block, name, linkage_name, domain);
1150
block_found = block;
1153
return fixup_symbol_section (sym, objfile);
1160
/* Check to see if the symbol is defined in one of the partial
1161
symtabs. BLOCK_INDEX should be either GLOBAL_BLOCK or
1162
STATIC_BLOCK, depending on whether or not we want to search global
1163
symbols or static symbols. */
1165
static struct symbol *
1166
lookup_symbol_aux_psymtabs (int block_index, const char *name,
1167
const char *linkage_name,
1168
const domain_enum domain,
1169
struct symtab **symtab)
1172
struct objfile *objfile;
1173
struct blockvector *bv;
1174
const struct block *block;
1175
struct partial_symtab *ps;
1177
const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
1179
ALL_PSYMTABS (objfile, ps)
1182
&& lookup_partial_symbol (ps, name, linkage_name,
1183
psymtab_index, domain))
1185
s = PSYMTAB_TO_SYMTAB (ps);
1186
bv = BLOCKVECTOR (s);
1187
block = BLOCKVECTOR_BLOCK (bv, block_index);
1188
sym = lookup_block_symbol (block, name, linkage_name, domain);
1191
/* This shouldn't be necessary, but as a last resort try
1192
looking in the statics even though the psymtab claimed
1193
the symbol was global, or vice-versa. It's possible
1194
that the psymtab gets it wrong in some cases. */
1196
/* FIXME: carlton/2002-09-30: Should we really do that?
1197
If that happens, isn't it likely to be a GDB error, in
1198
which case we should fix the GDB error rather than
1199
silently dealing with it here? So I'd vote for
1200
removing the check for the symbol in the other
1202
block = BLOCKVECTOR_BLOCK (bv,
1203
block_index == GLOBAL_BLOCK ?
1204
STATIC_BLOCK : GLOBAL_BLOCK);
1205
sym = lookup_block_symbol (block, name, linkage_name, domain);
1207
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>).",
1208
block_index == GLOBAL_BLOCK ? "global" : "static",
1209
name, ps->filename, name, name);
1213
return fixup_symbol_section (sym, objfile);
1221
/* Check for the possibility of the symbol being a function or a
1222
mangled variable that is stored in one of the minimal symbol
1223
tables. Eventually, all global symbols might be resolved in this
1226
/* NOTE: carlton/2002-12-05: At one point, this function was part of
1227
lookup_symbol_aux, and what are now 'return' statements within
1228
lookup_symbol_aux_minsyms returned from lookup_symbol_aux, even if
1229
sym was NULL. As far as I can tell, this was basically accidental;
1230
it didn't happen every time that msymbol was non-NULL, but only if
1231
some additional conditions held as well, and it caused problems
1232
with HP-generated symbol tables. */
1234
/* NOTE: carlton/2003-05-14: This function was once used as part of
1235
lookup_symbol. It is currently unnecessary for correctness
1236
reasons, however, and using it doesn't seem to be any faster than
1237
using lookup_symbol_aux_psymtabs, so I'm commenting it out. */
1239
static struct symbol *
1240
lookup_symbol_aux_minsyms (const char *name,
1241
const char *linkage_name,
1242
const domain_enum domain,
1243
int *is_a_field_of_this,
1244
struct symtab **symtab)
1247
struct blockvector *bv;
1248
const struct block *block;
1249
struct minimal_symbol *msymbol;
1252
if (domain == VAR_DOMAIN)
1254
msymbol = lookup_minimal_symbol (name, NULL, NULL);
1256
if (msymbol != NULL)
1258
/* OK, we found a minimal symbol in spite of not finding any
1259
symbol. There are various possible explanations for
1260
this. One possibility is the symbol exists in code not
1261
compiled -g. Another possibility is that the 'psymtab'
1262
isn't doing its job. A third possibility, related to #2,
1263
is that we were confused by name-mangling. For instance,
1264
maybe the psymtab isn't doing its job because it only
1265
know about demangled names, but we were given a mangled
1268
/* We first use the address in the msymbol to try to locate
1269
the appropriate symtab. Note that find_pc_sect_symtab()
1270
has a side-effect of doing psymtab-to-symtab expansion,
1271
for the found symtab. */
1272
s = find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol),
1273
SYMBOL_BFD_SECTION (msymbol));
1276
/* This is a function which has a symtab for its address. */
1277
bv = BLOCKVECTOR (s);
1278
block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1280
/* This call used to pass `SYMBOL_LINKAGE_NAME (msymbol)' as the
1281
`name' argument to lookup_block_symbol. But the name
1282
of a minimal symbol is always mangled, so that seems
1283
to be clearly the wrong thing to pass as the
1286
lookup_block_symbol (block, name, linkage_name, domain);
1287
/* We kept static functions in minimal symbol table as well as
1288
in static scope. We want to find them in the symbol table. */
1291
block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1292
sym = lookup_block_symbol (block, name,
1293
linkage_name, domain);
1296
/* NOTE: carlton/2002-12-04: The following comment was
1297
taken from a time when two versions of this function
1298
were part of the body of lookup_symbol_aux: this
1299
comment was taken from the version of the function
1300
that was #ifdef HPUXHPPA, and the comment was right
1301
before the 'return NULL' part of lookup_symbol_aux.
1302
(Hence the "Fall through and return 0" comment.)
1303
Elena did some digging into the situation for
1304
Fortran, and she reports:
1306
"I asked around (thanks to Jeff Knaggs), and I think
1307
the story for Fortran goes like this:
1309
"Apparently, in older Fortrans, '_' was not part of
1310
the user namespace. g77 attached a final '_' to
1311
procedure names as the exported symbols for linkage
1312
(foo_) , but the symbols went in the debug info just
1313
like 'foo'. The rationale behind this is not
1314
completely clear, and maybe it was done to other
1315
symbols as well, not just procedures." */
1317
/* If we get here with sym == 0, the symbol was
1318
found in the minimal symbol table
1319
but not in the symtab.
1320
Fall through and return 0 to use the msymbol
1321
definition of "foo_".
1322
(Note that outer code generally follows up a call
1323
to this routine with a call to lookup_minimal_symbol(),
1324
so a 0 return means we'll just flow into that other routine).
1326
This happens for Fortran "foo_" symbols,
1327
which are "foo" in the symtab.
1329
This can also happen if "asm" is used to make a
1330
regular symbol but not a debugging symbol, e.g.
1331
asm(".globl _main");
1335
if (symtab != NULL && sym != NULL)
1337
return fixup_symbol_section (sym, s->objfile);
1346
/* A default version of lookup_symbol_nonlocal for use by languages
1347
that can't think of anything better to do. This implements the C
1351
basic_lookup_symbol_nonlocal (const char *name,
1352
const char *linkage_name,
1353
const struct block *block,
1354
const domain_enum domain,
1355
struct symtab **symtab)
1359
/* NOTE: carlton/2003-05-19: The comments below were written when
1360
this (or what turned into this) was part of lookup_symbol_aux;
1361
I'm much less worried about these questions now, since these
1362
decisions have turned out well, but I leave these comments here
1365
/* NOTE: carlton/2002-12-05: There is a question as to whether or
1366
not it would be appropriate to search the current global block
1367
here as well. (That's what this code used to do before the
1368
is_a_field_of_this check was moved up.) On the one hand, it's
1369
redundant with the lookup_symbol_aux_symtabs search that happens
1370
next. On the other hand, if decode_line_1 is passed an argument
1371
like filename:var, then the user presumably wants 'var' to be
1372
searched for in filename. On the third hand, there shouldn't be
1373
multiple global variables all of which are named 'var', and it's
1374
not like decode_line_1 has ever restricted its search to only
1375
global variables in a single filename. All in all, only
1376
searching the static block here seems best: it's correct and it's
1379
/* NOTE: carlton/2002-12-05: There's also a possible performance
1380
issue here: if you usually search for global symbols in the
1381
current file, then it would be slightly better to search the
1382
current global block before searching all the symtabs. But there
1383
are other factors that have a much greater effect on performance
1384
than that one, so I don't think we should worry about that for
1387
sym = lookup_symbol_static (name, linkage_name, block, domain, symtab);
1391
return lookup_symbol_global (name, linkage_name, domain, symtab);
1394
/* Lookup a symbol in the static block associated to BLOCK, if there
1395
is one; do nothing if BLOCK is NULL or a global block. */
1398
lookup_symbol_static (const char *name,
1399
const char *linkage_name,
1400
const struct block *block,
1401
const domain_enum domain,
1402
struct symtab **symtab)
1404
const struct block *static_block = block_static_block (block);
1406
if (static_block != NULL)
1407
return lookup_symbol_aux_block (name, linkage_name, static_block,
1413
/* Lookup a symbol in all files' global blocks (searching psymtabs if
1417
lookup_symbol_global (const char *name,
1418
const char *linkage_name,
1419
const domain_enum domain,
1420
struct symtab **symtab)
1424
sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, linkage_name,
1429
return lookup_symbol_aux_psymtabs (GLOBAL_BLOCK, name, linkage_name,
1433
/* Look, in partial_symtab PST, for symbol whose natural name is NAME.
1434
If LINKAGE_NAME is non-NULL, check in addition that the symbol's
1435
linkage name matches it. Check the global symbols if GLOBAL, the
1436
static symbols if not */
1438
struct partial_symbol *
1439
lookup_partial_symbol (struct partial_symtab *pst, const char *name,
1440
const char *linkage_name, int global,
1443
struct partial_symbol *temp;
1444
struct partial_symbol **start, **psym;
1445
struct partial_symbol **top, **real_top, **bottom, **center;
1446
int length = (global ? pst->n_global_syms : pst->n_static_syms);
1447
int do_linear_search = 1;
1454
pst->objfile->global_psymbols.list + pst->globals_offset :
1455
pst->objfile->static_psymbols.list + pst->statics_offset);
1457
if (global) /* This means we can use a binary search. */
1459
do_linear_search = 0;
1461
/* Binary search. This search is guaranteed to end with center
1462
pointing at the earliest partial symbol whose name might be
1463
correct. At that point *all* partial symbols with an
1464
appropriate name will be checked against the correct
1468
top = start + length - 1;
1470
while (top > bottom)
1472
center = bottom + (top - bottom) / 2;
1473
if (!(center < top))
1474
internal_error (__FILE__, __LINE__, "failed internal consistency check");
1475
if (!do_linear_search
1476
&& (SYMBOL_LANGUAGE (*center) == language_java))
1478
do_linear_search = 1;
1480
if (strcmp_iw_ordered (SYMBOL_NATURAL_NAME (*center), name) >= 0)
1486
bottom = center + 1;
1489
if (!(top == bottom))
1490
internal_error (__FILE__, __LINE__, "failed internal consistency check");
1492
while (top <= real_top
1493
&& (linkage_name != NULL
1494
? strcmp (SYMBOL_LINKAGE_NAME (*top), linkage_name) == 0
1495
: SYMBOL_MATCHES_NATURAL_NAME (*top,name)))
1497
if (SYMBOL_DOMAIN (*top) == domain)
1505
/* Can't use a binary search or else we found during the binary search that
1506
we should also do a linear search. */
1508
if (do_linear_search)
1510
for (psym = start; psym < start + length; psym++)
1512
if (domain == SYMBOL_DOMAIN (*psym))
1514
if (linkage_name != NULL
1515
? strcmp (SYMBOL_LINKAGE_NAME (*psym), linkage_name) == 0
1516
: SYMBOL_MATCHES_NATURAL_NAME (*psym, name))
1527
/* Look up a type named NAME in the struct_domain. The type returned
1528
must not be opaque -- i.e., must have at least one field
1532
lookup_transparent_type (const char *name)
1534
return current_language->la_lookup_transparent_type (name);
1537
/* The standard implementation of lookup_transparent_type. This code
1538
was modeled on lookup_symbol -- the parts not relevant to looking
1539
up types were just left out. In particular it's assumed here that
1540
types are available in struct_domain and only at file-static or
1544
basic_lookup_transparent_type (const char *name)
1547
struct symtab *s = NULL;
1548
struct partial_symtab *ps;
1549
struct blockvector *bv;
1550
struct objfile *objfile;
1551
struct block *block;
1553
/* Now search all the global symbols. Do the symtab's first, then
1554
check the psymtab's. If a psymtab indicates the existence
1555
of the desired name as a global, then do psymtab-to-symtab
1556
conversion on the fly and return the found symbol. */
1558
ALL_SYMTABS (objfile, s)
1560
bv = BLOCKVECTOR (s);
1561
block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1562
sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
1563
if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1565
return SYMBOL_TYPE (sym);
1569
ALL_PSYMTABS (objfile, ps)
1571
if (!ps->readin && lookup_partial_symbol (ps, name, NULL,
1574
s = PSYMTAB_TO_SYMTAB (ps);
1575
bv = BLOCKVECTOR (s);
1576
block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1577
sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
1580
/* This shouldn't be necessary, but as a last resort
1581
* try looking in the statics even though the psymtab
1582
* claimed the symbol was global. It's possible that
1583
* the psymtab gets it wrong in some cases.
1585
block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1586
sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
1588
error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
1589
%s may be an inlined function, or may be a template function\n\
1590
(if a template, try specifying an instantiation: %s<type>).",
1591
name, ps->filename, name, name);
1593
if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1594
return SYMBOL_TYPE (sym);
1598
/* Now search the static file-level symbols.
1599
Not strictly correct, but more useful than an error.
1600
Do the symtab's first, then
1601
check the psymtab's. If a psymtab indicates the existence
1602
of the desired name as a file-level static, then do psymtab-to-symtab
1603
conversion on the fly and return the found symbol.
1606
ALL_SYMTABS (objfile, s)
1608
bv = BLOCKVECTOR (s);
1609
block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1610
sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
1611
if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1613
return SYMBOL_TYPE (sym);
1617
ALL_PSYMTABS (objfile, ps)
1619
if (!ps->readin && lookup_partial_symbol (ps, name, NULL, 0, STRUCT_DOMAIN))
1621
s = PSYMTAB_TO_SYMTAB (ps);
1622
bv = BLOCKVECTOR (s);
1623
block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1624
sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
1627
/* This shouldn't be necessary, but as a last resort
1628
* try looking in the globals even though the psymtab
1629
* claimed the symbol was static. It's possible that
1630
* the psymtab gets it wrong in some cases.
1632
block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1633
sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
1635
error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
1636
%s may be an inlined function, or may be a template function\n\
1637
(if a template, try specifying an instantiation: %s<type>).",
1638
name, ps->filename, name, name);
1640
if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1641
return SYMBOL_TYPE (sym);
1644
return (struct type *) 0;
1648
/* Find the psymtab containing main(). */
1649
/* FIXME: What about languages without main() or specially linked
1650
executables that have no main() ? */
1652
struct partial_symtab *
1653
find_main_psymtab (void)
1655
struct partial_symtab *pst;
1656
struct objfile *objfile;
1658
ALL_PSYMTABS (objfile, pst)
1660
if (lookup_partial_symbol (pst, main_name (), NULL, 1, VAR_DOMAIN))
1668
/* Search BLOCK for symbol NAME in DOMAIN.
1670
Note that if NAME is the demangled form of a C++ symbol, we will fail
1671
to find a match during the binary search of the non-encoded names, but
1672
for now we don't worry about the slight inefficiency of looking for
1673
a match we'll never find, since it will go pretty quick. Once the
1674
binary search terminates, we drop through and do a straight linear
1675
search on the symbols. Each symbol which is marked as being a ObjC/C++
1676
symbol (language_cplus or language_objc set) has both the encoded and
1677
non-encoded names tested for a match.
1679
If LINKAGE_NAME is non-NULL, verify that any symbol we find has this
1680
particular mangled name.
1684
lookup_block_symbol (const struct block *block, const char *name,
1685
const char *linkage_name,
1686
const domain_enum domain)
1688
struct dict_iterator iter;
1691
if (!BLOCK_FUNCTION (block))
1693
for (sym = dict_iter_name_first (BLOCK_DICT (block), name, &iter);
1695
sym = dict_iter_name_next (name, &iter))
1697
if (SYMBOL_DOMAIN (sym) == domain
1698
&& (linkage_name != NULL
1699
? strcmp (SYMBOL_LINKAGE_NAME (sym), linkage_name) == 0 : 1))
1706
/* Note that parameter symbols do not always show up last in the
1707
list; this loop makes sure to take anything else other than
1708
parameter symbols first; it only uses parameter symbols as a
1709
last resort. Note that this only takes up extra computation
1712
struct symbol *sym_found = NULL;
1714
for (sym = dict_iter_name_first (BLOCK_DICT (block), name, &iter);
1716
sym = dict_iter_name_next (name, &iter))
1718
if (SYMBOL_DOMAIN (sym) == domain
1719
&& (linkage_name != NULL
1720
? strcmp (SYMBOL_LINKAGE_NAME (sym), linkage_name) == 0 : 1))
1723
if (SYMBOL_CLASS (sym) != LOC_ARG &&
1724
SYMBOL_CLASS (sym) != LOC_LOCAL_ARG &&
1725
SYMBOL_CLASS (sym) != LOC_REF_ARG &&
1726
SYMBOL_CLASS (sym) != LOC_REGPARM &&
1727
SYMBOL_CLASS (sym) != LOC_REGPARM_ADDR &&
1728
SYMBOL_CLASS (sym) != LOC_BASEREG_ARG &&
1729
SYMBOL_CLASS (sym) != LOC_COMPUTED_ARG)
1735
return (sym_found); /* Will be NULL if not found. */
1739
/* Find the symtab associated with PC and SECTION. Look through the
1740
psymtabs and read in another symtab if necessary. */
1743
find_pc_sect_symtab (CORE_ADDR pc, asection *section)
1746
struct blockvector *bv;
1747
struct symtab *s = NULL;
1748
struct symtab *best_s = NULL;
1749
struct partial_symtab *ps;
1750
struct objfile *objfile;
1751
CORE_ADDR distance = 0;
1752
struct minimal_symbol *msymbol;
1754
/* If we know that this is not a text address, return failure. This is
1755
necessary because we loop based on the block's high and low code
1756
addresses, which do not include the data ranges, and because
1757
we call find_pc_sect_psymtab which has a similar restriction based
1758
on the partial_symtab's texthigh and textlow. */
1759
msymbol = lookup_minimal_symbol_by_pc_section (pc, section);
1761
&& (msymbol->type == mst_data
1762
|| msymbol->type == mst_bss
1763
|| msymbol->type == mst_abs
1764
|| msymbol->type == mst_file_data
1765
|| msymbol->type == mst_file_bss))
1768
/* Search all symtabs for the one whose file contains our address, and which
1769
is the smallest of all the ones containing the address. This is designed
1770
to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1771
and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1772
0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1774
This happens for native ecoff format, where code from included files
1775
gets its own symtab. The symtab for the included file should have
1776
been read in already via the dependency mechanism.
1777
It might be swifter to create several symtabs with the same name
1778
like xcoff does (I'm not sure).
1780
It also happens for objfiles that have their functions reordered.
1781
For these, the symtab we are looking for is not necessarily read in. */
1783
ALL_SYMTABS (objfile, s)
1785
bv = BLOCKVECTOR (s);
1786
b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1788
if (BLOCK_START (b) <= pc
1789
&& BLOCK_END (b) > pc
1791
|| BLOCK_END (b) - BLOCK_START (b) < distance))
1793
/* For an objfile that has its functions reordered,
1794
find_pc_psymtab will find the proper partial symbol table
1795
and we simply return its corresponding symtab. */
1796
/* In order to better support objfiles that contain both
1797
stabs and coff debugging info, we continue on if a psymtab
1799
if ((objfile->flags & OBJF_REORDERED) && objfile->psymtabs)
1801
ps = find_pc_sect_psymtab (pc, section);
1803
return PSYMTAB_TO_SYMTAB (ps);
1807
struct dict_iterator iter;
1808
struct symbol *sym = NULL;
1810
ALL_BLOCK_SYMBOLS (b, iter, sym)
1812
fixup_symbol_section (sym, objfile);
1813
if (section == SYMBOL_BFD_SECTION (sym))
1817
continue; /* no symbol in this symtab matches section */
1819
distance = BLOCK_END (b) - BLOCK_START (b);
1828
ps = find_pc_sect_psymtab (pc, section);
1832
/* Might want to error() here (in case symtab is corrupt and
1833
will cause a core dump), but maybe we can successfully
1834
continue, so let's not. */
1836
(Internal error: pc 0x%s in read in psymtab, but not in symtab.)\n",
1838
s = PSYMTAB_TO_SYMTAB (ps);
1843
/* Find the symtab associated with PC. Look through the psymtabs and
1844
read in another symtab if necessary. Backward compatibility, no section */
1847
find_pc_symtab (CORE_ADDR pc)
1849
return find_pc_sect_symtab (pc, find_pc_mapped_section (pc));
1853
/* Find the source file and line number for a given PC value and SECTION.
1854
Return a structure containing a symtab pointer, a line number,
1855
and a pc range for the entire source line.
1856
The value's .pc field is NOT the specified pc.
1857
NOTCURRENT nonzero means, if specified pc is on a line boundary,
1858
use the line that ends there. Otherwise, in that case, the line
1859
that begins there is used. */
1861
/* The big complication here is that a line may start in one file, and end just
1862
before the start of another file. This usually occurs when you #include
1863
code in the middle of a subroutine. To properly find the end of a line's PC
1864
range, we must search all symtabs associated with this compilation unit, and
1865
find the one whose first PC is closer than that of the next line in this
1868
/* If it's worth the effort, we could be using a binary search. */
1870
struct symtab_and_line
1871
find_pc_sect_line (CORE_ADDR pc, struct bfd_section *section, int notcurrent)
1874
struct linetable *l;
1877
struct linetable_entry *item;
1878
struct symtab_and_line val;
1879
struct blockvector *bv;
1880
struct minimal_symbol *msymbol;
1881
struct minimal_symbol *mfunsym;
1883
/* Info on best line seen so far, and where it starts, and its file. */
1885
struct linetable_entry *best = NULL;
1886
CORE_ADDR best_end = 0;
1887
struct symtab *best_symtab = 0;
1889
/* Store here the first line number
1890
of a file which contains the line at the smallest pc after PC.
1891
If we don't find a line whose range contains PC,
1892
we will use a line one less than this,
1893
with a range from the start of that file to the first line's pc. */
1894
struct linetable_entry *alt = NULL;
1895
struct symtab *alt_symtab = 0;
1897
/* Info on best line seen in this file. */
1899
struct linetable_entry *prev;
1901
/* If this pc is not from the current frame,
1902
it is the address of the end of a call instruction.
1903
Quite likely that is the start of the following statement.
1904
But what we want is the statement containing the instruction.
1905
Fudge the pc to make sure we get that. */
1907
init_sal (&val); /* initialize to zeroes */
1909
/* It's tempting to assume that, if we can't find debugging info for
1910
any function enclosing PC, that we shouldn't search for line
1911
number info, either. However, GAS can emit line number info for
1912
assembly files --- very helpful when debugging hand-written
1913
assembly code. In such a case, we'd have no debug info for the
1914
function, but we would have line info. */
1919
/* elz: added this because this function returned the wrong
1920
information if the pc belongs to a stub (import/export)
1921
to call a shlib function. This stub would be anywhere between
1922
two functions in the target, and the line info was erroneously
1923
taken to be the one of the line before the pc.
1925
/* RT: Further explanation:
1927
* We have stubs (trampolines) inserted between procedures.
1929
* Example: "shr1" exists in a shared library, and a "shr1" stub also
1930
* exists in the main image.
1932
* In the minimal symbol table, we have a bunch of symbols
1933
* sorted by start address. The stubs are marked as "trampoline",
1934
* the others appear as text. E.g.:
1936
* Minimal symbol table for main image
1937
* main: code for main (text symbol)
1938
* shr1: stub (trampoline symbol)
1939
* foo: code for foo (text symbol)
1941
* Minimal symbol table for "shr1" image:
1943
* shr1: code for shr1 (text symbol)
1946
* So the code below is trying to detect if we are in the stub
1947
* ("shr1" stub), and if so, find the real code ("shr1" trampoline),
1948
* and if found, do the symbolization from the real-code address
1949
* rather than the stub address.
1951
* Assumptions being made about the minimal symbol table:
1952
* 1. lookup_minimal_symbol_by_pc() will return a trampoline only
1953
* if we're really in the trampoline. If we're beyond it (say
1954
* we're in "foo" in the above example), it'll have a closer
1955
* symbol (the "foo" text symbol for example) and will not
1956
* return the trampoline.
1957
* 2. lookup_minimal_symbol_text() will find a real text symbol
1958
* corresponding to the trampoline, and whose address will
1959
* be different than the trampoline address. I put in a sanity
1960
* check for the address being the same, to avoid an
1961
* infinite recursion.
1963
msymbol = lookup_minimal_symbol_by_pc (pc);
1964
if (msymbol != NULL)
1965
if (MSYMBOL_TYPE (msymbol) == mst_solib_trampoline)
1967
mfunsym = lookup_minimal_symbol_text (SYMBOL_LINKAGE_NAME (msymbol),
1969
if (mfunsym == NULL)
1970
/* I eliminated this warning since it is coming out
1971
* in the following situation:
1972
* gdb shmain // test program with shared libraries
1973
* (gdb) break shr1 // function in shared lib
1974
* Warning: In stub for ...
1975
* In the above situation, the shared lib is not loaded yet,
1976
* so of course we can't find the real func/line info,
1977
* but the "break" still works, and the warning is annoying.
1978
* So I commented out the warning. RT */
1979
/* warning ("In stub for %s; unable to find real function/line info", SYMBOL_LINKAGE_NAME (msymbol)) */ ;
1981
else if (SYMBOL_VALUE (mfunsym) == SYMBOL_VALUE (msymbol))
1982
/* Avoid infinite recursion */
1983
/* See above comment about why warning is commented out */
1984
/* warning ("In stub for %s; unable to find real function/line info", SYMBOL_LINKAGE_NAME (msymbol)) */ ;
1987
return find_pc_line (SYMBOL_VALUE (mfunsym), 0);
1991
s = find_pc_sect_symtab (pc, section);
1994
/* if no symbol information, return previous pc */
2001
bv = BLOCKVECTOR (s);
2003
/* Look at all the symtabs that share this blockvector.
2004
They all have the same apriori range, that we found was right;
2005
but they have different line tables. */
2007
for (; s && BLOCKVECTOR (s) == bv; s = s->next)
2009
/* Find the best line in this symtab. */
2016
/* I think len can be zero if the symtab lacks line numbers
2017
(e.g. gcc -g1). (Either that or the LINETABLE is NULL;
2018
I'm not sure which, and maybe it depends on the symbol
2024
item = l->item; /* Get first line info */
2026
/* Is this file's first line closer than the first lines of other files?
2027
If so, record this file, and its first line, as best alternate. */
2028
if (item->pc > pc && (!alt || item->pc < alt->pc))
2034
for (i = 0; i < len; i++, item++)
2036
/* Leave prev pointing to the linetable entry for the last line
2037
that started at or before PC. */
2044
/* At this point, prev points at the line whose start addr is <= pc, and
2045
item points at the next line. If we ran off the end of the linetable
2046
(pc >= start of the last line), then prev == item. If pc < start of
2047
the first line, prev will not be set. */
2049
/* Is this file's best line closer than the best in the other files?
2050
If so, record this file, and its best line, as best so far. Don't
2051
save prev if it represents the end of a function (i.e. line number
2052
0) instead of a real line. */
2054
if (prev && prev->line && (!best || prev->pc > best->pc))
2059
/* Discard BEST_END if it's before the PC of the current BEST. */
2060
if (best_end <= best->pc)
2064
/* If another line (denoted by ITEM) is in the linetable and its
2065
PC is after BEST's PC, but before the current BEST_END, then
2066
use ITEM's PC as the new best_end. */
2067
if (best && i < len && item->pc > best->pc
2068
&& (best_end == 0 || best_end > item->pc))
2069
best_end = item->pc;
2075
{ /* If we didn't find any line # info, just
2081
val.symtab = alt_symtab;
2082
val.line = alt->line - 1;
2084
/* Don't return line 0, that means that we didn't find the line. */
2088
val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
2092
else if (best->line == 0)
2094
/* If our best fit is in a range of PC's for which no line
2095
number info is available (line number is zero) then we didn't
2096
find any valid line information. */
2101
val.symtab = best_symtab;
2102
val.line = best->line;
2104
if (best_end && (!alt || best_end < alt->pc))
2109
val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
2111
val.section = section;
2115
/* Backward compatibility (no section) */
2117
struct symtab_and_line
2118
find_pc_line (CORE_ADDR pc, int notcurrent)
2122
section = find_pc_overlay (pc);
2123
if (pc_in_unmapped_range (pc, section))
2124
pc = overlay_mapped_address (pc, section);
2125
return find_pc_sect_line (pc, section, notcurrent);
2128
/* Find line number LINE in any symtab whose name is the same as
2131
If found, return the symtab that contains the linetable in which it was
2132
found, set *INDEX to the index in the linetable of the best entry
2133
found, and set *EXACT_MATCH nonzero if the value returned is an
2136
If not found, return NULL. */
2139
find_line_symtab (struct symtab *symtab, int line, int *index, int *exact_match)
2143
/* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
2147
struct linetable *best_linetable;
2148
struct symtab *best_symtab;
2150
/* First try looking it up in the given symtab. */
2151
best_linetable = LINETABLE (symtab);
2152
best_symtab = symtab;
2153
best_index = find_line_common (best_linetable, line, &exact);
2154
if (best_index < 0 || !exact)
2156
/* Didn't find an exact match. So we better keep looking for
2157
another symtab with the same name. In the case of xcoff,
2158
multiple csects for one source file (produced by IBM's FORTRAN
2159
compiler) produce multiple symtabs (this is unavoidable
2160
assuming csects can be at arbitrary places in memory and that
2161
the GLOBAL_BLOCK of a symtab has a begin and end address). */
2163
/* BEST is the smallest linenumber > LINE so far seen,
2164
or 0 if none has been seen so far.
2165
BEST_INDEX and BEST_LINETABLE identify the item for it. */
2168
struct objfile *objfile;
2171
if (best_index >= 0)
2172
best = best_linetable->item[best_index].line;
2176
ALL_SYMTABS (objfile, s)
2178
struct linetable *l;
2181
if (strcmp (symtab->filename, s->filename) != 0)
2184
ind = find_line_common (l, line, &exact);
2194
if (best == 0 || l->item[ind].line < best)
2196
best = l->item[ind].line;
2209
*index = best_index;
2211
*exact_match = exact;
2216
/* Set the PC value for a given source file and line number and return true.
2217
Returns zero for invalid line number (and sets the PC to 0).
2218
The source file is specified with a struct symtab. */
2221
find_line_pc (struct symtab *symtab, int line, CORE_ADDR *pc)
2223
struct linetable *l;
2230
symtab = find_line_symtab (symtab, line, &ind, NULL);
2233
l = LINETABLE (symtab);
2234
*pc = l->item[ind].pc;
2241
/* Find the range of pc values in a line.
2242
Store the starting pc of the line into *STARTPTR
2243
and the ending pc (start of next line) into *ENDPTR.
2244
Returns 1 to indicate success.
2245
Returns 0 if could not find the specified line. */
2248
find_line_pc_range (struct symtab_and_line sal, CORE_ADDR *startptr,
2251
CORE_ADDR startaddr;
2252
struct symtab_and_line found_sal;
2255
if (startaddr == 0 && !find_line_pc (sal.symtab, sal.line, &startaddr))
2258
/* This whole function is based on address. For example, if line 10 has
2259
two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
2260
"info line *0x123" should say the line goes from 0x100 to 0x200
2261
and "info line *0x355" should say the line goes from 0x300 to 0x400.
2262
This also insures that we never give a range like "starts at 0x134
2263
and ends at 0x12c". */
2265
found_sal = find_pc_sect_line (startaddr, sal.section, 0);
2266
if (found_sal.line != sal.line)
2268
/* The specified line (sal) has zero bytes. */
2269
*startptr = found_sal.pc;
2270
*endptr = found_sal.pc;
2274
*startptr = found_sal.pc;
2275
*endptr = found_sal.end;
2280
/* Given a line table and a line number, return the index into the line
2281
table for the pc of the nearest line whose number is >= the specified one.
2282
Return -1 if none is found. The value is >= 0 if it is an index.
2284
Set *EXACT_MATCH nonzero if the value returned is an exact match. */
2287
find_line_common (struct linetable *l, int lineno,
2293
/* BEST is the smallest linenumber > LINENO so far seen,
2294
or 0 if none has been seen so far.
2295
BEST_INDEX identifies the item for it. */
2297
int best_index = -1;
2306
for (i = 0; i < len; i++)
2308
struct linetable_entry *item = &(l->item[i]);
2310
if (item->line == lineno)
2312
/* Return the first (lowest address) entry which matches. */
2317
if (item->line > lineno && (best == 0 || item->line < best))
2324
/* If we got here, we didn't get an exact match. */
2331
find_pc_line_pc_range (CORE_ADDR pc, CORE_ADDR *startptr, CORE_ADDR *endptr)
2333
struct symtab_and_line sal;
2334
sal = find_pc_line (pc, 0);
2337
return sal.symtab != 0;
2340
/* Given a function symbol SYM, find the symtab and line for the start
2342
If the argument FUNFIRSTLINE is nonzero, we want the first line
2343
of real code inside the function. */
2345
struct symtab_and_line
2346
find_function_start_sal (struct symbol *sym, int funfirstline)
2349
struct symtab_and_line sal;
2351
pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
2352
fixup_symbol_section (sym, NULL);
2354
{ /* skip "first line" of function (which is actually its prologue) */
2355
asection *section = SYMBOL_BFD_SECTION (sym);
2356
/* If function is in an unmapped overlay, use its unmapped LMA
2357
address, so that SKIP_PROLOGUE has something unique to work on */
2358
if (section_is_overlay (section) &&
2359
!section_is_mapped (section))
2360
pc = overlay_unmapped_address (pc, section);
2362
pc += FUNCTION_START_OFFSET;
2363
pc = SKIP_PROLOGUE (pc);
2365
/* For overlays, map pc back into its mapped VMA range */
2366
pc = overlay_mapped_address (pc, section);
2368
sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
2370
/* Check if SKIP_PROLOGUE left us in mid-line, and the next
2371
line is still part of the same function. */
2373
&& BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= sal.end
2374
&& sal.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym)))
2376
/* First pc of next line */
2378
/* Recalculate the line number (might not be N+1). */
2379
sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
2386
/* If P is of the form "operator[ \t]+..." where `...' is
2387
some legitimate operator text, return a pointer to the
2388
beginning of the substring of the operator text.
2389
Otherwise, return "". */
2391
operator_chars (char *p, char **end)
2394
if (strncmp (p, "operator", 8))
2398
/* Don't get faked out by `operator' being part of a longer
2400
if (isalpha (*p) || *p == '_' || *p == '$' || *p == '\0')
2403
/* Allow some whitespace between `operator' and the operator symbol. */
2404
while (*p == ' ' || *p == '\t')
2407
/* Recognize 'operator TYPENAME'. */
2409
if (isalpha (*p) || *p == '_' || *p == '$')
2412
while (isalnum (*q) || *q == '_' || *q == '$')
2421
case '\\': /* regexp quoting */
2424
if (p[2] == '=') /* 'operator\*=' */
2426
else /* 'operator\*' */
2430
else if (p[1] == '[')
2433
error ("mismatched quoting on brackets, try 'operator\\[\\]'");
2434
else if (p[2] == '\\' && p[3] == ']')
2436
*end = p + 4; /* 'operator\[\]' */
2440
error ("nothing is allowed between '[' and ']'");
2444
/* Gratuitous qoute: skip it and move on. */
2466
if (p[0] == '-' && p[1] == '>')
2468
/* Struct pointer member operator 'operator->'. */
2471
*end = p + 3; /* 'operator->*' */
2474
else if (p[2] == '\\')
2476
*end = p + 4; /* Hopefully 'operator->\*' */
2481
*end = p + 2; /* 'operator->' */
2485
if (p[1] == '=' || p[1] == p[0])
2496
error ("`operator ()' must be specified without whitespace in `()'");
2501
error ("`operator ?:' must be specified without whitespace in `?:'");
2506
error ("`operator []' must be specified without whitespace in `[]'");
2510
error ("`operator %s' not supported", p);
2519
/* If FILE is not already in the table of files, return zero;
2520
otherwise return non-zero. Optionally add FILE to the table if ADD
2521
is non-zero. If *FIRST is non-zero, forget the old table
2524
filename_seen (const char *file, int add, int *first)
2526
/* Table of files seen so far. */
2527
static const char **tab = NULL;
2528
/* Allocated size of tab in elements.
2529
Start with one 256-byte block (when using GNU malloc.c).
2530
24 is the malloc overhead when range checking is in effect. */
2531
static int tab_alloc_size = (256 - 24) / sizeof (char *);
2532
/* Current size of tab in elements. */
2533
static int tab_cur_size;
2539
tab = (const char **) xmalloc (tab_alloc_size * sizeof (*tab));
2543
/* Is FILE in tab? */
2544
for (p = tab; p < tab + tab_cur_size; p++)
2545
if (strcmp (*p, file) == 0)
2548
/* No; maybe add it to tab. */
2551
if (tab_cur_size == tab_alloc_size)
2553
tab_alloc_size *= 2;
2554
tab = (const char **) xrealloc ((char *) tab,
2555
tab_alloc_size * sizeof (*tab));
2557
tab[tab_cur_size++] = file;
2563
/* Slave routine for sources_info. Force line breaks at ,'s.
2564
NAME is the name to print and *FIRST is nonzero if this is the first
2565
name printed. Set *FIRST to zero. */
2567
output_source_filename (char *name, int *first)
2569
/* Since a single source file can result in several partial symbol
2570
tables, we need to avoid printing it more than once. Note: if
2571
some of the psymtabs are read in and some are not, it gets
2572
printed both under "Source files for which symbols have been
2573
read" and "Source files for which symbols will be read in on
2574
demand". I consider this a reasonable way to deal with the
2575
situation. I'm not sure whether this can also happen for
2576
symtabs; it doesn't hurt to check. */
2578
/* Was NAME already seen? */
2579
if (filename_seen (name, 1, first))
2581
/* Yes; don't print it again. */
2584
/* No; print it and reset *FIRST. */
2591
printf_filtered (", ");
2595
fputs_filtered (name, gdb_stdout);
2599
sources_info (char *ignore, int from_tty)
2602
struct partial_symtab *ps;
2603
struct objfile *objfile;
2606
if (!have_full_symbols () && !have_partial_symbols ())
2608
error ("No symbol table is loaded. Use the \"file\" command.");
2611
printf_filtered ("Source files for which symbols have been read in:\n\n");
2614
ALL_SYMTABS (objfile, s)
2616
output_source_filename (s->filename, &first);
2618
printf_filtered ("\n\n");
2620
printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2623
ALL_PSYMTABS (objfile, ps)
2627
output_source_filename (ps->filename, &first);
2630
printf_filtered ("\n");
2634
file_matches (char *file, char *files[], int nfiles)
2638
if (file != NULL && nfiles != 0)
2640
for (i = 0; i < nfiles; i++)
2642
if (strcmp (files[i], lbasename (file)) == 0)
2646
else if (nfiles == 0)
2651
/* Free any memory associated with a search. */
2653
free_search_symbols (struct symbol_search *symbols)
2655
struct symbol_search *p;
2656
struct symbol_search *next;
2658
for (p = symbols; p != NULL; p = next)
2666
do_free_search_symbols_cleanup (void *symbols)
2668
free_search_symbols (symbols);
2672
make_cleanup_free_search_symbols (struct symbol_search *symbols)
2674
return make_cleanup (do_free_search_symbols_cleanup, symbols);
2677
/* Helper function for sort_search_symbols and qsort. Can only
2678
sort symbols, not minimal symbols. */
2680
compare_search_syms (const void *sa, const void *sb)
2682
struct symbol_search **sym_a = (struct symbol_search **) sa;
2683
struct symbol_search **sym_b = (struct symbol_search **) sb;
2685
return strcmp (SYMBOL_PRINT_NAME ((*sym_a)->symbol),
2686
SYMBOL_PRINT_NAME ((*sym_b)->symbol));
2689
/* Sort the ``nfound'' symbols in the list after prevtail. Leave
2690
prevtail where it is, but update its next pointer to point to
2691
the first of the sorted symbols. */
2692
static struct symbol_search *
2693
sort_search_symbols (struct symbol_search *prevtail, int nfound)
2695
struct symbol_search **symbols, *symp, *old_next;
2698
symbols = (struct symbol_search **) xmalloc (sizeof (struct symbol_search *)
2700
symp = prevtail->next;
2701
for (i = 0; i < nfound; i++)
2706
/* Generally NULL. */
2709
qsort (symbols, nfound, sizeof (struct symbol_search *),
2710
compare_search_syms);
2713
for (i = 0; i < nfound; i++)
2715
symp->next = symbols[i];
2718
symp->next = old_next;
2724
/* Search the symbol table for matches to the regular expression REGEXP,
2725
returning the results in *MATCHES.
2727
Only symbols of KIND are searched:
2728
FUNCTIONS_DOMAIN - search all functions
2729
TYPES_DOMAIN - search all type names
2730
METHODS_DOMAIN - search all methods NOT IMPLEMENTED
2731
VARIABLES_DOMAIN - search all symbols, excluding functions, type names,
2732
and constants (enums)
2734
free_search_symbols should be called when *MATCHES is no longer needed.
2736
The results are sorted locally; each symtab's global and static blocks are
2737
separately alphabetized.
2740
search_symbols (char *regexp, domain_enum kind, int nfiles, char *files[],
2741
struct symbol_search **matches)
2744
struct partial_symtab *ps;
2745
struct blockvector *bv;
2746
struct blockvector *prev_bv = 0;
2749
struct dict_iterator iter;
2751
struct partial_symbol **psym;
2752
struct objfile *objfile;
2753
struct minimal_symbol *msymbol;
2756
static enum minimal_symbol_type types[]
2758
{mst_data, mst_text, mst_abs, mst_unknown};
2759
static enum minimal_symbol_type types2[]
2761
{mst_bss, mst_file_text, mst_abs, mst_unknown};
2762
static enum minimal_symbol_type types3[]
2764
{mst_file_data, mst_solib_trampoline, mst_abs, mst_unknown};
2765
static enum minimal_symbol_type types4[]
2767
{mst_file_bss, mst_text, mst_abs, mst_unknown};
2768
enum minimal_symbol_type ourtype;
2769
enum minimal_symbol_type ourtype2;
2770
enum minimal_symbol_type ourtype3;
2771
enum minimal_symbol_type ourtype4;
2772
struct symbol_search *sr;
2773
struct symbol_search *psr;
2774
struct symbol_search *tail;
2775
struct cleanup *old_chain = NULL;
2777
if (kind < VARIABLES_DOMAIN)
2778
error ("must search on specific domain");
2780
ourtype = types[(int) (kind - VARIABLES_DOMAIN)];
2781
ourtype2 = types2[(int) (kind - VARIABLES_DOMAIN)];
2782
ourtype3 = types3[(int) (kind - VARIABLES_DOMAIN)];
2783
ourtype4 = types4[(int) (kind - VARIABLES_DOMAIN)];
2785
sr = *matches = NULL;
2790
/* Make sure spacing is right for C++ operators.
2791
This is just a courtesy to make the matching less sensitive
2792
to how many spaces the user leaves between 'operator'
2793
and <TYPENAME> or <OPERATOR>. */
2795
char *opname = operator_chars (regexp, &opend);
2798
int fix = -1; /* -1 means ok; otherwise number of spaces needed. */
2799
if (isalpha (*opname) || *opname == '_' || *opname == '$')
2801
/* There should 1 space between 'operator' and 'TYPENAME'. */
2802
if (opname[-1] != ' ' || opname[-2] == ' ')
2807
/* There should 0 spaces between 'operator' and 'OPERATOR'. */
2808
if (opname[-1] == ' ')
2811
/* If wrong number of spaces, fix it. */
2814
char *tmp = (char *) alloca (8 + fix + strlen (opname) + 1);
2815
sprintf (tmp, "operator%.*s%s", fix, " ", opname);
2820
if (0 != (val = re_comp (regexp)))
2821
error ("Invalid regexp (%s): %s", val, regexp);
2824
/* Search through the partial symtabs *first* for all symbols
2825
matching the regexp. That way we don't have to reproduce all of
2826
the machinery below. */
2828
ALL_PSYMTABS (objfile, ps)
2830
struct partial_symbol **bound, **gbound, **sbound;
2836
gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms;
2837
sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms;
2840
/* Go through all of the symbols stored in a partial
2841
symtab in one loop. */
2842
psym = objfile->global_psymbols.list + ps->globals_offset;
2847
if (bound == gbound && ps->n_static_syms != 0)
2849
psym = objfile->static_psymbols.list + ps->statics_offset;
2860
/* If it would match (logic taken from loop below)
2861
load the file and go on to the next one */
2862
if (file_matches (ps->filename, files, nfiles)
2864
|| re_exec (SYMBOL_NATURAL_NAME (*psym)) != 0)
2865
&& ((kind == VARIABLES_DOMAIN && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
2866
&& SYMBOL_CLASS (*psym) != LOC_BLOCK)
2867
|| (kind == FUNCTIONS_DOMAIN && SYMBOL_CLASS (*psym) == LOC_BLOCK)
2868
|| (kind == TYPES_DOMAIN && SYMBOL_CLASS (*psym) == LOC_TYPEDEF)
2869
|| (kind == METHODS_DOMAIN && SYMBOL_CLASS (*psym) == LOC_BLOCK))))
2871
PSYMTAB_TO_SYMTAB (ps);
2879
/* Here, we search through the minimal symbol tables for functions
2880
and variables that match, and force their symbols to be read.
2881
This is in particular necessary for demangled variable names,
2882
which are no longer put into the partial symbol tables.
2883
The symbol will then be found during the scan of symtabs below.
2885
For functions, find_pc_symtab should succeed if we have debug info
2886
for the function, for variables we have to call lookup_symbol
2887
to determine if the variable has debug info.
2888
If the lookup fails, set found_misc so that we will rescan to print
2889
any matching symbols without debug info.
2892
if (nfiles == 0 && (kind == VARIABLES_DOMAIN || kind == FUNCTIONS_DOMAIN))
2894
ALL_MSYMBOLS (objfile, msymbol)
2896
if (MSYMBOL_TYPE (msymbol) == ourtype ||
2897
MSYMBOL_TYPE (msymbol) == ourtype2 ||
2898
MSYMBOL_TYPE (msymbol) == ourtype3 ||
2899
MSYMBOL_TYPE (msymbol) == ourtype4)
2902
|| re_exec (SYMBOL_NATURAL_NAME (msymbol)) != 0)
2904
if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)))
2906
/* FIXME: carlton/2003-02-04: Given that the
2907
semantics of lookup_symbol keeps on changing
2908
slightly, it would be a nice idea if we had a
2909
function lookup_symbol_minsym that found the
2910
symbol associated to a given minimal symbol (if
2912
if (kind == FUNCTIONS_DOMAIN
2913
|| lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol),
2914
(struct block *) NULL,
2916
0, (struct symtab **) NULL) == NULL)
2924
ALL_SYMTABS (objfile, s)
2926
bv = BLOCKVECTOR (s);
2927
/* Often many files share a blockvector.
2928
Scan each blockvector only once so that
2929
we don't get every symbol many times.
2930
It happens that the first symtab in the list
2931
for any given blockvector is the main file. */
2933
for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
2935
struct symbol_search *prevtail = tail;
2937
b = BLOCKVECTOR_BLOCK (bv, i);
2938
ALL_BLOCK_SYMBOLS (b, iter, sym)
2941
if (file_matches (s->filename, files, nfiles)
2943
|| re_exec (SYMBOL_NATURAL_NAME (sym)) != 0)
2944
&& ((kind == VARIABLES_DOMAIN && SYMBOL_CLASS (sym) != LOC_TYPEDEF
2945
&& SYMBOL_CLASS (sym) != LOC_BLOCK
2946
&& SYMBOL_CLASS (sym) != LOC_CONST)
2947
|| (kind == FUNCTIONS_DOMAIN && SYMBOL_CLASS (sym) == LOC_BLOCK)
2948
|| (kind == TYPES_DOMAIN && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2949
|| (kind == METHODS_DOMAIN && SYMBOL_CLASS (sym) == LOC_BLOCK))))
2952
psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search));
2956
psr->msymbol = NULL;
2968
if (prevtail == NULL)
2970
struct symbol_search dummy;
2973
tail = sort_search_symbols (&dummy, nfound);
2976
old_chain = make_cleanup_free_search_symbols (sr);
2979
tail = sort_search_symbols (prevtail, nfound);
2985
/* If there are no eyes, avoid all contact. I mean, if there are
2986
no debug symbols, then print directly from the msymbol_vector. */
2988
if (found_misc || kind != FUNCTIONS_DOMAIN)
2990
ALL_MSYMBOLS (objfile, msymbol)
2992
if (MSYMBOL_TYPE (msymbol) == ourtype ||
2993
MSYMBOL_TYPE (msymbol) == ourtype2 ||
2994
MSYMBOL_TYPE (msymbol) == ourtype3 ||
2995
MSYMBOL_TYPE (msymbol) == ourtype4)
2998
|| re_exec (SYMBOL_NATURAL_NAME (msymbol)) != 0)
3000
/* Functions: Look up by address. */
3001
if (kind != FUNCTIONS_DOMAIN ||
3002
(0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol))))
3004
/* Variables/Absolutes: Look up by name */
3005
if (lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol),
3006
(struct block *) NULL, VAR_DOMAIN,
3007
0, (struct symtab **) NULL) == NULL)
3010
psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search));
3012
psr->msymbol = msymbol;
3019
old_chain = make_cleanup_free_search_symbols (sr);
3033
discard_cleanups (old_chain);
3036
/* Helper function for symtab_symbol_info, this function uses
3037
the data returned from search_symbols() to print information
3038
regarding the match to gdb_stdout.
3041
print_symbol_info (domain_enum kind, struct symtab *s, struct symbol *sym,
3042
int block, char *last)
3044
if (last == NULL || strcmp (last, s->filename) != 0)
3046
fputs_filtered ("\nFile ", gdb_stdout);
3047
fputs_filtered (s->filename, gdb_stdout);
3048
fputs_filtered (":\n", gdb_stdout);
3051
if (kind != TYPES_DOMAIN && block == STATIC_BLOCK)
3052
printf_filtered ("static ");
3054
/* Typedef that is not a C++ class */
3055
if (kind == TYPES_DOMAIN
3056
&& SYMBOL_DOMAIN (sym) != STRUCT_DOMAIN)
3057
typedef_print (SYMBOL_TYPE (sym), sym, gdb_stdout);
3058
/* variable, func, or typedef-that-is-c++-class */
3059
else if (kind < TYPES_DOMAIN ||
3060
(kind == TYPES_DOMAIN &&
3061
SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN))
3063
type_print (SYMBOL_TYPE (sym),
3064
(SYMBOL_CLASS (sym) == LOC_TYPEDEF
3065
? "" : SYMBOL_PRINT_NAME (sym)),
3068
printf_filtered (";\n");
3072
/* This help function for symtab_symbol_info() prints information
3073
for non-debugging symbols to gdb_stdout.
3076
print_msymbol_info (struct minimal_symbol *msymbol)
3080
if (TARGET_ADDR_BIT <= 32)
3081
tmp = local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol)
3082
& (CORE_ADDR) 0xffffffff,
3085
tmp = local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol),
3087
printf_filtered ("%s %s\n",
3088
tmp, SYMBOL_PRINT_NAME (msymbol));
3091
/* This is the guts of the commands "info functions", "info types", and
3092
"info variables". It calls search_symbols to find all matches and then
3093
print_[m]symbol_info to print out some useful information about the
3097
symtab_symbol_info (char *regexp, domain_enum kind, int from_tty)
3099
static char *classnames[]
3101
{"variable", "function", "type", "method"};
3102
struct symbol_search *symbols;
3103
struct symbol_search *p;
3104
struct cleanup *old_chain;
3105
char *last_filename = NULL;
3108
/* must make sure that if we're interrupted, symbols gets freed */
3109
search_symbols (regexp, kind, 0, (char **) NULL, &symbols);
3110
old_chain = make_cleanup_free_search_symbols (symbols);
3112
printf_filtered (regexp
3113
? "All %ss matching regular expression \"%s\":\n"
3114
: "All defined %ss:\n",
3115
classnames[(int) (kind - VARIABLES_DOMAIN)], regexp);
3117
for (p = symbols; p != NULL; p = p->next)
3121
if (p->msymbol != NULL)
3125
printf_filtered ("\nNon-debugging symbols:\n");
3128
print_msymbol_info (p->msymbol);
3132
print_symbol_info (kind,
3137
last_filename = p->symtab->filename;
3141
do_cleanups (old_chain);
3145
variables_info (char *regexp, int from_tty)
3147
symtab_symbol_info (regexp, VARIABLES_DOMAIN, from_tty);
3151
functions_info (char *regexp, int from_tty)
3153
symtab_symbol_info (regexp, FUNCTIONS_DOMAIN, from_tty);
3158
types_info (char *regexp, int from_tty)
3160
symtab_symbol_info (regexp, TYPES_DOMAIN, from_tty);
3163
/* Breakpoint all functions matching regular expression. */
3166
rbreak_command_wrapper (char *regexp, int from_tty)
3168
rbreak_command (regexp, from_tty);
3172
rbreak_command (char *regexp, int from_tty)
3174
struct symbol_search *ss;
3175
struct symbol_search *p;
3176
struct cleanup *old_chain;
3178
search_symbols (regexp, FUNCTIONS_DOMAIN, 0, (char **) NULL, &ss);
3179
old_chain = make_cleanup_free_search_symbols (ss);
3181
for (p = ss; p != NULL; p = p->next)
3183
if (p->msymbol == NULL)
3185
char *string = alloca (strlen (p->symtab->filename)
3186
+ strlen (SYMBOL_LINKAGE_NAME (p->symbol))
3188
strcpy (string, p->symtab->filename);
3189
strcat (string, ":'");
3190
strcat (string, SYMBOL_LINKAGE_NAME (p->symbol));
3191
strcat (string, "'");
3192
break_command (string, from_tty);
3193
print_symbol_info (FUNCTIONS_DOMAIN,
3197
p->symtab->filename);
3201
break_command (SYMBOL_LINKAGE_NAME (p->msymbol), from_tty);
3202
printf_filtered ("<function, no debug info> %s;\n",
3203
SYMBOL_PRINT_NAME (p->msymbol));
3207
do_cleanups (old_chain);
3211
/* Helper routine for make_symbol_completion_list. */
3213
static int return_val_size;
3214
static int return_val_index;
3215
static char **return_val;
3217
#define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
3218
completion_list_add_name \
3219
(SYMBOL_NATURAL_NAME (symbol), (sym_text), (len), (text), (word))
3221
/* Test to see if the symbol specified by SYMNAME (which is already
3222
demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3223
characters. If so, add it to the current completion list. */
3226
completion_list_add_name (char *symname, char *sym_text, int sym_text_len,
3227
char *text, char *word)
3232
/* clip symbols that cannot match */
3234
if (strncmp (symname, sym_text, sym_text_len) != 0)
3239
/* We have a match for a completion, so add SYMNAME to the current list
3240
of matches. Note that the name is moved to freshly malloc'd space. */
3244
if (word == sym_text)
3246
new = xmalloc (strlen (symname) + 5);
3247
strcpy (new, symname);
3249
else if (word > sym_text)
3251
/* Return some portion of symname. */
3252
new = xmalloc (strlen (symname) + 5);
3253
strcpy (new, symname + (word - sym_text));
3257
/* Return some of SYM_TEXT plus symname. */
3258
new = xmalloc (strlen (symname) + (sym_text - word) + 5);
3259
strncpy (new, word, sym_text - word);
3260
new[sym_text - word] = '\0';
3261
strcat (new, symname);
3264
if (return_val_index + 3 > return_val_size)
3266
newsize = (return_val_size *= 2) * sizeof (char *);
3267
return_val = (char **) xrealloc ((char *) return_val, newsize);
3269
return_val[return_val_index++] = new;
3270
return_val[return_val_index] = NULL;
3274
/* ObjC: In case we are completing on a selector, look as the msymbol
3275
again and feed all the selectors into the mill. */
3278
completion_list_objc_symbol (struct minimal_symbol *msymbol, char *sym_text,
3279
int sym_text_len, char *text, char *word)
3281
static char *tmp = NULL;
3282
static unsigned int tmplen = 0;
3284
char *method, *category, *selector;
3287
method = SYMBOL_NATURAL_NAME (msymbol);
3289
/* Is it a method? */
3290
if ((method[0] != '-') && (method[0] != '+'))
3293
if (sym_text[0] == '[')
3294
/* Complete on shortened method method. */
3295
completion_list_add_name (method + 1, sym_text, sym_text_len, text, word);
3297
while ((strlen (method) + 1) >= tmplen)
3303
tmp = xrealloc (tmp, tmplen);
3305
selector = strchr (method, ' ');
3306
if (selector != NULL)
3309
category = strchr (method, '(');
3311
if ((category != NULL) && (selector != NULL))
3313
memcpy (tmp, method, (category - method));
3314
tmp[category - method] = ' ';
3315
memcpy (tmp + (category - method) + 1, selector, strlen (selector) + 1);
3316
completion_list_add_name (tmp, sym_text, sym_text_len, text, word);
3317
if (sym_text[0] == '[')
3318
completion_list_add_name (tmp + 1, sym_text, sym_text_len, text, word);
3321
if (selector != NULL)
3323
/* Complete on selector only. */
3324
strcpy (tmp, selector);
3325
tmp2 = strchr (tmp, ']');
3329
completion_list_add_name (tmp, sym_text, sym_text_len, text, word);
3333
/* Break the non-quoted text based on the characters which are in
3334
symbols. FIXME: This should probably be language-specific. */
3337
language_search_unquoted_string (char *text, char *p)
3339
for (; p > text; --p)
3341
if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
3345
if ((current_language->la_language == language_objc))
3347
if (p[-1] == ':') /* might be part of a method name */
3349
else if (p[-1] == '[' && (p[-2] == '-' || p[-2] == '+'))
3350
p -= 2; /* beginning of a method name */
3351
else if (p[-1] == ' ' || p[-1] == '(' || p[-1] == ')')
3352
{ /* might be part of a method name */
3355
/* Seeing a ' ' or a '(' is not conclusive evidence
3356
that we are in the middle of a method name. However,
3357
finding "-[" or "+[" should be pretty un-ambiguous.
3358
Unfortunately we have to find it now to decide. */
3361
if (isalnum (t[-1]) || t[-1] == '_' ||
3362
t[-1] == ' ' || t[-1] == ':' ||
3363
t[-1] == '(' || t[-1] == ')')
3368
if (t[-1] == '[' && (t[-2] == '-' || t[-2] == '+'))
3369
p = t - 2; /* method name detected */
3370
/* else we leave with p unchanged */
3380
/* Return a NULL terminated array of all symbols (regardless of class)
3381
which begin by matching TEXT. If the answer is no symbols, then
3382
the return value is an array which contains only a NULL pointer.
3384
Problem: All of the symbols have to be copied because readline frees them.
3385
I'm not going to worry about this; hopefully there won't be that many. */
3388
make_symbol_completion_list (char *text, char *word)
3392
struct partial_symtab *ps;
3393
struct minimal_symbol *msymbol;
3394
struct objfile *objfile;
3395
struct block *b, *surrounding_static_block = 0;
3396
struct dict_iterator iter;
3398
struct partial_symbol **psym;
3399
/* The symbol we are completing on. Points in same buffer as text. */
3401
/* Length of sym_text. */
3404
/* Now look for the symbol we are supposed to complete on.
3405
FIXME: This should be language-specific. */
3409
char *quote_pos = NULL;
3411
/* First see if this is a quoted string. */
3413
for (p = text; *p != '\0'; ++p)
3415
if (quote_found != '\0')
3417
if (*p == quote_found)
3418
/* Found close quote. */
3420
else if (*p == '\\' && p[1] == quote_found)
3421
/* A backslash followed by the quote character
3422
doesn't end the string. */
3425
else if (*p == '\'' || *p == '"')
3431
if (quote_found == '\'')
3432
/* A string within single quotes can be a symbol, so complete on it. */
3433
sym_text = quote_pos + 1;
3434
else if (quote_found == '"')
3435
/* A double-quoted string is never a symbol, nor does it make sense
3436
to complete it any other way. */
3438
return_val = (char **) xmalloc (sizeof (char *));
3439
return_val[0] = NULL;
3444
/* It is not a quoted string. Break it based on the characters
3445
which are in symbols. */
3448
if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
3457
sym_text_len = strlen (sym_text);
3459
return_val_size = 100;
3460
return_val_index = 0;
3461
return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
3462
return_val[0] = NULL;
3464
/* Look through the partial symtabs for all symbols which begin
3465
by matching SYM_TEXT. Add each one that you find to the list. */
3467
ALL_PSYMTABS (objfile, ps)
3469
/* If the psymtab's been read in we'll get it when we search
3470
through the blockvector. */
3474
for (psym = objfile->global_psymbols.list + ps->globals_offset;
3475
psym < (objfile->global_psymbols.list + ps->globals_offset
3476
+ ps->n_global_syms);
3479
/* If interrupted, then quit. */
3481
COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
3484
for (psym = objfile->static_psymbols.list + ps->statics_offset;
3485
psym < (objfile->static_psymbols.list + ps->statics_offset
3486
+ ps->n_static_syms);
3490
COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
3494
/* At this point scan through the misc symbol vectors and add each
3495
symbol you find to the list. Eventually we want to ignore
3496
anything that isn't a text symbol (everything else will be
3497
handled by the psymtab code above). */
3499
ALL_MSYMBOLS (objfile, msymbol)
3502
COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, word);
3504
completion_list_objc_symbol (msymbol, sym_text, sym_text_len, text, word);
3507
/* Search upwards from currently selected frame (so that we can
3508
complete on local vars. */
3510
for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
3512
if (!BLOCK_SUPERBLOCK (b))
3514
surrounding_static_block = b; /* For elmin of dups */
3517
/* Also catch fields of types defined in this places which match our
3518
text string. Only complete on types visible from current context. */
3520
ALL_BLOCK_SYMBOLS (b, iter, sym)
3523
COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3524
if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
3526
struct type *t = SYMBOL_TYPE (sym);
3527
enum type_code c = TYPE_CODE (t);
3529
if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
3531
for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
3533
if (TYPE_FIELD_NAME (t, j))
3535
completion_list_add_name (TYPE_FIELD_NAME (t, j),
3536
sym_text, sym_text_len, text, word);
3544
/* Go through the symtabs and check the externs and statics for
3545
symbols which match. */
3547
ALL_SYMTABS (objfile, s)
3550
b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
3551
ALL_BLOCK_SYMBOLS (b, iter, sym)
3553
COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3557
ALL_SYMTABS (objfile, s)
3560
b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
3561
/* Don't do this block twice. */
3562
if (b == surrounding_static_block)
3564
ALL_BLOCK_SYMBOLS (b, iter, sym)
3566
COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3570
return (return_val);
3573
/* Like make_symbol_completion_list, but returns a list of symbols
3574
defined in a source file FILE. */
3577
make_file_symbol_completion_list (char *text, char *word, char *srcfile)
3582
struct dict_iterator iter;
3583
/* The symbol we are completing on. Points in same buffer as text. */
3585
/* Length of sym_text. */
3588
/* Now look for the symbol we are supposed to complete on.
3589
FIXME: This should be language-specific. */
3593
char *quote_pos = NULL;
3595
/* First see if this is a quoted string. */
3597
for (p = text; *p != '\0'; ++p)
3599
if (quote_found != '\0')
3601
if (*p == quote_found)
3602
/* Found close quote. */
3604
else if (*p == '\\' && p[1] == quote_found)
3605
/* A backslash followed by the quote character
3606
doesn't end the string. */
3609
else if (*p == '\'' || *p == '"')
3615
if (quote_found == '\'')
3616
/* A string within single quotes can be a symbol, so complete on it. */
3617
sym_text = quote_pos + 1;
3618
else if (quote_found == '"')
3619
/* A double-quoted string is never a symbol, nor does it make sense
3620
to complete it any other way. */
3622
return_val = (char **) xmalloc (sizeof (char *));
3623
return_val[0] = NULL;
3628
/* Not a quoted string. */
3629
sym_text = language_search_unquoted_string (text, p);
3633
sym_text_len = strlen (sym_text);
3635
return_val_size = 10;
3636
return_val_index = 0;
3637
return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
3638
return_val[0] = NULL;
3640
/* Find the symtab for SRCFILE (this loads it if it was not yet read
3642
s = lookup_symtab (srcfile);
3645
/* Maybe they typed the file with leading directories, while the
3646
symbol tables record only its basename. */
3647
const char *tail = lbasename (srcfile);
3650
s = lookup_symtab (tail);
3653
/* If we have no symtab for that file, return an empty list. */
3655
return (return_val);
3657
/* Go through this symtab and check the externs and statics for
3658
symbols which match. */
3660
b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
3661
ALL_BLOCK_SYMBOLS (b, iter, sym)
3663
COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3666
b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
3667
ALL_BLOCK_SYMBOLS (b, iter, sym)
3669
COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3672
return (return_val);
3675
/* A helper function for make_source_files_completion_list. It adds
3676
another file name to a list of possible completions, growing the
3677
list as necessary. */
3680
add_filename_to_list (const char *fname, char *text, char *word,
3681
char ***list, int *list_used, int *list_alloced)
3684
size_t fnlen = strlen (fname);
3686
if (*list_used + 1 >= *list_alloced)
3689
*list = (char **) xrealloc ((char *) *list,
3690
*list_alloced * sizeof (char *));
3695
/* Return exactly fname. */
3696
new = xmalloc (fnlen + 5);
3697
strcpy (new, fname);
3699
else if (word > text)
3701
/* Return some portion of fname. */
3702
new = xmalloc (fnlen + 5);
3703
strcpy (new, fname + (word - text));
3707
/* Return some of TEXT plus fname. */
3708
new = xmalloc (fnlen + (text - word) + 5);
3709
strncpy (new, word, text - word);
3710
new[text - word] = '\0';
3711
strcat (new, fname);
3713
(*list)[*list_used] = new;
3714
(*list)[++*list_used] = NULL;
3718
not_interesting_fname (const char *fname)
3720
static const char *illegal_aliens[] = {
3721
"_globals_", /* inserted by coff_symtab_read */
3726
for (i = 0; illegal_aliens[i]; i++)
3728
if (strcmp (fname, illegal_aliens[i]) == 0)
3734
/* Return a NULL terminated array of all source files whose names
3735
begin with matching TEXT. The file names are looked up in the
3736
symbol tables of this program. If the answer is no matchess, then
3737
the return value is an array which contains only a NULL pointer. */
3740
make_source_files_completion_list (char *text, char *word)
3743
struct partial_symtab *ps;
3744
struct objfile *objfile;
3746
int list_alloced = 1;
3748
size_t text_len = strlen (text);
3749
char **list = (char **) xmalloc (list_alloced * sizeof (char *));
3750
const char *base_name;
3754
if (!have_full_symbols () && !have_partial_symbols ())
3757
ALL_SYMTABS (objfile, s)
3759
if (not_interesting_fname (s->filename))
3761
if (!filename_seen (s->filename, 1, &first)
3762
#if HAVE_DOS_BASED_FILE_SYSTEM
3763
&& strncasecmp (s->filename, text, text_len) == 0
3765
&& strncmp (s->filename, text, text_len) == 0
3769
/* This file matches for a completion; add it to the current
3771
add_filename_to_list (s->filename, text, word,
3772
&list, &list_used, &list_alloced);
3776
/* NOTE: We allow the user to type a base name when the
3777
debug info records leading directories, but not the other
3778
way around. This is what subroutines of breakpoint
3779
command do when they parse file names. */
3780
base_name = lbasename (s->filename);
3781
if (base_name != s->filename
3782
&& !filename_seen (base_name, 1, &first)
3783
#if HAVE_DOS_BASED_FILE_SYSTEM
3784
&& strncasecmp (base_name, text, text_len) == 0
3786
&& strncmp (base_name, text, text_len) == 0
3789
add_filename_to_list (base_name, text, word,
3790
&list, &list_used, &list_alloced);
3794
ALL_PSYMTABS (objfile, ps)
3796
if (not_interesting_fname (ps->filename))
3800
if (!filename_seen (ps->filename, 1, &first)
3801
#if HAVE_DOS_BASED_FILE_SYSTEM
3802
&& strncasecmp (ps->filename, text, text_len) == 0
3804
&& strncmp (ps->filename, text, text_len) == 0
3808
/* This file matches for a completion; add it to the
3809
current list of matches. */
3810
add_filename_to_list (ps->filename, text, word,
3811
&list, &list_used, &list_alloced);
3816
base_name = lbasename (ps->filename);
3817
if (base_name != ps->filename
3818
&& !filename_seen (base_name, 1, &first)
3819
#if HAVE_DOS_BASED_FILE_SYSTEM
3820
&& strncasecmp (base_name, text, text_len) == 0
3822
&& strncmp (base_name, text, text_len) == 0
3825
add_filename_to_list (base_name, text, word,
3826
&list, &list_used, &list_alloced);
3834
/* Determine if PC is in the prologue of a function. The prologue is the area
3835
between the first instruction of a function, and the first executable line.
3836
Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3838
If non-zero, func_start is where we think the prologue starts, possibly
3839
by previous examination of symbol table information.
3843
in_prologue (CORE_ADDR pc, CORE_ADDR func_start)
3845
struct symtab_and_line sal;
3846
CORE_ADDR func_addr, func_end;
3848
/* We have several sources of information we can consult to figure
3850
- Compilers usually emit line number info that marks the prologue
3851
as its own "source line". So the ending address of that "line"
3852
is the end of the prologue. If available, this is the most
3854
- The minimal symbols and partial symbols, which can usually tell
3855
us the starting and ending addresses of a function.
3856
- If we know the function's start address, we can call the
3857
architecture-defined SKIP_PROLOGUE function to analyze the
3858
instruction stream and guess where the prologue ends.
3859
- Our `func_start' argument; if non-zero, this is the caller's
3860
best guess as to the function's entry point. At the time of
3861
this writing, handle_inferior_event doesn't get this right, so
3862
it should be our last resort. */
3864
/* Consult the partial symbol table, to find which function
3866
if (! find_pc_partial_function (pc, NULL, &func_addr, &func_end))
3868
CORE_ADDR prologue_end;
3870
/* We don't even have minsym information, so fall back to using
3871
func_start, if given. */
3873
return 1; /* We *might* be in a prologue. */
3875
prologue_end = SKIP_PROLOGUE (func_start);
3877
return func_start <= pc && pc < prologue_end;
3880
/* If we have line number information for the function, that's
3881
usually pretty reliable. */
3882
sal = find_pc_line (func_addr, 0);
3884
/* Now sal describes the source line at the function's entry point,
3885
which (by convention) is the prologue. The end of that "line",
3886
sal.end, is the end of the prologue.
3888
Note that, for functions whose source code is all on a single
3889
line, the line number information doesn't always end up this way.
3890
So we must verify that our purported end-of-prologue address is
3891
*within* the function, not at its start or end. */
3893
|| sal.end <= func_addr
3894
|| func_end <= sal.end)
3896
/* We don't have any good line number info, so use the minsym
3897
information, together with the architecture-specific prologue
3899
CORE_ADDR prologue_end = SKIP_PROLOGUE (func_addr);
3901
return func_addr <= pc && pc < prologue_end;
3904
/* We have line number info, and it looks good. */
3905
return func_addr <= pc && pc < sal.end;
3908
/* Given PC at the function's start address, attempt to find the
3909
prologue end using SAL information. Return zero if the skip fails.
3911
A non-optimized prologue traditionally has one SAL for the function
3912
and a second for the function body. A single line function has
3913
them both pointing at the same line.
3915
An optimized prologue is similar but the prologue may contain
3916
instructions (SALs) from the instruction body. Need to skip those
3917
while not getting into the function body.
3919
The functions end point and an increasing SAL line are used as
3920
indicators of the prologue's endpoint.
3922
This code is based on the function refine_prologue_limit (versions
3923
found in both ia64 and ppc). */
3926
skip_prologue_using_sal (CORE_ADDR func_addr)
3928
struct symtab_and_line prologue_sal;
3932
/* Get an initial range for the function. */
3933
find_pc_partial_function (func_addr, NULL, &start_pc, &end_pc);
3934
start_pc += FUNCTION_START_OFFSET;
3936
prologue_sal = find_pc_line (start_pc, 0);
3937
if (prologue_sal.line != 0)
3939
while (prologue_sal.end < end_pc)
3941
struct symtab_and_line sal;
3943
sal = find_pc_line (prologue_sal.end, 0);
3946
/* Assume that a consecutive SAL for the same (or larger)
3947
line mark the prologue -> body transition. */
3948
if (sal.line >= prologue_sal.line)
3950
/* The case in which compiler's optimizer/scheduler has
3951
moved instructions into the prologue. We look ahead in
3952
the function looking for address ranges whose
3953
corresponding line number is less the first one that we
3954
found for the function. This is more conservative then
3955
refine_prologue_limit which scans a large number of SALs
3956
looking for any in the prologue */
3960
return prologue_sal.end;
3963
struct symtabs_and_lines
3964
decode_line_spec (char *string, int funfirstline)
3966
struct symtabs_and_lines sals;
3967
struct symtab_and_line cursal;
3970
error ("Empty line specification.");
3972
/* We use whatever is set as the current source line. We do not try
3973
and get a default or it will recursively call us! */
3974
cursal = get_current_source_symtab_and_line ();
3976
sals = decode_line_1 (&string, funfirstline,
3977
cursal.symtab, cursal.line,
3978
(char ***) NULL, NULL);
3981
error ("Junk at end of line specification: %s", string);
3986
static char *name_of_main;
3989
set_main_name (const char *name)
3991
if (name_of_main != NULL)
3993
xfree (name_of_main);
3994
name_of_main = NULL;
3998
name_of_main = xstrdup (name);
4005
if (name_of_main != NULL)
4006
return name_of_main;
4013
_initialize_symtab (void)
4015
add_info ("variables", variables_info,
4016
"All global and static variable names, or those matching REGEXP.");
4018
add_com ("whereis", class_info, variables_info,
4019
"All global and static variable names, or those matching REGEXP.");
4021
add_info ("functions", functions_info,
4022
"All function names, or those matching REGEXP.");
4025
/* FIXME: This command has at least the following problems:
4026
1. It prints builtin types (in a very strange and confusing fashion).
4027
2. It doesn't print right, e.g. with
4028
typedef struct foo *FOO
4029
type_print prints "FOO" when we want to make it (in this situation)
4030
print "struct foo *".
4031
I also think "ptype" or "whatis" is more likely to be useful (but if
4032
there is much disagreement "info types" can be fixed). */
4033
add_info ("types", types_info,
4034
"All type names, or those matching REGEXP.");
4036
add_info ("sources", sources_info,
4037
"Source files in the program.");
4039
add_com ("rbreak", class_breakpoint, rbreak_command,
4040
"Set a breakpoint for all functions matching REGEXP.");
4044
add_com ("lf", class_info, sources_info, "Source files in the program");
4045
add_com ("lg", class_info, variables_info,
4046
"All global and static variable names, or those matching REGEXP.");
4049
/* Initialize the one built-in type that isn't language dependent... */
4050
builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0,
4051
"<unknown type>", (struct objfile *) NULL);
4055
#include "gdb-stabs.h"
4056
#include "version.h"
4058
#include "../../defs.h"
4060
static void get_member_data(struct gnu_request *, struct type *);
4061
static void dump_enum(struct type *, struct gnu_request *);
4062
static void eval_enum(struct type *, struct gnu_request *);
4063
static void gdb_get_line_number(struct gnu_request *);
4064
static void gdb_get_datatype(struct gnu_request *);
4065
static void gdb_get_symbol_type(struct gnu_request *);
4066
static void gdb_command_exists(struct gnu_request *);
4067
#ifdef NEEDS_NEW_FUNCTIONALITY
4068
static void gdb_stack_trace(struct gnu_request *);
4070
static void gdb_debug_command(struct gnu_request *);
4071
static void gdb_function_numargs(struct gnu_request *);
4072
static void gdb_add_symbol_file(struct gnu_request *);
4073
static void gdb_delete_symbol_file(struct gnu_request *);
4074
static void gdb_patch_symbol_values(struct gnu_request *);
4075
extern void replace_ui_file_FILE(struct ui_file *, FILE *);
4076
extern int get_frame_offset(CORE_ADDR);
4078
static struct objfile *gdb_kernel_objfile = { 0 };
4080
static ulong gdb_merge_flags = 0;
4081
#define KERNEL_SYMBOLS_PATCHED (0x1)
4084
#define STREQ(A, B) (A && B && (strcmp(A, B) == 0))
4087
* All commands from above come through here.
4090
gdb_command_funnel(struct gnu_request *req)
4094
if (req->command != GNU_VERSION) {
4095
replace_ui_file_FILE(gdb_stdout, req->fp);
4096
replace_ui_file_FILE(gdb_stderr, req->fp);
4097
do_cleanups((struct cleanup *)0);
4100
switch (req->command)
4103
req->buf = (char *)version;
4106
case GNU_PASS_THROUGH:
4107
execute_command(req->buf,
4108
req->flags & GNU_FROM_TTY_OFF ? FALSE : TRUE);
4111
case GNU_STACK_TRACE:
4112
#ifdef NEEDS_NEW_FUNCTIONALITY
4114
* The get_current_frame() function in frame.c no longer can
4115
* be subject of a CRASH_MERGE in which passed-in fp and pc
4116
* value were substituted for read_fp() and read_pc() calls.
4117
* Now there's a new unwind_to_current_frame() function and
4118
* a new frame_info structure that are used.
4120
gdb_stack_trace(req);
4122
req->flags |= GNU_COMMAND_FAILED;
4125
case GNU_RESOLVE_TEXT_ADDR:
4126
sym = find_pc_function(req->addr);
4127
if (!sym || TYPE_CODE(sym->type) != TYPE_CODE_FUNC)
4128
req->flags |= GNU_COMMAND_FAILED;
4131
case GNU_DISASSEMBLE:
4133
sprintf(req->buf, "disassemble 0x%lx 0x%lx",
4134
req->addr, req->addr2);
4136
sprintf(req->buf, "disassemble 0x%lx", req->addr);
4137
execute_command(req->buf, TRUE);
4140
case GNU_ADD_SYMBOL_FILE:
4141
gdb_add_symbol_file(req);
4144
case GNU_DELETE_SYMBOL_FILE:
4145
gdb_delete_symbol_file(req);
4148
case GNU_GET_LINE_NUMBER:
4149
gdb_get_line_number(req);
4152
case GNU_GET_DATATYPE:
4153
gdb_get_datatype(req);
4156
case GNU_GET_SYMBOL_TYPE:
4157
gdb_get_symbol_type(req);
4160
case GNU_COMMAND_EXISTS:
4161
gdb_command_exists(req);
4164
case GNU_ALPHA_FRAME_OFFSET:
4165
#ifdef NEEDS_NEW_FUNCTIONALITY
4167
* get_frame_offset() was a CRASH_MERGE function located in
4168
* alpha-tdep.c; going from 5.3 to 6.1 made its direct port
4169
* impossible because of dependencies that no longer exist.
4170
* Also changed in alpha-tdep.c, alpha_frame_chain() and
4171
* read_next_frame_reg() no longer exist, and both of those
4172
* contained CRASH_MERGE pieces. Until somebody gives me
4173
* a new port of a function to calculate the size of a function
4174
* frame, it appears that alpha back-traces may be far more
4177
req->value = get_frame_offset(req->pc);
4182
case GNU_FUNCTION_NUMARGS:
4183
gdb_function_numargs(req);
4186
case GNU_DEBUG_COMMAND:
4187
gdb_debug_command(req);
4190
case GNU_PATCH_SYMBOL_VALUES:
4191
gdb_patch_symbol_values(req);
4195
req->flags |= GNU_COMMAND_FAILED;
4201
* Given a PC value, return the file and line number.
4204
gdb_get_line_number(struct gnu_request *req)
4206
struct symtab_and_line sal;
4209
#define LASTCHAR(s) (s[strlen(s)-1])
4213
sal = find_pc_line(pc, 0);
4220
if (sal.symtab->filename && sal.symtab->dirname) {
4221
if (sal.symtab->filename[0] == '/')
4222
sprintf(req->buf, "%s: %d",
4223
sal.symtab->filename, sal.line);
4225
sprintf(req->buf, "%s%s%s: %d",
4226
sal.symtab->dirname,
4227
LASTCHAR(sal.symtab->dirname) == '/' ? "" : "/", sal.symtab->filename, sal.line);
4233
* General purpose routine for determining datatypes.
4237
gdb_get_datatype(struct gnu_request *req)
4239
register struct cleanup *old_chain = NULL;
4240
register struct type *type;
4241
register struct type *typedef_type;
4242
struct expression *expr;
4245
struct field *nextfield;
4248
if (gdb_CRASHDEBUG(2))
4249
console("gdb_get_datatype [%s] (a)\n", req->name);
4251
req->typecode = TYPE_CODE_UNDEF;
4254
* lookup_symbol() will pick up struct and union names.
4256
sym = lookup_symbol(req->name, 0, STRUCT_DOMAIN, 0,
4257
(struct symtab **) NULL);
4259
req->typecode = TYPE_CODE(sym->type);
4260
req->length = TYPE_LENGTH(sym->type);
4262
get_member_data(req, sym->type);
4264
if (TYPE_CODE(sym->type) == TYPE_CODE_ENUM) {
4265
if (req->flags & GNU_PRINT_ENUMERATORS)
4266
dump_enum(sym->type, req);
4273
* Otherwise parse the expression.
4275
if (gdb_CRASHDEBUG(2))
4276
console("gdb_get_datatype [%s] (b)\n", req->name);
4278
expr = parse_expression(req->name);
4280
old_chain = make_cleanup(free_current_contents, &expr);
4283
switch (expr->elts[0].opcode)
4286
if (gdb_CRASHDEBUG(2))
4287
console("expr->elts[0].opcode: OP_VAR_VALUE\n");
4288
type = expr->elts[2].symbol->type;
4289
if (TYPE_CODE(type) == TYPE_CODE_ENUM) {
4290
req->typecode = TYPE_CODE(type);
4291
req->value = SYMBOL_VALUE(expr->elts[2].symbol);
4292
req->tagname = TYPE_TAG_NAME(type);
4293
if (!req->tagname) {
4294
val = evaluate_type(expr);
4295
eval_enum(VALUE_TYPE(val), req);
4301
if (gdb_CRASHDEBUG(2))
4302
console("expr->elts[0].opcode: OP_TYPE\n");
4303
type = expr->elts[1].type;
4305
req->typecode = TYPE_CODE(type);
4306
req->length = TYPE_LENGTH(type);
4308
if (TYPE_CODE(type) == TYPE_CODE_TYPEDEF) {
4309
req->is_typedef = TYPE_CODE_TYPEDEF;
4310
if ((typedef_type = check_typedef(type))) {
4311
req->typecode = TYPE_CODE(typedef_type);
4312
req->length = TYPE_LENGTH(typedef_type);
4313
type = typedef_type;
4317
if (TYPE_CODE(type) == TYPE_CODE_ENUM) {
4318
if (req->is_typedef)
4319
if (req->flags & GNU_PRINT_ENUMERATORS) {
4320
if (req->is_typedef)
4321
fprintf_filtered(gdb_stdout,
4323
dump_enum(type, req);
4328
get_member_data(req, type);
4333
if (gdb_CRASHDEBUG(2))
4334
console("expr->elts[0].opcode: %d (?)\n",
4335
expr->elts[0].opcode);
4340
do_cleanups(old_chain);
4344
* More robust enum list dump that gdb's, showing the value of each
4345
* identifier, each on its own line.
4348
dump_enum(struct type *type, struct gnu_request *req)
4354
len = TYPE_NFIELDS (type);
4356
if (TYPE_TAG_NAME(type))
4357
fprintf_filtered(gdb_stdout,
4358
"enum %s {\n", TYPE_TAG_NAME (type));
4360
fprintf_filtered(gdb_stdout, "enum {\n");
4362
for (i = 0; i < len; i++) {
4363
fprintf_filtered(gdb_stdout, " %s",
4364
TYPE_FIELD_NAME (type, i));
4365
if (lastval != TYPE_FIELD_BITPOS (type, i)) {
4366
fprintf_filtered (gdb_stdout, " = %d",
4367
TYPE_FIELD_BITPOS (type, i));
4368
lastval = TYPE_FIELD_BITPOS (type, i);
4370
fprintf_filtered(gdb_stdout, " = %d", lastval);
4371
fprintf_filtered(gdb_stdout, "\n");
4374
if (TYPE_TAG_NAME(type))
4375
fprintf_filtered(gdb_stdout, "};\n");
4377
fprintf_filtered(gdb_stdout, "} %s;\n", req->name);
4381
* Given an enum type with no tagname, determine its value.
4384
eval_enum(struct type *type, struct gnu_request *req)
4390
len = TYPE_NFIELDS (type);
4393
for (i = 0; i < len; i++) {
4394
if (lastval != TYPE_FIELD_BITPOS (type, i)) {
4395
lastval = TYPE_FIELD_BITPOS (type, i);
4397
if (STREQ(TYPE_FIELD_NAME(type, i), req->name)) {
4398
req->tagname = "(unknown)";
4399
req->value = lastval;
4407
* Walk through a struct type's list of fields looking for the desired
4408
* member field, and when found, return its relevant data.
4411
get_member_data(struct gnu_request *req, struct type *type)
4414
struct field *nextfield;
4416
struct type *typedef_type;
4418
req->member_offset = -1;
4420
#ifdef TYPE_MAIN_TYPE
4421
nfields = TYPE_MAIN_TYPE(type)->nfields;
4422
nextfield = TYPE_MAIN_TYPE(type)->fields;
4424
nfields = type->nfields;
4425
nextfield = type->fields;
4429
struct type *newtype;
4430
newtype = lookup_transparent_type(req->name);
4432
console("get_member_data(%s.%s): switching type from %lx to %lx\n",
4433
req->name, req->member, type, newtype);
4434
#ifdef TYPE_MAIN_TYPE
4435
nfields = TYPE_MAIN_TYPE(newtype)->nfields;
4436
nextfield = TYPE_MAIN_TYPE(newtype)->fields;
4438
nfields = newtype->nfields;
4439
nextfield = newtype->fields;
4444
for (i = 0; i < nfields; i++) {
4445
if (STREQ(req->member, nextfield->name)) {
4446
req->member_offset = nextfield->loc.bitpos;
4447
req->member_length = TYPE_LENGTH(nextfield->type);
4448
req->member_typecode = TYPE_CODE(nextfield->type);
4449
if ((req->member_typecode == TYPE_CODE_TYPEDEF) &&
4450
(typedef_type = check_typedef(nextfield->type)))
4451
req->member_length = TYPE_LENGTH(typedef_type);
4458
#ifdef NEEDS_NEW_FUNCTIONALITY
4460
* Kick off a gdb stack trace, keeping copies of the starting frame and pc.
4463
CORE_ADDR gdb_starting_pc;
4464
CORE_ADDR gdb_starting_fp;
4467
gdb_stack_trace(struct gnu_request *req)
4469
target_has_stack = TRUE;
4470
target_has_registers = TRUE;
4471
stop_soon_quietly = TRUE;
4472
gdb_starting_pc = req->pc;
4473
gdb_starting_fp = req->sp;
4474
sprintf(req->buf, "backtrace");
4475
execute_command(req->buf, TRUE);
4480
* Check whether a command exists. If it doesn't, the command will be
4481
* returned indirectly via the error_hook.
4484
gdb_command_exists(struct gnu_request *req)
4486
extern struct cmd_list_element *cmdlist;
4487
register struct cmd_list_element *c;
4490
c = lookup_cmd(&req->name, cmdlist, "", 0, 1);
4495
gdb_function_numargs(struct gnu_request *req)
4499
sym = find_pc_function(req->pc);
4501
if (!sym || TYPE_CODE(sym->type) != TYPE_CODE_FUNC) {
4502
req->flags |= GNU_COMMAND_FAILED;
4506
req->value = (ulong)TYPE_NFIELDS(sym->type);
4509
struct load_module *gdb_current_load_module = NULL;
4512
gdb_add_symbol_file(struct gnu_request *req)
4514
register struct objfile *loaded_objfile = NULL;
4515
register struct objfile *objfile;
4516
register struct minimal_symbol *m;
4517
struct load_module *lm;
4520
int external, subsequent, found;
4522
ulong value, adjusted;
4524
struct expression *expr;
4525
struct cleanup *old_chain;
4531
gdb_current_load_module = lm = (struct load_module *)req->addr;
4533
req->name = lm->mod_namelist;
4534
gdb_delete_symbol_file(req);
4536
for (i = 0 ; i < lm->mod_sections; i++) {
4537
if (STREQ(lm->mod_section_data[i].name, ".text") &&
4538
(lm->mod_section_data[i].flags & SEC_FOUND))
4543
sprintf(req->buf, "add-symbol-file %s 0x%lx", lm->mod_namelist,
4544
lm->mod_text_start ? lm->mod_text_start : lm->mod_base);
4545
if (lm->mod_data_start) {
4546
sprintf(buf, " -s .data 0x%lx", lm->mod_data_start);
4547
strcat(req->buf, buf);
4549
if (lm->mod_bss_start) {
4550
sprintf(buf, " -s .bss 0x%lx", lm->mod_bss_start);
4551
strcat(req->buf, buf);
4553
if (lm->mod_rodata_start) {
4554
sprintf(buf, " -s .rodata 0x%lx", lm->mod_rodata_start);
4555
strcat(req->buf, buf);
4558
sprintf(req->buf, "add-symbol-file %s 0x%lx", lm->mod_namelist,
4559
lm->mod_text_start);
4560
for (i = 0; i < lm->mod_sections; i++) {
4561
secname = lm->mod_section_data[i].name;
4562
if ((lm->mod_section_data[i].flags & SEC_FOUND) &&
4563
!STREQ(secname, ".text")) {
4564
sprintf(buf, " -s %s 0x%lx", secname,
4565
lm->mod_section_data[i].offset + lm->mod_base);
4566
strcat(req->buf, buf);
4571
if (gdb_CRASHDEBUG(1)) {
4572
fprintf_filtered(gdb_stdout, "gdb_add_symbol_file: %s\n", req->buf);
4575
execute_command(req->buf, FALSE);
4577
ALL_OBJFILES(objfile) {
4578
if (same_file(objfile->name, lm->mod_namelist)) {
4579
loaded_objfile = objfile;
4584
if (!loaded_objfile)
4585
req->flags |= GNU_COMMAND_FAILED;
4589
patch_load_module(struct objfile *objfile, struct minimal_symbol *msymbol)
4592
struct syment *sp, *spx;
4593
struct load_module *lm;
4594
struct mod_section_data *msd;
4595
struct section_offsets *section_offsets;
4599
struct obj_section *s;
4600
extern void print_gdb_version (struct ui_file *);
4602
if (!gdb_kernel_objfile) {
4603
gdb_kernel_objfile = objfile;
4607
if (!(lm = gdb_current_load_module) ||
4608
(msymbol && !IN_MODULE(SYMBOL_VALUE_ADDRESS(msymbol), lm)))
4612
for (sp = lm->mod_load_symtable;
4613
sp < lm->mod_load_symend; sp++) {
4615
if ((sp->value < lm->mod_data_start) ||
4616
!STREQ(sp->name, msymbol->ginfo.name))
4619
for (external = FALSE,
4620
spx = lm->mod_ext_symtable;
4621
spx < lm->mod_ext_symend;
4623
if (STREQ(sp->name, spx->name)) {
4631
if (gdb_CRASHDEBUG(1)) {
4632
fprintf_filtered(gdb_stdout,
4633
"patch %s from %lx to %lx\n",
4634
msymbol->ginfo.name,
4635
SYMBOL_VALUE_ADDRESS(msymbol),
4639
console("patch %s from %lx to %lx\n",
4640
msymbol->ginfo.name,
4641
SYMBOL_VALUE_ADDRESS(msymbol), sp->value);
4643
SYMBOL_VALUE_ADDRESS(msymbol) = sp->value;
4650
for (s = objfile->sections; s < objfile->sections_end; ++s) {
4651
name = (char *)s->the_bfd_section->name;
4653
for (i = 0; i < lm->mod_sections; i++) {
4654
msd = &lm->mod_section_data[i];
4655
if (STREQ(msd->name, name)) {
4656
s->addr = lm->mod_base + msd->offset;
4657
s->endaddr = s->addr + msd->size;
4662
section_offsets = objfile->section_offsets;
4664
if (objfile->sect_index_text != -1)
4665
section_offsets->offsets[SECT_OFF_TEXT(objfile)] =
4668
if (objfile->sect_index_data != -1)
4669
section_offsets->offsets[SECT_OFF_DATA(objfile)] =
4672
if (objfile->sect_index_bss != -1)
4673
section_offsets->offsets[SECT_OFF_BSS(objfile)] =
4676
if (objfile->sect_index_rodata != -1)
4677
section_offsets->offsets[SECT_OFF_RODATA(objfile)] =
4678
lm->mod_rodata_start;
4680
#ifdef DEPRECATED_SECT_OFF_MAX
4681
if (gdb_CRASHDEBUG(1)) {
4682
for (i = 0; i < SECT_OFF_MAX; i++) {
4683
if (ANOFFSET(objfile->section_offsets, i)) {
4684
fprintf_filtered(gdb_stdout,
4685
"section_offsets[%d]: %lx\n", i,
4686
ANOFFSET(objfile->section_offsets, i));
4694
gdb_delete_symbol_file(struct gnu_request *req)
4696
register struct objfile *objfile;
4698
ALL_OBJFILES(objfile) {
4699
if (STREQ(objfile->name, req->name)) {
4700
free_objfile(objfile);
4705
if (gdb_CRASHDEBUG(1))
4706
ALL_OBJFILES(objfile)
4707
fprintf_filtered(gdb_stdout, "%s\n", objfile->name);
4711
* Walk through all minimal_symbols, patching their values with the
4712
* correct addresses.
4715
gdb_patch_symbol_values(struct gnu_request *req)
4717
struct minimal_symbol *msymbol;
4718
struct objfile *objfile;
4720
req->name = PATCH_KERNEL_SYMBOLS_START;
4721
patch_kernel_symbol(req);
4723
ALL_MSYMBOLS (objfile, msymbol)
4725
req->name = msymbol->ginfo.name;
4726
req->addr = (ulong)(&SYMBOL_VALUE_ADDRESS(msymbol));
4727
if (!patch_kernel_symbol(req)) {
4728
req->flags |= GNU_COMMAND_FAILED;
4733
req->name = PATCH_KERNEL_SYMBOLS_STOP;
4734
patch_kernel_symbol(req);
4736
clear_symtab_users();
4737
gdb_merge_flags |= KERNEL_SYMBOLS_PATCHED;
4741
gdb_get_symbol_type(struct gnu_request *req)
4743
struct expression *expr;
4745
struct cleanup *old_chain = NULL;
4747
struct type *target_type;
4749
req->typecode = TYPE_CODE_UNDEF;
4751
expr = parse_expression (req->name);
4752
old_chain = make_cleanup (free_current_contents, &expr);
4753
val = evaluate_type (expr);
4755
type = VALUE_TYPE(val);
4757
#ifdef TYPE_MAIN_TYPE
4758
req->typename = TYPE_MAIN_TYPE(type)->name;
4759
req->typecode = TYPE_MAIN_TYPE(type)->code;
4760
req->length = type->length;
4761
target_type = TYPE_MAIN_TYPE(type)->target_type;
4763
req->typename = type->name;
4764
req->typecode = type->code;
4765
req->length = type->length;
4766
target_type = type->target_type;
4770
#ifdef TYPE_MAIN_TYPE
4771
req->target_typename = TYPE_MAIN_TYPE(target_type)->name;
4772
req->target_typecode = TYPE_MAIN_TYPE(target_type)->code;
4773
req->target_length = target_type->length;
4775
req->target_typename = target_type->name;
4776
req->target_typecode = target_type->code;
4777
req->target_length = target_type->length;
4782
get_member_data(req, type);
4784
do_cleanups (old_chain);
4788
gdb_debug_command(struct gnu_request *req)
4794
* Only necessary on "patched" kernel symbol sessions, and called only by
4795
* lookup_symbol(), pull a symbol value bait-and-switch operation by altering
4796
* either a data symbol's address value or a text symbol's block start address.
4799
gdb_bait_and_switch(char *name, struct symbol *sym)
4801
struct minimal_symbol *msym;
4802
struct block *block;
4804
if ((gdb_merge_flags & KERNEL_SYMBOLS_PATCHED) &&
4805
(msym = lookup_minimal_symbol(name, NULL, gdb_kernel_objfile))) {
4806
if (sym->aclass == LOC_BLOCK) {
4807
block = (struct block *)SYMBOL_BLOCK_VALUE(sym);
4808
BLOCK_START(block) = SYMBOL_VALUE_ADDRESS(msym);
4810
SYMBOL_VALUE_ADDRESS(sym) = SYMBOL_VALUE_ADDRESS(msym);