Solved

Tracing a run-time error to a line of source code

Posted on 1998-06-02
3
217 Views
Last Modified: 2010-08-05
I am using MSVC 5.0.  I made a release build of my project ( 1 exe and several dlls).  I get a run-time error in one of the DLLs consistently when running the release build.  The run-time error does not happen with a debug build.  

My question is:

Is there a way for me to take the CS:EIP pointer that i'm given at the time of the error and somehow trace it back to a line of source code?  I've made a map file, but I haven't been able to get anything useful out of it.

thanks in advance for any help
Bob Brickhouse
Product Developement
Grayson Wireless
0
Comment
Question by:brickb
3 Comments
 

Expert Comment

by:alfredj
ID: 1165121
I can't answer your question specifically, but you might be able to
solve your problem by downloading (if you havent already)  the
<A HREF=www.microsoft.com/visualc/download> Visual C++ service pack</A>  from  www.microsoft.com/visualc/download.  Many strange
optimizer problems went away when I upgraded.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1165122
You don't need the CS value.  But the EIP should be one of the addresses in your map file.

Unfortunately, it could be an address from the run-time library, or from a DLL.  So it might not help.

This is not the best way to debug.  Can you print "progress" messages to find out where the problem is occurring.   OutputDebugString is great in this capacity.
0
 
LVL 2

Accepted Solution

by:
abesoft earned 200 total points
ID: 1165123
The major problem with tracing an instruction pointer back to a map file is that the DLL is (actually, it may be) re-mapped when it is loaded into memory.  So the register is pointing at a location that is offset from the actual code in the map file.

So, in order to get back to the actual line, you will need to figure out the offset that the DLL was loaded at.  Matt Pietrek wrote a utility for MSJ that did this: it was called LoadProf32, but I can't seem to find it at the MS site right now- their search engine makes my proxy gag somehow, or maybe it's the other way around ;)  Anyway, one of the things that LoadProf32 would do is report on the offset that each DLL is loaded at.  (It also reported a lot of useful info about the initialization time for each module loaded:  I highly recommend this utility...)

Taking the load offset, and seeing if it was different from the anticipated load offset, you will know where the fault actually happened.  This should let you look back into your map file to find out where it happened.  

If you combine this with a good post-mortem (like a stack dump from Dr Watson) you should be able to trace into things a little more.

Of course, you will still be only getting to the function level- the actual line won't be available to you, since that info is completely missing from a release build.  But you WILL be able to either read through the assembler (if you're comfortable with that) or go back to the source and add extra logging statements to track down the actual line.

Good luck!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

829 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