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