Add missing elements from newer versions of CodeView.#23341
Add missing elements from newer versions of CodeView.#23341LightBender wants to merge 22 commits into
Conversation
…and changes since CV8 implementation was written.
|
I might be biased, but I'm not sure this is the right approach:
I'd rather prefer focused fixes to the existing code for specific bugs. |
|
@rainers The duplication is intentional. There have been a lot of new features added to CodeView since CV8, and branching all of them out for a preview switch would have made CV8 a much more complicated file to review and maintain. Which gets to why this PR in the first place. This isn't about fixing a bug or two. There are a lot of new features that CV8 does not implement, we're on CV13 now according to documents from LLVM, and this adds as much as makes sense for D. As for test cases, I can certainly add those. I can try to enable the preview switch for testing, but I strongly suspect that all the additions will break the current tests. Should be fun to watch the failure though. Here is full explanation of everything added/fixed. 1. New symbol records (not emitted by cv8.d)
2. New type / ID-stream records (not in cv8.d)
3. Enhanced source-file & line info
4. Full TLS support
Values are identical, but 5. Named constants instead of magic numbers
6. Structural / robustness changes
7. Behavior shared / reused (not reimplemented)
8. Not yet implementedTracked in
Summary
|
|
I have compared pdb.d (a misnomer as this is still CV written to an obj file) and cv8.d, most of the changes are just renaming and reformatting. Using identifiers instead of magic numbers is good.
Not much materializes, though:
The only string added is "dmd".
It hashes the filename, not the content of the file!
Indeed, the header is a bit more verbose. It ignores the configured language, though.
These could be some actual improvements, but it only emits dummy values. It also omits the "member function type info" in cv8.
No change
These are not available in the backend AFAICT. |
I covered that at beerconf, but didn't insist on a name change. Even though it is required. Adam was under the belief that the pdb file would be emitted directly, when it's the linker that does it. |
|
@rainers That bit of feedback made the LLM work out hard. Hopefully it looks better. What are we thinking for names? IMO, at this point we really probably want to just merge everything into one file since we will never be emitting CV4 (OMF) again, and we're a bit beyond CV8. |
|
I see some improvements (language selection restored, frameproc now has some info). The hash is calculated from the file content now, but it should not have to read the file again. It is already in Module.src and should be passed down somehow or retrieved from FileManager.getFileContents(). So far there are still only tiny improvements that you won't notice in a debugging session. I think these could just be applied to cv8.d. Long term, we could ditch CV4 support, but there are still some remnants for OBJ_OMF that should be removed first. Then cv8.d might be renamed codeview.d while only using a There are a couple of more files involved (tocvdebug.d, cgcv.d). Not sure if merging these is useful or whether there is a sensible separation. |
…ove the preview switch.
|
Alright @rainers here it is. I've merged |
|
Unfortunately this is growing to become even harder to review. I was hoping for smaller PRs rather than larger ones ;) Taking step 3 (renaming to codeview and cv_-functions) before the other 2 (eliminating OMF and CV4) now produces the strange call chain that a cv-function calls a cv4-function that conditionally calls a cv_ function for CV8 to do the actual work. Keeping cv8 for both module and function names would probably be good enough to make this step manageable. |
|
BTW: I think it needs Walters approval to remove all the ancient CodeView code that is inherited from the DMC compiler backend. |
… and remove the preview switch." This reverts commit 494c9f3.
…long with the preview switch.
|
@rainers I've reworked this PR to only included the CodeView additions/improvements to the This PR should be a bit smaller now, but the added tests will definitely add some weight to the review. |
rainers
left a comment
There was a problem hiding this comment.
Thanks, looks a lot better, especially with the added tests. Just a few nits remaining...
|
Note: FreeBSD 13.2 is an out-dated test that we replaced last weekend. |
The code for PR was generated using an LLM.
LLM Model : Opus 4.8 (Extra High)
Prompt:
I've attached files for D's CodeView implementations. Using these files, we would like to add a new implementation that uses the latest information from Microsoft (here: https://github.com/microsoft/microsoft-pdb) and LLVM (here: https://llvm.org/docs/PDB/). We would like to add a new D file called "pdb.d" to the backend folder that implements the latest PDB information from LLVM with the goal being to achieve similar PDB quality and coverage as LLVM does. This new implementation should not touch the existing CodeView4/8 implementations but should be entirely self-sufficient with the intent being to eventually retire the existing implementations. This implementation can modify cgcv.d as needed, but edits that would effect CV4/CV8 should be kept minimal. This new PDB emitter should be hidden behind a preview compiler flag called "-preview=newpdb". This flag is to be threaded through the backend config. Please be sure to add pdb.d to the appropriate build scripts and VC++ projects.
I have attached two detailed analysis of features missing from D's CodeView generation. Both analysis uncovered different things so path attention to both. Considering that D may not support all of these features (example: we know that live sites and S_DEFRANGE are not supported in DMD) please make a plan to implemented as many of these as possible in pdb.d. Please included a detailed list of what you plan to implement and what you determine cannot be implemented with existing DMD infrastructure. The overall goal of this plan is to implement as much of CodeView as is possible with the existing DMD infrastructure, and then use the list of what cannot be implemented to potentially add that infrastructure at a later time. Please put the list of unimplemented CodeView features into a markdown file in the backend folder.
Things we would like to implement from the analysis that are not currently implemented:
Second Prompt:
Let's do one final check to make sure that we added everything that we can use for DMD from the latest CodeView/PDB implementations from Microsoft (here: https://github.com/microsoft/microsoft-pdb) and LLVM (here: https://llvm.org/docs/PDB/). If there are additional items to add, please add them.
Bug-fix prompts:
I received the following error while attempting to build an app:
core.exception.ArrayIndexError@src\dmd\common\outbuffer.d(282): index [192] is out of bounds for array of length 192
I am now getting the following linker warning:
coalesce.obj : warning LNK4209: debugging information corrupt; recompile module; linking object as if no debug info
I have attached the .obj file for you to use in your diagnosis.