-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathdbgdwarf.pas
3597 lines (3194 loc) · 142 KB
/
dbgdwarf.pas
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
{
Copyright (c) 2003-2006 by Peter Vreman and Florian Klaempfl
This units contains support for DWARF debug info generation
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
****************************************************************************
}
{
This units contains support for DWARF debug info generation.
Currently a lot of code looks like being mergable with dbgstabs. This might
change however when improved dwarf info is generated, so the stuff shouldn't be
merged yet. (FK)
The easiest way to debug dwarf debug info generation is the usage of
readelf --debug-dump <executable>
This works only with elf targets though.
There is a similar utility called dwarfdump which is not elf-specific and
which has been ported to most systems.
}
unit dbgdwarf;
{$i fpcdefs.inc}
interface
uses
cclasses,globtype,
aasmbase,aasmtai,aasmdata,
symconst,symbase,symtype,symdef,symsym,
finput,
DbgBase;
type
{ Tag names and codes. }
tdwarf_tag = (DW_TAG_padding := $00,DW_TAG_array_type := $01,
DW_TAG_class_type := $02,DW_TAG_entry_point := $03,
DW_TAG_enumeration_type := $04,DW_TAG_formal_parameter := $05,
DW_TAG_imported_declaration := $08,DW_TAG_label := $0a,
DW_TAG_lexical_block := $0b,DW_TAG_member := $0d,
DW_TAG_pointer_type := $0f,DW_TAG_reference_type := $10,
DW_TAG_compile_unit := $11,DW_TAG_stringtypee := $12,
DW_TAG_structure_type := $13,DW_TAG_subroutine_type := $15,
DW_TAG_typedef := $16,DW_TAG_union_type := $17,
DW_TAG_unspecified_parameters := $18,
DW_TAG_variant := $19,DW_TAG_common_block := $1a,
DW_TAG_common_inclusion := $1b,DW_TAG_inheritance := $1c,
DW_TAG_inlined_subroutine := $1d,DW_TAG_module := $1e,
DW_TAG_ptr_to_member_type := $1f,DW_TAG_set_type := $20,
DW_TAG_subrange_type := $21,DW_TAG_with_stmt := $22,
DW_TAG_access_declaration := $23,DW_TAG_base_type := $24,
DW_TAG_catch_block := $25,DW_TAG_const_type := $26,
DW_TAG_constant := $27,DW_TAG_enumerator := $28,
DW_TAG_file_type := $29,DW_TAG_friend := $2a,
DW_TAG_namelist := $2b,DW_TAG_namelist_item := $2c,
DW_TAG_packed_type := $2d,DW_TAG_subprogram := $2e,
DW_TAG_template_type_param := $2f,DW_TAG_template_value_param := $30,
DW_TAG_thrown_type := $31,DW_TAG_try_block := $32,
DW_TAG_variant_part := $33,DW_TAG_variable := $34,
DW_TAG_volatile_type := $35,
{ DWARF 3. }
DW_TAG_dwarf_procedure := $36,
DW_TAG_restrict_type := $37,DW_TAG_interface_type := $38,
DW_TAG_namespace := $39,DW_TAG_imported_module := $3a,
DW_TAG_unspecified_type := $3b,DW_TAG_partial_unit := $3c,
DW_TAG_imported_unit := $3d,
{ SGI/MIPS Extensions. }
DW_TAG_MIPS_loop := $4081,
{ HP extensions. See: ftp://ftp.hp.com/pub/lang/tools/WDB/wdb-4.0.tar.gz . }
DW_TAG_HP_array_descriptor := $4090,
{ GNU extensions. }
{ For FORTRAN 77 and Fortran 90. }
DW_TAG_format_label := $4101,
{ For C++. }
DW_TAG_function_template := $4102,DW_TAG_class_template := $4103,
DW_TAG_GNU_BINCL := $4104,DW_TAG_GNU_EINCL := $4105,
{ Extensions for UPC. See: http://upc.gwu.edu/~upc. }
DW_TAG_upc_shared_type := $8765,DW_TAG_upc_strict_type := $8766,
DW_TAG_upc_relaxed_type := $8767,
{ PGI (STMicroelectronics) extensions. No documentation available. }
DW_TAG_PGI_kanji_type := $A000,
DW_TAG_PGI_interface_block := $A020);
{$notes off}
{ Attribute names and codes. }
tdwarf_attribute = (DW_AT_sibling := $01,DW_AT_location := $02,
DW_AT_name := $03,DW_AT_ordering := $09,
DW_AT_subscr_data := $0a,DW_AT_byte_size := $0b,
DW_AT_bit_offset := $0c,DW_AT_bit_size := $0d,
DW_AT_element_list := $0f,DW_AT_stmt_list := $10,
DW_AT_low_pc := $11,DW_AT_high_pc := $12,
DW_AT_language := $13,DW_AT_member := $14,
DW_AT_discr := $15,DW_AT_discr_value := $16,
DW_AT_visibility := $17,DW_AT_import := $18,
DW_AT_string_length := $19,DW_AT_common_reference := $1a,
DW_AT_comp_dir := $1b,DW_AT_const_value := $1c,
DW_AT_containing_type := $1d,DW_AT_default_value := $1e,
DW_AT_inline := $20,DW_AT_is_optional := $21,
DW_AT_lower_bound := $22,DW_AT_producer := $25,
DW_AT_prototyped := $27,DW_AT_return_addr := $2a,
DW_AT_start_scope := $2c,DW_AT_stride_size := $2e,
DW_AT_upper_bound := $2f,DW_AT_abstract_origin := $31,
DW_AT_accessibility := $32,DW_AT_address_class := $33,
DW_AT_artificial := $34,DW_AT_base_types := $35,
DW_AT_calling_convention := $36,DW_AT_count := $37,
DW_AT_data_member_location := $38,DW_AT_decl_column := $39,
DW_AT_decl_file := $3a,DW_AT_decl_line := $3b,
DW_AT_declaration := $3c,DW_AT_discr_list := $3d,
DW_AT_encoding := $3e,DW_AT_external := $3f,
DW_AT_frame_base := $40,DW_AT_friend := $41,
DW_AT_identifier_case := $42,DW_AT_macro_info := $43,
DW_AT_namelist_items := $44,DW_AT_priority := $45,
DW_AT_segment := $46,DW_AT_specification := $47,
DW_AT_static_link := $48,DW_AT_type := $49,
DW_AT_use_location := $4a,DW_AT_variable_parameter := $4b,
DW_AT_virtuality := $4c,DW_AT_vtable_elem_location := $4d,
{ DWARF 3 values. }
DW_AT_allocated := $4e,DW_AT_associated := $4f,
DW_AT_data_location := $50,DW_AT_byte_stride := $51,
DW_AT_entry_pc := $52,DW_AT_use_UTF8 := $53,
DW_AT_extension := $54,DW_AT_ranges := $55,
DW_AT_trampoline := $56,DW_AT_call_column := $57,
DW_AT_call_file := $58,DW_AT_call_line := $59,
{ SGI/MIPS extensions. }
DW_AT_MIPS_fde := $2001,DW_AT_MIPS_loop_begin := $2002,
DW_AT_MIPS_tail_loop_begin := $2003,DW_AT_MIPS_epilog_begin := $2004,
DW_AT_MIPS_loop_unroll_factor := $2005,
DW_AT_MIPS_software_pipeline_depth := $2006,
DW_AT_MIPS_linkage_name := $2007,DW_AT_MIPS_stride := $2008,
DW_AT_MIPS_abstract_name := $2009,DW_AT_MIPS_clone_origin := $200a,
DW_AT_MIPS_has_inlines := $200b,
{ HP extensions. }
DW_AT_HP_block_index := $2000,
DW_AT_HP_unmodifiable := $2001,DW_AT_HP_actuals_stmt_list := $2010,
DW_AT_HP_proc_per_section := $2011,DW_AT_HP_raw_data_ptr := $2012,
DW_AT_HP_pass_by_reference := $2013,DW_AT_HP_opt_level := $2014,
DW_AT_HP_prof_version_id := $2015,DW_AT_HP_opt_flags := $2016,
DW_AT_HP_cold_region_low_pc := $2017,DW_AT_HP_cold_region_high_pc := $2018,
DW_AT_HP_all_variables_modifiable := $2019,
DW_AT_HP_linkage_name := $201a,DW_AT_HP_prof_flags := $201b,
{ GNU extensions. }
DW_AT_sf_names := $2101,DW_AT_src_info := $2102,
DW_AT_mac_info := $2103,DW_AT_src_coords := $2104,
DW_AT_body_begin := $2105,DW_AT_body_end := $2106,
DW_AT_GNU_vector := $2107,
{ VMS extensions. }
DW_AT_VMS_rtnbeg_pd_address := $2201,
{ UPC extension. }
DW_AT_upc_threads_scaled := $3210,
{ PGI (STMicroelectronics) extensions. }
DW_AT_PGI_lbase := $3a00,
DW_AT_PGI_soffset := $3a01,DW_AT_PGI_lstride := $3a02
);
{$notes on}
{ Form names and codes. }
Tdwarf_form = (DW_FORM_addr := $01,DW_FORM_block2 := $03,
DW_FORM_block4 := $04,DW_FORM_data2 := $05,
DW_FORM_data4 := $06,DW_FORM_data8 := $07,
DW_FORM_string := $08,DW_FORM_block := $09,
DW_FORM_block1 := $0a,DW_FORM_data1 := $0b,
DW_FORM_flag := $0c,DW_FORM_sdata := $0d,
DW_FORM_strp := $0e,DW_FORM_udata := $0f,
DW_FORM_ref_addr := $10,DW_FORM_ref1 := $11,
DW_FORM_ref2 := $12,DW_FORM_ref4 := $13,
DW_FORM_ref8 := $14,DW_FORM_ref_udata := $15,
DW_FORM_indirect := $16);
TDwarfFile = record
Index: integer;
Name: PChar;
end;
{ TDebugInfoDwarf }
TDebugInfoDwarf = class(TDebugInfo)
private
currabbrevnumber : longint;
{ collect all defs in one list so we can reset them easily }
defnumberlist,
deftowritelist : TFPObjectList;
{ use this defs to create info for variants and file handles }
{ unused (MWE)
filerecdef,
textrecdef : tdef;
}
dirlist: TFPHashObjectList;
filesequence: Integer;
loclist: tdynamicarray;
asmline: TAsmList;
function def_dwarf_lab(def:tdef) : tasmsymbol;
function def_dwarf_ref_lab(def:tdef) : tasmsymbol;
function def_dwarf_class_struct_lab(def:tobjectdef) : tasmsymbol;
function get_file_index(afile: tinputfile): Integer;
function relative_dwarf_path(const s:tcmdstr):tcmdstr;
protected
// set if we should use 64bit headers (dwarf3 and up)
_use_64bit_headers: Boolean;
// set to ait_const32bit if use_64bit_headers is false, otherwise
// to ait_const64bit
offsetreltype,
offsetabstype : taiconst_type;
// set if we generated any lineinfo at all. If not, we have to terminate
// when insertmoduleinfo is called.
generated_lineinfo: boolean;
vardatadef: trecorddef;
procedure set_use_64bit_headers(state: boolean);
property use_64bit_headers: Boolean read _use_64bit_headers write set_use_64bit_headers;
procedure set_def_dwarf_labs(def:tdef);
{ Convenience version of the method below, so the compiler creates the
tvarrec for us (must only pass one element in the last parameter). }
procedure append_attribute(attr: tdwarf_attribute; form: tdwarf_form; const values: array of const);
procedure append_attribute(attr: tdwarf_attribute; form: tdwarf_form; const value: tvarrec);
procedure append_entry(tag : tdwarf_tag;has_children : boolean;data : array of const);
procedure append_block1(attr: tdwarf_attribute; size: aint);
procedure append_labelentry(attr : tdwarf_attribute;sym : tasmsymbol);
procedure append_labelentry_ref(attr : tdwarf_attribute;sym : tasmsymbol);
procedure append_labelentry_dataptr_abs(attr : tdwarf_attribute;sym : tasmsymbol);
procedure append_labelentry_dataptr_rel(attr : tdwarf_attribute;sym,endsym : tasmsymbol);
procedure append_labelentry_dataptr_common(attr : tdwarf_attribute);
procedure beforeappenddef(list:TAsmList;def:tdef);override;
procedure afterappenddef(list:TAsmList;def:tdef);override;
procedure appenddef_ord(list:TAsmList;def:torddef);override;
procedure appenddef_float(list:TAsmList;def:tfloatdef);override;
procedure appenddef_enum(list:TAsmList;def:tenumdef);override;
procedure appenddef_array(list:TAsmList;def:tarraydef);override;
procedure appenddef_record(list:TAsmList;def:trecorddef);override;
procedure appenddef_pointer(list:TAsmList;def:tpointerdef);override;
procedure appenddef_string(list:TAsmList;def:tstringdef);override;
procedure appenddef_procvar(list:TAsmList;def:tprocvardef);override;
procedure appendprocdef(list:TAsmList;def:tprocdef);override;
function get_symlist_sym_offset(symlist: ppropaccesslistitem; out sym: tabstractvarsym; out offset: pint): boolean;
procedure appendsym_var(list:TAsmList;sym:tabstractnormalvarsym);
{ used for global/static variables, local variables, parameters and
absolute variables
}
procedure appendsym_var_with_name_type_offset(list:TAsmList; sym:tabstractnormalvarsym; const name: string; def: tdef; offset: pint; do_self: boolean);
{ used for fields and properties mapped to fields }
procedure appendsym_fieldvar_with_name_offset(list:TAsmList;sym: tfieldvarsym;const name: string; def: tdef; offset: pint);
procedure beforeappendsym(list:TAsmList;sym:tsym);override;
procedure appendsym_staticvar(list:TAsmList;sym:tstaticvarsym);override;
procedure appendsym_paravar(list:TAsmList;sym:tparavarsym);override;
procedure appendsym_localvar(list:TAsmList;sym:tlocalvarsym);override;
procedure appendsym_fieldvar(list:TAsmList;sym:tfieldvarsym);override;
procedure appendsym_const(list:TAsmList;sym:tconstsym);override;
procedure appendsym_type(list:TAsmList;sym:ttypesym);override;
procedure appendsym_label(list:TAsmList;sym:tlabelsym);override;
procedure appendsym_absolute(list:TAsmList;sym:tabsolutevarsym);override;
procedure appendsym_property(list:TAsmList;sym:tpropertysym);override;
function symname(sym:tsym): String; virtual;
procedure append_visibility(vis: tvisibility);
procedure enum_membersyms_callback(p:TObject;arg:pointer);
procedure finish_children;
procedure finish_entry;
procedure finish_lineinfo;
public
constructor Create;override;
destructor Destroy;override;
procedure insertmoduleinfo;override;
procedure inserttypeinfo;override;
procedure referencesections(list:TAsmList);override;
procedure insertlineinfo(list:TAsmList);override;
function dwarf_version: Word; virtual; abstract;
end;
{ TDebugInfoDwarf2 }
TDebugInfoDwarf2 = class(TDebugInfoDwarf)
private
protected
procedure appenddef_set_intern(list:TAsmList;def:tsetdef; force_tag_set: boolean);
procedure appenddef_file(list:TAsmList;def:tfiledef); override;
procedure appenddef_formal(list:TAsmList;def:tformaldef); override;
procedure appenddef_object(list:TAsmList;def:tobjectdef); override;
procedure appenddef_set(list:TAsmList;def:tsetdef); override;
procedure appenddef_undefined(list:TAsmList;def:tundefineddef); override;
procedure appenddef_variant(list:TAsmList;def:tvariantdef); override;
public
function dwarf_version: Word; override;
end;
{ TDebugInfoDwarf3 }
TDebugInfoDwarf3 = class(TDebugInfoDwarf2)
private
protected
procedure appenddef_array(list:TAsmList;def:tarraydef); override;
procedure appenddef_string(list:TAsmList;def:tstringdef);override;
procedure appenddef_file(list:TAsmList;def:tfiledef); override;
procedure appenddef_formal(list:TAsmList;def:tformaldef); override;
procedure appenddef_object(list:TAsmList;def:tobjectdef); override;
procedure appenddef_set(list:TAsmList;def: tsetdef); override;
procedure appenddef_undefined(list:TAsmList;def:tundefineddef); override;
procedure appenddef_variant(list:TAsmList;def:tvariantdef); override;
function symname(sym:tsym): String; override;
public
function dwarf_version: Word; override;
end;
implementation
uses
sysutils,cutils,cfileutl,constexp,
version,globals,verbose,systems,
cpubase,cgbase,paramgr,
fmodule,
defutil,symtable,ppu
;
const
LINE_BASE = 1;
OPCODE_BASE = 13;
const
DW_TAG_lo_user = $4080;
DW_TAG_hi_user = $ffff;
{ Flag that tells whether entry has a child or not. }
DW_children_no = 0;
DW_children_yes = 1;
const
{ Implementation-defined range start. }
DW_AT_lo_user = $2000;
{ Implementation-defined range end. }
DW_AT_hi_user = $3ff0;
type
{ Source language names and codes. }
tdwarf_source_language = (DW_LANG_C89 := $0001,DW_LANG_C := $0002,DW_LANG_Ada83 := $0003,
DW_LANG_C_plus_plus := $0004,DW_LANG_Cobol74 := $0005,
DW_LANG_Cobol85 := $0006,DW_LANG_Fortran77 := $0007,
DW_LANG_Fortran90 := $0008,DW_LANG_Pascal83 := $0009,
DW_LANG_Modula2 := $000a,DW_LANG_Java := $000b,
{ DWARF 3. }
DW_LANG_C99 := $000c,DW_LANG_Ada95 := $000d,
DW_LANG_Fortran95 := $000e,
{ MIPS. }
DW_LANG_Mips_Assembler := $8001,
{ UPC. }
DW_LANG_Upc := $8765
);
const
{ Implementation-defined range start. }
DW_LANG_lo_user = $8000;
{ Implementation-defined range start. }
DW_LANG_hi_user = $ffff;
type
{ Names and codes for macro information. }
tdwarf_macinfo_record_type = (DW_MACINFO_define := 1,DW_MACINFO_undef := 2,
DW_MACINFO_start_file := 3,DW_MACINFO_end_file := 4,
DW_MACINFO_vendor_ext := 255);
type
{ Type encodings. }
Tdwarf_type = (DW_ATE_void := $0,DW_ATE_address := $1,
DW_ATE_boolean := $2,DW_ATE_complex_float := $3,
DW_ATE_float := $4,DW_ATE_signed := $5,
DW_ATE_signed_char := $6,DW_ATE_unsigned := $7,
DW_ATE_unsigned_char := $8,DW_ATE_imaginary_float := $9,
{ HP extensions. }
DW_ATE_HP_float80 := $80,DW_ATE_HP_complex_float80 := $81,
DW_ATE_HP_float128 := $82,DW_ATE_HP_complex_float128 := $83,
DW_ATE_HP_floathpintel := $84,DW_ATE_HP_imaginary_float80 := $85,
DW_ATE_HP_imaginary_float128 := $86
);
const
DW_ATE_lo_user = $80;
DW_ATE_hi_user = $ff;
type
Tdwarf_array_dim_ordering = (DW_ORD_row_major := 0,DW_ORD_col_major := 1
);
{ Access attribute. }
Tdwarf_access_attribute = (DW_ACCESS_public := 1,DW_ACCESS_protected := 2,
DW_ACCESS_private := 3);
{ Visibility. }
Tdwarf_visibility_attribute = (DW_VIS_local := 1,DW_VIS_exported := 2,
DW_VIS_qualified := 3);
{ Virtuality. }
Tdwarf_virtuality_attribute = (DW_VIRTUALITY_none := 0,DW_VIRTUALITY_virtual := 1,
DW_VIRTUALITY_pure_virtual := 2);
{ Case sensitivity. }
Tdwarf_id_case = (DW_ID_case_sensitive := 0,DW_ID_up_case := 1,
DW_ID_down_case := 2,DW_ID_case_insensitive := 3
);
{ Calling convention. }
Tdwarf_calling_convention = (DW_CC_normal := $1,DW_CC_program := $2,
DW_CC_nocall := $3,DW_CC_GNU_renesas_sh := $40, DW_CC_GNU_borland_fastcall_i386 := $41
);
{$notes off}
{ Location atom names and codes. }
Tdwarf_location_atom = (DW_OP_addr := $03,DW_OP_deref := $06,DW_OP_const1u := $08,
DW_OP_const1s := $09,DW_OP_const2u := $0a,
DW_OP_const2s := $0b,DW_OP_const4u := $0c,
DW_OP_const4s := $0d,DW_OP_const8u := $0e,
DW_OP_const8s := $0f,DW_OP_constu := $10,
DW_OP_consts := $11,DW_OP_dup := $12,DW_OP_drop := $13,
DW_OP_over := $14,DW_OP_pick := $15,DW_OP_swap := $16,
DW_OP_rot := $17,DW_OP_xderef := $18,DW_OP_abs := $19,
DW_OP_and := $1a,DW_OP_div := $1b,DW_OP_minus := $1c,
DW_OP_mod := $1d,DW_OP_mul := $1e,DW_OP_neg := $1f,
DW_OP_not := $20,DW_OP_or := $21,DW_OP_plus := $22,
DW_OP_plus_uconst := $23,DW_OP_shl := $24,
DW_OP_shr := $25,DW_OP_shra := $26,DW_OP_xor := $27,
DW_OP_bra := $28,DW_OP_eq := $29,DW_OP_ge := $2a,
DW_OP_gt := $2b,DW_OP_le := $2c,DW_OP_lt := $2d,
DW_OP_ne := $2e,DW_OP_skip := $2f,DW_OP_lit0 := $30,
DW_OP_lit1 := $31,DW_OP_lit2 := $32,DW_OP_lit3 := $33,
DW_OP_lit4 := $34,DW_OP_lit5 := $35,DW_OP_lit6 := $36,
DW_OP_lit7 := $37,DW_OP_lit8 := $38,DW_OP_lit9 := $39,
DW_OP_lit10 := $3a,DW_OP_lit11 := $3b,
DW_OP_lit12 := $3c,DW_OP_lit13 := $3d,
DW_OP_lit14 := $3e,DW_OP_lit15 := $3f,
DW_OP_lit16 := $40,DW_OP_lit17 := $41,
DW_OP_lit18 := $42,DW_OP_lit19 := $43,
DW_OP_lit20 := $44,DW_OP_lit21 := $45,
DW_OP_lit22 := $46,DW_OP_lit23 := $47,
DW_OP_lit24 := $48,DW_OP_lit25 := $49,
DW_OP_lit26 := $4a,DW_OP_lit27 := $4b,
DW_OP_lit28 := $4c,DW_OP_lit29 := $4d,
DW_OP_lit30 := $4e,DW_OP_lit31 := $4f,
DW_OP_reg0 := $50,DW_OP_reg1 := $51,DW_OP_reg2 := $52,
DW_OP_reg3 := $53,DW_OP_reg4 := $54,DW_OP_reg5 := $55,
DW_OP_reg6 := $56,DW_OP_reg7 := $57,DW_OP_reg8 := $58,
DW_OP_reg9 := $59,DW_OP_reg10 := $5a,DW_OP_reg11 := $5b,
DW_OP_reg12 := $5c,DW_OP_reg13 := $5d,
DW_OP_reg14 := $5e,DW_OP_reg15 := $5f,
DW_OP_reg16 := $60,DW_OP_reg17 := $61,
DW_OP_reg18 := $62,DW_OP_reg19 := $63,
DW_OP_reg20 := $64,DW_OP_reg21 := $65,
DW_OP_reg22 := $66,DW_OP_reg23 := $67,
DW_OP_reg24 := $68,DW_OP_reg25 := $69,
DW_OP_reg26 := $6a,DW_OP_reg27 := $6b,
DW_OP_reg28 := $6c,DW_OP_reg29 := $6d,
DW_OP_reg30 := $6e,DW_OP_reg31 := $6f,
DW_OP_breg0 := $70,DW_OP_breg1 := $71,
DW_OP_breg2 := $72,DW_OP_breg3 := $73,
DW_OP_breg4 := $74,DW_OP_breg5 := $75,
DW_OP_breg6 := $76,DW_OP_breg7 := $77,
DW_OP_breg8 := $78,DW_OP_breg9 := $79,
DW_OP_breg10 := $7a,DW_OP_breg11 := $7b,
DW_OP_breg12 := $7c,DW_OP_breg13 := $7d,
DW_OP_breg14 := $7e,DW_OP_breg15 := $7f,
DW_OP_breg16 := $80,DW_OP_breg17 := $81,
DW_OP_breg18 := $82,DW_OP_breg19 := $83,
DW_OP_breg20 := $84,DW_OP_breg21 := $85,
DW_OP_breg22 := $86,DW_OP_breg23 := $87,
DW_OP_breg24 := $88,DW_OP_breg25 := $89,
DW_OP_breg26 := $8a,DW_OP_breg27 := $8b,
DW_OP_breg28 := $8c,DW_OP_breg29 := $8d,
DW_OP_breg30 := $8e,DW_OP_breg31 := $8f,
DW_OP_regx := $90,DW_OP_fbreg := $91,DW_OP_bregx := $92,
DW_OP_piece := $93,DW_OP_deref_size := $94,
DW_OP_xderef_size := $95,DW_OP_nop := $96,
{ DWARF 3 extensions. }
DW_OP_push_object_address := $97,DW_OP_call2 := $98,
DW_OP_call4 := $99,DW_OP_call_ref := $9a,
{ GNU extensions. }
DW_OP_GNU_push_tls_address := $e0,
{ HP extensions. }
DW_OP_HP_unknown := $e0,
DW_OP_HP_is_value := $e1,DW_OP_HP_fltconst4 := $e2,
DW_OP_HP_fltconst8 := $e3,DW_OP_HP_mod_range := $e4,
DW_OP_HP_unmod_range := $e5,DW_OP_HP_tls := $e6
);
{$notes on}
const
{ Implementation-defined range start. }
DW_OP_lo_user = $e0;
{ Implementation-defined range end. }
DW_OP_hi_user = $ff;
const
DW_LNS_extended_op = $00;
{ next copied from cfidwarf, need to go to something shared }
DW_LNS_copy = $01;
DW_LNS_advance_pc = $02;
DW_LNS_advance_line = $03;
DW_LNS_set_file = $04;
DW_LNS_set_column = $05;
DW_LNS_negate_stmt = $06;
DW_LNS_set_basic_block = $07;
DW_LNS_const_add_pc = $08;
DW_LNS_fixed_advance_pc = $09;
DW_LNS_set_prologue_end = $0a;
DW_LNS_set_epilogue_begin = $0b;
DW_LNS_set_isa = $0c;
DW_LNE_end_sequence = $01;
DW_LNE_set_address = $02;
DW_LNE_define_file = $03;
DW_LNE_lo_user = $80;
DW_LNE_hi_user = $ff;
type
{ TDirIndexItem }
TDirIndexItem = class(TFPHashObject)
private
FFiles: TFPHashObjectList;
public
IndexNr : Integer;
constructor Create(AList:TFPHashObjectList;const AName: String; AIndex: Integer);
destructor Destroy;override;
property Files: TFPHashObjectList read FFiles;
end;
{ TFileIndexItem }
TFileIndexItem = class(TFPHashObject)
private
FDirIndex: Integer;
public
IndexNr : Integer;
constructor Create(AList:TFPHashObjectList;const AName: String; ADirIndex, AIndex: Integer);
property DirIndex: Integer read FDirIndex;
end;
{****************************************************************************
procs
****************************************************************************}
function DirListSortCompare(AItem1, AItem2: Pointer): Integer;
begin
Result := TDirIndexItem(AItem1).IndexNr - TDirIndexItem(AItem2).IndexNr;
end;
function FileListSortCompare(AItem1, AItem2: Pointer): Integer;
begin
Result := TFileIndexItem(AItem1).IndexNr - TFileIndexItem(AItem2).IndexNr;
end;
{****************************************************************************
TDirIndexItem
****************************************************************************}
constructor TDirIndexItem.Create(AList:TFPHashObjectList;const AName: String; AIndex: Integer);
begin
inherited Create(AList,AName);
FFiles := TFPHashObjectList.Create;
IndexNr := AIndex;
end;
destructor TDirIndexItem.Destroy;
begin
FFiles.Free;
inherited Destroy;
end;
{****************************************************************************
TFileIndexItem
****************************************************************************}
constructor TFileIndexItem.Create(AList:TFPHashObjectList;const AName: String; ADirIndex, AIndex: Integer);
begin
inherited Create(AList,Aname);
FDirIndex := ADirIndex;
IndexNr := AIndex;
end;
{****************************************************************************
TDebugInfoDwarf
****************************************************************************}
function TDebugInfoDwarf.relative_dwarf_path(const s:tcmdstr):tcmdstr;
begin
{ Make a clean path for gdb. Remove trailing / and ./ prefixes and
use always a / }
result:=BsToSlash(ExcludeTrailingPathDelimiter(ExtractRelativePath(GetCurrentDir,FixFileName(ExpandFileName(s)))));
end;
procedure TDebugInfoDwarf.set_use_64bit_headers(state: boolean);
begin
_use_64bit_headers:=state;
if not(state) then
begin
if (target_info.system in system_windows+system_wince) then
offsetabstype:=aitconst_secrel32_symbol
else
offsetabstype:=aitconst_32bit;
if (target_info.system in systems_darwin) then
offsetreltype:=aitconst_darwin_dwarf_delta32
else
offsetreltype:=aitconst_32bit;
end
else
begin
if (target_info.system in systems_darwin) then
offsetreltype:=aitconst_darwin_dwarf_delta64
else
offsetreltype:=aitconst_64bit;
offsetabstype:=aitconst_64bit;
end;
end;
procedure TDebugInfoDwarf.set_def_dwarf_labs(def:tdef);
begin
{ Keep track of used dwarf entries, this info is only usefull for dwarf entries
referenced by the symbols. Definitions will always include all
required stabs }
if def.dbg_state=dbg_state_unused then
def.dbg_state:=dbg_state_used;
{ Need a new label? }
if not assigned(def.dwarf_lab) then
begin
if not(tf_dwarf_only_local_labels in target_info.flags) then
begin
if (ds_dwarf_dbg_info_written in def.defstates) then
begin
if not assigned(def.typesym) then
internalerror(200610011);
def.dwarf_lab:=current_asmdata.RefAsmSymbol(make_mangledname('DBG',def.owner,symname(def.typesym)));
def.dwarf_ref_lab:=current_asmdata.RefAsmSymbol(make_mangledname('DBGREF',def.owner,symname(def.typesym)));
if is_class_or_interface_or_dispinterface(def) then
tobjectdef(def).dwarf_struct_lab:=current_asmdata.RefAsmSymbol(make_mangledname('DBG2',def.owner,symname(def.typesym)));
def.dbg_state:=dbg_state_written;
end
else
begin
{ Create an exported DBG symbol if we are generating a def defined in the
globalsymtable of the current unit }
if assigned(def.typesym) and
(def.owner.symtabletype=globalsymtable) and
(def.owner.iscurrentunit) then
begin
def.dwarf_lab:=current_asmdata.DefineAsmSymbol(make_mangledname('DBG',def.owner,symname(def.typesym)),AB_GLOBAL,AT_DATA);
def.dwarf_ref_lab:=current_asmdata.DefineAsmSymbol(make_mangledname('DBGREF',def.owner,symname(def.typesym)),AB_GLOBAL,AT_DATA);
if is_class_or_interface_or_dispinterface(def) then
tobjectdef(def).dwarf_struct_lab:=current_asmdata.DefineAsmSymbol(make_mangledname('DBG2',def.owner,symname(def.typesym)),AB_GLOBAL,AT_DATA);
include(def.defstates,ds_dwarf_dbg_info_written);
end
else
begin
{ The pointer typecast is needed to prevent a problem with range checking
on when the typecast is changed to 'as' }
current_asmdata.getdatalabel(TAsmLabel(pointer(def.dwarf_lab)));
current_asmdata.getdatalabel(TAsmLabel(pointer(def.dwarf_ref_lab)));
if is_class_or_interface_or_dispinterface(def) then
current_asmdata.getdatalabel(TAsmLabel(pointer(tobjectdef(def).dwarf_struct_lab)));
end;
end;
end
else
begin
{ The pointer typecast is needed to prevent a problem with range checking
on when the typecast is changed to 'as' }
{ addrlabel instead of datalabel because it must be a local one }
current_asmdata.getaddrlabel(TAsmLabel(pointer(def.dwarf_lab)));
current_asmdata.getaddrlabel(TAsmLabel(pointer(def.dwarf_ref_lab)));
if is_class_or_interface_or_dispinterface(def) then
current_asmdata.getaddrlabel(TAsmLabel(pointer(tobjectdef(def).dwarf_struct_lab)));
end;
if def.dbg_state=dbg_state_used then
deftowritelist.Add(def);
defnumberlist.Add(def);
end;
end;
function TDebugInfoDwarf.def_dwarf_lab(def: tdef): tasmsymbol;
begin
set_def_dwarf_labs(def);
result:=def.dwarf_lab;
end;
function TDebugInfoDwarf.def_dwarf_class_struct_lab(def: tobjectdef): tasmsymbol;
begin
set_def_dwarf_labs(def);
result:=def.dwarf_struct_lab;
end;
function TDebugInfoDwarf.def_dwarf_ref_lab(def: tdef): tasmsymbol;
begin
set_def_dwarf_labs(def);
result:=def.dwarf_ref_lab;
end;
constructor TDebugInfoDwarf.Create;
begin
inherited Create;
{ 64bit headers are only supported for dwarf3 and up, so default off }
use_64bit_headers := false;
{ we haven't generated any lineinfo yet }
generated_lineinfo := false;
dirlist := TFPHashObjectList.Create;
{ add current dir as first item (index=0) }
TDirIndexItem.Create(dirlist,'.', 0);
asmline := TAsmList.create;
loclist := tdynamicarray.Create(4096);
end;
destructor TDebugInfoDwarf.Destroy;
begin
dirlist.Free;
dirlist := nil;
asmline.free;
asmline:=nil;
loclist.Free;
loclist := nil;
inherited Destroy;
end;
procedure TDebugInfoDwarf.enum_membersyms_callback(p:TObject; arg: pointer);
begin
case tsym(p).typ of
fieldvarsym:
appendsym_fieldvar(TAsmList(arg),tfieldvarsym(p));
propertysym:
appendsym_property(TAsmList(arg),tpropertysym(p));
end;
end;
function TDebugInfoDwarf.get_file_index(afile: tinputfile): Integer;
var
dirname: String;
diritem: TDirIndexItem;
diridx: Integer;
fileitem: TFileIndexItem;
begin
if afile.path^ = '' then
dirname := '.'
else
begin
{ add the canonical form here already to avoid problems with }
{ paths such as './' etc }
dirname := relative_dwarf_path(afile.path^);
if dirname = '' then
dirname := '.';
end;
diritem := TDirIndexItem(dirlist.Find(dirname));
if diritem = nil then
diritem := TDirIndexItem.Create(dirlist,dirname, dirlist.Count);
diridx := diritem.IndexNr;
fileitem := TFileIndexItem(diritem.files.Find(afile.name^));
if fileitem = nil then
begin
Inc(filesequence);
fileitem := TFileIndexItem.Create(diritem.files,afile.name^, diridx, filesequence);
end;
Result := fileitem.IndexNr;
end;
procedure TDebugInfoDwarf.append_attribute(attr: tdwarf_attribute; form: tdwarf_form; const values: array of const);
begin
if length(values)<>1 then
internalerror(2009040402);
append_attribute(attr,form,values[0]);
end;
procedure TDebugInfoDwarf.append_attribute(attr: tdwarf_attribute; form: tdwarf_form; const value: tvarrec);
begin
{ attribute }
current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(cardinal(attr)));
{ form }
current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(cardinal(form)));
{ info itself }
case form of
DW_FORM_string:
case value.VType of
vtChar:
current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(value.VChar));
vtString:
current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(value.VString^));
vtAnsistring:
current_asmdata.asmlists[al_dwarf_info].concat(tai_string.create(Ansistring(value.VAnsiString)));
else
internalerror(200601264);
end;
DW_FORM_flag:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(byte(value.VBoolean)));
DW_FORM_data1:
case value.VType of
vtInteger:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(value.VInteger));
vtInt64:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(value.VInt64^));
vtQWord:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(value.VQWord^));
else
internalerror(200602143);
end;
DW_FORM_data2:
case value.VType of
vtInteger:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(value.VInteger));
vtInt64:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(value.VInt64^));
vtQWord:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(value.VQWord^));
else
internalerror(200602144);
end;
DW_FORM_data4:
case value.VType of
vtInteger:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(value.VInteger));
vtInt64:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(value.VInt64^));
vtQWord:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(value.VQWord^));
else
internalerror(200602145);
end;
DW_FORM_data8:
case value.VType of
vtInteger:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(value.VInteger));
vtInt64:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(value.VInt64^));
vtQWord:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_64bit(value.VQWord^));
else
internalerror(200602146);
end;
DW_FORM_sdata:
case value.VType of
vtInteger:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(value.VInteger));
vtInt64:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(value.VInt64^));
vtQWord:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(value.VQWord^));
else
internalerror(200601285);
end;
DW_FORM_udata:
case value.VType of
vtInteger:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(value.VInteger));
vtInt64:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(value.VInt64^));
vtQWord:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(value.VQWord^));
else
internalerror(200601284);
end;
{ block gets only the size, the rest is appended manually by the caller }
DW_FORM_block1:
case value.VType of
vtInteger:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(value.VInteger));
vtInt64:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(value.VInt64^));
vtQWord:
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(value.VQWord^));
else
internalerror(200602141);
end;
else
internalerror(200601263);
end;
end;
{ writing the data through a few simply procedures allows to create easily extra information
for debugging of debug info }
procedure TDebugInfoDwarf.append_entry(tag : tdwarf_tag;has_children : boolean;data : array of const);
var
i : longint;
begin
{ todo: store defined abbrevs, so you have to define tehm only once (for this unit) (MWE) }
inc(currabbrevnumber);
current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_comment.Create(strpnew('Abbrev '+tostr(currabbrevnumber))));
{ abbrev number }
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_uleb128bit(currabbrevnumber));
current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(currabbrevnumber));
{ tag }
current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(tag)));
{ children? }
current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_8bit(ord(has_children)));
i:=0;
while i<=high(data) do
begin
if (i+2 > high(data)) then
internalerror(2009040401);
if data[i].VType<>vtInteger then
internalerror(200601261);
if data[i+1].VType<>vtInteger then
internalerror(200601261);
append_attribute(tdwarf_attribute(data[i].VInteger),tdwarf_form(data[i+1].VInteger),data[i+2]);
inc(i,3);
end;
end;
procedure TDebugInfoDwarf.append_block1(attr: tdwarf_attribute; size: aint);
begin
current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(attr)));
current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_block1)));
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_8bit(size));
end;
procedure TDebugInfoDwarf.append_labelentry(attr : tdwarf_attribute;sym : tasmsymbol);
begin
current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(attr)));
current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_addr)));
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sym(sym));
end;
procedure TDebugInfoDwarf.append_labelentry_ref(attr : tdwarf_attribute;sym : tasmsymbol);
begin
current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(attr)));
if not(tf_dwarf_only_local_labels in target_info.flags) then