Skip to content

Commit

Permalink
Merge branch 'fix/gdbgui_py311_v5.2' into 'release/v5.2'
Browse files Browse the repository at this point in the history
Tools: Fix support of gdbgui on Unix with Python 3.11 (v5.2)

See merge request espressif/esp-idf!28313
  • Loading branch information
dobairoland committed Feb 18, 2024
2 parents 6717fa0 + 33a62c8 commit 0d3486b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
27 changes: 17 additions & 10 deletions 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
Expand Down Expand Up @@ -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]
Expand All @@ -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.')
Expand Down
6 changes: 4 additions & 2 deletions 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"

0 comments on commit 0d3486b

Please sign in to comment.