OrangeC icon indicating copy to clipboard operation
OrangeC copied to clipboard

Adding CodeView 8 as a debug type

Open chuggafan opened this issue 7 years ago • 9 comments

This is another long-term project that should probably go hand-in-hand with my re-write, which is updating the debugger, https://github.com/yasm/yasm/tree/master/modules/dbgfmts/codeview YASM gives a nice overview of the updated CodeView format, of which link.exe can use from COFF objects to create PDB's, so that Visual Studio can debug it. LLVM has some nice stuff about PDB generation AND About CodeView 8 generation although this is more specific to the LLVM subsystem. This is where clang generates it's DebugInfo, of which CodeView is one option, the issue with generating up-to-date CodeView is that doing so means that we have to follow microsoft name mangling, thankfully however, Clang implements that thank's to microsoft wanting them too However, a better link for the exact specifics would be here.

Extra links to various Debug Formats:

NASM's implementation of CodeView 8

LDC's collection of links on this topic

LLD on PDBs (This is incomplete on their part, so I wouldn't look into it too much)

Microsoft's PDB stuff that they open sourced for LLVM

[And here's

I'm mostly using this issue as an aggregate of things to do while I do a bunch of minor edits to Utils, etc. (I'm going to add an Error Handler to Util so that there's one, singular error handler for the entirety of OCC soon, I just need to figure out exactly what is needed by everything first)

chuggafan avatar Oct 20 '18 16:10 chuggafan

so you make a codeview 8 module, then process it with microsoft link, and suddenly it works in visual studio? That sounds nice!

I had codeview 6 or 7 support in the old CC386 compiler so I'm at least conversant with the format as a general thing.

LADSoft avatar Oct 22 '18 21:10 LADSoft

so you make a codeview 8 module, then process it with microsoft link, and suddenly it works in visual studio? That sounds nice!

That's (hopefully) the idea, dropping the information off into COFF objects, then taking the COFF objects and process them using Microsoft's Link and out pops a PDB, or a CV8 debug format module.

It should be possible to use Clang's work to create PDBs ourselves, meaning less reliance on outside tools and more tunable generation.

chuggafan avatar Oct 22 '18 22:10 chuggafan

@chuggafan Slightly topic drifting from my side: Does this mean that you could create PDB for any binaries (including for languages other than C/C++)? What is needed to do so (and what is needed to use the resulting PDB + original source file in VS / vscode)?

GitMensch avatar Oct 23 '18 14:10 GitMensch

Does this mean that you could create PDB for any binaries (including for languages other than C/C++)?

Yes!

The file format is the same for everything, https://github.com/dlang/dmd DMD does PDB generation iirc, so they're a good example of other languages doing it.

chuggafan avatar Oct 23 '18 15:10 chuggafan

... I've glanced at this code for some minutes but fail to find the PDB parts.

GitMensch avatar Oct 23 '18 18:10 GitMensch

Looks like I was wrong, they generate CodeView 8, which is then taken into the PDB by Microsoft's Link.exe

So that's how they do it, there's also https://github.com/rainers/cv2pdb doing its own version of this.

chuggafan avatar Oct 23 '18 19:10 chuggafan

So no "fast" way yet to create a PDB directly?

GitMensch avatar Oct 23 '18 20:10 GitMensch

Clang and LLVM seem to be able to do so for the most part, and MSVC's Internal way to create them was made public for the express purpose of getting clang and LLVM to implement it. Going off the code from MSVC is essentially a surefire ticket to actually being able to create a PDB.

chuggafan avatar Oct 23 '18 20:10 chuggafan

also a request to make occil generate PDB files (see #510)

LADSoft avatar May 21 '20 00:05 LADSoft