CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
69 lines
2.5 KiB
TeX
69 lines
2.5 KiB
TeX
\section{Examples}
|
|
\label{sec:example}
|
|
|
|
\subsection{Function Disassembly}
|
|
|
|
The following example uses ParseAPI and InstructionAPI to disassemble
|
|
the basic blocks in a function. As an example, it can be built with
|
|
G++ as follows: \code{g++ -std=c++0x -o code\_sample code\_sample.cc -L<library
|
|
install path> -I<headers install path> -lparseAPI -linstructionAPI
|
|
-lsymtabAPI -lsymLite -ldynDwarf -ldynElf -lcommon -L<libelf path>
|
|
-lelf -L<libdwarf path> -ldwarf}. Note: this example must be
|
|
compiled with C++11x support; for G++ this is enabled with
|
|
\code{-std=c++0x}, and it is on by default for Visual Studio.
|
|
|
|
\lstset{language=[GNU]C++,basicstyle=\fontfamily{fvm}\selectfont\small}
|
|
\lstset{numbers=left, numberstyle=\tiny, stepnumber=5, numbersep=5pt}
|
|
\lstset{showstringspaces=false}
|
|
\lstinputlisting{code_sample.cc}
|
|
|
|
\subsection{Control flow graph traversal}
|
|
|
|
The following complete example uses the ParseAPI to parse a binary and
|
|
dump its control flow graph in the Graphviz file format. As an
|
|
example, it can be built with G++ as follows: \code{g++ -std=c++0x -o example
|
|
example.cc -L<library install path> -I<headers install path>
|
|
-lparseAPI -linstructionAPI -lsymtabAPI -lsymLite -ldynDwarf
|
|
-ldynElf -lcommon -L<libelf path> -lelf -L<libdwarf path>
|
|
-ldwarf}. Note: this example must be compiled with C++11x support;
|
|
for G++ this is enabled with \code{-std=c++0x}, and it is on by
|
|
default for Visual Studio.
|
|
|
|
\lstset{language=[GNU]C++,basicstyle=\fontfamily{fvm}\selectfont\small}
|
|
\lstset{numbers=left, numberstyle=\tiny, stepnumber=5, numbersep=5pt}
|
|
\lstset{showstringspaces=false}
|
|
\lstinputlisting{example.cc}
|
|
|
|
\subsection{Loop analysis}
|
|
|
|
The following code example shows how to get loop information using ParseAPI once we have an parsed Function object.
|
|
|
|
\lstset{language=[GNU]C++,basicstyle=\fontfamily{fvm}\selectfont\small}
|
|
\lstset{numbers=left, numberstyle=\tiny, stepnumber=5, numbersep=5pt}
|
|
\lstset{showstringspaces=false}
|
|
\begin{lstlisting}
|
|
void GetLoopInFunc(Function *f) {
|
|
// Get all loops in the function
|
|
vector<Loop*> loops;
|
|
f->getLoops(loops);
|
|
|
|
// Iterate over all loops
|
|
for (auto lit = loops.begin(); lit != loops.end(); ++lit) {
|
|
Loop *loop = *lit;
|
|
|
|
// Get all the entry blocks of the loop
|
|
vector<Block*> entries;
|
|
loop->getLoopEntries(entries);
|
|
|
|
// Get all the blocks in the loop
|
|
vector<Block*> blocks;
|
|
loop->getLoopBasicBlocks(blocks);
|
|
|
|
// Get all the back edges in the loop
|
|
vector<Edge*> backEdges;
|
|
loop->getBackEdges(backEdges);
|
|
}
|
|
}
|
|
\end{lstlisting}
|
|
|