* som.h (som_symbol_type): Delete unwind field.
[deliverable/binutils-gdb.git] / gdb / nlmread.c
CommitLineData
db85f523 1/* Read NLM (NetWare Loadable Module) format executable files for GDB.
ba47c66a 2 Copyright 1993, 1994 Free Software Foundation, Inc.
db85f523
FF
3 Written by Fred Fish at Cygnus Support (fnf@cygnus.com).
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"
ba47c66a 22#include <string.h>
db85f523
FF
23#include "bfd.h"
24#include "symtab.h"
25#include "symfile.h"
26#include "objfiles.h"
27#include "gdb-stabs.h"
100f92e2 28#include "buildsym.h"
6a6fe3db 29#include "stabsread.h"
db85f523
FF
30
31static void
32nlm_new_init PARAMS ((struct objfile *));
33
34static void
35nlm_symfile_init PARAMS ((struct objfile *));
36
37static void
38nlm_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int));
39
40static void
41nlm_symfile_finish PARAMS ((struct objfile *));
42
43static void
44nlm_symtab_read PARAMS ((bfd *, CORE_ADDR, struct objfile *));
45
46static struct section_offsets *
47nlm_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR));
48
49static void
50record_minimal_symbol PARAMS ((char *, CORE_ADDR, enum minimal_symbol_type,
51 struct objfile *));
52
53
54/* Initialize anything that needs initializing when a completely new symbol
55 file is specified (not just adding some symbols from another file, e.g. a
56 shared library).
57
58 We reinitialize buildsym, since gdb will be able to read stabs from an NLM
59 file at some point in the near future. */
60
61static void
62nlm_new_init (ignore)
63 struct objfile *ignore;
64{
65 stabsread_new_init ();
66 buildsym_new_init ();
67}
68
69
70/* NLM specific initialization routine for reading symbols.
71
72 It is passed a pointer to a struct sym_fns which contains, among other
73 things, the BFD for the file whose symbols are being read, and a slot for
74 a pointer to "private data" which we can fill with goodies.
75
76 For now at least, we have nothing in particular to do, so this function is
77 just a stub. */
78
79static void
80nlm_symfile_init (ignore)
81 struct objfile *ignore;
82{
83}
84
85static void
86record_minimal_symbol (name, address, ms_type, objfile)
87 char *name;
88 CORE_ADDR address;
89 enum minimal_symbol_type ms_type;
90 struct objfile *objfile;
91{
92 name = obsavestring (name, strlen (name), &objfile -> symbol_obstack);
8d60affd 93 prim_record_minimal_symbol (name, address, ms_type, objfile);
db85f523
FF
94}
95
96
97/*
98
99LOCAL FUNCTION
100
101 nlm_symtab_read -- read the symbol table of an NLM file
102
103SYNOPSIS
104
105 void nlm_symtab_read (bfd *abfd, CORE_ADDR addr,
106 struct objfile *objfile)
107
108DESCRIPTION
109
110 Given an open bfd, a base address to relocate symbols to, and a
111 flag that specifies whether or not this bfd is for an executable
112 or not (may be shared library for example), add all the global
113 function and data symbols to the minimal symbol table.
114*/
115
116static void
117nlm_symtab_read (abfd, addr, objfile)
118 bfd *abfd;
119 CORE_ADDR addr;
120 struct objfile *objfile;
121{
70f42bae 122 long storage_needed;
db85f523
FF
123 asymbol *sym;
124 asymbol **symbol_table;
70f42bae
ILT
125 long number_of_symbols;
126 long i;
db85f523
FF
127 struct cleanup *back_to;
128 CORE_ADDR symaddr;
129 enum minimal_symbol_type ms_type;
130
70f42bae
ILT
131 storage_needed = bfd_get_symtab_upper_bound (abfd);
132 if (storage_needed < 0)
133 error ("Can't read symbols from %s: %s", bfd_get_filename (abfd),
134 bfd_errmsg (bfd_get_error ()));
db85f523
FF
135 if (storage_needed > 0)
136 {
137 symbol_table = (asymbol **) xmalloc (storage_needed);
138 back_to = make_cleanup (free, symbol_table);
139 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
70f42bae
ILT
140 if (number_of_symbols < 0)
141 error ("Can't read symbols from %s: %s", bfd_get_filename (abfd),
142 bfd_errmsg (bfd_get_error ()));
db85f523
FF
143
144 for (i = 0; i < number_of_symbols; i++)
145 {
146 sym = symbol_table[i];
a66e8382 147 if (/*sym -> flags & BSF_GLOBAL*/ 1)
db85f523
FF
148 {
149 /* Bfd symbols are section relative. */
150 symaddr = sym -> value + sym -> section -> vma;
151 /* Relocate all non-absolute symbols by base address. */
152 if (sym -> section != &bfd_abs_section)
a4b4f520 153 symaddr += addr;
db85f523
FF
154
155 /* For non-absolute symbols, use the type of the section
a4b4f520 156 they are relative to, to intuit text/data. BFD provides
db85f523
FF
157 no way of figuring this out for absolute symbols. */
158 if (sym -> section -> flags & SEC_CODE)
a4b4f520 159 ms_type = mst_text;
db85f523 160 else if (sym -> section -> flags & SEC_DATA)
a4b4f520 161 ms_type = mst_data;
db85f523 162 else
a4b4f520
SG
163 ms_type = mst_unknown;
164
db85f523
FF
165 record_minimal_symbol ((char *) sym -> name, symaddr, ms_type,
166 objfile);
167 }
168 }
169 do_cleanups (back_to);
170 }
171}
172
173
174/* Scan and build partial symbols for a symbol file.
175 We have been initialized by a call to nlm_symfile_init, which
176 currently does nothing.
177
178 SECTION_OFFSETS is a set of offsets to apply to relocate the symbols
179 in each section. We simplify it down to a single offset for all
180 symbols. FIXME.
181
182 MAINLINE is true if we are reading the main symbol
183 table (as opposed to a shared lib or dynamically loaded file).
184
185 This function only does the minimum work necessary for letting the
186 user "name" things symbolically; it does not read the entire symtab.
187 Instead, it reads the external and static symbols and puts them in partial
188 symbol tables. When more extensive information is requested of a
189 file, the corresponding partial symbol table is mutated into a full
190 fledged symbol table by going back and reading the symbols
191 for real.
192
193 Note that NLM files have two sets of information that is potentially
194 useful for building gdb's minimal symbol table. The first is a list
195 of the publically exported symbols, and is currently used to build
196 bfd's canonical symbol table. The second is an optional native debugging
197 format which contains additional symbols (and possibly duplicates of
198 the publically exported symbols). The optional native debugging format
199 is not currently used. */
200
201static void
202nlm_symfile_read (objfile, section_offsets, mainline)
203 struct objfile *objfile;
204 struct section_offsets *section_offsets;
205 int mainline;
206{
207 bfd *abfd = objfile -> obfd;
208 struct cleanup *back_to;
209 CORE_ADDR offset;
a4b4f520 210 struct symbol *mainsym;
db85f523
FF
211
212 init_minimal_symbol_collection ();
213 back_to = make_cleanup (discard_minimal_symbols, 0);
214
215 /* FIXME, should take a section_offsets param, not just an offset. */
216
217 offset = ANOFFSET (section_offsets, 0);
218
219 /* Process the NLM export records, which become the bfd's canonical symbol
220 table. */
221
222 nlm_symtab_read (abfd, offset, objfile);
223
a66e8382 224 stabsect_build_psymtabs (objfile, section_offsets, mainline, ".stab",
6a86fa48 225 ".stabstr", ".text");
a66e8382 226
a4b4f520
SG
227 mainsym = lookup_symbol ("main", NULL, VAR_NAMESPACE, NULL, NULL);
228
229 if (mainsym
7314b3ee 230 && SYMBOL_CLASS(mainsym) == LOC_BLOCK)
a4b4f520
SG
231 {
232 objfile->ei.main_func_lowpc = BLOCK_START (SYMBOL_BLOCK_VALUE (mainsym));
233 objfile->ei.main_func_highpc = BLOCK_END (SYMBOL_BLOCK_VALUE (mainsym));
234 }
235
db85f523
FF
236 /* FIXME: We could locate and read the optional native debugging format
237 here and add the symbols to the minimal symbol table. */
238
db85f523
FF
239 /* Install any minimal symbols that have been collected as the current
240 minimal symbols for this objfile. */
241
242 install_minimal_symbols (objfile);
243
244 do_cleanups (back_to);
245}
246
247
248/* Perform any local cleanups required when we are done with a particular
249 objfile. I.E, we are in the process of discarding all symbol information
250 for an objfile, freeing up all memory held for it, and unlinking the
251 objfile struct from the global list of known objfiles. */
252
253static void
254nlm_symfile_finish (objfile)
255 struct objfile *objfile;
256{
257 if (objfile -> sym_private != NULL)
258 {
259 mfree (objfile -> md, objfile -> sym_private);
260 }
261}
262
263/* NLM specific parsing routine for section offsets.
264 FIXME: This may or may not be necessary. All the symbol readers seem
265 to have similar code. See if it can be generalized and moved elsewhere. */
266
267static
268struct section_offsets *
269nlm_symfile_offsets (objfile, addr)
270 struct objfile *objfile;
271 CORE_ADDR addr;
272{
273 struct section_offsets *section_offsets;
274 int i;
4d57c599
JK
275
276 objfile->num_sections = SECT_OFF_MAX;
db85f523
FF
277 section_offsets = (struct section_offsets *)
278 obstack_alloc (&objfile -> psymbol_obstack,
279 sizeof (struct section_offsets) +
280 sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1));
281
282 for (i = 0; i < SECT_OFF_MAX; i++)
283 {
284 ANOFFSET (section_offsets, i) = addr;
285 }
286
287 return (section_offsets);
288}
289
290\f
4d57c599 291/* Register that we are able to handle NLM file format. */
db85f523
FF
292
293static struct sym_fns nlm_sym_fns =
294{
0eed42de 295 bfd_target_nlm_flavour,
db85f523
FF
296 nlm_new_init, /* sym_new_init: init anything gbl to entire symtab */
297 nlm_symfile_init, /* sym_init: read initial info, setup for sym_read() */
298 nlm_symfile_read, /* sym_read: read a symbol file into symtab */
299 nlm_symfile_finish, /* sym_finish: finished with file, cleanup */
300 nlm_symfile_offsets, /* sym_offsets: Translate ext. to int. relocation */
301 NULL /* next: pointer to next struct sym_fns */
302};
303
304void
305_initialize_nlmread ()
306{
307 add_symtab_fns (&nlm_sym_fns);
308}
This page took 0.098049 seconds and 4 git commands to generate.