forked from riscvarchive/riscv-gcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbxout.c
3932 lines (3385 loc) · 116 KB
/
dbxout.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Output dbx-format symbol table information from GNU compiler.
Copyright (C) 1987-2020 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
/* Output dbx-format symbol table data.
This consists of many symbol table entries, each of them
a .stabs assembler pseudo-op with four operands:
a "name" which is really a description of one symbol and its type,
a "code", which is a symbol defined in stab.h whose name starts with N_,
an unused operand always 0,
and a "value" which is an address or an offset.
The name is enclosed in doublequote characters.
Each function, variable, typedef, and structure tag
has a symbol table entry to define it.
The beginning and end of each level of name scoping within
a function are also marked by special symbol table entries.
The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
and a data type number. The data type number may be followed by
"=" and a type definition; normally this will happen the first time
the type number is mentioned. The type definition may refer to
other types by number, and those type numbers may be followed
by "=" and nested definitions.
This can make the "name" quite long.
When a name is more than 80 characters, we split the .stabs pseudo-op
into two .stabs pseudo-ops, both sharing the same "code" and "value".
The first one is marked as continued with a double-backslash at the
end of its "name".
The kind-of-symbol letter distinguished function names from global
variables from file-scope variables from parameters from auto
variables in memory from typedef names from register variables.
See `dbxout_symbol'.
The "code" is mostly redundant with the kind-of-symbol letter
that goes in the "name", but not entirely: for symbols located
in static storage, the "code" says which segment the address is in,
which controls how it is relocated.
The "value" for a symbol in static storage
is the core address of the symbol (actually, the assembler
label for the symbol). For a symbol located in a stack slot
it is the stack offset; for one in a register, the register number.
For a typedef symbol, it is zero.
If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
output while in the text section.
For more on data type definitions, see `dbxout_type'. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "target.h"
#include "function.h"
#include "rtl.h"
#include "tree.h"
#include "memmodel.h"
#include "tm_p.h"
#include "stringpool.h"
#include "insn-config.h"
#include "emit-rtl.h"
#include "cgraph.h"
#include "diagnostic-core.h"
#include "fold-const.h"
#include "varasm.h"
#include "stor-layout.h"
#include "reload.h"
#include "output.h"
#include "dbxout.h"
#include "toplev.h"
#include "debug.h"
#include "common/common-target.h"
#include "langhooks.h"
#include "expr.h"
#include "file-prefix-map.h" /* remap_debug_filename() */
#ifdef XCOFF_DEBUGGING_INFO
#include "xcoffout.h"
#endif
#ifndef ASM_STABS_OP
# ifdef XCOFF_DEBUGGING_INFO
# define ASM_STABS_OP "\t.stabx\t"
# else
# define ASM_STABS_OP "\t.stabs\t"
# endif
#endif
#ifndef ASM_STABN_OP
#define ASM_STABN_OP "\t.stabn\t"
#endif
#ifndef ASM_STABD_OP
#define ASM_STABD_OP "\t.stabd\t"
#endif
#ifndef DBX_TYPE_DECL_STABS_CODE
#define DBX_TYPE_DECL_STABS_CODE N_LSYM
#endif
#ifndef DBX_STATIC_CONST_VAR_CODE
#define DBX_STATIC_CONST_VAR_CODE N_FUN
#endif
#ifndef DBX_REGPARM_STABS_CODE
#define DBX_REGPARM_STABS_CODE N_RSYM
#endif
#ifndef DBX_REGPARM_STABS_LETTER
#define DBX_REGPARM_STABS_LETTER 'P'
#endif
#ifndef NO_DBX_FUNCTION_END
#define NO_DBX_FUNCTION_END 0
#endif
#ifndef NO_DBX_BNSYM_ENSYM
#define NO_DBX_BNSYM_ENSYM 0
#endif
#ifndef NO_DBX_MAIN_SOURCE_DIRECTORY
#define NO_DBX_MAIN_SOURCE_DIRECTORY 0
#endif
#ifndef DBX_BLOCKS_FUNCTION_RELATIVE
#define DBX_BLOCKS_FUNCTION_RELATIVE 0
#endif
#ifndef DBX_LINES_FUNCTION_RELATIVE
#define DBX_LINES_FUNCTION_RELATIVE 0
#endif
#ifndef DBX_CONTIN_LENGTH
#define DBX_CONTIN_LENGTH 80
#endif
#ifndef DBX_CONTIN_CHAR
#define DBX_CONTIN_CHAR '\\'
#endif
enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
/* Structure recording information about a C data type.
The status element says whether we have yet output
the definition of the type. TYPE_XREF says we have
output it as a cross-reference only.
The file_number and type_number elements are used if DBX_USE_BINCL
is defined. */
struct GTY(()) typeinfo {
enum typestatus status;
int file_number;
int type_number;
};
/* Vector recording information about C data types.
When we first notice a data type (a tree node),
we assign it a number using next_type_number.
That is its index in this vector. */
static GTY ((length ("typevec_len"))) struct typeinfo *typevec;
/* Number of elements of space allocated in `typevec'. */
static GTY(()) int typevec_len;
/* In dbx output, each type gets a unique number.
This is the number for the next type output.
The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
static GTY(()) int next_type_number;
/* The C front end may call dbxout_symbol before dbxout_init runs.
We save all such decls in this list and output them when we get
to dbxout_init. */
static GTY(()) tree preinit_symbols;
enum binclstatus {BINCL_NOT_REQUIRED, BINCL_PENDING, BINCL_PROCESSED};
/* When using N_BINCL in dbx output, each type number is actually a
pair of the file number and the type number within the file.
This is a stack of input files. */
struct dbx_file
{
struct dbx_file *next;
int file_number;
int next_type_number;
enum binclstatus bincl_status; /* Keep track of lazy bincl. */
const char *pending_bincl_name; /* Name of bincl. */
struct dbx_file *prev; /* Chain to traverse all pending bincls. */
};
/* This is the top of the stack.
This is not saved for PCH, because restoring a PCH should not change it.
next_file_number does have to be saved, because the PCH may use some
file numbers; however, just before restoring a PCH, next_file_number
should always be 0 because we should not have needed any file numbers
yet. */
#if (defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)) \
&& defined (DBX_USE_BINCL)
static struct dbx_file *current_file;
#endif
/* This is the next file number to use. */
static GTY(()) int next_file_number;
/* A counter for dbxout_function_end. */
static GTY(()) int scope_labelno;
/* A counter for dbxout_source_line. */
static GTY(()) int dbxout_source_line_counter;
/* Number for the next N_SOL filename stabs label. The number 0 is reserved
for the N_SO filename stabs label. */
static GTY(()) int source_label_number = 1;
/* Last source file name mentioned in a NOTE insn. */
static GTY(()) const char *lastfile;
/* Last line number mentioned in a NOTE insn. */
static GTY(()) unsigned int lastlineno;
/* Used by PCH machinery to detect if 'lastfile' should be reset to
base_input_file. */
static GTY(()) int lastfile_is_base;
/* Typical USG systems don't have stab.h, and they also have
no use for DBX-format debugging info. */
#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
#ifdef DBX_USE_BINCL
/* If zero then there is no pending BINCL. */
static int pending_bincls = 0;
#endif
/* The original input file name. */
static const char *base_input_file;
#ifdef DEBUG_SYMS_TEXT
#define FORCE_TEXT switch_to_section (current_function_section ())
#else
#define FORCE_TEXT
#endif
#include "gstab.h"
/* 1 if PARM is passed to this function in memory. */
#define PARM_PASSED_IN_MEMORY(PARM) \
(MEM_P (DECL_INCOMING_RTL (PARM)))
/* A C expression for the integer offset value of an automatic variable
(N_LSYM) having address X (an RTX). */
#ifndef DEBUGGER_AUTO_OFFSET
#define DEBUGGER_AUTO_OFFSET(X) \
(GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
#endif
/* A C expression for the integer offset value of an argument (N_PSYM)
having address X (an RTX). The nominal offset is OFFSET.
Note that we use OFFSET + 0 here to avoid the self-assign warning
when the macro is called in a context like
number = DEBUGGER_ARG_OFFSET(number, X) */
#ifndef DEBUGGER_ARG_OFFSET
#define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET + 0)
#endif
/* This obstack holds the stab string currently being constructed. We
build it up here, then write it out, so we can split long lines up
properly (see dbxout_finish_complex_stabs). */
static struct obstack stabstr_ob;
static size_t stabstr_last_contin_point;
#ifdef DBX_USE_BINCL
static void emit_bincl_stab (const char *c);
static void emit_pending_bincls (void);
#endif
static inline void emit_pending_bincls_if_required (void);
static void dbxout_init (const char *);
static void dbxout_finish (const char *);
static void dbxout_start_source_file (unsigned, const char *);
static void dbxout_end_source_file (unsigned);
static void dbxout_typedefs (tree);
static void dbxout_type_index (tree);
static void dbxout_args (tree);
static void dbxout_type_fields (tree);
static void dbxout_type_method_1 (tree);
static void dbxout_type_methods (tree);
static void dbxout_range_type (tree, tree, tree);
static void dbxout_type (tree, int);
static bool print_int_cst_bounds_in_octal_p (tree, tree, tree);
static bool is_fortran (void);
static void dbxout_type_name (tree);
static void dbxout_class_name_qualifiers (tree);
static int dbxout_symbol_location (tree, tree, const char *, rtx);
static void dbxout_symbol_name (tree, const char *, int);
static void dbxout_common_name (tree, const char *, stab_code_type);
static const char *dbxout_common_check (tree, int *);
static void dbxout_early_global_decl (tree);
static void dbxout_late_global_decl (tree);
static void dbxout_type_decl (tree, int);
static void dbxout_handle_pch (unsigned);
static void debug_free_queue (void);
/* The debug hooks structure. */
#if defined (DBX_DEBUGGING_INFO)
static void dbxout_source_line (unsigned int, unsigned int, const char *,
int, bool);
static void dbxout_switch_text_section (void);
static void dbxout_begin_prologue (unsigned int, unsigned int, const char *);
static void dbxout_source_file (const char *);
static void dbxout_function_end (tree);
static void dbxout_begin_function (tree);
static void dbxout_begin_block (unsigned, unsigned);
static void dbxout_end_block (unsigned, unsigned);
static void dbxout_function_decl (tree);
const struct gcc_debug_hooks dbx_debug_hooks =
{
dbxout_init,
dbxout_finish,
debug_nothing_charstar,
debug_nothing_void,
debug_nothing_int_charstar,
debug_nothing_int_charstar,
dbxout_start_source_file,
dbxout_end_source_file,
dbxout_begin_block,
dbxout_end_block,
debug_true_const_tree, /* ignore_block */
dbxout_source_line, /* source_line */
dbxout_begin_prologue, /* begin_prologue */
debug_nothing_int_charstar, /* end_prologue */
debug_nothing_int_charstar, /* begin_epilogue */
debug_nothing_int_charstar, /* end_epilogue */
#ifdef DBX_FUNCTION_FIRST
dbxout_begin_function,
#else
debug_nothing_tree, /* begin_function */
#endif
debug_nothing_int, /* end_function */
debug_nothing_tree, /* register_main_translation_unit */
dbxout_function_decl,
dbxout_early_global_decl, /* early_global_decl */
dbxout_late_global_decl, /* late_global_decl */
dbxout_type_decl, /* type_decl */
debug_nothing_tree_tree_tree_bool_bool,/* imported_module_or_decl */
debug_false_tree_charstarstar_uhwistar,/* die_ref_for_decl */
debug_nothing_tree_charstar_uhwi, /* register_external_die */
debug_nothing_tree, /* deferred_inline_function */
debug_nothing_tree, /* outlining_inline_function */
debug_nothing_rtx_code_label, /* label */
dbxout_handle_pch, /* handle_pch */
debug_nothing_rtx_insn, /* var_location */
debug_nothing_tree, /* inline_entry */
debug_nothing_tree, /* size_function */
dbxout_switch_text_section, /* switch_text_section */
debug_nothing_tree_tree, /* set_name */
0, /* start_end_main_source_file */
TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
};
#endif /* DBX_DEBUGGING_INFO */
#if defined (XCOFF_DEBUGGING_INFO)
const struct gcc_debug_hooks xcoff_debug_hooks =
{
dbxout_init,
dbxout_finish,
debug_nothing_charstar,
debug_nothing_void,
debug_nothing_int_charstar,
debug_nothing_int_charstar,
dbxout_start_source_file,
dbxout_end_source_file,
xcoffout_begin_block,
xcoffout_end_block,
debug_true_const_tree, /* ignore_block */
xcoffout_source_line,
xcoffout_begin_prologue, /* begin_prologue */
debug_nothing_int_charstar, /* end_prologue */
debug_nothing_int_charstar, /* begin_epilogue */
xcoffout_end_epilogue,
debug_nothing_tree, /* begin_function */
xcoffout_end_function,
debug_nothing_tree, /* register_main_translation_unit */
debug_nothing_tree, /* function_decl */
dbxout_early_global_decl, /* early_global_decl */
dbxout_late_global_decl, /* late_global_decl */
dbxout_type_decl, /* type_decl */
debug_nothing_tree_tree_tree_bool_bool,/* imported_module_or_decl */
debug_false_tree_charstarstar_uhwistar,/* die_ref_for_decl */
debug_nothing_tree_charstar_uhwi, /* register_external_die */
debug_nothing_tree, /* deferred_inline_function */
debug_nothing_tree, /* outlining_inline_function */
debug_nothing_rtx_code_label, /* label */
dbxout_handle_pch, /* handle_pch */
debug_nothing_rtx_insn, /* var_location */
debug_nothing_tree, /* inline_entry */
debug_nothing_tree, /* size_function */
debug_nothing_void, /* switch_text_section */
debug_nothing_tree_tree, /* set_name */
0, /* start_end_main_source_file */
TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
};
#endif /* XCOFF_DEBUGGING_INFO */
/* Numeric formatting helper macro. Note that this does not handle
hexadecimal. */
#define NUMBER_FMT_LOOP(P, NUM, BASE) \
do \
{ \
int digit = NUM % BASE; \
NUM /= BASE; \
*--P = digit + '0'; \
} \
while (NUM > 0)
/* Utility: write a decimal integer NUM to asm_out_file. */
void
dbxout_int (int num)
{
char buf[64];
char *p = buf + sizeof buf;
unsigned int unum;
if (num == 0)
{
putc ('0', asm_out_file);
return;
}
if (num < 0)
{
putc ('-', asm_out_file);
unum = -(unsigned int) num;
}
else
unum = num;
NUMBER_FMT_LOOP (p, unum, 10);
while (p < buf + sizeof buf)
{
putc (*p, asm_out_file);
p++;
}
}
/* Primitives for emitting simple stabs directives. All other stabs
routines should use these functions instead of directly emitting
stabs. They are exported because machine-dependent code may need
to invoke them, e.g. in a DBX_OUTPUT_* macro whose definition
forwards to code in CPU.c. */
/* The following functions should all be called immediately after one
of the dbxout_begin_stab* functions (below). They write out
various things as the value of a stab. */
/* Write out a literal zero as the value of a stab. */
void
dbxout_stab_value_zero (void)
{
fputs ("0\n", asm_out_file);
}
/* Write out the label LABEL as the value of a stab. */
void
dbxout_stab_value_label (const char *label)
{
assemble_name (asm_out_file, label);
putc ('\n', asm_out_file);
}
/* Write out the difference of two labels, LABEL - BASE, as the value
of a stab. */
void
dbxout_stab_value_label_diff (const char *label, const char *base)
{
assemble_name (asm_out_file, label);
putc ('-', asm_out_file);
assemble_name (asm_out_file, base);
putc ('\n', asm_out_file);
}
/* Write out an internal label as the value of a stab, and immediately
emit that internal label. This should be used only when
dbxout_stabd will not work. STEM is the name stem of the label,
COUNTERP is a pointer to a counter variable which will be used to
guarantee label uniqueness. */
void
dbxout_stab_value_internal_label (const char *stem, int *counterp)
{
char label[100];
int counter = counterp ? (*counterp)++ : 0;
ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
dbxout_stab_value_label (label);
targetm.asm_out.internal_label (asm_out_file, stem, counter);
}
/* Write out the difference between BASE and an internal label as the
value of a stab, and immediately emit that internal label. STEM and
COUNTERP are as for dbxout_stab_value_internal_label. */
void
dbxout_stab_value_internal_label_diff (const char *stem, int *counterp,
const char *base)
{
char label[100];
int counter = counterp ? (*counterp)++ : 0;
ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
dbxout_stab_value_label_diff (label, base);
targetm.asm_out.internal_label (asm_out_file, stem, counter);
}
/* The following functions produce specific kinds of stab directives. */
/* Write a .stabd directive with type STYPE and desc SDESC to asm_out_file. */
void
dbxout_stabd (int stype, int sdesc)
{
fputs (ASM_STABD_OP, asm_out_file);
dbxout_int (stype);
fputs (",0,", asm_out_file);
dbxout_int (sdesc);
putc ('\n', asm_out_file);
}
/* Write a .stabn directive with type STYPE. This function stops
short of emitting the value field, which is the responsibility of
the caller (normally it will be either a symbol or the difference
of two symbols). */
void
dbxout_begin_stabn (int stype)
{
fputs (ASM_STABN_OP, asm_out_file);
dbxout_int (stype);
fputs (",0,0,", asm_out_file);
}
/* Write a .stabn directive with type N_SLINE and desc LINE. As above,
the value field is the responsibility of the caller. */
void
dbxout_begin_stabn_sline (int lineno)
{
fputs (ASM_STABN_OP, asm_out_file);
dbxout_int (N_SLINE);
fputs (",0,", asm_out_file);
dbxout_int (lineno);
putc (',', asm_out_file);
}
/* Begin a .stabs directive with string "", type STYPE, and desc and
other fields 0. The value field is the responsibility of the
caller. This function cannot be used for .stabx directives. */
void
dbxout_begin_empty_stabs (int stype)
{
fputs (ASM_STABS_OP, asm_out_file);
fputs ("\"\",", asm_out_file);
dbxout_int (stype);
fputs (",0,0,", asm_out_file);
}
/* Begin a .stabs directive with string STR, type STYPE, and desc 0.
The value field is the responsibility of the caller. */
void
dbxout_begin_simple_stabs (const char *str, int stype)
{
fputs (ASM_STABS_OP, asm_out_file);
output_quoted_string (asm_out_file, str);
putc (',', asm_out_file);
dbxout_int (stype);
fputs (",0,0,", asm_out_file);
}
/* As above but use SDESC for the desc field. */
void
dbxout_begin_simple_stabs_desc (const char *str, int stype, int sdesc)
{
fputs (ASM_STABS_OP, asm_out_file);
output_quoted_string (asm_out_file, str);
putc (',', asm_out_file);
dbxout_int (stype);
fputs (",0,", asm_out_file);
dbxout_int (sdesc);
putc (',', asm_out_file);
}
/* The next set of functions are entirely concerned with production of
"complex" .stabs directives: that is, .stabs directives whose
strings have to be constructed piecemeal. dbxout_type,
dbxout_symbol, etc. use these routines heavily. The string is queued
up in an obstack, then written out by dbxout_finish_complex_stabs, which
is also responsible for splitting it up if it exceeds DBX_CONTIN_LENGTH.
(You might think it would be more efficient to go straight to stdio
when DBX_CONTIN_LENGTH is 0 (i.e. no length limit) but that turns
out not to be the case, and anyway this needs fewer #ifdefs.) */
/* Begin a complex .stabs directive. If we can, write the initial
ASM_STABS_OP to the asm_out_file. */
static void
dbxout_begin_complex_stabs (void)
{
emit_pending_bincls_if_required ();
FORCE_TEXT;
fputs (ASM_STABS_OP, asm_out_file);
putc ('"', asm_out_file);
gcc_assert (stabstr_last_contin_point == 0);
}
/* As above, but do not force text or emit pending bincls. This is
used by dbxout_symbol_location, which needs to do something else. */
static void
dbxout_begin_complex_stabs_noforcetext (void)
{
fputs (ASM_STABS_OP, asm_out_file);
putc ('"', asm_out_file);
gcc_assert (stabstr_last_contin_point == 0);
}
/* Add CHR, a single character, to the string being built. */
#define stabstr_C(chr) obstack_1grow (&stabstr_ob, chr)
/* Add STR, a normal C string, to the string being built. */
#define stabstr_S(str) obstack_grow (&stabstr_ob, str, strlen (str))
/* Add the text of ID, an IDENTIFIER_NODE, to the string being built. */
#define stabstr_I(id) obstack_grow (&stabstr_ob, \
IDENTIFIER_POINTER (id), \
IDENTIFIER_LENGTH (id))
/* Add NUM, a signed decimal number, to the string being built. */
static void
stabstr_D (HOST_WIDE_INT num)
{
char buf[64];
char *p = buf + sizeof buf;
unsigned HOST_WIDE_INT unum;
if (num == 0)
{
stabstr_C ('0');
return;
}
if (num < 0)
{
stabstr_C ('-');
unum = -(unsigned HOST_WIDE_INT) num;
}
else
unum = num;
NUMBER_FMT_LOOP (p, unum, 10);
obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
}
/* Add NUM, an unsigned decimal number, to the string being built. */
static void
stabstr_U (unsigned HOST_WIDE_INT num)
{
char buf[64];
char *p = buf + sizeof buf;
if (num == 0)
{
stabstr_C ('0');
return;
}
NUMBER_FMT_LOOP (p, num, 10);
obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
}
/* Add CST, an INTEGER_CST tree, to the string being built as an
unsigned octal number. This routine handles values which are
larger than a single HOST_WIDE_INT. */
static void
stabstr_O (tree cst)
{
int prec = TYPE_PRECISION (TREE_TYPE (cst));
int res_pres = prec % 3;
int i;
unsigned int digit;
/* Leading zero for base indicator. */
stabstr_C ('0');
/* If the value is zero, the base indicator will serve as the value
all by itself. */
if (wi::to_wide (cst) == 0)
return;
/* GDB wants constants with no extra leading "1" bits, so
we need to remove any sign-extension that might be
present. */
if (res_pres == 1)
{
digit = wi::extract_uhwi (wi::to_wide (cst), prec - 1, 1);
stabstr_C ('0' + digit);
}
else if (res_pres == 2)
{
digit = wi::extract_uhwi (wi::to_wide (cst), prec - 2, 2);
stabstr_C ('0' + digit);
}
prec -= res_pres;
for (i = prec - 3; i >= 0; i = i - 3)
{
digit = wi::extract_uhwi (wi::to_wide (cst), i, 3);
stabstr_C ('0' + digit);
}
}
/* Called whenever it is safe to break a stabs string into multiple
.stabs directives. If the current string has exceeded the limit
set by DBX_CONTIN_LENGTH, mark the current position in the buffer
as a continuation point by inserting DBX_CONTIN_CHAR (doubled if
it is a backslash) and a null character. */
static inline void
stabstr_continue (void)
{
if (DBX_CONTIN_LENGTH > 0
&& obstack_object_size (&stabstr_ob) - stabstr_last_contin_point
> DBX_CONTIN_LENGTH)
{
if (DBX_CONTIN_CHAR == '\\')
obstack_1grow (&stabstr_ob, '\\');
obstack_1grow (&stabstr_ob, DBX_CONTIN_CHAR);
obstack_1grow (&stabstr_ob, '\0');
stabstr_last_contin_point = obstack_object_size (&stabstr_ob);
}
}
#define CONTIN stabstr_continue ()
/* Macro subroutine of dbxout_finish_complex_stabs, which emits
all of the arguments to the .stabs directive after the string.
Overridden by xcoffout.h. CODE is the stabs code for this symbol;
LINE is the source line to write into the desc field (in extended
mode); SYM is the symbol itself.
ADDR, LABEL, and NUMBER are three different ways to represent the
stabs value field. At most one of these should be nonzero.
ADDR is used most of the time; it represents the value as an
RTL address constant.
LABEL is used (currently) only for N_CATCH stabs; it represents
the value as a string suitable for assemble_name.
NUMBER is used when the value is an offset from an implicit base
pointer (e.g. for a stack variable), or an index (e.g. for a
register variable). It represents the value as a decimal integer. */
#ifndef DBX_FINISH_STABS
#define DBX_FINISH_STABS(SYM, CODE, LINE, ADDR, LABEL, NUMBER) \
do { \
int line_ = use_gnu_debug_info_extensions ? LINE : 0; \
\
dbxout_int (CODE); \
fputs (",0,", asm_out_file); \
dbxout_int (line_); \
putc (',', asm_out_file); \
if (ADDR) \
output_addr_const (asm_out_file, ADDR); \
else if (LABEL) \
assemble_name (asm_out_file, LABEL); \
else \
dbxout_int (NUMBER); \
putc ('\n', asm_out_file); \
} while (0)
#endif
/* Finish the emission of a complex .stabs directive. When DBX_CONTIN_LENGTH
is zero, this has only to emit the close quote and the remainder of
the arguments. When it is nonzero, the string has been marshalled in
stabstr_ob, and this routine is responsible for breaking it up into
DBX_CONTIN_LENGTH-sized chunks.
SYM is the DECL of the symbol under consideration; it is used only
for its DECL_SOURCE_LINE. The other arguments are all passed directly
to DBX_FINISH_STABS; see above for details. */
static void
dbxout_finish_complex_stabs (tree sym, stab_code_type code,
rtx addr, const char *label, int number)
{
int line ATTRIBUTE_UNUSED;
char *str;
size_t len;
line = sym ? DECL_SOURCE_LINE (sym) : 0;
if (DBX_CONTIN_LENGTH > 0)
{
char *chunk;
size_t chunklen;
/* Nul-terminate the growing string, then get its size and
address. */
obstack_1grow (&stabstr_ob, '\0');
len = obstack_object_size (&stabstr_ob);
chunk = str = XOBFINISH (&stabstr_ob, char *);
/* Within the buffer are a sequence of NUL-separated strings,
each of which is to be written out as a separate stab
directive. */
for (;;)
{
chunklen = strlen (chunk);
fwrite (chunk, 1, chunklen, asm_out_file);
fputs ("\",", asm_out_file);
/* Must add an extra byte to account for the NUL separator. */
chunk += chunklen + 1;
len -= chunklen + 1;
/* Only put a line number on the last stab in the sequence. */
DBX_FINISH_STABS (sym, code, len == 0 ? line : 0,
addr, label, number);
if (len == 0)
break;
fputs (ASM_STABS_OP, asm_out_file);
putc ('"', asm_out_file);
}
stabstr_last_contin_point = 0;
}
else
{
/* No continuations - we can put the whole string out at once.
It is faster to augment the string with the close quote and
comma than to do a two-character fputs. */
obstack_grow (&stabstr_ob, "\",", 2);
len = obstack_object_size (&stabstr_ob);
str = XOBFINISH (&stabstr_ob, char *);
fwrite (str, 1, len, asm_out_file);
DBX_FINISH_STABS (sym, code, line, addr, label, number);
}
obstack_free (&stabstr_ob, str);
}
#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
/* When -gused is used, emit debug info for only used symbols. But in
addition to the standard intercepted debug_hooks there are some
direct calls into this file, i.e., dbxout_symbol, dbxout_parms, and
dbxout_reg_params. Those routines may also be called from a higher
level intercepted routine. So to prevent recording data for an inner
call to one of these for an intercept, we maintain an intercept
nesting counter (debug_nesting). We only save the intercepted
arguments if the nesting is 1. */
static int debug_nesting = 0;
static tree *symbol_queue;
static int symbol_queue_index = 0;
static int symbol_queue_size = 0;
#define DBXOUT_DECR_NESTING \
if (--debug_nesting == 0 && symbol_queue_index > 0) \
{ emit_pending_bincls_if_required (); debug_flush_symbol_queue (); }
#define DBXOUT_DECR_NESTING_AND_RETURN(x) \
do {--debug_nesting; return (x);} while (0)
#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
#if defined (DBX_DEBUGGING_INFO)
static void
dbxout_function_end (tree decl ATTRIBUTE_UNUSED)
{
char lscope_label_name[100];
/* The Lscope label must be emitted even if we aren't doing anything
else; dbxout_block needs it. */
switch_to_section (current_function_section ());
/* Convert Lscope into the appropriate format for local labels in case
the system doesn't insert underscores in front of user generated
labels. */
ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
targetm.asm_out.internal_label (asm_out_file, "Lscope", scope_labelno);
/* The N_FUN tag at the end of the function is a GNU extension,
which may be undesirable, and is unnecessary if we do not have
named sections. */
if (!use_gnu_debug_info_extensions
|| NO_DBX_FUNCTION_END
|| !targetm_common.have_named_sections)
return;
/* By convention, GCC will mark the end of a function with an N_FUN
symbol and an empty string. */
if (crtl->has_bb_partition)
{
dbxout_begin_empty_stabs (N_FUN);
if (in_cold_section_p)
dbxout_stab_value_label_diff (crtl->subsections.cold_section_end_label,
crtl->subsections.cold_section_label);
else
dbxout_stab_value_label_diff (crtl->subsections.hot_section_end_label,
crtl->subsections.hot_section_label);
}
else
{
char begin_label[20];
/* Reference current function start using LFBB. */
ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
dbxout_begin_empty_stabs (N_FUN);
dbxout_stab_value_label_diff (lscope_label_name, begin_label);
}
if (!NO_DBX_BNSYM_ENSYM && !flag_debug_only_used_symbols)
dbxout_stabd (N_ENSYM, 0);
}
#endif /* DBX_DEBUGGING_INFO */
/* Get lang description for N_SO stab. */
static unsigned int ATTRIBUTE_UNUSED
get_lang_number (void)
{
const char *language_string = lang_hooks.name;
if (lang_GNU_C ())
return N_SO_C;
else if (lang_GNU_CXX ())
return N_SO_CC;
else if (strcmp (language_string, "GNU F77") == 0)
return N_SO_FORTRAN;
else if (lang_GNU_Fortran ())
return N_SO_FORTRAN90; /* CHECKME */
else if (strcmp (language_string, "GNU Objective-C") == 0)
return N_SO_OBJC;
else if (strcmp (language_string, "GNU Objective-C++") == 0)
return N_SO_OBJCPLUS;
else
return 0;
}
static bool
is_fortran (void)
{
unsigned int lang = get_lang_number ();
return (lang == N_SO_FORTRAN) || (lang == N_SO_FORTRAN90);
}
/* At the beginning of compilation, start writing the symbol table.
Initialize `typevec' and output the standard data types of C. */
static void
dbxout_init (const char *input_file_name)
{
char ltext_label_name[100];
bool used_ltext_label_name = false;
tree syms = lang_hooks.decls.getdecls ();
const char *mapped_name;
typevec_len = 100;
typevec = ggc_cleared_vec_alloc<typeinfo> (typevec_len);
/* stabstr_ob contains one string, which will be just fine with
1-byte alignment. */