Skip to content

Wrong line number with getLineNumber() #1360

@seviezhou

Description

@seviezhou

Hi, I am trying to use soot to get the line number of each Stmt. Here is my code:

while (stmtIt.hasNext()) {

	Stmt stmt = (Stmt) stmtIt.next();

	try {
		if (stmt.hasTag("LineNumberTag")) {
			LineNumberTag tag = (LineNumberTag)stmt.getTag(("LineNumberTag"));
			stmtFilewriter.write(method.getName() + "~" +tag.getLineNumber() + "::" + stmt.toString() + "\n");
		} else {
			stmtFilewriter.write(stmt.toString() + "\t" + Integer.toString(stmtLocalIndex) + "\n");
		}
	} catch (Exception e) {
	}
}

I found that soot wrongly compute the line number for expression like:

if (statement1 && statement2)

The statements before and after && (or ||) should be in the same line, but soot returns different lines for them.

Here is my target program:

package asg;

public class Utils {

    public static boolean wildcardMatch(final String fileName, final String wildcardMatcher) {
        if (fileName == null && wildcardMatcher == null) {
            return true;
        }
        return false;
 }

The result is:

fileName := @parameter0: java.lang.String
wildcardMatcher := @parameter1: java.lang.String
wildcardMatch~6::if fileName != null goto return 0
wildcardMatch~9::if wildcardMatcher != null goto return 0
wildcardMatch~7::return 1
wildcardMatch~9::return 0

fileName != null and wildcardMatcher != null should all be in line 6, but the result for wildcardMatcher != null is line 9.

Here is the output of javap -classpath utils_bin -l -c asg.Utils, and it gets correct result:

Compiled from "Utils.java"
public class asg.Utils {
  public asg.Utils();
    Code:
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: return
    LineNumberTable:
      line 3: 0
    LocalVariableTable:
      Start  Length  Slot  Name   Signature
          0       5     0  this   Lasg/Utils;

  public static boolean wildcardMatch(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ifnonnull     10
       4: aload_1
       5: ifnonnull     10
       8: iconst_1
       9: ireturn
      10: iconst_0
      11: ireturn
    LineNumberTable:
      line 6: 0
      line 7: 8
      line 9: 10
    LocalVariableTable:
      Start  Length  Slot  Name   Signature
          0      12     0 fileName   Ljava/lang/String;
          0      12     1 wildcardMatcher   Ljava/lang/String;
}

Here is all the files to reproduce, run with run.sh:
bug.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions