Ejemplo n.º 1
0
    def doIt(self, dbg):
        """ Converts request into python variable """
        try:
            xml = "<xml>"
            valDict = pydevd_vars.resolveCompoundVariable(self.thread_id, self.frame_id, self.scope, self.attributes)
            if valDict is None:
                valDict = {}

            keys = valDict.keys()
            if hasattr(keys, 'sort'):
                keys.sort(compare_object_attrs) #Python 3.0 does not have it
            else:
                if IS_PY3K:
                    keys = sorted(keys, key=cmp_to_key(compare_object_attrs)) #Jython 2.1 does not have it (and all must be compared as strings).
                else:
                    keys = sorted(keys, cmp=compare_object_attrs) #Jython 2.1 does not have it (and all must be compared as strings).

            for k in keys:
                xml += pydevd_vars.varToXML(valDict[k], to_string(k))

            xml += "</xml>"
            cmd = dbg.cmdFactory.makeGetVariableMessage(self.sequence, xml)
            dbg.writer.addCommand(cmd)
        except Exception:
            cmd = dbg.cmdFactory.makeErrorMessage(self.sequence, "Error resolving variables " + GetExceptionTracebackStr())
            dbg.writer.addCommand(cmd)
Ejemplo n.º 2
0
    def doIt(self, dbg):
        """ Converts request into python variable """
        pydev_start_new_thread = None
        try:
            try:
                pydev_start_new_thread = thread.start_new_thread

                thread.start_new_thread = thread._original_start_new_thread #don't trace new threads created by console command
                thread.start_new = thread._original_start_new_thread

                result = pydevconsole.consoleExec(self.thread_id, self.frame_id, self.expression)
                xml = "<xml>"
                xml += pydevd_vars.varToXML(result, "")
                xml += "</xml>"
                cmd = dbg.cmdFactory.makeEvaluateExpressionMessage(self.sequence, xml)
                dbg.writer.addCommand(cmd)
            except:
                exc = GetExceptionTracebackStr()
                sys.stderr.write('%s\n' % (exc,))
                cmd = dbg.cmdFactory.makeErrorMessage(self.sequence, "Error evaluating console expression " + exc)
                dbg.writer.addCommand(cmd)
        finally:
            thread.start_new_thread = pydev_start_new_thread
            thread.start_new = pydev_start_new_thread
            sys.stderr.flush()
            sys.stdout.flush()
Ejemplo n.º 3
0
    def evaluate(self, expression):
        xml = "<xml>"
        result = pydevd_vars.evalInContext(expression, self.getNamespace(), self.getNamespace())

        xml += pydevd_vars.varToXML(result, expression)

        xml += "</xml>"

        return xml
    def evaluate(self, expression):
        xml = "<xml>"
        result = pydevd_vars.evalInContext(expression, self.getNamespace(), self.getNamespace())

        xml += pydevd_vars.varToXML(result, expression)

        xml += "</xml>"

        return xml
Ejemplo n.º 5
0
 def doIt(self, dbg):
     """ Converts request into python variable """
     try:
         result = pydevd_vars.changeAttrExpression(self.thread_id, self.frame_id, self.attr, self.expression)
         xml = "<xml>"
         xml += pydevd_vars.varToXML(result, "")
         xml += "</xml>"
         cmd = dbg.cmdFactory.makeVariableChangedMessage(self.sequence, xml)
         dbg.writer.addCommand(cmd)
     except Exception:
         cmd = dbg.cmdFactory.makeErrorMessage(self.sequence, "Error changing variable attr:%s expression:%s traceback:%s" % (self.attr, self.expression, GetExceptionTracebackStr()))
         dbg.writer.addCommand(cmd)
Ejemplo n.º 6
0
 def doIt(self, dbg):
     """ Converts request into python variable """
     try:
         result = pydevd_vars.evaluateExpression(self.thread_id, self.frame_id, self.expression, self.doExec)
         xml = "<xml>"
         xml += pydevd_vars.varToXML(result, "")
         xml += "</xml>"
         cmd = dbg.cmdFactory.makeEvaluateExpressionMessage(self.sequence, xml)
         dbg.writer.addCommand(cmd)
     except:
         exc = GetExceptionTracebackStr()
         print >> sys.stderr, exc
         cmd = dbg.cmdFactory.makeErrorMessage(self.sequence, "Error evaluating expression " + exc)
         dbg.writer.addCommand(cmd)
Ejemplo n.º 7
0
    def getVariable(self, attributes):
        xml = "<xml>"
        valDict = pydevd_vars.resolveVar(self.getNamespace(), attributes)
        if valDict is None:
            valDict = {}

        keys = valDict.keys()

        for k in keys:
            xml += pydevd_vars.varToXML(valDict[k], to_string(k))

        xml += "</xml>"

        return xml
Ejemplo n.º 8
0
 def doIt(self, dbg):
     """ Converts request into python variable """
     try:
         result = pydevd_vars.evaluateExpression(self.thread_id, self.frame_id, self.expression, self.doExec)
         xml = "<xml>"
         xml += pydevd_vars.varToXML(result, "", self.doTrim)
         xml += "</xml>"
         cmd = dbg.cmdFactory.makeEvaluateExpressionMessage(self.sequence, xml)
         dbg.writer.addCommand(cmd)
     except:
         exc = GetExceptionTracebackStr()
         sys.stderr.write('%s\n' % (exc,))
         cmd = dbg.cmdFactory.makeErrorMessage(self.sequence, "Error evaluating expression " + exc)
         dbg.writer.addCommand(cmd)
Ejemplo n.º 9
0
    def getVariable(self, attributes):
        xml = "<xml>"
        valDict = pydevd_vars.resolveVar(self.getNamespace(), attributes)
        if valDict is None:
            valDict = {}

        keys = valDict.keys()

        for k in keys:
            xml += pydevd_vars.varToXML(valDict[k], to_string(k))

        xml += "</xml>"

        return xml
Ejemplo n.º 10
0
    def doIt(self, dbg):
        """ Converts request into python variable """
        try:
            xml = "<xml>"            
            valDict = pydevd_vars.resolveCompoundVariable(self.thread_id, self.frame_id, self.scope, self.attributes)                        
            keys = valDict.keys()
            keys.sort()
            for k in keys:
                xml += pydevd_vars.varToXML(valDict[k], str(k))

            xml += "</xml>"
            cmd = dbg.cmdFactory.makeGetVariableMessage(self.sequence, xml)
            dbg.writer.addCommand(cmd)
        except Exception:
            cmd = dbg.cmdFactory.makeErrorMessage(self.sequence, "Error resolving variables " + GetExceptionTracebackStr())
            dbg.writer.addCommand(cmd)
Ejemplo n.º 11
0
def get_referrer_info(searched_obj):
    try:
        if searched_obj is None:
            ret = ["<xml>\n"]

            ret.append("<for>\n")
            ret.append(
                pydevd_vars.varToXML(
                    searched_obj, "Skipping getting referrers for None", ' id="%s"' % (id(searched_obj),)
                )
            )
            ret.append("</for>\n")
            ret.append("</xml>")
            ret = "".join(ret)
            return ret

        obj_id = id(searched_obj)

        try:
            import gc

            referrers = gc.get_referrers(searched_obj)
        except:
            import traceback

            traceback.print_exc()
            ret = ["<xml>\n"]

            ret.append("<for>\n")
            ret.append(
                pydevd_vars.varToXML(
                    searched_obj, "Exception raised while trying to get_referrers.", ' id="%s"' % (id(searched_obj),)
                )
            )
            ret.append("</for>\n")
            ret.append("</xml>")
            ret = "".join(ret)
            return ret

            traceback.print_exc()

        curr_frame = sys._getframe()
        frame_type = type(curr_frame)

        # Ignore this frame and any caller frame of this frame

        ignore_frames = {}  # Should be a set, but it's not available on all python versions.
        while curr_frame is not None:
            if basename(curr_frame.f_code.co_filename).startswith("pydev"):
                ignore_frames[curr_frame] = 1
            curr_frame = curr_frame.f_back

        ret = ["<xml>\n"]

        ret.append("<for>\n")
        ret.append(pydevd_vars.varToXML(searched_obj, "Referrers of", ' id="%s"' % (obj_id,)))
        ret.append("</for>\n")

        all_objects = None

        for r in referrers:
            try:
                if DictContains(ignore_frames, r):
                    continue  # Skip the references we may add ourselves
            except:
                pass  # Ok: unhashable type checked...

            if r is referrers:
                continue

            r_type = type(r)
            r_id = str(id(r))

            representation = str(r_type)

            found_as = ""
            if r_type == frame_type:
                for key, val in r.f_locals.items():
                    if val is searched_obj:
                        found_as = key
                        break

            elif r_type == dict:
                # Try to check if it's a value in the dict (and under which key it was found)
                for key, val in r.items():
                    if val is searched_obj:
                        found_as = key
                        break

                # Ok, there's one annoying thing: many times we find it in a dict from an instance,
                # but with this we don't directly have the class, only the dict, so, to workaround that
                # we iterate over all reachable objects ad check if one of those has the given dict.
                if all_objects is None:
                    all_objects = gc.get_objects()

                for x in all_objects:
                    try:
                        if getattr(x, "__dict__", None) is r:
                            r = x
                            r_type = type(x)
                            r_id = str(id(r))
                            representation = str(r_type)
                            break
                    except:
                        pass  # Just ignore any error here (i.e.: ReferenceError, etc.)

            elif r_type in (tuple, list):

                # Don't use enumerate() because not all Python versions have it.
                i = 0
                for x in r:
                    if x is searched_obj:
                        found_as = "%s[%s]" % (r_type.__name__, i)
                        break
                    i += 1

            if found_as:
                found_as = ' found_as="%s"' % (pydevd_vars.makeValidXmlValue(found_as),)

            ret.append(pydevd_vars.varToXML(r, representation, ' id="%s"%s' % (r_id, found_as)))
    finally:
        # If we have any exceptions, don't keep dangling references from this frame to any of our objects.
        all_objects = None
        referrers = None
        searched_obj = None
        r = None
        x = None
        key = None
        val = None
        curr_frame = None
        ignore_frames = None

    ret.append("</xml>")
    ret = "".join(ret)
    return ret
Ejemplo n.º 12
0
def get_referrer_info(searched_obj):
    try:
        if searched_obj is None:
            ret = ['<xml>\n']

            ret.append('<for>\n')
            ret.append(
                pydevd_vars.varToXML(searched_obj,
                                     'Skipping getting referrers for None',
                                     ' id="%s"' % (id(searched_obj), )))
            ret.append('</for>\n')
            ret.append('</xml>')
            ret = ''.join(ret)
            return ret

        obj_id = id(searched_obj)

        try:
            import gc
            referrers = gc.get_referrers(searched_obj)
        except:
            import traceback
            traceback.print_exc()
            ret = ['<xml>\n']

            ret.append('<for>\n')
            ret.append(
                pydevd_vars.varToXML(
                    searched_obj,
                    'Exception raised while trying to get_referrers.',
                    ' id="%s"' % (id(searched_obj), )))
            ret.append('</for>\n')
            ret.append('</xml>')
            ret = ''.join(ret)
            return ret

            traceback.print_exc()

        curr_frame = sys._getframe()
        frame_type = type(curr_frame)

        #Ignore this frame and any caller frame of this frame

        ignore_frames = {
        }  #Should be a set, but it's not available on all python versions.
        while curr_frame is not None:
            if basename(curr_frame.f_code.co_filename).startswith('pydev'):
                ignore_frames[curr_frame] = 1
            curr_frame = curr_frame.f_back

        ret = ['<xml>\n']

        ret.append('<for>\n')
        ret.append(
            pydevd_vars.varToXML(searched_obj, 'Referrers of',
                                 ' id="%s"' % (obj_id, )))
        ret.append('</for>\n')

        all_objects = None

        for r in referrers:
            try:
                if DictContains(ignore_frames, r):
                    continue  #Skip the references we may add ourselves
            except:
                pass  #Ok: unhashable type checked...

            if r is referrers:
                continue

            r_type = type(r)
            r_id = str(id(r))

            representation = str(r_type)

            found_as = ''
            if r_type == frame_type:
                for key, val in r.f_locals.items():
                    if val is searched_obj:
                        found_as = key
                        break

            elif r_type == dict:
                # Try to check if it's a value in the dict (and under which key it was found)
                for key, val in r.items():
                    if val is searched_obj:
                        found_as = key
                        break

                #Ok, there's one annoying thing: many times we find it in a dict from an instance,
                #but with this we don't directly have the class, only the dict, so, to workaround that
                #we iterate over all reachable objects ad check if one of those has the given dict.
                if all_objects is None:
                    all_objects = gc.get_objects()

                for x in all_objects:
                    if getattr(x, '__dict__', None) is r:
                        r = x
                        r_type = type(x)
                        r_id = str(id(r))
                        representation = str(r_type)
                        break

            elif r_type in (tuple, list):

                #Don't use enumerate() because not all Python versions have it.
                i = 0
                for x in r:
                    if x is searched_obj:
                        found_as = '%s[%s]' % (r_type.__name__, i)
                        break
                    i += 1

            if found_as:
                found_as = ' found_as="%s"' % (
                    pydevd_vars.makeValidXmlValue(found_as), )

            ret.append(
                pydevd_vars.varToXML(r, representation,
                                     ' id="%s"%s' % (r_id, found_as)))
    finally:
        #If we have any exceptions, don't keep dangling references from this frame to any of our objects.
        all_objects = None
        referrers = None
        searched_obj = None
        r = None
        x = None
        key = None
        val = None
        curr_frame = None
        ignore_frames = None

    ret.append('</xml>')
    ret = ''.join(ret)
    return ret