]>
Commit | Line | Data |
---|---|---|
bfe2f12b | 1 | /* Read HP PA/Risc object files for GDB. |
436d4143 | 2 | Copyright 1991, 1992, 1996 Free Software Foundation, Inc. |
bfe2f12b JL |
3 | Written by Fred Fish at Cygnus Support. |
4 | ||
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
6c9638b4 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
bfe2f12b JL |
20 | |
21 | #include "defs.h" | |
22 | #include "bfd.h" | |
bfe2f12b JL |
23 | #include "som.h" |
24 | #include "libhppa.h" | |
25 | #include <syms.h> | |
26 | #include "symtab.h" | |
27 | #include "symfile.h" | |
28 | #include "objfiles.h" | |
29 | #include "buildsym.h" | |
30 | #include "stabsread.h" | |
31 | #include "gdb-stabs.h" | |
32 | #include "complaints.h" | |
2b576293 | 33 | #include "gdb_string.h" |
bfe2f12b JL |
34 | #include "demangle.h" |
35 | #include <sys/file.h> | |
36 | ||
bfe2f12b JL |
37 | /* Various things we might complain about... */ |
38 | ||
39 | static void | |
6a86fa48 | 40 | som_symfile_init PARAMS ((struct objfile *)); |
bfe2f12b JL |
41 | |
42 | static void | |
43 | som_new_init PARAMS ((struct objfile *)); | |
44 | ||
45 | static void | |
46 | som_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int)); | |
47 | ||
48 | static void | |
49 | som_symfile_finish PARAMS ((struct objfile *)); | |
50 | ||
51 | static void | |
bb140953 JL |
52 | som_symtab_read PARAMS ((bfd *, struct objfile *, |
53 | struct section_offsets *)); | |
bfe2f12b | 54 | |
bfe2f12b JL |
55 | static struct section_offsets * |
56 | som_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR)); | |
57 | ||
3f550b59 FF |
58 | /* FIXME: These should really be in a common header somewhere */ |
59 | ||
60 | extern void | |
61 | hpread_build_psymtabs PARAMS ((struct objfile *, struct section_offsets *, int)); | |
62 | ||
63 | extern void | |
64 | hpread_symfile_finish PARAMS ((struct objfile *)); | |
65 | ||
66 | extern void | |
67 | hpread_symfile_init PARAMS ((struct objfile *)); | |
68 | ||
bfe2f12b JL |
69 | /* |
70 | ||
71 | LOCAL FUNCTION | |
72 | ||
73 | som_symtab_read -- read the symbol table of a SOM file | |
74 | ||
75 | SYNOPSIS | |
76 | ||
bb140953 JL |
77 | void som_symtab_read (bfd *abfd, struct objfile *objfile, |
78 | struct section_offsets *section_offsets) | |
bfe2f12b JL |
79 | |
80 | DESCRIPTION | |
81 | ||
82 | Given an open bfd, a base address to relocate symbols to, and a | |
83 | flag that specifies whether or not this bfd is for an executable | |
84 | or not (may be shared library for example), add all the global | |
85 | function and data symbols to the minimal symbol table. | |
86 | */ | |
87 | ||
88 | static void | |
bb140953 | 89 | som_symtab_read (abfd, objfile, section_offsets) |
bfe2f12b | 90 | bfd *abfd; |
bfe2f12b | 91 | struct objfile *objfile; |
bb140953 | 92 | struct section_offsets *section_offsets; |
bfe2f12b JL |
93 | { |
94 | unsigned int number_of_symbols; | |
bfe2f12b JL |
95 | int val, dynamic; |
96 | char *stringtab; | |
97 | asection *shlib_info; | |
98 | struct symbol_dictionary_record *buf, *bufp, *endbufp; | |
99 | char *symname; | |
100 | CONST int symsize = sizeof (struct symbol_dictionary_record); | |
506af7a7 | 101 | CORE_ADDR text_offset, data_offset; |
bb140953 JL |
102 | |
103 | ||
bb140953 | 104 | text_offset = ANOFFSET (section_offsets, 0); |
506af7a7 | 105 | data_offset = ANOFFSET (section_offsets, 1); |
bfe2f12b JL |
106 | |
107 | number_of_symbols = bfd_get_symcount (abfd); | |
108 | ||
109 | buf = alloca (symsize * number_of_symbols); | |
987622b5 | 110 | bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET); |
bfe2f12b JL |
111 | val = bfd_read (buf, symsize * number_of_symbols, 1, abfd); |
112 | if (val != symsize * number_of_symbols) | |
113 | error ("Couldn't read symbol dictionary!"); | |
114 | ||
115 | stringtab = alloca (obj_som_stringtab_size (abfd)); | |
987622b5 | 116 | bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET); |
bfe2f12b JL |
117 | val = bfd_read (stringtab, obj_som_stringtab_size (abfd), 1, abfd); |
118 | if (val != obj_som_stringtab_size (abfd)) | |
119 | error ("Can't read in HP string table."); | |
120 | ||
121 | /* We need to determine if objfile is a dynamic executable (so we | |
122 | can do the right thing for ST_ENTRY vs ST_CODE symbols). | |
123 | ||
124 | There's nothing in the header which easily allows us to do | |
125 | this. The only reliable way I know of is to check for the | |
126 | existance of a $SHLIB_INFO$ section with a non-zero size. */ | |
127 | shlib_info = bfd_get_section_by_name (objfile->obfd, "$SHLIB_INFO$"); | |
128 | if (shlib_info) | |
129 | dynamic = (bfd_section_size (objfile->obfd, shlib_info) != 0); | |
130 | else | |
131 | dynamic = 0; | |
132 | ||
133 | endbufp = buf + number_of_symbols; | |
134 | for (bufp = buf; bufp < endbufp; ++bufp) | |
135 | { | |
136 | enum minimal_symbol_type ms_type; | |
137 | ||
138 | QUIT; | |
139 | ||
140 | switch (bufp->symbol_scope) | |
141 | { | |
142 | case SS_UNIVERSAL: | |
143 | case SS_EXTERNAL: | |
144 | switch (bufp->symbol_type) | |
145 | { | |
146 | case ST_SYM_EXT: | |
147 | case ST_ARG_EXT: | |
148 | continue; | |
149 | ||
150 | case ST_CODE: | |
151 | case ST_PRI_PROG: | |
152 | case ST_SEC_PROG: | |
153 | case ST_MILLICODE: | |
154 | symname = bufp->name.n_strx + stringtab; | |
155 | ms_type = mst_text; | |
bb140953 | 156 | bufp->symbol_value += text_offset; |
bfe2f12b JL |
157 | #ifdef SMASH_TEXT_ADDRESS |
158 | SMASH_TEXT_ADDRESS (bufp->symbol_value); | |
159 | #endif | |
160 | break; | |
161 | ||
162 | case ST_ENTRY: | |
163 | symname = bufp->name.n_strx + stringtab; | |
164 | /* For a dynamic executable, ST_ENTRY symbols are | |
165 | the stubs, while the ST_CODE symbol is the real | |
166 | function. */ | |
167 | if (dynamic) | |
168 | ms_type = mst_solib_trampoline; | |
169 | else | |
170 | ms_type = mst_text; | |
bb140953 | 171 | bufp->symbol_value += text_offset; |
bfe2f12b JL |
172 | #ifdef SMASH_TEXT_ADDRESS |
173 | SMASH_TEXT_ADDRESS (bufp->symbol_value); | |
174 | #endif | |
175 | break; | |
176 | ||
177 | case ST_STUB: | |
178 | symname = bufp->name.n_strx + stringtab; | |
179 | ms_type = mst_solib_trampoline; | |
bb140953 | 180 | bufp->symbol_value += text_offset; |
bfe2f12b JL |
181 | #ifdef SMASH_TEXT_ADDRESS |
182 | SMASH_TEXT_ADDRESS (bufp->symbol_value); | |
183 | #endif | |
184 | break; | |
185 | ||
186 | case ST_DATA: | |
187 | symname = bufp->name.n_strx + stringtab; | |
506af7a7 | 188 | bufp->symbol_value += data_offset; |
bfe2f12b JL |
189 | ms_type = mst_data; |
190 | break; | |
191 | default: | |
192 | continue; | |
193 | } | |
194 | break; | |
195 | ||
196 | #if 0 | |
197 | /* SS_GLOBAL and SS_LOCAL are two names for the same thing (!). */ | |
198 | case SS_GLOBAL: | |
199 | #endif | |
200 | case SS_LOCAL: | |
201 | switch (bufp->symbol_type) | |
202 | { | |
203 | case ST_SYM_EXT: | |
204 | case ST_ARG_EXT: | |
205 | continue; | |
206 | ||
207 | case ST_CODE: | |
208 | symname = bufp->name.n_strx + stringtab; | |
209 | ms_type = mst_file_text; | |
bb140953 | 210 | bufp->symbol_value += text_offset; |
bfe2f12b JL |
211 | #ifdef SMASH_TEXT_ADDRESS |
212 | SMASH_TEXT_ADDRESS (bufp->symbol_value); | |
213 | #endif | |
214 | ||
215 | check_strange_names: | |
216 | /* Utah GCC 2.5, FSF GCC 2.6 and later generate correct local | |
217 | label prefixes for stabs, constant data, etc. So we need | |
218 | only filter out L$ symbols which are left in due to | |
219 | limitations in how GAS generates SOM relocations. | |
220 | ||
221 | When linking in the HPUX C-library the HP linker has | |
222 | the nasty habit of placing section symbols from the literal | |
223 | subspaces in the middle of the program's text. Filter | |
224 | those out as best we can. Check for first and last character | |
2097152a JL |
225 | being '$'. |
226 | ||
227 | And finally, the newer HP compilers emit crud like $PIC_foo$N | |
228 | in some circumstance (PIC code I guess). It's also claimed | |
229 | that they emit D$ symbols too. What stupidity. */ | |
bfe2f12b | 230 | if ((symname[0] == 'L' && symname[1] == '$') |
2097152a JL |
231 | || (symname[0] == '$' && symname[strlen(symname) - 1] == '$') |
232 | || (symname[0] == 'D' && symname[1] == '$') | |
233 | || (strncmp (symname, "$PIC", 4) == 0)) | |
bfe2f12b JL |
234 | continue; |
235 | break; | |
236 | ||
237 | case ST_PRI_PROG: | |
238 | case ST_SEC_PROG: | |
239 | case ST_MILLICODE: | |
240 | symname = bufp->name.n_strx + stringtab; | |
241 | ms_type = mst_file_text; | |
bb140953 | 242 | bufp->symbol_value += text_offset; |
bfe2f12b JL |
243 | #ifdef SMASH_TEXT_ADDRESS |
244 | SMASH_TEXT_ADDRESS (bufp->symbol_value); | |
245 | #endif | |
246 | break; | |
247 | ||
248 | case ST_ENTRY: | |
249 | symname = bufp->name.n_strx + stringtab; | |
250 | /* For a dynamic executable, ST_ENTRY symbols are | |
251 | the stubs, while the ST_CODE symbol is the real | |
252 | function. */ | |
253 | if (dynamic) | |
254 | ms_type = mst_solib_trampoline; | |
255 | else | |
256 | ms_type = mst_file_text; | |
bb140953 | 257 | bufp->symbol_value += text_offset; |
bfe2f12b JL |
258 | #ifdef SMASH_TEXT_ADDRESS |
259 | SMASH_TEXT_ADDRESS (bufp->symbol_value); | |
260 | #endif | |
261 | break; | |
262 | ||
263 | case ST_STUB: | |
264 | symname = bufp->name.n_strx + stringtab; | |
265 | ms_type = mst_solib_trampoline; | |
bb140953 | 266 | bufp->symbol_value += text_offset; |
bfe2f12b JL |
267 | #ifdef SMASH_TEXT_ADDRESS |
268 | SMASH_TEXT_ADDRESS (bufp->symbol_value); | |
269 | #endif | |
270 | break; | |
271 | ||
272 | ||
273 | case ST_DATA: | |
274 | symname = bufp->name.n_strx + stringtab; | |
506af7a7 | 275 | bufp->symbol_value += data_offset; |
bfe2f12b JL |
276 | ms_type = mst_file_data; |
277 | goto check_strange_names; | |
278 | ||
279 | default: | |
280 | continue; | |
281 | } | |
282 | break; | |
283 | ||
5dc74605 JL |
284 | /* This can happen for common symbols when -E is passed to the |
285 | final link. No idea _why_ that would make the linker force | |
286 | common symbols to have an SS_UNSAT scope, but it does. */ | |
287 | case SS_UNSAT: | |
288 | switch (bufp->symbol_type) | |
289 | { | |
290 | case ST_STORAGE: | |
291 | symname = bufp->name.n_strx + stringtab; | |
292 | bufp->symbol_value += data_offset; | |
293 | ms_type = mst_data; | |
294 | break; | |
295 | ||
296 | default: | |
297 | continue; | |
298 | } | |
299 | break; | |
300 | ||
bfe2f12b JL |
301 | default: |
302 | continue; | |
303 | } | |
304 | ||
305 | if (bufp->name.n_strx > obj_som_stringtab_size (abfd)) | |
306 | error ("Invalid symbol data; bad HP string table offset: %d", | |
307 | bufp->name.n_strx); | |
308 | ||
ace4b8d7 FF |
309 | prim_record_minimal_symbol (symname, bufp->symbol_value, ms_type, |
310 | objfile); | |
bfe2f12b | 311 | } |
bfe2f12b JL |
312 | } |
313 | ||
314 | /* Scan and build partial symbols for a symbol file. | |
315 | We have been initialized by a call to som_symfile_init, which | |
316 | currently does nothing. | |
317 | ||
318 | SECTION_OFFSETS is a set of offsets to apply to relocate the symbols | |
319 | in each section. This is ignored, as it isn't needed for SOM. | |
320 | ||
321 | MAINLINE is true if we are reading the main symbol | |
322 | table (as opposed to a shared lib or dynamically loaded file). | |
323 | ||
324 | This function only does the minimum work necessary for letting the | |
325 | user "name" things symbolically; it does not read the entire symtab. | |
326 | Instead, it reads the external and static symbols and puts them in partial | |
327 | symbol tables. When more extensive information is requested of a | |
328 | file, the corresponding partial symbol table is mutated into a full | |
329 | fledged symbol table by going back and reading the symbols | |
330 | for real. | |
331 | ||
332 | We look for sections with specific names, to tell us what debug | |
333 | format to look for: FIXME!!! | |
334 | ||
335 | somstab_build_psymtabs() handles STABS symbols. | |
336 | ||
337 | Note that SOM files have a "minimal" symbol table, which is vaguely | |
338 | reminiscent of a COFF symbol table, but has only the minimal information | |
339 | necessary for linking. We process this also, and use the information to | |
340 | build gdb's minimal symbol table. This gives us some minimal debugging | |
341 | capability even for files compiled without -g. */ | |
342 | ||
343 | static void | |
344 | som_symfile_read (objfile, section_offsets, mainline) | |
345 | struct objfile *objfile; | |
346 | struct section_offsets *section_offsets; | |
347 | int mainline; | |
348 | { | |
349 | bfd *abfd = objfile->obfd; | |
350 | struct cleanup *back_to; | |
bfe2f12b JL |
351 | |
352 | init_minimal_symbol_collection (); | |
353 | back_to = make_cleanup (discard_minimal_symbols, 0); | |
354 | ||
6a86fa48 | 355 | /* Process the normal SOM symbol table first. */ |
bfe2f12b | 356 | |
bb140953 | 357 | som_symtab_read (abfd, objfile, section_offsets); |
bfe2f12b | 358 | |
98c0e047 | 359 | /* Now read information from the stabs debug sections. */ |
6a86fa48 JL |
360 | stabsect_build_psymtabs (objfile, section_offsets, mainline, |
361 | "$GDB_SYMBOLS$", "$GDB_STRINGS$", "$TEXT$"); | |
bfe2f12b | 362 | |
98c0e047 JL |
363 | /* Now read the native debug information. */ |
364 | hpread_build_psymtabs (objfile, section_offsets, mainline); | |
98c0e047 | 365 | |
6a86fa48 JL |
366 | /* Install any minimal symbols that have been collected as the current |
367 | minimal symbols for this objfile. */ | |
368 | install_minimal_symbols (objfile); | |
bfe2f12b | 369 | |
31b2518a | 370 | /* Force hppa-tdep.c to re-read the unwind descriptors. */ |
c676d827 | 371 | objfile->obj_private = NULL; |
6a86fa48 | 372 | do_cleanups (back_to); |
bfe2f12b JL |
373 | } |
374 | ||
375 | /* Initialize anything that needs initializing when a completely new symbol | |
376 | file is specified (not just adding some symbols from another file, e.g. a | |
377 | shared library). | |
378 | ||
379 | We reinitialize buildsym, since we may be reading stabs from a SOM file. */ | |
380 | ||
381 | static void | |
382 | som_new_init (ignore) | |
383 | struct objfile *ignore; | |
384 | { | |
385 | stabsread_new_init (); | |
386 | buildsym_new_init (); | |
387 | } | |
388 | ||
389 | /* Perform any local cleanups required when we are done with a particular | |
390 | objfile. I.E, we are in the process of discarding all symbol information | |
391 | for an objfile, freeing up all memory held for it, and unlinking the | |
392 | objfile struct from the global list of known objfiles. */ | |
393 | ||
394 | static void | |
395 | som_symfile_finish (objfile) | |
396 | struct objfile *objfile; | |
397 | { | |
398 | if (objfile -> sym_stab_info != NULL) | |
399 | { | |
400 | mfree (objfile -> md, objfile -> sym_stab_info); | |
401 | } | |
98c0e047 | 402 | hpread_symfile_finish (objfile); |
bfe2f12b JL |
403 | } |
404 | ||
436d4143 | 405 | /* SOM specific initialization routine for reading symbols. */ |
bfe2f12b | 406 | |
bfe2f12b | 407 | static void |
98c0e047 JL |
408 | som_symfile_init (objfile) |
409 | struct objfile *objfile; | |
bfe2f12b | 410 | { |
436d4143 JL |
411 | /* SOM objects may be reordered, so set OBJF_REORDERED. If we |
412 | find this causes a significant slowdown in gdb then we could | |
413 | set it in the debug symbol readers only when necessary. */ | |
414 | objfile->flags |= OBJF_REORDERED; | |
98c0e047 | 415 | hpread_symfile_init (objfile); |
bfe2f12b JL |
416 | } |
417 | ||
418 | /* SOM specific parsing routine for section offsets. | |
419 | ||
420 | Plain and simple for now. */ | |
421 | ||
422 | static struct section_offsets * | |
423 | som_symfile_offsets (objfile, addr) | |
424 | struct objfile *objfile; | |
425 | CORE_ADDR addr; | |
426 | { | |
427 | struct section_offsets *section_offsets; | |
428 | int i; | |
429 | ||
430 | objfile->num_sections = SECT_OFF_MAX; | |
431 | section_offsets = (struct section_offsets *) | |
e74acce4 | 432 | obstack_alloc (&objfile -> psymbol_obstack, SIZEOF_SECTION_OFFSETS); |
bfe2f12b | 433 | |
506af7a7 JL |
434 | /* First see if we're a shared library. If so, get the section |
435 | offsets from the library, else get them from addr. */ | |
436 | if (!som_solib_section_offsets (objfile, section_offsets)) | |
437 | { | |
438 | for (i = 0; i < SECT_OFF_MAX; i++) | |
439 | ANOFFSET (section_offsets, i) = addr; | |
440 | } | |
bfe2f12b JL |
441 | |
442 | return section_offsets; | |
443 | } | |
444 | \f | |
445 | /* Register that we are able to handle SOM object file formats. */ | |
446 | ||
447 | static struct sym_fns som_sym_fns = | |
448 | { | |
449 | bfd_target_som_flavour, | |
450 | som_new_init, /* sym_new_init: init anything gbl to entire symtab */ | |
451 | som_symfile_init, /* sym_init: read initial info, setup for sym_read() */ | |
452 | som_symfile_read, /* sym_read: read a symbol file into symtab */ | |
453 | som_symfile_finish, /* sym_finish: finished with file, cleanup */ | |
454 | som_symfile_offsets, /* sym_offsets: Translate ext. to int. relocation */ | |
455 | NULL /* next: pointer to next struct sym_fns */ | |
456 | }; | |
457 | ||
458 | void | |
459 | _initialize_somread () | |
460 | { | |
461 | add_symtab_fns (&som_sym_fns); | |
462 | } |