This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
Re: Help using elfutils to get function and line number
- From: Mihai Tarce <mihaitarce at yahoo dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Mon, 16 Mar 2009 13:35:23 -0700
- Subject: Re: Help using elfutils to get function and line number
>(We're not quite there yet, but this sort of thing will be pretty
>easy to express with systemtap, as in ...)
I hadn't heard of systemtap, but now that I looked it up, I have to say that I
think it will be a great tool. Great work!
>This is fine an encouraged if the resulting code you're producing is not
>closed source and you're trying to sell it.
As I have said in a previous post, I'm writing this application as my diploma thesis
at university. And yes, I intend to release the code under the GPL.
I looked at the eu-addr2line tool, and it does pretty much everything I need.
In order to provide it with the correct addresses, I do the following:
- get the base pointer of the main program file (dlopen(NULL), dlsym("main"))
- use dladdr() on all the stack return addresses, to determine to which
object file they belong to
- if the object file differs from the main program file (its base pointer differs),
I subtract its base pointer from it, to get its address in the object file
This works as long as I use the -rdynamic flag, but most tested programs won't
have this flag. I should be able to solve the problem by reading the information
directly from debug section (since I have the address and file name) -- I should
be able to do that with help from eu-addr2line.
There is still one problem how can I determine which object file contains the main()
function? This file will have the stack return addresses which I can process directly.
When I remove the -rdynamic flag, the dlopen/dlsym doesn't work anymore, as
expected. Any ideas?
Sorry for making this post so long, I just wanted to give you a better
image of what I am trying to do.
Thanks for your help,
Mihai