Commit | Line | Data |
---|---|---|
f5167986 ILT |
1 | /* ieee.c -- Write out IEEE-695 debugging information. |
2 | Copyright (C) 1996 Free Software Foundation, Inc. | |
3 | Written by Ian Lance Taylor <ian@cygnus.com>. | |
4 | ||
5 | This file is part of GNU Binutils. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
21 | ||
22 | /* This file reads and writes IEEE-695 debugging information. */ | |
23 | ||
24 | #include <stdio.h> | |
25 | #include <assert.h> | |
26 | ||
27 | #include "bfd.h" | |
28 | #include "ieee.h" | |
29 | #include "bucomm.h" | |
30 | #include "libiberty.h" | |
31 | #include "debug.h" | |
32 | #include "budbg.h" | |
33 | ||
34 | /* This structure holds an entry on the block stack. */ | |
35 | ||
36 | struct ieee_block | |
37 | { | |
38 | /* The kind of block. */ | |
39 | int kind; | |
40 | /* The source file name, for a BB5 block. */ | |
41 | const char *filename; | |
42 | }; | |
43 | ||
44 | /* This structure is the block stack. */ | |
45 | ||
46 | #define BLOCKSTACK_SIZE (16) | |
47 | ||
48 | struct ieee_blockstack | |
49 | { | |
50 | /* The stack pointer. */ | |
51 | struct ieee_block *bsp; | |
52 | /* The stack. */ | |
53 | struct ieee_block stack[BLOCKSTACK_SIZE]; | |
54 | }; | |
55 | ||
56 | /* This structure holds information for a variable. */ | |
57 | ||
58 | struct ieee_var | |
59 | { | |
60 | /* Start of name. */ | |
61 | const char *name; | |
62 | /* Length of name. */ | |
63 | unsigned long namlen; | |
64 | /* Type. */ | |
65 | debug_type type; | |
66 | }; | |
67 | ||
68 | /* This structure holds all the variables. */ | |
69 | ||
70 | struct ieee_vars | |
71 | { | |
72 | /* Number of slots allocated. */ | |
73 | unsigned int alloc; | |
74 | /* Variables. */ | |
75 | struct ieee_var *vars; | |
76 | }; | |
77 | ||
78 | /* This structure holds information for a type. We need this because | |
79 | we don't want to represent bitfields as real types. */ | |
80 | ||
81 | struct ieee_type | |
82 | { | |
83 | /* Type. */ | |
84 | debug_type type; | |
3d015864 ILT |
85 | /* Slot if this is type is referenced before it is defined. */ |
86 | debug_type *pslot; | |
f5167986 ILT |
87 | /* If this is a bitfield, this is the size in bits. If this is not |
88 | a bitfield, this is zero. */ | |
89 | unsigned long bitsize; | |
90 | /* If this is a function type ('x' or 'X') this is the return type. */ | |
91 | debug_type return_type; | |
92 | }; | |
93 | ||
94 | /* This structure holds all the type information. */ | |
95 | ||
96 | struct ieee_types | |
97 | { | |
98 | /* Number of slots allocated. */ | |
99 | unsigned int alloc; | |
100 | /* Types. */ | |
101 | struct ieee_type *types; | |
102 | /* Builtin types. */ | |
103 | #define BUILTIN_TYPE_COUNT (60) | |
104 | debug_type builtins[BUILTIN_TYPE_COUNT]; | |
105 | }; | |
106 | ||
3d015864 ILT |
107 | /* Basic builtin types, not including the pointers. */ |
108 | ||
109 | enum builtin_types | |
110 | { | |
111 | builtin_unknown = 0, | |
112 | builtin_void = 1, | |
113 | builtin_signed_char = 2, | |
114 | builtin_unsigned_char = 3, | |
115 | builtin_signed_short_int = 4, | |
116 | builtin_unsigned_short_int = 5, | |
117 | builtin_signed_long = 6, | |
118 | builtin_unsigned_long = 7, | |
119 | builtin_signed_long_long = 8, | |
120 | builtin_unsigned_long_long = 9, | |
121 | builtin_float = 10, | |
122 | builtin_double = 11, | |
123 | builtin_long_double = 12, | |
124 | builtin_long_long_double = 13, | |
125 | builtin_quoted_string = 14, | |
126 | builtin_instruction_address = 15, | |
127 | builtin_int = 16, | |
128 | builtin_unsigned = 17, | |
129 | builtin_unsigned_int = 18, | |
130 | builtin_char = 19, | |
131 | builtin_long = 20, | |
132 | builtin_short = 21, | |
133 | builtin_unsigned_short = 22, | |
134 | builtin_short_int = 23, | |
135 | builtin_signed_short = 24, | |
136 | builtin_bcd_float = 25 | |
137 | }; | |
138 | ||
f5167986 ILT |
139 | static void ieee_error |
140 | PARAMS ((bfd *, const bfd_byte *, const bfd_byte *, const char *)); | |
141 | static void ieee_eof PARAMS ((bfd *)); | |
142 | static char *savestring PARAMS ((const char *, unsigned long)); | |
143 | static boolean ieee_read_number | |
144 | PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *, | |
145 | bfd_vma *)); | |
146 | static boolean ieee_read_optional_number | |
147 | PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *, | |
148 | bfd_vma *, boolean *)); | |
149 | static boolean ieee_read_id | |
150 | PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *, | |
151 | const char **, unsigned long *)); | |
152 | static boolean ieee_read_optional_id | |
153 | PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *, | |
154 | const char **, unsigned long *, boolean *)); | |
155 | static boolean ieee_read_expression | |
156 | PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *, | |
157 | bfd_vma *)); | |
158 | static debug_type ieee_builtin_type | |
159 | PARAMS ((PTR, bfd *, struct ieee_types *, const bfd_byte *, | |
160 | const bfd_byte *, unsigned int)); | |
3d015864 ILT |
161 | static boolean ieee_alloc_type |
162 | PARAMS ((PTR, struct ieee_types *, unsigned int, boolean)); | |
f5167986 ILT |
163 | static boolean ieee_read_type_index |
164 | PARAMS ((PTR, bfd *, struct ieee_types *, const bfd_byte *, | |
165 | const bfd_byte **, const bfd_byte *, debug_type *)); | |
3d015864 ILT |
166 | static int ieee_regno_to_genreg PARAMS ((bfd *, int)); |
167 | static int ieee_genreg_to_regno PARAMS ((bfd *, int)); | |
f5167986 ILT |
168 | static boolean parse_ieee_bb |
169 | PARAMS ((PTR, bfd *, struct ieee_types *, struct ieee_blockstack *, | |
170 | const bfd_byte *, const bfd_byte **, const bfd_byte *)); | |
171 | static boolean parse_ieee_be | |
172 | PARAMS ((PTR, bfd *, struct ieee_blockstack *, const bfd_byte *, | |
173 | const bfd_byte **, const bfd_byte *)); | |
174 | static boolean parse_ieee_nn | |
175 | PARAMS ((PTR, bfd *, struct ieee_vars *, const bfd_byte *, | |
176 | const bfd_byte **, const bfd_byte *)); | |
177 | static boolean parse_ieee_ty | |
178 | PARAMS ((PTR, bfd *, struct ieee_types *, struct ieee_vars *, | |
179 | const bfd_byte *, const bfd_byte **, const bfd_byte *)); | |
180 | static boolean parse_ieee_atn | |
181 | PARAMS ((PTR, bfd *, struct ieee_types *, struct ieee_vars *, int, | |
182 | const bfd_byte *, const bfd_byte **, const bfd_byte *)); | |
183 | static boolean ieee_require_asn | |
184 | PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *, | |
185 | bfd_vma *)); | |
186 | ||
187 | /* Report an error in the IEEE debugging information. */ | |
188 | ||
189 | static void | |
190 | ieee_error (abfd, bytes, p, s) | |
191 | bfd *abfd; | |
192 | const bfd_byte *bytes; | |
193 | const bfd_byte *p; | |
194 | const char *s; | |
195 | { | |
196 | if (p != NULL) | |
197 | fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (abfd), | |
198 | (unsigned long) (p - bytes), s, *p); | |
199 | else | |
200 | fprintf (stderr, "%s: %s\n", bfd_get_filename (abfd), s); | |
201 | } | |
202 | ||
203 | /* Report an unexpected EOF in the IEEE debugging information. */ | |
204 | ||
205 | static void | |
206 | ieee_eof (abfd) | |
207 | bfd *abfd; | |
208 | { | |
209 | ieee_error (abfd, (const bfd_byte *) NULL, (const bfd_byte *) NULL, | |
210 | "unexpected end of debugging information"); | |
211 | } | |
212 | ||
213 | /* Save a string in memory. */ | |
214 | ||
215 | static char * | |
216 | savestring (start, len) | |
217 | const char *start; | |
218 | unsigned long len; | |
219 | { | |
220 | char *ret; | |
221 | ||
222 | ret = (char *) xmalloc (len + 1); | |
223 | memcpy (ret, start, len); | |
224 | ret[len] = '\0'; | |
225 | return ret; | |
226 | } | |
227 | ||
228 | /* Read a number which must be present in an IEEE file. */ | |
229 | ||
230 | static boolean | |
231 | ieee_read_number (abfd, bytes, pp, pend, pv) | |
232 | bfd *abfd; | |
233 | const bfd_byte *bytes; | |
234 | const bfd_byte **pp; | |
235 | const bfd_byte *pend; | |
236 | bfd_vma *pv; | |
237 | { | |
238 | return ieee_read_optional_number (abfd, bytes, pp, pend, pv, | |
239 | (boolean *) NULL); | |
240 | } | |
241 | ||
242 | /* Read a number in an IEEE file. If ppresent is not NULL, the number | |
243 | need not be there. */ | |
244 | ||
245 | static boolean | |
246 | ieee_read_optional_number (abfd, bytes, pp, pend, pv, ppresent) | |
247 | bfd *abfd; | |
248 | const bfd_byte *bytes; | |
249 | const bfd_byte **pp; | |
250 | const bfd_byte *pend; | |
251 | bfd_vma *pv; | |
252 | boolean *ppresent; | |
253 | { | |
254 | ieee_record_enum_type b; | |
255 | ||
256 | if (*pp >= pend) | |
257 | { | |
258 | if (ppresent != NULL) | |
259 | { | |
260 | *ppresent = false; | |
261 | return true; | |
262 | } | |
263 | ieee_eof (abfd); | |
264 | return false; | |
265 | } | |
266 | ||
267 | b = (ieee_record_enum_type) **pp; | |
268 | ++*pp; | |
269 | ||
270 | if (b <= ieee_number_end_enum) | |
271 | { | |
272 | *pv = (bfd_vma) b; | |
273 | if (ppresent != NULL) | |
274 | *ppresent = true; | |
275 | return true; | |
276 | } | |
277 | ||
278 | if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum) | |
279 | { | |
280 | unsigned int i; | |
281 | ||
282 | i = (int) b - (int) ieee_number_repeat_start_enum; | |
283 | if (*pp + i - 1 >= pend) | |
284 | { | |
285 | ieee_eof (abfd); | |
286 | return false; | |
287 | } | |
288 | ||
289 | *pv = 0; | |
290 | for (; i > 0; i--) | |
291 | { | |
292 | *pv <<= 8; | |
293 | *pv += **pp; | |
294 | ++*pp; | |
295 | } | |
296 | ||
297 | if (ppresent != NULL) | |
298 | *ppresent = true; | |
299 | ||
300 | return true; | |
301 | } | |
302 | ||
303 | if (ppresent != NULL) | |
304 | { | |
305 | --*pp; | |
306 | *ppresent = false; | |
307 | return true; | |
308 | } | |
309 | ||
310 | ieee_error (abfd, bytes, *pp - 1, "invalid number"); | |
311 | return false; | |
312 | } | |
313 | ||
314 | /* Read a required string from an IEEE file. */ | |
315 | ||
316 | static boolean | |
317 | ieee_read_id (abfd, bytes, pp, pend, pname, pnamlen) | |
318 | bfd *abfd; | |
319 | const bfd_byte *bytes; | |
320 | const bfd_byte **pp; | |
321 | const bfd_byte *pend; | |
322 | const char **pname; | |
323 | unsigned long *pnamlen; | |
324 | { | |
325 | return ieee_read_optional_id (abfd, bytes, pp, pend, pname, pnamlen, | |
326 | (boolean *) NULL); | |
327 | } | |
328 | ||
329 | /* Read a string from an IEEE file. If ppresent is not NULL, the | |
330 | string is optional. */ | |
331 | ||
332 | static boolean | |
333 | ieee_read_optional_id (abfd, bytes, pp, pend, pname, pnamlen, ppresent) | |
334 | bfd *abfd; | |
335 | const bfd_byte *bytes; | |
336 | const bfd_byte **pp; | |
337 | const bfd_byte *pend; | |
338 | const char **pname; | |
339 | unsigned long *pnamlen; | |
340 | boolean *ppresent; | |
341 | { | |
342 | bfd_byte b; | |
343 | unsigned long len; | |
344 | ||
345 | if (*pp >= pend) | |
346 | { | |
347 | ieee_eof (abfd); | |
348 | return false; | |
349 | } | |
350 | ||
351 | b = **pp; | |
352 | ++*pp; | |
353 | ||
354 | if (b <= 0x7f) | |
355 | len = b; | |
356 | else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum) | |
357 | { | |
358 | len = **pp; | |
359 | ++*pp; | |
360 | } | |
361 | else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum) | |
362 | { | |
363 | len = (**pp << 8) + (*pp)[1]; | |
364 | *pp += 2; | |
365 | } | |
366 | else | |
367 | { | |
368 | if (ppresent != NULL) | |
369 | { | |
370 | --*pp; | |
371 | *ppresent = false; | |
372 | return true; | |
373 | } | |
374 | ieee_error (abfd, bytes, *pp - 1, "invalid string length"); | |
375 | return false; | |
376 | } | |
377 | ||
378 | if ((unsigned long) (pend - *pp) < len) | |
379 | { | |
380 | ieee_eof (abfd); | |
381 | return false; | |
382 | } | |
383 | ||
384 | *pname = (const char *) *pp; | |
385 | *pnamlen = len; | |
386 | *pp += len; | |
387 | ||
388 | if (ppresent != NULL) | |
389 | *ppresent = true; | |
390 | ||
391 | return true; | |
392 | } | |
393 | ||
394 | /* Read an expression from an IEEE file. Since this code is only used | |
395 | to parse debugging information, I haven't bothered to write a full | |
396 | blown IEEE expression parser. I've only thrown in the things I've | |
397 | seen in debugging information. This can be easily extended if | |
398 | necessary. */ | |
399 | ||
400 | static boolean | |
401 | ieee_read_expression (abfd, bytes, pp, pend, pv) | |
402 | bfd *abfd; | |
403 | const bfd_byte *bytes; | |
404 | const bfd_byte **pp; | |
405 | const bfd_byte *pend; | |
406 | bfd_vma *pv; | |
407 | { | |
408 | const bfd_byte *expr_start; | |
409 | #define EXPR_STACK_SIZE (10) | |
410 | bfd_vma expr_stack[EXPR_STACK_SIZE]; | |
411 | bfd_vma *esp; | |
412 | ||
413 | expr_start = *pp; | |
414 | ||
415 | esp = expr_stack; | |
416 | ||
417 | while (1) | |
418 | { | |
419 | const bfd_byte *start; | |
420 | bfd_vma val; | |
421 | boolean present; | |
422 | ieee_record_enum_type c; | |
423 | ||
424 | start = *pp; | |
425 | ||
426 | if (! ieee_read_optional_number (abfd, bytes, pp, pend, &val, &present)) | |
427 | return false; | |
428 | ||
429 | if (present) | |
430 | { | |
431 | if (esp - expr_stack >= EXPR_STACK_SIZE) | |
432 | { | |
433 | ieee_error (abfd, bytes, start, "expression stack overflow"); | |
434 | return false; | |
435 | } | |
436 | *esp++ = val; | |
437 | continue; | |
438 | } | |
439 | ||
440 | c = (ieee_record_enum_type) **pp; | |
441 | ||
442 | if (c >= ieee_module_beginning_enum) | |
443 | break; | |
444 | ||
445 | ++*pp; | |
446 | ||
447 | if (c == ieee_comma) | |
448 | break; | |
449 | ||
450 | switch (c) | |
451 | { | |
452 | default: | |
453 | ieee_error (abfd, bytes, start, | |
454 | "unsupported IEEE expression operator"); | |
455 | break; | |
456 | ||
457 | case ieee_variable_R_enum: | |
458 | { | |
459 | bfd_vma indx; | |
460 | asection *s; | |
461 | ||
462 | if (! ieee_read_number (abfd, bytes, pp, pend, &indx)) | |
463 | return false; | |
464 | for (s = abfd->sections; s != NULL; s = s->next) | |
465 | if ((bfd_vma) s->target_index == indx) | |
466 | break; | |
467 | if (s == NULL) | |
468 | { | |
469 | ieee_error (abfd, bytes, start, "unknown section"); | |
470 | return false; | |
471 | } | |
472 | ||
473 | if (esp - expr_stack >= EXPR_STACK_SIZE) | |
474 | { | |
475 | ieee_error (abfd, bytes, start, "expression stack overflow"); | |
476 | return false; | |
477 | } | |
478 | ||
479 | *esp++ = bfd_get_section_vma (abfd, s); | |
480 | } | |
481 | break; | |
482 | ||
483 | case ieee_function_plus_enum: | |
484 | case ieee_function_minus_enum: | |
485 | { | |
486 | bfd_vma v1, v2; | |
487 | ||
488 | if (esp - expr_stack < 2) | |
489 | { | |
490 | ieee_error (abfd, bytes, start, "expression stack underflow"); | |
491 | return false; | |
492 | } | |
493 | ||
494 | v1 = *--esp; | |
495 | v2 = *--esp; | |
496 | *esp++ = v1 + v2; | |
497 | } | |
498 | break; | |
499 | } | |
500 | } | |
501 | ||
502 | if (esp - 1 != expr_stack) | |
503 | { | |
504 | ieee_error (abfd, bytes, expr_start, "expression stack mismatch"); | |
505 | return false; | |
506 | } | |
507 | ||
508 | *pv = *--esp; | |
509 | ||
510 | return true; | |
511 | } | |
512 | ||
513 | /* Return an IEEE builtin type. */ | |
514 | ||
515 | static debug_type | |
516 | ieee_builtin_type (dhandle, abfd, types, bytes, p, indx) | |
517 | PTR dhandle; | |
518 | bfd *abfd; | |
519 | struct ieee_types *types; | |
520 | const bfd_byte *bytes; | |
521 | const bfd_byte *p; | |
522 | unsigned int indx; | |
523 | { | |
f5167986 ILT |
524 | debug_type type; |
525 | const char *name; | |
526 | ||
527 | if (indx < BUILTIN_TYPE_COUNT | |
528 | && types->builtins[indx] != DEBUG_TYPE_NULL) | |
529 | return types->builtins[indx]; | |
530 | ||
3d015864 ILT |
531 | if (indx >= 32 && indx < 64) |
532 | { | |
533 | type = debug_make_pointer_type (dhandle, | |
534 | ieee_builtin_type (dhandle, abfd, | |
535 | types, bytes, p, | |
536 | indx - 32)); | |
537 | assert (indx < BUILTIN_TYPE_COUNT); | |
538 | types->builtins[indx] = type; | |
539 | return type; | |
540 | } | |
541 | ||
542 | switch ((enum builtin_types) indx) | |
f5167986 ILT |
543 | { |
544 | default: | |
545 | ieee_error (abfd, bytes, p, "unknown builtin type"); | |
546 | return NULL; | |
547 | ||
3d015864 | 548 | case builtin_unknown: |
f5167986 ILT |
549 | type = debug_make_void_type (dhandle); |
550 | name = NULL; | |
551 | break; | |
552 | ||
3d015864 | 553 | case builtin_void: |
f5167986 ILT |
554 | type = debug_make_void_type (dhandle); |
555 | name = "void"; | |
556 | break; | |
557 | ||
3d015864 | 558 | case builtin_signed_char: |
f5167986 ILT |
559 | type = debug_make_int_type (dhandle, 1, false); |
560 | name = "signed char"; | |
561 | break; | |
562 | ||
3d015864 | 563 | case builtin_unsigned_char: |
f5167986 ILT |
564 | type = debug_make_int_type (dhandle, 1, true); |
565 | name = "unsigned char"; | |
566 | break; | |
567 | ||
3d015864 | 568 | case builtin_signed_short_int: |
f5167986 ILT |
569 | type = debug_make_int_type (dhandle, 2, false); |
570 | name = "signed short int"; | |
571 | break; | |
572 | ||
3d015864 | 573 | case builtin_unsigned_short_int: |
f5167986 ILT |
574 | type = debug_make_int_type (dhandle, 2, true); |
575 | name = "unsigned short int"; | |
576 | break; | |
577 | ||
3d015864 | 578 | case builtin_signed_long: |
f5167986 ILT |
579 | type = debug_make_int_type (dhandle, 4, false); |
580 | name = "signed long"; | |
581 | break; | |
582 | ||
3d015864 | 583 | case builtin_unsigned_long: |
f5167986 ILT |
584 | type = debug_make_int_type (dhandle, 4, true); |
585 | name = "unsigned long"; | |
586 | break; | |
587 | ||
3d015864 | 588 | case builtin_signed_long_long: |
f5167986 ILT |
589 | type = debug_make_int_type (dhandle, 8, false); |
590 | name = "signed long long"; | |
591 | break; | |
592 | ||
3d015864 | 593 | case builtin_unsigned_long_long: |
f5167986 ILT |
594 | type = debug_make_int_type (dhandle, 8, true); |
595 | name = "unsigned long long"; | |
596 | break; | |
597 | ||
3d015864 | 598 | case builtin_float: |
f5167986 ILT |
599 | type = debug_make_float_type (dhandle, 4); |
600 | name = "float"; | |
601 | break; | |
602 | ||
3d015864 | 603 | case builtin_double: |
f5167986 ILT |
604 | type = debug_make_float_type (dhandle, 8); |
605 | name = "double"; | |
606 | break; | |
607 | ||
3d015864 | 608 | case builtin_long_double: |
f5167986 ILT |
609 | /* FIXME: The size for this type should depend upon the |
610 | processor. */ | |
611 | type = debug_make_float_type (dhandle, 12); | |
612 | name = "long double"; | |
613 | break; | |
614 | ||
3d015864 | 615 | case builtin_long_long_double: |
f5167986 ILT |
616 | type = debug_make_float_type (dhandle, 16); |
617 | name = "long long double"; | |
618 | break; | |
619 | ||
3d015864 | 620 | case builtin_quoted_string: |
f5167986 ILT |
621 | type = debug_make_array_type (dhandle, |
622 | ieee_builtin_type (dhandle, abfd, types, | |
3d015864 ILT |
623 | bytes, p, |
624 | ((unsigned int) | |
625 | builtin_char)), | |
f5167986 | 626 | ieee_builtin_type (dhandle, abfd, types, |
3d015864 ILT |
627 | bytes, p, |
628 | ((unsigned int) | |
629 | builtin_int)), | |
f5167986 ILT |
630 | 0, -1, true); |
631 | name = "QUOTED STRING"; | |
632 | break; | |
633 | ||
3d015864 | 634 | case builtin_instruction_address: |
f5167986 ILT |
635 | /* FIXME: This should be a code address. */ |
636 | type = debug_make_int_type (dhandle, 4, true); | |
637 | name = "instruction address"; | |
638 | break; | |
639 | ||
3d015864 | 640 | case builtin_int: |
f5167986 ILT |
641 | /* FIXME: The size for this type should depend upon the |
642 | processor. */ | |
643 | type = debug_make_int_type (dhandle, 4, false); | |
644 | name = "int"; | |
645 | break; | |
646 | ||
3d015864 | 647 | case builtin_unsigned: |
f5167986 ILT |
648 | /* FIXME: The size for this type should depend upon the |
649 | processor. */ | |
650 | type = debug_make_int_type (dhandle, 4, true); | |
651 | name = "unsigned"; | |
652 | break; | |
653 | ||
3d015864 | 654 | case builtin_unsigned_int: |
f5167986 ILT |
655 | /* FIXME: The size for this type should depend upon the |
656 | processor. */ | |
657 | type = debug_make_int_type (dhandle, 4, true); | |
658 | name = "unsigned int"; | |
659 | break; | |
660 | ||
3d015864 | 661 | case builtin_char: |
f5167986 ILT |
662 | type = debug_make_int_type (dhandle, 1, false); |
663 | name = "char"; | |
664 | break; | |
665 | ||
3d015864 | 666 | case builtin_long: |
f5167986 ILT |
667 | type = debug_make_int_type (dhandle, 4, false); |
668 | name = "long"; | |
669 | break; | |
670 | ||
3d015864 | 671 | case builtin_short: |
f5167986 ILT |
672 | type = debug_make_int_type (dhandle, 2, false); |
673 | name = "short"; | |
674 | break; | |
675 | ||
3d015864 | 676 | case builtin_unsigned_short: |
f5167986 ILT |
677 | type = debug_make_int_type (dhandle, 2, true); |
678 | name = "unsigned short"; | |
679 | break; | |
680 | ||
3d015864 | 681 | case builtin_short_int: |
f5167986 ILT |
682 | type = debug_make_int_type (dhandle, 2, false); |
683 | name = "short int"; | |
684 | break; | |
685 | ||
3d015864 | 686 | case builtin_signed_short: |
f5167986 ILT |
687 | type = debug_make_int_type (dhandle, 2, false); |
688 | name = "signed short"; | |
689 | break; | |
690 | ||
3d015864 | 691 | case builtin_bcd_float: |
f5167986 ILT |
692 | ieee_error (abfd, bytes, p, "BCD float type not supported"); |
693 | return false; | |
694 | } | |
695 | ||
3d015864 | 696 | if (name != NULL) |
f5167986 ILT |
697 | type = debug_name_type (dhandle, name, type); |
698 | ||
699 | assert (indx < BUILTIN_TYPE_COUNT); | |
700 | ||
701 | types->builtins[indx] = type; | |
702 | ||
703 | return type; | |
704 | } | |
705 | ||
3d015864 ILT |
706 | /* Allocate more space in the type table. If ref is true, this is a |
707 | reference to the type; if it is not already defined, we should set | |
708 | up an indirect type. */ | |
709 | ||
710 | static boolean | |
711 | ieee_alloc_type (dhandle, types, indx, ref) | |
712 | PTR dhandle; | |
713 | struct ieee_types *types; | |
714 | unsigned int indx; | |
715 | boolean ref; | |
716 | { | |
717 | unsigned int nalloc; | |
718 | register struct ieee_type *t; | |
719 | struct ieee_type *tend; | |
720 | ||
721 | if (indx >= types->alloc) | |
722 | { | |
723 | nalloc = types->alloc; | |
724 | if (nalloc == 0) | |
725 | nalloc = 4; | |
726 | while (indx >= nalloc) | |
727 | nalloc *= 2; | |
728 | ||
729 | types->types = ((struct ieee_type *) | |
730 | xrealloc (types->types, nalloc * sizeof *types->types)); | |
731 | ||
732 | memset (types->types + types->alloc, 0, | |
733 | (nalloc - types->alloc) * sizeof *types->types); | |
734 | ||
735 | tend = types->types + nalloc; | |
736 | for (t = types->types + types->alloc; t < tend; t++) | |
737 | { | |
738 | t->type = DEBUG_TYPE_NULL; | |
739 | t->return_type = DEBUG_TYPE_NULL; | |
740 | } | |
741 | ||
742 | types->alloc = nalloc; | |
743 | } | |
744 | ||
745 | if (ref) | |
746 | { | |
747 | t = types->types + indx; | |
748 | if (t->type == NULL) | |
749 | { | |
750 | t->pslot = (debug_type *) xmalloc (sizeof *t->pslot); | |
751 | *t->pslot = DEBUG_TYPE_NULL; | |
752 | t->type = debug_make_indirect_type (dhandle, t->pslot, | |
753 | (const char *) NULL); | |
754 | if (t->type == NULL) | |
755 | return false; | |
756 | } | |
757 | } | |
758 | ||
759 | return true; | |
760 | } | |
761 | ||
f5167986 ILT |
762 | /* Read a type index and return the corresponding type. */ |
763 | ||
764 | static boolean | |
765 | ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, ptype) | |
766 | PTR dhandle; | |
767 | bfd *abfd; | |
768 | struct ieee_types *types; | |
769 | const bfd_byte *bytes; | |
770 | const bfd_byte **pp; | |
771 | const bfd_byte *pend; | |
772 | debug_type *ptype; | |
773 | { | |
774 | const bfd_byte *start; | |
775 | bfd_vma indx; | |
776 | ||
777 | start = *pp; | |
778 | ||
779 | if (! ieee_read_number (abfd, bytes, pp, pend, &indx)) | |
780 | return false; | |
781 | ||
782 | if (indx < 256) | |
783 | { | |
784 | *ptype = ieee_builtin_type (dhandle, abfd, types, bytes, start, indx); | |
785 | if (*ptype == NULL) | |
786 | return false; | |
787 | return true; | |
788 | } | |
789 | ||
790 | indx -= 256; | |
3d015864 ILT |
791 | if (! ieee_alloc_type (dhandle, types, indx, true)) |
792 | return false; | |
f5167986 ILT |
793 | |
794 | *ptype = types->types[indx].type; | |
795 | ||
796 | return true; | |
797 | } | |
798 | ||
f5167986 ILT |
799 | /* Parse IEEE debugging information for a file. This is passed the |
800 | bytes which compose the Debug Information Part of an IEEE file. */ | |
801 | ||
802 | boolean | |
803 | parse_ieee (dhandle, abfd, bytes, len) | |
804 | PTR dhandle; | |
805 | bfd *abfd; | |
806 | const bfd_byte *bytes; | |
807 | bfd_size_type len; | |
808 | { | |
809 | struct ieee_blockstack blockstack; | |
810 | struct ieee_vars vars; | |
811 | struct ieee_types types; | |
812 | unsigned int i; | |
813 | const bfd_byte *p, *pend; | |
814 | ||
815 | blockstack.bsp = blockstack.stack; | |
816 | vars.alloc = 0; | |
817 | vars.vars = NULL; | |
818 | types.alloc = 0; | |
819 | types.types = NULL; | |
820 | for (i = 0; i < BUILTIN_TYPE_COUNT; i++) | |
821 | types.builtins[i] = DEBUG_TYPE_NULL; | |
822 | ||
823 | p = bytes; | |
824 | pend = bytes + len; | |
825 | while (p < pend) | |
826 | { | |
827 | const bfd_byte *record_start; | |
828 | ieee_record_enum_type c; | |
829 | ||
830 | record_start = p; | |
831 | ||
832 | c = (ieee_record_enum_type) *p++; | |
833 | ||
834 | if (c == ieee_at_record_enum) | |
835 | c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++); | |
836 | ||
837 | if (c <= ieee_number_repeat_end_enum) | |
838 | { | |
839 | ieee_error (abfd, bytes, record_start, "unexpected number"); | |
840 | return false; | |
841 | } | |
842 | ||
843 | switch (c) | |
844 | { | |
845 | default: | |
846 | ieee_error (abfd, bytes, record_start, "unexpected record type"); | |
847 | return false; | |
848 | ||
849 | case ieee_bb_record_enum: | |
850 | if (! parse_ieee_bb (dhandle, abfd, &types, &blockstack, bytes, | |
851 | &p, pend)) | |
852 | return false; | |
853 | break; | |
854 | ||
855 | case ieee_be_record_enum: | |
856 | if (! parse_ieee_be (dhandle, abfd, &blockstack, bytes, &p, pend)) | |
857 | return false; | |
858 | break; | |
859 | ||
860 | case ieee_nn_record: | |
861 | if (! parse_ieee_nn (dhandle, abfd, &vars, bytes, &p, pend)) | |
862 | return false; | |
863 | break; | |
864 | ||
865 | case ieee_ty_record_enum: | |
866 | if (! parse_ieee_ty (dhandle, abfd, &types, &vars, bytes, &p, pend)) | |
867 | return false; | |
868 | break; | |
869 | ||
870 | case ieee_atn_record_enum: | |
871 | if (! parse_ieee_atn (dhandle, abfd, &types, &vars, | |
872 | (blockstack.bsp <= blockstack.stack | |
873 | ? 0 | |
874 | : blockstack.bsp[-1].kind), | |
875 | bytes, &p, pend)) | |
876 | return false; | |
877 | break; | |
878 | } | |
879 | } | |
880 | ||
881 | if (blockstack.bsp != blockstack.stack) | |
882 | { | |
883 | ieee_error (abfd, (const bfd_byte *) NULL, (const bfd_byte *) NULL, | |
884 | "blocks left on stack at end"); | |
885 | return false; | |
886 | } | |
887 | ||
888 | return true; | |
889 | } | |
890 | ||
891 | /* Handle an IEEE BB record. */ | |
892 | ||
893 | static boolean | |
894 | parse_ieee_bb (dhandle, abfd, types, blockstack, bytes, pp, pend) | |
895 | PTR dhandle; | |
896 | bfd *abfd; | |
897 | struct ieee_types *types; | |
898 | struct ieee_blockstack *blockstack; | |
899 | const bfd_byte *bytes; | |
900 | const bfd_byte **pp; | |
901 | const bfd_byte *pend; | |
902 | { | |
903 | const bfd_byte *block_start; | |
904 | bfd_byte b; | |
905 | bfd_vma size; | |
906 | const char *name; | |
907 | unsigned long namlen; | |
908 | char *namcopy; | |
909 | ||
910 | block_start = *pp; | |
911 | ||
912 | b = **pp; | |
913 | ++*pp; | |
914 | ||
915 | if (! ieee_read_number (abfd, bytes, pp, pend, &size) | |
916 | || ! ieee_read_id (abfd, bytes, pp, pend, &name, &namlen)) | |
917 | return false; | |
918 | ||
919 | switch (b) | |
920 | { | |
921 | case 1: | |
922 | /* BB1: Type definitions local to a module. */ | |
923 | namcopy = savestring (name, namlen); | |
924 | if (namcopy == NULL) | |
925 | return false; | |
926 | if (! debug_set_filename (dhandle, namcopy)) | |
927 | return false; | |
928 | break; | |
929 | ||
930 | case 2: | |
931 | /* BB2: Global type definitions. The name is supposed to be | |
932 | empty, but we don't check. */ | |
933 | if (! debug_set_filename (dhandle, "*global*")) | |
934 | return false; | |
935 | break; | |
936 | ||
937 | case 3: | |
938 | /* BB3: High level module block begin. We don't have to do | |
939 | anything here. The name is supposed to be the same as for | |
940 | the BB1, but we don't check. */ | |
941 | break; | |
942 | ||
943 | case 4: | |
944 | /* BB4: Global function. */ | |
945 | { | |
946 | bfd_vma stackspace, typindx, offset; | |
947 | debug_type return_type; | |
948 | ||
949 | if (! ieee_read_number (abfd, bytes, pp, pend, &stackspace) | |
950 | || ! ieee_read_number (abfd, bytes, pp, pend, &typindx) | |
951 | || ! ieee_read_expression (abfd, bytes, pp, pend, &offset)) | |
952 | return false; | |
953 | ||
954 | /* We have no way to record the stack space. FIXME. */ | |
955 | ||
956 | if (typindx < 256) | |
957 | { | |
958 | return_type = ieee_builtin_type (dhandle, abfd, types, bytes, | |
959 | block_start, typindx); | |
960 | if (return_type == NULL) | |
961 | return false; | |
962 | } | |
963 | else | |
964 | { | |
965 | typindx -= 256; | |
3d015864 ILT |
966 | if (! ieee_alloc_type (dhandle, types, typindx, true)) |
967 | return false; | |
f5167986 ILT |
968 | return_type = types->types[typindx].return_type; |
969 | if (return_type == NULL) | |
970 | return_type = types->types[typindx].type; | |
971 | } | |
972 | ||
973 | namcopy = savestring (name, namlen); | |
974 | if (namcopy == NULL) | |
975 | return false; | |
976 | if (! debug_record_function (dhandle, namcopy, return_type, | |
977 | true, offset)) | |
978 | return false; | |
979 | } | |
980 | break; | |
981 | ||
982 | case 5: | |
983 | /* BB5: File name for source line numbers. */ | |
984 | { | |
985 | unsigned int i; | |
986 | ||
987 | /* We ignore the date and time. FIXME. */ | |
988 | for (i = 0; i < 6; i++) | |
989 | { | |
990 | bfd_vma ignore; | |
991 | boolean present; | |
992 | ||
993 | if (! ieee_read_optional_number (abfd, bytes, pp, pend, &ignore, | |
994 | &present)) | |
995 | return false; | |
996 | if (! present) | |
997 | break; | |
998 | } | |
999 | ||
1000 | namcopy = savestring (name, namlen); | |
1001 | if (namcopy == NULL) | |
1002 | return false; | |
1003 | if (! debug_start_source (dhandle, namcopy)) | |
1004 | return false; | |
1005 | } | |
1006 | break; | |
1007 | ||
1008 | case 6: | |
1009 | /* BB6: Local function or block. */ | |
1010 | { | |
1011 | bfd_vma stackspace, typindx, offset; | |
1012 | ||
1013 | if (! ieee_read_number (abfd, bytes, pp, pend, &stackspace) | |
1014 | || ! ieee_read_number (abfd, bytes, pp, pend, &typindx) | |
1015 | || ! ieee_read_expression (abfd, bytes, pp, pend, &offset)) | |
1016 | return false; | |
1017 | ||
1018 | /* We have no way to record the stack space. FIXME. */ | |
1019 | ||
1020 | if (namlen == 0) | |
1021 | { | |
1022 | if (! debug_start_block (dhandle, offset)) | |
1023 | return false; | |
1024 | /* Change b to indicate that this is a block | |
1025 | rather than a function. */ | |
1026 | b = 0x86; | |
1027 | } | |
1028 | else | |
1029 | { | |
1030 | debug_type return_type; | |
1031 | ||
1032 | if (typindx < 256) | |
1033 | { | |
1034 | return_type = ieee_builtin_type (dhandle, abfd, types, bytes, | |
1035 | block_start, typindx); | |
1036 | if (return_type == NULL) | |
1037 | return false; | |
1038 | } | |
1039 | else | |
1040 | { | |
1041 | typindx -= 256; | |
3d015864 ILT |
1042 | if (! ieee_alloc_type (dhandle, types, typindx, true)) |
1043 | return false; | |
f5167986 ILT |
1044 | return_type = types->types[typindx].return_type; |
1045 | if (return_type == NULL) | |
1046 | return_type = types->types[typindx].type; | |
1047 | } | |
1048 | ||
1049 | namcopy = savestring (name, namlen); | |
1050 | if (namcopy == NULL) | |
1051 | return false; | |
1052 | if (! debug_record_function (dhandle, namcopy, return_type, | |
1053 | false, offset)) | |
1054 | return false; | |
1055 | } | |
1056 | } | |
1057 | break; | |
1058 | ||
1059 | case 10: | |
1060 | /* BB10: Assembler module scope. We completely ignore all this | |
1061 | information. FIXME. */ | |
1062 | { | |
1063 | const char *inam, *vstr; | |
1064 | unsigned long inamlen, vstrlen; | |
1065 | bfd_vma tool_type; | |
1066 | boolean present; | |
1067 | unsigned int i; | |
1068 | ||
1069 | if (! ieee_read_id (abfd, bytes, pp, pend, &inam, &inamlen) | |
1070 | || ! ieee_read_number (abfd, bytes, pp, pend, &tool_type) | |
1071 | || ! ieee_read_optional_id (abfd, bytes, pp, pend, &vstr, &vstrlen, | |
1072 | &present)) | |
1073 | return false; | |
1074 | for (i = 0; i < 6; i++) | |
1075 | { | |
1076 | bfd_vma ignore; | |
1077 | ||
1078 | if (! ieee_read_optional_number (abfd, bytes, pp, pend, &ignore, | |
1079 | &present)) | |
1080 | return false; | |
1081 | if (! present) | |
1082 | break; | |
1083 | } | |
1084 | } | |
1085 | break; | |
1086 | ||
1087 | case 11: | |
1088 | /* BB11: Module section. We completely ignore all this | |
1089 | information. FIXME. */ | |
1090 | { | |
1091 | bfd_vma sectype, secindx, offset, map; | |
1092 | boolean present; | |
1093 | ||
1094 | if (! ieee_read_number (abfd, bytes, pp, pend, §ype) | |
1095 | || ! ieee_read_number (abfd, bytes, pp, pend, &secindx) | |
1096 | || ! ieee_read_expression (abfd, bytes, pp, pend, &offset) | |
1097 | || ! ieee_read_optional_number (abfd, bytes, pp, pend, &map, | |
1098 | &present)) | |
1099 | return false; | |
1100 | } | |
1101 | break; | |
1102 | ||
1103 | default: | |
1104 | ieee_error (abfd, bytes, block_start, "unknown BB type"); | |
1105 | return false; | |
1106 | } | |
1107 | ||
1108 | ||
1109 | /* Push this block on the block stack. */ | |
1110 | ||
1111 | if (blockstack->bsp >= blockstack->stack + BLOCKSTACK_SIZE) | |
1112 | { | |
1113 | ieee_error (abfd, (const bfd_byte *) NULL, (const bfd_byte *) NULL, | |
1114 | "stack overflow"); | |
1115 | return false; | |
1116 | } | |
1117 | ||
1118 | blockstack->bsp->kind = b; | |
1119 | if (b == 5) | |
1120 | blockstack->bsp->filename = namcopy; | |
1121 | ++blockstack->bsp; | |
1122 | ||
1123 | return true; | |
1124 | } | |
1125 | ||
1126 | /* Handle an IEEE BE record. */ | |
1127 | ||
1128 | static boolean | |
1129 | parse_ieee_be (dhandle, abfd, blockstack, bytes, pp, pend) | |
1130 | PTR dhandle; | |
1131 | bfd *abfd; | |
1132 | struct ieee_blockstack *blockstack; | |
1133 | const bfd_byte *bytes; | |
1134 | const bfd_byte **pp; | |
1135 | const bfd_byte *pend; | |
1136 | { | |
1137 | bfd_vma offset; | |
1138 | ||
1139 | if (blockstack->bsp <= blockstack->stack) | |
1140 | { | |
1141 | ieee_error (abfd, bytes, *pp, "stack underflow"); | |
1142 | return false; | |
1143 | } | |
1144 | --blockstack->bsp; | |
1145 | ||
1146 | switch (blockstack->bsp->kind) | |
1147 | { | |
1148 | case 4: | |
1149 | case 6: | |
1150 | if (! ieee_read_expression (abfd, bytes, pp, pend, &offset)) | |
1151 | return false; | |
1152 | if (! debug_end_function (dhandle, offset)) | |
1153 | return false; | |
1154 | break; | |
1155 | ||
1156 | case 0x86: | |
1157 | /* This is BE6 when BB6 started a block rather than a local | |
1158 | function. */ | |
1159 | if (! ieee_read_expression (abfd, bytes, pp, pend, &offset)) | |
1160 | return false; | |
1161 | if (! debug_end_block (dhandle, offset)) | |
1162 | return false; | |
1163 | break; | |
1164 | ||
1165 | case 5: | |
1166 | /* When we end a BB5, we look up the stack for the last BB5, if | |
1167 | there is one, so that we can call debug_start_source. */ | |
1168 | if (blockstack->bsp > blockstack->stack) | |
1169 | { | |
1170 | struct ieee_block *bl; | |
1171 | ||
1172 | bl = blockstack->bsp; | |
1173 | do | |
1174 | { | |
1175 | --bl; | |
1176 | if (bl->kind == 5) | |
1177 | { | |
1178 | if (! debug_start_source (dhandle, bl->filename)) | |
1179 | return false; | |
1180 | break; | |
1181 | } | |
1182 | } | |
1183 | while (bl != blockstack->stack); | |
1184 | } | |
1185 | break; | |
1186 | ||
1187 | case 11: | |
1188 | if (! ieee_read_expression (abfd, bytes, pp, pend, &offset)) | |
1189 | return false; | |
1190 | /* We just ignore the module size. FIXME. */ | |
1191 | break; | |
1192 | ||
1193 | default: | |
1194 | /* Other block types do not have any trailing information. */ | |
1195 | break; | |
1196 | } | |
1197 | ||
1198 | return true; | |
1199 | } | |
1200 | ||
1201 | /* Parse an NN record. */ | |
1202 | ||
1203 | static boolean | |
1204 | parse_ieee_nn (dhandle, abfd, vars, bytes, pp, pend) | |
1205 | PTR dhandle; | |
1206 | bfd *abfd; | |
1207 | struct ieee_vars *vars; | |
1208 | const bfd_byte *bytes; | |
1209 | const bfd_byte **pp; | |
1210 | const bfd_byte *pend; | |
1211 | { | |
1212 | const bfd_byte *nn_start; | |
1213 | bfd_vma varindx; | |
1214 | const char *name; | |
1215 | unsigned long namlen; | |
1216 | ||
1217 | nn_start = *pp; | |
1218 | ||
1219 | if (! ieee_read_number (abfd, bytes, pp, pend, &varindx) | |
1220 | || ! ieee_read_id (abfd, bytes, pp, pend, &name, &namlen)) | |
1221 | return false; | |
1222 | ||
1223 | if (varindx < 32) | |
1224 | { | |
1225 | ieee_error (abfd, bytes, nn_start, "illegal variable index"); | |
1226 | return false; | |
1227 | } | |
1228 | varindx -= 32; | |
1229 | ||
1230 | if (varindx >= vars->alloc) | |
1231 | { | |
1232 | unsigned int alloc; | |
1233 | ||
1234 | alloc = vars->alloc; | |
1235 | if (alloc == 0) | |
1236 | alloc = 4; | |
1237 | while (varindx >= alloc) | |
1238 | alloc *= 2; | |
1239 | vars->vars = ((struct ieee_var *) | |
1240 | xrealloc (vars->vars, alloc * sizeof *vars->vars)); | |
1241 | memset (vars->vars + vars->alloc, 0, | |
1242 | (alloc - vars->alloc) * sizeof *vars->vars); | |
1243 | vars->alloc = alloc; | |
1244 | } | |
1245 | ||
1246 | vars->vars[varindx].name = name; | |
1247 | vars->vars[varindx].namlen = namlen; | |
1248 | ||
1249 | return true; | |
1250 | } | |
1251 | ||
1252 | /* Parse a TY record. */ | |
1253 | ||
1254 | static boolean | |
1255 | parse_ieee_ty (dhandle, abfd, types, vars, bytes, pp, pend) | |
1256 | PTR dhandle; | |
1257 | bfd *abfd; | |
1258 | struct ieee_types *types; | |
1259 | struct ieee_vars *vars; | |
1260 | const bfd_byte *bytes; | |
1261 | const bfd_byte **pp; | |
1262 | const bfd_byte *pend; | |
1263 | { | |
1264 | const bfd_byte *ty_start, *ty_var_start, *ty_code_start; | |
1265 | bfd_vma typeindx, varindx, tc; | |
1266 | debug_type type; | |
1267 | boolean tag, typdef; | |
1268 | unsigned long type_bitsize; | |
1269 | debug_type return_type; | |
1270 | ||
1271 | ty_start = *pp; | |
1272 | ||
1273 | if (! ieee_read_number (abfd, bytes, pp, pend, &typeindx)) | |
1274 | return false; | |
1275 | ||
1276 | if (typeindx < 256) | |
1277 | { | |
1278 | ieee_error (abfd, bytes, ty_start, "illegal type index"); | |
1279 | return false; | |
1280 | } | |
f5167986 | 1281 | |
3d015864 ILT |
1282 | typeindx -= 256; |
1283 | if (! ieee_alloc_type (dhandle, types, typeindx, false)) | |
1284 | return false; | |
f5167986 ILT |
1285 | |
1286 | if (**pp != 0xce) | |
1287 | { | |
1288 | ieee_error (abfd, bytes, *pp, "unknown TY code"); | |
1289 | return false; | |
1290 | } | |
1291 | ++*pp; | |
1292 | ||
1293 | ty_var_start = *pp; | |
1294 | ||
1295 | if (! ieee_read_number (abfd, bytes, pp, pend, &varindx)) | |
1296 | return false; | |
1297 | ||
1298 | if (varindx < 32) | |
1299 | { | |
1300 | ieee_error (abfd, bytes, ty_var_start, "illegal variable index"); | |
1301 | return false; | |
1302 | } | |
1303 | varindx -= 32; | |
1304 | ||
1305 | if (varindx >= vars->alloc || vars->vars[varindx].name == NULL) | |
1306 | { | |
1307 | ieee_error (abfd, bytes, ty_var_start, "undefined variable in TY"); | |
1308 | return false; | |
1309 | } | |
1310 | ||
1311 | ty_code_start = *pp; | |
1312 | ||
1313 | if (! ieee_read_number (abfd, bytes, pp, pend, &tc)) | |
1314 | return false; | |
1315 | ||
1316 | tag = false; | |
1317 | typdef = false; | |
1318 | type_bitsize = 0; | |
1319 | return_type = DEBUG_TYPE_NULL; | |
1320 | switch (tc) | |
1321 | { | |
1322 | default: | |
1323 | ieee_error (abfd, bytes, ty_code_start, "unknown TY code"); | |
1324 | return false; | |
1325 | ||
1326 | case '!': | |
1327 | /* Unknown type, with size. We treat it as int. FIXME. */ | |
1328 | { | |
1329 | bfd_vma size; | |
1330 | ||
1331 | if (! ieee_read_number (abfd, bytes, pp, pend, &size)) | |
1332 | return false; | |
1333 | type = debug_make_int_type (dhandle, size, false); | |
1334 | } | |
1335 | break; | |
1336 | ||
1337 | case 'A': /* Array. */ | |
1338 | case 'a': /* FORTRAN array in column/row order. FIXME: Not | |
1339 | distinguished from normal array. */ | |
1340 | { | |
1341 | debug_type ele_type; | |
1342 | bfd_vma lower, upper; | |
1343 | ||
1344 | if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, | |
1345 | &ele_type) | |
1346 | || ! ieee_read_number (abfd, bytes, pp, pend, &lower) | |
1347 | || ! ieee_read_number (abfd, bytes, pp, pend, &upper)) | |
1348 | return false; | |
1349 | type = debug_make_array_type (dhandle, ele_type, | |
3d015864 ILT |
1350 | ieee_builtin_type (dhandle, abfd, types, |
1351 | bytes, ty_code_start, | |
1352 | ((unsigned int) | |
1353 | builtin_int)), | |
f5167986 ILT |
1354 | (bfd_signed_vma) lower, |
1355 | (bfd_signed_vma) upper, | |
1356 | false); | |
1357 | } | |
1358 | break; | |
1359 | ||
1360 | case 'E': | |
1361 | /* Simple enumeration. */ | |
1362 | { | |
1363 | bfd_vma size; | |
1364 | unsigned int alloc; | |
1365 | const char **names; | |
1366 | unsigned int c; | |
1367 | bfd_signed_vma *vals; | |
1368 | unsigned int i; | |
1369 | ||
1370 | if (! ieee_read_number (abfd, bytes, pp, pend, &size)) | |
1371 | return false; | |
1372 | /* FIXME: we ignore the enumeration size. */ | |
1373 | ||
1374 | alloc = 10; | |
1375 | names = (const char **) xmalloc (alloc * sizeof *names); | |
1376 | memset (names, 0, alloc * sizeof *names); | |
1377 | c = 0; | |
1378 | while (1) | |
1379 | { | |
1380 | const char *name; | |
1381 | unsigned long namlen; | |
1382 | boolean present; | |
1383 | ||
1384 | if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name, | |
1385 | &namlen, &present)) | |
1386 | return false; | |
1387 | if (! present) | |
1388 | break; | |
1389 | ||
1390 | if (c + 1 >= alloc) | |
1391 | { | |
1392 | alloc += 10; | |
1393 | names = ((const char **) | |
1394 | xrealloc (names, alloc * sizeof *names)); | |
1395 | } | |
1396 | ||
1397 | names[c] = savestring (name, namlen); | |
1398 | if (names[c] == NULL) | |
1399 | return false; | |
1400 | ++c; | |
1401 | } | |
1402 | ||
1403 | names[c] = NULL; | |
1404 | ||
1405 | vals = (bfd_signed_vma *) xmalloc (c * sizeof *vals); | |
1406 | for (i = 0; i < c; i++) | |
1407 | vals[i] = i; | |
1408 | ||
1409 | type = debug_make_enum_type (dhandle, names, vals); | |
1410 | tag = true; | |
1411 | } | |
1412 | break; | |
1413 | ||
1414 | case 'G': | |
1415 | /* Struct with bit fields. */ | |
1416 | { | |
1417 | bfd_vma size; | |
1418 | unsigned int alloc; | |
1419 | debug_field *fields; | |
1420 | unsigned int c; | |
1421 | ||
1422 | if (! ieee_read_number (abfd, bytes, pp, pend, &size)) | |
1423 | return false; | |
1424 | ||
1425 | alloc = 10; | |
1426 | fields = (debug_field *) xmalloc (alloc * sizeof *fields); | |
1427 | c = 0; | |
1428 | while (1) | |
1429 | { | |
1430 | const char *name; | |
1431 | unsigned long namlen; | |
1432 | boolean present; | |
1433 | debug_type ftype; | |
1434 | bfd_vma bitpos, bitsize; | |
1435 | ||
1436 | if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name, | |
1437 | &namlen, &present)) | |
1438 | return false; | |
1439 | if (! present) | |
1440 | break; | |
1441 | if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, | |
1442 | &ftype) | |
1443 | || ! ieee_read_number (abfd, bytes, pp, pend, &bitpos) | |
1444 | || ! ieee_read_number (abfd, bytes, pp, pend, &bitsize)) | |
1445 | return false; | |
1446 | ||
1447 | if (c + 1 >= alloc) | |
1448 | { | |
1449 | alloc += 10; | |
1450 | fields = ((debug_field *) | |
1451 | xrealloc (fields, alloc * sizeof *fields)); | |
1452 | } | |
1453 | ||
1454 | fields[c] = debug_make_field (dhandle, savestring (name, namlen), | |
1455 | ftype, bitpos, bitsize, | |
1456 | DEBUG_VISIBILITY_PUBLIC); | |
1457 | if (fields[c] == NULL) | |
1458 | return false; | |
1459 | ++c; | |
1460 | } | |
1461 | ||
1462 | fields[c] = NULL; | |
1463 | ||
1464 | type = debug_make_struct_type (dhandle, true, size, fields); | |
1465 | tag = true; | |
1466 | } | |
1467 | break; | |
1468 | ||
1469 | case 'N': | |
1470 | /* Enumeration. */ | |
1471 | { | |
1472 | unsigned int alloc; | |
1473 | const char **names; | |
1474 | bfd_signed_vma *vals; | |
1475 | unsigned int c; | |
1476 | ||
1477 | alloc = 10; | |
1478 | names = (const char **) xmalloc (alloc * sizeof *names); | |
1479 | vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *names); | |
1480 | c = 0; | |
1481 | while (1) | |
1482 | { | |
1483 | const char *name; | |
1484 | unsigned long namlen; | |
1485 | boolean present; | |
1486 | bfd_vma val; | |
1487 | ||
1488 | if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name, | |
1489 | &namlen, &present)) | |
1490 | return false; | |
1491 | if (! present) | |
1492 | break; | |
1493 | if (! ieee_read_number (abfd, bytes, pp, pend, &val)) | |
1494 | return false; | |
1495 | ||
1496 | /* If the length of the name is zero, then the value is | |
1497 | actually the size of the enum. We ignore this | |
1498 | information. FIXME. */ | |
1499 | if (namlen == 0) | |
1500 | continue; | |
1501 | ||
1502 | if (c + 1 >= alloc) | |
1503 | { | |
1504 | alloc += 10; | |
1505 | names = ((const char **) | |
1506 | xrealloc (names, alloc * sizeof *names)); | |
1507 | vals = ((bfd_signed_vma *) | |
1508 | xrealloc (vals, alloc * sizeof *vals)); | |
1509 | } | |
1510 | ||
1511 | names[c] = savestring (name, namlen); | |
1512 | if (names[c] == NULL) | |
1513 | return false; | |
1514 | vals[c] = (bfd_signed_vma) val; | |
1515 | ++c; | |
1516 | } | |
1517 | ||
1518 | names[c] = NULL; | |
1519 | ||
1520 | type = debug_make_enum_type (dhandle, names, vals); | |
1521 | tag = true; | |
1522 | } | |
1523 | break; | |
1524 | ||
1525 | case 'O': /* Small pointer. We don't distinguish small and large | |
1526 | pointers. FIXME. */ | |
1527 | case 'P': /* Large pointer. */ | |
1528 | { | |
1529 | debug_type t; | |
1530 | ||
1531 | if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, &t)) | |
1532 | return false; | |
1533 | type = debug_make_pointer_type (dhandle, t); | |
1534 | } | |
1535 | break; | |
1536 | ||
1537 | case 'R': | |
1538 | /* Range. */ | |
1539 | { | |
1540 | bfd_vma low, high, signedp, size; | |
1541 | ||
1542 | if (! ieee_read_number (abfd, bytes, pp, pend, &low) | |
1543 | || ! ieee_read_number (abfd, bytes, pp, pend, &high) | |
1544 | || ! ieee_read_number (abfd, bytes, pp, pend, &signedp) | |
1545 | || ! ieee_read_number (abfd, bytes, pp, pend, &size)) | |
1546 | return false; | |
1547 | ||
1548 | type = debug_make_range_type (dhandle, | |
1549 | debug_make_int_type (dhandle, size, | |
1550 | ! signedp), | |
1551 | (bfd_signed_vma) low, | |
1552 | (bfd_signed_vma) high); | |
1553 | } | |
1554 | break; | |
1555 | ||
1556 | case 'S': /* Struct. */ | |
1557 | case 'U': /* Union. */ | |
1558 | { | |
1559 | bfd_vma size; | |
1560 | unsigned int alloc; | |
1561 | debug_field *fields; | |
1562 | unsigned int c; | |
1563 | ||
1564 | if (! ieee_read_number (abfd, bytes, pp, pend, &size)) | |
1565 | return false; | |
1566 | ||
1567 | alloc = 10; | |
1568 | fields = (debug_field *) xmalloc (alloc * sizeof *fields); | |
1569 | c = 0; | |
1570 | while (1) | |
1571 | { | |
1572 | const char *name; | |
1573 | unsigned long namlen; | |
1574 | boolean present; | |
1575 | bfd_vma tindx; | |
1576 | bfd_vma offset; | |
1577 | debug_type ftype; | |
1578 | bfd_vma bitsize; | |
1579 | ||
1580 | if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name, | |
1581 | &namlen, &present)) | |
1582 | return false; | |
1583 | if (! present) | |
1584 | break; | |
1585 | if (! ieee_read_number (abfd, bytes, pp, pend, &tindx) | |
1586 | || ! ieee_read_number (abfd, bytes, pp, pend, &offset)) | |
1587 | return false; | |
1588 | ||
1589 | if (tindx < 256) | |
1590 | { | |
1591 | ftype = ieee_builtin_type (dhandle, abfd, types, bytes, | |
1592 | ty_code_start, tindx); | |
1593 | bitsize = 0; | |
1594 | offset *= 8; | |
1595 | } | |
1596 | else | |
1597 | { | |
1598 | struct ieee_type *t; | |
1599 | ||
1600 | tindx -= 256; | |
3d015864 ILT |
1601 | if (! ieee_alloc_type (dhandle, types, tindx, true)) |
1602 | return false; | |
1603 | t = types->types + tindx; | |
f5167986 ILT |
1604 | ftype = t->type; |
1605 | bitsize = t->bitsize; | |
1606 | if (bitsize == 0) | |
1607 | offset *= 8; | |
1608 | } | |
1609 | ||
1610 | if (c + 1 >= alloc) | |
1611 | { | |
1612 | alloc += 10; | |
1613 | fields = ((debug_field *) | |
1614 | xrealloc (fields, alloc * sizeof *fields)); | |
1615 | } | |
1616 | ||
1617 | fields[c] = debug_make_field (dhandle, savestring (name, namlen), | |
1618 | ftype, offset, bitsize, | |
1619 | DEBUG_VISIBILITY_PUBLIC); | |
1620 | if (fields[c] == NULL) | |
1621 | return false; | |
1622 | ++c; | |
1623 | } | |
1624 | ||
1625 | fields[c] = NULL; | |
1626 | ||
1627 | type = debug_make_struct_type (dhandle, tc == 'S', size, fields); | |
1628 | tag = true; | |
1629 | } | |
1630 | break; | |
1631 | ||
1632 | case 'T': | |
1633 | /* Typedef. */ | |
1634 | if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, | |
1635 | &type)) | |
1636 | return false; | |
1637 | typdef = true; | |
1638 | break; | |
1639 | ||
1640 | case 'X': | |
1641 | /* Procedure. FIXME: This is an extern declaration, which we | |
1642 | have no way of representing. */ | |
1643 | { | |
1644 | bfd_vma attr; | |
1645 | debug_type rtype; | |
1646 | bfd_vma nargs; | |
1647 | boolean present; | |
1648 | ||
1649 | /* FIXME: We ignore the attribute and the argument names. */ | |
1650 | ||
1651 | if (! ieee_read_number (abfd, bytes, pp, pend, &attr) | |
1652 | || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, | |
1653 | &rtype) | |
1654 | || ! ieee_read_number (abfd, bytes, pp, pend, &nargs)) | |
1655 | return false; | |
1656 | do | |
1657 | { | |
1658 | const char *name; | |
1659 | unsigned long namlen; | |
1660 | ||
1661 | if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name, | |
1662 | &namlen, &present)) | |
1663 | return false; | |
1664 | } | |
1665 | while (present); | |
1666 | ||
1667 | type = debug_make_function_type (dhandle, rtype); | |
1668 | return_type = rtype; | |
1669 | } | |
1670 | break; | |
1671 | ||
1672 | case 'Z': | |
1673 | /* Array with 0 lower bound. */ | |
1674 | { | |
1675 | debug_type etype; | |
1676 | bfd_vma high; | |
1677 | ||
1678 | if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, | |
1679 | &etype) | |
1680 | || ! ieee_read_number (abfd, bytes, pp, pend, &high)) | |
1681 | return false; | |
1682 | ||
1683 | type = debug_make_array_type (dhandle, etype, | |
3d015864 ILT |
1684 | ieee_builtin_type (dhandle, abfd, types, |
1685 | bytes, ty_code_start, | |
1686 | ((unsigned int) | |
1687 | builtin_int)), | |
f5167986 ILT |
1688 | 0, (bfd_signed_vma) high, false); |
1689 | } | |
1690 | break; | |
1691 | ||
1692 | case 'c': /* Complex. */ | |
1693 | case 'd': /* Double complex. */ | |
1694 | { | |
1695 | const char *name; | |
1696 | unsigned long namlen; | |
1697 | ||
1698 | /* FIXME: I don't know what the name means. */ | |
1699 | ||
1700 | if (! ieee_read_id (abfd, bytes, pp, pend, &name, &namlen)) | |
1701 | return false; | |
1702 | ||
1703 | type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8); | |
1704 | } | |
1705 | break; | |
1706 | ||
1707 | case 'f': | |
1708 | /* Pascal file name. FIXME. */ | |
1709 | ieee_error (abfd, bytes, ty_code_start, | |
1710 | "Pascal file name not supported"); | |
1711 | return false; | |
1712 | ||
1713 | case 'g': | |
1714 | /* Bitfield type. */ | |
1715 | { | |
1716 | bfd_vma signedp, bitsize; | |
1717 | ||
1718 | if (! ieee_read_number (abfd, bytes, pp, pend, &signedp) | |
1719 | || ! ieee_read_number (abfd, bytes, pp, pend, &bitsize) | |
1720 | || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, | |
1721 | &type)) | |
1722 | return false; | |
1723 | ||
1724 | /* FIXME: This is just a guess. */ | |
1725 | if (! signedp) | |
1726 | type = debug_make_int_type (dhandle, 4, true); | |
1727 | type_bitsize = bitsize; | |
1728 | } | |
1729 | break; | |
1730 | ||
1731 | case 'n': | |
1732 | /* Qualifier. */ | |
1733 | { | |
1734 | bfd_vma kind; | |
1735 | debug_type t; | |
1736 | ||
1737 | if (! ieee_read_number (abfd, bytes, pp, pend, &kind) | |
1738 | || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, | |
1739 | &t)) | |
1740 | return false; | |
1741 | ||
1742 | switch (kind) | |
1743 | { | |
1744 | default: | |
1745 | ieee_error (abfd, bytes, ty_start, "unsupported qualifer"); | |
1746 | return false; | |
1747 | ||
1748 | case 1: | |
1749 | type = debug_make_const_type (dhandle, t); | |
1750 | break; | |
1751 | ||
1752 | case 2: | |
1753 | type = debug_make_volatile_type (dhandle, t); | |
1754 | break; | |
1755 | } | |
1756 | } | |
1757 | break; | |
1758 | ||
1759 | case 's': | |
1760 | /* Set. */ | |
1761 | { | |
1762 | bfd_vma size; | |
1763 | debug_type etype; | |
1764 | ||
1765 | if (! ieee_read_number (abfd, bytes, pp, pend, &size) | |
1766 | || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, | |
1767 | &etype)) | |
1768 | return false; | |
1769 | ||
1770 | /* FIXME: We ignore the size. */ | |
1771 | ||
1772 | type = debug_make_set_type (dhandle, etype, false); | |
1773 | } | |
1774 | break; | |
1775 | ||
1776 | case 'x': | |
1777 | /* Procedure with compiler dependencies. FIXME: This is an | |
1778 | extern declaration, which we have no way of representing. */ | |
1779 | { | |
1780 | bfd_vma attr, frame_type, push_mask, nargs, level, father; | |
1781 | debug_type rtype; | |
1782 | boolean present; | |
1783 | ||
1784 | /* FIXME: We ignore almost all this information. */ | |
1785 | ||
1786 | if (! ieee_read_number (abfd, bytes, pp, pend, &attr) | |
1787 | || ! ieee_read_number (abfd, bytes, pp, pend, &frame_type) | |
1788 | || ! ieee_read_number (abfd, bytes, pp, pend, &push_mask) | |
1789 | || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, | |
1790 | &rtype) | |
1791 | || ! ieee_read_number (abfd, bytes, pp, pend, &nargs)) | |
1792 | return false; | |
1793 | if (nargs != (bfd_vma) -1) | |
1794 | { | |
1795 | for (; nargs > 0; nargs--) | |
1796 | { | |
1797 | debug_type atype; | |
1798 | ||
1799 | if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, | |
1800 | pend, &atype)) | |
1801 | return false; | |
1802 | } | |
1803 | } | |
1804 | if (! ieee_read_number (abfd, bytes, pp, pend, &level) | |
1805 | || ! ieee_read_optional_number (abfd, bytes, pp, pend, &father, | |
1806 | &present)) | |
1807 | return false; | |
1808 | ||
1809 | type = debug_make_function_type (dhandle, rtype); | |
1810 | return_type = rtype; | |
1811 | } | |
1812 | break; | |
1813 | } | |
1814 | ||
1815 | /* Record the type in the table. If the corresponding NN record has | |
1816 | a name, name it. FIXME: Is this always correct? */ | |
1817 | ||
1818 | if (type == NULL) | |
1819 | return false; | |
1820 | ||
1821 | if ((tag || typdef) | |
1822 | && vars->vars[varindx].namlen > 0) | |
1823 | { | |
1824 | const char *name; | |
1825 | ||
1826 | name = savestring (vars->vars[varindx].name, | |
1827 | vars->vars[varindx].namlen); | |
1828 | if (tag) | |
1829 | type = debug_tag_type (dhandle, name, type); | |
1830 | else | |
1831 | type = debug_name_type (dhandle, name, type); | |
1832 | if (type == NULL) | |
1833 | return false; | |
1834 | } | |
1835 | ||
1836 | types->types[typeindx].type = type; | |
1837 | types->types[typeindx].bitsize = type_bitsize; | |
1838 | types->types[typeindx].return_type = return_type; | |
1839 | ||
3d015864 ILT |
1840 | /* We may have already allocated type as an indirect type pointing |
1841 | to slot. It does no harm to replace the indirect type with the | |
1842 | real type. Filling in slot as well handles the indirect types | |
1843 | which are already hanging around. */ | |
1844 | if (types->types[typeindx].pslot != NULL) | |
1845 | *types->types[typeindx].pslot = type; | |
1846 | ||
f5167986 ILT |
1847 | return true; |
1848 | } | |
1849 | ||
1850 | /* Parse an ATN record. */ | |
1851 | ||
1852 | static boolean | |
1853 | parse_ieee_atn (dhandle, abfd, types, vars, blocktype, bytes, pp, pend) | |
1854 | PTR dhandle; | |
1855 | bfd *abfd; | |
1856 | struct ieee_types *types; | |
1857 | struct ieee_vars *vars; | |
1858 | int blocktype; | |
1859 | const bfd_byte *bytes; | |
1860 | const bfd_byte **pp; | |
1861 | const bfd_byte *pend; | |
1862 | { | |
1863 | const bfd_byte *atn_start, *atn_code_start; | |
1864 | bfd_vma varindx; | |
1865 | boolean zeroindx; | |
1866 | debug_type type; | |
1867 | bfd_vma atn_code; | |
1868 | bfd_vma v, v2, v3, v4, v5; | |
1869 | const char *name; | |
1870 | unsigned long namlen; | |
1871 | char *namcopy; | |
1872 | boolean present; | |
1873 | ||
1874 | atn_start = *pp; | |
1875 | ||
1876 | if (! ieee_read_number (abfd, bytes, pp, pend, &varindx) | |
1877 | || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, &type)) | |
1878 | return false; | |
1879 | ||
1880 | atn_code_start = *pp; | |
1881 | ||
1882 | if (! ieee_read_number (abfd, bytes, pp, pend, &atn_code)) | |
1883 | return false; | |
1884 | ||
1885 | if (varindx == 0) | |
1886 | { | |
1887 | zeroindx = true; | |
1888 | name = ""; | |
1889 | namlen = 0; | |
1890 | } | |
1891 | else if (varindx < 32) | |
1892 | { | |
1893 | ieee_error (abfd, bytes, atn_start, "illegal variable index"); | |
1894 | return false; | |
1895 | } | |
1896 | else | |
1897 | { | |
1898 | varindx -= 32; | |
1899 | zeroindx = false; | |
1900 | if (varindx >= vars->alloc || vars->vars[varindx].name == NULL) | |
1901 | { | |
1902 | ieee_error (abfd, bytes, atn_start, "undefined variable in ATN"); | |
1903 | return false; | |
1904 | } | |
1905 | ||
1906 | vars->vars[varindx].type = type; | |
1907 | ||
1908 | name = vars->vars[varindx].name; | |
1909 | namlen = vars->vars[varindx].namlen; | |
1910 | } | |
1911 | ||
1912 | switch (atn_code) | |
1913 | { | |
1914 | default: | |
1915 | ieee_error (abfd, bytes, atn_code_start, "unknown ATN type"); | |
1916 | return false; | |
1917 | ||
1918 | case 1: | |
1919 | /* Automatic variable. */ | |
1920 | if (! ieee_read_number (abfd, bytes, pp, pend, &v)) | |
1921 | return false; | |
1922 | namcopy = savestring (name, namlen); | |
1923 | if (type == NULL) | |
1924 | type = debug_make_void_type (dhandle); | |
1925 | return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v); | |
1926 | ||
1927 | case 2: | |
1928 | /* Register variable. */ | |
1929 | if (! ieee_read_number (abfd, bytes, pp, pend, &v)) | |
1930 | return false; | |
1931 | namcopy = savestring (name, namlen); | |
1932 | if (type == NULL) | |
1933 | type = debug_make_void_type (dhandle); | |
1934 | return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, | |
3d015864 | 1935 | ieee_regno_to_genreg (abfd, v)); |
f5167986 ILT |
1936 | |
1937 | case 3: | |
1938 | /* Static variable. */ | |
1939 | if (! ieee_require_asn (abfd, bytes, pp, pend, &v)) | |
1940 | return false; | |
1941 | namcopy = savestring (name, namlen); | |
1942 | if (type == NULL) | |
1943 | type = debug_make_void_type (dhandle); | |
1944 | return debug_record_variable (dhandle, namcopy, type, | |
1945 | (blocktype == 4 || blocktype == 6 | |
1946 | ? DEBUG_LOCAL_STATIC | |
1947 | : DEBUG_STATIC), | |
1948 | v); | |
1949 | ||
1950 | case 4: | |
1951 | /* External function. We don't currently record these. FIXME. */ | |
1952 | return true; | |
1953 | ||
1954 | case 5: | |
1955 | /* External variable. We don't currently record these. FIXME. */ | |
1956 | return true; | |
1957 | ||
1958 | case 7: | |
1959 | if (! ieee_read_number (abfd, bytes, pp, pend, &v) | |
1960 | || ! ieee_read_number (abfd, bytes, pp, pend, &v2) | |
1961 | || ! ieee_read_optional_number (abfd, bytes, pp, pend, &v3, | |
1962 | &present)) | |
1963 | return false; | |
1964 | if (present) | |
1965 | { | |
1966 | if (! ieee_read_optional_number (abfd, bytes, pp, pend, &v4, | |
1967 | &present)) | |
1968 | return false; | |
1969 | } | |
1970 | ||
1971 | /* We just ignore the two optional fields in v3 and v4, since | |
1972 | they are not defined. */ | |
1973 | ||
1974 | if (! ieee_require_asn (abfd, bytes, pp, pend, &v3)) | |
1975 | return false; | |
1976 | ||
1977 | /* We have no way to record the column number. FIXME. */ | |
1978 | ||
1979 | return debug_record_line (dhandle, v, v3); | |
1980 | ||
1981 | case 8: | |
1982 | /* Global variable. */ | |
1983 | if (! ieee_require_asn (abfd, bytes, pp, pend, &v)) | |
1984 | return false; | |
1985 | namcopy = savestring (name, namlen); | |
1986 | if (type == NULL) | |
1987 | type = debug_make_void_type (dhandle); | |
1988 | return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v); | |
1989 | ||
1990 | case 9: | |
1991 | /* Variable lifetime information. */ | |
1992 | if (! ieee_read_number (abfd, bytes, pp, pend, &v)) | |
1993 | return false; | |
1994 | ||
1995 | /* We have no way to record this information. FIXME. */ | |
1996 | return true; | |
1997 | ||
1998 | case 10: | |
1999 | /* Locked register. */ | |
2000 | if (! ieee_read_number (abfd, bytes, pp, pend, &v) | |
2001 | || ! ieee_read_number (abfd, bytes, pp, pend, &v2)) | |
2002 | return false; | |
2003 | ||
3d015864 ILT |
2004 | /* I think this means a variable that is both in a register and |
2005 | a frame slot. We ignore the frame slot. FIXME. */ | |
f5167986 | 2006 | |
3d015864 ILT |
2007 | namcopy = savestring (name, namlen); |
2008 | if (type == NULL) | |
2009 | type = debug_make_void_type (dhandle); | |
2010 | return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, v); | |
f5167986 ILT |
2011 | |
2012 | case 11: | |
2013 | /* Reserved for FORTRAN common. */ | |
2014 | ieee_error (abfd, bytes, atn_code_start, "unsupported ATN11"); | |
2015 | ||
2016 | /* Return true to keep going. */ | |
2017 | return true; | |
2018 | ||
2019 | case 12: | |
2020 | /* Based variable. */ | |
2021 | v3 = 0; | |
2022 | v4 = 0x80; | |
2023 | v5 = 0; | |
2024 | if (! ieee_read_number (abfd, bytes, pp, pend, &v) | |
2025 | || ! ieee_read_number (abfd, bytes, pp, pend, &v2) | |
2026 | || ! ieee_read_optional_number (abfd, bytes, pp, pend, &v3, | |
2027 | &present)) | |
2028 | return false; | |
2029 | if (present) | |
2030 | { | |
2031 | if (! ieee_read_optional_number (abfd, bytes, pp, pend, &v4, | |
2032 | &present)) | |
2033 | return false; | |
2034 | if (present) | |
2035 | { | |
2036 | if (! ieee_read_optional_number (abfd, bytes, pp, pend, &v5, | |
2037 | &present)) | |
2038 | return false; | |
2039 | } | |
2040 | } | |
2041 | ||
2042 | /* We have no way to record this information. FIXME. */ | |
2043 | ||
2044 | ieee_error (abfd, bytes, atn_code_start, "unsupported ATN12"); | |
2045 | ||
2046 | /* Return true to keep going. */ | |
2047 | return true; | |
2048 | ||
2049 | case 16: | |
2050 | /* Constant. The description of this that I have is ambiguous, | |
2051 | so I'm not going to try to implement it. */ | |
2052 | ieee_error (abfd, bytes, atn_code_start, "unsupported ATN16"); | |
2053 | return false; | |
2054 | ||
2055 | case 19: | |
2056 | /* Static variable from assembler. */ | |
2057 | v2 = 0; | |
2058 | if (! ieee_read_number (abfd, bytes, pp, pend, &v) | |
2059 | || ! ieee_read_optional_number (abfd, bytes, pp, pend, &v2, | |
2060 | &present) | |
2061 | || ! ieee_require_asn (abfd, bytes, pp, pend, &v3)) | |
2062 | return false; | |
2063 | namcopy = savestring (name, namlen); | |
2064 | /* We don't really handle this correctly. FIXME. */ | |
2065 | return debug_record_variable (dhandle, namcopy, | |
2066 | debug_make_void_type (dhandle), | |
2067 | v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC, | |
2068 | v3); | |
2069 | ||
2070 | case 62: | |
2071 | /* Procedure miscellaneous information. */ | |
2072 | case 63: | |
2073 | /* Variable miscellaneous information. */ | |
2074 | case 64: | |
2075 | /* Module miscellaneous information. */ | |
2076 | if (! ieee_read_number (abfd, bytes, pp, pend, &v) | |
2077 | || ! ieee_read_number (abfd, bytes, pp, pend, &v2) | |
2078 | || ! ieee_read_optional_id (abfd, bytes, pp, pend, &name, &namlen, | |
2079 | &present)) | |
2080 | return false; | |
2081 | ||
2082 | /* We just ignore all of this stuff. FIXME. */ | |
2083 | ||
2084 | for (; v2 > 0; --v2) | |
2085 | { | |
2086 | ieee_record_enum_type c; | |
2087 | bfd_vma vindx; | |
2088 | const char *str; | |
2089 | unsigned long strlen; | |
2090 | ||
2091 | c = (ieee_record_enum_type) **pp; | |
2092 | ++*pp; | |
2093 | if (c != ieee_at_record_enum | |
2094 | && c != ieee_e2_first_byte_enum) | |
2095 | { | |
2096 | ieee_error (abfd, bytes, *pp - 1, "bad misc record"); | |
2097 | return false; | |
2098 | } | |
2099 | ||
2100 | c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp); | |
2101 | ++*pp; | |
2102 | switch (c) | |
2103 | { | |
2104 | default: | |
2105 | ieee_error (abfd, bytes, *pp - 2, "bad misc record"); | |
2106 | return false; | |
2107 | ||
2108 | case ieee_atn_record_enum: | |
2109 | if (! ieee_read_number (abfd, bytes, pp, pend, &vindx)) | |
2110 | return false; | |
2111 | if ((*pp)[0] != 0 || (*pp)[1] != 65) | |
2112 | { | |
2113 | ieee_error (abfd, bytes, *pp, "bad atn in misc"); | |
2114 | return false; | |
2115 | } | |
2116 | *pp += 2; | |
2117 | if (! ieee_read_id (abfd, bytes, pp, pend, &str, &strlen)) | |
2118 | return false; | |
2119 | break; | |
2120 | ||
2121 | case ieee_asn_record_enum: | |
2122 | if (! ieee_read_number (abfd, bytes, pp, pend, &vindx) | |
2123 | || ! ieee_read_expression (abfd, bytes, pp, pend, &v3)) | |
2124 | return false; | |
2125 | break; | |
2126 | } | |
2127 | } | |
2128 | ||
2129 | return true; | |
2130 | } | |
2131 | ||
2132 | /*NOTREACHED*/ | |
2133 | } | |
2134 | ||
2135 | /* Require an ASN record. */ | |
2136 | ||
2137 | static boolean | |
2138 | ieee_require_asn (abfd, bytes, pp, pend, pv) | |
2139 | bfd *abfd; | |
2140 | const bfd_byte *bytes; | |
2141 | const bfd_byte **pp; | |
2142 | const bfd_byte *pend; | |
2143 | bfd_vma *pv; | |
2144 | { | |
2145 | const bfd_byte *start; | |
2146 | ieee_record_enum_type c; | |
2147 | bfd_vma varindx; | |
2148 | ||
2149 | start = *pp; | |
2150 | ||
2151 | c = (ieee_record_enum_type) **pp; | |
2152 | if (c != ieee_e2_first_byte_enum) | |
2153 | { | |
2154 | ieee_error (abfd, bytes, start, "missing required ASN"); | |
2155 | return false; | |
2156 | } | |
2157 | ++*pp; | |
2158 | ||
2159 | c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp); | |
2160 | if (c != ieee_asn_record_enum) | |
2161 | { | |
2162 | ieee_error (abfd, bytes, start, "missing required ASN"); | |
2163 | return false; | |
2164 | } | |
2165 | ++*pp; | |
2166 | ||
2167 | /* Just ignore the variable index. */ | |
2168 | if (! ieee_read_number (abfd, bytes, pp, pend, &varindx)) | |
2169 | return false; | |
2170 | ||
2171 | return ieee_read_expression (abfd, bytes, pp, pend, pv); | |
2172 | } | |
3d015864 ILT |
2173 | \f |
2174 | /* Convert a register number in IEEE debugging information into a | |
2175 | generic register number. */ | |
2176 | ||
2177 | static int | |
2178 | ieee_regno_to_genreg (abfd, r) | |
2179 | bfd *abfd; | |
2180 | int r; | |
2181 | { | |
2182 | return r; | |
2183 | } | |
2184 | ||
2185 | /* Convert a generic register number to an IEEE specific one. */ | |
2186 | ||
2187 | static int | |
2188 | ieee_genreg_to_regno (abfd, r) | |
2189 | bfd *abfd; | |
2190 | int r; | |
2191 | { | |
2192 | return r; | |
2193 | } | |
2194 | \f | |
2195 | /* These routines build IEEE debugging information out of the generic | |
2196 | debugging information. */ | |
2197 | ||
2198 | /* We build the IEEE debugging information byte by byte. Rather than | |
2199 | waste time copying data around, we use a linked list of buffers to | |
2200 | hold the data. */ | |
2201 | ||
2202 | #define IEEE_BUFSIZE (490) | |
2203 | ||
2204 | struct ieee_buf | |
2205 | { | |
2206 | /* Next buffer. */ | |
2207 | struct ieee_buf *next; | |
2208 | /* Number of data bytes in this buffer. */ | |
2209 | unsigned int c; | |
2210 | /* Bytes. */ | |
2211 | bfd_byte buf[IEEE_BUFSIZE]; | |
2212 | }; | |
2213 | ||
2214 | /* In order to generate the BB11 blocks required by the HP emulator, | |
2215 | we keep track of ranges of addresses which correspond to a given | |
2216 | compilation unit. */ | |
2217 | ||
2218 | struct ieee_range | |
2219 | { | |
2220 | /* Next range. */ | |
2221 | struct ieee_range *next; | |
2222 | /* Low address. */ | |
2223 | bfd_vma low; | |
2224 | /* High address. */ | |
2225 | bfd_vma high; | |
2226 | }; | |
2227 | ||
2228 | /* This is how we store types for the writing routines. Most types | |
2229 | are simply represented by a type index. */ | |
2230 | ||
2231 | struct ieee_write_type | |
2232 | { | |
2233 | /* Type index. */ | |
2234 | unsigned int indx; | |
2235 | /* The size of the type, if known. */ | |
2236 | unsigned int size; | |
2237 | /* If this is a struct, this is where the struct definition is | |
2238 | built. */ | |
2239 | struct ieee_buf *strdef; | |
2240 | /* Whether the type is unsigned. */ | |
2241 | unsigned int unsignedp : 1; | |
2242 | /* Whether this is a reference type. */ | |
2243 | unsigned int referencep : 1; | |
2244 | }; | |
2245 | ||
2246 | /* This is the type stack used by the debug writing routines. FIXME: | |
2247 | We could generate more efficient output if we remembered when we | |
2248 | have output a particular type before. */ | |
2249 | ||
2250 | struct ieee_type_stack | |
2251 | { | |
2252 | /* Next entry on stack. */ | |
2253 | struct ieee_type_stack *next; | |
2254 | /* Type information. */ | |
2255 | struct ieee_write_type type; | |
2256 | }; | |
2257 | ||
2258 | /* This is a list of associations between names and types. This could | |
2259 | be more efficiently implemented as a hash table. */ | |
2260 | ||
2261 | struct ieee_name_type | |
2262 | { | |
2263 | /* Next name/type assocation. */ | |
2264 | struct ieee_name_type *next; | |
2265 | /* Name. */ | |
2266 | const char *name; | |
2267 | /* Type. */ | |
2268 | struct ieee_write_type type; | |
2269 | /* If this is a tag which has not yet been defined, this is the | |
2270 | kind. If the tag has been defined, this is DEBUG_KIND_VOID. */ | |
2271 | enum debug_type_kind kind; | |
2272 | }; | |
2273 | ||
2274 | /* This is a list of pending function parameter information. We don't | |
2275 | output them until we see the first block. */ | |
2276 | ||
2277 | struct ieee_pending_parm | |
2278 | { | |
2279 | /* Next pending parameter. */ | |
2280 | struct ieee_pending_parm *next; | |
2281 | /* Name. */ | |
2282 | const char *name; | |
2283 | /* Type index. */ | |
2284 | unsigned int type; | |
2285 | /* Kind. */ | |
2286 | enum debug_parm_kind kind; | |
2287 | /* Value. */ | |
2288 | bfd_vma val; | |
2289 | }; | |
2290 | ||
2291 | /* This is the handle passed down by debug_write. */ | |
2292 | ||
2293 | struct ieee_handle | |
2294 | { | |
2295 | /* BFD we are writing to. */ | |
2296 | bfd *abfd; | |
2297 | /* Current data buffer. */ | |
2298 | struct ieee_buf *current; | |
2299 | /* Filename of current compilation unit. */ | |
2300 | const char *filename; | |
2301 | /* Module name of current compilation unit. */ | |
2302 | const char *modname; | |
2303 | /* List of finished data buffers. */ | |
2304 | struct ieee_buf *data; | |
2305 | /* List of buffers for typedefs in the current compilation unit. */ | |
2306 | struct ieee_buf *types; | |
2307 | /* List of buffers for variables and functions in the current | |
2308 | compilation unit. */ | |
2309 | struct ieee_buf *vars; | |
2310 | /* List of buffers for line numbers in the current compilation unit. */ | |
2311 | struct ieee_buf *linenos; | |
2312 | /* Ranges for the current compilation unit. */ | |
2313 | struct ieee_range *ranges; | |
2314 | /* Nested pending ranges. */ | |
2315 | struct ieee_range *pending_ranges; | |
2316 | /* Type stack. */ | |
2317 | struct ieee_type_stack *type_stack; | |
2318 | /* Next unallocated type index. */ | |
2319 | unsigned int type_indx; | |
2320 | /* Next unallocated name index. */ | |
2321 | unsigned int name_indx; | |
2322 | /* Typedefs. */ | |
2323 | struct ieee_name_type *typedefs; | |
2324 | /* Tags. */ | |
2325 | struct ieee_name_type *tags; | |
2326 | /* The depth of block nesting. This is 0 outside a function, and 1 | |
2327 | just after start_function is called. */ | |
2328 | unsigned int block_depth; | |
2329 | /* Pending function parameters. */ | |
2330 | struct ieee_pending_parm *pending_parms; | |
2331 | /* Current line number filename. */ | |
2332 | const char *lineno_filename; | |
2333 | /* Line number name index. */ | |
2334 | unsigned int lineno_name_indx; | |
2335 | }; | |
2336 | ||
2337 | static boolean ieee_change_buffer | |
2338 | PARAMS ((struct ieee_handle *, struct ieee_buf **)); | |
2339 | static boolean ieee_push_type | |
2340 | PARAMS ((struct ieee_handle *, unsigned int, unsigned int, boolean)); | |
2341 | static unsigned int ieee_pop_type PARAMS ((struct ieee_handle *)); | |
2342 | static boolean ieee_add_range | |
2343 | PARAMS ((struct ieee_handle *, bfd_vma, bfd_vma)); | |
2344 | static boolean ieee_start_range PARAMS ((struct ieee_handle *, bfd_vma)); | |
2345 | static boolean ieee_end_range PARAMS ((struct ieee_handle *, bfd_vma)); | |
2346 | static boolean ieee_real_write_byte PARAMS ((struct ieee_handle *, int)); | |
2347 | static boolean ieee_write_2bytes PARAMS ((struct ieee_handle *, int)); | |
2348 | static boolean ieee_write_number PARAMS ((struct ieee_handle *, bfd_vma)); | |
2349 | static boolean ieee_write_id PARAMS ((struct ieee_handle *, const char *)); | |
2350 | static boolean ieee_define_type | |
2351 | PARAMS ((struct ieee_handle *, unsigned int, boolean)); | |
2352 | static boolean ieee_define_named_type | |
2353 | PARAMS ((struct ieee_handle *, const char *, boolean, unsigned int, boolean, | |
2354 | struct ieee_buf **)); | |
2355 | static boolean ieee_finish_compilation_unit PARAMS ((struct ieee_handle *)); | |
2356 | static boolean ieee_output_pending_parms PARAMS ((struct ieee_handle *)); | |
2357 | ||
2358 | static boolean ieee_start_compilation_unit PARAMS ((PTR, const char *)); | |
2359 | static boolean ieee_start_source PARAMS ((PTR, const char *)); | |
2360 | static boolean ieee_empty_type PARAMS ((PTR)); | |
2361 | static boolean ieee_void_type PARAMS ((PTR)); | |
2362 | static boolean ieee_int_type PARAMS ((PTR, unsigned int, boolean)); | |
2363 | static boolean ieee_float_type PARAMS ((PTR, unsigned int)); | |
2364 | static boolean ieee_complex_type PARAMS ((PTR, unsigned int)); | |
2365 | static boolean ieee_bool_type PARAMS ((PTR, unsigned int)); | |
2366 | static boolean ieee_enum_type | |
2367 | PARAMS ((PTR, const char *, const char **, bfd_signed_vma *)); | |
2368 | static boolean ieee_pointer_type PARAMS ((PTR)); | |
2369 | static boolean ieee_function_type PARAMS ((PTR)); | |
2370 | static boolean ieee_reference_type PARAMS ((PTR)); | |
2371 | static boolean ieee_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma)); | |
2372 | static boolean ieee_array_type | |
2373 | PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, boolean)); | |
2374 | static boolean ieee_set_type PARAMS ((PTR, boolean)); | |
2375 | static boolean ieee_offset_type PARAMS ((PTR)); | |
2376 | static boolean ieee_method_type PARAMS ((PTR, boolean, int)); | |
2377 | static boolean ieee_const_type PARAMS ((PTR)); | |
2378 | static boolean ieee_volatile_type PARAMS ((PTR)); | |
2379 | static boolean ieee_start_struct_type | |
2380 | PARAMS ((PTR, const char *, boolean, unsigned int)); | |
2381 | static boolean ieee_struct_field | |
2382 | PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility)); | |
2383 | static boolean ieee_end_struct_type PARAMS ((PTR)); | |
2384 | static boolean ieee_start_class_type | |
2385 | PARAMS ((PTR, const char *, boolean, unsigned int, boolean, boolean)); | |
2386 | static boolean ieee_class_static_member | |
2387 | PARAMS ((PTR, const char *, const char *, enum debug_visibility)); | |
2388 | static boolean ieee_class_baseclass | |
2389 | PARAMS ((PTR, bfd_vma, boolean, enum debug_visibility)); | |
2390 | static boolean ieee_class_start_method PARAMS ((PTR, const char *)); | |
2391 | static boolean ieee_class_method_variant | |
2392 | PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean, | |
2393 | bfd_vma, boolean)); | |
2394 | static boolean ieee_class_static_method_variant | |
2395 | PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean)); | |
2396 | static boolean ieee_class_end_method PARAMS ((PTR)); | |
2397 | static boolean ieee_end_class_type PARAMS ((PTR)); | |
2398 | static boolean ieee_typedef_type PARAMS ((PTR, const char *)); | |
2399 | static boolean ieee_tag_type | |
2400 | PARAMS ((PTR, const char *, enum debug_type_kind)); | |
2401 | static boolean ieee_typdef PARAMS ((PTR, const char *)); | |
2402 | static boolean ieee_tag PARAMS ((PTR, const char *)); | |
2403 | static boolean ieee_int_constant PARAMS ((PTR, const char *, bfd_vma)); | |
2404 | static boolean ieee_float_constant PARAMS ((PTR, const char *, double)); | |
2405 | static boolean ieee_typed_constant PARAMS ((PTR, const char *, bfd_vma)); | |
2406 | static boolean ieee_variable | |
2407 | PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma)); | |
2408 | static boolean ieee_start_function PARAMS ((PTR, const char *, boolean)); | |
2409 | static boolean ieee_function_parameter | |
2410 | PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma)); | |
2411 | static boolean ieee_start_block PARAMS ((PTR, bfd_vma)); | |
2412 | static boolean ieee_end_block PARAMS ((PTR, bfd_vma)); | |
2413 | static boolean ieee_end_function PARAMS ((PTR)); | |
2414 | static boolean ieee_lineno | |
2415 | PARAMS ((PTR, const char *, unsigned long, bfd_vma)); | |
2416 | ||
2417 | static const struct debug_write_fns ieee_fns = | |
2418 | { | |
2419 | ieee_start_compilation_unit, | |
2420 | ieee_start_source, | |
2421 | ieee_empty_type, | |
2422 | ieee_void_type, | |
2423 | ieee_int_type, | |
2424 | ieee_float_type, | |
2425 | ieee_complex_type, | |
2426 | ieee_bool_type, | |
2427 | ieee_enum_type, | |
2428 | ieee_pointer_type, | |
2429 | ieee_function_type, | |
2430 | ieee_reference_type, | |
2431 | ieee_range_type, | |
2432 | ieee_array_type, | |
2433 | ieee_set_type, | |
2434 | ieee_offset_type, | |
2435 | ieee_method_type, | |
2436 | ieee_const_type, | |
2437 | ieee_volatile_type, | |
2438 | ieee_start_struct_type, | |
2439 | ieee_struct_field, | |
2440 | ieee_end_struct_type, | |
2441 | ieee_start_class_type, | |
2442 | ieee_class_static_member, | |
2443 | ieee_class_baseclass, | |
2444 | ieee_class_start_method, | |
2445 | ieee_class_method_variant, | |
2446 | ieee_class_static_method_variant, | |
2447 | ieee_class_end_method, | |
2448 | ieee_end_class_type, | |
2449 | ieee_typedef_type, | |
2450 | ieee_tag_type, | |
2451 | ieee_typdef, | |
2452 | ieee_tag, | |
2453 | ieee_int_constant, | |
2454 | ieee_float_constant, | |
2455 | ieee_typed_constant, | |
2456 | ieee_variable, | |
2457 | ieee_start_function, | |
2458 | ieee_function_parameter, | |
2459 | ieee_start_block, | |
2460 | ieee_end_block, | |
2461 | ieee_end_function, | |
2462 | ieee_lineno | |
2463 | }; | |
2464 | ||
2465 | /* Change the current buffer to a specified buffer chain. */ | |
2466 | ||
2467 | static boolean | |
2468 | ieee_change_buffer (info, ppbuf) | |
2469 | struct ieee_handle *info; | |
2470 | struct ieee_buf **ppbuf; | |
2471 | { | |
2472 | struct ieee_buf *buf; | |
2473 | ||
2474 | if (*ppbuf != NULL) | |
2475 | { | |
2476 | for (buf = *ppbuf; buf->next != NULL; buf = buf->next) | |
2477 | ; | |
2478 | } | |
2479 | else | |
2480 | { | |
2481 | buf = (struct ieee_buf *) xmalloc (sizeof *buf); | |
2482 | buf->next = NULL; | |
2483 | buf->c = 0; | |
2484 | *ppbuf = buf; | |
2485 | } | |
2486 | ||
2487 | info->current = buf; | |
2488 | return true; | |
2489 | } | |
2490 | ||
2491 | /* Push a type index onto the type stack. */ | |
2492 | ||
2493 | static boolean | |
2494 | ieee_push_type (info, indx, size, unsignedp) | |
2495 | struct ieee_handle *info; | |
2496 | unsigned int indx; | |
2497 | unsigned int size; | |
2498 | boolean unsignedp; | |
2499 | { | |
2500 | struct ieee_type_stack *ts; | |
2501 | ||
2502 | ts = (struct ieee_type_stack *) xmalloc (sizeof *ts); | |
2503 | memset (ts, 0, sizeof *ts); | |
2504 | ||
2505 | ts->type.indx = indx; | |
2506 | ts->type.size = size; | |
2507 | ts->type.unsignedp = unsignedp; | |
2508 | ||
2509 | ts->next = info->type_stack; | |
2510 | info->type_stack = ts; | |
2511 | ||
2512 | return true; | |
2513 | } | |
2514 | ||
2515 | /* Pop a type index off the type stack. */ | |
2516 | ||
2517 | static unsigned int | |
2518 | ieee_pop_type (info) | |
2519 | struct ieee_handle *info; | |
2520 | { | |
2521 | struct ieee_type_stack *ts; | |
2522 | unsigned int ret; | |
2523 | ||
2524 | ts = info->type_stack; | |
2525 | assert (ts != NULL); | |
2526 | ret = ts->type.indx; | |
2527 | info->type_stack = ts->next; | |
2528 | free (ts); | |
2529 | return ret; | |
2530 | } | |
2531 | ||
2532 | /* Add a range of bytes included in the current compilation unit. */ | |
2533 | ||
2534 | static boolean | |
2535 | ieee_add_range (info, low, high) | |
2536 | struct ieee_handle *info; | |
2537 | bfd_vma low; | |
2538 | bfd_vma high; | |
2539 | { | |
2540 | struct ieee_range *r, **pr; | |
2541 | ||
2542 | if (low == (bfd_vma) -1 || high == (bfd_vma) -1) | |
2543 | return true; | |
2544 | ||
2545 | for (r = info->ranges; r != NULL; r = r->next) | |
2546 | { | |
2547 | if (high >= r->low && low <= r->high) | |
2548 | { | |
2549 | /* The new range overlaps r. */ | |
2550 | if (low < r->low) | |
2551 | r->low = low; | |
2552 | if (high > r->high) | |
2553 | r->high = high; | |
2554 | pr = &r->next; | |
2555 | while (*pr != NULL && (*pr)->low <= r->high) | |
2556 | { | |
2557 | struct ieee_range *n; | |
2558 | ||
2559 | if ((*pr)->high > r->high) | |
2560 | r->high = (*pr)->high; | |
2561 | n = (*pr)->next; | |
2562 | free (*pr); | |
2563 | *pr = n; | |
2564 | } | |
2565 | return true; | |
2566 | } | |
2567 | } | |
2568 | ||
2569 | r = (struct ieee_range *) xmalloc (sizeof *r); | |
2570 | memset (r, 0, sizeof *r); | |
2571 | ||
2572 | r->low = low; | |
2573 | r->high = high; | |
2574 | ||
2575 | /* Store the ranges sorted by address. */ | |
2576 | for (pr = &info->ranges; *pr != NULL; pr = &(*pr)->next) | |
2577 | if ((*pr)->next != NULL && (*pr)->next->low > high) | |
2578 | break; | |
2579 | r->next = *pr; | |
2580 | *pr = r; | |
2581 | ||
2582 | return true; | |
2583 | } | |
2584 | ||
2585 | /* Start a new range for which we only have the low address. */ | |
2586 | ||
2587 | static boolean | |
2588 | ieee_start_range (info, low) | |
2589 | struct ieee_handle *info; | |
2590 | bfd_vma low; | |
2591 | { | |
2592 | struct ieee_range *r; | |
2593 | ||
2594 | r = (struct ieee_range *) xmalloc (sizeof *r); | |
2595 | memset (r, 0, sizeof *r); | |
2596 | r->low = low; | |
2597 | r->next = info->pending_ranges; | |
2598 | info->pending_ranges = r; | |
2599 | return true; | |
2600 | } | |
2601 | ||
2602 | /* Finish a range started by ieee_start_range. */ | |
2603 | ||
2604 | static boolean | |
2605 | ieee_end_range (info, high) | |
2606 | struct ieee_handle *info; | |
2607 | bfd_vma high; | |
2608 | { | |
2609 | struct ieee_range *r; | |
2610 | bfd_vma low; | |
2611 | ||
2612 | assert (info->pending_ranges != NULL); | |
2613 | r = info->pending_ranges; | |
2614 | low = r->low; | |
2615 | info->pending_ranges = r->next; | |
2616 | free (r); | |
2617 | return ieee_add_range (info, low, high); | |
2618 | } | |
2619 | ||
2620 | /* Write a byte into the buffer. We use a macro for speed and a | |
2621 | function for the complex cases. */ | |
2622 | ||
2623 | #define ieee_write_byte(info, b) \ | |
2624 | ((info)->current->c < IEEE_BUFSIZE \ | |
2625 | ? ((info)->current->buf[(info)->current->c++] = (b), true) \ | |
2626 | : ieee_real_write_byte ((info), (b))) | |
2627 | ||
2628 | static boolean | |
2629 | ieee_real_write_byte (info, b) | |
2630 | struct ieee_handle *info; | |
2631 | int b; | |
2632 | { | |
2633 | if (info->current->c >= IEEE_BUFSIZE) | |
2634 | { | |
2635 | struct ieee_buf *n; | |
2636 | ||
2637 | n = (struct ieee_buf *) xmalloc (sizeof *n); | |
2638 | n->next = NULL; | |
2639 | n->c = 0; | |
2640 | info->current->next = n; | |
2641 | info->current = n; | |
2642 | } | |
2643 | ||
2644 | info->current->buf[info->current->c] = b; | |
2645 | ++info->current->c; | |
2646 | ||
2647 | return true; | |
2648 | } | |
2649 | ||
2650 | /* Write out two bytes. */ | |
2651 | ||
2652 | static boolean | |
2653 | ieee_write_2bytes (info, i) | |
2654 | struct ieee_handle *info; | |
2655 | int i; | |
2656 | { | |
2657 | return (ieee_write_byte (info, i >> 8) | |
2658 | && ieee_write_byte (info, i & 0xff)); | |
2659 | } | |
2660 | ||
2661 | /* Write out an integer. */ | |
2662 | ||
2663 | static boolean | |
2664 | ieee_write_number (info, v) | |
2665 | struct ieee_handle *info; | |
2666 | bfd_vma v; | |
2667 | { | |
2668 | bfd_vma t; | |
2669 | bfd_byte ab[20]; | |
2670 | bfd_byte *p; | |
2671 | unsigned int c; | |
2672 | ||
2673 | if (v <= (bfd_vma) ieee_number_end_enum) | |
2674 | return ieee_write_byte (info, (int) v); | |
2675 | ||
2676 | t = v; | |
2677 | p = ab + sizeof ab; | |
2678 | while (t != 0) | |
2679 | { | |
2680 | *--p = t & 0xff; | |
2681 | t >>= 8; | |
2682 | } | |
2683 | c = (ab + 20) - p; | |
2684 | ||
2685 | if (c > (unsigned int) (ieee_number_repeat_end_enum | |
2686 | - ieee_number_repeat_start_enum)) | |
2687 | { | |
2688 | fprintf (stderr, "IEEE numeric overflow: 0x"); | |
2689 | fprintf_vma (stderr, v); | |
2690 | fprintf (stderr, "\n"); | |
2691 | return false; | |
2692 | } | |
2693 | ||
2694 | if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c)) | |
2695 | return false; | |
2696 | for (; c > 0; --c, ++p) | |
2697 | { | |
2698 | if (! ieee_write_byte (info, *p)) | |
2699 | return false; | |
2700 | } | |
2701 | ||
2702 | return true; | |
2703 | } | |
2704 | ||
2705 | /* Write out a string. */ | |
2706 | ||
2707 | static boolean | |
2708 | ieee_write_id (info, s) | |
2709 | struct ieee_handle *info; | |
2710 | const char *s; | |
2711 | { | |
2712 | unsigned int len; | |
2713 | ||
2714 | len = strlen (s); | |
2715 | if (len <= 0x7f) | |
2716 | { | |
2717 | if (! ieee_write_byte (info, len)) | |
2718 | return false; | |
2719 | } | |
2720 | else if (len <= 0xff) | |
2721 | { | |
2722 | if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum) | |
2723 | || ! ieee_write_byte (info, len)) | |
2724 | return false; | |
2725 | } | |
2726 | else if (len <= 0xffff) | |
2727 | { | |
2728 | if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum) | |
2729 | || ! ieee_write_2bytes (info, len)) | |
2730 | return false; | |
2731 | } | |
2732 | else | |
2733 | { | |
2734 | fprintf (stderr, "IEEE string length overflow: %u\n", len); | |
2735 | return false; | |
2736 | } | |
2737 | ||
2738 | for (; *s != '\0'; s++) | |
2739 | if (! ieee_write_byte (info, *s)) | |
2740 | return false; | |
2741 | ||
2742 | return true; | |
2743 | } | |
2744 | ||
2745 | /* Start defining a type. */ | |
2746 | ||
2747 | static boolean | |
2748 | ieee_define_type (info, size, unsignedp) | |
2749 | struct ieee_handle *info; | |
2750 | unsigned int size; | |
2751 | boolean unsignedp; | |
2752 | { | |
2753 | return ieee_define_named_type (info, (const char *) NULL, false, size, | |
2754 | unsignedp, (struct ieee_buf **) NULL); | |
2755 | } | |
2756 | ||
2757 | /* Start defining a named type. */ | |
2758 | ||
2759 | static boolean | |
2760 | ieee_define_named_type (info, name, tagp, size, unsignedp, ppbuf) | |
2761 | struct ieee_handle *info; | |
2762 | const char *name; | |
2763 | boolean tagp; | |
2764 | unsigned int size; | |
2765 | boolean unsignedp; | |
2766 | struct ieee_buf **ppbuf; | |
2767 | { | |
2768 | unsigned int type_indx; | |
2769 | unsigned int name_indx; | |
2770 | ||
2771 | if (! tagp || name == NULL || *name == '\0') | |
2772 | { | |
2773 | type_indx = info->type_indx; | |
2774 | ++info->type_indx; | |
2775 | } | |
2776 | else | |
2777 | { | |
2778 | struct ieee_name_type *nt; | |
2779 | ||
2780 | /* The name is a tag. If we have already defined the tag, we | |
2781 | must use the existing type index. */ | |
2782 | for (nt = info->tags; nt != NULL; nt = nt->next) | |
2783 | if (nt->name[0] == name[0] | |
2784 | && strcmp (nt->name, name) == 0) | |
2785 | break; | |
2786 | ||
2787 | if (nt == NULL) | |
2788 | { | |
2789 | nt = (struct ieee_name_type *) xmalloc (sizeof *nt); | |
2790 | memset (nt, 0, sizeof *nt); | |
2791 | nt->name = name; | |
2792 | nt->next = info->tags; | |
2793 | info->tags = nt; | |
2794 | nt->type.indx = info->type_indx; | |
2795 | ++info->type_indx; | |
2796 | } | |
2797 | ||
2798 | nt->type.size = size; | |
2799 | nt->type.unsignedp = unsignedp; | |
2800 | nt->kind = DEBUG_KIND_VOID; | |
2801 | ||
2802 | type_indx = nt->type.indx; | |
2803 | } | |
2804 | ||
2805 | name_indx = info->name_indx; | |
2806 | ++info->name_indx; | |
2807 | ||
2808 | if (name == NULL) | |
2809 | name = ""; | |
2810 | ||
2811 | /* If we were given a buffer, use it; otherwise, use the general | |
2812 | type information, and make sure that the type block is started. */ | |
2813 | if (ppbuf != NULL) | |
2814 | { | |
2815 | if (! ieee_change_buffer (info, ppbuf)) | |
2816 | return false; | |
2817 | } | |
2818 | else if (info->types != NULL) | |
2819 | { | |
2820 | if (! ieee_change_buffer (info, &info->types)) | |
2821 | return false; | |
2822 | } | |
2823 | else | |
2824 | { | |
2825 | if (! ieee_change_buffer (info, &info->types) | |
2826 | || ! ieee_write_byte (info, (int) ieee_bb_record_enum) | |
2827 | || ! ieee_write_byte (info, 1) | |
2828 | || ! ieee_write_number (info, 0) | |
2829 | || ! ieee_write_id (info, info->modname)) | |
2830 | return false; | |
2831 | } | |
2832 | ||
2833 | /* Push the new type on the type stack, write out an NN record, and | |
2834 | write out the start of a TY record. The caller will then finish | |
2835 | the TY record. */ | |
2836 | return (ieee_push_type (info, type_indx, size, unsignedp) | |
2837 | && ieee_write_byte (info, (int) ieee_nn_record) | |
2838 | && ieee_write_number (info, name_indx) | |
2839 | && ieee_write_id (info, name) | |
2840 | && ieee_write_byte (info, (int) ieee_ty_record_enum) | |
2841 | && ieee_write_number (info, type_indx) | |
2842 | && ieee_write_byte (info, 0xce) | |
2843 | && ieee_write_number (info, name_indx)); | |
2844 | } | |
2845 | \f | |
2846 | /* The general routine to write out IEEE debugging information. */ | |
2847 | ||
2848 | boolean | |
2849 | write_ieee_debugging_info (abfd, dhandle) | |
2850 | bfd *abfd; | |
2851 | PTR dhandle; | |
2852 | { | |
2853 | struct ieee_handle info; | |
2854 | struct ieee_buf *tags; | |
2855 | struct ieee_name_type *nt; | |
2856 | asection *s; | |
2857 | const char *err; | |
2858 | struct ieee_buf *b; | |
2859 | ||
2860 | memset (&info, 0, sizeof info); | |
2861 | info.abfd = abfd; | |
2862 | info.type_indx = 256; | |
2863 | info.name_indx = 32; | |
2864 | ||
2865 | if (! debug_write (dhandle, &ieee_fns, (PTR) &info)) | |
2866 | return false; | |
2867 | ||
2868 | if (info.filename != NULL) | |
2869 | { | |
2870 | if (! ieee_finish_compilation_unit (&info)) | |
2871 | return false; | |
2872 | } | |
2873 | ||
2874 | /* Put any undefined tags in the global typedef information. */ | |
2875 | tags = NULL; | |
2876 | for (nt = info.tags; nt != NULL; nt = nt->next) | |
2877 | { | |
2878 | unsigned int name_indx; | |
2879 | char code; | |
2880 | ||
2881 | if (nt->kind == DEBUG_KIND_VOID) | |
2882 | continue; | |
2883 | if (tags == NULL) | |
2884 | { | |
2885 | if (! ieee_change_buffer (&info, &tags) | |
2886 | || ! ieee_write_byte (&info, (int) ieee_bb_record_enum) | |
2887 | || ! ieee_write_byte (&info, 2) | |
2888 | || ! ieee_write_number (&info, 0) | |
2889 | || ! ieee_write_id (&info, "")) | |
2890 | return false; | |
2891 | } | |
2892 | name_indx = info.name_indx; | |
2893 | ++info.name_indx; | |
2894 | if (! ieee_write_byte (&info, (int) ieee_nn_record) | |
2895 | || ! ieee_write_number (&info, name_indx) | |
2896 | || ! ieee_write_id (&info, nt->name) | |
2897 | || ! ieee_write_byte (&info, (int) ieee_ty_record_enum) | |
2898 | || ! ieee_write_number (&info, nt->type.indx) | |
2899 | || ! ieee_write_byte (&info, 0xce) | |
2900 | || ! ieee_write_number (&info, name_indx)) | |
2901 | return false; | |
2902 | switch (nt->kind) | |
2903 | { | |
2904 | default: | |
2905 | abort (); | |
2906 | return false; | |
2907 | case DEBUG_KIND_STRUCT: | |
2908 | case DEBUG_KIND_CLASS: | |
2909 | code = 'S'; | |
2910 | break; | |
2911 | case DEBUG_KIND_UNION: | |
2912 | case DEBUG_KIND_UNION_CLASS: | |
2913 | code = 'U'; | |
2914 | break; | |
2915 | case DEBUG_KIND_ENUM: | |
2916 | code = 'E'; | |
2917 | break; | |
2918 | } | |
2919 | if (! ieee_write_number (&info, code) | |
2920 | || ! ieee_write_number (&info, 0)) | |
2921 | return false; | |
2922 | } | |
2923 | if (tags != NULL) | |
2924 | { | |
2925 | struct ieee_buf **pb; | |
2926 | ||
2927 | if (! ieee_write_byte (&info, (int) ieee_be_record_enum)) | |
2928 | return false; | |
2929 | ||
2930 | for (pb = &tags; *pb != NULL; pb = &(*pb)->next) | |
2931 | ; | |
2932 | *pb = info.data; | |
2933 | info.data = tags; | |
2934 | } | |
2935 | ||
2936 | /* Now all the data is in info.data. Write it out to the BFD. We | |
2937 | normally would need to worry about whether all the other sections | |
2938 | are set up yet, but the IEEE backend will handle this particular | |
2939 | case correctly regardless. */ | |
2940 | if (info.data == NULL) | |
2941 | { | |
2942 | /* There is no debugging information. */ | |
2943 | return true; | |
2944 | } | |
2945 | err = NULL; | |
2946 | s = bfd_make_section (abfd, ".debug"); | |
2947 | if (s == NULL) | |
2948 | err = "bfd_make_section"; | |
2949 | if (err == NULL) | |
2950 | { | |
2951 | if (! bfd_set_section_flags (abfd, s, SEC_DEBUGGING | SEC_HAS_CONTENTS)) | |
2952 | err = "bfd_set_section_flags"; | |
2953 | } | |
2954 | if (err == NULL) | |
2955 | { | |
2956 | bfd_size_type size; | |
2957 | ||
2958 | size = 0; | |
2959 | for (b = info.data; b != NULL; b = b->next) | |
2960 | size += b->c; | |
2961 | if (! bfd_set_section_size (abfd, s, size)) | |
2962 | err = "bfd_set_section_size"; | |
2963 | } | |
2964 | if (err == NULL) | |
2965 | { | |
2966 | file_ptr offset; | |
2967 | ||
2968 | offset = 0; | |
2969 | for (b = info.data; b != NULL; b = b->next) | |
2970 | { | |
2971 | if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c)) | |
2972 | { | |
2973 | err = "bfd_set_section_contents"; | |
2974 | break; | |
2975 | } | |
2976 | offset += b->c; | |
2977 | } | |
2978 | } | |
2979 | ||
2980 | if (err != NULL) | |
2981 | { | |
2982 | fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), err, | |
2983 | bfd_errmsg (bfd_get_error ())); | |
2984 | return false; | |
2985 | } | |
2986 | ||
2987 | return true; | |
2988 | } | |
2989 | ||
2990 | /* Start writing out information for a compilation unit. */ | |
2991 | ||
2992 | static boolean | |
2993 | ieee_start_compilation_unit (p, filename) | |
2994 | PTR p; | |
2995 | const char *filename; | |
2996 | { | |
2997 | struct ieee_handle *info = (struct ieee_handle *) p; | |
2998 | const char *modname; | |
2999 | char *c, *s; | |
3000 | ||
3001 | if (info->filename != NULL) | |
3002 | { | |
3003 | if (! ieee_finish_compilation_unit (info)) | |
3004 | return false; | |
3005 | } | |
3006 | ||
3007 | info->filename = filename; | |
3008 | modname = strrchr (filename, '/'); | |
3009 | if (modname != NULL) | |
3010 | ++modname; | |
3011 | else | |
3012 | { | |
3013 | modname = strrchr (filename, '\\'); | |
3014 | if (modname != NULL) | |
3015 | ++modname; | |
3016 | else | |
3017 | modname = filename; | |
3018 | } | |
3019 | c = xstrdup (modname); | |
3020 | s = strrchr (c, '.'); | |
3021 | if (s != NULL) | |
3022 | *s = '\0'; | |
3023 | info->modname = c; | |
3024 | ||
3025 | info->types = NULL; | |
3026 | info->vars = NULL; | |
3027 | info->linenos = NULL; | |
3028 | info->ranges = NULL; | |
3029 | ||
3030 | return true; | |
3031 | } | |
3032 | ||
3033 | /* Finish up a compilation unit. */ | |
3034 | ||
3035 | static boolean | |
3036 | ieee_finish_compilation_unit (info) | |
3037 | struct ieee_handle *info; | |
3038 | { | |
3039 | struct ieee_buf **pp; | |
3040 | struct ieee_range *r; | |
3041 | ||
3042 | if (info->types != NULL) | |
3043 | { | |
3044 | if (! ieee_change_buffer (info, &info->types) | |
3045 | || ! ieee_write_byte (info, (int) ieee_be_record_enum)) | |
3046 | return false; | |
3047 | } | |
3048 | ||
3049 | if (info->vars != NULL) | |
3050 | { | |
3051 | if (! ieee_change_buffer (info, &info->vars) | |
3052 | || ! ieee_write_byte (info, (int) ieee_be_record_enum)) | |
3053 | return false; | |
3054 | } | |
3055 | ||
3056 | if (info->linenos != NULL) | |
3057 | { | |
3058 | if (! ieee_change_buffer (info, &info->linenos) | |
3059 | || ! ieee_write_byte (info, (int) ieee_be_record_enum)) | |
3060 | return false; | |
3061 | } | |
3062 | ||
3063 | for (pp = &info->data; *pp != NULL; pp = &(*pp)->next) | |
3064 | ; | |
3065 | *pp = info->types; | |
3066 | for (; *pp != NULL; pp = &(*pp)->next) | |
3067 | ; | |
3068 | *pp = info->vars; | |
3069 | for (; *pp != NULL; pp = &(*pp)->next) | |
3070 | ; | |
3071 | *pp = info->linenos; | |
3072 | ||
3073 | /* Build BB10/BB11 blocks based on the ranges we recorded. */ | |
3074 | if (! ieee_change_buffer (info, &info->data)) | |
3075 | return false; | |
3076 | ||
3077 | if (! ieee_write_byte (info, (int) ieee_bb_record_enum) | |
3078 | || ! ieee_write_byte (info, 10) | |
3079 | || ! ieee_write_number (info, 0) | |
3080 | || ! ieee_write_id (info, info->modname) | |
3081 | || ! ieee_write_id (info, "") | |
3082 | || ! ieee_write_number (info, 0) | |
3083 | || ! ieee_write_id (info, "GNU objcopy")) | |
3084 | return false; | |
3085 | ||
3086 | for (r = info->ranges; r != NULL; r = r->next) | |
3087 | { | |
3088 | bfd_vma low, high; | |
3089 | asection *s; | |
3090 | int kind; | |
3091 | ||
3092 | low = r->low; | |
3093 | high = r->high; | |
3094 | ||
3095 | /* Find the section corresponding to this range. */ | |
3096 | for (s = info->abfd->sections; s != NULL; s = s->next) | |
3097 | { | |
3098 | if (bfd_get_section_vma (info->abfd, s) <= low | |
3099 | && high <= (bfd_get_section_vma (info->abfd, s) | |
3100 | + bfd_section_size (info->abfd, s))) | |
3101 | break; | |
3102 | } | |
3103 | ||
3104 | if (s == NULL) | |
3105 | { | |
3106 | /* Just ignore this range. */ | |
3107 | continue; | |
3108 | } | |
3109 | ||
3110 | /* Coalesce ranges if it seems reasonable. */ | |
3111 | while (r->next != NULL | |
3112 | && high + 64 >= r->next->low | |
3113 | && (r->next->high | |
3114 | <= (bfd_get_section_vma (info->abfd, s) | |
3115 | + bfd_section_size (info->abfd, s)))) | |
3116 | { | |
3117 | r = r->next; | |
3118 | high = r->next->high; | |
3119 | } | |
3120 | ||
3121 | if ((s->flags & SEC_CODE) != 0) | |
3122 | kind = 1; | |
3123 | else if ((s->flags & SEC_READONLY) != 0) | |
3124 | kind = 3; | |
3125 | else | |
3126 | kind = 2; | |
3127 | ||
3128 | if (! ieee_write_byte (info, (int) ieee_bb_record_enum) | |
3129 | || ! ieee_write_byte (info, 11) | |
3130 | || ! ieee_write_number (info, 0) | |
3131 | || ! ieee_write_id (info, "") | |
3132 | || ! ieee_write_number (info, kind) | |
3133 | || ! ieee_write_number (info, s->index) | |
3134 | || ! ieee_write_number (info, low) | |
3135 | || ! ieee_write_byte (info, (int) ieee_be_record_enum) | |
3136 | || ! ieee_write_number (info, high - low)) | |
3137 | return false; | |
3138 | } | |
3139 | ||
3140 | if (! ieee_write_byte (info, (int) ieee_be_record_enum)) | |
3141 | return false; | |
3142 | ||
3143 | return true; | |
3144 | } | |
3145 | ||
3146 | /* Start recording information from a particular source file. This is | |
3147 | used to record which file defined which types, variables, etc. It | |
3148 | is not used for line numbers, since the lineno entry point passes | |
3149 | down the file name anyhow. IEEE debugging information doesn't seem | |
3150 | to store this information anywhere. */ | |
3151 | ||
3152 | /*ARGSUSED*/ | |
3153 | static boolean | |
3154 | ieee_start_source (p, filename) | |
3155 | PTR p; | |
3156 | const char *filename; | |
3157 | { | |
3158 | return true; | |
3159 | } | |
3160 | ||
3161 | /* Make an empty type. */ | |
3162 | ||
3163 | static boolean | |
3164 | ieee_empty_type (p) | |
3165 | PTR p; | |
3166 | { | |
3167 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3168 | ||
3169 | return ieee_push_type (info, 0, 0, false); | |
3170 | } | |
3171 | ||
3172 | /* Make a void type. */ | |
3173 | ||
3174 | static boolean | |
3175 | ieee_void_type (p) | |
3176 | PTR p; | |
3177 | { | |
3178 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3179 | ||
3180 | return ieee_push_type (info, 1, 0, false); | |
3181 | } | |
3182 | ||
3183 | /* Make an integer type. */ | |
3184 | ||
3185 | static boolean | |
3186 | ieee_int_type (p, size, unsignedp) | |
3187 | PTR p; | |
3188 | unsigned int size; | |
3189 | boolean unsignedp; | |
3190 | { | |
3191 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3192 | unsigned int indx; | |
3193 | ||
3194 | switch (size) | |
3195 | { | |
3196 | case 1: | |
3197 | indx = (int) builtin_signed_char; | |
3198 | break; | |
3199 | case 2: | |
3200 | indx = (int) builtin_signed_short_int; | |
3201 | break; | |
3202 | case 4: | |
3203 | indx = (int) builtin_signed_long; | |
3204 | break; | |
3205 | case 8: | |
3206 | indx = (int) builtin_signed_long_long; | |
3207 | break; | |
3208 | default: | |
3209 | fprintf (stderr, "IEEE unsupported integer type size %u\n", size); | |
3210 | return false; | |
3211 | } | |
3212 | ||
3213 | if (unsignedp) | |
3214 | ++indx; | |
3215 | ||
3216 | return ieee_push_type (info, indx, size, unsignedp); | |
3217 | } | |
3218 | ||
3219 | /* Make a floating point type. */ | |
3220 | ||
3221 | static boolean | |
3222 | ieee_float_type (p, size) | |
3223 | PTR p; | |
3224 | unsigned int size; | |
3225 | { | |
3226 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3227 | unsigned int indx; | |
3228 | ||
3229 | switch (size) | |
3230 | { | |
3231 | case 4: | |
3232 | indx = (int) builtin_float; | |
3233 | break; | |
3234 | case 8: | |
3235 | indx = (int) builtin_double; | |
3236 | break; | |
3237 | case 12: | |
3238 | /* FIXME: This size really depends upon the processor. */ | |
3239 | indx = (int) builtin_long_double; | |
3240 | break; | |
3241 | case 16: | |
3242 | indx = (int) builtin_long_long_double; | |
3243 | break; | |
3244 | default: | |
3245 | fprintf (stderr, "IEEE unsupported float type size %u\n", size); | |
3246 | return false; | |
3247 | } | |
3248 | ||
3249 | return ieee_push_type (info, indx, size, false); | |
3250 | } | |
3251 | ||
3252 | /* Make a complex type. */ | |
3253 | ||
3254 | static boolean | |
3255 | ieee_complex_type (p, size) | |
3256 | PTR p; | |
3257 | unsigned int size; | |
3258 | { | |
3259 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3260 | char code; | |
3261 | ||
3262 | switch (size) | |
3263 | { | |
3264 | case 4: | |
3265 | code = 'c'; | |
3266 | break; | |
3267 | case 8: | |
3268 | code = 'd'; | |
3269 | break; | |
3270 | default: | |
3271 | fprintf (stderr, "IEEE unsupported complex type size %u\n", size); | |
3272 | return false; | |
3273 | } | |
3274 | ||
3275 | /* FIXME: I don't know what the string is for. */ | |
3276 | return (ieee_define_type (info, size, false) | |
3277 | && ieee_write_number (info, code) | |
3278 | && ieee_write_id (info, "")); | |
3279 | } | |
3280 | ||
3281 | /* Make a boolean type. IEEE doesn't support these, so we just make | |
3282 | an integer type instead. */ | |
3283 | ||
3284 | static boolean | |
3285 | ieee_bool_type (p, size) | |
3286 | PTR p; | |
3287 | unsigned int size; | |
3288 | { | |
3289 | return ieee_int_type (p, size, true); | |
3290 | } | |
3291 | ||
3292 | /* Make an enumeration. */ | |
3293 | ||
3294 | static boolean | |
3295 | ieee_enum_type (p, tag, names, vals) | |
3296 | PTR p; | |
3297 | const char *tag; | |
3298 | const char **names; | |
3299 | bfd_signed_vma *vals; | |
3300 | { | |
3301 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3302 | boolean simple; | |
3303 | int i; | |
3304 | ||
3305 | /* If this is a simple enumeration, in which the values start at 0 | |
3306 | and always increment by 1, we can use type E. Otherwise we must | |
3307 | use type N. */ | |
3308 | ||
3309 | simple = true; | |
3310 | for (i = 0; names[i] != NULL; i++) | |
3311 | { | |
3312 | if (vals[i] != i) | |
3313 | { | |
3314 | simple = false; | |
3315 | break; | |
3316 | } | |
3317 | } | |
3318 | ||
3319 | if (! ieee_define_named_type (info, tag, true, 0, true, | |
3320 | (struct ieee_buf **) NULL) | |
3321 | || ! ieee_write_number (info, simple ? 'E' : 'N')) | |
3322 | return false; | |
3323 | if (simple) | |
3324 | { | |
3325 | /* FIXME: This is supposed to be the enumeration size, but we | |
3326 | don't store that. */ | |
3327 | if (! ieee_write_number (info, 4)) | |
3328 | return false; | |
3329 | } | |
3330 | for (i = 0; names[i] != NULL; i++) | |
3331 | { | |
3332 | if (! ieee_write_id (info, names[i])) | |
3333 | return false; | |
3334 | if (! simple) | |
3335 | { | |
3336 | if (! ieee_write_number (info, vals[i])) | |
3337 | return false; | |
3338 | } | |
3339 | } | |
3340 | ||
3341 | return true; | |
3342 | } | |
3343 | ||
3344 | /* Make a pointer type. */ | |
3345 | ||
3346 | static boolean | |
3347 | ieee_pointer_type (p) | |
3348 | PTR p; | |
3349 | { | |
3350 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3351 | unsigned int indx; | |
3352 | ||
3353 | indx = ieee_pop_type (info); | |
3354 | ||
3355 | /* A pointer to a simple builtin type can be obtained by adding 32. */ | |
3356 | if (indx < 32) | |
3357 | return ieee_push_type (info, indx + 32, 0, true); | |
3358 | ||
3359 | return (ieee_define_type (info, 0, true) | |
3360 | && ieee_write_number (info, 'P') | |
3361 | && ieee_write_number (info, indx)); | |
3362 | } | |
3363 | ||
3364 | /* Make a function type. */ | |
3365 | ||
3366 | static boolean | |
3367 | ieee_function_type (p) | |
3368 | PTR p; | |
3369 | { | |
3370 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3371 | unsigned int indx; | |
3372 | ||
3373 | indx = ieee_pop_type (info); | |
3374 | ||
3375 | /* FIXME: IEEE can represent the argument types for the function, | |
3376 | but we didn't store them. */ | |
3377 | ||
3378 | /* An attribute of 0x41 means that the frame and push mask are | |
3379 | unknown. */ | |
3380 | return (ieee_define_type (info, 0, true) | |
3381 | && ieee_write_number (info, 'x') | |
3382 | && ieee_write_number (info, 0x41) | |
3383 | && ieee_write_number (info, 0) | |
3384 | && ieee_write_number (info, 0) | |
3385 | && ieee_write_number (info, indx) | |
3386 | && ieee_write_number (info, (bfd_vma) -1) | |
3387 | && ieee_write_number (info, 0)); | |
3388 | } | |
3389 | ||
3390 | /* Make a reference type. */ | |
3391 | ||
3392 | static boolean | |
3393 | ieee_reference_type (p) | |
3394 | PTR p; | |
3395 | { | |
3396 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3397 | ||
3398 | /* IEEE appears to record a normal pointer type, and then use a | |
3399 | pmisc record to indicate that it is really a reference. */ | |
3400 | ||
3401 | if (! ieee_pointer_type (p)) | |
3402 | return false; | |
3403 | info->type_stack->type.referencep = true; | |
3404 | return true; | |
3405 | } | |
3406 | ||
3407 | /* Make a range type. */ | |
3408 | ||
3409 | static boolean | |
3410 | ieee_range_type (p, low, high) | |
3411 | PTR p; | |
3412 | bfd_signed_vma low; | |
3413 | bfd_signed_vma high; | |
3414 | { | |
3415 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3416 | unsigned int size; | |
3417 | boolean unsignedp; | |
3418 | ||
3419 | size = info->type_stack->type.size; | |
3420 | unsignedp = info->type_stack->type.unsignedp; | |
3421 | (void) ieee_pop_type (info); | |
3422 | return (ieee_define_type (info, size, unsignedp) | |
3423 | && ieee_write_number (info, 'R') | |
3424 | && ieee_write_number (info, (bfd_vma) low) | |
3425 | && ieee_write_number (info, (bfd_vma) high) | |
3426 | && ieee_write_number (info, unsignedp ? 0 : 1) | |
3427 | && ieee_write_number (info, size)); | |
3428 | } | |
3429 | ||
3430 | /* Make an array type. */ | |
3431 | ||
3432 | /*ARGSUSED*/ | |
3433 | static boolean | |
3434 | ieee_array_type (p, low, high, stringp) | |
3435 | PTR p; | |
3436 | bfd_signed_vma low; | |
3437 | bfd_signed_vma high; | |
3438 | boolean stringp; | |
3439 | { | |
3440 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3441 | unsigned int eleindx; | |
3442 | ||
3443 | /* IEEE does not store the range, so we just ignore it. */ | |
3444 | (void) ieee_pop_type (info); | |
3445 | eleindx = ieee_pop_type (info); | |
3446 | ||
3447 | if (! ieee_define_type (info, 0, false) | |
3448 | || ! ieee_write_number (info, low == 0 ? 'Z' : 'C') | |
3449 | || ! ieee_write_number (info, eleindx)) | |
3450 | return false; | |
3451 | if (low != 0) | |
3452 | { | |
3453 | if (! ieee_write_number (info, low)) | |
3454 | return false; | |
3455 | } | |
3456 | ||
3457 | return ieee_write_number (info, high); | |
3458 | } | |
3459 | ||
3460 | /* Make a set type. */ | |
3461 | ||
3462 | static boolean | |
3463 | ieee_set_type (p, bitstringp) | |
3464 | PTR p; | |
3465 | boolean bitstringp; | |
3466 | { | |
3467 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3468 | unsigned int eleindx; | |
3469 | ||
3470 | eleindx = ieee_pop_type (info); | |
3471 | ||
3472 | /* FIXME: We don't know the size, so we just use 4. */ | |
3473 | ||
3474 | return (ieee_define_type (info, 0, true) | |
3475 | && ieee_write_number (info, 's') | |
3476 | && ieee_write_number (info, 4) | |
3477 | && ieee_write_number (info, eleindx)); | |
3478 | } | |
3479 | ||
3480 | /* Make an offset type. */ | |
3481 | ||
3482 | static boolean | |
3483 | ieee_offset_type (p) | |
3484 | PTR p; | |
3485 | { | |
3486 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3487 | unsigned int targetindx, baseindx; | |
3488 | ||
3489 | targetindx = ieee_pop_type (info); | |
3490 | baseindx = ieee_pop_type (info); | |
3491 | ||
3492 | /* FIXME: The MRI C++ compiler does not appear to generate any | |
3493 | useful type information about an offset type. It just records a | |
3494 | pointer to member as an integer. The MRI/HP IEEE spec does | |
3495 | describe a pmisc record which can be used for a pointer to | |
3496 | member. Unfortunately, it does not describe the target type, | |
3497 | which seems pretty important. I'm going to punt this for now. */ | |
3498 | ||
3499 | return ieee_int_type (p, 4, true); | |
3500 | } | |
3501 | ||
3502 | /* Make a method type. */ | |
3503 | ||
3504 | static boolean | |
3505 | ieee_method_type (p, domain, argcount) | |
3506 | PTR p; | |
3507 | boolean domain; | |
3508 | int argcount; | |
3509 | { | |
3510 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3511 | unsigned int *args = NULL; | |
3512 | int i; | |
3513 | unsigned int retindx; | |
3514 | ||
3515 | /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a | |
3516 | method, but the definition is incomplete. We just output an 'x' | |
3517 | type. */ | |
3518 | ||
3519 | if (domain) | |
3520 | (void) ieee_pop_type (info); | |
3521 | ||
3522 | if (argcount > 0) | |
3523 | { | |
3524 | args = (unsigned int *) xmalloc (argcount * sizeof *args); | |
3525 | for (i = argcount - 1; i >= 0; i--) | |
3526 | args[i] = ieee_pop_type (info); | |
3527 | } | |
3528 | ||
3529 | retindx = ieee_pop_type (info); | |
3530 | ||
3531 | if (! ieee_define_type (info, 0, true) | |
3532 | || ! ieee_write_number (info, 'x') | |
3533 | || ! ieee_write_number (info, 0x41) | |
3534 | || ! ieee_write_number (info, 0) | |
3535 | || ! ieee_write_number (info, 0) | |
3536 | || ! ieee_write_number (info, retindx) | |
3537 | || ! ieee_write_number (info, (bfd_vma) argcount)) | |
3538 | return false; | |
3539 | if (argcount > 0) | |
3540 | { | |
3541 | for (i = 0; i < argcount; i++) | |
3542 | if (! ieee_write_number (info, args[i])) | |
3543 | return false; | |
3544 | free (args); | |
3545 | } | |
3546 | ||
3547 | return ieee_write_number (info, 0); | |
3548 | } | |
3549 | ||
3550 | /* Make a const qualified type. */ | |
3551 | ||
3552 | static boolean | |
3553 | ieee_const_type (p) | |
3554 | PTR p; | |
3555 | { | |
3556 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3557 | unsigned int size; | |
3558 | boolean unsignedp; | |
3559 | unsigned int indx; | |
3560 | ||
3561 | size = info->type_stack->type.size; | |
3562 | unsignedp = info->type_stack->type.unsignedp; | |
3563 | indx = ieee_pop_type (info); | |
3564 | return (ieee_define_type (info, size, unsignedp) | |
3565 | && ieee_write_number (info, 'n') | |
3566 | && ieee_write_number (info, 1) | |
3567 | && ieee_write_number (info, indx)); | |
3568 | } | |
3569 | ||
3570 | /* Make a volatile qualified type. */ | |
3571 | ||
3572 | static boolean | |
3573 | ieee_volatile_type (p) | |
3574 | PTR p; | |
3575 | { | |
3576 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3577 | unsigned int size; | |
3578 | boolean unsignedp; | |
3579 | unsigned int indx; | |
3580 | ||
3581 | size = info->type_stack->type.size; | |
3582 | unsignedp = info->type_stack->type.unsignedp; | |
3583 | indx = ieee_pop_type (info); | |
3584 | return (ieee_define_type (info, size, unsignedp) | |
3585 | && ieee_write_number (info, 'n') | |
3586 | && ieee_write_number (info, 2) | |
3587 | && ieee_write_number (info, indx)); | |
3588 | } | |
3589 | ||
3590 | /* Start defining a struct type. We build it in the strdef field on | |
3591 | the stack, to avoid confusing type definitions required by the | |
3592 | fields with the struct type itself. */ | |
3593 | ||
3594 | static boolean | |
3595 | ieee_start_struct_type (p, tag, structp, size) | |
3596 | PTR p; | |
3597 | const char *tag; | |
3598 | boolean structp; | |
3599 | unsigned int size; | |
3600 | { | |
3601 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3602 | struct ieee_buf *strdef; | |
3603 | ||
3604 | strdef = NULL; | |
3605 | if (! ieee_define_named_type (info, tag, true, size, true, &strdef) | |
3606 | || ! ieee_write_number (info, structp ? 'S' : 'U') | |
3607 | || ! ieee_write_number (info, size)) | |
3608 | return false; | |
3609 | ||
3610 | info->type_stack->type.strdef = strdef; | |
3611 | ||
3612 | return true; | |
3613 | } | |
3614 | ||
3615 | /* Add a field to a struct. */ | |
3616 | ||
3617 | static boolean | |
3618 | ieee_struct_field (p, name, bitpos, bitsize, visibility) | |
3619 | PTR p; | |
3620 | const char *name; | |
3621 | bfd_vma bitpos; | |
3622 | bfd_vma bitsize; | |
3623 | enum debug_visibility visibility; | |
3624 | { | |
3625 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3626 | unsigned int size; | |
3627 | boolean unsignedp; | |
3628 | unsigned int indx; | |
3629 | bfd_vma offset; | |
3630 | ||
3631 | size = info->type_stack->type.size; | |
3632 | unsignedp = info->type_stack->type.unsignedp; | |
3633 | indx = ieee_pop_type (info); | |
3634 | ||
3635 | assert (info->type_stack != NULL && info->type_stack->type.strdef != NULL); | |
3636 | ||
3637 | /* If the bitsize doesn't match the expected size, we need to output | |
3638 | a bitfield type. */ | |
3639 | if (size == 0 || bitsize == size * 8) | |
3640 | offset = bitpos / 8; | |
3641 | else | |
3642 | { | |
3643 | if (! ieee_define_type (info, 0, unsignedp) | |
3644 | || ! ieee_write_number (info, 'g') | |
3645 | || ! ieee_write_number (info, unsignedp ? 0 : 1) | |
3646 | || ! ieee_write_number (info, indx)) | |
3647 | return false; | |
3648 | indx = ieee_pop_type (info); | |
3649 | offset = bitpos; | |
3650 | } | |
3651 | ||
3652 | /* Switch to the struct we are building in order to output this | |
3653 | field definition. */ | |
3654 | return (ieee_change_buffer (info, &info->type_stack->type.strdef) | |
3655 | && ieee_write_id (info, name) | |
3656 | && ieee_write_number (info, indx) | |
3657 | && ieee_write_number (info, offset)); | |
3658 | } | |
3659 | ||
3660 | /* Finish up a struct type. */ | |
3661 | ||
3662 | static boolean | |
3663 | ieee_end_struct_type (p) | |
3664 | PTR p; | |
3665 | { | |
3666 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3667 | struct ieee_buf **pb; | |
3668 | ||
3669 | assert (info->type_stack != NULL && info->type_stack->type.strdef != NULL); | |
3670 | ||
3671 | /* Make sure we have started the types block. */ | |
3672 | if (info->types == NULL) | |
3673 | { | |
3674 | if (! ieee_change_buffer (info, &info->types) | |
3675 | || ! ieee_write_byte (info, (int) ieee_bb_record_enum) | |
3676 | || ! ieee_write_byte (info, 1) | |
3677 | || ! ieee_write_number (info, 0) | |
3678 | || ! ieee_write_id (info, info->modname)) | |
3679 | return false; | |
3680 | } | |
3681 | ||
3682 | /* Append the struct definition to the types. */ | |
3683 | for (pb = &info->types; *pb != NULL; pb = &(*pb)->next) | |
3684 | ; | |
3685 | *pb = info->type_stack->type.strdef; | |
3686 | info->type_stack->type.strdef = NULL; | |
3687 | ||
3688 | /* Leave the struct on the type stack. */ | |
3689 | ||
3690 | return true; | |
3691 | } | |
3692 | ||
3693 | /* Start a class type. */ | |
3694 | ||
3695 | static boolean | |
3696 | ieee_start_class_type (p, tag, structp, size, vptr, ownvptr) | |
3697 | PTR p; | |
3698 | const char *tag; | |
3699 | boolean structp; | |
3700 | unsigned int size; | |
3701 | boolean vptr; | |
3702 | boolean ownvptr; | |
3703 | { | |
3704 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3705 | ||
3706 | /* FIXME. */ | |
3707 | if (vptr && ! ownvptr) | |
3708 | (void) ieee_pop_type (info); | |
3709 | return ieee_start_struct_type (p, tag, structp, size); | |
3710 | } | |
3711 | ||
3712 | /* Add a static member to a class. */ | |
3713 | ||
3714 | static boolean | |
3715 | ieee_class_static_member (p, name, physname, visibility) | |
3716 | PTR p; | |
3717 | const char *name; | |
3718 | const char *physname; | |
3719 | enum debug_visibility visibility; | |
3720 | { | |
3721 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3722 | ||
3723 | /* FIXME. */ | |
3724 | (void) ieee_pop_type (info); | |
3725 | return true; | |
3726 | } | |
3727 | ||
3728 | /* Add a base class to a class. */ | |
3729 | ||
3730 | static boolean | |
3731 | ieee_class_baseclass (p, bitpos, virtual, visibility) | |
3732 | PTR p; | |
3733 | bfd_vma bitpos; | |
3734 | boolean virtual; | |
3735 | enum debug_visibility visibility; | |
3736 | { | |
3737 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3738 | ||
3739 | /* FIXME. */ | |
3740 | (void) ieee_pop_type (info); | |
3741 | return true; | |
3742 | } | |
3743 | ||
3744 | /* Start building a method for a class. */ | |
3745 | ||
3746 | static boolean | |
3747 | ieee_class_start_method (p, name) | |
3748 | PTR p; | |
3749 | const char *name; | |
3750 | { | |
3751 | /* FIXME. */ | |
3752 | return true; | |
3753 | } | |
3754 | ||
3755 | /* Define a new method variant. */ | |
3756 | ||
3757 | static boolean | |
3758 | ieee_class_method_variant (p, name, visibility, constp, volatilep, | |
3759 | voffset, context) | |
3760 | PTR p; | |
3761 | const char *name; | |
3762 | enum debug_visibility visibility; | |
3763 | boolean constp; | |
3764 | boolean volatilep; | |
3765 | bfd_vma voffset; | |
3766 | boolean context; | |
3767 | { | |
3768 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3769 | ||
3770 | /* FIXME. */ | |
3771 | (void) ieee_pop_type (info); | |
3772 | if (context) | |
3773 | (void) ieee_pop_type (info); | |
3774 | return true; | |
3775 | } | |
3776 | ||
3777 | /* Define a new static method variant. */ | |
3778 | ||
3779 | static boolean | |
3780 | ieee_class_static_method_variant (p, name, visibility, constp, volatilep) | |
3781 | PTR p; | |
3782 | const char *name; | |
3783 | enum debug_visibility visibility; | |
3784 | boolean constp; | |
3785 | boolean volatilep; | |
3786 | { | |
3787 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3788 | ||
3789 | /* FIXME. */ | |
3790 | (void) ieee_pop_type (info); | |
3791 | return true; | |
3792 | } | |
3793 | ||
3794 | /* Finish up a method. */ | |
3795 | ||
3796 | static boolean | |
3797 | ieee_class_end_method (p) | |
3798 | PTR p; | |
3799 | { | |
3800 | /* FIXME. */ | |
3801 | return true; | |
3802 | } | |
3803 | ||
3804 | /* Finish up a class. */ | |
3805 | ||
3806 | static boolean | |
3807 | ieee_end_class_type (p) | |
3808 | PTR p; | |
3809 | { | |
3810 | return ieee_end_struct_type (p); | |
3811 | } | |
3812 | ||
3813 | /* Push a previously seen typedef onto the type stack. */ | |
3814 | ||
3815 | static boolean | |
3816 | ieee_typedef_type (p, name) | |
3817 | PTR p; | |
3818 | const char *name; | |
3819 | { | |
3820 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3821 | register struct ieee_name_type *nt; | |
3822 | ||
3823 | for (nt = info->typedefs; nt != NULL; nt = nt->next) | |
3824 | { | |
3825 | if (nt->name[0] == name[0] | |
3826 | && strcmp (nt->name, name) == 0) | |
3827 | { | |
3828 | if (! ieee_push_type (info, nt->type.indx, nt->type.size, | |
3829 | nt->type.unsignedp)) | |
3830 | return false; | |
3831 | /* Copy over any other type information we may have. */ | |
3832 | info->type_stack->type = nt->type; | |
3833 | return true; | |
3834 | } | |
3835 | } | |
3836 | ||
3837 | abort (); | |
3838 | } | |
3839 | ||
3840 | /* Push a tagged type onto the type stack. */ | |
3841 | ||
3842 | static boolean | |
3843 | ieee_tag_type (p, name, kind) | |
3844 | PTR p; | |
3845 | const char *name; | |
3846 | enum debug_type_kind kind; | |
3847 | { | |
3848 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3849 | register struct ieee_name_type *nt; | |
3850 | ||
3851 | for (nt = info->tags; nt != NULL; nt = nt->next) | |
3852 | { | |
3853 | if (nt->name[0] == name[0] | |
3854 | && strcmp (nt->name, name) == 0) | |
3855 | { | |
3856 | if (! ieee_push_type (info, nt->type.indx, nt->type.size, | |
3857 | nt->type.unsignedp)) | |
3858 | return false; | |
3859 | /* Copy over any other type information we may have. */ | |
3860 | info->type_stack->type = nt->type; | |
3861 | return true; | |
3862 | } | |
3863 | } | |
3864 | ||
3865 | nt = (struct ieee_name_type *) xmalloc (sizeof *nt); | |
3866 | memset (nt, 0, sizeof *nt); | |
3867 | ||
3868 | nt->name = name; | |
3869 | nt->type.indx = info->type_indx; | |
3870 | ++info->type_indx; | |
3871 | nt->kind = kind; | |
3872 | ||
3873 | nt->next = info->tags; | |
3874 | info->tags = nt; | |
3875 | ||
3876 | return ieee_push_type (info, nt->type.indx, 0, false); | |
3877 | } | |
3878 | ||
3879 | /* Output a typedef. */ | |
3880 | ||
3881 | static boolean | |
3882 | ieee_typdef (p, name) | |
3883 | PTR p; | |
3884 | const char *name; | |
3885 | { | |
3886 | struct ieee_handle *info = (struct ieee_handle *) p; | |
3887 | struct ieee_name_type *nt; | |
3888 | unsigned int size; | |
3889 | boolean unsignedp; | |
3890 | unsigned int indx; | |
3891 | ||
3892 | nt = (struct ieee_name_type *) xmalloc (sizeof *nt); | |
3893 | memset (nt, 0, sizeof *nt); | |
3894 | nt->name = name; | |
3895 | nt->type = info->type_stack->type; | |
3896 | nt->kind = DEBUG_KIND_VOID; | |
3897 | ||
3898 | nt->next = info->typedefs; | |
3899 | info->typedefs = nt; | |
3900 | ||
3901 | size = info->type_stack->type.size; | |
3902 | unsignedp = info->type_stack->type.unsignedp; | |
3903 | indx = ieee_pop_type (info); | |
3904 | ||
3905 | /* If this is a simple builtin type using a builtin name, we don't | |
3906 | want to output the typedef itself. We also want to change the | |
3907 | type index to correspond to the name being used. We recognize | |
3908 | names used in stabs debugging output even if they don't exactly | |
3909 | correspond to the names used for the IEEE builtin types. */ | |
3910 | if (indx <= (unsigned int) builtin_bcd_float) | |
3911 | { | |
3912 | boolean found; | |
3913 | ||
3914 | found = false; | |
3915 | switch ((enum builtin_types) indx) | |
3916 | { | |
3917 | default: | |
3918 | break; | |
3919 | ||
3920 | case builtin_void: | |
3921 | if (strcmp (name, "void") == 0) | |
3922 | found = true; | |
3923 | break; | |
3924 | ||
3925 | case builtin_signed_char: | |
3926 | case builtin_char: | |
3927 | if (strcmp (name, "signed char") == 0) | |
3928 | { | |
3929 | indx = (unsigned int) builtin_signed_char; | |
3930 | found = true; | |
3931 | } | |
3932 | else if (strcmp (name, "char") == 0) | |
3933 | { | |
3934 | indx = (unsigned int) builtin_char; | |
3935 | found = true; | |
3936 | } | |
3937 | break; | |
3938 | ||
3939 | case builtin_unsigned_char: | |
3940 | if (strcmp (name, "unsigned char") == 0) | |
3941 | found = true; | |
3942 | break; | |
3943 | ||
3944 | case builtin_signed_short_int: | |
3945 | case builtin_short: | |
3946 | case builtin_short_int: | |
3947 | case builtin_signed_short: | |
3948 | if (strcmp (name, "signed short int") == 0) | |
3949 | { | |
3950 | indx = (unsigned int) builtin_signed_short_int; | |
3951 | found = true; | |
3952 | } | |
3953 | else if (strcmp (name, "short") == 0) | |
3954 | { | |
3955 | indx = (unsigned int) builtin_short; | |
3956 | found = true; | |
3957 | } | |
3958 | else if (strcmp (name, "short int") == 0) | |
3959 | { | |
3960 | indx = (unsigned int) builtin_short_int; | |
3961 | found = true; | |
3962 | } | |
3963 | else if (strcmp (name, "signed short") == 0) | |
3964 | { | |
3965 | indx = (unsigned int) builtin_signed_short; | |
3966 | found = true; | |
3967 | } | |
3968 | break; | |
3969 | ||
3970 | case builtin_unsigned_short_int: | |
3971 | case builtin_unsigned_short: | |
3972 | if (strcmp (name, "unsigned short int") == 0 | |
3973 | || strcmp (name, "short unsigned int") == 0) | |
3974 | { | |
3975 | indx = builtin_unsigned_short_int; | |
3976 | found = true; | |
3977 | } | |
3978 | else if (strcmp (name, "unsigned short") == 0) | |
3979 | { | |
3980 | indx = builtin_unsigned_short; | |
3981 | found = true; | |
3982 | } | |
3983 | break; | |
3984 | ||
3985 | case builtin_signed_long: | |
3986 | case builtin_int: /* FIXME: Size depends upon architecture. */ | |
3987 | case builtin_long: | |
3988 | if (strcmp (name, "signed long") == 0) | |
3989 | { | |
3990 | indx = builtin_signed_long; | |
3991 | found = true; | |
3992 | } | |
3993 | else if (strcmp (name, "int") == 0) | |
3994 | { | |
3995 | indx = builtin_int; | |
3996 | found = true; | |
3997 | } | |
3998 | else if (strcmp (name, "long") == 0 | |
3999 | || strcmp (name, "long int") == 0) | |
4000 | { | |
4001 | indx = builtin_long; | |
4002 | found = true; | |
4003 | } | |
4004 | break; | |
4005 | ||
4006 | case builtin_unsigned_long: | |
4007 | case builtin_unsigned: /* FIXME: Size depends upon architecture. */ | |
4008 | case builtin_unsigned_int: /* FIXME: Like builtin_unsigned. */ | |
4009 | if (strcmp (name, "unsigned long") == 0 | |
4010 | || strcmp (name, "long unsigned int") == 0) | |
4011 | { | |
4012 | indx = builtin_unsigned_long; | |
4013 | found = true; | |
4014 | } | |
4015 | else if (strcmp (name, "unsigned") == 0) | |
4016 | { | |
4017 | indx = builtin_unsigned; | |
4018 | found = true; | |
4019 | } | |
4020 | else if (strcmp (name, "unsigned int") == 0) | |
4021 | { | |
4022 | indx = builtin_unsigned_int; | |
4023 | found = true; | |
4024 | } | |
4025 | break; | |
4026 | ||
4027 | case builtin_signed_long_long: | |
4028 | if (strcmp (name, "signed long long") == 0 | |
4029 | || strcmp (name, "long long int") == 0) | |
4030 | found = true; | |
4031 | break; | |
4032 | ||
4033 | case builtin_unsigned_long_long: | |
4034 | if (strcmp (name, "unsigned long long") == 0 | |
4035 | || strcmp (name, "long long unsigned int") == 0) | |
4036 | found = true; | |
4037 | break; | |
4038 | ||
4039 | case builtin_float: | |
4040 | if (strcmp (name, "float") == 0) | |
4041 | found = true; | |
4042 | break; | |
4043 | ||
4044 | case builtin_double: | |
4045 | if (strcmp (name, "double") == 0) | |
4046 | found = true; | |
4047 | break; | |
4048 | ||
4049 | case builtin_long_double: | |
4050 | if (strcmp (name, "long double") == 0) | |
4051 | found = true; | |
4052 | break; | |
4053 | ||
4054 | case builtin_long_long_double: | |
4055 | if (strcmp (name, "long long double") == 0) | |
4056 | found = true; | |
4057 | break; | |
4058 | } | |
4059 | ||
4060 | if (found) | |
4061 | { | |
4062 | nt->type.indx = indx; | |
4063 | return true; | |
4064 | } | |
4065 | } | |
4066 | ||
4067 | if (! ieee_define_named_type (info, name, false, size, unsignedp, | |
4068 | (struct ieee_buf **) NULL) | |
4069 | || ! ieee_write_number (info, 'T') | |
4070 | || ! ieee_write_number (info, indx)) | |
4071 | return false; | |
4072 | ||
4073 | /* Remove the type we just added to the type stack. */ | |
4074 | (void) ieee_pop_type (info); | |
4075 | ||
4076 | return true; | |
4077 | } | |
4078 | ||
4079 | /* Output a tag for a type. We don't have to do anything here. */ | |
4080 | ||
4081 | static boolean | |
4082 | ieee_tag (p, name) | |
4083 | PTR p; | |
4084 | const char *name; | |
4085 | { | |
4086 | struct ieee_handle *info = (struct ieee_handle *) p; | |
4087 | ||
4088 | (void) ieee_pop_type (info); | |
4089 | return true; | |
4090 | } | |
4091 | ||
4092 | /* Output an integer constant. */ | |
4093 | ||
4094 | static boolean | |
4095 | ieee_int_constant (p, name, val) | |
4096 | PTR p; | |
4097 | const char *name; | |
4098 | bfd_vma val; | |
4099 | { | |
4100 | /* FIXME. */ | |
4101 | return true; | |
4102 | } | |
4103 | ||
4104 | /* Output a floating point constant. */ | |
4105 | ||
4106 | static boolean | |
4107 | ieee_float_constant (p, name, val) | |
4108 | PTR p; | |
4109 | const char *name; | |
4110 | double val; | |
4111 | { | |
4112 | /* FIXME. */ | |
4113 | return true; | |
4114 | } | |
4115 | ||
4116 | /* Output a typed constant. */ | |
4117 | ||
4118 | static boolean | |
4119 | ieee_typed_constant (p, name, val) | |
4120 | PTR p; | |
4121 | const char *name; | |
4122 | bfd_vma val; | |
4123 | { | |
4124 | struct ieee_handle *info = (struct ieee_handle *) p; | |
4125 | ||
4126 | /* FIXME. */ | |
4127 | (void) ieee_pop_type (info); | |
4128 | return true; | |
4129 | } | |
4130 | ||
4131 | /* Output a variable. */ | |
4132 | ||
4133 | static boolean | |
4134 | ieee_variable (p, name, kind, val) | |
4135 | PTR p; | |
4136 | const char *name; | |
4137 | enum debug_var_kind kind; | |
4138 | bfd_vma val; | |
4139 | { | |
4140 | struct ieee_handle *info = (struct ieee_handle *) p; | |
4141 | unsigned int name_indx; | |
4142 | unsigned int size; | |
4143 | unsigned int type_indx; | |
4144 | boolean asn; | |
4145 | ||
4146 | /* Make sure the variable section is started. */ | |
4147 | if (info->vars != NULL) | |
4148 | { | |
4149 | if (! ieee_change_buffer (info, &info->vars)) | |
4150 | return false; | |
4151 | } | |
4152 | else | |
4153 | { | |
4154 | if (! ieee_change_buffer (info, &info->vars) | |
4155 | || ! ieee_write_byte (info, (int) ieee_bb_record_enum) | |
4156 | || ! ieee_write_byte (info, 3) | |
4157 | || ! ieee_write_number (info, 0) | |
4158 | || ! ieee_write_id (info, info->modname)) | |
4159 | return false; | |
4160 | } | |
4161 | ||
4162 | name_indx = info->name_indx; | |
4163 | ++info->name_indx; | |
4164 | ||
4165 | size = info->type_stack->type.size; | |
4166 | type_indx = ieee_pop_type (info); | |
4167 | ||
4168 | /* Write out an NN and an ATN record for this variable. */ | |
4169 | if (! ieee_write_byte (info, (int) ieee_nn_record) | |
4170 | || ! ieee_write_number (info, name_indx) | |
4171 | || ! ieee_write_id (info, name) | |
4172 | || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum) | |
4173 | || ! ieee_write_number (info, name_indx) | |
4174 | || ! ieee_write_number (info, type_indx)) | |
4175 | return false; | |
4176 | switch (kind) | |
4177 | { | |
4178 | default: | |
4179 | abort (); | |
4180 | return false; | |
4181 | case DEBUG_GLOBAL: | |
4182 | if (! ieee_write_number (info, 8) | |
4183 | || ! ieee_add_range (info, val, val + size)) | |
4184 | return false; | |
4185 | asn = true; | |
4186 | break; | |
4187 | case DEBUG_STATIC: | |
4188 | case DEBUG_LOCAL_STATIC: | |
4189 | if (! ieee_write_number (info, 3) | |
4190 | || ! ieee_add_range (info, val, val + size)) | |
4191 | return false; | |
4192 | asn = true; | |
4193 | break; | |
4194 | case DEBUG_LOCAL: | |
4195 | if (! ieee_write_number (info, 1) | |
4196 | || ! ieee_write_number (info, val)) | |
4197 | return false; | |
4198 | asn = false; | |
4199 | break; | |
4200 | case DEBUG_REGISTER: | |
4201 | if (! ieee_write_number (info, 2) | |
4202 | || ! ieee_write_number (info, | |
4203 | ieee_genreg_to_regno (info->abfd, val))) | |
4204 | return false; | |
4205 | asn = false; | |
4206 | break; | |
4207 | } | |
4208 | ||
4209 | if (asn) | |
4210 | { | |
4211 | if (! ieee_write_2bytes (info, (int) ieee_asn_record_enum) | |
4212 | || ! ieee_write_number (info, name_indx) | |
4213 | || ! ieee_write_number (info, val)) | |
4214 | return false; | |
4215 | } | |
4216 | ||
4217 | return true; | |
4218 | } | |
4219 | ||
4220 | /* Start outputting information for a function. */ | |
4221 | ||
4222 | static boolean | |
4223 | ieee_start_function (p, name, global) | |
4224 | PTR p; | |
4225 | const char *name; | |
4226 | boolean global; | |
4227 | { | |
4228 | struct ieee_handle *info = (struct ieee_handle *) p; | |
4229 | unsigned int indx; | |
4230 | ||
4231 | /* Make sure the variable section is started. */ | |
4232 | if (info->vars != NULL) | |
4233 | { | |
4234 | if (! ieee_change_buffer (info, &info->vars)) | |
4235 | return false; | |
4236 | } | |
4237 | else | |
4238 | { | |
4239 | if (! ieee_change_buffer (info, &info->vars) | |
4240 | || ! ieee_write_byte (info, (int) ieee_bb_record_enum) | |
4241 | || ! ieee_write_byte (info, 3) | |
4242 | || ! ieee_write_number (info, 0) | |
4243 | || ! ieee_write_id (info, info->modname)) | |
4244 | return false; | |
4245 | } | |
4246 | ||
4247 | indx = ieee_pop_type (info); | |
4248 | ||
4249 | /* The address is written out as the first block. */ | |
4250 | ||
4251 | ++info->block_depth; | |
4252 | ||
4253 | return (ieee_write_byte (info, (int) ieee_bb_record_enum) | |
4254 | && ieee_write_byte (info, global ? 4 : 6) | |
4255 | && ieee_write_number (info, 0) | |
4256 | && ieee_write_id (info, name) | |
4257 | && ieee_write_number (info, 0) | |
4258 | && ieee_write_number (info, indx)); | |
4259 | } | |
4260 | ||
4261 | /* Add a function parameter. This will normally be called before the | |
4262 | first block, so we postpone them until we see the block. */ | |
4263 | ||
4264 | static boolean | |
4265 | ieee_function_parameter (p, name, kind, val) | |
4266 | PTR p; | |
4267 | const char *name; | |
4268 | enum debug_parm_kind kind; | |
4269 | bfd_vma val; | |
4270 | { | |
4271 | struct ieee_handle *info = (struct ieee_handle *) p; | |
4272 | struct ieee_pending_parm *m, **pm; | |
4273 | ||
4274 | assert (info->block_depth == 1); | |
4275 | ||
4276 | m = (struct ieee_pending_parm *) xmalloc (sizeof *m); | |
4277 | memset (m, 0, sizeof *m); | |
4278 | ||
4279 | m->next = NULL; | |
4280 | m->name = name; | |
4281 | m->type = ieee_pop_type (info); | |
4282 | m->kind = kind; | |
4283 | m->val = val; | |
4284 | ||
4285 | for (pm = &info->pending_parms; *pm != NULL; pm = &(*pm)->next) | |
4286 | ; | |
4287 | *pm = m; | |
4288 | ||
4289 | return true; | |
4290 | } | |
4291 | ||
4292 | /* Output pending function parameters. */ | |
4293 | ||
4294 | static boolean | |
4295 | ieee_output_pending_parms (info) | |
4296 | struct ieee_handle *info; | |
4297 | { | |
4298 | struct ieee_pending_parm *m; | |
4299 | ||
4300 | m = info->pending_parms; | |
4301 | while (m != NULL) | |
4302 | { | |
4303 | struct ieee_pending_parm *next; | |
4304 | enum debug_var_kind vkind; | |
4305 | ||
4306 | switch (m->kind) | |
4307 | { | |
4308 | default: | |
4309 | abort (); | |
4310 | return false; | |
4311 | case DEBUG_PARM_STACK: | |
4312 | case DEBUG_PARM_REFERENCE: | |
4313 | vkind = DEBUG_LOCAL; | |
4314 | break; | |
4315 | case DEBUG_PARM_REG: | |
4316 | case DEBUG_PARM_REF_REG: | |
4317 | vkind = DEBUG_REGISTER; | |
4318 | break; | |
4319 | } | |
4320 | ||
4321 | if (! ieee_push_type (info, m->type, 0, false) | |
4322 | || ! ieee_variable ((PTR) info, m->name, vkind, m->val)) | |
4323 | return false; | |
4324 | ||
4325 | /* FIXME: We should output a pmisc note here for reference | |
4326 | parameters. */ | |
4327 | ||
4328 | next = m->next; | |
4329 | free (m); | |
4330 | m = next; | |
4331 | } | |
4332 | info->pending_parms = NULL; | |
4333 | ||
4334 | return true; | |
4335 | } | |
4336 | ||
4337 | /* Start a block. If this is the first block, we output the address | |
4338 | to finish the BB4 or BB6, and then output the function parameters. */ | |
4339 | ||
4340 | static boolean | |
4341 | ieee_start_block (p, addr) | |
4342 | PTR p; | |
4343 | bfd_vma addr; | |
4344 | { | |
4345 | struct ieee_handle *info = (struct ieee_handle *) p; | |
4346 | ||
4347 | if (! ieee_change_buffer (info, &info->vars)) | |
4348 | return false; | |
4349 | ||
4350 | if (info->block_depth == 1) | |
4351 | { | |
4352 | if (! ieee_write_number (info, addr) | |
4353 | || ! ieee_output_pending_parms (info)) | |
4354 | return false; | |
4355 | } | |
4356 | else | |
4357 | { | |
4358 | if (! ieee_write_byte (info, (int) ieee_bb_record_enum) | |
4359 | || ! ieee_write_byte (info, 6) | |
4360 | || ! ieee_write_byte (info, 0) | |
4361 | || ! ieee_write_id (info, "") | |
4362 | || ! ieee_write_number (info, 0) | |
4363 | || ! ieee_write_number (info, 0) | |
4364 | || ! ieee_write_number (info, addr)) | |
4365 | return false; | |
4366 | } | |
4367 | ||
4368 | if (! ieee_start_range (info, addr)) | |
4369 | return false; | |
4370 | ||
4371 | ++info->block_depth; | |
4372 | ||
4373 | return true; | |
4374 | } | |
4375 | ||
4376 | /* End a block. */ | |
4377 | ||
4378 | static boolean | |
4379 | ieee_end_block (p, addr) | |
4380 | PTR p; | |
4381 | bfd_vma addr; | |
4382 | { | |
4383 | struct ieee_handle *info = (struct ieee_handle *) p; | |
4384 | ||
4385 | if (! ieee_change_buffer (info, &info->vars) | |
4386 | || ! ieee_write_byte (info, (int) ieee_be_record_enum) | |
4387 | || ! ieee_write_number (info, addr)) | |
4388 | return false; | |
4389 | ||
4390 | if (! ieee_end_range (info, addr)) | |
4391 | return false; | |
4392 | ||
4393 | --info->block_depth; | |
4394 | ||
4395 | return true; | |
4396 | } | |
4397 | ||
4398 | /* End a function. */ | |
4399 | ||
4400 | static boolean | |
4401 | ieee_end_function (p) | |
4402 | PTR p; | |
4403 | { | |
4404 | struct ieee_handle *info = (struct ieee_handle *) p; | |
4405 | ||
4406 | assert (info->block_depth == 1); | |
4407 | ||
4408 | --info->block_depth; | |
4409 | ||
4410 | return true; | |
4411 | } | |
4412 | ||
4413 | /* Record line number information. */ | |
4414 | ||
4415 | static boolean | |
4416 | ieee_lineno (p, filename, lineno, addr) | |
4417 | PTR p; | |
4418 | const char *filename; | |
4419 | unsigned long lineno; | |
4420 | bfd_vma addr; | |
4421 | { | |
4422 | struct ieee_handle *info = (struct ieee_handle *) p; | |
4423 | ||
4424 | assert (info->filename != NULL); | |
4425 | ||
4426 | /* Make sure we have a line number block. */ | |
4427 | if (info->linenos != NULL) | |
4428 | { | |
4429 | if (! ieee_change_buffer (info, &info->linenos)) | |
4430 | return false; | |
4431 | } | |
4432 | else | |
4433 | { | |
4434 | info->lineno_name_indx = info->name_indx; | |
4435 | ++info->name_indx; | |
4436 | if (! ieee_change_buffer (info, &info->linenos) | |
4437 | || ! ieee_write_byte (info, (int) ieee_bb_record_enum) | |
4438 | || ! ieee_write_byte (info, 5) | |
4439 | || ! ieee_write_number (info, 0) | |
4440 | || ! ieee_write_id (info, info->filename) | |
4441 | || ! ieee_write_byte (info, (int) ieee_nn_record) | |
4442 | || ! ieee_write_number (info, info->lineno_name_indx) | |
4443 | || ! ieee_write_id (info, "")) | |
4444 | return false; | |
4445 | info->lineno_filename = info->filename; | |
4446 | } | |
4447 | ||
4448 | if (strcmp (filename, info->lineno_filename) != 0) | |
4449 | { | |
4450 | if (strcmp (info->filename, info->lineno_filename) != 0) | |
4451 | { | |
4452 | /* We were not in the main file. Close the block for the | |
4453 | included file. */ | |
4454 | if (! ieee_write_byte (info, (int) ieee_be_record_enum)) | |
4455 | return false; | |
4456 | } | |
4457 | if (strcmp (info->filename, filename) != 0) | |
4458 | { | |
4459 | /* We are not changing to the main file. Open a block for | |
4460 | the new included file. */ | |
4461 | if (! ieee_write_byte (info, (int) ieee_bb_record_enum) | |
4462 | || ! ieee_write_byte (info, 5) | |
4463 | || ! ieee_write_number (info, 0) | |
4464 | || ! ieee_write_id (info, filename)) | |
4465 | return false; | |
4466 | } | |
4467 | info->lineno_filename = filename; | |
4468 | } | |
4469 | ||
4470 | return (ieee_write_2bytes (info, (int) ieee_atn_record_enum) | |
4471 | && ieee_write_number (info, info->lineno_name_indx) | |
4472 | && ieee_write_number (info, 0) | |
4473 | && ieee_write_number (info, 7) | |
4474 | && ieee_write_number (info, lineno) | |
4475 | && ieee_write_number (info, 0) | |
4476 | && ieee_write_2bytes (info, (int) ieee_asn_record_enum) | |
4477 | && ieee_write_number (info, info->lineno_name_indx) | |
4478 | && ieee_write_number (info, addr)); | |
4479 | } |