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 virtual bool show_kobject(Kobject_common *, int) { return true; }
43 Jdb_log_list_hdl::invoke(Kobject_common *, Syscall_frame *f, Utcb *utcb)
45 switch (utcb->values[0])
47 case Op_query_log_typeid:
49 unsigned char const idx = utcb->values[1];
50 if (f->tag().words() < 3 || _log_table + idx >= &_log_table_end)
52 f->tag(Kobject_iface::commit_result(-L4_err::EInval));
57 strncpy(nbuf, (char const *)&utcb->values[2], sizeof(nbuf));
58 nbuf[sizeof(nbuf) - 1] = 0;
60 Tb_log_table_entry *r;
61 r = Jdb_log_list::find_next_log(nbuf, nbuf, _log_table + idx);
63 utcb->values[0] = r ? (r - _log_table) + Tbuf_dynentries : ~0UL;
64 f->tag(Kobject_iface::commit_result(0, 1));
67 case Op_query_log_name:
69 unsigned char const idx = utcb->values[1];
70 if (f->tag().words() != 2 || _log_table + idx >= &_log_table_end)
72 f->tag(Kobject_iface::commit_result(-L4_err::EInval));
76 Tb_log_table_entry *e = _log_table + idx;
77 char *dst = (char *)&utcb->values[0];
78 unsigned sz = strlen(e->name) + 1;
79 sz += strlen(e->name + sz) + 1;
80 if (sz > sizeof(utcb->values))
81 sz = sizeof(utcb->values);
82 memcpy(dst, e->name, sz);
85 f->tag(Kobject_iface::commit_result(0, (sz + sizeof(Mword) - 1)
91 if (f->tag().words() < 3)
93 f->tag(Kobject_iface::commit_result(-L4_err::EInval));
97 bool on = utcb->values[1];
99 strncpy(nbuf, (char const *)&utcb->values[2], sizeof(nbuf));
100 nbuf[sizeof(nbuf) - 1] = 0;
102 Tb_log_table_entry *r = _log_table;
103 while ((r = Jdb_log_list::find_next_log(nbuf, nbuf, r)))
105 Jdb_log_list::patch_item(r, on ? Jdb_log_list::patch_val(r) : 0);
109 f->tag(Kobject_iface::commit_result(0));
119 Jdb_log_list::show_item(String_buffer *buffer, void *item) const
121 Tb_log_table_entry const *e = static_cast<Tb_log_table_entry const*>(item);
122 char const *sc = e->name;
123 sc += strlen(e->name) + 1;
124 buffer->printf("%s %s (%s)", *(e->patch) ? "[on ]" : "[off]", e->name, sc);
127 PRIVATE static inline
129 Jdb_log_list::patch_val(Tb_log_table_entry const *e)
130 { return (e - _log_table) + Tbuf_dynentries; }
134 Jdb_log_list::find_next_log(const char *name, const char *sc,
135 Tb_log_table_entry *i)
137 for (; i < _end; ++i)
138 if ( !strcmp(name, i->name)
139 || !strcmp(sc, i->name + strlen(i->name) + 1))
146 Jdb_log_list::enter_item(void *item) const
148 Tb_log_table_entry const *e = static_cast<Tb_log_table_entry const*>(item);
149 patch_item(e, *(e->patch) ? 0 : patch_val(e));
155 Jdb_log_list::patch_item(Tb_log_table_entry const *e, unsigned char val)
160 Mem_unit::make_coherent_to_pou(e->patch);
163 for (Tb_log_table_entry *x = _end; x < &_log_table_end; ++x)
165 if (equal(x, e) && x->patch)
168 Mem_unit::make_coherent_to_pou(x->patch);
175 Jdb_log_list::equal(Tb_log_table_entry const *a, Tb_log_table_entry const *b)
177 if (strcmp(a->name, b->name))
180 char const *sca = a->name; sca += strlen(sca) + 1;
181 char const *scb = b->name; scb += strlen(scb) + 1;
183 if (strcmp(sca, scb))
186 return a->fmt == b->fmt;
191 Jdb_log_list::next(void **item)
193 Tb_log_table_entry *e = static_cast<Tb_log_table_entry*>(*item);
195 while (e + 1 < &_log_table_end)
213 Jdb_log_list::pref(void **item)
215 Tb_log_table_entry *e = static_cast<Tb_log_table_entry*>(*item);
222 while (e > _log_table)
237 Jdb_log_list::seek(int cnt, void **item)
239 Tb_log_table_entry *e = static_cast<Tb_log_table_entry*>(*item);
247 if (e + cnt < _log_table)
248 cnt = _log_table - e;
260 class Jdb_log : public Jdb_module
263 Jdb_log() FIASCO_INIT;
268 static void swap(Tb_log_table_entry *a, Tb_log_table_entry *b)
270 Tb_log_table_entry x = *a;
275 static bool lt_cmp(Tb_log_table_entry *a, Tb_log_table_entry *b)
277 if (strcmp(a->name, b->name) < 0)
283 static void sort_tb_log_table()
285 for (Tb_log_table_entry *p = _log_table; p < &_log_table_end; ++p)
287 for (Tb_log_table_entry *x = &_log_table_end -1; x > p; --x)
288 if (lt_cmp(x, x - 1))
296 Jdb_log_list::move_dups()
298 _end = &_log_table_end;
299 Tb_log_table_entry *const tab_end = &_log_table_end;
300 for (Tb_log_table_entry *p = _log_table + 1; p < _end;)
307 Tb_log_table_entry tmp = *p;
308 memmove(p, p + 1, sizeof(Tb_log_table_entry) * (tab_end - p - 1));
309 *(tab_end - 1) = tmp;
320 static void disable_all()
322 for (Tb_log_table_entry *p = _log_table; p < _log_table_end; ++p)
330 : Jdb_module("MONITORING")
334 Jdb_log_list::move_dups();
336 static Jdb_log_list_hdl hdl;
337 Jdb_kobject::module()->register_handler(&hdl);
341 Jdb_module::Action_code
342 Jdb_log::action(int, void *&, char const *&, int &)
344 if (_log_table >= &_log_table_end)
348 list.set_start(_log_table);
355 Jdb_module::Cmd const *
356 Jdb_log::cmds() const
360 { 0, "O", "log", "", "O\tselect log events", 0 },
367 Jdb_log::num_cmds() const
370 static Jdb_log jdb_log INIT_PRIORITY(JDB_MODULE_INIT_PRIO);