Debuggers never worked for me, but this time I need one

For a long time, since debuggers never worked for me, I've been "print debugging". It requires recompilation every time I want to inspect something, and when the code I want to inspect is in one of the dependencies, I need to clone it, which takes a lot of time. So, it's getting increasingly clear that I need a working debugger.

When I first tried to use gdb, I hit an issue documented here:

It mentions a workaround where you debug the executable in deps. I tried and it did not work.

When I tried lldb, I hit another issue. Similarly enough, it spits out a bunch of errors:

error: <executable> debug map object file '/path/to/my-project/target/debug/deps/<executable>.<randomstring>.rcgu.o' has changed (actual time is yyyy-mm-dd hh:mm:ss.000000000, debug map time is 1970-01-01 09:00:00.000000000) since this executable was linked, file will be ignored
<same error, for each .rcgu.o file>

This error also occurs in gdb:

warning: `/path/to/my-project/target/debug/deps/<executable>.<randomstring>.rcgu.o': file time stamp mismatch.

Admittedly, I've never used native debugger before, so something is likely wrong with my setup. I'll also need to learn how to use the debuggers. But for now, I'm just trying to get them to load.

This might be overkill, but you could try to debug your code from a Linux machine. Both gdb and lldb work perfectly fine there.

Alternatively, if you use VS Code and the rust-analyzer extension you might be able to debug your code inside your editor. rust-analyzer gives you a nice "debug this test" button which looks after the debugger setup.

You may want to try a few options.

  • I hit a similar problem on command line. Once I tried rustc -g --emit="obj,link" <source file>.rs which produced a <binary name>, <binary name>.o and <binary name>.dSYM folder. Then trying to debug using rust-gdb <binary name> file worked flawlessly on Mac
  • If you prefer using Vim or Neovim, you should definitely try setting up Vimspector or Nvim-dap. I was able to setup both of them on my Mac as well as Linux
  • I haven't tried this but you may want to check the following: How to do `--emit=obj`? · Issue #223 · japaric/xargo · GitHub
  • I never had an issue with lldb on Mac or Linux. If you don't mind sharing your setup for OS, editor etc. the issue could be narrowed down
  • As mentioned earlier by @Michael-F-Bryan , you could just use VS Code with CodeLLDB or Microsoft Cpptools.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.