一、一个简单的例子
1. 实验Demo
(1) Android.mk
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= mytest.c LOCAL_MODULE:= mytest LOCAL_C_FLAGS += -g -O0 LOCAL_SHARED_LIBRARIES := libc include $(BUILD_EXECUTABLE)
(2) 测试程序
1 #include <stdio.h> 2 #include <unistd.h> 3 4 static void my_sleep_func(void) { 5 int i; 6 7 for(i = 0; i < 10; i++) { 8 usleep(5000); 9 } 10 } 11 12 int main() 13 { 14 15 int *p = NULL; 16 17 printf("Hello World!\n"); 18 19 my_sleep_func(); 20 21 *p = 110; //dump 22 23 return 0; 24 }
2. out目录下生成的可用文件
obj/EXECUTABLES/mytest_intermediates/LINKED/mytest //OK obj/EXECUTABLES/mytest_intermediates/mytest //不能用,list 命令显示"No symbol table is loaded" symbols/system/bin/mytest //OK system/bin/mytest //不能用,list 命令显示"No symbol table is loaded"
3. 实验示范
先将编译生成的 mytest 可执行elf文件push到设备的 /data/local/tmp 目录下,然后将测试文件也push到这个目录下。然后启动 adeb,使用其中的 gdb 工具进行调试。
root@localhost:/data/local/tmp# gdb mytest_1 (gdb) l 3 vendor/oplus/frameworks/cmd/mytest/mytest.c: No such file or directory. //若没有将.c文件放到当前目录或 (gdb) show dir Source directories searched: $cdir:$cwd //应该是表示compile dir 和 current dir为两个默认的源文件搜索路径 (gdb) b 15 Breakpoint 1 at 0x1064: file vendor/oplus/frameworks/cmd/mytest/mytest.c, line 17. //和源文件行号对应不上,b 15却显示的是17 (gdb) r Starting program: /data/local/tmp/mytest_1 Breakpoint 1, main () at vendor/oplus/frameworks/cmd/mytest/mytest.c:17 17 printf("Hello World!\n"); (gdb) c Continuing. Hello World! //输出后就正常oops死机了
标签:17,mytest,gdb,GDB,调试程序,Android,include,LOCAL,dir From: https://www.cnblogs.com/hellokitty2/p/16869220.html