ipdb icon indicating copy to clipboard operation
ipdb copied to clipboard

History across different ipdb sessions?

Open phani-vadrevu opened this issue 11 years ago • 11 comments

Is it possible to save history across different ipdb sessions? I would like pull up commands from my previous ipdb debug session that was invoked using ipdb.set_trace().

phani-vadrevu avatar Nov 07 '14 23:11 phani-vadrevu

I have never tried myself. Anyone else ?

gotcha avatar Dec 15 '14 10:12 gotcha

Why is this issue closed? History across different sessions is still unavailable.

michelesr avatar Jul 08 '16 12:07 michelesr

PR welcome :-)

gotcha avatar Jul 12 '16 10:07 gotcha

https://github.com/ipython/ipython/issues/682

michelesr avatar Jul 12 '16 21:07 michelesr

Maybe the history support should be implemented in IPython or pdb.

michelesr avatar Jul 12 '16 21:07 michelesr

However, seems that using ipdb with IPython 5.0.0 doesn't show the history at all, while using it with previous versions will show the IPython history.

michelesr avatar Jul 12 '16 21:07 michelesr

The history for the current session is stored in p.shell.debugger_history.strings, where p is the debugger instance (that is created with _init_pdb()).

However... even if the history can be easily loaded inside _init_pdb(), I didn't find a way to store it in a file because it has to be done after ipdb console exit.

Is there a way to execute a function after ipdb console exit, without changing the user experience?

If for example ipdb.set_trace() is used, the executions breaks in the line that calls it, but there's no way to do something after the end of the debugging session because the scope returns on the main program and not on ipdb code.

michelesr avatar Jul 13 '16 00:07 michelesr

@gotcha: sorry for all this mess... I added the Fix tag on the commit message while experimenting and it generated an event for every commit amend.

However, I sent you a PR that enables history for IPython 5.0.0.

The history works by creating a file in the IPython profile directory (usually ~/.ipython/profile-default/) or in user home if the profile isn't available.

When a line is entered, it's appended in the history file (if valid and not already present as last entry in the file). Then, on IPython debugger initialization the file is loaded back in the shell history.

This works only in 5.0.0, that use a dedicated history for the debugger. However, ipdb behavior with previous version of IPython is not changed in this patch.

michelesr avatar Jul 13 '16 16:07 michelesr

Is this still being worked on..

Something lik this can possibly be incorporated.. https://wiki.python.org/moin/PdbRcIdea

alphaCTzo7G avatar Jun 03 '18 14:06 alphaCTzo7G

Isn't this a solution? https://github.com/michelesr/ipdb/commit/2c808b5343deb3482f6cd025ab11d4bf355a6929

darthdeus avatar Jan 22 '19 22:01 darthdeus

So far I received no feedback from @gotcha in #104, and that was opened in 2016 so the code must have changed in the meantime.

I'll be happy to resolve the conflicts if I can get that PR merged.

michelesr avatar Jan 28 '19 22:01 michelesr

Support for history is provided by recent IPython : see https://github.com/gotcha/ipdb/issues/236

gotcha avatar Dec 13 '22 15:12 gotcha