Skip to content

Splitting the debugger and console part of the python debugger #2406

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

Merged
merged 1 commit into from
Jul 23, 2018

Conversation

TamasZakor
Copy link
Contributor

Move DebuggerPrompt to jerry_client.py
Implement JerryDebugger functions in the jerry_client_ws.py file
Server response is displayed by jerry_client.py

JerryScript-DCO-1.0-Signed-off-by: Tamas Zakor [email protected]

Copy link
Member

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good direction.

return -1


def print_source(debugger, line_num, offset):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be part of the debugger, retuning a list of lines


if result is None:
continue
elif '\3' in result:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\3?

break

prompt.debugger.mainloop()
result = prompt.debugger.smessage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't mainloop() return with this?

self._exec_command(JERRY_DEBUGGER_FINISH)

def next(self):
""" Next breakpoint in the same context """
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these comments are used?

@TamasZakor TamasZakor force-pushed the jerry-db-3 branch 2 times, most recently from 36874be to d39cd04 Compare June 20, 2018 13:47
self.quit = False
self.cont = True
self.debugger.non_interactive = False
self.dsp = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What this variable means or serve? This should be a more talkative name.

if line_num >= 0:
print(self.debugger.print_source(line_num, 0))
elif line_num == 0:
print(self.debugger.print_source(self.debugger.default_viewrange, 0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will never be reached (the previous condition already checked it).

debugger.src_offset_diff = int(max(math.floor(debugger.display / 3), 1))
if direction == "up":
debugger.src_offset -= debugger.src_offset_diff
print(debugger.print_source(debugger.display, debugger.src_offset))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the print functions after the else statement to eliminate the code duplication.


if args.client_source is not None:
if args.client_source != []:
prompt.debugger.store_client_sources(args.client_source)
Copy link
Contributor

@robertsipka robertsipka Jun 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for two if statements.

if args.client_source:
    prompt.debugger.store_client_sources(args.client_source)

@TamasZakor TamasZakor force-pushed the jerry-db-3 branch 7 times, most recently from 479a8d1 to e545934 Compare June 25, 2018 07:32

prompt = DebuggerPrompt(debugger)
prompt.prompt = "(jerry-debugger) "
prompt.debugger.non_interactive = non_interactive
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This non_interactive variable is unnecessary. You can use arg.non_interactive directly.

sbp = self.breakpoint_info
self.breakpoint_info = ''
return sbp
return None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be prettier.

_set_breakpoint(self, args, False)

if self.breakpoint_info == '':
  return None

sbp = self.breakpoint_info
self.breakpoint_info = ''
return sbp

if not args:
result = "Error: Status expected!"
else:
enable = int(args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will leads to a crash if I gave a non integer argument. Please handle it also.

@TamasZakor TamasZakor force-pushed the jerry-db-3 branch 2 times, most recently from bf793e9 to be9f4c2 Compare June 27, 2018 06:47
self.breakpoint_info = ''
return sbp


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the extra line.

else:
result = "Error: Invalid input! Usage 1: [Enable] or 0: [Disable]."
return result

Copy link
Contributor

@robertsipka robertsipka Jun 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the nitpicks, but maybe you could rewrite this function to increase the readability.

    def exception(self, args):
        try:
            enabled = int(args)
        except (ValueError, TypeError) as val_errno:
            return "Error: Positive integer number expected, %s" % (val_errno)

        if enabled not in [0,1]:
            return "Error: Invalid input! Usage 1: [Enable] or 0: [Disable]."

        if enabled:
            logging.debug("Stop at exception enabled")
            self.send_exception_config(enabled)

            return "Stop at exception enabled"

        logging.debug("Stop at exception disabled")
        self.send_exception_config(enabled)

        return "Stop at exception disabled"

except ValueError as val_errno:
print("Error: Positive breakpoint index expected: %s" % val_errno)
else:
sbreak = self.debugger.set_break(args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do these checks on the other side (set_break), and return with a text. If the text is empty, don't print anything. Otherwise print the text.

""" Lists the available breakpoints """
if self.debugger.active_breakpoint_list:
print("=== %sActive breakpoints %s ===" % (self.debugger.green_bg, self.debugger.nocolor))
for breakpoint in self.debugger.active_breakpoint_list.values():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to use functions to return these values instead of directly access private variables. Please make these variables private.


result = prompt.debugger.mainloop()

if result == '':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like a result with a type and data fields, where data depends on the type. It can be a simple class.

if not args:
print("Error: Breakpoint index expected")
print("Delete the given breakpoint, use 'delete all|active|pending' to clear all the given breakpoints ")
elif args in ['all', 'pending', 'active']:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move all of these checks to debugger side.

@TamasZakor TamasZakor force-pushed the jerry-db-3 branch 2 times, most recently from fdd1c71 to 56718fd Compare June 29, 2018 06:30
Copy link
Member

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@robertsipka robertsipka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@robertsipka
Copy link
Contributor

@TamasZakor Please rebase it to the master.

@TamasZakor TamasZakor force-pushed the jerry-db-3 branch 7 times, most recently from 61677d6 to 36f3a22 Compare July 19, 2018 13:17
Copy link
Member

@rerobika rerobika left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work just a minor suggestion.

@@ -169,7 +166,7 @@ def __str__(self):
class JerryFunction(object):
# pylint: disable=too-many-instance-attributes,too-many-arguments
def __init__(self, is_func, byte_code_cp, source, source_name, line, column, name, lines, offsets):
self.is_func = is_func
self.is_func = True if is_func else False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the bool cast is necessary I'd rather use self.is_func = bool (is_func).

Move DebuggerPrompt to jerry_client.py
Implement JerryDebugger functions in the jerry_client_ws.py file
Server response is displayed by jerry_client.py

JerryScript-DCO-1.0-Signed-off-by: Tamas Zakor [email protected]
@zherczeg
Copy link
Member

Can we land this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants