* Makefile.in, gdb.{base,c++,chill}/Makefile.in (GDB, GDBFLAGS):
[deliverable/binutils-gdb.git] / gdb / somread.c
CommitLineData
bfe2f12b
JL
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.
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21#include "defs.h"
22#include "bfd.h"
bfe2f12b
JL
23#include "som.h"
24#include "libhppa.h"
25#include <syms.h>
26#include "symtab.h"
27#include "symfile.h"
28#include "objfiles.h"
29#include "buildsym.h"
30#include "stabsread.h"
31#include "gdb-stabs.h"
32#include "complaints.h"
33#include <string.h>
34#include "demangle.h"
35#include <sys/file.h>
36
bfe2f12b
JL
37/* Various things we might complain about... */
38
39static void
6a86fa48 40som_symfile_init PARAMS ((struct objfile *));
bfe2f12b
JL
41
42static void
43som_new_init PARAMS ((struct objfile *));
44
45static void
46som_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int));
47
48static void
49som_symfile_finish PARAMS ((struct objfile *));
50
51static void
bb140953
JL
52som_symtab_read PARAMS ((bfd *, struct objfile *,
53 struct section_offsets *));
bfe2f12b 54
bfe2f12b
JL
55static struct section_offsets *
56som_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR));
57
58static void
59record_minimal_symbol PARAMS ((char *, CORE_ADDR,
60 enum minimal_symbol_type,
61 struct objfile *));
62
63static void
64record_minimal_symbol (name, address, ms_type, objfile)
65 char *name;
66 CORE_ADDR address;
67 enum minimal_symbol_type ms_type;
68 struct objfile *objfile;
69{
70 name = obsavestring (name, strlen (name), &objfile -> symbol_obstack);
71 prim_record_minimal_symbol (name, address, ms_type, objfile);
72}
73
74/*
75
76LOCAL FUNCTION
77
78 som_symtab_read -- read the symbol table of a SOM file
79
80SYNOPSIS
81
bb140953
JL
82 void som_symtab_read (bfd *abfd, struct objfile *objfile,
83 struct section_offsets *section_offsets)
bfe2f12b
JL
84
85DESCRIPTION
86
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.
91*/
92
93static void
bb140953 94som_symtab_read (abfd, objfile, section_offsets)
bfe2f12b 95 bfd *abfd;
bfe2f12b 96 struct objfile *objfile;
bb140953 97 struct section_offsets *section_offsets;
bfe2f12b
JL
98{
99 unsigned int number_of_symbols;
bfe2f12b
JL
100 int val, dynamic;
101 char *stringtab;
102 asection *shlib_info;
103 struct symbol_dictionary_record *buf, *bufp, *endbufp;
104 char *symname;
105 CONST int symsize = sizeof (struct symbol_dictionary_record);
506af7a7 106 CORE_ADDR text_offset, data_offset;
bb140953
JL
107
108
bb140953 109 text_offset = ANOFFSET (section_offsets, 0);
506af7a7 110 data_offset = ANOFFSET (section_offsets, 1);
bfe2f12b
JL
111
112 number_of_symbols = bfd_get_symcount (abfd);
113
114 buf = alloca (symsize * number_of_symbols);
115 bfd_seek (abfd, obj_som_sym_filepos (abfd), L_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!");
119
120 stringtab = alloca (obj_som_stringtab_size (abfd));
121 bfd_seek (abfd, obj_som_str_filepos (abfd), L_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.");
125
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).
128
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$");
133 if (shlib_info)
134 dynamic = (bfd_section_size (objfile->obfd, shlib_info) != 0);
135 else
136 dynamic = 0;
137
138 endbufp = buf + number_of_symbols;
139 for (bufp = buf; bufp < endbufp; ++bufp)
140 {
141 enum minimal_symbol_type ms_type;
142
143 QUIT;
144
145 switch (bufp->symbol_scope)
146 {
147 case SS_UNIVERSAL:
148 case SS_EXTERNAL:
149 switch (bufp->symbol_type)
150 {
151 case ST_SYM_EXT:
152 case ST_ARG_EXT:
153 continue;
154
155 case ST_CODE:
156 case ST_PRI_PROG:
157 case ST_SEC_PROG:
158 case ST_MILLICODE:
159 symname = bufp->name.n_strx + stringtab;
160 ms_type = mst_text;
bb140953 161 bufp->symbol_value += text_offset;
bfe2f12b
JL
162#ifdef SMASH_TEXT_ADDRESS
163 SMASH_TEXT_ADDRESS (bufp->symbol_value);
164#endif
165 break;
166
167 case ST_ENTRY:
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
171 function. */
172 if (dynamic)
173 ms_type = mst_solib_trampoline;
174 else
175 ms_type = mst_text;
bb140953 176 bufp->symbol_value += text_offset;
bfe2f12b
JL
177#ifdef SMASH_TEXT_ADDRESS
178 SMASH_TEXT_ADDRESS (bufp->symbol_value);
179#endif
180 break;
181
182 case ST_STUB:
183 symname = bufp->name.n_strx + stringtab;
184 ms_type = mst_solib_trampoline;
bb140953 185 bufp->symbol_value += text_offset;
bfe2f12b
JL
186#ifdef SMASH_TEXT_ADDRESS
187 SMASH_TEXT_ADDRESS (bufp->symbol_value);
188#endif
189 break;
190
191 case ST_DATA:
192 symname = bufp->name.n_strx + stringtab;
506af7a7 193 bufp->symbol_value += data_offset;
bfe2f12b
JL
194 ms_type = mst_data;
195 break;
196 default:
197 continue;
198 }
199 break;
200
201#if 0
202 /* SS_GLOBAL and SS_LOCAL are two names for the same thing (!). */
203 case SS_GLOBAL:
204#endif
205 case SS_LOCAL:
206 switch (bufp->symbol_type)
207 {
208 case ST_SYM_EXT:
209 case ST_ARG_EXT:
210 continue;
211
212 case ST_CODE:
213 symname = bufp->name.n_strx + stringtab;
214 ms_type = mst_file_text;
bb140953 215 bufp->symbol_value += text_offset;
bfe2f12b
JL
216#ifdef SMASH_TEXT_ADDRESS
217 SMASH_TEXT_ADDRESS (bufp->symbol_value);
218#endif
219
220 check_strange_names:
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.
225
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
230 being '$'. */
231 if ((symname[0] == 'L' && symname[1] == '$')
232 || (symname[0] == '$' && symname[strlen(symname) - 1] == '$'))
233 continue;
234 break;
235
236 case ST_PRI_PROG:
237 case ST_SEC_PROG:
238 case ST_MILLICODE:
239 symname = bufp->name.n_strx + stringtab;
240 ms_type = mst_file_text;
bb140953 241 bufp->symbol_value += text_offset;
bfe2f12b
JL
242#ifdef SMASH_TEXT_ADDRESS
243 SMASH_TEXT_ADDRESS (bufp->symbol_value);
244#endif
245 break;
246
247 case ST_ENTRY:
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
251 function. */
252 if (dynamic)
253 ms_type = mst_solib_trampoline;
254 else
255 ms_type = mst_file_text;
bb140953 256 bufp->symbol_value += text_offset;
bfe2f12b
JL
257#ifdef SMASH_TEXT_ADDRESS
258 SMASH_TEXT_ADDRESS (bufp->symbol_value);
259#endif
260 break;
261
262 case ST_STUB:
263 symname = bufp->name.n_strx + stringtab;
264 ms_type = mst_solib_trampoline;
bb140953 265 bufp->symbol_value += text_offset;
bfe2f12b
JL
266#ifdef SMASH_TEXT_ADDRESS
267 SMASH_TEXT_ADDRESS (bufp->symbol_value);
268#endif
269 break;
270
271
272 case ST_DATA:
273 symname = bufp->name.n_strx + stringtab;
506af7a7 274 bufp->symbol_value += data_offset;
bfe2f12b
JL
275 ms_type = mst_file_data;
276 goto check_strange_names;
277
278 default:
279 continue;
280 }
281 break;
282
283 default:
284 continue;
285 }
286
287 if (bufp->name.n_strx > obj_som_stringtab_size (abfd))
288 error ("Invalid symbol data; bad HP string table offset: %d",
289 bufp->name.n_strx);
290
291 record_minimal_symbol (symname,
292 bufp->symbol_value, ms_type,
293 objfile);
294 }
bfe2f12b
JL
295}
296
297/* Scan and build partial symbols for a symbol file.
298 We have been initialized by a call to som_symfile_init, which
299 currently does nothing.
300
301 SECTION_OFFSETS is a set of offsets to apply to relocate the symbols
302 in each section. This is ignored, as it isn't needed for SOM.
303
304 MAINLINE is true if we are reading the main symbol
305 table (as opposed to a shared lib or dynamically loaded file).
306
307 This function only does the minimum work necessary for letting the
308 user "name" things symbolically; it does not read the entire symtab.
309 Instead, it reads the external and static symbols and puts them in partial
310 symbol tables. When more extensive information is requested of a
311 file, the corresponding partial symbol table is mutated into a full
312 fledged symbol table by going back and reading the symbols
313 for real.
314
315 We look for sections with specific names, to tell us what debug
316 format to look for: FIXME!!!
317
318 somstab_build_psymtabs() handles STABS symbols.
319
320 Note that SOM files have a "minimal" symbol table, which is vaguely
321 reminiscent of a COFF symbol table, but has only the minimal information
322 necessary for linking. We process this also, and use the information to
323 build gdb's minimal symbol table. This gives us some minimal debugging
324 capability even for files compiled without -g. */
325
326static void
327som_symfile_read (objfile, section_offsets, mainline)
328 struct objfile *objfile;
329 struct section_offsets *section_offsets;
330 int mainline;
331{
332 bfd *abfd = objfile->obfd;
333 struct cleanup *back_to;
bfe2f12b
JL
334
335 init_minimal_symbol_collection ();
336 back_to = make_cleanup (discard_minimal_symbols, 0);
337
6a86fa48 338 /* Process the normal SOM symbol table first. */
bfe2f12b 339
bb140953 340 som_symtab_read (abfd, objfile, section_offsets);
bfe2f12b 341
98c0e047 342 /* Now read information from the stabs debug sections. */
6a86fa48
JL
343 stabsect_build_psymtabs (objfile, section_offsets, mainline,
344 "$GDB_SYMBOLS$", "$GDB_STRINGS$", "$TEXT$");
bfe2f12b 345
98c0e047
JL
346 /* Now read the native debug information. */
347 hpread_build_psymtabs (objfile, section_offsets, mainline);
98c0e047 348
6a86fa48
JL
349 /* Install any minimal symbols that have been collected as the current
350 minimal symbols for this objfile. */
351 install_minimal_symbols (objfile);
bfe2f12b 352
31b2518a 353 /* Force hppa-tdep.c to re-read the unwind descriptors. */
c676d827 354 objfile->obj_private = NULL;
6a86fa48 355 do_cleanups (back_to);
bfe2f12b
JL
356}
357
358/* Initialize anything that needs initializing when a completely new symbol
359 file is specified (not just adding some symbols from another file, e.g. a
360 shared library).
361
362 We reinitialize buildsym, since we may be reading stabs from a SOM file. */
363
364static void
365som_new_init (ignore)
366 struct objfile *ignore;
367{
368 stabsread_new_init ();
369 buildsym_new_init ();
370}
371
372/* Perform any local cleanups required when we are done with a particular
373 objfile. I.E, we are in the process of discarding all symbol information
374 for an objfile, freeing up all memory held for it, and unlinking the
375 objfile struct from the global list of known objfiles. */
376
377static void
378som_symfile_finish (objfile)
379 struct objfile *objfile;
380{
381 if (objfile -> sym_stab_info != NULL)
382 {
383 mfree (objfile -> md, objfile -> sym_stab_info);
384 }
98c0e047 385 hpread_symfile_finish (objfile);
bfe2f12b
JL
386}
387
388/* SOM specific initialization routine for reading symbols.
389
6a86fa48 390 Nothing SOM specific left to do anymore. */
bfe2f12b 391static void
98c0e047
JL
392som_symfile_init (objfile)
393 struct objfile *objfile;
bfe2f12b 394{
98c0e047 395 hpread_symfile_init (objfile);
bfe2f12b
JL
396}
397
398/* SOM specific parsing routine for section offsets.
399
400 Plain and simple for now. */
401
402static struct section_offsets *
403som_symfile_offsets (objfile, addr)
404 struct objfile *objfile;
405 CORE_ADDR addr;
406{
407 struct section_offsets *section_offsets;
408 int i;
409
410 objfile->num_sections = SECT_OFF_MAX;
411 section_offsets = (struct section_offsets *)
412 obstack_alloc (&objfile -> psymbol_obstack,
413 sizeof (struct section_offsets)
414 + sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1));
415
506af7a7
JL
416 /* First see if we're a shared library. If so, get the section
417 offsets from the library, else get them from addr. */
418 if (!som_solib_section_offsets (objfile, section_offsets))
419 {
420 for (i = 0; i < SECT_OFF_MAX; i++)
421 ANOFFSET (section_offsets, i) = addr;
422 }
bfe2f12b
JL
423
424 return section_offsets;
425}
426\f
427/* Register that we are able to handle SOM object file formats. */
428
429static struct sym_fns som_sym_fns =
430{
431 bfd_target_som_flavour,
432 som_new_init, /* sym_new_init: init anything gbl to entire symtab */
433 som_symfile_init, /* sym_init: read initial info, setup for sym_read() */
434 som_symfile_read, /* sym_read: read a symbol file into symtab */
435 som_symfile_finish, /* sym_finish: finished with file, cleanup */
436 som_symfile_offsets, /* sym_offsets: Translate ext. to int. relocation */
437 NULL /* next: pointer to next struct sym_fns */
438};
439
440void
441_initialize_somread ()
442{
443 add_symtab_fns (&som_sym_fns);
444}
This page took 0.071046 seconds and 4 git commands to generate.