14 Comments

Great thanks, I'm not used to VS Code either, so there are so many pain points, I tried eclipse for this course before, with which I'm more familiar. But didn't know how to configure it for bazel.

Still facing issues, when I debug the program having put this in the launch.json:

```

"program": "${workspaceFolder}/bazel-bin/format/format_test",

```

VS Code then complains that `/workspaces/daily-bite-course-06/format/format_error` does not exist. I'm running it in the container, so I should have the same as you, but can't figure out why it is removing the `bazel-bin` part of the path.

Also, I don't think it's related but, VS Code also complains that it cannot open "catch2/catch_test_macros.hpp: No such file or directory gcc" in the include. When I run it with bazel from the command line it builds and runs OK. So when I try to launch it says gcc could noot compile it.

I know it doesn't need to because bazel generated the runnable. But I also don't know how to make VS Code debug the program because it doesn't find it.

Expand full comment

Sorry My last replies didn't arrive as replies, when I clicked on the view comment in the mail notification, I thought the big entry box was for a reply, but not, it was for a new comment. I just realized I had to click the little reply button that I missed the other times.

I see what I was doing wrong there, I was hitting the debug button in the test, not starting a new debug from the menubar, I thought it would do the same.

Now, I've been able to debug and place breakpoints in the test case, but not in the method implementation. I guess it is because it is a template method, or because it is a header file? It is ignoring all my breakpoints there, when I'm debugging the red dots are transformed into unfilled gray dots.

Do you know if it can be solved?

I will check tomorrow with another exercise if the same happens with methods in source files.

Expand full comment

So debugging should work fine with --config=debug, --config=addrsan and --config=ubsan.

However, the base binary without any config will not have debug information, which is why you are not getting breakpoints to trigger.

Expand full comment

Sorry I wasn't clear, I am getting breakpoint hits, but not in the function. I can debug the format_test.cc, and even enter the template function in format.h and even debug it step by step, but breakpoints there are grayed and not hit.

The function also exits with an exception when it tries to write to the output stream, which it doesn't happen while running with bazel in the command line.

Expand full comment

Hmm, that's a bit weird.

Can you rerun bazel run @hedron_compile_commands//:refresh_all? This is what generates the information about the project structure for VSCode.

I don't think you should need to rerun the command, but if VSCode is not picking up on the files, then this is a potential culprit.

Expand full comment

Thank you very much for your prompt response, but still the same.

The `format.h` file was already being detected as the source for the function, since when I entered the function in the step by step debugging it was working. So I guess the issue should be other.

Are you sure it has nothing to do with it being a template function?

Expand full comment

If it was the template function, you couldn't step in it. This sounds like a problem specifically with VSCode.

Expand full comment

ahh, when I debug it, it is also quitting with an exception, even though when I run it from the terminal it runs ok:

```

Breakpoint 1, main (argc=1, argv=0x7ffff1fd3cf8) at external/catch2~3.3.0/src/catch2/internal/catch_main.cpp:29

Loaded '/usr/local/lib64/libstdc++.so.6'. Symbols loaded.

Loaded '/lib/x86_64-linux-gnu/libm.so.6'. Symbols loaded.

Loaded '/usr/local/lib64/libgcc_s.so.1'. Symbols loaded.

Loaded '/lib/x86_64-linux-gnu/libc.so.6'. Symbols loaded.

[Inferior 1 (process 84959) exited normally]

The program '/workspaces/daily-bite-course-06/bazel-bin/format/format_test' has exited with code 0 (0x00000000).

```

It exits with zero code, but through an exception, inside the `format_range` where I have the line:

s << '{';

In that session's terminal, it says all tests passed, but it doesn't show the test as ran:

```

Warning: Bazel shard configuration is missing 'TEST_SHARD_INDEX'. Shard configuration is skipped.

Warning: Bazel shard configuration is missing 'TEST_TOTAL_SHARDS'. Shard configuration is skipped.

Warning: Bazel shard configuration is missing 'TEST_SHARD_STATUS_FILE'. Shard configuration is skipped.

Randomness seeded to: 1379184129

===============================================================================

All tests passed (4 assertions in 1 test case)

[1] + Done "/usr/local/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-54jomuen.bhj" 1>"/tmp/Microsoft-MIEngine-Out-eqrbgbpr.vva"

```

Compared with:

```

root@6a27be740e2e:/workspaces/daily-bite-course-06# bazel test --config=debug //format/...

INFO: Analyzed 2 targets (0 packages loaded, 0 targets configured).

INFO: Found 1 target and 1 test target...

INFO: Elapsed time: 0.149s, Critical Path: 0.03s

INFO: 1 process: 1 internal.

INFO: Build completed successfully, 1 total action

//format:format_test (cached) PASSED in 0.1s

Executed 0 out of 1 test: 1 test passes.

There were tests whose specified size is too big. Use the --test_verbose_timeout_warnings command line option to see which ones these are.

```

Expand full comment

Yes, I remember something about that, but I couldn't understand it at the moment, and as it said you would talk more about debugging later I just kept going.

Moreover I still can't figure out which is the bazel binary I have to set in the `launch.json`. Never used bazel before. Do I have to modify the `launch.json` for each test?

I guess I should also run the bazel build with debug before, because I don't see the `bazel-bin/debugging` directory in the dist.

I guess with this I have enough to try and make it work, but If you could add a more detailed guide for that it would be easier for other starters.

Thanks.

Expand full comment

Aaah. Yeah, these (obvious to me) points are some I want to iron out in later editions of this course.

So, bazel-bin is the directory for binaries in bazel. If you compile (or run, since that needs to compile first) a binary lets say //foo/bla:something_test, it will end up as bazel-bin/foo/bla/something_test. So if you want to debug that, change the launch.json path to bazel-bin/foo/bla/something_test.

And yeah, unfortunately, this is a limitation of VSCode, since it's mostly an editor, it doesn't understand how to debug things, so you need to tell it every time.

Expand full comment

Hi Simon, nice course.

Is there a way to easily run bazel in debug and attach the process to VS Code? So we can debug the tests without having to write a main?

Thank you for the course.

Expand full comment

Yup, it was covered in lesson 1. You need to modify the .vscode/launch.json file to point to the corresponding test binary, set a breakpoint and then Run>Start Debugging.

Expand full comment

wow! great material!!

Expand full comment

Thanks :-D

Expand full comment