1 /* Read HP PA/Risc object files for GDB.
2 Copyright 1991, 1992 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /************************************************************************
25 * This file is still under construction. When it is complete, this *
26 * notice will be removed. Until then, direct any questions or changes *
27 * to Fred Fish at Cygnus Support (fnf@cygnus.com) *
29 * FIXME Still needs support for shared libraries. *
30 * FIXME Still needs support for core files. *
31 * FIXME The ".debug" and ".line" section names are hardwired. *
33 ************************************************************************/
44 #include "gdb-stabs.h"
45 #include "complaints.h"
50 /* Various things we might complain about... */
53 pa_symfile_init PARAMS ((struct objfile *));
56 pa_new_init PARAMS ((struct objfile *));
59 pa_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int));
62 pa_symfile_finish PARAMS ((struct objfile *));
65 pa_symtab_read PARAMS ((bfd *, CORE_ADDR, struct objfile *));
68 free_painfo PARAMS ((PTR));
70 static struct section_offsets *
71 pa_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR));
74 record_minimal_symbol PARAMS ((char *, CORE_ADDR,
75 enum minimal_symbol_type,
79 record_minimal_symbol (name, address, ms_type, objfile)
82 enum minimal_symbol_type ms_type;
83 struct objfile *objfile;
85 name = obsavestring (name, strlen (name), &objfile -> symbol_obstack);
86 prim_record_minimal_symbol (name, address, ms_type);
93 pa_symtab_read -- read the symbol table of a PA file
97 void pa_symtab_read (bfd *abfd, CORE_ADDR addr,
98 struct objfile *objfile)
102 Given an open bfd, a base address to relocate symbols to, and a
103 flag that specifies whether or not this bfd is for an executable
104 or not (may be shared library for example), add all the global
105 function and data symbols to the minimal symbol table.
109 pa_symtab_read (abfd, addr, objfile)
112 struct objfile *objfile;
114 unsigned int number_of_symbols;
118 struct symbol_dictionary_record *buf, *bufp;
120 number_of_symbols = obj_hp_sym_count (abfd);
122 buf = alloca (obj_hp_symbol_entry_size (abfd) * number_of_symbols);
123 bfd_seek (abfd, obj_hp_sym_filepos (abfd), L_SET);
124 val = bfd_read (buf, obj_hp_symbol_entry_size (abfd) * number_of_symbols,
126 if (val != obj_hp_symbol_entry_size (abfd) * number_of_symbols)
127 error ("Couldn't read symbol dictionary!");
129 stringtab = alloca (obj_hp_stringtab_size (abfd));
130 bfd_seek (abfd, obj_hp_str_filepos (abfd), L_SET);
131 val = bfd_read (stringtab, obj_hp_stringtab_size (abfd), 1, abfd);
132 if (val != obj_hp_stringtab_size (abfd))
133 error ("Can't read in HP string table.");
135 for (i = 0, bufp = buf; i < number_of_symbols; i++, bufp++)
137 enum minimal_symbol_type ms_type;
141 if (bufp->symbol_scope != SS_UNIVERSAL)
144 switch (bufp->symbol_type)
155 bufp->symbol_value &= ~0x3; /* clear out permission bits */
164 if (bufp->name.n_strx > obj_hp_stringtab_size (abfd))
165 error ("Invalid symbol data; bad HP string table offset: %d",
168 record_minimal_symbol (bufp->name.n_strx + stringtab,
169 bufp->symbol_value, ms_type,
173 install_minimal_symbols (objfile);
176 /* Scan and build partial symbols for a symbol file.
177 We have been initialized by a call to pa_symfile_init, which
178 currently does nothing.
180 SECTION_OFFSETS is a set of offsets to apply to relocate the symbols
181 in each section. This is ignored, as it isn't needed for the PA.
183 MAINLINE is true if we are reading the main symbol
184 table (as opposed to a shared lib or dynamically loaded file).
186 This function only does the minimum work necessary for letting the
187 user "name" things symbolically; it does not read the entire symtab.
188 Instead, it reads the external and static symbols and puts them in partial
189 symbol tables. When more extensive information is requested of a
190 file, the corresponding partial symbol table is mutated into a full
191 fledged symbol table by going back and reading the symbols
194 We look for sections with specific names, to tell us what debug
195 format to look for: FIXME!!!
197 pastab_build_psymtabs() handles STABS symbols.
199 Note that PA files have a "minimal" symbol table, which is vaguely
200 reminiscent of a COFF symbol table, but has only the minimal information
201 necessary for linking. We process this also, and use the information to
202 build gdb's minimal symbol table. This gives us some minimal debugging
203 capability even for files compiled without -g. */
206 pa_symfile_read (objfile, section_offsets, mainline)
207 struct objfile *objfile;
208 struct section_offsets *section_offsets;
211 bfd *abfd = objfile->obfd;
212 struct cleanup *back_to;
215 init_minimal_symbol_collection ();
216 back_to = make_cleanup (discard_minimal_symbols, 0);
218 make_cleanup (free_painfo, (PTR) objfile);
220 /* Process the normal PA symbol table first. */
222 /* FIXME, should take a section_offsets param, not just an offset. */
224 offset = ANOFFSET (section_offsets, 0);
225 pa_symtab_read (abfd, offset, objfile);
227 /* Now process debugging information, which is contained in
228 special PA sections. */
230 pastab_build_psymtabs (objfile, section_offsets, mainline);
232 do_cleanups (back_to);
235 /* This cleans up the objfile's sym_private pointer, and the chain of
236 stab_section_info's, that might be dangling from it. */
242 struct objfile *objfile = (struct objfile *)objp;
243 struct dbx_symfile_info *dbxinfo = (struct dbx_symfile_info *)
244 objfile->sym_private;
245 struct stab_section_info *ssi, *nssi;
247 ssi = dbxinfo->stab_section_info;
251 mfree (objfile->md, ssi);
255 dbxinfo->stab_section_info = 0; /* Just say No mo info about this. */
258 /* Initialize anything that needs initializing when a completely new symbol
259 file is specified (not just adding some symbols from another file, e.g. a
262 We reinitialize buildsym, since we may be reading stabs from a PA file. */
266 struct objfile *ignore;
268 stabsread_new_init ();
269 buildsym_new_init ();
272 /* Perform any local cleanups required when we are done with a particular
273 objfile. I.E, we are in the process of discarding all symbol information
274 for an objfile, freeing up all memory held for it, and unlinking the
275 objfile struct from the global list of known objfiles. */
278 pa_symfile_finish (objfile)
279 struct objfile *objfile;
281 if (objfile -> sym_private != NULL)
283 mfree (objfile -> md, objfile -> sym_private);
294 stabsect->filepos, /* .stab offset */
295 bfd_get_section_size_before_reloc (stabsect), /* .stab size */
296 stabstringsect->filepos, /* .stabstr offset */
297 bfd_get_section_size_before_reloc (stabstringsect), /* .stabstr size */
298 obj_dbx_symbol_entry_size (abfd));
303 /* PA specific initialization routine for reading symbols.
305 It is passed a pointer to a struct sym_fns which contains, among other
306 things, the BFD for the file whose symbols are being read, and a slot for
307 a pointer to "private data" which we can fill with goodies.
309 This routine is almost a complete ripoff of dbx_symfile_init. The
310 common parts of these routines should be extracted and used instead of
311 duplicating this code. FIXME. */
314 pa_symfile_init (objfile)
315 struct objfile *objfile;
318 bfd *sym_bfd = objfile->obfd;
319 char *name = bfd_get_filename (sym_bfd);
321 /* Allocate struct to keep track of the symfile */
322 objfile->sym_private = (PTR)
323 xmmalloc (objfile -> md, sizeof (struct dbx_symfile_info));
325 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
326 #define STRING_TABLE_OFFSET (obj_dbx_str_filepos (sym_bfd))
327 #define SYMBOL_TABLE_OFFSET (obj_dbx_sym_filepos (sym_bfd))
329 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
331 DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL;
332 DBX_TEXT_SECT (objfile) = bfd_get_section_by_name (sym_bfd, ".text");
333 if (!DBX_TEXT_SECT (objfile))
334 error ("Can't find .text section in symbol file");
336 DBX_SYMBOL_SIZE (objfile) = obj_dbx_symbol_entry_size (sym_bfd);
337 DBX_SYMCOUNT (objfile) = obj_dbx_sym_count (sym_bfd);
338 DBX_SYMTAB_OFFSET (objfile) = SYMBOL_TABLE_OFFSET;
340 /* Read the string table and stash it away in the psymbol_obstack. It is
341 only needed as long as we need to expand psymbols into full symbols,
342 so when we blow away the psymbol the string table goes away as well.
343 Note that gdb used to use the results of attempting to malloc the
344 string table, based on the size it read, as a form of sanity check
345 for botched byte swapping, on the theory that a byte swapped string
346 table size would be so totally bogus that the malloc would fail. Now
347 that we put in on the psymbol_obstack, we can't do this since gdb gets
348 a fatal error (out of virtual memory) if the size is bogus. We can
349 however at least check to see if the size is zero or some negative
352 DBX_STRINGTAB_SIZE (objfile) = obj_dbx_stringtab_size (sym_bfd);
354 if (DBX_SYMCOUNT (objfile) == 0
355 || DBX_STRINGTAB_SIZE (objfile) == 0)
358 if (DBX_STRINGTAB_SIZE (objfile) <= 0
359 || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
360 error ("ridiculous string table size (%d bytes).",
361 DBX_STRINGTAB_SIZE (objfile));
363 DBX_STRINGTAB (objfile) =
364 (char *) obstack_alloc (&objfile -> psymbol_obstack,
365 DBX_STRINGTAB_SIZE (objfile));
367 /* Now read in the string table in one big gulp. */
369 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
371 perror_with_name (name);
372 val = bfd_read (DBX_STRINGTAB (objfile), DBX_STRINGTAB_SIZE (objfile), 1,
374 if (val != DBX_STRINGTAB_SIZE (objfile))
375 perror_with_name (name);
378 /* PA specific parsing routine for section offsets.
380 Plain and simple for now. */
382 static struct section_offsets *
383 pa_symfile_offsets (objfile, addr)
384 struct objfile *objfile;
387 struct section_offsets *section_offsets;
390 section_offsets = (struct section_offsets *)
391 obstack_alloc (&objfile -> psymbol_obstack,
392 sizeof (struct section_offsets) +
393 sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1));
395 for (i = 0; i < SECT_OFF_MAX; i++)
396 ANOFFSET (section_offsets, i) = addr;
398 return section_offsets;
401 /* Register that we are able to handle PA object file formats. */
403 /* This is probably a mistake. FIXME. Why can't the HP's use an ordinary
404 file format name with an -hppa suffix? */
405 static struct sym_fns pa_sym_fns =
407 "hppa", /* sym_name: name or name prefix of BFD target type */
408 4, /* sym_namelen: number of significant sym_name chars */
409 pa_new_init, /* sym_new_init: init anything gbl to entire symtab */
410 pa_symfile_init, /* sym_init: read initial info, setup for sym_read() */
411 pa_symfile_read, /* sym_read: read a symbol file into symtab */
412 pa_symfile_finish, /* sym_finish: finished with file, cleanup */
413 pa_symfile_offsets, /* sym_offsets: Translate ext. to int. relocation */
414 NULL /* next: pointer to next struct sym_fns */
418 _initialize_paread ()
420 add_symtab_fns (&pa_sym_fns);