大家好,非常感谢昨天的回复。上个问题已经解决,但是还是有新的问题。
源代码我附在下面了。
请问大家,如何用gdb调试这样一个小工程呢?
现在我用gdb 可以list main.cpp里的源代码也可以在main.cpp里设置断点,但是看不见 mytool1.cpp 和mytool2.cpp 的内容,也不知道怎么在这两个文件里设置断点。run 的时候,用step 会显示:
(gdb) s
This is mytool1 print hello
26 mytool2_print("hello,husince");
(gdb) s
Breakpoint 3, 0x00000000004005dc in mytool2_print ()
Current language: auto; currently asm
(gdb) s
Single stepping until exit from function _Z13mytool2_printPc,
which has no line number information.
This is mytool2 print hello,hu yi ng wei
main (argc=1, argv=0x7fffc0e14238) at main.cpp:27
27 }
Current language: auto; currently c++
我希望能够步进调试时进入到mytool2.cpp 看到是哪个函数在运行 或者 至少能在mytool2.cpp里设置断点,运行到那里的时候可以停下看看结果。
网上找到的都是调试一个单文件的test.c,我也在makefile文件里加-g了,gdb 的官网的manual 也下载查了,但是还是没什么启发。
请指点一下,最好具体点。非常感谢。
我的程序很简单,是在网上找到的,代码如下:
文件一: main.cpp
#include "mytool1.h"
#include "mytool2.h"
#include "stdio.h"
int main(int argc, char **argv) {
mytool1_print("hello");
mytool2_print("hello,husince");
}
文件二: mytool1.cpp
#include "mytool1.h"
#include "stdio.h"
void mytool1_print(char *print_str){
printf("This is mytool1 print %s\n",print_str);
}
文件三:mytool1.h
#ifndef _MYTOOL_1_H
#define _MYTOOL_1_H
void mytool1_print(char *print_str);
#endif
文件四:mytool2.cpp
#include "mytool2.h"
#include "stdio.h"
void mytool2_print(char *print_str){
printf("This is mytool2 print %s\n", print_str);
}
文件五:mytool2.h
#ifndef _MYTOOL_2_H
#define _MYTOOL_2_H
void mytool2_print(char *print_str);
#endif
以上是源文件, 还写了个makefile:
x : main.o mytool1.o mytool2.o
g++ -g -o x $^
main.o : main.cpp mytool1.h mytool2.h
g++ -g -c main.cpp
mytoo11.o : mytool1.cpp mytool1.h
g++ -g -c mytool1.cpp
mytool2.o : mytool2.cpp mytool2.h
g++ -g -c mytool2.cpp
clean :
rm x main.o mytool1.o mytool2.o
求助:如何用gdb调试多个源文件的工程?(已经解决)
-
- 帖子: 6
- 注册时间: 2007-12-22 19:38
求助:如何用gdb调试多个源文件的工程?(已经解决)
上次由 husince 在 2009-09-02 20:47,总共编辑 1 次。
-
- 帖子: 6
- 注册时间: 2007-12-22 19:38
Re: 求助:如何用gdb调试多个源文件的工程?
最后是baidu到这个问题的解决的,google花了很久时间也没结果。其实很方便
1。 对每个文件都加-g编译 g++ -g -c ...(其实原来已经这么做了)
2。在运行时对main.cpp的mytool1_print("hello");该行设置断点,然后用s命令(step)就可以进入mytool1.cpp文件了。
可以用list查看,并加新的断点,继续调试。
1。 对每个文件都加-g编译 g++ -g -c ...(其实原来已经这么做了)
2。在运行时对main.cpp的mytool1_print("hello");该行设置断点,然后用s命令(step)就可以进入mytool1.cpp文件了。
可以用list查看,并加新的断点,继续调试。
- BigSnake.NET
- 帖子: 12522
- 注册时间: 2006-07-02 11:16
- 来自: 廣州
- 联系:
Re: 求助:如何用gdb调试多个源文件的工程?(已经解决)
list finename.c:linenumber
^_^ ~~~
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。