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