How to debug tvm::PrimExpr?

Hi, I’m debugging the C++ backend and encountering issues when trying to call PrimExpr::Script() method in LLDB. When executing shape[0].get()->Script(tvm::NullOpt), I get the following symbol lookup errors, suggesting these symbols might have been optimized out. So what’s the recommended way to inspect Array<PrimExpr> contents during debugging? The TVM was built with Debug and I’ve tried both Downcast and explicit PrinterConfig construction without success.

$ p shape 
(tvm::runtime::Array<tvm::PrimExpr, void>) {
  tvm::runtime::ObjectRef = {
    data_ = {
      data_ = 0x0000561b31f4d0f0
    }
  }
}

$ p shape.size()
(size_t) 2

$ p shape[0].get()->Script(tvm::NullOpt)
error: Couldn't look up symbols:
  tvm::runtime::Optional<tvm::PrinterConfig>::Optional(tvm::runtime::NullOptType)
Hint: The expression tried to call a function that is not present in the target, perhaps because it was optimized out by the compiler.

You should be able to print using the p tvm::Dump(shape) function. For gdb, I had built a small extension using gdb python api to make the debugging easier.

Something similar can be quickly created to support LLDB as well. Please feel free to add a PR to that repo, or copy the code and create a new one as you see fit if you think it’ll be useful.

1 Like

Thanks Anirudh, I had also built some print commands using lldb python api, I will add a PR to your repo.