c - store memory address in a char* and & in gdb -


i trying create chain of pointer addresses, first pointing address of next, , on.

for example, char *a 's address 0x1, char *b address 0x2, char *x address 0x3. want link a->b->c, hope store value 0x2 0x1 memory address, value 0x3 0x2 memory address.

i have following codes:

#define put(p, val) (*(unsigned long *)(p) = (val)) #define set_next_ptr(p, ptr) (*(char**)(p) = (char*)((unsigned long)(ptr))) void chain(char* bp){     char *first = mem_sbrk(size);     char *second =mem_sbrk(size);     put(first, (unsigned long)bp);     put(bp, *second); } 

when run gdb, , exam memory address. after call mem_sbrk first , second.

(gdb) x /x first 0x7ffff661c020: 0x00000000  (gdb) x /x bp  0x7ffff661b020: 0x00000000 (gdb) x/x second  0x7ffff661d020: 0x00000000 

after call put macro:

(gdb) x/x second  0x7ffff661d020: 0x00000000      0x00000000 (gdb) x /2x first 0x7ffff661c020: 0xf661b020      0x00007fff    (gdb) p first  0x7ffff661c020 " \260a\366\377\177"   (gdb) x /2x bp 0x7ffff661b020: 0xf661d020      0x00007fff 

it seems working. wonder how can convert memory address pointer. since entire memory address stores 0x7ffff661d020 , 0x7ffff661d024. when use p first, returns meaningless string.

second question, in gdb when call

(gdb) p &bp (char **) 0x7fffffffe3e8 

i wonder 0x7fffffffe3e8? thought & getting memory address,i expect gdb shows

(void*) 0x7ffff661b020 

third question difference between

#define put(p, val) (*(unsigned long *)(p) = (val)) #define set_next_ptr(p, ptr) (*(char**)(p) = (char*)((unsigned long)(ptr))) 


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -