diff --git a/tools/idf_py_actions/debug_ext.py b/tools/idf_py_actions/debug_ext.py index 5e4974beb70..dd4cacc1b41 100644 --- a/tools/idf_py_actions/debug_ext.py +++ b/tools/idf_py_actions/debug_ext.py @@ -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 import json import os @@ -405,15 +405,21 @@ def gdbui(action: str, ctx: Context, args: PropertyDict, gdbgui_port: Optional[s gdb = project_desc['monitor_toolprefix'] + 'gdb' generate_gdbinit_files(gdb, gdbinit, project_desc) - # this is a workaround for gdbgui - # gdbgui is using shlex.split for the --gdb-args option. When the input is: - # - '"-x=foo -x=bar"', would return ['foo bar'] - # - '-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. 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) - args = ['gdbgui', '-g', gdb, '--gdb-args', gdb_args] - print(args) + 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 + # gdbgui is using shlex.split for the --gdb-args option. When the input is: + # - '"-x=foo -x=bar"', would return ['foo bar'] + # - '-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. + 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] if gdbgui_port is not None: args += ['--port', gdbgui_port] @@ -425,10 +431,11 @@ def gdbui(action: str, ctx: Context, args: PropertyDict, gdbgui_port: Optional[s # pygdbmi). env['PURE_PYTHON'] = '1' try: + print('Running: ', args) process = subprocess.Popen(args, stdout=gdbgui_out, stderr=subprocess.STDOUT, bufsize=1, env=env) except (OSError, subprocess.CalledProcessError) as 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. ' 'See: https://github.com/espressif/esp-idf/issues/10116. ' 'Please use "idf.py gdb" or debug in Eclipse/Vscode instead.') diff --git a/tools/requirements/requirements.gdbgui.txt b/tools/requirements/requirements.gdbgui.txt index 0e78495afbb..a00523d1e4d 100644 --- a/tools/requirements/requirements.gdbgui.txt +++ b/tools/requirements/requirements.gdbgui.txt @@ -1,5 +1,7 @@ # Python package requirements for gdbgui support ESP-IDF. # 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_version < "3.11" +# gdbgui Python 3.11 issue https://github.com/cs01/gdbgui/issues/447 was fixed in 0.15.2.0. Windows users need an +# 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"