Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Output exe's debuginfo points to PDB with out+hash.pdb instead of out.pdb #7358

Closed
snf opened this issue Sep 13, 2019 · 7 comments
Closed
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` O-windows OS: Windows

Comments

@snf
Copy link
Contributor

snf commented Sep 13, 2019

Describe the problem you are trying to solve

Whenever cargo build is run, it creates the files name+hash.exe and name+hash.pdb in the directory target/xxx/deps/. Then when the files are copied to target/xxx/, the .exe still references to the .pdb in the deps directory which also includes the hash in the name.

Then there are problems if the .pdb is distributed along the .exe. When someone tries to debug the program without the deps/ folder, the debugger doesn't find the symbols. I understand this is only a one-time issue per person (once they educate themselves on this behaviour) but it's not a good default.

Describe the solution you'd like

I tried looking up if there were previous discussions about it but couldn't find anything.

The only solution I could think of was creating the exe and pdb with the same name that should go into target/ and then copy them to deps/. I believe it's not a common practice to debug the files in deps/ so it shouldn't be an issue if the pdb link in that folder mismatches the name.

Notes

@snf snf added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Sep 13, 2019
@alexcrichton
Copy link
Member

Thanks for the report! We've had to deal with this before, but can you detail a bit more about how the .pdb is referenced from the .exe? Is it by absolute path? By relative? Or is it assumed to just sit next to foo.exe?

@snf
Copy link
Contributor Author

snf commented Sep 19, 2019

So the information inside the .exe is

0:000> lm
start             end                 module name
00007ff7`a6090000 00007ff7`a60b6000   heap_oob_simple_82ee03cff5089374   (deferred)             
00007ff9`4b7f0000 00007ff9`4b861000   verifier   (deferred)             
00007ff9`615a0000 00007ff9`615b6000   VCRUNTIME140   (deferred)             
00007ff9`707c0000 00007ff9`7084f000   apphelp    (deferred)             
00007ff9`79530000 00007ff9`7962a000   ucrtbase   (deferred)             
00007ff9`7a1a0000 00007ff9`7a443000   KERNELBASE   (deferred)             
00007ff9`7c0d0000 00007ff9`7c182000   KERNEL32   (deferred)             
00007ff9`7c3a0000 00007ff9`7c590000   ntdll      (export symbols)       C:\WINDOWS\SYSTEM32\ntdll.dll

And the symbol information:

0:000> !lmi heap_oob_simple-82ee03cff5089374.exe
Loaded Module Info: [heap_oob_simple-82ee03cff5089374.exe] 
         Module: heap_oob_simple-82ee03cff5089374
   Base Address: 00007ff7a6090000
     Image Name: heap_oob_simple-82ee03cff5089374.exe
   Machine Type: 34404 (X64)
     Time Stamp: 5d6d0c92 Mon Sep  2 13:35:30 2019
           Size: 26000
       CheckSum: 0
Characteristics: 22  
Debug Data Dirs: Type  Size     VA  Pointer
             CODEVIEW    77, 1de2c,   1c82c RSDS - GUID: {609AC086-FD2A-4CF0-9679-6D1433420803}
               Age: 1, Pdb: C:\Users\XXX\projects\rust_crash\target\release\deps\heap_oob_simple-82ee03cff5089374.pdb
           VC_FEATURE    14, 1dea4,   1c8a4 [Data not mapped]
                 POGO   2fc, 1deb8,   1c8b8 [Data not mapped]
    Symbol Type: DEFERRED - No error - symbol load deferred
    Load Report: no symbols loaded

The debugging tools usually have a file finding algorithm that trim the path to look for the file. The problem is that the file it's looking for is heap_oob_simple-82ee03cff5089374.pdb (in the deps/ folder but doesn't mater as the algorithms will get rid of the paths) that doesn't match the name of the file generated in the output directory. The problems appear when they are distributed.

@alexcrichton
Copy link
Member

Ok thanks for the information! Would you be able to compile Cargo locally and give a patch a spin? I think the change would go around here and would look like this line except use contains("msvc") instead

@snf
Copy link
Contributor Author

snf commented Sep 20, 2019

Thanks so much Alex! I will try as soon as I have a few cycles and report back.

@snf
Copy link
Contributor Author

snf commented Sep 21, 2019

Just tried it and it seems to get rid of the hash indeed:

0:000> !lmi heap_oob_simple
Loaded Module Info: [heap_oob_simple] 
         Module: heap_oob_simple
   Base Address: 00007ff6b8bc0000
     Image Name: heap_oob_simple.exe
   Machine Type: 34404 (X64)
     Time Stamp: 5d857e8b Fri Sep 20 18:36:11 2019
           Size: 26000
       CheckSum: 0
Characteristics: 22  
Debug Data Dirs: Type  Size     VA  Pointer
             CODEVIEW    66, 1de2c,   1c82c RSDS - GUID: {A044E1E7-FBDC-40A9-BAD5-0A22A92F5A13}
               Age: 1, Pdb: C:\Users\sefernan\projects\rust_crash\target\release\deps\heap_oob_simple.pdb
           VC_FEATURE    14, 1de94,   1c894 [Data not mapped]
                 POGO   2fc, 1dea8,   1c8a8 [Data not mapped]
     Image Type: FILE     - Image read successfully from debugger.
                 C:\Users\xxx\projects\rust_crash\target\release\heap_oob_simple.exe
    Symbol Type: PDB      - Symbols loaded successfully from image path.
                 C:\Users\xxx\projects\rust_crash\target\release\heap_oob_simple.pdb
       Compiler: MASM - front end [1.36 bld 0] - back end [8000.0 bld 0]
    Load Report: private symbols & lines, not source indexed 
                 C:\Users\xxx\projects\rust_crash\target\release\heap_oob_simple.pdb

I'm submitting a PR but let me know if there is anything else that I should check before we can merge this.

@alexcrichton
Copy link
Member

Great! Thanks for testing this out, I'll go check out the PR and we can take it from there.

bors added a commit that referenced this issue Oct 2, 2019
Removing hash from output files when using MSVC

This is the fix for #7358 suggested by @alexcrichton . Tested and working.

I see a few tests failling but seem unrelated. I'll investigate them tomorrow.
@snf
Copy link
Contributor Author

snf commented Oct 2, 2019

Thanks so much for your help Alex! Closing the issue.

@snf snf closed this as completed Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` O-windows OS: Windows
Projects
None yet
Development

No branches or pull requests

3 participants