Example #1
0
 def get_from_thread_name_or_id(self, name_or_id, report_error=True):
     """See if *name_or_id* is either a thread name or a thread id.
     The frame of that id/name is returned, or None if name_or_id is
     invalid."""
     thread_id = self.proc.get_int_noerr(name_or_id)
     if thread_id is None:
         # Must be a "frame" command with frame name, not a frame
         # number (or invalid command).
         name2id = Mthread.map_thread_names()
         if name_or_id == ".":
             name_or_id = Mthread.current_thread_name()
             pass
         thread_id = name2id.get(name_or_id)
         if thread_id is None:
             self.errmsg("I don't know about thread name %s." % name_or_id)
             return None, None
         pass
     # Above we should have set thread_id. Now see if we can
     # find it.
     threads = sys._current_frames()
     frame = threads.get(thread_id)
     if frame is None and report_error:
         self.errmsg(
             "I don't know about thread number %s (%d)." % name_or_id, thread_id
         )
         # self.info_thread_terse()
         return None, None
     return frame, thread_id
Example #2
0
 def get_from_thread_name_or_id(self, name_or_id, report_error=True):
     '''See if *name_or_id* is either a thread name or a thread id.
     The frame of that id/name is returned, or None if name_or_id is
     invalid.'''
     thread_id = self.proc.get_int_noerr(name_or_id)
     if thread_id is None:
         # Must be a "frame" command with frame name, not a frame
         # number (or invalid command).
         name2id = Mthread.map_thread_names()
         if name_or_id == '.':
             name_or_id = Mthread.current_thread_name()
             pass
         thread_id = name2id.get(name_or_id)
         if thread_id is None:
             self.errmsg("I don't know about thread name %s." %
                         name_or_id)
             return None, None
         pass
     # Above we should have set thread_id. Now see if we can
     # find it.
     threads   = sys._current_frames()
     frame     = threads.get(thread_id)
     if frame is None and report_error:
         self.errmsg("I don't know about thread number %s (%d)." %
                     name_or_id, thread_id)
         # self.info_thread_terse()
         return None, None
     return frame, thread_id
Example #3
0
 def id_name_checker(self):
     '''Helper for testing map_thread_names and id2thread'''
     name2id = Mthread.map_thread_names()
     for thread_id, f in list(sys._current_frames().items()):
         self.assertEqual(thread_id,
                          name2id[Mthread.id2thread_name(thread_id)])
         # FIXME: use a better test
         self.assertNotEqual(f, Mthread.find_debugged_frame(f))
         pass
 def id_name_checker(self):
     '''Helper for testing map_thread_names and id2thread'''
     if sys.version_info[0] == 2 and sys.version_info[1] <= 4:
         # Don't have sys._current_frames
         return
     name2id = Mthread.map_thread_names()
     for thread_id, f in list(sys._current_frames().items()):
         self.assertEqual(thread_id,
                          name2id[Mthread.id2thread_name(thread_id)])
         # FIXME: use a better test
         self.assertNotEqual(f, Mthread.find_debugged_frame(f))
         pass
Example #5
0
 def id_name_checker(self):
     '''Helper for testing map_thread_names and id2thread'''
     if sys.version_info[0] == 2 and sys.version_info[1] <= 4:
         # Don't have sys._current_frames
         return
     name2id = Mthread.map_thread_names()
     for thread_id, f in list(sys._current_frames().items()):
         self.assertEqual(thread_id,
                          name2id[Mthread.id2thread_name(thread_id)])
         # FIXME: use a better test
         self.assertNotEqual(f, Mthread.find_debugged_frame(f))
         pass
Example #6
0
    def run(self, args):
        # FIXME: add thread locking here?

        self.thread_name = Mthread.current_thread_name()

        name2id = Mthread.map_thread_names()
        # invert threading._active
        for thread_id in list(threading._active.keys()):
            thread = threading._active[thread_id]
            name = thread.getName()
            if name not in list(self.name2id.keys()):
                self.name2id[name] = thread_id
                pass
            pass

        all_verbose = False
        if len(args) == 1:
            if args[0].startswith('verbose'):
                all_verbose = True
            elif args[0].startswith('terse'):
                self.info_thread_terse(name2id)
                return
            pass

        if len(args) > 0 and not all_verbose:
            thread_name = args[0]
            if thread_name == '.':
                thread_name = self.thread_name
            try:
                thread_id = int(thread_name)
                if thread_id not in list(threading._active.keys()):
                    self.errmsg("Don't know about thread number %s" %
                                thread_name)
                    self.info_thread_terse(name2id)
                    return
            except ValueError:
                if thread_name not in list(self.name2id.keys()):
                    self.errmsg("Don't know about thread %s" % thread_name)
                    self.info_thread_terse(name2id)
                    return
                thread_id = self.name2id[thread_name]
                pass

            frame = sys._current_frames()[thread_id]
            self.stack_trace(frame)
            return

        # Show info about *all* threads
        thread_key_list = list(self.name2id.keys())
        thread_key_list.sort()
        for thread_name in thread_key_list:
            thread_id = self.name2id[thread_name]
            frame = sys._current_frames()[thread_id]
            s = ''
            # Print location where thread was created and line number
            if thread_id in threading._active:
                thread = threading._active[thread_id]
                thread_name = thread.getName()
                if thread_name == self.proc.frame_thread_name:
                    prefix = '-> '
                    if not self.settings['dbg_trepan']:
                        frame = Mthread.find_debugged_frame(frame)
                        pass
                    pass
                elif thread_name == self.proc.thread_name:
                    prefix = '=> '
                else:
                    prefix='   '
                    pass
                s += "%s%s" % (prefix, str(thread))
                if all_verbose:
                    s += ": %d" % thread_id
                    pass
            else:
                s += "    thread id: %d" % thread_id
                pass
            s += "\n    "
            s += Mstack.format_stack_entry(self, (frame, frame.f_lineno),
                                           color=self.settings['highlight'])
            self.section('-' * 40)
            self.msg(s)
            frame = frame.f_back
            if all_verbose and frame:
                self.stack_trace(frame)
                pass
        return
Example #7
0
    def run(self, args):
        # FIXME: add thread locking here?

        self.thread_name = Mthread.current_thread_name()

        name2id = Mthread.map_thread_names()
        # invert threading._active
        for thread_id in list(threading._active.keys()):
            thread = threading._active[thread_id]
            name = thread.getName()
            if name not in list(self.name2id.keys()):
                self.name2id[name] = thread_id
                pass
            pass

        all_verbose = False
        if len(args) == 1:
            if args[0].startswith('verbose'):
                all_verbose = True
            elif args[0].startswith('terse'):
                self.info_thread_terse(name2id)
                return
            pass

        if len(args) > 0 and not all_verbose:
            thread_name = args[0]
            if thread_name == '.':
                thread_name = self.thread_name
            try:
                thread_id = int(thread_name)
                if thread_id not in list(threading._active.keys()):
                    self.errmsg("Don't know about thread number %s" %
                                thread_name)
                    self.info_thread_terse(name2id)
                    return
            except ValueError:
                if thread_name not in list(self.name2id.keys()):
                    self.errmsg("Don't know about thread %s" % thread_name)
                    self.info_thread_terse(name2id)
                    return
                thread_id = self.name2id[thread_name]
                pass

            frame = sys._current_frames()[thread_id]
            self.stack_trace(frame)
            return

        # Show info about *all* threads
        thread_key_list = list(self.name2id.keys())
        thread_key_list.sort()
        for thread_name in thread_key_list:
            thread_id = self.name2id[thread_name]
            frame = sys._current_frames()[thread_id]
            s = ''
            # Print location where thread was created and line number
            if thread_id in threading._active:
                thread = threading._active[thread_id]
                thread_name = thread.getName()
                if thread_name == self.proc.frame_thread_name:
                    prefix = '-> '
                    if not self.settings['dbg_trepan']:
                        frame = Mthread.find_debugged_frame(frame)
                        pass
                    pass
                elif thread_name == self.proc.thread_name:
                    prefix = '=> '
                else:
                    prefix = '   '
                    pass
                s += "%s%s" % (prefix, str(thread))
                if all_verbose:
                    s += ": %d" % thread_id
                    pass
            else:
                s += "    thread id: %d" % thread_id
                pass
            s += "\n    "
            s += Mstack.format_stack_entry(self, (frame, frame.f_lineno),
                                           color=self.settings['highlight'])
            self.section('-' * 40)
            self.msg(s)
            frame = frame.f_back
            if all_verbose and frame:
                self.stack_trace(frame)
                pass
        return