public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: Sonal Santan <sonals@xilinx.com>,
	"elfutils-devel@sourceware.org" <elfutils-devel@sourceware.org>
Subject: Re: Working with ELF already loaded in memory
Date: Fri, 09 Jul 2021 13:00:46 +0200	[thread overview]
Message-ID: <196abc454208d90d8819e887500cbd34e29ce772.camel@klomp.org> (raw)
In-Reply-To: <BY5PR02MB62604135F2380EEB6619AB06BB189@BY5PR02MB6260.namprd02.prod.outlook.com>

Hi Sonal,

On Fri, 2021-07-09 at 05:34 +0000, Sonal Santan wrote:
> 
> Thanks for the pointer. I was looking for APIs inside
> /usr/include/elfutils directory and
> did not realize elfutils also places header files under /usr/include
> directory. I am working 
> with this API now.

Ah, yes, the libelf library is kind of "standard" (it is also available
on BSDs, AIX, Solaris, etc.) so it goes under /usr/include. The libdw
library places its headers under
/usr/include/elfutils/{libdw.h,libdwelf.h,libdwfl.h}.

> > You can also use libdwfl (part of libdw) to do some of the above automagically.
> > See for example:
> > 
> > /* Call dwfl_report_module for each file mapped into the address space of PID.
> >    Returns zero on success, -1 if dwfl_report_module failed,
> >    or an errno code if opening the proc files failed.  */ extern int
> > dwfl_linux_proc_report (Dwfl *dwfl, pid_t pid);
> 
> Does this also work for ELF files which are loaded into heap as blob -- not really
> _mapped_ into the address space? I guess I will have to provide some hints to dwfl
> so it can locate the loaded blob when walking through the process map?

It probably wouldn't work if the the library is not normally mapped
into memory since it relies on the content of /proc/<pid>/map to locate
what is mapped where. You can also create your own and use:

/* Similar, but reads an input stream in the format of Linux
/proc/PID/maps
   files giving module layout, not the file for a live process.  */
extern int dwfl_linux_proc_maps_report (Dwfl *dwfl, FILE *);

But there are also more specific interfaces to map segments to modules
in libdwfl.h. They don't have to be file mapped, but can also come for
memory or parts of a file (see for example the core file mapper). But
these interfaces are a little obscure with minimal documentation.
Please feel free to ask for more background if you get stuck.

Cheers,

Mark

      reply	other threads:[~2021-07-09 11:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-08  5:02 Sonal Santan
2021-07-08 15:02 ` Mark Wielaard
2021-07-09  5:34   ` Sonal Santan
2021-07-09 11:00     ` Mark Wielaard [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=196abc454208d90d8819e887500cbd34e29ce772.camel@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    --cc=sonals@xilinx.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).