使用gdb&进行C ++调试淡褐色(& emacs) [英] C++ debugging with gdb & bazel (& emacs)

查看:77
本文介绍了使用gdb&进行C ++调试淡褐色(& emacs)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调试使用Bazel生成的可执行文件. gdb调试器丢失了Bazel生成的链接,并且无法向我展示C ++源代码.该如何解决?

I want to debug an executable generated with Bazel. The gdb debugger is lost with the links generated by Bazel and is not able to show me the C++ source code. How to fix that?

项目根目录为/home/.../Cpp/

./Cpp/
├── bazel-bin -> /home/picaud/.cache/bazel/_bazel_picaud...
├── bazel-Cpp -> /home/picaud/.cache/bazel/_bazel_picaud...
├── bazel-genfiles -> /home/picaud/.cache/bazel/_bazel_picaud...  
├── bazel-out -> /home/picaud/.cache/bazel/_bazel_picaud...   
├── bin
│   ├── BUILD
│   └── main.cpp
├── MyLib
│   ├── BUILD
│   ├── ....hpp
│   ├──  ...cpp
└── WORKSPACE

推荐答案

第一步是使用调试模式生成可执行文件:

The first step is to generate executables using the debug mode:

bazel build ... --compilation_mode=dbg -s

( -s 选项不是必需的,它仅显示已执行的命令,如果需要,可以将其删除)

(the -s option is not mandatory it only shows the executed commands, you can remove it if you want)

gdb调试:

您可以使用命令(从项目根目录)启动 gdb :

You can start gdb with this command (from your project root directory):

gdbtui bazel-bin/bin/main

->一切正常,您应该看到C ++源代码.

-> everything is okay, you should see your C++ source code.

发生错误:

cd bazel-bin/bin/
gdbtui main

在这种情况下,由于链接,gdb无法检索源代码.

In that case, because of the links, gdb is not able to retrieve the source code.

从Emacs进行gdb调试:

照常

M-x gdb 

在emacs提示符下,定义可执行文件的完整绝对路径:

In the emacs prompt define the complete absolute path to the executable:

gdb -i=mi /home/picaud/.../Cpp/bazel-bin/bin/main

现在,在 gdb缓冲区中,您必须通过定义项目根目录(WORKSPACE文件所在的位置)的绝对路径来告诉gdb在哪里找到源:

Now in the gdb buffer you must tell gdb where to find source by defining your absolute path to the project root directory (where your WORKSPACE file is):

set directories /home/picaud/.../Cpp

现在emacs gdb命令应该可以正常工作了,您可以照常调试.

Now the emacs gdb command should work properly and you can debug as usual.

(嗯,这是一个简单的解决方法,只是一条注释,也许可以帮助您...)

(well this was an easy fix, just a note that maybe can help...)

这篇关于使用gdb&进行C ++调试淡褐色(& emacs)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆