GDB watch if var !=value

本文分享了一个复杂的内存越界Bug的解决过程,该Bug具有一定随机性,通过定位产生Bug时的seed并利用gdb的watchif功能进行跟踪,最终找到了问题所在的具体代码行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有一个内存越界的bug找了2天才找到,最后还是通过借助gdb的帮助,利用watch if 来跟踪某个值什么时候不等于期望值,从而跟踪到越界指令。

reproduce a bug 是找到bug的的第一步,然后再通过一些跟踪调试工具来找到原因。


这个bug算是我目前为止遇到最复杂的了,因为有一定的随机性,所以一开始要找到产生bug时的seed,然后再reproduce the bug ,如果不利用gdb,很难locate到具体到那一行代码出的问题。

:/mnt/hgfs/UbuntuShared/3.4rockx_face_camera_vi$ arm-linux-gnueabihf-gdb ./rockx_face_camera_vi GNU gdb (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36)) 8.2.1.20190227-git Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=x86_64-pc-linux-gnu --target=arm-linux-gnueabihf". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://bugs.linaro.org/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./rockx_face_camera_vi...done. (gdb) target remote 192.168.100.75:1234 Remote debugging using 192.168.100.75:1234 Reading symbols from /opt/rv1126_rv1109_linux_sdk_v1.8.0_20210224/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib/ld-linux-armhf.so.3...done. 0xa6ed0a00 in _start () from /opt/rv1126_rv1109_linux_sdk_v1.8.0_20210224/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib/ld-linux-armhf.so.3 (gdb) break main Breakpoint 1 at 0x11ddc: file rockx_face_camera_vi.cpp, line 76. (gdb) continue Continuing. warning: Could not load shared library symbols for 47 libraries, e.g. /oem/usr/lib/libeasymedia.so.1. Use the "info sharedlibrary" command to see the complete listing. Do you need "set solib-search-path" or "set sysroot"? warning: Could not load shared library symbols for /usr/lib/libv4l/plugins/libv4l-mplane.so. Do you need "set solib-search-path" or "set sysroot"? [New Thread 1096.1913] Thread 1 "rockx_face_came" hit Breakpoint 1, main (argc=1, argv=0xaeb0ed24) at rockx_face_camera_vi.cpp:76 76 memset(&vi_chn_attr, 0, sizeof(VI_CHN_ATTR_S)); (gdb) next 77 vi_chn_attr.pcVideoNode = CAMERA_PATH; // Path (gdb) 78 vi_chn_attr.u32Width = 1920; // Width (gdb) next 79 vi_chn_attr.u32Height = 1080; // Height (gdb) next 80 vi_chn_attr.enPixFmt = IMAGE_TYPE_NV12; // ImageType (gdb) next 81 vi_chn_attr.enBufType = VI_CHN_BUF_TYPE_MMAP; // BufType (gdb) next 82 vi_chn_attr.u32BufCnt = 3; // Cnt (gdb) next 83 vi_chn_attr.enWorkMode = VI_WORK_MODE_NORMAL; // Mode (gdb) next 84 ret = RK_MPI_VI_SetChnAttr(CAMERA_ID, CAMERA_CHN, &vi_chn_attr); (gdb) next 85 if (ret) (gdb) next 87 printf("Vi Set Attr Failed.....\n"); (gdb) next 88 return 0; (gdb) next 92 printf("Vi Set Attr Success.....\n"); (gdb) next 95 ret = RK_MPI_VI_EnableChn(CAMERA_ID, CAMERA_CHN); (gdb) next [New Thread 1096.2089] [New Thread 1096.2090] 96 if (ret) (gdb) next 99 return 0; (gdb) next 103 printf("Vi Enable Attr Success.....\n"); (gdb) next 107 memset(&venc_chn_attr, 0, sizeof(VENC_CHN_ATTR_S)); (gdb) next 110 venc_chn_attr.stVencAttr.u32VirWidth = 1920; (gdb) next 111 venc_chn_attr.stVencAttr.u32VirHeight = 1080; (gdb) next 112 venc_chn_attr.stVencAttr.imageType = IMAGE_TYPE_NV12; (gdb) next 113 venc_chn_attr.stVencAttr.enType = RK_CODEC_TYPE_H264; (gdb) next [New Thread 1096.2167] 114 venc_chn_attr.stVencAttr.u32Profile = 66; (gdb) next 115 venc_chn_attr.stRcAttr.enRcMode = VENC_RC_MODE_H264CBR; (gdb) next 121 venc_chn_attr.stRcAttr.stH264Cbr.u32SrcFrameRateNum = 25; (gdb) next 122 ret = RK_MPI_VENC_CreateChn(VENC_CHN, &venc_chn_attr); (gdb) next 123 if (ret) (gdb) next 125 printf("ERROR: Create venc failed!\n"); (gdb) next 126 exit(0); (gdb) next 129 ret = RK_MPI_VI_StartStream(CAMERA_ID, CAMERA_CHN); (gdb) next 130 if (ret) (gdb) next 148 cerr<<"pthread create successed...."<<endl; (gdb) next 151 rockx_config_t *face_detect_config = rockx_create_config(); (gdb) next 152 ret=rockx_add_config(face_detect_config, ROCKX_CONFIG_DATA_PATH, "/userdata/rockx_data"); (gdb) next warning: Could not load shared library symbols for 6 libraries, e.g. /usr/lib32/librknn_runtime.so. Use the "info sharedlibrary" command to see the complete listing. Do you need "set solib-search-path" or "set sysroot"? [New Thread 1096.2250] 153 if (ret != ROCKX_RET_SUCCESS) (gdb) next 155 printf("Failed to add config: error code = %d\n", ret); (gdb) next 160 printf("Invalid parameter: check key or value\n"); (gdb) next 161 break; (gdb) next 163 printf("Memory allocation failed\n"); (gdb) next 164 break; (gdb) next 166 printf("类型不匹配 ...\n"); (gdb) next 175 printf("rockx_add_config successfully\n"); (gdb) next 178 rockx_handle_t face_detect_handle=NULL; (gdb) next 181 printf("第一处断点\n"); (gdb) next 183 rockx_module_t face_detect_module = ROCKX_MODULE_FACE_DETECTION_V2; (gdb) next 187 rockx_release_config(face_detect_config); // 释放配置 (gdb) next 188 printf("第三处断点\n"); (gdb) next 189 if (face_detect_ret != ROCKX_RET_SUCCESS) (gdb) next 191 printf("rockx_create face_detect failed...\n"); (gdb) next 192 return -1; (gdb) next 200 rv1126_rockx_image.width = WIDTH; (gdb) next 201 rv1126_rockx_image.height = HEIGHT; (gdb) next 202 rv1126_rockx_image.pixel_format = ROCKX_PIXEL_FORMAT_YUV420SP_NV12; (gdb) next 203 printf("Image params: width=%d, height=%d, format=%d\n", (gdb) next 206 rv1126_rockx_image.pixel_format); (gdb) next 203 printf("Image params: width=%d, height=%d, format=%d\n", (gdb) next 217 mb = RK_MPI_SYS_GetMediaBuffer(RK_ID_VI, CAMERA_CHN, -1); (gdb) next 218 if (!mb) (gdb) next 220 printf("Get Vi Stream break....\n"); (gdb) next 297 RK_MPI_VENC_DestroyChn(VENC_CHN); (gdb) next 298 RK_MPI_VI_DisableChn(CAMERA_ID, CAMERA_CHN); (gdb) next cv::String::String (this=0xaeb0ebe8, s=0x11cc3f "") at ./arm_opencv_source/include/opencv2/core/cvstd.hpp:599 599 if (!s) return; (gdb) next 601 if (!len) return; (gdb) next 603 } (gdb) next cv::String::~String (this=0xa2170b1c <__GI__IO_file_jumps>, __in_chrg=<optimized out>) at ./arm_opencv_source/include/opencv2/core/cvstd.hpp:646 646 String::~String() (gdb) next cv::String::~String (this=0x0, __in_chrg=<optimized out>) at ./arm_opencv_source/include/opencv2/core/cvstd.hpp:648 648 deallocate(); (gdb) next 649 } (gdb) next cv::String::operator= (this=0xa2170b1c <__GI__IO_file_jumps>, str=...) at ./arm_opencv_source/include/opencv2/core/cvstd.hpp:653 653 { (gdb)
最新发布
06-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值