-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbxread.c
4589 lines (3872 loc) · 124 KB
/
dbxread.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
/* Read dbx symbol tables and convert to internal format, for GDB.
Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
GDB is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY. No author or distributor accepts responsibility to anyone
for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing.
Refer to the GDB General Public License for full details.
Everyone is granted permission to copy, modify and redistribute GDB,
but only under the conditions described in the GDB General Public
License. A copy of this license is supposed to have been given to you
along with GDB so you can know your rights and responsibilities. It
should be in a file named COPYING. Among other things, the copyright
notice and this notice must be preserved on all copies.
In other words, go ahead and share GDB, but don't try to stop
anyone else from sharing it farther. Help stamp out software hoarding!
*/
#include "param.h"
#ifdef READ_DBX_FORMAT
#ifdef USG
#include <sys/types.h>
#include <sys/fcntl.h>
#define L_SET 0
#define L_INCR 1
#endif
#ifdef COFF_ENCAPSULATE
#include "a.out.encap.h"
#include "stab.gnu.h"
#else
#include <a.out.h>
#include <stab.h>
#endif
/*
* Define specifically gnu symbols here.
*/
/* The following type indicates the definition of a symbol as being
an indirect reference to another symbol. The other symbol
appears as an undefined reference, immediately following this symbol.
Indirection is asymmetrical. The other symbol's value will be used
to satisfy requests for the indirect symbol, but not vice versa.
If the other symbol does not have a definition, libraries will
be searched to find a definition. */
#ifndef N_INDR
#define N_INDR 0xa
#endif
/* The following symbols refer to set elements.
All the N_SET[ATDB] symbols with the same name form one set.
Space is allocated for the set in the text section, and each set
element's value is stored into one word of the space.
The first word of the space is the length of the set (number of elements).
The address of the set is made into an N_SETV symbol
whose name is the same as the name of the set.
This symbol acts like a N_DATA global symbol
in that it can satisfy undefined external references. */
#ifndef N_SETA
#define N_SETA 0x14 /* Absolute set element symbol */
#endif /* This is input to LD, in a .o file. */
#ifndef N_SETT
#define N_SETT 0x16 /* Text set element symbol */
#endif /* This is input to LD, in a .o file. */
#ifndef N_SETD
#define N_SETD 0x18 /* Data set element symbol */
#endif /* This is input to LD, in a .o file. */
#ifndef N_SETB
#define N_SETB 0x1A /* Bss set element symbol */
#endif /* This is input to LD, in a .o file. */
/* Macros dealing with the set element symbols defined in a.out.h */
#define SET_ELEMENT_P(x) ((x)>=N_SETA&&(x)<=(N_SETB|N_EXT))
#define TYPE_OF_SET_ELEMENT(x) ((x)-N_SETA+N_ABS)
#ifndef N_SETV
#define N_SETV 0x1C /* Pointer to set vector in data area. */
#endif /* This is output from LD. */
#ifndef N_WARNING
#define N_WARNING 0x1E /* Warning message to print if file included */
#endif /* This is input to ld */
#ifndef __GNU_STAB__
/* Line number for the data section. This is to be used to describe
the source location of a variable declaration. */
#ifndef N_DSLINE
#define N_DSLINE (N_SLINE+N_DATA-N_TEXT)
#endif
/* Line number for the bss section. This is to be used to describe
the source location of a variable declaration. */
#ifndef N_BSLINE
#define N_BSLINE (N_SLINE+N_BSS-N_TEXT)
#endif
#endif /* not __GNU_STAB__ */
#include <stdio.h>
#include <obstack.h>
#include <sys/param.h>
#include <sys/file.h>
#include <sys/stat.h>
#include "defs.h"
#include "symtab.h"
#ifndef COFF_FORMAT
#define AOUTHDR struct exec
#endif
static void add_symbol_to_list ();
static void read_dbx_symtab ();
static void process_one_symbol ();
static void free_all_psymbols ();
static struct type *read_type ();
static struct type *read_range_type ();
static struct type *read_enum_type ();
static struct type *read_struct_type ();
static struct type *read_array_type ();
static long read_number ();
static void finish_block ();
static struct blockvector *make_blockvector ();
static struct symbol *define_symbol ();
static void start_subfile ();
static int hashname ();
static void hash_symsegs ();
extern struct symtab *read_symsegs ();
extern void free_all_symtabs ();
extern void free_all_psymtabs ();
extern void free_inclink_symtabs ();
/* C++ */
static struct type **read_args ();
/* Macro to determine which symbols to ignore when reading the first symbol
of a file. Some machines override this definition. */
#ifdef N_NSYMS
#ifndef IGNORE_SYMBOL
/* This code is used on Ultrix systems. Ignore it */
#define IGNORE_SYMBOL(type) (type == N_NSYMS)
#endif
#else
#ifndef IGNORE_SYMBOL
/* Don't ignore any symbols. */
#define IGNORE_SYMBOL(type) (0)
#endif
#endif /* not N_NSYMS */
/* Macro for number of symbol table entries (in usual a.out format).
Some machines override this definition. */
#ifndef NUMBER_OF_SYMBOLS
#ifdef COFF_HEADER
#define NUMBER_OF_SYMBOLS \
((COFF_HEADER(hdr) ? hdr.coffhdr.filehdr.f_nsyms : hdr.a_syms) / \
sizeof (struct nlist))
#else
#define NUMBER_OF_SYMBOLS (hdr.a_syms / sizeof (struct nlist))
#endif
#endif
/* Macro for file-offset of symbol table (in usual a.out format). */
#ifndef SYMBOL_TABLE_OFFSET
#define SYMBOL_TABLE_OFFSET N_SYMOFF (hdr)
#endif
/* Macro for file-offset of string table (in usual a.out format). */
#ifndef STRING_TABLE_OFFSET
#define STRING_TABLE_OFFSET (N_SYMOFF (hdr) + hdr.a_syms)
#endif
/* Macro to store the length of the string table data in INTO. */
#ifndef READ_STRING_TABLE_SIZE
#define READ_STRING_TABLE_SIZE(INTO) \
{ val = myread (desc, &INTO, sizeof INTO); \
if (val < 0) perror_with_name (name); }
#endif
/* Macro to declare variables to hold the file's header data. */
#ifndef DECLARE_FILE_HEADERS
#define DECLARE_FILE_HEADERS AOUTHDR hdr
#endif
/* Macro to read the header data from descriptor DESC and validate it.
NAME is the file name, for error messages. */
#ifndef READ_FILE_HEADERS
#ifdef HEADER_SEEK_FD
#define READ_FILE_HEADERS(DESC, NAME) \
{ HEADER_SEEK_FD (DESC); \
val = myread (DESC, &hdr, sizeof hdr); \
if (val < 0) perror_with_name (NAME); \
if (N_BADMAG (hdr)) \
error ("File \"%s\" not in POS 5 executable format.", NAME); }
#else
#define READ_FILE_HEADERS(DESC, NAME) \
{ val = myread (DESC, &hdr, sizeof hdr); \
if (val < 0) perror_with_name (NAME); \
if (N_BADMAG (hdr)) \
error ("File \"%s\" not in POS 6 executable format.", NAME); }
#endif
#endif
/* Macro for size of text segment */
#ifndef SIZE_OF_TEXT_SEGMENT
#define SIZE_OF_TEXT_SEGMENT hdr.a_text
#endif
/* Macro for name of symbol to indicate a file compiled with gcc. */
#ifndef GCC_COMPILED_FLAG_SYMBOL
#define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
#endif
/* Chain of symtabs made from reading the file's symsegs.
These symtabs do not go into symtab_list themselves,
but the information is copied from them when appropriate
to make the symtabs that will exist permanently. */
static struct symtab *symseg_chain;
/* Symseg symbol table for the file whose data we are now processing.
It is one of those in symseg_chain. Or 0, for a compilation that
has no symseg. */
static struct symtab *current_symseg;
/* Name of source file whose symbol data we are now processing.
This comes from a symbol of type N_SO. */
static char *last_source_file;
/* Core address of start of text of current source file.
This too comes from the N_SO symbol. */
static CORE_ADDR last_source_start_addr;
/* End of the text segment of the executable file,
as found in the symbol _etext. */
static CORE_ADDR end_of_text_addr;
/* The list of sub-source-files within the current individual compilation.
Each file gets its own symtab with its own linetable and associated info,
but they all share one blockvector. */
struct subfile
{
struct subfile *next;
char *name;
struct linetable *line_vector;
int line_vector_length;
int line_vector_index;
int prev_line_number;
};
static struct subfile *subfiles;
static struct subfile *current_subfile;
/* Count symbols as they are processed, for error messages. */
static int symnum;
/* Vector of types defined so far, indexed by their dbx type numbers.
(In newer sun systems, dbx uses a pair of numbers in parens,
as in "(SUBFILENUM,NUMWITHINSUBFILE)". Then these numbers must be
translated through the type_translations hash table to get
the index into the type vector.) */
static struct typevector *type_vector;
/* Number of elements allocated for type_vector currently. */
static int type_vector_length;
/* Vector of line number information. */
static struct linetable *line_vector;
/* Index of next entry to go in line_vector_index. */
static int line_vector_index;
/* Last line number recorded in the line vector. */
static int prev_line_number;
/* Number of elements allocated for line_vector currently. */
static int line_vector_length;
/* Hash table of global symbols whose values are not known yet.
They are chained thru the SYMBOL_VALUE, since we don't
have the correct data for that slot yet. */
#define HASHSIZE 127
static struct symbol *global_sym_chain[HASHSIZE];
/* Record the symbols defined for each context in a list.
We don't create a struct block for the context until we
know how long to make it. */
#define PENDINGSIZE 100
struct pending
{
struct pending *next;
int nsyms;
struct symbol *symbol[PENDINGSIZE];
};
/* List of free `struct pending' structures for reuse. */
struct pending *free_pendings;
/* Here are the three lists that symbols are put on. */
struct pending *file_symbols; /* static at top level, and types */
struct pending *global_symbols; /* global functions and variables */
struct pending *local_symbols; /* everything local to lexical context */
/* Stack representing unclosed lexical contexts
(that will become blocks, eventually). */
struct context_stack
{
struct pending *locals;
struct pending_block *old_blocks;
struct symbol *name;
CORE_ADDR start_addr;
int depth;
};
struct context_stack *context_stack;
/* Index of first unused entry in context stack. */
int context_stack_depth;
/* Currently allocated size of context stack. */
int context_stack_size;
/* Nonzero if within a function (so symbols should be local,
if nothing says specifically). */
int within_function;
/* List of blocks already made (lexical contexts already closed).
This is used at the end to make the blockvector. */
struct pending_block
{
struct pending_block *next;
struct block *block;
};
struct pending_block *pending_blocks;
extern CORE_ADDR first_object_file_end; /* From blockframe.c */
/* File name symbols were loaded from. */
static char *symfile;
/* Low and high symbol values (inclusive) for the global variable
entries in the symbol file. */
static int first_global_sym, last_global_sym;
/* Partial symbol list for all of the global and static symbols found
in a file */
struct partial_symbol *global_psymbols, *static_psymbols;
int global_psymbols_allocated, static_psymbols_allocated;
/* Position for next psymbol to be added */
struct partial_symbol *next_ps_global, *next_ps_static;
/* Global variable which, when set, indicates that we are processing a
.o file compiled with gcc */
static unsigned char processing_gcc_compilation;
static int
xxmalloc (n)
{
int v = malloc (n);
if (v == 0)
abort ();
return v;
}
/* Make a copy of the string at PTR with SIZE characters in the symbol obstack
(and add a null character at the end in the copy).
Returns the address of the copy. */
static char *
obsavestring (ptr, size)
char *ptr;
int size;
{
register char *p = (char *) obstack_alloc (symbol_obstack, size + 1);
/* Open-coded bcopy--saves function call time.
These strings are usually short. */
{
register char *p1 = ptr;
register char *p2 = p;
char *end = ptr + size;
while (p1 != end)
*p2++ = *p1++;
}
p[size] = 0;
return p;
}
/* Concatenate strings S1, S2 and S3; return the new string.
Space is found in the symbol_obstack. */
static char *
obconcat (s1, s2, s3)
char *s1, *s2, *s3;
{
register int len = strlen (s1) + strlen (s2) + strlen (s3) + 1;
register char *val = (char *) obstack_alloc (symbol_obstack, len);
strcpy (val, s1);
strcat (val, s2);
strcat (val, s3);
return val;
}
/* Support for Sun changes to dbx symbol format */
/* For each identified header file, we have a table of types defined
in that header file.
header_files maps header file names to their type tables.
It is a vector of n_header_files elements.
Each element describes one header file.
It contains a vector of types.
Sometimes it can happen that the same header file produces
different results when included in different places.
This can result from conditionals or from different
things done before including the file.
When this happens, there are multiple entries for the file in this table,
one entry for each distinct set of results.
The entries are distinguished by the INSTANCE field.
The INSTANCE field appears in the N_BINCL and N_EXCL symbol table and is
used to match header-file references to their corresponding data. */
struct header_file
{
char *name; /* Name of header file */
int instance; /* Numeric code distinguishing instances
of one header file that produced
different results when included.
It comes from the N_BINCL or N_EXCL. */
struct type **vector; /* Pointer to vector of types */
int length; /* Allocated length (# elts) of that vector */
};
static struct header_file *header_files;
static int n_header_files;
static int n_allocated_header_files;
/* During initial symbol readin, we need to have a structure to keep
track of which psymtabs have which bincls in them. This structure
is used during readin to setup the list of dependencies within each
partial symbol table. */
struct header_file_location
{
char *name; /* Name of header file */
int instance; /* See above */
struct partial_symtab *pst; /* Partial symtab that has the
BINCL/EINCL defs for this file */
};
/* The actual list and controling variables */
static struct header_file_location *bincl_list, *next_bincl;
static int bincls_allocated;
/* Within each object file, various header files are assigned numbers.
A type is defined or referred to with a pair of numbers
(FILENUM,TYPENUM) where FILENUM is the number of the header file
and TYPENUM is the number within that header file.
TYPENUM is the index within the vector of types for that header file.
FILENUM == 1 is special; it refers to the main source of the object file,
and not to any header file. FILENUM != 1 is interpreted by looking it up
in the following table, which contains indices in header_files. */
static int *this_object_header_files;
static int n_this_object_header_files;
static int n_allocated_this_object_header_files;
/* When a header file is getting special overriding definitions
for one source file, record here the header_files index
of its normal definition vector.
At other times, this is -1. */
static int header_file_prev_index;
/* At the start of reading dbx symbols, allocate our tables. */
static void
init_header_files ()
{
n_allocated_header_files = 10;
header_files = (struct header_file *) xxmalloc (10 * sizeof (struct header_file));
n_header_files = 0;
n_allocated_this_object_header_files = 10;
this_object_header_files = (int *) xxmalloc (10 * sizeof (int));
}
/* At the end of reading dbx symbols, free our tables. */
static void
free_header_files ()
{
register int i;
for (i = 0; i < n_header_files; i++)
free (header_files[i].name);
if (header_files) free (header_files);
if (this_object_header_files)
free (this_object_header_files);
}
/* Called at the start of each object file's symbols.
Clear out the mapping of header file numbers to header files. */
static void
new_object_header_files ()
{
/* Leave FILENUM of 0 free for builtin types and this file's types. */
n_this_object_header_files = 1;
header_file_prev_index = -1;
}
/* Add header file number I for this object file
at the next successive FILENUM. */
static void
add_this_object_header_file (i)
int i;
{
if (n_this_object_header_files == n_allocated_this_object_header_files)
{
n_allocated_this_object_header_files *= 2;
this_object_header_files
= (int *) xrealloc (this_object_header_files,
n_allocated_this_object_header_files * sizeof (int));
}
this_object_header_files[n_this_object_header_files++] = i;
}
/* Add to this file an "old" header file, one already seen in
a previous object file. NAME is the header file's name.
INSTANCE is its instance code, to select among multiple
symbol tables for the same header file. */
static void
add_old_header_file (name, instance)
char *name;
int instance;
{
register struct header_file *p = header_files;
register int i;
for (i = 0; i < n_header_files; i++)
if (!strcmp (p[i].name, name) && instance == p[i].instance)
{
add_this_object_header_file (i);
return;
}
error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
symnum);
}
/* Add to this file a "new" header file: definitions for its types follow.
NAME is the header file's name.
Most often this happens only once for each distinct header file,
but not necessarily. If it happens more than once, INSTANCE has
a different value each time, and references to the header file
use INSTANCE values to select among them.
dbx output contains "begin" and "end" markers for each new header file,
but at this level we just need to know which files there have been;
so we record the file when its "begin" is seen and ignore the "end". */
static void
add_new_header_file (name, instance)
char *name;
int instance;
{
register int i;
register struct header_file *p = header_files;
header_file_prev_index = -1;
#if 0
/* This code was used before I knew about the instance codes.
My first hypothesis is that it is not necessary now
that instance codes are handled. */
/* Has this header file a previous definition?
If so, make a new entry anyway so that this use in this source file
gets a separate entry. Later source files get the old entry.
Record here the index of the old entry, so that any type indices
not previously defined can get defined in the old entry as
well as in the new one. */
for (i = 0; i < n_header_files; i++)
if (!strcmp (p[i].name, name))
{
header_file_prev_index = i;
}
#endif
/* Make sure there is room for one more header file. */
if (n_header_files == n_allocated_header_files)
{
n_allocated_header_files *= 2;
header_files = (struct header_file *)
xrealloc (header_files,
(n_allocated_header_files
* sizeof (struct header_file)));
}
/* Create an entry for this header file. */
i = n_header_files++;
header_files[i].name = savestring (name, strlen(name));
header_files[i].instance = instance;
header_files[i].length = 10;
header_files[i].vector
= (struct type **) xxmalloc (10 * sizeof (struct type *));
bzero (header_files[i].vector, 10 * sizeof (struct type *));
add_this_object_header_file (i);
}
/* Look up a dbx type-number pair. Return the address of the slot
where the type for that number-pair is stored.
The number-pair is in TYPENUMS.
This can be used for finding the type associated with that pair
or for associating a new type with the pair. */
static struct type **
dbx_lookup_type (typenums)
int typenums[2];
{
register int filenum = typenums[0], index = typenums[1];
if (filenum < 0 || filenum >= n_this_object_header_files)
error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
filenum, index, symnum);
if (filenum == 0)
{
/* Type is defined outside of header files.
Find it in this object file's type vector. */
if (index >= type_vector_length)
{
type_vector_length *= 2;
type_vector = (struct typevector *)
xrealloc (type_vector,
(sizeof (struct typevector)
+ type_vector_length * sizeof (struct type *)));
bzero (&type_vector->type[type_vector_length / 2],
type_vector_length * sizeof (struct type *) / 2);
}
return &type_vector->type[index];
}
else
{
register int real_filenum = this_object_header_files[filenum];
register struct header_file *f;
if (real_filenum >= n_header_files)
abort ();
f = &header_files[real_filenum];
if (index >= f->length)
{
f->length *= 2;
f->vector = (struct type **)
xrealloc (f->vector, f->length * sizeof (struct type *));
bzero (&f->vector[f->length / 2],
f->length * sizeof (struct type *) / 2);
}
return &f->vector[index];
}
}
/* Make sure there is a type allocated for type numbers TYPENUMS
and return the type object.
This can create an empty (zeroed) type object. */
static struct type *
dbx_alloc_type (typenums)
int typenums[2];
{
register struct type **type_addr = dbx_lookup_type (typenums);
register struct type *type = *type_addr;
/* If we are referring to a type not known at all yet,
allocate an empty type for it.
We will fill it in later if we find out how. */
if (type == 0)
{
type = (struct type *) obstack_alloc (symbol_obstack,
sizeof (struct type));
bzero (type, sizeof (struct type));
TYPE_VPTR_FIELDNO (type) = -1;
*type_addr = type;
}
return type;
}
#if 0
static struct type **
explicit_lookup_type (real_filenum, index)
int real_filenum, index;
{
register struct header_file *f = &header_files[real_filenum];
if (index >= f->length)
{
f->length *= 2;
f->vector = (struct type **)
xrealloc (f->vector, f->length * sizeof (struct type *));
bzero (&f->vector[f->length / 2],
f->length * sizeof (struct type *) / 2);
}
return &f->vector[index];
}
#endif
/* maintain the lists of symbols and blocks */
/* Add a symbol to one of the lists of symbols. */
static void
add_symbol_to_list (symbol, listhead)
struct symbol *symbol;
struct pending **listhead;
{
/* We keep PENDINGSIZE symbols in each link of the list.
If we don't have a link with room in it, add a new link. */
if (*listhead == 0 || (*listhead)->nsyms == PENDINGSIZE)
{
register struct pending *link;
if (free_pendings)
{
link = free_pendings;
free_pendings = link->next;
}
else
link = (struct pending *) xxmalloc (sizeof (struct pending));
link->next = *listhead;
*listhead = link;
link->nsyms = 0;
}
(*listhead)->symbol[(*listhead)->nsyms++] = symbol;
}
/* At end of reading syms, or in case of quit,
really free as many `struct pending's as we can easily find. */
static void
really_free_pendings ()
{
struct pending *next, *next1;
struct pending_block *bnext, *bnext1;
for (next = free_pendings; next; next = next1)
{
next1 = next->next;
free (next);
}
free_pendings = 0;
for (bnext = pending_blocks; bnext; bnext = bnext1)
{
bnext1 = bnext->next;
free (bnext);
}
pending_blocks = 0;
for (next = file_symbols; next; next = next1)
{
next1 = next->next;
free (next);
}
for (next = global_symbols; next; next = next1)
{
next1 = next->next;
free (next);
}
}
/* Take one of the lists of symbols and make a block from it.
Keep the order the symbols have in the list (reversed from the input file).
Put the block on the list of pending blocks. */
static void
finish_block (symbol, listhead, old_blocks, start, end)
struct symbol *symbol;
struct pending **listhead;
struct pending_block *old_blocks;
CORE_ADDR start, end;
{
register struct pending *next, *next1;
register struct block *block;
register struct pending_block *pblock;
struct pending_block *opblock;
register int i;
/* Count the length of the list of symbols. */
for (next = *listhead, i = 0; next; i += next->nsyms, next = next->next);
block = (struct block *) obstack_alloc (symbol_obstack,
(sizeof (struct block)
+ ((i - 1)
* sizeof (struct symbol *))));
/* Copy the symbols into the block. */
BLOCK_NSYMS (block) = i;
for (next = *listhead; next; next = next->next)
{
register int j;
for (j = next->nsyms - 1; j >= 0; j--)
BLOCK_SYM (block, --i) = next->symbol[j];
}
BLOCK_START (block) = start;
BLOCK_END (block) = end;
BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */
BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
/* Put the block in as the value of the symbol that names it. */
if (symbol)
{
SYMBOL_BLOCK_VALUE (symbol) = block;
BLOCK_FUNCTION (block) = symbol;
}
else
BLOCK_FUNCTION (block) = 0;
/* Now "free" the links of the list, and empty the list. */
for (next = *listhead; next; next = next1)
{
next1 = next->next;
next->next = free_pendings;
free_pendings = next;
}
*listhead = 0;
/* Install this block as the superblock
of all blocks made since the start of this scope
that don't have superblocks yet. */
opblock = 0;
for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
{
if (BLOCK_SUPERBLOCK (pblock->block) == 0)
BLOCK_SUPERBLOCK (pblock->block) = block;
opblock = pblock;
}
/* Record this block on the list of all blocks in the file.
Put it after opblock, or at the beginning if opblock is 0.
This puts the block in the list after all its subblocks. */
/* Allocate in the symbol_obstack to save time.
It wastes a little space. */
pblock = (struct pending_block *)
obstack_alloc (symbol_obstack,
sizeof (struct pending_block));
pblock->block = block;
if (opblock)
{
pblock->next = opblock->next;
opblock->next = pblock;
}
else
{
pblock->next = pending_blocks;
pending_blocks = pblock;
}
}
static struct blockvector *
make_blockvector ()
{
register struct pending_block *next, *next1;
register struct blockvector *blockvector;
register int i;
/* Count the length of the list of blocks. */
for (next = pending_blocks, i = 0; next; next = next->next, i++);
blockvector = (struct blockvector *)
obstack_alloc (symbol_obstack,
(sizeof (struct blockvector)
+ (i - 1) * sizeof (struct block *)));
/* Copy the blocks into the blockvector.
This is done in reverse order, which happens to put
the blocks into the proper order (ascending starting address).
finish_block has hair to insert each block into the list
after its subblocks in order to make sure this is true. */
BLOCKVECTOR_NBLOCKS (blockvector) = i;
for (next = pending_blocks; next; next = next->next)
BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
#if 0 /* Now we make the links in the obstack, so don't free them. */
/* Now free the links of the list, and empty the list. */
for (next = pending_blocks; next; next = next1)
{
next1 = next->next;
free (next);
}
#endif
pending_blocks = 0;
return blockvector;
}
/* Manage the vector of line numbers. */
static void
record_line (line, pc)
int line;
CORE_ADDR pc;
{
struct linetable_entry *e;
/* Ignore the dummy line number in libg.o */
if (line == 0xffff)
return;
/* Make sure line vector is big enough. */
if (line_vector_index + 1 >= line_vector_length)
{
line_vector_length *= 2;
line_vector = (struct linetable *)
xrealloc (line_vector,
(sizeof (struct linetable)
+ line_vector_length * sizeof (struct linetable_entry)));
current_subfile->line_vector = line_vector;
}
e = line_vector->item + line_vector_index++;
e->line = line; e->pc = pc;
}
/* Start a new symtab for a new source file.
This is called when a dbx symbol of type N_SO is seen;
it indicates the start of data for one original source file. */
static void
start_symtab (name, start_addr)
char *name;
CORE_ADDR start_addr;
{
register struct symtab *s;