下面的命令在Hisi的Hi3716C的Android4.0平台测试
1.Strace
作用:显示所有由用户空间程序发出的系统调用。
strace 显示这些调用的参数并返回符号形式的值。strace 从内核接收信息,而且不需要以任何特殊的方式来构建内核。 下面记录几个常用 option . 1 -f -F选项告诉strace同时跟踪fork和vfork出来的进程 2 -o xxx.txt 输出到某个文件。 3 -e execve 只记录 execve 这类系统调用
实例:cat运行时的系统调用
root@android:/mnt/sda/sda1 # strace -o /mnt/sdcard/output cat
aaaabbbbcccc^Croot@android:/mnt/sda/sda1 # root@android:/mnt/sda/sda1 # root@android:/mnt/sda/sda1 # cat /mnt/sdcard/output execve("/system/bin/cat", ["cat"], [/* 21 vars */]) = 0syscall_983045(0xb0012c78, 0xb00144c4, 0xffffffc8, 0, 0, 0xb00094f0, 0xbee58b90, 0xf0005, 0xb0012c78, 0, 0, 0, 0, 0xbee58b40, 0xb00047bb, 0xb0001200, 0x10, 0xb0012c78, 0xb691, 0, 0x7379732f, 0x2f6d6574, 0x2f6e6962, 0x746163, 0, 0, 0, 0, 0, 0, 0, 0) = 0getpid() = 14443getuid32() = 0geteuid32() = 0getgid32() = 1007getegid32() = 1007sigaction(SIGILL, {0xb0005b29, [], SA_RESTART|SA_SIGINFO}, NULL, 0x700020) = 0sigaction(SIGABRT, {0xb0005b29, [], SA_RESTART|SA_SIGINFO}, NULL, 0x700020) = 0sigaction(SIGBUS, {0xb0005b29, [], SA_RESTART|SA_SIGINFO}, NULL, 0x700020) = 0sigaction(SIGFPE, {0xb0005b29, [], SA_RESTART|SA_SIGINFO}, NULL, 0x700020) = 0sigaction(SIGSEGV, {0xb0005b29, [], SA_RESTART|SA_SIGINFO}, NULL, 0x700020) = 0sigaction(SIGSTKFLT, {0xb0005b29, [], SA_RESTART|SA_SIGINFO}, NULL, 0x700020) = 0sigaction(SIGPIPE, {0xb0005b29, [], SA_RESTART|SA_SIGINFO}, NULL, 0x700020) = 0stat64("/vendor/lib/liblog.so", 0xbee58830) = -1 ENOENT (No such file or directory)stat64("/system/lib/liblog.so", {st_mode=S_IFREG|0644, st_size=13888, ...}) = 0open("/system/lib/liblog.so", O_RDONLY|O_LARGEFILE) = 3lseek(3, 0, SEEK_SET) = 0read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\000"..., 4096) = 4096lseek(3, -8, SEEK_END) = 13880read(3, "\1\0\0\0\0\0\0\0", 8) = 8mmap2(NULL, 16384, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40042000mmap2(0x40042000, 10956, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x40042000mprotect(0x40042000, 12288, PROT_READ|PROT_WRITE|PROT_EXEC) = 0mmap2(0x40045000, 412, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x3) = 0x40045000close(3) = 0stat64("/vendor/lib/libc.so", 0xbee58588) = -1 ENOENT (No such file or directory)stat64("/system/lib/libc.so", {st_mode=S_IFREG|0644, st_size=282244, ...}) = 0open("/system/lib/libc.so", O_RDONLY|O_LARGEFILE) = 3lseek(3, 0, SEEK_SET) = 0read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\000"..., 4096) = 4096lseek(3, -8, SEEK_END) = 282236read(3, "\1\0\0\0\0\0\0\0", 8) = 8mmap2(NULL, 327680, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400de000mmap2(0x400de000, 268384, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x400de000mprotect(0x400de000, 270336, PROT_READ|PROT_WRITE|PROT_EXEC) = 0mmap2(0x40120000, 10132, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x42) = 0x40120000mmap2(0x40123000, 43804, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40123000close(3) = 0mprotect(0x400de000, 270336, PROT_READ|PROT_EXEC) = 0SYS_224(0, 0xbee39000, 0x20000, 0xbee58570) = 14443syscall_983045(0x4012d4c4, 0x4012d488, 0x4012d5c0, 0x40, 0x4012d488, 0xbee58b90, 0xbee58b9c, 0xf0005, 0xbee39000, 0x40123000, 0x50000, 0x400de000, 0, 0xbee58568, 0x40105c79, 0x400eb434, 0x60000010, 0x4012d4c4, 0xb691, 0, 0x7379732f, 0x2f6d6574, 0x2f62696c, 0x6362696c, 0x6f732e, 0x6f, 0, 0, 0, 0, 0, 0) = 0mmap2(NULL, 32768, PROT_READ, MAP_SHARED, 8, 0) = 0x4012e000msgget(0x1, 0xbee58590, 0x400f7ba5, 0x400f7ba7) = 0open("/dev/urandom", O_RDONLY|O_LARGEFILE) = 3read(3, "Iµòì", 4) = 4close(3) = 0stat64("/vendor/lib/libstdc++.so", 0xbee58588) = -1 ENOENT (No such file or directory)stat64("/system/lib/libstdc++.so", {st_mode=S_IFREG|0644, st_size=5520, ...}) = 0open("/system/lib/libstdc++.so", O_RDONLY|O_LARGEFILE) = 3lseek(3, 0, SEEK_SET) = 0read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\000"..., 4096) = 4096lseek(3, -8, SEEK_END) = 5512read(3, "\1\0\0\0\0\0\0\0", 8) = 8mmap2(NULL, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40136000mmap2(0x40136000, 2728, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x40136000mprotect(0x40136000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC) = 0mmap2(0x40137000, 276, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x1) = 0x40137000close(3) = 0mprotect(0x40136000, 4096, PROT_READ|PROT_EXEC) = 0stat64("/vendor/lib/libm.so", 0xbee58588) = -1 ENOENT (No such file or directory)stat64("/system/lib/libm.so", {st_mode=S_IFREG|0644, st_size=87412, ...}) = 0open("/system/lib/libm.so", O_RDONLY|O_LARGEFILE) = 3lseek(3, 0, SEEK_SET) = 0read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\000"..., 4096) = 4096lseek(3, -8, SEEK_END) = 87404read(3, "\1\0\0\0\0\0\0\0", 8) = 8mmap2(NULL, 90112, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40138000mmap2(0x40138000, 84300, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x40138000mprotect(0x40138000, 86016, PROT_READ|PROT_WRITE|PROT_EXEC) = 0mmap2(0x4014d000, 256, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x15) = 0x4014d000close(3) = 0mprotect(0x40138000, 86016, PROT_READ|PROT_EXEC) = 0mprotect(0x40042000, 12288, PROT_READ|PROT_EXEC) = 0stat64("/vendor/lib/libcutils.so", 0xbee58830) = -1 ENOENT (No such file or directory)stat64("/system/lib/libcutils.so", {st_mode=S_IFREG|0644, st_size=63908, ...}) = 0open("/system/lib/libcutils.so", O_RDONLY|O_LARGEFILE) = 3lseek(3, 0, SEEK_SET) = 0read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\000"..., 4096) = 4096lseek(3, -8, SEEK_END) = 63900read(3, "\1\0\0\0\0\0\0\0", 8) = 8mmap2(NULL, 126976, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40058000mmap2(0x40058000, 57644, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x40058000mprotect(0x40058000, 61440, PROT_READ|PROT_WRITE|PROT_EXEC) = 0mmap2(0x40067000, 1224, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0xf) = 0x40067000mmap2(0x40068000, 57788, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40068000close(3) = 0mprotect(0x40058000, 61440, PROT_READ|PROT_EXEC) = 0stat64("/vendor/lib/libusbhost.so", 0xbee58830) = -1 ENOENT (No such file or directory)stat64("/system/lib/libusbhost.so", {st_mode=S_IFREG|0644, st_size=9696, ...}) = 0open("/system/lib/libusbhost.so", O_RDONLY|O_LARGEFILE) = 3lseek(3, 0, SEEK_SET) = 0read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\000"..., 4096) = 4096lseek(3, -8, SEEK_END) = 9688read(3, "\1\0\0\0\0\0\0\0", 8) = 8mmap2(NULL, 12288, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40089000mmap2(0x40089000, 6324, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x40089000mprotect(0x40089000, 8192, PROT_READ|PROT_WRITE|PROT_EXEC) = 0mmap2(0x4008b000, 356, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x2) = 0x4008b000close(3) = 0mprotect(0x40089000, 8192, PROT_READ|PROT_EXEC) = 0mprotect(0x8000, 94208, PROT_READ|PROT_EXEC) = 0mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40077000mprotect(0x40077000, 4096, PROT_READ) = 0fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(204, 64), ...}) = 0brk(0) = 0x7f2000brk(0x7f2000) = 0x7f2000brk(0x7f4000) = 0x7f4000/* 输入 aa。。。调试*/read(0, "\n", 4096) = 1write(1, "\n", 1) = 1read(0, "aa\n", 4096) = 3write(1, "aa\n", 3) = 3read(0, "bb\n", 4096) = 3write(1, "bb\n", 3) = 3read(0, "cc\n", 4096) = 3write(1, "cc\n", 3) = 3read(0, 0x7f2008, 4096) = ? ERESTARTSYS (To be restarted)/* ctrl +c 退出*/--- SIGINT (Interrupt) @ 0 (0) ---+++ killed by SIGINT +++
相关文章
- 自助Linux之问题诊断工具strace【转】
- linux命令之调试工具strace的深入分析
- [置顶] 自娱自乐6之Linux gadget驱动5(自编gadget驱动,包涵与之通讯的主机usb驱动,已调试通过)
- [置顶] Linux调试工具之:Strace
- Linux下的调试工具strace与ltrace
- Linux调试工具strace和gdb常用命令小结
- [置顶] 自娱自乐7之Linux UDC驱动2(自编udc驱动,现完成枚举过程,从驱动代码分析枚举过程)
- [置顶] Linux调试工具之:ftrace
- [置顶] Linux命令之远程登录/无密码登录-ssh,ssh-keygen,ssh-copy-id
- [置顶] Linux调试工具之:Strace