use of com.android.tools.ndk.run.attach.AndroidNativeAttachConfiguration 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());
}
Aggregations