1
#include <stdio.h>

void __cyg_profile_func_enter(void *func, void *caller) __attribute__((no_instrument_function));
void __cyg_profile_func_exit(void *this_fn, void *call_site) __attribute__((no_instrument_function));

void __cyg_profile_func_enter(void *func, void *caller)
{
    printf("%p\n", func);
    printf("%p\n", caller);
}

void __cyg_profile_func_exit(void *this_fn, void *call_site)
{
}

void my_function(int a, int b)
{
    a = a * b;
}

void dummy_function()
{
    int a = 10;
    int b = 20;
    my_function(a, b);
}

int main()
{
    int x = 42;
    int y = 73;
    dummy_function();
    my_function(x, y);

    return 0;
}

Build commands:

gcc -x c boost_stacktrace.cpp -finstrument-functions -rdynamic -g -O0 -o boost_stacktrace.exe
./boost_stacktrace.exe | tee addrs.txt
0x55d97d38324c
0x7f0fa12b0d90
0x55d97d3831f4
0x55d97d383287
0x55d97d3831a9
0x55d97d383233
0x55d97d3831a9
0x55d97d383296
addr2line -e boost_stacktrace.exe -f -i -p < addrs.txt
?? ??:0
?? ??:0
?? ??:0
?? ??:0
?? ??:0
?? ??:0
?? ??:0
?? ??:0

QUESTION
What am I doing wrong?

Bob
  • 4,576
  • 7
  • 39
  • 107
  • 2
    One possible reason might be [address space layout randomization](https://en.wikipedia.org/wiki/Address_space_layout_randomization). Check the different values on multiple runs. – the busybee Apr 10 '23 at 20:21
  • @thebusybee Yes it was due to that: adding `-no-pie` fixed the issue. – Bob Apr 11 '23 at 14:18

1 Answers1

2

After I added -no-pie to my compile command, it worked.

Bob
  • 4,576
  • 7
  • 39
  • 107
  • Tip: It is generally courteous to provide attribution (even though it can be seen from the comment below the question). Something simple like "... it worked as suggested by [@thebusybee](https://stackoverflow.com/users/11294831/the-busybee)." Good job in providing an answer for the question. – David C. Rankin Apr 11 '23 at 18:54