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"
49 #include "aout/aout64.h"
51 /* Various things we might complain about... */
54 pa_symfile_init
PARAMS ((struct objfile
*));
57 pa_new_init
PARAMS ((struct objfile
*));
60 pa_symfile_read
PARAMS ((struct objfile
*, struct section_offsets
*, int));
63 pa_symfile_finish
PARAMS ((struct objfile
*));
66 pa_symtab_read
PARAMS ((bfd
*, CORE_ADDR
, struct objfile
*));
69 free_painfo
PARAMS ((PTR
));
71 static struct section_offsets
*
72 pa_symfile_offsets
PARAMS ((struct objfile
*, CORE_ADDR
));
75 record_minimal_symbol
PARAMS ((char *, CORE_ADDR
,
76 enum minimal_symbol_type
,
80 record_minimal_symbol (name
, address
, ms_type
, objfile
)
83 enum minimal_symbol_type ms_type
;
84 struct objfile
*objfile
;
86 name
= obsavestring (name
, strlen (name
), &objfile
-> symbol_obstack
);
87 prim_record_minimal_symbol (name
, address
, ms_type
);
94 pa_symtab_read -- read the symbol table of a PA file
98 void pa_symtab_read (bfd *abfd, CORE_ADDR addr,
99 struct objfile *objfile)
103 Given an open bfd, a base address to relocate symbols to, and a
104 flag that specifies whether or not this bfd is for an executable
105 or not (may be shared library for example), add all the global
106 function and data symbols to the minimal symbol table.
110 pa_symtab_read (abfd
, addr
, objfile
)
113 struct objfile
*objfile
;
115 unsigned int number_of_symbols
;
119 struct symbol_dictionary_record
*buf
, *bufp
;
120 CONST
int symsize
= sizeof (struct symbol_dictionary_record
);
122 number_of_symbols
= bfd_get_symcount (abfd
);
124 buf
= alloca (symsize
* number_of_symbols
);
125 bfd_seek (abfd
, obj_sym_filepos (abfd
), L_SET
);
126 val
= bfd_read (buf
, symsize
* number_of_symbols
, 1, abfd
);
127 if (val
!= symsize
* number_of_symbols
)
128 error ("Couldn't read symbol dictionary!");
130 stringtab
= alloca (obj_stringtab_size (abfd
));
131 bfd_seek (abfd
, obj_str_filepos (abfd
), L_SET
);
132 val
= bfd_read (stringtab
, obj_stringtab_size (abfd
), 1, abfd
);
133 if (val
!= obj_stringtab_size (abfd
))
134 error ("Can't read in HP string table.");
136 for (i
= 0, bufp
= buf
; i
< number_of_symbols
; i
++, bufp
++)
138 enum minimal_symbol_type ms_type
;
142 if (bufp
->symbol_scope
!= SS_UNIVERSAL
)
145 switch (bufp
->symbol_type
)
156 bufp
->symbol_value
&= ~0x3; /* clear out permission bits */
165 if (bufp
->name
.n_strx
> obj_stringtab_size (abfd
))
166 error ("Invalid symbol data; bad HP string table offset: %d",
169 record_minimal_symbol (bufp
->name
.n_strx
+ stringtab
,
170 bufp
->symbol_value
, ms_type
,
174 install_minimal_symbols (objfile
);
177 /* Scan and build partial symbols for a symbol file.
178 We have been initialized by a call to pa_symfile_init, which
179 currently does nothing.
181 SECTION_OFFSETS is a set of offsets to apply to relocate the symbols
182 in each section. This is ignored, as it isn't needed for the PA.
184 MAINLINE is true if we are reading the main symbol
185 table (as opposed to a shared lib or dynamically loaded file).
187 This function only does the minimum work necessary for letting the
188 user "name" things symbolically; it does not read the entire symtab.
189 Instead, it reads the external and static symbols and puts them in partial
190 symbol tables. When more extensive information is requested of a
191 file, the corresponding partial symbol table is mutated into a full
192 fledged symbol table by going back and reading the symbols
195 We look for sections with specific names, to tell us what debug
196 format to look for: FIXME!!!
198 pastab_build_psymtabs() handles STABS symbols.
200 Note that PA files have a "minimal" symbol table, which is vaguely
201 reminiscent of a COFF symbol table, but has only the minimal information
202 necessary for linking. We process this also, and use the information to
203 build gdb's minimal symbol table. This gives us some minimal debugging
204 capability even for files compiled without -g. */
207 pa_symfile_read (objfile
, section_offsets
, mainline
)
208 struct objfile
*objfile
;
209 struct section_offsets
*section_offsets
;
212 bfd
*abfd
= objfile
->obfd
;
213 struct cleanup
*back_to
;
216 init_minimal_symbol_collection ();
217 back_to
= make_cleanup (discard_minimal_symbols
, 0);
219 make_cleanup (free_painfo
, (PTR
) objfile
);
221 /* Process the normal PA symbol table first. */
223 /* FIXME, should take a section_offsets param, not just an offset. */
225 offset
= ANOFFSET (section_offsets
, 0);
226 pa_symtab_read (abfd
, offset
, objfile
);
228 /* Now process debugging information, which is contained in
229 special PA sections. */
231 pastab_build_psymtabs (objfile
, section_offsets
, mainline
);
233 do_cleanups (back_to
);
236 /* This cleans up the objfile's sym_private pointer, and the chain of
237 stab_section_info's, that might be dangling from it. */
243 struct objfile
*objfile
= (struct objfile
*)objp
;
244 struct dbx_symfile_info
*dbxinfo
= (struct dbx_symfile_info
*)
245 objfile
->sym_private
;
246 struct stab_section_info
*ssi
, *nssi
;
248 ssi
= dbxinfo
->stab_section_info
;
252 mfree (objfile
->md
, ssi
);
256 dbxinfo
->stab_section_info
= 0; /* Just say No mo info about this. */
259 /* Initialize anything that needs initializing when a completely new symbol
260 file is specified (not just adding some symbols from another file, e.g. a
263 We reinitialize buildsym, since we may be reading stabs from a PA file. */
267 struct objfile
*ignore
;
269 stabsread_new_init ();
270 buildsym_new_init ();
273 /* Perform any local cleanups required when we are done with a particular
274 objfile. I.E, we are in the process of discarding all symbol information
275 for an objfile, freeing up all memory held for it, and unlinking the
276 objfile struct from the global list of known objfiles. */
279 pa_symfile_finish (objfile
)
280 struct objfile
*objfile
;
282 if (objfile
-> sym_private
!= NULL
)
284 mfree (objfile
-> md
, objfile
-> sym_private
);
288 /* PA specific initialization routine for reading symbols.
290 It is passed a pointer to a struct sym_fns which contains, among other
291 things, the BFD for the file whose symbols are being read, and a slot for
292 a pointer to "private data" which we can fill with goodies.
294 This routine is almost a complete ripoff of dbx_symfile_init. The
295 common parts of these routines should be extracted and used instead of
296 duplicating this code. FIXME. */
299 pa_symfile_init (objfile
)
300 struct objfile
*objfile
;
303 bfd
*sym_bfd
= objfile
->obfd
;
304 char *name
= bfd_get_filename (sym_bfd
);
305 asection
*stabsect
; /* Section containing symbol table entries */
306 asection
*stringsect
; /* Section containing symbol name strings */
308 stabsect
= bfd_get_section_by_name (sym_bfd
, "$GDB_SYMBOLS$");
309 stringsect
= bfd_get_section_by_name (sym_bfd
, "$GDB_STRINGS$");
311 /* Allocate struct to keep track of the symfile */
312 objfile
->sym_private
= (PTR
)
313 xmmalloc (objfile
-> md
, sizeof (struct dbx_symfile_info
));
315 memset ((PTR
) objfile
->sym_private
, 0, sizeof (struct dbx_symfile_info
));
321 error ("Found stabs, but not string section");
323 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
324 #define STRING_TABLE_OFFSET (stringsect->filepos)
325 #define SYMBOL_TABLE_OFFSET (stabsect->filepos)
327 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
329 DBX_SYMFILE_INFO (objfile
)->stab_section_info
= NULL
;
330 DBX_TEXT_SECT (objfile
) = bfd_get_section_by_name (sym_bfd
, ".text");
331 if (!DBX_TEXT_SECT (objfile
))
332 error ("Can't find .text section in symbol file");
334 DBX_SYMBOL_SIZE (objfile
) = sizeof (struct internal_nlist
);
335 DBX_SYMCOUNT (objfile
) = bfd_section_size (sym_bfd
, stabsect
)
336 / DBX_SYMBOL_SIZE (objfile
);
337 DBX_SYMTAB_OFFSET (objfile
) = SYMBOL_TABLE_OFFSET
;
339 /* Read the string table and stash it away in the psymbol_obstack. It is
340 only needed as long as we need to expand psymbols into full symbols,
341 so when we blow away the psymbol the string table goes away as well.
342 Note that gdb used to use the results of attempting to malloc the
343 string table, based on the size it read, as a form of sanity check
344 for botched byte swapping, on the theory that a byte swapped string
345 table size would be so totally bogus that the malloc would fail. Now
346 that we put in on the psymbol_obstack, we can't do this since gdb gets
347 a fatal error (out of virtual memory) if the size is bogus. We can
348 however at least check to see if the size is zero or some negative
351 DBX_STRINGTAB_SIZE (objfile
) = bfd_section_size (sym_bfd
, stringsect
);
353 if (DBX_SYMCOUNT (objfile
) == 0
354 || DBX_STRINGTAB_SIZE (objfile
) == 0)
357 if (DBX_STRINGTAB_SIZE (objfile
) <= 0
358 || DBX_STRINGTAB_SIZE (objfile
) > bfd_get_size (sym_bfd
))
359 error ("ridiculous string table size (%d bytes).",
360 DBX_STRINGTAB_SIZE (objfile
));
362 DBX_STRINGTAB (objfile
) =
363 (char *) obstack_alloc (&objfile
-> psymbol_obstack
,
364 DBX_STRINGTAB_SIZE (objfile
));
366 /* Now read in the string table in one big gulp. */
368 val
= bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, L_SET
);
370 perror_with_name (name
);
371 val
= bfd_read (DBX_STRINGTAB (objfile
), DBX_STRINGTAB_SIZE (objfile
), 1,
373 if (val
!= DBX_STRINGTAB_SIZE (objfile
))
374 perror_with_name (name
);
377 /* PA specific parsing routine for section offsets.
379 Plain and simple for now. */
381 static struct section_offsets
*
382 pa_symfile_offsets (objfile
, addr
)
383 struct objfile
*objfile
;
386 struct section_offsets
*section_offsets
;
389 section_offsets
= (struct section_offsets
*)
390 obstack_alloc (&objfile
-> psymbol_obstack
,
391 sizeof (struct section_offsets
) +
392 sizeof (section_offsets
->offsets
) * (SECT_OFF_MAX
-1));
394 for (i
= 0; i
< SECT_OFF_MAX
; i
++)
395 ANOFFSET (section_offsets
, i
) = addr
;
397 return section_offsets
;
400 /* Register that we are able to handle PA object file formats. */
402 /* This is probably a mistake. FIXME. Why can't the HP's use an ordinary
403 file format name with an -hppa suffix? */
404 static struct sym_fns pa_sym_fns
=
406 "hppa", /* sym_name: name or name prefix of BFD target type */
407 4, /* sym_namelen: number of significant sym_name chars */
408 pa_new_init
, /* sym_new_init: init anything gbl to entire symtab */
409 pa_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
410 pa_symfile_read
, /* sym_read: read a symbol file into symtab */
411 pa_symfile_finish
, /* sym_finish: finished with file, cleanup */
412 pa_symfile_offsets
, /* sym_offsets: Translate ext. to int. relocation */
413 NULL
/* next: pointer to next struct sym_fns */
417 _initialize_paread ()
419 add_symtab_fns (&pa_sym_fns
);