1*ef5ccd6cSJohn Marino /* Read HP PA/Risc object files for GDB.
2*ef5ccd6cSJohn Marino Copyright (C) 1991-2013 Free Software Foundation, Inc.
3*ef5ccd6cSJohn Marino Written by Fred Fish at Cygnus Support.
4*ef5ccd6cSJohn Marino
5*ef5ccd6cSJohn Marino This file is part of GDB.
6*ef5ccd6cSJohn Marino
7*ef5ccd6cSJohn Marino This program is free software; you can redistribute it and/or modify
8*ef5ccd6cSJohn Marino it under the terms of the GNU General Public License as published by
9*ef5ccd6cSJohn Marino the Free Software Foundation; either version 3 of the License, or
10*ef5ccd6cSJohn Marino (at your option) any later version.
11*ef5ccd6cSJohn Marino
12*ef5ccd6cSJohn Marino This program is distributed in the hope that it will be useful,
13*ef5ccd6cSJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of
14*ef5ccd6cSJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*ef5ccd6cSJohn Marino GNU General Public License for more details.
16*ef5ccd6cSJohn Marino
17*ef5ccd6cSJohn Marino You should have received a copy of the GNU General Public License
18*ef5ccd6cSJohn Marino along with this program. If not, see <http://www.gnu.org/licenses/>. */
19*ef5ccd6cSJohn Marino
20*ef5ccd6cSJohn Marino #include "defs.h"
21*ef5ccd6cSJohn Marino #include "bfd.h"
22*ef5ccd6cSJohn Marino #include "som/aout.h"
23*ef5ccd6cSJohn Marino #include "symtab.h"
24*ef5ccd6cSJohn Marino #include "symfile.h"
25*ef5ccd6cSJohn Marino #include "objfiles.h"
26*ef5ccd6cSJohn Marino #include "buildsym.h"
27*ef5ccd6cSJohn Marino #include "stabsread.h"
28*ef5ccd6cSJohn Marino #include "gdb-stabs.h"
29*ef5ccd6cSJohn Marino #include "complaints.h"
30*ef5ccd6cSJohn Marino #include "gdb_string.h"
31*ef5ccd6cSJohn Marino #include "demangle.h"
32*ef5ccd6cSJohn Marino #include "som.h"
33*ef5ccd6cSJohn Marino #include "libhppa.h"
34*ef5ccd6cSJohn Marino #include "psymtab.h"
35*ef5ccd6cSJohn Marino
36*ef5ccd6cSJohn Marino #include "solib-som.h"
37*ef5ccd6cSJohn Marino
38*ef5ccd6cSJohn Marino /* Read the symbol table of a SOM file.
39*ef5ccd6cSJohn Marino
40*ef5ccd6cSJohn Marino Given an open bfd, a base address to relocate symbols to, and a
41*ef5ccd6cSJohn Marino flag that specifies whether or not this bfd is for an executable
42*ef5ccd6cSJohn Marino or not (may be shared library for example), add all the global
43*ef5ccd6cSJohn Marino function and data symbols to the minimal symbol table. */
44*ef5ccd6cSJohn Marino
45*ef5ccd6cSJohn Marino static void
som_symtab_read(bfd * abfd,struct objfile * objfile,struct section_offsets * section_offsets)46*ef5ccd6cSJohn Marino som_symtab_read (bfd *abfd, struct objfile *objfile,
47*ef5ccd6cSJohn Marino struct section_offsets *section_offsets)
48*ef5ccd6cSJohn Marino {
49*ef5ccd6cSJohn Marino struct gdbarch *gdbarch = get_objfile_arch (objfile);
50*ef5ccd6cSJohn Marino unsigned int number_of_symbols;
51*ef5ccd6cSJohn Marino int val, dynamic;
52*ef5ccd6cSJohn Marino char *stringtab;
53*ef5ccd6cSJohn Marino asection *shlib_info;
54*ef5ccd6cSJohn Marino struct som_external_symbol_dictionary_record *buf, *bufp, *endbufp;
55*ef5ccd6cSJohn Marino char *symname;
56*ef5ccd6cSJohn Marino CONST int symsize = sizeof (struct som_external_symbol_dictionary_record);
57*ef5ccd6cSJohn Marino CORE_ADDR text_offset, data_offset;
58*ef5ccd6cSJohn Marino
59*ef5ccd6cSJohn Marino
60*ef5ccd6cSJohn Marino text_offset = ANOFFSET (section_offsets, 0);
61*ef5ccd6cSJohn Marino data_offset = ANOFFSET (section_offsets, 1);
62*ef5ccd6cSJohn Marino
63*ef5ccd6cSJohn Marino number_of_symbols = bfd_get_symcount (abfd);
64*ef5ccd6cSJohn Marino
65*ef5ccd6cSJohn Marino /* Allocate a buffer to read in the debug info.
66*ef5ccd6cSJohn Marino We avoid using alloca because the memory size could be so large
67*ef5ccd6cSJohn Marino that we could hit the stack size limit. */
68*ef5ccd6cSJohn Marino buf = xmalloc (symsize * number_of_symbols);
69*ef5ccd6cSJohn Marino make_cleanup (xfree, buf);
70*ef5ccd6cSJohn Marino bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET);
71*ef5ccd6cSJohn Marino val = bfd_bread (buf, symsize * number_of_symbols, abfd);
72*ef5ccd6cSJohn Marino if (val != symsize * number_of_symbols)
73*ef5ccd6cSJohn Marino error (_("Couldn't read symbol dictionary!"));
74*ef5ccd6cSJohn Marino
75*ef5ccd6cSJohn Marino /* Allocate a buffer to read in the som stringtab section of
76*ef5ccd6cSJohn Marino the debugging info. Again, we avoid using alloca because
77*ef5ccd6cSJohn Marino the data could be so large that we could potentially hit
78*ef5ccd6cSJohn Marino the stack size limitat. */
79*ef5ccd6cSJohn Marino stringtab = xmalloc (obj_som_stringtab_size (abfd));
80*ef5ccd6cSJohn Marino make_cleanup (xfree, stringtab);
81*ef5ccd6cSJohn Marino bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET);
82*ef5ccd6cSJohn Marino val = bfd_bread (stringtab, obj_som_stringtab_size (abfd), abfd);
83*ef5ccd6cSJohn Marino if (val != obj_som_stringtab_size (abfd))
84*ef5ccd6cSJohn Marino error (_("Can't read in HP string table."));
85*ef5ccd6cSJohn Marino
86*ef5ccd6cSJohn Marino /* We need to determine if objfile is a dynamic executable (so we
87*ef5ccd6cSJohn Marino can do the right thing for ST_ENTRY vs ST_CODE symbols).
88*ef5ccd6cSJohn Marino
89*ef5ccd6cSJohn Marino There's nothing in the header which easily allows us to do
90*ef5ccd6cSJohn Marino this.
91*ef5ccd6cSJohn Marino
92*ef5ccd6cSJohn Marino This code used to rely upon the existence of a $SHLIB_INFO$
93*ef5ccd6cSJohn Marino section to make this determination. HP claims that it is
94*ef5ccd6cSJohn Marino more accurate to check for a nonzero text offset, but they
95*ef5ccd6cSJohn Marino have not provided any information about why that test is
96*ef5ccd6cSJohn Marino more accurate. */
97*ef5ccd6cSJohn Marino dynamic = (text_offset != 0);
98*ef5ccd6cSJohn Marino
99*ef5ccd6cSJohn Marino endbufp = buf + number_of_symbols;
100*ef5ccd6cSJohn Marino for (bufp = buf; bufp < endbufp; ++bufp)
101*ef5ccd6cSJohn Marino {
102*ef5ccd6cSJohn Marino enum minimal_symbol_type ms_type;
103*ef5ccd6cSJohn Marino unsigned int flags = bfd_getb32 (bufp->flags);
104*ef5ccd6cSJohn Marino unsigned int symbol_type
105*ef5ccd6cSJohn Marino = (flags >> SOM_SYMBOL_TYPE_SH) & SOM_SYMBOL_TYPE_MASK;
106*ef5ccd6cSJohn Marino unsigned int symbol_scope
107*ef5ccd6cSJohn Marino = (flags >> SOM_SYMBOL_SCOPE_SH) & SOM_SYMBOL_SCOPE_MASK;
108*ef5ccd6cSJohn Marino CORE_ADDR symbol_value = bfd_getb32 (bufp->symbol_value);
109*ef5ccd6cSJohn Marino
110*ef5ccd6cSJohn Marino QUIT;
111*ef5ccd6cSJohn Marino
112*ef5ccd6cSJohn Marino switch (symbol_scope)
113*ef5ccd6cSJohn Marino {
114*ef5ccd6cSJohn Marino case SS_UNIVERSAL:
115*ef5ccd6cSJohn Marino case SS_EXTERNAL:
116*ef5ccd6cSJohn Marino switch (symbol_type)
117*ef5ccd6cSJohn Marino {
118*ef5ccd6cSJohn Marino case ST_SYM_EXT:
119*ef5ccd6cSJohn Marino case ST_ARG_EXT:
120*ef5ccd6cSJohn Marino continue;
121*ef5ccd6cSJohn Marino
122*ef5ccd6cSJohn Marino case ST_CODE:
123*ef5ccd6cSJohn Marino case ST_PRI_PROG:
124*ef5ccd6cSJohn Marino case ST_SEC_PROG:
125*ef5ccd6cSJohn Marino case ST_MILLICODE:
126*ef5ccd6cSJohn Marino symname = bfd_getb32 (bufp->name) + stringtab;
127*ef5ccd6cSJohn Marino ms_type = mst_text;
128*ef5ccd6cSJohn Marino symbol_value += text_offset;
129*ef5ccd6cSJohn Marino symbol_value = gdbarch_addr_bits_remove (gdbarch, symbol_value);
130*ef5ccd6cSJohn Marino break;
131*ef5ccd6cSJohn Marino
132*ef5ccd6cSJohn Marino case ST_ENTRY:
133*ef5ccd6cSJohn Marino symname = bfd_getb32 (bufp->name) + stringtab;
134*ef5ccd6cSJohn Marino /* For a dynamic executable, ST_ENTRY symbols are
135*ef5ccd6cSJohn Marino the stubs, while the ST_CODE symbol is the real
136*ef5ccd6cSJohn Marino function. */
137*ef5ccd6cSJohn Marino if (dynamic)
138*ef5ccd6cSJohn Marino ms_type = mst_solib_trampoline;
139*ef5ccd6cSJohn Marino else
140*ef5ccd6cSJohn Marino ms_type = mst_text;
141*ef5ccd6cSJohn Marino symbol_value += text_offset;
142*ef5ccd6cSJohn Marino symbol_value = gdbarch_addr_bits_remove (gdbarch, symbol_value);
143*ef5ccd6cSJohn Marino break;
144*ef5ccd6cSJohn Marino
145*ef5ccd6cSJohn Marino case ST_STUB:
146*ef5ccd6cSJohn Marino symname = bfd_getb32 (bufp->name) + stringtab;
147*ef5ccd6cSJohn Marino ms_type = mst_solib_trampoline;
148*ef5ccd6cSJohn Marino symbol_value += text_offset;
149*ef5ccd6cSJohn Marino symbol_value = gdbarch_addr_bits_remove (gdbarch, symbol_value);
150*ef5ccd6cSJohn Marino break;
151*ef5ccd6cSJohn Marino
152*ef5ccd6cSJohn Marino case ST_DATA:
153*ef5ccd6cSJohn Marino symname = bfd_getb32 (bufp->name) + stringtab;
154*ef5ccd6cSJohn Marino symbol_value += data_offset;
155*ef5ccd6cSJohn Marino ms_type = mst_data;
156*ef5ccd6cSJohn Marino break;
157*ef5ccd6cSJohn Marino default:
158*ef5ccd6cSJohn Marino continue;
159*ef5ccd6cSJohn Marino }
160*ef5ccd6cSJohn Marino break;
161*ef5ccd6cSJohn Marino
162*ef5ccd6cSJohn Marino #if 0
163*ef5ccd6cSJohn Marino /* SS_GLOBAL and SS_LOCAL are two names for the same thing (!). */
164*ef5ccd6cSJohn Marino case SS_GLOBAL:
165*ef5ccd6cSJohn Marino #endif
166*ef5ccd6cSJohn Marino case SS_LOCAL:
167*ef5ccd6cSJohn Marino switch (symbol_type)
168*ef5ccd6cSJohn Marino {
169*ef5ccd6cSJohn Marino case ST_SYM_EXT:
170*ef5ccd6cSJohn Marino case ST_ARG_EXT:
171*ef5ccd6cSJohn Marino continue;
172*ef5ccd6cSJohn Marino
173*ef5ccd6cSJohn Marino case ST_CODE:
174*ef5ccd6cSJohn Marino symname = bfd_getb32 (bufp->name) + stringtab;
175*ef5ccd6cSJohn Marino ms_type = mst_file_text;
176*ef5ccd6cSJohn Marino symbol_value += text_offset;
177*ef5ccd6cSJohn Marino symbol_value = gdbarch_addr_bits_remove (gdbarch, symbol_value);
178*ef5ccd6cSJohn Marino
179*ef5ccd6cSJohn Marino check_strange_names:
180*ef5ccd6cSJohn Marino /* Utah GCC 2.5, FSF GCC 2.6 and later generate correct local
181*ef5ccd6cSJohn Marino label prefixes for stabs, constant data, etc. So we need
182*ef5ccd6cSJohn Marino only filter out L$ symbols which are left in due to
183*ef5ccd6cSJohn Marino limitations in how GAS generates SOM relocations.
184*ef5ccd6cSJohn Marino
185*ef5ccd6cSJohn Marino When linking in the HPUX C-library the HP linker has
186*ef5ccd6cSJohn Marino the nasty habit of placing section symbols from the literal
187*ef5ccd6cSJohn Marino subspaces in the middle of the program's text. Filter
188*ef5ccd6cSJohn Marino those out as best we can. Check for first and last character
189*ef5ccd6cSJohn Marino being '$'.
190*ef5ccd6cSJohn Marino
191*ef5ccd6cSJohn Marino And finally, the newer HP compilers emit crud like $PIC_foo$N
192*ef5ccd6cSJohn Marino in some circumstance (PIC code I guess). It's also claimed
193*ef5ccd6cSJohn Marino that they emit D$ symbols too. What stupidity. */
194*ef5ccd6cSJohn Marino if ((symname[0] == 'L' && symname[1] == '$')
195*ef5ccd6cSJohn Marino || (symname[0] == '$' && symname[strlen (symname) - 1] == '$')
196*ef5ccd6cSJohn Marino || (symname[0] == 'D' && symname[1] == '$')
197*ef5ccd6cSJohn Marino || (strncmp (symname, "L0\001", 3) == 0)
198*ef5ccd6cSJohn Marino || (strncmp (symname, "$PIC", 4) == 0))
199*ef5ccd6cSJohn Marino continue;
200*ef5ccd6cSJohn Marino break;
201*ef5ccd6cSJohn Marino
202*ef5ccd6cSJohn Marino case ST_PRI_PROG:
203*ef5ccd6cSJohn Marino case ST_SEC_PROG:
204*ef5ccd6cSJohn Marino case ST_MILLICODE:
205*ef5ccd6cSJohn Marino symname = bfd_getb32 (bufp->name) + stringtab;
206*ef5ccd6cSJohn Marino ms_type = mst_file_text;
207*ef5ccd6cSJohn Marino symbol_value += text_offset;
208*ef5ccd6cSJohn Marino symbol_value = gdbarch_addr_bits_remove (gdbarch, symbol_value);
209*ef5ccd6cSJohn Marino break;
210*ef5ccd6cSJohn Marino
211*ef5ccd6cSJohn Marino case ST_ENTRY:
212*ef5ccd6cSJohn Marino symname = bfd_getb32 (bufp->name) + stringtab;
213*ef5ccd6cSJohn Marino /* SS_LOCAL symbols in a shared library do not have
214*ef5ccd6cSJohn Marino export stubs, so we do not have to worry about
215*ef5ccd6cSJohn Marino using mst_file_text vs mst_solib_trampoline here like
216*ef5ccd6cSJohn Marino we do for SS_UNIVERSAL and SS_EXTERNAL symbols above. */
217*ef5ccd6cSJohn Marino ms_type = mst_file_text;
218*ef5ccd6cSJohn Marino symbol_value += text_offset;
219*ef5ccd6cSJohn Marino symbol_value = gdbarch_addr_bits_remove (gdbarch, symbol_value);
220*ef5ccd6cSJohn Marino break;
221*ef5ccd6cSJohn Marino
222*ef5ccd6cSJohn Marino case ST_STUB:
223*ef5ccd6cSJohn Marino symname = bfd_getb32 (bufp->name) + stringtab;
224*ef5ccd6cSJohn Marino ms_type = mst_solib_trampoline;
225*ef5ccd6cSJohn Marino symbol_value += text_offset;
226*ef5ccd6cSJohn Marino symbol_value = gdbarch_addr_bits_remove (gdbarch, symbol_value);
227*ef5ccd6cSJohn Marino break;
228*ef5ccd6cSJohn Marino
229*ef5ccd6cSJohn Marino
230*ef5ccd6cSJohn Marino case ST_DATA:
231*ef5ccd6cSJohn Marino symname = bfd_getb32 (bufp->name) + stringtab;
232*ef5ccd6cSJohn Marino symbol_value += data_offset;
233*ef5ccd6cSJohn Marino ms_type = mst_file_data;
234*ef5ccd6cSJohn Marino goto check_strange_names;
235*ef5ccd6cSJohn Marino
236*ef5ccd6cSJohn Marino default:
237*ef5ccd6cSJohn Marino continue;
238*ef5ccd6cSJohn Marino }
239*ef5ccd6cSJohn Marino break;
240*ef5ccd6cSJohn Marino
241*ef5ccd6cSJohn Marino /* This can happen for common symbols when -E is passed to the
242*ef5ccd6cSJohn Marino final link. No idea _why_ that would make the linker force
243*ef5ccd6cSJohn Marino common symbols to have an SS_UNSAT scope, but it does.
244*ef5ccd6cSJohn Marino
245*ef5ccd6cSJohn Marino This also happens for weak symbols, but their type is
246*ef5ccd6cSJohn Marino ST_DATA. */
247*ef5ccd6cSJohn Marino case SS_UNSAT:
248*ef5ccd6cSJohn Marino switch (symbol_type)
249*ef5ccd6cSJohn Marino {
250*ef5ccd6cSJohn Marino case ST_STORAGE:
251*ef5ccd6cSJohn Marino case ST_DATA:
252*ef5ccd6cSJohn Marino symname = bfd_getb32 (bufp->name) + stringtab;
253*ef5ccd6cSJohn Marino symbol_value += data_offset;
254*ef5ccd6cSJohn Marino ms_type = mst_data;
255*ef5ccd6cSJohn Marino break;
256*ef5ccd6cSJohn Marino
257*ef5ccd6cSJohn Marino default:
258*ef5ccd6cSJohn Marino continue;
259*ef5ccd6cSJohn Marino }
260*ef5ccd6cSJohn Marino break;
261*ef5ccd6cSJohn Marino
262*ef5ccd6cSJohn Marino default:
263*ef5ccd6cSJohn Marino continue;
264*ef5ccd6cSJohn Marino }
265*ef5ccd6cSJohn Marino
266*ef5ccd6cSJohn Marino if (bfd_getb32 (bufp->name) > obj_som_stringtab_size (abfd))
267*ef5ccd6cSJohn Marino error (_("Invalid symbol data; bad HP string table offset: %s"),
268*ef5ccd6cSJohn Marino plongest (bfd_getb32 (bufp->name)));
269*ef5ccd6cSJohn Marino
270*ef5ccd6cSJohn Marino prim_record_minimal_symbol (symname, symbol_value, ms_type, objfile);
271*ef5ccd6cSJohn Marino }
272*ef5ccd6cSJohn Marino }
273*ef5ccd6cSJohn Marino
274*ef5ccd6cSJohn Marino /* Scan and build partial symbols for a symbol file.
275*ef5ccd6cSJohn Marino We have been initialized by a call to som_symfile_init, which
276*ef5ccd6cSJohn Marino currently does nothing.
277*ef5ccd6cSJohn Marino
278*ef5ccd6cSJohn Marino SECTION_OFFSETS is a set of offsets to apply to relocate the symbols
279*ef5ccd6cSJohn Marino in each section. This is ignored, as it isn't needed for SOM.
280*ef5ccd6cSJohn Marino
281*ef5ccd6cSJohn Marino This function only does the minimum work necessary for letting the
282*ef5ccd6cSJohn Marino user "name" things symbolically; it does not read the entire symtab.
283*ef5ccd6cSJohn Marino Instead, it reads the external and static symbols and puts them in partial
284*ef5ccd6cSJohn Marino symbol tables. When more extensive information is requested of a
285*ef5ccd6cSJohn Marino file, the corresponding partial symbol table is mutated into a full
286*ef5ccd6cSJohn Marino fledged symbol table by going back and reading the symbols
287*ef5ccd6cSJohn Marino for real.
288*ef5ccd6cSJohn Marino
289*ef5ccd6cSJohn Marino We look for sections with specific names, to tell us what debug
290*ef5ccd6cSJohn Marino format to look for: FIXME!!!
291*ef5ccd6cSJohn Marino
292*ef5ccd6cSJohn Marino somstab_build_psymtabs() handles STABS symbols.
293*ef5ccd6cSJohn Marino
294*ef5ccd6cSJohn Marino Note that SOM files have a "minimal" symbol table, which is vaguely
295*ef5ccd6cSJohn Marino reminiscent of a COFF symbol table, but has only the minimal information
296*ef5ccd6cSJohn Marino necessary for linking. We process this also, and use the information to
297*ef5ccd6cSJohn Marino build gdb's minimal symbol table. This gives us some minimal debugging
298*ef5ccd6cSJohn Marino capability even for files compiled without -g. */
299*ef5ccd6cSJohn Marino
300*ef5ccd6cSJohn Marino static void
som_symfile_read(struct objfile * objfile,int symfile_flags)301*ef5ccd6cSJohn Marino som_symfile_read (struct objfile *objfile, int symfile_flags)
302*ef5ccd6cSJohn Marino {
303*ef5ccd6cSJohn Marino bfd *abfd = objfile->obfd;
304*ef5ccd6cSJohn Marino struct cleanup *back_to;
305*ef5ccd6cSJohn Marino
306*ef5ccd6cSJohn Marino init_minimal_symbol_collection ();
307*ef5ccd6cSJohn Marino back_to = make_cleanup_discard_minimal_symbols ();
308*ef5ccd6cSJohn Marino
309*ef5ccd6cSJohn Marino /* Process the normal SOM symbol table first.
310*ef5ccd6cSJohn Marino This reads in the DNTT and string table, but doesn't
311*ef5ccd6cSJohn Marino actually scan the DNTT. It does scan the linker symbol
312*ef5ccd6cSJohn Marino table and thus build up a "minimal symbol table". */
313*ef5ccd6cSJohn Marino
314*ef5ccd6cSJohn Marino som_symtab_read (abfd, objfile, objfile->section_offsets);
315*ef5ccd6cSJohn Marino
316*ef5ccd6cSJohn Marino /* Install any minimal symbols that have been collected as the current
317*ef5ccd6cSJohn Marino minimal symbols for this objfile.
318*ef5ccd6cSJohn Marino Further symbol-reading is done incrementally, file-by-file,
319*ef5ccd6cSJohn Marino in a step known as "psymtab-to-symtab" expansion. hp-symtab-read.c
320*ef5ccd6cSJohn Marino contains the code to do the actual DNTT scanning and symtab building. */
321*ef5ccd6cSJohn Marino install_minimal_symbols (objfile);
322*ef5ccd6cSJohn Marino do_cleanups (back_to);
323*ef5ccd6cSJohn Marino
324*ef5ccd6cSJohn Marino /* Now read information from the stabs debug sections.
325*ef5ccd6cSJohn Marino This is emitted by gcc. */
326*ef5ccd6cSJohn Marino stabsect_build_psymtabs (objfile,
327*ef5ccd6cSJohn Marino "$GDB_SYMBOLS$", "$GDB_STRINGS$", "$TEXT$");
328*ef5ccd6cSJohn Marino }
329*ef5ccd6cSJohn Marino
330*ef5ccd6cSJohn Marino /* Initialize anything that needs initializing when a completely new symbol
331*ef5ccd6cSJohn Marino file is specified (not just adding some symbols from another file, e.g. a
332*ef5ccd6cSJohn Marino shared library).
333*ef5ccd6cSJohn Marino
334*ef5ccd6cSJohn Marino We reinitialize buildsym, since we may be reading stabs from a SOM file. */
335*ef5ccd6cSJohn Marino
336*ef5ccd6cSJohn Marino static void
som_new_init(struct objfile * ignore)337*ef5ccd6cSJohn Marino som_new_init (struct objfile *ignore)
338*ef5ccd6cSJohn Marino {
339*ef5ccd6cSJohn Marino stabsread_new_init ();
340*ef5ccd6cSJohn Marino buildsym_new_init ();
341*ef5ccd6cSJohn Marino }
342*ef5ccd6cSJohn Marino
343*ef5ccd6cSJohn Marino /* Perform any local cleanups required when we are done with a particular
344*ef5ccd6cSJohn Marino objfile. I.e, we are in the process of discarding all symbol information
345*ef5ccd6cSJohn Marino for an objfile, freeing up all memory held for it, and unlinking the
346*ef5ccd6cSJohn Marino objfile struct from the global list of known objfiles. */
347*ef5ccd6cSJohn Marino
348*ef5ccd6cSJohn Marino static void
som_symfile_finish(struct objfile * objfile)349*ef5ccd6cSJohn Marino som_symfile_finish (struct objfile *objfile)
350*ef5ccd6cSJohn Marino {
351*ef5ccd6cSJohn Marino }
352*ef5ccd6cSJohn Marino
353*ef5ccd6cSJohn Marino /* SOM specific initialization routine for reading symbols. */
354*ef5ccd6cSJohn Marino
355*ef5ccd6cSJohn Marino static void
som_symfile_init(struct objfile * objfile)356*ef5ccd6cSJohn Marino som_symfile_init (struct objfile *objfile)
357*ef5ccd6cSJohn Marino {
358*ef5ccd6cSJohn Marino /* SOM objects may be reordered, so set OBJF_REORDERED. If we
359*ef5ccd6cSJohn Marino find this causes a significant slowdown in gdb then we could
360*ef5ccd6cSJohn Marino set it in the debug symbol readers only when necessary. */
361*ef5ccd6cSJohn Marino objfile->flags |= OBJF_REORDERED;
362*ef5ccd6cSJohn Marino }
363*ef5ccd6cSJohn Marino
364*ef5ccd6cSJohn Marino /* SOM specific parsing routine for section offsets.
365*ef5ccd6cSJohn Marino
366*ef5ccd6cSJohn Marino Plain and simple for now. */
367*ef5ccd6cSJohn Marino
368*ef5ccd6cSJohn Marino static void
som_symfile_offsets(struct objfile * objfile,struct section_addr_info * addrs)369*ef5ccd6cSJohn Marino som_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
370*ef5ccd6cSJohn Marino {
371*ef5ccd6cSJohn Marino int i;
372*ef5ccd6cSJohn Marino CORE_ADDR text_addr;
373*ef5ccd6cSJohn Marino
374*ef5ccd6cSJohn Marino objfile->num_sections = bfd_count_sections (objfile->obfd);
375*ef5ccd6cSJohn Marino objfile->section_offsets = (struct section_offsets *)
376*ef5ccd6cSJohn Marino obstack_alloc (&objfile->objfile_obstack,
377*ef5ccd6cSJohn Marino SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
378*ef5ccd6cSJohn Marino
379*ef5ccd6cSJohn Marino /* FIXME: ezannoni 2000-04-20 The section names in SOM are not
380*ef5ccd6cSJohn Marino .text, .data, etc, but $TEXT$, $DATA$,... We should initialize
381*ef5ccd6cSJohn Marino SET_OFF_* from bfd. (See default_symfile_offsets()). But I don't
382*ef5ccd6cSJohn Marino know the correspondence between SOM sections and GDB's idea of
383*ef5ccd6cSJohn Marino section names. So for now we default to what is was before these
384*ef5ccd6cSJohn Marino changes. */
385*ef5ccd6cSJohn Marino objfile->sect_index_text = 0;
386*ef5ccd6cSJohn Marino objfile->sect_index_data = 1;
387*ef5ccd6cSJohn Marino objfile->sect_index_bss = 2;
388*ef5ccd6cSJohn Marino objfile->sect_index_rodata = 3;
389*ef5ccd6cSJohn Marino
390*ef5ccd6cSJohn Marino /* First see if we're a shared library. If so, get the section
391*ef5ccd6cSJohn Marino offsets from the library, else get them from addrs. */
392*ef5ccd6cSJohn Marino if (!som_solib_section_offsets (objfile, objfile->section_offsets))
393*ef5ccd6cSJohn Marino {
394*ef5ccd6cSJohn Marino /* Note: Here is OK to compare with ".text" because this is the
395*ef5ccd6cSJohn Marino name that gdb itself gives to that section, not the SOM
396*ef5ccd6cSJohn Marino name. */
397*ef5ccd6cSJohn Marino for (i = 0; i < addrs->num_sections && addrs->other[i].name; i++)
398*ef5ccd6cSJohn Marino if (strcmp (addrs->other[i].name, ".text") == 0)
399*ef5ccd6cSJohn Marino break;
400*ef5ccd6cSJohn Marino text_addr = addrs->other[i].addr;
401*ef5ccd6cSJohn Marino
402*ef5ccd6cSJohn Marino for (i = 0; i < objfile->num_sections; i++)
403*ef5ccd6cSJohn Marino (objfile->section_offsets)->offsets[i] = text_addr;
404*ef5ccd6cSJohn Marino }
405*ef5ccd6cSJohn Marino }
406*ef5ccd6cSJohn Marino
407*ef5ccd6cSJohn Marino
408*ef5ccd6cSJohn Marino
409*ef5ccd6cSJohn Marino /* Register that we are able to handle SOM object file formats. */
410*ef5ccd6cSJohn Marino
411*ef5ccd6cSJohn Marino static const struct sym_fns som_sym_fns =
412*ef5ccd6cSJohn Marino {
413*ef5ccd6cSJohn Marino bfd_target_som_flavour,
414*ef5ccd6cSJohn Marino som_new_init, /* init anything gbl to entire symtab */
415*ef5ccd6cSJohn Marino som_symfile_init, /* read initial info, setup for sym_read() */
416*ef5ccd6cSJohn Marino som_symfile_read, /* read a symbol file into symtab */
417*ef5ccd6cSJohn Marino NULL, /* sym_read_psymbols */
418*ef5ccd6cSJohn Marino som_symfile_finish, /* finished with file, cleanup */
419*ef5ccd6cSJohn Marino som_symfile_offsets, /* Translate ext. to int. relocation */
420*ef5ccd6cSJohn Marino default_symfile_segments, /* Get segment information from a file. */
421*ef5ccd6cSJohn Marino NULL,
422*ef5ccd6cSJohn Marino default_symfile_relocate, /* Relocate a debug section. */
423*ef5ccd6cSJohn Marino NULL, /* sym_get_probes */
424*ef5ccd6cSJohn Marino &psym_functions
425*ef5ccd6cSJohn Marino };
426*ef5ccd6cSJohn Marino
427*ef5ccd6cSJohn Marino initialize_file_ftype _initialize_somread;
428*ef5ccd6cSJohn Marino
429*ef5ccd6cSJohn Marino void
_initialize_somread(void)430*ef5ccd6cSJohn Marino _initialize_somread (void)
431*ef5ccd6cSJohn Marino {
432*ef5ccd6cSJohn Marino add_symtab_fns (&som_sym_fns);
433*ef5ccd6cSJohn Marino }
434