12 typedef unsigned (Format_entry_fn)(Tb_entry *tb, const char *tidstr,
13 unsigned tidlen, char *buf, int maxlen);
14 static Format_entry_fn *_format_entry_fn[];
15 static bool show_names;
26 #include "initcalls.h"
28 #include "jdb_kobject_names.h"
29 #include "jdb_regex.h"
30 #include "jdb_symbol.h"
33 #include "kernel_console.h"
35 #include "processor.h"
36 #include "static_init.h"
38 #include "terminate.h"
42 Jdb_tbuf_output::Format_entry_fn *Jdb_tbuf_output::_format_entry_fn[Tbuf_max];
43 bool Jdb_tbuf_output::show_names;
46 console_log_entry(Tb_entry *e, const char *)
48 static char log_message[80];
50 // disable all interrupts to stop other threads
52 Proc::Status s = Proc::cli_save();
54 Jdb_tbuf_output::print_entry(e, log_message, sizeof(log_message));
55 printf("%s\n", log_message);
57 // do not use getchar here because we ran cli'd
58 // and getchar may do halt
61 while ((c=Kconsole::console()->getchar(false)) == -1)
69 // enable interrupts we previously disabled
76 Jdb_tbuf_output::dummy_format_entry (Tb_entry *tb, const char *, unsigned,
77 char *buf, int maxlen)
79 int len = snprintf(buf, maxlen,
80 " << no format_entry_fn for type %d registered >>", tb->type());
81 return len >= maxlen ? maxlen-1 : len;
84 STATIC_INITIALIZE(Jdb_tbuf_output);
88 Jdb_tbuf_output::init()
92 Jdb_tbuf::direct_log_entry = &console_log_entry;
93 for (i=0; i<sizeof(_format_entry_fn)/sizeof(_format_entry_fn[0]); i++)
94 if (!_format_entry_fn[i])
95 _format_entry_fn[i] = dummy_format_entry;
100 Jdb_tbuf_output::register_ff(Unsigned8 type, Format_entry_fn format_entry_fn)
102 assert(type < Tbuf_max);
104 if ( (_format_entry_fn[type] != 0)
105 && (_format_entry_fn[type] != dummy_format_entry))
106 panic("format entry function for type %d already registered", type);
108 _format_entry_fn[type] = format_entry_fn;
111 // return thread+ip of entry <e_nr>
114 Jdb_tbuf_output::thread_ip(int e_nr, Thread const **th, Mword *ip)
116 Tb_entry *e = Jdb_tbuf::lookup(e_nr);
121 *th = Thread::lookup(e->ctx());
130 Jdb_tbuf_output::toggle_names()
132 show_names = !show_names;
137 formatter_default(Tb_entry *tb, const char *tidstr, unsigned tidlen,
138 char *buf, int maxlen)
140 if (tb->type() < Tbuf_dynentries)
143 int idx = tb->type()-Tbuf_dynentries;
145 Tb_entry_formatter *fmt = _log_table[idx].fmt;
146 char const *sc = _log_table[idx].name;
147 sc += strlen(sc) + 1;
149 unsigned l = snprintf(buf, maxlen, "%-3s: %-*s ", sc, tidlen, tidstr);
155 Tb_entry_ke_reg *e = static_cast<Tb_entry_ke_reg*>(tb);
157 snprintf(ip_buf, sizeof(ip_buf), " @ "L4_PTR_FMT, e->ip());
158 snprintf(buf, maxlen, "\"%s\" "
159 L4_PTR_FMT" "L4_PTR_FMT" "L4_PTR_FMT"%s",
160 e->msg(), e->val1(), e->val2(), e->val3(),
161 e->ip() ? ip_buf : "");
166 return fmt(tb, maxlen, buf);
171 Jdb_tbuf_output::print_entry(int e_nr, char *buf, int maxlen)
173 Tb_entry *tb = Jdb_tbuf::lookup(e_nr);
176 print_entry(tb, buf, maxlen);
181 Jdb_tbuf_output::print_entry(Tb_entry *tb, char *buf, int maxlen)
183 assert(tb->type() < Tbuf_max);
186 Thread const *t = Thread::lookup(tb->ctx());
188 if (!t || !Kobject_dbg::is_kobj(t))
189 strcpy(tidstr, "????");
193 = Jdb_kobject_extension::find_extension<Jdb_kobject_name>(t->kobject());
194 if (show_names && ex)
195 snprintf(tidstr, sizeof(tidstr), "%04lx %-*.*s", t->dbg_info()->dbg_id(), ex->max_len(), ex->max_len(), ex->name());
197 snprintf(tidstr, sizeof(tidstr), "%04lx", t->dbg_info()->dbg_id());
200 if (Config::Max_num_cpus > 1)
202 snprintf(buf, maxlen, Config::Max_num_cpus > 16 ? "%02d " : "%d ", tb->cpu());
203 buf += 2 + (Config::Max_num_cpus > 16);
204 maxlen -= 2 + (Config::Max_num_cpus > 16);
209 if (tb->type() >= Tbuf_dynentries)
210 len = formatter_default(tb, tidstr, show_names ? 21 : 4, buf, maxlen);
212 len = _format_entry_fn[tb->type()](tb, tidstr,
213 show_names ? 21 : 4, buf, maxlen);
224 Jdb_tbuf_output::set_filter(const char *filter_str, Mword *entries)
226 if (*filter_str && Jdb_regex::avail() && !Jdb_regex::start(filter_str))
231 for (Mword n=0; n<Jdb_tbuf::unfiltered_entries(); n++)
232 Jdb_tbuf::unfiltered_lookup(n)->unhide();
234 Jdb_tbuf::disable_filter();
236 *entries = Jdb_tbuf::unfiltered_entries();
242 for (Mword n=0; n<Jdb_tbuf::unfiltered_entries(); n++)
244 Tb_entry *e = Jdb_tbuf::unfiltered_lookup(n);
247 print_entry(e, s, sizeof(s));
248 if (Jdb_regex::avail())
250 if (Jdb_regex::find(s, 0, 0))
259 if (strstr(s, filter_str))
271 Jdb_tbuf::enable_filter();