forked from gbenson/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsymtab.c
2155 lines (1838 loc) · 60.9 KB
/
psymtab.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
/* Partial symbol tables.
Copyright (C) 2009-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 "psympriv.h"
#include "objfiles.h"
#include "block.h"
#include "filenames.h"
#include "source.h"
#include "addrmap.h"
#include "gdbtypes.h"
#include "bcache.h"
#include "ui-out.h"
#include "command.h"
#include "readline/readline.h"
#include "gdb_regex.h"
#include "dictionary.h"
#include "language.h"
#include "cp-support.h"
#include "gdbcmd.h"
#ifndef DEV_TTY
#define DEV_TTY "/dev/tty"
#endif
struct psymbol_bcache
{
struct bcache *bcache;
};
static struct partial_symbol *match_partial_symbol (struct objfile *,
struct partial_symtab *,
int,
const char *, domain_enum,
symbol_compare_ftype *,
symbol_compare_ftype *);
static struct partial_symbol *lookup_partial_symbol (struct objfile *,
struct partial_symtab *,
const char *, int,
domain_enum);
static const char *psymtab_to_fullname (struct partial_symtab *ps);
static struct partial_symbol *find_pc_sect_psymbol (struct objfile *,
struct partial_symtab *,
CORE_ADDR,
struct obj_section *);
static void fixup_psymbol_section (struct partial_symbol *psym,
struct objfile *objfile);
static struct compunit_symtab *psymtab_to_symtab (struct objfile *objfile,
struct partial_symtab *pst);
/* Ensure that the partial symbols for OBJFILE have been loaded. This
function always returns its argument, as a convenience. */
struct objfile *
require_partial_symbols (struct objfile *objfile, int verbose)
{
if ((objfile->flags & OBJF_PSYMTABS_READ) == 0)
{
objfile->flags |= OBJF_PSYMTABS_READ;
if (objfile->sf->sym_read_psymbols)
{
if (verbose)
{
printf_unfiltered (_("Reading symbols from %s..."),
objfile_name (objfile));
gdb_flush (gdb_stdout);
}
(*objfile->sf->sym_read_psymbols) (objfile);
if (verbose)
{
if (!objfile_has_symbols (objfile))
{
wrap_here ("");
printf_unfiltered (_("(no debugging symbols found)..."));
wrap_here ("");
}
printf_unfiltered (_("done.\n"));
}
}
}
return objfile;
}
/* Traverse all psymtabs in one objfile, requiring that the psymtabs
be read in. */
#define ALL_OBJFILE_PSYMTABS_REQUIRED(objfile, p) \
for ((p) = require_partial_symbols (objfile, 1)->psymtabs; \
(p) != NULL; \
(p) = (p)->next)
/* We want to make sure this file always requires psymtabs. */
#undef ALL_OBJFILE_PSYMTABS
/* Traverse all psymtabs in all objfiles. */
#define ALL_PSYMTABS(objfile, p) \
ALL_OBJFILES (objfile) \
ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
/* Helper function for psym_map_symtabs_matching_filename that
expands the symtabs and calls the iterator. */
static int
partial_map_expand_apply (struct objfile *objfile,
const char *name,
const char *real_path,
struct partial_symtab *pst,
int (*callback) (struct symtab *, void *),
void *data)
{
struct compunit_symtab *last_made = objfile->compunit_symtabs;
/* Shared psymtabs should never be seen here. Instead they should
be handled properly by the caller. */
gdb_assert (pst->user == NULL);
/* Don't visit already-expanded psymtabs. */
if (pst->readin)
return 0;
/* This may expand more than one symtab, and we want to iterate over
all of them. */
psymtab_to_symtab (objfile, pst);
return iterate_over_some_symtabs (name, real_path, callback, data,
objfile->compunit_symtabs, last_made);
}
/* Psymtab version of map_symtabs_matching_filename. See its definition in
the definition of quick_symbol_functions in symfile.h. */
static int
psym_map_symtabs_matching_filename (struct objfile *objfile,
const char *name,
const char *real_path,
int (*callback) (struct symtab *,
void *),
void *data)
{
struct partial_symtab *pst;
const char *name_basename = lbasename (name);
ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
{
/* We can skip shared psymtabs here, because any file name will be
attached to the unshared psymtab. */
if (pst->user != NULL)
continue;
/* Anonymous psymtabs don't have a file name. */
if (pst->anonymous)
continue;
if (compare_filenames_for_search (pst->filename, name))
{
if (partial_map_expand_apply (objfile, name, real_path,
pst, callback, data))
return 1;
continue;
}
/* Before we invoke realpath, which can get expensive when many
files are involved, do a quick comparison of the basenames. */
if (! basenames_may_differ
&& FILENAME_CMP (name_basename, lbasename (pst->filename)) != 0)
continue;
if (compare_filenames_for_search (psymtab_to_fullname (pst), name))
{
if (partial_map_expand_apply (objfile, name, real_path,
pst, callback, data))
return 1;
continue;
}
/* If the user gave us an absolute path, try to find the file in
this symtab and use its absolute path. */
if (real_path != NULL)
{
gdb_assert (IS_ABSOLUTE_PATH (real_path));
gdb_assert (IS_ABSOLUTE_PATH (name));
if (filename_cmp (psymtab_to_fullname (pst), real_path) == 0)
{
if (partial_map_expand_apply (objfile, name, real_path,
pst, callback, data))
return 1;
continue;
}
}
}
return 0;
}
/* Find which partial symtab contains PC and SECTION starting at psymtab PST.
We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
static struct partial_symtab *
find_pc_sect_psymtab_closer (struct objfile *objfile,
CORE_ADDR pc, struct obj_section *section,
struct partial_symtab *pst,
struct bound_minimal_symbol msymbol)
{
struct partial_symtab *tpst;
struct partial_symtab *best_pst = pst;
CORE_ADDR best_addr = pst->textlow;
gdb_assert (!pst->psymtabs_addrmap_supported);
/* An objfile that has its functions reordered might have
many partial symbol tables containing the PC, but
we want the partial symbol table that contains the
function containing the PC. */
if (!(objfile->flags & OBJF_REORDERED)
&& section == NULL) /* Can't validate section this way. */
return pst;
if (msymbol.minsym == NULL)
return pst;
/* The code range of partial symtabs sometimes overlap, so, in
the loop below, we need to check all partial symtabs and
find the one that fits better for the given PC address. We
select the partial symtab that contains a symbol whose
address is closest to the PC address. By closest we mean
that find_pc_sect_symbol returns the symbol with address
that is closest and still less than the given PC. */
for (tpst = pst; tpst != NULL; tpst = tpst->next)
{
if (pc >= tpst->textlow && pc < tpst->texthigh)
{
struct partial_symbol *p;
CORE_ADDR this_addr;
/* NOTE: This assumes that every psymbol has a
corresponding msymbol, which is not necessarily
true; the debug info might be much richer than the
object's symbol table. */
p = find_pc_sect_psymbol (objfile, tpst, pc, section);
if (p != NULL
&& (SYMBOL_VALUE_ADDRESS (p)
== BMSYMBOL_VALUE_ADDRESS (msymbol)))
return tpst;
/* Also accept the textlow value of a psymtab as a
"symbol", to provide some support for partial
symbol tables with line information but no debug
symbols (e.g. those produced by an assembler). */
if (p != NULL)
this_addr = SYMBOL_VALUE_ADDRESS (p);
else
this_addr = tpst->textlow;
/* Check whether it is closer than our current
BEST_ADDR. Since this symbol address is
necessarily lower or equal to PC, the symbol closer
to PC is the symbol which address is the highest.
This way we return the psymtab which contains such
best match symbol. This can help in cases where the
symbol information/debuginfo is not complete, like
for instance on IRIX6 with gcc, where no debug info
is emitted for statics. (See also the nodebug.exp
testcase.) */
if (this_addr > best_addr)
{
best_addr = this_addr;
best_pst = tpst;
}
}
}
return best_pst;
}
/* Find which partial symtab contains PC and SECTION. Return NULL if
none. We return the psymtab that contains a symbol whose address
exactly matches PC, or, if we cannot find an exact match, the
psymtab that contains a symbol whose address is closest to PC. */
static struct partial_symtab *
find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
struct obj_section *section,
struct bound_minimal_symbol msymbol)
{
struct partial_symtab *pst;
/* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
than the later used TEXTLOW/TEXTHIGH one. */
if (objfile->psymtabs_addrmap != NULL)
{
pst = addrmap_find (objfile->psymtabs_addrmap, pc);
if (pst != NULL)
{
/* FIXME: addrmaps currently do not handle overlayed sections,
so fall back to the non-addrmap case if we're debugging
overlays and the addrmap returned the wrong section. */
if (overlay_debugging && msymbol.minsym != NULL && section != NULL)
{
struct partial_symbol *p;
/* NOTE: This assumes that every psymbol has a
corresponding msymbol, which is not necessarily
true; the debug info might be much richer than the
object's symbol table. */
p = find_pc_sect_psymbol (objfile, pst, pc, section);
if (p == NULL
|| (SYMBOL_VALUE_ADDRESS (p)
!= BMSYMBOL_VALUE_ADDRESS (msymbol)))
goto next;
}
/* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
PSYMTABS_ADDRMAP we used has already the best 1-byte
granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
overlap. */
return pst;
}
}
next:
/* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
which still have no corresponding full SYMTABs read. But it is not
present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
so far. */
/* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
debug info type in single OBJFILE. */
ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
if (!pst->psymtabs_addrmap_supported
&& pc >= pst->textlow && pc < pst->texthigh)
{
struct partial_symtab *best_pst;
best_pst = find_pc_sect_psymtab_closer (objfile, pc, section, pst,
msymbol);
if (best_pst != NULL)
return best_pst;
}
return NULL;
}
/* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
the definition of quick_symbol_functions in symfile.h. */
static struct compunit_symtab *
psym_find_pc_sect_compunit_symtab (struct objfile *objfile,
struct bound_minimal_symbol msymbol,
CORE_ADDR pc,
struct obj_section *section,
int warn_if_readin)
{
struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
msymbol);
if (ps != NULL)
{
if (warn_if_readin && ps->readin)
/* Might want to error() here (in case symtab is corrupt and
will cause a core dump), but maybe we can successfully
continue, so let's not. */
warning (_("\
(Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
paddress (get_objfile_arch (objfile), pc));
psymtab_to_symtab (objfile, ps);
return ps->compunit_symtab;
}
return NULL;
}
/* Find which partial symbol within a psymtab matches PC and SECTION.
Return NULL if none. */
static struct partial_symbol *
find_pc_sect_psymbol (struct objfile *objfile,
struct partial_symtab *psymtab, CORE_ADDR pc,
struct obj_section *section)
{
struct partial_symbol *best = NULL, *p, **pp;
CORE_ADDR best_pc;
gdb_assert (psymtab != NULL);
/* Cope with programs that start at address 0. */
best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
/* Search the global symbols as well as the static symbols, so that
find_pc_partial_function doesn't use a minimal symbol and thus
cache a bad endaddr. */
for (pp = objfile->global_psymbols.list + psymtab->globals_offset;
(pp - (objfile->global_psymbols.list + psymtab->globals_offset)
< psymtab->n_global_syms);
pp++)
{
p = *pp;
if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
&& PSYMBOL_CLASS (p) == LOC_BLOCK
&& pc >= SYMBOL_VALUE_ADDRESS (p)
&& (SYMBOL_VALUE_ADDRESS (p) > best_pc
|| (psymtab->textlow == 0
&& best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
{
if (section != NULL) /* Match on a specific section. */
{
fixup_psymbol_section (p, objfile);
if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile, p),
section))
continue;
}
best_pc = SYMBOL_VALUE_ADDRESS (p);
best = p;
}
}
for (pp = objfile->static_psymbols.list + psymtab->statics_offset;
(pp - (objfile->static_psymbols.list + psymtab->statics_offset)
< psymtab->n_static_syms);
pp++)
{
p = *pp;
if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
&& PSYMBOL_CLASS (p) == LOC_BLOCK
&& pc >= SYMBOL_VALUE_ADDRESS (p)
&& (SYMBOL_VALUE_ADDRESS (p) > best_pc
|| (psymtab->textlow == 0
&& best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
{
if (section != NULL) /* Match on a specific section. */
{
fixup_psymbol_section (p, objfile);
if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile, p),
section))
continue;
}
best_pc = SYMBOL_VALUE_ADDRESS (p);
best = p;
}
}
return best;
}
static void
fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
{
CORE_ADDR addr;
if (psym == NULL)
return;
if (SYMBOL_SECTION (psym) >= 0)
return;
gdb_assert (objfile);
switch (PSYMBOL_CLASS (psym))
{
case LOC_STATIC:
case LOC_LABEL:
case LOC_BLOCK:
addr = SYMBOL_VALUE_ADDRESS (psym);
break;
default:
/* Nothing else will be listed in the minsyms -- no use looking
it up. */
return;
}
fixup_section (&psym->ginfo, addr, objfile);
}
/* Psymtab version of lookup_symbol. See its definition in
the definition of quick_symbol_functions in symfile.h. */
static struct compunit_symtab *
psym_lookup_symbol (struct objfile *objfile,
int block_index, const char *name,
const domain_enum domain)
{
struct partial_symtab *ps;
const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
struct compunit_symtab *stab_best = NULL;
ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
{
if (!ps->readin && lookup_partial_symbol (objfile, ps, name,
psymtab_index, domain))
{
struct symbol *sym, *with_opaque = NULL;
struct compunit_symtab *stab = psymtab_to_symtab (objfile, ps);
/* Note: While psymtab_to_symtab can return NULL if the partial symtab
is empty, we can assume it won't here because lookup_partial_symbol
succeeded. */
const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
sym = block_find_symbol (block, name, domain,
block_find_non_opaque_type_preferred,
&with_opaque);
/* Some caution must be observed with overloaded functions
and methods, since the index will not contain any overload
information (but NAME might contain it). */
if (sym != NULL
&& strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
return stab;
if (with_opaque != NULL
&& strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque), name) == 0)
stab_best = stab;
/* Keep looking through other psymtabs. */
}
}
return stab_best;
}
/* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
the global block of PST if GLOBAL, and otherwise the static block.
MATCH is the comparison operation that returns true iff MATCH (s,
NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
non-null, the symbols in the block are assumed to be ordered
according to it (allowing binary search). It must be compatible
with MATCH. Returns the symbol, if found, and otherwise NULL. */
static struct partial_symbol *
match_partial_symbol (struct objfile *objfile,
struct partial_symtab *pst, int global,
const char *name, domain_enum domain,
symbol_compare_ftype *match,
symbol_compare_ftype *ordered_compare)
{
struct partial_symbol **start, **psym;
struct partial_symbol **top, **real_top, **bottom, **center;
int length = (global ? pst->n_global_syms : pst->n_static_syms);
int do_linear_search = 1;
if (length == 0)
return NULL;
start = (global ?
objfile->global_psymbols.list + pst->globals_offset :
objfile->static_psymbols.list + pst->statics_offset);
if (global && ordered_compare) /* Can use a binary search. */
{
do_linear_search = 0;
/* Binary search. This search is guaranteed to end with center
pointing at the earliest partial symbol whose name might be
correct. At that point *all* partial symbols with an
appropriate name will be checked against the correct
domain. */
bottom = start;
top = start + length - 1;
real_top = top;
while (top > bottom)
{
center = bottom + (top - bottom) / 2;
gdb_assert (center < top);
if (!do_linear_search
&& (SYMBOL_LANGUAGE (*center) == language_java))
do_linear_search = 1;
if (ordered_compare (SYMBOL_SEARCH_NAME (*center), name) >= 0)
top = center;
else
bottom = center + 1;
}
gdb_assert (top == bottom);
while (top <= real_top
&& match (SYMBOL_SEARCH_NAME (*top), name) == 0)
{
if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
SYMBOL_DOMAIN (*top), domain))
return *top;
top++;
}
}
/* Can't use a binary search or else we found during the binary search that
we should also do a linear search. */
if (do_linear_search)
{
for (psym = start; psym < start + length; psym++)
{
if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
SYMBOL_DOMAIN (*psym), domain)
&& match (SYMBOL_SEARCH_NAME (*psym), name) == 0)
return *psym;
}
}
return NULL;
}
/* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
not contain any method/function instance information (since this would
force reading type information while reading psymtabs). Therefore,
if NAME contains overload information, it must be stripped before searching
psymtabs.
The caller is responsible for freeing the return result. */
static char *
psymtab_search_name (const char *name)
{
switch (current_language->la_language)
{
case language_cplus:
case language_java:
{
if (strchr (name, '('))
{
char *ret = cp_remove_params (name);
if (ret)
return ret;
}
}
break;
default:
break;
}
return xstrdup (name);
}
/* Look, in partial_symtab PST, for symbol whose natural name is NAME.
Check the global symbols if GLOBAL, the static symbols if not. */
static struct partial_symbol *
lookup_partial_symbol (struct objfile *objfile,
struct partial_symtab *pst, const char *name,
int global, domain_enum domain)
{
struct partial_symbol **start, **psym;
struct partial_symbol **top, **real_top, **bottom, **center;
int length = (global ? pst->n_global_syms : pst->n_static_syms);
int do_linear_search = 1;
char *search_name;
struct cleanup *cleanup;
if (length == 0)
return NULL;
search_name = psymtab_search_name (name);
cleanup = make_cleanup (xfree, search_name);
start = (global ?
objfile->global_psymbols.list + pst->globals_offset :
objfile->static_psymbols.list + pst->statics_offset);
if (global) /* This means we can use a binary search. */
{
do_linear_search = 0;
/* Binary search. This search is guaranteed to end with center
pointing at the earliest partial symbol whose name might be
correct. At that point *all* partial symbols with an
appropriate name will be checked against the correct
domain. */
bottom = start;
top = start + length - 1;
real_top = top;
while (top > bottom)
{
center = bottom + (top - bottom) / 2;
if (!(center < top))
internal_error (__FILE__, __LINE__,
_("failed internal consistency check"));
if (!do_linear_search
&& SYMBOL_LANGUAGE (*center) == language_java)
{
do_linear_search = 1;
}
if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
search_name) >= 0)
{
top = center;
}
else
{
bottom = center + 1;
}
}
if (!(top == bottom))
internal_error (__FILE__, __LINE__,
_("failed internal consistency check"));
/* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
top--;
/* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
top++;
while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
{
if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
SYMBOL_DOMAIN (*top), domain))
{
do_cleanups (cleanup);
return *top;
}
top++;
}
}
/* Can't use a binary search or else we found during the binary search that
we should also do a linear search. */
if (do_linear_search)
{
for (psym = start; psym < start + length; psym++)
{
if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
SYMBOL_DOMAIN (*psym), domain)
&& SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name))
{
do_cleanups (cleanup);
return *psym;
}
}
}
do_cleanups (cleanup);
return NULL;
}
/* Get the symbol table that corresponds to a partial_symtab.
This is fast after the first time you do it.
The result will be NULL if the primary symtab has no symbols,
which can happen. Otherwise the result is the primary symtab
that contains PST. */
static struct compunit_symtab *
psymtab_to_symtab (struct objfile *objfile, struct partial_symtab *pst)
{
/* If it is a shared psymtab, find an unshared psymtab that includes
it. Any such psymtab will do. */
while (pst->user != NULL)
pst = pst->user;
/* If it's been looked up before, return it. */
if (pst->compunit_symtab)
return pst->compunit_symtab;
/* If it has not yet been read in, read it. */
if (!pst->readin)
{
struct cleanup *back_to = increment_reading_symtab ();
(*pst->read_symtab) (pst, objfile);
do_cleanups (back_to);
}
return pst->compunit_symtab;
}
/* Psymtab version of relocate. See its definition in
the definition of quick_symbol_functions in symfile.h. */
static void
psym_relocate (struct objfile *objfile,
const struct section_offsets *new_offsets,
const struct section_offsets *delta)
{
struct partial_symbol **psym;
struct partial_symtab *p;
ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
{
p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
}
for (psym = objfile->global_psymbols.list;
psym < objfile->global_psymbols.next;
psym++)
{
fixup_psymbol_section (*psym, objfile);
if (SYMBOL_SECTION (*psym) >= 0)
SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
SYMBOL_SECTION (*psym));
}
for (psym = objfile->static_psymbols.list;
psym < objfile->static_psymbols.next;
psym++)
{
fixup_psymbol_section (*psym, objfile);
if (SYMBOL_SECTION (*psym) >= 0)
SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
SYMBOL_SECTION (*psym));
}
}
/* Psymtab version of find_last_source_symtab. See its definition in
the definition of quick_symbol_functions in symfile.h. */
static struct symtab *
psym_find_last_source_symtab (struct objfile *ofp)
{
struct partial_symtab *ps;
struct partial_symtab *cs_pst = NULL;
ALL_OBJFILE_PSYMTABS_REQUIRED (ofp, ps)
{
const char *name = ps->filename;
int len = strlen (name);
if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
|| strcmp (name, "<<C++-namespaces>>") == 0)))
cs_pst = ps;
}
if (cs_pst)
{
if (cs_pst->readin)
{
internal_error (__FILE__, __LINE__,
_("select_source_symtab: "
"readin pst found and no symtabs."));
}
else
{
struct compunit_symtab *cust = psymtab_to_symtab (ofp, cs_pst);
if (cust == NULL)
return NULL;
return compunit_primary_filetab (cust);
}
}
return NULL;
}
/* Psymtab version of forget_cached_source_info. See its definition in
the definition of quick_symbol_functions in symfile.h. */
static void
psym_forget_cached_source_info (struct objfile *objfile)
{
struct partial_symtab *pst;
ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
{
if (pst->fullname != NULL)
{
xfree (pst->fullname);
pst->fullname = NULL;
}
}
}
static void
print_partial_symbols (struct gdbarch *gdbarch,
struct partial_symbol **p, int count, char *what,
struct ui_file *outfile)
{
fprintf_filtered (outfile, " %s partial symbols:\n", what);
while (count-- > 0)
{
QUIT;
fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
{
fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
}
fputs_filtered (", ", outfile);
switch (SYMBOL_DOMAIN (*p))
{
case UNDEF_DOMAIN:
fputs_filtered ("undefined domain, ", outfile);
break;
case VAR_DOMAIN:
/* This is the usual thing -- don't print it. */
break;
case STRUCT_DOMAIN:
fputs_filtered ("struct domain, ", outfile);
break;
case LABEL_DOMAIN:
fputs_filtered ("label domain, ", outfile);
break;
default:
fputs_filtered ("<invalid domain>, ", outfile);
break;
}
switch (PSYMBOL_CLASS (*p))
{
case LOC_UNDEF:
fputs_filtered ("undefined", outfile);
break;
case LOC_CONST:
fputs_filtered ("constant int", outfile);
break;
case LOC_STATIC:
fputs_filtered ("static", outfile);
break;
case LOC_REGISTER:
fputs_filtered ("register", outfile);
break;
case LOC_ARG:
fputs_filtered ("pass by value", outfile);
break;
case LOC_REF_ARG:
fputs_filtered ("pass by reference", outfile);
break;
case LOC_REGPARM_ADDR:
fputs_filtered ("register address parameter", outfile);
break;
case LOC_LOCAL:
fputs_filtered ("stack parameter", outfile);
break;
case LOC_TYPEDEF:
fputs_filtered ("type", outfile);
break;
case LOC_LABEL:
fputs_filtered ("label", outfile);
break;
case LOC_BLOCK:
fputs_filtered ("function", outfile);
break;
case LOC_CONST_BYTES:
fputs_filtered ("constant bytes", outfile);
break;
case LOC_UNRESOLVED:
fputs_filtered ("unresolved", outfile);
break;
case LOC_OPTIMIZED_OUT:
fputs_filtered ("optimized out", outfile);
break;
case LOC_COMPUTED:
fputs_filtered ("computed at runtime", outfile);
break;
default:
fputs_filtered ("<invalid location>", outfile);
break;
}
fputs_filtered (", ", outfile);
fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
fprintf_filtered (outfile, "\n");
p++;
}
}
static void
dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
struct ui_file *outfile)
{
struct gdbarch *gdbarch = get_objfile_arch (objfile);
int i;
if (psymtab->anonymous)
{
fprintf_filtered (outfile, "\nAnonymous partial symtab (%s) ",
psymtab->filename);
}
else
{
fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
psymtab->filename);
}
fprintf_filtered (outfile, "(object ");
gdb_print_host_address (psymtab, outfile);
fprintf_filtered (outfile, ")\n\n");