Package org.eclipse.php.internal.debug.core.xdebug.dbgp.model

Examples of org.eclipse.php.internal.debug.core.xdebug.dbgp.model.DBGpTarget


   * @throws CoreException
   */
  private void createLaunch(DBGpSession session) throws CoreException {
    boolean stopAtFirstLine = PHPProjectPreferences
        .getStopAtFirstLine(null);
    DBGpTarget target = null;
    PathMapper mapper = null;
    PHPSourceLookupDirector srcLocator = new PHPSourceLookupDirector();
    srcLocator.setSourcePathComputer(DebugPlugin
        .getDefault()
        .getLaunchManager()
        .getSourcePathComputer(
            "org.eclipse.php.debug.core.sourcePathComputer.php")); //$NON-NLS-1$
    ILaunchConfigurationType type = null;
    ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager();

    if (session.getSessionId() == null) {
      // web launch
      type = lm
          .getLaunchConfigurationType(IPHPDebugConstants.PHPServerLaunchType);
    } else {
      // cli launch
      type = lm
          .getLaunchConfigurationType(IPHPDebugConstants.PHPEXELaunchType);
    }

    ILaunchConfiguration launchConfig = type.newInstance(null,
        PHPDebugCoreMessages.XDebugMessage_remoteSessionTitle);
    srcLocator.initializeDefaults(launchConfig);
    srcLocator.initializeParticipants();
    ILaunch remoteLaunch = new Launch(launchConfig,
        ILaunchManager.DEBUG_MODE, srcLocator);
    boolean multiSession = XDebugPreferenceMgr.useMultiSession();

    if (session.getSessionId() == null && !multiSession) {
      // non multisession web launch
      target = new DBGpTarget(remoteLaunch, null, null,
          session.getIdeKey(), stopAtFirstLine, null);

      // try to locate a relevant server definition so we can get its path
      // mapper
      Server server = null;
      Server[] servers = ServersManager.getServers();
      for (int i = 0; i < servers.length; i++) {
        if (servers[i].getPort() == session.getRemotePort()
            && servers[i].getHost().equalsIgnoreCase(
                session.getRemoteHostname())) {
          server = servers[i];
          break;
        }
      }
      if (server != null) {
        mapper = PathMapperRegistry.getByServer(server);
      }

      if (mapper == null) {
        // create a temporary path mapper, we may look to holding these
        // via the pathmapper registry in the future
        // but they would be persisted.
        mapper = new PathMapper();
      }
      // need to add ourselves as a session listener for future sessions
      DBGpSessionHandler.getInstance().addSessionListener(
          (IDBGpSessionListener) target);
    } else {
      // cli launch or multisession web launch: create a single shot
      // target
      target = new DBGpTarget(remoteLaunch, null /* no script name */,
          session.getIdeKey(), session.getSessionId(),
          stopAtFirstLine);
      // PathMapper p = PathMapperRegistry.getByPHPExe(null);
      // create a temporary path mapper
      mapper = new PathMapper();
    }

    // set up the target with the relevant connections
    target.setPathMapper(mapper);
    target.setSession(session);
    session.setDebugTarget(target);

    if (multiSession && session.getSessionId() == null) {
      // we are a multisession web launch
      DBGpMultiSessionTarget multiSessionTarget = new DBGpMultiSessionTarget(
          remoteLaunch, null, null, session.getIdeKey(),
          stopAtFirstLine, null);
      DBGpSessionHandler.getInstance().addSessionListener(
          (IDBGpSessionListener) multiSessionTarget);
      remoteLaunch.addDebugTarget(multiSessionTarget);
      multiSessionTarget.sessionReceived(
          (DBGpBreakpointFacade) IDELayerFactory.getIDELayer(),
          XDebugPreferenceMgr.createSessionPreferences(), target,
          mapper);
    } else {
      // we are not a multisession web launch, so just add to the launch
      remoteLaunch.addDebugTarget(target);
      // tell the target it now has a session.
      target.sessionReceived(
          (DBGpBreakpointFacade) IDELayerFactory.getIDELayer(),
          XDebugPreferenceMgr.createSessionPreferences());
      // probably could do waitForInitialSession as session has already
      // been set.
    }

    // add the remote launch to the launch manager
    DebugPlugin.getDefault().getLaunchManager().addLaunch(remoteLaunch);

    // check to see owning session target is still active, if so do a
    // perspective switch
    if (target.isTerminated() == false && target.isTerminating() == false) {
      Display.getDefault().asyncExec(new Runnable() {

        public void run() {
          IWorkbenchWindow window = PlatformUI.getWorkbench()
              .getActiveWorkbenchWindow();
View Full Code Here


                      file, lineNumber);
                  RunToLineHandler handler = new RunToLineHandler(
                      debugTarget, target, breakpoint);
                  handler.run(new NullProgressMonitor());
                } else if (debugTarget instanceof DBGpTarget) {
                  DBGpTarget t = (DBGpTarget) debugTarget;
                  t.runToLine(file, lineNumber);
                }
                return;
              }
            }
          } else {
View Full Code Here

    String initialValue = value.getValueString();

    if (value instanceof DBGpStringValue) {
      DBGpStringValue strValue = (DBGpStringValue) value;
      if (strValue.isComplete() == false) {
        DBGpTarget target = (DBGpTarget) value.getDebugTarget();
        DBGpVariable dbgpVar = (DBGpVariable) variable;
        String stackLevel = dbgpVar.getStackLevel();
        Node result = target.getCompleteString(dbgpVar.getFullName(),
            stackLevel, strValue.getRequiredBytes());
        if (result != null) {
          IVariable tempVar = new DBGpVariable(target, result,
              stackLevel);
          IValue valRes = null;
View Full Code Here

    return value;
  }

  protected String getPropertyValue(DBGpStackFrame context, String variable) {
    String value = null;
    DBGpTarget debugTarget = (DBGpTarget) context.getDebugTarget();
    Node resp = debugTarget.getProperty(variable, context.getStackLevel(),
        0);
    if (resp == null) {
      return ""; //$NON-NLS-1$
    }
    IVariable tempVar = new DBGpVariable(debugTarget, resp, "-2"); //$NON-NLS-1$
View Full Code Here

            startStopURLs[1], ideKey, stopAtFirstLine, browser[0]);
        target.setPathMapper(PathMapperRegistry.getByServer(server));
        launch.addDebugTarget(target); // has to be added now, not
                        // later.
      } else {
        target = new DBGpTarget(launch, launchScript, startStopURLs[1],
            ideKey, stopAtFirstLine, browser[0]);
        target.setPathMapper(PathMapperRegistry.getByServer(server));
      }
      DBGpSessionHandler.getInstance().addSessionListener(
          (IDBGpSessionListener) target);
View Full Code Here

      return;
    }

    // determine the environment variables
    String[] envVarString = null;
    DBGpTarget target = null;
    if (mode.equals(ILaunchManager.DEBUG_MODE)) {
      // check the launch for stop at first line, if not there go to
      // project specifics
      boolean stopAtFirstLine = PHPProjectPreferences
          .getStopAtFirstLine(project);
      stopAtFirstLine = configuration
          .getAttribute(IDebugParametersKeys.FIRST_LINE_BREAKPOINT,
              stopAtFirstLine);
      String sessionID = DBGpSessionHandler.getInstance()
          .generateSessionId();
      String ideKey = null;
      if (DBGpProxyHandler.instance.useProxy()) {
        ideKey = DBGpProxyHandler.instance.getCurrentIdeKey();
        if (DBGpProxyHandler.instance.registerWithProxy() == false) {
          displayErrorMessage(PHPDebugCoreMessages.XDebug_ExeLaunchConfigurationDelegate_2
              + DBGpProxyHandler.instance.getErrorMsg());
          DebugPlugin.getDefault().getLaunchManager()
              .removeLaunch(launch);
          return;
        }
      } else {
        ideKey = DBGpSessionHandler.getInstance().getIDEKey();
      }
      target = new DBGpTarget(launch, phpFile.lastSegment(), ideKey,
          sessionID, stopAtFirstLine);
      target.setPathMapper(PathMapperRegistry
          .getByLaunchConfiguration(configuration));
      DBGpSessionHandler.getInstance().addSessionListener(target);
      envVarString = createDebugLaunchEnvironment(configuration,
          sessionID, ideKey, phpExe);
    } else {
      envVarString = PHPLaunchUtilities.getEnvironment(configuration,
          new String[] { getLibraryPath(phpExe) });
    }

    IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 30);
    subMonitor.beginTask(
        PHPDebugCoreMessages.XDebug_ExeLaunchConfigurationDelegate_3,
        10);

    // determine the working directory. default is the location of the
    // script
    IPath workingPath = phpFile.removeLastSegments(1);
    File workingDir = workingPath.makeAbsolute().toFile();

    boolean found = false;
    for (int i = 0; i < envVarString.length && !found; i++) {
      String envEntity = envVarString[i];
      String[] elements = envEntity.split("="); //$NON-NLS-1$
      if (elements.length > 0 && elements[0].equals("XDEBUG_WORKING_DIR")) { //$NON-NLS-1$
        found = true;
        workingPath = new Path(elements[1]);
        File temp = workingPath.makeAbsolute().toFile();
        if (temp.exists()) {
          workingDir = temp;
        }
      }
    }

    // Detect PHP SAPI type and thus where we need arguments
    File phpExeFile = new File(phpExeString);
    String sapiType = null;
    String phpV = null;
    PHPexeItem[] items = PHPexes.getInstance().getAllItems();
    for (PHPexeItem item : items) {
      if (item.getExecutable().equals(phpExeFile)) {
        sapiType = item.getSapiType();
        phpV = item.getVersion();
        break;
      }
    }
    String[] args = null;
    if (PHPexeItem.SAPI_CLI.equals(sapiType)) {
      args = PHPLaunchUtilities.getProgramArguments(launch
          .getLaunchConfiguration());
    }

    // define the command line for launching
    String[] cmdLine = null;
    cmdLine = PHPLaunchUtilities.getCommandLine(configuration,
        phpExe.toOSString(), tempIni.toString(), phpFile.toOSString(),
        args, phpV);

    // Launch the process
    final Process phpExeProcess = DebugPlugin.exec(cmdLine, workingDir,
        envVarString);
    // Attach a crash detector
    new Thread(new ProcessCrashDetector(launch, phpExeProcess)).start();

    IProcess eclipseProcessWrapper = null;
    if (phpExeProcess != null) {
      subMonitor.worked(10);
      eclipseProcessWrapper = DebugPlugin.newProcess(launch,
          phpExeProcess, phpExe.toOSString(), processAttributes);
      if (eclipseProcessWrapper == null) {

        // another error so we stop everything somehow
        phpExeProcess.destroy();
        subMonitor.done();
        DebugPlugin.getDefault().getLaunchManager()
            .removeLaunch(launch);
        throw new CoreException(new Status(IStatus.ERROR,
            PHPDebugPlugin.ID, 0, null, null));
      }

      // if launching in debug mode, create the debug infrastructure and
      // link it with the launched process
      if (mode.equals(ILaunchManager.DEBUG_MODE) && target != null) {
        target.setProcess(eclipseProcessWrapper);
        launch.addDebugTarget(target);
        subMonitor
            .subTask(PHPDebugCoreMessages.XDebug_ExeLaunchConfigurationDelegate_4);
        target.waitForInitialSession(
            (DBGpBreakpointFacade) IDELayerFactory.getIDELayer(),
            XDebugPreferenceMgr.createSessionPreferences(), monitor);
      }

    } else {
View Full Code Here

TOP

Related Classes of org.eclipse.php.internal.debug.core.xdebug.dbgp.model.DBGpTarget

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.