1 /* Output VMS debug format symbol table information from GCC.
2 Copyright (C) 1987-2014 Free Software Foundation, Inc.
3 Contributed by Douglas B. Rupp (rupp@gnat.com).
4 Updated by Bernard W. Giroud (bgiroud@users.sourceforge.net).
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
27 #ifdef VMS_DEBUGGING_INFO
36 #include "langhooks.h"
40 /* Difference in seconds between the VMS Epoch and the Unix Epoch */
41 static const long long vms_epoch_offset
= 3506716800ll;
43 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
45 /* NOTE: In the comments in this file, many references are made to "Debug
46 Symbol Table". This term is abbreviated as `DST' throughout the remainder
49 typedef struct dst_line_info_struct
*dst_line_info_ref
;
51 /* Each entry in the line_info_table maintains the file and
52 line number associated with the label generated for that
53 entry. The label gives the PC value associated with
54 the line number entry. */
55 typedef struct dst_line_info_struct
57 unsigned long dst_file_num
;
58 unsigned long dst_line_num
;
62 typedef struct dst_file_info_struct
*dst_file_info_ref
;
64 typedef struct dst_file_info_struct
67 unsigned int max_line
;
68 unsigned int listing_line_start
;
76 /* Maximum size (in bytes) of an artificially generated label. */
77 #define MAX_ARTIFICIAL_LABEL_BYTES 30
79 /* Make sure we know the sizes of the various types debug can describe. These
80 are only defaults. If the sizes are different for your target, you should
81 override these values by defining the appropriate symbols in your tm.h
84 #define PTR_SIZE 4 /* Must be 32 bits for VMS debug info */
87 /* Pointer to a structure of filenames referenced by this compilation unit. */
88 static dst_file_info_ref file_info_table
;
90 /* Total number of entries in the table (i.e. array) pointed to by
91 `file_info_table'. This is the *total* and includes both used and unused
93 static unsigned int file_info_table_allocated
;
95 /* Number of entries in the file_info_table which are actually in use. */
96 static unsigned int file_info_table_in_use
;
98 /* Size (in elements) of increments by which we may expand the filename
100 #define FILE_TABLE_INCREMENT 64
102 typedef char *char_p
;
104 static vec
<char_p
> funcnam_table
;
105 static vec
<unsigned> funcnum_table
;
106 #define FUNC_TABLE_INITIAL 256
108 /* Local pointer to the name of the main input file. Initialized in
110 static const char *primary_filename
;
112 static char *module_producer
;
113 static unsigned int module_language
;
115 /* A pointer to the base of a table that contains line information
116 for each source code line in .text in the compilation unit. */
117 static dst_line_info_ref line_info_table
;
119 /* Number of elements currently allocated for line_info_table. */
120 static unsigned int line_info_table_allocated
;
122 /* Number of elements in line_info_table currently in use. */
123 static unsigned int line_info_table_in_use
;
125 /* Size (in elements) of increments by which we may expand line_info_table. */
126 #define LINE_INFO_TABLE_INCREMENT 1024
128 /* Forward declarations for functions defined in this file. */
129 static char *full_name (const char *);
130 static unsigned int lookup_filename (const char *);
131 static int write_debug_header (DST_HEADER
*, const char *, int);
132 static int write_debug_addr (const char *, const char *, int);
133 static int write_debug_data1 (unsigned int, const char *, int);
134 static int write_debug_data2 (unsigned int, const char *, int);
135 static int write_debug_data4 (unsigned long, const char *, int);
136 static int write_debug_data8 (unsigned long long, const char *, int);
137 static int write_debug_delta4 (const char *, const char *, const char *, int);
138 static int write_debug_string (const char *, const char *, int);
139 static int write_modbeg (int);
140 static int write_modend (int);
141 static int write_rtnbeg (int, int);
142 static int write_rtnend (int, int);
143 static int write_pclines (int);
144 static int write_srccorr (int, dst_file_info_entry
, int);
145 static int write_srccorrs (int);
147 static void vmsdbgout_init (const char *);
148 static void vmsdbgout_finish (const char *);
149 static void vmsdbgout_assembly_start (void);
150 static void vmsdbgout_define (unsigned int, const char *);
151 static void vmsdbgout_undef (unsigned int, const char *);
152 static void vmsdbgout_start_source_file (unsigned int, const char *);
153 static void vmsdbgout_end_source_file (unsigned int);
154 static void vmsdbgout_begin_block (unsigned int, unsigned int);
155 static void vmsdbgout_end_block (unsigned int, unsigned int);
156 static bool vmsdbgout_ignore_block (const_tree
);
157 static void vmsdbgout_source_line (unsigned int, const char *, int, bool);
158 static void vmsdbgout_write_source_line (unsigned, const char *, int , bool);
159 static void vmsdbgout_begin_prologue (unsigned int, const char *);
160 static void vmsdbgout_end_prologue (unsigned int, const char *);
161 static void vmsdbgout_end_function (unsigned int);
162 static void vmsdbgout_begin_epilogue (unsigned int, const char *);
163 static void vmsdbgout_end_epilogue (unsigned int, const char *);
164 static void vmsdbgout_begin_function (tree
);
165 static void vmsdbgout_decl (tree
);
166 static void vmsdbgout_global_decl (tree
);
167 static void vmsdbgout_type_decl (tree
, int);
168 static void vmsdbgout_abstract_function (tree
);
170 /* The debug hooks structure. */
172 const struct gcc_debug_hooks vmsdbg_debug_hooks
175 vmsdbgout_assembly_start
,
178 vmsdbgout_start_source_file
,
179 vmsdbgout_end_source_file
,
180 vmsdbgout_begin_block
,
182 vmsdbgout_ignore_block
,
183 vmsdbgout_source_line
,
184 vmsdbgout_begin_prologue
,
185 vmsdbgout_end_prologue
,
186 vmsdbgout_begin_epilogue
,
187 vmsdbgout_end_epilogue
,
188 vmsdbgout_begin_function
,
189 vmsdbgout_end_function
,
191 vmsdbgout_global_decl
,
192 vmsdbgout_type_decl
, /* type_decl */
193 debug_nothing_tree_tree_tree_bool
, /* imported_module_or_decl */
194 debug_nothing_tree
, /* deferred_inline_function */
195 vmsdbgout_abstract_function
,
196 debug_nothing_rtx
, /* label */
197 debug_nothing_int
, /* handle_pch */
198 debug_nothing_rtx
, /* var_location */
199 debug_nothing_void
, /* switch_text_section */
200 debug_nothing_tree_tree
, /* set_name */
201 0, /* start_end_main_source_file */
202 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
205 /* Definitions of defaults for assembler-dependent names of various
206 pseudo-ops and section names. */
207 #define VMS_UNALIGNED_SHORT_ASM_OP ".word"
208 #define VMS_UNALIGNED_INT_ASM_OP ".long"
209 #define VMS_UNALIGNED_LONG_ASM_OP ".long"
210 #define VMS_UNALIGNED_DOUBLE_INT_ASM_OP ".quad"
212 #define VMS_ASM_BYTE_OP ".byte"
214 #define NUMBYTES(I) ((I) < 256 ? 1 : (I) < 65536 ? 2 : 4)
216 #define NUMBYTES0(I) ((I) < 128 ? 0 : (I) < 65536 ? 2 : 4)
218 #ifndef UNALIGNED_PTR_ASM_OP
219 #define UNALIGNED_PTR_ASM_OP \
220 (PTR_SIZE == 8 ? VMS_UNALIGNED_DOUBLE_INT_ASM_OP : VMS_UNALIGNED_INT_ASM_OP)
223 #ifndef UNALIGNED_OFFSET_ASM_OP
224 #define UNALIGNED_OFFSET_ASM_OP(OFFSET) \
225 (NUMBYTES (OFFSET) == 4 \
226 ? VMS_UNALIGNED_LONG_ASM_OP \
227 : (NUMBYTES (OFFSET) == 2 ? VMS_UNALIGNED_SHORT_ASM_OP : VMS_ASM_BYTE_OP))
230 /* Definitions of defaults for formats and names of various special
231 (artificial) labels which may be generated within this file (when the -g
232 options is used and VMS_DEBUGGING_INFO is in effect. If necessary, these
233 may be overridden from within the tm.h file, but typically, overriding these
234 defaults is unnecessary. */
236 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
238 #ifndef TEXT_END_LABEL
239 #define TEXT_END_LABEL "Lvetext"
241 #ifndef FUNC_BEGIN_LABEL
242 #define FUNC_BEGIN_LABEL "LVFB"
244 #ifndef FUNC_PROLOG_LABEL
245 #define FUNC_PROLOG_LABEL "LVFP"
247 #ifndef FUNC_EPILOG_LABEL
248 #define FUNC_EPILOG_LABEL "LVEB"
250 #ifndef FUNC_END_LABEL
251 #define FUNC_END_LABEL "LVFE"
253 #ifndef BLOCK_BEGIN_LABEL
254 #define BLOCK_BEGIN_LABEL "LVBB"
256 #ifndef BLOCK_END_LABEL
257 #define BLOCK_END_LABEL "LVBE"
259 #ifndef LINE_CODE_LABEL
260 #define LINE_CODE_LABEL "LVM"
263 #ifndef ASM_OUTPUT_DEBUG_DELTA2
264 #define ASM_OUTPUT_DEBUG_DELTA2(FILE,LABEL1,LABEL2) \
267 fprintf ((FILE), "\t%s\t", VMS_UNALIGNED_SHORT_ASM_OP); \
268 assemble_name (FILE, LABEL1); \
269 fprintf (FILE, "-"); \
270 assemble_name (FILE, LABEL2); \
275 #ifndef ASM_OUTPUT_DEBUG_DELTA4
276 #define ASM_OUTPUT_DEBUG_DELTA4(FILE,LABEL1,LABEL2) \
279 fprintf ((FILE), "\t%s\t", VMS_UNALIGNED_INT_ASM_OP); \
280 assemble_name (FILE, LABEL1); \
281 fprintf (FILE, "-"); \
282 assemble_name (FILE, LABEL2); \
287 #ifndef ASM_OUTPUT_DEBUG_ADDR_DELTA
288 #define ASM_OUTPUT_DEBUG_ADDR_DELTA(FILE,LABEL1,LABEL2) \
291 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
292 assemble_name (FILE, LABEL1); \
293 fprintf (FILE, "-"); \
294 assemble_name (FILE, LABEL2); \
299 #ifndef ASM_OUTPUT_DEBUG_ADDR
300 #define ASM_OUTPUT_DEBUG_ADDR(FILE,LABEL) \
303 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
304 assemble_name (FILE, LABEL); \
309 #ifndef ASM_OUTPUT_DEBUG_ADDR_CONST
310 #define ASM_OUTPUT_DEBUG_ADDR_CONST(FILE,ADDR) \
311 fprintf ((FILE), "\t%s\t%s", UNALIGNED_PTR_ASM_OP, (ADDR))
314 #ifndef ASM_OUTPUT_DEBUG_DATA1
315 #define ASM_OUTPUT_DEBUG_DATA1(FILE,VALUE) \
316 fprintf ((FILE), "\t%s\t%#x", VMS_ASM_BYTE_OP, (unsigned char) VALUE)
319 #ifndef ASM_OUTPUT_DEBUG_DATA2
320 #define ASM_OUTPUT_DEBUG_DATA2(FILE,VALUE) \
321 fprintf ((FILE), "\t%s\t%#x", VMS_UNALIGNED_SHORT_ASM_OP, \
322 (unsigned short) VALUE)
325 #ifndef ASM_OUTPUT_DEBUG_DATA4
326 #define ASM_OUTPUT_DEBUG_DATA4(FILE,VALUE) \
327 fprintf ((FILE), "\t%s\t%#lx", VMS_UNALIGNED_INT_ASM_OP, \
328 (unsigned long) VALUE)
331 #ifndef ASM_OUTPUT_DEBUG_DATA
332 #define ASM_OUTPUT_DEBUG_DATA(FILE,VALUE) \
333 fprintf ((FILE), "\t%s\t%#lx", UNALIGNED_OFFSET_ASM_OP (VALUE), VALUE)
336 #ifndef ASM_OUTPUT_DEBUG_ADDR_DATA
337 #define ASM_OUTPUT_DEBUG_ADDR_DATA(FILE,VALUE) \
338 fprintf ((FILE), "\t%s\t%#lx", UNALIGNED_PTR_ASM_OP, \
339 (unsigned long) VALUE)
342 #ifndef ASM_OUTPUT_DEBUG_DATA8
343 #define ASM_OUTPUT_DEBUG_DATA8(FILE,VALUE) \
344 fprintf ((FILE), "\t%s\t%#llx", VMS_UNALIGNED_DOUBLE_INT_ASM_OP, \
345 (unsigned long long) VALUE)
348 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
349 newline is produced. When flag_verbose_asm is asserted, we add commentary
350 at the end of the line, so we must avoid output of a newline here. */
351 #ifndef ASM_OUTPUT_DEBUG_STRING
352 #define ASM_OUTPUT_DEBUG_STRING(FILE,P) \
355 register int slen = strlen (P); \
356 register const char *p = (P); \
358 fprintf (FILE, "\t.ascii \""); \
359 for (i = 0; i < slen; i++) \
361 register int c = p[i]; \
362 if (c == '\"' || c == '\\') \
364 if (c >= ' ' && c < 0177) \
367 fprintf (FILE, "\\%o", c); \
369 fprintf (FILE, "\""); \
374 /* Convert a reference to the assembler name of a C-level name. This
375 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
376 a string rather than writing to a file. */
377 #ifndef ASM_NAME_TO_STRING
378 #define ASM_NAME_TO_STRING(STR, NAME) \
381 if ((NAME)[0] == '*') \
382 strcpy (STR, NAME+1); \
384 strcpy (STR, NAME); \
390 /* Output the debug header HEADER. Also output COMMENT if flag_verbose_asm is
391 set. Return the header size. Just return the size if DOSIZEONLY is
395 write_debug_header (DST_HEADER
*header
, const char *comment
, int dosizeonly
)
399 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file
,
400 header
->dst__header_length
.dst_w_length
);
402 if (flag_verbose_asm
)
403 fprintf (asm_out_file
, "\t%s record length", ASM_COMMENT_START
);
404 fputc ('\n', asm_out_file
);
406 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file
,
407 header
->dst__header_type
.dst_w_type
);
409 if (flag_verbose_asm
)
410 fprintf (asm_out_file
, "\t%s record type (%s)", ASM_COMMENT_START
,
413 fputc ('\n', asm_out_file
);
419 /* Output the address of SYMBOL. Also output COMMENT if flag_verbose_asm is
420 set. Return the address size. Just return the size if DOSIZEONLY is
424 write_debug_addr (const char *symbol
, const char *comment
, int dosizeonly
)
428 ASM_OUTPUT_DEBUG_ADDR (asm_out_file
, symbol
);
429 if (flag_verbose_asm
)
430 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
, comment
);
431 fputc ('\n', asm_out_file
);
437 /* Output the single byte DATA1. Also output COMMENT if flag_verbose_asm is
438 set. Return the data size. Just return the size if DOSIZEONLY is
442 write_debug_data1 (unsigned int data1
, const char *comment
, int dosizeonly
)
446 ASM_OUTPUT_DEBUG_DATA1 (asm_out_file
, data1
);
447 if (flag_verbose_asm
)
448 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
, comment
);
449 fputc ('\n', asm_out_file
);
455 /* Output the single word DATA2. Also output COMMENT if flag_verbose_asm is
456 set. Return the data size. Just return the size if DOSIZEONLY is
460 write_debug_data2 (unsigned int data2
, const char *comment
, int dosizeonly
)
464 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file
, data2
);
465 if (flag_verbose_asm
)
466 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
, comment
);
467 fputc ('\n', asm_out_file
);
473 /* Output double word DATA4. Also output COMMENT if flag_verbose_asm is set.
474 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
477 write_debug_data4 (unsigned long data4
, const char *comment
, int dosizeonly
)
481 ASM_OUTPUT_DEBUG_DATA4 (asm_out_file
, data4
);
482 if (flag_verbose_asm
)
483 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
, comment
);
484 fputc ('\n', asm_out_file
);
490 /* Output quad word DATA8. Also output COMMENT if flag_verbose_asm is set.
491 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
494 write_debug_data8 (unsigned long long data8
, const char *comment
,
499 ASM_OUTPUT_DEBUG_DATA8 (asm_out_file
, data8
);
500 if (flag_verbose_asm
)
501 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
, comment
);
502 fputc ('\n', asm_out_file
);
508 /* Output the difference between LABEL1 and LABEL2. Also output COMMENT if
509 flag_verbose_asm is set. Return the data size. Just return the size if
510 DOSIZEONLY is nonzero. */
513 write_debug_delta4 (const char *label1
, const char *label2
,
514 const char *comment
, int dosizeonly
)
518 ASM_OUTPUT_DEBUG_DELTA4 (asm_out_file
, label1
, label2
);
519 if (flag_verbose_asm
)
520 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
, comment
);
521 fputc ('\n', asm_out_file
);
527 /* Output a character string STRING. Also write COMMENT if flag_verbose_asm is
528 set. Return the string length. Just return the length if DOSIZEONLY is
532 write_debug_string (const char *string
, const char *comment
, int dosizeonly
)
536 ASM_OUTPUT_DEBUG_STRING (asm_out_file
, string
);
537 if (flag_verbose_asm
)
538 fprintf (asm_out_file
, "\t%s %s", ASM_COMMENT_START
, comment
);
539 fputc ('\n', asm_out_file
);
542 return strlen (string
);
545 /* Output a module begin header and return the header size. Just return the
546 size if DOSIZEONLY is nonzero. */
549 write_modbeg (int dosizeonly
)
551 DST_MODULE_BEGIN modbeg
;
554 char *module_name
, *m
;
559 /* Assumes primary filename has Unix syntax file spec. */
560 module_name
= xstrdup (lbasename (primary_filename
));
562 m
= strrchr (module_name
, '.');
566 modnamelen
= strlen (module_name
);
567 for (i
= 0; i
< modnamelen
; i
++)
568 module_name
[i
] = TOUPPER (module_name
[i
]);
570 prodnamelen
= strlen (module_producer
);
572 modbeg
.dst_a_modbeg_header
.dst__header_length
.dst_w_length
573 = DST_K_MODBEG_SIZE
+ modnamelen
+ DST_K_MB_TRLR_SIZE
+ prodnamelen
- 1;
574 modbeg
.dst_a_modbeg_header
.dst__header_type
.dst_w_type
= DST_K_MODBEG
;
575 modbeg
.dst_b_modbeg_flags
.dst_v_modbeg_hide
= 0;
576 modbeg
.dst_b_modbeg_flags
.dst_v_modbeg_version
= 1;
577 modbeg
.dst_b_modbeg_flags
.dst_v_modbeg_unused
= 0;
578 modbeg
.dst_b_modbeg_unused
= 0;
579 modbeg
.dst_l_modbeg_language
= (DST_LANGUAGE
) module_language
;
580 modbeg
.dst_w_version_major
= DST_K_VERSION_MAJOR
;
581 modbeg
.dst_w_version_minor
= DST_K_VERSION_MINOR
;
582 modbeg
.dst_b_modbeg_name
= strlen (module_name
);
584 mb_trlr
.dst_b_compiler
= strlen (module_producer
);
586 totsize
+= write_debug_header (&modbeg
.dst_a_modbeg_header
,
587 "modbeg", dosizeonly
);
588 totsize
+= write_debug_data1 (*((char *) &modbeg
.dst_b_modbeg_flags
),
589 "flags", dosizeonly
);
590 totsize
+= write_debug_data1 (modbeg
.dst_b_modbeg_unused
,
591 "unused", dosizeonly
);
592 totsize
+= write_debug_data4 (modbeg
.dst_l_modbeg_language
,
593 "language", dosizeonly
);
594 totsize
+= write_debug_data2 (modbeg
.dst_w_version_major
,
595 "DST major version", dosizeonly
);
596 totsize
+= write_debug_data2 (modbeg
.dst_w_version_minor
,
597 "DST minor version", dosizeonly
);
598 totsize
+= write_debug_data1 (modbeg
.dst_b_modbeg_name
,
599 "length of module name", dosizeonly
);
600 totsize
+= write_debug_string (module_name
, "module name", dosizeonly
);
601 totsize
+= write_debug_data1 (mb_trlr
.dst_b_compiler
,
602 "length of compiler name", dosizeonly
);
603 totsize
+= write_debug_string (module_producer
, "compiler name", dosizeonly
);
608 /* Output a module end trailer and return the trailer size. Just return
609 the size if DOSIZEONLY is nonzero. */
612 write_modend (int dosizeonly
)
614 DST_MODULE_END modend
;
617 modend
.dst_a_modend_header
.dst__header_length
.dst_w_length
618 = DST_K_MODEND_SIZE
- 1;
619 modend
.dst_a_modend_header
.dst__header_type
.dst_w_type
= DST_K_MODEND
;
621 totsize
+= write_debug_header (&modend
.dst_a_modend_header
, "modend",
627 /* Output a routine begin header routine RTNNUM and return the header size.
628 Just return the size if DOSIZEONLY is nonzero. */
631 write_rtnbeg (int rtnnum
, int dosizeonly
)
637 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
638 DST_ROUTINE_BEGIN rtnbeg
;
641 rtnname
= funcnam_table
[rtnnum
];
642 rtnnamelen
= strlen (rtnname
);
643 rtnentryname
= concat (rtnname
, "..en", NULL
);
645 if (!strcmp (rtnname
, "main"))
648 const char *go
= "TRANSFER$BREAK$GO";
650 /* This command isn't documented in DSTRECORDS, so it's made to
651 look like what DEC C does */
653 /* header size - 1st byte + flag byte + STO_LW size
654 + string count byte + string length */
655 header
.dst__header_length
.dst_w_length
656 = DST_K_DST_HEADER_SIZE
- 1 + 1 + 4 + 1 + strlen (go
);
657 header
.dst__header_type
.dst_w_type
= DST_K_TBG
;
659 totsize
+= write_debug_header (&header
, "transfer", dosizeonly
);
661 /* I think this is a flag byte, but I don't know what this flag means */
662 totsize
+= write_debug_data1 (0x1, "flags ???", dosizeonly
);
664 /* Routine Begin PD Address */
665 totsize
+= write_debug_addr (rtnname
, "main procedure descriptor",
667 totsize
+= write_debug_data1 (strlen (go
), "length of main_name",
669 totsize
+= write_debug_string (go
, "main name", dosizeonly
);
672 /* The header length never includes the length byte. */
673 rtnbeg
.dst_a_rtnbeg_header
.dst__header_length
.dst_w_length
674 = DST_K_RTNBEG_SIZE
+ rtnnamelen
- 1;
675 rtnbeg
.dst_a_rtnbeg_header
.dst__header_type
.dst_w_type
= DST_K_RTNBEG
;
676 rtnbeg
.dst_b_rtnbeg_flags
.dst_v_rtnbeg_unused
= 0;
677 rtnbeg
.dst_b_rtnbeg_flags
.dst_v_rtnbeg_unalloc
= 0;
678 rtnbeg
.dst_b_rtnbeg_flags
.dst_v_rtnbeg_prototype
= 0;
679 rtnbeg
.dst_b_rtnbeg_flags
.dst_v_rtnbeg_inlined
= 0;
680 rtnbeg
.dst_b_rtnbeg_flags
.dst_v_rtnbeg_no_call
= 1;
681 rtnbeg
.dst_b_rtnbeg_name
= rtnnamelen
;
683 totsize
+= write_debug_header (&rtnbeg
.dst_a_rtnbeg_header
, "rtnbeg",
685 totsize
+= write_debug_data1 (*((char *) &rtnbeg
.dst_b_rtnbeg_flags
),
686 "flags", dosizeonly
);
688 /* Routine Begin Address */
689 totsize
+= write_debug_addr (rtnentryname
, "routine entry name", dosizeonly
);
691 /* Routine Begin PD Address */
692 totsize
+= write_debug_addr (rtnname
, "routine procedure descriptor",
695 /* Routine Begin Name */
696 totsize
+= write_debug_data1 (rtnbeg
.dst_b_rtnbeg_name
,
697 "length of routine name", dosizeonly
);
699 totsize
+= write_debug_string (rtnname
, "routine name", dosizeonly
);
703 if (debug_info_level
> DINFO_LEVEL_TERSE
)
705 prolog
.dst_a_prolog_header
.dst__header_length
.dst_w_length
706 = DST_K_PROLOG_SIZE
- 1;
707 prolog
.dst_a_prolog_header
.dst__header_type
.dst_w_type
= DST_K_PROLOG
;
709 totsize
+= write_debug_header (&prolog
.dst_a_prolog_header
, "prolog",
712 ASM_GENERATE_INTERNAL_LABEL
713 (label
, FUNC_PROLOG_LABEL
,
714 funcnum_table
[rtnnum
]);
715 totsize
+= write_debug_addr (label
, "prolog breakpoint addr",
722 /* Output a routine end trailer for routine RTNNUM and return the header size.
723 Just return the size if DOSIZEONLY is nonzero. */
726 write_rtnend (int rtnnum
, int dosizeonly
)
728 DST_ROUTINE_END rtnend
;
729 char label1
[MAX_ARTIFICIAL_LABEL_BYTES
];
730 char label2
[MAX_ARTIFICIAL_LABEL_BYTES
];
735 rtnend
.dst_a_rtnend_header
.dst__header_length
.dst_w_length
736 = DST_K_RTNEND_SIZE
- 1;
737 rtnend
.dst_a_rtnend_header
.dst__header_type
.dst_w_type
= DST_K_RTNEND
;
738 rtnend
.dst_b_rtnend_unused
= 0;
739 rtnend
.dst_l_rtnend_size
= 0; /* Calculated below. */
741 totsize
+= write_debug_header (&rtnend
.dst_a_rtnend_header
, "rtnend",
743 totsize
+= write_debug_data1 (rtnend
.dst_b_rtnend_unused
, "unused",
746 ASM_GENERATE_INTERNAL_LABEL
747 (label1
, FUNC_BEGIN_LABEL
,
748 funcnum_table
[rtnnum
]);
749 ASM_GENERATE_INTERNAL_LABEL
750 (label2
, FUNC_END_LABEL
,
751 funcnum_table
[rtnnum
]);
752 totsize
+= write_debug_delta4 (label2
, label1
, "routine size", dosizeonly
);
757 #define K_DELTA_PC(I) \
758 ((I) < 128 ? -(I) : (I) < 65536 ? DST_K_DELTA_PC_W : DST_K_DELTA_PC_L)
760 #define K_SET_LINUM(I) \
761 ((I) < 256 ? DST_K_SET_LINUM_B \
762 : (I) < 65536 ? DST_K_SET_LINUM : DST_K_SET_LINUM_L)
764 #define K_INCR_LINUM(I) \
765 ((I) < 256 ? DST_K_INCR_LINUM \
766 : (I) < 65536 ? DST_K_INCR_LINUM_W : DST_K_INCR_LINUM_L)
768 /* Output the PC to line number correlations and return the size. Just return
769 the size if DOSIZEONLY is nonzero */
772 write_pclines (int dosizeonly
)
779 DST_LINE_NUM_HEADER line_num
;
780 DST_PCLINE_COMMANDS pcline
;
781 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
782 char lastlabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
786 max_line
= file_info_table
[1].max_line
;
787 file_info_table
[1].listing_line_start
= linestart
;
788 linestart
= linestart
+ ((max_line
/ 100000) + 1) * 100000;
790 for (i
= 2; i
< file_info_table_in_use
; i
++)
792 max_line
= file_info_table
[i
].max_line
;
793 file_info_table
[i
].listing_line_start
= linestart
;
794 linestart
= linestart
+ ((max_line
/ 10000) + 1) * 10000;
797 /* Set starting address to beginning of text section. */
798 line_num
.dst_a_line_num_header
.dst__header_length
.dst_w_length
= 8;
799 line_num
.dst_a_line_num_header
.dst__header_type
.dst_w_type
= DST_K_LINE_NUM
;
800 pcline
.dst_b_pcline_command
= DST_K_SET_ABS_PC
;
802 totsize
+= write_debug_header (&line_num
.dst_a_line_num_header
,
803 "line_num", dosizeonly
);
804 totsize
+= write_debug_data1 (pcline
.dst_b_pcline_command
,
805 "line_num (SET ABS PC)", dosizeonly
);
811 ASM_OUTPUT_DEBUG_ADDR (asm_out_file
, TEXT_SECTION_ASM_OP
);
812 if (flag_verbose_asm
)
813 fprintf (asm_out_file
, "\t%s line_num", ASM_COMMENT_START
);
814 fputc ('\n', asm_out_file
);
817 fn
= line_info_table
[1].dst_file_num
;
818 ln
= (file_info_table
[fn
].listing_line_start
819 + line_info_table
[1].dst_line_num
);
820 line_num
.dst_a_line_num_header
.dst__header_length
.dst_w_length
= 4 + 4;
821 pcline
.dst_b_pcline_command
= DST_K_SET_LINUM_L
;
823 totsize
+= write_debug_header (&line_num
.dst_a_line_num_header
,
824 "line_num", dosizeonly
);
825 totsize
+= write_debug_data1 (pcline
.dst_b_pcline_command
,
826 "line_num (SET LINUM LONG)", dosizeonly
);
828 sprintf (buff
, "line_num (%d)", ln
? ln
- 1 : 0);
829 totsize
+= write_debug_data4 (ln
? ln
- 1 : 0, buff
, dosizeonly
);
832 strcpy (lastlabel
, TEXT_SECTION_ASM_OP
);
833 for (i
= 1; i
< line_info_table_in_use
; i
++)
837 fn
= line_info_table
[i
].dst_file_num
;
838 ln
= (file_info_table
[fn
].listing_line_start
839 + line_info_table
[i
].dst_line_num
);
842 extrabytes
= 5; /* NUMBYTES (ln - lastln - 1) + 1; */
843 else if (ln
<= lastln
)
844 extrabytes
= 5; /* NUMBYTES (ln - 1) + 1; */
848 line_num
.dst_a_line_num_header
.dst__header_length
.dst_w_length
851 totsize
+= write_debug_header
852 (&line_num
.dst_a_line_num_header
, "line_num", dosizeonly
);
856 int lndif
= ln
- lastln
- 1;
858 /* K_INCR_LINUM (lndif); */
859 pcline
.dst_b_pcline_command
= DST_K_INCR_LINUM_L
;
861 totsize
+= write_debug_data1 (pcline
.dst_b_pcline_command
,
862 "line_num (INCR LINUM LONG)",
865 sprintf (buff
, "line_num (%d)", lndif
);
866 totsize
+= write_debug_data4 (lndif
, buff
, dosizeonly
);
868 else if (ln
<= lastln
)
870 /* K_SET_LINUM (ln-1); */
871 pcline
.dst_b_pcline_command
= DST_K_SET_LINUM_L
;
873 totsize
+= write_debug_data1 (pcline
.dst_b_pcline_command
,
874 "line_num (SET LINUM LONG)",
877 sprintf (buff
, "line_num (%d)", ln
- 1);
878 totsize
+= write_debug_data4 (ln
- 1, buff
, dosizeonly
);
881 pcline
.dst_b_pcline_command
= DST_K_DELTA_PC_L
;
883 totsize
+= write_debug_data1 (pcline
.dst_b_pcline_command
,
884 "line_num (DELTA PC LONG)", dosizeonly
);
886 ASM_GENERATE_INTERNAL_LABEL (label
, LINE_CODE_LABEL
, i
);
887 totsize
+= write_debug_delta4 (label
, lastlabel
, "increment line_num",
891 strcpy (lastlabel
, label
);
897 /* Output a source correlation for file FILEID using information saved in
898 FILE_INFO_ENTRY and return the size. Just return the size if DOSIZEONLY is
902 write_srccorr (int fileid
, dst_file_info_entry file_info_entry
,
905 int src_command_size
;
906 int linesleft
= file_info_entry
.max_line
;
907 int linestart
= file_info_entry
.listing_line_start
;
908 int flen
= strlen (file_info_entry
.file_name
);
910 DST_SOURCE_CORR src_header
;
911 DST_SRC_COMMAND src_command
;
912 DST_SRC_COMMAND src_command_sf
;
913 DST_SRC_COMMAND src_command_sl
;
914 DST_SRC_COMMAND src_command_sr
;
915 DST_SRC_COMMAND src_command_dl
;
916 DST_SRC_CMDTRLR src_cmdtrlr
;
922 src_header
.dst_a_source_corr_header
.dst__header_length
.dst_w_length
923 = DST_K_SOURCE_CORR_HEADER_SIZE
+ 1 - 1;
924 src_header
.dst_a_source_corr_header
.dst__header_type
.dst_w_type
926 src_command
.dst_b_src_command
= DST_K_SRC_FORMFEED
;
928 totsize
+= write_debug_header (&src_header
.dst_a_source_corr_header
,
929 "source corr", dosizeonly
);
931 totsize
+= write_debug_data1 (src_command
.dst_b_src_command
,
932 "source_corr (SRC FORMFEED)",
937 = DST_K_SRC_COMMAND_SIZE
+ flen
+ DST_K_SRC_CMDTRLR_SIZE
;
938 src_command
.dst_b_src_command
= DST_K_SRC_DECLFILE
;
939 src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_b_src_df_length
940 = src_command_size
- 2;
941 src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_b_src_df_flags
= 0;
942 src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_w_src_df_fileid
944 src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_q_src_df_rms_cdt
945 = file_info_entry
.cdt
;
946 src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_l_src_df_rms_ebk
947 = file_info_entry
.ebk
;
948 src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_w_src_df_rms_ffb
949 = file_info_entry
.ffb
;
950 src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_b_src_df_rms_rfo
951 = file_info_entry
.rfo
;
952 src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_b_src_df_filename
955 src_header
.dst_a_source_corr_header
.dst__header_length
.dst_w_length
956 = DST_K_SOURCE_CORR_HEADER_SIZE
+ src_command_size
- 1;
957 src_header
.dst_a_source_corr_header
.dst__header_type
.dst_w_type
960 src_cmdtrlr
.dst_b_src_df_libmodname
= 0;
962 totsize
+= write_debug_header (&src_header
.dst_a_source_corr_header
,
963 "source corr", dosizeonly
);
964 totsize
+= write_debug_data1 (src_command
.dst_b_src_command
,
965 "source_corr (DECL SRC FILE)", dosizeonly
);
966 totsize
+= write_debug_data1
967 (src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_b_src_df_length
,
968 "source_corr (length)", dosizeonly
);
970 totsize
+= write_debug_data1
971 (src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_b_src_df_flags
,
972 "source_corr (flags)", dosizeonly
);
974 totsize
+= write_debug_data2
975 (src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_w_src_df_fileid
,
976 "source_corr (fileid)", dosizeonly
);
978 totsize
+= write_debug_data8
979 (src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_q_src_df_rms_cdt
,
980 "source_corr (creation date)", dosizeonly
);
982 totsize
+= write_debug_data4
983 (src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_l_src_df_rms_ebk
,
984 "source_corr (EOF block number)", dosizeonly
);
986 totsize
+= write_debug_data2
987 (src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_w_src_df_rms_ffb
,
988 "source_corr (first free byte)", dosizeonly
);
990 totsize
+= write_debug_data1
991 (src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_b_src_df_rms_rfo
,
992 "source_corr (record and file organization)", dosizeonly
);
994 totsize
+= write_debug_data1
995 (src_command
.dst_a_src_cmd_fields
.dst_a_src_decl_src
.dst_b_src_df_filename
,
996 "source_corr (filename length)", dosizeonly
);
998 totsize
+= write_debug_string (remap_debug_filename (
999 file_info_entry
.file_name
),
1000 "source file name", dosizeonly
);
1001 totsize
+= write_debug_data1 (src_cmdtrlr
.dst_b_src_df_libmodname
,
1002 "source_corr (libmodname)", dosizeonly
);
1004 src_command_sf
.dst_b_src_command
= DST_K_SRC_SETFILE
;
1005 src_command_sf
.dst_a_src_cmd_fields
.dst_w_src_unsword
= fileid
;
1007 src_command_sr
.dst_b_src_command
= DST_K_SRC_SETREC_W
;
1008 src_command_sr
.dst_a_src_cmd_fields
.dst_w_src_unsword
= 1;
1010 src_command_sl
.dst_b_src_command
= DST_K_SRC_SETLNUM_L
;
1011 src_command_sl
.dst_a_src_cmd_fields
.dst_l_src_unslong
= linestart
+ 1;
1013 src_command_dl
.dst_b_src_command
= DST_K_SRC_DEFLINES_W
;
1015 if (linesleft
> 65534)
1016 linesleft
= linesleft
- 65534, linestodo
= 65534;
1018 linestodo
= linesleft
, linesleft
= 0;
1020 src_command_dl
.dst_a_src_cmd_fields
.dst_w_src_unsword
= linestodo
;
1022 src_header
.dst_a_source_corr_header
.dst__header_length
.dst_w_length
1023 = DST_K_SOURCE_CORR_HEADER_SIZE
+ 3 + 3 + 5 + 3 - 1;
1024 src_header
.dst_a_source_corr_header
.dst__header_type
.dst_w_type
1027 if (src_command_dl
.dst_a_src_cmd_fields
.dst_w_src_unsword
)
1029 totsize
+= write_debug_header (&src_header
.dst_a_source_corr_header
,
1030 "source corr", dosizeonly
);
1032 totsize
+= write_debug_data1 (src_command_sf
.dst_b_src_command
,
1033 "source_corr (src setfile)", dosizeonly
);
1035 totsize
+= write_debug_data2
1036 (src_command_sf
.dst_a_src_cmd_fields
.dst_w_src_unsword
,
1037 "source_corr (fileid)", dosizeonly
);
1039 totsize
+= write_debug_data1 (src_command_sr
.dst_b_src_command
,
1040 "source_corr (setrec)", dosizeonly
);
1042 totsize
+= write_debug_data2
1043 (src_command_sr
.dst_a_src_cmd_fields
.dst_w_src_unsword
,
1044 "source_corr (recnum)", dosizeonly
);
1046 totsize
+= write_debug_data1 (src_command_sl
.dst_b_src_command
,
1047 "source_corr (setlnum)", dosizeonly
);
1049 totsize
+= write_debug_data4
1050 (src_command_sl
.dst_a_src_cmd_fields
.dst_l_src_unslong
,
1051 "source_corr (linenum)", dosizeonly
);
1053 totsize
+= write_debug_data1 (src_command_dl
.dst_b_src_command
,
1054 "source_corr (deflines)", dosizeonly
);
1056 sprintf (buff
, "source_corr (%d)",
1057 src_command_dl
.dst_a_src_cmd_fields
.dst_w_src_unsword
);
1058 totsize
+= write_debug_data2
1059 (src_command_dl
.dst_a_src_cmd_fields
.dst_w_src_unsword
,
1062 while (linesleft
> 0)
1064 src_header
.dst_a_source_corr_header
.dst__header_length
.dst_w_length
1065 = DST_K_SOURCE_CORR_HEADER_SIZE
+ 3 - 1;
1066 src_header
.dst_a_source_corr_header
.dst__header_type
.dst_w_type
1068 src_command_dl
.dst_b_src_command
= DST_K_SRC_DEFLINES_W
;
1070 if (linesleft
> 65534)
1071 linesleft
= linesleft
- 65534, linestodo
= 65534;
1073 linestodo
= linesleft
, linesleft
= 0;
1075 src_command_dl
.dst_a_src_cmd_fields
.dst_w_src_unsword
= linestodo
;
1077 totsize
+= write_debug_header (&src_header
.dst_a_source_corr_header
,
1078 "source corr", dosizeonly
);
1079 totsize
+= write_debug_data1 (src_command_dl
.dst_b_src_command
,
1080 "source_corr (deflines)", dosizeonly
);
1081 sprintf (buff
, "source_corr (%d)",
1082 src_command_dl
.dst_a_src_cmd_fields
.dst_w_src_unsword
);
1083 totsize
+= write_debug_data2
1084 (src_command_dl
.dst_a_src_cmd_fields
.dst_w_src_unsword
,
1092 /* Output all the source correlation entries and return the size. Just return
1093 the size if DOSIZEONLY is nonzero. */
1096 write_srccorrs (int dosizeonly
)
1101 for (i
= 1; i
< file_info_table_in_use
; i
++)
1102 totsize
+= write_srccorr (i
, file_info_table
[i
], dosizeonly
);
1107 /* Output a marker (i.e. a label) for the beginning of a function, before
1111 vmsdbgout_begin_prologue (unsigned int line
, const char *file
)
1113 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1115 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1116 (*dwarf2_debug_hooks
.begin_prologue
) (line
, file
);
1118 if (debug_info_level
> DINFO_LEVEL_NONE
)
1120 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1121 current_function_funcdef_no
);
1122 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1126 /* Output a marker (i.e. a label) for the beginning of a function, after
1130 vmsdbgout_end_prologue (unsigned int line
, const char *file
)
1132 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1134 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1135 (*dwarf2_debug_hooks
.end_prologue
) (line
, file
);
1137 if (debug_info_level
> DINFO_LEVEL_TERSE
)
1139 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_PROLOG_LABEL
,
1140 current_function_funcdef_no
);
1141 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1143 /* VMS PCA expects every PC range to correlate to some line and file. */
1144 vmsdbgout_write_source_line (line
, file
, 0, true);
1148 /* No output for VMS debug, but make obligatory call to Dwarf2 debug */
1151 vmsdbgout_end_function (unsigned int line
)
1153 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1154 (*dwarf2_debug_hooks
.end_function
) (line
);
1157 /* Output a marker (i.e. a label) for the beginning of the epilogue.
1158 This gets called *before* the epilogue code has been generated. */
1161 vmsdbgout_begin_epilogue (unsigned int line
, const char *file
)
1163 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1164 static int save_current_function_funcdef_no
= -1;
1166 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1167 (*dwarf2_debug_hooks
.begin_epilogue
) (line
, file
);
1169 if (debug_info_level
> DINFO_LEVEL_NONE
)
1171 if (save_current_function_funcdef_no
!= current_function_funcdef_no
)
1173 /* Output a label to mark the endpoint of the code generated for this
1175 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_EPILOG_LABEL
,
1176 current_function_funcdef_no
);
1178 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1180 save_current_function_funcdef_no
= current_function_funcdef_no
;
1182 /* VMS PCA expects every PC range to correlate to some line and
1184 vmsdbgout_write_source_line (line
, file
, 0, true);
1189 /* Output a marker (i.e. a label) for the absolute end of the generated code
1190 for a function definition. This gets called *after* the epilogue code has
1194 vmsdbgout_end_epilogue (unsigned int line
, const char *file
)
1196 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1198 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1199 (*dwarf2_debug_hooks
.end_epilogue
) (line
, file
);
1201 if (debug_info_level
> DINFO_LEVEL_NONE
)
1203 /* Output a label to mark the endpoint of the code generated for this
1205 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1206 current_function_funcdef_no
);
1207 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1209 /* VMS PCA expects every PC range to correlate to some line and file. */
1210 vmsdbgout_write_source_line (line
, file
, 0, true);
1214 /* Output a marker (i.e. a label) for the beginning of the generated code for
1218 vmsdbgout_begin_block (register unsigned line
, register unsigned blocknum
)
1220 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1221 (*dwarf2_debug_hooks
.begin_block
) (line
, blocknum
);
1223 if (debug_info_level
> DINFO_LEVEL_TERSE
)
1224 targetm
.asm_out
.internal_label (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
1227 /* Output a marker (i.e. a label) for the end of the generated code for a
1231 vmsdbgout_end_block (register unsigned line
, register unsigned blocknum
)
1233 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1234 (*dwarf2_debug_hooks
.end_block
) (line
, blocknum
);
1236 if (debug_info_level
> DINFO_LEVEL_TERSE
)
1237 targetm
.asm_out
.internal_label (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
1240 /* Not implemented in VMS Debug. */
1243 vmsdbgout_ignore_block (const_tree block
)
1247 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1248 retval
= (*dwarf2_debug_hooks
.ignore_block
) (block
);
1253 /* Add an entry for function DECL into the funcnam_table. */
1256 vmsdbgout_begin_function (tree decl
)
1258 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
1260 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1261 (*dwarf2_debug_hooks
.begin_function
) (decl
);
1263 /* Add the new entry to the end of the function name table. */
1264 funcnam_table
.safe_push (xstrdup (name
));
1265 funcnum_table
.safe_push (current_function_funcdef_no
);
1268 static char fullname_buff
[4096];
1270 /* Return the full file specification for FILENAME. The specification must be
1271 in VMS syntax in order to be processed by VMS Debug. */
1274 full_name (const char *filename
)
1277 FILE *fp
= fopen (filename
, "r");
1279 fgetname (fp
, fullname_buff
, 1);
1282 /* Unix paths really mess up VMS debug. Better to just output the
1284 strcpy (fullname_buff
, filename
);
1287 return fullname_buff
;
1290 /* Lookup a filename (in the list of filenames that we know about here in
1291 vmsdbgout.c) and return its "index". The index of each (known) filename is
1292 just a unique number which is associated with only that one filename. We
1293 need such numbers for the sake of generating labels and references
1294 to those files numbers. If the filename given as an argument is not
1295 found in our current list, add it to the list and assign it the next
1296 available unique index number. In order to speed up searches, we remember
1297 the index of the filename was looked up last. This handles the majority of
1301 lookup_filename (const char *file_name
)
1303 static unsigned int last_file_lookup_index
= 0;
1305 register unsigned i
;
1314 fnam
= full_name (file_name
);
1316 /* Check to see if the file name that was searched on the previous call
1317 matches this file name. If so, return the index. */
1318 if (last_file_lookup_index
!= 0)
1320 fn
= file_info_table
[last_file_lookup_index
].file_name
;
1321 if (strcmp (fnam
, fn
) == 0)
1322 return last_file_lookup_index
;
1325 /* Didn't match the previous lookup, search the table */
1326 for (i
= 1; i
< file_info_table_in_use
; ++i
)
1328 fn
= file_info_table
[i
].file_name
;
1329 if (strcmp (fnam
, fn
) == 0)
1331 last_file_lookup_index
= i
;
1336 /* Prepare to add a new table entry by making sure there is enough space in
1337 the table to do so. If not, expand the current table. */
1338 if (file_info_table_in_use
== file_info_table_allocated
)
1341 file_info_table_allocated
+= FILE_TABLE_INCREMENT
;
1342 file_info_table
= XRESIZEVEC (dst_file_info_entry
, file_info_table
,
1343 file_info_table_allocated
);
1346 if (vms_file_stats_name (file_name
, &cdt
, &siz
, &rfo
, &ver
) == 0)
1348 ebk
= siz
/ 512 + 1;
1349 ffb
= siz
- ((siz
/ 512) * 512);
1352 /* Add the new entry to the end of the filename table. */
1353 file_info_table
[file_info_table_in_use
].file_name
= xstrdup (fnam
);
1354 file_info_table
[file_info_table_in_use
].max_line
= 0;
1355 file_info_table
[file_info_table_in_use
].cdt
= cdt
;
1356 file_info_table
[file_info_table_in_use
].ebk
= ebk
;
1357 file_info_table
[file_info_table_in_use
].ffb
= ffb
;
1358 file_info_table
[file_info_table_in_use
].rfo
= rfo
;
1360 last_file_lookup_index
= file_info_table_in_use
++;
1361 return last_file_lookup_index
;
1364 /* Output a label to mark the beginning of a source code line entry
1365 and record information relating to this source line, in
1366 'line_info_table' for later output of the .debug_line section. */
1369 vmsdbgout_write_source_line (unsigned line
, const char *filename
,
1370 int /* discriminator */, bool /* is_stmt */)
1372 dst_line_info_ref line_info
;
1374 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
,
1375 line_info_table_in_use
);
1377 /* Expand the line info table if necessary. */
1378 if (line_info_table_in_use
== line_info_table_allocated
)
1380 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
1381 line_info_table
= XRESIZEVEC (dst_line_info_entry
, line_info_table
,
1382 line_info_table_allocated
);
1385 /* Add the new entry at the end of the line_info_table. */
1386 line_info
= &line_info_table
[line_info_table_in_use
++];
1387 line_info
->dst_file_num
= lookup_filename (filename
);
1388 line_info
->dst_line_num
= line
;
1389 if (line
> file_info_table
[line_info
->dst_file_num
].max_line
)
1390 file_info_table
[line_info
->dst_file_num
].max_line
= line
;
1394 vmsdbgout_source_line (register unsigned line
, register const char *filename
,
1395 int discriminator
, bool is_stmt
)
1397 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1398 (*dwarf2_debug_hooks
.source_line
) (line
, filename
, discriminator
, is_stmt
);
1400 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
1401 vmsdbgout_write_source_line (line
, filename
, discriminator
, is_stmt
);
1404 /* Record the beginning of a new source file, for later output.
1405 At present, unimplemented. */
1408 vmsdbgout_start_source_file (unsigned int lineno
, const char *filename
)
1410 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1411 (*dwarf2_debug_hooks
.start_source_file
) (lineno
, filename
);
1414 /* Record the end of a source file, for later output.
1415 At present, unimplemented. */
1418 vmsdbgout_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
1420 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1421 (*dwarf2_debug_hooks
.end_source_file
) (lineno
);
1424 /* Set up for Debug output at the start of compilation. */
1427 vmsdbgout_init (const char *filename
)
1429 const char *language_string
= lang_hooks
.name
;
1431 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1432 (*dwarf2_debug_hooks
.init
) (filename
);
1434 if (debug_info_level
== DINFO_LEVEL_NONE
)
1437 /* Remember the name of the primary input file. */
1438 primary_filename
= filename
;
1440 /* Allocate the initial hunk of the file_info_table. */
1441 file_info_table
= XCNEWVEC (dst_file_info_entry
, FILE_TABLE_INCREMENT
);
1442 file_info_table_allocated
= FILE_TABLE_INCREMENT
;
1443 /* Skip the first entry - file numbers begin at 1. */
1444 file_info_table_in_use
= 1;
1446 funcnam_table
.create (FUNC_TABLE_INITIAL
);
1447 funcnum_table
.create (FUNC_TABLE_INITIAL
);
1449 /* Allocate the initial hunk of the line_info_table. */
1450 line_info_table
= XCNEWVEC (dst_line_info_entry
, LINE_INFO_TABLE_INCREMENT
);
1451 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
1452 /* zero-th entry is allocated, but unused */
1453 line_info_table_in_use
= 1;
1455 lookup_filename (primary_filename
);
1457 if (!strcmp (language_string
, "GNU C"))
1458 module_language
= DST_K_C
;
1459 else if (!strcmp (language_string
, "GNU C++"))
1460 module_language
= DST_K_CXX
;
1461 else if (!strcmp (language_string
, "GNU Ada"))
1462 module_language
= DST_K_ADA
;
1463 else if (!strcmp (language_string
, "GNU F77"))
1464 module_language
= DST_K_FORTRAN
;
1466 module_language
= DST_K_UNKNOWN
;
1468 module_producer
= concat (language_string
, " ", version_string
, NULL
);
1470 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
1474 /* Not implemented in VMS Debug. */
1477 vmsdbgout_assembly_start (void)
1479 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1480 (*dwarf2_debug_hooks
.assembly_start
) ();
1483 /* Not implemented in VMS Debug. */
1486 vmsdbgout_define (unsigned int lineno
, const char *buffer
)
1488 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1489 (*dwarf2_debug_hooks
.define
) (lineno
, buffer
);
1492 /* Not implemented in VMS Debug. */
1495 vmsdbgout_undef (unsigned int lineno
, const char *buffer
)
1497 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1498 (*dwarf2_debug_hooks
.undef
) (lineno
, buffer
);
1501 /* Not implemented in VMS Debug. */
1504 vmsdbgout_decl (tree decl
)
1506 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1507 (*dwarf2_debug_hooks
.function_decl
) (decl
);
1510 /* Not implemented in VMS Debug. */
1513 vmsdbgout_global_decl (tree decl
)
1515 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1516 (*dwarf2_debug_hooks
.global_decl
) (decl
);
1519 /* Not implemented in VMS Debug. */
1522 vmsdbgout_type_decl (tree decl
, int local
)
1524 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1525 (*dwarf2_debug_hooks
.type_decl
) (decl
, local
);
1528 /* Not implemented in VMS Debug. */
1531 vmsdbgout_abstract_function (tree decl
)
1533 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1534 (*dwarf2_debug_hooks
.outlining_inline_function
) (decl
);
1537 /* Output stuff that Debug requires at the end of every file and generate the
1538 VMS Debug debugging info. */
1541 vmsdbgout_finish (const char *filename ATTRIBUTE_UNUSED
)
1543 unsigned int i
, ifunc
;
1546 if (write_symbols
== VMS_AND_DWARF2_DEBUG
)
1547 (*dwarf2_debug_hooks
.finish
) (filename
);
1549 if (debug_info_level
== DINFO_LEVEL_NONE
)
1552 /* Output a terminator label for the .text section. */
1553 switch_to_section (text_section
);
1554 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
1556 /* Output debugging information.
1557 Warning! Do not change the name of the .vmsdebug section without
1558 changing it in the assembler also. */
1559 switch_to_section (get_named_section (NULL
, ".vmsdebug", 0));
1560 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
1562 totsize
= write_modbeg (1);
1563 FOR_EACH_VEC_ELT (funcnum_table
, i
, ifunc
)
1565 totsize
+= write_rtnbeg (i
, 1);
1566 totsize
+= write_rtnend (i
, 1);
1568 totsize
+= write_pclines (1);
1571 FOR_EACH_VEC_ELT (funcnum_table
, i
, ifunc
)
1573 write_rtnbeg (i
, 0);
1574 write_rtnend (i
, 0);
1578 if (debug_info_level
> DINFO_LEVEL_TERSE
)
1580 totsize
= write_srccorrs (1);
1584 totsize
= write_modend (1);
1588 /* Need for both Dwarf2 on IVMS and VMS Debug on AVMS */
1591 #define __NEW_STARLET 1
1592 #include <vms/rms.h>
1593 #include <vms/atrdef.h>
1594 #include <vms/fibdef.h>
1595 #include <vms/stsdef.h>
1596 #include <vms/iodef.h>
1597 #include <vms/fatdef.h>
1598 #include <vms/descrip.h>
1599 #include <unixlib.h>
1603 /* descrip.h doesn't have everything ... */
1604 typedef struct fibdef
* __fibdef_ptr32
__attribute__ (( mode (SI
) ));
1605 struct dsc$descriptor_fib
1607 unsigned int fib$l_len
;
1608 __fibdef_ptr32 fib$l_addr
;
1611 /* I/O Status Block. */
1614 unsigned short status
, count
;
1615 unsigned int devdep
;
1618 static char *tryfile
;
1620 /* Variable length string. */
1624 char string
[NAM$C_MAXRSS
+1];
1627 static char filename_buff
[MAXPATH
];
1628 static char vms_filespec
[MAXPATH
];
1630 /* Callback function for filespec style conversion. */
1633 translate_unix (char *name
, int type ATTRIBUTE_UNUSED
)
1635 strncpy (filename_buff
, name
, MAXPATH
);
1636 filename_buff
[MAXPATH
- 1] = (char) 0;
1640 /* Wrapper for DECC function that converts a Unix filespec
1641 to VMS style filespec. */
1644 to_vms_file_spec (char *filespec
)
1646 strncpy (vms_filespec
, "", MAXPATH
);
1647 decc$
to_vms (filespec
, translate_unix
, 1, 1);
1648 strncpy (vms_filespec
, filename_buff
, MAXPATH
);
1650 vms_filespec
[MAXPATH
- 1] = (char) 0;
1652 return vms_filespec
;
1656 #define VMS_EPOCH_OFFSET 35067168000000000LL
1657 #define VMS_GRANULARITY_FACTOR 10000000
1660 /* Return VMS file date, size, format, version given a name. */
1663 vms_file_stats_name (const char *filename
, long long *cdt
, long *siz
, char *rfo
,
1670 unsigned long long create
;
1672 char ascnamebuff
[256];
1676 { ATR$S_CREDATE
, ATR$C_CREDATE
, &create
},
1677 { ATR$S_RECATTR
, ATR$C_RECATTR
, &recattr
},
1678 { ATR$S_ASCNAME
, ATR$C_ASCNAME
, &ascnamebuff
},
1683 struct dsc$descriptor_fib fibdsc
= {sizeof (fib
), (void *) &fib
};
1688 unsigned short chan
;
1690 struct vstring file
;
1691 struct dsc$descriptor_s filedsc
1692 = {NAM$C_MAXRSS
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, (void *) file
.string
};
1693 struct vstring device
;
1694 struct dsc$descriptor_s devicedsc
1695 = {NAM$C_MAXRSS
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, (void *) device
.string
};
1696 struct vstring result
;
1697 struct dsc$descriptor_s resultdsc
1698 = {NAM$C_MAXRSS
, DSC$K_DTYPE_VT
, DSC$K_CLASS_VS
, (void *) result
.string
};
1700 if (strcmp (filename
, "<internal>") == 0
1701 || strcmp (filename
, "<built-in>") == 0)
1718 tryfile
= to_vms_file_spec (filename
);
1720 /* Allocate and initialize a FAB and NAM structures. */
1724 nam
.nam$l_esa
= file
.string
;
1725 nam
.nam$b_ess
= NAM$C_MAXRSS
;
1726 nam
.nam$l_rsa
= result
.string
;
1727 nam
.nam$b_rss
= NAM$C_MAXRSS
;
1728 fab
.fab$l_fna
= tryfile
;
1729 fab
.fab$b_fns
= strlen (tryfile
);
1730 fab
.fab$l_nam
= &nam
;
1732 /* Validate filespec syntax and device existence. */
1733 status
= SYS$
PARSE (&fab
, 0, 0);
1734 if ((status
& 1) != 1)
1737 file
.string
[nam
.nam$b_esl
] = 0;
1739 /* Find matching filespec. */
1740 status
= SYS$
SEARCH (&fab
, 0, 0);
1741 if ((status
& 1) != 1)
1744 file
.string
[nam
.nam$b_esl
] = 0;
1745 result
.string
[result
.length
=nam
.nam$b_rsl
] = 0;
1747 /* Get the device name and assign an IO channel. */
1748 strncpy (device
.string
, nam
.nam$l_dev
, nam
.nam$b_dev
);
1749 devicedsc
.dsc$w_length
= nam
.nam$b_dev
;
1751 status
= SYS$
ASSIGN (&devicedsc
, &chan
, 0, 0, 0);
1752 if ((status
& 1) != 1)
1755 /* Initialize the FIB and fill in the directory id field. */
1756 memset (&fib
, 0, sizeof (fib
));
1757 fib
.fib$w_did
[0] = nam
.nam$w_did
[0];
1758 fib
.fib$w_did
[1] = nam
.nam$w_did
[1];
1759 fib
.fib$w_did
[2] = nam
.nam$w_did
[2];
1760 fib
.fib$l_acctl
= 0;
1762 strcpy (file
.string
, (strrchr (result
.string
, ']') + 1));
1763 filedsc
.dsc$w_length
= strlen (file
.string
);
1764 result
.string
[result
.length
= 0] = 0;
1766 /* Open and close the file to fill in the attributes. */
1768 = SYS$
QIOW (0, chan
, IO$_ACCESS
|IO$M_ACCESS
, &iosb
, 0, 0,
1769 &fibdsc
, &filedsc
, &result
.length
, &resultdsc
, &atrlst
, 0);
1770 if ((status
& 1) != 1)
1772 if ((iosb
.status
& 1) != 1)
1775 result
.string
[result
.length
] = 0;
1776 status
= SYS$
QIOW (0, chan
, IO$_DEACCESS
, &iosb
, 0, 0, &fibdsc
, 0, 0, 0,
1778 if ((status
& 1) != 1)
1780 if ((iosb
.status
& 1) != 1)
1783 /* Deassign the channel and exit. */
1784 status
= SYS$
DASSGN (chan
);
1785 if ((status
& 1) != 1)
1788 if (cdt
) *cdt
= create
;
1789 if (siz
) *siz
= (512 * 65536 * recattr
.fat$w_efblkh
) +
1790 (512 * (recattr
.fat$w_efblkl
- 1)) +
1791 recattr
.fat$w_ffbyte
;
1792 if (rfo
) *rfo
= recattr
.fat$v_rtype
;
1793 if (ver
) *ver
= strtol (strrchr (ascnamebuff
, ';')+1, 0, 10);
1799 if ((stat (filename
, &buff
)) != 0)
1803 *cdt
= (long long) (buff
.st_mtime
* VMS_GRANULARITY_FACTOR
)
1807 *siz
= buff
.st_size
;
1810 *rfo
= 2; /* Stream LF format */