- 以这个程序为例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#include <iostream> #include <mysql/mysql.h> #include <stdio.h> using namespace std; #define SERVER "localhost" #define USER "root" #define PASSWORD "Piercing77#" #define DATABASE "shfuture" int main() { MYSQL *connect; connect=mysql_init(NULL); if (!connect) { cout<<"MySQL Initialization failed"; return 1; } connect=mysql_real_connect(connect, HOST, USER, PASSWORD , DATABASE ,0,NULL,0); if (connect) { cout<<"connection Succeeded\n"; } else { cout<<"connection failed\n"; } |
- 编译 ,注意要带 -g , 因为是c++ ,所以用 g++, c程序用 gcc
1 |
g++ -g -o connAndQuery connAndQuery.c $(mysql_config --libs) |
- 启动gdb
1 |
gdb ./connAndQuery |
- 流程控制
break line number : 在某行下断点 ,centos 显示行号 ctrl + c
run 执行
next 执行一步
c : 执行到完
break
- gdb 带参数执行 :
1 |
gdb --args executablename arg1 arg2 arg3 |
- 参考文章
http://www.math.bas.bg/~nkirov/2005/netb151/debugging-with-gdb.html
http://kirste.userpage.fu-berlin.de/chemnet/use/info/gdb/gdb_6.html