Re: [DynInst_API:] SymtabAPI segmentation fault


Date: Tue, 08 Jan 2019 22:22:00 +0530
From: Buddhika Chamith Kahawitage Don <budkahaw@xxxxxx>
Subject: Re: [DynInst_API:] SymtabAPI segmentation fault
Great! I used Block::getInsns and it worked!

Thanks for the help.

On Tue, Jan 8, 2019 at 9:46 PM Xiaozhu Meng <mxz297@xxxxxxxxx> wrote:
Since you are using one InstructionDecoder object for decoding the whole block, rather than one instruction. The second parameter of the InstructionDecoder constructor should the length of the whole block. So, InstructionDecoder::maxInstructionLength should be changed to the block length.

On the other hand, since you are just trying to get all instructions in a block. You can use Block::getInsns(Block::Insns) to directly get all instructions in a block. Block::Insns is just a map from the address to the instruction.

typedef std::map<Offset, InstructionAPI::Instruction> Insns;

On Tue, Jan 8, 2019 at 10:08 AM Buddhika Chamith Kahawitage Don <budkahaw@xxxxxx> wrote:
Looks like the instruction is not valid.

Here is the function being decoded.

ÂÂ 0x0000000000400528 <+0>:ÂÂÂ subÂÂÂ $0x8,%rsp
ÂÂ 0x000000000040052c <+4>:ÂÂÂ movÂÂÂ 0x200ac5(%rip),%raxÂÂÂÂÂÂÂ # 0x600ff8
ÂÂ 0x0000000000400533 <+11>:ÂÂÂ testÂÂ %rax,%rax
ÂÂ 0x0000000000400536 <+14>:ÂÂÂ jeÂÂÂÂ 0x40053d <_init+21>
 0x0000000000400538 <+16>: callq 0x400580
ÂÂ 0x000000000040053d <+21>:ÂÂÂ addÂÂÂ $0x8,%rsp
ÂÂ 0x0000000000400541 <+25>:ÂÂÂ retqÂÂ

Instruction boundaries at the decoder are (from a log I added)

Instruction at : 0x400528
Instruction at : 0x40052f
Instruction at : 0x400532
Instruction at : 0x400534
INVALID INSTRUCTION at : 0x400534

Looks like something is going wrong at the decoder.

My decode loop looks like this. Maybe there is something wrong I am doing in there.

 CodeObject co; // Get CodeObject
 for (; fit != co->funcs().end(); ++fit) {
ÂÂÂ Function *f = *fit;
ÂÂÂ if (co->cs()->linkage().find(f->addr()) != co->cs()->linkage().end())
ÂÂÂÂÂ continue;

ÂÂÂ InstructionDecoder decoder(f->isrc()->getPtrToInstruction(f->addr()),
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ InstructionDecoder::maxInstructionLength,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ f->region()->getArch());

ÂÂÂ Address crtAddr = f->addr();
ÂÂÂ int instr_count = 0;
ÂÂÂ instr = decoder.decode();
ÂÂÂ auto fbl = f->blocks().end();
ÂÂÂ fbl--;
ÂÂÂ Block *b = *fbl;
ÂÂÂ Address lastAddr = b->last();

ÂÂÂ // if current function has zero instructions, don't output it
ÂÂÂ if (crtAddr == lastAddr)
ÂÂÂÂÂ continue;

ÂÂÂ std::set<std::string> read;
ÂÂÂ std::set<std::string> written;
ÂÂÂ std::set<std::string> used;
ÂÂÂ while (crtAddr < lastAddr) {
ÂÂÂÂÂ instr = decoder.decode();

ÂÂÂÂÂ printf("Instruction at : %p\n", crtAddr);

ÂÂÂÂÂ if (!instr.isValid()) {
ÂÂÂÂÂÂÂ printf("INVALID INSTRUCTION at : %p\n", crtAddr);
ÂÂÂÂÂÂÂ return -1;
ÂÂÂÂÂ }

ÂÂÂÂÂ InsnCategory c = instr.getCategory();
ÂÂÂÂÂ std::set<RegisterAST::Ptr> regsRead;
ÂÂÂÂÂ std::set<RegisterAST::Ptr> regsWritten;
ÂÂÂÂÂ instr.getReadSet(regsRead);
ÂÂÂÂÂ instr.getWriteSet(regsWritten);
ÂÂÂÂÂ ....
ÂÂ

On Tue, Jan 8, 2019 at 9:20 PM Xiaozhu Meng <mxz297@xxxxxxxxx> wrote:
Thanks for the update.

Before you call Instruction::getReadSet(), can you first call Instruction::isValid()? Instruction::isValid() returns a boolean representing whether this is a valid instruction. I guess the problem here is that Dyninst wrongly decodes a valid instruction into an invalid instruction. And then when you try get registers from an invalid instruction, Dyninst did not handle such corner case properly and asserted.Â

If there is indeed invalid instructions reported by Dyninst, can you share the binary with me so that I can continue to fix the instruction decoding?

Thanks,

--XiaozhuÂ

On Tue, Jan 8, 2019 at 9:32 AM Buddhika Chamith Kahawitage Don <budkahaw@xxxxxx> wrote:
Also when I checked the f->region()->geArch() parameter passed to the decoder it showed me Dyninst::Arch_x86_64.

On Tue, Jan 8, 2019 at 9:00 PM Buddhika Chamith Kahawitage Don <budkahaw@xxxxxx> wrote:
I retired with Dyninst 10.0.0. Now I get the following

RegAudit: /home/buddhika/Builds/dyninst-10.0.0/instructionAPI/src/InstructionDecoderImpl.C:77: static Dyninst::InstructionAPI::InstructionDecoderImpl::Ptr Dyninst::InstructionAPI::InstructionDecoderImpl::makeDecoderImpl(Dyninst::Architecture): Assertion `0' failed.

Thread 1 "RegAudit" received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51ÂÂÂ ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0Â __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1Â 0x00007ffff639b801 in __GI_abort () at abort.c:79
#2Â 0x00007ffff638b39a in __assert_fail_base (fmt=0x7ffff65127d8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n",
ÂÂÂ assertion=assertion@entry=0x7ffff73f2a48 "0",
ÂÂÂ file=file@entry=0x7ffff73fbc00 "/home/buddhika/Builds/dyninst-10.0.0/instructionAPI/src/InstructionDecoderImpl.C", line=line@entry=77,
ÂÂÂ function=function@entry=0x7ffff73fc180 <Dyninst::InstructionAPI::InstructionDecoderImpl::makeDecoderImpl(Dyninst::Architecture)::__PRETTY_FUNCTION__> "static Dyninst::InstructionAPI::InstructionDecoderImpl::Ptr Dyninst::InstructionAPI::InstructionDecoderImpl::makeDecoderImpl(Dyninst::Architecture)") at assert.c:92
#3Â 0x00007ffff638b412 in __GI___assert_fail (assertion=assertion@entry=0x7ffff73f2a48 "0",
ÂÂÂ file=file@entry=0x7ffff73fbc00 "/home/buddhika/Builds/dyninst-10.0.0/instructionAPI/src/InstructionDecoderImpl.C", line=line@entry=77,
ÂÂÂ function=function@entry=0x7ffff73fc180 <Dyninst::InstructionAPI::InstructionDecoderImpl::makeDecoderImpl(Dyninst::Architecture)::__PRETTY_FUNCTION__> "static Dyninst::InstructionAPI::InstructionDecoderImpl::Ptr Dyninst::InstructionAPI::InstructionDecoderImpl::makeDecoderImpl(Dyninst::Architecture)") at assert.c:101
#4Â 0x00007ffff73f0d56 in Dyninst::InstructionAPI::InstructionDecoderImpl::makeDecoderImpl (
ÂÂÂ a=a@entry=Dyninst::Arch_none)
ÂÂÂ at /home/buddhika/Builds/dyninst-10.0.0/instructionAPI/src/InstructionDecoderImpl.C:77
#5Â 0x00007ffff7277644 in Dyninst::InstructionAPI::InstructionDecoder::InstructionDecoder (this=0x7fffffffd210,
ÂÂÂ buffer=<optimized out>, size=<optimized out>, arch=Dyninst::Arch_none)
ÂÂÂ at /home/buddhika/Builds/dyninst-10.0.0/instructionAPI/src/InstructionDecoder.C:49
#6Â 0x00007ffff72533a8 in Dyninst::InstructionAPI::Instruction::decodeOperands (this=0x7fffffffd540)
ÂÂÂ at /home/buddhika/Builds/dyninst-10.0.0/instructionAPI/src/Instruction.C:120
#7Â 0x00007ffff72554d5 in Dyninst::InstructionAPI::Instruction::getReadSet (this=0x7fffffffd540,
ÂÂÂ regsRead=std::set with 0 elements) at /home/buddhika/Builds/dyninst-10.0.0/instructionAPI/src/Instruction.C:288
#8Â 0x0000555555559025 in main (argc=2, argv=0x7fffffffd968) at RegAudit.cpp:178

Looks like it didn't pick up the Architecture looking at InstructionDecoderImpl.C? I create the InstructionDecoder as below.

ÂÂÂ Function* f; // Get function from CodeObject->funcs()
ÂÂÂ InstructionDecoder decoder(f->isrc()->getPtrToInstruction(f->addr()),
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ InstructionDecoder::maxInstructionLength,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ f->region()->getArch());

Any ideas?

Cheers

On Tue, Jan 8, 2019 at 5:34 PM Buddhika Chamith Kahawitage Don <budkahaw@xxxxxx> wrote:
Sure. I will update and report back.

Thanks
Buddhika

On Mon, Jan 7, 2019 at 8:45 PM Xiaozhu Meng <mxz297@xxxxxxxxx> wrote:
Hi,

Can you upgrade to use Dyninst 10.0.0? Dyninst 10 contains many bug fixes and new features over 9.3.2, but you will need to use libdw-0.173. If the same problem shows up, please let me know and I will take a look at it.

Thanks,

--Xiaozhu

On Sat, Jan 5, 2019 at 9:56 PM Buddhika Chamith Kahawitage Don <budkahaw@xxxxxx> wrote:
Hi,

I am trying to use SymtabAPI to analyze the register usage of a binary. My implementation fails on some binaries (built with -g) with below stack trace.

I have installed libdw-0.170 on my system using Ubuntu package manager. Does this look familiar?


#0Â Dyninst::SymtabAPI::DwarfWalker::findDieName (dbg=dbg@entry=0x5555557be3c0, die=0x5555559b3840, name="")
ÂÂÂ at /home/buddhika/Builds/dyninst-9.3.2/symtabAPI/src/dwarfWalker.C:1448
#1Â 0x00007ffff7226767 in Dyninst::SymtabAPI::Object::dwarf_parse_aranges (this=this@entry=0x5555557b6440,
ÂÂÂ dbg=dbg@entry=0x5555557be3c0, dies_seen=std::set with 0 elements)
ÂÂÂ at /home/buddhika/Builds/dyninst-9.3.2/symtabAPI/src/Object-elf.C:2461
#2Â 0x00007ffff7226b75 in Dyninst::SymtabAPI::Object::fix_global_symbol_modules_static_dwarf (
ÂÂÂ this=this@entry=0x5555557b6440) at /home/buddhika/Builds/dyninst-9.3.2/symtabAPI/src/Object-elf.C:2490
#3Â 0x00007ffff7229ab4 in Dyninst::SymtabAPI::Object::load_object (this=this@entry=0x5555557b6440,
ÂÂÂ alloc_syms=alloc_syms@entry=true) at /home/buddhika/Builds/dyninst-9.3.2/symtabAPI/src/Object-elf.C:1602
#4Â 0x00007ffff722aa1e in Dyninst::SymtabAPI::Object::Object (this=0x5555557b6440, mf_=0x5555557b0460,
ÂÂÂ err_func=<optimized out>, alloc_syms=<optimized out>, st=<optimized out>)
ÂÂÂ at /home/buddhika/Builds/dyninst-9.3.2/symtabAPI/src/Object-elf.C:2967
#5Â 0x00007ffff71e63d3 in Dyninst::SymtabAPI::Symtab::Symtab (this=0x5555557b5230, filename="",
ÂÂÂ defensive_bin=<optimized out>, err=@0x7fffffffd61f: false)
ÂÂÂ at /home/buddhika/Builds/dyninst-9.3.2/symtabAPI/src/Symtab.C:1261
#6Â 0x00007ffff71e68d1 in Dyninst::SymtabAPI::Symtab::openFile (obj=@0x7fffffffd6a0: 0x0, filename="CG",
ÂÂÂ def_binary=Dyninst::SymtabAPI::Symtab::NotDefensive)
ÂÂÂ at /home/buddhika/Builds/dyninst-9.3.2/symtabAPI/src/Symtab.C:2077


Regards
Buddhika
_______________________________________________
Dyninst-api mailing list
Dyninst-api@xxxxxxxxxxx
https://lists.cs.wisc.edu/mailman/listinfo/dyninst-api
_______________________________________________
Dyninst-api mailing list
Dyninst-api@xxxxxxxxxxx
https://lists.cs.wisc.edu/mailman/listinfo/dyninst-api
_______________________________________________
Dyninst-api mailing list
Dyninst-api@xxxxxxxxxxx
https://lists.cs.wisc.edu/mailman/listinfo/dyninst-api
[← Prev in Thread] Current Thread [Next in Thread→]