Re: [DynInst_API:] Basic Blocks and Register Access


Date: Thu, 01 May 2014 14:15:18 +0200
From: Sergej Proskurin <prosig@xxxxxxx>
Subject: Re: [DynInst_API:] Basic Blocks and Register Access
Dear Bill,

This seems unusual, and suggests that there's some memory corruption going on somewhere. Any chance you can run this under valgrind and send me the results?

sure, the following provides the valgrind --leak-check=full dump of the following code snippet:

---
...

BPatch_Vector<BPatch_function *> funcs;
BPatch_function *func_lib;
BPatch_image* img;

img = app->getImage();

/* look for the predefined library function 'prolog' */
funcs.clear();
img->findFunction("pfunc_epilog", funcs);
func_lib = funcs[0];

/* no arguments required for function 'pprolog' */
std::vector<BPatch_snippet *> args;
BPatch_funcCallExpr func_instr(*func_lib, args);

SnippetPtr snippet = PatchAPI::convert(func_instr);
if(!snippet) {
    std::cout << "[ERROR] could not create snippet" << std::endl;
    exit(-1);
}

Point p* = mgr->findPoint(Location::Block(block), Point::BlockEntry, true)
/* SEGFAULT: the following results in a SEGFAULT*/
InsertedCode::Ptr icode = PatchModifier::insert(post_block->object(), snippet, p);

---

Valgrind Dump:

---
...
==19356== Invalid read of size 4
==19356==    at 0x45B1EF3: func_instance::obj() const (in /usr/lib/libdyninstAPI.so.8.1.2)
==19356==    by 0x45625C1: registerSpace::actualRegSpace(instPoint*) (in /usr/lib/libdyninstAPI.so.8.1.2)
==19356==    by 0x454BD59: AstNode::generate(Dyninst::PatchAPI::Point*, Dyninst::Buffer&) (in /usr/lib/libdyninstAPI.so.8.1.2)
==19356==    by 0x408EE2E: Dyninst::PatchAPI::PatchModifier::insert(Dyninst::PatchAPI::PatchObject*, boost::shared_ptr<Dyninst::PatchAPI::Snippet>, Dyninst::PatchAPI::Point*) (PatchModifier.C:188)
==19356==    by 0x8052CDD: binedit::instrument_epilog(void*, unsigned char*, unsigned int, unsigned int, Dyninst::PatchAPI::PatchBlock*) (binedit.cpp:1096)
==19356==    by 0x804F5A0: binedit::stack_protect_func(BPatch_function*) (binedit.cpp:398)
==19356==    by 0x804F13D: binedit::stack_protect() (binedit.cpp:273)
==19356==    by 0x805859A: perform_operation(binedit*, unsigned int, std::string, std::string) (main.cpp:63)
==19356==    by 0x8058E6F: main (main.cpp:277)
==19356==  Address 0xf8 is not stack'd, malloc'd or (recently) free'd
==19356==
==19356==
==19356== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==19356==  Access not within mapped region at address 0xF8
==19356==    at 0x45B1EF3: func_instance::obj() const (in /usr/lib/libdyninstAPI.so.8.1.2)
==19356==    by 0x45625C1: registerSpace::actualRegSpace(instPoint*) (in /usr/lib/libdyninstAPI.so.8.1.2)
==19356==    by 0x454BD59: AstNode::generate(Dyninst::PatchAPI::Point*, Dyninst::Buffer&) (in /usr/lib/libdyninstAPI.so.8.1.2)
==19356==    by 0x408EE2E: Dyninst::PatchAPI::PatchModifier::insert(Dyninst::PatchAPI::PatchObject*, boost::shared_ptr<Dyninst::PatchAPI::Snippet>, Dyninst::PatchAPI::Point*) (PatchModifier.C:188)
==19356==    by 0x8052CDD: binedit::instrument_epilog(void*, unsigned char*, unsigned int, unsigned int, Dyninst::PatchAPI::PatchBlock*) (binedit.cpp:1096)
==19356==    by 0x804F5A0: binedit::stack_protect_func(BPatch_function*) (binedit.cpp:398)
==19356==    by 0x804F13D: binedit::stack_protect() (binedit.cpp:273)
==19356==    by 0x805859A: perform_operation(binedit*, unsigned int, std::string, std::string) (main.cpp:63)
==19356==    by 0x8058E6F: main (main.cpp:277)
==19356==  If you believe this happened as a result of a stack
==19356==  overflow in your program's main thread (unlikely but
==19356==  possible), you can try to increase the size of the
==19356==  main thread stack using the --main-stacksize= flag.
==19356==  The main thread stack size used in this run was 8388608.

---

I hope this provides some useful information to you.

FYI:
I have tried to use not only the insertion varian presented above, using a predefined point, but also the variant without provisioning of any points of the basic block (see short code snippet at the bottom) - since this should be handled by the PatchModifier::insert function, as far as I understood. Nevertheless, I get the same result as above:

---
InsertedCode::Ptr icode = PatchModifier::insert(post_block->object(), snippet, NULL);
---

Best regards,
Sergej


[← Prev in Thread] Current Thread [Next in Thread→]