Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added instruction_addr_adjustment attribute #2151

Merged
merged 8 commits into from
Feb 8, 2023
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- Added `instruction_addr_adjustment` attribute to SentryStackTrace ([#2151](https://github.com/getsentry/sentry-dotnet/pull/2151))

### Fixes

- Workaround Visual Studio "Pair to Mac" issue (on Windows), and Update bundled Cocoa SDK to version 7.31.5 ([#2164](https://github.com/getsentry/sentry-dotnet/pull/2164))
Expand Down
59 changes: 58 additions & 1 deletion src/Sentry/SentryStackTrace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,35 @@

namespace Sentry;

/// <summary>
/// Instruction Address Adjustments
/// </summary>
public enum InstructionAddressAdjustment
{
/// <summary>
/// Symbolicator will use the `"all_but_first"` strategy **unless** the event has a crashing `signal`
/// attribute and the Stack Trace has a `registers` map, and the instruction pointer register (`rip` / `pc`)
/// does not match the first frame. In that case, `"all"` frames will be adjusted.
/// </summary>
Auto,

/// <summary>
/// All frames of the stack trace will be adjusted, subtracting one instruction with (or `1`) from the
/// incoming `instruction_addr` before symbolication.
/// </summary>
All,

/// <summary>
/// All frames but the first (in callee to caller / child to parent direction) should be adjusted.
/// </summary>
AllButFirst,

/// <summary>
/// No adjustment will be applied whatsoever.
/// </summary>
None
}

/// <summary>
/// Sentry Stacktrace interface.
/// </summary>
Expand All @@ -27,13 +56,35 @@ public IList<SentryStackFrame> Frames
set => InternalFrames = value;
}

/// <summary>
/// The optional instruction address adjustment.
/// </summary>
/// <remarks>
/// Tells the symbolicator if and what adjustment for is needed.
/// </remarks>
public InstructionAddressAdjustment? AddressAdjustment { get; set; }

/// <inheritdoc />
public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger)
{
writer.WriteStartObject();

writer.WriteArrayIfNotEmpty("frames", InternalFrames, logger);

if (AddressAdjustment is { } instructionAddressAdjustment)
{
var adjustmentType = instructionAddressAdjustment switch
{
InstructionAddressAdjustment.Auto => "auto",
InstructionAddressAdjustment.All => "all",
InstructionAddressAdjustment.AllButFirst => "all_but_first",
InstructionAddressAdjustment.None => "none",
_ => "auto"
};

writer.WriteString("instruction_addr_adjustment", adjustmentType);
}

writer.WriteEndObject();
}

Expand All @@ -48,9 +99,15 @@ public static SentryStackTrace FromJson(JsonElement json)
.Select(SentryStackFrame.FromJson)
.ToArray();

var instructionAddressAdjustment = json
.GetPropertyOrNull("instruction_addr_adjustment")
?.ToString()
?.ParseEnum<InstructionAddressAdjustment>();

return new SentryStackTrace
{
InternalFrames = frames
InternalFrames = frames,
AddressAdjustment = instructionAddressAdjustment
};
}
}
8 changes: 8 additions & 0 deletions test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ namespace Sentry
string Name { get; }
}
public interface ITransactionData : Sentry.IEventLike, Sentry.IHasBreadcrumbs, Sentry.IHasExtra, Sentry.IHasTags, Sentry.ISpanContext, Sentry.ISpanData, Sentry.ITransactionContext, Sentry.Protocol.ITraceContext { }
public enum InstructionAddressAdjustment
{
Auto = 0,
All = 1,
AllButFirst = 2,
None = 3,
}
public static class MeasurementExtensions
{
public static void SetMeasurement(this Sentry.ITransactionData transaction, string name, double value, Sentry.MeasurementUnit unit = default) { }
Expand Down Expand Up @@ -699,6 +706,7 @@ namespace Sentry
public class SentryStackTrace : Sentry.IJsonSerializable
{
public SentryStackTrace() { }
public Sentry.InstructionAddressAdjustment? AddressAdjustment { get; set; }
public System.Collections.Generic.IList<Sentry.SentryStackFrame> Frames { get; set; }
public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { }
public static Sentry.SentryStackTrace FromJson(System.Text.Json.JsonElement json) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ namespace Sentry
string Name { get; }
}
public interface ITransactionData : Sentry.IEventLike, Sentry.IHasBreadcrumbs, Sentry.IHasExtra, Sentry.IHasTags, Sentry.ISpanContext, Sentry.ISpanData, Sentry.ITransactionContext, Sentry.Protocol.ITraceContext { }
public enum InstructionAddressAdjustment
{
Auto = 0,
All = 1,
AllButFirst = 2,
None = 3,
}
public static class MeasurementExtensions
{
public static void SetMeasurement(this Sentry.ITransactionData transaction, string name, double value, Sentry.MeasurementUnit unit = default) { }
Expand Down Expand Up @@ -698,6 +705,7 @@ namespace Sentry
public class SentryStackTrace : Sentry.IJsonSerializable
{
public SentryStackTrace() { }
public Sentry.InstructionAddressAdjustment? AddressAdjustment { get; set; }
public System.Collections.Generic.IList<Sentry.SentryStackFrame> Frames { get; set; }
public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { }
public static Sentry.SentryStackTrace FromJson(System.Text.Json.JsonElement json) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ namespace Sentry
string Name { get; }
}
public interface ITransactionData : Sentry.IEventLike, Sentry.IHasBreadcrumbs, Sentry.IHasExtra, Sentry.IHasTags, Sentry.ISpanContext, Sentry.ISpanData, Sentry.ITransactionContext, Sentry.Protocol.ITraceContext { }
public enum InstructionAddressAdjustment
{
Auto = 0,
All = 1,
AllButFirst = 2,
None = 3,
}
public static class MeasurementExtensions
{
public static void SetMeasurement(this Sentry.ITransactionData transaction, string name, double value, Sentry.MeasurementUnit unit = default) { }
Expand Down Expand Up @@ -699,6 +706,7 @@ namespace Sentry
public class SentryStackTrace : Sentry.IJsonSerializable
{
public SentryStackTrace() { }
public Sentry.InstructionAddressAdjustment? AddressAdjustment { get; set; }
public System.Collections.Generic.IList<Sentry.SentryStackFrame> Frames { get; set; }
public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { }
public static Sentry.SentryStackTrace FromJson(System.Text.Json.JsonElement json) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ namespace Sentry
string Name { get; }
}
public interface ITransactionData : Sentry.IEventLike, Sentry.IHasBreadcrumbs, Sentry.IHasExtra, Sentry.IHasTags, Sentry.ISpanContext, Sentry.ISpanData, Sentry.ITransactionContext, Sentry.Protocol.ITraceContext { }
public enum InstructionAddressAdjustment
{
Auto = 0,
All = 1,
AllButFirst = 2,
None = 3,
}
public static class MeasurementExtensions
{
public static void SetMeasurement(this Sentry.ITransactionData transaction, string name, double value, Sentry.MeasurementUnit unit = default) { }
Expand Down Expand Up @@ -699,6 +706,7 @@ namespace Sentry
public class SentryStackTrace : Sentry.IJsonSerializable
{
public SentryStackTrace() { }
public Sentry.InstructionAddressAdjustment? AddressAdjustment { get; set; }
public System.Collections.Generic.IList<Sentry.SentryStackFrame> Frames { get; set; }
public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { }
public static Sentry.SentryStackTrace FromJson(System.Text.Json.JsonElement json) { }
Expand Down