1 /* Parser for linespec for the GNU debugger, GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
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 2 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, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
33 #include "completer.h"
35 #include "parser-defs.h"
37 #include "objc-lang.h"
39 #include "exceptions.h"
41 /* We share this one with symtab.c, but it is not exported widely. */
43 extern char *operator_chars (char *, char **);
45 /* Prototypes for local functions */
47 static void initialize_defaults (struct symtab
**default_symtab
,
50 static void set_flags (char *arg
, int *is_quoted
, char **paren_pointer
);
52 static struct symtabs_and_lines
decode_indirect (char **argptr
);
54 static char *locate_first_half (char **argptr
, int *is_quote_enclosed
);
56 static struct symtabs_and_lines
decode_objc (char **argptr
,
58 struct symtab
*file_symtab
,
62 static struct symtabs_and_lines
decode_compound (char **argptr
,
68 static struct symbol
*lookup_prefix_sym (char **argptr
, char *p
);
70 static struct symtabs_and_lines
find_method (int funfirstline
,
75 struct symbol
*sym_class
);
77 static int collect_methods (char *copy
, struct type
*t
,
78 struct symbol
**sym_arr
);
80 static NORETURN
void cplusplus_error (const char *name
,
82 ATTR_NORETURN
ATTR_FORMAT (printf
, 2, 3);
84 static int total_number_of_methods (struct type
*type
);
86 static int find_methods (struct type
*, char *, struct symbol
**);
88 static int add_matching_methods (int method_counter
, struct type
*t
,
89 struct symbol
**sym_arr
);
91 static int add_constructors (int method_counter
, struct type
*t
,
92 struct symbol
**sym_arr
);
94 static void build_canonical_line_spec (struct symtab_and_line
*,
97 static char *find_toplevel_char (char *s
, char c
);
99 static int is_objc_method_format (const char *s
);
101 static struct symtabs_and_lines
decode_line_2 (struct symbol
*[],
104 static struct symtab
*symtab_from_filename (char **argptr
,
105 char *p
, int is_quote_enclosed
,
109 symtabs_and_lines
decode_all_digits (char **argptr
,
110 struct symtab
*default_symtab
,
113 struct symtab
*file_symtab
,
116 static struct symtabs_and_lines
decode_dollar (char *copy
,
118 struct symtab
*default_symtab
,
120 struct symtab
*file_symtab
);
122 static struct symtabs_and_lines
decode_variable (char *copy
,
125 struct symtab
*file_symtab
,
129 symtabs_and_lines
symbol_found (int funfirstline
,
133 struct symtab
*file_symtab
,
134 struct symtab
*sym_symtab
);
137 symtabs_and_lines
minsym_found (int funfirstline
,
138 struct minimal_symbol
*msymbol
);
140 /* Helper functions. */
142 /* Issue a helpful hint on using the command completion feature on
143 single quoted demangled C++ symbols as part of the completion
147 cplusplus_error (const char *name
, const char *fmt
, ...)
149 struct ui_file
*tmp_stream
;
150 tmp_stream
= mem_fileopen ();
151 make_cleanup_ui_file_delete (tmp_stream
);
155 va_start (args
, fmt
);
156 vfprintf_unfiltered (tmp_stream
, fmt
, args
);
160 while (*name
== '\'')
162 fprintf_unfiltered (tmp_stream
,
163 ("Hint: try '%s<TAB> or '%s<ESC-?>\n"
164 "(Note leading single quote.)"),
166 error_stream (tmp_stream
);
169 /* Return the number of methods described for TYPE, including the
170 methods from types it derives from. This can't be done in the symbol
171 reader because the type of the baseclass might still be stubbed
172 when the definition of the derived class is parsed. */
175 total_number_of_methods (struct type
*type
)
180 CHECK_TYPEDEF (type
);
181 if (TYPE_CPLUS_SPECIFIC (type
) == NULL
)
183 count
= TYPE_NFN_FIELDS_TOTAL (type
);
185 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
186 count
+= total_number_of_methods (TYPE_BASECLASS (type
, n
));
191 /* Recursive helper function for decode_line_1.
192 Look for methods named NAME in type T.
193 Return number of matches.
194 Put matches in SYM_ARR, which should have been allocated with
195 a size of total_number_of_methods (T) * sizeof (struct symbol *).
196 Note that this function is g++ specific. */
199 find_methods (struct type
*t
, char *name
, struct symbol
**sym_arr
)
203 char *class_name
= type_name_no_tag (t
);
205 /* Ignore this class if it doesn't have a name. This is ugly, but
206 unless we figure out how to get the physname without the name of
207 the class, then the loop can't do any good. */
209 && (lookup_symbol (class_name
, (struct block
*) NULL
,
210 STRUCT_DOMAIN
, (int *) NULL
,
211 (struct symtab
**) NULL
)))
214 int name_len
= strlen (name
);
218 /* Loop over each method name. At this level, all overloads of a name
219 are counted as a single name. There is an inner loop which loops over
222 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
226 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
229 if (strncmp (method_name
, "__", 2) == 0 ||
230 strncmp (method_name
, "op", 2) == 0 ||
231 strncmp (method_name
, "type", 4) == 0)
233 if (cplus_demangle_opname (method_name
, dem_opname
, DMGL_ANSI
))
234 method_name
= dem_opname
;
235 else if (cplus_demangle_opname (method_name
, dem_opname
, 0))
236 method_name
= dem_opname
;
239 if (strcmp_iw (name
, method_name
) == 0)
240 /* Find all the overloaded methods with that name. */
241 i1
+= add_matching_methods (method_counter
, t
,
243 else if (strncmp (class_name
, name
, name_len
) == 0
244 && (class_name
[name_len
] == '\0'
245 || class_name
[name_len
] == '<'))
246 i1
+= add_constructors (method_counter
, t
,
251 /* Only search baseclasses if there is no match yet, since names in
252 derived classes override those in baseclasses.
254 FIXME: The above is not true; it is only true of member functions
255 if they have the same number of arguments (??? - section 13.1 of the
256 ARM says the function members are not in the same scope but doesn't
257 really spell out the rules in a way I understand. In any case, if
258 the number of arguments differ this is a case in which we can overload
259 rather than hiding without any problem, and gcc 2.4.5 does overload
260 rather than hiding in this case). */
263 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
264 i1
+= find_methods (TYPE_BASECLASS (t
, ibase
), name
, sym_arr
+ i1
);
269 /* Add the symbols associated to methods of the class whose type is T
270 and whose name matches the method indexed by METHOD_COUNTER in the
271 array SYM_ARR. Return the number of methods added. */
274 add_matching_methods (int method_counter
, struct type
*t
,
275 struct symbol
**sym_arr
)
280 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
287 f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
289 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
293 tmp_name
= gdb_mangle_name (t
,
296 phys_name
= alloca (strlen (tmp_name
) + 1);
297 strcpy (phys_name
, tmp_name
);
301 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
303 /* Destructor is handled by caller, don't add it to
305 if (is_destructor_name (phys_name
) != 0)
308 sym_arr
[i1
] = lookup_symbol (phys_name
,
311 (struct symtab
**) NULL
);
316 /* This error message gets printed, but the method
317 still seems to be found
318 fputs_filtered("(Cannot find method ", gdb_stdout);
319 fprintf_symbol_filtered (gdb_stdout, phys_name,
321 DMGL_PARAMS | DMGL_ANSI);
322 fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
330 /* Add the symbols associated to constructors of the class whose type
331 is CLASS_TYPE and which are indexed by by METHOD_COUNTER to the
332 array SYM_ARR. Return the number of methods added. */
335 add_constructors (int method_counter
, struct type
*t
,
336 struct symbol
**sym_arr
)
341 /* For GCC 3.x and stabs, constructors and destructors
342 have names like __base_ctor and __complete_dtor.
343 Check the physname for now if we're looking for a
346 = TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
353 f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
355 /* GCC 3.x will never produce stabs stub methods, so
356 we don't need to handle this case. */
357 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
359 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
360 if (! is_constructor_name (phys_name
))
363 /* If this method is actually defined, include it in the
365 sym_arr
[i1
] = lookup_symbol (phys_name
,
368 (struct symtab
**) NULL
);
376 /* Helper function for decode_line_1.
377 Build a canonical line spec in CANONICAL if it is non-NULL and if
378 the SAL has a symtab.
379 If SYMNAME is non-NULL the canonical line spec is `filename:symname'.
380 If SYMNAME is NULL the line number from SAL is used and the canonical
381 line spec is `filename:linenum'. */
384 build_canonical_line_spec (struct symtab_and_line
*sal
, char *symname
,
387 char **canonical_arr
;
388 char *canonical_name
;
390 struct symtab
*s
= sal
->symtab
;
392 if (s
== (struct symtab
*) NULL
393 || s
->filename
== (char *) NULL
394 || canonical
== (char ***) NULL
)
397 canonical_arr
= (char **) xmalloc (sizeof (char *));
398 *canonical
= canonical_arr
;
400 filename
= s
->filename
;
403 canonical_name
= xmalloc (strlen (filename
) + strlen (symname
) + 2);
404 sprintf (canonical_name
, "%s:%s", filename
, symname
);
408 canonical_name
= xmalloc (strlen (filename
) + 30);
409 sprintf (canonical_name
, "%s:%d", filename
, sal
->line
);
411 canonical_arr
[0] = canonical_name
;
416 /* Find an instance of the character C in the string S that is outside
417 of all parenthesis pairs, single-quoted strings, and double-quoted
418 strings. Also, ignore the char within a template name, like a ','
419 within foo<int, int>. */
422 find_toplevel_char (char *s
, char c
)
424 int quoted
= 0; /* zero if we're not in quotes;
425 '"' if we're in a double-quoted string;
426 '\'' if we're in a single-quoted string. */
427 int depth
= 0; /* Number of unclosed parens we've seen. */
430 for (scan
= s
; *scan
; scan
++)
436 else if (*scan
== '\\' && *(scan
+ 1))
439 else if (*scan
== c
&& ! quoted
&& depth
== 0)
441 else if (*scan
== '"' || *scan
== '\'')
443 else if (*scan
== '(' || *scan
== '<')
445 else if ((*scan
== ')' || *scan
== '>') && depth
> 0)
452 /* Determines if the gives string corresponds to an Objective-C method
453 representation, such as -[Foo bar:] or +[Foo bar]. Objective-C symbols
454 are allowed to have spaces and parentheses in them. */
457 is_objc_method_format (const char *s
)
459 if (s
== NULL
|| *s
== '\0')
461 /* Handle arguments with the format FILENAME:SYMBOL. */
462 if ((s
[0] == ':') && (strchr ("+-", s
[1]) != NULL
)
463 && (s
[2] == '[') && strchr(s
, ']'))
465 /* Handle arguments that are just SYMBOL. */
466 else if ((strchr ("+-", s
[0]) != NULL
) && (s
[1] == '[') && strchr(s
, ']'))
471 /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
472 operate on (ask user if necessary).
473 If CANONICAL is non-NULL return a corresponding array of mangled names
474 as canonical line specs there. */
476 static struct symtabs_and_lines
477 decode_line_2 (struct symbol
*sym_arr
[], int nelts
, int funfirstline
,
480 struct symtabs_and_lines values
, return_values
;
485 struct cleanup
*old_chain
;
486 char **canonical_arr
= (char **) NULL
;
488 values
.sals
= (struct symtab_and_line
*)
489 alloca (nelts
* sizeof (struct symtab_and_line
));
490 return_values
.sals
= (struct symtab_and_line
*)
491 xmalloc (nelts
* sizeof (struct symtab_and_line
));
492 old_chain
= make_cleanup (xfree
, return_values
.sals
);
496 canonical_arr
= (char **) xmalloc (nelts
* sizeof (char *));
497 make_cleanup (xfree
, canonical_arr
);
498 memset (canonical_arr
, 0, nelts
* sizeof (char *));
499 *canonical
= canonical_arr
;
503 printf_unfiltered (_("[0] cancel\n[1] all\n"));
506 init_sal (&return_values
.sals
[i
]); /* Initialize to zeroes. */
507 init_sal (&values
.sals
[i
]);
508 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
510 values
.sals
[i
] = find_function_start_sal (sym_arr
[i
], funfirstline
);
511 if (values
.sals
[i
].symtab
)
512 printf_unfiltered ("[%d] %s at %s:%d\n",
514 SYMBOL_PRINT_NAME (sym_arr
[i
]),
515 values
.sals
[i
].symtab
->filename
,
516 values
.sals
[i
].line
);
518 printf_unfiltered (_("[%d] %s at ?FILE:%d [No symtab? Probably broken debug info...]\n"),
520 SYMBOL_PRINT_NAME (sym_arr
[i
]),
521 values
.sals
[i
].line
);
525 printf_unfiltered (_("?HERE\n"));
529 prompt
= getenv ("PS2");
534 args
= command_line_input (prompt
, 0, "overload-choice");
536 if (args
== 0 || *args
== 0)
537 error_no_arg (_("one or more choice numbers"));
545 while (*arg1
>= '0' && *arg1
<= '9')
547 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
548 error (_("Arguments must be choice numbers."));
553 error (_("canceled"));
558 for (i
= 0; i
< nelts
; i
++)
560 if (canonical_arr
[i
] == NULL
)
562 symname
= DEPRECATED_SYMBOL_NAME (sym_arr
[i
]);
563 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
567 memcpy (return_values
.sals
, values
.sals
,
568 (nelts
* sizeof (struct symtab_and_line
)));
569 return_values
.nelts
= nelts
;
570 discard_cleanups (old_chain
);
571 return return_values
;
574 if (num
>= nelts
+ 2)
576 printf_unfiltered (_("No choice number %d.\n"), num
);
581 if (values
.sals
[num
].pc
)
585 symname
= DEPRECATED_SYMBOL_NAME (sym_arr
[num
]);
586 make_cleanup (xfree
, symname
);
587 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
589 return_values
.sals
[i
++] = values
.sals
[num
];
590 values
.sals
[num
].pc
= 0;
594 printf_unfiltered (_("duplicate request for %d ignored.\n"), num
);
599 while (*args
== ' ' || *args
== '\t')
602 return_values
.nelts
= i
;
603 discard_cleanups (old_chain
);
604 return return_values
;
607 /* The parser of linespec itself. */
609 /* Parse a string that specifies a line number.
610 Pass the address of a char * variable; that variable will be
611 advanced over the characters actually parsed.
615 LINENUM -- that line number in current file. PC returned is 0.
616 FILE:LINENUM -- that line in that file. PC returned is 0.
617 FUNCTION -- line number of openbrace of that function.
618 PC returned is the start of the function.
619 VARIABLE -- line number of definition of that variable.
621 FILE:FUNCTION -- likewise, but prefer functions in that file.
622 *EXPR -- line in which address EXPR appears.
624 This may all be followed by an "if EXPR", which we ignore.
626 FUNCTION may be an undebuggable function found in minimal symbol table.
628 If the argument FUNFIRSTLINE is nonzero, we want the first line
629 of real code inside a function when a function is specified, and it is
630 not OK to specify a variable or type to get its line number.
632 DEFAULT_SYMTAB specifies the file to use if none is specified.
633 It defaults to current_source_symtab.
634 DEFAULT_LINE specifies the line number to use for relative
635 line numbers (that start with signs). Defaults to current_source_line.
636 If CANONICAL is non-NULL, store an array of strings containing the canonical
637 line specs there if necessary. Currently overloaded member functions and
638 line numbers or static functions without a filename yield a canonical
639 line spec. The array and the line spec strings are allocated on the heap,
640 it is the callers responsibility to free them.
642 Note that it is possible to return zero for the symtab
643 if no file is validly specified. Callers must check that.
644 Also, the line number returned may be invalid.
646 If NOT_FOUND_PTR is not null, store a boolean true/false value at the location, based
647 on whether or not failure occurs due to an unknown function or file. In the case
648 where failure does occur due to an unknown function or file, do not issue an error
651 /* We allow single quotes in various places. This is a hideous
652 kludge, which exists because the completer can't yet deal with the
653 lack of single quotes. FIXME: write a linespec_completer which we
654 can use as appropriate instead of make_symbol_completion_list. */
656 struct symtabs_and_lines
657 decode_line_1 (char **argptr
, int funfirstline
, struct symtab
*default_symtab
,
658 int default_line
, char ***canonical
, int *not_found_ptr
)
662 /* If a file name is specified, this is its symtab. */
663 struct symtab
*file_symtab
= NULL
;
666 /* This is NULL if there are no parens in *ARGPTR, or a pointer to
667 the closing parenthesis if there are parens. */
669 /* This says whether or not something in *ARGPTR is quoted with
670 completer_quotes (i.e. with single quotes). */
672 /* Is part of *ARGPTR is enclosed in double quotes? */
673 int is_quote_enclosed
;
674 int is_objc_method
= 0;
675 char *saved_arg
= *argptr
;
680 /* Defaults have defaults. */
682 initialize_defaults (&default_symtab
, &default_line
);
684 /* See if arg is *PC. */
687 return decode_indirect (argptr
);
689 /* Set various flags. 'paren_pointer' is important for overload
690 checking, where we allow things like:
691 (gdb) break c::f(int)
694 set_flags (*argptr
, &is_quoted
, &paren_pointer
);
696 /* Check to see if it's a multipart linespec (with colons or
699 /* Locate the end of the first half of the linespec.
700 After the call, for instance, if the argptr string is "foo.c:123"
701 p will point at "123". If there is only one part, like "foo", p
702 will point to "". If this is a C++ name, like "A::B::foo", p will
703 point to "::B::foo". Argptr is not changed by this call. */
705 p
= locate_first_half (argptr
, &is_quote_enclosed
);
707 /* Check if this is an Objective-C method (anything that starts with
708 a '+' or '-' and a '['). */
709 if (is_objc_method_format (p
))
712 paren_pointer
= NULL
; /* Just a category name. Ignore it. */
715 /* Check if the symbol could be an Objective-C selector. */
718 struct symtabs_and_lines values
;
719 values
= decode_objc (argptr
, funfirstline
, NULL
,
720 canonical
, saved_arg
);
721 if (values
.sals
!= NULL
)
725 /* Does it look like there actually were two parts? */
727 if ((p
[0] == ':' || p
[0] == '.') && paren_pointer
== NULL
)
730 *argptr
= *argptr
+ 1;
732 /* Is it a C++ or Java compound data structure?
733 The check on p[1] == ':' is capturing the case of "::",
734 since p[0]==':' was checked above.
735 Note that the call to decode_compound does everything
736 for us, including the lookup on the symbol table, so we
739 if (p
[0] == '.' || p
[1] == ':')
740 return decode_compound (argptr
, funfirstline
, canonical
,
743 /* No, the first part is a filename; set s to be that file's
744 symtab. Also, move argptr past the filename. */
746 file_symtab
= symtab_from_filename (argptr
, p
, is_quote_enclosed
,
750 /* No one really seems to know why this was added. It certainly
751 breaks the command line, though, whenever the passed
752 name is of the form ClassName::Method. This bit of code
753 singles out the class name, and if funfirstline is set (for
754 example, you are setting a breakpoint at this function),
755 you get an error. This did not occur with earlier
756 verions, so I am ifdef'ing this out. 3/29/99 */
759 /* Check if what we have till now is a symbol name */
761 /* We may be looking at a template instantiation such
762 as "foo<int>". Check here whether we know about it,
763 instead of falling through to the code below which
764 handles ordinary function names, because that code
765 doesn't like seeing '<' and '>' in a name -- the
766 skip_quoted call doesn't go past them. So see if we
767 can figure it out right now. */
769 copy
= (char *) alloca (p
- *argptr
+ 1);
770 memcpy (copy
, *argptr
, p
- *argptr
);
771 copy
[p
- *argptr
] = '\000';
772 sym
= lookup_symbol (copy
, 0, VAR_DOMAIN
, 0, &sym_symtab
);
775 *argptr
= (*p
== '\'') ? p
+ 1 : p
;
776 return symbol_found (funfirstline
, canonical
, copy
, sym
,
779 /* Otherwise fall out from here and go to file/line spec
784 /* S is specified file's symtab, or 0 if no file specified.
785 arg no longer contains the file name. */
787 /* Check whether arg is all digits (and sign). */
790 if (*q
== '-' || *q
== '+')
792 while (*q
>= '0' && *q
<= '9')
795 if (q
!= *argptr
&& (*q
== 0 || *q
== ' ' || *q
== '\t' || *q
== ','))
796 /* We found a token consisting of all digits -- at least one digit. */
797 return decode_all_digits (argptr
, default_symtab
, default_line
,
798 canonical
, file_symtab
, q
);
800 /* Arg token is not digits => try it as a variable name
801 Find the next token (everything up to end or next whitespace). */
803 if (**argptr
== '$') /* May be a convenience variable. */
804 /* One or two $ chars possible. */
805 p
= skip_quoted (*argptr
+ (((*argptr
)[1] == '$') ? 2 : 1));
808 p
= skip_quoted (*argptr
);
810 error (_("Unmatched single quote."));
812 else if (is_objc_method
)
814 /* allow word separators in method names for Obj-C */
815 p
= skip_quoted_chars (*argptr
, NULL
, "");
817 else if (paren_pointer
!= NULL
)
819 p
= paren_pointer
+ 1;
823 p
= skip_quoted (*argptr
);
826 copy
= (char *) alloca (p
- *argptr
+ 1);
827 memcpy (copy
, *argptr
, p
- *argptr
);
828 copy
[p
- *argptr
] = '\0';
831 && copy
[0] == copy
[p
- *argptr
- 1]
832 && strchr (get_gdb_completer_quote_characters (), copy
[0]) != NULL
)
834 copy
[p
- *argptr
- 1] = '\0';
837 while (*p
== ' ' || *p
== '\t')
841 /* If it starts with $: may be a legitimate variable or routine name
842 (e.g. HP-UX millicode routines such as $$dyncall), or it may
843 be history value, or it may be a convenience variable. */
846 return decode_dollar (copy
, funfirstline
, default_symtab
,
847 canonical
, file_symtab
);
849 /* Look up that token as a variable.
850 If file specified, use that file's per-file block to start with. */
852 return decode_variable (copy
, funfirstline
, canonical
,
853 file_symtab
, not_found_ptr
);
858 /* Now, more helper functions for decode_line_1. Some conventions
859 that these functions follow:
861 Decode_line_1 typically passes along some of its arguments or local
862 variables to the subfunctions. It passes the variables by
863 reference if they are modified by the subfunction, and by value
866 Some of the functions have side effects that don't arise from
867 variables that are passed by reference. In particular, if a
868 function is passed ARGPTR as an argument, it modifies what ARGPTR
869 points to; typically, it advances *ARGPTR past whatever substring
870 it has just looked at. (If it doesn't modify *ARGPTR, then the
871 function gets passed *ARGPTR instead, which is then called ARG: see
872 set_flags, for example.) Also, functions that return a struct
873 symtabs_and_lines may modify CANONICAL, as in the description of
876 If a function returns a struct symtabs_and_lines, then that struct
877 will immediately make its way up the call chain to be returned by
878 decode_line_1. In particular, all of the functions decode_XXX
879 calculate the appropriate struct symtabs_and_lines, under the
880 assumption that their argument is of the form XXX. */
882 /* First, some functions to initialize stuff at the beggining of the
886 initialize_defaults (struct symtab
**default_symtab
, int *default_line
)
888 if (*default_symtab
== 0)
890 /* Use whatever we have for the default source line. We don't use
891 get_current_or_default_symtab_and_line as it can recurse and call
893 struct symtab_and_line cursal
=
894 get_current_source_symtab_and_line ();
896 *default_symtab
= cursal
.symtab
;
897 *default_line
= cursal
.line
;
902 set_flags (char *arg
, int *is_quoted
, char **paren_pointer
)
907 /* 'has_if' is for the syntax:
908 (gdb) break foo if (a==b)
910 if ((ii
= strstr (arg
, " if ")) != NULL
||
911 (ii
= strstr (arg
, "\tif ")) != NULL
||
912 (ii
= strstr (arg
, " if\t")) != NULL
||
913 (ii
= strstr (arg
, "\tif\t")) != NULL
||
914 (ii
= strstr (arg
, " if(")) != NULL
||
915 (ii
= strstr (arg
, "\tif( ")) != NULL
)
917 /* Temporarily zap out "if (condition)" to not confuse the
918 parenthesis-checking code below. This is undone below. Do not
926 && strchr (get_gdb_completer_quote_characters (),
929 *paren_pointer
= strchr (arg
, '(');
930 if (*paren_pointer
!= NULL
)
931 *paren_pointer
= strrchr (*paren_pointer
, ')');
933 /* Now that we're safely past the paren_pointer check, put back " if
934 (condition)" so outer layers can see it. */
941 /* Decode arg of the form *PC. */
943 static struct symtabs_and_lines
944 decode_indirect (char **argptr
)
946 struct symtabs_and_lines values
;
950 pc
= parse_and_eval_address_1 (argptr
);
952 values
.sals
= (struct symtab_and_line
*)
953 xmalloc (sizeof (struct symtab_and_line
));
956 values
.sals
[0] = find_pc_line (pc
, 0);
957 values
.sals
[0].pc
= pc
;
958 values
.sals
[0].section
= find_pc_overlay (pc
);
965 /* Locate the first half of the linespec, ending in a colon, period,
966 or whitespace. (More or less.) Also, check to see if *ARGPTR is
967 enclosed in double quotes; if so, set is_quote_enclosed, advance
968 ARGPTR past that and zero out the trailing double quote.
969 If ARGPTR is just a simple name like "main", p will point to ""
973 locate_first_half (char **argptr
, int *is_quote_enclosed
)
979 /* Maybe we were called with a line range FILENAME:LINENUM,FILENAME:LINENUM
980 and we must isolate the first half. Outer layers will call again later
983 Don't count commas that appear in argument lists of overloaded
984 functions, or in quoted strings. It's stupid to go to this much
985 trouble when the rest of the function is such an obvious roach hotel. */
986 ii
= find_toplevel_char (*argptr
, ',');
987 has_comma
= (ii
!= 0);
989 /* Temporarily zap out second half to not confuse the code below.
990 This is undone below. Do not change ii!! */
996 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION. May also be
997 CLASS::MEMBER, or NAMESPACE::NAME. Look for ':', but ignore
1003 *is_quote_enclosed
= 1;
1008 *is_quote_enclosed
= 0;
1013 char *temp_end
= find_template_name_end (p
);
1015 error (_("malformed template specification in command"));
1018 /* Check for a colon and a plus or minus and a [ (which
1019 indicates an Objective-C method) */
1020 if (is_objc_method_format (p
))
1024 /* Check for the end of the first half of the linespec. End of
1025 line, a tab, a double colon or the last single colon, or a
1026 space. But if enclosed in double quotes we do not break on
1031 && ((p
[1] == ':') || (strchr (p
+ 1, ':') == NULL
)))
1032 || ((p
[0] == ' ') && !*is_quote_enclosed
))
1034 if (p
[0] == '.' && strchr (p
, ':') == NULL
)
1036 /* Java qualified method. Find the *last* '.', since the
1037 others are package qualifiers. */
1038 for (p1
= p
; *p1
; p1
++)
1046 while (p
[0] == ' ' || p
[0] == '\t')
1049 /* If the closing double quote was left at the end, remove it. */
1050 if (*is_quote_enclosed
)
1052 char *closing_quote
= strchr (p
- 1, '"');
1053 if (closing_quote
&& closing_quote
[1] == '\0')
1054 *closing_quote
= '\0';
1057 /* Now that we've safely parsed the first half, put back ',' so
1058 outer layers can see it. */
1067 /* Here's where we recognise an Objective-C Selector. An Objective C
1068 selector may be implemented by more than one class, therefore it
1069 may represent more than one method/function. This gives us a
1070 situation somewhat analogous to C++ overloading. If there's more
1071 than one method that could represent the selector, then use some of
1072 the existing C++ code to let the user choose one. */
1074 struct symtabs_and_lines
1075 decode_objc (char **argptr
, int funfirstline
, struct symtab
*file_symtab
,
1076 char ***canonical
, char *saved_arg
)
1078 struct symtabs_and_lines values
;
1079 struct symbol
**sym_arr
= NULL
;
1080 struct symbol
*sym
= NULL
;
1082 struct block
*block
= NULL
;
1089 if (file_symtab
!= NULL
)
1090 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_symtab
), STATIC_BLOCK
);
1092 block
= get_selected_block (0);
1094 copy
= find_imps (file_symtab
, block
, *argptr
, NULL
, &i1
, &i2
);
1098 sym_arr
= (struct symbol
**) alloca ((i1
+ 1) * sizeof (struct symbol
*));
1101 copy
= find_imps (file_symtab
, block
, *argptr
, sym_arr
, &i1
, &i2
);
1105 /* i1 now represents the TOTAL number of matches found.
1106 i2 represents how many HIGH-LEVEL (struct symbol) matches,
1107 which will come first in the sym_arr array. Any low-level
1108 (minimal_symbol) matches will follow those. */
1114 /* Already a struct symbol. */
1119 sym
= find_pc_function (SYMBOL_VALUE_ADDRESS (sym_arr
[0]));
1120 if ((sym
!= NULL
) && strcmp (SYMBOL_LINKAGE_NAME (sym_arr
[0]), SYMBOL_LINKAGE_NAME (sym
)) != 0)
1122 warning (_("debugging symbol \"%s\" does not match selector; ignoring"), SYMBOL_LINKAGE_NAME (sym
));
1127 values
.sals
= (struct symtab_and_line
*) xmalloc (sizeof (struct symtab_and_line
));
1130 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1132 /* Canonicalize this, so it remains resolved for dylib loads. */
1133 values
.sals
[0] = find_function_start_sal (sym
, funfirstline
);
1134 build_canonical_line_spec (values
.sals
, SYMBOL_NATURAL_NAME (sym
), canonical
);
1138 /* The only match was a non-debuggable symbol. */
1139 values
.sals
[0].symtab
= 0;
1140 values
.sals
[0].line
= 0;
1141 values
.sals
[0].end
= 0;
1142 values
.sals
[0].pc
= SYMBOL_VALUE_ADDRESS (sym_arr
[0]);
1149 /* More than one match. The user must choose one or more. */
1150 return decode_line_2 (sym_arr
, i2
, funfirstline
, canonical
);
1156 /* This handles C++ and Java compound data structures. P should point
1157 at the first component separator, i.e. double-colon or period. As
1158 an example, on entrance to this function we could have ARGPTR
1159 pointing to "AAA::inA::fun" and P pointing to "::inA::fun". */
1161 static struct symtabs_and_lines
1162 decode_compound (char **argptr
, int funfirstline
, char ***canonical
,
1163 char *saved_arg
, char *p
)
1165 struct symtabs_and_lines values
;
1167 char *saved_arg2
= *argptr
;
1170 /* The symtab that SYM was found in. */
1171 struct symtab
*sym_symtab
;
1173 struct symbol
*sym_class
;
1174 struct symbol
**sym_arr
;
1177 /* First check for "global" namespace specification, of the form
1178 "::foo". If found, skip over the colons and jump to normal
1179 symbol processing. I.e. the whole line specification starts with
1180 "::" (note the condition that *argptr == p). */
1182 && ((*argptr
== p
) || (p
[-1] == ' ') || (p
[-1] == '\t')))
1185 /* Given our example "AAA::inA::fun", we have two cases to consider:
1187 1) AAA::inA is the name of a class. In that case, presumably it
1188 has a method called "fun"; we then look up that method using
1191 2) AAA::inA isn't the name of a class. In that case, either the
1192 user made a typo or AAA::inA is the name of a namespace.
1193 Either way, we just look up AAA::inA::fun with lookup_symbol.
1195 Thus, our first task is to find everything before the last set of
1196 double-colons and figure out if it's the name of a class. So we
1197 first loop through all of the double-colons. */
1199 p2
= p
; /* Save for restart. */
1201 /* This is very messy. Following the example above we have now the
1204 argptr -> "AAA::inA::fun
1205 saved_arg -> "AAA::inA::fun
1206 saved_arg2 -> "AAA::inA::fun
1207 p2 -> "::inA::fun". */
1209 /* In the loop below, with these strings, we'll make 2 passes, each
1210 is marked in comments.*/
1214 /* Move pointer up to next possible class/namespace token. */
1216 p
= p2
+ 1; /* Restart with old value +1. */
1218 /* PASS1: at this point p2->"::inA::fun", so p->":inA::fun",
1219 i.e. if there is a double-colon, p will now point to the
1221 /* PASS2: p2->"::fun", p->":fun" */
1223 /* Move pointer ahead to next double-colon. */
1224 while (*p
&& (p
[0] != ' ') && (p
[0] != '\t') && (p
[0] != '\''))
1228 temp_end
= find_template_name_end (p
);
1230 error (_("malformed template specification in command"));
1233 /* Note that, since, at the start of this loop, p would be
1234 pointing to the second colon in a double-colon, we only
1235 satisfy the condition below if there is another
1236 double-colon to the right (after). I.e. there is another
1237 component that can be a class or a namespace. I.e, if at
1238 the beginning of this loop (PASS1), we had
1239 p->":inA::fun", we'll trigger this when p has been
1240 advanced to point to "::fun". */
1241 /* PASS2: we will not trigger this. */
1242 else if ((p
[0] == ':') && (p
[1] == ':'))
1243 break; /* Found double-colon. */
1245 /* PASS2: We'll keep getting here, until p->"", at which point
1246 we exit this loop. */
1251 break; /* Out of the while (1). This would happen
1252 for instance if we have looked up
1253 unsuccessfully all the components of the
1254 string, and p->""(PASS2) */
1256 /* We get here if p points to ' ', '\t', '\'', "::" or ""(i.e
1258 /* Save restart for next time around. */
1260 /* Restore argptr as it was on entry to this function. */
1261 *argptr
= saved_arg2
;
1262 /* PASS1: at this point p->"::fun" argptr->"AAA::inA::fun",
1265 /* All ready for next pass through the loop. */
1269 /* Start of lookup in the symbol tables. */
1271 /* Lookup in the symbol table the substring between argptr and
1272 p. Note, this call changes the value of argptr. */
1273 /* Before the call, argptr->"AAA::inA::fun",
1274 p->"", p2->"::fun". After the call: argptr->"fun", p, p2
1276 sym_class
= lookup_prefix_sym (argptr
, p2
);
1278 /* If sym_class has been found, and if "AAA::inA" is a class, then
1279 we're in case 1 above. So we look up "fun" as a method of that
1282 (t
= check_typedef (SYMBOL_TYPE (sym_class
)),
1283 (TYPE_CODE (t
) == TYPE_CODE_STRUCT
1284 || TYPE_CODE (t
) == TYPE_CODE_UNION
)))
1286 /* Arg token is not digits => try it as a function name.
1287 Find the next token (everything up to end or next
1290 && strchr (get_gdb_completer_quote_characters (),
1293 p
= skip_quoted (*argptr
);
1294 *argptr
= *argptr
+ 1;
1298 /* At this point argptr->"fun". */
1300 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!= ':')
1302 /* At this point p->"". String ended. */
1305 /* Allocate our own copy of the substring between argptr and
1307 copy
= (char *) alloca (p
- *argptr
+ 1);
1308 memcpy (copy
, *argptr
, p
- *argptr
);
1309 copy
[p
- *argptr
] = '\0';
1311 && copy
[p
- *argptr
- 1]
1312 && strchr (get_gdb_completer_quote_characters (),
1313 copy
[p
- *argptr
- 1]) != NULL
)
1314 copy
[p
- *argptr
- 1] = '\0';
1316 /* At this point copy->"fun", p->"" */
1318 /* No line number may be specified. */
1319 while (*p
== ' ' || *p
== '\t')
1322 /* At this point arptr->"". */
1324 /* Look for copy as a method of sym_class. */
1325 /* At this point copy->"fun", sym_class is "AAA:inA",
1326 saved_arg->"AAA::inA::fun". This concludes the scanning of
1327 the string for possible components matches. If we find it
1328 here, we return. If not, and we are at the and of the string,
1329 we'll lookup the whole string in the symbol tables. */
1331 return find_method (funfirstline
, canonical
, saved_arg
,
1332 copy
, t
, sym_class
);
1334 } /* End if symbol found */
1337 /* We couldn't find a class, so we're in case 2 above. We check the
1338 entire name as a symbol instead. */
1340 copy
= (char *) alloca (p
- saved_arg2
+ 1);
1341 memcpy (copy
, saved_arg2
, p
- saved_arg2
);
1342 /* Note: if is_quoted should be true, we snuff out quote here
1344 copy
[p
- saved_arg2
] = '\000';
1345 /* Set argptr to skip over the name. */
1346 *argptr
= (*p
== '\'') ? p
+ 1 : p
;
1348 /* Look up entire name */
1349 sym
= lookup_symbol (copy
, 0, VAR_DOMAIN
, 0, &sym_symtab
);
1351 return symbol_found (funfirstline
, canonical
, copy
, sym
,
1354 /* Couldn't find any interpretation as classes/namespaces, so give
1355 up. The quotes are important if copy is empty. */
1356 cplusplus_error (saved_arg
,
1357 "Can't find member of namespace, class, struct, or union named \"%s\"\n",
1361 /* Next come some helper functions for decode_compound. */
1363 /* Return the symbol corresponding to the substring of *ARGPTR ending
1364 at P, allowing whitespace. Also, advance *ARGPTR past the symbol
1365 name in question, the compound object separator ("::" or "."), and
1366 whitespace. Note that *ARGPTR is changed whether or not the
1367 lookup_symbol call finds anything (i.e we return NULL). As an
1368 example, say ARGPTR is "AAA::inA::fun" and P is "::inA::fun". */
1370 static struct symbol
*
1371 lookup_prefix_sym (char **argptr
, char *p
)
1376 /* Extract the class name. */
1378 while (p
!= *argptr
&& p
[-1] == ' ')
1380 copy
= (char *) alloca (p
- *argptr
+ 1);
1381 memcpy (copy
, *argptr
, p
- *argptr
);
1382 copy
[p
- *argptr
] = 0;
1384 /* Discard the class name from the argptr. */
1385 p
= p1
+ (p1
[0] == ':' ? 2 : 1);
1386 while (*p
== ' ' || *p
== '\t')
1390 /* At this point p1->"::inA::fun", p->"inA::fun" copy->"AAA",
1391 argptr->"inA::fun" */
1393 return lookup_symbol (copy
, 0, STRUCT_DOMAIN
, 0,
1394 (struct symtab
**) NULL
);
1397 /* This finds the method COPY in the class whose type is T and whose
1398 symbol is SYM_CLASS. */
1400 static struct symtabs_and_lines
1401 find_method (int funfirstline
, char ***canonical
, char *saved_arg
,
1402 char *copy
, struct type
*t
, struct symbol
*sym_class
)
1404 struct symtabs_and_lines values
;
1405 struct symbol
*sym
= 0;
1406 int i1
; /* Counter for the symbol array. */
1407 struct symbol
**sym_arr
= alloca (total_number_of_methods (t
)
1408 * sizeof (struct symbol
*));
1410 /* Find all methods with a matching name, and put them in
1413 i1
= collect_methods (copy
, t
, sym_arr
);
1417 /* There is exactly one field with that name. */
1420 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1422 values
.sals
= (struct symtab_and_line
*)
1423 xmalloc (sizeof (struct symtab_and_line
));
1425 values
.sals
[0] = find_function_start_sal (sym
,
1437 /* There is more than one field with that name
1438 (overloaded). Ask the user which one to use. */
1439 return decode_line_2 (sym_arr
, i1
, funfirstline
, canonical
);
1445 if (is_operator_name (copy
))
1447 tmp
= (char *) alloca (strlen (copy
+ 3) + 9);
1448 strcpy (tmp
, "operator ");
1449 strcat (tmp
, copy
+ 3);
1454 cplusplus_error (saved_arg
,
1455 "the class `%s' does not have destructor defined\n",
1456 SYMBOL_PRINT_NAME (sym_class
));
1458 cplusplus_error (saved_arg
,
1459 "the class %s does not have any method named %s\n",
1460 SYMBOL_PRINT_NAME (sym_class
), tmp
);
1464 /* Find all methods named COPY in the class whose type is T, and put
1465 them in SYM_ARR. Return the number of methods found. */
1468 collect_methods (char *copy
, struct type
*t
,
1469 struct symbol
**sym_arr
)
1471 int i1
= 0; /* Counter for the symbol array. */
1473 if (destructor_name_p (copy
, t
))
1475 /* Destructors are a special case. */
1476 int m_index
, f_index
;
1478 if (get_destructor_fn_field (t
, &m_index
, &f_index
))
1480 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, m_index
);
1483 lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f
, f_index
),
1484 NULL
, VAR_DOMAIN
, (int *) NULL
,
1485 (struct symtab
**) NULL
);
1491 i1
= find_methods (t
, copy
, sym_arr
);
1498 /* Return the symtab associated to the filename given by the substring
1499 of *ARGPTR ending at P, and advance ARGPTR past that filename. If
1500 NOT_FOUND_PTR is not null and the source file is not found, store
1501 boolean true at the location pointed to and do not issue an
1504 static struct symtab
*
1505 symtab_from_filename (char **argptr
, char *p
, int is_quote_enclosed
,
1510 struct symtab
*file_symtab
;
1513 while (p
!= *argptr
&& p
[-1] == ' ')
1515 if ((*p
== '"') && is_quote_enclosed
)
1517 copy
= (char *) alloca (p
- *argptr
+ 1);
1518 memcpy (copy
, *argptr
, p
- *argptr
);
1519 /* It may have the ending quote right after the file name. */
1520 if (is_quote_enclosed
&& copy
[p
- *argptr
- 1] == '"')
1521 copy
[p
- *argptr
- 1] = 0;
1523 copy
[p
- *argptr
] = 0;
1525 /* Find that file's data. */
1526 file_symtab
= lookup_symtab (copy
);
1527 if (file_symtab
== 0)
1529 if (!have_full_symbols () && !have_partial_symbols ())
1530 error (_("No symbol table is loaded. Use the \"file\" command."));
1533 throw_error (NOT_FOUND_ERROR
, _("No source file named %s."), copy
);
1536 /* Discard the file name from the arg. */
1538 while (*p
== ' ' || *p
== '\t')
1547 /* This decodes a line where the argument is all digits (possibly
1548 preceded by a sign). Q should point to the end of those digits;
1549 the other arguments are as usual. */
1551 static struct symtabs_and_lines
1552 decode_all_digits (char **argptr
, struct symtab
*default_symtab
,
1553 int default_line
, char ***canonical
,
1554 struct symtab
*file_symtab
, char *q
)
1557 struct symtabs_and_lines values
;
1558 struct symtab_and_line val
;
1566 /* We might need a canonical line spec if no file was specified. */
1567 int need_canonical
= (file_symtab
== 0) ? 1 : 0;
1571 /* This is where we need to make sure that we have good defaults.
1572 We must guarantee that this section of code is never executed
1573 when we are called with just a function name, since
1574 set_default_source_symtab_and_line uses
1575 select_source_symtab that calls us with such an argument. */
1577 if (file_symtab
== 0 && default_symtab
== 0)
1579 /* Make sure we have at least a default source file. */
1580 set_default_source_symtab_and_line ();
1581 initialize_defaults (&default_symtab
, &default_line
);
1584 if (**argptr
== '+')
1585 sign
= plus
, (*argptr
)++;
1586 else if (**argptr
== '-')
1587 sign
= minus
, (*argptr
)++;
1588 val
.line
= atoi (*argptr
);
1594 if (file_symtab
== 0)
1595 val
.line
= default_line
+ val
.line
;
1600 if (file_symtab
== 0)
1601 val
.line
= default_line
- val
.line
;
1606 break; /* No need to adjust val.line. */
1609 while (*q
== ' ' || *q
== '\t')
1612 if (file_symtab
== 0)
1613 file_symtab
= default_symtab
;
1615 /* It is possible that this source file has more than one symtab,
1616 and that the new line number specification has moved us from the
1617 default (in file_symtab) to a new one. */
1618 val
.symtab
= find_line_symtab (file_symtab
, val
.line
, NULL
, NULL
);
1619 if (val
.symtab
== 0)
1620 val
.symtab
= file_symtab
;
1623 values
.sals
= (struct symtab_and_line
*)
1624 xmalloc (sizeof (struct symtab_and_line
));
1625 values
.sals
[0] = val
;
1628 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
1634 /* Decode a linespec starting with a dollar sign. */
1636 static struct symtabs_and_lines
1637 decode_dollar (char *copy
, int funfirstline
, struct symtab
*default_symtab
,
1638 char ***canonical
, struct symtab
*file_symtab
)
1642 int need_canonical
= 0;
1643 struct symtabs_and_lines values
;
1644 struct symtab_and_line val
;
1647 /* The symtab that SYM was found in. */
1648 struct symtab
*sym_symtab
;
1649 struct minimal_symbol
*msymbol
;
1651 p
= (copy
[1] == '$') ? copy
+ 2 : copy
+ 1;
1652 while (*p
>= '0' && *p
<= '9')
1654 if (!*p
) /* Reached end of token without hitting non-digit. */
1656 /* We have a value history reference. */
1657 sscanf ((copy
[1] == '$') ? copy
+ 2 : copy
+ 1, "%d", &index
);
1658 valx
= access_value_history ((copy
[1] == '$') ? -index
: index
);
1659 if (TYPE_CODE (value_type (valx
)) != TYPE_CODE_INT
)
1660 error (_("History values used in line specs must have integer values."));
1664 /* Not all digits -- may be user variable/function or a
1665 convenience variable. */
1667 /* Look up entire name as a symbol first. */
1668 sym
= lookup_symbol (copy
, 0, VAR_DOMAIN
, 0, &sym_symtab
);
1669 file_symtab
= (struct symtab
*) 0;
1671 /* Symbol was found --> jump to normal symbol processing. */
1673 return symbol_found (funfirstline
, canonical
, copy
, sym
,
1676 /* If symbol was not found, look in minimal symbol tables. */
1677 msymbol
= lookup_minimal_symbol (copy
, NULL
, NULL
);
1678 /* Min symbol was found --> jump to minsym processing. */
1680 return minsym_found (funfirstline
, msymbol
);
1682 /* Not a user variable or function -- must be convenience variable. */
1683 need_canonical
= (file_symtab
== 0) ? 1 : 0;
1684 valx
= value_of_internalvar (lookup_internalvar (copy
+ 1));
1685 if (TYPE_CODE (value_type (valx
)) != TYPE_CODE_INT
)
1686 error (_("Convenience variables used in line specs must have integer values."));
1691 /* Either history value or convenience value from above, in valx. */
1692 val
.symtab
= file_symtab
? file_symtab
: default_symtab
;
1693 val
.line
= value_as_long (valx
);
1696 values
.sals
= (struct symtab_and_line
*) xmalloc (sizeof val
);
1697 values
.sals
[0] = val
;
1701 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
1708 /* Decode a linespec that's a variable. If FILE_SYMTAB is non-NULL,
1709 look in that symtab's static variables first. If NOT_FOUND_PTR is not NULL and
1710 the function cannot be found, store boolean true in the location pointed to
1711 and do not issue an error message. */
1713 static struct symtabs_and_lines
1714 decode_variable (char *copy
, int funfirstline
, char ***canonical
,
1715 struct symtab
*file_symtab
, int *not_found_ptr
)
1718 /* The symtab that SYM was found in. */
1719 struct symtab
*sym_symtab
;
1721 struct minimal_symbol
*msymbol
;
1723 sym
= lookup_symbol (copy
,
1725 ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_symtab
),
1727 : get_selected_block (0)),
1728 VAR_DOMAIN
, 0, &sym_symtab
);
1731 return symbol_found (funfirstline
, canonical
, copy
, sym
,
1732 file_symtab
, sym_symtab
);
1734 msymbol
= lookup_minimal_symbol (copy
, NULL
, NULL
);
1736 if (msymbol
!= NULL
)
1737 return minsym_found (funfirstline
, msymbol
);
1739 if (!have_full_symbols () &&
1740 !have_partial_symbols () && !have_minimal_symbols ())
1741 error (_("No symbol table is loaded. Use the \"file\" command."));
1745 throw_error (NOT_FOUND_ERROR
, _("Function \"%s\" not defined."), copy
);
1751 /* Now come some functions that are called from multiple places within
1754 /* We've found a symbol SYM to associate with our linespec; build a
1755 corresponding struct symtabs_and_lines. */
1757 static struct symtabs_and_lines
1758 symbol_found (int funfirstline
, char ***canonical
, char *copy
,
1759 struct symbol
*sym
, struct symtab
*file_symtab
,
1760 struct symtab
*sym_symtab
)
1762 struct symtabs_and_lines values
;
1764 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1766 /* Arg is the name of a function */
1767 values
.sals
= (struct symtab_and_line
*)
1768 xmalloc (sizeof (struct symtab_and_line
));
1769 values
.sals
[0] = find_function_start_sal (sym
, funfirstline
);
1772 /* Don't use the SYMBOL_LINE; if used at all it points to
1773 the line containing the parameters or thereabouts, not
1774 the first line of code. */
1776 /* We might need a canonical line spec if it is a static
1778 if (file_symtab
== 0)
1780 struct blockvector
*bv
= BLOCKVECTOR (sym_symtab
);
1781 struct block
*b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1782 if (lookup_block_symbol (b
, copy
, NULL
, VAR_DOMAIN
) != NULL
)
1783 build_canonical_line_spec (values
.sals
, copy
, canonical
);
1790 error (_("\"%s\" is not a function"), copy
);
1791 else if (SYMBOL_LINE (sym
) != 0)
1793 /* We know its line number. */
1794 values
.sals
= (struct symtab_and_line
*)
1795 xmalloc (sizeof (struct symtab_and_line
));
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
);
1803 /* This can happen if it is compiled with a compiler which doesn't
1804 put out line numbers for variables. */
1805 /* FIXME: Shouldn't we just set .line and .symtab to zero
1806 and return? For example, "info line foo" could print
1808 error (_("Line number not known for symbol \"%s\""), copy
);
1812 /* We've found a minimal symbol MSYMBOL to associate with our
1813 linespec; build a corresponding struct symtabs_and_lines. */
1815 static struct symtabs_and_lines
1816 minsym_found (int funfirstline
, struct minimal_symbol
*msymbol
)
1818 struct symtabs_and_lines values
;
1820 values
.sals
= (struct symtab_and_line
*)
1821 xmalloc (sizeof (struct symtab_and_line
));
1822 values
.sals
[0] = find_pc_sect_line (SYMBOL_VALUE_ADDRESS (msymbol
),
1823 (struct bfd_section
*) 0, 0);
1824 values
.sals
[0].section
= SYMBOL_BFD_SECTION (msymbol
);
1827 values
.sals
[0].pc
+= DEPRECATED_FUNCTION_START_OFFSET
;
1828 values
.sals
[0].pc
= SKIP_PROLOGUE (values
.sals
[0].pc
);