Skip to content

gh-154580: Fix python-gdb.py pretty-printing non-ASCII strings in non-UTF-8 locales#154581

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:gdb-pretty-print-host-charset
Jul 24, 2026
Merged

gh-154580: Fix python-gdb.py pretty-printing non-ASCII strings in non-UTF-8 locales#154581
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:gdb-pretty-print-host-charset

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

The gdb pretty-printer used locale.getpreferredencoding() to decide whether to escape a character, but gdb writes its output in its host charset, which may differ (e.g. the embedded Python coerces the C locale to UTF-8 while the host charset is ASCII). Use gdb.host_charset() instead. test_strings had the same problem.

…in non-UTF-8 locales

The gdb pretty-printer used locale.getpreferredencoding() to decide whether to
escape a character, but gdb writes its output in its host charset.  Use
gdb.host_charset() instead.  test_strings had the same problem.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 24, 2026
@serhiy-storchaka
serhiy-storchaka merged commit 6cb93bd into python:main Jul 24, 2026
58 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@serhiy-storchaka
serhiy-storchaka deleted the gdb-pretty-print-host-charset branch July 24, 2026 16:11
@bedevere-app

bedevere-app Bot commented Jul 24, 2026

Copy link
Copy Markdown

GH-154635 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 24, 2026
@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 6cb93bd039ec1c5e0909d2d75cfc4fb3641c693b 3.13

@bedevere-app

bedevere-app Bot commented Jul 24, 2026

Copy link
Copy Markdown

GH-154636 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jul 24, 2026
@bedevere-app

bedevere-app Bot commented Jul 24, 2026

Copy link
Copy Markdown

GH-154637 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jul 24, 2026
serhiy-storchaka added a commit that referenced this pull request Jul 24, 2026
… in non-UTF-8 locales (GH-154581) (GH-154637)

The gdb pretty-printer used locale.getpreferredencoding() to decide whether to
escape a character, but gdb writes its output in its host charset.  Use
gdb.host_charset() instead.  test_strings had the same problem.
(cherry picked from commit 6cb93bd)

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
serhiy-storchaka added a commit that referenced this pull request Jul 24, 2026
… in non-UTF-8 locales (GH-154581) (GH-154636)

The gdb pretty-printer used locale.getpreferredencoding() to decide whether to
escape a character, but gdb writes its output in its host charset.  Use
gdb.host_charset() instead.  test_strings had the same problem.
(cherry picked from commit 6cb93bd)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
serhiy-storchaka added a commit that referenced this pull request Jul 24, 2026
… in non-UTF-8 locales (GH-154581) (GH-154635)

The gdb pretty-printer used locale.getpreferredencoding() to decide whether to
escape a character, but gdb writes its output in its host charset.  Use
gdb.host_charset() instead.  test_strings had the same problem.
(cherry picked from commit 6cb93bd)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant