程序死在段错误上面,如何看gdb调试的错误代码地址?

武陵老祖 2017-08-21 02:14:36
利用gdb打印信息如下:
Program received signal SIGSEGV, Segmentation fault.
[Switching to LWP 287]
0xb741a938 in ?? ()
(gdb) bt
#0 0xb741a938 in ?? ()
#1 0x002f6e28 in COMM_IVE_BlobToRect ()
#2 0x002f1ee4 in XM_IA_Work ()
#3 0x002edac8 in IMPALGOProc_Task ()
#4 0xb6fcf6d8 in ?? () from /lib/libpthread.so.0
#5 0xb6fcf6d8 in ?? () from /lib/libpthread.so.0
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)
[END] 2017/8/19 12:59:46

但从打印上面看 是死在COMM_IVE_BlobToRect ()里面,想问函数前的地址怎么看

...全文
2006 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ForestDB 2017-08-22
  • 打赏
  • 举报
回复
如果生成对象文件时有带-g参数,那么有个addr2line的工具可以查出来0x002f6e28这样的地址对应于源码的行数。
赵4老师 2017-08-22
  • 打赏
  • 举报
回复
判断是否越界访问,可以在数组的最后一个元素之后对应的地址处设置数据读写断点。如果该地址对应其它变量干扰判断,可将数组多声明一个元素,并设置数据读写断点在该多出元素对应的地址上。
#include <time.h>
#include <stdlib.h>
#include <windows.h>
int main() {
    int a,b[11];//本来是b[10],为判断哪句越界,故意声明为b[11]

    srand((unsigned int)time(NULL));//按两次F11,等黄色右箭头指向本行时,调试、新建断点、新建数据断点,地址:&b[10],字节计数:4,确定。
    while (1) {//按F5,会停在下面某句,此时a的值为10,b[10]已经被修改为对应0..4之一。
        b[(a=rand()%11)]=0;
        Sleep(100);
        b[(a=rand()%11)]=1;
        Sleep(100);
        b[(a=rand()%11)]=2;
        Sleep(100);
        b[(a=rand()%11)]=3;
        Sleep(100);
        b[(a=rand()%11)]=4;
        Sleep(100);
    }
    return 0;
}
武陵老祖 2017-08-22
  • 打赏
  • 举报
回复
引用 6 楼 zhao4zhong1 的回复:
排查越界访问可以使用watch命令。 2. 设置观察点(WatchPoint) 观察点一般用来观察某个表达式(变量也是一种表达式)的值是否变化了。如果有变化,马上停住程序。有下面的几种方法来设置观察点: watch <expr> 为表达式(变量)expr设置一个观察点。一旦表达式值有变化时,马上停住程序。 rwatch <expr> 当表达式(变量)expr被读时,停住程序。 awatch <expr> 当表达式(变量)的值被读或被写时,停住程序。 info watchpoints 列出当前设置的所有观察点。
主要是我只知道gdb定位到这个函数内,无法定位到具体哪一行
武陵老祖 2017-08-22
  • 打赏
  • 举报
回复
引用 5 楼 cfjtaishan 的回复:
[quote=引用 4 楼 jgh211 的回复:] 代码在楼上 很简单
代码很简单? 从代码上看,很可能时越界访问了。建议楼主排查边界。 [/quote]主要是这是个循环,可能这个函数循环了N次之后才会段错误。越界的话,我加了越界打印,但是并没有打印过越界的信息;
赵4老师 2017-08-22
  • 打赏
  • 举报
回复
排查越界访问可以使用watch命令。 2. 设置观察点(WatchPoint) 观察点一般用来观察某个表达式(变量也是一种表达式)的值是否变化了。如果有变化,马上停住程序。有下面的几种方法来设置观察点: watch <expr> 为表达式(变量)expr设置一个观察点。一旦表达式值有变化时,马上停住程序。 rwatch <expr> 当表达式(变量)expr被读时,停住程序。 awatch <expr> 当表达式(变量)的值被读或被写时,停住程序。 info watchpoints 列出当前设置的所有观察点。
自信男孩 2017-08-22
  • 打赏
  • 举报
回复
引用 4 楼 jgh211 的回复:
代码在楼上 很简单
代码很简单? 从代码上看,很可能时越界访问了。建议楼主排查边界。
武陵老祖 2017-08-22
  • 打赏
  • 举报
回复
代码在楼上 很简单
武陵老祖 2017-08-22
  • 打赏
  • 举报
回复
HI_S32 iIndex = 0; HI_U16 u16Num; HI_U16 i, j, k; HI_U16 u16Thr = 0; HI_BOOL bValid; if (pstBlob->u8RegionNum > u16RectMaxNum) { u16Thr = pstBlob->u16CurAreaThr; do { u16Num = 0; u16Thr += u16AreaThrStep; for (i = 0; i < 254; i++) { if (pstBlob->astRegion[i].u32Area > u16Thr) { u16Num++; } } } while (u16Num > u16RectMaxNum); } u16Num = 0; for (i = 0; i < 254; i++) { if (pstBlob->astRegion[i].u32Area > u16Thr) { HI_S32 usWid, usHgt; usWid = (HI_S32)(pstBlob->astRegion[i].u16Right - pstBlob->astRegion[i].u16Left); usHgt = (HI_S32)(pstBlob->astRegion[i].u16Bottom - pstBlob->astRegion[i].u16Top); //NreCode-7.11 #if 0 if (presetPos == 1 && pstBlob->astRegion[i].u16Bottom * 3 < imageHgt) { usWid += 3; usHgt += 6; } #endif //width height 最小尺寸 //if ((usWid * 30 < imageWid) || (usHgt * 30 < imageHgt)) if ((usWid * 90 < imageWid) || (usHgt * 30 < imageHgt)) { continue; } #if 0 if (presetPos == 1 && pstBlob->astRegion[i].u16Bottom * 3 < imageHgt) { usWid -= 3; usHgt -= 6; } #endif if ((usWid + 88) > imageWid || (usHgt + 10) > imageHgt) { continue; } //NreCode_6.15 if (usWid * usHgt * 3 > imageWid * imageHgt) { continue; } //比例异常 if (usWid > usHgt * 5 || usHgt > usWid * 10) { continue; } //占空比异常 if (pstBlob->astRegion[i].u32Area < usWid * usHgt * 0.15) { continue; } pstRect->astRect[u16Num].u32Area = (HI_S32)(pstBlob->astRegion[i].u32Area); /********************************0-左上 1-右上 2-右下 3-左下*****************************/ pstRect->astRect[u16Num].astPoint[0].s32X = (HI_S32)(pstBlob->astRegion[i].u16Left) & (~1); pstRect->astRect[u16Num].astPoint[0].s32Y = (HI_S32)(pstBlob->astRegion[i].u16Top) & (~1); pstRect->astRect[u16Num].astPoint[1].s32X = (HI_S32)(pstBlob->astRegion[i].u16Right) & (~1); pstRect->astRect[u16Num].astPoint[1].s32Y = (HI_S32)(pstBlob->astRegion[i].u16Top) & (~1); pstRect->astRect[u16Num].astPoint[2].s32X = (HI_S32)(pstBlob->astRegion[i].u16Right) & (~1); pstRect->astRect[u16Num].astPoint[2].s32Y = (HI_S32)(pstBlob->astRegion[i].u16Bottom) & (~1); pstRect->astRect[u16Num].astPoint[3].s32X = (HI_S32)(pstBlob->astRegion[i].u16Left) & (~1); pstRect->astRect[u16Num].astPoint[3].s32Y = (HI_S32)(pstBlob->astRegion[i].u16Bottom) & (~1); bValid = HI_TRUE; for (j = 0; j < 3; j++) { for (k = j + 1; k < 4; k++) { if ((pstRect->astRect[u16Num].astPoint[j].s32X == pstRect->astRect[u16Num].astPoint[k].s32X) && (pstRect->astRect[u16Num].astPoint[j].s32Y == pstRect->astRect[u16Num].astPoint[k].s32Y)) { bValid = HI_FALSE; break; } } } if (HI_TRUE == bValid) { u16Num++; } } } /********************************CCL区域后期处理***************************/ for (j = 0; j < u16Num - 1; j++) { if (0 != pstRect->astRect[j].u32Area) { for (k = j + 1; k < u16Num; k++) { if (0 == pstRect->astRect[k].u32Area) { continue; } int iWidj = (int)pstRect->astRect[j].astPoint[1].s32X - (int)pstRect->astRect[j].astPoint[0].s32X; int iHgtj = (int)pstRect->astRect[j].astPoint[2].s32Y - (int)pstRect->astRect[j].astPoint[0].s32Y; int iWidk = (int)pstRect->astRect[k].astPoint[1].s32X - (int)pstRect->astRect[k].astPoint[0].s32X; int iHgtk = (int)pstRect->astRect[k].astPoint[2].s32Y - (int)pstRect->astRect[k].astPoint[0].s32Y; //中心点坐标的两倍,和j、k宽高的两倍做比较,就不除以2了 int icenterjx = (int)pstRect->astRect[j].astPoint[1].s32X + (int)pstRect->astRect[j].astPoint[0].s32X; int icenterjy = (int)pstRect->astRect[j].astPoint[2].s32Y + (int)pstRect->astRect[j].astPoint[0].s32Y; int icenterkx = (int)pstRect->astRect[k].astPoint[1].s32X + (int)pstRect->astRect[k].astPoint[0].s32X; int icenterky = (int)pstRect->astRect[k].astPoint[2].s32Y + (int)pstRect->astRect[k].astPoint[0].s32Y; if (((abs(icenterjx - icenterkx)) <= (iWidj + iWidk)) && (abs(icenterjy - icenterky) <= (iHgtj + iHgtk))) { pstRect->astRect[j].u32Area = pstRect->astRect[j].u32Area + pstRect->astRect[k].u32Area; pstRect->astRect[j].astPoint[0].s32X = MIN(pstRect->astRect[k].astPoint[0].s32X, pstRect->astRect[j].astPoint[0].s32X); pstRect->astRect[j].astPoint[0].s32Y = MIN(pstRect->astRect[k].astPoint[0].s32Y, pstRect->astRect[j].astPoint[0].s32Y); pstRect->astRect[j].astPoint[1].s32X = MAX(pstRect->astRect[k].astPoint[1].s32X, pstRect->astRect[j].astPoint[1].s32X); pstRect->astRect[j].astPoint[1].s32Y = MIN(pstRect->astRect[k].astPoint[1].s32Y, pstRect->astRect[j].astPoint[1].s32Y); pstRect->astRect[j].astPoint[2].s32X = MAX(pstRect->astRect[k].astPoint[2].s32X, pstRect->astRect[j].astPoint[2].s32X); pstRect->astRect[j].astPoint[2].s32Y = MAX(pstRect->astRect[k].astPoint[2].s32Y, pstRect->astRect[j].astPoint[2].s32Y); pstRect->astRect[j].astPoint[3].s32X = MIN(pstRect->astRect[k].astPoint[3].s32X, pstRect->astRect[j].astPoint[3].s32X); pstRect->astRect[j].astPoint[3].s32Y = MAX(pstRect->astRect[k].astPoint[3].s32Y, pstRect->astRect[j].astPoint[3].s32Y); pstRect->astRect[k].u32Area = 0; } } } } /****************过滤融合和后的目标框*******************/ for (j = 0; j < u16Num - 1; j++) { int iWid = pstRect->astRect[j].astPoint[1].s32X - pstRect->astRect[j].astPoint[0].s32X; int iHgt = pstRect->astRect[j].astPoint[2].s32Y - pstRect->astRect[j].astPoint[0].s32Y; if (iWid * 2 > imageWid) { pstRect->astRect[j].u32Area = 0; } if (iWid * iHgt * 3 > imageWid * imageHgt) { pstRect->astRect[j].u32Area = 0; } if (iWid > iHgt * 5 || iHgt > iWid * 10) { pstRect->astRect[j].u32Area = 0; } } for (j = 0; j < u16Num; j++) { if (pstRect->astRect[j].u32Area > 0) { if (iIndex != j) { memcpy(pstRect->astRect + iIndex, pstRect->astRect + j, sizeof(IVE_CCLRECT_S)); } iIndex++; } } if (iIndex < MAX_OBJ_NUM) { memset(pstRect->astRect + iIndex, 0, sizeof(IVE_CCLRECT_S)*(MAX_OBJ_NUM - iIndex)); } pstRect->u16Num = iIndex;
赵4老师 2017-08-21
  • 打赏
  • 举报
回复
进程意外退出会在当前目录下产生‘core’文件或形如‘core.数字’的文件比如‘core.1234’ 使用命令 gdb 运行程序名 core或core.数字 进入gdb然后使用bt命令 可以查看进程意外退出前函数调用的堆栈,内容为从上到下列出对应从里层到外层的函数调用历史。 如果进程意外退出不产生core文件,参考“ulimit -c core文件最大块大小”命令
自信男孩 2017-08-21
  • 打赏
  • 举报
回复
建议把代码贴出来,段错误应该是非法地址访问了。

69,371

社区成员

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

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