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