Skip to content

Commit

Permalink
Merge pull request #692 from JetBrains/232-mb-net48
Browse files Browse the repository at this point in the history
Azure Functions: Support debugging .NET 4.8 isolated worker projects
  • Loading branch information
maartenba authored Jun 21, 2023
2 parents a896917 + fb91c71 commit 51240ea
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.jvmargs='-Duser.language=en'
sources=false

intellij_version=IC-232.6095-EAP-CANDIDATE-SNAPSHOT
rider_version=RD-2023.2-EAP2-SNAPSHOT
rider_version=RD-2023.2-EAP5-SNAPSHOT
#rider_version=RD-2023.1
build_common_code_with=rider
intellij_plugin_name=azure-toolkit-for-intellij
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<h4>Added:</h4>
<ul>
<li>Compatibility with Rider 2023.2</li>
<li>Azure Functions: Support debugging .NET 4.8 isolated worker projects (<a href="https://github.com/JetBrains/azure-tools-for-intellij/issues/691">#691</a>)</li>
</ul>
</html>
]]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<p>[3.50.0-2023.2]</p>
<ul>
<li>Compatibility with Rider 2023.2</li>
<li>Azure Functions: Support debugging .NET 4.8 isolated worker projects (<a href="https://github.com/JetBrains/azure-tools-for-intellij/issues/691">#691</a>)</li>
</ul>
<p>[3.50.0-2023.1]</p>
<ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AzureFunctionsDotNetCoreRuntime(val coreToolsInfo: FunctionsCoreToolsInfo,
override fun createDebugState(dotNetExecutable: DotNetExecutable, executionEnvironment: ExecutionEnvironment) : IDotNetDebugProfileState {
return when (workerRuntime) {
FunctionsWorkerRuntime.DotNetDefault -> DotNetCoreDebugProfile(DotNetCoreRuntime(coreToolsInfo.coreToolsExecutable), dotNetExecutable, executionEnvironment, coreToolsInfo.coreToolsExecutable)
FunctionsWorkerRuntime.DotNetIsolated -> AzureFunctionsDotNetCoreIsolatedDebugProfile(dotNetExecutable, this, executionEnvironment)
FunctionsWorkerRuntime.DotNetIsolated -> AzureFunctionsIsolatedDebugProfile(dotNetExecutable, this, executionEnvironment)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task
import com.intellij.openapi.rd.util.withBackgroundContext
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.io.FileUtil
import com.intellij.util.execution.ParametersListUtil
Expand All @@ -46,10 +47,15 @@ import com.jetbrains.rdclient.util.idea.pumpMessages
import com.jetbrains.rider.debugger.DebuggerHelperHost
import com.jetbrains.rider.debugger.DebuggerWorkerPlatform
import com.jetbrains.rider.debugger.DebuggerWorkerProcessHandler
import com.jetbrains.rider.debugger.RiderDebuggerBundle
import com.jetbrains.rider.model.DesktopClrRuntime
import com.jetbrains.rider.model.debuggerWorker.DebuggerStartInfoBase
import com.jetbrains.rider.model.debuggerWorker.DotNetClrAttachStartInfo
import com.jetbrains.rider.model.debuggerWorker.DotNetCoreAttachStartInfo
import com.jetbrains.rider.run.*
import com.jetbrains.rider.run.dotNetCore.DotNetCoreAttachProfileState
import com.jetbrains.rider.run.dotNetCore.getWorkerPlatform
import com.jetbrains.rider.run.msNet.MsNetAttachProfileState
import com.jetbrains.rider.runtime.DotNetExecutable
import com.jetbrains.rider.runtime.DotNetRuntime
import com.jetbrains.rider.runtime.apply
Expand All @@ -59,14 +65,14 @@ import org.jetbrains.plugins.azure.RiderAzureBundle
import java.io.File
import java.time.Duration

class AzureFunctionsDotNetCoreIsolatedDebugProfile(
class AzureFunctionsIsolatedDebugProfile(
private val dotNetExecutable: DotNetExecutable,
private val dotNetRuntime: DotNetRuntime,
executionEnvironment: ExecutionEnvironment)
: DebugProfileStateBase(executionEnvironment) {

companion object {
private val logger = Logger.getInstance(AzureFunctionsDotNetCoreIsolatedDebugProfile::class.java)
private val logger = Logger.getInstance(AzureFunctionsIsolatedDebugProfile::class.java)
private val waitDuration = Duration.ofMinutes(1)
private const val DOTNET_ISOLATED_DEBUG_ARGUMENT = "--dotnet-isolated-debug"
private const val DOTNET_ENABLE_JSON_OUTPUT_ARGUMENT = "--enable-json-output"
Expand All @@ -75,6 +81,7 @@ class AzureFunctionsDotNetCoreIsolatedDebugProfile(
}

private var processId = 0
private var isNetFrameworkProcess = false
private lateinit var targetProcessHandler: ProcessHandler
private lateinit var console: ConsoleView

Expand Down Expand Up @@ -117,18 +124,37 @@ class AzureFunctionsDotNetCoreIsolatedDebugProfile(
RiderAzureBundle.message("run_config.run_function_app.debug.notification.isolated_worker_pid_unspecified"))
}

val targetProcess = ProcessListUtil.getProcessList().firstOrNull { it.pid == processId }
// Get process info
val targetProcess = withBackgroundContext {
ProcessListUtil.getProcessList().firstOrNull { it.pid == processId }
}

if (targetProcess == null) {
logger.warn("Unable to find target process with pid $processId")
// Create debugger worker info
return createWorkerRunInfoFor(port, DebuggerWorkerPlatform.AnyCpu)
}

// Determine process architecture, and whether it is .NET / .NET Core
val processExecutablePath = ParametersListUtil.parse(targetProcess.commandLine).firstOrNull()
val processArchitecture = DebuggerHelperHost.getInstance(executionEnvironment.project)
.getProcessArchitecture(lifetime, processId)
val processTargetFramework = processExecutablePath?.let {
DebuggerHelperHost.getInstance(executionEnvironment.project)
.getAssemblyTargetFramework(processExecutablePath!!, lifetime)
}

return DotNetCoreAttachProfileState(targetProcess, executionEnvironment, processArchitecture)
.createWorkerRunInfo(lifetime, helper, port)
isNetFrameworkProcess = processExecutablePath?.endsWith("dotnet.exe") == false && (processTargetFramework?.isNetFramework ?: false)
return if (!isNetFrameworkProcess) {
// .NET Core
DotNetCoreAttachProfileState(targetProcess, executionEnvironment, processArchitecture)
.createWorkerRunInfo(lifetime, helper, port)
} else {
// .NET Framework
val clrRuntime = DesktopClrRuntime("")
MsNetAttachProfileState(targetProcess, processArchitecture.getWorkerPlatform(), clrRuntime, executionEnvironment, RiderDebuggerBundle.message("MsNetAttachDebugger.display.name", clrRuntime.version))
.createWorkerRunInfo(lifetime, helper, port)
}
}

private fun launchAzureFunctionsHost() {
Expand Down Expand Up @@ -280,5 +306,11 @@ class AzureFunctionsDotNetCoreIsolatedDebugProfile(
}

override suspend fun createModelStartInfo(lifetime: Lifetime): DebuggerStartInfoBase
= DotNetCoreAttachStartInfo(processId)
= if (!isNetFrameworkProcess) {
// .NET Core
DotNetCoreAttachStartInfo(processId)
} else {
// .NET Framework
DotNetClrAttachStartInfo("", processId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.actionSystem.ex.ActionUtil
import com.intellij.openapi.actionSystem.impl.SimpleDataContext
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.util.Key
import icons.CommonIcons
import org.jetbrains.plugins.azure.RiderAzureBundle
Expand Down Expand Up @@ -71,12 +72,14 @@ class AzuriteBeforeRunTaskProvider : BeforeRunTaskProvider<AzuriteBeforeRunTask>

val project = configuration.project

ActionUtil.invokeAction(
StartAzuriteAction(),
SimpleDataContext.getProjectContext(project),
ActionPlaces.INTENTION_MENU,
null,
null)
ApplicationManager.getApplication().invokeLater {
ActionUtil.invokeAction(
StartAzuriteAction(),
SimpleDataContext.getProjectContext(project),
ActionPlaces.INTENTION_MENU,
null,
null)
}

return true
}
Expand Down

0 comments on commit 51240ea

Please sign in to comment.