Fix a bug that broke -freorder-functions
[official-gcc.git] / gcc / vmsdbgout.c
blob84a96c010e7d01fa8d5f0a845289393f022cff16
1 /* Output VMS debug format symbol table information from GCC.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5 Contributed by Douglas B. Rupp (rupp@gnat.com).
6 Updated by Bernard W. Giroud (bgiroud@users.sourceforge.net).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
13 version.
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
29 #ifdef VMS_DEBUGGING_INFO
30 #include "tree.h"
31 #include "version.h"
32 #include "flags.h"
33 #include "rtl.h"
34 #include "output.h"
35 #include "vmsdbg.h"
36 #include "debug.h"
37 #include "langhooks.h"
38 #include "function.h"
39 #include "target.h"
41 /* Difference in seconds between the VMS Epoch and the Unix Epoch */
42 static const long long vms_epoch_offset = 3506716800ll;
44 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
46 /* NOTE: In the comments in this file, many references are made to "Debug
47 Symbol Table". This term is abbreviated as `DST' throughout the remainder
48 of this file. */
50 typedef struct dst_line_info_struct *dst_line_info_ref;
52 /* Each entry in the line_info_table maintains the file and
53 line number associated with the label generated for that
54 entry. The label gives the PC value associated with
55 the line number entry. */
56 typedef struct dst_line_info_struct
58 unsigned long dst_file_num;
59 unsigned long dst_line_num;
61 dst_line_info_entry;
63 typedef struct dst_file_info_struct *dst_file_info_ref;
65 typedef struct dst_file_info_struct
67 char *file_name;
68 unsigned int max_line;
69 unsigned int listing_line_start;
70 long long cdt;
71 long ebk;
72 short ffb;
73 char rfo;
75 dst_file_info_entry;
77 /* Maximum size (in bytes) of an artificially generated label. */
78 #define MAX_ARTIFICIAL_LABEL_BYTES 30
80 /* Make sure we know the sizes of the various types debug can describe. These
81 are only defaults. If the sizes are different for your target, you should
82 override these values by defining the appropriate symbols in your tm.h
83 file. */
84 #ifndef PTR_SIZE
85 #define PTR_SIZE 4 /* Must be 32 bits for VMS debug info */
86 #endif
88 /* Pointer to a structure of filenames referenced by this compilation unit. */
89 static dst_file_info_ref file_info_table;
91 /* Total number of entries in the table (i.e. array) pointed to by
92 `file_info_table'. This is the *total* and includes both used and unused
93 slots. */
94 static unsigned int file_info_table_allocated;
96 /* Number of entries in the file_info_table which are actually in use. */
97 static unsigned int file_info_table_in_use;
99 /* Size (in elements) of increments by which we may expand the filename
100 table. */
101 #define FILE_TABLE_INCREMENT 64
103 typedef char *char_p;
104 DEF_VEC_P(char_p);
105 DEF_VEC_ALLOC_P(char_p,heap);
107 static VEC(char_p,heap) *funcnam_table;
108 static VEC(unsigned,heap) *funcnum_table;
109 #define FUNC_TABLE_INITIAL 256
111 /* Local pointer to the name of the main input file. Initialized in
112 vmsdbgout_init. */
113 static const char *primary_filename;
115 static char *module_producer;
116 static unsigned int module_language;
118 /* A pointer to the base of a table that contains line information
119 for each source code line in .text in the compilation unit. */
120 static dst_line_info_ref line_info_table;
122 /* Number of elements currently allocated for line_info_table. */
123 static unsigned int line_info_table_allocated;
125 /* Number of elements in line_info_table currently in use. */
126 static unsigned int line_info_table_in_use;
128 /* Size (in elements) of increments by which we may expand line_info_table. */
129 #define LINE_INFO_TABLE_INCREMENT 1024
131 /* Forward declarations for functions defined in this file. */
132 static char *full_name (const char *);
133 static unsigned int lookup_filename (const char *);
134 static int write_debug_header (DST_HEADER *, const char *, int);
135 static int write_debug_addr (const char *, const char *, int);
136 static int write_debug_data1 (unsigned int, const char *, int);
137 static int write_debug_data2 (unsigned int, const char *, int);
138 static int write_debug_data4 (unsigned long, const char *, int);
139 static int write_debug_data8 (unsigned long long, const char *, int);
140 static int write_debug_delta4 (const char *, const char *, const char *, int);
141 static int write_debug_string (const char *, const char *, int);
142 static int write_modbeg (int);
143 static int write_modend (int);
144 static int write_rtnbeg (int, int);
145 static int write_rtnend (int, int);
146 static int write_pclines (int);
147 static int write_srccorr (int, dst_file_info_entry, int);
148 static int write_srccorrs (int);
150 static void vmsdbgout_init (const char *);
151 static void vmsdbgout_finish (const char *);
152 static void vmsdbgout_assembly_start (void);
153 static void vmsdbgout_define (unsigned int, const char *);
154 static void vmsdbgout_undef (unsigned int, const char *);
155 static void vmsdbgout_start_source_file (unsigned int, const char *);
156 static void vmsdbgout_end_source_file (unsigned int);
157 static void vmsdbgout_begin_block (unsigned int, unsigned int);
158 static void vmsdbgout_end_block (unsigned int, unsigned int);
159 static bool vmsdbgout_ignore_block (const_tree);
160 static void vmsdbgout_source_line (unsigned int, const char *, int, bool);
161 static void vmsdbgout_begin_prologue (unsigned int, const char *);
162 static void vmsdbgout_end_prologue (unsigned int, const char *);
163 static void vmsdbgout_end_function (unsigned int);
164 static void vmsdbgout_begin_epilogue (unsigned int, const char *);
165 static void vmsdbgout_end_epilogue (unsigned int, const char *);
166 static void vmsdbgout_begin_function (tree);
167 static void vmsdbgout_decl (tree);
168 static void vmsdbgout_global_decl (tree);
169 static void vmsdbgout_type_decl (tree, int);
170 static void vmsdbgout_abstract_function (tree);
172 /* The debug hooks structure. */
174 const struct gcc_debug_hooks vmsdbg_debug_hooks
175 = {vmsdbgout_init,
176 vmsdbgout_finish,
177 vmsdbgout_assembly_start,
178 vmsdbgout_define,
179 vmsdbgout_undef,
180 vmsdbgout_start_source_file,
181 vmsdbgout_end_source_file,
182 vmsdbgout_begin_block,
183 vmsdbgout_end_block,
184 vmsdbgout_ignore_block,
185 vmsdbgout_source_line,
186 vmsdbgout_begin_prologue,
187 vmsdbgout_end_prologue,
188 vmsdbgout_begin_epilogue,
189 vmsdbgout_end_epilogue,
190 vmsdbgout_begin_function,
191 vmsdbgout_end_function,
192 vmsdbgout_decl,
193 vmsdbgout_global_decl,
194 vmsdbgout_type_decl, /* type_decl */
195 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
196 debug_nothing_tree, /* deferred_inline_function */
197 vmsdbgout_abstract_function,
198 debug_nothing_rtx, /* label */
199 debug_nothing_int, /* handle_pch */
200 debug_nothing_rtx, /* var_location */
201 debug_nothing_void, /* switch_text_section */
202 debug_nothing_tree_tree, /* set_name */
203 0, /* start_end_main_source_file */
204 TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
207 /* Definitions of defaults for assembler-dependent names of various
208 pseudo-ops and section names.
209 Theses may be overridden in the tm.h file (if necessary) for a particular
210 assembler. */
211 #ifdef UNALIGNED_SHORT_ASM_OP
212 #undef UNALIGNED_SHORT_ASM_OP
213 #endif
214 #define UNALIGNED_SHORT_ASM_OP ".word"
216 #ifdef UNALIGNED_INT_ASM_OP
217 #undef UNALIGNED_INT_ASM_OP
218 #endif
219 #define UNALIGNED_INT_ASM_OP ".long"
221 #ifdef UNALIGNED_LONG_ASM_OP
222 #undef UNALIGNED_LONG_ASM_OP
223 #endif
224 #define UNALIGNED_LONG_ASM_OP ".long"
226 #ifdef UNALIGNED_DOUBLE_INT_ASM_OP
227 #undef UNALIGNED_DOUBLE_INT_ASM_OP
228 #endif
229 #define UNALIGNED_DOUBLE_INT_ASM_OP ".quad"
231 #ifdef ASM_BYTE_OP
232 #undef ASM_BYTE_OP
233 #endif
234 #define ASM_BYTE_OP ".byte"
236 #define NUMBYTES(I) ((I) < 256 ? 1 : (I) < 65536 ? 2 : 4)
238 #define NUMBYTES0(I) ((I) < 128 ? 0 : (I) < 65536 ? 2 : 4)
240 #ifndef UNALIGNED_PTR_ASM_OP
241 #define UNALIGNED_PTR_ASM_OP \
242 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
243 #endif
245 #ifndef UNALIGNED_OFFSET_ASM_OP
246 #define UNALIGNED_OFFSET_ASM_OP(OFFSET) \
247 (NUMBYTES(OFFSET) == 4 \
248 ? UNALIGNED_LONG_ASM_OP \
249 : (NUMBYTES(OFFSET) == 2 ? UNALIGNED_SHORT_ASM_OP : ASM_BYTE_OP))
250 #endif
252 /* Definitions of defaults for formats and names of various special
253 (artificial) labels which may be generated within this file (when the -g
254 options is used and VMS_DEBUGGING_INFO is in effect. If necessary, these
255 may be overridden from within the tm.h file, but typically, overriding these
256 defaults is unnecessary. */
258 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
260 #ifndef TEXT_END_LABEL
261 #define TEXT_END_LABEL "Lvetext"
262 #endif
263 #ifndef FUNC_BEGIN_LABEL
264 #define FUNC_BEGIN_LABEL "LVFB"
265 #endif
266 #ifndef FUNC_PROLOG_LABEL
267 #define FUNC_PROLOG_LABEL "LVFP"
268 #endif
269 #ifndef FUNC_EPILOG_LABEL
270 #define FUNC_EPILOG_LABEL "LVEB"
271 #endif
272 #ifndef FUNC_END_LABEL
273 #define FUNC_END_LABEL "LVFE"
274 #endif
275 #ifndef BLOCK_BEGIN_LABEL
276 #define BLOCK_BEGIN_LABEL "LVBB"
277 #endif
278 #ifndef BLOCK_END_LABEL
279 #define BLOCK_END_LABEL "LVBE"
280 #endif
281 #ifndef LINE_CODE_LABEL
282 #define LINE_CODE_LABEL "LVM"
283 #endif
285 #ifndef ASM_OUTPUT_DEBUG_DELTA2
286 #define ASM_OUTPUT_DEBUG_DELTA2(FILE,LABEL1,LABEL2) \
287 do \
289 fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
290 assemble_name (FILE, LABEL1); \
291 fprintf (FILE, "-"); \
292 assemble_name (FILE, LABEL2); \
294 while (0)
295 #endif
297 #ifndef ASM_OUTPUT_DEBUG_DELTA4
298 #define ASM_OUTPUT_DEBUG_DELTA4(FILE,LABEL1,LABEL2) \
299 do \
301 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
302 assemble_name (FILE, LABEL1); \
303 fprintf (FILE, "-"); \
304 assemble_name (FILE, LABEL2); \
306 while (0)
307 #endif
309 #ifndef ASM_OUTPUT_DEBUG_ADDR_DELTA
310 #define ASM_OUTPUT_DEBUG_ADDR_DELTA(FILE,LABEL1,LABEL2) \
311 do \
313 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
314 assemble_name (FILE, LABEL1); \
315 fprintf (FILE, "-"); \
316 assemble_name (FILE, LABEL2); \
318 while (0)
319 #endif
321 #ifndef ASM_OUTPUT_DEBUG_ADDR
322 #define ASM_OUTPUT_DEBUG_ADDR(FILE,LABEL) \
323 do \
325 fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP); \
326 assemble_name (FILE, LABEL); \
328 while (0)
329 #endif
331 #ifndef ASM_OUTPUT_DEBUG_ADDR_CONST
332 #define ASM_OUTPUT_DEBUG_ADDR_CONST(FILE,ADDR) \
333 fprintf ((FILE), "\t%s\t%s", UNALIGNED_PTR_ASM_OP, (ADDR))
334 #endif
336 #ifndef ASM_OUTPUT_DEBUG_DATA1
337 #define ASM_OUTPUT_DEBUG_DATA1(FILE,VALUE) \
338 fprintf ((FILE), "\t%s\t%#x", ASM_BYTE_OP, (unsigned char) VALUE)
339 #endif
341 #ifndef ASM_OUTPUT_DEBUG_DATA2
342 #define ASM_OUTPUT_DEBUG_DATA2(FILE,VALUE) \
343 fprintf ((FILE), "\t%s\t%#x", UNALIGNED_SHORT_ASM_OP, \
344 (unsigned short) VALUE)
345 #endif
347 #ifndef ASM_OUTPUT_DEBUG_DATA4
348 #define ASM_OUTPUT_DEBUG_DATA4(FILE,VALUE) \
349 fprintf ((FILE), "\t%s\t%#lx", UNALIGNED_INT_ASM_OP, (unsigned long) VALUE)
350 #endif
352 #ifndef ASM_OUTPUT_DEBUG_DATA
353 #define ASM_OUTPUT_DEBUG_DATA(FILE,VALUE) \
354 fprintf ((FILE), "\t%s\t%#lx", UNALIGNED_OFFSET_ASM_OP(VALUE), VALUE)
355 #endif
357 #ifndef ASM_OUTPUT_DEBUG_ADDR_DATA
358 #define ASM_OUTPUT_DEBUG_ADDR_DATA(FILE,VALUE) \
359 fprintf ((FILE), "\t%s\t%#lx", UNALIGNED_PTR_ASM_OP, \
360 (unsigned long) VALUE)
361 #endif
363 #ifndef ASM_OUTPUT_DEBUG_DATA8
364 #define ASM_OUTPUT_DEBUG_DATA8(FILE,VALUE) \
365 fprintf ((FILE), "\t%s\t%#llx", UNALIGNED_DOUBLE_INT_ASM_OP, \
366 (unsigned long long) VALUE)
367 #endif
369 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
370 newline is produced. When flag_verbose_asm is asserted, we add commentary
371 at the end of the line, so we must avoid output of a newline here. */
372 #ifndef ASM_OUTPUT_DEBUG_STRING
373 #define ASM_OUTPUT_DEBUG_STRING(FILE,P) \
374 do \
376 register int slen = strlen(P); \
377 register const char *p = (P); \
378 register int i; \
379 fprintf (FILE, "\t.ascii \""); \
380 for (i = 0; i < slen; i++) \
382 register int c = p[i]; \
383 if (c == '\"' || c == '\\') \
384 putc ('\\', FILE); \
385 if (c >= ' ' && c < 0177) \
386 putc (c, FILE); \
387 else \
388 fprintf (FILE, "\\%o", c); \
390 fprintf (FILE, "\""); \
392 while (0)
393 #endif
395 /* Convert a reference to the assembler name of a C-level name. This
396 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
397 a string rather than writing to a file. */
398 #ifndef ASM_NAME_TO_STRING
399 #define ASM_NAME_TO_STRING(STR, NAME) \
400 do \
402 if ((NAME)[0] == '*') \
403 strcpy (STR, NAME+1); \
404 else \
405 strcpy (STR, NAME); \
407 while (0)
408 #endif
411 /* Output the debug header HEADER. Also output COMMENT if flag_verbose_asm is
412 set. Return the header size. Just return the size if DOSIZEONLY is
413 nonzero. */
415 static int
416 write_debug_header (DST_HEADER *header, const char *comment, int dosizeonly)
418 if (!dosizeonly)
420 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
421 header->dst__header_length.dst_w_length);
423 if (flag_verbose_asm)
424 fprintf (asm_out_file, "\t%s record length", ASM_COMMENT_START);
425 fputc ('\n', asm_out_file);
427 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
428 header->dst__header_type.dst_w_type);
430 if (flag_verbose_asm)
431 fprintf (asm_out_file, "\t%s record type (%s)", ASM_COMMENT_START,
432 comment);
434 fputc ('\n', asm_out_file);
437 return 4;
440 /* Output the address of SYMBOL. Also output COMMENT if flag_verbose_asm is
441 set. Return the address size. Just return the size if DOSIZEONLY is
442 nonzero. */
444 static int
445 write_debug_addr (const char *symbol, const char *comment, int dosizeonly)
447 if (!dosizeonly)
449 ASM_OUTPUT_DEBUG_ADDR (asm_out_file, symbol);
450 if (flag_verbose_asm)
451 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
452 fputc ('\n', asm_out_file);
455 return PTR_SIZE;
458 /* Output the single byte DATA1. Also output COMMENT if flag_verbose_asm is
459 set. Return the data size. Just return the size if DOSIZEONLY is
460 nonzero. */
462 static int
463 write_debug_data1 (unsigned int data1, const char *comment, int dosizeonly)
465 if (!dosizeonly)
467 ASM_OUTPUT_DEBUG_DATA1 (asm_out_file, data1);
468 if (flag_verbose_asm)
469 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
470 fputc ('\n', asm_out_file);
473 return 1;
476 /* Output the single word DATA2. Also output COMMENT if flag_verbose_asm is
477 set. Return the data size. Just return the size if DOSIZEONLY is
478 nonzero. */
480 static int
481 write_debug_data2 (unsigned int data2, const char *comment, int dosizeonly)
483 if (!dosizeonly)
485 ASM_OUTPUT_DEBUG_DATA2 (asm_out_file, data2);
486 if (flag_verbose_asm)
487 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
488 fputc ('\n', asm_out_file);
491 return 2;
494 /* Output double word DATA4. Also output COMMENT if flag_verbose_asm is set.
495 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
497 static int
498 write_debug_data4 (unsigned long data4, const char *comment, int dosizeonly)
500 if (!dosizeonly)
502 ASM_OUTPUT_DEBUG_DATA4 (asm_out_file, data4);
503 if (flag_verbose_asm)
504 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
505 fputc ('\n', asm_out_file);
508 return 4;
511 /* Output quad word DATA8. Also output COMMENT if flag_verbose_asm is set.
512 Return the data size. Just return the size if DOSIZEONLY is nonzero. */
514 static int
515 write_debug_data8 (unsigned long long data8, const char *comment,
516 int dosizeonly)
518 if (!dosizeonly)
520 ASM_OUTPUT_DEBUG_DATA8 (asm_out_file, data8);
521 if (flag_verbose_asm)
522 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
523 fputc ('\n', asm_out_file);
526 return 8;
529 /* Output the difference between LABEL1 and LABEL2. Also output COMMENT if
530 flag_verbose_asm is set. Return the data size. Just return the size if
531 DOSIZEONLY is nonzero. */
533 static int
534 write_debug_delta4 (const char *label1, const char *label2,
535 const char *comment, int dosizeonly)
537 if (!dosizeonly)
539 ASM_OUTPUT_DEBUG_DELTA4 (asm_out_file, label1, label2);
540 if (flag_verbose_asm)
541 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
542 fputc ('\n', asm_out_file);
545 return 4;
548 /* Output a character string STRING. Also write COMMENT if flag_verbose_asm is
549 set. Return the string length. Just return the length if DOSIZEONLY is
550 nonzero. */
552 static int
553 write_debug_string (const char *string, const char *comment, int dosizeonly)
555 if (!dosizeonly)
557 ASM_OUTPUT_DEBUG_STRING (asm_out_file, string);
558 if (flag_verbose_asm)
559 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
560 fputc ('\n', asm_out_file);
563 return strlen (string);
566 /* Output a module begin header and return the header size. Just return the
567 size if DOSIZEONLY is nonzero. */
569 static int
570 write_modbeg (int dosizeonly)
572 DST_MODULE_BEGIN modbeg;
573 DST_MB_TRLR mb_trlr;
574 int i;
575 char *module_name, *m;
576 int modnamelen;
577 int prodnamelen;
578 int totsize = 0;
580 /* Assumes primary filename has Unix syntax file spec. */
581 module_name = xstrdup (lbasename (primary_filename));
583 m = strrchr (module_name, '.');
584 if (m)
585 *m = 0;
587 modnamelen = strlen (module_name);
588 for (i = 0; i < modnamelen; i++)
589 module_name[i] = TOUPPER (module_name[i]);
591 prodnamelen = strlen (module_producer);
593 modbeg.dst_a_modbeg_header.dst__header_length.dst_w_length
594 = DST_K_MODBEG_SIZE + modnamelen + DST_K_MB_TRLR_SIZE + prodnamelen - 1;
595 modbeg.dst_a_modbeg_header.dst__header_type.dst_w_type = DST_K_MODBEG;
596 modbeg.dst_b_modbeg_flags.dst_v_modbeg_hide = 0;
597 modbeg.dst_b_modbeg_flags.dst_v_modbeg_version = 1;
598 modbeg.dst_b_modbeg_flags.dst_v_modbeg_unused = 0;
599 modbeg.dst_b_modbeg_unused = 0;
600 modbeg.dst_l_modbeg_language = (DST_LANGUAGE) module_language;
601 modbeg.dst_w_version_major = DST_K_VERSION_MAJOR;
602 modbeg.dst_w_version_minor = DST_K_VERSION_MINOR;
603 modbeg.dst_b_modbeg_name = strlen (module_name);
605 mb_trlr.dst_b_compiler = strlen (module_producer);
607 totsize += write_debug_header (&modbeg.dst_a_modbeg_header,
608 "modbeg", dosizeonly);
609 totsize += write_debug_data1 (*((char *) &modbeg.dst_b_modbeg_flags),
610 "flags", dosizeonly);
611 totsize += write_debug_data1 (modbeg.dst_b_modbeg_unused,
612 "unused", dosizeonly);
613 totsize += write_debug_data4 (modbeg.dst_l_modbeg_language,
614 "language", dosizeonly);
615 totsize += write_debug_data2 (modbeg.dst_w_version_major,
616 "DST major version", dosizeonly);
617 totsize += write_debug_data2 (modbeg.dst_w_version_minor,
618 "DST minor version", dosizeonly);
619 totsize += write_debug_data1 (modbeg.dst_b_modbeg_name,
620 "length of module name", dosizeonly);
621 totsize += write_debug_string (module_name, "module name", dosizeonly);
622 totsize += write_debug_data1 (mb_trlr.dst_b_compiler,
623 "length of compiler name", dosizeonly);
624 totsize += write_debug_string (module_producer, "compiler name", dosizeonly);
626 return totsize;
629 /* Output a module end trailer and return the trailer size. Just return
630 the size if DOSIZEONLY is nonzero. */
632 static int
633 write_modend (int dosizeonly)
635 DST_MODULE_END modend;
636 int totsize = 0;
638 modend.dst_a_modend_header.dst__header_length.dst_w_length
639 = DST_K_MODEND_SIZE - 1;
640 modend.dst_a_modend_header.dst__header_type.dst_w_type = DST_K_MODEND;
642 totsize += write_debug_header (&modend.dst_a_modend_header, "modend",
643 dosizeonly);
645 return totsize;
648 /* Output a routine begin header routine RTNNUM and return the header size.
649 Just return the size if DOSIZEONLY is nonzero. */
651 static int
652 write_rtnbeg (int rtnnum, int dosizeonly)
654 const char *rtnname;
655 int rtnnamelen;
656 char *rtnentryname;
657 int totsize = 0;
658 char label[MAX_ARTIFICIAL_LABEL_BYTES];
659 DST_ROUTINE_BEGIN rtnbeg;
660 DST_PROLOG prolog;
662 rtnname = VEC_index (char_p, funcnam_table, rtnnum);
663 rtnnamelen = strlen (rtnname);
664 rtnentryname = concat (rtnname, "..en", NULL);
666 if (!strcmp (rtnname, "main"))
668 DST_HEADER header;
669 const char *go = "TRANSFER$BREAK$GO";
671 /* This command isn't documented in DSTRECORDS, so it's made to
672 look like what DEC C does */
674 /* header size - 1st byte + flag byte + STO_LW size
675 + string count byte + string length */
676 header.dst__header_length.dst_w_length
677 = DST_K_DST_HEADER_SIZE - 1 + 1 + 4 + 1 + strlen (go);
678 header.dst__header_type.dst_w_type = DST_K_TBG;
680 totsize += write_debug_header (&header, "transfer", dosizeonly);
682 /* I think this is a flag byte, but I don't know what this flag means */
683 totsize += write_debug_data1 (0x1, "flags ???", dosizeonly);
685 /* Routine Begin PD Address */
686 totsize += write_debug_addr (rtnname, "main procedure descriptor",
687 dosizeonly);
688 totsize += write_debug_data1 (strlen (go), "length of main_name",
689 dosizeonly);
690 totsize += write_debug_string (go, "main name", dosizeonly);
693 /* The header length never includes the length byte. */
694 rtnbeg.dst_a_rtnbeg_header.dst__header_length.dst_w_length
695 = DST_K_RTNBEG_SIZE + rtnnamelen - 1;
696 rtnbeg.dst_a_rtnbeg_header.dst__header_type.dst_w_type = DST_K_RTNBEG;
697 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unused = 0;
698 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unalloc = 0;
699 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_prototype = 0;
700 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_inlined = 0;
701 rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_no_call = 1;
702 rtnbeg.dst_b_rtnbeg_name = rtnnamelen;
704 totsize += write_debug_header (&rtnbeg.dst_a_rtnbeg_header, "rtnbeg",
705 dosizeonly);
706 totsize += write_debug_data1 (*((char *) &rtnbeg.dst_b_rtnbeg_flags),
707 "flags", dosizeonly);
709 /* Routine Begin Address */
710 totsize += write_debug_addr (rtnentryname, "routine entry name", dosizeonly);
712 /* Routine Begin PD Address */
713 totsize += write_debug_addr (rtnname, "routine procedure descriptor",
714 dosizeonly);
716 /* Routine Begin Name */
717 totsize += write_debug_data1 (rtnbeg.dst_b_rtnbeg_name,
718 "length of routine name", dosizeonly);
720 totsize += write_debug_string (rtnname, "routine name", dosizeonly);
722 free (rtnentryname);
724 if (debug_info_level > DINFO_LEVEL_TERSE)
726 prolog.dst_a_prolog_header.dst__header_length.dst_w_length
727 = DST_K_PROLOG_SIZE - 1;
728 prolog.dst_a_prolog_header.dst__header_type.dst_w_type = DST_K_PROLOG;
730 totsize += write_debug_header (&prolog.dst_a_prolog_header, "prolog",
731 dosizeonly);
733 ASM_GENERATE_INTERNAL_LABEL
734 (label, FUNC_PROLOG_LABEL,
735 VEC_index (unsigned, funcnum_table, rtnnum));
736 totsize += write_debug_addr (label, "prolog breakpoint addr",
737 dosizeonly);
740 return totsize;
743 /* Output a routine end trailer for routine RTNNUM and return the header size.
744 Just return the size if DOSIZEONLY is nonzero. */
746 static int
747 write_rtnend (int rtnnum, int dosizeonly)
749 DST_ROUTINE_END rtnend;
750 char label1[MAX_ARTIFICIAL_LABEL_BYTES];
751 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
752 int totsize;
754 totsize = 0;
756 rtnend.dst_a_rtnend_header.dst__header_length.dst_w_length
757 = DST_K_RTNEND_SIZE - 1;
758 rtnend.dst_a_rtnend_header.dst__header_type.dst_w_type = DST_K_RTNEND;
759 rtnend.dst_b_rtnend_unused = 0;
760 rtnend.dst_l_rtnend_size = 0; /* Calculated below. */
762 totsize += write_debug_header (&rtnend.dst_a_rtnend_header, "rtnend",
763 dosizeonly);
764 totsize += write_debug_data1 (rtnend.dst_b_rtnend_unused, "unused",
765 dosizeonly);
767 ASM_GENERATE_INTERNAL_LABEL
768 (label1, FUNC_BEGIN_LABEL,
769 VEC_index (unsigned, funcnum_table, rtnnum));
770 ASM_GENERATE_INTERNAL_LABEL
771 (label2, FUNC_END_LABEL,
772 VEC_index (unsigned, funcnum_table, rtnnum));
773 totsize += write_debug_delta4 (label2, label1, "routine size", dosizeonly);
775 return totsize;
778 #define K_DELTA_PC(I) \
779 ((I) < 128 ? -(I) : (I) < 65536 ? DST_K_DELTA_PC_W : DST_K_DELTA_PC_L)
781 #define K_SET_LINUM(I) \
782 ((I) < 256 ? DST_K_SET_LINUM_B \
783 : (I) < 65536 ? DST_K_SET_LINUM : DST_K_SET_LINUM_L)
785 #define K_INCR_LINUM(I) \
786 ((I) < 256 ? DST_K_INCR_LINUM \
787 : (I) < 65536 ? DST_K_INCR_LINUM_W : DST_K_INCR_LINUM_L)
789 /* Output the PC to line number correlations and return the size. Just return
790 the size if DOSIZEONLY is nonzero */
792 static int
793 write_pclines (int dosizeonly)
795 unsigned i;
796 int fn;
797 int ln, lastln;
798 int linestart = 0;
799 int max_line;
800 DST_LINE_NUM_HEADER line_num;
801 DST_PCLINE_COMMANDS pcline;
802 char label[MAX_ARTIFICIAL_LABEL_BYTES];
803 char lastlabel[MAX_ARTIFICIAL_LABEL_BYTES];
804 int totsize = 0;
805 char buff[256];
807 max_line = file_info_table[1].max_line;
808 file_info_table[1].listing_line_start = linestart;
809 linestart = linestart + ((max_line / 100000) + 1) * 100000;
811 for (i = 2; i < file_info_table_in_use; i++)
813 max_line = file_info_table[i].max_line;
814 file_info_table[i].listing_line_start = linestart;
815 linestart = linestart + ((max_line / 10000) + 1) * 10000;
818 /* Set starting address to beginning of text section. */
819 line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 8;
820 line_num.dst_a_line_num_header.dst__header_type.dst_w_type = DST_K_LINE_NUM;
821 pcline.dst_b_pcline_command = DST_K_SET_ABS_PC;
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 ABS PC)", dosizeonly);
828 if (dosizeonly)
829 totsize += 4;
830 else
832 ASM_OUTPUT_DEBUG_ADDR (asm_out_file, TEXT_SECTION_ASM_OP);
833 if (flag_verbose_asm)
834 fprintf (asm_out_file, "\t%s line_num", ASM_COMMENT_START);
835 fputc ('\n', asm_out_file);
838 fn = line_info_table[1].dst_file_num;
839 ln = (file_info_table[fn].listing_line_start
840 + line_info_table[1].dst_line_num);
841 line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 4 + 4;
842 pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
844 totsize += write_debug_header (&line_num.dst_a_line_num_header,
845 "line_num", dosizeonly);
846 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
847 "line_num (SET LINUM LONG)", dosizeonly);
849 sprintf (buff, "line_num (%d)", ln ? ln - 1 : 0);
850 totsize += write_debug_data4 (ln ? ln - 1 : 0, buff, dosizeonly);
852 lastln = ln;
853 strcpy (lastlabel, TEXT_SECTION_ASM_OP);
854 for (i = 1; i < line_info_table_in_use; i++)
856 int extrabytes;
858 fn = line_info_table[i].dst_file_num;
859 ln = (file_info_table[fn].listing_line_start
860 + line_info_table[i].dst_line_num);
862 if (ln - lastln > 1)
863 extrabytes = 5; /* NUMBYTES (ln - lastln - 1) + 1; */
864 else if (ln <= lastln)
865 extrabytes = 5; /* NUMBYTES (ln - 1) + 1; */
866 else
867 extrabytes = 0;
869 line_num.dst_a_line_num_header.dst__header_length.dst_w_length
870 = 8 + extrabytes;
872 totsize += write_debug_header
873 (&line_num.dst_a_line_num_header, "line_num", dosizeonly);
875 if (ln - lastln > 1)
877 int lndif = ln - lastln - 1;
879 /* K_INCR_LINUM (lndif); */
880 pcline.dst_b_pcline_command = DST_K_INCR_LINUM_L;
882 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
883 "line_num (INCR LINUM LONG)",
884 dosizeonly);
886 sprintf (buff, "line_num (%d)", lndif);
887 totsize += write_debug_data4 (lndif, buff, dosizeonly);
889 else if (ln <= lastln)
891 /* K_SET_LINUM (ln-1); */
892 pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
894 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
895 "line_num (SET LINUM LONG)",
896 dosizeonly);
898 sprintf (buff, "line_num (%d)", ln - 1);
899 totsize += write_debug_data4 (ln - 1, buff, dosizeonly);
902 pcline.dst_b_pcline_command = DST_K_DELTA_PC_L;
904 totsize += write_debug_data1 (pcline.dst_b_pcline_command,
905 "line_num (DELTA PC LONG)", dosizeonly);
907 ASM_GENERATE_INTERNAL_LABEL (label, LINE_CODE_LABEL, i);
908 totsize += write_debug_delta4 (label, lastlabel, "increment line_num",
909 dosizeonly);
911 lastln = ln;
912 strcpy (lastlabel, label);
915 return totsize;
918 /* Output a source correlation for file FILEID using information saved in
919 FILE_INFO_ENTRY and return the size. Just return the size if DOSIZEONLY is
920 nonzero. */
922 static int
923 write_srccorr (int fileid, dst_file_info_entry file_info_entry,
924 int dosizeonly)
926 int src_command_size;
927 int linesleft = file_info_entry.max_line;
928 int linestart = file_info_entry.listing_line_start;
929 int flen = strlen (file_info_entry.file_name);
930 int linestodo = 0;
931 DST_SOURCE_CORR src_header;
932 DST_SRC_COMMAND src_command;
933 DST_SRC_COMMAND src_command_sf;
934 DST_SRC_COMMAND src_command_sl;
935 DST_SRC_COMMAND src_command_sr;
936 DST_SRC_COMMAND src_command_dl;
937 DST_SRC_CMDTRLR src_cmdtrlr;
938 char buff[256];
939 int totsize = 0;
941 if (fileid == 1)
943 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
944 = DST_K_SOURCE_CORR_HEADER_SIZE + 1 - 1;
945 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
946 = DST_K_SOURCE;
947 src_command.dst_b_src_command = DST_K_SRC_FORMFEED;
949 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
950 "source corr", dosizeonly);
952 totsize += write_debug_data1 (src_command.dst_b_src_command,
953 "source_corr (SRC FORMFEED)",
954 dosizeonly);
957 src_command_size
958 = DST_K_SRC_COMMAND_SIZE + flen + DST_K_SRC_CMDTRLR_SIZE;
959 src_command.dst_b_src_command = DST_K_SRC_DECLFILE;
960 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length
961 = src_command_size - 2;
962 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags = 0;
963 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid
964 = fileid;
965 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt
966 = file_info_entry.cdt;
967 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk
968 = file_info_entry.ebk;
969 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb
970 = file_info_entry.ffb;
971 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo
972 = file_info_entry.rfo;
973 src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename
974 = flen;
976 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
977 = DST_K_SOURCE_CORR_HEADER_SIZE + src_command_size - 1;
978 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
979 = DST_K_SOURCE;
981 src_cmdtrlr.dst_b_src_df_libmodname = 0;
983 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
984 "source corr", dosizeonly);
985 totsize += write_debug_data1 (src_command.dst_b_src_command,
986 "source_corr (DECL SRC FILE)", dosizeonly);
987 totsize += write_debug_data1
988 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length,
989 "source_corr (length)", dosizeonly);
991 totsize += write_debug_data1
992 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags,
993 "source_corr (flags)", dosizeonly);
995 totsize += write_debug_data2
996 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid,
997 "source_corr (fileid)", dosizeonly);
999 totsize += write_debug_data8
1000 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt,
1001 "source_corr (creation date)", dosizeonly);
1003 totsize += write_debug_data4
1004 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk,
1005 "source_corr (EOF block number)", dosizeonly);
1007 totsize += write_debug_data2
1008 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb,
1009 "source_corr (first free byte)", dosizeonly);
1011 totsize += write_debug_data1
1012 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo,
1013 "source_corr (record and file organization)", dosizeonly);
1015 totsize += write_debug_data1
1016 (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename,
1017 "source_corr (filename length)", dosizeonly);
1019 totsize += write_debug_string (remap_debug_filename (
1020 file_info_entry.file_name),
1021 "source file name", dosizeonly);
1022 totsize += write_debug_data1 (src_cmdtrlr.dst_b_src_df_libmodname,
1023 "source_corr (libmodname)", dosizeonly);
1025 src_command_sf.dst_b_src_command = DST_K_SRC_SETFILE;
1026 src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword = fileid;
1028 src_command_sr.dst_b_src_command = DST_K_SRC_SETREC_W;
1029 src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword = 1;
1031 src_command_sl.dst_b_src_command = DST_K_SRC_SETLNUM_L;
1032 src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong = linestart + 1;
1034 src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1036 if (linesleft > 65534)
1037 linesleft = linesleft - 65534, linestodo = 65534;
1038 else
1039 linestodo = linesleft, linesleft = 0;
1041 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1043 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1044 = DST_K_SOURCE_CORR_HEADER_SIZE + 3 + 3 + 5 + 3 - 1;
1045 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1046 = DST_K_SOURCE;
1048 if (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword)
1050 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1051 "source corr", dosizeonly);
1053 totsize += write_debug_data1 (src_command_sf.dst_b_src_command,
1054 "source_corr (src setfile)", dosizeonly);
1056 totsize += write_debug_data2
1057 (src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword,
1058 "source_corr (fileid)", dosizeonly);
1060 totsize += write_debug_data1 (src_command_sr.dst_b_src_command,
1061 "source_corr (setrec)", dosizeonly);
1063 totsize += write_debug_data2
1064 (src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword,
1065 "source_corr (recnum)", dosizeonly);
1067 totsize += write_debug_data1 (src_command_sl.dst_b_src_command,
1068 "source_corr (setlnum)", dosizeonly);
1070 totsize += write_debug_data4
1071 (src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong,
1072 "source_corr (linenum)", dosizeonly);
1074 totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1075 "source_corr (deflines)", dosizeonly);
1077 sprintf (buff, "source_corr (%d)",
1078 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1079 totsize += write_debug_data2
1080 (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
1081 buff, dosizeonly);
1083 while (linesleft > 0)
1085 src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1086 = DST_K_SOURCE_CORR_HEADER_SIZE + 3 - 1;
1087 src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1088 = DST_K_SOURCE;
1089 src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1091 if (linesleft > 65534)
1092 linesleft = linesleft - 65534, linestodo = 65534;
1093 else
1094 linestodo = linesleft, linesleft = 0;
1096 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1098 totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1099 "source corr", dosizeonly);
1100 totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1101 "source_corr (deflines)", dosizeonly);
1102 sprintf (buff, "source_corr (%d)",
1103 src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1104 totsize += write_debug_data2
1105 (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
1106 buff, dosizeonly);
1110 return totsize;
1113 /* Output all the source correlation entries and return the size. Just return
1114 the size if DOSIZEONLY is nonzero. */
1116 static int
1117 write_srccorrs (int dosizeonly)
1119 unsigned int i;
1120 int totsize = 0;
1122 for (i = 1; i < file_info_table_in_use; i++)
1123 totsize += write_srccorr (i, file_info_table[i], dosizeonly);
1125 return totsize;
1128 /* Output a marker (i.e. a label) for the beginning of a function, before
1129 the prologue. */
1131 static void
1132 vmsdbgout_begin_prologue (unsigned int line, const char *file)
1134 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1136 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1137 (*dwarf2_debug_hooks.begin_prologue) (line, file);
1139 if (debug_info_level > DINFO_LEVEL_NONE)
1141 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1142 current_function_funcdef_no);
1143 ASM_OUTPUT_LABEL (asm_out_file, label);
1147 /* Output a marker (i.e. a label) for the beginning of a function, after
1148 the prologue. */
1150 static void
1151 vmsdbgout_end_prologue (unsigned int line, const char *file)
1153 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1155 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1156 (*dwarf2_debug_hooks.end_prologue) (line, file);
1158 if (debug_info_level > DINFO_LEVEL_TERSE)
1160 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_PROLOG_LABEL,
1161 current_function_funcdef_no);
1162 ASM_OUTPUT_LABEL (asm_out_file, label);
1164 /* VMS PCA expects every PC range to correlate to some line and file. */
1165 vmsdbgout_source_line (line, file, 0, true);
1169 /* No output for VMS debug, but make obligatory call to Dwarf2 debug */
1171 static void
1172 vmsdbgout_end_function (unsigned int line)
1174 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1175 (*dwarf2_debug_hooks.end_function) (line);
1178 /* Output a marker (i.e. a label) for the beginning of the epilogue.
1179 This gets called *before* the epilogue code has been generated. */
1181 static void
1182 vmsdbgout_begin_epilogue (unsigned int line, const char *file)
1184 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1185 static int save_current_function_funcdef_no = -1;
1187 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1188 (*dwarf2_debug_hooks.begin_epilogue) (line, file);
1190 if (debug_info_level > DINFO_LEVEL_NONE)
1192 if (save_current_function_funcdef_no != current_function_funcdef_no)
1194 /* Output a label to mark the endpoint of the code generated for this
1195 function. */
1196 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_EPILOG_LABEL,
1197 current_function_funcdef_no);
1199 ASM_OUTPUT_LABEL (asm_out_file, label);
1201 save_current_function_funcdef_no = current_function_funcdef_no;
1203 /* VMS PCA expects every PC range to correlate to some line and
1204 file. */
1205 vmsdbgout_source_line (line, file, 0, true);
1210 /* Output a marker (i.e. a label) for the absolute end of the generated code
1211 for a function definition. This gets called *after* the epilogue code has
1212 been generated. */
1214 static void
1215 vmsdbgout_end_epilogue (unsigned int line, const char *file)
1217 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1219 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1220 (*dwarf2_debug_hooks.end_epilogue) (line, file);
1222 if (debug_info_level > DINFO_LEVEL_NONE)
1224 /* Output a label to mark the endpoint of the code generated for this
1225 function. */
1226 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1227 current_function_funcdef_no);
1228 ASM_OUTPUT_LABEL (asm_out_file, label);
1230 /* VMS PCA expects every PC range to correlate to some line and file. */
1231 vmsdbgout_source_line (line, file, 0, true);
1235 /* Output a marker (i.e. a label) for the beginning of the generated code for
1236 a lexical block. */
1238 static void
1239 vmsdbgout_begin_block (register unsigned line, register unsigned blocknum)
1241 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1242 (*dwarf2_debug_hooks.begin_block) (line, blocknum);
1244 if (debug_info_level > DINFO_LEVEL_TERSE)
1245 targetm.asm_out.internal_label (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
1248 /* Output a marker (i.e. a label) for the end of the generated code for a
1249 lexical block. */
1251 static void
1252 vmsdbgout_end_block (register unsigned line, register unsigned blocknum)
1254 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1255 (*dwarf2_debug_hooks.end_block) (line, blocknum);
1257 if (debug_info_level > DINFO_LEVEL_TERSE)
1258 targetm.asm_out.internal_label (asm_out_file, BLOCK_END_LABEL, blocknum);
1261 /* Not implemented in VMS Debug. */
1263 static bool
1264 vmsdbgout_ignore_block (const_tree block)
1266 bool retval = 0;
1268 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1269 retval = (*dwarf2_debug_hooks.ignore_block) (block);
1271 return retval;
1274 /* Add an entry for function DECL into the funcnam_table. */
1276 static void
1277 vmsdbgout_begin_function (tree decl)
1279 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1281 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1282 (*dwarf2_debug_hooks.begin_function) (decl);
1284 /* Add the new entry to the end of the function name table. */
1285 VEC_safe_push (char_p, heap, funcnam_table, xstrdup (name));
1286 VEC_safe_push (unsigned, heap, funcnum_table,
1287 current_function_funcdef_no);
1290 static char fullname_buff [4096];
1292 /* Return the full file specification for FILENAME. The specification must be
1293 in VMS syntax in order to be processed by VMS Debug. */
1295 static char *
1296 full_name (const char *filename)
1298 #ifdef VMS
1299 FILE *fp = fopen (filename, "r");
1301 fgetname (fp, fullname_buff, 1);
1302 fclose (fp);
1303 #else
1304 /* Unix paths really mess up VMS debug. Better to just output the
1305 base filename. */
1306 strcpy (fullname_buff, filename);
1307 #endif
1309 return fullname_buff;
1312 /* Lookup a filename (in the list of filenames that we know about here in
1313 vmsdbgout.c) and return its "index". The index of each (known) filename is
1314 just a unique number which is associated with only that one filename. We
1315 need such numbers for the sake of generating labels and references
1316 to those files numbers. If the filename given as an argument is not
1317 found in our current list, add it to the list and assign it the next
1318 available unique index number. In order to speed up searches, we remember
1319 the index of the filename was looked up last. This handles the majority of
1320 all searches. */
1322 static unsigned int
1323 lookup_filename (const char *file_name)
1325 static unsigned int last_file_lookup_index = 0;
1326 register char *fn;
1327 register unsigned i;
1328 const char *fnam;
1329 long long cdt = 0;
1330 long ebk = 0;
1331 short ffb = 0;
1332 char rfo = 0;
1333 long siz = 0;
1334 int ver = 0;
1336 fnam = full_name (file_name);
1338 /* Check to see if the file name that was searched on the previous call
1339 matches this file name. If so, return the index. */
1340 if (last_file_lookup_index != 0)
1342 fn = file_info_table[last_file_lookup_index].file_name;
1343 if (strcmp (fnam, fn) == 0)
1344 return last_file_lookup_index;
1347 /* Didn't match the previous lookup, search the table */
1348 for (i = 1; i < file_info_table_in_use; ++i)
1350 fn = file_info_table[i].file_name;
1351 if (strcmp (fnam, fn) == 0)
1353 last_file_lookup_index = i;
1354 return i;
1358 /* Prepare to add a new table entry by making sure there is enough space in
1359 the table to do so. If not, expand the current table. */
1360 if (file_info_table_in_use == file_info_table_allocated)
1363 file_info_table_allocated += FILE_TABLE_INCREMENT;
1364 file_info_table = XRESIZEVEC (dst_file_info_entry, file_info_table,
1365 file_info_table_allocated);
1368 if (vms_file_stats_name (file_name, &cdt, &siz, &rfo, &ver) == 0)
1370 ebk = siz / 512 + 1;
1371 ffb = siz - ((siz / 512) * 512);
1374 /* Add the new entry to the end of the filename table. */
1375 file_info_table[file_info_table_in_use].file_name = xstrdup (fnam);
1376 file_info_table[file_info_table_in_use].max_line = 0;
1377 file_info_table[file_info_table_in_use].cdt = cdt;
1378 file_info_table[file_info_table_in_use].ebk = ebk;
1379 file_info_table[file_info_table_in_use].ffb = ffb;
1380 file_info_table[file_info_table_in_use].rfo = rfo;
1382 last_file_lookup_index = file_info_table_in_use++;
1383 return last_file_lookup_index;
1386 /* Output a label to mark the beginning of a source code line entry
1387 and record information relating to this source line, in
1388 'line_info_table' for later output of the .debug_line section. */
1390 static void
1391 vmsdbgout_source_line (register unsigned line, register const char *filename,
1392 int discriminator, bool is_stmt)
1394 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1395 (*dwarf2_debug_hooks.source_line) (line, filename, discriminator, is_stmt);
1397 if (debug_info_level >= DINFO_LEVEL_TERSE)
1399 dst_line_info_ref line_info;
1401 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
1402 line_info_table_in_use);
1404 /* Expand the line info table if necessary. */
1405 if (line_info_table_in_use == line_info_table_allocated)
1407 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
1408 line_info_table = XRESIZEVEC (dst_line_info_entry, line_info_table,
1409 line_info_table_allocated);
1412 /* Add the new entry at the end of the line_info_table. */
1413 line_info = &line_info_table[line_info_table_in_use++];
1414 line_info->dst_file_num = lookup_filename (filename);
1415 line_info->dst_line_num = line;
1416 if (line > file_info_table[line_info->dst_file_num].max_line)
1417 file_info_table[line_info->dst_file_num].max_line = line;
1421 /* Record the beginning of a new source file, for later output.
1422 At present, unimplemented. */
1424 static void
1425 vmsdbgout_start_source_file (unsigned int lineno, const char *filename)
1427 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1428 (*dwarf2_debug_hooks.start_source_file) (lineno, filename);
1431 /* Record the end of a source file, for later output.
1432 At present, unimplemented. */
1434 static void
1435 vmsdbgout_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
1437 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1438 (*dwarf2_debug_hooks.end_source_file) (lineno);
1441 /* Set up for Debug output at the start of compilation. */
1443 static void
1444 vmsdbgout_init (const char *filename)
1446 const char *language_string = lang_hooks.name;
1448 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1449 (*dwarf2_debug_hooks.init) (filename);
1451 if (debug_info_level == DINFO_LEVEL_NONE)
1452 return;
1454 /* Remember the name of the primary input file. */
1455 primary_filename = filename;
1457 /* Allocate the initial hunk of the file_info_table. */
1458 file_info_table = XCNEWVEC (dst_file_info_entry, FILE_TABLE_INCREMENT);
1459 file_info_table_allocated = FILE_TABLE_INCREMENT;
1460 /* Skip the first entry - file numbers begin at 1. */
1461 file_info_table_in_use = 1;
1463 funcnam_table = VEC_alloc (char_p, heap, FUNC_TABLE_INITIAL);
1464 funcnum_table = VEC_alloc (unsigned, heap, FUNC_TABLE_INITIAL);
1466 /* Allocate the initial hunk of the line_info_table. */
1467 line_info_table = XCNEWVEC (dst_line_info_entry, LINE_INFO_TABLE_INCREMENT);
1468 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
1469 /* zero-th entry is allocated, but unused */
1470 line_info_table_in_use = 1;
1472 lookup_filename (primary_filename);
1474 if (!strcmp (language_string, "GNU C"))
1475 module_language = DST_K_C;
1476 else if (!strcmp (language_string, "GNU C++"))
1477 module_language = DST_K_CXX;
1478 else if (!strcmp (language_string, "GNU Ada"))
1479 module_language = DST_K_ADA;
1480 else if (!strcmp (language_string, "GNU F77"))
1481 module_language = DST_K_FORTRAN;
1482 else
1483 module_language = DST_K_UNKNOWN;
1485 module_producer = concat (language_string, " ", version_string, NULL);
1487 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
1491 /* Not implemented in VMS Debug. */
1493 static void
1494 vmsdbgout_assembly_start (void)
1496 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1497 (*dwarf2_debug_hooks.assembly_start) ();
1500 /* Not implemented in VMS Debug. */
1502 static void
1503 vmsdbgout_define (unsigned int lineno, const char *buffer)
1505 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1506 (*dwarf2_debug_hooks.define) (lineno, buffer);
1509 /* Not implemented in VMS Debug. */
1511 static void
1512 vmsdbgout_undef (unsigned int lineno, const char *buffer)
1514 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1515 (*dwarf2_debug_hooks.undef) (lineno, buffer);
1518 /* Not implemented in VMS Debug. */
1520 static void
1521 vmsdbgout_decl (tree decl)
1523 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1524 (*dwarf2_debug_hooks.function_decl) (decl);
1527 /* Not implemented in VMS Debug. */
1529 static void
1530 vmsdbgout_global_decl (tree decl)
1532 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1533 (*dwarf2_debug_hooks.global_decl) (decl);
1536 /* Not implemented in VMS Debug. */
1538 static void
1539 vmsdbgout_type_decl (tree decl, int local)
1541 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1542 (*dwarf2_debug_hooks.type_decl) (decl, local);
1545 /* Not implemented in VMS Debug. */
1547 static void
1548 vmsdbgout_abstract_function (tree decl)
1550 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1551 (*dwarf2_debug_hooks.outlining_inline_function) (decl);
1554 /* Output stuff that Debug requires at the end of every file and generate the
1555 VMS Debug debugging info. */
1557 static void
1558 vmsdbgout_finish (const char *filename ATTRIBUTE_UNUSED)
1560 unsigned int i, ifunc;
1561 int totsize;
1563 if (write_symbols == VMS_AND_DWARF2_DEBUG)
1564 (*dwarf2_debug_hooks.finish) (filename);
1566 if (debug_info_level == DINFO_LEVEL_NONE)
1567 return;
1569 /* Output a terminator label for the .text section. */
1570 switch_to_section (text_section);
1571 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
1573 /* Output debugging information.
1574 Warning! Do not change the name of the .vmsdebug section without
1575 changing it in the assembler also. */
1576 switch_to_section (get_named_section (NULL, ".vmsdebug", 0));
1577 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1579 totsize = write_modbeg (1);
1580 FOR_EACH_VEC_ELT (unsigned, funcnum_table, i, ifunc)
1582 totsize += write_rtnbeg (i, 1);
1583 totsize += write_rtnend (i, 1);
1585 totsize += write_pclines (1);
1587 write_modbeg (0);
1588 FOR_EACH_VEC_ELT (unsigned, funcnum_table, i, ifunc)
1590 write_rtnbeg (i, 0);
1591 write_rtnend (i, 0);
1593 write_pclines (0);
1595 if (debug_info_level > DINFO_LEVEL_TERSE)
1597 totsize = write_srccorrs (1);
1598 write_srccorrs (0);
1601 totsize = write_modend (1);
1602 write_modend (0);
1605 /* Need for both Dwarf2 on IVMS and VMS Debug on AVMS */
1607 #ifdef VMS
1608 #define __NEW_STARLET 1
1609 #include <vms/rms.h>
1610 #include <vms/atrdef.h>
1611 #include <vms/fibdef.h>
1612 #include <vms/stsdef.h>
1613 #include <vms/iodef.h>
1614 #include <vms/fatdef.h>
1615 #include <vms/descrip.h>
1616 #include <unixlib.h>
1618 #define MAXPATH 256
1620 /* descrip.h doesn't have everything ... */
1621 typedef struct fibdef* __fibdef_ptr32 __attribute__ (( mode (SI) ));
1622 struct dsc$descriptor_fib
1624 unsigned int fib$l_len;
1625 __fibdef_ptr32 fib$l_addr;
1628 /* I/O Status Block. */
1629 struct IOSB
1631 unsigned short status, count;
1632 unsigned int devdep;
1635 static char *tryfile;
1637 /* Variable length string. */
1638 struct vstring
1640 short length;
1641 char string[NAM$C_MAXRSS+1];
1644 static char filename_buff [MAXPATH];
1645 static char vms_filespec [MAXPATH];
1647 /* Callback function for filespec style conversion. */
1649 static int
1650 translate_unix (char *name, int type ATTRIBUTE_UNUSED)
1652 strncpy (filename_buff, name, MAXPATH);
1653 filename_buff [MAXPATH - 1] = (char) 0;
1654 return 0;
1657 /* Wrapper for DECC function that converts a Unix filespec
1658 to VMS style filespec. */
1660 static char *
1661 to_vms_file_spec (char *filespec)
1663 strncpy (vms_filespec, "", MAXPATH);
1664 decc$to_vms (filespec, translate_unix, 1, 1);
1665 strncpy (vms_filespec, filename_buff, MAXPATH);
1667 vms_filespec [MAXPATH - 1] = (char) 0;
1669 return vms_filespec;
1672 #else
1673 #define VMS_EPOCH_OFFSET 35067168000000000
1674 #define VMS_GRANULARITY_FACTOR 10000000
1675 #endif
1677 /* Return VMS file date, size, format, version given a name. */
1680 vms_file_stats_name (const char *filename, long long *cdt, long *siz, char *rfo,
1681 int *ver)
1683 #ifdef VMS
1684 struct FAB fab;
1685 struct NAM nam;
1687 unsigned long long create;
1688 FAT recattr;
1689 char ascnamebuff [256];
1691 ATRDEF atrlst[]
1693 { ATR$S_CREDATE, ATR$C_CREDATE, &create },
1694 { ATR$S_RECATTR, ATR$C_RECATTR, &recattr },
1695 { ATR$S_ASCNAME, ATR$C_ASCNAME, &ascnamebuff },
1696 { 0, 0, 0}
1699 FIBDEF fib;
1700 struct dsc$descriptor_fib fibdsc = {sizeof (fib), (void *) &fib};
1702 struct IOSB iosb;
1704 long status;
1705 unsigned short chan;
1707 struct vstring file;
1708 struct dsc$descriptor_s filedsc
1709 = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) file.string};
1710 struct vstring device;
1711 struct dsc$descriptor_s devicedsc
1712 = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) device.string};
1713 struct vstring result;
1714 struct dsc$descriptor_s resultdsc
1715 = {NAM$C_MAXRSS, DSC$K_DTYPE_VT, DSC$K_CLASS_VS, (void *) result.string};
1717 if (strcmp (filename, "<internal>") == 0
1718 || strcmp (filename, "<built-in>") == 0)
1720 if (cdt)
1721 *cdt = 0;
1723 if (siz)
1724 *siz = 0;
1726 if (rfo)
1727 *rfo = 0;
1729 if (ver)
1730 *ver = 0;
1732 return 0;
1735 tryfile = to_vms_file_spec (filename);
1737 /* Allocate and initialize a FAB and NAM structures. */
1738 fab = cc$rms_fab;
1739 nam = cc$rms_nam;
1741 nam.nam$l_esa = file.string;
1742 nam.nam$b_ess = NAM$C_MAXRSS;
1743 nam.nam$l_rsa = result.string;
1744 nam.nam$b_rss = NAM$C_MAXRSS;
1745 fab.fab$l_fna = tryfile;
1746 fab.fab$b_fns = strlen (tryfile);
1747 fab.fab$l_nam = &nam;
1749 /* Validate filespec syntax and device existence. */
1750 status = SYS$PARSE (&fab, 0, 0);
1751 if ((status & 1) != 1)
1752 return 1;
1754 file.string[nam.nam$b_esl] = 0;
1756 /* Find matching filespec. */
1757 status = SYS$SEARCH (&fab, 0, 0);
1758 if ((status & 1) != 1)
1759 return 1;
1761 file.string[nam.nam$b_esl] = 0;
1762 result.string[result.length=nam.nam$b_rsl] = 0;
1764 /* Get the device name and assign an IO channel. */
1765 strncpy (device.string, nam.nam$l_dev, nam.nam$b_dev);
1766 devicedsc.dsc$w_length = nam.nam$b_dev;
1767 chan = 0;
1768 status = SYS$ASSIGN (&devicedsc, &chan, 0, 0, 0);
1769 if ((status & 1) != 1)
1770 return 1;
1772 /* Initialize the FIB and fill in the directory id field. */
1773 memset (&fib, 0, sizeof (fib));
1774 fib.fib$w_did[0] = nam.nam$w_did[0];
1775 fib.fib$w_did[1] = nam.nam$w_did[1];
1776 fib.fib$w_did[2] = nam.nam$w_did[2];
1777 fib.fib$l_acctl = 0;
1778 fib.fib$l_wcc = 0;
1779 strcpy (file.string, (strrchr (result.string, ']') + 1));
1780 filedsc.dsc$w_length = strlen (file.string);
1781 result.string[result.length = 0] = 0;
1783 /* Open and close the file to fill in the attributes. */
1784 status
1785 = SYS$QIOW (0, chan, IO$_ACCESS|IO$M_ACCESS, &iosb, 0, 0,
1786 &fibdsc, &filedsc, &result.length, &resultdsc, &atrlst, 0);
1787 if ((status & 1) != 1)
1788 return 1;
1789 if ((iosb.status & 1) != 1)
1790 return 1;
1792 result.string[result.length] = 0;
1793 status = SYS$QIOW (0, chan, IO$_DEACCESS, &iosb, 0, 0, &fibdsc, 0, 0, 0,
1794 &atrlst, 0);
1795 if ((status & 1) != 1)
1796 return 1;
1797 if ((iosb.status & 1) != 1)
1798 return 1;
1800 /* Deassign the channel and exit. */
1801 status = SYS$DASSGN (chan);
1802 if ((status & 1) != 1)
1803 return 1;
1805 if (cdt) *cdt = create;
1806 if (siz) *siz = (512 * 65536 * recattr.fat$w_efblkh) +
1807 (512 * (recattr.fat$w_efblkl - 1)) +
1808 recattr.fat$w_ffbyte;
1809 if (rfo) *rfo = recattr.fat$v_rtype;
1810 if (ver) *ver = strtol (strrchr (ascnamebuff, ';')+1, 0, 10);
1812 return 0;
1813 #else
1814 struct stat buff;
1816 if ((stat (filename, &buff)) != 0)
1817 return 1;
1819 if (cdt)
1820 *cdt = (long long) (buff.st_mtime * VMS_GRANULARITY_FACTOR)
1821 + VMS_EPOCH_OFFSET;
1823 if (siz)
1824 *siz = buff.st_size;
1826 if (rfo)
1827 *rfo = 2; /* Stream LF format */
1829 if (ver)
1830 *ver = 1;
1832 return 0;
1833 #endif
1835 #endif