Solved

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

Posted on 1998-06-02
3
213 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now