|
楼主 |
发表于 2006-4-13 15:55:45
|
显示全部楼层
再贴详细一点:
很郁闷,不知为啥。代码如下(没有贴.h文件了)
hello.cpp:
#include "hello.h"
#include "compute.h"
#include <iostream>
Test::Test()
{
}
Test::~Test()
{
}
void Test::print()
{
std::cout<<"A:Hello,this is my first c++ program"<<std::endl;
std::cout<<"B:Hello,this is my first c++ program"<<std::endl;
std::cout<<"C:Hello,this is my first c++ program"<<std::endl;
std::cout<<"D:Hello,this is my first c++ program"<<std::endl;
std::cout<<"------------------------------------"<<std::endl;
std::cout<<"Call the methods of Compute now:"<<std::endl;
Compute compute;
std::cout<<"3+4="<<compute.add(3,4)<<std::endl;
std::cout<<"3-4="<<compute.sub(3,4)<<std::endl;
std::cout<<"3*4="<<compute.mul(3,4)<<std::endl;
std::cout<<"3/4="<<compute.dev(3,4)<<std::endl;
}
int main()
{
Test test;
test.print();
return 0;
}
compute.cpp:
#include "compute.h"
Compute::Compute()
{
}
Compute::~Compute()
{
}
int Compute::add(int i,int j)
{
return i+j;
}
int Compute::sub(int i,int j)
{
return i-j;
}
int Compute::mul(int i,int j)
{
return i*j;
}
float Compute::dev(int i,int j)
{
return i/j;
}
Makefile:
all:hello.o compute.o
g++ -g -o hello hello.o compute.o
compute.o:compute.h compute.cpp
g++ -g -c compute.cpp
hello.o:hello.cpp hello.h
g++ -g -c hello.cpp
(1)db hello进入调试以后,使用list:
(gdb) list
20 Compute compute;
21 std::cout<<"3+4="<<compute.add(3,4)<<std::endl;
22 std::cout<<"3-4="<<compute.sub(3,4)<<std::endl;
23 std::cout<<"3*4="<<compute.mul(3,4)<<std::endl;
24 std::cout<<"3/4="<<compute.dev(3,4)<<std::endl;
25 }
26
27 int main()
28 {
29 Test test;
(2)设置断点:
(gdb) break 21
Breakpoint 1 at 0x80487ee: file hello.cpp, line 21.
(gdb)
(3)运行
(gdb) run
Starting program: /usr/c/test/hello
A:Hello,this is my first c++ program
B:Hello,this is my first c++ program
C:Hello,this is my first c++ program
D:Hello,this is my first c++ program
------------------------------------
Call the methods of Compute now:
Breakpoint 1, Test::print() (this=0xbfffea60) at hello.cpp:21
21 std::cout<<"3+4="<<compute.add(3,4)<<std::endl;
(gdb)
(4)step跟踪:
(gdb) step
3+4=7
22 std::cout<<"3-4="<<compute.sub(3,4)<<std::endl;
(gdb)
在这一步就跟踪不进去了!
我想直接在Compute类里设置断点(不能列出Compute类的代码,只能用方法设置了),结果如下:
(5)
(gdb) break Compute::add
the class Compute does not have any method named add
Hint: try 'Compute::add<TAB> or 'Compute::add<ESC-?>
(Note leading single quote.)
(gdb)
(6)按照楼上说的用list则是如下结果:
(gdb) l compute.cpp:0
No source file named compute.cpp.
(gdb) |
|