Skip to content

Commit f3f12c1

Browse files
committed
Lab2/Assignment2 comments and tips + launch.json
1 parent 492d4ef commit f3f12c1

File tree

5 files changed

+31
-15
lines changed

5 files changed

+31
-15
lines changed

.vscode/launch.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "(lldb) Launch",
6-
"type": "lldb",
5+
"name": "(debug) Launch",
6+
"type": "cppdbg",
77
"request": "launch",
88
// Please change to the executable of your current lab or assignment
99
// | Lab/Assignment | "program" | "args" |
@@ -16,7 +16,8 @@
1616
"program": "${workspaceFolder}/bin/hello",
1717
"args": [], // may input the test llvm bc file or other options and flags the program may use
1818
"cwd": "${workspaceFolder}",
19-
"preLaunchTask": "C/C++: cpp build active file"
19+
"preLaunchTask": "C/C++: cpp build active file",
20+
"MIMode": "lldb"
2021
}
2122
]
2223
}

Assignment-2/Assignment-2.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ using namespace z3;
3535

3636
/// TODO: Implement your context-sensitive ICFG traversal here to traverse each program path (once for any loop) from
3737
/// You will need to collect each path from src node to snk node and then add the path to the `paths` set by
38-
/// implementing the `collectICFGPath` method. This implementation, slightly different from Assignment-1, requires
39-
/// ICFGNode* as the first argument.
38+
/// calling the `collectAndTranslatePath` method which is then trigger the path translation.
39+
/// This implementation, slightly different from Assignment-1, requires ICFGNode* as the first argument.
4040
void SSE::reachability(const ICFGEdge* curEdge, const ICFGNode* snk) {
4141
/// TODO: your code starts from here
4242
}
4343

4444
/// TODO: collect each path once this method is called during reachability analysis, and
4545
/// Collect each program path from the entry to each assertion of the program. In this function,
4646
/// you will need (1) add each path into the paths set, (2) call translatePath to convert each path into Z3 expressions.
47-
/// Note that translatePath returns true if the path is feasible, infeasible otherwise. (3) If a path is feasible,
47+
/// Note that translatePath returns true if the path is feasible, false if the path is infeasible. (3) If a path is feasible,
4848
/// you will need to call assertchecking to verify the assertion (which is the last ICFGNode of this path).
4949
void SSE::collectAndTranslatePath() {
5050
/// TODO: your code starts from here
@@ -64,8 +64,16 @@ bool SSE::handleRet(const RetCFGEdge* retEdge) {
6464
return true;
6565
}
6666

67-
/// TODO: Implement handling of branch statement inside a function
68-
/// Return true means a feasible path, false otherwise
67+
/// TODO: Implement handling of branch statements inside a function
68+
/// Return true if the path is feasible, false otherwise.
69+
/// A given branch on the ICFG looks like the following:
70+
/// ICFGNode1 (condition %cmp)
71+
/// 1 / \ 0
72+
/// ICFGNode2 ICFGNode3
73+
/// edge->getCondition() returns the branch condition variable (%cmp) of type SVFValue* (for if/else) or a numeric condition variable (for switch).
74+
/// Given the condition variable, you could obtain the SVFVar ID via "svfir->getValueNode(edge->getCondition())""
75+
/// edge->getCondition() returns nullptr if this IntraCFGEdge is not a branch.
76+
/// edge->getSuccessorCondValue() returns the actual condition value (1/0 for if/else) when this branch/IntraCFGEdge is executed. For example, the successorCondValue is 1 on the edge from ICFGNode1 to ICFGNode2, and 0 on the edge from ICFGNode1 to ICFGNode3
6977
bool SSE::handleBranch(const IntraCFGEdge* edge) {
7078
/// TODO: your code starts from here
7179
return true;
@@ -100,6 +108,12 @@ bool SSE::handleNonBranch(const IntraCFGEdge* edge) {
100108
{
101109
// TODO: implement GepStmt handler here
102110
}
111+
/// Given a CmpStmt "r = a > b"
112+
/// cmp->getOpVarID(0)/cmp->getOpVarID(1) returns the first/second operand, i.e., "a" and "b"
113+
/// cmp->getResID() returns the result operand "r" and cmp->getPredicate() gives you the predicate ">"
114+
/// Find the comparison predicates in "class CmpStmt:Predicate" under SVF/svf/include/SVFIR/SVFStatements.h
115+
/// You are only required to handle integer predicates, including ICMP_EQ, ICMP_NE, ICMP_UGT, ICMP_UGE, ICMP_ULT, ICMP_ULE, ICMP_SGT, ICMP_SGE, ICMP_SLE
116+
/// We assume integer-overflow-free in this assignment
103117
else if (const CmpStmt *cmp = SVFUtil::dyn_cast<CmpStmt>(stmt))
104118
{
105119
// TODO: implement CmpStmt handler here
@@ -201,9 +215,9 @@ void SSE::analyse() {
201215
assert(SVFUtil::isa<GlobalICFGNode>(src) && "reachability should start with GlobalICFGNode!");
202216
for (const ICFGNode* sink : identifySinks()) {
203217
const IntraCFGEdge startEdge(nullptr, const_cast<ICFGNode*>(src));
204-
handleIntra(&startEdge);
218+
/// start traversing from the entry to each assertion and translate each path
205219
reachability(&startEdge, sink);
206220
resetSolver();
207221
}
208222
}
209-
}
223+
}

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ENV HOME=/home/SVF-tools
1515

1616
# Define dependencies.
1717
ENV lib_deps="cmake g++ gcc git zlib1g-dev libncurses5-dev libtinfo6 build-essential libssl-dev libpcre2-dev zip libzstd-dev"
18-
ENV build_deps="wget xz-utils git tcl software-properties-common"
18+
ENV build_deps="wget xz-utils git gdb tcl software-properties-common"
1919

2020
# Fetch dependencies.
2121
RUN apt-get update --fix-missing
@@ -56,5 +56,6 @@ WORKDIR ${HOME}
5656
RUN git clone "https://github.com/SVF-tools/Software-Security-Analysis.git"
5757
WORKDIR ${HOME}/Software-Security-Analysis
5858
RUN echo "Building Software-Security-Analysis ..."
59+
RUN sed -i 's/lldb/gdb/g' ${HOME}/Software-Security-Analysis/.vscode/launch.json
5960
RUN cmake -DCMAKE_BUILD_TYPE=MinSizeRel .
6061
RUN make -j8

Lab-Exercise-2/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ target_link_libraries(lab2 ${SVF_LIB} ${llvm_libs} ${Z3_LIBRARIES})
88
set_target_properties(lab2 PROPERTIES
99
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
1010

11-
foreach (i RANGE 1 7)
11+
foreach (i RANGE 1 10)
1212
add_test(
1313
NAME lab2_test${i}
1414
COMMAND lab2 test${i}
1515
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
1616
)
17-
endforeach ()
17+
endforeach ()

Lab-Exercise-2/test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ int main(int argc, char** argv) {
9898
}
9999

100100
if (result) {
101-
std::cout << "The test-" << test_name << " passed!!" << std::endl;
101+
std::cout << test_name << " passed!!" << std::endl;
102102
}
103103
else {
104-
std::cout << SVFUtil::errMsg("The test-") << SVFUtil::errMsg(test_name)
104+
std::cout << SVFUtil::errMsg(test_name)
105105
<< SVFUtil::errMsg(" assertion is unsatisfiable!!") << std::endl;
106106
assert(result);
107107
}

0 commit comments

Comments
 (0)