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