From: Sasha Da Rocha Pinheiro <darochapinhe@wisc.edu>
To: "elfutils-devel@sourceware.org" <elfutils-devel@sourceware.org>,
Mark Wielaard <mjw@redhat.com>, Ben Woodard <woodard@redhat.com>
Subject: Re: unknown error after dwarf_cfi_addrframe()
Date: Tue, 12 Feb 2019 01:15:00 -0000 [thread overview]
Message-ID: <BN6PR06MB29329E00438415D5435169ACA6650@BN6PR06MB2932.namprd06.prod.outlook.com> (raw)
In-Reply-To: <BN6PR06MB2932AF6647E5E7108DD46E80A6680@BN6PR06MB2932.namprd06.prod.outlook.com>
I found that when libdw will try to get the base CFI from the ABI, the function ebl_abi_cfi() ends calling default_abi_cfi() which returns -1, when should be calling x86_64_abi_cfi().
In addition, the symbol x86_64_abi_cfi in the file libdw.so is not present, but all the respective default_* ones are.
It seems that the library is being compiled using BACKEND as default and not catching the correct architecture (?).
Sasha
From: Sasha Da Rocha Pinheiro
Sent: Thursday, February 7, 2019 4:57 PM
To: elfutils-devel@sourceware.org; Mark Wielaard
Subject: unknown error after dwarf_cfi_addrframe()
Hi all,
I'm trying to read frame info from .eh_frame section. But I'm getting "unknown error".
I'll copy the snippet where I use libelf functions to print all sections of the file and get the index of .eh_frame, to then use libdw to go through .eh_frame Dwarf_CFI_Entry entries, to count them. The count matches was dwarfdump from libdwarf prints out. I'll attach that too.
Following I create a Dwarf_CFI and try to lock up an address with dwarf_cfi_addrframe(). But got unknown error.
I'll attach the binary too.
As you can see in the GDB output below that I try to get frame info for the address 0x40ae19, and the FDE with index 94 (see dwarfdump output) has addresses of <0x0040ae19:0x0040aed3>.
Regards,
Sasha
============ snippet for what I'm doing ==============
//testing printing count for CIE and FDE in this eh_frame
auto e_ident = elf_getident(dbg_eh_frame, NULL);
Elf_Scn *scn = NULL;
Elf64_Shdr *shdr;
char *section_name;
size_t eh_frame_index = -1, shstrndx;
if(elf_getshdrstrndx(dbg_eh_frame, &shstrndx)!=0)
fprintf(stderr, "elf_getshdrstrndx() failed: %s.", elf_errmsg(-1));
while((scn = elf_nextscn(dbg_eh_frame,scn))!=NULL)
{
if((shdr = elf64_getshdr(scn))!=shdr)
fprintf(stderr, "getshdr() failed: %s.\n", elf_errmsg(-1));
if((section_name = elf_strptr(dbg_eh_frame, shstrndx, shdr->sh_name))==NULL)
fprintf(stderr, "elf_strptr() failed: %s.\n", elf_errmsg(-1));
fprintf(stderr, "Section [%d]: %s\n", elf_ndxscn(scn), section_name);
if(strcmp(section_name, ".eh_frame")==0)
eh_frame_index = elf_ndxscn(scn);
}
assert(eh_frame_index!=-1);
scn = elf_getscn(dbg_eh_frame,eh_frame_index);
fprintf( stderr, "elf_getscn() failed: %s.\n", elf_errmsg(-1));
auto eh_frame_data = elf_getdata(scn, NULL);
fprintf( stderr, "elf_getdata() failed: %s.\n", elf_errmsg(-1));
assert(eh_frame_data!=NULL);
Dwarf_CFI_Entry entry;
Dwarf_Off offset = 0, next_offset, saved_cur_offset;
int res = 0, count_fde=0, count_cie=0;
do{
res = dwarf_next_cfi((const unsigned char *)e_ident, eh_frame_data,
true, offset, &next_offset, &entry);
saved_cur_offset = offset;
offset = next_offset;
if(res==1 && next_offset==(Dwarf_Off)-1) break;
if(res == -1) {
if (offset != saved_cur_offset) {
fprintf(stderr, "dwarf_next_cfi() returns -1. Error: %s\n", dwarf_errmsg(-1));
continue; // Soft error, skip to the next CFI entry
}
// Since offset didn't advance, we can't skip this CFI entry and need to quit
break;
}
if(dwarf_cfi_cie_p(&entry)) count_cie++;
else count_fde++;
}while(true);
cerr << "Count_cie: " << count_cie << endl;
cerr << "Count_fde: " << count_fde << endl;
Dwarf_CFI * cfi = nullptr;
cfi = dwarf_getcfi_elf(dbg_eh_frame);
if(!cfi) assert(false);
auto next_pc = range.first;
while(next_pc < range.second)
{
Dwarf_Frame * frame = NULL;
int result = dwarf_cfi_addrframe(cfi, next_pc, &frame);
fprintf( stderr, "dwarf_cfi_addrframe() failed: %s.\n", dwarf_errmsg(-1));
if(result==-1) break;
============ end of snippet ==============
GDB output:
Thread 1 "test_driver" hit Breakpoint 11, Dyninst::DwarfDyninst::DwarfFrameParser::getRegsForFunction (
this=0x1a70320, range=..., reg=..., locs=std::vector of length 0, capacity 0, err_result=@0x7fffffffd3fc: 32767)
at /<hidden-filepath>...Parser.C:162
162 {
(gdb) until 231
Section [1]: .interp
Section [2]: .note.ABI-tag
Section [3]: .note.gnu.build-id
Section [4]: .gnu.hash
Section [5]: .dynsym
Section [6]: .dynstr
Section [7]: .gnu.version
Section [8]: .gnu.version_r
Section [9]: .rela.dyn
Section [10]: .rela.plt
Section [11]: .init
Section [12]: .plt
Section [13]: .plt.got
Section [14]: .text
Section [15]: .fini
Section [16]: .rodata
Section [17]: .eh_frame_hdr
Section [18]: .eh_frame
Section [19]: .init_array
Section [20]: .fini_array
Section [21]: .jcr
Section [22]: .dynamic
Section [23]: .got
Section [24]: .got.plt
Section [25]: .data
Section [26]: .bss
Section [27]: .gnu_debuglink
Section [28]: .shstrtab
elf_getscn() failed: no error.
elf_getdata() failed: no error.
Count_cie: 2
Count_fde: 205
Dyninst::DwarfDyninst::DwarfFrameParser::getRegsForFunction (this=0x1a70320, range=..., reg=...,
locs=std::vector of length 0, capacity 0, err_result=@0x7fffffffd3fc: Dyninst::DwarfDyninst::FE_No_Error)
at /<hidden-filepath>...Parser.C:231
231 Dwarf_CFI * cfi = nullptr;
(gdb) n
232 cfi = dwarf_getcfi_elf(dbg_eh_frame);
(gdb)
233 if(!cfi) assert(false);
(gdb)
235 auto next_pc = range.first;
(gdb)
236 while(next_pc < range.second)
(gdb)
238 Dwarf_Frame * frame = NULL;
(gdb)
239 int result = dwarf_cfi_addrframe(cfi, next_pc, &frame);
(gdb)
240 fprintf( stderr, "dwarf_cfi_addrframe() failed: %s.\n", dwarf_errmsg(-1));
(gdb)
dwarf_cfi_addrframe() failed: unknown error.
241 if(result==-1) break;
(gdb) p/x next_pc
$73 = 0x40ae19
next prev parent reply other threads:[~2019-02-12 1:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-07 22:57 Sasha Da Rocha Pinheiro
2019-02-12 1:15 ` Sasha Da Rocha Pinheiro [this message]
2019-02-12 6:47 ` Mark Wielaard
[not found] ` <BN6PR06MB293247BE5B8443B3E3EB967BA6650@BN6PR06MB2932.namprd06.prod.outlook.com>
2019-02-12 8:09 ` Mark Wielaard
2019-02-12 17:57 ` Sasha Da Rocha Pinheiro
2019-02-12 18:39 ` Ben Woodard
2019-02-12 18:43 ` Sasha Da Rocha Pinheiro
2019-02-12 18:41 ` Sasha Da Rocha Pinheiro
[not found] ` <BN6PR06MB29322B835ECA93DFEEA81C2AA6650@BN6PR06MB2932.namprd06.prod.outlook.com>
2019-02-12 19:47 ` Sasha Da Rocha Pinheiro
2019-02-12 20:58 ` Mark Wielaard
2019-02-12 21:39 ` Sasha Da Rocha Pinheiro
2019-02-12 20:42 ` Mark Wielaard
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=BN6PR06MB29329E00438415D5435169ACA6650@BN6PR06MB2932.namprd06.prod.outlook.com \
--to=darochapinhe@wisc.edu \
--cc=elfutils-devel@sourceware.org \
--cc=mjw@redhat.com \
--cc=woodard@redhat.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).