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