]>
Commit | Line | Data |
---|---|---|
e5448ca9 PS |
1 | --- LeakTracer.cc.orig 2005-12-10 23:57:27.000000000 +0000 |
2 | +++ LeakTracer.cc 2005-12-11 00:12:19.592655400 +0000 | |
628118ff | 3 | @@ -86,6 +86,24 @@ |
e5448ca9 PS |
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; | |
628118ff | 15 | +#elif defined(__powerpc__) |
3729947b | 16 | +// ppc32/64: bl [mem] takes 4 bytes. |
e5448ca9 | 17 | + c -= 4; |
3729947b | 18 | +#elif defined(__sparc__) |
7bf2ab89 PS |
19 | +// sparc32/64: call with delay slot takes 8 bytes |
20 | +// but %i7 (r31) contains return_address-8, so no change here. | |
e5448ca9 PS |
21 | +#endif |
22 | + return (const void*)c; | |
23 | +} | |
24 | + | |
25 | static class LeakTracer { | |
26 | struct Leak { | |
27 | const void *addr; | |
28 | @@ -326,7 +341,7 @@ | |
29 | leaks[i].addr = p; | |
30 | leaks[i].size = size; | |
31 | leaks[i].type = type; | |
32 | - leaks[i].allocAddr=__builtin_return_address(1); | |
33 | + leaks[i].allocAddr = caller_address(__builtin_return_address(1)); | |
34 | firstFreeSpot = i+1; | |
35 | // allow to lookup our index fast. | |
36 | int *hashPos = &leakHash[ ADDR_HASH(p) ]; | |
37 | @@ -410,7 +425,7 @@ | |
38 | "S %10p %10p # new%s but delete%s " | |
39 | "; size %zd\n", | |
40 | leaks[i].allocAddr, | |
41 | - __builtin_return_address(1), | |
42 | + caller_address(__builtin_return_address(1)), | |
43 | ((!type) ? "[]" : " normal"), | |
44 | ((type) ? "[]" : " normal"), | |
45 | leaks[i].size); |