-
Notifications
You must be signed in to change notification settings - Fork 10.8k
/
SymbolFileDWARF.cpp
4389 lines (3902 loc) · 170 KB
/
SymbolFileDWARF.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
//===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "SymbolFileDWARF.h"
// Other libraries and framework includes
#include "llvm/Support/Casting.h"
#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/RegularExpression.h"
#include "lldb/Core/Scalar.h"
#include "lldb/Core/Section.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/Timer.h"
#include "lldb/Core/Value.h"
#include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
#include "lldb/Interpreter/OptionValueFileSpecList.h"
#include "lldb/Interpreter/OptionValueProperties.h"
#include "lldb/Symbol/Block.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/CompilerDecl.h"
#include "lldb/Symbol/CompilerDeclContext.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Symbol/TypeMap.h"
#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
#include "Plugins/Language/ObjC/ObjCLanguage.h"
#include "lldb/Target/Language.h"
#include "lldb/Utility/TaskPool.h"
#include "DWARFASTParser.h"
#include "DWARFCompileUnit.h"
#include "DWARFDebugAbbrev.h"
#include "DWARFDebugAranges.h"
#include "DWARFDebugInfo.h"
#include "DWARFDebugLine.h"
#include "DWARFDebugPubnames.h"
#include "DWARFDebugRanges.h"
#include "DWARFDeclContext.h"
#include "DWARFDIECollection.h"
#include "DWARFFormValue.h"
#include "LogChannelDWARF.h"
#include "SymbolFileDWARFDwo.h"
#include "SymbolFileDWARFDebugMap.h"
#include <map>
#include <ctype.h>
#include <string.h>
//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
#ifdef ENABLE_DEBUG_PRINTF
#include <stdio.h>
#define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#define DEBUG_PRINTF(fmt, ...)
#endif
using namespace lldb;
using namespace lldb_private;
//static inline bool
//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
//{
// switch (tag)
// {
// default:
// break;
// case DW_TAG_subprogram:
// case DW_TAG_inlined_subroutine:
// case DW_TAG_class_type:
// case DW_TAG_structure_type:
// case DW_TAG_union_type:
// return true;
// }
// return false;
//}
//
namespace {
PropertyDefinition
g_properties[] =
{
{ "comp-dir-symlink-paths" , OptionValue::eTypeFileSpecList, true, 0 , nullptr, nullptr, "If the DW_AT_comp_dir matches any of these paths the symbolic links will be resolved at DWARF parse time." },
{ nullptr , OptionValue::eTypeInvalid , false, 0, nullptr, nullptr, nullptr }
};
enum
{
ePropertySymLinkPaths
};
class PluginProperties : public Properties
{
public:
static ConstString
GetSettingName()
{
return SymbolFileDWARF::GetPluginNameStatic();
}
PluginProperties()
{
m_collection_sp.reset (new OptionValueProperties(GetSettingName()));
m_collection_sp->Initialize(g_properties);
}
FileSpecList&
GetSymLinkPaths()
{
OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, true, ePropertySymLinkPaths);
assert(option_value);
return option_value->GetCurrentValue();
}
};
typedef std::shared_ptr<PluginProperties> SymbolFileDWARFPropertiesSP;
static const SymbolFileDWARFPropertiesSP&
GetGlobalPluginProperties()
{
static const auto g_settings_sp(std::make_shared<PluginProperties>());
return g_settings_sp;
}
} // anonymous namespace end
static const char*
removeHostnameFromPathname(const char* path_from_dwarf)
{
if (!path_from_dwarf || !path_from_dwarf[0])
{
return path_from_dwarf;
}
const char *colon_pos = strchr(path_from_dwarf, ':');
if (nullptr == colon_pos)
{
return path_from_dwarf;
}
const char *slash_pos = strchr(path_from_dwarf, '/');
if (slash_pos && (slash_pos < colon_pos))
{
return path_from_dwarf;
}
// check whether we have a windows path, and so the first character
// is a drive-letter not a hostname.
if (
colon_pos == path_from_dwarf + 1 &&
isalpha(*path_from_dwarf) &&
strlen(path_from_dwarf) > 2 &&
'\\' == path_from_dwarf[2])
{
return path_from_dwarf;
}
return colon_pos + 1;
}
static const char*
resolveCompDir(const char* path_from_dwarf)
{
if (!path_from_dwarf)
return nullptr;
// DWARF2/3 suggests the form hostname:pathname for compilation directory.
// Remove the host part if present.
const char* local_path = removeHostnameFromPathname(path_from_dwarf);
if (!local_path)
return nullptr;
bool is_symlink = false;
FileSpec local_path_spec(local_path, false);
const auto& file_specs = GetGlobalPluginProperties()->GetSymLinkPaths();
for (size_t i = 0; i < file_specs.GetSize() && !is_symlink; ++i)
is_symlink = FileSpec::Equal(file_specs.GetFileSpecAtIndex(i), local_path_spec, true);
if (!is_symlink)
return local_path;
if (!local_path_spec.IsSymbolicLink())
return local_path;
FileSpec resolved_local_path_spec;
const auto error = FileSystem::Readlink(local_path_spec, resolved_local_path_spec);
if (error.Success())
return resolved_local_path_spec.GetCString();
return nullptr;
}
void
SymbolFileDWARF::Initialize()
{
LogChannelDWARF::Initialize();
PluginManager::RegisterPlugin (GetPluginNameStatic(),
GetPluginDescriptionStatic(),
CreateInstance,
DebuggerInitialize);
}
void
SymbolFileDWARF::DebuggerInitialize(Debugger &debugger)
{
if (!PluginManager::GetSettingForSymbolFilePlugin(debugger, PluginProperties::GetSettingName()))
{
const bool is_global_setting = true;
PluginManager::CreateSettingForSymbolFilePlugin(debugger,
GetGlobalPluginProperties()->GetValueProperties(),
ConstString ("Properties for the dwarf symbol-file plug-in."),
is_global_setting);
}
}
void
SymbolFileDWARF::Terminate()
{
PluginManager::UnregisterPlugin (CreateInstance);
LogChannelDWARF::Initialize();
}
lldb_private::ConstString
SymbolFileDWARF::GetPluginNameStatic()
{
static ConstString g_name("dwarf");
return g_name;
}
const char *
SymbolFileDWARF::GetPluginDescriptionStatic()
{
return "DWARF and DWARF3 debug symbol file reader.";
}
SymbolFile*
SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
{
return new SymbolFileDWARF(obj_file);
}
TypeList *
SymbolFileDWARF::GetTypeList ()
{
if (GetDebugMapSymfile ())
return m_debug_map_symfile->GetTypeList();
return m_obj_file->GetModule()->GetTypeList();
}
void
SymbolFileDWARF::GetTypes (const DWARFDIE &die,
dw_offset_t min_die_offset,
dw_offset_t max_die_offset,
uint32_t type_mask,
TypeSet &type_set)
{
if (die)
{
const dw_offset_t die_offset = die.GetOffset();
if (die_offset >= max_die_offset)
return;
if (die_offset >= min_die_offset)
{
const dw_tag_t tag = die.Tag();
bool add_type = false;
switch (tag)
{
case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break;
case DW_TAG_unspecified_type:
case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break;
case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break;
case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break;
case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break;
case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break;
case DW_TAG_subroutine_type:
case DW_TAG_subprogram:
case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break;
case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break;
case DW_TAG_rvalue_reference_type:
case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break;
case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break;
case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break;
}
if (add_type)
{
const bool assert_not_being_parsed = true;
Type *type = ResolveTypeUID (die, assert_not_being_parsed);
if (type)
{
if (type_set.find(type) == type_set.end())
type_set.insert(type);
}
}
}
for (DWARFDIE child_die = die.GetFirstChild();
child_die.IsValid();
child_die = child_die.GetSibling())
{
GetTypes (child_die, min_die_offset, max_die_offset, type_mask, type_set);
}
}
}
size_t
SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope,
uint32_t type_mask,
TypeList &type_list)
{
TypeSet type_set;
CompileUnit *comp_unit = NULL;
DWARFCompileUnit* dwarf_cu = NULL;
if (sc_scope)
comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
if (comp_unit)
{
dwarf_cu = GetDWARFCompileUnit(comp_unit);
if (dwarf_cu == 0)
return 0;
GetTypes (dwarf_cu->DIE(),
dwarf_cu->GetOffset(),
dwarf_cu->GetNextCompileUnitOffset(),
type_mask,
type_set);
}
else
{
DWARFDebugInfo* info = DebugInfo();
if (info)
{
const size_t num_cus = info->GetNumCompileUnits();
for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx)
{
dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
if (dwarf_cu)
{
GetTypes (dwarf_cu->DIE(),
0,
UINT32_MAX,
type_mask,
type_set);
}
}
}
}
std::set<CompilerType> compiler_type_set;
size_t num_types_added = 0;
for (Type *type : type_set)
{
CompilerType compiler_type = type->GetForwardCompilerType ();
if (compiler_type_set.find(compiler_type) == compiler_type_set.end())
{
compiler_type_set.insert(compiler_type);
type_list.Insert (type->shared_from_this());
++num_types_added;
}
}
return num_types_added;
}
//----------------------------------------------------------------------
// Gets the first parent that is a lexical block, function or inlined
// subroutine, or compile unit.
//----------------------------------------------------------------------
DWARFDIE
SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDIE &child_die)
{
DWARFDIE die;
for (die = child_die.GetParent(); die; die = die.GetParent())
{
dw_tag_t tag = die.Tag();
switch (tag)
{
case DW_TAG_compile_unit:
case DW_TAG_subprogram:
case DW_TAG_inlined_subroutine:
case DW_TAG_lexical_block:
return die;
}
}
return DWARFDIE();
}
SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
SymbolFile (objfile),
UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID
m_debug_map_module_wp (),
m_debug_map_symfile (NULL),
m_data_debug_abbrev (),
m_data_debug_aranges (),
m_data_debug_frame (),
m_data_debug_info (),
m_data_debug_line (),
m_data_debug_loc (),
m_data_debug_ranges (),
m_data_debug_str (),
m_data_apple_names (),
m_data_apple_types (),
m_data_apple_namespaces (),
m_abbr(),
m_info(),
m_line(),
m_apple_names_ap (),
m_apple_types_ap (),
m_apple_namespaces_ap (),
m_apple_objc_ap (),
m_function_basename_index(),
m_function_fullname_index(),
m_function_method_index(),
m_function_selector_index(),
m_objc_class_selectors_index(),
m_global_index(),
m_type_index(),
m_namespace_index(),
m_indexed (false),
m_using_apple_tables (false),
m_fetched_external_modules (false),
m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
m_ranges(),
m_unique_ast_type_map ()
{
}
SymbolFileDWARF::~SymbolFileDWARF()
{
}
static const ConstString &
GetDWARFMachOSegmentName ()
{
static ConstString g_dwarf_section_name ("__DWARF");
return g_dwarf_section_name;
}
UniqueDWARFASTTypeMap &
SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
{
if (GetDebugMapSymfile ())
return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
return m_unique_ast_type_map;
}
TypeSystem *
SymbolFileDWARF::GetTypeSystemForLanguage (LanguageType language)
{
SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
TypeSystem *type_system;
if (debug_map_symfile)
{
type_system = debug_map_symfile->GetTypeSystemForLanguage(language);
}
else
{
type_system = m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
if (type_system)
type_system->SetSymbolFile(this);
}
return type_system;
}
void
SymbolFileDWARF::InitializeObject()
{
ModuleSP module_sp (m_obj_file->GetModule());
if (module_sp)
{
const SectionList *section_list = module_sp->GetSectionList();
const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
// Memory map the DWARF mach-o segment so we have everything mmap'ed
// to keep our heap memory usage down.
if (section)
m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
}
get_apple_names_data();
if (m_data_apple_names.m_data.GetByteSize() > 0)
{
m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names.m_data,
get_debug_str_data(),
".apple_names"));
if (m_apple_names_ap->IsValid())
m_using_apple_tables = true;
else
m_apple_names_ap.reset();
}
get_apple_types_data();
if (m_data_apple_types.m_data.GetByteSize() > 0)
{
m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types.m_data,
get_debug_str_data(),
".apple_types"));
if (m_apple_types_ap->IsValid())
m_using_apple_tables = true;
else
m_apple_types_ap.reset();
}
get_apple_namespaces_data();
if (m_data_apple_namespaces.m_data.GetByteSize() > 0)
{
m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces.m_data,
get_debug_str_data(),
".apple_namespaces"));
if (m_apple_namespaces_ap->IsValid())
m_using_apple_tables = true;
else
m_apple_namespaces_ap.reset();
}
get_apple_objc_data();
if (m_data_apple_objc.m_data.GetByteSize() > 0)
{
m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc.m_data,
get_debug_str_data(),
".apple_objc"));
if (m_apple_objc_ap->IsValid())
m_using_apple_tables = true;
else
m_apple_objc_ap.reset();
}
}
bool
SymbolFileDWARF::SupportedVersion(uint16_t version)
{
return version == 2 || version == 3 || version == 4;
}
uint32_t
SymbolFileDWARF::CalculateAbilities ()
{
uint32_t abilities = 0;
if (m_obj_file != NULL)
{
const Section* section = NULL;
const SectionList *section_list = m_obj_file->GetSectionList();
if (section_list == NULL)
return 0;
uint64_t debug_abbrev_file_size = 0;
uint64_t debug_info_file_size = 0;
uint64_t debug_line_file_size = 0;
section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
if (section)
section_list = §ion->GetChildren ();
section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
if (section != NULL)
{
debug_info_file_size = section->GetFileSize();
section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
if (section)
debug_abbrev_file_size = section->GetFileSize();
section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
if (section)
debug_line_file_size = section->GetFileSize();
}
else
{
const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
if (symfile_dir_cstr)
{
if (strcasestr(symfile_dir_cstr, ".dsym"))
{
if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
{
// We have a dSYM file that didn't have a any debug info.
// If the string table has a size of 1, then it was made from
// an executable with no debug info, or from an executable that
// was stripped.
section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
if (section && section->GetFileSize() == 1)
{
m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
}
}
}
}
}
if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
if (debug_line_file_size > 0)
abilities |= LineTables;
}
return abilities;
}
const DWARFDataExtractor&
SymbolFileDWARF::GetCachedSectionData (lldb::SectionType sect_type, DWARFDataSegment& data_segment)
{
std::call_once(data_segment.m_flag,
&SymbolFileDWARF::LoadSectionData,
this,
sect_type,
std::ref(data_segment.m_data));
return data_segment.m_data;
}
void
SymbolFileDWARF::LoadSectionData (lldb::SectionType sect_type, DWARFDataExtractor& data)
{
ModuleSP module_sp (m_obj_file->GetModule());
const SectionList *section_list = module_sp->GetSectionList();
if (section_list)
{
SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
if (section_sp)
{
// See if we memory mapped the DWARF segment?
if (m_dwarf_data.GetByteSize())
{
data.SetData(m_dwarf_data, section_sp->GetOffset(), section_sp->GetFileSize());
}
else
{
if (m_obj_file->ReadSectionData(section_sp.get(), data) == 0)
data.Clear();
}
}
}
}
const DWARFDataExtractor&
SymbolFileDWARF::get_debug_abbrev_data()
{
return GetCachedSectionData (eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
}
const DWARFDataExtractor&
SymbolFileDWARF::get_debug_addr_data()
{
return GetCachedSectionData (eSectionTypeDWARFDebugAddr, m_data_debug_addr);
}
const DWARFDataExtractor&
SymbolFileDWARF::get_debug_aranges_data()
{
return GetCachedSectionData (eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
}
const DWARFDataExtractor&
SymbolFileDWARF::get_debug_frame_data()
{
return GetCachedSectionData (eSectionTypeDWARFDebugFrame, m_data_debug_frame);
}
const DWARFDataExtractor&
SymbolFileDWARF::get_debug_info_data()
{
return GetCachedSectionData (eSectionTypeDWARFDebugInfo, m_data_debug_info);
}
const DWARFDataExtractor&
SymbolFileDWARF::get_debug_line_data()
{
return GetCachedSectionData (eSectionTypeDWARFDebugLine, m_data_debug_line);
}
const DWARFDataExtractor&
SymbolFileDWARF::get_debug_loc_data()
{
return GetCachedSectionData (eSectionTypeDWARFDebugLoc, m_data_debug_loc);
}
const DWARFDataExtractor&
SymbolFileDWARF::get_debug_ranges_data()
{
return GetCachedSectionData (eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
}
const DWARFDataExtractor&
SymbolFileDWARF::get_debug_str_data()
{
return GetCachedSectionData (eSectionTypeDWARFDebugStr, m_data_debug_str);
}
const DWARFDataExtractor&
SymbolFileDWARF::get_debug_str_offsets_data()
{
return GetCachedSectionData (eSectionTypeDWARFDebugStrOffsets, m_data_debug_str_offsets);
}
const DWARFDataExtractor&
SymbolFileDWARF::get_apple_names_data()
{
return GetCachedSectionData (eSectionTypeDWARFAppleNames, m_data_apple_names);
}
const DWARFDataExtractor&
SymbolFileDWARF::get_apple_types_data()
{
return GetCachedSectionData (eSectionTypeDWARFAppleTypes, m_data_apple_types);
}
const DWARFDataExtractor&
SymbolFileDWARF::get_apple_namespaces_data()
{
return GetCachedSectionData (eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
}
const DWARFDataExtractor&
SymbolFileDWARF::get_apple_objc_data()
{
return GetCachedSectionData (eSectionTypeDWARFAppleObjC, m_data_apple_objc);
}
DWARFDebugAbbrev*
SymbolFileDWARF::DebugAbbrev()
{
if (m_abbr.get() == NULL)
{
const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data();
if (debug_abbrev_data.GetByteSize() > 0)
{
m_abbr.reset(new DWARFDebugAbbrev());
if (m_abbr.get())
m_abbr->Parse(debug_abbrev_data);
}
}
return m_abbr.get();
}
const DWARFDebugAbbrev*
SymbolFileDWARF::DebugAbbrev() const
{
return m_abbr.get();
}
DWARFDebugInfo*
SymbolFileDWARF::DebugInfo()
{
if (m_info.get() == NULL)
{
Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
__PRETTY_FUNCTION__, static_cast<void*>(this));
if (get_debug_info_data().GetByteSize() > 0)
{
m_info.reset(new DWARFDebugInfo());
if (m_info.get())
{
m_info->SetDwarfData(this);
}
}
}
return m_info.get();
}
const DWARFDebugInfo*
SymbolFileDWARF::DebugInfo() const
{
return m_info.get();
}
DWARFCompileUnit*
SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
{
if (!comp_unit)
return nullptr;
DWARFDebugInfo* info = DebugInfo();
if (info)
{
if (GetDebugMapSymfile ())
{
// The debug map symbol file made the compile units for this DWARF
// file which is .o file with DWARF in it, and we should have
// only 1 compile unit which is at offset zero in the DWARF.
// TODO: modify to support LTO .o files where each .o file might
// have multiple DW_TAG_compile_unit tags.
DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0);
if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
dwarf_cu->SetUserData(comp_unit);
return dwarf_cu;
}
else
{
// Just a normal DWARF file whose user ID for the compile unit is
// the DWARF offset itself
DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID());
if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
dwarf_cu->SetUserData(comp_unit);
return dwarf_cu;
}
}
return NULL;
}
DWARFDebugRanges*
SymbolFileDWARF::DebugRanges()
{
if (m_ranges.get() == NULL)
{
Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
__PRETTY_FUNCTION__, static_cast<void*>(this));
if (get_debug_ranges_data().GetByteSize() > 0)
{
m_ranges.reset(new DWARFDebugRanges());
if (m_ranges.get())
m_ranges->Extract(this);
}
}
return m_ranges.get();
}
const DWARFDebugRanges*
SymbolFileDWARF::DebugRanges() const
{
return m_ranges.get();
}
lldb::CompUnitSP
SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
{
CompUnitSP cu_sp;
if (dwarf_cu)
{
CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
if (comp_unit)
{
// We already parsed this compile unit, had out a shared pointer to it
cu_sp = comp_unit->shared_from_this();
}
else
{
if (dwarf_cu->GetSymbolFileDWARF() != this)
{
return dwarf_cu->GetSymbolFileDWARF()->ParseCompileUnit(dwarf_cu, cu_idx);
}
else if (GetDebugMapSymfile ())
{
// Let the debug map create the compile unit
cu_sp = m_debug_map_symfile->GetCompileUnit(this);
dwarf_cu->SetUserData(cu_sp.get());
}
else
{
ModuleSP module_sp (m_obj_file->GetModule());
if (module_sp)
{
const DWARFDIE cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
if (cu_die)
{
FileSpec cu_file_spec{cu_die.GetName(), false};
if (cu_file_spec)
{
// If we have a full path to the compile unit, we don't need to resolve
// the file. This can be expensive e.g. when the source files are NFS mounted.
if (cu_file_spec.IsRelative())
{
const char *cu_comp_dir{cu_die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr)};
cu_file_spec.PrependPathComponent(resolveCompDir(cu_comp_dir));
}
std::string remapped_file;
if (module_sp->RemapSourceFile(cu_file_spec.GetCString(), remapped_file))
cu_file_spec.SetFile(remapped_file, false);
}
LanguageType cu_language = DWARFCompileUnit::LanguageTypeFromDWARF(cu_die.GetAttributeValueAsUnsigned(DW_AT_language, 0));
bool is_optimized = dwarf_cu->GetIsOptimized ();
cu_sp.reset(new CompileUnit (module_sp,
dwarf_cu,
cu_file_spec,
dwarf_cu->GetID(),
cu_language,
is_optimized));
if (cu_sp)
{
// If we just created a compile unit with an invalid file spec, try and get the
// first entry in the supports files from the line table as that should be the
// compile unit.
if (!cu_file_spec)
{
cu_file_spec = cu_sp->GetSupportFiles().GetFileSpecAtIndex(1);
if (cu_file_spec)
{
(FileSpec &)(*cu_sp) = cu_file_spec;
// Also fix the invalid file spec which was copied from the compile unit.
cu_sp->GetSupportFiles().Replace(0, cu_file_spec);
}
}
dwarf_cu->SetUserData(cu_sp.get());
// Figure out the compile unit index if we weren't given one
if (cu_idx == UINT32_MAX)
DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
}
}
}
}
}
}
return cu_sp;
}
uint32_t
SymbolFileDWARF::GetNumCompileUnits()
{
DWARFDebugInfo* info = DebugInfo();
if (info)
return info->GetNumCompileUnits();
return 0;
}
CompUnitSP
SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
{
CompUnitSP cu_sp;
DWARFDebugInfo* info = DebugInfo();
if (info)
{
DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
if (dwarf_cu)
cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
}
return cu_sp;
}
Function *
SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, const DWARFDIE &die)
{
if (die.IsValid())
{
TypeSystem *type_system = GetTypeSystemForLanguage(die.GetCU()->GetLanguageType());
if (type_system)
{
DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
if (dwarf_ast)
return dwarf_ast->ParseFunctionFromDWARF(sc, die);
}
}
return nullptr;
}
bool
SymbolFileDWARF::FixupAddress (Address &addr)
{