Make sure TABs are expanded in TUI windows on MS-Windows.
[deliverable/binutils-gdb.git] / gdb / tui / tui-regs.c
CommitLineData
f377b406 1/* TUI display registers in window.
f33c6cbf 2
32d0add0 3 Copyright (C) 1998-2015 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"
35#include "tui/tui-windata.h"
36#include "tui/tui-wingeneral.h"
37#include "tui/tui-file.h"
2c0b251b 38#include "tui/tui-regs.h"
312809f8 39#include "tui/tui-io.h"
10f59415 40#include "reggroups.h"
79a45b7d 41#include "valprint.h"
c906108c 42
6a83354a 43#include "gdb_curses.h"
96ec9981 44
c906108c
SS
45
46/*****************************************
10f59415 47** STATIC LOCAL FUNCTIONS FORWARD DECLS **
c906108c 48******************************************/
10f59415
SC
49static void
50tui_display_register (struct tui_data_element *data,
51 struct tui_gen_win_info *win_info);
c906108c 52
5eccfcc2
UW
53static enum tui_status tui_show_register_group (struct reggroup *group,
54 struct frame_info *frame,
55 int refresh_values_only);
56
57static enum tui_status tui_get_register (struct frame_info *frame,
58 struct tui_data_element *data,
59 int regnum, int *changedp);
60
6ba8e26f
AC
61static void tui_scroll_regs_forward_command (char *, int);
62static void tui_scroll_regs_backward_command (char *, int);
c906108c
SS
63
64
65
66/*****************************************
67** PUBLIC FUNCTIONS **
68******************************************/
69
55fb0713
AC
70/* Answer the number of the last line in the regs display. If there
71 are no registers (-1) is returned. */
c906108c 72int
55fb0713 73tui_last_regs_line_no (void)
c906108c 74{
d02c80cd 75 int num_lines = (-1);
c906108c 76
6d012f14 77 if (TUI_DATA_WIN->detail.data_display_info.regs_content_count > 0)
c906108c 78 {
6ba8e26f 79 num_lines = (TUI_DATA_WIN->detail.data_display_info.regs_content_count /
6d012f14
AC
80 TUI_DATA_WIN->detail.data_display_info.regs_column_count);
81 if (TUI_DATA_WIN->detail.data_display_info.regs_content_count %
82 TUI_DATA_WIN->detail.data_display_info.regs_column_count)
6ba8e26f 83 num_lines++;
c906108c 84 }
6ba8e26f 85 return num_lines;
55fb0713 86}
c906108c
SS
87
88
6ba8e26f
AC
89/* Answer the line number that the register element at element_no is
90 on. If element_no is greater than the number of register elements
55fb0713 91 there are, -1 is returned. */
c906108c 92int
6ba8e26f 93tui_line_from_reg_element_no (int element_no)
c906108c 94{
6ba8e26f 95 if (element_no < TUI_DATA_WIN->detail.data_display_info.regs_content_count)
c906108c
SS
96 {
97 int i, line = (-1);
98
99 i = 1;
100 while (line == (-1))
101 {
6ba8e26f 102 if (element_no <
6d012f14 103 (TUI_DATA_WIN->detail.data_display_info.regs_column_count * i))
c906108c
SS
104 line = i - 1;
105 else
106 i++;
107 }
108
109 return line;
110 }
111 else
112 return (-1);
55fb0713 113}
c906108c
SS
114
115
1cc6d956
MS
116/* Answer the index of the first element in line_no. If line_no is
117 past the register area (-1) is returned. */
c906108c 118int
6ba8e26f 119tui_first_reg_element_no_inline (int line_no)
c906108c 120{
6ba8e26f 121 if ((line_no * TUI_DATA_WIN->detail.data_display_info.regs_column_count)
6d012f14 122 <= TUI_DATA_WIN->detail.data_display_info.regs_content_count)
6ba8e26f 123 return ((line_no + 1) *
6d012f14
AC
124 TUI_DATA_WIN->detail.data_display_info.regs_column_count) -
125 TUI_DATA_WIN->detail.data_display_info.regs_column_count;
c906108c
SS
126 else
127 return (-1);
55fb0713 128}
c906108c
SS
129
130
10f59415
SC
131/* Show the registers of the given group in the data window
132 and refresh the window. */
c906108c 133void
10f59415 134tui_show_registers (struct reggroup *group)
c906108c 135{
22940a24 136 enum tui_status ret = TUI_FAILURE;
0bfbda3b 137 struct tui_data_info *display_info;
c906108c 138
0bfbda3b
SC
139 /* Make sure the curses mode is enabled. */
140 tui_enable ();
141
142 /* Make sure the register window is visible. If not, select an
143 appropriate layout. */
144 if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->generic.is_visible)
145 tui_set_layout_for_display_command (DATA_NAME);
146
147 display_info = &TUI_DATA_WIN->detail.data_display_info;
10f59415
SC
148 if (group == 0)
149 group = general_reggroup;
c906108c 150
1cc6d956
MS
151 /* Say that registers should be displayed, even if there is a
152 problem. */
10f59415
SC
153 display_info->display_regs = TRUE;
154
155 if (target_has_registers && target_has_stack && target_has_memory)
c906108c 156 {
8eb6bda2 157 ret = tui_show_register_group (group, get_selected_frame (NULL),
10f59415 158 group == display_info->current_group);
c906108c
SS
159 }
160 if (ret == TUI_FAILURE)
161 {
10f59415 162 display_info->current_group = 0;
edae1ccf 163 tui_erase_data_content (NO_REGS_STRING);
c906108c
SS
164 }
165 else
166 {
167 int i;
168
1cc6d956 169 /* Clear all notation of changed values. */
10f59415 170 for (i = 0; i < display_info->regs_content_count; i++)
c906108c 171 {
10f59415
SC
172 struct tui_gen_win_info *data_item_win;
173 struct tui_win_element *win;
c906108c 174
10f59415
SC
175 data_item_win = &display_info->regs_content[i]
176 ->which_element.data_window;
177 win = (struct tui_win_element *) data_item_win->content[0];
178 win->which_element.data.highlight = FALSE;
c906108c 179 }
10f59415 180 display_info->current_group = group;
edae1ccf 181 tui_display_all_data ();
c906108c 182 }
55fb0713 183}
c906108c
SS
184
185
10f59415 186/* Set the data window to display the registers of the register group
1cc6d956
MS
187 using the given frame. Values are refreshed only when
188 refresh_values_only is TRUE. */
10f59415
SC
189
190static enum tui_status
5eccfcc2 191tui_show_register_group (struct reggroup *group,
08ef48c5
MS
192 struct frame_info *frame,
193 int refresh_values_only)
10f59415 194{
5eccfcc2 195 struct gdbarch *gdbarch = get_frame_arch (frame);
10f59415
SC
196 enum tui_status ret = TUI_FAILURE;
197 int nr_regs;
198 int allocated_here = FALSE;
199 int regnum, pos;
200 char title[80];
201 struct tui_data_info *display_info = &TUI_DATA_WIN->detail.data_display_info;
202
203 /* Make a new title showing which group we display. */
204 snprintf (title, sizeof (title) - 1, "Register group: %s",
205 reggroup_name (group));
206 xfree (TUI_DATA_WIN->generic.title);
207 TUI_DATA_WIN->generic.title = xstrdup (title);
208
209 /* See how many registers must be displayed. */
210 nr_regs = 0;
f57d151a 211 for (regnum = 0;
5eccfcc2
UW
212 regnum < gdbarch_num_regs (gdbarch)
213 + gdbarch_num_pseudo_regs (gdbarch);
f57d151a 214 regnum++)
10f59415 215 {
d20c1c3f
PA
216 const char *name;
217
218 /* Must be in the group. */
219 if (!gdbarch_register_reggroup_p (gdbarch, regnum, group))
220 continue;
221
222 /* If the register name is empty, it is undefined for this
223 processor, so don't display anything. */
224 name = gdbarch_register_name (gdbarch, regnum);
225 if (name == 0 || *name == '\0')
226 continue;
227
228 nr_regs++;
10f59415
SC
229 }
230
231 if (display_info->regs_content_count > 0 && !refresh_values_only)
232 {
233 tui_free_data_content (display_info->regs_content,
234 display_info->regs_content_count);
235 display_info->regs_content_count = 0;
236 }
237
238 if (display_info->regs_content_count <= 0)
239 {
240 display_info->regs_content = tui_alloc_content (nr_regs, DATA_WIN);
241 allocated_here = TRUE;
242 refresh_values_only = FALSE;
243 }
244
245 if (display_info->regs_content != (tui_win_content) NULL)
246 {
247 if (!refresh_values_only || allocated_here)
248 {
249 TUI_DATA_WIN->generic.content = (void*) NULL;
250 TUI_DATA_WIN->generic.content_size = 0;
251 tui_add_content_elements (&TUI_DATA_WIN->generic, nr_regs);
252 display_info->regs_content
253 = (tui_win_content) TUI_DATA_WIN->generic.content;
254 display_info->regs_content_count = nr_regs;
255 }
256
1cc6d956 257 /* Now set the register names and values. */
10f59415 258 pos = 0;
f57d151a 259 for (regnum = 0;
5eccfcc2
UW
260 regnum < gdbarch_num_regs (gdbarch)
261 + gdbarch_num_pseudo_regs (gdbarch);
f57d151a 262 regnum++)
10f59415
SC
263 {
264 struct tui_gen_win_info *data_item_win;
265 struct tui_data_element *data;
266 const char *name;
267
d20c1c3f 268 /* Must be in the group. */
10f59415
SC
269 if (!gdbarch_register_reggroup_p (gdbarch, regnum, group))
270 continue;
271
d20c1c3f
PA
272 /* If the register name is empty, it is undefined for this
273 processor, so don't display anything. */
274 name = gdbarch_register_name (gdbarch, regnum);
275 if (name == 0 || *name == '\0')
276 continue;
10f59415
SC
277
278 data_item_win =
279 &display_info->regs_content[pos]->which_element.data_window;
9a2b4c1b
MS
280 data = &((struct tui_win_element *)
281 data_item_win->content[0])->which_element.data;
10f59415
SC
282 if (data)
283 {
284 if (!refresh_values_only)
285 {
286 data->item_no = regnum;
287 data->name = name;
288 data->highlight = FALSE;
289 }
5eccfcc2 290 tui_get_register (frame, data, regnum, 0);
10f59415
SC
291 }
292 pos++;
293 }
294
295 TUI_DATA_WIN->generic.content_size =
296 display_info->regs_content_count + display_info->data_content_count;
297 ret = TUI_SUCCESS;
298 }
299
300 return ret;
301}
302
55fb0713 303/* Function to display the registers in the content from
6ba8e26f 304 'start_element_no' until the end of the register content or the end
55fb0713
AC
305 of the display height. No checking for displaying past the end of
306 the registers is done here. */
c906108c 307void
6ba8e26f 308tui_display_registers_from (int start_element_no)
c906108c 309{
10f59415
SC
310 struct tui_data_info *display_info = &TUI_DATA_WIN->detail.data_display_info;
311
e5908723
MS
312 if (display_info->regs_content != (tui_win_content) NULL
313 && display_info->regs_content_count > 0)
c906108c 314 {
d02c80cd 315 int i = start_element_no;
0043e6a5 316 int j, item_win_width, cur_y;
10f59415
SC
317
318 int max_len = 0;
319 for (i = 0; i < display_info->regs_content_count; i++)
320 {
321 struct tui_data_element *data;
322 struct tui_gen_win_info *data_item_win;
323 char *p;
324 int len;
325
9a2b4c1b
MS
326 data_item_win
327 = &display_info->regs_content[i]->which_element.data_window;
10f59415
SC
328 data = &((struct tui_win_element *)
329 data_item_win->content[0])->which_element.data;
330 len = 0;
331 p = data->content;
332 if (p != 0)
333 while (*p)
334 {
335 if (*p++ == '\t')
336 len = 8 * ((len / 8) + 1);
337 else
338 len++;
339 }
340
341 if (len > max_len)
342 max_len = len;
343 }
344 item_win_width = max_len + 1;
345 i = start_element_no;
346
347 display_info->regs_column_count =
348 (TUI_DATA_WIN->generic.width - 2) / item_win_width;
349 if (display_info->regs_column_count == 0)
350 display_info->regs_column_count = 1;
351 item_win_width =
352 (TUI_DATA_WIN->generic.width - 2) / display_info->regs_column_count;
353
ef5eab5a
MS
354 /* Now create each data "sub" window, and write the display into
355 it. */
6ba8e26f 356 cur_y = 1;
e5908723
MS
357 while (i < display_info->regs_content_count
358 && cur_y <= TUI_DATA_WIN->generic.viewport_height)
c906108c
SS
359 {
360 for (j = 0;
e5908723
MS
361 j < display_info->regs_column_count
362 && i < display_info->regs_content_count;
363 j++)
c906108c 364 {
5b6fe301
MS
365 struct tui_gen_win_info *data_item_win;
366 struct tui_data_element *data_element_ptr;
c906108c 367
1cc6d956 368 /* Create the window if necessary. */
10f59415
SC
369 data_item_win = &display_info->regs_content[i]
370 ->which_element.data_window;
6ba8e26f 371 data_element_ptr = &((struct tui_win_element *)
9a2b4c1b 372 data_item_win->content[0])->which_element.data;
10f59415
SC
373 if (data_item_win->handle != (WINDOW*) NULL
374 && (data_item_win->height != 1
375 || data_item_win->width != item_win_width
376 || data_item_win->origin.x != (item_win_width * j) + 1
377 || data_item_win->origin.y != cur_y))
378 {
379 tui_delete_win (data_item_win->handle);
380 data_item_win->handle = 0;
381 }
382
6ba8e26f 383 if (data_item_win->handle == (WINDOW *) NULL)
c906108c 384 {
6ba8e26f 385 data_item_win->height = 1;
10f59415 386 data_item_win->width = item_win_width;
6ba8e26f
AC
387 data_item_win->origin.x = (item_win_width * j) + 1;
388 data_item_win->origin.y = cur_y;
389 tui_make_window (data_item_win, DONT_BOX_WINDOW);
390 scrollok (data_item_win->handle, FALSE);
c906108c 391 }
6ba8e26f 392 touchwin (data_item_win->handle);
fea14702 393
10f59415
SC
394 /* Get the printable representation of the register
395 and display it. */
396 tui_display_register (data_element_ptr, data_item_win);
1cc6d956 397 i++; /* Next register. */
c906108c 398 }
1cc6d956 399 cur_y++; /* Next row. */
c906108c
SS
400 }
401 }
55fb0713 402}
c906108c
SS
403
404
6ba8e26f
AC
405/* Function to display the registers in the content from
406 'start_element_no' on 'start_line_no' until the end of the register
407 content or the end of the display height. This function checks
408 that we won't display off the end of the register display. */
2c0b251b 409static void
08ef48c5
MS
410tui_display_reg_element_at_line (int start_element_no,
411 int start_line_no)
c906108c 412{
9a2b4c1b
MS
413 if (TUI_DATA_WIN->detail.data_display_info.regs_content
414 != (tui_win_content) NULL
e5908723 415 && TUI_DATA_WIN->detail.data_display_info.regs_content_count > 0)
c906108c 416 {
d02c80cd 417 int element_no = start_element_no;
c906108c 418
6ba8e26f 419 if (start_element_no != 0 && start_line_no != 0)
c906108c 420 {
d02c80cd 421 int last_line_no, first_line_on_last_page;
c906108c 422
6ba8e26f 423 last_line_no = tui_last_regs_line_no ();
9a2b4c1b
MS
424 first_line_on_last_page
425 = last_line_no - (TUI_DATA_WIN->generic.height - 2);
6ba8e26f
AC
426 if (first_line_on_last_page < 0)
427 first_line_on_last_page = 0;
ef5eab5a
MS
428
429 /* If there is no other data displayed except registers, and
430 the element_no causes us to scroll past the end of the
431 registers, adjust what element to really start the
432 display at. */
e5908723
MS
433 if (TUI_DATA_WIN->detail.data_display_info.data_content_count <= 0
434 && start_line_no > first_line_on_last_page)
9a2b4c1b
MS
435 element_no
436 = tui_first_reg_element_no_inline (first_line_on_last_page);
c906108c 437 }
6ba8e26f 438 tui_display_registers_from (element_no);
c906108c 439 }
6ba8e26f 440}
c906108c
SS
441
442
443
6ba8e26f 444/* Function to display the registers starting at line line_no in the
55fb0713
AC
445 data window. Answers the line number that the display actually
446 started from. If nothing is displayed (-1) is returned. */
c906108c 447int
08ef48c5
MS
448tui_display_registers_from_line (int line_no,
449 int force_display)
c906108c 450{
6d012f14 451 if (TUI_DATA_WIN->detail.data_display_info.regs_content_count > 0)
c906108c 452 {
6ba8e26f 453 int line, element_no;
c906108c 454
6ba8e26f 455 if (line_no < 0)
c906108c 456 line = 0;
6ba8e26f 457 else if (force_display)
ef5eab5a
MS
458 { /* If we must display regs (force_display is true), then
459 make sure that we don't display off the end of the
460 registers. */
6ba8e26f 461 if (line_no >= tui_last_regs_line_no ())
c906108c 462 {
55fb0713 463 if ((line = tui_line_from_reg_element_no (
6d012f14 464 TUI_DATA_WIN->detail.data_display_info.regs_content_count - 1)) < 0)
c906108c
SS
465 line = 0;
466 }
467 else
6ba8e26f 468 line = line_no;
c906108c
SS
469 }
470 else
6ba8e26f 471 line = line_no;
c906108c 472
6ba8e26f 473 element_no = tui_first_reg_element_no_inline (line);
9a2b4c1b
MS
474 if (element_no
475 < TUI_DATA_WIN->detail.data_display_info.regs_content_count)
6ba8e26f 476 tui_display_reg_element_at_line (element_no, line);
c906108c
SS
477 else
478 line = (-1);
479
480 return line;
481 }
482
1cc6d956 483 return (-1); /* Nothing was displayed. */
55fb0713 484}
c906108c
SS
485
486
55fb0713
AC
487/* This function check all displayed registers for changes in values,
488 given a particular frame. If the values have changed, they are
489 updated with the new value and highlighted. */
c906108c 490void
55fb0713 491tui_check_register_values (struct frame_info *frame)
c906108c 492{
e5908723
MS
493 if (TUI_DATA_WIN != NULL
494 && TUI_DATA_WIN->generic.is_visible)
c906108c 495 {
10f59415
SC
496 struct tui_data_info *display_info
497 = &TUI_DATA_WIN->detail.data_display_info;
498
e5908723
MS
499 if (display_info->regs_content_count <= 0
500 && display_info->display_regs)
10f59415 501 tui_show_registers (display_info->current_group);
c906108c
SS
502 else
503 {
0043e6a5 504 int i;
c906108c 505
10f59415 506 for (i = 0; (i < display_info->regs_content_count); i++)
c906108c 507 {
10f59415
SC
508 struct tui_data_element *data;
509 struct tui_gen_win_info *data_item_win_ptr;
6ba8e26f 510 int was_hilighted;
c906108c 511
10f59415
SC
512 data_item_win_ptr = &display_info->regs_content[i]->
513 which_element.data_window;
514 data = &((struct tui_win_element *)
515 data_item_win_ptr->content[0])->which_element.data;
516 was_hilighted = data->highlight;
517
5eccfcc2 518 tui_get_register (frame, data,
10f59415
SC
519 data->item_no, &data->highlight);
520
521 if (data->highlight || was_hilighted)
c906108c 522 {
10f59415 523 tui_display_register (data, data_item_win_ptr);
c906108c
SS
524 }
525 }
526 }
527 }
55fb0713 528}
c906108c 529
1cc6d956
MS
530/* Display a register in a window. If hilite is TRUE, then the value
531 will be displayed in reverse video. */
10f59415
SC
532static void
533tui_display_register (struct tui_data_element *data,
534 struct tui_gen_win_info *win_info)
535{
536 if (win_info->handle != (WINDOW *) NULL)
537 {
538 int i;
c906108c 539
10f59415 540 if (data->highlight)
cae3f17b
JB
541 /* We ignore the return value, casting it to void in order to avoid
542 a compiler warning. The warning itself was introduced by a patch
543 to ncurses 5.7 dated 2009-08-29, changing this macro to expand
544 to code that causes the compiler to generate an unused-value
545 warning. */
ae3bccd4 546 (void) wstandout (win_info->handle);
10f59415
SC
547
548 wmove (win_info->handle, 0, 0);
549 for (i = 1; i < win_info->width; i++)
550 waddch (win_info->handle, ' ');
551 wmove (win_info->handle, 0, 0);
552 if (data->content)
553 waddstr (win_info->handle, data->content);
554
555 if (data->highlight)
cae3f17b
JB
556 /* We ignore the return value, casting it to void in order to avoid
557 a compiler warning. The warning itself was introduced by a patch
558 to ncurses 5.7 dated 2009-08-29, changing this macro to expand
559 to code that causes the compiler to generate an unused-value
560 warning. */
ae3bccd4 561 (void) wstandend (win_info->handle);
10f59415
SC
562 tui_refresh_win (win_info);
563 }
564}
565
566static void
567tui_reg_next_command (char *arg, int from_tty)
c906108c 568{
e17c207e
UW
569 struct gdbarch *gdbarch = get_current_arch ();
570
10f59415
SC
571 if (TUI_DATA_WIN != 0)
572 {
573 struct reggroup *group
574 = TUI_DATA_WIN->detail.data_display_info.current_group;
c906108c 575
e17c207e 576 group = reggroup_next (gdbarch, group);
10f59415 577 if (group == 0)
e17c207e 578 group = reggroup_next (gdbarch, 0);
10f59415
SC
579
580 if (group)
581 tui_show_registers (group);
582 }
583}
584
585static void
586tui_reg_float_command (char *arg, int from_tty)
587{
588 tui_show_registers (float_reggroup);
589}
c906108c 590
10f59415
SC
591static void
592tui_reg_general_command (char *arg, int from_tty)
593{
594 tui_show_registers (general_reggroup);
595}
c906108c 596
10f59415
SC
597static void
598tui_reg_system_command (char *arg, int from_tty)
599{
600 tui_show_registers (system_reggroup);
601}
602
603static struct cmd_list_element *tuireglist;
c906108c 604
10f59415
SC
605static void
606tui_reg_command (char *args, int from_tty)
607{
a3f17187
AC
608 printf_unfiltered (_("\"tui reg\" must be followed by the name of a "
609 "tui reg command.\n"));
635c7e8a 610 help_list (tuireglist, "tui reg ", all_commands, gdb_stdout);
10f59415 611}
c906108c 612
2c0b251b
PA
613/* Provide a prototype to silence -Wmissing-prototypes. */
614extern initialize_file_ftype _initialize_tui_regs;
615
c906108c 616void
6ba8e26f 617_initialize_tui_regs (void)
c906108c 618{
10f59415
SC
619 struct cmd_list_element **tuicmd;
620
621 tuicmd = tui_get_cmd_list ();
622
623 add_prefix_cmd ("reg", class_tui, tui_reg_command,
1bedd215 624 _("TUI commands to control the register window."),
10f59415
SC
625 &tuireglist, "tui reg ", 0,
626 tuicmd);
627
628 add_cmd ("float", class_tui, tui_reg_float_command,
1a966eab 629 _("Display only floating point registers."),
10f59415
SC
630 &tuireglist);
631 add_cmd ("general", class_tui, tui_reg_general_command,
1a966eab 632 _("Display only general registers."),
10f59415
SC
633 &tuireglist);
634 add_cmd ("system", class_tui, tui_reg_system_command,
1a966eab 635 _("Display only system registers."),
10f59415
SC
636 &tuireglist);
637 add_cmd ("next", class_tui, tui_reg_next_command,
1a966eab 638 _("Display next register group."),
10f59415
SC
639 &tuireglist);
640
41783295 641 if (xdb_commands)
c906108c 642 {
10f59415 643 add_com ("fr", class_tui, tui_reg_float_command,
1bedd215 644 _("Display only floating point registers\n"));
10f59415 645 add_com ("gr", class_tui, tui_reg_general_command,
1bedd215 646 _("Display only general registers\n"));
10f59415 647 add_com ("sr", class_tui, tui_reg_system_command,
1bedd215 648 _("Display only special registers\n"));
6ba8e26f 649 add_com ("+r", class_tui, tui_scroll_regs_forward_command,
1bedd215 650 _("Scroll the registers window forward\n"));
6ba8e26f 651 add_com ("-r", class_tui, tui_scroll_regs_backward_command,
1bedd215 652 _("Scroll the register window backward\n"));
c906108c 653 }
41783295 654}
c906108c
SS
655
656
657/*****************************************
658** STATIC LOCAL FUNCTIONS **
659******************************************/
660
c46cc7df
SC
661static void
662tui_restore_gdbout (void *ui)
663{
664 ui_file_delete (gdb_stdout);
665 gdb_stdout = (struct ui_file*) ui;
666 pagination_enabled = 1;
667}
c906108c 668
6eed1678
PA
669/* Get the register from the frame and return a printable
670 representation of it. */
671
672static char *
673tui_register_format (struct frame_info *frame, int regnum)
c906108c 674{
5eccfcc2 675 struct gdbarch *gdbarch = get_frame_arch (frame);
d9fcf2fb 676 struct ui_file *stream;
c46cc7df 677 struct ui_file *old_stdout;
c46cc7df 678 struct cleanup *cleanups;
10f59415 679 char *p, *s;
6eed1678 680 char *ret;
d20c1c3f 681
c46cc7df
SC
682 pagination_enabled = 0;
683 old_stdout = gdb_stdout;
10f59415 684 stream = tui_sfileopen (256);
c46cc7df
SC
685 gdb_stdout = stream;
686 cleanups = make_cleanup (tui_restore_gdbout, (void*) old_stdout);
b30aa278 687 gdbarch_print_registers_info (gdbarch, stream, frame, regnum, 1);
10f59415
SC
688
689 /* Save formatted output in the buffer. */
690 p = tui_file_get_strbuf (stream);
c46cc7df
SC
691
692 /* Remove the possible \n. */
10f59415
SC
693 s = strrchr (p, '\n');
694 if (s && s[1] == 0)
695 *s = 0;
c46cc7df 696
312809f8
EZ
697 /* Expand tabs into spaces, since ncurses on MS-Windows doesn't. */
698 ret = tui_expand_tabs (p, 0);
699
c46cc7df 700 do_cleanups (cleanups);
6eed1678
PA
701
702 return ret;
c46cc7df 703}
c906108c 704
1cc6d956
MS
705/* Get the register value from the given frame and format it for the
706 display. When changep is set, check if the new register value has
707 changed with respect to the previous call. */
22940a24 708static enum tui_status
5eccfcc2 709tui_get_register (struct frame_info *frame,
08ef48c5
MS
710 struct tui_data_element *data,
711 int regnum, int *changedp)
c906108c 712{
22940a24 713 enum tui_status ret = TUI_FAILURE;
c906108c 714
10f59415
SC
715 if (changedp)
716 *changedp = FALSE;
c906108c
SS
717 if (target_has_registers)
718 {
6eed1678 719 char *prev_content = data->content;
10f59415 720
6eed1678 721 data->content = tui_register_format (frame, regnum);
9c5ea4d9 722
6eed1678
PA
723 if (changedp != NULL
724 && strcmp (prev_content, data->content) != 0)
725 *changedp = 1;
d20c1c3f 726
6eed1678 727 xfree (prev_content);
9c5ea4d9
UW
728
729 ret = TUI_SUCCESS;
c906108c 730 }
c906108c 731 return ret;
6ba8e26f 732}
c906108c 733
c906108c 734static void
6ba8e26f 735tui_scroll_regs_forward_command (char *arg, int from_tty)
c906108c 736{
6d012f14 737 tui_scroll (FORWARD_SCROLL, TUI_DATA_WIN, 1);
e8b915dc 738}
c906108c
SS
739
740
741static void
6ba8e26f 742tui_scroll_regs_backward_command (char *arg, int from_tty)
c906108c 743{
6d012f14 744 tui_scroll (BACKWARD_SCROLL, TUI_DATA_WIN, 1);
e8b915dc 745}
This page took 3.40997 seconds and 4 git commands to generate.