Skip to content

Commit ec0a8ff

Browse files
committed
restore exceptionInfo with better response
1 parent 0825356 commit ec0a8ff

File tree

4 files changed

+119
-1
lines changed

4 files changed

+119
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Capabilities:
175175
* [x] supportsHitConditionalBreakpoints
176176
* [x] supportsSetVariable
177177
* [x] supportTerminateDebuggee
178-
* [ ] supportsExceptionInfoRequest
178+
* [x] supportsExceptionInfoRequest
179179
* [ ] supportsExceptionOptions
180180
* [x] supportsConfigurationDoneRequest
181181

lua/osv/init.lua

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ local builtin_debug_traceback
55

66
local exception_error_msg = nil
77

8+
local exception_stacktrace
9+
810
local limit = 0
911

1012
local stack_level = 0
@@ -499,6 +501,20 @@ function M.prepare_attach(blocking)
499501
end
500502
end
501503

504+
function handlers.exceptionInfo(request)
505+
sendProxyDAP(make_response(request,{
506+
body = {
507+
exceptionId = "",
508+
breakMode = "always",
509+
description = exception_error_msg,
510+
details = {
511+
message = exception_error_msg,
512+
stackTrace = exception_stacktrace,
513+
}
514+
}
515+
}))
516+
end
517+
502518
function handlers.next(request)
503519
local depth = 0
504520
local surface = 0
@@ -972,17 +988,67 @@ function M.prepare_attach(blocking)
972988

973989
local traceback_args = { ... }
974990
exception_error_msg = nil
991+
log(vim.inspect({...}))
975992
if #traceback_args > 0 then
976993
exception_error_msg = traceback_args[1]
977994
end
978995

996+
local start_frame = 0
997+
local levels = 1
998+
local skip = 0
999+
1000+
local off = 0
1001+
while true do
1002+
local info = debug.getinfo(off+levels+start_frame)
1003+
if not info then
1004+
break
1005+
end
1006+
1007+
local inside_osv = false
1008+
if info.source:sub(1, 1) == '@' and #info.source > 8 and info.source:sub(#info.source-8+1,#info.source) == "init.lua" then
1009+
local source = info.source:sub(2)
1010+
-- local path = vim.fn.resolve(vim.fn.fnamemodify(source, ":p"))
1011+
local parent = vim.fs.dirname(source)
1012+
if parent and vim.fs.basename(parent) == "osv" then
1013+
inside_osv = true
1014+
end
1015+
end
1016+
1017+
1018+
if inside_osv then
1019+
skip = off + 1
1020+
end
1021+
1022+
off = off + 1
1023+
end
1024+
1025+
1026+
exception_stacktrace = {}
1027+
while true do
1028+
local info = debug.getinfo(skip+levels+start_frame)
1029+
if not info then
1030+
break
1031+
end
1032+
local stack_desc = ""
1033+
stack_desc = info.source .. ":" .. info.currentline
1034+
if info.name then
1035+
stack_desc = stack_desc .. " in function " .. info.name
1036+
elseif info.what then
1037+
stack_desc = stack_desc .. " in " .. info.what .. " chunk"
1038+
end
1039+
table.insert(exception_stacktrace, stack_desc)
1040+
levels = levels + 1
1041+
end
1042+
1043+
exception_stacktrace = table.concat(exception_stacktrace, "\n")
9791044
local msg = make_event("stopped")
9801045
msg.body = {
9811046
reason = "exception",
9821047
threadId = 1,
9831048
text = exception_error_msg
9841049
}
9851050
sendProxyDAP(msg)
1051+
9861052
running = false
9871053
while not running do
9881054
if M.stop_freeze then
@@ -1760,6 +1826,8 @@ function M.start_server(host, port, do_log)
17601826

17611827
supportTerminateDebuggee = true,
17621828

1829+
supportsExceptionInfoRequest = true,
1830+
17631831
supportsHitConditionalBreakpoints = true,
17641832
supportsConditionalBreakpoints = true,
17651833

src/exception_handler.lua.t2

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ debug.traceback = function(...)
1212
; if osv is not running bail out
1313
; if traceback was called explicitly return builtin
1414
; save error message
15+
; save error stacktrace
1516
; send exception stopped event
1617
; freeze neovim instance
1718
return builtin_debug_traceback(...)
@@ -65,6 +66,7 @@ local exception_error_msg = nil
6566
;; save error message
6667
local traceback_args = { ... }
6768
exception_error_msg = nil
69+
log(vim.inspect({...}))
6870
if #traceback_args > 0 then
6971
exception_error_msg = traceback_args[1]
7072
end
@@ -77,3 +79,32 @@ msg.body = {
7779
text = exception_error_msg
7880
}
7981
sendProxyDAP(msg)
82+
83+
;; script variables
84+
local exception_stacktrace
85+
86+
;; save error stacktrace
87+
local start_frame = 0
88+
local levels = 1
89+
local skip = 0
90+
91+
; skip internal frames
92+
93+
exception_stacktrace = {}
94+
while true do
95+
local info = debug.getinfo(skip+levels+start_frame)
96+
if not info then
97+
break
98+
end
99+
local stack_desc = ""
100+
stack_desc = info.source .. ":" .. info.currentline
101+
if info.name then
102+
stack_desc = stack_desc .. " in function " .. info.name
103+
elseif info.what then
104+
stack_desc = stack_desc .. " in " .. info.what .. " chunk"
105+
end
106+
table.insert(exception_stacktrace, stack_desc)
107+
levels = levels + 1
108+
end
109+
110+
exception_stacktrace = table.concat(exception_stacktrace, "\n")

src/handlers/exception_info.lua.t2

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
;;; ../lua-debug
2+
;; support capabilities
3+
supportsExceptionInfoRequest = true,
4+
5+
;; implement handlers
6+
function handlers.exceptionInfo(request)
7+
sendProxyDAP(make_response(request,{
8+
body = {
9+
exceptionId = "",
10+
breakMode = "always",
11+
description = exception_error_msg,
12+
details = {
13+
message = exception_error_msg,
14+
stackTrace = exception_stacktrace,
15+
}
16+
}
17+
}))
18+
end
19+

0 commit comments

Comments
 (0)