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