I have a complex cc_test which has tons of args and envs specified in the rules:
cc_test(
name="my_test",
args=[...tons of args...],
env= {...tons of envs...},
)
Now I want to run it locally by running ./bazel-bin/my_test, so that I can use GDB to debug it.
The problem is I neeed to copy&paste args and env form the rules manually, to get the full command like:
ENV1=X ENV2=Y ./bazel-bin/my_test --args1=x --args2=y
Which is very a waste of time.
Is there a faster way to get this command? Or is there any other simpler way to debug a cc_test with GDB?
To see exactly what actions bazel executes and how it executes them, you can use
--subcommands: https://bazel.build/docs/user-manual#subcommandsNote that that will also print all the commands executed to build everything in the build request, so there might be a lot of things to look through. But the test execution should be one of the last items.
There is also
aqueryto examine all the actions in a build target: https://bazel.build/query/aqueryThere is also
--run_under: https://bazel.build/docs/user-manual#run_under. From this disucussion: https://github.com/bazelbuild/bazel/issues/2815 you would usebazel runinstead ofbazel test:bazel run <test> --run_under='gdb --args'Addition:
You could also inspect the cc_test target using an asepct and have it print out the command. It's somewhat specific to cc_test though (i.e. manually inspects the env and args attributes and assembles the command line):