Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How WinDbg get to know source code?

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

like image 297
Pranit Kothari Avatar asked Dec 06 '13 10:12

Pranit Kothari


People also ask

How does a WinDbg work?

The windbg on your host OS uses the pdb file to translate line nubers in the source files to addresses in your guest OS (xp) . Then the the debugger agent uses this address to set break points (Int 3) in the guest OS. This is much in the same way as a local debugger do to a local process.

How do I debug code in source?

Drag and drop the generated source files you want to debug into Visual Studio. Place break points in the source code in Visual Studio. Open the menu option Debug > Attach to Process Ctrl + Alt + P in Visual Studio. Select menu option Run > Resume, if you selected Debug as > Real Time Application in RSA-RTE.


1 Answers

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.

like image 131
Violet Giraffe Avatar answered Sep 23 '22 14:09

Violet Giraffe