Skip to content

Commit 1d752ca

Browse files
committed
Isolate drgn_type to CodeGenV1
1 parent 233ce3c commit 1d752ca

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

oi/Features.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ std::optional<std::string_view> featureHelp(Feature f) {
3636
return "Generate statistics on padding of structures.";
3737
case Feature::CaptureThriftIsset:
3838
return "Capture isset data for Thrift object.";
39+
case Feature::LLDB:
40+
return "Use LLDB (instead of drgn) to parse the debug info.";
3941
case Feature::TypeGraph:
4042
return "Use Type Graph for code generation (CodeGen v2).";
4143
case Feature::PruneTypeGraph:
@@ -60,6 +62,9 @@ std::optional<std::string_view> featureHelp(Feature f) {
6062

6163
std::span<const Feature> requirements(Feature f) {
6264
switch (f) {
65+
case Feature::LLDB:
66+
static constexpr std::array lldb = {Feature::TypeGraph};
67+
return lldb;
6368
case Feature::TreeBuilderV2:
6469
static constexpr std::array tb2 = {Feature::TypeGraph};
6570
return tb2;

oi/Features.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
X(PackStructs, "pack-structs") \
2828
X(GenPaddingStats, "gen-padding-stats") \
2929
X(CaptureThriftIsset, "capture-thrift-isset") \
30+
X(LLDB, "lldb") \
3031
X(TypeGraph, "type-graph") \
3132
X(PruneTypeGraph, "prune-type-graph") \
3233
X(Library, "library") \

oi/OIDebugger.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2962,17 +2962,24 @@ bool OIDebugger::processTargetData() {
29622962
}
29632963

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

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

29722968
if (generatorConfig.features[Feature::TypeGraph]) {
29732969
// CodeGen v2
2970+
std::string rootVariableName;
29742971
CodeGen codegen2{generatorConfig, *symbols};
2975-
codegen2.codegenFromDrgn(root->type.type, code);
2972+
if (generatorConfig.features[Feature::LLDB]) {
2973+
throw std::runtime_error{"LLDB is not implemented yet"};
2974+
} else {
2975+
auto root = symbols->getDrgnRootType(req);
2976+
if (!root.has_value()) {
2977+
return std::nullopt;
2978+
}
2979+
2980+
rootVariableName = std::move(root->varName);
2981+
codegen2.codegenFromDrgn(root->type.type, code);
2982+
}
29762983

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

2984-
typeInfos[req] = {RootInfo{root->varName, {rootType, drgn_qualifiers{}}},
2991+
typeInfos[req] = {RootInfo{rootVariableName, {rootType, drgn_qualifiers{}}},
29852992
th,
29862993
std::map<std::string, PaddingInfo>{}};
29872994
} else {
2995+
auto root = symbols->getDrgnRootType(req);
2996+
if (!root.has_value()) {
2997+
return std::nullopt;
2998+
}
2999+
29883000
// OICodeGen (v1)
29893001
auto codegen = OICodeGen::buildFromConfig(generatorConfig, *symbols);
29903002
if (!codegen) {

oi/SymbolService.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ std::string SymbolService::getTypeName(struct drgn_type* type) {
804804
return drgn_utils::typeToName(type);
805805
}
806806

807-
std::optional<RootInfo> SymbolService::getRootType(const irequest& req) {
807+
std::optional<RootInfo> SymbolService::getDrgnRootType(const irequest& req) {
808808
if (req.type == "global") {
809809
/*
810810
* This is super simple as all we have to do is locate assign the

oi/SymbolService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class SymbolService {
5454
std::shared_ptr<FuncDesc> findFuncDesc(const irequest&);
5555
std::shared_ptr<GlobalDesc> findGlobalDesc(const std::string&);
5656
static std::string getTypeName(struct drgn_type*);
57-
std::optional<RootInfo> getRootType(const irequest&);
57+
std::optional<RootInfo> getDrgnRootType(const irequest&);
5858

5959
static std::optional<drgn_qualified_type> findTypeOfSymbol(
6060
drgn_program*, const std::string& symbolName);

test/test_drgn_parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ DrgnParser DrgnParserTest::getDrgnParser(TypeGraph& typeGraph,
3535

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

0 commit comments

Comments
 (0)