简体   繁体   English

Eclipse:使用JDIDebugModel设置断点

[英]Eclipse: set breakpoint with JDIDebugModel

I'm trying to set a breakpoint programmatically in my Eclipse plug-in. 我正在尝试以编程方式在Eclipse插件中设置断点。 It seems to work fine; 似乎工作正常; the marker is added to the editor sidebar and a breakboint entry is also added to the Breakpoints view. 标记将添加到编辑器侧栏,并且Breakboint条目也将添加到Breakpoints视图。 But when I debug the program, the VM does not suspend at the breakpoint. 但是,当我调试程序时,VM不会在断点处挂起。 Furthermore, if I suspend the VM before the call to getNormalFlowFunction and then try to step into the method, the VM suddenly resumes and runs until the end of the program. 此外,如果我在调用getNormalFlowFunction之前挂起VM,然后尝试进入该方法,则VM会突然恢复并运行,直到程序结束。 Unfortunately, there is no error message. 不幸的是,没有错误消息。 I assume, that something is wrong with my parameters, but from the documentation and sample code I found, I can not tell, what's going wrong. 我以为我的参数有问题,但是从我发现的文档和示例代码中,我不知道出了什么问题。 Any ideas? 有任何想法吗?

Here is how I'm setting the breakpoint 这是我设置断点的方式

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

I use these parameter values: 我使用以下参数值:

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: {}

The target class looks like this: 目标类如下所示:

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");
    }
}

Edit : I also noticed, that when I set a breakpoint manually before launching the debugger, the manually set breakpoint gets the little checkmark, but my programmatically set breakpoint does not. 编辑 :我还注意到,当我在启动调试器之前手动设置一个断点时,手动设置的断点会出现一个小勾号,但是我以编程方式设置的断点却没有。

Turns out, there were several problems with my parameters. 原来,我的参数有几个问题。 I had to debug into JDT to find out, how the parameters have to look like 我必须调试到JDT中才能找出参数的外观

  1. class has to be the fully qualified name 类必须是完全限定名称
  2. signature needs to be resolved. 签名需要解决。 I copied code from ToggleBreakpointAdapter 我从ToggleBreakpointAdapter复制了代码
  3. chartStart and charEnd have to point to the method name. chartStart和charEnd必须指向方法名称。 charStart points to the g of getNormalFlowFunction and charEnd points behind the n charStart指向getNormalFlowFunction的g,而charEnd指向n的后面

Here is an updated list of the parameters: 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 这是参数的更新列表: 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 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM