Mlir-tblgen debug mode

Hello,

I am trying to trace or look at how the mlir-tblgen is generating the lhlo_ops.cc.inc file using the lhlo_ops.td file. When I try to run the command using gdb, it says no debugging symbols found. I have specified the optimisation level in the Bazel build command but it has not worked.I have checked the logs and it is building it using -g0 and -O2. How would I be able to change it to -g and -O0 so that I can trace it using gdb ?

Thanks,
J.

Given that you’re talking about building with Bazel and lhlo, this might be more appropriate for the mlir@tensorflow.org list (https://groups.google.com/a/tensorflow.org/g/mlir). But since I’m here, I’ll try to answer your question :slight_smile: The optimization level you’re setting in the Bazel build command is specifically for the target configuration. Bazel generally assumes you’re doing some sort of cross-compilation, in the sense that the tools that you’re using as part of the build step shouldn’t necessarily be built in the same configuration as your target. So when you set -c dbg or similar, you’re telling it to build the target binaries in debug mode. So you have a few options here:

Pass --nodistinct_host_configuration to force Bazel to build the host tools in the target configuration. You’re likely going to end up rebuilding a lot of stuff and thrash various caches, but this is likely the simplest.
Build mlir-tblgen directly as your target bazel build -c dbg @llvm-project//mlir:mlir-tblgen and then manually invoke it in the same way as Bazel is. You can see what commands Bazel runs with the -s (User manual - Bazel). Be warned that it will produce quite a bit of output as that will list the command for every command Bazel runs that isn’t cached. If you’re just trying to debug a failed command use --verbose_failures.
Manually pass the relevant compilation options to --host_copt (User manual - Bazel). bazel build --host_copt=-O0 --host_copt-UNDEBUG --host_copt=-g ... I think would be the invocation, though untested

Some more background/complaints: Please add a way to control compilation mode in host-build tools · Issue #4485 · bazelbuild/bazel · GitHub

1 Like

Thank you gcmn for the clear and concise answer! I will try to follow your suggestion and see where it leads to. I will definitely post my related questions if any in mlir@tensorflow.org.

Thanks again,
J.