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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:32:13  来源:igfitidea点击:

GDB examine memory permissions

clinuxgccgdbvirtual-address-space

提问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 sis 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 READONLYflag.

并寻找READONLY旗帜。

Alternatively, look into /proc/PID/mapswhere PIDis the pid of the process you're debugging and you can get with info proc.

或者,查看您正在调试的进程的 pid/proc/PID/maps在哪里PID,您可以使用info proc.