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