diff --git a/CHANGELOG.md b/CHANGELOG.md index 834d6ba6f..66ca78f80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/BugsnagUnity/Payload/StackTraceLine.cs b/src/BugsnagUnity/Payload/StackTraceLine.cs index 76a3fe4c6..063da00c4 100644 --- a/src/BugsnagUnity/Payload/StackTraceLine.cs +++ b/src/BugsnagUnity/Payload/StackTraceLine.cs @@ -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); } } @@ -74,8 +71,9 @@ IEnumerator IEnumerable.GetEnumerator() /// public class StackTraceLine : Dictionary, IStackframe { - private static Regex StackTraceLineRegex { get; } = new Regex(@"(?[^()]+)(?\([^()]*?\))(?:\s(?:\[.*\]\s*in\s|\(at\s*\s*)(?.*):(?\d+))?"); - private static Regex StackTraceAndroidJavaLineRegex { get; } = new Regex(@"^\s*(?[a-z][^()]+)\((?[^:]*)?(?::(?\d+))?\)"); + private static Regex StackTraceLineRegex { get; } = new Regex(@"(?:\s*at\s)?(?(?:\(.*\)\s)?[^()]+)(?\([^()]*?\))(?:\s(?:\[.*\]\s*in\s|\(at\s*\s*)(?.*):(?\d+))?"); + private static Regex StackTraceAndroidJavaLineRegex { get; } = new Regex(@"^\s*(?:at\s)?(?[a-z][^()]+)\((?[^:]*)?(?::(?\d+))?\)"); + public static StackTraceLine FromLogMessage(string message) { diff --git a/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs b/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs index 30afb03f6..d016a6464 100644 --- a/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs +++ b/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs @@ -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() { @@ -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); + } } }