From 84a14a2f061d8ed31671f8ad9604b5f67ad38080 Mon Sep 17 00:00:00 2001 From: Richard Elms Date: Tue, 23 May 2023 11:51:02 +0200 Subject: [PATCH 1/6] initial fix --- src/BugsnagUnity/Payload/StackTraceLine.cs | 18 ++++++++++++++++-- .../StackFrameParsingTests.cs | 11 +++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/BugsnagUnity/Payload/StackTraceLine.cs b/src/BugsnagUnity/Payload/StackTraceLine.cs index 76a3fe4c6..3d1ade6b4 100644 --- a/src/BugsnagUnity/Payload/StackTraceLine.cs +++ b/src/BugsnagUnity/Payload/StackTraceLine.cs @@ -43,11 +43,12 @@ 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', ' '); + frame.Method = frame.Method.Remove(0, 3); } frames.Add(frame); } @@ -77,11 +78,20 @@ 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+))?\)"); + public static StackTraceLine FromLogMessage(string message) { + + var wrapperMatch = new Regex(@"at \(wrapper \S+\)").Match(message); + if (wrapperMatch.Success) + { + message = message.Replace(wrapperMatch.Value, string.Empty); + } + Match match = StackTraceLineRegex.Match(message); + if (match.Success) - { + { int? lineNumber = null; int parsedValue; if (System.Int32.TryParse(match.Groups["linenumber"].Value, out parsedValue)) @@ -90,6 +100,10 @@ public static StackTraceLine FromLogMessage(string message) } string method = string.Join("", new string[]{match.Groups["method"].Value.Trim(), match.Groups["methodargs"].Value}); + if (wrapperMatch.Success) + { + method = wrapperMatch.Value + method; + } return new StackTraceLine(match.Groups["file"].Value, lineNumber, method); } diff --git a/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs b/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs index 30afb03f6..d55cea511 100644 --- a/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs +++ b/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs @@ -94,5 +94,16 @@ 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); + + } } } From de200e0d3912fa28a1494bffe7023d419641f94a Mon Sep 17 00:00:00 2001 From: Richard Elms Date: Tue, 23 May 2023 13:16:33 +0200 Subject: [PATCH 2/6] unit test fix --- CHANGELOG.md | 4 ++++ tests/BugsnagUnity.Tests/StackFrameParsingTests.cs | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 834d6ba6f..41b7d1e3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ ### 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) + +### Bug fixes + * 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/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs b/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs index d55cea511..5b711df8e 100644 --- a/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs +++ b/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs @@ -99,10 +99,10 @@ public void ParseGenericMethod() 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); + Assert.AreEqual("at (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); + stackframe = Payload.StackTraceLine.FromLogMessage("at (wrapper scoop-de-woop) SomeClass.SomeMethod(Program / Something else)"); + Assert.AreEqual("at (wrapper scoop-de-woop)SomeClass.SomeMethod(Program / Something else)", stackframe.Method); } } From a608a4339cbffb3e8f11f152d2f18aa7b97015e0 Mon Sep 17 00:00:00 2001 From: Richard Elms Date: Tue, 23 May 2023 15:02:49 +0200 Subject: [PATCH 3/6] typo --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41b7d1e3f..66ca78f80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,6 @@ * Fix an issue where stack frames containing (wrapper some/wrapper) entries were incorrectly formatted. [#713](https://github.com/bugsnag/bugsnag-unity/pull/713) -### Bug fixes - * Fix an issue where Config.GenerateAnonymousId was not respected. [#704](https://github.com/bugsnag/bugsnag-unity/pull/704) ## 7.5.2 (2023-03-08) From 022b5031570d891e26d4ddade2aa829df27c8b64 Mon Sep 17 00:00:00 2001 From: Richard Elms Date: Tue, 23 May 2023 16:16:35 +0200 Subject: [PATCH 4/6] simpler regex --- src/BugsnagUnity/Payload/StackTraceLine.cs | 20 ++----------------- .../StackFrameParsingTests.cs | 4 ++-- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/BugsnagUnity/Payload/StackTraceLine.cs b/src/BugsnagUnity/Payload/StackTraceLine.cs index 3d1ade6b4..098e6c55d 100644 --- a/src/BugsnagUnity/Payload/StackTraceLine.cs +++ b/src/BugsnagUnity/Payload/StackTraceLine.cs @@ -46,10 +46,6 @@ internal StackTrace(string stackTrace, StackTraceFormat format) if (frame != null) { - if (frame.Method.StartsWith("at ")) - { - frame.Method = frame.Method.Remove(0, 3); - } frames.Add(frame); } } @@ -75,21 +71,13 @@ 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 StackTraceLineRegex { get; } = new Regex(@"(?:at\s)?(?(?:\(.*\)\s)?[^()]+)(?\([^()]*?\))(?:\s(?:\[.*\]\s*in\s|\(at\s*\s*)(?.*):(?\d+))?"); private static Regex StackTraceAndroidJavaLineRegex { get; } = new Regex(@"^\s*(?[a-z][^()]+)\((?[^:]*)?(?::(?\d+))?\)"); public static StackTraceLine FromLogMessage(string message) - { - - var wrapperMatch = new Regex(@"at \(wrapper \S+\)").Match(message); - if (wrapperMatch.Success) - { - message = message.Replace(wrapperMatch.Value, string.Empty); - } - + { Match match = StackTraceLineRegex.Match(message); - if (match.Success) { int? lineNumber = null; @@ -100,10 +88,6 @@ public static StackTraceLine FromLogMessage(string message) } string method = string.Join("", new string[]{match.Groups["method"].Value.Trim(), match.Groups["methodargs"].Value}); - if (wrapperMatch.Success) - { - method = wrapperMatch.Value + method; - } return new StackTraceLine(match.Groups["file"].Value, lineNumber, method); } diff --git a/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs b/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs index 5b711df8e..8d950a722 100644 --- a/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs +++ b/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs @@ -99,10 +99,10 @@ public void ParseGenericMethod() public void ParseUnknownManagedToNative() { var stackframe = Payload.StackTraceLine.FromLogMessage("at (wrapper managed-to-native) Program.NativeMethod(Program/StructToMarshal)"); - Assert.AreEqual("at (wrapper managed-to-native)Program.NativeMethod(Program/StructToMarshal)", stackframe.Method); + 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("at (wrapper scoop-de-woop)SomeClass.SomeMethod(Program / Something else)", stackframe.Method); + Assert.AreEqual("(wrapper scoop-de-woop) SomeClass.SomeMethod(Program / Something else)", stackframe.Method); } } From 228a841f1b68b004ac6ff41e651155ac91f5278c Mon Sep 17 00:00:00 2001 From: Richard Elms Date: Tue, 23 May 2023 22:36:36 +0200 Subject: [PATCH 5/6] regex fix for beginning whitespace --- src/BugsnagUnity/Payload/StackTraceLine.cs | 6 +++--- tests/BugsnagUnity.Tests/StackFrameParsingTests.cs | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/BugsnagUnity/Payload/StackTraceLine.cs b/src/BugsnagUnity/Payload/StackTraceLine.cs index 098e6c55d..f717e87ea 100644 --- a/src/BugsnagUnity/Payload/StackTraceLine.cs +++ b/src/BugsnagUnity/Payload/StackTraceLine.cs @@ -71,15 +71,15 @@ IEnumerator IEnumerable.GetEnumerator() /// public class StackTraceLine : Dictionary, IStackframe { - private static Regex StackTraceLineRegex { get; } = new Regex(@"(?:at\s)?(?(?:\(.*\)\s)?[^()]+)(?\([^()]*?\))(?:\s(?:\[.*\]\s*in\s|\(at\s*\s*)(?.*):(?\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*(?[a-z][^()]+)\((?[^:]*)?(?::(?\d+))?\)"); public static StackTraceLine FromLogMessage(string message) - { + { Match match = StackTraceLineRegex.Match(message); if (match.Success) - { + { int? lineNumber = null; int parsedValue; if (System.Int32.TryParse(match.Groups["linenumber"].Value, out parsedValue)) diff --git a/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs b/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs index 8d950a722..5c04a65cf 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() { From 772babe477515be0605a0a8a59102041f5efc310 Mon Sep 17 00:00:00 2001 From: Richard Elms Date: Wed, 24 May 2023 09:11:22 +0200 Subject: [PATCH 6/6] android regex fix and unit test --- src/BugsnagUnity/Payload/StackTraceLine.cs | 2 +- tests/BugsnagUnity.Tests/StackFrameParsingTests.cs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/BugsnagUnity/Payload/StackTraceLine.cs b/src/BugsnagUnity/Payload/StackTraceLine.cs index f717e87ea..063da00c4 100644 --- a/src/BugsnagUnity/Payload/StackTraceLine.cs +++ b/src/BugsnagUnity/Payload/StackTraceLine.cs @@ -72,7 +72,7 @@ IEnumerator IEnumerable.GetEnumerator() public class StackTraceLine : Dictionary, IStackframe { 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*(?[a-z][^()]+)\((?[^:]*)?(?::(?\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 5c04a65cf..d016a6464 100644 --- a/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs +++ b/tests/BugsnagUnity.Tests/StackFrameParsingTests.cs @@ -115,5 +115,14 @@ public void ParseUnknownManagedToNative() 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); + } } }