22

I've an address in memory and I want to find out the permissions (r/w/x) of that memory address.

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) ?

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
viji
  • 2,706
  • 5
  • 28
  • 34
  • 1
    You can use `info proc mappings` in GDB, but it doesn't give you the permissions. You can look at `/proc/PID/maps`, where `PID` is the pid of your process -- this will give you the maps with their permissions. – Dietrich Epp May 28 '12 at 07:11

1 Answers1

23

You can first find where s is pointing to:

(gdb) print s
$6 = 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.

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

Michael Foukarakis
  • 39,737
  • 6
  • 87
  • 123