[Rose-public] Help with Binary inter-procedural dataflow analysis

Robb Matzke matzke at hoosierfocus.com
Tue Mar 3 06:22:28 PST 2015


Hi,

The semantics framework in the
src/midend/binaryAnalyses/instructionSemantics/*2.h files is designed to
be extendible by users.  It seems you want to derive a new MemoryCell
class that can store multiple "latest writers", call it MyMemoryCell.

In order to use MyMemoryCell in a semantics framework, you need to build
the framework at runtime by hand rather than calling
SymbolicSemantics::RiscOperators::instance(regdict,solver). It's only a
few lines of code. You'll want to replace its call to
SymbolicSemantics::MemoryState::instance(protoval,protoval) with
SymbolicSemantics::MemoryState::instance(protocell) where protocell is
an instance of MyCellType. The MemoryState always creates new cells by
invoking your create or clone virtual constructors of the protocell.

I don't think we have an example that derives a new MemoryCell type, but
the process is very similar to deriving a new subclass from any of the
other virtually-constructed classes. For instance,
SymbolicSemantics::MemoryState is derived from
BaseSemantics::MemoryCellList, and SymbolicSemantics::SValue is derived
from BaseSemantics::SValue. Other users have been doing this as well.
Your MyMemoryCell class MUST implement "create" and "clone"; it SHOULD
implement the same static constructors, "instance", "promote", and "print".

If you want the same special behavior for registers you'll need to also
derive a new register state class from the one that SymbolicSemantics
uses, namely BaseSemantics::RegisterStateGeneric.

There are other ways you could do this too.  Perhaps you could store
your writers sets in your dataflow state class. Since they're not
actually accessed by Dispatcher::processInstruction(insn), it might be
more convenient to store them at that higher level in the semantics
framework.  You could also store the writers in objects of an entirely
separate class that are instantiated in a lookup table, one object per
dataflow CFG vertex.  You'd then make that table available to your
dataflow merge operation, with the advantage that you wouldn't need to
understand the virtual-constructed semantics framework.

--Robb

On 03/02/2015 11:17 PM, Shubham Bansal wrote:
> Hi,
> 
> I have one more problem with the storing latest writer for a memorycell.
> According to the following code in DataFlow.C :-
> 
>             // Merge writer sets (but do not set changed=true because
> writer sets don't form a lattice and might not
>             // converge to a fixed point during the dataflow loop).
>             std::set<rose_addr_t> srcWriters =
> srcState->get_latest_writers(srcCell->get_address(), 8, ops_.get(),
> ops_.get());
>             std::set<rose_addr_t> dstWriters =
> dstState->get_latest_writers(srcCell->get_address(), 8, ops_.get(),
> ops_.get());
>             if (srcWriters.size()!=dstWriters.size() ||
> !std::equal(srcWriters.begin(), srcWriters.end(), dstWriters.begin())) {
>                 MemoryCellList::CellList dstCells =
> dstState->scan(srcCell->get_address(), 8, ops_.get(), ops_.get(),
>                                                                  
>  shortCircuited /*out*/);
>                 BOOST_FOREACH (const MemoryCellPtr &dstCell, dstCells)
>                     dstCell->clear_latest_writer();
> 
> It has not merged the two sets of rose_addr_t i.e srcWriters and dstWriters.
> Another problem with same code is that as far as i know, we can add only
> writer rose_addr_t to a MemoryCell but my project requires me to store
> more then one writer instructions rose_addr_t ( because of the case of
> merging of two or more BB ). Is there any way possible to implement this ?
> 
> Thanks,
> Shubham Bansal


More information about the rose-public mailing list