124e9a250e839961c8cb9127cd259135570e04f2
[deliverable/binutils-gdb.git] / gdb / elfread.c
1 /* Read ELF (Executable and Linking Format) object files for GDB.
2 Copyright (C) 1991 Free Software Foundation, Inc.
3 Written by Fred Fish at Cygnus Support.
4
5 This file is part of GDB.
6
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.
11
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.
16
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. */
20
21 /************************************************************************
22 * *
23 * NOTICE *
24 * *
25 * This file is still under construction. When it is complete, this *
26 * notice will be removed. Until then, direct any questions or changes *
27 * to Fred Fish at Cygnus Support (fnf@cygint) *
28 * *
29 * FIXME Still needs support for shared libraries. *
30 * FIXME Still needs support for core files. *
31 * FIXME The ".debug" and ".line" section names are hardwired. *
32 * FIXME Still needs support ELF symbol tables (as distinct *
33 * from DWARF support). Can use them to build the misc *
34 * function vector at least. This is fairly trivial once *
35 * bfd is extended to handle ELF symbol tables. *
36 * *
37 ************************************************************************/
38
39 #include <stdio.h>
40
41 #include "defs.h"
42 #include "param.h"
43 #include "elf-common.h"
44 #include "elf-external.h"
45 #include "elf-internal.h"
46 #include "bfd.h"
47 #include "symfile.h"
48 #include "symtab.h"
49 #include "ansidecl.h"
50
51 extern int EXFUN(strcmp, (CONST char *a, CONST char *b));
52 #define STREQ(a,b) (strcmp((a),(b))==0)
53
54 struct elfinfo {
55 unsigned int dboffset; /* Offset to dwarf debug section */
56 unsigned int dbsize; /* Size of dwarf debug section */
57 unsigned int lnoffset; /* Offset to dwarf line number section */
58 unsigned int lnsize; /* Size of dwarf line number section */
59 };
60
61 #if 0
62 /* FIXME - crude hack to resolve undefined global. This function is
63 part of support for corefiles, which is not yet implemented. */
64
65 unsigned int
66 DEFUN(register_addr, (regno, blockend),
67 int regno AND
68 int blockend)
69 {
70 error ("Fetching registers from corefiles unimplemented.");
71 }
72 #endif
73
74 /* We are called once per section from elf_symfile_read. We
75 need to examine each section we are passed, check to see
76 if it is something we are interested in processing, and
77 if so, stash away some access information for the section.
78
79 For now we recognize the dwarf debug information sections and
80 line number sections from matching their section names. The
81 ELF definition is no real help here since it has no direct
82 knowledge of DWARF (by design, so any debugging format can be
83 used).
84
85 FIXME: The section names should not be hardwired strings. */
86
87 static void
88 DEFUN(elf_locate_sections, (abfd, sectp, ei),
89 bfd *abfd AND
90 asection *sectp AND
91 struct elfinfo *ei)
92 {
93 if (STREQ (sectp -> name, ".debug"))
94 {
95 ei -> dboffset = sectp -> filepos;
96 ei -> dbsize = sectp -> size;
97 }
98 else if (STREQ (sectp -> name, ".line"))
99 {
100 ei -> lnoffset = sectp -> filepos;
101 ei -> lnsize = sectp -> size;
102 }
103 }
104
105 /* Scan and build partial symbols for a symbol file.
106 We have been initialized by a call to elf_symfile_init, which
107 currently does nothing.
108
109 ADDR is the address relative to which the symbols in it are (e.g.
110 the base address of the text segment).
111
112 MAINLINE is true if we are reading the main symbol
113 table (as opposed to a shared lib or dynamically loaded file).
114
115 This function only does the minimum work necessary for letting the
116 user "name" things symbolically; it does not read the entire symtab.
117 Instead, it reads the external and static symbols and puts them in partial
118 symbol tables. When more extensive information is requested of a
119 file, the corresponding partial symbol table is mutated into a full
120 fledged symbol table by going back and reading the symbols
121 for real. The function dwarf_psymtab_to_symtab() is the function that
122 does this for DWARF symbols. */
123
124 static void
125 DEFUN(elf_symfile_read, (sf, addr, mainline),
126 struct sym_fns *sf AND
127 CORE_ADDR addr AND
128 int mainline)
129 {
130 bfd *abfd = sf -> sym_bfd;
131 struct elfinfo ei;
132
133 bfd_map_over_sections (abfd, elf_locate_sections, &ei);
134 if (ei.dboffset && ei.lnoffset)
135 {
136 addr = 0; /* FIXME: force address base to zero for now */
137 dwarf_build_psymtabs (fileno ((FILE *)(abfd -> iostream)),
138 bfd_get_filename (abfd),
139 addr, mainline,
140 ei.dboffset, ei.dbsize,
141 ei.lnoffset, ei.lnsize);
142 }
143 if (!partial_symtab_list)
144 {
145 wrap_here ("");
146 printf_filtered ("(no debugging symbols found)...");
147 wrap_here ("");
148 }
149 }
150
151 /* Initialize anything that needs initializing when a completely new symbol
152 file is specified (not just adding some symbols from another file, e.g. a
153 shared library).
154
155 For now at least, we have nothing in particular to do, so this function is
156 just a stub. */
157
158 static void
159 DEFUN_VOID (elf_new_init)
160 {
161 }
162
163 /* ELF specific initialization routine for reading symbols.
164
165 It is passed a pointer to a struct sym_fns which contains, among other
166 things, the BFD for the file whose symbols are being read, and a slot for
167 a pointer to "private data" which we can fill with goodies.
168
169 For now at least, we have nothing in particular to do, so this function is
170 just a stub. */
171
172 static void
173 DEFUN(elf_symfile_init, (sf),
174 struct sym_fns *sf)
175 {
176 }
177
178 \f
179 /* Register that we are able to handle ELF object file formats and DWARF
180 debugging formats.
181
182 Unlike other object file formats, where the debugging information format
183 is implied by the object file format, the ELF object file format and the
184 DWARF debugging information format are two distinct, and potentially
185 separate entities. I.E. it is perfectly possible to have ELF objects
186 with debugging formats other than DWARF. And it is conceivable that the
187 DWARF debugging format might be used with another object file format,
188 like COFF, by simply using COFF's custom section feature.
189
190 GDB, and to a lesser extent BFD, should support the notion of separate
191 object file formats and debugging information formats. For now, we just
192 use "elf" in the same sense as "a.out" or "coff", to imply both the ELF
193 object file format and the DWARF debugging format. */
194
195 static struct sym_fns elf_sym_fns = {
196 "elf", /* sym_name: name or name prefix of BFD target type */
197 3, /* sym_namelen: number of significant sym_name chars */
198 elf_new_init, /* sym_new_init: init anything gbl to entire symtab */
199 elf_symfile_init, /* sym_init: read initial info, setup for sym_read() */
200 elf_symfile_read, /* sym_read: read a symbol file into symtab */
201 NULL, /* sym_bfd: accessor for symbol file being read */
202 NULL, /* sym_private: sym_init & sym_read shared info */
203 NULL /* next: pointer to next struct sym_fns */
204 };
205
206 void
207 DEFUN_VOID (_initialize_elfread)
208 {
209 add_symtab_fns (&elf_sym_fns);
210 }
This page took 0.033036 seconds and 4 git commands to generate.