[Ada] Unnesting: properly handle local subprogram in declare blocks
[official-gcc.git] / gcc / vmsdbgout.c
blobad0eac2e7d015be10c0ec50ccf3ac17c69a5f4aa
1 /* Output VMS debug format symbol table information from GCC.
2 Copyright (C) 1987-2018 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
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
27 #ifdef VMS_DEBUGGING_INFO
28 #include "alias.h"
29 #include "tree.h"
30 #include "varasm.h"
31 #include "version.h"
32 #include "flags.h"
33 #include "rtl.h"
34 #include "output.h"
35 #include "vmsdbg.h"
36 #include "debug.h"
37 #include "langhooks.h"
38 #include "function.h"
39 #include "target.h"
40 #include "file-prefix-map.h" /* remap_debug_filename() */
42 /* Difference in seconds between the VMS Epoch and the Unix Epoch */
43 static const long long vms_epoch_offset = 3506716800ll;
45 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
47 /* NOTE: In the comments in this file, many references are made to "Debug
48 Symbol Table". This term is abbreviated as `DST' throughout the remainder
49 of this file. */
51 typedef struct dst_line_info_struct *dst_line_info_ref;
53 /* Each entry in the line_info_table maintains the file and
54 line number associated with the label generated for that
55 entry. The label gives the PC value associated with
56 the line number entry. */
57 typedef struct dst_line_info_struct
59 unsigned long dst_file_num;
60 unsigned long dst_line_num;
62 dst_line_info_entry;
64 typedef struct dst_file_info_struct *dst_file_info_ref;
66 typedef struct dst_file_info_struct
68 char *file_name;
69 unsigned int max_line;
70 unsigned int listing_line_start;
71 long long cdt;
72 long ebk;
73 short ffb;
74 char rfo;
76 dst_file_info_entry;
78 /* Maximum size (in bytes) of an artificially generated label. */
79 #define MAX_ARTIFICIAL_LABEL_BYTES 30
81 /* Make sure we know the sizes of the various types debug can describe. These
82 are only defaults. If the sizes are different for your target, you should
83 override these values by defining the appropriate symbols in your tm.h
84 file. */
85 #ifndef PTR_SIZE
86 #define PTR_SIZE 4 /* Must be 32 bits for VMS debug info */
87 #endif
89 /* Pointer to a structure of filenames referenced by this compilation unit. */
90 static dst_file_info_ref file_info_table;
92 /* Total number of entries in the table (i.e. array) pointed to by
93 `file_info_table'. This is the *total* and includes both used and unused
94 slots. */
95 static unsigned int file_info_table_allocated;
97 /* Number of entries in the file_info_table which are actually in use. */
98 static unsigned int file_info_table_in_use;
100 /* Size (in elements) of increments by which we may expand the filename
101 table. */
102 #define FILE_TABLE_INCREMENT 64
104 typedef char *char_p;
106 static vec<char_p> funcnam_table;
107 static vec<unsigned> funcnum_table;
108 #define FUNC_TABLE_INITIAL 256
110 /* Local pointer to the name of the main input file. Initialized in
111 vmsdbgout_init. */
112 static const char *primary_filename;
114 static char *module_producer;
115 static unsigned int module_language;
117 /* A pointer to the base of a table that contains line information
118 for each source code line in .text in the compilation unit. */
119 static dst_line_info_ref line_info_table;
121 /* Number of elements currently allocated for line_info_table. */
122 static unsigned int line_info_table_allocated;
124 /* Number of elements in line_info_table currently in use. */
125 static unsigned int line_info_table_in_use;
127 /* Size (in elements) of increments by which we may expand line_info_table. */
128 #define LINE_INFO_TABLE_INCREMENT 1024
130 /* Forward declarations for functions defined in this file. */
131 static char *full_name (const char *);
132 static unsigned int lookup_filename (const char *);
133 static int write_debug_header (DST_HEADER *, const char *, int);
134 static int write_debug_addr (const char *, const char *, int);
135 static int write_debug_data1 (unsigned int, const char *, int);
136 static int write_debug_data2 (unsigned int, const char *, int);
137 static int write_debug_data4 (unsigned long, const char *, int);
138 static int write_debug_data8 (unsigned long long, const char *, int);
139 static int write_debug_delta4 (const char *, const char *, const char *, int);
140 static int write_debug_string (const char *, const char *, int);
141 static int write_modbeg (int);
142 static int write_modend (int);
143 static int write_rtnbeg (int, int);
144 static int write_rtnend (int, int);
145 static int write_pclines (int);
146 static int write_srccorr (int, dst_file_info_entry, int);
147 static int write_srccorrs (int);
149 static void vmsdbgout_init (const char *);
150 static void vmsdbgout_finish (const char *);
151 static void vmsdbgout_early_finish (const char *);
152 static void vmsdbgout_assembly_start (void);
153 static void vmsdbgout_define (unsigned int, const char *);
154 static void vmsdbgout_undef (unsigned int, const char *);
155 static void vmsdbgout_start_source_file (unsigned int, const char *);
156 static void vmsdbgout_end_source_file (unsigned int);
157 static void vmsdbgout_begin_block (unsigned int, unsigned int);
158 static void vmsdbgout_end_block (unsigned int, unsigned int);
159 static bool vmsdbgout_ignore_block (const_tree);
160 static void vmsdbgout_source_line (unsigned int, unsigned int, const char *,
161 int, bool);
162 static void vmsdbgout_write_source_line (unsigned, const char *, int , bool);
163 static void vmsdbgout_begin_prologue (unsigned int, unsigned int,
164 const char *);
165 static void vmsdbgout_end_prologue (unsigned int, const char *);
166 static void vmsdbgout_end_function (unsigned int);
167 static void vmsdbgout_begin_epilogue (unsigned int, const char *);
168 static void vmsdbgout_end_epilogue (unsigned int, const char *);
169 static void vmsdbgout_begin_function (tree);
170 static void vmsdbgout_function_decl (tree);
171 static void vmsdbgout_early_global_decl (tree);
172 static void vmsdbgout_late_global_decl (tree);
173 static void vmsdbgout_type_decl (tree, int);
174 static void vmsdbgout_abstract_function (tree);
176 /* The debug hooks structure. */
178 const struct gcc_debug_hooks vmsdbg_debug_hooks
179 = {vmsdbgout_init,
180 vmsdbgout_finish,
181 vmsdbgout_early_finish,
182 vmsdbgout_assembly_start,
183 vmsdbgout_define,
184 vmsdbgout_undef,
185 vmsdbgout_start_source_file,
186 vmsdbgout_end_source_file,
187 vmsdbgout_begin_block,
188 vmsdbgout_end_block,
189 vmsdbgout_ignore_block,
190 vmsdbgout_source_line,
191 vmsdbgout_begin_prologue,
192 vmsdbgout_end_prologue,
193 vmsdbgout_begin_epilogue,
194 vmsdbgout_end_epilogue,
195 vmsdbgout_begin_function,
196 vmsdbgout_end_function,
197 debug_nothing_tree, /* register_main_translation_unit */
198 vmsdbgout_function_decl,
199 vmsdbgout_early_global_decl,
200 vmsdbgout_late_global_decl,
201 vmsdbgout_type_decl, /* type_decl */
202 debug_nothing_tree_tree_tree_bool_bool, /* imported_module_or_decl */
203 debug_false_tree_charstarstar_uhwistar, /* die_ref_for_decl */
204 debug_nothing_tree_charstar_uhwi, /* register_external_die */
205 debug_nothing_tree, /* deferred_inline_function */
206 vmsdbgout_abstract_function,
207 debug_nothing_rtx_code_label, /* label */
208 debug_nothing_int, /* handle_pch */
209 debug_nothing_rtx_insn, /* var_location */
210 debug_nothing_tree, /* inline_entry */
211 debug_nothing_tree, /* size_function */
212 debug_nothing_void, /* switch_text_section */
213 debug_nothing_tree_tree, /* set_name */
214 0, /* start_end_main_source_file */
215 TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
218 /* Definitions of defaults for assembler-dependent names of various
219 pseudo-ops and section names. */
220 #define VMS_UNALIGNED_SHORT_ASM_OP ".word"
221 #define VMS_UNALIGNED_INT_ASM_OP ".long"
222 #define VMS_UNALIGNED_LONG_ASM_OP ".long"
223 #define VMS_UNALIGNED_DOUBLE_INT_ASM_OP ".quad"
225 #define VMS_ASM_BYTE_OP ".byte"
227 #define NUMBYTES(I) ((I) < 256 ? 1 : (I) < 65536 ? 2 : 4)
229 #define NUMBYTES0(I) ((I) < 128 ? 0 : (I) < 65536 ? 2 : 4)
231 #ifndef UNALIGNED_PTR_ASM_OP
232 #define UNALIGNED_PTR_ASM_OP \
233 (PTR_SIZE == 8 ? VMS_UNALIGNED_DOUBLE_INT_ASM_OP : VMS_UNALIGNED_INT_ASM_OP)
234 #endif
236 #ifndef UNALIGNED_OFFSET_ASM_OP
237 #define UNALIGNED_OFFSET_ASM_OP(OFFSET) \
238 (NUMBYTES (OFFSET) == 4 \
239 ? VMS_UNALIGNED_LONG_ASM_OP \
240 : (NUMBYTES (OFFSET) == 2 ? VMS_UNALIGNED_SHORT_ASM_OP : VMS_ASM_BYTE_OP))
241 #endif
243 /* Definitions of defaults for formats and names of various special
244 (artificial) labels which may be generated within this file (when the -g
245 options is used and VMS_DEBUGGING_INFO is in effect. If necessary, these
246 may be overridden from within the tm.h file, but typically, overriding these
247 defaults is unnecessary. */
249 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
251 #ifndef TEXT_END_LABEL
252 #define TEXT_END_LABEL "Lvetext"
253 #endif
254 #ifndef FUNC_BEGIN_LABEL
255 #define FUNC_BEGIN_LABEL "LVFB"
256 #endif
257 #ifndef FUNC_PROLOG_LABEL
258 #define FUNC_PROLOG_LABEL "LVFP"
259 #endif
260 #ifndef FUNC_EPILOG_LABEL
261 #define FUNC_EPILOG_LABEL "LVEB"
262 #endif
263 #ifndef FUNC_END_LABEL
264 #define FUNC_END_LABEL "LVFE"
265 #endif
266 #ifndef BLOCK_BEGIN_LABEL
267 #define BLOCK_BEGIN_LABEL "LVBB"
268 #endif
269 #ifndef BLOCK_END_LABEL
270 #define BLOCK_END_LABEL "LVBE"
271 #endif
272 #ifndef LINE_CODE_LABEL
273 #define LINE_CODE_LABEL "LVM"
274 #endif
276 #ifndef ASM_OUTPUT_DEBUG_DELTA2
277 #define ASM_OUTPUT_DEBUG_DELTA2(FILE,LABEL1,LABEL2) \
278 do \
280 fprintf ((FILE), "\t%s\t", VMS_UNALIGNED_SHORT_ASM_OP); \
281 assemble_name (FILE, LABEL1); \
282 fprintf (FILE, "-"); \
283 assemble_name (FILE, LABEL2); \
285 while (0)
286 #endif
288 #ifndef ASM_OUTPUT_DEBUG_DELTA4
289 #define ASM_OUTPUT_DEBUG_DELTA4(FILE,LABEL1,LABEL2) \
290 do \
292 fprintf ((FILE), "\t%s\t", VMS_UNALIGNED_INT_ASM_OP); \
293 assemble_name (FILE, LABEL1); \
294 fprintf (FILE, "-"); \
295 assemble_name (FILE, LABEL2); \
297 while (0)
298 #endif
300 #ifndef ASM_OUTPUT_DEBUG_ADDR_DELTA
301 #define ASM_OUTPUT_DEBUG_ADDR_DELTA(FILE,LABEL1,LABEL2) \
302 do \
304 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
305 assemble_name (FILE, LABEL1); \
306 fprintf (FILE, "-"); \
307 assemble_name (FILE, LABEL2); \
309 while (0)
310 #endif
312 #ifndef ASM_OUTPUT_DEBUG_ADDR
313 #define ASM_OUTPUT_DEBUG_ADDR(FILE,LABEL) \
314 do \
316 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
317 assemble_name (FILE, LABEL); \
319 while (0)
320 #endif
322 #ifndef ASM_OUTPUT_DEBUG_ADDR_CONST
323 #define ASM_OUTPUT_DEBUG_ADDR_CONST(FILE,ADDR) \
324 fprintf ((FILE), "\t%s\t%s", UNALIGNED_PTR_ASM_OP, (ADDR))
325 #endif
327 #ifndef ASM_OUTPUT_DEBUG_DATA1
328 #define ASM_OUTPUT_DEBUG_DATA1(FILE,VALUE) \
329 fprintf ((FILE), "\t%s\t%#x", VMS_ASM_BYTE_OP, (unsigned char) VALUE)
330 #endif
332 #ifndef ASM_OUTPUT_DEBUG_DATA2
333 #define ASM_OUTPUT_DEBUG_DATA2(FILE,VALUE) \
334 fprintf ((FILE), "\t%s\t%#x", VMS_UNALIGNED_SHORT_ASM_OP, \
335 (unsigned short) VALUE)
336 #endif
338 #ifndef ASM_OUTPUT_DEBUG_DATA4
339 #define ASM_OUTPUT_DEBUG_DATA4(FILE,VALUE) \
340 fprintf ((FILE), "\t%s\t%#lx", VMS_UNALIGNED_INT_ASM_OP, \
341 (unsigned long) VALUE)
342 #endif
344 #ifndef ASM_OUTPUT_DEBUG_DATA
345 #define ASM_OUTPUT_DEBUG_DATA(FILE,VALUE) \
346 fprintf ((FILE), "\t%s\t%#lx", UNALIGNED_OFFSET_ASM_OP (VALUE), VALUE)
347 #endif
349 #ifndef ASM_OUTPUT_DEBUG_ADDR_DATA
350 #define ASM_OUTPUT_DEBUG_ADDR_DATA(FILE,VALUE) \
351 fprintf ((FILE), "\t%s\t%#lx", UNALIGNED_PTR_ASM_OP, \
352 (unsigned long) VALUE)
353 #endif
355 #ifndef ASM_OUTPUT_DEBUG_DATA8
356 #define ASM_OUTPUT_DEBUG_DATA8(FILE,VALUE) \
357 fprintf ((FILE), "\t%s\t%#llx", VMS_UNALIGNED_DOUBLE_INT_ASM_OP, \
358 (unsigned long long) VALUE)
359 #endif
361 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
362 newline is produced. When flag_verbose_asm is asserted, we add commentary
363 at the end of the line, so we must avoid output of a newline here. */
364 #ifndef ASM_OUTPUT_DEBUG_STRING
365 #define ASM_OUTPUT_DEBUG_STRING(FILE,P) \
366 do \
368 register int slen = strlen (P); \
369 register const char *p = (P); \
370 register int i; \
371 fprintf (FILE, "\t.ascii \""); \
372 for (i = 0; i < slen; i++) \
374 register int c = p[i]; \
375 if (c == '\"' || c == '\\') \
376 putc ('\\', FILE); \
377 if (c >= ' ' && c < 0177) \
378 putc (c, FILE); \
379 else \
380 fprintf (FILE, "\\%o", c); \
382 fprintf (FILE, "\""); \
384 while (0)
385 #endif
387 /* Convert a reference to the assembler name of a C-level name. This
388 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
389 a string rather than writing to a file. */
390 #ifndef ASM_NAME_TO_STRING
391 #define ASM_NAME_TO_STRING(STR, NAME) \
392 do \
394 if ((NAME)[0] == '*') \
395 strcpy (STR, NAME+1); \
396 else \
397 strcpy (STR, NAME); \
399 while (0)
400 #endif
403 /* Output the debug header HEADER. Also output COMMENT if flag_verbose_asm is
404 set. Return the header size. Just return the size if DOSIZEONLY is
405 nonzero. */
407 static int
408 write_debug_header (DST_HEADER *header, const char *comment, int dosizeonly)
410 if (!dosizeonly)
412 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
413 header->dst__header_length.dst_w_length);
415 if (flag_verbose_asm)
416 fprintf (asm_out_file, "\t%s record length", ASM_COMMENT_START);
417 fputc ('\n', asm_out_file);
419 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
420 header->dst__header_type.dst_w_type);
422 if (flag_verbose_asm)
423 fprintf (asm_out_file, "\t%s record type (%s)", ASM_COMMENT_START,
424 comment);
426 fputc ('\n', asm_out_file);
429 return 4;
432 /* Output the address of SYMBOL. Also output COMMENT if flag_verbose_asm is
433 set. Return the address size. Just return the size if DOSIZEONLY is
434 nonzero. */
436 static int
437 write_debug_addr (const char *symbol, const char *comment, int dosizeonly)
439 if (!dosizeonly)
441 ASM_OUTPUT_DEBUG_ADDR (asm_out_file, symbol);
442 if (flag_verbose_asm)
443 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
444 fputc ('\n', asm_out_file);
447 return PTR_SIZE;
450 /* Output the single byte DATA1. Also output COMMENT if flag_verbose_asm is
451 set. Return the data size. Just return the size if DOSIZEONLY is
452 nonzero. */
454 static int
455 write_debug_data1 (unsigned int data1, const char *comment, int dosizeonly)
457 if (!dosizeonly)
459 ASM_OUTPUT_DEBUG_DATA1 (asm_out_file, data1);
460 if (flag_verbose_asm)
461 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
462 fputc ('\n', asm_out_file);
465 return 1;
468 /* Output the single word DATA2. Also output COMMENT if flag_verbose_asm is
469 set. Return the data size. Just return the size if DOSIZEONLY is
470 nonzero. */
472 static int
473 write_debug_data2 (unsigned int data2, const char *comment, int dosizeonly)
475 if (!dosizeonly)
477 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file, data2);
478 if (flag_verbose_asm)
479 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
480 fputc ('\n', asm_out_file);
483 return 2;
486 /* Output double word DATA4. Also output COMMENT if flag_verbose_asm is set.
487 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
489 static int
490 write_debug_data4 (unsigned long data4, const char *comment, int dosizeonly)
492 if (!dosizeonly)
494 ASM_OUTPUT_DEBUG_DATA4 (asm_out_file, data4);
495 if (flag_verbose_asm)
496 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
497 fputc ('\n', asm_out_file);
500 return 4;
503 /* Output quad word DATA8. Also output COMMENT if flag_verbose_asm is set.
504 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
506 static int
507 write_debug_data8 (unsigned long long data8, const char *comment,
508 int dosizeonly)
510 if (!dosizeonly)
512 ASM_OUTPUT_DEBUG_DATA8 (asm_out_file, data8);
513 if (flag_verbose_asm)
514 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
515 fputc ('\n', asm_out_file);
518 return 8;
521 /* Output the difference between LABEL1 and LABEL2. Also output COMMENT if
522 flag_verbose_asm is set. Return the data size. Just return the size if
523 DOSIZEONLY is nonzero. */
525 static int
526 write_debug_delta4 (const char *label1, const char *label2,
527 const char *comment, int dosizeonly)
529 if (!dosizeonly)
531 ASM_OUTPUT_DEBUG_DELTA4 (asm_out_file, label1, label2);
532 if (flag_verbose_asm)
533 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
534 fputc ('\n', asm_out_file);
537 return 4;
540 /* Output a character string STRING. Also write COMMENT if flag_verbose_asm is
541 set. Return the string length. Just return the length if DOSIZEONLY is
542 nonzero. */
544 static int
545 write_debug_string (const char *string, const char *comment, int dosizeonly)
547 if (!dosizeonly)
549 ASM_OUTPUT_DEBUG_STRING (asm_out_file, string);
550 if (flag_verbose_asm)
551 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
552 fputc ('\n', asm_out_file);
555 return strlen (string);
558 /* Output a module begin header and return the header size. Just return the
559 size if DOSIZEONLY is nonzero. */
561 static int
562 write_modbeg (int dosizeonly)
564 DST_MODULE_BEGIN modbeg;
565 DST_MB_TRLR mb_trlr;
566 int i;
567 char *module_name, *m;
568 int modnamelen;
569 int prodnamelen;
570 int totsize = 0;
572 /* Assumes primary filename has Unix syntax file spec. */
573 module_name = xstrdup (lbasename (primary_filename));
575 m = strrchr (module_name, '.');
576 if (m)
577 *m = 0;
579 modnamelen = strlen (module_name);
580 for (i = 0; i < modnamelen; i++)
581 module_name[i] = TOUPPER (module_name[i]);
583 prodnamelen = strlen (module_producer);
585 modbeg.dst_a_modbeg_header.dst__header_length.dst_w_length
586 = DST_K_MODBEG_SIZE + modnamelen + DST_K_MB_TRLR_SIZE + prodnamelen - 1;
587 modbeg.dst_a_modbeg_header.dst__header_type.dst_w_type = DST_K_MODBEG;
588 modbeg.dst_b_modbeg_flags.dst_v_modbeg_hide = 0;
589 modbeg.dst_b_modbeg_flags.dst_v_modbeg_version = 1;
590 modbeg.dst_b_modbeg_flags.dst_v_modbeg_unused = 0;
591 modbeg.dst_b_modbeg_unused = 0;
592 modbeg.dst_l_modbeg_language = (DST_LANGUAGE) module_language;
593 modbeg.dst_w_version_major = DST_K_VERSION_MAJOR;
594 modbeg.dst_w_version_minor = DST_K_VERSION_MINOR;
595 modbeg.dst_b_modbeg_name = strlen (module_name);
597 mb_trlr.dst_b_compiler = strlen (module_producer);
599 totsize += write_debug_header (&modbeg.dst_a_modbeg_header,
600 "modbeg", dosizeonly);
601 totsize += write_debug_data1 (*((char *) &modbeg.dst_b_modbeg_flags),
602 "flags", dosizeonly);
603 totsize += write_debug_data1 (modbeg.dst_b_modbeg_unused,
604 "unused", dosizeonly);
605 totsize += write_debug_data4 (modbeg.dst_l_modbeg_language,
606 "language", dosizeonly);
607 totsize += write_debug_data2 (modbeg.dst_w_version_major,
608 "DST major version", dosizeonly);
609 totsize += write_debug_data2 (modbeg.dst_w_version_minor,
610 "DST minor version", dosizeonly);
611 totsize += write_debug_data1 (modbeg.dst_b_modbeg_name,
612 "length of module name", dosizeonly);
613 totsize += write_debug_string (module_name, "module name", dosizeonly);
614 totsize += write_debug_data1 (mb_trlr.dst_b_compiler,
615 "length of compiler name", dosizeonly);
616 totsize += write_debug_string (module_producer, "compiler name", dosizeonly);
618 return totsize;
621 /* Output a module end trailer and return the trailer size. Just return
622 the size if DOSIZEONLY is nonzero. */
624 static int
625 write_modend (int dosizeonly)
627 DST_MODULE_END modend;
628 int totsize = 0;
630 modend.dst_a_modend_header.dst__header_length.dst_w_length
631 = DST_K_MODEND_SIZE - 1;
632 modend.dst_a_modend_header.dst__header_type.dst_w_type = DST_K_MODEND;
634 totsize += write_debug_header (&modend.dst_a_modend_header, "modend",
635 dosizeonly);
637 return totsize;
640 /* Output a routine begin header routine RTNNUM and return the header size.
641 Just return the size if DOSIZEONLY is nonzero. */
643 static int
644 write_rtnbeg (int rtnnum, int dosizeonly)
646 const char *rtnname;
647 int rtnnamelen;
648 char *rtnentryname;
649 int totsize = 0;
650 char label[MAX_ARTIFICIAL_LABEL_BYTES];
651 DST_ROUTINE_BEGIN rtnbeg;
652 DST_PROLOG prolog;
654 rtnname = funcnam_table[rtnnum];
655 rtnnamelen = strlen (rtnname);
656 rtnentryname = concat (rtnname, "..en", NULL);
658 if (!strcmp (rtnname, "main"))
660 DST_HEADER header;
661 const char *go = "TRANSFER$BREAK$GO";
663 /* This command isn't documented in DSTRECORDS, so it's made to
664 look like what DEC C does */
666 /* header size - 1st byte + flag byte + STO_LW size
667 + string count byte + string length */
668 header.dst__header_length.dst_w_length
669 = DST_K_DST_HEADER_SIZE - 1 + 1 + 4 + 1 + strlen (go);
670 header.dst__header_type.dst_w_type = DST_K_TBG;
672 totsize += write_debug_header (&header, "transfer", dosizeonly);
674 /* I think this is a flag byte, but I don't know what this flag means */
675 totsize += write_debug_data1 (0x1, "flags ???", dosizeonly);
677 /* Routine Begin PD Address */
678 totsize += write_debug_addr (rtnname, "main procedure descriptor",
679 dosizeonly);
680 totsize += write_debug_data1 (strlen (go), "length of main_name",
681 dosizeonly);
682 totsize += write_debug_string (go, "main name", dosizeonly);
685 /* The header length never includes the length byte. */
686 rtnbeg.dst_a_rtnbeg_header.dst__header_length.dst_w_length
687 = DST_K_RTNBEG_SIZE + rtnnamelen - 1;
688 rtnbeg.dst_a_rtnbeg_header.dst__header_type.dst_w_type = DST_K_RTNBEG;
689 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unused = 0;
690 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unalloc = 0;
691 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_prototype = 0;
692 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_inlined = 0;
693 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_no_call = 1;
694 rtnbeg.dst_b_rtnbeg_name = rtnnamelen;
696 totsize += write_debug_header (&rtnbeg.dst_a_rtnbeg_header, "rtnbeg",
697 dosizeonly);
698 totsize += write_debug_data1 (*((char *) &rtnbeg.dst_b_rtnbeg_flags),
699 "flags", dosizeonly);
701 /* Routine Begin Address */
702 totsize += write_debug_addr (rtnentryname, "routine entry name", dosizeonly);
704 /* Routine Begin PD Address */
705 totsize += write_debug_addr (rtnname, "routine procedure descriptor",
706 dosizeonly);
708 /* Routine Begin Name */
709 totsize += write_debug_data1 (rtnbeg.dst_b_rtnbeg_name,
710 "length of routine name", dosizeonly);
712 totsize += write_debug_string (rtnname, "routine name", dosizeonly);
714 free (rtnentryname);
716 if (debug_info_level > DINFO_LEVEL_TERSE)
718 prolog.dst_a_prolog_header.dst__header_length.dst_w_length
719 = DST_K_PROLOG_SIZE - 1;
720 prolog.dst_a_prolog_header.dst__header_type.dst_w_type = DST_K_PROLOG;
722 totsize += write_debug_header (&prolog.dst_a_prolog_header, "prolog",
723 dosizeonly);
725 ASM_GENERATE_INTERNAL_LABEL
726 (label, FUNC_PROLOG_LABEL,
727 funcnum_table[rtnnum]);
728 totsize += write_debug_addr (label, "prolog breakpoint addr",
729 dosizeonly);
732 return totsize;
735 /* Output a routine end trailer for routine RTNNUM and return the header size.
736 Just return the size if DOSIZEONLY is nonzero. */
738 static int
739 write_rtnend (int rtnnum, int dosizeonly)
741 DST_ROUTINE_END rtnend;
742 char label1[MAX_ARTIFICIAL_LABEL_BYTES];
743 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
744 int totsize;
746 totsize = 0;
748 rtnend.dst_a_rtnend_header.dst__header_length.dst_w_length
749 = DST_K_RTNEND_SIZE - 1;
750 rtnend.dst_a_rtnend_header.dst__header_type.dst_w_type = DST_K_RTNEND;
751 rtnend.dst_b_rtnend_unused = 0;
752 rtnend.dst_l_rtnend_size = 0; /* Calculated below. */
754 totsize += write_debug_header (&rtnend.dst_a_rtnend_header, "rtnend",
755 dosizeonly);
756 totsize += write_debug_data1 (rtnend.dst_b_rtnend_unused, "unused",
757 dosizeonly);
759 ASM_GENERATE_INTERNAL_LABEL
760 (label1, FUNC_BEGIN_LABEL,
761 funcnum_table[rtnnum]);
762 ASM_GENERATE_INTERNAL_LABEL
763 (label2, FUNC_END_LABEL,
764 funcnum_table[rtnnum]);
765 totsize += write_debug_delta4 (label2, label1, "routine size", dosizeonly);
767 return totsize;
770 #define K_DELTA_PC(I) \
771 ((I) < 128 ? -(I) : (I) < 65536 ? DST_K_DELTA_PC_W : DST_K_DELTA_PC_L)
773 #define K_SET_LINUM(I) \
774 ((I) < 256 ? DST_K_SET_LINUM_B \
775 : (I) < 65536 ? DST_K_SET_LINUM : DST_K_SET_LINUM_L)
777 #define K_INCR_LINUM(I) \
778 ((I) < 256 ? DST_K_INCR_LINUM \
779 : (I) < 65536 ? DST_K_INCR_LINUM_W : DST_K_INCR_LINUM_L)
781 /* Output the PC to line number correlations and return the size. Just return
782 the size if DOSIZEONLY is nonzero */
784 static int
785 write_pclines (int dosizeonly)
787 unsigned i;
788 int fn;
789 int ln, lastln;
790 int linestart = 0;
791 int max_line;
792 DST_LINE_NUM_HEADER line_num;
793 DST_PCLINE_COMMANDS pcline;
794 char label[MAX_ARTIFICIAL_LABEL_BYTES];
795 char lastlabel[MAX_ARTIFICIAL_LABEL_BYTES];
796 int totsize = 0;
797 char buff[256];
799 max_line = file_info_table[1].max_line;
800 file_info_table[1].listing_line_start = linestart;
801 linestart = linestart + ((max_line / 100000) + 1) * 100000;
803 for (i = 2; i < file_info_table_in_use; i++)
805 max_line = file_info_table[i].max_line;
806 file_info_table[i].listing_line_start = linestart;
807 linestart = linestart + ((max_line / 10000) + 1) * 10000;
810 /* Set starting address to beginning of text section. */
811 line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 8;
812 line_num.dst_a_line_num_header.dst__header_type.dst_w_type = DST_K_LINE_NUM;
813 pcline.dst_b_pcline_command = DST_K_SET_ABS_PC;
815 totsize += write_debug_header (&line_num.dst_a_line_num_header,
816 "line_num", dosizeonly);
817 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
818 "line_num (SET ABS PC)", dosizeonly);
820 if (dosizeonly)
821 totsize += 4;
822 else
824 ASM_OUTPUT_DEBUG_ADDR (asm_out_file, TEXT_SECTION_ASM_OP);
825 if (flag_verbose_asm)
826 fprintf (asm_out_file, "\t%s line_num", ASM_COMMENT_START);
827 fputc ('\n', asm_out_file);
830 fn = line_info_table[1].dst_file_num;
831 ln = (file_info_table[fn].listing_line_start
832 + line_info_table[1].dst_line_num);
833 line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 4 + 4;
834 pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
836 totsize += write_debug_header (&line_num.dst_a_line_num_header,
837 "line_num", dosizeonly);
838 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
839 "line_num (SET LINUM LONG)", dosizeonly);
841 sprintf (buff, "line_num (%d)", ln ? ln - 1 : 0);
842 totsize += write_debug_data4 (ln ? ln - 1 : 0, buff, dosizeonly);
844 lastln = ln;
845 strcpy (lastlabel, TEXT_SECTION_ASM_OP);
846 for (i = 1; i < line_info_table_in_use; i++)
848 int extrabytes;
850 fn = line_info_table[i].dst_file_num;
851 ln = (file_info_table[fn].listing_line_start
852 + line_info_table[i].dst_line_num);
854 if (ln - lastln > 1)
855 extrabytes = 5; /* NUMBYTES (ln - lastln - 1) + 1; */
856 else if (ln <= lastln)
857 extrabytes = 5; /* NUMBYTES (ln - 1) + 1; */
858 else
859 extrabytes = 0;
861 line_num.dst_a_line_num_header.dst__header_length.dst_w_length
862 = 8 + extrabytes;
864 totsize += write_debug_header
865 (&line_num.dst_a_line_num_header, "line_num", dosizeonly);
867 if (ln - lastln > 1)
869 int lndif = ln - lastln - 1;
871 /* K_INCR_LINUM (lndif); */
872 pcline.dst_b_pcline_command = DST_K_INCR_LINUM_L;
874 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
875 "line_num (INCR LINUM LONG)",
876 dosizeonly);
878 sprintf (buff, "line_num (%d)", lndif);
879 totsize += write_debug_data4 (lndif, buff, dosizeonly);
881 else if (ln <= lastln)
883 /* K_SET_LINUM (ln-1); */
884 pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
886 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
887 "line_num (SET LINUM LONG)",
888 dosizeonly);
890 sprintf (buff, "line_num (%d)", ln - 1);
891 totsize += write_debug_data4 (ln - 1, buff, dosizeonly);
894 pcline.dst_b_pcline_command = DST_K_DELTA_PC_L;
896 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
897 "line_num (DELTA PC LONG)", dosizeonly);
899 ASM_GENERATE_INTERNAL_LABEL (label, LINE_CODE_LABEL, i);
900 totsize += write_debug_delta4 (label, lastlabel, "increment line_num",
901 dosizeonly);
903 lastln = ln;
904 strcpy (lastlabel, label);
907 return totsize;
910 /* Output a source correlation for file FILEID using information saved in
911 FILE_INFO_ENTRY and return the size. Just return the size if DOSIZEONLY is
912 nonzero. */
914 static int
915 write_srccorr (int fileid, dst_file_info_entry file_info_entry,
916 int dosizeonly)
918 int src_command_size;
919 int linesleft = file_info_entry.max_line;
920 int linestart = file_info_entry.listing_line_start;
921 int flen = strlen (file_info_entry.file_name);
922 int linestodo = 0;
923 DST_SOURCE_CORR src_header;
924 DST_SRC_COMMAND src_command;
925 DST_SRC_COMMAND src_command_sf;
926 DST_SRC_COMMAND src_command_sl;
927 DST_SRC_COMMAND src_command_sr;
928 DST_SRC_COMMAND src_command_dl;
929 DST_SRC_CMDTRLR src_cmdtrlr;
930 char buff[256];
931 int totsize = 0;
933 if (fileid == 1)
935 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
936 = DST_K_SOURCE_CORR_HEADER_SIZE + 1 - 1;
937 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
938 = DST_K_SOURCE;
939 src_command.dst_b_src_command = DST_K_SRC_FORMFEED;
941 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
942 "source corr", dosizeonly);
944 totsize += write_debug_data1 (src_command.dst_b_src_command,
945 "source_corr (SRC FORMFEED)",
946 dosizeonly);
949 src_command_size
950 = DST_K_SRC_COMMAND_SIZE + flen + DST_K_SRC_CMDTRLR_SIZE;
951 src_command.dst_b_src_command = DST_K_SRC_DECLFILE;
952 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length
953 = src_command_size - 2;
954 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags = 0;
955 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid
956 = fileid;
957 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt
958 = file_info_entry.cdt;
959 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk
960 = file_info_entry.ebk;
961 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb
962 = file_info_entry.ffb;
963 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo
964 = file_info_entry.rfo;
965 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename
966 = flen;
968 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
969 = DST_K_SOURCE_CORR_HEADER_SIZE + src_command_size - 1;
970 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
971 = DST_K_SOURCE;
973 src_cmdtrlr.dst_b_src_df_libmodname = 0;
975 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
976 "source corr", dosizeonly);
977 totsize += write_debug_data1 (src_command.dst_b_src_command,
978 "source_corr (DECL SRC FILE)", dosizeonly);
979 totsize += write_debug_data1
980 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length,
981 "source_corr (length)", dosizeonly);
983 totsize += write_debug_data1
984 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags,
985 "source_corr (flags)", dosizeonly);
987 totsize += write_debug_data2
988 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid,
989 "source_corr (fileid)", dosizeonly);
991 totsize += write_debug_data8
992 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt,
993 "source_corr (creation date)", dosizeonly);
995 totsize += write_debug_data4
996 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk,
997 "source_corr (EOF block number)", dosizeonly);
999 totsize += write_debug_data2
1000 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb,
1001 "source_corr (first free byte)", dosizeonly);
1003 totsize += write_debug_data1
1004 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo,
1005 "source_corr (record and file organization)", dosizeonly);
1007 totsize += write_debug_data1
1008 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename,
1009 "source_corr (filename length)", dosizeonly);
1011 totsize += write_debug_string (remap_debug_filename (
1012 file_info_entry.file_name),
1013 "source file name", dosizeonly);
1014 totsize += write_debug_data1 (src_cmdtrlr.dst_b_src_df_libmodname,
1015 "source_corr (libmodname)", dosizeonly);
1017 src_command_sf.dst_b_src_command = DST_K_SRC_SETFILE;
1018 src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword = fileid;
1020 src_command_sr.dst_b_src_command = DST_K_SRC_SETREC_W;
1021 src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword = 1;
1023 src_command_sl.dst_b_src_command = DST_K_SRC_SETLNUM_L;
1024 src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong = linestart + 1;
1026 src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1028 if (linesleft > 65534)
1029 linesleft = linesleft - 65534, linestodo = 65534;
1030 else
1031 linestodo = linesleft, linesleft = 0;
1033 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1035 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1036 = DST_K_SOURCE_CORR_HEADER_SIZE + 3 + 3 + 5 + 3 - 1;
1037 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1038 = DST_K_SOURCE;
1040 if (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword)
1042 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1043 "source corr", dosizeonly);
1045 totsize += write_debug_data1 (src_command_sf.dst_b_src_command,
1046 "source_corr (src setfile)", dosizeonly);
1048 totsize += write_debug_data2
1049 (src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword,
1050 "source_corr (fileid)", dosizeonly);
1052 totsize += write_debug_data1 (src_command_sr.dst_b_src_command,
1053 "source_corr (setrec)", dosizeonly);
1055 totsize += write_debug_data2
1056 (src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword,
1057 "source_corr (recnum)", dosizeonly);
1059 totsize += write_debug_data1 (src_command_sl.dst_b_src_command,
1060 "source_corr (setlnum)", dosizeonly);
1062 totsize += write_debug_data4
1063 (src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong,
1064 "source_corr (linenum)", dosizeonly);
1066 totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1067 "source_corr (deflines)", dosizeonly);
1069 sprintf (buff, "source_corr (%d)",
1070 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1071 totsize += write_debug_data2
1072 (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
1073 buff, dosizeonly);
1075 while (linesleft > 0)
1077 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1078 = DST_K_SOURCE_CORR_HEADER_SIZE + 3 - 1;
1079 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1080 = DST_K_SOURCE;
1081 src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1083 if (linesleft > 65534)
1084 linesleft = linesleft - 65534, linestodo = 65534;
1085 else
1086 linestodo = linesleft, linesleft = 0;
1088 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1090 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1091 "source corr", dosizeonly);
1092 totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1093 "source_corr (deflines)", dosizeonly);
1094 sprintf (buff, "source_corr (%d)",
1095 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1096 totsize += write_debug_data2
1097 (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
1098 buff, dosizeonly);
1102 return totsize;
1105 /* Output all the source correlation entries and return the size. Just return
1106 the size if DOSIZEONLY is nonzero. */
1108 static int
1109 write_srccorrs (int dosizeonly)
1111 unsigned int i;
1112 int totsize = 0;
1114 for (i = 1; i < file_info_table_in_use; i++)
1115 totsize += write_srccorr (i, file_info_table[i], dosizeonly);
1117 return totsize;
1120 /* Output a marker (i.e. a label) for the beginning of a function, before
1121 the prologue. */
1123 static void
1124 vmsdbgout_begin_prologue (unsigned int line, unsigned int column,
1125 const char *file)
1127 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1129 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1130 (*dwarf2_debug_hooks.begin_prologue) (line, column, file);
1132 if (debug_info_level > DINFO_LEVEL_NONE)
1134 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1135 current_function_funcdef_no);
1136 ASM_OUTPUT_LABEL (asm_out_file, label);
1140 /* Output a marker (i.e. a label) for the beginning of a function, after
1141 the prologue. */
1143 static void
1144 vmsdbgout_end_prologue (unsigned int line, const char *file)
1146 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1148 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1149 (*dwarf2_debug_hooks.end_prologue) (line, file);
1151 if (debug_info_level > DINFO_LEVEL_TERSE)
1153 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_PROLOG_LABEL,
1154 current_function_funcdef_no);
1155 ASM_OUTPUT_LABEL (asm_out_file, label);
1157 /* VMS PCA expects every PC range to correlate to some line and file. */
1158 vmsdbgout_write_source_line (line, file, 0, true);
1162 /* No output for VMS debug, but make obligatory call to Dwarf2 debug */
1164 static void
1165 vmsdbgout_end_function (unsigned int line)
1167 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1168 (*dwarf2_debug_hooks.end_function) (line);
1171 /* Output a marker (i.e. a label) for the beginning of the epilogue.
1172 This gets called *before* the epilogue code has been generated. */
1174 static void
1175 vmsdbgout_begin_epilogue (unsigned int line, const char *file)
1177 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1178 static int save_current_function_funcdef_no = -1;
1180 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1181 (*dwarf2_debug_hooks.begin_epilogue) (line, file);
1183 if (debug_info_level > DINFO_LEVEL_NONE)
1185 if (save_current_function_funcdef_no != current_function_funcdef_no)
1187 /* Output a label to mark the endpoint of the code generated for this
1188 function. */
1189 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_EPILOG_LABEL,
1190 current_function_funcdef_no);
1192 ASM_OUTPUT_LABEL (asm_out_file, label);
1194 save_current_function_funcdef_no = current_function_funcdef_no;
1196 /* VMS PCA expects every PC range to correlate to some line and
1197 file. */
1198 vmsdbgout_write_source_line (line, file, 0, true);
1203 /* Output a marker (i.e. a label) for the absolute end of the generated code
1204 for a function definition. This gets called *after* the epilogue code has
1205 been generated. */
1207 static void
1208 vmsdbgout_end_epilogue (unsigned int line, const char *file)
1210 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1212 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1213 (*dwarf2_debug_hooks.end_epilogue) (line, file);
1215 if (debug_info_level > DINFO_LEVEL_NONE)
1217 /* Output a label to mark the endpoint of the code generated for this
1218 function. */
1219 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1220 current_function_funcdef_no);
1221 ASM_OUTPUT_LABEL (asm_out_file, label);
1223 /* VMS PCA expects every PC range to correlate to some line and file. */
1224 vmsdbgout_write_source_line (line, file, 0, true);
1228 /* Output a marker (i.e. a label) for the beginning of the generated code for
1229 a lexical block. */
1231 static void
1232 vmsdbgout_begin_block (register unsigned line, register unsigned blocknum)
1234 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1235 (*dwarf2_debug_hooks.begin_block) (line, blocknum);
1237 if (debug_info_level > DINFO_LEVEL_TERSE)
1238 targetm.asm_out.internal_label (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
1241 /* Output a marker (i.e. a label) for the end of the generated code for a
1242 lexical block. */
1244 static void
1245 vmsdbgout_end_block (register unsigned line, register unsigned blocknum)
1247 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1248 (*dwarf2_debug_hooks.end_block) (line, blocknum);
1250 if (debug_info_level > DINFO_LEVEL_TERSE)
1251 targetm.asm_out.internal_label (asm_out_file, BLOCK_END_LABEL, blocknum);
1254 /* Not implemented in VMS Debug. */
1256 static bool
1257 vmsdbgout_ignore_block (const_tree block)
1259 bool retval = 0;
1261 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1262 retval = (*dwarf2_debug_hooks.ignore_block) (block);
1264 return retval;
1267 /* Add an entry for function DECL into the funcnam_table. */
1269 static void
1270 vmsdbgout_begin_function (tree decl)
1272 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1274 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1275 (*dwarf2_debug_hooks.begin_function) (decl);
1277 /* Add the new entry to the end of the function name table. */
1278 funcnam_table.safe_push (xstrdup (name));
1279 funcnum_table.safe_push (current_function_funcdef_no);
1282 static char fullname_buff [4096];
1284 /* Return the full file specification for FILENAME. The specification must be
1285 in VMS syntax in order to be processed by VMS Debug. */
1287 static char *
1288 full_name (const char *filename)
1290 #ifdef VMS
1291 FILE *fp = fopen (filename, "r");
1293 fgetname (fp, fullname_buff, 1);
1294 fclose (fp);
1295 #else
1296 /* Unix paths really mess up VMS debug. Better to just output the
1297 base filename. */
1298 strcpy (fullname_buff, filename);
1299 #endif
1301 return fullname_buff;
1304 /* Lookup a filename (in the list of filenames that we know about here in
1305 vmsdbgout.c) and return its "index". The index of each (known) filename is
1306 just a unique number which is associated with only that one filename. We
1307 need such numbers for the sake of generating labels and references
1308 to those files numbers. If the filename given as an argument is not
1309 found in our current list, add it to the list and assign it the next
1310 available unique index number. In order to speed up searches, we remember
1311 the index of the filename was looked up last. This handles the majority of
1312 all searches. */
1314 static unsigned int
1315 lookup_filename (const char *file_name)
1317 static unsigned int last_file_lookup_index = 0;
1318 register char *fn;
1319 register unsigned i;
1320 const char *fnam;
1321 long long cdt = 0;
1322 long ebk = 0;
1323 short ffb = 0;
1324 char rfo = 0;
1325 long siz = 0;
1326 int ver = 0;
1328 fnam = full_name (file_name);
1330 /* Check to see if the file name that was searched on the previous call
1331 matches this file name. If so, return the index. */
1332 if (last_file_lookup_index != 0)
1334 fn = file_info_table[last_file_lookup_index].file_name;
1335 if (strcmp (fnam, fn) == 0)
1336 return last_file_lookup_index;
1339 /* Didn't match the previous lookup, search the table */
1340 for (i = 1; i < file_info_table_in_use; ++i)
1342 fn = file_info_table[i].file_name;
1343 if (strcmp (fnam, fn) == 0)
1345 last_file_lookup_index = i;
1346 return i;
1350 /* Prepare to add a new table entry by making sure there is enough space in
1351 the table to do so. If not, expand the current table. */
1352 if (file_info_table_in_use == file_info_table_allocated)
1355 file_info_table_allocated += FILE_TABLE_INCREMENT;
1356 file_info_table = XRESIZEVEC (dst_file_info_entry, file_info_table,
1357 file_info_table_allocated);
1360 if (vms_file_stats_name (file_name, &cdt, &siz, &rfo, &ver) == 0)
1362 ebk = siz / 512 + 1;
1363 ffb = siz - ((siz / 512) * 512);
1366 /* Add the new entry to the end of the filename table. */
1367 file_info_table[file_info_table_in_use].file_name = xstrdup (fnam);
1368 file_info_table[file_info_table_in_use].max_line = 0;
1369 file_info_table[file_info_table_in_use].cdt = cdt;
1370 file_info_table[file_info_table_in_use].ebk = ebk;
1371 file_info_table[file_info_table_in_use].ffb = ffb;
1372 file_info_table[file_info_table_in_use].rfo = rfo;
1374 last_file_lookup_index = file_info_table_in_use++;
1375 return last_file_lookup_index;
1378 /* Output a label to mark the beginning of a source code line entry
1379 and record information relating to this source line, in
1380 'line_info_table' for later output of the .debug_line section. */
1382 static void
1383 vmsdbgout_write_source_line (unsigned line, const char *filename,
1384 int /* discriminator */, bool /* is_stmt */)
1386 dst_line_info_ref line_info;
1388 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
1389 line_info_table_in_use);
1391 /* Expand the line info table if necessary. */
1392 if (line_info_table_in_use == line_info_table_allocated)
1394 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
1395 line_info_table = XRESIZEVEC (dst_line_info_entry, line_info_table,
1396 line_info_table_allocated);
1399 /* Add the new entry at the end of the line_info_table. */
1400 line_info = &line_info_table[line_info_table_in_use++];
1401 line_info->dst_file_num = lookup_filename (filename);
1402 line_info->dst_line_num = line;
1403 if (line > file_info_table[line_info->dst_file_num].max_line)
1404 file_info_table[line_info->dst_file_num].max_line = line;
1407 static void
1408 vmsdbgout_source_line (register unsigned line, unsigned int column,
1409 register const char *filename,
1410 int discriminator, bool is_stmt)
1412 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1413 (*dwarf2_debug_hooks.source_line) (line, column, filename, discriminator,
1414 is_stmt);
1416 if (debug_info_level >= DINFO_LEVEL_TERSE)
1417 vmsdbgout_write_source_line (line, filename, discriminator, is_stmt);
1420 /* Record the beginning of a new source file, for later output.
1421 At present, unimplemented. */
1423 static void
1424 vmsdbgout_start_source_file (unsigned int lineno, const char *filename)
1426 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1427 (*dwarf2_debug_hooks.start_source_file) (lineno, filename);
1430 /* Record the end of a source file, for later output.
1431 At present, unimplemented. */
1433 static void
1434 vmsdbgout_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
1436 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1437 (*dwarf2_debug_hooks.end_source_file) (lineno);
1440 /* Set up for Debug output at the start of compilation. */
1442 static void
1443 vmsdbgout_init (const char *filename)
1445 const char *language_string = lang_hooks.name;
1447 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1448 (*dwarf2_debug_hooks.init) (filename);
1450 if (debug_info_level == DINFO_LEVEL_NONE)
1451 return;
1453 /* Remember the name of the primary input file. */
1454 primary_filename = filename;
1456 /* Allocate the initial hunk of the file_info_table. */
1457 file_info_table = XCNEWVEC (dst_file_info_entry, FILE_TABLE_INCREMENT);
1458 file_info_table_allocated = FILE_TABLE_INCREMENT;
1459 /* Skip the first entry - file numbers begin at 1. */
1460 file_info_table_in_use = 1;
1462 funcnam_table.create (FUNC_TABLE_INITIAL);
1463 funcnum_table.create (FUNC_TABLE_INITIAL);
1465 /* Allocate the initial hunk of the line_info_table. */
1466 line_info_table = XCNEWVEC (dst_line_info_entry, LINE_INFO_TABLE_INCREMENT);
1467 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
1468 /* zero-th entry is allocated, but unused */
1469 line_info_table_in_use = 1;
1471 lookup_filename (primary_filename);
1473 if (lang_GNU_C ())
1474 module_language = DST_K_C;
1475 else if (lang_GNU_CXX ())
1476 module_language = DST_K_CXX;
1477 else if (!strcmp (language_string, "GNU Ada"))
1478 module_language = DST_K_ADA;
1479 else if (!strcmp (language_string, "GNU F77"))
1480 module_language = DST_K_FORTRAN;
1481 else
1482 module_language = DST_K_UNKNOWN;
1484 module_producer = concat (language_string, " ", version_string, NULL);
1486 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
1490 /* Not implemented in VMS Debug. */
1492 static void
1493 vmsdbgout_assembly_start (void)
1495 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1496 (*dwarf2_debug_hooks.assembly_start) ();
1499 /* Not implemented in VMS Debug. */
1501 static void
1502 vmsdbgout_define (unsigned int lineno, const char *buffer)
1504 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1505 (*dwarf2_debug_hooks.define) (lineno, buffer);
1508 /* Not implemented in VMS Debug. */
1510 static void
1511 vmsdbgout_undef (unsigned int lineno, const char *buffer)
1513 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1514 (*dwarf2_debug_hooks.undef) (lineno, buffer);
1517 /* Not implemented in VMS Debug. */
1519 static void
1520 vmsdbgout_function_decl (tree decl)
1522 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1523 (*dwarf2_debug_hooks.function_decl) (decl);
1526 /* Not implemented in VMS Debug. */
1528 static void
1529 vmsdbgout_early_global_decl (tree decl)
1531 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1532 (*dwarf2_debug_hooks.early_global_decl) (decl);
1535 /* Not implemented in VMS Debug. */
1537 static void
1538 vmsdbgout_late_global_decl (tree decl)
1540 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1541 (*dwarf2_debug_hooks.late_global_decl) (decl);
1544 /* Not implemented in VMS Debug. */
1546 static void
1547 vmsdbgout_type_decl (tree decl, int local)
1549 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1550 (*dwarf2_debug_hooks.type_decl) (decl, local);
1553 /* Not implemented in VMS Debug. */
1555 static void
1556 vmsdbgout_abstract_function (tree decl)
1558 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1559 (*dwarf2_debug_hooks.outlining_inline_function) (decl);
1562 static void
1563 vmsdbgout_early_finish (const char *filename)
1565 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1566 (*dwarf2_debug_hooks.early_finish) (filename);
1569 /* Output stuff that Debug requires at the end of every file and generate the
1570 VMS Debug debugging info. */
1572 static void
1573 vmsdbgout_finish (const char *filename ATTRIBUTE_UNUSED)
1575 unsigned int i, ifunc;
1576 int totsize;
1578 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1579 (*dwarf2_debug_hooks.finish) (filename);
1581 if (debug_info_level == DINFO_LEVEL_NONE)
1582 return;
1584 /* Output a terminator label for the .text section. */
1585 switch_to_section (text_section);
1586 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
1588 /* Output debugging information.
1589 Warning! Do not change the name of the .vmsdebug section without
1590 changing it in the assembler also. */
1591 switch_to_section (get_named_section (NULL, ".vmsdebug", 0));
1592 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1594 totsize = write_modbeg (1);
1595 FOR_EACH_VEC_ELT (funcnum_table, i, ifunc)
1597 totsize += write_rtnbeg (i, 1);
1598 totsize += write_rtnend (i, 1);
1600 totsize += write_pclines (1);
1602 write_modbeg (0);
1603 FOR_EACH_VEC_ELT (funcnum_table, i, ifunc)
1605 write_rtnbeg (i, 0);
1606 write_rtnend (i, 0);
1608 write_pclines (0);
1610 if (debug_info_level > DINFO_LEVEL_TERSE)
1612 totsize = write_srccorrs (1);
1613 write_srccorrs (0);
1616 totsize = write_modend (1);
1617 write_modend (0);
1620 /* Need for both Dwarf2 on IVMS and VMS Debug on AVMS */
1622 #ifdef VMS
1623 #define __NEW_STARLET 1
1624 #include <vms/rms.h>
1625 #include <vms/atrdef.h>
1626 #include <vms/fibdef.h>
1627 #include <vms/stsdef.h>
1628 #include <vms/iodef.h>
1629 #include <vms/fatdef.h>
1630 #include <vms/descrip.h>
1631 #include <unixlib.h>
1633 #define MAXPATH 256
1635 /* descrip.h doesn't have everything ... */
1636 typedef struct fibdef* __fibdef_ptr32 __attribute__ (( mode (SI) ));
1637 struct dsc$descriptor_fib
1639 unsigned int fib$l_len;
1640 __fibdef_ptr32 fib$l_addr;
1643 /* I/O Status Block. */
1644 struct IOSB
1646 unsigned short status, count;
1647 unsigned int devdep;
1650 static char *tryfile;
1652 /* Variable length string. */
1653 struct vstring
1655 short length;
1656 char string[NAM$C_MAXRSS+1];
1659 static char filename_buff [MAXPATH];
1660 static char vms_filespec [MAXPATH];
1662 /* Callback function for filespec style conversion. */
1664 static int
1665 translate_unix (char *name, int type ATTRIBUTE_UNUSED)
1667 strncpy (filename_buff, name, MAXPATH);
1668 filename_buff [MAXPATH - 1] = (char) 0;
1669 return 0;
1672 /* Wrapper for DECC function that converts a Unix filespec
1673 to VMS style filespec. */
1675 static char *
1676 to_vms_file_spec (char *filespec)
1678 strncpy (vms_filespec, "", MAXPATH);
1679 decc$to_vms (filespec, translate_unix, 1, 1);
1680 strncpy (vms_filespec, filename_buff, MAXPATH);
1682 vms_filespec [MAXPATH - 1] = (char) 0;
1684 return vms_filespec;
1687 #else
1688 #define VMS_EPOCH_OFFSET 35067168000000000LL
1689 #define VMS_GRANULARITY_FACTOR 10000000
1690 #endif
1692 /* Return VMS file date, size, format, version given a name. */
1695 vms_file_stats_name (const char *filename, long long *cdt, long *siz, char *rfo,
1696 int *ver)
1698 #ifdef VMS
1699 struct FAB fab;
1700 struct NAM nam;
1702 unsigned long long create;
1703 FAT recattr;
1704 char ascnamebuff [256];
1706 ATRDEF atrlst[]
1708 { ATR$S_CREDATE, ATR$C_CREDATE, &create },
1709 { ATR$S_RECATTR, ATR$C_RECATTR, &recattr },
1710 { ATR$S_ASCNAME, ATR$C_ASCNAME, &ascnamebuff },
1711 { 0, 0, 0}
1714 FIBDEF fib;
1715 struct dsc$descriptor_fib fibdsc = {sizeof (fib), (void *) &fib};
1717 struct IOSB iosb;
1719 long status;
1720 unsigned short chan;
1722 struct vstring file;
1723 struct dsc$descriptor_s filedsc
1724 = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) file.string};
1725 struct vstring device;
1726 struct dsc$descriptor_s devicedsc
1727 = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) device.string};
1728 struct vstring result;
1729 struct dsc$descriptor_s resultdsc
1730 = {NAM$C_MAXRSS, DSC$K_DTYPE_VT, DSC$K_CLASS_VS, (void *) result.string};
1732 if (strcmp (filename, "<internal>") == 0
1733 || strcmp (filename, "<built-in>") == 0)
1735 if (cdt)
1736 *cdt = 0;
1738 if (siz)
1739 *siz = 0;
1741 if (rfo)
1742 *rfo = 0;
1744 if (ver)
1745 *ver = 0;
1747 return 0;
1750 tryfile = to_vms_file_spec (filename);
1752 /* Allocate and initialize a FAB and NAM structures. */
1753 fab = cc$rms_fab;
1754 nam = cc$rms_nam;
1756 nam.nam$l_esa = file.string;
1757 nam.nam$b_ess = NAM$C_MAXRSS;
1758 nam.nam$l_rsa = result.string;
1759 nam.nam$b_rss = NAM$C_MAXRSS;
1760 fab.fab$l_fna = tryfile;
1761 fab.fab$b_fns = strlen (tryfile);
1762 fab.fab$l_nam = &nam;
1764 /* Validate filespec syntax and device existence. */
1765 status = SYS$PARSE (&fab, 0, 0);
1766 if ((status & 1) != 1)
1767 return 1;
1769 file.string[nam.nam$b_esl] = 0;
1771 /* Find matching filespec. */
1772 status = SYS$SEARCH (&fab, 0, 0);
1773 if ((status & 1) != 1)
1774 return 1;
1776 file.string[nam.nam$b_esl] = 0;
1777 result.string[result.length=nam.nam$b_rsl] = 0;
1779 /* Get the device name and assign an IO channel. */
1780 strncpy (device.string, nam.nam$l_dev, nam.nam$b_dev);
1781 devicedsc.dsc$w_length = nam.nam$b_dev;
1782 chan = 0;
1783 status = SYS$ASSIGN (&devicedsc, &chan, 0, 0, 0);
1784 if ((status & 1) != 1)
1785 return 1;
1787 /* Initialize the FIB and fill in the directory id field. */
1788 memset (&fib, 0, sizeof (fib));
1789 fib.fib$w_did[0] = nam.nam$w_did[0];
1790 fib.fib$w_did[1] = nam.nam$w_did[1];
1791 fib.fib$w_did[2] = nam.nam$w_did[2];
1792 fib.fib$l_acctl = 0;
1793 fib.fib$l_wcc = 0;
1794 strcpy (file.string, (strrchr (result.string, ']') + 1));
1795 filedsc.dsc$w_length = strlen (file.string);
1796 result.string[result.length = 0] = 0;
1798 /* Open and close the file to fill in the attributes. */
1799 status
1800 = SYS$QIOW (0, chan, IO$_ACCESS|IO$M_ACCESS, &iosb, 0, 0,
1801 &fibdsc, &filedsc, &result.length, &resultdsc, &atrlst, 0);
1802 if ((status & 1) != 1)
1803 return 1;
1804 if ((iosb.status & 1) != 1)
1805 return 1;
1807 result.string[result.length] = 0;
1808 status = SYS$QIOW (0, chan, IO$_DEACCESS, &iosb, 0, 0, &fibdsc, 0, 0, 0,
1809 &atrlst, 0);
1810 if ((status & 1) != 1)
1811 return 1;
1812 if ((iosb.status & 1) != 1)
1813 return 1;
1815 /* Deassign the channel and exit. */
1816 status = SYS$DASSGN (chan);
1817 if ((status & 1) != 1)
1818 return 1;
1820 if (cdt) *cdt = create;
1821 if (siz) *siz = (512 * 65536 * recattr.fat$w_efblkh) +
1822 (512 * (recattr.fat$w_efblkl - 1)) +
1823 recattr.fat$w_ffbyte;
1824 if (rfo) *rfo = recattr.fat$v_rtype;
1825 if (ver) *ver = strtol (strrchr (ascnamebuff, ';')+1, 0, 10);
1827 return 0;
1828 #else
1829 struct stat buff;
1831 if ((stat (filename, &buff)) != 0)
1832 return 1;
1834 if (cdt)
1835 *cdt = (long long) (buff.st_mtime * VMS_GRANULARITY_FACTOR)
1836 + VMS_EPOCH_OFFSET;
1838 if (siz)
1839 *siz = buff.st_size;
1841 if (rfo)
1842 *rfo = 2; /* Stream LF format */
1844 if (ver)
1845 *ver = 1;
1847 return 0;
1848 #endif
1850 #endif