1e93f7393Sniklas /* Read hp debug symbols and convert to internal format, for GDB.
2b725ae77Skettenis Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3b725ae77Skettenis 2002, 2003, 2004 Free Software Foundation, Inc.
4e93f7393Sniklas
5e93f7393Sniklas This file is part of GDB.
6e93f7393Sniklas
7e93f7393Sniklas This program is free software; you can redistribute it and/or modify
8e93f7393Sniklas it under the terms of the GNU General Public License as published by
9e93f7393Sniklas the Free Software Foundation; either version 2 of the License, or
10e93f7393Sniklas (at your option) any later version.
11e93f7393Sniklas
12e93f7393Sniklas This program is distributed in the hope that it will be useful,
13e93f7393Sniklas but WITHOUT ANY WARRANTY; without even the implied warranty of
14e93f7393Sniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15e93f7393Sniklas GNU General Public License for more details.
16e93f7393Sniklas
17e93f7393Sniklas You should have received a copy of the GNU General Public License
18e93f7393Sniklas along with this program; if not, write to the Free Software
19b725ae77Skettenis Foundation, Inc., 59 Temple Place - Suite 330,
20b725ae77Skettenis Boston, MA 02111-1307, USA.
21e93f7393Sniklas
22e93f7393Sniklas Written by the Center for Software Science at the University of Utah
23e93f7393Sniklas and by Cygnus Support. */
24e93f7393Sniklas
25e93f7393Sniklas #include "defs.h"
26e93f7393Sniklas #include "bfd.h"
27e93f7393Sniklas #include "gdb_string.h"
28e93f7393Sniklas #include "hp-symtab.h"
29e93f7393Sniklas #include "syms.h"
30e93f7393Sniklas #include "symtab.h"
31e93f7393Sniklas #include "symfile.h"
32e93f7393Sniklas #include "objfiles.h"
33e93f7393Sniklas #include "buildsym.h"
34e93f7393Sniklas #include "complaints.h"
35e93f7393Sniklas #include "gdb-stabs.h"
36e93f7393Sniklas #include "gdbtypes.h"
37e93f7393Sniklas #include "demangle.h"
38b725ae77Skettenis #include "somsolib.h"
39b725ae77Skettenis #include "gdb_assert.h"
40*63addd46Skettenis #include "hppa-tdep.h"
41e93f7393Sniklas
42e93f7393Sniklas /* Private information attached to an objfile which we use to find
43e93f7393Sniklas and internalize the HP C debug symbols within that objfile. */
44e93f7393Sniklas
45e93f7393Sniklas struct hpread_symfile_info
46e93f7393Sniklas {
47e93f7393Sniklas /* The contents of each of the debug sections (there are 4 of them). */
48e93f7393Sniklas char *gntt;
49e93f7393Sniklas char *lntt;
50e93f7393Sniklas char *slt;
51e93f7393Sniklas char *vt;
52e93f7393Sniklas
53e93f7393Sniklas /* We keep the size of the $VT$ section for range checking. */
54e93f7393Sniklas unsigned int vt_size;
55e93f7393Sniklas
56e93f7393Sniklas /* Some routines still need to know the number of symbols in the
57e93f7393Sniklas main debug sections ($LNTT$ and $GNTT$). */
58e93f7393Sniklas unsigned int lntt_symcount;
59e93f7393Sniklas unsigned int gntt_symcount;
60e93f7393Sniklas
61e93f7393Sniklas /* To keep track of all the types we've processed. */
62b725ae77Skettenis struct type **dntt_type_vector;
63b725ae77Skettenis int dntt_type_vector_length;
64e93f7393Sniklas
65e93f7393Sniklas /* Keeps track of the beginning of a range of source lines. */
66e93f7393Sniklas sltpointer sl_index;
67e93f7393Sniklas
68e93f7393Sniklas /* Some state variables we'll need. */
69e93f7393Sniklas int within_function;
70e93f7393Sniklas
71e93f7393Sniklas /* Keep track of the current function's address. We may need to look
72e93f7393Sniklas up something based on this address. */
73e93f7393Sniklas unsigned int current_function_value;
74e93f7393Sniklas };
75e93f7393Sniklas
76e93f7393Sniklas /* Accessor macros to get at the fields. */
77e93f7393Sniklas #define HPUX_SYMFILE_INFO(o) \
78e93f7393Sniklas ((struct hpread_symfile_info *)((o)->sym_private))
79e93f7393Sniklas #define GNTT(o) (HPUX_SYMFILE_INFO(o)->gntt)
80e93f7393Sniklas #define LNTT(o) (HPUX_SYMFILE_INFO(o)->lntt)
81e93f7393Sniklas #define SLT(o) (HPUX_SYMFILE_INFO(o)->slt)
82e93f7393Sniklas #define VT(o) (HPUX_SYMFILE_INFO(o)->vt)
83e93f7393Sniklas #define VT_SIZE(o) (HPUX_SYMFILE_INFO(o)->vt_size)
84e93f7393Sniklas #define LNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->lntt_symcount)
85e93f7393Sniklas #define GNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->gntt_symcount)
86b725ae77Skettenis #define DNTT_TYPE_VECTOR(o) (HPUX_SYMFILE_INFO(o)->dntt_type_vector)
87b725ae77Skettenis #define DNTT_TYPE_VECTOR_LENGTH(o) \
88b725ae77Skettenis (HPUX_SYMFILE_INFO(o)->dntt_type_vector_length)
89e93f7393Sniklas #define SL_INDEX(o) (HPUX_SYMFILE_INFO(o)->sl_index)
90e93f7393Sniklas #define WITHIN_FUNCTION(o) (HPUX_SYMFILE_INFO(o)->within_function)
91e93f7393Sniklas #define CURRENT_FUNCTION_VALUE(o) (HPUX_SYMFILE_INFO(o)->current_function_value)
92e93f7393Sniklas
93e93f7393Sniklas
94e93f7393Sniklas /* We put a pointer to this structure in the read_symtab_private field
95e93f7393Sniklas of the psymtab. */
96e93f7393Sniklas
97e93f7393Sniklas struct symloc
98e93f7393Sniklas {
99e93f7393Sniklas /* The offset within the file symbol table of first local symbol for
100e93f7393Sniklas this file. */
101e93f7393Sniklas
102e93f7393Sniklas int ldsymoff;
103e93f7393Sniklas
104e93f7393Sniklas /* Length (in bytes) of the section of the symbol table devoted to
105e93f7393Sniklas this file's symbols (actually, the section bracketed may contain
106e93f7393Sniklas more than just this file's symbols). If ldsymlen is 0, the only
107e93f7393Sniklas reason for this thing's existence is the dependency list.
108e93f7393Sniklas Nothing else will happen when it is read in. */
109e93f7393Sniklas
110e93f7393Sniklas int ldsymlen;
111e93f7393Sniklas };
112e93f7393Sniklas
113e93f7393Sniklas #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
114e93f7393Sniklas #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
115e93f7393Sniklas #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
116e93f7393Sniklas
117e93f7393Sniklas /* Complaints about the symbols we have encountered. */
118b725ae77Skettenis static void
lbrac_unmatched_complaint(int arg1)119b725ae77Skettenis lbrac_unmatched_complaint (int arg1)
120b725ae77Skettenis {
121b725ae77Skettenis complaint (&symfile_complaints, "unmatched N_LBRAC before symtab pos %d",
122b725ae77Skettenis arg1);
123b725ae77Skettenis }
124e93f7393Sniklas
125b725ae77Skettenis static void
lbrac_mismatch_complaint(int arg1)126b725ae77Skettenis lbrac_mismatch_complaint (int arg1)
127b725ae77Skettenis {
128b725ae77Skettenis complaint (&symfile_complaints,
129b725ae77Skettenis "N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", arg1);
130b725ae77Skettenis }
131e93f7393Sniklas
132b725ae77Skettenis /* To generate dumping code, uncomment this define. The dumping
133b725ae77Skettenis itself is controlled by routine-local statics called "dumping". */
134b725ae77Skettenis /* #define DUMPING 1 */
135e93f7393Sniklas
136b725ae77Skettenis /* To use the quick look-up tables, uncomment this define. */
137b725ae77Skettenis #define QUICK_LOOK_UP 1
138e93f7393Sniklas
139b725ae77Skettenis /* To call PXDB to process un-processed files, uncomment this define. */
140b725ae77Skettenis #define USE_PXDB 1
141e93f7393Sniklas
142b725ae77Skettenis /* Forward procedure declarations */
143e93f7393Sniklas
144b725ae77Skettenis /* Used in somread.c. */
145b725ae77Skettenis void hpread_symfile_init (struct objfile *);
146e93f7393Sniklas
147b725ae77Skettenis void do_pxdb (bfd *);
148e93f7393Sniklas
149b725ae77Skettenis void hpread_build_psymtabs (struct objfile *, int);
150e93f7393Sniklas
151b725ae77Skettenis void hpread_symfile_finish (struct objfile *);
152e93f7393Sniklas
153b725ae77Skettenis static void set_namestring (union dnttentry *sym, char **namep,
154b725ae77Skettenis struct objfile *objfile);
155b725ae77Skettenis
156b725ae77Skettenis static union dnttentry *hpread_get_gntt (int, struct objfile *);
157b725ae77Skettenis
158b725ae77Skettenis static union dnttentry *hpread_get_lntt (int index, struct objfile *objfile);
159b725ae77Skettenis
160b725ae77Skettenis
161b725ae77Skettenis static unsigned long hpread_get_textlow (int, int, struct objfile *, int);
162e93f7393Sniklas
163e93f7393Sniklas static struct partial_symtab *hpread_start_psymtab
164b725ae77Skettenis (struct objfile *, char *, CORE_ADDR, int,
165b725ae77Skettenis struct partial_symbol **, struct partial_symbol **);
166e93f7393Sniklas
167e93f7393Sniklas static struct partial_symtab *hpread_end_psymtab
168b725ae77Skettenis (struct partial_symtab *, char **, int, int, CORE_ADDR,
169b725ae77Skettenis struct partial_symtab **, int);
170b725ae77Skettenis
171b725ae77Skettenis static unsigned long hpread_get_scope_start (sltpointer, struct objfile *);
172b725ae77Skettenis
173b725ae77Skettenis static unsigned long hpread_get_line (sltpointer, struct objfile *);
174b725ae77Skettenis
175b725ae77Skettenis static CORE_ADDR hpread_get_location (sltpointer, struct objfile *);
176b725ae77Skettenis
177b725ae77Skettenis static int hpread_has_name (enum dntt_entry_type kind);
178b725ae77Skettenis
179b725ae77Skettenis static void hpread_psymtab_to_symtab_1 (struct partial_symtab *);
180b725ae77Skettenis
181b725ae77Skettenis static void hpread_psymtab_to_symtab (struct partial_symtab *);
182e93f7393Sniklas
183e93f7393Sniklas static struct symtab *hpread_expand_symtab
184b725ae77Skettenis (struct objfile *, int, int, CORE_ADDR, int,
185b725ae77Skettenis struct section_offsets *, char *);
186e93f7393Sniklas
187b725ae77Skettenis static int hpread_type_translate (dnttpointer);
188e93f7393Sniklas
189b725ae77Skettenis static struct type **hpread_lookup_type (dnttpointer, struct objfile *);
190b725ae77Skettenis
191b725ae77Skettenis static struct type *hpread_alloc_type (dnttpointer, struct objfile *);
192b725ae77Skettenis
193b725ae77Skettenis static struct type *hpread_read_enum_type
194b725ae77Skettenis (dnttpointer, union dnttentry *, struct objfile *);
195e93f7393Sniklas
196e93f7393Sniklas static struct type *hpread_read_function_type
197b725ae77Skettenis (dnttpointer, union dnttentry *, struct objfile *, int);
198e93f7393Sniklas
199b725ae77Skettenis static struct type *hpread_read_doc_function_type
200b725ae77Skettenis (dnttpointer, union dnttentry *, struct objfile *, int);
201e93f7393Sniklas
202b725ae77Skettenis static struct type *hpread_read_struct_type
203b725ae77Skettenis (dnttpointer, union dnttentry *, struct objfile *);
204e93f7393Sniklas
205b725ae77Skettenis static struct type *hpread_get_nth_template_arg (struct objfile *, int);
206e93f7393Sniklas
207b725ae77Skettenis static struct type *hpread_read_templ_arg_type
208b725ae77Skettenis (dnttpointer, union dnttentry *, struct objfile *, char *);
209e93f7393Sniklas
210b725ae77Skettenis static struct type *hpread_read_set_type
211b725ae77Skettenis (dnttpointer, union dnttentry *, struct objfile *);
212b725ae77Skettenis
213b725ae77Skettenis static struct type *hpread_read_array_type
214b725ae77Skettenis (dnttpointer, union dnttentry *dn_bufp, struct objfile *objfile);
215b725ae77Skettenis
216b725ae77Skettenis static struct type *hpread_read_subrange_type
217b725ae77Skettenis (dnttpointer, union dnttentry *, struct objfile *);
218b725ae77Skettenis
219b725ae77Skettenis static struct type *hpread_type_lookup (dnttpointer, struct objfile *);
220b725ae77Skettenis
221b725ae77Skettenis static sltpointer hpread_record_lines
222b725ae77Skettenis (struct subfile *, sltpointer, sltpointer, struct objfile *, CORE_ADDR);
223b725ae77Skettenis
224b725ae77Skettenis static void hpread_process_one_debug_symbol
225b725ae77Skettenis (union dnttentry *, char *, struct section_offsets *,
226b725ae77Skettenis struct objfile *, CORE_ADDR, int, char *, int, int *);
227b725ae77Skettenis
228b725ae77Skettenis static int hpread_get_scope_depth (union dnttentry *, struct objfile *, int);
229b725ae77Skettenis
230b725ae77Skettenis static void fix_static_member_physnames
231b725ae77Skettenis (struct type *, char *, struct objfile *);
232b725ae77Skettenis
233b725ae77Skettenis static void fixup_class_method_type
234b725ae77Skettenis (struct type *, struct type *, struct objfile *);
235b725ae77Skettenis
236b725ae77Skettenis static void hpread_adjust_bitoffsets (struct type *, int);
237b725ae77Skettenis
238*63addd46Skettenis static int hpread_adjust_stack_address (CORE_ADDR func_addr);
239*63addd46Skettenis
240b725ae77Skettenis static dnttpointer hpread_get_next_skip_over_anon_unions
241b725ae77Skettenis (int, dnttpointer, union dnttentry **, struct objfile *);
242e93f7393Sniklas
243e93f7393Sniklas
244b725ae77Skettenis /* Static used to indicate a class type that requires a
245b725ae77Skettenis fix-up of one of its method types */
246b725ae77Skettenis static struct type *fixup_class = NULL;
247b725ae77Skettenis
248b725ae77Skettenis /* Static used to indicate the method type that is to be
249b725ae77Skettenis used to fix-up the type for fixup_class */
250b725ae77Skettenis static struct type *fixup_method = NULL;
251b725ae77Skettenis
252b725ae77Skettenis #ifdef USE_PXDB
253b725ae77Skettenis
254b725ae77Skettenis /* NOTE use of system files! May not be portable. */
255b725ae77Skettenis
256b725ae77Skettenis #define PXDB_SVR4 "/opt/langtools/bin/pxdb"
257b725ae77Skettenis #define PXDB_BSD "/usr/bin/pxdb"
258b725ae77Skettenis
259b725ae77Skettenis #include <stdlib.h>
260b725ae77Skettenis #include "gdb_string.h"
261b725ae77Skettenis
262b725ae77Skettenis /* check for the existence of a file, given its full pathname */
263b725ae77Skettenis static int
file_exists(char * filename)264b725ae77Skettenis file_exists (char *filename)
265b725ae77Skettenis {
266b725ae77Skettenis if (filename)
267b725ae77Skettenis return (access (filename, F_OK) == 0);
268b725ae77Skettenis return 0;
269b725ae77Skettenis }
270b725ae77Skettenis
271b725ae77Skettenis
272b725ae77Skettenis /* Translate from the "hp_language" enumeration in hp-symtab.h
273b725ae77Skettenis used in the debug info to gdb's generic enumeration in defs.h. */
274b725ae77Skettenis static enum language
trans_lang(enum hp_language in_lang)275b725ae77Skettenis trans_lang (enum hp_language in_lang)
276b725ae77Skettenis {
277b725ae77Skettenis if (in_lang == HP_LANGUAGE_C)
278b725ae77Skettenis return language_c;
279b725ae77Skettenis
280b725ae77Skettenis else if (in_lang == HP_LANGUAGE_CPLUSPLUS)
281b725ae77Skettenis return language_cplus;
282b725ae77Skettenis
283b725ae77Skettenis else if (in_lang == HP_LANGUAGE_FORTRAN)
284b725ae77Skettenis return language_fortran;
285b725ae77Skettenis
286b725ae77Skettenis else
287b725ae77Skettenis return language_unknown;
288b725ae77Skettenis }
289b725ae77Skettenis
290b725ae77Skettenis static char main_string[] = "main";
291b725ae77Skettenis
292b725ae77Skettenis
293b725ae77Skettenis /* Given the native debug symbol SYM, set NAMEP to the name associated
294b725ae77Skettenis with the debug symbol. Note we may be called with a debug symbol which
295b725ae77Skettenis has no associated name, in that case we return an empty string. */
296b725ae77Skettenis
297b725ae77Skettenis static void
set_namestring(union dnttentry * sym,char ** namep,struct objfile * objfile)298b725ae77Skettenis set_namestring (union dnttentry *sym, char **namep, struct objfile *objfile)
299b725ae77Skettenis {
300b725ae77Skettenis /* Note that we "know" that the name for any symbol is always in the same
301b725ae77Skettenis place. Hence we don't have to conditionalize on the symbol type. */
302b725ae77Skettenis if (! hpread_has_name (sym->dblock.kind))
303b725ae77Skettenis *namep = "";
304b725ae77Skettenis else if ((unsigned) sym->dsfile.name >= VT_SIZE (objfile))
305b725ae77Skettenis {
306b725ae77Skettenis complaint (&symfile_complaints, "bad string table offset in symbol %d",
307b725ae77Skettenis symnum);
308b725ae77Skettenis *namep = "";
309b725ae77Skettenis }
310b725ae77Skettenis else
311b725ae77Skettenis *namep = sym->dsfile.name + VT (objfile);
312b725ae77Skettenis }
313b725ae77Skettenis
314b725ae77Skettenis /* Call PXDB to process our file.
315b725ae77Skettenis
316b725ae77Skettenis Approach copied from DDE's "dbgk_run_pxdb". Note: we
317b725ae77Skettenis don't check for BSD location of pxdb, nor for existence
318b725ae77Skettenis of pxdb itself, etc.
319b725ae77Skettenis
320b725ae77Skettenis NOTE: uses system function and string functions directly.
321b725ae77Skettenis
322b725ae77Skettenis Return value: 1 if ok, 0 if not */
323b725ae77Skettenis static int
hpread_call_pxdb(const char * file_name)324b725ae77Skettenis hpread_call_pxdb (const char *file_name)
325b725ae77Skettenis {
326b725ae77Skettenis char *p;
327b725ae77Skettenis int status;
328b725ae77Skettenis int retval;
329b725ae77Skettenis
330b725ae77Skettenis if (file_exists (PXDB_SVR4))
331b725ae77Skettenis {
332b725ae77Skettenis p = xmalloc (strlen (PXDB_SVR4) + strlen (file_name) + 2);
333b725ae77Skettenis strcpy (p, PXDB_SVR4);
334b725ae77Skettenis strcat (p, " ");
335b725ae77Skettenis strcat (p, file_name);
336b725ae77Skettenis
337b725ae77Skettenis warning ("File not processed by pxdb--about to process now.\n");
338b725ae77Skettenis status = system (p);
339b725ae77Skettenis
340b725ae77Skettenis retval = (status == 0);
341b725ae77Skettenis }
342b725ae77Skettenis else
343b725ae77Skettenis {
344b725ae77Skettenis warning ("pxdb not found at standard location: /opt/langtools/bin\ngdb will not be able to debug %s.\nPlease install pxdb at the above location and then restart gdb.\nYou can also run pxdb on %s with the command\n\"pxdb %s\" and then restart gdb.", file_name, file_name, file_name);
345b725ae77Skettenis
346b725ae77Skettenis retval = 0;
347b725ae77Skettenis }
348b725ae77Skettenis return retval;
349b725ae77Skettenis } /* hpread_call_pxdb */
350b725ae77Skettenis
351b725ae77Skettenis
352b725ae77Skettenis /* Return 1 if the file turns out to need pre-processing
353b725ae77Skettenis by PXDB, and we have thus called PXDB to do this processing
354b725ae77Skettenis and the file therefore needs to be re-loaded. Otherwise
355b725ae77Skettenis return 0. */
356b725ae77Skettenis static int
hpread_pxdb_needed(bfd * sym_bfd)357b725ae77Skettenis hpread_pxdb_needed (bfd *sym_bfd)
358b725ae77Skettenis {
359b725ae77Skettenis asection *pinfo_section, *debug_section, *header_section;
360b725ae77Skettenis unsigned int do_pxdb;
361b725ae77Skettenis char *buf;
362b725ae77Skettenis bfd_size_type header_section_size;
363b725ae77Skettenis
364b725ae77Skettenis unsigned long tmp;
365b725ae77Skettenis unsigned int pxdbed;
366b725ae77Skettenis
367b725ae77Skettenis header_section = bfd_get_section_by_name (sym_bfd, "$HEADER$");
368b725ae77Skettenis if (!header_section)
369b725ae77Skettenis {
370b725ae77Skettenis return 0; /* No header at all, can't recover... */
371b725ae77Skettenis }
372b725ae77Skettenis
373b725ae77Skettenis debug_section = bfd_get_section_by_name (sym_bfd, "$DEBUG$");
374b725ae77Skettenis pinfo_section = bfd_get_section_by_name (sym_bfd, "$PINFO$");
375b725ae77Skettenis
376b725ae77Skettenis if (pinfo_section && !debug_section)
377b725ae77Skettenis {
378b725ae77Skettenis /* Debug info with DOC, has different header format.
379b725ae77Skettenis this only happens if the file was pxdbed and compiled optimized
380b725ae77Skettenis otherwise the PINFO section is not there. */
381b725ae77Skettenis header_section_size = bfd_section_size (objfile->obfd, header_section);
382b725ae77Skettenis
383b725ae77Skettenis if (header_section_size == (bfd_size_type) sizeof (DOC_info_PXDB_header))
384b725ae77Skettenis {
385b725ae77Skettenis buf = alloca (sizeof (DOC_info_PXDB_header));
386*63addd46Skettenis memset (buf, 0, sizeof (DOC_info_PXDB_header));
387b725ae77Skettenis
388b725ae77Skettenis if (!bfd_get_section_contents (sym_bfd,
389b725ae77Skettenis header_section,
390b725ae77Skettenis buf, 0,
391b725ae77Skettenis header_section_size))
392b725ae77Skettenis error ("bfd_get_section_contents\n");
393b725ae77Skettenis
394b725ae77Skettenis tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 4));
395b725ae77Skettenis pxdbed = (tmp >> 31) & 0x1;
396b725ae77Skettenis
397b725ae77Skettenis if (!pxdbed)
398b725ae77Skettenis error ("file debug header info invalid\n");
399b725ae77Skettenis do_pxdb = 0;
400b725ae77Skettenis }
401b725ae77Skettenis
402b725ae77Skettenis else
403b725ae77Skettenis error ("invalid $HEADER$ size in executable \n");
404b725ae77Skettenis }
405b725ae77Skettenis
406b725ae77Skettenis else
407b725ae77Skettenis {
408b725ae77Skettenis
409b725ae77Skettenis /* this can be three different cases:
410b725ae77Skettenis 1. pxdbed and not doc
411b725ae77Skettenis - DEBUG and HEADER sections are there
412b725ae77Skettenis - header is PXDB_header type
413b725ae77Skettenis - pxdbed flag is set to 1
414b725ae77Skettenis
415b725ae77Skettenis 2. not pxdbed and doc
416b725ae77Skettenis - DEBUG and HEADER sections are there
417b725ae77Skettenis - header is DOC_info_header type
418b725ae77Skettenis - pxdbed flag is set to 0
419b725ae77Skettenis
420b725ae77Skettenis 3. not pxdbed and not doc
421b725ae77Skettenis - DEBUG and HEADER sections are there
422b725ae77Skettenis - header is XDB_header type
423b725ae77Skettenis - pxdbed flag is set to 0
424b725ae77Skettenis
425b725ae77Skettenis NOTE: the pxdbed flag is meaningful also in the not
426b725ae77Skettenis already pxdb processed version of the header,
427b725ae77Skettenis because in case on non-already processed by pxdb files
428b725ae77Skettenis that same bit in the header would be always zero.
429b725ae77Skettenis Why? Because the bit is the leftmost bit of a word
430b725ae77Skettenis which contains a 'length' which is always a positive value
431b725ae77Skettenis so that bit is never set to 1 (otherwise it would be negative)
432b725ae77Skettenis
433b725ae77Skettenis Given the above, we have two choices : either we ignore the
434b725ae77Skettenis size of the header itself and just look at the pxdbed field,
435b725ae77Skettenis or we check the size and then we (for safety and paranoia related
436b725ae77Skettenis issues) check the bit.
437b725ae77Skettenis The first solution is used by DDE, the second by PXDB itself.
438b725ae77Skettenis I am using the second one here, because I already wrote it,
439b725ae77Skettenis and it is the end of a long day.
440b725ae77Skettenis Also, using the first approach would still involve size issues
441b725ae77Skettenis because we need to read in the contents of the header section, and
442b725ae77Skettenis give the correct amount of stuff we want to read to the
443b725ae77Skettenis get_bfd_section_contents function. */
444b725ae77Skettenis
445b725ae77Skettenis /* decide which case depending on the size of the header section.
446b725ae77Skettenis The size is as defined in hp-symtab.h */
447b725ae77Skettenis
448b725ae77Skettenis header_section_size = bfd_section_size (objfile->obfd, header_section);
449b725ae77Skettenis
450b725ae77Skettenis if (header_section_size == (bfd_size_type) sizeof (PXDB_header)) /* pxdb and not doc */
451b725ae77Skettenis {
452b725ae77Skettenis
453b725ae77Skettenis buf = alloca (sizeof (PXDB_header));
454*63addd46Skettenis memset (buf, 0, sizeof (PXDB_header));
455b725ae77Skettenis if (!bfd_get_section_contents (sym_bfd,
456b725ae77Skettenis header_section,
457b725ae77Skettenis buf, 0,
458b725ae77Skettenis header_section_size))
459b725ae77Skettenis error ("bfd_get_section_contents\n");
460b725ae77Skettenis
461b725ae77Skettenis tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 3));
462b725ae77Skettenis pxdbed = (tmp >> 31) & 0x1;
463b725ae77Skettenis
464b725ae77Skettenis if (pxdbed)
465b725ae77Skettenis do_pxdb = 0;
466b725ae77Skettenis else
467b725ae77Skettenis error ("file debug header invalid\n");
468b725ae77Skettenis }
469b725ae77Skettenis else /*not pxdbed and doc OR not pxdbed and non doc */
470b725ae77Skettenis do_pxdb = 1;
471b725ae77Skettenis }
472b725ae77Skettenis
473b725ae77Skettenis if (do_pxdb)
474b725ae77Skettenis {
475b725ae77Skettenis return 1;
476b725ae77Skettenis }
477b725ae77Skettenis else
478b725ae77Skettenis {
479b725ae77Skettenis return 0;
480b725ae77Skettenis }
481b725ae77Skettenis } /* hpread_pxdb_needed */
482b725ae77Skettenis
483b725ae77Skettenis #endif
484b725ae77Skettenis
485b725ae77Skettenis /* Check whether the file needs to be preprocessed by pxdb.
486b725ae77Skettenis If so, call pxdb. */
487b725ae77Skettenis
488b725ae77Skettenis void
do_pxdb(bfd * sym_bfd)489b725ae77Skettenis do_pxdb (bfd *sym_bfd)
490b725ae77Skettenis {
491b725ae77Skettenis /* The following code is HP-specific. The "right" way of
492b725ae77Skettenis doing this is unknown, but we bet would involve a target-
493b725ae77Skettenis specific pre-file-load check using a generic mechanism. */
494b725ae77Skettenis
495b725ae77Skettenis /* This code will not be executed if the file is not in SOM
496b725ae77Skettenis format (i.e. if compiled with gcc) */
497b725ae77Skettenis if (hpread_pxdb_needed (sym_bfd))
498b725ae77Skettenis {
499b725ae77Skettenis /*This file has not been pre-processed. Preprocess now */
500b725ae77Skettenis
501b725ae77Skettenis if (hpread_call_pxdb (sym_bfd->filename))
502b725ae77Skettenis {
503b725ae77Skettenis /* The call above has changed the on-disk file,
504b725ae77Skettenis we can close the file anyway, because the
505b725ae77Skettenis symbols will be reread in when the target is run */
506b725ae77Skettenis bfd_close (sym_bfd);
507b725ae77Skettenis }
508b725ae77Skettenis }
509b725ae77Skettenis }
510b725ae77Skettenis
511b725ae77Skettenis
512b725ae77Skettenis
513b725ae77Skettenis #ifdef QUICK_LOOK_UP
514b725ae77Skettenis
515b725ae77Skettenis /* Code to handle quick lookup-tables follows. */
516b725ae77Skettenis
517b725ae77Skettenis
518b725ae77Skettenis /* Some useful macros */
519b725ae77Skettenis #define VALID_FILE(i) ((i) < pxdb_header_p->fd_entries)
520b725ae77Skettenis #define VALID_MODULE(i) ((i) < pxdb_header_p->md_entries)
521b725ae77Skettenis #define VALID_PROC(i) ((i) < pxdb_header_p->pd_entries)
522b725ae77Skettenis #define VALID_CLASS(i) ((i) < pxdb_header_p->cd_entries)
523b725ae77Skettenis
524b725ae77Skettenis #define FILE_START(i) (qFD[i].adrStart)
525b725ae77Skettenis #define MODULE_START(i) (qMD[i].adrStart)
526b725ae77Skettenis #define PROC_START(i) (qPD[i].adrStart)
527b725ae77Skettenis
528b725ae77Skettenis #define FILE_END(i) (qFD[i].adrEnd)
529b725ae77Skettenis #define MODULE_END(i) (qMD[i].adrEnd)
530b725ae77Skettenis #define PROC_END(i) (qPD[i].adrEnd)
531b725ae77Skettenis
532b725ae77Skettenis #define FILE_ISYM(i) (qFD[i].isym)
533b725ae77Skettenis #define MODULE_ISYM(i) (qMD[i].isym)
534b725ae77Skettenis #define PROC_ISYM(i) (qPD[i].isym)
535b725ae77Skettenis
536b725ae77Skettenis #define VALID_CURR_FILE (curr_fd < pxdb_header_p->fd_entries)
537b725ae77Skettenis #define VALID_CURR_MODULE (curr_md < pxdb_header_p->md_entries)
538b725ae77Skettenis #define VALID_CURR_PROC (curr_pd < pxdb_header_p->pd_entries)
539b725ae77Skettenis #define VALID_CURR_CLASS (curr_cd < pxdb_header_p->cd_entries)
540b725ae77Skettenis
541b725ae77Skettenis #define CURR_FILE_START (qFD[curr_fd].adrStart)
542b725ae77Skettenis #define CURR_MODULE_START (qMD[curr_md].adrStart)
543b725ae77Skettenis #define CURR_PROC_START (qPD[curr_pd].adrStart)
544b725ae77Skettenis
545b725ae77Skettenis #define CURR_FILE_END (qFD[curr_fd].adrEnd)
546b725ae77Skettenis #define CURR_MODULE_END (qMD[curr_md].adrEnd)
547b725ae77Skettenis #define CURR_PROC_END (qPD[curr_pd].adrEnd)
548b725ae77Skettenis
549b725ae77Skettenis #define CURR_FILE_ISYM (qFD[curr_fd].isym)
550b725ae77Skettenis #define CURR_MODULE_ISYM (qMD[curr_md].isym)
551b725ae77Skettenis #define CURR_PROC_ISYM (qPD[curr_pd].isym)
552b725ae77Skettenis
553b725ae77Skettenis #define TELL_OBJFILE \
554b725ae77Skettenis do { \
555b725ae77Skettenis if( !told_objfile ) { \
556b725ae77Skettenis told_objfile = 1; \
557b725ae77Skettenis warning ("\nIn object file \"%s\":\n", \
558b725ae77Skettenis objfile->name); \
559b725ae77Skettenis } \
560b725ae77Skettenis } while (0)
561b725ae77Skettenis
562b725ae77Skettenis
563b725ae77Skettenis
564b725ae77Skettenis /* Keeping track of the start/end symbol table (LNTT) indices of
565b725ae77Skettenis psymtabs created so far */
566b725ae77Skettenis
567b725ae77Skettenis typedef struct
568b725ae77Skettenis {
569b725ae77Skettenis int start;
570b725ae77Skettenis int end;
571b725ae77Skettenis }
572b725ae77Skettenis pst_syms_struct;
573b725ae77Skettenis
574b725ae77Skettenis static pst_syms_struct *pst_syms_array = 0;
575b725ae77Skettenis
576b725ae77Skettenis static int pst_syms_count = 0;
577b725ae77Skettenis static int pst_syms_size = 0;
578b725ae77Skettenis
579b725ae77Skettenis /* used by the TELL_OBJFILE macro */
580b725ae77Skettenis static int told_objfile = 0;
581b725ae77Skettenis
582b725ae77Skettenis /* Set up psymtab symbol index stuff */
583b725ae77Skettenis static void
init_pst_syms(void)584b725ae77Skettenis init_pst_syms (void)
585b725ae77Skettenis {
586b725ae77Skettenis pst_syms_count = 0;
587b725ae77Skettenis pst_syms_size = 20;
588b725ae77Skettenis pst_syms_array = (pst_syms_struct *) xmalloc (20 * sizeof (pst_syms_struct));
589b725ae77Skettenis }
590b725ae77Skettenis
591b725ae77Skettenis /* Clean up psymtab symbol index stuff */
592b725ae77Skettenis static void
clear_pst_syms(void)593b725ae77Skettenis clear_pst_syms (void)
594b725ae77Skettenis {
595b725ae77Skettenis pst_syms_count = 0;
596b725ae77Skettenis pst_syms_size = 0;
597b725ae77Skettenis xfree (pst_syms_array);
598b725ae77Skettenis pst_syms_array = 0;
599b725ae77Skettenis }
600b725ae77Skettenis
601b725ae77Skettenis /* Add information about latest psymtab to symbol index table */
602b725ae77Skettenis static void
record_pst_syms(int start_sym,int end_sym)603b725ae77Skettenis record_pst_syms (int start_sym, int end_sym)
604b725ae77Skettenis {
605b725ae77Skettenis if (++pst_syms_count > pst_syms_size)
606b725ae77Skettenis {
607b725ae77Skettenis pst_syms_array = (pst_syms_struct *) xrealloc (pst_syms_array,
608b725ae77Skettenis 2 * pst_syms_size * sizeof (pst_syms_struct));
609b725ae77Skettenis pst_syms_size *= 2;
610b725ae77Skettenis }
611b725ae77Skettenis pst_syms_array[pst_syms_count - 1].start = start_sym;
612b725ae77Skettenis pst_syms_array[pst_syms_count - 1].end = end_sym;
613b725ae77Skettenis }
614b725ae77Skettenis
615b725ae77Skettenis /* Find a suitable symbol table index which can serve as the upper
616b725ae77Skettenis bound of a psymtab that starts at INDEX
617b725ae77Skettenis
618b725ae77Skettenis This scans backwards in the psymtab symbol index table to find a
619b725ae77Skettenis "hole" in which the given index can fit. This is a heuristic!!
620b725ae77Skettenis We don't search the entire table to check for multiple holes,
621b725ae77Skettenis we don't care about overlaps, etc.
622b725ae77Skettenis
623b725ae77Skettenis Return 0 => not found */
624b725ae77Skettenis static int
find_next_pst_start(int index)625b725ae77Skettenis find_next_pst_start (int index)
626b725ae77Skettenis {
627b725ae77Skettenis int i;
628b725ae77Skettenis
629b725ae77Skettenis for (i = pst_syms_count - 1; i >= 0; i--)
630b725ae77Skettenis if (pst_syms_array[i].end <= index)
631b725ae77Skettenis return (i == pst_syms_count - 1) ? 0 : pst_syms_array[i + 1].start - 1;
632b725ae77Skettenis
633b725ae77Skettenis if (pst_syms_array[0].start > index)
634b725ae77Skettenis return pst_syms_array[0].start - 1;
635b725ae77Skettenis
636b725ae77Skettenis return 0;
637b725ae77Skettenis }
638b725ae77Skettenis
639b725ae77Skettenis
640b725ae77Skettenis
641b725ae77Skettenis /* Utility functions to find the ending symbol index for a psymtab */
642b725ae77Skettenis
643b725ae77Skettenis /* Find the next file entry that begins beyond INDEX, and return
644b725ae77Skettenis its starting symbol index - 1.
645b725ae77Skettenis QFD is the file table, CURR_FD is the file entry from where to start,
646b725ae77Skettenis PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
647b725ae77Skettenis
648b725ae77Skettenis Return 0 => not found */
649b725ae77Skettenis static int
find_next_file_isym(int index,quick_file_entry * qFD,int curr_fd,PXDB_header_ptr pxdb_header_p)650b725ae77Skettenis find_next_file_isym (int index, quick_file_entry *qFD, int curr_fd,
651b725ae77Skettenis PXDB_header_ptr pxdb_header_p)
652b725ae77Skettenis {
653b725ae77Skettenis while (VALID_CURR_FILE)
654b725ae77Skettenis {
655b725ae77Skettenis if (CURR_FILE_ISYM >= index)
656b725ae77Skettenis return CURR_FILE_ISYM - 1;
657b725ae77Skettenis curr_fd++;
658b725ae77Skettenis }
659b725ae77Skettenis return 0;
660b725ae77Skettenis }
661b725ae77Skettenis
662b725ae77Skettenis /* Find the next procedure entry that begins beyond INDEX, and return
663b725ae77Skettenis its starting symbol index - 1.
664b725ae77Skettenis QPD is the procedure table, CURR_PD is the proc entry from where to start,
665b725ae77Skettenis PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
666b725ae77Skettenis
667b725ae77Skettenis Return 0 => not found */
668b725ae77Skettenis static int
find_next_proc_isym(int index,quick_procedure_entry * qPD,int curr_pd,PXDB_header_ptr pxdb_header_p)669b725ae77Skettenis find_next_proc_isym (int index, quick_procedure_entry *qPD, int curr_pd,
670b725ae77Skettenis PXDB_header_ptr pxdb_header_p)
671b725ae77Skettenis {
672b725ae77Skettenis while (VALID_CURR_PROC)
673b725ae77Skettenis {
674b725ae77Skettenis if (CURR_PROC_ISYM >= index)
675b725ae77Skettenis return CURR_PROC_ISYM - 1;
676b725ae77Skettenis curr_pd++;
677b725ae77Skettenis }
678b725ae77Skettenis return 0;
679b725ae77Skettenis }
680b725ae77Skettenis
681b725ae77Skettenis /* Find the next module entry that begins beyond INDEX, and return
682b725ae77Skettenis its starting symbol index - 1.
683b725ae77Skettenis QMD is the module table, CURR_MD is the modue entry from where to start,
684b725ae77Skettenis PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
685b725ae77Skettenis
686b725ae77Skettenis Return 0 => not found */
687b725ae77Skettenis static int
find_next_module_isym(int index,quick_module_entry * qMD,int curr_md,PXDB_header_ptr pxdb_header_p)688b725ae77Skettenis find_next_module_isym (int index, quick_module_entry *qMD, int curr_md,
689b725ae77Skettenis PXDB_header_ptr pxdb_header_p)
690b725ae77Skettenis {
691b725ae77Skettenis while (VALID_CURR_MODULE)
692b725ae77Skettenis {
693b725ae77Skettenis if (CURR_MODULE_ISYM >= index)
694b725ae77Skettenis return CURR_MODULE_ISYM - 1;
695b725ae77Skettenis curr_md++;
696b725ae77Skettenis }
697b725ae77Skettenis return 0;
698b725ae77Skettenis }
699b725ae77Skettenis
700b725ae77Skettenis /* Scan and record partial symbols for all functions starting from index
701b725ae77Skettenis pointed to by CURR_PD_P, and between code addresses START_ADR and END_ADR.
702b725ae77Skettenis Other parameters are explained in comments below. */
703b725ae77Skettenis
704b725ae77Skettenis /* This used to be inline in hpread_quick_traverse, but now that we do
705b725ae77Skettenis essentially the same thing for two different cases (modules and
706b725ae77Skettenis module-less files), it's better organized in a separate routine,
707b725ae77Skettenis although it does take lots of arguments. pai/1997-10-08
708b725ae77Skettenis
709b725ae77Skettenis CURR_PD_P is the pointer to the current proc index. QPD is the
710b725ae77Skettenis procedure quick lookup table. MAX_PROCS is the number of entries
711b725ae77Skettenis in the proc. table. START_ADR is the beginning of the code range
712b725ae77Skettenis for the current psymtab. end_adr is the end of the code range for
713b725ae77Skettenis the current psymtab. PST is the current psymtab. VT_bits is
714b725ae77Skettenis a pointer to the strings table of SOM debug space. OBJFILE is
715b725ae77Skettenis the current object file. */
716b725ae77Skettenis
717b725ae77Skettenis static int
scan_procs(int * curr_pd_p,quick_procedure_entry * qPD,int max_procs,CORE_ADDR start_adr,CORE_ADDR end_adr,struct partial_symtab * pst,char * vt_bits,struct objfile * objfile)718b725ae77Skettenis scan_procs (int *curr_pd_p, quick_procedure_entry *qPD, int max_procs,
719b725ae77Skettenis CORE_ADDR start_adr, CORE_ADDR end_adr, struct partial_symtab *pst,
720b725ae77Skettenis char *vt_bits, struct objfile *objfile)
721b725ae77Skettenis {
722b725ae77Skettenis union dnttentry *dn_bufp;
723b725ae77Skettenis int symbol_count = 0; /* Total number of symbols in this psymtab */
724b725ae77Skettenis int curr_pd = *curr_pd_p; /* Convenience variable -- avoid dereferencing pointer all the time */
725b725ae77Skettenis
726b725ae77Skettenis #ifdef DUMPING
727b725ae77Skettenis /* Turn this on for lots of debugging information in this routine */
728b725ae77Skettenis static int dumping = 0;
729b725ae77Skettenis #endif
730b725ae77Skettenis
731b725ae77Skettenis #ifdef DUMPING
732b725ae77Skettenis if (dumping)
733b725ae77Skettenis {
734b725ae77Skettenis printf ("Scan_procs called, addresses %x to %x, proc %x\n", start_adr, end_adr, curr_pd);
735b725ae77Skettenis }
736b725ae77Skettenis #endif
737b725ae77Skettenis
738b725ae77Skettenis while ((CURR_PROC_START <= end_adr) && (curr_pd < max_procs))
739b725ae77Skettenis {
740b725ae77Skettenis
741b725ae77Skettenis char *rtn_name; /* mangled name */
742b725ae77Skettenis char *rtn_dem_name; /* qualified demangled name */
743b725ae77Skettenis char *class_name;
744b725ae77Skettenis int class;
745b725ae77Skettenis
746b725ae77Skettenis if ((trans_lang ((enum hp_language) qPD[curr_pd].language) == language_cplus) &&
747b725ae77Skettenis vt_bits[(long) qPD[curr_pd].sbAlias]) /* not a null string */
748b725ae77Skettenis {
749b725ae77Skettenis /* Get mangled name for the procedure, and demangle it */
750b725ae77Skettenis rtn_name = &vt_bits[(long) qPD[curr_pd].sbAlias];
751b725ae77Skettenis rtn_dem_name = cplus_demangle (rtn_name, DMGL_ANSI | DMGL_PARAMS);
752b725ae77Skettenis }
753b725ae77Skettenis else
754b725ae77Skettenis {
755b725ae77Skettenis rtn_name = &vt_bits[(long) qPD[curr_pd].sbProc];
756b725ae77Skettenis rtn_dem_name = NULL;
757b725ae77Skettenis }
758b725ae77Skettenis
759b725ae77Skettenis /* Hack to get around HP C/C++ compilers' insistence on providing
760b725ae77Skettenis "_MAIN_" as an alternate name for "main" */
761b725ae77Skettenis if ((strcmp (rtn_name, "_MAIN_") == 0) &&
762b725ae77Skettenis (strcmp (&vt_bits[(long) qPD[curr_pd].sbProc], "main") == 0))
763b725ae77Skettenis rtn_dem_name = rtn_name = main_string;
764b725ae77Skettenis
765b725ae77Skettenis #ifdef DUMPING
766b725ae77Skettenis if (dumping)
767b725ae77Skettenis {
768b725ae77Skettenis printf ("..add %s (demangled %s), index %x to this psymtab\n", rtn_name, rtn_dem_name, curr_pd);
769b725ae77Skettenis }
770b725ae77Skettenis #endif
771b725ae77Skettenis
772b725ae77Skettenis /* Check for module-spanning routines. */
773b725ae77Skettenis if (CURR_PROC_END > end_adr)
774b725ae77Skettenis {
775b725ae77Skettenis TELL_OBJFILE;
776b725ae77Skettenis warning ("Procedure \"%s\" [0x%x] spans file or module boundaries.", rtn_name, curr_pd);
777b725ae77Skettenis }
778b725ae77Skettenis
779b725ae77Skettenis /* Add this routine symbol to the list in the objfile.
780b725ae77Skettenis Unfortunately we have to go to the LNTT to determine the
781b725ae77Skettenis correct list to put it on. An alternative (which the
782b725ae77Skettenis code used to do) would be to not check and always throw
783b725ae77Skettenis it on the "static" list. But if we go that route, then
784b725ae77Skettenis symbol_lookup() needs to be tweaked a bit to account
785b725ae77Skettenis for the fact that the function might not be found on
786b725ae77Skettenis the correct list in the psymtab. - RT */
787b725ae77Skettenis dn_bufp = hpread_get_lntt (qPD[curr_pd].isym, objfile);
788b725ae77Skettenis if (dn_bufp->dfunc.global)
789b725ae77Skettenis add_psymbol_with_dem_name_to_list (rtn_name,
790b725ae77Skettenis strlen (rtn_name),
791b725ae77Skettenis rtn_dem_name,
792b725ae77Skettenis strlen (rtn_dem_name),
793b725ae77Skettenis VAR_DOMAIN,
794b725ae77Skettenis LOC_BLOCK, /* "I am a routine" */
795b725ae77Skettenis &objfile->global_psymbols,
796b725ae77Skettenis (qPD[curr_pd].adrStart + /* Starting address of rtn */
797b725ae77Skettenis ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))),
798b725ae77Skettenis 0, /* core addr?? */
799b725ae77Skettenis trans_lang ((enum hp_language) qPD[curr_pd].language),
800b725ae77Skettenis objfile);
801b725ae77Skettenis else
802b725ae77Skettenis add_psymbol_with_dem_name_to_list (rtn_name,
803b725ae77Skettenis strlen (rtn_name),
804b725ae77Skettenis rtn_dem_name,
805b725ae77Skettenis strlen (rtn_dem_name),
806b725ae77Skettenis VAR_DOMAIN,
807b725ae77Skettenis LOC_BLOCK, /* "I am a routine" */
808b725ae77Skettenis &objfile->static_psymbols,
809b725ae77Skettenis (qPD[curr_pd].adrStart + /* Starting address of rtn */
810b725ae77Skettenis ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))),
811b725ae77Skettenis 0, /* core addr?? */
812b725ae77Skettenis trans_lang ((enum hp_language) qPD[curr_pd].language),
813b725ae77Skettenis objfile);
814b725ae77Skettenis
815b725ae77Skettenis symbol_count++;
816b725ae77Skettenis *curr_pd_p = ++curr_pd; /* bump up count & reflect in caller */
817b725ae77Skettenis } /* loop over procedures */
818b725ae77Skettenis
819b725ae77Skettenis #ifdef DUMPING
820b725ae77Skettenis if (dumping)
821b725ae77Skettenis {
822b725ae77Skettenis if (symbol_count == 0)
823b725ae77Skettenis printf ("Scan_procs: no symbols found!\n");
824b725ae77Skettenis }
825b725ae77Skettenis #endif
826b725ae77Skettenis
827b725ae77Skettenis return symbol_count;
828b725ae77Skettenis }
829b725ae77Skettenis
830b725ae77Skettenis
831b725ae77Skettenis /* Traverse the quick look-up tables, building a set of psymtabs.
832b725ae77Skettenis
833b725ae77Skettenis This constructs a psymtab for modules and files in the quick lookup
834b725ae77Skettenis tables.
835b725ae77Skettenis
836b725ae77Skettenis Mostly, modules correspond to compilation units, so we try to
837b725ae77Skettenis create psymtabs that correspond to modules; however, in some cases
838b725ae77Skettenis a file can result in a compiled object which does not have a module
839b725ae77Skettenis entry for it, so in such cases we create a psymtab for the file. */
840b725ae77Skettenis
841b725ae77Skettenis static int
hpread_quick_traverse(struct objfile * objfile,char * gntt_bits,char * vt_bits,PXDB_header_ptr pxdb_header_p)842b725ae77Skettenis hpread_quick_traverse (struct objfile *objfile, char *gntt_bits,
843b725ae77Skettenis char *vt_bits, PXDB_header_ptr pxdb_header_p)
844b725ae77Skettenis {
845b725ae77Skettenis struct partial_symtab *pst;
846b725ae77Skettenis
847b725ae77Skettenis char *addr;
848b725ae77Skettenis
849b725ae77Skettenis quick_procedure_entry *qPD;
850b725ae77Skettenis quick_file_entry *qFD;
851b725ae77Skettenis quick_module_entry *qMD;
852b725ae77Skettenis quick_class_entry *qCD;
853b725ae77Skettenis
854b725ae77Skettenis int idx;
855b725ae77Skettenis int i;
856b725ae77Skettenis CORE_ADDR start_adr; /* current psymtab's starting code addr */
857b725ae77Skettenis CORE_ADDR end_adr; /* current psymtab's ending code addr */
858b725ae77Skettenis CORE_ADDR next_mod_adr; /* next module's starting code addr */
859b725ae77Skettenis int curr_pd; /* current procedure */
860b725ae77Skettenis int curr_fd; /* current file */
861b725ae77Skettenis int curr_md; /* current module */
862b725ae77Skettenis int start_sym; /* current psymtab's starting symbol index */
863b725ae77Skettenis int end_sym; /* current psymtab's ending symbol index */
864b725ae77Skettenis int max_LNTT_sym_index;
865b725ae77Skettenis int syms_in_pst;
866b725ae77Skettenis B_TYPE *class_entered;
867b725ae77Skettenis
868b725ae77Skettenis struct partial_symbol **global_syms; /* We'll be filling in the "global" */
869b725ae77Skettenis struct partial_symbol **static_syms; /* and "static" tables in the objfile
870b725ae77Skettenis as we go, so we need a pair of
871b725ae77Skettenis current pointers. */
872b725ae77Skettenis
873b725ae77Skettenis #ifdef DUMPING
874b725ae77Skettenis /* Turn this on for lots of debugging information in this routine.
875b725ae77Skettenis You get a blow-by-blow account of quick lookup table reading */
876b725ae77Skettenis static int dumping = 0;
877b725ae77Skettenis #endif
878b725ae77Skettenis
879b725ae77Skettenis pst = (struct partial_symtab *) 0;
880b725ae77Skettenis
881b725ae77Skettenis /* Clear out some globals */
882b725ae77Skettenis init_pst_syms ();
883b725ae77Skettenis told_objfile = 0;
884b725ae77Skettenis
885b725ae77Skettenis /* Demangling style -- if EDG style already set, don't change it,
886b725ae77Skettenis as HP style causes some problems with the KAI EDG compiler */
887b725ae77Skettenis if (current_demangling_style != edg_demangling)
888b725ae77Skettenis {
889b725ae77Skettenis /* Otherwise, ensure that we are using HP style demangling */
890b725ae77Skettenis set_demangling_style (HP_DEMANGLING_STYLE_STRING);
891b725ae77Skettenis }
892b725ae77Skettenis
893b725ae77Skettenis /* First we need to find the starting points of the quick
894b725ae77Skettenis look-up tables in the GNTT. */
895b725ae77Skettenis
896b725ae77Skettenis addr = gntt_bits;
897b725ae77Skettenis
898b725ae77Skettenis qPD = (quick_procedure_entry_ptr) addr;
899b725ae77Skettenis addr += pxdb_header_p->pd_entries * sizeof (quick_procedure_entry);
900b725ae77Skettenis
901b725ae77Skettenis #ifdef DUMPING
902b725ae77Skettenis if (dumping)
903b725ae77Skettenis {
904b725ae77Skettenis printf ("\n Printing routines as we see them\n");
905b725ae77Skettenis for (i = 0; VALID_PROC (i); i++)
906b725ae77Skettenis {
907b725ae77Skettenis idx = (long) qPD[i].sbProc;
908b725ae77Skettenis printf ("%s %x..%x\n", &vt_bits[idx],
909b725ae77Skettenis (int) PROC_START (i),
910b725ae77Skettenis (int) PROC_END (i));
911b725ae77Skettenis }
912b725ae77Skettenis }
913b725ae77Skettenis #endif
914b725ae77Skettenis
915b725ae77Skettenis qFD = (quick_file_entry_ptr) addr;
916b725ae77Skettenis addr += pxdb_header_p->fd_entries * sizeof (quick_file_entry);
917b725ae77Skettenis
918b725ae77Skettenis #ifdef DUMPING
919b725ae77Skettenis if (dumping)
920b725ae77Skettenis {
921b725ae77Skettenis printf ("\n Printing files as we see them\n");
922b725ae77Skettenis for (i = 0; VALID_FILE (i); i++)
923b725ae77Skettenis {
924b725ae77Skettenis idx = (long) qFD[i].sbFile;
925b725ae77Skettenis printf ("%s %x..%x\n", &vt_bits[idx],
926b725ae77Skettenis (int) FILE_START (i),
927b725ae77Skettenis (int) FILE_END (i));
928b725ae77Skettenis }
929b725ae77Skettenis }
930b725ae77Skettenis #endif
931b725ae77Skettenis
932b725ae77Skettenis qMD = (quick_module_entry_ptr) addr;
933b725ae77Skettenis addr += pxdb_header_p->md_entries * sizeof (quick_module_entry);
934b725ae77Skettenis
935b725ae77Skettenis #ifdef DUMPING
936b725ae77Skettenis if (dumping)
937b725ae77Skettenis {
938b725ae77Skettenis printf ("\n Printing modules as we see them\n");
939b725ae77Skettenis for (i = 0; i < pxdb_header_p->md_entries; i++)
940b725ae77Skettenis {
941b725ae77Skettenis idx = (long) qMD[i].sbMod;
942b725ae77Skettenis printf ("%s\n", &vt_bits[idx]);
943b725ae77Skettenis }
944b725ae77Skettenis }
945b725ae77Skettenis #endif
946b725ae77Skettenis
947b725ae77Skettenis qCD = (quick_class_entry_ptr) addr;
948b725ae77Skettenis addr += pxdb_header_p->cd_entries * sizeof (quick_class_entry);
949b725ae77Skettenis
950b725ae77Skettenis #ifdef DUMPING
951b725ae77Skettenis if (dumping)
952b725ae77Skettenis {
953b725ae77Skettenis printf ("\n Printing classes as we see them\n");
954b725ae77Skettenis for (i = 0; VALID_CLASS (i); i++)
955b725ae77Skettenis {
956b725ae77Skettenis idx = (long) qCD[i].sbClass;
957b725ae77Skettenis printf ("%s\n", &vt_bits[idx]);
958b725ae77Skettenis }
959b725ae77Skettenis
960b725ae77Skettenis printf ("\n Done with dump, on to build!\n");
961b725ae77Skettenis }
962b725ae77Skettenis #endif
963b725ae77Skettenis
964b725ae77Skettenis /* We need this index only while hp-symtab-read.c expects
965b725ae77Skettenis a byte offset to the end of the LNTT entries for a given
966b725ae77Skettenis psymtab. Thus the need for it should go away someday.
967b725ae77Skettenis
968b725ae77Skettenis When it goes away, then we won't have any need to load the
969b725ae77Skettenis LNTT from the objfile at psymtab-time, and start-up will be
970b725ae77Skettenis faster. To make that work, we'll need some way to create
971b725ae77Skettenis a null pst for the "globals" pseudo-module. */
972b725ae77Skettenis max_LNTT_sym_index = LNTT_SYMCOUNT (objfile);
973b725ae77Skettenis
974b725ae77Skettenis /* Scan the module descriptors and make a psymtab for each.
975b725ae77Skettenis
976b725ae77Skettenis We know the MDs, FDs and the PDs are in order by starting
977b725ae77Skettenis address. We use that fact to traverse all three arrays in
978b725ae77Skettenis parallel, knowing when the next PD is in a new file
979b725ae77Skettenis and we need to create a new psymtab. */
980b725ae77Skettenis curr_pd = 0; /* Current procedure entry */
981b725ae77Skettenis curr_fd = 0; /* Current file entry */
982b725ae77Skettenis curr_md = 0; /* Current module entry */
983b725ae77Skettenis
984b725ae77Skettenis start_adr = 0; /* Current psymtab code range */
985b725ae77Skettenis end_adr = 0;
986b725ae77Skettenis
987b725ae77Skettenis start_sym = 0; /* Current psymtab symbol range */
988b725ae77Skettenis end_sym = 0;
989b725ae77Skettenis
990b725ae77Skettenis syms_in_pst = 0; /* Symbol count for psymtab */
991b725ae77Skettenis
992b725ae77Skettenis /* Psts actually just have pointers into the objfile's
993b725ae77Skettenis symbol table, not their own symbol tables. */
994b725ae77Skettenis global_syms = objfile->global_psymbols.list;
995b725ae77Skettenis static_syms = objfile->static_psymbols.list;
996b725ae77Skettenis
997b725ae77Skettenis
998b725ae77Skettenis /* First skip over pseudo-entries with address 0. These represent inlined
999b725ae77Skettenis routines and abstract (uninstantiated) template routines.
1000b725ae77Skettenis FIXME: These should be read in and available -- even if we can't set
1001b725ae77Skettenis breakpoints, etc., there's some information that can be presented
1002b725ae77Skettenis to the user. pai/1997-10-08 */
1003b725ae77Skettenis
1004b725ae77Skettenis while (VALID_CURR_PROC && (CURR_PROC_START == 0))
1005b725ae77Skettenis curr_pd++;
1006b725ae77Skettenis
1007b725ae77Skettenis /* Loop over files, modules, and procedures in code address order. Each
1008b725ae77Skettenis time we enter an iteration of this loop, curr_pd points to the first
1009b725ae77Skettenis unprocessed procedure, curr_fd points to the first unprocessed file, and
1010b725ae77Skettenis curr_md to the first unprocessed module. Each iteration of this loop
1011b725ae77Skettenis updates these as required -- any or all of them may be bumpd up
1012b725ae77Skettenis each time around. When we exit this loop, we are done with all files
1013b725ae77Skettenis and modules in the tables -- there may still be some procedures, however.
1014b725ae77Skettenis
1015b725ae77Skettenis Note: This code used to loop only over module entries, under the assumption
1016b725ae77Skettenis that files can occur via inclusions and are thus unreliable, while a
1017b725ae77Skettenis compiled object always corresponds to a module. With CTTI in the HP aCC
1018b725ae77Skettenis compiler, it turns out that compiled objects may have only files and no
1019b725ae77Skettenis modules; so we have to loop over files and modules, creating psymtabs for
1020b725ae77Skettenis either as appropriate. Unfortunately there are some problems (notably:
1021b725ae77Skettenis 1. the lack of "SRC_FILE_END" entries in the LNTT, 2. the lack of pointers
1022b725ae77Skettenis to the ending symbol indices of a module or a file) which make it quite hard
1023b725ae77Skettenis to do this correctly. Currently it uses a bunch of heuristics to start and
1024b725ae77Skettenis end psymtabs; they seem to work well with most objects generated by aCC, but
1025b725ae77Skettenis who knows when that will change... */
1026b725ae77Skettenis
1027b725ae77Skettenis while (VALID_CURR_FILE || VALID_CURR_MODULE)
1028b725ae77Skettenis {
1029b725ae77Skettenis
1030b725ae77Skettenis char *mod_name_string = NULL;
1031b725ae77Skettenis char *full_name_string;
1032b725ae77Skettenis
1033b725ae77Skettenis /* First check for modules like "version.c", which have no code
1034b725ae77Skettenis in them but still have qMD entries. They also have no qFD or
1035b725ae77Skettenis qPD entries. Their start address is -1 and their end address
1036b725ae77Skettenis is 0. */
1037b725ae77Skettenis if (VALID_CURR_MODULE && (CURR_MODULE_START == -1) && (CURR_MODULE_END == 0))
1038b725ae77Skettenis {
1039b725ae77Skettenis
1040b725ae77Skettenis mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
1041b725ae77Skettenis
1042b725ae77Skettenis #ifdef DUMPING
1043b725ae77Skettenis if (dumping)
1044b725ae77Skettenis printf ("Module with data only %s\n", mod_name_string);
1045b725ae77Skettenis #endif
1046b725ae77Skettenis
1047b725ae77Skettenis /* We'll skip the rest (it makes error-checking easier), and
1048b725ae77Skettenis just make an empty pst. Right now empty psts are not put
1049b725ae77Skettenis in the pst chain, so all this is for naught, but later it
1050b725ae77Skettenis might help. */
1051b725ae77Skettenis
1052b725ae77Skettenis pst = hpread_start_psymtab (objfile,
1053b725ae77Skettenis mod_name_string,
1054b725ae77Skettenis CURR_MODULE_START, /* Low text address: bogus! */
1055b725ae77Skettenis (CURR_MODULE_ISYM * sizeof (struct dntt_type_block)),
1056b725ae77Skettenis /* ldsymoff */
1057b725ae77Skettenis global_syms,
1058b725ae77Skettenis static_syms);
1059b725ae77Skettenis
1060b725ae77Skettenis pst = hpread_end_psymtab (pst,
1061b725ae77Skettenis NULL, /* psymtab_include_list */
1062b725ae77Skettenis 0, /* includes_used */
1063b725ae77Skettenis end_sym * sizeof (struct dntt_type_block),
1064b725ae77Skettenis /* byte index in LNTT of end
1065b725ae77Skettenis = capping symbol offset
1066b725ae77Skettenis = LDSYMOFF of nextfile */
1067b725ae77Skettenis 0, /* text high */
1068b725ae77Skettenis NULL, /* dependency_list */
1069b725ae77Skettenis 0); /* dependencies_used */
1070b725ae77Skettenis
1071b725ae77Skettenis global_syms = objfile->global_psymbols.next;
1072b725ae77Skettenis static_syms = objfile->static_psymbols.next;
1073b725ae77Skettenis
1074b725ae77Skettenis curr_md++;
1075b725ae77Skettenis }
1076b725ae77Skettenis else if (VALID_CURR_MODULE &&
1077b725ae77Skettenis ((CURR_MODULE_START == 0) || (CURR_MODULE_START == -1) ||
1078b725ae77Skettenis (CURR_MODULE_END == 0) || (CURR_MODULE_END == -1)))
1079b725ae77Skettenis {
1080b725ae77Skettenis TELL_OBJFILE;
1081b725ae77Skettenis warning ("Module \"%s\" [0x%s] has non-standard addresses. It starts at 0x%s, ends at 0x%s, and will be skipped.",
1082b725ae77Skettenis mod_name_string, paddr_nz (curr_md), paddr_nz (start_adr), paddr_nz (end_adr));
1083b725ae77Skettenis /* On to next module */
1084b725ae77Skettenis curr_md++;
1085b725ae77Skettenis }
1086b725ae77Skettenis else
1087b725ae77Skettenis {
1088b725ae77Skettenis /* First check if we are looking at a file with code in it
1089b725ae77Skettenis that does not overlap the current module's code range */
1090b725ae77Skettenis
1091b725ae77Skettenis if (VALID_CURR_FILE ? (VALID_CURR_MODULE ? (CURR_FILE_END < CURR_MODULE_START) : 1) : 0)
1092b725ae77Skettenis {
1093b725ae77Skettenis
1094b725ae77Skettenis /* Looking at file not corresponding to any module,
1095b725ae77Skettenis create a psymtab for it */
1096b725ae77Skettenis full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
1097b725ae77Skettenis start_adr = CURR_FILE_START;
1098b725ae77Skettenis end_adr = CURR_FILE_END;
1099b725ae77Skettenis start_sym = CURR_FILE_ISYM;
1100b725ae77Skettenis
1101b725ae77Skettenis /* Check if there are any procedures not handled until now, that
1102b725ae77Skettenis begin before the start address of this file, and if so, adjust
1103b725ae77Skettenis this module's start address to include them. This handles routines that
1104b725ae77Skettenis are in between file or module ranges for some reason (probably
1105b725ae77Skettenis indicates a compiler bug */
1106b725ae77Skettenis
1107b725ae77Skettenis if (CURR_PROC_START < start_adr)
1108b725ae77Skettenis {
1109b725ae77Skettenis TELL_OBJFILE;
1110b725ae77Skettenis warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
1111b725ae77Skettenis &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
1112b725ae77Skettenis start_adr = CURR_PROC_START;
1113b725ae77Skettenis if (CURR_PROC_ISYM < start_sym)
1114b725ae77Skettenis start_sym = CURR_PROC_ISYM;
1115b725ae77Skettenis }
1116b725ae77Skettenis
1117b725ae77Skettenis /* Sometimes (compiler bug -- COBOL) the module end address is higher
1118b725ae77Skettenis than the start address of the next module, so check for that and
1119b725ae77Skettenis adjust accordingly */
1120b725ae77Skettenis
1121b725ae77Skettenis if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
1122b725ae77Skettenis {
1123b725ae77Skettenis TELL_OBJFILE;
1124b725ae77Skettenis warning ("File \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
1125b725ae77Skettenis full_name_string, curr_fd);
1126b725ae77Skettenis end_adr = FILE_START (curr_fd + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */
1127b725ae77Skettenis }
1128b725ae77Skettenis if (VALID_MODULE (curr_md) && (CURR_MODULE_START <= end_adr))
1129b725ae77Skettenis {
1130b725ae77Skettenis TELL_OBJFILE;
1131b725ae77Skettenis warning ("File \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
1132b725ae77Skettenis full_name_string, curr_fd);
1133b725ae77Skettenis end_adr = CURR_MODULE_START - 1; /* Is -4 (or -8 for 64-bit) better? */
1134b725ae77Skettenis }
1135b725ae77Skettenis
1136b725ae77Skettenis
1137b725ae77Skettenis #ifdef DUMPING
1138b725ae77Skettenis if (dumping)
1139b725ae77Skettenis {
1140b725ae77Skettenis printf ("Make new psymtab for file %s (%x to %x).\n",
1141b725ae77Skettenis full_name_string, start_adr, end_adr);
1142b725ae77Skettenis }
1143b725ae77Skettenis #endif
1144b725ae77Skettenis /* Create the basic psymtab, connecting it in the list
1145b725ae77Skettenis for this objfile and pointing its symbol entries
1146b725ae77Skettenis to the current end of the symbol areas in the objfile.
1147b725ae77Skettenis
1148b725ae77Skettenis The "ldsymoff" parameter is the byte offset in the LNTT
1149b725ae77Skettenis of the first symbol in this file. Some day we should
1150b725ae77Skettenis turn this into an index (fix in hp-symtab-read.c as well).
1151b725ae77Skettenis And it's not even the right byte offset, as we're using
1152b725ae77Skettenis the size of a union! FIXME! */
1153b725ae77Skettenis pst = hpread_start_psymtab (objfile,
1154b725ae77Skettenis full_name_string,
1155b725ae77Skettenis start_adr, /* Low text address */
1156b725ae77Skettenis (start_sym * sizeof (struct dntt_type_block)),
1157b725ae77Skettenis /* ldsymoff */
1158b725ae77Skettenis global_syms,
1159b725ae77Skettenis static_syms);
1160b725ae77Skettenis
1161b725ae77Skettenis /* Set up to only enter each class referenced in this module once. */
1162b725ae77Skettenis class_entered = xmalloc (B_BYTES (pxdb_header_p->cd_entries));
1163b725ae77Skettenis B_CLRALL (class_entered, pxdb_header_p->cd_entries);
1164b725ae77Skettenis
1165b725ae77Skettenis /* Scan the procedure descriptors for procedures in the current
1166b725ae77Skettenis file, based on the starting addresses. */
1167b725ae77Skettenis
1168b725ae77Skettenis syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1169b725ae77Skettenis start_adr, end_adr, pst, vt_bits, objfile);
1170b725ae77Skettenis
1171b725ae77Skettenis /* Get ending symbol offset */
1172b725ae77Skettenis
1173b725ae77Skettenis end_sym = 0;
1174b725ae77Skettenis /* First check for starting index before previous psymtab */
1175b725ae77Skettenis if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
1176b725ae77Skettenis {
1177b725ae77Skettenis end_sym = find_next_pst_start (start_sym);
1178b725ae77Skettenis }
1179b725ae77Skettenis /* Look for next start index of a file or module, or procedure */
1180b725ae77Skettenis if (!end_sym)
1181b725ae77Skettenis {
1182b725ae77Skettenis int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
1183b725ae77Skettenis int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md, pxdb_header_p);
1184b725ae77Skettenis int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
1185b725ae77Skettenis
1186b725ae77Skettenis if (next_file_isym && next_module_isym)
1187b725ae77Skettenis {
1188b725ae77Skettenis /* pick lower of next file or module start index */
1189b725ae77Skettenis end_sym = min (next_file_isym, next_module_isym);
1190b725ae77Skettenis }
1191b725ae77Skettenis else
1192b725ae77Skettenis {
1193b725ae77Skettenis /* one of them is zero, pick the other */
1194b725ae77Skettenis end_sym = max (next_file_isym, next_module_isym);
1195b725ae77Skettenis }
1196b725ae77Skettenis
1197b725ae77Skettenis /* As a precaution, check next procedure index too */
1198b725ae77Skettenis if (!end_sym)
1199b725ae77Skettenis end_sym = next_proc_isym;
1200b725ae77Skettenis else
1201b725ae77Skettenis end_sym = min (end_sym, next_proc_isym);
1202b725ae77Skettenis }
1203b725ae77Skettenis
1204b725ae77Skettenis /* Couldn't find procedure, file, or module, use globals as default */
1205b725ae77Skettenis if (!end_sym)
1206b725ae77Skettenis end_sym = pxdb_header_p->globals;
1207b725ae77Skettenis
1208b725ae77Skettenis #ifdef DUMPING
1209b725ae77Skettenis if (dumping)
1210b725ae77Skettenis {
1211b725ae77Skettenis printf ("File psymtab indices: %x to %x\n", start_sym, end_sym);
1212b725ae77Skettenis }
1213b725ae77Skettenis #endif
1214b725ae77Skettenis
1215b725ae77Skettenis pst = hpread_end_psymtab (pst,
1216b725ae77Skettenis NULL, /* psymtab_include_list */
1217b725ae77Skettenis 0, /* includes_used */
1218b725ae77Skettenis end_sym * sizeof (struct dntt_type_block),
1219b725ae77Skettenis /* byte index in LNTT of end
1220b725ae77Skettenis = capping symbol offset
1221b725ae77Skettenis = LDSYMOFF of nextfile */
1222b725ae77Skettenis end_adr, /* text high */
1223b725ae77Skettenis NULL, /* dependency_list */
1224b725ae77Skettenis 0); /* dependencies_used */
1225b725ae77Skettenis
1226b725ae77Skettenis record_pst_syms (start_sym, end_sym);
1227b725ae77Skettenis
1228b725ae77Skettenis if (NULL == pst)
1229b725ae77Skettenis warning ("No symbols in psymtab for file \"%s\" [0x%x].", full_name_string, curr_fd);
1230b725ae77Skettenis
1231b725ae77Skettenis #ifdef DUMPING
1232b725ae77Skettenis if (dumping)
1233b725ae77Skettenis {
1234b725ae77Skettenis printf ("Made new psymtab for file %s (%x to %x), sym %x to %x.\n",
1235b725ae77Skettenis full_name_string, start_adr, end_adr, CURR_FILE_ISYM, end_sym);
1236b725ae77Skettenis }
1237b725ae77Skettenis #endif
1238b725ae77Skettenis /* Prepare for the next psymtab. */
1239b725ae77Skettenis global_syms = objfile->global_psymbols.next;
1240b725ae77Skettenis static_syms = objfile->static_psymbols.next;
1241b725ae77Skettenis xfree (class_entered);
1242b725ae77Skettenis
1243b725ae77Skettenis curr_fd++;
1244b725ae77Skettenis } /* Psymtab for file */
1245b725ae77Skettenis else
1246b725ae77Skettenis {
1247b725ae77Skettenis /* We have a module for which we create a psymtab */
1248b725ae77Skettenis
1249b725ae77Skettenis mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
1250b725ae77Skettenis
1251b725ae77Skettenis /* We will include the code ranges of any files that happen to
1252b725ae77Skettenis overlap with this module */
1253b725ae77Skettenis
1254b725ae77Skettenis /* So, first pick the lower of the file's and module's start addresses */
1255b725ae77Skettenis start_adr = CURR_MODULE_START;
1256b725ae77Skettenis if (VALID_CURR_FILE)
1257b725ae77Skettenis {
1258b725ae77Skettenis if (CURR_FILE_START < CURR_MODULE_START)
1259b725ae77Skettenis {
1260b725ae77Skettenis TELL_OBJFILE;
1261b725ae77Skettenis warning ("File \"%s\" [0x%x] crosses beginning of module \"%s\".",
1262b725ae77Skettenis &vt_bits[(long) qFD[curr_fd].sbFile],
1263b725ae77Skettenis curr_fd, mod_name_string);
1264b725ae77Skettenis
1265b725ae77Skettenis start_adr = CURR_FILE_START;
1266b725ae77Skettenis }
1267b725ae77Skettenis }
1268b725ae77Skettenis
1269b725ae77Skettenis /* Also pick the lower of the file's and the module's start symbol indices */
1270b725ae77Skettenis start_sym = CURR_MODULE_ISYM;
1271b725ae77Skettenis if (VALID_CURR_FILE && (CURR_FILE_ISYM < CURR_MODULE_ISYM))
1272b725ae77Skettenis start_sym = CURR_FILE_ISYM;
1273b725ae77Skettenis
1274b725ae77Skettenis /* For the end address, we scan through the files till we find one
1275b725ae77Skettenis that overlaps the current module but ends beyond it; if no such file exists we
1276b725ae77Skettenis simply use the module's start address.
1277b725ae77Skettenis (Note, if file entries themselves overlap
1278b725ae77Skettenis we take the longest overlapping extension beyond the end of the module...)
1279b725ae77Skettenis We assume that modules never overlap. */
1280b725ae77Skettenis
1281b725ae77Skettenis end_adr = CURR_MODULE_END;
1282b725ae77Skettenis
1283b725ae77Skettenis if (VALID_CURR_FILE)
1284b725ae77Skettenis {
1285b725ae77Skettenis while (VALID_CURR_FILE && (CURR_FILE_START < end_adr))
1286b725ae77Skettenis {
1287b725ae77Skettenis
1288b725ae77Skettenis #ifdef DUMPING
1289b725ae77Skettenis if (dumping)
1290b725ae77Skettenis printf ("Maybe skipping file %s which overlaps with module %s\n",
1291b725ae77Skettenis &vt_bits[(long) qFD[curr_fd].sbFile], mod_name_string);
1292b725ae77Skettenis #endif
1293b725ae77Skettenis if (CURR_FILE_END > end_adr)
1294b725ae77Skettenis {
1295b725ae77Skettenis TELL_OBJFILE;
1296b725ae77Skettenis warning ("File \"%s\" [0x%x] crosses end of module \"%s\".",
1297b725ae77Skettenis &vt_bits[(long) qFD[curr_fd].sbFile],
1298b725ae77Skettenis curr_fd, mod_name_string);
1299b725ae77Skettenis end_adr = CURR_FILE_END;
1300b725ae77Skettenis }
1301b725ae77Skettenis curr_fd++;
1302b725ae77Skettenis }
1303b725ae77Skettenis curr_fd--; /* back up after going too far */
1304b725ae77Skettenis }
1305b725ae77Skettenis
1306b725ae77Skettenis /* Sometimes (compiler bug -- COBOL) the module end address is higher
1307b725ae77Skettenis than the start address of the next module, so check for that and
1308b725ae77Skettenis adjust accordingly */
1309b725ae77Skettenis
1310b725ae77Skettenis if (VALID_MODULE (curr_md + 1) && (MODULE_START (curr_md + 1) <= end_adr))
1311b725ae77Skettenis {
1312b725ae77Skettenis TELL_OBJFILE;
1313b725ae77Skettenis warning ("Module \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
1314b725ae77Skettenis mod_name_string, curr_md);
1315b725ae77Skettenis end_adr = MODULE_START (curr_md + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */
1316b725ae77Skettenis }
1317b725ae77Skettenis if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
1318b725ae77Skettenis {
1319b725ae77Skettenis TELL_OBJFILE;
1320b725ae77Skettenis warning ("Module \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
1321b725ae77Skettenis mod_name_string, curr_md);
1322b725ae77Skettenis end_adr = FILE_START (curr_fd + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */
1323b725ae77Skettenis }
1324b725ae77Skettenis
1325b725ae77Skettenis /* Use one file to get the full name for the module. This
1326b725ae77Skettenis situation can arise if there is executable code in a #include
1327b725ae77Skettenis file. Each file with code in it gets a qFD. Files which don't
1328b725ae77Skettenis contribute code don't get a qFD, even if they include files
1329b725ae77Skettenis which do, e.g.:
1330b725ae77Skettenis
1331b725ae77Skettenis body.c: rtn.h:
1332b725ae77Skettenis int x; int main() {
1333b725ae77Skettenis #include "rtn.h" return x;
1334b725ae77Skettenis }
1335b725ae77Skettenis
1336b725ae77Skettenis There will a qFD for "rtn.h",and a qMD for "body.c",
1337b725ae77Skettenis but no qMD for "rtn.h" or qFD for "body.c"!
1338b725ae77Skettenis
1339b725ae77Skettenis We pick the name of the last file to overlap with this
1340b725ae77Skettenis module. C convention is to put include files first. In a
1341b725ae77Skettenis perfect world, we could check names and use the file whose full
1342b725ae77Skettenis path name ends with the module name. */
1343b725ae77Skettenis
1344b725ae77Skettenis if (VALID_CURR_FILE)
1345b725ae77Skettenis full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
1346b725ae77Skettenis else
1347b725ae77Skettenis full_name_string = mod_name_string;
1348b725ae77Skettenis
1349b725ae77Skettenis /* Check if there are any procedures not handled until now, that
1350b725ae77Skettenis begin before the start address we have now, and if so, adjust
1351b725ae77Skettenis this psymtab's start address to include them. This handles routines that
1352b725ae77Skettenis are in between file or module ranges for some reason (probably
1353b725ae77Skettenis indicates a compiler bug */
1354b725ae77Skettenis
1355b725ae77Skettenis if (CURR_PROC_START < start_adr)
1356b725ae77Skettenis {
1357b725ae77Skettenis TELL_OBJFILE;
1358b725ae77Skettenis warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
1359b725ae77Skettenis &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
1360b725ae77Skettenis start_adr = CURR_PROC_START;
1361b725ae77Skettenis if (CURR_PROC_ISYM < start_sym)
1362b725ae77Skettenis start_sym = CURR_PROC_ISYM;
1363b725ae77Skettenis }
1364b725ae77Skettenis
1365b725ae77Skettenis #ifdef DUMPING
1366b725ae77Skettenis if (dumping)
1367b725ae77Skettenis {
1368b725ae77Skettenis printf ("Make new psymtab for module %s (%x to %x), using file %s\n",
1369b725ae77Skettenis mod_name_string, start_adr, end_adr, full_name_string);
1370b725ae77Skettenis }
1371b725ae77Skettenis #endif
1372b725ae77Skettenis /* Create the basic psymtab, connecting it in the list
1373b725ae77Skettenis for this objfile and pointing its symbol entries
1374b725ae77Skettenis to the current end of the symbol areas in the objfile.
1375b725ae77Skettenis
1376b725ae77Skettenis The "ldsymoff" parameter is the byte offset in the LNTT
1377b725ae77Skettenis of the first symbol in this file. Some day we should
1378b725ae77Skettenis turn this into an index (fix in hp-symtab-read.c as well).
1379b725ae77Skettenis And it's not even the right byte offset, as we're using
1380b725ae77Skettenis the size of a union! FIXME! */
1381b725ae77Skettenis pst = hpread_start_psymtab (objfile,
1382b725ae77Skettenis full_name_string,
1383b725ae77Skettenis start_adr, /* Low text address */
1384b725ae77Skettenis (start_sym * sizeof (struct dntt_type_block)),
1385b725ae77Skettenis /* ldsymoff */
1386b725ae77Skettenis global_syms,
1387b725ae77Skettenis static_syms);
1388b725ae77Skettenis
1389b725ae77Skettenis /* Set up to only enter each class referenced in this module once. */
1390b725ae77Skettenis class_entered = xmalloc (B_BYTES (pxdb_header_p->cd_entries));
1391b725ae77Skettenis B_CLRALL (class_entered, pxdb_header_p->cd_entries);
1392b725ae77Skettenis
1393b725ae77Skettenis /* Scan the procedure descriptors for procedures in the current
1394b725ae77Skettenis module, based on the starting addresses. */
1395b725ae77Skettenis
1396b725ae77Skettenis syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1397b725ae77Skettenis start_adr, end_adr, pst, vt_bits, objfile);
1398b725ae77Skettenis
1399b725ae77Skettenis /* Get ending symbol offset */
1400b725ae77Skettenis
1401b725ae77Skettenis end_sym = 0;
1402b725ae77Skettenis /* First check for starting index before previous psymtab */
1403b725ae77Skettenis if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
1404b725ae77Skettenis {
1405b725ae77Skettenis end_sym = find_next_pst_start (start_sym);
1406b725ae77Skettenis }
1407b725ae77Skettenis /* Look for next start index of a file or module, or procedure */
1408b725ae77Skettenis if (!end_sym)
1409b725ae77Skettenis {
1410b725ae77Skettenis int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
1411b725ae77Skettenis int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md + 1, pxdb_header_p);
1412b725ae77Skettenis int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
1413b725ae77Skettenis
1414b725ae77Skettenis if (next_file_isym && next_module_isym)
1415b725ae77Skettenis {
1416b725ae77Skettenis /* pick lower of next file or module start index */
1417b725ae77Skettenis end_sym = min (next_file_isym, next_module_isym);
1418b725ae77Skettenis }
1419b725ae77Skettenis else
1420b725ae77Skettenis {
1421b725ae77Skettenis /* one of them is zero, pick the other */
1422b725ae77Skettenis end_sym = max (next_file_isym, next_module_isym);
1423b725ae77Skettenis }
1424b725ae77Skettenis
1425b725ae77Skettenis /* As a precaution, check next procedure index too */
1426b725ae77Skettenis if (!end_sym)
1427b725ae77Skettenis end_sym = next_proc_isym;
1428b725ae77Skettenis else
1429b725ae77Skettenis end_sym = min (end_sym, next_proc_isym);
1430b725ae77Skettenis }
1431b725ae77Skettenis
1432b725ae77Skettenis /* Couldn't find procedure, file, or module, use globals as default */
1433b725ae77Skettenis if (!end_sym)
1434b725ae77Skettenis end_sym = pxdb_header_p->globals;
1435b725ae77Skettenis
1436b725ae77Skettenis #ifdef DUMPING
1437b725ae77Skettenis if (dumping)
1438b725ae77Skettenis {
1439b725ae77Skettenis printf ("Module psymtab indices: %x to %x\n", start_sym, end_sym);
1440b725ae77Skettenis }
1441b725ae77Skettenis #endif
1442b725ae77Skettenis
1443b725ae77Skettenis pst = hpread_end_psymtab (pst,
1444b725ae77Skettenis NULL, /* psymtab_include_list */
1445b725ae77Skettenis 0, /* includes_used */
1446b725ae77Skettenis end_sym * sizeof (struct dntt_type_block),
1447b725ae77Skettenis /* byte index in LNTT of end
1448b725ae77Skettenis = capping symbol offset
1449b725ae77Skettenis = LDSYMOFF of nextfile */
1450b725ae77Skettenis end_adr, /* text high */
1451b725ae77Skettenis NULL, /* dependency_list */
1452b725ae77Skettenis 0); /* dependencies_used */
1453b725ae77Skettenis
1454b725ae77Skettenis record_pst_syms (start_sym, end_sym);
1455b725ae77Skettenis
1456b725ae77Skettenis if (NULL == pst)
1457b725ae77Skettenis warning ("No symbols in psymtab for module \"%s\" [0x%x].", mod_name_string, curr_md);
1458b725ae77Skettenis
1459b725ae77Skettenis #ifdef DUMPING
1460b725ae77Skettenis if (dumping)
1461b725ae77Skettenis {
1462b725ae77Skettenis printf ("Made new psymtab for module %s (%x to %x), sym %x to %x.\n",
1463b725ae77Skettenis mod_name_string, start_adr, end_adr, CURR_MODULE_ISYM, end_sym);
1464b725ae77Skettenis }
1465b725ae77Skettenis #endif
1466b725ae77Skettenis
1467b725ae77Skettenis /* Prepare for the next psymtab. */
1468b725ae77Skettenis global_syms = objfile->global_psymbols.next;
1469b725ae77Skettenis static_syms = objfile->static_psymbols.next;
1470b725ae77Skettenis xfree (class_entered);
1471b725ae77Skettenis
1472b725ae77Skettenis curr_md++;
1473b725ae77Skettenis curr_fd++;
1474b725ae77Skettenis } /* psymtab for module */
1475b725ae77Skettenis } /* psymtab for non-bogus file or module */
1476b725ae77Skettenis } /* End of while loop over all files & modules */
1477b725ae77Skettenis
1478b725ae77Skettenis /* There may be some routines after all files and modules -- these will get
1479b725ae77Skettenis inserted in a separate new module of their own */
1480b725ae77Skettenis if (VALID_CURR_PROC)
1481b725ae77Skettenis {
1482b725ae77Skettenis start_adr = CURR_PROC_START;
1483b725ae77Skettenis end_adr = qPD[pxdb_header_p->pd_entries - 1].adrEnd;
1484b725ae77Skettenis TELL_OBJFILE;
1485b725ae77Skettenis warning ("Found functions beyond end of all files and modules [0x%x].", curr_pd);
1486b725ae77Skettenis #ifdef DUMPING
1487b725ae77Skettenis if (dumping)
1488b725ae77Skettenis {
1489b725ae77Skettenis printf ("Orphan functions at end, PD %d and beyond (%x to %x)\n",
1490b725ae77Skettenis curr_pd, start_adr, end_adr);
1491b725ae77Skettenis }
1492b725ae77Skettenis #endif
1493b725ae77Skettenis pst = hpread_start_psymtab (objfile,
1494b725ae77Skettenis "orphans",
1495b725ae77Skettenis start_adr, /* Low text address */
1496b725ae77Skettenis (CURR_PROC_ISYM * sizeof (struct dntt_type_block)),
1497b725ae77Skettenis /* ldsymoff */
1498b725ae77Skettenis global_syms,
1499b725ae77Skettenis static_syms);
1500b725ae77Skettenis
1501b725ae77Skettenis scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1502b725ae77Skettenis start_adr, end_adr, pst, vt_bits, objfile);
1503b725ae77Skettenis
1504b725ae77Skettenis pst = hpread_end_psymtab (pst,
1505b725ae77Skettenis NULL, /* psymtab_include_list */
1506b725ae77Skettenis 0, /* includes_used */
1507b725ae77Skettenis pxdb_header_p->globals * sizeof (struct dntt_type_block),
1508b725ae77Skettenis /* byte index in LNTT of end
1509b725ae77Skettenis = capping symbol offset
1510b725ae77Skettenis = LDSYMOFF of nextfile */
1511b725ae77Skettenis end_adr, /* text high */
1512b725ae77Skettenis NULL, /* dependency_list */
1513b725ae77Skettenis 0); /* dependencies_used */
1514b725ae77Skettenis }
1515b725ae77Skettenis
1516b725ae77Skettenis
1517b725ae77Skettenis #ifdef NEVER_NEVER
1518b725ae77Skettenis /* Now build psts for non-module things (in the tail of
1519b725ae77Skettenis the LNTT, after the last END MODULE entry).
1520b725ae77Skettenis
1521b725ae77Skettenis If null psts were kept on the chain, this would be
1522b725ae77Skettenis a solution. FIXME */
1523b725ae77Skettenis pst = hpread_start_psymtab (objfile,
1524b725ae77Skettenis "globals",
1525b725ae77Skettenis 0,
1526b725ae77Skettenis (pxdb_header_p->globals
1527b725ae77Skettenis * sizeof (struct dntt_type_block)),
1528b725ae77Skettenis objfile->global_psymbols.next,
1529b725ae77Skettenis objfile->static_psymbols.next);
1530b725ae77Skettenis hpread_end_psymtab (pst,
1531b725ae77Skettenis NULL, 0,
1532b725ae77Skettenis (max_LNTT_sym_index * sizeof (struct dntt_type_block)),
1533b725ae77Skettenis 0,
1534b725ae77Skettenis NULL, 0);
1535b725ae77Skettenis #endif
1536b725ae77Skettenis
1537b725ae77Skettenis clear_pst_syms ();
1538b725ae77Skettenis
1539b725ae77Skettenis return 1;
1540b725ae77Skettenis
1541b725ae77Skettenis } /* End of hpread_quick_traverse. */
1542b725ae77Skettenis
1543b725ae77Skettenis
1544b725ae77Skettenis /* Get appropriate header, based on pxdb type.
1545b725ae77Skettenis Return value: 1 if ok, 0 if not */
1546b725ae77Skettenis static int
hpread_get_header(struct objfile * objfile,PXDB_header_ptr pxdb_header_p)1547b725ae77Skettenis hpread_get_header (struct objfile *objfile, PXDB_header_ptr pxdb_header_p)
1548b725ae77Skettenis {
1549b725ae77Skettenis asection *pinfo_section, *debug_section, *header_section;
1550b725ae77Skettenis
1551b725ae77Skettenis #ifdef DUMPING
1552b725ae77Skettenis /* Turn on for debugging information */
1553b725ae77Skettenis static int dumping = 0;
1554b725ae77Skettenis #endif
1555b725ae77Skettenis
1556b725ae77Skettenis header_section = bfd_get_section_by_name (objfile->obfd, "$HEADER$");
1557b725ae77Skettenis if (!header_section)
1558b725ae77Skettenis {
1559b725ae77Skettenis /* We don't have either PINFO or DEBUG sections. But
1560b725ae77Skettenis stuff like "libc.sl" has no debug info. There's no
1561b725ae77Skettenis need to warn the user of this, as it may be ok. The
1562b725ae77Skettenis caller will figure it out and issue any needed
1563b725ae77Skettenis messages. */
1564b725ae77Skettenis #ifdef DUMPING
1565b725ae77Skettenis if (dumping)
1566b725ae77Skettenis printf ("==No debug info at all for %s.\n", objfile->name);
1567b725ae77Skettenis #endif
1568b725ae77Skettenis
1569b725ae77Skettenis return 0;
1570b725ae77Skettenis }
1571b725ae77Skettenis
1572b725ae77Skettenis /* We would like either a $DEBUG$ or $PINFO$ section.
1573b725ae77Skettenis Once we know which, we can understand the header
1574b725ae77Skettenis data (which we have defined to suit the more common
1575b725ae77Skettenis $DEBUG$ case). */
1576b725ae77Skettenis debug_section = bfd_get_section_by_name (objfile->obfd, "$DEBUG$");
1577b725ae77Skettenis pinfo_section = bfd_get_section_by_name (objfile->obfd, "$PINFO$");
1578b725ae77Skettenis if (debug_section)
1579b725ae77Skettenis {
1580b725ae77Skettenis /* The expected case: normal pxdb header. */
1581b725ae77Skettenis bfd_get_section_contents (objfile->obfd, header_section,
1582b725ae77Skettenis pxdb_header_p, 0, sizeof (PXDB_header));
1583b725ae77Skettenis
1584b725ae77Skettenis if (!pxdb_header_p->pxdbed)
1585b725ae77Skettenis {
1586b725ae77Skettenis /* This shouldn't happen if we check in "symfile.c". */
1587b725ae77Skettenis return 0;
1588b725ae77Skettenis } /* DEBUG section */
1589b725ae77Skettenis }
1590b725ae77Skettenis
1591b725ae77Skettenis else if (pinfo_section)
1592b725ae77Skettenis {
1593b725ae77Skettenis /* The DOC case; we need to translate this into a
1594b725ae77Skettenis regular header. */
1595b725ae77Skettenis DOC_info_PXDB_header doc_header;
1596b725ae77Skettenis
1597b725ae77Skettenis #ifdef DUMPING
1598b725ae77Skettenis if (dumping)
1599b725ae77Skettenis {
1600b725ae77Skettenis printf ("==OOps, PINFO, let's try to handle this, %s.\n", objfile->name);
1601b725ae77Skettenis }
1602b725ae77Skettenis #endif
1603b725ae77Skettenis
1604b725ae77Skettenis bfd_get_section_contents (objfile->obfd,
1605b725ae77Skettenis header_section,
1606b725ae77Skettenis &doc_header, 0,
1607b725ae77Skettenis sizeof (DOC_info_PXDB_header));
1608b725ae77Skettenis
1609b725ae77Skettenis if (!doc_header.pxdbed)
1610b725ae77Skettenis {
1611b725ae77Skettenis /* This shouldn't happen if we check in "symfile.c". */
1612b725ae77Skettenis warning ("File \"%s\" not processed by pxdb!", objfile->name);
1613b725ae77Skettenis return 0;
1614b725ae77Skettenis }
1615b725ae77Skettenis
1616b725ae77Skettenis /* Copy relevent fields to standard header passed in. */
1617b725ae77Skettenis pxdb_header_p->pd_entries = doc_header.pd_entries;
1618b725ae77Skettenis pxdb_header_p->fd_entries = doc_header.fd_entries;
1619b725ae77Skettenis pxdb_header_p->md_entries = doc_header.md_entries;
1620b725ae77Skettenis pxdb_header_p->pxdbed = doc_header.pxdbed;
1621b725ae77Skettenis pxdb_header_p->bighdr = doc_header.bighdr;
1622b725ae77Skettenis pxdb_header_p->sa_header = doc_header.sa_header;
1623b725ae77Skettenis pxdb_header_p->inlined = doc_header.inlined;
1624b725ae77Skettenis pxdb_header_p->globals = doc_header.globals;
1625b725ae77Skettenis pxdb_header_p->time = doc_header.time;
1626b725ae77Skettenis pxdb_header_p->pg_entries = doc_header.pg_entries;
1627b725ae77Skettenis pxdb_header_p->functions = doc_header.functions;
1628b725ae77Skettenis pxdb_header_p->files = doc_header.files;
1629b725ae77Skettenis pxdb_header_p->cd_entries = doc_header.cd_entries;
1630b725ae77Skettenis pxdb_header_p->aa_entries = doc_header.aa_entries;
1631b725ae77Skettenis pxdb_header_p->oi_entries = doc_header.oi_entries;
1632b725ae77Skettenis pxdb_header_p->version = doc_header.version;
1633b725ae77Skettenis } /* PINFO section */
1634b725ae77Skettenis
1635b725ae77Skettenis else
1636b725ae77Skettenis {
1637b725ae77Skettenis #ifdef DUMPING
1638b725ae77Skettenis if (dumping)
1639b725ae77Skettenis printf ("==No debug info at all for %s.\n", objfile->name);
1640b725ae77Skettenis #endif
1641b725ae77Skettenis
1642b725ae77Skettenis return 0;
1643b725ae77Skettenis
1644b725ae77Skettenis }
1645b725ae77Skettenis
1646b725ae77Skettenis return 1;
1647b725ae77Skettenis } /* End of hpread_get_header */
1648b725ae77Skettenis #endif /* QUICK_LOOK_UP */
1649b725ae77Skettenis
1650b725ae77Skettenis
1651e93f7393Sniklas /* Initialization for reading native HP C debug symbols from OBJFILE.
1652e93f7393Sniklas
1653b725ae77Skettenis Its only purpose in life is to set up the symbol reader's private
1654e93f7393Sniklas per-objfile data structures, and read in the raw contents of the debug
1655e93f7393Sniklas sections (attaching pointers to the debug info into the private data
1656e93f7393Sniklas structures).
1657e93f7393Sniklas
1658e93f7393Sniklas Since BFD doesn't know how to read debug symbols in a format-independent
1659e93f7393Sniklas way (and may never do so...), we have to do it ourselves. Note we may
1660e93f7393Sniklas be called on a file without native HP C debugging symbols.
1661e93f7393Sniklas
1662b725ae77Skettenis FIXME, there should be a cleaner peephole into the BFD environment
1663b725ae77Skettenis here. */
1664e93f7393Sniklas void
hpread_symfile_init(struct objfile * objfile)1665b725ae77Skettenis hpread_symfile_init (struct objfile *objfile)
1666e93f7393Sniklas {
1667e93f7393Sniklas asection *vt_section, *slt_section, *lntt_section, *gntt_section;
1668e93f7393Sniklas
1669e93f7393Sniklas /* Allocate struct to keep track of the symfile */
1670b725ae77Skettenis objfile->sym_private =
1671*63addd46Skettenis xmalloc (sizeof (struct hpread_symfile_info));
1672e93f7393Sniklas memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
1673e93f7393Sniklas
1674e93f7393Sniklas /* We haven't read in any types yet. */
1675b725ae77Skettenis DNTT_TYPE_VECTOR (objfile) = 0;
1676e93f7393Sniklas
1677e93f7393Sniklas /* Read in data from the $GNTT$ subspace. */
1678e93f7393Sniklas gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
1679e93f7393Sniklas if (!gntt_section)
1680e93f7393Sniklas return;
1681e93f7393Sniklas
1682e93f7393Sniklas GNTT (objfile)
1683b725ae77Skettenis = obstack_alloc (&objfile->objfile_obstack,
1684e93f7393Sniklas bfd_section_size (objfile->obfd, gntt_section));
1685e93f7393Sniklas
1686e93f7393Sniklas bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
1687e93f7393Sniklas 0, bfd_section_size (objfile->obfd, gntt_section));
1688e93f7393Sniklas
1689e93f7393Sniklas GNTT_SYMCOUNT (objfile)
1690e93f7393Sniklas = bfd_section_size (objfile->obfd, gntt_section)
1691e93f7393Sniklas / sizeof (struct dntt_type_block);
1692e93f7393Sniklas
1693e93f7393Sniklas /* Read in data from the $LNTT$ subspace. Also keep track of the number
1694b725ae77Skettenis of LNTT symbols.
1695b725ae77Skettenis
1696b725ae77Skettenis FIXME: this could be moved into the psymtab-to-symtab expansion
1697b725ae77Skettenis code, and save startup time. At the moment this data is
1698b725ae77Skettenis still used, though. We'd need a way to tell hp-symtab-read.c
1699b725ae77Skettenis whether or not to load the LNTT. */
1700e93f7393Sniklas lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
1701e93f7393Sniklas if (!lntt_section)
1702e93f7393Sniklas return;
1703e93f7393Sniklas
1704e93f7393Sniklas LNTT (objfile)
1705b725ae77Skettenis = obstack_alloc (&objfile->objfile_obstack,
1706e93f7393Sniklas bfd_section_size (objfile->obfd, lntt_section));
1707e93f7393Sniklas
1708e93f7393Sniklas bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
1709e93f7393Sniklas 0, bfd_section_size (objfile->obfd, lntt_section));
1710e93f7393Sniklas
1711e93f7393Sniklas LNTT_SYMCOUNT (objfile)
1712e93f7393Sniklas = bfd_section_size (objfile->obfd, lntt_section)
1713e93f7393Sniklas / sizeof (struct dntt_type_block);
1714e93f7393Sniklas
1715e93f7393Sniklas /* Read in data from the $SLT$ subspace. $SLT$ contains information
1716e93f7393Sniklas on source line numbers. */
1717e93f7393Sniklas slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
1718e93f7393Sniklas if (!slt_section)
1719e93f7393Sniklas return;
1720e93f7393Sniklas
1721e93f7393Sniklas SLT (objfile) =
1722b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack,
1723e93f7393Sniklas bfd_section_size (objfile->obfd, slt_section));
1724e93f7393Sniklas
1725e93f7393Sniklas bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
1726e93f7393Sniklas 0, bfd_section_size (objfile->obfd, slt_section));
1727e93f7393Sniklas
1728e93f7393Sniklas /* Read in data from the $VT$ subspace. $VT$ contains things like
1729e93f7393Sniklas names and constants. Keep track of the number of symbols in the VT. */
1730e93f7393Sniklas vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
1731e93f7393Sniklas if (!vt_section)
1732e93f7393Sniklas return;
1733e93f7393Sniklas
1734e93f7393Sniklas VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
1735e93f7393Sniklas
1736e93f7393Sniklas VT (objfile) =
1737b725ae77Skettenis (char *) obstack_alloc (&objfile->objfile_obstack,
1738e93f7393Sniklas VT_SIZE (objfile));
1739e93f7393Sniklas
1740e93f7393Sniklas bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
1741e93f7393Sniklas 0, VT_SIZE (objfile));
1742e93f7393Sniklas }
1743e93f7393Sniklas
1744e93f7393Sniklas /* Scan and build partial symbols for a symbol file.
1745e93f7393Sniklas
1746e93f7393Sniklas The minimal symbol table (either SOM or HP a.out) has already been
1747e93f7393Sniklas read in; all we need to do is setup partial symbols based on the
1748e93f7393Sniklas native debugging information.
1749e93f7393Sniklas
1750b725ae77Skettenis Note that the minimal table is produced by the linker, and has
1751b725ae77Skettenis only global routines in it; the psymtab is based on compiler-
1752b725ae77Skettenis generated debug information and has non-global
1753b725ae77Skettenis routines in it as well as files and class information.
1754b725ae77Skettenis
1755e93f7393Sniklas We assume hpread_symfile_init has been called to initialize the
1756e93f7393Sniklas symbol reader's private data structures.
1757e93f7393Sniklas
1758b725ae77Skettenis MAINLINE is true if we are reading the main symbol table (as
1759b725ae77Skettenis opposed to a shared lib or dynamically loaded file). */
1760e93f7393Sniklas
1761e93f7393Sniklas void
hpread_build_psymtabs(struct objfile * objfile,int mainline)1762b725ae77Skettenis hpread_build_psymtabs (struct objfile *objfile, int mainline)
1763e93f7393Sniklas {
1764b725ae77Skettenis
1765b725ae77Skettenis #ifdef DUMPING
1766b725ae77Skettenis /* Turn this on to get debugging output. */
1767b725ae77Skettenis static int dumping = 0;
1768b725ae77Skettenis #endif
1769b725ae77Skettenis
1770e93f7393Sniklas char *namestring;
1771e93f7393Sniklas int past_first_source_file = 0;
1772e93f7393Sniklas struct cleanup *old_chain;
1773e93f7393Sniklas
1774e93f7393Sniklas int hp_symnum, symcount, i;
1775b725ae77Skettenis int scan_start = 0;
1776e93f7393Sniklas
1777e93f7393Sniklas union dnttentry *dn_bufp;
1778e93f7393Sniklas unsigned long valu;
1779e93f7393Sniklas char *p;
1780e93f7393Sniklas int texthigh = 0;
1781e93f7393Sniklas int have_name = 0;
1782e93f7393Sniklas
1783e93f7393Sniklas /* Current partial symtab */
1784e93f7393Sniklas struct partial_symtab *pst;
1785e93f7393Sniklas
1786e93f7393Sniklas /* List of current psymtab's include files */
1787e93f7393Sniklas char **psymtab_include_list;
1788e93f7393Sniklas int includes_allocated;
1789e93f7393Sniklas int includes_used;
1790e93f7393Sniklas
1791e93f7393Sniklas /* Index within current psymtab dependency list */
1792e93f7393Sniklas struct partial_symtab **dependency_list;
1793e93f7393Sniklas int dependencies_used, dependencies_allocated;
1794e93f7393Sniklas
1795e93f7393Sniklas /* Just in case the stabs reader left turds lying around. */
1796e93f7393Sniklas free_pending_blocks ();
1797e93f7393Sniklas make_cleanup (really_free_pendings, 0);
1798e93f7393Sniklas
1799e93f7393Sniklas pst = (struct partial_symtab *) 0;
1800e93f7393Sniklas
1801e93f7393Sniklas /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
1802e93f7393Sniklas a number of problems with cross compilation and creating useless holes
1803e93f7393Sniklas in the stack when we have to allocate new entries. FIXME. */
1804e93f7393Sniklas
1805e93f7393Sniklas includes_allocated = 30;
1806e93f7393Sniklas includes_used = 0;
1807e93f7393Sniklas psymtab_include_list = (char **) alloca (includes_allocated *
1808e93f7393Sniklas sizeof (char *));
1809e93f7393Sniklas
1810e93f7393Sniklas dependencies_allocated = 30;
1811e93f7393Sniklas dependencies_used = 0;
1812e93f7393Sniklas dependency_list =
1813e93f7393Sniklas (struct partial_symtab **) alloca (dependencies_allocated *
1814e93f7393Sniklas sizeof (struct partial_symtab *));
1815e93f7393Sniklas
1816b725ae77Skettenis old_chain = make_cleanup_free_objfile (objfile);
1817e93f7393Sniklas
1818e93f7393Sniklas last_source_file = 0;
1819e93f7393Sniklas
1820b725ae77Skettenis #ifdef QUICK_LOOK_UP
1821b725ae77Skettenis {
1822b725ae77Skettenis /* Begin code for new-style loading of quick look-up tables. */
1823b725ae77Skettenis
1824b725ae77Skettenis /* elz: this checks whether the file has beeen processed by pxdb.
1825b725ae77Skettenis If not we would like to try to read the psymbols in
1826b725ae77Skettenis anyway, but it turns out to be not so easy. So this could
1827b725ae77Skettenis actually be commented out, but I leave it in, just in case
1828b725ae77Skettenis we decide to add support for non-pxdb-ed stuff in the future. */
1829b725ae77Skettenis PXDB_header pxdb_header;
1830b725ae77Skettenis int found_modules_in_program;
1831b725ae77Skettenis
1832b725ae77Skettenis if (hpread_get_header (objfile, &pxdb_header))
1833b725ae77Skettenis {
1834b725ae77Skettenis /* Build a minimal table. No types, no global variables,
1835b725ae77Skettenis no include files.... */
1836b725ae77Skettenis #ifdef DUMPING
1837b725ae77Skettenis if (dumping)
1838b725ae77Skettenis printf ("\nNew method for %s\n", objfile->name);
1839b725ae77Skettenis #endif
1840b725ae77Skettenis
1841b725ae77Skettenis /* elz: quick_traverse returns true if it found
1842b725ae77Skettenis some modules in the main source file, other
1843b725ae77Skettenis than those in end.c
1844b725ae77Skettenis In C and C++, all the files have MODULES entries
1845b725ae77Skettenis in the LNTT, and the quick table traverse is all
1846b725ae77Skettenis based on finding these MODULES entries. Without
1847b725ae77Skettenis those it cannot work.
1848b725ae77Skettenis It happens that F77 programs don't have MODULES
1849b725ae77Skettenis so the quick traverse gets confused. F90 programs
1850b725ae77Skettenis have modules, and the quick method still works.
1851b725ae77Skettenis So, if modules (other than those in end.c) are
1852b725ae77Skettenis not found we give up on the quick table stuff,
1853b725ae77Skettenis and fall back on the slower method */
1854b725ae77Skettenis found_modules_in_program = hpread_quick_traverse (objfile,
1855b725ae77Skettenis GNTT (objfile),
1856b725ae77Skettenis VT (objfile),
1857b725ae77Skettenis &pxdb_header);
1858b725ae77Skettenis
1859b725ae77Skettenis discard_cleanups (old_chain);
1860b725ae77Skettenis
1861b725ae77Skettenis /* Set up to scan the global section of the LNTT.
1862b725ae77Skettenis
1863b725ae77Skettenis This field is not always correct: if there are
1864b725ae77Skettenis no globals, it will point to the last record in
1865b725ae77Skettenis the regular LNTT, which is usually an END MODULE.
1866b725ae77Skettenis
1867b725ae77Skettenis Since it might happen that there could be a file
1868b725ae77Skettenis with just one global record, there's no way to
1869b725ae77Skettenis tell other than by looking at the record, so that's
1870b725ae77Skettenis done below. */
1871b725ae77Skettenis if (found_modules_in_program)
1872b725ae77Skettenis scan_start = pxdb_header.globals;
1873b725ae77Skettenis }
1874b725ae77Skettenis #ifdef DUMPING
1875b725ae77Skettenis else
1876b725ae77Skettenis {
1877b725ae77Skettenis if (dumping)
1878b725ae77Skettenis printf ("\nGoing on to old method for %s\n", objfile->name);
1879b725ae77Skettenis }
1880b725ae77Skettenis #endif
1881b725ae77Skettenis }
1882b725ae77Skettenis #endif /* QUICK_LOOK_UP */
1883b725ae77Skettenis
1884b725ae77Skettenis /* Make two passes, one over the GNTT symbols, the other for the
1885b725ae77Skettenis LNTT symbols.
1886b725ae77Skettenis
1887b725ae77Skettenis JB comment: above isn't true--they only make one pass, over
1888b725ae77Skettenis the LNTT. */
1889e93f7393Sniklas for (i = 0; i < 1; i++)
1890e93f7393Sniklas {
1891e93f7393Sniklas int within_function = 0;
1892e93f7393Sniklas
1893e93f7393Sniklas if (i)
1894e93f7393Sniklas symcount = GNTT_SYMCOUNT (objfile);
1895e93f7393Sniklas else
1896e93f7393Sniklas symcount = LNTT_SYMCOUNT (objfile);
1897e93f7393Sniklas
1898b725ae77Skettenis
1899b725ae77Skettenis for (hp_symnum = scan_start; hp_symnum < symcount; hp_symnum++)
1900e93f7393Sniklas {
1901e93f7393Sniklas QUIT;
1902e93f7393Sniklas if (i)
1903e93f7393Sniklas dn_bufp = hpread_get_gntt (hp_symnum, objfile);
1904e93f7393Sniklas else
1905e93f7393Sniklas dn_bufp = hpread_get_lntt (hp_symnum, objfile);
1906e93f7393Sniklas
1907e93f7393Sniklas if (dn_bufp->dblock.extension)
1908e93f7393Sniklas continue;
1909e93f7393Sniklas
1910e93f7393Sniklas /* Only handle things which are necessary for minimal symbols.
1911e93f7393Sniklas everything else is ignored. */
1912e93f7393Sniklas switch (dn_bufp->dblock.kind)
1913e93f7393Sniklas {
1914e93f7393Sniklas case DNTT_TYPE_SRCFILE:
1915e93f7393Sniklas {
1916b725ae77Skettenis #ifdef QUICK_LOOK_UP
1917b725ae77Skettenis if (scan_start == hp_symnum
1918b725ae77Skettenis && symcount == hp_symnum + 1)
1919b725ae77Skettenis {
1920b725ae77Skettenis /* If there are NO globals in an executable,
1921b725ae77Skettenis PXDB's index to the globals will point to
1922b725ae77Skettenis the last record in the file, which
1923b725ae77Skettenis could be this record. (this happened for F77 libraries)
1924b725ae77Skettenis ignore it and be done! */
1925b725ae77Skettenis continue;
1926b725ae77Skettenis }
1927b725ae77Skettenis #endif /* QUICK_LOOK_UP */
1928b725ae77Skettenis
1929e93f7393Sniklas /* A source file of some kind. Note this may simply
1930e93f7393Sniklas be an included file. */
1931b725ae77Skettenis set_namestring (dn_bufp, &namestring, objfile);
1932e93f7393Sniklas
1933e93f7393Sniklas /* Check if this is the source file we are already working
1934e93f7393Sniklas with. */
1935e93f7393Sniklas if (pst && !strcmp (namestring, pst->filename))
1936e93f7393Sniklas continue;
1937e93f7393Sniklas
1938e93f7393Sniklas /* Check if this is an include file, if so check if we have
1939e93f7393Sniklas already seen it. Add it to the include list */
1940e93f7393Sniklas p = strrchr (namestring, '.');
1941e93f7393Sniklas if (!strcmp (p, ".h"))
1942e93f7393Sniklas {
1943e93f7393Sniklas int j, found;
1944e93f7393Sniklas
1945e93f7393Sniklas found = 0;
1946e93f7393Sniklas for (j = 0; j < includes_used; j++)
1947e93f7393Sniklas if (!strcmp (namestring, psymtab_include_list[j]))
1948e93f7393Sniklas {
1949e93f7393Sniklas found = 1;
1950e93f7393Sniklas break;
1951e93f7393Sniklas }
1952e93f7393Sniklas if (found)
1953e93f7393Sniklas continue;
1954e93f7393Sniklas
1955e93f7393Sniklas /* Add it to the list of includes seen so far and
1956e93f7393Sniklas allocate more include space if necessary. */
1957e93f7393Sniklas psymtab_include_list[includes_used++] = namestring;
1958e93f7393Sniklas if (includes_used >= includes_allocated)
1959e93f7393Sniklas {
1960e93f7393Sniklas char **orig = psymtab_include_list;
1961e93f7393Sniklas
1962e93f7393Sniklas psymtab_include_list = (char **)
1963e93f7393Sniklas alloca ((includes_allocated *= 2) *
1964e93f7393Sniklas sizeof (char *));
1965b725ae77Skettenis memcpy (psymtab_include_list, orig,
1966e93f7393Sniklas includes_used * sizeof (char *));
1967e93f7393Sniklas }
1968e93f7393Sniklas continue;
1969e93f7393Sniklas }
1970e93f7393Sniklas
1971e93f7393Sniklas if (pst)
1972e93f7393Sniklas {
1973e93f7393Sniklas if (!have_name)
1974e93f7393Sniklas {
1975e93f7393Sniklas pst->filename = (char *)
1976b725ae77Skettenis obstack_alloc (&pst->objfile->objfile_obstack,
1977e93f7393Sniklas strlen (namestring) + 1);
1978e93f7393Sniklas strcpy (pst->filename, namestring);
1979e93f7393Sniklas have_name = 1;
1980e93f7393Sniklas continue;
1981e93f7393Sniklas }
1982e93f7393Sniklas continue;
1983e93f7393Sniklas }
1984e93f7393Sniklas
1985e93f7393Sniklas /* This is a bonafide new source file.
1986e93f7393Sniklas End the current partial symtab and start a new one. */
1987e93f7393Sniklas
1988e93f7393Sniklas if (pst && past_first_source_file)
1989e93f7393Sniklas {
1990e93f7393Sniklas hpread_end_psymtab (pst, psymtab_include_list,
1991e93f7393Sniklas includes_used,
1992e93f7393Sniklas (hp_symnum
1993e93f7393Sniklas * sizeof (struct dntt_type_block)),
1994e93f7393Sniklas texthigh,
1995e93f7393Sniklas dependency_list, dependencies_used);
1996e93f7393Sniklas pst = (struct partial_symtab *) 0;
1997e93f7393Sniklas includes_used = 0;
1998e93f7393Sniklas dependencies_used = 0;
1999e93f7393Sniklas }
2000e93f7393Sniklas else
2001e93f7393Sniklas past_first_source_file = 1;
2002e93f7393Sniklas
2003b725ae77Skettenis valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
2004b725ae77Skettenis valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2005b725ae77Skettenis pst = hpread_start_psymtab (objfile,
2006e93f7393Sniklas namestring, valu,
2007e93f7393Sniklas (hp_symnum
2008e93f7393Sniklas * sizeof (struct dntt_type_block)),
2009e93f7393Sniklas objfile->global_psymbols.next,
2010e93f7393Sniklas objfile->static_psymbols.next);
2011e93f7393Sniklas texthigh = valu;
2012e93f7393Sniklas have_name = 1;
2013e93f7393Sniklas continue;
2014e93f7393Sniklas }
2015e93f7393Sniklas
2016e93f7393Sniklas case DNTT_TYPE_MODULE:
2017e93f7393Sniklas /* A source file. It's still unclear to me what the
2018e93f7393Sniklas real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
2019e93f7393Sniklas is supposed to be. */
2020b725ae77Skettenis
2021b725ae77Skettenis /* First end the previous psymtab */
2022b725ae77Skettenis if (pst)
2023b725ae77Skettenis {
2024b725ae77Skettenis hpread_end_psymtab (pst, psymtab_include_list, includes_used,
2025b725ae77Skettenis ((hp_symnum - 1)
2026b725ae77Skettenis * sizeof (struct dntt_type_block)),
2027b725ae77Skettenis texthigh,
2028b725ae77Skettenis dependency_list, dependencies_used);
2029b725ae77Skettenis pst = (struct partial_symtab *) 0;
2030b725ae77Skettenis includes_used = 0;
2031b725ae77Skettenis dependencies_used = 0;
2032b725ae77Skettenis have_name = 0;
2033b725ae77Skettenis }
2034b725ae77Skettenis
2035b725ae77Skettenis /* Now begin a new module and a new psymtab for it */
2036b725ae77Skettenis set_namestring (dn_bufp, &namestring, objfile);
2037b725ae77Skettenis valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
2038b725ae77Skettenis valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2039e93f7393Sniklas if (!pst)
2040e93f7393Sniklas {
2041b725ae77Skettenis pst = hpread_start_psymtab (objfile,
2042e93f7393Sniklas namestring, valu,
2043e93f7393Sniklas (hp_symnum
2044e93f7393Sniklas * sizeof (struct dntt_type_block)),
2045e93f7393Sniklas objfile->global_psymbols.next,
2046e93f7393Sniklas objfile->static_psymbols.next);
2047e93f7393Sniklas texthigh = valu;
2048e93f7393Sniklas have_name = 0;
2049e93f7393Sniklas }
2050e93f7393Sniklas continue;
2051b725ae77Skettenis
2052e93f7393Sniklas case DNTT_TYPE_FUNCTION:
2053e93f7393Sniklas case DNTT_TYPE_ENTRY:
2054e93f7393Sniklas /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
2055e93f7393Sniklas a secondary entry point. */
2056b725ae77Skettenis valu = dn_bufp->dfunc.hiaddr + ANOFFSET (objfile->section_offsets,
2057b725ae77Skettenis SECT_OFF_TEXT (objfile));
2058e93f7393Sniklas if (valu > texthigh)
2059e93f7393Sniklas texthigh = valu;
2060e93f7393Sniklas valu = dn_bufp->dfunc.lowaddr +
2061b725ae77Skettenis ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2062b725ae77Skettenis set_namestring (dn_bufp, &namestring, objfile);
2063b725ae77Skettenis if (dn_bufp->dfunc.global)
2064e93f7393Sniklas add_psymbol_to_list (namestring, strlen (namestring),
2065b725ae77Skettenis VAR_DOMAIN, LOC_BLOCK,
2066b725ae77Skettenis &objfile->global_psymbols, valu,
2067b725ae77Skettenis 0, language_unknown, objfile);
2068b725ae77Skettenis else
2069b725ae77Skettenis add_psymbol_to_list (namestring, strlen (namestring),
2070b725ae77Skettenis VAR_DOMAIN, LOC_BLOCK,
2071e93f7393Sniklas &objfile->static_psymbols, valu,
2072e93f7393Sniklas 0, language_unknown, objfile);
2073e93f7393Sniklas within_function = 1;
2074e93f7393Sniklas continue;
2075b725ae77Skettenis
2076b725ae77Skettenis case DNTT_TYPE_DOC_FUNCTION:
2077b725ae77Skettenis valu = dn_bufp->ddocfunc.hiaddr + ANOFFSET (objfile->section_offsets,
2078b725ae77Skettenis SECT_OFF_TEXT (objfile));
2079b725ae77Skettenis if (valu > texthigh)
2080b725ae77Skettenis texthigh = valu;
2081b725ae77Skettenis valu = dn_bufp->ddocfunc.lowaddr +
2082b725ae77Skettenis ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2083b725ae77Skettenis set_namestring (dn_bufp, &namestring, objfile);
2084b725ae77Skettenis if (dn_bufp->ddocfunc.global)
2085b725ae77Skettenis add_psymbol_to_list (namestring, strlen (namestring),
2086b725ae77Skettenis VAR_DOMAIN, LOC_BLOCK,
2087b725ae77Skettenis &objfile->global_psymbols, valu,
2088b725ae77Skettenis 0, language_unknown, objfile);
2089b725ae77Skettenis else
2090b725ae77Skettenis add_psymbol_to_list (namestring, strlen (namestring),
2091b725ae77Skettenis VAR_DOMAIN, LOC_BLOCK,
2092b725ae77Skettenis &objfile->static_psymbols, valu,
2093b725ae77Skettenis 0, language_unknown, objfile);
2094b725ae77Skettenis within_function = 1;
2095b725ae77Skettenis continue;
2096b725ae77Skettenis
2097e93f7393Sniklas case DNTT_TYPE_BEGIN:
2098e93f7393Sniklas case DNTT_TYPE_END:
2099b725ae77Skettenis /* We don't check MODULE end here, because there can be
2100b725ae77Skettenis symbols beyond the module end which properly belong to the
2101b725ae77Skettenis current psymtab -- so we wait till the next MODULE start */
2102b725ae77Skettenis
2103b725ae77Skettenis
2104b725ae77Skettenis #ifdef QUICK_LOOK_UP
2105b725ae77Skettenis if (scan_start == hp_symnum
2106b725ae77Skettenis && symcount == hp_symnum + 1)
2107b725ae77Skettenis {
2108b725ae77Skettenis /* If there are NO globals in an executable,
2109b725ae77Skettenis PXDB's index to the globals will point to
2110b725ae77Skettenis the last record in the file, which is
2111b725ae77Skettenis probably an END MODULE, i.e. this record.
2112b725ae77Skettenis ignore it and be done! */
2113b725ae77Skettenis continue;
2114b725ae77Skettenis }
2115b725ae77Skettenis #endif /* QUICK_LOOK_UP */
2116b725ae77Skettenis
2117e93f7393Sniklas /* Scope block begin/end. We only care about function
2118e93f7393Sniklas and file blocks right now. */
2119b725ae77Skettenis
2120b725ae77Skettenis if ((dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION) ||
2121b725ae77Skettenis (dn_bufp->dend.endkind == DNTT_TYPE_DOC_FUNCTION))
2122e93f7393Sniklas within_function = 0;
2123e93f7393Sniklas continue;
2124b725ae77Skettenis
2125e93f7393Sniklas case DNTT_TYPE_SVAR:
2126e93f7393Sniklas case DNTT_TYPE_DVAR:
2127e93f7393Sniklas case DNTT_TYPE_TYPEDEF:
2128e93f7393Sniklas case DNTT_TYPE_TAGDEF:
2129e93f7393Sniklas {
2130e93f7393Sniklas /* Variables, typedefs an the like. */
2131e93f7393Sniklas enum address_class storage;
2132b725ae77Skettenis domain_enum domain;
2133e93f7393Sniklas
2134e93f7393Sniklas /* Don't add locals to the partial symbol table. */
2135e93f7393Sniklas if (within_function
2136e93f7393Sniklas && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
2137e93f7393Sniklas || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
2138e93f7393Sniklas continue;
2139e93f7393Sniklas
2140b725ae77Skettenis /* TAGDEFs go into the structure domain. */
2141e93f7393Sniklas if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
2142b725ae77Skettenis domain = STRUCT_DOMAIN;
2143e93f7393Sniklas else
2144b725ae77Skettenis domain = VAR_DOMAIN;
2145e93f7393Sniklas
2146e93f7393Sniklas /* What kind of "storage" does this use? */
2147e93f7393Sniklas if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
2148e93f7393Sniklas storage = LOC_STATIC;
2149e93f7393Sniklas else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
2150e93f7393Sniklas && dn_bufp->ddvar.regvar)
2151e93f7393Sniklas storage = LOC_REGISTER;
2152e93f7393Sniklas else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
2153e93f7393Sniklas storage = LOC_LOCAL;
2154e93f7393Sniklas else
2155e93f7393Sniklas storage = LOC_UNDEF;
2156e93f7393Sniklas
2157b725ae77Skettenis set_namestring (dn_bufp, &namestring, objfile);
2158e93f7393Sniklas if (!pst)
2159e93f7393Sniklas {
2160b725ae77Skettenis pst = hpread_start_psymtab (objfile,
2161e93f7393Sniklas "globals", 0,
2162e93f7393Sniklas (hp_symnum
2163e93f7393Sniklas * sizeof (struct dntt_type_block)),
2164e93f7393Sniklas objfile->global_psymbols.next,
2165e93f7393Sniklas objfile->static_psymbols.next);
2166e93f7393Sniklas }
2167b725ae77Skettenis
2168b725ae77Skettenis /* Compute address of the data symbol */
2169b725ae77Skettenis valu = dn_bufp->dsvar.location;
2170b725ae77Skettenis /* Relocate in case it's in a shared library */
2171b725ae77Skettenis if (storage == LOC_STATIC)
2172b725ae77Skettenis valu += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2173b725ae77Skettenis
2174b725ae77Skettenis /* Luckily, dvar, svar, typedef, and tagdef all
2175b725ae77Skettenis have their "global" bit in the same place, so it works
2176b725ae77Skettenis (though it's bad programming practice) to reference
2177b725ae77Skettenis "dsvar.global" even though we may be looking at
2178b725ae77Skettenis any of the above four types. */
2179e93f7393Sniklas if (dn_bufp->dsvar.global)
2180e93f7393Sniklas {
2181e93f7393Sniklas add_psymbol_to_list (namestring, strlen (namestring),
2182b725ae77Skettenis domain, storage,
2183b725ae77Skettenis &objfile->global_psymbols,
2184b725ae77Skettenis valu,
2185b725ae77Skettenis 0, language_unknown, objfile);
2186b725ae77Skettenis }
2187b725ae77Skettenis else
2188b725ae77Skettenis {
2189b725ae77Skettenis add_psymbol_to_list (namestring, strlen (namestring),
2190b725ae77Skettenis domain, storage,
2191b725ae77Skettenis &objfile->static_psymbols,
2192b725ae77Skettenis valu,
2193b725ae77Skettenis 0, language_unknown, objfile);
2194b725ae77Skettenis }
2195b725ae77Skettenis
2196b725ae77Skettenis /* For TAGDEF's, the above code added the tagname to the
2197b725ae77Skettenis struct domain. This will cause tag "t" to be found
2198b725ae77Skettenis on a reference of the form "(struct t) x". But for
2199b725ae77Skettenis C++ classes, "t" will also be a typename, which we
2200b725ae77Skettenis want to find on a reference of the form "ptype t".
2201b725ae77Skettenis Therefore, we also add "t" to the var domain.
2202b725ae77Skettenis Do the same for enum's due to the way aCC generates
2203b725ae77Skettenis debug info for these (see more extended comment
2204b725ae77Skettenis in hp-symtab-read.c).
2205b725ae77Skettenis We do the same for templates, so that "ptype t"
2206b725ae77Skettenis where "t" is a template also works. */
2207b725ae77Skettenis if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF &&
2208b725ae77Skettenis dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
2209b725ae77Skettenis {
2210b725ae77Skettenis int global = dn_bufp->dtag.global;
2211b725ae77Skettenis /* Look ahead to see if it's a C++ class */
2212b725ae77Skettenis dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
2213b725ae77Skettenis if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS ||
2214b725ae77Skettenis dn_bufp->dblock.kind == DNTT_TYPE_ENUM ||
2215b725ae77Skettenis dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
2216b725ae77Skettenis {
2217b725ae77Skettenis if (global)
2218b725ae77Skettenis {
2219b725ae77Skettenis add_psymbol_to_list (namestring, strlen (namestring),
2220b725ae77Skettenis VAR_DOMAIN, storage,
2221e93f7393Sniklas &objfile->global_psymbols,
2222e93f7393Sniklas dn_bufp->dsvar.location,
2223e93f7393Sniklas 0, language_unknown, objfile);
2224e93f7393Sniklas }
2225e93f7393Sniklas else
2226e93f7393Sniklas {
2227e93f7393Sniklas add_psymbol_to_list (namestring, strlen (namestring),
2228b725ae77Skettenis VAR_DOMAIN, storage,
2229e93f7393Sniklas &objfile->static_psymbols,
2230e93f7393Sniklas dn_bufp->dsvar.location,
2231e93f7393Sniklas 0, language_unknown, objfile);
2232e93f7393Sniklas }
2233e93f7393Sniklas }
2234b725ae77Skettenis }
2235b725ae77Skettenis }
2236b725ae77Skettenis continue;
2237b725ae77Skettenis
2238e93f7393Sniklas case DNTT_TYPE_MEMENUM:
2239e93f7393Sniklas case DNTT_TYPE_CONST:
2240e93f7393Sniklas /* Constants and members of enumerated types. */
2241b725ae77Skettenis set_namestring (dn_bufp, &namestring, objfile);
2242e93f7393Sniklas if (!pst)
2243e93f7393Sniklas {
2244b725ae77Skettenis pst = hpread_start_psymtab (objfile,
2245e93f7393Sniklas "globals", 0,
2246e93f7393Sniklas (hp_symnum
2247e93f7393Sniklas * sizeof (struct dntt_type_block)),
2248e93f7393Sniklas objfile->global_psymbols.next,
2249e93f7393Sniklas objfile->static_psymbols.next);
2250e93f7393Sniklas }
2251b725ae77Skettenis if (dn_bufp->dconst.global)
2252e93f7393Sniklas add_psymbol_to_list (namestring, strlen (namestring),
2253b725ae77Skettenis VAR_DOMAIN, LOC_CONST,
2254b725ae77Skettenis &objfile->global_psymbols, 0,
2255b725ae77Skettenis 0, language_unknown, objfile);
2256b725ae77Skettenis else
2257b725ae77Skettenis add_psymbol_to_list (namestring, strlen (namestring),
2258b725ae77Skettenis VAR_DOMAIN, LOC_CONST,
2259e93f7393Sniklas &objfile->static_psymbols, 0,
2260e93f7393Sniklas 0, language_unknown, objfile);
2261e93f7393Sniklas continue;
2262e93f7393Sniklas default:
2263e93f7393Sniklas continue;
2264e93f7393Sniklas }
2265e93f7393Sniklas }
2266e93f7393Sniklas }
2267e93f7393Sniklas
2268e93f7393Sniklas /* End any pending partial symbol table. */
2269e93f7393Sniklas if (pst)
2270e93f7393Sniklas {
2271e93f7393Sniklas hpread_end_psymtab (pst, psymtab_include_list, includes_used,
2272e93f7393Sniklas hp_symnum * sizeof (struct dntt_type_block),
2273e93f7393Sniklas 0, dependency_list, dependencies_used);
2274e93f7393Sniklas }
2275e93f7393Sniklas
2276e93f7393Sniklas discard_cleanups (old_chain);
2277e93f7393Sniklas }
2278e93f7393Sniklas
2279e93f7393Sniklas /* Perform any local cleanups required when we are done with a particular
2280e93f7393Sniklas objfile. I.E, we are in the process of discarding all symbol information
2281e93f7393Sniklas for an objfile, freeing up all memory held for it, and unlinking the
2282e93f7393Sniklas objfile struct from the global list of known objfiles. */
2283e93f7393Sniklas
2284e93f7393Sniklas void
hpread_symfile_finish(struct objfile * objfile)2285b725ae77Skettenis hpread_symfile_finish (struct objfile *objfile)
2286e93f7393Sniklas {
2287e93f7393Sniklas if (objfile->sym_private != NULL)
2288e93f7393Sniklas {
2289*63addd46Skettenis xfree (objfile->sym_private);
2290e93f7393Sniklas }
2291e93f7393Sniklas }
2292e93f7393Sniklas
2293e93f7393Sniklas
2294e93f7393Sniklas /* The remaining functions are all for internal use only. */
2295e93f7393Sniklas
2296e93f7393Sniklas /* Various small functions to get entries in the debug symbol sections. */
2297e93f7393Sniklas
2298e93f7393Sniklas static union dnttentry *
hpread_get_lntt(int index,struct objfile * objfile)2299b725ae77Skettenis hpread_get_lntt (int index, struct objfile *objfile)
2300e93f7393Sniklas {
2301e93f7393Sniklas return (union dnttentry *)
2302e93f7393Sniklas &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
2303e93f7393Sniklas }
2304e93f7393Sniklas
2305e93f7393Sniklas static union dnttentry *
hpread_get_gntt(int index,struct objfile * objfile)2306b725ae77Skettenis hpread_get_gntt (int index, struct objfile *objfile)
2307e93f7393Sniklas {
2308e93f7393Sniklas return (union dnttentry *)
2309e93f7393Sniklas &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
2310e93f7393Sniklas }
2311e93f7393Sniklas
2312e93f7393Sniklas static union sltentry *
hpread_get_slt(int index,struct objfile * objfile)2313b725ae77Skettenis hpread_get_slt (int index, struct objfile *objfile)
2314e93f7393Sniklas {
2315e93f7393Sniklas return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]);
2316e93f7393Sniklas }
2317e93f7393Sniklas
2318e93f7393Sniklas /* Get the low address associated with some symbol (typically the start
2319e93f7393Sniklas of a particular source file or module). Since that information is not
2320b725ae77Skettenis stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we
2321b725ae77Skettenis must infer it from the existence of DNTT_TYPE_FUNCTION symbols. */
2322e93f7393Sniklas
2323e93f7393Sniklas static unsigned long
hpread_get_textlow(int global,int index,struct objfile * objfile,int symcount)2324b725ae77Skettenis hpread_get_textlow (int global, int index, struct objfile *objfile,
2325b725ae77Skettenis int symcount)
2326e93f7393Sniklas {
2327b725ae77Skettenis union dnttentry *dn_bufp = NULL;
2328e93f7393Sniklas struct minimal_symbol *msymbol;
2329e93f7393Sniklas
2330e93f7393Sniklas /* Look for a DNTT_TYPE_FUNCTION symbol. */
2331b725ae77Skettenis if (index < symcount) /* symcount is the number of symbols in */
2332b725ae77Skettenis { /* the dbinfo, LNTT table */
2333e93f7393Sniklas do
2334e93f7393Sniklas {
2335e93f7393Sniklas if (global)
2336e93f7393Sniklas dn_bufp = hpread_get_gntt (index++, objfile);
2337e93f7393Sniklas else
2338e93f7393Sniklas dn_bufp = hpread_get_lntt (index++, objfile);
2339b725ae77Skettenis }
2340b725ae77Skettenis while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
2341b725ae77Skettenis && dn_bufp->dblock.kind != DNTT_TYPE_DOC_FUNCTION
2342b725ae77Skettenis && dn_bufp->dblock.kind != DNTT_TYPE_END
2343b725ae77Skettenis && index < symcount);
2344b725ae77Skettenis }
2345b725ae77Skettenis
2346b725ae77Skettenis /* NOTE: cagney/2003-03-29: If !(index < symcount), dn_bufp is left
2347b725ae77Skettenis undefined and that means that the test below is using a garbage
2348b725ae77Skettenis pointer from the stack. */
2349b725ae77Skettenis gdb_assert (dn_bufp != NULL);
2350e93f7393Sniklas
2351e93f7393Sniklas /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
2352e93f7393Sniklas might happen when a sourcefile has no functions. */
2353e93f7393Sniklas if (dn_bufp->dblock.kind == DNTT_TYPE_END)
2354e93f7393Sniklas return 0;
2355e93f7393Sniklas
2356b725ae77Skettenis /* Avoid going past the end of the LNTT file */
2357b725ae77Skettenis if (index == symcount)
2358b725ae77Skettenis return 0;
2359b725ae77Skettenis
2360e93f7393Sniklas /* The minimal symbols are typically more accurate for some reason. */
2361b725ae77Skettenis if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION)
2362e93f7393Sniklas msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
2363e93f7393Sniklas objfile);
2364b725ae77Skettenis else /* must be a DNTT_TYPE_DOC_FUNCTION */
2365b725ae77Skettenis msymbol = lookup_minimal_symbol (dn_bufp->ddocfunc.name + VT (objfile), NULL,
2366b725ae77Skettenis objfile);
2367b725ae77Skettenis
2368e93f7393Sniklas if (msymbol)
2369e93f7393Sniklas return SYMBOL_VALUE_ADDRESS (msymbol);
2370e93f7393Sniklas else
2371e93f7393Sniklas return dn_bufp->dfunc.lowaddr;
2372e93f7393Sniklas }
2373e93f7393Sniklas
2374e93f7393Sniklas /* Allocate and partially fill a partial symtab. It will be
2375e93f7393Sniklas completely filled at the end of the symbol list.
2376e93f7393Sniklas
2377e93f7393Sniklas SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2378e93f7393Sniklas is the address relative to which its symbols are (incremental) or 0
2379e93f7393Sniklas (normal). */
2380e93f7393Sniklas
2381e93f7393Sniklas static struct partial_symtab *
hpread_start_psymtab(struct objfile * objfile,char * filename,CORE_ADDR textlow,int ldsymoff,struct partial_symbol ** global_syms,struct partial_symbol ** static_syms)2382b725ae77Skettenis hpread_start_psymtab (struct objfile *objfile, char *filename,
2383b725ae77Skettenis CORE_ADDR textlow, int ldsymoff,
2384b725ae77Skettenis struct partial_symbol **global_syms,
2385b725ae77Skettenis struct partial_symbol **static_syms)
2386e93f7393Sniklas {
2387b725ae77Skettenis int offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2388b725ae77Skettenis extern void hpread_psymtab_to_symtab ();
2389e93f7393Sniklas struct partial_symtab *result =
2390b725ae77Skettenis start_psymtab_common (objfile, objfile->section_offsets,
2391e93f7393Sniklas filename, textlow, global_syms, static_syms);
2392e93f7393Sniklas
2393b725ae77Skettenis result->textlow += offset;
2394e93f7393Sniklas result->read_symtab_private = (char *)
2395b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack, sizeof (struct symloc));
2396e93f7393Sniklas LDSYMOFF (result) = ldsymoff;
2397e93f7393Sniklas result->read_symtab = hpread_psymtab_to_symtab;
2398e93f7393Sniklas
2399e93f7393Sniklas return result;
2400e93f7393Sniklas }
2401e93f7393Sniklas
2402e93f7393Sniklas
2403e93f7393Sniklas /* Close off the current usage of PST.
2404e93f7393Sniklas Returns PST or NULL if the partial symtab was empty and thrown away.
2405e93f7393Sniklas
2406b725ae77Skettenis capping_symbol_offset --Byte index in LNTT or GNTT of the
2407b725ae77Skettenis last symbol processed during the build
2408b725ae77Skettenis of the previous pst.
2409b725ae77Skettenis
2410e93f7393Sniklas FIXME: List variables and peculiarities of same. */
2411e93f7393Sniklas
2412e93f7393Sniklas static struct partial_symtab *
hpread_end_psymtab(struct partial_symtab * pst,char ** include_list,int num_includes,int capping_symbol_offset,CORE_ADDR capping_text,struct partial_symtab ** dependency_list,int number_dependencies)2413b725ae77Skettenis hpread_end_psymtab (struct partial_symtab *pst, char **include_list,
2414b725ae77Skettenis int num_includes, int capping_symbol_offset,
2415b725ae77Skettenis CORE_ADDR capping_text,
2416b725ae77Skettenis struct partial_symtab **dependency_list,
2417b725ae77Skettenis int number_dependencies)
2418e93f7393Sniklas {
2419e93f7393Sniklas int i;
2420e93f7393Sniklas struct objfile *objfile = pst->objfile;
2421b725ae77Skettenis int offset = ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (objfile));
2422b725ae77Skettenis
2423b725ae77Skettenis #ifdef DUMPING
2424b725ae77Skettenis /* Turn on to see what kind of a psymtab we've built. */
2425b725ae77Skettenis static int dumping = 0;
2426b725ae77Skettenis #endif
2427e93f7393Sniklas
2428e93f7393Sniklas if (capping_symbol_offset != -1)
2429e93f7393Sniklas LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
2430b725ae77Skettenis else
2431b725ae77Skettenis LDSYMLEN (pst) = 0;
2432b725ae77Skettenis pst->texthigh = capping_text + offset;
2433e93f7393Sniklas
2434e93f7393Sniklas pst->n_global_syms =
2435e93f7393Sniklas objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
2436e93f7393Sniklas pst->n_static_syms =
2437e93f7393Sniklas objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
2438e93f7393Sniklas
2439b725ae77Skettenis #ifdef DUMPING
2440b725ae77Skettenis if (dumping)
2441b725ae77Skettenis {
2442b725ae77Skettenis printf ("\nPst %s, LDSYMOFF %x (%x), LDSYMLEN %x (%x), globals %d, statics %d\n",
2443b725ae77Skettenis pst->filename,
2444b725ae77Skettenis LDSYMOFF (pst),
2445b725ae77Skettenis LDSYMOFF (pst) / sizeof (struct dntt_type_block),
2446b725ae77Skettenis LDSYMLEN (pst),
2447b725ae77Skettenis LDSYMLEN (pst) / sizeof (struct dntt_type_block),
2448b725ae77Skettenis pst->n_global_syms, pst->n_static_syms);
2449b725ae77Skettenis }
2450b725ae77Skettenis #endif
2451b725ae77Skettenis
2452e93f7393Sniklas pst->number_of_dependencies = number_dependencies;
2453e93f7393Sniklas if (number_dependencies)
2454e93f7393Sniklas {
2455e93f7393Sniklas pst->dependencies = (struct partial_symtab **)
2456b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack,
2457e93f7393Sniklas number_dependencies * sizeof (struct partial_symtab *));
2458e93f7393Sniklas memcpy (pst->dependencies, dependency_list,
2459e93f7393Sniklas number_dependencies * sizeof (struct partial_symtab *));
2460e93f7393Sniklas }
2461e93f7393Sniklas else
2462e93f7393Sniklas pst->dependencies = 0;
2463e93f7393Sniklas
2464e93f7393Sniklas for (i = 0; i < num_includes; i++)
2465e93f7393Sniklas {
2466e93f7393Sniklas struct partial_symtab *subpst =
2467e93f7393Sniklas allocate_psymtab (include_list[i], objfile);
2468e93f7393Sniklas
2469e93f7393Sniklas subpst->section_offsets = pst->section_offsets;
2470e93f7393Sniklas subpst->read_symtab_private =
2471b725ae77Skettenis (char *) obstack_alloc (&objfile->objfile_obstack,
2472e93f7393Sniklas sizeof (struct symloc));
2473e93f7393Sniklas LDSYMOFF (subpst) =
2474e93f7393Sniklas LDSYMLEN (subpst) =
2475e93f7393Sniklas subpst->textlow =
2476e93f7393Sniklas subpst->texthigh = 0;
2477e93f7393Sniklas
2478e93f7393Sniklas /* We could save slight bits of space by only making one of these,
2479e93f7393Sniklas shared by the entire set of include files. FIXME-someday. */
2480e93f7393Sniklas subpst->dependencies = (struct partial_symtab **)
2481b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack,
2482e93f7393Sniklas sizeof (struct partial_symtab *));
2483e93f7393Sniklas subpst->dependencies[0] = pst;
2484e93f7393Sniklas subpst->number_of_dependencies = 1;
2485e93f7393Sniklas
2486e93f7393Sniklas subpst->globals_offset =
2487e93f7393Sniklas subpst->n_global_syms =
2488e93f7393Sniklas subpst->statics_offset =
2489e93f7393Sniklas subpst->n_static_syms = 0;
2490e93f7393Sniklas
2491e93f7393Sniklas subpst->readin = 0;
2492e93f7393Sniklas subpst->symtab = 0;
2493e93f7393Sniklas subpst->read_symtab = pst->read_symtab;
2494e93f7393Sniklas }
2495e93f7393Sniklas
2496e93f7393Sniklas sort_pst_symbols (pst);
2497e93f7393Sniklas
2498e93f7393Sniklas /* If there is already a psymtab or symtab for a file of this name, remove it.
2499e93f7393Sniklas (If there is a symtab, more drastic things also happen.)
2500e93f7393Sniklas This happens in VxWorks. */
2501e93f7393Sniklas free_named_symtabs (pst->filename);
2502e93f7393Sniklas
2503e93f7393Sniklas if (num_includes == 0
2504e93f7393Sniklas && number_dependencies == 0
2505e93f7393Sniklas && pst->n_global_syms == 0
2506e93f7393Sniklas && pst->n_static_syms == 0)
2507e93f7393Sniklas {
2508e93f7393Sniklas /* Throw away this psymtab, it's empty. We can't deallocate it, since
2509b725ae77Skettenis it is on the obstack, but we can forget to chain it on the list.
2510b725ae77Skettenis Empty psymtabs happen as a result of header files which don't have
2511e93f7393Sniklas any symbols in them. There can be a lot of them. But this check
2512e93f7393Sniklas is wrong, in that a psymtab with N_SLINE entries but nothing else
2513e93f7393Sniklas is not empty, but we don't realize that. Fixing that without slowing
2514b725ae77Skettenis things down might be tricky.
2515b725ae77Skettenis It's also wrong if we're using the quick look-up tables, as
2516b725ae77Skettenis we can get empty psymtabs from modules with no routines in
2517b725ae77Skettenis them. */
2518e93f7393Sniklas
2519b725ae77Skettenis discard_psymtab (pst);
2520e93f7393Sniklas
2521e93f7393Sniklas /* Indicate that psymtab was thrown away. */
2522e93f7393Sniklas pst = (struct partial_symtab *) NULL;
2523b725ae77Skettenis
2524e93f7393Sniklas }
2525e93f7393Sniklas return pst;
2526e93f7393Sniklas }
2527b725ae77Skettenis
2528e93f7393Sniklas
2529b725ae77Skettenis /* Get the nesting depth for the source line identified by INDEX. */
2530b725ae77Skettenis
2531b725ae77Skettenis static unsigned long
hpread_get_scope_start(sltpointer index,struct objfile * objfile)2532b725ae77Skettenis hpread_get_scope_start (sltpointer index, struct objfile *objfile)
2533b725ae77Skettenis {
2534b725ae77Skettenis union sltentry *sl_bufp;
2535b725ae77Skettenis
2536b725ae77Skettenis sl_bufp = hpread_get_slt (index, objfile);
2537b725ae77Skettenis return sl_bufp->sspec.backptr.dnttp.index;
2538b725ae77Skettenis }
2539b725ae77Skettenis
2540b725ae77Skettenis /* Get the source line number the the line identified by INDEX. */
2541b725ae77Skettenis
2542b725ae77Skettenis static unsigned long
hpread_get_line(sltpointer index,struct objfile * objfile)2543b725ae77Skettenis hpread_get_line (sltpointer index, struct objfile *objfile)
2544b725ae77Skettenis {
2545b725ae77Skettenis union sltentry *sl_bufp;
2546b725ae77Skettenis
2547b725ae77Skettenis sl_bufp = hpread_get_slt (index, objfile);
2548b725ae77Skettenis return sl_bufp->snorm.line;
2549b725ae77Skettenis }
2550b725ae77Skettenis
2551b725ae77Skettenis /* Find the code address associated with a given sltpointer */
2552b725ae77Skettenis
2553b725ae77Skettenis static CORE_ADDR
hpread_get_location(sltpointer index,struct objfile * objfile)2554b725ae77Skettenis hpread_get_location (sltpointer index, struct objfile *objfile)
2555b725ae77Skettenis {
2556b725ae77Skettenis union sltentry *sl_bufp;
2557b725ae77Skettenis int i;
2558b725ae77Skettenis
2559b725ae77Skettenis /* code location of special sltentrys is determined from context */
2560b725ae77Skettenis sl_bufp = hpread_get_slt (index, objfile);
2561b725ae77Skettenis
2562b725ae77Skettenis if (sl_bufp->snorm.sltdesc == SLT_END)
2563b725ae77Skettenis {
2564b725ae77Skettenis /* find previous normal sltentry and get address */
2565b725ae77Skettenis for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
2566b725ae77Skettenis (sl_bufp->snorm.sltdesc != SLT_NORMAL_OFFSET) &&
2567b725ae77Skettenis (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
2568b725ae77Skettenis sl_bufp = hpread_get_slt (index - i, objfile);
2569b725ae77Skettenis if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET)
2570b725ae77Skettenis return sl_bufp->snormoff.address;
2571b725ae77Skettenis else
2572b725ae77Skettenis return sl_bufp->snorm.address;
2573b725ae77Skettenis }
2574b725ae77Skettenis
2575b725ae77Skettenis /* find next normal sltentry and get address */
2576b725ae77Skettenis for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
2577b725ae77Skettenis (sl_bufp->snorm.sltdesc != SLT_NORMAL_OFFSET) &&
2578b725ae77Skettenis (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
2579b725ae77Skettenis sl_bufp = hpread_get_slt (index + i, objfile);
2580b725ae77Skettenis if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET)
2581b725ae77Skettenis return sl_bufp->snormoff.address;
2582b725ae77Skettenis else
2583b725ae77Skettenis return sl_bufp->snorm.address;
2584b725ae77Skettenis }
2585b725ae77Skettenis
2586b725ae77Skettenis
2587b725ae77Skettenis /* Return 1 if an HP debug symbol of type KIND has a name associated with
2588b725ae77Skettenis * it, else return 0. (This function is not currently used, but I'll
2589b725ae77Skettenis * leave it here in case it proves useful later on. - RT).
2590b725ae77Skettenis */
2591b725ae77Skettenis
2592b725ae77Skettenis static int
hpread_has_name(enum dntt_entry_type kind)2593b725ae77Skettenis hpread_has_name (enum dntt_entry_type kind)
2594b725ae77Skettenis {
2595b725ae77Skettenis switch (kind)
2596b725ae77Skettenis {
2597b725ae77Skettenis case DNTT_TYPE_SRCFILE:
2598b725ae77Skettenis case DNTT_TYPE_MODULE:
2599b725ae77Skettenis case DNTT_TYPE_FUNCTION:
2600b725ae77Skettenis case DNTT_TYPE_DOC_FUNCTION:
2601b725ae77Skettenis case DNTT_TYPE_ENTRY:
2602b725ae77Skettenis case DNTT_TYPE_IMPORT:
2603b725ae77Skettenis case DNTT_TYPE_LABEL:
2604b725ae77Skettenis case DNTT_TYPE_FPARAM:
2605b725ae77Skettenis case DNTT_TYPE_SVAR:
2606b725ae77Skettenis case DNTT_TYPE_DVAR:
2607b725ae77Skettenis case DNTT_TYPE_CONST:
2608b725ae77Skettenis case DNTT_TYPE_TYPEDEF:
2609b725ae77Skettenis case DNTT_TYPE_TAGDEF:
2610b725ae77Skettenis case DNTT_TYPE_MEMENUM:
2611b725ae77Skettenis case DNTT_TYPE_FIELD:
2612b725ae77Skettenis case DNTT_TYPE_SA:
2613b725ae77Skettenis case DNTT_TYPE_BLOCKDATA:
2614b725ae77Skettenis case DNTT_TYPE_MEMFUNC:
2615b725ae77Skettenis case DNTT_TYPE_DOC_MEMFUNC:
2616b725ae77Skettenis return 1;
2617b725ae77Skettenis
2618b725ae77Skettenis case DNTT_TYPE_BEGIN:
2619b725ae77Skettenis case DNTT_TYPE_END:
2620b725ae77Skettenis case DNTT_TYPE_POINTER:
2621b725ae77Skettenis case DNTT_TYPE_ENUM:
2622b725ae77Skettenis case DNTT_TYPE_SET:
2623b725ae77Skettenis case DNTT_TYPE_ARRAY:
2624b725ae77Skettenis case DNTT_TYPE_STRUCT:
2625b725ae77Skettenis case DNTT_TYPE_UNION:
2626b725ae77Skettenis case DNTT_TYPE_VARIANT:
2627b725ae77Skettenis case DNTT_TYPE_FILE:
2628b725ae77Skettenis case DNTT_TYPE_FUNCTYPE:
2629b725ae77Skettenis case DNTT_TYPE_SUBRANGE:
2630b725ae77Skettenis case DNTT_TYPE_WITH:
2631b725ae77Skettenis case DNTT_TYPE_COMMON:
2632b725ae77Skettenis case DNTT_TYPE_COBSTRUCT:
2633b725ae77Skettenis case DNTT_TYPE_XREF:
2634b725ae77Skettenis case DNTT_TYPE_MACRO:
2635b725ae77Skettenis case DNTT_TYPE_CLASS_SCOPE:
2636b725ae77Skettenis case DNTT_TYPE_REFERENCE:
2637b725ae77Skettenis case DNTT_TYPE_PTRMEM:
2638b725ae77Skettenis case DNTT_TYPE_PTRMEMFUNC:
2639b725ae77Skettenis case DNTT_TYPE_CLASS:
2640b725ae77Skettenis case DNTT_TYPE_GENFIELD:
2641b725ae77Skettenis case DNTT_TYPE_VFUNC:
2642b725ae77Skettenis case DNTT_TYPE_MEMACCESS:
2643b725ae77Skettenis case DNTT_TYPE_INHERITANCE:
2644b725ae77Skettenis case DNTT_TYPE_FRIEND_CLASS:
2645b725ae77Skettenis case DNTT_TYPE_FRIEND_FUNC:
2646b725ae77Skettenis case DNTT_TYPE_MODIFIER:
2647b725ae77Skettenis case DNTT_TYPE_OBJECT_ID:
2648b725ae77Skettenis case DNTT_TYPE_TEMPLATE:
2649b725ae77Skettenis case DNTT_TYPE_TEMPLATE_ARG:
2650b725ae77Skettenis case DNTT_TYPE_FUNC_TEMPLATE:
2651b725ae77Skettenis case DNTT_TYPE_LINK:
2652b725ae77Skettenis /* DNTT_TYPE_DYN_ARRAY_DESC ? */
2653b725ae77Skettenis /* DNTT_TYPE_DESC_SUBRANGE ? */
2654b725ae77Skettenis /* DNTT_TYPE_BEGIN_EXT ? */
2655b725ae77Skettenis /* DNTT_TYPE_INLN ? */
2656b725ae77Skettenis /* DNTT_TYPE_INLN_LIST ? */
2657b725ae77Skettenis /* DNTT_TYPE_ALIAS ? */
2658b725ae77Skettenis default:
2659b725ae77Skettenis return 0;
2660b725ae77Skettenis }
2661b725ae77Skettenis }
2662b725ae77Skettenis
2663e93f7393Sniklas /* Do the dirty work of reading in the full symbol from a partial symbol
2664e93f7393Sniklas table. */
2665e93f7393Sniklas
2666e93f7393Sniklas static void
hpread_psymtab_to_symtab_1(struct partial_symtab * pst)2667b725ae77Skettenis hpread_psymtab_to_symtab_1 (struct partial_symtab *pst)
2668e93f7393Sniklas {
2669e93f7393Sniklas struct cleanup *old_chain;
2670e93f7393Sniklas int i;
2671e93f7393Sniklas
2672e93f7393Sniklas /* Get out quick if passed junk. */
2673e93f7393Sniklas if (!pst)
2674e93f7393Sniklas return;
2675e93f7393Sniklas
2676e93f7393Sniklas /* Complain if we've already read in this symbol table. */
2677e93f7393Sniklas if (pst->readin)
2678e93f7393Sniklas {
2679b725ae77Skettenis fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in."
2680b725ae77Skettenis " Shouldn't happen.\n",
2681e93f7393Sniklas pst->filename);
2682e93f7393Sniklas return;
2683e93f7393Sniklas }
2684e93f7393Sniklas
2685e93f7393Sniklas /* Read in all partial symtabs on which this one is dependent */
2686e93f7393Sniklas for (i = 0; i < pst->number_of_dependencies; i++)
2687e93f7393Sniklas if (!pst->dependencies[i]->readin)
2688e93f7393Sniklas {
2689e93f7393Sniklas /* Inform about additional files that need to be read in. */
2690e93f7393Sniklas if (info_verbose)
2691e93f7393Sniklas {
2692b725ae77Skettenis fputs_filtered (" ", gdb_stdout);
2693e93f7393Sniklas wrap_here ("");
2694b725ae77Skettenis fputs_filtered ("and ", gdb_stdout);
2695e93f7393Sniklas wrap_here ("");
2696e93f7393Sniklas printf_filtered ("%s...", pst->dependencies[i]->filename);
2697e93f7393Sniklas wrap_here (""); /* Flush output */
2698b725ae77Skettenis gdb_flush (gdb_stdout);
2699e93f7393Sniklas }
2700e93f7393Sniklas hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
2701e93f7393Sniklas }
2702e93f7393Sniklas
2703e93f7393Sniklas /* If it's real... */
2704e93f7393Sniklas if (LDSYMLEN (pst))
2705e93f7393Sniklas {
2706e93f7393Sniklas /* Init stuff necessary for reading in symbols */
2707e93f7393Sniklas buildsym_init ();
2708e93f7393Sniklas old_chain = make_cleanup (really_free_pendings, 0);
2709e93f7393Sniklas
2710e93f7393Sniklas pst->symtab =
2711e93f7393Sniklas hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
2712e93f7393Sniklas pst->textlow, pst->texthigh - pst->textlow,
2713e93f7393Sniklas pst->section_offsets, pst->filename);
2714e93f7393Sniklas
2715e93f7393Sniklas do_cleanups (old_chain);
2716e93f7393Sniklas }
2717e93f7393Sniklas
2718e93f7393Sniklas pst->readin = 1;
2719e93f7393Sniklas }
2720e93f7393Sniklas
2721e93f7393Sniklas /* Read in all of the symbols for a given psymtab for real.
2722e93f7393Sniklas Be verbose about it if the user wants that. */
2723e93f7393Sniklas
2724e93f7393Sniklas static void
hpread_psymtab_to_symtab(struct partial_symtab * pst)2725b725ae77Skettenis hpread_psymtab_to_symtab (struct partial_symtab *pst)
2726e93f7393Sniklas {
2727e93f7393Sniklas /* Get out quick if given junk. */
2728e93f7393Sniklas if (!pst)
2729e93f7393Sniklas return;
2730e93f7393Sniklas
2731e93f7393Sniklas /* Sanity check. */
2732e93f7393Sniklas if (pst->readin)
2733e93f7393Sniklas {
2734b725ae77Skettenis fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in."
2735b725ae77Skettenis " Shouldn't happen.\n",
2736e93f7393Sniklas pst->filename);
2737e93f7393Sniklas return;
2738e93f7393Sniklas }
2739e93f7393Sniklas
2740b725ae77Skettenis /* elz: setting the flag to indicate that the code of the target
2741b725ae77Skettenis was compiled using an HP compiler (aCC, cc)
2742b725ae77Skettenis the processing_acc_compilation variable is declared in the
2743b725ae77Skettenis file buildsym.h, the HP_COMPILED_TARGET is defined to be equal
2744b725ae77Skettenis to 3 in the file tm_hppa.h */
2745b725ae77Skettenis
2746b725ae77Skettenis processing_gcc_compilation = 0;
2747b725ae77Skettenis
2748e93f7393Sniklas if (LDSYMLEN (pst) || pst->number_of_dependencies)
2749e93f7393Sniklas {
2750e93f7393Sniklas /* Print the message now, before reading the string table,
2751e93f7393Sniklas to avoid disconcerting pauses. */
2752e93f7393Sniklas if (info_verbose)
2753e93f7393Sniklas {
2754e93f7393Sniklas printf_filtered ("Reading in symbols for %s...", pst->filename);
2755b725ae77Skettenis gdb_flush (gdb_stdout);
2756e93f7393Sniklas }
2757e93f7393Sniklas
2758e93f7393Sniklas hpread_psymtab_to_symtab_1 (pst);
2759e93f7393Sniklas
2760e93f7393Sniklas /* Match with global symbols. This only needs to be done once,
2761e93f7393Sniklas after all of the symtabs and dependencies have been read in. */
2762e93f7393Sniklas scan_file_globals (pst->objfile);
2763e93f7393Sniklas
2764e93f7393Sniklas /* Finish up the debug error message. */
2765e93f7393Sniklas if (info_verbose)
2766e93f7393Sniklas printf_filtered ("done.\n");
2767e93f7393Sniklas }
2768e93f7393Sniklas }
2769b725ae77Skettenis
2770e93f7393Sniklas /* Read in a defined section of a specific object file's symbols.
2771e93f7393Sniklas
2772e93f7393Sniklas DESC is the file descriptor for the file, positioned at the
2773e93f7393Sniklas beginning of the symtab
2774e93f7393Sniklas SYM_OFFSET is the offset within the file of
2775e93f7393Sniklas the beginning of the symbols we want to read
2776e93f7393Sniklas SYM_SIZE is the size of the symbol info to read in.
2777e93f7393Sniklas TEXT_OFFSET is the beginning of the text segment we are reading symbols for
2778e93f7393Sniklas TEXT_SIZE is the size of the text segment read in.
2779e93f7393Sniklas SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
2780e93f7393Sniklas
2781e93f7393Sniklas static struct symtab *
hpread_expand_symtab(struct objfile * objfile,int sym_offset,int sym_size,CORE_ADDR text_offset,int text_size,struct section_offsets * section_offsets,char * filename)2782b725ae77Skettenis hpread_expand_symtab (struct objfile *objfile, int sym_offset, int sym_size,
2783b725ae77Skettenis CORE_ADDR text_offset, int text_size,
2784b725ae77Skettenis struct section_offsets *section_offsets, char *filename)
2785e93f7393Sniklas {
2786e93f7393Sniklas char *namestring;
2787e93f7393Sniklas union dnttentry *dn_bufp;
2788e93f7393Sniklas unsigned max_symnum;
2789b725ae77Skettenis int at_module_boundary = 0;
2790b725ae77Skettenis /* 1 => at end, -1 => at beginning */
2791e93f7393Sniklas
2792e93f7393Sniklas int sym_index = sym_offset / sizeof (struct dntt_type_block);
2793e93f7393Sniklas
2794e93f7393Sniklas current_objfile = objfile;
2795e93f7393Sniklas subfile_stack = 0;
2796e93f7393Sniklas
2797e93f7393Sniklas last_source_file = 0;
2798e93f7393Sniklas
2799b725ae77Skettenis /* Demangling style -- if EDG style already set, don't change it,
2800b725ae77Skettenis as HP style causes some problems with the KAI EDG compiler */
2801b725ae77Skettenis if (current_demangling_style != edg_demangling)
2802b725ae77Skettenis {
2803b725ae77Skettenis /* Otherwise, ensure that we are using HP style demangling */
2804b725ae77Skettenis set_demangling_style (HP_DEMANGLING_STYLE_STRING);
2805b725ae77Skettenis }
2806b725ae77Skettenis
2807e93f7393Sniklas dn_bufp = hpread_get_lntt (sym_index, objfile);
2808e93f7393Sniklas if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
2809e93f7393Sniklas (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
2810b725ae77Skettenis {
2811e93f7393Sniklas start_symtab ("globals", NULL, 0);
2812b725ae77Skettenis record_debugformat ("HP");
2813b725ae77Skettenis }
2814e93f7393Sniklas
2815b725ae77Skettenis /* The psymtab builder (hp-psymtab-read.c) is the one that
2816b725ae77Skettenis * determined the "sym_size" argument (i.e. how many DNTT symbols
2817b725ae77Skettenis * are in this symtab), which we use to compute "max_symnum"
2818b725ae77Skettenis * (point in DNTT to which we read).
2819b725ae77Skettenis *
2820b725ae77Skettenis * Perhaps this should be changed so that
2821b725ae77Skettenis * process_one_debug_symbol() "knows" when
2822b725ae77Skettenis * to stop reading (based on reading from the MODULE to the matching
2823b725ae77Skettenis * END), and take out this reliance on a #-syms being passed in...
2824b725ae77Skettenis * (I'm worried about the reliability of this number). But I'll
2825b725ae77Skettenis * leave it as-is, for now. - RT
2826b725ae77Skettenis *
2827b725ae77Skettenis * The change above has been made. I've left the "for" loop control
2828b725ae77Skettenis * in to prepare for backing this out again. -JB
2829b725ae77Skettenis */
2830e93f7393Sniklas max_symnum = sym_size / sizeof (struct dntt_type_block);
2831b725ae77Skettenis /* No reason to multiply on pst side and divide on sym side... FIXME */
2832e93f7393Sniklas
2833b725ae77Skettenis /* Read in and process each debug symbol within the specified range.
2834b725ae77Skettenis */
2835e93f7393Sniklas for (symnum = 0;
2836e93f7393Sniklas symnum < max_symnum;
2837e93f7393Sniklas symnum++)
2838e93f7393Sniklas {
2839e93f7393Sniklas QUIT; /* Allow this to be interruptable */
2840e93f7393Sniklas dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
2841e93f7393Sniklas
2842e93f7393Sniklas if (dn_bufp->dblock.extension)
2843e93f7393Sniklas continue;
2844e93f7393Sniklas
2845b725ae77Skettenis /* Yow! We call set_namestring on things without names! */
2846b725ae77Skettenis set_namestring (dn_bufp, &namestring, objfile);
2847e93f7393Sniklas
2848e93f7393Sniklas hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
2849e93f7393Sniklas objfile, text_offset, text_size,
2850b725ae77Skettenis filename, symnum + sym_index,
2851b725ae77Skettenis &at_module_boundary
2852b725ae77Skettenis );
2853b725ae77Skettenis
2854b725ae77Skettenis /* OLD COMMENTS: This routine is only called for psts. All psts
2855b725ae77Skettenis * correspond to MODULES. If we ever do lazy-reading of globals
2856b725ae77Skettenis * from the LNTT, then there will be a pst which ends when the
2857b725ae77Skettenis * LNTT ends, and not at an END MODULE entry. Then we'll have
2858b725ae77Skettenis * to re-visit this break.
2859b725ae77Skettenis
2860b725ae77Skettenis if( at_end_of_module )
2861b725ae77Skettenis break;
2862b725ae77Skettenis
2863b725ae77Skettenis */
2864b725ae77Skettenis
2865b725ae77Skettenis /* We no longer break out of the loop when we reach the end of a
2866b725ae77Skettenis module. The reason is that with CTTI, the compiler can generate
2867b725ae77Skettenis function symbols (for template function instantiations) which are not
2868b725ae77Skettenis in any module; typically they show up beyond a module's end, and
2869b725ae77Skettenis before the next module's start. We include them in the current
2870b725ae77Skettenis module. However, we still don't trust the MAX_SYMNUM value from
2871b725ae77Skettenis the psymtab, so we break out if we enter a new module. */
2872b725ae77Skettenis
2873b725ae77Skettenis if (at_module_boundary == -1)
2874b725ae77Skettenis break;
2875e93f7393Sniklas }
2876e93f7393Sniklas
2877e93f7393Sniklas current_objfile = NULL;
2878*63addd46Skettenis deprecated_hp_som_som_object_present = 1; /* Indicate we've processed an HP SOM SOM file */
2879e93f7393Sniklas
2880b725ae77Skettenis return end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT (objfile));
2881e93f7393Sniklas }
2882e93f7393Sniklas
2883e93f7393Sniklas
2884b725ae77Skettenis
2885b725ae77Skettenis
2886e93f7393Sniklas /* Convert basic types from HP debug format into GDB internal format. */
2887e93f7393Sniklas
2888e93f7393Sniklas static int
hpread_type_translate(dnttpointer typep)2889b725ae77Skettenis hpread_type_translate (dnttpointer typep)
2890e93f7393Sniklas {
2891e93f7393Sniklas if (!typep.dntti.immediate)
2892b725ae77Skettenis {
2893b725ae77Skettenis error ("error in hpread_type_translate\n.");
2894b725ae77Skettenis return FT_VOID;
2895b725ae77Skettenis }
2896e93f7393Sniklas
2897e93f7393Sniklas switch (typep.dntti.type)
2898e93f7393Sniklas {
2899e93f7393Sniklas case HP_TYPE_BOOLEAN:
2900e93f7393Sniklas case HP_TYPE_BOOLEAN_S300_COMPAT:
2901e93f7393Sniklas case HP_TYPE_BOOLEAN_VAX_COMPAT:
2902e93f7393Sniklas return FT_BOOLEAN;
2903b725ae77Skettenis case HP_TYPE_CHAR: /* C signed char, C++ plain char */
2904b725ae77Skettenis
2905e93f7393Sniklas case HP_TYPE_WIDE_CHAR:
2906e93f7393Sniklas return FT_CHAR;
2907e93f7393Sniklas case HP_TYPE_INT:
2908e93f7393Sniklas if (typep.dntti.bitlength <= 8)
2909b725ae77Skettenis return FT_SIGNED_CHAR; /* C++ signed char */
2910e93f7393Sniklas if (typep.dntti.bitlength <= 16)
2911e93f7393Sniklas return FT_SHORT;
2912e93f7393Sniklas if (typep.dntti.bitlength <= 32)
2913e93f7393Sniklas return FT_INTEGER;
2914e93f7393Sniklas return FT_LONG_LONG;
2915e93f7393Sniklas case HP_TYPE_LONG:
2916b725ae77Skettenis if (typep.dntti.bitlength <= 8)
2917b725ae77Skettenis return FT_SIGNED_CHAR; /* C++ signed char. */
2918e93f7393Sniklas return FT_LONG;
2919e93f7393Sniklas case HP_TYPE_UNSIGNED_LONG:
2920e93f7393Sniklas if (typep.dntti.bitlength <= 8)
2921b725ae77Skettenis return FT_UNSIGNED_CHAR; /* C/C++ unsigned char */
2922e93f7393Sniklas if (typep.dntti.bitlength <= 16)
2923e93f7393Sniklas return FT_UNSIGNED_SHORT;
2924e93f7393Sniklas if (typep.dntti.bitlength <= 32)
2925e93f7393Sniklas return FT_UNSIGNED_LONG;
2926e93f7393Sniklas return FT_UNSIGNED_LONG_LONG;
2927e93f7393Sniklas case HP_TYPE_UNSIGNED_INT:
2928e93f7393Sniklas if (typep.dntti.bitlength <= 8)
2929e93f7393Sniklas return FT_UNSIGNED_CHAR;
2930e93f7393Sniklas if (typep.dntti.bitlength <= 16)
2931e93f7393Sniklas return FT_UNSIGNED_SHORT;
2932e93f7393Sniklas if (typep.dntti.bitlength <= 32)
2933e93f7393Sniklas return FT_UNSIGNED_INTEGER;
2934e93f7393Sniklas return FT_UNSIGNED_LONG_LONG;
2935e93f7393Sniklas case HP_TYPE_REAL:
2936e93f7393Sniklas case HP_TYPE_REAL_3000:
2937e93f7393Sniklas case HP_TYPE_DOUBLE:
2938e93f7393Sniklas if (typep.dntti.bitlength == 64)
2939e93f7393Sniklas return FT_DBL_PREC_FLOAT;
2940e93f7393Sniklas if (typep.dntti.bitlength == 128)
2941e93f7393Sniklas return FT_EXT_PREC_FLOAT;
2942e93f7393Sniklas return FT_FLOAT;
2943e93f7393Sniklas case HP_TYPE_COMPLEX:
2944e93f7393Sniklas case HP_TYPE_COMPLEXS3000:
2945e93f7393Sniklas if (typep.dntti.bitlength == 128)
2946e93f7393Sniklas return FT_DBL_PREC_COMPLEX;
2947e93f7393Sniklas if (typep.dntti.bitlength == 192)
2948e93f7393Sniklas return FT_EXT_PREC_COMPLEX;
2949e93f7393Sniklas return FT_COMPLEX;
2950b725ae77Skettenis case HP_TYPE_VOID:
2951b725ae77Skettenis return FT_VOID;
2952e93f7393Sniklas case HP_TYPE_STRING200:
2953e93f7393Sniklas case HP_TYPE_LONGSTRING200:
2954e93f7393Sniklas case HP_TYPE_FTN_STRING_SPEC:
2955e93f7393Sniklas case HP_TYPE_MOD_STRING_SPEC:
2956e93f7393Sniklas case HP_TYPE_MOD_STRING_3000:
2957e93f7393Sniklas case HP_TYPE_FTN_STRING_S300_COMPAT:
2958e93f7393Sniklas case HP_TYPE_FTN_STRING_VAX_COMPAT:
2959e93f7393Sniklas return FT_STRING;
2960b725ae77Skettenis case HP_TYPE_TEMPLATE_ARG:
2961b725ae77Skettenis return FT_TEMPLATE_ARG;
2962b725ae77Skettenis case HP_TYPE_TEXT:
2963b725ae77Skettenis case HP_TYPE_FLABEL:
2964b725ae77Skettenis case HP_TYPE_PACKED_DECIMAL:
2965b725ae77Skettenis case HP_TYPE_ANYPOINTER:
2966b725ae77Skettenis case HP_TYPE_GLOBAL_ANYPOINTER:
2967b725ae77Skettenis case HP_TYPE_LOCAL_ANYPOINTER:
2968e93f7393Sniklas default:
2969b725ae77Skettenis warning ("hpread_type_translate: unhandled type code.\n");
2970b725ae77Skettenis return FT_VOID;
2971e93f7393Sniklas }
2972e93f7393Sniklas }
2973e93f7393Sniklas
2974b725ae77Skettenis /* Given a position in the DNTT, return a pointer to the
2975b725ae77Skettenis * already-built "struct type" (if any), for the type defined
2976b725ae77Skettenis * at that position.
2977b725ae77Skettenis */
2978e93f7393Sniklas
2979e93f7393Sniklas static struct type **
hpread_lookup_type(dnttpointer hp_type,struct objfile * objfile)2980b725ae77Skettenis hpread_lookup_type (dnttpointer hp_type, struct objfile *objfile)
2981e93f7393Sniklas {
2982e93f7393Sniklas unsigned old_len;
2983e93f7393Sniklas int index = hp_type.dnttp.index;
2984b725ae77Skettenis int size_changed = 0;
2985e93f7393Sniklas
2986b725ae77Skettenis /* The immediate flag indicates this doesn't actually point to
2987b725ae77Skettenis * a type DNTT.
2988b725ae77Skettenis */
2989e93f7393Sniklas if (hp_type.dntti.immediate)
2990e93f7393Sniklas return NULL;
2991e93f7393Sniklas
2992b725ae77Skettenis /* For each objfile, we maintain a "type vector".
2993b725ae77Skettenis * This an array of "struct type *"'s with one pointer per DNTT index.
2994b725ae77Skettenis * Given a DNTT index, we look in this array to see if we have
2995b725ae77Skettenis * already processed this DNTT and if it is a type definition.
2996b725ae77Skettenis * If so, then we can locate a pointer to the already-built
2997b725ae77Skettenis * "struct type", and not build it again.
2998b725ae77Skettenis *
2999b725ae77Skettenis * The need for this arises because our DNTT-walking code wanders
3000b725ae77Skettenis * around. In particular, it will encounter the same type multiple
3001b725ae77Skettenis * times (once for each object of that type). We don't want to
3002b725ae77Skettenis * built multiple "struct type"'s for the same thing.
3003b725ae77Skettenis *
3004b725ae77Skettenis * Having said this, I should point out that this type-vector is
3005b725ae77Skettenis * an expensive way to keep track of this. If most DNTT entries are
3006b725ae77Skettenis * 3 words, the type-vector will be 1/3 the size of the DNTT itself.
3007b725ae77Skettenis * Alternative solutions:
3008b725ae77Skettenis * - Keep a compressed or hashed table. Less memory, but more expensive
3009b725ae77Skettenis * to search and update.
3010b725ae77Skettenis * - (Suggested by JB): Overwrite the DNTT entry itself
3011b725ae77Skettenis * with the info. Create a new type code "ALREADY_BUILT", and modify
3012b725ae77Skettenis * the DNTT to have that type code and point to the already-built entry.
3013b725ae77Skettenis * -RT
3014b725ae77Skettenis */
3015b725ae77Skettenis
3016e93f7393Sniklas if (index < LNTT_SYMCOUNT (objfile))
3017e93f7393Sniklas {
3018b725ae77Skettenis if (index >= DNTT_TYPE_VECTOR_LENGTH (objfile))
3019e93f7393Sniklas {
3020b725ae77Skettenis old_len = DNTT_TYPE_VECTOR_LENGTH (objfile);
3021b725ae77Skettenis
3022b725ae77Skettenis /* See if we need to allocate a type-vector. */
3023e93f7393Sniklas if (old_len == 0)
3024e93f7393Sniklas {
3025b725ae77Skettenis DNTT_TYPE_VECTOR_LENGTH (objfile) = LNTT_SYMCOUNT (objfile) + GNTT_SYMCOUNT (objfile);
3026b725ae77Skettenis DNTT_TYPE_VECTOR (objfile) = (struct type **)
3027*63addd46Skettenis xmalloc (DNTT_TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
3028b725ae77Skettenis memset (&DNTT_TYPE_VECTOR (objfile)[old_len], 0,
3029b725ae77Skettenis (DNTT_TYPE_VECTOR_LENGTH (objfile) - old_len) *
3030e93f7393Sniklas sizeof (struct type *));
3031e93f7393Sniklas }
3032b725ae77Skettenis
3033b725ae77Skettenis /* See if we need to resize type-vector. With my change to
3034b725ae77Skettenis * initially allocate a correct-size type-vector, this code
3035b725ae77Skettenis * should no longer trigger.
3036b725ae77Skettenis */
3037b725ae77Skettenis while (index >= DNTT_TYPE_VECTOR_LENGTH (objfile))
3038b725ae77Skettenis {
3039b725ae77Skettenis DNTT_TYPE_VECTOR_LENGTH (objfile) *= 2;
3040b725ae77Skettenis size_changed = 1;
3041b725ae77Skettenis }
3042b725ae77Skettenis if (size_changed)
3043b725ae77Skettenis {
3044b725ae77Skettenis DNTT_TYPE_VECTOR (objfile) = (struct type **)
3045*63addd46Skettenis xrealloc ((char *) DNTT_TYPE_VECTOR (objfile),
3046b725ae77Skettenis (DNTT_TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
3047b725ae77Skettenis
3048b725ae77Skettenis memset (&DNTT_TYPE_VECTOR (objfile)[old_len], 0,
3049b725ae77Skettenis (DNTT_TYPE_VECTOR_LENGTH (objfile) - old_len) *
3050b725ae77Skettenis sizeof (struct type *));
3051b725ae77Skettenis }
3052b725ae77Skettenis
3053b725ae77Skettenis }
3054b725ae77Skettenis return &DNTT_TYPE_VECTOR (objfile)[index];
3055e93f7393Sniklas }
3056e93f7393Sniklas else
3057e93f7393Sniklas return NULL;
3058e93f7393Sniklas }
3059e93f7393Sniklas
3060e93f7393Sniklas /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
3061e93f7393Sniklas Note we'll just return the address of a GDB internal type if we already
3062e93f7393Sniklas have it lying around. */
3063e93f7393Sniklas
3064e93f7393Sniklas static struct type *
hpread_alloc_type(dnttpointer hp_type,struct objfile * objfile)3065b725ae77Skettenis hpread_alloc_type (dnttpointer hp_type, struct objfile *objfile)
3066e93f7393Sniklas {
3067e93f7393Sniklas struct type **type_addr;
3068e93f7393Sniklas
3069e93f7393Sniklas type_addr = hpread_lookup_type (hp_type, objfile);
3070e93f7393Sniklas if (*type_addr == 0)
3071b725ae77Skettenis {
3072e93f7393Sniklas *type_addr = alloc_type (objfile);
3073e93f7393Sniklas
3074b725ae77Skettenis /* A hack - if we really are a C++ class symbol, then this default
3075b725ae77Skettenis * will get overriden later on.
3076b725ae77Skettenis */
3077e93f7393Sniklas TYPE_CPLUS_SPECIFIC (*type_addr)
3078e93f7393Sniklas = (struct cplus_struct_type *) &cplus_struct_default;
3079b725ae77Skettenis }
3080b725ae77Skettenis
3081e93f7393Sniklas return *type_addr;
3082e93f7393Sniklas }
3083e93f7393Sniklas
3084e93f7393Sniklas /* Read a native enumerated type and return it in GDB internal form. */
3085e93f7393Sniklas
3086e93f7393Sniklas static struct type *
hpread_read_enum_type(dnttpointer hp_type,union dnttentry * dn_bufp,struct objfile * objfile)3087b725ae77Skettenis hpread_read_enum_type (dnttpointer hp_type, union dnttentry *dn_bufp,
3088b725ae77Skettenis struct objfile *objfile)
3089e93f7393Sniklas {
3090e93f7393Sniklas struct type *type;
3091e93f7393Sniklas struct pending **symlist, *osyms, *syms;
3092b725ae77Skettenis struct pending *local_list = NULL;
3093e93f7393Sniklas int o_nsyms, nsyms = 0;
3094e93f7393Sniklas dnttpointer mem;
3095e93f7393Sniklas union dnttentry *memp;
3096e93f7393Sniklas char *name;
3097e93f7393Sniklas long n;
3098e93f7393Sniklas struct symbol *sym;
3099e93f7393Sniklas
3100b725ae77Skettenis /* Allocate a GDB type. If we've already read in this enum type,
3101b725ae77Skettenis * it'll return the already built GDB type, so stop here.
3102b725ae77Skettenis * (Note: I added this check, to conform with what's done for
3103b725ae77Skettenis * struct, union, class.
3104b725ae77Skettenis * I assume this is OK. - RT)
3105b725ae77Skettenis */
3106e93f7393Sniklas type = hpread_alloc_type (hp_type, objfile);
3107b725ae77Skettenis if (TYPE_CODE (type) == TYPE_CODE_ENUM)
3108b725ae77Skettenis return type;
3109b725ae77Skettenis
3110b725ae77Skettenis /* HP C supports "sized enums", where a specifier such as "short" or
3111b725ae77Skettenis "char" can be used to get enums of different sizes. So don't assume
3112b725ae77Skettenis an enum is always 4 bytes long. pai/1997-08-21 */
3113b725ae77Skettenis TYPE_LENGTH (type) = dn_bufp->denum.bitlength / 8;
3114e93f7393Sniklas
3115e93f7393Sniklas symlist = &file_symbols;
3116e93f7393Sniklas osyms = *symlist;
3117e93f7393Sniklas o_nsyms = osyms ? osyms->nsyms : 0;
3118e93f7393Sniklas
3119b725ae77Skettenis /* Get a name for each member and add it to our list of members.
3120b725ae77Skettenis * The list of "mem" SOM records we are walking should all be
3121b725ae77Skettenis * SOM type DNTT_TYPE_MEMENUM (not checked).
3122b725ae77Skettenis */
3123e93f7393Sniklas mem = dn_bufp->denum.firstmem;
3124b725ae77Skettenis while (mem.word && mem.word != DNTTNIL)
3125e93f7393Sniklas {
3126e93f7393Sniklas memp = hpread_get_lntt (mem.dnttp.index, objfile);
3127e93f7393Sniklas
3128e93f7393Sniklas name = VT (objfile) + memp->dmember.name;
3129b725ae77Skettenis sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
3130e93f7393Sniklas sizeof (struct symbol));
3131e93f7393Sniklas memset (sym, 0, sizeof (struct symbol));
3132b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
3133b725ae77Skettenis &objfile->objfile_obstack);
3134e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_CONST;
3135b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
3136e93f7393Sniklas SYMBOL_VALUE (sym) = memp->dmember.value;
3137e93f7393Sniklas add_symbol_to_list (sym, symlist);
3138e93f7393Sniklas nsyms++;
3139e93f7393Sniklas mem = memp->dmember.nextmem;
3140e93f7393Sniklas }
3141e93f7393Sniklas
3142e93f7393Sniklas /* Now that we know more about the enum, fill in more info. */
3143e93f7393Sniklas TYPE_CODE (type) = TYPE_CODE_ENUM;
3144e93f7393Sniklas TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
3145e93f7393Sniklas TYPE_NFIELDS (type) = nsyms;
3146e93f7393Sniklas TYPE_FIELDS (type) = (struct field *)
3147b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack, sizeof (struct field) * nsyms);
3148e93f7393Sniklas
3149e93f7393Sniklas /* Find the symbols for the members and put them into the type.
3150e93f7393Sniklas The symbols can be found in the symlist that we put them on
3151e93f7393Sniklas to cause them to be defined. osyms contains the old value
3152e93f7393Sniklas of that symlist; everything up to there was defined by us.
3153e93f7393Sniklas
3154e93f7393Sniklas Note that we preserve the order of the enum constants, so
3155e93f7393Sniklas that in something like "enum {FOO, LAST_THING=FOO}" we print
3156e93f7393Sniklas FOO, not LAST_THING. */
3157e93f7393Sniklas for (syms = *symlist, n = 0; syms; syms = syms->next)
3158e93f7393Sniklas {
3159e93f7393Sniklas int j = 0;
3160e93f7393Sniklas if (syms == osyms)
3161e93f7393Sniklas j = o_nsyms;
3162e93f7393Sniklas for (; j < syms->nsyms; j++, n++)
3163e93f7393Sniklas {
3164e93f7393Sniklas struct symbol *xsym = syms->symbol[j];
3165e93f7393Sniklas SYMBOL_TYPE (xsym) = type;
3166b725ae77Skettenis TYPE_FIELD_NAME (type, n) = DEPRECATED_SYMBOL_NAME (xsym);
3167e93f7393Sniklas TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
3168e93f7393Sniklas TYPE_FIELD_BITSIZE (type, n) = 0;
3169b725ae77Skettenis TYPE_FIELD_STATIC_KIND (type, n) = 0;
3170e93f7393Sniklas }
3171e93f7393Sniklas if (syms == osyms)
3172e93f7393Sniklas break;
3173e93f7393Sniklas }
3174e93f7393Sniklas
3175e93f7393Sniklas return type;
3176e93f7393Sniklas }
3177e93f7393Sniklas
3178e93f7393Sniklas /* Read and internalize a native function debug symbol. */
3179e93f7393Sniklas
3180e93f7393Sniklas static struct type *
hpread_read_function_type(dnttpointer hp_type,union dnttentry * dn_bufp,struct objfile * objfile,int newblock)3181b725ae77Skettenis hpread_read_function_type (dnttpointer hp_type, union dnttentry *dn_bufp,
3182b725ae77Skettenis struct objfile *objfile, int newblock)
3183e93f7393Sniklas {
3184e93f7393Sniklas struct type *type, *type1;
3185b725ae77Skettenis struct pending *syms;
3186b725ae77Skettenis struct pending *local_list = NULL;
3187b725ae77Skettenis int nsyms = 0;
3188e93f7393Sniklas dnttpointer param;
3189e93f7393Sniklas union dnttentry *paramp;
3190e93f7393Sniklas char *name;
3191e93f7393Sniklas long n;
3192e93f7393Sniklas struct symbol *sym;
3193b725ae77Skettenis int record_args = 1;
3194e93f7393Sniklas
3195e93f7393Sniklas /* See if we've already read in this type. */
3196e93f7393Sniklas type = hpread_alloc_type (hp_type, objfile);
3197e93f7393Sniklas if (TYPE_CODE (type) == TYPE_CODE_FUNC)
3198b725ae77Skettenis {
3199b725ae77Skettenis record_args = 0; /* already read in, don't modify type */
3200b725ae77Skettenis }
3201b725ae77Skettenis else
3202b725ae77Skettenis {
3203e93f7393Sniklas /* Nope, so read it in and store it away. */
3204b725ae77Skettenis if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION ||
3205b725ae77Skettenis dn_bufp->dblock.kind == DNTT_TYPE_MEMFUNC)
3206e93f7393Sniklas type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
3207e93f7393Sniklas objfile));
3208b725ae77Skettenis else if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTYPE)
3209b725ae77Skettenis type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
3210b725ae77Skettenis objfile));
3211b725ae77Skettenis else /* expect DNTT_TYPE_FUNC_TEMPLATE */
3212b725ae77Skettenis type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc_template.retval,
3213b725ae77Skettenis objfile));
3214b725ae77Skettenis replace_type (type, type1);
3215e93f7393Sniklas
3216b725ae77Skettenis /* Mark it -- in the middle of processing */
3217b725ae77Skettenis TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE;
3218b725ae77Skettenis }
3219e93f7393Sniklas
3220e93f7393Sniklas /* Now examine each parameter noting its type, location, and a
3221e93f7393Sniklas wealth of other information. */
3222b725ae77Skettenis if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION ||
3223b725ae77Skettenis dn_bufp->dblock.kind == DNTT_TYPE_MEMFUNC)
3224b725ae77Skettenis param = dn_bufp->dfunc.firstparam;
3225b725ae77Skettenis else if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTYPE)
3226b725ae77Skettenis param = dn_bufp->dfunctype.firstparam;
3227b725ae77Skettenis else /* expect DNTT_TYPE_FUNC_TEMPLATE */
3228b725ae77Skettenis param = dn_bufp->dfunc_template.firstparam;
3229e93f7393Sniklas while (param.word && param.word != DNTTNIL)
3230e93f7393Sniklas {
3231e93f7393Sniklas paramp = hpread_get_lntt (param.dnttp.index, objfile);
3232e93f7393Sniklas nsyms++;
3233e93f7393Sniklas param = paramp->dfparam.nextparam;
3234e93f7393Sniklas
3235e93f7393Sniklas /* Get the name. */
3236e93f7393Sniklas name = VT (objfile) + paramp->dfparam.name;
3237b725ae77Skettenis sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
3238e93f7393Sniklas sizeof (struct symbol));
3239e93f7393Sniklas (void) memset (sym, 0, sizeof (struct symbol));
3240b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
3241b725ae77Skettenis &objfile->objfile_obstack);
3242e93f7393Sniklas
3243e93f7393Sniklas /* Figure out where it lives. */
3244e93f7393Sniklas if (paramp->dfparam.regparam)
3245e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_REGPARM;
3246e93f7393Sniklas else if (paramp->dfparam.indirect)
3247e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_REF_ARG;
3248e93f7393Sniklas else
3249e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_ARG;
3250b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
3251e93f7393Sniklas if (paramp->dfparam.copyparam)
3252e93f7393Sniklas {
3253e93f7393Sniklas SYMBOL_VALUE (sym) = paramp->dfparam.location;
3254e93f7393Sniklas SYMBOL_VALUE (sym)
3255*63addd46Skettenis += hpread_adjust_stack_address (CURRENT_FUNCTION_VALUE (objfile));
3256*63addd46Skettenis
3257e93f7393Sniklas /* This is likely a pass-by-invisible reference parameter,
3258e93f7393Sniklas Hack on the symbol class to make GDB happy. */
3259b725ae77Skettenis /* ??rehrauer: This appears to be broken w/r/t to passing
3260b725ae77Skettenis C values of type float and struct. Perhaps this ought
3261b725ae77Skettenis to be highighted as a special case, but for now, just
3262b725ae77Skettenis allowing these to be LOC_ARGs seems to work fine.
3263b725ae77Skettenis */
3264b725ae77Skettenis #if 0
3265e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
3266b725ae77Skettenis #endif
3267e93f7393Sniklas }
3268e93f7393Sniklas else
3269e93f7393Sniklas SYMBOL_VALUE (sym) = paramp->dfparam.location;
3270e93f7393Sniklas
3271e93f7393Sniklas /* Get its type. */
3272e93f7393Sniklas SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
3273b725ae77Skettenis /* Add it to the symbol list. */
3274b725ae77Skettenis /* Note 1 (RT) At the moment, add_symbol_to_list() is also being
3275b725ae77Skettenis * called on FPARAM symbols from the process_one_debug_symbol()
3276b725ae77Skettenis * level... so parameters are getting added twice! (this shows
3277b725ae77Skettenis * up in the symbol dump you get from "maint print symbols ...").
3278b725ae77Skettenis * Note 2 (RT) I took out the processing of FPARAM from the
3279b725ae77Skettenis * process_one_debug_symbol() level, so at the moment parameters are only
3280b725ae77Skettenis * being processed here. This seems to have no ill effect.
3281b725ae77Skettenis */
3282b725ae77Skettenis /* Note 3 (pai/1997-08-11) I removed the add_symbol_to_list() which put
3283b725ae77Skettenis each fparam on the local_symbols list from here. Now we use the
3284b725ae77Skettenis local_list to which fparams are added below, and set the param_symbols
3285b725ae77Skettenis global to point to that at the end of this routine. */
3286b725ae77Skettenis /* elz: I added this new list of symbols which is local to the function.
3287b725ae77Skettenis this list is the one which is actually used to build the type for the
3288b725ae77Skettenis function rather than the gloabal list pointed to by symlist.
3289b725ae77Skettenis Using a global list to keep track of the parameters is wrong, because
3290b725ae77Skettenis this function is called recursively if one parameter happend to be
3291b725ae77Skettenis a function itself with more parameters in it. Adding parameters to the
3292b725ae77Skettenis same global symbol list would not work!
3293b725ae77Skettenis Actually it did work in case of cc compiled programs where you do
3294b725ae77Skettenis not check the parameter lists of the arguments. */
3295b725ae77Skettenis add_symbol_to_list (sym, &local_list);
3296e93f7393Sniklas
3297e93f7393Sniklas }
3298e93f7393Sniklas
3299b725ae77Skettenis /* If type was read in earlier, don't bother with modifying
3300b725ae77Skettenis the type struct */
3301b725ae77Skettenis if (!record_args)
3302b725ae77Skettenis goto finish;
3303b725ae77Skettenis
3304e93f7393Sniklas /* Note how many parameters we found. */
3305e93f7393Sniklas TYPE_NFIELDS (type) = nsyms;
3306e93f7393Sniklas TYPE_FIELDS (type) = (struct field *)
3307b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack,
3308e93f7393Sniklas sizeof (struct field) * nsyms);
3309e93f7393Sniklas
3310b725ae77Skettenis /* Find the symbols for the parameters and
3311b725ae77Skettenis use them to fill parameter-type information into the function-type.
3312b725ae77Skettenis The parameter symbols can be found in the local_list that we just put them on. */
3313e93f7393Sniklas /* Note that we preserve the order of the parameters, so
3314e93f7393Sniklas that in something like "enum {FOO, LAST_THING=FOO}" we print
3315e93f7393Sniklas FOO, not LAST_THING. */
3316b725ae77Skettenis
3317b725ae77Skettenis /* get the parameters types from the local list not the global list
3318b725ae77Skettenis so that the type can be correctly constructed for functions which
3319b725ae77Skettenis have function as parameters */
3320b725ae77Skettenis for (syms = local_list, n = 0; syms; syms = syms->next)
3321e93f7393Sniklas {
3322e93f7393Sniklas int j = 0;
3323b725ae77Skettenis for (j = 0; j < syms->nsyms; j++, n++)
3324e93f7393Sniklas {
3325e93f7393Sniklas struct symbol *xsym = syms->symbol[j];
3326b725ae77Skettenis TYPE_FIELD_NAME (type, n) = DEPRECATED_SYMBOL_NAME (xsym);
3327e93f7393Sniklas TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
3328b725ae77Skettenis TYPE_FIELD_ARTIFICIAL (type, n) = 0;
3329e93f7393Sniklas TYPE_FIELD_BITSIZE (type, n) = 0;
3330b725ae77Skettenis TYPE_FIELD_STATIC_KIND (type, n) = 0;
3331e93f7393Sniklas }
3332e93f7393Sniklas }
3333b725ae77Skettenis /* Mark it as having been processed */
3334b725ae77Skettenis TYPE_FLAGS (type) &= ~(TYPE_FLAG_INCOMPLETE);
3335b725ae77Skettenis
3336b725ae77Skettenis /* Check whether we need to fix-up a class type with this function's type */
3337b725ae77Skettenis if (fixup_class && (fixup_method == type))
3338b725ae77Skettenis {
3339b725ae77Skettenis fixup_class_method_type (fixup_class, fixup_method, objfile);
3340b725ae77Skettenis fixup_class = NULL;
3341b725ae77Skettenis fixup_method = NULL;
3342b725ae77Skettenis }
3343b725ae77Skettenis
3344b725ae77Skettenis /* Set the param list of this level of the context stack
3345b725ae77Skettenis to our local list. Do this only if this function was
3346b725ae77Skettenis called for creating a new block, and not if it was called
3347b725ae77Skettenis simply to get the function type. This prevents recursive
3348b725ae77Skettenis invocations from trashing param_symbols. */
3349b725ae77Skettenis finish:
3350b725ae77Skettenis if (newblock)
3351b725ae77Skettenis param_symbols = local_list;
3352b725ae77Skettenis
3353e93f7393Sniklas return type;
3354e93f7393Sniklas }
3355e93f7393Sniklas
3356b725ae77Skettenis
3357b725ae77Skettenis /* Read and internalize a native DOC function debug symbol. */
3358b725ae77Skettenis /* This is almost identical to hpread_read_function_type(), except
3359b725ae77Skettenis * for references to dn_bufp->ddocfunc instead of db_bufp->dfunc.
3360b725ae77Skettenis * Since debug information for DOC functions is more likely to be
3361b725ae77Skettenis * volatile, please leave it this way.
3362b725ae77Skettenis */
3363b725ae77Skettenis static struct type *
hpread_read_doc_function_type(dnttpointer hp_type,union dnttentry * dn_bufp,struct objfile * objfile,int newblock)3364b725ae77Skettenis hpread_read_doc_function_type (dnttpointer hp_type, union dnttentry *dn_bufp,
3365b725ae77Skettenis struct objfile *objfile, int newblock)
3366b725ae77Skettenis {
3367b725ae77Skettenis struct pending *syms;
3368b725ae77Skettenis struct pending *local_list = NULL;
3369b725ae77Skettenis int nsyms = 0;
3370b725ae77Skettenis struct type *type;
3371b725ae77Skettenis dnttpointer param;
3372b725ae77Skettenis union dnttentry *paramp;
3373b725ae77Skettenis char *name;
3374b725ae77Skettenis long n;
3375b725ae77Skettenis struct symbol *sym;
3376b725ae77Skettenis int record_args = 1;
3377b725ae77Skettenis
3378b725ae77Skettenis /* See if we've already read in this type. */
3379b725ae77Skettenis type = hpread_alloc_type (hp_type, objfile);
3380b725ae77Skettenis if (TYPE_CODE (type) == TYPE_CODE_FUNC)
3381b725ae77Skettenis {
3382b725ae77Skettenis record_args = 0; /* already read in, don't modify type */
3383b725ae77Skettenis }
3384b725ae77Skettenis else
3385b725ae77Skettenis {
3386b725ae77Skettenis struct type *type1 = NULL;
3387b725ae77Skettenis /* Nope, so read it in and store it away. */
3388b725ae77Skettenis if (dn_bufp->dblock.kind == DNTT_TYPE_DOC_FUNCTION ||
3389b725ae77Skettenis dn_bufp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC)
3390b725ae77Skettenis type1 = lookup_function_type (hpread_type_lookup (dn_bufp->ddocfunc.retval,
3391b725ae77Skettenis objfile));
3392b725ae77Skettenis /* NOTE: cagney/2003-03-29: Oh, no not again. TYPE1 is
3393b725ae77Skettenis potentially left undefined here. Assert it isn't and hope
3394b725ae77Skettenis the assert never fails ... */
3395b725ae77Skettenis gdb_assert (type1 != NULL);
3396b725ae77Skettenis
3397b725ae77Skettenis replace_type (type, type1);
3398b725ae77Skettenis
3399b725ae77Skettenis /* Mark it -- in the middle of processing */
3400b725ae77Skettenis TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE;
3401b725ae77Skettenis }
3402b725ae77Skettenis
3403b725ae77Skettenis /* Now examine each parameter noting its type, location, and a
3404b725ae77Skettenis wealth of other information. */
3405b725ae77Skettenis if (dn_bufp->dblock.kind == DNTT_TYPE_DOC_FUNCTION ||
3406b725ae77Skettenis dn_bufp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC)
3407b725ae77Skettenis param = dn_bufp->ddocfunc.firstparam;
3408b725ae77Skettenis while (param.word && param.word != DNTTNIL)
3409b725ae77Skettenis {
3410b725ae77Skettenis paramp = hpread_get_lntt (param.dnttp.index, objfile);
3411b725ae77Skettenis nsyms++;
3412b725ae77Skettenis param = paramp->dfparam.nextparam;
3413b725ae77Skettenis
3414b725ae77Skettenis /* Get the name. */
3415b725ae77Skettenis name = VT (objfile) + paramp->dfparam.name;
3416b725ae77Skettenis sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
3417b725ae77Skettenis sizeof (struct symbol));
3418b725ae77Skettenis (void) memset (sym, 0, sizeof (struct symbol));
3419b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = name;
3420b725ae77Skettenis
3421b725ae77Skettenis /* Figure out where it lives. */
3422b725ae77Skettenis if (paramp->dfparam.regparam)
3423b725ae77Skettenis SYMBOL_CLASS (sym) = LOC_REGPARM;
3424b725ae77Skettenis else if (paramp->dfparam.indirect)
3425b725ae77Skettenis SYMBOL_CLASS (sym) = LOC_REF_ARG;
3426b725ae77Skettenis else
3427b725ae77Skettenis SYMBOL_CLASS (sym) = LOC_ARG;
3428b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
3429b725ae77Skettenis if (paramp->dfparam.copyparam)
3430b725ae77Skettenis {
3431b725ae77Skettenis SYMBOL_VALUE (sym) = paramp->dfparam.location;
3432b725ae77Skettenis SYMBOL_VALUE (sym)
3433*63addd46Skettenis += hpread_adjust_stack_address(CURRENT_FUNCTION_VALUE (objfile));
3434*63addd46Skettenis
3435b725ae77Skettenis /* This is likely a pass-by-invisible reference parameter,
3436b725ae77Skettenis Hack on the symbol class to make GDB happy. */
3437b725ae77Skettenis /* ??rehrauer: This appears to be broken w/r/t to passing
3438b725ae77Skettenis C values of type float and struct. Perhaps this ought
3439b725ae77Skettenis to be highighted as a special case, but for now, just
3440b725ae77Skettenis allowing these to be LOC_ARGs seems to work fine.
3441b725ae77Skettenis */
3442b725ae77Skettenis #if 0
3443b725ae77Skettenis SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
3444b725ae77Skettenis #endif
3445b725ae77Skettenis }
3446b725ae77Skettenis else
3447b725ae77Skettenis SYMBOL_VALUE (sym) = paramp->dfparam.location;
3448b725ae77Skettenis
3449b725ae77Skettenis /* Get its type. */
3450b725ae77Skettenis SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
3451b725ae77Skettenis /* Add it to the symbol list. */
3452b725ae77Skettenis /* Note 1 (RT) At the moment, add_symbol_to_list() is also being
3453b725ae77Skettenis * called on FPARAM symbols from the process_one_debug_symbol()
3454b725ae77Skettenis * level... so parameters are getting added twice! (this shows
3455b725ae77Skettenis * up in the symbol dump you get from "maint print symbols ...").
3456b725ae77Skettenis * Note 2 (RT) I took out the processing of FPARAM from the
3457b725ae77Skettenis * process_one_debug_symbol() level, so at the moment parameters are only
3458b725ae77Skettenis * being processed here. This seems to have no ill effect.
3459b725ae77Skettenis */
3460b725ae77Skettenis /* Note 3 (pai/1997-08-11) I removed the add_symbol_to_list() which put
3461b725ae77Skettenis each fparam on the local_symbols list from here. Now we use the
3462b725ae77Skettenis local_list to which fparams are added below, and set the param_symbols
3463b725ae77Skettenis global to point to that at the end of this routine. */
3464b725ae77Skettenis
3465b725ae77Skettenis /* elz: I added this new list of symbols which is local to the function.
3466b725ae77Skettenis this list is the one which is actually used to build the type for the
3467b725ae77Skettenis function rather than the gloabal list pointed to by symlist.
3468b725ae77Skettenis Using a global list to keep track of the parameters is wrong, because
3469b725ae77Skettenis this function is called recursively if one parameter happend to be
3470b725ae77Skettenis a function itself with more parameters in it. Adding parameters to the
3471b725ae77Skettenis same global symbol list would not work!
3472b725ae77Skettenis Actually it did work in case of cc compiled programs where you do not check the
3473b725ae77Skettenis parameter lists of the arguments. */
3474b725ae77Skettenis add_symbol_to_list (sym, &local_list);
3475b725ae77Skettenis }
3476b725ae77Skettenis
3477b725ae77Skettenis /* If type was read in earlier, don't bother with modifying
3478b725ae77Skettenis the type struct */
3479b725ae77Skettenis if (!record_args)
3480b725ae77Skettenis goto finish;
3481b725ae77Skettenis
3482b725ae77Skettenis /* Note how many parameters we found. */
3483b725ae77Skettenis TYPE_NFIELDS (type) = nsyms;
3484b725ae77Skettenis TYPE_FIELDS (type) = (struct field *)
3485b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack,
3486b725ae77Skettenis sizeof (struct field) * nsyms);
3487b725ae77Skettenis
3488b725ae77Skettenis /* Find the symbols for the parameters and
3489b725ae77Skettenis use them to fill parameter-type information into the function-type.
3490b725ae77Skettenis The parameter symbols can be found in the local_list that we just put them on. */
3491b725ae77Skettenis /* Note that we preserve the order of the parameters, so
3492b725ae77Skettenis that in something like "enum {FOO, LAST_THING=FOO}" we print
3493b725ae77Skettenis FOO, not LAST_THING. */
3494b725ae77Skettenis
3495b725ae77Skettenis /* get the parameters types from the local list not the global list
3496b725ae77Skettenis so that the type can be correctly constructed for functions which
3497b725ae77Skettenis have function as parameters
3498b725ae77Skettenis */
3499b725ae77Skettenis for (syms = local_list, n = 0; syms; syms = syms->next)
3500b725ae77Skettenis {
3501b725ae77Skettenis int j = 0;
3502b725ae77Skettenis for (j = 0; j < syms->nsyms; j++, n++)
3503b725ae77Skettenis {
3504b725ae77Skettenis struct symbol *xsym = syms->symbol[j];
3505b725ae77Skettenis TYPE_FIELD_NAME (type, n) = DEPRECATED_SYMBOL_NAME (xsym);
3506b725ae77Skettenis TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
3507b725ae77Skettenis TYPE_FIELD_ARTIFICIAL (type, n) = 0;
3508b725ae77Skettenis TYPE_FIELD_BITSIZE (type, n) = 0;
3509b725ae77Skettenis TYPE_FIELD_STATIC_KIND (type, n) = 0;
3510b725ae77Skettenis }
3511b725ae77Skettenis }
3512b725ae77Skettenis
3513b725ae77Skettenis /* Mark it as having been processed */
3514b725ae77Skettenis TYPE_FLAGS (type) &= ~(TYPE_FLAG_INCOMPLETE);
3515b725ae77Skettenis
3516b725ae77Skettenis /* Check whether we need to fix-up a class type with this function's type */
3517b725ae77Skettenis if (fixup_class && (fixup_method == type))
3518b725ae77Skettenis {
3519b725ae77Skettenis fixup_class_method_type (fixup_class, fixup_method, objfile);
3520b725ae77Skettenis fixup_class = NULL;
3521b725ae77Skettenis fixup_method = NULL;
3522b725ae77Skettenis }
3523b725ae77Skettenis
3524b725ae77Skettenis /* Set the param list of this level of the context stack
3525b725ae77Skettenis to our local list. Do this only if this function was
3526b725ae77Skettenis called for creating a new block, and not if it was called
3527b725ae77Skettenis simply to get the function type. This prevents recursive
3528b725ae77Skettenis invocations from trashing param_symbols. */
3529b725ae77Skettenis finish:
3530b725ae77Skettenis if (newblock)
3531b725ae77Skettenis param_symbols = local_list;
3532b725ae77Skettenis
3533b725ae77Skettenis return type;
3534b725ae77Skettenis }
3535b725ae77Skettenis
3536b725ae77Skettenis
3537b725ae77Skettenis
3538b725ae77Skettenis /* A file-level variable which keeps track of the current-template
3539b725ae77Skettenis * being processed. Set in hpread_read_struct_type() while processing
3540b725ae77Skettenis * a template type. Referred to in hpread_get_nth_templ_arg().
3541b725ae77Skettenis * Yes, this is a kludge, but it arises from the kludge that already
3542b725ae77Skettenis * exists in symtab.h, namely the fact that they encode
3543b725ae77Skettenis * "template argument n" with fundamental type FT_TEMPLATE_ARG and
3544b725ae77Skettenis * bitlength n. This means that deep in processing fundamental types
3545b725ae77Skettenis * I need to ask the question "what template am I in the middle of?".
3546b725ae77Skettenis * The alternative to stuffing a global would be to pass an argument
3547b725ae77Skettenis * down the chain of calls just for this purpose.
3548b725ae77Skettenis *
3549b725ae77Skettenis * There may be problems handling nested templates... tough.
3550b725ae77Skettenis */
3551b725ae77Skettenis static struct type *current_template = NULL;
3552b725ae77Skettenis
3553b725ae77Skettenis /* Read in and internalize a structure definition.
3554b725ae77Skettenis * This same routine is called for struct, union, and class types.
3555b725ae77Skettenis * Also called for templates, since they build a very similar
3556b725ae77Skettenis * type entry as for class types.
3557b725ae77Skettenis */
3558e93f7393Sniklas
3559e93f7393Sniklas static struct type *
hpread_read_struct_type(dnttpointer hp_type,union dnttentry * dn_bufp,struct objfile * objfile)3560b725ae77Skettenis hpread_read_struct_type (dnttpointer hp_type, union dnttentry *dn_bufp,
3561b725ae77Skettenis struct objfile *objfile)
3562e93f7393Sniklas {
3563b725ae77Skettenis /* The data members get linked together into a list of struct nextfield's */
3564e93f7393Sniklas struct nextfield
3565e93f7393Sniklas {
3566e93f7393Sniklas struct nextfield *next;
3567e93f7393Sniklas struct field field;
3568b725ae77Skettenis unsigned char attributes; /* store visibility and virtuality info */
3569b725ae77Skettenis #define ATTR_VIRTUAL 1
3570b725ae77Skettenis #define ATTR_PRIVATE 2
3571b725ae77Skettenis #define ATTR_PROTECT 3
3572b725ae77Skettenis };
3573b725ae77Skettenis
3574b725ae77Skettenis
3575b725ae77Skettenis /* The methods get linked together into a list of struct next_fn_field's */
3576b725ae77Skettenis struct next_fn_field
3577b725ae77Skettenis {
3578b725ae77Skettenis struct next_fn_field *next;
3579b725ae77Skettenis struct fn_fieldlist field;
3580b725ae77Skettenis struct fn_field fn_field;
3581b725ae77Skettenis int num_fn_fields;
3582b725ae77Skettenis };
3583b725ae77Skettenis
3584b725ae77Skettenis /* The template args get linked together into a list of struct next_template's */
3585b725ae77Skettenis struct next_template
3586b725ae77Skettenis {
3587b725ae77Skettenis struct next_template *next;
3588b725ae77Skettenis struct template_arg arg;
3589b725ae77Skettenis };
3590b725ae77Skettenis
3591b725ae77Skettenis /* The template instantiations get linked together into a list of these... */
3592b725ae77Skettenis struct next_instantiation
3593b725ae77Skettenis {
3594b725ae77Skettenis struct next_instantiation *next;
3595b725ae77Skettenis struct type *t;
3596e93f7393Sniklas };
3597e93f7393Sniklas
3598e93f7393Sniklas struct type *type;
3599b725ae77Skettenis struct type *baseclass;
3600b725ae77Skettenis struct type *memtype;
3601b725ae77Skettenis struct nextfield *list = 0, *tmp_list = 0;
3602b725ae77Skettenis struct next_fn_field *fn_list = 0;
3603b725ae77Skettenis struct next_fn_field *fn_p;
3604b725ae77Skettenis struct next_template *t_new, *t_list = 0;
3605e93f7393Sniklas struct nextfield *new;
3606b725ae77Skettenis struct next_fn_field *fn_new;
3607b725ae77Skettenis struct next_instantiation *i_new, *i_list = 0;
3608b725ae77Skettenis int n, nfields = 0, n_fn_fields = 0, n_fn_fields_total = 0;
3609b725ae77Skettenis int n_base_classes = 0, n_templ_args = 0;
3610b725ae77Skettenis int ninstantiations = 0;
3611b725ae77Skettenis dnttpointer field, fn_field, parent;
3612b725ae77Skettenis union dnttentry *fieldp, *fn_fieldp, *parentp;
3613b725ae77Skettenis int i;
3614b725ae77Skettenis int static_member = 0;
3615b725ae77Skettenis int const_member = 0;
3616b725ae77Skettenis int volatile_member = 0;
3617b725ae77Skettenis unsigned long vtbl_offset;
3618b725ae77Skettenis int need_bitvectors = 0;
3619b725ae77Skettenis char *method_name = NULL;
3620b725ae77Skettenis char *method_alias = NULL;
3621b725ae77Skettenis
3622e93f7393Sniklas
3623e93f7393Sniklas /* Is it something we've already dealt with? */
3624e93f7393Sniklas type = hpread_alloc_type (hp_type, objfile);
3625e93f7393Sniklas if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
3626b725ae77Skettenis (TYPE_CODE (type) == TYPE_CODE_UNION) ||
3627b725ae77Skettenis (TYPE_CODE (type) == TYPE_CODE_CLASS) ||
3628b725ae77Skettenis (TYPE_CODE (type) == TYPE_CODE_TEMPLATE))
3629e93f7393Sniklas return type;
3630e93f7393Sniklas
3631e93f7393Sniklas /* Get the basic type correct. */
3632e93f7393Sniklas if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
3633e93f7393Sniklas {
3634e93f7393Sniklas TYPE_CODE (type) = TYPE_CODE_STRUCT;
3635e93f7393Sniklas TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
3636e93f7393Sniklas }
3637e93f7393Sniklas else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
3638e93f7393Sniklas {
3639e93f7393Sniklas TYPE_CODE (type) = TYPE_CODE_UNION;
3640e93f7393Sniklas TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
3641e93f7393Sniklas }
3642b725ae77Skettenis else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
3643b725ae77Skettenis {
3644b725ae77Skettenis TYPE_CODE (type) = TYPE_CODE_CLASS;
3645b725ae77Skettenis TYPE_LENGTH (type) = dn_bufp->dclass.bitlength / 8;
3646b725ae77Skettenis
3647b725ae77Skettenis /* Overrides the TYPE_CPLUS_SPECIFIC(type) with allocated memory
3648b725ae77Skettenis * rather than &cplus_struct_default.
3649b725ae77Skettenis */
3650b725ae77Skettenis allocate_cplus_struct_type (type);
3651b725ae77Skettenis
3652b725ae77Skettenis /* Fill in declared-type.
3653b725ae77Skettenis * (The C++ compiler will emit TYPE_CODE_CLASS
3654b725ae77Skettenis * for all 3 of "class", "struct"
3655b725ae77Skettenis * "union", and we have to look at the "class_decl" field if we
3656b725ae77Skettenis * want to know how it was really declared)
3657b725ae77Skettenis */
3658b725ae77Skettenis /* (0==class, 1==union, 2==struct) */
3659b725ae77Skettenis TYPE_DECLARED_TYPE (type) = dn_bufp->dclass.class_decl;
3660b725ae77Skettenis }
3661b725ae77Skettenis else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
3662b725ae77Skettenis {
3663b725ae77Skettenis /* Get the basic type correct. */
3664b725ae77Skettenis TYPE_CODE (type) = TYPE_CODE_TEMPLATE;
3665b725ae77Skettenis allocate_cplus_struct_type (type);
3666b725ae77Skettenis TYPE_DECLARED_TYPE (type) = DECLARED_TYPE_TEMPLATE;
3667b725ae77Skettenis }
3668e93f7393Sniklas else
3669e93f7393Sniklas return type;
3670e93f7393Sniklas
3671e93f7393Sniklas
3672e93f7393Sniklas TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
3673e93f7393Sniklas
3674b725ae77Skettenis /* For classes, read the parent list.
3675b725ae77Skettenis * Question (RT): Do we need to do this for templates also?
3676b725ae77Skettenis */
3677b725ae77Skettenis if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
3678b725ae77Skettenis {
3679b725ae77Skettenis
3680b725ae77Skettenis /* First read the parent-list (classes from which we derive fields) */
3681b725ae77Skettenis parent = dn_bufp->dclass.parentlist;
3682b725ae77Skettenis while (parent.word && parent.word != DNTTNIL)
3683b725ae77Skettenis {
3684b725ae77Skettenis parentp = hpread_get_lntt (parent.dnttp.index, objfile);
3685b725ae77Skettenis
3686b725ae77Skettenis /* "parentp" should point to a DNTT_TYPE_INHERITANCE record */
3687b725ae77Skettenis
3688b725ae77Skettenis /* Get space to record the next field/data-member. */
3689b725ae77Skettenis new = (struct nextfield *) alloca (sizeof (struct nextfield));
3690*63addd46Skettenis memset (new, 0, sizeof (struct nextfield));
3691b725ae77Skettenis new->next = list;
3692b725ae77Skettenis list = new;
3693b725ae77Skettenis
3694b725ae77Skettenis FIELD_BITSIZE (list->field) = 0;
3695b725ae77Skettenis FIELD_STATIC_KIND (list->field) = 0;
3696b725ae77Skettenis
3697b725ae77Skettenis /* The "classname" field is actually a DNTT pointer to the base class */
3698b725ae77Skettenis baseclass = hpread_type_lookup (parentp->dinheritance.classname,
3699b725ae77Skettenis objfile);
3700b725ae77Skettenis FIELD_TYPE (list->field) = baseclass;
3701b725ae77Skettenis
3702b725ae77Skettenis list->field.name = type_name_no_tag (FIELD_TYPE (list->field));
3703b725ae77Skettenis
3704b725ae77Skettenis list->attributes = 0;
3705b725ae77Skettenis
3706b725ae77Skettenis /* Check for virtuality of base, and set the
3707b725ae77Skettenis * offset of the base subobject within the object.
3708b725ae77Skettenis * (Offset set to -1 for virtual bases (for now).)
3709b725ae77Skettenis */
3710b725ae77Skettenis if (parentp->dinheritance.Virtual)
3711b725ae77Skettenis {
3712b725ae77Skettenis B_SET (&(list->attributes), ATTR_VIRTUAL);
3713b725ae77Skettenis parentp->dinheritance.offset = -1;
3714b725ae77Skettenis }
3715b725ae77Skettenis else
3716b725ae77Skettenis FIELD_BITPOS (list->field) = parentp->dinheritance.offset;
3717b725ae77Skettenis
3718b725ae77Skettenis /* Check visibility */
3719b725ae77Skettenis switch (parentp->dinheritance.visibility)
3720b725ae77Skettenis {
3721b725ae77Skettenis case 1:
3722b725ae77Skettenis B_SET (&(list->attributes), ATTR_PROTECT);
3723b725ae77Skettenis break;
3724b725ae77Skettenis case 2:
3725b725ae77Skettenis B_SET (&(list->attributes), ATTR_PRIVATE);
3726b725ae77Skettenis break;
3727b725ae77Skettenis }
3728b725ae77Skettenis
3729b725ae77Skettenis n_base_classes++;
3730b725ae77Skettenis nfields++;
3731b725ae77Skettenis
3732b725ae77Skettenis parent = parentp->dinheritance.next;
3733b725ae77Skettenis }
3734b725ae77Skettenis }
3735b725ae77Skettenis
3736b725ae77Skettenis /* For templates, read the template argument list.
3737b725ae77Skettenis * This must be done before processing the member list, because
3738b725ae77Skettenis * the member list may refer back to this. E.g.:
3739b725ae77Skettenis * template <class T1, class T2> class q2 {
3740b725ae77Skettenis * public:
3741b725ae77Skettenis * T1 a;
3742b725ae77Skettenis * T2 b;
3743b725ae77Skettenis * };
3744b725ae77Skettenis * We need to read the argument list "T1", "T2" first.
3745b725ae77Skettenis */
3746b725ae77Skettenis if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
3747b725ae77Skettenis {
3748b725ae77Skettenis /* Kludge alert: This stuffs a global "current_template" which
3749b725ae77Skettenis * is referred to by hpread_get_nth_templ_arg(). The global
3750b725ae77Skettenis * is cleared at the end of this routine.
3751b725ae77Skettenis */
3752b725ae77Skettenis current_template = type;
3753b725ae77Skettenis
3754b725ae77Skettenis /* Read in the argument list */
3755b725ae77Skettenis field = dn_bufp->dtemplate.arglist;
3756b725ae77Skettenis while (field.word && field.word != DNTTNIL)
3757b725ae77Skettenis {
3758b725ae77Skettenis /* Get this template argument */
3759b725ae77Skettenis fieldp = hpread_get_lntt (field.dnttp.index, objfile);
3760b725ae77Skettenis if (fieldp->dblock.kind != DNTT_TYPE_TEMPLATE_ARG)
3761b725ae77Skettenis {
3762b725ae77Skettenis warning ("Invalid debug info: Template argument entry is of wrong kind");
3763b725ae77Skettenis break;
3764b725ae77Skettenis }
3765b725ae77Skettenis /* Bump the count */
3766b725ae77Skettenis n_templ_args++;
3767b725ae77Skettenis /* Allocate and fill in a struct next_template */
3768b725ae77Skettenis t_new = (struct next_template *) alloca (sizeof (struct next_template));
3769*63addd46Skettenis memset (t_new, 0, sizeof (struct next_template));
3770b725ae77Skettenis t_new->next = t_list;
3771b725ae77Skettenis t_list = t_new;
3772b725ae77Skettenis t_list->arg.name = VT (objfile) + fieldp->dtempl_arg.name;
3773b725ae77Skettenis t_list->arg.type = hpread_read_templ_arg_type (field, fieldp,
3774b725ae77Skettenis objfile, t_list->arg.name);
3775b725ae77Skettenis /* Walk to the next template argument */
3776b725ae77Skettenis field = fieldp->dtempl_arg.nextarg;
3777b725ae77Skettenis }
3778b725ae77Skettenis }
3779b725ae77Skettenis
3780b725ae77Skettenis TYPE_NTEMPLATE_ARGS (type) = n_templ_args;
3781b725ae77Skettenis
3782b725ae77Skettenis if (n_templ_args > 0)
3783b725ae77Skettenis TYPE_TEMPLATE_ARGS (type) = (struct template_arg *)
3784b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack, sizeof (struct template_arg) * n_templ_args);
3785b725ae77Skettenis for (n = n_templ_args; t_list; t_list = t_list->next)
3786b725ae77Skettenis {
3787b725ae77Skettenis n -= 1;
3788b725ae77Skettenis TYPE_TEMPLATE_ARG (type, n) = t_list->arg;
3789b725ae77Skettenis }
3790b725ae77Skettenis
3791b725ae77Skettenis /* Next read in and internalize all the fields/members. */
3792b725ae77Skettenis if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
3793e93f7393Sniklas field = dn_bufp->dstruct.firstfield;
3794b725ae77Skettenis else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
3795b725ae77Skettenis field = dn_bufp->dunion.firstfield;
3796b725ae77Skettenis else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
3797b725ae77Skettenis field = dn_bufp->dclass.memberlist;
3798b725ae77Skettenis else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
3799b725ae77Skettenis field = dn_bufp->dtemplate.memberlist;
3800b725ae77Skettenis else
3801b725ae77Skettenis field.word = DNTTNIL;
3802b725ae77Skettenis
3803b725ae77Skettenis while (field.word && field.word != DNTTNIL)
3804e93f7393Sniklas {
3805e93f7393Sniklas fieldp = hpread_get_lntt (field.dnttp.index, objfile);
3806e93f7393Sniklas
3807b725ae77Skettenis /* At this point "fieldp" may point to either a DNTT_TYPE_FIELD
3808b725ae77Skettenis * or a DNTT_TYPE_GENFIELD record.
3809b725ae77Skettenis */
3810b725ae77Skettenis vtbl_offset = 0;
3811b725ae77Skettenis static_member = 0;
3812b725ae77Skettenis const_member = 0;
3813b725ae77Skettenis volatile_member = 0;
3814b725ae77Skettenis
3815b725ae77Skettenis if (fieldp->dblock.kind == DNTT_TYPE_GENFIELD)
3816b725ae77Skettenis {
3817b725ae77Skettenis
3818b725ae77Skettenis /* The type will be GENFIELD if the field is a method or
3819b725ae77Skettenis * a static member (or some other cases -- see below)
3820b725ae77Skettenis */
3821b725ae77Skettenis
3822b725ae77Skettenis /* Follow a link to get to the record for the field. */
3823b725ae77Skettenis fn_field = fieldp->dgenfield.field;
3824b725ae77Skettenis fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile);
3825b725ae77Skettenis
3826b725ae77Skettenis /* Virtual funcs are indicated by a VFUNC which points to the
3827b725ae77Skettenis * real entry
3828b725ae77Skettenis */
3829b725ae77Skettenis if (fn_fieldp->dblock.kind == DNTT_TYPE_VFUNC)
3830b725ae77Skettenis {
3831b725ae77Skettenis vtbl_offset = fn_fieldp->dvfunc.vtbl_offset;
3832b725ae77Skettenis fn_field = fn_fieldp->dvfunc.funcptr;
3833b725ae77Skettenis fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile);
3834b725ae77Skettenis }
3835b725ae77Skettenis
3836b725ae77Skettenis /* A function's entry may be preceded by a modifier which
3837b725ae77Skettenis * labels it static/constant/volatile.
3838b725ae77Skettenis */
3839b725ae77Skettenis if (fn_fieldp->dblock.kind == DNTT_TYPE_MODIFIER)
3840b725ae77Skettenis {
3841b725ae77Skettenis static_member = fn_fieldp->dmodifier.m_static;
3842b725ae77Skettenis const_member = fn_fieldp->dmodifier.m_const;
3843b725ae77Skettenis volatile_member = fn_fieldp->dmodifier.m_volatile;
3844b725ae77Skettenis fn_field = fn_fieldp->dmodifier.type;
3845b725ae77Skettenis fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile);
3846b725ae77Skettenis }
3847b725ae77Skettenis
3848b725ae77Skettenis /* Check whether we have a method */
3849b725ae77Skettenis if ((fn_fieldp->dblock.kind == DNTT_TYPE_MEMFUNC) ||
3850b725ae77Skettenis (fn_fieldp->dblock.kind == DNTT_TYPE_FUNCTION) ||
3851b725ae77Skettenis (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC) ||
3852b725ae77Skettenis (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_FUNCTION))
3853b725ae77Skettenis {
3854b725ae77Skettenis /* Method found */
3855b725ae77Skettenis
3856b725ae77Skettenis short ix = 0;
3857b725ae77Skettenis
3858b725ae77Skettenis /* Look up function type of method */
3859b725ae77Skettenis memtype = hpread_type_lookup (fn_field, objfile);
3860b725ae77Skettenis
3861b725ae77Skettenis /* Methods can be seen before classes in the SOM records.
3862b725ae77Skettenis If we are processing this class because it's a parameter of a
3863b725ae77Skettenis method, at this point the method's type is actually incomplete;
3864b725ae77Skettenis we'll have to fix it up later; mark the class for this. */
3865b725ae77Skettenis
3866b725ae77Skettenis if (TYPE_INCOMPLETE (memtype))
3867b725ae77Skettenis {
3868b725ae77Skettenis TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE;
3869b725ae77Skettenis if (fixup_class)
3870b725ae77Skettenis warning ("Two classes to fix up for method?? Type information may be incorrect for some classes.");
3871b725ae77Skettenis if (fixup_method)
3872b725ae77Skettenis warning ("Two methods to be fixed up at once?? Type information may be incorrect for some classes.");
3873b725ae77Skettenis fixup_class = type; /* remember this class has to be fixed up */
3874b725ae77Skettenis fixup_method = memtype; /* remember the method type to be used in fixup */
3875b725ae77Skettenis }
3876b725ae77Skettenis
3877b725ae77Skettenis /* HP aCC generates operator names without the "operator" keyword, and
3878b725ae77Skettenis generates null strings as names for operators that are
3879b725ae77Skettenis user-defined type conversions to basic types (e.g. operator int ()).
3880b725ae77Skettenis So try to reconstruct name as best as possible. */
3881b725ae77Skettenis
3882b725ae77Skettenis method_name = (char *) (VT (objfile) + fn_fieldp->dfunc.name);
3883b725ae77Skettenis method_alias = (char *) (VT (objfile) + fn_fieldp->dfunc.alias);
3884b725ae77Skettenis
3885b725ae77Skettenis if (!method_name || /* no name */
3886b725ae77Skettenis !*method_name || /* or null name */
3887b725ae77Skettenis cplus_mangle_opname (method_name, DMGL_ANSI)) /* or name is an operator like "<" */
3888b725ae77Skettenis {
3889b725ae77Skettenis char *tmp_name = cplus_demangle (method_alias, DMGL_ANSI);
3890b725ae77Skettenis char *op_string = strstr (tmp_name, "operator");
3891b725ae77Skettenis method_name = xmalloc (strlen (op_string) + 1); /* don't overwrite VT! */
3892b725ae77Skettenis strcpy (method_name, op_string);
3893b725ae77Skettenis }
3894b725ae77Skettenis
3895b725ae77Skettenis /* First check if a method of the same name has already been seen. */
3896b725ae77Skettenis fn_p = fn_list;
3897b725ae77Skettenis while (fn_p)
3898b725ae77Skettenis {
3899b725ae77Skettenis if (DEPRECATED_STREQ (fn_p->field.name, method_name))
3900b725ae77Skettenis break;
3901b725ae77Skettenis fn_p = fn_p->next;
3902b725ae77Skettenis }
3903b725ae77Skettenis
3904b725ae77Skettenis /* If no such method was found, allocate a new entry in the list */
3905b725ae77Skettenis if (!fn_p)
3906b725ae77Skettenis {
3907b725ae77Skettenis /* Get space to record this member function */
3908b725ae77Skettenis /* Note: alloca used; this will disappear on routine exit */
3909b725ae77Skettenis fn_new = (struct next_fn_field *) alloca (sizeof (struct next_fn_field));
3910*63addd46Skettenis memset (fn_new, 0, sizeof (struct next_fn_field));
3911b725ae77Skettenis fn_new->next = fn_list;
3912b725ae77Skettenis fn_list = fn_new;
3913b725ae77Skettenis
3914b725ae77Skettenis /* Fill in the fields of the struct nextfield */
3915b725ae77Skettenis
3916b725ae77Skettenis /* Record the (unmangled) method name */
3917b725ae77Skettenis fn_list->field.name = method_name;
3918b725ae77Skettenis /* Initial space for overloaded methods */
3919b725ae77Skettenis /* Note: xmalloc is used; this will persist after this routine exits */
3920b725ae77Skettenis fn_list->field.fn_fields = (struct fn_field *) xmalloc (5 * (sizeof (struct fn_field)));
3921b725ae77Skettenis fn_list->field.length = 1; /* Init # of overloaded instances */
3922b725ae77Skettenis fn_list->num_fn_fields = 5; /* # of entries for which space allocated */
3923b725ae77Skettenis fn_p = fn_list;
3924b725ae77Skettenis ix = 0; /* array index for fn_field */
3925b725ae77Skettenis /* Bump the total count of the distinctly named methods */
3926b725ae77Skettenis n_fn_fields++;
3927b725ae77Skettenis }
3928b725ae77Skettenis else
3929b725ae77Skettenis /* Another overloaded instance of an already seen method name */
3930b725ae77Skettenis {
3931b725ae77Skettenis if (++(fn_p->field.length) > fn_p->num_fn_fields)
3932b725ae77Skettenis {
3933b725ae77Skettenis /* Increase space allocated for overloaded instances */
3934b725ae77Skettenis fn_p->field.fn_fields
3935b725ae77Skettenis = (struct fn_field *) xrealloc (fn_p->field.fn_fields,
3936b725ae77Skettenis (fn_p->num_fn_fields + 5) * sizeof (struct fn_field));
3937b725ae77Skettenis fn_p->num_fn_fields += 5;
3938b725ae77Skettenis }
3939b725ae77Skettenis ix = fn_p->field.length - 1; /* array index for fn_field */
3940b725ae77Skettenis }
3941b725ae77Skettenis
3942b725ae77Skettenis /* "physname" is intended to be the name of this overloaded instance. */
3943b725ae77Skettenis if ((fn_fieldp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) &&
3944b725ae77Skettenis method_alias &&
3945b725ae77Skettenis *method_alias) /* not a null string */
3946b725ae77Skettenis fn_p->field.fn_fields[ix].physname = method_alias;
3947b725ae77Skettenis else
3948b725ae77Skettenis fn_p->field.fn_fields[ix].physname = method_name;
3949b725ae77Skettenis /* What's expected here is the function type */
3950b725ae77Skettenis /* But mark it as NULL if the method was incompletely processed
3951b725ae77Skettenis We'll fix this up later when the method is fully processed */
3952b725ae77Skettenis if (TYPE_INCOMPLETE (memtype))
3953b725ae77Skettenis fn_p->field.fn_fields[ix].type = NULL;
3954b725ae77Skettenis else
3955b725ae77Skettenis fn_p->field.fn_fields[ix].type = memtype;
3956b725ae77Skettenis
3957b725ae77Skettenis /* For virtual functions, fill in the voffset field with the
3958b725ae77Skettenis * virtual table offset. (This is just copied over from the
3959b725ae77Skettenis * SOM record; not sure if it is what GDB expects here...).
3960b725ae77Skettenis * But if the function is a static method, set it to 1.
3961b725ae77Skettenis *
3962b725ae77Skettenis * Note that we have to add 1 because 1 indicates a static
3963b725ae77Skettenis * method, and 0 indicates a non-static, non-virtual method */
3964b725ae77Skettenis
3965b725ae77Skettenis if (static_member)
3966b725ae77Skettenis fn_p->field.fn_fields[ix].voffset = VOFFSET_STATIC;
3967b725ae77Skettenis else
3968b725ae77Skettenis fn_p->field.fn_fields[ix].voffset = vtbl_offset ? vtbl_offset + 1 : 0;
3969b725ae77Skettenis
3970b725ae77Skettenis /* Also fill in the fcontext field with the current
3971b725ae77Skettenis * class. (The latter isn't quite right: should be the baseclass
3972b725ae77Skettenis * that defines the virtual function... Note we do have
3973b725ae77Skettenis * a variable "baseclass" that we could stuff into the fcontext
3974b725ae77Skettenis * field, but "baseclass" isn't necessarily right either,
3975b725ae77Skettenis * since the virtual function could have been defined more
3976b725ae77Skettenis * than one level up).
3977b725ae77Skettenis */
3978b725ae77Skettenis
3979b725ae77Skettenis if (vtbl_offset != 0)
3980b725ae77Skettenis fn_p->field.fn_fields[ix].fcontext = type;
3981b725ae77Skettenis else
3982b725ae77Skettenis fn_p->field.fn_fields[ix].fcontext = NULL;
3983b725ae77Skettenis
3984b725ae77Skettenis /* Other random fields pertaining to this method */
3985b725ae77Skettenis fn_p->field.fn_fields[ix].is_const = const_member;
3986b725ae77Skettenis fn_p->field.fn_fields[ix].is_volatile = volatile_member; /* ?? */
3987b725ae77Skettenis switch (fieldp->dgenfield.visibility)
3988b725ae77Skettenis {
3989b725ae77Skettenis case 1:
3990b725ae77Skettenis fn_p->field.fn_fields[ix].is_protected = 1;
3991b725ae77Skettenis fn_p->field.fn_fields[ix].is_private = 0;
3992b725ae77Skettenis break;
3993b725ae77Skettenis case 2:
3994b725ae77Skettenis fn_p->field.fn_fields[ix].is_protected = 0;
3995b725ae77Skettenis fn_p->field.fn_fields[ix].is_private = 1;
3996b725ae77Skettenis break;
3997b725ae77Skettenis default: /* public */
3998b725ae77Skettenis fn_p->field.fn_fields[ix].is_protected = 0;
3999b725ae77Skettenis fn_p->field.fn_fields[ix].is_private = 0;
4000b725ae77Skettenis }
4001b725ae77Skettenis fn_p->field.fn_fields[ix].is_stub = 0;
4002b725ae77Skettenis
4003b725ae77Skettenis /* HP aCC emits both MEMFUNC and FUNCTION entries for a method;
4004b725ae77Skettenis if the class points to the FUNCTION, there is usually separate
4005b725ae77Skettenis code for the method; but if we have a MEMFUNC, the method has
4006b725ae77Skettenis been inlined (and there is usually no FUNCTION entry)
4007b725ae77Skettenis FIXME Not sure if this test is accurate. pai/1997-08-22 */
4008b725ae77Skettenis if ((fn_fieldp->dblock.kind == DNTT_TYPE_MEMFUNC) ||
4009b725ae77Skettenis (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC))
4010b725ae77Skettenis fn_p->field.fn_fields[ix].is_inlined = 1;
4011b725ae77Skettenis else
4012b725ae77Skettenis fn_p->field.fn_fields[ix].is_inlined = 0;
4013b725ae77Skettenis
4014b725ae77Skettenis fn_p->field.fn_fields[ix].dummy = 0;
4015b725ae77Skettenis
4016b725ae77Skettenis /* Bump the total count of the member functions */
4017b725ae77Skettenis n_fn_fields_total++;
4018b725ae77Skettenis
4019b725ae77Skettenis }
4020b725ae77Skettenis else if (fn_fieldp->dblock.kind == DNTT_TYPE_SVAR)
4021b725ae77Skettenis {
4022b725ae77Skettenis /* This case is for static data members of classes */
4023b725ae77Skettenis
4024b725ae77Skettenis /* pai:: FIXME -- check that "staticmem" bit is set */
4025b725ae77Skettenis
4026b725ae77Skettenis /* Get space to record this static member */
4027b725ae77Skettenis new = (struct nextfield *) alloca (sizeof (struct nextfield));
4028*63addd46Skettenis memset (new, 0, sizeof (struct nextfield));
4029b725ae77Skettenis new->next = list;
4030b725ae77Skettenis list = new;
4031b725ae77Skettenis
4032b725ae77Skettenis list->field.name = VT (objfile) + fn_fieldp->dsvar.name;
4033b725ae77Skettenis SET_FIELD_PHYSNAME (list->field, 0); /* initialize to empty */
4034b725ae77Skettenis memtype = hpread_type_lookup (fn_fieldp->dsvar.type, objfile);
4035b725ae77Skettenis
4036b725ae77Skettenis FIELD_TYPE (list->field) = memtype;
4037b725ae77Skettenis list->attributes = 0;
4038b725ae77Skettenis switch (fieldp->dgenfield.visibility)
4039b725ae77Skettenis {
4040b725ae77Skettenis case 1:
4041b725ae77Skettenis B_SET (&(list->attributes), ATTR_PROTECT);
4042b725ae77Skettenis break;
4043b725ae77Skettenis case 2:
4044b725ae77Skettenis B_SET (&(list->attributes), ATTR_PRIVATE);
4045b725ae77Skettenis break;
4046b725ae77Skettenis }
4047b725ae77Skettenis nfields++;
4048b725ae77Skettenis }
4049b725ae77Skettenis
4050b725ae77Skettenis else if (fn_fieldp->dblock.kind == DNTT_TYPE_FIELD)
4051b725ae77Skettenis {
4052b725ae77Skettenis /* FIELDs follow GENFIELDs for fields of anonymous unions.
4053b725ae77Skettenis Code below is replicated from the case for FIELDs further
4054b725ae77Skettenis below, except that fieldp is replaced by fn_fieldp */
4055b725ae77Skettenis if (!fn_fieldp->dfield.a_union)
4056b725ae77Skettenis warning ("Debug info inconsistent: FIELD of anonymous union doesn't have a_union bit set");
4057b725ae77Skettenis /* Get space to record the next field/data-member. */
4058b725ae77Skettenis new = (struct nextfield *) alloca (sizeof (struct nextfield));
4059*63addd46Skettenis memset (new, 0, sizeof (struct nextfield));
4060b725ae77Skettenis new->next = list;
4061b725ae77Skettenis list = new;
4062b725ae77Skettenis
4063b725ae77Skettenis list->field.name = VT (objfile) + fn_fieldp->dfield.name;
4064b725ae77Skettenis FIELD_BITPOS (list->field) = fn_fieldp->dfield.bitoffset;
4065b725ae77Skettenis if (fn_fieldp->dfield.bitlength % 8)
4066b725ae77Skettenis list->field.bitsize = fn_fieldp->dfield.bitlength;
4067b725ae77Skettenis else
4068b725ae77Skettenis list->field.bitsize = 0;
4069b725ae77Skettenis
4070b725ae77Skettenis memtype = hpread_type_lookup (fn_fieldp->dfield.type, objfile);
4071b725ae77Skettenis list->field.type = memtype;
4072b725ae77Skettenis list->attributes = 0;
4073b725ae77Skettenis switch (fn_fieldp->dfield.visibility)
4074b725ae77Skettenis {
4075b725ae77Skettenis case 1:
4076b725ae77Skettenis B_SET (&(list->attributes), ATTR_PROTECT);
4077b725ae77Skettenis break;
4078b725ae77Skettenis case 2:
4079b725ae77Skettenis B_SET (&(list->attributes), ATTR_PRIVATE);
4080b725ae77Skettenis break;
4081b725ae77Skettenis }
4082b725ae77Skettenis nfields++;
4083b725ae77Skettenis }
4084b725ae77Skettenis else if (fn_fieldp->dblock.kind == DNTT_TYPE_SVAR)
4085b725ae77Skettenis {
4086b725ae77Skettenis /* Field of anonymous union; union is not inside a class */
4087b725ae77Skettenis if (!fn_fieldp->dsvar.a_union)
4088b725ae77Skettenis warning ("Debug info inconsistent: SVAR field in anonymous union doesn't have a_union bit set");
4089b725ae77Skettenis /* Get space to record the next field/data-member. */
4090b725ae77Skettenis new = (struct nextfield *) alloca (sizeof (struct nextfield));
4091*63addd46Skettenis memset (new, 0, sizeof (struct nextfield));
4092b725ae77Skettenis new->next = list;
4093b725ae77Skettenis list = new;
4094b725ae77Skettenis
4095b725ae77Skettenis list->field.name = VT (objfile) + fn_fieldp->dsvar.name;
4096b725ae77Skettenis FIELD_BITPOS (list->field) = 0; /* FIXME is this always true? */
4097b725ae77Skettenis FIELD_BITSIZE (list->field) = 0; /* use length from type */
4098b725ae77Skettenis FIELD_STATIC_KIND (list->field) = 0;
4099b725ae77Skettenis memtype = hpread_type_lookup (fn_fieldp->dsvar.type, objfile);
4100b725ae77Skettenis list->field.type = memtype;
4101b725ae77Skettenis list->attributes = 0;
4102b725ae77Skettenis /* No info to set visibility -- always public */
4103b725ae77Skettenis nfields++;
4104b725ae77Skettenis }
4105b725ae77Skettenis else if (fn_fieldp->dblock.kind == DNTT_TYPE_DVAR)
4106b725ae77Skettenis {
4107b725ae77Skettenis /* Field of anonymous union; union is not inside a class */
4108b725ae77Skettenis if (!fn_fieldp->ddvar.a_union)
4109b725ae77Skettenis warning ("Debug info inconsistent: DVAR field in anonymous union doesn't have a_union bit set");
4110b725ae77Skettenis /* Get space to record the next field/data-member. */
4111b725ae77Skettenis new = (struct nextfield *) alloca (sizeof (struct nextfield));
4112*63addd46Skettenis memset (new, 0, sizeof (struct nextfield));
4113b725ae77Skettenis new->next = list;
4114b725ae77Skettenis list = new;
4115b725ae77Skettenis
4116b725ae77Skettenis list->field.name = VT (objfile) + fn_fieldp->ddvar.name;
4117b725ae77Skettenis FIELD_BITPOS (list->field) = 0; /* FIXME is this always true? */
4118b725ae77Skettenis FIELD_BITSIZE (list->field) = 0; /* use length from type */
4119b725ae77Skettenis FIELD_STATIC_KIND (list->field) = 0;
4120b725ae77Skettenis memtype = hpread_type_lookup (fn_fieldp->ddvar.type, objfile);
4121b725ae77Skettenis list->field.type = memtype;
4122b725ae77Skettenis list->attributes = 0;
4123b725ae77Skettenis /* No info to set visibility -- always public */
4124b725ae77Skettenis nfields++;
4125b725ae77Skettenis }
4126b725ae77Skettenis else
4127b725ae77Skettenis { /* Not a method, nor a static data member, nor an anon union field */
4128b725ae77Skettenis
4129b725ae77Skettenis /* This case is for miscellaneous type entries (local enums,
4130b725ae77Skettenis local function templates, etc.) that can be present
4131b725ae77Skettenis inside a class. */
4132b725ae77Skettenis
4133b725ae77Skettenis /* Enums -- will be handled by other code that takes care
4134b725ae77Skettenis of DNTT_TYPE_ENUM; here we see only DNTT_TYPE_MEMENUM so
4135b725ae77Skettenis it's not clear we could have handled them here at all. */
4136b725ae77Skettenis /* FUNC_TEMPLATE: is handled by other code (?). */
4137b725ae77Skettenis /* MEMACCESS: modified access for inherited member. Not
4138b725ae77Skettenis sure what to do with this, ignoriing it at present. */
4139b725ae77Skettenis
4140b725ae77Skettenis /* What other entries can appear following a GENFIELD which
4141b725ae77Skettenis we do not handle above? (MODIFIER, VFUNC handled above.) */
4142b725ae77Skettenis
4143b725ae77Skettenis if ((fn_fieldp->dblock.kind != DNTT_TYPE_MEMACCESS) &&
4144b725ae77Skettenis (fn_fieldp->dblock.kind != DNTT_TYPE_MEMENUM) &&
4145b725ae77Skettenis (fn_fieldp->dblock.kind != DNTT_TYPE_FUNC_TEMPLATE))
4146b725ae77Skettenis warning ("Internal error: Unexpected debug record kind %d found following DNTT_GENFIELD",
4147b725ae77Skettenis fn_fieldp->dblock.kind);
4148b725ae77Skettenis }
4149b725ae77Skettenis /* walk to the next FIELD or GENFIELD */
4150b725ae77Skettenis field = fieldp->dgenfield.nextfield;
4151b725ae77Skettenis
4152b725ae77Skettenis }
4153b725ae77Skettenis else if (fieldp->dblock.kind == DNTT_TYPE_FIELD)
4154b725ae77Skettenis {
4155b725ae77Skettenis
4156b725ae77Skettenis /* Ordinary structure/union/class field */
4157b725ae77Skettenis struct type *anon_union_type;
4158b725ae77Skettenis
4159b725ae77Skettenis /* Get space to record the next field/data-member. */
4160e93f7393Sniklas new = (struct nextfield *) alloca (sizeof (struct nextfield));
4161*63addd46Skettenis memset (new, 0, sizeof (struct nextfield));
4162e93f7393Sniklas new->next = list;
4163e93f7393Sniklas list = new;
4164e93f7393Sniklas
4165e93f7393Sniklas list->field.name = VT (objfile) + fieldp->dfield.name;
4166b725ae77Skettenis
4167b725ae77Skettenis
4168b725ae77Skettenis /* A FIELD by itself (without a GENFIELD) can also be a static
4169b725ae77Skettenis member. Mark it as static with a physname of NULL.
4170b725ae77Skettenis fix_static_member_physnames will assign the physname later. */
4171b725ae77Skettenis if (fieldp->dfield.staticmem)
4172b725ae77Skettenis {
4173b725ae77Skettenis SET_FIELD_PHYSNAME (list->field, NULL);
4174b725ae77Skettenis FIELD_BITPOS (list->field) = 0;
4175b725ae77Skettenis FIELD_BITSIZE (list->field) = 0;
4176b725ae77Skettenis }
4177e93f7393Sniklas else
4178b725ae77Skettenis /* Non-static data member */
4179b725ae77Skettenis {
4180b725ae77Skettenis FIELD_STATIC_KIND (list->field) = 0;
4181b725ae77Skettenis FIELD_BITPOS (list->field) = fieldp->dfield.bitoffset;
4182b725ae77Skettenis if (fieldp->dfield.bitlength % 8)
4183b725ae77Skettenis FIELD_BITSIZE (list->field) = fieldp->dfield.bitlength;
4184b725ae77Skettenis else
4185b725ae77Skettenis FIELD_BITSIZE (list->field) = 0;
4186e93f7393Sniklas }
4187e93f7393Sniklas
4188b725ae77Skettenis memtype = hpread_type_lookup (fieldp->dfield.type, objfile);
4189b725ae77Skettenis FIELD_TYPE (list->field) = memtype;
4190b725ae77Skettenis list->attributes = 0;
4191b725ae77Skettenis switch (fieldp->dfield.visibility)
4192b725ae77Skettenis {
4193b725ae77Skettenis case 1:
4194b725ae77Skettenis B_SET (&(list->attributes), ATTR_PROTECT);
4195b725ae77Skettenis break;
4196b725ae77Skettenis case 2:
4197b725ae77Skettenis B_SET (&(list->attributes), ATTR_PRIVATE);
4198b725ae77Skettenis break;
4199b725ae77Skettenis }
4200b725ae77Skettenis nfields++;
4201e93f7393Sniklas
4202b725ae77Skettenis
4203b725ae77Skettenis /* Note 1: First, we have to check if the current field is an anonymous
4204b725ae77Skettenis union. If it is, then *its* fields are threaded along in the
4205b725ae77Skettenis nextfield chain. :-( This was supposed to help debuggers, but is
4206b725ae77Skettenis really just a nuisance since we deal with anonymous unions anyway by
4207b725ae77Skettenis checking that the name is null. So anyway, we skip over the fields
4208b725ae77Skettenis of the anonymous union. pai/1997-08-22 */
4209b725ae77Skettenis /* Note 2: In addition, the bitoffsets for the fields of the anon union
4210b725ae77Skettenis are relative to the enclosing struct, *NOT* relative to the anon
4211b725ae77Skettenis union! This is an even bigger nuisance -- we have to go in and munge
4212b725ae77Skettenis the anon union's type information appropriately. pai/1997-08-22 */
4213b725ae77Skettenis
4214b725ae77Skettenis /* Both tasks noted above are done by a separate function. This takes us
4215b725ae77Skettenis to the next FIELD or GENFIELD, skipping anon unions, and recursively
4216b725ae77Skettenis processing intermediate types. */
4217b725ae77Skettenis field = hpread_get_next_skip_over_anon_unions (1, field, &fieldp, objfile);
4218b725ae77Skettenis
4219b725ae77Skettenis }
4220b725ae77Skettenis else
4221b725ae77Skettenis {
4222b725ae77Skettenis /* neither field nor genfield ?? is this possible?? */
4223b725ae77Skettenis /* pai:: FIXME walk to the next -- how? */
4224b725ae77Skettenis warning ("Internal error: unexpected DNTT kind %d encountered as field of struct",
4225b725ae77Skettenis fieldp->dblock.kind);
4226b725ae77Skettenis warning ("Skipping remaining fields of struct");
4227b725ae77Skettenis break; /* get out of loop of fields */
4228b725ae77Skettenis }
4229b725ae77Skettenis }
4230b725ae77Skettenis
4231b725ae77Skettenis /* If it's a template, read in the instantiation list */
4232b725ae77Skettenis if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
4233b725ae77Skettenis {
4234b725ae77Skettenis ninstantiations = 0;
4235b725ae77Skettenis field = dn_bufp->dtemplate.expansions;
4236b725ae77Skettenis while (field.word && field.word != DNTTNIL)
4237b725ae77Skettenis {
4238b725ae77Skettenis fieldp = hpread_get_lntt (field.dnttp.index, objfile);
4239b725ae77Skettenis
4240b725ae77Skettenis /* The expansions or nextexp should point to a tagdef */
4241b725ae77Skettenis if (fieldp->dblock.kind != DNTT_TYPE_TAGDEF)
4242b725ae77Skettenis break;
4243b725ae77Skettenis
4244b725ae77Skettenis i_new = (struct next_instantiation *) alloca (sizeof (struct next_instantiation));
4245*63addd46Skettenis memset (i_new, 0, sizeof (struct next_instantiation));
4246b725ae77Skettenis i_new->next = i_list;
4247b725ae77Skettenis i_list = i_new;
4248b725ae77Skettenis i_list->t = hpread_type_lookup (field, objfile);
4249b725ae77Skettenis ninstantiations++;
4250b725ae77Skettenis
4251b725ae77Skettenis /* And the "type" field of that should point to a class */
4252b725ae77Skettenis field = fieldp->dtag.type;
4253b725ae77Skettenis fieldp = hpread_get_lntt (field.dnttp.index, objfile);
4254b725ae77Skettenis if (fieldp->dblock.kind != DNTT_TYPE_CLASS)
4255b725ae77Skettenis break;
4256b725ae77Skettenis
4257b725ae77Skettenis /* Get the next expansion */
4258b725ae77Skettenis field = fieldp->dclass.nextexp;
4259b725ae77Skettenis }
4260b725ae77Skettenis }
4261b725ae77Skettenis TYPE_NINSTANTIATIONS (type) = ninstantiations;
4262b725ae77Skettenis if (ninstantiations > 0)
4263b725ae77Skettenis TYPE_INSTANTIATIONS (type) = (struct type **)
4264b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack, sizeof (struct type *) * ninstantiations);
4265b725ae77Skettenis for (n = ninstantiations; i_list; i_list = i_list->next)
4266e93f7393Sniklas {
4267e93f7393Sniklas n -= 1;
4268b725ae77Skettenis TYPE_INSTANTIATION (type, n) = i_list->t;
4269e93f7393Sniklas }
4270b725ae77Skettenis
4271b725ae77Skettenis
4272b725ae77Skettenis /* Copy the field-list to GDB's symbol table */
4273b725ae77Skettenis TYPE_NFIELDS (type) = nfields;
4274b725ae77Skettenis TYPE_N_BASECLASSES (type) = n_base_classes;
4275b725ae77Skettenis TYPE_FIELDS (type) = (struct field *)
4276b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack, sizeof (struct field) * nfields);
4277b725ae77Skettenis /* Copy the saved-up fields into the field vector. */
4278b725ae77Skettenis for (n = nfields, tmp_list = list; tmp_list; tmp_list = tmp_list->next)
4279b725ae77Skettenis {
4280b725ae77Skettenis n -= 1;
4281b725ae77Skettenis TYPE_FIELD (type, n) = tmp_list->field;
4282b725ae77Skettenis }
4283b725ae77Skettenis
4284b725ae77Skettenis /* Copy the "function-field-list" (i.e., the list of member
4285b725ae77Skettenis * functions in the class) to GDB's symbol table
4286b725ae77Skettenis */
4287b725ae77Skettenis TYPE_NFN_FIELDS (type) = n_fn_fields;
4288b725ae77Skettenis TYPE_NFN_FIELDS_TOTAL (type) = n_fn_fields_total;
4289b725ae77Skettenis TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
4290b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack, sizeof (struct fn_fieldlist) * n_fn_fields);
4291b725ae77Skettenis for (n = n_fn_fields; fn_list; fn_list = fn_list->next)
4292b725ae77Skettenis {
4293b725ae77Skettenis n -= 1;
4294b725ae77Skettenis TYPE_FN_FIELDLIST (type, n) = fn_list->field;
4295b725ae77Skettenis }
4296b725ae77Skettenis
4297b725ae77Skettenis /* pai:: FIXME -- perhaps each bitvector should be created individually */
4298b725ae77Skettenis for (n = nfields, tmp_list = list; tmp_list; tmp_list = tmp_list->next)
4299b725ae77Skettenis {
4300b725ae77Skettenis n -= 1;
4301b725ae77Skettenis if (tmp_list->attributes)
4302b725ae77Skettenis {
4303b725ae77Skettenis need_bitvectors = 1;
4304b725ae77Skettenis break;
4305b725ae77Skettenis }
4306b725ae77Skettenis }
4307b725ae77Skettenis
4308b725ae77Skettenis if (need_bitvectors)
4309b725ae77Skettenis {
4310b725ae77Skettenis /* pai:: this step probably redundant */
4311b725ae77Skettenis ALLOCATE_CPLUS_STRUCT_TYPE (type);
4312b725ae77Skettenis
4313b725ae77Skettenis TYPE_FIELD_VIRTUAL_BITS (type) =
4314b725ae77Skettenis (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4315b725ae77Skettenis B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), nfields);
4316b725ae77Skettenis
4317b725ae77Skettenis TYPE_FIELD_PRIVATE_BITS (type) =
4318b725ae77Skettenis (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4319b725ae77Skettenis B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
4320b725ae77Skettenis
4321b725ae77Skettenis TYPE_FIELD_PROTECTED_BITS (type) =
4322b725ae77Skettenis (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4323b725ae77Skettenis B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
4324b725ae77Skettenis
4325b725ae77Skettenis /* this field vector isn't actually used with HP aCC */
4326b725ae77Skettenis TYPE_FIELD_IGNORE_BITS (type) =
4327b725ae77Skettenis (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4328b725ae77Skettenis B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
4329b725ae77Skettenis
4330b725ae77Skettenis while (nfields-- > 0)
4331b725ae77Skettenis {
4332b725ae77Skettenis if (B_TST (&(list->attributes), ATTR_VIRTUAL))
4333b725ae77Skettenis SET_TYPE_FIELD_VIRTUAL (type, nfields);
4334b725ae77Skettenis if (B_TST (&(list->attributes), ATTR_PRIVATE))
4335b725ae77Skettenis SET_TYPE_FIELD_PRIVATE (type, nfields);
4336b725ae77Skettenis if (B_TST (&(list->attributes), ATTR_PROTECT))
4337b725ae77Skettenis SET_TYPE_FIELD_PROTECTED (type, nfields);
4338b725ae77Skettenis
4339b725ae77Skettenis list = list->next;
4340b725ae77Skettenis }
4341b725ae77Skettenis }
4342b725ae77Skettenis else
4343b725ae77Skettenis {
4344b725ae77Skettenis TYPE_FIELD_VIRTUAL_BITS (type) = NULL;
4345b725ae77Skettenis TYPE_FIELD_PROTECTED_BITS (type) = NULL;
4346b725ae77Skettenis TYPE_FIELD_PRIVATE_BITS (type) = NULL;
4347b725ae77Skettenis }
4348b725ae77Skettenis
4349b725ae77Skettenis if (has_vtable (type))
4350b725ae77Skettenis {
4351b725ae77Skettenis /* Allocate space for class runtime information */
4352b725ae77Skettenis TYPE_RUNTIME_PTR (type) = (struct runtime_info *) xmalloc (sizeof (struct runtime_info));
4353b725ae77Skettenis /* Set flag for vtable */
4354b725ae77Skettenis TYPE_VTABLE (type) = 1;
4355b725ae77Skettenis /* The first non-virtual base class with a vtable. */
4356b725ae77Skettenis TYPE_PRIMARY_BASE (type) = primary_base_class (type);
4357b725ae77Skettenis /* The virtual base list. */
4358b725ae77Skettenis TYPE_VIRTUAL_BASE_LIST (type) = virtual_base_list (type);
4359b725ae77Skettenis }
4360b725ae77Skettenis else
4361b725ae77Skettenis TYPE_RUNTIME_PTR (type) = NULL;
4362b725ae77Skettenis
4363b725ae77Skettenis /* If this is a local type (C++ - declared inside a function), record file name & line # */
4364b725ae77Skettenis if (hpread_get_scope_depth (dn_bufp, objfile, 1 /* no need for real depth */ ))
4365b725ae77Skettenis {
4366b725ae77Skettenis TYPE_LOCALTYPE_PTR (type) = (struct local_type_info *) xmalloc (sizeof (struct local_type_info));
4367b725ae77Skettenis TYPE_LOCALTYPE_FILE (type) = (char *) xmalloc (strlen (current_subfile->name) + 1);
4368b725ae77Skettenis strcpy (TYPE_LOCALTYPE_FILE (type), current_subfile->name);
4369b725ae77Skettenis if (current_subfile->line_vector && (current_subfile->line_vector->nitems > 0))
4370b725ae77Skettenis TYPE_LOCALTYPE_LINE (type) = current_subfile->line_vector->item[current_subfile->line_vector->nitems - 1].line;
4371b725ae77Skettenis else
4372b725ae77Skettenis TYPE_LOCALTYPE_LINE (type) = 0;
4373b725ae77Skettenis }
4374b725ae77Skettenis else
4375b725ae77Skettenis TYPE_LOCALTYPE_PTR (type) = NULL;
4376b725ae77Skettenis
4377b725ae77Skettenis /* Clear the global saying what template we are in the middle of processing */
4378b725ae77Skettenis current_template = NULL;
4379b725ae77Skettenis
4380b725ae77Skettenis return type;
4381b725ae77Skettenis }
4382b725ae77Skettenis
4383b725ae77Skettenis /* Adjust the physnames for each static member of a struct
4384b725ae77Skettenis or class type to be something like "A::x"; then various
4385b725ae77Skettenis other pieces of code that do a lookup_symbol on the phyname
4386b725ae77Skettenis work correctly.
4387b725ae77Skettenis TYPE is a pointer to the struct/class type
4388b725ae77Skettenis NAME is a char * (string) which is the class/struct name
4389b725ae77Skettenis Void return */
4390b725ae77Skettenis
4391b725ae77Skettenis static void
fix_static_member_physnames(struct type * type,char * class_name,struct objfile * objfile)4392b725ae77Skettenis fix_static_member_physnames (struct type *type, char *class_name,
4393b725ae77Skettenis struct objfile *objfile)
4394b725ae77Skettenis {
4395b725ae77Skettenis int i;
4396b725ae77Skettenis
4397b725ae77Skettenis /* We fix the member names only for classes or structs */
4398b725ae77Skettenis if (TYPE_CODE (type) != TYPE_CODE_STRUCT)
4399b725ae77Skettenis return;
4400b725ae77Skettenis
4401b725ae77Skettenis for (i = 0; i < TYPE_NFIELDS (type); i++)
4402b725ae77Skettenis if (TYPE_FIELD_STATIC (type, i))
4403b725ae77Skettenis {
4404b725ae77Skettenis if (TYPE_FIELD_STATIC_PHYSNAME (type, i))
4405b725ae77Skettenis return; /* physnames are already set */
4406b725ae77Skettenis
4407b725ae77Skettenis SET_FIELD_PHYSNAME (TYPE_FIELDS (type)[i],
4408b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack,
4409b725ae77Skettenis strlen (class_name) + strlen (TYPE_FIELD_NAME (type, i)) + 3));
4410b725ae77Skettenis strcpy (TYPE_FIELD_STATIC_PHYSNAME (type, i), class_name);
4411b725ae77Skettenis strcat (TYPE_FIELD_STATIC_PHYSNAME (type, i), "::");
4412b725ae77Skettenis strcat (TYPE_FIELD_STATIC_PHYSNAME (type, i), TYPE_FIELD_NAME (type, i));
4413b725ae77Skettenis }
4414b725ae77Skettenis }
4415b725ae77Skettenis
4416b725ae77Skettenis /* Fix-up the type structure for a CLASS so that the type entry
4417b725ae77Skettenis * for a method (previously marked with a null type in hpread_read_struct_type()
4418b725ae77Skettenis * is set correctly to METHOD.
4419b725ae77Skettenis * OBJFILE is as for other such functions.
4420b725ae77Skettenis * Void return. */
4421b725ae77Skettenis
4422b725ae77Skettenis static void
fixup_class_method_type(struct type * class,struct type * method,struct objfile * objfile)4423b725ae77Skettenis fixup_class_method_type (struct type *class, struct type *method,
4424b725ae77Skettenis struct objfile *objfile)
4425b725ae77Skettenis {
4426b725ae77Skettenis int i, j, k;
4427b725ae77Skettenis
4428b725ae77Skettenis if (!class || !method || !objfile)
4429b725ae77Skettenis return;
4430b725ae77Skettenis
4431b725ae77Skettenis /* Only for types that have methods */
4432b725ae77Skettenis if ((TYPE_CODE (class) != TYPE_CODE_CLASS) &&
4433b725ae77Skettenis (TYPE_CODE (class) != TYPE_CODE_UNION))
4434b725ae77Skettenis return;
4435b725ae77Skettenis
4436b725ae77Skettenis /* Loop over all methods and find the one marked with a NULL type */
4437b725ae77Skettenis for (i = 0; i < TYPE_NFN_FIELDS (class); i++)
4438b725ae77Skettenis for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (class, i); j++)
4439b725ae77Skettenis if (TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j) == NULL)
4440b725ae77Skettenis {
4441b725ae77Skettenis /* Set the method type */
4442b725ae77Skettenis TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j) = method;
4443b725ae77Skettenis
4444b725ae77Skettenis /* Break out of both loops -- only one method to fix up in a class */
4445b725ae77Skettenis goto finish;
4446b725ae77Skettenis }
4447b725ae77Skettenis
4448b725ae77Skettenis finish:
4449b725ae77Skettenis TYPE_FLAGS (class) &= ~TYPE_FLAG_INCOMPLETE;
4450b725ae77Skettenis }
4451b725ae77Skettenis
4452b725ae77Skettenis
4453b725ae77Skettenis /* If we're in the middle of processing a template, get a pointer
4454b725ae77Skettenis * to the Nth template argument.
4455b725ae77Skettenis * An example may make this clearer:
4456b725ae77Skettenis * template <class T1, class T2> class q2 {
4457b725ae77Skettenis * public:
4458b725ae77Skettenis * T1 a;
4459b725ae77Skettenis * T2 b;
4460b725ae77Skettenis * };
4461b725ae77Skettenis * The type for "a" will be "first template arg" and
4462b725ae77Skettenis * the type for "b" will be "second template arg".
4463b725ae77Skettenis * We need to look these up in order to fill in "a" and "b"'s type.
4464b725ae77Skettenis * This is called from hpread_type_lookup().
4465b725ae77Skettenis */
4466b725ae77Skettenis static struct type *
hpread_get_nth_template_arg(struct objfile * objfile,int n)4467b725ae77Skettenis hpread_get_nth_template_arg (struct objfile *objfile, int n)
4468b725ae77Skettenis {
4469b725ae77Skettenis if (current_template != NULL)
4470b725ae77Skettenis return TYPE_TEMPLATE_ARG (current_template, n).type;
4471b725ae77Skettenis else
4472b725ae77Skettenis return lookup_fundamental_type (objfile, FT_TEMPLATE_ARG);
4473b725ae77Skettenis }
4474b725ae77Skettenis
4475b725ae77Skettenis /* Read in and internalize a TEMPL_ARG (template arg) symbol. */
4476b725ae77Skettenis
4477b725ae77Skettenis static struct type *
hpread_read_templ_arg_type(dnttpointer hp_type,union dnttentry * dn_bufp,struct objfile * objfile,char * name)4478b725ae77Skettenis hpread_read_templ_arg_type (dnttpointer hp_type, union dnttentry *dn_bufp,
4479b725ae77Skettenis struct objfile *objfile, char *name)
4480b725ae77Skettenis {
4481b725ae77Skettenis struct type *type;
4482b725ae77Skettenis
4483b725ae77Skettenis /* See if it's something we've already deal with. */
4484b725ae77Skettenis type = hpread_alloc_type (hp_type, objfile);
4485b725ae77Skettenis if (TYPE_CODE (type) == TYPE_CODE_TEMPLATE_ARG)
4486b725ae77Skettenis return type;
4487b725ae77Skettenis
4488b725ae77Skettenis /* Nope. Fill in the appropriate fields. */
4489b725ae77Skettenis TYPE_CODE (type) = TYPE_CODE_TEMPLATE_ARG;
4490b725ae77Skettenis TYPE_LENGTH (type) = 0;
4491b725ae77Skettenis TYPE_NFIELDS (type) = 0;
4492b725ae77Skettenis TYPE_NAME (type) = name;
4493e93f7393Sniklas return type;
4494e93f7393Sniklas }
4495e93f7393Sniklas
4496e93f7393Sniklas /* Read in and internalize a set debug symbol. */
4497e93f7393Sniklas
4498e93f7393Sniklas static struct type *
hpread_read_set_type(dnttpointer hp_type,union dnttentry * dn_bufp,struct objfile * objfile)4499b725ae77Skettenis hpread_read_set_type (dnttpointer hp_type, union dnttentry *dn_bufp,
4500b725ae77Skettenis struct objfile *objfile)
4501e93f7393Sniklas {
4502e93f7393Sniklas struct type *type;
4503e93f7393Sniklas
4504e93f7393Sniklas /* See if it's something we've already deal with. */
4505e93f7393Sniklas type = hpread_alloc_type (hp_type, objfile);
4506e93f7393Sniklas if (TYPE_CODE (type) == TYPE_CODE_SET)
4507e93f7393Sniklas return type;
4508e93f7393Sniklas
4509e93f7393Sniklas /* Nope. Fill in the appropriate fields. */
4510e93f7393Sniklas TYPE_CODE (type) = TYPE_CODE_SET;
4511e93f7393Sniklas TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
4512e93f7393Sniklas TYPE_NFIELDS (type) = 0;
4513e93f7393Sniklas TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
4514e93f7393Sniklas objfile);
4515e93f7393Sniklas return type;
4516e93f7393Sniklas }
4517e93f7393Sniklas
4518e93f7393Sniklas /* Read in and internalize an array debug symbol. */
4519e93f7393Sniklas
4520e93f7393Sniklas static struct type *
hpread_read_array_type(dnttpointer hp_type,union dnttentry * dn_bufp,struct objfile * objfile)4521b725ae77Skettenis hpread_read_array_type (dnttpointer hp_type, union dnttentry *dn_bufp,
4522b725ae77Skettenis struct objfile *objfile)
4523e93f7393Sniklas {
4524e93f7393Sniklas struct type *type;
4525e93f7393Sniklas
4526b725ae77Skettenis /* Allocate an array type symbol.
4527b725ae77Skettenis * Why no check for already-read here, like in the other
4528b725ae77Skettenis * hpread_read_xxx_type routines? Because it kept us
4529b725ae77Skettenis * from properly determining the size of the array!
4530b725ae77Skettenis */
4531e93f7393Sniklas type = hpread_alloc_type (hp_type, objfile);
4532e93f7393Sniklas
4533e93f7393Sniklas TYPE_CODE (type) = TYPE_CODE_ARRAY;
4534e93f7393Sniklas
4535b725ae77Skettenis /* Although the hp-symtab.h does not *require* this to be the case,
4536b725ae77Skettenis * GDB is assuming that "arrayisbytes" and "elemisbytes" be consistent.
4537b725ae77Skettenis * I.e., express both array-length and element-length in bits,
4538b725ae77Skettenis * or express both array-length and element-length in bytes.
4539b725ae77Skettenis */
4540b725ae77Skettenis if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes) ||
4541b725ae77Skettenis (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
4542b725ae77Skettenis {
4543b725ae77Skettenis warning ("error in hpread_array_type.\n");
4544b725ae77Skettenis return NULL;
4545b725ae77Skettenis }
4546e93f7393Sniklas else if (dn_bufp->darray.arraylength == 0x7fffffff)
4547e93f7393Sniklas {
4548e93f7393Sniklas /* The HP debug format represents char foo[]; as an array with
4549b725ae77Skettenis * length 0x7fffffff. Internally GDB wants to represent this
4550b725ae77Skettenis * as an array of length zero.
4551b725ae77Skettenis */
4552e93f7393Sniklas TYPE_LENGTH (type) = 0;
4553e93f7393Sniklas }
4554b725ae77Skettenis else if (dn_bufp->darray.arrayisbytes)
4555b725ae77Skettenis TYPE_LENGTH (type) = dn_bufp->darray.arraylength;
4556b725ae77Skettenis else /* arraylength is in bits */
4557e93f7393Sniklas TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
4558e93f7393Sniklas
4559e93f7393Sniklas TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
4560e93f7393Sniklas objfile);
4561b725ae77Skettenis
4562b725ae77Skettenis /* The one "field" is used to store the subscript type */
4563b725ae77Skettenis /* Since C and C++ multi-dimensional arrays are simply represented
4564b725ae77Skettenis * as: array of array of ..., we only need one subscript-type
4565b725ae77Skettenis * per array. This subscript type is typically a subrange of integer.
4566b725ae77Skettenis * If this gets extended to support languages like Pascal, then
4567b725ae77Skettenis * we need to fix this to represent multi-dimensional arrays properly.
4568b725ae77Skettenis */
4569b725ae77Skettenis TYPE_NFIELDS (type) = 1;
4570e93f7393Sniklas TYPE_FIELDS (type) = (struct field *)
4571b725ae77Skettenis obstack_alloc (&objfile->objfile_obstack, sizeof (struct field));
4572e93f7393Sniklas TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
4573e93f7393Sniklas objfile);
4574e93f7393Sniklas return type;
4575e93f7393Sniklas }
4576e93f7393Sniklas
4577e93f7393Sniklas /* Read in and internalize a subrange debug symbol. */
4578e93f7393Sniklas static struct type *
hpread_read_subrange_type(dnttpointer hp_type,union dnttentry * dn_bufp,struct objfile * objfile)4579b725ae77Skettenis hpread_read_subrange_type (dnttpointer hp_type, union dnttentry *dn_bufp,
4580b725ae77Skettenis struct objfile *objfile)
4581e93f7393Sniklas {
4582e93f7393Sniklas struct type *type;
4583e93f7393Sniklas
4584e93f7393Sniklas /* Is it something we've already dealt with. */
4585e93f7393Sniklas type = hpread_alloc_type (hp_type, objfile);
4586e93f7393Sniklas if (TYPE_CODE (type) == TYPE_CODE_RANGE)
4587e93f7393Sniklas return type;
4588e93f7393Sniklas
4589e93f7393Sniklas /* Nope, internalize it. */
4590e93f7393Sniklas TYPE_CODE (type) = TYPE_CODE_RANGE;
4591e93f7393Sniklas TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
4592e93f7393Sniklas TYPE_NFIELDS (type) = 2;
4593e93f7393Sniklas TYPE_FIELDS (type)
4594b725ae77Skettenis = (struct field *) obstack_alloc (&objfile->objfile_obstack,
4595e93f7393Sniklas 2 * sizeof (struct field));
4596e93f7393Sniklas
4597e93f7393Sniklas if (dn_bufp->dsubr.dyn_low)
4598e93f7393Sniklas TYPE_FIELD_BITPOS (type, 0) = 0;
4599e93f7393Sniklas else
4600e93f7393Sniklas TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
4601e93f7393Sniklas
4602e93f7393Sniklas if (dn_bufp->dsubr.dyn_high)
4603e93f7393Sniklas TYPE_FIELD_BITPOS (type, 1) = -1;
4604e93f7393Sniklas else
4605e93f7393Sniklas TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
4606e93f7393Sniklas TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
4607e93f7393Sniklas objfile);
4608e93f7393Sniklas return type;
4609e93f7393Sniklas }
4610e93f7393Sniklas
4611b725ae77Skettenis /* struct type * hpread_type_lookup(hp_type, objfile)
4612b725ae77Skettenis * Arguments:
4613b725ae77Skettenis * hp_type: A pointer into the DNTT specifying what type we
4614b725ae77Skettenis * are about to "look up"., or else [for fundamental types
4615b725ae77Skettenis * like int, float, ...] an "immediate" structure describing
4616b725ae77Skettenis * the type.
4617b725ae77Skettenis * objfile: ?
4618b725ae77Skettenis * Return value: A pointer to a "struct type" (representation of a
4619b725ae77Skettenis * type in GDB's internal symbol table - see gdbtypes.h)
4620b725ae77Skettenis * Routine description:
4621b725ae77Skettenis * There are a variety of places when scanning the DNTT when we
4622b725ae77Skettenis * need to interpret a "type" field. The simplest and most basic
4623b725ae77Skettenis * example is when we're processing the symbol table record
4624b725ae77Skettenis * for a data symbol (a SVAR or DVAR record). That has
4625b725ae77Skettenis * a "type" field specifying the type of the data symbol. That
4626b725ae77Skettenis * "type" field is either an "immediate" type specification (for the
4627b725ae77Skettenis * fundamental types) or a DNTT pointer (for more complicated types).
4628b725ae77Skettenis * For the more complicated types, we may or may not have already
4629b725ae77Skettenis * processed the pointed-to type. (Multiple data symbols can of course
4630b725ae77Skettenis * share the same type).
4631b725ae77Skettenis * The job of hpread_type_lookup() is to process this "type" field.
4632b725ae77Skettenis * Most of the real work is done in subroutines. Here we interpret
4633b725ae77Skettenis * the immediate flag. If not immediate, chase the DNTT pointer to
4634b725ae77Skettenis * find our way to the SOM record describing the type, switch on
4635b725ae77Skettenis * the SOM kind, and then call an appropriate subroutine depending
4636b725ae77Skettenis * on what kind of type we are constructing. (e.g., an array type,
4637b725ae77Skettenis * a struct/class type, etc).
4638b725ae77Skettenis */
4639e93f7393Sniklas static struct type *
hpread_type_lookup(dnttpointer hp_type,struct objfile * objfile)4640b725ae77Skettenis hpread_type_lookup (dnttpointer hp_type, struct objfile *objfile)
4641e93f7393Sniklas {
4642e93f7393Sniklas union dnttentry *dn_bufp;
4643b725ae77Skettenis struct type *tmp_type;
4644e93f7393Sniklas
4645e93f7393Sniklas /* First see if it's a simple builtin type. */
4646e93f7393Sniklas if (hp_type.dntti.immediate)
4647b725ae77Skettenis {
4648b725ae77Skettenis /* If this is a template argument, the argument number is
4649b725ae77Skettenis * encoded in the bitlength. All other cases, just return
4650b725ae77Skettenis * GDB's representation of this fundamental type.
4651b725ae77Skettenis */
4652b725ae77Skettenis if (hp_type.dntti.type == HP_TYPE_TEMPLATE_ARG)
4653b725ae77Skettenis return hpread_get_nth_template_arg (objfile, hp_type.dntti.bitlength);
4654b725ae77Skettenis else
4655b725ae77Skettenis return lookup_fundamental_type (objfile,
4656b725ae77Skettenis hpread_type_translate (hp_type));
4657b725ae77Skettenis }
4658e93f7393Sniklas
4659e93f7393Sniklas /* Not a builtin type. We'll have to read it in. */
4660e93f7393Sniklas if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
4661e93f7393Sniklas dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
4662e93f7393Sniklas else
4663b725ae77Skettenis /* This is a fancy way of returning NULL */
4664e93f7393Sniklas return lookup_fundamental_type (objfile, FT_VOID);
4665e93f7393Sniklas
4666e93f7393Sniklas switch (dn_bufp->dblock.kind)
4667e93f7393Sniklas {
4668e93f7393Sniklas case DNTT_TYPE_SRCFILE:
4669e93f7393Sniklas case DNTT_TYPE_MODULE:
4670e93f7393Sniklas case DNTT_TYPE_ENTRY:
4671e93f7393Sniklas case DNTT_TYPE_BEGIN:
4672e93f7393Sniklas case DNTT_TYPE_END:
4673e93f7393Sniklas case DNTT_TYPE_IMPORT:
4674e93f7393Sniklas case DNTT_TYPE_LABEL:
4675e93f7393Sniklas case DNTT_TYPE_FPARAM:
4676e93f7393Sniklas case DNTT_TYPE_SVAR:
4677e93f7393Sniklas case DNTT_TYPE_DVAR:
4678e93f7393Sniklas case DNTT_TYPE_CONST:
4679b725ae77Skettenis case DNTT_TYPE_MEMENUM:
4680b725ae77Skettenis case DNTT_TYPE_VARIANT:
4681b725ae77Skettenis case DNTT_TYPE_FILE:
4682b725ae77Skettenis case DNTT_TYPE_WITH:
4683b725ae77Skettenis case DNTT_TYPE_COMMON:
4684b725ae77Skettenis case DNTT_TYPE_COBSTRUCT:
4685b725ae77Skettenis case DNTT_TYPE_XREF:
4686b725ae77Skettenis case DNTT_TYPE_SA:
4687b725ae77Skettenis case DNTT_TYPE_MACRO:
4688b725ae77Skettenis case DNTT_TYPE_BLOCKDATA:
4689b725ae77Skettenis case DNTT_TYPE_CLASS_SCOPE:
4690b725ae77Skettenis case DNTT_TYPE_MEMACCESS:
4691b725ae77Skettenis case DNTT_TYPE_INHERITANCE:
4692b725ae77Skettenis case DNTT_TYPE_OBJECT_ID:
4693b725ae77Skettenis case DNTT_TYPE_FRIEND_CLASS:
4694b725ae77Skettenis case DNTT_TYPE_FRIEND_FUNC:
4695b725ae77Skettenis /* These are not types - something went wrong. */
4696b725ae77Skettenis /* This is a fancy way of returning NULL */
4697e93f7393Sniklas return lookup_fundamental_type (objfile, FT_VOID);
4698e93f7393Sniklas
4699b725ae77Skettenis case DNTT_TYPE_FUNCTION:
4700b725ae77Skettenis /* We wind up here when dealing with class member functions
4701b725ae77Skettenis * (called from hpread_read_struct_type(), i.e. when processing
4702b725ae77Skettenis * the class definition itself).
4703b725ae77Skettenis */
4704b725ae77Skettenis return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
4705b725ae77Skettenis
4706b725ae77Skettenis case DNTT_TYPE_DOC_FUNCTION:
4707b725ae77Skettenis return hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 0);
4708b725ae77Skettenis
4709e93f7393Sniklas case DNTT_TYPE_TYPEDEF:
4710e93f7393Sniklas {
4711b725ae77Skettenis /* A typedef - chase it down by making a recursive call */
4712e93f7393Sniklas struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
4713e93f7393Sniklas objfile);
4714b725ae77Skettenis
4715b725ae77Skettenis /* The following came from the base hpread.c that we inherited.
4716b725ae77Skettenis * It is WRONG so I have commented it out. - RT
4717b725ae77Skettenis *...
4718b725ae77Skettenis
4719e93f7393Sniklas char *suffix;
4720e93f7393Sniklas suffix = VT (objfile) + dn_bufp->dtype.name;
4721e93f7393Sniklas TYPE_NAME (structtype) = suffix;
4722b725ae77Skettenis
4723b725ae77Skettenis * ... further explanation ....
4724b725ae77Skettenis *
4725b725ae77Skettenis * What we have here is a typedef pointing to a typedef.
4726b725ae77Skettenis * E.g.,
4727b725ae77Skettenis * typedef int foo;
4728b725ae77Skettenis * typedef foo fum;
4729b725ae77Skettenis *
4730b725ae77Skettenis * What we desire to build is (these are pictures
4731b725ae77Skettenis * of "struct type"'s):
4732b725ae77Skettenis *
4733b725ae77Skettenis * +---------+ +----------+ +------------+
4734b725ae77Skettenis * | typedef | | typedef | | fund. type |
4735b725ae77Skettenis * | type| -> | type| -> | |
4736b725ae77Skettenis * | "fum" | | "foo" | | "int" |
4737b725ae77Skettenis * +---------+ +----------+ +------------+
4738b725ae77Skettenis *
4739b725ae77Skettenis * What this commented-out code is doing is smashing the
4740b725ae77Skettenis * name of pointed-to-type to be the same as the pointed-from
4741b725ae77Skettenis * type. So we wind up with something like:
4742b725ae77Skettenis *
4743b725ae77Skettenis * +---------+ +----------+ +------------+
4744b725ae77Skettenis * | typedef | | typedef | | fund. type |
4745b725ae77Skettenis * | type| -> | type| -> | |
4746b725ae77Skettenis * | "fum" | | "fum" | | "fum" |
4747b725ae77Skettenis * +---------+ +----------+ +------------+
4748b725ae77Skettenis *
4749b725ae77Skettenis */
4750b725ae77Skettenis
4751e93f7393Sniklas return structtype;
4752e93f7393Sniklas }
4753e93f7393Sniklas
4754e93f7393Sniklas case DNTT_TYPE_TAGDEF:
4755e93f7393Sniklas {
4756e93f7393Sniklas /* Just a little different from above. We have to tack on
4757b725ae77Skettenis * an identifier of some kind (struct, union, enum, class, etc).
4758b725ae77Skettenis */
4759e93f7393Sniklas struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
4760e93f7393Sniklas objfile);
4761e93f7393Sniklas char *prefix, *suffix;
4762e93f7393Sniklas suffix = VT (objfile) + dn_bufp->dtype.name;
4763e93f7393Sniklas
4764e93f7393Sniklas /* Lookup the next type in the list. It should be a structure,
4765b725ae77Skettenis * union, class, enum, or template type.
4766b725ae77Skettenis * We will need to attach that to our name.
4767b725ae77Skettenis */
4768e93f7393Sniklas if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
4769e93f7393Sniklas dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
4770e93f7393Sniklas else
4771b725ae77Skettenis {
4772b725ae77Skettenis complaint (&symfile_complaints, "error in hpread_type_lookup().");
4773b725ae77Skettenis return NULL;
4774b725ae77Skettenis }
4775e93f7393Sniklas
4776e93f7393Sniklas if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
4777b725ae77Skettenis {
4778e93f7393Sniklas prefix = "struct ";
4779b725ae77Skettenis }
4780e93f7393Sniklas else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
4781b725ae77Skettenis {
4782e93f7393Sniklas prefix = "union ";
4783b725ae77Skettenis }
4784b725ae77Skettenis else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
4785b725ae77Skettenis {
4786b725ae77Skettenis /* Further field for CLASS saying how it was really declared */
4787b725ae77Skettenis /* 0==class, 1==union, 2==struct */
4788b725ae77Skettenis if (dn_bufp->dclass.class_decl == 0)
4789b725ae77Skettenis prefix = "class ";
4790b725ae77Skettenis else if (dn_bufp->dclass.class_decl == 1)
4791b725ae77Skettenis prefix = "union ";
4792b725ae77Skettenis else if (dn_bufp->dclass.class_decl == 2)
4793b725ae77Skettenis prefix = "struct ";
4794e93f7393Sniklas else
4795b725ae77Skettenis prefix = "";
4796b725ae77Skettenis }
4797b725ae77Skettenis else if (dn_bufp->dblock.kind == DNTT_TYPE_ENUM)
4798b725ae77Skettenis {
4799e93f7393Sniklas prefix = "enum ";
4800b725ae77Skettenis }
4801b725ae77Skettenis else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
4802b725ae77Skettenis {
4803b725ae77Skettenis prefix = "template ";
4804b725ae77Skettenis }
4805b725ae77Skettenis else
4806b725ae77Skettenis {
4807b725ae77Skettenis prefix = "";
4808b725ae77Skettenis }
4809e93f7393Sniklas
4810e93f7393Sniklas /* Build the correct name. */
4811b725ae77Skettenis TYPE_NAME (structtype)
4812b725ae77Skettenis = (char *) obstack_alloc (&objfile->objfile_obstack,
4813e93f7393Sniklas strlen (prefix) + strlen (suffix) + 1);
4814e93f7393Sniklas TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
4815e93f7393Sniklas TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
4816e93f7393Sniklas TYPE_TAG_NAME (structtype) = suffix;
4817e93f7393Sniklas
4818b725ae77Skettenis /* For classes/structs, we have to set the static member "physnames"
4819b725ae77Skettenis to point to strings like "Class::Member" */
4820b725ae77Skettenis if (TYPE_CODE (structtype) == TYPE_CODE_STRUCT)
4821b725ae77Skettenis fix_static_member_physnames (structtype, suffix, objfile);
4822e93f7393Sniklas
4823e93f7393Sniklas return structtype;
4824e93f7393Sniklas }
4825b725ae77Skettenis
4826e93f7393Sniklas case DNTT_TYPE_POINTER:
4827b725ae77Skettenis /* Pointer type - call a routine in gdbtypes.c that constructs
4828b725ae77Skettenis * the appropriate GDB type.
4829b725ae77Skettenis */
4830b725ae77Skettenis return make_pointer_type (
4831b725ae77Skettenis hpread_type_lookup (dn_bufp->dptr.pointsto,
4832b725ae77Skettenis objfile),
4833b725ae77Skettenis NULL);
4834b725ae77Skettenis
4835b725ae77Skettenis case DNTT_TYPE_REFERENCE:
4836b725ae77Skettenis /* C++ reference type - call a routine in gdbtypes.c that constructs
4837b725ae77Skettenis * the appropriate GDB type.
4838b725ae77Skettenis */
4839b725ae77Skettenis return make_reference_type (
4840b725ae77Skettenis hpread_type_lookup (dn_bufp->dreference.pointsto,
4841b725ae77Skettenis objfile),
4842b725ae77Skettenis NULL);
4843b725ae77Skettenis
4844e93f7393Sniklas case DNTT_TYPE_ENUM:
4845e93f7393Sniklas return hpread_read_enum_type (hp_type, dn_bufp, objfile);
4846e93f7393Sniklas case DNTT_TYPE_SET:
4847e93f7393Sniklas return hpread_read_set_type (hp_type, dn_bufp, objfile);
4848e93f7393Sniklas case DNTT_TYPE_SUBRANGE:
4849e93f7393Sniklas return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
4850e93f7393Sniklas case DNTT_TYPE_ARRAY:
4851e93f7393Sniklas return hpread_read_array_type (hp_type, dn_bufp, objfile);
4852e93f7393Sniklas case DNTT_TYPE_STRUCT:
4853e93f7393Sniklas case DNTT_TYPE_UNION:
4854e93f7393Sniklas return hpread_read_struct_type (hp_type, dn_bufp, objfile);
4855e93f7393Sniklas case DNTT_TYPE_FIELD:
4856e93f7393Sniklas return hpread_type_lookup (dn_bufp->dfield.type, objfile);
4857b725ae77Skettenis
4858e93f7393Sniklas case DNTT_TYPE_FUNCTYPE:
4859b725ae77Skettenis /* Here we want to read the function SOMs and return a
4860b725ae77Skettenis * type for it. We get here, for instance, when processing
4861b725ae77Skettenis * pointer-to-function type.
4862b725ae77Skettenis */
4863b725ae77Skettenis return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
4864b725ae77Skettenis
4865b725ae77Skettenis case DNTT_TYPE_PTRMEM:
4866b725ae77Skettenis /* Declares a C++ pointer-to-data-member type.
4867b725ae77Skettenis * The "pointsto" field defines the class,
4868b725ae77Skettenis * while the "memtype" field defines the pointed-to-type.
4869b725ae77Skettenis */
4870b725ae77Skettenis {
4871b725ae77Skettenis struct type *ptrmemtype;
4872b725ae77Skettenis struct type *class_type;
4873b725ae77Skettenis struct type *memtype;
4874b725ae77Skettenis memtype = hpread_type_lookup (dn_bufp->dptrmem.memtype,
4875b725ae77Skettenis objfile),
4876b725ae77Skettenis class_type = hpread_type_lookup (dn_bufp->dptrmem.pointsto,
4877b725ae77Skettenis objfile),
4878b725ae77Skettenis ptrmemtype = alloc_type (objfile);
4879b725ae77Skettenis smash_to_member_type (ptrmemtype, class_type, memtype);
4880b725ae77Skettenis return make_pointer_type (ptrmemtype, NULL);
4881b725ae77Skettenis }
4882b725ae77Skettenis break;
4883b725ae77Skettenis
4884b725ae77Skettenis case DNTT_TYPE_PTRMEMFUNC:
4885b725ae77Skettenis /* Defines a C++ pointer-to-function-member type.
4886b725ae77Skettenis * The "pointsto" field defines the class,
4887b725ae77Skettenis * while the "memtype" field defines the pointed-to-type.
4888b725ae77Skettenis */
4889b725ae77Skettenis {
4890b725ae77Skettenis struct type *ptrmemtype;
4891b725ae77Skettenis struct type *class_type;
4892b725ae77Skettenis struct type *functype;
4893b725ae77Skettenis struct type *retvaltype;
4894b725ae77Skettenis int nargs;
4895b725ae77Skettenis int i;
4896b725ae77Skettenis class_type = hpread_type_lookup (dn_bufp->dptrmem.pointsto,
4897b725ae77Skettenis objfile);
4898b725ae77Skettenis functype = hpread_type_lookup (dn_bufp->dptrmem.memtype,
4899b725ae77Skettenis objfile);
4900b725ae77Skettenis retvaltype = TYPE_TARGET_TYPE (functype);
4901b725ae77Skettenis nargs = TYPE_NFIELDS (functype);
4902b725ae77Skettenis ptrmemtype = alloc_type (objfile);
4903b725ae77Skettenis
4904b725ae77Skettenis smash_to_method_type (ptrmemtype, class_type, retvaltype,
4905b725ae77Skettenis TYPE_FIELDS (functype),
4906b725ae77Skettenis TYPE_NFIELDS (functype),
4907b725ae77Skettenis 0);
4908b725ae77Skettenis return make_pointer_type (ptrmemtype, NULL);
4909b725ae77Skettenis }
4910b725ae77Skettenis break;
4911b725ae77Skettenis
4912b725ae77Skettenis case DNTT_TYPE_CLASS:
4913b725ae77Skettenis return hpread_read_struct_type (hp_type, dn_bufp, objfile);
4914b725ae77Skettenis
4915b725ae77Skettenis case DNTT_TYPE_GENFIELD:
4916b725ae77Skettenis /* Chase pointer from GENFIELD to FIELD, and make recursive
4917b725ae77Skettenis * call on that.
4918b725ae77Skettenis */
4919b725ae77Skettenis return hpread_type_lookup (dn_bufp->dgenfield.field, objfile);
4920b725ae77Skettenis
4921b725ae77Skettenis case DNTT_TYPE_VFUNC:
4922b725ae77Skettenis /* C++ virtual function.
4923b725ae77Skettenis * We get here in the course of processing a class type which
4924b725ae77Skettenis * contains virtual functions. Just go through another level
4925b725ae77Skettenis * of indirection to get to the pointed-to function SOM.
4926b725ae77Skettenis */
4927b725ae77Skettenis return hpread_type_lookup (dn_bufp->dvfunc.funcptr, objfile);
4928b725ae77Skettenis
4929b725ae77Skettenis case DNTT_TYPE_MODIFIER:
4930b725ae77Skettenis /* Check the modifiers and then just make a recursive call on
4931b725ae77Skettenis * the "type" pointed to by the modifier DNTT.
4932b725ae77Skettenis *
4933b725ae77Skettenis * pai:: FIXME -- do we ever want to handle "m_duplicate" and
4934b725ae77Skettenis * "m_void" modifiers? Is static_flag really needed here?
4935b725ae77Skettenis * (m_static used for methods of classes, elsewhere).
4936b725ae77Skettenis */
4937b725ae77Skettenis tmp_type = make_cv_type (dn_bufp->dmodifier.m_const,
4938b725ae77Skettenis dn_bufp->dmodifier.m_volatile,
4939b725ae77Skettenis hpread_type_lookup (dn_bufp->dmodifier.type, objfile),
4940b725ae77Skettenis 0);
4941b725ae77Skettenis return tmp_type;
4942b725ae77Skettenis
4943b725ae77Skettenis
4944b725ae77Skettenis case DNTT_TYPE_MEMFUNC:
4945b725ae77Skettenis /* Member function. Treat like a function.
4946b725ae77Skettenis * I think we get here in the course of processing a
4947b725ae77Skettenis * pointer-to-member-function type...
4948b725ae77Skettenis */
4949b725ae77Skettenis return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
4950b725ae77Skettenis
4951b725ae77Skettenis case DNTT_TYPE_DOC_MEMFUNC:
4952b725ae77Skettenis return hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 0);
4953b725ae77Skettenis
4954b725ae77Skettenis case DNTT_TYPE_TEMPLATE:
4955b725ae77Skettenis /* Template - sort of the header for a template definition,
4956b725ae77Skettenis * which like a class, points to a member list and also points
4957b725ae77Skettenis * to a TEMPLATE_ARG list of type-arguments.
4958b725ae77Skettenis */
4959b725ae77Skettenis return hpread_read_struct_type (hp_type, dn_bufp, objfile);
4960b725ae77Skettenis
4961b725ae77Skettenis case DNTT_TYPE_TEMPLATE_ARG:
4962b725ae77Skettenis {
4963b725ae77Skettenis char *name;
4964b725ae77Skettenis /* The TEMPLATE record points to an argument list of
4965b725ae77Skettenis * TEMPLATE_ARG records, each of which describes one
4966b725ae77Skettenis * of the type-arguments.
4967b725ae77Skettenis */
4968b725ae77Skettenis name = VT (objfile) + dn_bufp->dtempl_arg.name;
4969b725ae77Skettenis return hpread_read_templ_arg_type (hp_type, dn_bufp, objfile, name);
4970b725ae77Skettenis }
4971b725ae77Skettenis
4972b725ae77Skettenis case DNTT_TYPE_FUNC_TEMPLATE:
4973b725ae77Skettenis /* We wind up here when processing a TEMPLATE type,
4974b725ae77Skettenis * if the template has member function(s).
4975b725ae77Skettenis * Treat it like a FUNCTION.
4976b725ae77Skettenis */
4977b725ae77Skettenis return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
4978b725ae77Skettenis
4979b725ae77Skettenis case DNTT_TYPE_LINK:
4980b725ae77Skettenis /* The LINK record is used to link up templates with instantiations.
4981b725ae77Skettenis * There is no type associated with the LINK record per se.
4982b725ae77Skettenis */
4983b725ae77Skettenis return lookup_fundamental_type (objfile, FT_VOID);
4984b725ae77Skettenis
4985b725ae77Skettenis /* Also not yet handled... */
4986b725ae77Skettenis /* case DNTT_TYPE_DYN_ARRAY_DESC: */
4987b725ae77Skettenis /* case DNTT_TYPE_DESC_SUBRANGE: */
4988b725ae77Skettenis /* case DNTT_TYPE_BEGIN_EXT: */
4989b725ae77Skettenis /* case DNTT_TYPE_INLN: */
4990b725ae77Skettenis /* case DNTT_TYPE_INLN_LIST: */
4991b725ae77Skettenis /* case DNTT_TYPE_ALIAS: */
4992e93f7393Sniklas default:
4993b725ae77Skettenis /* A fancy way of returning NULL */
4994e93f7393Sniklas return lookup_fundamental_type (objfile, FT_VOID);
4995e93f7393Sniklas }
4996e93f7393Sniklas }
4997e93f7393Sniklas
4998e93f7393Sniklas static sltpointer
hpread_record_lines(struct subfile * subfile,sltpointer s_idx,sltpointer e_idx,struct objfile * objfile,CORE_ADDR offset)4999b725ae77Skettenis hpread_record_lines (struct subfile *subfile, sltpointer s_idx,
5000b725ae77Skettenis sltpointer e_idx, struct objfile *objfile,
5001b725ae77Skettenis CORE_ADDR offset)
5002e93f7393Sniklas {
5003e93f7393Sniklas union sltentry *sl_bufp;
5004e93f7393Sniklas
5005e93f7393Sniklas while (s_idx <= e_idx)
5006e93f7393Sniklas {
5007e93f7393Sniklas sl_bufp = hpread_get_slt (s_idx, objfile);
5008e93f7393Sniklas /* Only record "normal" entries in the SLT. */
5009e93f7393Sniklas if (sl_bufp->snorm.sltdesc == SLT_NORMAL
5010e93f7393Sniklas || sl_bufp->snorm.sltdesc == SLT_EXIT)
5011e93f7393Sniklas record_line (subfile, sl_bufp->snorm.line,
5012e93f7393Sniklas sl_bufp->snorm.address + offset);
5013b725ae77Skettenis else if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET)
5014b725ae77Skettenis record_line (subfile, sl_bufp->snormoff.line,
5015b725ae77Skettenis sl_bufp->snormoff.address + offset);
5016e93f7393Sniklas s_idx++;
5017e93f7393Sniklas }
5018e93f7393Sniklas return e_idx;
5019e93f7393Sniklas }
5020e93f7393Sniklas
5021b725ae77Skettenis /* Given a function "f" which is a member of a class, find
5022b725ae77Skettenis * the classname that it is a member of. Used to construct
5023b725ae77Skettenis * the name (e.g., "c::f") which GDB will put in the
5024b725ae77Skettenis * "demangled name" field of the function's symbol.
5025b725ae77Skettenis * Called from hpread_process_one_debug_symbol()
5026b725ae77Skettenis * If "f" is not a member function, return NULL.
5027b725ae77Skettenis */
5028b725ae77Skettenis static char *
class_of(struct type * functype)5029b725ae77Skettenis class_of (struct type *functype)
5030b725ae77Skettenis {
5031b725ae77Skettenis struct type *first_param_type;
5032b725ae77Skettenis char *first_param_name;
5033b725ae77Skettenis struct type *pointed_to_type;
5034b725ae77Skettenis char *class_name;
5035b725ae77Skettenis
5036b725ae77Skettenis /* Check that the function has a first argument "this",
5037b725ae77Skettenis * and that "this" is a pointer to a class. If not,
5038b725ae77Skettenis * functype is not a member function, so return NULL.
5039b725ae77Skettenis */
5040b725ae77Skettenis if (TYPE_NFIELDS (functype) == 0)
5041b725ae77Skettenis return NULL;
5042b725ae77Skettenis first_param_name = TYPE_FIELD_NAME (functype, 0);
5043b725ae77Skettenis if (first_param_name == NULL)
5044b725ae77Skettenis return NULL; /* paranoia */
5045b725ae77Skettenis if (strcmp (first_param_name, "this"))
5046b725ae77Skettenis return NULL;
5047b725ae77Skettenis first_param_type = TYPE_FIELD_TYPE (functype, 0);
5048b725ae77Skettenis if (first_param_type == NULL)
5049b725ae77Skettenis return NULL; /* paranoia */
5050b725ae77Skettenis if (TYPE_CODE (first_param_type) != TYPE_CODE_PTR)
5051b725ae77Skettenis return NULL;
5052b725ae77Skettenis
5053b725ae77Skettenis /* Get the thing that "this" points to, check that
5054b725ae77Skettenis * it's a class, and get its class name.
5055b725ae77Skettenis */
5056b725ae77Skettenis pointed_to_type = TYPE_TARGET_TYPE (first_param_type);
5057b725ae77Skettenis if (pointed_to_type == NULL)
5058b725ae77Skettenis return NULL; /* paranoia */
5059b725ae77Skettenis if (TYPE_CODE (pointed_to_type) != TYPE_CODE_CLASS)
5060b725ae77Skettenis return NULL;
5061b725ae77Skettenis class_name = TYPE_NAME (pointed_to_type);
5062b725ae77Skettenis if (class_name == NULL)
5063b725ae77Skettenis return NULL; /* paranoia */
5064b725ae77Skettenis
5065b725ae77Skettenis /* The class name may be of the form "class c", in which case
5066b725ae77Skettenis * we want to strip off the leading "class ".
5067b725ae77Skettenis */
5068b725ae77Skettenis if (strncmp (class_name, "class ", 6) == 0)
5069b725ae77Skettenis class_name += 6;
5070b725ae77Skettenis
5071b725ae77Skettenis return class_name;
5072b725ae77Skettenis }
5073b725ae77Skettenis
5074b725ae77Skettenis /* Internalize one native debug symbol.
5075b725ae77Skettenis * Called in a loop from hpread_expand_symtab().
5076b725ae77Skettenis * Arguments:
5077b725ae77Skettenis * dn_bufp:
5078b725ae77Skettenis * name:
5079b725ae77Skettenis * section_offsets:
5080b725ae77Skettenis * objfile:
5081b725ae77Skettenis * text_offset:
5082b725ae77Skettenis * text_size:
5083b725ae77Skettenis * filename:
5084b725ae77Skettenis * index: Index of this symbol
5085b725ae77Skettenis * at_module_boundary_p Pointer to boolean flag to control caller's loop.
5086b725ae77Skettenis */
5087e93f7393Sniklas
5088e93f7393Sniklas static void
hpread_process_one_debug_symbol(union dnttentry * dn_bufp,char * name,struct section_offsets * section_offsets,struct objfile * objfile,CORE_ADDR text_offset,int text_size,char * filename,int index,int * at_module_boundary_p)5089b725ae77Skettenis hpread_process_one_debug_symbol (union dnttentry *dn_bufp, char *name,
5090b725ae77Skettenis struct section_offsets *section_offsets,
5091b725ae77Skettenis struct objfile *objfile, CORE_ADDR text_offset,
5092b725ae77Skettenis int text_size, char *filename, int index,
5093b725ae77Skettenis int *at_module_boundary_p)
5094e93f7393Sniklas {
5095e93f7393Sniklas unsigned long desc;
5096e93f7393Sniklas int type;
5097e93f7393Sniklas CORE_ADDR valu;
5098b725ae77Skettenis int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
5099b725ae77Skettenis int data_offset = ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
5100e93f7393Sniklas union dnttentry *dn_temp;
5101e93f7393Sniklas dnttpointer hp_type;
5102e93f7393Sniklas struct symbol *sym;
5103e93f7393Sniklas struct context_stack *new;
5104b725ae77Skettenis char *class_scope_name;
5105e93f7393Sniklas
5106e93f7393Sniklas /* Allocate one GDB debug symbol and fill in some default values. */
5107b725ae77Skettenis sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
5108e93f7393Sniklas sizeof (struct symbol));
5109e93f7393Sniklas memset (sym, 0, sizeof (struct symbol));
5110b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->objfile_obstack);
5111e93f7393Sniklas SYMBOL_LANGUAGE (sym) = language_auto;
5112b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5113e93f7393Sniklas SYMBOL_LINE (sym) = 0;
5114e93f7393Sniklas SYMBOL_VALUE (sym) = 0;
5115e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5116e93f7393Sniklas
5117b725ae77Skettenis /* Just a trick in case the SOM debug symbol is a type definition.
5118b725ae77Skettenis * There are routines that are set up to build a GDB type symbol, given
5119b725ae77Skettenis * a SOM dnttpointer. So we set up a dummy SOM dnttpointer "hp_type".
5120b725ae77Skettenis * This allows us to call those same routines.
5121b725ae77Skettenis */
5122e93f7393Sniklas hp_type.dnttp.extension = 1;
5123e93f7393Sniklas hp_type.dnttp.immediate = 0;
5124e93f7393Sniklas hp_type.dnttp.global = 0;
5125e93f7393Sniklas hp_type.dnttp.index = index;
5126e93f7393Sniklas
5127b725ae77Skettenis /* This "type" is the type of SOM record.
5128b725ae77Skettenis * Switch on SOM type.
5129b725ae77Skettenis */
5130e93f7393Sniklas type = dn_bufp->dblock.kind;
5131e93f7393Sniklas switch (type)
5132e93f7393Sniklas {
5133e93f7393Sniklas case DNTT_TYPE_SRCFILE:
5134b725ae77Skettenis /* This type of symbol indicates from which source file or
5135b725ae77Skettenis * include file any following data comes. It may indicate:
5136b725ae77Skettenis *
5137b725ae77Skettenis * o The start of an entirely new source file (and thus
5138b725ae77Skettenis * a new module)
5139b725ae77Skettenis *
5140b725ae77Skettenis * o The start of a different source file due to #include
5141b725ae77Skettenis *
5142b725ae77Skettenis * o The end of an include file and the return to the original
5143b725ae77Skettenis * file. Thus if "foo.c" includes "bar.h", we see first
5144b725ae77Skettenis * a SRCFILE for foo.c, then one for bar.h, and then one for
5145b725ae77Skettenis * foo.c again.
5146b725ae77Skettenis *
5147b725ae77Skettenis * If it indicates the start of a new module then we must
5148b725ae77Skettenis * finish the symbol table of the previous module
5149b725ae77Skettenis * (if any) and start accumulating a new symbol table.
5150b725ae77Skettenis */
5151e93f7393Sniklas
5152e93f7393Sniklas valu = text_offset;
5153e93f7393Sniklas if (!last_source_file)
5154e93f7393Sniklas {
5155b725ae77Skettenis /*
5156b725ae77Skettenis * A note on "last_source_file": this is a char* pointing
5157b725ae77Skettenis * to the actual file name. "start_symtab" sets it,
5158b725ae77Skettenis * "end_symtab" clears it.
5159b725ae77Skettenis *
5160b725ae77Skettenis * So if "last_source_file" is NULL, then either this is
5161b725ae77Skettenis * the first record we are looking at, or a previous call
5162b725ae77Skettenis * to "end_symtab()" was made to close out the previous
5163b725ae77Skettenis * module. Since we're now quitting the scan loop when we
5164b725ae77Skettenis * see a MODULE END record, we should never get here, except
5165b725ae77Skettenis * in the case that we're not using the quick look-up tables
5166b725ae77Skettenis * and have to use the old system as a fall-back.
5167b725ae77Skettenis */
5168e93f7393Sniklas start_symtab (name, NULL, valu);
5169b725ae77Skettenis record_debugformat ("HP");
5170e93f7393Sniklas SL_INDEX (objfile) = dn_bufp->dsfile.address;
5171e93f7393Sniklas }
5172b725ae77Skettenis
5173e93f7393Sniklas else
5174e93f7393Sniklas {
5175b725ae77Skettenis /* Either a new include file, or a SRCFILE record
5176b725ae77Skettenis * saying we are back in the main source (or out of
5177b725ae77Skettenis * a nested include file) again.
5178b725ae77Skettenis */
5179e93f7393Sniklas SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5180e93f7393Sniklas SL_INDEX (objfile),
5181e93f7393Sniklas dn_bufp->dsfile.address,
5182e93f7393Sniklas objfile, offset);
5183e93f7393Sniklas }
5184b725ae77Skettenis
5185b725ae77Skettenis /* A note on "start_subfile". This routine will check
5186b725ae77Skettenis * the name we pass it and look for an existing subfile
5187b725ae77Skettenis * of that name. There's thus only one sub-file for the
5188b725ae77Skettenis * actual source (e.g. for "foo.c" in foo.c), despite the
5189b725ae77Skettenis * fact that we'll see lots of SRCFILE entries for foo.c
5190b725ae77Skettenis * inside foo.c.
5191b725ae77Skettenis */
5192e93f7393Sniklas start_subfile (name, NULL);
5193e93f7393Sniklas break;
5194e93f7393Sniklas
5195e93f7393Sniklas case DNTT_TYPE_MODULE:
5196b725ae77Skettenis /*
5197b725ae77Skettenis * We no longer ignore DNTT_TYPE_MODULE symbols. The module
5198b725ae77Skettenis * represents the meaningful semantic structure of a compilation
5199b725ae77Skettenis * unit. We expect to start the psymtab-to-symtab expansion
5200b725ae77Skettenis * looking at a MODULE entry, and to end it at the corresponding
5201b725ae77Skettenis * END MODULE entry.
5202b725ae77Skettenis *
5203b725ae77Skettenis *--Begin outdated comments
5204b725ae77Skettenis *
5205b725ae77Skettenis * This record signifies the start of a new source module
5206b725ae77Skettenis * In C/C++ there is no explicit "module" construct in the language,
5207b725ae77Skettenis * but each compilation unit is implicitly a module and they
5208b725ae77Skettenis * do emit the DNTT_TYPE_MODULE records.
5209b725ae77Skettenis * The end of the module is marked by a matching DNTT_TYPE_END record.
5210b725ae77Skettenis *
5211b725ae77Skettenis * The reason GDB gets away with ignoring the DNTT_TYPE_MODULE record
5212b725ae77Skettenis * is it notices the DNTT_TYPE_END record for the previous
5213b725ae77Skettenis * module (see comments under DNTT_TYPE_END case), and then treats
5214b725ae77Skettenis * the next DNTT_TYPE_SRCFILE record as if it were the module-start record.
5215b725ae77Skettenis * (i.e., it makes a start_symtab() call).
5216b725ae77Skettenis * This scheme seems a little convoluted, but I'll leave it
5217b725ae77Skettenis * alone on the principle "if it ain't broke don't fix
5218b725ae77Skettenis * it". (RT).
5219b725ae77Skettenis *
5220b725ae77Skettenis *-- End outdated comments
5221b725ae77Skettenis */
5222b725ae77Skettenis
5223b725ae77Skettenis valu = text_offset;
5224b725ae77Skettenis if (!last_source_file)
5225b725ae77Skettenis {
5226b725ae77Skettenis /* Start of a new module. We know this because "last_source_file"
5227b725ae77Skettenis * is NULL, which can only happen the first time or if we just
5228b725ae77Skettenis * made a call to end_symtab() to close out the previous module.
5229b725ae77Skettenis */
5230b725ae77Skettenis start_symtab (name, NULL, valu);
5231b725ae77Skettenis SL_INDEX (objfile) = dn_bufp->dmodule.address;
5232b725ae77Skettenis }
5233b725ae77Skettenis else
5234b725ae77Skettenis {
5235b725ae77Skettenis /* This really shouldn't happen if we're using the quick
5236b725ae77Skettenis * look-up tables, as it would mean we'd scanned past an
5237b725ae77Skettenis * END MODULE entry. But if we're not using the tables,
5238b725ae77Skettenis * we started the module on the SRCFILE entry, so it's ok.
5239b725ae77Skettenis * For now, accept this.
5240b725ae77Skettenis */
5241b725ae77Skettenis /* warning( "Error expanding psymtab, missed module end, found entry for %s",
5242b725ae77Skettenis * name );
5243b725ae77Skettenis */
5244b725ae77Skettenis *at_module_boundary_p = -1;
5245b725ae77Skettenis }
5246b725ae77Skettenis
5247b725ae77Skettenis start_subfile (name, NULL);
5248e93f7393Sniklas break;
5249e93f7393Sniklas
5250e93f7393Sniklas case DNTT_TYPE_FUNCTION:
5251e93f7393Sniklas case DNTT_TYPE_ENTRY:
5252e93f7393Sniklas /* A function or secondary entry point. */
5253e93f7393Sniklas valu = dn_bufp->dfunc.lowaddr + offset;
5254b725ae77Skettenis
5255b725ae77Skettenis /* Record lines up to this point. */
5256e93f7393Sniklas SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5257e93f7393Sniklas SL_INDEX (objfile),
5258e93f7393Sniklas dn_bufp->dfunc.address,
5259e93f7393Sniklas objfile, offset);
5260e93f7393Sniklas
5261e93f7393Sniklas WITHIN_FUNCTION (objfile) = 1;
5262e93f7393Sniklas CURRENT_FUNCTION_VALUE (objfile) = valu;
5263e93f7393Sniklas
5264e93f7393Sniklas /* Stack must be empty now. */
5265e93f7393Sniklas if (context_stack_depth != 0)
5266b725ae77Skettenis lbrac_unmatched_complaint (symnum);
5267e93f7393Sniklas new = push_context (0, valu);
5268e93f7393Sniklas
5269b725ae77Skettenis /* Built a type for the function. This includes processing
5270b725ae77Skettenis * the symbol records for the function parameters.
5271b725ae77Skettenis */
5272e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_BLOCK;
5273b725ae77Skettenis SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile, 1);
5274b725ae77Skettenis
5275b725ae77Skettenis /* All functions in C++ have prototypes. For C we don't have enough
5276b725ae77Skettenis information in the debug info. */
5277b725ae77Skettenis if (SYMBOL_LANGUAGE (sym) == language_cplus)
5278b725ae77Skettenis TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
5279b725ae77Skettenis
5280b725ae77Skettenis /* The "DEPRECATED_SYMBOL_NAME" field is expected to be the mangled name
5281b725ae77Skettenis * (if any), which we get from the "alias" field of the SOM record
5282b725ae77Skettenis * if that exists.
5283b725ae77Skettenis */
5284b725ae77Skettenis if ((dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) &&
5285b725ae77Skettenis dn_bufp->dfunc.alias && /* has an alias */
5286b725ae77Skettenis *(char *) (VT (objfile) + dn_bufp->dfunc.alias)) /* not a null string */
5287b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.alias;
5288b725ae77Skettenis else
5289b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.name;
5290b725ae77Skettenis
5291b725ae77Skettenis /* Special hack to get around HP compilers' insistence on
5292b725ae77Skettenis * reporting "main" as "_MAIN_" for C/C++ */
5293b725ae77Skettenis if ((strcmp (DEPRECATED_SYMBOL_NAME (sym), "_MAIN_") == 0) &&
5294b725ae77Skettenis (strcmp (VT (objfile) + dn_bufp->dfunc.name, "main") == 0))
5295b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.name;
5296b725ae77Skettenis
5297b725ae77Skettenis /* The SYMBOL_CPLUS_DEMANGLED_NAME field is expected to
5298b725ae77Skettenis * be the demangled name.
5299b725ae77Skettenis */
5300b725ae77Skettenis if (dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS)
5301b725ae77Skettenis {
5302b725ae77Skettenis /* SYMBOL_INIT_DEMANGLED_NAME is a macro which winds up
5303b725ae77Skettenis * calling the demangler in libiberty (cplus_demangle()) to
5304b725ae77Skettenis * do the job. This generally does the job, even though
5305b725ae77Skettenis * it's intended for the GNU compiler and not the aCC compiler
5306b725ae77Skettenis * Note that SYMBOL_INIT_DEMANGLED_NAME calls the
5307b725ae77Skettenis * demangler with arguments DMGL_PARAMS | DMGL_ANSI.
5308b725ae77Skettenis * Generally, we don't want params when we display
5309b725ae77Skettenis * a demangled name, but when I took out the DMGL_PARAMS,
5310b725ae77Skettenis * some things broke, so I'm leaving it in here, and
5311b725ae77Skettenis * working around the issue in stack.c. - RT
5312b725ae77Skettenis */
5313b725ae77Skettenis SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->objfile_obstack);
5314b725ae77Skettenis if ((DEPRECATED_SYMBOL_NAME (sym) == VT (objfile) + dn_bufp->dfunc.alias) &&
5315b725ae77Skettenis (!SYMBOL_CPLUS_DEMANGLED_NAME (sym)))
5316b725ae77Skettenis {
5317b725ae77Skettenis
5318b725ae77Skettenis /* Well, the symbol name is mangled, but the
5319b725ae77Skettenis * demangler in libiberty failed so the demangled
5320b725ae77Skettenis * field is still NULL. Try to
5321b725ae77Skettenis * do the job ourselves based on the "name" field
5322b725ae77Skettenis * in the SOM record. A complication here is that
5323b725ae77Skettenis * the name field contains only the function name
5324b725ae77Skettenis * (like "f"), whereas we want the class qualification
5325b725ae77Skettenis * (as in "c::f"). Try to reconstruct that.
5326b725ae77Skettenis */
5327b725ae77Skettenis char *basename;
5328b725ae77Skettenis char *classname;
5329b725ae77Skettenis char *dem_name;
5330b725ae77Skettenis basename = VT (objfile) + dn_bufp->dfunc.name;
5331b725ae77Skettenis classname = class_of (SYMBOL_TYPE (sym));
5332b725ae77Skettenis if (classname)
5333b725ae77Skettenis {
5334b725ae77Skettenis dem_name = xmalloc (strlen (basename) + strlen (classname) + 3);
5335b725ae77Skettenis strcpy (dem_name, classname);
5336b725ae77Skettenis strcat (dem_name, "::");
5337b725ae77Skettenis strcat (dem_name, basename);
5338b725ae77Skettenis SYMBOL_CPLUS_DEMANGLED_NAME (sym) = dem_name;
5339b725ae77Skettenis SYMBOL_LANGUAGE (sym) = language_cplus;
5340b725ae77Skettenis }
5341b725ae77Skettenis }
5342b725ae77Skettenis }
5343b725ae77Skettenis
5344b725ae77Skettenis /* Add the function symbol to the list of symbols in this blockvector */
5345e93f7393Sniklas if (dn_bufp->dfunc.global)
5346e93f7393Sniklas add_symbol_to_list (sym, &global_symbols);
5347e93f7393Sniklas else
5348e93f7393Sniklas add_symbol_to_list (sym, &file_symbols);
5349e93f7393Sniklas new->name = sym;
5350e93f7393Sniklas
5351b725ae77Skettenis /* Search forward to the next BEGIN and also read
5352b725ae77Skettenis * in the line info up to that point.
5353b725ae77Skettenis * Not sure why this is needed.
5354b725ae77Skettenis * In HP FORTRAN this code is harmful since there
5355b725ae77Skettenis * may not be a BEGIN after the FUNCTION.
5356b725ae77Skettenis * So I made it C/C++ specific. - RT
5357b725ae77Skettenis */
5358b725ae77Skettenis if (dn_bufp->dfunc.language == HP_LANGUAGE_C ||
5359b725ae77Skettenis dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS)
5360b725ae77Skettenis {
5361e93f7393Sniklas while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
5362e93f7393Sniklas {
5363e93f7393Sniklas dn_bufp = hpread_get_lntt (++index, objfile);
5364e93f7393Sniklas if (dn_bufp->dblock.extension)
5365e93f7393Sniklas continue;
5366e93f7393Sniklas }
5367e93f7393Sniklas SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5368e93f7393Sniklas SL_INDEX (objfile),
5369e93f7393Sniklas dn_bufp->dbegin.address,
5370e93f7393Sniklas objfile, offset);
5371e93f7393Sniklas SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
5372b725ae77Skettenis }
5373b725ae77Skettenis record_line (current_subfile, SYMBOL_LINE (sym), valu);
5374b725ae77Skettenis break;
5375b725ae77Skettenis
5376b725ae77Skettenis case DNTT_TYPE_DOC_FUNCTION:
5377b725ae77Skettenis valu = dn_bufp->ddocfunc.lowaddr + offset;
5378b725ae77Skettenis
5379b725ae77Skettenis /* Record lines up to this point. */
5380b725ae77Skettenis SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5381b725ae77Skettenis SL_INDEX (objfile),
5382b725ae77Skettenis dn_bufp->ddocfunc.address,
5383b725ae77Skettenis objfile, offset);
5384b725ae77Skettenis
5385b725ae77Skettenis WITHIN_FUNCTION (objfile) = 1;
5386b725ae77Skettenis CURRENT_FUNCTION_VALUE (objfile) = valu;
5387b725ae77Skettenis /* Stack must be empty now. */
5388b725ae77Skettenis if (context_stack_depth != 0)
5389b725ae77Skettenis lbrac_unmatched_complaint (symnum);
5390b725ae77Skettenis new = push_context (0, valu);
5391b725ae77Skettenis
5392b725ae77Skettenis /* Built a type for the function. This includes processing
5393b725ae77Skettenis * the symbol records for the function parameters.
5394b725ae77Skettenis */
5395b725ae77Skettenis SYMBOL_CLASS (sym) = LOC_BLOCK;
5396b725ae77Skettenis SYMBOL_TYPE (sym) = hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 1);
5397b725ae77Skettenis
5398b725ae77Skettenis /* The "DEPRECATED_SYMBOL_NAME" field is expected to be the mangled name
5399b725ae77Skettenis * (if any), which we get from the "alias" field of the SOM record
5400b725ae77Skettenis * if that exists.
5401b725ae77Skettenis */
5402b725ae77Skettenis if ((dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS) &&
5403b725ae77Skettenis dn_bufp->ddocfunc.alias && /* has an alias */
5404b725ae77Skettenis *(char *) (VT (objfile) + dn_bufp->ddocfunc.alias)) /* not a null string */
5405b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.alias;
5406b725ae77Skettenis else
5407b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.name;
5408b725ae77Skettenis
5409b725ae77Skettenis /* Special hack to get around HP compilers' insistence on
5410b725ae77Skettenis * reporting "main" as "_MAIN_" for C/C++ */
5411b725ae77Skettenis if ((strcmp (DEPRECATED_SYMBOL_NAME (sym), "_MAIN_") == 0) &&
5412b725ae77Skettenis (strcmp (VT (objfile) + dn_bufp->ddocfunc.name, "main") == 0))
5413b725ae77Skettenis DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.name;
5414b725ae77Skettenis
5415b725ae77Skettenis if (dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS)
5416b725ae77Skettenis {
5417b725ae77Skettenis
5418b725ae77Skettenis /* SYMBOL_INIT_DEMANGLED_NAME is a macro which winds up
5419b725ae77Skettenis * calling the demangler in libiberty (cplus_demangle()) to
5420b725ae77Skettenis * do the job. This generally does the job, even though
5421b725ae77Skettenis * it's intended for the GNU compiler and not the aCC compiler
5422b725ae77Skettenis * Note that SYMBOL_INIT_DEMANGLED_NAME calls the
5423b725ae77Skettenis * demangler with arguments DMGL_PARAMS | DMGL_ANSI.
5424b725ae77Skettenis * Generally, we don't want params when we display
5425b725ae77Skettenis * a demangled name, but when I took out the DMGL_PARAMS,
5426b725ae77Skettenis * some things broke, so I'm leaving it in here, and
5427b725ae77Skettenis * working around the issue in stack.c. - RT
5428b725ae77Skettenis */
5429b725ae77Skettenis SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->objfile_obstack);
5430b725ae77Skettenis
5431b725ae77Skettenis if ((DEPRECATED_SYMBOL_NAME (sym) == VT (objfile) + dn_bufp->ddocfunc.alias) &&
5432b725ae77Skettenis (!SYMBOL_CPLUS_DEMANGLED_NAME (sym)))
5433b725ae77Skettenis {
5434b725ae77Skettenis
5435b725ae77Skettenis /* Well, the symbol name is mangled, but the
5436b725ae77Skettenis * demangler in libiberty failed so the demangled
5437b725ae77Skettenis * field is still NULL. Try to
5438b725ae77Skettenis * do the job ourselves based on the "name" field
5439b725ae77Skettenis * in the SOM record. A complication here is that
5440b725ae77Skettenis * the name field contains only the function name
5441b725ae77Skettenis * (like "f"), whereas we want the class qualification
5442b725ae77Skettenis * (as in "c::f"). Try to reconstruct that.
5443b725ae77Skettenis */
5444b725ae77Skettenis char *basename;
5445b725ae77Skettenis char *classname;
5446b725ae77Skettenis char *dem_name;
5447b725ae77Skettenis basename = VT (objfile) + dn_bufp->ddocfunc.name;
5448b725ae77Skettenis classname = class_of (SYMBOL_TYPE (sym));
5449b725ae77Skettenis if (classname)
5450b725ae77Skettenis {
5451b725ae77Skettenis dem_name = xmalloc (strlen (basename) + strlen (classname) + 3);
5452b725ae77Skettenis strcpy (dem_name, classname);
5453b725ae77Skettenis strcat (dem_name, "::");
5454b725ae77Skettenis strcat (dem_name, basename);
5455b725ae77Skettenis SYMBOL_CPLUS_DEMANGLED_NAME (sym) = dem_name;
5456b725ae77Skettenis SYMBOL_LANGUAGE (sym) = language_cplus;
5457b725ae77Skettenis }
5458b725ae77Skettenis }
5459b725ae77Skettenis }
5460b725ae77Skettenis
5461b725ae77Skettenis /* Add the function symbol to the list of symbols in this blockvector */
5462b725ae77Skettenis if (dn_bufp->ddocfunc.global)
5463b725ae77Skettenis add_symbol_to_list (sym, &global_symbols);
5464b725ae77Skettenis else
5465b725ae77Skettenis add_symbol_to_list (sym, &file_symbols);
5466b725ae77Skettenis new->name = sym;
5467b725ae77Skettenis
5468b725ae77Skettenis /* Search forward to the next BEGIN and also read
5469b725ae77Skettenis * in the line info up to that point.
5470b725ae77Skettenis * Not sure why this is needed.
5471b725ae77Skettenis * In HP FORTRAN this code is harmful since there
5472b725ae77Skettenis * may not be a BEGIN after the FUNCTION.
5473b725ae77Skettenis * So I made it C/C++ specific. - RT
5474b725ae77Skettenis */
5475b725ae77Skettenis if (dn_bufp->ddocfunc.language == HP_LANGUAGE_C ||
5476b725ae77Skettenis dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS)
5477b725ae77Skettenis {
5478b725ae77Skettenis while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
5479b725ae77Skettenis {
5480b725ae77Skettenis dn_bufp = hpread_get_lntt (++index, objfile);
5481b725ae77Skettenis if (dn_bufp->dblock.extension)
5482b725ae77Skettenis continue;
5483b725ae77Skettenis }
5484b725ae77Skettenis SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5485b725ae77Skettenis SL_INDEX (objfile),
5486b725ae77Skettenis dn_bufp->dbegin.address,
5487b725ae77Skettenis objfile, offset);
5488b725ae77Skettenis SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
5489b725ae77Skettenis }
5490e93f7393Sniklas record_line (current_subfile, SYMBOL_LINE (sym), valu);
5491e93f7393Sniklas break;
5492e93f7393Sniklas
5493e93f7393Sniklas case DNTT_TYPE_BEGIN:
5494e93f7393Sniklas /* Begin a new scope. */
5495b725ae77Skettenis if (context_stack_depth == 1 /* this means we're at function level */ &&
5496b725ae77Skettenis context_stack[0].name != NULL /* this means it's a function */ &&
5497b725ae77Skettenis context_stack[0].depth == 0 /* this means it's the first BEGIN
5498b725ae77Skettenis we've seen after the FUNCTION */
5499b725ae77Skettenis )
5500b725ae77Skettenis {
5501b725ae77Skettenis /* This is the first BEGIN after a FUNCTION.
5502b725ae77Skettenis * We ignore this one, since HP compilers always insert
5503b725ae77Skettenis * at least one BEGIN, i.e. it's:
5504b725ae77Skettenis *
5505b725ae77Skettenis * FUNCTION
5506b725ae77Skettenis * argument symbols
5507b725ae77Skettenis * BEGIN
5508b725ae77Skettenis * local symbols
5509b725ae77Skettenis * (possibly nested BEGIN ... END's if there are inner { } blocks)
5510b725ae77Skettenis * END
5511b725ae77Skettenis * END
5512b725ae77Skettenis *
5513b725ae77Skettenis * By ignoring this first BEGIN, the local symbols get treated
5514b725ae77Skettenis * as belonging to the function scope, and "print func::local_sym"
5515b725ae77Skettenis * works (which is what we want).
5516b725ae77Skettenis */
5517b725ae77Skettenis
5518b725ae77Skettenis /* All we do here is increase the depth count associated with
5519b725ae77Skettenis * the FUNCTION entry in the context stack. This ensures that
5520b725ae77Skettenis * the next BEGIN we see (if any), representing a real nested { }
5521b725ae77Skettenis * block, will get processed.
5522b725ae77Skettenis */
5523b725ae77Skettenis
5524b725ae77Skettenis context_stack[0].depth++;
5525b725ae77Skettenis
5526b725ae77Skettenis }
5527b725ae77Skettenis else
5528b725ae77Skettenis {
5529b725ae77Skettenis
5530b725ae77Skettenis /* Record lines up to this SLT pointer. */
5531e93f7393Sniklas SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5532e93f7393Sniklas SL_INDEX (objfile),
5533e93f7393Sniklas dn_bufp->dbegin.address,
5534e93f7393Sniklas objfile, offset);
5535b725ae77Skettenis /* Calculate start address of new scope */
5536e93f7393Sniklas valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
5537e93f7393Sniklas valu += offset; /* Relocate for dynamic loading */
5538b725ae77Skettenis /* We use the scope start DNTT index as nesting depth identifier! */
5539b725ae77Skettenis desc = hpread_get_scope_start (dn_bufp->dbegin.address, objfile);
5540e93f7393Sniklas new = push_context (desc, valu);
5541b725ae77Skettenis }
5542e93f7393Sniklas break;
5543e93f7393Sniklas
5544e93f7393Sniklas case DNTT_TYPE_END:
5545e93f7393Sniklas /* End a scope. */
5546b725ae77Skettenis
5547b725ae77Skettenis /* Valid end kinds are:
5548b725ae77Skettenis * MODULE
5549b725ae77Skettenis * FUNCTION
5550b725ae77Skettenis * WITH
5551b725ae77Skettenis * COMMON
5552b725ae77Skettenis * BEGIN
5553b725ae77Skettenis * CLASS_SCOPE
5554b725ae77Skettenis */
5555b725ae77Skettenis
5556e93f7393Sniklas SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5557e93f7393Sniklas SL_INDEX (objfile),
5558b725ae77Skettenis dn_bufp->dend.address,
5559e93f7393Sniklas objfile, offset);
5560e93f7393Sniklas switch (dn_bufp->dend.endkind)
5561e93f7393Sniklas {
5562e93f7393Sniklas case DNTT_TYPE_MODULE:
5563b725ae77Skettenis /* Ending a module ends the symbol table for that module.
5564b725ae77Skettenis * Calling end_symtab() has the side effect of clearing the
5565b725ae77Skettenis * last_source_file pointer, which in turn signals
5566b725ae77Skettenis * process_one_debug_symbol() to treat the next DNTT_TYPE_SRCFILE
5567b725ae77Skettenis * record as a module-begin.
5568b725ae77Skettenis */
5569e93f7393Sniklas valu = text_offset + text_size + offset;
5570b725ae77Skettenis
5571b725ae77Skettenis /* Tell our caller that we're done with expanding the
5572b725ae77Skettenis * debug information for a module.
5573b725ae77Skettenis */
5574b725ae77Skettenis *at_module_boundary_p = 1;
5575b725ae77Skettenis
5576b725ae77Skettenis /* Don't do this, as our caller will do it!
5577b725ae77Skettenis
5578b725ae77Skettenis * (void) end_symtab (valu, objfile, 0);
5579b725ae77Skettenis */
5580e93f7393Sniklas break;
5581e93f7393Sniklas
5582e93f7393Sniklas case DNTT_TYPE_FUNCTION:
5583e93f7393Sniklas /* Ending a function, well, ends the function's scope. */
5584e93f7393Sniklas dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
5585e93f7393Sniklas objfile);
5586e93f7393Sniklas valu = dn_temp->dfunc.hiaddr + offset;
5587b725ae77Skettenis /* Insert func params into local list */
5588b725ae77Skettenis merge_symbol_lists (¶m_symbols, &local_symbols);
5589e93f7393Sniklas new = pop_context ();
5590e93f7393Sniklas /* Make a block for the local symbols within. */
5591e93f7393Sniklas finish_block (new->name, &local_symbols, new->old_blocks,
5592e93f7393Sniklas new->start_addr, valu, objfile);
5593b725ae77Skettenis WITHIN_FUNCTION (objfile) = 0; /* This may have to change for Pascal */
5594b725ae77Skettenis local_symbols = new->locals;
5595b725ae77Skettenis param_symbols = new->params;
5596e93f7393Sniklas break;
5597b725ae77Skettenis
5598e93f7393Sniklas case DNTT_TYPE_BEGIN:
5599b725ae77Skettenis if (context_stack_depth == 1 &&
5600b725ae77Skettenis context_stack[0].name != NULL &&
5601b725ae77Skettenis context_stack[0].depth == 1)
5602b725ae77Skettenis {
5603b725ae77Skettenis /* This is the END corresponding to the
5604b725ae77Skettenis * BEGIN which we ignored - see DNTT_TYPE_BEGIN case above.
5605b725ae77Skettenis */
5606b725ae77Skettenis context_stack[0].depth--;
5607b725ae77Skettenis }
5608b725ae77Skettenis else
5609b725ae77Skettenis {
5610b725ae77Skettenis /* Ending a local scope. */
5611e93f7393Sniklas valu = hpread_get_location (dn_bufp->dend.address, objfile);
5612e93f7393Sniklas /* Why in the hell is this needed? */
5613e93f7393Sniklas valu += offset + 9; /* Relocate for dynamic loading */
5614e93f7393Sniklas new = pop_context ();
5615e93f7393Sniklas desc = dn_bufp->dend.beginscope.dnttp.index;
5616e93f7393Sniklas if (desc != new->depth)
5617b725ae77Skettenis lbrac_mismatch_complaint (symnum);
5618b725ae77Skettenis
5619e93f7393Sniklas /* Make a block for the local symbols within. */
5620e93f7393Sniklas finish_block (new->name, &local_symbols, new->old_blocks,
5621e93f7393Sniklas new->start_addr, valu, objfile);
5622e93f7393Sniklas local_symbols = new->locals;
5623b725ae77Skettenis param_symbols = new->params;
5624b725ae77Skettenis }
5625b725ae77Skettenis break;
5626b725ae77Skettenis
5627b725ae77Skettenis case DNTT_TYPE_WITH:
5628b725ae77Skettenis /* Since we ignore the DNTT_TYPE_WITH that starts the scope,
5629b725ae77Skettenis * we can ignore the DNTT_TYPE_END that ends it.
5630b725ae77Skettenis */
5631b725ae77Skettenis break;
5632b725ae77Skettenis
5633b725ae77Skettenis case DNTT_TYPE_COMMON:
5634b725ae77Skettenis /* End a FORTRAN common block. We don't currently handle these */
5635b725ae77Skettenis complaint (&symfile_complaints,
5636b725ae77Skettenis "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_COMMON/DNTT_TYPE_END.\n");
5637b725ae77Skettenis break;
5638b725ae77Skettenis
5639b725ae77Skettenis case DNTT_TYPE_CLASS_SCOPE:
5640b725ae77Skettenis
5641b725ae77Skettenis /* pai: FIXME Not handling nested classes for now -- must
5642b725ae77Skettenis * maintain a stack */
5643b725ae77Skettenis class_scope_name = NULL;
5644b725ae77Skettenis
5645b725ae77Skettenis #if 0
5646b725ae77Skettenis /* End a class scope */
5647b725ae77Skettenis valu = hpread_get_location (dn_bufp->dend.address, objfile);
5648b725ae77Skettenis /* Why in the hell is this needed? */
5649b725ae77Skettenis valu += offset + 9; /* Relocate for dynamic loading */
5650b725ae77Skettenis new = pop_context ();
5651b725ae77Skettenis desc = dn_bufp->dend.beginscope.dnttp.index;
5652b725ae77Skettenis if (desc != new->depth)
5653b725ae77Skettenis lbrac_mismatch_complaint ((char *) symnum);
5654b725ae77Skettenis /* Make a block for the local symbols within. */
5655b725ae77Skettenis finish_block (new->name, &local_symbols, new->old_blocks,
5656b725ae77Skettenis new->start_addr, valu, objfile);
5657b725ae77Skettenis local_symbols = new->locals;
5658b725ae77Skettenis param_symbols = new->params;
5659b725ae77Skettenis #endif
5660b725ae77Skettenis break;
5661b725ae77Skettenis
5662b725ae77Skettenis default:
5663b725ae77Skettenis complaint (&symfile_complaints,
5664b725ae77Skettenis "internal error in hp-symtab-read.c: Unexpected DNTT_TYPE_END kind.");
5665e93f7393Sniklas break;
5666e93f7393Sniklas }
5667e93f7393Sniklas break;
5668b725ae77Skettenis
5669b725ae77Skettenis /* DNTT_TYPE_IMPORT is not handled */
5670b725ae77Skettenis
5671e93f7393Sniklas case DNTT_TYPE_LABEL:
5672b725ae77Skettenis SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
5673e93f7393Sniklas break;
5674b725ae77Skettenis
5675e93f7393Sniklas case DNTT_TYPE_FPARAM:
5676e93f7393Sniklas /* Function parameters. */
5677b725ae77Skettenis /* Note 1: This code was present in the 4.16 sources, and then
5678b725ae77Skettenis removed, because fparams are handled in
5679b725ae77Skettenis hpread_read_function_type(). However, while fparam symbols
5680b725ae77Skettenis are indeed handled twice, this code here cannot be removed
5681b725ae77Skettenis because then they don't get added to the local symbol list of
5682b725ae77Skettenis the function's code block, which leads to a failure to look
5683b725ae77Skettenis up locals, "this"-relative member names, etc. So I've put
5684b725ae77Skettenis this code back in. pai/1997-07-21 */
5685b725ae77Skettenis /* Note 2: To fix a defect, we stopped adding FPARAMS to local_symbols
5686b725ae77Skettenis in hpread_read_function_type(), so FPARAMS had to be handled
5687b725ae77Skettenis here. I changed the location to be the appropriate argument
5688b725ae77Skettenis kinds rather than LOC_LOCAL. pai/1997-08-08 */
5689b725ae77Skettenis /* Note 3: Well, the fix in Note 2 above broke argument printing
5690b725ae77Skettenis in traceback frames, and further it makes assumptions about the
5691b725ae77Skettenis order of the FPARAM entries from HP compilers (cc and aCC in particular
5692b725ae77Skettenis generate them in reverse orders -- fixing one breaks for the other).
5693b725ae77Skettenis So I've added code in hpread_read_function_type() to add fparams
5694b725ae77Skettenis to a param_symbols list for the current context level. These are
5695b725ae77Skettenis then merged into local_symbols when a function end is reached.
5696b725ae77Skettenis pai/1997-08-11 */
5697b725ae77Skettenis
5698b725ae77Skettenis break; /* do nothing; handled in hpread_read_function_type() */
5699b725ae77Skettenis
5700b725ae77Skettenis #if 0 /* Old code */
5701e93f7393Sniklas if (dn_bufp->dfparam.regparam)
5702e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_REGISTER;
5703b725ae77Skettenis else if (dn_bufp->dfparam.indirect)
5704b725ae77Skettenis SYMBOL_CLASS (sym) = LOC_REF_ARG;
5705e93f7393Sniklas else
5706b725ae77Skettenis SYMBOL_CLASS (sym) = LOC_ARG;
5707b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5708e93f7393Sniklas if (dn_bufp->dfparam.copyparam)
5709e93f7393Sniklas {
5710e93f7393Sniklas SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
5711e93f7393Sniklas SYMBOL_VALUE (sym)
5712*63addd46Skettenis += hpread_adjust_stack_address (CURRENT_FUNCTION_VALUE (objfile));
5713e93f7393Sniklas }
5714e93f7393Sniklas else
5715e93f7393Sniklas SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
5716e93f7393Sniklas SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
5717b725ae77Skettenis add_symbol_to_list (sym, &fparam_symbols);
5718e93f7393Sniklas break;
5719b725ae77Skettenis #endif
5720b725ae77Skettenis
5721e93f7393Sniklas case DNTT_TYPE_SVAR:
5722e93f7393Sniklas /* Static variables. */
5723e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_STATIC;
5724b725ae77Skettenis
5725b725ae77Skettenis /* Note: There is a case that arises with globals in shared
5726b725ae77Skettenis * libraries where we need to set the address to LOC_INDIRECT.
5727b725ae77Skettenis * This case is if you have a global "g" in one library, and
5728b725ae77Skettenis * it is referenced "extern <type> g;" in another library.
5729b725ae77Skettenis * If we're processing the symbols for the referencing library,
5730b725ae77Skettenis * we'll see a global "g", but in this case the address given
5731b725ae77Skettenis * in the symbol table contains a pointer to the real "g".
5732b725ae77Skettenis * We use the storage class LOC_INDIRECT to indicate this. RT
5733b725ae77Skettenis */
5734b725ae77Skettenis if (is_in_import_list (DEPRECATED_SYMBOL_NAME (sym), objfile))
5735b725ae77Skettenis SYMBOL_CLASS (sym) = LOC_INDIRECT;
5736b725ae77Skettenis
5737b725ae77Skettenis SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location + data_offset;
5738e93f7393Sniklas SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
5739b725ae77Skettenis
5740e93f7393Sniklas if (dn_bufp->dsvar.global)
5741e93f7393Sniklas add_symbol_to_list (sym, &global_symbols);
5742b725ae77Skettenis
5743e93f7393Sniklas else if (WITHIN_FUNCTION (objfile))
5744e93f7393Sniklas add_symbol_to_list (sym, &local_symbols);
5745b725ae77Skettenis
5746e93f7393Sniklas else
5747e93f7393Sniklas add_symbol_to_list (sym, &file_symbols);
5748b725ae77Skettenis
5749b725ae77Skettenis if (dn_bufp->dsvar.thread_specific)
5750b725ae77Skettenis {
5751b725ae77Skettenis /* Thread-local variable.
5752b725ae77Skettenis */
5753b725ae77Skettenis SYMBOL_CLASS (sym) = LOC_HP_THREAD_LOCAL_STATIC;
5754*63addd46Skettenis SYMBOL_BASEREG (sym) = HPPA_CR27_REGNUM;
5755b725ae77Skettenis
5756b725ae77Skettenis if (objfile->flags & OBJF_SHARED)
5757b725ae77Skettenis {
5758b725ae77Skettenis /*
5759b725ae77Skettenis * This variable is not only thread local but
5760b725ae77Skettenis * in a shared library.
5761b725ae77Skettenis *
5762b725ae77Skettenis * Alas, the shared lib structures are private
5763b725ae77Skettenis * to "somsolib.c". But C lets us point to one.
5764b725ae77Skettenis */
5765b725ae77Skettenis struct so_list *so;
5766*63addd46Skettenis struct hppa_objfile_private *priv;
5767b725ae77Skettenis
5768*63addd46Skettenis priv = (struct hppa_objfile_private *)
5769*63addd46Skettenis objfile_data (objfile, hppa_objfile_priv_data);
5770*63addd46Skettenis if (priv == NULL)
5771b725ae77Skettenis error ("Internal error in reading shared library information.");
5772b725ae77Skettenis
5773*63addd46Skettenis so = ((struct hppa_objfile_private *) priv)->so_info;
5774b725ae77Skettenis if (so == NULL)
5775b725ae77Skettenis error ("Internal error in reading shared library information.");
5776b725ae77Skettenis
5777b725ae77Skettenis /* Thread-locals in shared libraries do NOT have the
5778b725ae77Skettenis * standard offset ("data_offset"), so we re-calculate
5779b725ae77Skettenis * where to look for this variable, using a call-back
5780b725ae77Skettenis * to interpret the private shared-library data.
5781b725ae77Skettenis */
5782b725ae77Skettenis SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location +
5783b725ae77Skettenis so_lib_thread_start_addr (so);
5784b725ae77Skettenis }
5785b725ae77Skettenis }
5786e93f7393Sniklas break;
5787b725ae77Skettenis
5788e93f7393Sniklas case DNTT_TYPE_DVAR:
5789e93f7393Sniklas /* Dynamic variables. */
5790e93f7393Sniklas if (dn_bufp->ddvar.regvar)
5791e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_REGISTER;
5792e93f7393Sniklas else
5793e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_LOCAL;
5794b725ae77Skettenis
5795e93f7393Sniklas SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
5796e93f7393Sniklas SYMBOL_VALUE (sym)
5797*63addd46Skettenis += hpread_adjust_stack_address (CURRENT_FUNCTION_VALUE (objfile));
5798e93f7393Sniklas SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
5799e93f7393Sniklas if (dn_bufp->ddvar.global)
5800e93f7393Sniklas add_symbol_to_list (sym, &global_symbols);
5801e93f7393Sniklas else if (WITHIN_FUNCTION (objfile))
5802e93f7393Sniklas add_symbol_to_list (sym, &local_symbols);
5803e93f7393Sniklas else
5804e93f7393Sniklas add_symbol_to_list (sym, &file_symbols);
5805e93f7393Sniklas break;
5806b725ae77Skettenis
5807e93f7393Sniklas case DNTT_TYPE_CONST:
5808e93f7393Sniklas /* A constant (pascal?). */
5809e93f7393Sniklas SYMBOL_CLASS (sym) = LOC_CONST;
5810e93f7393Sniklas SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
5811e93f7393Sniklas SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
5812e93f7393Sniklas if (dn_bufp->dconst.global)
5813e93f7393Sniklas add_symbol_to_list (sym, &global_symbols);
5814e93f7393Sniklas else if (WITHIN_FUNCTION (objfile))
5815e93f7393Sniklas add_symbol_to_list (sym, &local_symbols);
5816e93f7393Sniklas else
5817e93f7393Sniklas add_symbol_to_list (sym, &file_symbols);
5818e93f7393Sniklas break;
5819b725ae77Skettenis
5820e93f7393Sniklas case DNTT_TYPE_TYPEDEF:
5821b725ae77Skettenis /* A typedef. We do want to process these, since a name is
5822b725ae77Skettenis * added to the domain for the typedef'ed name.
5823b725ae77Skettenis */
5824b725ae77Skettenis SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5825e93f7393Sniklas SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
5826e93f7393Sniklas if (dn_bufp->dtype.global)
5827e93f7393Sniklas add_symbol_to_list (sym, &global_symbols);
5828e93f7393Sniklas else if (WITHIN_FUNCTION (objfile))
5829e93f7393Sniklas add_symbol_to_list (sym, &local_symbols);
5830e93f7393Sniklas else
5831e93f7393Sniklas add_symbol_to_list (sym, &file_symbols);
5832e93f7393Sniklas break;
5833b725ae77Skettenis
5834e93f7393Sniklas case DNTT_TYPE_TAGDEF:
5835b725ae77Skettenis {
5836b725ae77Skettenis int global = dn_bufp->dtag.global;
5837b725ae77Skettenis /* Structure, union, enum, template, or class tag definition */
5838b725ae77Skettenis /* We do want to process these, since a name is
5839b725ae77Skettenis * added to the domain for the tag name (and if C++ class,
5840b725ae77Skettenis * for the typename also).
5841b725ae77Skettenis */
5842b725ae77Skettenis SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
5843b725ae77Skettenis
5844b725ae77Skettenis /* The tag contains in its "type" field a pointer to the
5845b725ae77Skettenis * DNTT_TYPE_STRUCT, DNTT_TYPE_UNION, DNTT_TYPE_ENUM,
5846b725ae77Skettenis * DNTT_TYPE_CLASS or DNTT_TYPE_TEMPLATE
5847b725ae77Skettenis * record that actually defines the type.
5848b725ae77Skettenis */
5849e93f7393Sniklas SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
5850b725ae77Skettenis TYPE_NAME (sym->type) = DEPRECATED_SYMBOL_NAME (sym);
5851b725ae77Skettenis TYPE_TAG_NAME (sym->type) = DEPRECATED_SYMBOL_NAME (sym);
5852b725ae77Skettenis if (dn_bufp->dtag.global)
5853e93f7393Sniklas add_symbol_to_list (sym, &global_symbols);
5854e93f7393Sniklas else if (WITHIN_FUNCTION (objfile))
5855e93f7393Sniklas add_symbol_to_list (sym, &local_symbols);
5856e93f7393Sniklas else
5857e93f7393Sniklas add_symbol_to_list (sym, &file_symbols);
5858b725ae77Skettenis
5859b725ae77Skettenis /* If this is a C++ class, then we additionally
5860b725ae77Skettenis * need to define a typedef for the
5861b725ae77Skettenis * class type. E.g., so that the name "c" becomes visible as
5862b725ae77Skettenis * a type name when the user says "class c { ... }".
5863b725ae77Skettenis * In order to figure this out, we need to chase down the "type"
5864b725ae77Skettenis * field to get to the DNTT_TYPE_CLASS record.
5865b725ae77Skettenis *
5866b725ae77Skettenis * We also add the typename for ENUM. Though this isn't
5867b725ae77Skettenis * strictly correct, it is necessary because of the debug info
5868b725ae77Skettenis * generated by the aCC compiler, in which we cannot
5869b725ae77Skettenis * distinguish between:
5870b725ae77Skettenis * enum e { ... };
5871b725ae77Skettenis * and
5872b725ae77Skettenis * typedef enum { ... } e;
5873b725ae77Skettenis * I.e., the compiler emits the same debug info for the above
5874b725ae77Skettenis * two cases, in both cases "e" appearing as a tagdef.
5875b725ae77Skettenis * Therefore go ahead and generate the typename so that
5876b725ae77Skettenis * "ptype e" will work in the above cases.
5877b725ae77Skettenis *
5878b725ae77Skettenis * We also add the typename for TEMPLATE, so as to allow "ptype t"
5879b725ae77Skettenis * when "t" is a template name.
5880b725ae77Skettenis */
5881b725ae77Skettenis if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
5882b725ae77Skettenis dn_bufp = hpread_get_lntt (dn_bufp->dtag.type.dnttp.index, objfile);
5883b725ae77Skettenis else
5884b725ae77Skettenis {
5885b725ae77Skettenis complaint (&symfile_complaints, "error processing class tagdef");
5886b725ae77Skettenis return;
5887b725ae77Skettenis }
5888b725ae77Skettenis if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS ||
5889b725ae77Skettenis dn_bufp->dblock.kind == DNTT_TYPE_ENUM ||
5890b725ae77Skettenis dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
5891b725ae77Skettenis {
5892b725ae77Skettenis struct symbol *newsym;
5893b725ae77Skettenis
5894b725ae77Skettenis newsym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
5895b725ae77Skettenis sizeof (struct symbol));
5896b725ae77Skettenis memset (newsym, 0, sizeof (struct symbol));
5897b725ae77Skettenis DEPRECATED_SYMBOL_NAME (newsym) = name;
5898b725ae77Skettenis SYMBOL_LANGUAGE (newsym) = language_auto;
5899b725ae77Skettenis SYMBOL_DOMAIN (newsym) = VAR_DOMAIN;
5900b725ae77Skettenis SYMBOL_LINE (newsym) = 0;
5901b725ae77Skettenis SYMBOL_VALUE (newsym) = 0;
5902b725ae77Skettenis SYMBOL_CLASS (newsym) = LOC_TYPEDEF;
5903b725ae77Skettenis SYMBOL_TYPE (newsym) = sym->type;
5904b725ae77Skettenis if (global)
5905b725ae77Skettenis add_symbol_to_list (newsym, &global_symbols);
5906b725ae77Skettenis else if (WITHIN_FUNCTION (objfile))
5907b725ae77Skettenis add_symbol_to_list (newsym, &local_symbols);
5908b725ae77Skettenis else
5909b725ae77Skettenis add_symbol_to_list (newsym, &file_symbols);
5910b725ae77Skettenis }
5911b725ae77Skettenis }
5912e93f7393Sniklas break;
5913b725ae77Skettenis
5914e93f7393Sniklas case DNTT_TYPE_POINTER:
5915b725ae77Skettenis /* Declares a pointer type. Should not be necessary to do anything
5916b725ae77Skettenis * with the type at this level; these are processed
5917b725ae77Skettenis * at the hpread_type_lookup() level.
5918b725ae77Skettenis */
5919e93f7393Sniklas break;
5920b725ae77Skettenis
5921e93f7393Sniklas case DNTT_TYPE_ENUM:
5922b725ae77Skettenis /* Declares an enum type. Should not be necessary to do anything
5923b725ae77Skettenis * with the type at this level; these are processed
5924b725ae77Skettenis * at the hpread_type_lookup() level.
5925b725ae77Skettenis */
5926e93f7393Sniklas break;
5927b725ae77Skettenis
5928e93f7393Sniklas case DNTT_TYPE_MEMENUM:
5929b725ae77Skettenis /* Member of enum */
5930b725ae77Skettenis /* Ignored at this level, but hpread_read_enum_type() will take
5931b725ae77Skettenis * care of walking the list of enumeration members.
5932b725ae77Skettenis */
5933e93f7393Sniklas break;
5934b725ae77Skettenis
5935e93f7393Sniklas case DNTT_TYPE_SET:
5936b725ae77Skettenis /* Declares a set type. Should not be necessary to do anything
5937b725ae77Skettenis * with the type at this level; these are processed
5938b725ae77Skettenis * at the hpread_type_lookup() level.
5939b725ae77Skettenis */
5940e93f7393Sniklas break;
5941b725ae77Skettenis
5942e93f7393Sniklas case DNTT_TYPE_SUBRANGE:
5943b725ae77Skettenis /* Declares a subrange type. Should not be necessary to do anything
5944b725ae77Skettenis * with the type at this level; these are processed
5945b725ae77Skettenis * at the hpread_type_lookup() level.
5946b725ae77Skettenis */
5947e93f7393Sniklas break;
5948b725ae77Skettenis
5949e93f7393Sniklas case DNTT_TYPE_ARRAY:
5950b725ae77Skettenis /* Declares an array type. Should not be necessary to do anything
5951b725ae77Skettenis * with the type at this level; these are processed
5952b725ae77Skettenis * at the hpread_type_lookup() level.
5953b725ae77Skettenis */
5954e93f7393Sniklas break;
5955b725ae77Skettenis
5956e93f7393Sniklas case DNTT_TYPE_STRUCT:
5957e93f7393Sniklas case DNTT_TYPE_UNION:
5958b725ae77Skettenis /* Declares an struct/union type.
5959b725ae77Skettenis * Should not be necessary to do anything
5960b725ae77Skettenis * with the type at this level; these are processed
5961b725ae77Skettenis * at the hpread_type_lookup() level.
5962b725ae77Skettenis */
5963b725ae77Skettenis break;
5964b725ae77Skettenis
5965b725ae77Skettenis case DNTT_TYPE_FIELD:
5966b725ae77Skettenis /* Structure/union/class field */
5967b725ae77Skettenis /* Ignored at this level, but hpread_read_struct_type() will take
5968b725ae77Skettenis * care of walking the list of structure/union/class members.
5969b725ae77Skettenis */
5970b725ae77Skettenis break;
5971b725ae77Skettenis
5972b725ae77Skettenis /* DNTT_TYPE_VARIANT is not handled by GDB */
5973b725ae77Skettenis
5974b725ae77Skettenis /* DNTT_TYPE_FILE is not handled by GDB */
5975b725ae77Skettenis
5976b725ae77Skettenis case DNTT_TYPE_FUNCTYPE:
5977b725ae77Skettenis /* Function type */
5978b725ae77Skettenis /* Ignored at this level, handled within hpread_type_lookup() */
5979b725ae77Skettenis break;
5980b725ae77Skettenis
5981b725ae77Skettenis case DNTT_TYPE_WITH:
5982b725ae77Skettenis /* This is emitted within methods to indicate "with <class>"
5983b725ae77Skettenis * scoping rules (i.e., indicate that the class data members
5984b725ae77Skettenis * are directly visible).
5985b725ae77Skettenis * However, since GDB already infers this by looking at the
5986b725ae77Skettenis * "this" argument, interpreting the DNTT_TYPE_WITH
5987b725ae77Skettenis * symbol record is unnecessary.
5988b725ae77Skettenis */
5989b725ae77Skettenis break;
5990b725ae77Skettenis
5991b725ae77Skettenis case DNTT_TYPE_COMMON:
5992b725ae77Skettenis /* FORTRAN common. Not yet handled. */
5993b725ae77Skettenis complaint (&symfile_complaints,
5994b725ae77Skettenis "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_COMMON.");
5995b725ae77Skettenis break;
5996b725ae77Skettenis
5997b725ae77Skettenis /* DNTT_TYPE_COBSTRUCT is not handled by GDB. */
5998b725ae77Skettenis /* DNTT_TYPE_XREF is not handled by GDB. */
5999b725ae77Skettenis /* DNTT_TYPE_SA is not handled by GDB. */
6000b725ae77Skettenis /* DNTT_TYPE_MACRO is not handled by GDB */
6001b725ae77Skettenis
6002b725ae77Skettenis case DNTT_TYPE_BLOCKDATA:
6003b725ae77Skettenis /* Not sure what this is - part of FORTRAN support maybe?
6004b725ae77Skettenis * Anyway, not yet handled.
6005b725ae77Skettenis */
6006b725ae77Skettenis complaint (&symfile_complaints,
6007b725ae77Skettenis "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_BLOCKDATA.");
6008b725ae77Skettenis break;
6009b725ae77Skettenis
6010b725ae77Skettenis case DNTT_TYPE_CLASS_SCOPE:
6011b725ae77Skettenis
6012b725ae77Skettenis
6013b725ae77Skettenis
6014b725ae77Skettenis /* The compiler brackets member functions with a CLASS_SCOPE/END
6015b725ae77Skettenis * pair of records, presumably to put them in a different scope
6016b725ae77Skettenis * from the module scope where they are normally defined.
6017b725ae77Skettenis * E.g., in the situation:
6018b725ae77Skettenis * void f() { ... }
6019b725ae77Skettenis * void c::f() { ...}
6020b725ae77Skettenis * The member function "c::f" will be bracketed by a CLASS_SCOPE/END.
6021b725ae77Skettenis * This causes "break f" at the module level to pick the
6022b725ae77Skettenis * the file-level function f(), not the member function
6023b725ae77Skettenis * (which needs to be referenced via "break c::f").
6024b725ae77Skettenis *
6025b725ae77Skettenis * Here we record the class name to generate the demangled names of
6026b725ae77Skettenis * member functions later.
6027b725ae77Skettenis *
6028b725ae77Skettenis * FIXME Not being used now for anything -- cplus_demangle seems
6029b725ae77Skettenis * enough for getting the class-qualified names of functions. We
6030b725ae77Skettenis * may need this for handling nested classes and types. */
6031b725ae77Skettenis
6032b725ae77Skettenis /* pai: FIXME Not handling nested classes for now -- need to
6033b725ae77Skettenis * maintain a stack */
6034b725ae77Skettenis
6035b725ae77Skettenis dn_temp = hpread_get_lntt (dn_bufp->dclass_scope.type.dnttp.index, objfile);
6036b725ae77Skettenis if (dn_temp->dblock.kind == DNTT_TYPE_TAGDEF)
6037b725ae77Skettenis class_scope_name = VT (objfile) + dn_temp->dtag.name;
6038b725ae77Skettenis else
6039b725ae77Skettenis class_scope_name = NULL;
6040b725ae77Skettenis
6041b725ae77Skettenis #if 0
6042b725ae77Skettenis
6043b725ae77Skettenis /* Begin a new scope. */
6044b725ae77Skettenis SL_INDEX (objfile) = hpread_record_lines (current_subfile,
6045b725ae77Skettenis SL_INDEX (objfile),
6046b725ae77Skettenis dn_bufp->dclass_scope.address,
6047b725ae77Skettenis objfile, offset);
6048b725ae77Skettenis valu = hpread_get_location (dn_bufp->dclass_scope.address, objfile);
6049b725ae77Skettenis valu += offset; /* Relocate for dynamic loading */
6050b725ae77Skettenis desc = hpread_get_scope_start (dn_bufp->dclass_scope.address, objfile);
6051b725ae77Skettenis /* We use the scope start DNTT index as the nesting depth identifier! */
6052b725ae77Skettenis new = push_context (desc, valu);
6053b725ae77Skettenis #endif
6054b725ae77Skettenis break;
6055b725ae77Skettenis
6056b725ae77Skettenis case DNTT_TYPE_REFERENCE:
6057b725ae77Skettenis /* Declares a C++ reference type. Should not be necessary to do anything
6058b725ae77Skettenis * with the type at this level; these are processed
6059b725ae77Skettenis * at the hpread_type_lookup() level.
6060b725ae77Skettenis */
6061b725ae77Skettenis break;
6062b725ae77Skettenis
6063b725ae77Skettenis case DNTT_TYPE_PTRMEM:
6064b725ae77Skettenis /* Declares a C++ pointer-to-data-member type. This does not
6065b725ae77Skettenis * need to be handled at this level; being a type description it
6066b725ae77Skettenis * is instead handled at the hpread_type_lookup() level.
6067b725ae77Skettenis */
6068b725ae77Skettenis break;
6069b725ae77Skettenis
6070b725ae77Skettenis case DNTT_TYPE_PTRMEMFUNC:
6071b725ae77Skettenis /* Declares a C++ pointer-to-function-member type. This does not
6072b725ae77Skettenis * need to be handled at this level; being a type description it
6073b725ae77Skettenis * is instead handled at the hpread_type_lookup() level.
6074b725ae77Skettenis */
6075b725ae77Skettenis break;
6076b725ae77Skettenis
6077b725ae77Skettenis case DNTT_TYPE_CLASS:
6078b725ae77Skettenis /* Declares a class type.
6079b725ae77Skettenis * Should not be necessary to do anything
6080b725ae77Skettenis * with the type at this level; these are processed
6081b725ae77Skettenis * at the hpread_type_lookup() level.
6082b725ae77Skettenis */
6083b725ae77Skettenis break;
6084b725ae77Skettenis
6085b725ae77Skettenis case DNTT_TYPE_GENFIELD:
6086b725ae77Skettenis /* I believe this is used for class member functions */
6087b725ae77Skettenis /* Ignored at this level, but hpread_read_struct_type() will take
6088b725ae77Skettenis * care of walking the list of class members.
6089b725ae77Skettenis */
6090b725ae77Skettenis break;
6091b725ae77Skettenis
6092b725ae77Skettenis case DNTT_TYPE_VFUNC:
6093b725ae77Skettenis /* Virtual function */
6094b725ae77Skettenis /* This does not have to be handled at this level; handled in
6095b725ae77Skettenis * the course of processing class symbols.
6096b725ae77Skettenis */
6097b725ae77Skettenis break;
6098b725ae77Skettenis
6099b725ae77Skettenis case DNTT_TYPE_MEMACCESS:
6100b725ae77Skettenis /* DDE ignores this symbol table record.
6101b725ae77Skettenis * It has something to do with "modified access" to class members.
6102b725ae77Skettenis * I'll assume we can safely ignore it too.
6103b725ae77Skettenis */
6104b725ae77Skettenis break;
6105b725ae77Skettenis
6106b725ae77Skettenis case DNTT_TYPE_INHERITANCE:
6107b725ae77Skettenis /* These don't have to be handled here, since they are handled
6108b725ae77Skettenis * within hpread_read_struct_type() in the process of constructing
6109b725ae77Skettenis * a class type.
6110b725ae77Skettenis */
6111b725ae77Skettenis break;
6112b725ae77Skettenis
6113b725ae77Skettenis case DNTT_TYPE_FRIEND_CLASS:
6114b725ae77Skettenis case DNTT_TYPE_FRIEND_FUNC:
6115b725ae77Skettenis /* These can safely be ignored, as GDB doesn't need this
6116b725ae77Skettenis * info. DDE only uses it in "describe". We may later want
6117b725ae77Skettenis * to extend GDB's "ptype" to give this info, but for now
6118b725ae77Skettenis * it seems safe enough to ignore it.
6119b725ae77Skettenis */
6120b725ae77Skettenis break;
6121b725ae77Skettenis
6122b725ae77Skettenis case DNTT_TYPE_MODIFIER:
6123b725ae77Skettenis /* Intended to supply "modified access" to a type */
6124b725ae77Skettenis /* From the way DDE handles this, it looks like it always
6125b725ae77Skettenis * modifies a type. Therefore it is safe to ignore it at this
6126b725ae77Skettenis * level, and handle it in hpread_type_lookup().
6127b725ae77Skettenis */
6128b725ae77Skettenis break;
6129b725ae77Skettenis
6130b725ae77Skettenis case DNTT_TYPE_OBJECT_ID:
6131b725ae77Skettenis /* Just ignore this - that's all DDE does */
6132b725ae77Skettenis break;
6133b725ae77Skettenis
6134b725ae77Skettenis case DNTT_TYPE_MEMFUNC:
6135b725ae77Skettenis /* Member function */
6136b725ae77Skettenis /* This does not have to be handled at this level; handled in
6137b725ae77Skettenis * the course of processing class symbols.
6138b725ae77Skettenis */
6139b725ae77Skettenis break;
6140b725ae77Skettenis
6141b725ae77Skettenis case DNTT_TYPE_DOC_MEMFUNC:
6142b725ae77Skettenis /* Member function */
6143b725ae77Skettenis /* This does not have to be handled at this level; handled in
6144b725ae77Skettenis * the course of processing class symbols.
6145b725ae77Skettenis */
6146b725ae77Skettenis break;
6147b725ae77Skettenis
6148b725ae77Skettenis case DNTT_TYPE_TEMPLATE:
6149b725ae77Skettenis /* Template - sort of the header for a template definition,
6150b725ae77Skettenis * which like a class, points to a member list and also points
6151b725ae77Skettenis * to a TEMPLATE_ARG list of type-arguments.
6152b725ae77Skettenis * We do not need to process TEMPLATE records at this level though.
6153b725ae77Skettenis */
6154b725ae77Skettenis break;
6155b725ae77Skettenis
6156b725ae77Skettenis case DNTT_TYPE_TEMPLATE_ARG:
6157b725ae77Skettenis /* The TEMPLATE record points to an argument list of
6158b725ae77Skettenis * TEMPLATE_ARG records, each of which describes one
6159b725ae77Skettenis * of the type-arguments.
6160b725ae77Skettenis * We do not need to process TEMPLATE_ARG records at this level though.
6161b725ae77Skettenis */
6162b725ae77Skettenis break;
6163b725ae77Skettenis
6164b725ae77Skettenis case DNTT_TYPE_FUNC_TEMPLATE:
6165b725ae77Skettenis /* This will get emitted for member functions of templates.
6166b725ae77Skettenis * But we don't need to process this record at this level though,
6167b725ae77Skettenis * we will process it in the course of processing a TEMPLATE
6168b725ae77Skettenis * record.
6169b725ae77Skettenis */
6170b725ae77Skettenis break;
6171b725ae77Skettenis
6172b725ae77Skettenis case DNTT_TYPE_LINK:
6173b725ae77Skettenis /* The LINK record is used to link up templates with instantiations. */
6174b725ae77Skettenis /* It is not clear why this is needed, and furthermore aCC does
6175b725ae77Skettenis * not appear to generate this, so I think we can safely ignore it. - RT
6176b725ae77Skettenis */
6177b725ae77Skettenis break;
6178b725ae77Skettenis
6179b725ae77Skettenis /* DNTT_TYPE_DYN_ARRAY_DESC is not handled by GDB */
6180b725ae77Skettenis /* DNTT_TYPE_DESC_SUBRANGE is not handled by GDB */
6181b725ae77Skettenis /* DNTT_TYPE_BEGIN_EXT is not handled by GDB */
6182b725ae77Skettenis /* DNTT_TYPE_INLN is not handled by GDB */
6183b725ae77Skettenis /* DNTT_TYPE_INLN_LIST is not handled by GDB */
6184b725ae77Skettenis /* DNTT_TYPE_ALIAS is not handled by GDB */
6185b725ae77Skettenis
6186b725ae77Skettenis default:
6187b725ae77Skettenis break;
6188b725ae77Skettenis }
6189b725ae77Skettenis }
6190b725ae77Skettenis
6191b725ae77Skettenis /* Get nesting depth for a DNTT entry.
6192b725ae77Skettenis * DN_BUFP points to a DNTT entry.
6193b725ae77Skettenis * OBJFILE is the object file.
6194b725ae77Skettenis * REPORT_NESTED is a flag; if 0, real nesting depth is
6195b725ae77Skettenis * reported, if it is 1, the function simply returns a
6196b725ae77Skettenis * non-zero value if the nesting depth is anything > 0.
6197b725ae77Skettenis *
6198b725ae77Skettenis * Return value is an integer. 0 => not a local type / name
6199b725ae77Skettenis * positive return => type or name is local to some
6200b725ae77Skettenis * block or function.
6201b725ae77Skettenis */
6202b725ae77Skettenis
6203b725ae77Skettenis
6204b725ae77Skettenis /* elz: ATTENTION: FIXME: NOTE: WARNING!!!!
6205b725ae77Skettenis this function now returns 0 right away. It was taking too much time
6206b725ae77Skettenis at start up. Now, though, the local types are not handled correctly.
6207b725ae77Skettenis */
6208b725ae77Skettenis
6209b725ae77Skettenis
6210b725ae77Skettenis static int
hpread_get_scope_depth(union dnttentry * dn_bufp,struct objfile * objfile,int report_nested)6211b725ae77Skettenis hpread_get_scope_depth (union dnttentry *dn_bufp, struct objfile *objfile,
6212b725ae77Skettenis int report_nested)
6213b725ae77Skettenis {
6214b725ae77Skettenis int index;
6215b725ae77Skettenis union dnttentry *dn_tmp;
6216b725ae77Skettenis short depth = 0;
6217b725ae77Skettenis /****************************/
6218b725ae77Skettenis return 0;
6219b725ae77Skettenis /****************************/
6220b725ae77Skettenis
6221b725ae77Skettenis index = (((char *) dn_bufp) - LNTT (objfile)) / (sizeof (struct dntt_type_block));
6222b725ae77Skettenis
6223b725ae77Skettenis while (--index >= 0)
6224b725ae77Skettenis {
6225b725ae77Skettenis dn_tmp = hpread_get_lntt (index, objfile);
6226b725ae77Skettenis switch (dn_tmp->dblock.kind)
6227b725ae77Skettenis {
6228b725ae77Skettenis case DNTT_TYPE_MODULE:
6229b725ae77Skettenis return depth;
6230b725ae77Skettenis case DNTT_TYPE_END:
6231b725ae77Skettenis /* index is signed int; dnttp.index is 29-bit unsigned int! */
6232b725ae77Skettenis index = (int) dn_tmp->dend.beginscope.dnttp.index;
6233b725ae77Skettenis break;
6234b725ae77Skettenis case DNTT_TYPE_BEGIN:
6235b725ae77Skettenis case DNTT_TYPE_FUNCTION:
6236b725ae77Skettenis case DNTT_TYPE_DOC_FUNCTION:
6237b725ae77Skettenis case DNTT_TYPE_WITH:
6238b725ae77Skettenis case DNTT_TYPE_COMMON:
6239b725ae77Skettenis case DNTT_TYPE_CLASS_SCOPE:
6240b725ae77Skettenis depth++;
6241b725ae77Skettenis if (report_nested)
6242b725ae77Skettenis return 1;
6243e93f7393Sniklas break;
6244e93f7393Sniklas default:
6245e93f7393Sniklas break;
6246e93f7393Sniklas }
6247e93f7393Sniklas }
6248b725ae77Skettenis return depth;
6249b725ae77Skettenis }
6250b725ae77Skettenis
6251b725ae77Skettenis /* Adjust the bitoffsets for all fields of an anonymous union of
6252b725ae77Skettenis type TYPE by negative BITS. This handles HP aCC's hideous habit
6253b725ae77Skettenis of giving members of anonymous unions bit offsets relative to the
6254b725ae77Skettenis enclosing structure instead of relative to the union itself. */
6255b725ae77Skettenis
6256b725ae77Skettenis static void
hpread_adjust_bitoffsets(struct type * type,int bits)6257b725ae77Skettenis hpread_adjust_bitoffsets (struct type *type, int bits)
6258b725ae77Skettenis {
6259b725ae77Skettenis int i;
6260b725ae77Skettenis
6261b725ae77Skettenis /* This is done only for unions; caller had better check that
6262b725ae77Skettenis it is an anonymous one. */
6263b725ae77Skettenis if (TYPE_CODE (type) != TYPE_CODE_UNION)
6264b725ae77Skettenis return;
6265b725ae77Skettenis
6266b725ae77Skettenis /* Adjust each field; since this is a union, there are no base
6267b725ae77Skettenis classes. Also no static membes. Also, no need for recursion as
6268b725ae77Skettenis the members of this union if themeselves structs or unions, have
6269b725ae77Skettenis the correct bitoffsets; if an anonymous union is a member of this
6270b725ae77Skettenis anonymous union, the code in hpread_read_struct_type() will
6271b725ae77Skettenis adjust for that. */
6272b725ae77Skettenis
6273b725ae77Skettenis for (i = 0; i < TYPE_NFIELDS (type); i++)
6274b725ae77Skettenis TYPE_FIELD_BITPOS (type, i) -= bits;
6275b725ae77Skettenis }
6276b725ae77Skettenis
6277*63addd46Skettenis /* Return the adjustment necessary to make for addresses on the stack
6278*63addd46Skettenis as presented by hpread.c.
6279*63addd46Skettenis
6280*63addd46Skettenis This is necessary because of the stack direction on the PA and the
6281*63addd46Skettenis bizarre way in which someone (?) decided they wanted to handle
6282*63addd46Skettenis frame pointerless code in GDB. */
6283*63addd46Skettenis int
hpread_adjust_stack_address(CORE_ADDR func_addr)6284*63addd46Skettenis hpread_adjust_stack_address (CORE_ADDR func_addr)
6285*63addd46Skettenis {
6286*63addd46Skettenis struct unwind_table_entry *u;
6287*63addd46Skettenis
6288*63addd46Skettenis u = find_unwind_entry (func_addr);
6289*63addd46Skettenis if (!u)
6290*63addd46Skettenis return 0;
6291*63addd46Skettenis else
6292*63addd46Skettenis return u->Total_frame_size << 3;
6293*63addd46Skettenis }
6294*63addd46Skettenis
6295b725ae77Skettenis /* Because of quirks in HP compilers' treatment of anonymous unions inside
6296b725ae77Skettenis classes, we have to chase through a chain of threaded FIELD entries.
6297b725ae77Skettenis If we encounter an anonymous union in the chain, we must recursively skip over
6298b725ae77Skettenis that too.
6299b725ae77Skettenis
6300b725ae77Skettenis This function does a "next" in the chain of FIELD entries, but transparently
6301b725ae77Skettenis skips over anonymous unions' fields (recursively).
6302b725ae77Skettenis
6303b725ae77Skettenis Inputs are the number of times to do "next" at the top level, the dnttpointer
6304b725ae77Skettenis (FIELD) and entry pointer (FIELDP) for the dntt record corresponding to it,
6305b725ae77Skettenis and the ubiquitous objfile parameter. (Note: FIELDP is a **.) Return value
6306b725ae77Skettenis is a dnttpointer for the new field after all the skipped ones */
6307b725ae77Skettenis
6308b725ae77Skettenis static dnttpointer
hpread_get_next_skip_over_anon_unions(int skip_fields,dnttpointer field,union dnttentry ** fieldp,struct objfile * objfile)6309b725ae77Skettenis hpread_get_next_skip_over_anon_unions (int skip_fields, dnttpointer field,
6310b725ae77Skettenis union dnttentry **fieldp,
6311b725ae77Skettenis struct objfile *objfile)
6312b725ae77Skettenis {
6313b725ae77Skettenis struct type *anon_type;
6314b725ae77Skettenis int i;
6315b725ae77Skettenis int bitoffset;
6316b725ae77Skettenis char *name;
6317b725ae77Skettenis
6318b725ae77Skettenis for (i = 0; i < skip_fields; i++)
6319b725ae77Skettenis {
6320b725ae77Skettenis /* Get type of item we're looking at now; recursively processes the types
6321b725ae77Skettenis of these intermediate items we skip over, so they aren't lost. */
6322b725ae77Skettenis anon_type = hpread_type_lookup ((*fieldp)->dfield.type, objfile);
6323b725ae77Skettenis anon_type = CHECK_TYPEDEF (anon_type);
6324b725ae77Skettenis bitoffset = (*fieldp)->dfield.bitoffset;
6325b725ae77Skettenis name = VT (objfile) + (*fieldp)->dfield.name;
6326b725ae77Skettenis /* First skip over one item to avoid stack death on recursion */
6327b725ae77Skettenis field = (*fieldp)->dfield.nextfield;
6328b725ae77Skettenis *fieldp = hpread_get_lntt (field.dnttp.index, objfile);
6329b725ae77Skettenis /* Do we have another anonymous union? If so, adjust the bitoffsets
6330b725ae77Skettenis of its members and skip over its members. */
6331b725ae77Skettenis if ((TYPE_CODE (anon_type) == TYPE_CODE_UNION) &&
6332b725ae77Skettenis (!name || DEPRECATED_STREQ (name, "")))
6333b725ae77Skettenis {
6334b725ae77Skettenis hpread_adjust_bitoffsets (anon_type, bitoffset);
6335b725ae77Skettenis field = hpread_get_next_skip_over_anon_unions (TYPE_NFIELDS (anon_type), field, fieldp, objfile);
6336b725ae77Skettenis }
6337b725ae77Skettenis }
6338b725ae77Skettenis return field;
6339b725ae77Skettenis }
6340