Christophe Weblog Wiki Code Publications Music
store calls and frames on entry to sldb itself
[swankr.git] / swank.R
diff --git a/swank.R b/swank.R
index a9b62c6737994c8184a0961f07d29d3d8f8717c2..b5fd98c202e1bb8751ddd03c01b273c681d8f9f8 100644 (file)
--- a/swank.R
+++ b/swank.R
@@ -54,7 +54,9 @@ emacsRex <- function(io, sldbState, form, pkg, thread, id, level=0) {
 }
 
 makeSldbState <- function(condition, level, id) {
-  ret <- list(condition=condition, level=level, id=id)
+  calls <- rev(sys.calls())[-1]
+  frames <- rev(sys.frames())[-1]
+  ret <- list(condition=condition, level=level, id=id, calls=calls, frames=frames)
   class(ret) <- c("sldbState", class(ret))
   ret
 }
@@ -69,17 +71,25 @@ sldbLoop <- function(io, sldbState, id) {
 
 debuggerInfoForEmacs <- function(sldbState, from=0, to=NULL) {
   backtraceForEmacs <- function() {
-    calls <- sys.calls()
+    calls <- sldbState$calls
     if(is.null(to)) to <- length(calls)
     from <- from+1
     calls <- lapply(calls[from:to], { frameNumber <- from-1;
                              function (x) { ret <- list(frameNumber, paste(format(x), sep="", collapse=" ")); frameNumber <<- 1+frameNumber; ret }})
   }
+  computeRestartsForEmacs <- function () {
+    lapply(computeRestarts(sldbState$condition),
+           function(x) {
+             ## this is all a little bit internalsy
+             restartName <- x[[1]][[1]]
+             description <- restartDescription(x)
+             list(restartName, if(is.null(description)) restartName else description)
+           })
+  }
   list(list(as.character(sldbState$condition), sprintf("  [%s]", class(sldbState$condition)[[1]]), FALSE),
-       lapply(computeRestarts(), function(x) list(x[[1]][[1]], x[[1]][[1]])),
+       computeRestartsForEmacs(),
        backtraceForEmacs(),
        list(sldbState$id))
-#       lapply(calls[from:to], function(x) paste(format(x), sep="", collapse=" ")))
 }
 
 readPacket <- function(io) {
@@ -231,7 +241,7 @@ writeSexpToString <- function(obj) {
 }
 
 `swank:listener-eval` <- function(io, sldbState, string) {
-  val <- eval(parse(text=string))
+  val <- eval(parse(text=string), envir = globalenv())
   f <- fifo("")
   sink(f)
   print(val)
@@ -253,3 +263,13 @@ writeSexpToString <- function(obj) {
 `swank:debugger-info-for-emacs` <- function(io, sldbState, from, to) {
   debuggerInfoForEmacs(sldbState, from=from, to=to)
 }
+
+`swank:invoke-nth-restart-for-emacs` <- function(io, sldbState, level, n) {
+  if(sldbState$level == level) {
+    invokeRestart(computeRestarts()[[n+1]])
+  }
+}
+
+`swank:buffer-first-change` <- function(io, sldbState, filename) {
+  FALSE
+}