def _onitemrightclick(self, item):
     varname = self.GetItemText(item, VariablesList.COL_NAME)
     RpdbDebugger().setexpression(varname, True)
     RpdbDebugger().restoreexpressions()
     ed_msg.PostMessage(
         ed_msg.EDMSG_UI_SB_TXT,
         (ed_glob.SB_INFO, _("Added %s to PyExpression shelf.") % varname))
 def OnClear(self, event):
     """Clear all breakpoints"""
     for fname, points in dict(RpdbDebugger().breakpoints).iteritems():
         for line in points.keys():
             BreakpointController.DeleteBreakpoint(fname, int(line))
     RpdbDebugger().breakpoints = {}
     self.SaveAndRestoreBreakpoints()
 def Unsubscription(self):
     """Cleanup items on destroy"""
     editor = wx.GetApp().GetCurrentBuffer()
     RpdbDebugger().saveandrestorebreakpoints = lambda:None
     RpdbDebugger().install_breakpoints()
     if BreakpointController.BreakpointWindow is self:
         BreakpointController.BreakpointWindow = None
 def RestoreBreakPoints(self):
     """Restore breakpoints"""
     self._listCtrl.Clear()
     self._listCtrl.PopulateRows(RpdbDebugger().breakpoints)
     self._listCtrl.RefreshRows()
     editor = wx.GetApp().GetCurrentBuffer()
     if editor:
         RpdbDebugger().restorestepmarker(editor)
 def Evaluate(self, enabled, expression, idx):
     if not enabled or not expression or not RpdbDebugger().broken:
         return
     worker = RunProcInThread("Expr", self.fillexpressionvalue, \
                              RpdbDebugger().evaluate, expression)
     worker.pass_parameter(idx)
     worker.start()
     worker2 = RunProcInThread("Expr", self.fillexpressiontype, \
                              RpdbDebugger().evaluate, "type(%s).__name__" % expression)
     worker2.pass_parameter(idx)
     worker2.start()
Beispiel #6
0
    def _unhandledexception(self):
        dlg = wx.MessageDialog(self.mainwindow,
                               _("An unhandled exception was caught. Would you like to analyze it?"),
                               _("Warning"),
                               wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION)
        res = dlg.ShowModal()
        dlg.Destroy()

        if res != wx.ID_YES:
            RpdbDebugger().unhandledexception = False
            RpdbDebugger().do_go()
        else:
            RpdbDebugger().set_analyze(True)
Beispiel #7
0
 def UpdateForEditor(self, editor, force=False):
     """Update the context based on the current editor."""
     self._updateeditor = None
     if not editor:
         return
     langid = getattr(editor, 'GetLangId', lambda: -1)()
     ispython = langid == synglob.ID_LANG_PYTHON
     filename = os.path.normcase(editor.GetFileName())
     self.debugeditorupdate(ispython, filename, force)
     self._prevfile = filename
     RpdbDebugger().saveandrestoreexpressions()
     RpdbDebugger().saveandrestorebreakpoints()
     self.RestoreStepMarker(editor)
    def __init__(self, parent):
        """Initialize the window"""
        super(StackThreadShelfWindow, self).__init__(parent)

        # Attributes
        self.prevstack = None
        self.current_thread = None
        self.threads_list = None
        bstyle = eclib.SEGBOOK_STYLE_NO_DIVIDERS|eclib.SEGBOOK_STYLE_LEFT
        self._nb = eclib.SegmentBook(self, style=bstyle)
        self._stackframe = StackFrameList(self._nb)
        self._threads = ThreadsList(self._nb)

        # Setup
        self._InitImageList()
        self._nb.AddPage(self._stackframe, _("Stack Frame"), img_id=0)
        self._nb.AddPage(self._threads, _("Threads"), img_id=1)
        ctrlbar = self.setup(self._nb, self._stackframe,
                             self._threads)
        ctrlbar.AddStretchSpacer()
        self.layout()

        # Debugger Attributes
        RpdbDebugger().clearframe = self.ClearStackList
        RpdbDebugger().selectframe = self._stackframe.select_frame
        RpdbDebugger().updatestacklist = self.UpdateStackList
        RpdbDebugger().clearthread = self.ClearThreadList
        RpdbDebugger().updatethread = self._threads.update_thread
        RpdbDebugger().updatethreadlist = self.UpdateThreadList

        RpdbDebugger().update_stack()
        current_thread, threads_list = RpdbDebugger().get_thread_list()
        self.UpdateThreadList(current_thread, threads_list)
Beispiel #9
0
    def __init__(self, parent):
        """Initialize the window"""
        super(ExpressionsShelfWindow, self).__init__(parent)

        # setup
        ctrlbar = self.setup(ExpressionsList(self))
        self.addbtn = self.AddPlateButton(u"", ed_glob.ID_ADD, wx.ALIGN_LEFT)
        self.addbtn.ToolTip = wx.ToolTip(_("Set Expression"))
        self.delbtn = self.AddPlateButton(u"", ed_glob.ID_REMOVE,
                                          wx.ALIGN_LEFT)
        self.delbtn.ToolTip = wx.ToolTip(_("Delete Expression"))
        self.delallbtn = self.AddPlateButton(u"", ed_glob.ID_DELETE,
                                             wx.ALIGN_LEFT)
        self.delallbtn.ToolTip = wx.ToolTip(_("Delete All Expressions"))
        self.refreshbtn = self.AddPlateButton(u"", ed_glob.ID_REFRESH,
                                              wx.ALIGN_LEFT)
        self.refreshbtn.ToolTip = wx.ToolTip(_("Refresh Expressions"))
        ctrlbar.AddStretchSpacer()
        self.layout("Execute", self.OnExecute)
        bmp = wx.ArtProvider.GetBitmap(str(ed_glob.ID_BIN_FILE), wx.ART_MENU)
        self.taskbtn.SetBitmap(bmp)
        self.taskbtn.ToolTip = wx.ToolTip(_("Execute"))

        # Attributes
        expressionslist = ToolConfig.GetConfigValue(ToolConfig.TLC_EXPRESSIONS)
        self.expressions = OrderedDict()
        if isinstance(expressionslist, list):
            for tup in expressionslist:
                if isinstance(tup, tuple) and len(tup) == 2:
                    expression, enabled = tup
                    self.expressions[expression] = enabled

        self.ignoredwarnings = {}

        # Debugger Attributes
        RpdbDebugger().setexpression = self.SetExpression
        RpdbDebugger().restoreexpressions = self.RestoreExpressions
        RpdbDebugger(
        ).saveandrestoreexpressions = self.SaveAndRestoreExpressions
        RpdbDebugger(
        ).clearexpressionvalues = self._listCtrl.clearexpressionvalues

        self._listCtrl.PopulateRows(self.expressions)

        # Event Handlers
        self.Bind(wx.EVT_BUTTON, self.OnButton, self.addbtn)
        self.Bind(wx.EVT_BUTTON, self.OnButton, self.delbtn)
        self.Bind(wx.EVT_BUTTON, self.OnClear, self.delallbtn)
        self.Bind(wx.EVT_BUTTON, self.OnRefresh, self.refreshbtn)
    def _onitemactivated(self, item, expr, is_valid):
        default_value = self.GetItemText(item, VariablesList.COL_VALUE)[1:]

        if is_valid:
            desc = "The new expression will be evaluated at the debuggee and its value will be set to the item."
            labeltext = "New Expression:"
            style = wx.TE_MULTILINE
        else:
            desc = "The current value of the expression (read only)."
            labeltext = "Current Expression:"
            style = wx.TE_MULTILINE | wx.TE_READONLY

        expr_dialog = ExpressionDialog(self, default_value, "Enter Expression",
                                       desc, labeltext, (1000, -1), style)
        pos = self.GetPositionTuple()
        expr_dialog.SetPosition((pos[0] + 50, pos[1] + 50))
        r = expr_dialog.ShowModal()
        if r != wx.ID_OK:
            expr_dialog.Destroy()
            return

        _expr = expr_dialog.get_expression()

        expr_dialog.Destroy()

        _suite = "%s = %s" % (expr, _expr)

        worker = RunProcInThread(self.listtype, self._onitemactivatedcallback,
                                 RpdbDebugger().execute, _suite)
        worker.start()
    def _onserverlist(self, res):
        """Callback from do_refresh thread"""
        assert wx.Thread_IsMain(), "Must Update UI from Main Thread!!"

        if not res:
            return
        (self.m_server_list, self.m_errors) = res

        if len(self.m_errors) > 0:
            for k, el in self.m_errors.items():
                if k in [rpdb2.AuthenticationBadData, rpdb2.AuthenticationFailure]:
                    self.report_attach_warning(rpdb2.STR_ACCESS_DENIED)

                elif k == rpdb2.EncryptionNotSupported:
                    self.report_attach_warning(rpdb2.STR_DEBUGGEE_NO_ENCRYPTION)

                elif k == rpdb2.EncryptionExpected:
                    self.report_attach_warning(rpdb2.STR_ENCRYPTION_EXPECTED)

                elif k == rpdb2.BadVersion:
                    for (t, v, tb) in el:
                        self.report_attach_warning(rpdb2.STR_BAD_VERSION % {'value': v})

        host = RpdbDebugger().get_host()
        self.m_entry_host.SetValue(host)

        self.m_listbox_scripts.DeleteAllItems()

        # TODO: change this to not use sys.maxint, this is a bad example from
        #       wxPython demo.
        for i, s in enumerate(self.m_server_list):
            index = self.m_listbox_scripts.InsertStringItem(sys.maxint, repr(s.m_pid))
            self.m_listbox_scripts.SetStringItem(index, 1, s.m_filename)
            self.m_listbox_scripts.SetItemData(index, i)
 def OnThreadSelected(self, evt):
     index = evt.GetIndex()
     if self.previndex == index:
         return
     self.previndex = index
     tid = int(self.GetItem(index, ThreadsList.COL_ID).GetText())
     RpdbDebugger().set_thread(tid)
Beispiel #13
0
 def InstallComponents(self, parent):
     """Initialize and install"""
     setattr(self, '_installed', True)
     # Initialize singletons
     RpdbDebugger()
     MessageHandler()
     BreakpointController()
 def do_refresh(self, event=None):
     host = self.m_entry_host.Value
     if not host:
         host = 'localhost'
     self.Parent._lasthost = host
     worker = RunProcInThread("DbgAttach", self._onserverlist,
                              RpdbDebugger().get_server_list, host)
     worker.start()
Beispiel #15
0
    def DoProcessExit(self, code=0):
        """Override this method to do any post processing after the running
        task has exited. Typically this is a good place to call
        L{OutputBuffer.Stop} to stop the buffers timer.
        @keyword code: Exit code of program
        @return: None

        """
        self.AppendUpdate(self.DEBUGGEEFINISHEDTEXT)
        self.restoreautorun()
        self.Stop()
        RpdbDebugger().debugbuttonsupdate()
        RpdbDebugger().clearlocalvariables()
        RpdbDebugger().clearglobalvariables()
        RpdbDebugger().clearexceptions()

        
Beispiel #16
0
    def __init__(self):
        """Initialize"""
        super(MessageHandler, self).__init__()

        # Attributes
        self._prevfile = u""
        self._evthandler = wx.EvtHandler()
        self._jobtimer = wx.Timer(self._evthandler)
        self._updateeditor = None
        self.editor = None
        self.editorlineno = None
        self.contextlineno = None
        self.contextmenus = {1:(True, ID_ON_RUNTOLINE, _("Run To Line"), self.OnRunToLine), 
                             2:(True, ID_ON_JUMP, _("Jump"), self.OnJump)}
        self.debugeditorupdate = lambda x,y,z:None
        
        # Setup debugger hooks
        rpdbdebugger = RpdbDebugger() # singleton don't keep ref
        rpdbdebugger.conflictingmodules = self.ConflictingModules
        rpdbdebugger.clearstepmarker = self.ClearStepMarker
        rpdbdebugger.setstepmarker = self.SetStepMarker
        rpdbdebugger.restorestepmarker = self.RestoreStepMarker
        rpdbdebugger.catchunhandledexception = self.CatchUnhandledException
        
        # Editra Message Handlers
        ed_msg.Subscribe(self.OnFileLoad, ed_msg.EDMSG_FILE_OPENED)
        ed_msg.Subscribe(self.OnFileSave, ed_msg.EDMSG_FILE_SAVED)
        ed_msg.Subscribe(self.OnPageChanged, ed_msg.EDMSG_UI_NB_CHANGED)        
        ed_msg.Subscribe(self.OnContextMenu, ed_msg.EDMSG_UI_STC_CONTEXT_MENU)
        self._evthandler.Bind(wx.EVT_TIMER,
                              lambda evt: self.UpdateForEditor(self._updateeditor))
 def ToggleBreakpoint(self, editor, event):
     """Toggle a breakpoint"""
     filepath = os.path.normcase(editor.GetFileName())
     if not BreakpointController.DeleteBreakpoint(filepath, MessageHandler().ContextLine):
         BreakpointController.SetBreakpoint(filepath, MessageHandler().ContextLine, "", True)
     if self.BreakpointWindow:
         self.BreakpointWindow.RestoreBreakPoints()
     else:
         RpdbDebugger().restorestepmarker(editor)
    def DeleteBreakpoint(filepath, lineno):
        """Remove a breakpoint from the list"""
        if not os.path.isfile(filepath) or \
           not filepath in RpdbDebugger().breakpoints:
            return None
        linenos = RpdbDebugger().breakpoints[filepath]
        if not lineno in linenos:
            return None

        # Delete the breakpoint
        enabled, exprstr = linenos[lineno]
        del linenos[lineno]
        if len(linenos) == 0:
            del RpdbDebugger().breakpoints[filepath]
        RpdbDebugger().delete_breakpoint(filepath, lineno)
        BreakpointController.SaveBreakpoints()
        BreakpointController.SetEditorBreakpoint(filepath, lineno, False, True)
        return lineno
Beispiel #19
0
 def Unsubscription(self):
     """Cleanup on Destroy"""
     RpdbDebugger().clearlocalvariables = lambda: None
     RpdbDebugger().updatelocalvariables = lambda x, y: (None, None)
     RpdbDebugger().clearglobalvariables = lambda: None
     RpdbDebugger().updateglobalvariables = lambda x, y: (None, None)
     RpdbDebugger().clearexceptions = lambda: None
     RpdbDebugger().updateexceptions = lambda x, y: (None, None)
     RpdbDebugger().updateanalyze = lambda: None
    def OnTrapExceptionsCheckBox(self, evt):
        config = Profile_Get(PYTOOL_CONFIG, default=dict())
        if evt.GetEventObject() is self._trapcb:
            trap = self._trapcb.GetValue()
            config[TLC_TRAP_EXCEPTIONS] = trap
            RpdbDebugger().set_trap_unhandled_exceptions(trap)
        else:
            evt.Skip()
            return

        Profile_Set(PYTOOL_CONFIG, config)
Beispiel #21
0
    def CatchUnhandledException(self):
        if not ToolConfig.GetConfigValue(ToolConfig.TLC_IGNORE_SYSEXIT, True):
            wx.CallAfter(self._unhandledexception)
            return
            
        expressionlist = [(RPDBEXCEPTIONSSTR, True)]

        worker = RunProcInThread(RPDBEXCEPTIONSSTR, self._issysexit,
                                 RpdbDebugger().catchexc_get_namespace,
                                 expressionlist, 0)
        worker.start()
    def OnSynchronicityCheckBox(self, evt):
        evt_obj = evt.GetEventObject()
        config = Profile_Get(PYTOOL_CONFIG, default=dict())
        if evt_obj is self._synccb:
            synchronicity = self._synccb.GetValue()
            config[TLC_SYNCHRONICITY] = synchronicity
            RpdbDebugger().set_synchronicity(synchronicity)
        else:
            evt.Skip()
            return

        Profile_Set(PYTOOL_CONFIG, config)
    def SetBreakpoint(filepath, lineno, exprstr, enabled):
        """Set a breakpoint in the given file
        @param filepath: normalized file path
        @param lineno: buffer display line number

        """
        if not os.path.isfile(filepath):
            return
        if filepath in RpdbDebugger().breakpoints:
            linenos = RpdbDebugger().breakpoints[filepath]
        else:
            linenos = {}
            RpdbDebugger().breakpoints[filepath] = linenos
        linenos[lineno] = (enabled, exprstr)
        util.Log("[DbgBp][info] SetBreakpoint %s, %d, %s, %s" % \
                 (filepath, lineno, enabled, exprstr))
        if enabled:
            RpdbDebugger().set_breakpoint(filepath, lineno, exprstr)
        BreakpointController.SaveBreakpoints()
        BreakpointController.SetEditorBreakpoint(filepath, lineno, enabled, False)
        return lineno
Beispiel #24
0
    def _issysexit(self, variables):
        if not variables:
            wx.CallAfter(self._unhandledexception)
            return
        variables_with_expr = []
        for expression in variables:
            if hasattr(expression, "get"):
                variables_with_expr.append(expression)
        if variables_with_expr == []:
            wx.CallAfter(self._unhandledexception)
            return

        first_variable_with_expr = variables_with_expr[0]
        if first_variable_with_expr is None:
            wx.CallAfter(self._unhandledexception)
            return

        if "error" in first_variable_with_expr:
            wx.CallAfter(self._unhandledexception)
            return

        if first_variable_with_expr["n_subnodes"] == 0:
            wx.CallAfter(self._unhandledexception)
            return

        #
        # Create a list of the subitems.
        # The list is indexed by name or directory key.
        # In case of a list, no sorting is needed.
        #
        for subnode in first_variable_with_expr["subnodes"]:
            _name = unicode(subnode["name"])
            _type = unicode(subnode["type"])
            _value = PyStudioUtils.get_unicodevalue(subnode["repr"])
            if _name == u"type" and _value.find(u"SystemExit") != -1:
                RpdbDebugger().unhandledexception = False
                RpdbDebugger().do_go()
                return

        wx.CallAfter(self._unhandledexception)
    def __init__(self, parent):
        """Initialize the window"""
        super(BreakPointsShelfWindow, self).__init__(parent)

        ctrlbar = self.setup(BreakPointsList(self))
        ctrlbar.AddControl(wx.StaticLine(ctrlbar, size=(1, 16), style=wx.LI_VERTICAL),
                           0, wx.ALIGN_LEFT)
        self.addbtn = self.AddPlateButton(u"", ed_glob.ID_ADD, wx.ALIGN_LEFT)
        self.addbtn.ToolTip = wx.ToolTip(_("Set Breakpoint"))
        self.delbtn = self.AddPlateButton(u"", ed_glob.ID_REMOVE, wx.ALIGN_LEFT)
        self.delbtn.ToolTip = wx.ToolTip(_("Delete Breakpoint"))
        self.delallbtn = self.AddPlateButton(u"", ed_glob.ID_DELETE, wx.ALIGN_LEFT)
        self.delallbtn.ToolTip = wx.ToolTip(_("Delete All Breakpoints"))
        self.layout(None, None)

        # Attributes
        bpoints = ToolConfig.GetConfigValue(ToolConfig.TLC_BREAKPOINTS)
        if isinstance(bpoints, dict):
            RpdbDebugger().breakpoints = bpoints
        else:
            RpdbDebugger().breakpoints = dict()        
        RpdbDebugger().saveandrestorebreakpoints = self.SaveAndRestoreBreakpoints
        
        self._listCtrl.PopulateRows(RpdbDebugger().breakpoints)
        editor = wx.GetApp().GetCurrentBuffer()
        if editor:
            RpdbDebugger().restorestepmarker(editor)
        RpdbDebugger().install_breakpoints()
        BreakpointController().BreakpointWindow = self

        # Event Handlers
        self.Bind(wx.EVT_BUTTON, self.OnButton, self.addbtn)
        self.Bind(wx.EVT_BUTTON, self.OnButton, self.delbtn)
        self.Bind(wx.EVT_BUTTON, self.OnClear, self.delallbtn)
Beispiel #26
0
 def OnExecute(self, event):
     """Execute an expression"""
     desc = _("This code will be executed at the debuggee:")
     expr_dialog = ExpressionDialog(self, u"", _("Enter Code to Execute"),
                                    desc, None, (200, 200))
     pos = self.GetPositionTuple()
     expr_dialog.SetPosition((pos[0] + 50, pos[1] + 50))
     if expr_dialog.ShowModal() == wx.ID_OK:
         _expr = expr_dialog.get_expression()
         worker = RunProcInThread("DbgExec", self._oncodeexecuted,
                                  RpdbDebugger().execute, _expr)
         worker.start()
     expr_dialog.Destroy()
Beispiel #27
0
    def OnContextMenu(self, msg):
        """Customize the editor buffers context menu"""
        if not len(self.contextmenus):
            return
        ctxmgr = msg.GetData()
        editor = ctxmgr.GetUserData('buffer')
        if not editor:
            return
        langid = editor.GetLangId()
        if langid != synglob.ID_LANG_PYTHON:
            return

        # Add our custom options to the menu
        menu = ctxmgr.GetMenu()
        self.contextlineno = editor.LineFromPosition(ctxmgr.GetPosition()) + 1
        menu.AppendSeparator()
        for pos in sorted(self.contextmenus.keys()):
            reqattach, wxid, menutitle, menufncallback = self.contextmenus[pos]
            if reqattach and not RpdbDebugger().attached and not RpdbDebugger().broken:
                continue
            menu.Append(wxid, menutitle)
            ctxmgr.AddHandler(wxid, menufncallback)
 def Unsubscription(self):
     """Cleanup on Destroy"""
     RpdbDebugger().clearframe = lambda:None
     RpdbDebugger().selectframe = lambda x:None
     RpdbDebugger().updatestacklist = lambda x:None
     RpdbDebugger().clearthread = lambda:None
     RpdbDebugger().updatethread = lambda x,y,z:None
     RpdbDebugger().updatethreadlist = lambda x,y:None
    def OnEscapingCheckBox(self, evt):
        evt_obj = evt.GetEventObject()
        config = Profile_Get(PYTOOL_CONFIG, default=dict())
        if evt_obj is self._esccb:
            encoding = self._encch.GetStringSelection()
            config[TLC_EXECEVALENCODING] = encoding
            escaping = self._esccb.GetValue()
            config[TLC_EXECEVALESCAPING] = escaping
            RpdbDebugger().set_encoding(encoding, escaping)
        else:
            evt.Skip()
            return

        Profile_Set(PYTOOL_CONFIG, config)
        def Authenticate():
            pwd_dialog = PasswordDialog(self, self.Parent._lastpwd)
            pos = self.GetPositionTuple()
            pwd_dialog.CenterOnParent()
            if pwd_dialog.ShowModal() != wx.ID_OK:
                pwd_dialog.Destroy()
                self.Close()
                return

            self.Parent._lastpwd = pwd_dialog.get_password()
            pwd_dialog.Destroy()

            RpdbDebugger().set_password(self.Parent._lastpwd)
            self.do_refresh()