Skip to content

Commit

Permalink
udb: prepare to add debug adapter protocol support
Browse files Browse the repository at this point in the history
Tableize breakpoint
Tableize stackFrame
Tableize checkstep
Tableize run
Add full reset command
Alter required response handling
Alter error handling
Update version number

Signed-off-by: mstreeter10 <[email protected]>
  • Loading branch information
mstreeter10 authored and Jafaral committed Jan 9, 2024
1 parent c605903 commit 773ed0d
Show file tree
Hide file tree
Showing 13 changed files with 613 additions and 278 deletions.
484 changes: 296 additions & 188 deletions uni/udb/breakpoint.icn

Large diffs are not rendered by default.

41 changes: 33 additions & 8 deletions uni/udb/console.icn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Console : Session(
ENTER, # The enter key
BkSp, # The Back Space key
badKeys, # A set of all other control keys
mode # Either &null (normal) or "-line"; test with \ or /
mode # Either &null (normal), "-line", or "-adapter"
)

#
Expand Down Expand Up @@ -61,8 +61,8 @@ method get_Line()
writes(PROMPT)

# if line mode, read a whole line the old fashioned way, skip this function
if \mode == "-line" then
return read() | "quit"
if \mode == "-line" | \mode == "-adapter" then
return DState.stateRead() | "quit"

# normal mode, read the line interactively
repeat {
Expand Down Expand Up @@ -160,17 +160,28 @@ end
# Here where we start a UDB Console Session and have
# most of the user control debugging interface
#
method startConsole(argv)
local ans, cmd, old_State := NONE, funame
method startConsole(argv, sock, progSock)
local ans, cmd, old_State := NONE, funame, port, errorTable

# check whether we are on Solaris, and if so, default to cooked input
if funame := open("uname","p") then {
if find("SunOS", read(funame)) then mode := "-line"
close(funame)
}
if argv[1] == "-line" then { mode := pop(argv); udb_no_more_flag := 1 }
else if argv[1] == "-adapter" then {
mode := pop(argv)

# Don't let DState try and initialize a port number
pop(argv)

DState.sock := sock
DState.progSock := progSock
udb_no_more_flag := 1
}
else if argv[1] == "-noline" then { mode := &null; pop(argv) }

DState.mode := mode
DState.initializeState(argv)

# main interface loop
Expand Down Expand Up @@ -212,6 +223,14 @@ $endif
old_State := DState.State
# user interaction loop during debug
while DState.State ~= RUN do {
if \DState.mode == "-adapter" then {
if \&errornumber then {
errorTable := table("type", "crash", "errornumber", &errornumber)
errorTable["errortext"] := \&errortext
errorTable["errorvalue"] := \&errorvalue
DState.Write(errorTable)
}
}
case DState.State of {
RELOAD |
END |
Expand Down Expand Up @@ -268,7 +287,10 @@ $endif
# update current symbol table before user input
DState.srcFile.updateCurrSymtab(DState.coState)

if cmd := get_CommandLine() then parse_Command(cmd)
if cmd := get_CommandLine() then {
if cmd[1] == "reset" then return "reset"
else parse_Command(cmd)
}
else DState.State := SKIP
}# end of while
}#end of every
Expand Down Expand Up @@ -297,7 +319,10 @@ $endif
}
} # end case DState.State
old_State := DState.State
if cmd := get_CommandLine() then parse_Command(cmd)
if cmd := get_CommandLine() then {
if cmd[1] == "reset" then return "reset"
else parse_Command(cmd)
}
else DState.State := SKIP
}# end while DState.State
end
Expand Down Expand Up @@ -350,4 +375,4 @@ $else
BkSp := "\b"
badKeys := otherControls()
$endif
end
end
84 changes: 66 additions & 18 deletions uni/udb/data.icn
Original file line number Diff line number Diff line change
Expand Up @@ -22,64 +22,112 @@ class Data(
# prints all of Global Variables state in some level
#
method printGlobals(level)
local x, i, CMonitored := DState.coState.target.val, output := []
local x, i, CMonitored := DState.coState.target.val, output := [], globalsTable, variableTable

/level := DState.coState.target.curr_frame
globalsTable := table()
globalsTable["type"] := "globals"

if /DState.mode | \DState.mode ~== "-adapter" then put(output,"\n Global variables:")

put(output,"\n Global variables:")
every x := !DState.srcFile.getCurrGlobals() do {
i := variable(x, CMonitored, keyword("level",CMonitored))
put(output," "||x||" = "||image(i)||" : "|| type(i))
if /DState.mode | \DState.mode ~== "-adapter" then put(output," "||x||" = "||image(i)||" : "|| type(i))
else {
variableTable := table("name", x, "value", image(i), "type", type(i))
variableTable["value"] := replace(variableTable["value"], "\"", "\\\"")
variableTable["type"] := replace(variableTable["type"], "\"", "\\\"")
put(output, variableTable)
}
more(output)
}

globalsTable["variables"] := output
if /DState.mode | \DState.mode ~== "-adapter" then more(output)
else DState.Write(globalsTable)
end

#
# prints all Local Variables for some Level
#
method printLocals(level)
local x, i, CMonitored := DState.coState.target.val, output := []
local x, i, CMonitored := DState.coState.target.val, output := [], localsTable, variableTable

/level := DState.coState.target.curr_frame
/level := DState.coState.target.curr_frame
localsTable := table()
localsTable["type"] := "locals"

if /DState.mode | \DState.mode ~== "-adapter" then put(output,"\n Local variables:")

put(output,"\n Local variables:")
every x := !DState.srcFile.getCurrLocals() do {
i := variable(x, CMonitored, level)
put(output," "||x||" = "||image(i)||" : "|| type(i))
if /DState.mode | \DState.mode ~== "-adapter" then put(output," "||x||" = "||image(i)||" : "|| type(i))
else {
variableTable := table("name", x, "value", image(i), "type", type(i))
variableTable["value"] := replace(variableTable["value"], "\"", "\\\"")
variableTable["type"] := replace(variableTable["type"], "\"", "\\\"")
put(output, variableTable)
}
more(output)
}

localsTable["variables"] := output
if /DState.mode | \DState.mode ~== "-adapter" then more(output)
else DState.Write(localsTable)
end

#
# prints all Local Variables for some Level
#
method printStatics(level)
local x, i, CMonitored := DState.coState.target.val, output := []
local x, i, CMonitored := DState.coState.target.val, output := [], staticsTable, variableTable

/level := DState.coState.target.curr_frame
staticsTable := table()
staticsTable["type"] := "statics"

if /DState.mode | \DState.mode ~== "-adapter" then put(output,"\n Static variables:")

put(output,"\n Static variables:")
every x := !DState.srcFile.getCurrStatics() do {
i := variable(x, CMonitored, level)
put(output," "||x||" = "||image(i)||" : "|| type(i))
if /DState.mode | \DState.mode ~== "-adapter" then put(output," "||x||" = "||image(i)||" : "|| type(i))
else {
variableTable := table("name", x, "value", image(i), "type", type(i))
variableTable["value"] := replace(variableTable["value"], "\"", "\\\"")
variableTable["type"] := replace(variableTable["type"], "\"", "\\\"")
put(output, variableTable)
}
more(output)
}

staticsTable["variables"] := output
if /DState.mode | \DState.mode ~== "-adapter" then more(output)
else DState.Write(staticsTable)
end

#
# prints all Formal Parameters for some Level
#
method printParams(level)
local x, i, CMonitored := DState.coState.target.val, output := []
local x, i, CMonitored := DState.coState.target.val, output := [], paramsTable, variableTable

/level := DState.coState.target.curr_frame
/level := DState.coState.target.curr_frame
paramsTable := table()
paramsTable["type"] := "params"

if /DState.mode | \DState.mode ~== "-adapter" then put(output,"\n Parameters:")

put(output,"\n Parameters:")
every x := !DState.srcFile.getCurrParams() do {
i := variable(x, CMonitored, level)
put(output," "||x||" = "||image(i)||" : "|| type(i))
if /DState.mode | \DState.mode ~== "-adapter" then put(output," "||x||" = "||image(i)||" : "|| type(i))
else {
variableTable := table("name", x, "value", image(i), "type", type(i))
variableTable["value"] := replace(variableTable["value"], "\"", "\\\"")
variableTable["type"] := replace(variableTable["type"], "\"", "\\\"")
put(output, variableTable)
}
more(output)
}

paramsTable["variables"] := output
if /DState.mode | \DState.mode ~== "-adapter" then more(output)
else DState.Write(paramsTable)
end

#
Expand Down
2 changes: 1 addition & 1 deletion uni/udb/defaults.icn
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ $define PROMPT "(udb) "
#
# The UDB Version
#
$define VERSION " UDB Version 2.1, July 4, 2018."
$define VERSION " UDB Version 2.2, December 12, 2023."

#
# Set of all the letters and all digits
Expand Down
2 changes: 1 addition & 1 deletion uni/udb/dta/temporals.icn
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ method cmdAssert(cmd)
msg :="\n An assertion is found in virtual location"
msg ||:="\n Do you want to replace it with the new one (Y|n):"
DState.Writes(msg)
if (not (ans:=read())) | (*ans=0) | not(ans[1] == ("n"|"N")) then{
if (not (ans:=DState.stateRead())) | (*ans=0) | not(ans[1] == ("n"|"N")) then{
assertTable[loc] := obj
put(assertList,loc)#assertList[-1] := loc
fname := line := code := &null
Expand Down
6 changes: 4 additions & 2 deletions uni/udb/evaluator.icn
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ end
# Handles UDB's E_Error Events and prints the RunTime error Messages
#
method handle_Error()
local cur_line, cur_file, cur_p, src
local cur_line, cur_file, cur_p, src, resultTable := table()

DState.State := PAUSE
#DState.State := END
Expand All @@ -167,7 +167,9 @@ method handle_Error()
Message ||:="\n"||DState.srcFile.getSrcLine(cur_file, cur_line)
Message ||:="\n"||repl("-", keyword("column",MONITORED))||"^"
Message ||:="\n"||keyword("errortext",MONITORED)
DState.Write(Message)
resultTable["consoleMsg"] := Message
resultTable["type"] := "stderr"
DState.Write(resultTable)
end

#
Expand Down
61 changes: 38 additions & 23 deletions uni/udb/session.icn
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ class Session(
#
method startSession()
local arg, t
local resultTable := table()

#-- it may need to be in EvInit() for the sake of re-run
&eventsource := &null

EvInit(DState.TP) | stop("cant start evinit on " || DState.TP[1])

if \DState.mode == "-adapter" then EvInit(DState.TP, DState.progSock, DState.progSock, DState.progSock) | stop("cant start evinit on " || DState.TP[1])
else EvInit(DState.TP) | stop("cant start evinit on " || DState.TP[1])

Message :=" Starting program: "
every arg := !DState.TP do Message ||:=" "||arg
Message ||:="\n"
Expand All @@ -44,7 +47,7 @@ method startSession()
if DState.State = PAUSE then {
if DState.RunCode = SIGNAL then {
Message := "\n "||DState.TP[1]||" program received a signal "||
&eventvalue||"."
&eventvalue||"."
DState.Write(Message)
}
# suspends the loop and go back to udb_Console() for a new cmd.
Expand All @@ -66,10 +69,13 @@ method startSession()
#write("====================================")
#--- Test

DState.State := END
Message := "\n "||DState.TP[1]||" program exited normally."
DState.Write(Message)
return
DState.State := END
Message := "\n "||DState.TP[1]||" program exited normally."
resultTable["consoleMsg"] := Message
resultTable["type"] := "exited"
resultTable["exitCode"] := 0
DState.Write(resultTable)
return
end

#
Expand Down Expand Up @@ -201,64 +207,73 @@ end
#
method cmdRun(cmd)
local i, ans, args
local resultTable := table()

if DState.State = (LOAD | END | PAUSE) then {
# run - use args from 'load'
if *cmd = 1 then {
args := DState.TP
}
}
# run args - overwrite args from 'load'
else if *cmd >= 2 then {
args := [DState.TP[1]]
every i:=2 to *cmd do put(args, cmd[i])
}
}
DState.TP := args

if DState.State = PAUSE then{
Message :="\n The program being debugged has been started already."
Message||:="\n Start it from the beginning? (Y/n)?: "
DState.Writes(Message)
resultTable["consoleMsg"] := Message
resultTable["requireResponse"] := "__true__"
DState.Writes(resultTable)
# rerun
if *(ans:=read())=0 | not(ans[1] == ("n"|"N")) then {
if *(ans:=DState.stateRead())=0 | not(ans[1] == ("n"|"N")) then {
Debug.Watch.resetWatchInfo()
Debug.Trace.resetTraceInfo()
DState.Update(RERUN)
}
}
else{
DState.State := SKIP
return
}
}
}
}
# run (like normal)
else{
else {
DState.Update(RUN)
if DState.RunCount >= 1 then{
Debug.Watch.resetWatchInfo()
Debug.Trace.resetTraceInfo()
}
}
}
}
else{
}
else {
DState.State := ERROR
Message := "\n No program to RUN, load program first_
\n Type \"help\" for assistance"
DState.Write(Message)
resultTable["consoleMsg"] := msg
resultTable["success"] := "__false__"
DState.Write(resultTable)
}
end

#
# Allows you to quit the program.
#
method cmdQuit()
local ans
local ans, msg
local resultTable := table()

# check whether a program is running or not, Paused, etc??????
# do not exit directlly if the program is in the running state
if DState.State = (RUN | PAUSE) then{
DState.Writes("\n The program \""||
msg := "\n The program \""||
DState.srcFile.exeName ||
"\" is running. Exit anyhow (Y/n)?: ")
if (not (ans:=read())) | (*ans=0) | (map(ans[1]) == "y") then {
"\" is running. Exit anyhow (Y/n)?: "
resultTable["consoleMsg"] := msg
resultTable["requireResponse"] := "__true__"
DState.Writes(resultTable)
if (not (ans:=DState.stateRead())) | (*ans=0) | (map(ans[1]) == "y") then {
DState.State := QUIT
}
else
Expand Down
Loading

0 comments on commit 773ed0d

Please sign in to comment.