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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
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
*));
47 record_minimal_symbol
PARAMS ((char *, CORE_ADDR
, enum minimal_symbol_type
,
51 /* Initialize anything that needs initializing when a completely new symbol
52 file is specified (not just adding some symbols from another file, e.g. a
55 We reinitialize buildsym, since gdb will be able to read stabs from an NLM
56 file at some point in the near future. */
60 struct objfile
*ignore
;
62 stabsread_new_init ();
67 /* NLM specific initialization routine for reading symbols.
69 It is passed a pointer to a struct sym_fns which contains, among other
70 things, the BFD for the file whose symbols are being read, and a slot for
71 a pointer to "private data" which we can fill with goodies.
73 For now at least, we have nothing in particular to do, so this function is
77 nlm_symfile_init (ignore
)
78 struct objfile
*ignore
;
83 record_minimal_symbol (name
, address
, ms_type
, objfile
)
86 enum minimal_symbol_type ms_type
;
87 struct objfile
*objfile
;
89 name
= obsavestring (name
, strlen (name
), &objfile
-> symbol_obstack
);
90 prim_record_minimal_symbol (name
, address
, ms_type
, objfile
);
98 nlm_symtab_read -- read the symbol table of an NLM file
102 void nlm_symtab_read (bfd *abfd, CORE_ADDR addr,
103 struct objfile *objfile)
107 Given an open bfd, a base address to relocate symbols to, and a
108 flag that specifies whether or not this bfd is for an executable
109 or not (may be shared library for example), add all the global
110 function and data symbols to the minimal symbol table.
114 nlm_symtab_read (abfd
, addr
, objfile
)
117 struct objfile
*objfile
;
121 asymbol
**symbol_table
;
122 long number_of_symbols
;
124 struct cleanup
*back_to
;
126 enum minimal_symbol_type ms_type
;
128 storage_needed
= bfd_get_symtab_upper_bound (abfd
);
129 if (storage_needed
< 0)
130 error ("Can't read symbols from %s: %s", bfd_get_filename (abfd
),
131 bfd_errmsg (bfd_get_error ()));
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
);
137 if (number_of_symbols
< 0)
138 error ("Can't read symbols from %s: %s", bfd_get_filename (abfd
),
139 bfd_errmsg (bfd_get_error ()));
141 for (i
= 0; i
< number_of_symbols
; i
++)
143 sym
= symbol_table
[i
];
144 if (/*sym -> flags & BSF_GLOBAL*/ 1)
146 /* Bfd symbols are section relative. */
147 symaddr
= sym
-> value
+ sym
-> section
-> vma
;
148 /* Relocate all non-absolute symbols by base address. */
149 if (sym
-> section
!= &bfd_abs_section
)
152 /* For non-absolute symbols, use the type of the section
153 they are relative to, to intuit text/data. BFD provides
154 no way of figuring this out for absolute symbols. */
155 if (sym
-> section
-> flags
& SEC_CODE
)
157 else if (sym
-> section
-> flags
& SEC_DATA
)
160 ms_type
= mst_unknown
;
162 record_minimal_symbol ((char *) sym
-> name
, symaddr
, ms_type
,
166 do_cleanups (back_to
);
171 /* Scan and build partial symbols for a symbol file.
172 We have been initialized by a call to nlm_symfile_init, which
173 currently does nothing.
175 SECTION_OFFSETS is a set of offsets to apply to relocate the symbols
176 in each section. We simplify it down to a single offset for all
179 MAINLINE is true if we are reading the main symbol
180 table (as opposed to a shared lib or dynamically loaded file).
182 This function only does the minimum work necessary for letting the
183 user "name" things symbolically; it does not read the entire symtab.
184 Instead, it reads the external and static symbols and puts them in partial
185 symbol tables. When more extensive information is requested of a
186 file, the corresponding partial symbol table is mutated into a full
187 fledged symbol table by going back and reading the symbols
190 Note that NLM files have two sets of information that is potentially
191 useful for building gdb's minimal symbol table. The first is a list
192 of the publically exported symbols, and is currently used to build
193 bfd's canonical symbol table. The second is an optional native debugging
194 format which contains additional symbols (and possibly duplicates of
195 the publically exported symbols). The optional native debugging format
196 is not currently used. */
199 nlm_symfile_read (objfile
, section_offsets
, mainline
)
200 struct objfile
*objfile
;
201 struct section_offsets
*section_offsets
;
204 bfd
*abfd
= objfile
-> obfd
;
205 struct cleanup
*back_to
;
207 struct symbol
*mainsym
;
209 init_minimal_symbol_collection ();
210 back_to
= make_cleanup (discard_minimal_symbols
, 0);
212 /* FIXME, should take a section_offsets param, not just an offset. */
214 offset
= ANOFFSET (section_offsets
, 0);
216 /* Process the NLM export records, which become the bfd's canonical symbol
219 nlm_symtab_read (abfd
, offset
, objfile
);
221 stabsect_build_psymtabs (objfile
, section_offsets
, mainline
, ".stab",
222 ".stabstr", ".text");
224 mainsym
= lookup_symbol ("main", NULL
, VAR_NAMESPACE
, NULL
, NULL
);
227 && SYMBOL_CLASS(mainsym
) == LOC_BLOCK
)
229 objfile
->ei
.main_func_lowpc
= BLOCK_START (SYMBOL_BLOCK_VALUE (mainsym
));
230 objfile
->ei
.main_func_highpc
= BLOCK_END (SYMBOL_BLOCK_VALUE (mainsym
));
233 /* FIXME: We could locate and read the optional native debugging format
234 here and add the symbols to the minimal symbol table. */
236 /* Install any minimal symbols that have been collected as the current
237 minimal symbols for this objfile. */
239 install_minimal_symbols (objfile
);
241 do_cleanups (back_to
);
245 /* Perform any local cleanups required when we are done with a particular
246 objfile. I.E, we are in the process of discarding all symbol information
247 for an objfile, freeing up all memory held for it, and unlinking the
248 objfile struct from the global list of known objfiles. */
251 nlm_symfile_finish (objfile
)
252 struct objfile
*objfile
;
254 if (objfile
-> sym_private
!= NULL
)
256 mfree (objfile
-> md
, objfile
-> sym_private
);
260 /* Register that we are able to handle NLM file format. */
262 static struct sym_fns nlm_sym_fns
=
264 bfd_target_nlm_flavour
,
265 nlm_new_init
, /* sym_new_init: init anything gbl to entire symtab */
266 nlm_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
267 nlm_symfile_read
, /* sym_read: read a symbol file into symtab */
268 nlm_symfile_finish
, /* sym_finish: finished with file, cleanup */
269 default_symfile_offsets
,
270 /* sym_offsets: Translate ext. to int. relocation */
271 NULL
/* next: pointer to next struct sym_fns */
275 _initialize_nlmread ()
277 add_symtab_fns (&nlm_sym_fns
);