fix(gdbgui): Fix support of gdbgui on Unix with Python 3.11

Closes https://github.com/espressif/esp-idf/issues/12764
This commit is contained in:
Roland Dobai 2024-01-03 16:08:32 +01:00
parent db1e54a0c5
commit 74b20f3885
2 changed files with 21 additions and 12 deletions

View File

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD # SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import json import json
import os import os
@ -387,15 +387,21 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
gdb = project_desc['monitor_toolprefix'] + 'gdb' gdb = project_desc['monitor_toolprefix'] + 'gdb'
generate_gdbinit_files(gdb, gdbinit, project_desc) generate_gdbinit_files(gdb, gdbinit, project_desc)
gdb_args_list = get_gdb_args(project_desc)
if sys.version_info[:2] >= (3, 11):
# If we use Python 3.11+ then the only compatible gdbgui doesn't support the --gdb-args argument. This
# check is easier than checking gdbgui version or re-running the process in case of gdb-args-related
# failure.
gdb_args = ' '.join(gdb_args_list)
args = ['gdbgui', '-g', ' '.join((gdb, gdb_args))]
else:
# this is a workaround for gdbgui # this is a workaround for gdbgui
# gdbgui is using shlex.split for the --gdb-args option. When the input is: # gdbgui is using shlex.split for the --gdb-args option. When the input is:
# - '"-x=foo -x=bar"', would return ['foo bar'] # - '"-x=foo -x=bar"', would return ['foo bar']
# - '-x=foo', would return ['-x', 'foo'] and mess up the former option '--gdb-args' # - '-x=foo', would return ['-x', 'foo'] and mess up the former option '--gdb-args'
# so for one item, use extra double quotes. for more items, use no extra double quotes. # so for one item, use extra double quotes. for more items, use no extra double quotes.
gdb_args_list = get_gdb_args(project_desc)
gdb_args = '"{}"'.format(' '.join(gdb_args_list)) if len(gdb_args_list) == 1 else ' '.join(gdb_args_list) gdb_args = '"{}"'.format(' '.join(gdb_args_list)) if len(gdb_args_list) == 1 else ' '.join(gdb_args_list)
args = ['gdbgui', '-g', gdb, '--gdb-args', gdb_args] args = ['gdbgui', '-g', gdb, '--gdb-args', gdb_args]
print(args)
if gdbgui_port is not None: if gdbgui_port is not None:
args += ['--port', gdbgui_port] args += ['--port', gdbgui_port]
@ -407,10 +413,11 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
# pygdbmi). # pygdbmi).
env['PURE_PYTHON'] = '1' env['PURE_PYTHON'] = '1'
try: try:
print('Running: ', args)
process = subprocess.Popen(args, stdout=gdbgui_out, stderr=subprocess.STDOUT, bufsize=1, env=env) process = subprocess.Popen(args, stdout=gdbgui_out, stderr=subprocess.STDOUT, bufsize=1, env=env)
except (OSError, subprocess.CalledProcessError) as e: except (OSError, subprocess.CalledProcessError) as e:
print(e) print(e)
if sys.version_info[:2] >= (3, 11): if sys.version_info[:2] >= (3, 11) and sys.platform == 'win32':
raise SystemExit('Unfortunately, gdbgui is supported only with Python 3.10 or older. ' raise SystemExit('Unfortunately, gdbgui is supported only with Python 3.10 or older. '
'See: https://github.com/espressif/esp-idf/issues/10116. ' 'See: https://github.com/espressif/esp-idf/issues/10116. '
'Please use "idf.py gdb" or debug in Eclipse/Vscode instead.') 'Please use "idf.py gdb" or debug in Eclipse/Vscode instead.')

View File

@ -1,5 +1,7 @@
# Python package requirements for gdbgui support ESP-IDF. # Python package requirements for gdbgui support ESP-IDF.
# This feature can be enabled by running "install.{sh,bat,ps1,fish} --enable-gdbgui" # This feature can be enabled by running "install.{sh,bat,ps1,fish} --enable-gdbgui"
# gdbgui is not supported on Python 3.11. See https://github.com/cs01/gdbgui/issues/447 # gdbgui Python 3.11 issue https://github.com/cs01/gdbgui/issues/447 was fixed in 0.15.2.0. Windows users need an
gdbgui; python_version < "3.11" # older Python to use since new gdbgui versions don't support Windows anymore.
gdbgui; sys_platform != 'win32'
gdbgui; sys_platform == 'win32' and python_version < "3.11"