Search in sources :

Example 1 with AndroidDebuggerState

use of com.android.tools.idea.run.editor.AndroidDebuggerState in project intellij by bazelbuild.

the class BlazeAndroidLaunchTasksProvider method getConnectDebuggerTask.

@Nullable
@Override
public DebugConnectorTask getConnectDebuggerTask(@NotNull LaunchStatus launchStatus, @Nullable AndroidVersion version) {
    if (!isDebug) {
        return null;
    }
    Set<String> packageIds = Sets.newHashSet();
    try {
        String packageName = applicationIdProvider.getPackageName();
        packageIds.add(packageName);
    } catch (ApkProvisionException e) {
        Logger.getInstance(AndroidLaunchTasksProvider.class).error(e);
    }
    try {
        String packageName = applicationIdProvider.getTestPackageName();
        if (packageName != null) {
            packageIds.add(packageName);
        }
    } catch (ApkProvisionException e) {
        // not as severe as failing to obtain package id for main application
        Logger.getInstance(AndroidLaunchTasksProvider.class).warn("Unable to obtain test package name, will not connect debugger " + "if tests don't instantiate main application");
    }
    AndroidDebugger androidDebugger = debuggerManager.getAndroidDebugger();
    AndroidDebuggerState androidDebuggerState = debuggerManager.getAndroidDebuggerState(project);
    if (androidDebugger == null || androidDebuggerState == null) {
        return null;
    }
    try {
        return runContext.getDebuggerTask(androidDebugger, androidDebuggerState, packageIds, monitorRemoteProcess());
    } catch (ExecutionException e) {
        launchStatus.terminateLaunch(e.getMessage());
        return null;
    }
}
Also used : AndroidDebugger(com.android.tools.idea.run.editor.AndroidDebugger) ApkProvisionException(com.android.tools.idea.run.ApkProvisionException) AndroidDebuggerState(com.android.tools.idea.run.editor.AndroidDebuggerState) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with AndroidDebuggerState

use of com.android.tools.idea.run.editor.AndroidDebuggerState in project android by JetBrains.

the class AndroidLaunchTasksProvider method getConnectDebuggerTask.

@Nullable
@Override
public DebugConnectorTask getConnectDebuggerTask(@NotNull LaunchStatus launchStatus, @Nullable AndroidVersion version) {
    if (!myLaunchOptions.isDebug()) {
        return null;
    }
    Logger logger = Logger.getInstance(AndroidLaunchTasksProvider.class);
    Set<String> packageIds = Sets.newHashSet();
    try {
        String packageName = myApplicationIdProvider.getPackageName();
        packageIds.add(packageName);
    } catch (ApkProvisionException e) {
        logger.error(e);
    }
    try {
        String packageName = myApplicationIdProvider.getTestPackageName();
        if (packageName != null) {
            packageIds.add(packageName);
        }
    } catch (ApkProvisionException e) {
        // not as severe as failing to obtain package id for main application
        logger.warn("Unable to obtain test package name, will not connect debugger if tests don't instantiate main application");
    }
    AndroidDebuggerContext androidDebuggerContext = myRunConfig.getAndroidDebuggerContext();
    AndroidDebugger debugger = androidDebuggerContext.getAndroidDebugger();
    if (debugger == null) {
        logger.warn("Unable to determine debugger to use for this launch");
        return null;
    }
    logger.info("Using debugger: " + debugger.getId());
    AndroidDebuggerState androidDebuggerState = androidDebuggerContext.getAndroidDebuggerState();
    if (androidDebuggerState != null) {
        //noinspection unchecked
        return debugger.getConnectDebuggerTask(myEnv, version, packageIds, myFacet, androidDebuggerState, myRunConfig.getType().getId(), monitorRemoteProcess());
    }
    return null;
}
Also used : AndroidDebugger(com.android.tools.idea.run.editor.AndroidDebugger) AndroidDebuggerState(com.android.tools.idea.run.editor.AndroidDebuggerState) AndroidDebuggerContext(com.android.tools.idea.run.editor.AndroidDebuggerContext) Logger(com.intellij.openapi.diagnostic.Logger) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with AndroidDebuggerState

use of com.android.tools.idea.run.editor.AndroidDebuggerState in project intellij by bazelbuild.

the class BlazeAndroidRunConfigurationDebuggerManager method writeExternal.

@Override
public void writeExternal(Element element) throws WriteExternalException {
    for (Map.Entry<String, AndroidDebuggerState> entry : androidDebuggerStates.entrySet()) {
        Element optionElement = new Element(entry.getKey());
        element.addContent(optionElement);
        entry.getValue().writeExternal(optionElement);
    }
}
Also used : AndroidDebuggerState(com.android.tools.idea.run.editor.AndroidDebuggerState) NativeAndroidDebuggerState(com.android.tools.ndk.run.editor.NativeAndroidDebuggerState) Element(org.jdom.Element) Map(java.util.Map)

Example 4 with AndroidDebuggerState

use of com.android.tools.idea.run.editor.AndroidDebuggerState in project intellij by bazelbuild.

the class BlazeNativeAndroidDebugger method attachToClient.

@Override
public void attachToClient(Project project, Client client) {
    final String clientDescr = client.getClientData().getClientDescription();
    Module module = null;
    final List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
    for (AndroidFacet facet : facets) {
        try {
            final String packageName = ApkProviderUtil.computePackageName(facet);
            if (clientDescr.startsWith(packageName)) {
                module = facet.getModule();
                break;
            }
        } catch (ApkProvisionException ignored) {
        // ignored
        }
    }
    if (module == null) {
        throw new RuntimeException("Cannot find module by package name");
    }
    if (hasExistingSession(project, client)) {
        return;
    }
    // Detach any existing JDWP debug session - reusing an existing session is troublesome
    // because we need to setup a custom XDebugProcess.
    DebuggerSession debuggerSession = findJdwpDebuggerSession(project, getClientDebugPort(client));
    if (debuggerSession != null) {
        debuggerSession.getProcess().stop(false);
    }
    // Create run configuration
    // TODO: Important modification here. Make sure to keep this in refactor.
    // We need a custom BlazeAndroidNativeAttachConfiguration to skip a bunch of launch checks so
    // validate passes.
    ConfigurationFactory factory = BlazeAndroidNativeAttachConfigurationFactory.getInstance();
    String runConfigurationName = String.format("Android Native Debugger (%d)", client.getClientData().getPid());
    RunnerAndConfigurationSettings runSettings = RunManager.getInstance(project).createRunConfiguration(runConfigurationName, factory);
    AndroidNativeAttachConfiguration configuration = (AndroidNativeAttachConfiguration) runSettings.getConfiguration();
    configuration.setClient(client);
    configuration.getAndroidDebuggerContext().setDebuggerType(getId());
    configuration.getConfigurationModule().setModule(module);
    // TODO: Important modification here. Make sure to keep this in refactor.
    // We need to set the correct working dir to find sources while debugging.
    // See BlazeAndroidRunConfigurationDebuggerManager#getAndroidDebuggerState
    AndroidDebuggerState state = configuration.getAndroidDebuggerContext().getAndroidDebuggerState();
    if (state instanceof NativeAndroidDebuggerState) {
        NativeAndroidDebuggerState nativeState = (NativeAndroidDebuggerState) state;
        nativeState.setWorkingDir(WorkspaceRoot.fromProject(project).directory().getPath());
    }
    ProgramRunnerUtil.executeConfiguration(project, runSettings, DefaultDebugExecutor.getDebugExecutorInstance());
}
Also used : DebuggerSession(com.intellij.debugger.impl.DebuggerSession) ApkProvisionException(com.android.tools.idea.run.ApkProvisionException) AndroidDebuggerState(com.android.tools.idea.run.editor.AndroidDebuggerState) NativeAndroidDebuggerState(com.android.tools.ndk.run.editor.NativeAndroidDebuggerState) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) BlazeAndroidNativeAttachConfigurationFactory(com.google.idea.blaze.android.run.attach.BlazeAndroidNativeAttachConfigurationFactory) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) AndroidNativeAttachConfiguration(com.android.tools.ndk.run.attach.AndroidNativeAttachConfiguration) Module(com.intellij.openapi.module.Module) NativeAndroidDebuggerState(com.android.tools.ndk.run.editor.NativeAndroidDebuggerState) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Aggregations

AndroidDebuggerState (com.android.tools.idea.run.editor.AndroidDebuggerState)4 ApkProvisionException (com.android.tools.idea.run.ApkProvisionException)2 AndroidDebugger (com.android.tools.idea.run.editor.AndroidDebugger)2 NativeAndroidDebuggerState (com.android.tools.ndk.run.editor.NativeAndroidDebuggerState)2 Nullable (org.jetbrains.annotations.Nullable)2 AndroidDebuggerContext (com.android.tools.idea.run.editor.AndroidDebuggerContext)1 AndroidNativeAttachConfiguration (com.android.tools.ndk.run.attach.AndroidNativeAttachConfiguration)1 BlazeAndroidNativeAttachConfigurationFactory (com.google.idea.blaze.android.run.attach.BlazeAndroidNativeAttachConfigurationFactory)1 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)1 ExecutionException (com.intellij.execution.ExecutionException)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Module (com.intellij.openapi.module.Module)1 Map (java.util.Map)1 Element (org.jdom.Element)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1