New VECTOR_CST layout
[official-gcc.git] / gcc / vmsdbgout.c
blob91dcd2e391096fbdcc8a6a147759d6236cb2b7dc
1 /* Output VMS debug format symbol table information from GCC.
2 Copyright (C) 1987-2017 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"
41 /* Difference in seconds between the VMS Epoch and the Unix Epoch */
42 static const long long vms_epoch_offset = 3506716800ll;
44 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
46 /* NOTE: In the comments in this file, many references are made to "Debug
47 Symbol Table". This term is abbreviated as `DST' throughout the remainder
48 of this file. */
50 typedef struct dst_line_info_struct *dst_line_info_ref;
52 /* Each entry in the line_info_table maintains the file and
53 line number associated with the label generated for that
54 entry. The label gives the PC value associated with
55 the line number entry. */
56 typedef struct dst_line_info_struct
58 unsigned long dst_file_num;
59 unsigned long dst_line_num;
61 dst_line_info_entry;
63 typedef struct dst_file_info_struct *dst_file_info_ref;
65 typedef struct dst_file_info_struct
67 char *file_name;
68 unsigned int max_line;
69 unsigned int listing_line_start;
70 long long cdt;
71 long ebk;
72 short ffb;
73 char rfo;
75 dst_file_info_entry;
77 /* Maximum size (in bytes) of an artificially generated label. */
78 #define MAX_ARTIFICIAL_LABEL_BYTES 30
80 /* Make sure we know the sizes of the various types debug can describe. These
81 are only defaults. If the sizes are different for your target, you should
82 override these values by defining the appropriate symbols in your tm.h
83 file. */
84 #ifndef PTR_SIZE
85 #define PTR_SIZE 4 /* Must be 32 bits for VMS debug info */
86 #endif
88 /* Pointer to a structure of filenames referenced by this compilation unit. */
89 static dst_file_info_ref file_info_table;
91 /* Total number of entries in the table (i.e. array) pointed to by
92 `file_info_table'. This is the *total* and includes both used and unused
93 slots. */
94 static unsigned int file_info_table_allocated;
96 /* Number of entries in the file_info_table which are actually in use. */
97 static unsigned int file_info_table_in_use;
99 /* Size (in elements) of increments by which we may expand the filename
100 table. */
101 #define FILE_TABLE_INCREMENT 64
103 typedef char *char_p;
105 static vec<char_p> funcnam_table;
106 static vec<unsigned> funcnum_table;
107 #define FUNC_TABLE_INITIAL 256
109 /* Local pointer to the name of the main input file. Initialized in
110 vmsdbgout_init. */
111 static const char *primary_filename;
113 static char *module_producer;
114 static unsigned int module_language;
116 /* A pointer to the base of a table that contains line information
117 for each source code line in .text in the compilation unit. */
118 static dst_line_info_ref line_info_table;
120 /* Number of elements currently allocated for line_info_table. */
121 static unsigned int line_info_table_allocated;
123 /* Number of elements in line_info_table currently in use. */
124 static unsigned int line_info_table_in_use;
126 /* Size (in elements) of increments by which we may expand line_info_table. */
127 #define LINE_INFO_TABLE_INCREMENT 1024
129 /* Forward declarations for functions defined in this file. */
130 static char *full_name (const char *);
131 static unsigned int lookup_filename (const char *);
132 static int write_debug_header (DST_HEADER *, const char *, int);
133 static int write_debug_addr (const char *, const char *, int);
134 static int write_debug_data1 (unsigned int, const char *, int);
135 static int write_debug_data2 (unsigned int, const char *, int);
136 static int write_debug_data4 (unsigned long, const char *, int);
137 static int write_debug_data8 (unsigned long long, const char *, int);
138 static int write_debug_delta4 (const char *, const char *, const char *, int);
139 static int write_debug_string (const char *, const char *, int);
140 static int write_modbeg (int);
141 static int write_modend (int);
142 static int write_rtnbeg (int, int);
143 static int write_rtnend (int, int);
144 static int write_pclines (int);
145 static int write_srccorr (int, dst_file_info_entry, int);
146 static int write_srccorrs (int);
148 static void vmsdbgout_init (const char *);
149 static void vmsdbgout_finish (const char *);
150 static void vmsdbgout_early_finish (const char *);
151 static void vmsdbgout_assembly_start (void);
152 static void vmsdbgout_define (unsigned int, const char *);
153 static void vmsdbgout_undef (unsigned int, const char *);
154 static void vmsdbgout_start_source_file (unsigned int, const char *);
155 static void vmsdbgout_end_source_file (unsigned int);
156 static void vmsdbgout_begin_block (unsigned int, unsigned int);
157 static void vmsdbgout_end_block (unsigned int, unsigned int);
158 static bool vmsdbgout_ignore_block (const_tree);
159 static void vmsdbgout_source_line (unsigned int, unsigned int, const char *,
160 int, bool);
161 static void vmsdbgout_write_source_line (unsigned, const char *, int , bool);
162 static void vmsdbgout_begin_prologue (unsigned int, unsigned int,
163 const char *);
164 static void vmsdbgout_end_prologue (unsigned int, const char *);
165 static void vmsdbgout_end_function (unsigned int);
166 static void vmsdbgout_begin_epilogue (unsigned int, const char *);
167 static void vmsdbgout_end_epilogue (unsigned int, const char *);
168 static void vmsdbgout_begin_function (tree);
169 static void vmsdbgout_function_decl (tree);
170 static void vmsdbgout_early_global_decl (tree);
171 static void vmsdbgout_late_global_decl (tree);
172 static void vmsdbgout_type_decl (tree, int);
173 static void vmsdbgout_abstract_function (tree);
175 /* The debug hooks structure. */
177 const struct gcc_debug_hooks vmsdbg_debug_hooks
178 = {vmsdbgout_init,
179 vmsdbgout_finish,
180 vmsdbgout_early_finish,
181 vmsdbgout_assembly_start,
182 vmsdbgout_define,
183 vmsdbgout_undef,
184 vmsdbgout_start_source_file,
185 vmsdbgout_end_source_file,
186 vmsdbgout_begin_block,
187 vmsdbgout_end_block,
188 vmsdbgout_ignore_block,
189 vmsdbgout_source_line,
190 vmsdbgout_begin_prologue,
191 vmsdbgout_end_prologue,
192 vmsdbgout_begin_epilogue,
193 vmsdbgout_end_epilogue,
194 vmsdbgout_begin_function,
195 vmsdbgout_end_function,
196 debug_nothing_tree, /* register_main_translation_unit */
197 vmsdbgout_function_decl,
198 vmsdbgout_early_global_decl,
199 vmsdbgout_late_global_decl,
200 vmsdbgout_type_decl, /* type_decl */
201 debug_nothing_tree_tree_tree_bool_bool, /* imported_module_or_decl */
202 debug_false_tree_charstarstar_uhwistar, /* die_ref_for_decl */
203 debug_nothing_tree_charstar_uhwi, /* register_external_die */
204 debug_nothing_tree, /* deferred_inline_function */
205 vmsdbgout_abstract_function,
206 debug_nothing_rtx_code_label, /* label */
207 debug_nothing_int, /* handle_pch */
208 debug_nothing_rtx_insn, /* var_location */
209 debug_nothing_tree, /* size_function */
210 debug_nothing_void, /* switch_text_section */
211 debug_nothing_tree_tree, /* set_name */
212 0, /* start_end_main_source_file */
213 TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
216 /* Definitions of defaults for assembler-dependent names of various
217 pseudo-ops and section names. */
218 #define VMS_UNALIGNED_SHORT_ASM_OP ".word"
219 #define VMS_UNALIGNED_INT_ASM_OP ".long"
220 #define VMS_UNALIGNED_LONG_ASM_OP ".long"
221 #define VMS_UNALIGNED_DOUBLE_INT_ASM_OP ".quad"
223 #define VMS_ASM_BYTE_OP ".byte"
225 #define NUMBYTES(I) ((I) < 256 ? 1 : (I) < 65536 ? 2 : 4)
227 #define NUMBYTES0(I) ((I) < 128 ? 0 : (I) < 65536 ? 2 : 4)
229 #ifndef UNALIGNED_PTR_ASM_OP
230 #define UNALIGNED_PTR_ASM_OP \
231 (PTR_SIZE == 8 ? VMS_UNALIGNED_DOUBLE_INT_ASM_OP : VMS_UNALIGNED_INT_ASM_OP)
232 #endif
234 #ifndef UNALIGNED_OFFSET_ASM_OP
235 #define UNALIGNED_OFFSET_ASM_OP(OFFSET) \
236 (NUMBYTES (OFFSET) == 4 \
237 ? VMS_UNALIGNED_LONG_ASM_OP \
238 : (NUMBYTES (OFFSET) == 2 ? VMS_UNALIGNED_SHORT_ASM_OP : VMS_ASM_BYTE_OP))
239 #endif
241 /* Definitions of defaults for formats and names of various special
242 (artificial) labels which may be generated within this file (when the -g
243 options is used and VMS_DEBUGGING_INFO is in effect. If necessary, these
244 may be overridden from within the tm.h file, but typically, overriding these
245 defaults is unnecessary. */
247 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
249 #ifndef TEXT_END_LABEL
250 #define TEXT_END_LABEL "Lvetext"
251 #endif
252 #ifndef FUNC_BEGIN_LABEL
253 #define FUNC_BEGIN_LABEL "LVFB"
254 #endif
255 #ifndef FUNC_PROLOG_LABEL
256 #define FUNC_PROLOG_LABEL "LVFP"
257 #endif
258 #ifndef FUNC_EPILOG_LABEL
259 #define FUNC_EPILOG_LABEL "LVEB"
260 #endif
261 #ifndef FUNC_END_LABEL
262 #define FUNC_END_LABEL "LVFE"
263 #endif
264 #ifndef BLOCK_BEGIN_LABEL
265 #define BLOCK_BEGIN_LABEL "LVBB"
266 #endif
267 #ifndef BLOCK_END_LABEL
268 #define BLOCK_END_LABEL "LVBE"
269 #endif
270 #ifndef LINE_CODE_LABEL
271 #define LINE_CODE_LABEL "LVM"
272 #endif
274 #ifndef ASM_OUTPUT_DEBUG_DELTA2
275 #define ASM_OUTPUT_DEBUG_DELTA2(FILE,LABEL1,LABEL2) \
276 do \
278 fprintf ((FILE), "\t%s\t", VMS_UNALIGNED_SHORT_ASM_OP); \
279 assemble_name (FILE, LABEL1); \
280 fprintf (FILE, "-"); \
281 assemble_name (FILE, LABEL2); \
283 while (0)
284 #endif
286 #ifndef ASM_OUTPUT_DEBUG_DELTA4
287 #define ASM_OUTPUT_DEBUG_DELTA4(FILE,LABEL1,LABEL2) \
288 do \
290 fprintf ((FILE), "\t%s\t", VMS_UNALIGNED_INT_ASM_OP); \
291 assemble_name (FILE, LABEL1); \
292 fprintf (FILE, "-"); \
293 assemble_name (FILE, LABEL2); \
295 while (0)
296 #endif
298 #ifndef ASM_OUTPUT_DEBUG_ADDR_DELTA
299 #define ASM_OUTPUT_DEBUG_ADDR_DELTA(FILE,LABEL1,LABEL2) \
300 do \
302 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
303 assemble_name (FILE, LABEL1); \
304 fprintf (FILE, "-"); \
305 assemble_name (FILE, LABEL2); \
307 while (0)
308 #endif
310 #ifndef ASM_OUTPUT_DEBUG_ADDR
311 #define ASM_OUTPUT_DEBUG_ADDR(FILE,LABEL) \
312 do \
314 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
315 assemble_name (FILE, LABEL); \
317 while (0)
318 #endif
320 #ifndef ASM_OUTPUT_DEBUG_ADDR_CONST
321 #define ASM_OUTPUT_DEBUG_ADDR_CONST(FILE,ADDR) \
322 fprintf ((FILE), "\t%s\t%s", UNALIGNED_PTR_ASM_OP, (ADDR))
323 #endif
325 #ifndef ASM_OUTPUT_DEBUG_DATA1
326 #define ASM_OUTPUT_DEBUG_DATA1(FILE,VALUE) \
327 fprintf ((FILE), "\t%s\t%#x", VMS_ASM_BYTE_OP, (unsigned char) VALUE)
328 #endif
330 #ifndef ASM_OUTPUT_DEBUG_DATA2
331 #define ASM_OUTPUT_DEBUG_DATA2(FILE,VALUE) \
332 fprintf ((FILE), "\t%s\t%#x", VMS_UNALIGNED_SHORT_ASM_OP, \
333 (unsigned short) VALUE)
334 #endif
336 #ifndef ASM_OUTPUT_DEBUG_DATA4
337 #define ASM_OUTPUT_DEBUG_DATA4(FILE,VALUE) \
338 fprintf ((FILE), "\t%s\t%#lx", VMS_UNALIGNED_INT_ASM_OP, \
339 (unsigned long) VALUE)
340 #endif
342 #ifndef ASM_OUTPUT_DEBUG_DATA
343 #define ASM_OUTPUT_DEBUG_DATA(FILE,VALUE) \
344 fprintf ((FILE), "\t%s\t%#lx", UNALIGNED_OFFSET_ASM_OP (VALUE), VALUE)
345 #endif
347 #ifndef ASM_OUTPUT_DEBUG_ADDR_DATA
348 #define ASM_OUTPUT_DEBUG_ADDR_DATA(FILE,VALUE) \
349 fprintf ((FILE), "\t%s\t%#lx", UNALIGNED_PTR_ASM_OP, \
350 (unsigned long) VALUE)
351 #endif
353 #ifndef ASM_OUTPUT_DEBUG_DATA8
354 #define ASM_OUTPUT_DEBUG_DATA8(FILE,VALUE) \
355 fprintf ((FILE), "\t%s\t%#llx", VMS_UNALIGNED_DOUBLE_INT_ASM_OP, \
356 (unsigned long long) VALUE)
357 #endif
359 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
360 newline is produced. When flag_verbose_asm is asserted, we add commentary
361 at the end of the line, so we must avoid output of a newline here. */
362 #ifndef ASM_OUTPUT_DEBUG_STRING
363 #define ASM_OUTPUT_DEBUG_STRING(FILE,P) \
364 do \
366 register int slen = strlen (P); \
367 register const char *p = (P); \
368 register int i; \
369 fprintf (FILE, "\t.ascii \""); \
370 for (i = 0; i < slen; i++) \
372 register int c = p[i]; \
373 if (c == '\"' || c == '\\') \
374 putc ('\\', FILE); \
375 if (c >= ' ' && c < 0177) \
376 putc (c, FILE); \
377 else \
378 fprintf (FILE, "\\%o", c); \
380 fprintf (FILE, "\""); \
382 while (0)
383 #endif
385 /* Convert a reference to the assembler name of a C-level name. This
386 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
387 a string rather than writing to a file. */
388 #ifndef ASM_NAME_TO_STRING
389 #define ASM_NAME_TO_STRING(STR, NAME) \
390 do \
392 if ((NAME)[0] == '*') \
393 strcpy (STR, NAME+1); \
394 else \
395 strcpy (STR, NAME); \
397 while (0)
398 #endif
401 /* Output the debug header HEADER. Also output COMMENT if flag_verbose_asm is
402 set. Return the header size. Just return the size if DOSIZEONLY is
403 nonzero. */
405 static int
406 write_debug_header (DST_HEADER *header, const char *comment, int dosizeonly)
408 if (!dosizeonly)
410 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
411 header->dst__header_length.dst_w_length);
413 if (flag_verbose_asm)
414 fprintf (asm_out_file, "\t%s record length", ASM_COMMENT_START);
415 fputc ('\n', asm_out_file);
417 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
418 header->dst__header_type.dst_w_type);
420 if (flag_verbose_asm)
421 fprintf (asm_out_file, "\t%s record type (%s)", ASM_COMMENT_START,
422 comment);
424 fputc ('\n', asm_out_file);
427 return 4;
430 /* Output the address of SYMBOL. Also output COMMENT if flag_verbose_asm is
431 set. Return the address size. Just return the size if DOSIZEONLY is
432 nonzero. */
434 static int
435 write_debug_addr (const char *symbol, const char *comment, int dosizeonly)
437 if (!dosizeonly)
439 ASM_OUTPUT_DEBUG_ADDR (asm_out_file, symbol);
440 if (flag_verbose_asm)
441 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
442 fputc ('\n', asm_out_file);
445 return PTR_SIZE;
448 /* Output the single byte DATA1. Also output COMMENT if flag_verbose_asm is
449 set. Return the data size. Just return the size if DOSIZEONLY is
450 nonzero. */
452 static int
453 write_debug_data1 (unsigned int data1, const char *comment, int dosizeonly)
455 if (!dosizeonly)
457 ASM_OUTPUT_DEBUG_DATA1 (asm_out_file, data1);
458 if (flag_verbose_asm)
459 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
460 fputc ('\n', asm_out_file);
463 return 1;
466 /* Output the single word DATA2. Also output COMMENT if flag_verbose_asm is
467 set. Return the data size. Just return the size if DOSIZEONLY is
468 nonzero. */
470 static int
471 write_debug_data2 (unsigned int data2, const char *comment, int dosizeonly)
473 if (!dosizeonly)
475 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file, data2);
476 if (flag_verbose_asm)
477 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
478 fputc ('\n', asm_out_file);
481 return 2;
484 /* Output double word DATA4. Also output COMMENT if flag_verbose_asm is set.
485 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
487 static int
488 write_debug_data4 (unsigned long data4, const char *comment, int dosizeonly)
490 if (!dosizeonly)
492 ASM_OUTPUT_DEBUG_DATA4 (asm_out_file, data4);
493 if (flag_verbose_asm)
494 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
495 fputc ('\n', asm_out_file);
498 return 4;
501 /* Output quad word DATA8. Also output COMMENT if flag_verbose_asm is set.
502 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
504 static int
505 write_debug_data8 (unsigned long long data8, const char *comment,
506 int dosizeonly)
508 if (!dosizeonly)
510 ASM_OUTPUT_DEBUG_DATA8 (asm_out_file, data8);
511 if (flag_verbose_asm)
512 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
513 fputc ('\n', asm_out_file);
516 return 8;
519 /* Output the difference between LABEL1 and LABEL2. Also output COMMENT if
520 flag_verbose_asm is set. Return the data size. Just return the size if
521 DOSIZEONLY is nonzero. */
523 static int
524 write_debug_delta4 (const char *label1, const char *label2,
525 const char *comment, int dosizeonly)
527 if (!dosizeonly)
529 ASM_OUTPUT_DEBUG_DELTA4 (asm_out_file, label1, label2);
530 if (flag_verbose_asm)
531 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
532 fputc ('\n', asm_out_file);
535 return 4;
538 /* Output a character string STRING. Also write COMMENT if flag_verbose_asm is
539 set. Return the string length. Just return the length if DOSIZEONLY is
540 nonzero. */
542 static int
543 write_debug_string (const char *string, const char *comment, int dosizeonly)
545 if (!dosizeonly)
547 ASM_OUTPUT_DEBUG_STRING (asm_out_file, string);
548 if (flag_verbose_asm)
549 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
550 fputc ('\n', asm_out_file);
553 return strlen (string);
556 /* Output a module begin header and return the header size. Just return the
557 size if DOSIZEONLY is nonzero. */
559 static int
560 write_modbeg (int dosizeonly)
562 DST_MODULE_BEGIN modbeg;
563 DST_MB_TRLR mb_trlr;
564 int i;
565 char *module_name, *m;
566 int modnamelen;
567 int prodnamelen;
568 int totsize = 0;
570 /* Assumes primary filename has Unix syntax file spec. */
571 module_name = xstrdup (lbasename (primary_filename));
573 m = strrchr (module_name, '.');
574 if (m)
575 *m = 0;
577 modnamelen = strlen (module_name);
578 for (i = 0; i < modnamelen; i++)
579 module_name[i] = TOUPPER (module_name[i]);
581 prodnamelen = strlen (module_producer);
583 modbeg.dst_a_modbeg_header.dst__header_length.dst_w_length
584 = DST_K_MODBEG_SIZE + modnamelen + DST_K_MB_TRLR_SIZE + prodnamelen - 1;
585 modbeg.dst_a_modbeg_header.dst__header_type.dst_w_type = DST_K_MODBEG;
586 modbeg.dst_b_modbeg_flags.dst_v_modbeg_hide = 0;
587 modbeg.dst_b_modbeg_flags.dst_v_modbeg_version = 1;
588 modbeg.dst_b_modbeg_flags.dst_v_modbeg_unused = 0;
589 modbeg.dst_b_modbeg_unused = 0;
590 modbeg.dst_l_modbeg_language = (DST_LANGUAGE) module_language;
591 modbeg.dst_w_version_major = DST_K_VERSION_MAJOR;
592 modbeg.dst_w_version_minor = DST_K_VERSION_MINOR;
593 modbeg.dst_b_modbeg_name = strlen (module_name);
595 mb_trlr.dst_b_compiler = strlen (module_producer);
597 totsize += write_debug_header (&modbeg.dst_a_modbeg_header,
598 "modbeg", dosizeonly);
599 totsize += write_debug_data1 (*((char *) &modbeg.dst_b_modbeg_flags),
600 "flags", dosizeonly);
601 totsize += write_debug_data1 (modbeg.dst_b_modbeg_unused,
602 "unused", dosizeonly);
603 totsize += write_debug_data4 (modbeg.dst_l_modbeg_language,
604 "language", dosizeonly);
605 totsize += write_debug_data2 (modbeg.dst_w_version_major,
606 "DST major version", dosizeonly);
607 totsize += write_debug_data2 (modbeg.dst_w_version_minor,
608 "DST minor version", dosizeonly);
609 totsize += write_debug_data1 (modbeg.dst_b_modbeg_name,
610 "length of module name", dosizeonly);
611 totsize += write_debug_string (module_name, "module name", dosizeonly);
612 totsize += write_debug_data1 (mb_trlr.dst_b_compiler,
613 "length of compiler name", dosizeonly);
614 totsize += write_debug_string (module_producer, "compiler name", dosizeonly);
616 return totsize;
619 /* Output a module end trailer and return the trailer size. Just return
620 the size if DOSIZEONLY is nonzero. */
622 static int
623 write_modend (int dosizeonly)
625 DST_MODULE_END modend;
626 int totsize = 0;
628 modend.dst_a_modend_header.dst__header_length.dst_w_length
629 = DST_K_MODEND_SIZE - 1;
630 modend.dst_a_modend_header.dst__header_type.dst_w_type = DST_K_MODEND;
632 totsize += write_debug_header (&modend.dst_a_modend_header, "modend",
633 dosizeonly);
635 return totsize;
638 /* Output a routine begin header routine RTNNUM and return the header size.
639 Just return the size if DOSIZEONLY is nonzero. */
641 static int
642 write_rtnbeg (int rtnnum, int dosizeonly)
644 const char *rtnname;
645 int rtnnamelen;
646 char *rtnentryname;
647 int totsize = 0;
648 char label[MAX_ARTIFICIAL_LABEL_BYTES];
649 DST_ROUTINE_BEGIN rtnbeg;
650 DST_PROLOG prolog;
652 rtnname = funcnam_table[rtnnum];
653 rtnnamelen = strlen (rtnname);
654 rtnentryname = concat (rtnname, "..en", NULL);
656 if (!strcmp (rtnname, "main"))
658 DST_HEADER header;
659 const char *go = "TRANSFER$BREAK$GO";
661 /* This command isn't documented in DSTRECORDS, so it's made to
662 look like what DEC C does */
664 /* header size - 1st byte + flag byte + STO_LW size
665 + string count byte + string length */
666 header.dst__header_length.dst_w_length
667 = DST_K_DST_HEADER_SIZE - 1 + 1 + 4 + 1 + strlen (go);
668 header.dst__header_type.dst_w_type = DST_K_TBG;
670 totsize += write_debug_header (&header, "transfer", dosizeonly);
672 /* I think this is a flag byte, but I don't know what this flag means */
673 totsize += write_debug_data1 (0x1, "flags ???", dosizeonly);
675 /* Routine Begin PD Address */
676 totsize += write_debug_addr (rtnname, "main procedure descriptor",
677 dosizeonly);
678 totsize += write_debug_data1 (strlen (go), "length of main_name",
679 dosizeonly);
680 totsize += write_debug_string (go, "main name", dosizeonly);
683 /* The header length never includes the length byte. */
684 rtnbeg.dst_a_rtnbeg_header.dst__header_length.dst_w_length
685 = DST_K_RTNBEG_SIZE + rtnnamelen - 1;
686 rtnbeg.dst_a_rtnbeg_header.dst__header_type.dst_w_type = DST_K_RTNBEG;
687 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unused = 0;
688 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unalloc = 0;
689 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_prototype = 0;
690 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_inlined = 0;
691 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_no_call = 1;
692 rtnbeg.dst_b_rtnbeg_name = rtnnamelen;
694 totsize += write_debug_header (&rtnbeg.dst_a_rtnbeg_header, "rtnbeg",
695 dosizeonly);
696 totsize += write_debug_data1 (*((char *) &rtnbeg.dst_b_rtnbeg_flags),
697 "flags", dosizeonly);
699 /* Routine Begin Address */
700 totsize += write_debug_addr (rtnentryname, "routine entry name", dosizeonly);
702 /* Routine Begin PD Address */
703 totsize += write_debug_addr (rtnname, "routine procedure descriptor",
704 dosizeonly);
706 /* Routine Begin Name */
707 totsize += write_debug_data1 (rtnbeg.dst_b_rtnbeg_name,
708 "length of routine name", dosizeonly);
710 totsize += write_debug_string (rtnname, "routine name", dosizeonly);
712 free (rtnentryname);
714 if (debug_info_level > DINFO_LEVEL_TERSE)
716 prolog.dst_a_prolog_header.dst__header_length.dst_w_length
717 = DST_K_PROLOG_SIZE - 1;
718 prolog.dst_a_prolog_header.dst__header_type.dst_w_type = DST_K_PROLOG;
720 totsize += write_debug_header (&prolog.dst_a_prolog_header, "prolog",
721 dosizeonly);
723 ASM_GENERATE_INTERNAL_LABEL
724 (label, FUNC_PROLOG_LABEL,
725 funcnum_table[rtnnum]);
726 totsize += write_debug_addr (label, "prolog breakpoint addr",
727 dosizeonly);
730 return totsize;
733 /* Output a routine end trailer for routine RTNNUM and return the header size.
734 Just return the size if DOSIZEONLY is nonzero. */
736 static int
737 write_rtnend (int rtnnum, int dosizeonly)
739 DST_ROUTINE_END rtnend;
740 char label1[MAX_ARTIFICIAL_LABEL_BYTES];
741 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
742 int totsize;
744 totsize = 0;
746 rtnend.dst_a_rtnend_header.dst__header_length.dst_w_length
747 = DST_K_RTNEND_SIZE - 1;
748 rtnend.dst_a_rtnend_header.dst__header_type.dst_w_type = DST_K_RTNEND;
749 rtnend.dst_b_rtnend_unused = 0;
750 rtnend.dst_l_rtnend_size = 0; /* Calculated below. */
752 totsize += write_debug_header (&rtnend.dst_a_rtnend_header, "rtnend",
753 dosizeonly);
754 totsize += write_debug_data1 (rtnend.dst_b_rtnend_unused, "unused",
755 dosizeonly);
757 ASM_GENERATE_INTERNAL_LABEL
758 (label1, FUNC_BEGIN_LABEL,
759 funcnum_table[rtnnum]);
760 ASM_GENERATE_INTERNAL_LABEL
761 (label2, FUNC_END_LABEL,
762 funcnum_table[rtnnum]);
763 totsize += write_debug_delta4 (label2, label1, "routine size", dosizeonly);
765 return totsize;
768 #define K_DELTA_PC(I) \
769 ((I) < 128 ? -(I) : (I) < 65536 ? DST_K_DELTA_PC_W : DST_K_DELTA_PC_L)
771 #define K_SET_LINUM(I) \
772 ((I) < 256 ? DST_K_SET_LINUM_B \
773 : (I) < 65536 ? DST_K_SET_LINUM : DST_K_SET_LINUM_L)
775 #define K_INCR_LINUM(I) \
776 ((I) < 256 ? DST_K_INCR_LINUM \
777 : (I) < 65536 ? DST_K_INCR_LINUM_W : DST_K_INCR_LINUM_L)
779 /* Output the PC to line number correlations and return the size. Just return
780 the size if DOSIZEONLY is nonzero */
782 static int
783 write_pclines (int dosizeonly)
785 unsigned i;
786 int fn;
787 int ln, lastln;
788 int linestart = 0;
789 int max_line;
790 DST_LINE_NUM_HEADER line_num;
791 DST_PCLINE_COMMANDS pcline;
792 char label[MAX_ARTIFICIAL_LABEL_BYTES];
793 char lastlabel[MAX_ARTIFICIAL_LABEL_BYTES];
794 int totsize = 0;
795 char buff[256];
797 max_line = file_info_table[1].max_line;
798 file_info_table[1].listing_line_start = linestart;
799 linestart = linestart + ((max_line / 100000) + 1) * 100000;
801 for (i = 2; i < file_info_table_in_use; i++)
803 max_line = file_info_table[i].max_line;
804 file_info_table[i].listing_line_start = linestart;
805 linestart = linestart + ((max_line / 10000) + 1) * 10000;
808 /* Set starting address to beginning of text section. */
809 line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 8;
810 line_num.dst_a_line_num_header.dst__header_type.dst_w_type = DST_K_LINE_NUM;
811 pcline.dst_b_pcline_command = DST_K_SET_ABS_PC;
813 totsize += write_debug_header (&line_num.dst_a_line_num_header,
814 "line_num", dosizeonly);
815 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
816 "line_num (SET ABS PC)", dosizeonly);
818 if (dosizeonly)
819 totsize += 4;
820 else
822 ASM_OUTPUT_DEBUG_ADDR (asm_out_file, TEXT_SECTION_ASM_OP);
823 if (flag_verbose_asm)
824 fprintf (asm_out_file, "\t%s line_num", ASM_COMMENT_START);
825 fputc ('\n', asm_out_file);
828 fn = line_info_table[1].dst_file_num;
829 ln = (file_info_table[fn].listing_line_start
830 + line_info_table[1].dst_line_num);
831 line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 4 + 4;
832 pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
834 totsize += write_debug_header (&line_num.dst_a_line_num_header,
835 "line_num", dosizeonly);
836 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
837 "line_num (SET LINUM LONG)", dosizeonly);
839 sprintf (buff, "line_num (%d)", ln ? ln - 1 : 0);
840 totsize += write_debug_data4 (ln ? ln - 1 : 0, buff, dosizeonly);
842 lastln = ln;
843 strcpy (lastlabel, TEXT_SECTION_ASM_OP);
844 for (i = 1; i < line_info_table_in_use; i++)
846 int extrabytes;
848 fn = line_info_table[i].dst_file_num;
849 ln = (file_info_table[fn].listing_line_start
850 + line_info_table[i].dst_line_num);
852 if (ln - lastln > 1)
853 extrabytes = 5; /* NUMBYTES (ln - lastln - 1) + 1; */
854 else if (ln <= lastln)
855 extrabytes = 5; /* NUMBYTES (ln - 1) + 1; */
856 else
857 extrabytes = 0;
859 line_num.dst_a_line_num_header.dst__header_length.dst_w_length
860 = 8 + extrabytes;
862 totsize += write_debug_header
863 (&line_num.dst_a_line_num_header, "line_num", dosizeonly);
865 if (ln - lastln > 1)
867 int lndif = ln - lastln - 1;
869 /* K_INCR_LINUM (lndif); */
870 pcline.dst_b_pcline_command = DST_K_INCR_LINUM_L;
872 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
873 "line_num (INCR LINUM LONG)",
874 dosizeonly);
876 sprintf (buff, "line_num (%d)", lndif);
877 totsize += write_debug_data4 (lndif, buff, dosizeonly);
879 else if (ln <= lastln)
881 /* K_SET_LINUM (ln-1); */
882 pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
884 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
885 "line_num (SET LINUM LONG)",
886 dosizeonly);
888 sprintf (buff, "line_num (%d)", ln - 1);
889 totsize += write_debug_data4 (ln - 1, buff, dosizeonly);
892 pcline.dst_b_pcline_command = DST_K_DELTA_PC_L;
894 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
895 "line_num (DELTA PC LONG)", dosizeonly);
897 ASM_GENERATE_INTERNAL_LABEL (label, LINE_CODE_LABEL, i);
898 totsize += write_debug_delta4 (label, lastlabel, "increment line_num",
899 dosizeonly);
901 lastln = ln;
902 strcpy (lastlabel, label);
905 return totsize;
908 /* Output a source correlation for file FILEID using information saved in
909 FILE_INFO_ENTRY and return the size. Just return the size if DOSIZEONLY is
910 nonzero. */
912 static int
913 write_srccorr (int fileid, dst_file_info_entry file_info_entry,
914 int dosizeonly)
916 int src_command_size;
917 int linesleft = file_info_entry.max_line;
918 int linestart = file_info_entry.listing_line_start;
919 int flen = strlen (file_info_entry.file_name);
920 int linestodo = 0;
921 DST_SOURCE_CORR src_header;
922 DST_SRC_COMMAND src_command;
923 DST_SRC_COMMAND src_command_sf;
924 DST_SRC_COMMAND src_command_sl;
925 DST_SRC_COMMAND src_command_sr;
926 DST_SRC_COMMAND src_command_dl;
927 DST_SRC_CMDTRLR src_cmdtrlr;
928 char buff[256];
929 int totsize = 0;
931 if (fileid == 1)
933 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
934 = DST_K_SOURCE_CORR_HEADER_SIZE + 1 - 1;
935 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
936 = DST_K_SOURCE;
937 src_command.dst_b_src_command = DST_K_SRC_FORMFEED;
939 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
940 "source corr", dosizeonly);
942 totsize += write_debug_data1 (src_command.dst_b_src_command,
943 "source_corr (SRC FORMFEED)",
944 dosizeonly);
947 src_command_size
948 = DST_K_SRC_COMMAND_SIZE + flen + DST_K_SRC_CMDTRLR_SIZE;
949 src_command.dst_b_src_command = DST_K_SRC_DECLFILE;
950 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length
951 = src_command_size - 2;
952 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags = 0;
953 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid
954 = fileid;
955 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt
956 = file_info_entry.cdt;
957 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk
958 = file_info_entry.ebk;
959 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb
960 = file_info_entry.ffb;
961 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo
962 = file_info_entry.rfo;
963 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename
964 = flen;
966 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
967 = DST_K_SOURCE_CORR_HEADER_SIZE + src_command_size - 1;
968 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
969 = DST_K_SOURCE;
971 src_cmdtrlr.dst_b_src_df_libmodname = 0;
973 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
974 "source corr", dosizeonly);
975 totsize += write_debug_data1 (src_command.dst_b_src_command,
976 "source_corr (DECL SRC FILE)", dosizeonly);
977 totsize += write_debug_data1
978 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length,
979 "source_corr (length)", dosizeonly);
981 totsize += write_debug_data1
982 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags,
983 "source_corr (flags)", dosizeonly);
985 totsize += write_debug_data2
986 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid,
987 "source_corr (fileid)", dosizeonly);
989 totsize += write_debug_data8
990 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt,
991 "source_corr (creation date)", dosizeonly);
993 totsize += write_debug_data4
994 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk,
995 "source_corr (EOF block number)", dosizeonly);
997 totsize += write_debug_data2
998 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb,
999 "source_corr (first free byte)", dosizeonly);
1001 totsize += write_debug_data1
1002 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo,
1003 "source_corr (record and file organization)", dosizeonly);
1005 totsize += write_debug_data1
1006 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename,
1007 "source_corr (filename length)", dosizeonly);
1009 totsize += write_debug_string (remap_debug_filename (
1010 file_info_entry.file_name),
1011 "source file name", dosizeonly);
1012 totsize += write_debug_data1 (src_cmdtrlr.dst_b_src_df_libmodname,
1013 "source_corr (libmodname)", dosizeonly);
1015 src_command_sf.dst_b_src_command = DST_K_SRC_SETFILE;
1016 src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword = fileid;
1018 src_command_sr.dst_b_src_command = DST_K_SRC_SETREC_W;
1019 src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword = 1;
1021 src_command_sl.dst_b_src_command = DST_K_SRC_SETLNUM_L;
1022 src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong = linestart + 1;
1024 src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1026 if (linesleft > 65534)
1027 linesleft = linesleft - 65534, linestodo = 65534;
1028 else
1029 linestodo = linesleft, linesleft = 0;
1031 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1033 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1034 = DST_K_SOURCE_CORR_HEADER_SIZE + 3 + 3 + 5 + 3 - 1;
1035 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1036 = DST_K_SOURCE;
1038 if (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword)
1040 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1041 "source corr", dosizeonly);
1043 totsize += write_debug_data1 (src_command_sf.dst_b_src_command,
1044 "source_corr (src setfile)", dosizeonly);
1046 totsize += write_debug_data2
1047 (src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword,
1048 "source_corr (fileid)", dosizeonly);
1050 totsize += write_debug_data1 (src_command_sr.dst_b_src_command,
1051 "source_corr (setrec)", dosizeonly);
1053 totsize += write_debug_data2
1054 (src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword,
1055 "source_corr (recnum)", dosizeonly);
1057 totsize += write_debug_data1 (src_command_sl.dst_b_src_command,
1058 "source_corr (setlnum)", dosizeonly);
1060 totsize += write_debug_data4
1061 (src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong,
1062 "source_corr (linenum)", dosizeonly);
1064 totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1065 "source_corr (deflines)", dosizeonly);
1067 sprintf (buff, "source_corr (%d)",
1068 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1069 totsize += write_debug_data2
1070 (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
1071 buff, dosizeonly);
1073 while (linesleft > 0)
1075 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1076 = DST_K_SOURCE_CORR_HEADER_SIZE + 3 - 1;
1077 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1078 = DST_K_SOURCE;
1079 src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1081 if (linesleft > 65534)
1082 linesleft = linesleft - 65534, linestodo = 65534;
1083 else
1084 linestodo = linesleft, linesleft = 0;
1086 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1088 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1089 "source corr", dosizeonly);
1090 totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1091 "source_corr (deflines)", dosizeonly);
1092 sprintf (buff, "source_corr (%d)",
1093 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1094 totsize += write_debug_data2
1095 (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
1096 buff, dosizeonly);
1100 return totsize;
1103 /* Output all the source correlation entries and return the size. Just return
1104 the size if DOSIZEONLY is nonzero. */
1106 static int
1107 write_srccorrs (int dosizeonly)
1109 unsigned int i;
1110 int totsize = 0;
1112 for (i = 1; i < file_info_table_in_use; i++)
1113 totsize += write_srccorr (i, file_info_table[i], dosizeonly);
1115 return totsize;
1118 /* Output a marker (i.e. a label) for the beginning of a function, before
1119 the prologue. */
1121 static void
1122 vmsdbgout_begin_prologue (unsigned int line, unsigned int column,
1123 const char *file)
1125 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1127 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1128 (*dwarf2_debug_hooks.begin_prologue) (line, column, file);
1130 if (debug_info_level > DINFO_LEVEL_NONE)
1132 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1133 current_function_funcdef_no);
1134 ASM_OUTPUT_LABEL (asm_out_file, label);
1138 /* Output a marker (i.e. a label) for the beginning of a function, after
1139 the prologue. */
1141 static void
1142 vmsdbgout_end_prologue (unsigned int line, const char *file)
1144 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1146 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1147 (*dwarf2_debug_hooks.end_prologue) (line, file);
1149 if (debug_info_level > DINFO_LEVEL_TERSE)
1151 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_PROLOG_LABEL,
1152 current_function_funcdef_no);
1153 ASM_OUTPUT_LABEL (asm_out_file, label);
1155 /* VMS PCA expects every PC range to correlate to some line and file. */
1156 vmsdbgout_write_source_line (line, file, 0, true);
1160 /* No output for VMS debug, but make obligatory call to Dwarf2 debug */
1162 static void
1163 vmsdbgout_end_function (unsigned int line)
1165 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1166 (*dwarf2_debug_hooks.end_function) (line);
1169 /* Output a marker (i.e. a label) for the beginning of the epilogue.
1170 This gets called *before* the epilogue code has been generated. */
1172 static void
1173 vmsdbgout_begin_epilogue (unsigned int line, const char *file)
1175 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1176 static int save_current_function_funcdef_no = -1;
1178 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1179 (*dwarf2_debug_hooks.begin_epilogue) (line, file);
1181 if (debug_info_level > DINFO_LEVEL_NONE)
1183 if (save_current_function_funcdef_no != current_function_funcdef_no)
1185 /* Output a label to mark the endpoint of the code generated for this
1186 function. */
1187 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_EPILOG_LABEL,
1188 current_function_funcdef_no);
1190 ASM_OUTPUT_LABEL (asm_out_file, label);
1192 save_current_function_funcdef_no = current_function_funcdef_no;
1194 /* VMS PCA expects every PC range to correlate to some line and
1195 file. */
1196 vmsdbgout_write_source_line (line, file, 0, true);
1201 /* Output a marker (i.e. a label) for the absolute end of the generated code
1202 for a function definition. This gets called *after* the epilogue code has
1203 been generated. */
1205 static void
1206 vmsdbgout_end_epilogue (unsigned int line, const char *file)
1208 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1210 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1211 (*dwarf2_debug_hooks.end_epilogue) (line, file);
1213 if (debug_info_level > DINFO_LEVEL_NONE)
1215 /* Output a label to mark the endpoint of the code generated for this
1216 function. */
1217 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1218 current_function_funcdef_no);
1219 ASM_OUTPUT_LABEL (asm_out_file, label);
1221 /* VMS PCA expects every PC range to correlate to some line and file. */
1222 vmsdbgout_write_source_line (line, file, 0, true);
1226 /* Output a marker (i.e. a label) for the beginning of the generated code for
1227 a lexical block. */
1229 static void
1230 vmsdbgout_begin_block (register unsigned line, register unsigned blocknum)
1232 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1233 (*dwarf2_debug_hooks.begin_block) (line, blocknum);
1235 if (debug_info_level > DINFO_LEVEL_TERSE)
1236 targetm.asm_out.internal_label (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
1239 /* Output a marker (i.e. a label) for the end of the generated code for a
1240 lexical block. */
1242 static void
1243 vmsdbgout_end_block (register unsigned line, register unsigned blocknum)
1245 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1246 (*dwarf2_debug_hooks.end_block) (line, blocknum);
1248 if (debug_info_level > DINFO_LEVEL_TERSE)
1249 targetm.asm_out.internal_label (asm_out_file, BLOCK_END_LABEL, blocknum);
1252 /* Not implemented in VMS Debug. */
1254 static bool
1255 vmsdbgout_ignore_block (const_tree block)
1257 bool retval = 0;
1259 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1260 retval = (*dwarf2_debug_hooks.ignore_block) (block);
1262 return retval;
1265 /* Add an entry for function DECL into the funcnam_table. */
1267 static void
1268 vmsdbgout_begin_function (tree decl)
1270 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1272 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1273 (*dwarf2_debug_hooks.begin_function) (decl);
1275 /* Add the new entry to the end of the function name table. */
1276 funcnam_table.safe_push (xstrdup (name));
1277 funcnum_table.safe_push (current_function_funcdef_no);
1280 static char fullname_buff [4096];
1282 /* Return the full file specification for FILENAME. The specification must be
1283 in VMS syntax in order to be processed by VMS Debug. */
1285 static char *
1286 full_name (const char *filename)
1288 #ifdef VMS
1289 FILE *fp = fopen (filename, "r");
1291 fgetname (fp, fullname_buff, 1);
1292 fclose (fp);
1293 #else
1294 /* Unix paths really mess up VMS debug. Better to just output the
1295 base filename. */
1296 strcpy (fullname_buff, filename);
1297 #endif
1299 return fullname_buff;
1302 /* Lookup a filename (in the list of filenames that we know about here in
1303 vmsdbgout.c) and return its "index". The index of each (known) filename is
1304 just a unique number which is associated with only that one filename. We
1305 need such numbers for the sake of generating labels and references
1306 to those files numbers. If the filename given as an argument is not
1307 found in our current list, add it to the list and assign it the next
1308 available unique index number. In order to speed up searches, we remember
1309 the index of the filename was looked up last. This handles the majority of
1310 all searches. */
1312 static unsigned int
1313 lookup_filename (const char *file_name)
1315 static unsigned int last_file_lookup_index = 0;
1316 register char *fn;
1317 register unsigned i;
1318 const char *fnam;
1319 long long cdt = 0;
1320 long ebk = 0;
1321 short ffb = 0;
1322 char rfo = 0;
1323 long siz = 0;
1324 int ver = 0;
1326 fnam = full_name (file_name);
1328 /* Check to see if the file name that was searched on the previous call
1329 matches this file name. If so, return the index. */
1330 if (last_file_lookup_index != 0)
1332 fn = file_info_table[last_file_lookup_index].file_name;
1333 if (strcmp (fnam, fn) == 0)
1334 return last_file_lookup_index;
1337 /* Didn't match the previous lookup, search the table */
1338 for (i = 1; i < file_info_table_in_use; ++i)
1340 fn = file_info_table[i].file_name;
1341 if (strcmp (fnam, fn) == 0)
1343 last_file_lookup_index = i;
1344 return i;
1348 /* Prepare to add a new table entry by making sure there is enough space in
1349 the table to do so. If not, expand the current table. */
1350 if (file_info_table_in_use == file_info_table_allocated)
1353 file_info_table_allocated += FILE_TABLE_INCREMENT;
1354 file_info_table = XRESIZEVEC (dst_file_info_entry, file_info_table,
1355 file_info_table_allocated);
1358 if (vms_file_stats_name (file_name, &cdt, &siz, &rfo, &ver) == 0)
1360 ebk = siz / 512 + 1;
1361 ffb = siz - ((siz / 512) * 512);
1364 /* Add the new entry to the end of the filename table. */
1365 file_info_table[file_info_table_in_use].file_name = xstrdup (fnam);
1366 file_info_table[file_info_table_in_use].max_line = 0;
1367 file_info_table[file_info_table_in_use].cdt = cdt;
1368 file_info_table[file_info_table_in_use].ebk = ebk;
1369 file_info_table[file_info_table_in_use].ffb = ffb;
1370 file_info_table[file_info_table_in_use].rfo = rfo;
1372 last_file_lookup_index = file_info_table_in_use++;
1373 return last_file_lookup_index;
1376 /* Output a label to mark the beginning of a source code line entry
1377 and record information relating to this source line, in
1378 'line_info_table' for later output of the .debug_line section. */
1380 static void
1381 vmsdbgout_write_source_line (unsigned line, const char *filename,
1382 int /* discriminator */, bool /* is_stmt */)
1384 dst_line_info_ref line_info;
1386 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
1387 line_info_table_in_use);
1389 /* Expand the line info table if necessary. */
1390 if (line_info_table_in_use == line_info_table_allocated)
1392 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
1393 line_info_table = XRESIZEVEC (dst_line_info_entry, line_info_table,
1394 line_info_table_allocated);
1397 /* Add the new entry at the end of the line_info_table. */
1398 line_info = &line_info_table[line_info_table_in_use++];
1399 line_info->dst_file_num = lookup_filename (filename);
1400 line_info->dst_line_num = line;
1401 if (line > file_info_table[line_info->dst_file_num].max_line)
1402 file_info_table[line_info->dst_file_num].max_line = line;
1405 static void
1406 vmsdbgout_source_line (register unsigned line, unsigned int column,
1407 register const char *filename,
1408 int discriminator, bool is_stmt)
1410 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1411 (*dwarf2_debug_hooks.source_line) (line, column, filename, discriminator,
1412 is_stmt);
1414 if (debug_info_level >= DINFO_LEVEL_TERSE)
1415 vmsdbgout_write_source_line (line, filename, discriminator, is_stmt);
1418 /* Record the beginning of a new source file, for later output.
1419 At present, unimplemented. */
1421 static void
1422 vmsdbgout_start_source_file (unsigned int lineno, const char *filename)
1424 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1425 (*dwarf2_debug_hooks.start_source_file) (lineno, filename);
1428 /* Record the end of a source file, for later output.
1429 At present, unimplemented. */
1431 static void
1432 vmsdbgout_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
1434 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1435 (*dwarf2_debug_hooks.end_source_file) (lineno);
1438 /* Set up for Debug output at the start of compilation. */
1440 static void
1441 vmsdbgout_init (const char *filename)
1443 const char *language_string = lang_hooks.name;
1445 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1446 (*dwarf2_debug_hooks.init) (filename);
1448 if (debug_info_level == DINFO_LEVEL_NONE)
1449 return;
1451 /* Remember the name of the primary input file. */
1452 primary_filename = filename;
1454 /* Allocate the initial hunk of the file_info_table. */
1455 file_info_table = XCNEWVEC (dst_file_info_entry, FILE_TABLE_INCREMENT);
1456 file_info_table_allocated = FILE_TABLE_INCREMENT;
1457 /* Skip the first entry - file numbers begin at 1. */
1458 file_info_table_in_use = 1;
1460 funcnam_table.create (FUNC_TABLE_INITIAL);
1461 funcnum_table.create (FUNC_TABLE_INITIAL);
1463 /* Allocate the initial hunk of the line_info_table. */
1464 line_info_table = XCNEWVEC (dst_line_info_entry, LINE_INFO_TABLE_INCREMENT);
1465 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
1466 /* zero-th entry is allocated, but unused */
1467 line_info_table_in_use = 1;
1469 lookup_filename (primary_filename);
1471 if (lang_GNU_C ())
1472 module_language = DST_K_C;
1473 else if (lang_GNU_CXX ())
1474 module_language = DST_K_CXX;
1475 else if (!strcmp (language_string, "GNU Ada"))
1476 module_language = DST_K_ADA;
1477 else if (!strcmp (language_string, "GNU F77"))
1478 module_language = DST_K_FORTRAN;
1479 else
1480 module_language = DST_K_UNKNOWN;
1482 module_producer = concat (language_string, " ", version_string, NULL);
1484 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
1488 /* Not implemented in VMS Debug. */
1490 static void
1491 vmsdbgout_assembly_start (void)
1493 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1494 (*dwarf2_debug_hooks.assembly_start) ();
1497 /* Not implemented in VMS Debug. */
1499 static void
1500 vmsdbgout_define (unsigned int lineno, const char *buffer)
1502 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1503 (*dwarf2_debug_hooks.define) (lineno, buffer);
1506 /* Not implemented in VMS Debug. */
1508 static void
1509 vmsdbgout_undef (unsigned int lineno, const char *buffer)
1511 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1512 (*dwarf2_debug_hooks.undef) (lineno, buffer);
1515 /* Not implemented in VMS Debug. */
1517 static void
1518 vmsdbgout_function_decl (tree decl)
1520 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1521 (*dwarf2_debug_hooks.function_decl) (decl);
1524 /* Not implemented in VMS Debug. */
1526 static void
1527 vmsdbgout_early_global_decl (tree decl)
1529 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1530 (*dwarf2_debug_hooks.early_global_decl) (decl);
1533 /* Not implemented in VMS Debug. */
1535 static void
1536 vmsdbgout_late_global_decl (tree decl)
1538 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1539 (*dwarf2_debug_hooks.late_global_decl) (decl);
1542 /* Not implemented in VMS Debug. */
1544 static void
1545 vmsdbgout_type_decl (tree decl, int local)
1547 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1548 (*dwarf2_debug_hooks.type_decl) (decl, local);
1551 /* Not implemented in VMS Debug. */
1553 static void
1554 vmsdbgout_abstract_function (tree decl)
1556 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1557 (*dwarf2_debug_hooks.outlining_inline_function) (decl);
1560 static void
1561 vmsdbgout_early_finish (const char *filename)
1563 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1564 (*dwarf2_debug_hooks.early_finish) (filename);
1567 /* Output stuff that Debug requires at the end of every file and generate the
1568 VMS Debug debugging info. */
1570 static void
1571 vmsdbgout_finish (const char *filename ATTRIBUTE_UNUSED)
1573 unsigned int i, ifunc;
1574 int totsize;
1576 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1577 (*dwarf2_debug_hooks.finish) (filename);
1579 if (debug_info_level == DINFO_LEVEL_NONE)
1580 return;
1582 /* Output a terminator label for the .text section. */
1583 switch_to_section (text_section);
1584 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
1586 /* Output debugging information.
1587 Warning! Do not change the name of the .vmsdebug section without
1588 changing it in the assembler also. */
1589 switch_to_section (get_named_section (NULL, ".vmsdebug", 0));
1590 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1592 totsize = write_modbeg (1);
1593 FOR_EACH_VEC_ELT (funcnum_table, i, ifunc)
1595 totsize += write_rtnbeg (i, 1);
1596 totsize += write_rtnend (i, 1);
1598 totsize += write_pclines (1);
1600 write_modbeg (0);
1601 FOR_EACH_VEC_ELT (funcnum_table, i, ifunc)
1603 write_rtnbeg (i, 0);
1604 write_rtnend (i, 0);
1606 write_pclines (0);
1608 if (debug_info_level > DINFO_LEVEL_TERSE)
1610 totsize = write_srccorrs (1);
1611 write_srccorrs (0);
1614 totsize = write_modend (1);
1615 write_modend (0);
1618 /* Need for both Dwarf2 on IVMS and VMS Debug on AVMS */
1620 #ifdef VMS
1621 #define __NEW_STARLET 1
1622 #include <vms/rms.h>
1623 #include <vms/atrdef.h>
1624 #include <vms/fibdef.h>
1625 #include <vms/stsdef.h>
1626 #include <vms/iodef.h>
1627 #include <vms/fatdef.h>
1628 #include <vms/descrip.h>
1629 #include <unixlib.h>
1631 #define MAXPATH 256
1633 /* descrip.h doesn't have everything ... */
1634 typedef struct fibdef* __fibdef_ptr32 __attribute__ (( mode (SI) ));
1635 struct dsc$descriptor_fib
1637 unsigned int fib$l_len;
1638 __fibdef_ptr32 fib$l_addr;
1641 /* I/O Status Block. */
1642 struct IOSB
1644 unsigned short status, count;
1645 unsigned int devdep;
1648 static char *tryfile;
1650 /* Variable length string. */
1651 struct vstring
1653 short length;
1654 char string[NAM$C_MAXRSS+1];
1657 static char filename_buff [MAXPATH];
1658 static char vms_filespec [MAXPATH];
1660 /* Callback function for filespec style conversion. */
1662 static int
1663 translate_unix (char *name, int type ATTRIBUTE_UNUSED)
1665 strncpy (filename_buff, name, MAXPATH);
1666 filename_buff [MAXPATH - 1] = (char) 0;
1667 return 0;
1670 /* Wrapper for DECC function that converts a Unix filespec
1671 to VMS style filespec. */
1673 static char *
1674 to_vms_file_spec (char *filespec)
1676 strncpy (vms_filespec, "", MAXPATH);
1677 decc$to_vms (filespec, translate_unix, 1, 1);
1678 strncpy (vms_filespec, filename_buff, MAXPATH);
1680 vms_filespec [MAXPATH - 1] = (char) 0;
1682 return vms_filespec;
1685 #else
1686 #define VMS_EPOCH_OFFSET 35067168000000000LL
1687 #define VMS_GRANULARITY_FACTOR 10000000
1688 #endif
1690 /* Return VMS file date, size, format, version given a name. */
1693 vms_file_stats_name (const char *filename, long long *cdt, long *siz, char *rfo,
1694 int *ver)
1696 #ifdef VMS
1697 struct FAB fab;
1698 struct NAM nam;
1700 unsigned long long create;
1701 FAT recattr;
1702 char ascnamebuff [256];
1704 ATRDEF atrlst[]
1706 { ATR$S_CREDATE, ATR$C_CREDATE, &create },
1707 { ATR$S_RECATTR, ATR$C_RECATTR, &recattr },
1708 { ATR$S_ASCNAME, ATR$C_ASCNAME, &ascnamebuff },
1709 { 0, 0, 0}
1712 FIBDEF fib;
1713 struct dsc$descriptor_fib fibdsc = {sizeof (fib), (void *) &fib};
1715 struct IOSB iosb;
1717 long status;
1718 unsigned short chan;
1720 struct vstring file;
1721 struct dsc$descriptor_s filedsc
1722 = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) file.string};
1723 struct vstring device;
1724 struct dsc$descriptor_s devicedsc
1725 = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) device.string};
1726 struct vstring result;
1727 struct dsc$descriptor_s resultdsc
1728 = {NAM$C_MAXRSS, DSC$K_DTYPE_VT, DSC$K_CLASS_VS, (void *) result.string};
1730 if (strcmp (filename, "<internal>") == 0
1731 || strcmp (filename, "<built-in>") == 0)
1733 if (cdt)
1734 *cdt = 0;
1736 if (siz)
1737 *siz = 0;
1739 if (rfo)
1740 *rfo = 0;
1742 if (ver)
1743 *ver = 0;
1745 return 0;
1748 tryfile = to_vms_file_spec (filename);
1750 /* Allocate and initialize a FAB and NAM structures. */
1751 fab = cc$rms_fab;
1752 nam = cc$rms_nam;
1754 nam.nam$l_esa = file.string;
1755 nam.nam$b_ess = NAM$C_MAXRSS;
1756 nam.nam$l_rsa = result.string;
1757 nam.nam$b_rss = NAM$C_MAXRSS;
1758 fab.fab$l_fna = tryfile;
1759 fab.fab$b_fns = strlen (tryfile);
1760 fab.fab$l_nam = &nam;
1762 /* Validate filespec syntax and device existence. */
1763 status = SYS$PARSE (&fab, 0, 0);
1764 if ((status & 1) != 1)
1765 return 1;
1767 file.string[nam.nam$b_esl] = 0;
1769 /* Find matching filespec. */
1770 status = SYS$SEARCH (&fab, 0, 0);
1771 if ((status & 1) != 1)
1772 return 1;
1774 file.string[nam.nam$b_esl] = 0;
1775 result.string[result.length=nam.nam$b_rsl] = 0;
1777 /* Get the device name and assign an IO channel. */
1778 strncpy (device.string, nam.nam$l_dev, nam.nam$b_dev);
1779 devicedsc.dsc$w_length = nam.nam$b_dev;
1780 chan = 0;
1781 status = SYS$ASSIGN (&devicedsc, &chan, 0, 0, 0);
1782 if ((status & 1) != 1)
1783 return 1;
1785 /* Initialize the FIB and fill in the directory id field. */
1786 memset (&fib, 0, sizeof (fib));
1787 fib.fib$w_did[0] = nam.nam$w_did[0];
1788 fib.fib$w_did[1] = nam.nam$w_did[1];
1789 fib.fib$w_did[2] = nam.nam$w_did[2];
1790 fib.fib$l_acctl = 0;
1791 fib.fib$l_wcc = 0;
1792 strcpy (file.string, (strrchr (result.string, ']') + 1));
1793 filedsc.dsc$w_length = strlen (file.string);
1794 result.string[result.length = 0] = 0;
1796 /* Open and close the file to fill in the attributes. */
1797 status
1798 = SYS$QIOW (0, chan, IO$_ACCESS|IO$M_ACCESS, &iosb, 0, 0,
1799 &fibdsc, &filedsc, &result.length, &resultdsc, &atrlst, 0);
1800 if ((status & 1) != 1)
1801 return 1;
1802 if ((iosb.status & 1) != 1)
1803 return 1;
1805 result.string[result.length] = 0;
1806 status = SYS$QIOW (0, chan, IO$_DEACCESS, &iosb, 0, 0, &fibdsc, 0, 0, 0,
1807 &atrlst, 0);
1808 if ((status & 1) != 1)
1809 return 1;
1810 if ((iosb.status & 1) != 1)
1811 return 1;
1813 /* Deassign the channel and exit. */
1814 status = SYS$DASSGN (chan);
1815 if ((status & 1) != 1)
1816 return 1;
1818 if (cdt) *cdt = create;
1819 if (siz) *siz = (512 * 65536 * recattr.fat$w_efblkh) +
1820 (512 * (recattr.fat$w_efblkl - 1)) +
1821 recattr.fat$w_ffbyte;
1822 if (rfo) *rfo = recattr.fat$v_rtype;
1823 if (ver) *ver = strtol (strrchr (ascnamebuff, ';')+1, 0, 10);
1825 return 0;
1826 #else
1827 struct stat buff;
1829 if ((stat (filename, &buff)) != 0)
1830 return 1;
1832 if (cdt)
1833 *cdt = (long long) (buff.st_mtime * VMS_GRANULARITY_FACTOR)
1834 + VMS_EPOCH_OFFSET;
1836 if (siz)
1837 *siz = buff.st_size;
1839 if (rfo)
1840 *rfo = 2; /* Stream LF format */
1842 if (ver)
1843 *ver = 1;
1845 return 0;
1846 #endif
1848 #endif