|
7 | 7 | import static com.datadog.debugger.util.MoshiSnapshotHelper.REDACTED_IDENT_REASON; |
8 | 8 | import static com.datadog.debugger.util.MoshiSnapshotHelper.REDACTED_TYPE_REASON; |
9 | 9 | import static com.datadog.debugger.util.MoshiSnapshotTestHelper.VALUE_ADAPTER; |
| 10 | +import static com.datadog.debugger.util.TestHelper.setFieldInConfig; |
10 | 11 | import static datadog.trace.bootstrap.debugger.util.Redaction.REDACTED_VALUE; |
11 | 12 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; |
@@ -238,14 +239,20 @@ public void oldClass1_1() throws Exception { |
238 | 239 |
|
239 | 240 | @Test |
240 | 241 | public void oldJavacBug() throws Exception { |
241 | | - final String CLASS_NAME = "com.datadog.debugger.classfiles.JavacBug"; // compiled with jdk 1.6 |
242 | | - TestSnapshotListener listener = installSingleProbe(CLASS_NAME, "main", null); |
243 | | - Class<?> testClass = Class.forName(CLASS_NAME); |
244 | | - assertNotNull(testClass); |
245 | | - int result = Reflect.onClass(testClass).call("main", "").get(); |
246 | | - assertEquals(45, result); |
247 | | - // with local var hoisting and initialization at the beginning of the method, issue is resolved |
248 | | - assertEquals(1, listener.snapshots.size()); |
| 242 | + setFieldInConfig(Config.get(), "debuggerHoistLocalVarsEnabled", true); |
| 243 | + try { |
| 244 | + final String CLASS_NAME = "com.datadog.debugger.classfiles.JavacBug"; // compiled with jdk 1.6 |
| 245 | + TestSnapshotListener listener = installSingleProbe(CLASS_NAME, "main", null); |
| 246 | + Class<?> testClass = Class.forName(CLASS_NAME); |
| 247 | + assertNotNull(testClass); |
| 248 | + int result = Reflect.onClass(testClass).call("main", "").get(); |
| 249 | + assertEquals(45, result); |
| 250 | + // with local var hoisting and initialization at the beginning of the method, issue is |
| 251 | + // resolved |
| 252 | + assertEquals(1, listener.snapshots.size()); |
| 253 | + } finally { |
| 254 | + setFieldInConfig(Config.get(), "debuggerHoistLocalVarsEnabled", false); |
| 255 | + } |
249 | 256 | } |
250 | 257 |
|
251 | 258 | @Test |
@@ -1801,32 +1808,39 @@ public void evaluateAtExitFalse() throws IOException, URISyntaxException { |
1801 | 1808 | value = "datadog.trace.api.Platform#isJ9", |
1802 | 1809 | disabledReason = "we cannot get local variable debug info") |
1803 | 1810 | public void uncaughtExceptionConditionLocalVar() throws IOException, URISyntaxException { |
1804 | | - final String CLASS_NAME = "CapturedSnapshot05"; |
1805 | | - LogProbe probe = |
1806 | | - createProbeBuilder(PROBE_ID, CLASS_NAME, "main", "(String)") |
1807 | | - .when( |
1808 | | - new ProbeCondition(DSL.when(DSL.ge(DSL.ref("after"), DSL.value(0))), "after >= 0")) |
1809 | | - .evaluateAt(MethodLocation.EXIT) |
1810 | | - .build(); |
1811 | | - TestSnapshotListener listener = installProbes(probe); |
1812 | | - Class<?> testClass = compileAndLoadClass(CLASS_NAME); |
| 1811 | + setFieldInConfig(Config.get(), "debuggerHoistLocalVarsEnabled", true); |
1813 | 1812 | try { |
1814 | | - Reflect.onClass(testClass).call("main", "triggerUncaughtException").get(); |
1815 | | - Assertions.fail("should not reach this code"); |
1816 | | - } catch (ReflectException ex) { |
1817 | | - assertEquals("oops", ex.getCause().getCause().getMessage()); |
| 1813 | + |
| 1814 | + final String CLASS_NAME = "CapturedSnapshot05"; |
| 1815 | + LogProbe probe = |
| 1816 | + createProbeBuilder(PROBE_ID, CLASS_NAME, "main", "(String)") |
| 1817 | + .when( |
| 1818 | + new ProbeCondition( |
| 1819 | + DSL.when(DSL.ge(DSL.ref("after"), DSL.value(0))), "after >= 0")) |
| 1820 | + .evaluateAt(MethodLocation.EXIT) |
| 1821 | + .build(); |
| 1822 | + TestSnapshotListener listener = installProbes(probe); |
| 1823 | + Class<?> testClass = compileAndLoadClass(CLASS_NAME); |
| 1824 | + try { |
| 1825 | + Reflect.onClass(testClass).call("main", "triggerUncaughtException").get(); |
| 1826 | + Assertions.fail("should not reach this code"); |
| 1827 | + } catch (ReflectException ex) { |
| 1828 | + assertEquals("oops", ex.getCause().getCause().getMessage()); |
| 1829 | + } |
| 1830 | + Snapshot snapshot = assertOneSnapshot(listener); |
| 1831 | + assertCaptureThrowable( |
| 1832 | + snapshot.getCaptures().getReturn(), |
| 1833 | + "CapturedSnapshot05$CustomException", |
| 1834 | + "oops", |
| 1835 | + "CapturedSnapshot05.triggerUncaughtException", |
| 1836 | + 8); |
| 1837 | + assertNull(snapshot.getEvaluationErrors()); |
| 1838 | + // after is 0 because the exception is thrown before the assignment and local var initialized |
| 1839 | + // at the beginning of the method by instrumentation |
| 1840 | + assertCaptureLocals(snapshot.getCaptures().getReturn(), "after", "long", "0"); |
| 1841 | + } finally { |
| 1842 | + setFieldInConfig(Config.get(), "debuggerHoistLocalVarsEnabled", false); |
1818 | 1843 | } |
1819 | | - Snapshot snapshot = assertOneSnapshot(listener); |
1820 | | - assertCaptureThrowable( |
1821 | | - snapshot.getCaptures().getReturn(), |
1822 | | - "CapturedSnapshot05$CustomException", |
1823 | | - "oops", |
1824 | | - "CapturedSnapshot05.triggerUncaughtException", |
1825 | | - 8); |
1826 | | - assertNull(snapshot.getEvaluationErrors()); |
1827 | | - // after is 0 because the exception is thrown before the assignment and local var initialized |
1828 | | - // at the beginning of the method by instrumentation |
1829 | | - assertCaptureLocals(snapshot.getCaptures().getReturn(), "after", "long", "0"); |
1830 | 1844 | } |
1831 | 1845 |
|
1832 | 1846 | @Test |
@@ -1858,15 +1872,20 @@ public void uncaughtExceptionCaptureLocalVars() throws IOException, URISyntaxExc |
1858 | 1872 | value = "datadog.trace.api.Platform#isJ9", |
1859 | 1873 | disabledReason = "we cannot get local variable debug info") |
1860 | 1874 | public void methodProbeLocalVarsLocalScopes() throws IOException, URISyntaxException { |
1861 | | - final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot31"; |
1862 | | - LogProbe probe = createProbeAtExit(PROBE_ID, CLASS_NAME, "localScopes", "(String)"); |
1863 | | - TestSnapshotListener listener = installProbes(probe); |
1864 | | - Class<?> testClass = compileAndLoadClass(CLASS_NAME); |
1865 | | - int result = Reflect.onClass(testClass).call("main", "localScopes").get(); |
1866 | | - assertEquals(42, result); |
1867 | | - Snapshot snapshot = assertOneSnapshot(listener); |
1868 | | - assertEquals(1, snapshot.getCaptures().getReturn().getLocals().size()); |
1869 | | - assertCaptureLocals(snapshot.getCaptures().getReturn(), "@return", "int", "42"); |
| 1875 | + setFieldInConfig(Config.get(), "debuggerHoistLocalVarsEnabled", true); |
| 1876 | + try { |
| 1877 | + final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot31"; |
| 1878 | + LogProbe probe = createProbeAtExit(PROBE_ID, CLASS_NAME, "localScopes", "(String)"); |
| 1879 | + TestSnapshotListener listener = installProbes(probe); |
| 1880 | + Class<?> testClass = compileAndLoadClass(CLASS_NAME); |
| 1881 | + int result = Reflect.onClass(testClass).call("main", "localScopes").get(); |
| 1882 | + assertEquals(42, result); |
| 1883 | + Snapshot snapshot = assertOneSnapshot(listener); |
| 1884 | + assertEquals(1, snapshot.getCaptures().getReturn().getLocals().size()); |
| 1885 | + assertCaptureLocals(snapshot.getCaptures().getReturn(), "@return", "int", "42"); |
| 1886 | + } finally { |
| 1887 | + setFieldInConfig(Config.get(), "debuggerHoistLocalVarsEnabled", false); |
| 1888 | + } |
1870 | 1889 | } |
1871 | 1890 |
|
1872 | 1891 | @Test |
@@ -1957,16 +1976,21 @@ public void overlappingLocalVarSlot() throws IOException, URISyntaxException { |
1957 | 1976 | value = "datadog.trace.api.Platform#isJ9", |
1958 | 1977 | disabledReason = "we cannot get local variable debug info") |
1959 | 1978 | public void duplicateLocalDifferentScope() throws IOException, URISyntaxException { |
1960 | | - final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot31"; |
1961 | | - LogProbe probe = |
1962 | | - createProbeAtExit(PROBE_ID, CLASS_NAME, "duplicateLocalDifferentScope", "(String)"); |
1963 | | - TestSnapshotListener listener = installProbes(probe); |
1964 | | - Class<?> testClass = compileAndLoadClass(CLASS_NAME); |
1965 | | - int result = Reflect.onClass(testClass).call("main", "duplicateLocalDifferentScope").get(); |
1966 | | - assertEquals(28, result); |
1967 | | - Snapshot snapshot = assertOneSnapshot(listener); |
1968 | | - assertCaptureLocals( |
1969 | | - snapshot.getCaptures().getReturn(), "ch", Character.TYPE.getTypeName(), "e"); |
| 1979 | + setFieldInConfig(Config.get(), "debuggerHoistLocalVarsEnabled", true); |
| 1980 | + try { |
| 1981 | + final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot31"; |
| 1982 | + LogProbe probe = |
| 1983 | + createProbeAtExit(PROBE_ID, CLASS_NAME, "duplicateLocalDifferentScope", "(String)"); |
| 1984 | + TestSnapshotListener listener = installProbes(probe); |
| 1985 | + Class<?> testClass = compileAndLoadClass(CLASS_NAME); |
| 1986 | + int result = Reflect.onClass(testClass).call("main", "duplicateLocalDifferentScope").get(); |
| 1987 | + assertEquals(28, result); |
| 1988 | + Snapshot snapshot = assertOneSnapshot(listener); |
| 1989 | + assertCaptureLocals( |
| 1990 | + snapshot.getCaptures().getReturn(), "ch", Character.TYPE.getTypeName(), "e"); |
| 1991 | + } finally { |
| 1992 | + setFieldInConfig(Config.get(), "debuggerHoistLocalVarsEnabled", false); |
| 1993 | + } |
1970 | 1994 | } |
1971 | 1995 |
|
1972 | 1996 | @Test |
|
0 commit comments