OSDN Git Service

* doc/include/gcc-common.texi (version-GCC): Increase to 3.3.
[pf3gnuchains/gcc-fork.git] / gcc / vmsdbgout.c
1 /* Output VMS debug format symbol table information from the GNU C compiler.
2    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4    Contributed by Douglas B. Rupp (rupp@gnat.com).
5
6 This file is part of GNU CC.
7
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 2, or (at your option) any later
11 version.
12
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.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING.  If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA.  */
22
23 #include "config.h"
24
25 #ifdef VMS_DEBUGGING_INFO
26 #include "system.h"
27 #include "tree.h"
28 #include "flags.h"
29 #include "rtl.h"
30 #include "output.h"
31 #include "vmsdbg.h"
32 #include "debug.h"
33 #include "langhooks.h"
34 #include "function.h"
35
36 /* Difference in seconds between the VMS Epoch and the Unix Epoch */
37 static const long long vms_epoch_offset = 3506716800ll;
38
39 /* NOTE: In the comments in this file, many references are made to "Debug
40    Symbol Table".  This term is abbreviated as `DST' throughout the remainder
41    of this file.  */
42
43 typedef struct dst_line_info_struct *dst_line_info_ref;
44
45 /* Each entry in the line_info_table maintains the file and
46    line number associated with the label generated for that
47    entry.  The label gives the PC value associated with
48    the line number entry.  */
49 typedef struct dst_line_info_struct
50 {
51   unsigned long dst_file_num;
52   unsigned long dst_line_num;
53 }
54 dst_line_info_entry;
55
56 typedef struct dst_file_info_struct *dst_file_info_ref;
57
58 typedef struct dst_file_info_struct
59 {
60   char *file_name;
61   unsigned int max_line;
62   unsigned int listing_line_start;
63   long long cdt;
64   long ebk;
65   short ffb;
66   char rfo;
67   char flen;
68 }
69 dst_file_info_entry;
70
71 /* How to start an assembler comment.  */
72 #ifndef ASM_COMMENT_START
73 #define ASM_COMMENT_START ";#"
74 #endif
75
76 /* Maximum size (in bytes) of an artificially generated label.  */
77 #define MAX_ARTIFICIAL_LABEL_BYTES      30
78
79 /* Make sure we know the sizes of the various types debug can describe. These
80    are only defaults.  If the sizes are different for your target, you should
81    override these values by defining the appropriate symbols in your tm.h
82    file.  */
83 #ifndef PTR_SIZE
84 #define PTR_SIZE 4 /* Must be 32 bits for VMS debug info */
85 #endif
86
87 /* Pointer to an structure of filenames referenced by this compilation unit.  */
88 static dst_file_info_ref file_info_table;
89
90 /* Total number of entries in the table (i.e. array) pointed to by
91    `file_info_table'.  This is the *total* and includes both used and unused
92    slots.  */
93 static unsigned int file_info_table_allocated;
94
95 /* Number of entries in the file_info_table which are actually in use.  */
96 static unsigned int file_info_table_in_use;
97
98 /* Size (in elements) of increments by which we may expand the filename
99    table.  */
100 #define FILE_TABLE_INCREMENT 64
101
102 static char **func_table;
103 static unsigned int func_table_allocated;
104 static unsigned int func_table_in_use;
105 #define FUNC_TABLE_INCREMENT 256
106
107 /* Local pointer to the name of the main input file.  Initialized in
108    avmdbgout_init.  */
109 static const char *primary_filename;
110
111 static char *module_producer;
112 static unsigned int module_language;
113
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;
117
118 /* Number of elements currently allocated for line_info_table.  */
119 static unsigned int line_info_table_allocated;
120
121 /* Number of elements in line_info_table currently in use.  */
122 static unsigned int line_info_table_in_use;
123
124 /* Size (in elements) of increments by which we may expand line_info_table.  */
125 #define LINE_INFO_TABLE_INCREMENT 1024
126
127 /* Forward declarations for functions defined in this file.  */
128 static char *full_name          PARAMS ((const char *));
129 static unsigned int lookup_filename PARAMS ((const char *));
130 static void addr_const_to_string PARAMS ((char *, rtx));
131 static int write_debug_header   PARAMS ((DST_HEADER *, const char *, int));
132 static int write_debug_addr     PARAMS ((char *, const char *, int));
133 static int write_debug_data1    PARAMS ((unsigned int, const char *, int));
134 static int write_debug_data2    PARAMS ((unsigned int, const char *, int));
135 static int write_debug_data4    PARAMS ((unsigned long, const char *, int));
136 static int write_debug_data8    PARAMS ((unsigned long long, const char *,
137                                          int));
138 static int write_debug_delta4   PARAMS ((char *, char *, const char *, int));
139 static int write_debug_string   PARAMS ((char *, const char *, int));
140 static int write_modbeg         PARAMS ((int));
141 static int write_modend         PARAMS ((int));
142 static int write_rtnbeg         PARAMS ((int, int));
143 static int write_rtnend         PARAMS ((int, int));
144 static int write_pclines        PARAMS ((int));
145 static int write_srccorr        PARAMS ((int, dst_file_info_entry, int));
146 static int write_srccorrs       PARAMS ((int));
147
148 static void vmsdbgout_init              PARAMS ((const char *));
149 static void vmsdbgout_finish            PARAMS ((const char *));
150 static void vmsdbgout_define            PARAMS ((unsigned int, const char *));
151 static void vmsdbgout_undef             PARAMS ((unsigned int, const char *));
152 static void vmsdbgout_start_source_file PARAMS ((unsigned int, const char *));
153 static void vmsdbgout_end_source_file   PARAMS ((unsigned int));
154 static void vmsdbgout_begin_block       PARAMS ((unsigned int, unsigned int));
155 static void vmsdbgout_end_block         PARAMS ((unsigned int, unsigned int));
156 static bool vmsdbgout_ignore_block      PARAMS ((tree));
157 static void vmsdbgout_source_line       PARAMS ((unsigned int, const char *));
158 static void vmsdbgout_begin_prologue    PARAMS ((unsigned int, const char *));
159 static void vmsdbgout_end_epilogue      PARAMS ((void));
160 static void vmsdbgout_begin_function    PARAMS ((tree));
161 static void vmsdbgout_decl              PARAMS ((tree));
162 static void vmsdbgout_global_decl       PARAMS ((tree));
163 static void vmsdbgout_abstract_function PARAMS ((tree));
164
165 /* The debug hooks structure.  */
166
167 const struct gcc_debug_hooks vmsdbg_debug_hooks
168 = {vmsdbgout_init,
169    vmsdbgout_finish,
170    vmsdbgout_define,
171    vmsdbgout_undef,
172    vmsdbgout_start_source_file,
173    vmsdbgout_end_source_file,
174    vmsdbgout_begin_block,
175    vmsdbgout_end_block,
176    vmsdbgout_ignore_block,
177    vmsdbgout_source_line,
178    vmsdbgout_begin_prologue,
179    debug_nothing_int,           /* end_prologue */
180    vmsdbgout_end_epilogue,      /* end_epilogue */
181    vmsdbgout_begin_function,    /* begin_function */
182    debug_nothing_int,           /* end_function */
183    vmsdbgout_decl,
184    vmsdbgout_global_decl,
185    debug_nothing_tree,          /* deferred_inline_function */
186    vmsdbgout_abstract_function,
187    debug_nothing_rtx            /* label */
188 };
189
190 /* Definitions of defaults for assembler-dependent names of various
191    pseudo-ops and section names.
192    Theses may be overridden in the tm.h file (if necessary) for a particular
193    assembler.  */
194 #ifdef UNALIGNED_SHORT_ASM_OP
195 #undef UNALIGNED_SHORT_ASM_OP
196 #endif
197 #define UNALIGNED_SHORT_ASM_OP  ".word"
198
199 #ifdef UNALIGNED_INT_ASM_OP
200 #undef UNALIGNED_INT_ASM_OP
201 #endif
202 #define UNALIGNED_INT_ASM_OP    ".long"
203
204 #ifdef UNALIGNED_LONG_ASM_OP
205 #undef UNALIGNED_LONG_ASM_OP
206 #endif
207 #define UNALIGNED_LONG_ASM_OP   ".long"
208
209 #ifdef UNALIGNED_DOUBLE_INT_ASM_OP
210 #undef UNALIGNED_DOUBLE_INT_ASM_OP
211 #endif
212 #define UNALIGNED_DOUBLE_INT_ASM_OP     ".quad"
213
214 #ifdef ASM_BYTE_OP
215 #undef ASM_BYTE_OP
216 #endif
217 #define ASM_BYTE_OP     ".byte"
218
219 #define NUMBYTES(I) ((I) < 256 ? 1 : (I) < 65536 ? 2 : 4)
220
221 #define NUMBYTES0(I) ((I) < 128 ? 0 : (I) < 65536 ? 2 : 4)
222
223 #ifndef UNALIGNED_PTR_ASM_OP
224 #define UNALIGNED_PTR_ASM_OP \
225   (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
226 #endif
227
228 #ifndef UNALIGNED_OFFSET_ASM_OP
229 #define UNALIGNED_OFFSET_ASM_OP(OFFSET) \
230   (NUMBYTES(OFFSET) == 4 \
231    ? UNALIGNED_LONG_ASM_OP \
232    : (NUMBYTES(OFFSET) == 2 ? UNALIGNED_SHORT_ASM_OP : ASM_BYTE_OP))
233 #endif
234
235 /* Definitions of defaults for formats and names of various special
236    (artificial) labels which may be generated within this file (when the -g
237    options is used and VMS_DEBUGGING_INFO is in effect.  If necessary, these
238    may be overridden from within the tm.h file, but typically, overriding these
239    defaults is unnecessary.  */
240
241 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
242
243 #ifndef TEXT_END_LABEL
244 #define TEXT_END_LABEL          "Lvetext"
245 #endif
246 #ifndef FUNC_BEGIN_LABEL
247 #define FUNC_BEGIN_LABEL        "LVFB"
248 #endif
249 #ifndef FUNC_PROLOG_LABEL
250 #define FUNC_PROLOG_LABEL       "LVFP"
251 #endif
252 #ifndef FUNC_END_LABEL
253 #define FUNC_END_LABEL          "LVFE"
254 #endif
255 #ifndef BLOCK_BEGIN_LABEL
256 #define BLOCK_BEGIN_LABEL       "LVBB"
257 #endif
258 #ifndef BLOCK_END_LABEL
259 #define BLOCK_END_LABEL         "LVBE"
260 #endif
261 #ifndef LINE_CODE_LABEL
262 #define LINE_CODE_LABEL         "LVM"
263 #endif
264
265 #ifndef ASM_OUTPUT_DEBUG_DELTA2
266 #define ASM_OUTPUT_DEBUG_DELTA2(FILE,LABEL1,LABEL2)                      \
267   do                                                                     \
268     {                                                                    \
269       fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP);                \
270       assemble_name (FILE, LABEL1);                                      \
271       fprintf (FILE, "-");                                               \
272       assemble_name (FILE, LABEL2);                                      \
273     }                                                                    \
274   while (0)
275 #endif
276
277 #ifndef ASM_OUTPUT_DEBUG_DELTA4
278 #define ASM_OUTPUT_DEBUG_DELTA4(FILE,LABEL1,LABEL2)                      \
279   do                                                                     \
280     {                                                                    \
281       fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);                  \
282       assemble_name (FILE, LABEL1);                                      \
283       fprintf (FILE, "-");                                               \
284       assemble_name (FILE, LABEL2);                                      \
285     }                                                                    \
286   while (0)
287 #endif
288
289 #ifndef ASM_OUTPUT_DEBUG_ADDR_DELTA
290 #define ASM_OUTPUT_DEBUG_ADDR_DELTA(FILE,LABEL1,LABEL2)                  \
291   do                                                                     \
292     {                                                                    \
293       fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP);                  \
294       assemble_name (FILE, LABEL1);                                      \
295       fprintf (FILE, "-");                                               \
296       assemble_name (FILE, LABEL2);                                      \
297     }                                                                    \
298   while (0)
299 #endif
300
301 #ifndef ASM_OUTPUT_DEBUG_ADDR
302 #define ASM_OUTPUT_DEBUG_ADDR(FILE,LABEL)                                \
303   do                                                                     \
304     {                                                                    \
305       fprintf ((FILE), "\t%s\t", UNALIGNED_PTR_ASM_OP);                  \
306       assemble_name (FILE, LABEL);                                       \
307     }                                                                    \
308   while (0)
309 #endif
310
311 #ifndef ASM_OUTPUT_DEBUG_ADDR_CONST
312 #define ASM_OUTPUT_DEBUG_ADDR_CONST(FILE,ADDR)                          \
313   fprintf ((FILE), "\t%s\t%s", UNALIGNED_PTR_ASM_OP, (ADDR))
314 #endif
315
316 #ifndef ASM_OUTPUT_DEBUG_DATA1
317 #define ASM_OUTPUT_DEBUG_DATA1(FILE,VALUE) \
318   fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned char) VALUE)
319 #endif
320
321 #ifndef ASM_OUTPUT_DEBUG_DATA2
322 #define ASM_OUTPUT_DEBUG_DATA2(FILE,VALUE) \
323   fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, \
324            (unsigned short) VALUE)
325 #endif
326
327 #ifndef ASM_OUTPUT_DEBUG_DATA4
328 #define ASM_OUTPUT_DEBUG_DATA4(FILE,VALUE) \
329   fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (unsigned long) VALUE)
330 #endif
331
332 #ifndef ASM_OUTPUT_DEBUG_DATA
333 #define ASM_OUTPUT_DEBUG_DATA(FILE,VALUE) \
334   fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP(VALUE), VALUE)
335 #endif
336
337 #ifndef ASM_OUTPUT_DEBUG_ADDR_DATA
338 #define ASM_OUTPUT_DEBUG_ADDR_DATA(FILE,VALUE) \
339   fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_PTR_ASM_OP, \
340            (unsigned long) VALUE)
341 #endif
342
343 #ifndef ASM_OUTPUT_DEBUG_DATA8
344 #define ASM_OUTPUT_DEBUG_DATA8(FILE,VALUE) \
345   fprintf ((FILE), "\t%s\t0x%llx", UNALIGNED_DOUBLE_INT_ASM_OP, \
346                                  (unsigned long long) VALUE)
347 #endif
348
349 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
350    newline is produced.  When flag_verbose_asm is asserted, we add commnetary
351    at the end of the line, so we must avoid output of a newline here.  */
352 #ifndef ASM_OUTPUT_DEBUG_STRING
353 #define ASM_OUTPUT_DEBUG_STRING(FILE,P)         \
354   do                                            \
355     {                                           \
356       register int slen = strlen(P);            \
357       register char *p = (P);                   \
358       register int i;                           \
359       fprintf (FILE, "\t.ascii \"");            \
360       for (i = 0; i < slen; i++)                \
361         {                                       \
362           register int c = p[i];                \
363           if (c == '\"' || c == '\\')           \
364             putc ('\\', FILE);                  \
365           if (c >= ' ' && c < 0177)             \
366             putc (c, FILE);                     \
367           else                                  \
368             fprintf (FILE, "\\%o", c);          \
369         }                                       \
370       fprintf (FILE, "\"");                     \
371     }                                           \
372   while (0)
373 #endif
374
375 /* Convert a reference to the assembler name of a C-level name.  This
376    macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
377    a string rather than writing to a file.  */
378 #ifndef ASM_NAME_TO_STRING
379 #define ASM_NAME_TO_STRING(STR, NAME)           \
380   do                                            \
381     {                                           \
382       if ((NAME)[0] == '*')                     \
383         strcpy (STR, NAME+1);                   \
384       else                                      \
385         strcpy (STR, NAME);                     \
386     }                                           \
387   while (0)
388 #endif
389
390 \f
391 /* General utility functions.  */
392
393 /* Convert an integer constant expression into assembler syntax.  Addition and
394    subtraction are the only arithmetic that may appear in these expressions.
395    This is an adaptation of output_addr_const in final.c.  Here, the target
396    of the conversion is a string buffer.  We can't use output_addr_const
397    directly, because it writes to a file.  */
398
399 static void
400 addr_const_to_string (str, x)
401      char *str;
402      rtx x;
403 {
404   char buf1[256];
405   char buf2[256];
406
407 restart:
408   str[0] = '\0';
409   switch (GET_CODE (x))
410     {
411     case PC:
412       if (flag_pic)
413         strcat (str, ",");
414       else
415         abort ();
416       break;
417
418     case SYMBOL_REF:
419       ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
420       strcat (str, buf1);
421       break;
422
423     case LABEL_REF:
424       ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
425       ASM_NAME_TO_STRING (buf2, buf1);
426       strcat (str, buf2);
427       break;
428
429     case CODE_LABEL:
430       ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
431       ASM_NAME_TO_STRING (buf2, buf1);
432       strcat (str, buf2);
433       break;
434
435     case CONST_INT:
436       sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
437       strcat (str, buf1);
438       break;
439
440     case CONST:
441       /* This used to output parentheses around the expression, but that does
442          not work on the 386 (either ATT or BSD assembler).  */
443       addr_const_to_string (buf1, XEXP (x, 0));
444       strcat (str, buf1);
445       break;
446
447     case CONST_DOUBLE:
448       if (GET_MODE (x) == VOIDmode)
449         {
450           /* We can use %d if the number is one word and positive.  */
451           if (CONST_DOUBLE_HIGH (x))
452             sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
453                      CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
454           else if (CONST_DOUBLE_LOW (x) < 0)
455             sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
456           else
457             sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
458                      CONST_DOUBLE_LOW (x));
459           strcat (str, buf1);
460         }
461       else
462         /* We can't handle floating point constants; PRINT_OPERAND must
463            handle them.  */
464         output_operand_lossage ("floating constant misused");
465       break;
466
467     case PLUS:
468       /* Some assemblers need integer constants to appear last (eg masm).  */
469       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
470         {
471           addr_const_to_string (buf1, XEXP (x, 1));
472           strcat (str, buf1);
473           if (INTVAL (XEXP (x, 0)) >= 0)
474             strcat (str, "+");
475           addr_const_to_string (buf1, XEXP (x, 0));
476           strcat (str, buf1);
477         }
478       else
479         {
480           addr_const_to_string (buf1, XEXP (x, 0));
481           strcat (str, buf1);
482           if (INTVAL (XEXP (x, 1)) >= 0)
483             strcat (str, "+");
484           addr_const_to_string (buf1, XEXP (x, 1));
485           strcat (str, buf1);
486         }
487       break;
488
489     case MINUS:
490       /* Avoid outputting things like x-x or x+5-x, since some assemblers
491          can't handle that.  */
492       x = simplify_subtraction (x);
493       if (GET_CODE (x) != MINUS)
494         goto restart;
495
496       addr_const_to_string (buf1, XEXP (x, 0));
497       strcat (str, buf1);
498       strcat (str, "-");
499       if (GET_CODE (XEXP (x, 1)) == CONST_INT
500           && INTVAL (XEXP (x, 1)) < 0)
501         {
502           strcat (str, "(");
503           addr_const_to_string (buf1, XEXP (x, 1));
504           strcat (str, buf1);
505           strcat (str, ")");
506         }
507       else
508         {
509           addr_const_to_string (buf1, XEXP (x, 1));
510           strcat (str, buf1);
511         }
512       break;
513
514     case ZERO_EXTEND:
515     case SIGN_EXTEND:
516       addr_const_to_string (buf1, XEXP (x, 0));
517       strcat (str, buf1);
518       break;
519
520     default:
521       output_operand_lossage ("invalid expression as operand");
522     }
523 }
524
525 /* Output the debug header HEADER.  Also output COMMENT if flag_verbose_asm is
526    set.  Return the header size.  Just return the size if DOSIZEONLY is
527    non-zero.  */
528
529 static int
530 write_debug_header (header, comment, dosizeonly)
531      DST_HEADER *header;
532      const char *comment;
533      int dosizeonly;
534 {
535   if (!dosizeonly)
536     {
537       ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
538                               header->dst__header_length.dst_w_length);
539
540       if (flag_verbose_asm)
541         fprintf (asm_out_file, "\t%s record length", ASM_COMMENT_START);
542       fputc ('\n', asm_out_file);
543
544       ASM_OUTPUT_DEBUG_DATA2 (asm_out_file,
545                               header->dst__header_type.dst_w_type);
546
547       if (flag_verbose_asm)
548         fprintf (asm_out_file, "\t%s record type (%s)", ASM_COMMENT_START,
549                  comment);
550
551       fputc ('\n', asm_out_file);
552     }
553
554   return 4;
555 }
556
557 /* Output the address of SYMBOL.  Also output COMMENT if flag_verbose_asm is
558    set.  Return the address size.  Just return the size if DOSIZEONLY is
559    non-zero.  */
560
561 static int
562 write_debug_addr (symbol, comment, dosizeonly)
563      char *symbol;
564      const char *comment;
565      int dosizeonly;
566 {
567   if (!dosizeonly)
568     {
569       ASM_OUTPUT_DEBUG_ADDR (asm_out_file, symbol);
570       if (flag_verbose_asm)
571         fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
572       fputc ('\n', asm_out_file);
573     }
574
575   return PTR_SIZE;
576 }
577
578 /* Output the single byte DATA1.  Also output COMMENT if flag_verbose_asm is
579    set.  Return the data size.  Just return the size if DOSIZEONLY is
580    non-zero.  */
581
582 static int
583 write_debug_data1 (data1, comment, dosizeonly)
584      unsigned int data1;
585      const char *comment;
586      int dosizeonly;
587 {
588   if (!dosizeonly)
589     {
590       ASM_OUTPUT_DEBUG_DATA1 (asm_out_file, data1);
591       if (flag_verbose_asm)
592         fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
593       fputc ('\n', asm_out_file);
594     }
595
596   return 1;
597 }
598
599 /* Output the single word DATA2.  Also output COMMENT if flag_verbose_asm is
600    set.  Return the data size.  Just return the size if DOSIZEONLY is
601    non-zero.  */
602
603 static int
604 write_debug_data2 (data2, comment, dosizeonly)
605      unsigned int data2;
606      const char *comment;
607      int dosizeonly;
608 {
609   if (!dosizeonly)
610     {
611       ASM_OUTPUT_DEBUG_DATA2 (asm_out_file, data2);
612       if (flag_verbose_asm)
613         fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
614       fputc ('\n', asm_out_file);
615     }
616
617   return 2;
618 }
619
620 /* Output double word DATA4.  Also output COMMENT if flag_verbose_asm is set.
621    Return the data size.  Just return the size if DOSIZEONLY is non-zero.  */
622
623 static int
624 write_debug_data4 (data4, comment, dosizeonly)
625      unsigned long data4;
626      const char *comment;
627      int dosizeonly;
628 {
629   if (!dosizeonly)
630     {
631       ASM_OUTPUT_DEBUG_DATA4 (asm_out_file, data4);
632       if (flag_verbose_asm)
633         fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
634       fputc ('\n', asm_out_file);
635     }
636
637   return 4;
638 }
639
640 /* Output quad word DATA8.  Also output COMMENT if flag_verbose_asm is set.
641    Return the data size.  Just return the size if DOSIZEONLY is non-zero.  */
642
643 static int
644 write_debug_data8 (data8, comment, dosizeonly)
645      unsigned long long data8;
646      const char *comment;
647      int dosizeonly;
648 {
649   if (!dosizeonly)
650     {
651       ASM_OUTPUT_DEBUG_DATA8 (asm_out_file, data8);
652       if (flag_verbose_asm)
653         fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
654       fputc ('\n', asm_out_file);
655     }
656
657   return 8;
658 }
659
660 /* Output the difference between LABEL1 and LABEL2.  Also output COMMENT if
661    flag_verbose_asm is set.  Return the data size.  Just return the size if
662    DOSIZEONLY is non-zero.  */
663
664 static int
665 write_debug_delta4 (label1, label2, comment, dosizeonly)
666      char *label1;
667      char *label2;
668      const char *comment;
669      int dosizeonly;
670 {
671   if (!dosizeonly)
672     {
673       ASM_OUTPUT_DEBUG_DELTA4 (asm_out_file, label1, label2);
674       if (flag_verbose_asm)
675         fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
676       fputc ('\n', asm_out_file);
677     }
678
679   return 4;
680 }
681
682 /* Output a character string STRING.  Also write COMMENT if flag_verbose_asm is
683    set.  Return the string length.  Just return the length if DOSIZEONLY is
684    non-zero.  */
685
686 static int
687 write_debug_string (string, comment, dosizeonly)
688      char *string;
689      const char *comment;
690      int dosizeonly;
691 {
692   if (!dosizeonly)
693     {
694       ASM_OUTPUT_DEBUG_STRING (asm_out_file, string);
695       if (flag_verbose_asm)
696         fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, comment);
697       fputc ('\n', asm_out_file);
698     }
699
700   return strlen (string);
701 }
702
703 /* Output a module begin header and return the header size.  Just return the
704    size if DOSIZEONLY is non-zero.  */
705
706 static int
707 write_modbeg (dosizeonly)
708      int dosizeonly;
709 {
710   DST_MODULE_BEGIN modbeg;
711   DST_MB_TRLR mb_trlr;
712   int i;
713   char *module_name, *m;
714   int modnamelen;
715   int prodnamelen;
716   int totsize = 0;
717
718   /* Assumes primary filename has Unix syntax file spec.  */
719   module_name = xstrdup (basename ((char *) primary_filename));
720
721   m = strrchr (module_name, '.');
722   if (m)
723     *m = 0;
724
725   modnamelen = strlen (module_name);
726   for (i = 0; i < modnamelen; i++)
727     module_name[i] = TOUPPER (module_name[i]);
728
729   prodnamelen = strlen (module_producer);
730
731   modbeg.dst_a_modbeg_header.dst__header_length.dst_w_length
732     = DST_K_MODBEG_SIZE + modnamelen + DST_K_MB_TRLR_SIZE + prodnamelen - 1;
733   modbeg.dst_a_modbeg_header.dst__header_type.dst_w_type = DST_K_MODBEG;
734   modbeg.dst_b_modbeg_flags.dst_v_modbeg_hide = 0;
735   modbeg.dst_b_modbeg_flags.dst_v_modbeg_version = 1;
736   modbeg.dst_b_modbeg_flags.dst_v_modbeg_unused = 0;
737   modbeg.dst_b_modbeg_unused = 0;
738   modbeg.dst_l_modbeg_language = module_language;
739   modbeg.dst_w_version_major = DST_K_VERSION_MAJOR;
740   modbeg.dst_w_version_minor = DST_K_VERSION_MINOR;
741   modbeg.dst_b_modbeg_name = strlen (module_name);
742
743   mb_trlr.dst_b_compiler = strlen (module_producer);
744
745   totsize += write_debug_header (&modbeg.dst_a_modbeg_header,
746                                  "modbeg", dosizeonly);
747   totsize += write_debug_data1 (*((char *) &modbeg.dst_b_modbeg_flags),
748                                 "flags", dosizeonly);
749   totsize += write_debug_data1 (modbeg.dst_b_modbeg_unused,
750                                 "unused", dosizeonly);
751   totsize += write_debug_data4 (modbeg.dst_l_modbeg_language,
752                                 "language", dosizeonly);
753   totsize += write_debug_data2 (modbeg.dst_w_version_major,
754                                 "DST major version", dosizeonly);
755   totsize += write_debug_data2 (modbeg.dst_w_version_minor,
756                                 "DST minor version", dosizeonly);
757   totsize += write_debug_data1 (modbeg.dst_b_modbeg_name,
758                                 "length of module name", dosizeonly);
759   totsize += write_debug_string (module_name, "module name", dosizeonly);
760   totsize += write_debug_data1 (mb_trlr.dst_b_compiler,
761                                 "length of compiler name", dosizeonly);
762   totsize += write_debug_string (module_producer, "compiler name", dosizeonly);
763
764   return totsize;
765 }
766
767 /* Output a module end trailer and return the trailer size.   Just return
768    the size if DOSIZEONLY is non-zero.  */
769
770 static int
771 write_modend (dosizeonly)
772      int dosizeonly;
773 {
774   DST_MODULE_END modend;
775   int totsize = 0;
776
777   modend.dst_a_modend_header.dst__header_length.dst_w_length
778    = DST_K_MODEND_SIZE - 1;
779   modend.dst_a_modend_header.dst__header_type.dst_w_type = DST_K_MODEND;
780
781   totsize += write_debug_header (&modend.dst_a_modend_header, "modend",
782                                  dosizeonly);
783
784   return totsize;
785 }
786
787 /* Output a routine begin header routine RTNNUM and return the header size.
788    Just return the size if DOSIZEONLY is non-zero.  */
789
790 static int
791 write_rtnbeg (rtnnum, dosizeonly)
792      int rtnnum;
793      int dosizeonly;
794 {
795   char *rtnname;
796   int rtnnamelen;
797   char *rtnentryname;
798   int totsize = 0;
799   char label[MAX_ARTIFICIAL_LABEL_BYTES];
800   DST_ROUTINE_BEGIN rtnbeg;
801   DST_PROLOG prolog;
802
803   rtnname = func_table[rtnnum];
804   rtnnamelen = strlen (rtnname);
805   rtnentryname = concat (rtnname, "..en", NULL);
806
807   if (!strcmp (rtnname, "main"))
808     {
809       DST_HEADER header;
810       const char *go = "TRANSFER$BREAK$GO";
811
812       /* This command isn't documented in DSTRECORDS, so it's made to
813          look like what DEC C does */
814
815       /* header size - 1st byte + flag byte + STO_LW size
816          + string count byte + string length */
817       header.dst__header_length.dst_w_length
818         = DST_K_DST_HEADER_SIZE - 1 + 1 + 4 + 1 + strlen (go);
819       header.dst__header_type.dst_w_type = 0x17;
820
821       totsize += write_debug_header (&header, "transfer", dosizeonly);
822
823       /* I think this is a flag byte, but I don't know what this flag means */
824       totsize += write_debug_data1 (0x1, "flags ???", dosizeonly);
825
826       /* Routine Begin PD Address */
827       totsize += write_debug_addr (rtnname, "main procedure descriptor",
828                                    dosizeonly);
829       totsize += write_debug_data1 (strlen (go), "length of main_name",
830                                     dosizeonly);
831       totsize += write_debug_string ((char *) go, "main name", dosizeonly);
832     }
833
834   /* The header length never includes the length byte */
835   rtnbeg.dst_a_rtnbeg_header.dst__header_length.dst_w_length
836    = DST_K_RTNBEG_SIZE + rtnnamelen - 1;
837   rtnbeg.dst_a_rtnbeg_header.dst__header_type.dst_w_type = DST_K_RTNBEG;
838   rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unused = 0;
839   rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_unalloc = 0;
840   rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_prototype = 0;
841   rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_inlined = 0;
842   rtnbeg.dst_b_rtnbeg_flags.dst_v_rtnbeg_no_call = 1;
843   rtnbeg.dst_b_rtnbeg_name = rtnnamelen;
844
845   totsize += write_debug_header (&rtnbeg.dst_a_rtnbeg_header, "rtnbeg",
846                                  dosizeonly);
847   totsize += write_debug_data1 (*((char *) &rtnbeg.dst_b_rtnbeg_flags),
848                                 "flags", dosizeonly);
849
850   /* Routine Begin Address */
851   totsize += write_debug_addr (rtnentryname, "routine entry name", dosizeonly);
852
853   /* Routine Begin PD Address */
854   totsize += write_debug_addr (rtnname, "routine procedure descriptor",
855                                dosizeonly);
856
857   /* Routine Begin Name */
858   totsize += write_debug_data1 (rtnbeg.dst_b_rtnbeg_name,
859                                 "length of routine name", dosizeonly);
860
861   totsize += write_debug_string (rtnname, "routine name", dosizeonly);
862
863   free (rtnentryname);
864
865   if (debug_info_level > DINFO_LEVEL_TERSE)
866     {
867       prolog.dst_a_prolog_header.dst__header_length.dst_w_length
868         = DST_K_PROLOG_SIZE - 1;
869       prolog.dst_a_prolog_header.dst__header_type.dst_w_type = DST_K_PROLOG;
870
871       totsize += write_debug_header (&prolog.dst_a_prolog_header, "prolog",
872                                      dosizeonly);
873
874       ASM_GENERATE_INTERNAL_LABEL (label, FUNC_PROLOG_LABEL, rtnnum);
875       totsize += write_debug_addr (label, "prolog breakpoint addr",
876                                    dosizeonly);
877     }
878
879   return totsize;
880 }
881
882 /* Output a routine end trailer for routine RTNNUM and return the header size.
883    Just return the size if DOSIZEONLY is non-zero.  */
884
885 static int
886 write_rtnend (rtnnum, dosizeonly)
887      int rtnnum;
888      int dosizeonly;
889 {
890   DST_ROUTINE_END rtnend;
891   char label1[MAX_ARTIFICIAL_LABEL_BYTES];
892   char label2[MAX_ARTIFICIAL_LABEL_BYTES];
893   int totsize;
894
895   totsize = 0;
896
897   rtnend.dst_a_rtnend_header.dst__header_length.dst_w_length
898    = DST_K_RTNEND_SIZE - 1;
899   rtnend.dst_a_rtnend_header.dst__header_type.dst_w_type = DST_K_RTNEND;
900   rtnend.dst_b_rtnend_unused = 0;
901   rtnend.dst_l_rtnend_size = 0; /* Calculated below.  */
902
903   totsize += write_debug_header (&rtnend.dst_a_rtnend_header, "rtnend",
904                                  dosizeonly);
905   totsize += write_debug_data1 (rtnend.dst_b_rtnend_unused, "unused",
906                                 dosizeonly);
907
908   ASM_GENERATE_INTERNAL_LABEL (label1, FUNC_BEGIN_LABEL, rtnnum);
909   ASM_GENERATE_INTERNAL_LABEL (label2, FUNC_END_LABEL, rtnnum);
910   totsize += write_debug_delta4 (label2, label1, "routine size", dosizeonly);
911
912   return totsize;
913 }
914
915 #define K_DELTA_PC(I) \
916  ((I) < 128 ? -(I) : (I) < 65536 ? DST_K_DELTA_PC_W : DST_K_DELTA_PC_L)
917
918 #define K_SET_LINUM(I) \
919  ((I) < 256 ? DST_K_SET_LINUM_B \
920   : (I) < 65536 ? DST_K_SET_LINUM : DST_K_SET_LINUM_L)
921
922 #define K_INCR_LINUM(I) \
923  ((I) < 256 ? DST_K_INCR_LINUM \
924   : (I) < 65536 ? DST_K_INCR_LINUM_W : DST_K_INCR_LINUM_L)
925
926 /* Output the PC to line number correlations and return the size.  Just return
927    the size if DOSIZEONLY is non-zero */
928
929 static int
930 write_pclines (dosizeonly)
931      int dosizeonly;
932 {
933   unsigned i;
934   int fn;
935   int ln, lastln;
936   int linestart = 0;
937   int max_line;
938   DST_LINE_NUM_HEADER line_num;
939   DST_PCLINE_COMMANDS pcline;
940   char label[MAX_ARTIFICIAL_LABEL_BYTES];
941   char lastlabel[MAX_ARTIFICIAL_LABEL_BYTES];
942   int totsize = 0;
943   char buff[256];
944
945   max_line = file_info_table[1].max_line;
946   file_info_table[1].listing_line_start = linestart;
947   linestart = linestart + ((max_line / 100000) + 1) * 100000;
948
949   for (i = 2; i < file_info_table_in_use; i++)
950     {
951       max_line = file_info_table[i].max_line;
952       file_info_table[i].listing_line_start = linestart;
953       linestart = linestart + ((max_line / 10000) + 1) * 10000;
954     }
955
956   /* Set starting address to beginning of text section */
957   line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 8;
958   line_num.dst_a_line_num_header.dst__header_type.dst_w_type = DST_K_LINE_NUM;
959   pcline.dst_b_pcline_command = DST_K_SET_ABS_PC;
960
961   totsize += write_debug_header (&line_num.dst_a_line_num_header,
962                                  "line_num", dosizeonly);
963   totsize += write_debug_data1 (pcline.dst_b_pcline_command,
964                                 "line_num (SET ABS PC)", dosizeonly);
965
966   if (dosizeonly)
967     totsize += 4;
968   else
969     {
970       ASM_OUTPUT_DEBUG_ADDR (asm_out_file, TEXT_SECTION_ASM_OP);
971       if (flag_verbose_asm)
972         fprintf (asm_out_file, "\t%s line_num", ASM_COMMENT_START);
973       fputc ('\n', asm_out_file);
974     }
975
976   fn = line_info_table[1].dst_file_num;
977   ln = (file_info_table[fn].listing_line_start
978         + line_info_table[1].dst_line_num);
979   line_num.dst_a_line_num_header.dst__header_length.dst_w_length = 4 + 4;
980   pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
981
982   totsize += write_debug_header (&line_num.dst_a_line_num_header,
983                                  "line_num", dosizeonly);
984   totsize += write_debug_data1 (pcline.dst_b_pcline_command,
985                                 "line_num (SET LINUM LONG)", dosizeonly);
986
987   sprintf (buff, "line_num (%d)", ln - 1);
988   totsize += write_debug_data4 (ln - 1, buff, dosizeonly);
989
990   lastln = ln;
991   strcpy (lastlabel, TEXT_SECTION_ASM_OP);
992   for (i = 1; i < line_info_table_in_use; i++)
993     {
994       int extrabytes;
995
996       fn = line_info_table[i].dst_file_num;
997       ln = (file_info_table[fn].listing_line_start
998             + line_info_table[i].dst_line_num);
999
1000       if (ln - lastln > 1)
1001         extrabytes = 5; /* NUMBYTES (ln - lastln - 1) + 1; */
1002       else if (ln <= lastln)
1003         extrabytes = 5; /* NUMBYTES (ln - 1) + 1; */
1004       else
1005         extrabytes = 0;
1006
1007       line_num.dst_a_line_num_header.dst__header_length.dst_w_length
1008         = 8 + extrabytes;
1009
1010       totsize += write_debug_header
1011         (&line_num.dst_a_line_num_header, "line_num", dosizeonly);
1012
1013       if (ln - lastln > 1)
1014         {
1015           int lndif = ln - lastln - 1;
1016
1017           /* K_INCR_LINUM (lndif); */
1018           pcline.dst_b_pcline_command = DST_K_INCR_LINUM_L;
1019
1020           totsize += write_debug_data1 (pcline.dst_b_pcline_command,
1021                                         "line_num (INCR LINUM LONG)",
1022                                         dosizeonly);
1023
1024           sprintf (buff, "line_num (%d)", lndif);
1025           totsize += write_debug_data4 (lndif, buff, dosizeonly);
1026         }
1027       else if (ln <= lastln)
1028         {
1029           /* K_SET_LINUM (ln-1); */
1030           pcline.dst_b_pcline_command = DST_K_SET_LINUM_L;
1031
1032           totsize += write_debug_data1 (pcline.dst_b_pcline_command,
1033                                         "line_num (SET LINUM LONG)",
1034                                         dosizeonly);
1035
1036           sprintf (buff, "line_num (%d)", ln - 1);
1037           totsize += write_debug_data4 (ln - 1, buff, dosizeonly);
1038         }
1039
1040       pcline.dst_b_pcline_command = DST_K_DELTA_PC_L;
1041
1042       totsize += write_debug_data1 (pcline.dst_b_pcline_command,
1043                                     "line_num (DELTA PC LONG)", dosizeonly);
1044
1045       ASM_GENERATE_INTERNAL_LABEL (label, LINE_CODE_LABEL, i);
1046       totsize += write_debug_delta4 (label, lastlabel, "increment line_num",
1047                                      dosizeonly);
1048
1049       lastln = ln;
1050       strcpy (lastlabel, label);
1051     }
1052
1053   return totsize;
1054 }
1055
1056 /* Output a source correlation for file FILEID using information saved in
1057    FILE_INFO_ENTRY and return the size.  Just return the size if DOSIZEONLY is
1058    non-zero.  */
1059
1060 static int
1061 write_srccorr (fileid, file_info_entry, dosizeonly)
1062      int fileid;
1063      dst_file_info_entry file_info_entry;
1064      int dosizeonly;
1065 {
1066   int src_command_size;
1067   int linesleft = file_info_entry.max_line;
1068   int linestart = file_info_entry.listing_line_start;
1069   int flen = file_info_entry.flen;
1070   int linestodo = 0;
1071   DST_SOURCE_CORR src_header;
1072   DST_SRC_COMMAND src_command;
1073   DST_SRC_COMMAND src_command_sf;
1074   DST_SRC_COMMAND src_command_sl;
1075   DST_SRC_COMMAND src_command_sr;
1076   DST_SRC_COMMAND src_command_dl;
1077   DST_SRC_CMDTRLR src_cmdtrlr;
1078   char buff[256];
1079   int totsize = 0;
1080
1081   if (fileid == 1)
1082     {
1083       src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1084         = DST_K_SOURCE_CORR_HEADER_SIZE + 1 - 1;
1085       src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1086         = DST_K_SOURCE;
1087       src_command.dst_b_src_command = DST_K_SRC_FORMFEED;
1088
1089       totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1090                                      "source corr", dosizeonly);
1091
1092       totsize += write_debug_data1 (src_command.dst_b_src_command,
1093                                     "source_corr (SRC FORMFEED)",
1094                                     dosizeonly);
1095     }
1096
1097   src_command_size
1098     = DST_K_SRC_COMMAND_SIZE + flen + DST_K_SRC_CMDTRLR_SIZE;
1099   src_command.dst_b_src_command = DST_K_SRC_DECLFILE;
1100   src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length
1101     = src_command_size - 2;
1102   src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags = 0;
1103   src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid
1104     = fileid;
1105   src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt
1106     = file_info_entry.cdt;
1107   src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk
1108     = file_info_entry.ebk;
1109   src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb
1110     = file_info_entry.ffb;
1111   src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo
1112     = file_info_entry.rfo;
1113   src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename
1114     = file_info_entry.flen;
1115
1116   src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1117     = DST_K_SOURCE_CORR_HEADER_SIZE + src_command_size - 1;
1118   src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1119     = DST_K_SOURCE;
1120
1121   src_cmdtrlr.dst_b_src_df_libmodname = 0;
1122
1123   totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1124                                  "source corr", dosizeonly);
1125   totsize += write_debug_data1 (src_command.dst_b_src_command,
1126                                 "source_corr (DECL SRC FILE)", dosizeonly);
1127   totsize += write_debug_data1
1128     (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_length,
1129      "source_corr (length)", dosizeonly);
1130
1131   totsize += write_debug_data1
1132     (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_flags,
1133      "source_corr (flags)", dosizeonly);
1134
1135   totsize += write_debug_data2
1136     (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_fileid,
1137      "source_corr (fileid)", dosizeonly);
1138
1139   totsize += write_debug_data8
1140     (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_q_src_df_rms_cdt,
1141      "source_corr (creation date)", dosizeonly);
1142
1143   totsize += write_debug_data4
1144     (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_l_src_df_rms_ebk,
1145      "source_corr (EOF block number)", dosizeonly);
1146
1147   totsize += write_debug_data2
1148     (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_w_src_df_rms_ffb,
1149      "source_corr (first free byte)", dosizeonly);
1150
1151   totsize += write_debug_data1
1152     (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_rms_rfo,
1153      "source_corr (record and file organization)", dosizeonly);
1154
1155   totsize += write_debug_data1
1156     (src_command.dst_a_src_cmd_fields.dst_a_src_decl_src.dst_b_src_df_filename,
1157      "source_corr (filename length)", dosizeonly);
1158
1159   totsize += write_debug_string (file_info_entry.file_name,
1160                                  "source file name", dosizeonly);
1161   totsize += write_debug_data1 (src_cmdtrlr.dst_b_src_df_libmodname,
1162                                 "source_corr (libmodname)", dosizeonly);
1163
1164   src_command_sf.dst_b_src_command = DST_K_SRC_SETFILE;
1165   src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword = fileid;
1166
1167   src_command_sr.dst_b_src_command = DST_K_SRC_SETREC_W;
1168   src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword = 1;
1169
1170   src_command_sl.dst_b_src_command = DST_K_SRC_SETLNUM_L;
1171   src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong = linestart + 1;
1172
1173   src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1174
1175   if (linesleft > 65534)
1176     linesleft = linesleft - 65534, linestodo = 65534;
1177   else
1178     linestodo = linesleft, linesleft = 0;
1179
1180   src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1181
1182   src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1183     = DST_K_SOURCE_CORR_HEADER_SIZE + 3 + 3 + 5 + 3 - 1;
1184   src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1185     = DST_K_SOURCE;
1186
1187   totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1188                                  "source corr", dosizeonly);
1189
1190   totsize += write_debug_data1 (src_command_sf.dst_b_src_command,
1191                                 "source_corr (src setfile)", dosizeonly);
1192
1193   totsize += write_debug_data2
1194     (src_command_sf.dst_a_src_cmd_fields.dst_w_src_unsword,
1195      "source_corr (fileid)", dosizeonly);
1196
1197   totsize += write_debug_data1 (src_command_sr.dst_b_src_command,
1198                                 "source_corr (setrec)", dosizeonly);
1199
1200   totsize += write_debug_data2
1201     (src_command_sr.dst_a_src_cmd_fields.dst_w_src_unsword,
1202      "source_corr (recnum)", dosizeonly);
1203
1204   totsize += write_debug_data1 (src_command_sl.dst_b_src_command,
1205                                 "source_corr (setlnum)", dosizeonly);
1206
1207   totsize += write_debug_data4
1208     (src_command_sl.dst_a_src_cmd_fields.dst_l_src_unslong,
1209      "source_corr (linenum)", dosizeonly);
1210
1211   totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1212                                 "source_corr (deflines)", dosizeonly);
1213
1214   sprintf (buff, "source_corr (%d)",
1215            src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1216   totsize += write_debug_data2
1217     (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword, buff, dosizeonly);
1218
1219   while (linesleft > 0)
1220     {
1221       src_header.dst_a_source_corr_header.dst__header_length.dst_w_length
1222         = DST_K_SOURCE_CORR_HEADER_SIZE + 3 - 1;
1223       src_header.dst_a_source_corr_header.dst__header_type.dst_w_type
1224         = DST_K_SOURCE;
1225       src_command_dl.dst_b_src_command = DST_K_SRC_DEFLINES_W;
1226
1227       if (linesleft > 65534)
1228         linesleft = linesleft - 65534, linestodo = 65534;
1229       else
1230         linestodo = linesleft, linesleft = 0;
1231
1232       src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword = linestodo;
1233
1234       totsize += write_debug_header (&src_header.dst_a_source_corr_header,
1235                                      "source corr", dosizeonly);
1236       totsize += write_debug_data1 (src_command_dl.dst_b_src_command,
1237                                     "source_corr (deflines)", dosizeonly);
1238       sprintf (buff, "source_corr (%d)",
1239                src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword);
1240       totsize += write_debug_data2
1241         (src_command_dl.dst_a_src_cmd_fields.dst_w_src_unsword,
1242          buff, dosizeonly);
1243     }
1244
1245   return totsize;
1246 }
1247
1248 /* Output all the source correlation entries and return the size.  Just return
1249    the size if DOSIZEONLY is non-zero.  */
1250
1251 static int
1252 write_srccorrs (dosizeonly)
1253      int dosizeonly;
1254 {
1255   unsigned int i;
1256   int totsize = 0;
1257
1258   for (i = 1; i < file_info_table_in_use; i++)
1259     totsize += write_srccorr (i, file_info_table[i], dosizeonly);
1260
1261   return totsize;
1262 }
1263 \f
1264 /* Output a marker (i.e. a label) for the beginning of a function, before
1265    the prologue.  */
1266
1267 static void
1268 vmsdbgout_begin_prologue (line, file)
1269      unsigned int line;
1270      const char *file;
1271 {
1272   char label[MAX_ARTIFICIAL_LABEL_BYTES];
1273
1274   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1275     (*dwarf2_debug_hooks.begin_prologue) (line, file);
1276
1277   if (debug_info_level > DINFO_LEVEL_NONE)
1278     {
1279       ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1280                                    current_function_funcdef_no);
1281       ASM_OUTPUT_LABEL (asm_out_file, label);
1282     }
1283 }
1284
1285 /* Output a marker (i.e. a label) for the beginning of a function, after
1286    the prologue.  */
1287
1288 void
1289 vmsdbgout_after_prologue ()
1290 {
1291   char label[MAX_ARTIFICIAL_LABEL_BYTES];
1292
1293   if (debug_info_level > DINFO_LEVEL_TERSE)
1294     {
1295       ASM_GENERATE_INTERNAL_LABEL (label, FUNC_PROLOG_LABEL,
1296                                    current_function_funcdef_no);
1297       ASM_OUTPUT_LABEL (asm_out_file, label);
1298     }
1299 }
1300
1301 /* Output a marker (i.e. a label) for the absolute end of the generated code
1302    for a function definition.  This gets called *after* the epilogue code has
1303    been generated.  */
1304
1305 static void
1306 vmsdbgout_end_epilogue ()
1307 {
1308   char label[MAX_ARTIFICIAL_LABEL_BYTES];
1309
1310   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1311     (*dwarf2_debug_hooks.end_epilogue) ();
1312
1313   if (debug_info_level > DINFO_LEVEL_NONE)
1314     {
1315       /* Output a label to mark the endpoint of the code generated for this
1316          function.  */
1317       ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1318                                    current_function_funcdef_no);
1319       ASM_OUTPUT_LABEL (asm_out_file, label);
1320     }
1321 }
1322
1323 /* Output a marker (i.e. a label) for the beginning of the generated code for
1324    a lexical block.  */
1325
1326 static void
1327 vmsdbgout_begin_block (line, blocknum)
1328      register unsigned line;
1329      register unsigned blocknum;
1330 {
1331   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1332     (*dwarf2_debug_hooks.begin_block) (line, blocknum);
1333
1334   if (debug_info_level > DINFO_LEVEL_TERSE)
1335     ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
1336 }
1337
1338 /* Output a marker (i.e. a label) for the end of the generated code for a
1339    lexical block.  */
1340
1341 static void
1342 vmsdbgout_end_block (line, blocknum)
1343      register unsigned line;
1344      register unsigned blocknum;
1345 {
1346   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1347     (*dwarf2_debug_hooks.end_block) (line, blocknum);
1348
1349   if (debug_info_level > DINFO_LEVEL_TERSE)
1350     ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
1351 }
1352
1353 /* Not implemented in VMS Debug.  */
1354
1355 static bool
1356 vmsdbgout_ignore_block (block)
1357      tree block;
1358 {
1359   bool retval = 0;
1360
1361   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1362     retval = (*dwarf2_debug_hooks.ignore_block) (block);
1363
1364   return retval;
1365 }
1366
1367 /* Add an entry for function DECL into the func_table.  */
1368
1369 static void
1370 vmsdbgout_begin_function (decl)
1371      tree decl;
1372 {
1373   const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1374
1375   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1376     (*dwarf2_debug_hooks.begin_function) (decl);
1377
1378   if (func_table_in_use == func_table_allocated)
1379     {
1380       func_table_allocated += FUNC_TABLE_INCREMENT;
1381       func_table = (char **) xrealloc (func_table,
1382                                        func_table_allocated * sizeof (char *));
1383     }
1384
1385   /* Add the new entry to the end of the function name table.  */
1386   func_table[func_table_in_use++] = xstrdup (name);
1387 }
1388
1389 static char fullname_buff [4096];
1390
1391 /* Return the full file specification for FILENAME.  The specification must be
1392    in VMS syntax in order to be processed by VMS Debug.  */
1393
1394 static char *
1395 full_name (filename)
1396      const char *filename;
1397 {
1398 #ifdef VMS
1399   FILE *fp = fopen (filename, "r");
1400
1401   fgetname (fp, fullname_buff, 1);
1402   fclose (fp);
1403 #else
1404   getcwd (fullname_buff, sizeof (fullname_buff));
1405
1406   strcat (fullname_buff, "/");
1407   strcat (fullname_buff, filename);
1408
1409   /* ??? Insert hairy code here to translate Unix style file specification
1410      to VMS style.  */
1411 #endif
1412
1413   return fullname_buff;
1414 }
1415
1416 /* Lookup a filename (in the list of filenames that we know about here in
1417    vmsdbgout.c) and return its "index".  The index of each (known) filename is
1418    just a unique number which is associated with only that one filename.  We
1419    need such numbers for the sake of generating labels  and references
1420    to those files numbers.  If the filename given as an argument is not
1421    found in our current list, add it to the list and assign it the next
1422    available unique index number.  In order to speed up searches, we remember
1423    the index of the filename was looked up last.  This handles the majority of
1424    all searches.  */
1425
1426 static unsigned int
1427 lookup_filename (file_name)
1428      const char *file_name;
1429 {
1430   static unsigned int last_file_lookup_index = 0;
1431   register char *fn;
1432   register unsigned i;
1433   char *fnam;
1434   long long cdt;
1435   long ebk;
1436   short ffb;
1437   char rfo;
1438   char flen;
1439   struct stat statbuf;
1440
1441   if (stat (file_name, &statbuf) == 0)
1442     {
1443       long gmtoff;
1444 #ifdef VMS
1445       struct tm *ts;
1446
1447       /* Adjust for GMT */
1448       ts = (struct tm *) localtime (&statbuf.st_ctime);
1449       gmtoff = ts->tm_gmtoff;
1450
1451       /* VMS has multiple file format types */
1452       rfo = statbuf.st_fab_rfm;
1453 #else
1454       /* Is GMT adjustment an issue with a cross-compiler? */
1455       gmtoff = 0;
1456
1457       /* Assume stream LF type file */
1458       rfo = 2;
1459 #endif
1460       cdt = 10000000 * (statbuf.st_ctime + gmtoff + vms_epoch_offset);
1461       ebk = statbuf.st_size / 512 + 1;
1462       ffb = statbuf.st_size - ((statbuf.st_size / 512) * 512);
1463       fnam = full_name (file_name);
1464       flen = strlen (fnam);
1465     }
1466   else
1467     {
1468       cdt = 0;
1469       ebk = 0;
1470       ffb = 0;
1471       rfo = 0;
1472       fnam = (char *) "";
1473       flen = 0;
1474     }
1475
1476   /* Check to see if the file name that was searched on the previous call
1477      matches this file name. If so, return the index.  */
1478   if (last_file_lookup_index != 0)
1479     {
1480       fn = file_info_table[last_file_lookup_index].file_name;
1481       if (strcmp (fnam, fn) == 0)
1482         return last_file_lookup_index;
1483     }
1484
1485   /* Didn't match the previous lookup, search the table */
1486   for (i = 1; i < file_info_table_in_use; ++i)
1487     {
1488       fn = file_info_table[i].file_name;
1489       if (strcmp (fnam, fn) == 0)
1490         {
1491           last_file_lookup_index = i;
1492           return i;
1493         }
1494     }
1495
1496   /* Prepare to add a new table entry by making sure there is enough space in
1497      the table to do so.  If not, expand the current table.  */
1498   if (file_info_table_in_use == file_info_table_allocated)
1499     {
1500
1501       file_info_table_allocated += FILE_TABLE_INCREMENT;
1502       file_info_table
1503         = (dst_file_info_ref) xrealloc (file_info_table,
1504                                         (file_info_table_allocated
1505                                          * sizeof (dst_file_info_entry)));
1506     }
1507
1508   /* Add the new entry to the end of the filename table.  */
1509   file_info_table[file_info_table_in_use].file_name = xstrdup (fnam);
1510   file_info_table[file_info_table_in_use].max_line = 0;
1511   file_info_table[file_info_table_in_use].cdt = cdt;
1512   file_info_table[file_info_table_in_use].ebk = ebk;
1513   file_info_table[file_info_table_in_use].ffb = ffb;
1514   file_info_table[file_info_table_in_use].rfo = rfo;
1515   file_info_table[file_info_table_in_use].flen = flen;
1516
1517   last_file_lookup_index = file_info_table_in_use++;
1518   return last_file_lookup_index;
1519 }
1520
1521 /* Output a label to mark the beginning of a source code line entry
1522    and record information relating to this source line, in
1523    'line_info_table' for later output of the .debug_line section.  */
1524
1525 static void
1526 vmsdbgout_source_line (line, filename)
1527      register unsigned line;
1528      register const char *filename;
1529 {
1530   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1531     (*dwarf2_debug_hooks.source_line) (line, filename);
1532
1533   if (debug_info_level >= DINFO_LEVEL_TERSE)
1534     {
1535       dst_line_info_ref line_info;
1536
1537       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
1538                                  line_info_table_in_use);
1539
1540       /* Expand the line info table if necessary.  */
1541       if (line_info_table_in_use == line_info_table_allocated)
1542         {
1543           line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
1544           line_info_table
1545             = (dst_line_info_ref) xrealloc (line_info_table,
1546                                             (line_info_table_allocated
1547                                              * sizeof (dst_line_info_entry)));
1548         }
1549
1550       /* Add the new entry at the end of the line_info_table.  */
1551       line_info = &line_info_table[line_info_table_in_use++];
1552       line_info->dst_file_num = lookup_filename (filename);
1553       line_info->dst_line_num = line;
1554       if (line > file_info_table[line_info->dst_file_num].max_line)
1555         file_info_table[line_info->dst_file_num].max_line = line;
1556     }
1557 }
1558
1559 /* Record the beginning of a new source file, for later output.
1560    At present, unimplemented.  */
1561
1562 static void
1563 vmsdbgout_start_source_file (lineno, filename)
1564      unsigned int lineno;
1565      const char *filename;
1566 {
1567   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1568     (*dwarf2_debug_hooks.start_source_file) (lineno, filename);
1569 }
1570
1571 /* Record the end of a source file, for later output.
1572    At present, unimplemented.  */
1573
1574 static void
1575 vmsdbgout_end_source_file (lineno)
1576      unsigned int lineno ATTRIBUTE_UNUSED;
1577 {
1578   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1579     (*dwarf2_debug_hooks.end_source_file) (lineno);
1580 }
1581
1582 /* Set up for Debug output at the start of compilation.  */
1583
1584 static void
1585 vmsdbgout_init (main_input_filename)
1586      const char *main_input_filename;
1587 {
1588   const char *language_string = lang_hooks.name;
1589
1590   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1591     (*dwarf2_debug_hooks.init) (main_input_filename);
1592
1593   if (debug_info_level == DINFO_LEVEL_NONE)
1594     return;
1595
1596   /* Remember the name of the primary input file.  */
1597   primary_filename = main_input_filename;
1598
1599   /* Allocate the initial hunk of the file_info_table.  */
1600   file_info_table
1601     = (dst_file_info_ref) xcalloc (FILE_TABLE_INCREMENT,
1602                                    sizeof (dst_file_info_entry));
1603   file_info_table_allocated = FILE_TABLE_INCREMENT;
1604
1605   /* Skip the first entry - file numbers begin at 1 */
1606   file_info_table_in_use = 1;
1607
1608   func_table = (char **) xcalloc (FUNC_TABLE_INCREMENT, sizeof (char *));
1609   func_table_allocated = FUNC_TABLE_INCREMENT;
1610   func_table_in_use = 1;
1611
1612   /* Allocate the initial hunk of the line_info_table.  */
1613   line_info_table
1614     = (dst_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
1615                                    sizeof (dst_line_info_entry));
1616   line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
1617   /* zero-th entry is allocated, but unused */
1618   line_info_table_in_use = 1;
1619
1620   lookup_filename (primary_filename);
1621
1622   if (!strcmp (language_string, "GNU C"))
1623     module_language = DST_K_C;
1624   else if (!strcmp (language_string, "GNU C++"))
1625     module_language = DST_K_CXX;
1626   else if (!strcmp (language_string, "GNU Ada"))
1627     module_language = DST_K_ADA;
1628   else if (!strcmp (language_string, "GNU F77"))
1629     module_language = DST_K_FORTRAN;
1630   else
1631     module_language = DST_K_UNKNOWN;
1632
1633   module_producer = concat (language_string, " ", version_string, NULL);
1634
1635   ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
1636
1637 }
1638
1639 /* Not implemented in VMS Debug.  */
1640
1641 static void
1642 vmsdbgout_define (lineno, buffer)
1643      unsigned int lineno;
1644      const char *buffer;
1645 {
1646   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1647     (*dwarf2_debug_hooks.define) (lineno, buffer);
1648 }
1649
1650 /* Not implemented in VMS Debug.  */
1651
1652 static void
1653 vmsdbgout_undef (lineno, buffer)
1654      unsigned int lineno;
1655      const char *buffer;
1656 {
1657   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1658     (*dwarf2_debug_hooks.undef) (lineno, buffer);
1659 }
1660
1661 /* Not implemented in VMS Debug.  */
1662
1663 static void
1664 vmsdbgout_decl (decl)
1665      tree decl;
1666 {
1667   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1668     (*dwarf2_debug_hooks.function_decl) (decl);
1669 }
1670
1671 /* Not implemented in VMS Debug.  */
1672
1673 static void
1674 vmsdbgout_global_decl (decl)
1675      tree decl;
1676 {
1677   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1678     (*dwarf2_debug_hooks.global_decl) (decl);
1679 }
1680
1681 /* Not implemented in VMS Debug.  */
1682
1683 static void
1684 vmsdbgout_abstract_function (decl)
1685      tree decl;
1686 {
1687   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1688     (*dwarf2_debug_hooks.outlining_inline_function) (decl);
1689 }
1690
1691 /* Output stuff that Debug requires at the end of every file and generate the
1692    VMS Debug debugging info.  */
1693
1694 static void
1695 vmsdbgout_finish (input_filename)
1696      const char *input_filename ATTRIBUTE_UNUSED;
1697 {
1698   unsigned int i;
1699   int totsize;
1700
1701   if (write_symbols == VMS_AND_DWARF2_DEBUG)
1702     (*dwarf2_debug_hooks.finish) (input_filename);
1703
1704   if (debug_info_level == DINFO_LEVEL_NONE)
1705     return;
1706
1707   /* Output a terminator label for the .text section.  */
1708   text_section ();
1709   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
1710
1711   /* Output debugging information.
1712      Warning! Do not change the name of the .vmsdebug section without
1713      changing it in the assembler also.  */
1714   named_section (NULL_TREE, ".vmsdebug", 0);
1715   ASM_OUTPUT_ALIGN (asm_out_file, 0);
1716
1717   totsize = write_modbeg (1);
1718   for (i = 1; i < func_table_in_use; i++)
1719     {
1720       totsize += write_rtnbeg (i, 1);
1721       totsize += write_rtnend (i, 1);
1722     }
1723   totsize += write_pclines (1);
1724
1725   write_modbeg (0);
1726   for (i = 1; i < func_table_in_use; i++)
1727     {
1728       write_rtnbeg (i, 0);
1729       write_rtnend (i, 0);
1730     }
1731   write_pclines (0);
1732
1733   if (debug_info_level > DINFO_LEVEL_TERSE)
1734     {
1735       totsize = write_srccorrs (1);
1736       write_srccorrs (0);
1737     }
1738
1739   totsize = write_modend (1);
1740   write_modend (0);
1741 }
1742 #endif /* VMS_DEBUGGING_INFO */