How do I print debug the written Toy to MLIR code?

Hi all,
As the title says I am trying to debug some of the variables inside the codebase for Toy Ch2. For instance I want to see the output of variable name dataType here. How do I go about doing this?

I have tried the standard llvm::errs << dataType << "\n"; and rebuilt the project. But the error message does not shows up in the console when that function is running…

I assume it is a typo here and your code has the missing parentheses: llvm::errs() << dataType << "\n"; ?

If nothing shows up on the console, the best explanation is that the function is never executed. You should be able to figure with a debugger?

I think it does - used gdb to confirm to it. Also you’re right I meant llvm::errs(). Is there any other way I can see the output of the variable; say llvm:critical() or op->getWarning() or something else?

Here is the output of the gdb, for the above linked code

(gdb) break ConstantOp::build
Breakpoint 1 at 0x263f84 (2 locations)
(gdb) start
Temporary breakpoint 2 at 0x23f214
Starting program: build/tools/opt -emit=mlir example.toy

Temporary breakpoint 2, 0x000000000023f214 in main ()
(gdb) c
Continuing.

Breakpoint 1, 0x0000000000264164 in mlir::nnfls::ConstantOp::build(mlir::OpBuilder&, mlir::OperationState&, mlir::Type, mlir::DenseElementsAttr) ()

This breakpoint didn’t hit the function you pointed at before, check the signature carefully.

1 Like

Ouch you are right - thanks a mil