Commit | Line | Data |
---|---|---|
1340861c KH |
1 | /* Read os9/os9k symbol tables and convert to internal format, for GDB. |
2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993 | |
3 | Free Software Foundation, Inc. | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | /* This module provides three functions: os9k_symfile_init, | |
22 | which initializes to read a symbol file; os9k_new_init, which | |
23 | discards existing cached information when all symbols are being | |
24 | discarded; and os9k_symfile_read, which reads a symbol table | |
25 | from a file. | |
26 | ||
27 | os9k_symfile_read only does the minimum work necessary for letting the | |
28 | user "name" things symbolically; it does not read the entire symtab. | |
29 | Instead, it reads the external and static symbols and puts them in partial | |
30 | symbol tables. When more extensive information is requested of a | |
31 | file, the corresponding partial symbol table is mutated into a full | |
32 | fledged symbol table by going back and reading the symbols | |
33 | for real. os9k_psymtab_to_symtab() is the function that does this */ | |
34 | ||
35 | #include "defs.h" | |
36 | #include <string.h> | |
37 | #include <stdio.h> | |
38 | ||
39 | #if defined(USG) || defined(__CYGNUSCLIB__) | |
40 | #include <sys/types.h> | |
41 | #include <fcntl.h> | |
42 | #endif | |
43 | ||
44 | #include <obstack.h> | |
45 | #include <sys/param.h> | |
46 | #ifndef NO_SYS_FILE | |
47 | #include <sys/file.h> | |
48 | #endif | |
49 | #include <sys/stat.h> | |
50 | #include <ctype.h> | |
51 | #include "symtab.h" | |
52 | #include "breakpoint.h" | |
53 | #include "command.h" | |
54 | #include "target.h" | |
55 | #include "gdbcore.h" /* for bfd stuff */ | |
56 | #include "libbfd.h" /* FIXME Secret internal BFD stuff (bfd_read) */ | |
57 | #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */ | |
58 | #include "symfile.h" | |
59 | #include "objfiles.h" | |
60 | #include "buildsym.h" | |
61 | #include "gdb-stabs.h" | |
62 | #include "demangle.h" | |
63 | #include "language.h" /* Needed inside partial-stab.h */ | |
64 | #include "complaints.h" | |
65 | #include "os9k.h" | |
66 | ||
67 | #if !defined (SEEK_SET) | |
68 | #define SEEK_SET 0 | |
69 | #define SEEK_CUR 1 | |
70 | #endif | |
71 | ||
72 | /* Each partial symbol table entry contains a pointer to private data for the | |
73 | read_symtab() function to use when expanding a partial symbol table entry | |
74 | to a full symbol table entry. | |
75 | ||
76 | For dbxread this structure contains the offset within the file symbol table | |
77 | of first local symbol for this file, and count of the section | |
78 | of the symbol table devoted to this file's symbols (actually, the section | |
79 | bracketed may contain more than just this file's symbols). It also contains | |
80 | further information needed to locate the symbols if they are in an ELF file. | |
81 | ||
82 | If ldsymcnt is 0, the only reason for this thing's existence is the | |
83 | dependency list. Nothing else will happen when it is read in. */ | |
84 | ||
85 | #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff) | |
86 | #define LDSYMCNT(p) (((struct symloc *)((p)->read_symtab_private))->ldsymnum) | |
87 | ||
88 | struct symloc { | |
89 | int ldsymoff; | |
90 | int ldsymnum; | |
91 | }; | |
92 | ||
93 | /* Remember what we deduced to be the source language of this psymtab. */ | |
94 | static enum language psymtab_language = language_unknown; | |
95 | ||
96 | /* keep partial symbol table file nested depth */ | |
97 | static int psymfile_depth = 0; | |
98 | ||
99 | /* keep symbol table file nested depth */ | |
100 | static int symfile_depth = 0; | |
101 | ||
102 | /* Nonzero means give verbose info on gdb action. From main.c. */ | |
103 | extern int info_verbose; | |
104 | ||
105 | extern int previous_stab_code; | |
106 | ||
107 | /* The BFD for this file -- implicit parameter to next_symbol_text. */ | |
108 | static bfd *symfile_bfd; | |
109 | ||
110 | /* Name of last function encountered. Used in Solaris to approximate | |
111 | object file boundaries. */ | |
112 | static char *last_function_name; | |
113 | ||
114 | /* Complaints about the symbols we have encountered. */ | |
115 | extern struct complaint lbrac_complaint; | |
116 | ||
117 | extern struct complaint unknown_symtype_complaint; | |
118 | ||
119 | extern struct complaint unknown_symchar_complaint; | |
120 | ||
121 | extern struct complaint lbrac_rbrac_complaint; | |
122 | ||
123 | extern struct complaint repeated_header_complaint; | |
124 | ||
125 | extern struct complaint repeated_header_name_complaint; | |
126 | ||
127 | static struct complaint lbrac_unmatched_complaint = | |
128 | {"unmatched Increment Block Entry before symtab pos %d", 0, 0}; | |
129 | ||
130 | static struct complaint lbrac_mismatch_complaint = | |
131 | {"IBE/IDE symbol mismatch at symtab pos %d", 0, 0}; | |
132 | ||
133 | extern struct symbol * | |
134 | os9k_define_symbol PARAMS ((CORE_ADDR, char *, int, int, struct objfile *)); | |
135 | ||
136 | \f | |
137 | /* Local function prototypes */ | |
138 | static void | |
139 | os9k_read_ofile_symtab PARAMS ((struct partial_symtab *)); | |
140 | ||
141 | static void | |
142 | os9k_psymtab_to_symtab PARAMS ((struct partial_symtab *)); | |
143 | ||
144 | static void | |
145 | os9k_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *)); | |
146 | ||
147 | static void | |
148 | read_os9k_psymtab PARAMS ((struct section_offsets *, struct objfile *, | |
149 | CORE_ADDR, int)); | |
150 | ||
151 | static void | |
152 | init_psymbol_list PARAMS ((struct objfile *)); | |
153 | ||
154 | static char * | |
155 | os9k_next_symbol_text PARAMS ((void)); | |
156 | ||
157 | static int | |
158 | fill_sym PARAMS ((FILE *, bfd *)); | |
159 | ||
160 | static void | |
161 | os9k_symfile_init PARAMS ((struct objfile *)); | |
162 | ||
163 | static void | |
164 | os9k_new_init PARAMS ((struct objfile *)); | |
165 | ||
166 | static void | |
167 | os9k_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int)); | |
168 | ||
169 | static void | |
170 | os9k_symfile_finish PARAMS ((struct objfile *)); | |
171 | ||
172 | static void | |
173 | os9k_process_one_symbol PARAMS ((int, int, CORE_ADDR, char *, | |
174 | struct section_offsets *, struct objfile *)); | |
175 | ||
176 | static struct partial_symtab * | |
177 | os9k_start_psymtab PARAMS ((struct objfile *, struct section_offsets *, char *, | |
178 | CORE_ADDR, int, int, struct partial_symbol *, | |
179 | struct partial_symbol *)); | |
180 | ||
181 | static struct partial_symtab * | |
182 | os9k_end_psymtab PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR, | |
183 | struct partial_symtab **, int)); | |
184 | ||
185 | static void | |
186 | record_minimal_symbol PARAMS ((char *, CORE_ADDR, int, struct objfile *)); | |
187 | \f | |
188 | #define HANDLE_RBRAC(val) \ | |
189 | if ((val) > pst->texthigh) pst->texthigh = (val); | |
190 | ||
191 | #define SWAP_STBHDR(hdrp, abfd) \ | |
192 | { \ | |
193 | (hdrp)->fmtno = bfd_get_16(abfd, (unsigned char *)&(hdrp)->fmtno); \ | |
194 | (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \ | |
195 | (hdrp)->offset = bfd_get_32(abfd, (unsigned char *)&(hdrp)->offset); \ | |
196 | (hdrp)->nsym = bfd_get_32(abfd, (unsigned char *)&(hdrp)->nsym); \ | |
197 | } | |
198 | #define SWAP_STBSYM(symp, abfd) \ | |
199 | { \ | |
200 | (symp)->value = bfd_get_32(abfd, (unsigned char *)&(symp)->value); \ | |
201 | (symp)->type = bfd_get_16(abfd, (unsigned char *)&(symp)->type); \ | |
202 | (symp)->stroff = bfd_get_32(abfd, (unsigned char *)&(symp)->stroff); \ | |
203 | } | |
204 | #define N_DATA 0 | |
205 | #define N_BSS 1 | |
206 | #define N_RDATA 2 | |
207 | #define N_IDATA 3 | |
208 | #define N_TEXT 4 | |
209 | #define N_ABS 6 | |
210 | ||
211 | static void | |
212 | record_minimal_symbol (name, address, type, objfile) | |
213 | char *name; | |
214 | CORE_ADDR address; | |
215 | int type; | |
216 | struct objfile *objfile; | |
217 | { | |
218 | enum minimal_symbol_type ms_type; | |
219 | ||
220 | switch (type) | |
221 | { | |
222 | case N_TEXT: ms_type = mst_text; break; | |
223 | case N_DATA: ms_type = mst_data; break; | |
224 | case N_BSS: ms_type = mst_bss; break; | |
225 | case N_RDATA: ms_type = mst_bss; break; | |
226 | case N_IDATA: ms_type = mst_data; break; | |
227 | case N_ABS: ms_type = mst_abs; break; | |
228 | default: ms_type = mst_unknown; break; | |
229 | } | |
230 | ||
231 | prim_record_minimal_symbol | |
232 | (obsavestring (name, strlen(name), &objfile->symbol_obstack), | |
233 | address, ms_type, objfile); | |
234 | } | |
235 | ||
236 | /* read and process .stb file and store in minimal symbol table */ | |
237 | typedef char mhhdr[80]; | |
238 | struct stbhdr { | |
239 | mhhdr comhdr; | |
240 | char * name; | |
241 | short fmtno; | |
242 | int crc; | |
243 | int offset; | |
244 | int nsym; | |
245 | char *pad; | |
246 | }; | |
247 | struct stbsymbol { | |
248 | int value; | |
249 | short type; | |
250 | int stroff; | |
251 | }; | |
252 | #define STBSYMSIZE 10 | |
253 | ||
254 | static int | |
255 | read_minimal_symbols(objfile) | |
256 | struct objfile *objfile; | |
257 | { | |
258 | FILE *fp; | |
259 | bfd *abfd; | |
260 | struct stbhdr hdr; | |
261 | struct stbsymbol sym; | |
262 | int ch, i, j, off; | |
263 | char buf[64], buf1[128]; | |
264 | ||
265 | fp = objfile->auxf1; | |
266 | if (fp == NULL) return; | |
267 | abfd = objfile->obfd; | |
268 | fread(&hdr.comhdr[0], sizeof(mhhdr), 1, fp); | |
269 | i = 0; | |
270 | ch = getc(fp); | |
271 | while (ch != -1) { | |
272 | buf[i] = (char)ch; | |
273 | i++; | |
274 | if (ch == 0) break; | |
275 | ch = getc(fp); | |
276 | }; | |
277 | hdr.name = &buf[0]; | |
278 | ||
279 | fread(&hdr.fmtno, sizeof(hdr.fmtno), 1, fp); | |
280 | fread(&hdr.crc, sizeof(hdr.crc), 1, fp); | |
281 | fread(&hdr.offset, sizeof(hdr.offset), 1, fp); | |
282 | fread(&hdr.nsym, sizeof(hdr.nsym), 1, fp); | |
283 | SWAP_STBHDR(&hdr, abfd); | |
284 | ||
285 | /* read symbols */ | |
286 | init_minimal_symbol_collection(); | |
287 | off = hdr.offset; | |
288 | for (i = hdr.nsym; i > 0; i--) { | |
289 | fseek(fp, (long)off, 0); | |
290 | fread(&sym.value, sizeof(sym.value), 1, fp); | |
291 | fread(&sym.type, sizeof(sym.type), 1, fp); | |
292 | fread(&sym.stroff, sizeof(sym.stroff), 1, fp); | |
293 | SWAP_STBSYM (&sym, abfd); | |
294 | fseek(fp, (long)sym.stroff, 0); | |
295 | j = 0; | |
296 | ch = getc(fp); | |
297 | while (ch != -1) { | |
298 | buf1[j] = (char)ch; | |
299 | j++; | |
300 | if (ch == 0) break; | |
301 | ch = getc(fp); | |
302 | }; | |
303 | record_minimal_symbol(buf1, sym.value, sym.type&7, objfile); | |
304 | off += STBSYMSIZE; | |
305 | }; | |
306 | install_minimal_symbols (objfile); | |
307 | return 1; | |
308 | } | |
309 | \f | |
310 | /* Scan and build partial symbols for a symbol file. | |
311 | We have been initialized by a call to os9k_symfile_init, which | |
312 | put all the relevant info into a "struct os9k_symfile_info", | |
313 | hung off the objfile structure. | |
314 | ||
315 | SECTION_OFFSETS contains offsets relative to which the symbols in the | |
316 | various sections are (depending where the sections were actually loaded). | |
317 | MAINLINE is true if we are reading the main symbol | |
318 | table (as opposed to a shared lib or dynamically loaded file). */ | |
319 | ||
320 | static void | |
321 | os9k_symfile_read (objfile, section_offsets, mainline) | |
322 | struct objfile *objfile; | |
323 | struct section_offsets *section_offsets; | |
324 | int mainline; /* FIXME comments above */ | |
325 | { | |
326 | bfd *sym_bfd; | |
327 | int val; | |
328 | int stb_exist; | |
329 | struct cleanup *back_to; | |
330 | ||
331 | sym_bfd = objfile->obfd; | |
332 | /* If we are reinitializing, or if we have never loaded syms yet, init */ | |
333 | if (mainline || objfile->global_psymbols.size == 0 || | |
334 | objfile->static_psymbols.size == 0) | |
335 | init_psymbol_list (objfile); | |
336 | ||
337 | pending_blocks = 0; | |
338 | back_to = make_cleanup (really_free_pendings, 0); | |
339 | ||
340 | make_cleanup (discard_minimal_symbols, 0); | |
341 | read_minimal_symbols (objfile); | |
342 | ||
343 | /* Now that the symbol table data of the executable file are all in core, | |
344 | process them and define symbols accordingly. */ | |
345 | read_os9k_psymtab (section_offsets, objfile, | |
346 | bfd_section_vma (sym_bfd, DBX_TEXT_SECT (objfile)), | |
347 | bfd_section_size (sym_bfd, DBX_TEXT_SECT (objfile))); | |
348 | ||
349 | if (!have_partial_symbols ()) { | |
350 | wrap_here (""); | |
351 | printf_filtered ("(no debugging symbols found)..."); | |
352 | wrap_here (""); | |
353 | } | |
354 | ||
355 | do_cleanups (back_to); | |
356 | } | |
357 | ||
358 | /* Initialize anything that needs initializing when a completely new | |
359 | symbol file is specified (not just adding some symbols from another | |
360 | file, e.g. a shared library). */ | |
361 | ||
362 | static void | |
363 | os9k_new_init (ignore) | |
364 | struct objfile *ignore; | |
365 | { | |
366 | stabsread_new_init (); | |
367 | buildsym_new_init (); | |
368 | psymfile_depth = 0; | |
369 | /* | |
370 | init_header_files (); | |
371 | */ | |
372 | } | |
373 | ||
374 | /* os9k_symfile_init () | |
375 | It is passed a struct objfile which contains, among other things, | |
376 | the BFD for the file whose symbols are being read, and a slot for a pointer | |
377 | to "private data" which we fill with goodies. | |
378 | ||
379 | Since BFD doesn't know how to read debug symbols in a format-independent | |
380 | way (and may never do so...), we have to do it ourselves. We will never | |
381 | be called unless this is an a.out (or very similar) file. | |
382 | FIXME, there should be a cleaner peephole into the BFD environment here. */ | |
383 | ||
384 | static void | |
385 | os9k_symfile_init (objfile) | |
386 | struct objfile *objfile; | |
387 | { | |
388 | int val; | |
389 | bfd *sym_bfd = objfile->obfd; | |
390 | char *name = bfd_get_filename (sym_bfd); | |
391 | char dbgname[64], stbname[64]; | |
392 | FILE *symfile = 0; | |
393 | FILE *minfile = 0; | |
394 | ||
395 | ||
396 | strcpy(dbgname, name); | |
397 | strcat(dbgname, ".dbg"); | |
398 | strcpy(stbname, name); | |
399 | strcat(stbname, ".stb"); | |
400 | ||
401 | if ((symfile = fopen(dbgname, "r")) == NULL) { | |
402 | warning("Symbol file %s not found", dbgname); | |
403 | } | |
404 | objfile->auxf2 = symfile; | |
405 | ||
406 | if ((minfile = fopen(stbname, "r")) == NULL) { | |
407 | warning("Symbol file %s not found", stbname); | |
408 | } | |
409 | objfile->auxf1 = minfile; | |
410 | ||
411 | /* Allocate struct to keep track of the symfile */ | |
412 | objfile->sym_stab_info = (PTR) | |
413 | xmmalloc (objfile -> md, sizeof (struct dbx_symfile_info)); | |
414 | DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL; | |
415 | ||
416 | DBX_TEXT_SECT (objfile) = bfd_get_section_by_name (sym_bfd, ".text"); | |
417 | if (!DBX_TEXT_SECT (objfile)) | |
418 | error ("Can't find .text section in file"); | |
419 | ||
420 | DBX_SYMBOL_SIZE (objfile) = 0; /* variable size symbol */ | |
421 | DBX_SYMCOUNT (objfile) = 0; /* used to be bfd_get_symcount(sym_bfd) */ | |
422 | DBX_SYMTAB_OFFSET (objfile) = 0; /* used to be SYMBOL_TABLE_OFFSET */ | |
423 | } | |
424 | ||
425 | /* Perform any local cleanups required when we are done with a particular | |
426 | objfile. I.E, we are in the process of discarding all symbol information | |
427 | for an objfile, freeing up all memory held for it, and unlinking the | |
428 | objfile struct from the global list of known objfiles. */ | |
429 | ||
430 | static void | |
431 | os9k_symfile_finish (objfile) | |
432 | struct objfile *objfile; | |
433 | { | |
434 | if (objfile->sym_stab_info != NULL) | |
435 | { | |
436 | mfree (objfile -> md, objfile->sym_stab_info); | |
437 | } | |
438 | /* | |
439 | free_header_files (); | |
440 | */ | |
441 | } | |
442 | ||
443 | \f | |
444 | struct dbghdr { | |
445 | int sync; | |
446 | short rev; | |
447 | int crc; | |
448 | short os; | |
449 | short cpu; | |
450 | }; | |
451 | ||
452 | #define SWAP_DBGHDR(hdrp, abfd) \ | |
453 | { \ | |
454 | (hdrp)->sync = bfd_get_32(abfd, (unsigned char *)&(hdrp)->sync); \ | |
455 | (hdrp)->rev = bfd_get_16(abfd, (unsigned char *)&(hdrp)->rev); \ | |
456 | (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \ | |
457 | (hdrp)->os = bfd_get_16(abfd, (unsigned char *)&(hdrp)->os); \ | |
458 | (hdrp)->cpu = bfd_get_16(abfd, (unsigned char *)&(hdrp)->cpu); \ | |
459 | } | |
460 | ||
461 | #define N_SYM_CMPLR 0 | |
462 | #define N_SYM_SLINE 1 | |
463 | #define N_SYM_SYM 2 | |
464 | #define N_SYM_LBRAC 3 | |
465 | #define N_SYM_RBRAC 4 | |
466 | #define N_SYM_SE 5 | |
467 | ||
468 | struct internal_symstruct { | |
469 | short n_type; | |
470 | short n_desc; | |
471 | long n_value; | |
472 | char * n_strx; | |
473 | }; | |
474 | static struct internal_symstruct symbol; | |
475 | static struct internal_symstruct *symbuf = &symbol; | |
476 | static char strbuf[256]; | |
477 | ||
478 | static int | |
479 | fill_sym (dbg_file, abfd) | |
480 | FILE *dbg_file; | |
481 | bfd *abfd; | |
482 | { | |
483 | short id; | |
484 | short si; | |
485 | long li; | |
486 | int ii; | |
487 | ||
488 | int nbytes = fread(&si, sizeof(si), 1, dbg_file); | |
489 | if (nbytes == 0) | |
490 | return 0; | |
491 | if (nbytes < 0) | |
492 | perror_with_name ("reading .dbg file."); | |
493 | symbuf->n_desc = 0; | |
494 | symbuf->n_value = 0; | |
495 | symbuf->n_strx = NULL; | |
496 | symbuf->n_type = bfd_get_16 (abfd, (unsigned char *)&si); | |
497 | symbuf->n_type = 0xf & symbuf->n_type; | |
498 | switch (symbuf->n_type) | |
499 | { | |
500 | case N_SYM_CMPLR: | |
501 | fread(&si, sizeof(si), 1, dbg_file); | |
502 | symbuf->n_desc = bfd_get_16(abfd, (unsigned char *)&si); | |
503 | break; | |
504 | case N_SYM_SLINE: | |
505 | fread(&li, sizeof(li), 1, dbg_file); | |
506 | symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li); | |
507 | fread(&li, sizeof(li), 1, dbg_file); | |
508 | li = bfd_get_32(abfd, (unsigned char *)&li); | |
509 | symbuf->n_strx = (char *)(li >> 12); | |
510 | symbuf->n_desc = li & 0xfff; | |
511 | break; | |
512 | case N_SYM_SYM: | |
513 | fread(&li, sizeof(li), 1, dbg_file); | |
514 | symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li); | |
515 | si = 0; | |
516 | do { | |
517 | ii = getc(dbg_file); | |
518 | strbuf[si++] = (char) ii; | |
519 | } while (ii != 0 || si % 2 != 0); | |
520 | symbuf->n_strx = strbuf; | |
521 | break; | |
522 | case N_SYM_LBRAC: | |
523 | fread(&li, sizeof(li), 1, dbg_file); | |
524 | symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li); | |
525 | break; | |
526 | case N_SYM_RBRAC: | |
527 | fread(&li, sizeof(li), 1, dbg_file); | |
528 | symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li); | |
529 | break; | |
530 | case N_SYM_SE: | |
531 | break; | |
532 | } | |
533 | return 1; | |
534 | } | |
535 | \f | |
536 | /* Initializes storage for all of the partial symbols that will be | |
537 | created by read_dbx_symtab and subsidiaries. */ | |
538 | ||
539 | static void | |
540 | init_psymbol_list (objfile) | |
541 | struct objfile *objfile; | |
542 | { | |
543 | /* Free any previously allocated psymbol lists. */ | |
544 | if (objfile -> global_psymbols.list) | |
545 | mfree (objfile -> md, (PTR)objfile -> global_psymbols.list); | |
546 | if (objfile -> static_psymbols.list) | |
547 | mfree (objfile -> md, (PTR)objfile -> static_psymbols.list); | |
548 | ||
549 | /* Current best guess is that there are approximately a twentieth | |
550 | of the total symbols (in a debugging file) are global or static | |
551 | oriented symbols */ | |
552 | objfile -> global_psymbols.size = DBX_SYMCOUNT (objfile) / 10; | |
553 | objfile -> static_psymbols.size = DBX_SYMCOUNT (objfile) / 10; | |
554 | objfile -> global_psymbols.next = objfile -> global_psymbols.list = (struct partial_symbol *) | |
555 | xmmalloc (objfile -> md, objfile -> global_psymbols.size * sizeof (struct partial_symbol)); | |
556 | objfile -> static_psymbols.next = objfile -> static_psymbols.list = (struct partial_symbol *) | |
557 | xmmalloc (objfile -> md, objfile -> static_psymbols.size * sizeof (struct partial_symbol)); | |
558 | } | |
559 | ||
560 | /* Given pointers to an a.out symbol table in core containing dbx | |
561 | style data, setup partial_symtab's describing each source file for | |
562 | which debugging information is available. | |
563 | SYMFILE_NAME is the name of the file we are reading from | |
564 | and SECTION_OFFSETS is the set of offsets for the various sections | |
565 | of the file (a set of zeros if the mainline program). */ | |
566 | ||
567 | static void | |
568 | read_os9k_psymtab (section_offsets, objfile, text_addr, text_size) | |
569 | struct section_offsets *section_offsets; | |
570 | struct objfile *objfile; | |
571 | CORE_ADDR text_addr; | |
572 | int text_size; | |
573 | { | |
574 | register struct internal_symstruct *bufp = 0; /* =0 avoids gcc -Wall glitch*/ | |
575 | register char *namestring; | |
576 | int nsl; | |
577 | int past_first_source_file = 0; | |
578 | CORE_ADDR last_o_file_start = 0; | |
579 | struct cleanup *back_to; | |
580 | bfd *abfd; | |
581 | FILE *fp; | |
582 | struct dbghdr hdr; | |
583 | ||
584 | /* End of the text segment of the executable file. */ | |
585 | static CORE_ADDR end_of_text_addr; | |
586 | ||
587 | /* Current partial symtab */ | |
588 | static struct partial_symtab *pst = 0; | |
589 | ||
590 | /* List of current psymtab's include files */ | |
591 | char **psymtab_include_list; | |
592 | int includes_allocated; | |
593 | int includes_used; | |
594 | ||
595 | /* Index within current psymtab dependency list */ | |
596 | struct partial_symtab **dependency_list; | |
597 | int dependencies_used, dependencies_allocated; | |
598 | ||
599 | includes_allocated = 30; | |
600 | includes_used = 0; | |
601 | psymtab_include_list = (char **) alloca (includes_allocated * | |
602 | sizeof (char *)); | |
603 | ||
604 | dependencies_allocated = 30; | |
605 | dependencies_used = 0; | |
606 | dependency_list = | |
607 | (struct partial_symtab **) alloca (dependencies_allocated * | |
608 | sizeof (struct partial_symtab *)); | |
609 | ||
610 | last_source_file = NULL; | |
611 | ||
612 | #ifdef END_OF_TEXT_DEFAULT | |
613 | end_of_text_addr = END_OF_TEXT_DEFAULT; | |
614 | #else | |
615 | end_of_text_addr = text_addr + section_offsets->offsets[SECT_OFF_TEXT] | |
616 | + text_size; /* Relocate */ | |
617 | #endif | |
618 | ||
619 | abfd = objfile->obfd; | |
620 | fp = objfile->auxf2; | |
621 | ||
622 | fread(&hdr.sync, sizeof(hdr.sync), 1, fp); | |
623 | fread(&hdr.rev, sizeof(hdr.rev), 1, fp); | |
624 | fread(&hdr.crc, sizeof(hdr.crc), 1, fp); | |
625 | fread(&hdr.os, sizeof(hdr.os), 1, fp); | |
626 | fread(&hdr.cpu, sizeof(hdr.cpu), 1, fp); | |
627 | SWAP_DBGHDR(&hdr, abfd); | |
628 | ||
629 | symnum = 0; | |
630 | while(1) | |
631 | { | |
632 | int ret; | |
633 | long cursymoffset; | |
634 | ||
635 | /* Get the symbol for this run and pull out some info */ | |
636 | QUIT; /* allow this to be interruptable */ | |
637 | cursymoffset = ftell(objfile->auxf2); | |
638 | ret = fill_sym(objfile->auxf2, abfd); | |
639 | if (ret <= 0) break; | |
640 | else symnum++; | |
641 | bufp = symbuf; | |
642 | ||
643 | /* Special case to speed up readin. */ | |
644 | if (bufp->n_type == (short)N_SYM_SLINE) continue; | |
645 | ||
646 | #define CUR_SYMBOL_VALUE bufp->n_value | |
647 | /* partial-stab.h */ | |
648 | ||
649 | switch (bufp->n_type) | |
650 | { | |
651 | char *p; | |
652 | ||
653 | case N_SYM_CMPLR: | |
654 | continue; | |
655 | ||
656 | case N_SYM_SE: | |
657 | CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT); | |
658 | if (psymfile_depth == 1 && pst) | |
659 | { | |
660 | os9k_end_psymtab (pst, psymtab_include_list, includes_used, | |
661 | symnum, CUR_SYMBOL_VALUE, | |
662 | dependency_list, dependencies_used); | |
663 | pst = (struct partial_symtab *) 0; | |
664 | includes_used = 0; | |
665 | dependencies_used = 0; | |
666 | } | |
667 | psymfile_depth--; | |
668 | continue; | |
669 | ||
670 | case N_SYM_SYM: /* Typedef or automatic variable. */ | |
671 | namestring = bufp->n_strx; | |
672 | p = (char *) strchr (namestring, ':'); | |
673 | if (!p) | |
674 | continue; /* Not a debugging symbol. */ | |
675 | ||
676 | /* Main processing section for debugging symbols which | |
677 | the initial read through the symbol tables needs to worry | |
678 | about. If we reach this point, the symbol which we are | |
679 | considering is definitely one we are interested in. | |
680 | p must also contain the (valid) index into the namestring | |
681 | which indicates the debugging type symbol. */ | |
682 | ||
683 | switch (p[1]) | |
684 | { | |
685 | case 'S' : | |
686 | { | |
687 | unsigned long valu; | |
688 | enum language tmp_language; | |
689 | ||
690 | valu = CUR_SYMBOL_VALUE + | |
691 | ANOFFSET (section_offsets, SECT_OFF_TEXT); | |
692 | past_first_source_file = 1; | |
693 | ||
694 | if (psymfile_depth == 0) { | |
695 | if (!pst) | |
696 | pst = os9k_start_psymtab (objfile, section_offsets, | |
697 | namestring, valu, | |
698 | cursymoffset, | |
699 | symnum-1, | |
700 | objfile -> global_psymbols.next, | |
701 | objfile -> static_psymbols.next); | |
702 | } else { /* this is a include file */ | |
703 | tmp_language = deduce_language_from_filename (namestring); | |
704 | if (tmp_language != language_unknown | |
705 | && (tmp_language != language_c | |
706 | || psymtab_language != language_cplus)) | |
707 | psymtab_language = tmp_language; | |
708 | ||
709 | /* | |
710 | if (pst && STREQ (namestring, pst->filename)) | |
711 | continue; | |
712 | { | |
713 | register int i; | |
714 | for (i = 0; i < includes_used; i++) | |
715 | if (STREQ (namestring, psymtab_include_list[i])) | |
716 | { | |
717 | i = -1; | |
718 | break; | |
719 | } | |
720 | if (i == -1) | |
721 | continue; | |
722 | } | |
723 | */ | |
724 | ||
725 | psymtab_include_list[includes_used++] = namestring; | |
726 | if (includes_used >= includes_allocated) | |
727 | { | |
728 | char **orig = psymtab_include_list; | |
729 | ||
730 | psymtab_include_list = (char **) | |
731 | alloca ((includes_allocated *= 2) * sizeof (char *)); | |
732 | memcpy ((PTR)psymtab_include_list, (PTR)orig, | |
733 | includes_used * sizeof (char *)); | |
734 | } | |
735 | ||
736 | } | |
737 | psymfile_depth++; | |
738 | continue; | |
739 | } | |
740 | ||
741 | case 'v': | |
742 | ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring, | |
743 | VAR_NAMESPACE, LOC_STATIC, | |
744 | objfile->static_psymbols, | |
745 | CUR_SYMBOL_VALUE, | |
746 | psymtab_language, objfile); | |
747 | continue; | |
748 | case 'V': | |
749 | ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring, | |
750 | VAR_NAMESPACE, LOC_STATIC, | |
751 | objfile->global_psymbols, | |
752 | CUR_SYMBOL_VALUE, | |
753 | psymtab_language, objfile); | |
754 | continue; | |
755 | ||
756 | case 'T': | |
757 | if (p != namestring) /* a name is there, not just :T... */ | |
758 | { | |
759 | ADD_PSYMBOL_TO_LIST (namestring, p - namestring, | |
760 | STRUCT_NAMESPACE, LOC_TYPEDEF, | |
761 | objfile->static_psymbols, | |
762 | CUR_SYMBOL_VALUE, | |
763 | psymtab_language, objfile); | |
764 | if (p[2] == 't') | |
765 | { | |
766 | /* Also a typedef with the same name. */ | |
767 | ADD_PSYMBOL_TO_LIST (namestring, p - namestring, | |
768 | VAR_NAMESPACE, LOC_TYPEDEF, | |
769 | objfile->static_psymbols, | |
770 | CUR_SYMBOL_VALUE, psymtab_language, | |
771 | objfile); | |
772 | p += 1; | |
773 | } | |
774 | /* The semantics of C++ state that "struct foo { ... }" | |
775 | also defines a typedef for "foo". Unfortuantely, cfront | |
776 | never makes the typedef when translating from C++ to C. | |
777 | We make the typedef here so that "ptype foo" works as | |
778 | expected for cfront translated code. */ | |
779 | else if (psymtab_language == language_cplus) | |
780 | { | |
781 | /* Also a typedef with the same name. */ | |
782 | ADD_PSYMBOL_TO_LIST (namestring, p - namestring, | |
783 | VAR_NAMESPACE, LOC_TYPEDEF, | |
784 | objfile->static_psymbols, | |
785 | CUR_SYMBOL_VALUE, psymtab_language, | |
786 | objfile); | |
787 | } | |
788 | } | |
789 | goto check_enum; | |
790 | case 't': | |
791 | if (p != namestring) /* a name is there, not just :T... */ | |
792 | { | |
793 | ADD_PSYMBOL_TO_LIST (namestring, p - namestring, | |
794 | VAR_NAMESPACE, LOC_TYPEDEF, | |
795 | objfile->static_psymbols, | |
796 | CUR_SYMBOL_VALUE, | |
797 | psymtab_language, objfile); | |
798 | } | |
799 | check_enum: | |
800 | /* If this is an enumerated type, we need to | |
801 | add all the enum constants to the partial symbol | |
802 | table. This does not cover enums without names, e.g. | |
803 | "enum {a, b} c;" in C, but fortunately those are | |
804 | rare. There is no way for GDB to find those from the | |
805 | enum type without spending too much time on it. Thus | |
806 | to solve this problem, the compiler needs to put out the | |
807 | enum in a nameless type. GCC2 does this. */ | |
808 | ||
809 | /* We are looking for something of the form | |
810 | <name> ":" ("t" | "T") [<number> "="] "e" <size> | |
811 | {<constant> ":" <value> ","} ";". */ | |
812 | ||
813 | /* Skip over the colon and the 't' or 'T'. */ | |
814 | p += 2; | |
815 | /* This type may be given a number. Also, numbers can come | |
816 | in pairs like (0,26). Skip over it. */ | |
817 | while ((*p >= '0' && *p <= '9') | |
818 | || *p == '(' || *p == ',' || *p == ')' | |
819 | || *p == '=') | |
820 | p++; | |
821 | ||
822 | if (*p++ == 'e') | |
823 | { | |
824 | /* We have found an enumerated type. skip size */ | |
825 | while (*p >= '0' && *p <= '9') p++; | |
826 | /* According to comments in read_enum_type | |
827 | a comma could end it instead of a semicolon. | |
828 | I don't know where that happens. | |
829 | Accept either. */ | |
830 | while (*p && *p != ';' && *p != ',') | |
831 | { | |
832 | char *q; | |
833 | ||
834 | /* Check for and handle cretinous dbx symbol name | |
835 | continuation! | |
836 | if (*p == '\\') | |
837 | p = next_symbol_text (); | |
838 | */ | |
839 | ||
840 | /* Point to the character after the name | |
841 | of the enum constant. */ | |
842 | for (q = p; *q && *q != ':'; q++) | |
843 | ; | |
844 | /* Note that the value doesn't matter for | |
845 | enum constants in psymtabs, just in symtabs. */ | |
846 | ADD_PSYMBOL_TO_LIST (p, q - p, | |
847 | VAR_NAMESPACE, LOC_CONST, | |
848 | objfile->static_psymbols, 0, | |
849 | psymtab_language, objfile); | |
850 | /* Point past the name. */ | |
851 | p = q; | |
852 | /* Skip over the value. */ | |
853 | while (*p && *p != ',') | |
854 | p++; | |
855 | /* Advance past the comma. */ | |
856 | if (*p) | |
857 | p++; | |
858 | } | |
859 | } | |
860 | continue; | |
861 | case 'c': | |
862 | /* Constant, e.g. from "const" in Pascal. */ | |
863 | ADD_PSYMBOL_TO_LIST (namestring, p - namestring, | |
864 | VAR_NAMESPACE, LOC_CONST, | |
865 | objfile->static_psymbols, CUR_SYMBOL_VALUE, | |
866 | psymtab_language, objfile); | |
867 | continue; | |
868 | ||
869 | case 'f': | |
870 | CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT); | |
871 | if (pst && pst->textlow == 0) | |
872 | pst->textlow = CUR_SYMBOL_VALUE; | |
873 | ||
874 | ADD_PSYMBOL_TO_LIST (namestring, p - namestring, | |
875 | VAR_NAMESPACE, LOC_BLOCK, | |
876 | objfile->static_psymbols, CUR_SYMBOL_VALUE, | |
877 | psymtab_language, objfile); | |
878 | continue; | |
879 | ||
880 | case 'F': | |
881 | CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT); | |
882 | if (pst && pst->textlow == 0) | |
883 | pst->textlow = CUR_SYMBOL_VALUE; | |
884 | ||
885 | ADD_PSYMBOL_TO_LIST (namestring, p - namestring, | |
886 | VAR_NAMESPACE, LOC_BLOCK, | |
887 | objfile->global_psymbols, CUR_SYMBOL_VALUE, | |
888 | psymtab_language, objfile); | |
889 | continue; | |
890 | ||
891 | case 'p': | |
892 | case 'l': | |
893 | continue; | |
894 | ||
895 | case ':': | |
896 | /* It is a C++ nested symbol. We don't need to record it | |
897 | (I don't think); if we try to look up foo::bar::baz, | |
898 | then symbols for the symtab containing foo should get | |
899 | read in, I think. */ | |
900 | /* Someone says sun cc puts out symbols like | |
901 | /foo/baz/maclib::/usr/local/bin/maclib, | |
902 | which would get here with a symbol type of ':'. */ | |
903 | continue; | |
904 | ||
905 | default: | |
906 | /* Unexpected symbol descriptor. The second and subsequent stabs | |
907 | of a continued stab can show up here. The question is | |
908 | whether they ever can mimic a normal stab--it would be | |
909 | nice if not, since we certainly don't want to spend the | |
910 | time searching to the end of every string looking for | |
911 | a backslash. */ | |
912 | ||
913 | complain (&unknown_symchar_complaint, p[1]); | |
914 | continue; | |
915 | } | |
916 | ||
917 | case N_SYM_RBRAC: | |
918 | CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT); | |
919 | #ifdef HANDLE_RBRAC | |
920 | HANDLE_RBRAC(CUR_SYMBOL_VALUE); | |
921 | continue; | |
922 | #endif | |
923 | case N_SYM_LBRAC: | |
924 | continue; | |
925 | ||
926 | default: | |
927 | /* If we haven't found it yet, ignore it. It's probably some | |
928 | new type we don't know about yet. */ | |
929 | complain (&unknown_symtype_complaint, | |
930 | local_hex_string ((unsigned long) bufp->n_type)); | |
931 | continue; | |
932 | } | |
933 | } | |
934 | ||
935 | DBX_SYMCOUNT (objfile) = symnum; | |
936 | ||
937 | /* If there's stuff to be cleaned up, clean it up. */ | |
938 | if (DBX_SYMCOUNT (objfile) > 0 | |
939 | /*FIXME, does this have a bug at start address 0? */ | |
940 | && last_o_file_start | |
941 | && objfile -> ei.entry_point < bufp->n_value | |
942 | && objfile -> ei.entry_point >= last_o_file_start) | |
943 | { | |
944 | objfile -> ei.entry_file_lowpc = last_o_file_start; | |
945 | objfile -> ei.entry_file_highpc = bufp->n_value; | |
946 | } | |
947 | ||
948 | if (pst) | |
949 | { | |
950 | os9k_end_psymtab (pst, psymtab_include_list, includes_used, | |
951 | symnum, end_of_text_addr, | |
952 | dependency_list, dependencies_used); | |
953 | } | |
954 | /* | |
955 | do_cleanups (back_to); | |
956 | */ | |
957 | } | |
958 | ||
959 | /* Allocate and partially fill a partial symtab. It will be | |
960 | completely filled at the end of the symbol list. | |
961 | ||
962 | SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR | |
963 | is the address relative to which its symbols are (incremental) or 0 | |
964 | (normal). */ | |
965 | ||
966 | ||
967 | static struct partial_symtab * | |
968 | os9k_start_psymtab (objfile, section_offsets, | |
969 | filename, textlow, ldsymoff,ldsymcnt, global_syms, static_syms) | |
970 | struct objfile *objfile; | |
971 | struct section_offsets *section_offsets; | |
972 | char *filename; | |
973 | CORE_ADDR textlow; | |
974 | int ldsymoff; | |
975 | int ldsymcnt; | |
976 | struct partial_symbol *global_syms; | |
977 | struct partial_symbol *static_syms; | |
978 | { | |
979 | struct partial_symtab *result = | |
980 | start_psymtab_common(objfile, section_offsets, | |
981 | filename, textlow, global_syms, static_syms); | |
982 | ||
983 | result->read_symtab_private = (char *) | |
984 | obstack_alloc (&objfile -> psymbol_obstack, sizeof (struct symloc)); | |
985 | ||
986 | LDSYMOFF(result) = ldsymoff; | |
987 | LDSYMCNT(result) = ldsymcnt; | |
988 | result->read_symtab = os9k_psymtab_to_symtab; | |
989 | ||
990 | /* Deduce the source language from the filename for this psymtab. */ | |
991 | psymtab_language = deduce_language_from_filename (filename); | |
992 | return result; | |
993 | } | |
994 | ||
995 | /* Close off the current usage of PST. | |
996 | Returns PST or NULL if the partial symtab was empty and thrown away. | |
997 | FIXME: List variables and peculiarities of same. */ | |
998 | ||
999 | static struct partial_symtab * | |
1000 | os9k_end_psymtab (pst, include_list, num_includes, capping_symbol_cnt, | |
1001 | capping_text, dependency_list, number_dependencies) | |
1002 | struct partial_symtab *pst; | |
1003 | char **include_list; | |
1004 | int num_includes; | |
1005 | int capping_symbol_cnt; | |
1006 | CORE_ADDR capping_text; | |
1007 | struct partial_symtab **dependency_list; | |
1008 | int number_dependencies; | |
1009 | /* struct partial_symbol *capping_global, *capping_static;*/ | |
1010 | { | |
1011 | int i; | |
1012 | struct partial_symtab *p1; | |
1013 | struct objfile *objfile = pst -> objfile; | |
1014 | ||
1015 | if (capping_symbol_cnt != -1) | |
1016 | LDSYMCNT(pst) = capping_symbol_cnt - LDSYMCNT(pst); | |
1017 | ||
1018 | /* Under Solaris, the N_SO symbols always have a value of 0, | |
1019 | instead of the usual address of the .o file. Therefore, | |
1020 | we have to do some tricks to fill in texthigh and textlow. | |
1021 | The first trick is in partial-stab.h: if we see a static | |
1022 | or global function, and the textlow for the current pst | |
1023 | is still 0, then we use that function's address for | |
1024 | the textlow of the pst. | |
1025 | ||
1026 | Now, to fill in texthigh, we remember the last function seen | |
1027 | in the .o file (also in partial-stab.h). Also, there's a hack in | |
1028 | bfd/elf.c and gdb/elfread.c to pass the ELF st_size field | |
1029 | to here via the misc_info field. Therefore, we can fill in | |
1030 | a reliable texthigh by taking the address plus size of the | |
1031 | last function in the file. | |
1032 | ||
1033 | Unfortunately, that does not cover the case where the last function | |
1034 | in the file is static. See the paragraph below for more comments | |
1035 | on this situation. | |
1036 | ||
1037 | Finally, if we have a valid textlow for the current file, we run | |
1038 | down the partial_symtab_list filling in previous texthighs that | |
1039 | are still unknown. */ | |
1040 | ||
1041 | if (pst->texthigh == 0 && last_function_name) { | |
1042 | char *p; | |
1043 | int n; | |
1044 | struct minimal_symbol *minsym; | |
1045 | ||
1046 | p = strchr (last_function_name, ':'); | |
1047 | if (p == NULL) | |
1048 | p = last_function_name; | |
1049 | n = p - last_function_name; | |
1050 | p = alloca (n + 1); | |
1051 | strncpy (p, last_function_name, n); | |
1052 | p[n] = 0; | |
1053 | ||
1054 | minsym = lookup_minimal_symbol (p, objfile); | |
1055 | ||
1056 | if (minsym) { | |
1057 | pst->texthigh = SYMBOL_VALUE_ADDRESS(minsym)+(long)MSYMBOL_INFO(minsym); | |
1058 | } else { | |
1059 | /* This file ends with a static function, and it's | |
1060 | difficult to imagine how hard it would be to track down | |
1061 | the elf symbol. Luckily, most of the time no one will notice, | |
1062 | since the next file will likely be compiled with -g, so | |
1063 | the code below will copy the first fuction's start address | |
1064 | back to our texthigh variable. (Also, if this file is the | |
1065 | last one in a dynamically linked program, texthigh already | |
1066 | has the right value.) If the next file isn't compiled | |
1067 | with -g, then the last function in this file winds up owning | |
1068 | all of the text space up to the next -g file, or the end (minus | |
1069 | shared libraries). This only matters for single stepping, | |
1070 | and even then it will still work, except that it will single | |
1071 | step through all of the covered functions, instead of setting | |
1072 | breakpoints around them as it usualy does. This makes it | |
1073 | pretty slow, but at least it doesn't fail. | |
1074 | ||
1075 | We can fix this with a fairly big change to bfd, but we need | |
1076 | to coordinate better with Cygnus if we want to do that. FIXME. */ | |
1077 | } | |
1078 | last_function_name = NULL; | |
1079 | } | |
1080 | ||
1081 | /* this test will be true if the last .o file is only data */ | |
1082 | if (pst->textlow == 0) | |
1083 | pst->textlow = pst->texthigh; | |
1084 | ||
1085 | /* If we know our own starting text address, then walk through all other | |
1086 | psymtabs for this objfile, and if any didn't know their ending text | |
1087 | address, set it to our starting address. Take care to not set our | |
1088 | own ending address to our starting address, nor to set addresses on | |
1089 | `dependency' files that have both textlow and texthigh zero. */ | |
1090 | if (pst->textlow) { | |
1091 | ALL_OBJFILE_PSYMTABS (objfile, p1) { | |
1092 | if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst) { | |
1093 | p1->texthigh = pst->textlow; | |
1094 | /* if this file has only data, then make textlow match texthigh */ | |
1095 | if (p1->textlow == 0) | |
1096 | p1->textlow = p1->texthigh; | |
1097 | } | |
1098 | } | |
1099 | } | |
1100 | ||
1101 | /* End of kludge for patching Solaris textlow and texthigh. */ | |
1102 | ||
1103 | pst->n_global_syms = | |
1104 | objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset); | |
1105 | pst->n_static_syms = | |
1106 | objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset); | |
1107 | ||
1108 | pst->number_of_dependencies = number_dependencies; | |
1109 | if (number_dependencies) | |
1110 | { | |
1111 | pst->dependencies = (struct partial_symtab **) | |
1112 | obstack_alloc (&objfile->psymbol_obstack, | |
1113 | number_dependencies * sizeof (struct partial_symtab *)); | |
1114 | memcpy (pst->dependencies, dependency_list, | |
1115 | number_dependencies * sizeof (struct partial_symtab *)); | |
1116 | } | |
1117 | else | |
1118 | pst->dependencies = 0; | |
1119 | ||
1120 | for (i = 0; i < num_includes; i++) | |
1121 | { | |
1122 | struct partial_symtab *subpst = | |
1123 | allocate_psymtab (include_list[i], objfile); | |
1124 | ||
1125 | subpst->section_offsets = pst->section_offsets; | |
1126 | subpst->read_symtab_private = | |
1127 | (char *) obstack_alloc (&objfile->psymbol_obstack, | |
1128 | sizeof (struct symloc)); | |
1129 | LDSYMOFF(subpst) = | |
1130 | LDSYMCNT(subpst) = | |
1131 | subpst->textlow = | |
1132 | subpst->texthigh = 0; | |
1133 | ||
1134 | /* We could save slight bits of space by only making one of these, | |
1135 | shared by the entire set of include files. FIXME-someday. */ | |
1136 | subpst->dependencies = (struct partial_symtab **) | |
1137 | obstack_alloc (&objfile->psymbol_obstack, | |
1138 | sizeof (struct partial_symtab *)); | |
1139 | subpst->dependencies[0] = pst; | |
1140 | subpst->number_of_dependencies = 1; | |
1141 | ||
1142 | subpst->globals_offset = | |
1143 | subpst->n_global_syms = | |
1144 | subpst->statics_offset = | |
1145 | subpst->n_static_syms = 0; | |
1146 | ||
1147 | subpst->readin = 0; | |
1148 | subpst->symtab = 0; | |
1149 | subpst->read_symtab = pst->read_symtab; | |
1150 | } | |
1151 | ||
1152 | sort_pst_symbols (pst); | |
1153 | ||
1154 | /* If there is already a psymtab or symtab for a file of this name, | |
1155 | remove it. | |
1156 | (If there is a symtab, more drastic things also happen.) | |
1157 | This happens in VxWorks. */ | |
1158 | free_named_symtabs (pst->filename); | |
1159 | ||
1160 | if (num_includes == 0 | |
1161 | && number_dependencies == 0 | |
1162 | && pst->n_global_syms == 0 | |
1163 | && pst->n_static_syms == 0) { | |
1164 | /* Throw away this psymtab, it's empty. We can't deallocate it, since | |
1165 | it is on the obstack, but we can forget to chain it on the list. */ | |
1166 | struct partial_symtab *prev_pst; | |
1167 | ||
1168 | /* First, snip it out of the psymtab chain */ | |
1169 | ||
1170 | if (pst->objfile->psymtabs == pst) | |
1171 | pst->objfile->psymtabs = pst->next; | |
1172 | else | |
1173 | for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next) | |
1174 | if (prev_pst->next == pst) | |
1175 | prev_pst->next = pst->next; | |
1176 | ||
1177 | /* Next, put it on a free list for recycling */ | |
1178 | pst->next = pst->objfile->free_psymtabs; | |
1179 | pst->objfile->free_psymtabs = pst; | |
1180 | ||
1181 | /* Indicate that psymtab was thrown away. */ | |
1182 | pst = (struct partial_symtab *)NULL; | |
1183 | } | |
1184 | return pst; | |
1185 | } | |
1186 | \f | |
1187 | static void | |
1188 | os9k_psymtab_to_symtab_1 (pst) | |
1189 | struct partial_symtab *pst; | |
1190 | { | |
1191 | struct cleanup *old_chain; | |
1192 | int i; | |
1193 | ||
1194 | if (!pst) | |
1195 | return; | |
1196 | ||
1197 | if (pst->readin) | |
1198 | { | |
1199 | fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n", | |
1200 | pst->filename); | |
1201 | return; | |
1202 | } | |
1203 | ||
1204 | /* Read in all partial symtabs on which this one is dependent */ | |
1205 | for (i = 0; i < pst->number_of_dependencies; i++) | |
1206 | if (!pst->dependencies[i]->readin) | |
1207 | { | |
1208 | /* Inform about additional files that need to be read in. */ | |
1209 | if (info_verbose) | |
1210 | { | |
1211 | fputs_filtered (" ", gdb_stdout); | |
1212 | wrap_here (""); | |
1213 | fputs_filtered ("and ", gdb_stdout); | |
1214 | wrap_here (""); | |
1215 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
1216 | wrap_here (""); /* Flush output */ | |
1217 | gdb_flush (gdb_stdout); | |
1218 | } | |
1219 | os9k_psymtab_to_symtab_1 (pst->dependencies[i]); | |
1220 | } | |
1221 | ||
1222 | if (LDSYMCNT(pst)) /* Otherwise it's a dummy */ | |
1223 | { | |
1224 | /* Init stuff necessary for reading in symbols */ | |
1225 | stabsread_init (); | |
1226 | buildsym_init (); | |
1227 | old_chain = make_cleanup (really_free_pendings, 0); | |
1228 | ||
1229 | /* Read in this file's symbols */ | |
1230 | os9k_read_ofile_symtab (pst); | |
1231 | sort_symtab_syms (pst->symtab); | |
1232 | do_cleanups (old_chain); | |
1233 | } | |
1234 | ||
1235 | pst->readin = 1; | |
1236 | } | |
1237 | ||
1238 | /* Read in all of the symbols for a given psymtab for real. | |
1239 | Be verbose about it if the user wants that. */ | |
1240 | ||
1241 | static void | |
1242 | os9k_psymtab_to_symtab (pst) | |
1243 | struct partial_symtab *pst; | |
1244 | { | |
1245 | bfd *sym_bfd; | |
1246 | ||
1247 | if (!pst) | |
1248 | return; | |
1249 | ||
1250 | if (pst->readin) | |
1251 | { | |
1252 | fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n", | |
1253 | pst->filename); | |
1254 | return; | |
1255 | } | |
1256 | ||
1257 | if (LDSYMCNT(pst) || pst->number_of_dependencies) | |
1258 | { | |
1259 | /* Print the message now, before reading the string table, | |
1260 | to avoid disconcerting pauses. */ | |
1261 | if (info_verbose) | |
1262 | { | |
1263 | printf_filtered ("Reading in symbols for %s...", pst->filename); | |
1264 | gdb_flush (gdb_stdout); | |
1265 | } | |
1266 | ||
1267 | sym_bfd = pst->objfile->obfd; | |
1268 | os9k_psymtab_to_symtab_1 (pst); | |
1269 | ||
1270 | /* Match with global symbols. This only needs to be done once, | |
1271 | after all of the symtabs and dependencies have been read in. */ | |
1272 | scan_file_globals (pst->objfile); | |
1273 | ||
1274 | /* Finish up the debug error message. */ | |
1275 | if (info_verbose) | |
1276 | printf_filtered ("done.\n"); | |
1277 | } | |
1278 | } | |
1279 | ||
1280 | /* Read in a defined section of a specific object file's symbols. */ | |
1281 | static void | |
1282 | os9k_read_ofile_symtab (pst) | |
1283 | struct partial_symtab *pst; | |
1284 | { | |
1285 | register struct internal_symstruct *bufp; | |
1286 | unsigned char type; | |
1287 | unsigned max_symnum; | |
1288 | register bfd *abfd; | |
1289 | struct objfile *objfile; | |
1290 | int sym_offset; /* Offset to start of symbols to read */ | |
1291 | CORE_ADDR text_offset; /* Start of text segment for symbols */ | |
1292 | int text_size; /* Size of text segment for symbols */ | |
1293 | struct section_offsets *section_offsets; | |
1294 | FILE *dbg_file; | |
1295 | ||
1296 | objfile = pst->objfile; | |
1297 | sym_offset = LDSYMOFF(pst); | |
1298 | max_symnum = LDSYMCNT(pst); | |
1299 | text_offset = pst->textlow; | |
1300 | text_size = pst->texthigh - pst->textlow; | |
1301 | section_offsets = pst->section_offsets; | |
1302 | ||
1303 | current_objfile = objfile; | |
1304 | subfile_stack = NULL; | |
1305 | last_source_file = NULL; | |
1306 | ||
1307 | abfd = objfile->obfd; | |
1308 | dbg_file = objfile->auxf2; | |
1309 | ||
1310 | #if 0 | |
1311 | /* It is necessary to actually read one symbol *before* the start | |
1312 | of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL | |
1313 | occurs before the N_SO symbol. | |
1314 | Detecting this in read_dbx_symtab | |
1315 | would slow down initial readin, so we look for it here instead. */ | |
1316 | if (!processing_acc_compilation && sym_offset >= (int)symbol_size) | |
1317 | { | |
1318 | fseek (objefile->auxf2, sym_offset, SEEK_CUR); | |
1319 | fill_sym(objfile->auxf2, abfd); | |
1320 | bufp = symbuf; | |
1321 | ||
1322 | processing_gcc_compilation = 0; | |
1323 | if (bufp->n_type == N_TEXT) | |
1324 | { | |
1325 | if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL)) | |
1326 | processing_gcc_compilation = 1; | |
1327 | else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL)) | |
1328 | processing_gcc_compilation = 2; | |
1329 | } | |
1330 | ||
1331 | /* Try to select a C++ demangling based on the compilation unit | |
1332 | producer. */ | |
1333 | ||
1334 | if (processing_gcc_compilation) | |
1335 | { | |
1336 | if (AUTO_DEMANGLING) | |
1337 | { | |
1338 | set_demangling_style (GNU_DEMANGLING_STYLE_STRING); | |
1339 | } | |
1340 | } | |
1341 | } | |
1342 | else | |
1343 | { | |
1344 | /* The N_SO starting this symtab is the first symbol, so we | |
1345 | better not check the symbol before it. I'm not this can | |
1346 | happen, but it doesn't hurt to check for it. */ | |
1347 | bfd_seek (symfile_bfd, sym_offset, SEEK_CUR); | |
1348 | processing_gcc_compilation = 0; | |
1349 | } | |
1350 | #endif 0 | |
1351 | ||
1352 | fseek(dbg_file, (long)sym_offset, 0); | |
1353 | /* | |
1354 | if (bufp->n_type != (unsigned char)N_SYM_SYM) | |
1355 | error("First symbol in segment of executable not a source symbol"); | |
1356 | */ | |
1357 | ||
1358 | for (symnum = 0; symnum < max_symnum; symnum++) | |
1359 | { | |
1360 | QUIT; /* Allow this to be interruptable */ | |
1361 | fill_sym(dbg_file, abfd); | |
1362 | bufp = symbuf; | |
1363 | type = bufp->n_type; | |
1364 | ||
1365 | os9k_process_one_symbol (type, bufp->n_desc, bufp->n_value, | |
1366 | bufp->n_strx, section_offsets, objfile); | |
1367 | ||
1368 | /* We skip checking for a new .o or -l file; that should never | |
1369 | happen in this routine. */ | |
1370 | #if 0 | |
1371 | else if (type == N_TEXT) | |
1372 | { | |
1373 | /* I don't think this code will ever be executed, because | |
1374 | the GCC_COMPILED_FLAG_SYMBOL usually is right before | |
1375 | the N_SO symbol which starts this source file. | |
1376 | However, there is no reason not to accept | |
1377 | the GCC_COMPILED_FLAG_SYMBOL anywhere. */ | |
1378 | ||
1379 | if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL)) | |
1380 | processing_gcc_compilation = 1; | |
1381 | else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL)) | |
1382 | processing_gcc_compilation = 2; | |
1383 | ||
1384 | if (AUTO_DEMANGLING) | |
1385 | { | |
1386 | set_demangling_style (GNU_DEMANGLING_STYLE_STRING); | |
1387 | } | |
1388 | } | |
1389 | else if (type & N_EXT || type == (unsigned char)N_TEXT | |
1390 | || type == (unsigned char)N_NBTEXT | |
1391 | ) { | |
1392 | /* Global symbol: see if we came across a dbx defintion for | |
1393 | a corresponding symbol. If so, store the value. Remove | |
1394 | syms from the chain when their values are stored, but | |
1395 | search the whole chain, as there may be several syms from | |
1396 | different files with the same name. */ | |
1397 | /* This is probably not true. Since the files will be read | |
1398 | in one at a time, each reference to a global symbol will | |
1399 | be satisfied in each file as it appears. So we skip this | |
1400 | section. */ | |
1401 | ; | |
1402 | } | |
1403 | #endif 0 | |
1404 | } | |
1405 | ||
1406 | current_objfile = NULL; | |
1407 | ||
1408 | /* In a Solaris elf file, this variable, which comes from the | |
1409 | value of the N_SO symbol, will still be 0. Luckily, text_offset, | |
1410 | which comes from pst->textlow is correct. */ | |
1411 | if (last_source_start_addr == 0) | |
1412 | last_source_start_addr = text_offset; | |
1413 | pst->symtab = end_symtab (text_offset + text_size, 0, 0, objfile, | |
1414 | SECT_OFF_TEXT); | |
1415 | end_stabs (); | |
1416 | } | |
1417 | ||
1418 | \f | |
1419 | /* This handles a single symbol from the symbol-file, building symbols | |
1420 | into a GDB symtab. It takes these arguments and an implicit argument. | |
1421 | ||
1422 | TYPE is the type field of the ".stab" symbol entry. | |
1423 | DESC is the desc field of the ".stab" entry. | |
1424 | VALU is the value field of the ".stab" entry. | |
1425 | NAME is the symbol name, in our address space. | |
1426 | SECTION_OFFSETS is a set of amounts by which the sections of this object | |
1427 | file were relocated when it was loaded into memory. | |
1428 | All symbols that refer | |
1429 | to memory locations need to be offset by these amounts. | |
1430 | OBJFILE is the object file from which we are reading symbols. | |
1431 | It is used in end_symtab. */ | |
1432 | ||
1433 | static void | |
1434 | os9k_process_one_symbol (type, desc, valu, name, section_offsets, objfile) | |
1435 | int type, desc; | |
1436 | CORE_ADDR valu; | |
1437 | char *name; | |
1438 | struct section_offsets *section_offsets; | |
1439 | struct objfile *objfile; | |
1440 | { | |
1441 | register struct context_stack *new; | |
1442 | /* The stab type used for the definition of the last function. | |
1443 | N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */ | |
1444 | static int function_stab_type = 0; | |
1445 | ||
1446 | #if 0 | |
1447 | /* Something is wrong if we see real data before | |
1448 | seeing a source file name. */ | |
1449 | if (last_source_file == NULL && type != (unsigned char)N_SO) | |
1450 | { | |
1451 | /* Ignore any symbols which appear before an N_SO symbol. Currently | |
1452 | no one puts symbols there, but we should deal gracefully with the | |
1453 | case. A complain()t might be in order (if !IGNORE_SYMBOL (type)), | |
1454 | but this should not be an error (). */ | |
1455 | return; | |
1456 | } | |
1457 | #endif 0 | |
1458 | ||
1459 | switch (type) | |
1460 | { | |
1461 | case N_SYM_LBRAC: | |
1462 | /* On most machines, the block addresses are relative to the | |
1463 | N_SO, the linker did not relocate them (sigh). */ | |
1464 | valu += last_source_start_addr; | |
1465 | new = push_context (desc, valu); | |
1466 | break; | |
1467 | ||
1468 | case N_SYM_RBRAC: | |
1469 | valu += last_source_start_addr; | |
1470 | new = pop_context(); | |
1471 | ||
1472 | #if !defined (VARIABLES_INSIDE_BLOCK) | |
1473 | #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 1 | |
1474 | #endif | |
1475 | ||
1476 | if (!VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)) | |
1477 | local_symbols = new->locals; | |
1478 | ||
1479 | if (context_stack_depth > 1) | |
1480 | { | |
1481 | /* This is not the outermost LBRAC...RBRAC pair in the function, | |
1482 | its local symbols preceded it, and are the ones just recovered | |
1483 | from the context stack. Define the block for them (but don't | |
1484 | bother if the block contains no symbols. Should we complain | |
1485 | on blocks without symbols? I can't think of any useful purpose | |
1486 | for them). */ | |
1487 | if (local_symbols != NULL) | |
1488 | { | |
1489 | /* Muzzle a compiler bug that makes end < start. (which | |
1490 | compilers? Is this ever harmful?). */ | |
1491 | if (new->start_addr > valu) | |
1492 | { | |
1493 | complain (&lbrac_rbrac_complaint); | |
1494 | new->start_addr = valu; | |
1495 | } | |
1496 | /* Make a block for the local symbols within. */ | |
1497 | finish_block (0, &local_symbols, new->old_blocks, | |
1498 | new->start_addr, valu, objfile); | |
1499 | } | |
1500 | } | |
1501 | else | |
1502 | { | |
1503 | if (context_stack_depth == 0) | |
1504 | { | |
1505 | within_function = 0; | |
1506 | /* Make a block for the local symbols within. */ | |
1507 | finish_block (new->name, &local_symbols, new->old_blocks, | |
1508 | new->start_addr, valu, objfile); | |
1509 | } | |
1510 | else | |
1511 | { | |
1512 | /* attach local_symbols to the end of new->locals */ | |
1513 | if (!new->locals) new->locals = local_symbols; | |
1514 | else { | |
1515 | struct pending *p; | |
1516 | ||
1517 | p = new->locals; | |
1518 | while (p->next) p = p->next; | |
1519 | p->next = local_symbols; | |
1520 | } | |
1521 | } | |
1522 | } | |
1523 | ||
1524 | if (VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)) | |
1525 | /* Now pop locals of block just finished. */ | |
1526 | local_symbols = new->locals; | |
1527 | break; | |
1528 | ||
1529 | ||
1530 | case N_SYM_SLINE: | |
1531 | /* This type of "symbol" really just records | |
1532 | one line-number -- core-address correspondence. | |
1533 | Enter it in the line list for this symbol table. */ | |
1534 | /* Relocate for dynamic loading and for ELF acc fn-relative syms. */ | |
1535 | valu += last_source_start_addr; | |
1536 | record_line (current_subfile, (int)name, valu); | |
1537 | break; | |
1538 | ||
1539 | /* The following symbol types need to have the appropriate offset added | |
1540 | to their value; then we process symbol definitions in the name. */ | |
1541 | case N_SYM_SYM: | |
1542 | ||
1543 | if (name) | |
1544 | { | |
1545 | char deftype; | |
1546 | char *dirn, *n; | |
1547 | char *p = strchr (name, ':'); | |
1548 | if (p == NULL) | |
1549 | deftype = '\0'; | |
1550 | else | |
1551 | deftype = p[1]; | |
1552 | ||
1553 | ||
1554 | switch (deftype) | |
1555 | { | |
1556 | case 'S': | |
1557 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT); | |
1558 | n = strrchr(name, '/'); | |
1559 | if (n != NULL) { | |
1560 | *n = '\0'; | |
1561 | n++; | |
1562 | dirn = name; | |
1563 | } else { | |
1564 | n = name; | |
1565 | dirn = NULL; | |
1566 | } | |
1567 | *p = '\0'; | |
1568 | if (symfile_depth++ == 0) { | |
1569 | if (last_source_file) { | |
1570 | end_symtab (valu, 0, 0, objfile, SECT_OFF_TEXT); | |
1571 | end_stabs (); | |
1572 | } | |
1573 | start_stabs (); | |
1574 | start_symtab (n, dirn, valu); | |
1575 | } else { | |
1576 | push_subfile(); | |
1577 | start_subfile (n, dirn!=NULL ? dirn : current_subfile->dirname); | |
1578 | } | |
1579 | break; | |
1580 | ||
1581 | case 'f': | |
1582 | case 'F': | |
1583 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT); | |
1584 | function_stab_type = type; | |
1585 | ||
1586 | within_function = 1; | |
1587 | new = push_context (0, valu); | |
1588 | new->name = os9k_define_symbol (valu, name, desc, type, objfile); | |
1589 | break; | |
1590 | ||
1591 | case 'V': | |
1592 | case 'v': | |
1593 | valu += ANOFFSET (section_offsets, SECT_OFF_DATA); | |
1594 | os9k_define_symbol (valu, name, desc, type, objfile); | |
1595 | break; | |
1596 | ||
1597 | default: | |
1598 | os9k_define_symbol (valu, name, desc, type, objfile); | |
1599 | break; | |
1600 | } | |
1601 | } | |
1602 | break; | |
1603 | ||
1604 | case N_SYM_SE: | |
1605 | if (--symfile_depth != 0) | |
1606 | start_subfile(pop_subfile(), current_subfile->dirname); | |
1607 | break; | |
1608 | ||
1609 | default: | |
1610 | complain (&unknown_symtype_complaint, | |
1611 | local_hex_string((unsigned long) type)); | |
1612 | /* FALLTHROUGH */ | |
1613 | break; | |
1614 | ||
1615 | case N_SYM_CMPLR: | |
1616 | break; | |
1617 | } | |
1618 | previous_stab_code = type; | |
1619 | } | |
1620 | \f | |
1621 | /* Parse the user's idea of an offset for dynamic linking, into our idea | |
1622 | of how to represent it for fast symbol reading. */ | |
1623 | ||
1624 | static struct section_offsets * | |
1625 | os9k_symfile_offsets (objfile, addr) | |
1626 | struct objfile *objfile; | |
1627 | CORE_ADDR addr; | |
1628 | { | |
1629 | struct section_offsets *section_offsets; | |
1630 | int i; | |
1631 | ||
1632 | objfile->num_sections = SECT_OFF_MAX; | |
1633 | section_offsets = (struct section_offsets *) | |
1634 | obstack_alloc (&objfile -> psymbol_obstack, | |
1635 | sizeof (struct section_offsets) | |
1636 | + sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1)); | |
1637 | ||
1638 | for (i = 0; i < SECT_OFF_MAX; i++) | |
1639 | ANOFFSET (section_offsets, i) = addr; | |
1640 | ||
1641 | return section_offsets; | |
1642 | } | |
1643 | \f | |
1644 | static struct sym_fns os9k_sym_fns = | |
1645 | { | |
1646 | bfd_target_os9k_flavour, | |
1647 | os9k_new_init, /* sym_new_init: init anything gbl to entire symtab */ | |
1648 | os9k_symfile_init, /* sym_init: read initial info, setup for sym_read() */ | |
1649 | os9k_symfile_read, /* sym_read: read a symbol file into symtab */ | |
1650 | os9k_symfile_finish, /* sym_finish: finished with file, cleanup */ | |
1651 | os9k_symfile_offsets, /* sym_offsets: parse user's offsets to internal form*/ | |
1652 | NULL /* next: pointer to next struct sym_fns */ | |
1653 | }; | |
1654 | ||
1655 | void | |
1656 | _initialize_os9kread () | |
1657 | { | |
1658 | add_symtab_fns(&os9k_sym_fns); | |
1659 | } |