gdb 共享库中的错误文件名

gdb wrong filename in shared library

尝试学习 fmbt,在 c++ test 它使用共享库,共享库的源文件是从另一个文件预处理的,如下面的 make 输出所示:

g++ -O0 -g -Wall -pedantic -I../../src -I/usr/include/fmbt -fPIC   -c -o mycounter.o mycounter.cc

fmbt-aalc -o mycountertest.cc mycountertest.cc.aal

g++ -O0 -g -Wall -pedantic -I../../src -I/usr/include/fmbt -fPIC   -c -o mycountertest.o mycountertest.cc

g++ -shared -o mycountertest.so mycounter.o mycountertest.o 

当我尝试调试共享库时,它总是转到 mycountertest.cc.aal 文件:

ubuntu@i-hics5mzq:~/fMBT/examples/c++-unittest$ gdb  fmbt
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.3) 7.7.1
Copyright (C) 2014 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:
<http://www.gnu.org/software/gdb/bugs/>.

Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from fmbt...done.
(gdb) break awrapper.cc:149
Breakpoint 1 at 0x585e06: file awrapper.cc, line 149.
(gdb) run test.conf
Starting program: /usr/local/bin/fmbt test.conf
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
<fmbt_log>
<version>
    0.38-1

</version>
<conf_load>
    <conf_file name="test.conf"/>
    <end_time time="1501727367.947618"/>
</conf_load>
<conf_execute>
    <action_name name="iCreate"/>
    <action_name name="iDestroy"/>
    <action_name name="iIncrement"/>
    <action_name name="iReset"/>
    <action_name name="iCount"/>
    <test_engine>
        <tags enabled=""/>
        <status steps="0" coverage="0.000000" scov="0.000000e+00"/>
        <current_time time="1501727366.958535"/>
        <suggested_action type="input" name="iCreate" time="1501727366.958600"/>


Breakpoint 1, Awrapper::execute (this=0x93b6d0, action=std::vector of length 1, capacity 1 = {...}) at awrapper.cc:149
149       int tmp=ada->adapter_execute(1,"");
(gdb) s
_gen_mycountertest::adapter_execute (this=0x94ce50, action=1, param=0x65f8b0 "") at mycountertest.cc.aal:27
27              adapter() {

为什么 gdb 不使用生成的 mycountertest.cc 文件。

这里是mycountertest.cc的内容,class这个特殊的名字有什么关系吗? :

#line 3 "mycountertest.cc.aal"

        #include "mycounter.h"
    #include "aal.hh"

class _gen_mycountertest:public aal {
private:

#line 6 "mycountertest.cc.aal"
//variables

        MyCounter* mycounter;
        int value;


//action1: "iCreate"

#line 17 "mycountertest.cc.aal"
bool action1_guard(const std::string& name) {
{
 return mycounter == NULL; 
}
return true;//default
}

why gdb is not using the generated mycountertest.cc file

因为被告知不要这样做。特别是这一行:

#line 17 "mycountertest.cc.aal"
bool action1_guard(const std::string& name) {

告诉 GCC 告诉 GDB 接下来的代码是从 mycountertest.cc.aal 的第 17 行生成的,所以这就是 GDB 将显示的内容。

通常这正是生成代码所需要的。

您可以在编译之前安全地从 mycountertest.cc 中删除 #line 指令,然后 GDB 将显示生成的源代码:

fmbt-aalc mycountertest.cc.aal | sed -e '/^#line/d' > mycountertest.cc