getsentry/sentry-cocoa

CreateStacktrace helper method

philipphofmann opened this issue · 3 comments

Description

Write a helper method that creates a SentryStacktrace by passing in a list of raw stack memory addresses similar to what native offers with sentry_value_new_stacktrace, so that users can build their own events with their custom stacktraces. This can be reused for #741.

This came up here #741 (comment):

Being able to attach a custom stack trace to events would be quite useful for some type of errors. In my project we're using Chromium's zombie detector to detect some security and stability issues. When a zombie access is detected we get a breadcrumb containing an array of stack address indicating where the dealloc happened. Being able to symbolize this stack trace and add it to the event would be incredibly useful as it'd give us crash reports that clearly indicate where an object has been dealloc'd and where it is being accessed.

We do something similar when creating converting the MetricKit payloads to SentryFrames in our SentryMetricKitIntegration:

- (SentryStacktrace *)convertMXFramesToSentryStacktrace:(NSEnumerator<SentryMXFrame *> *)mxFrames
{
NSMutableArray<SentryFrame *> *frames = [NSMutableArray array];
for (SentryMXFrame *mxFrame in mxFrames) {
SentryFrame *frame = [[SentryFrame alloc] init];
frame.package = mxFrame.binaryName;
frame.inApp = @([self.inAppLogic isInApp:mxFrame.binaryName]);
frame.instructionAddress = sentry_formatHexAddressUInt64(mxFrame.address);
uint64_t imageAddress = mxFrame.address - mxFrame.offsetIntoBinaryTextSegment;
frame.imageAddress = sentry_formatHexAddressUInt64(imageAddress);
[frames addObject:frame];
}
SentryStacktrace *stacktrace = [[SentryStacktrace alloc] initWithFrames:frames registers:@{}];
return stacktrace;
}

We also need to ensure that the correct debug meta data is attached.

Any rough ETA for this ? No pressure but I'm trying to decide whether or not I should implement a temporary solution for now, I'm blocked by this for some bug investigations. I could probably figure out how to do this based on the instructions provided above, just want to make sure that we're not both doing the same work in parallel! I'm just slightly concerned that I'm not familiar enough with the Sentry codebase to provide a "clean" implementation of this.

I'm sorry we can't give you an ETA on this, as we don't see a high demand for this at the moment.

No worries! In this case I'll implement a temporary solution myself, I'll share it here (or via a PR) if it's not too ugly 😅 .