1 /* Read NLM (NetWare Loadable Module) format executable files for GDB.
2 Copyright 1993, 1994 Free Software Foundation, Inc.
3 Written by Fred Fish at Cygnus Support (fnf@cygnus.com).
5 This file is part of GDB.
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.
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.
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. */
27 #include "gdb-stabs.h"
29 #include "stabsread.h"
32 nlm_new_init
PARAMS ((struct objfile
*));
35 nlm_symfile_init
PARAMS ((struct objfile
*));
38 nlm_symfile_read
PARAMS ((struct objfile
*, struct section_offsets
*, int));
41 nlm_symfile_finish
PARAMS ((struct objfile
*));
44 nlm_symtab_read
PARAMS ((bfd
*, CORE_ADDR
, struct objfile
*));
46 static struct section_offsets
*
47 nlm_symfile_offsets
PARAMS ((struct objfile
*, CORE_ADDR
));
50 record_minimal_symbol
PARAMS ((char *, CORE_ADDR
, enum minimal_symbol_type
,
54 /* Initialize anything that needs initializing when a completely new symbol
55 file is specified (not just adding some symbols from another file, e.g. a
58 We reinitialize buildsym, since gdb will be able to read stabs from an NLM
59 file at some point in the near future. */
63 struct objfile
*ignore
;
65 stabsread_new_init ();
70 /* NLM specific initialization routine for reading symbols.
72 It is passed a pointer to a struct sym_fns which contains, among other
73 things, the BFD for the file whose symbols are being read, and a slot for
74 a pointer to "private data" which we can fill with goodies.
76 For now at least, we have nothing in particular to do, so this function is
80 nlm_symfile_init (ignore
)
81 struct objfile
*ignore
;
86 record_minimal_symbol (name
, address
, ms_type
, objfile
)
89 enum minimal_symbol_type ms_type
;
90 struct objfile
*objfile
;
92 name
= obsavestring (name
, strlen (name
), &objfile
-> symbol_obstack
);
93 prim_record_minimal_symbol (name
, address
, ms_type
, objfile
);
101 nlm_symtab_read -- read the symbol table of an NLM file
105 void nlm_symtab_read (bfd *abfd, CORE_ADDR addr,
106 struct objfile *objfile)
110 Given an open bfd, a base address to relocate symbols to, and a
111 flag that specifies whether or not this bfd is for an executable
112 or not (may be shared library for example), add all the global
113 function and data symbols to the minimal symbol table.
117 nlm_symtab_read (abfd
, addr
, objfile
)
120 struct objfile
*objfile
;
122 unsigned int storage_needed
;
124 asymbol
**symbol_table
;
125 unsigned int number_of_symbols
;
127 struct cleanup
*back_to
;
129 enum minimal_symbol_type ms_type
;
131 storage_needed
= get_symtab_upper_bound (abfd
);
132 if (storage_needed
> 0)
134 symbol_table
= (asymbol
**) xmalloc (storage_needed
);
135 back_to
= make_cleanup (free
, symbol_table
);
136 number_of_symbols
= bfd_canonicalize_symtab (abfd
, symbol_table
);
138 for (i
= 0; i
< number_of_symbols
; i
++)
140 sym
= symbol_table
[i
];
141 if (sym
-> flags
& BSF_GLOBAL
)
143 /* Bfd symbols are section relative. */
144 symaddr
= sym
-> value
+ sym
-> section
-> vma
;
145 /* Relocate all non-absolute symbols by base address. */
146 if (sym
-> section
!= &bfd_abs_section
)
151 /* For non-absolute symbols, use the type of the section
152 they are relative to, to intuit text/data. Bfd provides
153 no way of figuring this out for absolute symbols. */
154 if (sym
-> section
-> flags
& SEC_CODE
)
158 else if (sym
-> section
-> flags
& SEC_DATA
)
164 ms_type
= mst_unknown
;
166 record_minimal_symbol ((char *) sym
-> name
, symaddr
, ms_type
,
170 do_cleanups (back_to
);
175 /* Scan and build partial symbols for a symbol file.
176 We have been initialized by a call to nlm_symfile_init, which
177 currently does nothing.
179 SECTION_OFFSETS is a set of offsets to apply to relocate the symbols
180 in each section. We simplify it down to a single offset for all
183 MAINLINE is true if we are reading the main symbol
184 table (as opposed to a shared lib or dynamically loaded file).
186 This function only does the minimum work necessary for letting the
187 user "name" things symbolically; it does not read the entire symtab.
188 Instead, it reads the external and static symbols and puts them in partial
189 symbol tables. When more extensive information is requested of a
190 file, the corresponding partial symbol table is mutated into a full
191 fledged symbol table by going back and reading the symbols
194 Note that NLM files have two sets of information that is potentially
195 useful for building gdb's minimal symbol table. The first is a list
196 of the publically exported symbols, and is currently used to build
197 bfd's canonical symbol table. The second is an optional native debugging
198 format which contains additional symbols (and possibly duplicates of
199 the publically exported symbols). The optional native debugging format
200 is not currently used. */
203 nlm_symfile_read (objfile
, section_offsets
, mainline
)
204 struct objfile
*objfile
;
205 struct section_offsets
*section_offsets
;
208 bfd
*abfd
= objfile
-> obfd
;
209 struct cleanup
*back_to
;
212 init_minimal_symbol_collection ();
213 back_to
= make_cleanup (discard_minimal_symbols
, 0);
215 /* FIXME, should take a section_offsets param, not just an offset. */
217 offset
= ANOFFSET (section_offsets
, 0);
219 /* Process the NLM export records, which become the bfd's canonical symbol
222 nlm_symtab_read (abfd
, offset
, objfile
);
224 /* FIXME: We could locate and read the optional native debugging format
225 here and add the symbols to the minimal symbol table. */
227 if (!have_partial_symbols ())
230 printf_filtered ("(no debugging symbols found)...");
234 /* Install any minimal symbols that have been collected as the current
235 minimal symbols for this objfile. */
237 install_minimal_symbols (objfile
);
239 do_cleanups (back_to
);
243 /* Perform any local cleanups required when we are done with a particular
244 objfile. I.E, we are in the process of discarding all symbol information
245 for an objfile, freeing up all memory held for it, and unlinking the
246 objfile struct from the global list of known objfiles. */
249 nlm_symfile_finish (objfile
)
250 struct objfile
*objfile
;
252 if (objfile
-> sym_private
!= NULL
)
254 mfree (objfile
-> md
, objfile
-> sym_private
);
258 /* NLM specific parsing routine for section offsets.
259 FIXME: This may or may not be necessary. All the symbol readers seem
260 to have similar code. See if it can be generalized and moved elsewhere. */
263 struct section_offsets
*
264 nlm_symfile_offsets (objfile
, addr
)
265 struct objfile
*objfile
;
268 struct section_offsets
*section_offsets
;
271 objfile
->num_sections
= SECT_OFF_MAX
;
272 section_offsets
= (struct section_offsets
*)
273 obstack_alloc (&objfile
-> psymbol_obstack
,
274 sizeof (struct section_offsets
) +
275 sizeof (section_offsets
->offsets
) * (SECT_OFF_MAX
-1));
277 for (i
= 0; i
< SECT_OFF_MAX
; i
++)
279 ANOFFSET (section_offsets
, i
) = addr
;
282 return (section_offsets
);
286 /* Register that we are able to handle NLM file format. */
288 static struct sym_fns nlm_sym_fns
=
290 bfd_target_nlm_flavour
,
291 nlm_new_init
, /* sym_new_init: init anything gbl to entire symtab */
292 nlm_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
293 nlm_symfile_read
, /* sym_read: read a symbol file into symtab */
294 nlm_symfile_finish
, /* sym_finish: finished with file, cleanup */
295 nlm_symfile_offsets
, /* sym_offsets: Translate ext. to int. relocation */
296 NULL
/* next: pointer to next struct sym_fns */
300 _initialize_nlmread ()
302 add_symtab_fns (&nlm_sym_fns
);