Skip to content

Commit 2f35586

Browse files
committed
reuse existing codeId -> debugId conversion instead of adding a new converter
1 parent e3b33bd commit 2f35586

File tree

6 files changed

+105
-161
lines changed

6 files changed

+105
-161
lines changed

sentry-android-core/src/main/java/io/sentry/android/core/internal/threaddump/ThreadDumpParser.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@
2222
import io.sentry.SentryLockReason;
2323
import io.sentry.SentryOptions;
2424
import io.sentry.SentryStackTraceFactory;
25+
import io.sentry.android.core.internal.util.NativeEventUtils;
2526
import io.sentry.protocol.DebugImage;
2627
import io.sentry.protocol.SentryStackFrame;
2728
import io.sentry.protocol.SentryStackTrace;
2829
import io.sentry.protocol.SentryThread;
29-
import java.math.BigInteger;
30-
import java.nio.BufferUnderflowException;
31-
import java.nio.ByteBuffer;
32-
import java.nio.ByteOrder;
3330
import java.util.ArrayList;
3431
import java.util.Collections;
3532
import java.util.HashMap;
@@ -130,25 +127,6 @@ public List<SentryThread> getThreads() {
130127
return threads;
131128
}
132129

133-
@Nullable
134-
private static String buildIdToDebugId(final @NotNull String buildId) {
135-
try {
136-
// Abuse BigInteger as a hex string parser. Extra byte needed to handle leading zeros.
137-
final ByteBuffer buf = ByteBuffer.wrap(new BigInteger("10" + buildId, 16).toByteArray());
138-
buf.get();
139-
return String.format(
140-
"%08x-%04x-%04x-%04x-%04x%08x",
141-
buf.order(ByteOrder.LITTLE_ENDIAN).getInt(),
142-
buf.getShort(),
143-
buf.getShort(),
144-
buf.order(ByteOrder.BIG_ENDIAN).getShort(),
145-
buf.getShort(),
146-
buf.getInt());
147-
} catch (NumberFormatException | BufferUnderflowException e) {
148-
return null;
149-
}
150-
}
151-
152130
public void parse(final @NotNull Lines lines) {
153131

154132
final Matcher beginManagedThreadRe = BEGIN_MANAGED_THREAD_RE.matcher("");
@@ -279,7 +257,7 @@ private SentryStackTrace parseStacktrace(
279257
frame.setPlatform("native");
280258

281259
final String buildId = nativeRe.group(8);
282-
final String debugId = buildId == null ? null : buildIdToDebugId(buildId);
260+
final String debugId = buildId == null ? null : NativeEventUtils.buildIdToDebugId(buildId);
283261
if (debugId != null) {
284262
if (!debugImages.containsKey(debugId)) {
285263
final DebugImage debugImage = new DebugImage();

sentry-android-core/src/main/java/io/sentry/android/core/internal/tombstone/OleGuidFormatter.java

Lines changed: 0 additions & 89 deletions
This file was deleted.

sentry-android-core/src/main/java/io/sentry/android/core/internal/tombstone/TombstoneParser.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import androidx.annotation.NonNull;
44
import io.sentry.SentryEvent;
55
import io.sentry.SentryLevel;
6+
import io.sentry.android.core.internal.util.NativeEventUtils;
67
import io.sentry.protocol.DebugImage;
78
import io.sentry.protocol.DebugMeta;
89
import io.sentry.protocol.Mechanism;
@@ -196,9 +197,13 @@ private DebugMeta createDebugMeta(@NonNull final TombstoneProtos.Tombstone tombs
196197
continue;
197198
}
198199
final DebugImage image = new DebugImage();
199-
image.setCodeId(module.getBuildId());
200+
final String codeId = module.getBuildId();
201+
image.setCodeId(codeId);
200202
image.setCodeFile(module.getMappingName());
201-
image.setDebugId(OleGuidFormatter.convert(module.getBuildId()));
203+
204+
final String debugId = NativeEventUtils.buildIdToDebugId(codeId);
205+
image.setDebugId(debugId != null ? debugId : codeId);
206+
202207
image.setImageAddr(formatHex(module.getBeginAddress()));
203208
image.setImageSize(module.getEndAddress() - module.getBeginAddress());
204209
image.setType("elf");
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.sentry.android.core.internal.util;
2+
3+
import java.math.BigInteger;
4+
import java.nio.BufferUnderflowException;
5+
import java.nio.ByteBuffer;
6+
import java.nio.ByteOrder;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.jetbrains.annotations.Nullable;
9+
10+
public class NativeEventUtils {
11+
@Nullable
12+
public static String buildIdToDebugId(final @NotNull String buildId) {
13+
try {
14+
// Abuse BigInteger as a hex string parser. Extra byte needed to handle leading zeros.
15+
final ByteBuffer buf = ByteBuffer.wrap(new BigInteger("10" + buildId, 16).toByteArray());
16+
buf.get();
17+
return String.format(
18+
"%08x-%04x-%04x-%04x-%04x%08x",
19+
buf.order(ByteOrder.LITTLE_ENDIAN).getInt(),
20+
buf.getShort(),
21+
buf.getShort(),
22+
buf.order(ByteOrder.BIG_ENDIAN).getShort(),
23+
buf.getShort(),
24+
buf.getInt());
25+
} catch (NumberFormatException | BufferUnderflowException e) {
26+
return null;
27+
}
28+
}
29+
}

sentry-android-core/src/test/java/io/sentry/android/core/internal/tombstone/OleGuidFormatterTest.kt

Lines changed: 0 additions & 46 deletions
This file was deleted.

sentry-android-core/src/test/java/io/sentry/android/core/internal/tombstone/TombstoneParserTest.kt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry.android.core.internal.tombstone
22

3+
import java.io.ByteArrayInputStream
34
import java.io.File
45
import kotlin.test.Test
56
import kotlin.test.assertEquals
@@ -108,4 +109,70 @@ class TombstoneParserTest {
108109
assert(image.imageSize!! > 0)
109110
}
110111
}
112+
113+
@Test
114+
fun `debugId falls back to codeId when OleGuidFormatter conversion fails`() {
115+
// Create a tombstone with a memory mapping that has an invalid buildId
116+
// (contains 'ZZ' which are not valid hex characters)
117+
val invalidBuildId = "ZZ00112233445566778899aabbccddeeff00112233"
118+
val validBuildId = "f1c3bcc0279865fe3058404b2831d9e64135386c"
119+
120+
val tombstone =
121+
TombstoneProtos.Tombstone.newBuilder()
122+
.setPid(1234)
123+
.setTid(1234)
124+
.setSignalInfo(
125+
TombstoneProtos.Signal.newBuilder()
126+
.setNumber(11)
127+
.setName("SIGSEGV")
128+
.setCode(1)
129+
.setCodeName("SEGV_MAPERR")
130+
)
131+
.addMemoryMappings(
132+
TombstoneProtos.MemoryMapping.newBuilder()
133+
.setBuildId(invalidBuildId)
134+
.setMappingName("/system/lib64/libc.so")
135+
.setBeginAddress(0x7000000000)
136+
.setEndAddress(0x7000001000)
137+
.setExecute(true)
138+
)
139+
.addMemoryMappings(
140+
TombstoneProtos.MemoryMapping.newBuilder()
141+
.setBuildId(validBuildId)
142+
.setMappingName("/system/lib64/libm.so")
143+
.setBeginAddress(0x7000002000)
144+
.setEndAddress(0x7000003000)
145+
.setExecute(true)
146+
)
147+
.putThreads(
148+
1234,
149+
TombstoneProtos.Thread.newBuilder()
150+
.setId(1234)
151+
.setName("main")
152+
.addCurrentBacktrace(
153+
TombstoneProtos.BacktraceFrame.newBuilder()
154+
.setPc(0x7000000100)
155+
.setFunctionName("crash")
156+
.setFileName("/system/lib64/libc.so")
157+
)
158+
.build(),
159+
)
160+
.build()
161+
162+
val parser = TombstoneParser(ByteArrayInputStream(tombstone.toByteArray()))
163+
val event = parser.parse()
164+
165+
val images = event.debugMeta!!.images!!
166+
assertEquals(2, images.size)
167+
168+
// First image has invalid buildId - debugId should fall back to codeId
169+
val invalidImage = images.find { it.codeFile == "/system/lib64/libc.so" }!!
170+
assertEquals(invalidBuildId, invalidImage.codeId)
171+
assertEquals(invalidBuildId, invalidImage.debugId)
172+
173+
// Second image has valid buildId - debugId should be converted
174+
val validImage = images.find { it.codeFile == "/system/lib64/libm.so" }!!
175+
assertEquals(validBuildId, validImage.codeId)
176+
assertEquals("c0bcc3f1-9827-fe65-3058-404b2831d9e6", validImage.debugId)
177+
}
111178
}

0 commit comments

Comments
 (0)