resess / Slicer4J

Slicer4J is an accurate, low-overhead dynamic slicer for Java programs.
MIT License
39 stars 17 forks source link

trace.log_icdg.log does not contain required jimple-statement #2

Closed ArtemUntila closed 2 years ago

ArtemUntila commented 2 years ago

Issue.java:

1.  public class Issue {
2.      
3.      public static void main(String[] args) {
4.          if (args.length != 1)
5.              throw new IllegalArgumentException();
6.          Integer length = getLength(args[0]);
7.          String output = "Empty";
8.          if (length != null) {
9.              output = "Not " + output;
10.         }
11.         System.out.println(output);
12.     }
13.     
14.     private static Integer getLength(String s) {
15.         int length = s.length();
16.         if (length == 0) {
17.             return null;
18.         }
19.         return length;
20.     }
21.     
22. }

Running Slicer4J w.r.t. Issue:11 line:

cd scripts
python3 slicer4j.py -j ../issue.jar -o ../issue -b Issue:11 -m "Issue something"

And it fails with:

Slicing from line Issue:11
Traceback (most recent call last):
  ...
UnboundLocalError: local variable 'sc' referenced before assignment

https://github.com/resess/Slicer4J/blob/235b4661dbfc414cd8d629d127d2c5984d933ebe/scripts/slicer4j.py#L117 The reason is that trace.log_icdg.log does not contain jimple-statement println() and statement with LINENO:11:FILE:Issue at all. If we remove some of the statements if (args.length != 1), if (javaFiles != null) or method call with parameter args[0]getLength(args[0]), it will work fine.

khaled-e-a commented 2 years ago

Thank you for bringing this to my attention. Fixed in latest commit in the dynamic slicing core. Added this issue as a test case.