Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tips for debugging stack smash?



At 1:32 PM -0400 8/2/06, Cameron Hayne wrote:
On 2-Aug-06, at 12:27 PM, Scott Ribe wrote:

Sigh... I'm smashing the stack, leaving things where XCode doesn't show any
useful info when it breaks.

Suggestions:
1) Look carefully at what is on the stack. Try to figure out what those hex bytes might represent - that could give you a clue. If there is a common pattern of hex bytes on the stack when the problem occurs, maybe installing a conditional break point in gdb will allow you to determine where the problem occurs.
2) Scan your code for functions whose return values are larger than what would fit in a register - e.g. functions that return a struct or object by value. Look carefully at those functions. I've some times seen cases where the return statement was missing and, for some reason that I don't understand, the compiler wasn't complaining.

It doesn't, and I forget all the reasons. I think it's because the compiler cannot catch all possible "naked" exits, so it doesn't try. But that should not cause a crash.


3) Turn on all warnings in gcc. Also try running 'lint' on your code.
4) Try divide & conquer techniques like commenting out half of your code and seeing if the problem occurs.


--
Cameron Hayne
email@hidden

In particular, look for any arrays whose bounds might be exceeded. Also check for uninitialized pointers or calculations on pointers that aren't right.


David
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden
References: 
 >Tips for debugging stack smash? (From: Scott Ribe <email@hidden>)
 >Re: Tips for debugging stack smash? (From: Cameron Hayne <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.