0

在mongodb中,类游标被定义为'Cursor : boost::noncopyable',然后有很多类是从它派生的。我想知道客户端的给定操作使用了哪个 XXXCursor。所以我想在 Cursor::Cursor 上设置一个断点。但失败了。

(gdb) b mongo::Cursor::Cursor
the class mongo::Cursor does not have any method named Cursor
Hint: try 'mongo::Cursor::Cursor<TAB> or 'mongo::Cursor::Cursor<ESC-?>
(Note leading single quote.)
Make breakpoint pending on future shared library load? (y or [n]) n

(gdb) ptype mongo::Cursor
type = class mongo::Cursor : private boost::noncopyable_::noncopyable {
  public:
    ~Cursor(int);
    virtual bool ok(void);
    bool eof(void);
    virtual mongo::Record * _current(void);
    virtual mongo::BSONObj current(void);
    virtual mongo::DiskLoc currLoc(void);
    virtual bool advance(void);
    virtual mongo::BSONObj currKey(void) const;
    ....
}
(gdb) list mongo::Cursor::Cursor
**the class mongo::Cursor does not have any method named Cursor
Hint: try 'mongo::Cursor::Cursor<TAB> or 'mongo::Cursor::Cursor<ESC-?>**
(Note leading single quote.)

但是我写了一个类似的程序

#include <iostream>
#include <boost/utility.hpp>
class Base : boost::noncopyable {
public:
    void printx() {std::cout<< getx() <<"\n" ;}
    virtual int getx()=0;
};


class P : public Base {
public:
    int x;
    virtual int getx() { return x*3;}
    P(int c){ x= c;}
};

int main(){
    P p(2);
    p.printx();
    return 0;
}

我可以成功地在 Base::Base 上设置断点。

你知道为什么我不能在 mongo::Cursor::Cursor 上设置断点吗?

mongo::Cursor 在这里定义: https ://github.com/mongodb/mongo/blob/master/src/mongo/db/cursor.h

4

1 回答 1

0

至于你的例子。如果我这样编译它:

g++ -O0 -g -m64 -I ./boost_1_53_0 main.cpp

我可以设置一个断点Base::Base,我看到Base::Base一个符号:

>nm -C a.out | grep Base::Base
0000000000400a4e W Base::Base()

如果我像这样编译它(优化级别 O2):

g++ -O2 -g -m64 -I ./boost_1_53_0 main.cpp

我不认为 Base::Base 是一个符号:

>nm -C a.out | grep Base::Base
>

并且不能设置断点:

(gdb) b Base::Base
the class Base does not have any method named Base
Hint: try 'Base::Base<TAB> or 'Base::Base<ESC-?>

因此,作为第一步,请确保在您的程序或共享库中有 mongo::Cursor::Cursor 作为符号。可以优化出来。

于 2013-08-13T13:51:06.473 回答