1 /* Output xcoff-format symbol table information from GNU compiler.
2 Copyright (C) 1992-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* Output xcoff-format symbol table data. The main functionality is contained
21 in dbxout.c. This file implements the sdbout-like parts of the xcoff
22 interface. Many functions are very similar to their counterparts in
27 #include "coretypes.h"
35 #include "diagnostic-core.h"
40 #ifdef XCOFF_DEBUGGING_INFO
42 /* This defines the C_* storage classes. */
48 /* Line number of beginning of current function, minus one.
49 Negative means not in a function or not using xcoff. */
51 static int xcoff_begin_function_line
= -1;
52 static int xcoff_inlining
= 0;
54 /* Name of the current include file. */
56 const char *xcoff_current_include_file
;
58 /* Name of the current function file. This is the file the `.bf' is
59 emitted from. In case a line is emitted from a different file,
60 (by including that file of course), then the line number will be
63 static const char *xcoff_current_function_file
;
65 /* Names of bss and data sections. These should be unique names for each
68 char *xcoff_bss_section_name
;
69 char *xcoff_private_data_section_name
;
70 char *xcoff_tls_data_section_name
;
71 char *xcoff_tbss_section_name
;
72 char *xcoff_read_only_section_name
;
74 /* Last source file name mentioned in a NOTE insn. */
76 const char *xcoff_lastfile
;
78 /* Macro definitions used below. */
80 #define ABS_OR_RELATIVE_LINENO(LINENO) \
81 ((xcoff_inlining) ? (LINENO) : (LINENO) - xcoff_begin_function_line)
83 /* Output source line numbers via ".line". */
84 #define ASM_OUTPUT_LINE(FILE,LINENUM) \
87 /* Make sure we're in a function and prevent output of .line 0, as \
88 line # 0 is meant for symbol addresses in xcoff. Additionally, \
89 line numbers are 'unsigned short' in 32-bit mode. */ \
90 if (xcoff_begin_function_line >= 0) \
92 int lno = ABS_OR_RELATIVE_LINENO (LINENUM); \
93 if (lno > 0 && (TARGET_64BIT || lno <= (int)USHRT_MAX)) \
94 fprintf (FILE, "\t.line\t%d\n", lno); \
99 #define ASM_OUTPUT_LFB(FILE,LINENUM) \
101 if (xcoff_begin_function_line == -1) \
103 xcoff_begin_function_line = (LINENUM) - 1;\
104 fprintf (FILE, "\t.bf\t%d\n", (LINENUM)); \
106 xcoff_current_function_file \
107 = (xcoff_current_include_file \
108 ? xcoff_current_include_file : main_input_filename); \
111 #define ASM_OUTPUT_LFE(FILE,LINENUM) \
114 fprintf (FILE, "\t.ef\t%d\n", (LINENUM)); \
115 xcoff_begin_function_line = -1; \
119 #define ASM_OUTPUT_LBB(FILE,LINENUM,BLOCKNUM) \
120 fprintf (FILE, "\t.bb\t%d\n", ABS_OR_RELATIVE_LINENO (LINENUM))
122 #define ASM_OUTPUT_LBE(FILE,LINENUM,BLOCKNUM) \
123 fprintf (FILE, "\t.eb\t%d\n", ABS_OR_RELATIVE_LINENO (LINENUM))
125 static void xcoffout_block (tree
, int, tree
);
126 static void xcoffout_source_file (FILE *, const char *, int);
128 /* Support routines for XCOFF debugging info. */
130 struct xcoff_type_number
135 static const struct xcoff_type_number xcoff_type_numbers
[] = {
139 { "long int", -4 }, /* fiddled to -31 if 64 bits */
140 { "unsigned char", -5 },
141 { "signed char", -6 },
142 { "short unsigned int", -7 },
143 { "unsigned int", -8 },
144 /* No such type "unsigned". */
145 { "long unsigned int", -10 }, /* fiddled to -32 if 64 bits */
149 { "long double", -14 },
150 /* Pascal and Fortran types run from -15 to -29. */
151 { "wchar", -30 }, /* XXX Should be "wchar_t" ? */
152 { "long long int", -31 },
153 { "long long unsigned int", -32 },
154 /* Additional Fortran types run from -33 to -37. */
156 /* ??? Should also handle built-in C++ and Obj-C types. There perhaps
157 aren't any that C doesn't already have. */
160 /* Returns an XCOFF fundamental type number for DECL (assumed to be a
161 TYPE_DECL), or 0 if dbxout.c should assign a type number normally. */
163 xcoff_assign_fundamental_type_number (tree decl
)
168 /* Do not waste time searching the list for non-intrinsic types. */
169 if (DECL_NAME (decl
) == 0 || ! DECL_IS_BUILTIN (decl
))
172 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
174 /* Linear search, blech, but the list is too small to bother
175 doing anything else. */
176 for (i
= 0; i
< ARRAY_SIZE (xcoff_type_numbers
); i
++)
177 if (!strcmp (xcoff_type_numbers
[i
].name
, name
))
182 /* -4 and -10 should be replaced with -31 and -32, respectively,
183 when used for a 64-bit type. */
184 if (int_size_in_bytes (TREE_TYPE (decl
)) == 8)
186 if (xcoff_type_numbers
[i
].number
== -4)
188 if (xcoff_type_numbers
[i
].number
== -10)
191 return xcoff_type_numbers
[i
].number
;
194 /* Print an error message for unrecognized stab codes. */
196 #define UNKNOWN_STAB(STR) \
197 internal_error ("no sclass for %s stab (0x%x)", STR, stab)
199 /* Conversion routine from BSD stabs to AIX storage classes. */
202 stab_to_sclass (int stab
)
210 UNKNOWN_STAB ("N_FNAME");
220 UNKNOWN_STAB ("N_MAIN");
226 UNKNOWN_STAB ("N_SSYM");
241 UNKNOWN_STAB ("N_SO");
244 UNKNOWN_STAB ("N_SOL");
247 UNKNOWN_STAB ("N_SLINE");
250 UNKNOWN_STAB ("N_DSLINE");
253 UNKNOWN_STAB ("N_BSLINE");
256 UNKNOWN_STAB ("N_BINCL");
259 UNKNOWN_STAB ("N_EINCL");
262 UNKNOWN_STAB ("N_EXCL");
265 UNKNOWN_STAB ("N_LBRAC");
268 UNKNOWN_STAB ("N_RBRAC");
278 UNKNOWN_STAB ("N_LENG");
281 UNKNOWN_STAB ("N_PC");
284 UNKNOWN_STAB ("N_M2C");
287 UNKNOWN_STAB ("N_SCOPE");
290 UNKNOWN_STAB ("N_CATCH");
293 UNKNOWN_STAB ("N_OPT");
300 /* Output debugging info to FILE to switch to sourcefile FILENAME.
301 INLINE_P is true if this is from an inlined function. */
304 xcoffout_source_file (FILE *file
, const char *filename
, int inline_p
)
307 && (xcoff_lastfile
== 0 || strcmp (filename
, xcoff_lastfile
)
308 || (inline_p
&& ! xcoff_inlining
)
309 || (! inline_p
&& xcoff_inlining
)))
311 if (xcoff_current_include_file
)
313 fprintf (file
, "\t.ei\t");
314 output_quoted_string (file
,
315 remap_debug_filename (xcoff_current_include_file
));
316 fprintf (file
, "\n");
317 xcoff_current_include_file
= NULL
;
319 xcoff_inlining
= inline_p
;
320 if (strcmp (main_input_filename
, filename
) || inline_p
)
322 fprintf (file
, "\t.bi\t");
323 output_quoted_string (file
, remap_debug_filename (filename
));
324 fprintf (file
, "\n");
325 xcoff_current_include_file
= filename
;
327 xcoff_lastfile
= filename
;
331 /* Output a line number symbol entry for location (FILENAME, LINE). */
334 xcoffout_source_line (unsigned int line
, const char *filename
,
335 int discriminator ATTRIBUTE_UNUSED
,
336 bool is_stmt ATTRIBUTE_UNUSED
)
338 bool inline_p
= (strcmp (xcoff_current_function_file
, filename
) != 0
339 || (int) line
< xcoff_begin_function_line
);
341 xcoffout_source_file (asm_out_file
, filename
, inline_p
);
343 ASM_OUTPUT_LINE (asm_out_file
, line
);
346 /* Output the symbols defined in block number DO_BLOCK.
348 This function works by walking the tree structure of blocks,
349 counting blocks until it finds the desired block. */
351 static int do_block
= 0;
354 xcoffout_block (tree block
, int depth
, tree args
)
358 /* Ignore blocks never expanded or otherwise marked as real. */
359 if (TREE_USED (block
))
361 /* When we reach the specified block, output its symbols. */
362 if (BLOCK_NUMBER (block
) == do_block
)
364 /* Output the syms of the block. */
365 if (debug_info_level
!= DINFO_LEVEL_TERSE
|| depth
== 0)
366 dbxout_syms (BLOCK_VARS (block
));
368 dbxout_reg_parms (args
);
370 /* We are now done with the block. Don't go to inner blocks. */
373 /* If we are past the specified block, stop the scan. */
374 else if (BLOCK_NUMBER (block
) >= do_block
)
377 /* Output the subblocks. */
378 xcoffout_block (BLOCK_SUBBLOCKS (block
), depth
+ 1, NULL_TREE
);
380 block
= BLOCK_CHAIN (block
);
384 /* Describe the beginning of an internal block within a function.
385 Also output descriptions of variables defined in this block.
387 N is the number of the block, by order of beginning, counting from 1,
388 and not counting the outermost (function top-level) block.
389 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
390 if the count starts at 0 for the outermost one. */
393 xcoffout_begin_block (unsigned int line
, unsigned int n
)
395 tree decl
= current_function_decl
;
397 /* The IBM AIX compiler does not emit a .bb for the function level scope,
398 so we avoid it here also. */
400 ASM_OUTPUT_LBB (asm_out_file
, line
, n
);
403 xcoffout_block (DECL_INITIAL (decl
), 0, DECL_ARGUMENTS (decl
));
406 /* Describe the end line-number of an internal block within a function. */
409 xcoffout_end_block (unsigned int line
, unsigned int n
)
412 ASM_OUTPUT_LBE (asm_out_file
, line
, n
);
415 /* Called at beginning of function (before prologue).
416 Declare function as needed for debugging. */
419 xcoffout_declare_function (FILE *file
, tree decl
, const char *name
)
426 if (name
[len
- 1] == ']')
428 char *n
= XALLOCAVEC (char, len
- 3);
429 memcpy (n
, name
, len
- 4);
434 /* Any pending .bi or .ei must occur before the .function pseudo op.
435 Otherwise debuggers will think that the function is in the previous
436 file and/or at the wrong line number. */
437 xcoffout_source_file (file
, DECL_SOURCE_FILE (decl
), 0);
438 dbxout_symbol (decl
, 0);
440 /* .function NAME, TOP, MAPPING, TYPE, SIZE
441 16 and 044 are placeholders for backwards compatibility */
442 fprintf (file
, "\t.function .%s,.%s,16,044,FE..%s-.%s\n",
443 name
, name
, name
, name
);
446 /* Called at beginning of function body (at start of prologue).
447 Record the function's starting line number, so we can output
448 relative line numbers for the other lines.
449 Record the file name that this function is contained in. */
452 xcoffout_begin_prologue (unsigned int line
,
453 const char *file ATTRIBUTE_UNUSED
)
455 ASM_OUTPUT_LFB (asm_out_file
, line
);
456 dbxout_parms (DECL_ARGUMENTS (current_function_decl
));
458 /* Emit the symbols for the outermost BLOCK's variables. sdbout.c does this
459 in sdbout_begin_block, but there is no guarantee that there will be any
460 inner block 1, so we must do it here. This gives a result similar to
461 dbxout, so it does make some sense. */
462 do_block
= BLOCK_NUMBER (DECL_INITIAL (current_function_decl
));
463 xcoffout_block (DECL_INITIAL (current_function_decl
), 0,
464 DECL_ARGUMENTS (current_function_decl
));
466 ASM_OUTPUT_LINE (asm_out_file
, line
);
469 /* Called at end of function (before epilogue).
470 Describe end of outermost block. */
473 xcoffout_end_function (unsigned int last_linenum
)
475 ASM_OUTPUT_LFE (asm_out_file
, last_linenum
);
478 /* Output xcoff info for the absolute end of a function.
479 Called after the epilogue is output. */
482 xcoffout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
483 const char *file ATTRIBUTE_UNUSED
)
485 /* We need to pass the correct function size to .function, otherwise,
486 the xas assembler can't figure out the correct size for the function
487 aux entry. So, we emit a label after the last instruction which can
488 be used by the .function pseudo op to calculate the function size. */
490 const char *fname
= XSTR (XEXP (DECL_RTL (current_function_decl
), 0), 0);
493 fprintf (asm_out_file
, "FE..");
494 ASM_OUTPUT_LABEL (asm_out_file
, fname
);
496 #endif /* XCOFF_DEBUGGING_INFO */