调试损坏的memoy

编程入门 行业动态 更新时间:2024-10-08 18:32:56
本文介绍了调试损坏的memoy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好, 我调用了一个指向用户定义结构的指针。指针的值是 类似0x0000002aaaaa(实际上不记得,我没有运行代码的 计算机)。然后我在 分配的结构上执行一些东西,这些结构必须是错误的,因为在执行之后,指针的值就像0xffffff2aaaaa,即相同的lsb,不同的 msb。我不知道从哪里开始调试这个。显然,当我运行 程序时,我在引用指针时得到一个SIGSEGV,而valgrind显示没有 无效内存访问的指示。你对如何启动 调试这个有任何线索吗?下面是我的代码的模板。 static int do_stuff() { obj_t res = * calloc((size_t)1,sizeof (obj_t)); // res是0x000000 .. obj_iterate(res); // res是0xffffff .. do_other_stuff(res-> fied); < - SIGSEGV } Julien PS:我的架构是X86_64,Linux,gcc- 4;代码编译没有 优化,调试符号激活

解决方案

Julien Lafaye写道:

你好, i调用了一个指向用户定义结构的指针。指针的值是 类似0x0000002aaaaa(实际上不记得,我没有运行代码的 计算机)。然后我在 分配的结构上执行一些东西,这些结构必须是错误的,因为在执行之后,指针的值就像0xffffff2aaaaa,即相同的lsb,不同的 msb。我不知道从哪里开始调试这个。显然,当我运行 程序时,我在引用指针时得到一个SIGSEGV,而valgrind显示没有 无效内存访问的指示。你对如何启动 调试这个有任何线索吗?下面是我的代码的模板。 static int do_stuff() { obj_t res = * calloc((size_t )1,sizeof(obj_t)); // res是0x000000 .. obj_iterate(res); // res是0xffffff .. do_other_stuff(res-> fied); < - SIGSEGV } Julien PS:我的架构是X86_64,Linux,gcc- 4;代码编译没有 优化,调试符号激活

Julien ... 为什么calloc前面的星号? - Morris Dovey DeSoto Solar DeSoto ,爱荷华州美国 www.iedu/DeSoto/

Julien Lafaye写道:

您好, i调用了一个指向用户定义结构的指针。指针的值是 类似0x0000002aaaaa(实际上不记得,我没有运行代码的 计算机)。然后我在 分配的结构上执行一些东西,这些结构必须是错误的,因为在执行之后,指针的值就像0xffffff2aaaaa,即相同的lsb,不同的 msb。我不知道从哪里开始调试这个。显然,当我运行 程序时,我在引用指针时得到一个SIGSEGV,而valgrind显示没有 无效内存访问的指示。你对如何启动 调试这个有任何线索吗?下面是我的代码的模板。 static int do_stuff() { obj_t res = * calloc((size_t )1,sizeof(obj_t)); // res是0x000000 .. obj_iterate(res); // res是0xffffff .. do_other_stuff(res-> fied); < - SIGSEGV }

Julien,如果这不是最不实用的问题描述 我曾经见过,它必须紧随其后。值是 like,代码类似于模板。没有编译的希望, 更少运行,你自己认为的部分必须是错误的 是完全隐藏的...... 你说我不知道从哪里开始调试,所有 我根据你所呈现的内容提供的是Line forty-two。

PS:my架构是X86_64,Linux,gcc-4;编译代码没有 优化,调试符号激活

这很好。你的头发和眼睛颜色是什么? 这里有人愿意并且可能能够帮助你b $ b b b b b b b b b b b b b 。让我们看看一些 *实际*数据(不是类似的东西)和*实际*代码(不是 a" template),也许我们可以做点什么。但是在那之前...... 医生,它很疼! 伤到什么? 别介意细节,只是让它变得更好! - Eric Sosman es*****@ieee-dot-org.inva 盖

Julien Lafaye< se *********** @ pinglouwrote:

i调用了一个指向用户的指针 - 定义的结构。指针的值是 类似0x0000002aaaaa(实际上不记得,我没有运行代码的 计算机)。然后我在 分配的结构上执行一些东西,这些结构必须是错误的,因为在执行之后,指针的值就像0xffffff2aaaaa,即相同的lsb,不同的 msb。我不知道从哪里开始调试这个。显然,当我运行 程序时,我在引用指针时得到一个SIGSEGV,而valgrind显示没有 无效内存访问的指示。你对如何启动 调试这个有任何线索吗?下面是我的代码模板。

static int do_stuff() { obj_t res = * calloc((size_t )1,sizeof(obj_t));

这看起来很错误。首先,什么是''obj_t'''type'' to?它是指向结构还是结构的指针?从右侧使用 它看起来像是'typedef''作为指针 到一个结构,而'sizeof(使用''sizeof( obj_t)让它看起来好像是另一种方式(或者你只是为指针而不是结构分配足够的 内存)。 然后在calloc()调用前面的''*'肯定是 错误 - 你不想要返回值指向 (你将取消引用一个无效指针,这是为了-BG / b )但是你想要将'(res)'中存储的calloc()返回存储。 你的编译器是不是在大声抱怨,或者你没有忘记 要求它报告有问题的代码(至少)''-W -Wall''? 还有一个问题,如果你包括< stdlib.h- 没有原型范围,你可以得到奇怪的效果。 最后,你应该检查回报va在你使用它之前,你需要使用calloc() ;-)

// res是0x000000 .. 你是如何得到这个结果的?而且,对于 a类型来说,''obj_t'是什么?

obj_iterate(res); // res是0xffffff ..

请报告您使用的确切源代码加上 的确切结果,而不是你觉得你还记得 - 很多 经常会犯错误,弄清楚 真正的问题是不可能的。 问候,Jens - \ Jens Thoms Toerring ___ jt@toerring.de \ __________________________ toerring.de

Hello, i callocated a pointer to a user-defined struct. The value of the pointer is something like 0x0000002aaaaa (can''t remember actually, I don''t have the computer running the code with me). Then I perform some stuff on the allocated structure which must be buggy since after its execution the value of the pointer is something like 0xffffff2aaaaa, i.e. same lsb, different msb. I don''t know where to start to debug this. Obviously, when I run the programm I get a SIGSEGV when deferencing the pointer and valgrind shows no indication of invalid memory access. Do you have any clue on how to start debugging this. Below is the template of my code. static int do_stuff() { obj_t res = *calloc((size_t)1, sizeof(obj_t)); // res is 0x000000.. obj_iterate(res); // res is 0xffffff.. do_other_stuff(res->fied); <-- SIGSEGV } Julien PS: my architecture is X86_64, Linux, gcc-4; code is compiled without optimization, debugging symbols activated

解决方案

Julien Lafaye wrote:

Hello, i callocated a pointer to a user-defined struct. The value of the pointer is something like 0x0000002aaaaa (can''t remember actually, I don''t have the computer running the code with me). Then I perform some stuff on the allocated structure which must be buggy since after its execution the value of the pointer is something like 0xffffff2aaaaa, i.e. same lsb, different msb. I don''t know where to start to debug this. Obviously, when I run the programm I get a SIGSEGV when deferencing the pointer and valgrind shows no indication of invalid memory access. Do you have any clue on how to start debugging this. Below is the template of my code. static int do_stuff() { obj_t res = *calloc((size_t)1, sizeof(obj_t)); // res is 0x000000.. obj_iterate(res); // res is 0xffffff.. do_other_stuff(res->fied); <-- SIGSEGV } Julien PS: my architecture is X86_64, Linux, gcc-4; code is compiled without optimization, debugging symbols activated

Julien... Why the asterisk in front of calloc? -- Morris Dovey DeSoto Solar DeSoto, Iowa USA www.iedu/DeSoto/

Julien Lafaye wrote:

Hello, i callocated a pointer to a user-defined struct. The value of the pointer is something like 0x0000002aaaaa (can''t remember actually, I don''t have the computer running the code with me). Then I perform some stuff on the allocated structure which must be buggy since after its execution the value of the pointer is something like 0xffffff2aaaaa, i.e. same lsb, different msb. I don''t know where to start to debug this. Obviously, when I run the programm I get a SIGSEGV when deferencing the pointer and valgrind shows no indication of invalid memory access. Do you have any clue on how to start debugging this. Below is the template of my code. static int do_stuff() { obj_t res = *calloc((size_t)1, sizeof(obj_t)); // res is 0x000000.. obj_iterate(res); // res is 0xffffff.. do_other_stuff(res->fied); <-- SIGSEGV }

Julien, if this isn''t the least useful problem description I''ve ever seen, it must be a close second. Values are "something like," code resembles a "template" that has no hope of compiling, much less running, the part that you yourself think "must be buggy" is completely concealed ... You say "I don''t know where to start debugging this," and all I can offer based on what you''ve presented is "Line forty-two."

PS: my architecture is X86_64, Linux, gcc-4; code is compiled without optimization, debugging symbols activated

That''s nice. What are your hair and eye colors? There are people here who are willing and probably able to help you, but very few of us are mind readers. Let''s see some *actual* data (not "something like") and *actual* code (not a "template"), and maybe we can do something. But until then ... "Doctor, it hurts!" "What hurts?" "Never mind the details, just make it better!" -- Eric Sosman es*****@ieee-dot-org.invalid

Julien Lafaye <se***********@pinglouwrote:

i callocated a pointer to a user-defined struct. The value of the pointer is something like 0x0000002aaaaa (can''t remember actually, I don''t have the computer running the code with me). Then I perform some stuff on the allocated structure which must be buggy since after its execution the value of the pointer is something like 0xffffff2aaaaa, i.e. same lsb, different msb. I don''t know where to start to debug this. Obviously, when I run the programm I get a SIGSEGV when deferencing the pointer and valgrind shows no indication of invalid memory access. Do you have any clue on how to start debugging this. Below is the template of my code.

static int do_stuff() { obj_t res = *calloc((size_t)1, sizeof(obj_t));

This looks pretty wrong. First of all, what is ''obj_t''typeded''ed to?Is it a pointer to a structure or a structure? From its use on the right hand side it looks like it''s typedef''ed as a pointer to a structure, while the use of ''sizeof(obj_t) makes it look like the other way round (or you would just be allocating enough memory for a pointer and not a structure). And then the ''*'' in front of the calloc() call is definitely wrong - you don''t want what the return value is pointing to (and you would be dereferencing a void pointer, which is for- bidden) but you want what calloc() returned stored in ''res''. Wasn''t your compiler complaining loudly or did you forgot to ask it to report problematic code with (at least) ''-W -Wall''? And there''s also the question if you included <stdlib.h- without a prototype in scope you can get weird effects. And, finally, you should check the return value of calloc() before you use it;-)

// res is 0x000000..

How did you got that result? And, again, what is ''obj_t'' for a kind of type?

obj_iterate(res); // res is 0xffffff..

Please report the exact source code you were using plus the exact results, not something you think you remember - much too often one is making mistakes that make figuring out the real problem impossible. Regards, Jens -- \ Jens Thoms Toerring ___ jt@toerring.de \__________________________ toerring.de

更多推荐

调试损坏的memoy

本文发布于:2023-11-23 22:11:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622998.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:memoy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!