Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug symbols in release mode

On an ASP.NET 2.0 website I log details of unhandled exceptions. I would like to log the source filename and line number, but I don't get this in the stack trace when an exception occurs. The reason for this is that I have debug="false" in the web.config compilation settings (it's a production site), therefore no PDB files are being generated on the server. Is there a way to get ASP.NET to generate the debug symbol files in release mode? I don't want to precompile the site.

like image 343
noj Avatar asked Nov 12 '09 00:11

noj


People also ask

Can we debug code in release mode?

You can debug in Release mode to an extent. Debug and Release are simply build configurations (of which you can create many), the real difference is that Debug configuration doesn't optimize the generated binary code (optimized code complicates debugging). It also generates additional debug data which release does not.

What is release debug?

Release vs Debug Essentially, they're just 2 separate configurations of the compiler. and it depends on what language you are using, Debug includes debugging information in the compiled files (allowing easy debugging) while Release usually has optimizations enabled.

What is the difference between debug and release mode?

By default, Debug includes debug information in the compiled files (allowing easy debugging) while Release usually has optimizations enabled. As far as conditional compilation goes, they each define different symbols that can be checked in your program, but they are language-specific macros.

How do you know if a debug symbol is present?

To check if there's debug info inside the kernel object, you can add the following at the end of the objdump command: | grep debug . If this string is found, you know the kernel object contains debug information. If not, then it's a "clean" kernel object.


2 Answers

OK, I found an answer. You can set debug="false" to get optimisations, and then set compilerOptions="/debug:pdbonly" in the system.codedom compiler settings to get symbols. Here's the relevant web.config excerpts:

<system.web>
  ....
  <compilation debug="false" defaultLanguage="c#">
  ...
  </compilation>
</system.web>
<system.codedom>
  <compilers>
    <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
        type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        compilerOptions="/debug:pdbonly">
      <providerOption name="CompilerVersion" value="v3.5"/>
      <providerOption name="WarnAsError" value="false"/>
    </compiler>
    ...
  </compilers>
</system.codedom>
like image 152
noj Avatar answered Oct 17 '22 08:10

noj


Unless Im missing something the difference between debug & release build are in the optimizations. You should be able to create a normal debug binary with pdb and make sure to enable all the optimization settings in the project settings. Afaik unless theres an exception the pdb file wount be loaded, etc...

like image 23
Alexandre Gomes Avatar answered Oct 17 '22 07:10

Alexandre Gomes