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