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