Skip to content

Commit 0330ef8

Browse files
committed
Take list of pass-through types from config instead of hardcoding
As we now store ContainerInfo objects in OICodeGen::Config, we can not copy it any more. Change all places that took copies to take const references instead. The copy in OICodeGen modified membersToStub, the contents of which form part of OICache's hash. However, as OICache also previously had its own copy, it would not have been OICodeGen's modifications.
1 parent e86ebb7 commit 0330ef8

15 files changed

+92
-62
lines changed

dev.oid.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,8 @@ containers = [
4747
"PWD/types/thrift_isset_type.toml",
4848
"PWD/types/weak_ptr_type.toml",
4949
]
50+
pass_through = [
51+
["std::allocator", "memory"],
52+
["std::char_traits", "string"],
53+
["folly::fbstring_core", "folly/FBString.h"],
54+
]

oi/CodeGen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,15 +712,16 @@ void CodeGen::addDrgnRoot(struct drgn_type* drgnType,
712712
void CodeGen::transform(type_graph::TypeGraph& typeGraph) {
713713
type_graph::PassManager pm;
714714
pm.addPass(type_graph::Flattener::createPass());
715-
pm.addPass(type_graph::TypeIdentifier::createPass());
715+
pm.addPass(type_graph::TypeIdentifier::createPass(config_.passThroughTypes));
716716
if (config_.features[Feature::PolymorphicInheritance]) {
717717
type_graph::DrgnParser drgnParser{
718718
typeGraph, containerInfos_,
719719
config_.features[Feature::ChaseRawPointers]};
720720
pm.addPass(type_graph::AddChildren::createPass(drgnParser, symbols_));
721721
// Re-run passes over newly added children
722722
pm.addPass(type_graph::Flattener::createPass());
723-
pm.addPass(type_graph::TypeIdentifier::createPass());
723+
pm.addPass(
724+
type_graph::TypeIdentifier::createPass(config_.passThroughTypes));
724725
}
725726
pm.addPass(type_graph::RemoveIgnored::createPass(config_.membersToStub));
726727
pm.addPass(type_graph::AddPadding::createPass());

oi/CodeGen.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class TypeGraph;
3737

3838
class CodeGen {
3939
public:
40-
CodeGen(OICodeGen::Config& config, SymbolService& symbols)
40+
CodeGen(const OICodeGen::Config& config, SymbolService& symbols)
4141
: config_(config), symbols_(symbols) {
4242
}
4343

@@ -58,7 +58,7 @@ class CodeGen {
5858
);
5959

6060
private:
61-
OICodeGen::Config config_;
61+
const OICodeGen::Config& config_;
6262
SymbolService& symbols_;
6363
std::vector<ContainerInfo> containerInfos_;
6464
std::unordered_set<const ContainerInfo*> definedContainers_;

oi/OICache.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ namespace fs = std::filesystem;
2828

2929
class OICache {
3030
public:
31+
OICache(const OICodeGen::Config& generatorConfig)
32+
: generatorConfig(generatorConfig) {
33+
}
34+
3135
fs::path basePath{};
3236
std::shared_ptr<SymbolService> symbols{};
3337
bool downloadedRemote = false;
@@ -37,7 +41,7 @@ class OICache {
3741

3842
// We need the generator config to download the cache
3943
// with the matching configuration.
40-
OICodeGen::Config generatorConfig{};
44+
const OICodeGen::Config& generatorConfig;
4145

4246
// Entity is used to index the `extensions` array
4347
// So we must keep the Entity enum and `extensions` array in sync!

oi/OICodeGen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ OICodeGen::OICodeGen(const Config& c, SymbolService& s)
8989
"event",
9090
};
9191

92-
config.membersToStub.reserve(typesToStub.size());
92+
membersToStub = config.membersToStub;
9393
for (const auto& type : typesToStub) {
94-
config.membersToStub.emplace_back(type, "*");
94+
membersToStub.emplace_back(type, "*");
9595
}
9696

9797
// `knownTypes` has been made obsolete by the introduction of using the
@@ -1269,10 +1269,10 @@ bool OICodeGen::generateMemberDefinition(drgn_type* type,
12691269
std::optional<std::pair<std::string_view, std::string_view>>
12701270
OICodeGen::isMemberToStub(const std::string& typeName,
12711271
const std::string& member) {
1272-
auto it = std::ranges::find_if(config.membersToStub, [&](auto& s) {
1272+
auto it = std::ranges::find_if(membersToStub, [&](auto& s) {
12731273
return typeName.starts_with(s.first) && s.second == member;
12741274
});
1275-
if (it == std::end(config.membersToStub)) {
1275+
if (it == std::end(membersToStub)) {
12761276
return std::nullopt;
12771277
}
12781278
return *it;

oi/OICodeGen.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,19 @@ struct ParentMember {
5151
class OICodeGen {
5252
public:
5353
struct Config {
54-
/*
55-
* Note: don't set default values for the config so the user gets an
56-
* uninitialized field" warning if they missed any.
57-
*/
58-
bool useDataSegment;
59-
60-
FeatureSet features{};
54+
Config() = default;
55+
Config(const Config& other) = delete;
56+
Config& operator=(const Config& other) = delete;
57+
Config(Config&& other) = delete;
58+
Config& operator=(Config&& other) = delete;
6159

62-
std::set<fs::path> containerConfigPaths{};
63-
std::set<std::string> defaultHeaders{};
64-
std::set<std::string> defaultNamespaces{};
65-
std::vector<std::pair<std::string, std::string>> membersToStub{};
60+
bool useDataSegment;
61+
FeatureSet features;
62+
std::set<fs::path> containerConfigPaths;
63+
std::set<std::string> defaultHeaders;
64+
std::set<std::string> defaultNamespaces;
65+
std::vector<std::pair<std::string, std::string>> membersToStub;
66+
std::vector<ContainerInfo> passThroughTypes;
6667

6768
std::string toString() const;
6869
std::vector<std::string> toOptions() const;
@@ -108,7 +109,7 @@ class OICodeGen {
108109
bool isDynamic(drgn_type* type) const;
109110

110111
private:
111-
Config config{};
112+
const Config& config;
112113
FuncGen funcGen;
113114

114115
using ContainerTypeMapEntry =
@@ -152,6 +153,7 @@ class OICodeGen {
152153
std::map<drgn_type*, drgn_type*> pointerToTypeMap;
153154
std::set<drgn_type*> thriftIssetStructTypes;
154155
std::vector<drgn_type*> topoSortedStructTypes;
156+
std::vector<std::pair<std::string, std::string>> membersToStub;
155157

156158
ContainerInfoRefSet containerTypesFuncDef;
157159

oi/OID.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,10 +655,9 @@ int main(int argc, char* argv[]) {
655655

656656
OICompiler::Config compilerConfig{};
657657

658-
OICodeGen::Config codeGenConfig{
659-
.useDataSegment = true,
660-
.features = {}, // fill in after processing the config file
661-
};
658+
OICodeGen::Config codeGenConfig;
659+
codeGenConfig.useDataSegment = true;
660+
codeGenConfig.features = {}; // fill in after processing the config file
662661

663662
TreeBuilder::Config tbConfig{
664663
.features = {}, // fill in after processing the config file

oi/OIDebugger.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,24 +1878,23 @@ bool OIDebugger::removeTrap(pid_t pid, const trapInfo& t) {
18781878
return true;
18791879
}
18801880

1881-
OIDebugger::OIDebugger(OICodeGen::Config genConfig,
1881+
OIDebugger::OIDebugger(const OICodeGen::Config& genConfig,
18821882
OICompiler::Config ccConfig,
18831883
TreeBuilder::Config tbConfig)
1884-
: compilerConfig{std::move(ccConfig)},
1885-
generatorConfig{std::move(genConfig)},
1884+
: cache{genConfig},
1885+
compilerConfig{std::move(ccConfig)},
1886+
generatorConfig{genConfig},
18861887
treeBuilderConfig{std::move(tbConfig)} {
18871888
debug = true;
18881889

1889-
cache.generatorConfig = generatorConfig;
18901890
VLOG(1) << "CodeGen config: " << generatorConfig.toString();
18911891
}
18921892

18931893
OIDebugger::OIDebugger(pid_t pid,
1894-
OICodeGen::Config genConfig,
1894+
const OICodeGen::Config& genConfig,
18951895
OICompiler::Config ccConfig,
18961896
TreeBuilder::Config tbConfig)
1897-
: OIDebugger(
1898-
std::move(genConfig), std::move(ccConfig), std::move(tbConfig)) {
1897+
: OIDebugger(genConfig, std::move(ccConfig), std::move(tbConfig)) {
18991898
traceePid = pid;
19001899
symbols = std::make_shared<SymbolService>(traceePid);
19011900
setDataSegmentSize(dataSegSize);
@@ -1904,11 +1903,10 @@ OIDebugger::OIDebugger(pid_t pid,
19041903
}
19051904

19061905
OIDebugger::OIDebugger(fs::path debugInfo,
1907-
OICodeGen::Config genConfig,
1906+
const OICodeGen::Config& genConfig,
19081907
OICompiler::Config ccConfig,
19091908
TreeBuilder::Config tbConfig)
1910-
: OIDebugger(
1911-
std::move(genConfig), std::move(ccConfig), std::move(tbConfig)) {
1909+
: OIDebugger(genConfig, std::move(ccConfig), std::move(tbConfig)) {
19121910
symbols = std::make_shared<SymbolService>(std::move(debugInfo));
19131911
cache.symbols = symbols;
19141912
}
@@ -2699,8 +2697,6 @@ void OIDebugger::setDataSegmentSize(size_t size) {
26992697
int pgsz = getpagesize();
27002698
dataSegSize = ((size + pgsz - 1) & ~(pgsz - 1));
27012699

2702-
generatorConfig.useDataSegment = dataSegSize > 0;
2703-
27042700
VLOG(1) << "setDataSegmentSize: segment size: " << dataSegSize;
27052701
}
27062702

oi/OIDebugger.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@
3232
namespace fs = std::filesystem;
3333

3434
class OIDebugger {
35-
OIDebugger(OICodeGen::Config, OICompiler::Config, TreeBuilder::Config);
35+
OIDebugger(const OICodeGen::Config&, OICompiler::Config, TreeBuilder::Config);
3636

3737
public:
38-
OIDebugger(pid_t, OICodeGen::Config, OICompiler::Config, TreeBuilder::Config);
38+
OIDebugger(pid_t,
39+
const OICodeGen::Config&,
40+
OICompiler::Config,
41+
TreeBuilder::Config);
3942
OIDebugger(fs::path,
40-
OICodeGen::Config,
43+
const OICodeGen::Config&,
4144
OICompiler::Config,
4245
TreeBuilder::Config);
4346

@@ -170,7 +173,7 @@ class OIDebugger {
170173
const int replayInstSize = 512;
171174
bool trapsRemoved{false};
172175
std::shared_ptr<SymbolService> symbols;
173-
OICache cache{};
176+
OICache cache;
174177

175178
/*
176179
* Map address of valid INT3 instruction to metadata for that interrupt.
@@ -231,7 +234,7 @@ class OIDebugger {
231234
std::optional<std::vector<uintptr_t>> findRetLocs(FuncDesc&);
232235

233236
OICompiler::Config compilerConfig{};
234-
OICodeGen::Config generatorConfig{};
237+
const OICodeGen::Config& generatorConfig;
235238
TreeBuilder::Config treeBuilderConfig{};
236239
std::optional<std::string> generateCode(const irequest&);
237240

oi/OIUtils.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,25 @@ std::optional<ObjectIntrospection::FeatureSet> processConfigFile(
8484
}
8585
});
8686
}
87+
if (toml::array* arr = (*types)["pass_through"].as_array()) {
88+
for (auto&& el : *arr) {
89+
auto* type = el.as_array();
90+
if (type && type->size() == 2 && (*type)[0].is_string() &&
91+
(*type)[1].is_string()) {
92+
std::string name = (*type)[0].as_string()->get();
93+
std::string header = (*type)[1].as_string()->get();
94+
generatorConfig.passThroughTypes.emplace_back(
95+
std::move(name), DUMMY_TYPE, std::move(header));
96+
} else {
97+
LOG(ERROR) << "pass_through elements must be lists of [type_name, "
98+
"header_file]";
99+
return {};
100+
}
101+
}
102+
} else {
103+
LOG(ERROR) << "pass_through must be a list";
104+
return {};
105+
}
87106
}
88107

89108
if (toml::table* headers = config["headers"].as_table()) {

0 commit comments

Comments
 (0)