3

I'm trying to read (hopefully write as well) to the memory mapped hardware registers in a qemu virtual machine using gdb (remote connected). But it's just not working:

(gdb) p *0x2000000
Cannot access memory at address 0x20000000

But if I log in to the machine and do

# devmem 0x2000000
0xE321F0D3

This works fine. Clearly gdb isn't getting its info from /dev/mem though. I've enabled all compile-time debug flags that I could think of, I can place breakpoints, step through code and dereference pointers associated with a symbol just fine. But most raw pointer dereferences fail.

For the record this is how I launched qemu:

qemu-system-arm -M versatilepb -kernel output/images/zImage     \
                -dtb output/images/versatile-pb.dtb             \
                -drive file=output/images/rootfs.ext2,if=scsi   \
                -append "root=/dev/sda console=ttyAMA0,115200 nokaslr norandmaps printk.devkmsg=on printk.time=y"  \
                -nographic -s

where I added nokaslr etc because I thought it would make a difference. It clearly did not. Anyone know what's going on here?

0

gdb and devmem are looking at two different things. gdb is looking at location 0x20000000 as mapped into your process address space, which is different from process to process (it has to be, or else swap files and page tables would essentially be useless.) devmem is looking at the file /dev/mem, which looks directly at physical memory.

Why does process address space not expose all physical address locations to a process? The main reason is that it would be an enormous security breach: you don't want a random process to be able to read and write data from memory that they don't own (otherwise they could trivially bypass security.) Additionally, as the devmem page puts it, "Some physical addresses are hardware registers; writing or even reading them can cause your computer/device [to] crash or melt down or explode. You've been warned!"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.