From f254fe0a3c89c6d887a90d96e71fadf8d343bc54 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Fri, 9 Jul 2021 00:44:03 +0800 Subject: [PATCH 01/15] =?UTF-8?q?=E6=8F=90=E4=BE=9Blaunch=20=E8=B0=83?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/META-INF/plugin.xml | 2 + .../emmyAttach/EmmyAttachDebuggerProvider.kt | 2 +- .../emmyLaunch/EmmyLaunchConfigurationType.kt | 95 ++++++++ .../emmyLaunch/EmmyLaunchDebugProcess.kt | 229 ++++++++++++++++++ .../EmmyLaunchDebugSettingsPanel.form | 86 +++++++ .../EmmyLaunchDebugSettingsPanel.java | 67 +++++ .../debugger/emmyLaunch/EmmyLaunchRunner.kt | 40 +++ 7 files changed, 520 insertions(+), 1 deletion(-) create mode 100644 src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchConfigurationType.kt create mode 100644 src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt create mode 100644 src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.form create mode 100644 src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.java create mode 100644 src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchRunner.kt diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index eaf84e7..b7e9ae2 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -16,6 +16,8 @@ + + \ No newline at end of file diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebuggerProvider.kt b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebuggerProvider.kt index fd5d1a1..13e8865 100644 --- a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebuggerProvider.kt +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebuggerProvider.kt @@ -48,7 +48,7 @@ class EmmyAttachDebuggerProvider : XLocalAttachDebuggerProvider { val notification = Notification( "Emmylua", "Error", - "Debugging tool 'emmy.arch.exe' has been removed, please reinstall the 'emmylua' plugin", + "Debugging tool 'emmy_tool.exe' has been removed, please reinstall the 'emmylua' plugin", NotificationType.WARNING) notification.isImportant = true Notifications.Bus.notify(notification) diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchConfigurationType.kt b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchConfigurationType.kt new file mode 100644 index 0000000..9ecb294 --- /dev/null +++ b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchConfigurationType.kt @@ -0,0 +1,95 @@ +package com.tang.intellij.lua.debugger.emmyLaunch + +import com.intellij.execution.Executor +import com.intellij.execution.configurations.ConfigurationFactory +import com.intellij.execution.configurations.ConfigurationType +import com.intellij.execution.configurations.RunConfiguration +import com.intellij.execution.configurations.RunProfileState +import com.intellij.execution.runners.ExecutionEnvironment +import com.intellij.execution.runners.RunConfigurationWithSuppressedDefaultRunAction +import com.intellij.openapi.module.Module +import com.intellij.openapi.options.SettingsEditor +import com.intellij.openapi.options.SettingsEditorGroup +import com.intellij.openapi.project.Project +import com.intellij.openapi.util.JDOMExternalizerUtil +import com.tang.intellij.lua.debugger.LuaCommandLineState +import com.tang.intellij.lua.debugger.LuaConfigurationFactory +import com.tang.intellij.lua.debugger.LuaRunConfiguration +import com.tang.intellij.lua.lang.LuaIcons +import org.jdom.Element +import javax.swing.Icon + +class EmmyLaunchConfigurationType : ConfigurationType { + override fun getIcon(): Icon { + return LuaIcons.FILE + } + + override fun getConfigurationTypeDescription(): String { + return "Emmy Launch debugger" + } + + override fun getId(): String { + return "lua.emmyLaunch.debugger" + } + + override fun getDisplayName(): String { + return "Emmy Launch debugger" + } + + override fun getConfigurationFactories(): Array { + return arrayOf( EmmyLaunchDebuggerConfigurationFactory(this)) + } +} + + +class EmmyLaunchDebuggerConfigurationFactory(val type: EmmyLaunchConfigurationType) : LuaConfigurationFactory(type) { + override fun createTemplateConfiguration(project: Project): RunConfiguration { + return EmmyLaunchDebugConfiguration(project, this) + } +} + +class EmmyLaunchDebugConfiguration(project: Project, factory: EmmyLaunchDebuggerConfigurationFactory) : LuaRunConfiguration(project, factory), + RunConfigurationWithSuppressedDefaultRunAction { + var program = "lua" + var workingDirectory = "" + var parameter = "" + var useWindowsTerminal = false + + override fun getConfigurationEditor(): SettingsEditor { + val group = SettingsEditorGroup() + group.addEditor("emmy", EmmyLaunchDebugSettingsPanel(project)) + return group + } + + override fun getState(executor: Executor, environment: ExecutionEnvironment): RunProfileState { + return LuaCommandLineState(environment) + } + + override fun getValidModules(): Collection { + return emptyList() + } + + override fun writeExternal(element: Element) { + super.writeExternal(element) + JDOMExternalizerUtil.writeField(element, "Program", program) + JDOMExternalizerUtil.writeField(element, "WorkingDirectory", workingDirectory) + JDOMExternalizerUtil.writeField(element, "Parameter", parameter) + JDOMExternalizerUtil.writeField(element, "UseWindowsTerminal", useWindowsTerminal.toString()) + } + + override fun readExternal(element: Element) { + super.readExternal(element) + JDOMExternalizerUtil.readField(element, "Program")?.let { + program = it + } + JDOMExternalizerUtil.readField(element, "WorkingDirectory")?.let { + workingDirectory = it + } + JDOMExternalizerUtil.readField(element, "Parameter")?.let { + parameter = it + } + JDOMExternalizerUtil.readField(element, "UseWindowsTerminal")?.let { value -> + useWindowsTerminal = value == "true" + } + } +} \ No newline at end of file diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt new file mode 100644 index 0000000..1ce5589 --- /dev/null +++ b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt @@ -0,0 +1,229 @@ +package com.tang.intellij.lua.debugger.emmyLaunch + +import com.google.gson.Gson +import com.intellij.execution.configurations.GeneralCommandLine +import com.intellij.execution.process.* +import com.intellij.execution.ui.ConsoleViewContentType +import com.intellij.openapi.util.Key +import com.intellij.xdebugger.XDebugSession +import com.tang.intellij.lua.debugger.LogConsoleType +import com.tang.intellij.lua.debugger.emmy.* +import com.tang.intellij.lua.debugger.utils.FileUtils +import kotlinx.coroutines.Delay +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.InputStreamReader +import java.io.OutputStreamWriter +import java.net.Socket +import java.util.concurrent.ThreadLocalRandom +import kotlin.random.Random + +class EmmyLaunchDebugProcess(session: XDebugSession, val configuration: EmmyLaunchDebugConfiguration) : + EmmyDebugProcessBase(session) { + + var client: Socket? = null + + override fun setupTransporter() { + if (configuration.useWindowsTerminal) { + runAndAttachUseWindowsTerminal() + } else { + runAndAttach() + } + } + + private fun attachTo(pid: Int) { + val port = getPort(pid) + val transporter = SocketClientTransporter("localhost", port) + transporter.handler = this + transporter.logger = this + this.transporter = transporter + transporter.start() + } + + private fun getPort(pid: Int): Int { + var port = pid + // 1024 - 65535 + while (port > 0xffff) port -= 0xffff + while (port < 0x400) port += 0x400 + return port; + } + + private fun detectArch(): EmmyWinArch { + val tool = FileUtils.getPluginVirtualFile("debugger/emmy/windows/x64/emmy_tool.exe") + val commandLine = GeneralCommandLine(tool) + commandLine.addParameters("arch_file", configuration.program) + val process = commandLine.createProcess() + process.waitFor() + val exitValue = process.exitValue() + return if (exitValue == 0) EmmyWinArch.X64 else EmmyWinArch.X86 + } + + private fun runAndAttachUseWindowsTerminal() { + val port = getPort(ThreadLocalRandom.current().nextInt(10240) + 10240); + val arch = detectArch() + val path = FileUtils.getPluginVirtualFile("debugger/emmy/windows/${arch}") + val re = Regex("[^/\\\\]+\$") + val mc = re.find(configuration.program) + + val commandLine = GeneralCommandLine() + commandLine.exePath = "wt" + commandLine.setWorkDirectory(path) + commandLine.addParameters( + "--title", + if (mc != null) mc.groups[0]?.value else configuration.program, + "emmy_tool.exe", + "run_and_attach", + "-dll", + "emmy_hook.dll", + "-dir", + "\"${path}\"", + "-work", + "\"${configuration.workingDirectory}\"", + "-block-on-exit", + "-exe", + "\"${configuration.program}\"", + "-debug-port", + port.toString(), + "-listen-mode", + "-args", + "\"${configuration.parameter}\"" + ) + + val handler = OSProcessHandler(commandLine) + handler.addProcessListener(object : ProcessListener { + override fun startNotified(processEvent: ProcessEvent) { + } + + override fun processTerminated(processEvent: ProcessEvent) { + } + + override fun processWillTerminate(processEvent: ProcessEvent, b: Boolean) { + } + + override fun onTextAvailable(processEvent: ProcessEvent, key: Key<*>) { + when (key) { + ProcessOutputTypes.STDERR -> print( + processEvent.text, + LogConsoleType.NORMAL, + ConsoleViewContentType.ERROR_OUTPUT + ) + ProcessOutputTypes.STDOUT -> print( + processEvent.text, + LogConsoleType.NORMAL, + ConsoleViewContentType.SYSTEM_OUTPUT + ) + } + } + }) + handler.startNotify() + + client = Socket("localhost", port) + client?.let { + it.soTimeout = 10000 + val inputStream = it.getInputStream() + val br = BufferedReader(InputStreamReader(inputStream)) + + val pidString = br.readLine() + val pid = pidString.toInt() + attachTo(pid) + + Thread.sleep(300) + val outputStream = it.getOutputStream() + val bw = BufferedWriter(OutputStreamWriter(outputStream)) + bw.write("connected"); + bw.flush() + } + } + + private fun runAndAttach() { + val port = getPort(ThreadLocalRandom.current().nextInt(10240) + 10240); + val arch = detectArch() + val path = FileUtils.getPluginVirtualFile("debugger/emmy/windows/${arch}") +// val re = Regex("[^/\\\\]+\$") +// val mc = re.find(configuration.program) + + val commandLine = GeneralCommandLine() + commandLine.exePath = "${path}/emmy_tool.exe" + commandLine.setWorkDirectory(path) + commandLine.addParameters( + "run_and_attach", + "-dll", + "emmy_hook.dll", + "-dir", + "\"${path}\"", + "-work", + "\"${configuration.workingDirectory}\"", + "-block-on-exit", + "-exe", + "\"${configuration.program}\"", + "-debug-port", + port.toString(), + "-listen-mode", + "-args", + "\"${configuration.parameter}\"" + ) + + + val handler = OSProcessHandler(commandLine) + handler.addProcessListener(object : ProcessListener { + override fun startNotified(processEvent: ProcessEvent) { + } + + override fun processTerminated(processEvent: ProcessEvent) { + } + + override fun processWillTerminate(processEvent: ProcessEvent, b: Boolean) { + } + + override fun onTextAvailable(processEvent: ProcessEvent, key: Key<*>) { + when (key) { + ProcessOutputTypes.STDERR -> print( + processEvent.text, + LogConsoleType.NORMAL, + ConsoleViewContentType.ERROR_OUTPUT + ) + ProcessOutputTypes.STDOUT -> print( + processEvent.text, + LogConsoleType.NORMAL, + ConsoleViewContentType.SYSTEM_OUTPUT + ) + } + } + }) + handler.startNotify() + + client = Socket("localhost", port) + client?.let { + it.soTimeout = 10000 + val inputStream = it.getInputStream() + val br = BufferedReader(InputStreamReader(inputStream)) + + val pidString = br.readLine() + val pid = pidString.toInt() + attachTo(pid) + + Thread.sleep(300) + val outputStream = it.getOutputStream() + val bw = BufferedWriter(OutputStreamWriter(outputStream)) + bw.write("connected"); + bw.flush() + } + + } + + + + override fun onReceiveMessage(cmd: MessageCMD, json: String) { + if (cmd == MessageCMD.AttachedNotify) { + val msg = Gson().fromJson(json, AttachedNotify::class.java) + println( + "Attached to lua state 0x${msg.state.toString(16)}", + LogConsoleType.NORMAL, + ConsoleViewContentType.SYSTEM_OUTPUT + ) + } else super.onReceiveMessage(cmd, json) + } +} \ No newline at end of file diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.form b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.form new file mode 100644 index 0000000..4097d58 --- /dev/null +++ b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.form @@ -0,0 +1,86 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.java b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.java new file mode 100644 index 0000000..29bd50e --- /dev/null +++ b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.java @@ -0,0 +1,67 @@ +package com.tang.intellij.lua.debugger.emmyLaunch; + +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.options.SettingsEditor; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +public class EmmyLaunchDebugSettingsPanel extends SettingsEditor implements DocumentListener { + private JTextField Program; + private JTextField WorkingDirectory; + private JTextField Parameters; + private JCheckBox useWindowsTerminalCheckBox; + private JPanel panel; + + public EmmyLaunchDebugSettingsPanel(Project project) { + Program.getDocument().addDocumentListener(this); + WorkingDirectory.getDocument().addDocumentListener(this); + Parameters.getDocument().addDocumentListener(this); + useWindowsTerminalCheckBox.addActionListener(e -> onChanged()); + } + + + @Override + protected void resetEditorFrom(@NotNull EmmyLaunchDebugConfiguration emmyLaunchDebugConfiguration) { + Program.setText(emmyLaunchDebugConfiguration.getProgram()); + WorkingDirectory.setText(emmyLaunchDebugConfiguration.getWorkingDirectory()); + Parameters.setText(emmyLaunchDebugConfiguration.getParameter()); + useWindowsTerminalCheckBox.setSelected(emmyLaunchDebugConfiguration.getUseWindowsTerminal()); + } + + @Override + protected void applyEditorTo(@NotNull EmmyLaunchDebugConfiguration emmyLaunchDebugConfiguration) throws ConfigurationException { + emmyLaunchDebugConfiguration.setProgram(Program.getText()); + emmyLaunchDebugConfiguration.setWorkingDirectory(WorkingDirectory.getText()); + emmyLaunchDebugConfiguration.setParameter(Parameters.getText()); + emmyLaunchDebugConfiguration.setUseWindowsTerminal(useWindowsTerminalCheckBox.isSelected()); + } + + @Override + protected @NotNull + JComponent createEditor() { + return panel; + } + + @Override + public void insertUpdate(DocumentEvent documentEvent) { + onChanged(); + } + + @Override + public void removeUpdate(DocumentEvent documentEvent) { + onChanged(); + } + + @Override + public void changedUpdate(DocumentEvent documentEvent) { + onChanged(); + } + + private void onChanged() { + fireEditorStateChanged(); + } +} diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchRunner.kt b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchRunner.kt new file mode 100644 index 0000000..ed24908 --- /dev/null +++ b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchRunner.kt @@ -0,0 +1,40 @@ +package com.tang.intellij.lua.debugger.emmyLaunch + +import com.intellij.execution.configurations.RunProfile +import com.intellij.execution.configurations.RunProfileState +import com.intellij.execution.executors.DefaultDebugExecutor +import com.intellij.execution.runners.ExecutionEnvironment +import com.intellij.execution.ui.RunContentDescriptor +import com.intellij.xdebugger.XDebugProcess +import com.intellij.xdebugger.XDebugProcessStarter +import com.intellij.xdebugger.XDebugSession +import com.intellij.xdebugger.XDebuggerManager +import com.tang.intellij.lua.debugger.LuaRunner +import com.tang.intellij.lua.debugger.emmy.EmmyDebugProcess + +class EmmyLaunchRunner : LuaRunner() { + companion object { + const val ID = "lua.emmyLaunch.runner" + } + var configuration: EmmyLaunchDebugConfiguration? = null; + + override fun getRunnerId() = ID + + override fun canRun(executorId: String, runProfile: RunProfile): Boolean { + if(DefaultDebugExecutor.EXECUTOR_ID == executorId && runProfile is EmmyLaunchDebugConfiguration){ + configuration = runProfile + return true + } + return false + } + + override fun doExecute(state: RunProfileState, environment: ExecutionEnvironment): RunContentDescriptor { + val manager = XDebuggerManager.getInstance(environment.project) + val session = manager.startSession(environment, object : XDebugProcessStarter() { + override fun start(session: XDebugSession): XDebugProcess { + return EmmyLaunchDebugProcess(session, configuration!!) + } + }) + return session.runContentDescriptor + } +} \ No newline at end of file From c20ae78db1974174fb13a506a6deedbcc33e2c83 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Fri, 9 Jul 2021 11:59:12 +0800 Subject: [PATCH 02/15] =?UTF-8?q?=E6=B7=BB=E5=8A=A0attach=20=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/META-INF/plugin.xml | 3 + .../emmyAttach/EmmyAttachConfigurationType.kt | 95 +++++++++++++++++++ .../emmyAttach/EmmyAttachDebugProcess.kt | 44 ++++++--- .../EmmyAttachDebugSettingsPanel.form | 34 +++++++ .../EmmyAttachDebugSettingsPanel.java | 67 +++++++++++++ .../debugger/emmyAttach/EmmyAttachDebugger.kt | 11 ++- .../debugger/emmyAttach/EmmyAttachRunner.kt | 43 +++++++++ 7 files changed, 277 insertions(+), 20 deletions(-) create mode 100644 src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachConfigurationType.kt create mode 100644 src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.form create mode 100644 src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.java create mode 100644 src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachRunner.kt diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index b7e9ae2..3efe64a 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -18,6 +18,9 @@ implementation="com.tang.intellij.lua.debugger.emmyAttach.EmmyAttachDebuggerProvider"/> + + + \ No newline at end of file diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachConfigurationType.kt b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachConfigurationType.kt new file mode 100644 index 0000000..e5d3381 --- /dev/null +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachConfigurationType.kt @@ -0,0 +1,95 @@ +package com.tang.intellij.lua.debugger.emmyAttach + +import com.intellij.execution.Executor +import com.intellij.execution.configurations.ConfigurationFactory +import com.intellij.execution.configurations.ConfigurationType +import com.intellij.execution.configurations.RunConfiguration +import com.intellij.execution.configurations.RunProfileState +import com.intellij.execution.runners.ExecutionEnvironment +import com.intellij.execution.runners.RunConfigurationWithSuppressedDefaultRunAction +import com.intellij.openapi.module.Module +import com.intellij.openapi.options.SettingsEditor +import com.intellij.openapi.options.SettingsEditorGroup +import com.intellij.openapi.project.Project +import com.intellij.openapi.util.JDOMExternalizerUtil +import com.tang.intellij.lua.debugger.LuaCommandLineState +import com.tang.intellij.lua.debugger.LuaConfigurationFactory +import com.tang.intellij.lua.debugger.LuaRunConfiguration +import com.tang.intellij.lua.lang.LuaIcons +import org.jdom.Element +import javax.swing.Icon + +class EmmyAttachConfigurationType : ConfigurationType { + override fun getIcon(): Icon { + return LuaIcons.FILE + } + + override fun getConfigurationTypeDescription(): String { + return "Emmy Attach Debugger" + } + + override fun getId(): String { + return "lua.emmyAttach.debugger" + } + + override fun getDisplayName(): String { + return "Emmy Attach Debugger" + } + + override fun getConfigurationFactories(): Array { + return arrayOf( EmmyAttachDebuggerConfigurationFactory(this)) + } +} + + +class EmmyAttachDebuggerConfigurationFactory(val type: EmmyAttachConfigurationType) : LuaConfigurationFactory(type) { + override fun createTemplateConfiguration(project: Project): RunConfiguration { + return EmmyAttachDebugConfiguration(project, this) + } +} + +class EmmyAttachDebugConfiguration(project: Project, factory: EmmyAttachDebuggerConfigurationFactory) : LuaRunConfiguration(project, factory), + RunConfigurationWithSuppressedDefaultRunAction { + var pid = "0" +// var processName = "" +// var usePid = true + var captureLog = false + + override fun getConfigurationEditor(): SettingsEditor { + val group = SettingsEditorGroup() + group.addEditor("emmy", EmmyAttachDebugSettingsPanel(project)) + return group + } + + override fun getState(executor: Executor, environment: ExecutionEnvironment): RunProfileState { + return LuaCommandLineState(environment) + } + + override fun getValidModules(): Collection { + return emptyList() + } + + override fun writeExternal(element: Element) { + super.writeExternal(element) + JDOMExternalizerUtil.writeField(element, "Pid", pid) +// JDOMExternalizerUtil.writeField(element, "ProcessName", processName) +// JDOMExternalizerUtil.writeField(element, "UsePid", usePid.toString()) + JDOMExternalizerUtil.writeField(element, "CaptureLog", captureLog.toString()) + } + + override fun readExternal(element: Element) { + super.readExternal(element) + JDOMExternalizerUtil.readField(element, "Pid")?.let { + pid = it + } +// JDOMExternalizerUtil.readField(element, "ProcessName")?.let { +// processName = it +// } +// JDOMExternalizerUtil.readField(element, "UsePid")?.let { +// usePid = it == "true" +// } + JDOMExternalizerUtil.readField(element, "CaptureLog")?.let { value -> + captureLog = value == "true" + } + } +} \ No newline at end of file diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt index ca92e21..58c2706 100644 --- a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt @@ -26,7 +26,10 @@ import com.tang.intellij.lua.debugger.LogConsoleType import com.tang.intellij.lua.debugger.emmy.* import com.tang.intellij.lua.debugger.utils.FileUtils -class EmmyAttachDebugProcess(session: XDebugSession, private val processInfo: ProcessInfo) : EmmyDebugProcessBase(session) { +class EmmyAttachDebugProcess( + session: XDebugSession, + private val processInfo: ProcessInfo +) : EmmyDebugProcessBase(session) { override fun setupTransporter() { val suc = attach() if (!suc) { @@ -45,7 +48,7 @@ class EmmyAttachDebugProcess(session: XDebugSession, private val processInfo: Pr transporter.start() } - private fun detectArch(pid: Int): EmmyWinArch { + private fun detectArchByPid(pid: Int): EmmyWinArch { val tool = FileUtils.getPluginVirtualFile("debugger/emmy/windows/x86/emmy_tool.exe") val commandLine = GeneralCommandLine(tool) commandLine.addParameters("arch_pid", "$pid") @@ -56,17 +59,17 @@ class EmmyAttachDebugProcess(session: XDebugSession, private val processInfo: Pr } private fun attach(): Boolean { - val arch = detectArch(processInfo.pid) + val arch = detectArchByPid(processInfo.pid) val path = FileUtils.getPluginVirtualFile("debugger/emmy/windows/${arch}") val commandLine = GeneralCommandLine("${path}/emmy_tool.exe") commandLine.addParameters( - "attach", - "-p", - "${processInfo.pid}", - "-dir", - path, - "-dll", - "emmy_hook.dll" + "attach", + "-p", + "${processInfo.pid}", + "-dir", + path, + "-dll", + "emmy_hook.dll" ) val handler = OSProcessHandler(commandLine) handler.addProcessListener(object : ProcessListener { @@ -81,8 +84,16 @@ class EmmyAttachDebugProcess(session: XDebugSession, private val processInfo: Pr override fun onTextAvailable(processEvent: ProcessEvent, key: Key<*>) { when (key) { - ProcessOutputTypes.STDERR -> print(processEvent.text, LogConsoleType.NORMAL, ConsoleViewContentType.ERROR_OUTPUT) - ProcessOutputTypes.STDOUT -> print(processEvent.text, LogConsoleType.NORMAL, ConsoleViewContentType.SYSTEM_OUTPUT) + ProcessOutputTypes.STDERR -> print( + processEvent.text, + LogConsoleType.NORMAL, + ConsoleViewContentType.ERROR_OUTPUT + ) + ProcessOutputTypes.STDOUT -> print( + processEvent.text, + LogConsoleType.NORMAL, + ConsoleViewContentType.SYSTEM_OUTPUT + ) } } }) @@ -94,8 +105,11 @@ class EmmyAttachDebugProcess(session: XDebugSession, private val processInfo: Pr override fun onReceiveMessage(cmd: MessageCMD, json: String) { if (cmd == MessageCMD.AttachedNotify) { val msg = Gson().fromJson(json, AttachedNotify::class.java) - println("Attached to lua state 0x${msg.state.toString(16)}", LogConsoleType.NORMAL, ConsoleViewContentType.SYSTEM_OUTPUT) - } - else super.onReceiveMessage(cmd, json) + println( + "Attached to lua state 0x${msg.state.toString(16)}", + LogConsoleType.NORMAL, + ConsoleViewContentType.SYSTEM_OUTPUT + ) + } else super.onReceiveMessage(cmd, json) } } \ No newline at end of file diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.form b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.form new file mode 100644 index 0000000..280df08 --- /dev/null +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.form @@ -0,0 +1,34 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.java b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.java new file mode 100644 index 0000000..28328a6 --- /dev/null +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.java @@ -0,0 +1,67 @@ +package com.tang.intellij.lua.debugger.emmyAttach; + +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.options.SettingsEditor; +import com.intellij.openapi.project.Project; +import com.tang.intellij.lua.debugger.utils.ProcessDetailInfo; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +public class EmmyAttachDebugSettingsPanel extends SettingsEditor implements DocumentListener { + private JTextField ProcessId; +// private JCheckBox captureProcessLogCheckBox; + private JPanel panel; +// private JList ProcessList; + + private ButtonGroup UseType; + + public EmmyAttachDebugSettingsPanel(Project project) { + ProcessId.getDocument().addDocumentListener(this); +// DefaultListModel model = new DefaultListModel<>(); +// ProcessList.setModel(model); + +// captureProcessLogCheckBox.addActionListener(e -> onChanged()); + } + + + @Override + protected void resetEditorFrom(@NotNull EmmyAttachDebugConfiguration configuration) { + ProcessId.setText(configuration.getPid()); + +// captureProcessLogCheckBox.setSelected(configuration.getCaptureLog()); + } + + @Override + protected void applyEditorTo(@NotNull EmmyAttachDebugConfiguration configuration) throws ConfigurationException { + configuration.setPid(ProcessId.getText()); +// configuration.setCaptureLog(captureProcessLogCheckBox.isSelected()); + } + + @Override + protected @NotNull + JComponent createEditor() { + return panel; + } + + @Override + public void insertUpdate(DocumentEvent documentEvent) { + onChanged(); + } + + @Override + public void removeUpdate(DocumentEvent documentEvent) { + onChanged(); + } + + @Override + public void changedUpdate(DocumentEvent documentEvent) { + onChanged(); + } + + private void onChanged() { + fireEditorStateChanged(); + } +} diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugger.kt b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugger.kt index 97daf8a..88cf15a 100644 --- a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugger.kt +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugger.kt @@ -27,15 +27,16 @@ import com.tang.intellij.lua.debugger.utils.ProcessDetailInfo import com.tang.intellij.lua.debugger.utils.getDisplayName class EmmyAttachDebugger( - private val processInfo: ProcessInfo, - private val detailInfo: ProcessDetailInfo + private val processInfo: ProcessInfo, + private val detailInfo: ProcessDetailInfo ) : XLocalAttachDebugger { override fun attachDebugSession(project: Project, processInfo: ProcessInfo) { val displayName = "PID:${processInfo.pid}($debuggerDisplayName)" - XDebuggerManager.getInstance(project).startSessionAndShowTab(displayName, null, object : XDebugProcessStarter() { - override fun start(xDebugSession: XDebugSession): XDebugProcess = + XDebuggerManager.getInstance(project) + .startSessionAndShowTab(displayName, null, object : XDebugProcessStarter() { + override fun start(xDebugSession: XDebugSession): XDebugProcess = EmmyAttachDebugProcess(xDebugSession, processInfo) - }) + }) } override fun getDebuggerDisplayName(): String { diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachRunner.kt b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachRunner.kt new file mode 100644 index 0000000..4f849e7 --- /dev/null +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachRunner.kt @@ -0,0 +1,43 @@ +package com.tang.intellij.lua.debugger.emmyAttach + +import com.intellij.execution.configurations.RunProfile +import com.intellij.execution.configurations.RunProfileState +import com.intellij.execution.executors.DefaultDebugExecutor +import com.intellij.execution.process.ProcessInfo +import com.intellij.execution.runners.ExecutionEnvironment +import com.intellij.execution.ui.RunContentDescriptor +import com.intellij.xdebugger.XDebugProcess +import com.intellij.xdebugger.XDebugProcessStarter +import com.intellij.xdebugger.XDebugSession +import com.intellij.xdebugger.XDebuggerManager +import com.tang.intellij.lua.debugger.LuaRunner + + +class EmmyAttachRunner : LuaRunner() { + companion object { + const val ID = "lua.emmyAttach.runner" + } + + var configuration: EmmyAttachDebugConfiguration? = null; + + override fun getRunnerId() = ID + + override fun canRun(executorId: String, runProfile: RunProfile): Boolean { + if (DefaultDebugExecutor.EXECUTOR_ID == executorId && runProfile is EmmyAttachDebugConfiguration) { + configuration = runProfile + return true + } + return false + } + + override fun doExecute(state: RunProfileState, environment: ExecutionEnvironment): RunContentDescriptor { + val manager = XDebuggerManager.getInstance(environment.project) + val session = manager.startSession(environment, object : XDebugProcessStarter() { + override fun start(session: XDebugSession): XDebugProcess { + val processInfo = ProcessInfo(configuration!!.pid.toInt(),"","","") + return EmmyAttachDebugProcess(session, processInfo) + } + }) + return session.runContentDescriptor + } +} \ No newline at end of file From 2ca59232b2985c9e21494b2927940a6fe9e7d015 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Fri, 9 Jul 2021 20:01:35 +0800 Subject: [PATCH 03/15] =?UTF-8?q?work=20around=20=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E6=96=AD=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/tang/intellij/lua/debugger/emmy/protoEx.kt | 9 +++++++++ .../lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt | 11 +++++++++++ .../lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt | 11 ++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/com/tang/intellij/lua/debugger/emmy/protoEx.kt diff --git a/src/com/tang/intellij/lua/debugger/emmy/protoEx.kt b/src/com/tang/intellij/lua/debugger/emmy/protoEx.kt new file mode 100644 index 0000000..d862800 --- /dev/null +++ b/src/com/tang/intellij/lua/debugger/emmy/protoEx.kt @@ -0,0 +1,9 @@ +package com.tang.intellij.lua.debugger.emmy + +// work around 等intellij-idea 加上以后删掉 + +class BreakPointEx(val file: String, val line: Int, val condition: String?) { +} + +class AddBreakPointReqEx(val breakPoints: List) : Message(MessageCMD.AddBreakPointReq) + diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt index 58c2706..c07a26a 100644 --- a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt @@ -22,6 +22,8 @@ import com.intellij.execution.process.* import com.intellij.execution.ui.ConsoleViewContentType import com.intellij.openapi.util.Key import com.intellij.xdebugger.XDebugSession +import com.intellij.xdebugger.XSourcePosition +import com.intellij.xdebugger.breakpoints.XLineBreakpoint import com.tang.intellij.lua.debugger.LogConsoleType import com.tang.intellij.lua.debugger.emmy.* import com.tang.intellij.lua.debugger.utils.FileUtils @@ -102,6 +104,15 @@ class EmmyAttachDebugProcess( return handler.exitCode == 0 } + // work around 等以后删掉 + override fun registerBreakpoint(sourcePosition: XSourcePosition, breakpoint: XLineBreakpoint<*>) { + val file = sourcePosition.file + val shortPath = file.canonicalPath + if (shortPath != null) { + send(AddBreakPointReqEx(listOf(BreakPointEx(shortPath, breakpoint.line + 1, breakpoint.conditionExpression?.expression)))) + } + } + override fun onReceiveMessage(cmd: MessageCMD, json: String) { if (cmd == MessageCMD.AttachedNotify) { val msg = Gson().fromJson(json, AttachedNotify::class.java) diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt index 1ce5589..1338742 100644 --- a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt +++ b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt @@ -6,6 +6,8 @@ import com.intellij.execution.process.* import com.intellij.execution.ui.ConsoleViewContentType import com.intellij.openapi.util.Key import com.intellij.xdebugger.XDebugSession +import com.intellij.xdebugger.XSourcePosition +import com.intellij.xdebugger.breakpoints.XLineBreakpoint import com.tang.intellij.lua.debugger.LogConsoleType import com.tang.intellij.lua.debugger.emmy.* import com.tang.intellij.lua.debugger.utils.FileUtils @@ -214,7 +216,14 @@ class EmmyLaunchDebugProcess(session: XDebugSession, val configuration: EmmyLaun } - + // work around 等以后删掉 + override fun registerBreakpoint(sourcePosition: XSourcePosition, breakpoint: XLineBreakpoint<*>) { + val file = sourcePosition.file + val shortPath = file.canonicalPath + if (shortPath != null) { + send(AddBreakPointReqEx(listOf(BreakPointEx(shortPath, breakpoint.line + 1, breakpoint.conditionExpression?.expression)))) + } + } override fun onReceiveMessage(cmd: MessageCMD, json: String) { if (cmd == MessageCMD.AttachedNotify) { From 5a73ec76c90c913c0c1ab8b6836da7d22a12a40f Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Mon, 12 Jul 2021 10:43:03 +0800 Subject: [PATCH 04/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dlaunch=20=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E6=9C=AA=E8=83=BD=E6=AD=A3=E7=A1=AE=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt index 1338742..70d6d65 100644 --- a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt +++ b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt @@ -158,7 +158,6 @@ class EmmyLaunchDebugProcess(session: XDebugSession, val configuration: EmmyLaun "\"${path}\"", "-work", "\"${configuration.workingDirectory}\"", - "-block-on-exit", "-exe", "\"${configuration.program}\"", "-debug-port", @@ -225,6 +224,11 @@ class EmmyLaunchDebugProcess(session: XDebugSession, val configuration: EmmyLaun } } + override fun onDisconnect() { + super.onDisconnect() + client?.close() + } + override fun onReceiveMessage(cmd: MessageCMD, json: String) { if (cmd == MessageCMD.AttachedNotify) { val msg = Gson().fromJson(json, AttachedNotify::class.java) From 4c0717e6571f04a3cfa165f65fc553a7dd55dd19 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Sun, 12 Sep 2021 14:45:59 +0800 Subject: [PATCH 05/15] =?UTF-8?q?=E5=8F=96=E6=B6=88workaround=EF=BC=8C?= =?UTF-8?q?=E5=90=84=E7=A7=8D=E8=B0=83=E8=AF=95=E7=89=B9=E6=80=A7=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E4=B8=BA=E4=B8=BB=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt | 8 -------- .../lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt | 8 -------- 2 files changed, 16 deletions(-) diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt index c07a26a..0eb208c 100644 --- a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt @@ -104,14 +104,6 @@ class EmmyAttachDebugProcess( return handler.exitCode == 0 } - // work around 等以后删掉 - override fun registerBreakpoint(sourcePosition: XSourcePosition, breakpoint: XLineBreakpoint<*>) { - val file = sourcePosition.file - val shortPath = file.canonicalPath - if (shortPath != null) { - send(AddBreakPointReqEx(listOf(BreakPointEx(shortPath, breakpoint.line + 1, breakpoint.conditionExpression?.expression)))) - } - } override fun onReceiveMessage(cmd: MessageCMD, json: String) { if (cmd == MessageCMD.AttachedNotify) { diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt index 70d6d65..5bd5744 100644 --- a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt +++ b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt @@ -215,14 +215,6 @@ class EmmyLaunchDebugProcess(session: XDebugSession, val configuration: EmmyLaun } - // work around 等以后删掉 - override fun registerBreakpoint(sourcePosition: XSourcePosition, breakpoint: XLineBreakpoint<*>) { - val file = sourcePosition.file - val shortPath = file.canonicalPath - if (shortPath != null) { - send(AddBreakPointReqEx(listOf(BreakPointEx(shortPath, breakpoint.line + 1, breakpoint.conditionExpression?.expression)))) - } - } override fun onDisconnect() { super.onDisconnect() From c4475ac1006424773049d9c2091b41eae9c09fc7 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Fri, 24 Sep 2021 15:37:52 +0800 Subject: [PATCH 06/15] =?UTF-8?q?api=E7=89=88=E6=9C=AC=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E5=88=B0202=EF=BC=8C=E9=99=84=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=9A=E8=BF=87=E8=BF=9B=E7=A8=8Btitle?= =?UTF-8?q?=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/META-INF/plugin.xml | 3 +- .../intellij/lua/debugger/emmy/protoEx.kt | 9 -- .../emmyAttach/EmmyAttachConfigurationType.kt | 47 +++--- .../emmyAttach/EmmyAttachDebugProcess.kt | 11 -- .../EmmyAttachDebugSettingsPanel.form | 65 +++++++- .../EmmyAttachDebugSettingsPanel.java | 41 ++++- .../emmyAttach/EmmyAttachDebuggerProvider.kt | 14 +- .../debugger/emmyAttach/EmmyAttachGroup.kt | 18 ++- .../debugger/emmyAttach/EmmyAttachRunner.kt | 11 +- .../EmmyConfigAttachDebugProcess.kt | 151 ++++++++++++++++++ .../emmyLaunch/EmmyLaunchConfigurationType.kt | 8 +- .../emmyLaunch/EmmyLaunchDebugProcess.kt | 125 +++++++-------- .../debugger/emmyLaunch/EmmyLaunchRunner.kt | 6 +- .../lua/debugger/utils/ProcessUtils.kt | 29 +++- 14 files changed, 401 insertions(+), 137 deletions(-) delete mode 100644 src/com/tang/intellij/lua/debugger/emmy/protoEx.kt create mode 100644 src/com/tang/intellij/lua/debugger/emmyAttach/EmmyConfigAttachDebugProcess.kt diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 3efe64a..0627432 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -8,7 +8,7 @@ EmmyLua Attach Debugger Plugin for EmmyLua ]]> - + com.intellij.modules.platform com.tang @@ -16,6 +16,7 @@ + diff --git a/src/com/tang/intellij/lua/debugger/emmy/protoEx.kt b/src/com/tang/intellij/lua/debugger/emmy/protoEx.kt deleted file mode 100644 index d862800..0000000 --- a/src/com/tang/intellij/lua/debugger/emmy/protoEx.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.tang.intellij.lua.debugger.emmy - -// work around 等intellij-idea 加上以后删掉 - -class BreakPointEx(val file: String, val line: Int, val condition: String?) { -} - -class AddBreakPointReqEx(val breakPoints: List) : Message(MessageCMD.AddBreakPointReq) - diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachConfigurationType.kt b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachConfigurationType.kt index e5d3381..51211d2 100644 --- a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachConfigurationType.kt +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachConfigurationType.kt @@ -13,13 +13,14 @@ import com.intellij.openapi.options.SettingsEditorGroup import com.intellij.openapi.project.Project import com.intellij.openapi.util.JDOMExternalizerUtil import com.tang.intellij.lua.debugger.LuaCommandLineState -import com.tang.intellij.lua.debugger.LuaConfigurationFactory import com.tang.intellij.lua.debugger.LuaRunConfiguration import com.tang.intellij.lua.lang.LuaIcons import org.jdom.Element import javax.swing.Icon +import com.tang.intellij.lua.debugger.LuaConfigurationFactory +import com.tang.intellij.lua.debugger.emmy.EmmyDebugTransportType -class EmmyAttachConfigurationType : ConfigurationType { +class EmmyAttachConfigurationType : ConfigurationType { override fun getIcon(): Icon { return LuaIcons.FILE } @@ -37,10 +38,18 @@ class EmmyAttachConfigurationType : ConfigurationType { } override fun getConfigurationFactories(): Array { - return arrayOf( EmmyAttachDebuggerConfigurationFactory(this)) + return arrayOf(EmmyAttachDebuggerConfigurationFactory(this)) } } +enum class EmmyAttachMode(private val desc: String) { + Pid("Pid"), + ProcessName("ProcessName"); + + override fun toString(): String { + return desc; + } +} class EmmyAttachDebuggerConfigurationFactory(val type: EmmyAttachConfigurationType) : LuaConfigurationFactory(type) { override fun createTemplateConfiguration(project: Project): RunConfiguration { @@ -48,12 +57,13 @@ class EmmyAttachDebuggerConfigurationFactory(val type: EmmyAttachConfigurationTy } } -class EmmyAttachDebugConfiguration(project: Project, factory: EmmyAttachDebuggerConfigurationFactory) : LuaRunConfiguration(project, factory), +class EmmyAttachDebugConfiguration(project: Project, factory: EmmyAttachDebuggerConfigurationFactory) : + LuaRunConfiguration(project, factory), RunConfigurationWithSuppressedDefaultRunAction { + var attachMode = EmmyAttachMode.Pid; var pid = "0" -// var processName = "" -// var usePid = true - var captureLog = false + var processName = "" + var encoding = "gbk" override fun getConfigurationEditor(): SettingsEditor { val group = SettingsEditorGroup() @@ -71,25 +81,26 @@ class EmmyAttachDebugConfiguration(project: Project, factory: EmmyAttachDebugger override fun writeExternal(element: Element) { super.writeExternal(element) + JDOMExternalizerUtil.writeField(element, "AttachMode", attachMode.ordinal.toString()) JDOMExternalizerUtil.writeField(element, "Pid", pid) -// JDOMExternalizerUtil.writeField(element, "ProcessName", processName) -// JDOMExternalizerUtil.writeField(element, "UsePid", usePid.toString()) - JDOMExternalizerUtil.writeField(element, "CaptureLog", captureLog.toString()) + JDOMExternalizerUtil.writeField(element, "ProcessName", processName) + JDOMExternalizerUtil.writeField(element, "Encoding", encoding) } override fun readExternal(element: Element) { super.readExternal(element) + JDOMExternalizerUtil.readField(element, "AttachMode")?.let { value -> + val i = value.toInt() + attachMode = EmmyAttachMode.values().find { it.ordinal == i } ?: EmmyAttachMode.Pid + } JDOMExternalizerUtil.readField(element, "Pid")?.let { pid = it } -// JDOMExternalizerUtil.readField(element, "ProcessName")?.let { -// processName = it -// } -// JDOMExternalizerUtil.readField(element, "UsePid")?.let { -// usePid = it == "true" -// } - JDOMExternalizerUtil.readField(element, "CaptureLog")?.let { value -> - captureLog = value == "true" + JDOMExternalizerUtil.readField(element, "ProcessName")?.let { + processName = it + } + JDOMExternalizerUtil.readField(element, "Encoding")?.let { + encoding = it } } } \ No newline at end of file diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt index c07a26a..58c2706 100644 --- a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt @@ -22,8 +22,6 @@ import com.intellij.execution.process.* import com.intellij.execution.ui.ConsoleViewContentType import com.intellij.openapi.util.Key import com.intellij.xdebugger.XDebugSession -import com.intellij.xdebugger.XSourcePosition -import com.intellij.xdebugger.breakpoints.XLineBreakpoint import com.tang.intellij.lua.debugger.LogConsoleType import com.tang.intellij.lua.debugger.emmy.* import com.tang.intellij.lua.debugger.utils.FileUtils @@ -104,15 +102,6 @@ class EmmyAttachDebugProcess( return handler.exitCode == 0 } - // work around 等以后删掉 - override fun registerBreakpoint(sourcePosition: XSourcePosition, breakpoint: XLineBreakpoint<*>) { - val file = sourcePosition.file - val shortPath = file.canonicalPath - if (shortPath != null) { - send(AddBreakPointReqEx(listOf(BreakPointEx(shortPath, breakpoint.line + 1, breakpoint.conditionExpression?.expression)))) - } - } - override fun onReceiveMessage(cmd: MessageCMD, json: String) { if (cmd == MessageCMD.AttachedNotify) { val msg = Gson().fromJson(json, AttachedNotify::class.java) diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.form b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.form index 280df08..bca49bb 100644 --- a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.form +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.form @@ -1,6 +1,6 @@
- + @@ -10,12 +10,12 @@ - + - + @@ -29,6 +29,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.java b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.java index 28328a6..1df8332 100644 --- a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.java +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.java @@ -12,32 +12,57 @@ public class EmmyAttachDebugSettingsPanel extends SettingsEditor implements DocumentListener { private JTextField ProcessId; -// private JCheckBox captureProcessLogCheckBox; + private JPanel panel; -// private JList ProcessList; + private JTextField ProcessName; + private JTextField Encoding; - private ButtonGroup UseType; + private JRadioButton UsePid; + private JRadioButton UseProcessName; + private JPanel AttachMode; + private ButtonGroup AttachModeGroup; public EmmyAttachDebugSettingsPanel(Project project) { ProcessId.getDocument().addDocumentListener(this); -// DefaultListModel model = new DefaultListModel<>(); -// ProcessList.setModel(model); + ProcessName.getDocument().addDocumentListener(this); + + Encoding.setText("gbk"); + Encoding.getDocument().addDocumentListener(this); -// captureProcessLogCheckBox.addActionListener(e -> onChanged()); + AttachModeGroup = new ButtonGroup(); + AttachModeGroup.add(UsePid); + AttachModeGroup.add(UseProcessName); + UsePid.addChangeListener(e -> onChanged()); + UseProcessName.addChangeListener(e -> onChanged()); } @Override protected void resetEditorFrom(@NotNull EmmyAttachDebugConfiguration configuration) { ProcessId.setText(configuration.getPid()); + ProcessName.setText(configuration.getProcessName()); + Encoding.setText(configuration.getEncoding()); + + if(configuration.getAttachMode() == EmmyAttachMode.Pid){ + UsePid.setSelected(true); + } + else if(configuration.getAttachMode() == EmmyAttachMode.ProcessName){ + UseProcessName.setSelected(true); + } -// captureProcessLogCheckBox.setSelected(configuration.getCaptureLog()); } @Override protected void applyEditorTo(@NotNull EmmyAttachDebugConfiguration configuration) throws ConfigurationException { configuration.setPid(ProcessId.getText()); -// configuration.setCaptureLog(captureProcessLogCheckBox.isSelected()); + configuration.setProcessName(ProcessName.getText()); + configuration.setEncoding(Encoding.getText()); + + if (UsePid.isSelected()) { + configuration.setAttachMode(EmmyAttachMode.Pid); + } else if (UseProcessName.isSelected()) { + configuration.setAttachMode(EmmyAttachMode.ProcessName); + } } @Override diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebuggerProvider.kt b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebuggerProvider.kt index 13e8865..cb4340a 100644 --- a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebuggerProvider.kt +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebuggerProvider.kt @@ -25,20 +25,25 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.util.Key import com.intellij.openapi.util.SystemInfoRt import com.intellij.openapi.util.UserDataHolder +import com.intellij.xdebugger.attach.XAttachDebuggerProvider +import com.intellij.xdebugger.attach.XAttachHost import com.intellij.xdebugger.attach.XLocalAttachDebugger -import com.intellij.xdebugger.attach.XLocalAttachDebuggerProvider import com.tang.intellij.lua.debugger.utils.FileUtils import com.tang.intellij.lua.debugger.utils.ProcessDetailInfo import com.tang.intellij.lua.debugger.utils.listProcesses -class EmmyAttachDebuggerProvider : XLocalAttachDebuggerProvider { +class EmmyAttachDebuggerProvider : XAttachDebuggerProvider { companion object { val DETAIL_KEY = Key.create>("LuaLocalAttachDebuggerProvider.key") } private var processMap = mapOf() - override fun getAvailableDebuggers(project: Project, processInfo: ProcessInfo, userDataHolder: UserDataHolder): List { + override fun isAttachHostApplicable(p0: XAttachHost): Boolean { + return true + } + + override fun getAvailableDebuggers(project: Project, attachHost: XAttachHost , processInfo: ProcessInfo, userDataHolder: UserDataHolder): List { if (!SystemInfoRt.isWindows) return emptyList() if (userDataHolder.getUserData(DETAIL_KEY) == null) { @@ -69,5 +74,6 @@ class EmmyAttachDebuggerProvider : XLocalAttachDebuggerProvider { return emptyList() } - override fun getAttachGroup() = EmmyAttachGroup.instance + override fun getPresentationGroup() = EmmyAttachGroup.instance + } \ No newline at end of file diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt index 80e7e9c..d96b5ca 100644 --- a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt @@ -14,25 +14,26 @@ * limitations under the License. */ + package com.tang.intellij.lua.debugger.emmyAttach import com.intellij.execution.process.ProcessInfo import com.intellij.openapi.project.Project import com.intellij.openapi.util.UserDataHolder -import com.intellij.xdebugger.attach.XLocalAttachGroup +import com.intellij.xdebugger.attach.XAttachProcessPresentationGroup import com.tang.intellij.lua.debugger.utils.getDisplayName import com.tang.intellij.lua.lang.LuaIcons import java.io.File import javax.swing.Icon import javax.swing.filechooser.FileSystemView -class EmmyAttachGroup : XLocalAttachGroup { +class EmmyAttachGroup : XAttachProcessPresentationGroup { companion object { val instance = EmmyAttachGroup() } - override fun getProcessDisplayText(project: Project, processInfo: ProcessInfo, userDataHolder: UserDataHolder): String { + override fun getItemDisplayText(project: Project, processInfo: ProcessInfo, userDataHolder: UserDataHolder): String { val map = userDataHolder.getUserData(EmmyAttachDebuggerProvider.DETAIL_KEY) if (map != null) { val detail = map[processInfo.pid] @@ -42,7 +43,7 @@ class EmmyAttachGroup : XLocalAttachGroup { return processInfo.executableName } - override fun getProcessIcon(project: Project, processInfo: ProcessInfo, userDataHolder: UserDataHolder): Icon { + override fun getItemIcon(project: Project, processInfo: ProcessInfo, userDataHolder: UserDataHolder): Icon { val map = userDataHolder.getUserData(EmmyAttachDebuggerProvider.DETAIL_KEY) if (map != null) { val detail = map[processInfo.pid] @@ -59,10 +60,17 @@ class EmmyAttachGroup : XLocalAttachGroup { override fun getGroupName() = "EmmyLua Attach Debugger" - override fun compare(project: Project, a: ProcessInfo, b: ProcessInfo, userDataHolder: UserDataHolder) = + override fun compare(a: ProcessInfo, b: ProcessInfo): Int = a.executableName.toLowerCase().compareTo(b.executableName.toLowerCase()) override fun getOrder(): Int { return 0 } + + override fun getProcessIcon(p0: Project, p1: ProcessInfo, p2: UserDataHolder): Icon { + return getItemIcon(p0,p1,p2); + } + override fun getProcessDisplayText(p0: Project, p1: ProcessInfo, p2: UserDataHolder): String { + return getItemDisplayText(p0,p1,p2); + } } \ No newline at end of file diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachRunner.kt b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachRunner.kt index 4f849e7..d3cc0e5 100644 --- a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachRunner.kt +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachRunner.kt @@ -2,15 +2,22 @@ package com.tang.intellij.lua.debugger.emmyAttach import com.intellij.execution.configurations.RunProfile import com.intellij.execution.configurations.RunProfileState +import com.intellij.execution.configurations.RunnerSettings import com.intellij.execution.executors.DefaultDebugExecutor import com.intellij.execution.process.ProcessInfo +import com.intellij.execution.runners.AsyncProgramRunner import com.intellij.execution.runners.ExecutionEnvironment +import com.intellij.execution.runners.GenericProgramRunner +import com.intellij.execution.runners.ProgramRunner import com.intellij.execution.ui.RunContentDescriptor +import com.intellij.openapi.ui.popup.JBPopupFactory import com.intellij.xdebugger.XDebugProcess import com.intellij.xdebugger.XDebugProcessStarter import com.intellij.xdebugger.XDebugSession import com.intellij.xdebugger.XDebuggerManager import com.tang.intellij.lua.debugger.LuaRunner +import org.jetbrains.concurrency.AsyncPromise +import org.jetbrains.concurrency.Promise class EmmyAttachRunner : LuaRunner() { @@ -34,10 +41,10 @@ class EmmyAttachRunner : LuaRunner() { val manager = XDebuggerManager.getInstance(environment.project) val session = manager.startSession(environment, object : XDebugProcessStarter() { override fun start(session: XDebugSession): XDebugProcess { - val processInfo = ProcessInfo(configuration!!.pid.toInt(),"","","") - return EmmyAttachDebugProcess(session, processInfo) + return EmmyConfigAttachDebugProcess(session, configuration!!) } }) return session.runContentDescriptor } + } \ No newline at end of file diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyConfigAttachDebugProcess.kt b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyConfigAttachDebugProcess.kt new file mode 100644 index 0000000..239aba2 --- /dev/null +++ b/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyConfigAttachDebugProcess.kt @@ -0,0 +1,151 @@ +package com.tang.intellij.lua.debugger.emmyAttach + +import com.google.gson.Gson +import com.intellij.execution.configurations.GeneralCommandLine +import com.intellij.execution.process.OSProcessHandler +import com.intellij.execution.process.ProcessEvent +import com.intellij.execution.process.ProcessListener +import com.intellij.execution.process.ProcessOutputTypes +import com.intellij.execution.ui.ConsoleViewContentType +import com.intellij.openapi.ui.popup.JBPopupFactory +import com.intellij.openapi.util.Key +import com.intellij.xdebugger.XDebugSession +import com.tang.intellij.lua.debugger.LogConsoleType +import com.tang.intellij.lua.debugger.emmy.* +import com.tang.intellij.lua.debugger.utils.FileUtils +import com.tang.intellij.lua.debugger.utils.ProcessDetailInfo +import com.tang.intellij.lua.debugger.utils.listProcessesByEncoding + + +class EmmyConfigAttachDebugProcess( + session: XDebugSession, + val configuration: EmmyAttachDebugConfiguration +) : EmmyDebugProcessBase(session) { + + private var pid: Int = 0 + + override fun sessionInitialized() { + val attachMode = configuration.attachMode + + + if (attachMode == EmmyAttachMode.Pid) { + pid = configuration.pid.toInt() + return super.sessionInitialized() + } + + val processName = configuration.processName + val processes = listProcessesByEncoding(configuration.encoding) + val attachableList = mutableListOf() + for (info in processes) { + if (info.title.indexOf(processName) != -1 || info.path.indexOf(processName) != -1) { + attachableList.add(info) + } + } + + if (attachableList.size == 1) { + pid = attachableList.first().pid + return super.sessionInitialized() + } + + val jbInstance = JBPopupFactory.getInstance() + val displayMap = mutableMapOf() + + for (processDetailInfo in attachableList) { + displayMap["${processDetailInfo.pid}:${processDetailInfo.title}"] = processDetailInfo + } + + jbInstance.createPopupChooserBuilder(displayMap.keys.toList()) + .setTitle("choose best match process") + .setMovable(true) + .setItemChosenCallback { + val processDetailInfo = displayMap[it] + if (processDetailInfo != null) { + pid = processDetailInfo.pid + } + super.sessionInitialized() + }.createPopup().showInFocusCenter() + } + + override fun setupTransporter() { + val suc = attach() + if (!suc) { + session.stop() + return + } + var port = pid + // 1024 - 65535 + while (port > 0xffff) port -= 0xffff + while (port < 0x400) port += 0x400 + + val transporter = SocketClientTransporter("localhost", port) + transporter.handler = this + transporter.logger = this + this.transporter = transporter + transporter.start() + } + + private fun detectArchByPid(pid: Int): EmmyWinArch { + val tool = FileUtils.getPluginVirtualFile("debugger/emmy/windows/x86/emmy_tool.exe") + val commandLine = GeneralCommandLine(tool) + commandLine.addParameters("arch_pid", "$pid") + val process = commandLine.createProcess() + process.waitFor() + val exitValue = process.exitValue() + return if (exitValue == 0) EmmyWinArch.X64 else EmmyWinArch.X86 + } + + private fun attach(): Boolean { + val arch = detectArchByPid(pid) + val path = FileUtils.getPluginVirtualFile("debugger/emmy/windows/${arch}") + val commandLine = GeneralCommandLine("${path}/emmy_tool.exe") + commandLine.addParameters( + "attach", + "-p", + "${pid}", + "-dir", + path, + "-dll", + "emmy_hook.dll" + ) + val handler = OSProcessHandler(commandLine) + handler.addProcessListener(object : ProcessListener { + override fun startNotified(processEvent: ProcessEvent) { + } + + override fun processTerminated(processEvent: ProcessEvent) { + } + + override fun processWillTerminate(processEvent: ProcessEvent, b: Boolean) { + } + + override fun onTextAvailable(processEvent: ProcessEvent, key: Key<*>) { + when (key) { + ProcessOutputTypes.STDERR -> print( + processEvent.text, + LogConsoleType.NORMAL, + ConsoleViewContentType.ERROR_OUTPUT + ) + ProcessOutputTypes.STDOUT -> print( + processEvent.text, + LogConsoleType.NORMAL, + ConsoleViewContentType.SYSTEM_OUTPUT + ) + } + } + }) + handler.startNotify() + handler.waitFor() + return handler.exitCode == 0 + } + + override fun onReceiveMessage(cmd: MessageCMD, json: String) { + if (cmd == MessageCMD.AttachedNotify) { + val msg = Gson().fromJson(json, AttachedNotify::class.java) + println( + "Attached to lua state 0x${msg.state.toString(16)}", + LogConsoleType.NORMAL, + ConsoleViewContentType.SYSTEM_OUTPUT + ) + } else super.onReceiveMessage(cmd, json) + } +} \ No newline at end of file diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchConfigurationType.kt b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchConfigurationType.kt index 9ecb294..03cdc63 100644 --- a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchConfigurationType.kt +++ b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchConfigurationType.kt @@ -1,10 +1,7 @@ package com.tang.intellij.lua.debugger.emmyLaunch import com.intellij.execution.Executor -import com.intellij.execution.configurations.ConfigurationFactory -import com.intellij.execution.configurations.ConfigurationType -import com.intellij.execution.configurations.RunConfiguration -import com.intellij.execution.configurations.RunProfileState +import com.intellij.execution.configurations.* import com.intellij.execution.runners.ExecutionEnvironment import com.intellij.execution.runners.RunConfigurationWithSuppressedDefaultRunAction import com.intellij.openapi.module.Module @@ -19,6 +16,7 @@ import com.tang.intellij.lua.lang.LuaIcons import org.jdom.Element import javax.swing.Icon + class EmmyLaunchConfigurationType : ConfigurationType { override fun getIcon(): Icon { return LuaIcons.FILE @@ -92,4 +90,6 @@ class EmmyLaunchDebugConfiguration(project: Project, factory: EmmyLaunchDebugger useWindowsTerminal = value == "true" } } + + } \ No newline at end of file diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt index 70d6d65..c228bc6 100644 --- a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt +++ b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt @@ -2,8 +2,10 @@ package com.tang.intellij.lua.debugger.emmyLaunch import com.google.gson.Gson import com.intellij.execution.configurations.GeneralCommandLine +import com.intellij.execution.filters.TextConsoleBuilderFactory import com.intellij.execution.process.* import com.intellij.execution.ui.ConsoleViewContentType +import com.intellij.openapi.project.Project import com.intellij.openapi.util.Key import com.intellij.xdebugger.XDebugSession import com.intellij.xdebugger.XSourcePosition @@ -11,20 +13,20 @@ import com.intellij.xdebugger.breakpoints.XLineBreakpoint import com.tang.intellij.lua.debugger.LogConsoleType import com.tang.intellij.lua.debugger.emmy.* import com.tang.intellij.lua.debugger.utils.FileUtils -import kotlinx.coroutines.Delay -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch import java.io.BufferedReader import java.io.BufferedWriter import java.io.InputStreamReader import java.io.OutputStreamWriter import java.net.Socket import java.util.concurrent.ThreadLocalRandom -import kotlin.random.Random -class EmmyLaunchDebugProcess(session: XDebugSession, val configuration: EmmyLaunchDebugConfiguration) : - EmmyDebugProcessBase(session) { + +class EmmyLaunchDebugProcess( + session: XDebugSession, + val configuration: EmmyLaunchDebugConfiguration, + val project: Project +) : + EmmyDebugProcessBase(session) { var client: Socket? = null @@ -74,24 +76,24 @@ class EmmyLaunchDebugProcess(session: XDebugSession, val configuration: EmmyLaun commandLine.exePath = "wt" commandLine.setWorkDirectory(path) commandLine.addParameters( - "--title", - if (mc != null) mc.groups[0]?.value else configuration.program, - "emmy_tool.exe", - "run_and_attach", - "-dll", - "emmy_hook.dll", - "-dir", - "\"${path}\"", - "-work", - "\"${configuration.workingDirectory}\"", - "-block-on-exit", - "-exe", - "\"${configuration.program}\"", - "-debug-port", - port.toString(), - "-listen-mode", - "-args", - "\"${configuration.parameter}\"" + "--title", + if (mc != null) mc.groups[0]?.value else configuration.program, + "emmy_tool.exe", + "run_and_attach", + "-dll", + "emmy_hook.dll", + "-dir", + "\"${path}\"", + "-work", + "\"${configuration.workingDirectory}\"", + "-block-on-exit", + "-exe", + "\"${configuration.program}\"", + "-debug-port", + port.toString(), + "-listen-mode", + "-args", + "\"${configuration.parameter}\"" ) val handler = OSProcessHandler(commandLine) @@ -108,14 +110,14 @@ class EmmyLaunchDebugProcess(session: XDebugSession, val configuration: EmmyLaun override fun onTextAvailable(processEvent: ProcessEvent, key: Key<*>) { when (key) { ProcessOutputTypes.STDERR -> print( - processEvent.text, - LogConsoleType.NORMAL, - ConsoleViewContentType.ERROR_OUTPUT + processEvent.text, + LogConsoleType.NORMAL, + ConsoleViewContentType.ERROR_OUTPUT ) ProcessOutputTypes.STDOUT -> print( - processEvent.text, - LogConsoleType.NORMAL, - ConsoleViewContentType.SYSTEM_OUTPUT + processEvent.text, + LogConsoleType.NORMAL, + ConsoleViewContentType.SYSTEM_OUTPUT ) } } @@ -144,31 +146,30 @@ class EmmyLaunchDebugProcess(session: XDebugSession, val configuration: EmmyLaun val port = getPort(ThreadLocalRandom.current().nextInt(10240) + 10240); val arch = detectArch() val path = FileUtils.getPluginVirtualFile("debugger/emmy/windows/${arch}") -// val re = Regex("[^/\\\\]+\$") -// val mc = re.find(configuration.program) val commandLine = GeneralCommandLine() commandLine.exePath = "${path}/emmy_tool.exe" commandLine.setWorkDirectory(path) commandLine.addParameters( - "run_and_attach", - "-dll", - "emmy_hook.dll", - "-dir", - "\"${path}\"", - "-work", - "\"${configuration.workingDirectory}\"", - "-exe", - "\"${configuration.program}\"", - "-debug-port", - port.toString(), - "-listen-mode", - "-args", - "\"${configuration.parameter}\"" + "run_and_attach", + "-dll", + "emmy_hook.dll", + "-dir", + "\"${path}\"", + "-work", + "\"${configuration.workingDirectory}\"", + "-exe", + "\"${configuration.program}\"", + "-unitbuf", + "-debug-port", + port.toString(), + "-listen-mode", + "-args", + "\"${configuration.parameter}\"" ) - val handler = OSProcessHandler(commandLine) + val handler = ColoredProcessHandler(commandLine) handler.addProcessListener(object : ProcessListener { override fun startNotified(processEvent: ProcessEvent) { } @@ -182,18 +183,19 @@ class EmmyLaunchDebugProcess(session: XDebugSession, val configuration: EmmyLaun override fun onTextAvailable(processEvent: ProcessEvent, key: Key<*>) { when (key) { ProcessOutputTypes.STDERR -> print( - processEvent.text, - LogConsoleType.NORMAL, - ConsoleViewContentType.ERROR_OUTPUT + processEvent.text, + LogConsoleType.NORMAL, + ConsoleViewContentType.ERROR_OUTPUT ) ProcessOutputTypes.STDOUT -> print( - processEvent.text, - LogConsoleType.NORMAL, - ConsoleViewContentType.SYSTEM_OUTPUT + processEvent.text, + LogConsoleType.NORMAL, + ConsoleViewContentType.SYSTEM_OUTPUT ) } } }) + handler.startNotify() client = Socket("localhost", port) @@ -215,15 +217,6 @@ class EmmyLaunchDebugProcess(session: XDebugSession, val configuration: EmmyLaun } - // work around 等以后删掉 - override fun registerBreakpoint(sourcePosition: XSourcePosition, breakpoint: XLineBreakpoint<*>) { - val file = sourcePosition.file - val shortPath = file.canonicalPath - if (shortPath != null) { - send(AddBreakPointReqEx(listOf(BreakPointEx(shortPath, breakpoint.line + 1, breakpoint.conditionExpression?.expression)))) - } - } - override fun onDisconnect() { super.onDisconnect() client?.close() @@ -233,9 +226,9 @@ class EmmyLaunchDebugProcess(session: XDebugSession, val configuration: EmmyLaun if (cmd == MessageCMD.AttachedNotify) { val msg = Gson().fromJson(json, AttachedNotify::class.java) println( - "Attached to lua state 0x${msg.state.toString(16)}", - LogConsoleType.NORMAL, - ConsoleViewContentType.SYSTEM_OUTPUT + "Attached to lua state 0x${msg.state.toString(16)}", + LogConsoleType.NORMAL, + ConsoleViewContentType.SYSTEM_OUTPUT ) } else super.onReceiveMessage(cmd, json) } diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchRunner.kt b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchRunner.kt index ed24908..838aae9 100644 --- a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchRunner.kt +++ b/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchRunner.kt @@ -10,7 +10,6 @@ import com.intellij.xdebugger.XDebugProcessStarter import com.intellij.xdebugger.XDebugSession import com.intellij.xdebugger.XDebuggerManager import com.tang.intellij.lua.debugger.LuaRunner -import com.tang.intellij.lua.debugger.emmy.EmmyDebugProcess class EmmyLaunchRunner : LuaRunner() { companion object { @@ -29,10 +28,11 @@ class EmmyLaunchRunner : LuaRunner() { } override fun doExecute(state: RunProfileState, environment: ExecutionEnvironment): RunContentDescriptor { - val manager = XDebuggerManager.getInstance(environment.project) + val project = environment.project + val manager = XDebuggerManager.getInstance(project) val session = manager.startSession(environment, object : XDebugProcessStarter() { override fun start(session: XDebugSession): XDebugProcess { - return EmmyLaunchDebugProcess(session, configuration!!) + return EmmyLaunchDebugProcess(session, configuration!!, project) } }) return session.runContentDescriptor diff --git a/src/com/tang/intellij/lua/debugger/utils/ProcessUtils.kt b/src/com/tang/intellij/lua/debugger/utils/ProcessUtils.kt index 360165e..87d2520 100644 --- a/src/com/tang/intellij/lua/debugger/utils/ProcessUtils.kt +++ b/src/com/tang/intellij/lua/debugger/utils/ProcessUtils.kt @@ -19,11 +19,12 @@ package com.tang.intellij.lua.debugger.utils import com.intellij.execution.configurations.GeneralCommandLine import com.intellij.execution.process.ProcessInfo import com.intellij.execution.util.ExecUtil +import java.nio.charset.Charset data class ProcessDetailInfo( - var pid: Int = 0, - var path: String = "", - var title: String = "" + var pid: Int = 0, + var path: String = "", + var title: String = "", ) private const val MAX_DISPLAY_LEN = 60 @@ -58,4 +59,26 @@ fun listProcesses(): Map { processMap[pid] = p } return processMap +} + +fun listProcessesByEncoding(encoding: String): List { + val processes = mutableListOf() + val archExe = FileUtils.archExeFile ?: return processes + val commandLine = GeneralCommandLine(archExe) + commandLine.charset = Charset.forName(encoding) + commandLine.addParameters("list_processes") + + val processOutput = ExecUtil.execAndGetOutput(commandLine) + + val text = processOutput.stdout + val lines= text.split("\n") + val size = lines.size / 4 + for (i in 0 until size) { + val pid = lines[i * 4 + 0].toInt() + val title = lines[i * 4 + 1] + val path = lines[i * 4 + 2] + val p = ProcessDetailInfo(pid, path, title) + processes.add(p) + } + return processes } \ No newline at end of file From 33aca07d40721c5cad854d996ccfb3b4beb21ccb Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Fri, 9 Dec 2022 11:41:57 +0800 Subject: [PATCH 07/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 11 ++++---- gradle.properties | 26 ------------------- settings.gradle.kts | 1 + .../emmyAttach/EmmyAttachConfigurationType.kt | 0 .../emmyAttach/EmmyAttachDebugProcess.kt | 0 .../EmmyAttachDebugSettingsPanel.form | 0 .../EmmyAttachDebugSettingsPanel.java | 0 .../debugger/emmyAttach/EmmyAttachDebugger.kt | 0 .../emmyAttach/EmmyAttachDebuggerProvider.kt | 0 .../debugger/emmyAttach/EmmyAttachGroup.kt | 0 .../debugger/emmyAttach/EmmyAttachRunner.kt | 0 .../EmmyConfigAttachDebugProcess.kt | 0 .../emmyLaunch/EmmyLaunchConfigurationType.kt | 0 .../emmyLaunch/EmmyLaunchDebugProcess.kt | 0 .../EmmyLaunchDebugSettingsPanel.form | 0 .../EmmyLaunchDebugSettingsPanel.java | 0 .../debugger/emmyLaunch/EmmyLaunchRunner.kt | 0 .../intellij/lua/debugger/utils/FileUtils.kt | 0 .../lua/debugger/utils/ProcessUtils.kt | 0 .../main/resources}/META-INF/plugin.xml | 0 20 files changed, 7 insertions(+), 31 deletions(-) delete mode 100644 gradle.properties create mode 100644 settings.gradle.kts rename src/{ => main/java}/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachConfigurationType.kt (100%) rename src/{ => main/java}/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt (100%) rename src/{ => main/java}/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.form (100%) rename src/{ => main/java}/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.java (100%) rename src/{ => main/java}/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugger.kt (100%) rename src/{ => main/java}/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebuggerProvider.kt (100%) rename src/{ => main/java}/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt (100%) rename src/{ => main/java}/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachRunner.kt (100%) rename src/{ => main/java}/com/tang/intellij/lua/debugger/emmyAttach/EmmyConfigAttachDebugProcess.kt (100%) rename src/{ => main/java}/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchConfigurationType.kt (100%) rename src/{ => main/java}/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt (100%) rename src/{ => main/java}/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.form (100%) rename src/{ => main/java}/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.java (100%) rename src/{ => main/java}/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchRunner.kt (100%) rename src/{ => main/java}/com/tang/intellij/lua/debugger/utils/FileUtils.kt (100%) rename src/{ => main/java}/com/tang/intellij/lua/debugger/utils/ProcessUtils.kt (100%) rename {resources => src/main/resources}/META-INF/plugin.xml (100%) diff --git a/build.gradle.kts b/build.gradle.kts index 95b6c4e..85b8bf1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,7 +19,7 @@ import de.undercouch.gradle.tasks.download.* plugins { id("java") id("org.jetbrains.kotlin.jvm") version "1.7.20" - id("org.jetbrains.intellij") version "1.9.0" + id("org.jetbrains.intellij") version "1.10.0" id("de.undercouch.download").version("5.3.0") } @@ -61,6 +61,7 @@ task("unzipDebugger", type = Copy::class) { task("installDebugger", type = Copy::class) { dependsOn("unzipDebugger") from("temp/bin") { + include("emmy*") into("bin/") } @@ -70,11 +71,11 @@ task("installDebugger", type = Copy::class) { tasks { // Set the JVM compatibility versions withType { - sourceCompatibility = "11" - targetCompatibility = "11" + sourceCompatibility = "17" + targetCompatibility = "17" } withType { - kotlinOptions.jvmTarget = "11" + kotlinOptions.jvmTarget = "17" } patchPluginXml { @@ -100,7 +101,7 @@ tasks { doLast { copy { from("src/main/debugger/bin") - into("$destinationDir/${pluginName.get()}/debugger/") + into("$destinationDir/${pluginName.get()}/debugger/bin") } } } diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index b9ad18a..0000000 --- a/gradle.properties +++ /dev/null @@ -1,26 +0,0 @@ -# -# Copyright (c) 2017. tangzx(love.tangzx@qq.com) -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -version = 1.0.0 -# https://github.com/EmmyLua/EmmyLuaDebugger/releases -emmyDebuggerVersion = 1.0.16 -# https://github.com/EmmyLua/EmmyLuaLegacyDebugger/releases - -javaVersion = 1.8 - -artifactsPath = build/artifacts - -org.gradle.jvmargs=-Xmx1536m -Dfile.encoding=utf-8 diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..dbb10a8 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "EmmyLua-AttachDebugger" \ No newline at end of file diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachConfigurationType.kt b/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachConfigurationType.kt similarity index 100% rename from src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachConfigurationType.kt rename to src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachConfigurationType.kt diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt b/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt similarity index 100% rename from src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt rename to src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugProcess.kt diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.form b/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.form similarity index 100% rename from src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.form rename to src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.form diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.java b/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.java similarity index 100% rename from src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.java rename to src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugSettingsPanel.java diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugger.kt b/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugger.kt similarity index 100% rename from src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugger.kt rename to src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebugger.kt diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebuggerProvider.kt b/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebuggerProvider.kt similarity index 100% rename from src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebuggerProvider.kt rename to src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachDebuggerProvider.kt diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt b/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt similarity index 100% rename from src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt rename to src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachRunner.kt b/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachRunner.kt similarity index 100% rename from src/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachRunner.kt rename to src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachRunner.kt diff --git a/src/com/tang/intellij/lua/debugger/emmyAttach/EmmyConfigAttachDebugProcess.kt b/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyConfigAttachDebugProcess.kt similarity index 100% rename from src/com/tang/intellij/lua/debugger/emmyAttach/EmmyConfigAttachDebugProcess.kt rename to src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyConfigAttachDebugProcess.kt diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchConfigurationType.kt b/src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchConfigurationType.kt similarity index 100% rename from src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchConfigurationType.kt rename to src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchConfigurationType.kt diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt b/src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt similarity index 100% rename from src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt rename to src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.form b/src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.form similarity index 100% rename from src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.form rename to src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.form diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.java b/src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.java similarity index 100% rename from src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.java rename to src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugSettingsPanel.java diff --git a/src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchRunner.kt b/src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchRunner.kt similarity index 100% rename from src/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchRunner.kt rename to src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchRunner.kt diff --git a/src/com/tang/intellij/lua/debugger/utils/FileUtils.kt b/src/main/java/com/tang/intellij/lua/debugger/utils/FileUtils.kt similarity index 100% rename from src/com/tang/intellij/lua/debugger/utils/FileUtils.kt rename to src/main/java/com/tang/intellij/lua/debugger/utils/FileUtils.kt diff --git a/src/com/tang/intellij/lua/debugger/utils/ProcessUtils.kt b/src/main/java/com/tang/intellij/lua/debugger/utils/ProcessUtils.kt similarity index 100% rename from src/com/tang/intellij/lua/debugger/utils/ProcessUtils.kt rename to src/main/java/com/tang/intellij/lua/debugger/utils/ProcessUtils.kt diff --git a/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml similarity index 100% rename from resources/META-INF/plugin.xml rename to src/main/resources/META-INF/plugin.xml From c19c7039c13d401fa5fff64d1d562ae1e77d9073 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Fri, 9 Dec 2022 13:55:51 +0800 Subject: [PATCH 08/15] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=94=AF=E6=8C=812022.?= =?UTF-8?q?3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 7 +++---- .../intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt | 2 +- .../java/com/tang/intellij/lua/debugger/utils/FileUtils.kt | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 85b8bf1..2211335 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -50,10 +50,10 @@ task("downloadDebugger", type = Download::class) { task("unzipDebugger", type = Copy::class) { dependsOn("downloadDebugger") from(zipTree("temp/win32-x64.zip")) { - into("bin") + into("bin/win32-x64") } from(zipTree("temp/win32-x86.zip")) { - into("bin") + into("bin/win32-x86") } destinationDir = file("temp") } @@ -61,8 +61,7 @@ task("unzipDebugger", type = Copy::class) { task("installDebugger", type = Copy::class) { dependsOn("unzipDebugger") from("temp/bin") { - include("emmy*") - into("bin/") + into("bin") } destinationDir = file("src/main/resources/debugger") diff --git a/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt b/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt index d96b5ca..001eca8 100644 --- a/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt +++ b/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt @@ -61,7 +61,7 @@ class EmmyAttachGroup : XAttachProcessPresentationGroup { override fun getGroupName() = "EmmyLua Attach Debugger" override fun compare(a: ProcessInfo, b: ProcessInfo): Int = - a.executableName.toLowerCase().compareTo(b.executableName.toLowerCase()) + a.executableName.lowercase().compareTo(b.executableName.lowercase()) override fun getOrder(): Int { return 0 diff --git a/src/main/java/com/tang/intellij/lua/debugger/utils/FileUtils.kt b/src/main/java/com/tang/intellij/lua/debugger/utils/FileUtils.kt index 948b4ae..2ebe4ce 100644 --- a/src/main/java/com/tang/intellij/lua/debugger/utils/FileUtils.kt +++ b/src/main/java/com/tang/intellij/lua/debugger/utils/FileUtils.kt @@ -1,16 +1,16 @@ package com.tang.intellij.lua.debugger.utils -import com.intellij.ide.plugins.PluginManager import com.intellij.openapi.extensions.PluginId import com.intellij.openapi.vfs.VfsUtil import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFileManager +import com.intellij.ide.plugins.PluginManagerCore import java.io.File object FileUtils { private val pluginVirtualDirectory: VirtualFile? get() { - val descriptor = PluginManager.getPlugin(PluginId.getId("com.tang.emmylua.attach-debugger")) + val descriptor = PluginManagerCore.getPlugin(PluginId.getId("com.tang.emmylua.attach-debugger")) if (descriptor != null) { val pluginPath = descriptor.path From d70476760bea9e2fe64f637b8df3c6aa2b705333 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Mon, 24 Apr 2023 17:41:19 +0800 Subject: [PATCH 09/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 2211335..9b7d19a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -99,7 +99,7 @@ tasks { withType { doLast { copy { - from("src/main/debugger/bin") + from("src/main/resources/debugger/bin") into("$destinationDir/${pluginName.get()}/debugger/bin") } } diff --git a/src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt b/src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt index edad139..9a7f85c 100644 --- a/src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt +++ b/src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt @@ -134,7 +134,7 @@ class EmmyLaunchDebugProcess( val pid = pidString.toInt() attachTo(pid) - Thread.sleep(300) + Thread.sleep(500) val outputStream = it.getOutputStream() val bw = BufferedWriter(OutputStreamWriter(outputStream)) bw.write("connected"); From be67165688c10541e09377b7047fed3a3bb5c844 Mon Sep 17 00:00:00 2001 From: CppCXY <40318218+CppCXY@users.noreply.github.com> Date: Fri, 5 May 2023 11:21:40 +0800 Subject: [PATCH 10/15] Update build.gradle.kts --- build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 9b7d19a..db5691d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,7 +35,7 @@ intellij { plugins.set(listOf("com.tang:1.3.8-IDEA223")) } -val emmyluaDebuggerVersion = "1.4.1" +val emmyluaDebuggerVersion = "1.5.0" val emmyluaDebuggerProjectUrl = "https://github.com/EmmyLua/EmmyLuaDebugger" task("downloadDebugger", type = Download::class) { @@ -104,4 +104,4 @@ tasks { } } } -} \ No newline at end of file +} From f48c5a1bc143ad3249b1cd0beb39312111a558e5 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Mon, 21 Aug 2023 14:08:12 +0800 Subject: [PATCH 11/15] =?UTF-8?q?=E6=94=AF=E6=8C=812023.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 10 +- .../debugger/emmyAttach/EmmyAttachGroup.kt | 15 +- .../emmyLaunch/EmmyLaunchDebugProcess.kt | 132 ++++++++---------- 3 files changed, 66 insertions(+), 91 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 9b7d19a..b43b607 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,7 +19,7 @@ import de.undercouch.gradle.tasks.download.* plugins { id("java") id("org.jetbrains.kotlin.jvm") version "1.7.20" - id("org.jetbrains.intellij") version "1.10.0" + id("org.jetbrains.intellij") version "1.13.2" id("de.undercouch.download").version("5.3.0") } @@ -29,13 +29,13 @@ repositories { intellij { pluginName.set("EmmyLua-AttachDebugger") - version.set("2022.3") + version.set("2023.1") type.set("IC") // Target IDE Platform - plugins.set(listOf("com.tang:1.3.8-IDEA223")) + plugins.set(listOf("com.tang:1.4.8-IDEA231")) } -val emmyluaDebuggerVersion = "1.4.1" +val emmyluaDebuggerVersion = "1.6.2" val emmyluaDebuggerProjectUrl = "https://github.com/EmmyLua/EmmyLuaDebugger" task("downloadDebugger", type = Download::class) { @@ -79,7 +79,7 @@ tasks { patchPluginXml { sinceBuild.set("223") - untilBuild.set("231.*") + untilBuild.set("232.*") } signPlugin { diff --git a/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt b/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt index 001eca8..0bade35 100644 --- a/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt +++ b/src/main/java/com/tang/intellij/lua/debugger/emmyAttach/EmmyAttachGroup.kt @@ -33,7 +33,11 @@ class EmmyAttachGroup : XAttachProcessPresentationGroup { val instance = EmmyAttachGroup() } - override fun getItemDisplayText(project: Project, processInfo: ProcessInfo, userDataHolder: UserDataHolder): String { + override fun getItemDisplayText( + project: Project, + processInfo: ProcessInfo, + userDataHolder: UserDataHolder + ): String { val map = userDataHolder.getUserData(EmmyAttachDebuggerProvider.DETAIL_KEY) if (map != null) { val detail = map[processInfo.pid] @@ -61,16 +65,9 @@ class EmmyAttachGroup : XAttachProcessPresentationGroup { override fun getGroupName() = "EmmyLua Attach Debugger" override fun compare(a: ProcessInfo, b: ProcessInfo): Int = - a.executableName.lowercase().compareTo(b.executableName.lowercase()) + a.executableName.lowercase().compareTo(b.executableName.lowercase()) override fun getOrder(): Int { return 0 } - - override fun getProcessIcon(p0: Project, p1: ProcessInfo, p2: UserDataHolder): Icon { - return getItemIcon(p0,p1,p2); - } - override fun getProcessDisplayText(p0: Project, p1: ProcessInfo, p2: UserDataHolder): String { - return getItemDisplayText(p0,p1,p2); - } } \ No newline at end of file diff --git a/src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt b/src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt index 9a7f85c..5b5cc40 100644 --- a/src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt +++ b/src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt @@ -2,14 +2,11 @@ package com.tang.intellij.lua.debugger.emmyLaunch import com.google.gson.Gson import com.intellij.execution.configurations.GeneralCommandLine -import com.intellij.execution.filters.TextConsoleBuilderFactory import com.intellij.execution.process.* import com.intellij.execution.ui.ConsoleViewContentType import com.intellij.openapi.project.Project import com.intellij.openapi.util.Key import com.intellij.xdebugger.XDebugSession -import com.intellij.xdebugger.XSourcePosition -import com.intellij.xdebugger.breakpoints.XLineBreakpoint import com.tang.intellij.lua.debugger.LogConsoleType import com.tang.intellij.lua.debugger.emmy.* import com.tang.intellij.lua.debugger.utils.FileUtils @@ -18,23 +15,26 @@ import java.io.BufferedWriter import java.io.InputStreamReader import java.io.OutputStreamWriter import java.net.Socket +import java.nio.charset.Charset import java.util.concurrent.ThreadLocalRandom class EmmyLaunchDebugProcess( session: XDebugSession, - val configuration: EmmyLaunchDebugConfiguration, + private val configuration: EmmyLaunchDebugConfiguration, val project: Project ) : EmmyDebugProcessBase(session) { - - var client: Socket? = null + private var toolProcessHandler: ColoredProcessHandler? = null; override fun setupTransporter() { - if (configuration.useWindowsTerminal) { - runAndAttachUseWindowsTerminal() - } else { - runAndAttach() + LaunchDebug() { it -> + attachTo(it) + Thread.sleep(300) + toolProcessHandler?.let { tool -> + tool.processInput.write("connected\n".toByteArray()) + tool.processInput.flush() + } } } @@ -65,7 +65,7 @@ class EmmyLaunchDebugProcess( return if (exitValue == 0) EmmyWinArch.X64 else EmmyWinArch.X86 } - private fun runAndAttachUseWindowsTerminal() { + private fun LaunchWithWindows() { val port = getPort(ThreadLocalRandom.current().nextInt(10240) + 10240); val arch = detectArch() val path = FileUtils.getPluginVirtualFile("debugger/bin/win32-${arch}") @@ -114,6 +114,7 @@ class EmmyLaunchDebugProcess( LogConsoleType.NORMAL, ConsoleViewContentType.ERROR_OUTPUT ) + ProcessOutputTypes.STDOUT -> print( processEvent.text, LogConsoleType.NORMAL, @@ -123,58 +124,43 @@ class EmmyLaunchDebugProcess( } }) handler.startNotify() - - client = Socket("localhost", port) - client?.let { - it.soTimeout = 10000 - val inputStream = it.getInputStream() - val br = BufferedReader(InputStreamReader(inputStream)) - - val pidString = br.readLine() - val pid = pidString.toInt() - attachTo(pid) - - Thread.sleep(500) - val outputStream = it.getOutputStream() - val bw = BufferedWriter(OutputStreamWriter(outputStream)) - bw.write("connected"); - bw.flush() - } } - private fun runAndAttach() { - val port = getPort(ThreadLocalRandom.current().nextInt(10240) + 10240); + private fun LaunchDebug(onConnected: (pid: Int) -> Unit) { val arch = detectArch() val path = FileUtils.getPluginVirtualFile("debugger/bin/win32-${arch}") - val commandLine = GeneralCommandLine() - commandLine.exePath = "${path}/emmy_tool.exe" - commandLine.setWorkDirectory(path) - commandLine.addParameters( - "run_and_attach", - "-dll", - "emmy_hook.dll", - "-dir", - "\"${path}\"", - "-work", - "\"${configuration.workingDirectory}\"", - "-exe", - "\"${configuration.program}\"", - "-unitbuf", - "-debug-port", - port.toString(), - "-listen-mode", - "-args", - "\"${configuration.parameter}\"" - ) + val commandLine = GeneralCommandLine().apply { + exePath = "${path}/emmy_tool.exe" + setWorkDirectory(path) + addParameter("launch") + if (configuration.useWindowsTerminal) { + addParameter("-create-new-window") + } + addParameters( + "-dll", + "emmy_hook.dll", + "-dir", + "\"${path}\"", + "-work", + "\"${configuration.workingDirectory}\"", + "-exe", + "\"${configuration.program}\"", + "-args", + "\"${configuration.parameter}\"" + ) + charset = Charset.forName("utf8") + } - val handler = ColoredProcessHandler(commandLine) - handler.addProcessListener(object : ProcessListener { + var forOut = false; + toolProcessHandler = ColoredProcessHandler(commandLine) + toolProcessHandler?.addProcessListener(object : ProcessListener { override fun startNotified(processEvent: ProcessEvent) { } override fun processTerminated(processEvent: ProcessEvent) { + toolProcessHandler = null } override fun processWillTerminate(processEvent: ProcessEvent, b: Boolean) { @@ -187,39 +173,31 @@ class EmmyLaunchDebugProcess( LogConsoleType.NORMAL, ConsoleViewContentType.ERROR_OUTPUT ) - ProcessOutputTypes.STDOUT -> print( - processEvent.text, - LogConsoleType.NORMAL, - ConsoleViewContentType.SYSTEM_OUTPUT - ) + + ProcessOutputTypes.STDOUT -> { + if (!forOut) { + forOut = true + val pid = processEvent.text.trim().toInt() + onConnected(pid) + return + } + print( + processEvent.text, + LogConsoleType.NORMAL, + ConsoleViewContentType.SYSTEM_OUTPUT + ) + } } } }) - handler.startNotify() - - client = Socket("localhost", port) - client?.let { - it.soTimeout = 10000 - val inputStream = it.getInputStream() - val br = BufferedReader(InputStreamReader(inputStream)) - - val pidString = br.readLine() - val pid = pidString.toInt() - attachTo(pid) - - Thread.sleep(300) - val outputStream = it.getOutputStream() - val bw = BufferedWriter(OutputStreamWriter(outputStream)) - bw.write("connected"); - bw.flush() - } - + toolProcessHandler?.startNotify() } override fun onDisconnect() { super.onDisconnect() - client?.close() + toolProcessHandler?.processInput?.write("close\n".toByteArray()) + toolProcessHandler = null } override fun onReceiveMessage(cmd: MessageCMD, json: String) { From 1b507e7b536ad0cb849f2e44ca3f161178ebab41 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Thu, 7 Dec 2023 11:07:08 +0800 Subject: [PATCH 12/15] =?UTF-8?q?=E5=85=BC=E5=AE=B92023.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index aa9261c..be9de6e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -32,10 +32,10 @@ intellij { version.set("2023.1") type.set("IC") // Target IDE Platform - plugins.set(listOf("com.tang:1.4.8-IDEA231")) + plugins.set(listOf("com.tang:1.4.9-IDEA231")) } -val emmyluaDebuggerVersion = "1.6.2" +val emmyluaDebuggerVersion = "1.7.1" val emmyluaDebuggerProjectUrl = "https://github.com/EmmyLua/EmmyLuaDebugger" task("downloadDebugger", type = Download::class) { @@ -79,7 +79,7 @@ tasks { patchPluginXml { sinceBuild.set("223") - untilBuild.set("232.*") + untilBuild.set("233.*") } signPlugin { From c92559636c2fd0037c99184257557341ae384d90 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Thu, 7 Dec 2023 11:12:13 +0800 Subject: [PATCH 13/15] update build --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index be9de6e..e9e5f54 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -32,7 +32,7 @@ intellij { version.set("2023.1") type.set("IC") // Target IDE Platform - plugins.set(listOf("com.tang:1.4.9-IDEA231")) + plugins.set(listOf("com.tang:1.4.8-IDEA231")) } val emmyluaDebuggerVersion = "1.7.1" From cace11550a596a9b72c2c36202f64b3ff0db90a5 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Sun, 7 Apr 2024 20:12:44 +0800 Subject: [PATCH 14/15] 2024.1 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index e9e5f54..55b3bfb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -79,7 +79,7 @@ tasks { patchPluginXml { sinceBuild.set("223") - untilBuild.set("233.*") + untilBuild.set("241.*") } signPlugin { From f71615601af6512b1422e3aab2031cd97e1662e3 Mon Sep 17 00:00:00 2001 From: CppCXY <40318218+CppCXY@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:42:47 +0800 Subject: [PATCH 15/15] Update build.gradle.kts --- build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 55b3bfb..77ee969 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,7 +35,7 @@ intellij { plugins.set(listOf("com.tang:1.4.8-IDEA231")) } -val emmyluaDebuggerVersion = "1.7.1" +val emmyluaDebuggerVersion = "1.8.2" val emmyluaDebuggerProjectUrl = "https://github.com/EmmyLua/EmmyLuaDebugger" task("downloadDebugger", type = Download::class) { @@ -79,7 +79,7 @@ tasks { patchPluginXml { sinceBuild.set("223") - untilBuild.set("241.*") + untilBuild.set("242.*") } signPlugin {