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