Windows下,Visual Studio系列的IDE(Visual Studio 2010/2013/2015/2017/2019/2022)都内置了C++调试引擎,可通过可视化的界面完成调试操作:在IDE里设置调试断点,然后按F5就可以开始调试了,简单又方便。而且功能强大,支持 断点调试、变量查看、单步执行、堆栈跟踪等等。
intdivision(int a, int b) { return (int)(a / b); }
intmain() { std::string name = "Spencer"; std::cout << "Hello, " << name << "!" << std::endl; int a = 5; int b = 0; int c = division(a, b); int d = add(c, 20); std::cout << "d = " << d << std::endl; return0; }
gdb ./demo02.out GNU gdb (Ubuntu 15.0.50.20240403-0ubuntu1) 15.0.50.20240403-git Copyright (C) 2024 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty"for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration"for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. <http://www.gnu.org/software/gdb/documentation/>.
--Type <RET> for more, q to quit, c to continue without paging-- <http://www.gnu.org/software/gdb/documentation/>.
--Type <RET> for more, q to quit, c to continue without paging-- For help, type"help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./demo02.out... <http://www.gnu.org/software/gdb/documentation/>.
--Type <RET> for more, q to quit, c to continue without paging--
--Type <RET> for more, q to quit, c to continue without paging-- --Type <RET> for more, q to quit, c to continue without paging-- For help, type"help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./demo02.out... (gdb) (gdb) q
1 2 3 4
gdb -q ./demo02.out Reading symbols from ./demo02.out... (gdb) (gdb) q