Hi,
I'm assuming backtrace() is a gcc 4 function because I can't find it in gcc
3, but yes, it looks like what you want. The only problem is that it's not
just a simple rewrite. There's no stack frame information returned by
backtrace(), only return addresses, and mpatrol currently uses the frame
pointer to identify the position in the stack before then going on to look
at the return address. You shouldn't need backtrace_symbols() because
mpatrol already has symbol support, including more formats than
backtrace_symbols() supports, and it should work fine with the return
addresses that backtrace() supplies.
I think only stack.[ch] and addr.c would need to be changed to accommodate
this change, and possibly checkalloca() in inter.c (since it also uses the
frame pointers to determine if an allocation can be freed when a function
has returned).
And now you're going to ask me how to do it ;-)
You might be best looking at all the code contained within the
MP_BUILTINSTACK_SUPPORT macro and changing it to use backtrace() instead.
The __builtin_frame_address/__builtin_return_address mechanism and
backtrace() are quite similar, except that the former has a hard-limit to
the size of the stack at compile-time, and the latter returns no frame
pointers as described above. I'll add this to my things to do in the future
with mpatrol but you should be able to get something working at the moment
with the minimum of changes. And more to the point, you shouldn't need to
worry about any assembler code. Alternatively, if you really need something
working quickly, you could just try building mpatrol with
MP_BUILTINSTACK_SUPPORT to see if that works for you.
Good luck,
Graeme.
-----Original Message-----
From: Sagar [mailto:sagarseth@...]
Sent: 17 November 2008 13:08
To: Daniel Jacobowitz; mpatrol; graeme_roy@...
Subject: Re: [mpatrol] mpatrol 64 bit issue ....
Hello everyone,,
I got an interesting comment from suse guys ,,,
"One easy way to do backtracing in a portable way over multiple Linux
architectures is to use glibc's backtrace() function. "
http://www.gnu.org/software/libtool/manual/libc/Backtraces.html
does it makes sense for us ,, can we use this and questions comes .. how
....???
i know i am asking too many questions and many of them could be dumb but
please bear with me ...
Thanks
Sagar
On 11/17/08, Sagar <sagarseth@...> wrote:
> Hello Friend ,,
>
> I am confused ... from what i see inside the code i need to re-write
>
> 1. struct frameinfo and stackinfo ( for 64bit) 2. then need to write
> the getaddr unwind getframe and all other functions in stack.c
>
> right ???
>
> please help with some documentation.. better will be an example ..
>
> here is something useful that i found over the weekend ,... please
> have look ,, let me know about further steps...
>
>
> thanks in advance...
> Seth
>
>
>
>
> From: Graeme Roy <graeme_roy@...>
> Date: Fri, 14 Nov 2008 22:09:22 -0000
> Subject: RE: [mpatrol] mpatrol 64 bit issue ....
> To: Sagar <sagarseth@...>
>
> Hi,
>
>
>
> If you've got the time to have a look, the code for all the stack
> tracebacks is in mpatrol/src/stack.c. Just look for the x86-specific
> code - there's not much because for 32-bit x86 it's really easy, you
> just follow the chain of frame pointers. Daniel from CodeSourcery
> replied to the mpatrol group as well, suggesting that it's a lot more
> complicated for 64-bit x86 since you have to look at the .eh_frame
> section in the executable file and any shared libraries.
>
>
>
> What you could do is try defining MP_BUILTINSTACK_SUPPORT when you
> build the mpatrol library. This will make gcc plant some code to help
> traverse the stack instead of using mpatrol's code. Unfortunately it
> will only work for a finite size stack (see the comments in
> mpatrol/src/config.h) but it'll get you up and running, I hope. It
> doesn't always work on all platforms but it's worth you giving it a try.
>
>
>
> Good luck,
>
>
>
> Graeme.
>
>
>
> _____
>
> From: Sagar [mailto:sagarseth@...]
> Sent: 14 November 2008 12:51
> To: graeme_roy@...
> Subject: Re: [mpatrol] mpatrol 64 bit issue ....
>
>
>
> Hi Friend,
>
> Can u show me where is the
> "source code for getting stack tracebacks in 32 bit"
>
> I can try to put effort for developing the source for 64 bit..
>
> may be i can help u in developing 64 bit version.....
>
> i got a free weekend ...
>
> Sagar
>
> On 11/14/08, Graeme Roy <graeme_roy@...> wrote:
>> Hi,
>>
>> Yes, it sounds like there's been no support added for stack
>> tracebacks on 64-bit x86. The 32-bit x86 code will not work, as you
>> have found out and
> I
>> haven't written support for 64-bit x86 as I don't have access to it.
>>
>> If anyone has written the extra source code for getting stack
>> tracebacks
> to
>> work for mpatrol on that architecture could they post it here? It
>> should only be a few lines of diffs anyway, compared to what I'd
>> expect support
> for
>> Itanium to be.
>>
>> Thanks,
>>
>> Graeme.
>>
>> _____
>>
>> From: mpatrol@yahoogroups.com [mailto:mpatrol@yahoogroups.com] On
>> Behalf
> Of
>> Sagar
>> Sent: 11 November 2008 11:11
>> To: mpatrol@yahoogroups.com
>> Subject: [mpatrol] mpatrol 64 bit issue ....
>>
>>
>>
>> Hello Graeme,
>>
>> Thanks for the update ,, we took the target.h file and places where
>> the ARCH and ENVIRON variables were defined .. we did a undef and
>> redefined them to ARCH_IX86 and ENVIRON_64.
>>
>> CPUs in the box are AMD opteron 275.
>>
>> Now we are getting a core for mpatrol .
>>
>> When we did the analysis on the core then I am getting #0
>> 0x0000002a9567cab4 in __mp_getframe () from /src/lib64/libmpatrol.so
>>
>> What could be wrong .
>>
>> .....-----------------
>>
>> Glad to hear it's working OK for you, at least on one of your machines.
>>
>> For SuSE Enterprise 64-bit, I assume that it's running on Intel Core
>> 2 Duo
>
>> and is therefore x86-64 (and not Itanium). mpatrol has been ported to
>> 64-bit architectures before (MIPS and SPARC for example) but I don't
>> know
> if
>> anything's been done by anyone to port it to 64-bit x86 (i.e. running
>> in a
>
>> 64-bit environment and not just under a 32-bit OS). For example, the
>> stack
>
>> reading code will most likely be different which is probably why
>> you're
> not
>> getting any location information for the allocations.
>>
>> Has anyone here run mpatrol on a 64-bit x86 architecture and got
>> stack tracebacks to work? I imagine there won't be too many changes
>> to make
> (just
>> ensure that ARCH = ARCH_IX86 and ENVIRON = ENVIRON_64 when building
> mpatrol)
>> - just look for ENVIRON_64 in the mpatrol source code to see where I
>> did
> the
>> changes for MIPS and SPARC. I don't have access to a 64-bit OS at the
>> moment so I can't really help much.
>>
>>
>>
>>
>
>
>
> --
> Thanks and Regards
> Sagar
>
>
>
>
> --
> Thanks and Regards
> Sagar
>
--
Thanks and Regards
Sagar