Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add Debugging features #1537

Merged
merged 14 commits into from Apr 2, 2019

Conversation

galaunay
Copy link
Collaborator

@galaunay galaunay commented Feb 18, 2019

PR Summary

Add functions to ease debugging.

  • elpy-pdb-toggle-breakpoint-at-point: set (or unset) a breakpoint at the current line.
  • elpy-pdb-clear-breakpoints: clear all breakpoint in the buffer.
  • elpy-pdb-debug-buffer: start pdb on the current buffer
  • elpy-pdb-break-at-point: start pdb on the current buffer and jump to the current line
  • elpy-pdb-debug-last-exception: start post mortem pdb on the last exception

Todo:

  • Add functions
  • Add ability to set breakpoints at specific lines, with fringe indicator
  • Add keybindings
  • add menubar entries
  • Add documentation
  • Add tests

@gopar
Copy link
Collaborator

gopar commented Feb 19, 2019

Ohhhhhhh niiiiiice!!!!! Tried it out and it's awesome \o/
Had no idea pdb could do post mortem. Guess that's what happens when you don't read the docs :P

Oh and it LGTM

@gopar
Copy link
Collaborator

gopar commented Feb 19, 2019

What other funcs are you planning on adding?
I noticed that you have it labels as WIP so just curious :P

@galaunay
Copy link
Collaborator Author

Glad you like it :).

I was thinking about the possibility of setting breakpoints to specific lines (with a nice fringe indicator).
(I added that to the todo list).

It may worth looking at what other IDE do to get some additional ideas.

@coveralls
Copy link

coveralls commented Feb 21, 2019

Coverage Status

Coverage remained the same at 85.505% when pulling a8d016f on galaunay:Add-debug-features into d240487 on jorgenschaefer:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 85.574% when pulling 3d7adb0 on galaunay:Add-debug-features into 762eb3a on jorgenschaefer:master.

@galaunay galaunay force-pushed the Add-debug-features branch 3 times, most recently from aae4553 to 2717990 Compare February 24, 2019 15:52
@galaunay galaunay force-pushed the Add-debug-features branch 2 times, most recently from b9e535a to 237f6d7 Compare March 21, 2019 22:22
@galaunay galaunay merged commit ac422a9 into jorgenschaefer:master Apr 2, 2019
@galaunay galaunay deleted the Add-debug-features branch April 2, 2019 23:57
@galaunay
Copy link
Collaborator Author

galaunay commented Apr 2, 2019

Finally done.

@usnigg
Copy link

usnigg commented Apr 13, 2019

Thanks a lot for this feature! There is one problem I ran into and maybe someone with more experience could help with:
I use ipython 7.4.0 with python 3.7.3.
When I set a breakpoint at some line using C-c C-g b and then run the script it nicely enters the pdb shell and stops at that line. However when I either quit the debugger (q) or continue through the end (c), I can then no longer use the ipython buffer, i.e. if I type a valid python command e.g. '5' I get:

KeyError Traceback (most recent call last)
~/<omitted_path>/repro.py in
----> 1 5

~/.virtualenvs/memory/lib/python3.7/site-packages/IPython/core/displayhook.py in call(self, result)
256 self.write_output_prompt()
257 format_dict, md_dict = self.compute_format_data(result)
--> 258 self.update_user_ns(result)
259 self.fill_exec_result(result)
260 if format_dict:

~/.virtualenvs/memory/lib/python3.7/site-packages/IPython/core/displayhook.py in update_user_ns(self, result)
194
195 # Avoid recursive reference when displaying _oh/Out
--> 196 if result is not self.shell.user_ns['_oh']:
197 if len(self.shell.user_ns['_oh']) >= self.cache_size and self.do_full_cache:
198 self.cull_cache()

KeyError: '_oh'

I have looked a little bit online for more information and it seems this may have something to do with: ipython/ipython#136 although perhaps not exactly the same issue.

I think it's a ipython specific problem since it works normally when I use the python interpreter shell instead.

I think it should be possible to fix this because if I set the breakpoint instead "manually" with 'import pdb; pdb.set_trace()' then everything works fine, i.e. after exiting the pdb shell the ipython shell is still useable.

Here is a minimal script to try and reproduce the problem:

def f(x):
    y = x + 1

if __name__ == '__main__':
    f(4)

And here is the workflow that yields the error:

  1. start an ipython shell from elpy with C-c C-z
  2. set a breakpoint at the line 'y=x+1' inside of f(x) --> a nice read circle appears in the sidebar
  3. Execute C-c C-g g --> the ipython buffer is 'replaced' by a pdb shell stopped at the line with the breakpoint
  4. (optional) use pdb commands such as 'n' etc.
  5. quit the debugger with 'q'
  6. type any valid command at the ipython prompt --> the error copied above is raised

Any suggestions for how to fix this appreciated. Thanks!

@galaunay
Copy link
Collaborator Author

Hi,

I could not reproduce this with IPython on mine.

Could you create a new issue with your Elpy configuration and OS so I can investigate a bit further ?

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.

None yet

4 participants