1 //===-- DWARFASTParserOCaml.cpp ---------------------------------*- C++ -*-===//
3 #include "DWARFASTParserOCaml.h"
5 #include "lldb/Core/Module.h"
6 #include "lldb/Symbol/CompileUnit.h"
7 #include "lldb/Symbol/Function.h"
8 #include "lldb/Symbol/ObjectFile.h"
9 #include "lldb/Symbol/Type.h"
10 #include "lldb/Symbol/TypeList.h"
11 #include "lldb/Utility/Log.h"
12 #include "lldb/Utility/Status.h"
15 using namespace lldb_private;
17 DWARFASTParserOCaml::DWARFASTParserOCaml(OCamlASTContext &ast) : m_ast(ast) {}
19 DWARFASTParserOCaml::~DWARFASTParserOCaml() {}
21 TypeSP DWARFASTParserOCaml::ParseBaseTypeFromDIE(const DWARFDIE &die) {
22 SymbolFileDWARF *dwarf = die.GetDWARF();
23 dwarf->m_die_to_type[die.GetDIE()] = DIE_IS_BEING_PARSED;
25 ConstString type_name;
26 uint64_t byte_size = 0;
28 DWARFAttributes attributes;
29 const size_t num_attributes = die.GetAttributes(attributes);
30 for (uint32_t i = 0; i < num_attributes; ++i) {
31 DWARFFormValue form_value;
32 dw_attr_t attr = attributes.AttributeAtIndex(i);
33 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
36 type_name.SetCString(form_value.AsCString());
39 byte_size = form_value.Unsigned();
44 assert(false && "Unsupported attribute for DW_TAG_base_type");
50 CompilerType compiler_type = m_ast.CreateBaseType(type_name, byte_size);
51 return std::make_shared<Type>(die.GetID(), dwarf, type_name, byte_size,
52 nullptr, LLDB_INVALID_UID, Type::eEncodingIsUID,
53 decl, compiler_type, Type::eResolveStateFull);
56 lldb::TypeSP DWARFASTParserOCaml::ParseTypeFromDWARF(const SymbolContext &sc,
59 bool *type_is_new_ptr) {
61 *type_is_new_ptr = false;
66 SymbolFileDWARF *dwarf = die.GetDWARF();
68 Type *type_ptr = dwarf->m_die_to_type.lookup(die.GetDIE());
69 if (type_ptr == DIE_IS_BEING_PARSED)
71 if (type_ptr != nullptr)
72 return type_ptr->shared_from_this();
76 *type_is_new_ptr = true;
79 case DW_TAG_base_type: {
80 type_sp = ParseBaseTypeFromDIE(die);
83 case DW_TAG_array_type: {
86 case DW_TAG_class_type: {
89 case DW_TAG_reference_type: {
97 DWARFDIE sc_parent_die = SymbolFileDWARF::GetParentSymbolContextDIE(die);
98 dw_tag_t sc_parent_tag = sc_parent_die.Tag();
100 SymbolContextScope *symbol_context_scope = nullptr;
101 if (sc_parent_tag == DW_TAG_compile_unit) {
102 symbol_context_scope = sc.comp_unit;
103 } else if (sc.function != nullptr && sc_parent_die) {
104 symbol_context_scope =
105 sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID());
106 if (symbol_context_scope == nullptr)
107 symbol_context_scope = sc.function;
110 if (symbol_context_scope != nullptr)
111 type_sp->SetSymbolContextScope(symbol_context_scope);
113 dwarf->GetTypeList()->Insert(type_sp);
114 dwarf->m_die_to_type[die.GetDIE()] = type_sp.get();
119 Function *DWARFASTParserOCaml::ParseFunctionFromDWARF(const SymbolContext &sc,
120 const DWARFDIE &die) {
121 DWARFRangeList func_ranges;
122 const char *name = NULL;
123 const char *mangled = NULL;
130 DWARFExpression frame_base(die.GetCU());
132 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_LANGUAGE));
135 SymbolFileDWARF *dwarf = die.GetDWARF();
137 dwarf->GetObjectFile()->GetModule()->LogMessage(
138 log, "DWARFASTParserOCaml::ParseFunctionFromDWARF (die = 0x%8.8x) %s "
140 die.GetOffset(), DW_TAG_value_to_name(die.Tag()), die.GetName());
144 assert(die.Tag() == DW_TAG_subprogram);
146 if (die.Tag() != DW_TAG_subprogram)
149 if (die.GetDIENamesAndRanges(name, mangled, func_ranges, decl_file, decl_line,
150 decl_column, call_file, call_line, call_column,
152 AddressRange func_range;
153 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase(0);
154 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd(0);
155 if (lowest_func_addr != LLDB_INVALID_ADDRESS &&
156 lowest_func_addr <= highest_func_addr) {
157 ModuleSP module_sp(die.GetModule());
158 func_range.GetBaseAddress().ResolveAddressUsingFileSections(
159 lowest_func_addr, module_sp->GetSectionList());
160 if (func_range.GetBaseAddress().IsValid())
161 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
164 if (func_range.GetBaseAddress().IsValid()) {
167 func_name.SetValue(ConstString(name), true);
170 std::unique_ptr<Declaration> decl_ap;
171 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
172 decl_ap.reset(new Declaration(
173 sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
174 decl_line, decl_column));
176 SymbolFileDWARF *dwarf = die.GetDWARF();
177 Type *func_type = dwarf->m_die_to_type.lookup(die.GetDIE());
179 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
181 if (dwarf->FixupAddress(func_range.GetBaseAddress())) {
182 const user_id_t func_user_id = die.GetID();
183 func_sp.reset(new Function(sc.comp_unit,
184 func_user_id, // UserID is the DIE offset
185 func_user_id, func_name, func_type,
186 func_range)); // first address range
188 if (func_sp.get() != NULL) {
189 if (frame_base.IsValid())
190 func_sp->GetFrameBaseExpression() = frame_base;
191 sc.comp_unit->AddFunction(func_sp);
192 return func_sp.get();
201 lldb_private::CompilerDeclContext
202 DWARFASTParserOCaml::GetDeclContextForUIDFromDWARF(const DWARFDIE &die) {
203 return CompilerDeclContext();
206 lldb_private::CompilerDeclContext
207 DWARFASTParserOCaml::GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) {
208 return CompilerDeclContext();