Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Read hp debug symbols and convert to internal format, for GDB. |
d7f0b9ce DJ |
2 | Copyright 1993, 1996, 1998, 1999, 2000, 2001, 2002 |
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 | /* Common include for hp-symtab-read.c and hp-psymtab-read.c. | |
26 | * Note this has nested includes for a bunch of stuff. | |
27 | */ | |
28 | #include "defs.h" | |
29 | #include "symtab.h" | |
30 | #include "gdbtypes.h" | |
31 | #include "hpread.h" | |
32 | #include "demangle.h" | |
33 | #include "complaints.h" | |
c906108c SS |
34 | \f |
35 | ||
36 | ||
c5aa993b JM |
37 | |
38 | static struct complaint hpread_unhandled_end_common_complaint = | |
c906108c SS |
39 | { |
40 | "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_COMMON/DNTT_TYPE_END.\n", 0, 0 | |
41 | }; | |
42 | ||
c5aa993b | 43 | static struct complaint hpread_unhandled_type_complaint = |
c906108c SS |
44 | { |
45 | "hpread_type_translate: unhandled type code.", 0, 0 | |
46 | }; | |
47 | ||
c5aa993b | 48 | static struct complaint hpread_struct_complaint = |
c906108c SS |
49 | { |
50 | "hpread_read_struct_type: expected SVAR type...", 0, 0 | |
51 | }; | |
52 | ||
53 | static struct complaint hpread_array_complaint = | |
54 | { | |
55 | "error in hpread_array_type.", 0, 0 | |
56 | }; | |
57 | ||
c5aa993b | 58 | static struct complaint hpread_type_lookup_complaint = |
c906108c SS |
59 | { |
60 | "error in hpread_type_lookup().", 0, 0 | |
61 | }; | |
62 | ||
63 | ||
c5aa993b | 64 | static struct complaint hpread_unexpected_end_complaint = |
c906108c SS |
65 | { |
66 | "internal error in hp-symtab-read.c: Unexpected DNTT_TYPE_END kind.", 0, 0 | |
67 | }; | |
68 | ||
c5aa993b | 69 | static struct complaint hpread_tagdef_complaint = |
c906108c SS |
70 | { |
71 | "error processing class tagdef", 0, 0 | |
72 | }; | |
73 | ||
c5aa993b | 74 | static struct complaint hpread_unhandled_common_complaint = |
c906108c SS |
75 | { |
76 | "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_COMMON.", 0, 0 | |
77 | }; | |
78 | ||
c5aa993b | 79 | static struct complaint hpread_unhandled_blockdata_complaint = |
c906108c SS |
80 | { |
81 | "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_BLOCKDATA.", 0, 0 | |
82 | }; | |
83 | ||
84 | ||
85 | /* Forward procedure declarations */ | |
86 | ||
a14ed312 | 87 | static unsigned long hpread_get_scope_start (sltpointer, struct objfile *); |
c906108c | 88 | |
a14ed312 | 89 | static unsigned long hpread_get_line (sltpointer, struct objfile *); |
c906108c | 90 | |
a14ed312 | 91 | static CORE_ADDR hpread_get_location (sltpointer, struct objfile *); |
c906108c | 92 | |
a14ed312 | 93 | static void hpread_psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 94 | |
a14ed312 | 95 | void hpread_psymtab_to_symtab (struct partial_symtab *); |
c906108c SS |
96 | |
97 | static struct symtab *hpread_expand_symtab | |
a14ed312 KB |
98 | (struct objfile *, int, int, CORE_ADDR, int, |
99 | struct section_offsets *, char *); | |
c906108c | 100 | |
a14ed312 | 101 | static int hpread_type_translate (dnttpointer); |
c906108c | 102 | |
a14ed312 | 103 | static struct type **hpread_lookup_type (dnttpointer, struct objfile *); |
c906108c | 104 | |
a14ed312 | 105 | static struct type *hpread_alloc_type (dnttpointer, struct objfile *); |
c906108c SS |
106 | |
107 | static struct type *hpread_read_enum_type | |
a14ed312 | 108 | (dnttpointer, union dnttentry *, struct objfile *); |
c906108c SS |
109 | |
110 | static struct type *hpread_read_function_type | |
a14ed312 | 111 | (dnttpointer, union dnttentry *, struct objfile *, int); |
c906108c SS |
112 | |
113 | static struct type *hpread_read_doc_function_type | |
a14ed312 | 114 | (dnttpointer, union dnttentry *, struct objfile *, int); |
c906108c SS |
115 | |
116 | static struct type *hpread_read_struct_type | |
a14ed312 | 117 | (dnttpointer, union dnttentry *, struct objfile *); |
c906108c | 118 | |
a14ed312 | 119 | static struct type *hpread_get_nth_template_arg (struct objfile *, int); |
c906108c | 120 | |
c5aa993b | 121 | static struct type *hpread_read_templ_arg_type |
a14ed312 | 122 | (dnttpointer, union dnttentry *, struct objfile *, char *); |
c906108c SS |
123 | |
124 | static struct type *hpread_read_set_type | |
a14ed312 | 125 | (dnttpointer, union dnttentry *, struct objfile *); |
c906108c | 126 | |
c5aa993b | 127 | static struct type *hpread_read_array_type |
a14ed312 | 128 | (dnttpointer, union dnttentry *dn_bufp, struct objfile *objfile); |
c906108c SS |
129 | |
130 | static struct type *hpread_read_subrange_type | |
a14ed312 | 131 | (dnttpointer, union dnttentry *, struct objfile *); |
c906108c | 132 | |
a14ed312 | 133 | static struct type *hpread_type_lookup (dnttpointer, struct objfile *); |
c906108c SS |
134 | |
135 | static sltpointer hpread_record_lines | |
a14ed312 | 136 | (struct subfile *, sltpointer, sltpointer, struct objfile *, CORE_ADDR); |
c906108c SS |
137 | |
138 | static void hpread_process_one_debug_symbol | |
a14ed312 KB |
139 | (union dnttentry *, char *, struct section_offsets *, |
140 | struct objfile *, CORE_ADDR, int, char *, int, int *); | |
c906108c | 141 | |
a14ed312 | 142 | static int hpread_get_scope_depth (union dnttentry *, struct objfile *, int); |
c906108c | 143 | |
c5aa993b | 144 | static void fix_static_member_physnames |
a14ed312 | 145 | (struct type *, char *, struct objfile *); |
c906108c SS |
146 | |
147 | static void fixup_class_method_type | |
a14ed312 | 148 | (struct type *, struct type *, struct objfile *); |
c906108c | 149 | |
a14ed312 | 150 | static void hpread_adjust_bitoffsets (struct type *, int); |
c906108c SS |
151 | |
152 | static dnttpointer hpread_get_next_skip_over_anon_unions | |
a14ed312 | 153 | (int, dnttpointer, union dnttentry **, struct objfile *); |
c906108c SS |
154 | |
155 | /* Global to indicate presence of HP-compiled objects, | |
156 | in particular, SOM executable file with SOM debug info | |
c5aa993b | 157 | Defined in symtab.c, used in hppa-tdep.c. */ |
c906108c SS |
158 | extern int hp_som_som_object_present; |
159 | ||
160 | /* Static used to indicate a class type that requires a | |
161 | fix-up of one of its method types */ | |
c5aa993b | 162 | static struct type *fixup_class = NULL; |
c906108c SS |
163 | |
164 | /* Static used to indicate the method type that is to be | |
165 | used to fix-up the type for fixup_class */ | |
c5aa993b | 166 | static struct type *fixup_method = NULL; |
c906108c SS |
167 | \f |
168 | ||
c5aa993b | 169 | |
c906108c SS |
170 | /* Get the nesting depth for the source line identified by INDEX. */ |
171 | ||
172 | static unsigned long | |
fba45db2 | 173 | hpread_get_scope_start (sltpointer index, struct objfile *objfile) |
c906108c SS |
174 | { |
175 | union sltentry *sl_bufp; | |
176 | ||
177 | sl_bufp = hpread_get_slt (index, objfile); | |
178 | return sl_bufp->sspec.backptr.dnttp.index; | |
179 | } | |
180 | ||
181 | /* Get the source line number the the line identified by INDEX. */ | |
182 | ||
183 | static unsigned long | |
fba45db2 | 184 | hpread_get_line (sltpointer index, struct objfile *objfile) |
c906108c SS |
185 | { |
186 | union sltentry *sl_bufp; | |
187 | ||
188 | sl_bufp = hpread_get_slt (index, objfile); | |
189 | return sl_bufp->snorm.line; | |
190 | } | |
191 | ||
192 | /* Find the code address associated with a given sltpointer */ | |
193 | ||
194 | static CORE_ADDR | |
fba45db2 | 195 | hpread_get_location (sltpointer index, struct objfile *objfile) |
c906108c SS |
196 | { |
197 | union sltentry *sl_bufp; | |
198 | int i; | |
199 | ||
200 | /* code location of special sltentrys is determined from context */ | |
201 | sl_bufp = hpread_get_slt (index, objfile); | |
202 | ||
203 | if (sl_bufp->snorm.sltdesc == SLT_END) | |
204 | { | |
205 | /* find previous normal sltentry and get address */ | |
206 | for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) && | |
c5aa993b | 207 | (sl_bufp->snorm.sltdesc != SLT_NORMAL_OFFSET) && |
c906108c SS |
208 | (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++) |
209 | sl_bufp = hpread_get_slt (index - i, objfile); | |
210 | if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET) | |
c5aa993b | 211 | return sl_bufp->snormoff.address; |
c906108c | 212 | else |
c5aa993b | 213 | return sl_bufp->snorm.address; |
c906108c SS |
214 | } |
215 | ||
216 | /* find next normal sltentry and get address */ | |
217 | for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) && | |
218 | (sl_bufp->snorm.sltdesc != SLT_NORMAL_OFFSET) && | |
c5aa993b | 219 | (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++) |
c906108c | 220 | sl_bufp = hpread_get_slt (index + i, objfile); |
c5aa993b JM |
221 | if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET) |
222 | return sl_bufp->snormoff.address; | |
223 | else | |
224 | return sl_bufp->snorm.address; | |
c906108c SS |
225 | } |
226 | \f | |
227 | ||
228 | /* Return 1 if an HP debug symbol of type KIND has a name associated with | |
229 | * it, else return 0. (This function is not currently used, but I'll | |
230 | * leave it here in case it proves useful later on. - RT). | |
231 | */ | |
232 | ||
233 | int | |
fba45db2 | 234 | hpread_has_name (enum dntt_entry_type kind) |
c906108c SS |
235 | { |
236 | switch (kind) | |
237 | { | |
238 | case DNTT_TYPE_SRCFILE: | |
239 | case DNTT_TYPE_MODULE: | |
240 | case DNTT_TYPE_FUNCTION: | |
241 | case DNTT_TYPE_DOC_FUNCTION: | |
242 | case DNTT_TYPE_ENTRY: | |
243 | case DNTT_TYPE_IMPORT: | |
244 | case DNTT_TYPE_LABEL: | |
245 | case DNTT_TYPE_FPARAM: | |
246 | case DNTT_TYPE_SVAR: | |
247 | case DNTT_TYPE_DVAR: | |
248 | case DNTT_TYPE_CONST: | |
249 | case DNTT_TYPE_TYPEDEF: | |
250 | case DNTT_TYPE_TAGDEF: | |
251 | case DNTT_TYPE_MEMENUM: | |
252 | case DNTT_TYPE_FIELD: | |
253 | case DNTT_TYPE_SA: | |
254 | case DNTT_TYPE_BLOCKDATA: | |
255 | case DNTT_TYPE_MEMFUNC: | |
256 | case DNTT_TYPE_DOC_MEMFUNC: | |
257 | return 1; | |
258 | ||
259 | case DNTT_TYPE_BEGIN: | |
260 | case DNTT_TYPE_END: | |
261 | case DNTT_TYPE_POINTER: | |
262 | case DNTT_TYPE_ENUM: | |
263 | case DNTT_TYPE_SET: | |
264 | case DNTT_TYPE_ARRAY: | |
265 | case DNTT_TYPE_STRUCT: | |
266 | case DNTT_TYPE_UNION: | |
267 | case DNTT_TYPE_VARIANT: | |
268 | case DNTT_TYPE_FILE: | |
269 | case DNTT_TYPE_FUNCTYPE: | |
270 | case DNTT_TYPE_SUBRANGE: | |
271 | case DNTT_TYPE_WITH: | |
272 | case DNTT_TYPE_COMMON: | |
273 | case DNTT_TYPE_COBSTRUCT: | |
274 | case DNTT_TYPE_XREF: | |
275 | case DNTT_TYPE_MACRO: | |
276 | case DNTT_TYPE_CLASS_SCOPE: | |
277 | case DNTT_TYPE_REFERENCE: | |
278 | case DNTT_TYPE_PTRMEM: | |
279 | case DNTT_TYPE_PTRMEMFUNC: | |
280 | case DNTT_TYPE_CLASS: | |
281 | case DNTT_TYPE_GENFIELD: | |
282 | case DNTT_TYPE_VFUNC: | |
283 | case DNTT_TYPE_MEMACCESS: | |
284 | case DNTT_TYPE_INHERITANCE: | |
285 | case DNTT_TYPE_FRIEND_CLASS: | |
286 | case DNTT_TYPE_FRIEND_FUNC: | |
c5aa993b | 287 | case DNTT_TYPE_MODIFIER: |
c906108c SS |
288 | case DNTT_TYPE_OBJECT_ID: |
289 | case DNTT_TYPE_TEMPLATE: | |
290 | case DNTT_TYPE_TEMPLATE_ARG: | |
291 | case DNTT_TYPE_FUNC_TEMPLATE: | |
292 | case DNTT_TYPE_LINK: | |
c5aa993b JM |
293 | /* DNTT_TYPE_DYN_ARRAY_DESC ? */ |
294 | /* DNTT_TYPE_DESC_SUBRANGE ? */ | |
295 | /* DNTT_TYPE_BEGIN_EXT ? */ | |
296 | /* DNTT_TYPE_INLN ? */ | |
297 | /* DNTT_TYPE_INLN_LIST ? */ | |
298 | /* DNTT_TYPE_ALIAS ? */ | |
c906108c SS |
299 | default: |
300 | return 0; | |
301 | } | |
302 | } | |
303 | ||
304 | /* Do the dirty work of reading in the full symbol from a partial symbol | |
305 | table. */ | |
306 | ||
307 | static void | |
fba45db2 | 308 | hpread_psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c SS |
309 | { |
310 | struct cleanup *old_chain; | |
311 | int i; | |
312 | ||
313 | /* Get out quick if passed junk. */ | |
314 | if (!pst) | |
315 | return; | |
316 | ||
317 | /* Complain if we've already read in this symbol table. */ | |
318 | if (pst->readin) | |
319 | { | |
320 | fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n", | |
321 | pst->filename); | |
322 | return; | |
323 | } | |
324 | ||
325 | /* Read in all partial symtabs on which this one is dependent */ | |
326 | for (i = 0; i < pst->number_of_dependencies; i++) | |
327 | if (!pst->dependencies[i]->readin) | |
328 | { | |
329 | /* Inform about additional files that need to be read in. */ | |
330 | if (info_verbose) | |
331 | { | |
332 | fputs_filtered (" ", gdb_stdout); | |
333 | wrap_here (""); | |
334 | fputs_filtered ("and ", gdb_stdout); | |
335 | wrap_here (""); | |
336 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
337 | wrap_here (""); /* Flush output */ | |
338 | gdb_flush (gdb_stdout); | |
339 | } | |
340 | hpread_psymtab_to_symtab_1 (pst->dependencies[i]); | |
341 | } | |
342 | ||
343 | /* If it's real... */ | |
344 | if (LDSYMLEN (pst)) | |
345 | { | |
346 | /* Init stuff necessary for reading in symbols */ | |
347 | buildsym_init (); | |
348 | old_chain = make_cleanup (really_free_pendings, 0); | |
349 | ||
350 | pst->symtab = | |
351 | hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst), | |
352 | pst->textlow, pst->texthigh - pst->textlow, | |
353 | pst->section_offsets, pst->filename); | |
354 | sort_symtab_syms (pst->symtab); | |
355 | ||
356 | do_cleanups (old_chain); | |
357 | } | |
358 | ||
359 | pst->readin = 1; | |
360 | } | |
361 | ||
362 | /* Read in all of the symbols for a given psymtab for real. | |
363 | Be verbose about it if the user wants that. */ | |
364 | ||
365 | void | |
fba45db2 | 366 | hpread_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
367 | { |
368 | /* Get out quick if given junk. */ | |
369 | if (!pst) | |
370 | return; | |
371 | ||
372 | /* Sanity check. */ | |
373 | if (pst->readin) | |
374 | { | |
375 | fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n", | |
376 | pst->filename); | |
377 | return; | |
378 | } | |
379 | ||
380 | /* elz: setting the flag to indicate that the code of the target | |
381 | was compiled using an HP compiler (aCC, cc) | |
382 | the processing_acc_compilation variable is declared in the | |
383 | file buildsym.h, the HP_COMPILED_TARGET is defined to be equal | |
c5aa993b | 384 | to 3 in the file tm_hppa.h */ |
c906108c SS |
385 | |
386 | processing_gcc_compilation = 0; | |
387 | ||
388 | if (LDSYMLEN (pst) || pst->number_of_dependencies) | |
389 | { | |
390 | /* Print the message now, before reading the string table, | |
391 | to avoid disconcerting pauses. */ | |
392 | if (info_verbose) | |
393 | { | |
394 | printf_filtered ("Reading in symbols for %s...", pst->filename); | |
395 | gdb_flush (gdb_stdout); | |
396 | } | |
397 | ||
398 | hpread_psymtab_to_symtab_1 (pst); | |
399 | ||
400 | /* Match with global symbols. This only needs to be done once, | |
401 | after all of the symtabs and dependencies have been read in. */ | |
402 | scan_file_globals (pst->objfile); | |
403 | ||
404 | /* Finish up the debug error message. */ | |
405 | if (info_verbose) | |
406 | printf_filtered ("done.\n"); | |
407 | } | |
408 | } | |
409 | ||
410 | /* Read in a defined section of a specific object file's symbols. | |
411 | ||
412 | DESC is the file descriptor for the file, positioned at the | |
413 | beginning of the symtab | |
414 | SYM_OFFSET is the offset within the file of | |
415 | the beginning of the symbols we want to read | |
416 | SYM_SIZE is the size of the symbol info to read in. | |
417 | TEXT_OFFSET is the beginning of the text segment we are reading symbols for | |
418 | TEXT_SIZE is the size of the text segment read in. | |
419 | SECTION_OFFSETS are the relocation offsets which get added to each symbol. */ | |
420 | ||
421 | static struct symtab * | |
fba45db2 KB |
422 | hpread_expand_symtab (struct objfile *objfile, int sym_offset, int sym_size, |
423 | CORE_ADDR text_offset, int text_size, | |
424 | struct section_offsets *section_offsets, char *filename) | |
c906108c | 425 | { |
c5aa993b | 426 | char *namestring; |
c906108c | 427 | union dnttentry *dn_bufp; |
c5aa993b JM |
428 | unsigned max_symnum; |
429 | int at_module_boundary = 0; | |
430 | /* 1 => at end, -1 => at beginning */ | |
c906108c SS |
431 | |
432 | int sym_index = sym_offset / sizeof (struct dntt_type_block); | |
433 | ||
434 | current_objfile = objfile; | |
435 | subfile_stack = 0; | |
436 | ||
437 | last_source_file = 0; | |
438 | ||
439 | /* Demangling style -- if EDG style already set, don't change it, | |
c5aa993b JM |
440 | as HP style causes some problems with the KAI EDG compiler */ |
441 | if (current_demangling_style != edg_demangling) | |
442 | { | |
443 | /* Otherwise, ensure that we are using HP style demangling */ | |
444 | set_demangling_style (HP_DEMANGLING_STYLE_STRING); | |
445 | } | |
c906108c SS |
446 | |
447 | dn_bufp = hpread_get_lntt (sym_index, objfile); | |
448 | if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) || | |
449 | (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE))) | |
450 | { | |
451 | start_symtab ("globals", NULL, 0); | |
452 | record_debugformat ("HP"); | |
453 | } | |
454 | ||
455 | /* The psymtab builder (hp-psymtab-read.c) is the one that | |
456 | * determined the "sym_size" argument (i.e. how many DNTT symbols | |
457 | * are in this symtab), which we use to compute "max_symnum" | |
458 | * (point in DNTT to which we read). | |
459 | * | |
460 | * Perhaps this should be changed so that | |
461 | * process_one_debug_symbol() "knows" when | |
462 | * to stop reading (based on reading from the MODULE to the matching | |
463 | * END), and take out this reliance on a #-syms being passed in... | |
464 | * (I'm worried about the reliability of this number). But I'll | |
465 | * leave it as-is, for now. - RT | |
466 | * | |
467 | * The change above has been made. I've left the "for" loop control | |
468 | * in to prepare for backing this out again. -JB | |
469 | */ | |
470 | max_symnum = sym_size / sizeof (struct dntt_type_block); | |
c5aa993b | 471 | /* No reason to multiply on pst side and divide on sym side... FIXME */ |
c906108c SS |
472 | |
473 | /* Read in and process each debug symbol within the specified range. | |
474 | */ | |
475 | for (symnum = 0; | |
c5aa993b | 476 | symnum < max_symnum; |
c906108c SS |
477 | symnum++) |
478 | { | |
479 | QUIT; /* Allow this to be interruptable */ | |
480 | dn_bufp = hpread_get_lntt (sym_index + symnum, objfile); | |
481 | ||
482 | if (dn_bufp->dblock.extension) | |
483 | continue; | |
484 | ||
485 | /* Yow! We call SET_NAMESTRING on things without names! */ | |
486 | SET_NAMESTRING (dn_bufp, &namestring, objfile); | |
487 | ||
488 | hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets, | |
489 | objfile, text_offset, text_size, | |
490 | filename, symnum + sym_index, | |
c5aa993b JM |
491 | &at_module_boundary |
492 | ); | |
493 | ||
c906108c SS |
494 | /* OLD COMMENTS: This routine is only called for psts. All psts |
495 | * correspond to MODULES. If we ever do lazy-reading of globals | |
496 | * from the LNTT, then there will be a pst which ends when the | |
497 | * LNTT ends, and not at an END MODULE entry. Then we'll have | |
498 | * to re-visit this break. | |
499 | ||
500 | if( at_end_of_module ) | |
c5aa993b | 501 | break; |
c906108c SS |
502 | |
503 | */ | |
504 | ||
505 | /* We no longer break out of the loop when we reach the end of a | |
506 | module. The reason is that with CTTI, the compiler can generate | |
507 | function symbols (for template function instantiations) which are not | |
508 | in any module; typically they show up beyond a module's end, and | |
509 | before the next module's start. We include them in the current | |
510 | module. However, we still don't trust the MAX_SYMNUM value from | |
511 | the psymtab, so we break out if we enter a new module. */ | |
512 | ||
513 | if (at_module_boundary == -1) | |
c5aa993b | 514 | break; |
c906108c SS |
515 | } |
516 | ||
517 | current_objfile = NULL; | |
c5aa993b JM |
518 | hp_som_som_object_present = 1; /* Indicate we've processed an HP SOM SOM file */ |
519 | ||
44c75fb3 | 520 | return end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
521 | } |
522 | \f | |
523 | ||
524 | ||
525 | ||
526 | /* Convert basic types from HP debug format into GDB internal format. */ | |
527 | ||
528 | static int | |
fba45db2 | 529 | hpread_type_translate (dnttpointer typep) |
c906108c | 530 | { |
c5aa993b JM |
531 | if (!typep.dntti.immediate) |
532 | { | |
533 | error ("error in hpread_type_translate\n."); | |
1faa59a8 | 534 | return FT_VOID; |
c5aa993b | 535 | } |
c906108c SS |
536 | |
537 | switch (typep.dntti.type) | |
538 | { | |
539 | case HP_TYPE_BOOLEAN: | |
540 | case HP_TYPE_BOOLEAN_S300_COMPAT: | |
541 | case HP_TYPE_BOOLEAN_VAX_COMPAT: | |
542 | return FT_BOOLEAN; | |
c5aa993b JM |
543 | case HP_TYPE_CHAR: /* C signed char, C++ plain char */ |
544 | ||
c906108c SS |
545 | case HP_TYPE_WIDE_CHAR: |
546 | return FT_CHAR; | |
547 | case HP_TYPE_INT: | |
548 | if (typep.dntti.bitlength <= 8) | |
c5aa993b | 549 | return FT_SIGNED_CHAR; /* C++ signed char */ |
c906108c SS |
550 | if (typep.dntti.bitlength <= 16) |
551 | return FT_SHORT; | |
552 | if (typep.dntti.bitlength <= 32) | |
553 | return FT_INTEGER; | |
554 | return FT_LONG_LONG; | |
555 | case HP_TYPE_LONG: | |
556 | if (typep.dntti.bitlength <= 8) | |
c5aa993b | 557 | return FT_SIGNED_CHAR; /* C++ signed char. */ |
c906108c SS |
558 | return FT_LONG; |
559 | case HP_TYPE_UNSIGNED_LONG: | |
560 | if (typep.dntti.bitlength <= 8) | |
c5aa993b | 561 | return FT_UNSIGNED_CHAR; /* C/C++ unsigned char */ |
c906108c SS |
562 | if (typep.dntti.bitlength <= 16) |
563 | return FT_UNSIGNED_SHORT; | |
564 | if (typep.dntti.bitlength <= 32) | |
565 | return FT_UNSIGNED_LONG; | |
566 | return FT_UNSIGNED_LONG_LONG; | |
567 | case HP_TYPE_UNSIGNED_INT: | |
568 | if (typep.dntti.bitlength <= 8) | |
569 | return FT_UNSIGNED_CHAR; | |
570 | if (typep.dntti.bitlength <= 16) | |
571 | return FT_UNSIGNED_SHORT; | |
572 | if (typep.dntti.bitlength <= 32) | |
573 | return FT_UNSIGNED_INTEGER; | |
574 | return FT_UNSIGNED_LONG_LONG; | |
575 | case HP_TYPE_REAL: | |
576 | case HP_TYPE_REAL_3000: | |
577 | case HP_TYPE_DOUBLE: | |
578 | if (typep.dntti.bitlength == 64) | |
579 | return FT_DBL_PREC_FLOAT; | |
580 | if (typep.dntti.bitlength == 128) | |
581 | return FT_EXT_PREC_FLOAT; | |
582 | return FT_FLOAT; | |
583 | case HP_TYPE_COMPLEX: | |
584 | case HP_TYPE_COMPLEXS3000: | |
585 | if (typep.dntti.bitlength == 128) | |
586 | return FT_DBL_PREC_COMPLEX; | |
587 | if (typep.dntti.bitlength == 192) | |
588 | return FT_EXT_PREC_COMPLEX; | |
589 | return FT_COMPLEX; | |
590 | case HP_TYPE_VOID: | |
591 | return FT_VOID; | |
592 | case HP_TYPE_STRING200: | |
593 | case HP_TYPE_LONGSTRING200: | |
594 | case HP_TYPE_FTN_STRING_SPEC: | |
595 | case HP_TYPE_MOD_STRING_SPEC: | |
596 | case HP_TYPE_MOD_STRING_3000: | |
597 | case HP_TYPE_FTN_STRING_S300_COMPAT: | |
598 | case HP_TYPE_FTN_STRING_VAX_COMPAT: | |
599 | return FT_STRING; | |
600 | case HP_TYPE_TEMPLATE_ARG: | |
601 | return FT_TEMPLATE_ARG; | |
602 | case HP_TYPE_TEXT: | |
603 | case HP_TYPE_FLABEL: | |
604 | case HP_TYPE_PACKED_DECIMAL: | |
c5aa993b | 605 | case HP_TYPE_ANYPOINTER: |
c906108c | 606 | case HP_TYPE_GLOBAL_ANYPOINTER: |
c5aa993b | 607 | case HP_TYPE_LOCAL_ANYPOINTER: |
c906108c SS |
608 | default: |
609 | warning ("hpread_type_translate: unhandled type code.\n"); | |
610 | return FT_VOID; | |
611 | } | |
612 | } | |
613 | ||
614 | /* Given a position in the DNTT, return a pointer to the | |
615 | * already-built "struct type" (if any), for the type defined | |
616 | * at that position. | |
617 | */ | |
618 | ||
619 | static struct type ** | |
fba45db2 | 620 | hpread_lookup_type (dnttpointer hp_type, struct objfile *objfile) |
c906108c SS |
621 | { |
622 | unsigned old_len; | |
623 | int index = hp_type.dnttp.index; | |
624 | int size_changed = 0; | |
625 | ||
626 | /* The immediate flag indicates this doesn't actually point to | |
627 | * a type DNTT. | |
628 | */ | |
629 | if (hp_type.dntti.immediate) | |
630 | return NULL; | |
631 | ||
632 | /* For each objfile, we maintain a "type vector". | |
633 | * This an array of "struct type *"'s with one pointer per DNTT index. | |
634 | * Given a DNTT index, we look in this array to see if we have | |
635 | * already processed this DNTT and if it is a type definition. | |
636 | * If so, then we can locate a pointer to the already-built | |
637 | * "struct type", and not build it again. | |
638 | * | |
639 | * The need for this arises because our DNTT-walking code wanders | |
640 | * around. In particular, it will encounter the same type multiple | |
641 | * times (once for each object of that type). We don't want to | |
642 | * built multiple "struct type"'s for the same thing. | |
643 | * | |
644 | * Having said this, I should point out that this type-vector is | |
645 | * an expensive way to keep track of this. If most DNTT entries are | |
646 | * 3 words, the type-vector will be 1/3 the size of the DNTT itself. | |
647 | * Alternative solutions: | |
648 | * - Keep a compressed or hashed table. Less memory, but more expensive | |
649 | * to search and update. | |
650 | * - (Suggested by JB): Overwrite the DNTT entry itself | |
651 | * with the info. Create a new type code "ALREADY_BUILT", and modify | |
652 | * the DNTT to have that type code and point to the already-built entry. | |
653 | * -RT | |
654 | */ | |
655 | ||
656 | if (index < LNTT_SYMCOUNT (objfile)) | |
657 | { | |
658 | if (index >= TYPE_VECTOR_LENGTH (objfile)) | |
659 | { | |
660 | old_len = TYPE_VECTOR_LENGTH (objfile); | |
661 | ||
c5aa993b | 662 | /* See if we need to allocate a type-vector. */ |
c906108c SS |
663 | if (old_len == 0) |
664 | { | |
c5aa993b | 665 | TYPE_VECTOR_LENGTH (objfile) = LNTT_SYMCOUNT (objfile) + GNTT_SYMCOUNT (objfile); |
c906108c SS |
666 | TYPE_VECTOR (objfile) = (struct type **) |
667 | xmmalloc (objfile->md, TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)); | |
668 | memset (&TYPE_VECTOR (objfile)[old_len], 0, | |
c5aa993b JM |
669 | (TYPE_VECTOR_LENGTH (objfile) - old_len) * |
670 | sizeof (struct type *)); | |
c906108c SS |
671 | } |
672 | ||
c5aa993b JM |
673 | /* See if we need to resize type-vector. With my change to |
674 | * initially allocate a correct-size type-vector, this code | |
675 | * should no longer trigger. | |
676 | */ | |
677 | while (index >= TYPE_VECTOR_LENGTH (objfile)) | |
678 | { | |
679 | TYPE_VECTOR_LENGTH (objfile) *= 2; | |
680 | size_changed = 1; | |
681 | } | |
682 | if (size_changed) | |
683 | { | |
684 | TYPE_VECTOR (objfile) = (struct type **) | |
685 | xmrealloc (objfile->md, | |
686 | (char *) TYPE_VECTOR (objfile), | |
687 | (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *))); | |
c906108c SS |
688 | |
689 | memset (&TYPE_VECTOR (objfile)[old_len], 0, | |
c5aa993b JM |
690 | (TYPE_VECTOR_LENGTH (objfile) - old_len) * |
691 | sizeof (struct type *)); | |
692 | } | |
c906108c SS |
693 | |
694 | } | |
695 | return &TYPE_VECTOR (objfile)[index]; | |
696 | } | |
697 | else | |
698 | return NULL; | |
699 | } | |
700 | ||
701 | /* Possibly allocate a GDB internal type so we can internalize HP_TYPE. | |
702 | Note we'll just return the address of a GDB internal type if we already | |
703 | have it lying around. */ | |
704 | ||
705 | static struct type * | |
fba45db2 | 706 | hpread_alloc_type (dnttpointer hp_type, struct objfile *objfile) |
c906108c SS |
707 | { |
708 | struct type **type_addr; | |
709 | ||
710 | type_addr = hpread_lookup_type (hp_type, objfile); | |
c5aa993b JM |
711 | if (*type_addr == 0) |
712 | { | |
713 | *type_addr = alloc_type (objfile); | |
c906108c | 714 | |
c5aa993b JM |
715 | /* A hack - if we really are a C++ class symbol, then this default |
716 | * will get overriden later on. | |
717 | */ | |
718 | TYPE_CPLUS_SPECIFIC (*type_addr) | |
719 | = (struct cplus_struct_type *) &cplus_struct_default; | |
720 | } | |
c906108c SS |
721 | |
722 | return *type_addr; | |
723 | } | |
724 | ||
725 | /* Read a native enumerated type and return it in GDB internal form. */ | |
726 | ||
727 | static struct type * | |
fba45db2 KB |
728 | hpread_read_enum_type (dnttpointer hp_type, union dnttentry *dn_bufp, |
729 | struct objfile *objfile) | |
c906108c SS |
730 | { |
731 | struct type *type; | |
732 | struct pending **symlist, *osyms, *syms; | |
733 | struct pending *local_list = NULL; | |
734 | int o_nsyms, nsyms = 0; | |
735 | dnttpointer mem; | |
736 | union dnttentry *memp; | |
737 | char *name; | |
738 | long n; | |
739 | struct symbol *sym; | |
740 | ||
741 | /* Allocate a GDB type. If we've already read in this enum type, | |
742 | * it'll return the already built GDB type, so stop here. | |
743 | * (Note: I added this check, to conform with what's done for | |
744 | * struct, union, class. | |
745 | * I assume this is OK. - RT) | |
746 | */ | |
747 | type = hpread_alloc_type (hp_type, objfile); | |
748 | if (TYPE_CODE (type) == TYPE_CODE_ENUM) | |
749 | return type; | |
750 | ||
751 | /* HP C supports "sized enums", where a specifier such as "short" or | |
752 | "char" can be used to get enums of different sizes. So don't assume | |
753 | an enum is always 4 bytes long. pai/1997-08-21 */ | |
754 | TYPE_LENGTH (type) = dn_bufp->denum.bitlength / 8; | |
755 | ||
756 | symlist = &file_symbols; | |
757 | osyms = *symlist; | |
758 | o_nsyms = osyms ? osyms->nsyms : 0; | |
759 | ||
760 | /* Get a name for each member and add it to our list of members. | |
761 | * The list of "mem" SOM records we are walking should all be | |
762 | * SOM type DNTT_TYPE_MEMENUM (not checked). | |
763 | */ | |
764 | mem = dn_bufp->denum.firstmem; | |
765 | while (mem.word && mem.word != DNTTNIL) | |
766 | { | |
767 | memp = hpread_get_lntt (mem.dnttp.index, objfile); | |
768 | ||
769 | name = VT (objfile) + memp->dmember.name; | |
770 | sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack, | |
771 | sizeof (struct symbol)); | |
772 | memset (sym, 0, sizeof (struct symbol)); | |
c5aa993b | 773 | SYMBOL_NAME (sym) = obsavestring (name, strlen (name), |
c906108c SS |
774 | &objfile->symbol_obstack); |
775 | SYMBOL_CLASS (sym) = LOC_CONST; | |
776 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
777 | SYMBOL_VALUE (sym) = memp->dmember.value; | |
778 | add_symbol_to_list (sym, symlist); | |
779 | nsyms++; | |
780 | mem = memp->dmember.nextmem; | |
781 | } | |
782 | ||
783 | /* Now that we know more about the enum, fill in more info. */ | |
784 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
785 | TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB; | |
786 | TYPE_NFIELDS (type) = nsyms; | |
787 | TYPE_FIELDS (type) = (struct field *) | |
788 | obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms); | |
789 | ||
790 | /* Find the symbols for the members and put them into the type. | |
791 | The symbols can be found in the symlist that we put them on | |
792 | to cause them to be defined. osyms contains the old value | |
793 | of that symlist; everything up to there was defined by us. | |
794 | ||
795 | Note that we preserve the order of the enum constants, so | |
796 | that in something like "enum {FOO, LAST_THING=FOO}" we print | |
797 | FOO, not LAST_THING. */ | |
798 | for (syms = *symlist, n = 0; syms; syms = syms->next) | |
799 | { | |
800 | int j = 0; | |
801 | if (syms == osyms) | |
802 | j = o_nsyms; | |
803 | for (; j < syms->nsyms; j++, n++) | |
804 | { | |
805 | struct symbol *xsym = syms->symbol[j]; | |
806 | SYMBOL_TYPE (xsym) = type; | |
807 | TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym); | |
808 | TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym); | |
809 | TYPE_FIELD_BITSIZE (type, n) = 0; | |
810 | } | |
811 | if (syms == osyms) | |
812 | break; | |
813 | } | |
814 | ||
815 | return type; | |
816 | } | |
817 | ||
818 | /* Read and internalize a native function debug symbol. */ | |
819 | ||
820 | static struct type * | |
fba45db2 KB |
821 | hpread_read_function_type (dnttpointer hp_type, union dnttentry *dn_bufp, |
822 | struct objfile *objfile, int newblock) | |
c906108c SS |
823 | { |
824 | struct type *type, *type1; | |
825 | struct pending *syms; | |
826 | struct pending *local_list = NULL; | |
827 | int nsyms = 0; | |
828 | dnttpointer param; | |
829 | union dnttentry *paramp; | |
830 | char *name; | |
831 | long n; | |
832 | struct symbol *sym; | |
833 | int record_args = 1; | |
834 | ||
835 | /* See if we've already read in this type. */ | |
836 | type = hpread_alloc_type (hp_type, objfile); | |
837 | if (TYPE_CODE (type) == TYPE_CODE_FUNC) | |
838 | { | |
c5aa993b | 839 | record_args = 0; /* already read in, don't modify type */ |
c906108c SS |
840 | } |
841 | else | |
842 | { | |
843 | /* Nope, so read it in and store it away. */ | |
844 | if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION || | |
c5aa993b JM |
845 | dn_bufp->dblock.kind == DNTT_TYPE_MEMFUNC) |
846 | type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval, | |
847 | objfile)); | |
c906108c | 848 | else if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTYPE) |
c5aa993b JM |
849 | type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval, |
850 | objfile)); | |
851 | else /* expect DNTT_TYPE_FUNC_TEMPLATE */ | |
852 | type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc_template.retval, | |
853 | objfile)); | |
c906108c | 854 | memcpy ((char *) type, (char *) type1, sizeof (struct type)); |
c5aa993b JM |
855 | |
856 | /* Mark it -- in the middle of processing */ | |
c906108c SS |
857 | TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE; |
858 | } | |
859 | ||
860 | /* Now examine each parameter noting its type, location, and a | |
861 | wealth of other information. */ | |
862 | if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION || | |
863 | dn_bufp->dblock.kind == DNTT_TYPE_MEMFUNC) | |
864 | param = dn_bufp->dfunc.firstparam; | |
865 | else if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTYPE) | |
866 | param = dn_bufp->dfunctype.firstparam; | |
c5aa993b | 867 | else /* expect DNTT_TYPE_FUNC_TEMPLATE */ |
c906108c SS |
868 | param = dn_bufp->dfunc_template.firstparam; |
869 | while (param.word && param.word != DNTTNIL) | |
870 | { | |
871 | paramp = hpread_get_lntt (param.dnttp.index, objfile); | |
872 | nsyms++; | |
873 | param = paramp->dfparam.nextparam; | |
874 | ||
875 | /* Get the name. */ | |
876 | name = VT (objfile) + paramp->dfparam.name; | |
877 | sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack, | |
878 | sizeof (struct symbol)); | |
879 | (void) memset (sym, 0, sizeof (struct symbol)); | |
880 | SYMBOL_NAME (sym) = obsavestring (name, strlen (name), | |
881 | &objfile->symbol_obstack); | |
882 | ||
883 | /* Figure out where it lives. */ | |
884 | if (paramp->dfparam.regparam) | |
885 | SYMBOL_CLASS (sym) = LOC_REGPARM; | |
886 | else if (paramp->dfparam.indirect) | |
887 | SYMBOL_CLASS (sym) = LOC_REF_ARG; | |
888 | else | |
889 | SYMBOL_CLASS (sym) = LOC_ARG; | |
890 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
891 | if (paramp->dfparam.copyparam) | |
892 | { | |
c5aa993b | 893 | SYMBOL_VALUE (sym) = paramp->dfparam.location; |
c906108c SS |
894 | #ifdef HPREAD_ADJUST_STACK_ADDRESS |
895 | SYMBOL_VALUE (sym) | |
896 | += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile)); | |
897 | #endif | |
898 | /* This is likely a pass-by-invisible reference parameter, | |
899 | Hack on the symbol class to make GDB happy. */ | |
c5aa993b JM |
900 | /* ??rehrauer: This appears to be broken w/r/t to passing |
901 | C values of type float and struct. Perhaps this ought | |
902 | to be highighted as a special case, but for now, just | |
903 | allowing these to be LOC_ARGs seems to work fine. | |
904 | */ | |
c906108c SS |
905 | #if 0 |
906 | SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR; | |
907 | #endif | |
908 | } | |
909 | else | |
910 | SYMBOL_VALUE (sym) = paramp->dfparam.location; | |
911 | ||
912 | /* Get its type. */ | |
913 | SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile); | |
914 | /* Add it to the symbol list. */ | |
915 | /* Note 1 (RT) At the moment, add_symbol_to_list() is also being | |
916 | * called on FPARAM symbols from the process_one_debug_symbol() | |
917 | * level... so parameters are getting added twice! (this shows | |
918 | * up in the symbol dump you get from "maint print symbols ..."). | |
919 | * Note 2 (RT) I took out the processing of FPARAM from the | |
920 | * process_one_debug_symbol() level, so at the moment parameters are only | |
921 | * being processed here. This seems to have no ill effect. | |
922 | */ | |
923 | /* Note 3 (pai/1997-08-11) I removed the add_symbol_to_list() which put | |
924 | each fparam on the local_symbols list from here. Now we use the | |
925 | local_list to which fparams are added below, and set the param_symbols | |
c5aa993b | 926 | global to point to that at the end of this routine. */ |
c906108c SS |
927 | /* elz: I added this new list of symbols which is local to the function. |
928 | this list is the one which is actually used to build the type for the | |
929 | function rather than the gloabal list pointed to by symlist. | |
930 | Using a global list to keep track of the parameters is wrong, because | |
931 | this function is called recursively if one parameter happend to be | |
932 | a function itself with more parameters in it. Adding parameters to the | |
933 | same global symbol list would not work! | |
934 | Actually it did work in case of cc compiled programs where you do | |
c5aa993b | 935 | not check the parameter lists of the arguments. */ |
c906108c SS |
936 | add_symbol_to_list (sym, &local_list); |
937 | ||
938 | } | |
939 | ||
940 | /* If type was read in earlier, don't bother with modifying | |
c5aa993b | 941 | the type struct */ |
c906108c SS |
942 | if (!record_args) |
943 | goto finish; | |
c5aa993b | 944 | |
c906108c SS |
945 | /* Note how many parameters we found. */ |
946 | TYPE_NFIELDS (type) = nsyms; | |
947 | TYPE_FIELDS (type) = (struct field *) | |
948 | obstack_alloc (&objfile->type_obstack, | |
949 | sizeof (struct field) * nsyms); | |
950 | ||
951 | /* Find the symbols for the parameters and | |
952 | use them to fill parameter-type information into the function-type. | |
953 | The parameter symbols can be found in the local_list that we just put them on. */ | |
954 | /* Note that we preserve the order of the parameters, so | |
955 | that in something like "enum {FOO, LAST_THING=FOO}" we print | |
956 | FOO, not LAST_THING. */ | |
c5aa993b | 957 | |
c906108c SS |
958 | /* get the parameters types from the local list not the global list |
959 | so that the type can be correctly constructed for functions which | |
960 | have function as parameters */ | |
961 | for (syms = local_list, n = 0; syms; syms = syms->next) | |
962 | { | |
963 | int j = 0; | |
c5aa993b | 964 | for (j = 0; j < syms->nsyms; j++, n++) |
c906108c SS |
965 | { |
966 | struct symbol *xsym = syms->symbol[j]; | |
967 | TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym); | |
968 | TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym); | |
8176bb6d | 969 | TYPE_FIELD_ARTIFICIAL (type, n) = 0; |
c906108c SS |
970 | TYPE_FIELD_BITSIZE (type, n) = 0; |
971 | } | |
972 | } | |
c5aa993b | 973 | /* Mark it as having been processed */ |
c906108c SS |
974 | TYPE_FLAGS (type) &= ~(TYPE_FLAG_INCOMPLETE); |
975 | ||
976 | /* Check whether we need to fix-up a class type with this function's type */ | |
977 | if (fixup_class && (fixup_method == type)) | |
978 | { | |
979 | fixup_class_method_type (fixup_class, fixup_method, objfile); | |
980 | fixup_class = NULL; | |
981 | fixup_method = NULL; | |
982 | } | |
983 | ||
984 | /* Set the param list of this level of the context stack | |
985 | to our local list. Do this only if this function was | |
986 | called for creating a new block, and not if it was called | |
987 | simply to get the function type. This prevents recursive | |
988 | invocations from trashing param_symbols. */ | |
c5aa993b | 989 | finish: |
c906108c SS |
990 | if (newblock) |
991 | param_symbols = local_list; | |
c5aa993b JM |
992 | |
993 | return type; | |
c906108c SS |
994 | } |
995 | ||
996 | ||
997 | /* Read and internalize a native DOC function debug symbol. */ | |
998 | /* This is almost identical to hpread_read_function_type(), except | |
999 | * for references to dn_bufp->ddocfunc instead of db_bufp->dfunc. | |
1000 | * Since debug information for DOC functions is more likely to be | |
1001 | * volatile, please leave it this way. | |
1002 | */ | |
1003 | static struct type * | |
fba45db2 KB |
1004 | hpread_read_doc_function_type (dnttpointer hp_type, union dnttentry *dn_bufp, |
1005 | struct objfile *objfile, int newblock) | |
c906108c SS |
1006 | { |
1007 | struct type *type, *type1; | |
1008 | struct pending *syms; | |
1009 | struct pending *local_list = NULL; | |
1010 | int nsyms = 0; | |
1011 | dnttpointer param; | |
1012 | union dnttentry *paramp; | |
1013 | char *name; | |
1014 | long n; | |
1015 | struct symbol *sym; | |
1016 | int record_args = 1; | |
1017 | ||
1018 | /* See if we've already read in this type. */ | |
1019 | type = hpread_alloc_type (hp_type, objfile); | |
1020 | if (TYPE_CODE (type) == TYPE_CODE_FUNC) | |
1021 | { | |
c5aa993b | 1022 | record_args = 0; /* already read in, don't modify type */ |
c906108c SS |
1023 | } |
1024 | else | |
1025 | { | |
1026 | /* Nope, so read it in and store it away. */ | |
1027 | if (dn_bufp->dblock.kind == DNTT_TYPE_DOC_FUNCTION || | |
c5aa993b JM |
1028 | dn_bufp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC) |
1029 | type1 = lookup_function_type (hpread_type_lookup (dn_bufp->ddocfunc.retval, | |
1030 | objfile)); | |
c906108c | 1031 | memcpy ((char *) type, (char *) type1, sizeof (struct type)); |
c5aa993b JM |
1032 | |
1033 | /* Mark it -- in the middle of processing */ | |
c906108c SS |
1034 | TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE; |
1035 | } | |
1036 | ||
1037 | /* Now examine each parameter noting its type, location, and a | |
1038 | wealth of other information. */ | |
1039 | if (dn_bufp->dblock.kind == DNTT_TYPE_DOC_FUNCTION || | |
1040 | dn_bufp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC) | |
1041 | param = dn_bufp->ddocfunc.firstparam; | |
1042 | while (param.word && param.word != DNTTNIL) | |
1043 | { | |
1044 | paramp = hpread_get_lntt (param.dnttp.index, objfile); | |
1045 | nsyms++; | |
1046 | param = paramp->dfparam.nextparam; | |
1047 | ||
1048 | /* Get the name. */ | |
1049 | name = VT (objfile) + paramp->dfparam.name; | |
1050 | sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack, | |
1051 | sizeof (struct symbol)); | |
1052 | (void) memset (sym, 0, sizeof (struct symbol)); | |
1053 | SYMBOL_NAME (sym) = name; | |
1054 | ||
1055 | /* Figure out where it lives. */ | |
1056 | if (paramp->dfparam.regparam) | |
1057 | SYMBOL_CLASS (sym) = LOC_REGPARM; | |
1058 | else if (paramp->dfparam.indirect) | |
1059 | SYMBOL_CLASS (sym) = LOC_REF_ARG; | |
1060 | else | |
1061 | SYMBOL_CLASS (sym) = LOC_ARG; | |
1062 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
1063 | if (paramp->dfparam.copyparam) | |
1064 | { | |
c5aa993b | 1065 | SYMBOL_VALUE (sym) = paramp->dfparam.location; |
c906108c SS |
1066 | #ifdef HPREAD_ADJUST_STACK_ADDRESS |
1067 | SYMBOL_VALUE (sym) | |
1068 | += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile)); | |
1069 | #endif | |
1070 | /* This is likely a pass-by-invisible reference parameter, | |
1071 | Hack on the symbol class to make GDB happy. */ | |
c5aa993b JM |
1072 | /* ??rehrauer: This appears to be broken w/r/t to passing |
1073 | C values of type float and struct. Perhaps this ought | |
1074 | to be highighted as a special case, but for now, just | |
1075 | allowing these to be LOC_ARGs seems to work fine. | |
1076 | */ | |
c906108c SS |
1077 | #if 0 |
1078 | SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR; | |
1079 | #endif | |
1080 | } | |
1081 | else | |
1082 | SYMBOL_VALUE (sym) = paramp->dfparam.location; | |
1083 | ||
1084 | /* Get its type. */ | |
1085 | SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile); | |
1086 | /* Add it to the symbol list. */ | |
1087 | /* Note 1 (RT) At the moment, add_symbol_to_list() is also being | |
1088 | * called on FPARAM symbols from the process_one_debug_symbol() | |
1089 | * level... so parameters are getting added twice! (this shows | |
1090 | * up in the symbol dump you get from "maint print symbols ..."). | |
1091 | * Note 2 (RT) I took out the processing of FPARAM from the | |
1092 | * process_one_debug_symbol() level, so at the moment parameters are only | |
1093 | * being processed here. This seems to have no ill effect. | |
1094 | */ | |
1095 | /* Note 3 (pai/1997-08-11) I removed the add_symbol_to_list() which put | |
1096 | each fparam on the local_symbols list from here. Now we use the | |
1097 | local_list to which fparams are added below, and set the param_symbols | |
c5aa993b JM |
1098 | global to point to that at the end of this routine. */ |
1099 | ||
c906108c SS |
1100 | /* elz: I added this new list of symbols which is local to the function. |
1101 | this list is the one which is actually used to build the type for the | |
1102 | function rather than the gloabal list pointed to by symlist. | |
1103 | Using a global list to keep track of the parameters is wrong, because | |
1104 | this function is called recursively if one parameter happend to be | |
1105 | a function itself with more parameters in it. Adding parameters to the | |
1106 | same global symbol list would not work! | |
1107 | Actually it did work in case of cc compiled programs where you do not check the | |
1108 | parameter lists of the arguments. */ | |
1109 | add_symbol_to_list (sym, &local_list); | |
1110 | } | |
1111 | ||
1112 | /* If type was read in earlier, don't bother with modifying | |
c5aa993b | 1113 | the type struct */ |
c906108c SS |
1114 | if (!record_args) |
1115 | goto finish; | |
c5aa993b | 1116 | |
c906108c SS |
1117 | /* Note how many parameters we found. */ |
1118 | TYPE_NFIELDS (type) = nsyms; | |
1119 | TYPE_FIELDS (type) = (struct field *) | |
1120 | obstack_alloc (&objfile->type_obstack, | |
c5aa993b | 1121 | sizeof (struct field) * nsyms); |
c906108c SS |
1122 | |
1123 | /* Find the symbols for the parameters and | |
1124 | use them to fill parameter-type information into the function-type. | |
1125 | The parameter symbols can be found in the local_list that we just put them on. */ | |
1126 | /* Note that we preserve the order of the parameters, so | |
1127 | that in something like "enum {FOO, LAST_THING=FOO}" we print | |
1128 | FOO, not LAST_THING. */ | |
c5aa993b | 1129 | |
c906108c SS |
1130 | /* get the parameters types from the local list not the global list |
1131 | so that the type can be correctly constructed for functions which | |
1132 | have function as parameters | |
c5aa993b | 1133 | */ |
c906108c SS |
1134 | for (syms = local_list, n = 0; syms; syms = syms->next) |
1135 | { | |
1136 | int j = 0; | |
1137 | for (j = 0; j < syms->nsyms; j++, n++) | |
c5aa993b JM |
1138 | { |
1139 | struct symbol *xsym = syms->symbol[j]; | |
1140 | TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym); | |
1141 | TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym); | |
8176bb6d | 1142 | TYPE_FIELD_ARTIFICIAL (type, n) = 0; |
c5aa993b JM |
1143 | TYPE_FIELD_BITSIZE (type, n) = 0; |
1144 | } | |
c906108c | 1145 | } |
c5aa993b JM |
1146 | |
1147 | /* Mark it as having been processed */ | |
c906108c SS |
1148 | TYPE_FLAGS (type) &= ~(TYPE_FLAG_INCOMPLETE); |
1149 | ||
1150 | /* Check whether we need to fix-up a class type with this function's type */ | |
1151 | if (fixup_class && (fixup_method == type)) | |
1152 | { | |
1153 | fixup_class_method_type (fixup_class, fixup_method, objfile); | |
1154 | fixup_class = NULL; | |
1155 | fixup_method = NULL; | |
1156 | } | |
1157 | ||
1158 | /* Set the param list of this level of the context stack | |
1159 | to our local list. Do this only if this function was | |
1160 | called for creating a new block, and not if it was called | |
1161 | simply to get the function type. This prevents recursive | |
1162 | invocations from trashing param_symbols. */ | |
c5aa993b | 1163 | finish: |
c906108c SS |
1164 | if (newblock) |
1165 | param_symbols = local_list; | |
c5aa993b | 1166 | |
c906108c SS |
1167 | return type; |
1168 | } | |
1169 | ||
1170 | ||
1171 | ||
1172 | /* A file-level variable which keeps track of the current-template | |
1173 | * being processed. Set in hpread_read_struct_type() while processing | |
1174 | * a template type. Referred to in hpread_get_nth_templ_arg(). | |
1175 | * Yes, this is a kludge, but it arises from the kludge that already | |
1176 | * exists in symtab.h, namely the fact that they encode | |
1177 | * "template argument n" with fundamental type FT_TEMPLATE_ARG and | |
1178 | * bitlength n. This means that deep in processing fundamental types | |
1179 | * I need to ask the question "what template am I in the middle of?". | |
1180 | * The alternative to stuffing a global would be to pass an argument | |
1181 | * down the chain of calls just for this purpose. | |
1182 | * | |
1183 | * There may be problems handling nested templates... tough. | |
1184 | */ | |
c5aa993b | 1185 | static struct type *current_template = NULL; |
c906108c SS |
1186 | |
1187 | /* Read in and internalize a structure definition. | |
1188 | * This same routine is called for struct, union, and class types. | |
1189 | * Also called for templates, since they build a very similar | |
1190 | * type entry as for class types. | |
1191 | */ | |
1192 | ||
1193 | static struct type * | |
fba45db2 KB |
1194 | hpread_read_struct_type (dnttpointer hp_type, union dnttentry *dn_bufp, |
1195 | struct objfile *objfile) | |
c906108c SS |
1196 | { |
1197 | /* The data members get linked together into a list of struct nextfield's */ | |
1198 | struct nextfield | |
1199 | { | |
1200 | struct nextfield *next; | |
1201 | struct field field; | |
c5aa993b JM |
1202 | unsigned char attributes; /* store visibility and virtuality info */ |
1203 | #define ATTR_VIRTUAL 1 | |
1204 | #define ATTR_PRIVATE 2 | |
1205 | #define ATTR_PROTECT 3 | |
c906108c SS |
1206 | }; |
1207 | ||
1208 | ||
1209 | /* The methods get linked together into a list of struct next_fn_field's */ | |
1210 | struct next_fn_field | |
1211 | { | |
1212 | struct next_fn_field *next; | |
1213 | struct fn_fieldlist field; | |
1214 | struct fn_field fn_field; | |
1215 | int num_fn_fields; | |
c5aa993b | 1216 | }; |
c906108c SS |
1217 | |
1218 | /* The template args get linked together into a list of struct next_template's */ | |
1219 | struct next_template | |
1220 | { | |
1221 | struct next_template *next; | |
1222 | struct template_arg arg; | |
1223 | }; | |
1224 | ||
1225 | /* The template instantiations get linked together into a list of these... */ | |
c5aa993b | 1226 | struct next_instantiation |
c906108c | 1227 | { |
c5aa993b JM |
1228 | struct next_instantiation *next; |
1229 | struct type *t; | |
c906108c SS |
1230 | }; |
1231 | ||
1232 | struct type *type; | |
1233 | struct type *baseclass; | |
1234 | struct type *memtype; | |
1235 | struct nextfield *list = 0, *tmp_list = 0; | |
1236 | struct next_fn_field *fn_list = 0; | |
1237 | struct next_fn_field *fn_p; | |
1238 | struct next_template *t_new, *t_list = 0; | |
1239 | struct nextfield *new; | |
1240 | struct next_fn_field *fn_new; | |
1241 | struct next_instantiation *i_new, *i_list = 0; | |
1242 | int n, nfields = 0, n_fn_fields = 0, n_fn_fields_total = 0; | |
1243 | int n_base_classes = 0, n_templ_args = 0; | |
1244 | int ninstantiations = 0; | |
1245 | dnttpointer field, fn_field, parent; | |
1246 | union dnttentry *fieldp, *fn_fieldp, *parentp; | |
1247 | int i; | |
1248 | int static_member = 0; | |
1249 | int const_member = 0; | |
1250 | int volatile_member = 0; | |
1251 | unsigned long vtbl_offset; | |
1252 | int need_bitvectors = 0; | |
c5aa993b JM |
1253 | char *method_name = NULL; |
1254 | char *method_alias = NULL; | |
1255 | ||
c906108c SS |
1256 | |
1257 | /* Is it something we've already dealt with? */ | |
1258 | type = hpread_alloc_type (hp_type, objfile); | |
1259 | if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) || | |
1260 | (TYPE_CODE (type) == TYPE_CODE_UNION) || | |
1261 | (TYPE_CODE (type) == TYPE_CODE_CLASS) || | |
1262 | (TYPE_CODE (type) == TYPE_CODE_TEMPLATE)) | |
c5aa993b | 1263 | return type; |
c906108c SS |
1264 | |
1265 | /* Get the basic type correct. */ | |
1266 | if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT) | |
1267 | { | |
1268 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
1269 | TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8; | |
1270 | } | |
1271 | else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION) | |
1272 | { | |
1273 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
1274 | TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8; | |
1275 | } | |
1276 | else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS) | |
1277 | { | |
c5aa993b | 1278 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
c906108c SS |
1279 | TYPE_LENGTH (type) = dn_bufp->dclass.bitlength / 8; |
1280 | ||
1281 | /* Overrides the TYPE_CPLUS_SPECIFIC(type) with allocated memory | |
1282 | * rather than &cplus_struct_default. | |
1283 | */ | |
c5aa993b | 1284 | allocate_cplus_struct_type (type); |
c906108c SS |
1285 | |
1286 | /* Fill in declared-type. | |
1287 | * (The C++ compiler will emit TYPE_CODE_CLASS | |
1288 | * for all 3 of "class", "struct" | |
1289 | * "union", and we have to look at the "class_decl" field if we | |
1290 | * want to know how it was really declared) | |
1291 | */ | |
1292 | /* (0==class, 1==union, 2==struct) */ | |
c5aa993b | 1293 | TYPE_DECLARED_TYPE (type) = dn_bufp->dclass.class_decl; |
c906108c SS |
1294 | } |
1295 | else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE) | |
1296 | { | |
1297 | /* Get the basic type correct. */ | |
c5aa993b JM |
1298 | TYPE_CODE (type) = TYPE_CODE_TEMPLATE; |
1299 | allocate_cplus_struct_type (type); | |
1300 | TYPE_DECLARED_TYPE (type) = DECLARED_TYPE_TEMPLATE; | |
c906108c SS |
1301 | } |
1302 | else | |
1303 | return type; | |
1304 | ||
1305 | ||
1306 | TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB; | |
1307 | ||
1308 | /* For classes, read the parent list. | |
1309 | * Question (RT): Do we need to do this for templates also? | |
1310 | */ | |
c5aa993b JM |
1311 | if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS) |
1312 | { | |
c906108c | 1313 | |
c5aa993b JM |
1314 | /* First read the parent-list (classes from which we derive fields) */ |
1315 | parent = dn_bufp->dclass.parentlist; | |
1316 | while (parent.word && parent.word != DNTTNIL) | |
1317 | { | |
1318 | parentp = hpread_get_lntt (parent.dnttp.index, objfile); | |
c906108c | 1319 | |
c5aa993b | 1320 | /* "parentp" should point to a DNTT_TYPE_INHERITANCE record */ |
c906108c | 1321 | |
c5aa993b JM |
1322 | /* Get space to record the next field/data-member. */ |
1323 | new = (struct nextfield *) alloca (sizeof (struct nextfield)); | |
1324 | new->next = list; | |
1325 | list = new; | |
c906108c | 1326 | |
c5aa993b | 1327 | FIELD_BITSIZE (list->field) = 0; |
c906108c | 1328 | |
c5aa993b JM |
1329 | /* The "classname" field is actually a DNTT pointer to the base class */ |
1330 | baseclass = hpread_type_lookup (parentp->dinheritance.classname, | |
1331 | objfile); | |
1332 | FIELD_TYPE (list->field) = baseclass; | |
c906108c | 1333 | |
c5aa993b | 1334 | list->field.name = type_name_no_tag (FIELD_TYPE (list->field)); |
c906108c | 1335 | |
c5aa993b | 1336 | list->attributes = 0; |
c906108c | 1337 | |
c5aa993b JM |
1338 | /* Check for virtuality of base, and set the |
1339 | * offset of the base subobject within the object. | |
1340 | * (Offset set to -1 for virtual bases (for now).) | |
1341 | */ | |
1342 | if (parentp->dinheritance.Virtual) | |
1343 | { | |
1344 | B_SET (&(list->attributes), ATTR_VIRTUAL); | |
1345 | parentp->dinheritance.offset = -1; | |
1346 | } | |
1347 | else | |
1348 | FIELD_BITPOS (list->field) = parentp->dinheritance.offset; | |
1349 | ||
1350 | /* Check visibility */ | |
1351 | switch (parentp->dinheritance.visibility) | |
1352 | { | |
1353 | case 1: | |
1354 | B_SET (&(list->attributes), ATTR_PROTECT); | |
1355 | break; | |
1356 | case 2: | |
1357 | B_SET (&(list->attributes), ATTR_PRIVATE); | |
1358 | break; | |
1359 | } | |
1360 | ||
1361 | n_base_classes++; | |
1362 | nfields++; | |
1363 | ||
1364 | parent = parentp->dinheritance.next; | |
1365 | } | |
c906108c | 1366 | } |
c906108c SS |
1367 | |
1368 | /* For templates, read the template argument list. | |
1369 | * This must be done before processing the member list, because | |
1370 | * the member list may refer back to this. E.g.: | |
1371 | * template <class T1, class T2> class q2 { | |
1372 | * public: | |
1373 | * T1 a; | |
1374 | * T2 b; | |
1375 | * }; | |
1376 | * We need to read the argument list "T1", "T2" first. | |
1377 | */ | |
c5aa993b JM |
1378 | if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE) |
1379 | { | |
1380 | /* Kludge alert: This stuffs a global "current_template" which | |
1381 | * is referred to by hpread_get_nth_templ_arg(). The global | |
1382 | * is cleared at the end of this routine. | |
1383 | */ | |
1384 | current_template = type; | |
c906108c | 1385 | |
c5aa993b JM |
1386 | /* Read in the argument list */ |
1387 | field = dn_bufp->dtemplate.arglist; | |
1388 | while (field.word && field.word != DNTTNIL) | |
1389 | { | |
1390 | /* Get this template argument */ | |
1391 | fieldp = hpread_get_lntt (field.dnttp.index, objfile); | |
1392 | if (fieldp->dblock.kind != DNTT_TYPE_TEMPLATE_ARG) | |
1393 | { | |
1394 | warning ("Invalid debug info: Template argument entry is of wrong kind"); | |
1395 | break; | |
1396 | } | |
1397 | /* Bump the count */ | |
1398 | n_templ_args++; | |
1399 | /* Allocate and fill in a struct next_template */ | |
1400 | t_new = (struct next_template *) alloca (sizeof (struct next_template)); | |
1401 | t_new->next = t_list; | |
1402 | t_list = t_new; | |
1403 | t_list->arg.name = VT (objfile) + fieldp->dtempl_arg.name; | |
1404 | t_list->arg.type = hpread_read_templ_arg_type (field, fieldp, | |
1405 | objfile, t_list->arg.name); | |
1406 | /* Walk to the next template argument */ | |
1407 | field = fieldp->dtempl_arg.nextarg; | |
1408 | } | |
c906108c | 1409 | } |
c906108c | 1410 | |
c5aa993b | 1411 | TYPE_NTEMPLATE_ARGS (type) = n_templ_args; |
c906108c SS |
1412 | |
1413 | if (n_templ_args > 0) | |
c5aa993b | 1414 | TYPE_TEMPLATE_ARGS (type) = (struct template_arg *) |
c906108c SS |
1415 | obstack_alloc (&objfile->type_obstack, sizeof (struct template_arg) * n_templ_args); |
1416 | for (n = n_templ_args; t_list; t_list = t_list->next) | |
1417 | { | |
1418 | n -= 1; | |
c5aa993b | 1419 | TYPE_TEMPLATE_ARG (type, n) = t_list->arg; |
c906108c SS |
1420 | } |
1421 | ||
1422 | /* Next read in and internalize all the fields/members. */ | |
1423 | if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT) | |
1424 | field = dn_bufp->dstruct.firstfield; | |
1425 | else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION) | |
1426 | field = dn_bufp->dunion.firstfield; | |
1427 | else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS) | |
1428 | field = dn_bufp->dclass.memberlist; | |
1429 | else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE) | |
1430 | field = dn_bufp->dtemplate.memberlist; | |
1431 | else | |
1432 | field.word = DNTTNIL; | |
1433 | ||
1434 | while (field.word && field.word != DNTTNIL) | |
1435 | { | |
1436 | fieldp = hpread_get_lntt (field.dnttp.index, objfile); | |
1437 | ||
1438 | /* At this point "fieldp" may point to either a DNTT_TYPE_FIELD | |
1439 | * or a DNTT_TYPE_GENFIELD record. | |
1440 | */ | |
1441 | vtbl_offset = 0; | |
1442 | static_member = 0; | |
1443 | const_member = 0; | |
1444 | volatile_member = 0; | |
c5aa993b JM |
1445 | |
1446 | if (fieldp->dblock.kind == DNTT_TYPE_GENFIELD) | |
1447 | { | |
1448 | ||
1449 | /* The type will be GENFIELD if the field is a method or | |
1450 | * a static member (or some other cases -- see below) | |
1451 | */ | |
1452 | ||
1453 | /* Follow a link to get to the record for the field. */ | |
1454 | fn_field = fieldp->dgenfield.field; | |
1455 | fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile); | |
1456 | ||
1457 | /* Virtual funcs are indicated by a VFUNC which points to the | |
1458 | * real entry | |
1459 | */ | |
1460 | if (fn_fieldp->dblock.kind == DNTT_TYPE_VFUNC) | |
1461 | { | |
1462 | vtbl_offset = fn_fieldp->dvfunc.vtbl_offset; | |
1463 | fn_field = fn_fieldp->dvfunc.funcptr; | |
1464 | fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile); | |
1465 | } | |
1466 | ||
1467 | /* A function's entry may be preceded by a modifier which | |
1468 | * labels it static/constant/volatile. | |
1469 | */ | |
1470 | if (fn_fieldp->dblock.kind == DNTT_TYPE_MODIFIER) | |
1471 | { | |
1472 | static_member = fn_fieldp->dmodifier.m_static; | |
1473 | const_member = fn_fieldp->dmodifier.m_const; | |
1474 | volatile_member = fn_fieldp->dmodifier.m_volatile; | |
1475 | fn_field = fn_fieldp->dmodifier.type; | |
1476 | fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile); | |
1477 | } | |
1478 | ||
1479 | /* Check whether we have a method */ | |
1480 | if ((fn_fieldp->dblock.kind == DNTT_TYPE_MEMFUNC) || | |
1481 | (fn_fieldp->dblock.kind == DNTT_TYPE_FUNCTION) || | |
1482 | (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC) || | |
1483 | (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_FUNCTION)) | |
1484 | { | |
1485 | /* Method found */ | |
1486 | ||
1487 | short ix = 0; | |
1488 | ||
1489 | /* Look up function type of method */ | |
1490 | memtype = hpread_type_lookup (fn_field, objfile); | |
1491 | ||
1492 | /* Methods can be seen before classes in the SOM records. | |
1493 | If we are processing this class because it's a parameter of a | |
1494 | method, at this point the method's type is actually incomplete; | |
1495 | we'll have to fix it up later; mark the class for this. */ | |
1496 | ||
1497 | if (TYPE_INCOMPLETE (memtype)) | |
1498 | { | |
1499 | TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE; | |
1500 | if (fixup_class) | |
1501 | warning ("Two classes to fix up for method?? Type information may be incorrect for some classes."); | |
1502 | if (fixup_method) | |
1503 | warning ("Two methods to be fixed up at once?? Type information may be incorrect for some classes."); | |
1504 | fixup_class = type; /* remember this class has to be fixed up */ | |
1505 | fixup_method = memtype; /* remember the method type to be used in fixup */ | |
1506 | } | |
1507 | ||
1508 | /* HP aCC generates operator names without the "operator" keyword, and | |
1509 | generates null strings as names for operators that are | |
1510 | user-defined type conversions to basic types (e.g. operator int ()). | |
1511 | So try to reconstruct name as best as possible. */ | |
1512 | ||
1513 | method_name = (char *) (VT (objfile) + fn_fieldp->dfunc.name); | |
1514 | method_alias = (char *) (VT (objfile) + fn_fieldp->dfunc.alias); | |
1515 | ||
1516 | if (!method_name || /* no name */ | |
1517 | !*method_name || /* or null name */ | |
1518 | cplus_mangle_opname (method_name, DMGL_ANSI)) /* or name is an operator like "<" */ | |
1519 | { | |
1520 | char *tmp_name = cplus_demangle (method_alias, DMGL_ANSI); | |
1521 | char *op_string = strstr (tmp_name, "operator"); | |
1522 | method_name = xmalloc (strlen (op_string) + 1); /* don't overwrite VT! */ | |
1523 | strcpy (method_name, op_string); | |
1524 | } | |
1525 | ||
1526 | /* First check if a method of the same name has already been seen. */ | |
1527 | fn_p = fn_list; | |
1528 | while (fn_p) | |
1529 | { | |
1530 | if (STREQ (fn_p->field.name, method_name)) | |
1531 | break; | |
1532 | fn_p = fn_p->next; | |
1533 | } | |
1534 | ||
1535 | /* If no such method was found, allocate a new entry in the list */ | |
1536 | if (!fn_p) | |
1537 | { | |
1538 | /* Get space to record this member function */ | |
1539 | /* Note: alloca used; this will disappear on routine exit */ | |
1540 | fn_new = (struct next_fn_field *) alloca (sizeof (struct next_fn_field)); | |
1541 | fn_new->next = fn_list; | |
1542 | fn_list = fn_new; | |
1543 | ||
1544 | /* Fill in the fields of the struct nextfield */ | |
1545 | ||
1546 | /* Record the (unmangled) method name */ | |
1547 | fn_list->field.name = method_name; | |
1548 | /* Initial space for overloaded methods */ | |
1549 | /* Note: xmalloc is used; this will persist after this routine exits */ | |
1550 | fn_list->field.fn_fields = (struct fn_field *) xmalloc (5 * (sizeof (struct fn_field))); | |
1551 | fn_list->field.length = 1; /* Init # of overloaded instances */ | |
1552 | fn_list->num_fn_fields = 5; /* # of entries for which space allocated */ | |
1553 | fn_p = fn_list; | |
1554 | ix = 0; /* array index for fn_field */ | |
1555 | /* Bump the total count of the distinctly named methods */ | |
1556 | n_fn_fields++; | |
1557 | } | |
1558 | else | |
1559 | /* Another overloaded instance of an already seen method name */ | |
1560 | { | |
1561 | if (++(fn_p->field.length) > fn_p->num_fn_fields) | |
1562 | { | |
1563 | /* Increase space allocated for overloaded instances */ | |
1564 | fn_p->field.fn_fields | |
1565 | = (struct fn_field *) xrealloc (fn_p->field.fn_fields, | |
1566 | (fn_p->num_fn_fields + 5) * sizeof (struct fn_field)); | |
1567 | fn_p->num_fn_fields += 5; | |
1568 | } | |
1569 | ix = fn_p->field.length - 1; /* array index for fn_field */ | |
1570 | } | |
1571 | ||
1572 | /* "physname" is intended to be the name of this overloaded instance. */ | |
1573 | if ((fn_fieldp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) && | |
1574 | method_alias && | |
1575 | *method_alias) /* not a null string */ | |
1576 | fn_p->field.fn_fields[ix].physname = method_alias; | |
1577 | else | |
1578 | fn_p->field.fn_fields[ix].physname = method_name; | |
1579 | /* What's expected here is the function type */ | |
1580 | /* But mark it as NULL if the method was incompletely processed | |
1581 | We'll fix this up later when the method is fully processed */ | |
1582 | if (TYPE_INCOMPLETE (memtype)) | |
1583 | { | |
1584 | fn_p->field.fn_fields[ix].type = NULL; | |
1585 | fn_p->field.fn_fields[ix].args = NULL; | |
1586 | } | |
1587 | else | |
1588 | { | |
1589 | fn_p->field.fn_fields[ix].type = memtype; | |
1590 | ||
1591 | /* The argument list */ | |
1592 | fn_p->field.fn_fields[ix].type->type_specific.arg_types = | |
1593 | (struct type **) obstack_alloc (&objfile->type_obstack, | |
1594 | sizeof (struct type *) * (memtype->nfields + 1)); | |
1595 | for (i = 0; i < memtype->nfields; i++) | |
1596 | fn_p->field.fn_fields[ix].type->type_specific.arg_types[i] = memtype->fields[i].type; | |
1597 | /* void termination */ | |
1598 | fn_p->field.fn_fields[ix].type->type_specific.arg_types[memtype->nfields] = builtin_type_void; | |
1599 | ||
1600 | /* pai: It's not clear why this args field has to be set. Perhaps | |
1601 | * it should be eliminated entirely. */ | |
1602 | fn_p->field.fn_fields[ix].args = | |
1603 | (struct type **) obstack_alloc (&objfile->type_obstack, | |
1604 | sizeof (struct type *) * (memtype->nfields + 1)); | |
1605 | for (i = 0; i < memtype->nfields; i++) | |
1606 | fn_p->field.fn_fields[ix].args[i] = memtype->fields[i].type; | |
1607 | /* null-terminated, unlike arg_types above e */ | |
1608 | fn_p->field.fn_fields[ix].args[memtype->nfields] = NULL; | |
1609 | } | |
1610 | /* For virtual functions, fill in the voffset field with the | |
1611 | * virtual table offset. (This is just copied over from the | |
1612 | * SOM record; not sure if it is what GDB expects here...). | |
1613 | * But if the function is a static method, set it to 1. | |
1614 | * | |
1615 | * Note that we have to add 1 because 1 indicates a static | |
1616 | * method, and 0 indicates a non-static, non-virtual method */ | |
1617 | ||
1618 | if (static_member) | |
1619 | fn_p->field.fn_fields[ix].voffset = VOFFSET_STATIC; | |
1620 | else | |
1621 | fn_p->field.fn_fields[ix].voffset = vtbl_offset ? vtbl_offset + 1 : 0; | |
1622 | ||
1623 | /* Also fill in the fcontext field with the current | |
1624 | * class. (The latter isn't quite right: should be the baseclass | |
1625 | * that defines the virtual function... Note we do have | |
1626 | * a variable "baseclass" that we could stuff into the fcontext | |
1627 | * field, but "baseclass" isn't necessarily right either, | |
1628 | * since the virtual function could have been defined more | |
1629 | * than one level up). | |
1630 | */ | |
1631 | ||
1632 | if (vtbl_offset != 0) | |
1633 | fn_p->field.fn_fields[ix].fcontext = type; | |
1634 | else | |
1635 | fn_p->field.fn_fields[ix].fcontext = NULL; | |
1636 | ||
1637 | /* Other random fields pertaining to this method */ | |
1638 | fn_p->field.fn_fields[ix].is_const = const_member; | |
1639 | fn_p->field.fn_fields[ix].is_volatile = volatile_member; /* ?? */ | |
1640 | switch (fieldp->dgenfield.visibility) | |
1641 | { | |
1642 | case 1: | |
1643 | fn_p->field.fn_fields[ix].is_protected = 1; | |
1644 | fn_p->field.fn_fields[ix].is_private = 0; | |
1645 | break; | |
1646 | case 2: | |
1647 | fn_p->field.fn_fields[ix].is_protected = 0; | |
1648 | fn_p->field.fn_fields[ix].is_private = 1; | |
1649 | break; | |
1650 | default: /* public */ | |
1651 | fn_p->field.fn_fields[ix].is_protected = 0; | |
1652 | fn_p->field.fn_fields[ix].is_private = 0; | |
1653 | } | |
1654 | fn_p->field.fn_fields[ix].is_stub = 0; | |
1655 | ||
1656 | /* HP aCC emits both MEMFUNC and FUNCTION entries for a method; | |
1657 | if the class points to the FUNCTION, there is usually separate | |
1658 | code for the method; but if we have a MEMFUNC, the method has | |
1659 | been inlined (and there is usually no FUNCTION entry) | |
1660 | FIXME Not sure if this test is accurate. pai/1997-08-22 */ | |
1661 | if ((fn_fieldp->dblock.kind == DNTT_TYPE_MEMFUNC) || | |
1662 | (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC)) | |
1663 | fn_p->field.fn_fields[ix].is_inlined = 1; | |
1664 | else | |
1665 | fn_p->field.fn_fields[ix].is_inlined = 0; | |
1666 | ||
1667 | fn_p->field.fn_fields[ix].dummy = 0; | |
1668 | ||
1669 | /* Bump the total count of the member functions */ | |
1670 | n_fn_fields_total++; | |
1671 | ||
1672 | } | |
1673 | else if (fn_fieldp->dblock.kind == DNTT_TYPE_SVAR) | |
1674 | { | |
1675 | /* This case is for static data members of classes */ | |
1676 | ||
1677 | /* pai:: FIXME -- check that "staticmem" bit is set */ | |
1678 | ||
1679 | /* Get space to record this static member */ | |
1680 | new = (struct nextfield *) alloca (sizeof (struct nextfield)); | |
1681 | new->next = list; | |
1682 | list = new; | |
1683 | ||
1684 | list->field.name = VT (objfile) + fn_fieldp->dsvar.name; | |
1685 | FIELD_BITSIZE (list->field) = -1; /* indicates static member */ | |
1686 | SET_FIELD_PHYSNAME (list->field, 0); /* initialize to empty */ | |
1687 | memtype = hpread_type_lookup (fn_fieldp->dsvar.type, objfile); | |
1688 | ||
1689 | FIELD_TYPE (list->field) = memtype; | |
1690 | list->attributes = 0; | |
1691 | switch (fieldp->dgenfield.visibility) | |
1692 | { | |
1693 | case 1: | |
1694 | B_SET (&(list->attributes), ATTR_PROTECT); | |
1695 | break; | |
1696 | case 2: | |
1697 | B_SET (&(list->attributes), ATTR_PRIVATE); | |
1698 | break; | |
1699 | } | |
1700 | nfields++; | |
1701 | } | |
1702 | ||
1703 | else if (fn_fieldp->dblock.kind == DNTT_TYPE_FIELD) | |
1704 | { | |
1705 | /* FIELDs follow GENFIELDs for fields of anonymous unions. | |
1706 | Code below is replicated from the case for FIELDs further | |
1707 | below, except that fieldp is replaced by fn_fieldp */ | |
1708 | if (!fn_fieldp->dfield.a_union) | |
1709 | warning ("Debug info inconsistent: FIELD of anonymous union doesn't have a_union bit set"); | |
1710 | /* Get space to record the next field/data-member. */ | |
1711 | new = (struct nextfield *) alloca (sizeof (struct nextfield)); | |
1712 | new->next = list; | |
1713 | list = new; | |
1714 | ||
1715 | list->field.name = VT (objfile) + fn_fieldp->dfield.name; | |
1716 | FIELD_BITPOS (list->field) = fn_fieldp->dfield.bitoffset; | |
1717 | if (fn_fieldp->dfield.bitlength % 8) | |
1718 | list->field.bitsize = fn_fieldp->dfield.bitlength; | |
1719 | else | |
1720 | list->field.bitsize = 0; | |
1721 | ||
1722 | memtype = hpread_type_lookup (fn_fieldp->dfield.type, objfile); | |
1723 | list->field.type = memtype; | |
1724 | list->attributes = 0; | |
1725 | switch (fn_fieldp->dfield.visibility) | |
1726 | { | |
1727 | case 1: | |
1728 | B_SET (&(list->attributes), ATTR_PROTECT); | |
1729 | break; | |
1730 | case 2: | |
1731 | B_SET (&(list->attributes), ATTR_PRIVATE); | |
1732 | break; | |
1733 | } | |
1734 | nfields++; | |
1735 | } | |
1736 | else if (fn_fieldp->dblock.kind == DNTT_TYPE_SVAR) | |
1737 | { | |
1738 | /* Field of anonymous union; union is not inside a class */ | |
1739 | if (!fn_fieldp->dsvar.a_union) | |
1740 | warning ("Debug info inconsistent: SVAR field in anonymous union doesn't have a_union bit set"); | |
1741 | /* Get space to record the next field/data-member. */ | |
1742 | new = (struct nextfield *) alloca (sizeof (struct nextfield)); | |
1743 | new->next = list; | |
1744 | list = new; | |
1745 | ||
1746 | list->field.name = VT (objfile) + fn_fieldp->dsvar.name; | |
1747 | FIELD_BITPOS (list->field) = 0; /* FIXME is this always true? */ | |
1748 | FIELD_BITSIZE (list->field) = 0; /* use length from type */ | |
1749 | memtype = hpread_type_lookup (fn_fieldp->dsvar.type, objfile); | |
1750 | list->field.type = memtype; | |
1751 | list->attributes = 0; | |
1752 | /* No info to set visibility -- always public */ | |
1753 | nfields++; | |
1754 | } | |
1755 | else if (fn_fieldp->dblock.kind == DNTT_TYPE_DVAR) | |
1756 | { | |
1757 | /* Field of anonymous union; union is not inside a class */ | |
1758 | if (!fn_fieldp->ddvar.a_union) | |
1759 | warning ("Debug info inconsistent: DVAR field in anonymous union doesn't have a_union bit set"); | |
1760 | /* Get space to record the next field/data-member. */ | |
1761 | new = (struct nextfield *) alloca (sizeof (struct nextfield)); | |
1762 | new->next = list; | |
1763 | list = new; | |
1764 | ||
1765 | list->field.name = VT (objfile) + fn_fieldp->ddvar.name; | |
1766 | FIELD_BITPOS (list->field) = 0; /* FIXME is this always true? */ | |
1767 | FIELD_BITSIZE (list->field) = 0; /* use length from type */ | |
1768 | memtype = hpread_type_lookup (fn_fieldp->ddvar.type, objfile); | |
1769 | list->field.type = memtype; | |
1770 | list->attributes = 0; | |
1771 | /* No info to set visibility -- always public */ | |
1772 | nfields++; | |
1773 | } | |
c906108c | 1774 | else |
c5aa993b JM |
1775 | { /* Not a method, nor a static data member, nor an anon union field */ |
1776 | ||
1777 | /* This case is for miscellaneous type entries (local enums, | |
1778 | local function templates, etc.) that can be present | |
1779 | inside a class. */ | |
1780 | ||
1781 | /* Enums -- will be handled by other code that takes care | |
1782 | of DNTT_TYPE_ENUM; here we see only DNTT_TYPE_MEMENUM so | |
1783 | it's not clear we could have handled them here at all. */ | |
1faa59a8 | 1784 | /* FUNC_TEMPLATE: is handled by other code (?). */ |
c5aa993b JM |
1785 | /* MEMACCESS: modified access for inherited member. Not |
1786 | sure what to do with this, ignoriing it at present. */ | |
1787 | ||
1788 | /* What other entries can appear following a GENFIELD which | |
1789 | we do not handle above? (MODIFIER, VFUNC handled above.) */ | |
1790 | ||
1791 | if ((fn_fieldp->dblock.kind != DNTT_TYPE_MEMACCESS) && | |
1792 | (fn_fieldp->dblock.kind != DNTT_TYPE_MEMENUM) && | |
1793 | (fn_fieldp->dblock.kind != DNTT_TYPE_FUNC_TEMPLATE)) | |
1794 | warning ("Internal error: Unexpected debug record kind %d found following DNTT_GENFIELD", | |
1795 | fn_fieldp->dblock.kind); | |
1796 | } | |
1797 | /* walk to the next FIELD or GENFIELD */ | |
1798 | field = fieldp->dgenfield.nextfield; | |
1799 | ||
1800 | } | |
1801 | else if (fieldp->dblock.kind == DNTT_TYPE_FIELD) | |
1802 | { | |
1803 | ||
1804 | /* Ordinary structure/union/class field */ | |
1805 | struct type *anon_union_type; | |
1806 | ||
1807 | /* Get space to record the next field/data-member. */ | |
1808 | new = (struct nextfield *) alloca (sizeof (struct nextfield)); | |
1809 | new->next = list; | |
1810 | list = new; | |
1811 | ||
1812 | list->field.name = VT (objfile) + fieldp->dfield.name; | |
1813 | ||
1814 | ||
1815 | /* A FIELD by itself (without a GENFIELD) can also be a static member */ | |
1816 | if (fieldp->dfield.staticmem) | |
1817 | { | |
1818 | FIELD_BITPOS (list->field) = -1; | |
c906108c | 1819 | FIELD_BITSIZE (list->field) = 0; |
c5aa993b JM |
1820 | } |
1821 | else | |
1822 | /* Non-static data member */ | |
1823 | { | |
1824 | FIELD_BITPOS (list->field) = fieldp->dfield.bitoffset; | |
1825 | if (fieldp->dfield.bitlength % 8) | |
1826 | FIELD_BITSIZE (list->field) = fieldp->dfield.bitlength; | |
1827 | else | |
1828 | FIELD_BITSIZE (list->field) = 0; | |
1829 | } | |
1830 | ||
1831 | memtype = hpread_type_lookup (fieldp->dfield.type, objfile); | |
1832 | FIELD_TYPE (list->field) = memtype; | |
1833 | list->attributes = 0; | |
1834 | switch (fieldp->dfield.visibility) | |
1835 | { | |
1836 | case 1: | |
1837 | B_SET (&(list->attributes), ATTR_PROTECT); | |
1838 | break; | |
1839 | case 2: | |
1840 | B_SET (&(list->attributes), ATTR_PRIVATE); | |
1841 | break; | |
1842 | } | |
1843 | nfields++; | |
1844 | ||
1845 | ||
1846 | /* Note 1: First, we have to check if the current field is an anonymous | |
1847 | union. If it is, then *its* fields are threaded along in the | |
1848 | nextfield chain. :-( This was supposed to help debuggers, but is | |
1849 | really just a nuisance since we deal with anonymous unions anyway by | |
1850 | checking that the name is null. So anyway, we skip over the fields | |
1851 | of the anonymous union. pai/1997-08-22 */ | |
1852 | /* Note 2: In addition, the bitoffsets for the fields of the anon union | |
1853 | are relative to the enclosing struct, *NOT* relative to the anon | |
1854 | union! This is an even bigger nuisance -- we have to go in and munge | |
1855 | the anon union's type information appropriately. pai/1997-08-22 */ | |
1856 | ||
1857 | /* Both tasks noted above are done by a separate function. This takes us | |
1858 | to the next FIELD or GENFIELD, skipping anon unions, and recursively | |
1859 | processing intermediate types. */ | |
1860 | field = hpread_get_next_skip_over_anon_unions (1, field, &fieldp, objfile); | |
1861 | ||
1862 | } | |
1863 | else | |
1864 | { | |
1865 | /* neither field nor genfield ?? is this possible?? */ | |
1866 | /* pai:: FIXME walk to the next -- how? */ | |
1faa59a8 AC |
1867 | warning ("Internal error: unexpected DNTT kind %d encountered as field of struct", |
1868 | fieldp->dblock.kind); | |
c5aa993b JM |
1869 | warning ("Skipping remaining fields of struct"); |
1870 | break; /* get out of loop of fields */ | |
1871 | } | |
c906108c SS |
1872 | } |
1873 | ||
1874 | /* If it's a template, read in the instantiation list */ | |
c5aa993b JM |
1875 | if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE) |
1876 | { | |
1877 | ninstantiations = 0; | |
1878 | field = dn_bufp->dtemplate.expansions; | |
1879 | while (field.word && field.word != DNTTNIL) | |
1880 | { | |
1881 | fieldp = hpread_get_lntt (field.dnttp.index, objfile); | |
1882 | ||
1883 | /* The expansions or nextexp should point to a tagdef */ | |
1884 | if (fieldp->dblock.kind != DNTT_TYPE_TAGDEF) | |
1885 | break; | |
1886 | ||
1887 | i_new = (struct next_instantiation *) alloca (sizeof (struct next_instantiation)); | |
1888 | i_new->next = i_list; | |
1889 | i_list = i_new; | |
1890 | i_list->t = hpread_type_lookup (field, objfile); | |
1891 | ninstantiations++; | |
1892 | ||
1893 | /* And the "type" field of that should point to a class */ | |
1894 | field = fieldp->dtag.type; | |
1895 | fieldp = hpread_get_lntt (field.dnttp.index, objfile); | |
1896 | if (fieldp->dblock.kind != DNTT_TYPE_CLASS) | |
1897 | break; | |
1898 | ||
1899 | /* Get the next expansion */ | |
1900 | field = fieldp->dclass.nextexp; | |
1901 | } | |
c906108c | 1902 | } |
c5aa993b JM |
1903 | TYPE_NINSTANTIATIONS (type) = ninstantiations; |
1904 | if (ninstantiations > 0) | |
1905 | TYPE_INSTANTIATIONS (type) = (struct type **) | |
c906108c SS |
1906 | obstack_alloc (&objfile->type_obstack, sizeof (struct type *) * ninstantiations); |
1907 | for (n = ninstantiations; i_list; i_list = i_list->next) | |
1908 | { | |
1909 | n -= 1; | |
c5aa993b | 1910 | TYPE_INSTANTIATION (type, n) = i_list->t; |
c906108c SS |
1911 | } |
1912 | ||
1913 | ||
1914 | /* Copy the field-list to GDB's symbol table */ | |
1915 | TYPE_NFIELDS (type) = nfields; | |
1916 | TYPE_N_BASECLASSES (type) = n_base_classes; | |
1917 | TYPE_FIELDS (type) = (struct field *) | |
1918 | obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields); | |
1919 | /* Copy the saved-up fields into the field vector. */ | |
1920 | for (n = nfields, tmp_list = list; tmp_list; tmp_list = tmp_list->next) | |
1921 | { | |
1922 | n -= 1; | |
1923 | TYPE_FIELD (type, n) = tmp_list->field; | |
1924 | } | |
1925 | ||
1926 | /* Copy the "function-field-list" (i.e., the list of member | |
1927 | * functions in the class) to GDB's symbol table | |
1928 | */ | |
1929 | TYPE_NFN_FIELDS (type) = n_fn_fields; | |
1930 | TYPE_NFN_FIELDS_TOTAL (type) = n_fn_fields_total; | |
c5aa993b | 1931 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) |
c906108c SS |
1932 | obstack_alloc (&objfile->type_obstack, sizeof (struct fn_fieldlist) * n_fn_fields); |
1933 | for (n = n_fn_fields; fn_list; fn_list = fn_list->next) | |
1934 | { | |
1935 | n -= 1; | |
c5aa993b | 1936 | TYPE_FN_FIELDLIST (type, n) = fn_list->field; |
c906108c SS |
1937 | } |
1938 | ||
1939 | /* pai:: FIXME -- perhaps each bitvector should be created individually */ | |
1940 | for (n = nfields, tmp_list = list; tmp_list; tmp_list = tmp_list->next) | |
1941 | { | |
1942 | n -= 1; | |
1943 | if (tmp_list->attributes) | |
c5aa993b JM |
1944 | { |
1945 | need_bitvectors = 1; | |
1946 | break; | |
1947 | } | |
c906108c SS |
1948 | } |
1949 | ||
1950 | if (need_bitvectors) | |
1951 | { | |
c5aa993b | 1952 | /* pai:: this step probably redundant */ |
c906108c SS |
1953 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
1954 | ||
1955 | TYPE_FIELD_VIRTUAL_BITS (type) = | |
1956 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
1957 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), nfields); | |
1958 | ||
1959 | TYPE_FIELD_PRIVATE_BITS (type) = | |
1960 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
1961 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
c5aa993b | 1962 | |
c906108c SS |
1963 | TYPE_FIELD_PROTECTED_BITS (type) = |
1964 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
1965 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
1966 | ||
1967 | /* this field vector isn't actually used with HP aCC */ | |
1968 | TYPE_FIELD_IGNORE_BITS (type) = | |
1969 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
1970 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
1971 | ||
1972 | while (nfields-- > 0) | |
c5aa993b JM |
1973 | { |
1974 | if (B_TST (&(list->attributes), ATTR_VIRTUAL)) | |
1975 | SET_TYPE_FIELD_VIRTUAL (type, nfields); | |
1976 | if (B_TST (&(list->attributes), ATTR_PRIVATE)) | |
1977 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
1978 | if (B_TST (&(list->attributes), ATTR_PROTECT)) | |
1979 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
1980 | ||
1981 | list = list->next; | |
1982 | } | |
c906108c SS |
1983 | } |
1984 | else | |
1985 | { | |
c5aa993b JM |
1986 | TYPE_FIELD_VIRTUAL_BITS (type) = NULL; |
1987 | TYPE_FIELD_PROTECTED_BITS (type) = NULL; | |
1988 | TYPE_FIELD_PRIVATE_BITS (type) = NULL; | |
c906108c | 1989 | } |
c5aa993b JM |
1990 | |
1991 | if (has_vtable (type)) | |
c906108c SS |
1992 | { |
1993 | /* Allocate space for class runtime information */ | |
c5aa993b | 1994 | TYPE_RUNTIME_PTR (type) = (struct runtime_info *) xmalloc (sizeof (struct runtime_info)); |
c906108c | 1995 | /* Set flag for vtable */ |
c5aa993b | 1996 | TYPE_VTABLE (type) = 1; |
c906108c | 1997 | /* The first non-virtual base class with a vtable. */ |
c5aa993b | 1998 | TYPE_PRIMARY_BASE (type) = primary_base_class (type); |
c906108c | 1999 | /* The virtual base list. */ |
c5aa993b | 2000 | TYPE_VIRTUAL_BASE_LIST (type) = virtual_base_list (type); |
c906108c SS |
2001 | } |
2002 | else | |
c5aa993b | 2003 | TYPE_RUNTIME_PTR (type) = NULL; |
c906108c SS |
2004 | |
2005 | /* If this is a local type (C++ - declared inside a function), record file name & line # */ | |
c5aa993b | 2006 | if (hpread_get_scope_depth (dn_bufp, objfile, 1 /* no need for real depth */ )) |
c906108c SS |
2007 | { |
2008 | TYPE_LOCALTYPE_PTR (type) = (struct local_type_info *) xmalloc (sizeof (struct local_type_info)); | |
2009 | TYPE_LOCALTYPE_FILE (type) = (char *) xmalloc (strlen (current_subfile->name) + 1); | |
2010 | strcpy (TYPE_LOCALTYPE_FILE (type), current_subfile->name); | |
2011 | if (current_subfile->line_vector && (current_subfile->line_vector->nitems > 0)) | |
c5aa993b | 2012 | TYPE_LOCALTYPE_LINE (type) = current_subfile->line_vector->item[current_subfile->line_vector->nitems - 1].line; |
c906108c | 2013 | else |
c5aa993b | 2014 | TYPE_LOCALTYPE_LINE (type) = 0; |
c906108c SS |
2015 | } |
2016 | else | |
2017 | TYPE_LOCALTYPE_PTR (type) = NULL; | |
2018 | ||
2019 | /* Clear the global saying what template we are in the middle of processing */ | |
2020 | current_template = NULL; | |
2021 | ||
a02fd225 DJ |
2022 | /* Fix up any cv-qualified versions of this type. */ |
2023 | finish_cv_type (type); | |
2024 | ||
c906108c SS |
2025 | return type; |
2026 | } | |
2027 | ||
2028 | /* Adjust the physnames for each static member of a struct | |
2029 | or class type to be something like "A::x"; then various | |
2030 | other pieces of code that do a lookup_symbol on the phyname | |
2031 | work correctly. | |
2032 | TYPE is a pointer to the struct/class type | |
2033 | NAME is a char * (string) which is the class/struct name | |
c5aa993b | 2034 | Void return */ |
c906108c SS |
2035 | |
2036 | static void | |
fba45db2 KB |
2037 | fix_static_member_physnames (struct type *type, char *class_name, |
2038 | struct objfile *objfile) | |
c906108c SS |
2039 | { |
2040 | int i; | |
2041 | ||
c5aa993b | 2042 | /* We fix the member names only for classes or structs */ |
c906108c SS |
2043 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT) |
2044 | return; | |
2045 | ||
c5aa993b | 2046 | for (i = 0; i < TYPE_NFIELDS (type); i++) |
c906108c SS |
2047 | if (TYPE_FIELD_STATIC (type, i)) |
2048 | { | |
c5aa993b JM |
2049 | if (TYPE_FIELD_STATIC_PHYSNAME (type, i)) |
2050 | return; /* physnames are already set */ | |
2051 | ||
2052 | SET_FIELD_PHYSNAME (type->fields[i], | |
2053 | obstack_alloc (&objfile->type_obstack, | |
2054 | strlen (class_name) + strlen (TYPE_FIELD_NAME (type, i)) + 3)); | |
2055 | strcpy (TYPE_FIELD_STATIC_PHYSNAME (type, i), class_name); | |
2056 | strcat (TYPE_FIELD_STATIC_PHYSNAME (type, i), "::"); | |
2057 | strcat (TYPE_FIELD_STATIC_PHYSNAME (type, i), TYPE_FIELD_NAME (type, i)); | |
c906108c SS |
2058 | } |
2059 | } | |
2060 | ||
2061 | /* Fix-up the type structure for a CLASS so that the type entry | |
2062 | * for a method (previously marked with a null type in hpread_read_struct_type() | |
2063 | * is set correctly to METHOD. | |
2064 | * OBJFILE is as for other such functions. | |
c5aa993b JM |
2065 | * Void return. */ |
2066 | ||
c906108c | 2067 | static void |
fba45db2 KB |
2068 | fixup_class_method_type (struct type *class, struct type *method, |
2069 | struct objfile *objfile) | |
c906108c SS |
2070 | { |
2071 | int i, j, k; | |
2072 | ||
2073 | if (!class || !method || !objfile) | |
2074 | return; | |
2075 | ||
2076 | /* Only for types that have methods */ | |
2077 | if ((TYPE_CODE (class) != TYPE_CODE_CLASS) && | |
2078 | (TYPE_CODE (class) != TYPE_CODE_UNION)) | |
2079 | return; | |
2080 | ||
c5aa993b | 2081 | /* Loop over all methods and find the one marked with a NULL type */ |
c906108c SS |
2082 | for (i = 0; i < TYPE_NFN_FIELDS (class); i++) |
2083 | for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (class, i); j++) | |
2084 | if (TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j) == NULL) | |
c5aa993b JM |
2085 | { |
2086 | /* Set the method type */ | |
2087 | TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j) = method; | |
2088 | /* The argument list */ | |
2089 | (TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j))->type_specific.arg_types | |
2090 | = (struct type **) obstack_alloc (&objfile->type_obstack, | |
2091 | sizeof (struct type *) * (method->nfields + 1)); | |
2092 | for (k = 0; k < method->nfields; k++) | |
2093 | (TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j))->type_specific.arg_types[k] = method->fields[k].type; | |
2094 | /* void termination */ | |
2095 | (TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j))->type_specific.arg_types[method->nfields] = builtin_type_void; | |
2096 | ||
2097 | /* pai: It's not clear why this args field has to be set. Perhaps | |
2098 | * it should be eliminated entirely. */ | |
2099 | (TYPE_FN_FIELD (TYPE_FN_FIELDLIST1 (class, i), j)).args | |
2100 | = (struct type **) obstack_alloc (&objfile->type_obstack, | |
2101 | sizeof (struct type *) * (method->nfields + 1)); | |
2102 | for (k = 0; k < method->nfields; k++) | |
2103 | (TYPE_FN_FIELD (TYPE_FN_FIELDLIST1 (class, i), j)).args[k] = method->fields[k].type; | |
2104 | /* null-terminated, unlike arg_types above */ | |
2105 | (TYPE_FN_FIELD (TYPE_FN_FIELDLIST1 (class, i), j)).args[method->nfields] = NULL; | |
2106 | ||
2107 | /* Break out of both loops -- only one method to fix up in a class */ | |
2108 | goto finish; | |
2109 | } | |
c906108c SS |
2110 | |
2111 | finish: | |
c5aa993b | 2112 | TYPE_FLAGS (class) &= ~TYPE_FLAG_INCOMPLETE; |
c906108c SS |
2113 | } |
2114 | ||
2115 | ||
2116 | /* If we're in the middle of processing a template, get a pointer | |
2117 | * to the Nth template argument. | |
2118 | * An example may make this clearer: | |
2119 | * template <class T1, class T2> class q2 { | |
2120 | * public: | |
2121 | * T1 a; | |
2122 | * T2 b; | |
2123 | * }; | |
2124 | * The type for "a" will be "first template arg" and | |
2125 | * the type for "b" will be "second template arg". | |
2126 | * We need to look these up in order to fill in "a" and "b"'s type. | |
2127 | * This is called from hpread_type_lookup(). | |
2128 | */ | |
c5aa993b | 2129 | static struct type * |
fba45db2 | 2130 | hpread_get_nth_template_arg (struct objfile *objfile, int n) |
c906108c | 2131 | { |
c5aa993b JM |
2132 | if (current_template != NULL) |
2133 | return TYPE_TEMPLATE_ARG (current_template, n).type; | |
2134 | else | |
2135 | return lookup_fundamental_type (objfile, FT_TEMPLATE_ARG); | |
c906108c SS |
2136 | } |
2137 | ||
2138 | /* Read in and internalize a TEMPL_ARG (template arg) symbol. */ | |
2139 | ||
2140 | static struct type * | |
fba45db2 KB |
2141 | hpread_read_templ_arg_type (dnttpointer hp_type, union dnttentry *dn_bufp, |
2142 | struct objfile *objfile, char *name) | |
c906108c SS |
2143 | { |
2144 | struct type *type; | |
2145 | ||
2146 | /* See if it's something we've already deal with. */ | |
2147 | type = hpread_alloc_type (hp_type, objfile); | |
2148 | if (TYPE_CODE (type) == TYPE_CODE_TEMPLATE_ARG) | |
2149 | return type; | |
2150 | ||
2151 | /* Nope. Fill in the appropriate fields. */ | |
2152 | TYPE_CODE (type) = TYPE_CODE_TEMPLATE_ARG; | |
2153 | TYPE_LENGTH (type) = 0; | |
2154 | TYPE_NFIELDS (type) = 0; | |
2155 | TYPE_NAME (type) = name; | |
2156 | return type; | |
2157 | } | |
2158 | ||
2159 | /* Read in and internalize a set debug symbol. */ | |
2160 | ||
2161 | static struct type * | |
fba45db2 KB |
2162 | hpread_read_set_type (dnttpointer hp_type, union dnttentry *dn_bufp, |
2163 | struct objfile *objfile) | |
c906108c SS |
2164 | { |
2165 | struct type *type; | |
2166 | ||
2167 | /* See if it's something we've already deal with. */ | |
2168 | type = hpread_alloc_type (hp_type, objfile); | |
2169 | if (TYPE_CODE (type) == TYPE_CODE_SET) | |
2170 | return type; | |
2171 | ||
2172 | /* Nope. Fill in the appropriate fields. */ | |
2173 | TYPE_CODE (type) = TYPE_CODE_SET; | |
2174 | TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8; | |
2175 | TYPE_NFIELDS (type) = 0; | |
2176 | TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype, | |
2177 | objfile); | |
2178 | return type; | |
2179 | } | |
2180 | ||
2181 | /* Read in and internalize an array debug symbol. */ | |
2182 | ||
2183 | static struct type * | |
fba45db2 KB |
2184 | hpread_read_array_type (dnttpointer hp_type, union dnttentry *dn_bufp, |
2185 | struct objfile *objfile) | |
c906108c SS |
2186 | { |
2187 | struct type *type; | |
c5aa993b | 2188 | |
c906108c SS |
2189 | /* Allocate an array type symbol. |
2190 | * Why no check for already-read here, like in the other | |
2191 | * hpread_read_xxx_type routines? Because it kept us | |
2192 | * from properly determining the size of the array! | |
2193 | */ | |
2194 | type = hpread_alloc_type (hp_type, objfile); | |
2195 | ||
2196 | TYPE_CODE (type) = TYPE_CODE_ARRAY; | |
2197 | ||
2198 | /* Although the hp-symtab.h does not *require* this to be the case, | |
2199 | * GDB is assuming that "arrayisbytes" and "elemisbytes" be consistent. | |
2200 | * I.e., express both array-length and element-length in bits, | |
2201 | * or express both array-length and element-length in bytes. | |
2202 | */ | |
2203 | if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes) || | |
c5aa993b JM |
2204 | (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes))) |
2205 | { | |
2206 | warning ("error in hpread_array_type.\n"); | |
1faa59a8 | 2207 | return NULL; |
c5aa993b JM |
2208 | } |
2209 | else if (dn_bufp->darray.arraylength == 0x7fffffff) | |
2210 | { | |
2211 | /* The HP debug format represents char foo[]; as an array with | |
2212 | * length 0x7fffffff. Internally GDB wants to represent this | |
2213 | * as an array of length zero. | |
2214 | */ | |
2215 | TYPE_LENGTH (type) = 0; | |
2216 | } | |
2217 | else if (dn_bufp->darray.arrayisbytes) | |
c906108c | 2218 | TYPE_LENGTH (type) = dn_bufp->darray.arraylength; |
c5aa993b | 2219 | else /* arraylength is in bits */ |
c906108c SS |
2220 | TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8; |
2221 | ||
2222 | TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype, | |
2223 | objfile); | |
2224 | ||
2225 | /* The one "field" is used to store the subscript type */ | |
2226 | /* Since C and C++ multi-dimensional arrays are simply represented | |
2227 | * as: array of array of ..., we only need one subscript-type | |
2228 | * per array. This subscript type is typically a subrange of integer. | |
2229 | * If this gets extended to support languages like Pascal, then | |
2230 | * we need to fix this to represent multi-dimensional arrays properly. | |
2231 | */ | |
2232 | TYPE_NFIELDS (type) = 1; | |
2233 | TYPE_FIELDS (type) = (struct field *) | |
2234 | obstack_alloc (&objfile->type_obstack, sizeof (struct field)); | |
2235 | TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype, | |
2236 | objfile); | |
2237 | return type; | |
2238 | } | |
2239 | ||
2240 | /* Read in and internalize a subrange debug symbol. */ | |
2241 | static struct type * | |
fba45db2 KB |
2242 | hpread_read_subrange_type (dnttpointer hp_type, union dnttentry *dn_bufp, |
2243 | struct objfile *objfile) | |
c906108c SS |
2244 | { |
2245 | struct type *type; | |
2246 | ||
2247 | /* Is it something we've already dealt with. */ | |
2248 | type = hpread_alloc_type (hp_type, objfile); | |
2249 | if (TYPE_CODE (type) == TYPE_CODE_RANGE) | |
2250 | return type; | |
2251 | ||
2252 | /* Nope, internalize it. */ | |
2253 | TYPE_CODE (type) = TYPE_CODE_RANGE; | |
2254 | TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8; | |
2255 | TYPE_NFIELDS (type) = 2; | |
2256 | TYPE_FIELDS (type) | |
2257 | = (struct field *) obstack_alloc (&objfile->type_obstack, | |
2258 | 2 * sizeof (struct field)); | |
2259 | ||
2260 | if (dn_bufp->dsubr.dyn_low) | |
2261 | TYPE_FIELD_BITPOS (type, 0) = 0; | |
2262 | else | |
2263 | TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound; | |
2264 | ||
2265 | if (dn_bufp->dsubr.dyn_high) | |
2266 | TYPE_FIELD_BITPOS (type, 1) = -1; | |
2267 | else | |
2268 | TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound; | |
2269 | TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype, | |
2270 | objfile); | |
2271 | return type; | |
2272 | } | |
2273 | ||
2274 | /* struct type * hpread_type_lookup(hp_type, objfile) | |
2275 | * Arguments: | |
2276 | * hp_type: A pointer into the DNTT specifying what type we | |
2277 | * are about to "look up"., or else [for fundamental types | |
2278 | * like int, float, ...] an "immediate" structure describing | |
2279 | * the type. | |
2280 | * objfile: ? | |
2281 | * Return value: A pointer to a "struct type" (representation of a | |
2282 | * type in GDB's internal symbol table - see gdbtypes.h) | |
2283 | * Routine description: | |
2284 | * There are a variety of places when scanning the DNTT when we | |
2285 | * need to interpret a "type" field. The simplest and most basic | |
2286 | * example is when we're processing the symbol table record | |
2287 | * for a data symbol (a SVAR or DVAR record). That has | |
2288 | * a "type" field specifying the type of the data symbol. That | |
2289 | * "type" field is either an "immediate" type specification (for the | |
2290 | * fundamental types) or a DNTT pointer (for more complicated types). | |
2291 | * For the more complicated types, we may or may not have already | |
2292 | * processed the pointed-to type. (Multiple data symbols can of course | |
2293 | * share the same type). | |
2294 | * The job of hpread_type_lookup() is to process this "type" field. | |
2295 | * Most of the real work is done in subroutines. Here we interpret | |
2296 | * the immediate flag. If not immediate, chase the DNTT pointer to | |
2297 | * find our way to the SOM record describing the type, switch on | |
2298 | * the SOM kind, and then call an appropriate subroutine depending | |
2299 | * on what kind of type we are constructing. (e.g., an array type, | |
2300 | * a struct/class type, etc). | |
2301 | */ | |
2302 | static struct type * | |
fba45db2 | 2303 | hpread_type_lookup (dnttpointer hp_type, struct objfile *objfile) |
c906108c SS |
2304 | { |
2305 | union dnttentry *dn_bufp; | |
c5aa993b | 2306 | struct type *tmp_type; |
c906108c SS |
2307 | |
2308 | /* First see if it's a simple builtin type. */ | |
2309 | if (hp_type.dntti.immediate) | |
1faa59a8 AC |
2310 | { |
2311 | /* If this is a template argument, the argument number is | |
2312 | * encoded in the bitlength. All other cases, just return | |
2313 | * GDB's representation of this fundamental type. | |
2314 | */ | |
2315 | if (hp_type.dntti.type == HP_TYPE_TEMPLATE_ARG) | |
2316 | return hpread_get_nth_template_arg (objfile, hp_type.dntti.bitlength); | |
2317 | else | |
2318 | return lookup_fundamental_type (objfile, | |
2319 | hpread_type_translate (hp_type)); | |
2320 | } | |
c906108c SS |
2321 | |
2322 | /* Not a builtin type. We'll have to read it in. */ | |
2323 | if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile)) | |
2324 | dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile); | |
2325 | else | |
2326 | /* This is a fancy way of returning NULL */ | |
2327 | return lookup_fundamental_type (objfile, FT_VOID); | |
2328 | ||
2329 | switch (dn_bufp->dblock.kind) | |
2330 | { | |
2331 | case DNTT_TYPE_SRCFILE: | |
2332 | case DNTT_TYPE_MODULE: | |
2333 | case DNTT_TYPE_ENTRY: | |
2334 | case DNTT_TYPE_BEGIN: | |
2335 | case DNTT_TYPE_END: | |
2336 | case DNTT_TYPE_IMPORT: | |
2337 | case DNTT_TYPE_LABEL: | |
2338 | case DNTT_TYPE_FPARAM: | |
2339 | case DNTT_TYPE_SVAR: | |
2340 | case DNTT_TYPE_DVAR: | |
2341 | case DNTT_TYPE_CONST: | |
2342 | case DNTT_TYPE_MEMENUM: | |
2343 | case DNTT_TYPE_VARIANT: | |
2344 | case DNTT_TYPE_FILE: | |
2345 | case DNTT_TYPE_WITH: | |
2346 | case DNTT_TYPE_COMMON: | |
2347 | case DNTT_TYPE_COBSTRUCT: | |
2348 | case DNTT_TYPE_XREF: | |
2349 | case DNTT_TYPE_SA: | |
2350 | case DNTT_TYPE_MACRO: | |
2351 | case DNTT_TYPE_BLOCKDATA: | |
2352 | case DNTT_TYPE_CLASS_SCOPE: | |
2353 | case DNTT_TYPE_MEMACCESS: | |
2354 | case DNTT_TYPE_INHERITANCE: | |
2355 | case DNTT_TYPE_OBJECT_ID: | |
2356 | case DNTT_TYPE_FRIEND_CLASS: | |
2357 | case DNTT_TYPE_FRIEND_FUNC: | |
2358 | /* These are not types - something went wrong. */ | |
2359 | /* This is a fancy way of returning NULL */ | |
2360 | return lookup_fundamental_type (objfile, FT_VOID); | |
2361 | ||
2362 | case DNTT_TYPE_FUNCTION: | |
2363 | /* We wind up here when dealing with class member functions | |
2364 | * (called from hpread_read_struct_type(), i.e. when processing | |
2365 | * the class definition itself). | |
2366 | */ | |
2367 | return hpread_read_function_type (hp_type, dn_bufp, objfile, 0); | |
2368 | ||
2369 | case DNTT_TYPE_DOC_FUNCTION: | |
2370 | return hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 0); | |
2371 | ||
2372 | case DNTT_TYPE_TYPEDEF: | |
2373 | { | |
c5aa993b | 2374 | /* A typedef - chase it down by making a recursive call */ |
c906108c SS |
2375 | struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type, |
2376 | objfile); | |
2377 | ||
c5aa993b JM |
2378 | /* The following came from the base hpread.c that we inherited. |
2379 | * It is WRONG so I have commented it out. - RT | |
2380 | *... | |
2381 | ||
2382 | char *suffix; | |
2383 | suffix = VT (objfile) + dn_bufp->dtype.name; | |
2384 | TYPE_NAME (structtype) = suffix; | |
2385 | ||
2386 | * ... further explanation .... | |
2387 | * | |
2388 | * What we have here is a typedef pointing to a typedef. | |
2389 | * E.g., | |
2390 | * typedef int foo; | |
2391 | * typedef foo fum; | |
2392 | * | |
2393 | * What we desire to build is (these are pictures | |
2394 | * of "struct type"'s): | |
2395 | * | |
2396 | * +---------+ +----------+ +------------+ | |
2397 | * | typedef | | typedef | | fund. type | | |
2398 | * | type| -> | type| -> | | | |
2399 | * | "fum" | | "foo" | | "int" | | |
2400 | * +---------+ +----------+ +------------+ | |
2401 | * | |
2402 | * What this commented-out code is doing is smashing the | |
2403 | * name of pointed-to-type to be the same as the pointed-from | |
2404 | * type. So we wind up with something like: | |
2405 | * | |
2406 | * +---------+ +----------+ +------------+ | |
2407 | * | typedef | | typedef | | fund. type | | |
2408 | * | type| -> | type| -> | | | |
2409 | * | "fum" | | "fum" | | "fum" | | |
2410 | * +---------+ +----------+ +------------+ | |
2411 | * | |
2412 | */ | |
c906108c SS |
2413 | |
2414 | return structtype; | |
2415 | } | |
2416 | ||
2417 | case DNTT_TYPE_TAGDEF: | |
c5aa993b | 2418 | { |
c906108c SS |
2419 | /* Just a little different from above. We have to tack on |
2420 | * an identifier of some kind (struct, union, enum, class, etc). | |
c5aa993b | 2421 | */ |
c906108c SS |
2422 | struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type, |
2423 | objfile); | |
2424 | char *prefix, *suffix; | |
2425 | suffix = VT (objfile) + dn_bufp->dtype.name; | |
2426 | ||
2427 | /* Lookup the next type in the list. It should be a structure, | |
2428 | * union, class, enum, or template type. | |
c5aa993b JM |
2429 | * We will need to attach that to our name. |
2430 | */ | |
c906108c SS |
2431 | if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile)) |
2432 | dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile); | |
c5aa993b JM |
2433 | else |
2434 | { | |
2435 | complain (&hpread_type_lookup_complaint); | |
1faa59a8 | 2436 | return NULL; |
c5aa993b JM |
2437 | } |
2438 | ||
2439 | if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT) | |
2440 | { | |
c906108c | 2441 | prefix = "struct "; |
c5aa993b JM |
2442 | } |
2443 | else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION) | |
2444 | { | |
2445 | prefix = "union "; | |
2446 | } | |
2447 | else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS) | |
2448 | { | |
2449 | /* Further field for CLASS saying how it was really declared */ | |
2450 | /* 0==class, 1==union, 2==struct */ | |
2451 | if (dn_bufp->dclass.class_decl == 0) | |
2452 | prefix = "class "; | |
2453 | else if (dn_bufp->dclass.class_decl == 1) | |
2454 | prefix = "union "; | |
2455 | else if (dn_bufp->dclass.class_decl == 2) | |
2456 | prefix = "struct "; | |
2457 | else | |
2458 | prefix = ""; | |
2459 | } | |
2460 | else if (dn_bufp->dblock.kind == DNTT_TYPE_ENUM) | |
2461 | { | |
2462 | prefix = "enum "; | |
2463 | } | |
2464 | else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE) | |
2465 | { | |
2466 | prefix = "template "; | |
2467 | } | |
2468 | else | |
2469 | { | |
2470 | prefix = ""; | |
2471 | } | |
c906108c SS |
2472 | |
2473 | /* Build the correct name. */ | |
2474 | structtype->name | |
2475 | = (char *) obstack_alloc (&objfile->type_obstack, | |
2476 | strlen (prefix) + strlen (suffix) + 1); | |
2477 | TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix); | |
2478 | TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix); | |
2479 | TYPE_TAG_NAME (structtype) = suffix; | |
2480 | ||
c5aa993b JM |
2481 | /* For classes/structs, we have to set the static member "physnames" |
2482 | to point to strings like "Class::Member" */ | |
2483 | if (TYPE_CODE (structtype) == TYPE_CODE_STRUCT) | |
2484 | fix_static_member_physnames (structtype, suffix, objfile); | |
c906108c SS |
2485 | |
2486 | return structtype; | |
2487 | } | |
2488 | ||
2489 | case DNTT_TYPE_POINTER: | |
2490 | /* Pointer type - call a routine in gdbtypes.c that constructs | |
2491 | * the appropriate GDB type. | |
2492 | */ | |
2493 | return make_pointer_type ( | |
c5aa993b JM |
2494 | hpread_type_lookup (dn_bufp->dptr.pointsto, |
2495 | objfile), | |
2496 | NULL); | |
c906108c SS |
2497 | |
2498 | case DNTT_TYPE_REFERENCE: | |
2499 | /* C++ reference type - call a routine in gdbtypes.c that constructs | |
2500 | * the appropriate GDB type. | |
2501 | */ | |
2502 | return make_reference_type ( | |
c5aa993b JM |
2503 | hpread_type_lookup (dn_bufp->dreference.pointsto, |
2504 | objfile), | |
2505 | NULL); | |
2506 | ||
c906108c SS |
2507 | case DNTT_TYPE_ENUM: |
2508 | return hpread_read_enum_type (hp_type, dn_bufp, objfile); | |
2509 | case DNTT_TYPE_SET: | |
2510 | return hpread_read_set_type (hp_type, dn_bufp, objfile); | |
2511 | case DNTT_TYPE_SUBRANGE: | |
2512 | return hpread_read_subrange_type (hp_type, dn_bufp, objfile); | |
2513 | case DNTT_TYPE_ARRAY: | |
2514 | return hpread_read_array_type (hp_type, dn_bufp, objfile); | |
2515 | case DNTT_TYPE_STRUCT: | |
2516 | case DNTT_TYPE_UNION: | |
2517 | return hpread_read_struct_type (hp_type, dn_bufp, objfile); | |
2518 | case DNTT_TYPE_FIELD: | |
2519 | return hpread_type_lookup (dn_bufp->dfield.type, objfile); | |
2520 | ||
2521 | case DNTT_TYPE_FUNCTYPE: | |
2522 | /* Here we want to read the function SOMs and return a | |
2523 | * type for it. We get here, for instance, when processing | |
2524 | * pointer-to-function type. | |
2525 | */ | |
2526 | return hpread_read_function_type (hp_type, dn_bufp, objfile, 0); | |
2527 | ||
2528 | case DNTT_TYPE_PTRMEM: | |
2529 | /* Declares a C++ pointer-to-data-member type. | |
2530 | * The "pointsto" field defines the class, | |
2531 | * while the "memtype" field defines the pointed-to-type. | |
2532 | */ | |
2533 | { | |
c5aa993b JM |
2534 | struct type *ptrmemtype; |
2535 | struct type *class_type; | |
2536 | struct type *memtype; | |
2537 | memtype = hpread_type_lookup (dn_bufp->dptrmem.memtype, | |
2538 | objfile), | |
2539 | class_type = hpread_type_lookup (dn_bufp->dptrmem.pointsto, | |
2540 | objfile), | |
2541 | ptrmemtype = alloc_type (objfile); | |
2542 | smash_to_member_type (ptrmemtype, class_type, memtype); | |
2543 | return make_pointer_type (ptrmemtype, NULL); | |
c906108c SS |
2544 | } |
2545 | break; | |
2546 | ||
2547 | case DNTT_TYPE_PTRMEMFUNC: | |
2548 | /* Defines a C++ pointer-to-function-member type. | |
2549 | * The "pointsto" field defines the class, | |
2550 | * while the "memtype" field defines the pointed-to-type. | |
2551 | */ | |
2552 | { | |
c5aa993b JM |
2553 | struct type *ptrmemtype; |
2554 | struct type *class_type; | |
2555 | struct type *functype; | |
2556 | struct type *retvaltype; | |
2557 | int nargs; | |
2558 | int i; | |
2559 | struct type **args_type; | |
2560 | class_type = hpread_type_lookup (dn_bufp->dptrmem.pointsto, | |
2561 | objfile); | |
2562 | functype = hpread_type_lookup (dn_bufp->dptrmem.memtype, | |
2563 | objfile); | |
2564 | retvaltype = TYPE_TARGET_TYPE (functype); | |
2565 | nargs = TYPE_NFIELDS (functype); | |
2566 | args_type = (struct type **) xmalloc ((nargs + 1) * sizeof (struct type *)); | |
2567 | for (i = 0; i < nargs; i++) | |
2568 | { | |
2569 | args_type[i] = TYPE_FIELD_TYPE (functype, i); | |
2570 | } | |
2571 | args_type[nargs] = NULL; | |
2572 | ptrmemtype = alloc_type (objfile); | |
2573 | smash_to_method_type (ptrmemtype, class_type, retvaltype, args_type); | |
2574 | return make_pointer_type (ptrmemtype, NULL); | |
c906108c SS |
2575 | } |
2576 | break; | |
2577 | ||
c5aa993b | 2578 | case DNTT_TYPE_CLASS: |
c906108c SS |
2579 | return hpread_read_struct_type (hp_type, dn_bufp, objfile); |
2580 | ||
2581 | case DNTT_TYPE_GENFIELD: | |
2582 | /* Chase pointer from GENFIELD to FIELD, and make recursive | |
2583 | * call on that. | |
2584 | */ | |
2585 | return hpread_type_lookup (dn_bufp->dgenfield.field, objfile); | |
2586 | ||
2587 | case DNTT_TYPE_VFUNC: | |
2588 | /* C++ virtual function. | |
2589 | * We get here in the course of processing a class type which | |
2590 | * contains virtual functions. Just go through another level | |
2591 | * of indirection to get to the pointed-to function SOM. | |
2592 | */ | |
2593 | return hpread_type_lookup (dn_bufp->dvfunc.funcptr, objfile); | |
2594 | ||
2595 | case DNTT_TYPE_MODIFIER: | |
2596 | /* Check the modifiers and then just make a recursive call on | |
2597 | * the "type" pointed to by the modifier DNTT. | |
2598 | * | |
2599 | * pai:: FIXME -- do we ever want to handle "m_duplicate" and | |
2600 | * "m_void" modifiers? Is static_flag really needed here? | |
2601 | * (m_static used for methods of classes, elsewhere). | |
2602 | */ | |
c5aa993b JM |
2603 | tmp_type = make_cv_type (dn_bufp->dmodifier.m_const, |
2604 | dn_bufp->dmodifier.m_volatile, | |
2605 | hpread_type_lookup (dn_bufp->dmodifier.type, objfile), | |
2606 | 0); | |
c906108c | 2607 | return tmp_type; |
c5aa993b | 2608 | |
c906108c SS |
2609 | |
2610 | case DNTT_TYPE_MEMFUNC: | |
2611 | /* Member function. Treat like a function. | |
2612 | * I think we get here in the course of processing a | |
2613 | * pointer-to-member-function type... | |
2614 | */ | |
2615 | return hpread_read_function_type (hp_type, dn_bufp, objfile, 0); | |
2616 | ||
2617 | case DNTT_TYPE_DOC_MEMFUNC: | |
2618 | return hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 0); | |
2619 | ||
2620 | case DNTT_TYPE_TEMPLATE: | |
2621 | /* Template - sort of the header for a template definition, | |
2622 | * which like a class, points to a member list and also points | |
2623 | * to a TEMPLATE_ARG list of type-arguments. | |
2624 | */ | |
2625 | return hpread_read_struct_type (hp_type, dn_bufp, objfile); | |
2626 | ||
2627 | case DNTT_TYPE_TEMPLATE_ARG: | |
2628 | { | |
c5aa993b JM |
2629 | char *name; |
2630 | /* The TEMPLATE record points to an argument list of | |
2631 | * TEMPLATE_ARG records, each of which describes one | |
2632 | * of the type-arguments. | |
2633 | */ | |
2634 | name = VT (objfile) + dn_bufp->dtempl_arg.name; | |
2635 | return hpread_read_templ_arg_type (hp_type, dn_bufp, objfile, name); | |
c906108c SS |
2636 | } |
2637 | ||
2638 | case DNTT_TYPE_FUNC_TEMPLATE: | |
2639 | /* We wind up here when processing a TEMPLATE type, | |
2640 | * if the template has member function(s). | |
2641 | * Treat it like a FUNCTION. | |
2642 | */ | |
2643 | return hpread_read_function_type (hp_type, dn_bufp, objfile, 0); | |
2644 | ||
2645 | case DNTT_TYPE_LINK: | |
2646 | /* The LINK record is used to link up templates with instantiations. | |
2647 | * There is no type associated with the LINK record per se. | |
2648 | */ | |
2649 | return lookup_fundamental_type (objfile, FT_VOID); | |
2650 | ||
c5aa993b JM |
2651 | /* Also not yet handled... */ |
2652 | /* case DNTT_TYPE_DYN_ARRAY_DESC: */ | |
2653 | /* case DNTT_TYPE_DESC_SUBRANGE: */ | |
2654 | /* case DNTT_TYPE_BEGIN_EXT: */ | |
2655 | /* case DNTT_TYPE_INLN: */ | |
2656 | /* case DNTT_TYPE_INLN_LIST: */ | |
2657 | /* case DNTT_TYPE_ALIAS: */ | |
c906108c SS |
2658 | default: |
2659 | /* A fancy way of returning NULL */ | |
2660 | return lookup_fundamental_type (objfile, FT_VOID); | |
2661 | } | |
2662 | } | |
2663 | ||
2664 | static sltpointer | |
fba45db2 KB |
2665 | hpread_record_lines (struct subfile *subfile, sltpointer s_idx, |
2666 | sltpointer e_idx, struct objfile *objfile, | |
2667 | CORE_ADDR offset) | |
c906108c SS |
2668 | { |
2669 | union sltentry *sl_bufp; | |
2670 | ||
2671 | while (s_idx <= e_idx) | |
2672 | { | |
2673 | sl_bufp = hpread_get_slt (s_idx, objfile); | |
2674 | /* Only record "normal" entries in the SLT. */ | |
2675 | if (sl_bufp->snorm.sltdesc == SLT_NORMAL | |
2676 | || sl_bufp->snorm.sltdesc == SLT_EXIT) | |
2677 | record_line (subfile, sl_bufp->snorm.line, | |
2678 | sl_bufp->snorm.address + offset); | |
2679 | else if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET) | |
2680 | record_line (subfile, sl_bufp->snormoff.line, | |
2681 | sl_bufp->snormoff.address + offset); | |
2682 | s_idx++; | |
2683 | } | |
2684 | return e_idx; | |
2685 | } | |
2686 | ||
2687 | /* Given a function "f" which is a member of a class, find | |
2688 | * the classname that it is a member of. Used to construct | |
2689 | * the name (e.g., "c::f") which GDB will put in the | |
2690 | * "demangled name" field of the function's symbol. | |
2691 | * Called from hpread_process_one_debug_symbol() | |
2692 | * If "f" is not a member function, return NULL. | |
2693 | */ | |
c5aa993b | 2694 | char * |
fba45db2 | 2695 | class_of (struct type *functype) |
c906108c | 2696 | { |
c5aa993b JM |
2697 | struct type *first_param_type; |
2698 | char *first_param_name; | |
2699 | struct type *pointed_to_type; | |
2700 | char *class_name; | |
c906108c SS |
2701 | |
2702 | /* Check that the function has a first argument "this", | |
2703 | * and that "this" is a pointer to a class. If not, | |
2704 | * functype is not a member function, so return NULL. | |
2705 | */ | |
c5aa993b | 2706 | if (TYPE_NFIELDS (functype) == 0) |
c906108c SS |
2707 | return NULL; |
2708 | first_param_name = TYPE_FIELD_NAME (functype, 0); | |
2709 | if (first_param_name == NULL) | |
c5aa993b JM |
2710 | return NULL; /* paranoia */ |
2711 | if (strcmp (first_param_name, "this")) | |
c906108c SS |
2712 | return NULL; |
2713 | first_param_type = TYPE_FIELD_TYPE (functype, 0); | |
2714 | if (first_param_type == NULL) | |
c5aa993b JM |
2715 | return NULL; /* paranoia */ |
2716 | if (TYPE_CODE (first_param_type) != TYPE_CODE_PTR) | |
c906108c SS |
2717 | return NULL; |
2718 | ||
2719 | /* Get the thing that "this" points to, check that | |
2720 | * it's a class, and get its class name. | |
2721 | */ | |
c5aa993b JM |
2722 | pointed_to_type = TYPE_TARGET_TYPE (first_param_type); |
2723 | if (pointed_to_type == NULL) | |
2724 | return NULL; /* paranoia */ | |
2725 | if (TYPE_CODE (pointed_to_type) != TYPE_CODE_CLASS) | |
c906108c | 2726 | return NULL; |
c5aa993b | 2727 | class_name = TYPE_NAME (pointed_to_type); |
c906108c | 2728 | if (class_name == NULL) |
c5aa993b | 2729 | return NULL; /* paranoia */ |
c906108c SS |
2730 | |
2731 | /* The class name may be of the form "class c", in which case | |
2732 | * we want to strip off the leading "class ". | |
2733 | */ | |
c5aa993b | 2734 | if (strncmp (class_name, "class ", 6) == 0) |
c906108c SS |
2735 | class_name += 6; |
2736 | ||
2737 | return class_name; | |
2738 | } | |
2739 | ||
2740 | /* Internalize one native debug symbol. | |
2741 | * Called in a loop from hpread_expand_symtab(). | |
2742 | * Arguments: | |
2743 | * dn_bufp: | |
2744 | * name: | |
2745 | * section_offsets: | |
2746 | * objfile: | |
2747 | * text_offset: | |
2748 | * text_size: | |
2749 | * filename: | |
c5aa993b | 2750 | * index: Index of this symbol |
c906108c SS |
2751 | * at_module_boundary_p Pointer to boolean flag to control caller's loop. |
2752 | */ | |
2753 | ||
2754 | static void | |
fba45db2 KB |
2755 | hpread_process_one_debug_symbol (union dnttentry *dn_bufp, char *name, |
2756 | struct section_offsets *section_offsets, | |
2757 | struct objfile *objfile, CORE_ADDR text_offset, | |
2758 | int text_size, char *filename, int index, | |
2759 | int *at_module_boundary_p) | |
c906108c SS |
2760 | { |
2761 | unsigned long desc; | |
2762 | int type; | |
2763 | CORE_ADDR valu; | |
b8fbeb18 EZ |
2764 | int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); |
2765 | int data_offset = ANOFFSET (section_offsets, SECT_OFF_DATA (objfile)); | |
c906108c SS |
2766 | union dnttentry *dn_temp; |
2767 | dnttpointer hp_type; | |
2768 | struct symbol *sym; | |
2769 | struct context_stack *new; | |
c5aa993b | 2770 | char *class_scope_name; |
c5aa993b | 2771 | |
c906108c SS |
2772 | /* Allocate one GDB debug symbol and fill in some default values. */ |
2773 | sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack, | |
2774 | sizeof (struct symbol)); | |
2775 | memset (sym, 0, sizeof (struct symbol)); | |
2776 | SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->symbol_obstack); | |
2777 | SYMBOL_LANGUAGE (sym) = language_auto; | |
2778 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
2779 | SYMBOL_LINE (sym) = 0; | |
2780 | SYMBOL_VALUE (sym) = 0; | |
2781 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
2782 | ||
2783 | /* Just a trick in case the SOM debug symbol is a type definition. | |
2784 | * There are routines that are set up to build a GDB type symbol, given | |
2785 | * a SOM dnttpointer. So we set up a dummy SOM dnttpointer "hp_type". | |
2786 | * This allows us to call those same routines. | |
2787 | */ | |
2788 | hp_type.dnttp.extension = 1; | |
2789 | hp_type.dnttp.immediate = 0; | |
2790 | hp_type.dnttp.global = 0; | |
2791 | hp_type.dnttp.index = index; | |
2792 | ||
2793 | /* This "type" is the type of SOM record. | |
2794 | * Switch on SOM type. | |
2795 | */ | |
2796 | type = dn_bufp->dblock.kind; | |
2797 | switch (type) | |
2798 | { | |
2799 | case DNTT_TYPE_SRCFILE: | |
2800 | /* This type of symbol indicates from which source file or | |
2801 | * include file any following data comes. It may indicate: | |
2802 | * | |
2803 | * o The start of an entirely new source file (and thus | |
2804 | * a new module) | |
2805 | * | |
2806 | * o The start of a different source file due to #include | |
2807 | * | |
2808 | * o The end of an include file and the return to the original | |
2809 | * file. Thus if "foo.c" includes "bar.h", we see first | |
2810 | * a SRCFILE for foo.c, then one for bar.h, and then one for | |
2811 | * foo.c again. | |
2812 | * | |
2813 | * If it indicates the start of a new module then we must | |
2814 | * finish the symbol table of the previous module | |
2815 | * (if any) and start accumulating a new symbol table. | |
2816 | */ | |
2817 | ||
2818 | valu = text_offset; | |
c5aa993b JM |
2819 | if (!last_source_file) |
2820 | { | |
2821 | /* | |
2822 | * A note on "last_source_file": this is a char* pointing | |
2823 | * to the actual file name. "start_symtab" sets it, | |
2824 | * "end_symtab" clears it. | |
2825 | * | |
2826 | * So if "last_source_file" is NULL, then either this is | |
2827 | * the first record we are looking at, or a previous call | |
2828 | * to "end_symtab()" was made to close out the previous | |
2829 | * module. Since we're now quitting the scan loop when we | |
2830 | * see a MODULE END record, we should never get here, except | |
2831 | * in the case that we're not using the quick look-up tables | |
2832 | * and have to use the old system as a fall-back. | |
2833 | */ | |
c906108c SS |
2834 | start_symtab (name, NULL, valu); |
2835 | record_debugformat ("HP"); | |
2836 | SL_INDEX (objfile) = dn_bufp->dsfile.address; | |
c5aa993b | 2837 | } |
c906108c | 2838 | |
c5aa993b JM |
2839 | else |
2840 | { | |
2841 | /* Either a new include file, or a SRCFILE record | |
2842 | * saying we are back in the main source (or out of | |
2843 | * a nested include file) again. | |
2844 | */ | |
c906108c SS |
2845 | SL_INDEX (objfile) = hpread_record_lines (current_subfile, |
2846 | SL_INDEX (objfile), | |
2847 | dn_bufp->dsfile.address, | |
2848 | objfile, offset); | |
c5aa993b | 2849 | } |
c906108c SS |
2850 | |
2851 | /* A note on "start_subfile". This routine will check | |
2852 | * the name we pass it and look for an existing subfile | |
2853 | * of that name. There's thus only one sub-file for the | |
2854 | * actual source (e.g. for "foo.c" in foo.c), despite the | |
2855 | * fact that we'll see lots of SRCFILE entries for foo.c | |
2856 | * inside foo.c. | |
2857 | */ | |
2858 | start_subfile (name, NULL); | |
2859 | break; | |
c5aa993b | 2860 | |
c906108c SS |
2861 | case DNTT_TYPE_MODULE: |
2862 | /* | |
2863 | * We no longer ignore DNTT_TYPE_MODULE symbols. The module | |
2864 | * represents the meaningful semantic structure of a compilation | |
2865 | * unit. We expect to start the psymtab-to-symtab expansion | |
2866 | * looking at a MODULE entry, and to end it at the corresponding | |
2867 | * END MODULE entry. | |
2868 | * | |
2869 | *--Begin outdated comments | |
2870 | * | |
2871 | * This record signifies the start of a new source module | |
2872 | * In C/C++ there is no explicit "module" construct in the language, | |
2873 | * but each compilation unit is implicitly a module and they | |
2874 | * do emit the DNTT_TYPE_MODULE records. | |
2875 | * The end of the module is marked by a matching DNTT_TYPE_END record. | |
2876 | * | |
2877 | * The reason GDB gets away with ignoring the DNTT_TYPE_MODULE record | |
2878 | * is it notices the DNTT_TYPE_END record for the previous | |
2879 | * module (see comments under DNTT_TYPE_END case), and then treats | |
2880 | * the next DNTT_TYPE_SRCFILE record as if it were the module-start record. | |
2881 | * (i.e., it makes a start_symtab() call). | |
2882 | * This scheme seems a little convoluted, but I'll leave it | |
2883 | * alone on the principle "if it ain't broke don't fix | |
2884 | * it". (RT). | |
2885 | * | |
2886 | *-- End outdated comments | |
2887 | */ | |
2888 | ||
2889 | valu = text_offset; | |
c5aa993b | 2890 | if (!last_source_file) |
c906108c | 2891 | { |
c5aa993b JM |
2892 | /* Start of a new module. We know this because "last_source_file" |
2893 | * is NULL, which can only happen the first time or if we just | |
2894 | * made a call to end_symtab() to close out the previous module. | |
2895 | */ | |
c906108c SS |
2896 | start_symtab (name, NULL, valu); |
2897 | SL_INDEX (objfile) = dn_bufp->dmodule.address; | |
2898 | } | |
2899 | else | |
2900 | { | |
c5aa993b JM |
2901 | /* This really shouldn't happen if we're using the quick |
2902 | * look-up tables, as it would mean we'd scanned past an | |
2903 | * END MODULE entry. But if we're not using the tables, | |
2904 | * we started the module on the SRCFILE entry, so it's ok. | |
2905 | * For now, accept this. | |
2906 | */ | |
2907 | /* warning( "Error expanding psymtab, missed module end, found entry for %s", | |
2908 | * name ); | |
2909 | */ | |
2910 | *at_module_boundary_p = -1; | |
c906108c SS |
2911 | } |
2912 | ||
2913 | start_subfile (name, NULL); | |
2914 | break; | |
2915 | ||
2916 | case DNTT_TYPE_FUNCTION: | |
2917 | case DNTT_TYPE_ENTRY: | |
2918 | /* A function or secondary entry point. */ | |
2919 | valu = dn_bufp->dfunc.lowaddr + offset; | |
2920 | ||
2921 | /* Record lines up to this point. */ | |
2922 | SL_INDEX (objfile) = hpread_record_lines (current_subfile, | |
2923 | SL_INDEX (objfile), | |
2924 | dn_bufp->dfunc.address, | |
2925 | objfile, offset); | |
c5aa993b | 2926 | |
c906108c SS |
2927 | WITHIN_FUNCTION (objfile) = 1; |
2928 | CURRENT_FUNCTION_VALUE (objfile) = valu; | |
2929 | ||
2930 | /* Stack must be empty now. */ | |
2931 | if (context_stack_depth != 0) | |
2932 | complain (&lbrac_unmatched_complaint, (char *) symnum); | |
2933 | new = push_context (0, valu); | |
2934 | ||
2935 | /* Built a type for the function. This includes processing | |
2936 | * the symbol records for the function parameters. | |
2937 | */ | |
2938 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
2939 | SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile, 1); | |
2940 | ||
2941 | /* The "SYMBOL_NAME" field is expected to be the mangled name | |
2942 | * (if any), which we get from the "alias" field of the SOM record | |
2943 | * if that exists. | |
2944 | */ | |
c5aa993b JM |
2945 | if ((dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) && |
2946 | dn_bufp->dfunc.alias && /* has an alias */ | |
2947 | *(char *) (VT (objfile) + dn_bufp->dfunc.alias)) /* not a null string */ | |
2948 | SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.alias; | |
c906108c | 2949 | else |
c5aa993b | 2950 | SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.name; |
c906108c SS |
2951 | |
2952 | /* Special hack to get around HP compilers' insistence on | |
2953 | * reporting "main" as "_MAIN_" for C/C++ */ | |
2954 | if ((strcmp (SYMBOL_NAME (sym), "_MAIN_") == 0) && | |
c5aa993b JM |
2955 | (strcmp (VT (objfile) + dn_bufp->dfunc.name, "main") == 0)) |
2956 | SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.name; | |
2957 | ||
c906108c SS |
2958 | /* The SYMBOL_CPLUS_DEMANGLED_NAME field is expected to |
2959 | * be the demangled name. | |
2960 | */ | |
2961 | if (dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) | |
2962 | { | |
c5aa993b JM |
2963 | /* SYMBOL_INIT_DEMANGLED_NAME is a macro which winds up |
2964 | * calling the demangler in libiberty (cplus_demangle()) to | |
2965 | * do the job. This generally does the job, even though | |
2966 | * it's intended for the GNU compiler and not the aCC compiler | |
2967 | * Note that SYMBOL_INIT_DEMANGLED_NAME calls the | |
2968 | * demangler with arguments DMGL_PARAMS | DMGL_ANSI. | |
2969 | * Generally, we don't want params when we display | |
2970 | * a demangled name, but when I took out the DMGL_PARAMS, | |
2971 | * some things broke, so I'm leaving it in here, and | |
2972 | * working around the issue in stack.c. - RT | |
2973 | */ | |
2974 | SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack); | |
2975 | if ((SYMBOL_NAME (sym) == VT (objfile) + dn_bufp->dfunc.alias) && | |
2976 | (!SYMBOL_CPLUS_DEMANGLED_NAME (sym))) | |
2977 | { | |
2978 | ||
2979 | /* Well, the symbol name is mangled, but the | |
2980 | * demangler in libiberty failed so the demangled | |
2981 | * field is still NULL. Try to | |
2982 | * do the job ourselves based on the "name" field | |
2983 | * in the SOM record. A complication here is that | |
2984 | * the name field contains only the function name | |
2985 | * (like "f"), whereas we want the class qualification | |
2986 | * (as in "c::f"). Try to reconstruct that. | |
2987 | */ | |
2988 | char *basename; | |
2989 | char *classname; | |
2990 | char *dem_name; | |
2991 | basename = VT (objfile) + dn_bufp->dfunc.name; | |
2992 | classname = class_of (SYMBOL_TYPE (sym)); | |
2993 | if (classname) | |
2994 | { | |
2995 | dem_name = xmalloc (strlen (basename) + strlen (classname) + 3); | |
2996 | strcpy (dem_name, classname); | |
2997 | strcat (dem_name, "::"); | |
2998 | strcat (dem_name, basename); | |
2999 | SYMBOL_CPLUS_DEMANGLED_NAME (sym) = dem_name; | |
3000 | SYMBOL_LANGUAGE (sym) = language_cplus; | |
3001 | } | |
3002 | } | |
3003 | } | |
3004 | ||
c906108c SS |
3005 | /* Add the function symbol to the list of symbols in this blockvector */ |
3006 | if (dn_bufp->dfunc.global) | |
3007 | add_symbol_to_list (sym, &global_symbols); | |
3008 | else | |
3009 | add_symbol_to_list (sym, &file_symbols); | |
3010 | new->name = sym; | |
3011 | ||
3012 | /* Search forward to the next BEGIN and also read | |
3013 | * in the line info up to that point. | |
3014 | * Not sure why this is needed. | |
3015 | * In HP FORTRAN this code is harmful since there | |
3016 | * may not be a BEGIN after the FUNCTION. | |
3017 | * So I made it C/C++ specific. - RT | |
3018 | */ | |
3019 | if (dn_bufp->dfunc.language == HP_LANGUAGE_C || | |
c5aa993b JM |
3020 | dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) |
3021 | { | |
3022 | while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN) | |
3023 | { | |
3024 | dn_bufp = hpread_get_lntt (++index, objfile); | |
3025 | if (dn_bufp->dblock.extension) | |
3026 | continue; | |
3027 | } | |
3028 | SL_INDEX (objfile) = hpread_record_lines (current_subfile, | |
3029 | SL_INDEX (objfile), | |
3030 | dn_bufp->dbegin.address, | |
3031 | objfile, offset); | |
3032 | SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile); | |
3033 | } | |
c906108c SS |
3034 | record_line (current_subfile, SYMBOL_LINE (sym), valu); |
3035 | break; | |
3036 | ||
3037 | case DNTT_TYPE_DOC_FUNCTION: | |
3038 | valu = dn_bufp->ddocfunc.lowaddr + offset; | |
3039 | ||
3040 | /* Record lines up to this point. */ | |
3041 | SL_INDEX (objfile) = hpread_record_lines (current_subfile, | |
3042 | SL_INDEX (objfile), | |
3043 | dn_bufp->ddocfunc.address, | |
3044 | objfile, offset); | |
c5aa993b | 3045 | |
c906108c SS |
3046 | WITHIN_FUNCTION (objfile) = 1; |
3047 | CURRENT_FUNCTION_VALUE (objfile) = valu; | |
3048 | /* Stack must be empty now. */ | |
3049 | if (context_stack_depth != 0) | |
3050 | complain (&lbrac_unmatched_complaint, (char *) symnum); | |
3051 | new = push_context (0, valu); | |
3052 | ||
3053 | /* Built a type for the function. This includes processing | |
3054 | * the symbol records for the function parameters. | |
3055 | */ | |
3056 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
3057 | SYMBOL_TYPE (sym) = hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 1); | |
3058 | ||
3059 | /* The "SYMBOL_NAME" field is expected to be the mangled name | |
3060 | * (if any), which we get from the "alias" field of the SOM record | |
3061 | * if that exists. | |
3062 | */ | |
c5aa993b JM |
3063 | if ((dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS) && |
3064 | dn_bufp->ddocfunc.alias && /* has an alias */ | |
3065 | *(char *) (VT (objfile) + dn_bufp->ddocfunc.alias)) /* not a null string */ | |
3066 | SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.alias; | |
c906108c | 3067 | else |
c5aa993b | 3068 | SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.name; |
c906108c SS |
3069 | |
3070 | /* Special hack to get around HP compilers' insistence on | |
3071 | * reporting "main" as "_MAIN_" for C/C++ */ | |
3072 | if ((strcmp (SYMBOL_NAME (sym), "_MAIN_") == 0) && | |
c5aa993b JM |
3073 | (strcmp (VT (objfile) + dn_bufp->ddocfunc.name, "main") == 0)) |
3074 | SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.name; | |
3075 | ||
3076 | if (dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS) | |
3077 | { | |
3078 | ||
3079 | /* SYMBOL_INIT_DEMANGLED_NAME is a macro which winds up | |
3080 | * calling the demangler in libiberty (cplus_demangle()) to | |
3081 | * do the job. This generally does the job, even though | |
3082 | * it's intended for the GNU compiler and not the aCC compiler | |
3083 | * Note that SYMBOL_INIT_DEMANGLED_NAME calls the | |
3084 | * demangler with arguments DMGL_PARAMS | DMGL_ANSI. | |
3085 | * Generally, we don't want params when we display | |
3086 | * a demangled name, but when I took out the DMGL_PARAMS, | |
3087 | * some things broke, so I'm leaving it in here, and | |
3088 | * working around the issue in stack.c. - RT | |
3089 | */ | |
3090 | SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack); | |
3091 | ||
3092 | if ((SYMBOL_NAME (sym) == VT (objfile) + dn_bufp->ddocfunc.alias) && | |
3093 | (!SYMBOL_CPLUS_DEMANGLED_NAME (sym))) | |
3094 | { | |
3095 | ||
3096 | /* Well, the symbol name is mangled, but the | |
3097 | * demangler in libiberty failed so the demangled | |
3098 | * field is still NULL. Try to | |
3099 | * do the job ourselves based on the "name" field | |
3100 | * in the SOM record. A complication here is that | |
3101 | * the name field contains only the function name | |
3102 | * (like "f"), whereas we want the class qualification | |
3103 | * (as in "c::f"). Try to reconstruct that. | |
3104 | */ | |
3105 | char *basename; | |
3106 | char *classname; | |
3107 | char *dem_name; | |
3108 | basename = VT (objfile) + dn_bufp->ddocfunc.name; | |
3109 | classname = class_of (SYMBOL_TYPE (sym)); | |
3110 | if (classname) | |
3111 | { | |
3112 | dem_name = xmalloc (strlen (basename) + strlen (classname) + 3); | |
3113 | strcpy (dem_name, classname); | |
3114 | strcat (dem_name, "::"); | |
3115 | strcat (dem_name, basename); | |
3116 | SYMBOL_CPLUS_DEMANGLED_NAME (sym) = dem_name; | |
3117 | SYMBOL_LANGUAGE (sym) = language_cplus; | |
3118 | } | |
3119 | } | |
3120 | } | |
c906108c SS |
3121 | |
3122 | /* Add the function symbol to the list of symbols in this blockvector */ | |
3123 | if (dn_bufp->ddocfunc.global) | |
3124 | add_symbol_to_list (sym, &global_symbols); | |
3125 | else | |
3126 | add_symbol_to_list (sym, &file_symbols); | |
3127 | new->name = sym; | |
3128 | ||
3129 | /* Search forward to the next BEGIN and also read | |
3130 | * in the line info up to that point. | |
3131 | * Not sure why this is needed. | |
3132 | * In HP FORTRAN this code is harmful since there | |
3133 | * may not be a BEGIN after the FUNCTION. | |
3134 | * So I made it C/C++ specific. - RT | |
3135 | */ | |
3136 | if (dn_bufp->ddocfunc.language == HP_LANGUAGE_C || | |
c5aa993b JM |
3137 | dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS) |
3138 | { | |
3139 | while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN) | |
3140 | { | |
3141 | dn_bufp = hpread_get_lntt (++index, objfile); | |
3142 | if (dn_bufp->dblock.extension) | |
3143 | continue; | |
3144 | } | |
3145 | SL_INDEX (objfile) = hpread_record_lines (current_subfile, | |
3146 | SL_INDEX (objfile), | |
3147 | dn_bufp->dbegin.address, | |
3148 | objfile, offset); | |
3149 | SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile); | |
3150 | } | |
c906108c SS |
3151 | record_line (current_subfile, SYMBOL_LINE (sym), valu); |
3152 | break; | |
3153 | ||
3154 | case DNTT_TYPE_BEGIN: | |
3155 | /* Begin a new scope. */ | |
c5aa993b JM |
3156 | if (context_stack_depth == 1 /* this means we're at function level */ && |
3157 | context_stack[0].name != NULL /* this means it's a function */ && | |
3158 | context_stack[0].depth == 0 /* this means it's the first BEGIN | |
3159 | we've seen after the FUNCTION */ | |
3160 | ) | |
3161 | { | |
3162 | /* This is the first BEGIN after a FUNCTION. | |
3163 | * We ignore this one, since HP compilers always insert | |
3164 | * at least one BEGIN, i.e. it's: | |
3165 | * | |
3166 | * FUNCTION | |
3167 | * argument symbols | |
3168 | * BEGIN | |
3169 | * local symbols | |
3170 | * (possibly nested BEGIN ... END's if there are inner { } blocks) | |
3171 | * END | |
3172 | * END | |
3173 | * | |
3174 | * By ignoring this first BEGIN, the local symbols get treated | |
3175 | * as belonging to the function scope, and "print func::local_sym" | |
3176 | * works (which is what we want). | |
3177 | */ | |
3178 | ||
3179 | /* All we do here is increase the depth count associated with | |
3180 | * the FUNCTION entry in the context stack. This ensures that | |
3181 | * the next BEGIN we see (if any), representing a real nested { } | |
3182 | * block, will get processed. | |
3183 | */ | |
3184 | ||
3185 | context_stack[0].depth++; | |
3186 | ||
3187 | } | |
3188 | else | |
3189 | { | |
3190 | ||
3191 | /* Record lines up to this SLT pointer. */ | |
3192 | SL_INDEX (objfile) = hpread_record_lines (current_subfile, | |
3193 | SL_INDEX (objfile), | |
3194 | dn_bufp->dbegin.address, | |
3195 | objfile, offset); | |
3196 | /* Calculate start address of new scope */ | |
3197 | valu = hpread_get_location (dn_bufp->dbegin.address, objfile); | |
3198 | valu += offset; /* Relocate for dynamic loading */ | |
3199 | /* We use the scope start DNTT index as nesting depth identifier! */ | |
3200 | desc = hpread_get_scope_start (dn_bufp->dbegin.address, objfile); | |
3201 | new = push_context (desc, valu); | |
3202 | } | |
c906108c SS |
3203 | break; |
3204 | ||
3205 | case DNTT_TYPE_END: | |
3206 | /* End a scope. */ | |
3207 | ||
3208 | /* Valid end kinds are: | |
3209 | * MODULE | |
3210 | * FUNCTION | |
3211 | * WITH | |
3212 | * COMMON | |
3213 | * BEGIN | |
3214 | * CLASS_SCOPE | |
3215 | */ | |
3216 | ||
3217 | SL_INDEX (objfile) = hpread_record_lines (current_subfile, | |
3218 | SL_INDEX (objfile), | |
3219 | dn_bufp->dend.address, | |
3220 | objfile, offset); | |
3221 | switch (dn_bufp->dend.endkind) | |
3222 | { | |
3223 | case DNTT_TYPE_MODULE: | |
3224 | /* Ending a module ends the symbol table for that module. | |
c5aa993b JM |
3225 | * Calling end_symtab() has the side effect of clearing the |
3226 | * last_source_file pointer, which in turn signals | |
3227 | * process_one_debug_symbol() to treat the next DNTT_TYPE_SRCFILE | |
3228 | * record as a module-begin. | |
3229 | */ | |
c906108c SS |
3230 | valu = text_offset + text_size + offset; |
3231 | ||
c5aa993b JM |
3232 | /* Tell our caller that we're done with expanding the |
3233 | * debug information for a module. | |
3234 | */ | |
3235 | *at_module_boundary_p = 1; | |
3236 | ||
3237 | /* Don't do this, as our caller will do it! | |
c906108c | 3238 | |
c5aa993b JM |
3239 | * (void) end_symtab (valu, objfile, 0); |
3240 | */ | |
c906108c SS |
3241 | break; |
3242 | ||
3243 | case DNTT_TYPE_FUNCTION: | |
3244 | /* Ending a function, well, ends the function's scope. */ | |
3245 | dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index, | |
3246 | objfile); | |
3247 | valu = dn_temp->dfunc.hiaddr + offset; | |
c5aa993b JM |
3248 | /* Insert func params into local list */ |
3249 | merge_symbol_lists (¶m_symbols, &local_symbols); | |
c906108c SS |
3250 | new = pop_context (); |
3251 | /* Make a block for the local symbols within. */ | |
3252 | finish_block (new->name, &local_symbols, new->old_blocks, | |
3253 | new->start_addr, valu, objfile); | |
c5aa993b JM |
3254 | WITHIN_FUNCTION (objfile) = 0; /* This may have to change for Pascal */ |
3255 | local_symbols = new->locals; | |
3256 | param_symbols = new->params; | |
c906108c SS |
3257 | break; |
3258 | ||
3259 | case DNTT_TYPE_BEGIN: | |
c5aa993b JM |
3260 | if (context_stack_depth == 1 && |
3261 | context_stack[0].name != NULL && | |
3262 | context_stack[0].depth == 1) | |
3263 | { | |
3264 | /* This is the END corresponding to the | |
3265 | * BEGIN which we ignored - see DNTT_TYPE_BEGIN case above. | |
3266 | */ | |
3267 | context_stack[0].depth--; | |
3268 | } | |
3269 | else | |
3270 | { | |
3271 | /* Ending a local scope. */ | |
3272 | valu = hpread_get_location (dn_bufp->dend.address, objfile); | |
3273 | /* Why in the hell is this needed? */ | |
3274 | valu += offset + 9; /* Relocate for dynamic loading */ | |
3275 | new = pop_context (); | |
3276 | desc = dn_bufp->dend.beginscope.dnttp.index; | |
3277 | if (desc != new->depth) | |
3278 | complain (&lbrac_mismatch_complaint, (char *) symnum); | |
3279 | ||
3280 | /* Make a block for the local symbols within. */ | |
3281 | finish_block (new->name, &local_symbols, new->old_blocks, | |
3282 | new->start_addr, valu, objfile); | |
3283 | local_symbols = new->locals; | |
3284 | param_symbols = new->params; | |
3285 | } | |
c906108c SS |
3286 | break; |
3287 | ||
c5aa993b JM |
3288 | case DNTT_TYPE_WITH: |
3289 | /* Since we ignore the DNTT_TYPE_WITH that starts the scope, | |
3290 | * we can ignore the DNTT_TYPE_END that ends it. | |
3291 | */ | |
c906108c SS |
3292 | break; |
3293 | ||
c5aa993b JM |
3294 | case DNTT_TYPE_COMMON: |
3295 | /* End a FORTRAN common block. We don't currently handle these */ | |
3296 | complain (&hpread_unhandled_end_common_complaint); | |
c906108c SS |
3297 | break; |
3298 | ||
c5aa993b | 3299 | case DNTT_TYPE_CLASS_SCOPE: |
c906108c | 3300 | |
c5aa993b JM |
3301 | /* pai: FIXME Not handling nested classes for now -- must |
3302 | * maintain a stack */ | |
3303 | class_scope_name = NULL; | |
c906108c SS |
3304 | |
3305 | #if 0 | |
c5aa993b | 3306 | /* End a class scope */ |
c906108c SS |
3307 | valu = hpread_get_location (dn_bufp->dend.address, objfile); |
3308 | /* Why in the hell is this needed? */ | |
3309 | valu += offset + 9; /* Relocate for dynamic loading */ | |
3310 | new = pop_context (); | |
3311 | desc = dn_bufp->dend.beginscope.dnttp.index; | |
3312 | if (desc != new->depth) | |
3313 | complain (&lbrac_mismatch_complaint, (char *) symnum); | |
3314 | /* Make a block for the local symbols within. */ | |
3315 | finish_block (new->name, &local_symbols, new->old_blocks, | |
3316 | new->start_addr, valu, objfile); | |
3317 | local_symbols = new->locals; | |
3318 | param_symbols = new->params; | |
3319 | #endif | |
3320 | break; | |
3321 | ||
c5aa993b JM |
3322 | default: |
3323 | complain (&hpread_unexpected_end_complaint); | |
3324 | break; | |
c906108c SS |
3325 | } |
3326 | break; | |
3327 | ||
c5aa993b | 3328 | /* DNTT_TYPE_IMPORT is not handled */ |
c906108c SS |
3329 | |
3330 | case DNTT_TYPE_LABEL: | |
3331 | SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE; | |
3332 | break; | |
3333 | ||
3334 | case DNTT_TYPE_FPARAM: | |
3335 | /* Function parameters. */ | |
3336 | /* Note 1: This code was present in the 4.16 sources, and then | |
3337 | removed, because fparams are handled in | |
3338 | hpread_read_function_type(). However, while fparam symbols | |
3339 | are indeed handled twice, this code here cannot be removed | |
3340 | because then they don't get added to the local symbol list of | |
3341 | the function's code block, which leads to a failure to look | |
3342 | up locals, "this"-relative member names, etc. So I've put | |
3343 | this code back in. pai/1997-07-21 */ | |
3344 | /* Note 2: To fix a defect, we stopped adding FPARAMS to local_symbols | |
3345 | in hpread_read_function_type(), so FPARAMS had to be handled | |
3346 | here. I changed the location to be the appropriate argument | |
3347 | kinds rather than LOC_LOCAL. pai/1997-08-08 */ | |
3348 | /* Note 3: Well, the fix in Note 2 above broke argument printing | |
3349 | in traceback frames, and further it makes assumptions about the | |
3350 | order of the FPARAM entries from HP compilers (cc and aCC in particular | |
3351 | generate them in reverse orders -- fixing one breaks for the other). | |
3352 | So I've added code in hpread_read_function_type() to add fparams | |
3353 | to a param_symbols list for the current context level. These are | |
3354 | then merged into local_symbols when a function end is reached. | |
c5aa993b JM |
3355 | pai/1997-08-11 */ |
3356 | ||
3357 | break; /* do nothing; handled in hpread_read_function_type() */ | |
3358 | ||
3359 | #if 0 /* Old code */ | |
c906108c | 3360 | if (dn_bufp->dfparam.regparam) |
c5aa993b | 3361 | SYMBOL_CLASS (sym) = LOC_REGISTER; |
c906108c SS |
3362 | else if (dn_bufp->dfparam.indirect) |
3363 | SYMBOL_CLASS (sym) = LOC_REF_ARG; | |
3364 | else | |
3365 | SYMBOL_CLASS (sym) = LOC_ARG; | |
3366 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3367 | if (dn_bufp->dfparam.copyparam) | |
c5aa993b JM |
3368 | { |
3369 | SYMBOL_VALUE (sym) = dn_bufp->dfparam.location; | |
c906108c | 3370 | #ifdef HPREAD_ADJUST_STACK_ADDRESS |
c5aa993b JM |
3371 | SYMBOL_VALUE (sym) |
3372 | += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile)); | |
c906108c | 3373 | #endif |
c5aa993b | 3374 | } |
c906108c | 3375 | else |
c5aa993b | 3376 | SYMBOL_VALUE (sym) = dn_bufp->dfparam.location; |
c906108c SS |
3377 | SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile); |
3378 | add_symbol_to_list (sym, &fparam_symbols); | |
3379 | break; | |
3380 | #endif | |
3381 | ||
3382 | case DNTT_TYPE_SVAR: | |
3383 | /* Static variables. */ | |
c5aa993b | 3384 | SYMBOL_CLASS (sym) = LOC_STATIC; |
c906108c SS |
3385 | |
3386 | /* Note: There is a case that arises with globals in shared | |
3387 | * libraries where we need to set the address to LOC_INDIRECT. | |
3388 | * This case is if you have a global "g" in one library, and | |
3389 | * it is referenced "extern <type> g;" in another library. | |
3390 | * If we're processing the symbols for the referencing library, | |
3391 | * we'll see a global "g", but in this case the address given | |
3392 | * in the symbol table contains a pointer to the real "g". | |
3393 | * We use the storage class LOC_INDIRECT to indicate this. RT | |
3394 | */ | |
c5aa993b JM |
3395 | if (is_in_import_list (SYMBOL_NAME (sym), objfile)) |
3396 | SYMBOL_CLASS (sym) = LOC_INDIRECT; | |
c906108c SS |
3397 | |
3398 | SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location + data_offset; | |
3399 | SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile); | |
3400 | ||
3401 | if (dn_bufp->dsvar.global) | |
3402 | add_symbol_to_list (sym, &global_symbols); | |
c5aa993b | 3403 | |
c906108c SS |
3404 | else if (WITHIN_FUNCTION (objfile)) |
3405 | add_symbol_to_list (sym, &local_symbols); | |
c5aa993b | 3406 | |
c906108c SS |
3407 | else |
3408 | add_symbol_to_list (sym, &file_symbols); | |
3409 | ||
3410 | if (dn_bufp->dsvar.thread_specific) | |
c5aa993b JM |
3411 | { |
3412 | /* Thread-local variable. | |
3413 | */ | |
3414 | SYMBOL_CLASS (sym) = LOC_THREAD_LOCAL_STATIC; | |
3415 | SYMBOL_BASEREG (sym) = CR27_REGNUM; | |
3416 | ||
3417 | if (objfile->flags & OBJF_SHARED) | |
3418 | { | |
3419 | /* | |
3420 | * This variable is not only thread local but | |
3421 | * in a shared library. | |
3422 | * | |
3423 | * Alas, the shared lib structures are private | |
3424 | * to "somsolib.c". But C lets us point to one. | |
3425 | */ | |
3426 | struct so_list *so; | |
3427 | ||
3428 | if (objfile->obj_private == NULL) | |
3429 | error ("Internal error in reading shared library information."); | |
3430 | ||
3431 | so = ((obj_private_data_t *) (objfile->obj_private))->so_info; | |
3432 | if (so == NULL) | |
3433 | error ("Internal error in reading shared library information."); | |
3434 | ||
3435 | /* Thread-locals in shared libraries do NOT have the | |
3436 | * standard offset ("data_offset"), so we re-calculate | |
3437 | * where to look for this variable, using a call-back | |
3438 | * to interpret the private shared-library data. | |
3439 | */ | |
3440 | SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location + | |
3441 | so_lib_thread_start_addr (so); | |
3442 | } | |
3443 | } | |
c906108c SS |
3444 | break; |
3445 | ||
3446 | case DNTT_TYPE_DVAR: | |
3447 | /* Dynamic variables. */ | |
3448 | if (dn_bufp->ddvar.regvar) | |
3449 | SYMBOL_CLASS (sym) = LOC_REGISTER; | |
3450 | else | |
3451 | SYMBOL_CLASS (sym) = LOC_LOCAL; | |
c5aa993b | 3452 | |
c906108c SS |
3453 | SYMBOL_VALUE (sym) = dn_bufp->ddvar.location; |
3454 | #ifdef HPREAD_ADJUST_STACK_ADDRESS | |
3455 | SYMBOL_VALUE (sym) | |
3456 | += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile)); | |
3457 | #endif | |
3458 | SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile); | |
3459 | if (dn_bufp->ddvar.global) | |
3460 | add_symbol_to_list (sym, &global_symbols); | |
3461 | else if (WITHIN_FUNCTION (objfile)) | |
3462 | add_symbol_to_list (sym, &local_symbols); | |
3463 | else | |
3464 | add_symbol_to_list (sym, &file_symbols); | |
3465 | break; | |
3466 | ||
3467 | case DNTT_TYPE_CONST: | |
3468 | /* A constant (pascal?). */ | |
3469 | SYMBOL_CLASS (sym) = LOC_CONST; | |
3470 | SYMBOL_VALUE (sym) = dn_bufp->dconst.location; | |
3471 | SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile); | |
3472 | if (dn_bufp->dconst.global) | |
3473 | add_symbol_to_list (sym, &global_symbols); | |
3474 | else if (WITHIN_FUNCTION (objfile)) | |
3475 | add_symbol_to_list (sym, &local_symbols); | |
3476 | else | |
3477 | add_symbol_to_list (sym, &file_symbols); | |
3478 | break; | |
3479 | ||
3480 | case DNTT_TYPE_TYPEDEF: | |
3481 | /* A typedef. We do want to process these, since a name is | |
3482 | * added to the namespace for the typedef'ed name. | |
3483 | */ | |
3484 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
3485 | SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile); | |
3486 | if (dn_bufp->dtype.global) | |
3487 | add_symbol_to_list (sym, &global_symbols); | |
3488 | else if (WITHIN_FUNCTION (objfile)) | |
3489 | add_symbol_to_list (sym, &local_symbols); | |
3490 | else | |
3491 | add_symbol_to_list (sym, &file_symbols); | |
3492 | break; | |
3493 | ||
3494 | case DNTT_TYPE_TAGDEF: | |
3495 | { | |
c5aa993b JM |
3496 | int global = dn_bufp->dtag.global; |
3497 | /* Structure, union, enum, template, or class tag definition */ | |
3498 | /* We do want to process these, since a name is | |
3499 | * added to the namespace for the tag name (and if C++ class, | |
3500 | * for the typename also). | |
3501 | */ | |
3502 | SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE; | |
3503 | ||
3504 | /* The tag contains in its "type" field a pointer to the | |
3505 | * DNTT_TYPE_STRUCT, DNTT_TYPE_UNION, DNTT_TYPE_ENUM, | |
3506 | * DNTT_TYPE_CLASS or DNTT_TYPE_TEMPLATE | |
3507 | * record that actually defines the type. | |
3508 | */ | |
3509 | SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile); | |
3510 | TYPE_NAME (sym->type) = SYMBOL_NAME (sym); | |
3511 | TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym); | |
3512 | if (dn_bufp->dtag.global) | |
3513 | add_symbol_to_list (sym, &global_symbols); | |
3514 | else if (WITHIN_FUNCTION (objfile)) | |
3515 | add_symbol_to_list (sym, &local_symbols); | |
3516 | else | |
3517 | add_symbol_to_list (sym, &file_symbols); | |
3518 | ||
3519 | /* If this is a C++ class, then we additionally | |
3520 | * need to define a typedef for the | |
3521 | * class type. E.g., so that the name "c" becomes visible as | |
3522 | * a type name when the user says "class c { ... }". | |
3523 | * In order to figure this out, we need to chase down the "type" | |
3524 | * field to get to the DNTT_TYPE_CLASS record. | |
3525 | * | |
3526 | * We also add the typename for ENUM. Though this isn't | |
3527 | * strictly correct, it is necessary because of the debug info | |
3528 | * generated by the aCC compiler, in which we cannot | |
3529 | * distinguish between: | |
3530 | * enum e { ... }; | |
3531 | * and | |
3532 | * typedef enum { ... } e; | |
3533 | * I.e., the compiler emits the same debug info for the above | |
3534 | * two cases, in both cases "e" appearing as a tagdef. | |
3535 | * Therefore go ahead and generate the typename so that | |
3536 | * "ptype e" will work in the above cases. | |
3537 | * | |
3538 | * We also add the typename for TEMPLATE, so as to allow "ptype t" | |
3539 | * when "t" is a template name. | |
3540 | */ | |
3541 | if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile)) | |
3542 | dn_bufp = hpread_get_lntt (dn_bufp->dtag.type.dnttp.index, objfile); | |
3543 | else | |
3544 | { | |
3545 | complain (&hpread_tagdef_complaint); | |
3546 | return; | |
3547 | } | |
3548 | if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS || | |
3549 | dn_bufp->dblock.kind == DNTT_TYPE_ENUM || | |
3550 | dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE) | |
3551 | { | |
3552 | struct symbol *newsym; | |
3553 | ||
3554 | newsym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack, | |
3555 | sizeof (struct symbol)); | |
3556 | memset (newsym, 0, sizeof (struct symbol)); | |
3557 | SYMBOL_NAME (newsym) = name; | |
3558 | SYMBOL_LANGUAGE (newsym) = language_auto; | |
3559 | SYMBOL_NAMESPACE (newsym) = VAR_NAMESPACE; | |
3560 | SYMBOL_LINE (newsym) = 0; | |
3561 | SYMBOL_VALUE (newsym) = 0; | |
3562 | SYMBOL_CLASS (newsym) = LOC_TYPEDEF; | |
3563 | SYMBOL_TYPE (newsym) = sym->type; | |
3564 | if (global) | |
3565 | add_symbol_to_list (newsym, &global_symbols); | |
3566 | else if (WITHIN_FUNCTION (objfile)) | |
3567 | add_symbol_to_list (newsym, &local_symbols); | |
3568 | else | |
3569 | add_symbol_to_list (newsym, &file_symbols); | |
3570 | } | |
c906108c SS |
3571 | } |
3572 | break; | |
3573 | ||
3574 | case DNTT_TYPE_POINTER: | |
3575 | /* Declares a pointer type. Should not be necessary to do anything | |
3576 | * with the type at this level; these are processed | |
3577 | * at the hpread_type_lookup() level. | |
3578 | */ | |
3579 | break; | |
3580 | ||
3581 | case DNTT_TYPE_ENUM: | |
3582 | /* Declares an enum type. Should not be necessary to do anything | |
3583 | * with the type at this level; these are processed | |
3584 | * at the hpread_type_lookup() level. | |
3585 | */ | |
3586 | break; | |
3587 | ||
3588 | case DNTT_TYPE_MEMENUM: | |
3589 | /* Member of enum */ | |
3590 | /* Ignored at this level, but hpread_read_enum_type() will take | |
3591 | * care of walking the list of enumeration members. | |
3592 | */ | |
3593 | break; | |
3594 | ||
3595 | case DNTT_TYPE_SET: | |
3596 | /* Declares a set type. Should not be necessary to do anything | |
3597 | * with the type at this level; these are processed | |
3598 | * at the hpread_type_lookup() level. | |
3599 | */ | |
3600 | break; | |
3601 | ||
3602 | case DNTT_TYPE_SUBRANGE: | |
3603 | /* Declares a subrange type. Should not be necessary to do anything | |
3604 | * with the type at this level; these are processed | |
3605 | * at the hpread_type_lookup() level. | |
3606 | */ | |
3607 | break; | |
3608 | ||
3609 | case DNTT_TYPE_ARRAY: | |
3610 | /* Declares an array type. Should not be necessary to do anything | |
3611 | * with the type at this level; these are processed | |
3612 | * at the hpread_type_lookup() level. | |
3613 | */ | |
3614 | break; | |
3615 | ||
3616 | case DNTT_TYPE_STRUCT: | |
3617 | case DNTT_TYPE_UNION: | |
3618 | /* Declares an struct/union type. | |
3619 | * Should not be necessary to do anything | |
3620 | * with the type at this level; these are processed | |
3621 | * at the hpread_type_lookup() level. | |
3622 | */ | |
3623 | break; | |
3624 | ||
3625 | case DNTT_TYPE_FIELD: | |
3626 | /* Structure/union/class field */ | |
3627 | /* Ignored at this level, but hpread_read_struct_type() will take | |
3628 | * care of walking the list of structure/union/class members. | |
3629 | */ | |
3630 | break; | |
3631 | ||
c5aa993b | 3632 | /* DNTT_TYPE_VARIANT is not handled by GDB */ |
c906108c | 3633 | |
c5aa993b | 3634 | /* DNTT_TYPE_FILE is not handled by GDB */ |
c906108c SS |
3635 | |
3636 | case DNTT_TYPE_FUNCTYPE: | |
3637 | /* Function type */ | |
3638 | /* Ignored at this level, handled within hpread_type_lookup() */ | |
3639 | break; | |
3640 | ||
3641 | case DNTT_TYPE_WITH: | |
3642 | /* This is emitted within methods to indicate "with <class>" | |
3643 | * scoping rules (i.e., indicate that the class data members | |
3644 | * are directly visible). | |
3645 | * However, since GDB already infers this by looking at the | |
3646 | * "this" argument, interpreting the DNTT_TYPE_WITH | |
3647 | * symbol record is unnecessary. | |
3648 | */ | |
3649 | break; | |
3650 | ||
3651 | case DNTT_TYPE_COMMON: | |
3652 | /* FORTRAN common. Not yet handled. */ | |
3653 | complain (&hpread_unhandled_common_complaint); | |
3654 | break; | |
3655 | ||
c5aa993b JM |
3656 | /* DNTT_TYPE_COBSTRUCT is not handled by GDB. */ |
3657 | /* DNTT_TYPE_XREF is not handled by GDB. */ | |
3658 | /* DNTT_TYPE_SA is not handled by GDB. */ | |
3659 | /* DNTT_TYPE_MACRO is not handled by GDB */ | |
c906108c SS |
3660 | |
3661 | case DNTT_TYPE_BLOCKDATA: | |
3662 | /* Not sure what this is - part of FORTRAN support maybe? | |
3663 | * Anyway, not yet handled. | |
3664 | */ | |
3665 | complain (&hpread_unhandled_blockdata_complaint); | |
3666 | break; | |
3667 | ||
3668 | case DNTT_TYPE_CLASS_SCOPE: | |
3669 | ||
3670 | ||
3671 | ||
3672 | /* The compiler brackets member functions with a CLASS_SCOPE/END | |
3673 | * pair of records, presumably to put them in a different scope | |
3674 | * from the module scope where they are normally defined. | |
3675 | * E.g., in the situation: | |
3676 | * void f() { ... } | |
3677 | * void c::f() { ...} | |
3678 | * The member function "c::f" will be bracketed by a CLASS_SCOPE/END. | |
3679 | * This causes "break f" at the module level to pick the | |
3680 | * the file-level function f(), not the member function | |
3681 | * (which needs to be referenced via "break c::f"). | |
3682 | * | |
3683 | * Here we record the class name to generate the demangled names of | |
3684 | * member functions later. | |
3685 | * | |
3686 | * FIXME Not being used now for anything -- cplus_demangle seems | |
3687 | * enough for getting the class-qualified names of functions. We | |
3688 | * may need this for handling nested classes and types. */ | |
3689 | ||
3690 | /* pai: FIXME Not handling nested classes for now -- need to | |
3691 | * maintain a stack */ | |
3692 | ||
3693 | dn_temp = hpread_get_lntt (dn_bufp->dclass_scope.type.dnttp.index, objfile); | |
3694 | if (dn_temp->dblock.kind == DNTT_TYPE_TAGDEF) | |
c5aa993b | 3695 | class_scope_name = VT (objfile) + dn_temp->dtag.name; |
c906108c | 3696 | else |
c5aa993b | 3697 | class_scope_name = NULL; |
c906108c SS |
3698 | |
3699 | #if 0 | |
3700 | ||
3701 | /* Begin a new scope. */ | |
3702 | SL_INDEX (objfile) = hpread_record_lines (current_subfile, | |
3703 | SL_INDEX (objfile), | |
c5aa993b | 3704 | dn_bufp->dclass_scope.address, |
c906108c SS |
3705 | objfile, offset); |
3706 | valu = hpread_get_location (dn_bufp->dclass_scope.address, objfile); | |
3707 | valu += offset; /* Relocate for dynamic loading */ | |
3708 | desc = hpread_get_scope_start (dn_bufp->dclass_scope.address, objfile); | |
3709 | /* We use the scope start DNTT index as the nesting depth identifier! */ | |
3710 | new = push_context (desc, valu); | |
3711 | #endif | |
3712 | break; | |
3713 | ||
3714 | case DNTT_TYPE_REFERENCE: | |
3715 | /* Declares a C++ reference type. Should not be necessary to do anything | |
3716 | * with the type at this level; these are processed | |
3717 | * at the hpread_type_lookup() level. | |
3718 | */ | |
3719 | break; | |
3720 | ||
3721 | case DNTT_TYPE_PTRMEM: | |
3722 | /* Declares a C++ pointer-to-data-member type. This does not | |
3723 | * need to be handled at this level; being a type description it | |
3724 | * is instead handled at the hpread_type_lookup() level. | |
3725 | */ | |
3726 | break; | |
3727 | ||
3728 | case DNTT_TYPE_PTRMEMFUNC: | |
3729 | /* Declares a C++ pointer-to-function-member type. This does not | |
3730 | * need to be handled at this level; being a type description it | |
3731 | * is instead handled at the hpread_type_lookup() level. | |
3732 | */ | |
3733 | break; | |
3734 | ||
3735 | case DNTT_TYPE_CLASS: | |
3736 | /* Declares a class type. | |
3737 | * Should not be necessary to do anything | |
3738 | * with the type at this level; these are processed | |
3739 | * at the hpread_type_lookup() level. | |
3740 | */ | |
3741 | break; | |
3742 | ||
3743 | case DNTT_TYPE_GENFIELD: | |
3744 | /* I believe this is used for class member functions */ | |
3745 | /* Ignored at this level, but hpread_read_struct_type() will take | |
3746 | * care of walking the list of class members. | |
3747 | */ | |
3748 | break; | |
3749 | ||
3750 | case DNTT_TYPE_VFUNC: | |
3751 | /* Virtual function */ | |
3752 | /* This does not have to be handled at this level; handled in | |
3753 | * the course of processing class symbols. | |
3754 | */ | |
3755 | break; | |
3756 | ||
3757 | case DNTT_TYPE_MEMACCESS: | |
3758 | /* DDE ignores this symbol table record. | |
3759 | * It has something to do with "modified access" to class members. | |
3760 | * I'll assume we can safely ignore it too. | |
3761 | */ | |
3762 | break; | |
3763 | ||
3764 | case DNTT_TYPE_INHERITANCE: | |
3765 | /* These don't have to be handled here, since they are handled | |
3766 | * within hpread_read_struct_type() in the process of constructing | |
3767 | * a class type. | |
3768 | */ | |
3769 | break; | |
3770 | ||
3771 | case DNTT_TYPE_FRIEND_CLASS: | |
3772 | case DNTT_TYPE_FRIEND_FUNC: | |
3773 | /* These can safely be ignored, as GDB doesn't need this | |
3774 | * info. DDE only uses it in "describe". We may later want | |
3775 | * to extend GDB's "ptype" to give this info, but for now | |
3776 | * it seems safe enough to ignore it. | |
c5aa993b | 3777 | */ |
c906108c SS |
3778 | break; |
3779 | ||
3780 | case DNTT_TYPE_MODIFIER: | |
3781 | /* Intended to supply "modified access" to a type */ | |
3782 | /* From the way DDE handles this, it looks like it always | |
3783 | * modifies a type. Therefore it is safe to ignore it at this | |
3784 | * level, and handle it in hpread_type_lookup(). | |
3785 | */ | |
3786 | break; | |
3787 | ||
3788 | case DNTT_TYPE_OBJECT_ID: | |
3789 | /* Just ignore this - that's all DDE does */ | |
3790 | break; | |
3791 | ||
3792 | case DNTT_TYPE_MEMFUNC: | |
3793 | /* Member function */ | |
3794 | /* This does not have to be handled at this level; handled in | |
3795 | * the course of processing class symbols. | |
3796 | */ | |
3797 | break; | |
3798 | ||
3799 | case DNTT_TYPE_DOC_MEMFUNC: | |
3800 | /* Member function */ | |
3801 | /* This does not have to be handled at this level; handled in | |
3802 | * the course of processing class symbols. | |
3803 | */ | |
3804 | break; | |
3805 | ||
3806 | case DNTT_TYPE_TEMPLATE: | |
3807 | /* Template - sort of the header for a template definition, | |
3808 | * which like a class, points to a member list and also points | |
3809 | * to a TEMPLATE_ARG list of type-arguments. | |
3810 | * We do not need to process TEMPLATE records at this level though. | |
3811 | */ | |
3812 | break; | |
3813 | ||
3814 | case DNTT_TYPE_TEMPLATE_ARG: | |
3815 | /* The TEMPLATE record points to an argument list of | |
3816 | * TEMPLATE_ARG records, each of which describes one | |
3817 | * of the type-arguments. | |
3818 | * We do not need to process TEMPLATE_ARG records at this level though. | |
3819 | */ | |
3820 | break; | |
3821 | ||
3822 | case DNTT_TYPE_FUNC_TEMPLATE: | |
3823 | /* This will get emitted for member functions of templates. | |
3824 | * But we don't need to process this record at this level though, | |
3825 | * we will process it in the course of processing a TEMPLATE | |
3826 | * record. | |
3827 | */ | |
3828 | break; | |
3829 | ||
3830 | case DNTT_TYPE_LINK: | |
3831 | /* The LINK record is used to link up templates with instantiations. */ | |
3832 | /* It is not clear why this is needed, and furthermore aCC does | |
3833 | * not appear to generate this, so I think we can safely ignore it. - RT | |
3834 | */ | |
3835 | break; | |
3836 | ||
c5aa993b JM |
3837 | /* DNTT_TYPE_DYN_ARRAY_DESC is not handled by GDB */ |
3838 | /* DNTT_TYPE_DESC_SUBRANGE is not handled by GDB */ | |
3839 | /* DNTT_TYPE_BEGIN_EXT is not handled by GDB */ | |
3840 | /* DNTT_TYPE_INLN is not handled by GDB */ | |
3841 | /* DNTT_TYPE_INLN_LIST is not handled by GDB */ | |
3842 | /* DNTT_TYPE_ALIAS is not handled by GDB */ | |
c906108c SS |
3843 | |
3844 | default: | |
3845 | break; | |
3846 | } | |
3847 | } | |
3848 | ||
3849 | /* Get nesting depth for a DNTT entry. | |
3850 | * DN_BUFP points to a DNTT entry. | |
3851 | * OBJFILE is the object file. | |
3852 | * REPORT_NESTED is a flag; if 0, real nesting depth is | |
3853 | * reported, if it is 1, the function simply returns a | |
3854 | * non-zero value if the nesting depth is anything > 0. | |
3855 | * | |
3856 | * Return value is an integer. 0 => not a local type / name | |
3857 | * positive return => type or name is local to some | |
3858 | * block or function. | |
c5aa993b | 3859 | */ |
c906108c SS |
3860 | |
3861 | ||
3862 | /* elz: ATTENTION: FIXME: NOTE: WARNING!!!! | |
3863 | this function now returns 0 right away. It was taking too much time | |
3864 | at start up. Now, though, the local types are not handled correctly. | |
c5aa993b | 3865 | */ |
c906108c SS |
3866 | |
3867 | ||
3868 | static int | |
fba45db2 KB |
3869 | hpread_get_scope_depth (union dnttentry *dn_bufp, struct objfile *objfile, |
3870 | int report_nested) | |
c906108c SS |
3871 | { |
3872 | register int index; | |
c5aa993b | 3873 | register union dnttentry *dn_tmp; |
c906108c SS |
3874 | register short depth = 0; |
3875 | /****************************/ | |
3876 | return 0; | |
3877 | /****************************/ | |
3878 | ||
3879 | index = (((char *) dn_bufp) - LNTT (objfile)) / (sizeof (struct dntt_type_block)); | |
c5aa993b | 3880 | |
c906108c SS |
3881 | while (--index >= 0) |
3882 | { | |
3883 | dn_tmp = hpread_get_lntt (index, objfile); | |
3884 | switch (dn_tmp->dblock.kind) | |
c5aa993b JM |
3885 | { |
3886 | case DNTT_TYPE_MODULE: | |
3887 | return depth; | |
3888 | case DNTT_TYPE_END: | |
3889 | /* index is signed int; dnttp.index is 29-bit unsigned int! */ | |
3890 | index = (int) dn_tmp->dend.beginscope.dnttp.index; | |
3891 | break; | |
3892 | case DNTT_TYPE_BEGIN: | |
3893 | case DNTT_TYPE_FUNCTION: | |
3894 | case DNTT_TYPE_DOC_FUNCTION: | |
3895 | case DNTT_TYPE_WITH: | |
3896 | case DNTT_TYPE_COMMON: | |
3897 | case DNTT_TYPE_CLASS_SCOPE: | |
3898 | depth++; | |
3899 | if (report_nested) | |
3900 | return 1; | |
3901 | break; | |
3902 | default: | |
3903 | break; | |
3904 | } | |
c906108c SS |
3905 | } |
3906 | return depth; | |
3907 | } | |
3908 | ||
3909 | /* Adjust the bitoffsets for all fields of an anonymous union of | |
3910 | type TYPE by negative BITS. This handles HP aCC's hideous habit | |
3911 | of giving members of anonymous unions bit offsets relative to the | |
c5aa993b | 3912 | enclosing structure instead of relative to the union itself. */ |
c906108c SS |
3913 | |
3914 | static void | |
fba45db2 | 3915 | hpread_adjust_bitoffsets (struct type *type, int bits) |
c906108c SS |
3916 | { |
3917 | register int i; | |
3918 | ||
3919 | /* This is done only for unions; caller had better check that | |
c5aa993b | 3920 | it is an anonymous one. */ |
c906108c SS |
3921 | if (TYPE_CODE (type) != TYPE_CODE_UNION) |
3922 | return; | |
3923 | ||
3924 | /* Adjust each field; since this is a union, there are no base | |
3925 | classes. Also no static membes. Also, no need for recursion as | |
3926 | the members of this union if themeselves structs or unions, have | |
3927 | the correct bitoffsets; if an anonymous union is a member of this | |
3928 | anonymous union, the code in hpread_read_struct_type() will | |
3929 | adjust for that. */ | |
3930 | ||
3931 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
3932 | TYPE_FIELD_BITPOS (type, i) -= bits; | |
3933 | } | |
3934 | ||
3935 | /* Because of quirks in HP compilers' treatment of anonymous unions inside | |
3936 | classes, we have to chase through a chain of threaded FIELD entries. | |
3937 | If we encounter an anonymous union in the chain, we must recursively skip over | |
3938 | that too. | |
3939 | ||
3940 | This function does a "next" in the chain of FIELD entries, but transparently | |
3941 | skips over anonymous unions' fields (recursively). | |
c5aa993b | 3942 | |
c906108c SS |
3943 | Inputs are the number of times to do "next" at the top level, the dnttpointer |
3944 | (FIELD) and entry pointer (FIELDP) for the dntt record corresponding to it, | |
3945 | and the ubiquitous objfile parameter. (Note: FIELDP is a **.) Return value | |
3946 | is a dnttpointer for the new field after all the skipped ones */ | |
3947 | ||
3948 | static dnttpointer | |
fba45db2 KB |
3949 | hpread_get_next_skip_over_anon_unions (int skip_fields, dnttpointer field, |
3950 | union dnttentry **fieldp, | |
3951 | struct objfile *objfile) | |
c906108c | 3952 | { |
c5aa993b | 3953 | struct type *anon_type; |
c906108c SS |
3954 | register int i; |
3955 | int bitoffset; | |
c5aa993b | 3956 | char *name; |
c906108c | 3957 | |
c5aa993b | 3958 | for (i = 0; i < skip_fields; i++) |
c906108c SS |
3959 | { |
3960 | /* Get type of item we're looking at now; recursively processes the types | |
3961 | of these intermediate items we skip over, so they aren't lost. */ | |
3962 | anon_type = hpread_type_lookup ((*fieldp)->dfield.type, objfile); | |
3963 | anon_type = CHECK_TYPEDEF (anon_type); | |
3964 | bitoffset = (*fieldp)->dfield.bitoffset; | |
3965 | name = VT (objfile) + (*fieldp)->dfield.name; | |
c5aa993b | 3966 | /* First skip over one item to avoid stack death on recursion */ |
c906108c SS |
3967 | field = (*fieldp)->dfield.nextfield; |
3968 | *fieldp = hpread_get_lntt (field.dnttp.index, objfile); | |
3969 | /* Do we have another anonymous union? If so, adjust the bitoffsets | |
3970 | of its members and skip over its members. */ | |
3971 | if ((TYPE_CODE (anon_type) == TYPE_CODE_UNION) && | |
c5aa993b JM |
3972 | (!name || STREQ (name, ""))) |
3973 | { | |
3974 | hpread_adjust_bitoffsets (anon_type, bitoffset); | |
3975 | field = hpread_get_next_skip_over_anon_unions (TYPE_NFIELDS (anon_type), field, fieldp, objfile); | |
3976 | } | |
c906108c SS |
3977 | } |
3978 | return field; | |
3979 | } |