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