gotcha / ipdb

Integration of IPython pdb
BSD 3-Clause "New" or "Revised" License
1.85k stars 146 forks source link

"list" syntax does not support "." as argument. #203

Closed yum-feng closed 1 year ago

yum-feng commented 4 years ago

The command l will print the source code based on where it last left off, which is as expected. In the normal pdb debugger, I would specify . as argument, l . to get back to the current line of execution.

This does not seem to work in IPDB, or am I doing something wrong ?

I'm running Python 3.6.8 with the following versions.

ipdb==0.13.3 ipython==7.14.0 ipython-genutils==0.2.0

willhansen commented 4 years ago

I've also run into this. It feels like a bug, because the only other way to reset list I've found is to use w to see the current line number, then use that as an argument for list

gotcha commented 4 years ago

I guess this is an issue with IPython. Can you check that you have the issue without ipdb ?

wztdream commented 3 years ago

same issue here, and confirm pdb support l . This is definitely a bug, consider l is high frequent use command, it is strange the bug still here today

mzr1996 commented 3 years ago

Same issue.

isidroas commented 1 year ago

Same issue, with ipdb it raises an error, 2022-11-27-105741_

but with pdb, it isn't, 2022-11-27-105040_

IPython version: 8.4.0 Python version: 3.10.6 ipdb version: 0.13.9

jessie-hu-95 commented 1 year ago

I found a workaround to support this. This definitely is an issue of IPython, and we can figure this out in their source code. By comparing do_list() in IPython and the function with same name in PDB, we can find the difference that in IPython code, they did not treat '.' as a valid argument. To enable the '.' argument, one can apply the following patch:

diff --git a/IPython/core/debugger.py b/IPython/core/debugger.py
index c8082e34e..5b793d783 100644
--- a/IPython/core/debugger.py
+++ b/IPython/core/debugger.py
@@ -640,7 +640,7 @@ def do_list(self, arg):
         """
         self.lastcmd = 'list'
         last = None
-        if arg:
+        if arg and arg != '.':
             try:
                 x = eval(arg, {}, {})
                 if type(x) == type(()):
@@ -655,7 +655,7 @@ def do_list(self, arg):
             except:
                 print('*** Error in argument:', repr(arg), file=self.stdout)
                 return
-        elif self.lineno is None:
+        elif self.lineno is None or arg == '.':
             first = max(1, self.curframe.f_lineno - 5)
         else:
             first = self.lineno + 1
gotcha commented 1 year ago

@jessie-hu-95 Did you submit this as a pull request in the IPython repository ?

jessie-hu-95 commented 1 year ago

I just created one. But I do not know if my PR is submitted correctly, since this is my first PR. 🤔

gotcha commented 1 year ago

Should be released in IPython 8.15