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.

classification
Title: IOError when launching script under pdb with backslash in script path
Type: behavior Stage: patch review
Components: Windows Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brian.curtin, jaraco, nukvar, python-dev
Priority: normal Keywords: patch

Created on 2010-01-21 22:18 by jaraco, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fix with test.patch jaraco, 2010-01-22 14:34 review
fix with test (releas26-maint).patch jaraco, 2010-01-22 14:46 review
Messages (12)
msg98116 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2010-01-21 22:18
Under Python 2.6.4 64-bit on Windows 7 64-bit, I found that when launching a script under the debugger, if backslashes were in the script pathname, they were not interpreted correctly by the interpreter.

For example, create a simple test script, "t-helloworld.py" with the canonical "hello-world" content. The script name must start with a backslash escape character such as 't' or 'n'. Then, from the command prompt:

> python -m pdb .\t-helloworld.py
IOError: (2, 'No such file or directory', '.\t-helloworld.py')
> <string>(1)<module>()
(Pdb)

However, using forward slashes works just fine.

> python -m pdb ./t-helloworld.py
> c:\debug\t-helloworld.py(1)<module>()
-> print "hello world"
(Pdb)

Note that launching the script from the python directly does not exhibit the error - it seems to be only when pdb is used.

Expected behavior: pdb should interpret the command-line parameters the same way Python does.
msg98121 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-01-22 00:06
You can see the same thing by doing execfile(".\test.py"), which is what pdb makes under the hood, then bdb exec's it.
msg98123 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2010-01-22 02:00
I'm changing the title back to the original title. I don't believe the problem is reproducible using execfile. That is, if a properly-escaped path is passed to execfile, it works fine.

So I believe the problem lies between when pdb takes control and where execfile is called - the command-line is not properly parsed.
msg98124 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2010-01-22 02:08
I suspect this patch may fix the problem. I haven't yet had time to test it.

Index: Lib/pdb.py
===================================================================
--- Lib/pdb.py  (revision 77683)
+++ Lib/pdb.py  (working copy)
@@ -1200,7 +1200,7 @@
         self._wait_for_mainpyfile = 1
         self.mainpyfile = self.canonic(filename)
         self._user_requested_quit = 0
-        statement = 'execfile( "%s")' % filename
+        statement = 'execfile(%r)' % filename
         self.run(statement)

 # Simplified interface
msg98125 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-01-22 02:15
Works for me, repr will escape the slash.
msg98128 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2010-01-22 02:32
The attached test-case identifies the failure mode (and verifies that the proposed fix corrects the issue).
msg98131 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-01-22 02:59
Can you add your test to Lib/test/test_pdb.py?

If the test fails the "hello world" script won't be removed, it won't make it to os.remove(). You'll need to make sure the file gets deleted in any case. Could use a temporary file.

Can you condense the cmd stuff into less lines? Super minor thing, but it's all short lines anyways.

Rather than testing using failIf, assertFalse is a better alternative. In 2.7 there is assertIn which would be ideal for this test, but this will go into 2.6 as well.
msg98144 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2010-01-22 14:34
Here's a new patch against the trunk that addresses Brian's concerns.
msg98145 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2010-01-22 14:46
For completeness, I've back-ported the patch to the release26-maint branch.
msg147828 - (view) Author: Nu Kvar (nukvar) Date: 2011-11-17 22:29
this bug exist also in python 2.5 (of course)

and the same patch as above fixes it (of course).
msg147829 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-11-17 23:53
New changeset f7dd5178f36a by Jason R. Coombs in branch '2.7':
PDB now will properly escape backslashes in the names of modules it executes. Fixes #7750
http://hg.python.org/cpython/rev/f7dd5178f36a
msg147830 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2011-11-17 23:59
This bug doesn't appear to be present in 3.1, so the 2.7 patch is all that applies at this time.
History
Date User Action Args
2022-04-11 14:56:56adminsetgithub: 51998
2011-11-17 23:59:22jaracosetstatus: open -> closed
resolution: fixed
messages: + msg147830

versions: - Python 2.6
2011-11-17 23:53:21python-devsetnosy: + python-dev
messages: + msg147829
2011-11-17 22:29:04nukvarsetnosy: + nukvar
messages: + msg147828
2010-01-22 14:46:36jaracosetfiles: - test_pdb.py
2010-01-22 14:46:31jaracosetfiles: + fix with test (releas26-maint).patch

messages: + msg98145
2010-01-22 14:34:53jaracosetfiles: + fix with test.patch
keywords: + patch
messages: + msg98144

versions: + Python 2.7
2010-01-22 02:59:51brian.curtinsetmessages: + msg98131
stage: test needed -> patch review
2010-01-22 02:32:21jaracosetfiles: + test_pdb.py

messages: + msg98128
2010-01-22 02:15:21brian.curtinsetmessages: + msg98125
2010-01-22 02:08:31jaracosetmessages: + msg98124
2010-01-22 02:00:30jaracosetmessages: + msg98123
title: IOError in execfile with backslash in path -> IOError when launching script under pdb with backslash in script path
2010-01-22 01:46:05jaracosettitle: IOError when launching script under pdb with backslash in script path -> IOError in execfile with backslash in path
2010-01-22 00:06:49brian.curtinsetpriority: normal

nosy: + brian.curtin
messages: + msg98121

type: behavior
stage: test needed
2010-01-21 22:18:23jaracocreate