前几天,在跑程序的时候遇到一个zbuf的异常,vxworks打印的调用链如下:
data storage
Exception current instruction address: 0x0050cb60
Machine Status Register: 0x00029230
Data Exception Address Register: 0x0069bf38
Condition Register: 0x44000082
Exception Syndrome Register: 0x00000000
Task: 0xe597970 "CES_BAPCCE"
**************************************************************
* *
* 3G-Plat PPC Exception Process Result *
* *
**************************************************************
Data Access Exception
Exception current instruction address: 0x0050cb60
Data Access Register: 0x0069bf38
Machine Status Register(tEsf.regSet.msr): 0x00029230
Condition Register(tEsf.regSet.cr): 0x44000082
VecNumber = 0x300
-------------------Infomation of Board start-----------------
_NET_ELEMENT=0x00080000 _PHY_BOARD=0x000000a7
_LOGIC_BOARD=0x000000a9
-------------------Infomation of Board End-------------------
-----------------Infomation of Task Start---------------------
Task Name : CES_BAPCCE
Task id : 0xe597970
Task options : 0x4
Task status : 0x0
Task Current priority : 0x32
Task Normal priority : 0x32
-----------------Infomation of Task End-----------------------
----------------Current Exception Context Start---------------
pc(tExcRegSet.pc) = 0x50cb60 _mbufLength
StackFrame(tExcRegSet.gpr[1]) = 0xe597658
lr(tExcRegSet.lr) = 0x5009ac zbufLength
----------------Current Exception Context End-----------------
Handle Common Function
Function calling list is as the following...
ret is in the lr register
0x0050cb60 _mbufLength
0x005009ac zbufLength
0x00280b84 _ZN6CCECTR18CSLPacketAndHeader5BuildEv
0x00276f5c _ZN6CCECTR17CSectorController23PrepareAccessParametersEv
0x002757d4 _ZN6CCECTR17CSectorController29PrepareAndTransmitSyncCapsuleEv
0x002740cc _ZNK6CCECTR25ProcessCCBuildCallBac
从调用链的结果分析是跑到_mbufLength里跑飞了,一开始我们认为有可能是传进去的mbufId是NULL导致的,但后来研究了mbufLib中的源代码,发现所有的函数都对入参做了保护,所以不太可能是这个导致。这个问题以前也遇到过,但出现频率极低,属于很烦躁的随机内存异常,到现在我也没再玩出来过~然后看了一下_mbufLength的实现,实现相当简单,就是求一个mbuf链的总长度,实现没发现有什么地方可能导致异常,所以很困惑~~所以想请问一下vxworks的开发高手们,像这种问题一般是什么情况引起的?特别是_mbufLength跑飞可能是什么情况下出现?
附上_mbufLength的实现:
int _mbufLength
(
MBUF_ID mbufId /* mbufId to find length of */
)
{
MBUF_SEG mbuf;
int length = 0; /* total length */
if (mbufId == NULL ||
mbufId->type != MBUF_VALID) /* invalid ID ? */
{
errno = S_mbufLib_ID_INVALID;
return (ERROR);
}
for (mbuf = mbufId->mbufHead; mbuf != NULL; mbuf = mbuf->m_next)
length += mbuf->m_len;
return (length); /* return total length */
}