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