Skip to content

Commit

Permalink
More progress on debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Jun 7, 2024
1 parent c1b6aef commit 4ab34d9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/text/language/dap_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ proc sendRPC(client: DAPClient, meth: string, command: string, args: Option[Json
proc sendRequest(client: DAPClient, command: string, args: Option[JsonNode]): Future[Response[JsonNode]] {.async.} =
let id = client.nextId
inc client.nextId
await client.sendRPC("request", command, args, id)

let requestFuture = newResolvableFuture[Response[JsonNode]]("DAPCLient.sendRequest " & command)

Expand All @@ -423,6 +422,7 @@ proc sendRequest(client: DAPClient, command: string, args: Option[JsonNode]): Fu
client.requestsPerMethod[command] = @[]
client.requestsPerMethod[command].add id

asyncCheck client.sendRPC("request", command, args, id)
return await requestFuture.future

proc cancelAllOf*(client: DAPClient, command: string) =
Expand All @@ -431,6 +431,7 @@ proc cancelAllOf*(client: DAPClient, command: string) =

var futures: seq[(int, ResolvableFuture[Response[JsonNode]])]
for id in client.requestsPerMethod[command]:
# log lvlError, &"Cancel request {command}:{id}"
let (_, future) = client.activeRequests[id]
futures.add (id, future)
client.activeRequests.del id
Expand Down Expand Up @@ -689,6 +690,9 @@ proc runAsync*(client: DAPClient) {.async.} =
log lvlError, fmt"[run] Bad response: {response}"
continue

if logVerbose:
debugf"[run] Response: {response.pretty}"

try:
case response["type"].getStr
of "event":
Expand Down
39 changes: 28 additions & 11 deletions src/text/language/debugger.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import std/[strutils, options, json, asynchttpserver, tables, sugar]
import std/[strutils, options, json, asynchttpserver, tables, sugar, osproc]
import misc/[id, custom_async, custom_logger, util, connection, myjsonutils, event, response]
import scripting/expose
import dap_client, dispatch_tables, app_interface, config_provider
Expand Down Expand Up @@ -99,22 +99,36 @@ proc createConnectionWithType(self: Debugger, name: string): Future[Option[Conne
log lvlError, &"No/invalid debugger type configuration with name '{name}' found: {config}"
return Connection.none

debugf"config: {config}"

let connectionType = config.tryGet("connection", DebuggerConnectionKind, "stdio".newJString):
log lvlError, &"No/invalid debugger connection type in {config.pretty}"
return Connection.none

debugf"{connectionType}"

case connectionType
of Tcp:
when not defined(js):
let host = config.tryGet("host", string, "127.0.0.1".newJString):
log lvlError, &"No/invalid debugger connection type in {config.pretty}"
return Connection.none
let port = getFreePort()
return newAsyncSocketConnection(host, port).await.Connection.some

if config.hasKey("path"):
let path = config.tryGet("path", string, newJNull()):
log lvlError, &"No/invalid debugger executable path in {config.pretty}"
return Connection.none

let port = getFreePort().int
log lvlInfo, &"Start process {path} with port {port}"
let process = startProcess(path, args = @["-p", $port], options = {poUsePath, poDaemon})

# todo: need to wait for process to open port?
await sleepAsync(500)

return newAsyncSocketConnection("127.0.0.1", port.Port).await.Connection.some

else:
let host = config.tryGet("host", string, "127.0.0.1".newJString):
log lvlError, &"No/invalid debugger host in {config.pretty}"
return Connection.none
let port = config.tryGet("port", int, 5678.newJInt):
log lvlError, &"No/invalid debugger port in {config.pretty}"
return Connection.none
return newAsyncSocketConnection(host, port.Port).await.Connection.some

of Stdio:
when not defined(js):
Expand Down Expand Up @@ -287,7 +301,10 @@ proc runConfigurationAsync(self: Debugger, name: string) {.async.} =
client.deinit()
return

let sourcePath = "/mnt/c/Absytree/temp/test.cpp" # todo
when defined(linux):
let sourcePath = "/mnt/c/Absytree/temp/test.cpp" # todo
else:
let sourcePath = "C:/Absytree/temp/test.cpp" # todo
await client.setBreakpoints(
Source(path: sourcePath.some),
@[
Expand Down
2 changes: 0 additions & 2 deletions src/ui/widget_builder_debugger.nim
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ proc createOutput*(self: DebuggerView, builder: UINodeBuilder, app: App, debugge
debugger.outputEditor.createUI(builder, app)

method createUI*(self: DebuggerView, builder: UINodeBuilder, app: App): seq[proc() {.closure.}] =
debugf"createUI debugger"

let dirty = self.dirty
self.dirty = false

Expand Down

0 comments on commit 4ab34d9

Please sign in to comment.