Print variables in mlir file in gdb/lldb

Hi, community!

I have a LLVMIR mlir file like:

1 func @ops(%arg: i32) {
2   %0 = llvm.add %arg0, arg0 : i32
3   ... // some code
4 }

then translate it and link it with debug mode:

mlir-translate -mlir-to-llvmir test.mlir | tee test.ll
llc test.ll --debugger-tune=gdb

which means I can debug it in the gdb.

So when I set a breakpoint (b test.mlir:3), how can I print the variables in this mlir file, like β€œ%0”?


You can’t. Adding this would be an interesting project!

1 Like

Thanks for your reply!

Yeah, this could be useful while debugging.
How about having a function like func private @printF32(%arg0: f32), which can be called in the gdb/lldb?

Any ideas?

Having such function is just a small part of it: generating the debug info expression to have %arg0 available is a bit more involved. See Source Level Debugging with LLVM β€” LLVM 13 documentation for the LLVM-level doc.

1 Like

Thanks for the doc. Let me check it. :slight_smile: