Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public class DebuggerTransformer implements ClassFileTransformer {
private static final Logger LOGGER = LoggerFactory.getLogger(DebuggerTransformer.class);
private static final String CANNOT_FIND_METHOD = "Cannot find method %s::%s%s";
private static final String INSTRUMENTATION_FAILS = "Instrumentation failed for %s: %s";
private static final String CANNOT_FIND_LINE = "No executable code was found at %s:L%s";
private static final Pattern COMMA_PATTERN = Pattern.compile(",");
private static final List<Class<?>> PROBE_ORDER =
Arrays.asList(
Expand Down Expand Up @@ -258,7 +257,7 @@ public byte[] transform(
if (instrumentTheWorld) {
return transformTheWorld(loader, classFilePath, protectionDomain, classfileBuffer);
}
if (skipInstrumentation(loader, classFilePath)) {
if (skipInstrumentation(classFilePath)) {
return null;
}
List<ProbeDefinition> definitions = Collections.emptyList();
Expand Down Expand Up @@ -375,7 +374,7 @@ private boolean checkRecordTypeAnnotation(
return true;
}

private boolean skipInstrumentation(ClassLoader loader, String classFilePath) {
private boolean skipInstrumentation(String classFilePath) {
if (definitionMatcher.isEmpty()) {
LOGGER.debug("No debugger definitions present.");
return true;
Expand Down Expand Up @@ -892,7 +891,6 @@ private static ProbeDefinition selectReferenceDefinition(
LogProbe.Capture capture = null;
boolean captureSnapshot = false;
ProbeCondition probeCondition = null;
List<LogProbe.CaptureExpression> captureExpressions = null;
Where where = capturedContextProbes.get(0).getWhere();
ProbeId probeId = capturedContextProbes.get(0).getProbeId();
for (ProbeDefinition definition : capturedContextProbes) {
Expand All @@ -904,8 +902,6 @@ private static ProbeDefinition selectReferenceDefinition(
LogProbe logProbe = (LogProbe) definition;
captureSnapshot = captureSnapshot | logProbe.isCaptureSnapshot();
capture = mergeCapture(capture, logProbe.getCapture());
// captureExpressions = mergeCaptureExpressions(captureExpressions,
// logProbe.getCaptureExpressions());
if (probeCondition == null) {
probeCondition = logProbe.getProbeCondition();
}
Expand Down Expand Up @@ -951,19 +947,6 @@ private static LogProbe.Capture mergeCapture(
Math.max(current.getMaxFieldCount(), newCapture.getMaxFieldCount()));
}

private static List<LogProbe.CaptureExpression> mergeCaptureExpressions(
List<LogProbe.CaptureExpression> captureExpressions,
List<LogProbe.CaptureExpression> newCaptureExpressions) {
if (captureExpressions == null) {
return newCaptureExpressions;
}
if (newCaptureExpressions == null) {
return captureExpressions;
}
captureExpressions.addAll(newCaptureExpressions);
return captureExpressions;
}

private InstrumentationResult.Status preCheckInstrumentation(
Map<ProbeId, List<DiagnosticMessage>> diagnostics, MethodInfo methodInfo) {
if ((methodInfo.getMethodNode().access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) != 0) {
Expand Down Expand Up @@ -1002,43 +985,6 @@ private static void addDiagnosticForAllProbes(
diagnostics.forEach((probeId, diagnosticMessages) -> diagnosticMessages.add(diagnosticMessage));
}

private List<MethodNode> matchMethodDescription(
ClassNode classNode, Where where, ClassFileLines classFileLines) {
List<MethodNode> result = new ArrayList<>();
try {
for (MethodNode methodNode : classNode.methods) {
if (where.isMethodMatching(methodNode, classFileLines) == Where.MethodMatching.MATCH) {
result.add(methodNode);
}
}
} catch (Exception ex) {
LOGGER.warn("Cannot match method: {}", ex.toString());
}
return result;
}

private MethodNode matchSourceFile(
ClassNode classNode, Where where, ClassFileLines classFileLines) {
Where.SourceLine[] lines = where.getSourceLines();
if (lines == null || lines.length == 0) {
return null;
}
Where.SourceLine sourceLine = lines[0]; // assume only 1 range
int matchingLine = sourceLine.getFrom();
List<MethodNode> matchingMethods = classFileLines.getMethodsByLine(matchingLine);
if (matchingMethods != null) {
matchingMethods.forEach(
methodNode -> {
LOGGER.debug("Found lineNode {} method: {}", matchingLine, methodNode.name);
});
// pick the first matching method.
// TODO need a way to disambiguate if multiple methods match the same line
return matchingMethods.isEmpty() ? null : matchingMethods.get(0);
}
LOGGER.debug("Cannot find line: {} in class {}", matchingLine, classNode.name);
return null;
}

private void dumpInstrumentedClassFile(String className, byte[] data) {
if (config.isDynamicInstrumentationClassFileDumpEnabled()) {
LOGGER.debug("Generated bytecode len: {}", data.length);
Expand Down Expand Up @@ -1125,7 +1071,7 @@ protected String getCommonSuperClass(String type1, String type2) {
try {
TypeDescription td1 = tpDatadogClassLoader.describe(type1.replace('/', '.')).resolve();
TypeDescription td2 = tpDatadogClassLoader.describe(type2.replace('/', '.')).resolve();
TypeDescription common = null;
TypeDescription common;
if (td1.isAssignableFrom(td2)) {
common = td1;
} else if (td2.isAssignableFrom(td1)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -60,6 +61,7 @@ private void populateDefinitionFileNamesMap(Collection<ProbeDefinition> definiti
continue;
}
fileName = normalizeWindowsToUnixPath(fileName);
fileName = fileName.toLowerCase(Locale.ROOT);
Map<String, List<ProbeDefinition>> targetMap =
fileName.indexOf('/') != -1
? definitionsByQualifiedFileNames
Expand Down Expand Up @@ -139,6 +141,7 @@ private List<ProbeDefinition> matchProbeDefinitionsBySourceFile(
sb.append(reversedPackageName);
}
String reversedFileName = sb.toString();
reversedFileName = reversedFileName.toLowerCase(Locale.ROOT);
List<ProbeDefinition> bySourceFileDefinitions = new ArrayList<>();
// try match qualified filenames
Collection<String> matchingFileNames =
Expand All @@ -153,6 +156,7 @@ private List<ProbeDefinition> matchProbeDefinitionsBySourceFile(
}
}
// try match simple filenames
sourceFileName = sourceFileName.toLowerCase(Locale.ROOT);
List<ProbeDefinition> definitions = definitionsBySimpleFileNames.get("/" + sourceFileName);
if (definitions != null) {
bySourceFileDefinitions.addAll(definitions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ public void sourceFileFullFileName() {
assertEquals(PROBE_ID1, probeDefinitions.get(0).getProbeId());
}

@Test
public void sourceFileFullFileNameCaseInsensitive() {
LogProbe probe = createProbe(PROBE_ID1, "Src/Main/Java/Java/LanG/STRING.jAvA", 23);
TransformerDefinitionMatcher matcher = createMatcher(probe);
List<ProbeDefinition> probeDefinitions = match(matcher, String.class);
assertEquals(1, probeDefinitions.size());
assertEquals(PROBE_ID1, probeDefinitions.get(0).getProbeId());
}

@Test
public void sourceFileAbsoluteFileName() {
LogProbe probe =
Expand Down Expand Up @@ -103,6 +112,15 @@ public void sourceFileSimpleFileName() {
assertEquals(PROBE_ID1, probeDefinitions.get(0).getProbeId());
}

@Test
public void sourceFileSimpleFileNameCaseInsensitive() {
LogProbe probe = createProbe(PROBE_ID1, "sTRINg.JAVA", 23);
TransformerDefinitionMatcher matcher = createMatcher(probe);
List<ProbeDefinition> probeDefinitions = match(matcher, String.class);
assertEquals(1, probeDefinitions.size());
assertEquals(PROBE_ID1, probeDefinitions.get(0).getProbeId());
}

@Test
public void multiProbesFQN() {
LogProbe probe1 = createProbe(PROBE_ID1, "java.lang.String", "indexOf");
Expand Down
Loading