GDB不能访问mmap()的内核分配内存? [英] GDB can't access mmap()'d kernel allocated memory?

查看:1355
本文介绍了GDB不能访问mmap()的内核分配内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,GDB和一些缓冲区分配在内核空间。缓冲区由内核模块分配,内核模块应分配连续的内存块,然后通过mmap()调用将内存映射到用户空间。然而,GDB似乎不能在任何时候访问这些块。例如,在GDB中击中断点后:

 (gdb)x / 10xb 0x4567e000 
0x4567e000:但是,查看应用程序在/ proc / smaps中当前映射的内存区域显示:

  4567e000-456d3000 rwxs 8913f000 00:0d 883 / dev / cmem 
大小:340 kB
Rss :340 kB
Pss:0 kB
Shared_Clean:0 kB
Shared_Dirty:0 kB
Private_Clean:0 kB
Private_Dirty:0 kB
参考:0 kB
Swap:0 kB

在运行期间的某个点,该缓冲器地址(或以类似方式分配的另一个)引起SIGSEGV。

 编程接收信号SIGSEGV,分段故障。 
[切换到线程0x49aea490(LWP 652)]
0x402e4ea8在fwrite()从/lib/libc.so.6
(gdb)
(gdb)
(gdb)其中
#0 0x402e4ea8在fwrite()中从/lib/libc.so.6
#1 0x000eb394在EncryptedWriter :: Write(this = 0x198600,buffRaw = 0x4567e000< Address 0x4567e000 out of encryption.cpp中的encrypted_writer.cpp:397
#2的0x0006b0f4:EncryptionWrapper :: Write(this = 0x3ab2698,buffer = 0x4567e000,size = 719):54

这种segfault发生,尽管事实上缓冲区已被大量使用直到崩溃,并且/ proc // smaps文件仍然



我完全失去了为什么会发生这种情况,以及为什么映射在/ proc中似乎有效,但从来没有gdb。

解决方案

关于为什么gdb无法访问你想要的内存,我相信Linux不能通过< a href =http://www.kernel.org/doc/man-pages/online/pages/man2/ptrace.2.html> ptrace()。



根据cmemk.c(我在 linuxutils_2_25.tar.gz ),mmap()确实设置了内存中的VM_IO标志。



要访问此内存gdb,给你的程序添加一个函数,读取这个内存并让gdb调用这个函数。


I'm running into an issue with GDB and some buffers allocated in kernel space. The buffers are allocated by a kernel module that is supposed to allocate contiguous blocks of memory, and then memory mapped into userspace via a mmap() call. GDB, however, can't seem to access these blocks at any time. For example, after hitting a breakpoint in GDB:

(gdb) x /10xb 0x4567e000
0x4567e000:     Cannot access memory at address 0x4567e000

However, looking at the application's currently mapped memory regions in /proc//smaps shows:

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

The reason I'm even looking into this is because at some point during the run, this buffer address (or another allocated in a similar manner) causes a 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

This segfault occurs despite the fact that the buffer had been used heavily up until the crash, and the /proc//smaps file still shows this buffer to be mapped as above.

I am completely at a loss as to why this might be happening, and why the mapping seems valid in /proc but never in GDB.

解决方案

About why gdb cannot access the memory you want, I believe Linux does not make I/O memory accessible via ptrace().

According to cmemk.c (which I found in linuxutils_2_25.tar.gz), mmap() does indeed set the VM_IO flag on the memory in question.

To access this memory from gdb, add a function to your program that reads this memory and have gdb call this function.

这篇关于GDB不能访问mmap()的内核分配内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆