Linux GDB 检查内存权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10780540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GDB examine memory permissions
提问by viji
I've an address in memory and I want to find out the permissions (r/w/x) of that memory address.
我在内存中有一个地址,我想找出该内存地址的权限(r/w/x)。
E.g.
例如
char *s = "hello";
Here, the string literal "hello" is stored in read-only memory. When running the program through gdb, is there a possibility to check out the permissions for that memory address (whether only read is permitted or etc) ?
在这里,字符串文字“hello”存储在只读存储器中。通过 gdb 运行程序时,是否有可能检查该内存地址的权限(是否只允许读取等)?
采纳答案by Michael Foukarakis
You can first find where s
is pointing to:
您可以先找到s
指向的位置:
(gdb) print s
= 0x400dbc "foo"
and then find the section in which it's in:
然后找到它所在的部分:
(gdb) maintenance info sections
Exec file:
`/home/mfukar/tmp', file type elf64-x86-64.
...sections...
0x00400db8->0x00400dfb at 0x00000db8: .rodata ALLOC LOAD READONLY DATA HAS_CONTENTS
...more sections...
and look for the READONLY
flag.
并寻找READONLY
旗帜。
Alternatively, look into /proc/PID/maps
where PID
is the pid of the process you're debugging and you can get with info proc
.
或者,查看您正在调试的进程的 pid/proc/PID/maps
在哪里PID
,您可以使用info proc
.