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