]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Read HP PA/Risc object files for GDB. |
0b302171 JB |
2 | Copyright (C) 1991-1992, 1994-1996, 1998-2002, 2004, 2007-2012 Free |
3 | Software Foundation, Inc. | |
c906108c SS |
4 | Written by Fred Fish at Cygnus Support. |
5 | ||
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
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 | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 11 | (at your option) any later version. |
c906108c | 12 | |
c5aa993b JM |
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. | |
c906108c | 17 | |
c5aa993b | 18 | You should have received a copy of the GNU General Public License |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
20 | |
21 | #include "defs.h" | |
22 | #include "bfd.h" | |
23 | #include <syms.h> | |
24 | #include "symtab.h" | |
25 | #include "symfile.h" | |
26 | #include "objfiles.h" | |
27 | #include "buildsym.h" | |
28 | #include "stabsread.h" | |
29 | #include "gdb-stabs.h" | |
30 | #include "complaints.h" | |
31 | #include "gdb_string.h" | |
32 | #include "demangle.h" | |
33 | #include "som.h" | |
34 | #include "libhppa.h" | |
ccefe4c4 | 35 | #include "psymtab.h" |
c906108c | 36 | |
17fe2d6e | 37 | #include "solib-som.h" |
c906108c | 38 | |
7f86f058 | 39 | /* Read the symbol table of a SOM file. |
c906108c | 40 | |
c5aa993b JM |
41 | Given an open bfd, a base address to relocate symbols to, and a |
42 | flag that specifies whether or not this bfd is for an executable | |
43 | or not (may be shared library for example), add all the global | |
7f86f058 | 44 | function and data symbols to the minimal symbol table. */ |
c906108c SS |
45 | |
46 | static void | |
fba45db2 KB |
47 | som_symtab_read (bfd *abfd, struct objfile *objfile, |
48 | struct section_offsets *section_offsets) | |
c906108c | 49 | { |
5e2b427d | 50 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
51 | unsigned int number_of_symbols; |
52 | int val, dynamic; | |
53 | char *stringtab; | |
54 | asection *shlib_info; | |
55 | struct symbol_dictionary_record *buf, *bufp, *endbufp; | |
56 | char *symname; | |
57 | CONST int symsize = sizeof (struct symbol_dictionary_record); | |
58 | CORE_ADDR text_offset, data_offset; | |
59 | ||
60 | ||
61 | text_offset = ANOFFSET (section_offsets, 0); | |
62 | data_offset = ANOFFSET (section_offsets, 1); | |
63 | ||
64 | number_of_symbols = bfd_get_symcount (abfd); | |
65 | ||
f31b3751 JB |
66 | /* Allocate a buffer to read in the debug info. |
67 | We avoid using alloca because the memory size could be so large | |
68 | that we could hit the stack size limit. */ | |
69 | buf = xmalloc (symsize * number_of_symbols); | |
70 | make_cleanup (xfree, buf); | |
c906108c | 71 | bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET); |
3a42e9d0 | 72 | val = bfd_bread (buf, symsize * number_of_symbols, abfd); |
c906108c | 73 | if (val != symsize * number_of_symbols) |
8a3fe4f8 | 74 | error (_("Couldn't read symbol dictionary!")); |
c906108c | 75 | |
f31b3751 JB |
76 | /* Allocate a buffer to read in the som stringtab section of |
77 | the debugging info. Again, we avoid using alloca because | |
78 | the data could be so large that we could potentially hit | |
79 | the stack size limitat. */ | |
80 | stringtab = xmalloc (obj_som_stringtab_size (abfd)); | |
81 | make_cleanup (xfree, stringtab); | |
c906108c | 82 | bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET); |
3a42e9d0 | 83 | val = bfd_bread (stringtab, obj_som_stringtab_size (abfd), abfd); |
c906108c | 84 | if (val != obj_som_stringtab_size (abfd)) |
8a3fe4f8 | 85 | error (_("Can't read in HP string table.")); |
c906108c SS |
86 | |
87 | /* We need to determine if objfile is a dynamic executable (so we | |
88 | can do the right thing for ST_ENTRY vs ST_CODE symbols). | |
89 | ||
90 | There's nothing in the header which easily allows us to do | |
3fa41cdb JL |
91 | this. |
92 | ||
93 | This code used to rely upon the existence of a $SHLIB_INFO$ | |
94 | section to make this determination. HP claims that it is | |
95 | more accurate to check for a nonzero text offset, but they | |
96 | have not provided any information about why that test is | |
97 | more accurate. */ | |
c906108c SS |
98 | dynamic = (text_offset != 0); |
99 | ||
100 | endbufp = buf + number_of_symbols; | |
101 | for (bufp = buf; bufp < endbufp; ++bufp) | |
102 | { | |
103 | enum minimal_symbol_type ms_type; | |
104 | ||
105 | QUIT; | |
106 | ||
107 | switch (bufp->symbol_scope) | |
108 | { | |
109 | case SS_UNIVERSAL: | |
110 | case SS_EXTERNAL: | |
111 | switch (bufp->symbol_type) | |
112 | { | |
113 | case ST_SYM_EXT: | |
114 | case ST_ARG_EXT: | |
115 | continue; | |
116 | ||
117 | case ST_CODE: | |
118 | case ST_PRI_PROG: | |
119 | case ST_SEC_PROG: | |
120 | case ST_MILLICODE: | |
121 | symname = bufp->name.n_strx + stringtab; | |
122 | ms_type = mst_text; | |
123 | bufp->symbol_value += text_offset; | |
260edbc2 | 124 | bufp->symbol_value = gdbarch_smash_text_address |
5e2b427d | 125 | (gdbarch, bufp->symbol_value); |
c906108c SS |
126 | break; |
127 | ||
128 | case ST_ENTRY: | |
129 | symname = bufp->name.n_strx + stringtab; | |
130 | /* For a dynamic executable, ST_ENTRY symbols are | |
c5aa993b JM |
131 | the stubs, while the ST_CODE symbol is the real |
132 | function. */ | |
c906108c SS |
133 | if (dynamic) |
134 | ms_type = mst_solib_trampoline; | |
135 | else | |
136 | ms_type = mst_text; | |
137 | bufp->symbol_value += text_offset; | |
260edbc2 | 138 | bufp->symbol_value = gdbarch_smash_text_address |
5e2b427d | 139 | (gdbarch, bufp->symbol_value); |
c906108c SS |
140 | break; |
141 | ||
142 | case ST_STUB: | |
143 | symname = bufp->name.n_strx + stringtab; | |
144 | ms_type = mst_solib_trampoline; | |
145 | bufp->symbol_value += text_offset; | |
260edbc2 | 146 | bufp->symbol_value = gdbarch_smash_text_address |
5e2b427d | 147 | (gdbarch, bufp->symbol_value); |
c906108c SS |
148 | break; |
149 | ||
150 | case ST_DATA: | |
151 | symname = bufp->name.n_strx + stringtab; | |
152 | bufp->symbol_value += data_offset; | |
153 | ms_type = mst_data; | |
154 | break; | |
155 | default: | |
156 | continue; | |
157 | } | |
158 | break; | |
159 | ||
160 | #if 0 | |
161 | /* SS_GLOBAL and SS_LOCAL are two names for the same thing (!). */ | |
162 | case SS_GLOBAL: | |
163 | #endif | |
164 | case SS_LOCAL: | |
165 | switch (bufp->symbol_type) | |
166 | { | |
167 | case ST_SYM_EXT: | |
168 | case ST_ARG_EXT: | |
169 | continue; | |
170 | ||
171 | case ST_CODE: | |
172 | symname = bufp->name.n_strx + stringtab; | |
173 | ms_type = mst_file_text; | |
174 | bufp->symbol_value += text_offset; | |
260edbc2 | 175 | bufp->symbol_value = gdbarch_smash_text_address |
5e2b427d | 176 | (gdbarch, bufp->symbol_value); |
c906108c SS |
177 | |
178 | check_strange_names: | |
179 | /* Utah GCC 2.5, FSF GCC 2.6 and later generate correct local | |
c5aa993b JM |
180 | label prefixes for stabs, constant data, etc. So we need |
181 | only filter out L$ symbols which are left in due to | |
182 | limitations in how GAS generates SOM relocations. | |
183 | ||
184 | When linking in the HPUX C-library the HP linker has | |
185 | the nasty habit of placing section symbols from the literal | |
186 | subspaces in the middle of the program's text. Filter | |
187 | those out as best we can. Check for first and last character | |
c378eb4e | 188 | being '$'. |
c5aa993b JM |
189 | |
190 | And finally, the newer HP compilers emit crud like $PIC_foo$N | |
191 | in some circumstance (PIC code I guess). It's also claimed | |
192 | that they emit D$ symbols too. What stupidity. */ | |
c906108c | 193 | if ((symname[0] == 'L' && symname[1] == '$') |
c5aa993b | 194 | || (symname[0] == '$' && symname[strlen (symname) - 1] == '$') |
c906108c | 195 | || (symname[0] == 'D' && symname[1] == '$') |
b887c273 | 196 | || (strncmp (symname, "L0\001", 3) == 0) |
c906108c SS |
197 | || (strncmp (symname, "$PIC", 4) == 0)) |
198 | continue; | |
199 | break; | |
200 | ||
201 | case ST_PRI_PROG: | |
202 | case ST_SEC_PROG: | |
203 | case ST_MILLICODE: | |
204 | symname = bufp->name.n_strx + stringtab; | |
205 | ms_type = mst_file_text; | |
206 | bufp->symbol_value += text_offset; | |
260edbc2 | 207 | bufp->symbol_value = gdbarch_smash_text_address |
5e2b427d | 208 | (gdbarch, bufp->symbol_value); |
c906108c SS |
209 | break; |
210 | ||
211 | case ST_ENTRY: | |
212 | symname = bufp->name.n_strx + stringtab; | |
3fa41cdb JL |
213 | /* SS_LOCAL symbols in a shared library do not have |
214 | export stubs, so we do not have to worry about | |
215 | using mst_file_text vs mst_solib_trampoline here like | |
216 | we do for SS_UNIVERSAL and SS_EXTERNAL symbols above. */ | |
217 | ms_type = mst_file_text; | |
c906108c | 218 | bufp->symbol_value += text_offset; |
260edbc2 | 219 | bufp->symbol_value = gdbarch_smash_text_address |
5e2b427d | 220 | (gdbarch, bufp->symbol_value); |
c906108c SS |
221 | break; |
222 | ||
223 | case ST_STUB: | |
224 | symname = bufp->name.n_strx + stringtab; | |
225 | ms_type = mst_solib_trampoline; | |
226 | bufp->symbol_value += text_offset; | |
260edbc2 | 227 | bufp->symbol_value = gdbarch_smash_text_address |
5e2b427d | 228 | (gdbarch, bufp->symbol_value); |
c906108c SS |
229 | break; |
230 | ||
231 | ||
232 | case ST_DATA: | |
233 | symname = bufp->name.n_strx + stringtab; | |
234 | bufp->symbol_value += data_offset; | |
235 | ms_type = mst_file_data; | |
236 | goto check_strange_names; | |
237 | ||
238 | default: | |
239 | continue; | |
240 | } | |
241 | break; | |
242 | ||
c5aa993b JM |
243 | /* This can happen for common symbols when -E is passed to the |
244 | final link. No idea _why_ that would make the linker force | |
245 | common symbols to have an SS_UNSAT scope, but it does. | |
c906108c | 246 | |
c5aa993b JM |
247 | This also happens for weak symbols, but their type is |
248 | ST_DATA. */ | |
c906108c SS |
249 | case SS_UNSAT: |
250 | switch (bufp->symbol_type) | |
251 | { | |
c5aa993b JM |
252 | case ST_STORAGE: |
253 | case ST_DATA: | |
254 | symname = bufp->name.n_strx + stringtab; | |
255 | bufp->symbol_value += data_offset; | |
256 | ms_type = mst_data; | |
257 | break; | |
258 | ||
259 | default: | |
260 | continue; | |
c906108c SS |
261 | } |
262 | break; | |
263 | ||
264 | default: | |
265 | continue; | |
266 | } | |
267 | ||
268 | if (bufp->name.n_strx > obj_som_stringtab_size (abfd)) | |
8a3fe4f8 | 269 | error (_("Invalid symbol data; bad HP string table offset: %d"), |
c906108c SS |
270 | bufp->name.n_strx); |
271 | ||
c5aa993b | 272 | prim_record_minimal_symbol (symname, bufp->symbol_value, ms_type, |
c906108c SS |
273 | objfile); |
274 | } | |
275 | } | |
276 | ||
277 | /* Scan and build partial symbols for a symbol file. | |
278 | We have been initialized by a call to som_symfile_init, which | |
279 | currently does nothing. | |
280 | ||
281 | SECTION_OFFSETS is a set of offsets to apply to relocate the symbols | |
282 | in each section. This is ignored, as it isn't needed for SOM. | |
283 | ||
c906108c SS |
284 | This function only does the minimum work necessary for letting the |
285 | user "name" things symbolically; it does not read the entire symtab. | |
286 | Instead, it reads the external and static symbols and puts them in partial | |
287 | symbol tables. When more extensive information is requested of a | |
288 | file, the corresponding partial symbol table is mutated into a full | |
289 | fledged symbol table by going back and reading the symbols | |
290 | for real. | |
291 | ||
292 | We look for sections with specific names, to tell us what debug | |
293 | format to look for: FIXME!!! | |
294 | ||
295 | somstab_build_psymtabs() handles STABS symbols. | |
296 | ||
297 | Note that SOM files have a "minimal" symbol table, which is vaguely | |
298 | reminiscent of a COFF symbol table, but has only the minimal information | |
299 | necessary for linking. We process this also, and use the information to | |
300 | build gdb's minimal symbol table. This gives us some minimal debugging | |
301 | capability even for files compiled without -g. */ | |
302 | ||
303 | static void | |
f4352531 | 304 | som_symfile_read (struct objfile *objfile, int symfile_flags) |
c906108c SS |
305 | { |
306 | bfd *abfd = objfile->obfd; | |
307 | struct cleanup *back_to; | |
308 | ||
c906108c | 309 | init_minimal_symbol_collection (); |
56e290f4 | 310 | back_to = make_cleanup_discard_minimal_symbols (); |
c906108c | 311 | |
c378eb4e | 312 | /* Process the normal SOM symbol table first. |
c906108c | 313 | This reads in the DNTT and string table, but doesn't |
c378eb4e MS |
314 | actually scan the DNTT. It does scan the linker symbol |
315 | table and thus build up a "minimal symbol table". */ | |
c5aa993b | 316 | |
96baa820 | 317 | som_symtab_read (abfd, objfile, objfile->section_offsets); |
c906108c | 318 | |
7134143f | 319 | /* Install any minimal symbols that have been collected as the current |
c378eb4e | 320 | minimal symbols for this objfile. |
7134143f | 321 | Further symbol-reading is done incrementally, file-by-file, |
c378eb4e MS |
322 | in a step known as "psymtab-to-symtab" expansion. hp-symtab-read.c |
323 | contains the code to do the actual DNTT scanning and symtab building. */ | |
7134143f DJ |
324 | install_minimal_symbols (objfile); |
325 | do_cleanups (back_to); | |
326 | ||
c906108c | 327 | /* Now read information from the stabs debug sections. |
4897bfb9 | 328 | This is emitted by gcc. */ |
c67a9c90 | 329 | stabsect_build_psymtabs (objfile, |
c906108c | 330 | "$GDB_SYMBOLS$", "$GDB_STRINGS$", "$TEXT$"); |
c906108c SS |
331 | } |
332 | ||
333 | /* Initialize anything that needs initializing when a completely new symbol | |
334 | file is specified (not just adding some symbols from another file, e.g. a | |
335 | shared library). | |
336 | ||
337 | We reinitialize buildsym, since we may be reading stabs from a SOM file. */ | |
338 | ||
339 | static void | |
fba45db2 | 340 | som_new_init (struct objfile *ignore) |
c906108c SS |
341 | { |
342 | stabsread_new_init (); | |
343 | buildsym_new_init (); | |
344 | } | |
345 | ||
346 | /* Perform any local cleanups required when we are done with a particular | |
c378eb4e | 347 | objfile. I.e, we are in the process of discarding all symbol information |
c906108c | 348 | for an objfile, freeing up all memory held for it, and unlinking the |
c378eb4e | 349 | objfile struct from the global list of known objfiles. */ |
c906108c SS |
350 | |
351 | static void | |
fba45db2 | 352 | som_symfile_finish (struct objfile *objfile) |
c906108c | 353 | { |
0a6ddd08 | 354 | if (objfile->deprecated_sym_stab_info != NULL) |
c906108c | 355 | { |
0a6ddd08 | 356 | xfree (objfile->deprecated_sym_stab_info); |
c906108c | 357 | } |
c906108c SS |
358 | } |
359 | ||
360 | /* SOM specific initialization routine for reading symbols. */ | |
361 | ||
362 | static void | |
fba45db2 | 363 | som_symfile_init (struct objfile *objfile) |
c906108c SS |
364 | { |
365 | /* SOM objects may be reordered, so set OBJF_REORDERED. If we | |
366 | find this causes a significant slowdown in gdb then we could | |
367 | set it in the debug symbol readers only when necessary. */ | |
368 | objfile->flags |= OBJF_REORDERED; | |
c906108c SS |
369 | } |
370 | ||
371 | /* SOM specific parsing routine for section offsets. | |
372 | ||
373 | Plain and simple for now. */ | |
374 | ||
d4f3574e | 375 | static void |
fba45db2 | 376 | som_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs) |
c906108c | 377 | { |
c906108c | 378 | int i; |
0aa9cf96 | 379 | CORE_ADDR text_addr; |
c906108c | 380 | |
a39a16c4 | 381 | objfile->num_sections = bfd_count_sections (objfile->obfd); |
d4f3574e | 382 | objfile->section_offsets = (struct section_offsets *) |
8b92e4d5 | 383 | obstack_alloc (&objfile->objfile_obstack, |
a39a16c4 | 384 | SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)); |
c906108c | 385 | |
b8fbeb18 | 386 | /* FIXME: ezannoni 2000-04-20 The section names in SOM are not |
c378eb4e MS |
387 | .text, .data, etc, but $TEXT$, $DATA$,... We should initialize |
388 | SET_OFF_* from bfd. (See default_symfile_offsets()). But I don't | |
b8fbeb18 | 389 | know the correspondence between SOM sections and GDB's idea of |
c378eb4e MS |
390 | section names. So for now we default to what is was before these |
391 | changes. */ | |
b8fbeb18 EZ |
392 | objfile->sect_index_text = 0; |
393 | objfile->sect_index_data = 1; | |
394 | objfile->sect_index_bss = 2; | |
395 | objfile->sect_index_rodata = 3; | |
396 | ||
c906108c | 397 | /* First see if we're a shared library. If so, get the section |
2acceee2 | 398 | offsets from the library, else get them from addrs. */ |
d4f3574e | 399 | if (!som_solib_section_offsets (objfile, objfile->section_offsets)) |
c906108c | 400 | { |
b8fbeb18 EZ |
401 | /* Note: Here is OK to compare with ".text" because this is the |
402 | name that gdb itself gives to that section, not the SOM | |
c378eb4e | 403 | name. */ |
8d498949 | 404 | for (i = 0; i < addrs->num_sections && addrs->other[i].name; i++) |
0aa9cf96 EZ |
405 | if (strcmp (addrs->other[i].name, ".text") == 0) |
406 | break; | |
407 | text_addr = addrs->other[i].addr; | |
408 | ||
a39a16c4 | 409 | for (i = 0; i < objfile->num_sections; i++) |
f0a58b0b | 410 | (objfile->section_offsets)->offsets[i] = text_addr; |
c906108c | 411 | } |
c906108c | 412 | } |
c5aa993b | 413 | \f |
c906108c SS |
414 | |
415 | ||
c906108c SS |
416 | /* Register that we are able to handle SOM object file formats. */ |
417 | ||
00b5771c | 418 | static const struct sym_fns som_sym_fns = |
c906108c SS |
419 | { |
420 | bfd_target_som_flavour, | |
3e43a32a MS |
421 | som_new_init, /* init anything gbl to entire symtab */ |
422 | som_symfile_init, /* read initial info, setup for sym_read() */ | |
423 | som_symfile_read, /* read a symbol file into symtab */ | |
b11896a5 | 424 | NULL, /* sym_read_psymbols */ |
3e43a32a MS |
425 | som_symfile_finish, /* finished with file, cleanup */ |
426 | som_symfile_offsets, /* Translate ext. to int. relocation */ | |
427 | default_symfile_segments, /* Get segment information from a file. */ | |
428 | NULL, | |
429 | default_symfile_relocate, /* Relocate a debug section. */ | |
55aa24fb | 430 | NULL, /* sym_get_probes */ |
00b5771c | 431 | &psym_functions |
c906108c SS |
432 | }; |
433 | ||
434 | void | |
fba45db2 | 435 | _initialize_somread (void) |
c906108c SS |
436 | { |
437 | add_symtab_fns (&som_sym_fns); | |
438 | } |