1 /* Read HP PA/Risc object files for GDB.
2 Copyright 1991, 1992, 1996 Free Software Foundation, Inc.
3 Written by Fred Fish at Cygnus Support.
5 This file is part of GDB.
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.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #include "stabsread.h"
29 #include "gdb-stabs.h"
30 #include "complaints.h"
31 #include "gdb_string.h"
36 /* Various things we might complain about... */
39 som_symfile_init
PARAMS ((struct objfile
*));
42 som_new_init
PARAMS ((struct objfile
*));
45 som_symfile_read
PARAMS ((struct objfile
*, struct section_offsets
*, int));
48 som_symfile_finish
PARAMS ((struct objfile
*));
51 som_symtab_read
PARAMS ((bfd
*, struct objfile
*,
52 struct section_offsets
*));
54 static struct section_offsets
*
55 som_symfile_offsets
PARAMS ((struct objfile
*, CORE_ADDR
));
57 /* FIXME: These should really be in a common header somewhere */
60 hpread_build_psymtabs
PARAMS ((struct objfile
*, struct section_offsets
*, int));
63 hpread_symfile_finish
PARAMS ((struct objfile
*));
66 hpread_symfile_init
PARAMS ((struct objfile
*));
72 som_symtab_read -- read the symbol table of a SOM file
76 void som_symtab_read (bfd *abfd, struct objfile *objfile,
77 struct section_offsets *section_offsets)
81 Given an open bfd, a base address to relocate symbols to, and a
82 flag that specifies whether or not this bfd is for an executable
83 or not (may be shared library for example), add all the global
84 function and data symbols to the minimal symbol table.
88 som_symtab_read (abfd
, objfile
, section_offsets
)
90 struct objfile
*objfile
;
91 struct section_offsets
*section_offsets
;
93 unsigned int number_of_symbols
;
97 struct symbol_dictionary_record
*buf
, *bufp
, *endbufp
;
99 CONST
int symsize
= sizeof (struct symbol_dictionary_record
);
100 CORE_ADDR text_offset
, data_offset
;
103 text_offset
= ANOFFSET (section_offsets
, 0);
104 data_offset
= ANOFFSET (section_offsets
, 1);
106 number_of_symbols
= bfd_get_symcount (abfd
);
108 buf
= alloca (symsize
* number_of_symbols
);
109 bfd_seek (abfd
, obj_som_sym_filepos (abfd
), SEEK_SET
);
110 val
= bfd_read (buf
, symsize
* number_of_symbols
, 1, abfd
);
111 if (val
!= symsize
* number_of_symbols
)
112 error ("Couldn't read symbol dictionary!");
114 stringtab
= alloca (obj_som_stringtab_size (abfd
));
115 bfd_seek (abfd
, obj_som_str_filepos (abfd
), SEEK_SET
);
116 val
= bfd_read (stringtab
, obj_som_stringtab_size (abfd
), 1, abfd
);
117 if (val
!= obj_som_stringtab_size (abfd
))
118 error ("Can't read in HP string table.");
120 /* We need to determine if objfile is a dynamic executable (so we
121 can do the right thing for ST_ENTRY vs ST_CODE symbols).
123 There's nothing in the header which easily allows us to do
124 this. The only reliable way I know of is to check for the
125 existance of a $SHLIB_INFO$ section with a non-zero size. */
126 shlib_info
= bfd_get_section_by_name (objfile
->obfd
, "$SHLIB_INFO$");
128 dynamic
= (bfd_section_size (objfile
->obfd
, shlib_info
) != 0);
132 endbufp
= buf
+ number_of_symbols
;
133 for (bufp
= buf
; bufp
< endbufp
; ++bufp
)
135 enum minimal_symbol_type ms_type
;
139 switch (bufp
->symbol_scope
)
143 switch (bufp
->symbol_type
)
153 symname
= bufp
->name
.n_strx
+ stringtab
;
155 bufp
->symbol_value
+= text_offset
;
156 #ifdef SMASH_TEXT_ADDRESS
157 SMASH_TEXT_ADDRESS (bufp
->symbol_value
);
162 symname
= bufp
->name
.n_strx
+ stringtab
;
163 /* For a dynamic executable, ST_ENTRY symbols are
164 the stubs, while the ST_CODE symbol is the real
167 ms_type
= mst_solib_trampoline
;
170 bufp
->symbol_value
+= text_offset
;
171 #ifdef SMASH_TEXT_ADDRESS
172 SMASH_TEXT_ADDRESS (bufp
->symbol_value
);
177 symname
= bufp
->name
.n_strx
+ stringtab
;
178 ms_type
= mst_solib_trampoline
;
179 bufp
->symbol_value
+= text_offset
;
180 #ifdef SMASH_TEXT_ADDRESS
181 SMASH_TEXT_ADDRESS (bufp
->symbol_value
);
186 symname
= bufp
->name
.n_strx
+ stringtab
;
187 bufp
->symbol_value
+= data_offset
;
196 /* SS_GLOBAL and SS_LOCAL are two names for the same thing (!). */
200 switch (bufp
->symbol_type
)
207 symname
= bufp
->name
.n_strx
+ stringtab
;
208 ms_type
= mst_file_text
;
209 bufp
->symbol_value
+= text_offset
;
210 #ifdef SMASH_TEXT_ADDRESS
211 SMASH_TEXT_ADDRESS (bufp
->symbol_value
);
215 /* Utah GCC 2.5, FSF GCC 2.6 and later generate correct local
216 label prefixes for stabs, constant data, etc. So we need
217 only filter out L$ symbols which are left in due to
218 limitations in how GAS generates SOM relocations.
220 When linking in the HPUX C-library the HP linker has
221 the nasty habit of placing section symbols from the literal
222 subspaces in the middle of the program's text. Filter
223 those out as best we can. Check for first and last character
226 And finally, the newer HP compilers emit crud like $PIC_foo$N
227 in some circumstance (PIC code I guess). It's also claimed
228 that they emit D$ symbols too. What stupidity. */
229 if ((symname
[0] == 'L' && symname
[1] == '$')
230 || (symname
[0] == '$' && symname
[strlen(symname
) - 1] == '$')
231 || (symname
[0] == 'D' && symname
[1] == '$')
232 || (strncmp (symname
, "$PIC", 4) == 0))
239 symname
= bufp
->name
.n_strx
+ stringtab
;
240 ms_type
= mst_file_text
;
241 bufp
->symbol_value
+= text_offset
;
242 #ifdef SMASH_TEXT_ADDRESS
243 SMASH_TEXT_ADDRESS (bufp
->symbol_value
);
248 symname
= bufp
->name
.n_strx
+ stringtab
;
249 /* For a dynamic executable, ST_ENTRY symbols are
250 the stubs, while the ST_CODE symbol is the real
253 ms_type
= mst_solib_trampoline
;
255 ms_type
= mst_file_text
;
256 bufp
->symbol_value
+= text_offset
;
257 #ifdef SMASH_TEXT_ADDRESS
258 SMASH_TEXT_ADDRESS (bufp
->symbol_value
);
263 symname
= bufp
->name
.n_strx
+ stringtab
;
264 ms_type
= mst_solib_trampoline
;
265 bufp
->symbol_value
+= text_offset
;
266 #ifdef SMASH_TEXT_ADDRESS
267 SMASH_TEXT_ADDRESS (bufp
->symbol_value
);
273 symname
= bufp
->name
.n_strx
+ stringtab
;
274 bufp
->symbol_value
+= data_offset
;
275 ms_type
= mst_file_data
;
276 goto check_strange_names
;
283 /* This can happen for common symbols when -E is passed to the
284 final link. No idea _why_ that would make the linker force
285 common symbols to have an SS_UNSAT scope, but it does. */
287 switch (bufp
->symbol_type
)
290 symname
= bufp
->name
.n_strx
+ stringtab
;
291 bufp
->symbol_value
+= data_offset
;
304 if (bufp
->name
.n_strx
> obj_som_stringtab_size (abfd
))
305 error ("Invalid symbol data; bad HP string table offset: %d",
308 prim_record_minimal_symbol (symname
, bufp
->symbol_value
, ms_type
,
313 /* Scan and build partial symbols for a symbol file.
314 We have been initialized by a call to som_symfile_init, which
315 currently does nothing.
317 SECTION_OFFSETS is a set of offsets to apply to relocate the symbols
318 in each section. This is ignored, as it isn't needed for SOM.
320 MAINLINE is true if we are reading the main symbol
321 table (as opposed to a shared lib or dynamically loaded file).
323 This function only does the minimum work necessary for letting the
324 user "name" things symbolically; it does not read the entire symtab.
325 Instead, it reads the external and static symbols and puts them in partial
326 symbol tables. When more extensive information is requested of a
327 file, the corresponding partial symbol table is mutated into a full
328 fledged symbol table by going back and reading the symbols
331 We look for sections with specific names, to tell us what debug
332 format to look for: FIXME!!!
334 somstab_build_psymtabs() handles STABS symbols.
336 Note that SOM files have a "minimal" symbol table, which is vaguely
337 reminiscent of a COFF symbol table, but has only the minimal information
338 necessary for linking. We process this also, and use the information to
339 build gdb's minimal symbol table. This gives us some minimal debugging
340 capability even for files compiled without -g. */
343 som_symfile_read (objfile
, section_offsets
, mainline
)
344 struct objfile
*objfile
;
345 struct section_offsets
*section_offsets
;
348 bfd
*abfd
= objfile
->obfd
;
349 struct cleanup
*back_to
;
351 init_minimal_symbol_collection ();
352 back_to
= make_cleanup (discard_minimal_symbols
, 0);
354 /* Process the normal SOM symbol table first. */
356 som_symtab_read (abfd
, objfile
, section_offsets
);
358 /* Now read information from the stabs debug sections. */
359 stabsect_build_psymtabs (objfile
, section_offsets
, mainline
,
360 "$GDB_SYMBOLS$", "$GDB_STRINGS$", "$TEXT$");
362 /* Now read the native debug information. */
363 hpread_build_psymtabs (objfile
, section_offsets
, mainline
);
365 /* Install any minimal symbols that have been collected as the current
366 minimal symbols for this objfile. */
367 install_minimal_symbols (objfile
);
369 /* Force hppa-tdep.c to re-read the unwind descriptors. */
370 objfile
->obj_private
= NULL
;
371 do_cleanups (back_to
);
374 /* Initialize anything that needs initializing when a completely new symbol
375 file is specified (not just adding some symbols from another file, e.g. a
378 We reinitialize buildsym, since we may be reading stabs from a SOM file. */
381 som_new_init (ignore
)
382 struct objfile
*ignore
;
384 stabsread_new_init ();
385 buildsym_new_init ();
388 /* Perform any local cleanups required when we are done with a particular
389 objfile. I.E, we are in the process of discarding all symbol information
390 for an objfile, freeing up all memory held for it, and unlinking the
391 objfile struct from the global list of known objfiles. */
394 som_symfile_finish (objfile
)
395 struct objfile
*objfile
;
397 if (objfile
-> sym_stab_info
!= NULL
)
399 mfree (objfile
-> md
, objfile
-> sym_stab_info
);
401 hpread_symfile_finish (objfile
);
404 /* SOM specific initialization routine for reading symbols. */
407 som_symfile_init (objfile
)
408 struct objfile
*objfile
;
410 /* SOM objects may be reordered, so set OBJF_REORDERED. If we
411 find this causes a significant slowdown in gdb then we could
412 set it in the debug symbol readers only when necessary. */
413 objfile
->flags
|= OBJF_REORDERED
;
414 hpread_symfile_init (objfile
);
417 /* SOM specific parsing routine for section offsets.
419 Plain and simple for now. */
421 static struct section_offsets
*
422 som_symfile_offsets (objfile
, addr
)
423 struct objfile
*objfile
;
426 struct section_offsets
*section_offsets
;
429 objfile
->num_sections
= SECT_OFF_MAX
;
430 section_offsets
= (struct section_offsets
*)
431 obstack_alloc (&objfile
-> psymbol_obstack
, SIZEOF_SECTION_OFFSETS
);
433 /* First see if we're a shared library. If so, get the section
434 offsets from the library, else get them from addr. */
435 if (!som_solib_section_offsets (objfile
, section_offsets
))
437 for (i
= 0; i
< SECT_OFF_MAX
; i
++)
438 ANOFFSET (section_offsets
, i
) = addr
;
441 return section_offsets
;
444 /* Register that we are able to handle SOM object file formats. */
446 static struct sym_fns som_sym_fns
=
448 bfd_target_som_flavour
,
449 som_new_init
, /* sym_new_init: init anything gbl to entire symtab */
450 som_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
451 som_symfile_read
, /* sym_read: read a symbol file into symtab */
452 som_symfile_finish
, /* sym_finish: finished with file, cleanup */
453 som_symfile_offsets
, /* sym_offsets: Translate ext. to int. relocation */
454 NULL
/* next: pointer to next struct sym_fns */
458 _initialize_somread ()
460 add_symtab_fns (&som_sym_fns
);