本文介绍了调试标准C库例程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 我在PPC主板上使用MontaVista Linux。 我正在使用的编译器是一个gnu交叉编译器交叉编译器 (ppc-82xx-gcc) 正在运行的应用程序/软件正在弄乱内存 ,因此后续的malloc失败。 当转储应用程序核心时,我没有在 代码中获得任何回溯(尽管应用程序是使用调试符号编译的,使用-g 选项)。我得到的唯一的东西是发生崩溃的函数的地址(而不是名字)。 在我找到的代码中使用print该应用程序在调用 malloc时崩溃。我将标准C库链接为.so,这可能是 为什么没有回溯包含我的应用程序的功能。 还不够板上的内存来运行gdb。另外由于场景的复杂性,并不总是可以运行gdbserver。 有可能的方法: 1。链接一个可调试版本的stdlib,当它被转储时会在核心中放入更多的信息。 2.我可以在stdlib中启用一些断言或额外信息吗? 告诉我memry是否搞砸了。 3.有没有办法将地址映射到.so的功能 加载到内存中。或者即使我知道地址属于ta perticaular .so 提前致谢。 解决方案 你有一个难题。 到(1)和(2) 首先,你不需要c库的完整调试版本,但仅仅是malloc / free的。我想你不要怀疑asin()是你问题的来源。一个这样的调试库是 http://www.hexco.de/rmdebug / 到(3) 如果我做了一个 objdump -T / lib /libc-2.2.4.so 我获得了一个带有地址的入口点列表。如果你知道 加载.so的地址你已经完成了设置。 初始化每个指针。检查每个malloc / calloc / realloc以确保它在您依赖其返回值之前成功获得。检查每个数组 访问是否在边界内(0到n - 1,对于n个元素的数组)。设置 不确定(''悬挂'')指针指向NULL。 按照这些简单的步骤将摆脱所有已知的99.90072% 与记忆相关的崩溃。 - Richard Heathfield Usenet是一个奇怪的地方 - dmr 29/7/1999 http://www.cpax.org.uk 电子邮件:rjh在上面的域名(但显然放弃了www) 初始化每个指针。 我不会建议初始化_every_指针。 #define POVER(arr) ((arr)+ sizeof(arr)/ sizeof *(arr)) int * p; for(p = array1; POVER(array1)!= p; ++ p)/ * Something * /; for(p = array2; POVER(array2)!= p; ++ p)/ *东西* /; 如果malloc''不到一千字节,我就不会打扰了。 当回顾一个'代码时,应该_always_注意这些事情。 在调试模式下,也许吧。它在发布模式下浪费了宝贵的纳秒(如果不是微秒) 。也许以下类似的事情是妥协: #ifdef NDEBUG #define DMODE(声明) #else #define DMODE(声明)声明 #endif int main() { int * p; ... free(p); DMODE(p = 0); } - Frederick Gotham I am working on MontaVista Linux on a PPC board.The compiler I am using is a gnu cross compiler cross compiler(ppc-82xx-gcc)The application/software that is being run, is messing up the memorydue to which a subsequent malloc fails.When the application core is dumped I do not get any backtrace in thecode (although the application is compiled with debug symbols, with -goption). The only thing I get is the address of the function (and notthe name) where the crash is happening.Using prints in the code I found that application crashes while callingmalloc. I am linking the standard C library as .so, and thats probablywhy there is not backtrace conatining the functions of my application.There is not enough memory on the board to run gdb. Also due to thecomplexity of the scenarios it is not always possible to run gdbserver.It there a possible way to:1. Link a debuggable version of stdlib which would put more informationin the core, when it is dumped.2. Can I enable some asserts or extra information in stdlib which wouldtell me if memry is being messed up.3. Is there a way by which I can map an address to a function of .soloaded in the memory. Or even if i know that the address belongs t aperticaular .soThanks in advance. 解决方案You have a hard problem there.To (1) and (2)First thing, you do not need a full debug version of the c library butjust of malloc/free. I suppose you do not suspect asin() as beeing thesource of your problems. One such a debug library is http://www.hexco.de/rmdebug/To (3)If I do anobjdump -T /lib/libc-2.2.4.soI obtain a list of entry points with their addresses. If you get to knowat which address the .so is loaded you are all set.Initialise every pointer. Check every malloc/calloc/realloc to ensure itsucceeded before you rely on its return value. Check that every arrayaccess is within bounds (0 to n - 1, for an array of n elements). Setindeterminate (''dangling'') pointers to NULL.Following these simple steps will get rid of 99.90072% of all knownmemory-related crashes.--Richard Heathfield"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.ukemail: rjh at above domain (but drop the www, obviously)Initialise every pointer.I wouldn''t go so far as to advise to initialise _every_ pointer.#define POVER(arr) ((arr) + sizeof(arr)/sizeof*(arr))int *p;for(p=array1;POVER(array1)!=p;++p) /* Something */ ;for(p=array2;POVER(array2)!=p;++p) /* Something */ ;If malloc''ing less than a kilobyte, I wouldn''t bother.One should _always_ watch out for such things when looking back over one''scode.In Debug Mode, maybe. It wastes valuable nanoseconds (if not microseconds)in Release Mode. Maybe something like the following would be a compromise:#ifdef NDEBUG#define DMODE(statement)#else#define DMODE(statement) statement#endifint main(){int *p;...free(p); DMODE(p=0);}--Frederick Gotham 这篇关于调试标准C库例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-06 08:39