Skip to content

Commit

Permalink
Isolate drgn_type to CodeGenV1
Browse files Browse the repository at this point in the history
  • Loading branch information
ttreyer committed Dec 19, 2023
1 parent 233ce3c commit 1d752ca
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
5 changes: 5 additions & 0 deletions oi/Features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ std::optional<std::string_view> featureHelp(Feature f) {
return "Generate statistics on padding of structures.";
case Feature::CaptureThriftIsset:
return "Capture isset data for Thrift object.";
case Feature::LLDB:
return "Use LLDB (instead of drgn) to parse the debug info.";
case Feature::TypeGraph:
return "Use Type Graph for code generation (CodeGen v2).";
case Feature::PruneTypeGraph:
Expand All @@ -60,6 +62,9 @@ std::optional<std::string_view> featureHelp(Feature f) {

std::span<const Feature> requirements(Feature f) {
switch (f) {
case Feature::LLDB:
static constexpr std::array lldb = {Feature::TypeGraph};
return lldb;
case Feature::TreeBuilderV2:
static constexpr std::array tb2 = {Feature::TypeGraph};
return tb2;
Expand Down
1 change: 1 addition & 0 deletions oi/Features.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
X(PackStructs, "pack-structs") \
X(GenPaddingStats, "gen-padding-stats") \
X(CaptureThriftIsset, "capture-thrift-isset") \
X(LLDB, "lldb") \
X(TypeGraph, "type-graph") \
X(PruneTypeGraph, "prune-type-graph") \
X(Library, "library") \
Expand Down
24 changes: 18 additions & 6 deletions oi/OIDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2962,17 +2962,24 @@ bool OIDebugger::processTargetData() {
}

std::optional<std::string> OIDebugger::generateCode(const irequest& req) {
auto root = symbols->getRootType(req);
if (!root.has_value()) {
return std::nullopt;
}

std::string code(headers::oi_OITraceCode_cpp);

if (generatorConfig.features[Feature::TypeGraph]) {
// CodeGen v2
std::string rootVariableName;
CodeGen codegen2{generatorConfig, *symbols};
codegen2.codegenFromDrgn(root->type.type, code);
if (generatorConfig.features[Feature::LLDB]) {
throw std::runtime_error{"LLDB is not implemented yet"};
} else {
auto root = symbols->getDrgnRootType(req);
if (!root.has_value()) {
return std::nullopt;
}

rootVariableName = std::move(root->varName);
codegen2.codegenFromDrgn(root->type.type, code);
}

TypeHierarchy th;
// Make this static as a big hack to extend the fake drgn_types' lifetimes
Expand All @@ -2981,10 +2988,15 @@ std::optional<std::string> OIDebugger::generateCode(const irequest& req) {
drgn_type* rootType;
codegen2.exportDrgnTypes(th, drgnTypes, &rootType);

typeInfos[req] = {RootInfo{root->varName, {rootType, drgn_qualifiers{}}},
typeInfos[req] = {RootInfo{rootVariableName, {rootType, drgn_qualifiers{}}},
th,
std::map<std::string, PaddingInfo>{}};
} else {
auto root = symbols->getDrgnRootType(req);
if (!root.has_value()) {
return std::nullopt;
}

// OICodeGen (v1)
auto codegen = OICodeGen::buildFromConfig(generatorConfig, *symbols);
if (!codegen) {
Expand Down
2 changes: 1 addition & 1 deletion oi/SymbolService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ std::string SymbolService::getTypeName(struct drgn_type* type) {
return drgn_utils::typeToName(type);
}

std::optional<RootInfo> SymbolService::getRootType(const irequest& req) {
std::optional<RootInfo> SymbolService::getDrgnRootType(const irequest& req) {
if (req.type == "global") {
/*
* This is super simple as all we have to do is locate assign the
Expand Down
2 changes: 1 addition & 1 deletion oi/SymbolService.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SymbolService {
std::shared_ptr<FuncDesc> findFuncDesc(const irequest&);
std::shared_ptr<GlobalDesc> findGlobalDesc(const std::string&);
static std::string getTypeName(struct drgn_type*);
std::optional<RootInfo> getRootType(const irequest&);
std::optional<RootInfo> getDrgnRootType(const irequest&);

static std::optional<drgn_qualified_type> findTypeOfSymbol(
drgn_program*, const std::string& symbolName);
Expand Down
2 changes: 1 addition & 1 deletion test/test_drgn_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ DrgnParser DrgnParserTest::getDrgnParser(TypeGraph& typeGraph,

drgn_type* DrgnParserTest::getDrgnRoot(std::string_view function) {
irequest req{"entry", std::string{function}, "arg0"};
auto* drgnRoot = symbols_->getRootType(req)->type.type;
auto* drgnRoot = symbols_->getDrgnRootType(req)->type.type;
return drgnRoot;
}

Expand Down

0 comments on commit 1d752ca

Please sign in to comment.