Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI display registers in window. |
f33c6cbf | 2 | |
42a4f53d | 3 | Copyright (C) 1998-2019 Free Software Foundation, Inc. |
f33c6cbf | 4 | |
f377b406 | 5 | Contributed by Hewlett-Packard Company. |
c906108c | 6 | |
f377b406 | 7 | This file is part of GDB. |
c906108c | 8 | |
f377b406 SC |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
f377b406 SC |
12 | (at your option) any later version. |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
e17c207e | 23 | #include "arch-utils.h" |
d7b2e967 AC |
24 | #include "tui/tui.h" |
25 | #include "tui/tui-data.h" | |
c906108c SS |
26 | #include "symtab.h" |
27 | #include "gdbtypes.h" | |
28 | #include "gdbcmd.h" | |
29 | #include "frame.h" | |
bc77de56 | 30 | #include "regcache.h" |
c906108c SS |
31 | #include "inferior.h" |
32 | #include "target.h" | |
d7b2e967 AC |
33 | #include "tui/tui-layout.h" |
34 | #include "tui/tui-win.h" | |
d7b2e967 AC |
35 | #include "tui/tui-wingeneral.h" |
36 | #include "tui/tui-file.h" | |
2c0b251b | 37 | #include "tui/tui-regs.h" |
312809f8 | 38 | #include "tui/tui-io.h" |
10f59415 | 39 | #include "reggroups.h" |
79a45b7d | 40 | #include "valprint.h" |
51f0e40d | 41 | #include "completer.h" |
c906108c | 42 | |
6a83354a | 43 | #include "gdb_curses.h" |
96ec9981 | 44 | |
41bcff7f | 45 | static void tui_display_register (struct tui_data_item_window *data); |
c906108c | 46 | |
e80cd204 TT |
47 | static void tui_show_register_group (tui_data_window *win_info, |
48 | struct reggroup *group, | |
21e1c91e TT |
49 | struct frame_info *frame, |
50 | int refresh_values_only); | |
5eccfcc2 | 51 | |
1a4f81dd TT |
52 | /* Get the register from the frame and return a printable |
53 | representation of it. */ | |
54 | ||
55 | static char * | |
56 | tui_register_format (struct frame_info *frame, int regnum) | |
57 | { | |
58 | struct gdbarch *gdbarch = get_frame_arch (frame); | |
5eccfcc2 | 59 | |
1a4f81dd TT |
60 | string_file stream; |
61 | ||
62 | scoped_restore save_pagination | |
63 | = make_scoped_restore (&pagination_enabled, 0); | |
64 | scoped_restore save_stdout | |
65 | = make_scoped_restore (&gdb_stdout, &stream); | |
66 | ||
67 | gdbarch_print_registers_info (gdbarch, &stream, frame, regnum, 1); | |
68 | ||
69 | /* Remove the possible \n. */ | |
70 | std::string &str = stream.string (); | |
71 | if (!str.empty () && str.back () == '\n') | |
72 | str.resize (str.size () - 1); | |
73 | ||
74 | /* Expand tabs into spaces, since ncurses on MS-Windows doesn't. */ | |
75 | return tui_expand_tabs (str.c_str (), 0); | |
76 | } | |
77 | ||
78 | /* Get the register value from the given frame and format it for the | |
79 | display. When changep is set, check if the new register value has | |
80 | changed with respect to the previous call. */ | |
81 | static void | |
82 | tui_get_register (struct frame_info *frame, | |
83 | struct tui_data_item_window *data, | |
84 | int regnum, bool *changedp) | |
85 | { | |
86 | if (changedp) | |
87 | *changedp = false; | |
88 | if (target_has_registers) | |
89 | { | |
90 | char *prev_content = data->content; | |
91 | ||
92 | data->content = tui_register_format (frame, regnum); | |
93 | ||
94 | if (changedp != NULL | |
95 | && strcmp (prev_content, data->content) != 0) | |
96 | *changedp = true; | |
97 | ||
98 | xfree (prev_content); | |
99 | } | |
100 | } | |
96bd6233 TT |
101 | |
102 | /* See tui-regs.h. */ | |
103 | ||
104 | tui_data_item_window::~tui_data_item_window () | |
105 | { | |
96bd6233 TT |
106 | xfree (content); |
107 | } | |
108 | ||
18ab23af | 109 | /* See tui-regs.h. */ |
0b5ec218 | 110 | |
c906108c | 111 | int |
0b5ec218 | 112 | tui_data_window::last_regs_line_no () const |
c906108c | 113 | { |
d02c80cd | 114 | int num_lines = (-1); |
c906108c | 115 | |
0b5ec218 | 116 | if (!regs_content.empty ()) |
c906108c | 117 | { |
0b5ec218 TT |
118 | num_lines = regs_content.size () / regs_column_count; |
119 | if (regs_content.size () % regs_column_count) | |
6ba8e26f | 120 | num_lines++; |
c906108c | 121 | } |
6ba8e26f | 122 | return num_lines; |
55fb0713 | 123 | } |
c906108c | 124 | |
18ab23af | 125 | /* See tui-regs.h. */ |
c906108c | 126 | |
c906108c | 127 | int |
3b23c5f2 | 128 | tui_data_window::line_from_reg_element_no (int element_no) const |
c906108c | 129 | { |
3b23c5f2 | 130 | if (element_no < regs_content.size ()) |
c906108c SS |
131 | { |
132 | int i, line = (-1); | |
133 | ||
134 | i = 1; | |
135 | while (line == (-1)) | |
136 | { | |
3b23c5f2 | 137 | if (element_no < regs_column_count * i) |
c906108c SS |
138 | line = i - 1; |
139 | else | |
140 | i++; | |
141 | } | |
142 | ||
143 | return line; | |
144 | } | |
145 | else | |
146 | return (-1); | |
55fb0713 | 147 | } |
c906108c | 148 | |
18ab23af | 149 | /* See tui-regs.h. */ |
c906108c | 150 | |
c906108c | 151 | int |
baff0c28 | 152 | tui_data_window::first_reg_element_no_inline (int line_no) const |
c906108c | 153 | { |
baff0c28 TT |
154 | if (line_no * regs_column_count <= regs_content.size ()) |
155 | return ((line_no + 1) * regs_column_count) - regs_column_count; | |
c906108c SS |
156 | else |
157 | return (-1); | |
55fb0713 | 158 | } |
c906108c | 159 | |
0379b883 TT |
160 | /* A helper function to display the register window in the appropriate |
161 | way. */ | |
162 | ||
163 | static void | |
164 | tui_reg_layout () | |
165 | { | |
166 | enum tui_layout_type cur_layout = tui_current_layout (); | |
167 | enum tui_layout_type new_layout; | |
168 | if (cur_layout == SRC_COMMAND || cur_layout == SRC_DATA_COMMAND) | |
169 | new_layout = SRC_DATA_COMMAND; | |
170 | else | |
171 | new_layout = DISASSEM_DATA_COMMAND; | |
172 | tui_set_layout (new_layout); | |
173 | } | |
c906108c | 174 | |
10f59415 SC |
175 | /* Show the registers of the given group in the data window |
176 | and refresh the window. */ | |
c906108c | 177 | void |
10f59415 | 178 | tui_show_registers (struct reggroup *group) |
c906108c | 179 | { |
0bfbda3b SC |
180 | /* Make sure the curses mode is enabled. */ |
181 | tui_enable (); | |
182 | ||
183 | /* Make sure the register window is visible. If not, select an | |
184 | appropriate layout. */ | |
2d83e710 | 185 | if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->is_visible ()) |
0379b883 | 186 | tui_reg_layout (); |
0bfbda3b | 187 | |
10f59415 SC |
188 | if (group == 0) |
189 | group = general_reggroup; | |
c906108c | 190 | |
1cc6d956 MS |
191 | /* Say that registers should be displayed, even if there is a |
192 | problem. */ | |
ceb13a13 | 193 | TUI_DATA_WIN->display_regs = true; |
10f59415 SC |
194 | |
195 | if (target_has_registers && target_has_stack && target_has_memory) | |
c906108c | 196 | { |
e80cd204 | 197 | tui_show_register_group (TUI_DATA_WIN, group, get_selected_frame (NULL), |
21e1c91e | 198 | group == TUI_DATA_WIN->current_group); |
368c1354 | 199 | |
1cc6d956 | 200 | /* Clear all notation of changed values. */ |
21e1c91e | 201 | for (auto &&data_item_win : TUI_DATA_WIN->regs_content) |
c906108c | 202 | { |
21e1c91e TT |
203 | if (data_item_win != nullptr) |
204 | data_item_win->highlight = false; | |
c906108c | 205 | } |
238eb706 | 206 | TUI_DATA_WIN->current_group = group; |
50daf268 | 207 | TUI_DATA_WIN->display_all_data (); |
c906108c | 208 | } |
368c1354 TT |
209 | else |
210 | { | |
211 | TUI_DATA_WIN->current_group = 0; | |
605dc2c2 | 212 | TUI_DATA_WIN->erase_data_content (_("[ Register Values Unavailable ]")); |
368c1354 | 213 | } |
55fb0713 | 214 | } |
c906108c SS |
215 | |
216 | ||
10f59415 | 217 | /* Set the data window to display the registers of the register group |
1cc6d956 MS |
218 | using the given frame. Values are refreshed only when |
219 | refresh_values_only is TRUE. */ | |
10f59415 | 220 | |
21e1c91e | 221 | static void |
e80cd204 TT |
222 | tui_show_register_group (tui_data_window *win_info, |
223 | struct reggroup *group, | |
08ef48c5 MS |
224 | struct frame_info *frame, |
225 | int refresh_values_only) | |
10f59415 | 226 | { |
5eccfcc2 | 227 | struct gdbarch *gdbarch = get_frame_arch (frame); |
10f59415 | 228 | int nr_regs; |
10f59415 SC |
229 | int regnum, pos; |
230 | char title[80]; | |
10f59415 SC |
231 | |
232 | /* Make a new title showing which group we display. */ | |
233 | snprintf (title, sizeof (title) - 1, "Register group: %s", | |
234 | reggroup_name (group)); | |
e80cd204 TT |
235 | xfree (win_info->title); |
236 | win_info->title = xstrdup (title); | |
10f59415 SC |
237 | |
238 | /* See how many registers must be displayed. */ | |
239 | nr_regs = 0; | |
f6efe3f8 | 240 | for (regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++) |
10f59415 | 241 | { |
d20c1c3f PA |
242 | const char *name; |
243 | ||
244 | /* Must be in the group. */ | |
245 | if (!gdbarch_register_reggroup_p (gdbarch, regnum, group)) | |
246 | continue; | |
247 | ||
248 | /* If the register name is empty, it is undefined for this | |
249 | processor, so don't display anything. */ | |
250 | name = gdbarch_register_name (gdbarch, regnum); | |
251 | if (name == 0 || *name == '\0') | |
252 | continue; | |
253 | ||
254 | nr_regs++; | |
10f59415 SC |
255 | } |
256 | ||
21e1c91e | 257 | if (!refresh_values_only) |
e80cd204 | 258 | win_info->regs_content.clear (); |
10f59415 | 259 | |
e80cd204 TT |
260 | if (nr_regs < win_info->regs_content.size ()) |
261 | win_info->regs_content.resize (nr_regs); | |
21e1c91e | 262 | else |
10f59415 | 263 | { |
e80cd204 TT |
264 | for (int i = win_info->regs_content.size (); i < nr_regs; ++i) |
265 | win_info->regs_content.emplace_back (new tui_data_item_window ()); | |
10f59415 SC |
266 | } |
267 | ||
21e1c91e TT |
268 | /* Now set the register names and values. */ |
269 | pos = 0; | |
270 | for (regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++) | |
10f59415 | 271 | { |
21e1c91e TT |
272 | struct tui_data_item_window *data_item_win; |
273 | const char *name; | |
10f59415 | 274 | |
21e1c91e TT |
275 | /* Must be in the group. */ |
276 | if (!gdbarch_register_reggroup_p (gdbarch, regnum, group)) | |
277 | continue; | |
10f59415 | 278 | |
21e1c91e TT |
279 | /* If the register name is empty, it is undefined for this |
280 | processor, so don't display anything. */ | |
281 | name = gdbarch_register_name (gdbarch, regnum); | |
282 | if (name == 0 || *name == '\0') | |
283 | continue; | |
10f59415 | 284 | |
e80cd204 | 285 | data_item_win = win_info->regs_content[pos].get (); |
21e1c91e TT |
286 | if (data_item_win) |
287 | { | |
288 | if (!refresh_values_only) | |
289 | { | |
290 | data_item_win->item_no = regnum; | |
291 | data_item_win->name = name; | |
292 | data_item_win->highlight = false; | |
293 | } | |
294 | tui_get_register (frame, data_item_win, regnum, 0); | |
295 | } | |
296 | pos++; | |
297 | } | |
10f59415 SC |
298 | } |
299 | ||
18ab23af | 300 | /* See tui-regs.h. */ |
517e9505 | 301 | |
c906108c | 302 | void |
517e9505 | 303 | tui_data_window::display_registers_from (int start_element_no) |
c906108c | 304 | { |
517e9505 | 305 | if (!regs_content.empty ()) |
c906108c | 306 | { |
0043e6a5 | 307 | int j, item_win_width, cur_y; |
10f59415 SC |
308 | |
309 | int max_len = 0; | |
517e9505 | 310 | for (auto &&data_item_win : regs_content) |
10f59415 | 311 | { |
10f59415 SC |
312 | char *p; |
313 | int len; | |
314 | ||
10f59415 | 315 | len = 0; |
41bcff7f | 316 | p = data_item_win->content; |
10f59415 SC |
317 | if (p != 0) |
318 | while (*p) | |
319 | { | |
320 | if (*p++ == '\t') | |
321 | len = 8 * ((len / 8) + 1); | |
322 | else | |
323 | len++; | |
324 | } | |
325 | ||
326 | if (len > max_len) | |
327 | max_len = len; | |
328 | } | |
329 | item_win_width = max_len + 1; | |
21e1c91e | 330 | int i = start_element_no; |
10f59415 | 331 | |
517e9505 TT |
332 | regs_column_count = (width - 2) / item_win_width; |
333 | if (regs_column_count == 0) | |
334 | regs_column_count = 1; | |
335 | item_win_width = (width - 2) / regs_column_count; | |
10f59415 | 336 | |
ef5eab5a MS |
337 | /* Now create each data "sub" window, and write the display into |
338 | it. */ | |
6ba8e26f | 339 | cur_y = 1; |
517e9505 TT |
340 | while (i < regs_content.size () |
341 | && cur_y <= viewport_height) | |
c906108c SS |
342 | { |
343 | for (j = 0; | |
517e9505 | 344 | j < regs_column_count && i < regs_content.size (); |
e5908723 | 345 | j++) |
c906108c | 346 | { |
41bcff7f | 347 | struct tui_data_item_window *data_item_win; |
c906108c | 348 | |
1cc6d956 | 349 | /* Create the window if necessary. */ |
517e9505 | 350 | data_item_win = regs_content[i].get (); |
cafb3438 | 351 | if (data_item_win->handle != NULL |
10f59415 SC |
352 | && (data_item_win->height != 1 |
353 | || data_item_win->width != item_win_width | |
354 | || data_item_win->origin.x != (item_win_width * j) + 1 | |
355 | || data_item_win->origin.y != cur_y)) | |
356 | { | |
357 | tui_delete_win (data_item_win->handle); | |
358 | data_item_win->handle = 0; | |
359 | } | |
360 | ||
cafb3438 | 361 | if (data_item_win->handle == NULL) |
c906108c | 362 | { |
6ba8e26f | 363 | data_item_win->height = 1; |
10f59415 | 364 | data_item_win->width = item_win_width; |
6ba8e26f AC |
365 | data_item_win->origin.x = (item_win_width * j) + 1; |
366 | data_item_win->origin.y = cur_y; | |
65962b20 | 367 | tui_make_window (data_item_win); |
6ba8e26f | 368 | scrollok (data_item_win->handle, FALSE); |
c906108c | 369 | } |
6ba8e26f | 370 | touchwin (data_item_win->handle); |
fea14702 | 371 | |
10f59415 SC |
372 | /* Get the printable representation of the register |
373 | and display it. */ | |
41bcff7f | 374 | tui_display_register (data_item_win); |
1cc6d956 | 375 | i++; /* Next register. */ |
c906108c | 376 | } |
1cc6d956 | 377 | cur_y++; /* Next row. */ |
c906108c SS |
378 | } |
379 | } | |
55fb0713 | 380 | } |
c906108c | 381 | |
18ab23af | 382 | /* See tui-regs.h. */ |
c906108c | 383 | |
aca2dd16 TT |
384 | void |
385 | tui_data_window::display_reg_element_at_line (int start_element_no, | |
386 | int start_line_no) | |
c906108c | 387 | { |
aca2dd16 | 388 | if (!regs_content.empty ()) |
c906108c | 389 | { |
d02c80cd | 390 | int element_no = start_element_no; |
c906108c | 391 | |
6ba8e26f | 392 | if (start_element_no != 0 && start_line_no != 0) |
c906108c | 393 | { |
d02c80cd | 394 | int last_line_no, first_line_on_last_page; |
c906108c | 395 | |
aca2dd16 TT |
396 | last_line_no = last_regs_line_no (); |
397 | first_line_on_last_page = last_line_no - (height - 2); | |
6ba8e26f AC |
398 | if (first_line_on_last_page < 0) |
399 | first_line_on_last_page = 0; | |
ef5eab5a | 400 | |
115ac53b | 401 | /* If the element_no causes us to scroll past the end of the |
ef5eab5a MS |
402 | registers, adjust what element to really start the |
403 | display at. */ | |
115ac53b | 404 | if (start_line_no > first_line_on_last_page) |
aca2dd16 | 405 | element_no = first_reg_element_no_inline (first_line_on_last_page); |
c906108c | 406 | } |
aca2dd16 | 407 | display_registers_from (element_no); |
c906108c | 408 | } |
6ba8e26f | 409 | } |
c906108c | 410 | |
18ab23af | 411 | /* See tui-regs.h. */ |
c906108c | 412 | |
c906108c | 413 | int |
517e9505 | 414 | tui_data_window::display_registers_from_line (int line_no) |
c906108c | 415 | { |
b4ef5aeb | 416 | check_and_display_highlight_if_needed (); |
517e9505 | 417 | if (!regs_content.empty ()) |
c906108c | 418 | { |
80cb6c27 | 419 | int element_no; |
c906108c | 420 | |
6ba8e26f | 421 | if (line_no < 0) |
80cb6c27 TT |
422 | line_no = 0; |
423 | else | |
424 | { | |
425 | /* Make sure that we don't display off the end of the | |
ef5eab5a | 426 | registers. */ |
517e9505 | 427 | if (line_no >= last_regs_line_no ()) |
c906108c | 428 | { |
517e9505 TT |
429 | line_no = line_from_reg_element_no (regs_content.size () - 1); |
430 | if (line_no < 0) | |
80cb6c27 | 431 | line_no = 0; |
c906108c | 432 | } |
c906108c | 433 | } |
c906108c | 434 | |
517e9505 TT |
435 | element_no = first_reg_element_no_inline (line_no); |
436 | if (element_no < regs_content.size ()) | |
aca2dd16 | 437 | display_reg_element_at_line (element_no, line_no); |
c906108c | 438 | else |
80cb6c27 | 439 | line_no = (-1); |
c906108c | 440 | |
80cb6c27 | 441 | return line_no; |
c906108c SS |
442 | } |
443 | ||
1cc6d956 | 444 | return (-1); /* Nothing was displayed. */ |
55fb0713 | 445 | } |
c906108c SS |
446 | |
447 | ||
18ab23af TT |
448 | /* Answer the index first element displayed. If none are displayed, |
449 | then return (-1). */ | |
450 | int | |
451 | tui_data_window::first_data_item_displayed () | |
452 | { | |
453 | for (int i = 0; i < regs_content.size (); i++) | |
454 | { | |
455 | struct tui_gen_win_info *data_item_win; | |
456 | ||
457 | data_item_win = regs_content[i].get (); | |
2d83e710 | 458 | if (data_item_win->is_visible ()) |
18ab23af TT |
459 | return i; |
460 | } | |
461 | ||
462 | return -1; | |
463 | } | |
464 | ||
465 | /* See tui-regs.h. */ | |
466 | ||
467 | void | |
468 | tui_data_window::delete_data_content_windows () | |
469 | { | |
470 | for (auto &&win : regs_content) | |
471 | { | |
472 | tui_delete_win (win->handle); | |
473 | win->handle = NULL; | |
18ab23af TT |
474 | } |
475 | } | |
476 | ||
477 | ||
478 | void | |
479 | tui_data_window::erase_data_content (const char *prompt) | |
480 | { | |
481 | werase (handle); | |
b4ef5aeb | 482 | check_and_display_highlight_if_needed (); |
18ab23af TT |
483 | if (prompt != NULL) |
484 | { | |
485 | int half_width = (width - 2) / 2; | |
486 | int x_pos; | |
487 | ||
488 | if (strlen (prompt) >= half_width) | |
489 | x_pos = 1; | |
490 | else | |
491 | x_pos = half_width - strlen (prompt); | |
492 | mvwaddstr (handle, (height / 2), x_pos, (char *) prompt); | |
493 | } | |
494 | wrefresh (handle); | |
495 | } | |
496 | ||
497 | /* See tui-regs.h. */ | |
498 | ||
499 | void | |
500 | tui_data_window::display_all_data () | |
501 | { | |
502 | if (regs_content.empty ()) | |
503 | erase_data_content (NO_DATA_STRING); | |
504 | else | |
505 | { | |
506 | erase_data_content (NULL); | |
507 | delete_data_content_windows (); | |
b4ef5aeb | 508 | check_and_display_highlight_if_needed (); |
18ab23af TT |
509 | display_registers_from (0); |
510 | } | |
511 | } | |
512 | ||
513 | ||
514 | /* Function to redisplay the contents of the data window. */ | |
515 | void | |
516 | tui_data_window::refresh_all () | |
517 | { | |
518 | erase_data_content (NULL); | |
519 | if (!regs_content.empty ()) | |
520 | { | |
521 | int first_element = first_data_item_displayed (); | |
522 | ||
523 | if (first_element >= 0) /* Re-use existing windows. */ | |
524 | { | |
525 | int first_line = (-1); | |
526 | ||
527 | if (first_element < regs_content.size ()) | |
528 | first_line = line_from_reg_element_no (first_element); | |
529 | ||
530 | if (first_line >= 0) | |
531 | { | |
532 | erase_data_content (NULL); | |
533 | display_registers_from_line (first_line); | |
534 | } | |
535 | } | |
536 | } | |
537 | } | |
538 | ||
539 | ||
540 | /* Scroll the data window vertically forward or backward. */ | |
541 | void | |
542 | tui_data_window::do_scroll_vertical (int num_to_scroll) | |
543 | { | |
544 | int first_element_no; | |
545 | int first_line = (-1); | |
546 | ||
547 | first_element_no = first_data_item_displayed (); | |
548 | if (first_element_no < regs_content.size ()) | |
549 | first_line = line_from_reg_element_no (first_element_no); | |
550 | else | |
551 | { /* Calculate the first line from the element number which is in | |
552 | the general data content. */ | |
553 | } | |
554 | ||
555 | if (first_line >= 0) | |
556 | { | |
557 | first_line += num_to_scroll; | |
558 | erase_data_content (NULL); | |
559 | delete_data_content_windows (); | |
560 | display_registers_from_line (first_line); | |
561 | } | |
562 | } | |
563 | ||
564 | /* See tui-regs.h. */ | |
565 | ||
18ab23af | 566 | void |
3df505f6 | 567 | tui_data_window::rerender () |
18ab23af TT |
568 | { |
569 | /* Delete all data item windows. */ | |
570 | for (auto &&win : regs_content) | |
571 | { | |
572 | tui_delete_win (win->handle); | |
573 | win->handle = NULL; | |
574 | } | |
18ab23af TT |
575 | display_all_data (); |
576 | } | |
577 | ||
578 | /* See tui-regs.h. */ | |
579 | ||
580 | void | |
581 | tui_data_window::refresh_window () | |
582 | { | |
583 | tui_gen_win_info::refresh_window (); | |
584 | for (auto &&win : regs_content) | |
585 | { | |
586 | if (win != NULL) | |
587 | win->refresh_window (); | |
588 | } | |
589 | } | |
590 | ||
55fb0713 AC |
591 | /* This function check all displayed registers for changes in values, |
592 | given a particular frame. If the values have changed, they are | |
593 | updated with the new value and highlighted. */ | |
c906108c | 594 | void |
55fb0713 | 595 | tui_check_register_values (struct frame_info *frame) |
c906108c | 596 | { |
e5908723 | 597 | if (TUI_DATA_WIN != NULL |
2d83e710 | 598 | && TUI_DATA_WIN->is_visible ()) |
c906108c | 599 | { |
21e1c91e | 600 | if (TUI_DATA_WIN->regs_content.empty () |
238eb706 TT |
601 | && TUI_DATA_WIN->display_regs) |
602 | tui_show_registers (TUI_DATA_WIN->current_group); | |
c906108c SS |
603 | else |
604 | { | |
21e1c91e | 605 | for (auto &&data_item_win_ptr : TUI_DATA_WIN->regs_content) |
c906108c | 606 | { |
6ba8e26f | 607 | int was_hilighted; |
c906108c | 608 | |
41bcff7f | 609 | was_hilighted = data_item_win_ptr->highlight; |
10f59415 | 610 | |
21e1c91e | 611 | tui_get_register (frame, data_item_win_ptr.get (), |
41bcff7f TT |
612 | data_item_win_ptr->item_no, |
613 | &data_item_win_ptr->highlight); | |
10f59415 | 614 | |
41bcff7f | 615 | if (data_item_win_ptr->highlight || was_hilighted) |
21e1c91e | 616 | tui_display_register (data_item_win_ptr.get ()); |
c906108c SS |
617 | } |
618 | } | |
619 | } | |
55fb0713 | 620 | } |
c906108c | 621 | |
1cc6d956 MS |
622 | /* Display a register in a window. If hilite is TRUE, then the value |
623 | will be displayed in reverse video. */ | |
10f59415 | 624 | static void |
41bcff7f | 625 | tui_display_register (struct tui_data_item_window *data) |
10f59415 | 626 | { |
41bcff7f | 627 | if (data->handle != NULL) |
10f59415 SC |
628 | { |
629 | int i; | |
c906108c | 630 | |
10f59415 | 631 | if (data->highlight) |
cae3f17b JB |
632 | /* We ignore the return value, casting it to void in order to avoid |
633 | a compiler warning. The warning itself was introduced by a patch | |
634 | to ncurses 5.7 dated 2009-08-29, changing this macro to expand | |
635 | to code that causes the compiler to generate an unused-value | |
636 | warning. */ | |
41bcff7f | 637 | (void) wstandout (data->handle); |
10f59415 | 638 | |
41bcff7f TT |
639 | wmove (data->handle, 0, 0); |
640 | for (i = 1; i < data->width; i++) | |
641 | waddch (data->handle, ' '); | |
642 | wmove (data->handle, 0, 0); | |
10f59415 | 643 | if (data->content) |
41bcff7f | 644 | waddstr (data->handle, data->content); |
10f59415 SC |
645 | |
646 | if (data->highlight) | |
cae3f17b JB |
647 | /* We ignore the return value, casting it to void in order to avoid |
648 | a compiler warning. The warning itself was introduced by a patch | |
649 | to ncurses 5.7 dated 2009-08-29, changing this macro to expand | |
650 | to code that causes the compiler to generate an unused-value | |
651 | warning. */ | |
41bcff7f TT |
652 | (void) wstandend (data->handle); |
653 | data->refresh_window (); | |
10f59415 SC |
654 | } |
655 | } | |
656 | ||
51f0e40d AB |
657 | /* Helper for "tui reg next", wraps a call to REGGROUP_NEXT, but adds wrap |
658 | around behaviour. Returns the next register group, or NULL if the | |
659 | register window is not currently being displayed. */ | |
660 | ||
661 | static struct reggroup * | |
fe3eaf1c | 662 | tui_reg_next (struct reggroup *current_group, struct gdbarch *gdbarch) |
c906108c | 663 | { |
51f0e40d | 664 | struct reggroup *group = NULL; |
e17c207e | 665 | |
fe3eaf1c | 666 | if (current_group != NULL) |
10f59415 | 667 | { |
fe3eaf1c | 668 | group = reggroup_next (gdbarch, current_group); |
b75c69bb AB |
669 | if (group == NULL) |
670 | group = reggroup_next (gdbarch, NULL); | |
10f59415 | 671 | } |
51f0e40d | 672 | return group; |
10f59415 SC |
673 | } |
674 | ||
51f0e40d AB |
675 | /* Helper for "tui reg prev", wraps a call to REGGROUP_PREV, but adds wrap |
676 | around behaviour. Returns the previous register group, or NULL if the | |
677 | register window is not currently being displayed. */ | |
55b40027 | 678 | |
51f0e40d | 679 | static struct reggroup * |
fe3eaf1c | 680 | tui_reg_prev (struct reggroup *current_group, struct gdbarch *gdbarch) |
55b40027 | 681 | { |
51f0e40d | 682 | struct reggroup *group = NULL; |
55b40027 | 683 | |
fe3eaf1c | 684 | if (current_group != NULL) |
55b40027 | 685 | { |
fe3eaf1c | 686 | group = reggroup_prev (gdbarch, current_group); |
55b40027 AB |
687 | if (group == NULL) |
688 | group = reggroup_prev (gdbarch, NULL); | |
55b40027 | 689 | } |
51f0e40d | 690 | return group; |
55b40027 AB |
691 | } |
692 | ||
51f0e40d AB |
693 | /* Implement the 'tui reg' command. Changes the register group displayed |
694 | in the tui register window. Displays the tui register window if it is | |
695 | not already on display. */ | |
c906108c | 696 | |
10f59415 | 697 | static void |
e2d8ae16 | 698 | tui_reg_command (const char *args, int from_tty) |
10f59415 | 699 | { |
51f0e40d | 700 | struct gdbarch *gdbarch = get_current_arch (); |
c906108c | 701 | |
51f0e40d AB |
702 | if (args != NULL) |
703 | { | |
704 | struct reggroup *group, *match = NULL; | |
705 | size_t len = strlen (args); | |
706 | ||
707 | /* Make sure the curses mode is enabled. */ | |
708 | tui_enable (); | |
709 | ||
710 | /* Make sure the register window is visible. If not, select an | |
711 | appropriate layout. We need to do this before trying to run the | |
712 | 'next' or 'prev' commands. */ | |
2d83e710 | 713 | if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->is_visible ()) |
0379b883 | 714 | tui_reg_layout (); |
51f0e40d | 715 | |
0f8d8876 | 716 | struct reggroup *current_group = TUI_DATA_WIN->current_group; |
51f0e40d | 717 | if (strncmp (args, "next", len) == 0) |
fe3eaf1c | 718 | match = tui_reg_next (current_group, gdbarch); |
51f0e40d | 719 | else if (strncmp (args, "prev", len) == 0) |
fe3eaf1c | 720 | match = tui_reg_prev (current_group, gdbarch); |
51f0e40d AB |
721 | |
722 | /* This loop matches on the initial part of a register group | |
723 | name. If this initial part in ARGS matches only one register | |
724 | group then the switch is made. */ | |
725 | for (group = reggroup_next (gdbarch, NULL); | |
726 | group != NULL; | |
727 | group = reggroup_next (gdbarch, group)) | |
728 | { | |
729 | if (strncmp (reggroup_name (group), args, len) == 0) | |
730 | { | |
731 | if (match != NULL) | |
732 | error (_("ambiguous register group name '%s'"), args); | |
733 | match = group; | |
734 | } | |
735 | } | |
736 | ||
737 | if (match == NULL) | |
738 | error (_("unknown register group '%s'"), args); | |
739 | ||
740 | tui_show_registers (match); | |
741 | } | |
742 | else | |
743 | { | |
744 | struct reggroup *group; | |
745 | int first; | |
746 | ||
747 | printf_unfiltered (_("\"tui reg\" must be followed by the name of " | |
748 | "either a register group,\nor one of 'next' " | |
749 | "or 'prev'. Known register groups are:\n")); | |
750 | ||
751 | for (first = 1, group = reggroup_next (gdbarch, NULL); | |
752 | group != NULL; | |
753 | first = 0, group = reggroup_next (gdbarch, group)) | |
754 | { | |
755 | if (!first) | |
756 | printf_unfiltered (", "); | |
757 | printf_unfiltered ("%s", reggroup_name (group)); | |
758 | } | |
759 | ||
760 | printf_unfiltered ("\n"); | |
761 | } | |
10f59415 SC |
762 | } |
763 | ||
51f0e40d AB |
764 | /* Complete names of register groups, and add the special "prev" and "next" |
765 | names. */ | |
c906108c | 766 | |
eb3ff9a5 | 767 | static void |
51f0e40d | 768 | tui_reggroup_completer (struct cmd_list_element *ignore, |
eb3ff9a5 | 769 | completion_tracker &tracker, |
51f0e40d | 770 | const char *text, const char *word) |
10f59415 | 771 | { |
51f0e40d AB |
772 | static const char *extra[] = { "next", "prev", NULL }; |
773 | size_t len = strlen (word); | |
774 | const char **tmp; | |
775 | ||
eb3ff9a5 | 776 | reggroup_completer (ignore, tracker, text, word); |
51f0e40d | 777 | |
eb3ff9a5 | 778 | /* XXXX use complete_on_enum instead? */ |
51f0e40d AB |
779 | for (tmp = extra; *tmp != NULL; ++tmp) |
780 | { | |
781 | if (strncmp (word, *tmp, len) == 0) | |
b02f78f9 | 782 | tracker.add_completion (make_unique_xstrdup (*tmp)); |
51f0e40d | 783 | } |
10f59415 | 784 | } |
c906108c | 785 | |
18ab23af TT |
786 | void |
787 | _initialize_tui_regs (void) | |
788 | { | |
789 | struct cmd_list_element **tuicmd, *cmd; | |
790 | ||
791 | tuicmd = tui_get_cmd_list (); | |
792 | ||
793 | cmd = add_cmd ("reg", class_tui, tui_reg_command, _("\ | |
794 | TUI command to control the register window."), tuicmd); | |
795 | set_cmd_completer (cmd, tui_reggroup_completer); | |
796 | } |