refactor(gdb): refactor gdb Debugger to be a gdb command (#7140)

This commit is contained in:
Benign X
2024-10-24 17:57:35 +08:00
committed by GitHub
parent 7f690a2f22
commit a8d2cc05f1
3 changed files with 81 additions and 3 deletions

View File

@@ -1,7 +1,16 @@
from .lvgl import *
from .value import *
from .debugger import *
# Debugger
Debugger()
# Dumps
DumpObj()
# Infos
InfoStyle()
InfoDrawUnit()
# Set instance
set_lvgl_instance(None)

View File

@@ -1,7 +1,54 @@
class Debugger(object):
import argparse
import gdb
class Debugger(gdb.Command):
"""Start debugpy server or connect to a debug server, so we can debug python code from IDE like PyCharm/VSCode"""
def __init__(self, host="localhost", port=11451):
self.__host = host
self.__port = port
super().__init__("debugger", gdb.COMMAND_USER)
def invoke(self, args, from_tty):
parser = argparse.ArgumentParser(description=Debugger.__doc__)
parser.add_argument(
"--host",
type=str,
help="Server listening host",
)
parser.add_argument(
"-p",
"--port",
type=int,
help="Server listening port",
)
parser.add_argument(
"-t",
"--type",
choices=["pycharm", "vscode", "eclipse"],
help="Debugger type",
required=True,
)
try:
args = parser.parse_args(gdb.string_to_argv(args))
except SystemExit:
return
if args.host:
self.__host = args.host
if args.port:
self.__port = args.port
if args.type == "pycharm":
self.connect_to_pycharm()
elif args.type == "vscode":
self.connect_to_vscode()
elif args.type == "eclipse":
self.connect_to_eclipse()
def connect_to_pycharm(self):
try:
@@ -13,7 +60,14 @@ class Debugger(object):
pydevd_pycharm.settrace(self.__host, port=self.__port, stdoutToServer=True, stderrToServer=True)
def connect_to_vscode(self):
raise NotImplementedError()
try:
import debugpy
except ImportError:
print("debugpy module not found. Please install it using pip.")
return
debugpy.listen((self.__host, self.__port))
debugpy.wait_for_client()
def connect_to_eclipse(self):
raise NotImplementedError()
print("Eclipse is not implemented yet")