]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/jdb/jdb_thread.cpp
3a09ea995f95445b8ca3f7952eb821e783c8dcd8
[l4.git] / kernel / fiasco / src / jdb / jdb_thread.cpp
1 INTERFACE:
2
3 #include "thread_object.h"
4
5 class Jdb_thread
6 {
7 };
8
9 IMPLEMENTATION:
10
11 #include "irq.h"
12 #include "jdb_kobject.h"
13 #include "kobject.h"
14 #include "thread_state.h"
15 #include "vlog.h"
16
17 #include <cstdio>
18
19 PUBLIC static
20 void
21 Jdb_thread::print_state_long(Thread *t, unsigned cut_on_len = 0)
22 {
23   static char const * const state_names[] =
24     {
25       "ready",         "drq_rdy",       "rcv",         "poll",
26       "ipc_progr",     "snd_progr",     "cancel",      "<unk>",
27       "<unk>",         "dead",          "suspended",   "<unk>",
28       "<unk>",         "delayed_deadl", "delayed_ipc", "fpu",
29       "alien",         "dealien",       "exc_progr",   "transfer",
30       "drq",           "lock_wait",     "vcpu",        "",
31       "vcpu_fpu_disabled", "vcpu_ext"
32     };
33
34   unsigned chars = 0;
35   bool comma = false;
36
37   Mword bits = t->state(false);
38
39   for (unsigned i = 0; i < sizeof (state_names) / sizeof (char *);
40        i++, bits >>= 1)
41     {
42       if (!(bits & 1))
43         continue;
44
45       if (cut_on_len)
46         {
47           unsigned add = strlen(state_names[i]) + comma;
48           if (chars + add > cut_on_len)
49             {
50               if (chars < cut_on_len - 4)
51                 putstr(",...");
52               break;
53             }
54           chars += add;
55         }
56
57       printf("%s%s", "," + !comma, state_names[i]);
58
59       comma = 1;
60     }
61 }
62
63 PUBLIC static
64 void
65 Jdb_thread::print_snd_partner(Thread *t, int task_format = 0)
66 {
67   if (t->state(false) & Thread_send_in_progress)
68     Jdb_kobject::print_uid(static_cast<Thread*>(t->receiver()), task_format);
69   else
70     // receiver() not valid
71     putstr("       ");
72 }
73
74 PUBLIC static
75 void
76 Jdb_thread::print_partner(Thread *t, int task_format = 0)
77 {
78   Sender *p = t->partner();
79
80   if (!(t->state(false) & Thread_receiving))
81     {
82       printf("%*s ", task_format, " ");
83       return;
84     }
85
86   if (!p)
87     {
88       printf("%*s ", task_format, "-");
89       return;
90     }
91
92   if (Kobject *o = Kobject::pointer_to_obj(p))
93     {
94       char flag = '?';
95       const char *n = o->kobj_type();
96
97       if (n == Thread_object::static_kobj_type)
98         flag = ' ';
99       else if (n == Irq::static_kobj_type)
100         flag = '*';
101
102       printf("%*.lx%c", task_format, o->dbg_info()->dbg_id(), flag);
103     }
104   else
105     printf("\033[31;1m%p\033[m ", p);
106 }