我在QNX GDB服务器上遇到一些困难

时间:2019-02-11 09:00:45

标签: c++ gdb

为简化问题,我重新编写了一个样本项目。现在我有三个文件:

func.h

int func();

func.cpp

#include "func.h"
#include <stdio.h>
int func(){
   printf("In func()\n");
   return 0;
}

helloworld.cpp

#include <stdio.h>
#include "func.h"

int main(){
   printf("in main\n");
   func();
   return 0;
}

我使用:

编译了项目
aarch64-unknown-nto-qnx7.0.0-g++ -g -fPIC -shared func.cpp -o libFunc.so

aarch64-unknown-nto-qnx7.0.0-g++ -g helloworld.cpp libFunc.so -o testApp

然后我将动态库libFunc.so和二进制执行程序testApp压缩到qnx目标。目标机器路径是/ home / user / test

在目标计算机控制台中,将PATH导出为

export LD_LIBRARY_PATH=/home/user/test:$LD_LIBRARY_PATHI

然后执行命令pdebug 8888

在主机上,我按如下方式运行调试:

ntoaarch64-gdb
Type "apropos word" to search for commands related to "word".
(gdb)file testApp
Reading symbols from testApp...done.
(gdb)target qnx 172.20.102.169:8888
Remote debugging using 172.20.102.169:8888 
Remote target is little-endian
(gdb) upload testApp /home/user/test/testApp
(gdb) b main
Breakpoint 1 at 0xb38: file helloworld.cpp, line 5.
(gdb) l
1   #include <stdio.h>
2   #include "func.h"
3
4   int main(){
5       int i = 0;
6       int j = 0;
7       i++;
8       j++;
9       func();
10      return 0;
(gdb) b 9
Breakpoint 2 at 0xb58: file helloworld.cpp, line 9.
gdb) r
Starting program: /sda/tmp/testApp
Remote: /home/user/testApp
Breakpoint 1, main () at helloworld.cpp:5
5       int i = 0;
(gdb) c
Continuing.

Breakpoint 2, main () at helloworld.cpp:9
9       func();
(gdb) s
Warning:
Cannot insert breakpoint 0.
Cannot access memory at address 0x100000001

0x00000000780137d0 in ?? ()

断点函数有内存错误。

当程序在断点2(在func之前)运行时,我键入命令disassemble

(gdb) disassemble

Dump of assembler code for function main():
0x00000000100c8b30 <+0>:    stp x29, x30, [sp,#-32]!
0x00000000100c8b34 <+4>:    mov x29, sp
0x00000000100c8b38 <+8>:    str wzr, [x29,#24]
0x00000000100c8b3c <+12>:   str wzr, [x29,#28]
0x00000000100c8b40 <+16>:   ldr w0, [x29,#24]
0x00000000100c8b44 <+20>:   add w0, w0, #0x1
0x00000000100c8b48 <+24>:   str w0, [x29,#24]
0x00000000100c8b4c <+28>:   ldr w0, [x29,#28]
0x00000000100c8b50 <+32>:   add w0, w0, #0x1
0x00000000100c8b54 <+36>:   str w0, [x29,#28]
=> 0x00000000100c8b58 <+40>:    bl  0x100c88e0 <_Z4funcv@plt>
0x00000000100c8b5c <+44>:   mov w0, #0x0                    // #0
0x00000000100c8b60 <+48>:   ldp x29, x30, [sp],#32
0x00000000100c8b64 <+52>:   ret
End of assembler dump.

您可以看到_Z4funcv@plt被省略。

如果我运行stepi,则结果为:

(gdb) stepi
0x00000000100c88e0 in func()@plt ()
(gdb)
0x00000000100c88e4 in func()@plt ()
(gdb)
0x00000000100c88e8 in func()@plt ()
(gdb)
0x00000000100c88ec in func()@plt ()
(gdb)
0x00000000780137d0 in ?? ()
(gdb)
0x00000000780137d4 in ?? ()
(gdb)

0 个答案:

没有答案