1 /* Read NLM (NetWare Loadable Module) format executable files for GDB.
2 Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000
3 Free Software Foundation, Inc.
4 Written by Fred Fish at Cygnus Support (fnf@cygnus.com).
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
29 #include "stabsread.h"
32 extern void _initialize_nlmread (void);
34 static void nlm_new_init (struct objfile
*);
36 static void nlm_symfile_init (struct objfile
*);
38 static void nlm_symfile_read (struct objfile
*, int);
40 static void nlm_symfile_finish (struct objfile
*);
42 static void nlm_symtab_read (bfd
*, CORE_ADDR
, struct objfile
*);
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
48 We reinitialize buildsym, since gdb will be able to read stabs from an NLM
49 file at some point in the near future. */
52 nlm_new_init (struct objfile
*ignore
)
54 stabsread_new_init ();
59 /* NLM specific initialization routine for reading symbols.
61 It is passed a pointer to a struct sym_fns which contains, among other
62 things, the BFD for the file whose symbols are being read, and a slot for
63 a pointer to "private data" which we can fill with goodies.
65 For now at least, we have nothing in particular to do, so this function is
69 nlm_symfile_init (struct objfile
*ignore
)
77 nlm_symtab_read -- read the symbol table of an NLM file
81 void nlm_symtab_read (bfd *abfd, CORE_ADDR addr,
82 struct objfile *objfile)
86 Given an open bfd, a base address to relocate symbols to, and a
87 flag that specifies whether or not this bfd is for an executable
88 or not (may be shared library for example), add all the global
89 function and data symbols to the minimal symbol table.
93 nlm_symtab_read (bfd
*abfd
, CORE_ADDR addr
, struct objfile
*objfile
)
97 asymbol
**symbol_table
;
98 long number_of_symbols
;
100 struct cleanup
*back_to
;
102 enum minimal_symbol_type ms_type
;
104 storage_needed
= bfd_get_symtab_upper_bound (abfd
);
105 if (storage_needed
< 0)
106 error (_("Can't read symbols from %s: %s"), bfd_get_filename (abfd
),
107 bfd_errmsg (bfd_get_error ()));
108 if (storage_needed
> 0)
110 symbol_table
= (asymbol
**) xmalloc (storage_needed
);
111 back_to
= make_cleanup (xfree
, symbol_table
);
112 number_of_symbols
= bfd_canonicalize_symtab (abfd
, symbol_table
);
113 if (number_of_symbols
< 0)
114 error (_("Can't read symbols from %s: %s"), bfd_get_filename (abfd
),
115 bfd_errmsg (bfd_get_error ()));
117 for (i
= 0; i
< number_of_symbols
; i
++)
119 sym
= symbol_table
[i
];
120 if ( /*sym -> flags & BSF_GLOBAL */ 1)
122 /* Bfd symbols are section relative. */
123 symaddr
= sym
->value
+ sym
->section
->vma
;
124 /* Relocate all non-absolute symbols by base address. */
125 if (sym
->section
!= &bfd_abs_section
)
128 /* For non-absolute symbols, use the type of the section
129 they are relative to, to intuit text/data. BFD provides
130 no way of figuring this out for absolute symbols. */
131 if (sym
->section
->flags
& SEC_CODE
)
133 else if (sym
->section
->flags
& SEC_DATA
)
136 ms_type
= mst_unknown
;
138 prim_record_minimal_symbol (sym
->name
, symaddr
, ms_type
,
142 do_cleanups (back_to
);
147 /* Scan and build partial symbols for a symbol file.
148 We have been initialized by a call to nlm_symfile_init, which
149 currently does nothing.
151 SECTION_OFFSETS is a set of offsets to apply to relocate the symbols
152 in each section. We simplify it down to a single offset for all
155 MAINLINE is true if we are reading the main symbol
156 table (as opposed to a shared lib or dynamically loaded file).
158 This function only does the minimum work necessary for letting the
159 user "name" things symbolically; it does not read the entire symtab.
160 Instead, it reads the external and static symbols and puts them in partial
161 symbol tables. When more extensive information is requested of a
162 file, the corresponding partial symbol table is mutated into a full
163 fledged symbol table by going back and reading the symbols
166 Note that NLM files have two sets of information that is potentially
167 useful for building gdb's minimal symbol table. The first is a list
168 of the publically exported symbols, and is currently used to build
169 bfd's canonical symbol table. The second is an optional native debugging
170 format which contains additional symbols (and possibly duplicates of
171 the publically exported symbols). The optional native debugging format
172 is not currently used. */
175 nlm_symfile_read (struct objfile
*objfile
, int mainline
)
177 bfd
*abfd
= objfile
->obfd
;
178 struct cleanup
*back_to
;
181 init_minimal_symbol_collection ();
182 back_to
= make_cleanup_discard_minimal_symbols ();
184 /* FIXME, should take a section_offsets param, not just an offset. */
186 offset
= ANOFFSET (objfile
->section_offsets
, 0);
188 /* Process the NLM export records, which become the bfd's canonical symbol
191 nlm_symtab_read (abfd
, offset
, objfile
);
193 /* Install any minimal symbols that have been collected as the current
194 minimal symbols for this objfile. */
196 install_minimal_symbols (objfile
);
197 do_cleanups (back_to
);
199 stabsect_build_psymtabs (objfile
, mainline
, ".stab",
200 ".stabstr", ".text");
201 /* FIXME: We could locate and read the optional native debugging format
202 here and add the symbols to the minimal symbol table. */
206 /* Perform any local cleanups required when we are done with a particular
207 objfile. I.E, we are in the process of discarding all symbol information
208 for an objfile, freeing up all memory held for it, and unlinking the
209 objfile struct from the global list of known objfiles. */
212 nlm_symfile_finish (struct objfile
*objfile
)
214 if (objfile
->deprecated_sym_private
!= NULL
)
216 xfree (objfile
->deprecated_sym_private
);
220 /* Register that we are able to handle NLM file format. */
222 static struct sym_fns nlm_sym_fns
=
224 bfd_target_nlm_flavour
,
225 nlm_new_init
, /* sym_new_init: init anything gbl to entire symtab */
226 nlm_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
227 nlm_symfile_read
, /* sym_read: read a symbol file into symtab */
228 nlm_symfile_finish
, /* sym_finish: finished with file, cleanup */
229 default_symfile_offsets
, /* sym_offsets: Translate ext. to int. relocation */
230 NULL
/* next: pointer to next struct sym_fns */
234 _initialize_nlmread (void)
236 add_symtab_fns (&nlm_sym_fns
);