-
Notifications
You must be signed in to change notification settings - Fork 10.8k
/
DWARFDebugInfoEntry.cpp
2041 lines (1837 loc) · 73.5 KB
/
DWARFDebugInfoEntry.cpp
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
//===-- DWARFDebugInfoEntry.cpp ---------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "DWARFDebugInfoEntry.h"
#include <assert.h>
#include <algorithm>
#include "lldb/Core/Module.h"
#include "lldb/Core/Stream.h"
#include "lldb/Expression/DWARFExpression.h"
#include "lldb/Symbol/ObjectFile.h"
#include "DWARFCompileUnit.h"
#include "DWARFDebugAbbrev.h"
#include "DWARFDebugAranges.h"
#include "DWARFDebugInfo.h"
#include "DWARFDeclContext.h"
#include "DWARFDIECollection.h"
#include "DWARFFormValue.h"
#include "DWARFDebugRanges.h"
#include "SymbolFileDWARF.h"
#include "SymbolFileDWARFDwo.h"
using namespace lldb_private;
using namespace std;
extern int g_verbose;
bool
DWARFDebugInfoEntry::FastExtract
(
const DWARFDataExtractor& debug_info_data,
const DWARFCompileUnit* cu,
const DWARFFormValue::FixedFormSizes& fixed_form_sizes,
lldb::offset_t *offset_ptr
)
{
m_offset = *offset_ptr;
m_parent_idx = 0;
m_sibling_idx = 0;
m_empty_children = false;
const uint64_t abbr_idx = debug_info_data.GetULEB128 (offset_ptr);
assert (abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE));
m_abbr_idx = abbr_idx;
//assert (fixed_form_sizes); // For best performance this should be specified!
if (m_abbr_idx)
{
lldb::offset_t offset = *offset_ptr;
const DWARFAbbreviationDeclaration *abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration(m_abbr_idx);
if (abbrevDecl == NULL)
{
cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: invalid abbreviation code %u, please file a bug and attach the file at the start of this error message",
m_offset,
(unsigned)abbr_idx);
// WE can't parse anymore if the DWARF is borked...
*offset_ptr = UINT32_MAX;
return false;
}
m_tag = abbrevDecl->Tag();
m_has_children = abbrevDecl->HasChildren();
// Skip all data in the .debug_info for the attributes
const uint32_t numAttributes = abbrevDecl->NumAttributes();
uint32_t i;
dw_form_t form;
for (i=0; i<numAttributes; ++i)
{
form = abbrevDecl->GetFormByIndexUnchecked(i);
const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
if (fixed_skip_size)
offset += fixed_skip_size;
else
{
bool form_is_indirect = false;
do
{
form_is_indirect = false;
uint32_t form_size = 0;
switch (form)
{
// Blocks if inlined data that have a length field and the data bytes
// inlined in the .debug_info
case DW_FORM_exprloc :
case DW_FORM_block : form_size = debug_info_data.GetULEB128 (&offset); break;
case DW_FORM_block1 : form_size = debug_info_data.GetU8_unchecked (&offset); break;
case DW_FORM_block2 : form_size = debug_info_data.GetU16_unchecked (&offset);break;
case DW_FORM_block4 : form_size = debug_info_data.GetU32_unchecked (&offset);break;
// Inlined NULL terminated C-strings
case DW_FORM_string :
debug_info_data.GetCStr (&offset);
break;
// Compile unit address sized values
case DW_FORM_addr :
form_size = cu->GetAddressByteSize();
break;
case DW_FORM_ref_addr :
if (cu->GetVersion() <= 2)
form_size = cu->GetAddressByteSize();
else
form_size = cu->IsDWARF64() ? 8 : 4;
break;
// 0 sized form
case DW_FORM_flag_present:
form_size = 0;
break;
// 1 byte values
case DW_FORM_data1 :
case DW_FORM_flag :
case DW_FORM_ref1 :
form_size = 1;
break;
// 2 byte values
case DW_FORM_data2 :
case DW_FORM_ref2 :
form_size = 2;
break;
// 4 byte values
case DW_FORM_data4 :
case DW_FORM_ref4 :
form_size = 4;
break;
// 8 byte values
case DW_FORM_data8 :
case DW_FORM_ref8 :
case DW_FORM_ref_sig8 :
form_size = 8;
break;
// signed or unsigned LEB 128 values
case DW_FORM_sdata :
case DW_FORM_udata :
case DW_FORM_ref_udata :
case DW_FORM_GNU_addr_index:
case DW_FORM_GNU_str_index :
debug_info_data.Skip_LEB128 (&offset);
break;
case DW_FORM_indirect :
form_is_indirect = true;
form = debug_info_data.GetULEB128 (&offset);
break;
case DW_FORM_strp :
case DW_FORM_sec_offset :
if (cu->IsDWARF64 ())
debug_info_data.GetU64 (offset_ptr);
else
debug_info_data.GetU32 (offset_ptr);
break;
default:
*offset_ptr = m_offset;
return false;
}
offset += form_size;
} while (form_is_indirect);
}
}
*offset_ptr = offset;
return true;
}
else
{
m_tag = 0;
m_has_children = false;
return true; // NULL debug tag entry
}
return false;
}
//----------------------------------------------------------------------
// Extract
//
// Extract a debug info entry for a given compile unit from the
// .debug_info and .debug_abbrev data within the SymbolFileDWARF class
// starting at the given offset
//----------------------------------------------------------------------
bool
DWARFDebugInfoEntry::Extract
(
SymbolFileDWARF* dwarf2Data,
const DWARFCompileUnit* cu,
lldb::offset_t *offset_ptr
)
{
const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
// const DWARFDataExtractor& debug_str_data = dwarf2Data->get_debug_str_data();
const uint32_t cu_end_offset = cu->GetNextCompileUnitOffset();
lldb::offset_t offset = *offset_ptr;
// if (offset >= cu_end_offset)
// Log::Error("DIE at offset 0x%8.8x is beyond the end of the current compile unit (0x%8.8x)", m_offset, cu_end_offset);
if ((offset < cu_end_offset) && debug_info_data.ValidOffset(offset))
{
m_offset = offset;
const uint64_t abbr_idx = debug_info_data.GetULEB128(&offset);
assert (abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE));
m_abbr_idx = abbr_idx;
if (abbr_idx)
{
const DWARFAbbreviationDeclaration *abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration(abbr_idx);
if (abbrevDecl)
{
m_tag = abbrevDecl->Tag();
m_has_children = abbrevDecl->HasChildren();
bool isCompileUnitTag = m_tag == DW_TAG_compile_unit;
if (cu && isCompileUnitTag)
const_cast<DWARFCompileUnit *>(cu)->SetBaseAddress(0);
// Skip all data in the .debug_info for the attributes
const uint32_t numAttributes = abbrevDecl->NumAttributes();
uint32_t i;
dw_attr_t attr;
dw_form_t form;
for (i=0; i<numAttributes; ++i)
{
abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
if (isCompileUnitTag && ((attr == DW_AT_entry_pc) || (attr == DW_AT_low_pc)))
{
DWARFFormValue form_value(cu, form);
if (form_value.ExtractValue(debug_info_data, &offset))
{
if (attr == DW_AT_low_pc || attr == DW_AT_entry_pc)
const_cast<DWARFCompileUnit*>(cu)->SetBaseAddress(form_value.Address());
}
}
else
{
bool form_is_indirect = false;
do
{
form_is_indirect = false;
uint32_t form_size = 0;
switch (form)
{
// Blocks if inlined data that have a length field and the data bytes
// inlined in the .debug_info
case DW_FORM_exprloc :
case DW_FORM_block : form_size = debug_info_data.GetULEB128(&offset); break;
case DW_FORM_block1 : form_size = debug_info_data.GetU8(&offset); break;
case DW_FORM_block2 : form_size = debug_info_data.GetU16(&offset); break;
case DW_FORM_block4 : form_size = debug_info_data.GetU32(&offset); break;
// Inlined NULL terminated C-strings
case DW_FORM_string : debug_info_data.GetCStr(&offset); break;
// Compile unit address sized values
case DW_FORM_addr :
form_size = cu->GetAddressByteSize();
break;
case DW_FORM_ref_addr :
if (cu->GetVersion() <= 2)
form_size = cu->GetAddressByteSize();
else
form_size = cu->IsDWARF64() ? 8 : 4;
break;
// 0 sized form
case DW_FORM_flag_present:
form_size = 0;
break;
// 1 byte values
case DW_FORM_data1 :
case DW_FORM_flag :
case DW_FORM_ref1 :
form_size = 1;
break;
// 2 byte values
case DW_FORM_data2 :
case DW_FORM_ref2 :
form_size = 2;
break;
// 4 byte values
case DW_FORM_data4 :
case DW_FORM_ref4 :
form_size = 4;
break;
// 8 byte values
case DW_FORM_data8 :
case DW_FORM_ref8 :
case DW_FORM_ref_sig8 :
form_size = 8;
break;
// signed or unsigned LEB 128 values
case DW_FORM_sdata :
case DW_FORM_udata :
case DW_FORM_ref_udata :
case DW_FORM_GNU_addr_index:
case DW_FORM_GNU_str_index :
debug_info_data.Skip_LEB128(&offset);
break;
case DW_FORM_indirect :
form = debug_info_data.GetULEB128(&offset);
form_is_indirect = true;
break;
case DW_FORM_strp :
case DW_FORM_sec_offset :
if (cu->IsDWARF64 ())
debug_info_data.GetU64 (offset_ptr);
else
debug_info_data.GetU32 (offset_ptr);
break;
default:
*offset_ptr = offset;
return false;
}
offset += form_size;
} while (form_is_indirect);
}
}
*offset_ptr = offset;
return true;
}
}
else
{
m_tag = 0;
m_has_children = false;
*offset_ptr = offset;
return true; // NULL debug tag entry
}
}
return false;
}
//----------------------------------------------------------------------
// DumpAncestry
//
// Dumps all of a debug information entries parents up until oldest and
// all of it's attributes to the specified stream.
//----------------------------------------------------------------------
void
DWARFDebugInfoEntry::DumpAncestry
(
SymbolFileDWARF* dwarf2Data,
const DWARFCompileUnit* cu,
const DWARFDebugInfoEntry* oldest,
Stream &s,
uint32_t recurse_depth
) const
{
const DWARFDebugInfoEntry* parent = GetParent();
if (parent && parent != oldest)
parent->DumpAncestry(dwarf2Data, cu, oldest, s, 0);
Dump(dwarf2Data, cu, s, recurse_depth);
}
//----------------------------------------------------------------------
// GetDIENamesAndRanges
//
// Gets the valid address ranges for a given DIE by looking for a
// DW_AT_low_pc/DW_AT_high_pc pair, DW_AT_entry_pc, or DW_AT_ranges
// attributes.
//----------------------------------------------------------------------
bool
DWARFDebugInfoEntry::GetDIENamesAndRanges
(
SymbolFileDWARF* dwarf2Data,
const DWARFCompileUnit* cu,
const char * &name,
const char * &mangled,
DWARFRangeList& ranges,
int& decl_file,
int& decl_line,
int& decl_column,
int& call_file,
int& call_line,
int& call_column,
DWARFExpression *frame_base
) const
{
if (dwarf2Data == nullptr)
return false;
SymbolFileDWARFDwo* dwo_symbol_file = cu->GetDwoSymbolFile();
if (dwo_symbol_file)
return GetDIENamesAndRanges(dwo_symbol_file,
dwo_symbol_file->GetCompileUnit(),
name,
mangled,
ranges,
decl_file,
decl_line,
decl_column,
call_file,
call_line,
call_column,
frame_base);
dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
std::vector<DIERef> die_refs;
bool set_frame_base_loclist_addr = false;
lldb::offset_t offset;
const DWARFAbbreviationDeclaration* abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
lldb::ModuleSP module = dwarf2Data->GetObjectFile()->GetModule();
if (abbrevDecl)
{
const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
if (!debug_info_data.ValidOffset(offset))
return false;
const uint32_t numAttributes = abbrevDecl->NumAttributes();
uint32_t i;
dw_attr_t attr;
dw_form_t form;
bool do_offset = false;
for (i=0; i<numAttributes; ++i)
{
abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
DWARFFormValue form_value(cu, form);
if (form_value.ExtractValue(debug_info_data, &offset))
{
switch (attr)
{
case DW_AT_low_pc:
lo_pc = form_value.Address();
if (do_offset)
hi_pc += lo_pc;
do_offset = false;
break;
case DW_AT_entry_pc:
lo_pc = form_value.Address();
break;
case DW_AT_high_pc:
if (form_value.Form() == DW_FORM_addr ||
form_value.Form() == DW_FORM_GNU_addr_index)
{
hi_pc = form_value.Address();
}
else
{
hi_pc = form_value.Unsigned();
if (lo_pc == LLDB_INVALID_ADDRESS)
do_offset = hi_pc != LLDB_INVALID_ADDRESS;
else
hi_pc += lo_pc; // DWARF 4 introduces <offset-from-lo-pc> to save on relocations
}
break;
case DW_AT_ranges:
{
const DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
if (debug_ranges)
{
debug_ranges->FindRanges(form_value.Unsigned(), ranges);
// All DW_AT_ranges are relative to the base address of the
// compile unit. We add the compile unit base address to make
// sure all the addresses are properly fixed up.
ranges.Slide(cu->GetBaseAddress());
}
else
{
cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: DIE has DW_AT_ranges(0x%" PRIx64 ") attribute yet DWARF has no .debug_ranges, please file a bug and attach the file at the start of this error message",
m_offset, form_value.Unsigned());
}
}
break;
case DW_AT_name:
if (name == NULL)
name = form_value.AsCString();
break;
case DW_AT_MIPS_linkage_name:
case DW_AT_linkage_name:
if (mangled == NULL)
mangled = form_value.AsCString();
break;
case DW_AT_abstract_origin:
die_refs.emplace_back(form_value);
break;
case DW_AT_specification:
die_refs.emplace_back(form_value);
break;
case DW_AT_decl_file:
if (decl_file == 0)
decl_file = form_value.Unsigned();
break;
case DW_AT_decl_line:
if (decl_line == 0)
decl_line = form_value.Unsigned();
break;
case DW_AT_decl_column:
if (decl_column == 0)
decl_column = form_value.Unsigned();
break;
case DW_AT_call_file:
if (call_file == 0)
call_file = form_value.Unsigned();
break;
case DW_AT_call_line:
if (call_line == 0)
call_line = form_value.Unsigned();
break;
case DW_AT_call_column:
if (call_column == 0)
call_column = form_value.Unsigned();
break;
case DW_AT_frame_base:
if (frame_base)
{
if (form_value.BlockData())
{
uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
uint32_t block_length = form_value.Unsigned();
frame_base->SetOpcodeData(module, debug_info_data, block_offset, block_length);
}
else
{
const DWARFDataExtractor &debug_loc_data = dwarf2Data->get_debug_loc_data();
const dw_offset_t debug_loc_offset = form_value.Unsigned();
size_t loc_list_length = DWARFExpression::LocationListSize(cu, debug_loc_data, debug_loc_offset);
if (loc_list_length > 0)
{
frame_base->SetOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
if (lo_pc != LLDB_INVALID_ADDRESS)
{
assert (lo_pc >= cu->GetBaseAddress());
frame_base->SetLocationListSlide(lo_pc - cu->GetBaseAddress());
}
else
{
set_frame_base_loclist_addr = true;
}
}
}
}
break;
default:
break;
}
}
}
}
if (ranges.IsEmpty())
{
if (lo_pc != LLDB_INVALID_ADDRESS)
{
if (hi_pc != LLDB_INVALID_ADDRESS && hi_pc > lo_pc)
ranges.Append(DWARFRangeList::Entry (lo_pc, hi_pc - lo_pc));
else
ranges.Append(DWARFRangeList::Entry (lo_pc, 0));
}
}
if (set_frame_base_loclist_addr)
{
dw_addr_t lowest_range_pc = ranges.GetMinRangeBase(0);
assert (lowest_range_pc >= cu->GetBaseAddress());
frame_base->SetLocationListSlide (lowest_range_pc - cu->GetBaseAddress());
}
if (ranges.IsEmpty() || name == NULL || mangled == NULL)
{
for (const DIERef& die_ref : die_refs)
{
if (die_ref.die_offset != DW_INVALID_OFFSET)
{
DWARFDIE die = dwarf2Data->DebugInfo()->GetDIE(die_ref);
if (die)
die.GetDIE()->GetDIENamesAndRanges(die.GetDWARF(), die.GetCU(), name, mangled, ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column);
}
}
}
return !ranges.IsEmpty();
}
//----------------------------------------------------------------------
// Dump
//
// Dumps a debug information entry and all of it's attributes to the
// specified stream.
//----------------------------------------------------------------------
void
DWARFDebugInfoEntry::Dump
(
SymbolFileDWARF* dwarf2Data,
const DWARFCompileUnit* cu,
Stream &s,
uint32_t recurse_depth
) const
{
const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
lldb::offset_t offset = m_offset;
if (debug_info_data.ValidOffset(offset))
{
dw_uleb128_t abbrCode = debug_info_data.GetULEB128(&offset);
s.Printf("\n0x%8.8x: ", m_offset);
s.Indent();
if (abbrCode != m_abbr_idx)
{
s.Printf( "error: DWARF has been modified\n");
}
else if (abbrCode)
{
const DWARFAbbreviationDeclaration* abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration (abbrCode);
if (abbrevDecl)
{
s.PutCString(DW_TAG_value_to_name(abbrevDecl->Tag()));
s.Printf( " [%u] %c\n", abbrCode, abbrevDecl->HasChildren() ? '*':' ');
// Dump all data in the .debug_info for the attributes
const uint32_t numAttributes = abbrevDecl->NumAttributes();
uint32_t i;
dw_attr_t attr;
dw_form_t form;
for (i=0; i<numAttributes; ++i)
{
abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
DumpAttribute(dwarf2Data, cu, debug_info_data, &offset, s, attr, form);
}
const DWARFDebugInfoEntry* child = GetFirstChild();
if (recurse_depth > 0 && child)
{
s.IndentMore();
while (child)
{
child->Dump(dwarf2Data, cu, s, recurse_depth-1);
child = child->GetSibling();
}
s.IndentLess();
}
}
else
s.Printf( "Abbreviation code note found in 'debug_abbrev' class for code: %u\n", abbrCode);
}
else
{
s.Printf( "NULL\n");
}
}
}
void
DWARFDebugInfoEntry::DumpLocation
(
SymbolFileDWARF* dwarf2Data,
DWARFCompileUnit* cu,
Stream &s
) const
{
const DWARFDIE cu_die = cu->GetCompileUnitDIEOnly();
const char *cu_name = NULL;
if (cu_die)
cu_name = cu_die.GetName ();
const char *obj_file_name = NULL;
ObjectFile *obj_file = dwarf2Data->GetObjectFile();
if (obj_file)
obj_file_name = obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>");
const char *die_name = GetName (dwarf2Data, cu);
s.Printf ("0x%8.8x/0x%8.8x: %-30s (from %s in %s)",
cu->GetOffset(),
GetOffset(),
die_name ? die_name : "",
cu_name ? cu_name : "<NULL>",
obj_file_name ? obj_file_name : "<NULL>");
}
//----------------------------------------------------------------------
// DumpAttribute
//
// Dumps a debug information entry attribute along with it's form. Any
// special display of attributes is done (disassemble location lists,
// show enumeration values for attributes, etc).
//----------------------------------------------------------------------
void
DWARFDebugInfoEntry::DumpAttribute
(
SymbolFileDWARF* dwarf2Data,
const DWARFCompileUnit* cu,
const DWARFDataExtractor& debug_info_data,
lldb::offset_t *offset_ptr,
Stream &s,
dw_attr_t attr,
dw_form_t form
)
{
bool verbose = s.GetVerbose();
bool show_form = s.GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowForm);
if (verbose)
s.Offset (*offset_ptr);
else
s.Printf (" ");
s.Indent(DW_AT_value_to_name(attr));
if (show_form)
{
s.Printf( "[%s", DW_FORM_value_to_name(form));
}
DWARFFormValue form_value(cu, form);
if (!form_value.ExtractValue(debug_info_data, offset_ptr))
return;
if (show_form)
{
if (form == DW_FORM_indirect)
{
s.Printf( " [%s]", DW_FORM_value_to_name(form_value.Form()));
}
s.PutCString("] ");
}
s.PutCString("( ");
// Always dump form value if verbose is enabled
if (verbose)
{
form_value.Dump(s);
}
// Check to see if we have any special attribute formatters
switch (attr)
{
case DW_AT_stmt_list:
if ( verbose ) s.PutCString(" ( ");
s.Printf( "0x%8.8" PRIx64, form_value.Unsigned());
if ( verbose ) s.PutCString(" )");
break;
case DW_AT_language:
if ( verbose ) s.PutCString(" ( ");
s.PutCString(DW_LANG_value_to_name(form_value.Unsigned()));
if ( verbose ) s.PutCString(" )");
break;
case DW_AT_encoding:
if ( verbose ) s.PutCString(" ( ");
s.PutCString(DW_ATE_value_to_name(form_value.Unsigned()));
if ( verbose ) s.PutCString(" )");
break;
case DW_AT_frame_base:
case DW_AT_location:
case DW_AT_data_member_location:
{
const uint8_t* blockData = form_value.BlockData();
if (blockData)
{
if (!verbose)
form_value.Dump(s);
// Location description is inlined in data in the form value
DWARFDataExtractor locationData(debug_info_data, (*offset_ptr) - form_value.Unsigned(), form_value.Unsigned());
if ( verbose ) s.PutCString(" ( ");
DWARFExpression::PrintDWARFExpression(s,
locationData,
DWARFCompileUnit::GetAddressByteSize(cu),
4,
false);
if ( verbose ) s.PutCString(" )");
}
else
{
// We have a location list offset as the value that is
// the offset into the .debug_loc section that describes
// the value over it's lifetime
uint64_t debug_loc_offset = form_value.Unsigned();
if (dwarf2Data)
{
if ( !verbose )
form_value.Dump(s);
DWARFExpression::PrintDWARFLocationList(s,
cu,
dwarf2Data->get_debug_loc_data(),
debug_loc_offset);
}
else
{
if ( !verbose )
form_value.Dump(s);
}
}
}
break;
case DW_AT_abstract_origin:
case DW_AT_specification:
{
uint64_t abstract_die_offset = form_value.Reference();
form_value.Dump(s);
// *ostrm_ptr << HEX32 << abstract_die_offset << " ( ";
if ( verbose ) s.PutCString(" ( ");
GetName(dwarf2Data, cu, abstract_die_offset, s);
if ( verbose ) s.PutCString(" )");
}
break;
case DW_AT_type:
{
uint64_t type_die_offset = form_value.Reference();
if (!verbose)
form_value.Dump(s);
s.PutCString(" ( ");
AppendTypeName(dwarf2Data, cu, type_die_offset, s);
s.PutCString(" )");
}
break;
case DW_AT_ranges:
{
if ( !verbose )
form_value.Dump(s);
lldb::offset_t ranges_offset = form_value.Unsigned();
dw_addr_t base_addr = cu ? cu->GetBaseAddress() : 0;
if (dwarf2Data)
DWARFDebugRanges::Dump(s, dwarf2Data->get_debug_ranges_data(), &ranges_offset, base_addr);
}
break;
default:
if ( !verbose )
form_value.Dump(s);
break;
}
s.PutCString(" )\n");
}
//----------------------------------------------------------------------
// Get all attribute values for a given DIE, including following any
// specification or abstract origin attributes and including those in
// the results. Any duplicate attributes will have the first instance
// take precedence (this can happen for declaration attributes).
//----------------------------------------------------------------------
size_t
DWARFDebugInfoEntry::GetAttributes (const DWARFCompileUnit* cu,
DWARFFormValue::FixedFormSizes fixed_form_sizes,
DWARFAttributes& attributes,
uint32_t curr_depth) const
{
SymbolFileDWARF* dwarf2Data = nullptr;
const DWARFAbbreviationDeclaration* abbrevDecl = nullptr;
lldb::offset_t offset = 0;
if (cu)
{
if (m_tag != DW_TAG_compile_unit)
{
SymbolFileDWARFDwo* dwo_symbol_file = cu->GetDwoSymbolFile();
if (dwo_symbol_file)
return GetAttributes(dwo_symbol_file->GetCompileUnit(),
fixed_form_sizes,
attributes,
curr_depth);
}
dwarf2Data = cu->GetSymbolFileDWARF();
abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
}
if (abbrevDecl)
{
const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
if (fixed_form_sizes.Empty())
fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize(
cu->GetAddressByteSize(), cu->IsDWARF64());
const uint32_t num_attributes = abbrevDecl->NumAttributes();
uint32_t i;
dw_attr_t attr;
dw_form_t form;
for (i=0; i<num_attributes; ++i)
{
abbrevDecl->GetAttrAndFormByIndexUnchecked (i, attr, form);
// If we are tracking down DW_AT_specification or DW_AT_abstract_origin
// attributes, the depth will be non-zero. We need to omit certain
// attributes that don't make sense.
switch (attr)
{
case DW_AT_sibling:
case DW_AT_declaration:
if (curr_depth > 0)
{
// This attribute doesn't make sense when combined with
// the DIE that references this DIE. We know a DIE is
// referencing this DIE because curr_depth is not zero
break;
}
// Fall through...
default:
attributes.Append(cu, offset, attr, form);
break;
}
if ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin))
{
DWARFFormValue form_value (cu, form);
if (form_value.ExtractValue(debug_info_data, &offset))
{
dw_offset_t die_offset = form_value.Reference();
DWARFDIE spec_die = const_cast<DWARFCompileUnit*>(cu)->GetDIE(die_offset);
if (spec_die)
spec_die.GetAttributes(attributes, curr_depth + 1);
}
}
else
{
const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
if (fixed_skip_size)
offset += fixed_skip_size;
else
DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu);
}
}
}
else
{
attributes.Clear();
}
return attributes.Size();
}
//----------------------------------------------------------------------
// GetAttributeValue
//
// Get the value of an attribute and return the .debug_info offset of the
// attribute if it was properly extracted into form_value, or zero
// if we fail since an offset of zero is invalid for an attribute (it
// would be a compile unit header).
//----------------------------------------------------------------------
dw_offset_t
DWARFDebugInfoEntry::GetAttributeValue
(
SymbolFileDWARF* dwarf2Data,
const DWARFCompileUnit* cu,
const dw_attr_t attr,
DWARFFormValue& form_value,
dw_offset_t* end_attr_offset_ptr,
bool check_specification_or_abstract_origin
) const
{
SymbolFileDWARFDwo* dwo_symbol_file = cu->GetDwoSymbolFile();
if (dwo_symbol_file && m_tag != DW_TAG_compile_unit)