Examining mmaped addresses using GDB

后端 未结 7 1966
[愿得一人]
[愿得一人] 2020-12-13 21:19

I\'m using the driver I posted at Direct Memory Access in Linux to mmap some physical ram into a userspace address. However, I can\'t use GDB to look at any of the address;

7条回答
  •  鱼传尺愫
    2020-12-13 21:37

    To access the mmapped memory, GDB will call ptrace, which will then call __access_remote_vm() to access the mmapped memory. If the memory is mapped with flags such as VMIO | VM_PFNMAP (for example, remap_pfn_range() sets them), GDB will access the memory though vm's access method defined by users.

    Instead of writing our own implementation for access(), kernel already provides a generic version called generic_access_phys(), and this method could be easily linked via vm_operations_struct as the /dev/mem device did:

    static const struct vm_operations_struct mmap_mem_ops = {
            .access = generic_access_phys };
    
    int mmap_mem()
    {
        .... ....
        vma->vm_ops = &mmap_mem_ops;
        .... ....
    }
    

提交回复
热议问题