diff --git a/include/hobbes/eval/cc.H b/include/hobbes/eval/cc.H index bdc6f397..d08b7953 100644 --- a/include/hobbes/eval/cc.H +++ b/include/hobbes/eval/cc.H @@ -219,6 +219,9 @@ public: // dump the contents of the generated module (useful for debugging) void dumpModule(); + // show jit functions in name:addr format + [[nodiscard]] std::string showJitMemoryAddresses() const; + // get the x86 machine code for an expression (useful for debugging) using bytes = std::vector; bytes machineCodeForExpr(const std::string &expr); diff --git a/include/hobbes/eval/funcdefs.H b/include/hobbes/eval/funcdefs.H index df7ea445..23b644ca 100644 --- a/include/hobbes/eval/funcdefs.H +++ b/include/hobbes/eval/funcdefs.H @@ -15,6 +15,8 @@ char* memalloc(size_t, size_t); const array* makeString(const std::string& x); std::string makeStdString(const array* x); +[[nodiscard]] std::string showDetailedMemoryPool(); + } #endif diff --git a/include/hobbes/eval/jitcc.H b/include/hobbes/eval/jitcc.H index 53e5527b..7986e751 100644 --- a/include/hobbes/eval/jitcc.H +++ b/include/hobbes/eval/jitcc.H @@ -56,6 +56,8 @@ public: // get the address of a bound symbol void* getSymbolAddress(const std::string&); + [[nodiscard]] std::string showJitMemoryAddresses(); + #if LLVM_VERSION_MAJOR < 11 // print all module contents void dump() const; diff --git a/lib/hobbes/eval/cc.C b/lib/hobbes/eval/cc.C index 0d17a3a7..ec8124e8 100644 --- a/lib/hobbes/eval/cc.C +++ b/lib/hobbes/eval/cc.C @@ -653,6 +653,11 @@ void cc::dumpModule() { #endif } +std::string cc::showJitMemoryAddresses() const { + hlock _; + return this->jit->showJitMemoryAddresses(); +} + cc::bytes cc::machineCodeForExpr(const std::string& expr) { hlock _; return this->jit->machineCodeForExpr(unsweetenExpression(readExpr(expr))); diff --git a/lib/hobbes/eval/funcdefs.C b/lib/hobbes/eval/funcdefs.C index cc859cd1..b91002c6 100644 --- a/lib/hobbes/eval/funcdefs.C +++ b/lib/hobbes/eval/funcdefs.C @@ -154,6 +154,18 @@ void printMemoryPool() { std::cout << showMemoryPool() << std::flush; } +std::string showDetailedMemoryPool() { + std::ostringstream oss; + oss << "{"; + std::string sep; + for (const auto& region: threadRegions()) { + oss << sep << "\n\"" << region.first << "\": " << region.second->show(); + sep = ","; + } + oss << "\n}"; + return std::move(oss).str(); +} + void resetMemoryPool() { threadRegion().clear(); } diff --git a/lib/hobbes/eval/jitcc.C b/lib/hobbes/eval/jitcc.C index dd28ded7..6a521d59 100644 --- a/lib/hobbes/eval/jitcc.C +++ b/lib/hobbes/eval/jitcc.C @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -728,6 +729,21 @@ void* jitcc::getSymbolAddress(const std::string& vn) { return 0; } +std::string jitcc::showJitMemoryAddresses() { + std::string s; + llvm::raw_string_ostream os(s); + for (const auto* m: this->modules) { + for (const auto& f: *m) { + if (!f.isDeclaration()) { + if (void* addr = this->getSymbolAddress(f.getName().str())) { + os << f.getName() << ':' << addr << '\n'; + } + } + } + } + return s; +} + void jitcc::dump() const { for (auto m : this->modules) { #if LLVM_VERSION_MAJOR == 6 || LLVM_VERSION_MAJOR >= 8