Pass files to open and breakpoints to Winpdb

27 views
Skip to first unread message

Mike Rans

unread,
Dec 21, 2010, 1:39:19 PM12/21/10
to Winpdb
I am running a module by way of a launcher script eg. python run.py
util.csvsave

The script of interest for debugging is not run.py but util
\csvsave.py.

1. Is there any way to pass to Winpdb on the command line or in a
config file, one or more files to open? If not, how can I request this
feature? Using this feature, for my example, I can get Winpdb to open
util\csvsave.py on launch

2. Can a list of files with breakpoints be passed to Winpdb on
the command line or in a config file? If not, how can I request this
feature? Using this feature, for my example, I can get Winpdb to put a
breakpoint at the start of util\csvsave.py on launch so I can
immediately press the continue button to go straight there

I have written a plugin for the editor Editra that launches Winpdb via
its command line, so I would then be able to write something to pass
files to open and initial breakpoints from the editor to Winpdb.

Mike Rans

unread,
Jan 5, 2011, 10:16:56 AM1/5/11
to Winpdb
Anybody there?

Mike Rans

unread,
Jan 20, 2011, 5:30:21 PM1/20/11
to Winpdb
Well, in spite of the lack of any feedback I've managed to do this
myself. I can pass a file of the form:
[C:\\working\\python\\helloworld.py]
5=True
6=False
[C:\\working\\python\\test4\\goodbyeworld.py]
2=True
5=False

Where the True or False indicate if the breakpoint is enabled or
disabled.

Code is as follows:

import os
import sys
import rpdb2
from winpdb import *
import ConfigParser

if 'wx' not in sys.modules and 'wxPython' not in sys.modules:
try:
import wxversion
wxversion.ensureMinimal(WXVER)
except ImportError:
rpdb2._print(STR_WXPYTHON_ERROR_MSG, sys.__stderr__)

try:
import Tkinter
import tkMessageBox

Tkinter.Tk().wm_withdraw()
tkMessageBox.showerror(STR_WXPYTHON_ERROR_TITLE,
STR_WXPYTHON_ERROR_MSG)

except:
pass

sys.exit(1)
import wx

assert wx.VERSION_STRING >= WXVER

winpdbbp_sm = None
winpdbbp_breakpoints = {}

def callback_setbreakpoints(event):
if not winpdbbp_sm or event.m_state != rpdb2.STATE_BROKEN:
return
wx.CallAfter(callafter_setbreakpoints, event)

def callafter_setbreakpoints(event):
winpdbbp_sm.load_breakpoints()
winpdbbp_sm.delete_breakpoint([], True)
for filepath in winpdbbp_breakpoints:
linenos = winpdbbp_breakpoints[filepath]
for lineno in linenos:
enabled = linenos[lineno]
winpdbbp_sm.set_breakpoint(filepath, '', lineno, enabled,
'')
print filepath, lineno, enabled
winpdbbp_sm.remove_callback(callback_setbreakpoints)

def StartWinPDBClient(command_line, fAttach, fchdir, pwd,
fAllowUnencrypted, fRemote, host):
global winpdbbp_sm
winpdbbp_sm = rpdb2.CSessionManager(pwd, fAllowUnencrypted,
fRemote, host)

try:
app = CWinpdbApp(winpdbbp_sm, fchdir, command_line, fAttach,
fAllowUnencrypted)
except SystemError:
if os.name == rpdb2.POSIX:
rpdb2._print(STR_X_ERROR_MSG, sys.__stderr__)
sys.exit(1)

raise

if not 'unicode' in wx.PlatformInfo:
dlg = wx.MessageDialog(None, STR_WXPYTHON_ANSI_WARNING_MSG,
STR_WXPYTHON_ANSI_WARNING_TITLE, wx.OK | wx.ICON_WARNING)
dlg.ShowModal()
dlg.Destroy()

event_type_dict = {rpdb2.CEventState: {}}
winpdbbp_sm.register_callback(callback_setbreakpoints,
event_type_dict, fSingleUse = False)
app.MainLoop()
winpdbbp_sm.shutdown()



def runwinpdb():
global winpdbbp_breakpoints
if rpdb2.get_version() != "RPDB_2_4_8":
rpdb2._print(STR_ERROR_INTERFACE_COMPATIBILITY %
("RPDB_2_4_8", rpdb2.get_version()))
return

configpath = os.path.abspath(sys.argv[1])
sys.argv = ["winpdb"] + sys.argv[2:]
print sys.argv
config = ConfigParser.ConfigParser()
config.read(configpath)
files_to_breakpoint = config.sections()
for file_to_breakpoint in files_to_breakpoint:
winpdbbp_breakpoints[file_to_breakpoint] = {}
for linenostr in config.options(file_to_breakpoint):
lineno = int(linenostr)
enabled = "True" == config.get(file_to_breakpoint,
linenostr)
winpdbbp_breakpoints[file_to_breakpoint][lineno] = enabled

return rpdb2.main(StartWinPDBClient, WINPDB_TITLE)


if __name__=='__main__':
ret = runwinpdb()

#
# Debuggee breaks (pauses) here
# before program termination.
#
# You can step to debug any exit handlers.
#
rpdb2.setbreak()
Reply all
Reply to author
Forward
0 new messages