9 #include "jdb_module.h"
10 #include "jdb_kobject.h"
12 #include "jdb_screen.h"
13 #include "kernel_console.h"
16 #include "ram_quota.h"
19 #include "static_init.h"
22 class Jdb_log_list : public Jdb_list
24 friend class Jdb_log_list_hdl;
26 void *get_head() const { return _log_table; }
27 char const *show_head() const { return "[Log]"; }
30 static Tb_log_table_entry *_end;
33 Tb_log_table_entry *Jdb_log_list::_end;
35 class Jdb_log_list_hdl : public Jdb_kobject_handler
38 Jdb_log_list_hdl() : Jdb_kobject_handler(0) {}
39 virtual bool show_kobject(Kobject_common *, int) { return true; }
44 Jdb_log_list_hdl::invoke(Kobject_common *, Syscall_frame *f, Utcb *utcb)
46 switch (utcb->values[0])
50 if (f->tag().words() < 3)
52 f->tag(Kobject_iface::commit_result(-L4_err::EInval));
56 unsigned char const idx = utcb->values[1];
58 if (_log_table + idx >= &_log_table_end)
60 f->tag(Kobject_iface::commit_result(-L4_err::EInval));
65 strncpy(nbuf, (char const *)&utcb->values[2], sizeof(nbuf));
66 nbuf[sizeof(nbuf) - 1] = 0;
68 Tb_log_table_entry *r;
69 r = Jdb_log_list::find_next_log(nbuf, nbuf, _log_table + idx);
71 utcb->values[0] = r ? (r - _log_table) + Tbuf_dynentries : ~0UL;
72 f->tag(Kobject_iface::commit_result(0, 1));
77 if (f->tag().words() < 3)
79 f->tag(Kobject_iface::commit_result(-L4_err::EInval));
83 bool on = utcb->values[1];
85 strncpy(nbuf, (char const *)&utcb->values[2], sizeof(nbuf));
86 nbuf[sizeof(nbuf) - 1] = 0;
88 Tb_log_table_entry *r = _log_table;
89 while ((r = Jdb_log_list::find_next_log(nbuf, nbuf, r)))
91 Jdb_log_list::patch_item(r, on ? Jdb_log_list::patch_val(r) : 0);
95 f->tag(Kobject_iface::commit_result(0));
105 Jdb_log_list::show_item(char *buffer, int max, void *item) const
107 Tb_log_table_entry const *e = static_cast<Tb_log_table_entry const*>(item);
108 char const *sc = e->name;
109 sc += strlen(e->name) + 1;
110 int pos = snprintf(buffer, max, "%s %s (%s)",
111 *(e->patch) ? "[on ]" : "[off]", e->name, sc);
115 PRIVATE static inline
117 Jdb_log_list::patch_val(Tb_log_table_entry const *e)
118 { return (e - _log_table) + Tbuf_dynentries; }
122 Jdb_log_list::find_next_log(const char *name, const char *sc,
123 Tb_log_table_entry *i)
125 for (; i < _end; ++i)
126 if ( !strcmp(name, i->name)
127 || !strcmp(sc, i->name + strlen(i->name) + 1))
134 Jdb_log_list::enter_item(void *item) const
136 Tb_log_table_entry const *e = static_cast<Tb_log_table_entry const*>(item);
137 patch_item(e, *(e->patch) ? 0 : patch_val(e));
143 Jdb_log_list::patch_item(Tb_log_table_entry const *e, unsigned char val)
148 Mem_unit::clean_dcache(e->patch);
151 for (Tb_log_table_entry *x = _end; x < &_log_table_end; ++x)
153 if (equal(x, e) && x->patch)
156 Mem_unit::clean_dcache(x->patch);
163 Jdb_log_list::equal(Tb_log_table_entry const *a, Tb_log_table_entry const *b)
165 if (strcmp(a->name, b->name))
168 char const *sca = a->name; sca += strlen(sca) + 1;
169 char const *scb = b->name; scb += strlen(scb) + 1;
171 if (strcmp(sca, scb))
174 return a->fmt == b->fmt;
179 Jdb_log_list::next(void **item)
181 Tb_log_table_entry *e = static_cast<Tb_log_table_entry*>(*item);
183 while (e + 1 < &_log_table_end)
201 Jdb_log_list::pref(void **item)
203 Tb_log_table_entry *e = static_cast<Tb_log_table_entry*>(*item);
210 while (e > _log_table)
225 Jdb_log_list::seek(int cnt, void **item)
227 Tb_log_table_entry *e = static_cast<Tb_log_table_entry*>(*item);
235 if (e + cnt < _log_table)
236 cnt = _log_table - e;
248 class Jdb_log : public Jdb_module
251 Jdb_log() FIASCO_INIT;
256 static void swap(Tb_log_table_entry *a, Tb_log_table_entry *b)
258 Tb_log_table_entry x = *a;
263 static bool lt_cmp(Tb_log_table_entry *a, Tb_log_table_entry *b)
265 if (strcmp(a->name, b->name) < 0)
271 static void sort_tb_log_table()
273 for (Tb_log_table_entry *p = _log_table; p < &_log_table_end; ++p)
275 for (Tb_log_table_entry *x = &_log_table_end -1; x > p; --x)
276 if (lt_cmp(x, x - 1))
284 Jdb_log_list::move_dups()
286 _end = &_log_table_end;
287 Tb_log_table_entry *const tab_end = &_log_table_end;
288 for (Tb_log_table_entry *p = _log_table + 1; p < _end;)
295 Tb_log_table_entry tmp = *p;
296 memmove(p, p + 1, sizeof(Tb_log_table_entry) * (tab_end - p - 1));
297 *(tab_end - 1) = tmp;
308 static void disable_all()
310 for (Tb_log_table_entry *p = _log_table; p < _log_table_end; ++p)
318 : Jdb_module("MONITORING")
322 Jdb_log_list::move_dups();
324 static Jdb_log_list_hdl hdl;
325 Jdb_kobject::module()->register_handler(&hdl);
329 Jdb_module::Action_code
330 Jdb_log::action(int, void *&, char const *&, int &)
332 if (_log_table >= &_log_table_end)
336 list.set_start(_log_table);
343 Jdb_module::Cmd const *
344 Jdb_log::cmds() const
348 { 0, "O", "log", "", "O\tselect log events", 0 },
355 Jdb_log::num_cmds() const
358 static Jdb_log jdb_log INIT_PRIORITY(JDB_MODULE_INIT_PRIO);