?
Solved

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

Posted on 1998-06-02
3
Medium Priority
?
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 800 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 clear a vector as well as how to detect empty vectors in C++.

719 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