2013-04-26 François Dumont <fdumont@gcc.gnu.org>
[official-gcc.git] / gcc / vmsdbgout.c
blob9f05c1cd32b71234d9a83020addab4e7fb02e71b
1 /* Output VMS debug format symbol table information from GCC.
2 Copyright (C) 1987-2013 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 "version.h"
30 #include "flags.h"
31 #include "rtl.h"
32 #include "output.h"
33 #include "vmsdbg.h"
34 #include "debug.h"
35 #include "langhooks.h"
36 #include "function.h"
37 #include "target.h"
39 /* Difference in seconds between the VMS Epoch and the Unix Epoch */
40 static const long long vms_epoch_offset = 3506716800ll;
42 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
44 /* NOTE: In the comments in this file, many references are made to "Debug
45 Symbol Table". This term is abbreviated as `DST' throughout the remainder
46 of this file. */
48 typedef struct dst_line_info_struct *dst_line_info_ref;
50 /* Each entry in the line_info_table maintains the file and
51 line number associated with the label generated for that
52 entry. The label gives the PC value associated with
53 the line number entry. */
54 typedef struct dst_line_info_struct
56 unsigned long dst_file_num;
57 unsigned long dst_line_num;
59 dst_line_info_entry;
61 typedef struct dst_file_info_struct *dst_file_info_ref;
63 typedef struct dst_file_info_struct
65 char *file_name;
66 unsigned int max_line;
67 unsigned int listing_line_start;
68 long long cdt;
69 long ebk;
70 short ffb;
71 char rfo;
73 dst_file_info_entry;
75 /* Maximum size (in bytes) of an artificially generated label. */
76 #define MAX_ARTIFICIAL_LABEL_BYTES 30
78 /* Make sure we know the sizes of the various types debug can describe. These
79 are only defaults. If the sizes are different for your target, you should
80 override these values by defining the appropriate symbols in your tm.h
81 file. */
82 #ifndef PTR_SIZE
83 #define PTR_SIZE 4 /* Must be 32 bits for VMS debug info */
84 #endif
86 /* Pointer to a structure of filenames referenced by this compilation unit. */
87 static dst_file_info_ref file_info_table;
89 /* Total number of entries in the table (i.e. array) pointed to by
90 `file_info_table'. This is the *total* and includes both used and unused
91 slots. */
92 static unsigned int file_info_table_allocated;
94 /* Number of entries in the file_info_table which are actually in use. */
95 static unsigned int file_info_table_in_use;
97 /* Size (in elements) of increments by which we may expand the filename
98 table. */
99 #define FILE_TABLE_INCREMENT 64
101 typedef char *char_p;
103 static vec<char_p> funcnam_table;
104 static vec<unsigned> funcnum_table;
105 #define FUNC_TABLE_INITIAL 256
107 /* Local pointer to the name of the main input file. Initialized in
108 vmsdbgout_init. */
109 static const char *primary_filename;
111 static char *module_producer;
112 static unsigned int module_language;
114 /* A pointer to the base of a table that contains line information
115 for each source code line in .text in the compilation unit. */
116 static dst_line_info_ref line_info_table;
118 /* Number of elements currently allocated for line_info_table. */
119 static unsigned int line_info_table_allocated;
121 /* Number of elements in line_info_table currently in use. */
122 static unsigned int line_info_table_in_use;
124 /* Size (in elements) of increments by which we may expand line_info_table. */
125 #define LINE_INFO_TABLE_INCREMENT 1024
127 /* Forward declarations for functions defined in this file. */
128 static char *full_name (const char *);
129 static unsigned int lookup_filename (const char *);
130 static int write_debug_header (DST_HEADER *, const char *, int);
131 static int write_debug_addr (const char *, const char *, int);
132 static int write_debug_data1 (unsigned int, const char *, int);
133 static int write_debug_data2 (unsigned int, const char *, int);
134 static int write_debug_data4 (unsigned long, const char *, int);
135 static int write_debug_data8 (unsigned long long, const char *, int);
136 static int write_debug_delta4 (const char *, const char *, const char *, int);
137 static int write_debug_string (const char *, const char *, int);
138 static int write_modbeg (int);
139 static int write_modend (int);
140 static int write_rtnbeg (int, int);
141 static int write_rtnend (int, int);
142 static int write_pclines (int);
143 static int write_srccorr (int, dst_file_info_entry, int);
144 static int write_srccorrs (int);
146 static void vmsdbgout_init (const char *);
147 static void vmsdbgout_finish (const char *);
148 static void vmsdbgout_assembly_start (void);
149 static void vmsdbgout_define (unsigned int, const char *);
150 static void vmsdbgout_undef (unsigned int, const char *);
151 static void vmsdbgout_start_source_file (unsigned int, const char *);
152 static void vmsdbgout_end_source_file (unsigned int);
153 static void vmsdbgout_begin_block (unsigned int, unsigned int);
154 static void vmsdbgout_end_block (unsigned int, unsigned int);
155 static bool vmsdbgout_ignore_block (const_tree);
156 static void vmsdbgout_source_line (unsigned int, const char *, int, bool);
157 static void vmsdbgout_write_source_line (unsigned, const char *, int , bool);
158 static void vmsdbgout_begin_prologue (unsigned int, const char *);
159 static void vmsdbgout_end_prologue (unsigned int, const char *);
160 static void vmsdbgout_end_function (unsigned int);
161 static void vmsdbgout_begin_epilogue (unsigned int, const char *);
162 static void vmsdbgout_end_epilogue (unsigned int, const char *);
163 static void vmsdbgout_begin_function (tree);
164 static void vmsdbgout_decl (tree);
165 static void vmsdbgout_global_decl (tree);
166 static void vmsdbgout_type_decl (tree, int);
167 static void vmsdbgout_abstract_function (tree);
169 /* The debug hooks structure. */
171 const struct gcc_debug_hooks vmsdbg_debug_hooks
172 = {vmsdbgout_init,
173 vmsdbgout_finish,
174 vmsdbgout_assembly_start,
175 vmsdbgout_define,
176 vmsdbgout_undef,
177 vmsdbgout_start_source_file,
178 vmsdbgout_end_source_file,
179 vmsdbgout_begin_block,
180 vmsdbgout_end_block,
181 vmsdbgout_ignore_block,
182 vmsdbgout_source_line,
183 vmsdbgout_begin_prologue,
184 vmsdbgout_end_prologue,
185 vmsdbgout_begin_epilogue,
186 vmsdbgout_end_epilogue,
187 vmsdbgout_begin_function,
188 vmsdbgout_end_function,
189 vmsdbgout_decl,
190 vmsdbgout_global_decl,
191 vmsdbgout_type_decl, /* type_decl */
192 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
193 debug_nothing_tree, /* deferred_inline_function */
194 vmsdbgout_abstract_function,
195 debug_nothing_rtx, /* label */
196 debug_nothing_int, /* handle_pch */
197 debug_nothing_rtx, /* var_location */
198 debug_nothing_void, /* switch_text_section */
199 debug_nothing_tree_tree, /* set_name */
200 0, /* start_end_main_source_file */
201 TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
204 /* Definitions of defaults for assembler-dependent names of various
205 pseudo-ops and section names. */
206 #define VMS_UNALIGNED_SHORT_ASM_OP ".word"
207 #define VMS_UNALIGNED_INT_ASM_OP ".long"
208 #define VMS_UNALIGNED_LONG_ASM_OP ".long"
209 #define VMS_UNALIGNED_DOUBLE_INT_ASM_OP ".quad"
211 #define VMS_ASM_BYTE_OP ".byte"
213 #define NUMBYTES(I) ((I) < 256 ? 1 : (I) < 65536 ? 2 : 4)
215 #define NUMBYTES0(I) ((I) < 128 ? 0 : (I) < 65536 ? 2 : 4)
217 #ifndef UNALIGNED_PTR_ASM_OP
218 #define UNALIGNED_PTR_ASM_OP \
219 (PTR_SIZE == 8 ? VMS_UNALIGNED_DOUBLE_INT_ASM_OP : VMS_UNALIGNED_INT_ASM_OP)
220 #endif
222 #ifndef UNALIGNED_OFFSET_ASM_OP
223 #define UNALIGNED_OFFSET_ASM_OP(OFFSET) \
224 (NUMBYTES(OFFSET) == 4 \
225 ? VMS_UNALIGNED_LONG_ASM_OP \
226 : (NUMBYTES(OFFSET) == 2 ? VMS_UNALIGNED_SHORT_ASM_OP : VMS_ASM_BYTE_OP))
227 #endif
229 /* Definitions of defaults for formats and names of various special
230 (artificial) labels which may be generated within this file (when the -g
231 options is used and VMS_DEBUGGING_INFO is in effect. If necessary, these
232 may be overridden from within the tm.h file, but typically, overriding these
233 defaults is unnecessary. */
235 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
237 #ifndef TEXT_END_LABEL
238 #define TEXT_END_LABEL "Lvetext"
239 #endif
240 #ifndef FUNC_BEGIN_LABEL
241 #define FUNC_BEGIN_LABEL "LVFB"
242 #endif
243 #ifndef FUNC_PROLOG_LABEL
244 #define FUNC_PROLOG_LABEL "LVFP"
245 #endif
246 #ifndef FUNC_EPILOG_LABEL
247 #define FUNC_EPILOG_LABEL "LVEB"
248 #endif
249 #ifndef FUNC_END_LABEL
250 #define FUNC_END_LABEL "LVFE"
251 #endif
252 #ifndef BLOCK_BEGIN_LABEL
253 #define BLOCK_BEGIN_LABEL "LVBB"
254 #endif
255 #ifndef BLOCK_END_LABEL
256 #define BLOCK_END_LABEL "LVBE"
257 #endif
258 #ifndef LINE_CODE_LABEL
259 #define LINE_CODE_LABEL "LVM"
260 #endif
262 #ifndef ASM_OUTPUT_DEBUG_DELTA2
263 #define ASM_OUTPUT_DEBUG_DELTA2(FILE,LABEL1,LABEL2) \
264 do \
266 fprintf ((FILE), "\t%s\t", VMS_UNALIGNED_SHORT_ASM_OP); \
267 assemble_name (FILE, LABEL1); \
268 fprintf (FILE, "-"); \
269 assemble_name (FILE, LABEL2); \
271 while (0)
272 #endif
274 #ifndef ASM_OUTPUT_DEBUG_DELTA4
275 #define ASM_OUTPUT_DEBUG_DELTA4(FILE,LABEL1,LABEL2) \
276 do \
278 fprintf ((FILE), "\t%s\t", VMS_UNALIGNED_INT_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_ADDR_DELTA
287 #define ASM_OUTPUT_DEBUG_ADDR_DELTA(FILE,LABEL1,LABEL2) \
288 do \
290 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_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
299 #define ASM_OUTPUT_DEBUG_ADDR(FILE,LABEL) \
300 do \
302 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
303 assemble_name (FILE, LABEL); \
305 while (0)
306 #endif
308 #ifndef ASM_OUTPUT_DEBUG_ADDR_CONST
309 #define ASM_OUTPUT_DEBUG_ADDR_CONST(FILE,ADDR) \
310 fprintf ((FILE), "\t%s\t%s", UNALIGNED_PTR_ASM_OP, (ADDR))
311 #endif
313 #ifndef ASM_OUTPUT_DEBUG_DATA1
314 #define ASM_OUTPUT_DEBUG_DATA1(FILE,VALUE) \
315 fprintf ((FILE), "\t%s\t%#x", VMS_ASM_BYTE_OP, (unsigned char) VALUE)
316 #endif
318 #ifndef ASM_OUTPUT_DEBUG_DATA2
319 #define ASM_OUTPUT_DEBUG_DATA2(FILE,VALUE) \
320 fprintf ((FILE), "\t%s\t%#x", VMS_UNALIGNED_SHORT_ASM_OP, \
321 (unsigned short) VALUE)
322 #endif
324 #ifndef ASM_OUTPUT_DEBUG_DATA4
325 #define ASM_OUTPUT_DEBUG_DATA4(FILE,VALUE) \
326 fprintf ((FILE), "\t%s\t%#lx", VMS_UNALIGNED_INT_ASM_OP, \
327 (unsigned long) VALUE)
328 #endif
330 #ifndef ASM_OUTPUT_DEBUG_DATA
331 #define ASM_OUTPUT_DEBUG_DATA(FILE,VALUE) \
332 fprintf ((FILE), "\t%s\t%#lx", UNALIGNED_OFFSET_ASM_OP(VALUE), VALUE)
333 #endif
335 #ifndef ASM_OUTPUT_DEBUG_ADDR_DATA
336 #define ASM_OUTPUT_DEBUG_ADDR_DATA(FILE,VALUE) \
337 fprintf ((FILE), "\t%s\t%#lx", UNALIGNED_PTR_ASM_OP, \
338 (unsigned long) VALUE)
339 #endif
341 #ifndef ASM_OUTPUT_DEBUG_DATA8
342 #define ASM_OUTPUT_DEBUG_DATA8(FILE,VALUE) \
343 fprintf ((FILE), "\t%s\t%#llx", VMS_UNALIGNED_DOUBLE_INT_ASM_OP, \
344 (unsigned long long) VALUE)
345 #endif
347 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
348 newline is produced. When flag_verbose_asm is asserted, we add commentary
349 at the end of the line, so we must avoid output of a newline here. */
350 #ifndef ASM_OUTPUT_DEBUG_STRING
351 #define ASM_OUTPUT_DEBUG_STRING(FILE,P) \
352 do \
354 register int slen = strlen(P); \
355 register const char *p = (P); \
356 register int i; \
357 fprintf (FILE, "\t.ascii \""); \
358 for (i = 0; i < slen; i++) \
360 register int c = p[i]; \
361 if (c == '\"' || c == '\\') \
362 putc ('\\', FILE); \
363 if (c >= ' ' && c < 0177) \
364 putc (c, FILE); \
365 else \
366 fprintf (FILE, "\\%o", c); \
368 fprintf (FILE, "\""); \
370 while (0)
371 #endif
373 /* Convert a reference to the assembler name of a C-level name. This
374 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
375 a string rather than writing to a file. */
376 #ifndef ASM_NAME_TO_STRING
377 #define ASM_NAME_TO_STRING(STR, NAME) \
378 do \
380 if ((NAME)[0] == '*') \
381 strcpy (STR, NAME+1); \
382 else \
383 strcpy (STR, NAME); \
385 while (0)
386 #endif
389 /* Output the debug header HEADER. Also output COMMENT if flag_verbose_asm is
390 set. Return the header size. Just return the size if DOSIZEONLY is
391 nonzero. */
393 static int
394 write_debug_header (DST_HEADER *header, const char *comment, int dosizeonly)
396 if (!dosizeonly)
398 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
399 header->dst__header_length.dst_w_length);
401 if (flag_verbose_asm)
402 fprintf (asm_out_file, "\t%s record length", ASM_COMMENT_START);
403 fputc ('\n', asm_out_file);
405 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
406 header->dst__header_type.dst_w_type);
408 if (flag_verbose_asm)
409 fprintf (asm_out_file, "\t%s record type (%s)", ASM_COMMENT_START,
410 comment);
412 fputc ('\n', asm_out_file);
415 return 4;
418 /* Output the address of SYMBOL. Also output COMMENT if flag_verbose_asm is
419 set. Return the address size. Just return the size if DOSIZEONLY is
420 nonzero. */
422 static int
423 write_debug_addr (const char *symbol, const char *comment, int dosizeonly)
425 if (!dosizeonly)
427 ASM_OUTPUT_DEBUG_ADDR (asm_out_file, symbol);
428 if (flag_verbose_asm)
429 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
430 fputc ('\n', asm_out_file);
433 return PTR_SIZE;
436 /* Output the single byte DATA1. Also output COMMENT if flag_verbose_asm is
437 set. Return the data size. Just return the size if DOSIZEONLY is
438 nonzero. */
440 static int
441 write_debug_data1 (unsigned int data1, const char *comment, int dosizeonly)
443 if (!dosizeonly)
445 ASM_OUTPUT_DEBUG_DATA1 (asm_out_file, data1);
446 if (flag_verbose_asm)
447 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
448 fputc ('\n', asm_out_file);
451 return 1;
454 /* Output the single word DATA2. Also output COMMENT if flag_verbose_asm is
455 set. Return the data size. Just return the size if DOSIZEONLY is
456 nonzero. */
458 static int
459 write_debug_data2 (unsigned int data2, const char *comment, int dosizeonly)
461 if (!dosizeonly)
463 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file, data2);
464 if (flag_verbose_asm)
465 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
466 fputc ('\n', asm_out_file);
469 return 2;
472 /* Output double word DATA4. Also output COMMENT if flag_verbose_asm is set.
473 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
475 static int
476 write_debug_data4 (unsigned long data4, const char *comment, int dosizeonly)
478 if (!dosizeonly)
480 ASM_OUTPUT_DEBUG_DATA4 (asm_out_file, data4);
481 if (flag_verbose_asm)
482 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
483 fputc ('\n', asm_out_file);
486 return 4;
489 /* Output quad word DATA8. Also output COMMENT if flag_verbose_asm is set.
490 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
492 static int
493 write_debug_data8 (unsigned long long data8, const char *comment,
494 int dosizeonly)
496 if (!dosizeonly)
498 ASM_OUTPUT_DEBUG_DATA8 (asm_out_file, data8);
499 if (flag_verbose_asm)
500 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
501 fputc ('\n', asm_out_file);
504 return 8;
507 /* Output the difference between LABEL1 and LABEL2. Also output COMMENT if
508 flag_verbose_asm is set. Return the data size. Just return the size if
509 DOSIZEONLY is nonzero. */
511 static int
512 write_debug_delta4 (const char *label1, const char *label2,
513 const char *comment, int dosizeonly)
515 if (!dosizeonly)
517 ASM_OUTPUT_DEBUG_DELTA4 (asm_out_file, label1, label2);
518 if (flag_verbose_asm)
519 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
520 fputc ('\n', asm_out_file);
523 return 4;
526 /* Output a character string STRING. Also write COMMENT if flag_verbose_asm is
527 set. Return the string length. Just return the length if DOSIZEONLY is
528 nonzero. */
530 static int
531 write_debug_string (const char *string, const char *comment, int dosizeonly)
533 if (!dosizeonly)
535 ASM_OUTPUT_DEBUG_STRING (asm_out_file, string);
536 if (flag_verbose_asm)
537 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
538 fputc ('\n', asm_out_file);
541 return strlen (string);
544 /* Output a module begin header and return the header size. Just return the
545 size if DOSIZEONLY is nonzero. */
547 static int
548 write_modbeg (int dosizeonly)
550 DST_MODULE_BEGIN modbeg;
551 DST_MB_TRLR mb_trlr;
552 int i;
553 char *module_name, *m;
554 int modnamelen;
555 int prodnamelen;
556 int totsize = 0;
558 /* Assumes primary filename has Unix syntax file spec. */
559 module_name = xstrdup (lbasename (primary_filename));
561 m = strrchr (module_name, '.');
562 if (m)
563 *m = 0;
565 modnamelen = strlen (module_name);
566 for (i = 0; i < modnamelen; i++)
567 module_name[i] = TOUPPER (module_name[i]);
569 prodnamelen = strlen (module_producer);
571 modbeg.dst_a_modbeg_header.dst__header_length.dst_w_length
572 = DST_K_MODBEG_SIZE + modnamelen + DST_K_MB_TRLR_SIZE + prodnamelen - 1;
573 modbeg.dst_a_modbeg_header.dst__header_type.dst_w_type = DST_K_MODBEG;
574 modbeg.dst_b_modbeg_flags.dst_v_modbeg_hide = 0;
575 modbeg.dst_b_modbeg_flags.dst_v_modbeg_version = 1;
576 modbeg.dst_b_modbeg_flags.dst_v_modbeg_unused = 0;
577 modbeg.dst_b_modbeg_unused = 0;
578 modbeg.dst_l_modbeg_language = (DST_LANGUAGE) module_language;
579 modbeg.dst_w_version_major = DST_K_VERSION_MAJOR;
580 modbeg.dst_w_version_minor = DST_K_VERSION_MINOR;
581 modbeg.dst_b_modbeg_name = strlen (module_name);
583 mb_trlr.dst_b_compiler = strlen (module_producer);
585 totsize += write_debug_header (&modbeg.dst_a_modbeg_header,
586 "modbeg", dosizeonly);
587 totsize += write_debug_data1 (*((char *) &modbeg.dst_b_modbeg_flags),
588 "flags", dosizeonly);
589 totsize += write_debug_data1 (modbeg.dst_b_modbeg_unused,
590 "unused", dosizeonly);
591 totsize += write_debug_data4 (modbeg.dst_l_modbeg_language,
592 "language", dosizeonly);
593 totsize += write_debug_data2 (modbeg.dst_w_version_major,
594 "DST major version", dosizeonly);
595 totsize += write_debug_data2 (modbeg.dst_w_version_minor,
596 "DST minor version", dosizeonly);
597 totsize += write_debug_data1 (modbeg.dst_b_modbeg_name,
598 "length of module name", dosizeonly);
599 totsize += write_debug_string (module_name, "module name", dosizeonly);
600 totsize += write_debug_data1 (mb_trlr.dst_b_compiler,
601 "length of compiler name", dosizeonly);
602 totsize += write_debug_string (module_producer, "compiler name", dosizeonly);
604 return totsize;
607 /* Output a module end trailer and return the trailer size. Just return
608 the size if DOSIZEONLY is nonzero. */
610 static int
611 write_modend (int dosizeonly)
613 DST_MODULE_END modend;
614 int totsize = 0;
616 modend.dst_a_modend_header.dst__header_length.dst_w_length
617 = DST_K_MODEND_SIZE - 1;
618 modend.dst_a_modend_header.dst__header_type.dst_w_type = DST_K_MODEND;
620 totsize += write_debug_header (&modend.dst_a_modend_header, "modend",
621 dosizeonly);
623 return totsize;
626 /* Output a routine begin header routine RTNNUM and return the header size.
627 Just return the size if DOSIZEONLY is nonzero. */
629 static int
630 write_rtnbeg (int rtnnum, int dosizeonly)
632 const char *rtnname;
633 int rtnnamelen;
634 char *rtnentryname;
635 int totsize = 0;
636 char label[MAX_ARTIFICIAL_LABEL_BYTES];
637 DST_ROUTINE_BEGIN rtnbeg;
638 DST_PROLOG prolog;
640 rtnname = funcnam_table[rtnnum];
641 rtnnamelen = strlen (rtnname);
642 rtnentryname = concat (rtnname, "..en", NULL);
644 if (!strcmp (rtnname, "main"))
646 DST_HEADER header;
647 const char *go = "TRANSFER$BREAK$GO";
649 /* This command isn't documented in DSTRECORDS, so it's made to
650 look like what DEC C does */
652 /* header size - 1st byte + flag byte + STO_LW size
653 + string count byte + string length */
654 header.dst__header_length.dst_w_length
655 = DST_K_DST_HEADER_SIZE - 1 + 1 + 4 + 1 + strlen (go);
656 header.dst__header_type.dst_w_type = DST_K_TBG;
658 totsize += write_debug_header (&header, "transfer", dosizeonly);
660 /* I think this is a flag byte, but I don't know what this flag means */
661 totsize += write_debug_data1 (0x1, "flags ???", dosizeonly);
663 /* Routine Begin PD Address */
664 totsize += write_debug_addr (rtnname, "main procedure descriptor",
665 dosizeonly);
666 totsize += write_debug_data1 (strlen (go), "length of main_name",
667 dosizeonly);
668 totsize += write_debug_string (go, "main name", dosizeonly);
671 /* The header length never includes the length byte. */
672 rtnbeg.dst_a_rtnbeg_header.dst__header_length.dst_w_length
673 = DST_K_RTNBEG_SIZE + rtnnamelen - 1;
674 rtnbeg.dst_a_rtnbeg_header.dst__header_type.dst_w_type = DST_K_RTNBEG;
675 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unused = 0;
676 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unalloc = 0;
677 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_prototype = 0;
678 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_inlined = 0;
679 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_no_call = 1;
680 rtnbeg.dst_b_rtnbeg_name = rtnnamelen;
682 totsize += write_debug_header (&rtnbeg.dst_a_rtnbeg_header, "rtnbeg",
683 dosizeonly);
684 totsize += write_debug_data1 (*((char *) &rtnbeg.dst_b_rtnbeg_flags),
685 "flags", dosizeonly);
687 /* Routine Begin Address */
688 totsize += write_debug_addr (rtnentryname, "routine entry name", dosizeonly);
690 /* Routine Begin PD Address */
691 totsize += write_debug_addr (rtnname, "routine procedure descriptor",
692 dosizeonly);
694 /* Routine Begin Name */
695 totsize += write_debug_data1 (rtnbeg.dst_b_rtnbeg_name,
696 "length of routine name", dosizeonly);
698 totsize += write_debug_string (rtnname, "routine name", dosizeonly);
700 free (rtnentryname);
702 if (debug_info_level > DINFO_LEVEL_TERSE)
704 prolog.dst_a_prolog_header.dst__header_length.dst_w_length
705 = DST_K_PROLOG_SIZE - 1;
706 prolog.dst_a_prolog_header.dst__header_type.dst_w_type = DST_K_PROLOG;
708 totsize += write_debug_header (&prolog.dst_a_prolog_header, "prolog",
709 dosizeonly);
711 ASM_GENERATE_INTERNAL_LABEL
712 (label, FUNC_PROLOG_LABEL,
713 funcnum_table[rtnnum]);
714 totsize += write_debug_addr (label, "prolog breakpoint addr",
715 dosizeonly);
718 return totsize;
721 /* Output a routine end trailer for routine RTNNUM and return the header size.
722 Just return the size if DOSIZEONLY is nonzero. */
724 static int
725 write_rtnend (int rtnnum, int dosizeonly)
727 DST_ROUTINE_END rtnend;
728 char label1[MAX_ARTIFICIAL_LABEL_BYTES];
729 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
730 int totsize;
732 totsize = 0;
734 rtnend.dst_a_rtnend_header.dst__header_length.dst_w_length
735 = DST_K_RTNEND_SIZE - 1;
736 rtnend.dst_a_rtnend_header.dst__header_type.dst_w_type = DST_K_RTNEND;
737 rtnend.dst_b_rtnend_unused = 0;
738 rtnend.dst_l_rtnend_size = 0; /* Calculated below. */
740 totsize += write_debug_header (&rtnend.dst_a_rtnend_header, "rtnend",
741 dosizeonly);
742 totsize += write_debug_data1 (rtnend.dst_b_rtnend_unused, "unused",
743 dosizeonly);
745 ASM_GENERATE_INTERNAL_LABEL
746 (label1, FUNC_BEGIN_LABEL,
747 funcnum_table[rtnnum]);
748 ASM_GENERATE_INTERNAL_LABEL
749 (label2, FUNC_END_LABEL,
750 funcnum_table[rtnnum]);
751 totsize += write_debug_delta4 (label2, label1, "routine size", dosizeonly);
753 return totsize;
756 #define K_DELTA_PC(I) \
757 ((I) < 128 ? -(I) : (I) < 65536 ? DST_K_DELTA_PC_W : DST_K_DELTA_PC_L)
759 #define K_SET_LINUM(I) \
760 ((I) < 256 ? DST_K_SET_LINUM_B \
761 : (I) < 65536 ? DST_K_SET_LINUM : DST_K_SET_LINUM_L)
763 #define K_INCR_LINUM(I) \
764 ((I) < 256 ? DST_K_INCR_LINUM \
765 : (I) < 65536 ? DST_K_INCR_LINUM_W : DST_K_INCR_LINUM_L)
767 /* Output the PC to line number correlations and return the size. Just return
768 the size if DOSIZEONLY is nonzero */
770 static int
771 write_pclines (int dosizeonly)
773 unsigned i;
774 int fn;
775 int ln, lastln;
776 int linestart = 0;
777 int max_line;
778 DST_LINE_NUM_HEADER line_num;
779 DST_PCLINE_COMMANDS pcline;
780 char label[MAX_ARTIFICIAL_LABEL_BYTES];
781 char lastlabel[MAX_ARTIFICIAL_LABEL_BYTES];
782 int totsize = 0;
783 char buff[256];
785 max_line = file_info_table[1].max_line;
786 file_info_table[1].listing_line_start = linestart;
787 linestart = linestart + ((max_line / 100000) + 1) * 100000;
789 for (i = 2; i < file_info_table_in_use; i++)
791 max_line = file_info_table[i].max_line;
792 file_info_table[i].listing_line_start = linestart;
793 linestart = linestart + ((max_line / 10000) + 1) * 10000;
796 /* Set starting address to beginning of text section. */
797 line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 8;
798 line_num.dst_a_line_num_header.dst__header_type.dst_w_type = DST_K_LINE_NUM;
799 pcline.dst_b_pcline_command = DST_K_SET_ABS_PC;
801 totsize += write_debug_header (&line_num.dst_a_line_num_header,
802 "line_num", dosizeonly);
803 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
804 "line_num (SET ABS PC)", dosizeonly);
806 if (dosizeonly)
807 totsize += 4;
808 else
810 ASM_OUTPUT_DEBUG_ADDR (asm_out_file, TEXT_SECTION_ASM_OP);
811 if (flag_verbose_asm)
812 fprintf (asm_out_file, "\t%s line_num", ASM_COMMENT_START);
813 fputc ('\n', asm_out_file);
816 fn = line_info_table[1].dst_file_num;
817 ln = (file_info_table[fn].listing_line_start
818 + line_info_table[1].dst_line_num);
819 line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 4 + 4;
820 pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
822 totsize += write_debug_header (&line_num.dst_a_line_num_header,
823 "line_num", dosizeonly);
824 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
825 "line_num (SET LINUM LONG)", dosizeonly);
827 sprintf (buff, "line_num (%d)", ln ? ln - 1 : 0);
828 totsize += write_debug_data4 (ln ? ln - 1 : 0, buff, dosizeonly);
830 lastln = ln;
831 strcpy (lastlabel, TEXT_SECTION_ASM_OP);
832 for (i = 1; i < line_info_table_in_use; i++)
834 int extrabytes;
836 fn = line_info_table[i].dst_file_num;
837 ln = (file_info_table[fn].listing_line_start
838 + line_info_table[i].dst_line_num);
840 if (ln - lastln > 1)
841 extrabytes = 5; /* NUMBYTES (ln - lastln - 1) + 1; */
842 else if (ln <= lastln)
843 extrabytes = 5; /* NUMBYTES (ln - 1) + 1; */
844 else
845 extrabytes = 0;
847 line_num.dst_a_line_num_header.dst__header_length.dst_w_length
848 = 8 + extrabytes;
850 totsize += write_debug_header
851 (&line_num.dst_a_line_num_header, "line_num", dosizeonly);
853 if (ln - lastln > 1)
855 int lndif = ln - lastln - 1;
857 /* K_INCR_LINUM (lndif); */
858 pcline.dst_b_pcline_command = DST_K_INCR_LINUM_L;
860 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
861 "line_num (INCR LINUM LONG)",
862 dosizeonly);
864 sprintf (buff, "line_num (%d)", lndif);
865 totsize += write_debug_data4 (lndif, buff, dosizeonly);
867 else if (ln <= lastln)
869 /* K_SET_LINUM (ln-1); */
870 pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
872 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
873 "line_num (SET LINUM LONG)",
874 dosizeonly);
876 sprintf (buff, "line_num (%d)", ln - 1);
877 totsize += write_debug_data4 (ln - 1, buff, dosizeonly);
880 pcline.dst_b_pcline_command = DST_K_DELTA_PC_L;
882 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
883 "line_num (DELTA PC LONG)", dosizeonly);
885 ASM_GENERATE_INTERNAL_LABEL (label, LINE_CODE_LABEL, i);
886 totsize += write_debug_delta4 (label, lastlabel, "increment line_num",
887 dosizeonly);
889 lastln = ln;
890 strcpy (lastlabel, label);
893 return totsize;
896 /* Output a source correlation for file FILEID using information saved in
897 FILE_INFO_ENTRY and return the size. Just return the size if DOSIZEONLY is
898 nonzero. */
900 static int
901 write_srccorr (int fileid, dst_file_info_entry file_info_entry,
902 int dosizeonly)
904 int src_command_size;
905 int linesleft = file_info_entry.max_line;
906 int linestart = file_info_entry.listing_line_start;
907 int flen = strlen (file_info_entry.file_name);
908 int linestodo = 0;
909 DST_SOURCE_CORR src_header;
910 DST_SRC_COMMAND src_command;
911 DST_SRC_COMMAND src_command_sf;
912 DST_SRC_COMMAND src_command_sl;
913 DST_SRC_COMMAND src_command_sr;
914 DST_SRC_COMMAND src_command_dl;
915 DST_SRC_CMDTRLR src_cmdtrlr;
916 char buff[256];
917 int totsize = 0;
919 if (fileid == 1)
921 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
922 = DST_K_SOURCE_CORR_HEADER_SIZE + 1 - 1;
923 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
924 = DST_K_SOURCE;
925 src_command.dst_b_src_command = DST_K_SRC_FORMFEED;
927 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
928 "source corr", dosizeonly);
930 totsize += write_debug_data1 (src_command.dst_b_src_command,
931 "source_corr (SRC FORMFEED)",
932 dosizeonly);
935 src_command_size
936 = DST_K_SRC_COMMAND_SIZE + flen + DST_K_SRC_CMDTRLR_SIZE;
937 src_command.dst_b_src_command = DST_K_SRC_DECLFILE;
938 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length
939 = src_command_size - 2;
940 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags = 0;
941 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid
942 = fileid;
943 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt
944 = file_info_entry.cdt;
945 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk
946 = file_info_entry.ebk;
947 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb
948 = file_info_entry.ffb;
949 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo
950 = file_info_entry.rfo;
951 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename
952 = flen;
954 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
955 = DST_K_SOURCE_CORR_HEADER_SIZE + src_command_size - 1;
956 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
957 = DST_K_SOURCE;
959 src_cmdtrlr.dst_b_src_df_libmodname = 0;
961 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
962 "source corr", dosizeonly);
963 totsize += write_debug_data1 (src_command.dst_b_src_command,
964 "source_corr (DECL SRC FILE)", dosizeonly);
965 totsize += write_debug_data1
966 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length,
967 "source_corr (length)", dosizeonly);
969 totsize += write_debug_data1
970 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags,
971 "source_corr (flags)", dosizeonly);
973 totsize += write_debug_data2
974 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid,
975 "source_corr (fileid)", dosizeonly);
977 totsize += write_debug_data8
978 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt,
979 "source_corr (creation date)", dosizeonly);
981 totsize += write_debug_data4
982 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk,
983 "source_corr (EOF block number)", dosizeonly);
985 totsize += write_debug_data2
986 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb,
987 "source_corr (first free byte)", dosizeonly);
989 totsize += write_debug_data1
990 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo,
991 "source_corr (record and file organization)", dosizeonly);
993 totsize += write_debug_data1
994 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename,
995 "source_corr (filename length)", dosizeonly);
997 totsize += write_debug_string (remap_debug_filename (
998 file_info_entry.file_name),
999 "source file name", dosizeonly);
1000 totsize += write_debug_data1 (src_cmdtrlr.dst_b_src_df_libmodname,
1001 "source_corr (libmodname)", dosizeonly);
1003 src_command_sf.dst_b_src_command = DST_K_SRC_SETFILE;
1004 src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword = fileid;
1006 src_command_sr.dst_b_src_command = DST_K_SRC_SETREC_W;
1007 src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword = 1;
1009 src_command_sl.dst_b_src_command = DST_K_SRC_SETLNUM_L;
1010 src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong = linestart + 1;
1012 src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1014 if (linesleft > 65534)
1015 linesleft = linesleft - 65534, linestodo = 65534;
1016 else
1017 linestodo = linesleft, linesleft = 0;
1019 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1021 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1022 = DST_K_SOURCE_CORR_HEADER_SIZE + 3 + 3 + 5 + 3 - 1;
1023 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1024 = DST_K_SOURCE;
1026 if (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword)
1028 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1029 "source corr", dosizeonly);
1031 totsize += write_debug_data1 (src_command_sf.dst_b_src_command,
1032 "source_corr (src setfile)", dosizeonly);
1034 totsize += write_debug_data2
1035 (src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword,
1036 "source_corr (fileid)", dosizeonly);
1038 totsize += write_debug_data1 (src_command_sr.dst_b_src_command,
1039 "source_corr (setrec)", dosizeonly);
1041 totsize += write_debug_data2
1042 (src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword,
1043 "source_corr (recnum)", dosizeonly);
1045 totsize += write_debug_data1 (src_command_sl.dst_b_src_command,
1046 "source_corr (setlnum)", dosizeonly);
1048 totsize += write_debug_data4
1049 (src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong,
1050 "source_corr (linenum)", dosizeonly);
1052 totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1053 "source_corr (deflines)", dosizeonly);
1055 sprintf (buff, "source_corr (%d)",
1056 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1057 totsize += write_debug_data2
1058 (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
1059 buff, dosizeonly);
1061 while (linesleft > 0)
1063 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1064 = DST_K_SOURCE_CORR_HEADER_SIZE + 3 - 1;
1065 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1066 = DST_K_SOURCE;
1067 src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1069 if (linesleft > 65534)
1070 linesleft = linesleft - 65534, linestodo = 65534;
1071 else
1072 linestodo = linesleft, linesleft = 0;
1074 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1076 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1077 "source corr", dosizeonly);
1078 totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1079 "source_corr (deflines)", dosizeonly);
1080 sprintf (buff, "source_corr (%d)",
1081 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1082 totsize += write_debug_data2
1083 (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
1084 buff, dosizeonly);
1088 return totsize;
1091 /* Output all the source correlation entries and return the size. Just return
1092 the size if DOSIZEONLY is nonzero. */
1094 static int
1095 write_srccorrs (int dosizeonly)
1097 unsigned int i;
1098 int totsize = 0;
1100 for (i = 1; i < file_info_table_in_use; i++)
1101 totsize += write_srccorr (i, file_info_table[i], dosizeonly);
1103 return totsize;
1106 /* Output a marker (i.e. a label) for the beginning of a function, before
1107 the prologue. */
1109 static void
1110 vmsdbgout_begin_prologue (unsigned int line, const char *file)
1112 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1114 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1115 (*dwarf2_debug_hooks.begin_prologue) (line, file);
1117 if (debug_info_level > DINFO_LEVEL_NONE)
1119 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1120 current_function_funcdef_no);
1121 ASM_OUTPUT_LABEL (asm_out_file, label);
1125 /* Output a marker (i.e. a label) for the beginning of a function, after
1126 the prologue. */
1128 static void
1129 vmsdbgout_end_prologue (unsigned int line, const char *file)
1131 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1133 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1134 (*dwarf2_debug_hooks.end_prologue) (line, file);
1136 if (debug_info_level > DINFO_LEVEL_TERSE)
1138 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_PROLOG_LABEL,
1139 current_function_funcdef_no);
1140 ASM_OUTPUT_LABEL (asm_out_file, label);
1142 /* VMS PCA expects every PC range to correlate to some line and file. */
1143 vmsdbgout_write_source_line (line, file, 0, true);
1147 /* No output for VMS debug, but make obligatory call to Dwarf2 debug */
1149 static void
1150 vmsdbgout_end_function (unsigned int line)
1152 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1153 (*dwarf2_debug_hooks.end_function) (line);
1156 /* Output a marker (i.e. a label) for the beginning of the epilogue.
1157 This gets called *before* the epilogue code has been generated. */
1159 static void
1160 vmsdbgout_begin_epilogue (unsigned int line, const char *file)
1162 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1163 static int save_current_function_funcdef_no = -1;
1165 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1166 (*dwarf2_debug_hooks.begin_epilogue) (line, file);
1168 if (debug_info_level > DINFO_LEVEL_NONE)
1170 if (save_current_function_funcdef_no != current_function_funcdef_no)
1172 /* Output a label to mark the endpoint of the code generated for this
1173 function. */
1174 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_EPILOG_LABEL,
1175 current_function_funcdef_no);
1177 ASM_OUTPUT_LABEL (asm_out_file, label);
1179 save_current_function_funcdef_no = current_function_funcdef_no;
1181 /* VMS PCA expects every PC range to correlate to some line and
1182 file. */
1183 vmsdbgout_write_source_line (line, file, 0, true);
1188 /* Output a marker (i.e. a label) for the absolute end of the generated code
1189 for a function definition. This gets called *after* the epilogue code has
1190 been generated. */
1192 static void
1193 vmsdbgout_end_epilogue (unsigned int line, const char *file)
1195 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1197 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1198 (*dwarf2_debug_hooks.end_epilogue) (line, file);
1200 if (debug_info_level > DINFO_LEVEL_NONE)
1202 /* Output a label to mark the endpoint of the code generated for this
1203 function. */
1204 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1205 current_function_funcdef_no);
1206 ASM_OUTPUT_LABEL (asm_out_file, label);
1208 /* VMS PCA expects every PC range to correlate to some line and file. */
1209 vmsdbgout_write_source_line (line, file, 0, true);
1213 /* Output a marker (i.e. a label) for the beginning of the generated code for
1214 a lexical block. */
1216 static void
1217 vmsdbgout_begin_block (register unsigned line, register unsigned blocknum)
1219 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1220 (*dwarf2_debug_hooks.begin_block) (line, blocknum);
1222 if (debug_info_level > DINFO_LEVEL_TERSE)
1223 targetm.asm_out.internal_label (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
1226 /* Output a marker (i.e. a label) for the end of the generated code for a
1227 lexical block. */
1229 static void
1230 vmsdbgout_end_block (register unsigned line, register unsigned blocknum)
1232 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1233 (*dwarf2_debug_hooks.end_block) (line, blocknum);
1235 if (debug_info_level > DINFO_LEVEL_TERSE)
1236 targetm.asm_out.internal_label (asm_out_file, BLOCK_END_LABEL, blocknum);
1239 /* Not implemented in VMS Debug. */
1241 static bool
1242 vmsdbgout_ignore_block (const_tree block)
1244 bool retval = 0;
1246 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1247 retval = (*dwarf2_debug_hooks.ignore_block) (block);
1249 return retval;
1252 /* Add an entry for function DECL into the funcnam_table. */
1254 static void
1255 vmsdbgout_begin_function (tree decl)
1257 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1259 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1260 (*dwarf2_debug_hooks.begin_function) (decl);
1262 /* Add the new entry to the end of the function name table. */
1263 funcnam_table.safe_push (xstrdup (name));
1264 funcnum_table.safe_push (current_function_funcdef_no);
1267 static char fullname_buff [4096];
1269 /* Return the full file specification for FILENAME. The specification must be
1270 in VMS syntax in order to be processed by VMS Debug. */
1272 static char *
1273 full_name (const char *filename)
1275 #ifdef VMS
1276 FILE *fp = fopen (filename, "r");
1278 fgetname (fp, fullname_buff, 1);
1279 fclose (fp);
1280 #else
1281 /* Unix paths really mess up VMS debug. Better to just output the
1282 base filename. */
1283 strcpy (fullname_buff, filename);
1284 #endif
1286 return fullname_buff;
1289 /* Lookup a filename (in the list of filenames that we know about here in
1290 vmsdbgout.c) and return its "index". The index of each (known) filename is
1291 just a unique number which is associated with only that one filename. We
1292 need such numbers for the sake of generating labels and references
1293 to those files numbers. If the filename given as an argument is not
1294 found in our current list, add it to the list and assign it the next
1295 available unique index number. In order to speed up searches, we remember
1296 the index of the filename was looked up last. This handles the majority of
1297 all searches. */
1299 static unsigned int
1300 lookup_filename (const char *file_name)
1302 static unsigned int last_file_lookup_index = 0;
1303 register char *fn;
1304 register unsigned i;
1305 const char *fnam;
1306 long long cdt = 0;
1307 long ebk = 0;
1308 short ffb = 0;
1309 char rfo = 0;
1310 long siz = 0;
1311 int ver = 0;
1313 fnam = full_name (file_name);
1315 /* Check to see if the file name that was searched on the previous call
1316 matches this file name. If so, return the index. */
1317 if (last_file_lookup_index != 0)
1319 fn = file_info_table[last_file_lookup_index].file_name;
1320 if (strcmp (fnam, fn) == 0)
1321 return last_file_lookup_index;
1324 /* Didn't match the previous lookup, search the table */
1325 for (i = 1; i < file_info_table_in_use; ++i)
1327 fn = file_info_table[i].file_name;
1328 if (strcmp (fnam, fn) == 0)
1330 last_file_lookup_index = i;
1331 return i;
1335 /* Prepare to add a new table entry by making sure there is enough space in
1336 the table to do so. If not, expand the current table. */
1337 if (file_info_table_in_use == file_info_table_allocated)
1340 file_info_table_allocated += FILE_TABLE_INCREMENT;
1341 file_info_table = XRESIZEVEC (dst_file_info_entry, file_info_table,
1342 file_info_table_allocated);
1345 if (vms_file_stats_name (file_name, &cdt, &siz, &rfo, &ver) == 0)
1347 ebk = siz / 512 + 1;
1348 ffb = siz - ((siz / 512) * 512);
1351 /* Add the new entry to the end of the filename table. */
1352 file_info_table[file_info_table_in_use].file_name = xstrdup (fnam);
1353 file_info_table[file_info_table_in_use].max_line = 0;
1354 file_info_table[file_info_table_in_use].cdt = cdt;
1355 file_info_table[file_info_table_in_use].ebk = ebk;
1356 file_info_table[file_info_table_in_use].ffb = ffb;
1357 file_info_table[file_info_table_in_use].rfo = rfo;
1359 last_file_lookup_index = file_info_table_in_use++;
1360 return last_file_lookup_index;
1363 /* Output a label to mark the beginning of a source code line entry
1364 and record information relating to this source line, in
1365 'line_info_table' for later output of the .debug_line section. */
1367 static void
1368 vmsdbgout_write_source_line (unsigned line, const char *filename,
1369 int /* discriminator */, bool /* is_stmt */)
1371 dst_line_info_ref line_info;
1373 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
1374 line_info_table_in_use);
1376 /* Expand the line info table if necessary. */
1377 if (line_info_table_in_use == line_info_table_allocated)
1379 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
1380 line_info_table = XRESIZEVEC (dst_line_info_entry, line_info_table,
1381 line_info_table_allocated);
1384 /* Add the new entry at the end of the line_info_table. */
1385 line_info = &line_info_table[line_info_table_in_use++];
1386 line_info->dst_file_num = lookup_filename (filename);
1387 line_info->dst_line_num = line;
1388 if (line > file_info_table[line_info->dst_file_num].max_line)
1389 file_info_table[line_info->dst_file_num].max_line = line;
1392 static void
1393 vmsdbgout_source_line (register unsigned line, register const char *filename,
1394 int discriminator, bool is_stmt)
1396 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1397 (*dwarf2_debug_hooks.source_line) (line, filename, discriminator, is_stmt);
1399 if (debug_info_level >= DINFO_LEVEL_TERSE)
1400 vmsdbgout_write_source_line (line, filename, discriminator, is_stmt);
1403 /* Record the beginning of a new source file, for later output.
1404 At present, unimplemented. */
1406 static void
1407 vmsdbgout_start_source_file (unsigned int lineno, const char *filename)
1409 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1410 (*dwarf2_debug_hooks.start_source_file) (lineno, filename);
1413 /* Record the end of a source file, for later output.
1414 At present, unimplemented. */
1416 static void
1417 vmsdbgout_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
1419 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1420 (*dwarf2_debug_hooks.end_source_file) (lineno);
1423 /* Set up for Debug output at the start of compilation. */
1425 static void
1426 vmsdbgout_init (const char *filename)
1428 const char *language_string = lang_hooks.name;
1430 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1431 (*dwarf2_debug_hooks.init) (filename);
1433 if (debug_info_level == DINFO_LEVEL_NONE)
1434 return;
1436 /* Remember the name of the primary input file. */
1437 primary_filename = filename;
1439 /* Allocate the initial hunk of the file_info_table. */
1440 file_info_table = XCNEWVEC (dst_file_info_entry, FILE_TABLE_INCREMENT);
1441 file_info_table_allocated = FILE_TABLE_INCREMENT;
1442 /* Skip the first entry - file numbers begin at 1. */
1443 file_info_table_in_use = 1;
1445 funcnam_table.create (FUNC_TABLE_INITIAL);
1446 funcnum_table.create (FUNC_TABLE_INITIAL);
1448 /* Allocate the initial hunk of the line_info_table. */
1449 line_info_table = XCNEWVEC (dst_line_info_entry, LINE_INFO_TABLE_INCREMENT);
1450 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
1451 /* zero-th entry is allocated, but unused */
1452 line_info_table_in_use = 1;
1454 lookup_filename (primary_filename);
1456 if (!strcmp (language_string, "GNU C"))
1457 module_language = DST_K_C;
1458 else if (!strcmp (language_string, "GNU C++"))
1459 module_language = DST_K_CXX;
1460 else if (!strcmp (language_string, "GNU Ada"))
1461 module_language = DST_K_ADA;
1462 else if (!strcmp (language_string, "GNU F77"))
1463 module_language = DST_K_FORTRAN;
1464 else
1465 module_language = DST_K_UNKNOWN;
1467 module_producer = concat (language_string, " ", version_string, NULL);
1469 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
1473 /* Not implemented in VMS Debug. */
1475 static void
1476 vmsdbgout_assembly_start (void)
1478 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1479 (*dwarf2_debug_hooks.assembly_start) ();
1482 /* Not implemented in VMS Debug. */
1484 static void
1485 vmsdbgout_define (unsigned int lineno, const char *buffer)
1487 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1488 (*dwarf2_debug_hooks.define) (lineno, buffer);
1491 /* Not implemented in VMS Debug. */
1493 static void
1494 vmsdbgout_undef (unsigned int lineno, const char *buffer)
1496 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1497 (*dwarf2_debug_hooks.undef) (lineno, buffer);
1500 /* Not implemented in VMS Debug. */
1502 static void
1503 vmsdbgout_decl (tree decl)
1505 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1506 (*dwarf2_debug_hooks.function_decl) (decl);
1509 /* Not implemented in VMS Debug. */
1511 static void
1512 vmsdbgout_global_decl (tree decl)
1514 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1515 (*dwarf2_debug_hooks.global_decl) (decl);
1518 /* Not implemented in VMS Debug. */
1520 static void
1521 vmsdbgout_type_decl (tree decl, int local)
1523 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1524 (*dwarf2_debug_hooks.type_decl) (decl, local);
1527 /* Not implemented in VMS Debug. */
1529 static void
1530 vmsdbgout_abstract_function (tree decl)
1532 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1533 (*dwarf2_debug_hooks.outlining_inline_function) (decl);
1536 /* Output stuff that Debug requires at the end of every file and generate the
1537 VMS Debug debugging info. */
1539 static void
1540 vmsdbgout_finish (const char *filename ATTRIBUTE_UNUSED)
1542 unsigned int i, ifunc;
1543 int totsize;
1545 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1546 (*dwarf2_debug_hooks.finish) (filename);
1548 if (debug_info_level == DINFO_LEVEL_NONE)
1549 return;
1551 /* Output a terminator label for the .text section. */
1552 switch_to_section (text_section);
1553 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
1555 /* Output debugging information.
1556 Warning! Do not change the name of the .vmsdebug section without
1557 changing it in the assembler also. */
1558 switch_to_section (get_named_section (NULL, ".vmsdebug", 0));
1559 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1561 totsize = write_modbeg (1);
1562 FOR_EACH_VEC_ELT (funcnum_table, i, ifunc)
1564 totsize += write_rtnbeg (i, 1);
1565 totsize += write_rtnend (i, 1);
1567 totsize += write_pclines (1);
1569 write_modbeg (0);
1570 FOR_EACH_VEC_ELT (funcnum_table, i, ifunc)
1572 write_rtnbeg (i, 0);
1573 write_rtnend (i, 0);
1575 write_pclines (0);
1577 if (debug_info_level > DINFO_LEVEL_TERSE)
1579 totsize = write_srccorrs (1);
1580 write_srccorrs (0);
1583 totsize = write_modend (1);
1584 write_modend (0);
1587 /* Need for both Dwarf2 on IVMS and VMS Debug on AVMS */
1589 #ifdef VMS
1590 #define __NEW_STARLET 1
1591 #include <vms/rms.h>
1592 #include <vms/atrdef.h>
1593 #include <vms/fibdef.h>
1594 #include <vms/stsdef.h>
1595 #include <vms/iodef.h>
1596 #include <vms/fatdef.h>
1597 #include <vms/descrip.h>
1598 #include <unixlib.h>
1600 #define MAXPATH 256
1602 /* descrip.h doesn't have everything ... */
1603 typedef struct fibdef* __fibdef_ptr32 __attribute__ (( mode (SI) ));
1604 struct dsc$descriptor_fib
1606 unsigned int fib$l_len;
1607 __fibdef_ptr32 fib$l_addr;
1610 /* I/O Status Block. */
1611 struct IOSB
1613 unsigned short status, count;
1614 unsigned int devdep;
1617 static char *tryfile;
1619 /* Variable length string. */
1620 struct vstring
1622 short length;
1623 char string[NAM$C_MAXRSS+1];
1626 static char filename_buff [MAXPATH];
1627 static char vms_filespec [MAXPATH];
1629 /* Callback function for filespec style conversion. */
1631 static int
1632 translate_unix (char *name, int type ATTRIBUTE_UNUSED)
1634 strncpy (filename_buff, name, MAXPATH);
1635 filename_buff [MAXPATH - 1] = (char) 0;
1636 return 0;
1639 /* Wrapper for DECC function that converts a Unix filespec
1640 to VMS style filespec. */
1642 static char *
1643 to_vms_file_spec (char *filespec)
1645 strncpy (vms_filespec, "", MAXPATH);
1646 decc$to_vms (filespec, translate_unix, 1, 1);
1647 strncpy (vms_filespec, filename_buff, MAXPATH);
1649 vms_filespec [MAXPATH - 1] = (char) 0;
1651 return vms_filespec;
1654 #else
1655 #define VMS_EPOCH_OFFSET 35067168000000000LL
1656 #define VMS_GRANULARITY_FACTOR 10000000
1657 #endif
1659 /* Return VMS file date, size, format, version given a name. */
1662 vms_file_stats_name (const char *filename, long long *cdt, long *siz, char *rfo,
1663 int *ver)
1665 #ifdef VMS
1666 struct FAB fab;
1667 struct NAM nam;
1669 unsigned long long create;
1670 FAT recattr;
1671 char ascnamebuff [256];
1673 ATRDEF atrlst[]
1675 { ATR$S_CREDATE, ATR$C_CREDATE, &create },
1676 { ATR$S_RECATTR, ATR$C_RECATTR, &recattr },
1677 { ATR$S_ASCNAME, ATR$C_ASCNAME, &ascnamebuff },
1678 { 0, 0, 0}
1681 FIBDEF fib;
1682 struct dsc$descriptor_fib fibdsc = {sizeof (fib), (void *) &fib};
1684 struct IOSB iosb;
1686 long status;
1687 unsigned short chan;
1689 struct vstring file;
1690 struct dsc$descriptor_s filedsc
1691 = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) file.string};
1692 struct vstring device;
1693 struct dsc$descriptor_s devicedsc
1694 = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) device.string};
1695 struct vstring result;
1696 struct dsc$descriptor_s resultdsc
1697 = {NAM$C_MAXRSS, DSC$K_DTYPE_VT, DSC$K_CLASS_VS, (void *) result.string};
1699 if (strcmp (filename, "<internal>") == 0
1700 || strcmp (filename, "<built-in>") == 0)
1702 if (cdt)
1703 *cdt = 0;
1705 if (siz)
1706 *siz = 0;
1708 if (rfo)
1709 *rfo = 0;
1711 if (ver)
1712 *ver = 0;
1714 return 0;
1717 tryfile = to_vms_file_spec (filename);
1719 /* Allocate and initialize a FAB and NAM structures. */
1720 fab = cc$rms_fab;
1721 nam = cc$rms_nam;
1723 nam.nam$l_esa = file.string;
1724 nam.nam$b_ess = NAM$C_MAXRSS;
1725 nam.nam$l_rsa = result.string;
1726 nam.nam$b_rss = NAM$C_MAXRSS;
1727 fab.fab$l_fna = tryfile;
1728 fab.fab$b_fns = strlen (tryfile);
1729 fab.fab$l_nam = &nam;
1731 /* Validate filespec syntax and device existence. */
1732 status = SYS$PARSE (&fab, 0, 0);
1733 if ((status & 1) != 1)
1734 return 1;
1736 file.string[nam.nam$b_esl] = 0;
1738 /* Find matching filespec. */
1739 status = SYS$SEARCH (&fab, 0, 0);
1740 if ((status & 1) != 1)
1741 return 1;
1743 file.string[nam.nam$b_esl] = 0;
1744 result.string[result.length=nam.nam$b_rsl] = 0;
1746 /* Get the device name and assign an IO channel. */
1747 strncpy (device.string, nam.nam$l_dev, nam.nam$b_dev);
1748 devicedsc.dsc$w_length = nam.nam$b_dev;
1749 chan = 0;
1750 status = SYS$ASSIGN (&devicedsc, &chan, 0, 0, 0);
1751 if ((status & 1) != 1)
1752 return 1;
1754 /* Initialize the FIB and fill in the directory id field. */
1755 memset (&fib, 0, sizeof (fib));
1756 fib.fib$w_did[0] = nam.nam$w_did[0];
1757 fib.fib$w_did[1] = nam.nam$w_did[1];
1758 fib.fib$w_did[2] = nam.nam$w_did[2];
1759 fib.fib$l_acctl = 0;
1760 fib.fib$l_wcc = 0;
1761 strcpy (file.string, (strrchr (result.string, ']') + 1));
1762 filedsc.dsc$w_length = strlen (file.string);
1763 result.string[result.length = 0] = 0;
1765 /* Open and close the file to fill in the attributes. */
1766 status
1767 = SYS$QIOW (0, chan, IO$_ACCESS|IO$M_ACCESS, &iosb, 0, 0,
1768 &fibdsc, &filedsc, &result.length, &resultdsc, &atrlst, 0);
1769 if ((status & 1) != 1)
1770 return 1;
1771 if ((iosb.status & 1) != 1)
1772 return 1;
1774 result.string[result.length] = 0;
1775 status = SYS$QIOW (0, chan, IO$_DEACCESS, &iosb, 0, 0, &fibdsc, 0, 0, 0,
1776 &atrlst, 0);
1777 if ((status & 1) != 1)
1778 return 1;
1779 if ((iosb.status & 1) != 1)
1780 return 1;
1782 /* Deassign the channel and exit. */
1783 status = SYS$DASSGN (chan);
1784 if ((status & 1) != 1)
1785 return 1;
1787 if (cdt) *cdt = create;
1788 if (siz) *siz = (512 * 65536 * recattr.fat$w_efblkh) +
1789 (512 * (recattr.fat$w_efblkl - 1)) +
1790 recattr.fat$w_ffbyte;
1791 if (rfo) *rfo = recattr.fat$v_rtype;
1792 if (ver) *ver = strtol (strrchr (ascnamebuff, ';')+1, 0, 10);
1794 return 0;
1795 #else
1796 struct stat buff;
1798 if ((stat (filename, &buff)) != 0)
1799 return 1;
1801 if (cdt)
1802 *cdt = (long long) (buff.st_mtime * VMS_GRANULARITY_FACTOR)
1803 + VMS_EPOCH_OFFSET;
1805 if (siz)
1806 *siz = buff.st_size;
1808 if (rfo)
1809 *rfo = 2; /* Stream LF format */
1811 if (ver)
1812 *ver = 1;
1814 return 0;
1815 #endif
1817 #endif