forked from gbenson/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinespec.c
3917 lines (3214 loc) · 108 KB
/
linespec.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Parser for linespec for the GNU debugger, GDB.
Copyright (C) 1986-2015 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "symtab.h"
#include "frame.h"
#include "command.h"
#include "symfile.h"
#include "objfiles.h"
#include "source.h"
#include "demangle.h"
#include "value.h"
#include "completer.h"
#include "cp-abi.h"
#include "cp-support.h"
#include "parser-defs.h"
#include "block.h"
#include "objc-lang.h"
#include "linespec.h"
#include "language.h"
#include "interps.h"
#include "mi/mi-cmds.h"
#include "target.h"
#include "arch-utils.h"
#include <ctype.h>
#include "cli/cli-utils.h"
#include "filenames.h"
#include "ada-lang.h"
#include "stack.h"
#include "location.h"
typedef struct symbol *symbolp;
DEF_VEC_P (symbolp);
typedef struct type *typep;
DEF_VEC_P (typep);
/* An address entry is used to ensure that any given location is only
added to the result a single time. It holds an address and the
program space from which the address came. */
struct address_entry
{
struct program_space *pspace;
CORE_ADDR addr;
};
typedef struct bound_minimal_symbol bound_minimal_symbol_d;
DEF_VEC_O (bound_minimal_symbol_d);
/* A linespec. Elements of this structure are filled in by a parser
(either parse_linespec or some other function). The structure is
then converted into SALs by convert_linespec_to_sals. */
struct linespec
{
/* An explicit location describing the SaLs. */
struct explicit_location explicit_loc;
/* The list of symtabs to search to which to limit the search. May not
be NULL. If explicit.SOURCE_FILENAME is NULL (no user-specified
filename), FILE_SYMTABS should contain one single NULL member. This
will cause the code to use the default symtab. */
VEC (symtab_ptr) *file_symtabs;
/* A list of matching function symbols and minimal symbols. Both lists
may be NULL if no matching symbols were found. */
VEC (symbolp) *function_symbols;
VEC (bound_minimal_symbol_d) *minimal_symbols;
/* A structure of matching label symbols and the corresponding
function symbol in which the label was found. Both may be NULL
or both must be non-NULL. */
struct
{
VEC (symbolp) *label_symbols;
VEC (symbolp) *function_symbols;
} labels;
};
typedef struct linespec *linespec_p;
/* A canonical linespec represented as a symtab-related string.
Each entry represents the "SYMTAB:SUFFIX" linespec string.
SYMTAB can be converted for example by symtab_to_fullname or
symtab_to_filename_for_display as needed. */
struct linespec_canonical_name
{
/* Remaining text part of the linespec string. */
char *suffix;
/* If NULL then SUFFIX is the whole linespec string. */
struct symtab *symtab;
};
/* An instance of this is used to keep all state while linespec
operates. This instance is passed around as a 'this' pointer to
the various implementation methods. */
struct linespec_state
{
/* The language in use during linespec processing. */
const struct language_defn *language;
/* The program space as seen when the module was entered. */
struct program_space *program_space;
/* The default symtab to use, if no other symtab is specified. */
struct symtab *default_symtab;
/* The default line to use. */
int default_line;
/* The 'funfirstline' value that was passed in to decode_line_1 or
decode_line_full. */
int funfirstline;
/* Nonzero if we are running in 'list' mode; see decode_line_list. */
int list_mode;
/* The 'canonical' value passed to decode_line_full, or NULL. */
struct linespec_result *canonical;
/* Canonical strings that mirror the symtabs_and_lines result. */
struct linespec_canonical_name *canonical_names;
/* This is a set of address_entry objects which is used to prevent
duplicate symbols from being entered into the result. */
htab_t addr_set;
/* Are we building a linespec? */
int is_linespec;
};
/* This is a helper object that is used when collecting symbols into a
result. */
struct collect_info
{
/* The linespec object in use. */
struct linespec_state *state;
/* A list of symtabs to which to restrict matches. */
VEC (symtab_ptr) *file_symtabs;
/* The result being accumulated. */
struct
{
VEC (symbolp) *symbols;
VEC (bound_minimal_symbol_d) *minimal_symbols;
} result;
};
/* Token types */
enum ls_token_type
{
/* A keyword */
LSTOKEN_KEYWORD = 0,
/* A colon "separator" */
LSTOKEN_COLON,
/* A string */
LSTOKEN_STRING,
/* A number */
LSTOKEN_NUMBER,
/* A comma */
LSTOKEN_COMMA,
/* EOI (end of input) */
LSTOKEN_EOI,
/* Consumed token */
LSTOKEN_CONSUMED
};
typedef enum ls_token_type linespec_token_type;
/* List of keywords */
static const char * const linespec_keywords[] = { "if", "thread", "task" };
#define IF_KEYWORD_INDEX 0
/* A token of the linespec lexer */
struct ls_token
{
/* The type of the token */
linespec_token_type type;
/* Data for the token */
union
{
/* A string, given as a stoken */
struct stoken string;
/* A keyword */
const char *keyword;
} data;
};
typedef struct ls_token linespec_token;
#define LS_TOKEN_STOKEN(TOK) (TOK).data.string
#define LS_TOKEN_KEYWORD(TOK) (TOK).data.keyword
/* An instance of the linespec parser. */
struct ls_parser
{
/* Lexer internal data */
struct
{
/* Save head of input stream. */
const char *saved_arg;
/* Head of the input stream. */
const char *stream;
#define PARSER_STREAM(P) ((P)->lexer.stream)
/* The current token. */
linespec_token current;
} lexer;
/* Is the entire linespec quote-enclosed? */
int is_quote_enclosed;
/* The state of the parse. */
struct linespec_state state;
#define PARSER_STATE(PPTR) (&(PPTR)->state)
/* The result of the parse. */
struct linespec result;
#define PARSER_RESULT(PPTR) (&(PPTR)->result)
};
typedef struct ls_parser linespec_parser;
/* A convenience macro for accessing the explicit location result of
the parser. */
#define PARSER_EXPLICIT(PPTR) (&PARSER_RESULT ((PPTR))->explicit_loc)
/* Prototypes for local functions. */
static void iterate_over_file_blocks (struct symtab *symtab,
const char *name, domain_enum domain,
symbol_found_callback_ftype *callback,
void *data);
static void initialize_defaults (struct symtab **default_symtab,
int *default_line);
CORE_ADDR linespec_expression_to_pc (const char **exp_ptr);
static struct symtabs_and_lines decode_objc (struct linespec_state *self,
linespec_p ls,
const char *arg);
static VEC (symtab_ptr) *symtabs_from_filename (const char *);
static VEC (symbolp) *find_label_symbols (struct linespec_state *self,
VEC (symbolp) *function_symbols,
VEC (symbolp) **label_funcs_ret,
const char *name);
static void find_linespec_symbols (struct linespec_state *self,
VEC (symtab_ptr) *file_symtabs,
const char *name,
VEC (symbolp) **symbols,
VEC (bound_minimal_symbol_d) **minsyms);
static struct line_offset
linespec_parse_variable (struct linespec_state *self,
const char *variable);
static int symbol_to_sal (struct symtab_and_line *result,
int funfirstline, struct symbol *sym);
static void add_matching_symbols_to_info (const char *name,
struct collect_info *info,
struct program_space *pspace);
static void add_all_symbol_names_from_pspace (struct collect_info *info,
struct program_space *pspace,
VEC (const_char_ptr) *names);
static VEC (symtab_ptr) *collect_symtabs_from_filename (const char *file);
static void decode_digits_ordinary (struct linespec_state *self,
linespec_p ls,
int line,
struct symtabs_and_lines *sals,
struct linetable_entry **best_entry);
static void decode_digits_list_mode (struct linespec_state *self,
linespec_p ls,
struct symtabs_and_lines *values,
struct symtab_and_line val);
static void minsym_found (struct linespec_state *self, struct objfile *objfile,
struct minimal_symbol *msymbol,
struct symtabs_and_lines *result);
static int compare_symbols (const void *a, const void *b);
static int compare_msymbols (const void *a, const void *b);
/* Permitted quote characters for the parser. This is different from the
completer's quote characters to allow backward compatibility with the
previous parser. */
static const char *const linespec_quote_characters = "\"\'";
/* Lexer functions. */
/* Lex a number from the input in PARSER. This only supports
decimal numbers.
Return true if input is decimal numbers. Return false if not. */
static int
linespec_lexer_lex_number (linespec_parser *parser, linespec_token *tokenp)
{
tokenp->type = LSTOKEN_NUMBER;
LS_TOKEN_STOKEN (*tokenp).length = 0;
LS_TOKEN_STOKEN (*tokenp).ptr = PARSER_STREAM (parser);
/* Keep any sign at the start of the stream. */
if (*PARSER_STREAM (parser) == '+' || *PARSER_STREAM (parser) == '-')
{
++LS_TOKEN_STOKEN (*tokenp).length;
++(PARSER_STREAM (parser));
}
while (isdigit (*PARSER_STREAM (parser)))
{
++LS_TOKEN_STOKEN (*tokenp).length;
++(PARSER_STREAM (parser));
}
/* If the next character in the input buffer is not a space, comma,
quote, or colon, this input does not represent a number. */
if (*PARSER_STREAM (parser) != '\0'
&& !isspace (*PARSER_STREAM (parser)) && *PARSER_STREAM (parser) != ','
&& *PARSER_STREAM (parser) != ':'
&& !strchr (linespec_quote_characters, *PARSER_STREAM (parser)))
{
PARSER_STREAM (parser) = LS_TOKEN_STOKEN (*tokenp).ptr;
return 0;
}
return 1;
}
/* See linespec.h. */
const char *
linespec_lexer_lex_keyword (const char *p)
{
int i;
if (p != NULL)
{
for (i = 0; i < ARRAY_SIZE (linespec_keywords); ++i)
{
int len = strlen (linespec_keywords[i]);
/* If P begins with one of the keywords and the next
character is whitespace, we may have found a keyword.
It is only a keyword if it is not followed by another
keyword. */
if (strncmp (p, linespec_keywords[i], len) == 0
&& isspace (p[len]))
{
int j;
/* Special case: "if" ALWAYS stops the lexer, since it
is not possible to predict what is going to appear in
the condition, which can only be parsed after SaLs have
been found. */
if (i != IF_KEYWORD_INDEX)
{
p += len;
p = skip_spaces_const (p);
for (j = 0; j < ARRAY_SIZE (linespec_keywords); ++j)
{
int nextlen = strlen (linespec_keywords[j]);
if (strncmp (p, linespec_keywords[j], nextlen) == 0
&& isspace (p[nextlen]))
return NULL;
}
}
return linespec_keywords[i];
}
}
}
return NULL;
}
/* See description in linespec.h. */
int
is_ada_operator (const char *string)
{
const struct ada_opname_map *mapping;
for (mapping = ada_opname_table;
mapping->encoded != NULL
&& !startswith (string, mapping->decoded); ++mapping)
;
return mapping->decoded == NULL ? 0 : strlen (mapping->decoded);
}
/* Find QUOTE_CHAR in STRING, accounting for the ':' terminal. Return
the location of QUOTE_CHAR, or NULL if not found. */
static const char *
skip_quote_char (const char *string, char quote_char)
{
const char *p, *last;
p = last = find_toplevel_char (string, quote_char);
while (p && *p != '\0' && *p != ':')
{
p = find_toplevel_char (p, quote_char);
if (p != NULL)
last = p++;
}
return last;
}
/* Make a writable copy of the string given in TOKEN, trimming
any trailing whitespace. */
static char *
copy_token_string (linespec_token token)
{
char *str, *s;
if (token.type == LSTOKEN_KEYWORD)
return xstrdup (LS_TOKEN_KEYWORD (token));
str = savestring (LS_TOKEN_STOKEN (token).ptr,
LS_TOKEN_STOKEN (token).length);
s = remove_trailing_whitespace (str, str + LS_TOKEN_STOKEN (token).length);
*s = '\0';
return str;
}
/* Does P represent the end of a quote-enclosed linespec? */
static int
is_closing_quote_enclosed (const char *p)
{
if (strchr (linespec_quote_characters, *p))
++p;
p = skip_spaces ((char *) p);
return (*p == '\0' || linespec_lexer_lex_keyword (p));
}
/* Find the end of the parameter list that starts with *INPUT.
This helper function assists with lexing string segments
which might contain valid (non-terminating) commas. */
static const char *
find_parameter_list_end (const char *input)
{
char end_char, start_char;
int depth;
const char *p;
start_char = *input;
if (start_char == '(')
end_char = ')';
else if (start_char == '<')
end_char = '>';
else
return NULL;
p = input;
depth = 0;
while (*p)
{
if (*p == start_char)
++depth;
else if (*p == end_char)
{
if (--depth == 0)
{
++p;
break;
}
}
++p;
}
return p;
}
/* Lex a string from the input in PARSER. */
static linespec_token
linespec_lexer_lex_string (linespec_parser *parser)
{
linespec_token token;
const char *start = PARSER_STREAM (parser);
token.type = LSTOKEN_STRING;
/* If the input stream starts with a quote character, skip to the next
quote character, regardless of the content. */
if (strchr (linespec_quote_characters, *PARSER_STREAM (parser)))
{
const char *end;
char quote_char = *PARSER_STREAM (parser);
/* Special case: Ada operators. */
if (PARSER_STATE (parser)->language->la_language == language_ada
&& quote_char == '\"')
{
int len = is_ada_operator (PARSER_STREAM (parser));
if (len != 0)
{
/* The input is an Ada operator. Return the quoted string
as-is. */
LS_TOKEN_STOKEN (token).ptr = PARSER_STREAM (parser);
LS_TOKEN_STOKEN (token).length = len;
PARSER_STREAM (parser) += len;
return token;
}
/* The input does not represent an Ada operator -- fall through
to normal quoted string handling. */
}
/* Skip past the beginning quote. */
++(PARSER_STREAM (parser));
/* Mark the start of the string. */
LS_TOKEN_STOKEN (token).ptr = PARSER_STREAM (parser);
/* Skip to the ending quote. */
end = skip_quote_char (PARSER_STREAM (parser), quote_char);
/* Error if the input did not terminate properly. */
if (end == NULL)
error (_("unmatched quote"));
/* Skip over the ending quote and mark the length of the string. */
PARSER_STREAM (parser) = (char *) ++end;
LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - 2 - start;
}
else
{
const char *p;
/* Otherwise, only identifier characters are permitted.
Spaces are the exception. In general, we keep spaces,
but only if the next characters in the input do not resolve
to one of the keywords.
This allows users to forgo quoting CV-qualifiers, template arguments,
and similar common language constructs. */
while (1)
{
if (isspace (*PARSER_STREAM (parser)))
{
p = skip_spaces_const (PARSER_STREAM (parser));
/* When we get here we know we've found something followed by
a space (we skip over parens and templates below).
So if we find a keyword now, we know it is a keyword and not,
say, a function name. */
if (linespec_lexer_lex_keyword (p) != NULL)
{
LS_TOKEN_STOKEN (token).ptr = start;
LS_TOKEN_STOKEN (token).length
= PARSER_STREAM (parser) - start;
return token;
}
/* Advance past the whitespace. */
PARSER_STREAM (parser) = p;
}
/* If the next character is EOI or (single) ':', the
string is complete; return the token. */
if (*PARSER_STREAM (parser) == 0)
{
LS_TOKEN_STOKEN (token).ptr = start;
LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - start;
return token;
}
else if (PARSER_STREAM (parser)[0] == ':')
{
/* Do not tokenize the C++ scope operator. */
if (PARSER_STREAM (parser)[1] == ':')
++(PARSER_STREAM (parser));
/* Do not tokenify if the input length so far is one
(i.e, a single-letter drive name) and the next character
is a directory separator. This allows Windows-style
paths to be recognized as filenames without quoting it. */
else if ((PARSER_STREAM (parser) - start) != 1
|| !IS_DIR_SEPARATOR (PARSER_STREAM (parser)[1]))
{
LS_TOKEN_STOKEN (token).ptr = start;
LS_TOKEN_STOKEN (token).length
= PARSER_STREAM (parser) - start;
return token;
}
}
/* Special case: permit quote-enclosed linespecs. */
else if (parser->is_quote_enclosed
&& strchr (linespec_quote_characters,
*PARSER_STREAM (parser))
&& is_closing_quote_enclosed (PARSER_STREAM (parser)))
{
LS_TOKEN_STOKEN (token).ptr = start;
LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - start;
return token;
}
/* Because commas may terminate a linespec and appear in
the middle of valid string input, special cases for
'<' and '(' are necessary. */
else if (*PARSER_STREAM (parser) == '<'
|| *PARSER_STREAM (parser) == '(')
{
const char *p;
p = find_parameter_list_end (PARSER_STREAM (parser));
if (p != NULL)
{
PARSER_STREAM (parser) = p;
continue;
}
}
/* Commas are terminators, but not if they are part of an
operator name. */
else if (*PARSER_STREAM (parser) == ',')
{
if ((PARSER_STATE (parser)->language->la_language
== language_cplus)
&& (PARSER_STREAM (parser) - start) > 8
/* strlen ("operator") */)
{
char *p = strstr (start, "operator");
if (p != NULL && is_operator_name (p))
{
/* This is an operator name. Keep going. */
++(PARSER_STREAM (parser));
continue;
}
}
/* Comma terminates the string. */
LS_TOKEN_STOKEN (token).ptr = start;
LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - start;
return token;
}
/* Advance the stream. */
++(PARSER_STREAM (parser));
}
}
return token;
}
/* Lex a single linespec token from PARSER. */
static linespec_token
linespec_lexer_lex_one (linespec_parser *parser)
{
const char *keyword;
if (parser->lexer.current.type == LSTOKEN_CONSUMED)
{
/* Skip any whitespace. */
PARSER_STREAM (parser) = skip_spaces_const (PARSER_STREAM (parser));
/* Check for a keyword, they end the linespec. */
keyword = linespec_lexer_lex_keyword (PARSER_STREAM (parser));
if (keyword != NULL)
{
parser->lexer.current.type = LSTOKEN_KEYWORD;
LS_TOKEN_KEYWORD (parser->lexer.current) = keyword;
/* We do not advance the stream here intentionally:
we would like lexing to stop when a keyword is seen.
PARSER_STREAM (parser) += strlen (keyword); */
return parser->lexer.current;
}
/* Handle other tokens. */
switch (*PARSER_STREAM (parser))
{
case 0:
parser->lexer.current.type = LSTOKEN_EOI;
break;
case '+': case '-':
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
if (!linespec_lexer_lex_number (parser, &(parser->lexer.current)))
parser->lexer.current = linespec_lexer_lex_string (parser);
break;
case ':':
/* If we have a scope operator, lex the input as a string.
Otherwise, return LSTOKEN_COLON. */
if (PARSER_STREAM (parser)[1] == ':')
parser->lexer.current = linespec_lexer_lex_string (parser);
else
{
parser->lexer.current.type = LSTOKEN_COLON;
++(PARSER_STREAM (parser));
}
break;
case '\'': case '\"':
/* Special case: permit quote-enclosed linespecs. */
if (parser->is_quote_enclosed
&& is_closing_quote_enclosed (PARSER_STREAM (parser)))
{
++(PARSER_STREAM (parser));
parser->lexer.current.type = LSTOKEN_EOI;
}
else
parser->lexer.current = linespec_lexer_lex_string (parser);
break;
case ',':
parser->lexer.current.type = LSTOKEN_COMMA;
LS_TOKEN_STOKEN (parser->lexer.current).ptr
= PARSER_STREAM (parser);
LS_TOKEN_STOKEN (parser->lexer.current).length = 1;
++(PARSER_STREAM (parser));
break;
default:
/* If the input is not a number, it must be a string.
[Keywords were already considered above.] */
parser->lexer.current = linespec_lexer_lex_string (parser);
break;
}
}
return parser->lexer.current;
}
/* Consume the current token and return the next token in PARSER's
input stream. */
static linespec_token
linespec_lexer_consume_token (linespec_parser *parser)
{
parser->lexer.current.type = LSTOKEN_CONSUMED;
return linespec_lexer_lex_one (parser);
}
/* Return the next token without consuming the current token. */
static linespec_token
linespec_lexer_peek_token (linespec_parser *parser)
{
linespec_token next;
const char *saved_stream = PARSER_STREAM (parser);
linespec_token saved_token = parser->lexer.current;
next = linespec_lexer_consume_token (parser);
PARSER_STREAM (parser) = saved_stream;
parser->lexer.current = saved_token;
return next;
}
/* Helper functions. */
/* Add SAL to SALS. */
static void
add_sal_to_sals_basic (struct symtabs_and_lines *sals,
struct symtab_and_line *sal)
{
++sals->nelts;
sals->sals = xrealloc (sals->sals, sals->nelts * sizeof (sals->sals[0]));
sals->sals[sals->nelts - 1] = *sal;
}
/* Add SAL to SALS, and also update SELF->CANONICAL_NAMES to reflect
the new sal, if needed. If not NULL, SYMNAME is the name of the
symbol to use when constructing the new canonical name.
If LITERAL_CANONICAL is non-zero, SYMNAME will be used as the
canonical name for the SAL. */
static void
add_sal_to_sals (struct linespec_state *self,
struct symtabs_and_lines *sals,
struct symtab_and_line *sal,
const char *symname, int literal_canonical)
{
add_sal_to_sals_basic (sals, sal);
if (self->canonical)
{
struct linespec_canonical_name *canonical;
self->canonical_names = xrealloc (self->canonical_names,
(sals->nelts
* sizeof (*self->canonical_names)));
canonical = &self->canonical_names[sals->nelts - 1];
if (!literal_canonical && sal->symtab)
{
const char *fullname = symtab_to_fullname (sal->symtab);
/* Note that the filter doesn't have to be a valid linespec
input. We only apply the ":LINE" treatment to Ada for
the time being. */
if (symname != NULL && sal->line != 0
&& self->language->la_language == language_ada)
canonical->suffix = xstrprintf ("%s:%d", symname, sal->line);
else if (symname != NULL)
canonical->suffix = xstrdup (symname);
else
canonical->suffix = xstrprintf ("%d", sal->line);
canonical->symtab = sal->symtab;
}
else
{
if (symname != NULL)
canonical->suffix = xstrdup (symname);
else
canonical->suffix = xstrdup ("<unknown>");
canonical->symtab = NULL;
}
}
}
/* A hash function for address_entry. */
static hashval_t
hash_address_entry (const void *p)
{
const struct address_entry *aep = p;
hashval_t hash;
hash = iterative_hash_object (aep->pspace, 0);
return iterative_hash_object (aep->addr, hash);
}
/* An equality function for address_entry. */
static int
eq_address_entry (const void *a, const void *b)
{
const struct address_entry *aea = a;
const struct address_entry *aeb = b;
return aea->pspace == aeb->pspace && aea->addr == aeb->addr;
}
/* Check whether the address, represented by PSPACE and ADDR, is
already in the set. If so, return 0. Otherwise, add it and return
1. */
static int
maybe_add_address (htab_t set, struct program_space *pspace, CORE_ADDR addr)
{
struct address_entry e, *p;
void **slot;
e.pspace = pspace;
e.addr = addr;
slot = htab_find_slot (set, &e, INSERT);
if (*slot)
return 0;
p = XNEW (struct address_entry);
memcpy (p, &e, sizeof (struct address_entry));
*slot = p;
return 1;
}
/* A callback function and the additional data to call it with. */
struct symbol_and_data_callback
{
/* The callback to use. */
symbol_found_callback_ftype *callback;
/* Data to be passed to the callback. */
void *data;
};
/* A helper for iterate_over_all_matching_symtabs that is used to
restrict calls to another callback to symbols representing inline
symbols only. */
static int
iterate_inline_only (struct symbol *sym, void *d)
{
if (SYMBOL_INLINED (sym))
{
struct symbol_and_data_callback *cad = d;
return cad->callback (sym, cad->data);
}
return 1; /* Continue iterating. */
}
/* Some data for the expand_symtabs_matching callback. */
struct symbol_matcher_data
{
/* The lookup name against which symbol name should be compared. */
const char *lookup_name;
/* The routine to be used for comparison. */
symbol_name_cmp_ftype symbol_name_cmp;
};
/* A helper for iterate_over_all_matching_symtabs that is passed as a
callback to the expand_symtabs_matching method. */
static int
iterate_name_matcher (const char *name, void *d)
{
const struct symbol_matcher_data *data = d;
if (data->symbol_name_cmp (name, data->lookup_name) == 0)
return 1; /* Expand this symbol's symbol table. */
return 0; /* Skip this symbol. */
}
/* A helper that walks over all matching symtabs in all objfiles and
calls CALLBACK for each symbol matching NAME. If SEARCH_PSPACE is
not NULL, then the search is restricted to just that program
space. If INCLUDE_INLINE is nonzero then symbols representing
inlined instances of functions will be included in the result. */
static void
iterate_over_all_matching_symtabs (struct linespec_state *state,
const char *name,
const domain_enum domain,
symbol_found_callback_ftype *callback,
void *data,
struct program_space *search_pspace,
int include_inline)
{
struct objfile *objfile;
struct program_space *pspace;
struct symbol_matcher_data matcher_data;
matcher_data.lookup_name = name;
matcher_data.symbol_name_cmp =
state->language->la_get_symbol_name_cmp != NULL
? state->language->la_get_symbol_name_cmp (name)
: strcmp_iw;
ALL_PSPACES (pspace)
{
if (search_pspace != NULL && search_pspace != pspace)
continue;
if (pspace->executing_startup)
continue;
set_current_program_space (pspace);
ALL_OBJFILES (objfile)
{
struct compunit_symtab *cu;