Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


C++ debug tools


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Aliii   Members   -  Reputation: 1448

Like
0Likes
Like

Posted 01 September 2012 - 07:19 AM

Are there any tools for detecting index out of bound bugs at runtime? I heard about Electric Fence but I need one for Win. Thanks!

Sponsor:

#2 Adam_42   Crossbones+   -  Reputation: 2619

Like
2Likes
Like

Posted 01 September 2012 - 08:45 AM

The simplest option is to enable Page Heap Mode but it does require plenty of spare address space (link with /LARGEADDRESSAWARE if it's a 32-bit program to double available address space when run on 64-bit Windows).

You could also try http://www.drmemory.org/ but it's not so easy to use.

#3 Aliii   Members   -  Reputation: 1448

Like
0Likes
Like

Posted 01 September 2012 - 09:08 AM

The simplest option is to enable Page Heap Mode but it does require plenty of spare address space (link with /LARGEADDRESSAWARE if it's a 32-bit program to double available address space when run on 64-bit Windows).

You could also try http://www.drmemory.org/ but it's not so easy to use.


Do these work when the "out of buond" is inside the programs memory?

#4 Hodgman   Moderators   -  Reputation: 31938

Like
2Likes
Like

Posted 01 September 2012 - 09:42 AM

What kind of allocation is being indexed? Is it created with malloc or new? Is it a member of a class with members on either side? Is it a container class that you've got the code for? Is it a standard container like a std::vector?

For structures that you allocate with malloc/new, most games I've worked on have had a #define that you can enable, which pads every new/malloc call with a begin/end buffer, so that you can watch the buffer areas for corruption. I guess your project doesn't have an allocator with debugging features like this?


There's some good tips in this blog post, including the above mentioned Page Heap mode:
http://randomascii.w...h-more-crashes/

Page Heap puts each allocation on its own 4-KB page, with the allocated memory aligned to the end of the page. Therefore if you overrun the buffer you will touch the next page. Page Heap ensures that the next page will be unmapped memory so you get a guaranteed access violation at the exact moment that you overrun the buffer.


Edited by Hodgman, 01 September 2012 - 09:44 AM.


#5 Ripiz   Members   -  Reputation: 529

Like
0Likes
Like

Posted 01 September 2012 - 10:03 AM

If I array size is static you should be able to replace it with std::array with no code modifications; it'll throw exception right away if you go out of bounds.
If it's dynamic then you can use std::vector, but that requires a bit code modification.

Edited by Ripiz, 01 September 2012 - 10:03 AM.


#6 Aliii   Members   -  Reputation: 1448

Like
0Likes
Like

Posted 01 September 2012 - 10:45 AM

Thanks! Im allocating with new. I have at least 100 classes in this project(and many many allocations)so I dont know where is it coming from, ...the program doesnt crash, no segmentation fault or anything, ....it overwrites some of the object geometry. But I cant reproduce this "error" in debug mode. On an other forum they said thats because in that mode the heap is allocated differently or something.

#7 e‍dd   Members   -  Reputation: 2105

Like
2Likes
Like

Posted 02 September 2012 - 12:59 PM

Is it always the same piece of object geometry that gets overwritten?

If so, assuming you're using Visual Studio, you can set a break point that is triggered when a particular piece of memory is modified. The call stack at that breakpoint will give you the culprit.

A better way, imho, is to start adding more assertions and/or tests.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS