Debugging MLIR with gdb

Hi all,
I am working on linking MLIR with C++ program. And I got trouble in when I wanted to use gdb to step into my MLIR function:

Breakpoint 1, 0x0000000000401200 in change_value ()
(gdb) n
Single stepping until exit from function change_value,
which has no line number information.
0x000000000040124e in _mlir_ciface_change_value ()
(gdb) n
Single stepping until exit from function _mlir_ciface_change_value,
which has no line number information.

The function change_value is a function written by MLIR, and _mlir_ciface_change_value is its wrapper. From the output of gdb, I thought the compilation lost its debug information. But I still couldn’t step into these functions when I tried to keep debug information in every step of compilation with these commands:

mlir-opt -lower-affine \
        -llvm-request-c-wrappers \
        -mlir-print-debuginfo \
        -convert-func-to-llvm \
        -convert-arith-to-llvm \
        -convert-scf-to-cf \
        -convert-memref-to-llvm \
        -reconcile-unrealized-casts \
        change_value.mlir > value.mlir
mlir-translate -mlir-to-llvmir -mlir-print-debuginfo value.mlir -o value.ll
llvm-as value.ll -o value.bc
llc -filetype=obj \
    -debugger-tune=gdb \
    -debugify-level=locations\
    -debug-entry-values \
    value.bc -o value.o
clang++ value.o main.cpp -O0 -g

Does it mean that the debug information of MLIR does not support conversion to LLVM IR? Or did I use it in a wrong way? I hope someone familiar with debugging MLIR could help me. Thanks in advance.

I find gdb can support debugging assembly code. I can use layout asm to debug the generated executable file and it helps.

Background Context:

We used to generate very basic (and very wrong) debug information when converting to LLVM which was generally enough to look at line tables for basic stuff, but not enough to do anything interesting. I recently started adding support to the LLVM dialect for actual debug information and when ⚙ D136543 [mlir:LLVM] Rewrite the LLVMIR export to use the debug info attributes landed we stopped generating the fake stuff, and started generating real stuff. The caveat to that is that now something has to be responsible for inserting valid debug information, given that we won’t do it implicitly anymore (which creates a slight regression, but is a necessary step in building real compiler support). Note that just file/line/col information isn’t actually enough to build real debug info, you need more information about the compilation/sub programs/etc. I’m currently/actively working towards building out abstractions in MLIR that will enable expressing debug information, provide support for viewing not just line tables but also variables/etc, and enable some of the “build debug info automatically for this IR blob”. That work won’t have anything upstream to show likely for a month or two.

Inline Responses:

LLVM has support for translating debug information, but (as noted above) you’ll need to ensure that you have the proper DI debug metadata attached, attaching subprograms (i.e. DISubprogramAttr to your FuncOps) is likely enough for just line tables (though some transformations may donk this up right now). When/where to attach really depends on the frontend that you are coming from, given that generally whatever is generating the initial IR should attach debug metadata when desired (though sometimes that’s outside of control).

– River

Thanks for your reply. As a newbie to MLIR, I got a lot from your answer.