我想通过操作将调试器附加到某个进程 在我的
actionPerformed
代码中我有这个
XDebuggerManager.getInstance(project).startSessionAndShowTab(...)
问题是
startSessionAndShowTab
有4个重载,我不知道在哪里可以获取这些参数
XDebugSession startSessionAndShowTab(
@NotNull @Nls String sessionName,
Nullable RunContentDescriptor contentToReuse,
NotNull XDebugProcessStarter starter)
XDebugSession startSessionAndShowTab(
@NotNull @Nls String sessionName,
NotNull XDebugProcessStarter starter,
NotNull ExecutionEnvironment environment)
XDebugSession startSessionAndShowTab(
@NotNull @Nls String sessionName,
@Nullable RunContentDescriptor contentToReuse,
boolean showToolWindowOnSuspendOnly,
@NotNull XDebugProcessStarter starter)
XDebugSession startSessionAndShowTab(
@NotNull @Nls String sessionName,
@Nullable Icon icon,
Nullable RunContentDescriptor contentToReuse,
boolean showToolWindowOnSuspendOnly,
@NotNull XDebugProcessStarter starter)
这些电话没有记录,我没有找到任何有用的信息
SessionName
没关系,听起来像是工具菜单中调试选项卡的名称RunContentDescriptor
- 没有线索,可能是有关当前所选运行配置的某种信息。不知道如何访问它的实例XDebugProcessStarter
- 不知道在哪里可以获取/创建它的实例ExecutionEnvironment
- 🗿
我知道单个进程可以有很多调试器,我需要为 Rider 硬编码“本机”调试器
可能有一种更简单的方法可以通过
DebuggerManager.attach(pid, "Native")
之类的调用来实现,或者我如何才能在 AnAction
上下文中实现上述工作?我想要与 Run -> Attach to process... -> [select process] -> Click Attach with LLDB
相同的行为,但以编程方式
startSessionAndShowTab
的第二次重载似乎是合适的:
XDebugSession startSessionAndShowTab(
@NotNull @Nls String sessionName,
@Nullable RunContentDescriptor contentToReuse,
@NotNull XDebugProcessStarter starter)
这是最简单的,允许启动调试会话,参数如下:
sessionName
:命名调试会话的String
:它只是一个用于标识调试会话的字符串。contentToReuse
:如果您不需要重用现有内容,可以是 RunContentDescriptor
。null
:
starter
的实例,您可以在其中实现创建和返回特定调试器进程的逻辑。这就是大部分工作的所在。
要附加到特定进程(例如
Rider 的本机进程),您可能需要与特定于 Rider 的较低级别 API 进行交互,也可能需要与 LLDB 进行交互。这更加复杂,通常不会通过高级 XDebugProcessStarter
API
公开。附加调试器的简化示例是:
XDebuggerManager
对于使用 LLDB 在 Rider 中进行本机调试,您将必须深入研究 Rider 的特定 API,并可能直接与 LLDB 交互,这可能会更加复杂,并且可能无法通过公共 API 完全支持。警告:Rider 中的
调试会话将比其他 IDE 慢得多
。
我在 JetBrains API 中没有看到简单的
import com.intellij.debugger.DebuggerManager;
import com.intellij.debugger.engine.JavaDebugProcess;
import com.intellij.execution.executors.DefaultDebugExecutor;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.xdebugger.XDebugProcessStarter;
import com.intellij.xdebugger.XDebuggerManager;
import com.intellij.xdebugger.XDebugSession;
// In your actionPerformed method
Project project = ...; // Get your current project
DebuggerManager debuggerManager = DebuggerManager.getInstance(project);
XDebugProcessStarter starter = new XDebugProcessStarter() {
@Override
public XDebugProcess start(@NotNull XDebugSession session) throws ExecutionException {
// Here you need to create and return an instance of your debugger process.
// For a Java process, it might look something like this:
return JavaDebugProcess.create(session, new RunContentDescriptor(...));
// For native processes, you will need a different implementation.
}
};
XDebugSession session = XDebuggerManager.getInstance(project).startSessionAndShowTab(
"My Debug Session", // session name
null, // runContentDescriptor, null if you do not need to reuse
starter // your custom debug process starter
);
方法。