309

Why does Visual Studio 2005 generate the .pdb files when compiling in release? I won't be debugging a release build, so why are they generated?

niico
  • 11,206
  • 23
  • 78
  • 161
m.edmondson
  • 30,382
  • 27
  • 123
  • 206
  • 23
    Why generate pdb in realease? So when a crash report comes in from the wild you have information to debug it. The other value is that customers can debug it when the original author won't. – Ian Boyd Feb 12 '12 at 18:14
  • @IanBoyd: The second sentence of that comment implies, that you deploy the PDB's. This is in the vast majority of cases not desirable. – IInspectable Jun 09 '17 at 11:52
  • 3
    @IInspectable Or [is desirable](https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/microsoft-public-symbols) – Ian Boyd Jun 09 '17 at 21:03
  • @IanBoyd: The vast majority of cases does not include OS deployments. Besides, those PDB's do not contain private symbols, which are included by default, when you generate PDB's. – IInspectable Jun 09 '17 at 21:12
  • @IInspectable On the other hand, releasing PBDs *is* desirable. Ideally, yes, everyone would write code compiled to IL, so that we can get symbol information ourselves. But native code compilers still have no easy way to support debugging in the field. – Ian Boyd Jun 10 '17 at 15:28
  • 1
    @IanBoyd: *"But native code compilers still have no easy way to support debugging in the field."* - Incidentally, they do. Pull a [minidump](https://msdn.microsoft.com/en-us/library/windows/desktop/ms680360.aspx), either as part of WER or at an arbitrary time using Task Manager, for example, and have the vendor analyze it. This does not require shipping PDB's. See [Crash Dump Analysis](https://msdn.microsoft.com/en-us/library/windows/desktop/ee416349.aspx) for information. – IInspectable Jun 10 '17 at 15:43

9 Answers9

471

Because without the PDB files, it would be impossible to debug a "Release" build by anything other than address-level debugging. Optimizations really do a number on your code, making it very difficult to find the culprit if something goes wrong (say, an exception is thrown). Even setting breakpoints is extremely difficult, because lines of source code cannot be matched up one-to-one with (or even in the same order as) the generated assembly code. PDB files help you and the debugger out, making post-mortem debugging significantly easier.

You make the point that if your software is ready for release, you should have done all your debugging by then. While that's certainly true, there are a couple of important points to keep in mind:

  1. You should also test and debug your application (before you release it) using the "Release" build. That's because turning optimizations on (they are disabled by default under the "Debug" configuration) can sometimes cause subtle bugs to appear that you wouldn't otherwise catch. When you're doing this debugging, you'll want the PDB symbols.

  2. Customers frequently report edge cases and bugs that only crop up under "ideal" conditions. These are things that are almost impossible to reproduce in the lab because they rely on some whacky configuration of that user's machine. If they're particularly helpful customers, they'll report the exception that was thrown and provide you with a stack trace. Or they'll even let you borrow their machine to debug your software remotely. In either of those cases, you'll want the PDB files to assist you.

  3. Profiling should always be done on "Release" builds with optimizations enabled. And once again, the PDB files come in handy, because they allow the assembly instructions being profiled to be mapped back to the source code that you actually wrote.

You can't go back and generate the PDB files after the compile.* If you don't create them during the build, you've lost your opportunity. It doesn't hurt anything to create them. If you don't want to distribute them, you can simply omit them from your binaries. But if you later decide you want them, you're out of luck. Better to always generate them and archive a copy, just in case you ever need them.

If you really want to turn them off, that's always an option. In your project's Properties window, set the "Debug Info" option to "none" for any configuration you want to change.

Do note, however, that the "Debug" and "Release" configurations do by default use different settings for emitting debug information. You will want to keep this setting. The "Debug Info" option is set to "full" for a Debug build, which means that in addition to a PDB file, debugging symbol information is embedded into the assembly. You also get symbols that support cool features like edit-and-continue. In Release mode, the "pdb-only" option is selected, which, like it sounds, includes only the PDB file, without affecting the content of the assembly. So it's not quite as simple as the mere presence or absence of PDB files in your /bin directory. But assuming you use the "pdb-only" option, the PDB file's presence will in no way affect the run-time performance of your code.

* As Marc Sherman points out in a comment, as long as your source code has not changed (or you can retrieve the original code from a version-control system), you can rebuild it and generate a matching PDB file. At least, usually. This works well most of the time, but the compiler is not guaranteed to generate identical binaries each time you compile the same code, so there may be subtle differences. Worse, if you have made any upgrades to your toolchain in the meantime (like applying a service pack for Visual Studio), the PDBs are even less likely to match. To guarantee the reliable generation of ex postfacto PDB files, you would need to archive not only the source code in your version-control system, but also the binaries for your entire build toolchain to ensure that you could precisely recreate the configuration of your build environment. It goes without saying that it is much easier to simply create and archive the PDB files.

Community
  • 1
  • 1
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • 23
    "You can't generate the PDB files after the compile." - If your source code hasn't changed then you can rebuild to generate a usable PDB after the fact. By default, windbg won't load this PDB but you can force it to load by specifying the /i option like this `.reload /i foo.dll`. That will load foo.pdb even if foo.pdb was created after releasing foo.dll. – Marc Sherman Nov 29 '12 at 14:20
  • 1
    I noticed that each new compile has different hash digest, so there are slight variances with each build even in the same environment. Could the addresses for the PDBs not change with variance, hence the need to keep the PDB from that build? Just putting this out as an idea since I don't really understand how PDBs work or why the hashes change between builds. – thebunnyrules Jan 31 '17 at 23:27
  • 3
    @the In the footnote, I linked to [an article](https://ericlippert.com/2012/05/31/past-performance-is-no-guarantee-of-future-results/) explaining that *"the C# compiler by design never produces the same binary twice. The C# compiler embeds a freshly generated GUID in every assembly, every time you run it, thereby ensuring that no two assemblies are ever bit-for-bit identical."* That explains why it has a different hash, and therefore a different PDB file. This is fixable with a hex editor, but not user-friendly. And also outside of this answer's scope. – Cody Gray - on strike Feb 01 '17 at 05:19
  • 7
    There is a new feature in Roslyn called deterministic builds. "The /deterministic flag causes the compiler to emit the exact same EXE / DLL, byte for byte, when given the same inputs." What this means is a project origionally compiled with this flag, can be recompiled to the exact same binary, as long as the code you are compiling is the same. A longer explanation can be found at [Deterministic builds in Roslyn](http://blog.paranoidcoding.com/2016/04/05/deterministic-builds-in-roslyn.html) – K Smith May 19 '17 at 14:34
  • I have never found the release version of the pdbs to be useful in any way – Mike Cheel Mar 04 '22 at 22:41
105

PDB can be generated for Release as well as for Debug. This is set at (in VS2010 but in VS2005 must be similar):

Project → Properties → Build → Advanced → Debug Info

Just change it to None.

Ajay2707
  • 5,690
  • 6
  • 40
  • 58
Aliostad
  • 80,612
  • 21
  • 160
  • 208
  • 2
    But why would you do that? If your software is ready for release then you should've done all your debugging by then – m.edmondson Mar 28 '11 at 09:40
  • 5
    Because you can debug the production issues. Once we had to do it. – Aliostad Mar 28 '11 at 09:44
  • 1
    How do you do this? Is there some kind of tool that lets you remotely debug? – m.edmondson Mar 28 '11 at 09:45
  • 29
    Advantage of heading PDBs for production code is that .NET will use these files when throwing exceptions. It generates stack traces with file names and line numbers, which is often very handy! – Steven Mar 28 '11 at 09:47
  • 1
    So if I don't have them on the server, there won't be any stack trace or exception info? – m.edmondson Mar 28 '11 at 09:50
  • 7
    @m.edmondson: Yes, that's correct. You'll still be informed what the thrown exception *was* (like `FileNotFoundException`), but you won't be able to see a stack trace. That makes it very difficult to pin down exactly which *line* of code caused the exception to be thrown. – Cody Gray - on strike Mar 29 '11 at 03:10
  • 2
    @m.edmondson Just to add if you are looking for a tool to remotely debug one of the issues in your production boxes then windows SDK comes with a very famous tool called WinDbg which supports remote debugging. Please have a look at the below mentioned link. Hope this helps! http://msdn.microsoft.com/en-in/library/windows/hardware/hh451173(v=vs.85).aspx – RBT Jan 15 '15 at 00:17
  • The logging you use to capture production exceptions would benefit from having info re stack trace, line numbers etc. – Resource Jan 26 '16 at 12:31
  • 2
    @Steven: Thank you so much. I have been struggling for days about why my testing servers do not include line numbers in stack traces while the same code in dev produces exceptions with stack traces having line numbers and file names! That explains it! – Punit Vora Feb 24 '16 at 23:00
  • 1
    Many comment here are just misleading. You will be able to see full stack trace with method names from metadata. Unless you obfuscate it, the only difference with/without .pdb files is existence of source file names and line numbers in the stacktrace. – TOP KEK May 17 '19 at 21:12
7

Without the .pdb files it is virtually imposible to step through the production code; you have to rely on other tools which can be costly and time consuming. I understand you can use tracing or windbg for instance but it really depends on what you want to achieve. In certain scenarios you just want to step through the remote code (no errors or exceptions) using the production data to observe particular behaviour, and this is where .pdb files come handy. Without them running the debugger on that code is impossible.

user1714880
  • 79
  • 1
  • 1
7

Why are you so sure you will not debug release builds? Sometimes (hopefully rarely but happens) you may get a defect report from a customer that is not reproducible in the debug version for some reason (different timings, small different behaviour or whatever). If that issue appears to be reproducible in the release build you'll be happy to have the matching pdb.

jdehaan
  • 19,700
  • 6
  • 57
  • 97
  • 5
    @m.edmondson Get access to the remote machine using RDP, Webex, etc. and install windbg there. Set up your symbols path and bam, you're golden! – Marc Sherman Nov 29 '12 at 14:14
  • A link to a more detailed guide would have been more helpful. This one-line how-to might lead people (like myself) on the wrong track. Most .NET devs will know nothing about Windbg for example. – marknuzz Sep 12 '14 at 18:54
  • 1
    @m.edmondson - Some editions of Visual Studio have the ability to perform remote debugging. From the debug menu you "attach to process" on the remote machine. – Matthew Nov 08 '14 at 16:01
  • Is it such a good idea to remote debug a production application instance? Won't it break parallel execution of threads and force them to run in serial while debugging? – Kaveh Hadjari Feb 04 '16 at 10:07
4

Also, you can utilize crash dumps to debug your software. The customer sends it to you and then you can use it to identify the exact version of your source - and Visual Studio will even pull the right set of debugging symbols (and source if you're set up correctly) using the crash dump. See Microsoft's documentation on Symbol Stores.

Tudor Berariu
  • 4,910
  • 2
  • 18
  • 29
rlranft
  • 162
  • 1
  • 1
  • 12
2

.PDB file is the short name of "Program Database". It contains the information about debug point for debugger and resources which are used or reference. Its generated when we build as debug mode. Its allow to application to debug at runtime.

The size is increase of .PDB file in debug mode. It is used when we are testing our application.

Good article of pdb file.

http://www.codeproject.com/Articles/37456/How-To-Inspect-the-Content-of-a-Program-Database-P

Ajay2707
  • 5,690
  • 6
  • 40
  • 58
  • 1
    "No need of this file when release or deploy" except when someone experiences a crash in that released version, and the crash report you get from them doesn't contain a usable stack trace... then you'll wish you included it after all. – Nyerguds Jan 02 '17 at 10:44
  • Not true. Without .pdb files you will get full stacktrace, but without source files names. You can recover it in-house after receiving crash report. If you cares about your intellectual rights and obfuscate sources, you have to save .pdb files but not to deploy them. – TOP KEK May 17 '19 at 21:08
1

In a multi-project solution, you usually want to have one configuration that generates no PDB or XML files at all. Instead of changing the Debug Info property of every project to none, I thought it would be more expedient to add a post-build event that only works in a specific configuration.

Unfortunately, Visual Studio doesn't allow you to specify different post-build events for different configurations. So I decided to do this manually, by editing the csproj file of the startup project and adding the following (instead of any existing PostBuildEvent tag):

  <PropertyGroup Condition="'$(Configuration)' == 'Publish'">
    <PostBuildEvent>
        del *.pdb
        del *.xml
    </PostBuildEvent>
  </PropertyGroup>

Unfortunately, this will make the post build event textbox blank and putting anything in it can have unpredictable results.

GregRos
  • 8,667
  • 3
  • 37
  • 63
1

Debug symbols (.pdb) and XML doc (.xml) files make up a large percentage of the total size and should not be part of the regular deployment package. But it should be possible to access them in case they are needed.

One possible approach: at the end of the TFS build process, move them to a separate artifact.

0

Actually without PDB files and symbolic information they have it would be impossible to create a successful crash report (memory dump files) and Microsoft would not have the complete picture what caused the problem.

And so having PDB improves crash reporting.

prosti
  • 42,291
  • 14
  • 186
  • 151
  • But what exactly will be missing without .pdb files? – TOP KEK May 17 '19 at 20:38
  • You can't generate the PDB files after the compile. So every version of the software major.minor[.build[.revision]] should have been saved at Microsoft in order to properly understand what happened, but this is not all. – prosti May 17 '19 at 20:42
  • The compiler is not guaranteed to generate identical binaries each time you compile the same code. – prosti May 17 '19 at 20:43
  • The question was what will be missing in crash reports and how crash reporting will be affected. .NET pdb files contain only private variable names and source files names. Everything else (methods names, signatures etc) will be in stacktrace from metadata info. – TOP KEK May 17 '19 at 20:55
  • No PDB files also contains non private data: https://github.com/microsoft/microsoft-pdb. – prosti May 17 '19 at 21:12
  • There are two types of crash dump files at least. – prosti May 17 '19 at 21:14
  • Private data like what? Can you provide a clear example? PDB is just a file format. The original question is about .net pdb files, not a format in general or C++ pdb. – TOP KEK May 17 '19 at 21:14
  • I provided you the link to the MS information about the format of PDB not the C++ pdb. Also please don't be crude. – prosti May 17 '19 at 21:15
  • I will ignore your further comments please investigate. – prosti May 17 '19 at 21:15
  • You're giving misleading comments related to C++ debugging. – TOP KEK May 17 '19 at 21:16
  • _Microsoft_ has no business looking into what crashes _my_ programs. The pdbs are useful for crash reports sent to _me_. This has nothing to do with Microsoft. – Nyerguds Jul 25 '19 at 06:50