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. */
30 #include "stabsread.h"
31 #include "gdb-stabs.h"
32 #include "complaints.h"
33 #include "gdb_string.h"
37 /* Various things we might complain about... */
40 som_symfile_init PARAMS ((struct objfile *));
43 som_new_init PARAMS ((struct objfile *));
46 som_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int));
49 som_symfile_finish PARAMS ((struct objfile *));
52 som_symtab_read PARAMS ((bfd *, struct objfile *,
53 struct section_offsets *));
55 static struct section_offsets *
56 som_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR));
59 record_minimal_symbol PARAMS ((char *, CORE_ADDR,
60 enum minimal_symbol_type,
64 record_minimal_symbol (name, address, ms_type, objfile)
67 enum minimal_symbol_type ms_type;
68 struct objfile *objfile;
70 name = obsavestring (name, strlen (name), &objfile -> symbol_obstack);
71 prim_record_minimal_symbol (name, address, ms_type, objfile);
78 som_symtab_read -- read the symbol table of a SOM file
82 void som_symtab_read (bfd *abfd, struct objfile *objfile,
83 struct section_offsets *section_offsets)
87 Given an open bfd, a base address to relocate symbols to, and a
88 flag that specifies whether or not this bfd is for an executable
89 or not (may be shared library for example), add all the global
90 function and data symbols to the minimal symbol table.
94 som_symtab_read (abfd, objfile, section_offsets)
96 struct objfile *objfile;
97 struct section_offsets *section_offsets;
99 unsigned int number_of_symbols;
102 asection *shlib_info;
103 struct symbol_dictionary_record *buf, *bufp, *endbufp;
105 CONST int symsize = sizeof (struct symbol_dictionary_record);
106 CORE_ADDR text_offset, data_offset;
109 text_offset = ANOFFSET (section_offsets, 0);
110 data_offset = ANOFFSET (section_offsets, 1);
112 number_of_symbols = bfd_get_symcount (abfd);
114 buf = alloca (symsize * number_of_symbols);
115 bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET);
116 val = bfd_read (buf, symsize * number_of_symbols, 1, abfd);
117 if (val != symsize * number_of_symbols)
118 error ("Couldn't read symbol dictionary!");
120 stringtab = alloca (obj_som_stringtab_size (abfd));
121 bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET);
122 val = bfd_read (stringtab, obj_som_stringtab_size (abfd), 1, abfd);
123 if (val != obj_som_stringtab_size (abfd))
124 error ("Can't read in HP string table.");
126 /* We need to determine if objfile is a dynamic executable (so we
127 can do the right thing for ST_ENTRY vs ST_CODE symbols).
129 There's nothing in the header which easily allows us to do
130 this. The only reliable way I know of is to check for the
131 existance of a $SHLIB_INFO$ section with a non-zero size. */
132 shlib_info = bfd_get_section_by_name (objfile->obfd, "$SHLIB_INFO$");
134 dynamic = (bfd_section_size (objfile->obfd, shlib_info) != 0);
138 endbufp = buf + number_of_symbols;
139 for (bufp = buf; bufp < endbufp; ++bufp)
141 enum minimal_symbol_type ms_type;
145 switch (bufp->symbol_scope)
149 switch (bufp->symbol_type)
159 symname = bufp->name.n_strx + stringtab;
161 bufp->symbol_value += text_offset;
162 #ifdef SMASH_TEXT_ADDRESS
163 SMASH_TEXT_ADDRESS (bufp->symbol_value);
168 symname = bufp->name.n_strx + stringtab;
169 /* For a dynamic executable, ST_ENTRY symbols are
170 the stubs, while the ST_CODE symbol is the real
173 ms_type = mst_solib_trampoline;
176 bufp->symbol_value += text_offset;
177 #ifdef SMASH_TEXT_ADDRESS
178 SMASH_TEXT_ADDRESS (bufp->symbol_value);
183 symname = bufp->name.n_strx + stringtab;
184 ms_type = mst_solib_trampoline;
185 bufp->symbol_value += text_offset;
186 #ifdef SMASH_TEXT_ADDRESS
187 SMASH_TEXT_ADDRESS (bufp->symbol_value);
192 symname = bufp->name.n_strx + stringtab;
193 bufp->symbol_value += data_offset;
202 /* SS_GLOBAL and SS_LOCAL are two names for the same thing (!). */
206 switch (bufp->symbol_type)
213 symname = bufp->name.n_strx + stringtab;
214 ms_type = mst_file_text;
215 bufp->symbol_value += text_offset;
216 #ifdef SMASH_TEXT_ADDRESS
217 SMASH_TEXT_ADDRESS (bufp->symbol_value);
221 /* Utah GCC 2.5, FSF GCC 2.6 and later generate correct local
222 label prefixes for stabs, constant data, etc. So we need
223 only filter out L$ symbols which are left in due to
224 limitations in how GAS generates SOM relocations.
226 When linking in the HPUX C-library the HP linker has
227 the nasty habit of placing section symbols from the literal
228 subspaces in the middle of the program's text. Filter
229 those out as best we can. Check for first and last character
232 And finally, the newer HP compilers emit crud like $PIC_foo$N
233 in some circumstance (PIC code I guess). It's also claimed
234 that they emit D$ symbols too. What stupidity. */
235 if ((symname[0] == 'L' && symname[1] == '$')
236 || (symname[0] == '$' && symname[strlen(symname) - 1] == '$')
237 || (symname[0] == 'D' && symname[1] == '$')
238 || (strncmp (symname, "$PIC", 4) == 0))
245 symname = bufp->name.n_strx + stringtab;
246 ms_type = mst_file_text;
247 bufp->symbol_value += text_offset;
248 #ifdef SMASH_TEXT_ADDRESS
249 SMASH_TEXT_ADDRESS (bufp->symbol_value);
254 symname = bufp->name.n_strx + stringtab;
255 /* For a dynamic executable, ST_ENTRY symbols are
256 the stubs, while the ST_CODE symbol is the real
259 ms_type = mst_solib_trampoline;
261 ms_type = mst_file_text;
262 bufp->symbol_value += text_offset;
263 #ifdef SMASH_TEXT_ADDRESS
264 SMASH_TEXT_ADDRESS (bufp->symbol_value);
269 symname = bufp->name.n_strx + stringtab;
270 ms_type = mst_solib_trampoline;
271 bufp->symbol_value += text_offset;
272 #ifdef SMASH_TEXT_ADDRESS
273 SMASH_TEXT_ADDRESS (bufp->symbol_value);
279 symname = bufp->name.n_strx + stringtab;
280 bufp->symbol_value += data_offset;
281 ms_type = mst_file_data;
282 goto check_strange_names;
289 /* This can happen for common symbols when -E is passed to the
290 final link. No idea _why_ that would make the linker force
291 common symbols to have an SS_UNSAT scope, but it does. */
293 switch (bufp->symbol_type)
296 symname = bufp->name.n_strx + stringtab;
297 bufp->symbol_value += data_offset;
310 if (bufp->name.n_strx > obj_som_stringtab_size (abfd))
311 error ("Invalid symbol data; bad HP string table offset: %d",
314 record_minimal_symbol (symname,
315 bufp->symbol_value, ms_type,
320 /* Scan and build partial symbols for a symbol file.
321 We have been initialized by a call to som_symfile_init, which
322 currently does nothing.
324 SECTION_OFFSETS is a set of offsets to apply to relocate the symbols
325 in each section. This is ignored, as it isn't needed for SOM.
327 MAINLINE is true if we are reading the main symbol
328 table (as opposed to a shared lib or dynamically loaded file).
330 This function only does the minimum work necessary for letting the
331 user "name" things symbolically; it does not read the entire symtab.
332 Instead, it reads the external and static symbols and puts them in partial
333 symbol tables. When more extensive information is requested of a
334 file, the corresponding partial symbol table is mutated into a full
335 fledged symbol table by going back and reading the symbols
338 We look for sections with specific names, to tell us what debug
339 format to look for: FIXME!!!
341 somstab_build_psymtabs() handles STABS symbols.
343 Note that SOM files have a "minimal" symbol table, which is vaguely
344 reminiscent of a COFF symbol table, but has only the minimal information
345 necessary for linking. We process this also, and use the information to
346 build gdb's minimal symbol table. This gives us some minimal debugging
347 capability even for files compiled without -g. */
350 som_symfile_read (objfile, section_offsets, mainline)
351 struct objfile *objfile;
352 struct section_offsets *section_offsets;
355 bfd *abfd = objfile->obfd;
356 struct cleanup *back_to;
358 init_minimal_symbol_collection ();
359 back_to = make_cleanup (discard_minimal_symbols, 0);
361 /* Process the normal SOM symbol table first. */
363 som_symtab_read (abfd, objfile, section_offsets);
365 /* Now read information from the stabs debug sections. */
366 stabsect_build_psymtabs (objfile, section_offsets, mainline,
367 "$GDB_SYMBOLS$", "$GDB_STRINGS$", "$TEXT$");
369 /* Now read the native debug information. */
370 hpread_build_psymtabs (objfile, section_offsets, mainline);
372 /* Install any minimal symbols that have been collected as the current
373 minimal symbols for this objfile. */
374 install_minimal_symbols (objfile);
376 /* Force hppa-tdep.c to re-read the unwind descriptors. */
377 objfile->obj_private = NULL;
378 do_cleanups (back_to);
381 /* Initialize anything that needs initializing when a completely new symbol
382 file is specified (not just adding some symbols from another file, e.g. a
385 We reinitialize buildsym, since we may be reading stabs from a SOM file. */
388 som_new_init (ignore)
389 struct objfile *ignore;
391 stabsread_new_init ();
392 buildsym_new_init ();
395 /* Perform any local cleanups required when we are done with a particular
396 objfile. I.E, we are in the process of discarding all symbol information
397 for an objfile, freeing up all memory held for it, and unlinking the
398 objfile struct from the global list of known objfiles. */
401 som_symfile_finish (objfile)
402 struct objfile *objfile;
404 if (objfile -> sym_stab_info != NULL)
406 mfree (objfile -> md, objfile -> sym_stab_info);
408 hpread_symfile_finish (objfile);
411 /* SOM specific initialization routine for reading symbols. */
414 som_symfile_init (objfile)
415 struct objfile *objfile;
417 /* SOM objects may be reordered, so set OBJF_REORDERED. If we
418 find this causes a significant slowdown in gdb then we could
419 set it in the debug symbol readers only when necessary. */
420 objfile->flags |= OBJF_REORDERED;
421 hpread_symfile_init (objfile);
424 /* SOM specific parsing routine for section offsets.
426 Plain and simple for now. */
428 static struct section_offsets *
429 som_symfile_offsets (objfile, addr)
430 struct objfile *objfile;
433 struct section_offsets *section_offsets;
436 objfile->num_sections = SECT_OFF_MAX;
437 section_offsets = (struct section_offsets *)
438 obstack_alloc (&objfile -> psymbol_obstack,
439 sizeof (struct section_offsets)
440 + sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1));
442 /* First see if we're a shared library. If so, get the section
443 offsets from the library, else get them from addr. */
444 if (!som_solib_section_offsets (objfile, section_offsets))
446 for (i = 0; i < SECT_OFF_MAX; i++)
447 ANOFFSET (section_offsets, i) = addr;
450 return section_offsets;
453 /* Register that we are able to handle SOM object file formats. */
455 static struct sym_fns som_sym_fns =
457 bfd_target_som_flavour,
458 som_new_init, /* sym_new_init: init anything gbl to entire symtab */
459 som_symfile_init, /* sym_init: read initial info, setup for sym_read() */
460 som_symfile_read, /* sym_read: read a symbol file into symtab */
461 som_symfile_finish, /* sym_finish: finished with file, cleanup */
462 som_symfile_offsets, /* sym_offsets: Translate ext. to int. relocation */
463 NULL /* next: pointer to next struct sym_fns */
467 _initialize_somread ()
469 add_symtab_fns (&som_sym_fns);