Exemplo n.º 1
0
  public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
    String defaultGdbCommand =
        Platform.getPreferencesService()
            .getString(
                GdbPlugin.PLUGIN_ID,
                IGdbDebugPreferenceConstants.PREF_DEFAULT_GDB_COMMAND,
                "",
                null); //$NON-NLS-1$
    configuration.setAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUG_NAME, defaultGdbCommand);

    CommandFactoryManager cfManager = MIPlugin.getDefault().getCommandFactoryManager();
    CommandFactoryDescriptor defDesc =
        cfManager.getDefaultDescriptor(IGDBJtagConstants.DEBUGGER_ID);
    configuration.setAttribute(
        IMILaunchConfigurationConstants.ATTR_DEBUGGER_COMMAND_FACTORY, defDesc.getName());
    configuration.setAttribute(
        IMILaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, defDesc.getMIVersions()[0]);
    configuration.setAttribute(
        IMILaunchConfigurationConstants.ATTR_DEBUGGER_VERBOSE_MODE,
        IMILaunchConfigurationConstants.DEBUGGER_VERBOSE_MODE_DEFAULT);
    configuration.setAttribute(
        IGDBJtagConstants.ATTR_USE_REMOTE_TARGET, IGDBJtagConstants.DEFAULT_USE_REMOTE_TARGET);
    configuration.setAttribute(
        IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_UPDATE_THREADLIST_ON_SUSPEND,
        IGDBLaunchConfigurationConstants.DEBUGGER_UPDATE_THREADLIST_ON_SUSPEND_DEFAULT);
  }
Exemplo n.º 2
0
  /**
   * Starts a process by executing the following command: gdb -q -nw -i <mi_version>(extracted from
   * the command factory) -tty<pty_name> (if <code>usePTY</code> is <code>true</code>) extraArgs
   * program (if <code>program</code> is not <code>null</code>)
   *
   * @param sessionType the type of debugging session: <code>MISession.PROGRAM</code>, <code>
   *     MISession.ATTACH</code> or <code>MISession.CORE</code>
   * @param gdb the name of the gdb file
   * @param factory the command set supported by gdb
   * @param program a program to debug or <code>null</code>
   * @param extraArgs arguments to pass to gdb
   * @param usePty whether to use pty or not
   * @param monitor a progress monitor
   * @return an instance of <code>ICDISession</code>
   * @throws IOException
   * @throws MIException
   */
  public Session createSession(
      int sessionType,
      String gdb,
      CommandFactory factory,
      File program,
      String[] extraArgs,
      boolean usePty,
      IProgressMonitor monitor)
      throws IOException, MIException {
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }

    if (gdb == null || gdb.length() == 0) {
      gdb = GDB;
    }

    IMITTY pty = null;

    if (usePty) {
      try {
        PTY pseudo = new PTY();
        pseudo.validateSlaveName();
        pty = new MITTYAdapter(pseudo);
      } catch (IOException e) {
        // Should we not print/log this ?
      }
    }

    ArrayList argList = new ArrayList(extraArgs.length + 8);
    argList.add(gdb);
    argList.add("-q"); // $NON-NLS-1$
    argList.add("-nw"); // $NON-NLS-1$
    argList.add("-i"); // $NON-NLS-1$
    argList.add(factory.getMIVersion());
    if (pty != null) {
      argList.add("-tty"); // $NON-NLS-1$
      argList.add(pty.getSlaveName());
    }
    argList.addAll(Arrays.asList(extraArgs));
    if (program != null) {
      argList.add(program.getAbsolutePath());
    }
    String[] args = (String[]) argList.toArray(new String[argList.size()]);
    int launchTimeout =
        MIPlugin.getDefault()
            .getPluginPreferences()
            .getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT);

    MISession miSession = null;
    MIProcess pgdb = null;
    boolean failed = false;
    try {
      pgdb = factory.createMIProcess(args, launchTimeout, monitor);

      if (MIPlugin.DEBUG) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < args.length; ++i) {
          sb.append(args[i]);
          sb.append(' ');
        }
        MIPlugin.getDefault().debugLog(sb.toString());
      }

      miSession = createMISession0(sessionType, pgdb, factory, pty, getCommandTimeout());
    } catch (MIException e) {
      failed = true;
      throw e;
    } catch (IOException e) {
      failed = true;
      throw e;
    } finally {
      if (failed) {
        // Kill gdb
        if (pgdb != null) pgdb.destroy();
        // Shutdown the pty console.
        if (pty != null) {
          try {
            OutputStream out = pty.getOutputStream();
            if (out != null) {
              out.close();
            }
            InputStream in = pty.getInputStream();
            if (in != null) {
              in.close();
            }
          } catch (IOException e) {
          }
        }
      }
    }

    return new Session(miSession);
  }
Exemplo n.º 3
0
  /**
   * Method createCSession; Post mortem debug with a core file.
   *
   * @param program
   * @param core
   * @return ICDISession
   * @throws IOException
   * @deprecated use <code>createSession</code>
   */
  @Deprecated
  public Session createCSession(
      String gdb,
      String miVersion,
      File program,
      File core,
      File cwd,
      String gdbinit,
      IProgressMonitor monitor)
      throws IOException, MIException {
    if (gdb == null || gdb.length() == 0) {
      gdb = GDB;
    }

    String commandFile =
        (gdbinit != null && gdbinit.length() > 0)
            ? "--command=" + gdbinit
            : "--nx"; //$NON-NLS-1$ //$NON-NLS-2$

    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }

    String[] args;
    if (program == null) {
      args =
          new String[] {
            gdb,
            "--cd=" + cwd.getAbsolutePath(),
            commandFile,
            "--quiet",
            "-nw",
            "-i",
            miVersion,
            "-c",
            core.getAbsolutePath()
          }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
    } else {
      args =
          new String[] {
            gdb,
            "--cd=" + cwd.getAbsolutePath(),
            commandFile,
            "--quiet",
            "-nw",
            "-i",
            miVersion,
            "-c",
            core.getAbsolutePath(),
            program.getAbsolutePath()
          }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
    }

    int launchTimeout =
        MIPlugin.getDefault()
            .getPluginPreferences()
            .getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT);
    MIProcess pgdb = new MIProcessAdapter(args, launchTimeout, monitor);

    if (MIPlugin.DEBUG) {
      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < args.length; ++i) {
        sb.append(args[i]);
        sb.append(' ');
      }
      MIPlugin.getDefault().debugLog(sb.toString());
    }

    MISession session;
    try {
      session = createMISession(pgdb, null, MISession.CORE, miVersion, monitor);
      // @@@ We have to manually set the suspended state when doing post-mortem
      session.getMIInferior().setSuspended();
    } catch (MIException e) {
      pgdb.destroy();
      throw e;
    }
    return new Session(session);
  }
Exemplo n.º 4
0
  /**
   * Method createCSession; remote debuging by selectin a target.
   *
   * @param program
   * @param pid
   * @return ICDISession
   * @throws IOException
   * @deprecated use <code>createSession</code>
   */
  @Deprecated
  public Session createCSession(
      String gdb,
      String miVersion,
      File program,
      int pid,
      String[] targetParams,
      File cwd,
      String gdbinit,
      IProgressMonitor monitor)
      throws IOException, MIException {
    if (gdb == null || gdb.length() == 0) {
      gdb = GDB;
    }

    String commandFile =
        (gdbinit != null && gdbinit.length() > 0)
            ? "--command=" + gdbinit
            : "--nx"; //$NON-NLS-1$ //$NON-NLS-2$

    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }

    String[] args;
    if (program == null) {
      args =
          new String[] {
            gdb, "--cd=" + cwd.getAbsolutePath(), commandFile, "--quiet", "-nw", "-i", miVersion
          }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    } else {
      args =
          new String[] {
            gdb,
            "--cd=" + cwd.getAbsolutePath(),
            commandFile,
            "--quiet",
            "-nw",
            "-i",
            miVersion,
            program.getAbsolutePath()
          }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    }

    int launchTimeout =
        MIPlugin.getDefault()
            .getPluginPreferences()
            .getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT);
    MIProcess pgdb = new MIProcessAdapter(args, launchTimeout, monitor);

    if (MIPlugin.getDefault().isDebugging()) {
      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < args.length; ++i) {
        sb.append(args[i]);
        sb.append(' ');
      }
      MIPlugin.getDefault().debugLog(sb.toString());
    }

    MISession session;
    try {
      session = createMISession(pgdb, null, MISession.ATTACH, miVersion, monitor);
    } catch (MIException e) {
      pgdb.destroy();
      throw e;
    }
    CommandFactory factory = session.getCommandFactory();
    try {
      if (targetParams != null && targetParams.length > 0) {
        MITargetSelect target = factory.createMITargetSelect(targetParams);
        session.postCommand(target);
        MIInfo info = target.getMIInfo();
        if (info == null) {
          throw new MIException(getResourceString("src.common.No_answer")); // $NON-NLS-1$
        }
      }
      if (pid > 0) {
        CLITargetAttach attach = factory.createCLITargetAttach(pid);
        session.postCommand(attach);
        MIInfo info = attach.getMIInfo();
        if (info == null) {
          throw new MIException(getResourceString("src.common.No_answer")); // $NON-NLS-1$
        }
        session.getMIInferior().setInferiorPID(pid);
        // @@@ for attach we nee to manually set the connected state
        // attach does not send the ^connected ack
        session.getMIInferior().setConnected();
      }
    } catch (MIException e) {
      if (session != null) session.terminate();

      pgdb.destroy();
      throw e;
    }
    // @@@ We have to manually set the suspended state when we attach
    session.getMIInferior().setSuspended();
    session.getMIInferior().update();
    return new Session(session, true);
  }
Exemplo n.º 5
0
  /**
   * Method createCSession; lauch gdb in mi mode for local debugging
   *
   * @param program
   * @return ICDISession
   * @throws IOException
   * @deprecated use <code>createSession</code>
   */
  @Deprecated
  public Session createCSession(
      String gdb,
      String miVersion,
      File program,
      File cwd,
      String gdbinit,
      IMITTY pty,
      IProgressMonitor monitor)
      throws IOException, MIException {
    if (gdb == null || gdb.length() == 0) {
      gdb = GDB;
    }

    String commandFile =
        (gdbinit != null && gdbinit.length() > 0)
            ? "--command=" + gdbinit
            : "--nx"; //$NON-NLS-1$ //$NON-NLS-2$

    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }

    String[] args;
    if (pty != null) {
      if (program == null) {
        args =
            new String[] {
              gdb,
              "--cd=" + cwd.getAbsolutePath(),
              commandFile,
              "-q",
              "-nw",
              "-tty",
              pty.getSlaveName(),
              "-i",
              miVersion
            }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
      } else {
        args =
            new String[] {
              gdb,
              "--cd=" + cwd.getAbsolutePath(),
              commandFile,
              "-q",
              "-nw",
              "-tty",
              pty.getSlaveName(),
              "-i",
              miVersion,
              program.getAbsolutePath()
            }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
      }
    } else {
      if (program == null) {
        args =
            new String[] {
              gdb, "--cd=" + cwd.getAbsolutePath(), commandFile, "-q", "-nw", "-i", miVersion
            }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
      } else {
        args =
            new String[] {
              gdb,
              "--cd=" + cwd.getAbsolutePath(),
              commandFile,
              "-q",
              "-nw",
              "-i",
              miVersion,
              program.getAbsolutePath()
            }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
      }
    }

    int launchTimeout =
        MIPlugin.getDefault()
            .getPluginPreferences()
            .getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT);
    MIProcess pgdb = new MIProcessAdapter(args, launchTimeout, monitor);

    if (MIPlugin.DEBUG) {
      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < args.length; ++i) {
        sb.append(args[i]);
        sb.append(' ');
      }
      MIPlugin.getDefault().debugLog(sb.toString());
    }

    MISession session;
    try {
      session = createMISession(pgdb, pty, MISession.PROGRAM, miVersion, monitor);
    } catch (MIException e) {
      pgdb.destroy();
      throw e;
    }
    // Try to detect if we have been attach/connected via "target remote localhost:port"
    // or "attach" and set the state to be suspended.
    try {
      CommandFactory factory = session.getCommandFactory();
      MIStackListFrames frames = factory.createMIStackListFrames();
      session.postCommand(frames);
      MIInfo info = frames.getMIInfo();
      if (info == null) {
        pgdb.destroy();
        throw new MIException(getResourceString("src.common.No_answer")); // $NON-NLS-1$
      }
      // @@@ We have to manually set the suspended state since we have some stackframes
      session.getMIInferior().setSuspended();
      session.getMIInferior().update();
    } catch (MIException e) {
      // If an exception is thrown that means ok
      // we did not attach/connect to any target.
    }
    return new Session(session, false);
  }