summaryrefslogtreecommitdiff
path: root/Cython/Debugger
diff options
context:
space:
mode:
authorscoder <stefan_ml@behnel.de>2017-02-12 11:36:02 +0100
committerGitHub <noreply@github.com>2017-02-12 11:36:02 +0100
commit1c9e174dc926d5574b4db48589fcb75e0edebde9 (patch)
tree9079cf008a60ac92f8b9a687d06f76dafb2a1754 /Cython/Debugger
parent71ec1a4af0da84e6f181dcf248d9f7045486da73 (diff)
parent4b95ec8eebbc3e43c3f136614576bad5b259d1d4 (diff)
downloadcython-1c9e174dc926d5574b4db48589fcb75e0edebde9.tar.gz
Merge pull request #1580 from jiajunhuang/py2k3k
Fix Python 2 and 3 have diffrent default encoding
Diffstat (limited to 'Cython/Debugger')
-rw-r--r--Cython/Debugger/Cygdb.py28
-rw-r--r--Cython/Debugger/libcython.py14
2 files changed, 27 insertions, 15 deletions
diff --git a/Cython/Debugger/Cygdb.py b/Cython/Debugger/Cygdb.py
index d18364a0f..45f31ce6f 100644
--- a/Cython/Debugger/Cygdb.py
+++ b/Cython/Debugger/Cygdb.py
@@ -138,19 +138,21 @@ def main(path_to_debug_info=None, gdb_argv=None, no_import=False):
tempfilename = make_command_file(path_to_debug_info, no_import=no_import)
logger.info("Launching %s with command file: %s and gdb_argv: %s",
options.gdb, tempfilename, gdb_argv)
- logger.debug('Command file (%s) contains: """\n%s"""', tempfilename, open(tempfilename).read())
- logger.info("Spawning %s...", options.gdb)
- p = subprocess.Popen([options.gdb, '-command', tempfilename] + gdb_argv)
- logger.info("Spawned %s (pid %d)", options.gdb, p.pid)
- while True:
- try:
- logger.debug("Waiting for gdb (pid %d) to exit...", p.pid)
- ret = p.wait()
- logger.debug("Wait for gdb (pid %d) to exit is done. Returned: %r", p.pid, ret)
- except KeyboardInterrupt:
- pass
- else:
- break
+ with open(tempfilename) as tempfile:
+ logger.debug('Command file (%s) contains: """\n%s"""', tempfilename, tempfile.read())
+ logger.info("Spawning %s...", options.gdb)
+ p = subprocess.Popen([options.gdb, '-command', tempfilename] + gdb_argv)
+ logger.info("Spawned %s (pid %d)", options.gdb, p.pid)
+ while True:
+ try:
+ logger.debug("Waiting for gdb (pid %d) to exit...", p.pid)
+ ret = p.wait()
+ logger.debug("Wait for gdb (pid %d) to exit is done. Returned: %r", p.pid, ret)
+ except KeyboardInterrupt:
+ pass
+ else:
+ break
+ logger.debug("Closing temp command file with fd: %s", tempfile.fileno())
logger.debug("Removing temp command file: %s", tempfilename)
os.remove(tempfilename)
logger.debug("Removed temp command file: %s", tempfilename)
diff --git a/Cython/Debugger/libcython.py b/Cython/Debugger/libcython.py
index 13a582ffa..ff6d58e3a 100644
--- a/Cython/Debugger/libcython.py
+++ b/Cython/Debugger/libcython.py
@@ -18,6 +18,13 @@ import collections
import gdb
+try: # python 2
+ UNICODE = unicode
+ BYTES = str
+except NameError: # python 3
+ UNICODE = str
+ BYTES = bytes
+
try:
from lxml import etree
have_lxml = True
@@ -689,7 +696,8 @@ class CyImport(CythonCommand):
completer_class = gdb.COMPLETE_FILENAME
def invoke(self, args, from_tty):
- args = args.encode(_filesystemencoding)
+ if isinstance(args, BYTES):
+ args = args.decode(_filesystemencoding)
for arg in string_to_argv(args):
try:
f = open(arg)
@@ -834,7 +842,9 @@ class CyBreak(CythonCommand):
gdb.execute('break %s' % func.pf_cname)
def invoke(self, function_names, from_tty):
- argv = string_to_argv(function_names.encode('UTF-8'))
+ if isinstance(function_names, BYTES):
+ function_names = function_names.decode(_filesystemencoding)
+ argv = string_to_argv(function_names)
if function_names.startswith('-p'):
argv = argv[1:]
python_breakpoints = True