调试流程
准备一份测试代码.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//luoTst.c
#include <stdlib.h>
#include <stdio.h>
//int fun1(int a, int b) __attribute((__annotate__(("fla"))));
//int fun2(int a, int b) __attribute((__annotate__(("nofla"))));
//int main(int argc, char** argv) __attribute((__annotate__(("bcf"))));
int fun1 ( int a , int b ){
if ( a + b > 10 ){
return 10 ;
} else {
return 100 ;
}
}
int fun2 ( int a , int b ){
if ( a - b > 10 ){
return 5 ;
} else {
return 50 ;
}
}
int main ( int argc , char ** argv ) {
if ( argc > 2 ){
printf ( "hello world \n " );
} else {
printf ( "hello ollvm \n " );
}
printf ( "fun1:%d \n " , fun1 ( argc , 6 ));
printf ( "fun2:%d \n " , fun2 ( argc , 8 ));
return 0 ;
}
移植ollvm到单独的so.
luoOllvm.7z
调试环境准备
1
2
3
4
5
①将 llvm编译出的debug二进制文件添加到环境变量中
export PATH =/ home / luohun / Desktop / llvm - project - 9.0.1 / build_debug / bin : $ PATH
②用 CLion打开上述移植的ollvm so工程 , 命令行添加如下命令
- Xclang - load - Xclang / home / luohun / Desktop / OLLVM / cmake - build - debug / ollvm / lib / Transforms / Obfuscation / LLVMObfuscation . so - mllvm - fla / home / luohun / Desktop / luo / luoTst . c - emit - llvm - S - o / home / luohun / Desktop / luo / luoTst_fla . ll
构造异常,看下真正的调试命令
上面的调试环境准备后以后,我们会发现仍然无法进行调试,原因是因为平时我们用clang进行编译的时候,它内部会调用clang-9来进行编译.接下来我们来人为构造异常,看下真正的调试命令.
更改调试命令
1
- cc1 - triple x86_64 - unknown - linux - gnu - emit - llvm - disable - free - main - file - name luoTst . c - mrelocation - model static - mthread - model posix - mdisable - fp - elim - fmath - errno - masm - verbose - mconstructor - aliases - munwind - tables - fuse - init - array - target - cpu x86 - 64 - dwarf - column - info - debugger - tuning = gdb - coverage - notes - file / home / luohun / Desktop / luo / luoTst_fla . gcno - resource - dir / home / luohun / Desktop / llvm - project - 9.0.1 / build_debug / lib / clang / 9.0.1 - internal - isystem / usr / local / include - internal - isystem / home / luohun / Desktop / llvm - project - 9.0.1 / build_debug / lib / clang / 9.0.1 / include - internal - externc - isystem / usr / include / x86_64 - linux - gnu - internal - externc - isystem / include - internal - externc - isystem / usr / include - fdebug - compilation - dir / home / luohun / Desktop / llvm - project - 9.0.1 / build_debug / bin - ferror - limit 19 - fmessage - length 0 - fobjc - runtime = gcc - fdiagnostics - show - option - fcolor - diagnostics - load / home / luohun / Desktop / OLLVM / cmake - build - debug / ollvm / lib / Transforms / Obfuscation / LLVMObfuscation . so - mllvm - fla - faddrsig - o / home / luohun / Desktop / luo / luoTst_fla . ll - x c / home / luohun / Desktop / luo / luoTst . c
进行调试
参考链接
WritingAnLLVMPass