* class.c (build_base_path): Tidy a bit.
[official-gcc.git] / gcc / vmsdbgout.c
blobe32564946b713159c23e2f9166a7c559f4e0d309
1 /* Output VMS debug format symbol table information from GCC.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4 Contributed by Douglas B. Rupp (rupp@gnat.com).
5 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 "flags.h"
32 #include "rtl.h"
33 #include "output.h"
34 #include "vmsdbg.h"
35 #include "debug.h"
36 #include "langhooks.h"
37 #include "function.h"
38 #include "target.h"
40 /* Difference in seconds between the VMS Epoch and the Unix Epoch */
41 static const long long vms_epoch_offset = 3506716800ll;
43 /* NOTE: In the comments in this file, many references are made to "Debug
44 Symbol Table". This term is abbreviated as `DST' throughout the remainder
45 of this file. */
47 typedef struct dst_line_info_struct *dst_line_info_ref;
49 /* Each entry in the line_info_table maintains the file and
50 line number associated with the label generated for that
51 entry. The label gives the PC value associated with
52 the line number entry. */
53 typedef struct dst_line_info_struct
55 unsigned long dst_file_num;
56 unsigned long dst_line_num;
58 dst_line_info_entry;
60 typedef struct dst_file_info_struct *dst_file_info_ref;
62 typedef struct dst_file_info_struct
64 char *file_name;
65 unsigned int max_line;
66 unsigned int listing_line_start;
67 long long cdt;
68 long ebk;
69 short ffb;
70 char rfo;
71 char flen;
73 dst_file_info_entry;
75 /* How to start an assembler comment. */
76 #ifndef ASM_COMMENT_START
77 #define ASM_COMMENT_START ";#"
78 #endif
80 /* Maximum size (in bytes) of an artificially generated label. */
81 #define MAX_ARTIFICIAL_LABEL_BYTES 30
83 /* Make sure we know the sizes of the various types debug can describe. These
84 are only defaults. If the sizes are different for your target, you should
85 override these values by defining the appropriate symbols in your tm.h
86 file. */
87 #ifndef PTR_SIZE
88 #define PTR_SIZE 4 /* Must be 32 bits for VMS debug info */
89 #endif
91 /* Pointer to a structure of filenames referenced by this compilation unit. */
92 static dst_file_info_ref file_info_table;
94 /* Total number of entries in the table (i.e. array) pointed to by
95 `file_info_table'. This is the *total* and includes both used and unused
96 slots. */
97 static unsigned int file_info_table_allocated;
99 /* Number of entries in the file_info_table which are actually in use. */
100 static unsigned int file_info_table_in_use;
102 /* Size (in elements) of increments by which we may expand the filename
103 table. */
104 #define FILE_TABLE_INCREMENT 64
106 /* A structure to hold basic information for the VMS end
107 routine. */
109 typedef struct vms_func_struct
111 const char *vms_func_name;
112 unsigned funcdef_number;
114 vms_func_node;
116 typedef struct vms_func_struct *vms_func_ref;
118 static unsigned int func_table_allocated;
119 static unsigned int func_table_in_use;
120 #define FUNC_TABLE_INCREMENT 256
122 /* A pointer to the base of a table that contains frame description
123 information for each routine. */
124 static vms_func_ref func_table;
126 /* Local pointer to the name of the main input file. Initialized in
127 avmdbgout_init. */
128 static const char *primary_filename;
130 static char *module_producer;
131 static unsigned int module_language;
133 /* A pointer to the base of a table that contains line information
134 for each source code line in .text in the compilation unit. */
135 static dst_line_info_ref line_info_table;
137 /* Number of elements currently allocated for line_info_table. */
138 static unsigned int line_info_table_allocated;
140 /* Number of elements in line_info_table currently in use. */
141 static unsigned int line_info_table_in_use;
143 /* Size (in elements) of increments by which we may expand line_info_table. */
144 #define LINE_INFO_TABLE_INCREMENT 1024
146 /* Forward declarations for functions defined in this file. */
147 static char *full_name (const char *);
148 static unsigned int lookup_filename (const char *);
149 static void addr_const_to_string (char *, rtx);
150 static int write_debug_header (DST_HEADER *, const char *, int);
151 static int write_debug_addr (char *, const char *, int);
152 static int write_debug_data1 (unsigned int, const char *, int);
153 static int write_debug_data2 (unsigned int, const char *, int);
154 static int write_debug_data4 (unsigned long, const char *, int);
155 static int write_debug_data8 (unsigned long long, const char *, int);
156 static int write_debug_delta4 (char *, char *, const char *, int);
157 static int write_debug_string (char *, const char *, int);
158 static int write_modbeg (int);
159 static int write_modend (int);
160 static int write_rtnbeg (int, int);
161 static int write_rtnend (int, int);
162 static int write_pclines (int);
163 static int write_srccorr (int, dst_file_info_entry, int);
164 static int write_srccorrs (int);
166 static void vmsdbgout_init (const char *);
167 static void vmsdbgout_finish (const char *);
168 static void vmsdbgout_define (unsigned int, const char *);
169 static void vmsdbgout_undef (unsigned int, const char *);
170 static void vmsdbgout_start_source_file (unsigned int, const char *);
171 static void vmsdbgout_end_source_file (unsigned int);
172 static void vmsdbgout_begin_block (unsigned int, unsigned int);
173 static void vmsdbgout_end_block (unsigned int, unsigned int);
174 static bool vmsdbgout_ignore_block (tree);
175 static void vmsdbgout_source_line (unsigned int, const char *);
176 static void vmsdbgout_begin_prologue (unsigned int, const char *);
177 static void vmsdbgout_end_prologue (unsigned int, const char *);
178 static void vmsdbgout_end_function (unsigned int);
179 static void vmsdbgout_end_epilogue (unsigned int, const char *);
180 static void vmsdbgout_begin_function (tree);
181 static void vmsdbgout_decl (tree);
182 static void vmsdbgout_global_decl (tree);
183 static void vmsdbgout_abstract_function (tree);
185 /* The debug hooks structure. */
187 const struct gcc_debug_hooks vmsdbg_debug_hooks
188 = {vmsdbgout_init,
189 vmsdbgout_finish,
190 vmsdbgout_define,
191 vmsdbgout_undef,
192 vmsdbgout_start_source_file,
193 vmsdbgout_end_source_file,
194 vmsdbgout_begin_block,
195 vmsdbgout_end_block,
196 vmsdbgout_ignore_block,
197 vmsdbgout_source_line,
198 vmsdbgout_begin_prologue,
199 vmsdbgout_end_prologue,
200 vmsdbgout_end_epilogue,
201 vmsdbgout_begin_function,
202 vmsdbgout_end_function,
203 vmsdbgout_decl,
204 vmsdbgout_global_decl,
205 debug_nothing_tree_int, /* type_decl */
206 debug_nothing_tree_tree, /* imported_module_or_decl */
207 debug_nothing_tree, /* deferred_inline_function */
208 vmsdbgout_abstract_function,
209 debug_nothing_rtx, /* label */
210 debug_nothing_int, /* handle_pch */
211 debug_nothing_rtx /* var_location */
214 /* Definitions of defaults for assembler-dependent names of various
215 pseudo-ops and section names.
216 Theses may be overridden in the tm.h file (if necessary) for a particular
217 assembler. */
218 #ifdef UNALIGNED_SHORT_ASM_OP
219 #undef UNALIGNED_SHORT_ASM_OP
220 #endif
221 #define UNALIGNED_SHORT_ASM_OP ".word"
223 #ifdef UNALIGNED_INT_ASM_OP
224 #undef UNALIGNED_INT_ASM_OP
225 #endif
226 #define UNALIGNED_INT_ASM_OP ".long"
228 #ifdef UNALIGNED_LONG_ASM_OP
229 #undef UNALIGNED_LONG_ASM_OP
230 #endif
231 #define UNALIGNED_LONG_ASM_OP ".long"
233 #ifdef UNALIGNED_DOUBLE_INT_ASM_OP
234 #undef UNALIGNED_DOUBLE_INT_ASM_OP
235 #endif
236 #define UNALIGNED_DOUBLE_INT_ASM_OP ".quad"
238 #ifdef ASM_BYTE_OP
239 #undef ASM_BYTE_OP
240 #endif
241 #define ASM_BYTE_OP ".byte"
243 #define NUMBYTES(I) ((I) < 256 ? 1 : (I) < 65536 ? 2 : 4)
245 #define NUMBYTES0(I) ((I) < 128 ? 0 : (I) < 65536 ? 2 : 4)
247 #ifndef UNALIGNED_PTR_ASM_OP
248 #define UNALIGNED_PTR_ASM_OP \
249 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
250 #endif
252 #ifndef UNALIGNED_OFFSET_ASM_OP
253 #define UNALIGNED_OFFSET_ASM_OP(OFFSET) \
254 (NUMBYTES(OFFSET) == 4 \
255 ? UNALIGNED_LONG_ASM_OP \
256 : (NUMBYTES(OFFSET) == 2 ? UNALIGNED_SHORT_ASM_OP : ASM_BYTE_OP))
257 #endif
259 /* Definitions of defaults for formats and names of various special
260 (artificial) labels which may be generated within this file (when the -g
261 options is used and VMS_DEBUGGING_INFO is in effect. If necessary, these
262 may be overridden from within the tm.h file, but typically, overriding these
263 defaults is unnecessary. */
265 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
267 #ifndef TEXT_END_LABEL
268 #define TEXT_END_LABEL "Lvetext"
269 #endif
270 #ifndef FUNC_BEGIN_LABEL
271 #define FUNC_BEGIN_LABEL "LVFB"
272 #endif
273 #ifndef FUNC_PROLOG_LABEL
274 #define FUNC_PROLOG_LABEL "LVFP"
275 #endif
276 #ifndef FUNC_END_LABEL
277 #define FUNC_END_LABEL "LVFE"
278 #endif
279 #ifndef BLOCK_BEGIN_LABEL
280 #define BLOCK_BEGIN_LABEL "LVBB"
281 #endif
282 #ifndef BLOCK_END_LABEL
283 #define BLOCK_END_LABEL "LVBE"
284 #endif
285 #ifndef LINE_CODE_LABEL
286 #define LINE_CODE_LABEL "LVM"
287 #endif
289 #ifndef ASM_OUTPUT_DEBUG_DELTA2
290 #define ASM_OUTPUT_DEBUG_DELTA2(FILE,LABEL1,LABEL2) \
291 do \
293 fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
294 assemble_name (FILE, LABEL1); \
295 fprintf (FILE, "-"); \
296 assemble_name (FILE, LABEL2); \
298 while (0)
299 #endif
301 #ifndef ASM_OUTPUT_DEBUG_DELTA4
302 #define ASM_OUTPUT_DEBUG_DELTA4(FILE,LABEL1,LABEL2) \
303 do \
305 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
306 assemble_name (FILE, LABEL1); \
307 fprintf (FILE, "-"); \
308 assemble_name (FILE, LABEL2); \
310 while (0)
311 #endif
313 #ifndef ASM_OUTPUT_DEBUG_ADDR_DELTA
314 #define ASM_OUTPUT_DEBUG_ADDR_DELTA(FILE,LABEL1,LABEL2) \
315 do \
317 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
318 assemble_name (FILE, LABEL1); \
319 fprintf (FILE, "-"); \
320 assemble_name (FILE, LABEL2); \
322 while (0)
323 #endif
325 #ifndef ASM_OUTPUT_DEBUG_ADDR
326 #define ASM_OUTPUT_DEBUG_ADDR(FILE,LABEL) \
327 do \
329 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
330 assemble_name (FILE, LABEL); \
332 while (0)
333 #endif
335 #ifndef ASM_OUTPUT_DEBUG_ADDR_CONST
336 #define ASM_OUTPUT_DEBUG_ADDR_CONST(FILE,ADDR) \
337 fprintf ((FILE), "\t%s\t%s", UNALIGNED_PTR_ASM_OP, (ADDR))
338 #endif
340 #ifndef ASM_OUTPUT_DEBUG_DATA1
341 #define ASM_OUTPUT_DEBUG_DATA1(FILE,VALUE) \
342 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned char) VALUE)
343 #endif
345 #ifndef ASM_OUTPUT_DEBUG_DATA2
346 #define ASM_OUTPUT_DEBUG_DATA2(FILE,VALUE) \
347 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, \
348 (unsigned short) VALUE)
349 #endif
351 #ifndef ASM_OUTPUT_DEBUG_DATA4
352 #define ASM_OUTPUT_DEBUG_DATA4(FILE,VALUE) \
353 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (unsigned long) VALUE)
354 #endif
356 #ifndef ASM_OUTPUT_DEBUG_DATA
357 #define ASM_OUTPUT_DEBUG_DATA(FILE,VALUE) \
358 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP(VALUE), VALUE)
359 #endif
361 #ifndef ASM_OUTPUT_DEBUG_ADDR_DATA
362 #define ASM_OUTPUT_DEBUG_ADDR_DATA(FILE,VALUE) \
363 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_PTR_ASM_OP, \
364 (unsigned long) VALUE)
365 #endif
367 #ifndef ASM_OUTPUT_DEBUG_DATA8
368 #define ASM_OUTPUT_DEBUG_DATA8(FILE,VALUE) \
369 fprintf ((FILE), "\t%s\t0x%llx", UNALIGNED_DOUBLE_INT_ASM_OP, \
370 (unsigned long long) VALUE)
371 #endif
373 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
374 newline is produced. When flag_verbose_asm is asserted, we add commentary
375 at the end of the line, so we must avoid output of a newline here. */
376 #ifndef ASM_OUTPUT_DEBUG_STRING
377 #define ASM_OUTPUT_DEBUG_STRING(FILE,P) \
378 do \
380 register int slen = strlen(P); \
381 register char *p = (P); \
382 register int i; \
383 fprintf (FILE, "\t.ascii \""); \
384 for (i = 0; i < slen; i++) \
386 register int c = p[i]; \
387 if (c == '\"' || c == '\\') \
388 putc ('\\', FILE); \
389 if (c >= ' ' && c < 0177) \
390 putc (c, FILE); \
391 else \
392 fprintf (FILE, "\\%o", c); \
394 fprintf (FILE, "\""); \
396 while (0)
397 #endif
399 /* Convert a reference to the assembler name of a C-level name. This
400 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
401 a string rather than writing to a file. */
402 #ifndef ASM_NAME_TO_STRING
403 #define ASM_NAME_TO_STRING(STR, NAME) \
404 do \
406 if ((NAME)[0] == '*') \
407 strcpy (STR, NAME+1); \
408 else \
409 strcpy (STR, NAME); \
411 while (0)
412 #endif
415 /* General utility functions. */
417 /* Convert an integer constant expression into assembler syntax. Addition and
418 subtraction are the only arithmetic that may appear in these expressions.
419 This is an adaptation of output_addr_const in final.c. Here, the target
420 of the conversion is a string buffer. We can't use output_addr_const
421 directly, because it writes to a file. */
423 static void
424 addr_const_to_string (char *str, rtx x)
426 char buf1[256];
427 char buf2[256];
429 restart:
430 str[0] = '\0';
431 switch (GET_CODE (x))
433 case PC:
434 if (flag_pic)
435 strcat (str, ",");
436 else
437 abort ();
438 break;
440 case SYMBOL_REF:
441 ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
442 strcat (str, buf1);
443 break;
445 case LABEL_REF:
446 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
447 ASM_NAME_TO_STRING (buf2, buf1);
448 strcat (str, buf2);
449 break;
451 case CODE_LABEL:
452 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
453 ASM_NAME_TO_STRING (buf2, buf1);
454 strcat (str, buf2);
455 break;
457 case CONST_INT:
458 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
459 strcat (str, buf1);
460 break;
462 case CONST:
463 /* This used to output parentheses around the expression, but that does
464 not work on the 386 (either ATT or BSD assembler). */
465 addr_const_to_string (buf1, XEXP (x, 0));
466 strcat (str, buf1);
467 break;
469 case CONST_DOUBLE:
470 if (GET_MODE (x) == VOIDmode)
472 /* We can use %d if the number is one word and positive. */
473 if (CONST_DOUBLE_HIGH (x))
474 sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
475 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
476 else if (CONST_DOUBLE_LOW (x) < 0)
477 sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
478 else
479 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
480 CONST_DOUBLE_LOW (x));
481 strcat (str, buf1);
483 else
484 /* We can't handle floating point constants; PRINT_OPERAND must
485 handle them. */
486 output_operand_lossage ("floating constant misused");
487 break;
489 case PLUS:
490 /* Some assemblers need integer constants to appear last (eg masm). */
491 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
493 addr_const_to_string (buf1, XEXP (x, 1));
494 strcat (str, buf1);
495 if (INTVAL (XEXP (x, 0)) >= 0)
496 strcat (str, "+");
497 addr_const_to_string (buf1, XEXP (x, 0));
498 strcat (str, buf1);
500 else
502 addr_const_to_string (buf1, XEXP (x, 0));
503 strcat (str, buf1);
504 if (INTVAL (XEXP (x, 1)) >= 0)
505 strcat (str, "+");
506 addr_const_to_string (buf1, XEXP (x, 1));
507 strcat (str, buf1);
509 break;
511 case MINUS:
512 /* Avoid outputting things like x-x or x+5-x, since some assemblers
513 can't handle that. */
514 x = simplify_subtraction (x);
515 if (GET_CODE (x) != MINUS)
516 goto restart;
518 addr_const_to_string (buf1, XEXP (x, 0));
519 strcat (str, buf1);
520 strcat (str, "-");
521 if (GET_CODE (XEXP (x, 1)) == CONST_INT
522 && INTVAL (XEXP (x, 1)) < 0)
524 strcat (str, "(");
525 addr_const_to_string (buf1, XEXP (x, 1));
526 strcat (str, buf1);
527 strcat (str, ")");
529 else
531 addr_const_to_string (buf1, XEXP (x, 1));
532 strcat (str, buf1);
534 break;
536 case ZERO_EXTEND:
537 case SIGN_EXTEND:
538 addr_const_to_string (buf1, XEXP (x, 0));
539 strcat (str, buf1);
540 break;
542 default:
543 output_operand_lossage ("invalid expression as operand");
547 /* Output the debug header HEADER. Also output COMMENT if flag_verbose_asm is
548 set. Return the header size. Just return the size if DOSIZEONLY is
549 nonzero. */
551 static int
552 write_debug_header (DST_HEADER *header, const char *comment, int dosizeonly)
554 if (!dosizeonly)
556 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
557 header->dst__header_length.dst_w_length);
559 if (flag_verbose_asm)
560 fprintf (asm_out_file, "\t%s record length", ASM_COMMENT_START);
561 fputc ('\n', asm_out_file);
563 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
564 header->dst__header_type.dst_w_type);
566 if (flag_verbose_asm)
567 fprintf (asm_out_file, "\t%s record type (%s)", ASM_COMMENT_START,
568 comment);
570 fputc ('\n', asm_out_file);
573 return 4;
576 /* Output the address of SYMBOL. Also output COMMENT if flag_verbose_asm is
577 set. Return the address size. Just return the size if DOSIZEONLY is
578 nonzero. */
580 static int
581 write_debug_addr (char *symbol, const char *comment, int dosizeonly)
583 if (!dosizeonly)
585 ASM_OUTPUT_DEBUG_ADDR (asm_out_file, symbol);
586 if (flag_verbose_asm)
587 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
588 fputc ('\n', asm_out_file);
591 return PTR_SIZE;
594 /* Output the single byte DATA1. Also output COMMENT if flag_verbose_asm is
595 set. Return the data size. Just return the size if DOSIZEONLY is
596 nonzero. */
598 static int
599 write_debug_data1 (unsigned int data1, const char *comment, int dosizeonly)
601 if (!dosizeonly)
603 ASM_OUTPUT_DEBUG_DATA1 (asm_out_file, data1);
604 if (flag_verbose_asm)
605 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
606 fputc ('\n', asm_out_file);
609 return 1;
612 /* Output the single word DATA2. Also output COMMENT if flag_verbose_asm is
613 set. Return the data size. Just return the size if DOSIZEONLY is
614 nonzero. */
616 static int
617 write_debug_data2 (unsigned int data2, const char *comment, int dosizeonly)
619 if (!dosizeonly)
621 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file, data2);
622 if (flag_verbose_asm)
623 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
624 fputc ('\n', asm_out_file);
627 return 2;
630 /* Output double word DATA4. Also output COMMENT if flag_verbose_asm is set.
631 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
633 static int
634 write_debug_data4 (unsigned long data4, const char *comment, int dosizeonly)
636 if (!dosizeonly)
638 ASM_OUTPUT_DEBUG_DATA4 (asm_out_file, data4);
639 if (flag_verbose_asm)
640 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
641 fputc ('\n', asm_out_file);
644 return 4;
647 /* Output quad word DATA8. Also output COMMENT if flag_verbose_asm is set.
648 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
650 static int
651 write_debug_data8 (unsigned long long data8, 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 (char *label1, char *label2, const char *comment,
671 int dosizeonly)
673 if (!dosizeonly)
675 ASM_OUTPUT_DEBUG_DELTA4 (asm_out_file, label1, label2);
676 if (flag_verbose_asm)
677 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
678 fputc ('\n', asm_out_file);
681 return 4;
684 /* Output a character string STRING. Also write COMMENT if flag_verbose_asm is
685 set. Return the string length. Just return the length if DOSIZEONLY is
686 nonzero. */
688 static int
689 write_debug_string (char *string, const char *comment, int dosizeonly)
691 if (!dosizeonly)
693 ASM_OUTPUT_DEBUG_STRING (asm_out_file, string);
694 if (flag_verbose_asm)
695 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
696 fputc ('\n', asm_out_file);
699 return strlen (string);
702 /* Output a module begin header and return the header size. Just return the
703 size if DOSIZEONLY is nonzero. */
705 static int
706 write_modbeg (int dosizeonly)
708 DST_MODULE_BEGIN modbeg;
709 DST_MB_TRLR mb_trlr;
710 int i;
711 char *module_name, *m;
712 int modnamelen;
713 int prodnamelen;
714 int totsize = 0;
716 /* Assumes primary filename has Unix syntax file spec. */
717 module_name = xstrdup (basename ((char *) primary_filename));
719 m = strrchr (module_name, '.');
720 if (m)
721 *m = 0;
723 modnamelen = strlen (module_name);
724 for (i = 0; i < modnamelen; i++)
725 module_name[i] = TOUPPER (module_name[i]);
727 prodnamelen = strlen (module_producer);
729 modbeg.dst_a_modbeg_header.dst__header_length.dst_w_length
730 = DST_K_MODBEG_SIZE + modnamelen + DST_K_MB_TRLR_SIZE + prodnamelen - 1;
731 modbeg.dst_a_modbeg_header.dst__header_type.dst_w_type = DST_K_MODBEG;
732 modbeg.dst_b_modbeg_flags.dst_v_modbeg_hide = 0;
733 modbeg.dst_b_modbeg_flags.dst_v_modbeg_version = 1;
734 modbeg.dst_b_modbeg_flags.dst_v_modbeg_unused = 0;
735 modbeg.dst_b_modbeg_unused = 0;
736 modbeg.dst_l_modbeg_language = module_language;
737 modbeg.dst_w_version_major = DST_K_VERSION_MAJOR;
738 modbeg.dst_w_version_minor = DST_K_VERSION_MINOR;
739 modbeg.dst_b_modbeg_name = strlen (module_name);
741 mb_trlr.dst_b_compiler = strlen (module_producer);
743 totsize += write_debug_header (&modbeg.dst_a_modbeg_header,
744 "modbeg", dosizeonly);
745 totsize += write_debug_data1 (*((char *) &modbeg.dst_b_modbeg_flags),
746 "flags", dosizeonly);
747 totsize += write_debug_data1 (modbeg.dst_b_modbeg_unused,
748 "unused", dosizeonly);
749 totsize += write_debug_data4 (modbeg.dst_l_modbeg_language,
750 "language", dosizeonly);
751 totsize += write_debug_data2 (modbeg.dst_w_version_major,
752 "DST major version", dosizeonly);
753 totsize += write_debug_data2 (modbeg.dst_w_version_minor,
754 "DST minor version", dosizeonly);
755 totsize += write_debug_data1 (modbeg.dst_b_modbeg_name,
756 "length of module name", dosizeonly);
757 totsize += write_debug_string (module_name, "module name", dosizeonly);
758 totsize += write_debug_data1 (mb_trlr.dst_b_compiler,
759 "length of compiler name", dosizeonly);
760 totsize += write_debug_string (module_producer, "compiler name", dosizeonly);
762 return totsize;
765 /* Output a module end trailer and return the trailer size. Just return
766 the size if DOSIZEONLY is nonzero. */
768 static int
769 write_modend (int dosizeonly)
771 DST_MODULE_END modend;
772 int totsize = 0;
774 modend.dst_a_modend_header.dst__header_length.dst_w_length
775 = DST_K_MODEND_SIZE - 1;
776 modend.dst_a_modend_header.dst__header_type.dst_w_type = DST_K_MODEND;
778 totsize += write_debug_header (&modend.dst_a_modend_header, "modend",
779 dosizeonly);
781 return totsize;
784 /* Output a routine begin header routine RTNNUM and return the header size.
785 Just return the size if DOSIZEONLY is nonzero. */
787 static int
788 write_rtnbeg (int rtnnum, int dosizeonly)
790 char *rtnname;
791 int rtnnamelen;
792 char *rtnentryname;
793 int totsize = 0;
794 char label[MAX_ARTIFICIAL_LABEL_BYTES];
795 DST_ROUTINE_BEGIN rtnbeg;
796 DST_PROLOG prolog;
797 vms_func_ref fde = &func_table[rtnnum];
799 rtnname = (char *)fde->vms_func_name;
800 rtnnamelen = strlen (rtnname);
801 rtnentryname = concat (rtnname, "..en", NULL);
803 if (!strcmp (rtnname, "main"))
805 DST_HEADER header;
806 const char *go = "TRANSFER$BREAK$GO";
808 /* This command isn't documented in DSTRECORDS, so it's made to
809 look like what DEC C does */
811 /* header size - 1st byte + flag byte + STO_LW size
812 + string count byte + string length */
813 header.dst__header_length.dst_w_length
814 = DST_K_DST_HEADER_SIZE - 1 + 1 + 4 + 1 + strlen (go);
815 header.dst__header_type.dst_w_type = 0x17;
817 totsize += write_debug_header (&header, "transfer", dosizeonly);
819 /* I think this is a flag byte, but I don't know what this flag means */
820 totsize += write_debug_data1 (0x1, "flags ???", dosizeonly);
822 /* Routine Begin PD Address */
823 totsize += write_debug_addr (rtnname, "main procedure descriptor",
824 dosizeonly);
825 totsize += write_debug_data1 (strlen (go), "length of main_name",
826 dosizeonly);
827 totsize += write_debug_string ((char *) go, "main name", dosizeonly);
830 /* The header length never includes the length byte. */
831 rtnbeg.dst_a_rtnbeg_header.dst__header_length.dst_w_length
832 = DST_K_RTNBEG_SIZE + rtnnamelen - 1;
833 rtnbeg.dst_a_rtnbeg_header.dst__header_type.dst_w_type = DST_K_RTNBEG;
834 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unused = 0;
835 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unalloc = 0;
836 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_prototype = 0;
837 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_inlined = 0;
838 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_no_call = 1;
839 rtnbeg.dst_b_rtnbeg_name = rtnnamelen;
841 totsize += write_debug_header (&rtnbeg.dst_a_rtnbeg_header, "rtnbeg",
842 dosizeonly);
843 totsize += write_debug_data1 (*((char *) &rtnbeg.dst_b_rtnbeg_flags),
844 "flags", dosizeonly);
846 /* Routine Begin Address */
847 totsize += write_debug_addr (rtnentryname, "routine entry name", dosizeonly);
849 /* Routine Begin PD Address */
850 totsize += write_debug_addr (rtnname, "routine procedure descriptor",
851 dosizeonly);
853 /* Routine Begin Name */
854 totsize += write_debug_data1 (rtnbeg.dst_b_rtnbeg_name,
855 "length of routine name", dosizeonly);
857 totsize += write_debug_string (rtnname, "routine name", dosizeonly);
859 free (rtnentryname);
861 if (debug_info_level > DINFO_LEVEL_TERSE)
863 prolog.dst_a_prolog_header.dst__header_length.dst_w_length
864 = DST_K_PROLOG_SIZE - 1;
865 prolog.dst_a_prolog_header.dst__header_type.dst_w_type = DST_K_PROLOG;
867 totsize += write_debug_header (&prolog.dst_a_prolog_header, "prolog",
868 dosizeonly);
870 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_PROLOG_LABEL, fde->funcdef_number);
871 totsize += write_debug_addr (label, "prolog breakpoint addr",
872 dosizeonly);
875 return totsize;
878 /* Output a routine end trailer for routine RTNNUM and return the header size.
879 Just return the size if DOSIZEONLY is nonzero. */
881 static int
882 write_rtnend (int rtnnum, int dosizeonly)
884 DST_ROUTINE_END rtnend;
885 char label1[MAX_ARTIFICIAL_LABEL_BYTES];
886 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
887 int totsize;
888 vms_func_ref fde = &func_table[rtnnum];
889 int corrected_rtnnum = fde->funcdef_number;
891 totsize = 0;
893 rtnend.dst_a_rtnend_header.dst__header_length.dst_w_length
894 = DST_K_RTNEND_SIZE - 1;
895 rtnend.dst_a_rtnend_header.dst__header_type.dst_w_type = DST_K_RTNEND;
896 rtnend.dst_b_rtnend_unused = 0;
897 rtnend.dst_l_rtnend_size = 0; /* Calculated below. */
899 totsize += write_debug_header (&rtnend.dst_a_rtnend_header, "rtnend",
900 dosizeonly);
901 totsize += write_debug_data1 (rtnend.dst_b_rtnend_unused, "unused",
902 dosizeonly);
904 ASM_GENERATE_INTERNAL_LABEL (label1, FUNC_BEGIN_LABEL, corrected_rtnnum);
905 ASM_GENERATE_INTERNAL_LABEL (label2, FUNC_END_LABEL, corrected_rtnnum);
906 totsize += write_debug_delta4 (label2, label1, "routine size", dosizeonly);
908 return totsize;
911 #define K_DELTA_PC(I) \
912 ((I) < 128 ? -(I) : (I) < 65536 ? DST_K_DELTA_PC_W : DST_K_DELTA_PC_L)
914 #define K_SET_LINUM(I) \
915 ((I) < 256 ? DST_K_SET_LINUM_B \
916 : (I) < 65536 ? DST_K_SET_LINUM : DST_K_SET_LINUM_L)
918 #define K_INCR_LINUM(I) \
919 ((I) < 256 ? DST_K_INCR_LINUM \
920 : (I) < 65536 ? DST_K_INCR_LINUM_W : DST_K_INCR_LINUM_L)
922 /* Output the PC to line number correlations and return the size. Just return
923 the size if DOSIZEONLY is nonzero */
925 static int
926 write_pclines (int dosizeonly)
928 unsigned i;
929 int fn;
930 int ln, lastln;
931 int linestart = 0;
932 int max_line;
933 DST_LINE_NUM_HEADER line_num;
934 DST_PCLINE_COMMANDS pcline;
935 char label[MAX_ARTIFICIAL_LABEL_BYTES];
936 char lastlabel[MAX_ARTIFICIAL_LABEL_BYTES];
937 int totsize = 0;
938 char buff[256];
940 max_line = file_info_table[1].max_line;
941 file_info_table[1].listing_line_start = linestart;
942 linestart = linestart + ((max_line / 100000) + 1) * 100000;
944 for (i = 2; i < file_info_table_in_use; i++)
946 max_line = file_info_table[i].max_line;
947 file_info_table[i].listing_line_start = linestart;
948 linestart = linestart + ((max_line / 10000) + 1) * 10000;
951 /* Set starting address to beginning of text section. */
952 line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 8;
953 line_num.dst_a_line_num_header.dst__header_type.dst_w_type = DST_K_LINE_NUM;
954 pcline.dst_b_pcline_command = DST_K_SET_ABS_PC;
956 totsize += write_debug_header (&line_num.dst_a_line_num_header,
957 "line_num", dosizeonly);
958 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
959 "line_num (SET ABS PC)", dosizeonly);
961 if (dosizeonly)
962 totsize += 4;
963 else
965 ASM_OUTPUT_DEBUG_ADDR (asm_out_file, TEXT_SECTION_ASM_OP);
966 if (flag_verbose_asm)
967 fprintf (asm_out_file, "\t%s line_num", ASM_COMMENT_START);
968 fputc ('\n', asm_out_file);
971 fn = line_info_table[1].dst_file_num;
972 ln = (file_info_table[fn].listing_line_start
973 + line_info_table[1].dst_line_num);
974 line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 4 + 4;
975 pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
977 totsize += write_debug_header (&line_num.dst_a_line_num_header,
978 "line_num", dosizeonly);
979 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
980 "line_num (SET LINUM LONG)", dosizeonly);
982 sprintf (buff, "line_num (%d)", ln ? ln - 1 : 0);
983 totsize += write_debug_data4 (ln ? ln - 1 : 0, buff, dosizeonly);
985 lastln = ln;
986 strcpy (lastlabel, TEXT_SECTION_ASM_OP);
987 for (i = 1; i < line_info_table_in_use; i++)
989 int extrabytes;
991 fn = line_info_table[i].dst_file_num;
992 ln = (file_info_table[fn].listing_line_start
993 + line_info_table[i].dst_line_num);
995 if (ln - lastln > 1)
996 extrabytes = 5; /* NUMBYTES (ln - lastln - 1) + 1; */
997 else if (ln <= lastln)
998 extrabytes = 5; /* NUMBYTES (ln - 1) + 1; */
999 else
1000 extrabytes = 0;
1002 line_num.dst_a_line_num_header.dst__header_length.dst_w_length
1003 = 8 + extrabytes;
1005 totsize += write_debug_header
1006 (&line_num.dst_a_line_num_header, "line_num", dosizeonly);
1008 if (ln - lastln > 1)
1010 int lndif = ln - lastln - 1;
1012 /* K_INCR_LINUM (lndif); */
1013 pcline.dst_b_pcline_command = DST_K_INCR_LINUM_L;
1015 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
1016 "line_num (INCR LINUM LONG)",
1017 dosizeonly);
1019 sprintf (buff, "line_num (%d)", lndif);
1020 totsize += write_debug_data4 (lndif, buff, dosizeonly);
1022 else if (ln <= lastln)
1024 /* K_SET_LINUM (ln-1); */
1025 pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
1027 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
1028 "line_num (SET LINUM LONG)",
1029 dosizeonly);
1031 sprintf (buff, "line_num (%d)", ln - 1);
1032 totsize += write_debug_data4 (ln - 1, buff, dosizeonly);
1035 pcline.dst_b_pcline_command = DST_K_DELTA_PC_L;
1037 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
1038 "line_num (DELTA PC LONG)", dosizeonly);
1040 ASM_GENERATE_INTERNAL_LABEL (label, LINE_CODE_LABEL, i);
1041 totsize += write_debug_delta4 (label, lastlabel, "increment line_num",
1042 dosizeonly);
1044 lastln = ln;
1045 strcpy (lastlabel, label);
1048 return totsize;
1051 /* Output a source correlation for file FILEID using information saved in
1052 FILE_INFO_ENTRY and return the size. Just return the size if DOSIZEONLY is
1053 nonzero. */
1055 static int
1056 write_srccorr (int fileid, dst_file_info_entry file_info_entry,
1057 int dosizeonly)
1059 int src_command_size;
1060 int linesleft = file_info_entry.max_line;
1061 int linestart = file_info_entry.listing_line_start;
1062 int flen = file_info_entry.flen;
1063 int linestodo = 0;
1064 DST_SOURCE_CORR src_header;
1065 DST_SRC_COMMAND src_command;
1066 DST_SRC_COMMAND src_command_sf;
1067 DST_SRC_COMMAND src_command_sl;
1068 DST_SRC_COMMAND src_command_sr;
1069 DST_SRC_COMMAND src_command_dl;
1070 DST_SRC_CMDTRLR src_cmdtrlr;
1071 char buff[256];
1072 int totsize = 0;
1074 if (fileid == 1)
1076 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1077 = DST_K_SOURCE_CORR_HEADER_SIZE + 1 - 1;
1078 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1079 = DST_K_SOURCE;
1080 src_command.dst_b_src_command = DST_K_SRC_FORMFEED;
1082 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1083 "source corr", dosizeonly);
1085 totsize += write_debug_data1 (src_command.dst_b_src_command,
1086 "source_corr (SRC FORMFEED)",
1087 dosizeonly);
1090 src_command_size
1091 = DST_K_SRC_COMMAND_SIZE + flen + DST_K_SRC_CMDTRLR_SIZE;
1092 src_command.dst_b_src_command = DST_K_SRC_DECLFILE;
1093 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length
1094 = src_command_size - 2;
1095 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags = 0;
1096 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid
1097 = fileid;
1098 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt
1099 = file_info_entry.cdt;
1100 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk
1101 = file_info_entry.ebk;
1102 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb
1103 = file_info_entry.ffb;
1104 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo
1105 = file_info_entry.rfo;
1106 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename
1107 = file_info_entry.flen;
1109 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1110 = DST_K_SOURCE_CORR_HEADER_SIZE + src_command_size - 1;
1111 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1112 = DST_K_SOURCE;
1114 src_cmdtrlr.dst_b_src_df_libmodname = 0;
1116 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1117 "source corr", dosizeonly);
1118 totsize += write_debug_data1 (src_command.dst_b_src_command,
1119 "source_corr (DECL SRC FILE)", dosizeonly);
1120 totsize += write_debug_data1
1121 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length,
1122 "source_corr (length)", dosizeonly);
1124 totsize += write_debug_data1
1125 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags,
1126 "source_corr (flags)", dosizeonly);
1128 totsize += write_debug_data2
1129 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid,
1130 "source_corr (fileid)", dosizeonly);
1132 totsize += write_debug_data8
1133 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt,
1134 "source_corr (creation date)", dosizeonly);
1136 totsize += write_debug_data4
1137 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk,
1138 "source_corr (EOF block number)", dosizeonly);
1140 totsize += write_debug_data2
1141 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb,
1142 "source_corr (first free byte)", dosizeonly);
1144 totsize += write_debug_data1
1145 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo,
1146 "source_corr (record and file organization)", dosizeonly);
1148 totsize += write_debug_data1
1149 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename,
1150 "source_corr (filename length)", dosizeonly);
1152 totsize += write_debug_string (file_info_entry.file_name,
1153 "source file name", dosizeonly);
1154 totsize += write_debug_data1 (src_cmdtrlr.dst_b_src_df_libmodname,
1155 "source_corr (libmodname)", dosizeonly);
1157 src_command_sf.dst_b_src_command = DST_K_SRC_SETFILE;
1158 src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword = fileid;
1160 src_command_sr.dst_b_src_command = DST_K_SRC_SETREC_W;
1161 src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword = 1;
1163 src_command_sl.dst_b_src_command = DST_K_SRC_SETLNUM_L;
1164 src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong = linestart + 1;
1166 src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1168 if (linesleft > 65534)
1169 linesleft = linesleft - 65534, linestodo = 65534;
1170 else
1171 linestodo = linesleft, linesleft = 0;
1173 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1175 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1176 = DST_K_SOURCE_CORR_HEADER_SIZE + 3 + 3 + 5 + 3 - 1;
1177 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1178 = DST_K_SOURCE;
1180 if (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword)
1182 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1183 "source corr", dosizeonly);
1185 totsize += write_debug_data1 (src_command_sf.dst_b_src_command,
1186 "source_corr (src setfile)", dosizeonly);
1188 totsize += write_debug_data2
1189 (src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword,
1190 "source_corr (fileid)", dosizeonly);
1192 totsize += write_debug_data1 (src_command_sr.dst_b_src_command,
1193 "source_corr (setrec)", dosizeonly);
1195 totsize += write_debug_data2
1196 (src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword,
1197 "source_corr (recnum)", dosizeonly);
1199 totsize += write_debug_data1 (src_command_sl.dst_b_src_command,
1200 "source_corr (setlnum)", dosizeonly);
1202 totsize += write_debug_data4
1203 (src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong,
1204 "source_corr (linenum)", dosizeonly);
1206 totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1207 "source_corr (deflines)", dosizeonly);
1209 sprintf (buff, "source_corr (%d)",
1210 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1211 totsize += write_debug_data2
1212 (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
1213 buff, dosizeonly);
1215 while (linesleft > 0)
1217 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1218 = DST_K_SOURCE_CORR_HEADER_SIZE + 3 - 1;
1219 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1220 = DST_K_SOURCE;
1221 src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1223 if (linesleft > 65534)
1224 linesleft = linesleft - 65534, linestodo = 65534;
1225 else
1226 linestodo = linesleft, linesleft = 0;
1228 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1230 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1231 "source corr", dosizeonly);
1232 totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1233 "source_corr (deflines)", dosizeonly);
1234 sprintf (buff, "source_corr (%d)",
1235 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1236 totsize += write_debug_data2
1237 (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
1238 buff, dosizeonly);
1242 return totsize;
1245 /* Output all the source correlation entries and return the size. Just return
1246 the size if DOSIZEONLY is nonzero. */
1248 static int
1249 write_srccorrs (int dosizeonly)
1251 unsigned int i;
1252 int totsize = 0;
1254 for (i = 1; i < file_info_table_in_use; i++)
1255 totsize += write_srccorr (i, file_info_table[i], dosizeonly);
1257 return totsize;
1260 /* Output a marker (i.e. a label) for the beginning of a function, before
1261 the prologue. */
1263 static void
1264 vmsdbgout_begin_prologue (unsigned int line, const char *file)
1266 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1268 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1269 (*dwarf2_debug_hooks.begin_prologue) (line, file);
1271 if (debug_info_level > DINFO_LEVEL_NONE)
1273 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1274 current_function_funcdef_no);
1275 ASM_OUTPUT_LABEL (asm_out_file, label);
1279 /* Output a marker (i.e. a label) for the beginning of a function, after
1280 the prologue. */
1282 static void
1283 vmsdbgout_end_prologue (unsigned int line, const char *file)
1285 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1287 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1288 (*dwarf2_debug_hooks.end_prologue) (line, file);
1290 if (debug_info_level > DINFO_LEVEL_TERSE)
1292 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_PROLOG_LABEL,
1293 current_function_funcdef_no);
1294 ASM_OUTPUT_LABEL (asm_out_file, label);
1296 /* VMS PCA expects every PC range to correlate to some line and file. */
1297 vmsdbgout_source_line (line, file);
1301 /* No output for VMS debug, but make obligatory call to Dwarf2 debug */
1303 static void
1304 vmsdbgout_end_function (unsigned int line)
1306 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1307 (*dwarf2_debug_hooks.end_function) (line);
1310 /* Output a marker (i.e. a label) for the absolute end of the generated code
1311 for a function definition. This gets called *after* the epilogue code has
1312 been generated. */
1314 static void
1315 vmsdbgout_end_epilogue (unsigned int line, const char *file)
1317 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1319 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1320 (*dwarf2_debug_hooks.end_epilogue) (line, file);
1322 if (debug_info_level > DINFO_LEVEL_NONE)
1324 /* Output a label to mark the endpoint of the code generated for this
1325 function. */
1326 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1327 current_function_funcdef_no);
1328 ASM_OUTPUT_LABEL (asm_out_file, label);
1330 /* VMS PCA expects every PC range to correlate to some line and file. */
1331 vmsdbgout_source_line (line, file);
1335 /* Output a marker (i.e. a label) for the beginning of the generated code for
1336 a lexical block. */
1338 static void
1339 vmsdbgout_begin_block (register unsigned line, register unsigned blocknum)
1341 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1342 (*dwarf2_debug_hooks.begin_block) (line, blocknum);
1344 if (debug_info_level > DINFO_LEVEL_TERSE)
1345 targetm.asm_out.internal_label (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
1348 /* Output a marker (i.e. a label) for the end of the generated code for a
1349 lexical block. */
1351 static void
1352 vmsdbgout_end_block (register unsigned line, register unsigned blocknum)
1354 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1355 (*dwarf2_debug_hooks.end_block) (line, blocknum);
1357 if (debug_info_level > DINFO_LEVEL_TERSE)
1358 targetm.asm_out.internal_label (asm_out_file, BLOCK_END_LABEL, blocknum);
1361 /* Not implemented in VMS Debug. */
1363 static bool
1364 vmsdbgout_ignore_block (tree block)
1366 bool retval = 0;
1368 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1369 retval = (*dwarf2_debug_hooks.ignore_block) (block);
1371 return retval;
1374 /* Add an entry for function DECL into the func_table. */
1376 static void
1377 vmsdbgout_begin_function (tree decl)
1379 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1380 vms_func_ref fde;
1382 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1383 (*dwarf2_debug_hooks.begin_function) (decl);
1385 if (func_table_in_use == func_table_allocated)
1387 func_table_allocated += FUNC_TABLE_INCREMENT;
1388 func_table
1389 = (vms_func_ref) xrealloc (func_table,
1390 func_table_allocated * sizeof (vms_func_node));
1393 /* Add the new entry to the end of the function name table. */
1394 fde = &func_table[func_table_in_use++];
1395 fde->vms_func_name = xstrdup (name);
1396 fde->funcdef_number = current_function_funcdef_no;
1400 static char fullname_buff [4096];
1402 /* Return the full file specification for FILENAME. The specification must be
1403 in VMS syntax in order to be processed by VMS Debug. */
1405 static char *
1406 full_name (const char *filename)
1408 #ifdef VMS
1409 FILE *fp = fopen (filename, "r");
1411 fgetname (fp, fullname_buff, 1);
1412 fclose (fp);
1413 #else
1414 getcwd (fullname_buff, sizeof (fullname_buff));
1416 strcat (fullname_buff, "/");
1417 strcat (fullname_buff, filename);
1419 /* ??? Insert hairy code here to translate Unix style file specification
1420 to VMS style. */
1421 #endif
1423 return fullname_buff;
1426 /* Lookup a filename (in the list of filenames that we know about here in
1427 vmsdbgout.c) and return its "index". The index of each (known) filename is
1428 just a unique number which is associated with only that one filename. We
1429 need such numbers for the sake of generating labels and references
1430 to those files numbers. If the filename given as an argument is not
1431 found in our current list, add it to the list and assign it the next
1432 available unique index number. In order to speed up searches, we remember
1433 the index of the filename was looked up last. This handles the majority of
1434 all searches. */
1436 static unsigned int
1437 lookup_filename (const char *file_name)
1439 static unsigned int last_file_lookup_index = 0;
1440 register char *fn;
1441 register unsigned i;
1442 char *fnam;
1443 long long cdt;
1444 long ebk;
1445 short ffb;
1446 char rfo;
1447 char flen;
1448 struct stat statbuf;
1450 if (stat (file_name, &statbuf) == 0)
1452 long gmtoff;
1453 #ifdef VMS
1454 struct tm *ts;
1456 /* Adjust for GMT. */
1457 ts = (struct tm *) localtime (&statbuf.st_ctime);
1458 gmtoff = ts->tm_gmtoff;
1460 /* VMS has multiple file format types. */
1461 rfo = statbuf.st_fab_rfm;
1462 #else
1463 /* Is GMT adjustment an issue with a cross-compiler? */
1464 gmtoff = 0;
1466 /* Assume stream LF type file. */
1467 rfo = 2;
1468 #endif
1469 cdt = 10000000 * (statbuf.st_ctime + gmtoff + vms_epoch_offset);
1470 ebk = statbuf.st_size / 512 + 1;
1471 ffb = statbuf.st_size - ((statbuf.st_size / 512) * 512);
1472 fnam = full_name (file_name);
1473 flen = strlen (fnam);
1475 else
1477 cdt = 0;
1478 ebk = 0;
1479 ffb = 0;
1480 rfo = 0;
1481 fnam = (char *) "";
1482 flen = 0;
1485 /* Check to see if the file name that was searched on the previous call
1486 matches this file name. If so, return the index. */
1487 if (last_file_lookup_index != 0)
1489 fn = file_info_table[last_file_lookup_index].file_name;
1490 if (strcmp (fnam, fn) == 0)
1491 return last_file_lookup_index;
1494 /* Didn't match the previous lookup, search the table */
1495 for (i = 1; i < file_info_table_in_use; ++i)
1497 fn = file_info_table[i].file_name;
1498 if (strcmp (fnam, fn) == 0)
1500 last_file_lookup_index = i;
1501 return i;
1505 /* Prepare to add a new table entry by making sure there is enough space in
1506 the table to do so. If not, expand the current table. */
1507 if (file_info_table_in_use == file_info_table_allocated)
1510 file_info_table_allocated += FILE_TABLE_INCREMENT;
1511 file_info_table = xrealloc (file_info_table,
1512 (file_info_table_allocated
1513 * sizeof (dst_file_info_entry)));
1516 /* Add the new entry to the end of the filename table. */
1517 file_info_table[file_info_table_in_use].file_name = xstrdup (fnam);
1518 file_info_table[file_info_table_in_use].max_line = 0;
1519 file_info_table[file_info_table_in_use].cdt = cdt;
1520 file_info_table[file_info_table_in_use].ebk = ebk;
1521 file_info_table[file_info_table_in_use].ffb = ffb;
1522 file_info_table[file_info_table_in_use].rfo = rfo;
1523 file_info_table[file_info_table_in_use].flen = flen;
1525 last_file_lookup_index = file_info_table_in_use++;
1526 return last_file_lookup_index;
1529 /* Output a label to mark the beginning of a source code line entry
1530 and record information relating to this source line, in
1531 'line_info_table' for later output of the .debug_line section. */
1533 static void
1534 vmsdbgout_source_line (register unsigned line, register const char *filename)
1536 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1537 (*dwarf2_debug_hooks.source_line) (line, filename);
1539 if (debug_info_level >= DINFO_LEVEL_TERSE)
1541 dst_line_info_ref line_info;
1543 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
1544 line_info_table_in_use);
1546 /* Expand the line info table if necessary. */
1547 if (line_info_table_in_use == line_info_table_allocated)
1549 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
1550 line_info_table = xrealloc (line_info_table,
1551 (line_info_table_allocated
1552 * sizeof (dst_line_info_entry)));
1555 /* Add the new entry at the end of the line_info_table. */
1556 line_info = &line_info_table[line_info_table_in_use++];
1557 line_info->dst_file_num = lookup_filename (filename);
1558 line_info->dst_line_num = line;
1559 if (line > file_info_table[line_info->dst_file_num].max_line)
1560 file_info_table[line_info->dst_file_num].max_line = line;
1564 /* Record the beginning of a new source file, for later output.
1565 At present, unimplemented. */
1567 static void
1568 vmsdbgout_start_source_file (unsigned int lineno, const char *filename)
1570 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1571 (*dwarf2_debug_hooks.start_source_file) (lineno, filename);
1574 /* Record the end of a source file, for later output.
1575 At present, unimplemented. */
1577 static void
1578 vmsdbgout_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
1580 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1581 (*dwarf2_debug_hooks.end_source_file) (lineno);
1584 /* Set up for Debug output at the start of compilation. */
1586 static void
1587 vmsdbgout_init (const char *main_input_filename)
1589 const char *language_string = lang_hooks.name;
1591 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1592 (*dwarf2_debug_hooks.init) (main_input_filename);
1594 if (debug_info_level == DINFO_LEVEL_NONE)
1595 return;
1597 /* Remember the name of the primary input file. */
1598 primary_filename = main_input_filename;
1600 /* Allocate the initial hunk of the file_info_table. */
1601 file_info_table
1602 = xcalloc (FILE_TABLE_INCREMENT, sizeof (dst_file_info_entry));
1603 file_info_table_allocated = FILE_TABLE_INCREMENT;
1605 /* Skip the first entry - file numbers begin at 1 */
1606 file_info_table_in_use = 1;
1608 func_table = (vms_func_ref) xcalloc (FUNC_TABLE_INCREMENT, sizeof (vms_func_node));
1609 func_table_allocated = FUNC_TABLE_INCREMENT;
1610 func_table_in_use = 1;
1612 /* Allocate the initial hunk of the line_info_table. */
1613 line_info_table
1614 = xcalloc (LINE_INFO_TABLE_INCREMENT, sizeof (dst_line_info_entry));
1615 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
1616 /* zero-th entry is allocated, but unused */
1617 line_info_table_in_use = 1;
1619 lookup_filename (primary_filename);
1621 if (!strcmp (language_string, "GNU C"))
1622 module_language = DST_K_C;
1623 else if (!strcmp (language_string, "GNU C++"))
1624 module_language = DST_K_CXX;
1625 else if (!strcmp (language_string, "GNU Ada"))
1626 module_language = DST_K_ADA;
1627 else if (!strcmp (language_string, "GNU F77"))
1628 module_language = DST_K_FORTRAN;
1629 else
1630 module_language = DST_K_UNKNOWN;
1632 module_producer = concat (language_string, " ", version_string, NULL);
1634 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
1638 /* Not implemented in VMS Debug. */
1640 static void
1641 vmsdbgout_define (unsigned int lineno, const char *buffer)
1643 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1644 (*dwarf2_debug_hooks.define) (lineno, buffer);
1647 /* Not implemented in VMS Debug. */
1649 static void
1650 vmsdbgout_undef (unsigned int lineno, const char *buffer)
1652 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1653 (*dwarf2_debug_hooks.undef) (lineno, buffer);
1656 /* Not implemented in VMS Debug. */
1658 static void
1659 vmsdbgout_decl (tree decl)
1661 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1662 (*dwarf2_debug_hooks.function_decl) (decl);
1665 /* Not implemented in VMS Debug. */
1667 static void
1668 vmsdbgout_global_decl (tree decl)
1670 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1671 (*dwarf2_debug_hooks.global_decl) (decl);
1674 /* Not implemented in VMS Debug. */
1676 static void
1677 vmsdbgout_abstract_function (tree decl)
1679 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1680 (*dwarf2_debug_hooks.outlining_inline_function) (decl);
1683 /* Output stuff that Debug requires at the end of every file and generate the
1684 VMS Debug debugging info. */
1686 static void
1687 vmsdbgout_finish (const char *main_input_filename ATTRIBUTE_UNUSED)
1689 unsigned int i;
1690 int totsize;
1692 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1693 (*dwarf2_debug_hooks.finish) (main_input_filename);
1695 if (debug_info_level == DINFO_LEVEL_NONE)
1696 return;
1698 /* Output a terminator label for the .text section. */
1699 text_section ();
1700 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
1702 /* Output debugging information.
1703 Warning! Do not change the name of the .vmsdebug section without
1704 changing it in the assembler also. */
1705 named_section (NULL_TREE, ".vmsdebug", 0);
1706 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1708 totsize = write_modbeg (1);
1709 for (i = 1; i < func_table_in_use; i++)
1711 totsize += write_rtnbeg (i, 1);
1712 totsize += write_rtnend (i, 1);
1714 totsize += write_pclines (1);
1716 write_modbeg (0);
1717 for (i = 1; i < func_table_in_use; i++)
1719 write_rtnbeg (i, 0);
1720 write_rtnend (i, 0);
1722 write_pclines (0);
1724 if (debug_info_level > DINFO_LEVEL_TERSE)
1726 totsize = write_srccorrs (1);
1727 write_srccorrs (0);
1730 totsize = write_modend (1);
1731 write_modend (0);
1733 #endif /* VMS_DEBUGGING_INFO */