我为非 gcp 环境设置了 google-cloud-debug。这是一个附加代理运行的示例代码。
import java.util.Random;
public class FooMain {
public static int SHARED_INT = 0;
public static void main(String[] args) throws Exception {
System.out.println("started");
Random random = new Random();
FooMain fooMain = new FooMain();
for (int i = 0; i < 10_000; i++) {
System.out.println("Coded message " + fooMain.m1(random.nextInt(100)));
SHARED_INT = random.nextInt(100); // <-- line# 13
Thread.sleep(1000);
}
}
private int m1(int num1) {
int num2 = num1 + 1;
int num3 = num2 + 1;
return m2(num2);
}
private int m2(int num1) {
int num3 = num1 + 1;
return m3(num3);
}
private int m3(int num1) {
int num4 = num1 + 1;
return m4(num4);
}
private int m4(int num1) {
int num5 = num1 + 1;
return m5(num5);
}
private int m5(int num1) {
int num6 = num1 + 1;
return num6;
}
}
我尝试使用此有效负载设置断点
"breakpoint": {
"id": "<some-id>",
"location": {
"path": "FooMain.java",
"line": 13
},
"expressions": [
"i"
],
"create_time": "2021-09-13T10:03:30.537Z",
"action": "LOG",
"log_message_format": "Message received, id = $0"
}
错误
I0913 09:59:24.572947 3128 jvm_breakpoint.cc:118] Line 13 in method main resolved to method ID: 0x7fe7b00013d8, location: 54
W0913 09:59:24.572988 3128 expression_util.cc:97] Expression could not be compiled
Input: i
AST: ( statement i )
Error message: ("Identifier $0 not found", "i")
I0913 09:59:24.573019 3128 jvm_breakpoint.cc:729] Activating breakpoint f0cec009-1f7a-4eec-88d5-6316634d87a0, path: FooMain.java, line: 13
I0913 09:59:24.573025 3128 jvm_breakpoints_manager.cc:295] Setting new JVMTI breakpoint, method = 0x7fe7b00013d8, location = 0x36
I0913 09:59:24.573696 3233 jni_logger.cc:31] transmitBreakpointUpdate format: json, breakpointId: f0cec009-1f7a-4eec-88d5-6316634d87a0, breakpoint: {"createTime":"2021-09-13T09:59:21.138Z","evaluatedExpressions":[{"name":"i","status":{"description":{"format":"Identifier $0 not found","parameters":["i"]},"isError":true,"refersTo":"VARIABLE_NAME"}}],"expressions":["i"],"id":"f0cec009-1f7a-4eec-88d5-6316634d87a0","location":{"line":13,"path":"FooMain.java"},"logMessageFormat":"Message received, id = $0"}
.
使用 Java 11(采用openjdk,11.0.11+9)。预期的行为是记录表达式。你能帮我理解这里有什么不正确吗?