Skip to content

Commit 55a6637

Browse files
authored
Merge pull request #94 from VlachJosef/master
Debugger support
2 parents dde7ffa + 58ef86f commit 55a6637

8 files changed

+2591
-15
lines changed

Diff for: README.md

+111-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ The following shortcuts are available by default:
217217
- <kbd>C-c C-b a</kbd> `gdscript-docs-browse-api`
218218
- <kbd>C-c C-b o</kbd> `gdscript-docs-browse-symbol-at-point`
219219
- Open hydra:
220-
- <kbd>C-c r</kbd> `gdscript-hydra-show` (require hydra package to be installed
220+
- <kbd>C-c r</kbd> `gdscript-hydra-show` (require hydra package to be installed)
221+
- <kbd>C-c n</kbd> `gdscript-debug-hydra` (require hydra package to be installed)
221222

222223
## Customization
223224

@@ -231,3 +232,112 @@ Code example:
231232
(setq gdscript-godot-executable "/path/to/godot") ;; Use this executable instead of 'godot' to open the Godot editor.
232233
(setq gdscript-gdformat-save-and-format t) ;; Save all buffers and format them with gdformat anytime Godot executable is run.
233234
```
235+
236+
## Debugger
237+
238+
Use <kbd>C-c C-d b</kbd> to add breakpoint to your GDScript file. Red dot will appear in the left fringe to indicate position where breakpoint is placed.
239+
Use <kbd>C-c C-d r</kbd> to remove breakpoint.
240+
241+
Once first breakpoint is added to the project, buffer named `* Breakpoints *` is created. This buffer displays all existing breakpoints in a project. Pressing <kbd>D</kbd> on breakpoint line deletes the breakpoint. Pressing <kbd>RET</kbd> on breakpoint line shows GDScript file with that breakpoint in other buffer.
242+
243+
When any breakpoint exists, running project will automatically start debugger server (if one isn't already running) and connect to it.
244+
Debugger server runs on `localhost` with port specified by `gdscript-debug-port` customizable variable (`6010` by default).
245+
246+
Once breakpoint is hit in your code, Emacs will show two special buffers with information related to a position of the breakpoint:
247+
248+
- `* Stack frame vars *` - Display locals/members/globals variables for current stack point. It show variable name, its type and its value.
249+
- `* Inspector *` - Display detailed information about selected `ObjectId`. By default it show `self` reference.
250+
251+
Any `ObjectId` in those two buffers can be inspected by pressing <kbd>RET</kbd> when point is on corresponding line.
252+
253+
### Oneline/multiline display
254+
255+
Variable values of types `Dictionary`, `PoolRealArray`, `PoolStringArray`, `PoolVector2Array`, `PoolVector3Array` and `PoolColorArray` could be toggled from one line display to multiline display by pressing `TAB` on corresponding line.
256+
257+
### Fetching `ObjectId` details
258+
259+
Pressing <kbd>d</kbd> in `* Stack frame vars *` or `* Inspector *` buffers (or on Debug Hydra) will fetch on the background data for all `ObjectId`s present in those two buffers and once all `ObjectId`s data are fetched, these two buffer are redisplayed. This redisplay will contain two additional informations about given `ObjectId`:
260+
- real type (for example `KinematicBody2D` instead of `ObjectId`)
261+
- node path
262+
263+
Also fetched data are cached and not fetched again when said `ObjectId` is inspected later on (until new breakpoint is hit).
264+
265+
On breakpoint hit Debug Hydra will be displayed below `* Stack frame vars *` and `* Inspector *` buffers.
266+
267+
### Debug Hydra
268+
269+
```
270+
n next c continue m step b breakpoints s stack v vars i inspector t scene-tree d details
271+
o pin u unpin q quit
272+
```
273+
274+
- <kbd>n</kbd> - Jump to next line and stops there
275+
- <kbd>c</kbd> - Continue program execution until another breakpoint is hit
276+
- <kbd>m</kbd> - Step into
277+
- <kbd>s</kbd> - Show `* Stack dump *` buffer
278+
- <kbd>v</kbd> - Show `* Stack frame vars *` buffer
279+
- <kbd>i</kbd> - Show `* Inspector *` buffer
280+
- <kbd>t</kbd> - Show `* Scene tree *` buffer
281+
- <kbd>d</kbd> - Fetch details for all `ObjectId`s present in `* Stack frame vars *` and `* Inspector *` buffers and redisplay them
282+
- <kbd>o</kbd> - Pin current `self` `ObjectId` in `* Inspector *` buffer. It stays displayed until it cease to exists or until it get unpinned
283+
- <kbd>u</kbd> - Unpin currently pinned `ObjectId`
284+
- <kbd>q</kbd> - Close Debug Hydra
285+
286+
### `* Stack frame vars *` buffer
287+
288+
Main source of information about running program. Contains information about locals/members/globals variables.
289+
290+
- Press <kbd>TAB</kbd> to toggling oneline/multiline display for selected types
291+
- Press <kbd>RET</kbd> on `ObjectId` line to display its details in `* Inspector *`buffer
292+
- Press <kbd>l</kbd> to display `* Stack dump *` buffer
293+
- Press <kbd>d</kbd> to display additional details for `ObjectId` variables
294+
- Press <kbd>p</kbd> to go to previous line
295+
- Press <kbd>n</kbd> to go to next line
296+
- Press <kbd>o</kbd> to pin current `ObjectId` in `* Inspector *` buffer
297+
- Press <kbd>u</kbd> to unpin currently pinned `ObjectId`
298+
- Press <kbd>q</kbd> to close the buffer
299+
300+
### `* Inspector *` buffer
301+
302+
Contains information about inspected object. By default `self` variable from `* Stack frame vars *` is displayed. Inspected object is kept to be focused until other object is inspected or until inspected object cease to exists, in which case current `self` is displayed instead.
303+
304+
- Press <kbd>TAB</kbd> to toggling oneline/multiline display for selected types
305+
- Press <kbd>RET</kbd> on `ObjectId` line to display its details
306+
- Press <kbd>RET</kbd> on `Node/path` line (second line from the top) to show given `ObjectId` in `* Scene Tree *` buffer
307+
- Press <kbd>l</kbd> deep in nested `ObjectId` to navigate one level up in the structure (ie. back). Pressing `l` while on top level object displays `* Stack frame vars *` buffer
308+
- Press <kbd>d</kbd> to display additional details for `ObjectId` variables
309+
- Press <kbd>p</kbd> to go to previous line
310+
- Press <kbd>n</kbd> to go to next line
311+
- Press <kbd>o</kbd> to pin current `ObjectId` in `* Inspector *` buffer
312+
- Press <kbd>u</kbd> to unpin currently pinned `ObjectId`
313+
- Press <kbd>q</kbd> to close the buffer
314+
315+
### `* Stack dump *` buffer
316+
317+
Contains stack dump information.
318+
319+
- Press <kbd>SPC</kbd> to jump to gdscript file where stack frame points to
320+
- Press <kbd>RET</kbd> to jump to gdscript file and to show `* Stack frame vars *`, `* Inspector *` buffers and a Debug Hydra
321+
- Press <kbd>l</kbd> to display `* Stack frame vars *` buffer
322+
- Press <kbd>p</kbd> to go to previous line
323+
- Press <kbd>n</kbd> to go to next line
324+
- Press <kbd>q</kbd> to close the buffer
325+
326+
### `* Breakpoints *` buffer
327+
328+
Contains list of all existing breakpoints.
329+
330+
- Press <kbd>SPC</kbd> to enable/disable all breakpoints
331+
- Press <kbd>RET</kbd> to open gdscript file where on give breakpoint position
332+
- Press <kbd>TAB</kbd> to display `* Stack dump *` buffer
333+
- Press <kbd>D</kbd> to delete the breakpoint
334+
- Press <kbd>q</kbd> to close the buffer
335+
336+
### `* Scene tree *` buffer
337+
338+
Contains tree visualisation of all `ObjectId`s in the running program.
339+
340+
- Press <kbd>RET</kbd> to open corresponding `ObjectId` in `* Inspector *` buffer
341+
- Press <kbd>p</kbd> to go to previous line
342+
- Press <kbd>n</kbd> to go to next line
343+
- Press <kbd>q</kbd> to close the buffer

Diff for: gdscript-comint.el

+9-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
(require 'comint)
3838
(require 'compile)
3939
(require 'gdscript-customization)
40+
(require 'gdscript-debug)
4041
(require 'gdscript-format)
4142
(require 'gdscript-utils)
4243

@@ -47,6 +48,7 @@
4748
comint-mode-map))
4849
(define-key map (kbd "C-a") 'comint-bol)
4950
(define-key map (kbd "C-c r") 'gdscript-hydra-show)
51+
(define-key map (kbd "C-c n") 'gdscript-debug-hydra)
5052
map)
5153
"Basic mode map for `godot-mode'.")
5254

@@ -76,9 +78,13 @@ When run it will kill existing process if one exists."
7678
Set process's buffer `inhibit-read-only' temporalily to value t,
7779
so that `internal-default-process-sentinel' can insert status
7880
message into the process’s buffer."
79-
(with-current-buffer (process-buffer process)
80-
(let ((inhibit-read-only t))
81-
(internal-default-process-sentinel process event))))
81+
(cond
82+
((string-match "hangup: 1\n" event)
83+
nil)
84+
(t
85+
(with-current-buffer (process-buffer process)
86+
(let ((inhibit-read-only t))
87+
(internal-default-process-sentinel process event))))))
8288

8389
(define-derived-mode godot-mode comint-mode "godot"
8490
"Major mode for godot.

Diff for: gdscript-customization.el

+5
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ directory path containing the file `index.html'."
139139
:type 'string
140140
:group 'gdscript)
141141

142+
(defcustom gdscript-debug-port 6010
143+
"Debugger server port."
144+
:type 'integer
145+
:group 'gdscript)
146+
142147

143148
(provide 'gdscript-customization)
144149
;;; gdscript-customization.el ends here

0 commit comments

Comments
 (0)