How WinDbg get to know source code?
Asked Answered
R

2

8

I made C++ application to use with WinDbg, and intentionally add access violation run-time error.

Application was compiled as release build, and then I copied exe from release folder to desktop. Still when I use WinDbg, and application crashes, it open my source code file showing error line highlighted.

I am not able to understand, how WinDbg understand my source code file path.

Also, when I get crash dump from client, it may be possible, I do not have source code available with me. So I want to simulate real world scenario.

Regards

Raseta answered 6/12, 2013 at 10:2 Comment(5)
@VioletGiraffe Yes you are right. When I delete pdb file, source code is not shown in WinDbg. Please write as answer so I can accept it.Raseta
It will only open the source file if you have added the path, it does not automatically know where to look, the pdb will show where the original path of the file was when compiled but this is almost always going to fail unless you are on the same machine. Also what do you mean by source code? the pdbs show the public (and if not stripped private) symbols only and allow the debugger to translate the offsets back to source line numbers. You do not see source code from the pdbsAnastigmatic
@Anastigmatic You are right. Actually I am using same where I have source code and WinDbg.Raseta
@VioletGiraffe But is it safe to have pdb file path in release exe?Raseta
@pranitkothari: Not sure what you mean by safety. It might reveal your personal information based on the names of folders in pdb path, but if a path doesn't contain a folder named after your surname - I don't see a problem.Faeroese
F
5

The way I understand it, Visual Studio compiler generates a .pdb file for any executable it creates (when /DEBUG flag is set). This PDB (Program Database) file contains information (including paths to source files) required for the debugger to match address in a binary module to source code. And it seems that a path to .pdb is hard-coded into the binary. So when you move a binary itself, debugger can still find pdb, from which it finds the sources.

All paths are probably absolute and will only work on the PC which compiled the binary.

Faeroese answered 6/12, 2013 at 10:20 Comment(2)
+1 for All paths are probably absolute and will only work on the PC which compiled the binary.Raseta
msdn.microsoft.com/en-us/library/windows/hardware/… You can rebuild pdb to use network share or even source control system ( tfs svn etc)Laclos
A
0

.pdb has source file full path name information. open a .pdb file you will see lines like this:f:\dd\vctools\crt\crtw32\stdcpp\locale0.cpp

Awash answered 2/9, 2016 at 16:17 Comment(1)
Read this sample from Microsoft, you will know what information is included in .pdb and how to read and parse .pdb. msdn.microsoft.com/en-us/library/b5ke49f5.aspxAwash

© 2022 - 2024 — McMap. All rights reserved.