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