我遇到了 GDB 和内核空间中分配的一些缓冲区的问题。缓冲区由内核模块分配,该内核模块应该分配连续的内存块,然后通过 mmap() 调用将内存映射到用户空间。然而,GDB 似乎无法随时访问这些块。例如,在 GDB 中遇到断点后:
(gdb) x /10xb 0x4567e000
0x4567e000: Cannot access memory at address 0x4567e000
但是,查看 /proc//smaps 中应用程序当前映射的内存区域显示:
4567e000-456d3000 rwxs 8913f000 00:0d 883 /dev/cmem
Size: 340 kB
Rss: 340 kB
Pss: 0 kB
Shared_Clean: 0 kB
Shared_Dirty: 0 kB
Private_Clean: 0 kB
Private_Dirty: 0 kB
Referenced: 0 kB
Swap: 0 kB
我什至正在研究这个的原因是因为在运行期间的某个时刻,这个缓冲区地址(或以类似方式分配的另一个)会导致 SIGSEGV。
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x49aea490 (LWP 652)]
0x402e4ea8 in fwrite () from /lib/libc.so.6
(gdb)
(gdb)
(gdb) where
#0 0x402e4ea8 in fwrite () from /lib/libc.so.6
#1 0x000eb394 in EncryptedWriter::Write (this=0x198600, buffRaw=0x4567e000 <Address 0x4567e000 out of bounds>, iLenRaw=719) at encrypted_writer.cpp:397
#2 0x0006b0f4 in EncryptionWrapper::Write (this=0x3ab2698, buffer=0x4567e000, size=719) at encryption.cpp:54
尽管缓冲区在崩溃之前已被大量使用,并且 /proc//smaps 文件仍显示此缓冲区要像上面那样映射,但仍会发生此段错误。
我完全不知道为什么会发生这种情况,以及为什么映射在 /proc 中似乎有效但在 GDB 中却从来没有。