Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How the CLR locates pdb symbol files

Tags:

c#

.net

symbols

clr

I would like to know how the CLR locates pdb symbol files, and if this behavior can be overridden.

I looked online (MSDN and other resources) but could not find a good answer.

In my app, i have DLLs placed in several subdirectories of the main .EXE path.

I would like to have a Symbols\ dir that will contain all symbols for my application. By default, i believe that symbols are picked up from where the assembly is. Can this be changed?

like image 870
lysergic-acid Avatar asked Jan 12 '12 12:01

lysergic-acid


People also ask

Where are PDB files located?

pdb file stores all debug information for the project's .exe file, and resides in the \debug subdirectory.

How are PDB files generated?

A PDB file is typically created from source files during compilation. It stores a list of all symbols in a module with their addresses and possibly the name of the file and the line on which the symbol was declared. This symbol information is not stored in the module itself, because it takes up a lot of space.

How do I read a PDB file?

Some PDB files are stored as plain text, like Geneious' Program Debug Database files, and are completely human-readable if opened in a text editor. You can open this kind of PDB file with any program that can read text documents, like the built-in Notepad program in Windows.

Why is there a PDB files in release folder?

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.


2 Answers

Look at this blog post if you havn't already:

http://blogs.msdn.com/b/rmbyers/archive/2007/06/21/customizing-pdb-lookup-for-source-information-in-stacktrace.aspx

like image 199
granaker Avatar answered Oct 26 '22 02:10

granaker


You could simply set the _NT_SYMBOL_PATH environment variable for your own process. This worked well:

using System;
using System.Runtime.CompilerServices;
using System.Reflection;
using System.IO;

class Program {
    static void Main(string[] args) {
        var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
        path = Path.Combine(path, "symbols");
        Environment.SetEnvironmentVariable("_NT_SYMBOL_PATH", path);
        try {
            Kaboom();
        }
        catch (Exception ex) {
            Console.WriteLine(ex.ToString());
        }
        Console.ReadLine();
    }
    [MethodImpl(MethodImplOptions.NoInlining)]
    static void Kaboom() {
        throw new Exception("test");
    }
}
like image 40
Hans Passant Avatar answered Oct 26 '22 03:10

Hans Passant