Android在执行c++代码时崩溃,不能用adb shell复制
Android crash executing C++ code not replicable with adb shell
我正在与应用程序的严重崩溃作斗争,我还失去了我剩下的一点头发。
问题是:如果我通过adb shell执行我的程序(用c++ 11编写),有NO崩溃。但是我仍然在eclipse模拟器和我的设备上得到SIGSEGV。
我必须通过一个简单的应用程序执行这个程序:
Android App代码:public BufferedReader startExample() {
String[] commandLine2 = {"/system/app/example", "/system/app/conf.xml"};
System.out.println("Example launched with "+currentScript);
Process process = null;
try {
process = Runtime.getRuntime().exec(commandLine2);
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
writer = new OutputStreamWriter(process.getOutputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return reader;
}
我在Logcat上收到的输出是这样的:
05-26 16:13:45.680: I/DEBUG(65): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
05-26 16:13:45.680: I/DEBUG(65): Build fingerprint: 'google/passion/passion:2.3.6/GRK39F/189904:user/release-keys'
05-26 16:13:45.680: I/DEBUG(65): pid: 2573, tid: 2573 >>> /system/app/example <<<
05-26 16:13:45.680: I/DEBUG(65): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
05-26 16:13:45.680: I/DEBUG(65): r0 00000027 r1 deadbaad r2 a0000000 r3 00000000
05-26 16:13:45.680: I/DEBUG(65): r4 00000001 r5 00000000 r6 001405d4 r7 00144838
05-26 16:13:45.680: I/DEBUG(65): r8 000eb53c r9 00000000 10 00000000 fp beba99b4
05-26 16:13:45.680: I/DEBUG(65): ip afd46668 sp beba97f8 lr afd191d9 pc afd15ca4 cpsr 60000030
05-26 16:13:45.680: I/DEBUG(65): d0 6772615f64696c75 d1 206e69687469776d
05-26 16:13:45.680: I/DEBUG(65): d2 7574706163206f65 d3 6874206e6f20656e
05-26 16:13:45.680: I/DEBUG(65): d4 2030202020203020 d5 2020203020202020
05-26 16:13:45.680: I/DEBUG(65): d6 3020202020202020 d7 2020202020202020
05-26 16:13:45.680: I/DEBUG(65): d8 0000000000000000 d9 0000000000000000
05-26 16:13:45.680: I/DEBUG(65): d10 0000000000000000 d11 0000000000000000
05-26 16:13:45.680: I/DEBUG(65): d12 0000000000000000 d13 0000000000000000
05-26 16:13:45.680: I/DEBUG(65): d14 0000000000000000 d15 0000000000000000
05-26 16:13:45.680: I/DEBUG(65): d16 bfa11178a5a14a1b d17 bfa0c9714fbcda40
05-26 16:13:45.680: I/DEBUG(65): d18 bfa0e1b8218a374c d19 bf91111111111116
05-26 16:13:45.680: I/DEBUG(65): d20 0000000000000000 d21 3fd99999ac013de9
05-26 16:13:45.680: I/DEBUG(65): d22 3fd24924a3334279 d23 3fcc71c536ee839c
05-26 16:13:45.680: I/DEBUG(65): d24 3fc74664af50539d d25 3fc39a09d078c69f
05-26 16:13:45.680: I/DEBUG(65): d26 0000000000000000 d27 0000000000000000
05-26 16:13:45.680: I/DEBUG(65): d28 0000000000000000 d29 0000000000000000
05-26 16:13:45.680: I/DEBUG(65): d30 0000000000000000 d31 0000000000000000
05-26 16:13:45.680: I/DEBUG(65): scr 00000010
05-26 16:13:45.680: I/DEBUG(65): #00 pc 00015ca4 /system/lib/libc.so
05-26 16:13:45.680: I/DEBUG(65): #01 lr afd191d9 /system/lib/libc.so
05-26 16:13:45.680: I/DEBUG(65): code around pc:
05-26 16:13:45.680: I/DEBUG(65): afd15c84 2c006824 e028d1fb b13368db c064f8df
05-26 16:13:45.680: I/DEBUG(65): afd15c94 44fc2401 4000f8cc 49124798 25002027
05-26 16:13:45.680: I/DEBUG(65): afd15ca4 f7f57008 2106ec7c edd8f7f6 460aa901
05-26 16:13:45.680: I/DEBUG(65): afd15cb4 f04f2006 95015380 95029303 e93ef7f6
05-26 16:13:45.680: I/DEBUG(65): afd15cc4 462aa905 f7f62002 f7f5e94a 2106ec68
05-26 16:13:45.680: I/DEBUG(65): code around lr:
05-26 16:13:45.680: I/DEBUG(65): afd191b8 4a0e4b0d e92d447b 589c41f0 26004680
05-26 16:13:45.680: I/DEBUG(65): afd191c8 686768a5 f9b5e006 b113300c 47c04628
05-26 16:13:45.680: I/DEBUG(65): afd191d8 35544306 37fff117 6824d5f5 d1ef2c00
05-26 16:13:45.680: I/DEBUG(65): afd191e8 e8bd4630 bf0081f0 00028344 ffffff88
05-26 16:13:45.680: I/DEBUG(65): afd191f8 b086b570 f602fb01 9004460c a804a901
05-26 16:13:45.680: I/DEBUG(65): stack:
05-26 16:13:45.680: I/DEBUG(65): beba97b8 afd42664
05-26 16:13:45.680: I/DEBUG(65): beba97bc 00147930
05-26 16:13:45.680: I/DEBUG(65): beba97c0 0000001a
05-26 16:13:45.680: I/DEBUG(65): beba97c4 afd182a1 /system/lib/libc.so
05-26 16:13:45.680: I/DEBUG(65): beba97c8 afd4270c
05-26 16:13:45.680: I/DEBUG(65): beba97cc afd426b8
05-26 16:13:45.680: I/DEBUG(65): beba97d0 00000000
05-26 16:13:45.680: I/DEBUG(65): beba97d4 afd191d9 /system/lib/libc.so
05-26 16:13:45.680: I/DEBUG(65): beba97d8 00000001
05-26 16:13:45.680: I/DEBUG(65): beba97dc beba980c
05-26 16:13:45.680: I/DEBUG(65): beba97e0 001405d4
05-26 16:13:45.680: I/DEBUG(65): beba97e4 00144838
05-26 16:13:45.680: I/DEBUG(65): beba97e8 000eb53c /system/app/example
05-26 16:13:45.680: I/DEBUG(65): beba97ec afd184fb /system/lib/libc.so
05-26 16:13:45.690: I/DEBUG(65): beba97f0 df002777
05-26 16:13:45.690: I/DEBUG(65): beba97f4 e3a070ad
05-26 16:13:45.690: I/DEBUG(65): #00 beba97f8 0000000a
05-26 16:13:45.690: I/DEBUG(65): beba97fc afd1c80f /system/lib/libc.so
05-26 16:13:45.690: I/DEBUG(65): beba9800 0000000a
05-26 16:13:45.690: I/DEBUG(65): beba9804 afd426b8
05-26 16:13:45.690: I/DEBUG(65): beba9808 001405d4
05-26 16:13:45.690: I/DEBUG(65): beba980c fffffbdf
05-26 16:13:45.690: I/DEBUG(65): beba9810 05000000
05-26 16:13:45.690: I/DEBUG(65): beba9814 afd42610
05-26 16:13:45.690: I/DEBUG(65): beba9818 00000001
05-26 16:13:45.690: I/DEBUG(65): beba981c 000eb654 /system/app/example
05-26 16:13:45.690: I/DEBUG(65): beba9820 0013fe40
05-26 16:13:45.690: I/DEBUG(65): beba9824 00000000
05-26 16:13:45.690: I/DEBUG(65): beba9828 0000004e
05-26 16:13:45.690: I/DEBUG(65): beba982c 0013fe40
05-26 16:13:45.690: I/DEBUG(65): beba9830 00000055
05-26 16:13:45.690: I/DEBUG(65): beba9834 0000004e
05-26 16:13:45.690: I/DEBUG(65): beba9838 00000047
05-26 16:13:45.690: I/DEBUG(65): beba983c 000ad0a0 /system/app/example
05-26 16:13:45.710: I/BootReceiver(96): Copying /data/tombstones/tombstone_05 to DropBox (SYSTEM_TOMBSTONE)
我已经通过stackoverflow和互联网搜索过了,但是没有Q/A适合我的问题。我认为这可能是由c++代码中内存管理api中的某种错误引起的,但我很困惑,因为启动adb shell程序根本没有错误。
你知道我应该继续解决这个问题吗?提前感谢
编辑老式的手动调试总是最好的(即使有点太慢了)。对于那些有类似问题的人:
m_source = pcap_open_live(name.c_str(),BUFSIZ,1 ,10,errbuf);
if(!m_source) {
throw(std::invalid_argument("TcpPcapSource::error within pcap_open_live"));
}
在抛出命令时发生崩溃。pcap希望程序以超级用户的权限运行,而我使用了一个糟糕的命令。当我用su/sudo(取决于你的adb版本)让App执行程序时,错误消失了。
如何逐渐从c++代码中删除东西,直到错误消失。这样,您就能够定位导致问题的代码区域。我知道这是一种痛苦的缓慢的方法,但这可能是我在你的情况下不得不做的。
这个错误是分段错误:http://en.wikipedia.org/wiki/SIGSEGV
段错误(通常简称为segfault)、总线错误或访问冲突通常是试图访问CPU无法物理寻址的内存。(即等价于空指针异常)出现分段故障的典型原因如下:
- 试图执行不能正确编译的程序。有些编译器会输出一个可执行文件,尽管存在编译时错误。
- 解除NULL指针的引用
- 试图访问程序无权访问的内存(例如进程上下文中的内核结构)
- 试图访问一个不存在的内存地址(在进程的地址空间之外)
- 试图写只读内存(如代码段)
- 缓冲区溢出
- 使用未初始化指针
所以你应该在你的代码中搜索你可能犯过上面一些错误的地方!
相关文章:
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 为什么我的for循环不能正确获取argv
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 为什么我不能在 FOR LOOP 中使用 i/10,C++?
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- 为什么模板类中的对象不能返回值
- 为什么我不能在一个类的不同行中声明和定义成员变量?
- 为什么我不能在 C++ 中的特定函数重载中调用同一函数的任何其他重载?
- ld:bind_at_load和-bitcode_bundle(Xcode设置ENABLE_bitcode=YES)不能
- 数组长度,为什么从命令行获取时不能使用它?
- Windows/Cygwin - 不能使用 pybind11 - 犯错误
- 为什么我不能使用 EGL 创建无头 OpenGl 上下文?
- 递归模板化函数不能分配给具有常量限定类型"const tt &"的变量"state"
- 为什么我不能将一个对象push_back到属于另一个类的对象向量中?
- 为什么我不能将 rand() 与数组的大小一起使用?
- 为什么虚函数不能是静态的和全局的?
- 为什么我不能在 while 循环中创建线程?
- 为什么这个音频包络不能通过开关的情况?
- Android在执行c++代码时崩溃,不能用adb shell复制