[Wala-wala] Mapping InstanceKey to SourceCode?

27 views
Skip to first unread message

Marcel Meissner

unread,
Jul 21, 2020, 7:42:29 AM7/21/20
to Wala...@lists.sourceforge.net
Hi,

I have only recently started to work with Wala for my master thesis.
I would like to include local parameters and static attributes in the
slice, which are currently not found.
For local parameters I could work this out.

private static int getLineNumber(int parameterIndex, Statement
statement, SSAAbstractInvokeInstruction ssa) {
    PointerKey pointerKey =
pa.getHeapModel().getPointerKeyForLocal(statement.getNode(),
ssa.getUse(parameterIndex));
    OrdinalSet<InstanceKey> set = pa.getPointsToSet(pointerKey);
    if (!set.iterator().hasNext()) {
        return -1;
    }
    InstanceKey instanceKey = set.iterator().next();
    System.out.println("InstanceKey: " + instanceKey);
    .....
    return lineNumber;
}

Is it possible that I get the line number of the source code by using
the InstanceKey?
For statements this is no problem, but I can't find any idea or solution
for InstanceKeys.
Furthermore, I would like to know how to get the InstanceKey for static
attributes.
Or is my approach wrong and there is an easier/better way to get the
line number of the source code of local parameters and attributes?
Thanks for your help in advance.

Greeting,
Marcel

_______________________________________________
Wala-wala mailing list
Wala...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wala-wala

Raffi T Khatchadourian

unread,
Jul 21, 2020, 11:30:02 AM7/21/20
to wala...@lists.sourceforge.net
-- 
Raffi Khatchadourian <raffi.khat...@hunter.cuny.edu>
Assistant Professor, Computer Science, Hunter College
Doctoral Faculty of the Graduate School and University Center's PhD Program in Computer Science
City University of New York (CUNY)

Marcel Meissner

unread,
Jul 23, 2020, 4:52:37 AM7/23/20
to wala...@lists.sourceforge.net

Hi Raffi,

Thanks for your tip. I took a closer look at the code and InstanceKey again.
InstanceKey unfortunately does not know SourcePosition. As far as I understood the code, you get SoucePosition or the line number via the instructionIndex. The problem is, the local variables are not directly mapped in the IR and therefore have no instructionIndex.

With this I mean the following point:
http://wala.sourceforge.net/wiki/index.php/UserGuide:Slicer
"Warning: exclusion of copy statements from slice".

Marcel

Manu Sridharan

unread,
Jul 23, 2020, 3:02:10 PM7/23/20
to WALA discussion and Q&A
Hi Marcel,

If an instance key is an AllocationSiteInNode, you can get the NewSiteReference, and then call IR.getNew() to get the corresponding IR instruction:


For other types of InstanceKeys, it may or may not make sense to have a corresponding source location; it depends on the level of abstraction.

Does that help?

--Manu

Marcel Meissner

unread,
Jul 23, 2020, 5:47:11 PM7/23/20
to wala...@lists.sourceforge.net

Hi Manu,

Unfortunately, this approach does not work either, since it also accesses instructions that do not exist. That is why there was a NullPointerExpetion.
It's best if I show you a sample of what I'm testing it on.

  private static int keyTwo = 256;
  public static void main(String[] args) {
    String s = "AES";
    Read read = Read.getInstance(s);
    SecRand secRand = new SecRand();
    int key = 256;
    String hallo = "hallo";
    test(hallo);
    read.init(key, secRand, keyTwo);
    read.generate();
  }

This example does not recognize "int key = 256" and string s = "AES", as expected.

I am looking at "read.init(key, secRand, keyTwo);". The statement is:
NORMAL main:invokevirtual < Application, LRead, init(ILSecRand;I)V > 5,8,6,11 @37 exception:12 Node: < Application, LReadWrite, main([Ljava/lang/String;)V > Context: Everywhere

If I output the statements (IR) as PDF, this one looks like this.
invokevirtual < Application, LRead, init(ILSecRand;I)V > v5,v8:#256,v6,v11 @37 exception:v12

This means v8 is "key", v6 is "secRand" and v11 is "keyTwo". So I try to get the line number from v8 somehow.
The PointerKey for this is: pointerKey[Node: < Application, LReadWrite, main([Ljava/lang/String;)V > Context: Everywhere, v8]
But from this key there is no InstanceKey through "pa.getPointsToSet(pointerKey)". I've only just realized it.
Therefore it is also possible that Wala has completely deleted this information. Because that would mean that it would be impossible to find out the LineNumber.
But maybe not, it's just a theory.

Marcel

Manu Sridharan

unread,
Jul 23, 2020, 8:10:53 PM7/23/20
to WALA discussion and Q&A
Hi Marcel,

I believe you are indeed running into this issue:


These types of assignments to locals get "optimized away" in the IR, and hence you cannot easily map back to source locations for these constant assignments.  If I were re-designing WALA from scratch I might go a different direction with this, but at this point this is pretty baked in to how the IR works.  I am not too sure what the best alternative here is.  You could potentially analyze the JVM bytecodes via Shrike and figure out where these string constants come from.  Alternately, you could separately parse the source code to find these statements.  Sorry I couldn't be more helpful.

Best,
Manu
Reply all
Reply to author
Forward
0 new messages