clang-format: set BinPackParameters=false

This commit is contained in:
Jake Hillion 2023-04-18 10:02:37 -07:00 committed by Jake Hillion
parent 789fb7ef6e
commit 4a64fc5c9c
26 changed files with 241 additions and 113 deletions

View File

@ -8,3 +8,4 @@ AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false AllowShortLoopsOnASingleLine: false
DerivePointerAlignment: false DerivePointerAlignment: false
PointerAlignment: Left PointerAlignment: Left
BinPackParameters: false

View File

@ -54,7 +54,9 @@ void Metrics::save(std::string object) {
} }
} }
void Metrics::saveArg(const char* name, const char* argName, ArgTiming timing, void Metrics::saveArg(const char* name,
const char* argName,
ArgTiming timing,
size_t size) { size_t size) {
std::string out = "{\"type\": \"size\", \"traceName\": \""; std::string out = "{\"type\": \"size\", \"traceName\": \"";
out += name; out += name;

View File

@ -58,7 +58,9 @@ class Metrics {
} }
static void save(std::string object); static void save(std::string object);
static void saveArg(const char* name, const char* argName, ArgTiming timing, static void saveArg(const char* name,
const char* argName,
ArgTiming timing,
size_t size); size_t size);
static void saveDuration(const char* name, static void saveDuration(const char* name,
std::chrono::milliseconds duration); std::chrono::milliseconds duration);

View File

@ -145,8 +145,10 @@ class CodegenHandler {
return lib->getObjectSize((void*)&objectAddr, objectSize); return lib->getObjectSize((void*)&objectAddr, objectSize);
} }
static int getObjectSize(const T& objectAddr, size_t& objectSize, static int getObjectSize(const T& objectAddr,
const options& opts, bool checkOptions = true) { size_t& objectSize,
const options& opts,
bool checkOptions = true) {
OILibrary* lib; OILibrary* lib;
if (int responseCode = getLibrary(lib, opts, checkOptions); if (int responseCode = getLibrary(lib, opts, checkOptions);
responseCode != Response::OIL_SUCCESS) { responseCode != Response::OIL_SUCCESS) {
@ -180,7 +182,8 @@ class CodegenHandler {
return Response::OIL_SUCCESS; return Response::OIL_SUCCESS;
} }
static int getLibrary(OILibrary*& result, const options& opts, static int getLibrary(OILibrary*& result,
const options& opts,
bool checkOptions) { bool checkOptions) {
std::atomic<OILibrary*>* curBoxedLib = getBoxedLib()->load(); std::atomic<OILibrary*>* curBoxedLib = getBoxedLib()->load();
@ -224,7 +227,9 @@ class CodegenHandler {
* Ahead-Of-Time (AOT) compilation. * Ahead-Of-Time (AOT) compilation.
*/ */
template <class T> template <class T>
int getObjectSize(const T& objectAddr, size_t& objectSize, const options& opts, int getObjectSize(const T& objectAddr,
size_t& objectSize,
const options& opts,
bool checkOptions = true) { bool checkOptions = true) {
return CodegenHandler<T>::getObjectSize(objectAddr, objectSize, opts, return CodegenHandler<T>::getObjectSize(objectAddr, objectSize, opts,
checkOptions); checkOptions);

View File

@ -36,9 +36,11 @@ struct ContainerInfo {
ContainerInfo& operator=(const ContainerInfo& other) = delete; ContainerInfo& operator=(const ContainerInfo& other) = delete;
ContainerInfo() = default; ContainerInfo() = default;
ContainerInfo(std::string typeName_, std::regex matcher_, ContainerInfo(std::string typeName_,
std::regex matcher_,
std::optional<size_t> numTemplateParams_, std::optional<size_t> numTemplateParams_,
ContainerTypeEnum ctype_, std::string header_, ContainerTypeEnum ctype_,
std::string header_,
std::vector<std::string> ns_, std::vector<std::string> ns_,
std::vector<size_t> replaceTemplateParamIndex_, std::vector<size_t> replaceTemplateParamIndex_,
std::optional<size_t> allocatorIndex_, std::optional<size_t> allocatorIndex_,

View File

@ -98,7 +98,8 @@ const char* symbol::name(drgn_symbol* sym) {
namespace drgn_utils { namespace drgn_utils {
void getDrgnArrayElementType(drgn_type* type, drgn_type** outElemType, void getDrgnArrayElementType(drgn_type* type,
drgn_type** outElemType,
size_t& outNumElems) { size_t& outNumElems) {
size_t elems = 1; size_t elems = 1;

View File

@ -137,7 +137,8 @@ namespace drgn_utils {
* data can be moved here. * data can be moved here.
*/ */
void getDrgnArrayElementType(drgn_type* type, drgn_type** outElemType, void getDrgnArrayElementType(drgn_type* type,
drgn_type** outElemType,
size_t& outNumElems); size_t& outNumElems);
std::string typeToName(drgn_type* type); std::string typeToName(drgn_type* type);

View File

@ -330,7 +330,8 @@ std::string OICodeGen::stripFullyQualifiedNameWithSeparators(
// Replace a specific template parameter with a generic DummySizedOperator // Replace a specific template parameter with a generic DummySizedOperator
void OICodeGen::replaceTemplateOperator( void OICodeGen::replaceTemplateOperator(
TemplateParamList& template_params, TemplateParamList& template_params,
std::vector<std::string>& template_params_strings, size_t index) { std::vector<std::string>& template_params_strings,
size_t index) {
if (index >= template_params.size()) { if (index >= template_params.size()) {
// Should this happen? // Should this happen?
return; return;
@ -365,7 +366,8 @@ void OICodeGen::replaceTemplateOperator(
} }
void OICodeGen::replaceTemplateParameters( void OICodeGen::replaceTemplateParameters(
drgn_type* type, TemplateParamList& template_params, drgn_type* type,
TemplateParamList& template_params,
std::vector<std::string>& template_params_strings, std::vector<std::string>& template_params_strings,
const std::string& nameWithoutTemplate) { const std::string& nameWithoutTemplate) {
auto optContainerInfo = getContainerInfo(type); auto optContainerInfo = getContainerInfo(type);
@ -393,7 +395,8 @@ void OICodeGen::replaceTemplateParameters(
} }
} }
bool OICodeGen::buildName(drgn_type* type, std::string& text, bool OICodeGen::buildName(drgn_type* type,
std::string& text,
std::string& outName) { std::string& outName) {
int ptrDepth = 0; int ptrDepth = 0;
drgn_type* ut = type; drgn_type* ut = type;
@ -418,7 +421,8 @@ bool OICodeGen::buildName(drgn_type* type, std::string& text,
return true; return true;
} }
bool OICodeGen::buildNameInt(drgn_type* type, std::string& nameWithoutTemplate, bool OICodeGen::buildNameInt(drgn_type* type,
std::string& nameWithoutTemplate,
std::string& outName) { std::string& outName) {
// Calling buildName only makes sense if a type is a container and has // Calling buildName only makes sense if a type is a container and has
// template parameters. For a generic template class, we just flatten the // template parameters. For a generic template class, we just flatten the
@ -588,7 +592,8 @@ bool OICodeGen::buildNameInt(drgn_type* type, std::string& nameWithoutTemplate,
} }
bool OICodeGen::getTemplateParams( bool OICodeGen::getTemplateParams(
drgn_type* type, size_t numTemplateParams, drgn_type* type,
size_t numTemplateParams,
std::vector<std::pair<drgn_qualified_type, std::string>>& v) { std::vector<std::pair<drgn_qualified_type, std::string>>& v) {
drgn_type_template_parameter* tParams = drgn_type_template_parameters(type); drgn_type_template_parameter* tParams = drgn_type_template_parameters(type);
@ -1662,8 +1667,10 @@ std::optional<std::string> OICodeGen::getNameForType(drgn_type* type) {
} }
void OICodeGen::getFuncDefClassMembers( void OICodeGen::getFuncDefClassMembers(
std::string& code, drgn_type* type, std::string& code,
std::unordered_map<std::string, int>& memberNames, bool skipPadding) { drgn_type* type,
std::unordered_map<std::string, int>& memberNames,
bool skipPadding) {
if (drgn_type_kind(type) == DRGN_TYPE_TYPEDEF) { if (drgn_type_kind(type) == DRGN_TYPE_TYPEDEF) {
// Handle case where parent is a typedef // Handle case where parent is a typedef
getFuncDefClassMembers(code, drgnUnderlyingType(type), memberNames); getFuncDefClassMembers(code, drgnUnderlyingType(type), memberNames);
@ -1761,7 +1768,8 @@ void OICodeGen::enumerateDescendants(drgn_type* type, drgn_type* baseType) {
} }
} }
void OICodeGen::getFuncDefinitionStr(std::string& code, drgn_type* type, void OICodeGen::getFuncDefinitionStr(std::string& code,
drgn_type* type,
const std::string& typeName) { const std::string& typeName) {
if (classMembersMap.find(type) == classMembersMap.end()) { if (classMembersMap.find(type) == classMembersMap.end()) {
return; return;
@ -2380,8 +2388,10 @@ bool OICodeGen::addPadding(uint64_t padding_bits, std::string& code) {
return true; return true;
} }
static inline void addSizeComment(bool genPaddingStats, std::string& code, static inline void addSizeComment(bool genPaddingStats,
size_t offset, size_t sizeInBits) { std::string& code,
size_t offset,
size_t sizeInBits) {
if (!genPaddingStats) { if (!genPaddingStats) {
return; return;
} }
@ -2417,8 +2427,10 @@ void OICodeGen::deduplicateMemberName(
std::optional<uint64_t> OICodeGen::generateMember( std::optional<uint64_t> OICodeGen::generateMember(
const DrgnClassMemberInfo& m, const DrgnClassMemberInfo& m,
std::unordered_map<std::string, int>& memberNames, uint64_t currOffsetBits, std::unordered_map<std::string, int>& memberNames,
std::string& code, bool isInUnion) { uint64_t currOffsetBits,
std::string& code,
bool isInUnion) {
// Generate unique name for member // Generate unique name for member
std::string memberName = m.member_name; std::string memberName = m.member_name;
deduplicateMemberName(memberNames, memberName); deduplicateMemberName(memberNames, memberName);
@ -2513,8 +2525,11 @@ std::optional<uint64_t> OICodeGen::generateMember(
} }
bool OICodeGen::generateParent( bool OICodeGen::generateParent(
drgn_type* p, std::unordered_map<std::string, int>& memberNames, drgn_type* p,
uint64_t& currOffsetBits, std::string& code, size_t offsetToNextMember) { std::unordered_map<std::string, int>& memberNames,
uint64_t& currOffsetBits,
std::string& code,
size_t offsetToNextMember) {
// Parent class could be a typedef // Parent class could be a typedef
PaddingInfo paddingInfo{}; PaddingInfo paddingInfo{};
bool violatesAlignmentRequirement = false; bool violatesAlignmentRequirement = false;
@ -2606,9 +2621,13 @@ std::optional<uint64_t> OICodeGen::getAlignmentRequirements(drgn_type* e) {
} }
bool OICodeGen::generateStructMembers( bool OICodeGen::generateStructMembers(
drgn_type* e, std::unordered_map<std::string, int>& memberNames, drgn_type* e,
std::string& code, uint64_t& out_offset_bits, PaddingInfo& paddingInfo, std::unordered_map<std::string, int>& memberNames,
bool& violatesAlignmentRequirement, size_t offsetToNextMemberInSubclass) { std::string& code,
uint64_t& out_offset_bits,
PaddingInfo& paddingInfo,
bool& violatesAlignmentRequirement,
size_t offsetToNextMemberInSubclass) {
if (classMembersMap.find(e) == classMembersMap.end()) { if (classMembersMap.find(e) == classMembersMap.end()) {
VLOG(1) << "Failed to find type in classMembersMap: " << e; VLOG(1) << "Failed to find type in classMembersMap: " << e;
} }
@ -3632,8 +3651,10 @@ bool OICodeGen::generate(std::string& code) {
* Generate static_asserts for the offsets of each member of the given type * Generate static_asserts for the offsets of each member of the given type
*/ */
bool OICodeGen::staticAssertMemberOffsets( bool OICodeGen::staticAssertMemberOffsets(
const std::string& struct_name, drgn_type* struct_type, const std::string& struct_name,
std::string& assert_str, std::unordered_map<std::string, int>& memberNames, drgn_type* struct_type,
std::string& assert_str,
std::unordered_map<std::string, int>& memberNames,
uint64_t base_offset) { uint64_t base_offset) {
if (knownDummyTypeList.find(struct_type) != knownDummyTypeList.end()) { if (knownDummyTypeList.find(struct_type) != knownDummyTypeList.end()) {
return true; return true;

View File

@ -224,7 +224,8 @@ class OICodeGen {
bool isKnownType(const std::string& type, std::string& matched); bool isKnownType(const std::string& type, std::string& matched);
static bool getTemplateParams( static bool getTemplateParams(
drgn_type* type, size_t numTemplateParams, drgn_type* type,
size_t numTemplateParams,
std::vector<std::pair<drgn_qualified_type, std::string>>& v); std::vector<std::pair<drgn_qualified_type, std::string>>& v);
bool enumerateTemplateParamIdxs(drgn_type* type, bool enumerateTemplateParamIdxs(drgn_type* type,
@ -233,7 +234,8 @@ class OICodeGen {
bool& ifStub); bool& ifStub);
bool getContainerTemplateParams(drgn_type* type, bool& ifStub); bool getContainerTemplateParams(drgn_type* type, bool& ifStub);
void enumerateDescendants(drgn_type* type, drgn_type* baseType); void enumerateDescendants(drgn_type* type, drgn_type* baseType);
void getFuncDefinitionStr(std::string& code, drgn_type* type, void getFuncDefinitionStr(std::string& code,
drgn_type* type,
const std::string& typeName); const std::string& typeName);
std::optional<uint64_t> getDrgnTypeSize(drgn_type* type); std::optional<uint64_t> getDrgnTypeSize(drgn_type* type);
@ -251,19 +253,24 @@ class OICodeGen {
std::optional<uint64_t> generateMember( std::optional<uint64_t> generateMember(
const DrgnClassMemberInfo& m, const DrgnClassMemberInfo& m,
std::unordered_map<std::string, int>& memberNames, std::unordered_map<std::string, int>& memberNames,
uint64_t currOffsetBits, std::string& code, bool isInUnion); uint64_t currOffsetBits,
std::string& code,
bool isInUnion);
bool generateParent(drgn_type* p, bool generateParent(drgn_type* p,
std::unordered_map<std::string, int>& memberNames, std::unordered_map<std::string, int>& memberNames,
uint64_t& currOffsetBits, std::string& code, uint64_t& currOffsetBits,
std::string& code,
size_t offsetToNextMember); size_t offsetToNextMember);
std::optional<uint64_t> getAlignmentRequirements(drgn_type* e); std::optional<uint64_t> getAlignmentRequirements(drgn_type* e);
bool generateStructMembers(drgn_type* e, bool generateStructMembers(drgn_type* e,
std::unordered_map<std::string, int>& memberNames, std::unordered_map<std::string, int>& memberNames,
std::string& code, uint64_t& out_offset_bits, std::string& code,
uint64_t& out_offset_bits,
PaddingInfo& paddingInfo, PaddingInfo& paddingInfo,
bool& violatesAlignmentRequirement, bool& violatesAlignmentRequirement,
size_t offsetToNextMember); size_t offsetToNextMember);
void getFuncDefClassMembers(std::string& code, drgn_type* type, void getFuncDefClassMembers(std::string& code,
drgn_type* type,
std::unordered_map<std::string, int>& memberNames, std::unordered_map<std::string, int>& memberNames,
bool skipPadding = false); bool skipPadding = false);
bool isDrgnSizeComplete(drgn_type* type); bool isDrgnSizeComplete(drgn_type* type);
@ -274,7 +281,8 @@ class OICodeGen {
bool ifEnumerateClass(const std::string& typeName); bool ifEnumerateClass(const std::string& typeName);
bool enumerateClassParents(drgn_type* type, const std::string& typeName); bool enumerateClassParents(drgn_type* type, const std::string& typeName);
bool enumerateClassMembers(drgn_type* type, const std::string& typeName, bool enumerateClassMembers(drgn_type* type,
const std::string& typeName,
bool& isStubbed); bool& isStubbed);
bool enumerateClassTemplateParams(drgn_type* type, bool enumerateClassTemplateParams(drgn_type* type,
const std::string& typeName, const std::string& typeName,
@ -308,17 +316,21 @@ class OICodeGen {
void getClassMembersIncludingParent(drgn_type* type, void getClassMembersIncludingParent(drgn_type* type,
std::vector<DrgnClassMemberInfo>& out); std::vector<DrgnClassMemberInfo>& out);
bool staticAssertMemberOffsets( bool staticAssertMemberOffsets(
const std::string& struct_name, drgn_type* struct_type, const std::string& struct_name,
drgn_type* struct_type,
std::string& assert_str, std::string& assert_str,
std::unordered_map<std::string, int>& member_names, std::unordered_map<std::string, int>& member_names,
uint64_t base_offset = 0); uint64_t base_offset = 0);
bool addStaticAssertsForType(drgn_type* type, bool generateAssertsForOffsets, bool addStaticAssertsForType(drgn_type* type,
bool generateAssertsForOffsets,
std::string& code); std::string& code);
bool buildNameInt(drgn_type* type, std::string& nameWithoutTemplate, bool buildNameInt(drgn_type* type,
std::string& nameWithoutTemplate,
std::string& outName); std::string& outName);
void replaceTemplateOperator( void replaceTemplateOperator(
std::vector<std::pair<drgn_qualified_type, std::string>>& template_params, std::vector<std::pair<drgn_qualified_type, std::string>>& template_params,
std::vector<std::string>& template_params_strings, size_t index); std::vector<std::string>& template_params_strings,
size_t index);
void replaceTemplateParameters( void replaceTemplateParameters(
drgn_type* type, drgn_type* type,
std::vector<std::pair<drgn_qualified_type, std::string>>& template_params, std::vector<std::pair<drgn_qualified_type, std::string>>& template_params,

View File

@ -53,8 +53,10 @@ using namespace llvm::object;
using namespace ObjectIntrospection; using namespace ObjectIntrospection;
static const char* symbolLookupCallback( static const char* symbolLookupCallback(
[[maybe_unused]] void* disInfo, [[maybe_unused]] uint64_t referenceValue, [[maybe_unused]] void* disInfo,
uint64_t* referenceType, [[maybe_unused]] uint64_t referencePC, [[maybe_unused]] uint64_t referenceValue,
uint64_t* referenceType,
[[maybe_unused]] uint64_t referencePC,
[[maybe_unused]] const char** referenceName) { [[maybe_unused]] const char** referenceName) {
*referenceType = LLVMDisassembler_ReferenceType_InOut_None; *referenceType = LLVMDisassembler_ReferenceType_InOut_None;
return nullptr; return nullptr;
@ -233,13 +235,15 @@ class OIMemoryManager : public RTDyldMemoryManager {
bool needsToReserveAllocationSpace(void) override { bool needsToReserveAllocationSpace(void) override {
return true; return true;
} }
void reserveAllocationSpace(uintptr_t, uint32_t, uintptr_t, uint32_t, void reserveAllocationSpace(
uintptr_t, uint32_t) override; uintptr_t, uint32_t, uintptr_t, uint32_t, uintptr_t, uint32_t) override;
uint8_t* allocateCodeSection(uintptr_t, unsigned, unsigned, uint8_t* allocateCodeSection(uintptr_t,
unsigned,
unsigned,
StringRef) override; StringRef) override;
uint8_t* allocateDataSection(uintptr_t, unsigned, unsigned, StringRef, uint8_t* allocateDataSection(
bool) override; uintptr_t, unsigned, unsigned, StringRef, bool) override;
/* Hook to set up proper memory permission. We don't handle that */ /* Hook to set up proper memory permission. We don't handle that */
bool finalizeMemory(std::string*) override { bool finalizeMemory(std::string*) override {
@ -268,9 +272,12 @@ class OIMemoryManager : public RTDyldMemoryManager {
} }
}; };
void OIMemoryManager::reserveAllocationSpace( void OIMemoryManager::reserveAllocationSpace(uintptr_t codeSize,
uintptr_t codeSize, uint32_t codeAlign, uintptr_t roDataSize, uint32_t codeAlign,
uint32_t roDataAlign, uintptr_t rwDataSize, uint32_t rwDataAlign) { uintptr_t roDataSize,
uint32_t roDataAlign,
uintptr_t rwDataSize,
uint32_t rwDataAlign) {
/* /*
* It looks like the sizes given to us already take into account the * It looks like the sizes given to us already take into account the
* alignment restrictions the different type of sections may have. Aligning * alignment restrictions the different type of sections may have. Aligning
@ -294,7 +301,9 @@ void OIMemoryManager::reserveAllocationSpace(
} }
uint8_t* OIMemoryManager::allocateCodeSection( uint8_t* OIMemoryManager::allocateCodeSection(
uintptr_t size, unsigned alignment, [[maybe_unused]] unsigned sectionID, uintptr_t size,
unsigned alignment,
[[maybe_unused]] unsigned sectionID,
StringRef sectionName) { StringRef sectionName) {
VLOG(1) << "allocateCodeSection(Size = " << size VLOG(1) << "allocateCodeSection(Size = " << size
<< ", Alignment = " << alignment << ", Alignment = " << alignment
@ -304,8 +313,11 @@ uint8_t* OIMemoryManager::allocateCodeSection(
} }
uint8_t* OIMemoryManager::allocateDataSection( uint8_t* OIMemoryManager::allocateDataSection(
uintptr_t size, unsigned alignment, [[maybe_unused]] unsigned sectionID, uintptr_t size,
StringRef sectionName, [[maybe_unused]] bool isReadOnly) { unsigned alignment,
[[maybe_unused]] unsigned sectionID,
StringRef sectionName,
[[maybe_unused]] bool isReadOnly) {
VLOG(1) << "allocateDataSection(Size = " << size VLOG(1) << "allocateDataSection(Size = " << size
<< ", Alignment = " << alignment << ", Alignment = " << alignment
<< ", SectionName = " << sectionName.data() << ")"; << ", SectionName = " << sectionName.data() << ")";
@ -451,7 +463,8 @@ static void debugDisAsm(
} }
} }
bool OICompiler::compile(const std::string& code, const fs::path& sourcePath, bool OICompiler::compile(const std::string& code,
const fs::path& sourcePath,
const fs::path& objectPath) { const fs::path& objectPath) {
Metrics::Tracing _("compile"); Metrics::Tracing _("compile");
@ -554,7 +567,8 @@ bool OICompiler::compile(const std::string& code, const fs::path& sourcePath,
} }
std::optional<OICompiler::RelocResult> OICompiler::applyRelocs( std::optional<OICompiler::RelocResult> OICompiler::applyRelocs(
uintptr_t baseRelocAddress, const std::set<fs::path>& objectFiles, uintptr_t baseRelocAddress,
const std::set<fs::path>& objectFiles,
const std::unordered_map<std::string, uintptr_t>& syntheticSymbols) { const std::unordered_map<std::string, uintptr_t>& syntheticSymbols) {
Metrics::Tracing relocationTracing("relocation"); Metrics::Tracing relocationTracing("relocation");

View File

@ -157,7 +157,8 @@ class OICompiler {
* another call. * another call.
*/ */
std::optional<RelocResult> applyRelocs( std::optional<RelocResult> applyRelocs(
uintptr_t, const std::set<fs::path>&, uintptr_t,
const std::set<fs::path>&,
const std::unordered_map<std::string, uintptr_t>&); const std::unordered_map<std::string, uintptr_t>&);
/** /**

View File

@ -282,8 +282,10 @@ struct Config {
} // namespace Oid } // namespace Oid
static ExitStatus::ExitStatus runScript( static ExitStatus::ExitStatus runScript(
const std::string& fileName, std::istream& script, const std::string& fileName,
const Oid::Config& oidConfig, const OICodeGen::Config& codeGenConfig, std::istream& script,
const Oid::Config& oidConfig,
const OICodeGen::Config& codeGenConfig,
const OICompiler::Config& compilerConfig, const OICompiler::Config& compilerConfig,
const TreeBuilder::Config& tbConfig) { const TreeBuilder::Config& tbConfig) {
if (!fileName.empty()) { if (!fileName.empty()) {

View File

@ -143,7 +143,8 @@ uint64_t OIDebugger::singlestepInst(pid_t pid, struct user_regs_struct& regs) {
return regs.rip; return regs.rip;
} }
void OIDebugger::dumpRegs(const char* text, pid_t pid, void OIDebugger::dumpRegs(const char* text,
pid_t pid,
struct user_regs_struct* regs) { struct user_regs_struct* regs) {
VLOG(1) << "(" << text << ")" VLOG(1) << "(" << text << ")"
<< " dumpRegs: pid: " << std::dec << pid << std::hex << " rip " << " dumpRegs: pid: " << std::dec << pid << std::hex << " rip "
@ -457,7 +458,8 @@ bool OIDebugger::contTargetThread(bool detach) const {
return true; return true;
} }
bool OIDebugger::replayTrappedInstr(const trapInfo& t, pid_t pid, bool OIDebugger::replayTrappedInstr(const trapInfo& t,
pid_t pid,
struct user_regs_struct& regs, struct user_regs_struct& regs,
struct user_fpregs_struct& fpregs) const { struct user_fpregs_struct& fpregs) const {
/* /*
@ -558,7 +560,9 @@ bool OIDebugger::locateObjectsAddresses(const trapInfo& tInfo,
} }
OIDebugger::processTrapRet OIDebugger::processFuncTrap( OIDebugger::processTrapRet OIDebugger::processFuncTrap(
const trapInfo& tInfo, pid_t pid, struct user_regs_struct& regs, const trapInfo& tInfo,
pid_t pid,
struct user_regs_struct& regs,
struct user_fpregs_struct& fpregs) { struct user_fpregs_struct& fpregs) {
assert(tInfo.trapKind != OID_TRAP_JITCODERET); assert(tInfo.trapKind != OID_TRAP_JITCODERET);
@ -904,7 +908,8 @@ bool OIDebugger::canProcessTrapForThread(pid_t thread_pid) const {
* (default) we wait for any thread to stop, if false we wait for the thread * (default) we wait for any thread to stop, if false we wait for the thread
* specified by the first parameter 'pid' to stop. * specified by the first parameter 'pid' to stop.
*/ */
OIDebugger::processTrapRet OIDebugger::processTrap(pid_t pid, bool blocking, OIDebugger::processTrapRet OIDebugger::processTrap(pid_t pid,
bool blocking,
bool anyPid) { bool anyPid) {
int status = 0; int status = 0;
pid_t newpid = 0; pid_t newpid = 0;
@ -1868,7 +1873,8 @@ bool OIDebugger::removeTrap(pid_t pid, const trapInfo& t) {
return true; return true;
} }
OIDebugger::OIDebugger(OICodeGen::Config genConfig, OICompiler::Config ccConfig, OIDebugger::OIDebugger(OICodeGen::Config genConfig,
OICompiler::Config ccConfig,
TreeBuilder::Config tbConfig) TreeBuilder::Config tbConfig)
: compilerConfig{std::move(ccConfig)}, : compilerConfig{std::move(ccConfig)},
generatorConfig{std::move(genConfig)}, generatorConfig{std::move(genConfig)},
@ -1879,11 +1885,12 @@ OIDebugger::OIDebugger(OICodeGen::Config genConfig, OICompiler::Config ccConfig,
VLOG(1) << "CodeGen config: " << generatorConfig.toString(); VLOG(1) << "CodeGen config: " << generatorConfig.toString();
} }
OIDebugger::OIDebugger(pid_t pid, OICodeGen::Config genConfig, OIDebugger::OIDebugger(pid_t pid,
OICodeGen::Config genConfig,
OICompiler::Config ccConfig, OICompiler::Config ccConfig,
TreeBuilder::Config tbConfig) TreeBuilder::Config tbConfig)
: OIDebugger(std::move(genConfig), std::move(ccConfig), : OIDebugger(
std::move(tbConfig)) { std::move(genConfig), std::move(ccConfig), std::move(tbConfig)) {
traceePid = pid; traceePid = pid;
symbols = std::make_shared<SymbolService>(traceePid); symbols = std::make_shared<SymbolService>(traceePid);
setDataSegmentSize(dataSegSize); setDataSegmentSize(dataSegSize);
@ -1891,11 +1898,12 @@ OIDebugger::OIDebugger(pid_t pid, OICodeGen::Config genConfig,
cache.symbols = symbols; cache.symbols = symbols;
} }
OIDebugger::OIDebugger(fs::path debugInfo, OICodeGen::Config genConfig, OIDebugger::OIDebugger(fs::path debugInfo,
OICodeGen::Config genConfig,
OICompiler::Config ccConfig, OICompiler::Config ccConfig,
TreeBuilder::Config tbConfig) TreeBuilder::Config tbConfig)
: OIDebugger(std::move(genConfig), std::move(ccConfig), : OIDebugger(
std::move(tbConfig)) { std::move(genConfig), std::move(ccConfig), std::move(tbConfig)) {
symbols = std::make_shared<SymbolService>(std::move(debugInfo)); symbols = std::make_shared<SymbolService>(std::move(debugInfo));
cache.symbols = symbols; cache.symbols = symbols;
} }
@ -1910,7 +1918,8 @@ OIDebugger::OIDebugger(fs::path debugInfo, OICodeGen::Config genConfig,
* @param[in] target_addr - target address where new data are to be written * @param[in] target_addr - target address where new data are to be written
* @param[in] bufsz - length of 'target_addr' buffer in bytes * @param[in] bufsz - length of 'target_addr' buffer in bytes
*/ */
bool OIDebugger::writeTargetMemory(void* local_buffer, void* target_addr, bool OIDebugger::writeTargetMemory(void* local_buffer,
void* target_addr,
size_t bufsz) const { size_t bufsz) const {
VLOG(1) << "Writing buffer " << std::hex << local_buffer << ", bufsz " VLOG(1) << "Writing buffer " << std::hex << local_buffer << ", bufsz "
<< std::dec << bufsz << " into target " << std::hex << target_addr; << std::dec << bufsz << " into target " << std::hex << target_addr;
@ -1953,7 +1962,8 @@ bool OIDebugger::writeTargetMemory(void* local_buffer, void* target_addr,
* @param[in] local_addr - local address where new data are to be written * @param[in] local_addr - local address where new data are to be written
* @param[in] bufsz - length of 'local_addr' buffer in bytes * @param[in] bufsz - length of 'local_addr' buffer in bytes
*/ */
bool OIDebugger::readTargetMemory(void* remote_buffer, void* local_addr, bool OIDebugger::readTargetMemory(void* remote_buffer,
void* local_addr,
size_t bufsz) const { size_t bufsz) const {
VLOG(1) << "Reading buffer " << std::hex << remote_buffer << ", bufsz " VLOG(1) << "Reading buffer " << std::hex << remote_buffer << ", bufsz "
<< std::dec << bufsz << " into local " << std::hex << local_addr; << std::dec << bufsz << " into local " << std::hex << local_addr;

View File

@ -36,7 +36,9 @@ class OIDebugger {
public: public:
OIDebugger(pid_t, OICodeGen::Config, OICompiler::Config, TreeBuilder::Config); OIDebugger(pid_t, OICodeGen::Config, OICompiler::Config, TreeBuilder::Config);
OIDebugger(fs::path, OICodeGen::Config, OICompiler::Config, OIDebugger(fs::path,
OICodeGen::Config,
OICompiler::Config,
TreeBuilder::Config); TreeBuilder::Config);
bool segmentInit(void); bool segmentInit(void);
@ -186,8 +188,9 @@ class OIDebugger {
std::unordered_map<pid_t, std::shared_ptr<trapInfo>> threadTrapState; std::unordered_map<pid_t, std::shared_ptr<trapInfo>> threadTrapState;
std::unordered_map<uintptr_t, uintptr_t> replayInstMap; std::unordered_map<uintptr_t, uintptr_t> replayInstMap;
std::unordered_map<irequest, std::tuple<RootInfo, TypeHierarchy, std::unordered_map<
std::map<std::string, PaddingInfo>>> irequest,
std::tuple<RootInfo, TypeHierarchy, std::map<std::string, PaddingInfo>>>
typeInfos; typeInfos;
template <typename Sys, typename... Args> template <typename Sys, typename... Args>
@ -217,10 +220,13 @@ class OIDebugger {
const uint64_t); const uint64_t);
bool functionPatch(const prequest&); bool functionPatch(const prequest&);
bool canProcessTrapForThread(pid_t) const; bool canProcessTrapForThread(pid_t) const;
bool replayTrappedInstr(const trapInfo&, pid_t, struct user_regs_struct&, bool replayTrappedInstr(const trapInfo&,
pid_t,
struct user_regs_struct&,
struct user_fpregs_struct&) const; struct user_fpregs_struct&) const;
bool locateObjectsAddresses(const trapInfo&, struct user_regs_struct&); bool locateObjectsAddresses(const trapInfo&, struct user_regs_struct&);
processTrapRet processFuncTrap(const trapInfo&, pid_t, processTrapRet processFuncTrap(const trapInfo&,
pid_t,
struct user_regs_struct&, struct user_regs_struct&,
struct user_fpregs_struct&); struct user_fpregs_struct&);
processTrapRet processJitCodeRet(const trapInfo&, pid_t); processTrapRet processJitCodeRet(const trapInfo&, pid_t);

View File

@ -55,8 +55,10 @@ class OIGenerator {
std::filesystem::path generateForType( std::filesystem::path generateForType(
const OICodeGen::Config& generatorConfig, const OICodeGen::Config& generatorConfig,
const OICompiler::Config& compilerConfig, const drgn_qualified_type& type, const OICompiler::Config& compilerConfig,
const std::string& linkageName, SymbolService& symbols); const drgn_qualified_type& type,
const std::string& linkageName,
SymbolService& symbols);
}; };
} // namespace ObjectIntrospection } // namespace ObjectIntrospection

View File

@ -32,8 +32,10 @@ using namespace ObjectIntrospection;
using namespace std::literals; using namespace std::literals;
std::optional<std::set<Feature>> processConfigFile( std::optional<std::set<Feature>> processConfigFile(
const std::string& configFilePath, std::map<Feature, bool> featureMap, const std::string& configFilePath,
OICompiler::Config& compilerConfig, OICodeGen::Config& generatorConfig) { std::map<Feature, bool> featureMap,
OICompiler::Config& compilerConfig,
OICodeGen::Config& generatorConfig) {
fs::path configDirectory = fs::path(configFilePath).remove_filename(); fs::path configDirectory = fs::path(configFilePath).remove_filename();
toml::table config; toml::table config;

View File

@ -25,7 +25,9 @@
namespace OIUtils { namespace OIUtils {
std::optional<std::set<Feature>> processConfigFile( std::optional<std::set<Feature>> processConfigFile(
const std::string& configFilePath, std::map<Feature, bool> featureMap, const std::string& configFilePath,
OICompiler::Config& compilerConfig, OICodeGen::Config& generatorConfig); std::map<Feature, bool> featureMap,
OICompiler::Config& compilerConfig,
OICodeGen::Config& generatorConfig);
} // namespace OIUtils } // namespace OIUtils

View File

@ -21,8 +21,12 @@
struct PaddingInfo { struct PaddingInfo {
public: public:
PaddingInfo() = default; PaddingInfo() = default;
PaddingInfo(size_t strSize, int saveSz, size_t paddSz, size_t issetSz, PaddingInfo(size_t strSize,
std::string def, size_t instCnt) int saveSz,
size_t paddSz,
size_t issetSz,
std::string def,
size_t instCnt)
: structSize{strSize}, : structSize{strSize},
alignmentRequirement{8}, alignmentRequirement{8},
savingSize{static_cast<size_t>(saveSz)}, savingSize{static_cast<size_t>(saveSz)},

View File

@ -67,7 +67,8 @@ void serialize(Archive& ar, PaddingInfo& p, const unsigned int version) {
INSTANCIATE_SERIALIZE(PaddingInfo) INSTANCIATE_SERIALIZE(PaddingInfo)
template <class Archive> template <class Archive>
void serialize(Archive& ar, struct drgn_location_description& location, void serialize(Archive& ar,
struct drgn_location_description& location,
const unsigned int version) { const unsigned int version) {
verify_version<struct drgn_location_description>(version); verify_version<struct drgn_location_description>(version);
ar& location.start; ar& location.start;
@ -86,7 +87,8 @@ void serialize(Archive& ar, struct drgn_location_description& location,
INSTANCIATE_SERIALIZE(struct drgn_location_description) INSTANCIATE_SERIALIZE(struct drgn_location_description)
template <class Archive> template <class Archive>
void serialize(Archive& ar, struct drgn_object_locator& locator, void serialize(Archive& ar,
struct drgn_object_locator& locator,
const unsigned int version) { const unsigned int version) {
verify_version<struct drgn_object_locator>(version); verify_version<struct drgn_object_locator>(version);
ar& locator.module_start; ar& locator.module_start;
@ -124,7 +126,8 @@ void serialize(Archive& ar, FuncDesc::Arg& arg, const unsigned int version) {
INSTANCIATE_SERIALIZE(FuncDesc::Arg) INSTANCIATE_SERIALIZE(FuncDesc::Arg)
template <class Archive> template <class Archive>
void serialize(Archive& ar, FuncDesc::Retval& retval, void serialize(Archive& ar,
FuncDesc::Retval& retval,
const unsigned int version) { const unsigned int version) {
verify_version<FuncDesc::Retval>(version); verify_version<FuncDesc::Retval>(version);
ar& retval.typeName; ar& retval.typeName;
@ -134,7 +137,8 @@ void serialize(Archive& ar, FuncDesc::Retval& retval,
INSTANCIATE_SERIALIZE(FuncDesc::Retval) INSTANCIATE_SERIALIZE(FuncDesc::Retval)
template <class Archive> template <class Archive>
void serialize(Archive& ar, FuncDesc::Range& range, void serialize(Archive& ar,
FuncDesc::Range& range,
const unsigned int version) { const unsigned int version) {
verify_version<FuncDesc::Range>(version); verify_version<FuncDesc::Range>(version);
ar& range.start; ar& range.start;
@ -188,7 +192,8 @@ static void serialize_c_string(Archive& ar, char** string) {
// what you're doing (or ask someone who does) before touching anything. // what you're doing (or ask someone who does) before touching anything.
// ########################################################################### // ###########################################################################
template <class Archive> template <class Archive>
void serialize(Archive& ar, struct drgn_type& type, void serialize(Archive& ar,
struct drgn_type& type,
const unsigned int version) { const unsigned int version) {
#define assert_in_same_union(member_1, member_2) \ #define assert_in_same_union(member_1, member_2) \
do { \ do { \
@ -307,7 +312,8 @@ void serialize(Archive& ar, struct drgn_type& type,
INSTANCIATE_SERIALIZE(struct drgn_type) INSTANCIATE_SERIALIZE(struct drgn_type)
template <class Archive> template <class Archive>
void serialize(Archive& ar, struct DrgnClassMemberInfo& m, void serialize(Archive& ar,
struct DrgnClassMemberInfo& m,
const unsigned int version) { const unsigned int version) {
verify_version<struct DrgnClassMemberInfo>(version); verify_version<struct DrgnClassMemberInfo>(version);
ar& m.type; ar& m.type;
@ -319,7 +325,8 @@ void serialize(Archive& ar, struct DrgnClassMemberInfo& m,
INSTANCIATE_SERIALIZE(DrgnClassMemberInfo) INSTANCIATE_SERIALIZE(DrgnClassMemberInfo)
template <class Archive> template <class Archive>
void serialize(Archive& ar, struct drgn_qualified_type& type, void serialize(Archive& ar,
struct drgn_qualified_type& type,
const unsigned int version) { const unsigned int version) {
verify_version<struct drgn_qualified_type>(version); verify_version<struct drgn_qualified_type>(version);
ar& type.type; ar& type.type;
@ -338,7 +345,8 @@ void serialize(Archive& ar, RootInfo& rootInfo, const unsigned int version) {
INSTANCIATE_SERIALIZE(RootInfo) INSTANCIATE_SERIALIZE(RootInfo)
template <class Archive> template <class Archive>
void serialize(Archive& ar, struct TypeHierarchy& th, void serialize(Archive& ar,
struct TypeHierarchy& th,
const unsigned int version) { const unsigned int version) {
verify_version<TypeHierarchy>(version); verify_version<TypeHierarchy>(version);
ar& th.classMembersMap; ar& th.classMembersMap;

View File

@ -119,8 +119,11 @@ struct ModParams {
* *
*/ */
static int moduleCallback(Dwfl_Module* mod, void** /* userData */, static int moduleCallback(Dwfl_Module* mod,
const char* name, Dwarf_Addr /* start */, void* arg) { void** /* userData */,
const char* name,
Dwarf_Addr /* start */,
void* arg) {
ModParams* m = (ModParams*)arg; ModParams* m = (ModParams*)arg;
int nsym = dwfl_module_getsymtab(mod); int nsym = dwfl_module_getsymtab(mod);
@ -296,8 +299,10 @@ static std::string bytesToHexString(const unsigned char* bytes, int nbbytes) {
* to this callback. So we always return DWARF_CB_ABORT, as this is * to this callback. So we always return DWARF_CB_ABORT, as this is
* the only build ID we are interested in. * the only build ID we are interested in.
*/ */
static int buildIDCallback(Dwfl_Module* mod, void** /* userData */, static int buildIDCallback(Dwfl_Module* mod,
const char* name, Dwarf_Addr /* start */, void** /* userData */,
const char* name,
Dwarf_Addr /* start */,
void* arg) { void* arg) {
auto* buildID = static_cast<std::optional<std::string>*>(arg); auto* buildID = static_cast<std::optional<std::string>*>(arg);
@ -430,8 +435,10 @@ struct drgn_program* SymbolService::getDrgnProgram() {
* Although 'parseFormalParam' has an all-encompassing sounding name, its sole * Although 'parseFormalParam' has an all-encompassing sounding name, its sole
* task is to extract the location information for this parameter if any exist. * task is to extract the location information for this parameter if any exist.
*/ */
static void parseFormalParam(Dwarf_Die& param, struct drgn_module* module, static void parseFormalParam(Dwarf_Die& param,
struct drgn_program* prog, Dwarf_Die& funcDie, struct drgn_module* module,
struct drgn_program* prog,
Dwarf_Die& funcDie,
std::shared_ptr<FuncDesc>& fd) { std::shared_ptr<FuncDesc>& fd) {
/* /*
* NOTE: It is vital that the function descriptors list of arguments * NOTE: It is vital that the function descriptors list of arguments

View File

@ -43,7 +43,9 @@ struct StringLiteral {
* know how to use the _Args to also statically check the type of the arguments. * know how to use the _Args to also statically check the type of the arguments.
* In the meantime, I can use the size of _Args to do a simple count check. * In the meantime, I can use the size of _Args to do a simple count check.
*/ */
template <StringLiteral _Name, unsigned long _SysNum, typename _RetType, template <StringLiteral _Name,
unsigned long _SysNum,
typename _RetType,
typename... _Args> typename... _Args>
struct Syscall { struct Syscall {
/* User friendly syscall name */ /* User friendly syscall name */

View File

@ -177,9 +177,19 @@ struct TreeBuilder::Node {
*/ */
size_t exclusiveSize{}; size_t exclusiveSize{};
MSGPACK_DEFINE_ARRAY(id, name, typeName, typePath, isTypedef, staticSize, MSGPACK_DEFINE_ARRAY(id,
dynamicSize, paddingSavingsSize, containerStats, pointer, name,
children, isset, exclusiveSize) typeName,
typePath,
isTypedef,
staticSize,
dynamicSize,
paddingSavingsSize,
containerStats,
pointer,
children,
isset,
exclusiveSize)
}; };
TreeBuilder::~TreeBuilder() { TreeBuilder::~TreeBuilder() {
@ -214,7 +224,8 @@ bool TreeBuilder::emptyOutput() const {
} }
void TreeBuilder::build(const std::vector<uint64_t>& data, void TreeBuilder::build(const std::vector<uint64_t>& data,
const std::string& argName, struct drgn_type* type, const std::string& argName,
struct drgn_type* type,
const TypeHierarchy& typeHierarchy) { const TypeHierarchy& typeHierarchy) {
th = &typeHierarchy; th = &typeHierarchy;
oidData = &data; oidData = &data;
@ -385,7 +396,8 @@ static std::string_view drgnKindStr(struct drgn_type* type) {
return kind; return kind;
} }
void TreeBuilder::setSize(TreeBuilder::Node& node, uint64_t dynamicSize, void TreeBuilder::setSize(TreeBuilder::Node& node,
uint64_t dynamicSize,
uint64_t memberSizes) { uint64_t memberSizes) {
node.dynamicSize = dynamicSize; node.dynamicSize = dynamicSize;
if (memberSizes > node.staticSize + node.dynamicSize) { if (memberSizes > node.staticSize + node.dynamicSize) {

View File

@ -50,8 +50,10 @@ class TreeBuilder {
TreeBuilder(Config); TreeBuilder(Config);
~TreeBuilder(); ~TreeBuilder();
void build(const std::vector<uint64_t>&, const std::string&, void build(const std::vector<uint64_t>&,
struct drgn_type*, const TypeHierarchy&); const std::string&,
struct drgn_type*,
const TypeHierarchy&);
void dumpJson(); void dumpJson();
void setPaddedStructs(std::map<std::string, PaddingInfo>* paddedStructs); void setPaddedStructs(std::map<std::string, PaddingInfo>* paddedStructs);
bool emptyOutput() const; bool emptyOutput() const;
@ -114,6 +116,7 @@ class TreeBuilder {
std::string_view serialize(const T&); std::string_view serialize(const T&);
void JSON(NodeID id, std::ofstream& output); void JSON(NodeID id, std::ofstream& output);
static void setSize(TreeBuilder::Node& node, uint64_t dynamicSize, static void setSize(TreeBuilder::Node& node,
uint64_t dynamicSize,
uint64_t memberSizes); uint64_t memberSizes);
}; };

View File

@ -295,7 +295,8 @@ OidProc OidIntegration::runOidOnProcess(OidOpts opts,
void OidIntegration::compare_json(const bpt::ptree& expected_json, void OidIntegration::compare_json(const bpt::ptree& expected_json,
const bpt::ptree& actual_json, const bpt::ptree& actual_json,
const std::string& full_key, bool expect_eq) { const std::string& full_key,
bool expect_eq) {
if (expected_json.empty()) { if (expected_json.empty()) {
if (expect_eq) { if (expect_eq) {
ASSERT_EQ(expected_json.data(), actual_json.data()) ASSERT_EQ(expected_json.data(), actual_json.data())
@ -358,7 +359,8 @@ std::string OilIntegration::TmpDirStr() {
return std::string("/tmp/oil-integration-XXXXXX"); return std::string("/tmp/oil-integration-XXXXXX");
} }
Proc OilIntegration::runOilTarget(OidOpts opts, std::string configPrefix, Proc OilIntegration::runOilTarget(OidOpts opts,
std::string configPrefix,
std::string configSuffix) { std::string configSuffix) {
fs::path thisConfig = createCustomConfig(configPrefix, configSuffix); fs::path thisConfig = createCustomConfig(configPrefix, configSuffix);

View File

@ -51,8 +51,10 @@ class OidIntegration : public IntegrationBase {
protected: protected:
std::string TmpDirStr() override; std::string TmpDirStr() override;
OidProc runOidOnProcess(OidOpts opts, std::vector<std::string> extra_args, OidProc runOidOnProcess(OidOpts opts,
std::string configPrefix, std::string configSuffix); std::vector<std::string> extra_args,
std::string configPrefix,
std::string configSuffix);
/* /*
* compare_json * compare_json
@ -70,6 +72,7 @@ class OilIntegration : public IntegrationBase {
protected: protected:
std::string TmpDirStr() override; std::string TmpDirStr() override;
Proc runOilTarget(OidOpts opts, std::string configPrefix, Proc runOilTarget(OidOpts opts,
std::string configPrefix,
std::string configSuffix); std::string configSuffix);
}; };

View File

@ -34,7 +34,8 @@ static std::string parseBadString(const std::string& script) {
return testing::internal::GetCapturedStderr(); return testing::internal::GetCapturedStderr();
} }
static void EXPECT_REQ_EQ(const prequest& req, const std::string& type, static void EXPECT_REQ_EQ(const prequest& req,
const std::string& type,
const std::string& func, const std::string& func,
const std::vector<std::string>& args) { const std::vector<std::string>& args) {
EXPECT_EQ(req.type, type); EXPECT_EQ(req.type, type);