Skip to content

Commit 7d2d144

Browse files
committed
-add breakpoint statement to ease with debugging, closes #3165
1 parent 99736e6 commit 7d2d144

File tree

7 files changed

+34
-1
lines changed

7 files changed

+34
-1
lines changed

modules/gdscript/gd_compiler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,10 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo
11561156
codegen.opcodes.push_back(GDFunction::OPCODE_ASSERT);
11571157
codegen.opcodes.push_back(ret);
11581158
} break;
1159+
case GDParser::Node::TYPE_BREAKPOINT: {
1160+
// try subblocks
1161+
codegen.opcodes.push_back(GDFunction::OPCODE_BREAKPOINT);
1162+
} break;
11591163
case GDParser::Node::TYPE_LOCAL_VAR: {
11601164

11611165

modules/gdscript/gd_parser.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,17 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
18621862
return;
18631863
}
18641864
} break;
1865+
case GDTokenizer::TK_PR_BREAKPOINT: {
1866+
1867+
tokenizer->advance();
1868+
BreakpointNode *bn = alloc_node<BreakpointNode>();
1869+
p_block->statements.push_back(bn);
1870+
1871+
if (!_end_statement()) {
1872+
_set_error("Expected end of statement after breakpoint.");
1873+
return;
1874+
}
1875+
} break;
18651876
default: {
18661877

18671878
Node *expression = _parse_and_reduce_expression(p_block,p_static,false,true);

modules/gdscript/gd_parser.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class GDParser {
5454
TYPE_CONTROL_FLOW,
5555
TYPE_LOCAL_VAR,
5656
TYPE_ASSERT,
57+
TYPE_BREAKPOINT,
5758
TYPE_NEWLINE,
5859
};
5960

@@ -276,6 +277,10 @@ class GDParser {
276277
AssertNode() { type=TYPE_ASSERT; }
277278
};
278279

280+
struct BreakpointNode : public Node {
281+
BreakpointNode() { type=TYPE_BREAKPOINT; }
282+
};
283+
279284
struct NewLineNode : public Node {
280285
NewLineNode() { type=TYPE_NEWLINE; }
281286
};

modules/gdscript/gd_script.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,14 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
10771077

10781078
ip+=2;
10791079
} continue;
1080+
case OPCODE_BREAKPOINT: {
1081+
#ifdef DEBUG_ENABLED
1082+
if (ScriptDebugger::get_singleton()) {
1083+
GDScriptLanguage::get_singleton()->debug_break("Breakpoint Statement",true);
1084+
}
1085+
#endif
1086+
ip+=1;
1087+
} continue;
10801088
case OPCODE_LINE: {
10811089
CHECK_SPACE(2);
10821090

@@ -2672,6 +2680,7 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const {
26722680
"or",
26732681
"export",
26742682
"assert",
2683+
"breakpoint",
26752684
"yield",
26762685
"static",
26772686
"float",

modules/gdscript/gd_script.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class GDFunction {
7171
OPCODE_ITERATE_BEGIN,
7272
OPCODE_ITERATE,
7373
OPCODE_ASSERT,
74+
OPCODE_BREAKPOINT,
7475
OPCODE_LINE,
7576
OPCODE_END
7677
};

modules/gdscript/gd_tokenizer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ const char* GDTokenizer::token_names[TK_MAX]={
9898
"assert",
9999
"yield",
100100
"signal",
101+
"breakpoint",
101102
"'['",
102103
"']'",
103104
"'{'",
@@ -861,6 +862,7 @@ void GDTokenizerText::_advance() {
861862
{TK_PR_ASSERT,"assert"},
862863
{TK_PR_YIELD,"yield"},
863864
{TK_PR_SIGNAL,"signal"},
865+
{TK_PR_BREAKPOINT,"breakpoint"},
864866
{TK_PR_CONST,"const"},
865867
//controlflow
866868
{TK_CF_IF,"if"},
@@ -1041,7 +1043,7 @@ void GDTokenizerText::advance(int p_amount) {
10411043

10421044
//////////////////////////////////////////////////////////////////////////////////////////////////////
10431045

1044-
#define BYTECODE_VERSION 6
1046+
#define BYTECODE_VERSION 7
10451047

10461048
Error GDTokenizerBuffer::set_code_buffer(const Vector<uint8_t> & p_buffer) {
10471049

modules/gdscript/gd_tokenizer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class GDTokenizer {
106106
TK_PR_ASSERT,
107107
TK_PR_YIELD,
108108
TK_PR_SIGNAL,
109+
TK_PR_BREAKPOINT,
109110
TK_BRACKET_OPEN,
110111
TK_BRACKET_CLOSE,
111112
TK_CURLY_BRACKET_OPEN,

0 commit comments

Comments
 (0)