Alan Spark
Alan Spark

Reputation: 8302

Custom Eclipse debug configuration

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

Upvotes: 1

Views: 847

Answers (1)

Alan Spark
Alan Spark

Reputation: 8302

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

Upvotes: 1

Related Questions