mips.h (MASK_FIX_SB1): Bump.
[gcc.git] / gcc / vmsdbgout.c
1 /* Output VMS debug format symbol table information from GCC.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4 Contributed by Douglas B. Rupp (rupp@gnat.com).
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA. */
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27
28 #ifdef VMS_DEBUGGING_INFO
29 #include "tree.h"
30 #include "flags.h"
31 #include "rtl.h"
32 #include "output.h"
33 #include "vmsdbg.h"
34 #include "debug.h"
35 #include "langhooks.h"
36 #include "function.h"
37 #include "target.h"
38
39 /* Difference in seconds between the VMS Epoch and the Unix Epoch */
40 static const long long vms_epoch_offset = 3506716800ll;
41
42 /* NOTE: In the comments in this file, many references are made to "Debug
43 Symbol Table". This term is abbreviated as `DST' throughout the remainder
44 of this file. */
45
46 typedef struct dst_line_info_struct *dst_line_info_ref;
47
48 /* Each entry in the line_info_table maintains the file and
49 line number associated with the label generated for that
50 entry. The label gives the PC value associated with
51 the line number entry. */
52 typedef struct dst_line_info_struct
53 {
54 unsigned long dst_file_num;
55 unsigned long dst_line_num;
56 }
57 dst_line_info_entry;
58
59 typedef struct dst_file_info_struct *dst_file_info_ref;
60
61 typedef struct dst_file_info_struct
62 {
63 char *file_name;
64 unsigned int max_line;
65 unsigned int listing_line_start;
66 long long cdt;
67 long ebk;
68 short ffb;
69 char rfo;
70 char flen;
71 }
72 dst_file_info_entry;
73
74 /* How to start an assembler comment. */
75 #ifndef ASM_COMMENT_START
76 #define ASM_COMMENT_START ";#"
77 #endif
78
79 /* Maximum size (in bytes) of an artificially generated label. */
80 #define MAX_ARTIFICIAL_LABEL_BYTES 30
81
82 /* Make sure we know the sizes of the various types debug can describe. These
83 are only defaults. If the sizes are different for your target, you should
84 override these values by defining the appropriate symbols in your tm.h
85 file. */
86 #ifndef PTR_SIZE
87 #define PTR_SIZE 4 /* Must be 32 bits for VMS debug info */
88 #endif
89
90 /* Pointer to a structure of filenames referenced by this compilation unit. */
91 static dst_file_info_ref file_info_table;
92
93 /* Total number of entries in the table (i.e. array) pointed to by
94 `file_info_table'. This is the *total* and includes both used and unused
95 slots. */
96 static unsigned int file_info_table_allocated;
97
98 /* Number of entries in the file_info_table which are actually in use. */
99 static unsigned int file_info_table_in_use;
100
101 /* Size (in elements) of increments by which we may expand the filename
102 table. */
103 #define FILE_TABLE_INCREMENT 64
104
105 static char **func_table;
106 static unsigned int func_table_allocated;
107 static unsigned int func_table_in_use;
108 #define FUNC_TABLE_INCREMENT 256
109
110 /* Local pointer to the name of the main input file. Initialized in
111 avmdbgout_init. */
112 static const char *primary_filename;
113
114 static char *module_producer;
115 static unsigned int module_language;
116
117 /* A pointer to the base of a table that contains line information
118 for each source code line in .text in the compilation unit. */
119 static dst_line_info_ref line_info_table;
120
121 /* Number of elements currently allocated for line_info_table. */
122 static unsigned int line_info_table_allocated;
123
124 /* Number of elements in line_info_table currently in use. */
125 static unsigned int line_info_table_in_use;
126
127 /* Size (in elements) of increments by which we may expand line_info_table. */
128 #define LINE_INFO_TABLE_INCREMENT 1024
129
130 /* Forward declarations for functions defined in this file. */
131 static char *full_name (const char *);
132 static unsigned int lookup_filename (const char *);
133 static void addr_const_to_string (char *, rtx);
134 static int write_debug_header (DST_HEADER *, const char *, int);
135 static int write_debug_addr (char *, const char *, int);
136 static int write_debug_data1 (unsigned int, const char *, int);
137 static int write_debug_data2 (unsigned int, const char *, int);
138 static int write_debug_data4 (unsigned long, const char *, int);
139 static int write_debug_data8 (unsigned long long, const char *, int);
140 static int write_debug_delta4 (char *, char *, const char *, int);
141 static int write_debug_string (char *, const char *, int);
142 static int write_modbeg (int);
143 static int write_modend (int);
144 static int write_rtnbeg (int, int);
145 static int write_rtnend (int, int);
146 static int write_pclines (int);
147 static int write_srccorr (int, dst_file_info_entry, int);
148 static int write_srccorrs (int);
149
150 static void vmsdbgout_init (const char *);
151 static void vmsdbgout_finish (const char *);
152 static void vmsdbgout_define (unsigned int, const char *);
153 static void vmsdbgout_undef (unsigned int, const char *);
154 static void vmsdbgout_start_source_file (unsigned int, const char *);
155 static void vmsdbgout_end_source_file (unsigned int);
156 static void vmsdbgout_begin_block (unsigned int, unsigned int);
157 static void vmsdbgout_end_block (unsigned int, unsigned int);
158 static bool vmsdbgout_ignore_block (tree);
159 static void vmsdbgout_source_line (unsigned int, const char *);
160 static void vmsdbgout_begin_prologue (unsigned int, const char *);
161 static void vmsdbgout_end_prologue (unsigned int, const char *);
162 static void vmsdbgout_end_function (unsigned int);
163 static void vmsdbgout_end_epilogue (unsigned int, const char *);
164 static void vmsdbgout_begin_function (tree);
165 static void vmsdbgout_decl (tree);
166 static void vmsdbgout_global_decl (tree);
167 static void vmsdbgout_abstract_function (tree);
168
169 /* The debug hooks structure. */
170
171 const struct gcc_debug_hooks vmsdbg_debug_hooks
172 = {vmsdbgout_init,
173 vmsdbgout_finish,
174 vmsdbgout_define,
175 vmsdbgout_undef,
176 vmsdbgout_start_source_file,
177 vmsdbgout_end_source_file,
178 vmsdbgout_begin_block,
179 vmsdbgout_end_block,
180 vmsdbgout_ignore_block,
181 vmsdbgout_source_line,
182 vmsdbgout_begin_prologue,
183 vmsdbgout_end_prologue,
184 vmsdbgout_end_epilogue,
185 vmsdbgout_begin_function,
186 vmsdbgout_end_function,
187 vmsdbgout_decl,
188 vmsdbgout_global_decl,
189 debug_nothing_tree_int, /* type_decl */
190 debug_nothing_tree_tree, /* imported_module_or_decl */
191 debug_nothing_tree, /* deferred_inline_function */
192 vmsdbgout_abstract_function,
193 debug_nothing_rtx, /* label */
194 debug_nothing_int, /* handle_pch */
195 debug_nothing_rtx /* var_location */
196 };
197
198 /* Definitions of defaults for assembler-dependent names of various
199 pseudo-ops and section names.
200 Theses may be overridden in the tm.h file (if necessary) for a particular
201 assembler. */
202 #ifdef UNALIGNED_SHORT_ASM_OP
203 #undef UNALIGNED_SHORT_ASM_OP
204 #endif
205 #define UNALIGNED_SHORT_ASM_OP ".word"
206
207 #ifdef UNALIGNED_INT_ASM_OP
208 #undef UNALIGNED_INT_ASM_OP
209 #endif
210 #define UNALIGNED_INT_ASM_OP ".long"
211
212 #ifdef UNALIGNED_LONG_ASM_OP
213 #undef UNALIGNED_LONG_ASM_OP
214 #endif
215 #define UNALIGNED_LONG_ASM_OP ".long"
216
217 #ifdef UNALIGNED_DOUBLE_INT_ASM_OP
218 #undef UNALIGNED_DOUBLE_INT_ASM_OP
219 #endif
220 #define UNALIGNED_DOUBLE_INT_ASM_OP ".quad"
221
222 #ifdef ASM_BYTE_OP
223 #undef ASM_BYTE_OP
224 #endif
225 #define ASM_BYTE_OP ".byte"
226
227 #define NUMBYTES(I) ((I) < 256 ? 1 : (I) < 65536 ? 2 : 4)
228
229 #define NUMBYTES0(I) ((I) < 128 ? 0 : (I) < 65536 ? 2 : 4)
230
231 #ifndef UNALIGNED_PTR_ASM_OP
232 #define UNALIGNED_PTR_ASM_OP \
233 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
234 #endif
235
236 #ifndef UNALIGNED_OFFSET_ASM_OP
237 #define UNALIGNED_OFFSET_ASM_OP(OFFSET) \
238 (NUMBYTES(OFFSET) == 4 \
239 ? UNALIGNED_LONG_ASM_OP \
240 : (NUMBYTES(OFFSET) == 2 ? UNALIGNED_SHORT_ASM_OP : ASM_BYTE_OP))
241 #endif
242
243 /* Definitions of defaults for formats and names of various special
244 (artificial) labels which may be generated within this file (when the -g
245 options is used and VMS_DEBUGGING_INFO is in effect. If necessary, these
246 may be overridden from within the tm.h file, but typically, overriding these
247 defaults is unnecessary. */
248
249 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
250
251 #ifndef TEXT_END_LABEL
252 #define TEXT_END_LABEL "Lvetext"
253 #endif
254 #ifndef FUNC_BEGIN_LABEL
255 #define FUNC_BEGIN_LABEL "LVFB"
256 #endif
257 #ifndef FUNC_PROLOG_LABEL
258 #define FUNC_PROLOG_LABEL "LVFP"
259 #endif
260 #ifndef FUNC_END_LABEL
261 #define FUNC_END_LABEL "LVFE"
262 #endif
263 #ifndef BLOCK_BEGIN_LABEL
264 #define BLOCK_BEGIN_LABEL "LVBB"
265 #endif
266 #ifndef BLOCK_END_LABEL
267 #define BLOCK_END_LABEL "LVBE"
268 #endif
269 #ifndef LINE_CODE_LABEL
270 #define LINE_CODE_LABEL "LVM"
271 #endif
272
273 #ifndef ASM_OUTPUT_DEBUG_DELTA2
274 #define ASM_OUTPUT_DEBUG_DELTA2(FILE,LABEL1,LABEL2) \
275 do \
276 { \
277 fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
278 assemble_name (FILE, LABEL1); \
279 fprintf (FILE, "-"); \
280 assemble_name (FILE, LABEL2); \
281 } \
282 while (0)
283 #endif
284
285 #ifndef ASM_OUTPUT_DEBUG_DELTA4
286 #define ASM_OUTPUT_DEBUG_DELTA4(FILE,LABEL1,LABEL2) \
287 do \
288 { \
289 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
290 assemble_name (FILE, LABEL1); \
291 fprintf (FILE, "-"); \
292 assemble_name (FILE, LABEL2); \
293 } \
294 while (0)
295 #endif
296
297 #ifndef ASM_OUTPUT_DEBUG_ADDR_DELTA
298 #define ASM_OUTPUT_DEBUG_ADDR_DELTA(FILE,LABEL1,LABEL2) \
299 do \
300 { \
301 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
302 assemble_name (FILE, LABEL1); \
303 fprintf (FILE, "-"); \
304 assemble_name (FILE, LABEL2); \
305 } \
306 while (0)
307 #endif
308
309 #ifndef ASM_OUTPUT_DEBUG_ADDR
310 #define ASM_OUTPUT_DEBUG_ADDR(FILE,LABEL) \
311 do \
312 { \
313 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
314 assemble_name (FILE, LABEL); \
315 } \
316 while (0)
317 #endif
318
319 #ifndef ASM_OUTPUT_DEBUG_ADDR_CONST
320 #define ASM_OUTPUT_DEBUG_ADDR_CONST(FILE,ADDR) \
321 fprintf ((FILE), "\t%s\t%s", UNALIGNED_PTR_ASM_OP, (ADDR))
322 #endif
323
324 #ifndef ASM_OUTPUT_DEBUG_DATA1
325 #define ASM_OUTPUT_DEBUG_DATA1(FILE,VALUE) \
326 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned char) VALUE)
327 #endif
328
329 #ifndef ASM_OUTPUT_DEBUG_DATA2
330 #define ASM_OUTPUT_DEBUG_DATA2(FILE,VALUE) \
331 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, \
332 (unsigned short) VALUE)
333 #endif
334
335 #ifndef ASM_OUTPUT_DEBUG_DATA4
336 #define ASM_OUTPUT_DEBUG_DATA4(FILE,VALUE) \
337 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (unsigned long) VALUE)
338 #endif
339
340 #ifndef ASM_OUTPUT_DEBUG_DATA
341 #define ASM_OUTPUT_DEBUG_DATA(FILE,VALUE) \
342 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP(VALUE), VALUE)
343 #endif
344
345 #ifndef ASM_OUTPUT_DEBUG_ADDR_DATA
346 #define ASM_OUTPUT_DEBUG_ADDR_DATA(FILE,VALUE) \
347 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_PTR_ASM_OP, \
348 (unsigned long) VALUE)
349 #endif
350
351 #ifndef ASM_OUTPUT_DEBUG_DATA8
352 #define ASM_OUTPUT_DEBUG_DATA8(FILE,VALUE) \
353 fprintf ((FILE), "\t%s\t0x%llx", UNALIGNED_DOUBLE_INT_ASM_OP, \
354 (unsigned long long) VALUE)
355 #endif
356
357 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
358 newline is produced. When flag_verbose_asm is asserted, we add commentary
359 at the end of the line, so we must avoid output of a newline here. */
360 #ifndef ASM_OUTPUT_DEBUG_STRING
361 #define ASM_OUTPUT_DEBUG_STRING(FILE,P) \
362 do \
363 { \
364 register int slen = strlen(P); \
365 register char *p = (P); \
366 register int i; \
367 fprintf (FILE, "\t.ascii \""); \
368 for (i = 0; i < slen; i++) \
369 { \
370 register int c = p[i]; \
371 if (c == '\"' || c == '\\') \
372 putc ('\\', FILE); \
373 if (c >= ' ' && c < 0177) \
374 putc (c, FILE); \
375 else \
376 fprintf (FILE, "\\%o", c); \
377 } \
378 fprintf (FILE, "\""); \
379 } \
380 while (0)
381 #endif
382
383 /* Convert a reference to the assembler name of a C-level name. This
384 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
385 a string rather than writing to a file. */
386 #ifndef ASM_NAME_TO_STRING
387 #define ASM_NAME_TO_STRING(STR, NAME) \
388 do \
389 { \
390 if ((NAME)[0] == '*') \
391 strcpy (STR, NAME+1); \
392 else \
393 strcpy (STR, NAME); \
394 } \
395 while (0)
396 #endif
397
398 \f
399 /* General utility functions. */
400
401 /* Convert an integer constant expression into assembler syntax. Addition and
402 subtraction are the only arithmetic that may appear in these expressions.
403 This is an adaptation of output_addr_const in final.c. Here, the target
404 of the conversion is a string buffer. We can't use output_addr_const
405 directly, because it writes to a file. */
406
407 static void
408 addr_const_to_string (char *str, rtx x)
409 {
410 char buf1[256];
411 char buf2[256];
412
413 restart:
414 str[0] = '\0';
415 switch (GET_CODE (x))
416 {
417 case PC:
418 if (flag_pic)
419 strcat (str, ",");
420 else
421 abort ();
422 break;
423
424 case SYMBOL_REF:
425 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
426 strcat (str, buf1);
427 break;
428
429 case LABEL_REF:
430 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
431 ASM_NAME_TO_STRING (buf2, buf1);
432 strcat (str, buf2);
433 break;
434
435 case CODE_LABEL:
436 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
437 ASM_NAME_TO_STRING (buf2, buf1);
438 strcat (str, buf2);
439 break;
440
441 case CONST_INT:
442 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
443 strcat (str, buf1);
444 break;
445
446 case CONST:
447 /* This used to output parentheses around the expression, but that does
448 not work on the 386 (either ATT or BSD assembler). */
449 addr_const_to_string (buf1, XEXP (x, 0));
450 strcat (str, buf1);
451 break;
452
453 case CONST_DOUBLE:
454 if (GET_MODE (x) == VOIDmode)
455 {
456 /* We can use %d if the number is one word and positive. */
457 if (CONST_DOUBLE_HIGH (x))
458 sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
459 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
460 else if (CONST_DOUBLE_LOW (x) < 0)
461 sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
462 else
463 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
464 CONST_DOUBLE_LOW (x));
465 strcat (str, buf1);
466 }
467 else
468 /* We can't handle floating point constants; PRINT_OPERAND must
469 handle them. */
470 output_operand_lossage ("floating constant misused");
471 break;
472
473 case PLUS:
474 /* Some assemblers need integer constants to appear last (eg masm). */
475 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
476 {
477 addr_const_to_string (buf1, XEXP (x, 1));
478 strcat (str, buf1);
479 if (INTVAL (XEXP (x, 0)) >= 0)
480 strcat (str, "+");
481 addr_const_to_string (buf1, XEXP (x, 0));
482 strcat (str, buf1);
483 }
484 else
485 {
486 addr_const_to_string (buf1, XEXP (x, 0));
487 strcat (str, buf1);
488 if (INTVAL (XEXP (x, 1)) >= 0)
489 strcat (str, "+");
490 addr_const_to_string (buf1, XEXP (x, 1));
491 strcat (str, buf1);
492 }
493 break;
494
495 case MINUS:
496 /* Avoid outputting things like x-x or x+5-x, since some assemblers
497 can't handle that. */
498 x = simplify_subtraction (x);
499 if (GET_CODE (x) != MINUS)
500 goto restart;
501
502 addr_const_to_string (buf1, XEXP (x, 0));
503 strcat (str, buf1);
504 strcat (str, "-");
505 if (GET_CODE (XEXP (x, 1)) == CONST_INT
506 && INTVAL (XEXP (x, 1)) < 0)
507 {
508 strcat (str, "(");
509 addr_const_to_string (buf1, XEXP (x, 1));
510 strcat (str, buf1);
511 strcat (str, ")");
512 }
513 else
514 {
515 addr_const_to_string (buf1, XEXP (x, 1));
516 strcat (str, buf1);
517 }
518 break;
519
520 case ZERO_EXTEND:
521 case SIGN_EXTEND:
522 addr_const_to_string (buf1, XEXP (x, 0));
523 strcat (str, buf1);
524 break;
525
526 default:
527 output_operand_lossage ("invalid expression as operand");
528 }
529 }
530
531 /* Output the debug header HEADER. Also output COMMENT if flag_verbose_asm is
532 set. Return the header size. Just return the size if DOSIZEONLY is
533 nonzero. */
534
535 static int
536 write_debug_header (DST_HEADER *header, const char *comment, int dosizeonly)
537 {
538 if (!dosizeonly)
539 {
540 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
541 header->dst__header_length.dst_w_length);
542
543 if (flag_verbose_asm)
544 fprintf (asm_out_file, "\t%s record length", ASM_COMMENT_START);
545 fputc ('\n', asm_out_file);
546
547 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
548 header->dst__header_type.dst_w_type);
549
550 if (flag_verbose_asm)
551 fprintf (asm_out_file, "\t%s record type (%s)", ASM_COMMENT_START,
552 comment);
553
554 fputc ('\n', asm_out_file);
555 }
556
557 return 4;
558 }
559
560 /* Output the address of SYMBOL. Also output COMMENT if flag_verbose_asm is
561 set. Return the address size. Just return the size if DOSIZEONLY is
562 nonzero. */
563
564 static int
565 write_debug_addr (char *symbol, const char *comment, int dosizeonly)
566 {
567 if (!dosizeonly)
568 {
569 ASM_OUTPUT_DEBUG_ADDR (asm_out_file, symbol);
570 if (flag_verbose_asm)
571 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
572 fputc ('\n', asm_out_file);
573 }
574
575 return PTR_SIZE;
576 }
577
578 /* Output the single byte DATA1. Also output COMMENT if flag_verbose_asm is
579 set. Return the data size. Just return the size if DOSIZEONLY is
580 nonzero. */
581
582 static int
583 write_debug_data1 (unsigned int data1, const char *comment, int dosizeonly)
584 {
585 if (!dosizeonly)
586 {
587 ASM_OUTPUT_DEBUG_DATA1 (asm_out_file, data1);
588 if (flag_verbose_asm)
589 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
590 fputc ('\n', asm_out_file);
591 }
592
593 return 1;
594 }
595
596 /* Output the single word DATA2. Also output COMMENT if flag_verbose_asm is
597 set. Return the data size. Just return the size if DOSIZEONLY is
598 nonzero. */
599
600 static int
601 write_debug_data2 (unsigned int data2, const char *comment, int dosizeonly)
602 {
603 if (!dosizeonly)
604 {
605 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file, data2);
606 if (flag_verbose_asm)
607 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
608 fputc ('\n', asm_out_file);
609 }
610
611 return 2;
612 }
613
614 /* Output double word DATA4. Also output COMMENT if flag_verbose_asm is set.
615 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
616
617 static int
618 write_debug_data4 (unsigned long data4, const char *comment, int dosizeonly)
619 {
620 if (!dosizeonly)
621 {
622 ASM_OUTPUT_DEBUG_DATA4 (asm_out_file, data4);
623 if (flag_verbose_asm)
624 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
625 fputc ('\n', asm_out_file);
626 }
627
628 return 4;
629 }
630
631 /* Output quad word DATA8. Also output COMMENT if flag_verbose_asm is set.
632 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
633
634 static int
635 write_debug_data8 (unsigned long long data8, const char *comment,
636 int dosizeonly)
637 {
638 if (!dosizeonly)
639 {
640 ASM_OUTPUT_DEBUG_DATA8 (asm_out_file, data8);
641 if (flag_verbose_asm)
642 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
643 fputc ('\n', asm_out_file);
644 }
645
646 return 8;
647 }
648
649 /* Output the difference between LABEL1 and LABEL2. Also output COMMENT if
650 flag_verbose_asm is set. Return the data size. Just return the size if
651 DOSIZEONLY is nonzero. */
652
653 static int
654 write_debug_delta4 (char *label1, char *label2, const char *comment,
655 int dosizeonly)
656 {
657 if (!dosizeonly)
658 {
659 ASM_OUTPUT_DEBUG_DELTA4 (asm_out_file, label1, label2);
660 if (flag_verbose_asm)
661 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
662 fputc ('\n', asm_out_file);
663 }
664
665 return 4;
666 }
667
668 /* Output a character string STRING. Also write COMMENT if flag_verbose_asm is
669 set. Return the string length. Just return the length if DOSIZEONLY is
670 nonzero. */
671
672 static int
673 write_debug_string (char *string, const char *comment, int dosizeonly)
674 {
675 if (!dosizeonly)
676 {
677 ASM_OUTPUT_DEBUG_STRING (asm_out_file, string);
678 if (flag_verbose_asm)
679 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
680 fputc ('\n', asm_out_file);
681 }
682
683 return strlen (string);
684 }
685
686 /* Output a module begin header and return the header size. Just return the
687 size if DOSIZEONLY is nonzero. */
688
689 static int
690 write_modbeg (int dosizeonly)
691 {
692 DST_MODULE_BEGIN modbeg;
693 DST_MB_TRLR mb_trlr;
694 int i;
695 char *module_name, *m;
696 int modnamelen;
697 int prodnamelen;
698 int totsize = 0;
699
700 /* Assumes primary filename has Unix syntax file spec. */
701 module_name = xstrdup (basename ((char *) primary_filename));
702
703 m = strrchr (module_name, '.');
704 if (m)
705 *m = 0;
706
707 modnamelen = strlen (module_name);
708 for (i = 0; i < modnamelen; i++)
709 module_name[i] = TOUPPER (module_name[i]);
710
711 prodnamelen = strlen (module_producer);
712
713 modbeg.dst_a_modbeg_header.dst__header_length.dst_w_length
714 = DST_K_MODBEG_SIZE + modnamelen + DST_K_MB_TRLR_SIZE + prodnamelen - 1;
715 modbeg.dst_a_modbeg_header.dst__header_type.dst_w_type = DST_K_MODBEG;
716 modbeg.dst_b_modbeg_flags.dst_v_modbeg_hide = 0;
717 modbeg.dst_b_modbeg_flags.dst_v_modbeg_version = 1;
718 modbeg.dst_b_modbeg_flags.dst_v_modbeg_unused = 0;
719 modbeg.dst_b_modbeg_unused = 0;
720 modbeg.dst_l_modbeg_language = module_language;
721 modbeg.dst_w_version_major = DST_K_VERSION_MAJOR;
722 modbeg.dst_w_version_minor = DST_K_VERSION_MINOR;
723 modbeg.dst_b_modbeg_name = strlen (module_name);
724
725 mb_trlr.dst_b_compiler = strlen (module_producer);
726
727 totsize += write_debug_header (&modbeg.dst_a_modbeg_header,
728 "modbeg", dosizeonly);
729 totsize += write_debug_data1 (*((char *) &modbeg.dst_b_modbeg_flags),
730 "flags", dosizeonly);
731 totsize += write_debug_data1 (modbeg.dst_b_modbeg_unused,
732 "unused", dosizeonly);
733 totsize += write_debug_data4 (modbeg.dst_l_modbeg_language,
734 "language", dosizeonly);
735 totsize += write_debug_data2 (modbeg.dst_w_version_major,
736 "DST major version", dosizeonly);
737 totsize += write_debug_data2 (modbeg.dst_w_version_minor,
738 "DST minor version", dosizeonly);
739 totsize += write_debug_data1 (modbeg.dst_b_modbeg_name,
740 "length of module name", dosizeonly);
741 totsize += write_debug_string (module_name, "module name", dosizeonly);
742 totsize += write_debug_data1 (mb_trlr.dst_b_compiler,
743 "length of compiler name", dosizeonly);
744 totsize += write_debug_string (module_producer, "compiler name", dosizeonly);
745
746 return totsize;
747 }
748
749 /* Output a module end trailer and return the trailer size. Just return
750 the size if DOSIZEONLY is nonzero. */
751
752 static int
753 write_modend (int dosizeonly)
754 {
755 DST_MODULE_END modend;
756 int totsize = 0;
757
758 modend.dst_a_modend_header.dst__header_length.dst_w_length
759 = DST_K_MODEND_SIZE - 1;
760 modend.dst_a_modend_header.dst__header_type.dst_w_type = DST_K_MODEND;
761
762 totsize += write_debug_header (&modend.dst_a_modend_header, "modend",
763 dosizeonly);
764
765 return totsize;
766 }
767
768 /* Output a routine begin header routine RTNNUM and return the header size.
769 Just return the size if DOSIZEONLY is nonzero. */
770
771 static int
772 write_rtnbeg (int rtnnum, int dosizeonly)
773 {
774 char *rtnname;
775 int rtnnamelen;
776 char *rtnentryname;
777 int totsize = 0;
778 char label[MAX_ARTIFICIAL_LABEL_BYTES];
779 DST_ROUTINE_BEGIN rtnbeg;
780 DST_PROLOG prolog;
781
782 rtnname = func_table[rtnnum];
783 rtnnamelen = strlen (rtnname);
784 rtnentryname = concat (rtnname, "..en", NULL);
785
786 if (!strcmp (rtnname, "main"))
787 {
788 DST_HEADER header;
789 const char *go = "TRANSFER$BREAK$GO";
790
791 /* This command isn't documented in DSTRECORDS, so it's made to
792 look like what DEC C does */
793
794 /* header size - 1st byte + flag byte + STO_LW size
795 + string count byte + string length */
796 header.dst__header_length.dst_w_length
797 = DST_K_DST_HEADER_SIZE - 1 + 1 + 4 + 1 + strlen (go);
798 header.dst__header_type.dst_w_type = 0x17;
799
800 totsize += write_debug_header (&header, "transfer", dosizeonly);
801
802 /* I think this is a flag byte, but I don't know what this flag means */
803 totsize += write_debug_data1 (0x1, "flags ???", dosizeonly);
804
805 /* Routine Begin PD Address */
806 totsize += write_debug_addr (rtnname, "main procedure descriptor",
807 dosizeonly);
808 totsize += write_debug_data1 (strlen (go), "length of main_name",
809 dosizeonly);
810 totsize += write_debug_string ((char *) go, "main name", dosizeonly);
811 }
812
813 /* The header length never includes the length byte. */
814 rtnbeg.dst_a_rtnbeg_header.dst__header_length.dst_w_length
815 = DST_K_RTNBEG_SIZE + rtnnamelen - 1;
816 rtnbeg.dst_a_rtnbeg_header.dst__header_type.dst_w_type = DST_K_RTNBEG;
817 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unused = 0;
818 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unalloc = 0;
819 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_prototype = 0;
820 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_inlined = 0;
821 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_no_call = 1;
822 rtnbeg.dst_b_rtnbeg_name = rtnnamelen;
823
824 totsize += write_debug_header (&rtnbeg.dst_a_rtnbeg_header, "rtnbeg",
825 dosizeonly);
826 totsize += write_debug_data1 (*((char *) &rtnbeg.dst_b_rtnbeg_flags),
827 "flags", dosizeonly);
828
829 /* Routine Begin Address */
830 totsize += write_debug_addr (rtnentryname, "routine entry name", dosizeonly);
831
832 /* Routine Begin PD Address */
833 totsize += write_debug_addr (rtnname, "routine procedure descriptor",
834 dosizeonly);
835
836 /* Routine Begin Name */
837 totsize += write_debug_data1 (rtnbeg.dst_b_rtnbeg_name,
838 "length of routine name", dosizeonly);
839
840 totsize += write_debug_string (rtnname, "routine name", dosizeonly);
841
842 free (rtnentryname);
843
844 if (debug_info_level > DINFO_LEVEL_TERSE)
845 {
846 prolog.dst_a_prolog_header.dst__header_length.dst_w_length
847 = DST_K_PROLOG_SIZE - 1;
848 prolog.dst_a_prolog_header.dst__header_type.dst_w_type = DST_K_PROLOG;
849
850 totsize += write_debug_header (&prolog.dst_a_prolog_header, "prolog",
851 dosizeonly);
852
853 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_PROLOG_LABEL, rtnnum);
854 totsize += write_debug_addr (label, "prolog breakpoint addr",
855 dosizeonly);
856 }
857
858 return totsize;
859 }
860
861 /* Output a routine end trailer for routine RTNNUM and return the header size.
862 Just return the size if DOSIZEONLY is nonzero. */
863
864 static int
865 write_rtnend (int rtnnum, int dosizeonly)
866 {
867 DST_ROUTINE_END rtnend;
868 char label1[MAX_ARTIFICIAL_LABEL_BYTES];
869 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
870 int totsize;
871
872 totsize = 0;
873
874 rtnend.dst_a_rtnend_header.dst__header_length.dst_w_length
875 = DST_K_RTNEND_SIZE - 1;
876 rtnend.dst_a_rtnend_header.dst__header_type.dst_w_type = DST_K_RTNEND;
877 rtnend.dst_b_rtnend_unused = 0;
878 rtnend.dst_l_rtnend_size = 0; /* Calculated below. */
879
880 totsize += write_debug_header (&rtnend.dst_a_rtnend_header, "rtnend",
881 dosizeonly);
882 totsize += write_debug_data1 (rtnend.dst_b_rtnend_unused, "unused",
883 dosizeonly);
884
885 ASM_GENERATE_INTERNAL_LABEL (label1, FUNC_BEGIN_LABEL, rtnnum);
886 ASM_GENERATE_INTERNAL_LABEL (label2, FUNC_END_LABEL, rtnnum);
887 totsize += write_debug_delta4 (label2, label1, "routine size", dosizeonly);
888
889 return totsize;
890 }
891
892 #define K_DELTA_PC(I) \
893 ((I) < 128 ? -(I) : (I) < 65536 ? DST_K_DELTA_PC_W : DST_K_DELTA_PC_L)
894
895 #define K_SET_LINUM(I) \
896 ((I) < 256 ? DST_K_SET_LINUM_B \
897 : (I) < 65536 ? DST_K_SET_LINUM : DST_K_SET_LINUM_L)
898
899 #define K_INCR_LINUM(I) \
900 ((I) < 256 ? DST_K_INCR_LINUM \
901 : (I) < 65536 ? DST_K_INCR_LINUM_W : DST_K_INCR_LINUM_L)
902
903 /* Output the PC to line number correlations and return the size. Just return
904 the size if DOSIZEONLY is nonzero */
905
906 static int
907 write_pclines (int dosizeonly)
908 {
909 unsigned i;
910 int fn;
911 int ln, lastln;
912 int linestart = 0;
913 int max_line;
914 DST_LINE_NUM_HEADER line_num;
915 DST_PCLINE_COMMANDS pcline;
916 char label[MAX_ARTIFICIAL_LABEL_BYTES];
917 char lastlabel[MAX_ARTIFICIAL_LABEL_BYTES];
918 int totsize = 0;
919 char buff[256];
920
921 max_line = file_info_table[1].max_line;
922 file_info_table[1].listing_line_start = linestart;
923 linestart = linestart + ((max_line / 100000) + 1) * 100000;
924
925 for (i = 2; i < file_info_table_in_use; i++)
926 {
927 max_line = file_info_table[i].max_line;
928 file_info_table[i].listing_line_start = linestart;
929 linestart = linestart + ((max_line / 10000) + 1) * 10000;
930 }
931
932 /* Set starting address to beginning of text section. */
933 line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 8;
934 line_num.dst_a_line_num_header.dst__header_type.dst_w_type = DST_K_LINE_NUM;
935 pcline.dst_b_pcline_command = DST_K_SET_ABS_PC;
936
937 totsize += write_debug_header (&line_num.dst_a_line_num_header,
938 "line_num", dosizeonly);
939 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
940 "line_num (SET ABS PC)", dosizeonly);
941
942 if (dosizeonly)
943 totsize += 4;
944 else
945 {
946 ASM_OUTPUT_DEBUG_ADDR (asm_out_file, TEXT_SECTION_ASM_OP);
947 if (flag_verbose_asm)
948 fprintf (asm_out_file, "\t%s line_num", ASM_COMMENT_START);
949 fputc ('\n', asm_out_file);
950 }
951
952 fn = line_info_table[1].dst_file_num;
953 ln = (file_info_table[fn].listing_line_start
954 + line_info_table[1].dst_line_num);
955 line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 4 + 4;
956 pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
957
958 totsize += write_debug_header (&line_num.dst_a_line_num_header,
959 "line_num", dosizeonly);
960 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
961 "line_num (SET LINUM LONG)", dosizeonly);
962
963 sprintf (buff, "line_num (%d)", ln ? ln - 1 : 0);
964 totsize += write_debug_data4 (ln ? ln - 1 : 0, buff, dosizeonly);
965
966 lastln = ln;
967 strcpy (lastlabel, TEXT_SECTION_ASM_OP);
968 for (i = 1; i < line_info_table_in_use; i++)
969 {
970 int extrabytes;
971
972 fn = line_info_table[i].dst_file_num;
973 ln = (file_info_table[fn].listing_line_start
974 + line_info_table[i].dst_line_num);
975
976 if (ln - lastln > 1)
977 extrabytes = 5; /* NUMBYTES (ln - lastln - 1) + 1; */
978 else if (ln <= lastln)
979 extrabytes = 5; /* NUMBYTES (ln - 1) + 1; */
980 else
981 extrabytes = 0;
982
983 line_num.dst_a_line_num_header.dst__header_length.dst_w_length
984 = 8 + extrabytes;
985
986 totsize += write_debug_header
987 (&line_num.dst_a_line_num_header, "line_num", dosizeonly);
988
989 if (ln - lastln > 1)
990 {
991 int lndif = ln - lastln - 1;
992
993 /* K_INCR_LINUM (lndif); */
994 pcline.dst_b_pcline_command = DST_K_INCR_LINUM_L;
995
996 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
997 "line_num (INCR LINUM LONG)",
998 dosizeonly);
999
1000 sprintf (buff, "line_num (%d)", lndif);
1001 totsize += write_debug_data4 (lndif, buff, dosizeonly);
1002 }
1003 else if (ln <= lastln)
1004 {
1005 /* K_SET_LINUM (ln-1); */
1006 pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
1007
1008 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
1009 "line_num (SET LINUM LONG)",
1010 dosizeonly);
1011
1012 sprintf (buff, "line_num (%d)", ln - 1);
1013 totsize += write_debug_data4 (ln - 1, buff, dosizeonly);
1014 }
1015
1016 pcline.dst_b_pcline_command = DST_K_DELTA_PC_L;
1017
1018 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
1019 "line_num (DELTA PC LONG)", dosizeonly);
1020
1021 ASM_GENERATE_INTERNAL_LABEL (label, LINE_CODE_LABEL, i);
1022 totsize += write_debug_delta4 (label, lastlabel, "increment line_num",
1023 dosizeonly);
1024
1025 lastln = ln;
1026 strcpy (lastlabel, label);
1027 }
1028
1029 return totsize;
1030 }
1031
1032 /* Output a source correlation for file FILEID using information saved in
1033 FILE_INFO_ENTRY and return the size. Just return the size if DOSIZEONLY is
1034 nonzero. */
1035
1036 static int
1037 write_srccorr (int fileid, dst_file_info_entry file_info_entry,
1038 int dosizeonly)
1039 {
1040 int src_command_size;
1041 int linesleft = file_info_entry.max_line;
1042 int linestart = file_info_entry.listing_line_start;
1043 int flen = file_info_entry.flen;
1044 int linestodo = 0;
1045 DST_SOURCE_CORR src_header;
1046 DST_SRC_COMMAND src_command;
1047 DST_SRC_COMMAND src_command_sf;
1048 DST_SRC_COMMAND src_command_sl;
1049 DST_SRC_COMMAND src_command_sr;
1050 DST_SRC_COMMAND src_command_dl;
1051 DST_SRC_CMDTRLR src_cmdtrlr;
1052 char buff[256];
1053 int totsize = 0;
1054
1055 if (fileid == 1)
1056 {
1057 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1058 = DST_K_SOURCE_CORR_HEADER_SIZE + 1 - 1;
1059 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1060 = DST_K_SOURCE;
1061 src_command.dst_b_src_command = DST_K_SRC_FORMFEED;
1062
1063 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1064 "source corr", dosizeonly);
1065
1066 totsize += write_debug_data1 (src_command.dst_b_src_command,
1067 "source_corr (SRC FORMFEED)",
1068 dosizeonly);
1069 }
1070
1071 src_command_size
1072 = DST_K_SRC_COMMAND_SIZE + flen + DST_K_SRC_CMDTRLR_SIZE;
1073 src_command.dst_b_src_command = DST_K_SRC_DECLFILE;
1074 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length
1075 = src_command_size - 2;
1076 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags = 0;
1077 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid
1078 = fileid;
1079 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt
1080 = file_info_entry.cdt;
1081 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk
1082 = file_info_entry.ebk;
1083 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb
1084 = file_info_entry.ffb;
1085 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo
1086 = file_info_entry.rfo;
1087 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename
1088 = file_info_entry.flen;
1089
1090 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1091 = DST_K_SOURCE_CORR_HEADER_SIZE + src_command_size - 1;
1092 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1093 = DST_K_SOURCE;
1094
1095 src_cmdtrlr.dst_b_src_df_libmodname = 0;
1096
1097 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1098 "source corr", dosizeonly);
1099 totsize += write_debug_data1 (src_command.dst_b_src_command,
1100 "source_corr (DECL SRC FILE)", dosizeonly);
1101 totsize += write_debug_data1
1102 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length,
1103 "source_corr (length)", dosizeonly);
1104
1105 totsize += write_debug_data1
1106 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags,
1107 "source_corr (flags)", dosizeonly);
1108
1109 totsize += write_debug_data2
1110 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid,
1111 "source_corr (fileid)", dosizeonly);
1112
1113 totsize += write_debug_data8
1114 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt,
1115 "source_corr (creation date)", dosizeonly);
1116
1117 totsize += write_debug_data4
1118 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk,
1119 "source_corr (EOF block number)", dosizeonly);
1120
1121 totsize += write_debug_data2
1122 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb,
1123 "source_corr (first free byte)", dosizeonly);
1124
1125 totsize += write_debug_data1
1126 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo,
1127 "source_corr (record and file organization)", dosizeonly);
1128
1129 totsize += write_debug_data1
1130 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename,
1131 "source_corr (filename length)", dosizeonly);
1132
1133 totsize += write_debug_string (file_info_entry.file_name,
1134 "source file name", dosizeonly);
1135 totsize += write_debug_data1 (src_cmdtrlr.dst_b_src_df_libmodname,
1136 "source_corr (libmodname)", dosizeonly);
1137
1138 src_command_sf.dst_b_src_command = DST_K_SRC_SETFILE;
1139 src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword = fileid;
1140
1141 src_command_sr.dst_b_src_command = DST_K_SRC_SETREC_W;
1142 src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword = 1;
1143
1144 src_command_sl.dst_b_src_command = DST_K_SRC_SETLNUM_L;
1145 src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong = linestart + 1;
1146
1147 src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1148
1149 if (linesleft > 65534)
1150 linesleft = linesleft - 65534, linestodo = 65534;
1151 else
1152 linestodo = linesleft, linesleft = 0;
1153
1154 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1155
1156 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1157 = DST_K_SOURCE_CORR_HEADER_SIZE + 3 + 3 + 5 + 3 - 1;
1158 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1159 = DST_K_SOURCE;
1160
1161 if (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword)
1162 {
1163 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1164 "source corr", dosizeonly);
1165
1166 totsize += write_debug_data1 (src_command_sf.dst_b_src_command,
1167 "source_corr (src setfile)", dosizeonly);
1168
1169 totsize += write_debug_data2
1170 (src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword,
1171 "source_corr (fileid)", dosizeonly);
1172
1173 totsize += write_debug_data1 (src_command_sr.dst_b_src_command,
1174 "source_corr (setrec)", dosizeonly);
1175
1176 totsize += write_debug_data2
1177 (src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword,
1178 "source_corr (recnum)", dosizeonly);
1179
1180 totsize += write_debug_data1 (src_command_sl.dst_b_src_command,
1181 "source_corr (setlnum)", dosizeonly);
1182
1183 totsize += write_debug_data4
1184 (src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong,
1185 "source_corr (linenum)", dosizeonly);
1186
1187 totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1188 "source_corr (deflines)", dosizeonly);
1189
1190 sprintf (buff, "source_corr (%d)",
1191 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1192 totsize += write_debug_data2
1193 (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
1194 buff, dosizeonly);
1195
1196 while (linesleft > 0)
1197 {
1198 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1199 = DST_K_SOURCE_CORR_HEADER_SIZE + 3 - 1;
1200 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1201 = DST_K_SOURCE;
1202 src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1203
1204 if (linesleft > 65534)
1205 linesleft = linesleft - 65534, linestodo = 65534;
1206 else
1207 linestodo = linesleft, linesleft = 0;
1208
1209 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1210
1211 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1212 "source corr", dosizeonly);
1213 totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1214 "source_corr (deflines)", dosizeonly);
1215 sprintf (buff, "source_corr (%d)",
1216 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1217 totsize += write_debug_data2
1218 (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
1219 buff, dosizeonly);
1220 }
1221 }
1222
1223 return totsize;
1224 }
1225
1226 /* Output all the source correlation entries and return the size. Just return
1227 the size if DOSIZEONLY is nonzero. */
1228
1229 static int
1230 write_srccorrs (int dosizeonly)
1231 {
1232 unsigned int i;
1233 int totsize = 0;
1234
1235 for (i = 1; i < file_info_table_in_use; i++)
1236 totsize += write_srccorr (i, file_info_table[i], dosizeonly);
1237
1238 return totsize;
1239 }
1240 \f
1241 /* Output a marker (i.e. a label) for the beginning of a function, before
1242 the prologue. */
1243
1244 static void
1245 vmsdbgout_begin_prologue (unsigned int line, const char *file)
1246 {
1247 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1248
1249 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1250 (*dwarf2_debug_hooks.begin_prologue) (line, file);
1251
1252 if (debug_info_level > DINFO_LEVEL_NONE)
1253 {
1254 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1255 current_function_funcdef_no);
1256 ASM_OUTPUT_LABEL (asm_out_file, label);
1257 }
1258 }
1259
1260 /* Output a marker (i.e. a label) for the beginning of a function, after
1261 the prologue. */
1262
1263 static void
1264 vmsdbgout_end_prologue (unsigned int line, const char *file)
1265 {
1266 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1267
1268 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1269 (*dwarf2_debug_hooks.end_prologue) (line, file);
1270
1271 if (debug_info_level > DINFO_LEVEL_TERSE)
1272 {
1273 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_PROLOG_LABEL,
1274 current_function_funcdef_no);
1275 ASM_OUTPUT_LABEL (asm_out_file, label);
1276
1277 /* VMS PCA expects every PC range to correlate to some line and file. */
1278 vmsdbgout_source_line (line, file);
1279 }
1280 }
1281
1282 /* No output for VMS debug, but make obligatory call to Dwarf2 debug */
1283
1284 static void
1285 vmsdbgout_end_function (unsigned int line)
1286 {
1287 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1288 (*dwarf2_debug_hooks.end_function) (line);
1289 }
1290
1291 /* Output a marker (i.e. a label) for the absolute end of the generated code
1292 for a function definition. This gets called *after* the epilogue code has
1293 been generated. */
1294
1295 static void
1296 vmsdbgout_end_epilogue (unsigned int line, const char *file)
1297 {
1298 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1299
1300 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1301 (*dwarf2_debug_hooks.end_epilogue) (line, file);
1302
1303 if (debug_info_level > DINFO_LEVEL_NONE)
1304 {
1305 /* Output a label to mark the endpoint of the code generated for this
1306 function. */
1307 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1308 current_function_funcdef_no);
1309 ASM_OUTPUT_LABEL (asm_out_file, label);
1310
1311 /* VMS PCA expects every PC range to correlate to some line and file. */
1312 vmsdbgout_source_line (line, file);
1313 }
1314 }
1315
1316 /* Output a marker (i.e. a label) for the beginning of the generated code for
1317 a lexical block. */
1318
1319 static void
1320 vmsdbgout_begin_block (register unsigned line, register unsigned blocknum)
1321 {
1322 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1323 (*dwarf2_debug_hooks.begin_block) (line, blocknum);
1324
1325 if (debug_info_level > DINFO_LEVEL_TERSE)
1326 (*targetm.asm_out.internal_label) (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
1327 }
1328
1329 /* Output a marker (i.e. a label) for the end of the generated code for a
1330 lexical block. */
1331
1332 static void
1333 vmsdbgout_end_block (register unsigned line, register unsigned blocknum)
1334 {
1335 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1336 (*dwarf2_debug_hooks.end_block) (line, blocknum);
1337
1338 if (debug_info_level > DINFO_LEVEL_TERSE)
1339 (*targetm.asm_out.internal_label) (asm_out_file, BLOCK_END_LABEL, blocknum);
1340 }
1341
1342 /* Not implemented in VMS Debug. */
1343
1344 static bool
1345 vmsdbgout_ignore_block (tree block)
1346 {
1347 bool retval = 0;
1348
1349 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1350 retval = (*dwarf2_debug_hooks.ignore_block) (block);
1351
1352 return retval;
1353 }
1354
1355 /* Add an entry for function DECL into the func_table. */
1356
1357 static void
1358 vmsdbgout_begin_function (tree decl)
1359 {
1360 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1361
1362 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1363 (*dwarf2_debug_hooks.begin_function) (decl);
1364
1365 if (func_table_in_use == func_table_allocated)
1366 {
1367 func_table_allocated += FUNC_TABLE_INCREMENT;
1368 func_table = xrealloc (func_table,
1369 func_table_allocated * sizeof (char *));
1370 }
1371
1372 /* Add the new entry to the end of the function name table. */
1373 func_table[func_table_in_use++] = xstrdup (name);
1374 }
1375
1376 static char fullname_buff [4096];
1377
1378 /* Return the full file specification for FILENAME. The specification must be
1379 in VMS syntax in order to be processed by VMS Debug. */
1380
1381 static char *
1382 full_name (const char *filename)
1383 {
1384 #ifdef VMS
1385 FILE *fp = fopen (filename, "r");
1386
1387 fgetname (fp, fullname_buff, 1);
1388 fclose (fp);
1389 #else
1390 getcwd (fullname_buff, sizeof (fullname_buff));
1391
1392 strcat (fullname_buff, "/");
1393 strcat (fullname_buff, filename);
1394
1395 /* ??? Insert hairy code here to translate Unix style file specification
1396 to VMS style. */
1397 #endif
1398
1399 return fullname_buff;
1400 }
1401
1402 /* Lookup a filename (in the list of filenames that we know about here in
1403 vmsdbgout.c) and return its "index". The index of each (known) filename is
1404 just a unique number which is associated with only that one filename. We
1405 need such numbers for the sake of generating labels and references
1406 to those files numbers. If the filename given as an argument is not
1407 found in our current list, add it to the list and assign it the next
1408 available unique index number. In order to speed up searches, we remember
1409 the index of the filename was looked up last. This handles the majority of
1410 all searches. */
1411
1412 static unsigned int
1413 lookup_filename (const char *file_name)
1414 {
1415 static unsigned int last_file_lookup_index = 0;
1416 register char *fn;
1417 register unsigned i;
1418 char *fnam;
1419 long long cdt;
1420 long ebk;
1421 short ffb;
1422 char rfo;
1423 char flen;
1424 struct stat statbuf;
1425
1426 if (stat (file_name, &statbuf) == 0)
1427 {
1428 long gmtoff;
1429 #ifdef VMS
1430 struct tm *ts;
1431
1432 /* Adjust for GMT. */
1433 ts = (struct tm *) localtime (&statbuf.st_ctime);
1434 gmtoff = ts->tm_gmtoff;
1435
1436 /* VMS has multiple file format types. */
1437 rfo = statbuf.st_fab_rfm;
1438 #else
1439 /* Is GMT adjustment an issue with a cross-compiler? */
1440 gmtoff = 0;
1441
1442 /* Assume stream LF type file. */
1443 rfo = 2;
1444 #endif
1445 cdt = 10000000 * (statbuf.st_ctime + gmtoff + vms_epoch_offset);
1446 ebk = statbuf.st_size / 512 + 1;
1447 ffb = statbuf.st_size - ((statbuf.st_size / 512) * 512);
1448 fnam = full_name (file_name);
1449 flen = strlen (fnam);
1450 }
1451 else
1452 {
1453 cdt = 0;
1454 ebk = 0;
1455 ffb = 0;
1456 rfo = 0;
1457 fnam = (char *) "";
1458 flen = 0;
1459 }
1460
1461 /* Check to see if the file name that was searched on the previous call
1462 matches this file name. If so, return the index. */
1463 if (last_file_lookup_index != 0)
1464 {
1465 fn = file_info_table[last_file_lookup_index].file_name;
1466 if (strcmp (fnam, fn) == 0)
1467 return last_file_lookup_index;
1468 }
1469
1470 /* Didn't match the previous lookup, search the table */
1471 for (i = 1; i < file_info_table_in_use; ++i)
1472 {
1473 fn = file_info_table[i].file_name;
1474 if (strcmp (fnam, fn) == 0)
1475 {
1476 last_file_lookup_index = i;
1477 return i;
1478 }
1479 }
1480
1481 /* Prepare to add a new table entry by making sure there is enough space in
1482 the table to do so. If not, expand the current table. */
1483 if (file_info_table_in_use == file_info_table_allocated)
1484 {
1485
1486 file_info_table_allocated += FILE_TABLE_INCREMENT;
1487 file_info_table = xrealloc (file_info_table,
1488 (file_info_table_allocated
1489 * sizeof (dst_file_info_entry)));
1490 }
1491
1492 /* Add the new entry to the end of the filename table. */
1493 file_info_table[file_info_table_in_use].file_name = xstrdup (fnam);
1494 file_info_table[file_info_table_in_use].max_line = 0;
1495 file_info_table[file_info_table_in_use].cdt = cdt;
1496 file_info_table[file_info_table_in_use].ebk = ebk;
1497 file_info_table[file_info_table_in_use].ffb = ffb;
1498 file_info_table[file_info_table_in_use].rfo = rfo;
1499 file_info_table[file_info_table_in_use].flen = flen;
1500
1501 last_file_lookup_index = file_info_table_in_use++;
1502 return last_file_lookup_index;
1503 }
1504
1505 /* Output a label to mark the beginning of a source code line entry
1506 and record information relating to this source line, in
1507 'line_info_table' for later output of the .debug_line section. */
1508
1509 static void
1510 vmsdbgout_source_line (register unsigned line, register const char *filename)
1511 {
1512 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1513 (*dwarf2_debug_hooks.source_line) (line, filename);
1514
1515 if (debug_info_level >= DINFO_LEVEL_TERSE)
1516 {
1517 dst_line_info_ref line_info;
1518
1519 (*targetm.asm_out.internal_label) (asm_out_file, LINE_CODE_LABEL,
1520 line_info_table_in_use);
1521
1522 /* Expand the line info table if necessary. */
1523 if (line_info_table_in_use == line_info_table_allocated)
1524 {
1525 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
1526 line_info_table = xrealloc (line_info_table,
1527 (line_info_table_allocated
1528 * sizeof (dst_line_info_entry)));
1529 }
1530
1531 /* Add the new entry at the end of the line_info_table. */
1532 line_info = &line_info_table[line_info_table_in_use++];
1533 line_info->dst_file_num = lookup_filename (filename);
1534 line_info->dst_line_num = line;
1535 if (line > file_info_table[line_info->dst_file_num].max_line)
1536 file_info_table[line_info->dst_file_num].max_line = line;
1537 }
1538 }
1539
1540 /* Record the beginning of a new source file, for later output.
1541 At present, unimplemented. */
1542
1543 static void
1544 vmsdbgout_start_source_file (unsigned int lineno, const char *filename)
1545 {
1546 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1547 (*dwarf2_debug_hooks.start_source_file) (lineno, filename);
1548 }
1549
1550 /* Record the end of a source file, for later output.
1551 At present, unimplemented. */
1552
1553 static void
1554 vmsdbgout_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
1555 {
1556 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1557 (*dwarf2_debug_hooks.end_source_file) (lineno);
1558 }
1559
1560 /* Set up for Debug output at the start of compilation. */
1561
1562 static void
1563 vmsdbgout_init (const char *main_input_filename)
1564 {
1565 const char *language_string = lang_hooks.name;
1566
1567 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1568 (*dwarf2_debug_hooks.init) (main_input_filename);
1569
1570 if (debug_info_level == DINFO_LEVEL_NONE)
1571 return;
1572
1573 /* Remember the name of the primary input file. */
1574 primary_filename = main_input_filename;
1575
1576 /* Allocate the initial hunk of the file_info_table. */
1577 file_info_table
1578 = xcalloc (FILE_TABLE_INCREMENT, sizeof (dst_file_info_entry));
1579 file_info_table_allocated = FILE_TABLE_INCREMENT;
1580
1581 /* Skip the first entry - file numbers begin at 1 */
1582 file_info_table_in_use = 1;
1583
1584 func_table = xcalloc (FUNC_TABLE_INCREMENT, sizeof (char *));
1585 func_table_allocated = FUNC_TABLE_INCREMENT;
1586 func_table_in_use = 1;
1587
1588 /* Allocate the initial hunk of the line_info_table. */
1589 line_info_table
1590 = xcalloc (LINE_INFO_TABLE_INCREMENT, sizeof (dst_line_info_entry));
1591 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
1592 /* zero-th entry is allocated, but unused */
1593 line_info_table_in_use = 1;
1594
1595 lookup_filename (primary_filename);
1596
1597 if (!strcmp (language_string, "GNU C"))
1598 module_language = DST_K_C;
1599 else if (!strcmp (language_string, "GNU C++"))
1600 module_language = DST_K_CXX;
1601 else if (!strcmp (language_string, "GNU Ada"))
1602 module_language = DST_K_ADA;
1603 else if (!strcmp (language_string, "GNU F77"))
1604 module_language = DST_K_FORTRAN;
1605 else
1606 module_language = DST_K_UNKNOWN;
1607
1608 module_producer = concat (language_string, " ", version_string, NULL);
1609
1610 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
1611
1612 }
1613
1614 /* Not implemented in VMS Debug. */
1615
1616 static void
1617 vmsdbgout_define (unsigned int lineno, const char *buffer)
1618 {
1619 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1620 (*dwarf2_debug_hooks.define) (lineno, buffer);
1621 }
1622
1623 /* Not implemented in VMS Debug. */
1624
1625 static void
1626 vmsdbgout_undef (unsigned int lineno, const char *buffer)
1627 {
1628 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1629 (*dwarf2_debug_hooks.undef) (lineno, buffer);
1630 }
1631
1632 /* Not implemented in VMS Debug. */
1633
1634 static void
1635 vmsdbgout_decl (tree decl)
1636 {
1637 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1638 (*dwarf2_debug_hooks.function_decl) (decl);
1639 }
1640
1641 /* Not implemented in VMS Debug. */
1642
1643 static void
1644 vmsdbgout_global_decl (tree decl)
1645 {
1646 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1647 (*dwarf2_debug_hooks.global_decl) (decl);
1648 }
1649
1650 /* Not implemented in VMS Debug. */
1651
1652 static void
1653 vmsdbgout_abstract_function (tree decl)
1654 {
1655 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1656 (*dwarf2_debug_hooks.outlining_inline_function) (decl);
1657 }
1658
1659 /* Output stuff that Debug requires at the end of every file and generate the
1660 VMS Debug debugging info. */
1661
1662 static void
1663 vmsdbgout_finish (const char *main_input_filename ATTRIBUTE_UNUSED)
1664 {
1665 unsigned int i;
1666 int totsize;
1667
1668 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1669 (*dwarf2_debug_hooks.finish) (main_input_filename);
1670
1671 if (debug_info_level == DINFO_LEVEL_NONE)
1672 return;
1673
1674 /* Output a terminator label for the .text section. */
1675 text_section ();
1676 (*targetm.asm_out.internal_label) (asm_out_file, TEXT_END_LABEL, 0);
1677
1678 /* Output debugging information.
1679 Warning! Do not change the name of the .vmsdebug section without
1680 changing it in the assembler also. */
1681 named_section (NULL_TREE, ".vmsdebug", 0);
1682 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1683
1684 totsize = write_modbeg (1);
1685 for (i = 1; i < func_table_in_use; i++)
1686 {
1687 totsize += write_rtnbeg (i, 1);
1688 totsize += write_rtnend (i, 1);
1689 }
1690 totsize += write_pclines (1);
1691
1692 write_modbeg (0);
1693 for (i = 1; i < func_table_in_use; i++)
1694 {
1695 write_rtnbeg (i, 0);
1696 write_rtnend (i, 0);
1697 }
1698 write_pclines (0);
1699
1700 if (debug_info_level > DINFO_LEVEL_TERSE)
1701 {
1702 totsize = write_srccorrs (1);
1703 write_srccorrs (0);
1704 }
1705
1706 totsize = write_modend (1);
1707 write_modend (0);
1708 }
1709 #endif /* VMS_DEBUGGING_INFO */