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