]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/jdb/jdb_sender_list.cpp
update
[l4.git] / kernel / fiasco / src / jdb / jdb_sender_list.cpp
1 IMPLEMENTATION:
2
3 #include <cstdio>
4 #include <cstring>
5
6 #include "thread_object.h"
7 #include "jdb.h"
8 #include "jdb_kobject.h"
9 #include "jdb_module.h"
10
11
12 class Jdb_sender_list : public Jdb_module, public Jdb_kobject_handler
13 {
14 public:
15   Jdb_sender_list() FIASCO_INIT;
16
17   virtual bool show_kobject(Kobject *, int) { return true; }
18 private:
19   static Kobject *thread;
20 };
21
22 static Jdb_sender_list jdb_sender_list INIT_PRIORITY(JDB_MODULE_INIT_PRIO);
23
24 Kobject *Jdb_sender_list::thread;
25
26
27 PRIVATE
28 void
29 Jdb_sender_list::show_sender_list(Thread *t, int printlines)
30 {
31   puts(printlines ? Jdb_screen::Line : "");
32   Jdb::clear_to_eol();
33   printf("Thread: %lx\n", t->dbg_info()->dbg_id());
34
35   Prio_list_elem *p = t->sender_list()->head();
36   if (!p)
37     {
38       Jdb::clear_to_eol();
39       printf("Nothing in sender list\n");
40       if (printlines)
41         puts(Jdb_screen::Line);
42       return;
43     }
44
45   while (p)
46     {
47       Jdb::clear_to_eol();
48       printf("%02x: ", p->prio());
49       Prio_list_elem *s = p;
50       do
51         {
52           Thread *ts = static_cast<Thread *>(Sender::cast(s));
53           printf("%s %lx", s == p ? "" : ",", ts->dbg_info()->dbg_id());
54           s = s->_s_next;
55         } while (s != p);
56       puts("");
57       p = p->_p_next;
58     }
59
60   if (printlines)
61     puts(Jdb_screen::Line);
62 }
63
64 PUBLIC
65 Jdb_module::Action_code
66 Jdb_sender_list::action(int cmd, void *&, char const *&, int &)
67 {
68   if (cmd)
69     return NOTHING;
70
71   Thread *t = Kobject::dcast<Thread_object *>(thread);
72   if (!t)
73     {
74       printf(" Invalid thread\n");
75       return NOTHING;
76     }
77
78   show_sender_list(t, 0);
79
80   return NOTHING;
81 }
82
83 PUBLIC
84 bool
85 Jdb_sender_list::handle_key(Kobject *o, int keycode)
86 {
87   if (keycode != 'S')
88     return false;
89
90   Thread *t = Kobject::dcast<Thread_object *>(o);
91   if (!t)
92     return false;
93
94   show_sender_list(t, 1);
95   Jdb::getchar();
96   return true;
97 }
98
99 PUBLIC
100 int Jdb_sender_list::num_cmds() const
101 { return 1; }
102
103 PUBLIC
104 Jdb_module::Cmd const * Jdb_sender_list::cmds() const
105 {
106   static Cmd cs[] =
107     {
108         { 0, "S", "senderlist", "%q",
109           "senderlist\tshow sender-list of thread", &thread }
110     };
111
112   return cs;
113 }
114
115 IMPLEMENT
116 Jdb_sender_list::Jdb_sender_list()
117   : Jdb_module("INFO"), Jdb_kobject_handler(0)
118 {
119   Jdb_kobject::module()->register_handler(this);
120 }