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