How the CLR locates pdb symbol files

2020-06-03 07:50发布

问题:

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?

回答1:

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");
    }
}


回答2:

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