简体   繁体   English

编写自定义eclipse调试器

[英]Writing a custom eclipse debugger

EDIT: There must be some way I can approach this without writing a whole new debugger. 编辑:必须有一些方法可以在不编写全新调试器的情况下实现此目的。 I'm currently looking into ways to build on top of the existing java debugger. 我目前正在研究在现有java调试器之上构建的方法。 If anyone has any ideas on how to grab information the Java debugger already has (about stack frames, variables, raw data etc.), that would be really helpful. 如果有人对如何获取Java调试器已有的信息有任何想法(关于堆栈帧,变量,原始数据等),那将非常有用。

-- -

What I'm trying to do is I have this framework/API built on Java, and I would like to write an eclipse plugin debugger that is customized to my framework. 我想要做的是我有这个基于Java的框架/ API,我想编写一个为我的框架定制的eclipse插件调试器。 Here is a simple example: 这是一个简单的例子:

I have two classes, one called scope and one called variable. 我有两个类,一个叫做范围,一个叫做变量。 The scope holds a map of variables. 范围包含变量图。 The code is all in java, but I'm using this scope-variable relationship almost like a new language, and would like a variable debug tab that gives me a list of currently active scopes with the variables that are currently stored inside. 代码全部都在java中,但我使用这个范围变量关系几乎就像一种新语言,并且想要一个变量调试选项卡,它给出了当前活动范围的列表,其中包含当前存储的变量。 Here is some code: 这是一些代码:

import java.util.Hashtable;

public class Scope {
    private Hashtable<String, Variable> variableList = new Hashtable<String, Variable>();

   // constructor 
    public Scope(){

    }

    public void put(String key, Variable v){
        variableList.put(key, v);
    }

    public Variable get(String key){
        return variableList.get(key);
    }


}

public class Variable {

    private String value;
    private String name;

    public Variable(String aName, String aValue){
        name = aName;
        value = aValue;
    }

    public String getValue(){
        return value;
    }

    public String getName(){
        return name;
    }

    public void setValue(String aValue){
        value = aValue;
    }
}

This is obviously an extremely simple example, but I would like to accomplish something similar to this where I can get a variables window, set a breakpoint, and have a "debugger" list out my active scope objects and the variable objects inside. 这显然是一个非常简单的例子,但是我想完成类似的事情,我可以获得一个变量窗口,设置一个断点,并有一个“调试器”列出我的活动范围对象和里面的变量对象。

I've been trying to read and understand: http://www.eclipse.org/articles/Article-Debugger/how-to.html 我一直在努力阅读和理解: http//www.eclipse.org/articles/Article-Debugger/how-to.html

and its pretty dense (as well as extremely outdated), but I will try to take some time to understand it. 它非常密集(以及非常过时),但我会花一些时间来理解它。 I just wanted to see if anyone had any high level recommendations on how to approach this type of problem, as I have little experience developing plugins in eclipse or making debuggers. 我只是想看看是否有人有关于如何处理这类问题的任何高级建议,因为我没有经验在eclipse中开发插件或制作调试器。

Thanks! 谢谢!

Not an easy task. 这不是一件容易的事。 That article is still the main reference, I think. 我认为那篇文章仍然是主要的参考。 Old, but not outdated. 旧的,但不过时。 Try to digest it, and preferably to make it work. 尝试消化它,并最好使其工作。 Before it, you should have a minimal experience developing Eclipse plugins. 在此之前,您应该具有开发Eclipse插件的最小经验。

There are many pieces in the picture, but the first thing you must understand is that when Eclipse is debugging something (assuming we are using the standard debug model), we have two separate "worlds": the Eclipse side, and the interpreter side (or, if you prefer, the "local" and "remote" sides). 图中有很多部分,但您必须首先理解的是,当Eclipse调试某些东西时(假设我们使用的是标准调试模型),我们有两个独立的“世界”:Eclipse端和解释端(或者,如果您愿意,可以选择“本地”和“偏远”方面。

Int the Eclipse side, the programming involves a cooperation between some Eclipse core classes and some classes of your own, which extend or implement some Eclipse classes/interfaces: 在Eclipse方面,编程涉及一些Eclipse核心类与您自己的一些类之间的合作,这些类扩展或实现了一些Eclipse类/接口:

  • A " launchConfigurationType " (extension point in your plugin.xml) which causes the apparition of a new custom configuration when you click "Debug As -> New Configuration); this goes togetther with some " launchConfigurationTabGroups " definition that defines the "Tabs" dialogs that will appear in your custom launch configuration ( eg ) (each Tab will have its own class typically). A“launchConfigurationType”(在plugin.xml扩展点),这导致当你点击一个新的自定义配置的幽灵“调试方式- >新建配置);这正好togetther一些” launchConfigurationTabGroups“定义,定义了‘标签’对话这将出现在您的自定义启动配置中( 例如 )(每个Tab通常都有自己的类)。

  • The launchConfigurationType is typically associated to a LaunchDelegate class, which is sort of your bootstrap class: it has the responsability of creating and starting a running/debugging instance, both on the Eclipse side and on the "interpreter" (or "remote") side. launchConfigurationType通常与LaunchDelegate类相关联,该类是您的引导类:它具有创建和启动运行/调试实例的责任,在Eclipse端和“解释器”(或“远程”)端都是如此。

  • On the Eclipse side, the running/debugging instance is represented by a IDebugTarget object and its children (the implementation is your responsability); 在Eclipse端,运行/调试实例由IDebugTarget对象及其子对象表示(实现是您的责任); this is created by the LaunchDelegate and "attached" to the remotely running process at launching time. 这是由LaunchDelegate创建的,并在启动时“附加”到远程运行的进程。

  • The remote side, the interpreter or program you are actually debugging, can be anything: a binary executable, a perl script, some app running in a some site (perhaps also a local Java program; but, even in this case, this would probably run in its own JVM, not in the debugging Eclipse JVM!). 你正在调试的远程端,解释器或程序可以是任何东西:二进制可执行文件,perl脚本,某个站点中运行的某个应用程序(也许是本地Java程序;但是,即使在这种情况下,这可能是在自己的JVM中运行,而不是在调试Eclipse JVM中运行!)。 Your IDebugTarget object must know how to communicate to the "remote interpreter" (eg, by TCP) and perform the typical debugger tasks (place breakpoints, step, run, ask for variables, etc) - but the protocol here is up to you, it's entirely arbitrary. 您的IDebugTarget对象必须知道如何与“远程解释器”进行通信(例如,通过TCP)并执行典型的调试器任务(放置断点,步进,运行,询问变量等) - 但此处的协议取决于您,这完全是武断的。

  • What is not arbitrary is the hierarchy of your custom classes that the running Eclipse debugger will use: these should have a IDebugTarget as root, and should implement "The debug model" (see figure in article). 什么不是任意的是运行的Eclipse调试器将使用的自定义类的层次结构:这些应该具有作为root的IDebugTarget,并且应该实现“调试模型”(参见文章中的 )。 As said above, the IDebugTarget object is who understands how to make the translation between the EClipse side and the remote side (see this image ) 如上所述,IDebugTarget对象是谁了解如何在EClipse端和远程端之间进行转换(参见此图

having worked on the eclipse edc debugger, it sounds like writing a whole debugger is not so much what you want. 曾经在eclipse edc调试器上工作,听起来像编写一个完整的调试器并不是你想要的。

it sounds like while running the debugger, you will have access to the objects that have the variables and scopes you are interested in. 这听起来像在运行调试器时,您将可以访问具有您感兴趣的变量和范围的对象。

you can use toString() in the classes themselves or use detail formatters to display a variation on the information you want. 您可以在类本身中使用toString()或使用详细格式化程序来显示所需信息的变体。 the toString() call can get quite detailed and nest into calls, show whole arrays, etc. detail formatters can also be quite complex. toString()调用可以非常详细并嵌入调用,显示整个数组等。详细格式化程序也可能非常复杂。

see http://www.robertwloch.net/2012/01/eclipse-tips-tricks-detail-formatter/ . http://www.robertwloch.net/2012/01/eclipse-tips-tricks-detail-formatter/ it's the best of several URLs (i have no association with the author). 它是几个URL中最好的(我与作者没有关联)。

once you are happy with the output of the Variable and Scope objects, you should be able to add watch expressions that will always show them in your expressions window (thus you don't have to rely on local variables in the stack frame you may be in). 一旦您对Variable和Scope对象的输出感到满意,您应该能够添加将始终在表达式窗口中显示它们的监视表达式(因此您不必依赖堆栈框架中的局部变量)在)。

this should then give you the list of Variables and Scopes from your framework that you are tracking … hopefully without having to write an entire eclipse debugger plugin to do so. 然后,这应该为您提供正在跟踪的框架中的变量和范围列表...希望无需编写完整的eclipse调试器插件。

ok, i'm going to add a second answer here … i guess i'm not familiar enough with the state of your environment to know why custom detail formatters would not do the trick. 好吧,我要在这里添加第二个答案......我想我对你的环境状态不太熟悉,不知道为什么自定义细节格式化程序不能解决问题。 for most cases, i think they'll provide you what you're looking for. 在大多数情况下,我认为他们会为您提供您正在寻找的东西。

but if you're really interested in creating another view holding these items, then you could check out the eclipse jdt project . 但如果你真的有兴趣创建另一个持有这些项目的视图,那么你可以查看eclipse jdt项目 it's entirely possible that the extension points it provides will give you access to the internal variables and stack-frame information that you're looking to add, and also perhaps some UI that will make your job easier. 它提供的扩展点完全有可能让您访问您想要添加的内部变量和堆栈框架信息,也可能是一些可以使您的工作更轻松的UI。

in other words, you might not have to write an entirely new debugger plugin, but perhaps a plug-in that can work together with jdt. 换句话说,您可能不必编写一个全新的调试器插件,但可能是一个可以与jdt一起工作的插件。

the site has pointers to the project plan, source repositories, the bugzilla issue tracking database (used for both bug-tracking and new feature discussion). 该站点指向项目计划,源存储库,bugzilla问题跟踪数据库(用于错误跟踪和新功能讨论)。 perhaps some of those who are experts on jdt can help weigh in with their opinions about what will best suit your needs. 也许一些jdt专家可以帮助他们对最适合您需求的观点进行评估。

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

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