简短的回答是:选择您喜欢的任何“编辑器”,然后使用GDB控制台或简单的GDB前端来调试应用程序。调试器带有别致的ide,例如Netbeans对于C/ c++来说很糟糕。我使用Netbeans作为编辑器,Insight和GDB控制台作为调试器。
有了洞察力,您就有了一个漂亮的GUI和GDB的原始功能。
一旦您习惯了GDB命令,您就会开始爱上它,因为您可以做使用GUI永远无法做的事情。如果您使用的是GDB 7或更新版本,您甚至可以使用Python作为脚本语言。
这里的大多数人更关注ide的“编辑器”。然而,如果你正在用C/ c++开发一个大型项目,你可能会很容易地把70%以上的时间花在“调试器”上。高级ide的调试器至少落后于Visual Studio 10年。例如,Netbenas与Visual Studio有非常相似的接口。但是与Visual Studio相比,它的调试器有许多缺点。
Very slow to display even a array with only a few hundreds of elements
No highlighting for changed value ( By default, visual studio shows changed values in the watch windows in red)
Very limited ability to show memory.
You cannot modify the source code then continue to run. If a bug takes a long time to hit, you would like to change the source and apply the changes live and continue to run your application.
You cannot change the "next statement" to run. In Visual Studio, you can use "Set Next Statement" to change how your application runs. Although this feature could crash your application if not used properly, but it will save you a lot of time. For instance, if you found the state of your application is not correct, but you do not know what caused the problems, you might want to rerun a certain region of the your source codes without restarting your application.
No built-in support for STL such as vector, list, deque and map etc.
No watch points. You need to have this feature, when you need to stop your application right at the point a variable is changed. Intel based computers have hardware watch points so that the watch points will not slow down your system. It might takes many hours to find some hard-to-find bugs without using watch points. "Visual Studio" calls "watch pointer" as "Data BreakPoint".
这个清单可以长得多。
Netbeans或其他类似ide的缺点让我非常沮丧,所以我开始学习GDB本身。我发现GDB本身非常强大。广发银行并不具备上述所有的“缺点”。实际上,GDB非常强大,在许多方面甚至比Visual Studio还要好。我给你们看一个非常简单的例子。
例如,你有一个这样的数组:
struct IdAndValue
{
int ID;
int value;
};
IdAndValue IdAndValues[1000];
当应用程序停止时,您希望检查IdAndValues中的数据。例如,如果你想在数组中找到特定“ID”的序数和值,你可以创建一个像下面这样的脚本:
define PrintVal
set $i=0
printf "ID = %d\n", $arg0
while $i<1000
if IdAndValues[$i].ID == $arg0
printf "ordinal = %d, value = %d\n", $i, IdAndValues[$i].vaue
set $i++
end
end
end
您可以在当前上下文中使用应用程序中的所有变量,包括您自己的变量(在本例中为$i)、传递的参数(在本例中为$arg0)以及所有GDB命令(内置或用户定义)。
使用GDB提示符中的PrintVal 1打印ID为“1”的值
顺便说一下,NetBeans确实附带了一个GDB控制台,但是通过使用控制台,您可能会使NetBeans崩溃。我相信这就是为什么控制台在NetBeans中默认是隐藏的