自定义 Eclipse 调试配置

发布于 2024-10-16 03:12:01 字数 2274 浏览 6 评论 0原文

我有一个 gcc/gdb 的自定义构建,我正在尝试将其与 Eclipse CDT 插件集成。我创建了一个自定义 Eclipse 工具链,并且可以使用它成功构建。

我现在想做的是启用远程调试,但目前还没有成功。

我创建了一个扩展 AbstractCLaunchDelegate 的启动配置子类。在启动方法中,我有这样的代码:

public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException
{
    // Get path to binary
    IPath exePath = CDebugUtils.verifyProgramPath(configuration);
    ICProject project = CDebugUtils.verifyCProject(configuration);
    IBinaryObject exeFile = verifyBinary(project, exePath);

    // If debugging
    if(mode.equals("debug"))
    {
        // Get debug configuration
        ICDebugConfiguration config = getDebugConfig(configuration);

        // Get debugger instance
        ICDIDebugger2 debugger = (ICDIDebugger2)config.createDebugger();

        // Create session
        ICDISession session = debugger2.createSession(launch, exePath.toFile(), monitor);

        // Note: Copied from LocalCDILaunchDelegate
        boolean stopInMain = configuration.getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false );
        String stopSymbol = null;
        if ( stopInMain )
            stopSymbol = launch.getLaunchConfiguration().getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT );
        ICDITarget[] targets = session.getTargets();
        for( int i = 0; i < targets.length; i++ ) {
            Process process = targets[i].getProcess();
            IProcess iprocess = null;
            if ( process != null ) {
                iprocess = DebugPlugin.newProcess( launch, process, renderProcessLabel( exePath.toOSString() ), getDefaultProcessMap() );
            }

            // Note: Failing here with SIGILL
            CDIDebugModel.newDebugTarget( launch, project.getProject(), targets[i], renderTargetLabel( config ), iprocess, exeFile, true, false, stopSymbol, true );
        }
    }
}

我的问题是,在调用 CDIDebugModel.newDebugTarget() 时,我从 GDB 收到 SIGILL 错误。如果我忽略此行,则会创建调试器会话,但不会命中断点。

当我尝试使用在 Eclipse 中创建(但失败)的相同二进制文件在命令提示符下手动调试时,没有任何问题。我注意到的唯一区别是我在运行“继续”命令之前调用“load [BinaryName]”(不这样做会导致相同的 SIGILL 错误)。

有什么想法吗?

谢谢, 艾伦

I have a custom build of gcc/gdb that I'm trying to integrate with an Eclipse CDT plugin. I've created a custom Eclipse toolchain and can successfully build with it.

What I'm trying to do now is enable remote debugging but I'm not succeeding at the moment.

I've created a launch configuration subclass that extends AbstractCLaunchDelegate. In the launch method I have code like this:

public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException
{
    // Get path to binary
    IPath exePath = CDebugUtils.verifyProgramPath(configuration);
    ICProject project = CDebugUtils.verifyCProject(configuration);
    IBinaryObject exeFile = verifyBinary(project, exePath);

    // If debugging
    if(mode.equals("debug"))
    {
        // Get debug configuration
        ICDebugConfiguration config = getDebugConfig(configuration);

        // Get debugger instance
        ICDIDebugger2 debugger = (ICDIDebugger2)config.createDebugger();

        // Create session
        ICDISession session = debugger2.createSession(launch, exePath.toFile(), monitor);

        // Note: Copied from LocalCDILaunchDelegate
        boolean stopInMain = configuration.getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false );
        String stopSymbol = null;
        if ( stopInMain )
            stopSymbol = launch.getLaunchConfiguration().getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT );
        ICDITarget[] targets = session.getTargets();
        for( int i = 0; i < targets.length; i++ ) {
            Process process = targets[i].getProcess();
            IProcess iprocess = null;
            if ( process != null ) {
                iprocess = DebugPlugin.newProcess( launch, process, renderProcessLabel( exePath.toOSString() ), getDefaultProcessMap() );
            }

            // Note: Failing here with SIGILL
            CDIDebugModel.newDebugTarget( launch, project.getProject(), targets[i], renderTargetLabel( config ), iprocess, exeFile, true, false, stopSymbol, true );
        }
    }
}

My problem is that I am getting a SIGILL error back from GDB when calling CDIDebugModel.newDebugTarget(). If I leave this line out then the debugger session is created but no breakpoints are hit.

When I try to debug manually at the command prompt using the same binary that was created (and failing) in Eclipse, I don't have any issues. The only difference I noticed was that I am calling "load [BinaryName]" before running the "continue" command (not doing this results in the same SIGILL error).

Any ideas?

Thanks,
Alan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦太阳 2024-10-23 03:12:01

我想我已经找到了问题,它与我在从命令提示符调试时调用“load [BinaryName]”而不是在 Eclipse 中调用“load [BinaryName]”这一事实有关。

我发现我需要获取 MISession,然后调用 MITargetDownload 命令(这似乎相当于我的手动“load [BinaryName]”命令)。

其基本代码是:

// Get MI session
MISession miSession = target.getMISession();

// Get target download command for loading program on target
MITargetDownload targetDownload = miSession.getCommandFactory().createMITargetDownload(exePath.toOSString());

// Load program on target
miSession.postCommand(targetDownload);

这需要在对 CDIDebugModel.newDebugTarget 的任何调用之前进行。

希望这能解决这个问题,并至少能帮助处于类似情况的其他人。

谢谢,
艾伦

I think I've found the problem and it was related to the fact that I was calling "load [BinaryName]" when debugging from the command prompt but not within Eclipse.

I found that I needed to get hold of an MISession and then invoke the MITargetDownload command (which seems to be the equivalent to my manual "load [BinaryName]" command).

The basic code for this is:

// Get MI session
MISession miSession = target.getMISession();

// Get target download command for loading program on target
MITargetDownload targetDownload = miSession.getCommandFactory().createMITargetDownload(exePath.toOSString());

// Load program on target
miSession.postCommand(targetDownload);

This needs to go before any calls to CDIDebugModel.newDebugTarget.

Hopefully this draws a line under the issue and will at least help anyone else in a similar situation.

Thanks,
Alan

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文