[ORC] Add an output stream operator for SymbolStringPool.

Handy for checking string pool state, e.g. when debugging dangling-pool-entry
errors.
This commit is contained in:
Lang Hames 2022-06-08 16:48:15 -07:00
parent 209c07d486
commit 3fcd3669e3
4 changed files with 29 additions and 0 deletions

View File

@ -92,6 +92,9 @@ raw_ostream &operator<<(raw_ostream &OS, const SymbolState &S);
/// Render a LookupKind.
raw_ostream &operator<<(raw_ostream &OS, const LookupKind &K);
/// Dump a SymbolStringPool. Useful for debugging dangling-pointer crashes.
raw_ostream &operator<<(raw_ostream &OS, const SymbolStringPool &SSP);
/// A function object that can be used as an ObjectTransformLayer transform
/// to dump object files to disk at a specified path.
class DumpObjects {

View File

@ -19,6 +19,9 @@
#include <mutex>
namespace llvm {
class raw_ostream;
namespace orc {
class SymbolStringPtr;
@ -26,6 +29,10 @@ class SymbolStringPtr;
/// String pool for symbol names used by the JIT.
class SymbolStringPool {
friend class SymbolStringPtr;
// Implemented in DebugUtils.h.
friend raw_ostream &operator<<(raw_ostream &OS, const SymbolStringPool &SSP);
public:
/// Destroy a SymbolStringPool.
~SymbolStringPool();

View File

@ -297,6 +297,13 @@ raw_ostream &operator<<(raw_ostream &OS, const SymbolState &S) {
llvm_unreachable("Invalid state");
}
raw_ostream &operator<<(raw_ostream &OS, const SymbolStringPool &SSP) {
std::lock_guard<std::mutex> Lock(SSP.PoolMutex);
for (auto &KV : SSP.Pool)
OS << KV.first() << ": " << KV.second << "\n";
return OS;
}
DumpObjects::DumpObjects(std::string DumpDir, std::string IdentifierOverride)
: DumpDir(std::move(DumpDir)),
IdentifierOverride(std::move(IdentifierOverride)) {

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ExecutionEngine/Orc/SymbolStringPool.h"
#include "llvm/ExecutionEngine/Orc/DebugUtils.h"
#include "gtest/gtest.h"
using namespace llvm;
@ -50,4 +51,15 @@ TEST(SymbolStringPool, ClearDeadEntries) {
EXPECT_TRUE(SP.empty()) << "pool should be empty";
}
TEST(SymbolStringPool, DebugDump) {
SymbolStringPool SP;
auto A1 = SP.intern("a");
auto A2 = A1;
auto B = SP.intern("b");
std::string DumpString;
raw_string_ostream(DumpString) << SP;
EXPECT_EQ(DumpString, "a: 2\nb: 1\n");
}
}