2002-12-09 David Carlton <carlton@math.stanford.edu>
[external/binutils.git] / gdb / linespec.c
1 /* Parser for linespec for the GNU debugger, GDB.
2    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3    1996, 1997, 1998, 1999, 2000, 2001
4    Free Software Foundation, Inc.
5
6    This file is part of GDB.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.  */
22
23 #include "defs.h"
24 #include "symtab.h"
25 #include "frame.h"
26 #include "command.h"
27 #include "symfile.h"
28 #include "objfiles.h"
29 #include "source.h"
30 #include "demangle.h"
31 #include "value.h"
32 #include "completer.h"
33 #include "cp-abi.h"
34 #include "parser-defs.h"
35
36 /* We share this one with symtab.c, but it is not exported widely. */
37
38 extern char *operator_chars (char *, char **);
39
40 /* Prototypes for local functions */
41
42 static void initialize_defaults (struct symtab **default_symtab,
43                                  int *default_line);
44
45 static void set_flags (char *arg, int *is_quoted, char **paren_pointer);
46
47 static struct symtabs_and_lines decode_indirect (char **argptr);
48
49 static char *locate_first_half (char **argptr, int *is_quote_enclosed);
50
51 static struct symtabs_and_lines decode_compound (char **argptr,
52                                                  int funfirstline,
53                                                  char ***canonical,
54                                                  char *saved_arg,
55                                                  char *p);
56
57 static NORETURN void cplusplus_error (const char *name,
58                                       const char *fmt, ...)
59      ATTR_NORETURN ATTR_FORMAT (printf, 2, 3);
60
61 static int total_number_of_methods (struct type *type);
62
63 static int find_methods (struct type *, char *, struct symbol **);
64
65 static void build_canonical_line_spec (struct symtab_and_line *,
66                                        char *, char ***);
67
68 static char *find_toplevel_char (char *s, char c);
69
70 static struct symtabs_and_lines decode_line_2 (struct symbol *[],
71                                                int, int, char ***);
72
73 static struct symtab *symtab_from_filename (char **argptr,
74                                             char *p, int is_quote_enclosed);
75
76 static struct
77 symtabs_and_lines symbol_found (int funfirstline,
78                                 char ***canonical,
79                                 char *copy,
80                                 struct symbol *sym,
81                                 struct symtab *s,
82                                 struct symtab *sym_symtab);
83
84 static struct
85 symtabs_and_lines minsym_found (int funfirstline,
86                                 struct minimal_symbol *msymbol);
87
88 /* Helper functions. */
89
90 /* Issue a helpful hint on using the command completion feature on
91    single quoted demangled C++ symbols as part of the completion
92    error.  */
93
94 static NORETURN void
95 cplusplus_error (const char *name, const char *fmt, ...)
96 {
97   struct ui_file *tmp_stream;
98   tmp_stream = mem_fileopen ();
99   make_cleanup_ui_file_delete (tmp_stream);
100
101   {
102     va_list args;
103     va_start (args, fmt);
104     vfprintf_unfiltered (tmp_stream, fmt, args);
105     va_end (args);
106   }
107
108   while (*name == '\'')
109     name++;
110   fprintf_unfiltered (tmp_stream,
111                       ("Hint: try '%s<TAB> or '%s<ESC-?>\n"
112                        "(Note leading single quote.)"),
113                       name, name);
114   error_stream (tmp_stream);
115 }
116
117 /* Return the number of methods described for TYPE, including the
118    methods from types it derives from. This can't be done in the symbol
119    reader because the type of the baseclass might still be stubbed
120    when the definition of the derived class is parsed.  */
121
122 static int
123 total_number_of_methods (struct type *type)
124 {
125   int n;
126   int count;
127
128   CHECK_TYPEDEF (type);
129   if (TYPE_CPLUS_SPECIFIC (type) == NULL)
130     return 0;
131   count = TYPE_NFN_FIELDS_TOTAL (type);
132
133   for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
134     count += total_number_of_methods (TYPE_BASECLASS (type, n));
135
136   return count;
137 }
138
139 /* Recursive helper function for decode_line_1.
140    Look for methods named NAME in type T.
141    Return number of matches.
142    Put matches in SYM_ARR, which should have been allocated with
143    a size of total_number_of_methods (T) * sizeof (struct symbol *).
144    Note that this function is g++ specific.  */
145
146 static int
147 find_methods (struct type *t, char *name, struct symbol **sym_arr)
148 {
149   int i1 = 0;
150   int ibase;
151   char *class_name = type_name_no_tag (t);
152
153   /* Ignore this class if it doesn't have a name.  This is ugly, but
154      unless we figure out how to get the physname without the name of
155      the class, then the loop can't do any good.  */
156   if (class_name
157       && (lookup_symbol (class_name, (struct block *) NULL,
158                          STRUCT_NAMESPACE, (int *) NULL,
159                          (struct symtab **) NULL)))
160     {
161       int method_counter;
162       int name_len = strlen (name);
163
164       CHECK_TYPEDEF (t);
165
166       /* Loop over each method name.  At this level, all overloads of a name
167          are counted as a single name.  There is an inner loop which loops over
168          each overload.  */
169
170       for (method_counter = TYPE_NFN_FIELDS (t) - 1;
171            method_counter >= 0;
172            --method_counter)
173         {
174           int field_counter;
175           char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
176           char dem_opname[64];
177
178           if (strncmp (method_name, "__", 2) == 0 ||
179               strncmp (method_name, "op", 2) == 0 ||
180               strncmp (method_name, "type", 4) == 0)
181             {
182               if (cplus_demangle_opname (method_name, dem_opname, DMGL_ANSI))
183                 method_name = dem_opname;
184               else if (cplus_demangle_opname (method_name, dem_opname, 0))
185                 method_name = dem_opname;
186             }
187
188           if (strcmp_iw (name, method_name) == 0)
189             /* Find all the overloaded methods with that name.  */
190             for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
191                  field_counter >= 0;
192                  --field_counter)
193               {
194                 struct fn_field *f;
195                 char *phys_name;
196
197                 f = TYPE_FN_FIELDLIST1 (t, method_counter);
198
199                 if (TYPE_FN_FIELD_STUB (f, field_counter))
200                   {
201                     char *tmp_name;
202
203                     tmp_name = gdb_mangle_name (t,
204                                                 method_counter,
205                                                 field_counter);
206                     phys_name = alloca (strlen (tmp_name) + 1);
207                     strcpy (phys_name, tmp_name);
208                     xfree (tmp_name);
209                   }
210                 else
211                   phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
212                 
213                 /* Destructor is handled by caller, dont add it to the list */
214                 if (is_destructor_name (phys_name) != 0)
215                   continue;
216
217                 sym_arr[i1] = lookup_symbol (phys_name,
218                                              NULL, VAR_NAMESPACE,
219                                              (int *) NULL,
220                                              (struct symtab **) NULL);
221                 if (sym_arr[i1])
222                   i1++;
223                 else
224                   {
225                     /* This error message gets printed, but the method
226                        still seems to be found
227                        fputs_filtered("(Cannot find method ", gdb_stdout);
228                        fprintf_symbol_filtered (gdb_stdout, phys_name,
229                        language_cplus,
230                        DMGL_PARAMS | DMGL_ANSI);
231                        fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
232                      */
233                   }
234               }
235           else if (strncmp (class_name, name, name_len) == 0
236                    && (class_name[name_len] == '\0'
237                        || class_name[name_len] == '<'))
238             {
239               /* For GCC 3.x and stabs, constructors and destructors have names
240                  like __base_ctor and __complete_dtor.  Check the physname for now
241                  if we're looking for a constructor.  */
242               for (field_counter
243                      = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
244                    field_counter >= 0;
245                    --field_counter)
246                 {
247                   struct fn_field *f;
248                   char *phys_name;
249                   
250                   f = TYPE_FN_FIELDLIST1 (t, method_counter);
251
252                   /* GCC 3.x will never produce stabs stub methods, so we don't need
253                      to handle this case.  */
254                   if (TYPE_FN_FIELD_STUB (f, field_counter))
255                     continue;
256                   phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
257                   if (! is_constructor_name (phys_name))
258                     continue;
259
260                   /* If this method is actually defined, include it in the
261                      list.  */
262                   sym_arr[i1] = lookup_symbol (phys_name,
263                                                NULL, VAR_NAMESPACE,
264                                                (int *) NULL,
265                                                (struct symtab **) NULL);
266                   if (sym_arr[i1])
267                     i1++;
268                 }
269             }
270         }
271     }
272
273   /* Only search baseclasses if there is no match yet, since names in
274      derived classes override those in baseclasses.
275
276      FIXME: The above is not true; it is only true of member functions
277      if they have the same number of arguments (??? - section 13.1 of the
278      ARM says the function members are not in the same scope but doesn't
279      really spell out the rules in a way I understand.  In any case, if
280      the number of arguments differ this is a case in which we can overload
281      rather than hiding without any problem, and gcc 2.4.5 does overload
282      rather than hiding in this case).  */
283
284   if (i1 == 0)
285     for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
286       i1 += find_methods (TYPE_BASECLASS (t, ibase), name, sym_arr + i1);
287
288   return i1;
289 }
290
291 /* Helper function for decode_line_1.
292    Build a canonical line spec in CANONICAL if it is non-NULL and if
293    the SAL has a symtab.
294    If SYMNAME is non-NULL the canonical line spec is `filename:symname'.
295    If SYMNAME is NULL the line number from SAL is used and the canonical
296    line spec is `filename:linenum'.  */
297
298 static void
299 build_canonical_line_spec (struct symtab_and_line *sal, char *symname,
300                            char ***canonical)
301 {
302   char **canonical_arr;
303   char *canonical_name;
304   char *filename;
305   struct symtab *s = sal->symtab;
306
307   if (s == (struct symtab *) NULL
308       || s->filename == (char *) NULL
309       || canonical == (char ***) NULL)
310     return;
311
312   canonical_arr = (char **) xmalloc (sizeof (char *));
313   *canonical = canonical_arr;
314
315   filename = s->filename;
316   if (symname != NULL)
317     {
318       canonical_name = xmalloc (strlen (filename) + strlen (symname) + 2);
319       sprintf (canonical_name, "%s:%s", filename, symname);
320     }
321   else
322     {
323       canonical_name = xmalloc (strlen (filename) + 30);
324       sprintf (canonical_name, "%s:%d", filename, sal->line);
325     }
326   canonical_arr[0] = canonical_name;
327 }
328
329
330
331 /* Find an instance of the character C in the string S that is outside
332    of all parenthesis pairs, single-quoted strings, and double-quoted
333    strings.  Also, ignore the char within a template name, like a ','
334    within foo<int, int>.  */
335
336 static char *
337 find_toplevel_char (char *s, char c)
338 {
339   int quoted = 0;               /* zero if we're not in quotes;
340                                    '"' if we're in a double-quoted string;
341                                    '\'' if we're in a single-quoted string.  */
342   int depth = 0;                /* number of unclosed parens we've seen */
343   char *scan;
344
345   for (scan = s; *scan; scan++)
346     {
347       if (quoted)
348         {
349           if (*scan == quoted)
350             quoted = 0;
351           else if (*scan == '\\' && *(scan + 1))
352             scan++;
353         }
354       else if (*scan == c && ! quoted && depth == 0)
355         return scan;
356       else if (*scan == '"' || *scan == '\'')
357         quoted = *scan;
358       else if (*scan == '(' || *scan == '<')
359         depth++;
360       else if ((*scan == ')' || *scan == '>') && depth > 0)
361         depth--;
362     }
363
364   return 0;
365 }
366
367 /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
368    operate on (ask user if necessary).
369    If CANONICAL is non-NULL return a corresponding array of mangled names
370    as canonical line specs there.  */
371
372 static struct symtabs_and_lines
373 decode_line_2 (struct symbol *sym_arr[], int nelts, int funfirstline,
374                char ***canonical)
375 {
376   struct symtabs_and_lines values, return_values;
377   char *args, *arg1;
378   int i;
379   char *prompt;
380   char *symname;
381   struct cleanup *old_chain;
382   char **canonical_arr = (char **) NULL;
383
384   values.sals = (struct symtab_and_line *)
385     alloca (nelts * sizeof (struct symtab_and_line));
386   return_values.sals = (struct symtab_and_line *)
387     xmalloc (nelts * sizeof (struct symtab_and_line));
388   old_chain = make_cleanup (xfree, return_values.sals);
389
390   if (canonical)
391     {
392       canonical_arr = (char **) xmalloc (nelts * sizeof (char *));
393       make_cleanup (xfree, canonical_arr);
394       memset (canonical_arr, 0, nelts * sizeof (char *));
395       *canonical = canonical_arr;
396     }
397
398   i = 0;
399   printf_unfiltered ("[0] cancel\n[1] all\n");
400   while (i < nelts)
401     {
402       init_sal (&return_values.sals[i]);        /* initialize to zeroes */
403       init_sal (&values.sals[i]);
404       if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK)
405         {
406           values.sals[i] = find_function_start_sal (sym_arr[i], funfirstline);
407           printf_unfiltered ("[%d] %s at %s:%d\n",
408                              (i + 2),
409                              SYMBOL_SOURCE_NAME (sym_arr[i]),
410                              values.sals[i].symtab->filename,
411                              values.sals[i].line);
412         }
413       else
414         printf_unfiltered ("?HERE\n");
415       i++;
416     }
417
418   if ((prompt = getenv ("PS2")) == NULL)
419     {
420       prompt = "> ";
421     }
422   args = command_line_input (prompt, 0, "overload-choice");
423
424   if (args == 0 || *args == 0)
425     error_no_arg ("one or more choice numbers");
426
427   i = 0;
428   while (*args)
429     {
430       int num;
431
432       arg1 = args;
433       while (*arg1 >= '0' && *arg1 <= '9')
434         arg1++;
435       if (*arg1 && *arg1 != ' ' && *arg1 != '\t')
436         error ("Arguments must be choice numbers.");
437
438       num = atoi (args);
439
440       if (num == 0)
441         error ("canceled");
442       else if (num == 1)
443         {
444           if (canonical_arr)
445             {
446               for (i = 0; i < nelts; i++)
447                 {
448                   if (canonical_arr[i] == NULL)
449                     {
450                       symname = SYMBOL_NAME (sym_arr[i]);
451                       canonical_arr[i] = savestring (symname, strlen (symname));
452                     }
453                 }
454             }
455           memcpy (return_values.sals, values.sals,
456                   (nelts * sizeof (struct symtab_and_line)));
457           return_values.nelts = nelts;
458           discard_cleanups (old_chain);
459           return return_values;
460         }
461
462       if (num >= nelts + 2)
463         {
464           printf_unfiltered ("No choice number %d.\n", num);
465         }
466       else
467         {
468           num -= 2;
469           if (values.sals[num].pc)
470             {
471               if (canonical_arr)
472                 {
473                   symname = SYMBOL_NAME (sym_arr[num]);
474                   make_cleanup (xfree, symname);
475                   canonical_arr[i] = savestring (symname, strlen (symname));
476                 }
477               return_values.sals[i++] = values.sals[num];
478               values.sals[num].pc = 0;
479             }
480           else
481             {
482               printf_unfiltered ("duplicate request for %d ignored.\n", num);
483             }
484         }
485
486       args = arg1;
487       while (*args == ' ' || *args == '\t')
488         args++;
489     }
490   return_values.nelts = i;
491   discard_cleanups (old_chain);
492   return return_values;
493 }
494 \f
495 /* The parser of linespec itself. */
496
497 /* Parse a string that specifies a line number.
498    Pass the address of a char * variable; that variable will be
499    advanced over the characters actually parsed.
500
501    The string can be:
502
503    LINENUM -- that line number in current file.  PC returned is 0.
504    FILE:LINENUM -- that line in that file.  PC returned is 0.
505    FUNCTION -- line number of openbrace of that function.
506    PC returned is the start of the function.
507    VARIABLE -- line number of definition of that variable.
508    PC returned is 0.
509    FILE:FUNCTION -- likewise, but prefer functions in that file.
510    *EXPR -- line in which address EXPR appears.
511
512    This may all be followed by an "if EXPR", which we ignore.
513
514    FUNCTION may be an undebuggable function found in minimal symbol table.
515
516    If the argument FUNFIRSTLINE is nonzero, we want the first line
517    of real code inside a function when a function is specified, and it is
518    not OK to specify a variable or type to get its line number.
519
520    DEFAULT_SYMTAB specifies the file to use if none is specified.
521    It defaults to current_source_symtab.
522    DEFAULT_LINE specifies the line number to use for relative
523    line numbers (that start with signs).  Defaults to current_source_line.
524    If CANONICAL is non-NULL, store an array of strings containing the canonical
525    line specs there if necessary. Currently overloaded member functions and
526    line numbers or static functions without a filename yield a canonical
527    line spec. The array and the line spec strings are allocated on the heap,
528    it is the callers responsibility to free them.
529
530    Note that it is possible to return zero for the symtab
531    if no file is validly specified.  Callers must check that.
532    Also, the line number returned may be invalid.  */
533
534 /* We allow single quotes in various places.  This is a hideous
535    kludge, which exists because the completer can't yet deal with the
536    lack of single quotes.  FIXME: write a linespec_completer which we
537    can use as appropriate instead of make_symbol_completion_list.  */
538
539 struct symtabs_and_lines
540 decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
541                int default_line, char ***canonical)
542 {
543   struct symtabs_and_lines values;
544   struct symtab_and_line val;
545   char *p;
546   char *q;
547   struct symtab *s = NULL;
548
549   struct symbol *sym;
550   /* The symtab that SYM was found in.  */
551   struct symtab *sym_symtab;
552
553   struct minimal_symbol *msymbol;
554   char *copy;
555   /* This is NULL if there are no parens in *ARGPTR, or a pointer to
556      the closing parenthesis if there are parens.  */
557   char *paren_pointer;
558   /* This says whether or not something in *ARGPTR is quoted with
559      completer_quotes (i.e. with single quotes).  */
560   int is_quoted;
561   /* Is part of *ARGPTR is enclosed in double quotes?  */
562   int is_quote_enclosed;
563   char *saved_arg = *argptr;
564
565   init_sal (&val);              /* initialize to zeroes */
566
567   /* Defaults have defaults.  */
568
569   initialize_defaults (&default_symtab, &default_line);
570   
571   /* See if arg is *PC */
572
573   if (**argptr == '*')
574     return decode_indirect (argptr);
575
576   /* Set various flags.
577    * 'paren_pointer' is important for overload checking, where
578    * we allow things like: 
579    *     (gdb) break c::f(int)
580    */
581
582   set_flags (*argptr, &is_quoted, &paren_pointer);
583
584   /* Check to see if it's a multipart linespec (with colons or
585      periods).  */
586
587   /* Locate the end of the first half of the linespec.  */
588
589   p = locate_first_half (argptr, &is_quote_enclosed);
590
591   /* Does it look like there actually were two parts?  */
592
593   if ((p[0] == ':' || p[0] == '.') && paren_pointer == NULL)
594     {
595       if (is_quoted)
596         *argptr = *argptr + 1;
597       
598       /* Is it a C++ or Java compound data structure?  */
599
600       if (p[0] == '.' || p[1] == ':')
601         return decode_compound (argptr, funfirstline, canonical,
602                                 saved_arg, p);
603
604       /* No, the first part is a filename; set s to be that file's
605          symtab.  Also, move argptr past the filename.  */
606
607       s = symtab_from_filename (argptr, p, is_quote_enclosed);
608     }
609 #if 0
610   /* No one really seems to know why this was added. It certainly
611      breaks the command line, though, whenever the passed
612      name is of the form ClassName::Method. This bit of code
613      singles out the class name, and if funfirstline is set (for
614      example, you are setting a breakpoint at this function),
615      you get an error. This did not occur with earlier
616      verions, so I am ifdef'ing this out. 3/29/99 */
617   else
618     {
619       /* Check if what we have till now is a symbol name */
620
621       /* We may be looking at a template instantiation such
622          as "foo<int>".  Check here whether we know about it,
623          instead of falling through to the code below which
624          handles ordinary function names, because that code
625          doesn't like seeing '<' and '>' in a name -- the
626          skip_quoted call doesn't go past them.  So see if we
627          can figure it out right now. */
628
629       copy = (char *) alloca (p - *argptr + 1);
630       memcpy (copy, *argptr, p - *argptr);
631       copy[p - *argptr] = '\000';
632       sym = lookup_symbol (copy, 0, VAR_NAMESPACE, 0, &sym_symtab);
633       if (sym)
634         {
635           *argptr = (*p == '\'') ? p + 1 : p;
636           return symbol_found (funfirstline, canonical, copy, sym,
637                                NULL, sym_symtab);
638         }
639       /* Otherwise fall out from here and go to file/line spec
640          processing, etc. */
641     }
642 #endif
643
644   /* S is specified file's symtab, or 0 if no file specified.
645      arg no longer contains the file name.  */
646
647   /* Check whether arg is all digits (and sign) */
648
649   q = *argptr;
650   if (*q == '-' || *q == '+')
651     q++;
652   while (*q >= '0' && *q <= '9')
653     q++;
654
655   if (q != *argptr && (*q == 0 || *q == ' ' || *q == '\t' || *q == ','))
656     {
657       /* We found a token consisting of all digits -- at least one digit.  */
658       enum sign
659         {
660           none, plus, minus
661         }
662       sign = none;
663
664       /* We might need a canonical line spec if no file was specified.  */
665       int need_canonical = (s == 0) ? 1 : 0;
666
667       /* This is where we need to make sure that we have good defaults.
668          We must guarantee that this section of code is never executed
669          when we are called with just a function name, since
670          set_default_source_symtab_and_line uses
671          select_source_symtab that calls us with such an argument  */
672
673       if (s == 0 && default_symtab == 0)
674         {
675           /* Make sure we have at least a default source file. */
676           set_default_source_symtab_and_line ();
677           initialize_defaults (&default_symtab, &default_line);
678         }
679
680       if (**argptr == '+')
681         sign = plus, (*argptr)++;
682       else if (**argptr == '-')
683         sign = minus, (*argptr)++;
684       val.line = atoi (*argptr);
685       switch (sign)
686         {
687         case plus:
688           if (q == *argptr)
689             val.line = 5;
690           if (s == 0)
691             val.line = default_line + val.line;
692           break;
693         case minus:
694           if (q == *argptr)
695             val.line = 15;
696           if (s == 0)
697             val.line = default_line - val.line;
698           else
699             val.line = 1;
700           break;
701         case none:
702           break;                /* No need to adjust val.line.  */
703         }
704
705       while (*q == ' ' || *q == '\t')
706         q++;
707       *argptr = q;
708       if (s == 0)
709         s = default_symtab;
710
711       /* It is possible that this source file has more than one symtab, 
712          and that the new line number specification has moved us from the
713          default (in s) to a new one.  */
714       val.symtab = find_line_symtab (s, val.line, NULL, NULL);
715       if (val.symtab == 0)
716         val.symtab = s;
717
718       val.pc = 0;
719       values.sals = (struct symtab_and_line *)
720         xmalloc (sizeof (struct symtab_and_line));
721       values.sals[0] = val;
722       values.nelts = 1;
723       if (need_canonical)
724         build_canonical_line_spec (values.sals, NULL, canonical);
725       return values;
726     }
727
728   /* Arg token is not digits => try it as a variable name
729      Find the next token (everything up to end or next whitespace).  */
730
731   if (**argptr == '$')          /* May be a convenience variable */
732     p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1));        /* One or two $ chars possible */
733   else if (is_quoted)
734     {
735       p = skip_quoted (*argptr);
736       if (p[-1] != '\'')
737         error ("Unmatched single quote.");
738     }
739   else if (paren_pointer != NULL)
740     {
741       p = paren_pointer + 1;
742     }
743   else
744     {
745       p = skip_quoted (*argptr);
746     }
747
748   copy = (char *) alloca (p - *argptr + 1);
749   memcpy (copy, *argptr, p - *argptr);
750   copy[p - *argptr] = '\0';
751   if (p != *argptr
752       && copy[0]
753       && copy[0] == copy[p - *argptr - 1]
754       && strchr (get_gdb_completer_quote_characters (), copy[0]) != NULL)
755     {
756       copy[p - *argptr - 1] = '\0';
757       copy++;
758     }
759   while (*p == ' ' || *p == '\t')
760     p++;
761   *argptr = p;
762
763   /* If it starts with $: may be a legitimate variable or routine name
764      (e.g. HP-UX millicode routines such as $$dyncall), or it may
765      be history value, or it may be a convenience variable */
766
767   if (*copy == '$')
768     {
769       struct value *valx;
770       int index = 0;
771       int need_canonical = 0;
772
773       p = (copy[1] == '$') ? copy + 2 : copy + 1;
774       while (*p >= '0' && *p <= '9')
775         p++;
776       if (!*p)                  /* reached end of token without hitting non-digit */
777         {
778           /* We have a value history reference */
779           sscanf ((copy[1] == '$') ? copy + 2 : copy + 1, "%d", &index);
780           valx = access_value_history ((copy[1] == '$') ? -index : index);
781           if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT)
782             error ("History values used in line specs must have integer values.");
783         }
784       else
785         {
786           /* Not all digits -- may be user variable/function or a
787              convenience variable */
788
789           /* Look up entire name as a symbol first */
790           sym = lookup_symbol (copy, 0, VAR_NAMESPACE, 0, &sym_symtab);
791           s = (struct symtab *) 0;
792           need_canonical = 1;
793           /* Symbol was found --> jump to normal symbol processing.  */
794           if (sym)
795             return symbol_found (funfirstline, canonical, copy, sym,
796                                  NULL, sym_symtab);
797
798           /* If symbol was not found, look in minimal symbol tables */
799           msymbol = lookup_minimal_symbol (copy, NULL, NULL);
800           /* Min symbol was found --> jump to minsym processing. */
801           if (msymbol)
802             return minsym_found (funfirstline, msymbol);
803
804           /* Not a user variable or function -- must be convenience variable */
805           need_canonical = (s == 0) ? 1 : 0;
806           valx = value_of_internalvar (lookup_internalvar (copy + 1));
807           if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT)
808             error ("Convenience variables used in line specs must have integer values.");
809         }
810
811       /* Either history value or convenience value from above, in valx */
812       val.symtab = s ? s : default_symtab;
813       val.line = value_as_long (valx);
814       val.pc = 0;
815
816       values.sals = (struct symtab_and_line *) xmalloc (sizeof val);
817       values.sals[0] = val;
818       values.nelts = 1;
819
820       if (need_canonical)
821         build_canonical_line_spec (values.sals, NULL, canonical);
822
823       return values;
824     }
825
826
827   /* Look up that token as a variable.
828      If file specified, use that file's per-file block to start with.  */
829
830   sym = lookup_symbol (copy,
831                        (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
832                         : get_selected_block (0)),
833                        VAR_NAMESPACE, 0, &sym_symtab);
834
835   if (sym != NULL)
836     return symbol_found (funfirstline, canonical, copy, sym, s, sym_symtab);
837
838   msymbol = lookup_minimal_symbol (copy, NULL, NULL);
839
840   if (msymbol != NULL)
841     return minsym_found (funfirstline, msymbol);
842
843   if (!have_full_symbols () &&
844       !have_partial_symbols () && !have_minimal_symbols ())
845     error ("No symbol table is loaded.  Use the \"file\" command.");
846
847   error ("Function \"%s\" not defined.", copy);
848   return values;                /* for lint */
849 }
850
851 \f
852
853 /* Now, more helper functions for decode_line_1.  Some conventions
854    that these functions follow:
855
856    Decode_line_1 typically passes along some of its arguments or local
857    variables to the subfunctions.  It passes the variables by
858    reference if they are modified by the subfunction, and by value
859    otherwise.
860
861    Some of the functions have side effects that don't arise from
862    variables that are passed by reference.  In particular, if a
863    function is passed ARGPTR as an argument, it modifies what ARGPTR
864    points to; typically, it advances *ARGPTR past whatever substring
865    it has just looked at.  (If it doesn't modify *ARGPTR, then the
866    function gets passed *ARGPTR instead, which is then called ARG: see
867    set_flags, for example.)  Also, functions that return a struct
868    symtabs_and_lines may modify CANONICAL, as in the description of
869    decode_line_1.
870
871    If a function returns a struct symtabs_and_lines, then that struct
872    will immediately make its way up the call chain to be returned by
873    decode_line_1.  In particular, all of the functions decode_XXX
874    calculate the appropriate struct symtabs_and_lines, under the
875    assumption that their argument is of the form XXX.  */
876
877 /* First, some functions to initialize stuff at the beggining of the
878    function.  */
879
880 static void
881 initialize_defaults (struct symtab **default_symtab, int *default_line)
882 {
883   if (*default_symtab == 0)
884     {
885       /* Use whatever we have for the default source line.  We don't use
886          get_current_or_default_symtab_and_line as it can recurse and call
887          us back! */
888       struct symtab_and_line cursal = 
889         get_current_source_symtab_and_line ();
890       
891       *default_symtab = cursal.symtab;
892       *default_line = cursal.line;
893     }
894 }
895
896 static void
897 set_flags (char *arg, int *is_quoted, char **paren_pointer)
898 {
899   char *ii;
900   int has_if = 0;
901
902   /* 'has_if' is for the syntax:
903    *     (gdb) break foo if (a==b)
904    */
905   if ((ii = strstr (arg, " if ")) != NULL ||
906       (ii = strstr (arg, "\tif ")) != NULL ||
907       (ii = strstr (arg, " if\t")) != NULL ||
908       (ii = strstr (arg, "\tif\t")) != NULL ||
909       (ii = strstr (arg, " if(")) != NULL ||
910       (ii = strstr (arg, "\tif( ")) != NULL)
911     has_if = 1;
912   /* Temporarily zap out "if (condition)" to not
913    * confuse the parenthesis-checking code below.
914    * This is undone below. Do not change ii!!
915    */
916   if (has_if)
917     {
918       *ii = '\0';
919     }
920
921   *is_quoted = (*arg
922                 && strchr (get_gdb_completer_quote_characters (),
923                            *arg) != NULL);
924
925   *paren_pointer = strchr (arg, '(');
926   if (*paren_pointer != NULL)
927     *paren_pointer = strrchr (*paren_pointer, ')');
928
929   /* Now that we're safely past the paren_pointer check,
930    * put back " if (condition)" so outer layers can see it 
931    */
932   if (has_if)
933     *ii = ' ';
934 }
935
936 \f
937
938 /* Decode arg of the form *PC.  */
939
940 static struct symtabs_and_lines
941 decode_indirect (char **argptr)
942 {
943   struct symtabs_and_lines values;
944   CORE_ADDR pc;
945   
946   (*argptr)++;
947   pc = parse_and_eval_address_1 (argptr);
948
949   values.sals = (struct symtab_and_line *)
950     xmalloc (sizeof (struct symtab_and_line));
951
952   values.nelts = 1;
953   values.sals[0] = find_pc_line (pc, 0);
954   values.sals[0].pc = pc;
955   values.sals[0].section = find_pc_overlay (pc);
956
957   return values;
958 }
959
960 \f
961
962 /* Locate the first half of the linespec, ending in a colon, period,
963    or whitespace.  (More or less.)  Also, check to see if *ARGPTR is
964    enclosed in double quotes; if so, set is_quote_enclosed, advance
965    ARGPTR past that and zero out the trailing double quote.  */
966
967 static char *
968 locate_first_half (char **argptr, int *is_quote_enclosed)
969 {
970   char *ii;
971   char *p, *p1;
972   int has_comma;
973
974   /* Maybe we were called with a line range FILENAME:LINENUM,FILENAME:LINENUM
975      and we must isolate the first half.  Outer layers will call again later
976      for the second half.
977
978      Don't count commas that appear in argument lists of overloaded
979      functions, or in quoted strings.  It's stupid to go to this much
980      trouble when the rest of the function is such an obvious roach hotel.  */
981   ii = find_toplevel_char (*argptr, ',');
982   has_comma = (ii != 0);
983
984   /* Temporarily zap out second half to not
985    * confuse the code below.
986    * This is undone below. Do not change ii!!
987    */
988   if (has_comma)
989     {
990       *ii = '\0';
991     }
992
993   /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
994   /* May also be CLASS::MEMBER, or NAMESPACE::NAME */
995   /* Look for ':', but ignore inside of <> */
996
997   p = *argptr;
998   if (p[0] == '"')
999     {
1000       *is_quote_enclosed = 1;
1001       (*argptr)++;
1002       p++;
1003     }
1004   else
1005     *is_quote_enclosed = 0;
1006   for (; *p; p++)
1007     {
1008       if (p[0] == '<')
1009         {
1010           char *temp_end = find_template_name_end (p);
1011           if (!temp_end)
1012             error ("malformed template specification in command");
1013           p = temp_end;
1014         }
1015       /* Check for the end of the first half of the linespec.  End of line,
1016          a tab, a double colon or the last single colon, or a space.  But
1017          if enclosed in double quotes we do not break on enclosed spaces */
1018       if (!*p
1019           || p[0] == '\t'
1020           || ((p[0] == ':')
1021               && ((p[1] == ':') || (strchr (p + 1, ':') == NULL)))
1022           || ((p[0] == ' ') && !*is_quote_enclosed))
1023         break;
1024       if (p[0] == '.' && strchr (p, ':') == NULL)       /* Java qualified method. */
1025         {
1026           /* Find the *last* '.', since the others are package qualifiers. */
1027           for (p1 = p; *p1; p1++)
1028             {
1029               if (*p1 == '.')
1030                 p = p1;
1031             }
1032           break;
1033         }
1034     }
1035   while (p[0] == ' ' || p[0] == '\t')
1036     p++;
1037
1038   /* if the closing double quote was left at the end, remove it */
1039   if (*is_quote_enclosed)
1040     {
1041       char *closing_quote = strchr (p - 1, '"');
1042       if (closing_quote && closing_quote[1] == '\0')
1043         *closing_quote = '\0';
1044     }
1045
1046   /* Now that we've safely parsed the first half,
1047    * put back ',' so outer layers can see it 
1048    */
1049   if (has_comma)
1050     *ii = ',';
1051
1052   return p;
1053 }
1054
1055 \f
1056
1057 /* This handles C++ and Java compound data structures.  P should point
1058    at the first component separator, i.e. double-colon or period.  */
1059
1060 static struct symtabs_and_lines
1061 decode_compound (char **argptr, int funfirstline, char ***canonical,
1062                  char *saved_arg, char *p)
1063 {
1064   struct symtabs_and_lines values;
1065   char *p1, *p2;
1066 #if 0
1067   char *q, *q1;
1068 #endif
1069   char *saved_arg2 = *argptr;
1070   char *temp_end;
1071   struct symbol *sym;
1072   /* The symtab that SYM was found in.  */
1073   struct symtab *sym_symtab;
1074   char *copy;
1075   struct symbol *sym_class;
1076   int i1;
1077   struct symbol **sym_arr;
1078   struct type *t;
1079
1080   /* First check for "global" namespace specification,
1081      of the form "::foo". If found, skip over the colons
1082      and jump to normal symbol processing */
1083   if (p[0] == ':' 
1084       && ((*argptr == p) || (p[-1] == ' ') || (p[-1] == '\t')))
1085     saved_arg2 += 2;
1086
1087   /* We have what looks like a class or namespace
1088      scope specification (A::B), possibly with many
1089      levels of namespaces or classes (A::B::C::D).
1090
1091      Some versions of the HP ANSI C++ compiler (as also possibly
1092      other compilers) generate class/function/member names with
1093      embedded double-colons if they are inside namespaces. To
1094      handle this, we loop a few times, considering larger and
1095      larger prefixes of the string as though they were single
1096      symbols.  So, if the initially supplied string is
1097      A::B::C::D::foo, we have to look up "A", then "A::B",
1098      then "A::B::C", then "A::B::C::D", and finally
1099      "A::B::C::D::foo" as single, monolithic symbols, because
1100      A, B, C or D may be namespaces.
1101
1102      Note that namespaces can nest only inside other
1103      namespaces, and not inside classes.  So we need only
1104      consider *prefixes* of the string; there is no need to look up
1105      "B::C" separately as a symbol in the previous example. */
1106
1107   p2 = p;               /* save for restart */
1108   while (1)
1109     {
1110       /* Extract the class name.  */
1111       p1 = p;
1112       while (p != *argptr && p[-1] == ' ')
1113         --p;
1114       copy = (char *) alloca (p - *argptr + 1);
1115       memcpy (copy, *argptr, p - *argptr);
1116       copy[p - *argptr] = 0;
1117
1118       /* Discard the class name from the arg.  */
1119       p = p1 + (p1[0] == ':' ? 2 : 1);
1120       while (*p == ' ' || *p == '\t')
1121         p++;
1122       *argptr = p;
1123
1124       sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0,
1125                                  (struct symtab **) NULL);
1126
1127       if (sym_class &&
1128           (t = check_typedef (SYMBOL_TYPE (sym_class)),
1129            (TYPE_CODE (t) == TYPE_CODE_STRUCT
1130             || TYPE_CODE (t) == TYPE_CODE_UNION)))
1131         {
1132           /* Arg token is not digits => try it as a function name
1133              Find the next token(everything up to end or next blank). */
1134           if (**argptr
1135               && strchr (get_gdb_completer_quote_characters (),
1136                          **argptr) != NULL)
1137             {
1138               p = skip_quoted (*argptr);
1139               *argptr = *argptr + 1;
1140             }
1141           else
1142             {
1143               p = *argptr;
1144               while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p != ':')
1145                 p++;
1146             }
1147 /*
1148    q = operator_chars (*argptr, &q1);
1149    if (q1 - q)
1150    {
1151    char *opname;
1152    char *tmp = alloca (q1 - q + 1);
1153    memcpy (tmp, q, q1 - q);
1154    tmp[q1 - q] = '\0';
1155    opname = cplus_mangle_opname (tmp, DMGL_ANSI);
1156    if (opname == NULL)
1157    {
1158    cplusplus_error (saved_arg, "no mangling for \"%s\"\n", tmp);
1159    }
1160    copy = (char*) alloca (3 + strlen(opname));
1161    sprintf (copy, "__%s", opname);
1162    p = q1;
1163    }
1164    else
1165  */
1166           {
1167             copy = (char *) alloca (p - *argptr + 1);
1168             memcpy (copy, *argptr, p - *argptr);
1169             copy[p - *argptr] = '\0';
1170             if (p != *argptr
1171                 && copy[p - *argptr - 1]
1172                 && strchr (get_gdb_completer_quote_characters (),
1173                            copy[p - *argptr - 1]) != NULL)
1174               copy[p - *argptr - 1] = '\0';
1175           }
1176
1177           /* no line number may be specified */
1178           while (*p == ' ' || *p == '\t')
1179             p++;
1180           *argptr = p;
1181
1182           sym = 0;
1183           i1 = 0;       /*  counter for the symbol array */
1184           sym_arr = (struct symbol **) alloca (total_number_of_methods (t)
1185                                                * sizeof (struct symbol *));
1186
1187           if (destructor_name_p (copy, t))
1188             {
1189               /* Destructors are a special case.  */
1190               int m_index, f_index;
1191
1192               if (get_destructor_fn_field (t, &m_index, &f_index))
1193                 {
1194                   struct fn_field *f = TYPE_FN_FIELDLIST1 (t, m_index);
1195
1196                   sym_arr[i1] =
1197                     lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, f_index),
1198                                    NULL, VAR_NAMESPACE, (int *) NULL,
1199                                    (struct symtab **) NULL);
1200                   if (sym_arr[i1])
1201                     i1++;
1202                 }
1203             }
1204           else
1205             i1 = find_methods (t, copy, sym_arr);
1206           if (i1 == 1)
1207             {
1208               /* There is exactly one field with that name.  */
1209               sym = sym_arr[0];
1210
1211               if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1212                 {
1213                   values.sals = (struct symtab_and_line *)
1214                     xmalloc (sizeof (struct symtab_and_line));
1215                   values.nelts = 1;
1216                   values.sals[0] = find_function_start_sal (sym,
1217                                                             funfirstline);
1218                 }
1219               else
1220                 {
1221                   values.nelts = 0;
1222                 }
1223               return values;
1224             }
1225           if (i1 > 0)
1226             {
1227               /* There is more than one field with that name
1228                  (overloaded).  Ask the user which one to use.  */
1229               return decode_line_2 (sym_arr, i1, funfirstline, canonical);
1230             }
1231           else
1232             {
1233               char *tmp;
1234
1235               if (is_operator_name (copy))
1236                 {
1237                   tmp = (char *) alloca (strlen (copy + 3) + 9);
1238                   strcpy (tmp, "operator ");
1239                   strcat (tmp, copy + 3);
1240                 }
1241               else
1242                 tmp = copy;
1243               if (tmp[0] == '~')
1244                 cplusplus_error (saved_arg,
1245                                  "the class `%s' does not have destructor defined\n",
1246                                  SYMBOL_SOURCE_NAME (sym_class));
1247               else
1248                 cplusplus_error (saved_arg,
1249                                  "the class %s does not have any method named %s\n",
1250                                  SYMBOL_SOURCE_NAME (sym_class), tmp);
1251             }
1252         }
1253
1254       /* Move pointer up to next possible class/namespace token */
1255       p = p2 + 1;       /* restart with old value +1 */
1256       /* Move pointer ahead to next double-colon */
1257       while (*p && (p[0] != ' ') && (p[0] != '\t') && (p[0] != '\''))
1258         {
1259           if (p[0] == '<')
1260             {
1261               temp_end = find_template_name_end (p);
1262               if (!temp_end)
1263                 error ("malformed template specification in command");
1264               p = temp_end;
1265             }
1266           else if ((p[0] == ':') && (p[1] == ':'))
1267             break;      /* found double-colon */
1268           else
1269             p++;
1270         }
1271
1272       if (*p != ':')
1273         break;          /* out of the while (1) */
1274
1275       p2 = p;           /* save restart for next time around */
1276       *argptr = saved_arg2;     /* restore argptr */
1277     }                   /* while (1) */
1278
1279   /* Last chance attempt -- check entire name as a symbol */
1280   /* Use "copy" in preparation for jumping out of this block,
1281      to be consistent with usage following the jump target */
1282   copy = (char *) alloca (p - saved_arg2 + 1);
1283   memcpy (copy, saved_arg2, p - saved_arg2);
1284   /* Note: if is_quoted should be true, we snuff out quote here anyway */
1285   copy[p - saved_arg2] = '\000';
1286   /* Set argptr to skip over the name */
1287   *argptr = (*p == '\'') ? p + 1 : p;
1288   /* Look up entire name */
1289   sym = lookup_symbol (copy, 0, VAR_NAMESPACE, 0, &sym_symtab);
1290   if (sym)
1291     return symbol_found (funfirstline, canonical, copy, sym,
1292                          NULL, sym_symtab);
1293
1294   /* Couldn't find any interpretation as classes/namespaces, so give up */
1295   /* The quotes are important if copy is empty.  */
1296   cplusplus_error (saved_arg,
1297                    "Can't find member of namespace, class, struct, or union named \"%s\"\n",
1298                    copy);
1299 }
1300
1301 \f
1302
1303 /* Return the symtab associated to the filename given by the substring
1304    of *ARGPTR ending at P, and advance ARGPTR past that filename.  */
1305
1306 static struct symtab *
1307 symtab_from_filename (char **argptr, char *p, int is_quote_enclosed)
1308 {
1309   char *p1;
1310   char *copy;
1311   struct symtab *s;
1312   
1313   p1 = p;
1314   while (p != *argptr && p[-1] == ' ')
1315     --p;
1316   if ((*p == '"') && is_quote_enclosed)
1317     --p;
1318   copy = (char *) alloca (p - *argptr + 1);
1319   memcpy (copy, *argptr, p - *argptr);
1320   /* It may have the ending quote right after the file name */
1321   if (is_quote_enclosed && copy[p - *argptr - 1] == '"')
1322     copy[p - *argptr - 1] = 0;
1323   else
1324     copy[p - *argptr] = 0;
1325
1326   /* Find that file's data.  */
1327   s = lookup_symtab (copy);
1328   if (s == 0)
1329     {
1330       if (!have_full_symbols () && !have_partial_symbols ())
1331         error ("No symbol table is loaded.  Use the \"file\" command.");
1332       error ("No source file named %s.", copy);
1333     }
1334
1335   /* Discard the file name from the arg.  */
1336   p = p1 + 1;
1337   while (*p == ' ' || *p == '\t')
1338     p++;
1339   *argptr = p;
1340
1341   return s;
1342 }
1343
1344
1345 \f
1346
1347 /* Now come some functions that are called from multiple places within
1348    decode_line_1.  */
1349
1350 /* We've found a symbol SYM to associate with our linespec; build a
1351    corresponding struct symtabs_and_lines.  */
1352
1353 static struct symtabs_and_lines
1354 symbol_found (int funfirstline, char ***canonical, char *copy,
1355               struct symbol *sym, struct symtab *s,
1356               struct symtab *sym_symtab)
1357 {
1358   struct symtabs_and_lines values;
1359   
1360   if (SYMBOL_CLASS (sym) == LOC_BLOCK)
1361     {
1362       /* Arg is the name of a function */
1363       values.sals = (struct symtab_and_line *)
1364         xmalloc (sizeof (struct symtab_and_line));
1365       values.sals[0] = find_function_start_sal (sym, funfirstline);
1366       values.nelts = 1;
1367
1368       /* Don't use the SYMBOL_LINE; if used at all it points to
1369          the line containing the parameters or thereabouts, not
1370          the first line of code.  */
1371
1372       /* We might need a canonical line spec if it is a static
1373          function.  */
1374       if (s == 0)
1375         {
1376           struct blockvector *bv = BLOCKVECTOR (sym_symtab);
1377           struct block *b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1378           if (lookup_block_symbol (b, copy, NULL, VAR_NAMESPACE) != NULL)
1379             build_canonical_line_spec (values.sals, copy, canonical);
1380         }
1381       return values;
1382     }
1383   else
1384     {
1385       if (funfirstline)
1386         error ("\"%s\" is not a function", copy);
1387       else if (SYMBOL_LINE (sym) != 0)
1388         {
1389           /* We know its line number.  */
1390           values.sals = (struct symtab_and_line *)
1391             xmalloc (sizeof (struct symtab_and_line));
1392           values.nelts = 1;
1393           memset (&values.sals[0], 0, sizeof (values.sals[0]));
1394           values.sals[0].symtab = sym_symtab;
1395           values.sals[0].line = SYMBOL_LINE (sym);
1396           return values;
1397         }
1398       else
1399         /* This can happen if it is compiled with a compiler which doesn't
1400            put out line numbers for variables.  */
1401         /* FIXME: Shouldn't we just set .line and .symtab to zero
1402            and return?  For example, "info line foo" could print
1403            the address.  */
1404         error ("Line number not known for symbol \"%s\"", copy);
1405     }
1406 }
1407
1408 /* We've found a minimal symbol MSYMBOL to associate with our
1409    linespec; build a corresponding struct symtabs_and_lines.  */
1410
1411 static struct symtabs_and_lines
1412 minsym_found (int funfirstline, struct minimal_symbol *msymbol)
1413 {
1414   struct symtabs_and_lines values;
1415
1416   values.sals = (struct symtab_and_line *)
1417     xmalloc (sizeof (struct symtab_and_line));
1418   values.sals[0] = find_pc_sect_line (SYMBOL_VALUE_ADDRESS (msymbol),
1419                                       (struct sec *) 0, 0);
1420   values.sals[0].section = SYMBOL_BFD_SECTION (msymbol);
1421   if (funfirstline)
1422     {
1423       values.sals[0].pc += FUNCTION_START_OFFSET;
1424       values.sals[0].pc = SKIP_PROLOGUE (values.sals[0].pc);
1425     }
1426   values.nelts = 1;
1427   return values;
1428 }