-1

I printed the current stack pointer as describe in this post

void myFunc1(void)
{
    char *p;
    char b=0x11;
    p = &b;
    printf("printStack(1) [%p]=%d\n",p,*p);
    myfunc2();

}

outout:

printStack(1) [0x7ec8a72f]=17

while the printout when using the snipped code from backtrace example :

backtrace() returned 4 addresses
/home/lib/libmy1.so(myfunc3+0x14) [0x2aba4378]
/home/lib/libmy1.so(myFunc1+0x220) [0x2aba5d74]
/home/my_demon() [0x1b0b8]
/home/my_demon(main+0x8b8) [0x19668]
/lib/libc.so.6(__libc_start_main+0x118) [0x2ac554c4]

I expect that the addresses in both printout would be in the same space address. So why there is diffrence in the address 0x7ec8a72f vs 0x2aba4378?

Arch: ARM

Thanks

Community
  • 1
  • 1
joni
  • 34
  • 3
  • 1
    Are you doing the `printf()` and the `backtrace` calls in the same program execution? – filaton May 03 '17 at 12:46
  • 3
    Why would a function's executable code be located on the stack for the currently-running thread? – Andrew Henle May 03 '17 at 12:47
  • Both calls ('printf()' and 'backtrace') done in same program execution. @AndrewHenle - Do you mean that the address printed by stacktrac is the data segment address? – joni May 03 '17 at 12:50
  • 1
    @joni backtrace is printing return addresses stored _in_ the stack. Your `printf` is printing a pointer to a stack location. They are completely separate. – Ian Abbott May 03 '17 at 13:20
  • **undefined behaviour**: %p requires a ptr-to-void, but you pass a `char *`. – Jens May 03 '17 at 13:41

1 Answers1

0

As mentioned in the comments (By Andrew Henle and Ian Abbott). The printf output is the address of stack location in memory, while backtrace prints the return address of the called functions stored in the stack. Thanks

joni
  • 34
  • 3