]> git.pld-linux.org Git - packages/LeakTracer.git/blob - LeakTracer-caller_addr.patch
- oops, sparc has a different call convention.
[packages/LeakTracer.git] / LeakTracer-caller_addr.patch
1 --- LeakTracer.cc.orig  2005-12-10 23:57:27.000000000 +0000
2 +++ LeakTracer.cc       2005-12-11 00:12:19.592655400 +0000
3 @@ -86,6 +86,25 @@
4   */
5  #define INITIALSIZE 32768
6  
7 +static inline
8 +const void* caller_address(const void* return_address)
9 +{
10 +       unsigned long c = (unsigned long)return_address;
11 +#if defined(__i386__) || defined(__x86_64__)
12 +// x86-32: call [mem] takes 5 bytes.
13 +// x86-64: callq/jmpq [mem] takes 5 bytes.
14 +       c -= 5;
15 +#elif defined(__powerpc__) || defined(__alpha__)
16 +// ppc32/64: bl [mem] takes 4 bytes.
17 +// alpha: bsr ra,[mem] takes 4 bytes.
18 +       c -= 4;
19 +#elif defined(__sparc__)
20 +// sparc32/64: call with delay slot takes 8 bytes
21 +// but %i7 (r31) contains return_address-8, so no change here.
22 +#endif
23 +       return (const void*)c;
24 +}
25 +
26  static class LeakTracer {
27         struct Leak {
28                 const void *addr;
29 @@ -326,7 +341,7 @@
30                                 leaks[i].addr = p;
31                                 leaks[i].size = size;
32                                 leaks[i].type = type;
33 -                               leaks[i].allocAddr=__builtin_return_address(1);
34 +                               leaks[i].allocAddr = caller_address(__builtin_return_address(1));
35                                 firstFreeSpot = i+1;
36                                 // allow to lookup our index fast.
37                                 int *hashPos = &leakHash[ ADDR_HASH(p) ];
38 @@ -410,7 +425,7 @@
39                                 "S %10p %10p  # new%s but delete%s "
40                                 "; size %zd\n",
41                                 leaks[i].allocAddr,
42 -                               __builtin_return_address(1),
43 +                               caller_address(__builtin_return_address(1)),
44                                 ((!type) ? "[]" : " normal"),
45                                 ((type) ? "[]" : " normal"),
46                                 leaks[i].size);
This page took 0.206659 seconds and 3 git commands to generate.