我的Android应用程序(Java+NDK)报告了由0xDeDADDD引起的一些崩溃(信号)。众所周知,这是Dalvik VM中止的速记。这些都不会发生在我的jni调用中,但是信号处理发生在本地。但是,本机崩溃报告通常报告的内容(寄存器、堆栈)对于调试这些内容毫无用处。
有没有办法从本地信号处理程序到达Java调用堆栈?或者丢弃最近logcat活动的一部分?
最佳答案
解决方案:在信号处理程序中为dead00d引入一个特殊条件。读取logcat的最后1024字节,将其塞入崩溃日志。
我正在用这种方法做一些像样的诊断。
//n is the length of the file tail to read
//Returns # of byte read
size_t ReadLogcat(char *Buf, size_t n)
{
char s[sizeof(s_DataPath) + 30];
//s_DataPath contains the result of Context.getDir("Data")
strcpy(s, "logcat -d -f ");
char *fn = s + strlen(s);
strcat(s, s_DataPath);
strcat(s, "/logcat"); //Temp file for the logcat
size_t r = 0;
system(s); //Dump the snapshot of the logcat into the file called logcat
FILE *f = fopen(fn, "r");
if(f)
{
fseek(f, -n, SEEK_END); //We need the end of the file
r = fread(Buf, 1, n, f);
fclose(f);
}
unlink(fn); //Don't need the logcat file anymore
return r;
}
static void DumpLogcat(FILE *f)
{
char Buf[1024];
size_t r;
if(r = ReadLogcat(Buf, sizeof(Buf)))
{
fputs("\nLogcat:\n", f);
fwrite(Buf, 1, r, f);
}
}
void OnSignal(int signal, siginfo_t *si, void *p)
{
FILE *f = OpenCrashLog(); //opens a file in the data dir; details are irrelevant
//Lots of data dumping here... Version, stack, registers, etc.
//...
if((unsigned)si->si_addr == 0xdeadd00d) //Try and dump some Logcat
DumpLogcat(f);
}
关于android - 如何从客户设备中找到相关的Deadd00d情况?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18766852/