7 #include "jdb_screen.h"
8 #include "kernel_console.h"
15 #include "static_init.h"
17 #include "jdb_kobject.h"
18 #include "jdb_kobject_names.h"
20 class Jdb_mapdb : public Jdb_module
22 friend class Jdb_kobject_mapdb_hdl;
24 Jdb_mapdb() FIASCO_INIT;
30 char Jdb_mapdb::subcmd;
31 Mword Jdb_mapdb::pagenum;
37 static char scratchbuf[6];
44 snprintf (scratchbuf, 6, "%u%c", unsigned(size), "BKMGTPX"[mult]);
50 Jdb_mapdb::val(Mdb_types::Pfn p, Mdb_types::Order base_size)
52 return cxx::int_value<Mdb_types::Pfn>(p << base_size);
58 Jdb_mapdb::show_tree(Treemap* pages, Mapping::Pcnt offset, Mdb_types::Order base_size,
59 unsigned &screenline, unsigned indent = 1)
61 typedef Treemap::Page Page;
63 Page page = pages->trunc_to_page(offset);
64 Physframe* f = pages->frame(page);
65 Mapping_tree* t = f->tree.get();
71 printf(" no mapping tree registered for frame number 0x%lx\033[K\n",
72 cxx::int_value<Mapping::Page>(page));
77 printf(" mapping tree for %s-page %012llx of task %lx - header at "
78 L4_PTR_FMT "\033[K\n",
79 size_str(1ULL << cxx::int_value<Mdb_types::Order>(pages->_page_shift + base_size)),
80 val(pages->vaddr(t->mappings()), base_size),
81 Kobject_dbg::pointer_to_id(t->mappings()[0].space()),
84 // If NDEBUG is active, t->_empty_count is undefined
85 printf(" header info: "
86 "entries used: %u free: -- total: %u lock=%u\033[K\n",
87 t->_count, t->number_of_entries(),
90 if (t->_count > t->number_of_entries())
94 " seems to be a wrong tree ! ...exiting");
96 for (i=6; i<Jdb_screen::height(); i++)
101 printf(" header info: "
102 "entries used: %u free: %u total: %u lock=%u\033[K\n",
103 t->_count, t->_empty_count, t->number_of_entries(),
106 if (unsigned (t->_count) + t->_empty_count > t->number_of_entries())
110 " seems to be a wrong tree ! ...exiting");
111 // clear rest of page
112 for (i=6; i<Jdb_screen::height(); i++)
118 Mapping* m = t->mappings();
122 for (i=0; i < t->_count; i++, m++)
124 Kconsole::console()->getchar_chance();
126 if (m->depth() == Mapping::Depth_submap)
127 printf("%*u: %lx subtree@" L4_PTR_FMT,
128 indent + m->parent()->depth() > 10
129 ? 0 : indent + m->parent()->depth(),
130 i+1, (Address) m->data(), (Mword) m->submap());
133 printf("%*u: %lx va=%012llx task=%lx depth=",
134 indent + m->depth() > 10 ? 0 : indent + m->depth(),
135 i+1, (Address) m->data(),
136 val(pages->vaddr(m), base_size),
137 Kobject_dbg::pointer_to_id(m->space()));
139 if (m->depth() == Mapping::Depth_root)
141 else if (m->depth() == Mapping::Depth_empty)
143 else if (m->depth() == Mapping::Depth_end)
146 printf("%lu", static_cast<unsigned long>(m->depth()));
152 if (screenline >= (m->depth() == Mapping::Depth_submap
153 ? Jdb_screen::height() - 3
154 : Jdb_screen::height()))
156 printf(" any key for next page or <ESC>");
157 Jdb::cursor(screenline, 33);
158 c = Jdb_core::getchar();
166 if (m->depth() == Mapping::Depth_submap)
168 if (! Jdb_mapdb::show_tree(m->submap(),
169 cxx::get_lsb(offset, pages->_page_shift),
171 screenline, indent + m->parent()->depth()))
181 Jdb_mapdb::end_address (Mapdb* mapdb)
183 return cxx::int_value<Mdb_types::Pfn>(mapdb->_treemap->end_addr());
188 Jdb_mapdb::show(Mapping::Pfn page, char which_mapdb)
194 typedef Mdb_types::Order Order;
200 Mapping::Pcnt super_inc;
201 Mdb_types::Order super_shift;
202 Order base_size = Order(0);
208 mapdb = mapdb_mem.get();
209 base_size = Order(Config::PAGE_SHIFT);
210 super_shift = Mdb_types::Order(Config::SUPERPAGE_SHIFT - Config::PAGE_SHIFT);
215 mapdb = mapdb_io.get();
216 base_size = Order(0);
217 super_shift = Mdb_types::Order(8);
224 super_inc = Mapping::Pcnt(1) << super_shift;
226 if (! mapdb->valid_address(page))
227 page = Mapping::Pfn(0);
230 printf("%s %012llx\033[K\n\033[K\n", type, val(page, base_size));
234 if (! Jdb_mapdb::show_tree(mapdb->_treemap, page - Mapping::Pfn(0), base_size, j))
237 for (; j<Jdb_screen::height(); j++)
240 static char prompt[] = "mapdb[m]";
241 prompt[6] = which_mapdb;
243 Jdb::printf_statline(prompt,
244 "n=next p=previous N=nextsuper P=prevsuper", "_");
246 for (bool redraw=false; !redraw; )
248 Jdb::cursor(Jdb_screen::height(), 10);
249 switch (c = Jdb_core::getchar())
252 case KEY_CURSOR_DOWN:
253 if (! mapdb->valid_address(++page))
254 page = Mapping::Pfn(0);
259 if (! mapdb->valid_address(--page))
260 page = Mapping::Pfn(end_address(mapdb) - 1);
265 page = cxx::mask_lsb(page + super_inc, super_shift);
266 if (! mapdb->valid_address(page))
267 page = Mapping::Pfn(0);
272 page = cxx::mask_lsb(page - super_inc, super_shift);
273 if (! mapdb->valid_address(page))
274 page = Mapping::Pfn(end_address(mapdb) - 1);
278 if (which_mapdb == 'm')
281 else if (which_mapdb == 'i')
287 Jdb::abort_command();
290 if (Jdb::is_toplevel_cmd(c))
298 Jdb_module::Action_code
299 Jdb_mapdb::action(int cmd, void *&args, char const *&fmt, int &next_char)
301 static char which_mapdb = 'm';
305 dump_all_cap_trees();
312 if (args == (void*) &subcmd)
327 fmt = " frame: " L4_FRAME_INPUT_FMT;
330 return EXTRA_INPUT_WITH_NEXTCHAR;
333 fmt = " frame: " L4_FRAME_INPUT_FMT;
338 fmt = " port: " L4_FRAME_INPUT_FMT;
343 which_mapdb = subcmd;
348 else if (args != (void*) &pagenum)
352 show(Mapping::Pfn(pagenum), which_mapdb);
357 Jdb_module::Cmd const *
358 Jdb_mapdb::cmds() const
362 { 0, "m", "mapdb", "%c",
363 "m[i]<addr>\tshow [I/O] mapping database starting at address",
365 { 1, "", "dumpmapdbobjs", "",
366 "dumpmapdbobjs\tDump complete object mapping database", 0 },
373 Jdb_mapdb::num_cmds() const
379 Jdb_mapdb::Jdb_mapdb()
383 static Jdb_mapdb jdb_mapdb INIT_PRIORITY(JDB_MODULE_INIT_PRIO);
385 // --------------------------------------------------------------------------
386 // Handler for kobject list
388 class Jdb_kobject_mapdb_hdl : public Jdb_kobject_handler
391 Jdb_kobject_mapdb_hdl() : Jdb_kobject_handler(0) {}
392 virtual bool show_kobject(Kobject_common *, int) { return true; }
393 virtual ~Jdb_kobject_mapdb_hdl() {}
396 PUBLIC static FIASCO_INIT
398 Jdb_kobject_mapdb_hdl::init()
400 static Jdb_kobject_mapdb_hdl hdl;
401 Jdb_kobject::module()->register_handler(&hdl);
406 Jdb_kobject_mapdb_hdl::handle_key(Kobject_common *o, int keycode)
410 Jdb_mapdb::show_simple_tree(o);
420 STATIC_INITIALIZE(Jdb_kobject_mapdb_hdl);
422 #if 0 // keep this for reanimation
425 Jdb_mapdb::dump_all_cap_trees()
427 printf("========= OBJECT DUMP BEGIN ===================\n");
428 Kobject *f = static_cast<Kobject*>(Kobject::_jdb_head.get_unused());
429 for (; f; f = static_cast<Kobject*>(f->_next))
433 Jdb_kobject::obj_description(s, sizeof(s), true, f);
434 s[sizeof(s) - 1] = 0;
437 Mapping_tree *t = f->tree.get();
445 Mapping *m = t->mappings();
448 for (int i = 0; i < t->_count; i++, m++)
450 if (m->depth() == Mapping::Depth_submap)
451 printf("%s[subtree]", i ? "," : "");
454 i ? "," : "", Kobject::pointer_to_id(m->space()),
459 if (m->depth() == Mapping::Depth_submap)
461 printf("not good, submap in simple mapping tree\n");
464 printf("========= OBJECT DUMP END ===================\n");
468 // --------------------------------------------------------------------------
471 #include "dbg_page_info.h"
475 Jdb_mapdb::show_simple_tree(Kobject_common *f, unsigned indent = 1)
480 unsigned screenline = 0;
483 puts(Jdb_screen::Line);
484 if (!f || f->map_root()->_root.empty())
486 printf(" no mapping tree registered for frame number 0x%lx\033[K\n",
489 puts(Jdb_screen::Line);
493 printf(" mapping tree for object D:%lx (%p) ref_cnt=%ld\n",
494 f->dbg_info()->dbg_id(), f, f->map_root()->_cnt);
498 for (Obj::Mapping::List::Iterator m = f->map_root()->_root.begin();
499 m != f->map_root()->_root.end(); ++m)
501 Kconsole::console()->getchar_chance();
503 Obj::Entry *e = static_cast<Obj::Entry*>(*m);
504 Dbg_page_info *pi = Dbg_page_info::table()[Virt_addr(e)];
506 Mword space_id = ~0UL;
507 Address cap_idx = ((Address)e % Config::PAGE_SIZE) / sizeof(Obj::Entry);
511 space_id = static_cast<Task*>(pi->info<Obj::Cap_page_dbg_info>()->s)->dbg_info()->dbg_id();
512 cap_idx += pi->info<Obj::Cap_page_dbg_info>()->offset;
515 printf(" " L4_PTR_FMT "[C:%lx]: space=D:%lx rights=%x flags=%lx obj=%p",
516 (Address)*m, cap_idx, space_id,
517 (unsigned)cxx::int_value<Obj::Attr>(e->rights()), e->_flags,
523 if (screenline >= Jdb_screen::height())
525 printf(" any key for next page or <ESC>");
526 Jdb::cursor(screenline, 33);
527 c = Jdb_core::getchar();
536 puts(Jdb_screen::Line);
542 Jdb_mapdb::dump_all_cap_trees()
544 printf("========= OBJECT DUMP BEGIN ===================\n");
545 printf("========= OBJECT DUMP END ===================\n");