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

Demangle Anonymous Function Names #166

Merged
merged 1 commit into from
Nov 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

}
}
}