# Protocol: debug, part 1 of 2

The `debug` commands a program sends to a running game, as the engine describes them: what each takes, what it answers and what it does. Back to [all commands](../protocol-commands.md).

## debug.attach

`debug.attach {scripts?: text, errors?: text} -> {attached: value, named: value, process: integer, state: text, step: integer, reason: text, file: text, line: integer, column: integer, nil: record, last_entity: text, last_entity_name: text, error: text, stops: integer, errors: text, note: text, pending_reload: [text]}` · write

Attaches the script debugger: from then on breakpoints, debug.pause and an error a script raises stop the scripts' `step`, part way through the game's step. A game runs the same, checksum for checksum, with a debugger attached that stops nothing. Scripts are compiled with the names of their locals only while it is attached: a game nothing has moved yet (step 0) is loaded again that way at once; one that has run keeps its code, and `named` is false until its scripts are loaded again. It stays attached, with its breakpoints, across game.reset. Not in an exported game.

| Parameters | Type | Meaning |
| --- | --- | --- |
| `scripts?` | text | "keep" (the default): the code that is loaded runs on untouched. "reload": every script is compiled again now, as script.reload would, so its top level runs again and what it keeps in local variables of its own starts over. |
| `errors?` | text | "stop" (what it is when first attached): a script stops where it raises an error nothing catches. "pass": such an error ends the step as it does with no debugger. Left out: as it was. Attach again to change it. |

| Result | Type | Meaning |
| --- | --- | --- |
| `attached` | value | true when the debugger is attached, false when not. |
| `named` | value | true when every loaded script is compiled with the names of its locals, so debug.scope can show them: it was loaded, reloaded or reset while the debugger was attached. false otherwise, and when no debugger is attached. |
| `process` | integer | The engine's own process id on this machine: where the game's scripts run, for a debugger of the machine to attach to. `frost dev` prints the same number on the line after the one that says where it listens, as `process PID`. |
| `state` | text | "running", or "paused" while a script is stopped part way through a step. |
| `step` | integer | How many fixed steps have run. |
| `reason` | text | Why it stopped: "breakpoint", "step", "pause" or "error". null while running. |
| `file` | text | The script or library it is stopped in, as the project names it. null while running. |
| `line` | integer | The line it stands on, which has not run yet; for an error, the line that raised it. null while running. |
| `column` | integer | The column on that line, from 1 in UTF-16 code units: the line's first code, as Luau stops at lines; for an error, where on the line it failed (the name that was nil, the call to error or assert). null while running. |
| `nil` | record | For an error that indexed or called a nil: {name, how, key, also, since}, the expression that was nil as written ("state.boss", "t.go", "t:go"), "index" or "call", the key it was indexed with or null, the other expressions on the line it may have been, and since (null here: a failed game.step says it). null otherwise. |
| `last_entity` | text | The id of the entity the script last read, wrote or removed in this step, like "e3.0": one of the many a script may touch, and most often the one an error is about. null when it touched none, and while running. |
| `last_entity_name` | text | That entity's scene name, or null. |
| `error` | text | The error's message when the reason is "error", else null. |
| `stops` | integer | How many times a script has stopped since this server started: it counts up at every stop, so a client that polls can tell a new stop from the one it knew, though file and line be the same. |
| `errors` | text | "stop": a script stops where it raises an error. "pass": the error ends the step as with no debugger. null when no debugger is attached. |
| `note` | text | null, or a sentence to show the person: the scripts were loaded before the debugger attached, so their locals have no names, and what to do about it. |
| `pending_reload` | [text] | The scripts whose new code waits for the stopped step to end: saved, or sent with script.reload, while a script was stopped. Empty otherwise. |

## debug.detach

`debug.detach {scripts?: text} -> {attached: value, named: value, process: integer, state: text, step: integer, reason: text, file: text, line: integer, column: integer, nil: record, last_entity: text, last_entity_name: text, error: text, stops: integer, errors: text, note: text, pending_reload: [text]}` · write

Detaches the debugger and forgets its breakpoints. A stopped script first runs to the end of its step; if that step fails, this fails with its error and the debugger is detached all the same. Scripts loaded from then on are compiled exactly as an exported game compiles them; those already loaded run on as they are until then.

| Parameters | Type | Meaning |
| --- | --- | --- |
| `scripts?` | text | "keep" (the default): the code that is loaded runs on untouched. "reload": every script is compiled again now, as script.reload would, so its top level runs again and what it keeps in local variables of its own starts over. |

| Result | Type | Meaning |
| --- | --- | --- |
| `attached` | value | true when the debugger is attached, false when not. |
| `named` | value | true when every loaded script is compiled with the names of its locals, so debug.scope can show them: it was loaded, reloaded or reset while the debugger was attached. false otherwise, and when no debugger is attached. |
| `process` | integer | The engine's own process id on this machine: where the game's scripts run, for a debugger of the machine to attach to. `frost dev` prints the same number on the line after the one that says where it listens, as `process PID`. |
| `state` | text | "running", or "paused" while a script is stopped part way through a step. |
| `step` | integer | How many fixed steps have run. |
| `reason` | text | Why it stopped: "breakpoint", "step", "pause" or "error". null while running. |
| `file` | text | The script or library it is stopped in, as the project names it. null while running. |
| `line` | integer | The line it stands on, which has not run yet; for an error, the line that raised it. null while running. |
| `column` | integer | The column on that line, from 1 in UTF-16 code units: the line's first code, as Luau stops at lines; for an error, where on the line it failed (the name that was nil, the call to error or assert). null while running. |
| `nil` | record | For an error that indexed or called a nil: {name, how, key, also, since}, the expression that was nil as written ("state.boss", "t.go", "t:go"), "index" or "call", the key it was indexed with or null, the other expressions on the line it may have been, and since (null here: a failed game.step says it). null otherwise. |
| `last_entity` | text | The id of the entity the script last read, wrote or removed in this step, like "e3.0": one of the many a script may touch, and most often the one an error is about. null when it touched none, and while running. |
| `last_entity_name` | text | That entity's scene name, or null. |
| `error` | text | The error's message when the reason is "error", else null. |
| `stops` | integer | How many times a script has stopped since this server started: it counts up at every stop, so a client that polls can tell a new stop from the one it knew, though file and line be the same. |
| `errors` | text | "stop": a script stops where it raises an error. "pass": the error ends the step as with no debugger. null when no debugger is attached. |
| `note` | text | null, or a sentence to show the person: the scripts were loaded before the debugger attached, so their locals have no names, and what to do about it. |
| `pending_reload` | [text] | The scripts whose new code waits for the stopped step to end: saved, or sent with script.reload, while a script was stopped. Empty otherwise. |

## debug.breakpoints

`debug.breakpoints {file: text, lines: [integer]} -> {file: text, breakpoints: [record]}` · write

Makes the given lines the breakpoints of one file, in place of those it had, and says where each was set. They are kept and set again when the file is reloaded and when the game is reset.

| Parameters | Type | Meaning |
| --- | --- | --- |
| `file` | text | A script's name as game.info lists it, or a library's as the project lists it. |
| `lines` | [integer] | The lines to stop at, from 1. An empty list clears the file's breakpoints. |

| Result | Type | Meaning |
| --- | --- | --- |
| `file` | text | The file. |
| `breakpoints` | [record] | One {asked, line} per line asked for, in order. line is where the breakpoint is: asked itself, or the next line that has code when asked has none (a comment, a blank line), or null when no code follows or no loaded code is from that file. |

## debug.pause

`debug.pause {} -> {attached: value, named: value, process: integer, state: text, step: integer, reason: text, file: text, line: integer, column: integer, nil: record, last_entity: text, last_entity_name: text, error: text, stops: integer, errors: text, note: text, pending_reload: [text]}` · write

Asks the scripts to stop at the first line of a `step` that runs next. Nothing stops until the game steps: by itself under frost dev, by game.step elsewhere.

| Result | Type | Meaning |
| --- | --- | --- |
| `attached` | value | true when the debugger is attached, false when not. |
| `named` | value | true when every loaded script is compiled with the names of its locals, so debug.scope can show them: it was loaded, reloaded or reset while the debugger was attached. false otherwise, and when no debugger is attached. |
| `process` | integer | The engine's own process id on this machine: where the game's scripts run, for a debugger of the machine to attach to. `frost dev` prints the same number on the line after the one that says where it listens, as `process PID`. |
| `state` | text | "running", or "paused" while a script is stopped part way through a step. |
| `step` | integer | How many fixed steps have run. |
| `reason` | text | Why it stopped: "breakpoint", "step", "pause" or "error". null while running. |
| `file` | text | The script or library it is stopped in, as the project names it. null while running. |
| `line` | integer | The line it stands on, which has not run yet; for an error, the line that raised it. null while running. |
| `column` | integer | The column on that line, from 1 in UTF-16 code units: the line's first code, as Luau stops at lines; for an error, where on the line it failed (the name that was nil, the call to error or assert). null while running. |
| `nil` | record | For an error that indexed or called a nil: {name, how, key, also, since}, the expression that was nil as written ("state.boss", "t.go", "t:go"), "index" or "call", the key it was indexed with or null, the other expressions on the line it may have been, and since (null here: a failed game.step says it). null otherwise. |
| `last_entity` | text | The id of the entity the script last read, wrote or removed in this step, like "e3.0": one of the many a script may touch, and most often the one an error is about. null when it touched none, and while running. |
| `last_entity_name` | text | That entity's scene name, or null. |
| `error` | text | The error's message when the reason is "error", else null. |
| `stops` | integer | How many times a script has stopped since this server started: it counts up at every stop, so a client that polls can tell a new stop from the one it knew, though file and line be the same. |
| `errors` | text | "stop": a script stops where it raises an error. "pass": the error ends the step as with no debugger. null when no debugger is attached. |
| `note` | text | null, or a sentence to show the person: the scripts were loaded before the debugger attached, so their locals have no names, and what to do about it. |
| `pending_reload` | [text] | The scripts whose new code waits for the stopped step to end: saved, or sent with script.reload, while a script was stopped. Empty otherwise. |

## debug.continue

`debug.continue {} -> {attached: value, named: value, process: integer, state: text, step: integer, reason: text, file: text, line: integer, column: integer, nil: record, last_entity: text, last_entity_name: text, error: text, stops: integer, errors: text, note: text, pending_reload: [text]}` · write

Lets the stopped script run on. It returns when a script stops again or the step is over: the scripts after it and the rest of the step (animation, sounds, a scene change) then run once, and what the step fails with is this command's error.

| Result | Type | Meaning |
| --- | --- | --- |
| `attached` | value | true when the debugger is attached, false when not. |
| `named` | value | true when every loaded script is compiled with the names of its locals, so debug.scope can show them: it was loaded, reloaded or reset while the debugger was attached. false otherwise, and when no debugger is attached. |
| `process` | integer | The engine's own process id on this machine: where the game's scripts run, for a debugger of the machine to attach to. `frost dev` prints the same number on the line after the one that says where it listens, as `process PID`. |
| `state` | text | "running", or "paused" while a script is stopped part way through a step. |
| `step` | integer | How many fixed steps have run. |
| `reason` | text | Why it stopped: "breakpoint", "step", "pause" or "error". null while running. |
| `file` | text | The script or library it is stopped in, as the project names it. null while running. |
| `line` | integer | The line it stands on, which has not run yet; for an error, the line that raised it. null while running. |
| `column` | integer | The column on that line, from 1 in UTF-16 code units: the line's first code, as Luau stops at lines; for an error, where on the line it failed (the name that was nil, the call to error or assert). null while running. |
| `nil` | record | For an error that indexed or called a nil: {name, how, key, also, since}, the expression that was nil as written ("state.boss", "t.go", "t:go"), "index" or "call", the key it was indexed with or null, the other expressions on the line it may have been, and since (null here: a failed game.step says it). null otherwise. |
| `last_entity` | text | The id of the entity the script last read, wrote or removed in this step, like "e3.0": one of the many a script may touch, and most often the one an error is about. null when it touched none, and while running. |
| `last_entity_name` | text | That entity's scene name, or null. |
| `error` | text | The error's message when the reason is "error", else null. |
| `stops` | integer | How many times a script has stopped since this server started: it counts up at every stop, so a client that polls can tell a new stop from the one it knew, though file and line be the same. |
| `errors` | text | "stop": a script stops where it raises an error. "pass": the error ends the step as with no debugger. null when no debugger is attached. |
| `note` | text | null, or a sentence to show the person: the scripts were loaded before the debugger attached, so their locals have no names, and what to do about it. |
| `pending_reload` | [text] | The scripts whose new code waits for the stopped step to end: saved, or sent with script.reload, while a script was stopped. Empty otherwise. |

## debug.step

`debug.step {kind: text} -> {attached: value, named: value, process: integer, state: text, step: integer, reason: text, file: text, line: integer, column: integer, nil: record, last_entity: text, last_entity_name: text, error: text, stops: integer, errors: text, note: text, pending_reload: [text]}` · write

Runs the stopped script to its next line and stops it there. When the script's `step` ends first, the game's step finishes as after debug.continue and the scripts stop at the first line that runs next.

| Parameters | Type | Meaning |
| --- | --- | --- |
| `kind` | text | "over": the next line of this function, running what the line calls. "into": the next line, inside a function the line calls. "out": the line this function returns to. |

| Result | Type | Meaning |
| --- | --- | --- |
| `attached` | value | true when the debugger is attached, false when not. |
| `named` | value | true when every loaded script is compiled with the names of its locals, so debug.scope can show them: it was loaded, reloaded or reset while the debugger was attached. false otherwise, and when no debugger is attached. |
| `process` | integer | The engine's own process id on this machine: where the game's scripts run, for a debugger of the machine to attach to. `frost dev` prints the same number on the line after the one that says where it listens, as `process PID`. |
| `state` | text | "running", or "paused" while a script is stopped part way through a step. |
| `step` | integer | How many fixed steps have run. |
| `reason` | text | Why it stopped: "breakpoint", "step", "pause" or "error". null while running. |
| `file` | text | The script or library it is stopped in, as the project names it. null while running. |
| `line` | integer | The line it stands on, which has not run yet; for an error, the line that raised it. null while running. |
| `column` | integer | The column on that line, from 1 in UTF-16 code units: the line's first code, as Luau stops at lines; for an error, where on the line it failed (the name that was nil, the call to error or assert). null while running. |
| `nil` | record | For an error that indexed or called a nil: {name, how, key, also, since}, the expression that was nil as written ("state.boss", "t.go", "t:go"), "index" or "call", the key it was indexed with or null, the other expressions on the line it may have been, and since (null here: a failed game.step says it). null otherwise. |
| `last_entity` | text | The id of the entity the script last read, wrote or removed in this step, like "e3.0": one of the many a script may touch, and most often the one an error is about. null when it touched none, and while running. |
| `last_entity_name` | text | That entity's scene name, or null. |
| `error` | text | The error's message when the reason is "error", else null. |
| `stops` | integer | How many times a script has stopped since this server started: it counts up at every stop, so a client that polls can tell a new stop from the one it knew, though file and line be the same. |
| `errors` | text | "stop": a script stops where it raises an error. "pass": the error ends the step as with no debugger. null when no debugger is attached. |
| `note` | text | null, or a sentence to show the person: the scripts were loaded before the debugger attached, so their locals have no names, and what to do about it. |
| `pending_reload` | [text] | The scripts whose new code waits for the stopped step to end: saved, or sent with script.reload, while a script was stopped. Empty otherwise. |
