Skip to content

Commit 7a0ab9d

Browse files
committed
Merge pull request #106485 from limbonaut/fix-release-backtrace-line-numbers
Fix script backtrace reporting wrong line numbers in release exports
2 parents ce400a9 + e06541e commit 7a0ab9d

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

modules/gdscript/gdscript.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ class GDScriptLanguage : public ScriptLanguage {
583583

584584
} strings;
585585

586+
_FORCE_INLINE_ bool should_track_call_stack() const { return track_call_stack; }
586587
_FORCE_INLINE_ bool should_track_locals() const { return track_locals; }
587588
_FORCE_INLINE_ int get_global_array_size() const { return global_array.size(); }
588589
_FORCE_INLINE_ Variant *get_global_array() { return _global_array; }

modules/gdscript/gdscript_byte_codegen.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030

3131
#include "gdscript_byte_codegen.h"
3232

33-
#include "gdscript.h"
34-
3533
#include "core/debugger/engine_debugger.h"
3634

3735
uint32_t GDScriptByteCodeGenerator::add_parameter(const StringName &p_name, bool p_is_optional, const GDScriptDataType &p_type) {
@@ -161,7 +159,6 @@ void GDScriptByteCodeGenerator::end_parameters() {
161159

162160
void GDScriptByteCodeGenerator::write_start(GDScript *p_script, const StringName &p_function_name, bool p_static, Variant p_rpc_config, const GDScriptDataType &p_return_type) {
163161
function = memnew(GDScriptFunction);
164-
debug_stack = GDScriptLanguage::get_singleton()->should_track_locals();
165162

166163
function->name = p_function_name;
167164
function->_script = p_script;
@@ -395,7 +392,7 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() {
395392
function->_lambdas_count = 0;
396393
}
397394

398-
if (debug_stack) {
395+
if (GDScriptLanguage::get_singleton()->should_track_locals()) {
399396
function->stack_debug = stack_debug;
400397
}
401398
function->_stack_size = GDScriptFunction::FIXED_ADDRESSES_MAX + max_locals + temporaries.size();
@@ -1762,9 +1759,12 @@ void GDScriptByteCodeGenerator::write_breakpoint() {
17621759
}
17631760

17641761
void GDScriptByteCodeGenerator::write_newline(int p_line) {
1765-
append_opcode(GDScriptFunction::OPCODE_LINE);
1766-
append(p_line);
1767-
current_line = p_line;
1762+
if (GDScriptLanguage::get_singleton()->should_track_call_stack()) {
1763+
// Add newline for debugger and stack tracking if enabled in the project settings.
1764+
append_opcode(GDScriptFunction::OPCODE_LINE);
1765+
append(p_line);
1766+
current_line = p_line;
1767+
}
17681768
}
17691769

17701770
void GDScriptByteCodeGenerator::write_return(const Address &p_return_value) {

modules/gdscript/gdscript_byte_codegen.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#pragma once
3232

33+
#include "gdscript.h"
3334
#include "gdscript_codegen.h"
3435
#include "gdscript_function.h"
3536
#include "gdscript_utility_functions.h"
@@ -74,7 +75,6 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator {
7475

7576
bool ended = false;
7677
GDScriptFunction *function = nullptr;
77-
bool debug_stack = false;
7878

7979
Vector<int> opcodes;
8080
List<RBMap<StringName, int>> stack_id_stack;
@@ -162,7 +162,7 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator {
162162
max_locals = locals.size();
163163
}
164164
stack_identifiers[p_id] = p_stackpos;
165-
if (debug_stack) {
165+
if (GDScriptLanguage::get_singleton()->should_track_locals()) {
166166
block_identifiers[p_id] = p_stackpos;
167167
GDScriptFunction::StackDebug sd;
168168
sd.added = true;
@@ -176,7 +176,7 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator {
176176
void push_stack_identifiers() {
177177
stack_identifiers_counts.push_back(locals.size());
178178
stack_id_stack.push_back(stack_identifiers);
179-
if (debug_stack) {
179+
if (GDScriptLanguage::get_singleton()->should_track_locals()) {
180180
RBMap<StringName, int> block_ids(block_identifiers);
181181
block_identifier_stack.push_back(block_ids);
182182
block_identifiers.clear();
@@ -197,7 +197,7 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator {
197197
dirty_locals.insert(i + GDScriptFunction::FIXED_ADDRESSES_MAX);
198198
}
199199
locals.resize(current_locals);
200-
if (debug_stack) {
200+
if (GDScriptLanguage::get_singleton()->should_track_locals()) {
201201
for (const KeyValue<StringName, int> &E : block_identifiers) {
202202
GDScriptFunction::StackDebug sd;
203203
sd.added = false;

modules/gdscript/gdscript_compiler.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,10 +1903,7 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Sui
19031903
for (int i = 0; i < p_block->statements.size(); i++) {
19041904
const GDScriptParser::Node *s = p_block->statements[i];
19051905

1906-
#ifdef DEBUG_ENABLED
1907-
// Add a newline before each statement, since the debugger needs those.
19081906
gen->write_newline(s->start_line);
1909-
#endif
19101907

19111908
switch (s->type) {
19121909
case GDScriptParser::Node::MATCH: {
@@ -1955,10 +1952,8 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Sui
19551952
// Add locals in block before patterns, so temporaries don't use the stack address for binds.
19561953
List<GDScriptCodeGenerator::Address> branch_locals = _add_block_locals(codegen, branch->block);
19571954

1958-
#ifdef DEBUG_ENABLED
1959-
// Add a newline before each branch, since the debugger needs those.
19601955
gen->write_newline(branch->start_line);
1961-
#endif
1956+
19621957
// For each pattern in branch.
19631958
GDScriptCodeGenerator::Address pattern_result = codegen.add_temporary();
19641959
for (int k = 0; k < branch->patterns.size(); k++) {
@@ -2367,7 +2362,6 @@ GDScriptFunction *GDScriptCompiler::_parse_function(Error &r_error, GDScript *p_
23672362
}
23682363

23692364
if (field->initializer) {
2370-
// Emit proper line change.
23712365
codegen.generator->write_newline(field->initializer->start_line);
23722366

23732367
GDScriptCodeGenerator::Address src_address = _parse_expression(codegen, r_error, field->initializer, false, true);
@@ -2562,7 +2556,6 @@ GDScriptFunction *GDScriptCompiler::_make_static_initializer(Error &r_error, GDS
25622556
}
25632557

25642558
if (field->initializer) {
2565-
// Emit proper line change.
25662559
codegen.generator->write_newline(field->initializer->start_line);
25672560

25682561
GDScriptCodeGenerator::Address src_address = _parse_expression(codegen, r_error, field->initializer, false, true);

0 commit comments

Comments
 (0)