Welcome to MSDN Blogs Sign in | Join | Help

Finding the Source Code for an Assembly

Sometimes, especially when working on large projects (such as, I don't know, say ... the CLR), you find yourself debugging a problem where you don't know where a component is built from.  Depending on the problem, it might be useful to get to the sources of the assembly to help diagnose what the issue is (or to look up in the source control system who the owner of the code is so you can contact them).  I ran into this problem recently, and using the IronPython MDbg extension was able to whip up a quick method that will dump the path to the source files that make up an assembly that you have symbols for:

def ShowAssemblySources(assembly):
    for module in Shell.Debugger.Processes.Active.Modules:
        if module.CorModule.Assembly.Name.Contains(assembly):
            print module.CorModule.Name
            if module.SymReader != None:
                for document in module.SymReader.GetDocuments():
                    print "  %s" % document.URL
            else:
                print "  module does not have symbols, skipping"

Using this method is pretty straight forward:

[p#:0, t#:0] mdbg> ShowAssemblySources("caspol")
c:\WINDOWS\Microsoft.NET\Framework64\v2.0.AMD64chk\caspol.exe
  d:\vbl\lab21s\ndp\clr\src\ToolBox\caspol\obj1c\amd64\CommonResStrings.cspp
  d:\vbl\lab21s\ndp\clr\src\ToolBox\caspol\obj1c\amd64\CommonResStrings.cs
  d:\vbl\lab21s\ndp\clr\src\ToolBox\caspol\caspol.cs

It's definately not an every-day debugging tool, which again makes it nice that IronPython makes extending the MDbg command set so easy since I wouldn't have wanted to spend more than a few minutes working this code out.

Published Tuesday, November 22, 2005 1:31 PM by shawnfa
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Finding the Source Code for an Assembly

Wednesday, November 23, 2005 1:54 AM by Jonathan de Halleux
Reflector has had the search feature for ages. You should give it a shot.

# re: Finding the Source Code for an Assembly

Monday, November 28, 2005 12:23 PM by shawnfa
Reflector can tell you where the source files are? How do you access that feature in the Reflector UI?

-Shawn

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker