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