This was approved for 3.4 BIB branch. But since it is dead now, I am putting
[official-gcc.git] / gcc / vmsdbgout.c
blob278d16b6458d304f1cf64eaab76e48fad24c3fe8
1 /* Output VMS debug format symbol table information from the GNU C compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 Contributed by Douglas B. Rupp (rupp@gnat.com).
6 This file is part of GNU CC.
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.
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.
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. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
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"
39 /* Difference in seconds between the VMS Epoch and the Unix Epoch */
40 static const long long vms_epoch_offset = 3506716800ll;
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. */
46 typedef struct dst_line_info_struct *dst_line_info_ref;
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
54 unsigned long dst_file_num;
55 unsigned long dst_line_num;
57 dst_line_info_entry;
59 typedef struct dst_file_info_struct *dst_file_info_ref;
61 typedef struct dst_file_info_struct
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;
72 dst_file_info_entry;
74 /* How to start an assembler comment. */
75 #ifndef ASM_COMMENT_START
76 #define ASM_COMMENT_START ";#"
77 #endif
79 /* Maximum size (in bytes) of an artificially generated label. */
80 #define MAX_ARTIFICIAL_LABEL_BYTES 30
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
90 /* Pointer to a structure of filenames referenced by this compilation unit. */
91 static dst_file_info_ref file_info_table;
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;
98 /* Number of entries in the file_info_table which are actually in use. */
99 static unsigned int file_info_table_in_use;
101 /* Size (in elements) of increments by which we may expand the filename
102 table. */
103 #define FILE_TABLE_INCREMENT 64
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
110 /* Local pointer to the name of the main input file. Initialized in
111 avmdbgout_init. */
112 static const char *primary_filename;
114 static char *module_producer;
115 static unsigned int module_language;
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;
121 /* Number of elements currently allocated for line_info_table. */
122 static unsigned int line_info_table_allocated;
124 /* Number of elements in line_info_table currently in use. */
125 static unsigned int line_info_table_in_use;
127 /* Size (in elements) of increments by which we may expand line_info_table. */
128 #define LINE_INFO_TABLE_INCREMENT 1024
130 /* Forward declarations for functions defined in this file. */
131 static char *full_name PARAMS ((const char *));
132 static unsigned int lookup_filename PARAMS ((const char *));
133 static void addr_const_to_string PARAMS ((char *, rtx));
134 static int write_debug_header PARAMS ((DST_HEADER *, const char *, int));
135 static int write_debug_addr PARAMS ((char *, const char *, int));
136 static int write_debug_data1 PARAMS ((unsigned int, const char *, int));
137 static int write_debug_data2 PARAMS ((unsigned int, const char *, int));
138 static int write_debug_data4 PARAMS ((unsigned long, const char *, int));
139 static int write_debug_data8 PARAMS ((unsigned long long, const char *,
140 int));
141 static int write_debug_delta4 PARAMS ((char *, char *, const char *, int));
142 static int write_debug_string PARAMS ((char *, const char *, int));
143 static int write_modbeg PARAMS ((int));
144 static int write_modend PARAMS ((int));
145 static int write_rtnbeg PARAMS ((int, int));
146 static int write_rtnend PARAMS ((int, int));
147 static int write_pclines PARAMS ((int));
148 static int write_srccorr PARAMS ((int, dst_file_info_entry, int));
149 static int write_srccorrs PARAMS ((int));
151 static void vmsdbgout_init PARAMS ((const char *));
152 static void vmsdbgout_finish PARAMS ((const char *));
153 static void vmsdbgout_define PARAMS ((unsigned int, const char *));
154 static void vmsdbgout_undef PARAMS ((unsigned int, const char *));
155 static void vmsdbgout_start_source_file PARAMS ((unsigned int, const char *));
156 static void vmsdbgout_end_source_file PARAMS ((unsigned int));
157 static void vmsdbgout_begin_block PARAMS ((unsigned int, unsigned int));
158 static void vmsdbgout_end_block PARAMS ((unsigned int, unsigned int));
159 static bool vmsdbgout_ignore_block PARAMS ((tree));
160 static void vmsdbgout_source_line PARAMS ((unsigned int, const char *));
161 static void vmsdbgout_begin_prologue PARAMS ((unsigned int, const char *));
162 static void vmsdbgout_end_prologue PARAMS ((unsigned int, const char *));
163 static void vmsdbgout_end_function PARAMS ((unsigned int));
164 static void vmsdbgout_end_epilogue PARAMS ((unsigned int, const char *));
165 static void vmsdbgout_begin_function PARAMS ((tree));
166 static void vmsdbgout_decl PARAMS ((tree));
167 static void vmsdbgout_global_decl PARAMS ((tree));
168 static void vmsdbgout_abstract_function PARAMS ((tree));
170 /* The debug hooks structure. */
172 const struct gcc_debug_hooks vmsdbg_debug_hooks
173 = {vmsdbgout_init,
174 vmsdbgout_finish,
175 vmsdbgout_define,
176 vmsdbgout_undef,
177 vmsdbgout_start_source_file,
178 vmsdbgout_end_source_file,
179 vmsdbgout_begin_block,
180 vmsdbgout_end_block,
181 vmsdbgout_ignore_block,
182 vmsdbgout_source_line,
183 vmsdbgout_begin_prologue,
184 vmsdbgout_end_prologue,
185 vmsdbgout_end_epilogue,
186 vmsdbgout_begin_function,
187 vmsdbgout_end_function,
188 vmsdbgout_decl,
189 vmsdbgout_global_decl,
190 debug_nothing_tree, /* deferred_inline_function */
191 vmsdbgout_abstract_function,
192 debug_nothing_rtx /* label */
195 /* Definitions of defaults for assembler-dependent names of various
196 pseudo-ops and section names.
197 Theses may be overridden in the tm.h file (if necessary) for a particular
198 assembler. */
199 #ifdef UNALIGNED_SHORT_ASM_OP
200 #undef UNALIGNED_SHORT_ASM_OP
201 #endif
202 #define UNALIGNED_SHORT_ASM_OP ".word"
204 #ifdef UNALIGNED_INT_ASM_OP
205 #undef UNALIGNED_INT_ASM_OP
206 #endif
207 #define UNALIGNED_INT_ASM_OP ".long"
209 #ifdef UNALIGNED_LONG_ASM_OP
210 #undef UNALIGNED_LONG_ASM_OP
211 #endif
212 #define UNALIGNED_LONG_ASM_OP ".long"
214 #ifdef UNALIGNED_DOUBLE_INT_ASM_OP
215 #undef UNALIGNED_DOUBLE_INT_ASM_OP
216 #endif
217 #define UNALIGNED_DOUBLE_INT_ASM_OP ".quad"
219 #ifdef ASM_BYTE_OP
220 #undef ASM_BYTE_OP
221 #endif
222 #define ASM_BYTE_OP ".byte"
224 #define NUMBYTES(I) ((I) < 256 ? 1 : (I) < 65536 ? 2 : 4)
226 #define NUMBYTES0(I) ((I) < 128 ? 0 : (I) < 65536 ? 2 : 4)
228 #ifndef UNALIGNED_PTR_ASM_OP
229 #define UNALIGNED_PTR_ASM_OP \
230 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
231 #endif
233 #ifndef UNALIGNED_OFFSET_ASM_OP
234 #define UNALIGNED_OFFSET_ASM_OP(OFFSET) \
235 (NUMBYTES(OFFSET) == 4 \
236 ? UNALIGNED_LONG_ASM_OP \
237 : (NUMBYTES(OFFSET) == 2 ? UNALIGNED_SHORT_ASM_OP : ASM_BYTE_OP))
238 #endif
240 /* Definitions of defaults for formats and names of various special
241 (artificial) labels which may be generated within this file (when the -g
242 options is used and VMS_DEBUGGING_INFO is in effect. If necessary, these
243 may be overridden from within the tm.h file, but typically, overriding these
244 defaults is unnecessary. */
246 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
248 #ifndef TEXT_END_LABEL
249 #define TEXT_END_LABEL "Lvetext"
250 #endif
251 #ifndef FUNC_BEGIN_LABEL
252 #define FUNC_BEGIN_LABEL "LVFB"
253 #endif
254 #ifndef FUNC_PROLOG_LABEL
255 #define FUNC_PROLOG_LABEL "LVFP"
256 #endif
257 #ifndef FUNC_END_LABEL
258 #define FUNC_END_LABEL "LVFE"
259 #endif
260 #ifndef BLOCK_BEGIN_LABEL
261 #define BLOCK_BEGIN_LABEL "LVBB"
262 #endif
263 #ifndef BLOCK_END_LABEL
264 #define BLOCK_END_LABEL "LVBE"
265 #endif
266 #ifndef LINE_CODE_LABEL
267 #define LINE_CODE_LABEL "LVM"
268 #endif
270 #ifndef ASM_OUTPUT_DEBUG_DELTA2
271 #define ASM_OUTPUT_DEBUG_DELTA2(FILE,LABEL1,LABEL2) \
272 do \
274 fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
275 assemble_name (FILE, LABEL1); \
276 fprintf (FILE, "-"); \
277 assemble_name (FILE, LABEL2); \
279 while (0)
280 #endif
282 #ifndef ASM_OUTPUT_DEBUG_DELTA4
283 #define ASM_OUTPUT_DEBUG_DELTA4(FILE,LABEL1,LABEL2) \
284 do \
286 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
287 assemble_name (FILE, LABEL1); \
288 fprintf (FILE, "-"); \
289 assemble_name (FILE, LABEL2); \
291 while (0)
292 #endif
294 #ifndef ASM_OUTPUT_DEBUG_ADDR_DELTA
295 #define ASM_OUTPUT_DEBUG_ADDR_DELTA(FILE,LABEL1,LABEL2) \
296 do \
298 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
299 assemble_name (FILE, LABEL1); \
300 fprintf (FILE, "-"); \
301 assemble_name (FILE, LABEL2); \
303 while (0)
304 #endif
306 #ifndef ASM_OUTPUT_DEBUG_ADDR
307 #define ASM_OUTPUT_DEBUG_ADDR(FILE,LABEL) \
308 do \
310 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
311 assemble_name (FILE, LABEL); \
313 while (0)
314 #endif
316 #ifndef ASM_OUTPUT_DEBUG_ADDR_CONST
317 #define ASM_OUTPUT_DEBUG_ADDR_CONST(FILE,ADDR) \
318 fprintf ((FILE), "\t%s\t%s", UNALIGNED_PTR_ASM_OP, (ADDR))
319 #endif
321 #ifndef ASM_OUTPUT_DEBUG_DATA1
322 #define ASM_OUTPUT_DEBUG_DATA1(FILE,VALUE) \
323 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned char) VALUE)
324 #endif
326 #ifndef ASM_OUTPUT_DEBUG_DATA2
327 #define ASM_OUTPUT_DEBUG_DATA2(FILE,VALUE) \
328 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, \
329 (unsigned short) VALUE)
330 #endif
332 #ifndef ASM_OUTPUT_DEBUG_DATA4
333 #define ASM_OUTPUT_DEBUG_DATA4(FILE,VALUE) \
334 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (unsigned long) VALUE)
335 #endif
337 #ifndef ASM_OUTPUT_DEBUG_DATA
338 #define ASM_OUTPUT_DEBUG_DATA(FILE,VALUE) \
339 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP(VALUE), VALUE)
340 #endif
342 #ifndef ASM_OUTPUT_DEBUG_ADDR_DATA
343 #define ASM_OUTPUT_DEBUG_ADDR_DATA(FILE,VALUE) \
344 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_PTR_ASM_OP, \
345 (unsigned long) VALUE)
346 #endif
348 #ifndef ASM_OUTPUT_DEBUG_DATA8
349 #define ASM_OUTPUT_DEBUG_DATA8(FILE,VALUE) \
350 fprintf ((FILE), "\t%s\t0x%llx", UNALIGNED_DOUBLE_INT_ASM_OP, \
351 (unsigned long long) VALUE)
352 #endif
354 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
355 newline is produced. When flag_verbose_asm is asserted, we add commnetary
356 at the end of the line, so we must avoid output of a newline here. */
357 #ifndef ASM_OUTPUT_DEBUG_STRING
358 #define ASM_OUTPUT_DEBUG_STRING(FILE,P) \
359 do \
361 register int slen = strlen(P); \
362 register char *p = (P); \
363 register int i; \
364 fprintf (FILE, "\t.ascii \""); \
365 for (i = 0; i < slen; i++) \
367 register int c = p[i]; \
368 if (c == '\"' || c == '\\') \
369 putc ('\\', FILE); \
370 if (c >= ' ' && c < 0177) \
371 putc (c, FILE); \
372 else \
373 fprintf (FILE, "\\%o", c); \
375 fprintf (FILE, "\""); \
377 while (0)
378 #endif
380 /* Convert a reference to the assembler name of a C-level name. This
381 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
382 a string rather than writing to a file. */
383 #ifndef ASM_NAME_TO_STRING
384 #define ASM_NAME_TO_STRING(STR, NAME) \
385 do \
387 if ((NAME)[0] == '*') \
388 strcpy (STR, NAME+1); \
389 else \
390 strcpy (STR, NAME); \
392 while (0)
393 #endif
396 /* General utility functions. */
398 /* Convert an integer constant expression into assembler syntax. Addition and
399 subtraction are the only arithmetic that may appear in these expressions.
400 This is an adaptation of output_addr_const in final.c. Here, the target
401 of the conversion is a string buffer. We can't use output_addr_const
402 directly, because it writes to a file. */
404 static void
405 addr_const_to_string (str, x)
406 char *str;
407 rtx x;
409 char buf1[256];
410 char buf2[256];
412 restart:
413 str[0] = '\0';
414 switch (GET_CODE (x))
416 case PC:
417 if (flag_pic)
418 strcat (str, ",");
419 else
420 abort ();
421 break;
423 case SYMBOL_REF:
424 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
425 strcat (str, buf1);
426 break;
428 case LABEL_REF:
429 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
430 ASM_NAME_TO_STRING (buf2, buf1);
431 strcat (str, buf2);
432 break;
434 case CODE_LABEL:
435 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
436 ASM_NAME_TO_STRING (buf2, buf1);
437 strcat (str, buf2);
438 break;
440 case CONST_INT:
441 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
442 strcat (str, buf1);
443 break;
445 case CONST:
446 /* This used to output parentheses around the expression, but that does
447 not work on the 386 (either ATT or BSD assembler). */
448 addr_const_to_string (buf1, XEXP (x, 0));
449 strcat (str, buf1);
450 break;
452 case CONST_DOUBLE:
453 if (GET_MODE (x) == VOIDmode)
455 /* We can use %d if the number is one word and positive. */
456 if (CONST_DOUBLE_HIGH (x))
457 sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
458 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
459 else if (CONST_DOUBLE_LOW (x) < 0)
460 sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
461 else
462 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
463 CONST_DOUBLE_LOW (x));
464 strcat (str, buf1);
466 else
467 /* We can't handle floating point constants; PRINT_OPERAND must
468 handle them. */
469 output_operand_lossage ("floating constant misused");
470 break;
472 case PLUS:
473 /* Some assemblers need integer constants to appear last (eg masm). */
474 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
476 addr_const_to_string (buf1, XEXP (x, 1));
477 strcat (str, buf1);
478 if (INTVAL (XEXP (x, 0)) >= 0)
479 strcat (str, "+");
480 addr_const_to_string (buf1, XEXP (x, 0));
481 strcat (str, buf1);
483 else
485 addr_const_to_string (buf1, XEXP (x, 0));
486 strcat (str, buf1);
487 if (INTVAL (XEXP (x, 1)) >= 0)
488 strcat (str, "+");
489 addr_const_to_string (buf1, XEXP (x, 1));
490 strcat (str, buf1);
492 break;
494 case MINUS:
495 /* Avoid outputting things like x-x or x+5-x, since some assemblers
496 can't handle that. */
497 x = simplify_subtraction (x);
498 if (GET_CODE (x) != MINUS)
499 goto restart;
501 addr_const_to_string (buf1, XEXP (x, 0));
502 strcat (str, buf1);
503 strcat (str, "-");
504 if (GET_CODE (XEXP (x, 1)) == CONST_INT
505 && INTVAL (XEXP (x, 1)) < 0)
507 strcat (str, "(");
508 addr_const_to_string (buf1, XEXP (x, 1));
509 strcat (str, buf1);
510 strcat (str, ")");
512 else
514 addr_const_to_string (buf1, XEXP (x, 1));
515 strcat (str, buf1);
517 break;
519 case ZERO_EXTEND:
520 case SIGN_EXTEND:
521 addr_const_to_string (buf1, XEXP (x, 0));
522 strcat (str, buf1);
523 break;
525 default:
526 output_operand_lossage ("invalid expression as operand");
530 /* Output the debug header HEADER. Also output COMMENT if flag_verbose_asm is
531 set. Return the header size. Just return the size if DOSIZEONLY is
532 nonzero. */
534 static int
535 write_debug_header (header, comment, dosizeonly)
536 DST_HEADER *header;
537 const char *comment;
538 int dosizeonly;
540 if (!dosizeonly)
542 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
543 header->dst__header_length.dst_w_length);
545 if (flag_verbose_asm)
546 fprintf (asm_out_file, "\t%s record length", ASM_COMMENT_START);
547 fputc ('\n', asm_out_file);
549 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
550 header->dst__header_type.dst_w_type);
552 if (flag_verbose_asm)
553 fprintf (asm_out_file, "\t%s record type (%s)", ASM_COMMENT_START,
554 comment);
556 fputc ('\n', asm_out_file);
559 return 4;
562 /* Output the address of SYMBOL. Also output COMMENT if flag_verbose_asm is
563 set. Return the address size. Just return the size if DOSIZEONLY is
564 nonzero. */
566 static int
567 write_debug_addr (symbol, comment, dosizeonly)
568 char *symbol;
569 const char *comment;
570 int dosizeonly;
572 if (!dosizeonly)
574 ASM_OUTPUT_DEBUG_ADDR (asm_out_file, symbol);
575 if (flag_verbose_asm)
576 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
577 fputc ('\n', asm_out_file);
580 return PTR_SIZE;
583 /* Output the single byte DATA1. Also output COMMENT if flag_verbose_asm is
584 set. Return the data size. Just return the size if DOSIZEONLY is
585 nonzero. */
587 static int
588 write_debug_data1 (data1, comment, dosizeonly)
589 unsigned int data1;
590 const char *comment;
591 int dosizeonly;
593 if (!dosizeonly)
595 ASM_OUTPUT_DEBUG_DATA1 (asm_out_file, data1);
596 if (flag_verbose_asm)
597 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
598 fputc ('\n', asm_out_file);
601 return 1;
604 /* Output the single word DATA2. Also output COMMENT if flag_verbose_asm is
605 set. Return the data size. Just return the size if DOSIZEONLY is
606 nonzero. */
608 static int
609 write_debug_data2 (data2, comment, dosizeonly)
610 unsigned int data2;
611 const char *comment;
612 int dosizeonly;
614 if (!dosizeonly)
616 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file, data2);
617 if (flag_verbose_asm)
618 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
619 fputc ('\n', asm_out_file);
622 return 2;
625 /* Output double word DATA4. Also output COMMENT if flag_verbose_asm is set.
626 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
628 static int
629 write_debug_data4 (data4, comment, dosizeonly)
630 unsigned long data4;
631 const char *comment;
632 int dosizeonly;
634 if (!dosizeonly)
636 ASM_OUTPUT_DEBUG_DATA4 (asm_out_file, data4);
637 if (flag_verbose_asm)
638 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
639 fputc ('\n', asm_out_file);
642 return 4;
645 /* Output quad word DATA8. Also output COMMENT if flag_verbose_asm is set.
646 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
648 static int
649 write_debug_data8 (data8, comment, dosizeonly)
650 unsigned long long data8;
651 const char *comment;
652 int dosizeonly;
654 if (!dosizeonly)
656 ASM_OUTPUT_DEBUG_DATA8 (asm_out_file, data8);
657 if (flag_verbose_asm)
658 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
659 fputc ('\n', asm_out_file);
662 return 8;
665 /* Output the difference between LABEL1 and LABEL2. Also output COMMENT if
666 flag_verbose_asm is set. Return the data size. Just return the size if
667 DOSIZEONLY is nonzero. */
669 static int
670 write_debug_delta4 (label1, label2, comment, dosizeonly)
671 char *label1;
672 char *label2;
673 const char *comment;
674 int dosizeonly;
676 if (!dosizeonly)
678 ASM_OUTPUT_DEBUG_DELTA4 (asm_out_file, label1, label2);
679 if (flag_verbose_asm)
680 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
681 fputc ('\n', asm_out_file);
684 return 4;
687 /* Output a character string STRING. Also write COMMENT if flag_verbose_asm is
688 set. Return the string length. Just return the length if DOSIZEONLY is
689 nonzero. */
691 static int
692 write_debug_string (string, comment, dosizeonly)
693 char *string;
694 const char *comment;
695 int dosizeonly;
697 if (!dosizeonly)
699 ASM_OUTPUT_DEBUG_STRING (asm_out_file, string);
700 if (flag_verbose_asm)
701 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
702 fputc ('\n', asm_out_file);
705 return strlen (string);
708 /* Output a module begin header and return the header size. Just return the
709 size if DOSIZEONLY is nonzero. */
711 static int
712 write_modbeg (dosizeonly)
713 int dosizeonly;
715 DST_MODULE_BEGIN modbeg;
716 DST_MB_TRLR mb_trlr;
717 int i;
718 char *module_name, *m;
719 int modnamelen;
720 int prodnamelen;
721 int totsize = 0;
723 /* Assumes primary filename has Unix syntax file spec. */
724 module_name = xstrdup (basename ((char *) primary_filename));
726 m = strrchr (module_name, '.');
727 if (m)
728 *m = 0;
730 modnamelen = strlen (module_name);
731 for (i = 0; i < modnamelen; i++)
732 module_name[i] = TOUPPER (module_name[i]);
734 prodnamelen = strlen (module_producer);
736 modbeg.dst_a_modbeg_header.dst__header_length.dst_w_length
737 = DST_K_MODBEG_SIZE + modnamelen + DST_K_MB_TRLR_SIZE + prodnamelen - 1;
738 modbeg.dst_a_modbeg_header.dst__header_type.dst_w_type = DST_K_MODBEG;
739 modbeg.dst_b_modbeg_flags.dst_v_modbeg_hide = 0;
740 modbeg.dst_b_modbeg_flags.dst_v_modbeg_version = 1;
741 modbeg.dst_b_modbeg_flags.dst_v_modbeg_unused = 0;
742 modbeg.dst_b_modbeg_unused = 0;
743 modbeg.dst_l_modbeg_language = module_language;
744 modbeg.dst_w_version_major = DST_K_VERSION_MAJOR;
745 modbeg.dst_w_version_minor = DST_K_VERSION_MINOR;
746 modbeg.dst_b_modbeg_name = strlen (module_name);
748 mb_trlr.dst_b_compiler = strlen (module_producer);
750 totsize += write_debug_header (&modbeg.dst_a_modbeg_header,
751 "modbeg", dosizeonly);
752 totsize += write_debug_data1 (*((char *) &modbeg.dst_b_modbeg_flags),
753 "flags", dosizeonly);
754 totsize += write_debug_data1 (modbeg.dst_b_modbeg_unused,
755 "unused", dosizeonly);
756 totsize += write_debug_data4 (modbeg.dst_l_modbeg_language,
757 "language", dosizeonly);
758 totsize += write_debug_data2 (modbeg.dst_w_version_major,
759 "DST major version", dosizeonly);
760 totsize += write_debug_data2 (modbeg.dst_w_version_minor,
761 "DST minor version", dosizeonly);
762 totsize += write_debug_data1 (modbeg.dst_b_modbeg_name,
763 "length of module name", dosizeonly);
764 totsize += write_debug_string (module_name, "module name", dosizeonly);
765 totsize += write_debug_data1 (mb_trlr.dst_b_compiler,
766 "length of compiler name", dosizeonly);
767 totsize += write_debug_string (module_producer, "compiler name", dosizeonly);
769 return totsize;
772 /* Output a module end trailer and return the trailer size. Just return
773 the size if DOSIZEONLY is nonzero. */
775 static int
776 write_modend (dosizeonly)
777 int dosizeonly;
779 DST_MODULE_END modend;
780 int totsize = 0;
782 modend.dst_a_modend_header.dst__header_length.dst_w_length
783 = DST_K_MODEND_SIZE - 1;
784 modend.dst_a_modend_header.dst__header_type.dst_w_type = DST_K_MODEND;
786 totsize += write_debug_header (&modend.dst_a_modend_header, "modend",
787 dosizeonly);
789 return totsize;
792 /* Output a routine begin header routine RTNNUM and return the header size.
793 Just return the size if DOSIZEONLY is nonzero. */
795 static int
796 write_rtnbeg (rtnnum, dosizeonly)
797 int rtnnum;
798 int dosizeonly;
800 char *rtnname;
801 int rtnnamelen;
802 char *rtnentryname;
803 int totsize = 0;
804 char label[MAX_ARTIFICIAL_LABEL_BYTES];
805 DST_ROUTINE_BEGIN rtnbeg;
806 DST_PROLOG prolog;
808 rtnname = func_table[rtnnum];
809 rtnnamelen = strlen (rtnname);
810 rtnentryname = concat (rtnname, "..en", NULL);
812 if (!strcmp (rtnname, "main"))
814 DST_HEADER header;
815 const char *go = "TRANSFER$BREAK$GO";
817 /* This command isn't documented in DSTRECORDS, so it's made to
818 look like what DEC C does */
820 /* header size - 1st byte + flag byte + STO_LW size
821 + string count byte + string length */
822 header.dst__header_length.dst_w_length
823 = DST_K_DST_HEADER_SIZE - 1 + 1 + 4 + 1 + strlen (go);
824 header.dst__header_type.dst_w_type = 0x17;
826 totsize += write_debug_header (&header, "transfer", dosizeonly);
828 /* I think this is a flag byte, but I don't know what this flag means */
829 totsize += write_debug_data1 (0x1, "flags ???", dosizeonly);
831 /* Routine Begin PD Address */
832 totsize += write_debug_addr (rtnname, "main procedure descriptor",
833 dosizeonly);
834 totsize += write_debug_data1 (strlen (go), "length of main_name",
835 dosizeonly);
836 totsize += write_debug_string ((char *) go, "main name", dosizeonly);
839 /* The header length never includes the length byte */
840 rtnbeg.dst_a_rtnbeg_header.dst__header_length.dst_w_length
841 = DST_K_RTNBEG_SIZE + rtnnamelen - 1;
842 rtnbeg.dst_a_rtnbeg_header.dst__header_type.dst_w_type = DST_K_RTNBEG;
843 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unused = 0;
844 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unalloc = 0;
845 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_prototype = 0;
846 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_inlined = 0;
847 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_no_call = 1;
848 rtnbeg.dst_b_rtnbeg_name = rtnnamelen;
850 totsize += write_debug_header (&rtnbeg.dst_a_rtnbeg_header, "rtnbeg",
851 dosizeonly);
852 totsize += write_debug_data1 (*((char *) &rtnbeg.dst_b_rtnbeg_flags),
853 "flags", dosizeonly);
855 /* Routine Begin Address */
856 totsize += write_debug_addr (rtnentryname, "routine entry name", dosizeonly);
858 /* Routine Begin PD Address */
859 totsize += write_debug_addr (rtnname, "routine procedure descriptor",
860 dosizeonly);
862 /* Routine Begin Name */
863 totsize += write_debug_data1 (rtnbeg.dst_b_rtnbeg_name,
864 "length of routine name", dosizeonly);
866 totsize += write_debug_string (rtnname, "routine name", dosizeonly);
868 free (rtnentryname);
870 if (debug_info_level > DINFO_LEVEL_TERSE)
872 prolog.dst_a_prolog_header.dst__header_length.dst_w_length
873 = DST_K_PROLOG_SIZE - 1;
874 prolog.dst_a_prolog_header.dst__header_type.dst_w_type = DST_K_PROLOG;
876 totsize += write_debug_header (&prolog.dst_a_prolog_header, "prolog",
877 dosizeonly);
879 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_PROLOG_LABEL, rtnnum);
880 totsize += write_debug_addr (label, "prolog breakpoint addr",
881 dosizeonly);
884 return totsize;
887 /* Output a routine end trailer for routine RTNNUM and return the header size.
888 Just return the size if DOSIZEONLY is nonzero. */
890 static int
891 write_rtnend (rtnnum, dosizeonly)
892 int rtnnum;
893 int dosizeonly;
895 DST_ROUTINE_END rtnend;
896 char label1[MAX_ARTIFICIAL_LABEL_BYTES];
897 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
898 int totsize;
900 totsize = 0;
902 rtnend.dst_a_rtnend_header.dst__header_length.dst_w_length
903 = DST_K_RTNEND_SIZE - 1;
904 rtnend.dst_a_rtnend_header.dst__header_type.dst_w_type = DST_K_RTNEND;
905 rtnend.dst_b_rtnend_unused = 0;
906 rtnend.dst_l_rtnend_size = 0; /* Calculated below. */
908 totsize += write_debug_header (&rtnend.dst_a_rtnend_header, "rtnend",
909 dosizeonly);
910 totsize += write_debug_data1 (rtnend.dst_b_rtnend_unused, "unused",
911 dosizeonly);
913 ASM_GENERATE_INTERNAL_LABEL (label1, FUNC_BEGIN_LABEL, rtnnum);
914 ASM_GENERATE_INTERNAL_LABEL (label2, FUNC_END_LABEL, rtnnum);
915 totsize += write_debug_delta4 (label2, label1, "routine size", dosizeonly);
917 return totsize;
920 #define K_DELTA_PC(I) \
921 ((I) < 128 ? -(I) : (I) < 65536 ? DST_K_DELTA_PC_W : DST_K_DELTA_PC_L)
923 #define K_SET_LINUM(I) \
924 ((I) < 256 ? DST_K_SET_LINUM_B \
925 : (I) < 65536 ? DST_K_SET_LINUM : DST_K_SET_LINUM_L)
927 #define K_INCR_LINUM(I) \
928 ((I) < 256 ? DST_K_INCR_LINUM \
929 : (I) < 65536 ? DST_K_INCR_LINUM_W : DST_K_INCR_LINUM_L)
931 /* Output the PC to line number correlations and return the size. Just return
932 the size if DOSIZEONLY is nonzero */
934 static int
935 write_pclines (dosizeonly)
936 int dosizeonly;
938 unsigned i;
939 int fn;
940 int ln, lastln;
941 int linestart = 0;
942 int max_line;
943 DST_LINE_NUM_HEADER line_num;
944 DST_PCLINE_COMMANDS pcline;
945 char label[MAX_ARTIFICIAL_LABEL_BYTES];
946 char lastlabel[MAX_ARTIFICIAL_LABEL_BYTES];
947 int totsize = 0;
948 char buff[256];
950 max_line = file_info_table[1].max_line;
951 file_info_table[1].listing_line_start = linestart;
952 linestart = linestart + ((max_line / 100000) + 1) * 100000;
954 for (i = 2; i < file_info_table_in_use; i++)
956 max_line = file_info_table[i].max_line;
957 file_info_table[i].listing_line_start = linestart;
958 linestart = linestart + ((max_line / 10000) + 1) * 10000;
961 /* Set starting address to beginning of text section */
962 line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 8;
963 line_num.dst_a_line_num_header.dst__header_type.dst_w_type = DST_K_LINE_NUM;
964 pcline.dst_b_pcline_command = DST_K_SET_ABS_PC;
966 totsize += write_debug_header (&line_num.dst_a_line_num_header,
967 "line_num", dosizeonly);
968 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
969 "line_num (SET ABS PC)", dosizeonly);
971 if (dosizeonly)
972 totsize += 4;
973 else
975 ASM_OUTPUT_DEBUG_ADDR (asm_out_file, TEXT_SECTION_ASM_OP);
976 if (flag_verbose_asm)
977 fprintf (asm_out_file, "\t%s line_num", ASM_COMMENT_START);
978 fputc ('\n', asm_out_file);
981 fn = line_info_table[1].dst_file_num;
982 ln = (file_info_table[fn].listing_line_start
983 + line_info_table[1].dst_line_num);
984 line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 4 + 4;
985 pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
987 totsize += write_debug_header (&line_num.dst_a_line_num_header,
988 "line_num", dosizeonly);
989 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
990 "line_num (SET LINUM LONG)", dosizeonly);
992 sprintf (buff, "line_num (%d)", ln ? ln - 1 : 0);
993 totsize += write_debug_data4 (ln ? ln - 1 : 0, buff, dosizeonly);
995 lastln = ln;
996 strcpy (lastlabel, TEXT_SECTION_ASM_OP);
997 for (i = 1; i < line_info_table_in_use; i++)
999 int extrabytes;
1001 fn = line_info_table[i].dst_file_num;
1002 ln = (file_info_table[fn].listing_line_start
1003 + line_info_table[i].dst_line_num);
1005 if (ln - lastln > 1)
1006 extrabytes = 5; /* NUMBYTES (ln - lastln - 1) + 1; */
1007 else if (ln <= lastln)
1008 extrabytes = 5; /* NUMBYTES (ln - 1) + 1; */
1009 else
1010 extrabytes = 0;
1012 line_num.dst_a_line_num_header.dst__header_length.dst_w_length
1013 = 8 + extrabytes;
1015 totsize += write_debug_header
1016 (&line_num.dst_a_line_num_header, "line_num", dosizeonly);
1018 if (ln - lastln > 1)
1020 int lndif = ln - lastln - 1;
1022 /* K_INCR_LINUM (lndif); */
1023 pcline.dst_b_pcline_command = DST_K_INCR_LINUM_L;
1025 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
1026 "line_num (INCR LINUM LONG)",
1027 dosizeonly);
1029 sprintf (buff, "line_num (%d)", lndif);
1030 totsize += write_debug_data4 (lndif, buff, dosizeonly);
1032 else if (ln <= lastln)
1034 /* K_SET_LINUM (ln-1); */
1035 pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
1037 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
1038 "line_num (SET LINUM LONG)",
1039 dosizeonly);
1041 sprintf (buff, "line_num (%d)", ln - 1);
1042 totsize += write_debug_data4 (ln - 1, buff, dosizeonly);
1045 pcline.dst_b_pcline_command = DST_K_DELTA_PC_L;
1047 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
1048 "line_num (DELTA PC LONG)", dosizeonly);
1050 ASM_GENERATE_INTERNAL_LABEL (label, LINE_CODE_LABEL, i);
1051 totsize += write_debug_delta4 (label, lastlabel, "increment line_num",
1052 dosizeonly);
1054 lastln = ln;
1055 strcpy (lastlabel, label);
1058 return totsize;
1061 /* Output a source correlation for file FILEID using information saved in
1062 FILE_INFO_ENTRY and return the size. Just return the size if DOSIZEONLY is
1063 nonzero. */
1065 static int
1066 write_srccorr (fileid, file_info_entry, dosizeonly)
1067 int fileid;
1068 dst_file_info_entry file_info_entry;
1069 int dosizeonly;
1071 int src_command_size;
1072 int linesleft = file_info_entry.max_line;
1073 int linestart = file_info_entry.listing_line_start;
1074 int flen = file_info_entry.flen;
1075 int linestodo = 0;
1076 DST_SOURCE_CORR src_header;
1077 DST_SRC_COMMAND src_command;
1078 DST_SRC_COMMAND src_command_sf;
1079 DST_SRC_COMMAND src_command_sl;
1080 DST_SRC_COMMAND src_command_sr;
1081 DST_SRC_COMMAND src_command_dl;
1082 DST_SRC_CMDTRLR src_cmdtrlr;
1083 char buff[256];
1084 int totsize = 0;
1086 if (fileid == 1)
1088 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1089 = DST_K_SOURCE_CORR_HEADER_SIZE + 1 - 1;
1090 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1091 = DST_K_SOURCE;
1092 src_command.dst_b_src_command = DST_K_SRC_FORMFEED;
1094 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1095 "source corr", dosizeonly);
1097 totsize += write_debug_data1 (src_command.dst_b_src_command,
1098 "source_corr (SRC FORMFEED)",
1099 dosizeonly);
1102 src_command_size
1103 = DST_K_SRC_COMMAND_SIZE + flen + DST_K_SRC_CMDTRLR_SIZE;
1104 src_command.dst_b_src_command = DST_K_SRC_DECLFILE;
1105 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length
1106 = src_command_size - 2;
1107 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags = 0;
1108 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid
1109 = fileid;
1110 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt
1111 = file_info_entry.cdt;
1112 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk
1113 = file_info_entry.ebk;
1114 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb
1115 = file_info_entry.ffb;
1116 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo
1117 = file_info_entry.rfo;
1118 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename
1119 = file_info_entry.flen;
1121 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1122 = DST_K_SOURCE_CORR_HEADER_SIZE + src_command_size - 1;
1123 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1124 = DST_K_SOURCE;
1126 src_cmdtrlr.dst_b_src_df_libmodname = 0;
1128 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1129 "source corr", dosizeonly);
1130 totsize += write_debug_data1 (src_command.dst_b_src_command,
1131 "source_corr (DECL SRC FILE)", dosizeonly);
1132 totsize += write_debug_data1
1133 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length,
1134 "source_corr (length)", dosizeonly);
1136 totsize += write_debug_data1
1137 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags,
1138 "source_corr (flags)", dosizeonly);
1140 totsize += write_debug_data2
1141 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid,
1142 "source_corr (fileid)", dosizeonly);
1144 totsize += write_debug_data8
1145 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt,
1146 "source_corr (creation date)", dosizeonly);
1148 totsize += write_debug_data4
1149 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk,
1150 "source_corr (EOF block number)", dosizeonly);
1152 totsize += write_debug_data2
1153 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb,
1154 "source_corr (first free byte)", dosizeonly);
1156 totsize += write_debug_data1
1157 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo,
1158 "source_corr (record and file organization)", dosizeonly);
1160 totsize += write_debug_data1
1161 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename,
1162 "source_corr (filename length)", dosizeonly);
1164 totsize += write_debug_string (file_info_entry.file_name,
1165 "source file name", dosizeonly);
1166 totsize += write_debug_data1 (src_cmdtrlr.dst_b_src_df_libmodname,
1167 "source_corr (libmodname)", dosizeonly);
1169 src_command_sf.dst_b_src_command = DST_K_SRC_SETFILE;
1170 src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword = fileid;
1172 src_command_sr.dst_b_src_command = DST_K_SRC_SETREC_W;
1173 src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword = 1;
1175 src_command_sl.dst_b_src_command = DST_K_SRC_SETLNUM_L;
1176 src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong = linestart + 1;
1178 src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1180 if (linesleft > 65534)
1181 linesleft = linesleft - 65534, linestodo = 65534;
1182 else
1183 linestodo = linesleft, linesleft = 0;
1185 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1187 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1188 = DST_K_SOURCE_CORR_HEADER_SIZE + 3 + 3 + 5 + 3 - 1;
1189 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1190 = DST_K_SOURCE;
1192 if (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword)
1194 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1195 "source corr", dosizeonly);
1197 totsize += write_debug_data1 (src_command_sf.dst_b_src_command,
1198 "source_corr (src setfile)", dosizeonly);
1200 totsize += write_debug_data2
1201 (src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword,
1202 "source_corr (fileid)", dosizeonly);
1204 totsize += write_debug_data1 (src_command_sr.dst_b_src_command,
1205 "source_corr (setrec)", dosizeonly);
1207 totsize += write_debug_data2
1208 (src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword,
1209 "source_corr (recnum)", dosizeonly);
1211 totsize += write_debug_data1 (src_command_sl.dst_b_src_command,
1212 "source_corr (setlnum)", dosizeonly);
1214 totsize += write_debug_data4
1215 (src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong,
1216 "source_corr (linenum)", dosizeonly);
1218 totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1219 "source_corr (deflines)", dosizeonly);
1221 sprintf (buff, "source_corr (%d)",
1222 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1223 totsize += write_debug_data2
1224 (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
1225 buff, dosizeonly);
1227 while (linesleft > 0)
1229 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1230 = DST_K_SOURCE_CORR_HEADER_SIZE + 3 - 1;
1231 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1232 = DST_K_SOURCE;
1233 src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1235 if (linesleft > 65534)
1236 linesleft = linesleft - 65534, linestodo = 65534;
1237 else
1238 linestodo = linesleft, linesleft = 0;
1240 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1242 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1243 "source corr", dosizeonly);
1244 totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1245 "source_corr (deflines)", dosizeonly);
1246 sprintf (buff, "source_corr (%d)",
1247 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1248 totsize += write_debug_data2
1249 (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
1250 buff, dosizeonly);
1254 return totsize;
1257 /* Output all the source correlation entries and return the size. Just return
1258 the size if DOSIZEONLY is nonzero. */
1260 static int
1261 write_srccorrs (dosizeonly)
1262 int dosizeonly;
1264 unsigned int i;
1265 int totsize = 0;
1267 for (i = 1; i < file_info_table_in_use; i++)
1268 totsize += write_srccorr (i, file_info_table[i], dosizeonly);
1270 return totsize;
1273 /* Output a marker (i.e. a label) for the beginning of a function, before
1274 the prologue. */
1276 static void
1277 vmsdbgout_begin_prologue (line, file)
1278 unsigned int line;
1279 const char *file;
1281 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1283 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1284 (*dwarf2_debug_hooks.begin_prologue) (line, file);
1286 if (debug_info_level > DINFO_LEVEL_NONE)
1288 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1289 current_function_funcdef_no);
1290 ASM_OUTPUT_LABEL (asm_out_file, label);
1294 /* Output a marker (i.e. a label) for the beginning of a function, after
1295 the prologue. */
1297 static void
1298 vmsdbgout_end_prologue (line, file)
1299 unsigned int line;
1300 const char *file;
1302 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1304 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1305 (*dwarf2_debug_hooks.end_prologue) (line, file);
1307 if (debug_info_level > DINFO_LEVEL_TERSE)
1309 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_PROLOG_LABEL,
1310 current_function_funcdef_no);
1311 ASM_OUTPUT_LABEL (asm_out_file, label);
1313 /* VMS PCA expects every PC range to correlate to some line and file */
1314 vmsdbgout_source_line (line, file);
1318 /* No output for VMS debug, but make obligatory call to Dwarf2 debug */
1320 static void
1321 vmsdbgout_end_function (line)
1322 unsigned int line;
1324 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1325 (*dwarf2_debug_hooks.end_function) (line);
1328 /* Output a marker (i.e. a label) for the absolute end of the generated code
1329 for a function definition. This gets called *after* the epilogue code has
1330 been generated. */
1332 static void
1333 vmsdbgout_end_epilogue (line, file)
1334 unsigned int line;
1335 const char *file;
1337 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1339 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1340 (*dwarf2_debug_hooks.end_epilogue) (line, file);
1342 if (debug_info_level > DINFO_LEVEL_NONE)
1344 /* Output a label to mark the endpoint of the code generated for this
1345 function. */
1346 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1347 current_function_funcdef_no);
1348 ASM_OUTPUT_LABEL (asm_out_file, label);
1350 /* VMS PCA expects every PC range to correlate to some line and file */
1351 vmsdbgout_source_line (line, file);
1355 /* Output a marker (i.e. a label) for the beginning of the generated code for
1356 a lexical block. */
1358 static void
1359 vmsdbgout_begin_block (line, blocknum)
1360 register unsigned line;
1361 register unsigned blocknum;
1363 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1364 (*dwarf2_debug_hooks.begin_block) (line, blocknum);
1366 if (debug_info_level > DINFO_LEVEL_TERSE)
1367 (*targetm.asm_out.internal_label) (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
1370 /* Output a marker (i.e. a label) for the end of the generated code for a
1371 lexical block. */
1373 static void
1374 vmsdbgout_end_block (line, blocknum)
1375 register unsigned line;
1376 register unsigned blocknum;
1378 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1379 (*dwarf2_debug_hooks.end_block) (line, blocknum);
1381 if (debug_info_level > DINFO_LEVEL_TERSE)
1382 (*targetm.asm_out.internal_label) (asm_out_file, BLOCK_END_LABEL, blocknum);
1385 /* Not implemented in VMS Debug. */
1387 static bool
1388 vmsdbgout_ignore_block (block)
1389 tree block;
1391 bool retval = 0;
1393 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1394 retval = (*dwarf2_debug_hooks.ignore_block) (block);
1396 return retval;
1399 /* Add an entry for function DECL into the func_table. */
1401 static void
1402 vmsdbgout_begin_function (decl)
1403 tree decl;
1405 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1407 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1408 (*dwarf2_debug_hooks.begin_function) (decl);
1410 if (func_table_in_use == func_table_allocated)
1412 func_table_allocated += FUNC_TABLE_INCREMENT;
1413 func_table = (char **) xrealloc (func_table,
1414 func_table_allocated * sizeof (char *));
1417 /* Add the new entry to the end of the function name table. */
1418 func_table[func_table_in_use++] = xstrdup (name);
1421 static char fullname_buff [4096];
1423 /* Return the full file specification for FILENAME. The specification must be
1424 in VMS syntax in order to be processed by VMS Debug. */
1426 static char *
1427 full_name (filename)
1428 const char *filename;
1430 #ifdef VMS
1431 FILE *fp = fopen (filename, "r");
1433 fgetname (fp, fullname_buff, 1);
1434 fclose (fp);
1435 #else
1436 getcwd (fullname_buff, sizeof (fullname_buff));
1438 strcat (fullname_buff, "/");
1439 strcat (fullname_buff, filename);
1441 /* ??? Insert hairy code here to translate Unix style file specification
1442 to VMS style. */
1443 #endif
1445 return fullname_buff;
1448 /* Lookup a filename (in the list of filenames that we know about here in
1449 vmsdbgout.c) and return its "index". The index of each (known) filename is
1450 just a unique number which is associated with only that one filename. We
1451 need such numbers for the sake of generating labels and references
1452 to those files numbers. If the filename given as an argument is not
1453 found in our current list, add it to the list and assign it the next
1454 available unique index number. In order to speed up searches, we remember
1455 the index of the filename was looked up last. This handles the majority of
1456 all searches. */
1458 static unsigned int
1459 lookup_filename (file_name)
1460 const char *file_name;
1462 static unsigned int last_file_lookup_index = 0;
1463 register char *fn;
1464 register unsigned i;
1465 char *fnam;
1466 long long cdt;
1467 long ebk;
1468 short ffb;
1469 char rfo;
1470 char flen;
1471 struct stat statbuf;
1473 if (stat (file_name, &statbuf) == 0)
1475 long gmtoff;
1476 #ifdef VMS
1477 struct tm *ts;
1479 /* Adjust for GMT */
1480 ts = (struct tm *) localtime (&statbuf.st_ctime);
1481 gmtoff = ts->tm_gmtoff;
1483 /* VMS has multiple file format types */
1484 rfo = statbuf.st_fab_rfm;
1485 #else
1486 /* Is GMT adjustment an issue with a cross-compiler? */
1487 gmtoff = 0;
1489 /* Assume stream LF type file */
1490 rfo = 2;
1491 #endif
1492 cdt = 10000000 * (statbuf.st_ctime + gmtoff + vms_epoch_offset);
1493 ebk = statbuf.st_size / 512 + 1;
1494 ffb = statbuf.st_size - ((statbuf.st_size / 512) * 512);
1495 fnam = full_name (file_name);
1496 flen = strlen (fnam);
1498 else
1500 cdt = 0;
1501 ebk = 0;
1502 ffb = 0;
1503 rfo = 0;
1504 fnam = (char *) "";
1505 flen = 0;
1508 /* Check to see if the file name that was searched on the previous call
1509 matches this file name. If so, return the index. */
1510 if (last_file_lookup_index != 0)
1512 fn = file_info_table[last_file_lookup_index].file_name;
1513 if (strcmp (fnam, fn) == 0)
1514 return last_file_lookup_index;
1517 /* Didn't match the previous lookup, search the table */
1518 for (i = 1; i < file_info_table_in_use; ++i)
1520 fn = file_info_table[i].file_name;
1521 if (strcmp (fnam, fn) == 0)
1523 last_file_lookup_index = i;
1524 return i;
1528 /* Prepare to add a new table entry by making sure there is enough space in
1529 the table to do so. If not, expand the current table. */
1530 if (file_info_table_in_use == file_info_table_allocated)
1533 file_info_table_allocated += FILE_TABLE_INCREMENT;
1534 file_info_table
1535 = (dst_file_info_ref) xrealloc (file_info_table,
1536 (file_info_table_allocated
1537 * sizeof (dst_file_info_entry)));
1540 /* Add the new entry to the end of the filename table. */
1541 file_info_table[file_info_table_in_use].file_name = xstrdup (fnam);
1542 file_info_table[file_info_table_in_use].max_line = 0;
1543 file_info_table[file_info_table_in_use].cdt = cdt;
1544 file_info_table[file_info_table_in_use].ebk = ebk;
1545 file_info_table[file_info_table_in_use].ffb = ffb;
1546 file_info_table[file_info_table_in_use].rfo = rfo;
1547 file_info_table[file_info_table_in_use].flen = flen;
1549 last_file_lookup_index = file_info_table_in_use++;
1550 return last_file_lookup_index;
1553 /* Output a label to mark the beginning of a source code line entry
1554 and record information relating to this source line, in
1555 'line_info_table' for later output of the .debug_line section. */
1557 static void
1558 vmsdbgout_source_line (line, filename)
1559 register unsigned line;
1560 register const char *filename;
1562 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1563 (*dwarf2_debug_hooks.source_line) (line, filename);
1565 if (debug_info_level >= DINFO_LEVEL_TERSE)
1567 dst_line_info_ref line_info;
1569 (*targetm.asm_out.internal_label) (asm_out_file, LINE_CODE_LABEL,
1570 line_info_table_in_use);
1572 /* Expand the line info table if necessary. */
1573 if (line_info_table_in_use == line_info_table_allocated)
1575 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
1576 line_info_table
1577 = (dst_line_info_ref) xrealloc (line_info_table,
1578 (line_info_table_allocated
1579 * sizeof (dst_line_info_entry)));
1582 /* Add the new entry at the end of the line_info_table. */
1583 line_info = &line_info_table[line_info_table_in_use++];
1584 line_info->dst_file_num = lookup_filename (filename);
1585 line_info->dst_line_num = line;
1586 if (line > file_info_table[line_info->dst_file_num].max_line)
1587 file_info_table[line_info->dst_file_num].max_line = line;
1591 /* Record the beginning of a new source file, for later output.
1592 At present, unimplemented. */
1594 static void
1595 vmsdbgout_start_source_file (lineno, filename)
1596 unsigned int lineno;
1597 const char *filename;
1599 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1600 (*dwarf2_debug_hooks.start_source_file) (lineno, filename);
1603 /* Record the end of a source file, for later output.
1604 At present, unimplemented. */
1606 static void
1607 vmsdbgout_end_source_file (lineno)
1608 unsigned int lineno ATTRIBUTE_UNUSED;
1610 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1611 (*dwarf2_debug_hooks.end_source_file) (lineno);
1614 /* Set up for Debug output at the start of compilation. */
1616 static void
1617 vmsdbgout_init (main_input_filename)
1618 const char *main_input_filename;
1620 const char *language_string = lang_hooks.name;
1622 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1623 (*dwarf2_debug_hooks.init) (main_input_filename);
1625 if (debug_info_level == DINFO_LEVEL_NONE)
1626 return;
1628 /* Remember the name of the primary input file. */
1629 primary_filename = main_input_filename;
1631 /* Allocate the initial hunk of the file_info_table. */
1632 file_info_table
1633 = (dst_file_info_ref) xcalloc (FILE_TABLE_INCREMENT,
1634 sizeof (dst_file_info_entry));
1635 file_info_table_allocated = FILE_TABLE_INCREMENT;
1637 /* Skip the first entry - file numbers begin at 1 */
1638 file_info_table_in_use = 1;
1640 func_table = (char **) xcalloc (FUNC_TABLE_INCREMENT, sizeof (char *));
1641 func_table_allocated = FUNC_TABLE_INCREMENT;
1642 func_table_in_use = 1;
1644 /* Allocate the initial hunk of the line_info_table. */
1645 line_info_table
1646 = (dst_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
1647 sizeof (dst_line_info_entry));
1648 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
1649 /* zero-th entry is allocated, but unused */
1650 line_info_table_in_use = 1;
1652 lookup_filename (primary_filename);
1654 if (!strcmp (language_string, "GNU C"))
1655 module_language = DST_K_C;
1656 else if (!strcmp (language_string, "GNU C++"))
1657 module_language = DST_K_CXX;
1658 else if (!strcmp (language_string, "GNU Ada"))
1659 module_language = DST_K_ADA;
1660 else if (!strcmp (language_string, "GNU F77"))
1661 module_language = DST_K_FORTRAN;
1662 else
1663 module_language = DST_K_UNKNOWN;
1665 module_producer = concat (language_string, " ", version_string, NULL);
1667 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
1671 /* Not implemented in VMS Debug. */
1673 static void
1674 vmsdbgout_define (lineno, buffer)
1675 unsigned int lineno;
1676 const char *buffer;
1678 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1679 (*dwarf2_debug_hooks.define) (lineno, buffer);
1682 /* Not implemented in VMS Debug. */
1684 static void
1685 vmsdbgout_undef (lineno, buffer)
1686 unsigned int lineno;
1687 const char *buffer;
1689 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1690 (*dwarf2_debug_hooks.undef) (lineno, buffer);
1693 /* Not implemented in VMS Debug. */
1695 static void
1696 vmsdbgout_decl (decl)
1697 tree decl;
1699 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1700 (*dwarf2_debug_hooks.function_decl) (decl);
1703 /* Not implemented in VMS Debug. */
1705 static void
1706 vmsdbgout_global_decl (decl)
1707 tree decl;
1709 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1710 (*dwarf2_debug_hooks.global_decl) (decl);
1713 /* Not implemented in VMS Debug. */
1715 static void
1716 vmsdbgout_abstract_function (decl)
1717 tree decl;
1719 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1720 (*dwarf2_debug_hooks.outlining_inline_function) (decl);
1723 /* Output stuff that Debug requires at the end of every file and generate the
1724 VMS Debug debugging info. */
1726 static void
1727 vmsdbgout_finish (input_filename)
1728 const char *input_filename ATTRIBUTE_UNUSED;
1730 unsigned int i;
1731 int totsize;
1733 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1734 (*dwarf2_debug_hooks.finish) (input_filename);
1736 if (debug_info_level == DINFO_LEVEL_NONE)
1737 return;
1739 /* Output a terminator label for the .text section. */
1740 text_section ();
1741 (*targetm.asm_out.internal_label) (asm_out_file, TEXT_END_LABEL, 0);
1743 /* Output debugging information.
1744 Warning! Do not change the name of the .vmsdebug section without
1745 changing it in the assembler also. */
1746 named_section (NULL_TREE, ".vmsdebug", 0);
1747 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1749 totsize = write_modbeg (1);
1750 for (i = 1; i < func_table_in_use; i++)
1752 totsize += write_rtnbeg (i, 1);
1753 totsize += write_rtnend (i, 1);
1755 totsize += write_pclines (1);
1757 write_modbeg (0);
1758 for (i = 1; i < func_table_in_use; i++)
1760 write_rtnbeg (i, 0);
1761 write_rtnend (i, 0);
1763 write_pclines (0);
1765 if (debug_info_level > DINFO_LEVEL_TERSE)
1767 totsize = write_srccorrs (1);
1768 write_srccorrs (0);
1771 totsize = write_modend (1);
1772 write_modend (0);
1774 #endif /* VMS_DEBUGGING_INFO */