【问题标题】:Eclipse: set breakpoint with JDIDebugModelEclipse:使用 JDIDebugModel 设置断点
【发布时间】:2016-11-04 12:46:40
【问题描述】:

我正在尝试在我的 Eclipse 插件中以编程方式设置断点。它似乎工作正常;标记被添加到编辑器侧边栏中,并且断点条目也被添加到断点视图中。但是当我调试程序时,VM 不会在断点处挂起。此外,如果我在调用 getNormalFlowFunction 之前暂停 VM,然后尝试进入 该方法,VM突然恢复运行,直到程序结束。不幸的是,没有错误消息。 我认为,我的参数有问题,但是从我找到的文档和示例代码中,我无法判断出了什么问题。有什么想法吗?

这是我设置断点的方式

IJavaMethodBreakpoint breakpoint = JDIDebugModel.createMethodBreakpoint(resource, className, methodName, methodSignature, entry, exit, nativeOnly, lineNumber, charStart, charEnd, hitCount, register, attrs);

我使用这些参数值:

resource: L/code/src/code/Main.java class: Main method: getNormalFlowFunction signature: (QString;)QString; resource: L/code/src/code/Main.java entry: true exit: false nativeOnly: false line: 12 charStart: 248 charEnd: 405 hit count: 0 register: true attrs: {}

目标类如下所示:

package code;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello World");
        System.out.println("Bla");
        String outSet = getNormalFlowFunction("Hallo");
        System.out.println(outSet);
        anotherMethod();
    }

    public static String getNormalFlowFunction(String inSet) {
        System.out.println("getNormalFlowFunction");
        String outSet = inSet + inSet;
        return outSet;
    }

    public static void anotherMethod() {
        System.out.println("Another method");
    }
}

编辑: 我还注意到,当我在启动调试器之前手动设置断点时,手动设置的断点会得到小复选标记,但我以编程方式设置的断点没有。

【问题讨论】:

    标签: java eclipse breakpoints programmatically


    【解决方案1】:

    事实证明,我的参数有几个问题。我不得不调试到 JDT 来找出参数的样子

    1. class 必须是完全限定名
    2. 需要解析签名。我从 ToggleBreakpointAdapter 复制代码
    3. chartStart 和 charEnd 必须指向方法名称。 charStart指向getNormalFlowFunction的g,charEnd指向n后面的g

    以下是更新后的参数列表: resource: L/code/src/code/Main.java class: code.Main method: getNormalFlowFunction signature: (Ljava/lang/String;)Ljava/lang/String; resource: L/code/src/code/Main.java entry: true exit: true nativeOnly: false line: 12 charStart: 269 charEnd: 290 hit count: 0 register: true attrs: null

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-14
      • 2015-12-28
      • 1970-01-01
      • 2014-10-12
      • 2010-10-08
      • 2011-05-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多