[lldb][NFC] Extract array type parsing from DWARFASTParserClang::ParseTypeFromDWARF

Part of the work to split up this monolithic parsing function.
This commit is contained in:
Raphael Isemann 2019-11-26 11:27:22 +01:00
parent e54c83ec4d
commit e8013ef53a
2 changed files with 95 additions and 84 deletions

View File

@ -1201,6 +1201,31 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
} break; } break;
case DW_TAG_array_type: { case DW_TAG_array_type: {
type_sp = ParseArrayType(die, attrs);
break;
}
case DW_TAG_ptr_to_member_type: {
type_sp = ParsePointerToMemberType(die, attrs);
break;
}
default:
dwarf->GetObjectFile()->GetModule()->ReportError(
"{0x%8.8x}: unhandled type tag 0x%4.4x (%s), please file a bug and "
"attach the file at the start of this error message",
die.GetOffset(), tag, DW_TAG_value_to_name(tag));
break;
}
// TODO: We should consider making the switch above exhaustive to simplify
// control flow in ParseTypeFromDWARF. Then, we could simply replace this
// return statement with a call to llvm_unreachable.
return UpdateSymbolContextScopeForType(sc, die, type_sp);
}
TypeSP DWARFASTParserClang::ParseArrayType(const DWARFDIE &die,
ParsedDWARFTypeAttributes &attrs) {
SymbolFileDWARF *dwarf = die.GetDWARF();
DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(),
DW_TAG_value_to_name(tag), type_name_cstr); DW_TAG_value_to_name(tag), type_name_cstr);
@ -1236,8 +1261,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
"forward declaration, not a complete definition.\nPlease " "forward declaration, not a complete definition.\nPlease "
"file a bug against the compiler and include the " "file a bug against the compiler and include the "
"preprocessed output for %s", "preprocessed output for %s",
die.GetOffset(), type_die.GetOffset(), die.GetOffset(), type_die.GetOffset(), GetUnitName(die).c_str());
GetUnitName(die).c_str());
} }
// We have no choice other than to pretend that the element class // We have no choice other than to pretend that the element class
@ -1245,8 +1269,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
// trying to layout the class. Since we provide layout // trying to layout the class. Since we provide layout
// assistance, all ivars in this class and other classes will be // assistance, all ivars in this class and other classes will be
// fine, this is the best we can do short of crashing. // fine, this is the best we can do short of crashing.
if (ClangASTContext::StartTagDeclarationDefinition( if (ClangASTContext::StartTagDeclarationDefinition(array_element_type)) {
array_element_type)) {
ClangASTContext::CompleteTagDeclarationDefinition(array_element_type); ClangASTContext::CompleteTagDeclarationDefinition(array_element_type);
} else { } else {
module_sp->ReportError("DWARF DIE at 0x%8.8x was not able to " module_sp->ReportError("DWARF DIE at 0x%8.8x was not able to "
@ -1259,48 +1282,33 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
uint64_t array_element_bit_stride = uint64_t array_element_bit_stride =
attrs.byte_stride * 8 + attrs.bit_stride; attrs.byte_stride * 8 + attrs.bit_stride;
CompilerType clang_type;
if (array_info && array_info->element_orders.size() > 0) { if (array_info && array_info->element_orders.size() > 0) {
uint64_t num_elements = 0; uint64_t num_elements = 0;
auto end = array_info->element_orders.rend(); auto end = array_info->element_orders.rend();
for (auto pos = array_info->element_orders.rbegin(); pos != end; for (auto pos = array_info->element_orders.rbegin(); pos != end; ++pos) {
++pos) {
num_elements = *pos; num_elements = *pos;
clang_type = m_ast.CreateArrayType(array_element_type, num_elements, clang_type = m_ast.CreateArrayType(array_element_type, num_elements,
attrs.is_vector); attrs.is_vector);
array_element_type = clang_type; array_element_type = clang_type;
array_element_bit_stride = array_element_bit_stride = num_elements
num_elements ? array_element_bit_stride * num_elements ? array_element_bit_stride * num_elements
: array_element_bit_stride; : array_element_bit_stride;
} }
} else { } else {
clang_type = m_ast.CreateArrayType(array_element_type, 0, attrs.is_vector); clang_type =
m_ast.CreateArrayType(array_element_type, 0, attrs.is_vector);
} }
ConstString empty_name; ConstString empty_name;
type_sp = std::make_shared<Type>( TypeSP type_sp = std::make_shared<Type>(
die.GetID(), dwarf, empty_name, array_element_bit_stride / 8, nullptr, die.GetID(), dwarf, empty_name, array_element_bit_stride / 8, nullptr,
dwarf->GetUID(type_die), Type::eEncodingIsUID, &attrs.decl, dwarf->GetUID(type_die), Type::eEncodingIsUID, &attrs.decl, clang_type,
clang_type, Type::ResolveState::Full); Type::ResolveState::Full);
type_sp->SetEncodingType(element_type); type_sp->SetEncodingType(element_type);
m_ast.SetMetadataAsUserID(clang_type.GetOpaqueQualType(), die.GetID()); m_ast.SetMetadataAsUserID(clang_type.GetOpaqueQualType(), die.GetID());
return type_sp;
} }
} break; return nullptr;
case DW_TAG_ptr_to_member_type: {
type_sp = ParsePointerToMemberType(die, attrs);
break;
}
default:
dwarf->GetObjectFile()->GetModule()->ReportError(
"{0x%8.8x}: unhandled type tag 0x%4.4x (%s), please file a bug and "
"attach the file at the start of this error message",
die.GetOffset(), tag, DW_TAG_value_to_name(tag));
break;
}
// TODO: We should consider making the switch above exhaustive to simplify
// control flow in ParseTypeFromDWARF. Then, we could simply replace this
// return statement with a call to llvm_unreachable.
return UpdateSymbolContextScopeForType(sc, die, type_sp);
} }
TypeSP DWARFASTParserClang::ParsePointerToMemberType( TypeSP DWARFASTParserClang::ParsePointerToMemberType(

View File

@ -170,6 +170,9 @@ protected:
lldb::ModuleSP GetModuleForType(const DWARFDIE &die); lldb::ModuleSP GetModuleForType(const DWARFDIE &die);
private: private:
// FIXME: attrs should be passed as a const reference.
lldb::TypeSP ParseArrayType(const DWARFDIE &die,
ParsedDWARFTypeAttributes &attrs);
lldb::TypeSP ParsePointerToMemberType(const DWARFDIE &die, lldb::TypeSP ParsePointerToMemberType(const DWARFDIE &die,
const ParsedDWARFTypeAttributes &attrs); const ParsedDWARFTypeAttributes &attrs);
}; };