From 66cd51b2a72e5e79efbf872f8718b7b2a3153a5e Mon Sep 17 00:00:00 2001 From: Jafar Al-Gharaibeh Date: Mon, 8 Jan 2024 23:35:37 -0600 Subject: [PATCH] simplify code in a few places Signed-off-by: Jafar Al-Gharaibeh --- uni/udb/udap/communicator.icn | 85 ++++++++++++++--------------------- 1 file changed, 33 insertions(+), 52 deletions(-) diff --git a/uni/udb/udap/communicator.icn b/uni/udb/udap/communicator.icn index 4b8a257b7..587e5f148 100644 --- a/uni/udb/udap/communicator.icn +++ b/uni/udb/udap/communicator.icn @@ -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 } } @@ -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 { @@ -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"] } } @@ -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. @@ -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 @@ -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