Skip to content

Commit

Permalink
simplify code in a few places
Browse files Browse the repository at this point in the history
Signed-off-by: Jafar Al-Gharaibeh <[email protected]>
  • Loading branch information
Jafaral committed Jan 9, 2024
1 parent 2b58129 commit 66cd51b
Showing 1 changed file with 33 additions and 52 deletions.
85 changes: 33 additions & 52 deletions uni/udb/udap/communicator.icn
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,17 @@ class Communicator(udb, udbSock, tpSock, dapcomSock, filePath, tpArgs)
# Returns a list of tables containing stack trace information.
# A table of with key "type" set to "crash" is returned if udb experiences an error.
method stack_trace()
local udbResTable, udbResTableList, i, frames

udbResTableList := list()
frames := list()

every i := udb_input("bt", 1) do {
put(udbResTableList, \i)
}
if *udbResTableList ~= 0 then {
every udbResTable := !udbResTableList do {
if member(udbResTable, "type") then {
if udbResTable["type"] == "frame" then {
udbResTable["name"] := replace(udbResTable["name"], "\"", "\\\"")
udbResTable["consoleMsg"] := replace(udbResTable["consoleMsg"], "\"", "\\\"")
put(frames, udbResTable)
}
if udbResTable["type"] == "crash" then return udbResTable
local udbResTable, udbResTableList, i, frames := [ ]
every put(udbResTableList := [ ], \(udb_input("bt", 1)))

every udbResTable := !udbResTableList do {
if member(udbResTable, "type") then {
if udbResTable["type"] == "frame" then {
udbResTable["name"] := replace(udbResTable["name"], "\"", "\\\"")
udbResTable["consoleMsg"] := replace(udbResTable["consoleMsg"], "\"", "\\\"")
put(frames, udbResTable)
}
if udbResTable["type"] == "crash" then return udbResTable
}
}

Expand All @@ -64,16 +57,11 @@ class Communicator(udb, udbSock, tpSock, dapcomSock, filePath, tpArgs)
# Returns a list of tables containing scope information.
# A table of with key "type" set to "crash" is returned if udb experiences an error.
method get_scopes(frame)
local udbResTableList, udbResTable, scopes, i, j, k, l, m

udbResTableList := list()
scopes := list()
local udbResTableList, udbResTable, scopes, c
scopes := []

every i := udb_input("frame " || frame, 1) do put(udbResTableList, \i)
every j := udb_input("print -g", 1) do put(udbResTableList, \j)
every k := udb_input("print -l", 1) do put(udbResTableList, \k)
every l := udb_input("print -s", 1) do put(udbResTableList, \l)
every m := udb_input("print -p", 1) do put(udbResTableList, \m)
every put(udbResTableList := [], \(udb_input("frame " || frame, 1)))
every put(udbResTableList, \(udb_input("print -" || !"glsp", 1)))

if *udbResTableList ~= 0 then {
every udbResTable := !udbResTableList do {
Expand Down Expand Up @@ -105,21 +93,18 @@ class Communicator(udb, udbSock, tpSock, dapcomSock, filePath, tpArgs)
method get_variables(variablesReference)
local udbResTable, udbResTableList, variables, cmd, i

udbResTableList := list()
variables := list()
udbResTableList := []
variables := []

if variablesReference = 1 then cmd := "print -g"
else if variablesReference = 2 then cmd := "print -l"
else if variablesReference = 3 then cmd := "print -s"
else if variablesReference = 4 then cmd := "print -p"
cmd := "print -" || "glsp"[variablesReference]

every i := udb_input(cmd, 1) do put(udbResTableList, \i)
every put(udbResTableList, \(udb_input(cmd, 1)))

if *udbResTableList ~= 0 then {
every udbResTable := !udbResTableList do {
if member(udbResTable, "type") then {
if member(udbResTable, "variables") then {
if udbResTable["type"] == "globals" | udbResTable["type"] == "locals" | udbResTable["type"] == "statics" | udbResTable["type"] == "params" then {
if udbResTable["type"] == "globals" | "locals" | "statics" | "params" then {
variables := udbResTable["variables"]
}
}
Expand Down Expand Up @@ -150,8 +135,10 @@ class Communicator(udb, udbSock, tpSock, dapcomSock, filePath, tpArgs)
suspend "dir args " || procs
}

if \tpArgs then suspend "load " || filePath || " " || tpArgs
else suspend "load " || filePath
if \tpArgs then
suspend "load " || filePath || " " || tpArgs
else
suspend "load " || filePath
end

# Sets the file path of the debuggee.
Expand All @@ -164,15 +151,11 @@ class Communicator(udb, udbSock, tpSock, dapcomSock, filePath, tpArgs)
local sock
if /port then return "udb communication port not declared"

every 1 to 5 do {
if sock := open(":" || port, "na") then {
every !5 do
if sock := open(":" || port, "na") then
return sock
}
else {
write("Attempting to open sock on port " || port || " again.")
else
delay(1000)
}
}

write("udap failed to open port: " || port)
end
Expand Down Expand Up @@ -270,27 +253,25 @@ class Communicator(udb, udbSock, tpSock, dapcomSock, filePath, tpArgs)
method set_breakpoints(arguments)
local breakpoints, bp, line, cond, udbResTable, udbResTableList, i

udbResTableList := list()

udbResTableList := []
udb_input("clear break", 1)

breakpoints := arguments["breakpoints"]
if *breakpoints = 0 then fail

every bp := 1 to *breakpoints do {
line := breakpoints[bp]["line"]
cond := \breakpoints[bp]["condition"]
every bp := !breakpoints do {
line := bp["line"]
cond := bp["condition"]

every i := udb_input("b " || arguments["source"]["name"] || ":" || line, 1) do put(udbResTableList, \i)
every put(udbResTableList, \(udb_input("b " || arguments["source"]["name"] || ":" || line, 1)))

if *udbResTableList ~= 0 then {
every udbResTable := !udbResTableList do {
if member(udbResTable, "type") then
if udbResTable["type"] == "crash" then return udbResTable
breakpoints[bp]["verified"] := udbResTable["success"]
bp["verified"] := udbResTable["success"]
}
}
else breakpoints[bp]["verified"] := "__false__"
else bp["verified"] := "__false__"
}
end
end

0 comments on commit 66cd51b

Please sign in to comment.