From 57d2f3d3802642ab8dcf1f8f6b340613885093bd Mon Sep 17 00:00:00 2001 From: Alastair Robertson Date: Fri, 11 Aug 2023 09:52:54 -0700 Subject: [PATCH] DrgnParser: Don't error out for certain bad DWARF Match the behaviour of CodeGen v1 and just log warnings when certain debug info has issues. --- oi/type_graph/DrgnParser.cpp | 57 ++++++++++++++++++++++++++---------- oi/type_graph/DrgnParser.h | 3 +- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/oi/type_graph/DrgnParser.cpp b/oi/type_graph/DrgnParser.cpp index 64ac748..21412b9 100644 --- a/oi/type_graph/DrgnParser.cpp +++ b/oi/type_graph/DrgnParser.cpp @@ -71,6 +71,10 @@ Primitive::Kind primitiveFloatKind(struct drgn_type* type) { } } +void warnForDrgnError(struct drgn_type* type, + const std::string& msg, + struct drgn_error* err); + } // namespace Type& DrgnParser::parse(struct drgn_type* root) { @@ -209,8 +213,9 @@ void DrgnParser::enumerateClassParents(struct drgn_type* type, struct drgn_error* err = drgn_template_parameter_type(&drgn_parents[i], &parent_qual_type); if (err) { - throw DrgnParserError{ - "Error looking up parent type (" + std::to_string(i) + ")", err}; + warnForDrgnError( + type, "Error looking up parent (" + std::to_string(i) + ")", err); + continue; } auto& ptype = enumerateType(parent_qual_type.type); @@ -237,8 +242,9 @@ void DrgnParser::enumerateClassMembers(struct drgn_type* type, struct drgn_error* err = drgn_member_type(&drgn_members[i], &member_qual_type, &bit_field_size); if (err) { - throw DrgnParserError{ - "Error looking up member type (" + std::to_string(i) + ")", err}; + warnForDrgnError( + type, "Error looking up member (" + std::to_string(i) + ")", err); + continue; } struct drgn_type* member_type = member_qual_type.type; @@ -272,14 +278,17 @@ void DrgnParser::enumerateClassMembers(struct drgn_type* type, }); } -void DrgnParser::enumerateTemplateParam(drgn_type_template_parameter* tparams, +void DrgnParser::enumerateTemplateParam(struct drgn_type* type, + drgn_type_template_parameter* tparams, size_t i, std::vector& params) { const drgn_object* obj = nullptr; if (auto* err = drgn_template_parameter_object(&tparams[i], &obj)) { - throw DrgnParserError{"Error looking up template parameter object (" + - std::to_string(i) + ")", - err}; + warnForDrgnError(type, + "Error looking up template parameter object (" + + std::to_string(i) + ")", + err); + return; } struct drgn_qualified_type tparamQualType; @@ -288,9 +297,11 @@ void DrgnParser::enumerateTemplateParam(drgn_type_template_parameter* tparams, struct drgn_error* err = drgn_template_parameter_type(&tparams[i], &tparamQualType); if (err) { - throw DrgnParserError{"Error looking up template parameter type (" + - std::to_string(i) + ")", - err}; + warnForDrgnError(type, + "Error looking up template parameter type (" + + std::to_string(i) + ")", + err); + return; } struct drgn_type* tparamType = tparamQualType.type; @@ -385,7 +396,7 @@ void DrgnParser::enumerateClassTemplateParams( struct drgn_type_template_parameter* tparams = drgn_type_template_parameters(type); for (size_t i = 0; i < numParams; i++) { - enumerateTemplateParam(tparams, i, params); + enumerateTemplateParam(type, tparams, i, params); } } @@ -399,10 +410,9 @@ void DrgnParser::enumerateClassFunctions(struct drgn_type* type, for (size_t i = 0; i < num_functions; i++) { drgn_qualified_type t{}; if (auto* err = drgn_member_function_type(&drgn_functions[i], &t)) { - LOG(WARNING) << "Error looking up member function (" + std::to_string(i) + - "): " + std::to_string(err->code) + " " + - err->message; - drgn_error_destroy(err); + warnForDrgnError( + type, "Error looking up member function (" + std::to_string(i) + ")", + err); continue; } @@ -500,4 +510,19 @@ DrgnParserError::~DrgnParserError() { drgn_error_destroy(err_); } +namespace { +void warnForDrgnError(struct drgn_type* type, + const std::string& msg, + struct drgn_error* err) { + const char* name = nullptr; + if (drgn_type_has_tag(type)) + name = drgn_type_tag(type); + else if (drgn_type_has_name(type)) + name = drgn_type_name(type); + LOG(WARNING) << msg << (name ? std::string{" for type '"} + name + "'" : "") + << ": " << err->code << " " << err->message; + drgn_error_destroy(err); +} +} // namespace + } // namespace oi::detail::type_graph diff --git a/oi/type_graph/DrgnParser.h b/oi/type_graph/DrgnParser.h index 7c3605a..d1fe224 100644 --- a/oi/type_graph/DrgnParser.h +++ b/oi/type_graph/DrgnParser.h @@ -67,7 +67,8 @@ class DrgnParser { Array& enumerateArray(struct drgn_type* type); Primitive& enumeratePrimitive(struct drgn_type* type); - void enumerateTemplateParam(drgn_type_template_parameter* tparams, + void enumerateTemplateParam(struct drgn_type* type, + drgn_type_template_parameter* tparams, size_t i, std::vector& params); void enumerateClassTemplateParams(struct drgn_type* type,