Skip to content

Commit

Permalink
LocalDebugger: Allow specifying quit exit code
Browse files Browse the repository at this point in the history
Rather than always exiting with a failure code, allow the user to
specify the code they want. This can be used to exit successfully, or it
could be used to exit with a unique code that the caller can detect.
  • Loading branch information
dbnicholson committed Jul 26, 2024
1 parent 2e77a97 commit c992fca
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions core/debugger/local_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,31 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
print_line("Added breakpoint at " + source + ":" + itos(linenr));
}

} else if (line == "q" || line == "quit" ||
} else if (line.begins_with("q") || line.begins_with("quit") ||
(line.is_empty() && feof(stdin))) {
int exit_code = EXIT_FAILURE;
if (line.get_slice_count(" ") > 1) {
String value = line.get_slicec(' ', 1);
if (!value.is_numeric()) {
print_line("Error: Invalid exit code '" + value + "'.");
continue;
}

exit_code = value.to_int();
if (exit_code < 0) {
print_line("Error: Invalid exit code " + itos(exit_code) + ".");
continue;
}
}

// Do not stop again on quit
script_debugger->clear_breakpoints();
script_debugger->set_depth(-1);
script_debugger->set_lines_left(-1);

MainLoop *main_loop = OS::get_singleton()->get_main_loop();
if (main_loop->get_class() == "SceneTree") {
main_loop->call("quit", EXIT_FAILURE);
main_loop->call("quit", exit_code);
}
break;
} else if (line.begins_with("delete")) {
Expand Down Expand Up @@ -312,7 +327,7 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
print_line("\tbr,break [source:line]\t List all breakpoints or place a breakpoint.");
print_line("\tdelete [source:line]:\t Delete one/all breakpoints.");
print_line("\tset [key=value]:\t List all options, or set one.");
print_line("\tq,quit\t\t\t Quit application.");
print_line("\tq,quit [exit_code]\t\t Quit application.");
} else {
print_line("Error: Invalid command, enter \"help\" for assistance.");
}
Expand Down

0 comments on commit c992fca

Please sign in to comment.