How to compile C program in GCC to enable debug in WinDbg?
Asked Answered
V

2

6

I compile such code by GCC (v7.1.0) (command line below).

int func()
{
    return 0x1234;
}

int main()
{
    func();
    return 0;
}

gcc .\001_simpleMain.c -O0 -m64 -g

After compilation I run WinDbg (10.0), open executable (Ctrl+E), program is loading. Breakpoint is hit on start process everthing is ok. After it I want to open source code (Ctrl+O) and try to put breakpoint inside func method.

WinDlg tells me:

*** ERROR: Module load completed but symbols could not be loaded for G:\Examples\Gcc\a.exe

Why it is not working? Should I change compilation param? MY CPU is AMD64

Victim answered 9/6, 2017 at 10:59 Comment(2)
Try to use gdb (if available)Quitrent
Clang has a Microsoft compatibility mode that emits CodeView-style debug info into the object files. If you then link those with Microsoft's link.exe, you'll have the PDBs required by WinDBG and other Windows debuggers. Note, however, the Microsoft compatibility mode has other effects as well. clang.llvm.org/docs/MSVCCompatibility.htmlTenedos
E
4

Since you're using Windows with WinDbg you need the proprietary PDB files, which contain the debugging information for debugger tools that come from Microsoft.

GCC will generate debugging information that can be used by the gdb debugger (well known in Linux) for example.

gcc -g:

Produce debugging information in the operating system’s native format (stabs, COFF, XCOFF, or DWARF). GDB can work with this debugging information.


If you are using MinGW or Cygwin already you can use gdb from there because it's available in the MinGW/Cygwin environment. If not there are several gdb implemenations for Windows available.

Eidson answered 9/6, 2017 at 11:14 Comment(0)
A
4

Once you have built debugging files according to @Andre Kampling's instructions, you'll first need to convert them into PDB format. But even then, WinDbg will likely still not find them.

The executable has some data which points to the PDB file. Since you built in on Linux, that will be a Linux path which is not available on your Windows system.

Therefore, you need to set up your symbol path correctly so that WinDbg knows where you put them.

Basically you'll need

0:000> .symfix c:\symbols

for the Microsoft symbols and

0:000> .sympath+ c:\path\to\your\symbols

and then instruct WinDbg to load them again

0:000> .reload /f
0:000> ld*
Anaglyph answered 9/6, 2017 at 13:37 Comment(2)
What u mentioned is correct in general but this does not solve the question that was asked originally. As mentioned earlier, gcc/ g++ with -g option generates debug symbols that are understood by gdb and as far as I know, there is no way to debug such program using windbg on windows.Saltant
@MaryamShabani: I added a link to a converterAnaglyph

© 2022 - 2024 — McMap. All rights reserved.