1
votes

I found two links showing how debugging with gdb under bazel should work (link 1, link 2).

Both links state that launching a debug session works when invoking the following command:

bazel run --compilation_mode=dbg --run_under=gdb //my:target

When I run the command, gdb starts just fine, loading the symbols and everything, but then immediately quits. The output is the same as shown in here (from link 2).

The first link also mentions the --direct_run-argument, but this argument does not work either. gdb instantly quits and the following message, which is appended after the output of gdb (from the previous link), is shown:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = "en_US.ISO-8859-1",
        LC_ALL = "en_US.ISO-8859-1",
        LC_MEASUREMENT = "de_DE.UTF-8",
        LC_PAPER = "de_DE.UTF-8",
        LC_MONETARY = "de_DE.UTF-8",
        LC_NAME = "de_DE.UTF-8",
        LC_CTYPE = "en_US.ISO-8859-1",
        LC_ADDRESS = "de_DE.UTF-8",
        LC_NUMERIC = "de_DE.UTF-8",
        LC_TELEPHONE = "de_DE.UTF-8",
        LC_IDENTIFICATION = "de_DE.UTF-8",
        LC_TIME = "de_DE.UTF-8",
        LANG = "en_US.ISO-8859-1"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

What am I doing wrong? How can I interact with gdb?

Thanks in advance.

1
what is your bazel version?Till Brychcy
@TillBrychcy version is 0.13.0Mike van Dyke
As an alternative, maybe you can try this procedure: stackoverflow.com/questions/45812725/…Picaud Vincent
@PicaudVincent That was my initial way of debugging, but it was kind of cumbersome. Take a look at the reply I have posted under Tom Tromeys answer. Maybe you're interested in that script aswell. Can be invoked like this: ./bazel-run.sh --compilation_mode=dbg --run_under=gdb //my:targetMike van Dyke
@MikevanDyke thanks for the clarification, I will have a look.Picaud Vincent

1 Answers

1
votes

Another message in that thread (https://groups.google.com/d/msg/bazel-discuss/Mu95dnuA2MQ/I2BDu0SDGAAJ) points out that bazel doesn't pass the tty to gdb's stdin. What you are seeing is what you would expect if you invoke gdb without stdin attached:

$ gdb -silent -nx  < /dev/null
(gdb) quit

One option for a workaround might be to write a wrapper script that invokes gdb < /dev/tty.