This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Dump data from object files
On 21/09/2010 09:52, Schmitt, Patrick wrote:
> Hello guys,
> I want to dump data from object files like "objdump -s fileName" does it.
> I open the object file in that way:
>
> bfd *abfd = NULL;
> const char ** target = NULL;
>
> bfd_init();
>
> target = bfd_target_list();
>
> abfd = bfd_openr("c:\\config.o", target);
^^^^^^
This is wrong, you're passing the whole array of char* pointers to
bfd_openr, it wants just a single char* pointing to the particular target
you've chosen from the list of all targets. When it tries to interpret that
as a char *, I'm surprised you don't get a NULL return from bfd_openr; when I
tried it, the failure to look up a value for target_vec in bfd_fopen caused an
immediate error return. (The compiler should have warned you about this.)
> Abfd is not null, but it doesnt contains sections.
See the description in the bfd man/info page, beginning from ...
> When a file is opened with bfd_openr, its format and target are unknown.
... up to and including the paragraph beginning ...
> Once the BFD has been opened and the target selected, the file format may
> be determined [ ... ]
Unless you know a priori what kind of object file you're going to be dealing
with, your best bet is probably to pass NULL to bfd_openr for the target,
which means that bfd_check_format will loop through the list of targets
looking for a match.
> What is the next step getting data from the sections ?
Once you've got the target argument right, "bfd_check_format (abfd,
bfd_object);" ought to do the rest for you, setting up the section table etc.
cheers,
DaveK