Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #166 from marcomorain/feature-demangle-private
Browse files Browse the repository at this point in the history
Demangle Anonymous Function Names
  • Loading branch information
asbjornu authored Nov 1, 2016
2 parents 8f1a69d + 87bff7b commit 2913aa1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/app/SharpRaven/Data/ExceptionFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public ExceptionFrame(StackFrame frame)
LineNumber = lineNo;
ColumnNumber = frame.GetFileColumnNumber();
InApp = !IsSystemModuleName(Module);
DemangleFunctionName();
DemangleAsyncFunctionName();
DemangleAnonymousFunction();
}


Expand Down Expand Up @@ -244,7 +245,7 @@ private static bool IsSystemModuleName(string moduleName)
/// names that appears in the Sentry UI will match the function and module
/// names in the original source-code.
/// </para>
private void DemangleFunctionName()
private void DemangleAsyncFunctionName()
{
if (Module == null || Function != "MoveNext")
{
Expand All @@ -266,5 +267,30 @@ private void DemangleFunctionName()
Function = match.Groups[2].Value;
}
}

/// <summary>
/// Clean up function names for anonymous lambda calls.
/// </summary>
private void DemangleAnonymousFunction()
{
if (Function == null)
{
return;
}

// Search for the function name in angle brackets followed by b__<digits/letters>.
//
// Change:
// <BeginInvokeAsynchronousActionMethod>b__36
// to:
// BeginInvokeAsynchronousActionMethod { <lambda> }

var mangled = @"^<(\w*)>b__\w+$";
var match = Regex.Match(Function, mangled);
if (match.Success && match.Groups.Count == 2)
{
Function = match.Groups[1].Value + " { <lambda> }";
}
}
}
}
11 changes: 11 additions & 0 deletions src/tests/SharpRaven.UnitTests/Data/ExceptionFrameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,16 @@ public void Constructor_Demangles_Function_Names()
Assert.AreEqual(frame.Function, "EditVrByJson");
Assert.AreEqual(frame.Module, "Flipdish.Domain.DomainModel.Services.RestaurantService");
}

[Test]
public void Contructor_Demangles_Lambdas()
{
var module = "Example.Module";

Assert.AreEqual("BeginInvokeAsynchronousActionMethod { <lambda> }", MockStackFrame(module, "<BeginInvokeAsynchronousActionMethod>b__36").Function);
Assert.AreEqual("InvokeActionMethodFilterAsynchronouslyRecursive { <lambda> }", MockStackFrame(module, "<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d").Function);
Assert.AreEqual("BeginInvokeAction { <lambda> }", MockStackFrame(module, "<BeginInvokeAction>b__1e").Function);

}
}
}

0 comments on commit 2913aa1

Please sign in to comment.