[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Bounds Checking for Visual Studi C++ 6.0

Posted on 2005-04-12
9
Medium Priority
?
673 Views
Last Modified: 2013-12-03
I have a C/C++ multithreaded application in Microsoft Visual Studio C++ 6.0
When I run the code in debug mode, at some point it segfaults ("Unhandled exception in MyApplication.exe: 0xC0000005: Access Violation")
Normally I can narrow down why by looking at the 'Context' drop down, showing me the stack trace back to the offending function and line of code.

But with this particular crash, all I get for context stack backtrace is '63732052()' and after that a bunch of NTDLL calls.
You can see a screenshot here: http://www.telparia.com/crash1.jpg
No matter how far back I go, I just see more of those NTDLL calls, it never hits my code.

Anyways, what I imagine is happening is somewhere in my code, I am over-writing data that doesn't belong to me.
For some odd reason, this isn't causing an immediate fault. Instead some time later when either my code touches that memory, bingo crash.

I've already tried commenting out recently added code, and visually looking for potential problems and have not yet found a solution.

Under linux there are awesome tools such as efence (http://freshmeat.net/projects/efence/) and valgrind (http://valgrind.org/)
These tools are capable of detecting when any code accesses code it shouldn't and breaks execution at the right code line.
I believe this is known as 'bounds checking' ?

I can't move the application to linux because it relies on several windows specific libraries, including some custom ODBC drivers only available for Windows.

So I need some sort of tool to detect these violations and determine where in my code the problem lies.

I found something called GlowCode (http://www.glowcode.com/) but it appears only to be a leak checker and a profilier.

I also found an app called BoundsChecker (http://www.compuware.com/products/devpartner/bounds.htm)
I don't know if BoundsChecker will help me with this, but the name certainly sounds correct.
I requested a trial, but have not yet heard from them. And at a price of $1,100 that will be hard to justify to management to purchase.

So what I'm asking is if there are any free apps out there that can help me in this situation.
Or maybe there's a way to extend the stack trace to include more than 10 functions?
Or some other solution that I'm not seeing?

I'll be rewarding points to the person who's advice leads me to locating and fixing my bug.
So if someone reccomends a product that finds it, or if someone suggests a modification to visual studio, or a technique to help narrow down the problem.
I'm open to everything.
0
Comment
Question by:Sembiance
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 600 total points
ID: 13767117
The best tool is your brain.....
Is the unique debugging tool i have used in the last 20 years....

PS. Forgot to mention, I love MessageBox() and TRACE()
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 900 total points
ID: 13767315
You could use 'BoundsChecker' for that. This (IMHO great) tool is quite expensive, but there's a trial version available via http://nashua.compuware.com/evaluations/
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 900 total points
ID: 13767331
Oh, BTW, be sure to also get the symbol files for your OS and service pack from http://www.microsoft.com/whdc/devtools/debugging/symbolpkg.mspx ("Download Windows Symbol Packages") which will help you to identify which calls to NTDLL were made.
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 16

Expert Comment

by:nonubik
ID: 13770228
For your particular crash, is there any of your function on the call stack? Or just ntdll's (it's not clear from the picture)
0
 

Author Comment

by:Sembiance
ID: 13772180
It's only NTDLL's as far as the trace goes back.
I'm taking jkr's advice and downloading the symbol packages now to see what part of NT DLL it comes from.

I've also applied for the trial version of BoundsChecker, but  haven't yet heard a response back yet.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 13772228
I can consider myself fortunate as I persuaded the management to buy one license :o)
0
 

Author Comment

by:Sembiance
ID: 13809849
Okay, well, I tried several products.
Rational Purify
BoundsChecker
HeapAgent

Rational Purify evaluation kept giving me errors about licenses even though I installed the license.
HeapAgent didn't seem to work correctly.
And BoundsChecker evaluation failed to install the BoundsChecker menu in Visual Studio.

I took the advice a fellow worker, and I took my code, and ran it through a quick script.
The script added a function call that will add to a log file what line/thread is currently on.
On EVERY single line I had it do this (almost every line).

Anyways, this narrowed it down to a specific for loop where I was able to find the problem.

Now my question is, why couldn't Visual Studio remember the last x lines of source code it ran and show me them to me when it crashes?
Does anyone know of a visual studio addon that would do that?
0
 
LVL 86

Expert Comment

by:jkr
ID: 13809880
>>Now my question is, why couldn't Visual Studio remember the last x lines of source code it ran

If the call stack is blown away (technically spoken: overwritten), no tool will be able to recover from that...
0
 

Author Comment

by:Sembiance
ID: 13886350
Now I don't know who deserves points.
My solution, writing a line to a file for every line was suggested by a coworker, and not in this thread.
Although common sense, for a multi-threaded C++ app I viewed it as a last resort, but it was pretty cool how well it worked.

Anyways, what should I do about points?
No one response solved the problem.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question