This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: pdb messes up when debugging an non-ascii program
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, isandler, smu
Priority: normal Keywords:

Created on 2009-08-17 16:50 by smu, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
pdb-nonascii.patch isandler, 2009-09-07 20:10
Messages (3)
msg91667 - (view) Author: samuel de framond (smu) Date: 2009-08-17 16:50
consider a program like this one:

---- File: ./ ----
#/usr/bin/env python
#coding: utf8

print 'qwerty'

Here is a shell (e.g. bash) session:

$ python -m pdb ./
> /usr/lib/python2.6/encodings/>'latin1'
-> return '_'.join(encoding.translate(_norm_encoding_map).split())

While for a file without the line #2, the output would be:

$ python -m pdb ./
> /home/.../<module>()
-> print 'qwerty'

Here is the thing: the normal behaviour of pdb in this case is to pause
before executing the first line of the program. Instead of this, it
pauses at line #69 in .../encodings/, which makes pdb almost
Plus, pdb's inline command "q" (or "quit") does not work anymore. Here,
the first line should close the program but it does not:

(Pdb) q
Traceback (most recent call last):
  File "/usr/lib/python2.6/", line 1283, in main
  File "/usr/lib/python2.6/", line 1202, in _runscript
  File "/usr/lib/python2.6/", line 368, in run
    exec cmd in globals, locals
  File "<string>", line 1, in <module>
  File "./", line 2
 SyntaxError: encoding problem: with BOM (, line 2)
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> <string>(1)<module>()

if 'q' is types a second time in a row, it goes like this and we are
back to starting point:

(Pdb) q
Post mortem debugger finished. The ./ will be restarted
> /usr/lib/python2.6/encodings/>'latin1'
-> return '_'.join(encoding.translate(_norm_encoding_map).split())
msg92389 - (view) Author: Ilya Sandler (isandler) Date: 2009-09-07 20:10
Here is what's happening: when pdb starts up it sets tracing and several
trace events happen before the pdb reaches the first line of the
debugged program. So, pdb has some logic to ignore certain events on
startup (_wait_for_main_pyfile).

On normal startup only "call" and "line"events need to be ignored and so
that's what pdb did. However, the "coding" directive causes some
additional code to get executed and results in "return" and "exception"

I am attaching the patch to properly ignore irrelevant "return" and
"exception"events on startup. The patch fixes both the startup and the
exit problems.
msg112057 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-07-30 09:43
Thanks, applied in r83269.
Date User Action Args
2022-04-11 14:56:52adminsetgithub: 50968
2010-07-30 09:43:09georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg112057

resolution: fixed
2009-09-07 20:10:28isandlersetfiles: + pdb-nonascii.patch
nosy: + isandler
messages: + msg92389

2009-08-17 16:50:09smucreate