srcSlice is a fast, lightweight srcML tool for static slicing. srcSlice reads srcML output files and produces variable slices in JSON, these slices contain details such as where a variable is used and defined, passed into a function as an argument, function of origin, class it is contained in, variables that are data-dependent of it, and potential aliases.
Install srcML
This is a srcML tool, if you do not have srcML installed you must install it. You can download an installer here or you can build from source.
# After running 'make' when building srcML, run 'make install' to ensure cmake can find the srcML package when building srcSlice
git clone --recursive https://github.com/srcML/srcML.gitgit clone --recursive https://github.com/srcML/srcSlice.git
cmake srcSlice/ -B build -DBUILD_TESTS=OFF
cmake --build build --target installgit clone --recursive https://github.com/srcML/srcSlice.git
cmake srcSlice/ -B buildThis project uses the nlohmann json for handling JSON
# Linux
apt install nlohmann-json3-dev
sudo pacman -S nlohmann-json
# macOS
brew install nlohmann-jsonInput: A srcML file of source code with --position and --hash options.
srcML file can be a single unit (one source code file) or an archive (multiple source code files).
srcml shell_sort.cpp -o shell_sort.cpp.xml --position --hash
Output: A JSON file containing the slice information about each variable contained in the input file.
./srcslice shell_sort.cpp.xml -o results.json
srcSlice supports multi-file slicing against a srcML archive:
srcml src/ -o src.xml -r --position --hash
./srcslice src.xml -o results.json
srcSlice (srcML Slicing Tool)
Usage: srcslice [OPTIONS] input
Positionals:
input srcML FILE REQUIRED Name of the srcML input file [Must be built using the --position and --hash flags]
Options:
-h,--help Print this help message and exit
-o,--output TEXT Name of the JSON output file [Stdout is Default]
-t,--threads INT [7] Number of concurrent threads [Default 7]
-i,--iterations INT [1] Number of iterations of interprocedural
-c,--control-edges Compute Control-Edges for all Slices
-a,--expand-aliases Perform Computations with Slice's Aliases
-v,--verbose Display Debug Info at Runtime
-p,--progress Display Visual Feedback at Runtime
Generate slices and write output to standard output
./srcslice shell_sort.cpp.xml
Generate slices and write output to slices.json
./srcslice shell_sort.cpp.xml -o slices.json
| Attribute | Description |
|---|---|
File |
File path of the source code the slice variable originates from |
Language |
Language of the source code file |
Namespace |
List of namespaces the slice variable is contained in |
Class |
Name of the class containing the slice variable |
Function |
Name of the function containing the slice variable |
Type |
Data type of the slice variable |
Name |
Variable name of the slice variable |
Decl |
Position of the slice variable's declaration |
Dependence |
A list of variable-position pairs, containing:
|
Aliases |
A list of potential targets of a pointer or reference |
Calls |
A list of function calls where the slice variable is used as an argument. This includes:
|
Use |
A set of positions where the slice variable is used |
Definition |
A set of positions where the slice variable is declared and redefined |
Control Edges |
A set of position pairs indicating the potential flow from a given starting point |