Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

### Bug fixes

* Fix an issue where stack frames containing (wrapper some/wrapper) entries were incorrectly formatted. [#713](https://github.com/bugsnag/bugsnag-unity/pull/713)

* Fix an issue where Config.GenerateAnonymousId was not respected. [#704](https://github.com/bugsnag/bugsnag-unity/pull/704)

## 7.5.2 (2023-03-08)
Expand Down
10 changes: 4 additions & 6 deletions src/BugsnagUnity/Payload/StackTraceLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ internal StackTrace(string stackTrace, StackTraceFormat format)
var frame = format == StackTraceFormat.AndroidJava
? StackTraceLine.FromAndroidJavaMessage(lines[i])
: StackTraceLine.FromLogMessage(lines[i]);

if (frame != null)
{
if (frame.Method.StartsWith("at "))
{
frame.Method = frame.Method.TrimStart('a', 't', ' ');
}
frames.Add(frame);
}
}
Expand All @@ -74,8 +71,9 @@ IEnumerator IEnumerable.GetEnumerator()
/// </summary>
public class StackTraceLine : Dictionary<string, object>, IStackframe
{
private static Regex StackTraceLineRegex { get; } = new Regex(@"(?<method>[^()]+)(?<methodargs>\([^()]*?\))(?:\s(?:\[.*\]\s*in\s|\(at\s*\s*)(?<file>.*):(?<linenumber>\d+))?");
private static Regex StackTraceAndroidJavaLineRegex { get; } = new Regex(@"^\s*(?<method>[a-z][^()]+)\((?<file>[^:]*)?(?::(?<linenumber>\d+))?\)");
private static Regex StackTraceLineRegex { get; } = new Regex(@"(?:\s*at\s)?(?<method>(?:\(.*\)\s)?[^()]+)(?<methodargs>\([^()]*?\))(?:\s(?:\[.*\]\s*in\s|\(at\s*\s*)(?<file>.*):(?<linenumber>\d+))?");
private static Regex StackTraceAndroidJavaLineRegex { get; } = new Regex(@"^\s*(?:at\s)?(?<method>[a-z][^()]+)\((?<file>[^:]*)?(?::(?<linenumber>\d+))?\)");


public static StackTraceLine FromLogMessage(string message)
{
Expand Down
30 changes: 30 additions & 0 deletions tests/BugsnagUnity.Tests/StackFrameParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ namespace BugsnagUnity.Payload.Tests
[TestFixture]
class StackFrameParsingTests
{

[Test]
public void ParseMethodWithAt()
{
var stackframe = Payload.StackTraceLine.FromLogMessage(
"at UnityEngine.Events.InvokableCall.Invoke () [0x00010] in /Users/bokken/build/output/unity/unity/Runtime/Export/UnityEvent/UnityEvent.cs:178"
);
Assert.AreEqual("UnityEngine.Events.InvokableCall.Invoke()", stackframe.Method);
}

[Test]
public void ParseMethodNameWithColon()
{
Expand Down Expand Up @@ -94,5 +104,25 @@ public void ParseGenericMethod()
Assert.AreEqual(null, stackframe.LineNumber);
Assert.AreEqual(null, stackframe.File);
}

[Test]
public void ParseUnknownManagedToNative()
{
var stackframe = Payload.StackTraceLine.FromLogMessage("at (wrapper managed-to-native) Program.NativeMethod(Program/StructToMarshal)");
Assert.AreEqual("(wrapper managed-to-native) Program.NativeMethod(Program/StructToMarshal)", stackframe.Method);

stackframe = Payload.StackTraceLine.FromLogMessage("at (wrapper scoop-de-woop) SomeClass.SomeMethod(Program / Something else)");
Assert.AreEqual("(wrapper scoop-de-woop) SomeClass.SomeMethod(Program / Something else)", stackframe.Method);

}

[Test]
public void ParseAndroidMethod()
{
var stackframe = Payload.StackTraceLine.FromAndroidJavaMessage("at com.example.lib.BugsnagCrash.throwJvmException(BugsnagCrash.java:14)");
Assert.AreEqual("com.example.lib.BugsnagCrash.throwJvmException()", stackframe.Method);
Assert.AreEqual("BugsnagCrash.java",stackframe.File);
Assert.AreEqual(14, stackframe.LineNumber);
}
}
}