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