在Ubuntu上进行C++调试,推荐使用以下几种工具:
GNU调试器(GDB):
sudo apt-get update
sudo apt-get install gdb
编译你的C++程序时添加 -g
标志以包含调试信息:g++ -g -o my_program my_program.cpp
gdb my_program
在GDB中,你可以使用各种命令进行调试,如设置断点、单步执行、查看变量值等。Visual Studio Code(VS Code):
.vscode
文件夹,并在其中创建 tasks.json
和 launch.json
文件来配置编译和调试任务。Valgrind:
sudo apt-get install valgrind
valgrind --leak-check=full ./my_program
Valgrind会报告内存泄漏、越界访问等问题。Eclipse:
这些工具各有优势,可以根据个人需求和偏好选择使用。