SVFIR - SVF-tools/Software-Security-Analysis GitHub Wiki
- SVFIR is the demo program sample to understand SVFIR and their graph representations, i.e., ICFG and PAG
SVFIR Layout
SVFIR/
|-- CMakeLists.txt
|-- SVFIR.cpp
|-- compile.sh
`-- src
|-- swap.c
|-- control-flow.c
|-- example.c
`-- demo.c
1. Get the latest code template
cd $HOME/Software-Security-Analysis
and git pull
in your terminal to make sure you always have the latest version of the code template.
* Before coding, please type 2. LLVM IR Generation
control + ~
to call out command line
* Use example.c
via the following command line
Option 1: Generate LLVM IR of cd /home/SVF-tools/Software-Security-Analysis/SVFIR
clang -S -c -O0 -fno-discard-value-names -emit-llvm src/example.c -o example.ll
opt -S -p=mem2reg example.ll -o example.ll # optional command line to simplify the IR to promote memory operations to registers
compile.sh
Option 2: Generate LLVM IR via cd /home/SVF-tools/Software-Security-Analysis/SVFIR
sh compile.sh src/example.c
The .ll file (i.e., example.ll) will be generated under the /home/SVF-tools/Software-Security-Analysis/SVFIR
folder
3. Run and debug code under the SVFIR folder
launch.json
3.1You need to set the "program"
to be the executable file of SVFIR, i.e., "${workspaceFolder}/bin/svfir"
in
launch.json in order to run and debug
You need to set the "args"
to be the .ll file you have just generated, i.e., "${workspaceFolder}/SVFIR/example.ll"
in
launch.json in order to run and debug
SVFIR.cpp
3.2 Debug and run -
The code in
SVFIR.cpp
shows examples of printing and dumping three types of code graphs, including ICFG, PAG and Constraint Graph. -
Tips for debugging: Always good to use "toString()" method to understand the value of each node and each edge on a code graph
-
The two dot files (i.e,
example.ll.icfg.dot
andexample.ll.pag.dot
) will be generated under the/home/SVF-tools/Teaching-Software-Verification/SVFIR
folder
4. Visualize ICFG, Constraint Graph and SVFIR/PAG graph
4.1 VSCode Graphviz Interactive Preview extensions
4.2 Open the dot file and graph visualization
- Open the dot file under, for example,
/home/SVF-tools/Teaching-Software-Verification/SVFIR/example.ll.icfg.dot
which is the ICFG of the program and call out the command palette
- Enter
> Graphviz
and select `Interactive Preview (beside)
- You will see the ICFG on the right hand side