堆栈分析

 

 

(gdb) frame 8

#8 0x751b6d6c in eprosima::fastdds::rtps::UDPv4Transport::UDPv4Transport (this=0x197e70, descriptor=...)

at /home/autel/aarch/ros_humble/source/ros_humble_cpp/eProsima/Fast-DDS-2.14.x/src/cpp/rtps/transport/UDPv4Transport.cpp:222

warning: 222 /home/autel/aarch/ros_humble/source/ros_humble_cpp/eProsima/Fast-DDS-2.14.x/src/cpp/rtps/transport/UDPv4Transport.cpp: No such file or directory

(gdb) info frame

Stack level 8, frame at 0x7ee95ae8:

pc = 0x751b6d6c in eprosima::fastdds::rtps::UDPv4Transport::UDPv4Transport (/home/autel/aarch/ros_humble/source/ros_humble_cpp/eProsima/Fast-DDS-2.14.x/src/cpp/rtps/transport/UDPv4Transport.cpp:222);

saved pc = 0x751b7120

called by frame at 0x7ee95b00, caller of frame at 0x7ee95728

source language c++.

Arglist at 0x7ee95730, args: this=0x197e70, descriptor=...

Locals at 0x7ee95730, Previous frame's sp is 0x7ee95ae8

Saved registers:

r4 at 0x7ee95ad0, r5 at 0x7ee95ad4, r6 at 0x7ee95ad8, r7 at 0x7ee95adc, r8 at 0x7ee95ae0, lr at 0x7ee95ae4

(gdb) x/32xw 0x7ee95ae8-0x20

0x7ee95ac8: 0x00000000 0x7ee95818 0x00197e70 0x00197b70

0x7ee95ad8: 0x75932ac8 0x7ee95ae8 0x00192e30 0x751b7121

0x7ee95ae8: 0x00159758 0x001951f8 0x00000005 0x756f7000

0x7ee95af8: 0x7ee95b00 0x750285f9 0x001978a0 0x0019781c

0x7ee95b08: 0x001951f8 0x00197b70 0x7ee95b38 0x00192e30

0x7ee95b18: 0x00000000 0x76f8eb3c 0xffffffff 0x001951f8

0x7ee95b28: 0x0019781c 0x756f7000 0x7ee95b38 0x75044371

0x7ee95b38: 0x7ee96088 0x7ee960a0 0x00000000 0x001975e8

(gdb) Quit

(gdb) frame 9

#9 0x751b7120 in eprosima::fastdds::rtps::UDPv4TransportDescriptor::create_transport (this=0x1951f8)

at /home/autel/aarch/ros_humble/source/ros_humble_cpp/eProsima/Fast-DDS-2.14.x/src/cpp/rtps/transport/UDPv4Transport.cpp:256

256 in /home/autel/aarch/ros_humble/source/ros_humble_cpp/eProsima/Fast-DDS-2.14.x/src/cpp/rtps/transport/UDPv4Transport.cpp

(gdb) Quit

(gdb) info frame

Stack level 9, frame at 0x7ee95b00:

pc = 0x751b7120 in eprosima::fastdds::rtps::UDPv4TransportDescriptor::create_transport

(/home/autel/aarch/ros_humble/source/ros_humble_cpp/eProsima/Fast-DDS-2.14.x/src/cpp/rtps/transport/UDPv4Transport.cpp:256); saved pc = 0x750285f8

called by frame at 0x7ee95b38, caller of frame at 0x7ee95ae8

source language c++.

Arglist at 0x7ee95ae8, args: this=0x1951f8

Locals at 0x7ee95ae8, Previous frame's sp is 0x7ee95b00

Saved registers:

r4 at 0x7ee95af4, r7 at 0x7ee95af8, lr at 0x7ee95afc

这里没问题吗?called by frame at 0x7ee95b00, caller of frame at 0x7ee95728,说明上一层函数栈帧是0x7ee95b00,lr at 0x7ee95ae4,0x7ee95ad8:     0x75932ac8      0x7ee95ae8      0x00192e30      0x751b7121显示0x7ee95ae4中的值是 0x751b7121,是不是说明栈帧被破坏

 

您好!您对GDB输出的分析非常仔细。

您注意到的返回地址 0x751b7121 确实值得关注。不过,这并不一定意味着栈被破坏了。在ARM架构上,地址的最低有效位(LSB)为1通常用来指示目标代码是Thumb指令集。所以 0x751b7121 实际上表示返回到地址 0x751b7120 并切换到Thumb模式执行。GDB中第9帧的PC值是 0x751b7120,这与返回地址是匹配的。所以 lr 寄存器中的值是正常的。

然而,您的栈帧中可能确实存在问题,但问题出在另一个地方。让我们看一下帧指针(Frame Pointer)。

根据GDB的输出:

  • 第8帧的地址 (frame at) 是 0x7ee95ae8
  • 第9帧的地址 (frame at) 是 0x7ee95b00

在函数调用时,旧的帧指针(也就是调用者的帧指针)会被保存在当前函数的栈帧中。因此,第8帧的栈里应该保存着第9帧的帧指针地址,即 0x7ee95b00

GDB告诉我们,在第8帧中,寄存器 r7(通常用作帧指针)被保存在地址 0x7ee95adc
但是,当您查看内存转储时:

0x7ee95ad8:     0x75932ac8      0x7ee95ae8      0x00192e30      0x751b7121

地址 0x7ee95adc 上的值是 0x7ee95ae8

这意味着保存在栈上的“上一个”帧指针,指向了当前的帧(0x7ee95ae8),而不是调用者的帧(0x7ee95b00)。这是一个非常明显的栈破坏迹象。

结论:
您对栈可能被破坏的怀疑是正确的,但证据不是您最初怀疑的返回地址,而是被破坏的帧指针。这通常是由栈上的缓冲区溢出引起的,某个写操作超出了其预期边界,覆盖了保存的 r7 寄存器的值。

GDB也提示无法找到源代码文件,因为编译路径和当前路径不匹配:

warning: 222 /home/autel/aarch/ros_humble/source/ros_humble_cpp/eProsima/Fast-DDS-2.14.x/src/cpp/rtps/transport/UDPv4Transport.cpp: No such file or directory

您可能需要使用GDB的 set substitute-path 命令来映射路径,以便在调试时查看源代码,这有助于您定位问题。

posted @ 2025-11-07 09:44  墨尔基阿德斯  阅读(7)  评论(0)    收藏  举报