3 #include "string_buffer.h"
8 virtual char const *get_mode_str() const { return "[std mode]"; }
9 virtual void next_mode() {}
10 virtual void next_sort() {}
11 virtual void *get_head() const = 0;
12 virtual void show_item(String_buffer *buffer, void *item) const = 0;
13 virtual char const *show_head() const = 0;
14 virtual int seek(int cnt, void **item) = 0;
15 virtual bool enter_item(void * /*item*/) const { return true; }
16 virtual void *follow_link(void *a) { return a; }
17 virtual bool handle_key(void * /*item*/, int /*keycode*/) { return false; }
18 virtual void *parent(void * /*item*/) { return 0; }
19 virtual void *get_valid(void *a) { return a; }
22 typedef String_buf<256> Line_buf;
29 // ---------------------------------------------------------------------------
38 #include "jdb_input.h"
39 #include "jdb_regex.h"
40 #include "jdb_screen.h"
41 #include "kernel_console.h"
50 : _start(0), _current(0)
55 // set _t_start element of list
58 Jdb_list::set_start(void *start)
63 // _t_start-- if possible
67 { return filtered_seek(-1, &_start); }
69 // _t_start++ if possible
74 if (filtered_seek(1, &_last))
75 return filtered_seek(1, &_start);
81 iter(+Jdb_screen::height()-2, &_t_start);
82 iter(-Jdb_screen::height()+3, &_t_start);
87 // _t_start -= 24 if possible
91 { return filtered_seek(-Jdb_screen::height()+2, &_start); }
93 // _t_start += 24 if possible
98 int fwd = filtered_seek(Jdb_screen::height()-2, &_last);
100 return filtered_seek(fwd, &_start);
105 Thread *t = _t_start;
106 iter(+Jdb_screen::height()*2-5, &_t_start);
107 iter(-Jdb_screen::height() +3, &_t_start);
108 return t != _t_start;
112 // _t_start = first element of list
115 Jdb_list::goto_home()
116 { return filtered_seek(-99999, &_start); }
118 // _t_start = last element of list
122 { return filtered_seek(99999, &_start); }
124 Thread *t = _t_start;
125 iter(+9999, &_t_start);
126 iter(-Jdb_screen::height()+2, &_t_start);
127 return t != _t_start;
131 // search index of search starting from _start
134 Jdb_list::lookup_in_visible_area(void *search)
139 for (i = 0, t = _start; i < Jdb_screen::height() - 3; ++i)
144 filtered_seek(1, &t);
150 // get y'th element of thread list starting from _t_start
153 Jdb_list::index(int y)
157 filtered_seek(y, &t);
163 Jdb_list::handle_string_filter_input()
165 Jdb::printf_statline("filter", 0, "%s=%s",
166 Jdb_regex::avail() ? "Regexp" : "Search",
169 Jdb::cursor(Jdb_screen::height(), 16 + strlen(_filter_str));
170 if (!Jdb_input::get_string(_filter_str, sizeof(_filter_str)) ||
175 if (Jdb_regex::avail() && !Jdb_regex::start(_filter_str))
178 Jdb::printf_statline("search", 0, "Error in regexp");
185 Jdb_list::render_visible(void *i)
187 static Line_buf buffer;
190 while ((p = parent(p)))
193 show_item(&buffer, i);
197 if (Jdb_regex::avail())
199 if (!Jdb_regex::find(buffer.begin(), 0, 0))
202 else if (!strstr(buffer.begin(), _filter_str))
214 Jdb_list::show_line(Jdb_list::Line_buf *b)
216 Kconsole::console()->getchar_chance();
218 printf("%.*s\033[K\n",
219 min((int)Jdb_screen::width(), b->length()), b->begin());
224 Jdb_list::get_visible(void *i)
226 if (render_visible(i))
229 filtered_seek(1, &i);
236 Jdb_list::filtered_seek(int cnt, void **item, Jdb_list::Line_buf **buf = 0)
242 int d = cnt < 0 ? -1 : 1;
247 if ((i = seek(d, item)) == 0)
250 if (Line_buf *b = render_visible(*item))
261 // show complete page using show callback function
264 Jdb_list::page_show()
269 if (Jdb_regex::avail() && _filter_str[0])
270 assert(Jdb_regex::start(_filter_str));
275 Line_buf *b = render_visible(t);
277 for (i = 0; i < Jdb_screen::height()-3; ++i)
286 if (!filtered_seek(1, &t, &b))
294 // show complete list using show callback function
297 Jdb_list::complete_show()
301 for (i = 0; ; ++i, seek(1, &t))
313 Jdb_module::Action_code
314 Jdb_thread_list::action(int cmd, void *&argbuf, char const *&fmt, int &)
316 static char const *const cpu_fmt = " cpu=%i\n";
317 static char const *const nfmt = "\n";
320 if (fmt != cpu_fmt && fmt != nfmt)
332 Thread *t = Jdb::get_current_active();
335 case 'r': cpu = 0; list_threads(t, 'r'); break;
336 case 'p': list_threads(t, 'p'); break;
338 if (Cpu::online(cpu))
339 list_threads(Jdb::get_thread(cpu), 'r');
341 printf("\nCPU %u is not online!\n", cpu);
344 case 't': Jdb::execute_command("lt"); break; // other module
349 Console *gzip = Kconsole::console()->find_console(Console::GZIP);
352 Thread *t = Jdb::get_current_active();
353 gzip->state(gzip->state() | Console::OUTENABLED);
355 Jdb_thread_list::init('p', t);
356 Jdb_thread_list::set_start(t);
357 Jdb_thread_list::goto_home();
358 Jdb_thread_list::complete_show(list_threads_show_thread);
360 gzip->state(gzip->state() & ~Console::OUTENABLED);
363 puts(" gzip module not available");
373 Jdb_list::show_header()
376 printf("%.*s\033[K\n", Jdb_screen::width(), show_head());
404 _start = get_visible(_start);
405 // set y to position of t_current in current displayed list
406 y = lookup_in_visible_area(_current);
413 for (bool resync=false; !resync;)
418 // clear rest of screen (if where less than 24 lines)
419 for (unsigned i = y_max; i < Jdb_screen::height()-3; ++i)
422 Jdb::printf_statline("Objs",
423 "<Space>=mode <Tab>=link <CR>=select /=filter",
424 _filter_str[0] ? "%s (%s)" : "%s",
425 get_mode_str(), _filter_str);
428 for (bool redraw=false; !redraw; )
431 switch (int c=Jdb_core::getchar())
438 redraw = line_back();
440 case KEY_CURSOR_DOWN:
445 redraw = line_forw();
449 if (!(redraw = page_back()))
454 if (!(redraw = page_forw()))
457 case KEY_CURSOR_HOME:
459 redraw = goto_home();
467 case 's': // switch sort
473 case ' ': // switch mode
476 _current = get_valid(_current);
477 _start = get_valid(_start);
482 handle_string_filter_input();
483 _current = get_visible(_current);
487 case KEY_TAB: // go to associated object
489 t = follow_link(_current);
499 if (!enter_item(_current))
505 Jdb::abort_command();
509 if (!handle_key(_current, c) && Jdb::is_toplevel_cmd(c))