Skip to content

Symbolic Execution using java.lang.String #12

@danglotb

Description

@danglotb

Hi,

I am using JBSE, I ran on the provided example, and on my own.

My example is a basic implementation of the standard charAt method of String: char charAt(String s, int i), i.e. it returns the char at the i th position in the given String s.

I setted up JBSE to perform the symbolic execution. But when I actually run it, It takes a while.

I assumed that came from the fact that there are a lot of possibilities. Also, I added an assumption at the begin of my method: assume(s.length < 4).

At the end, I obtain something like:

.1.1.1[3] 
Leaf state, raised exception: Object[2]
Path condition: 
	{R0} == Object[0] (fresh) &&
	pre_init(smalldemos/ifx/TestSuiteExample) &&
	{R1} == Object[1] (fresh) &&
	{V4} < 16
	where:
	{R0} == {ROOT}:this &&
	{R1} == {ROOT}:s &&
	{V4} == {ROOT}:s.count
Static store: {
	
}
Heap: {
	Object[0]: {
		Origin: {ROOT}:this
		Class: smalldemos/ifx/TestSuiteExample
	}
	Object[1]: {
		Origin: {ROOT}:s
		Class: java/lang/String
		Field[0]: Name: hash, Type: I, Value: {V5} (type: I)
		Field[1]: Name: value, Type: [C, Value: {R2} (type: L)
		Field[2]: Name: offset, Type: I, Value: {V3} (type: I)
		Field[3]: Name: count, Type: I, Value: {V4} (type: I)
	}
	Object[2]: {
		Class: java/lang/NoClassDefFoundError
		Field[0]: Name: detailMessage, Type: Ljava/lang/String;, Value: null (type: 0)
		Field[1]: Name: cause, Type: Ljava/lang/Throwable;, Value: null (type: 0)
		Field[2]: Name: backtrace, Type: Ljava/lang/Object;, Value: Object[3] (type: L)
		Field[3]: Name: stackTrace, Type: [Ljava/lang/StackTraceElement;, Value: null (type: 0)
	}
...

According to Leaf state, raised exception: Object[2] and to Object[2]: { Class: java/lang/NoClassDefFoundError, It seems that JBSE does not find java.lang.String, which is strange since I gave the rt.jar in the classpath.

Here, found more information about my setup:

@Test
    public void testExample() throws Exception {
        final RunParameters p = new RunParameters();
        p.addClasspath(
                "pathTo/jbse/data/jre/rt.jar",
                "./target/classes",
                "./target/test-classes",
                "lib/jbse-0.8.0-SNAPSHOT.jar"
        );
        p.setMethodSignature("smalldemos/ifx/Example", "(Ljava/lang/String;I)C", "charAt");
        p.setDecisionProcedureType(RunParameters.DecisionProcedureType.Z3);
        p.setExternalDecisionProcedurePath("lib/z3/bin/z3");
        p.setOutputFileName("out/runIf_z3.txt");
        p.setStepShowMode(RunParameters.StepShowMode.LEAVES);
        p.setStateFormatMode(RunParameters.StateFormatMode.FULLTEXT);
        final Run r = new Run(p);
        r.run();
    }
public char charAt(String s, int index) {
        assume(s.length() < 4);
        if (index <= 0)
            return s.charAt(0);
        else if (index < s.length())
            return s.charAt(index);
        else
            return s.charAt(s.length() - 1);
    }

Could you please tell me what I am doing wrong? Or point me some extra information?

Thank you very much.

-- Benjamin.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions