1 /* Parser for linespec for the GNU debugger, GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
31 #include "completer.h"
33 #include "parser-defs.h"
35 #include "objc-lang.h"
37 #include "exceptions.h"
40 #include "mi/mi-cmds.h"
43 /* We share this one with symtab.c, but it is not exported widely. */
45 extern char *operator_chars (char *, char **);
47 /* Prototypes for local functions */
49 static void initialize_defaults (struct symtab
**default_symtab
,
52 static void set_flags (char *arg
, int *is_quoted
, char **paren_pointer
);
54 static struct symtabs_and_lines
decode_indirect (char **argptr
);
56 static char *locate_first_half (char **argptr
, int *is_quote_enclosed
);
58 static struct symtabs_and_lines
decode_objc (char **argptr
,
60 struct symtab
*file_symtab
,
64 static struct symtabs_and_lines
decode_compound (char **argptr
,
70 static struct symbol
*lookup_prefix_sym (char **argptr
, char *p
);
72 static struct symtabs_and_lines
find_method (int funfirstline
,
77 struct symbol
*sym_class
);
79 static int collect_methods (char *copy
, struct type
*t
,
80 struct symbol
*sym_class
,
81 struct symbol
**sym_arr
);
83 static NORETURN
void cplusplus_error (const char *name
,
85 ATTR_NORETURN
ATTR_FORMAT (printf
, 2, 3);
87 static int total_number_of_methods (struct type
*type
);
89 static int find_methods (struct type
*, char *,
90 enum language
, struct symbol
**);
92 static int add_matching_methods (int method_counter
, struct type
*t
,
93 enum language language
,
94 struct symbol
**sym_arr
);
96 static int add_constructors (int method_counter
, struct type
*t
,
97 enum language language
,
98 struct symbol
**sym_arr
);
100 static void build_canonical_line_spec (struct symtab_and_line
*,
103 static char *find_toplevel_char (char *s
, char c
);
105 static int is_objc_method_format (const char *s
);
107 static struct symtabs_and_lines
decode_line_2 (struct symbol
*[],
110 static struct symtab
*symtab_from_filename (char **argptr
,
111 char *p
, int is_quote_enclosed
,
115 symtabs_and_lines
decode_all_digits (char **argptr
,
116 struct symtab
*default_symtab
,
119 struct symtab
*file_symtab
,
122 static struct symtabs_and_lines
decode_dollar (char *copy
,
124 struct symtab
*default_symtab
,
126 struct symtab
*file_symtab
);
128 static struct symtabs_and_lines
decode_variable (char *copy
,
131 struct symtab
*file_symtab
,
135 symtabs_and_lines
symbol_found (int funfirstline
,
139 struct symtab
*file_symtab
,
140 struct symtab
*sym_symtab
);
143 symtabs_and_lines
minsym_found (int funfirstline
,
144 struct minimal_symbol
*msymbol
);
146 /* Helper functions. */
148 /* Issue a helpful hint on using the command completion feature on
149 single quoted demangled C++ symbols as part of the completion
153 cplusplus_error (const char *name
, const char *fmt
, ...)
155 struct ui_file
*tmp_stream
;
156 tmp_stream
= mem_fileopen ();
157 make_cleanup_ui_file_delete (tmp_stream
);
161 va_start (args
, fmt
);
162 vfprintf_unfiltered (tmp_stream
, fmt
, args
);
166 while (*name
== '\'')
168 fprintf_unfiltered (tmp_stream
,
169 ("Hint: try '%s<TAB> or '%s<ESC-?>\n"
170 "(Note leading single quote.)"),
172 error_stream (tmp_stream
);
175 /* Return the number of methods described for TYPE, including the
176 methods from types it derives from. This can't be done in the symbol
177 reader because the type of the baseclass might still be stubbed
178 when the definition of the derived class is parsed. */
181 total_number_of_methods (struct type
*type
)
186 CHECK_TYPEDEF (type
);
187 if (TYPE_CPLUS_SPECIFIC (type
) == NULL
)
189 count
= TYPE_NFN_FIELDS_TOTAL (type
);
191 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
192 count
+= total_number_of_methods (TYPE_BASECLASS (type
, n
));
197 /* Recursive helper function for decode_line_1.
198 Look for methods named NAME in type T.
199 Return number of matches.
200 Put matches in SYM_ARR, which should have been allocated with
201 a size of total_number_of_methods (T) * sizeof (struct symbol *).
202 Note that this function is g++ specific. */
205 find_methods (struct type
*t
, char *name
, enum language language
,
206 struct symbol
**sym_arr
)
210 char *class_name
= type_name_no_tag (t
);
212 /* Ignore this class if it doesn't have a name. This is ugly, but
213 unless we figure out how to get the physname without the name of
214 the class, then the loop can't do any good. */
216 && (lookup_symbol_in_language (class_name
, (struct block
*) NULL
,
217 STRUCT_DOMAIN
, language
, (int *) NULL
,
218 (struct symtab
**) NULL
)))
221 int name_len
= strlen (name
);
225 /* Loop over each method name. At this level, all overloads of a name
226 are counted as a single name. There is an inner loop which loops over
229 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
233 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
236 if (strncmp (method_name
, "__", 2) == 0 ||
237 strncmp (method_name
, "op", 2) == 0 ||
238 strncmp (method_name
, "type", 4) == 0)
240 if (cplus_demangle_opname (method_name
, dem_opname
, DMGL_ANSI
))
241 method_name
= dem_opname
;
242 else if (cplus_demangle_opname (method_name
, dem_opname
, 0))
243 method_name
= dem_opname
;
246 if (strcmp_iw (name
, method_name
) == 0)
247 /* Find all the overloaded methods with that name. */
248 i1
+= add_matching_methods (method_counter
, t
, language
,
250 else if (strncmp (class_name
, name
, name_len
) == 0
251 && (class_name
[name_len
] == '\0'
252 || class_name
[name_len
] == '<'))
253 i1
+= add_constructors (method_counter
, t
, language
,
258 /* Only search baseclasses if there is no match yet, since names in
259 derived classes override those in baseclasses.
261 FIXME: The above is not true; it is only true of member functions
262 if they have the same number of arguments (??? - section 13.1 of the
263 ARM says the function members are not in the same scope but doesn't
264 really spell out the rules in a way I understand. In any case, if
265 the number of arguments differ this is a case in which we can overload
266 rather than hiding without any problem, and gcc 2.4.5 does overload
267 rather than hiding in this case). */
270 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
271 i1
+= find_methods (TYPE_BASECLASS (t
, ibase
), name
,
272 language
, sym_arr
+ i1
);
277 /* Add the symbols associated to methods of the class whose type is T
278 and whose name matches the method indexed by METHOD_COUNTER in the
279 array SYM_ARR. Return the number of methods added. */
282 add_matching_methods (int method_counter
, struct type
*t
,
283 enum language language
, struct symbol
**sym_arr
)
288 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
295 f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
297 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
301 tmp_name
= gdb_mangle_name (t
,
304 phys_name
= alloca (strlen (tmp_name
) + 1);
305 strcpy (phys_name
, tmp_name
);
309 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
311 /* Destructor is handled by caller, don't add it to
313 if (is_destructor_name (phys_name
) != 0)
316 sym_arr
[i1
] = lookup_symbol_in_language (phys_name
,
320 (struct symtab
**) NULL
);
325 /* This error message gets printed, but the method
326 still seems to be found
327 fputs_filtered("(Cannot find method ", gdb_stdout);
328 fprintf_symbol_filtered (gdb_stdout, phys_name,
330 DMGL_PARAMS | DMGL_ANSI);
331 fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
339 /* Add the symbols associated to constructors of the class whose type
340 is CLASS_TYPE and which are indexed by by METHOD_COUNTER to the
341 array SYM_ARR. Return the number of methods added. */
344 add_constructors (int method_counter
, struct type
*t
,
345 enum language language
, struct symbol
**sym_arr
)
350 /* For GCC 3.x and stabs, constructors and destructors
351 have names like __base_ctor and __complete_dtor.
352 Check the physname for now if we're looking for a
355 = TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
362 f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
364 /* GCC 3.x will never produce stabs stub methods, so
365 we don't need to handle this case. */
366 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
368 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
369 if (! is_constructor_name (phys_name
))
372 /* If this method is actually defined, include it in the
374 sym_arr
[i1
] = lookup_symbol_in_language (phys_name
,
378 (struct symtab
**) NULL
);
386 /* Helper function for decode_line_1.
387 Build a canonical line spec in CANONICAL if it is non-NULL and if
388 the SAL has a symtab.
389 If SYMNAME is non-NULL the canonical line spec is `filename:symname'.
390 If SYMNAME is NULL the line number from SAL is used and the canonical
391 line spec is `filename:linenum'. */
394 build_canonical_line_spec (struct symtab_and_line
*sal
, char *symname
,
397 char **canonical_arr
;
398 char *canonical_name
;
400 struct symtab
*s
= sal
->symtab
;
402 if (s
== (struct symtab
*) NULL
403 || s
->filename
== (char *) NULL
404 || canonical
== (char ***) NULL
)
407 canonical_arr
= (char **) xmalloc (sizeof (char *));
408 *canonical
= canonical_arr
;
410 filename
= s
->filename
;
413 canonical_name
= xmalloc (strlen (filename
) + strlen (symname
) + 2);
414 sprintf (canonical_name
, "%s:%s", filename
, symname
);
418 canonical_name
= xmalloc (strlen (filename
) + 30);
419 sprintf (canonical_name
, "%s:%d", filename
, sal
->line
);
421 canonical_arr
[0] = canonical_name
;
426 /* Find an instance of the character C in the string S that is outside
427 of all parenthesis pairs, single-quoted strings, and double-quoted
428 strings. Also, ignore the char within a template name, like a ','
429 within foo<int, int>. */
432 find_toplevel_char (char *s
, char c
)
434 int quoted
= 0; /* zero if we're not in quotes;
435 '"' if we're in a double-quoted string;
436 '\'' if we're in a single-quoted string. */
437 int depth
= 0; /* Number of unclosed parens we've seen. */
440 for (scan
= s
; *scan
; scan
++)
446 else if (*scan
== '\\' && *(scan
+ 1))
449 else if (*scan
== c
&& ! quoted
&& depth
== 0)
451 else if (*scan
== '"' || *scan
== '\'')
453 else if (*scan
== '(' || *scan
== '<')
455 else if ((*scan
== ')' || *scan
== '>') && depth
> 0)
462 /* Determines if the gives string corresponds to an Objective-C method
463 representation, such as -[Foo bar:] or +[Foo bar]. Objective-C symbols
464 are allowed to have spaces and parentheses in them. */
467 is_objc_method_format (const char *s
)
469 if (s
== NULL
|| *s
== '\0')
471 /* Handle arguments with the format FILENAME:SYMBOL. */
472 if ((s
[0] == ':') && (strchr ("+-", s
[1]) != NULL
)
473 && (s
[2] == '[') && strchr(s
, ']'))
475 /* Handle arguments that are just SYMBOL. */
476 else if ((strchr ("+-", s
[0]) != NULL
) && (s
[1] == '[') && strchr(s
, ']'))
481 /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
482 operate on (ask user if necessary).
483 If CANONICAL is non-NULL return a corresponding array of mangled names
484 as canonical line specs there. */
486 static struct symtabs_and_lines
487 decode_line_2 (struct symbol
*sym_arr
[], int nelts
, int funfirstline
,
490 struct symtabs_and_lines values
, return_values
;
495 struct cleanup
*old_chain
;
496 char **canonical_arr
= (char **) NULL
;
497 const char *select_mode
= multiple_symbols_select_mode ();
499 if (select_mode
== multiple_symbols_cancel
)
501 canceled because the command is ambiguous\n\
502 See set/show multiple-symbol."));
504 values
.sals
= (struct symtab_and_line
*)
505 alloca (nelts
* sizeof (struct symtab_and_line
));
506 return_values
.sals
= (struct symtab_and_line
*)
507 xmalloc (nelts
* sizeof (struct symtab_and_line
));
508 old_chain
= make_cleanup (xfree
, return_values
.sals
);
512 canonical_arr
= (char **) xmalloc (nelts
* sizeof (char *));
513 make_cleanup (xfree
, canonical_arr
);
514 memset (canonical_arr
, 0, nelts
* sizeof (char *));
515 *canonical
= canonical_arr
;
521 init_sal (&return_values
.sals
[i
]); /* Initialize to zeroes. */
522 init_sal (&values
.sals
[i
]);
523 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
524 values
.sals
[i
] = find_function_start_sal (sym_arr
[i
], funfirstline
);
528 /* If select_mode is "all", then do not print the multiple-choice
529 menu and act as if the user had chosen choice "1" (all). */
530 if (select_mode
== multiple_symbols_all
531 || ui_out_is_mi_like_p (interp_ui_out (top_level_interpreter ())))
536 printf_unfiltered (_("[0] cancel\n[1] all\n"));
539 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
541 if (values
.sals
[i
].symtab
)
542 printf_unfiltered ("[%d] %s at %s:%d\n",
544 SYMBOL_PRINT_NAME (sym_arr
[i
]),
545 values
.sals
[i
].symtab
->filename
,
546 values
.sals
[i
].line
);
548 printf_unfiltered (_("[%d] %s at ?FILE:%d [No symtab? Probably broken debug info...]\n"),
550 SYMBOL_PRINT_NAME (sym_arr
[i
]),
551 values
.sals
[i
].line
);
555 printf_unfiltered (_("?HERE\n"));
559 prompt
= getenv ("PS2");
564 args
= command_line_input (prompt
, 0, "overload-choice");
567 if (args
== 0 || *args
== 0)
568 error_no_arg (_("one or more choice numbers"));
576 while (*arg1
>= '0' && *arg1
<= '9')
578 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
579 error (_("Arguments must be choice numbers."));
584 error (_("canceled"));
589 for (i
= 0; i
< nelts
; i
++)
591 if (canonical_arr
[i
] == NULL
)
593 symname
= DEPRECATED_SYMBOL_NAME (sym_arr
[i
]);
594 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
598 memcpy (return_values
.sals
, values
.sals
,
599 (nelts
* sizeof (struct symtab_and_line
)));
600 return_values
.nelts
= nelts
;
601 discard_cleanups (old_chain
);
602 return return_values
;
605 if (num
>= nelts
+ 2)
607 printf_unfiltered (_("No choice number %d.\n"), num
);
612 if (values
.sals
[num
].pc
)
616 symname
= DEPRECATED_SYMBOL_NAME (sym_arr
[num
]);
617 make_cleanup (xfree
, symname
);
618 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
620 return_values
.sals
[i
++] = values
.sals
[num
];
621 values
.sals
[num
].pc
= 0;
625 printf_unfiltered (_("duplicate request for %d ignored.\n"), num
);
630 while (*args
== ' ' || *args
== '\t')
633 return_values
.nelts
= i
;
634 discard_cleanups (old_chain
);
635 return return_values
;
638 /* The parser of linespec itself. */
640 /* Parse a string that specifies a line number.
641 Pass the address of a char * variable; that variable will be
642 advanced over the characters actually parsed.
646 LINENUM -- that line number in current file. PC returned is 0.
647 FILE:LINENUM -- that line in that file. PC returned is 0.
648 FUNCTION -- line number of openbrace of that function.
649 PC returned is the start of the function.
650 VARIABLE -- line number of definition of that variable.
652 FILE:FUNCTION -- likewise, but prefer functions in that file.
653 *EXPR -- line in which address EXPR appears.
655 This may all be followed by an "if EXPR", which we ignore.
657 FUNCTION may be an undebuggable function found in minimal symbol table.
659 If the argument FUNFIRSTLINE is nonzero, we want the first line
660 of real code inside a function when a function is specified, and it is
661 not OK to specify a variable or type to get its line number.
663 DEFAULT_SYMTAB specifies the file to use if none is specified.
664 It defaults to current_source_symtab.
665 DEFAULT_LINE specifies the line number to use for relative
666 line numbers (that start with signs). Defaults to current_source_line.
667 If CANONICAL is non-NULL, store an array of strings containing the canonical
668 line specs there if necessary. Currently overloaded member functions and
669 line numbers or static functions without a filename yield a canonical
670 line spec. The array and the line spec strings are allocated on the heap,
671 it is the callers responsibility to free them.
673 Note that it is possible to return zero for the symtab
674 if no file is validly specified. Callers must check that.
675 Also, the line number returned may be invalid.
677 If NOT_FOUND_PTR is not null, store a boolean true/false value at the location, based
678 on whether or not failure occurs due to an unknown function or file. In the case
679 where failure does occur due to an unknown function or file, do not issue an error
682 /* We allow single quotes in various places. This is a hideous
683 kludge, which exists because the completer can't yet deal with the
684 lack of single quotes. FIXME: write a linespec_completer which we
685 can use as appropriate instead of make_symbol_completion_list. */
687 struct symtabs_and_lines
688 decode_line_1 (char **argptr
, int funfirstline
, struct symtab
*default_symtab
,
689 int default_line
, char ***canonical
, int *not_found_ptr
)
693 /* If a file name is specified, this is its symtab. */
694 struct symtab
*file_symtab
= NULL
;
697 /* This is NULL if there are no parens in *ARGPTR, or a pointer to
698 the closing parenthesis if there are parens. */
700 /* This says whether or not something in *ARGPTR is quoted with
701 completer_quotes (i.e. with single quotes). */
703 /* Is part of *ARGPTR is enclosed in double quotes? */
704 int is_quote_enclosed
;
705 int is_objc_method
= 0;
706 char *saved_arg
= *argptr
;
711 /* Defaults have defaults. */
713 initialize_defaults (&default_symtab
, &default_line
);
715 /* See if arg is *PC. */
718 return decode_indirect (argptr
);
720 /* Set various flags. 'paren_pointer' is important for overload
721 checking, where we allow things like:
722 (gdb) break c::f(int)
725 set_flags (*argptr
, &is_quoted
, &paren_pointer
);
727 /* Check to see if it's a multipart linespec (with colons or
730 /* Locate the end of the first half of the linespec.
731 After the call, for instance, if the argptr string is "foo.c:123"
732 p will point at "123". If there is only one part, like "foo", p
733 will point to "". If this is a C++ name, like "A::B::foo", p will
734 point to "::B::foo". Argptr is not changed by this call. */
736 p
= locate_first_half (argptr
, &is_quote_enclosed
);
738 /* Check if this is an Objective-C method (anything that starts with
739 a '+' or '-' and a '['). */
740 if (is_objc_method_format (p
))
743 paren_pointer
= NULL
; /* Just a category name. Ignore it. */
746 /* Check if the symbol could be an Objective-C selector. */
749 struct symtabs_and_lines values
;
750 values
= decode_objc (argptr
, funfirstline
, NULL
,
751 canonical
, saved_arg
);
752 if (values
.sals
!= NULL
)
756 /* Does it look like there actually were two parts? */
758 if ((p
[0] == ':' || p
[0] == '.') && paren_pointer
== NULL
)
761 *argptr
= *argptr
+ 1;
763 /* Is it a C++ or Java compound data structure?
764 The check on p[1] == ':' is capturing the case of "::",
765 since p[0]==':' was checked above.
766 Note that the call to decode_compound does everything
767 for us, including the lookup on the symbol table, so we
770 if (p
[0] == '.' || p
[1] == ':')
771 return decode_compound (argptr
, funfirstline
, canonical
,
774 /* No, the first part is a filename; set s to be that file's
775 symtab. Also, move argptr past the filename. */
777 file_symtab
= symtab_from_filename (argptr
, p
, is_quote_enclosed
,
781 /* No one really seems to know why this was added. It certainly
782 breaks the command line, though, whenever the passed
783 name is of the form ClassName::Method. This bit of code
784 singles out the class name, and if funfirstline is set (for
785 example, you are setting a breakpoint at this function),
786 you get an error. This did not occur with earlier
787 verions, so I am ifdef'ing this out. 3/29/99 */
790 /* Check if what we have till now is a symbol name */
792 /* We may be looking at a template instantiation such
793 as "foo<int>". Check here whether we know about it,
794 instead of falling through to the code below which
795 handles ordinary function names, because that code
796 doesn't like seeing '<' and '>' in a name -- the
797 skip_quoted call doesn't go past them. So see if we
798 can figure it out right now. */
800 copy
= (char *) alloca (p
- *argptr
+ 1);
801 memcpy (copy
, *argptr
, p
- *argptr
);
802 copy
[p
- *argptr
] = '\000';
803 sym
= lookup_symbol (copy
, 0, VAR_DOMAIN
, 0, &sym_symtab
);
806 *argptr
= (*p
== '\'') ? p
+ 1 : p
;
807 return symbol_found (funfirstline
, canonical
, copy
, sym
,
810 /* Otherwise fall out from here and go to file/line spec
815 /* S is specified file's symtab, or 0 if no file specified.
816 arg no longer contains the file name. */
818 /* Check whether arg is all digits (and sign). */
821 if (*q
== '-' || *q
== '+')
823 while (*q
>= '0' && *q
<= '9')
826 if (q
!= *argptr
&& (*q
== 0 || *q
== ' ' || *q
== '\t' || *q
== ','))
827 /* We found a token consisting of all digits -- at least one digit. */
828 return decode_all_digits (argptr
, default_symtab
, default_line
,
829 canonical
, file_symtab
, q
);
831 /* Arg token is not digits => try it as a variable name
832 Find the next token (everything up to end or next whitespace). */
834 if (**argptr
== '$') /* May be a convenience variable. */
835 /* One or two $ chars possible. */
836 p
= skip_quoted (*argptr
+ (((*argptr
)[1] == '$') ? 2 : 1));
839 p
= skip_quoted (*argptr
);
841 error (_("Unmatched single quote."));
843 else if (is_objc_method
)
845 /* allow word separators in method names for Obj-C */
846 p
= skip_quoted_chars (*argptr
, NULL
, "");
848 else if (paren_pointer
!= NULL
)
850 p
= paren_pointer
+ 1;
854 p
= skip_quoted (*argptr
);
857 copy
= (char *) alloca (p
- *argptr
+ 1);
858 memcpy (copy
, *argptr
, p
- *argptr
);
859 copy
[p
- *argptr
] = '\0';
862 && copy
[0] == copy
[p
- *argptr
- 1]
863 && strchr (get_gdb_completer_quote_characters (), copy
[0]) != NULL
)
865 copy
[p
- *argptr
- 1] = '\0';
868 while (*p
== ' ' || *p
== '\t')
872 /* If it starts with $: may be a legitimate variable or routine name
873 (e.g. HP-UX millicode routines such as $$dyncall), or it may
874 be history value, or it may be a convenience variable. */
877 return decode_dollar (copy
, funfirstline
, default_symtab
,
878 canonical
, file_symtab
);
880 /* Look up that token as a variable.
881 If file specified, use that file's per-file block to start with. */
883 return decode_variable (copy
, funfirstline
, canonical
,
884 file_symtab
, not_found_ptr
);
889 /* Now, more helper functions for decode_line_1. Some conventions
890 that these functions follow:
892 Decode_line_1 typically passes along some of its arguments or local
893 variables to the subfunctions. It passes the variables by
894 reference if they are modified by the subfunction, and by value
897 Some of the functions have side effects that don't arise from
898 variables that are passed by reference. In particular, if a
899 function is passed ARGPTR as an argument, it modifies what ARGPTR
900 points to; typically, it advances *ARGPTR past whatever substring
901 it has just looked at. (If it doesn't modify *ARGPTR, then the
902 function gets passed *ARGPTR instead, which is then called ARG: see
903 set_flags, for example.) Also, functions that return a struct
904 symtabs_and_lines may modify CANONICAL, as in the description of
907 If a function returns a struct symtabs_and_lines, then that struct
908 will immediately make its way up the call chain to be returned by
909 decode_line_1. In particular, all of the functions decode_XXX
910 calculate the appropriate struct symtabs_and_lines, under the
911 assumption that their argument is of the form XXX. */
913 /* First, some functions to initialize stuff at the beggining of the
917 initialize_defaults (struct symtab
**default_symtab
, int *default_line
)
919 if (*default_symtab
== 0)
921 /* Use whatever we have for the default source line. We don't use
922 get_current_or_default_symtab_and_line as it can recurse and call
924 struct symtab_and_line cursal
=
925 get_current_source_symtab_and_line ();
927 *default_symtab
= cursal
.symtab
;
928 *default_line
= cursal
.line
;
933 set_flags (char *arg
, int *is_quoted
, char **paren_pointer
)
938 /* 'has_if' is for the syntax:
939 (gdb) break foo if (a==b)
941 if ((ii
= strstr (arg
, " if ")) != NULL
||
942 (ii
= strstr (arg
, "\tif ")) != NULL
||
943 (ii
= strstr (arg
, " if\t")) != NULL
||
944 (ii
= strstr (arg
, "\tif\t")) != NULL
||
945 (ii
= strstr (arg
, " if(")) != NULL
||
946 (ii
= strstr (arg
, "\tif( ")) != NULL
)
948 /* Temporarily zap out "if (condition)" to not confuse the
949 parenthesis-checking code below. This is undone below. Do not
957 && strchr (get_gdb_completer_quote_characters (),
960 *paren_pointer
= strchr (arg
, '(');
961 if (*paren_pointer
!= NULL
)
962 *paren_pointer
= strrchr (*paren_pointer
, ')');
964 /* Now that we're safely past the paren_pointer check, put back " if
965 (condition)" so outer layers can see it. */
972 /* Decode arg of the form *PC. */
974 static struct symtabs_and_lines
975 decode_indirect (char **argptr
)
977 struct symtabs_and_lines values
;
981 pc
= parse_and_eval_address_1 (argptr
);
983 values
.sals
= (struct symtab_and_line
*)
984 xmalloc (sizeof (struct symtab_and_line
));
987 values
.sals
[0] = find_pc_line (pc
, 0);
988 values
.sals
[0].pc
= pc
;
989 values
.sals
[0].section
= find_pc_overlay (pc
);
990 values
.sals
[0].explicit_pc
= 1;
997 /* Locate the first half of the linespec, ending in a colon, period,
998 or whitespace. (More or less.) Also, check to see if *ARGPTR is
999 enclosed in double quotes; if so, set is_quote_enclosed, advance
1000 ARGPTR past that and zero out the trailing double quote.
1001 If ARGPTR is just a simple name like "main", p will point to ""
1005 locate_first_half (char **argptr
, int *is_quote_enclosed
)
1011 /* Maybe we were called with a line range FILENAME:LINENUM,FILENAME:LINENUM
1012 and we must isolate the first half. Outer layers will call again later
1013 for the second half.
1015 Don't count commas that appear in argument lists of overloaded
1016 functions, or in quoted strings. It's stupid to go to this much
1017 trouble when the rest of the function is such an obvious roach hotel. */
1018 ii
= find_toplevel_char (*argptr
, ',');
1019 has_comma
= (ii
!= 0);
1021 /* Temporarily zap out second half to not confuse the code below.
1022 This is undone below. Do not change ii!! */
1028 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION. May also be
1029 CLASS::MEMBER, or NAMESPACE::NAME. Look for ':', but ignore
1035 *is_quote_enclosed
= 1;
1040 *is_quote_enclosed
= 0;
1045 char *temp_end
= find_template_name_end (p
);
1047 error (_("malformed template specification in command"));
1050 /* Check for a colon and a plus or minus and a [ (which
1051 indicates an Objective-C method) */
1052 if (is_objc_method_format (p
))
1056 /* Check for the end of the first half of the linespec. End of
1057 line, a tab, a double colon or the last single colon, or a
1058 space. But if enclosed in double quotes we do not break on
1063 && ((p
[1] == ':') || (strchr (p
+ 1, ':') == NULL
)))
1064 || ((p
[0] == ' ') && !*is_quote_enclosed
))
1066 if (p
[0] == '.' && strchr (p
, ':') == NULL
)
1068 /* Java qualified method. Find the *last* '.', since the
1069 others are package qualifiers. */
1070 for (p1
= p
; *p1
; p1
++)
1078 while (p
[0] == ' ' || p
[0] == '\t')
1081 /* If the closing double quote was left at the end, remove it. */
1082 if (*is_quote_enclosed
)
1084 char *closing_quote
= strchr (p
- 1, '"');
1085 if (closing_quote
&& closing_quote
[1] == '\0')
1086 *closing_quote
= '\0';
1089 /* Now that we've safely parsed the first half, put back ',' so
1090 outer layers can see it. */
1099 /* Here's where we recognise an Objective-C Selector. An Objective C
1100 selector may be implemented by more than one class, therefore it
1101 may represent more than one method/function. This gives us a
1102 situation somewhat analogous to C++ overloading. If there's more
1103 than one method that could represent the selector, then use some of
1104 the existing C++ code to let the user choose one. */
1106 struct symtabs_and_lines
1107 decode_objc (char **argptr
, int funfirstline
, struct symtab
*file_symtab
,
1108 char ***canonical
, char *saved_arg
)
1110 struct symtabs_and_lines values
;
1111 struct symbol
**sym_arr
= NULL
;
1112 struct symbol
*sym
= NULL
;
1114 struct block
*block
= NULL
;
1121 if (file_symtab
!= NULL
)
1122 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_symtab
), STATIC_BLOCK
);
1124 block
= get_selected_block (0);
1126 copy
= find_imps (file_symtab
, block
, *argptr
, NULL
, &i1
, &i2
);
1130 sym_arr
= (struct symbol
**) alloca ((i1
+ 1) * sizeof (struct symbol
*));
1133 copy
= find_imps (file_symtab
, block
, *argptr
, sym_arr
, &i1
, &i2
);
1137 /* i1 now represents the TOTAL number of matches found.
1138 i2 represents how many HIGH-LEVEL (struct symbol) matches,
1139 which will come first in the sym_arr array. Any low-level
1140 (minimal_symbol) matches will follow those. */
1146 /* Already a struct symbol. */
1151 sym
= find_pc_function (SYMBOL_VALUE_ADDRESS (sym_arr
[0]));
1152 if ((sym
!= NULL
) && strcmp (SYMBOL_LINKAGE_NAME (sym_arr
[0]), SYMBOL_LINKAGE_NAME (sym
)) != 0)
1154 warning (_("debugging symbol \"%s\" does not match selector; ignoring"), SYMBOL_LINKAGE_NAME (sym
));
1159 values
.sals
= (struct symtab_and_line
*) xmalloc (sizeof (struct symtab_and_line
));
1162 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1164 /* Canonicalize this, so it remains resolved for dylib loads. */
1165 values
.sals
[0] = find_function_start_sal (sym
, funfirstline
);
1166 build_canonical_line_spec (values
.sals
, SYMBOL_NATURAL_NAME (sym
), canonical
);
1170 /* The only match was a non-debuggable symbol. */
1171 values
.sals
[0].symtab
= NULL
;
1172 values
.sals
[0].line
= 0;
1173 values
.sals
[0].end
= 0;
1174 values
.sals
[0].pc
= SYMBOL_VALUE_ADDRESS (sym_arr
[0]);
1181 /* More than one match. The user must choose one or more. */
1182 return decode_line_2 (sym_arr
, i2
, funfirstline
, canonical
);
1188 /* This handles C++ and Java compound data structures. P should point
1189 at the first component separator, i.e. double-colon or period. As
1190 an example, on entrance to this function we could have ARGPTR
1191 pointing to "AAA::inA::fun" and P pointing to "::inA::fun". */
1193 static struct symtabs_and_lines
1194 decode_compound (char **argptr
, int funfirstline
, char ***canonical
,
1195 char *saved_arg
, char *p
)
1197 struct symtabs_and_lines values
;
1199 char *saved_arg2
= *argptr
;
1202 /* The symtab that SYM was found in. */
1203 struct symtab
*sym_symtab
;
1205 struct symbol
*sym_class
;
1206 struct symbol
**sym_arr
;
1209 /* First check for "global" namespace specification, of the form
1210 "::foo". If found, skip over the colons and jump to normal
1211 symbol processing. I.e. the whole line specification starts with
1212 "::" (note the condition that *argptr == p). */
1214 && ((*argptr
== p
) || (p
[-1] == ' ') || (p
[-1] == '\t')))
1217 /* Given our example "AAA::inA::fun", we have two cases to consider:
1219 1) AAA::inA is the name of a class. In that case, presumably it
1220 has a method called "fun"; we then look up that method using
1223 2) AAA::inA isn't the name of a class. In that case, either the
1224 user made a typo or AAA::inA is the name of a namespace.
1225 Either way, we just look up AAA::inA::fun with lookup_symbol.
1227 Thus, our first task is to find everything before the last set of
1228 double-colons and figure out if it's the name of a class. So we
1229 first loop through all of the double-colons. */
1231 p2
= p
; /* Save for restart. */
1233 /* This is very messy. Following the example above we have now the
1236 argptr -> "AAA::inA::fun
1237 saved_arg -> "AAA::inA::fun
1238 saved_arg2 -> "AAA::inA::fun
1239 p2 -> "::inA::fun". */
1241 /* In the loop below, with these strings, we'll make 2 passes, each
1242 is marked in comments.*/
1246 /* Move pointer up to next possible class/namespace token. */
1248 p
= p2
+ 1; /* Restart with old value +1. */
1250 /* PASS1: at this point p2->"::inA::fun", so p->":inA::fun",
1251 i.e. if there is a double-colon, p will now point to the
1253 /* PASS2: p2->"::fun", p->":fun" */
1255 /* Move pointer ahead to next double-colon. */
1256 while (*p
&& (p
[0] != ' ') && (p
[0] != '\t') && (p
[0] != '\''))
1260 temp_end
= find_template_name_end (p
);
1262 error (_("malformed template specification in command"));
1265 /* Note that, since, at the start of this loop, p would be
1266 pointing to the second colon in a double-colon, we only
1267 satisfy the condition below if there is another
1268 double-colon to the right (after). I.e. there is another
1269 component that can be a class or a namespace. I.e, if at
1270 the beginning of this loop (PASS1), we had
1271 p->":inA::fun", we'll trigger this when p has been
1272 advanced to point to "::fun". */
1273 /* PASS2: we will not trigger this. */
1274 else if ((p
[0] == ':') && (p
[1] == ':'))
1275 break; /* Found double-colon. */
1277 /* PASS2: We'll keep getting here, until p->"", at which point
1278 we exit this loop. */
1283 break; /* Out of the while (1). This would happen
1284 for instance if we have looked up
1285 unsuccessfully all the components of the
1286 string, and p->""(PASS2) */
1288 /* We get here if p points to ' ', '\t', '\'', "::" or ""(i.e
1290 /* Save restart for next time around. */
1292 /* Restore argptr as it was on entry to this function. */
1293 *argptr
= saved_arg2
;
1294 /* PASS1: at this point p->"::fun" argptr->"AAA::inA::fun",
1297 /* All ready for next pass through the loop. */
1301 /* Start of lookup in the symbol tables. */
1303 /* Lookup in the symbol table the substring between argptr and
1304 p. Note, this call changes the value of argptr. */
1305 /* Before the call, argptr->"AAA::inA::fun",
1306 p->"", p2->"::fun". After the call: argptr->"fun", p, p2
1308 sym_class
= lookup_prefix_sym (argptr
, p2
);
1310 /* If sym_class has been found, and if "AAA::inA" is a class, then
1311 we're in case 1 above. So we look up "fun" as a method of that
1314 (t
= check_typedef (SYMBOL_TYPE (sym_class
)),
1315 (TYPE_CODE (t
) == TYPE_CODE_STRUCT
1316 || TYPE_CODE (t
) == TYPE_CODE_UNION
)))
1318 /* Arg token is not digits => try it as a function name.
1319 Find the next token (everything up to end or next
1322 && strchr (get_gdb_completer_quote_characters (),
1325 p
= skip_quoted (*argptr
);
1326 *argptr
= *argptr
+ 1;
1330 /* At this point argptr->"fun". */
1332 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!= ':')
1334 /* At this point p->"". String ended. */
1337 /* Allocate our own copy of the substring between argptr and
1339 copy
= (char *) alloca (p
- *argptr
+ 1);
1340 memcpy (copy
, *argptr
, p
- *argptr
);
1341 copy
[p
- *argptr
] = '\0';
1343 && copy
[p
- *argptr
- 1]
1344 && strchr (get_gdb_completer_quote_characters (),
1345 copy
[p
- *argptr
- 1]) != NULL
)
1346 copy
[p
- *argptr
- 1] = '\0';
1348 /* At this point copy->"fun", p->"" */
1350 /* No line number may be specified. */
1351 while (*p
== ' ' || *p
== '\t')
1354 /* At this point arptr->"". */
1356 /* Look for copy as a method of sym_class. */
1357 /* At this point copy->"fun", sym_class is "AAA:inA",
1358 saved_arg->"AAA::inA::fun". This concludes the scanning of
1359 the string for possible components matches. If we find it
1360 here, we return. If not, and we are at the and of the string,
1361 we'll lookup the whole string in the symbol tables. */
1363 return find_method (funfirstline
, canonical
, saved_arg
,
1364 copy
, t
, sym_class
);
1366 } /* End if symbol found */
1369 /* We couldn't find a class, so we're in case 2 above. We check the
1370 entire name as a symbol instead. */
1372 copy
= (char *) alloca (p
- saved_arg2
+ 1);
1373 memcpy (copy
, saved_arg2
, p
- saved_arg2
);
1374 /* Note: if is_quoted should be true, we snuff out quote here
1376 copy
[p
- saved_arg2
] = '\000';
1377 /* Set argptr to skip over the name. */
1378 *argptr
= (*p
== '\'') ? p
+ 1 : p
;
1380 /* Look up entire name */
1381 sym
= lookup_symbol (copy
, 0, VAR_DOMAIN
, 0, &sym_symtab
);
1383 return symbol_found (funfirstline
, canonical
, copy
, sym
,
1386 /* Couldn't find any interpretation as classes/namespaces, so give
1387 up. The quotes are important if copy is empty. */
1388 cplusplus_error (saved_arg
,
1389 "Can't find member of namespace, class, struct, or union named \"%s\"\n",
1393 /* Next come some helper functions for decode_compound. */
1395 /* Return the symbol corresponding to the substring of *ARGPTR ending
1396 at P, allowing whitespace. Also, advance *ARGPTR past the symbol
1397 name in question, the compound object separator ("::" or "."), and
1398 whitespace. Note that *ARGPTR is changed whether or not the
1399 lookup_symbol call finds anything (i.e we return NULL). As an
1400 example, say ARGPTR is "AAA::inA::fun" and P is "::inA::fun". */
1402 static struct symbol
*
1403 lookup_prefix_sym (char **argptr
, char *p
)
1408 /* Extract the class name. */
1410 while (p
!= *argptr
&& p
[-1] == ' ')
1412 copy
= (char *) alloca (p
- *argptr
+ 1);
1413 memcpy (copy
, *argptr
, p
- *argptr
);
1414 copy
[p
- *argptr
] = 0;
1416 /* Discard the class name from the argptr. */
1417 p
= p1
+ (p1
[0] == ':' ? 2 : 1);
1418 while (*p
== ' ' || *p
== '\t')
1422 /* At this point p1->"::inA::fun", p->"inA::fun" copy->"AAA",
1423 argptr->"inA::fun" */
1425 return lookup_symbol (copy
, 0, STRUCT_DOMAIN
, 0,
1426 (struct symtab
**) NULL
);
1429 /* This finds the method COPY in the class whose type is T and whose
1430 symbol is SYM_CLASS. */
1432 static struct symtabs_and_lines
1433 find_method (int funfirstline
, char ***canonical
, char *saved_arg
,
1434 char *copy
, struct type
*t
, struct symbol
*sym_class
)
1436 struct symtabs_and_lines values
;
1437 struct symbol
*sym
= NULL
;
1438 int i1
; /* Counter for the symbol array. */
1439 struct symbol
**sym_arr
= alloca (total_number_of_methods (t
)
1440 * sizeof (struct symbol
*));
1442 /* Find all methods with a matching name, and put them in
1445 i1
= collect_methods (copy
, t
, sym_class
, sym_arr
);
1449 /* There is exactly one field with that name. */
1452 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1454 values
.sals
= (struct symtab_and_line
*)
1455 xmalloc (sizeof (struct symtab_and_line
));
1457 values
.sals
[0] = find_function_start_sal (sym
,
1469 /* There is more than one field with that name
1470 (overloaded). Ask the user which one to use. */
1471 return decode_line_2 (sym_arr
, i1
, funfirstline
, canonical
);
1477 if (is_operator_name (copy
))
1479 tmp
= (char *) alloca (strlen (copy
+ 3) + 9);
1480 strcpy (tmp
, "operator ");
1481 strcat (tmp
, copy
+ 3);
1486 cplusplus_error (saved_arg
,
1487 "the class `%s' does not have destructor defined\n",
1488 SYMBOL_PRINT_NAME (sym_class
));
1490 cplusplus_error (saved_arg
,
1491 "the class %s does not have any method named %s\n",
1492 SYMBOL_PRINT_NAME (sym_class
), tmp
);
1496 /* Find all methods named COPY in the class whose type is T, and put
1497 them in SYM_ARR. Return the number of methods found. */
1500 collect_methods (char *copy
, struct type
*t
,
1501 struct symbol
*sym_class
, struct symbol
**sym_arr
)
1503 int i1
= 0; /* Counter for the symbol array. */
1505 if (destructor_name_p (copy
, t
))
1507 /* Destructors are a special case. */
1508 int m_index
, f_index
;
1510 if (get_destructor_fn_field (t
, &m_index
, &f_index
))
1512 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, m_index
);
1515 lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f
, f_index
),
1516 NULL
, VAR_DOMAIN
, (int *) NULL
,
1517 (struct symtab
**) NULL
);
1523 i1
= find_methods (t
, copy
, SYMBOL_LANGUAGE (sym_class
), sym_arr
);
1530 /* Return the symtab associated to the filename given by the substring
1531 of *ARGPTR ending at P, and advance ARGPTR past that filename. If
1532 NOT_FOUND_PTR is not null and the source file is not found, store
1533 boolean true at the location pointed to and do not issue an
1536 static struct symtab
*
1537 symtab_from_filename (char **argptr
, char *p
, int is_quote_enclosed
,
1542 struct symtab
*file_symtab
;
1545 while (p
!= *argptr
&& p
[-1] == ' ')
1547 if ((*p
== '"') && is_quote_enclosed
)
1549 copy
= (char *) alloca (p
- *argptr
+ 1);
1550 memcpy (copy
, *argptr
, p
- *argptr
);
1551 /* It may have the ending quote right after the file name. */
1552 if (is_quote_enclosed
&& copy
[p
- *argptr
- 1] == '"')
1553 copy
[p
- *argptr
- 1] = 0;
1555 copy
[p
- *argptr
] = 0;
1557 /* Find that file's data. */
1558 file_symtab
= lookup_symtab (copy
);
1559 if (file_symtab
== 0)
1561 if (!have_full_symbols () && !have_partial_symbols ())
1562 error (_("No symbol table is loaded. Use the \"file\" command."));
1565 throw_error (NOT_FOUND_ERROR
, _("No source file named %s."), copy
);
1568 /* Discard the file name from the arg. */
1570 while (*p
== ' ' || *p
== '\t')
1579 /* This decodes a line where the argument is all digits (possibly
1580 preceded by a sign). Q should point to the end of those digits;
1581 the other arguments are as usual. */
1583 static struct symtabs_and_lines
1584 decode_all_digits (char **argptr
, struct symtab
*default_symtab
,
1585 int default_line
, char ***canonical
,
1586 struct symtab
*file_symtab
, char *q
)
1589 struct symtabs_and_lines values
;
1590 struct symtab_and_line val
;
1598 /* We might need a canonical line spec if no file was specified. */
1599 int need_canonical
= (file_symtab
== NULL
) ? 1 : 0;
1603 /* This is where we need to make sure that we have good defaults.
1604 We must guarantee that this section of code is never executed
1605 when we are called with just a function name, since
1606 set_default_source_symtab_and_line uses
1607 select_source_symtab that calls us with such an argument. */
1609 if (file_symtab
== 0 && default_symtab
== 0)
1611 /* Make sure we have at least a default source file. */
1612 set_default_source_symtab_and_line ();
1613 initialize_defaults (&default_symtab
, &default_line
);
1616 if (**argptr
== '+')
1617 sign
= plus
, (*argptr
)++;
1618 else if (**argptr
== '-')
1619 sign
= minus
, (*argptr
)++;
1620 val
.line
= atoi (*argptr
);
1626 if (file_symtab
== 0)
1627 val
.line
= default_line
+ val
.line
;
1632 if (file_symtab
== 0)
1633 val
.line
= default_line
- val
.line
;
1638 break; /* No need to adjust val.line. */
1641 while (*q
== ' ' || *q
== '\t')
1644 if (file_symtab
== 0)
1645 file_symtab
= default_symtab
;
1647 /* It is possible that this source file has more than one symtab,
1648 and that the new line number specification has moved us from the
1649 default (in file_symtab) to a new one. */
1650 val
.symtab
= find_line_symtab (file_symtab
, val
.line
, NULL
, NULL
);
1651 if (val
.symtab
== 0)
1652 val
.symtab
= file_symtab
;
1655 values
.sals
= (struct symtab_and_line
*)
1656 xmalloc (sizeof (struct symtab_and_line
));
1657 values
.sals
[0] = val
;
1660 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
1661 values
.sals
[0].explicit_line
= 1;
1667 /* Decode a linespec starting with a dollar sign. */
1669 static struct symtabs_and_lines
1670 decode_dollar (char *copy
, int funfirstline
, struct symtab
*default_symtab
,
1671 char ***canonical
, struct symtab
*file_symtab
)
1675 int need_canonical
= 0;
1676 struct symtabs_and_lines values
;
1677 struct symtab_and_line val
;
1680 /* The symtab that SYM was found in. */
1681 struct symtab
*sym_symtab
;
1682 struct minimal_symbol
*msymbol
;
1684 p
= (copy
[1] == '$') ? copy
+ 2 : copy
+ 1;
1685 while (*p
>= '0' && *p
<= '9')
1687 if (!*p
) /* Reached end of token without hitting non-digit. */
1689 /* We have a value history reference. */
1690 sscanf ((copy
[1] == '$') ? copy
+ 2 : copy
+ 1, "%d", &index
);
1691 valx
= access_value_history ((copy
[1] == '$') ? -index
: index
);
1692 if (TYPE_CODE (value_type (valx
)) != TYPE_CODE_INT
)
1693 error (_("History values used in line specs must have integer values."));
1697 /* Not all digits -- may be user variable/function or a
1698 convenience variable. */
1700 /* Look up entire name as a symbol first. */
1701 sym
= lookup_symbol (copy
, 0, VAR_DOMAIN
, 0, &sym_symtab
);
1702 file_symtab
= (struct symtab
*) NULL
;
1704 /* Symbol was found --> jump to normal symbol processing. */
1706 return symbol_found (funfirstline
, canonical
, copy
, sym
,
1709 /* If symbol was not found, look in minimal symbol tables. */
1710 msymbol
= lookup_minimal_symbol (copy
, NULL
, NULL
);
1711 /* Min symbol was found --> jump to minsym processing. */
1713 return minsym_found (funfirstline
, msymbol
);
1715 /* Not a user variable or function -- must be convenience variable. */
1716 valx
= value_of_internalvar (lookup_internalvar (copy
+ 1));
1717 if (TYPE_CODE (value_type (valx
)) != TYPE_CODE_INT
)
1718 error (_("Convenience variables used in line specs must have integer values."));
1723 /* Either history value or convenience value from above, in valx. */
1724 val
.symtab
= file_symtab
? file_symtab
: default_symtab
;
1725 val
.line
= value_as_long (valx
);
1728 values
.sals
= (struct symtab_and_line
*) xmalloc (sizeof val
);
1729 values
.sals
[0] = val
;
1733 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
1740 /* Decode a linespec that's a variable. If FILE_SYMTAB is non-NULL,
1741 look in that symtab's static variables first. If NOT_FOUND_PTR is not NULL and
1742 the function cannot be found, store boolean true in the location pointed to
1743 and do not issue an error message. */
1745 static struct symtabs_and_lines
1746 decode_variable (char *copy
, int funfirstline
, char ***canonical
,
1747 struct symtab
*file_symtab
, int *not_found_ptr
)
1750 /* The symtab that SYM was found in. */
1751 struct symtab
*sym_symtab
;
1753 struct minimal_symbol
*msymbol
;
1755 sym
= lookup_symbol (copy
,
1757 ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_symtab
),
1759 : get_selected_block (0)),
1760 VAR_DOMAIN
, 0, &sym_symtab
);
1763 return symbol_found (funfirstline
, canonical
, copy
, sym
,
1764 file_symtab
, sym_symtab
);
1766 msymbol
= lookup_minimal_symbol (copy
, NULL
, NULL
);
1768 if (msymbol
!= NULL
)
1769 return minsym_found (funfirstline
, msymbol
);
1771 if (!have_full_symbols () &&
1772 !have_partial_symbols () && !have_minimal_symbols ())
1773 error (_("No symbol table is loaded. Use the \"file\" command."));
1777 throw_error (NOT_FOUND_ERROR
, _("Function \"%s\" not defined."), copy
);
1783 /* Now come some functions that are called from multiple places within
1786 /* We've found a symbol SYM to associate with our linespec; build a
1787 corresponding struct symtabs_and_lines. */
1789 static struct symtabs_and_lines
1790 symbol_found (int funfirstline
, char ***canonical
, char *copy
,
1791 struct symbol
*sym
, struct symtab
*file_symtab
,
1792 struct symtab
*sym_symtab
)
1794 struct symtabs_and_lines values
;
1796 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1798 /* Arg is the name of a function */
1799 values
.sals
= (struct symtab_and_line
*)
1800 xmalloc (sizeof (struct symtab_and_line
));
1801 values
.sals
[0] = find_function_start_sal (sym
, funfirstline
);
1804 /* Don't use the SYMBOL_LINE; if used at all it points to
1805 the line containing the parameters or thereabouts, not
1806 the first line of code. */
1808 /* We might need a canonical line spec if it is a static
1810 if (file_symtab
== 0)
1812 struct blockvector
*bv
= BLOCKVECTOR (sym_symtab
);
1813 struct block
*b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1814 if (lookup_block_symbol (b
, copy
, NULL
, VAR_DOMAIN
) != NULL
)
1815 build_canonical_line_spec (values
.sals
, copy
, canonical
);
1822 error (_("\"%s\" is not a function"), copy
);
1823 else if (SYMBOL_LINE (sym
) != 0)
1825 /* We know its line number. */
1826 values
.sals
= (struct symtab_and_line
*)
1827 xmalloc (sizeof (struct symtab_and_line
));
1829 memset (&values
.sals
[0], 0, sizeof (values
.sals
[0]));
1830 values
.sals
[0].symtab
= sym_symtab
;
1831 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1835 /* This can happen if it is compiled with a compiler which doesn't
1836 put out line numbers for variables. */
1837 /* FIXME: Shouldn't we just set .line and .symtab to zero
1838 and return? For example, "info line foo" could print
1840 error (_("Line number not known for symbol \"%s\""), copy
);
1844 /* We've found a minimal symbol MSYMBOL to associate with our
1845 linespec; build a corresponding struct symtabs_and_lines. */
1847 static struct symtabs_and_lines
1848 minsym_found (int funfirstline
, struct minimal_symbol
*msymbol
)
1850 struct objfile
*objfile
= msymbol_objfile (msymbol
);
1851 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1852 struct symtabs_and_lines values
;
1855 values
.sals
= (struct symtab_and_line
*)
1856 xmalloc (sizeof (struct symtab_and_line
));
1857 values
.sals
[0] = find_pc_sect_line (SYMBOL_VALUE_ADDRESS (msymbol
),
1858 (struct bfd_section
*) 0, 0);
1859 values
.sals
[0].section
= SYMBOL_BFD_SECTION (msymbol
);
1861 /* The minimal symbol might point to a function descriptor;
1862 resolve it to the actual code address instead. */
1863 pc
= gdbarch_convert_from_func_ptr_addr (gdbarch
,
1866 if (pc
!= values
.sals
[0].pc
)
1867 values
.sals
[0] = find_pc_sect_line (pc
, NULL
, 0);
1871 struct symtab_and_line sal
;
1873 values
.sals
[0].pc
= find_function_start_pc (gdbarch
,
1875 values
.sals
[0].section
);
1877 sal
= find_pc_sect_line (values
.sals
[0].pc
, values
.sals
[0].section
, 0);
1879 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
1880 line is still part of the same function. If there is no
1881 line information here, sal.pc will be the passed in PC. */
1882 if (sal
.pc
!= values
.sals
[0].pc
1883 && (lookup_minimal_symbol_by_pc_section (values
.sals
[0].pc
,
1884 values
.sals
[0].section
)
1885 == lookup_minimal_symbol_by_pc_section (sal
.end
,
1886 values
.sals
[0].section
)))
1887 /* Recalculate the line number (might not be N+1). */
1888 values
.sals
[0] = find_pc_sect_line (sal
.end
, values
.sals
[0].section
, 0);
This page took 0.069502 seconds and 5 git commands to generate.