Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory and conversion issues in python debugger #1300

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions tools/debugger/debugger_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class EscargotFunction(object):
def __init__(self, is_func, function_info, source, source_name, name, locations):
self.is_func = is_func
self.byte_code_ptr = function_info[0]
self.source = re.split("\r\n|[\r\n]", str(source))
self.source = source
self.source_name = source_name
self.name = name
self.lines = {}
Expand Down Expand Up @@ -832,10 +832,10 @@ def object(self, args):

# pylint: disable=too-many-branches,too-many-locals,too-many-statements
def _parse_source(self, data):
source = ""
source_name = ""
source = bytearray()
source_name = bytearray()
is_func = False
name = ""
name = bytearray()
locations = []

result = ""
Expand All @@ -859,22 +859,34 @@ def _parse_source(self, data):
return "%sSyntaxError: %s%s\n" % (self.red, error_str, self.nocolor)

elif buffer_type in [ESCARGOT_MESSAGE_SOURCE_8BIT, ESCARGOT_MESSAGE_SOURCE_8BIT_END]:
source += self.decode8(data[1:])
source += data[1:]
if buffer_type == ESCARGOT_MESSAGE_SOURCE_8BIT_END:
source = re.split("\r\n|[\r\n]", self.decode8(source))

elif buffer_type in [ESCARGOT_MESSAGE_SOURCE_16BIT, ESCARGOT_MESSAGE_SOURCE_16BIT_END]:
source += self.decode16(data[1:])
source += data[1:]
if buffer_type == ESCARGOT_MESSAGE_SOURCE_16BIT_END:
source = re.split("\r\n|[\r\n]", self.decode16(source))

elif buffer_type in [ESCARGOT_MESSAGE_FILE_NAME_8BIT, ESCARGOT_MESSAGE_FILE_NAME_8BIT_END]:
source_name += self.decode8(data[1:])
source_name += data[1:]
if buffer_type == ESCARGOT_MESSAGE_FILE_NAME_8BIT_END:
source_name = self.decode8(source_name)

elif buffer_type in [ESCARGOT_MESSAGE_FILE_NAME_16BIT, ESCARGOT_MESSAGE_FILE_NAME_16BIT_END]:
source_name += self.decode16(data[1:])
source_name += data[1:]
if buffer_type == ESCARGOT_MESSAGE_FILE_NAME_16BIT_END:
source_name = self.decode16(source_name)

elif buffer_type in [ESCARGOT_MESSAGE_FUNCTION_NAME_8BIT, ESCARGOT_MESSAGE_FUNCTION_NAME_8BIT_END]:
name += self.decode8(data[1:])
name += data[1:]
if buffer_type == ESCARGOT_MESSAGE_FUNCTION_NAME_8BIT_END:
name = self.decode8(name)

elif buffer_type in [ESCARGOT_MESSAGE_FUNCTION_NAME_16BIT, ESCARGOT_MESSAGE_FUNCTION_NAME_16BIT_END]:
name += self.decode16(data[1:])
name += data[1:]
if buffer_type == ESCARGOT_MESSAGE_FUNCTION_NAME_16BIT_END:
name = self.decode16(name)

elif buffer_type == ESCARGOT_MESSAGE_BREAKPOINT_LOCATION:
logging.debug("Breakpoint %s received", source_name)
Expand All @@ -891,10 +903,13 @@ def _parse_source(self, data):
function_info = struct.unpack(self.byte_order + self.pointer_format + self.idx_format + self.idx_format, data[1:])
logging.debug("Pointer %s received %d", source_name, function_info[0])

if isinstance(name, bytearray):
name = ""

function_list.append(EscargotFunction(is_func, function_info, source, source_name, name, locations))

is_func = True
name = ""
name = bytearray()
locations = []

elif buffer_type == ESCARGOT_MESSAGE_RELEASE_FUNCTION:
Expand Down