1 | /* stabshll.c -- Convert GNU-style a.out debug information into
|
---|
2 | IBM OS/2 HLL 3 debug information
|
---|
3 | Copyright (c) 1993-1998 Eberhard Mattes
|
---|
4 |
|
---|
5 | This file is part of emxomf.
|
---|
6 |
|
---|
7 | emxomf 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, or (at your option)
|
---|
10 | any later version.
|
---|
11 |
|
---|
12 | emxomf 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 emxomf; see the file COPYING. If not, write to
|
---|
19 | the Free Software Foundation, 59 Temple Place - Suite 330,
|
---|
20 | Boston, MA 02111-1307, USA. */
|
---|
21 | //#define HLL_DEBUG 1
|
---|
22 |
|
---|
23 | #define DEMANGLE_PROC_NAMES 1
|
---|
24 |
|
---|
25 | /*******************************************************************************
|
---|
26 | * Header Files *
|
---|
27 | *******************************************************************************/
|
---|
28 | #include <stdio.h>
|
---|
29 | #include <stdlib.h>
|
---|
30 | #include <string.h>
|
---|
31 | #include <stdarg.h>
|
---|
32 | #include <time.h>
|
---|
33 | #include <alloca.h>
|
---|
34 | #include <ctype.h>
|
---|
35 | #ifdef DEMANGLE_PROC_NAMES
|
---|
36 | # include <demangle.h>
|
---|
37 | #endif
|
---|
38 | #include "defs.h"
|
---|
39 | #include "emxomf.h"
|
---|
40 | #include "grow.h"
|
---|
41 | #include "stabshll.h"
|
---|
42 |
|
---|
43 |
|
---|
44 | /*******************************************************************************
|
---|
45 | * Defined Constants And Macros *
|
---|
46 | *******************************************************************************/
|
---|
47 | /* Field ID values for the type table. */
|
---|
48 |
|
---|
49 | #define FID_nil 0x80 /* No data */
|
---|
50 | #define FID_void 0x81 /* Type void */
|
---|
51 | #define FID_string 0x82 /* A length-prefixed string follows */
|
---|
52 | #define FID_index 0x83 /* A type index follows */
|
---|
53 | #define FID_span_16u 0x85 /* An unsigned 16-bit number follows */
|
---|
54 | #define FID_span_32u 0x86 /* An unsigned 32-bit number follows */
|
---|
55 | #define FID_span_8s 0x88 /* A signed 8-bit number follows */
|
---|
56 | #define FID_span_16s 0x89 /* A signed 16-bit number follows */
|
---|
57 | #define FID_span_32s 0x8a /* A signed 32-bit number follows */
|
---|
58 | #define FID_span_8u 0x8b /* An unsigned 8-bit number follows */
|
---|
59 |
|
---|
60 | /* Static scope table subrecord types. */
|
---|
61 |
|
---|
62 | #define SST_begin 0x00 /* Begin block */
|
---|
63 | #define SST_proc 0x01 /* Procedure */
|
---|
64 | #define SST_end 0x02 /* End block or end procedure */
|
---|
65 | #define SST_auto 0x04 /* Scoped variable */
|
---|
66 | #define SST_static 0x05 /* Static variable */
|
---|
67 | #define SST_reg 0x0d /* Register variable */
|
---|
68 | #define SST_changseg 0x11 /* Change default segment */
|
---|
69 | #define SST_tag 0x16 /* Structure, union, enum tags */
|
---|
70 | #define SST_tag2 0x19 /* Extended tag for long names (C++ class). */
|
---|
71 | #define SST_memfunc 0x1a /* C++ member function */
|
---|
72 | #define SST_CPPproc 0x1d /* C++ function */
|
---|
73 | #define SST_CPPstatic 0x1e /* C++ static variable */
|
---|
74 | #define SST_cuinfo 0x40 /* Compile unit information */
|
---|
75 |
|
---|
76 | /* Class visibility. */
|
---|
77 |
|
---|
78 | #define VIS_PRIVATE 0x00 /* private */
|
---|
79 | #define VIS_PROTECTED 0x01 /* protected */
|
---|
80 | #define VIS_PUBLIC 0x02 /* public */
|
---|
81 |
|
---|
82 | #define MEMBER_VIS 0x03 /* Member visibility mask */
|
---|
83 | #define MEMBER_FUNCTION 0x08 /* It's a member function */
|
---|
84 | #define MEMBER_VIRTUAL 0x10 /* Member function / base class is virtual */
|
---|
85 | #define MEMBER_VOLATILE 0x20 /* Member function is volatile */
|
---|
86 | #define MEMBER_CONST 0x40 /* Member function is const */
|
---|
87 | #define MEMBER_STATIC 0x80 /* Member is static */
|
---|
88 | #define MEMBER_CTOR 0x100 /* Member function is a constructor */
|
---|
89 | #define MEMBER_DTOR 0x200 /* Member function is a destructor */
|
---|
90 | #define MEMBER_BASE 0x400 /* It's a base class */
|
---|
91 |
|
---|
92 | /* Flags for ty_struc. */
|
---|
93 |
|
---|
94 | #define STRUC_FORWARD 0x01 /* Structure declared forward */
|
---|
95 |
|
---|
96 |
|
---|
97 | /*******************************************************************************
|
---|
98 | * Structures and Typedefs *
|
---|
99 | *******************************************************************************/
|
---|
100 | enum type_tag
|
---|
101 | {
|
---|
102 | ty_stabs_ref, /* Reference to stabs type */
|
---|
103 | ty_prim, /* Primitive type */
|
---|
104 | ty_alias, /* Equivalent type */
|
---|
105 | ty_pointer, /* Pointer type */
|
---|
106 | ty_func, /* Function */
|
---|
107 | ty_args, /* Function arguments */
|
---|
108 | ty_struc, /* Structure or union */
|
---|
109 | ty_types, /* Type list for structure/union */
|
---|
110 | ty_fields, /* Field list for structure/union */
|
---|
111 | ty_enu, /* Enumeration type */
|
---|
112 | ty_values, /* Enumeration values */
|
---|
113 | ty_array, /* Array */
|
---|
114 | ty_bits, /* Bit field / bit string */
|
---|
115 | ty_ref, /* Reference type (C++) */
|
---|
116 | ty_member, /* Member of a C++ class */
|
---|
117 | ty_class, /* A C++ class */
|
---|
118 | ty_memfunc, /* A C++ member function */
|
---|
119 | ty_baseclass, /* A C++ base class */
|
---|
120 | ty_max
|
---|
121 | };
|
---|
122 |
|
---|
123 | /* A structure field. */
|
---|
124 |
|
---|
125 | struct field
|
---|
126 | {
|
---|
127 | dword offset; /* Offset, in bytes */
|
---|
128 | const char *name; /* Field name */
|
---|
129 | };
|
---|
130 |
|
---|
131 | /* An enumeration value. */
|
---|
132 |
|
---|
133 | struct value
|
---|
134 | {
|
---|
135 | long index; /* The value */
|
---|
136 | const char *name; /* The name */
|
---|
137 | };
|
---|
138 |
|
---|
139 | /* Temporary representation of a structure field. */
|
---|
140 |
|
---|
141 | struct tmp_field
|
---|
142 | {
|
---|
143 | struct type *type; /* The internal type */
|
---|
144 | dword offset; /* The offset of the field */
|
---|
145 | const char *name; /* The field name */
|
---|
146 | const char *sname; /* Static name */
|
---|
147 | const char *mnglname; /* Mangled name for methods. (#456) */
|
---|
148 | int flags; /* Member flags (visibility) */
|
---|
149 | };
|
---|
150 |
|
---|
151 |
|
---|
152 | /* Internal representation of a type. */
|
---|
153 |
|
---|
154 | struct type
|
---|
155 | {
|
---|
156 | enum type_tag tag; /* The type of this type */
|
---|
157 | int index; /* The HLL index for this type */
|
---|
158 | struct type *next; /* All types are chained in a single list */
|
---|
159 | struct type *nexthash; /* All types are chained in the hash list */
|
---|
160 | union
|
---|
161 | {
|
---|
162 | int stabs_ref; /* Reference a stabs type */
|
---|
163 | struct type *pointer; /* Pointer to another type */
|
---|
164 | struct type *alias; /* Alias for another type */
|
---|
165 | struct type *ref; /* Reference to another type */
|
---|
166 | struct
|
---|
167 | { /* Structure */
|
---|
168 | struct type *types; /* Types of the fields */
|
---|
169 | struct type *fields; /* Field names and offsets */
|
---|
170 | dword size; /* Size of the structure, in bytes */
|
---|
171 | word count; /* Number of fields */
|
---|
172 | word flags; /* Flags (STRUC_FORWARD) */
|
---|
173 | const char *name; /* Name of the structure */
|
---|
174 | } struc;
|
---|
175 | struct
|
---|
176 | { /* Class */
|
---|
177 | struct type *members; /* Members */
|
---|
178 | dword size; /* Size of the class, in bytes */
|
---|
179 | word count; /* Number of fields */
|
---|
180 | const char *name; /* Name of the class */
|
---|
181 | } class;
|
---|
182 | struct
|
---|
183 | { /* Enumeration */
|
---|
184 | struct type *type; /* Base type */
|
---|
185 | struct type *values; /* Values */
|
---|
186 | long first; /* Smallest value */
|
---|
187 | long last; /* Biggest value */
|
---|
188 | const char *name; /* Name of the enum */
|
---|
189 | } enu;
|
---|
190 | struct
|
---|
191 | { /* Array */
|
---|
192 | struct type *itype; /* Index type */
|
---|
193 | struct type *etype; /* Element type */
|
---|
194 | long first; /* First index */
|
---|
195 | long last; /* Last index */
|
---|
196 | } array;
|
---|
197 | struct
|
---|
198 | { /* Bitfield */
|
---|
199 | struct type *type; /* Base type */
|
---|
200 | long start; /* First bit */
|
---|
201 | long count; /* Number of bits */
|
---|
202 | } bits;
|
---|
203 | struct
|
---|
204 | { /* Function */
|
---|
205 | struct type *ret; /* Return type */
|
---|
206 | struct type *args; /* Argument types */
|
---|
207 | struct type *domain; /* Domain type (C++ member) (#456) */
|
---|
208 | int arg_count; /* Number of arguments */
|
---|
209 | } func;
|
---|
210 | struct
|
---|
211 | { /* Function arguments */
|
---|
212 | struct type **list; /* Array of argument types */
|
---|
213 | int count; /* Number of arguments */
|
---|
214 | } args;
|
---|
215 | struct
|
---|
216 | { /* List of types */
|
---|
217 | struct type **list; /* Array of types */
|
---|
218 | int count; /* Number of types */
|
---|
219 | } types;
|
---|
220 | struct
|
---|
221 | { /* Structure fields */
|
---|
222 | struct field *list; /* The fields */
|
---|
223 | int count; /* Number of fields */
|
---|
224 | } fields;
|
---|
225 | struct
|
---|
226 | { /* Class member */
|
---|
227 | struct type *type; /* Type of the member */
|
---|
228 | dword offset; /* Offset of the member, in bytes */
|
---|
229 | int flags; /* Member flags (visibility etc.) */
|
---|
230 | const char *name; /* Name of the member */
|
---|
231 | const char *sname; /* Static name */
|
---|
232 | } member;
|
---|
233 | struct
|
---|
234 | { /* Enumeration values */
|
---|
235 | struct value *list; /* Array of values */
|
---|
236 | int count; /* Number of values */
|
---|
237 | } values;
|
---|
238 | struct
|
---|
239 | { /* Member function */
|
---|
240 | struct type *type; /* Function type */
|
---|
241 | dword offset; /* Offset in the virtual table */
|
---|
242 | int flags; /* Member flags (visibility etc.) */
|
---|
243 | const char *name; /* Name of the member function */
|
---|
244 | const char *mnglname; /* Mangled Name of the member function. (#456) */
|
---|
245 | } memfunc;
|
---|
246 | struct
|
---|
247 | { /* Base class */
|
---|
248 | struct type *type; /* The base class */
|
---|
249 | dword offset; /* Offset of the base class */
|
---|
250 | int flags; /* Visibility, virtual */
|
---|
251 | } baseclass;
|
---|
252 | } d;
|
---|
253 | };
|
---|
254 |
|
---|
255 |
|
---|
256 | /* A block. */
|
---|
257 |
|
---|
258 | struct block
|
---|
259 | {
|
---|
260 | dword addr; /* Start address of the block */
|
---|
261 | size_t patch_ptr; /* Index into SST buffer for patching */
|
---|
262 | };
|
---|
263 |
|
---|
264 | /* Timestamp for the compiler unit information SST subrecord. */
|
---|
265 |
|
---|
266 | #pragma pack(1)
|
---|
267 |
|
---|
268 | struct timestamp
|
---|
269 | {
|
---|
270 | byte hours;
|
---|
271 | byte minutes;
|
---|
272 | byte seconds;
|
---|
273 | byte hundredths;
|
---|
274 | byte day;
|
---|
275 | byte month;
|
---|
276 | word year;
|
---|
277 | };
|
---|
278 |
|
---|
279 | #pragma pack()
|
---|
280 |
|
---|
281 |
|
---|
282 | /*******************************************************************************
|
---|
283 | * Global Variables *
|
---|
284 | *******************************************************************************/
|
---|
285 | /* This variable points to the next character of a stabs type being
|
---|
286 | parsed. */
|
---|
287 |
|
---|
288 | static const char *parse_ptr;
|
---|
289 |
|
---|
290 | /* Start of the stabs string we're parsing. Useful when printing
|
---|
291 | messages. */
|
---|
292 | static const char *parse_start;
|
---|
293 |
|
---|
294 | /* Current stabs index. Useful when printing messages. */
|
---|
295 | static int *parse_pindex;
|
---|
296 |
|
---|
297 | /* The next HLL type index. When creating a complex type, this index
|
---|
298 | is used. Then, this variable is incremented. */
|
---|
299 |
|
---|
300 | static int hll_type_index;
|
---|
301 |
|
---|
302 | /* We keep all internal types in a single list. When creating a new
|
---|
303 | type, we first look through the list to find out whether an
|
---|
304 | identical type already exists. Doing a linear search is
|
---|
305 | inefficient, but that doesn't matter here, according to
|
---|
306 | experience. This variable points to the first type of the list. */
|
---|
307 |
|
---|
308 | static struct type *type_head;
|
---|
309 | #define TYPE_HASH_MAX 211
|
---|
310 | static struct type *atype_tag[TYPE_HASH_MAX];
|
---|
311 | #ifdef HASH_DEBUG
|
---|
312 | static int ctypes = 0;
|
---|
313 | static int ctype_tag[TYPE_HASH_MAX];
|
---|
314 | #endif
|
---|
315 |
|
---|
316 | /* This growing array keeps track of stabs vs. internal types. It is
|
---|
317 | indexed by stabs type numbers. */
|
---|
318 |
|
---|
319 | static struct type **stype_list;
|
---|
320 | static struct grow stype_grow;
|
---|
321 |
|
---|
322 | /* We collect function arguments in this growing array. */
|
---|
323 |
|
---|
324 | static struct type **args_list;
|
---|
325 | static struct grow args_grow;
|
---|
326 |
|
---|
327 | /* This stack (implemented with a growing array) keeps track of
|
---|
328 | begin/end block nesting. */
|
---|
329 |
|
---|
330 | static struct block *block_stack;
|
---|
331 | static struct grow block_grow;
|
---|
332 |
|
---|
333 | /* This string pool contains field names etc. */
|
---|
334 |
|
---|
335 | static struct strpool *str_pool;
|
---|
336 |
|
---|
337 | /* This variable holds the sym_ptr index of the most recently
|
---|
338 | encountered N_LBRAC symbol. */
|
---|
339 |
|
---|
340 | static int lbrac_index;
|
---|
341 |
|
---|
342 | /* The index (in sst) of the most recently started SST subrecord. */
|
---|
343 |
|
---|
344 | static size_t subrec_start;
|
---|
345 |
|
---|
346 | /* The proc_patch_base contains the index where the base address and
|
---|
347 | function length are to be patched into the SST. */
|
---|
348 |
|
---|
349 | static size_t proc_patch_base;
|
---|
350 |
|
---|
351 | /* The base address used by the most recently proc record in the
|
---|
352 | SST. */
|
---|
353 |
|
---|
354 | static size_t proc_start_addr;
|
---|
355 |
|
---|
356 | /* The internal type of the most recently defined function. Valid
|
---|
357 | only if last_fun_valid is TRUE. */
|
---|
358 |
|
---|
359 | static struct type last_fun_type;
|
---|
360 |
|
---|
361 | /* This variable is TRUE if a function has recently been defined. */
|
---|
362 |
|
---|
363 | static int last_fun_valid;
|
---|
364 |
|
---|
365 | /* The length of the prologue of the most recently defined
|
---|
366 | function. */
|
---|
367 |
|
---|
368 | static int prologue_length;
|
---|
369 |
|
---|
370 | /* The address of the most recently defined function. */
|
---|
371 |
|
---|
372 | static dword last_fun_addr;
|
---|
373 |
|
---|
374 | /* This variable is non-zero when converting a translated C++
|
---|
375 | program. */
|
---|
376 |
|
---|
377 | static int cplusplus_flag;
|
---|
378 |
|
---|
379 | /* Unnamed structures are numbered sequentially, using this
|
---|
380 | counter. */
|
---|
381 |
|
---|
382 | static int unnamed_struct_number;
|
---|
383 |
|
---|
384 | /* kso #456 2003-06-11: Reversed quiet workaround. */
|
---|
385 | #define no_warning warning_parse
|
---|
386 |
|
---|
387 |
|
---|
388 | /*******************************************************************************
|
---|
389 | * Internal Functions *
|
---|
390 | *******************************************************************************/
|
---|
391 | static void parse_typedef (int *index);
|
---|
392 | static void warning_parse (const char *pszFormat, ...);
|
---|
393 |
|
---|
394 |
|
---|
395 | /**
|
---|
396 | * Report an warning in which might be connecting to parsing.
|
---|
397 | *
|
---|
398 | * @param pszFormat Message string.
|
---|
399 | * @param ... More arguments
|
---|
400 | */
|
---|
401 | static void warning_parse (const char *pszFormat, ...)
|
---|
402 | {
|
---|
403 | va_list args;
|
---|
404 |
|
---|
405 | va_start (args, pszFormat);
|
---|
406 | fprintf (stderr, "emxomf warning: ");
|
---|
407 | vfprintf (stderr, pszFormat, args);
|
---|
408 | va_end (args);
|
---|
409 | fputc ('\n', stderr);
|
---|
410 |
|
---|
411 |
|
---|
412 | if (parse_ptr && parse_start && parse_ptr >= parse_start)
|
---|
413 | {
|
---|
414 | if (parse_pindex && *parse_pindex >= 0 && *parse_pindex < sym_count)
|
---|
415 | fprintf (stderr, "emxomf info: parsing sym no.%d type=%d at char '%c' in position %d:\n%s\n",
|
---|
416 | *parse_pindex, sym_ptr[*parse_pindex].n_type,
|
---|
417 | *parse_ptr, parse_ptr - parse_start, parse_start);
|
---|
418 | else
|
---|
419 | fprintf (stderr, "emxomf info: parsing '%c' at position %d:\n%s\n",
|
---|
420 | *parse_ptr, parse_ptr - parse_start, parse_start);
|
---|
421 | }
|
---|
422 | }
|
---|
423 |
|
---|
424 |
|
---|
425 | /* Start a type table record of type TYPE, with type qualifier QUAL.
|
---|
426 | tt_end() must be called to finish the record after writing the
|
---|
427 | record contents. */
|
---|
428 |
|
---|
429 | static void tt_start (byte type, byte qual)
|
---|
430 | {
|
---|
431 | subrec_start = tt.size;
|
---|
432 | grow_by (&tt_boundary_grow, 1);
|
---|
433 | tt_boundary[tt_boundary_grow.count++] = tt.size;
|
---|
434 | buffer_word (&tt, 0); /* Length of sub-record */
|
---|
435 | buffer_byte (&tt, type); /* Type of sub-record */
|
---|
436 | buffer_byte (&tt, qual); /* Type qualifier */
|
---|
437 | }
|
---|
438 |
|
---|
439 |
|
---|
440 | /* Finish a type table record. This function must be called after
|
---|
441 | tt_start(). */
|
---|
442 |
|
---|
443 | static void tt_end (void)
|
---|
444 | {
|
---|
445 | *(word *)(tt.buf + subrec_start) = tt.size - subrec_start - 2;
|
---|
446 | }
|
---|
447 |
|
---|
448 |
|
---|
449 | /* Put the type index TI into the type table. TI = -1 encodes the
|
---|
450 | `nil' type (no type), 0x97 encodes the `void' type. All other
|
---|
451 | values are type indices. */
|
---|
452 |
|
---|
453 | static void tt_index (int ti)
|
---|
454 | {
|
---|
455 | if (ti == -1) /* nil */
|
---|
456 | buffer_byte (&tt, FID_nil);
|
---|
457 | else if (ti == 0x97) /* void */
|
---|
458 | buffer_byte (&tt, FID_void);
|
---|
459 | else
|
---|
460 | {
|
---|
461 | buffer_byte (&tt, FID_index);
|
---|
462 | buffer_word (&tt, ti);
|
---|
463 | }
|
---|
464 | }
|
---|
465 |
|
---|
466 |
|
---|
467 | /* Put an 8-bit byte into the type table. */
|
---|
468 |
|
---|
469 | static void tt_byte (byte x)
|
---|
470 | {
|
---|
471 | buffer_byte (&tt, x);
|
---|
472 | }
|
---|
473 |
|
---|
474 |
|
---|
475 | /* Put a 16-bit word into the type table. */
|
---|
476 |
|
---|
477 | static void tt_word (word x)
|
---|
478 | {
|
---|
479 | buffer_word (&tt, x);
|
---|
480 | }
|
---|
481 |
|
---|
482 |
|
---|
483 | /* Put a 32-bit double word into the type table. */
|
---|
484 |
|
---|
485 | static void tt_dword (dword x)
|
---|
486 | {
|
---|
487 | buffer_dword (&tt, x);
|
---|
488 | }
|
---|
489 |
|
---|
490 |
|
---|
491 | /* Put the name S into the type table. */
|
---|
492 |
|
---|
493 | static void tt_name (const char *s)
|
---|
494 | {
|
---|
495 | buffer_byte (&tt, FID_string);
|
---|
496 | buffer_nstr (&tt, s);
|
---|
497 | }
|
---|
498 |
|
---|
499 |
|
---|
500 | /* Put the mangled name S into the type table. */
|
---|
501 |
|
---|
502 | static void tt_enc (const char *s)
|
---|
503 | {
|
---|
504 | buffer_enc (&tt, s);
|
---|
505 | }
|
---|
506 |
|
---|
507 |
|
---|
508 | /* Put the unsigned number N into the type table. Depending on the
|
---|
509 | magnitude of N, different encodings are used. */
|
---|
510 |
|
---|
511 | static void tt_unsigned_span (dword n)
|
---|
512 | {
|
---|
513 | if (n <= 0xff)
|
---|
514 | {
|
---|
515 | buffer_byte (&tt, FID_span_8u);
|
---|
516 | buffer_byte (&tt, n);
|
---|
517 | }
|
---|
518 | else if (n <= 0xffff)
|
---|
519 | {
|
---|
520 | buffer_byte (&tt, FID_span_16u);
|
---|
521 | buffer_word (&tt, n);
|
---|
522 | }
|
---|
523 | else
|
---|
524 | {
|
---|
525 | buffer_byte (&tt, FID_span_32u);
|
---|
526 | buffer_dword (&tt, n);
|
---|
527 | }
|
---|
528 | }
|
---|
529 |
|
---|
530 |
|
---|
531 | /* Put the signed number N into the type table. Depending on the
|
---|
532 | magnitude of N, different encodings are used. */
|
---|
533 |
|
---|
534 | static void tt_signed_span (long n)
|
---|
535 | {
|
---|
536 | if (-127 <= n && n <= 127)
|
---|
537 | {
|
---|
538 | buffer_byte (&tt, FID_span_8s);
|
---|
539 | buffer_byte (&tt, n);
|
---|
540 | }
|
---|
541 | else if (-32767 <= n && n <= 32767)
|
---|
542 | {
|
---|
543 | buffer_byte (&tt, FID_span_16s);
|
---|
544 | buffer_word (&tt, n);
|
---|
545 | }
|
---|
546 | else
|
---|
547 | {
|
---|
548 | buffer_byte (&tt, FID_span_32s);
|
---|
549 | buffer_dword (&tt, n);
|
---|
550 | }
|
---|
551 | }
|
---|
552 |
|
---|
553 |
|
---|
554 | /* Start a static scope table subrecord of type TYPE. sst_end() must
|
---|
555 | be called to finish the subrecord after writing the subrecord
|
---|
556 | data. */
|
---|
557 |
|
---|
558 | static void sst_start (byte type)
|
---|
559 | {
|
---|
560 | subrec_start = sst.size;
|
---|
561 | grow_by (&sst_boundary_grow, 1);
|
---|
562 | sst_boundary[sst_boundary_grow.count++] = sst.size;
|
---|
563 | /* Length of sub-record - bird: not sure if HL03 likes this. */
|
---|
564 | buffer_byte (&sst, 0x80);
|
---|
565 | buffer_byte (&sst, 0);
|
---|
566 | /* Type of sub-record */
|
---|
567 | buffer_byte (&sst, type);
|
---|
568 | }
|
---|
569 |
|
---|
570 |
|
---|
571 | /* Finish a static scope table subrecord. This function must be
|
---|
572 | called after sst_start(). */
|
---|
573 |
|
---|
574 | static void sst_end (void)
|
---|
575 | {
|
---|
576 | int len = sst.size - subrec_start - 2;
|
---|
577 | /* -- experimental...
|
---|
578 | if (len > 1000)
|
---|
579 | error ("sst_end: Record too big");
|
---|
580 | */
|
---|
581 | sst.buf[subrec_start] = (len >> 8) | 0x80;
|
---|
582 | sst.buf[subrec_start + 1] = 0xff & len;
|
---|
583 | }
|
---|
584 |
|
---|
585 |
|
---|
586 | /* Define a static variable in the static scope table. NAME is the
|
---|
587 | name of the variable, ADDR is the address of the variable (segment
|
---|
588 | offset), TYPE_INDEX is the HLL type index. If EXT is zero, SYM_SEG
|
---|
589 | is the segment (N_DATA, for instance). If EXT is non-zero, SYM_SEG
|
---|
590 | is the stabs symbol index (for the relocation table). This
|
---|
591 | function also creates appropriate relocation table entries. */
|
---|
592 |
|
---|
593 | static void sst_static (const char *name, dword addr, int type_index,
|
---|
594 | int sym_seg, int ext, const struct nlist *psym)
|
---|
595 | {
|
---|
596 | struct relocation_info r;
|
---|
597 | size_t len = strlen (name);
|
---|
598 |
|
---|
599 | if (!psym)
|
---|
600 | {
|
---|
601 | psym = find_symbol_ex (name, -1, ext);
|
---|
602 | if (!psym)
|
---|
603 | {
|
---|
604 | char *psz = alloca (len + 2);
|
---|
605 | *psz = '_';
|
---|
606 | memcpy(psz + 1, name, len + 1);
|
---|
607 | psym = find_symbol_ex (psz, -1, ext);
|
---|
608 | }
|
---|
609 | }
|
---|
610 | if (psym)
|
---|
611 | set_hll_type (psym - sym_ptr, type_index);
|
---|
612 |
|
---|
613 | if (len > 255)
|
---|
614 | sst_start (SST_CPPstatic);
|
---|
615 | else
|
---|
616 | sst_start (SST_static);
|
---|
617 | r.r_address = sst.size;
|
---|
618 | buffer_dword (&sst, addr); /* Segment offset */
|
---|
619 | buffer_word (&sst, 0); /* Segment address */
|
---|
620 | buffer_word (&sst, type_index); /* Type index */
|
---|
621 | if (len > 255)
|
---|
622 | buffer_enc (&sst, name); /* Symbol name - encoded. */
|
---|
623 | else
|
---|
624 | buffer_nstr (&sst, name); /* Symbol name */
|
---|
625 | sst_end ();
|
---|
626 | r.r_extern = ext;
|
---|
627 | r.r_length = 2;
|
---|
628 | r.r_symbolnum = sym_seg;
|
---|
629 | r.r_pcrel = 0;
|
---|
630 | r.r_pad = 0;
|
---|
631 | buffer_mem (&sst_reloc, &r, sizeof (r));
|
---|
632 | r.r_address += 4;
|
---|
633 | r.r_length = 1;
|
---|
634 | buffer_mem (&sst_reloc, &r, sizeof (r));
|
---|
635 | }
|
---|
636 |
|
---|
637 | /**
|
---|
638 | * Try calculate a good hash (yeah sure).
|
---|
639 | *
|
---|
640 | * @returns hash index.
|
---|
641 | * @param t type
|
---|
642 | */
|
---|
643 | static inline unsigned type_hash (struct type *t)
|
---|
644 | {
|
---|
645 | register unsigned uhash = 0;
|
---|
646 | switch (t->tag)
|
---|
647 | {
|
---|
648 | case ty_alias: uhash = (unsigned)t->d.alias; break;
|
---|
649 | case ty_stabs_ref: uhash = (unsigned)t->d.stabs_ref; break;
|
---|
650 | case ty_prim: uhash = (unsigned)t->index; break;
|
---|
651 | case ty_pointer: uhash = (unsigned)t->d.pointer; break;
|
---|
652 | case ty_ref: uhash = (unsigned)t->d.ref; break;
|
---|
653 | case ty_struc: uhash = (unsigned)t->d.struc.name; break;
|
---|
654 | case ty_class: uhash = (unsigned)t->d.class.name; break;
|
---|
655 | case ty_enu: uhash = (unsigned)t->d.enu.name; break;
|
---|
656 | case ty_array: uhash = (unsigned)t->d.array.etype; break;
|
---|
657 | case ty_bits: uhash = (unsigned)t->d.bits.type; break;
|
---|
658 | case ty_func: uhash = (unsigned)t->d.func.args ^ (unsigned)t->d.func.arg_count ^ (unsigned)t->d.func.ret ^ (unsigned)t->d.func.domain; break;
|
---|
659 | case ty_types: uhash = (unsigned)t->d.types.count << 3; break;
|
---|
660 | case ty_args: uhash = (unsigned)t->d.args.count << 3; break;
|
---|
661 | case ty_fields: uhash = (unsigned)t->d.fields.count << 3; break;
|
---|
662 | case ty_member: uhash = (unsigned)t->d.member.type ^ (unsigned)t->d.member.name >> 7; break;
|
---|
663 | case ty_values: uhash = (unsigned)t->d.values.count << 3; break;
|
---|
664 | case ty_memfunc: uhash = (unsigned)t->d.memfunc.type; break;
|
---|
665 | case ty_baseclass: uhash = (unsigned)t->d.baseclass.type; break;
|
---|
666 | default:break; /* shut up warnings. */
|
---|
667 | }
|
---|
668 | uhash += t->tag;
|
---|
669 | return (uhash ^ uhash >> 13) % TYPE_HASH_MAX;
|
---|
670 | }
|
---|
671 |
|
---|
672 |
|
---|
673 | /**
|
---|
674 | * Search a list for a type.
|
---|
675 | * @returns pointer to the type we found.
|
---|
676 | * @returns NULL if not found.
|
---|
677 | * @param p Pointer to the head list.
|
---|
678 | * @param src Type to find.
|
---|
679 | * @param fhash Whether or not to follow the hash list or the main list.
|
---|
680 | */
|
---|
681 | #ifdef HASH_DEBUG
|
---|
682 | static struct type *type_find (struct type *p, const struct type *src, int fhash)
|
---|
683 | #else
|
---|
684 | static struct type *type_find (struct type *p, const struct type *src)
|
---|
685 | #endif
|
---|
686 | {
|
---|
687 | int i;
|
---|
688 | for (; p != NULL;
|
---|
689 | #ifdef HASH_DEBUG
|
---|
690 | p = fhash ? p->nexthash : p->next )
|
---|
691 | #else
|
---|
692 | p = p->nexthash )
|
---|
693 | #endif
|
---|
694 | if (p->tag == src->tag)
|
---|
695 | switch (p->tag)
|
---|
696 | {
|
---|
697 | case ty_alias:
|
---|
698 | if (p->d.alias == src->d.alias)
|
---|
699 | return p;
|
---|
700 | break;
|
---|
701 | case ty_stabs_ref:
|
---|
702 | if (p->d.stabs_ref == src->d.stabs_ref)
|
---|
703 | return p;
|
---|
704 | break;
|
---|
705 | case ty_prim:
|
---|
706 | if (p->index == src->index)
|
---|
707 | return p;
|
---|
708 | break;
|
---|
709 | case ty_pointer:
|
---|
710 | if (p->d.pointer == src->d.pointer)
|
---|
711 | return p;
|
---|
712 | break;
|
---|
713 | case ty_ref:
|
---|
714 | if (p->d.ref == src->d.ref)
|
---|
715 | return p;
|
---|
716 | break;
|
---|
717 | case ty_struc:
|
---|
718 | if (p->d.struc.fields == src->d.struc.fields
|
---|
719 | && p->d.struc.types == src->d.struc.types
|
---|
720 | && p->d.struc.name == src->d.struc.name
|
---|
721 | && p->d.struc.flags == src->d.struc.flags)
|
---|
722 | return p;
|
---|
723 | break;
|
---|
724 | case ty_class:
|
---|
725 | if (p->d.class.members == src->d.class.members
|
---|
726 | && p->d.class.name == src->d.class.name)
|
---|
727 | return p;
|
---|
728 | break;
|
---|
729 | case ty_enu:
|
---|
730 | if (p->d.enu.type == src->d.enu.type
|
---|
731 | && p->d.enu.values == src->d.enu.values
|
---|
732 | && p->d.enu.name == src->d.enu.name)
|
---|
733 | return p;
|
---|
734 | break;
|
---|
735 | case ty_array:
|
---|
736 | if (p->d.array.etype == src->d.array.etype
|
---|
737 | && p->d.array.itype == src->d.array.itype
|
---|
738 | && p->d.array.first == src->d.array.first
|
---|
739 | && p->d.array.last == src->d.array.last)
|
---|
740 | return p;
|
---|
741 | break;
|
---|
742 | case ty_bits:
|
---|
743 | if (p->d.bits.type == src->d.bits.type
|
---|
744 | && p->d.bits.start == src->d.bits.start
|
---|
745 | && p->d.bits.count == src->d.bits.count)
|
---|
746 | return p;
|
---|
747 | break;
|
---|
748 | case ty_func:
|
---|
749 | if (p->d.func.ret == src->d.func.ret
|
---|
750 | && p->d.func.args == src->d.func.args
|
---|
751 | && p->d.func.domain == src->d.func.domain
|
---|
752 | && p->d.func.arg_count == src->d.func.arg_count)
|
---|
753 | return p;
|
---|
754 | break;
|
---|
755 | case ty_args:
|
---|
756 | if (p->d.args.count == src->d.args.count)
|
---|
757 | {
|
---|
758 | for (i = 0; i < p->d.args.count; ++i)
|
---|
759 | if (p->d.args.list[i] != src->d.args.list[i])
|
---|
760 | break;
|
---|
761 | if (i >= p->d.args.count)
|
---|
762 | return p;
|
---|
763 | }
|
---|
764 | break;
|
---|
765 | case ty_types:
|
---|
766 | if (p->d.types.count == src->d.types.count)
|
---|
767 | {
|
---|
768 | for (i = 0; i < p->d.types.count; ++i)
|
---|
769 | if (p->d.types.list[i] != src->d.types.list[i])
|
---|
770 | break;
|
---|
771 | if (i >= p->d.types.count)
|
---|
772 | return p;
|
---|
773 | }
|
---|
774 | break;
|
---|
775 | case ty_fields:
|
---|
776 | if (p->d.fields.count == src->d.fields.count)
|
---|
777 | {
|
---|
778 | for (i = 0; i < p->d.fields.count; ++i)
|
---|
779 | if (p->d.fields.list[i].offset != src->d.fields.list[i].offset
|
---|
780 | || p->d.fields.list[i].name != src->d.fields.list[i].name)
|
---|
781 | break;
|
---|
782 | if (i >= p->d.fields.count)
|
---|
783 | return p;
|
---|
784 | }
|
---|
785 | break;
|
---|
786 | case ty_member:
|
---|
787 | if (p->d.member.type == src->d.member.type
|
---|
788 | && p->d.member.offset == src->d.member.offset
|
---|
789 | && p->d.member.flags == src->d.member.flags
|
---|
790 | && p->d.member.name == src->d.member.name
|
---|
791 | && p->d.member.sname == src->d.member.sname)
|
---|
792 | return p;
|
---|
793 | break;
|
---|
794 | case ty_values:
|
---|
795 | if (p->d.values.count == src->d.values.count)
|
---|
796 | {
|
---|
797 | for (i = 0; i < p->d.values.count; ++i)
|
---|
798 | if (p->d.values.list[i].index != src->d.values.list[i].index
|
---|
799 | || p->d.values.list[i].name != src->d.values.list[i].name)
|
---|
800 | break;
|
---|
801 | if (i >= p->d.values.count)
|
---|
802 | return p;
|
---|
803 | }
|
---|
804 | break;
|
---|
805 | case ty_memfunc:
|
---|
806 | if (p->d.memfunc.type == src->d.memfunc.type
|
---|
807 | && p->d.memfunc.offset == src->d.memfunc.offset
|
---|
808 | && p->d.memfunc.flags == src->d.memfunc.flags
|
---|
809 | && p->d.memfunc.name == src->d.memfunc.name
|
---|
810 | && p->d.memfunc.mnglname == src->d.memfunc.mnglname)
|
---|
811 | return p;
|
---|
812 | break;
|
---|
813 | case ty_baseclass:
|
---|
814 | if (p->d.baseclass.type == src->d.baseclass.type
|
---|
815 | && p->d.baseclass.offset == src->d.baseclass.offset
|
---|
816 | && p->d.baseclass.flags == src->d.baseclass.flags)
|
---|
817 | return p;
|
---|
818 | break;
|
---|
819 | default:
|
---|
820 | abort ();
|
---|
821 | }
|
---|
822 | return NULL;
|
---|
823 | }
|
---|
824 |
|
---|
825 |
|
---|
826 | /* Add a new internal type to the list of internal types. If an
|
---|
827 | identical type already exists, a pointer to that type is returned.
|
---|
828 | Otherwise, a copy of the new type is added to the list and a
|
---|
829 | pointer to that type is returned. It isn't worth my while to
|
---|
830 | improve the speed of this function, for instance by using
|
---|
831 | hashing.
|
---|
832 |
|
---|
833 | Actually it is worth while optimizing it as it takes 85% of the
|
---|
834 | time here... or rather it was.
|
---|
835 |
|
---|
836 | ctypes=25301 */
|
---|
837 |
|
---|
838 | static struct type *type_add (struct type *src)
|
---|
839 | {
|
---|
840 | struct type *p;
|
---|
841 | unsigned ihash;
|
---|
842 | int i;
|
---|
843 |
|
---|
844 | ihash = type_hash(src);
|
---|
845 | #ifdef HASH_DEBUG
|
---|
846 | p = type_find (atype_tag[ihash], src, 1);
|
---|
847 | #else
|
---|
848 | p = type_find (atype_tag[ihash], src);
|
---|
849 | #endif
|
---|
850 | if (p)
|
---|
851 | {
|
---|
852 | return p;
|
---|
853 | }
|
---|
854 |
|
---|
855 | #ifdef HASH_DEBUG
|
---|
856 | /* {
|
---|
857 | struct type *pcheck = type_find (type_head, src, 0);
|
---|
858 | if (pcheck)
|
---|
859 | {
|
---|
860 | printf("\n\thash algorithm is borked! tag=%d\n", pcheck->tag);
|
---|
861 | return pcheck;
|
---|
862 | }
|
---|
863 | } */
|
---|
864 | ctype_tag[ihash]++;
|
---|
865 | ctypes++;
|
---|
866 | #endif
|
---|
867 |
|
---|
868 | p = xmalloc (sizeof (*p));
|
---|
869 | *p = *src;
|
---|
870 | p->next = type_head;
|
---|
871 | type_head = p;
|
---|
872 | p->nexthash = atype_tag[ihash];
|
---|
873 | atype_tag[ihash] = p;
|
---|
874 | switch (src->tag)
|
---|
875 | {
|
---|
876 | case ty_args:
|
---|
877 | i = src->d.args.count * sizeof (*(src->d.args.list));
|
---|
878 | p->d.args.list = xmalloc (i);
|
---|
879 | memcpy (p->d.args.list, src->d.args.list, i);
|
---|
880 | break;
|
---|
881 | case ty_types:
|
---|
882 | i = src->d.types.count * sizeof (*(src->d.types.list));
|
---|
883 | p->d.types.list = xmalloc (i);
|
---|
884 | memcpy (p->d.types.list, src->d.types.list, i);
|
---|
885 | break;
|
---|
886 | case ty_fields:
|
---|
887 | i = src->d.fields.count * sizeof (*(src->d.fields.list));
|
---|
888 | p->d.fields.list = xmalloc (i);
|
---|
889 | memcpy (p->d.fields.list, src->d.fields.list, i);
|
---|
890 | break;
|
---|
891 | case ty_values:
|
---|
892 | i = src->d.values.count * sizeof (*(src->d.values.list));
|
---|
893 | p->d.values.list = xmalloc (i);
|
---|
894 | memcpy (p->d.values.list, src->d.values.list, i);
|
---|
895 | break;
|
---|
896 | default:
|
---|
897 | break;
|
---|
898 | }
|
---|
899 | return p;
|
---|
900 | }
|
---|
901 |
|
---|
902 |
|
---|
903 | /* Associate the stabs type number NUMBER with the internal type
|
---|
904 | HLL. */
|
---|
905 |
|
---|
906 | static void stype_add (int number, struct type *hll)
|
---|
907 | {
|
---|
908 | int i;
|
---|
909 |
|
---|
910 | /* Stabs type numbers are greater than zero. */
|
---|
911 |
|
---|
912 | if (number < 1)
|
---|
913 | error ("stype_add: Invalid type index %d", number);
|
---|
914 |
|
---|
915 | /* Remember the current size of the table and grow the table as
|
---|
916 | required. */
|
---|
917 |
|
---|
918 | i = stype_grow.alloc;
|
---|
919 | grow_to (&stype_grow, number);
|
---|
920 |
|
---|
921 | /* Initialize the new table entries. */
|
---|
922 |
|
---|
923 | while (i < stype_grow.alloc)
|
---|
924 | stype_list[i++] = NULL;
|
---|
925 |
|
---|
926 | /* Put the type into the table. */
|
---|
927 |
|
---|
928 | #ifdef HLL_DEBUG
|
---|
929 | printf (" type: stabs %d => HLL 0x%x\n", number, hll->index);
|
---|
930 | #endif
|
---|
931 | #if 0 /* not good test... as we do some types twice. */
|
---|
932 | if (stype_list[number-1] != NULL && stype_list[number-1] != hll)
|
---|
933 | warning ("Type stabs %d allready mapped to HLL 0x%x, new HLL 0x%x!!\n", number, stype_list[number-1]->index, hll->index);
|
---|
934 | #endif
|
---|
935 |
|
---|
936 | stype_list[number-1] = hll;
|
---|
937 | }
|
---|
938 |
|
---|
939 |
|
---|
940 | /* Find the internal type associated with the stabs type number
|
---|
941 | NUMBER. If there is no such type, return NULL. */
|
---|
942 |
|
---|
943 | static struct type *stype_find (int number)
|
---|
944 | {
|
---|
945 | /* Stabs type numbers are greater than zero. */
|
---|
946 |
|
---|
947 | if (number < 1)
|
---|
948 | error ("stype_find: Invalid type index %d", number);
|
---|
949 |
|
---|
950 | /* Adjust the index and check if it is within the current size of
|
---|
951 | the table. */
|
---|
952 |
|
---|
953 | --number;
|
---|
954 | if (number >= stype_grow.alloc)
|
---|
955 | return NULL;
|
---|
956 | else
|
---|
957 | return stype_list[number];
|
---|
958 | }
|
---|
959 |
|
---|
960 |
|
---|
961 | /* Dereference stabs references until finding a non-reference. */
|
---|
962 |
|
---|
963 | static const struct type *follow_refs (const struct type *t)
|
---|
964 | {
|
---|
965 | const struct type *t2;
|
---|
966 |
|
---|
967 | while (t->tag == ty_stabs_ref)
|
---|
968 | {
|
---|
969 | t2 = stype_find (t->d.stabs_ref);
|
---|
970 | if (t2 == NULL)
|
---|
971 | break;
|
---|
972 | t = t2;
|
---|
973 | }
|
---|
974 |
|
---|
975 | return t;
|
---|
976 | }
|
---|
977 |
|
---|
978 |
|
---|
979 | #if defined (HLL_DEBUG)
|
---|
980 |
|
---|
981 | /* This function is used to print an internal type for debugging. */
|
---|
982 |
|
---|
983 | static void show_type (struct type *tp)
|
---|
984 | {
|
---|
985 | /* precaution so we don't iterate for ever here when showing classes. */
|
---|
986 | static int fShowClass;
|
---|
987 | int i;
|
---|
988 |
|
---|
989 | /* Currently we crash when showing FILE (stdio.h). So, better not crash here.. */
|
---|
990 | if (!tp)
|
---|
991 | {
|
---|
992 | printf("!!! error! NULL type pointer! !!!");
|
---|
993 | return;
|
---|
994 | }
|
---|
995 |
|
---|
996 | switch (tp->tag)
|
---|
997 | {
|
---|
998 | case ty_prim:
|
---|
999 | printf ("%#x", tp->index);
|
---|
1000 | break;
|
---|
1001 | case ty_stabs_ref:
|
---|
1002 | printf ("t%d", tp->d.stabs_ref);
|
---|
1003 | break;
|
---|
1004 | case ty_alias:
|
---|
1005 | show_type (tp->d.alias);
|
---|
1006 | break;
|
---|
1007 | case ty_pointer:
|
---|
1008 | printf ("(");
|
---|
1009 | show_type (tp->d.pointer);
|
---|
1010 | printf (")*");
|
---|
1011 | break;
|
---|
1012 | case ty_ref:
|
---|
1013 | printf ("(");
|
---|
1014 | show_type (tp->d.ref);
|
---|
1015 | printf (")&");
|
---|
1016 | break;
|
---|
1017 | case ty_struc:
|
---|
1018 | printf ("{");
|
---|
1019 | show_type (tp->d.struc.types);
|
---|
1020 | printf ("}");
|
---|
1021 | break;
|
---|
1022 | case ty_class:
|
---|
1023 | printf ("{");
|
---|
1024 | if (!fShowClass)
|
---|
1025 | {
|
---|
1026 | fShowClass = 1;
|
---|
1027 | show_type (tp->d.class.members);
|
---|
1028 | fShowClass = 0;
|
---|
1029 | }
|
---|
1030 | else
|
---|
1031 | printf ("<-!-!->");
|
---|
1032 | printf ("}");
|
---|
1033 | break;
|
---|
1034 | case ty_enu:
|
---|
1035 | printf ("{");
|
---|
1036 | show_type (tp->d.enu.values);
|
---|
1037 | printf ("}");
|
---|
1038 | break;
|
---|
1039 | case ty_array:
|
---|
1040 | printf ("(");
|
---|
1041 | show_type (tp->d.array.etype);
|
---|
1042 | printf ("[%ld]", tp->d.array.last + 1 - tp->d.array.first);
|
---|
1043 | break;
|
---|
1044 | case ty_bits:
|
---|
1045 | show_type (tp->d.bits.type);
|
---|
1046 | printf (":%ld:%ld", tp->d.bits.start, tp->d.bits.count);
|
---|
1047 | break;
|
---|
1048 | case ty_func:
|
---|
1049 | show_type (tp->d.func.ret);
|
---|
1050 | printf ("(");
|
---|
1051 | if (tp->d.func.args != NULL)
|
---|
1052 | show_type (tp->d.func.args);
|
---|
1053 | printf (")");
|
---|
1054 | break;
|
---|
1055 | case ty_args:
|
---|
1056 | for (i = 0; i < tp->d.args.count; ++i)
|
---|
1057 | {
|
---|
1058 | if (i != 0)
|
---|
1059 | printf (", ");
|
---|
1060 | show_type (tp->d.args.list[i]);
|
---|
1061 | }
|
---|
1062 | break;
|
---|
1063 | case ty_types:
|
---|
1064 | for (i = 0; i < tp->d.types.count; ++i)
|
---|
1065 | {
|
---|
1066 | if (i != 0)
|
---|
1067 | printf (", ");
|
---|
1068 | show_type (tp->d.types.list[i]);
|
---|
1069 | }
|
---|
1070 | break;
|
---|
1071 | case ty_fields:
|
---|
1072 | for (i = 0; i < tp->d.fields.count; ++i)
|
---|
1073 | {
|
---|
1074 | if (i != 0)
|
---|
1075 | printf (", ");
|
---|
1076 | printf ("%s", tp->d.fields.list[i].name);
|
---|
1077 | }
|
---|
1078 | break;
|
---|
1079 | case ty_member:
|
---|
1080 | printf ("%s", tp->d.member.name);
|
---|
1081 | break;
|
---|
1082 | case ty_values:
|
---|
1083 | for (i = 0; i < tp->d.values.count; ++i)
|
---|
1084 | {
|
---|
1085 | if (i != 0)
|
---|
1086 | printf (", ");
|
---|
1087 | printf ("%s", tp->d.values.list[i].name);
|
---|
1088 | }
|
---|
1089 | break;
|
---|
1090 | case ty_memfunc:
|
---|
1091 | show_type (tp->d.memfunc.type);
|
---|
1092 | break;
|
---|
1093 | case ty_baseclass:
|
---|
1094 | printf ("{");
|
---|
1095 | show_type (tp->d.baseclass.type);
|
---|
1096 | printf ("}");
|
---|
1097 | break;
|
---|
1098 | default:
|
---|
1099 | error ("show_type: Unknown type: %d", tp->tag);
|
---|
1100 | }
|
---|
1101 | }
|
---|
1102 |
|
---|
1103 | #endif
|
---|
1104 |
|
---|
1105 |
|
---|
1106 | /**
|
---|
1107 | * Tries to complete a struct forward reference.
|
---|
1108 | *
|
---|
1109 | * @returns 0 on success
|
---|
1110 | * @returns 1 on failure.
|
---|
1111 | * @param tp Pointer to the struct/class to complete.
|
---|
1112 | * @remark Nasy hack for strstreambuf.
|
---|
1113 | */
|
---|
1114 | static int try_complete_struct(const struct type *tp)
|
---|
1115 | {
|
---|
1116 | int cch;
|
---|
1117 | const char *pszName;
|
---|
1118 | int i;
|
---|
1119 |
|
---|
1120 | if (tp->tag == ty_struc)
|
---|
1121 | return 0;
|
---|
1122 | if (tp->d.struc.flags != STRUC_FORWARD)
|
---|
1123 | return 1;
|
---|
1124 |
|
---|
1125 | pszName = tp->d.struc.name;
|
---|
1126 | cch = strlen(pszName);
|
---|
1127 | for (i = 0; i < sym_count; ++i)
|
---|
1128 | switch (sym_ptr[i].n_type)
|
---|
1129 | {
|
---|
1130 | case N_LSYM:
|
---|
1131 | case N_LCSYM:
|
---|
1132 | case N_GSYM:
|
---|
1133 | case N_PSYM:
|
---|
1134 | case N_RSYM:
|
---|
1135 | case N_STSYM:
|
---|
1136 | case N_FUN:
|
---|
1137 | if ( !memcmp(str_ptr + sym_ptr[i].n_un.n_strx, pszName, cch)
|
---|
1138 | && *(char*)(str_ptr + sym_ptr[i].n_un.n_strx + cch) == ':'
|
---|
1139 | )
|
---|
1140 | {
|
---|
1141 | parse_typedef(&i);
|
---|
1142 | return 1;
|
---|
1143 | } /* if */
|
---|
1144 | } /* switch */
|
---|
1145 |
|
---|
1146 | return 0;
|
---|
1147 | }
|
---|
1148 |
|
---|
1149 |
|
---|
1150 |
|
---|
1151 | /* Return the size of the internal type TP, in bytes. */
|
---|
1152 |
|
---|
1153 | static dword type_size (const struct type *tp)
|
---|
1154 | {
|
---|
1155 | switch (tp->tag)
|
---|
1156 | {
|
---|
1157 | case ty_prim:
|
---|
1158 |
|
---|
1159 | /* Primitive types. */
|
---|
1160 |
|
---|
1161 | if (tp->index >= 0xa0 && tp->index <= 0xbf)
|
---|
1162 | return 4; /* Near pointer */
|
---|
1163 | switch (tp->index)
|
---|
1164 | {
|
---|
1165 | case 0x97: /* void */
|
---|
1166 | return 0;
|
---|
1167 | case 0x80: /* 8 bit signed */
|
---|
1168 | case 0x84: /* 8 bit unsigned */
|
---|
1169 | case 0x90: /* 8 bit boolean */
|
---|
1170 | return 1;
|
---|
1171 | case 0x81: /* 16 bit signed */
|
---|
1172 | case 0x85: /* 16 bit unsigned */
|
---|
1173 | return 2;
|
---|
1174 | case 0x82: /* 32 bit signed */
|
---|
1175 | case 0x86: /* 32 bit unsigned */
|
---|
1176 | case 0x88: /* 32 bit real */
|
---|
1177 | return 4;
|
---|
1178 | case 0x89: /* 64 bit real */
|
---|
1179 | case 0x8c: /* 64 bit complex */
|
---|
1180 | return 8;
|
---|
1181 | case 0x8a: /* 80 bit real (96 bits of storage) */
|
---|
1182 | return 12;
|
---|
1183 | case 0x8d: /* 128 bit complex */
|
---|
1184 | return 16;
|
---|
1185 | case 0x8e: /* 160 bit complex */
|
---|
1186 | return 24;
|
---|
1187 | case 0x8f: /* 256 bit complex (birds invention) */
|
---|
1188 | return 32;
|
---|
1189 | }
|
---|
1190 | error ("type_size: Unknown primitive type: %d", tp->index);
|
---|
1191 |
|
---|
1192 | case ty_stabs_ref:
|
---|
1193 |
|
---|
1194 | #if 0
|
---|
1195 | /* This should not happen. */
|
---|
1196 |
|
---|
1197 | no_warning ("stabs type %d not defined", tp->d.stabs_ref);
|
---|
1198 |
|
---|
1199 | return 4;
|
---|
1200 | #else
|
---|
1201 | /* This seems to happen although it shouldn't... Try do something at least. */
|
---|
1202 |
|
---|
1203 | tp = follow_refs (tp);
|
---|
1204 | if (!tp || tp->tag == ty_stabs_ref)
|
---|
1205 | {
|
---|
1206 | no_warning ("stabs type %d not defined", tp->d.stabs_ref);
|
---|
1207 | return 4;
|
---|
1208 | }
|
---|
1209 | return type_size (tp);
|
---|
1210 | #endif
|
---|
1211 |
|
---|
1212 | case ty_alias:
|
---|
1213 |
|
---|
1214 | /* An alias. Return the size of the referenced type. */
|
---|
1215 |
|
---|
1216 | return type_size (tp->d.alias);
|
---|
1217 |
|
---|
1218 | case ty_pointer:
|
---|
1219 | case ty_ref:
|
---|
1220 |
|
---|
1221 | /* Pointers and references are 32-bit values. */
|
---|
1222 |
|
---|
1223 | return 4;
|
---|
1224 |
|
---|
1225 | case ty_struc:
|
---|
1226 |
|
---|
1227 | /* The size of a structure is stored in the type structure. */
|
---|
1228 |
|
---|
1229 | if ( tp->d.struc.flags & STRUC_FORWARD
|
---|
1230 | && try_complete_struct(tp))
|
---|
1231 | {
|
---|
1232 | no_warning ("size of incomplete structure %s is unknown (off %ld)\n stabs: %s",
|
---|
1233 | tp->d.struc.name, parse_ptr - parse_start, parse_start);
|
---|
1234 | return 0;
|
---|
1235 | }
|
---|
1236 | return tp->d.struc.size;
|
---|
1237 |
|
---|
1238 | case ty_class:
|
---|
1239 |
|
---|
1240 | /* The size of a class is stored in the type structure. */
|
---|
1241 |
|
---|
1242 | return tp->d.class.size;
|
---|
1243 |
|
---|
1244 | case ty_enu:
|
---|
1245 |
|
---|
1246 | /* Return the size of the base type for an enumeration type. */
|
---|
1247 |
|
---|
1248 | return type_size (tp->d.enu.type);
|
---|
1249 |
|
---|
1250 | case ty_array:
|
---|
1251 |
|
---|
1252 | /* Multiply the element size with the number of array elements
|
---|
1253 | for arrays. */
|
---|
1254 |
|
---|
1255 | return ((tp->d.array.last + 1 - tp->d.array.first) *
|
---|
1256 | type_size (tp->d.array.etype));
|
---|
1257 |
|
---|
1258 | case ty_bits:
|
---|
1259 |
|
---|
1260 | /* Use the size of the base type for bitfields. */
|
---|
1261 |
|
---|
1262 | return type_size (tp->d.bits.type);
|
---|
1263 |
|
---|
1264 | case ty_member:
|
---|
1265 |
|
---|
1266 | /* Use the size of the member's type for members. */
|
---|
1267 |
|
---|
1268 | return type_size (tp->d.member.type);
|
---|
1269 |
|
---|
1270 | case ty_baseclass:
|
---|
1271 |
|
---|
1272 | /* The size of a base class is the size of the base class :-) */
|
---|
1273 |
|
---|
1274 | return type_size (tp->d.baseclass.type);
|
---|
1275 |
|
---|
1276 | case ty_func:
|
---|
1277 | case ty_args:
|
---|
1278 | case ty_types:
|
---|
1279 | case ty_fields:
|
---|
1280 | case ty_values:
|
---|
1281 | case ty_memfunc:
|
---|
1282 |
|
---|
1283 | /* This cannot not happen. */
|
---|
1284 |
|
---|
1285 | error ("type_size: cannot compute size for tag %d", tp->tag);
|
---|
1286 |
|
---|
1287 | default:
|
---|
1288 |
|
---|
1289 | /* This cannot happen. */
|
---|
1290 |
|
---|
1291 | error ("type_size: unknown type: %d", tp->tag);
|
---|
1292 | }
|
---|
1293 | }
|
---|
1294 |
|
---|
1295 |
|
---|
1296 | /* Turn a struct into a class. This needs to be done when a struct is
|
---|
1297 | referenced as base class (unfortunately, a simple class looks like
|
---|
1298 | a struct). */
|
---|
1299 |
|
---|
1300 | static void struct_to_class (struct type *tp)
|
---|
1301 | {
|
---|
1302 | struct type t, *t1, **list, **types;
|
---|
1303 | struct field *fields;
|
---|
1304 | int i, n;
|
---|
1305 |
|
---|
1306 | if (tp->index != -1)
|
---|
1307 | {
|
---|
1308 | warning ("Base class cannot be converted from struct");
|
---|
1309 | return;
|
---|
1310 | }
|
---|
1311 | n = tp->d.struc.count;
|
---|
1312 | if (n == 0)
|
---|
1313 | list = NULL;
|
---|
1314 | else
|
---|
1315 | {
|
---|
1316 | if (tp->d.struc.fields->tag != ty_fields
|
---|
1317 | || tp->d.struc.fields->d.fields.count != n)
|
---|
1318 | {
|
---|
1319 | warning ("Invalid struct field list");
|
---|
1320 | return;
|
---|
1321 | }
|
---|
1322 | fields = tp->d.struc.fields->d.fields.list;
|
---|
1323 | if (tp->d.struc.types->tag != ty_types
|
---|
1324 | || tp->d.struc.types->d.types.count != n)
|
---|
1325 | {
|
---|
1326 | warning ("Invalid struct types list");
|
---|
1327 | return;
|
---|
1328 | }
|
---|
1329 | types = tp->d.struc.types->d.types.list;
|
---|
1330 | list = xmalloc (n * sizeof (*list));
|
---|
1331 | for (i = 0; i < n; ++i)
|
---|
1332 | {
|
---|
1333 | t.tag = ty_member;
|
---|
1334 | t.index = -1;
|
---|
1335 | t.d.member.type = types[i];
|
---|
1336 | t.d.member.offset = fields[i].offset;
|
---|
1337 | t.d.member.flags = VIS_PUBLIC;
|
---|
1338 | t.d.member.name = fields[i].name;
|
---|
1339 | t.d.member.sname = NULL;
|
---|
1340 | list[i] = type_add (&t);
|
---|
1341 | }
|
---|
1342 | }
|
---|
1343 |
|
---|
1344 | t.tag = ty_types;
|
---|
1345 | t.index = -1;
|
---|
1346 | t.d.types.count = n;
|
---|
1347 | t.d.types.list = list;
|
---|
1348 | t1 = type_add (&t);
|
---|
1349 | free (list);
|
---|
1350 |
|
---|
1351 | t = *tp;
|
---|
1352 | tp->tag = ty_class;
|
---|
1353 | tp->d.class.members = t1;
|
---|
1354 | tp->d.class.size = t.d.struc.size;
|
---|
1355 | tp->d.class.count = t.d.struc.count;
|
---|
1356 | tp->d.class.name = t.d.struc.name;
|
---|
1357 | }
|
---|
1358 |
|
---|
1359 |
|
---|
1360 | /* Build and return the internal representation of the `long long'
|
---|
1361 | type. As IPMD doesn't know about `long long' we use the following
|
---|
1362 | structure instead:
|
---|
1363 |
|
---|
1364 | struct _long_long
|
---|
1365 | {
|
---|
1366 | unsigned long lo, hi;
|
---|
1367 | };
|
---|
1368 |
|
---|
1369 | This function could be optimized by remembering the type in a
|
---|
1370 | global variable. */
|
---|
1371 |
|
---|
1372 | static struct type *make_long_long (void)
|
---|
1373 | {
|
---|
1374 | struct type t, *t1, *t2, *t3, *types[2];
|
---|
1375 | struct field fields[2];
|
---|
1376 |
|
---|
1377 | /* Let t1 be `unsigned long'. */
|
---|
1378 |
|
---|
1379 | t.tag = ty_prim;
|
---|
1380 | t.index = 0x86; /* 32 bit unsigned */
|
---|
1381 | t1 = type_add (&t);
|
---|
1382 |
|
---|
1383 | /* Let t2 be the field types: unsigned long, unsigned long. */
|
---|
1384 |
|
---|
1385 | types[0] = t1;
|
---|
1386 | types[1] = t1;
|
---|
1387 | t.tag = ty_types;
|
---|
1388 | t.index = -1;
|
---|
1389 | t.d.types.count = 2;
|
---|
1390 | t.d.types.list = types;
|
---|
1391 | t2 = type_add (&t);
|
---|
1392 |
|
---|
1393 | /* Let t3 be the fields: lo (at 0), hi (at 4). */
|
---|
1394 |
|
---|
1395 | fields[0].offset = 0; fields[0].name = strpool_add (str_pool, "lo");
|
---|
1396 | fields[1].offset = 4; fields[1].name = strpool_add (str_pool, "hi");
|
---|
1397 | t.tag = ty_fields;
|
---|
1398 | t.index = -1;
|
---|
1399 | t.d.fields.count = 2;
|
---|
1400 | t.d.fields.list = fields;
|
---|
1401 | t3 = type_add (&t);
|
---|
1402 |
|
---|
1403 | /* Build the structure type from t1, t2 and t3. */
|
---|
1404 |
|
---|
1405 | t.tag = ty_struc;
|
---|
1406 | t.d.struc.count = 2;
|
---|
1407 | t.d.struc.size = 8;
|
---|
1408 | t.d.struc.types = t2;
|
---|
1409 | t.d.struc.fields = t3;
|
---|
1410 | t.d.struc.name = strpool_add (str_pool, "_long_long");
|
---|
1411 | t.d.struc.flags = 0;
|
---|
1412 | return type_add (&t);
|
---|
1413 | }
|
---|
1414 |
|
---|
1415 |
|
---|
1416 | /* Parse a (signed) long long number in a stabs type. The number is
|
---|
1417 | given in octal or decimal notation. The result is stored to
|
---|
1418 | *NUMBER. This function returns TRUE iff successful. We don't
|
---|
1419 | check for overflow. */
|
---|
1420 |
|
---|
1421 | static int parse_long_long (long long *number)
|
---|
1422 | {
|
---|
1423 | long long n;
|
---|
1424 | int neg, base;
|
---|
1425 |
|
---|
1426 | n = 0; neg = FALSE; base = 10;
|
---|
1427 | if (*parse_ptr == '-')
|
---|
1428 | {
|
---|
1429 | neg = TRUE;
|
---|
1430 | ++parse_ptr;
|
---|
1431 | }
|
---|
1432 | if (*parse_ptr == '0')
|
---|
1433 | base = 8;
|
---|
1434 | if (!(*parse_ptr >= '0' && *parse_ptr < base + '0'))
|
---|
1435 | {
|
---|
1436 | *number = 0;
|
---|
1437 | return FALSE;
|
---|
1438 | }
|
---|
1439 | while (*parse_ptr >= '0' && *parse_ptr < base + '0')
|
---|
1440 | {
|
---|
1441 | n = n * base + (*parse_ptr - '0');
|
---|
1442 | ++parse_ptr;
|
---|
1443 | }
|
---|
1444 | *number = (neg ? -n : n);
|
---|
1445 | return TRUE;
|
---|
1446 | }
|
---|
1447 |
|
---|
1448 |
|
---|
1449 | /* Parse a (signed) number in a stabs type. The number is given in
|
---|
1450 | octal or decimal notation. The result is stored to *NUMBER. This
|
---|
1451 | function returns TRUE iff successful. We don't check for
|
---|
1452 | overflow. */
|
---|
1453 |
|
---|
1454 | static int parse_number (long *number)
|
---|
1455 | {
|
---|
1456 | long long n;
|
---|
1457 | int result;
|
---|
1458 |
|
---|
1459 | result = parse_long_long (&n);
|
---|
1460 | *number = (long)n;
|
---|
1461 | return result;
|
---|
1462 | }
|
---|
1463 |
|
---|
1464 |
|
---|
1465 | /* Check the next character in a stabs type for C. If the next
|
---|
1466 | character matches C, the character is skipped and TRUE is
|
---|
1467 | returned. Otherwise, a warning message is displayed and FALSE is
|
---|
1468 | returned. */
|
---|
1469 |
|
---|
1470 | static int parse_char (char c)
|
---|
1471 | {
|
---|
1472 | if (*parse_ptr != c)
|
---|
1473 | {
|
---|
1474 | no_warning ("Invalid symbol data: `%c' expected, found '%c' (off %ld)\n stabs: %s",
|
---|
1475 | c, *parse_ptr, parse_ptr - parse_start, parse_start);
|
---|
1476 | return FALSE;
|
---|
1477 | }
|
---|
1478 | ++parse_ptr;
|
---|
1479 | return TRUE;
|
---|
1480 | }
|
---|
1481 |
|
---|
1482 |
|
---|
1483 | /* Parse mangled arguments of a member functions. For instance, ic
|
---|
1484 | means an `int' argument and a `char' argument. Return FALSE on
|
---|
1485 | failure. */
|
---|
1486 |
|
---|
1487 | static int parse_mangled_args (void)
|
---|
1488 | {
|
---|
1489 | while (*parse_ptr != ';')
|
---|
1490 | {
|
---|
1491 | switch (*parse_ptr)
|
---|
1492 | {
|
---|
1493 | case 0:
|
---|
1494 | warning ("Missing semicolon after mangled arguments");
|
---|
1495 | return FALSE;
|
---|
1496 | default:
|
---|
1497 | /* TODO */
|
---|
1498 | break;
|
---|
1499 | }
|
---|
1500 | ++parse_ptr;
|
---|
1501 | }
|
---|
1502 | ++parse_ptr; /* Skip semicolon */
|
---|
1503 | return TRUE;
|
---|
1504 | }
|
---|
1505 |
|
---|
1506 |
|
---|
1507 | /* Parse the visibility of a class or member. */
|
---|
1508 |
|
---|
1509 | static int parse_visibility (void)
|
---|
1510 | {
|
---|
1511 | switch (*parse_ptr)
|
---|
1512 | {
|
---|
1513 | case '0':
|
---|
1514 | ++parse_ptr;
|
---|
1515 | return VIS_PRIVATE;
|
---|
1516 | case '1':
|
---|
1517 | ++parse_ptr;
|
---|
1518 | return VIS_PROTECTED;
|
---|
1519 | case '2':
|
---|
1520 | ++parse_ptr;
|
---|
1521 | return VIS_PUBLIC;
|
---|
1522 | default:
|
---|
1523 | ++parse_ptr;
|
---|
1524 | no_warning ("Invalid visibility: %c", *parse_ptr);
|
---|
1525 | if (*parse_ptr != 0)
|
---|
1526 | ++parse_ptr;
|
---|
1527 | return VIS_PUBLIC;
|
---|
1528 | }
|
---|
1529 | }
|
---|
1530 |
|
---|
1531 |
|
---|
1532 | /* Add TYPE_NAME to `str_pool', replacing a NULL string with a unique
|
---|
1533 | string. */
|
---|
1534 |
|
---|
1535 | static const char *add_struct_name (const char *type_name)
|
---|
1536 | {
|
---|
1537 | char tmp[32];
|
---|
1538 |
|
---|
1539 | /* Some names have only spaces for gdb safety, let's make an
|
---|
1540 | fake name for those. */
|
---|
1541 | if (type_name != NULL)
|
---|
1542 | {
|
---|
1543 | const char *psz = type_name;
|
---|
1544 | while (*psz == ' ' || *psz == '\t')
|
---|
1545 | psz++;
|
---|
1546 | if (!*psz)
|
---|
1547 | type_name = NULL;
|
---|
1548 | }
|
---|
1549 |
|
---|
1550 | if (type_name == NULL)
|
---|
1551 | {
|
---|
1552 | sprintf (tmp, "__%d", unnamed_struct_number++);
|
---|
1553 | type_name = tmp;
|
---|
1554 | }
|
---|
1555 | return strpool_add (str_pool, type_name);
|
---|
1556 | }
|
---|
1557 |
|
---|
1558 | /**
|
---|
1559 | * Finds the next colon in the string and returns pointer to it.
|
---|
1560 | * For C++ template support, colons within <> are not considered.
|
---|
1561 | *
|
---|
1562 | * @returns Pointer to next colon within psz.
|
---|
1563 | * @returns NULL if not found.
|
---|
1564 | * @param pszString String to search.
|
---|
1565 | * @param chType Type we're parsing. Use '\0' if unknown or it
|
---|
1566 | * should be ignored
|
---|
1567 | * @remark Still a bad hack this.
|
---|
1568 | */
|
---|
1569 | #ifdef COLON_DEBUG
|
---|
1570 | static const char *nextcolon2(const char *pszString, char chType)
|
---|
1571 | {
|
---|
1572 | static const char *_nextcolon2(const char *pszString, char chType);
|
---|
1573 | const char *psz = _nextcolon2(pszString, chType);
|
---|
1574 | fprintf(stderr, "COLON: %.100s\n%.32s\n", pszString, psz);
|
---|
1575 | return psz;
|
---|
1576 | }
|
---|
1577 | static const char *_nextcolon2(const char *pszString, char chType)
|
---|
1578 | #else
|
---|
1579 | static const char *nextcolon2(const char *pszString, char chType)
|
---|
1580 | #endif
|
---|
1581 | {
|
---|
1582 | const char *pszColon;
|
---|
1583 | const char *psz;
|
---|
1584 |
|
---|
1585 | /* permanent operator hack */
|
---|
1586 | if ( pszString[0] == 'o'
|
---|
1587 | && pszString[1] == 'p'
|
---|
1588 | && pszString[2] == 'e'
|
---|
1589 | && pszString[3] == 'r'
|
---|
1590 | && pszString[4] == 'a'
|
---|
1591 | && pszString[5] == 't'
|
---|
1592 | && pszString[6] == 'o'
|
---|
1593 | && pszString[7] == 'r')
|
---|
1594 | {
|
---|
1595 | psz = pszString + 8;
|
---|
1596 | while (*psz && !isalnum(*psz) && *psz != '_') /* potential operator chars */
|
---|
1597 | {
|
---|
1598 | if (*psz == ':')
|
---|
1599 | {
|
---|
1600 | if ( psz - pszString >= 1 + 8
|
---|
1601 | && psz - pszString <= 3 + 8)
|
---|
1602 | return psz;
|
---|
1603 | break;
|
---|
1604 | }
|
---|
1605 | psz++;
|
---|
1606 | }
|
---|
1607 |
|
---|
1608 | }
|
---|
1609 |
|
---|
1610 | /* normal life */
|
---|
1611 | pszColon = strchr(pszString, ':');
|
---|
1612 | if (!pszColon)
|
---|
1613 | return NULL;
|
---|
1614 | psz = strchr(pszString, '<');
|
---|
1615 |
|
---|
1616 | if (psz && psz < pszColon && pszColon[1] == ':')
|
---|
1617 | {
|
---|
1618 | int cNesting = 0; /* <> level */
|
---|
1619 |
|
---|
1620 | for (;;psz++)
|
---|
1621 | {
|
---|
1622 | switch (*psz)
|
---|
1623 | {
|
---|
1624 | case '<': cNesting++; break;
|
---|
1625 | case '>': cNesting--; break;
|
---|
1626 | case ':':
|
---|
1627 | if (cNesting > 0)
|
---|
1628 | break;
|
---|
1629 | /* hack: continue on ">::" (but not on "operator...") */
|
---|
1630 | if ( chType != 'x'
|
---|
1631 | && psz[1] == ':'
|
---|
1632 | && psz > pszString && psz[-1] == '>'
|
---|
1633 | )
|
---|
1634 | {
|
---|
1635 | psz++;
|
---|
1636 | break;
|
---|
1637 | }
|
---|
1638 | return psz;
|
---|
1639 | case '\0':
|
---|
1640 | return NULL;
|
---|
1641 | }
|
---|
1642 | }
|
---|
1643 | }
|
---|
1644 | else
|
---|
1645 | {
|
---|
1646 | if (chType != 'x')
|
---|
1647 | {
|
---|
1648 | /* skip '::' (hack:) if not followed by number. */
|
---|
1649 | while (*pszColon && pszColon[1] == ':' && (pszColon[2] > '9' || pszColon[2] < '0'))
|
---|
1650 | {
|
---|
1651 | pszColon += 2;
|
---|
1652 | while (*pszColon != ':' && *pszColon)
|
---|
1653 | pszColon++;
|
---|
1654 | }
|
---|
1655 | }
|
---|
1656 | }
|
---|
1657 |
|
---|
1658 | return pszColon;
|
---|
1659 | }
|
---|
1660 |
|
---|
1661 | /* old version */
|
---|
1662 | static inline const char *nextcolon(const char *pszString)
|
---|
1663 | {
|
---|
1664 | return nextcolon2(pszString, '\0');
|
---|
1665 | }
|
---|
1666 |
|
---|
1667 |
|
---|
1668 |
|
---|
1669 | /* Parse a stabs type (which is named TYPE_NAME; TYPE_NAME is NULL for
|
---|
1670 | an unnamed type) and return the internal representation of that
|
---|
1671 | type. */
|
---|
1672 |
|
---|
1673 | static struct type *parse_type (const char *type_name)
|
---|
1674 | {
|
---|
1675 | const char *saved_ptr, *p1;
|
---|
1676 | char ch;
|
---|
1677 | struct type t, *result, *t1, *t2, *t3, **tlist;
|
---|
1678 | int i, n, class_flag, is_void;
|
---|
1679 | long num1, num2, size, lo, hi, valid, offset, width, code;
|
---|
1680 | long long range_lo, range_hi;
|
---|
1681 | struct tmp_field *tmp_fields, *tf;
|
---|
1682 | struct value *tmp_values, *tv;
|
---|
1683 | struct grow g1 = GROW_INIT;
|
---|
1684 | enum type_tag tt;
|
---|
1685 |
|
---|
1686 | valid = TRUE; result = NULL;
|
---|
1687 | t.index = -1;
|
---|
1688 | switch (*parse_ptr)
|
---|
1689 | {
|
---|
1690 | case '0': case '1': case '2': case '3': case '4':
|
---|
1691 | case '5': case '6': case '7': case '8': case '9':
|
---|
1692 | if (!parse_number (&num1))
|
---|
1693 | goto syntax;
|
---|
1694 |
|
---|
1695 | /* Special case: self reference => void */
|
---|
1696 | is_void = FALSE;
|
---|
1697 | if (*parse_ptr == '=' && parse_ptr[1] >= '0' && parse_ptr[1] <= '9')
|
---|
1698 | {
|
---|
1699 | saved_ptr = parse_ptr++;
|
---|
1700 | if (!parse_number (&num2))
|
---|
1701 | goto syntax;
|
---|
1702 | if (num2 == num1)
|
---|
1703 | is_void = TRUE;
|
---|
1704 | else
|
---|
1705 | parse_ptr = saved_ptr;
|
---|
1706 | }
|
---|
1707 | if (is_void)
|
---|
1708 | {
|
---|
1709 | t.tag = ty_prim;
|
---|
1710 | t.index = 0x97; /* void */
|
---|
1711 | result = type_add (&t);
|
---|
1712 | stype_add (num1, result);
|
---|
1713 | }
|
---|
1714 | else if (*parse_ptr == '=')
|
---|
1715 | {
|
---|
1716 | /* Nested definition */
|
---|
1717 | ++parse_ptr;
|
---|
1718 | result = parse_type (type_name);
|
---|
1719 | stype_add (num1, result);
|
---|
1720 | }
|
---|
1721 | else
|
---|
1722 | {
|
---|
1723 | result = stype_find (num1);
|
---|
1724 | if (result == NULL)
|
---|
1725 | {
|
---|
1726 | t.tag = ty_stabs_ref;
|
---|
1727 | t.d.stabs_ref = num1;
|
---|
1728 | }
|
---|
1729 | }
|
---|
1730 | break;
|
---|
1731 |
|
---|
1732 | case 'r':
|
---|
1733 |
|
---|
1734 | /* A range type: r<base_type>;<lower_bound>;<upper_bound>;
|
---|
1735 |
|
---|
1736 | Special cases:
|
---|
1737 |
|
---|
1738 | lower_bound | upper_bound | type
|
---|
1739 | ------------+-------------+------------------------
|
---|
1740 | n > 0 | 0 | floating point, n bytes
|
---|
1741 |
|
---|
1742 | */
|
---|
1743 |
|
---|
1744 | ++parse_ptr;
|
---|
1745 | if (!parse_number (&num1) || !parse_char (';')
|
---|
1746 | || !parse_long_long (&range_lo) || !parse_char (';')
|
---|
1747 | || !parse_long_long (&range_hi) || !parse_char (';'))
|
---|
1748 | goto syntax;
|
---|
1749 | t.tag = ty_prim;
|
---|
1750 | if (range_lo == -128 && range_hi == 127)
|
---|
1751 | t.index = 0x80; /* 8 bit signed */
|
---|
1752 | else if (range_lo == -32768 && range_hi == 32767)
|
---|
1753 | t.index = 0x81; /* 16 bit signed */
|
---|
1754 | else if (range_lo == -2147483647 - 1 && range_hi == 2147483647)
|
---|
1755 | t.index = 0x82; /* 32 bit signed */
|
---|
1756 | else if (range_lo == 0 && range_hi == 127)
|
---|
1757 | t.index = 0x84; /* 8 bit character */
|
---|
1758 | else if (range_lo == 0 && range_hi == 255)
|
---|
1759 | t.index = 0x84; /* 8 bit unsigned */
|
---|
1760 | else if (range_lo == 0 && range_hi == 65535)
|
---|
1761 | t.index = 0x85; /* 16 bit unsigned */
|
---|
1762 | else if (range_lo == 0 && range_hi == 0xffffffff)
|
---|
1763 | t.index = 0x86; /* 32 bit unsigned */
|
---|
1764 | else if (range_lo == 0 && range_hi == -1)
|
---|
1765 | {
|
---|
1766 | if (type_name != NULL
|
---|
1767 | && (strcmp (type_name, "long long unsigned int") == 0
|
---|
1768 | || strcmp (type_name, "long long int") == 0))
|
---|
1769 | result = make_long_long ();
|
---|
1770 | else
|
---|
1771 | t.index = 0x86; /* 32 bit unsigned */
|
---|
1772 | }
|
---|
1773 | else if ((unsigned long long)range_lo == 0x8000000000000000ULL
|
---|
1774 | && range_hi == 0x7fffffffffffffffLL)
|
---|
1775 | result = make_long_long ();
|
---|
1776 | else if (range_lo == 4 && range_hi == 0)
|
---|
1777 | t.index = 0x88; /* 32 bit real */
|
---|
1778 | else if (range_lo == 8 && range_hi == 0)
|
---|
1779 | t.index = 0x89; /* 64 bit real */
|
---|
1780 | else if (range_lo == 12 && range_hi == 0)
|
---|
1781 | t.index = 0x8a; /* 80 bit real */
|
---|
1782 | else
|
---|
1783 | {
|
---|
1784 | no_warning ("Unknown range type: %lld..%lld", range_lo, range_hi);
|
---|
1785 | goto syntax;
|
---|
1786 | }
|
---|
1787 | break;
|
---|
1788 |
|
---|
1789 | case 'R':
|
---|
1790 |
|
---|
1791 | /* Complex number: R<?base_type?>;<size bytes>;<0>; */
|
---|
1792 |
|
---|
1793 | ++parse_ptr;
|
---|
1794 | if (!parse_number (&num1) || !parse_char (';')
|
---|
1795 | || !parse_number (&width) || !parse_char (';')
|
---|
1796 | || !parse_number (&code) || !parse_char (';'))
|
---|
1797 | goto syntax;
|
---|
1798 |
|
---|
1799 | /*
|
---|
1800 | * The 192bit type is not defined in the HLL specs, but we assume it for
|
---|
1801 | * convenince right now.
|
---|
1802 | *
|
---|
1803 | * It seems like no debugger acutally supports these types. So, we should,
|
---|
1804 | * when somebody requires it for debugging complex math, make structs out
|
---|
1805 | * of these declarations like GCC does for the 'complex int' type.
|
---|
1806 | *
|
---|
1807 | * .stabs "FakeComplexInt:t21=22=s8real:1,0,32;imag:1,32,32;;",128,0,0,0
|
---|
1808 | * .stabs "FakeComplexFloat:t23=24=s8real:12,0,32;imag:12,32,32;;",128,0,0,0
|
---|
1809 | * .stabs "FakeComplexDouble:t25=26=s16real:13,0,64;imag:13,64,64;;",128,0,0,0
|
---|
1810 | * .stabs "FakeComplexLongDouble:t27=28=s24real:14,0,96;imag:14,96,96;;",128,0,0,0
|
---|
1811 | *
|
---|
1812 | */
|
---|
1813 | t.tag = ty_prim;
|
---|
1814 | if (width == 8 && code == 0)
|
---|
1815 | t.index = 0x8c;
|
---|
1816 | else if (width == 16 && code == 0)
|
---|
1817 | t.index = 0x8d ;
|
---|
1818 | else if (width == 20 && code == 0)
|
---|
1819 | t.index = 0x8e;
|
---|
1820 | else if (width == 24 && code == 0)
|
---|
1821 | t.index = 0x8f; //TODO: bogus!!!
|
---|
1822 | else
|
---|
1823 | {
|
---|
1824 | no_warning ("Unknown complex type: %ld/%ld", width, code);
|
---|
1825 | goto syntax;
|
---|
1826 | }
|
---|
1827 | break;
|
---|
1828 |
|
---|
1829 | case '*':
|
---|
1830 |
|
---|
1831 | /* A pointer type: *<type> */
|
---|
1832 |
|
---|
1833 | ++parse_ptr;
|
---|
1834 | t1 = parse_type (NULL);
|
---|
1835 | t.tag = ty_pointer;
|
---|
1836 | t.d.pointer = t1;
|
---|
1837 | break;
|
---|
1838 |
|
---|
1839 | case 'k':
|
---|
1840 |
|
---|
1841 | /* A const type: k<type>
|
---|
1842 | HLL don't have const typedefs afaik, so we just make it an alias. */
|
---|
1843 |
|
---|
1844 | ++parse_ptr;
|
---|
1845 | t1 = parse_type (NULL);
|
---|
1846 | t.tag = ty_alias;
|
---|
1847 | t.d.alias = t1;
|
---|
1848 | break;
|
---|
1849 |
|
---|
1850 | case 'B':
|
---|
1851 |
|
---|
1852 | /* A volatile type: B<type>
|
---|
1853 | This is a SUN extension, and right now we don't care to generate
|
---|
1854 | specific HLL for it and stick with an alias. */
|
---|
1855 |
|
---|
1856 | ++parse_ptr;
|
---|
1857 | t1 = parse_type (NULL);
|
---|
1858 | t.tag = ty_alias;
|
---|
1859 | t.d.alias = t1;
|
---|
1860 | break;
|
---|
1861 |
|
---|
1862 |
|
---|
1863 | case '&':
|
---|
1864 |
|
---|
1865 | /* A reference type (C++): &<type> */
|
---|
1866 |
|
---|
1867 | ++parse_ptr;
|
---|
1868 | t1 = parse_type (NULL);
|
---|
1869 | t.tag = ty_ref;
|
---|
1870 | t.d.ref = t1;
|
---|
1871 | break;
|
---|
1872 |
|
---|
1873 | case '#':
|
---|
1874 |
|
---|
1875 | /* A member function:
|
---|
1876 |
|
---|
1877 | short format: ##<return_type>;
|
---|
1878 |
|
---|
1879 | long format: #<domain_type>,<return_type>{,<arg_type>};
|
---|
1880 |
|
---|
1881 | */
|
---|
1882 |
|
---|
1883 | ++parse_ptr;
|
---|
1884 | args_grow.count = 0; /* ASSUMES we can safely use args_grow/args_list. */
|
---|
1885 | t2 = NULL; /* t2=Domain type; t1=Return type; */
|
---|
1886 | if (*parse_ptr == '#')
|
---|
1887 | {
|
---|
1888 | ++parse_ptr;
|
---|
1889 | t1 = parse_type (NULL);
|
---|
1890 | if (!parse_char (';'))
|
---|
1891 | goto syntax;
|
---|
1892 | no_warning ("We don't understand '##' methods.");
|
---|
1893 | }
|
---|
1894 | else
|
---|
1895 | {
|
---|
1896 | t2 = parse_type (NULL); /* Domain type */
|
---|
1897 | if (!parse_char (','))
|
---|
1898 | goto syntax;
|
---|
1899 | t1 = parse_type (NULL); /* Return type */
|
---|
1900 | /* Arguments */
|
---|
1901 | while (*parse_ptr != ';')
|
---|
1902 | {
|
---|
1903 | if (!parse_char (','))
|
---|
1904 | goto syntax;
|
---|
1905 | grow_by (&args_grow, 1);
|
---|
1906 | args_list[args_grow.count++] = parse_type (NULL); /* Argument type */
|
---|
1907 | }
|
---|
1908 | ++parse_ptr;
|
---|
1909 | }
|
---|
1910 |
|
---|
1911 | t3 = NULL;
|
---|
1912 | #if 0 /* this doesn't really seems to be required, but can just as well leave it in. */
|
---|
1913 | if (args_grow.count)
|
---|
1914 | {
|
---|
1915 | t.tag = ty_args;
|
---|
1916 | t.index = -1;
|
---|
1917 | t.d.args.count = args_grow.count;
|
---|
1918 | t.d.args.list = xmalloc (args_grow.count * sizeof (*args_list));
|
---|
1919 | memcpy (t.d.args.list, args_list, args_grow.count * sizeof (*args_list));
|
---|
1920 | t3 = type_add (&t);
|
---|
1921 | free (t.d.args.list);
|
---|
1922 | }
|
---|
1923 | #endif
|
---|
1924 |
|
---|
1925 | /* Make a function type from the return type t1 */
|
---|
1926 | t.tag = ty_func;
|
---|
1927 | t.d.func.ret = t1;
|
---|
1928 | t.d.func.domain = t2;
|
---|
1929 | t.d.func.args = t3;
|
---|
1930 | t.d.func.arg_count = args_grow.count;
|
---|
1931 | args_grow.count = 0;
|
---|
1932 | t1 = type_add(&t);
|
---|
1933 |
|
---|
1934 | break;
|
---|
1935 |
|
---|
1936 | case '@':
|
---|
1937 |
|
---|
1938 | /* Special GNU-defined types:
|
---|
1939 |
|
---|
1940 | @s<bits>;<code>;
|
---|
1941 |
|
---|
1942 | BITS: Number of bits
|
---|
1943 | CODE: Identifies the type:
|
---|
1944 | -16 bool
|
---|
1945 | -20 char
|
---|
1946 |
|
---|
1947 | @s<bits>;<range record>
|
---|
1948 | Used for 64 bit ints.
|
---|
1949 |
|
---|
1950 | @s<bits>;<num records>
|
---|
1951 | Used for non-standard enums.
|
---|
1952 |
|
---|
1953 | @<basetype>,<membertype>
|
---|
1954 | Used for addressing class/struct/union members.
|
---|
1955 | */
|
---|
1956 |
|
---|
1957 | ++parse_ptr;
|
---|
1958 | switch (*parse_ptr)
|
---|
1959 | {
|
---|
1960 | case 's':
|
---|
1961 | ++parse_ptr;
|
---|
1962 | if (!parse_number (&size) || !parse_char (';'))
|
---|
1963 | goto syntax;
|
---|
1964 | if (*parse_ptr == 'r')
|
---|
1965 | { /* nested */
|
---|
1966 | return parse_type(type_name);
|
---|
1967 | }
|
---|
1968 | if (*parse_ptr == 'e')
|
---|
1969 | goto l_parse_enum;
|
---|
1970 |
|
---|
1971 | if (!parse_number (&code))
|
---|
1972 | goto syntax;
|
---|
1973 | if (size == 8 && code == -16)
|
---|
1974 | {
|
---|
1975 | #if 0 /* debugger doesn't understand this game */
|
---|
1976 | t.tag = ty_prim;
|
---|
1977 | t.index = 0x90; /* 8 bit boolean */
|
---|
1978 | #else
|
---|
1979 | t.tag = ty_values;
|
---|
1980 | t.d.values.count = 2;
|
---|
1981 | t.d.values.list = xmalloc (2 * sizeof (*t.d.values.list));
|
---|
1982 | t.d.values.list[0].index = 0;
|
---|
1983 | t.d.values.list[0].name = strpool_add (str_pool, "false");
|
---|
1984 | t.d.values.list[1].index = 1;
|
---|
1985 | t.d.values.list[1].name = strpool_add (str_pool, "true");
|
---|
1986 | t1 = type_add (&t);
|
---|
1987 | free (t.d.values.list);
|
---|
1988 |
|
---|
1989 | t.tag = ty_prim;
|
---|
1990 | t.index = 0x80;
|
---|
1991 | t2 = type_add (&t);
|
---|
1992 |
|
---|
1993 | t.tag = ty_enu;
|
---|
1994 | t.index = -1;
|
---|
1995 | t.d.enu.values = t1;
|
---|
1996 | t.d.enu.type = t2;
|
---|
1997 | t.d.enu.name = add_struct_name (NULL);
|
---|
1998 | t.d.enu.first = 0;
|
---|
1999 | t.d.enu.last = 1;
|
---|
2000 | #endif
|
---|
2001 | }
|
---|
2002 | else
|
---|
2003 | {
|
---|
2004 | warning ("Unknown GNU extension type code: %ld, %ld bits",
|
---|
2005 | code, size);
|
---|
2006 | goto syntax;
|
---|
2007 | }
|
---|
2008 | if (!parse_char (';'))
|
---|
2009 | goto syntax;
|
---|
2010 | break;
|
---|
2011 |
|
---|
2012 | case '0': case '1': case '2': case '3': case '4':
|
---|
2013 | case '5': case '6': case '7': case '8': case '9':
|
---|
2014 | {
|
---|
2015 | /* just make it an integer - see dbxout.c OFFSET_TYPE case. */
|
---|
2016 | if ( parse_number (&num1)
|
---|
2017 | && *parse_ptr == ','
|
---|
2018 | && ++parse_ptr
|
---|
2019 | && parse_number (&num2)
|
---|
2020 | )
|
---|
2021 | {
|
---|
2022 | t.tag = ty_prim;
|
---|
2023 | t.index = 0x82; /* 32 bit signed */
|
---|
2024 | }
|
---|
2025 | else
|
---|
2026 | {
|
---|
2027 | warning_parse ("Invalid BASE_OFFSET GNU extension format!");
|
---|
2028 | goto syntax;
|
---|
2029 | }
|
---|
2030 | break;
|
---|
2031 | }
|
---|
2032 |
|
---|
2033 | default:
|
---|
2034 | warning ("Unknown GNU extension type: @%c", *parse_ptr);
|
---|
2035 | goto syntax;
|
---|
2036 | }
|
---|
2037 | break;
|
---|
2038 |
|
---|
2039 | case 'x':
|
---|
2040 |
|
---|
2041 | /* Incomplete type: xs<name>:
|
---|
2042 | xu<name>:
|
---|
2043 | xe<name>: */
|
---|
2044 |
|
---|
2045 | ++parse_ptr;
|
---|
2046 | ch = *parse_ptr++;
|
---|
2047 | p1 = nextcolon2 (parse_ptr, 'x');
|
---|
2048 | if (p1 == NULL)
|
---|
2049 | {
|
---|
2050 | warning ("Invalid forward reference: missing colon");
|
---|
2051 | goto syntax;
|
---|
2052 | }
|
---|
2053 |
|
---|
2054 | switch (ch)
|
---|
2055 | {
|
---|
2056 | case 's':
|
---|
2057 | case 'u':
|
---|
2058 | {
|
---|
2059 | /* make a fake structure. */
|
---|
2060 | t.tag = ty_prim;
|
---|
2061 | t.index = 0x80;
|
---|
2062 | tlist = xmalloc (1 * sizeof (*t.d.types.list));
|
---|
2063 | tlist[0] = type_add (&t);
|
---|
2064 | t.tag = ty_types;
|
---|
2065 | t.index = -1;
|
---|
2066 | t.d.types.count = 1;
|
---|
2067 | t.d.types.list = tlist;
|
---|
2068 | t1 = type_add (&t);
|
---|
2069 | free (tlist);
|
---|
2070 |
|
---|
2071 | t.tag = ty_fields;
|
---|
2072 | t.index = -1;
|
---|
2073 | t.d.fields.count = 1;
|
---|
2074 | t.d.fields.list = xmalloc (1 * sizeof (*t.d.fields.list));
|
---|
2075 | t.d.fields.list[0].offset = 0;
|
---|
2076 | t.d.fields.list[0].name = strpool_add (str_pool, "This_Is_an_Incomplete_Structure_SORRY");
|
---|
2077 | t2 = type_add (&t);
|
---|
2078 | free (t.d.fields.list);
|
---|
2079 |
|
---|
2080 | t.tag = ty_struc;
|
---|
2081 | t.index = -1;
|
---|
2082 | t.d.struc.types = t1;
|
---|
2083 | t.d.struc.fields = t2;
|
---|
2084 | t.d.struc.size = 1;
|
---|
2085 | t.d.struc.count = 1;
|
---|
2086 | t.d.struc.name = strpool_addn (str_pool, parse_ptr, p1 - parse_ptr);
|
---|
2087 | t.d.struc.flags = STRUC_FORWARD;
|
---|
2088 |
|
---|
2089 | /* Avoid adding an incomplete type if the complete one is
|
---|
2090 | already defined. We're ignoring scoping (TODO). */
|
---|
2091 |
|
---|
2092 | for (t3 = type_head; t3 != NULL; t3 = t3->next)
|
---|
2093 | if ((t3->tag == ty_struc && t3->d.struc.name == t.d.struc.name
|
---|
2094 | && !(t3->d.struc.flags & STRUC_FORWARD))
|
---|
2095 | || (t3->tag == ty_class && t3->d.class.name == t.d.struc.name))
|
---|
2096 | {
|
---|
2097 | result = t3;
|
---|
2098 | break;
|
---|
2099 | }
|
---|
2100 | break;
|
---|
2101 | }
|
---|
2102 |
|
---|
2103 | case 'e':
|
---|
2104 | { /* just make it a primary. */
|
---|
2105 | /** @todo make an enum perhaps? */
|
---|
2106 | t.tag = ty_prim;
|
---|
2107 | t.index = 0x82; /* 32 bit signed */
|
---|
2108 | break;
|
---|
2109 | }
|
---|
2110 |
|
---|
2111 | default:
|
---|
2112 | warning ("Unknown forward reference: %c", ch);
|
---|
2113 | parse_ptr = p1 + 1;
|
---|
2114 | goto syntax;
|
---|
2115 | }
|
---|
2116 | parse_ptr = p1 + 1;
|
---|
2117 | break;
|
---|
2118 |
|
---|
2119 | case 's': /* struct, class */
|
---|
2120 | case 'u': /* union */
|
---|
2121 |
|
---|
2122 | /* Structures, unions and classes:
|
---|
2123 |
|
---|
2124 | s<size>[<baseclasses>]{<field>}{<method>}
|
---|
2125 |
|
---|
2126 | BASECLASSES: !<#baseclasses>,{<baseclass>;}
|
---|
2127 | BASECLASS: <virtuality><visibility><offset>,<type>
|
---|
2128 | FIELD: <name>:[/0|1|2]<type>,<offset>,<width>;
|
---|
2129 | FIELD: <name>:[/0|1|2]<type>:<static_name>;
|
---|
2130 | METHOD: <name>::{<type>:<args>};
|
---|
2131 |
|
---|
2132 | */
|
---|
2133 |
|
---|
2134 | ++parse_ptr;
|
---|
2135 | class_flag = FALSE;
|
---|
2136 | if (!parse_number (&size))
|
---|
2137 | goto syntax;
|
---|
2138 | grow_init (&g1, &tmp_fields, sizeof (*tmp_fields), 8);
|
---|
2139 |
|
---|
2140 | /* Parse the base classes, if present. */
|
---|
2141 |
|
---|
2142 | if (*parse_ptr == '!')
|
---|
2143 | {
|
---|
2144 | long i, n;
|
---|
2145 |
|
---|
2146 | ++parse_ptr;
|
---|
2147 | class_flag = TRUE;
|
---|
2148 | if (!parse_number (&n) || !parse_char (','))
|
---|
2149 | goto syntax;
|
---|
2150 | for (i = 0; i < n; ++i)
|
---|
2151 | {
|
---|
2152 | grow_by (&g1, 1);
|
---|
2153 | tf = &tmp_fields[g1.count++];
|
---|
2154 | tf->flags = MEMBER_BASE;
|
---|
2155 | tf->name = NULL;
|
---|
2156 | tf->sname = NULL;
|
---|
2157 | switch (*parse_ptr)
|
---|
2158 | {
|
---|
2159 | case '0':
|
---|
2160 | ++parse_ptr;
|
---|
2161 | break;
|
---|
2162 | case '1':
|
---|
2163 | tf->flags |= MEMBER_VIRTUAL;
|
---|
2164 | ++parse_ptr;
|
---|
2165 | break;
|
---|
2166 | default:
|
---|
2167 | warning ("Invalid base class visibility: %c", *parse_ptr);
|
---|
2168 | if (*parse_ptr != 0)
|
---|
2169 | ++parse_ptr;
|
---|
2170 | }
|
---|
2171 |
|
---|
2172 | tf->flags |= parse_visibility ();
|
---|
2173 | if (!parse_number (&offset) || !parse_char (','))
|
---|
2174 | goto syntax;
|
---|
2175 | tf->offset = offset >> 3;
|
---|
2176 | t1 = parse_type (NULL);
|
---|
2177 | switch (t1->tag)
|
---|
2178 | {
|
---|
2179 | case ty_class:
|
---|
2180 | break;
|
---|
2181 | case ty_struc:
|
---|
2182 | /* kso #456 2003-06-11: Don't mess with forward defines! */
|
---|
2183 | if (!( (t1->d.struc.flags & STRUC_FORWARD)
|
---|
2184 | /*&& t1->d.struc.types == NULL
|
---|
2185 | && t1->d.struc.fields == NULL*/))
|
---|
2186 | struct_to_class (t1);
|
---|
2187 | break;
|
---|
2188 | default:
|
---|
2189 | warning ("Invalid base class type");
|
---|
2190 | }
|
---|
2191 | tf->type = t1;
|
---|
2192 | if (!parse_char (';'))
|
---|
2193 | goto syntax;
|
---|
2194 | }
|
---|
2195 | }
|
---|
2196 |
|
---|
2197 | while (*parse_ptr != ';')
|
---|
2198 | {
|
---|
2199 | p1 = nextcolon (parse_ptr);
|
---|
2200 | if (p1 == NULL)
|
---|
2201 | {
|
---|
2202 | warning ("Invalid structure type: missing colon");
|
---|
2203 | goto syntax;
|
---|
2204 | }
|
---|
2205 | n = p1 - parse_ptr;
|
---|
2206 | grow_by (&g1, 1);
|
---|
2207 | tf = &tmp_fields[g1.count++];
|
---|
2208 | tf->type = NULL;
|
---|
2209 | tf->offset = 0;
|
---|
2210 | tf->flags = VIS_PUBLIC;
|
---|
2211 | tf->name = strpool_addn (str_pool, parse_ptr, n);
|
---|
2212 | tf->mnglname = tf->sname = NULL;
|
---|
2213 | parse_ptr = p1 + 1;
|
---|
2214 | if (*parse_ptr == ':')
|
---|
2215 | {
|
---|
2216 | class_flag = TRUE;
|
---|
2217 | ++parse_ptr;
|
---|
2218 | do
|
---|
2219 | {
|
---|
2220 | const char * pszMangled;
|
---|
2221 |
|
---|
2222 | t1 = parse_type (NULL);
|
---|
2223 | offset = 0;
|
---|
2224 | if (t1 == NULL || t1->tag != ty_func)
|
---|
2225 | {
|
---|
2226 | no_warning ("Invalid member function type");
|
---|
2227 | goto syntax;
|
---|
2228 | }
|
---|
2229 |
|
---|
2230 | if (*parse_ptr != ':')
|
---|
2231 | {
|
---|
2232 | no_warning ("Arguments for member function missing");
|
---|
2233 | goto syntax;
|
---|
2234 | }
|
---|
2235 | ++parse_ptr;
|
---|
2236 | pszMangled = parse_ptr;
|
---|
2237 | if (!parse_mangled_args ())
|
---|
2238 | goto syntax;
|
---|
2239 | tf->mnglname = strpool_addn(str_pool, pszMangled, parse_ptr - pszMangled - 1); /* ASSUMES no extra spaces! */
|
---|
2240 | tf->flags = parse_visibility () | MEMBER_FUNCTION;
|
---|
2241 | switch (*parse_ptr)
|
---|
2242 | {
|
---|
2243 | case 'A':
|
---|
2244 | ++parse_ptr;
|
---|
2245 | break;
|
---|
2246 | case 'B':
|
---|
2247 | tf->flags |= MEMBER_CONST;
|
---|
2248 | ++parse_ptr;
|
---|
2249 | break;
|
---|
2250 | case 'C':
|
---|
2251 | tf->flags |= MEMBER_VOLATILE;
|
---|
2252 | ++parse_ptr;
|
---|
2253 | break;
|
---|
2254 | case 'D':
|
---|
2255 | tf->flags |= MEMBER_CONST | MEMBER_VOLATILE;
|
---|
2256 | ++parse_ptr;
|
---|
2257 | break;
|
---|
2258 | default:
|
---|
2259 | no_warning ("Unknown member function qualifier: %c",
|
---|
2260 | *parse_ptr);
|
---|
2261 | if (*parse_ptr != 0)
|
---|
2262 | ++parse_ptr;
|
---|
2263 | }
|
---|
2264 | switch (*parse_ptr)
|
---|
2265 | {
|
---|
2266 | case '.':
|
---|
2267 | ++parse_ptr;
|
---|
2268 | break;
|
---|
2269 | case '*':
|
---|
2270 | tf->flags |= MEMBER_VIRTUAL;
|
---|
2271 | ++parse_ptr;
|
---|
2272 | if (!parse_number (&offset) || !parse_char (';'))
|
---|
2273 | {
|
---|
2274 | warning ("Invalid data for virtual member function");
|
---|
2275 | goto syntax;
|
---|
2276 | }
|
---|
2277 | parse_type (NULL);
|
---|
2278 | if (!parse_char (';'))
|
---|
2279 | {
|
---|
2280 | warning ("Invalid data for virtual member function");
|
---|
2281 | goto syntax;
|
---|
2282 | }
|
---|
2283 | break;
|
---|
2284 | case '?':
|
---|
2285 | tf->flags |= MEMBER_STATIC;
|
---|
2286 | ++parse_ptr;
|
---|
2287 | break;
|
---|
2288 | default:
|
---|
2289 | no_warning ("Unknown member function qualifier: %c",
|
---|
2290 | *parse_ptr);
|
---|
2291 | if (*parse_ptr != 0)
|
---|
2292 | ++parse_ptr;
|
---|
2293 | }
|
---|
2294 | /* Contstructor / Destructor hack -
|
---|
2295 | * TODO: verify that this doesn't really work with overloaded constructors and fix it.
|
---|
2296 | */
|
---|
2297 | if (!(tf->flags & MEMBER_STATIC))
|
---|
2298 | {
|
---|
2299 | /* using the strpool is much faster! */
|
---|
2300 | static const char *pszCompCtor, *pszBaseCtor, *pszCompDtor, *pszBaseDtor = NULL;
|
---|
2301 | if (!pszBaseDtor)
|
---|
2302 | {
|
---|
2303 | pszCompCtor = strpool_addn(str_pool, "__comp_ctor", 11);
|
---|
2304 | pszBaseCtor = strpool_addn(str_pool, "__base_ctor", 11);
|
---|
2305 | pszCompDtor = strpool_addn(str_pool, "__comp_dtor", 11);
|
---|
2306 | pszBaseDtor = strpool_addn(str_pool, "__base_dtor", 11);
|
---|
2307 | }
|
---|
2308 |
|
---|
2309 | if (tf->name == pszCompCtor || tf->name == pszBaseCtor)
|
---|
2310 | tf->flags |= MEMBER_CTOR;
|
---|
2311 | else if (tf->name == pszCompDtor || tf->name == pszBaseDtor)
|
---|
2312 | tf->flags |= MEMBER_DTOR;
|
---|
2313 | }
|
---|
2314 | tf->type = t1;
|
---|
2315 | tf->offset = offset;
|
---|
2316 | if (*parse_ptr != ';')
|
---|
2317 | {
|
---|
2318 | /* Another member function with the same name
|
---|
2319 | follows. */
|
---|
2320 |
|
---|
2321 | grow_by (&g1, 1);
|
---|
2322 | tf = &tmp_fields[g1.count++];
|
---|
2323 | tf->flags = VIS_PUBLIC | MEMBER_FUNCTION;
|
---|
2324 | tf->name = tf[-1].name;
|
---|
2325 | }
|
---|
2326 | } while (*parse_ptr != ';');
|
---|
2327 | ++parse_ptr;
|
---|
2328 | }
|
---|
2329 | else
|
---|
2330 | {
|
---|
2331 | if (*parse_ptr == '/')
|
---|
2332 | {
|
---|
2333 | class_flag = TRUE;
|
---|
2334 | ++parse_ptr;
|
---|
2335 | tf->flags = parse_visibility ();
|
---|
2336 | }
|
---|
2337 | t1 = parse_type (NULL);
|
---|
2338 | if (*parse_ptr == ':')
|
---|
2339 | {
|
---|
2340 | /* Static member */
|
---|
2341 |
|
---|
2342 | ++parse_ptr;
|
---|
2343 | tf->flags |= MEMBER_STATIC;
|
---|
2344 | p1 = strchr (parse_ptr, ';');
|
---|
2345 | if (p1 == NULL)
|
---|
2346 | {
|
---|
2347 | warning ("Invalid static member: missing semicolon");
|
---|
2348 | goto syntax;
|
---|
2349 | }
|
---|
2350 | n = p1 - parse_ptr;
|
---|
2351 | tf->sname = strpool_addn (str_pool, parse_ptr, n);
|
---|
2352 | parse_ptr = p1 + 1;
|
---|
2353 | tf->offset = 0;
|
---|
2354 | }
|
---|
2355 | else
|
---|
2356 | {
|
---|
2357 | if (!parse_char (',') || !parse_number (&offset))
|
---|
2358 | goto syntax;
|
---|
2359 | if (*parse_ptr == ',')
|
---|
2360 | {
|
---|
2361 | ++parse_ptr;
|
---|
2362 | if (!parse_number (&width))
|
---|
2363 | goto syntax;
|
---|
2364 | }
|
---|
2365 | else
|
---|
2366 | width = 0; /* vtable pointer field */
|
---|
2367 | if (!parse_char (';'))
|
---|
2368 | goto syntax;
|
---|
2369 | if ((offset & 7) != 0 || width != 8 * type_size (t1))
|
---|
2370 | {
|
---|
2371 | t.tag = ty_bits;
|
---|
2372 | t.d.bits.type = t1;
|
---|
2373 | t.d.bits.start = offset & 7;
|
---|
2374 | t.d.bits.count = width;
|
---|
2375 | t1 = type_add (&t);
|
---|
2376 | }
|
---|
2377 | tf->offset = offset >> 3;
|
---|
2378 | }
|
---|
2379 | tf->type = t1;
|
---|
2380 | }
|
---|
2381 |
|
---|
2382 | /* the debuggers croak if the field doesn't have a name. */
|
---|
2383 |
|
---|
2384 | if ((!tf->name || !*tf->name)
|
---|
2385 | && (!tf->sname || !*tf->sname)
|
---|
2386 | && (!tf->mnglname || !*tf->mnglname))
|
---|
2387 | tf->name = strpool_add (str_pool, "<anonymous>");
|
---|
2388 | }
|
---|
2389 | ++parse_ptr;
|
---|
2390 | if (*parse_ptr == '~')
|
---|
2391 | {
|
---|
2392 | /* Type reference to the first base class. This field is
|
---|
2393 | present for classes which contain virtual functions. */
|
---|
2394 |
|
---|
2395 | ++parse_ptr;
|
---|
2396 | if (!parse_char ('%'))
|
---|
2397 | goto syntax;
|
---|
2398 | t1 = parse_type (NULL);
|
---|
2399 | if (!parse_char (';'))
|
---|
2400 | goto syntax;
|
---|
2401 | }
|
---|
2402 |
|
---|
2403 | if (class_flag)
|
---|
2404 | {
|
---|
2405 | tlist = xmalloc (g1.count * sizeof (*t.d.types.list));
|
---|
2406 | for (i = 0; i < g1.count; ++i)
|
---|
2407 | {
|
---|
2408 | if (tmp_fields[i].flags & MEMBER_FUNCTION)
|
---|
2409 | {
|
---|
2410 | t2 = tmp_fields[i].type;
|
---|
2411 | tt = follow_refs (t2)->tag;
|
---|
2412 | /* TODO: check later if ty_stabs_ref */
|
---|
2413 | if (tt != ty_func && tt != ty_stabs_ref)
|
---|
2414 | error ("Invalid type for member function %s",
|
---|
2415 | tmp_fields[i].name);
|
---|
2416 | t.tag = ty_memfunc;
|
---|
2417 | t.d.memfunc.type = t2;
|
---|
2418 | t.d.memfunc.name = tmp_fields[i].name;
|
---|
2419 | t.d.memfunc.mnglname = tmp_fields[i].mnglname;
|
---|
2420 | t.d.memfunc.flags = tmp_fields[i].flags;
|
---|
2421 | t.d.memfunc.offset = tmp_fields[i].offset;
|
---|
2422 | }
|
---|
2423 | else if (tmp_fields[i].flags & MEMBER_BASE)
|
---|
2424 | {
|
---|
2425 | t.tag = ty_baseclass;
|
---|
2426 | t.d.baseclass.type = tmp_fields[i].type;
|
---|
2427 | t.d.baseclass.flags = tmp_fields[i].flags;
|
---|
2428 | t.d.baseclass.offset = tmp_fields[i].offset;
|
---|
2429 | }
|
---|
2430 | else
|
---|
2431 | {
|
---|
2432 | t.tag = ty_member;
|
---|
2433 | t.d.member.type = tmp_fields[i].type;
|
---|
2434 | t.d.member.offset = tmp_fields[i].offset;
|
---|
2435 | t.d.member.flags = tmp_fields[i].flags;
|
---|
2436 | t.d.member.name = tmp_fields[i].name;
|
---|
2437 | t.d.member.sname = tmp_fields[i].sname;
|
---|
2438 | }
|
---|
2439 | t2 = type_add (&t);
|
---|
2440 | tlist[i] = t2;
|
---|
2441 | }
|
---|
2442 | t.tag = ty_types;
|
---|
2443 | t.d.types.count = g1.count;
|
---|
2444 | t.d.types.list = tlist;
|
---|
2445 | t1 = type_add (&t);
|
---|
2446 | free (tlist);
|
---|
2447 |
|
---|
2448 | t.tag = ty_class;
|
---|
2449 | t.d.class.members = t1;
|
---|
2450 | t.d.class.size = size;
|
---|
2451 | t.d.class.count = g1.count;
|
---|
2452 | t.d.class.name = add_struct_name (type_name);
|
---|
2453 |
|
---|
2454 | /* Check if there is an incomplete type waiting to be filled
|
---|
2455 | in (forward reference). We're ignoring scoping (TODO). */
|
---|
2456 |
|
---|
2457 | for (t3 = type_head; t3 != NULL; t3 = t3->next)
|
---|
2458 | if (t3->tag == ty_struc && t3->d.struc.name == t.d.class.name
|
---|
2459 | /*&& t3->d.struc.types == NULL && t3->d.struc.fields == NULL */
|
---|
2460 | && (t3->d.struc.flags & STRUC_FORWARD))
|
---|
2461 | {
|
---|
2462 | if (t3->index != -1)
|
---|
2463 | warning ("This cannot happen, case 1");
|
---|
2464 | result = t3;
|
---|
2465 | t3->tag = ty_class;
|
---|
2466 | t3->d.class = t.d.class;
|
---|
2467 | break;
|
---|
2468 | }
|
---|
2469 | }
|
---|
2470 | else
|
---|
2471 | {
|
---|
2472 | t.tag = ty_types;
|
---|
2473 | t.d.types.count = g1.count;
|
---|
2474 | t.d.types.list = xmalloc (g1.count * sizeof (*t.d.types.list));
|
---|
2475 | for (i = 0; i < g1.count; ++i)
|
---|
2476 | t.d.types.list[i] = tmp_fields[i].type;
|
---|
2477 | t1 = type_add (&t);
|
---|
2478 | free (t.d.types.list);
|
---|
2479 |
|
---|
2480 | t.tag = ty_fields;
|
---|
2481 | t.d.fields.count = g1.count;
|
---|
2482 | t.d.fields.list = xmalloc (g1.count * sizeof (*t.d.fields.list));
|
---|
2483 | for (i = 0; i < g1.count; ++i)
|
---|
2484 | {
|
---|
2485 | t.d.fields.list[i].offset = tmp_fields[i].offset;
|
---|
2486 | t.d.fields.list[i].name = tmp_fields[i].name;
|
---|
2487 | }
|
---|
2488 | t2 = type_add (&t);
|
---|
2489 | free (t.d.fields.list);
|
---|
2490 |
|
---|
2491 | t.tag = ty_struc;
|
---|
2492 | t.d.struc.count = g1.count;
|
---|
2493 | t.d.struc.size = size;
|
---|
2494 | t.d.struc.types = t1;
|
---|
2495 | t.d.struc.fields = t2;
|
---|
2496 | t.d.struc.name = add_struct_name (type_name);
|
---|
2497 | t.d.struc.flags = 0;
|
---|
2498 |
|
---|
2499 | /* Check if there is an incomplete type waiting to be filled
|
---|
2500 | in (forward reference). We're ignoring scoping (TODO). */
|
---|
2501 |
|
---|
2502 | for (t3 = type_head; t3 != NULL; t3 = t3->next)
|
---|
2503 | if (t3->tag == ty_struc && t3->d.struc.name == t.d.struc.name
|
---|
2504 | /* && t3->d.struc.types == NULL && t3->d.struc.fields == NULL */
|
---|
2505 | && (t3->d.struc.flags & STRUC_FORWARD))
|
---|
2506 | {
|
---|
2507 | if (t3->index != -1)
|
---|
2508 | warning ("This cannot happen, case 1");
|
---|
2509 | result = t3;
|
---|
2510 | t3->d.struc = t.d.struc;
|
---|
2511 | break;
|
---|
2512 | }
|
---|
2513 | }
|
---|
2514 | grow_free (&g1);
|
---|
2515 | break;
|
---|
2516 |
|
---|
2517 | case 'e':
|
---|
2518 | size = 32;
|
---|
2519 | l_parse_enum:
|
---|
2520 |
|
---|
2521 | /* Enumeration type: e{<name>:<value>,}; */
|
---|
2522 |
|
---|
2523 | ++parse_ptr;
|
---|
2524 | grow_init (&g1, &tmp_values, sizeof (*tmp_values), 8);
|
---|
2525 | while (*parse_ptr != ';')
|
---|
2526 | {
|
---|
2527 | p1 = nextcolon (parse_ptr);
|
---|
2528 | if (p1 == NULL)
|
---|
2529 | {
|
---|
2530 | warning ("Invalid enum type: missing colon");
|
---|
2531 | goto syntax;
|
---|
2532 | }
|
---|
2533 | n = p1 - parse_ptr;
|
---|
2534 | grow_by (&g1, 1);
|
---|
2535 | tv = &tmp_values[g1.count++];
|
---|
2536 | tv->name = strpool_addn (str_pool, parse_ptr, n);
|
---|
2537 | parse_ptr = p1 + 1;
|
---|
2538 | if (!parse_number (&tv->index) || !parse_char (','))
|
---|
2539 | goto syntax;
|
---|
2540 | }
|
---|
2541 | ++parse_ptr;
|
---|
2542 | t.tag = ty_values;
|
---|
2543 | t.d.values.count = g1.count;
|
---|
2544 | t.d.values.list = xmalloc (g1.count * sizeof (*t.d.values.list));
|
---|
2545 | if (g1.count == 0)
|
---|
2546 | lo = hi = 0;
|
---|
2547 | else
|
---|
2548 | lo = hi = tmp_values[0].index;
|
---|
2549 | for (i = 0; i < g1.count; ++i)
|
---|
2550 | {
|
---|
2551 | t.d.values.list[i].index = tmp_values[i].index;
|
---|
2552 | t.d.values.list[i].name = tmp_values[i].name;
|
---|
2553 | if (tmp_values[i].index < lo)
|
---|
2554 | lo = tmp_values[i].index;
|
---|
2555 | if (tmp_values[i].index > hi)
|
---|
2556 | hi = tmp_values[i].index;
|
---|
2557 | }
|
---|
2558 | t1 = type_add (&t);
|
---|
2559 | free (t.d.values.list);
|
---|
2560 |
|
---|
2561 | t.tag = ty_prim;
|
---|
2562 | switch (size)
|
---|
2563 | {
|
---|
2564 | case 8: t.index = 0x80; break; /* 8 bit signed */
|
---|
2565 | case 16: t.index = 0x81; break; /* 16 bit signed */
|
---|
2566 | case 32: t.index = 0x82; break; /* 32 bit signed */
|
---|
2567 | case 64: result = t2 = make_long_long (); break;
|
---|
2568 | default: goto syntax;
|
---|
2569 | }
|
---|
2570 | if (!result)
|
---|
2571 | t2 = type_add (&t);
|
---|
2572 |
|
---|
2573 | t.tag = ty_enu;
|
---|
2574 | t.index = -1;
|
---|
2575 | t.d.enu.values = t1;
|
---|
2576 | t.d.enu.type = t2;
|
---|
2577 | t.d.enu.name = add_struct_name (type_name);
|
---|
2578 | t.d.enu.first = lo;
|
---|
2579 | t.d.enu.last = hi;
|
---|
2580 | grow_free (&g1);
|
---|
2581 | break;
|
---|
2582 |
|
---|
2583 | case 'a':
|
---|
2584 | /* An array: ar<index_type>;<lower_bound>;<upper_bound>;<el_type> */
|
---|
2585 |
|
---|
2586 | ++parse_ptr;
|
---|
2587 | if (!parse_char ('r'))
|
---|
2588 | goto syntax;
|
---|
2589 | if (strncmp (parse_ptr, "0;", 2) == 0)
|
---|
2590 | {
|
---|
2591 | /* This invalid type index seems to be caused by a bug of
|
---|
2592 | GCC 2.8.1. Replace with a 32-bit signed integer. */
|
---|
2593 |
|
---|
2594 | t.tag = ty_prim;
|
---|
2595 | t.index = 0x82; /* 32 bit signed */
|
---|
2596 | t1 = type_add (&t);
|
---|
2597 | ++parse_ptr;
|
---|
2598 | }
|
---|
2599 | else
|
---|
2600 | t1 = parse_type (NULL); /* Index type */
|
---|
2601 | if (!parse_char (';')
|
---|
2602 | || !parse_number (&lo) || !parse_char (';') /* Lower bound */
|
---|
2603 | || !parse_number (&hi) || !parse_char (';')) /* Upper bound */
|
---|
2604 | goto syntax;
|
---|
2605 | t2 = parse_type (NULL); /* Elements type */
|
---|
2606 | if (lo == 0 && hi == 0) /* Variable-length array */
|
---|
2607 | {
|
---|
2608 | t.tag = ty_pointer; /* Turn into pointer */
|
---|
2609 | t.d.pointer = t2;
|
---|
2610 | }
|
---|
2611 | else
|
---|
2612 | {
|
---|
2613 | t.tag = ty_array;
|
---|
2614 | t.d.array.first = lo;
|
---|
2615 | t.d.array.last = hi;
|
---|
2616 | t.d.array.itype = t1;
|
---|
2617 | t.d.array.etype = t2;
|
---|
2618 | }
|
---|
2619 | break;
|
---|
2620 |
|
---|
2621 | case 'f':
|
---|
2622 |
|
---|
2623 | /* A function: f<return_type> */
|
---|
2624 |
|
---|
2625 | ++parse_ptr;
|
---|
2626 | t1 = parse_type (NULL); /* Return type */
|
---|
2627 | t.tag = ty_func;
|
---|
2628 | t.d.func.ret = t1;
|
---|
2629 | t.d.func.domain = NULL;
|
---|
2630 | t.d.func.args = NULL;
|
---|
2631 | t.d.func.arg_count = 0;
|
---|
2632 | break;
|
---|
2633 |
|
---|
2634 | default:
|
---|
2635 | no_warning ("Unknown type: %c", *parse_ptr);
|
---|
2636 | goto syntax;
|
---|
2637 | }
|
---|
2638 |
|
---|
2639 | /* Add the type to the tables. */
|
---|
2640 |
|
---|
2641 | if (result == NULL)
|
---|
2642 | result = type_add (&t);
|
---|
2643 | return result;
|
---|
2644 |
|
---|
2645 | syntax:
|
---|
2646 | no_warning ("syntax error in stabs: %c (off %ld)\n stabs: %s",
|
---|
2647 | *parse_ptr, parse_ptr - parse_start, parse_start);
|
---|
2648 |
|
---|
2649 | grow_free (&g1);
|
---|
2650 | t.tag = ty_prim;
|
---|
2651 | t.index = 0x82; /* 32 bit signed */
|
---|
2652 | return type_add (&t);
|
---|
2653 | }
|
---|
2654 |
|
---|
2655 |
|
---|
2656 | /* Parse a stabs type (the name of the type is TYPE_NAME, which is
|
---|
2657 | NULL for an unnamed type) and check for end of the string. If not
|
---|
2658 | all characters of the string have been parsed, a warning message is
|
---|
2659 | displayed. Return the internal representation of the type. */
|
---|
2660 |
|
---|
2661 | static struct type *parse_complete_type (const char *type_name)
|
---|
2662 | {
|
---|
2663 | struct type *tp;
|
---|
2664 |
|
---|
2665 | tp = parse_type (type_name);
|
---|
2666 | if (*parse_ptr != 0)
|
---|
2667 | no_warning ("unexpected character at end of stabs type: %c (off %ld)\n stabs: %s",
|
---|
2668 | *parse_ptr, parse_ptr - parse_start, parse_start);
|
---|
2669 | return tp;
|
---|
2670 | }
|
---|
2671 |
|
---|
2672 |
|
---|
2673 | /* Create an HLL type number for type TP. If a type number has already
|
---|
2674 | been assigned to TP, use that number. Otherwise, allocate a new
|
---|
2675 | (complex) type number and define the type in the $$TYPES segment.
|
---|
2676 | The HLL type number us stored to *HLL.
|
---|
2677 |
|
---|
2678 | Note: This function must not be called between sst_start() and
|
---|
2679 | sst_end() or tt_start() and tt_end() as entries are made both in
|
---|
2680 | the SST ($$SYMBOLS) and the type table ($$TYPES). */
|
---|
2681 |
|
---|
2682 | static void make_type (struct type *tp, int *hll)
|
---|
2683 | {
|
---|
2684 | struct type *t1;
|
---|
2685 | int ti_1, ti_2, ti_3, i, qual;
|
---|
2686 | int patch1;
|
---|
2687 |
|
---|
2688 | #define RETURN(X) do {*hll = (X); return;} while (0)
|
---|
2689 |
|
---|
2690 | if (tp->index <= -2)
|
---|
2691 | {
|
---|
2692 | /* bird: A hack where we allow a 2nd recursion of rectain types.
|
---|
2693 | * The normal issue is C++ class references. */
|
---|
2694 | if (tp->tag != ty_alias || tp->index <= -3)
|
---|
2695 | {
|
---|
2696 | warning_parse ("Cycle detected by make_type.");
|
---|
2697 | RETURN (0);
|
---|
2698 | }
|
---|
2699 | }
|
---|
2700 | if (tp->index > -1)
|
---|
2701 | RETURN (tp->index);
|
---|
2702 | tp->index--;
|
---|
2703 | switch (tp->tag)
|
---|
2704 | {
|
---|
2705 | case ty_stabs_ref:
|
---|
2706 | t1 = stype_find (tp->d.stabs_ref);
|
---|
2707 | if (t1 == NULL)
|
---|
2708 | {
|
---|
2709 | warning_parse ("Undefined stabs type %d referenced", tp->d.stabs_ref);
|
---|
2710 | RETURN (0x82); /* 32 bit signed */
|
---|
2711 | }
|
---|
2712 | make_type (t1, &tp->index);
|
---|
2713 | *hll = tp->index;
|
---|
2714 | break;
|
---|
2715 |
|
---|
2716 | case ty_alias:
|
---|
2717 | make_type (tp->d.alias, &tp->index);
|
---|
2718 | *hll = tp->index;
|
---|
2719 | break;
|
---|
2720 |
|
---|
2721 | case ty_pointer:
|
---|
2722 | ti_1 = tp->d.pointer->index;
|
---|
2723 | if (ti_1 >= 0x80 && ti_1 <= 0xa0)
|
---|
2724 | {
|
---|
2725 | tp->index = ti_1 + 0x20;
|
---|
2726 | RETURN (tp->index);
|
---|
2727 | }
|
---|
2728 | *hll = tp->index = hll_type_index++;
|
---|
2729 | tt_start (0x7a, 0x01); /* 32-bit near pointer */
|
---|
2730 | patch1 = tt.size;
|
---|
2731 | tt_index (0);
|
---|
2732 | tt_end ();
|
---|
2733 | make_type (tp->d.pointer, &ti_1);
|
---|
2734 | buffer_patch_word (&tt, patch1+1, ti_1);
|
---|
2735 | break;
|
---|
2736 |
|
---|
2737 | case ty_ref:
|
---|
2738 | *hll = tp->index = hll_type_index++;
|
---|
2739 | tt_start (0x48, 0x00); /* Reference type (C++) */
|
---|
2740 | patch1 = tt.size;
|
---|
2741 | tt_word (0);
|
---|
2742 | tt_end ();
|
---|
2743 | make_type (tp->d.ref, &ti_1);
|
---|
2744 | buffer_patch_word (&tt, patch1, ti_1);
|
---|
2745 | break;
|
---|
2746 |
|
---|
2747 | case ty_struc:
|
---|
2748 | {
|
---|
2749 | struct field *fields = NULL;
|
---|
2750 | struct type **types = NULL;
|
---|
2751 | int cFields = tp->d.struc.count;
|
---|
2752 |
|
---|
2753 | if ( tp->d.struc.fields
|
---|
2754 | && tp->d.struc.fields->tag == ty_fields
|
---|
2755 | && tp->d.struc.fields->d.fields.count == cFields)
|
---|
2756 | fields = tp->d.struc.fields->d.fields.list;
|
---|
2757 | if ( tp->d.struc.types
|
---|
2758 | && tp->d.struc.types->tag == ty_types
|
---|
2759 | && tp->d.struc.types->d.types.count == cFields)
|
---|
2760 | types = tp->d.struc.types->d.types.list;
|
---|
2761 |
|
---|
2762 | if (cplusplus_flag && ((types && fields) || !cFields))
|
---|
2763 | {
|
---|
2764 | struct type t;
|
---|
2765 | struct type **list;
|
---|
2766 | int i;
|
---|
2767 | *hll = tp->index = hll_type_index++;
|
---|
2768 | tt_start (0x40, 0x01); /* Class is-struct */
|
---|
2769 | tt_dword (tp->d.struc.size);
|
---|
2770 | tt_word (tp->d.struc.count);
|
---|
2771 | patch1 = tt.size;
|
---|
2772 | tt_word (0); /* Members */
|
---|
2773 | tt_enc (tp->d.struc.name); /* Class name */
|
---|
2774 | tt_end ();
|
---|
2775 |
|
---|
2776 | list = xmalloc (cFields * sizeof (*list));
|
---|
2777 | for (i = 0; i < cFields; ++i)
|
---|
2778 | {
|
---|
2779 | t.tag = ty_member;
|
---|
2780 | t.index = -1;
|
---|
2781 | t.d.member.type = types[i];
|
---|
2782 | t.d.member.offset = fields[i].offset;
|
---|
2783 | t.d.member.flags = VIS_PUBLIC;
|
---|
2784 | t.d.member.name = fields[i].name;
|
---|
2785 | t.d.member.sname = NULL;
|
---|
2786 | list[i] = type_add (&t);
|
---|
2787 | }
|
---|
2788 |
|
---|
2789 | t.tag = ty_types;
|
---|
2790 | t.index = -1;
|
---|
2791 | t.d.types.count = cFields;
|
---|
2792 | t.d.types.list = list;
|
---|
2793 | t1 = type_add (&t);
|
---|
2794 | free (list);
|
---|
2795 |
|
---|
2796 | make_type (t1, &ti_1);
|
---|
2797 | buffer_patch_word (&tt, patch1, ti_1);
|
---|
2798 | }
|
---|
2799 | else
|
---|
2800 | {
|
---|
2801 | tt_start (0x79, 0x00); /* Structure/Union */
|
---|
2802 | tt_dword (tp->d.struc.size);
|
---|
2803 | tt_word (tp->d.struc.count);
|
---|
2804 | patch1 = tt.size;
|
---|
2805 | tt_index (0);
|
---|
2806 | tt_index (0);
|
---|
2807 | tt_name (tp->d.struc.name);
|
---|
2808 | tt_end ();
|
---|
2809 | *hll = tp->index = hll_type_index++;
|
---|
2810 | if (tp->d.struc.types == NULL && tp->d.struc.fields == NULL)
|
---|
2811 | {
|
---|
2812 | ti_1 = 0;
|
---|
2813 | ti_2 = 1;
|
---|
2814 | }
|
---|
2815 | else
|
---|
2816 | {
|
---|
2817 | make_type (tp->d.struc.types, &ti_1);
|
---|
2818 | make_type (tp->d.struc.fields, &ti_2);
|
---|
2819 | }
|
---|
2820 | buffer_patch_word (&tt, patch1+1, ti_1);
|
---|
2821 | buffer_patch_word (&tt, patch1+4, ti_2);
|
---|
2822 | }
|
---|
2823 | break;
|
---|
2824 | }
|
---|
2825 |
|
---|
2826 | case ty_class:
|
---|
2827 | *hll = tp->index = hll_type_index++;
|
---|
2828 | tt_start (0x40, 0x00); /* Class */
|
---|
2829 | tt_dword (tp->d.class.size);
|
---|
2830 | tt_word (tp->d.class.count);
|
---|
2831 | patch1 = tt.size;
|
---|
2832 | tt_word (0); /* Members */
|
---|
2833 | tt_enc (tp->d.class.name); /* Class name */
|
---|
2834 | tt_end ();
|
---|
2835 | make_type (tp->d.class.members, &ti_1);
|
---|
2836 | buffer_patch_word (&tt, patch1, ti_1);
|
---|
2837 | break;
|
---|
2838 |
|
---|
2839 | case ty_member:
|
---|
2840 | qual = 0;
|
---|
2841 | if (tp->d.member.flags & MEMBER_STATIC)
|
---|
2842 | qual |= 0x01;
|
---|
2843 | tt_start (0x46, qual);
|
---|
2844 | tt_byte (tp->d.member.flags & MEMBER_VIS);
|
---|
2845 | patch1 = tt.size;
|
---|
2846 | tt_word (0);
|
---|
2847 | tt_unsigned_span (tp->d.member.offset);
|
---|
2848 | if (tp->d.member.flags & MEMBER_STATIC)
|
---|
2849 | tt_enc (tp->d.member.sname);
|
---|
2850 | else
|
---|
2851 | tt_enc ("");
|
---|
2852 | tt_enc (tp->d.member.name);
|
---|
2853 | tt_end ();
|
---|
2854 | *hll = tp->index = hll_type_index++;
|
---|
2855 |
|
---|
2856 | make_type (tp->d.member.type, &ti_1);
|
---|
2857 | buffer_patch_word (&tt, patch1, ti_1);
|
---|
2858 | break;
|
---|
2859 |
|
---|
2860 | case ty_enu:
|
---|
2861 | make_type (tp->d.enu.type, &ti_1);
|
---|
2862 | make_type (tp->d.enu.values, &ti_2);
|
---|
2863 | tt_start (0x7b, 0x00); /* Enum */
|
---|
2864 | tt_index (ti_1); /* Element's data type */
|
---|
2865 | tt_index (ti_2); /* List of values */
|
---|
2866 | tt_signed_span (tp->d.enu.first); /* Minimum index */
|
---|
2867 | tt_signed_span (tp->d.enu.last); /* Maximum index */
|
---|
2868 | tt_name (tp->d.enu.name);
|
---|
2869 | tt_end ();
|
---|
2870 | *hll = tp->index = hll_type_index++;
|
---|
2871 | break;
|
---|
2872 |
|
---|
2873 | case ty_array:
|
---|
2874 | make_type (tp->d.array.itype, &ti_1);
|
---|
2875 | make_type (tp->d.array.etype, &ti_2);
|
---|
2876 | tt_start (0x78, 0x00); /* Array */
|
---|
2877 | tt_dword (type_size (tp));
|
---|
2878 | tt_index (ti_1);
|
---|
2879 | tt_index (ti_2);
|
---|
2880 | tt_name (""); /* Name */
|
---|
2881 | tt_end ();
|
---|
2882 | *hll = tp->index = hll_type_index++;
|
---|
2883 | break;
|
---|
2884 |
|
---|
2885 | case ty_bits:
|
---|
2886 | tt_start (0x5c, 0x0a); /* Bit string */
|
---|
2887 | tt_byte (tp->d.bits.start);
|
---|
2888 | tt_unsigned_span (tp->d.bits.count);
|
---|
2889 | tt_end ();
|
---|
2890 | *hll = tp->index = hll_type_index++;
|
---|
2891 | break;
|
---|
2892 |
|
---|
2893 | case ty_func:
|
---|
2894 | tt_start (0x54, 0x05); /* Function */
|
---|
2895 | tt_word (tp->d.func.arg_count); /* Number of parameters */
|
---|
2896 | tt_word (tp->d.func.arg_count); /* Max. Number of parameters */
|
---|
2897 | patch1 = tt.size;
|
---|
2898 | tt_index (0); /* Return value */
|
---|
2899 | tt_index (0); /* Argument list */
|
---|
2900 | tt_end ();
|
---|
2901 | *hll = tp->index = hll_type_index++;
|
---|
2902 |
|
---|
2903 | if (tp->d.func.domain)
|
---|
2904 | make_type (tp->d.func.domain, &ti_3);
|
---|
2905 | make_type (tp->d.func.ret, &ti_1);
|
---|
2906 | if (tp->d.func.args == NULL)
|
---|
2907 | ti_2 = 0;
|
---|
2908 | else
|
---|
2909 | make_type (tp->d.func.args, &ti_2);
|
---|
2910 | buffer_patch_word (&tt, patch1+1, ti_1);
|
---|
2911 | buffer_patch_word (&tt, patch1+4, ti_2);
|
---|
2912 | break;
|
---|
2913 |
|
---|
2914 | case ty_args:
|
---|
2915 | if (tp->d.args.count == 0)
|
---|
2916 | {
|
---|
2917 | tp->index = 0;
|
---|
2918 | RETURN (tp->index);
|
---|
2919 | }
|
---|
2920 | for (i = 0; i < tp->d.args.count; ++i)
|
---|
2921 | make_type (tp->d.args.list[i], &ti_1);
|
---|
2922 | tt_start (0x7f, 0x04); /* List (function parameters) */
|
---|
2923 | for (i = 0; i < tp->d.args.count; ++i)
|
---|
2924 | {
|
---|
2925 | tt_byte (0x01); /* Flag: pass by value, no descriptor */
|
---|
2926 | tt_index (tp->d.args.list[i]->index);
|
---|
2927 | }
|
---|
2928 | tt_end ();
|
---|
2929 | *hll = tp->index = hll_type_index++;
|
---|
2930 | break;
|
---|
2931 |
|
---|
2932 | case ty_types:
|
---|
2933 | if (tp->d.types.count == 0)
|
---|
2934 | {
|
---|
2935 | tp->index = 0;
|
---|
2936 | RETURN (tp->index);
|
---|
2937 | }
|
---|
2938 | *hll = tp->index = hll_type_index++;
|
---|
2939 | tt_start (0x7f, 0x01); /* List (structure field types) */
|
---|
2940 | patch1 = tt.size;
|
---|
2941 | for (i = 0; i < tp->d.types.count; ++i)
|
---|
2942 | tt_index (0);
|
---|
2943 | tt_end ();
|
---|
2944 | for (i = 0; i < tp->d.types.count; ++i)
|
---|
2945 | {
|
---|
2946 | make_type (tp->d.types.list[i], &ti_1);
|
---|
2947 | buffer_patch_word (&tt, patch1 + 1 + 3*i, ti_1);
|
---|
2948 | }
|
---|
2949 | break;
|
---|
2950 |
|
---|
2951 | case ty_fields:
|
---|
2952 | if (tp->d.fields.count == 0)
|
---|
2953 | {
|
---|
2954 | tp->index = 0;
|
---|
2955 | RETURN (tp->index);
|
---|
2956 | }
|
---|
2957 | tt_start (0x7f, 0x02); /* List (structure field names) */
|
---|
2958 | for (i = 0; i < tp->d.fields.count; ++i)
|
---|
2959 | {
|
---|
2960 | tt_name (tp->d.fields.list[i].name);
|
---|
2961 | tt_unsigned_span (tp->d.fields.list[i].offset);
|
---|
2962 | }
|
---|
2963 | tt_end ();
|
---|
2964 | *hll = tp->index = hll_type_index++;
|
---|
2965 | break;
|
---|
2966 |
|
---|
2967 | case ty_values:
|
---|
2968 | if (tp->d.values.count == 0)
|
---|
2969 | {
|
---|
2970 | tp->index = -1;
|
---|
2971 | RETURN (tp->index);
|
---|
2972 | }
|
---|
2973 | tt_start (0x7f, 0x03); /* Enum values */
|
---|
2974 | for (i = 0; i < tp->d.values.count; ++i)
|
---|
2975 | {
|
---|
2976 | tt_name (tp->d.values.list[i].name);
|
---|
2977 | tt_unsigned_span (tp->d.values.list[i].index);
|
---|
2978 | }
|
---|
2979 | tt_end ();
|
---|
2980 | *hll = tp->index = hll_type_index++;
|
---|
2981 | break;
|
---|
2982 |
|
---|
2983 | case ty_memfunc:
|
---|
2984 | make_type (tp->d.memfunc.type, &ti_1);
|
---|
2985 | qual = 0;
|
---|
2986 | if (tp->d.memfunc.flags & MEMBER_STATIC)
|
---|
2987 | qual |= 0x01;
|
---|
2988 | if (tp->d.memfunc.flags & MEMBER_CONST)
|
---|
2989 | qual |= 0x04;
|
---|
2990 | if (tp->d.memfunc.flags & MEMBER_VOLATILE)
|
---|
2991 | qual |= 0x08;
|
---|
2992 | if (tp->d.memfunc.flags & MEMBER_VIRTUAL)
|
---|
2993 | qual |= 0x10;
|
---|
2994 | tt_start (0x45, qual); /* Member Function */
|
---|
2995 | tt_byte (tp->d.memfunc.flags & MEMBER_VIS); /* Protection */
|
---|
2996 | if (tp->d.memfunc.flags & MEMBER_CTOR)
|
---|
2997 | tt_byte (1); /* Constructor */
|
---|
2998 | else if (tp->d.memfunc.flags & MEMBER_DTOR)
|
---|
2999 | tt_byte (2); /* Destructor */
|
---|
3000 | else
|
---|
3001 | tt_byte (0); /* Regular member function */
|
---|
3002 | tt_word (ti_1); /* Type index of function */
|
---|
3003 | if (tp->d.memfunc.flags & MEMBER_VIRTUAL)
|
---|
3004 | tt_unsigned_span (tp->d.memfunc.offset); /* Index into vtable */
|
---|
3005 | tt_enc (tp->d.memfunc.name); /* Name of the function */
|
---|
3006 | tt_end ();
|
---|
3007 | *hll = tp->index = hll_type_index++;
|
---|
3008 | break;
|
---|
3009 |
|
---|
3010 | case ty_baseclass:
|
---|
3011 | make_type (tp->d.baseclass.type, &ti_1);
|
---|
3012 | qual = 0;
|
---|
3013 | if (tp->d.baseclass.flags & MEMBER_VIRTUAL)
|
---|
3014 | qual |= 0x01;
|
---|
3015 | tt_start (0x41, qual); /* Base Class */
|
---|
3016 | tt_byte (tp->d.baseclass.flags & MEMBER_VIS);
|
---|
3017 | tt_word (ti_1); /* Type */
|
---|
3018 | tt_unsigned_span (tp->d.baseclass.offset);
|
---|
3019 | tt_end ();
|
---|
3020 | *hll = tp->index = hll_type_index++;
|
---|
3021 | break;
|
---|
3022 |
|
---|
3023 | default:
|
---|
3024 | error ("make_type: unknown tag %d", tp->tag);
|
---|
3025 | }
|
---|
3026 | }
|
---|
3027 |
|
---|
3028 |
|
---|
3029 | /* Parse an unnamed stabs type and return an HLL type index for it. */
|
---|
3030 |
|
---|
3031 | static int hll_type (void)
|
---|
3032 | {
|
---|
3033 | struct type *tp;
|
---|
3034 | int ti;
|
---|
3035 |
|
---|
3036 | tp = parse_complete_type (NULL);
|
---|
3037 | make_type (tp, &ti);
|
---|
3038 | return ti;
|
---|
3039 | }
|
---|
3040 |
|
---|
3041 |
|
---|
3042 | /* Return the symbol name of symbol *INDEX, concatenating the names of
|
---|
3043 | successive symbol table entries if necessary. A pointer to the
|
---|
3044 | string is stored to *STR. If symbols are concatenated, *INDEX is
|
---|
3045 | adjusted to refer to the last symbol table entry used, in order to
|
---|
3046 | refer to the next symbol after incrementing by one. If TRUE is
|
---|
3047 | returned, the caller should free the string when it is no longer
|
---|
3048 | needed. If FALSE is returned, the string must not be freed. */
|
---|
3049 |
|
---|
3050 | static int concat_symbols (int *index, const char **str)
|
---|
3051 | {
|
---|
3052 | int i, n, len;
|
---|
3053 | char *new;
|
---|
3054 | const char *p;
|
---|
3055 |
|
---|
3056 | len = 0;
|
---|
3057 | for (i = *index; i < sym_count; ++i)
|
---|
3058 | {
|
---|
3059 | p = str_ptr + sym_ptr[i].n_un.n_strx;
|
---|
3060 | n = strlen (p);
|
---|
3061 | if (n > 0 && p[n-1] == '\\')
|
---|
3062 | len += n - 1;
|
---|
3063 | else
|
---|
3064 | {
|
---|
3065 | len += n;
|
---|
3066 | break;
|
---|
3067 | }
|
---|
3068 | }
|
---|
3069 | if (i == *index)
|
---|
3070 | {
|
---|
3071 | *str = str_ptr + sym_ptr[i].n_un.n_strx;
|
---|
3072 | return FALSE;
|
---|
3073 | }
|
---|
3074 | else
|
---|
3075 | {
|
---|
3076 | new = xmalloc (len + 1);
|
---|
3077 | *str = new;
|
---|
3078 | for (i = *index; i < sym_count; ++i)
|
---|
3079 | {
|
---|
3080 | p = str_ptr + sym_ptr[i].n_un.n_strx;
|
---|
3081 | n = strlen (p);
|
---|
3082 | if (n > 0 && p[n-1] == '\\')
|
---|
3083 | {
|
---|
3084 | memcpy (new, p, n - 1);
|
---|
3085 | new += n - 1;
|
---|
3086 | }
|
---|
3087 | else
|
---|
3088 | {
|
---|
3089 | memcpy (new, p, n);
|
---|
3090 | new += n;
|
---|
3091 | break;
|
---|
3092 | }
|
---|
3093 | }
|
---|
3094 | *new = 0;
|
---|
3095 | *index = i;
|
---|
3096 | return TRUE;
|
---|
3097 | }
|
---|
3098 | }
|
---|
3099 |
|
---|
3100 |
|
---|
3101 | /* Parse a stabs type definition and store the internal representation
|
---|
3102 | of that type. The sym_ptr index is passed in INDEX. As we might
|
---|
3103 | have to concatenate successive symbol table entries, *INDEX is
|
---|
3104 | updated to refer to the next symbol. */
|
---|
3105 |
|
---|
3106 | static void parse_typedef (int *index)
|
---|
3107 | {
|
---|
3108 | char *name;
|
---|
3109 | const char *str, *p;
|
---|
3110 | struct type *t;
|
---|
3111 | int n, alloc_flag;
|
---|
3112 |
|
---|
3113 | alloc_flag = concat_symbols (index, &str);
|
---|
3114 | parse_start = str;
|
---|
3115 | parse_pindex = index;
|
---|
3116 | p = nextcolon (str);
|
---|
3117 | if (p != NULL)
|
---|
3118 | {
|
---|
3119 | n = p - str;
|
---|
3120 | name = alloca (n + 1);
|
---|
3121 | memcpy (name, str, n);
|
---|
3122 | name[n] = 0;
|
---|
3123 | #if defined (HLL_DEBUG)
|
---|
3124 | printf ("LSYM/LCSYM/GSYM/PSYM/RSYM/STSYM/FUN %s\n", str);
|
---|
3125 | #endif
|
---|
3126 | parse_ptr = p + 1;
|
---|
3127 | switch (*parse_ptr)
|
---|
3128 | {
|
---|
3129 | case 'f':
|
---|
3130 | case 'F':
|
---|
3131 | ++parse_ptr;
|
---|
3132 | /* Note: don't call parse_complete_type() as there's a comma
|
---|
3133 | at the end for nested functions. */
|
---|
3134 | t = parse_type (NULL);
|
---|
3135 | break;
|
---|
3136 |
|
---|
3137 | case 't':
|
---|
3138 | case 'T':
|
---|
3139 | ++parse_ptr;
|
---|
3140 | if (*parse_ptr == 't')
|
---|
3141 | ++parse_ptr; /* synonymous type */
|
---|
3142 | t = parse_complete_type (name);
|
---|
3143 | #if defined (HLL_DEBUG)
|
---|
3144 | printf (" type: ");
|
---|
3145 | show_type (t);
|
---|
3146 | printf ("\n");
|
---|
3147 | #endif
|
---|
3148 | break;
|
---|
3149 |
|
---|
3150 | case 'p':
|
---|
3151 | case 'r':
|
---|
3152 | case 'G':
|
---|
3153 | case 'S':
|
---|
3154 | case 'V':
|
---|
3155 | ++parse_ptr;
|
---|
3156 | t = parse_complete_type (name);
|
---|
3157 | #if defined (HLL_DEBUG)
|
---|
3158 | printf (" type: ");
|
---|
3159 | show_type (t);
|
---|
3160 | printf ("\n");
|
---|
3161 | #endif
|
---|
3162 | break;
|
---|
3163 |
|
---|
3164 | case '0': case '1': case '2': case '3': case '4':
|
---|
3165 | case '5': case '6': case '7': case '8': case '9':
|
---|
3166 | t = parse_complete_type (name);
|
---|
3167 | #if defined (HLL_DEBUG)
|
---|
3168 | printf (" type: ");
|
---|
3169 | show_type (t);
|
---|
3170 | printf ("\n");
|
---|
3171 | #endif
|
---|
3172 | break;
|
---|
3173 | }
|
---|
3174 | }
|
---|
3175 | if (alloc_flag)
|
---|
3176 | free ((void *)str); /* remove const attribute */
|
---|
3177 | }
|
---|
3178 |
|
---|
3179 |
|
---|
3180 | /* Write a `begin' subrecord to the SST. The block begins at ADDR in
|
---|
3181 | the text segment. */
|
---|
3182 |
|
---|
3183 | static size_t hll_begin (dword addr)
|
---|
3184 | {
|
---|
3185 | size_t ptr;
|
---|
3186 | struct relocation_info r;
|
---|
3187 |
|
---|
3188 | sst_start (SST_begin);
|
---|
3189 | r.r_address = sst.size;
|
---|
3190 | ptr = sst.size;
|
---|
3191 | buffer_dword (&sst, addr); /* Segment offset */
|
---|
3192 | buffer_dword (&sst, 0); /* Length of block -- patched later */
|
---|
3193 | #if 1
|
---|
3194 | buffer_nstr (&sst, ""); /* Name of block (optional) */
|
---|
3195 | #endif
|
---|
3196 | sst_end ();
|
---|
3197 |
|
---|
3198 | r.r_extern = 0;
|
---|
3199 | r.r_length = 2;
|
---|
3200 | r.r_symbolnum = N_TEXT;
|
---|
3201 | r.r_pcrel = 0;
|
---|
3202 | r.r_pad = 0;
|
---|
3203 | buffer_mem (&sst_reloc, &r, sizeof (r));
|
---|
3204 | return ptr;
|
---|
3205 | }
|
---|
3206 |
|
---|
3207 |
|
---|
3208 | /* Start of a block. Write a `begin' subrecord to the SST. The block
|
---|
3209 | begins at ADDR in the text segment. Push the block onto the block
|
---|
3210 | stack. */
|
---|
3211 |
|
---|
3212 | static void block_begin (dword addr)
|
---|
3213 | {
|
---|
3214 | size_t ptr;
|
---|
3215 |
|
---|
3216 | ptr = hll_begin (addr);
|
---|
3217 | grow_by (&block_grow, 1);
|
---|
3218 | block_stack[block_grow.count].patch_ptr = ptr;
|
---|
3219 | block_stack[block_grow.count].addr = addr;
|
---|
3220 | ++block_grow.count;
|
---|
3221 | }
|
---|
3222 |
|
---|
3223 |
|
---|
3224 | /* Write an `end' subrecord to the SST. PATCH_PTR is the sst index of
|
---|
3225 | the `begin' subrecord for this block. Add ADD_START to the start
|
---|
3226 | address of the block and set the length of the block to LENGTH, in
|
---|
3227 | bytes. */
|
---|
3228 |
|
---|
3229 | static void hll_end (size_t patch_ptr, int add_start, size_t length)
|
---|
3230 | {
|
---|
3231 | *(dword *)(sst.buf+patch_ptr+0) += add_start;
|
---|
3232 | *(dword *)(sst.buf+patch_ptr+4) = length;
|
---|
3233 | sst_start (SST_end);
|
---|
3234 | sst_end ();
|
---|
3235 | }
|
---|
3236 |
|
---|
3237 |
|
---|
3238 | /* Return TRUE iff symbol table entry S defines a function. */
|
---|
3239 |
|
---|
3240 | static int is_fun (const struct nlist *s)
|
---|
3241 | {
|
---|
3242 | const char *p;
|
---|
3243 |
|
---|
3244 | if (s->n_type != N_FUN)
|
---|
3245 | return FALSE;
|
---|
3246 | p = nextcolon (str_ptr + s->n_un.n_strx);
|
---|
3247 | if (p == NULL)
|
---|
3248 | return FALSE;
|
---|
3249 | return (p[1] == 'F' || p[1] == 'f');
|
---|
3250 | }
|
---|
3251 |
|
---|
3252 |
|
---|
3253 | /* Approximate a function prologue length by examining the code. The
|
---|
3254 | function starts at START and ends at END. */
|
---|
3255 |
|
---|
3256 | static int get_prologue_length (dword start, dword end)
|
---|
3257 | {
|
---|
3258 | dword i;
|
---|
3259 |
|
---|
3260 | if (end > text_size)
|
---|
3261 | end = text_size;
|
---|
3262 | i = start;
|
---|
3263 | if (i < end && text_ptr[i] == 0x55) ++i; /* PUSH EBP */
|
---|
3264 | if (i + 1 < end && text_ptr[i+0] == 0x89
|
---|
3265 | && text_ptr[i+1] == 0xe5) /* MOV EBP, ESP */
|
---|
3266 | i += 2;
|
---|
3267 | if (i + 2 < end && text_ptr[i+0] == 0x83
|
---|
3268 | && text_ptr[i+1] == 0xec) /* SUB ESP, n8 */
|
---|
3269 | i += 3;
|
---|
3270 | return i - start;
|
---|
3271 | }
|
---|
3272 |
|
---|
3273 |
|
---|
3274 | /* End of a function reached. Try to find the function length. I is
|
---|
3275 | the sym_ptr index of the current symbol -- we search the symbol
|
---|
3276 | table starting at I to find the next function for estimating the
|
---|
3277 | function length. */
|
---|
3278 |
|
---|
3279 | static void fun_end (int i)
|
---|
3280 | {
|
---|
3281 | int p_len;
|
---|
3282 | dword addr;
|
---|
3283 |
|
---|
3284 | addr = text_size;
|
---|
3285 | while (i < sym_count)
|
---|
3286 | {
|
---|
3287 | if (is_fun (&sym_ptr[i]))
|
---|
3288 | {
|
---|
3289 | addr = sym_ptr[i].n_value;
|
---|
3290 | break;
|
---|
3291 | }
|
---|
3292 | ++i;
|
---|
3293 | }
|
---|
3294 | if (prologue_length != -1)
|
---|
3295 | p_len = prologue_length;
|
---|
3296 | else
|
---|
3297 | p_len = get_prologue_length (proc_start_addr, addr);
|
---|
3298 | *(dword *)(sst.buf+proc_patch_base + 0) = addr - proc_start_addr;
|
---|
3299 | *(word *)(sst.buf+proc_patch_base + 4) = p_len;
|
---|
3300 | *(dword *)(sst.buf+proc_patch_base + 6) = addr - proc_start_addr;
|
---|
3301 | proc_patch_base = 0;
|
---|
3302 | sst_start (SST_end);
|
---|
3303 | sst_end ();
|
---|
3304 | }
|
---|
3305 |
|
---|
3306 |
|
---|
3307 | /* End of a block (N_RBRAC encountered). I is the sym_ptr index of
|
---|
3308 | the N_RBRAC symbol. If we reach the outmost block level, we call
|
---|
3309 | fun_end(). */
|
---|
3310 |
|
---|
3311 | static void block_end (int i)
|
---|
3312 | {
|
---|
3313 | if (block_grow.count == 0)
|
---|
3314 | {
|
---|
3315 | /** @todo fix this - broken after my last change (bird 2003-10-06) */
|
---|
3316 | /* warning ("Invalid N_RBRAC without N_LBRAC"); */
|
---|
3317 | }
|
---|
3318 | else
|
---|
3319 | {
|
---|
3320 | --block_grow.count;
|
---|
3321 | hll_end (block_stack[block_grow.count].patch_ptr, 0,
|
---|
3322 | sym_ptr[i].n_value - block_stack[block_grow.count].addr);
|
---|
3323 | if (block_grow.count == 1) /* we make one extra begin */
|
---|
3324 | {
|
---|
3325 | --block_grow.count;
|
---|
3326 | hll_end (block_stack[block_grow.count].patch_ptr, 0,
|
---|
3327 | sym_ptr[i].n_value - block_stack[block_grow.count].addr);
|
---|
3328 | }
|
---|
3329 | if (block_grow.count == 0 && proc_patch_base != 0)
|
---|
3330 | fun_end (i);
|
---|
3331 | }
|
---|
3332 | }
|
---|
3333 |
|
---|
3334 |
|
---|
3335 | /* Define a function. SYMBOL points to the sym_ptr entry. The
|
---|
3336 | function arguments are taken from the args_list array. Several
|
---|
3337 | fields of the SST entry are filled-in later, when reaching the end
|
---|
3338 | of the function. proc_patch_base is used for remembering the place
|
---|
3339 | where to patch the SST entry. */
|
---|
3340 |
|
---|
3341 | static void define_fun (const struct nlist *symbol)
|
---|
3342 | {
|
---|
3343 | struct type t, *t1, *t2, *t3;
|
---|
3344 | struct relocation_info r;
|
---|
3345 | const char *str, *p, *p2;
|
---|
3346 | const char *name, *mnglname;
|
---|
3347 | #ifdef DEMANGLE_PROC_NAMES
|
---|
3348 | char *pszFree;
|
---|
3349 | #endif
|
---|
3350 | size_t cchName, cchMnglName;
|
---|
3351 | int ti, ticlass;
|
---|
3352 |
|
---|
3353 | str = str_ptr + symbol->n_un.n_strx;
|
---|
3354 | p = nextcolon (str);
|
---|
3355 | if (p == NULL)
|
---|
3356 | abort ();
|
---|
3357 | cchName = cchMnglName = p - str;
|
---|
3358 | name = mnglname = strpool_addn (str_pool, str, cchMnglName);
|
---|
3359 | proc_start_addr = symbol->n_value;
|
---|
3360 |
|
---|
3361 | #ifdef DEMANGLE_PROC_NAMES
|
---|
3362 | /* demangle the name */
|
---|
3363 | pszFree = cplus_demangle (mnglname, DMGL_ANSI | DMGL_PARAMS);
|
---|
3364 | if (!pszFree && (*mnglname == '_' || *mnglname == '*'))
|
---|
3365 | pszFree = cplus_demangle (mnglname + 1, DMGL_ANSI | DMGL_PARAMS);
|
---|
3366 | if (pszFree)
|
---|
3367 | {
|
---|
3368 | cchName = strlen (pszFree);
|
---|
3369 | name = pszFree;
|
---|
3370 | }
|
---|
3371 | else if (*mnglname == '*')
|
---|
3372 | {
|
---|
3373 | cchName--;
|
---|
3374 | name++;
|
---|
3375 | }
|
---|
3376 | #endif
|
---|
3377 |
|
---|
3378 | /* now let's see if there is a memfunc for this name. */
|
---|
3379 | for (t1 = type_head; t1; t1 = t1->next)
|
---|
3380 | if ( t1->tag == ty_memfunc
|
---|
3381 | && t1->d.memfunc.mnglname == mnglname)
|
---|
3382 | break;
|
---|
3383 |
|
---|
3384 | if (t1)
|
---|
3385 | { /* C++ member function */
|
---|
3386 | t2 = t1->d.memfunc.type;
|
---|
3387 | if (t2 && t2->tag == ty_func && t2->d.func.domain)
|
---|
3388 | make_type (t2->d.func.domain, &ticlass);
|
---|
3389 | else
|
---|
3390 | { /* the hard way - search for the freaking string in suitable .stabs.
|
---|
3391 | * I think this is rather slow when done for many members.. :/ */
|
---|
3392 | int i;
|
---|
3393 | for (i = 0, t3 = NULL, ticlass = -1; !t3 && i < sym_count; ++i)
|
---|
3394 | switch (sym_ptr[i].n_type)
|
---|
3395 | {
|
---|
3396 | case N_LSYM:
|
---|
3397 | {
|
---|
3398 | str = str_ptr + sym_ptr[i].n_un.n_strx;
|
---|
3399 | p = nextcolon (str);
|
---|
3400 | if (p && p[1] == 'T' && p[2] == 't')
|
---|
3401 | {
|
---|
3402 | /* Now, there can be several name which NAME is a
|
---|
3403 | * substring in.
|
---|
3404 | */
|
---|
3405 | /** @todo: the string parsing still is a bit spooky. */
|
---|
3406 | for (p2 = p; (p2 = strstr (p2, mnglname)) != NULL; p2 += cchMnglName)
|
---|
3407 | if (p2[-1] == ':' && p2[cchMnglName] == ';')
|
---|
3408 | {
|
---|
3409 | int stab = atoi (&p[3]);
|
---|
3410 | t3 = stype_find (stab);
|
---|
3411 | break;
|
---|
3412 | }
|
---|
3413 | }
|
---|
3414 | break;
|
---|
3415 | }
|
---|
3416 | }
|
---|
3417 | if (t3)
|
---|
3418 | make_type (t3, &ticlass);
|
---|
3419 | if (ticlass < 0)
|
---|
3420 | {
|
---|
3421 | warning (" Can't figure out which class method '%s' is a member of!", mnglname);
|
---|
3422 | ticlass = 0;
|
---|
3423 | }
|
---|
3424 | }
|
---|
3425 |
|
---|
3426 | make_type (t1, &ti);
|
---|
3427 | sst_start (SST_memfunc);
|
---|
3428 | r.r_address = sst.size;
|
---|
3429 | buffer_dword (&sst, symbol->n_value); /* Segment offset */
|
---|
3430 | buffer_word (&sst, ti); /* Type index */
|
---|
3431 | proc_patch_base = sst.size;
|
---|
3432 | buffer_dword (&sst, 0); /* Length of proc */
|
---|
3433 | buffer_word (&sst, 0); /* Length of prologue */
|
---|
3434 | buffer_dword (&sst, 0); /* Length of prologue and body */
|
---|
3435 | buffer_word (&sst, ticlass); /* Class type (for member functions) */
|
---|
3436 | buffer_byte (&sst, 8); /* 32-bit near */
|
---|
3437 | buffer_enc (&sst, name); /* Proc name */
|
---|
3438 | sst_end ();
|
---|
3439 | }
|
---|
3440 | else
|
---|
3441 | {
|
---|
3442 | if (args_grow.count == 0)
|
---|
3443 | t1 = NULL;
|
---|
3444 | else
|
---|
3445 | {
|
---|
3446 | t.tag = ty_args;
|
---|
3447 | t.index = -1;
|
---|
3448 | t.d.args.count = args_grow.count;
|
---|
3449 | t.d.args.list = xmalloc (args_grow.count * sizeof (*args_list));
|
---|
3450 | memcpy (t.d.args.list, args_list, args_grow.count * sizeof (*args_list));
|
---|
3451 | t1 = type_add (&t);
|
---|
3452 | free (t.d.args.list);
|
---|
3453 | }
|
---|
3454 | last_fun_type.d.func.args = t1;
|
---|
3455 | last_fun_type.d.func.arg_count = args_grow.count;
|
---|
3456 | t2 = type_add (&last_fun_type);
|
---|
3457 | make_type (t2, &ti);
|
---|
3458 |
|
---|
3459 | sst_start (cplusplus_flag || cchName > 255 ? SST_CPPproc : SST_proc);
|
---|
3460 | r.r_address = sst.size;
|
---|
3461 | buffer_dword (&sst, symbol->n_value); /* Segment offset */
|
---|
3462 | buffer_word (&sst, ti); /* Type index */
|
---|
3463 | proc_patch_base = sst.size;
|
---|
3464 | buffer_dword (&sst, 0); /* Length of proc */
|
---|
3465 | buffer_word (&sst, 0); /* Length of prologue */
|
---|
3466 | buffer_dword (&sst, 0); /* Length of prologue and body */
|
---|
3467 | buffer_word (&sst, 0); /* Class type (for member functions) */
|
---|
3468 | buffer_byte (&sst, 8); /* 32-bit near */
|
---|
3469 | if (cplusplus_flag || cchName > 255)
|
---|
3470 | buffer_enc (&sst, name); /* Proc name */
|
---|
3471 | else
|
---|
3472 | buffer_nstr (&sst, name); /* Proc name */
|
---|
3473 | sst_end ();
|
---|
3474 | }
|
---|
3475 | r.r_extern = 0;
|
---|
3476 | r.r_length = 2;
|
---|
3477 | r.r_symbolnum = N_TEXT;
|
---|
3478 | r.r_pcrel = 0;
|
---|
3479 | r.r_pad = 0;
|
---|
3480 | buffer_mem (&sst_reloc, &r, sizeof (r));
|
---|
3481 | set_hll_type (symbol - sym_ptr, ti);
|
---|
3482 |
|
---|
3483 | #ifdef DEMANGLE_PROC_NAMES
|
---|
3484 | /* free the demangled name. */
|
---|
3485 | free (pszFree);
|
---|
3486 | #endif
|
---|
3487 | }
|
---|
3488 |
|
---|
3489 |
|
---|
3490 | /* Locate the next N_LBRAC starting at symbol I. If found, set
|
---|
3491 | lbrac_index to the index of N_LBRAC and start a new block. If
|
---|
3492 | there is no N_LBRAC, set lbrac_index to -1. */
|
---|
3493 |
|
---|
3494 | static void next_lbrac (int i)
|
---|
3495 | {
|
---|
3496 | lbrac_index = -1;
|
---|
3497 | for (; i < sym_count; ++i)
|
---|
3498 | if (sym_ptr[i].n_type == N_RBRAC || is_fun (&sym_ptr[i]))
|
---|
3499 | return;
|
---|
3500 | else if (sym_ptr[i].n_type == N_LBRAC)
|
---|
3501 | {
|
---|
3502 | lbrac_index = i;
|
---|
3503 | block_begin (sym_ptr[i].n_value);
|
---|
3504 | return;
|
---|
3505 | }
|
---|
3506 | }
|
---|
3507 |
|
---|
3508 |
|
---|
3509 | /* Parse a stabs symbol. The sym_ptr index is passed in INDEX. As we
|
---|
3510 | might have to concatenate successive symbol table entries, *INDEX
|
---|
3511 | is updated to refer to the next symbol. WHERE is the segment where
|
---|
3512 | the symbol is defined (N_DATA, for instance). If WHERE is -1,
|
---|
3513 | there is no segment. MSG is used for warning messages. This
|
---|
3514 | function is called recursively for static functions (F) There's up
|
---|
3515 | to one level of recursion. The arguments of a function are read
|
---|
3516 | twice: If FLAG is TRUE, we turn the arguments into local symbols;
|
---|
3517 | if FLAG is FALSE, we put arguments into the args_list array. */
|
---|
3518 |
|
---|
3519 | static void parse_symbol (int *index, int where, const char *msg, int flag)
|
---|
3520 | {
|
---|
3521 | char *name;
|
---|
3522 | const char *str, *p;
|
---|
3523 | const struct nlist *symbol;
|
---|
3524 | struct type *t1;
|
---|
3525 | int i, n, ti, alloc_flag;
|
---|
3526 |
|
---|
3527 | symbol = &sym_ptr[*index];
|
---|
3528 | alloc_flag = concat_symbols (index, &str);
|
---|
3529 | parse_start = str;
|
---|
3530 | parse_pindex = index;
|
---|
3531 | p = nextcolon (str);
|
---|
3532 | if (p != NULL)
|
---|
3533 | {
|
---|
3534 | n = p - str;
|
---|
3535 | name = alloca (n + 1);
|
---|
3536 | memcpy (name, str, n);
|
---|
3537 | name[n] = 0;
|
---|
3538 | #if defined (HLL_DEBUG)
|
---|
3539 | printf ("%s %s\n", msg, str);
|
---|
3540 | #endif
|
---|
3541 |
|
---|
3542 | parse_ptr = p + 1;
|
---|
3543 | switch (*parse_ptr)
|
---|
3544 | {
|
---|
3545 | case 'G':
|
---|
3546 | /* Static storage, global scope */
|
---|
3547 | {
|
---|
3548 | const struct nlist *sym2 = NULL;
|
---|
3549 | ++parse_ptr;
|
---|
3550 | ti = hll_type ();
|
---|
3551 | #if defined (HLL_DEBUG)
|
---|
3552 | printf (" type=%#x\n", ti);
|
---|
3553 | #endif
|
---|
3554 |
|
---|
3555 | /* Check for a ugly hack in dbxout.c which allow us to resolve
|
---|
3556 | communal and global variables more accuratly. The n_value is -12357
|
---|
3557 | and the previous entry is 0xfe. What the previous entry contains
|
---|
3558 | is the assembly name of the symbol.
|
---|
3559 |
|
---|
3560 | Another part of that hack is that n_value is contains the
|
---|
3561 | symbol value so we don't need to look up the symbol for that
|
---|
3562 | reason (but as it turns out we have to look it up to see where
|
---|
3563 | it is in most cases, bah). */
|
---|
3564 | if ( symbol->n_value == -12357
|
---|
3565 | && *index >= 1
|
---|
3566 | && symbol[-1].n_type == 0xfe)
|
---|
3567 | {
|
---|
3568 | sym2 = find_symbol_ex (symbol[-1].n_un.n_strx + str_ptr, *index - 1, 1);
|
---|
3569 | if (!sym2)
|
---|
3570 | {
|
---|
3571 | warning ("Cannot find address of communal/external variable %s", name);
|
---|
3572 | return;
|
---|
3573 | }
|
---|
3574 | }
|
---|
3575 | else if (where == -1)
|
---|
3576 | { /* This is not very nice, we have to look up the symbol
|
---|
3577 | like we used to do in order to the the segment right.
|
---|
3578 | Should probably just use the external/communal hack above
|
---|
3579 | for everything or change the n_type of the 'G' stab... However,
|
---|
3580 | this will work for most cases and it will be compatible with
|
---|
3581 | the unmodified dbxout.c code. */
|
---|
3582 | if (symbol->n_type == N_FUN) /* in case GCC change... */
|
---|
3583 | where = N_TEXT;
|
---|
3584 | else
|
---|
3585 | {
|
---|
3586 | size_t cch = strlen (name);
|
---|
3587 | char *psz = alloca (cch + 2);
|
---|
3588 | *psz = '_';
|
---|
3589 | memcpy (psz + 1, name, cch + 1);
|
---|
3590 | sym2 = find_symbol (psz);
|
---|
3591 | if (!sym2)
|
---|
3592 | sym2 = find_symbol (psz + 1);
|
---|
3593 | where = N_DATA;
|
---|
3594 | }
|
---|
3595 | }
|
---|
3596 | /* if we're lucky we've got a symbol... */
|
---|
3597 | if (sym2)
|
---|
3598 | {
|
---|
3599 | if (sym2->n_type == N_EXT)
|
---|
3600 | sst_static (name, 0, ti, sym2 - sym_ptr, 1, sym2);
|
---|
3601 | else
|
---|
3602 | sst_static (name, sym2->n_value, ti, sym2->n_type, 0, sym2);
|
---|
3603 | }
|
---|
3604 | else
|
---|
3605 | sst_static (name, symbol->n_value, ti, where, 0, NULL);
|
---|
3606 | break;
|
---|
3607 | }
|
---|
3608 |
|
---|
3609 | case 'S':
|
---|
3610 | case 'V':
|
---|
3611 |
|
---|
3612 | /* S = static storage, file scope,
|
---|
3613 | V = static storage, local scope */
|
---|
3614 |
|
---|
3615 | if (where == -1)
|
---|
3616 | {
|
---|
3617 | warning ("Cannot use symbol type %c with N_%s", *parse_ptr, msg);
|
---|
3618 | return;
|
---|
3619 | }
|
---|
3620 | ++parse_ptr;
|
---|
3621 | ti = hll_type ();
|
---|
3622 | #if defined (HLL_DEBUG)
|
---|
3623 | printf (" type=%#x\n", ti);
|
---|
3624 | #endif
|
---|
3625 | sst_static (name, symbol->n_value, ti, where, 0, NULL);
|
---|
3626 | break;
|
---|
3627 |
|
---|
3628 | case 'p':
|
---|
3629 |
|
---|
3630 | /* Function argument. */
|
---|
3631 |
|
---|
3632 | if (where != -1)
|
---|
3633 | {
|
---|
3634 | warning ("Cannot use argument symbol with N_%s", msg);
|
---|
3635 | return;
|
---|
3636 | }
|
---|
3637 | ++parse_ptr;
|
---|
3638 | if (flag)
|
---|
3639 | {
|
---|
3640 | ti = hll_type ();
|
---|
3641 | #if defined (HLL_DEBUG)
|
---|
3642 | printf (" type=%#x\n", ti);
|
---|
3643 | #endif
|
---|
3644 | sst_start (SST_auto);
|
---|
3645 | buffer_dword (&sst, symbol->n_value);/* Offset into stk frame */
|
---|
3646 | buffer_word (&sst, ti); /* Type index */
|
---|
3647 | buffer_nstr (&sst, name); /* Symbol name */
|
---|
3648 | sst_end ();
|
---|
3649 | }
|
---|
3650 | else
|
---|
3651 | {
|
---|
3652 | t1 = parse_complete_type (NULL);
|
---|
3653 | grow_by (&args_grow, 1);
|
---|
3654 | args_list[args_grow.count++] = t1;
|
---|
3655 | }
|
---|
3656 | break;
|
---|
3657 |
|
---|
3658 | case 'r':
|
---|
3659 |
|
---|
3660 | /* Register variable. */
|
---|
3661 |
|
---|
3662 | if (where != -1)
|
---|
3663 | {
|
---|
3664 | warning ("Cannot use register symbol with N_%s", msg);
|
---|
3665 | return;
|
---|
3666 | }
|
---|
3667 | ++parse_ptr;
|
---|
3668 | ti = hll_type ();
|
---|
3669 | switch (symbol->n_value)
|
---|
3670 | {
|
---|
3671 | case 0: /* EAX */
|
---|
3672 | i = 0x10;
|
---|
3673 | break;
|
---|
3674 | case 1: /* ECX */
|
---|
3675 | i = 0x11;
|
---|
3676 | break;
|
---|
3677 | case 2: /* EDX */
|
---|
3678 | i = 0x12;
|
---|
3679 | break;
|
---|
3680 | case 3: /* EBX */
|
---|
3681 | i = 0x13;
|
---|
3682 | break;
|
---|
3683 | case 4: /* ESP */
|
---|
3684 | i = 0x14;
|
---|
3685 | break;
|
---|
3686 | case 5: /* EBP */
|
---|
3687 | i = 0x15;
|
---|
3688 | break;
|
---|
3689 | case 6: /* ESI */
|
---|
3690 | i = 0x16;
|
---|
3691 | break;
|
---|
3692 | case 7: /* EDI */
|
---|
3693 | i = 0x17;
|
---|
3694 | break;
|
---|
3695 | case 12: /* ST(0) */
|
---|
3696 | i = 0x80;
|
---|
3697 | break;
|
---|
3698 | case 13: /* ST(1) */
|
---|
3699 | i = 0x81;
|
---|
3700 | break;
|
---|
3701 | case 14: /* ST(2) */
|
---|
3702 | i = 0x82;
|
---|
3703 | break;
|
---|
3704 | case 15: /* ST(3) */
|
---|
3705 | i = 0x83;
|
---|
3706 | break;
|
---|
3707 | case 16: /* ST(4) */
|
---|
3708 | i = 0x84;
|
---|
3709 | break;
|
---|
3710 | case 17: /* ST(5) */
|
---|
3711 | i = 0x85;
|
---|
3712 | break;
|
---|
3713 | case 18: /* ST(6) */
|
---|
3714 | i = 0x86;
|
---|
3715 | break;
|
---|
3716 | case 19: /* ST(7) */
|
---|
3717 | i = 0x87;
|
---|
3718 | break;
|
---|
3719 | default:
|
---|
3720 | warning ("unknown register %lu", symbol->n_value);
|
---|
3721 | return;
|
---|
3722 | }
|
---|
3723 | sst_start (SST_reg); /* Register variable */
|
---|
3724 | buffer_word (&sst, ti); /* Type index */
|
---|
3725 | buffer_byte (&sst, i); /* Register number */
|
---|
3726 | buffer_nstr (&sst, name); /* Symbol name */
|
---|
3727 | sst_end ();
|
---|
3728 | break;
|
---|
3729 |
|
---|
3730 | case '0': case '1': case '2': case '3': case '4':
|
---|
3731 | case '5': case '6': case '7': case '8': case '9':
|
---|
3732 |
|
---|
3733 | /* Local symbol. */
|
---|
3734 |
|
---|
3735 | if (where != -1)
|
---|
3736 | {
|
---|
3737 | warning ("Cannot use local symbol with N_%s", msg);
|
---|
3738 | return;
|
---|
3739 | }
|
---|
3740 | ti = hll_type ();
|
---|
3741 | #if defined (HLL_DEBUG)
|
---|
3742 | printf (" type=%#x\n", ti);
|
---|
3743 | #endif
|
---|
3744 | sst_start (SST_auto);
|
---|
3745 | buffer_dword (&sst, symbol->n_value); /* Offset into stk frame */
|
---|
3746 | buffer_word (&sst, ti); /* Type index */
|
---|
3747 | buffer_nstr (&sst, name); /* Symbol name */
|
---|
3748 | sst_end ();
|
---|
3749 | break;
|
---|
3750 |
|
---|
3751 | case 'F':
|
---|
3752 | case 'f':
|
---|
3753 |
|
---|
3754 | /* Function. */
|
---|
3755 |
|
---|
3756 | ++parse_ptr;
|
---|
3757 | if (where != N_TEXT)
|
---|
3758 | {
|
---|
3759 | warning ("Cannot use function with N_%s", msg);
|
---|
3760 | return;
|
---|
3761 | }
|
---|
3762 | last_fun_type.tag = ty_func;
|
---|
3763 | last_fun_type.index = -1;
|
---|
3764 | last_fun_type.d.func.domain = NULL;
|
---|
3765 | last_fun_type.d.func.ret = parse_type (NULL);
|
---|
3766 |
|
---|
3767 | /* Don't check for end of string -- parse_ptr points to a
|
---|
3768 | comma for nested functions! */
|
---|
3769 |
|
---|
3770 | last_fun_type.d.func.args = NULL;
|
---|
3771 | last_fun_type.d.func.arg_count = 0;
|
---|
3772 | last_fun_valid = TRUE;
|
---|
3773 | args_grow.count = 0;
|
---|
3774 | last_fun_addr = symbol->n_value;
|
---|
3775 | prologue_length = -1;
|
---|
3776 |
|
---|
3777 | for (i = *index + 1; i < sym_count && sym_ptr[i].n_type == N_PSYM; ++i)
|
---|
3778 | parse_symbol (&i, -1, "PSYM", FALSE);
|
---|
3779 |
|
---|
3780 | define_fun (symbol);
|
---|
3781 |
|
---|
3782 | /* Now look for N_LBRAC */
|
---|
3783 | next_lbrac (i);
|
---|
3784 | if (lbrac_index != -1)
|
---|
3785 | {
|
---|
3786 | if (prologue_length == -1)
|
---|
3787 | prologue_length = sym_ptr[lbrac_index].n_value - last_fun_addr;
|
---|
3788 | }
|
---|
3789 | else
|
---|
3790 | {/* kso #456 2003-06-05: We need a begin to catch the parameters. */
|
---|
3791 | prologue_length = 0;
|
---|
3792 | block_begin (proc_start_addr);
|
---|
3793 | }
|
---|
3794 |
|
---|
3795 | /* Parameters */
|
---|
3796 | while (*index + 1 < sym_count && sym_ptr[*index+1].n_type == N_PSYM)
|
---|
3797 | {
|
---|
3798 | ++(*index);
|
---|
3799 | parse_symbol (index, -1, "PSYM", TRUE);
|
---|
3800 | }
|
---|
3801 |
|
---|
3802 | /* Start another block for the local variables. This is to work
|
---|
3803 | around some missing bracets in stabs and to fix problem with
|
---|
3804 | C++ bool type. */
|
---|
3805 | dword addr = proc_start_addr + prologue_length;
|
---|
3806 | if (lbrac_index >= 0 && sym_ptr[lbrac_index].n_value > addr)
|
---|
3807 | addr = sym_ptr[lbrac_index].n_value;
|
---|
3808 | block_begin (addr);
|
---|
3809 |
|
---|
3810 | /* Local variables (fix for boolparam testcase too). */
|
---|
3811 | while (*index + 1 < sym_count && sym_ptr[*index+1].n_type == N_LSYM)
|
---|
3812 | {
|
---|
3813 | ++(*index);
|
---|
3814 | parse_symbol (index, -1, "LSYM", TRUE);
|
---|
3815 | }
|
---|
3816 |
|
---|
3817 | /* If there's no N_LBRAC, write SST_end now */
|
---|
3818 | if (lbrac_index == -1)
|
---|
3819 | {/* kso #456 2003-06-05: We need a begin to catch the parameters. */
|
---|
3820 | while (block_grow.count > 0)
|
---|
3821 | block_end (*index+1);
|
---|
3822 | }
|
---|
3823 | break;
|
---|
3824 | }
|
---|
3825 | }
|
---|
3826 | if (alloc_flag)
|
---|
3827 | free ((void *)str); /* Remove the const attribute */
|
---|
3828 | }
|
---|
3829 |
|
---|
3830 |
|
---|
3831 | /* Create a type tag for HLL type index INDEX. TYPE is either SST_tag
|
---|
3832 | (for structures and unions) or SST_tag2 (for classes). NAME is
|
---|
3833 | the name of the structure, union or class. */
|
---|
3834 |
|
---|
3835 | static void type_tag (int type, int index, const char *name)
|
---|
3836 | {
|
---|
3837 | if (name != NULL)
|
---|
3838 | {
|
---|
3839 | size_t cch;
|
---|
3840 | if (type == SST_tag2 || (cch = strlen(name)) > 250)
|
---|
3841 | {
|
---|
3842 | sst_start (SST_tag2);
|
---|
3843 | buffer_word (&sst, index);
|
---|
3844 | buffer_enc (&sst, name);
|
---|
3845 | }
|
---|
3846 | else
|
---|
3847 | {
|
---|
3848 | char achName[256];
|
---|
3849 | memcpy (achName, name, cch);
|
---|
3850 | achName[cch] = '\0';
|
---|
3851 |
|
---|
3852 | sst_start (type);
|
---|
3853 | buffer_word (&sst, index);
|
---|
3854 | buffer_nstr (&sst, achName);
|
---|
3855 | }
|
---|
3856 | sst_end ();
|
---|
3857 | }
|
---|
3858 | }
|
---|
3859 |
|
---|
3860 |
|
---|
3861 | /* Write a CuInfo SST entry to tell the debugger what compiler (C or
|
---|
3862 | C++) has been used. */
|
---|
3863 |
|
---|
3864 | static void write_cuinfo (void)
|
---|
3865 | {
|
---|
3866 | struct timestamp ts;
|
---|
3867 | time_t now;
|
---|
3868 | struct tm *tp;
|
---|
3869 | byte lang;
|
---|
3870 |
|
---|
3871 | if (cplusplus_flag)
|
---|
3872 | lang = 0x02; /* C++ */
|
---|
3873 | else
|
---|
3874 | lang = 0x01; /* C */
|
---|
3875 |
|
---|
3876 | time (&now);
|
---|
3877 | tp = localtime (&now);
|
---|
3878 | ts.year = tp->tm_year + 1900;
|
---|
3879 | ts.month = tp->tm_mon + 1;
|
---|
3880 | ts.day = tp->tm_mday;
|
---|
3881 | ts.hours = tp->tm_hour;
|
---|
3882 | ts.minutes = tp->tm_min;
|
---|
3883 | ts.seconds = tp->tm_sec;
|
---|
3884 | ts.hundredths = 0;
|
---|
3885 | sst_start (SST_cuinfo);
|
---|
3886 | buffer_byte (&sst, lang);
|
---|
3887 | buffer_nstr (&sst, " "); /* Compiler options */
|
---|
3888 | buffer_nstr (&sst, __DATE__); /* Compiler date */
|
---|
3889 | buffer_mem (&sst, &ts, sizeof (ts));
|
---|
3890 | sst_end ();
|
---|
3891 | }
|
---|
3892 |
|
---|
3893 |
|
---|
3894 | /* Write a ChangSeg SST entry to define the text segment. */
|
---|
3895 |
|
---|
3896 | static void write_changseg (void)
|
---|
3897 | {
|
---|
3898 | struct relocation_info r;
|
---|
3899 |
|
---|
3900 | sst_start (SST_changseg);
|
---|
3901 | r.r_address = sst.size;
|
---|
3902 | buffer_word (&sst, 0); /* Segment number */
|
---|
3903 | buffer_word (&sst, 0); /* Reserved */
|
---|
3904 | sst_end ();
|
---|
3905 | r.r_extern = 0;
|
---|
3906 | r.r_length = 1;
|
---|
3907 | r.r_symbolnum = N_TEXT;
|
---|
3908 | r.r_pcrel = 0;
|
---|
3909 | r.r_pad = 0;
|
---|
3910 | buffer_mem (&sst_reloc, &r, sizeof (r));
|
---|
3911 | }
|
---|
3912 |
|
---|
3913 |
|
---|
3914 | /* Convert debug information. The data is taken from the symbol and
|
---|
3915 | string tables of the current a.out module. Output is put into the
|
---|
3916 | tt, sst etc. buffers. */
|
---|
3917 |
|
---|
3918 | void convert_debug (void)
|
---|
3919 | {
|
---|
3920 | int i;
|
---|
3921 | struct type *t1, *t2;
|
---|
3922 | #if defined (HLL_DEBUG)
|
---|
3923 | setvbuf(stdout, NULL, _IONBF, 256);
|
---|
3924 | #endif
|
---|
3925 |
|
---|
3926 | str_pool = strpool_init ();
|
---|
3927 | grow_init (&stype_grow, &stype_list, sizeof (*stype_list), 32);
|
---|
3928 | type_head = NULL; hll_type_index = 512;
|
---|
3929 | grow_init (&block_grow, &block_stack, sizeof (*block_stack), 16);
|
---|
3930 | grow_init (&args_grow, &args_list, sizeof (*args_list), 16);
|
---|
3931 | last_fun_valid = FALSE; prologue_length = -1;
|
---|
3932 | unnamed_struct_number = 1;
|
---|
3933 |
|
---|
3934 | /* Check whether converting a translated C++ program. */
|
---|
3935 | #if 1 /* kso #465 2003-06-04: pretend everything is C++, that symbols is no longer present. */
|
---|
3936 | cplusplus_flag = 1;
|
---|
3937 | #else
|
---|
3938 | cplusplus_flag = (find_symbol ("__gnu_compiled_cplusplus") != NULL);
|
---|
3939 | #endif
|
---|
3940 |
|
---|
3941 |
|
---|
3942 | /* Parse the typedefs to avoid forward references. */
|
---|
3943 |
|
---|
3944 | for (i = 0; i < sym_count; ++i)
|
---|
3945 | switch (sym_ptr[i].n_type)
|
---|
3946 | {
|
---|
3947 | case N_LSYM:
|
---|
3948 | case N_LCSYM:
|
---|
3949 | case N_GSYM:
|
---|
3950 | case N_PSYM:
|
---|
3951 | case N_RSYM:
|
---|
3952 | case N_STSYM:
|
---|
3953 | case N_FUN:
|
---|
3954 | parse_typedef (&i);
|
---|
3955 | break;
|
---|
3956 | }
|
---|
3957 |
|
---|
3958 | /* Provide information about the compiler. */
|
---|
3959 |
|
---|
3960 | write_cuinfo ();
|
---|
3961 |
|
---|
3962 | /* Change the default segment. */
|
---|
3963 |
|
---|
3964 | write_changseg ();
|
---|
3965 |
|
---|
3966 | /* Parse the other symbol table entries. */
|
---|
3967 |
|
---|
3968 | lbrac_index = -1; block_grow.count = 0; proc_patch_base = 0;
|
---|
3969 | for (i = 0; i < sym_count; ++i)
|
---|
3970 | switch (sym_ptr[i].n_type)
|
---|
3971 | {
|
---|
3972 | case N_LSYM:
|
---|
3973 | parse_symbol (&i, -1, "LSYM", TRUE);
|
---|
3974 | break;
|
---|
3975 |
|
---|
3976 | case N_GSYM:
|
---|
3977 | parse_symbol (&i, -1, "GSYM", TRUE);
|
---|
3978 | break;
|
---|
3979 |
|
---|
3980 | case N_LCSYM:
|
---|
3981 | parse_symbol (&i, N_BSS, "LCSYM", TRUE);
|
---|
3982 | break;
|
---|
3983 |
|
---|
3984 | case N_STSYM:
|
---|
3985 | parse_symbol (&i, N_DATA, "STSYM", TRUE);
|
---|
3986 | break;
|
---|
3987 |
|
---|
3988 | case N_RSYM:
|
---|
3989 | parse_symbol (&i, -1, "RSYM", TRUE);
|
---|
3990 | break;
|
---|
3991 |
|
---|
3992 | case N_LBRAC:
|
---|
3993 | if (lbrac_index == -1) /* N_LBRAC without local symbols */
|
---|
3994 | block_begin (sym_ptr[i].n_value);
|
---|
3995 | else if (i != lbrac_index)
|
---|
3996 | warning ("Invalid N_LBRAC");
|
---|
3997 | next_lbrac (i + 1);
|
---|
3998 | break;
|
---|
3999 |
|
---|
4000 | case N_RBRAC:
|
---|
4001 | block_end (i);
|
---|
4002 | next_lbrac (i + 1);
|
---|
4003 | break;
|
---|
4004 |
|
---|
4005 | case N_FUN:
|
---|
4006 | parse_symbol (&i, N_TEXT, "FUN", TRUE);
|
---|
4007 | break;
|
---|
4008 | }
|
---|
4009 |
|
---|
4010 | #ifdef HASH_DEBUG
|
---|
4011 | fprintf(stderr, "\n");
|
---|
4012 | for (i = 0; i < TYPE_HASH_MAX; i++)
|
---|
4013 | if (i % 7 == 6)
|
---|
4014 | fprintf(stderr, "%3d: %4d\n", i, ctype_tag[i]);
|
---|
4015 | else
|
---|
4016 | fprintf(stderr, "%3d: %4d ", i, ctype_tag[i]);
|
---|
4017 | fprintf(stderr, "\nctypes=%d\n", ctypes);
|
---|
4018 | for (i = 0; i < TYPE_HASH_MAX; i++)
|
---|
4019 | if (ctype_tag[i] > 1000)
|
---|
4020 | {
|
---|
4021 | int j;
|
---|
4022 | unsigned au[ty_max];
|
---|
4023 | memset(&au[0], 0, sizeof(au));
|
---|
4024 | for (t1 = atype_tag[i]; t1 != NULL; t1 = t1->nexthash)
|
---|
4025 | au[t1->tag]++;
|
---|
4026 |
|
---|
4027 | fprintf(stderr, "\nIndex %d is overpopulated (%d):\n", i, ctype_tag[i]);
|
---|
4028 | for (j = 0; j < 18; j++)
|
---|
4029 | if (j % 7 == 6)
|
---|
4030 | fprintf(stderr, "%2d: %4d\n", j, au[j]);
|
---|
4031 | else
|
---|
4032 | fprintf(stderr, "%2d: %4d ", j, au[j]);
|
---|
4033 | }
|
---|
4034 | #endif
|
---|
4035 |
|
---|
4036 | /* Create tags for structures, unions and classes. */
|
---|
4037 |
|
---|
4038 | for (t1 = type_head; t1 != NULL; t1 = t1->next)
|
---|
4039 | if (t1->index != -1)
|
---|
4040 | switch (t1->tag)
|
---|
4041 | {
|
---|
4042 | case ty_struc:
|
---|
4043 | type_tag (SST_tag, t1->index, t1->d.struc.name);
|
---|
4044 | break;
|
---|
4045 | case ty_class:
|
---|
4046 | type_tag (SST_tag2, t1->index, t1->d.class.name);
|
---|
4047 | break;
|
---|
4048 | case ty_enu:
|
---|
4049 | type_tag (SST_tag, t1->index, t1->d.enu.name);
|
---|
4050 | break;
|
---|
4051 | default:
|
---|
4052 | break;
|
---|
4053 | }
|
---|
4054 |
|
---|
4055 | #ifdef HLL_DEBUG
|
---|
4056 | printf ("Stabs to HLL type mappings: %d/%d\n", stype_grow.count, stype_grow.alloc);
|
---|
4057 | for (i = 0; i < stype_grow.alloc; i++)
|
---|
4058 | if (stype_list[i])
|
---|
4059 | {
|
---|
4060 | printf (" %3d => 0x%03x/%-3d ", i + 1, stype_list[i]->index, stype_list[i]->index);
|
---|
4061 | show_type (stype_list[i]);
|
---|
4062 | printf("\n");
|
---|
4063 | }
|
---|
4064 | #endif
|
---|
4065 |
|
---|
4066 |
|
---|
4067 | /* Deallocate memory. */
|
---|
4068 |
|
---|
4069 | grow_free (&stype_grow);
|
---|
4070 | grow_free (&args_grow);
|
---|
4071 | grow_free (&block_grow);
|
---|
4072 | for (t1 = type_head; t1 != NULL; t1 = t2)
|
---|
4073 | {
|
---|
4074 | t2 = t1->next;
|
---|
4075 | switch (t1->tag)
|
---|
4076 | {
|
---|
4077 | case ty_args:
|
---|
4078 | if (t1->d.args.list != NULL)
|
---|
4079 | free (t1->d.args.list);
|
---|
4080 | break;
|
---|
4081 | case ty_types:
|
---|
4082 | if (t1->d.types.list != NULL)
|
---|
4083 | free (t1->d.types.list);
|
---|
4084 | break;
|
---|
4085 | case ty_fields:
|
---|
4086 | if (t1->d.fields.list != NULL)
|
---|
4087 | free (t1->d.fields.list);
|
---|
4088 | break;
|
---|
4089 | case ty_values:
|
---|
4090 | if (t1->d.values.list != NULL)
|
---|
4091 | free (t1->d.values.list);
|
---|
4092 | break;
|
---|
4093 | default:
|
---|
4094 | break;
|
---|
4095 | }
|
---|
4096 | free (t1);
|
---|
4097 | }
|
---|
4098 | type_head = NULL;
|
---|
4099 | memset (&atype_tag, 0, sizeof(atype_tag));
|
---|
4100 | strpool_free (str_pool);
|
---|
4101 | str_pool = NULL;
|
---|
4102 | }
|
---|