0

This problem maybe has no specific answer appropriate for all situations,but is there some general principle we can respect? Overwrite happened in own module may be a little easy,but if the overwrite is caused by another module written by other people and the program crashed random, how we can do for these?

4
  • 1
    That's the problem, there is no specific answer. There are many general techniques and tools, but the question doesn't fit SO's model of specific, answerable questions. Commented Mar 19, 2014 at 2:06
  • Dynamically allocate memory and use valgrind to identify abuses of the dynamically allocated memory. Dealing with overwrites of static data or stack data is harder. The tool Purify from IBM is also very good, but more expensive than valgrind. Commented Mar 19, 2014 at 2:47
  • I believe the OP is asking for common techniques to debug this issue. While this doesn't have a specific answer, it seems like a good question which might create a collection of good answers Commented Mar 19, 2014 at 2:56
  • @thisisdog yes,i believe there are some good engineer practices when debug such issues.So,we can collect and reference them. Commented Mar 19, 2014 at 3:03

2 Answers 2

1

I have had a lot of luck with a product called Purify, that performs memory bounds checking, after you include it at compile time. The Wikipedia page I linked to also lists some open source alternatives.

Sign up to request clarification or add additional context in comments.

1 Comment

Rather than tools,i want to know some practices we can afford. Thx,anyhow.
1

Memory overwrite is often caused by dangling pointers. While this is not the only case, it's quite common and so I've found one technique that's pretty useful:

By implementing your own memory allocator you can turn on a special debug mode where you write some known pattern into freed memory. You then periodically check all free memory to see if the pattern has been overwritten. If it has you assert or log or something. This will often find the culprit that's writing to some dangling pointer.

In addition, you can use the custom allocator to log the allocations made by address. So if you see that someone has overwritten address 0x30203 you can just check who that memory was allocated to.

I realize this sounds like a special case, but it's helped me out of so many cases before

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.