Click here to Skip to main content
Click here to Skip to main content

Tagged as

How to determine corresponding source line from offset number

, 22 Jul 2003
Rate this:
Please Sign up or sign in to vote.
If you know offset number within exe file, you can specify where it corresponds in source file

Sample error

Introduction

Consider that your customer has reported you an error with the offset number; you can determine the line in the source which caused the error. This article explains how the erroneous source line can be detected using the offset address in release exe.

Advantage of this method is that it does not require neither to send any extra programs nor a debug exe to your customer nor rebuilding your program like explained in other articles submitted. Disadvantage is that you have to spend some extra effort by digging in two extra compiler generated file types: a .map and some .cod files.

A *.map file basically includes base addresses of compiled functions. A *.cod file generally includes Assembly, machine and source codes, if you apply settings below.

Using the code

  1. Open the supplied demo project OR create a new MFC dialog application using wizard and put some crashy code. Supplied project provides a button that crashes when clicked. Select Release from Build -> Set Active Configuration.
  2. Project -> Settings ->. Under "C/C++", Category "Listing Files". Select "Assembly, Machine Code, and Source" as "Listing File type:". This option forces compiler to generate a Source_File_Name.cod file for every source file separately.
  3. Again Project -> Settings ->. Under "Link", category "Debug". Mark "Generate map file", Click OK. This option forces compiler to generate a Project_Name.map file.
  4. The provided project exe generates error at address 148f: Open map file, determine function including code at 148f.

    These lines lie in sample map file.

     0001:00000470   ?OnQueryDragIcon@CDebugSampleDlg@@IAEPAUHICON__
                                     @@XZ 00401470 f   Debug SampleDlg.obj
     0001:00000480   ?OnButton1@CDebugSampleDlg@@IAEXXZ 
                                     00401480 f   Debug SampleDlg.obj
     0001:000004a0   ?BeginModalState@CWnd@@UAEXXZ 004014a0 
                                     f i Debug SampleDlg.obj

    The leading '1' is the segment address. Thus the function includes code at 48f is OnButton1 which begins at 480.

  5. Search string OnButton1 in cod files. Locate implementation of this function. In this listing, expressions such ; 174 : corresponds to line numbers in source code.

    Debug SampleDlg.cod file includes these lines:

    ?OnButton1@CDebugSampleDlg@@IAEXXZ PROC NEAR   
                                ; CDebugSampleDlg::OnButton1, COMDAT
    
    ; 174  : {
    
      00000    83 ec 0c     sub     esp, 12            ; 0000000cH
    
    ; 175  :     // TODO: Add your control notification handler code here
    ; 176  :     
    ; 177  :     // Some garbage code here {
    
    ...
    
    ; 182  :     //    }
    ; 183  :     
    ; 184  :     *( (int *) 0x0000) = 1;
    
      0000f    c7 05 00 00 00
        00 01 00 00 00     mov     DWORD PTR ds:0, 1
    
    ; 185  : }
  6. Subtract beginning address of function from the offset that error occurred: 148f - 1480 = fh. Source code generates machine code on line 000f exists on 182 - 184 numbered source code lines. That's
    ; 183  :     
    ; 184  :     *( (int *) 0x0000) = 1;
    
      0000f    c7 05 00 00 00
        00 01 00 00 00    mov   DWORD PTR ds:0, 1

    Error hides within OnButton1 function at line *( (int *) 0x0000) = 1;

Please let me now if you find this article useful, or know a better way.

History

  • 21.07.2003 : First release.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

eymre

United States United States
No Biography provided

Comments and Discussions

 
QuestionIrrelevant to managed code, correct? PinmemberSam Hobbs17-Mar-12 2:18 
QuestionWhat about using libraries ? PinmemberDavide Zaccanti1-Oct-06 21:15 
GeneralI did not set theMAP file option when I release last...HELP PinmemberGautam Jain5-Nov-04 0:40 
GeneralRe: I did not set theMAP file option when I release last...HELP Pinmemberqwerty666qwerty6666-Feb-06 22:00 
GeneralExcellent Piece of Information!!! PinmemberBalkrishna Talele26-Aug-04 20:31 
Cheers!!! Indeed it was useful information, thanks a lot
cheers
Balkrishna
QuestionIs there any way to get the exported function's name with proper parameter (in short signature)??? PinmemberJigar Mehta10-Jul-04 1:36 
QuestionHow you will find the offset address? PinmemberThangs31-Jul-03 8:02 
AnswerRe: How you will find the offset address? PinmemberEmre BURHAN1-Aug-03 4:13 
Questionhow do you find crashed function in system dlls? Pinmemberdiamant31-Jul-03 1:59 
AnswerRe: how do you find crashed function in system dlls? PinmemberMike Dimmick31-Jul-03 10:56 
AnswerRe: how do you find crashed function in system dlls? Pinmembercoolvcguy16-Aug-03 20:36 
GeneralRe: how do you find crashed function in system dlls? Pinmemberdiamant18-Aug-03 0:02 
GeneralDebugging book Pinmembernerd_biker30-Jul-03 5:08 
GeneralCrash Finder Pinmembermwilliamson23-Jul-03 7:44 
GeneralRe: Crash Finder PinmemberShaun Wilde28-Jul-03 21:56 
GeneralRe: Crash Finder PinmemberCarlos29-Jul-03 23:28 
GeneralCool! PinmemberRyan Binns22-Jul-03 23:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 23 Jul 2003
Article Copyright 2003 by eymre
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid