| 1 | /* Symbol table lookup for the GNU debugger, GDB. |
| 2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992 |
| 3 | Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 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 |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 20 | |
| 21 | #include "defs.h" |
| 22 | #include "symtab.h" |
| 23 | #include "gdbtypes.h" |
| 24 | #include "gdbcore.h" |
| 25 | #include "frame.h" |
| 26 | #include "target.h" |
| 27 | #include "value.h" |
| 28 | #include "symfile.h" |
| 29 | #include "objfiles.h" |
| 30 | #include "gdbcmd.h" |
| 31 | #include "call-cmds.h" |
| 32 | #include "regex.h" |
| 33 | #include "expression.h" |
| 34 | #include "language.h" |
| 35 | #include "demangle.h" |
| 36 | |
| 37 | #include <obstack.h> |
| 38 | #include <assert.h> |
| 39 | |
| 40 | #include <sys/types.h> |
| 41 | #include <fcntl.h> |
| 42 | #include <string.h> |
| 43 | #include <sys/stat.h> |
| 44 | #include <ctype.h> |
| 45 | |
| 46 | /* Prototypes for local functions */ |
| 47 | |
| 48 | static char * |
| 49 | expensive_mangler PARAMS ((const char *)); |
| 50 | |
| 51 | extern int |
| 52 | find_methods PARAMS ((struct type *, char *, char **, struct symbol **)); |
| 53 | |
| 54 | static void |
| 55 | completion_list_add_symbol PARAMS ((char *, char *, int)); |
| 56 | |
| 57 | static struct symtabs_and_lines |
| 58 | decode_line_2 PARAMS ((struct symbol *[], int, int)); |
| 59 | |
| 60 | static void |
| 61 | rbreak_command PARAMS ((char *, int)); |
| 62 | |
| 63 | static void |
| 64 | types_info PARAMS ((char *, int)); |
| 65 | |
| 66 | static void |
| 67 | functions_info PARAMS ((char *, int)); |
| 68 | |
| 69 | static void |
| 70 | variables_info PARAMS ((char *, int)); |
| 71 | |
| 72 | static void |
| 73 | sources_info PARAMS ((char *, int)); |
| 74 | |
| 75 | static void |
| 76 | list_symbols PARAMS ((char *, int, int)); |
| 77 | |
| 78 | static void |
| 79 | output_source_filename PARAMS ((char *, int *)); |
| 80 | |
| 81 | static char * |
| 82 | operator_chars PARAMS ((char *, char **)); |
| 83 | |
| 84 | static int |
| 85 | find_line_common PARAMS ((struct linetable *, int, int *)); |
| 86 | |
| 87 | static struct partial_symbol * |
| 88 | lookup_partial_symbol PARAMS ((struct partial_symtab *, const char *, |
| 89 | int, enum namespace)); |
| 90 | |
| 91 | static struct partial_symbol * |
| 92 | lookup_demangled_partial_symbol PARAMS ((const struct partial_symtab *, |
| 93 | const char *)); |
| 94 | |
| 95 | static struct symbol * |
| 96 | lookup_demangled_block_symbol PARAMS ((const struct block *, const char *)); |
| 97 | |
| 98 | static struct symtab * |
| 99 | lookup_symtab_1 PARAMS ((char *)); |
| 100 | |
| 101 | /* */ |
| 102 | |
| 103 | /* The single non-language-specific builtin type */ |
| 104 | struct type *builtin_type_error; |
| 105 | |
| 106 | /* Block in which the most recently searched-for symbol was found. |
| 107 | Might be better to make this a parameter to lookup_symbol and |
| 108 | value_of_this. */ |
| 109 | |
| 110 | const struct block *block_found; |
| 111 | |
| 112 | char no_symtab_msg[] = "No symbol table is loaded. Use the \"file\" command."; |
| 113 | |
| 114 | /* While the C++ support is still in flux, issue a possibly helpful hint on |
| 115 | using the new command completion feature on single quoted demangled C++ |
| 116 | symbols. Remove when loose ends are cleaned up. FIXME -fnf */ |
| 117 | |
| 118 | void |
| 119 | cplusplus_hint (name) |
| 120 | char *name; |
| 121 | { |
| 122 | printf ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name, name); |
| 123 | printf ("(Note leading single quote.)\n"); |
| 124 | } |
| 125 | |
| 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; |
| 136 | register char *slash; |
| 137 | register struct objfile *objfile; |
| 138 | |
| 139 | got_symtab: |
| 140 | |
| 141 | /* First, search for an exact match */ |
| 142 | |
| 143 | ALL_SYMTABS (objfile, s) |
| 144 | if (strcmp (name, s->filename) == 0) |
| 145 | return s; |
| 146 | |
| 147 | slash = strchr (name, '/'); |
| 148 | |
| 149 | /* Now, search for a matching tail (only if name doesn't have any dirs) */ |
| 150 | |
| 151 | if (!slash) |
| 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 | |
| 160 | if (strcmp (p, name) == 0) |
| 161 | return s; |
| 162 | } |
| 163 | |
| 164 | /* Same search rules as above apply here, but now we look thru the |
| 165 | psymtabs. */ |
| 166 | |
| 167 | ALL_PSYMTABS (objfile, ps) |
| 168 | if (strcmp (name, ps -> filename) == 0) |
| 169 | goto got_psymtab; |
| 170 | |
| 171 | if (!slash) |
| 172 | ALL_PSYMTABS (objfile, ps) |
| 173 | { |
| 174 | char *p = ps -> filename; |
| 175 | char *tail = strrchr (p, '/'); |
| 176 | |
| 177 | if (tail) |
| 178 | p = tail + 1; |
| 179 | |
| 180 | if (strcmp (p, name) == 0) |
| 181 | goto got_psymtab; |
| 182 | } |
| 183 | |
| 184 | return (NULL); |
| 185 | |
| 186 | got_psymtab: |
| 187 | |
| 188 | if (ps -> readin) |
| 189 | error ("Internal: readin pst for `%s' found when no symtab found.", name); |
| 190 | |
| 191 | s = PSYMTAB_TO_SYMTAB (ps); |
| 192 | |
| 193 | if (s) |
| 194 | return s; |
| 195 | |
| 196 | /* At this point, we have located the psymtab for this file, but |
| 197 | the conversion to a symtab has failed. This usually happens |
| 198 | when we are looking up an include file. In this case, |
| 199 | PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has |
| 200 | been created. So, we need to run through the symtabs again in |
| 201 | order to find the file. |
| 202 | XXX - This is a crock, and should be fixed inside of the the |
| 203 | symbol parsing routines. */ |
| 204 | goto got_symtab; |
| 205 | } |
| 206 | |
| 207 | /* Lookup the symbol table of a source file named NAME. Try a couple |
| 208 | of variations if the first lookup doesn't work. */ |
| 209 | |
| 210 | struct symtab * |
| 211 | lookup_symtab (name) |
| 212 | char *name; |
| 213 | { |
| 214 | register struct symtab *s; |
| 215 | register char *copy; |
| 216 | |
| 217 | s = lookup_symtab_1 (name); |
| 218 | if (s) return s; |
| 219 | |
| 220 | /* If name not found as specified, see if adding ".c" helps. */ |
| 221 | |
| 222 | copy = (char *) alloca (strlen (name) + 3); |
| 223 | strcpy (copy, name); |
| 224 | strcat (copy, ".c"); |
| 225 | s = lookup_symtab_1 (copy); |
| 226 | if (s) return s; |
| 227 | |
| 228 | /* We didn't find anything; die. */ |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | /* Lookup the partial symbol table of a source file named NAME. This |
| 233 | only returns true on an exact match (ie. this semantics are |
| 234 | different from lookup_symtab. */ |
| 235 | |
| 236 | struct partial_symtab * |
| 237 | lookup_partial_symtab (name) |
| 238 | char *name; |
| 239 | { |
| 240 | register struct partial_symtab *pst; |
| 241 | register struct objfile *objfile; |
| 242 | |
| 243 | ALL_PSYMTABS (objfile, pst) |
| 244 | { |
| 245 | if (strcmp (name, pst -> filename) == 0) |
| 246 | { |
| 247 | return (pst); |
| 248 | } |
| 249 | } |
| 250 | return (NULL); |
| 251 | } |
| 252 | \f |
| 253 | /* Demangle a GDB method stub type. */ |
| 254 | char * |
| 255 | gdb_mangle_name (type, i, j) |
| 256 | struct type *type; |
| 257 | int i, j; |
| 258 | { |
| 259 | int mangled_name_len; |
| 260 | char *mangled_name; |
| 261 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); |
| 262 | struct fn_field *method = &f[j]; |
| 263 | char *field_name = TYPE_FN_FIELDLIST_NAME (type, i); |
| 264 | char *physname = TYPE_FN_FIELD_PHYSNAME (f, j); |
| 265 | char *opname; |
| 266 | int is_constructor = strcmp (field_name, type_name_no_tag (type)) == 0; |
| 267 | |
| 268 | /* Need a new type prefix. */ |
| 269 | char *const_prefix = method->is_const ? "C" : ""; |
| 270 | char *volatile_prefix = method->is_volatile ? "V" : ""; |
| 271 | char buf[20]; |
| 272 | |
| 273 | if (is_constructor) |
| 274 | { |
| 275 | buf[0] = '\0'; |
| 276 | } |
| 277 | else |
| 278 | { |
| 279 | sprintf (buf, "__%s%s", const_prefix, volatile_prefix); |
| 280 | } |
| 281 | |
| 282 | mangled_name_len = ((is_constructor ? 0 : strlen (field_name)) |
| 283 | + strlen (buf) + strlen (physname) + 1); |
| 284 | |
| 285 | /* Only needed for GNU-mangled names. ANSI-mangled names |
| 286 | work with the normal mechanisms. */ |
| 287 | if (OPNAME_PREFIX_P (field_name)) |
| 288 | { |
| 289 | opname = cplus_mangle_opname (field_name + 3, 0); |
| 290 | if (opname == NULL) |
| 291 | { |
| 292 | error ("No mangling for \"%s\"", field_name); |
| 293 | } |
| 294 | mangled_name_len += strlen (opname); |
| 295 | mangled_name = (char *) xmalloc (mangled_name_len); |
| 296 | |
| 297 | strncpy (mangled_name, field_name, 3); |
| 298 | strcpy (mangled_name + 3, opname); |
| 299 | } |
| 300 | else |
| 301 | { |
| 302 | mangled_name = (char *) xmalloc (mangled_name_len); |
| 303 | if (is_constructor) |
| 304 | { |
| 305 | mangled_name[0] = '\0'; |
| 306 | } |
| 307 | else |
| 308 | { |
| 309 | strcpy (mangled_name, field_name); |
| 310 | } |
| 311 | } |
| 312 | strcat (mangled_name, buf); |
| 313 | strcat (mangled_name, physname); |
| 314 | |
| 315 | return (mangled_name); |
| 316 | } |
| 317 | |
| 318 | \f |
| 319 | /* Find which partial symtab on contains PC. Return 0 if none. */ |
| 320 | |
| 321 | struct partial_symtab * |
| 322 | find_pc_psymtab (pc) |
| 323 | register CORE_ADDR pc; |
| 324 | { |
| 325 | register struct partial_symtab *pst; |
| 326 | register struct objfile *objfile; |
| 327 | |
| 328 | ALL_PSYMTABS (objfile, pst) |
| 329 | { |
| 330 | if (pc >= pst -> textlow && pc < pst -> texthigh) |
| 331 | { |
| 332 | return (pst); |
| 333 | } |
| 334 | } |
| 335 | return (NULL); |
| 336 | } |
| 337 | |
| 338 | /* Find which partial symbol within a psymtab contains PC. Return 0 |
| 339 | if none. Check all psymtabs if PSYMTAB is 0. */ |
| 340 | struct partial_symbol * |
| 341 | find_pc_psymbol (psymtab, pc) |
| 342 | struct partial_symtab *psymtab; |
| 343 | CORE_ADDR pc; |
| 344 | { |
| 345 | struct partial_symbol *best, *p; |
| 346 | CORE_ADDR best_pc; |
| 347 | |
| 348 | if (!psymtab) |
| 349 | psymtab = find_pc_psymtab (pc); |
| 350 | if (!psymtab) |
| 351 | return 0; |
| 352 | |
| 353 | best_pc = psymtab->textlow - 1; |
| 354 | |
| 355 | for (p = psymtab->objfile->static_psymbols.list + psymtab->statics_offset; |
| 356 | (p - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset) |
| 357 | < psymtab->n_static_syms); |
| 358 | p++) |
| 359 | if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE |
| 360 | && SYMBOL_CLASS (p) == LOC_BLOCK |
| 361 | && pc >= SYMBOL_VALUE_ADDRESS (p) |
| 362 | && SYMBOL_VALUE_ADDRESS (p) > best_pc) |
| 363 | { |
| 364 | best_pc = SYMBOL_VALUE_ADDRESS (p); |
| 365 | best = p; |
| 366 | } |
| 367 | if (best_pc == psymtab->textlow - 1) |
| 368 | return 0; |
| 369 | return best; |
| 370 | } |
| 371 | |
| 372 | \f |
| 373 | /* Find the definition for a specified symbol name NAME |
| 374 | in namespace NAMESPACE, visible from lexical block BLOCK. |
| 375 | Returns the struct symbol pointer, or zero if no symbol is found. |
| 376 | If SYMTAB is non-NULL, store the symbol table in which the |
| 377 | symbol was found there, or NULL if not found. |
| 378 | C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if |
| 379 | NAME is a field of the current implied argument `this'. If so set |
| 380 | *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero. |
| 381 | BLOCK_FOUND is set to the block in which NAME is found (in the case of |
| 382 | a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */ |
| 383 | |
| 384 | struct symbol * |
| 385 | lookup_symbol (name, block, namespace, is_a_field_of_this, symtab) |
| 386 | const char *name; |
| 387 | register const struct block *block; |
| 388 | const enum namespace namespace; |
| 389 | int *is_a_field_of_this; |
| 390 | struct symtab **symtab; |
| 391 | { |
| 392 | register struct symbol *sym; |
| 393 | register struct symtab *s; |
| 394 | register struct partial_symtab *ps; |
| 395 | struct blockvector *bv; |
| 396 | register struct objfile *objfile; |
| 397 | register struct block *b; |
| 398 | register struct minimal_symbol *msymbol; |
| 399 | char *temp; |
| 400 | extern char *gdb_completer_word_break_characters; |
| 401 | |
| 402 | /* If NAME contains any characters from gdb_completer_word_break_characters |
| 403 | then it is probably from a quoted name string. So check to see if it |
| 404 | has a C++ mangled equivalent, and if so, use the mangled equivalent. */ |
| 405 | |
| 406 | if (strpbrk (name, gdb_completer_word_break_characters) != NULL) |
| 407 | { |
| 408 | if ((temp = expensive_mangler (name)) != NULL) |
| 409 | { |
| 410 | name = temp; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | /* Search specified block and its superiors. */ |
| 415 | |
| 416 | while (block != 0) |
| 417 | { |
| 418 | sym = lookup_block_symbol (block, name, namespace); |
| 419 | if (sym) |
| 420 | { |
| 421 | block_found = block; |
| 422 | if (symtab != NULL) |
| 423 | { |
| 424 | /* Search the list of symtabs for one which contains the |
| 425 | address of the start of this block. */ |
| 426 | ALL_SYMTABS (objfile, s) |
| 427 | { |
| 428 | bv = BLOCKVECTOR (s); |
| 429 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); |
| 430 | if (BLOCK_START (b) <= BLOCK_START (block) |
| 431 | && BLOCK_END (b) > BLOCK_START (block)) |
| 432 | goto found; |
| 433 | } |
| 434 | found: |
| 435 | *symtab = s; |
| 436 | } |
| 437 | |
| 438 | return (sym); |
| 439 | } |
| 440 | block = BLOCK_SUPERBLOCK (block); |
| 441 | } |
| 442 | |
| 443 | /* But that doesn't do any demangling for the STATIC_BLOCK. |
| 444 | I'm not sure whether demangling is needed in the case of |
| 445 | nested function in inner blocks; if so this needs to be changed. |
| 446 | |
| 447 | Don't need to mess with the psymtabs; if we have a block, |
| 448 | that file is read in. If we don't, then we deal later with |
| 449 | all the psymtab stuff that needs checking. */ |
| 450 | if (namespace == VAR_NAMESPACE && block != NULL) |
| 451 | { |
| 452 | struct block *b; |
| 453 | /* Find the right symtab. */ |
| 454 | ALL_SYMTABS (objfile, s) |
| 455 | { |
| 456 | bv = BLOCKVECTOR (s); |
| 457 | b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); |
| 458 | if (BLOCK_START (b) <= BLOCK_START (block) |
| 459 | && BLOCK_END (b) > BLOCK_START (block)) |
| 460 | { |
| 461 | sym = lookup_demangled_block_symbol (b, name); |
| 462 | if (sym) |
| 463 | { |
| 464 | block_found = b; |
| 465 | if (symtab != NULL) |
| 466 | *symtab = s; |
| 467 | return sym; |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | |
| 474 | /* C++: If requested to do so by the caller, |
| 475 | check to see if NAME is a field of `this'. */ |
| 476 | if (is_a_field_of_this) |
| 477 | { |
| 478 | struct value *v = value_of_this (0); |
| 479 | |
| 480 | *is_a_field_of_this = 0; |
| 481 | if (v && check_field (v, name)) |
| 482 | { |
| 483 | *is_a_field_of_this = 1; |
| 484 | if (symtab != NULL) |
| 485 | *symtab = NULL; |
| 486 | return 0; |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | /* Now search all global blocks. Do the symtab's first, then |
| 491 | check the psymtab's */ |
| 492 | |
| 493 | ALL_SYMTABS (objfile, s) |
| 494 | { |
| 495 | bv = BLOCKVECTOR (s); |
| 496 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); |
| 497 | sym = lookup_block_symbol (block, name, namespace); |
| 498 | if (sym) |
| 499 | { |
| 500 | block_found = block; |
| 501 | if (symtab != NULL) |
| 502 | *symtab = s; |
| 503 | return sym; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | /* Check for the possibility of the symbol being a global function |
| 508 | that is stored in one of the minimal symbol tables. Eventually, all |
| 509 | global symbols might be resolved in this way. */ |
| 510 | |
| 511 | if (namespace == VAR_NAMESPACE) |
| 512 | { |
| 513 | msymbol = lookup_minimal_symbol (name, (struct objfile *) NULL); |
| 514 | |
| 515 | if (msymbol == NULL) |
| 516 | { |
| 517 | /* Test each minimal symbol to see if the minimal symbol's name |
| 518 | is a C++ mangled name that matches a user visible name. */ |
| 519 | |
| 520 | char *demangled; |
| 521 | |
| 522 | ALL_MSYMBOLS (objfile, msymbol) |
| 523 | { |
| 524 | demangled = demangle_and_match (msymbol -> name, name, 0); |
| 525 | if (demangled != NULL) |
| 526 | { |
| 527 | free (demangled); |
| 528 | goto found_msym; |
| 529 | } |
| 530 | } |
| 531 | msymbol = NULL; /* Not found */ |
| 532 | } |
| 533 | |
| 534 | found_msym: |
| 535 | if (msymbol != NULL) |
| 536 | { |
| 537 | s = find_pc_symtab (msymbol -> address); |
| 538 | /* If S is NULL, there are no debug symbols for this file. |
| 539 | Skip this stuff and check for matching static symbols below. */ |
| 540 | if (s != NULL) |
| 541 | { |
| 542 | bv = BLOCKVECTOR (s); |
| 543 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); |
| 544 | sym = lookup_block_symbol (block, msymbol -> name, namespace); |
| 545 | /* We kept static functions in minimal symbol table as well as |
| 546 | in static scope. We want to find them in the symbol table. */ |
| 547 | if (!sym) { |
| 548 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); |
| 549 | sym = lookup_block_symbol (block, msymbol -> name, |
| 550 | namespace); |
| 551 | } |
| 552 | |
| 553 | /* sym == 0 if symbol was found in the minimal symbol table |
| 554 | but not in the symtab. |
| 555 | Return 0 to use the msymbol definition of "foo_". |
| 556 | |
| 557 | This happens for Fortran "foo_" symbols, |
| 558 | which are "foo" in the symtab. |
| 559 | |
| 560 | This can also happen if "asm" is used to make a |
| 561 | regular symbol but not a debugging symbol, e.g. |
| 562 | asm(".globl _main"); |
| 563 | asm("_main:"); |
| 564 | */ |
| 565 | |
| 566 | if (symtab != NULL) |
| 567 | *symtab = s; |
| 568 | return sym; |
| 569 | } |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | ALL_PSYMTABS (objfile, ps) |
| 574 | { |
| 575 | if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace)) |
| 576 | { |
| 577 | s = PSYMTAB_TO_SYMTAB(ps); |
| 578 | bv = BLOCKVECTOR (s); |
| 579 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); |
| 580 | sym = lookup_block_symbol (block, name, namespace); |
| 581 | if (!sym) |
| 582 | error ("Internal: global symbol `%s' found in psymtab but not in symtab", name); |
| 583 | if (symtab != NULL) |
| 584 | *symtab = s; |
| 585 | return sym; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | /* Now search all per-file blocks. |
| 590 | Not strictly correct, but more useful than an error. |
| 591 | Do the symtabs first, then check the psymtabs */ |
| 592 | |
| 593 | ALL_SYMTABS (objfile, s) |
| 594 | { |
| 595 | bv = BLOCKVECTOR (s); |
| 596 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); |
| 597 | sym = lookup_block_symbol (block, name, namespace); |
| 598 | if (sym) |
| 599 | { |
| 600 | block_found = block; |
| 601 | if (symtab != NULL) |
| 602 | *symtab = s; |
| 603 | return sym; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | ALL_PSYMTABS (objfile, ps) |
| 608 | { |
| 609 | if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace)) |
| 610 | { |
| 611 | s = PSYMTAB_TO_SYMTAB(ps); |
| 612 | bv = BLOCKVECTOR (s); |
| 613 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); |
| 614 | sym = lookup_block_symbol (block, name, namespace); |
| 615 | if (!sym) |
| 616 | error ("Internal: static symbol `%s' found in psymtab but not in symtab", name); |
| 617 | if (symtab != NULL) |
| 618 | *symtab = s; |
| 619 | return sym; |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | /* Now search all per-file blocks for static mangled symbols. |
| 624 | Do the symtabs first, then check the psymtabs. */ |
| 625 | |
| 626 | if (namespace == VAR_NAMESPACE) |
| 627 | { |
| 628 | ALL_SYMTABS (objfile, s) |
| 629 | { |
| 630 | bv = BLOCKVECTOR (s); |
| 631 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); |
| 632 | sym = lookup_demangled_block_symbol (block, name); |
| 633 | if (sym) |
| 634 | { |
| 635 | block_found = block; |
| 636 | if (symtab != NULL) |
| 637 | *symtab = s; |
| 638 | return sym; |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | ALL_PSYMTABS (objfile, ps) |
| 643 | { |
| 644 | if (!ps->readin && lookup_demangled_partial_symbol (ps, name)) |
| 645 | { |
| 646 | s = PSYMTAB_TO_SYMTAB(ps); |
| 647 | bv = BLOCKVECTOR (s); |
| 648 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); |
| 649 | sym = lookup_demangled_block_symbol (block, name); |
| 650 | if (!sym) |
| 651 | error ("Internal: mangled static symbol `%s' found in psymtab but not in symtab", name); |
| 652 | if (symtab != NULL) |
| 653 | *symtab = s; |
| 654 | return sym; |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | if (symtab != NULL) |
| 660 | *symtab = NULL; |
| 661 | return 0; |
| 662 | } |
| 663 | |
| 664 | /* Look for a static demangled symbol in block BLOCK. */ |
| 665 | |
| 666 | static struct symbol * |
| 667 | lookup_demangled_block_symbol (block, name) |
| 668 | register const struct block *block; |
| 669 | const char *name; |
| 670 | { |
| 671 | register int bot, top; |
| 672 | register struct symbol *sym; |
| 673 | char *demangled; |
| 674 | |
| 675 | bot = 0; |
| 676 | top = BLOCK_NSYMS (block); |
| 677 | |
| 678 | while (bot < top) |
| 679 | { |
| 680 | sym = BLOCK_SYM (block, bot); |
| 681 | if (SYMBOL_NAMESPACE (sym) == VAR_NAMESPACE) |
| 682 | { |
| 683 | demangled = demangle_and_match (SYMBOL_NAME (sym), name, 0); |
| 684 | if (demangled != NULL) |
| 685 | { |
| 686 | free (demangled); |
| 687 | return (sym); |
| 688 | } |
| 689 | } |
| 690 | bot++; |
| 691 | } |
| 692 | |
| 693 | return (NULL); |
| 694 | } |
| 695 | |
| 696 | /* Look, in partial_symtab PST, for static mangled symbol NAME. */ |
| 697 | |
| 698 | static struct partial_symbol * |
| 699 | lookup_demangled_partial_symbol (pst, name) |
| 700 | const struct partial_symtab *pst; |
| 701 | const char *name; |
| 702 | { |
| 703 | struct partial_symbol *start, *psym; |
| 704 | int length = pst->n_static_syms; |
| 705 | char *demangled; |
| 706 | |
| 707 | if (!length) |
| 708 | return (struct partial_symbol *) 0; |
| 709 | |
| 710 | start = pst->objfile->static_psymbols.list + pst->statics_offset; |
| 711 | for (psym = start; psym < start + length; psym++) |
| 712 | { |
| 713 | if (SYMBOL_NAMESPACE (psym) == VAR_NAMESPACE) |
| 714 | { |
| 715 | demangled = demangle_and_match (SYMBOL_NAME (psym), name, 0); |
| 716 | if (demangled != NULL) |
| 717 | { |
| 718 | free (demangled); |
| 719 | return (psym); |
| 720 | } |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | return (NULL); |
| 725 | } |
| 726 | |
| 727 | /* Look, in partial_symtab PST, for symbol NAME. Check the global |
| 728 | symbols if GLOBAL, the static symbols if not */ |
| 729 | |
| 730 | static struct partial_symbol * |
| 731 | lookup_partial_symbol (pst, name, global, namespace) |
| 732 | struct partial_symtab *pst; |
| 733 | const char *name; |
| 734 | int global; |
| 735 | enum namespace namespace; |
| 736 | { |
| 737 | struct partial_symbol *start, *psym; |
| 738 | int length = (global ? pst->n_global_syms : pst->n_static_syms); |
| 739 | |
| 740 | if (!length) |
| 741 | return (struct partial_symbol *) 0; |
| 742 | |
| 743 | start = (global ? |
| 744 | pst->objfile->global_psymbols.list + pst->globals_offset : |
| 745 | pst->objfile->static_psymbols.list + pst->statics_offset ); |
| 746 | |
| 747 | if (global) /* This means we can use a binary */ |
| 748 | /* search. */ |
| 749 | { |
| 750 | struct partial_symbol *top, *bottom, *center; |
| 751 | |
| 752 | /* Binary search. This search is guaranteed to end with center |
| 753 | pointing at the earliest partial symbol with the correct |
| 754 | name. At that point *all* partial symbols with that name |
| 755 | will be checked against the correct namespace. */ |
| 756 | bottom = start; |
| 757 | top = start + length - 1; |
| 758 | while (top > bottom) |
| 759 | { |
| 760 | center = bottom + (top - bottom) / 2; |
| 761 | |
| 762 | assert (center < top); |
| 763 | |
| 764 | if (strcmp (SYMBOL_NAME (center), name) >= 0) |
| 765 | top = center; |
| 766 | else |
| 767 | bottom = center + 1; |
| 768 | } |
| 769 | assert (top == bottom); |
| 770 | |
| 771 | while (!strcmp (SYMBOL_NAME (top), name)) |
| 772 | { |
| 773 | if (SYMBOL_NAMESPACE (top) == namespace) |
| 774 | return top; |
| 775 | top ++; |
| 776 | } |
| 777 | } |
| 778 | else |
| 779 | { |
| 780 | /* Can't use a binary search */ |
| 781 | for (psym = start; psym < start + length; psym++) |
| 782 | if (namespace == SYMBOL_NAMESPACE (psym) |
| 783 | && !strcmp (name, SYMBOL_NAME (psym))) |
| 784 | return psym; |
| 785 | } |
| 786 | |
| 787 | return (struct partial_symbol *) 0; |
| 788 | } |
| 789 | |
| 790 | /* Find the psymtab containing main(). */ |
| 791 | |
| 792 | struct partial_symtab * |
| 793 | find_main_psymtab () |
| 794 | { |
| 795 | register struct partial_symtab *pst; |
| 796 | register struct objfile *objfile; |
| 797 | |
| 798 | ALL_PSYMTABS (objfile, pst) |
| 799 | { |
| 800 | if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE)) |
| 801 | { |
| 802 | return (pst); |
| 803 | } |
| 804 | } |
| 805 | return (NULL); |
| 806 | } |
| 807 | |
| 808 | /* Look for a symbol in block BLOCK. */ |
| 809 | |
| 810 | struct symbol * |
| 811 | lookup_block_symbol (block, name, namespace) |
| 812 | register const struct block *block; |
| 813 | const char *name; |
| 814 | const enum namespace namespace; |
| 815 | { |
| 816 | register int bot, top, inc; |
| 817 | register struct symbol *sym, *parameter_sym; |
| 818 | |
| 819 | top = BLOCK_NSYMS (block); |
| 820 | bot = 0; |
| 821 | |
| 822 | /* If the blocks's symbols were sorted, start with a binary search. */ |
| 823 | |
| 824 | if (BLOCK_SHOULD_SORT (block)) |
| 825 | { |
| 826 | /* First, advance BOT to not far before |
| 827 | the first symbol whose name is NAME. */ |
| 828 | |
| 829 | while (1) |
| 830 | { |
| 831 | inc = (top - bot + 1); |
| 832 | /* No need to keep binary searching for the last few bits worth. */ |
| 833 | if (inc < 4) |
| 834 | break; |
| 835 | inc = (inc >> 1) + bot; |
| 836 | sym = BLOCK_SYM (block, inc); |
| 837 | if (SYMBOL_NAME (sym)[0] < name[0]) |
| 838 | bot = inc; |
| 839 | else if (SYMBOL_NAME (sym)[0] > name[0]) |
| 840 | top = inc; |
| 841 | else if (strcmp (SYMBOL_NAME (sym), name) < 0) |
| 842 | bot = inc; |
| 843 | else |
| 844 | top = inc; |
| 845 | } |
| 846 | |
| 847 | /* Now scan forward until we run out of symbols, |
| 848 | find one whose name is greater than NAME, |
| 849 | or find one we want. |
| 850 | If there is more than one symbol with the right name and namespace, |
| 851 | we return the first one. dbxread.c is careful to make sure |
| 852 | that if one is a register then it comes first. */ |
| 853 | |
| 854 | top = BLOCK_NSYMS (block); |
| 855 | while (bot < top) |
| 856 | { |
| 857 | sym = BLOCK_SYM (block, bot); |
| 858 | inc = SYMBOL_NAME (sym)[0] - name[0]; |
| 859 | if (inc == 0) |
| 860 | inc = strcmp (SYMBOL_NAME (sym), name); |
| 861 | if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace) |
| 862 | return sym; |
| 863 | if (inc > 0) |
| 864 | return 0; |
| 865 | bot++; |
| 866 | } |
| 867 | return 0; |
| 868 | } |
| 869 | |
| 870 | /* Here if block isn't sorted. |
| 871 | This loop is equivalent to the loop above, |
| 872 | but hacked greatly for speed. |
| 873 | |
| 874 | Note that parameter symbols do not always show up last in the |
| 875 | list; this loop makes sure to take anything else other than |
| 876 | parameter symbols first; it only uses parameter symbols as a |
| 877 | last resort. Note that this only takes up extra computation |
| 878 | time on a match. */ |
| 879 | |
| 880 | parameter_sym = (struct symbol *) 0; |
| 881 | top = BLOCK_NSYMS (block); |
| 882 | inc = name[0]; |
| 883 | while (bot < top) |
| 884 | { |
| 885 | sym = BLOCK_SYM (block, bot); |
| 886 | if (SYMBOL_NAME (sym)[0] == inc |
| 887 | && !strcmp (SYMBOL_NAME (sym), name) |
| 888 | && SYMBOL_NAMESPACE (sym) == namespace) |
| 889 | { |
| 890 | if (SYMBOL_CLASS (sym) == LOC_ARG |
| 891 | || SYMBOL_CLASS (sym) == LOC_LOCAL_ARG |
| 892 | || SYMBOL_CLASS (sym) == LOC_REF_ARG |
| 893 | || SYMBOL_CLASS (sym) == LOC_REGPARM) |
| 894 | parameter_sym = sym; |
| 895 | else |
| 896 | return sym; |
| 897 | } |
| 898 | bot++; |
| 899 | } |
| 900 | return parameter_sym; /* Will be 0 if not found. */ |
| 901 | } |
| 902 | \f |
| 903 | /* Return the symbol for the function which contains a specified |
| 904 | lexical block, described by a struct block BL. */ |
| 905 | |
| 906 | struct symbol * |
| 907 | block_function (bl) |
| 908 | struct block *bl; |
| 909 | { |
| 910 | while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0) |
| 911 | bl = BLOCK_SUPERBLOCK (bl); |
| 912 | |
| 913 | return BLOCK_FUNCTION (bl); |
| 914 | } |
| 915 | |
| 916 | /* Subroutine of find_pc_line */ |
| 917 | |
| 918 | struct symtab * |
| 919 | find_pc_symtab (pc) |
| 920 | register CORE_ADDR pc; |
| 921 | { |
| 922 | register struct block *b; |
| 923 | struct blockvector *bv; |
| 924 | register struct symtab *s = 0; |
| 925 | register struct partial_symtab *ps; |
| 926 | register struct objfile *objfile; |
| 927 | |
| 928 | /* Search all symtabs for one whose file contains our pc */ |
| 929 | |
| 930 | ALL_SYMTABS (objfile, s) |
| 931 | { |
| 932 | bv = BLOCKVECTOR (s); |
| 933 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); |
| 934 | if (BLOCK_START (b) <= pc |
| 935 | && BLOCK_END (b) > pc) |
| 936 | goto found; |
| 937 | } |
| 938 | |
| 939 | if (!s) |
| 940 | { |
| 941 | ps = find_pc_psymtab (pc); |
| 942 | if (ps && ps->readin) |
| 943 | { |
| 944 | printf_filtered ("(Internal error: pc 0x%x in read in psymtab, but not in symtab.)\n", pc); |
| 945 | } |
| 946 | if (ps) |
| 947 | { |
| 948 | s = PSYMTAB_TO_SYMTAB (ps); |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | found: |
| 953 | return (s); |
| 954 | } |
| 955 | |
| 956 | /* Find the source file and line number for a given PC value. |
| 957 | Return a structure containing a symtab pointer, a line number, |
| 958 | and a pc range for the entire source line. |
| 959 | The value's .pc field is NOT the specified pc. |
| 960 | NOTCURRENT nonzero means, if specified pc is on a line boundary, |
| 961 | use the line that ends there. Otherwise, in that case, the line |
| 962 | that begins there is used. */ |
| 963 | |
| 964 | struct symtab_and_line |
| 965 | find_pc_line (pc, notcurrent) |
| 966 | CORE_ADDR pc; |
| 967 | int notcurrent; |
| 968 | { |
| 969 | struct symtab *s; |
| 970 | register struct linetable *l; |
| 971 | register int len; |
| 972 | register int i; |
| 973 | register struct linetable_entry *item; |
| 974 | struct symtab_and_line val; |
| 975 | struct blockvector *bv; |
| 976 | |
| 977 | /* Info on best line seen so far, and where it starts, and its file. */ |
| 978 | |
| 979 | int best_line = 0; |
| 980 | CORE_ADDR best_pc = 0; |
| 981 | CORE_ADDR best_end = 0; |
| 982 | struct symtab *best_symtab = 0; |
| 983 | |
| 984 | /* Store here the first line number |
| 985 | of a file which contains the line at the smallest pc after PC. |
| 986 | If we don't find a line whose range contains PC, |
| 987 | we will use a line one less than this, |
| 988 | with a range from the start of that file to the first line's pc. */ |
| 989 | int alt_line = 0; |
| 990 | CORE_ADDR alt_pc = 0; |
| 991 | struct symtab *alt_symtab = 0; |
| 992 | |
| 993 | /* Info on best line seen in this file. */ |
| 994 | |
| 995 | int prev_line; |
| 996 | CORE_ADDR prev_pc; |
| 997 | |
| 998 | /* Info on first line of this file. */ |
| 999 | |
| 1000 | int first_line; |
| 1001 | CORE_ADDR first_pc; |
| 1002 | |
| 1003 | /* If this pc is not from the current frame, |
| 1004 | it is the address of the end of a call instruction. |
| 1005 | Quite likely that is the start of the following statement. |
| 1006 | But what we want is the statement containing the instruction. |
| 1007 | Fudge the pc to make sure we get that. */ |
| 1008 | |
| 1009 | if (notcurrent) pc -= 1; |
| 1010 | |
| 1011 | s = find_pc_symtab (pc); |
| 1012 | if (s == 0) |
| 1013 | { |
| 1014 | val.symtab = 0; |
| 1015 | val.line = 0; |
| 1016 | val.pc = pc; |
| 1017 | val.end = 0; |
| 1018 | return val; |
| 1019 | } |
| 1020 | |
| 1021 | bv = BLOCKVECTOR (s); |
| 1022 | |
| 1023 | /* Look at all the symtabs that share this blockvector. |
| 1024 | They all have the same apriori range, that we found was right; |
| 1025 | but they have different line tables. */ |
| 1026 | |
| 1027 | for (; s && BLOCKVECTOR (s) == bv; s = s->next) |
| 1028 | { |
| 1029 | /* Find the best line in this symtab. */ |
| 1030 | l = LINETABLE (s); |
| 1031 | if (!l) |
| 1032 | continue; |
| 1033 | len = l->nitems; |
| 1034 | prev_line = -1; |
| 1035 | first_line = -1; |
| 1036 | for (i = 0; i < len; i++) |
| 1037 | { |
| 1038 | item = &(l->item[i]); |
| 1039 | |
| 1040 | if (first_line < 0) |
| 1041 | { |
| 1042 | first_line = item->line; |
| 1043 | first_pc = item->pc; |
| 1044 | } |
| 1045 | /* Return the last line that did not start after PC. */ |
| 1046 | if (pc >= item->pc) |
| 1047 | { |
| 1048 | prev_line = item->line; |
| 1049 | prev_pc = item->pc; |
| 1050 | } |
| 1051 | else |
| 1052 | break; |
| 1053 | } |
| 1054 | |
| 1055 | /* Is this file's best line closer than the best in the other files? |
| 1056 | If so, record this file, and its best line, as best so far. */ |
| 1057 | if (prev_line >= 0 && prev_pc > best_pc) |
| 1058 | { |
| 1059 | best_pc = prev_pc; |
| 1060 | best_line = prev_line; |
| 1061 | best_symtab = s; |
| 1062 | /* If another line is in the linetable, and its PC is closer |
| 1063 | than the best_end we currently have, take it as best_end. */ |
| 1064 | if (i < len && (best_end == 0 || best_end > item->pc)) |
| 1065 | best_end = item->pc; |
| 1066 | } |
| 1067 | /* Is this file's first line closer than the first lines of other files? |
| 1068 | If so, record this file, and its first line, as best alternate. */ |
| 1069 | if (first_line >= 0 && first_pc > pc |
| 1070 | && (alt_pc == 0 || first_pc < alt_pc)) |
| 1071 | { |
| 1072 | alt_pc = first_pc; |
| 1073 | alt_line = first_line; |
| 1074 | alt_symtab = s; |
| 1075 | } |
| 1076 | } |
| 1077 | if (best_symtab == 0) |
| 1078 | { |
| 1079 | val.symtab = alt_symtab; |
| 1080 | val.line = alt_line - 1; |
| 1081 | val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)); |
| 1082 | val.end = alt_pc; |
| 1083 | } |
| 1084 | else |
| 1085 | { |
| 1086 | val.symtab = best_symtab; |
| 1087 | val.line = best_line; |
| 1088 | val.pc = best_pc; |
| 1089 | if (best_end && (alt_pc == 0 || best_end < alt_pc)) |
| 1090 | val.end = best_end; |
| 1091 | else if (alt_pc) |
| 1092 | val.end = alt_pc; |
| 1093 | else |
| 1094 | val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)); |
| 1095 | } |
| 1096 | return val; |
| 1097 | } |
| 1098 | \f |
| 1099 | /* Find the PC value for a given source file and line number. |
| 1100 | Returns zero for invalid line number. |
| 1101 | The source file is specified with a struct symtab. */ |
| 1102 | |
| 1103 | CORE_ADDR |
| 1104 | find_line_pc (symtab, line) |
| 1105 | struct symtab *symtab; |
| 1106 | int line; |
| 1107 | { |
| 1108 | register struct linetable *l; |
| 1109 | register int ind; |
| 1110 | int dummy; |
| 1111 | |
| 1112 | if (symtab == 0) |
| 1113 | return 0; |
| 1114 | l = LINETABLE (symtab); |
| 1115 | ind = find_line_common(l, line, &dummy); |
| 1116 | return (ind >= 0) ? l->item[ind].pc : 0; |
| 1117 | } |
| 1118 | |
| 1119 | /* Find the range of pc values in a line. |
| 1120 | Store the starting pc of the line into *STARTPTR |
| 1121 | and the ending pc (start of next line) into *ENDPTR. |
| 1122 | Returns 1 to indicate success. |
| 1123 | Returns 0 if could not find the specified line. */ |
| 1124 | |
| 1125 | int |
| 1126 | find_line_pc_range (symtab, thisline, startptr, endptr) |
| 1127 | struct symtab *symtab; |
| 1128 | int thisline; |
| 1129 | CORE_ADDR *startptr, *endptr; |
| 1130 | { |
| 1131 | register struct linetable *l; |
| 1132 | register int ind; |
| 1133 | int exact_match; /* did we get an exact linenumber match */ |
| 1134 | |
| 1135 | if (symtab == 0) |
| 1136 | return 0; |
| 1137 | |
| 1138 | l = LINETABLE (symtab); |
| 1139 | ind = find_line_common (l, thisline, &exact_match); |
| 1140 | if (ind >= 0) |
| 1141 | { |
| 1142 | *startptr = l->item[ind].pc; |
| 1143 | /* If we have not seen an entry for the specified line, |
| 1144 | assume that means the specified line has zero bytes. */ |
| 1145 | if (!exact_match || ind == l->nitems-1) |
| 1146 | *endptr = *startptr; |
| 1147 | else |
| 1148 | /* Perhaps the following entry is for the following line. |
| 1149 | It's worth a try. */ |
| 1150 | if (ind+1 < l->nitems |
| 1151 | && l->item[ind+1].line == thisline + 1) |
| 1152 | *endptr = l->item[ind+1].pc; |
| 1153 | else |
| 1154 | *endptr = find_line_pc (symtab, thisline+1); |
| 1155 | return 1; |
| 1156 | } |
| 1157 | |
| 1158 | return 0; |
| 1159 | } |
| 1160 | |
| 1161 | /* Given a line table and a line number, return the index into the line |
| 1162 | table for the pc of the nearest line whose number is >= the specified one. |
| 1163 | Return -1 if none is found. The value is >= 0 if it is an index. |
| 1164 | |
| 1165 | Set *EXACT_MATCH nonzero if the value returned is an exact match. */ |
| 1166 | |
| 1167 | static int |
| 1168 | find_line_common (l, lineno, exact_match) |
| 1169 | register struct linetable *l; |
| 1170 | register int lineno; |
| 1171 | int *exact_match; |
| 1172 | { |
| 1173 | register int i; |
| 1174 | register int len; |
| 1175 | |
| 1176 | /* BEST is the smallest linenumber > LINENO so far seen, |
| 1177 | or 0 if none has been seen so far. |
| 1178 | BEST_INDEX identifies the item for it. */ |
| 1179 | |
| 1180 | int best_index = -1; |
| 1181 | int best = 0; |
| 1182 | |
| 1183 | if (lineno <= 0) |
| 1184 | return -1; |
| 1185 | if (l == 0) |
| 1186 | return -1; |
| 1187 | |
| 1188 | len = l->nitems; |
| 1189 | for (i = 0; i < len; i++) |
| 1190 | { |
| 1191 | register struct linetable_entry *item = &(l->item[i]); |
| 1192 | |
| 1193 | if (item->line == lineno) |
| 1194 | { |
| 1195 | *exact_match = 1; |
| 1196 | return i; |
| 1197 | } |
| 1198 | |
| 1199 | if (item->line > lineno && (best == 0 || item->line < best)) |
| 1200 | { |
| 1201 | best = item->line; |
| 1202 | best_index = i; |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | /* If we got here, we didn't get an exact match. */ |
| 1207 | |
| 1208 | *exact_match = 0; |
| 1209 | return best_index; |
| 1210 | } |
| 1211 | |
| 1212 | int |
| 1213 | find_pc_line_pc_range (pc, startptr, endptr) |
| 1214 | CORE_ADDR pc; |
| 1215 | CORE_ADDR *startptr, *endptr; |
| 1216 | { |
| 1217 | struct symtab_and_line sal; |
| 1218 | sal = find_pc_line (pc, 0); |
| 1219 | *startptr = sal.pc; |
| 1220 | *endptr = sal.end; |
| 1221 | return sal.symtab != 0; |
| 1222 | } |
| 1223 | \f |
| 1224 | /* If P is of the form "operator[ \t]+..." where `...' is |
| 1225 | some legitimate operator text, return a pointer to the |
| 1226 | beginning of the substring of the operator text. |
| 1227 | Otherwise, return "". */ |
| 1228 | static char * |
| 1229 | operator_chars (p, end) |
| 1230 | char *p; |
| 1231 | char **end; |
| 1232 | { |
| 1233 | *end = ""; |
| 1234 | if (strncmp (p, "operator", 8)) |
| 1235 | return *end; |
| 1236 | p += 8; |
| 1237 | |
| 1238 | /* Don't get faked out by `operator' being part of a longer |
| 1239 | identifier. */ |
| 1240 | if (isalpha(*p) || *p == '_' || *p == '$' || *p == '\0') |
| 1241 | return *end; |
| 1242 | |
| 1243 | /* Allow some whitespace between `operator' and the operator symbol. */ |
| 1244 | while (*p == ' ' || *p == '\t') |
| 1245 | p++; |
| 1246 | |
| 1247 | /* Recognize 'operator TYPENAME'. */ |
| 1248 | |
| 1249 | if (isalpha(*p) || *p == '_' || *p == '$') |
| 1250 | { |
| 1251 | register char *q = p+1; |
| 1252 | while (isalnum(*q) || *q == '_' || *q == '$') |
| 1253 | q++; |
| 1254 | *end = q; |
| 1255 | return p; |
| 1256 | } |
| 1257 | |
| 1258 | switch (*p) |
| 1259 | { |
| 1260 | case '!': |
| 1261 | case '=': |
| 1262 | case '*': |
| 1263 | case '/': |
| 1264 | case '%': |
| 1265 | case '^': |
| 1266 | if (p[1] == '=') |
| 1267 | *end = p+2; |
| 1268 | else |
| 1269 | *end = p+1; |
| 1270 | return p; |
| 1271 | case '<': |
| 1272 | case '>': |
| 1273 | case '+': |
| 1274 | case '-': |
| 1275 | case '&': |
| 1276 | case '|': |
| 1277 | if (p[1] == '=' || p[1] == p[0]) |
| 1278 | *end = p+2; |
| 1279 | else |
| 1280 | *end = p+1; |
| 1281 | return p; |
| 1282 | case '~': |
| 1283 | case ',': |
| 1284 | *end = p+1; |
| 1285 | return p; |
| 1286 | case '(': |
| 1287 | if (p[1] != ')') |
| 1288 | error ("`operator ()' must be specified without whitespace in `()'"); |
| 1289 | *end = p+2; |
| 1290 | return p; |
| 1291 | case '?': |
| 1292 | if (p[1] != ':') |
| 1293 | error ("`operator ?:' must be specified without whitespace in `?:'"); |
| 1294 | *end = p+2; |
| 1295 | return p; |
| 1296 | case '[': |
| 1297 | if (p[1] != ']') |
| 1298 | error ("`operator []' must be specified without whitespace in `[]'"); |
| 1299 | *end = p+2; |
| 1300 | return p; |
| 1301 | default: |
| 1302 | error ("`operator %s' not supported", p); |
| 1303 | break; |
| 1304 | } |
| 1305 | *end = ""; |
| 1306 | return *end; |
| 1307 | } |
| 1308 | |
| 1309 | /* Recursive helper function for decode_line_1. |
| 1310 | * Look for methods named NAME in type T. |
| 1311 | * Return number of matches. |
| 1312 | * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!). |
| 1313 | * These allocations seem to define "big enough": |
| 1314 | * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*)); |
| 1315 | * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*)); |
| 1316 | */ |
| 1317 | |
| 1318 | int |
| 1319 | find_methods (t, name, physnames, sym_arr) |
| 1320 | struct type *t; |
| 1321 | char *name; |
| 1322 | char **physnames; |
| 1323 | struct symbol **sym_arr; |
| 1324 | { |
| 1325 | int i1 = 0; |
| 1326 | int ibase; |
| 1327 | struct symbol *sym_class; |
| 1328 | char *class_name = type_name_no_tag (t); |
| 1329 | /* Ignore this class if it doesn't have a name. |
| 1330 | This prevents core dumps, but is just a workaround |
| 1331 | because we might not find the function in |
| 1332 | certain cases, such as |
| 1333 | struct D {virtual int f();} |
| 1334 | struct C : D {virtual int g();} |
| 1335 | (in this case g++ 1.35.1- does not put out a name |
| 1336 | for D as such, it defines type 19 (for example) in |
| 1337 | the same stab as C, and then does a |
| 1338 | .stabs "D:T19" and a .stabs "D:t19". |
| 1339 | Thus |
| 1340 | "break C::f" should not be looking for field f in |
| 1341 | the class named D, |
| 1342 | but just for the field f in the baseclasses of C |
| 1343 | (no matter what their names). |
| 1344 | |
| 1345 | However, I don't know how to replace the code below |
| 1346 | that depends on knowing the name of D. */ |
| 1347 | if (class_name |
| 1348 | && (sym_class = lookup_symbol (class_name, |
| 1349 | (struct block *)NULL, |
| 1350 | STRUCT_NAMESPACE, |
| 1351 | (int *)NULL, |
| 1352 | (struct symtab **)NULL))) |
| 1353 | { |
| 1354 | int method_counter; |
| 1355 | t = SYMBOL_TYPE (sym_class); |
| 1356 | for (method_counter = TYPE_NFN_FIELDS (t) - 1; |
| 1357 | method_counter >= 0; |
| 1358 | --method_counter) |
| 1359 | { |
| 1360 | int field_counter; |
| 1361 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, method_counter); |
| 1362 | |
| 1363 | char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter); |
| 1364 | if (!strcmp (name, method_name)) |
| 1365 | /* Find all the fields with that name. */ |
| 1366 | for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1; |
| 1367 | field_counter >= 0; |
| 1368 | --field_counter) |
| 1369 | { |
| 1370 | char *phys_name; |
| 1371 | if (TYPE_FN_FIELD_STUB (f, field_counter)) |
| 1372 | check_stub_method (t, method_counter, field_counter); |
| 1373 | phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter); |
| 1374 | physnames[i1] = (char*) alloca (strlen (phys_name) + 1); |
| 1375 | strcpy (physnames[i1], phys_name); |
| 1376 | sym_arr[i1] = lookup_symbol (phys_name, |
| 1377 | SYMBOL_BLOCK_VALUE (sym_class), |
| 1378 | VAR_NAMESPACE, |
| 1379 | (int *) NULL, |
| 1380 | (struct symtab **) NULL); |
| 1381 | if (sym_arr[i1]) i1++; |
| 1382 | else |
| 1383 | { |
| 1384 | fputs_filtered("(Cannot find method ", stdout); |
| 1385 | fputs_demangled(phys_name, stdout, DMGL_PARAMS); |
| 1386 | fputs_filtered(" - possibly inlined.)\n", stdout); |
| 1387 | } |
| 1388 | } |
| 1389 | } |
| 1390 | } |
| 1391 | /* Only search baseclasses if there is no match yet, |
| 1392 | * since names in derived classes override those in baseclasses. |
| 1393 | */ |
| 1394 | if (i1) |
| 1395 | return i1; |
| 1396 | for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++) |
| 1397 | i1 += find_methods(TYPE_BASECLASS(t, ibase), name, |
| 1398 | physnames + i1, sym_arr + i1); |
| 1399 | return i1; |
| 1400 | } |
| 1401 | |
| 1402 | /* Parse a string that specifies a line number. |
| 1403 | Pass the address of a char * variable; that variable will be |
| 1404 | advanced over the characters actually parsed. |
| 1405 | |
| 1406 | The string can be: |
| 1407 | |
| 1408 | LINENUM -- that line number in current file. PC returned is 0. |
| 1409 | FILE:LINENUM -- that line in that file. PC returned is 0. |
| 1410 | FUNCTION -- line number of openbrace of that function. |
| 1411 | PC returned is the start of the function. |
| 1412 | VARIABLE -- line number of definition of that variable. |
| 1413 | PC returned is 0. |
| 1414 | FILE:FUNCTION -- likewise, but prefer functions in that file. |
| 1415 | *EXPR -- line in which address EXPR appears. |
| 1416 | |
| 1417 | FUNCTION may be an undebuggable function found in minimal symbol table. |
| 1418 | |
| 1419 | If the argument FUNFIRSTLINE is nonzero, we want the first line |
| 1420 | of real code inside a function when a function is specified. |
| 1421 | |
| 1422 | DEFAULT_SYMTAB specifies the file to use if none is specified. |
| 1423 | It defaults to current_source_symtab. |
| 1424 | DEFAULT_LINE specifies the line number to use for relative |
| 1425 | line numbers (that start with signs). Defaults to current_source_line. |
| 1426 | |
| 1427 | Note that it is possible to return zero for the symtab |
| 1428 | if no file is validly specified. Callers must check that. |
| 1429 | Also, the line number returned may be invalid. */ |
| 1430 | |
| 1431 | struct symtabs_and_lines |
| 1432 | decode_line_1 (argptr, funfirstline, default_symtab, default_line) |
| 1433 | char **argptr; |
| 1434 | int funfirstline; |
| 1435 | struct symtab *default_symtab; |
| 1436 | int default_line; |
| 1437 | { |
| 1438 | struct symtabs_and_lines values; |
| 1439 | struct symtab_and_line val; |
| 1440 | register char *p, *p1; |
| 1441 | char *q, *q1; |
| 1442 | register struct symtab *s; |
| 1443 | |
| 1444 | register struct symbol *sym; |
| 1445 | /* The symtab that SYM was found in. */ |
| 1446 | struct symtab *sym_symtab; |
| 1447 | |
| 1448 | register CORE_ADDR pc; |
| 1449 | register struct minimal_symbol *msymbol; |
| 1450 | char *copy; |
| 1451 | struct symbol *sym_class; |
| 1452 | int i1; |
| 1453 | int is_quoted; |
| 1454 | struct symbol **sym_arr; |
| 1455 | struct type *t; |
| 1456 | char **physnames; |
| 1457 | char *saved_arg = *argptr; |
| 1458 | extern char *gdb_completer_quote_characters; |
| 1459 | |
| 1460 | /* Defaults have defaults. */ |
| 1461 | |
| 1462 | if (default_symtab == 0) |
| 1463 | { |
| 1464 | default_symtab = current_source_symtab; |
| 1465 | default_line = current_source_line; |
| 1466 | } |
| 1467 | |
| 1468 | /* See if arg is *PC */ |
| 1469 | |
| 1470 | if (**argptr == '*') |
| 1471 | { |
| 1472 | if (**argptr == '*') |
| 1473 | { |
| 1474 | (*argptr)++; |
| 1475 | } |
| 1476 | pc = parse_and_eval_address_1 (argptr); |
| 1477 | values.sals = (struct symtab_and_line *) |
| 1478 | xmalloc (sizeof (struct symtab_and_line)); |
| 1479 | values.nelts = 1; |
| 1480 | values.sals[0] = find_pc_line (pc, 0); |
| 1481 | values.sals[0].pc = pc; |
| 1482 | return values; |
| 1483 | } |
| 1484 | |
| 1485 | /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */ |
| 1486 | |
| 1487 | s = NULL; |
| 1488 | is_quoted = (strchr (gdb_completer_quote_characters, **argptr) != NULL); |
| 1489 | |
| 1490 | for (p = *argptr; *p; p++) |
| 1491 | { |
| 1492 | if (p[0] == ':' || p[0] == ' ' || p[0] == '\t') |
| 1493 | break; |
| 1494 | } |
| 1495 | while (p[0] == ' ' || p[0] == '\t') p++; |
| 1496 | |
| 1497 | if ((p[0] == ':') && !is_quoted) |
| 1498 | { |
| 1499 | |
| 1500 | /* C++ */ |
| 1501 | if (p[1] ==':') |
| 1502 | { |
| 1503 | /* Extract the class name. */ |
| 1504 | p1 = p; |
| 1505 | while (p != *argptr && p[-1] == ' ') --p; |
| 1506 | copy = (char *) alloca (p - *argptr + 1); |
| 1507 | memcpy (copy, *argptr, p - *argptr); |
| 1508 | copy[p - *argptr] = 0; |
| 1509 | |
| 1510 | /* Discard the class name from the arg. */ |
| 1511 | p = p1 + 2; |
| 1512 | while (*p == ' ' || *p == '\t') p++; |
| 1513 | *argptr = p; |
| 1514 | |
| 1515 | sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0, |
| 1516 | (struct symtab **)NULL); |
| 1517 | |
| 1518 | if (sym_class && |
| 1519 | ( TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_STRUCT |
| 1520 | || TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_UNION)) |
| 1521 | { |
| 1522 | /* Arg token is not digits => try it as a function name |
| 1523 | Find the next token (everything up to end or next whitespace). */ |
| 1524 | p = *argptr; |
| 1525 | while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p !=':') p++; |
| 1526 | q = operator_chars (*argptr, &q1); |
| 1527 | |
| 1528 | if (q1 - q) |
| 1529 | { |
| 1530 | char *opname; |
| 1531 | char *tmp = alloca (q1 - q + 1); |
| 1532 | memcpy (tmp, q, q1 - q); |
| 1533 | tmp[q1 - q] = '\0'; |
| 1534 | opname = cplus_mangle_opname (tmp, DMGL_ANSI); |
| 1535 | if (opname == NULL) |
| 1536 | { |
| 1537 | warning ("no mangling for \"%s\"", tmp); |
| 1538 | cplusplus_hint (saved_arg); |
| 1539 | return_to_top_level (); |
| 1540 | } |
| 1541 | copy = (char*) alloca (3 + strlen(opname)); |
| 1542 | sprintf (copy, "__%s", opname); |
| 1543 | p = q1; |
| 1544 | } |
| 1545 | else |
| 1546 | { |
| 1547 | copy = (char *) alloca (p - *argptr + 1 + (q1 - q)); |
| 1548 | memcpy (copy, *argptr, p - *argptr); |
| 1549 | copy[p - *argptr] = '\0'; |
| 1550 | } |
| 1551 | |
| 1552 | /* no line number may be specified */ |
| 1553 | while (*p == ' ' || *p == '\t') p++; |
| 1554 | *argptr = p; |
| 1555 | |
| 1556 | sym = 0; |
| 1557 | i1 = 0; /* counter for the symbol array */ |
| 1558 | t = SYMBOL_TYPE (sym_class); |
| 1559 | sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*)); |
| 1560 | physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*)); |
| 1561 | |
| 1562 | if (destructor_name_p (copy, t)) |
| 1563 | { |
| 1564 | /* destructors are a special case. */ |
| 1565 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, 0); |
| 1566 | int len = TYPE_FN_FIELDLIST_LENGTH (t, 0) - 1; |
| 1567 | char *phys_name = TYPE_FN_FIELD_PHYSNAME (f, len); |
| 1568 | physnames[i1] = (char *)alloca (strlen (phys_name) + 1); |
| 1569 | strcpy (physnames[i1], phys_name); |
| 1570 | sym_arr[i1] = |
| 1571 | lookup_symbol (phys_name, SYMBOL_BLOCK_VALUE (sym_class), |
| 1572 | VAR_NAMESPACE, 0, (struct symtab **)NULL); |
| 1573 | if (sym_arr[i1]) i1++; |
| 1574 | } |
| 1575 | else |
| 1576 | i1 = find_methods (t, copy, physnames, sym_arr); |
| 1577 | if (i1 == 1) |
| 1578 | { |
| 1579 | /* There is exactly one field with that name. */ |
| 1580 | sym = sym_arr[0]; |
| 1581 | |
| 1582 | if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) |
| 1583 | { |
| 1584 | /* Arg is the name of a function */ |
| 1585 | pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET; |
| 1586 | if (funfirstline) |
| 1587 | SKIP_PROLOGUE (pc); |
| 1588 | values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line)); |
| 1589 | values.nelts = 1; |
| 1590 | values.sals[0] = find_pc_line (pc, 0); |
| 1591 | values.sals[0].pc = (values.sals[0].end && values.sals[0].pc != pc) ? values.sals[0].end : pc; |
| 1592 | } |
| 1593 | else |
| 1594 | { |
| 1595 | values.nelts = 0; |
| 1596 | } |
| 1597 | return values; |
| 1598 | } |
| 1599 | if (i1 > 0) |
| 1600 | { |
| 1601 | /* There is more than one field with that name |
| 1602 | (overloaded). Ask the user which one to use. */ |
| 1603 | return decode_line_2 (sym_arr, i1, funfirstline); |
| 1604 | } |
| 1605 | else |
| 1606 | { |
| 1607 | char *tmp; |
| 1608 | |
| 1609 | if (OPNAME_PREFIX_P (copy)) |
| 1610 | { |
| 1611 | tmp = (char *)alloca (strlen (copy+3) + 9); |
| 1612 | strcpy (tmp, "operator "); |
| 1613 | strcat (tmp, copy+3); |
| 1614 | } |
| 1615 | else |
| 1616 | tmp = copy; |
| 1617 | if (tmp[0] == '~') |
| 1618 | warning ("the class `%s' does not have destructor defined", |
| 1619 | sym_class->name); |
| 1620 | else |
| 1621 | warning ("the class %s does not have any method named %s", |
| 1622 | sym_class->name, tmp); |
| 1623 | cplusplus_hint (saved_arg); |
| 1624 | return_to_top_level (); |
| 1625 | } |
| 1626 | } |
| 1627 | else |
| 1628 | { |
| 1629 | /* The quotes are important if copy is empty. */ |
| 1630 | warning ("can't find class, struct, or union named \"%s\"", |
| 1631 | copy); |
| 1632 | cplusplus_hint (saved_arg); |
| 1633 | return_to_top_level (); |
| 1634 | } |
| 1635 | } |
| 1636 | /* end of C++ */ |
| 1637 | |
| 1638 | |
| 1639 | /* Extract the file name. */ |
| 1640 | p1 = p; |
| 1641 | while (p != *argptr && p[-1] == ' ') --p; |
| 1642 | copy = (char *) alloca (p - *argptr + 1); |
| 1643 | memcpy (copy, *argptr, p - *argptr); |
| 1644 | copy[p - *argptr] = 0; |
| 1645 | |
| 1646 | /* Find that file's data. */ |
| 1647 | s = lookup_symtab (copy); |
| 1648 | if (s == 0) |
| 1649 | { |
| 1650 | if (!have_full_symbols () && !have_partial_symbols ()) |
| 1651 | error (no_symtab_msg); |
| 1652 | error ("No source file named %s.", copy); |
| 1653 | } |
| 1654 | |
| 1655 | /* Discard the file name from the arg. */ |
| 1656 | p = p1 + 1; |
| 1657 | while (*p == ' ' || *p == '\t') p++; |
| 1658 | *argptr = p; |
| 1659 | } |
| 1660 | |
| 1661 | /* S is specified file's symtab, or 0 if no file specified. |
| 1662 | arg no longer contains the file name. */ |
| 1663 | |
| 1664 | /* Check whether arg is all digits (and sign) */ |
| 1665 | |
| 1666 | p = *argptr; |
| 1667 | if (*p == '-' || *p == '+') p++; |
| 1668 | while (*p >= '0' && *p <= '9') |
| 1669 | p++; |
| 1670 | |
| 1671 | if (p != *argptr && (*p == 0 || *p == ' ' || *p == '\t' || *p == ',')) |
| 1672 | { |
| 1673 | /* We found a token consisting of all digits -- at least one digit. */ |
| 1674 | enum sign {none, plus, minus} sign = none; |
| 1675 | |
| 1676 | /* This is where we need to make sure that we have good defaults. |
| 1677 | We must guarantee that this section of code is never executed |
| 1678 | when we are called with just a function name, since |
| 1679 | select_source_symtab calls us with such an argument */ |
| 1680 | |
| 1681 | if (s == 0 && default_symtab == 0) |
| 1682 | { |
| 1683 | select_source_symtab (0); |
| 1684 | default_symtab = current_source_symtab; |
| 1685 | default_line = current_source_line; |
| 1686 | } |
| 1687 | |
| 1688 | if (**argptr == '+') |
| 1689 | sign = plus, (*argptr)++; |
| 1690 | else if (**argptr == '-') |
| 1691 | sign = minus, (*argptr)++; |
| 1692 | val.line = atoi (*argptr); |
| 1693 | switch (sign) |
| 1694 | { |
| 1695 | case plus: |
| 1696 | if (p == *argptr) |
| 1697 | val.line = 5; |
| 1698 | if (s == 0) |
| 1699 | val.line = default_line + val.line; |
| 1700 | break; |
| 1701 | case minus: |
| 1702 | if (p == *argptr) |
| 1703 | val.line = 15; |
| 1704 | if (s == 0) |
| 1705 | val.line = default_line - val.line; |
| 1706 | else |
| 1707 | val.line = 1; |
| 1708 | break; |
| 1709 | case none: |
| 1710 | break; /* No need to adjust val.line. */ |
| 1711 | } |
| 1712 | |
| 1713 | while (*p == ' ' || *p == '\t') p++; |
| 1714 | *argptr = p; |
| 1715 | if (s == 0) |
| 1716 | s = default_symtab; |
| 1717 | val.symtab = s; |
| 1718 | val.pc = 0; |
| 1719 | values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line)); |
| 1720 | values.sals[0] = val; |
| 1721 | values.nelts = 1; |
| 1722 | return values; |
| 1723 | } |
| 1724 | |
| 1725 | /* Arg token is not digits => try it as a variable name |
| 1726 | Find the next token (everything up to end or next whitespace). */ |
| 1727 | |
| 1728 | p = skip_quoted (*argptr); |
| 1729 | copy = (char *) alloca (p - *argptr + 1); |
| 1730 | memcpy (copy, *argptr, p - *argptr); |
| 1731 | copy[p - *argptr] = '\0'; |
| 1732 | if ((copy[0] == copy [p - *argptr - 1]) |
| 1733 | && strchr (gdb_completer_quote_characters, copy[0]) != NULL) |
| 1734 | { |
| 1735 | char *temp; |
| 1736 | copy [p - *argptr - 1] = '\0'; |
| 1737 | copy++; |
| 1738 | if ((temp = expensive_mangler (copy)) != NULL) |
| 1739 | { |
| 1740 | copy = temp; |
| 1741 | } |
| 1742 | } |
| 1743 | while (*p == ' ' || *p == '\t') p++; |
| 1744 | *argptr = p; |
| 1745 | |
| 1746 | /* Look up that token as a variable. |
| 1747 | If file specified, use that file's per-file block to start with. */ |
| 1748 | |
| 1749 | sym = lookup_symbol (copy, |
| 1750 | (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) |
| 1751 | : get_selected_block ()), |
| 1752 | VAR_NAMESPACE, 0, &sym_symtab); |
| 1753 | |
| 1754 | if (sym != NULL) |
| 1755 | { |
| 1756 | if (SYMBOL_CLASS (sym) == LOC_BLOCK) |
| 1757 | { |
| 1758 | /* Arg is the name of a function */ |
| 1759 | pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET; |
| 1760 | if (funfirstline) |
| 1761 | SKIP_PROLOGUE (pc); |
| 1762 | val = find_pc_line (pc, 0); |
| 1763 | #ifdef PROLOGUE_FIRSTLINE_OVERLAP |
| 1764 | /* Convex: no need to suppress code on first line, if any */ |
| 1765 | val.pc = pc; |
| 1766 | #else |
| 1767 | /* If SKIP_PROLOGUE left us in mid-line, and the next line is still |
| 1768 | part of the same function: |
| 1769 | advance to next line, |
| 1770 | recalculate its line number (might not be N+1). */ |
| 1771 | if (val.pc != pc && val.end && |
| 1772 | lookup_minimal_symbol_by_pc (pc) == lookup_minimal_symbol_by_pc (val.end)) { |
| 1773 | pc = val.end; /* First pc of next line */ |
| 1774 | val = find_pc_line (pc, 0); |
| 1775 | } |
| 1776 | val.pc = pc; |
| 1777 | #endif |
| 1778 | values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line)); |
| 1779 | values.sals[0] = val; |
| 1780 | values.nelts = 1; |
| 1781 | |
| 1782 | /* I think this is always the same as the line that |
| 1783 | we calculate above, but the general principle is |
| 1784 | "trust the symbols more than stuff like |
| 1785 | SKIP_PROLOGUE". */ |
| 1786 | if (SYMBOL_LINE (sym) != 0) |
| 1787 | values.sals[0].line = SYMBOL_LINE (sym); |
| 1788 | |
| 1789 | return values; |
| 1790 | } |
| 1791 | else if (SYMBOL_LINE (sym) != 0) |
| 1792 | { |
| 1793 | /* We know its line number. */ |
| 1794 | values.sals = (struct symtab_and_line *) |
| 1795 | xmalloc (sizeof (struct symtab_and_line)); |
| 1796 | values.nelts = 1; |
| 1797 | memset (&values.sals[0], 0, sizeof (values.sals[0])); |
| 1798 | values.sals[0].symtab = sym_symtab; |
| 1799 | values.sals[0].line = SYMBOL_LINE (sym); |
| 1800 | return values; |
| 1801 | } |
| 1802 | else |
| 1803 | /* This can happen if it is compiled with a compiler which doesn't |
| 1804 | put out line numbers for variables. */ |
| 1805 | error ("Line number not known for symbol \"%s\"", copy); |
| 1806 | } |
| 1807 | |
| 1808 | msymbol = lookup_minimal_symbol (copy, (struct objfile *) NULL); |
| 1809 | if (msymbol != NULL) |
| 1810 | { |
| 1811 | val.symtab = 0; |
| 1812 | val.line = 0; |
| 1813 | val.pc = msymbol -> address + FUNCTION_START_OFFSET; |
| 1814 | if (funfirstline) |
| 1815 | SKIP_PROLOGUE (val.pc); |
| 1816 | values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line)); |
| 1817 | values.sals[0] = val; |
| 1818 | values.nelts = 1; |
| 1819 | return values; |
| 1820 | } |
| 1821 | |
| 1822 | if (!have_full_symbols () && |
| 1823 | !have_partial_symbols () && !have_minimal_symbols ()) |
| 1824 | error (no_symtab_msg); |
| 1825 | |
| 1826 | error ("Function \"%s\" not defined.", copy); |
| 1827 | return values; /* for lint */ |
| 1828 | } |
| 1829 | |
| 1830 | struct symtabs_and_lines |
| 1831 | decode_line_spec (string, funfirstline) |
| 1832 | char *string; |
| 1833 | int funfirstline; |
| 1834 | { |
| 1835 | struct symtabs_and_lines sals; |
| 1836 | if (string == 0) |
| 1837 | error ("Empty line specification."); |
| 1838 | sals = decode_line_1 (&string, funfirstline, |
| 1839 | current_source_symtab, current_source_line); |
| 1840 | if (*string) |
| 1841 | error ("Junk at end of line specification: %s", string); |
| 1842 | return sals; |
| 1843 | } |
| 1844 | |
| 1845 | /* Given a list of NELTS symbols in sym_arr (with corresponding |
| 1846 | mangled names in physnames), return a list of lines to operate on |
| 1847 | (ask user if necessary). */ |
| 1848 | static struct symtabs_and_lines |
| 1849 | decode_line_2 (sym_arr, nelts, funfirstline) |
| 1850 | struct symbol *sym_arr[]; |
| 1851 | int nelts; |
| 1852 | int funfirstline; |
| 1853 | { |
| 1854 | struct symtabs_and_lines values, return_values; |
| 1855 | register CORE_ADDR pc; |
| 1856 | char *args, *arg1; |
| 1857 | int i; |
| 1858 | char *prompt; |
| 1859 | char *demangled; |
| 1860 | |
| 1861 | values.sals = (struct symtab_and_line *) alloca (nelts * sizeof(struct symtab_and_line)); |
| 1862 | return_values.sals = (struct symtab_and_line *) xmalloc (nelts * sizeof(struct symtab_and_line)); |
| 1863 | |
| 1864 | i = 0; |
| 1865 | printf("[0] cancel\n[1] all\n"); |
| 1866 | while (i < nelts) |
| 1867 | { |
| 1868 | if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK) |
| 1869 | { |
| 1870 | /* Arg is the name of a function */ |
| 1871 | pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr[i])) |
| 1872 | + FUNCTION_START_OFFSET; |
| 1873 | if (funfirstline) |
| 1874 | SKIP_PROLOGUE (pc); |
| 1875 | values.sals[i] = find_pc_line (pc, 0); |
| 1876 | values.sals[i].pc = (values.sals[i].end && values.sals[i].pc != pc) ? |
| 1877 | values.sals[i].end : pc; |
| 1878 | demangled = cplus_demangle (SYMBOL_NAME (sym_arr[i]), |
| 1879 | DMGL_PARAMS | DMGL_ANSI); |
| 1880 | printf("[%d] %s at %s:%d\n", (i+2), |
| 1881 | demangled ? demangled : SYMBOL_NAME (sym_arr[i]), |
| 1882 | values.sals[i].symtab->filename, values.sals[i].line); |
| 1883 | if (demangled != NULL) |
| 1884 | { |
| 1885 | free (demangled); |
| 1886 | } |
| 1887 | } |
| 1888 | else printf ("?HERE\n"); |
| 1889 | i++; |
| 1890 | } |
| 1891 | |
| 1892 | if ((prompt = getenv ("PS2")) == NULL) |
| 1893 | { |
| 1894 | prompt = ">"; |
| 1895 | } |
| 1896 | printf("%s ",prompt); |
| 1897 | fflush(stdout); |
| 1898 | |
| 1899 | args = command_line_input ((char *) NULL, 0); |
| 1900 | |
| 1901 | if (args == 0) |
| 1902 | error_no_arg ("one or more choice numbers"); |
| 1903 | |
| 1904 | i = 0; |
| 1905 | while (*args) |
| 1906 | { |
| 1907 | int num; |
| 1908 | |
| 1909 | arg1 = args; |
| 1910 | while (*arg1 >= '0' && *arg1 <= '9') arg1++; |
| 1911 | if (*arg1 && *arg1 != ' ' && *arg1 != '\t') |
| 1912 | error ("Arguments must be choice numbers."); |
| 1913 | |
| 1914 | num = atoi (args); |
| 1915 | |
| 1916 | if (num == 0) |
| 1917 | error ("cancelled"); |
| 1918 | else if (num == 1) |
| 1919 | { |
| 1920 | memcpy (return_values.sals, values.sals, |
| 1921 | (nelts * sizeof(struct symtab_and_line))); |
| 1922 | return_values.nelts = nelts; |
| 1923 | return return_values; |
| 1924 | } |
| 1925 | |
| 1926 | if (num > nelts + 2) |
| 1927 | { |
| 1928 | printf ("No choice number %d.\n", num); |
| 1929 | } |
| 1930 | else |
| 1931 | { |
| 1932 | num -= 2; |
| 1933 | if (values.sals[num].pc) |
| 1934 | { |
| 1935 | return_values.sals[i++] = values.sals[num]; |
| 1936 | values.sals[num].pc = 0; |
| 1937 | } |
| 1938 | else |
| 1939 | { |
| 1940 | printf ("duplicate request for %d ignored.\n", num); |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | args = arg1; |
| 1945 | while (*args == ' ' || *args == '\t') args++; |
| 1946 | } |
| 1947 | return_values.nelts = i; |
| 1948 | return return_values; |
| 1949 | } |
| 1950 | |
| 1951 | \f |
| 1952 | /* Slave routine for sources_info. Force line breaks at ,'s. |
| 1953 | NAME is the name to print and *FIRST is nonzero if this is the first |
| 1954 | name printed. Set *FIRST to zero. */ |
| 1955 | static void |
| 1956 | output_source_filename (name, first) |
| 1957 | char *name; |
| 1958 | int *first; |
| 1959 | { |
| 1960 | /* Table of files printed so far. Since a single source file can |
| 1961 | result in several partial symbol tables, we need to avoid printing |
| 1962 | it more than once. Note: if some of the psymtabs are read in and |
| 1963 | some are not, it gets printed both under "Source files for which |
| 1964 | symbols have been read" and "Source files for which symbols will |
| 1965 | be read in on demand". I consider this a reasonable way to deal |
| 1966 | with the situation. I'm not sure whether this can also happen for |
| 1967 | symtabs; it doesn't hurt to check. */ |
| 1968 | static char **tab = NULL; |
| 1969 | /* Allocated size of tab in elements. |
| 1970 | Start with one 256-byte block (when using GNU malloc.c). |
| 1971 | 24 is the malloc overhead when range checking is in effect. */ |
| 1972 | static int tab_alloc_size = (256 - 24) / sizeof (char *); |
| 1973 | /* Current size of tab in elements. */ |
| 1974 | static int tab_cur_size; |
| 1975 | |
| 1976 | char **p; |
| 1977 | |
| 1978 | if (*first) |
| 1979 | { |
| 1980 | if (tab == NULL) |
| 1981 | tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab)); |
| 1982 | tab_cur_size = 0; |
| 1983 | } |
| 1984 | |
| 1985 | /* Is NAME in tab? */ |
| 1986 | for (p = tab; p < tab + tab_cur_size; p++) |
| 1987 | if (strcmp (*p, name) == 0) |
| 1988 | /* Yes; don't print it again. */ |
| 1989 | return; |
| 1990 | /* No; add it to tab. */ |
| 1991 | if (tab_cur_size == tab_alloc_size) |
| 1992 | { |
| 1993 | tab_alloc_size *= 2; |
| 1994 | tab = (char **) xrealloc ((char *) tab, tab_alloc_size * sizeof (*tab)); |
| 1995 | } |
| 1996 | tab[tab_cur_size++] = name; |
| 1997 | |
| 1998 | if (*first) |
| 1999 | { |
| 2000 | *first = 0; |
| 2001 | } |
| 2002 | else |
| 2003 | { |
| 2004 | printf_filtered (", "); |
| 2005 | } |
| 2006 | |
| 2007 | wrap_here (""); |
| 2008 | fputs_filtered (name, stdout); |
| 2009 | } |
| 2010 | |
| 2011 | static void |
| 2012 | sources_info (ignore, from_tty) |
| 2013 | char *ignore; |
| 2014 | int from_tty; |
| 2015 | { |
| 2016 | register struct symtab *s; |
| 2017 | register struct partial_symtab *ps; |
| 2018 | register struct objfile *objfile; |
| 2019 | int first; |
| 2020 | |
| 2021 | if (!have_full_symbols () && !have_partial_symbols ()) |
| 2022 | { |
| 2023 | error (no_symtab_msg); |
| 2024 | } |
| 2025 | |
| 2026 | printf_filtered ("Source files for which symbols have been read in:\n\n"); |
| 2027 | |
| 2028 | first = 1; |
| 2029 | ALL_SYMTABS (objfile, s) |
| 2030 | { |
| 2031 | output_source_filename (s -> filename, &first); |
| 2032 | } |
| 2033 | printf_filtered ("\n\n"); |
| 2034 | |
| 2035 | printf_filtered ("Source files for which symbols will be read in on demand:\n\n"); |
| 2036 | |
| 2037 | first = 1; |
| 2038 | ALL_PSYMTABS (objfile, ps) |
| 2039 | { |
| 2040 | if (!ps->readin) |
| 2041 | { |
| 2042 | output_source_filename (ps -> filename, &first); |
| 2043 | } |
| 2044 | } |
| 2045 | printf_filtered ("\n"); |
| 2046 | } |
| 2047 | |
| 2048 | static int |
| 2049 | name_match (name) |
| 2050 | char *name; |
| 2051 | { |
| 2052 | char *demangled = cplus_demangle (name, DMGL_ANSI); |
| 2053 | if (demangled != NULL) |
| 2054 | { |
| 2055 | int cond = re_exec (demangled); |
| 2056 | free (demangled); |
| 2057 | return (cond); |
| 2058 | } |
| 2059 | return (re_exec (name)); |
| 2060 | } |
| 2061 | #define NAME_MATCH(NAME) name_match(NAME) |
| 2062 | |
| 2063 | /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP. |
| 2064 | If CLASS is zero, list all symbols except functions, type names, and |
| 2065 | constants (enums). |
| 2066 | If CLASS is 1, list only functions. |
| 2067 | If CLASS is 2, list only type names. |
| 2068 | If CLASS is 3, list only method names. |
| 2069 | |
| 2070 | BPT is non-zero if we should set a breakpoint at the functions |
| 2071 | we find. */ |
| 2072 | |
| 2073 | static void |
| 2074 | list_symbols (regexp, class, bpt) |
| 2075 | char *regexp; |
| 2076 | int class; |
| 2077 | int bpt; |
| 2078 | { |
| 2079 | register struct symtab *s; |
| 2080 | register struct partial_symtab *ps; |
| 2081 | register struct blockvector *bv; |
| 2082 | struct blockvector *prev_bv = 0; |
| 2083 | register struct block *b; |
| 2084 | register int i, j; |
| 2085 | register struct symbol *sym; |
| 2086 | struct partial_symbol *psym; |
| 2087 | struct objfile *objfile; |
| 2088 | struct minimal_symbol *msymbol; |
| 2089 | char *val; |
| 2090 | static char *classnames[] |
| 2091 | = {"variable", "function", "type", "method"}; |
| 2092 | int found_in_file = 0; |
| 2093 | int found_misc = 0; |
| 2094 | static enum minimal_symbol_type types[] |
| 2095 | = {mst_data, mst_text, mst_abs, mst_unknown}; |
| 2096 | static enum minimal_symbol_type types2[] |
| 2097 | = {mst_bss, mst_text, mst_abs, mst_unknown}; |
| 2098 | enum minimal_symbol_type ourtype = types[class]; |
| 2099 | enum minimal_symbol_type ourtype2 = types2[class]; |
| 2100 | |
| 2101 | if (regexp) |
| 2102 | { |
| 2103 | /* Make sure spacing is right for C++ operators. |
| 2104 | This is just a courtesy to make the matching less sensitive |
| 2105 | to how many spaces the user leaves between 'operator' |
| 2106 | and <TYPENAME> or <OPERATOR>. */ |
| 2107 | char *opend; |
| 2108 | char *opname = operator_chars (regexp, &opend); |
| 2109 | if (*opname) |
| 2110 | { |
| 2111 | int fix = -1; /* -1 means ok; otherwise number of spaces needed. */ |
| 2112 | if (isalpha(*opname) || *opname == '_' || *opname == '$') |
| 2113 | { |
| 2114 | /* There should 1 space between 'operator' and 'TYPENAME'. */ |
| 2115 | if (opname[-1] != ' ' || opname[-2] == ' ') |
| 2116 | fix = 1; |
| 2117 | } |
| 2118 | else |
| 2119 | { |
| 2120 | /* There should 0 spaces between 'operator' and 'OPERATOR'. */ |
| 2121 | if (opname[-1] == ' ') |
| 2122 | fix = 0; |
| 2123 | } |
| 2124 | /* If wrong number of spaces, fix it. */ |
| 2125 | if (fix >= 0) |
| 2126 | { |
| 2127 | char *tmp = (char*) alloca(opend-opname+10); |
| 2128 | sprintf(tmp, "operator%.*s%s", fix, " ", opname); |
| 2129 | regexp = tmp; |
| 2130 | } |
| 2131 | } |
| 2132 | |
| 2133 | if (0 != (val = re_comp (regexp))) |
| 2134 | error ("Invalid regexp (%s): %s", val, regexp); |
| 2135 | } |
| 2136 | |
| 2137 | /* Search through the partial symtabs *first* for all symbols |
| 2138 | matching the regexp. That way we don't have to reproduce all of |
| 2139 | the machinery below. */ |
| 2140 | |
| 2141 | ALL_PSYMTABS (objfile, ps) |
| 2142 | { |
| 2143 | struct partial_symbol *bound, *gbound, *sbound; |
| 2144 | int keep_going = 1; |
| 2145 | |
| 2146 | if (ps->readin) continue; |
| 2147 | |
| 2148 | gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms; |
| 2149 | sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms; |
| 2150 | bound = gbound; |
| 2151 | |
| 2152 | /* Go through all of the symbols stored in a partial |
| 2153 | symtab in one loop. */ |
| 2154 | psym = objfile->global_psymbols.list + ps->globals_offset; |
| 2155 | while (keep_going) |
| 2156 | { |
| 2157 | if (psym >= bound) |
| 2158 | { |
| 2159 | if (bound == gbound && ps->n_static_syms != 0) |
| 2160 | { |
| 2161 | psym = objfile->static_psymbols.list + ps->statics_offset; |
| 2162 | bound = sbound; |
| 2163 | } |
| 2164 | else |
| 2165 | keep_going = 0; |
| 2166 | continue; |
| 2167 | } |
| 2168 | else |
| 2169 | { |
| 2170 | QUIT; |
| 2171 | |
| 2172 | /* If it would match (logic taken from loop below) |
| 2173 | load the file and go on to the next one */ |
| 2174 | if ((regexp == 0 || NAME_MATCH (SYMBOL_NAME (psym))) |
| 2175 | && ((class == 0 && SYMBOL_CLASS (psym) != LOC_TYPEDEF |
| 2176 | && SYMBOL_CLASS (psym) != LOC_BLOCK) |
| 2177 | || (class == 1 && SYMBOL_CLASS (psym) == LOC_BLOCK) |
| 2178 | || (class == 2 && SYMBOL_CLASS (psym) == LOC_TYPEDEF) |
| 2179 | || (class == 3 && SYMBOL_CLASS (psym) == LOC_BLOCK))) |
| 2180 | { |
| 2181 | PSYMTAB_TO_SYMTAB(ps); |
| 2182 | keep_going = 0; |
| 2183 | } |
| 2184 | } |
| 2185 | psym++; |
| 2186 | } |
| 2187 | } |
| 2188 | |
| 2189 | /* Here, we search through the minimal symbol tables for functions that |
| 2190 | match, and call find_pc_symtab on them to force their symbols to |
| 2191 | be read. The symbol will then be found during the scan of symtabs |
| 2192 | below. If find_pc_symtab fails, set found_misc so that we will |
| 2193 | rescan to print any matching symbols without debug info. */ |
| 2194 | |
| 2195 | if (class == 1) |
| 2196 | { |
| 2197 | ALL_MSYMBOLS (objfile, msymbol) |
| 2198 | { |
| 2199 | if (msymbol -> type == ourtype || msymbol -> type == ourtype2) |
| 2200 | { |
| 2201 | if (regexp == 0 || NAME_MATCH (msymbol -> name)) |
| 2202 | { |
| 2203 | if (0 == find_pc_symtab (msymbol -> address)) |
| 2204 | { |
| 2205 | found_misc = 1; |
| 2206 | } |
| 2207 | } |
| 2208 | } |
| 2209 | } |
| 2210 | } |
| 2211 | |
| 2212 | /* Printout here so as to get after the "Reading in symbols" |
| 2213 | messages which will be generated above. */ |
| 2214 | if (!bpt) |
| 2215 | printf_filtered (regexp |
| 2216 | ? "All %ss matching regular expression \"%s\":\n" |
| 2217 | : "All defined %ss:\n", |
| 2218 | classnames[class], |
| 2219 | regexp); |
| 2220 | |
| 2221 | ALL_SYMTABS (objfile, s) |
| 2222 | { |
| 2223 | found_in_file = 0; |
| 2224 | bv = BLOCKVECTOR (s); |
| 2225 | /* Often many files share a blockvector. |
| 2226 | Scan each blockvector only once so that |
| 2227 | we don't get every symbol many times. |
| 2228 | It happens that the first symtab in the list |
| 2229 | for any given blockvector is the main file. */ |
| 2230 | if (bv != prev_bv) |
| 2231 | for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++) |
| 2232 | { |
| 2233 | b = BLOCKVECTOR_BLOCK (bv, i); |
| 2234 | /* Skip the sort if this block is always sorted. */ |
| 2235 | if (!BLOCK_SHOULD_SORT (b)) |
| 2236 | sort_block_syms (b); |
| 2237 | for (j = 0; j < BLOCK_NSYMS (b); j++) |
| 2238 | { |
| 2239 | QUIT; |
| 2240 | sym = BLOCK_SYM (b, j); |
| 2241 | if ((regexp == 0 || NAME_MATCH (SYMBOL_NAME (sym))) |
| 2242 | && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF |
| 2243 | && SYMBOL_CLASS (sym) != LOC_BLOCK |
| 2244 | && SYMBOL_CLASS (sym) != LOC_CONST) |
| 2245 | || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK) |
| 2246 | || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF) |
| 2247 | || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK))) |
| 2248 | { |
| 2249 | if (bpt) |
| 2250 | { |
| 2251 | /* Set a breakpoint here, if it's a function */ |
| 2252 | if (class == 1) |
| 2253 | break_command (SYMBOL_NAME(sym), 0); |
| 2254 | } |
| 2255 | else if (!found_in_file) |
| 2256 | { |
| 2257 | fputs_filtered ("\nFile ", stdout); |
| 2258 | fputs_filtered (s->filename, stdout); |
| 2259 | fputs_filtered (":\n", stdout); |
| 2260 | } |
| 2261 | found_in_file = 1; |
| 2262 | |
| 2263 | if (class != 2 && i == STATIC_BLOCK) |
| 2264 | printf_filtered ("static "); |
| 2265 | |
| 2266 | /* Typedef that is not a C++ class */ |
| 2267 | if (class == 2 |
| 2268 | && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE) |
| 2269 | typedef_print (SYMBOL_TYPE(sym), sym, stdout); |
| 2270 | /* variable, func, or typedef-that-is-c++-class */ |
| 2271 | else if (class < 2 || |
| 2272 | (class == 2 && |
| 2273 | SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE)) |
| 2274 | { |
| 2275 | type_print (SYMBOL_TYPE (sym), |
| 2276 | (SYMBOL_CLASS (sym) == LOC_TYPEDEF |
| 2277 | ? "" : SYMBOL_NAME (sym)), |
| 2278 | stdout, 0); |
| 2279 | |
| 2280 | printf_filtered (";\n"); |
| 2281 | } |
| 2282 | else |
| 2283 | { |
| 2284 | # if 0 |
| 2285 | /* FIXME, why is this zapped out? */ |
| 2286 | char buf[1024]; |
| 2287 | type_print_base (TYPE_FN_FIELD_TYPE(t, i), stdout, 0, 0); |
| 2288 | type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), stdout, 0); |
| 2289 | sprintf (buf, " %s::", type_name_no_tag (t)); |
| 2290 | type_print_method_args (TYPE_FN_FIELD_ARGS (t, i), buf, name, stdout); |
| 2291 | # endif |
| 2292 | } |
| 2293 | } |
| 2294 | } |
| 2295 | } |
| 2296 | prev_bv = bv; |
| 2297 | } |
| 2298 | |
| 2299 | /* If there are no eyes, avoid all contact. I mean, if there are |
| 2300 | no debug symbols, then print directly from the msymbol_vector. */ |
| 2301 | |
| 2302 | if (found_misc || class != 1) |
| 2303 | { |
| 2304 | found_in_file = 0; |
| 2305 | ALL_MSYMBOLS (objfile, msymbol) |
| 2306 | { |
| 2307 | if (msymbol -> type == ourtype || msymbol -> type == ourtype2) |
| 2308 | { |
| 2309 | if (regexp == 0 || NAME_MATCH (msymbol -> name)) |
| 2310 | { |
| 2311 | /* Functions: Look up by address. */ |
| 2312 | if (class != 1 || |
| 2313 | (0 == find_pc_symtab (msymbol -> address))) |
| 2314 | { |
| 2315 | /* Variables/Absolutes: Look up by name */ |
| 2316 | if (lookup_symbol (msymbol -> name, |
| 2317 | (struct block *) 0, VAR_NAMESPACE, 0, |
| 2318 | (struct symtab **) 0) == NULL) |
| 2319 | { |
| 2320 | if (!found_in_file) |
| 2321 | { |
| 2322 | printf_filtered ("\nNon-debugging symbols:\n"); |
| 2323 | found_in_file = 1; |
| 2324 | } |
| 2325 | printf_filtered (" %08x %s\n", |
| 2326 | msymbol -> address, |
| 2327 | msymbol -> name); |
| 2328 | } |
| 2329 | } |
| 2330 | } |
| 2331 | } |
| 2332 | } |
| 2333 | } |
| 2334 | } |
| 2335 | |
| 2336 | static void |
| 2337 | variables_info (regexp, from_tty) |
| 2338 | char *regexp; |
| 2339 | int from_tty; |
| 2340 | { |
| 2341 | list_symbols (regexp, 0, 0); |
| 2342 | } |
| 2343 | |
| 2344 | static void |
| 2345 | functions_info (regexp, from_tty) |
| 2346 | char *regexp; |
| 2347 | int from_tty; |
| 2348 | { |
| 2349 | list_symbols (regexp, 1, 0); |
| 2350 | } |
| 2351 | |
| 2352 | static void |
| 2353 | types_info (regexp, from_tty) |
| 2354 | char *regexp; |
| 2355 | int from_tty; |
| 2356 | { |
| 2357 | list_symbols (regexp, 2, 0); |
| 2358 | } |
| 2359 | |
| 2360 | #if 0 |
| 2361 | /* Tiemann says: "info methods was never implemented." */ |
| 2362 | static void |
| 2363 | methods_info (regexp) |
| 2364 | char *regexp; |
| 2365 | { |
| 2366 | list_symbols (regexp, 3, 0); |
| 2367 | } |
| 2368 | #endif /* 0 */ |
| 2369 | |
| 2370 | /* Breakpoint all functions matching regular expression. */ |
| 2371 | static void |
| 2372 | rbreak_command (regexp, from_tty) |
| 2373 | char *regexp; |
| 2374 | int from_tty; |
| 2375 | { |
| 2376 | list_symbols (regexp, 1, 1); |
| 2377 | } |
| 2378 | \f |
| 2379 | |
| 2380 | /* Return Nonzero if block a is lexically nested within block b, |
| 2381 | or if a and b have the same pc range. |
| 2382 | Return zero otherwise. */ |
| 2383 | int |
| 2384 | contained_in (a, b) |
| 2385 | struct block *a, *b; |
| 2386 | { |
| 2387 | if (!a || !b) |
| 2388 | return 0; |
| 2389 | return BLOCK_START (a) >= BLOCK_START (b) |
| 2390 | && BLOCK_END (a) <= BLOCK_END (b); |
| 2391 | } |
| 2392 | |
| 2393 | \f |
| 2394 | /* Helper routine for make_symbol_completion_list. */ |
| 2395 | |
| 2396 | static int return_val_size; |
| 2397 | static int return_val_index; |
| 2398 | static char **return_val; |
| 2399 | |
| 2400 | /* Test to see if the symbol specified by SYMNAME (or it's demangled |
| 2401 | equivalent) matches TEXT in the first TEXT_LEN characters. If so, |
| 2402 | add it to the current completion list. */ |
| 2403 | |
| 2404 | static void |
| 2405 | completion_list_add_symbol (symname, text, text_len) |
| 2406 | char *symname; |
| 2407 | char *text; |
| 2408 | int text_len; |
| 2409 | { |
| 2410 | char *demangled; |
| 2411 | int newsize; |
| 2412 | |
| 2413 | /* First see if SYMNAME is a C++ mangled name, and if so, use the |
| 2414 | demangled name instead, including any parameters. */ |
| 2415 | |
| 2416 | if ((demangled = cplus_demangle (symname, DMGL_PARAMS | DMGL_ANSI)) != NULL) |
| 2417 | { |
| 2418 | symname = demangled; |
| 2419 | } |
| 2420 | |
| 2421 | /* If we have a match for a completion, then add SYMNAME to the current |
| 2422 | list of matches. Note that we always make a copy of the string, even |
| 2423 | if it is one that was returned from cplus_demangle and is already |
| 2424 | in malloc'd memory. */ |
| 2425 | |
| 2426 | if (strncmp (symname, text, text_len) == 0) |
| 2427 | { |
| 2428 | if (return_val_index + 3 > return_val_size) |
| 2429 | { |
| 2430 | newsize = (return_val_size *= 2) * sizeof (char *); |
| 2431 | return_val = (char **) xrealloc ((char *) return_val, newsize); |
| 2432 | } |
| 2433 | return_val[return_val_index++] = savestring (symname, strlen (symname)); |
| 2434 | return_val[return_val_index] = NULL; |
| 2435 | } |
| 2436 | |
| 2437 | if (demangled != NULL) |
| 2438 | { |
| 2439 | free (demangled); |
| 2440 | } |
| 2441 | } |
| 2442 | |
| 2443 | /* Return a NULL terminated array of all symbols (regardless of class) which |
| 2444 | begin by matching TEXT. If the answer is no symbols, then the return value |
| 2445 | is an array which contains only a NULL pointer. |
| 2446 | |
| 2447 | Problem: All of the symbols have to be copied because readline frees them. |
| 2448 | I'm not going to worry about this; hopefully there won't be that many. */ |
| 2449 | |
| 2450 | char ** |
| 2451 | make_symbol_completion_list (text) |
| 2452 | char *text; |
| 2453 | { |
| 2454 | register struct symbol *sym; |
| 2455 | register struct symtab *s; |
| 2456 | register struct partial_symtab *ps; |
| 2457 | register struct minimal_symbol *msymbol; |
| 2458 | register struct objfile *objfile; |
| 2459 | register struct block *b, *surrounding_static_block = 0; |
| 2460 | register int i, j; |
| 2461 | int text_len; |
| 2462 | struct partial_symbol *psym; |
| 2463 | |
| 2464 | text_len = strlen (text); |
| 2465 | return_val_size = 100; |
| 2466 | return_val_index = 0; |
| 2467 | return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *)); |
| 2468 | return_val[0] = NULL; |
| 2469 | |
| 2470 | /* Look through the partial symtabs for all symbols which begin |
| 2471 | by matching TEXT. Add each one that you find to the list. */ |
| 2472 | |
| 2473 | ALL_PSYMTABS (objfile, ps) |
| 2474 | { |
| 2475 | /* If the psymtab's been read in we'll get it when we search |
| 2476 | through the blockvector. */ |
| 2477 | if (ps->readin) continue; |
| 2478 | |
| 2479 | for (psym = objfile->global_psymbols.list + ps->globals_offset; |
| 2480 | psym < (objfile->global_psymbols.list + ps->globals_offset |
| 2481 | + ps->n_global_syms); |
| 2482 | psym++) |
| 2483 | { |
| 2484 | /* If interrupted, then quit. */ |
| 2485 | QUIT; |
| 2486 | completion_list_add_symbol (SYMBOL_NAME (psym), text, text_len); |
| 2487 | } |
| 2488 | |
| 2489 | for (psym = objfile->static_psymbols.list + ps->statics_offset; |
| 2490 | psym < (objfile->static_psymbols.list + ps->statics_offset |
| 2491 | + ps->n_static_syms); |
| 2492 | psym++) |
| 2493 | { |
| 2494 | QUIT; |
| 2495 | completion_list_add_symbol (SYMBOL_NAME (psym), text, text_len); |
| 2496 | } |
| 2497 | } |
| 2498 | |
| 2499 | /* At this point scan through the misc symbol vectors and add each |
| 2500 | symbol you find to the list. Eventually we want to ignore |
| 2501 | anything that isn't a text symbol (everything else will be |
| 2502 | handled by the psymtab code above). */ |
| 2503 | |
| 2504 | ALL_MSYMBOLS (objfile, msymbol) |
| 2505 | { |
| 2506 | QUIT; |
| 2507 | completion_list_add_symbol (msymbol -> name, text, text_len); |
| 2508 | } |
| 2509 | |
| 2510 | /* Search upwards from currently selected frame (so that we can |
| 2511 | complete on local vars. */ |
| 2512 | |
| 2513 | for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b)) |
| 2514 | { |
| 2515 | if (!BLOCK_SUPERBLOCK (b)) |
| 2516 | { |
| 2517 | surrounding_static_block = b; /* For elmin of dups */ |
| 2518 | } |
| 2519 | |
| 2520 | /* Also catch fields of types defined in this places which match our |
| 2521 | text string. Only complete on types visible from current context. */ |
| 2522 | |
| 2523 | for (i = 0; i < BLOCK_NSYMS (b); i++) |
| 2524 | { |
| 2525 | sym = BLOCK_SYM (b, i); |
| 2526 | completion_list_add_symbol (SYMBOL_NAME (sym), text, text_len); |
| 2527 | if (SYMBOL_CLASS (sym) == LOC_TYPEDEF) |
| 2528 | { |
| 2529 | struct type *t = SYMBOL_TYPE (sym); |
| 2530 | enum type_code c = TYPE_CODE (t); |
| 2531 | |
| 2532 | if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT) |
| 2533 | { |
| 2534 | for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++) |
| 2535 | { |
| 2536 | if (TYPE_FIELD_NAME (t, j)) |
| 2537 | { |
| 2538 | completion_list_add_symbol (TYPE_FIELD_NAME (t, j), |
| 2539 | text, text_len); |
| 2540 | } |
| 2541 | } |
| 2542 | } |
| 2543 | } |
| 2544 | } |
| 2545 | } |
| 2546 | |
| 2547 | /* Go through the symtabs and check the externs and statics for |
| 2548 | symbols which match. */ |
| 2549 | |
| 2550 | ALL_SYMTABS (objfile, s) |
| 2551 | { |
| 2552 | QUIT; |
| 2553 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); |
| 2554 | for (i = 0; i < BLOCK_NSYMS (b); i++) |
| 2555 | { |
| 2556 | sym = BLOCK_SYM (b, i); |
| 2557 | completion_list_add_symbol (SYMBOL_NAME (sym), text, text_len); |
| 2558 | } |
| 2559 | } |
| 2560 | |
| 2561 | ALL_SYMTABS (objfile, s) |
| 2562 | { |
| 2563 | QUIT; |
| 2564 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK); |
| 2565 | /* Don't do this block twice. */ |
| 2566 | if (b == surrounding_static_block) continue; |
| 2567 | for (i = 0; i < BLOCK_NSYMS (b); i++) |
| 2568 | { |
| 2569 | sym = BLOCK_SYM (b, i); |
| 2570 | completion_list_add_symbol (SYMBOL_NAME (sym), text, text_len); |
| 2571 | } |
| 2572 | } |
| 2573 | |
| 2574 | return (return_val); |
| 2575 | } |
| 2576 | |
| 2577 | \f |
| 2578 | /* Find a mangled symbol that corresponds to LOOKFOR using brute force. |
| 2579 | Basically we go munging through available symbols, demangling each one, |
| 2580 | looking for a match on the demangled result. */ |
| 2581 | |
| 2582 | static char * |
| 2583 | expensive_mangler (lookfor) |
| 2584 | const char *lookfor; |
| 2585 | { |
| 2586 | register struct symbol *sym; |
| 2587 | register struct symtab *s; |
| 2588 | register struct partial_symtab *ps; |
| 2589 | register struct minimal_symbol *msymbol; |
| 2590 | register struct objfile *objfile; |
| 2591 | register struct block *b, *surrounding_static_block = 0; |
| 2592 | register int i, j; |
| 2593 | struct partial_symbol *psym; |
| 2594 | char *demangled; |
| 2595 | |
| 2596 | /* Look through the partial symtabs for a symbol that matches */ |
| 2597 | |
| 2598 | ALL_PSYMTABS (objfile, ps) |
| 2599 | { |
| 2600 | /* If the psymtab's been read in we'll get it when we search |
| 2601 | through the blockvector. */ |
| 2602 | if (ps->readin) continue; |
| 2603 | |
| 2604 | for (psym = objfile->global_psymbols.list + ps->globals_offset; |
| 2605 | psym < (objfile->global_psymbols.list + ps->globals_offset |
| 2606 | + ps->n_global_syms); |
| 2607 | psym++) |
| 2608 | { |
| 2609 | QUIT; /* If interrupted, then quit. */ |
| 2610 | demangled = demangle_and_match (SYMBOL_NAME (psym), lookfor, |
| 2611 | DMGL_PARAMS | DMGL_ANSI); |
| 2612 | if (demangled != NULL) |
| 2613 | { |
| 2614 | free (demangled); |
| 2615 | return (SYMBOL_NAME (psym)); |
| 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | for (psym = objfile->static_psymbols.list + ps->statics_offset; |
| 2620 | psym < (objfile->static_psymbols.list + ps->statics_offset |
| 2621 | + ps->n_static_syms); |
| 2622 | psym++) |
| 2623 | { |
| 2624 | QUIT; |
| 2625 | demangled = demangle_and_match (SYMBOL_NAME (psym), lookfor, |
| 2626 | DMGL_PARAMS | DMGL_ANSI); |
| 2627 | if (demangled != NULL) |
| 2628 | { |
| 2629 | free (demangled); |
| 2630 | return (SYMBOL_NAME (psym)); |
| 2631 | } |
| 2632 | } |
| 2633 | } |
| 2634 | |
| 2635 | /* Scan through the misc symbol vectors looking for a match. */ |
| 2636 | |
| 2637 | ALL_MSYMBOLS (objfile, msymbol) |
| 2638 | { |
| 2639 | QUIT; |
| 2640 | demangled = demangle_and_match (msymbol -> name, lookfor, |
| 2641 | DMGL_PARAMS | DMGL_ANSI); |
| 2642 | if (demangled != NULL) |
| 2643 | { |
| 2644 | free (demangled); |
| 2645 | return (msymbol -> name); |
| 2646 | } |
| 2647 | } |
| 2648 | |
| 2649 | /* Search upwards from currently selected frame looking for a match */ |
| 2650 | |
| 2651 | for (b = get_selected_block (); b; b = BLOCK_SUPERBLOCK (b)) |
| 2652 | { |
| 2653 | if (!BLOCK_SUPERBLOCK (b)) |
| 2654 | surrounding_static_block = b; /* For elmin of dups */ |
| 2655 | |
| 2656 | /* Also catch fields of types defined in this places which |
| 2657 | match our text string. Only complete on types visible |
| 2658 | from current context. */ |
| 2659 | for (i = 0; i < BLOCK_NSYMS (b); i++) |
| 2660 | { |
| 2661 | sym = BLOCK_SYM (b, i); |
| 2662 | demangled = demangle_and_match (SYMBOL_NAME (sym), lookfor, |
| 2663 | DMGL_PARAMS | DMGL_ANSI); |
| 2664 | if (demangled != NULL) |
| 2665 | { |
| 2666 | free (demangled); |
| 2667 | return (SYMBOL_NAME (sym)); |
| 2668 | } |
| 2669 | if (SYMBOL_CLASS (sym) == LOC_TYPEDEF) |
| 2670 | { |
| 2671 | struct type *t = SYMBOL_TYPE (sym); |
| 2672 | enum type_code c = TYPE_CODE (t); |
| 2673 | |
| 2674 | if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT) |
| 2675 | { |
| 2676 | for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++) |
| 2677 | { |
| 2678 | if (TYPE_FIELD_NAME (t, j)) |
| 2679 | { |
| 2680 | demangled = |
| 2681 | demangle_and_match (TYPE_FIELD_NAME (t, j), |
| 2682 | lookfor, |
| 2683 | DMGL_PARAMS | DMGL_ANSI); |
| 2684 | if (demangled != NULL) |
| 2685 | { |
| 2686 | free (demangled); |
| 2687 | return (TYPE_FIELD_NAME (t, j)); |
| 2688 | } |
| 2689 | } |
| 2690 | } |
| 2691 | } |
| 2692 | } |
| 2693 | } |
| 2694 | } |
| 2695 | |
| 2696 | /* Go through the symtabs and check the externs and statics for |
| 2697 | symbols which match. */ |
| 2698 | |
| 2699 | ALL_SYMTABS (objfile, s) |
| 2700 | { |
| 2701 | QUIT; |
| 2702 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); |
| 2703 | for (i = 0; i < BLOCK_NSYMS (b); i++) |
| 2704 | { |
| 2705 | sym = BLOCK_SYM (b, i); |
| 2706 | demangled = demangle_and_match (SYMBOL_NAME (sym), lookfor, |
| 2707 | DMGL_PARAMS | DMGL_ANSI); |
| 2708 | if (demangled != NULL) |
| 2709 | { |
| 2710 | free (demangled); |
| 2711 | return (SYMBOL_NAME (sym)); |
| 2712 | } |
| 2713 | } |
| 2714 | } |
| 2715 | |
| 2716 | ALL_SYMTABS (objfile, s) |
| 2717 | { |
| 2718 | QUIT; |
| 2719 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK); |
| 2720 | /* Don't do this block twice. */ |
| 2721 | if (b == surrounding_static_block) continue; |
| 2722 | for (i = 0; i < BLOCK_NSYMS (b); i++) |
| 2723 | { |
| 2724 | sym = BLOCK_SYM (b, i); |
| 2725 | demangled = demangle_and_match (SYMBOL_NAME (sym), lookfor, |
| 2726 | DMGL_PARAMS | DMGL_ANSI); |
| 2727 | if (demangled != NULL) |
| 2728 | { |
| 2729 | free (demangled); |
| 2730 | return (SYMBOL_NAME (sym)); |
| 2731 | } |
| 2732 | } |
| 2733 | } |
| 2734 | |
| 2735 | return (NULL); |
| 2736 | } |
| 2737 | |
| 2738 | \f |
| 2739 | #if 0 |
| 2740 | /* Add the type of the symbol sym to the type of the current |
| 2741 | function whose block we are in (assumed). The type of |
| 2742 | this current function is contained in *TYPE. |
| 2743 | |
| 2744 | This basically works as follows: When we find a function |
| 2745 | symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record |
| 2746 | a pointer to its type in the global in_function_type. Every |
| 2747 | time we come across a parameter symbol ('p' in its name), then |
| 2748 | this procedure adds the name and type of that parameter |
| 2749 | to the function type pointed to by *TYPE. (Which should correspond |
| 2750 | to in_function_type if it was called correctly). |
| 2751 | |
| 2752 | Note that since we are modifying a type, the result of |
| 2753 | lookup_function_type() should be memcpy()ed before calling |
| 2754 | this. When not in strict typing mode, the expression |
| 2755 | evaluator can choose to ignore this. |
| 2756 | |
| 2757 | Assumption: All of a function's parameter symbols will |
| 2758 | appear before another function symbol is found. The parameters |
| 2759 | appear in the same order in the argument list as they do in the |
| 2760 | symbol table. */ |
| 2761 | |
| 2762 | void |
| 2763 | add_param_to_type (type,sym) |
| 2764 | struct type **type; |
| 2765 | struct symbol *sym; |
| 2766 | { |
| 2767 | int num = ++(TYPE_NFIELDS(*type)); |
| 2768 | |
| 2769 | if(TYPE_NFIELDS(*type)-1) |
| 2770 | TYPE_FIELDS(*type) = (struct field *) |
| 2771 | (*current_objfile->xrealloc) ((char *)(TYPE_FIELDS(*type)), |
| 2772 | num*sizeof(struct field)); |
| 2773 | else |
| 2774 | TYPE_FIELDS(*type) = (struct field *) |
| 2775 | (*current_objfile->xmalloc) (num*sizeof(struct field)); |
| 2776 | |
| 2777 | TYPE_FIELD_BITPOS(*type,num-1) = num-1; |
| 2778 | TYPE_FIELD_BITSIZE(*type,num-1) = 0; |
| 2779 | TYPE_FIELD_TYPE(*type,num-1) = SYMBOL_TYPE(sym); |
| 2780 | TYPE_FIELD_NAME(*type,num-1) = SYMBOL_NAME(sym); |
| 2781 | } |
| 2782 | #endif |
| 2783 | \f |
| 2784 | void |
| 2785 | _initialize_symtab () |
| 2786 | { |
| 2787 | add_info ("variables", variables_info, |
| 2788 | "All global and static variable names, or those matching REGEXP."); |
| 2789 | add_info ("functions", functions_info, |
| 2790 | "All function names, or those matching REGEXP."); |
| 2791 | |
| 2792 | /* FIXME: This command has at least the following problems: |
| 2793 | 1. It prints builtin types (in a very strange and confusing fashion). |
| 2794 | 2. It doesn't print right, e.g. with |
| 2795 | typedef struct foo *FOO |
| 2796 | type_print prints "FOO" when we want to make it (in this situation) |
| 2797 | print "struct foo *". |
| 2798 | I also think "ptype" or "whatis" is more likely to be useful (but if |
| 2799 | there is much disagreement "info types" can be fixed). */ |
| 2800 | add_info ("types", types_info, |
| 2801 | "All type names, or those matching REGEXP."); |
| 2802 | |
| 2803 | #if 0 |
| 2804 | add_info ("methods", methods_info, |
| 2805 | "All method names, or those matching REGEXP::REGEXP.\n\ |
| 2806 | If the class qualifier is omitted, it is assumed to be the current scope.\n\ |
| 2807 | If the first REGEXP is omitted, then all methods matching the second REGEXP\n\ |
| 2808 | are listed."); |
| 2809 | #endif |
| 2810 | add_info ("sources", sources_info, |
| 2811 | "Source files in the program."); |
| 2812 | |
| 2813 | add_com ("rbreak", no_class, rbreak_command, |
| 2814 | "Set a breakpoint for all functions matching REGEXP."); |
| 2815 | |
| 2816 | /* Initialize the one built-in type that isn't language dependent... */ |
| 2817 | builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0, |
| 2818 | "<unknown type>", (struct objfile *) NULL); |
| 2819 | } |