How can I get the function name when navigating symbols? #116

Closed
opened 2012-10-31 11:30:03 -05:00 by ghost · 1 comment
ghost commented 2012-10-31 11:30:03 -05:00 (Migrated from github.com)

Consider this C# pseudo-code:

public static void Main()
{
  Console.WriteLine();
}

I want to browse the assembly and discover where is the line containing the function "header" (i.e. the name, in my case - "Main"). Currently, I can get the method instructions and from them get the line which generates the first IL instruction. In my case this is the "Console.WriteLine()" line. Can I get to the header?
I know that it can span multiple lines, in this case, I would like to get to the starting line, if possible.

My current code looks like:

var metadataToken = new MetadataToken(functionMetadataToken);
var asm = AssemblyDefinition.ReadAssembly(assemblyFilepath, new ReaderParameters { ReadSymbols = true });
                var sp = (from modules in asm.Modules
                          from types in modules.Types
                          from method in types.Methods
                          where method.MetadataToken == metadataToken
                          select method.Body.Instructions)
                        .First().First().SequencePoint;

var line = sp.StartLine;

How can I improve it?

Consider this C# pseudo-code: ``` C# public static void Main() { Console.WriteLine(); } ``` I want to browse the assembly and discover where is the line containing the function "header" (i.e. the name, in my case - "Main"). Currently, I can get the method instructions and from them get the line which generates the first IL instruction. In my case this is the "Console.WriteLine()" line. Can I get to the header? I know that it can span multiple lines, in this case, I would like to get to the starting line, if possible. My current code looks like: ``` C# var metadataToken = new MetadataToken(functionMetadataToken); var asm = AssemblyDefinition.ReadAssembly(assemblyFilepath, new ReaderParameters { ReadSymbols = true }); var sp = (from modules in asm.Modules from types in modules.Types from method in types.Methods where method.MetadataToken == metadataToken select method.Body.Instructions) .First().First().SequencePoint; var line = sp.StartLine; ``` How can I improve it?
jbevain commented 2012-10-31 11:32:30 -05:00 (Migrated from github.com)

How is this a bug? Please use the appropriate channels to ask questions about Cecil.

How is this a bug? Please use the appropriate channels to ask questions about Cecil.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-jbevain/cecil#116
No description provided.