关于指针的问题

T-Quake 2011-08-01 02:05:10
大家好,我最近在调试android的时候,在运行经过大概50小时的时间后,系统crash掉,提示是system_server挂了。
我反汇编了出错信息,定位到
这个个文件中AsynchronousSocketCloseMonitor.cpp
文件的具体代码可以访问http://code.google.com/p/in-the-box/source/browse/trunk/InTheBoxSim/libcore/luni/src/main/native/AsynchronousSocketCloseMonitor.cpp?r=38
的一句话

void AsynchronousSocketCloseMonitor::signalBlockedThreads(int fd) {
ScopedPthreadMutexLock lock(&blockedThreadListMutex);
for (AsynchronousSocketCloseMonitor* it = blockedThreadList; it != NULL; it = it->mNext) {
if (it->mFd == fd) { //这个地方有问题
pthread_kill(it->mThread, BLOCKED_THREAD_SIGNAL);
// Keep going, because there may be more than one thread...
}
}
}

汇编的代码到15ebc: 68e3 ldr r3, [r4, #12]
这个通过解释 是将r4的地址+12字节 放入到r3中,通过分析知道r4是结构体初始地址 +12过后是试图访问mFD成员变量,也就是, 函数在it->mFd的时候挂掉了,我不知道为什么。根据对代码的分析,看不出有逻辑不对的地方。而且如果是空指针的话,前面for循环也已经做了限制了。这个就很奇怪了。
...全文
143 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2011-08-04
  • 打赏
  • 举报
回复
数组越界如果调试器支持的话,可以在数组最后一个元素或最后一个元素的后面对应内存地址处设置内存改变断点。

Setting a Breakpoint When the Value at a Specified Memory Address Changes
To break when the value at a specified memory address changes

From the Edit menu, click Breakpoints.


Click the Data tab of the Breakpoints dialog box.


In the Expression text box, type the memory address for the byte.
For a word or doubleword memory address, enclose the address in parentheses, and precede it with a cast operator. For example, WO(21406036) for the word at memory location 21406036. Use the cast operator BY for a byte (optional), WO for a word, or DW for a doubleword. (The debugger interprets all integer constants as decimal unless they begin with zero (0) for octal or zero and x (0x) for hexadecimal.)

In the Number Of Elements text box, type the number of bytes, words, or doublewords to monitor. If you used the BY operator in the Expression field, specify the number of bytes. If you used WO, specify the number of words. If you used DW, specify the number of doublewords.


Click OK to set the breakpoint.

----------------------------------------------------------

Setting a Breakpoint When a Variable Changes Value
To set a breakpoint when a variable changes value

From the Edit menu, click Breakpoints.


Click the Data tab of the Breakpoints dialog box.


In the Expression text box, type the name of the variable.


Click OK to set the breakpoint.
T-Quake 2011-08-03
  • 打赏
  • 举报
回复
这个函数是个android标准的libcore的代码。走到这就挂了,我在怀疑是不是 因为在上次的某些其他的操作有数组越界。或者是因为别的进程有内存泄漏。。正在反复的试验。数组越界很难查看到,目前在跟 内存泄漏。
Dirk 2011-08-01
  • 打赏
  • 举报
回复
通常来说,这个是链表到问题。不是t为null,而是访问了不该访问到地方。你看看自己到数据结构,好好分析一下。
shijiemoxing 2011-08-01
  • 打赏
  • 举报
回复
学习下
赵4老师 2011-08-01
  • 打赏
  • 举报
回复
监视系统中所有socket对象、锁对象、各块已分配内存大小的变化。

检查是否内存泄漏的办法之一:
任务管理器 进程 查看 选择列 内存使用
任务管理器 进程 查看 选择列 虚拟内存大小
让你的程序(进程)不退出,循环执行主流程很多遍,越多越好,比如1000000次甚至无限循环,记录以上两个数值,再隔至少一小时,越长越好,比如一个月,再记录以上两个数值。如果以上两组数值的差较大或随时间流逝不断增加,则铁定有内存泄漏!
G_8519 2011-08-01
  • 打赏
  • 举报
回复
最后一个节点的 it->mNext 确定是 NULL ?
至善者善之敌 2011-08-01
  • 打赏
  • 举报
回复
AsynchronousSocketCloseMonitor是用的链表存储?
hua_yang 2011-08-01
  • 打赏
  • 举报
回复
mark

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧