Commit | Line | Data |
---|---|---|
e38e0312 JG |
1 | /* Read AIXcoff symbol tables and convert to internal format, for GDB. |
2 | Copyright (C) 1986-1991 Free Software Foundation, Inc. | |
3 | Derived from coffread.c, dbxread.c, and a lot of hacking. | |
4 | Contributed by IBM Corporation. | |
5 | ||
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
21 | ||
3ae444f8 | 22 | #include <stdio.h> |
e38e0312 JG |
23 | #include "defs.h" |
24 | #include "bfd.h" | |
e38e0312 | 25 | |
e38e0312 JG |
26 | /* AIX COFF names have a preceeding dot `.' */ |
27 | #define NAMES_HAVE_DOT 1 | |
28 | ||
29 | #include <sys/types.h> | |
30 | #include <fcntl.h> | |
31 | #include <ctype.h> | |
32 | ||
33 | #include "obstack.h" | |
34 | #include <sys/param.h> | |
5e4d4b0f | 35 | #ifndef NO_SYS_FILE |
e38e0312 | 36 | #include <sys/file.h> |
5e4d4b0f | 37 | #endif |
e38e0312 JG |
38 | #include <sys/stat.h> |
39 | ||
40 | #include "symtab.h" | |
1ab3bf1b | 41 | #include "gdbtypes.h" |
e38e0312 JG |
42 | #include "symfile.h" |
43 | #include "buildsym.h" | |
44 | ||
f5f0679a | 45 | #include "coff/internal.h" /* FIXME, internal data from BFD */ |
e38e0312 | 46 | #include "libcoff.h" /* FIXME, internal data from BFD */ |
f5f0679a | 47 | #include "coff/rs6000.h" /* FIXME, raw file-format guts of xcoff */ |
e38e0312 | 48 | |
e38e0312 JG |
49 | /* Simplified internal version of coff symbol table information */ |
50 | ||
51 | struct coff_symbol { | |
52 | char *c_name; | |
53 | int c_symnum; /* symbol number of this entry */ | |
54 | int c_nsyms; /* 0 if syment only, 1 if syment + auxent */ | |
55 | long c_value; | |
56 | int c_sclass; | |
57 | int c_secnum; | |
58 | unsigned int c_type; | |
59 | }; | |
60 | ||
61 | /* The COFF line table, in raw form. */ | |
62 | static char *linetab = NULL; /* Its actual contents */ | |
63 | static long linetab_offset; /* Its offset in the file */ | |
64 | static unsigned long linetab_size; /* Its size */ | |
65 | ||
66 | /* last function's saved coff symbol `cs' */ | |
67 | ||
68 | static struct coff_symbol fcn_cs_saved; | |
69 | ||
70 | static bfd *symfile_bfd; | |
71 | ||
72 | /* Core address of start and end of text of current source file. | |
73 | This is calculated from the first function seen after a C_FILE | |
74 | symbol. */ | |
75 | ||
76 | static CORE_ADDR cur_src_start_addr; | |
77 | static CORE_ADDR cur_src_end_addr; | |
78 | ||
79 | /* Core address of the end of the first object file. */ | |
80 | ||
81 | static CORE_ADDR first_object_file_end; | |
82 | ||
83 | /* pointer to the string table */ | |
84 | static char *strtbl; | |
85 | ||
86 | /* length of the string table */ | |
87 | static int strtbl_len; | |
88 | ||
89 | /* pointer to debug section */ | |
90 | static char *debugsec; | |
91 | ||
92 | /* pointer to the a.out symbol table */ | |
93 | static char *symtbl; | |
94 | ||
95 | /* initial symbol-table-debug-string vector length */ | |
96 | ||
97 | #define INITIAL_STABVECTOR_LENGTH 40 | |
98 | ||
99 | struct pending_stabs *global_stabs; | |
100 | struct pending_stabs *file_stabs; | |
101 | ||
102 | /* Nonzero if within a function (so symbols should be local, | |
103 | if nothing says specifically). */ | |
104 | ||
105 | int within_function; | |
106 | ||
107 | /* Local variables that hold the shift and mask values for the | |
108 | COFF file that we are currently reading. These come back to us | |
109 | from BFD, and are referenced by their macro names, as well as | |
110 | internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF | |
111 | macros from ../internalcoff.h . */ | |
112 | ||
113 | static unsigned local_n_btshft; | |
114 | static unsigned local_n_tmask; | |
115 | ||
116 | #undef N_BTSHFT | |
117 | #define N_BTSHFT local_n_btshft | |
118 | #undef N_TMASK | |
119 | #define N_TMASK local_n_tmask | |
120 | ||
121 | /* Local variables that hold the sizes in the file of various COFF structures. | |
122 | (We only need to know this to read them from the file -- BFD will then | |
123 | translate the data in them, into `internal_xxx' structs in the right | |
124 | byte order, alignment, etc.) */ | |
125 | ||
126 | static unsigned local_symesz; | |
127 | ||
128 | /* coff_symfile_init() | |
129 | is the coff-specific initialization routine for reading symbols. | |
130 | It is passed a struct sym_fns which contains, among other things, | |
131 | the BFD for the file whose symbols are being read, and a slot for | |
132 | a pointer to "private data" which we fill with cookies and other | |
133 | treats for coff_symfile_read(). | |
134 | ||
135 | We will only be called if this is a COFF or COFF-like file. | |
136 | BFD handles figuring out the format of the file, and code in symtab.c | |
137 | uses BFD's determination to vector to us. | |
138 | ||
139 | The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */ | |
140 | ||
141 | struct coff_symfile_info { | |
142 | file_ptr min_lineno_offset; /* Where in file lowest line#s are */ | |
143 | file_ptr max_lineno_offset; /* 1+last byte of line#s in file */ | |
144 | }; | |
145 | ||
146 | ||
1ab3bf1b JG |
147 | static void |
148 | enter_line_range PARAMS ((struct subfile *, unsigned, unsigned, CORE_ADDR, | |
149 | unsigned *)); | |
150 | ||
151 | static void | |
152 | aixcoff_symfile_read PARAMS ((struct sym_fns *, CORE_ADDR, int)); | |
153 | ||
154 | static void | |
155 | free_debugsection PARAMS ((void)); | |
156 | ||
157 | static int | |
158 | init_debugsection PARAMS ((bfd *)); | |
159 | ||
160 | static int | |
161 | init_stringtab PARAMS ((bfd *, long, struct objfile *)); | |
162 | ||
163 | static void | |
164 | aixcoff_symfile_init PARAMS ((struct sym_fns *)); | |
165 | ||
166 | static void | |
167 | aixcoff_new_init PARAMS ((void)); | |
168 | ||
169 | static void | |
170 | dump_minimal_symbols PARAMS ((struct objfile *)); | |
171 | ||
172 | static void | |
173 | dump_symtab_lines PARAMS ((struct symtab *)); | |
174 | ||
175 | static void | |
176 | dump_symtabs PARAMS ((struct symtab *)); | |
177 | ||
178 | static void | |
179 | dump_last_symtab PARAMS ((struct symtab *)); | |
180 | ||
181 | static void | |
182 | dump_blockvector PARAMS ((struct blockvector *)); | |
183 | ||
184 | static void | |
185 | dump_block PARAMS ((struct block *)); | |
186 | ||
187 | static char * | |
188 | dump_addrclass PARAMS ((int)); | |
189 | ||
190 | static char * | |
191 | dump_namespace PARAMS ((int)); | |
192 | ||
193 | static void | |
194 | dump_symbol PARAMS ((struct symbol *)); | |
195 | ||
196 | static void | |
197 | dump_type PARAMS ((struct type *)); | |
198 | ||
199 | static void | |
200 | dump_linetable PARAMS ((struct linetable *)); | |
201 | ||
202 | static void | |
203 | dump_strtbl PARAMS ((void)); | |
204 | ||
205 | static int | |
206 | init_lineno PARAMS ((bfd *, long, int)); | |
207 | ||
208 | static void | |
209 | find_linenos PARAMS ((bfd *, sec_ptr, PTR)); | |
210 | ||
211 | static int | |
212 | read_symbol_lineno PARAMS ((char *, int)); | |
213 | ||
214 | static int | |
215 | read_symbol_nvalue PARAMS ((char *, int)); | |
216 | ||
217 | static struct symbol * | |
218 | process_xcoff_symbol PARAMS ((struct coff_symbol *, struct objfile *)); | |
219 | ||
220 | static void | |
221 | read_xcoff_symtab PARAMS ((struct objfile *, int)); | |
222 | ||
223 | static void | |
224 | enter_line_range PARAMS ((struct subfile *, unsigned, unsigned, CORE_ADDR, | |
225 | unsigned *)); | |
226 | ||
227 | static void | |
228 | add_stab_to_list PARAMS ((char *, struct pending_stabs **)); | |
229 | ||
230 | static void | |
231 | sort_syms PARAMS ((void)); | |
232 | ||
233 | static int | |
234 | compare_symbols PARAMS ((const void *, const void *)); | |
235 | ||
e38e0312 JG |
236 | /* Call sort_syms to sort alphabetically |
237 | the symbols of each block of each symtab. */ | |
238 | ||
239 | static int | |
1ab3bf1b JG |
240 | compare_symbols (s1p, s2p) |
241 | const PTR s1p; | |
242 | const PTR s2p; | |
e38e0312 JG |
243 | { |
244 | /* Names that are less should come first. */ | |
1ab3bf1b JG |
245 | register struct symbol **s1 = (struct symbol **) s1p; |
246 | register struct symbol **s2 = (struct symbol **) s2p; | |
e38e0312 JG |
247 | register int namediff = strcmp (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2)); |
248 | if (namediff != 0) | |
249 | return namediff; | |
250 | ||
251 | /* For symbols of the same name, registers should come first. */ | |
252 | return ((SYMBOL_CLASS (*s2) == LOC_REGISTER) | |
253 | - (SYMBOL_CLASS (*s1) == LOC_REGISTER)); | |
254 | } | |
255 | ||
256 | ||
257 | /* Sort a vector of symbols by their value. */ | |
258 | ||
259 | static void | |
260 | sort_syms () | |
261 | { | |
262 | register struct symtab *s; | |
1ab3bf1b | 263 | register struct objfile *objfile; |
e38e0312 JG |
264 | register int i, nbl; |
265 | register struct blockvector *bv; | |
266 | register struct block *b; | |
267 | ||
1ab3bf1b | 268 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
e38e0312 | 269 | { |
1ab3bf1b JG |
270 | for (s = objfile -> symtabs; s != NULL; s = s -> next) |
271 | { | |
272 | bv = BLOCKVECTOR (s); | |
273 | nbl = BLOCKVECTOR_NBLOCKS (bv); | |
274 | for (i = 0; i < nbl; i++) | |
275 | { | |
276 | b = BLOCKVECTOR_BLOCK (bv, i); | |
277 | if (BLOCK_SHOULD_SORT (b)) | |
278 | { | |
279 | qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b), | |
280 | sizeof (struct symbol *), compare_symbols); | |
281 | } | |
282 | } | |
283 | } | |
e38e0312 | 284 | } |
e38e0312 JG |
285 | } |
286 | ||
287 | ||
288 | /* add a given stab string into given stab vector. */ | |
289 | ||
290 | static void | |
291 | add_stab_to_list (stabname, stabvector) | |
292 | char *stabname; | |
293 | struct pending_stabs **stabvector; | |
294 | { | |
295 | if ( *stabvector == NULL) { | |
296 | *stabvector = (struct pending_stabs *) | |
297 | xmalloc (sizeof (struct pending_stabs) + | |
298 | INITIAL_STABVECTOR_LENGTH * sizeof (char*)); | |
299 | (*stabvector)->count = 0; | |
300 | (*stabvector)->length = INITIAL_STABVECTOR_LENGTH; | |
301 | } | |
302 | else if ((*stabvector)->count >= (*stabvector)->length) { | |
303 | (*stabvector)->length += INITIAL_STABVECTOR_LENGTH; | |
304 | *stabvector = (struct pending_stabs *) | |
1ab3bf1b | 305 | xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) + |
e38e0312 JG |
306 | (*stabvector)->length * sizeof (char*)); |
307 | } | |
308 | (*stabvector)->stab [(*stabvector)->count++] = stabname; | |
309 | } | |
310 | ||
311 | ||
e38e0312 JG |
312 | /* Enter a given range of lines into the line vector. |
313 | can be called in the following two ways: | |
314 | enter_line_range (subfile, beginoffset, endoffset, 0, firstLine) or | |
315 | enter_line_range (subfile, beginoffset, 0, endaddr, firstLine) */ | |
316 | ||
317 | static void | |
318 | enter_line_range (subfile, beginoffset, endoffset, endaddr, firstLine) | |
319 | struct subfile *subfile; /* which sub-file to put line#s in */ | |
320 | unsigned beginoffset, endoffset; /* offsets to line table */ | |
321 | CORE_ADDR endaddr; | |
322 | unsigned *firstLine; | |
323 | { | |
324 | char *pp, *limit; | |
325 | CORE_ADDR addr; | |
326 | struct internal_lineno lptr; | |
327 | unsigned local_linesz = coff_data (symfile_bfd)->local_linesz; | |
328 | ||
329 | pp = &linetab [beginoffset - linetab_offset]; | |
330 | limit = endoffset ? &linetab [endoffset - linetab_offset] | |
331 | : &linetab [linetab_size -1]; | |
332 | ||
333 | while (pp <= limit) { | |
334 | ||
335 | /* Swap and align this lineno entry into lptr. */ | |
336 | bfd_coff_swap_lineno_in (symfile_bfd, pp, &lptr); | |
337 | ||
338 | /* find the address this line represents */ | |
339 | addr = lptr.l_lnno ? | |
340 | lptr.l_addr.l_paddr : read_symbol_nvalue (symtbl, lptr.l_addr.l_symndx); | |
341 | ||
342 | if (endaddr && addr >= endaddr) | |
343 | return; | |
344 | ||
345 | if (lptr.l_lnno == 0) { | |
346 | *firstLine = read_symbol_lineno (symtbl, lptr.l_addr.l_symndx); | |
347 | --(*firstLine); | |
348 | } | |
349 | else | |
350 | record_line (subfile, *firstLine + lptr.l_lnno, addr); | |
351 | ||
352 | pp += local_linesz; | |
353 | } | |
354 | } | |
355 | ||
356 | ||
357 | /* Save the vital information for use when closing off the current file. | |
358 | NAME is the file name the symbols came from, START_ADDR is the first | |
359 | text address for the file, and SIZE is the number of bytes of text. */ | |
360 | ||
361 | #define complete_symtab(name, start_addr) { \ | |
362 | last_source_file = savestring (name, strlen (name)); \ | |
363 | cur_src_start_addr = start_addr; \ | |
364 | } | |
365 | ||
366 | ||
367 | /* Refill the symbol table input buffer | |
368 | and set the variables that control fetching entries from it. | |
369 | Reports an error if no data available. | |
370 | This function can read past the end of the symbol table | |
371 | (into the string table) but this does no harm. */ | |
372 | ||
373 | /* Reading symbol table has to be fast! Keep the followings as macros, rather | |
374 | than functions. */ | |
375 | ||
1ab3bf1b | 376 | #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED) \ |
e38e0312 JG |
377 | { \ |
378 | char *namestr; \ | |
379 | if (ALLOCED) \ | |
380 | namestr = (NAME) + 1; \ | |
381 | else { \ | |
1ab3bf1b | 382 | namestr = obstack_copy0 (&objfile->symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \ |
e38e0312 JG |
383 | (ALLOCED) = 1; \ |
384 | } \ | |
1ab3bf1b | 385 | prim_record_minimal_symbol (namestr, (ADDR), (TYPE)); \ |
e38e0312 JG |
386 | last_recorded_fun = (ADDR); \ |
387 | } | |
388 | ||
389 | ||
390 | ||
391 | /* aixcoff has static blocks marked in `.bs', `.es' pairs. They cannot be | |
392 | nested. At any given time, a symbol can only be in one static block. | |
393 | This is the base address of current static block, zero if non exists. */ | |
394 | ||
395 | static int static_block_base = 0; | |
396 | ||
397 | /* true if space for symbol name has been allocated. */ | |
398 | ||
399 | static int symname_alloced = 0; | |
400 | ||
401 | /* read the whole symbol table of a given bfd. */ | |
402 | ||
1ab3bf1b | 403 | static void |
e38e0312 JG |
404 | read_xcoff_symtab (objfile, nsyms) |
405 | struct objfile *objfile; /* Object file we're reading from */ | |
406 | int nsyms; /* # of symbols */ | |
407 | { | |
408 | bfd *abfd = objfile->obfd; | |
409 | /* char *symtbl; */ /* Raw symbol table base */ | |
410 | char *raw_symbol; /* Pointer into raw seething symbol table */ | |
411 | char *raw_auxptr; /* Pointer to first raw aux entry for sym */ | |
412 | struct internal_syment symbol[1]; | |
413 | union internal_auxent main_aux[1]; | |
414 | struct coff_symbol cs[1]; | |
415 | CORE_ADDR file_start_addr = 0; | |
416 | CORE_ADDR file_end_addr = 0; | |
417 | ||
418 | int next_file_symnum = -1; | |
419 | int just_started = 1; | |
420 | int depth = 0; | |
421 | int val; | |
422 | int fcn_first_line; | |
423 | int fcn_last_line; | |
424 | int fcn_start_addr; | |
425 | long fcn_line_offset; | |
426 | size_t size; | |
427 | ||
428 | /* fcn_cs_saved is global because process_xcoff_symbol needs it. */ | |
429 | union internal_auxent fcn_aux_saved; | |
430 | struct context_stack *new; | |
431 | ||
432 | char *filestring = " _start_ "; /* Name of the current file. */ | |
433 | char *last_seen_csect; | |
434 | int last_recorded_fun = 0; /* last recorded fun. value */ | |
435 | ||
1ab3bf1b JG |
436 | current_objfile = objfile; |
437 | ||
e38e0312 JG |
438 | /* Get the appropriate COFF "constants" related to the file we're handling. */ |
439 | N_TMASK = coff_data (abfd)->local_n_tmask; | |
440 | N_BTSHFT = coff_data (abfd)->local_n_btshft; | |
441 | local_symesz = coff_data (abfd)->local_symesz; | |
442 | ||
443 | last_source_file = 0; | |
444 | last_seen_csect = 0; | |
445 | last_recorded_fun = 0; | |
446 | ||
447 | start_symtab (filestring, (char *)NULL, file_start_addr); | |
448 | symnum = 0; | |
449 | first_object_file_end = 0; | |
450 | ||
451 | /* Allocate space for the entire symbol table at once, and read it | |
452 | all in. The bfd is already positioned at the beginning of | |
453 | the symbol table. */ | |
454 | ||
455 | size = coff_data (abfd)->local_symesz * nsyms; | |
456 | symtbl = xmalloc (size); | |
457 | ||
458 | val = bfd_read (symtbl, size, 1, abfd); | |
459 | if (val != size) | |
460 | perror_with_name ("reading symbol table"); | |
461 | ||
462 | raw_symbol = symtbl; | |
463 | ||
464 | while (symnum < nsyms) { | |
465 | ||
466 | QUIT; /* make this command interruptable. */ | |
467 | ||
468 | /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */ | |
469 | /* read one symbol into `cs' structure. After processing the whole symbol | |
470 | table, only string table will be kept in memory, symbol table and debug | |
471 | section of aixcoff will be freed. Thus we can mark symbols with names | |
472 | in string table as `alloced'. */ | |
473 | { | |
474 | int ii; | |
475 | ||
476 | /* Swap and align the symbol into a reasonable C structure. */ | |
477 | bfd_coff_swap_sym_in (abfd, raw_symbol, symbol); | |
478 | ||
479 | cs->c_symnum = symnum; | |
480 | cs->c_nsyms = symbol->n_numaux; | |
481 | if (symbol->n_zeroes) { | |
482 | symname_alloced = 0; | |
483 | /* We must use the original, unswapped, name here so the name field | |
484 | pointed to by cs->c_name will persist throughout xcoffread. If | |
485 | we use the new field, it gets overwritten for each symbol. */ | |
486 | cs->c_name = ((struct external_syment *)raw_symbol)->e.e_name; | |
487 | } else if (symbol->n_sclass & 0x80) { | |
488 | cs->c_name = debugsec + symbol->n_offset; | |
489 | symname_alloced = 0; | |
490 | } else { /* in string table */ | |
491 | cs->c_name = strtbl + (int)symbol->n_offset; | |
492 | symname_alloced = 1; | |
493 | } | |
494 | cs->c_value = symbol->n_value; | |
495 | cs->c_sclass = symbol->n_sclass & 0xff; | |
496 | cs->c_secnum = symbol->n_scnum; | |
497 | cs->c_type = (unsigned)symbol->n_type; | |
498 | ||
499 | raw_symbol += coff_data (abfd)->local_symesz; | |
500 | ++symnum; | |
501 | ||
502 | raw_auxptr = raw_symbol; /* Save addr of first aux entry */ | |
503 | ||
504 | /* Skip all the auxents associated with this symbol. */ | |
505 | for (ii = symbol->n_numaux; ii; --ii ) { | |
506 | raw_symbol += coff_data (abfd)->local_auxesz; | |
507 | ++symnum; | |
508 | } | |
509 | } | |
510 | ||
511 | /* if symbol name starts with ".$" or "$", ignore it. */ | |
512 | if (cs->c_name[0] == '$' || (cs->c_name[1] == '$' && cs->c_name[0] == '.')) | |
513 | continue; | |
514 | ||
515 | if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE) { | |
516 | if (last_source_file) | |
517 | end_symtab (cur_src_end_addr, 1, 1, objfile); | |
518 | ||
519 | start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0); | |
520 | cur_src_end_addr = first_object_file_end; | |
521 | /* done with all files, everything from here on is globals */ | |
522 | } | |
523 | ||
524 | /* if explicitly specified as a function, treat is as one. */ | |
525 | if (ISFCN(cs->c_type) && cs->c_sclass != C_TPDEF) { | |
526 | bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, | |
527 | main_aux); | |
528 | goto function_entry_point; | |
529 | } | |
530 | ||
531 | if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT) && cs->c_nsyms == 1) | |
532 | { | |
533 | /* dealing with a symbol with a csect entry. */ | |
534 | ||
535 | # define CSECT(PP) ((PP)->x_csect) | |
536 | # define CSECT_LEN(PP) (CSECT(PP).x_scnlen) | |
537 | # define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp)) | |
538 | # define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp)) | |
539 | # define CSECT_SCLAS(PP) (CSECT(PP).x_smclas) | |
540 | ||
541 | /* Convert the auxent to something we can access. */ | |
542 | bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, | |
543 | main_aux); | |
544 | ||
545 | switch (CSECT_SMTYP (main_aux)) { | |
546 | ||
547 | case XTY_ER : | |
548 | continue; /* ignore all external references. */ | |
549 | ||
550 | case XTY_SD : /* a section description. */ | |
551 | { | |
552 | switch (CSECT_SCLAS (main_aux)) { | |
553 | ||
554 | case XMC_PR : /* a `.text' csect. */ | |
555 | { | |
556 | ||
557 | /* A program csect is seen. | |
558 | ||
559 | We have to allocate one symbol table for each program csect. Normally | |
560 | gdb prefers one symtab for each compilation unit (CU). In case of AIX, one | |
561 | CU might include more than one prog csect, and they don't have to be | |
562 | adjacent in terms of the space they occupy in memory. Thus, one single | |
563 | CU might get fragmented in the memory and gdb's file start and end address | |
564 | approach does not work! */ | |
565 | ||
566 | if (last_seen_csect) { | |
567 | complete_symtab (filestring, file_start_addr); | |
568 | cur_src_end_addr = file_end_addr; | |
569 | end_symtab (file_end_addr, 1, 1, objfile); | |
570 | start_symtab ((char *)NULL, (char *)NULL, (CORE_ADDR)0); | |
571 | } | |
572 | ||
573 | /* If this is the very first csect seen, basically `__start'. */ | |
574 | if (just_started) { | |
575 | first_object_file_end = cs->c_value + CSECT_LEN (main_aux); | |
576 | just_started = 0; | |
577 | } | |
578 | ||
579 | file_start_addr = cs->c_value; | |
580 | file_end_addr = cs->c_value + CSECT_LEN (main_aux); | |
581 | ||
582 | if (cs->c_name && cs->c_name[0] == '.') { | |
583 | last_seen_csect = cs->c_name; | |
1ab3bf1b | 584 | RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_text, symname_alloced); |
e38e0312 JG |
585 | } |
586 | } | |
587 | continue; | |
588 | ||
589 | case XMC_RW : | |
590 | break; | |
591 | ||
592 | /* If the section is not a data description, ignore it. Note that | |
593 | uninitialized data will show up as XTY_CM/XMC_RW pair. */ | |
594 | ||
595 | case XMC_TC0: | |
596 | #ifdef XCOFF_ADD_TOC_TO_LOADINFO | |
597 | XCOFF_ADD_TOC_TO_LOADINFO (cs->c_value); | |
598 | #endif | |
599 | /* fall down to default case. */ | |
600 | ||
601 | case XMC_TC : /* ignore toc entries */ | |
602 | default : /* any other XMC_XXX */ | |
603 | continue; | |
604 | } | |
605 | } | |
606 | break; /* switch CSECT_SCLAS() */ | |
607 | ||
608 | case XTY_LD : | |
609 | ||
610 | /* a function entry point. */ | |
611 | if (CSECT_SCLAS (main_aux) == XMC_PR) { | |
612 | ||
613 | function_entry_point: | |
614 | if (cs->c_value != last_recorded_fun) | |
1ab3bf1b | 615 | RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_text, |
e38e0312 JG |
616 | symname_alloced); |
617 | ||
618 | fcn_line_offset = main_aux->x_sym.x_fcnary.x_fcn.x_lnnoptr; | |
619 | fcn_start_addr = cs->c_value; | |
620 | ||
621 | /* save the function header info, which will be used | |
622 | when `.bf' is seen. */ | |
623 | fcn_cs_saved = *cs; | |
624 | fcn_aux_saved = *main_aux; | |
625 | continue; | |
626 | } | |
627 | ||
628 | /* shared library function entry point. */ | |
629 | else if (CSECT_SCLAS (main_aux) == XMC_GL) { | |
630 | if (last_recorded_fun != cs->c_value) | |
1ab3bf1b | 631 | RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_text, |
e38e0312 JG |
632 | symname_alloced); |
633 | continue; | |
634 | } | |
635 | break; | |
636 | ||
637 | default : /* all other XTY_XXXs */ | |
638 | break; | |
639 | } /* switch CSECT_SMTYP() */ | |
640 | } | |
641 | ||
642 | switch (cs->c_sclass) { | |
643 | ||
644 | case C_FILE: | |
645 | ||
646 | /* c_value field contains symnum of next .file entry in table | |
647 | or symnum of first global after last .file. */ | |
648 | ||
649 | next_file_symnum = cs->c_value; | |
650 | ||
651 | /* complete symbol table for last object file containing | |
652 | debugging information. */ | |
653 | ||
654 | /* Whether or not there was a csect in the previous file, we have | |
655 | to call `end_symtab' and `start_symtab' to reset type_vector, | |
656 | line_vector, etc. structures. */ | |
657 | complete_symtab (filestring, file_start_addr); | |
658 | cur_src_end_addr = file_end_addr; | |
659 | end_symtab (file_end_addr, 1, 1, objfile); | |
660 | start_symtab (cs->c_name, (char *)NULL, (CORE_ADDR)0); | |
661 | last_seen_csect = 0; | |
662 | ||
663 | /* reset file start and end addresses. A compilation unit with no text | |
664 | (only data) should have zero file boundaries. */ | |
665 | file_start_addr = file_end_addr = 0; | |
666 | ||
667 | filestring = cs->c_name; | |
668 | break; | |
669 | ||
670 | ||
671 | case C_FCN: | |
672 | if (strcmp (cs->c_name, ".bf") == 0) { | |
673 | ||
674 | bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, | |
675 | main_aux); | |
676 | ||
677 | within_function = 1; | |
678 | ||
679 | /* value contains address of first non-init type code */ | |
680 | /* main_aux.x_sym.x_misc.x_lnsz.x_lnno | |
681 | contains line number of '{' } */ | |
682 | fcn_first_line = main_aux->x_sym.x_misc.x_lnsz.x_lnno; | |
683 | ||
684 | /* Linenos are now processed on a file-by-file, not fn-by-fn, basis. | |
685 | Metin did it, I'm not sure why. FIXME. -- gnu@cygnus.com */ | |
686 | /* mark_first_line (fcn_line_offset, cs->c_symnum); */ | |
687 | ||
688 | new = push_context (0, fcn_start_addr); | |
1ab3bf1b | 689 | new->name = process_xcoff_symbol (&fcn_cs_saved, objfile); |
e38e0312 JG |
690 | } |
691 | else if (strcmp (cs->c_name, ".ef") == 0) { | |
692 | ||
693 | bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, | |
694 | main_aux); | |
695 | ||
696 | /* the value of .ef is the address of epilogue code; | |
697 | not useful for gdb */ | |
698 | /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno | |
699 | contains number of lines to '}' */ | |
700 | ||
701 | fcn_last_line = main_aux->x_sym.x_misc.x_lnsz.x_lnno; | |
702 | #if 0 | |
703 | enter_linenos (fcn_line_offset, fcn_first_line, | |
704 | fcn_first_line + fcn_last_line); | |
705 | #endif | |
706 | ||
707 | new = pop_context (); | |
708 | if (context_stack_depth != 0) | |
709 | error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.", | |
710 | symnum); | |
711 | ||
712 | finish_block (new->name, &local_symbols, new->old_blocks, | |
713 | new->start_addr, | |
714 | fcn_cs_saved.c_value + | |
1ab3bf1b | 715 | fcn_aux_saved.x_sym.x_misc.x_fsize, objfile); |
e38e0312 JG |
716 | within_function = 0; |
717 | } | |
718 | break; | |
719 | ||
720 | case C_BSTAT : /* begin static block */ | |
721 | static_block_base = read_symbol_nvalue (symtbl, cs->c_value); | |
722 | break; | |
723 | ||
724 | case C_ESTAT : /* end of static block */ | |
725 | static_block_base = 0; | |
726 | break; | |
727 | ||
728 | case C_ARG : /* These are not implemented. */ | |
729 | case C_REGPARM : | |
730 | case C_TPDEF : | |
731 | case C_STRTAG : | |
732 | case C_UNTAG : | |
733 | case C_ENTAG : | |
734 | printf ("ERROR: Unimplemented storage class: %d.\n", cs->c_sclass); | |
735 | break; | |
736 | ||
737 | case C_HIDEXT : /* ignore these.. */ | |
738 | case C_LABEL : | |
739 | case C_NULL : | |
740 | break; | |
741 | ||
742 | case C_BINCL : /* beginning of include file */ | |
743 | push_subfile (); | |
744 | start_subfile (cs->c_name, (char *)0); | |
745 | fcn_first_line = cs->c_value; /* Offset to first lineno of file */ | |
746 | break; | |
747 | ||
748 | case C_EINCL : /* end of include file */ | |
749 | fcn_last_line = cs->c_value; /* Offset to last line number */ | |
750 | { long dummy = 0; | |
751 | enter_line_range (current_subfile, fcn_first_line, cs->c_value, 0, | |
1ab3bf1b | 752 | (unsigned *) &dummy); |
e38e0312 JG |
753 | } |
754 | start_subfile (pop_subfile (), (char *)0); | |
755 | break; | |
756 | ||
757 | case C_BLOCK : | |
758 | if (strcmp (cs->c_name, ".bb") == 0) { | |
759 | depth++; | |
760 | new = push_context (depth, cs->c_value); | |
761 | } | |
762 | else if (strcmp (cs->c_name, ".eb") == 0) { | |
763 | new = pop_context (); | |
764 | if (depth != new->depth) | |
765 | error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.", | |
766 | symnum); | |
767 | ||
768 | depth--; | |
769 | if (local_symbols && context_stack_depth > 0) { | |
770 | /* Make a block for the local symbols within. */ | |
771 | finish_block (new->name, &local_symbols, new->old_blocks, | |
1ab3bf1b | 772 | new->start_addr, cs->c_value, objfile); |
e38e0312 JG |
773 | } |
774 | local_symbols = new->locals; | |
775 | } | |
776 | break; | |
777 | ||
778 | default : | |
1ab3bf1b | 779 | (void) process_xcoff_symbol (cs, objfile); |
e38e0312 JG |
780 | break; |
781 | } | |
782 | ||
783 | } /* while */ | |
784 | ||
785 | if (last_source_file) | |
786 | end_symtab (cur_src_end_addr, 1, 1, objfile); | |
787 | ||
788 | free (symtbl); | |
1ab3bf1b | 789 | current_objfile = NULL; |
e38e0312 JG |
790 | } |
791 | ||
792 | #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \ | |
793 | (SYMBOL2) = (struct symbol *) \ | |
1ab3bf1b | 794 | obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \ |
e38e0312 JG |
795 | *(SYMBOL2) = *(SYMBOL1); |
796 | ||
797 | ||
798 | #define SYMNAME_ALLOC(NAME, ALLOCED) \ | |
1ab3bf1b | 799 | (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME)); |
e38e0312 JG |
800 | |
801 | ||
802 | ||
803 | /* process one xcoff symbol. */ | |
804 | ||
805 | static struct symbol * | |
1ab3bf1b | 806 | process_xcoff_symbol (cs, objfile) |
e38e0312 | 807 | register struct coff_symbol *cs; |
1ab3bf1b | 808 | struct objfile *objfile; |
e38e0312 JG |
809 | { |
810 | struct symbol onesymbol; | |
811 | register struct symbol *sym = &onesymbol; | |
812 | struct symbol *sym2 = NULL; | |
813 | struct type *ttype; | |
814 | char *name, *pp, *qq; | |
815 | ||
816 | name = cs->c_name; | |
817 | if (name[0] == '.') | |
818 | ++name; | |
819 | ||
820 | bzero (sym, sizeof (struct symbol)); | |
821 | ||
822 | /* default assumptions */ | |
823 | SYMBOL_VALUE (sym) = cs->c_value; | |
824 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
825 | ||
826 | if (ISFCN (cs->c_type)) { | |
827 | ||
828 | /* At this point, we don't know the type of the function and assume it | |
829 | is int. This will be patched with the type from its stab entry later | |
830 | on in patch_block_stabs () */ | |
831 | ||
832 | SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced); | |
1ab3bf1b | 833 | SYMBOL_TYPE (sym) = lookup_function_type (lookup_fundamental_type (current_objfile, FT_INTEGER)); |
e38e0312 JG |
834 | |
835 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
836 | SYMBOL_DUP (sym, sym2); | |
837 | ||
838 | if (cs->c_sclass == C_EXT) | |
839 | add_symbol_to_list (sym2, &global_symbols); | |
840 | else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT) | |
841 | add_symbol_to_list (sym2, &file_symbols); | |
842 | } | |
843 | ||
844 | else { | |
845 | ||
846 | /* in case we can't figure out the type, default is `int'. */ | |
1ab3bf1b | 847 | SYMBOL_TYPE (sym) = lookup_fundamental_type (current_objfile, FT_INTEGER); |
e38e0312 JG |
848 | |
849 | switch (cs->c_sclass) | |
850 | { | |
851 | case C_FUN: | |
852 | if (fcn_cs_saved.c_sclass == C_EXT) | |
853 | add_stab_to_list (name, &global_stabs); | |
854 | else | |
855 | add_stab_to_list (name, &file_stabs); | |
856 | break; | |
857 | ||
858 | case C_DECL: /* a type decleration?? */ | |
1ab3bf1b | 859 | qq = (char*) strchr (name, ':'); |
e38e0312 JG |
860 | if (!qq) /* skip if there is no ':' */ |
861 | return NULL; | |
862 | ||
863 | pp = qq + 2; | |
1ab3bf1b | 864 | ttype = SYMBOL_TYPE (sym) = read_type (&pp, objfile); |
e38e0312 JG |
865 | |
866 | /* read_type() will return null if type (or tag) definition was | |
867 | unnnecessarily duplicated. Also, if the symbol doesn't have a name, | |
868 | there is no need to keep it in symbol table. */ | |
869 | ||
870 | if (!ttype || name == qq) | |
871 | return NULL; | |
872 | ||
873 | if (qq[1] == 'T') | |
874 | SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE; | |
875 | else if (qq[1] == 't') | |
876 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
877 | else { | |
878 | printf ("ERROR: Unrecognized stab string.\n"); | |
879 | return NULL; | |
880 | } | |
881 | ||
882 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
1ab3bf1b | 883 | SYMBOL_NAME (sym) = obsavestring (name, qq-name, &objfile->symbol_obstack); |
e38e0312 JG |
884 | |
885 | if (SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE) | |
886 | TYPE_NAME (ttype) = concat ( | |
887 | TYPE_CODE (ttype) == TYPE_CODE_UNION ? "union " : | |
888 | TYPE_CODE (ttype) == TYPE_CODE_STRUCT? "struct " : "enum ", | |
58ae87f6 | 889 | SYMBOL_NAME (sym), NULL); |
e38e0312 JG |
890 | |
891 | else if (!TYPE_NAME (ttype)) /* else, regular typedef. */ | |
892 | TYPE_NAME (ttype) = SYMBOL_NAME (sym); | |
893 | ||
894 | SYMBOL_DUP (sym, sym2); | |
895 | add_symbol_to_list | |
896 | (sym2, within_function ? &local_symbols : &file_symbols); | |
897 | break; | |
898 | ||
899 | case C_GSYM: | |
900 | add_stab_to_list (name, &global_stabs); | |
901 | break; | |
902 | ||
903 | case C_PSYM: | |
1ab3bf1b | 904 | if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL) |
e38e0312 | 905 | return NULL; |
1ab3bf1b | 906 | SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack); |
e38e0312 JG |
907 | SYMBOL_CLASS (sym) = LOC_ARG; |
908 | pp += 2; | |
1ab3bf1b | 909 | SYMBOL_TYPE (sym) = read_type (&pp, objfile); |
e38e0312 JG |
910 | SYMBOL_DUP (sym, sym2); |
911 | add_symbol_to_list (sym2, &local_symbols); | |
912 | break; | |
913 | ||
914 | case C_STSYM: | |
1ab3bf1b | 915 | if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL) |
e38e0312 | 916 | return NULL; |
1ab3bf1b | 917 | SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack); |
e38e0312 JG |
918 | SYMBOL_CLASS (sym) = LOC_STATIC; |
919 | SYMBOL_VALUE (sym) += static_block_base; | |
920 | pp += 2; | |
1ab3bf1b | 921 | SYMBOL_TYPE (sym) = read_type (&pp, objfile); |
e38e0312 JG |
922 | SYMBOL_DUP (sym, sym2); |
923 | add_symbol_to_list | |
924 | (sym2, within_function ? &local_symbols : &file_symbols); | |
925 | break; | |
926 | ||
927 | case C_LSYM: | |
1ab3bf1b | 928 | if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL) |
e38e0312 | 929 | return NULL; |
1ab3bf1b | 930 | SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack); |
e38e0312 JG |
931 | SYMBOL_CLASS (sym) = LOC_LOCAL; |
932 | pp += 1; | |
1ab3bf1b | 933 | SYMBOL_TYPE (sym) = read_type (&pp, objfile); |
e38e0312 JG |
934 | SYMBOL_DUP (sym, sym2); |
935 | add_symbol_to_list (sym2, &local_symbols); | |
936 | break; | |
937 | ||
938 | case C_AUTO: | |
939 | SYMBOL_CLASS (sym) = LOC_LOCAL; | |
940 | SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced); | |
941 | SYMBOL_DUP (sym, sym2); | |
942 | add_symbol_to_list (sym2, &local_symbols); | |
943 | break; | |
944 | ||
945 | case C_EXT: | |
946 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
947 | SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced); | |
948 | SYMBOL_DUP (sym, sym2); | |
949 | add_symbol_to_list (sym2, &global_symbols); | |
950 | break; | |
951 | ||
952 | case C_STAT: | |
953 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
954 | SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced); | |
955 | SYMBOL_DUP (sym, sym2); | |
956 | add_symbol_to_list | |
957 | (sym2, within_function ? &local_symbols : &file_symbols); | |
958 | break; | |
959 | ||
960 | case C_REG: | |
961 | printf ("ERROR! C_REG is not fully implemented!\n"); | |
962 | SYMBOL_CLASS (sym) = LOC_REGISTER; | |
963 | SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced); | |
964 | SYMBOL_DUP (sym, sym2); | |
965 | add_symbol_to_list (sym2, &local_symbols); | |
966 | break; | |
967 | ||
968 | case C_RSYM: | |
1ab3bf1b | 969 | pp = (char*) strchr (name, ':'); |
e38e0312 JG |
970 | SYMBOL_CLASS (sym) = LOC_REGISTER; |
971 | SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (cs->c_value); | |
972 | if (pp) { | |
1ab3bf1b | 973 | SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack); |
e38e0312 JG |
974 | pp += 2; |
975 | if (*pp) | |
1ab3bf1b | 976 | SYMBOL_TYPE (sym) = read_type (&pp, objfile); |
e38e0312 JG |
977 | } |
978 | else | |
979 | /* else this is not a stab entry, suppose the type is either | |
980 | `int' or `float', depending on the register class. */ | |
981 | ||
1ab3bf1b JG |
982 | SYMBOL_TYPE (sym) = (SYMBOL_VALUE (sym) < 32) |
983 | ? lookup_fundamental_type (current_objfile, FT_INTEGER) | |
984 | : lookup_fundamental_type (current_objfile, FT_FLOAT); | |
e38e0312 JG |
985 | |
986 | SYMBOL_DUP (sym, sym2); | |
987 | add_symbol_to_list (sym2, &local_symbols); | |
988 | break; | |
989 | ||
990 | default : | |
991 | printf ("ERROR: Unexpected storage class: %d.\n", cs->c_sclass); | |
992 | return NULL; | |
993 | } | |
994 | } | |
995 | return sym2; | |
996 | } | |
997 | ||
998 | ||
999 | static int | |
1000 | read_symbol_nvalue (symtable, symno) | |
1001 | char *symtable; | |
1002 | int symno; | |
1003 | { | |
1004 | struct internal_syment symbol[1]; | |
1005 | ||
1006 | bfd_coff_swap_sym_in (symfile_bfd, symtable + (symno*local_symesz), symbol); | |
1007 | return symbol->n_value; | |
1008 | } | |
1009 | ||
1010 | ||
1011 | static int | |
1012 | read_symbol_lineno (symtable, symno) | |
1013 | char *symtable; | |
1014 | int symno; | |
1015 | { | |
1016 | struct internal_syment symbol[1]; | |
1017 | union internal_auxent main_aux[1]; | |
1018 | ||
1019 | int ii; | |
1020 | ||
1021 | for (ii = 0; ii < 50; ii++) { | |
1022 | bfd_coff_swap_sym_in (symfile_bfd, | |
1023 | symtable + (symno*local_symesz), symbol); | |
1024 | if (symbol->n_sclass == C_FCN && 0 == strcmp (symbol->n_name, ".bf")) | |
1025 | goto gotit; | |
6b5b330b | 1026 | symno += symbol->n_numaux+1; |
e38e0312 JG |
1027 | } |
1028 | ||
1029 | printf ("GDB Error: `.bf' not found.\n"); | |
1030 | return 0; | |
1031 | ||
1032 | gotit: | |
1033 | /* take aux entry and return its lineno */ | |
1034 | symno++; | |
1035 | bfd_coff_swap_aux_in (symfile_bfd, symtable+(symno*local_symesz), | |
1036 | symbol->n_type, symbol->n_sclass, main_aux); | |
1037 | ||
1038 | return main_aux->x_sym.x_misc.x_lnsz.x_lnno; | |
1039 | } | |
1040 | ||
1041 | /* Support for line number handling */ | |
1042 | ||
1043 | /* This function is called for every section; it finds the outer limits | |
1044 | * of the line table (minimum and maximum file offset) so that the | |
1045 | * mainline code can read the whole thing for efficiency. | |
1046 | */ | |
1047 | static void | |
1048 | find_linenos(abfd, asect, vpinfo) | |
1049 | bfd *abfd; | |
1050 | sec_ptr asect; | |
1ab3bf1b | 1051 | PTR vpinfo; |
e38e0312 JG |
1052 | { |
1053 | struct coff_symfile_info *info; | |
1054 | int size, count; | |
1055 | file_ptr offset, maxoff; | |
1056 | ||
1057 | count = asect->lineno_count; | |
1058 | ||
1059 | if (count == 0) | |
1060 | return; | |
1061 | ||
1062 | size = count * coff_data (symfile_bfd)->local_linesz; | |
1063 | info = (struct coff_symfile_info *)vpinfo; | |
1064 | offset = asect->line_filepos; | |
1065 | maxoff = offset + size; | |
1066 | ||
1067 | if (offset < info->min_lineno_offset || info->min_lineno_offset == 0) | |
1068 | info->min_lineno_offset = offset; | |
1069 | ||
1070 | if (maxoff > info->max_lineno_offset) | |
1071 | info->max_lineno_offset = maxoff; | |
1072 | } | |
1073 | ||
1074 | ||
1075 | /* Read in all the line numbers for fast lookups later. Leave them in | |
1076 | external (unswapped) format in memory; we'll swap them as we enter | |
1077 | them into GDB's data structures. */ | |
1078 | ||
1079 | static int | |
1080 | init_lineno (abfd, offset, size) | |
1081 | bfd *abfd; | |
1082 | long offset; | |
1083 | int size; | |
1084 | { | |
1085 | int val; | |
1086 | ||
1087 | if (bfd_seek(abfd, offset, 0) < 0) | |
1088 | return -1; | |
1089 | ||
1090 | linetab = (char *) xmalloc(size); | |
1091 | ||
1092 | val = bfd_read(linetab, 1, size, abfd); | |
1093 | if (val != size) | |
1094 | return -1; | |
1095 | ||
1096 | linetab_offset = offset; | |
1097 | linetab_size = size; | |
1ab3bf1b | 1098 | make_cleanup (free, linetab); /* Be sure it gets de-allocated. */ |
e38e0312 JG |
1099 | return 0; |
1100 | } | |
1101 | ||
1102 | ||
1ab3bf1b | 1103 | static void |
e38e0312 JG |
1104 | dump_strtbl () |
1105 | { | |
1106 | int ii; | |
1107 | printf ("===STRING TABLE DUMP...\n\n"); | |
1108 | for ( ii=0; ii < strtbl_len; ++ii ) | |
1109 | printf ("%c", isprint (*(strtbl+ii)) ? *(strtbl+ii) : ' '); | |
1110 | printf ("\n"); | |
1111 | } | |
1112 | ||
1ab3bf1b | 1113 | static void |
e38e0312 JG |
1114 | dump_linetable (ltb) |
1115 | struct linetable *ltb; | |
1116 | { | |
1117 | int ii; | |
1118 | for (ii=0; ii < ltb->nitems; ++ii) | |
1119 | printf ("line: %d, addr: 0x%x\n", ltb->item[ii].line, ltb->item[ii].pc); | |
1120 | } | |
1121 | ||
1ab3bf1b | 1122 | static void |
e38e0312 JG |
1123 | dump_type (typeP) |
1124 | struct type *typeP; | |
1125 | { | |
1126 | printf ("0x%x: name: %s\n", typeP, typeP->name ? typeP->name : "(nil)"); | |
1127 | } | |
1128 | ||
1ab3bf1b | 1129 | static void |
e38e0312 JG |
1130 | dump_symbol (pp) |
1131 | struct symbol *pp; | |
1132 | { | |
1133 | printf (" sym: %s\t%s,\t%s\ttype: 0x%x, val: 0x%x end: 0x%x\n", | |
1134 | pp->name, dump_namespace (pp->namespace), | |
1135 | dump_addrclass (pp->class), pp->type, | |
1136 | SYMBOL_CLASS(pp) == LOC_BLOCK ? BLOCK_START(SYMBOL_BLOCK_VALUE(pp)) | |
1137 | : pp->value.value, | |
1138 | SYMBOL_CLASS(pp) == LOC_BLOCK ? BLOCK_END(SYMBOL_BLOCK_VALUE(pp)) : 0); | |
1139 | } | |
1140 | ||
1ab3bf1b | 1141 | static char * |
e38e0312 JG |
1142 | dump_namespace (ns) |
1143 | int ns; | |
1144 | { | |
1145 | static char *ns_name [] = { | |
1146 | "UNDEF_NS", "VAR_NS", "STRUCT_NS", "LABEL_NS"}; | |
1147 | ||
1148 | switch (ns) { | |
1149 | case UNDEF_NAMESPACE: | |
1150 | case VAR_NAMESPACE: | |
1151 | case STRUCT_NAMESPACE: | |
1152 | case LABEL_NAMESPACE: | |
1153 | return ns_name[ns]; | |
1154 | } | |
1155 | ||
1156 | return "***ERROR***"; | |
1157 | } | |
1158 | ||
1ab3bf1b | 1159 | static char * |
e38e0312 JG |
1160 | dump_addrclass (ac) |
1161 | int ac; /* address class */ | |
1162 | { | |
1163 | static char *ac_name [] = { | |
1164 | "LOC_UNDEF", | |
1165 | "LOC_CONST", | |
1166 | "LOC_STATIC", | |
1167 | "LOC_REGISTER", | |
1168 | "LOC_ARG", | |
1169 | "LOC_REF_ARG", | |
1170 | "LOC_REGPARM", | |
1171 | "LOC_LOCAL", | |
1172 | "LOC_TYPEDEF", | |
1173 | "LOC_LABEL", | |
1174 | "LOC_BLOCK", | |
1175 | "LOC_CONST_BYTES", | |
1176 | "LOC_LOCAL_ARG", | |
1177 | }; | |
1178 | switch (ac) { | |
1179 | case LOC_UNDEF: | |
1180 | case LOC_CONST: | |
1181 | case LOC_STATIC: | |
1182 | case LOC_REGISTER: | |
1183 | case LOC_ARG: | |
1184 | case LOC_REF_ARG: | |
1185 | case LOC_REGPARM: | |
1186 | case LOC_LOCAL: | |
1187 | case LOC_TYPEDEF: | |
1188 | case LOC_LABEL: | |
1189 | case LOC_BLOCK: | |
1190 | case LOC_CONST_BYTES: | |
1191 | case LOC_LOCAL_ARG: | |
1192 | return ac_name [ac]; | |
1193 | } | |
1194 | return "***ERROR***"; | |
1195 | } | |
1196 | ||
1ab3bf1b | 1197 | static void |
e38e0312 JG |
1198 | dump_block (pp) |
1199 | struct block *pp; | |
1200 | { | |
1201 | int ii; | |
1202 | printf ("BLOCK..: start: 0x%x, end: 0x%x\n", pp->startaddr, pp->endaddr); | |
1203 | for (ii=0; ii < pp->nsyms; ++ii) | |
1204 | dump_symbol (pp->sym[ii]); | |
1205 | } | |
1206 | ||
1ab3bf1b | 1207 | static void |
e38e0312 JG |
1208 | dump_blockvector (pp) |
1209 | struct blockvector *pp; | |
1210 | { | |
1211 | int ii; | |
1212 | for (ii=0; ii < pp->nblocks; ++ii) | |
1213 | dump_block (pp->block [ii]); | |
1214 | } | |
1215 | ||
1ab3bf1b | 1216 | static void |
e38e0312 JG |
1217 | dump_last_symtab (pp) |
1218 | struct symtab *pp; | |
1219 | { | |
1220 | for ( ; pp; pp = pp->next) { | |
1221 | if ( pp->next == 0 ) { | |
1222 | printf ("SYMTAB NAME: %s\n", pp->filename); | |
1223 | dump_blockvector (pp->blockvector); | |
1224 | } | |
1225 | } | |
1226 | } | |
1227 | ||
1ab3bf1b | 1228 | static void |
e38e0312 JG |
1229 | dump_symtabs (pp) |
1230 | struct symtab *pp; | |
1231 | { | |
1232 | for ( ; pp; pp = pp->next) { | |
1233 | printf ("SYMTAB NAME: %s\n", pp->filename ? pp->filename : "(nil)"); | |
1234 | /* if (pp->linetable) | |
1235 | dump_linetable (pp->linetable); */ | |
1236 | dump_blockvector (pp->blockvector); | |
1237 | } | |
1238 | } | |
1239 | ||
1ab3bf1b | 1240 | static void |
e38e0312 JG |
1241 | dump_symtab_lines (pp) |
1242 | struct symtab *pp; | |
1243 | { | |
1244 | for ( ; pp; pp = pp->next) { | |
1245 | printf ("SYMTAB NAME: %s\n", pp->filename ? pp->filename : "(nil)"); | |
1246 | if (pp->linetable) | |
1247 | dump_linetable (pp->linetable); | |
1248 | /* dump_blockvector (pp->blockvector); */ | |
1249 | } | |
1250 | } | |
1251 | ||
1ab3bf1b JG |
1252 | static void |
1253 | dump_minimal_symbols (objfile) | |
1254 | struct objfile *objfile; | |
e38e0312 | 1255 | { |
1ab3bf1b JG |
1256 | struct minimal_symbol *msymbol; |
1257 | ||
1258 | for (msymbol = objfile -> msymbols; msymbol -> name != NULL; msymbol++) | |
1259 | { | |
1260 | printf ("name: %s, addr: 0x%x\n", msymbol -> name, msymbol -> address); | |
1261 | } | |
e38e0312 JG |
1262 | } |
1263 | ||
1264 | ||
1265 | /* dbx allows the text of a symbol name to be continued into the | |
1266 | next symbol name! When such a continuation is encountered | |
1267 | (a \ at the end of the text of a name) | |
1268 | call this function to get the continuation. */ | |
1269 | /* So far, I haven't seen this happenning xlc output. I doubt we'll need this | |
1270 | for aixcoff. */ | |
1271 | ||
1d4c28c5 | 1272 | #undef next_symbol_text |
e38e0312 JG |
1273 | #define next_symbol_text() \ |
1274 | printf ("Gdb Error: symbol names on multiple lines not implemented.\n") | |
1275 | ||
1276 | ||
1277 | /* xlc/dbx combination uses a set of builtin types, starting from -1. return | |
1278 | the proper type node fora given builtin type #. */ | |
1279 | ||
1280 | struct type * | |
1281 | builtin_type (pp) | |
1282 | char **pp; | |
1283 | { | |
1284 | int typenums[2]; | |
1285 | ||
1286 | if (**pp != '-') { | |
1287 | printf ("ERROR!, unknown built-in type!\n"); | |
1288 | return NULL; | |
1289 | } | |
1290 | *pp += 1; | |
1291 | read_type_number (pp, typenums); | |
1292 | ||
1293 | /* default types are defined in dbxstclass.h. */ | |
1294 | switch ( typenums[1] ) { | |
1295 | case 1: | |
1ab3bf1b | 1296 | return lookup_fundamental_type (current_objfile, FT_INTEGER); |
e38e0312 | 1297 | case 2: |
1ab3bf1b | 1298 | return lookup_fundamental_type (current_objfile, FT_CHAR); |
e38e0312 | 1299 | case 3: |
1ab3bf1b | 1300 | return lookup_fundamental_type (current_objfile, FT_SHORT); |
e38e0312 | 1301 | case 4: |
1ab3bf1b | 1302 | return lookup_fundamental_type (current_objfile, FT_LONG); |
e38e0312 | 1303 | case 5: |
1ab3bf1b | 1304 | return lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR); |
e38e0312 | 1305 | case 6: |
1ab3bf1b | 1306 | return lookup_fundamental_type (current_objfile, FT_SIGNED_CHAR); |
e38e0312 | 1307 | case 7: |
1ab3bf1b | 1308 | return lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT); |
e38e0312 | 1309 | case 8: |
1ab3bf1b | 1310 | return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER); |
e38e0312 | 1311 | case 9: |
1ab3bf1b | 1312 | return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER); |
e38e0312 | 1313 | case 10: |
1ab3bf1b | 1314 | return lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG); |
e38e0312 | 1315 | case 11: |
1ab3bf1b | 1316 | return lookup_fundamental_type (current_objfile, FT_VOID); |
e38e0312 | 1317 | case 12: |
1ab3bf1b | 1318 | return lookup_fundamental_type (current_objfile, FT_FLOAT); |
e38e0312 | 1319 | case 13: |
1ab3bf1b | 1320 | return lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT); |
e38e0312 | 1321 | case 14: |
1ab3bf1b | 1322 | return lookup_fundamental_type (current_objfile, FT_EXT_PREC_FLOAT); |
e38e0312 | 1323 | case 15: |
1ab3bf1b JG |
1324 | /* requires a builtin `integer' */ |
1325 | return lookup_fundamental_type (current_objfile, FT_INTEGER); | |
e38e0312 | 1326 | case 16: |
1ab3bf1b | 1327 | return lookup_fundamental_type (current_objfile, FT_BOOLEAN); |
e38e0312 | 1328 | case 17: |
1ab3bf1b JG |
1329 | /* requires builtin `short real' */ |
1330 | return lookup_fundamental_type (current_objfile, FT_FLOAT); | |
e38e0312 | 1331 | case 18: |
1ab3bf1b JG |
1332 | /* requires builtin `real' */ |
1333 | return lookup_fundamental_type (current_objfile, FT_FLOAT); | |
e38e0312 JG |
1334 | default : |
1335 | printf ("ERROR! Unknown builtin type -%d\n", typenums[1]); | |
1336 | return NULL; | |
1337 | } | |
1338 | } | |
1339 | ||
1ab3bf1b JG |
1340 | #if 0 /* Seems to be unused, don't bother converting from old misc function |
1341 | vector usage to new minimal symbol tables. FIXME: Delete this? */ | |
1342 | ||
e38e0312 JG |
1343 | /* if we now nothing about a function but its address, make a function symbol |
1344 | out of it with the limited knowladge you have. This will be used when | |
1345 | somebody refers to a function, which doesn't exist in the symbol table, | |
1ab3bf1b | 1346 | but is in the minimal symbol table. */ |
e38e0312 JG |
1347 | |
1348 | struct symbol * | |
1ab3bf1b | 1349 | build_function_symbol (ind, objfile) |
e38e0312 | 1350 | int ind; |
1ab3bf1b | 1351 | struct objfile *objfile; |
e38e0312 JG |
1352 | { |
1353 | struct symbol *sym = | |
1ab3bf1b | 1354 | (struct symbol *) obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); |
e38e0312 JG |
1355 | SYMBOL_NAME (sym) = misc_function_vector[ind].name; |
1356 | /* SYMBOL_VALUE (sym) = misc_function_vector[ind].address; */ | |
1357 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
1358 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
1ab3bf1b | 1359 | SYMBOL_TYPE (sym) = lookup_function_type (lookup_fundamental_type (current_objfile, FT_INTEGER)); |
e38e0312 | 1360 | SYMBOL_BLOCK_VALUE (sym) = (struct block *) |
1ab3bf1b | 1361 | obstack_alloc (&objfile->symbol_obstack, sizeof (struct block)); |
e38e0312 JG |
1362 | BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) = misc_function_vector[ind].address; |
1363 | return sym; | |
1364 | } | |
1365 | ||
1ab3bf1b | 1366 | #endif |
e38e0312 | 1367 | |
1ab3bf1b | 1368 | static void |
e38e0312 JG |
1369 | aixcoff_new_init () |
1370 | { | |
1371 | /* Nothin' to do. */ | |
1372 | } | |
1373 | ||
1ab3bf1b | 1374 | static void |
e38e0312 JG |
1375 | aixcoff_symfile_init (sf) |
1376 | struct sym_fns *sf; | |
1377 | { | |
1378 | bfd *abfd = sf->sym_bfd; | |
1379 | ||
1380 | /* Allocate struct to keep track of the symfile */ | |
1381 | /* FIXME memory leak */ | |
1382 | sf->sym_private = xmalloc(sizeof (struct coff_symfile_info)); | |
1383 | ||
1384 | /* | |
1385 | * Save startup file's range of PC addresses to help | |
1386 | * blockframe.c decide where the bottom of the stack is. | |
1387 | */ | |
1388 | if (bfd_get_file_flags(abfd) & EXEC_P) { | |
1389 | entry_point = bfd_get_start_address(abfd); | |
1390 | } else { | |
1391 | entry_point = ~0; | |
1392 | /* set the startup file to be an empty range. */ | |
1393 | startup_file_start = 0; | |
1394 | startup_file_end = 0; | |
1395 | } | |
1396 | } | |
1397 | ||
1398 | ||
1399 | static int | |
1ab3bf1b | 1400 | init_stringtab(abfd, offset, objfile) |
e38e0312 JG |
1401 | bfd *abfd; |
1402 | long offset; | |
1ab3bf1b | 1403 | struct objfile *objfile; |
e38e0312 JG |
1404 | { |
1405 | long length; | |
1406 | int val; | |
1407 | unsigned char lengthbuf[4]; | |
1408 | ||
1409 | if (bfd_seek(abfd, offset, 0) < 0) | |
1410 | return -1; | |
1411 | ||
1412 | val = bfd_read((char *)lengthbuf, 1, sizeof lengthbuf, abfd); | |
1413 | length = bfd_h_get_32(abfd, lengthbuf); | |
1414 | ||
1415 | /* If no string table is needed, then the file may end immediately | |
1416 | after the symbols. Just return with `strtbl' set to null. */ | |
1417 | ||
1418 | if (val != sizeof length || length < sizeof length) | |
1419 | return 0; | |
1420 | ||
1421 | /* Allocate string table from symbol_obstack. We will need this table | |
1422 | as long as we have its symbol table around. */ | |
1423 | ||
1ab3bf1b | 1424 | strtbl = (char*) obstack_alloc (&objfile->symbol_obstack, length); |
e38e0312 JG |
1425 | if (strtbl == NULL) |
1426 | return -1; | |
1427 | ||
1428 | bcopy(&length, strtbl, sizeof length); | |
1429 | if (length == sizeof length) | |
1430 | return 0; | |
1431 | ||
1432 | val = bfd_read(strtbl + sizeof length, 1, length - sizeof length, abfd); | |
1433 | ||
1434 | if (val != length - sizeof length || strtbl[length - 1] != '\0') | |
1435 | return -1; | |
1436 | ||
1437 | return 0; | |
1438 | } | |
1439 | ||
1440 | static int | |
1441 | init_debugsection(abfd) | |
1442 | bfd *abfd; | |
1443 | { | |
1444 | register sec_ptr secp; | |
1445 | bfd_size_type length; | |
1446 | ||
1447 | if (debugsec) { | |
1448 | free(debugsec); | |
1449 | debugsec = NULL; | |
1450 | } | |
1451 | ||
1452 | secp = bfd_get_section_by_name(abfd, ".debug"); | |
1453 | if (!secp) | |
1454 | return 0; | |
1455 | ||
1456 | if (!(length = bfd_section_size(abfd, secp))) | |
1457 | return 0; | |
1458 | ||
1ab3bf1b | 1459 | debugsec = (char *) xmalloc ((unsigned)length); |
e38e0312 JG |
1460 | if (debugsec == NULL) |
1461 | return -1; | |
1462 | ||
1463 | if (!bfd_get_section_contents(abfd, secp, debugsec, (file_ptr) 0, length)) { | |
1464 | printf ("Can't read .debug section from symbol file\n"); | |
1465 | return -1; | |
1466 | } | |
1467 | return 0; | |
1468 | } | |
1469 | ||
1470 | static void | |
1471 | free_debugsection() | |
1472 | { | |
1473 | if (debugsec) | |
1474 | free(debugsec); | |
1475 | debugsec = NULL; | |
1476 | } | |
1477 | ||
1478 | ||
1479 | /* aixcoff version of symbol file read. */ | |
1480 | ||
1ab3bf1b | 1481 | static void |
e38e0312 JG |
1482 | aixcoff_symfile_read (sf, addr, mainline) |
1483 | struct sym_fns *sf; | |
1484 | CORE_ADDR addr; | |
1485 | int mainline; | |
1486 | { | |
1487 | int num_symbols; /* # of symbols */ | |
1488 | int symtab_offset; /* symbol table and */ | |
1489 | int stringtab_offset; /* string table file offsets */ | |
1490 | int val; | |
1491 | bfd *abfd; | |
1492 | struct coff_symfile_info *info = (void*) sf->sym_private; | |
1493 | char *name; | |
1494 | ||
1495 | symfile_bfd = abfd = sf->objfile->obfd; | |
1496 | name = sf->objfile->name; | |
1497 | ||
1498 | num_symbols = bfd_get_symcount (abfd); /* # of symbols */ | |
1499 | symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */ | |
1500 | stringtab_offset = symtab_offset + | |
1501 | num_symbols * coff_data(abfd)->local_symesz; | |
1502 | ||
1503 | info->min_lineno_offset = 0; | |
1504 | info->max_lineno_offset = 0; | |
1505 | bfd_map_over_sections (abfd, find_linenos, info); | |
1506 | ||
1507 | /* FIXME! This stuff should move into symfile_init */ | |
1508 | if (info->min_lineno_offset != 0 | |
1509 | && info->max_lineno_offset > info->min_lineno_offset) { | |
1510 | ||
1511 | /* only read in the line # table if one exists */ | |
1512 | val = init_lineno(abfd, info->min_lineno_offset, | |
1513 | info->max_lineno_offset - info->min_lineno_offset); | |
1514 | ||
1515 | if (val < 0) | |
1516 | error("\"%s\": error reading line numbers\n", name); | |
1517 | } | |
1518 | ||
1ab3bf1b | 1519 | val = init_stringtab(abfd, stringtab_offset, sf->objfile); |
e38e0312 JG |
1520 | if (val < 0) { |
1521 | error ("\"%s\": can't get string table", name); | |
1522 | } | |
1523 | ||
1524 | if (init_debugsection(abfd) < 0) { | |
1525 | error ("Error reading .debug section of `%s'\n", name); | |
1526 | } | |
1527 | ||
1528 | /* Position to read the symbol table. Do not read it all at once. */ | |
1529 | val = bfd_seek(abfd, (long)symtab_offset, 0); | |
1530 | if (val < 0) | |
1531 | perror_with_name(name); | |
1532 | ||
1533 | if (bfd_tell(abfd) != symtab_offset) | |
1534 | fatal("bfd? BFD!"); | |
1535 | ||
1ab3bf1b JG |
1536 | init_minimal_symbol_collection (); |
1537 | make_cleanup (discard_minimal_symbols, 0); | |
e38e0312 JG |
1538 | |
1539 | #ifdef XCOFF_INIT_LOADINFO | |
1540 | if (mainline) | |
1541 | XCOFF_INIT_LOADINFO (); | |
1542 | #endif | |
1543 | ||
1544 | /* Now that the executable file is positioned at symbol table, | |
1545 | process it and define symbols accordingly. */ | |
1546 | ||
1547 | read_xcoff_symtab(sf->objfile, num_symbols); | |
1548 | ||
1ab3bf1b | 1549 | make_cleanup (free_debugsection, 0); |
e38e0312 JG |
1550 | |
1551 | /* Sort symbols alphabetically within each block. */ | |
1552 | sort_syms (); | |
1553 | ||
1ab3bf1b JG |
1554 | /* Install any minimal symbols that have been collected as the current |
1555 | minimal symbols for this objfile. */ | |
1556 | ||
1557 | install_minimal_symbols (!mainline, sf -> objfile); | |
e38e0312 JG |
1558 | |
1559 | /* Make a default for file to list. */ | |
1560 | select_source_symtab (0); | |
1561 | } | |
1562 | ||
1563 | /* Register our ability to parse symbols for aixcoff BFD files. */ | |
1564 | ||
1565 | static struct sym_fns aixcoff_sym_fns = | |
1566 | { | |
1567 | "aixcoff-rs6000", 15, | |
1568 | aixcoff_new_init, aixcoff_symfile_init, | |
1569 | aixcoff_symfile_read, | |
1570 | }; | |
1571 | ||
1572 | void | |
1573 | _initialize_xcoffread () | |
1574 | { | |
1575 | add_symtab_fns(&aixcoff_sym_fns); | |
1576 | } |