Skip to content

Commit 9775a58

Browse files
jpbempeldevflow.devflow-routing-intake
andauthored
Fix Kotlin Debug source mapping (#11803)
Fix Kotlin Debug source mapping KotlinDebug stratum in SMAP is not always emitted if not present make one empty and avoid throwing exception fix unit tests Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent 9d8cd4e commit 9775a58

4 files changed

Lines changed: 21 additions & 14 deletions

File tree

‎dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/symbol/SourceRemapper.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static SourceRemapper getSourceRemapper(String sourceFile, SourceMap sourceMap)
2222
}
2323
StratumExt stratumDebug = sourceMap.getStratum("KotlinDebug");
2424
if (stratumDebug == null) {
25-
throw new IllegalArgumentException("No stratumDebug found for KotlinDebug");
25+
stratumDebug = new StratumExt("KotlinDebug");
2626
}
2727
return new KotlinSourceRemapper(stratumMain, stratumDebug);
2828
default:

‎dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/symbol/SourceRemapperTest.java‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ public void noKotlinDebug() {
3838
StratumExt stratumMainMock = mock(StratumExt.class);
3939
when(sourceMapMock.getStratum(eq("Kotlin"))).thenReturn(stratumMainMock);
4040
when(sourceMapMock.getStratum(eq("KotlinDebug"))).thenReturn(null);
41-
IllegalArgumentException illegalArgumentException =
42-
assertThrows(
43-
IllegalArgumentException.class,
44-
() -> SourceRemapper.getSourceRemapper("foo.kt", sourceMapMock));
45-
assertEquals("No stratumDebug found for KotlinDebug", illegalArgumentException.getMessage());
41+
SourceRemapper sourceRemapper = SourceRemapper.getSourceRemapper("foo.kt", sourceMapMock);
42+
assertNotNull(sourceRemapper);
4643
}
4744
}

‎dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/symbol/SymbolExtractionTransformerTest.java‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -995,13 +995,13 @@ public void symbolExtraction16() throws IOException, URISyntaxException {
995995
KotlinHelper.compileAndLoad(CLASS_NAME, resource.getFile(), filesToDelete);
996996
Object companion = Reflect.onClass(testClass).get("Companion");
997997
int result = Reflect.on(companion).call("main", "").get();
998-
assertEquals(48, result);
998+
assertEquals(73, result);
999999
} finally {
10001000
filesToDelete.forEach(File::delete);
10011001
}
1002-
assertEquals(2, symbolSinkMock.jarScopes.size());
1002+
assertEquals(4, symbolSinkMock.jarScopes.size());
10031003
Scope classScope = symbolSinkMock.jarScopes.get(0).getScopes().get(0);
1004-
assertScope(classScope, ScopeType.CLASS, CLASS_NAME, 6, 23, SOURCE_FILE, 5, 1);
1004+
assertScope(classScope, ScopeType.CLASS, CLASS_NAME, 6, 28, SOURCE_FILE, 6, 1);
10051005
assertLangSpecifics(
10061006
classScope.getLanguageSpecifics(),
10071007
asList("public", "final"),
@@ -1026,12 +1026,15 @@ public void symbolExtraction16() throws IOException, URISyntaxException {
10261026
Scope f3MethodScope = classScope.getScopes().get(3);
10271027
assertScope(f3MethodScope, ScopeType.METHOD, "f3", 21, 23, SOURCE_FILE, 1, 1);
10281028
assertLineRanges(f3MethodScope, "21-23");
1029+
Scope f4MethodScope = classScope.getScopes().get(4);
1030+
assertScope(f4MethodScope, ScopeType.METHOD, "f4", 27, 28, SOURCE_FILE, 1, 1);
1031+
assertLineRanges(f4MethodScope, "27-28");
10291032
assertScope(
1030-
classScope.getScopes().get(4), ScopeType.METHOD, "<clinit>", 0, 0, SOURCE_FILE, 0, 0);
1033+
classScope.getScopes().get(5), ScopeType.METHOD, "<clinit>", 0, 0, SOURCE_FILE, 0, 0);
10311034

10321035
Scope companionClassScope = symbolSinkMock.jarScopes.get(1).getScopes().get(0);
10331036
assertScope(
1034-
companionClassScope, ScopeType.CLASS, CLASS_NAME + "$Companion", 28, 29, SOURCE_FILE, 3, 0);
1037+
companionClassScope, ScopeType.CLASS, CLASS_NAME + "$Companion", 33, 34, SOURCE_FILE, 3, 0);
10351038
assertLangSpecifics(
10361039
classScope.getLanguageSpecifics(),
10371040
asList("public", "final"),
@@ -1049,8 +1052,8 @@ public void symbolExtraction16() throws IOException, URISyntaxException {
10491052
0,
10501053
0);
10511054
Scope mainMethodScope = companionClassScope.getScopes().get(1);
1052-
assertScope(mainMethodScope, ScopeType.METHOD, "main", 28, 29, SOURCE_FILE, 1, 1);
1053-
assertLineRanges(mainMethodScope, "28-29");
1055+
assertScope(mainMethodScope, ScopeType.METHOD, "main", 33, 34, SOURCE_FILE, 1, 1);
1056+
assertLineRanges(mainMethodScope, "33-34");
10541057
}
10551058

10561059
@Test

‎dd-java-agent/agent-debugger/src/test/resources/com/datadog/debugger/symboltest/SymbolExtraction16.kt‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@ class SymbolExtraction16 {
2323
return value
2424
}
2525

26+
fun f4(value: Int): Int {
27+
val set = setOf(Person("john", "doe"), Person("agent", "smith"))
28+
return set.groupingBy { it.firstName }.eachCount().toMutableMap().size
29+
}
30+
2631
companion object {
2732
fun main(arg: String): Int {
2833
val c = SymbolExtraction16()
29-
return c.f1(31) + c.f2(17)
34+
return c.f1(31) + c.f2(17) + c.f3(23) + c.f4(0)
3035
}
3136
}
3237
}
38+
39+
data class Person(val firstName: String, val lastName: String)

0 commit comments

Comments
 (0)