Rename common to gdbsupport
[deliverable/binutils-gdb.git] / gdb / tui / tui-regs.c
CommitLineData
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"
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"
51f0e40d 42#include "completer.h"
c906108c 43
6a83354a 44#include "gdb_curses.h"
96ec9981 45
c906108c
SS
46
47/*****************************************
10f59415 48** STATIC LOCAL FUNCTIONS FORWARD DECLS **
c906108c 49******************************************/
41bcff7f 50static void tui_display_register (struct tui_data_item_window *data);
c906108c 51
21e1c91e
TT
52static void tui_show_register_group (struct reggroup *group,
53 struct frame_info *frame,
54 int refresh_values_only);
5eccfcc2
UW
55
56static enum tui_status tui_get_register (struct frame_info *frame,
41bcff7f
TT
57 struct tui_data_item_window *data,
58 int regnum, bool *changedp);
5eccfcc2 59
c906108c
SS
60
61
62/*****************************************
63** PUBLIC FUNCTIONS **
64******************************************/
65
55fb0713
AC
66/* Answer the number of the last line in the regs display. If there
67 are no registers (-1) is returned. */
c906108c 68int
55fb0713 69tui_last_regs_line_no (void)
c906108c 70{
d02c80cd 71 int num_lines = (-1);
c906108c 72
21e1c91e 73 if (!TUI_DATA_WIN->regs_content.empty ())
c906108c 74 {
21e1c91e 75 num_lines = (TUI_DATA_WIN->regs_content.size ()
238eb706 76 / TUI_DATA_WIN->regs_column_count);
21e1c91e 77 if (TUI_DATA_WIN->regs_content.size () % TUI_DATA_WIN->regs_column_count)
6ba8e26f 78 num_lines++;
c906108c 79 }
6ba8e26f 80 return num_lines;
55fb0713 81}
c906108c
SS
82
83
6ba8e26f
AC
84/* Answer the line number that the register element at element_no is
85 on. If element_no is greater than the number of register elements
55fb0713 86 there are, -1 is returned. */
c906108c 87int
6ba8e26f 88tui_line_from_reg_element_no (int element_no)
c906108c 89{
21e1c91e 90 if (element_no < TUI_DATA_WIN->regs_content.size ())
c906108c
SS
91 {
92 int i, line = (-1);
93
94 i = 1;
95 while (line == (-1))
96 {
238eb706 97 if (element_no < TUI_DATA_WIN->regs_column_count * i)
c906108c
SS
98 line = i - 1;
99 else
100 i++;
101 }
102
103 return line;
104 }
105 else
106 return (-1);
55fb0713 107}
c906108c
SS
108
109
1cc6d956
MS
110/* Answer the index of the first element in line_no. If line_no is
111 past the register area (-1) is returned. */
c906108c 112int
6ba8e26f 113tui_first_reg_element_no_inline (int line_no)
c906108c 114{
238eb706 115 if ((line_no * TUI_DATA_WIN->regs_column_count)
21e1c91e 116 <= TUI_DATA_WIN->regs_content.size ())
238eb706
TT
117 return (((line_no + 1) * TUI_DATA_WIN->regs_column_count)
118 - TUI_DATA_WIN->regs_column_count);
c906108c
SS
119 else
120 return (-1);
55fb0713 121}
c906108c
SS
122
123
10f59415
SC
124/* Show the registers of the given group in the data window
125 and refresh the window. */
c906108c 126void
10f59415 127tui_show_registers (struct reggroup *group)
c906108c 128{
22940a24 129 enum tui_status ret = TUI_FAILURE;
c906108c 130
0bfbda3b
SC
131 /* Make sure the curses mode is enabled. */
132 tui_enable ();
133
134 /* Make sure the register window is visible. If not, select an
135 appropriate layout. */
cb2ce893 136 if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->is_visible)
7bd0be3a 137 tui_set_layout_by_name (DATA_NAME);
0bfbda3b 138
10f59415
SC
139 if (group == 0)
140 group = general_reggroup;
c906108c 141
1cc6d956
MS
142 /* Say that registers should be displayed, even if there is a
143 problem. */
ceb13a13 144 TUI_DATA_WIN->display_regs = true;
10f59415
SC
145
146 if (target_has_registers && target_has_stack && target_has_memory)
c906108c 147 {
21e1c91e
TT
148 tui_show_register_group (group, get_selected_frame (NULL),
149 group == TUI_DATA_WIN->current_group);
150 ret = TUI_SUCCESS;
c906108c
SS
151 }
152 if (ret == TUI_FAILURE)
153 {
238eb706 154 TUI_DATA_WIN->current_group = 0;
edae1ccf 155 tui_erase_data_content (NO_REGS_STRING);
c906108c
SS
156 }
157 else
158 {
1cc6d956 159 /* Clear all notation of changed values. */
21e1c91e 160 for (auto &&data_item_win : TUI_DATA_WIN->regs_content)
c906108c 161 {
21e1c91e
TT
162 if (data_item_win != nullptr)
163 data_item_win->highlight = false;
c906108c 164 }
238eb706 165 TUI_DATA_WIN->current_group = group;
edae1ccf 166 tui_display_all_data ();
c906108c 167 }
55fb0713 168}
c906108c
SS
169
170
10f59415 171/* Set the data window to display the registers of the register group
1cc6d956
MS
172 using the given frame. Values are refreshed only when
173 refresh_values_only is TRUE. */
10f59415 174
21e1c91e 175static void
5eccfcc2 176tui_show_register_group (struct reggroup *group,
08ef48c5
MS
177 struct frame_info *frame,
178 int refresh_values_only)
10f59415 179{
5eccfcc2 180 struct gdbarch *gdbarch = get_frame_arch (frame);
10f59415 181 int nr_regs;
10f59415
SC
182 int regnum, pos;
183 char title[80];
10f59415
SC
184
185 /* Make a new title showing which group we display. */
186 snprintf (title, sizeof (title) - 1, "Register group: %s",
187 reggroup_name (group));
cb2ce893
TT
188 xfree (TUI_DATA_WIN->title);
189 TUI_DATA_WIN->title = xstrdup (title);
10f59415
SC
190
191 /* See how many registers must be displayed. */
192 nr_regs = 0;
f6efe3f8 193 for (regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++)
10f59415 194 {
d20c1c3f
PA
195 const char *name;
196
197 /* Must be in the group. */
198 if (!gdbarch_register_reggroup_p (gdbarch, regnum, group))
199 continue;
200
201 /* If the register name is empty, it is undefined for this
202 processor, so don't display anything. */
203 name = gdbarch_register_name (gdbarch, regnum);
204 if (name == 0 || *name == '\0')
205 continue;
206
207 nr_regs++;
10f59415
SC
208 }
209
21e1c91e
TT
210 if (!refresh_values_only)
211 TUI_DATA_WIN->regs_content.clear ();
10f59415 212
21e1c91e
TT
213 if (nr_regs < TUI_DATA_WIN->regs_content.size ())
214 TUI_DATA_WIN->regs_content.resize (nr_regs);
215 else
10f59415 216 {
21e1c91e
TT
217 for (int i = TUI_DATA_WIN->regs_content.size (); i < nr_regs; ++i)
218 TUI_DATA_WIN->regs_content.emplace_back (new tui_data_item_window ());
10f59415
SC
219 }
220
21e1c91e
TT
221 /* Now set the register names and values. */
222 pos = 0;
223 for (regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++)
10f59415 224 {
21e1c91e
TT
225 struct tui_data_item_window *data_item_win;
226 const char *name;
10f59415 227
21e1c91e
TT
228 /* Must be in the group. */
229 if (!gdbarch_register_reggroup_p (gdbarch, regnum, group))
230 continue;
10f59415 231
21e1c91e
TT
232 /* If the register name is empty, it is undefined for this
233 processor, so don't display anything. */
234 name = gdbarch_register_name (gdbarch, regnum);
235 if (name == 0 || *name == '\0')
236 continue;
10f59415 237
21e1c91e
TT
238 data_item_win = TUI_DATA_WIN->regs_content[pos].get ();
239 if (data_item_win)
240 {
241 if (!refresh_values_only)
242 {
243 data_item_win->item_no = regnum;
244 data_item_win->name = name;
245 data_item_win->highlight = false;
246 }
247 tui_get_register (frame, data_item_win, regnum, 0);
248 }
249 pos++;
250 }
10f59415
SC
251}
252
55fb0713 253/* Function to display the registers in the content from
6ba8e26f 254 'start_element_no' until the end of the register content or the end
55fb0713
AC
255 of the display height. No checking for displaying past the end of
256 the registers is done here. */
c906108c 257void
6ba8e26f 258tui_display_registers_from (int start_element_no)
c906108c 259{
21e1c91e 260 if (!TUI_DATA_WIN->regs_content.empty ())
c906108c 261 {
0043e6a5 262 int j, item_win_width, cur_y;
10f59415
SC
263
264 int max_len = 0;
21e1c91e 265 for (auto &&data_item_win : TUI_DATA_WIN->regs_content)
10f59415 266 {
10f59415
SC
267 char *p;
268 int len;
269
10f59415 270 len = 0;
41bcff7f 271 p = data_item_win->content;
10f59415
SC
272 if (p != 0)
273 while (*p)
274 {
275 if (*p++ == '\t')
276 len = 8 * ((len / 8) + 1);
277 else
278 len++;
279 }
280
281 if (len > max_len)
282 max_len = len;
283 }
284 item_win_width = max_len + 1;
21e1c91e 285 int i = start_element_no;
10f59415 286
238eb706 287 TUI_DATA_WIN->regs_column_count =
cb2ce893 288 (TUI_DATA_WIN->width - 2) / item_win_width;
238eb706
TT
289 if (TUI_DATA_WIN->regs_column_count == 0)
290 TUI_DATA_WIN->regs_column_count = 1;
10f59415 291 item_win_width =
cb2ce893 292 (TUI_DATA_WIN->width - 2) / TUI_DATA_WIN->regs_column_count;
10f59415 293
ef5eab5a
MS
294 /* Now create each data "sub" window, and write the display into
295 it. */
6ba8e26f 296 cur_y = 1;
21e1c91e 297 while (i < TUI_DATA_WIN->regs_content.size ()
cb2ce893 298 && cur_y <= TUI_DATA_WIN->viewport_height)
c906108c
SS
299 {
300 for (j = 0;
238eb706 301 j < TUI_DATA_WIN->regs_column_count
21e1c91e 302 && i < TUI_DATA_WIN->regs_content.size ();
e5908723 303 j++)
c906108c 304 {
41bcff7f 305 struct tui_data_item_window *data_item_win;
c906108c 306
1cc6d956 307 /* Create the window if necessary. */
21e1c91e 308 data_item_win = TUI_DATA_WIN->regs_content[i].get ();
cafb3438 309 if (data_item_win->handle != NULL
10f59415
SC
310 && (data_item_win->height != 1
311 || data_item_win->width != item_win_width
312 || data_item_win->origin.x != (item_win_width * j) + 1
313 || data_item_win->origin.y != cur_y))
314 {
315 tui_delete_win (data_item_win->handle);
316 data_item_win->handle = 0;
317 }
318
cafb3438 319 if (data_item_win->handle == NULL)
c906108c 320 {
6ba8e26f 321 data_item_win->height = 1;
10f59415 322 data_item_win->width = item_win_width;
6ba8e26f
AC
323 data_item_win->origin.x = (item_win_width * j) + 1;
324 data_item_win->origin.y = cur_y;
325 tui_make_window (data_item_win, DONT_BOX_WINDOW);
326 scrollok (data_item_win->handle, FALSE);
c906108c 327 }
6ba8e26f 328 touchwin (data_item_win->handle);
fea14702 329
10f59415
SC
330 /* Get the printable representation of the register
331 and display it. */
41bcff7f 332 tui_display_register (data_item_win);
1cc6d956 333 i++; /* Next register. */
c906108c 334 }
1cc6d956 335 cur_y++; /* Next row. */
c906108c
SS
336 }
337 }
55fb0713 338}
c906108c
SS
339
340
6ba8e26f
AC
341/* Function to display the registers in the content from
342 'start_element_no' on 'start_line_no' until the end of the register
343 content or the end of the display height. This function checks
344 that we won't display off the end of the register display. */
2c0b251b 345static void
08ef48c5
MS
346tui_display_reg_element_at_line (int start_element_no,
347 int start_line_no)
c906108c 348{
21e1c91e 349 if (!TUI_DATA_WIN->regs_content.empty ())
c906108c 350 {
d02c80cd 351 int element_no = start_element_no;
c906108c 352
6ba8e26f 353 if (start_element_no != 0 && start_line_no != 0)
c906108c 354 {
d02c80cd 355 int last_line_no, first_line_on_last_page;
c906108c 356
6ba8e26f 357 last_line_no = tui_last_regs_line_no ();
9a2b4c1b 358 first_line_on_last_page
cb2ce893 359 = last_line_no - (TUI_DATA_WIN->height - 2);
6ba8e26f
AC
360 if (first_line_on_last_page < 0)
361 first_line_on_last_page = 0;
ef5eab5a 362
115ac53b 363 /* If the element_no causes us to scroll past the end of the
ef5eab5a
MS
364 registers, adjust what element to really start the
365 display at. */
115ac53b 366 if (start_line_no > first_line_on_last_page)
9a2b4c1b
MS
367 element_no
368 = tui_first_reg_element_no_inline (first_line_on_last_page);
c906108c 369 }
6ba8e26f 370 tui_display_registers_from (element_no);
c906108c 371 }
6ba8e26f 372}
c906108c
SS
373
374
375
6ba8e26f 376/* Function to display the registers starting at line line_no in the
55fb0713
AC
377 data window. Answers the line number that the display actually
378 started from. If nothing is displayed (-1) is returned. */
c906108c 379int
08ef48c5
MS
380tui_display_registers_from_line (int line_no,
381 int force_display)
c906108c 382{
21e1c91e 383 if (!TUI_DATA_WIN->regs_content.empty ())
c906108c 384 {
6ba8e26f 385 int line, element_no;
c906108c 386
6ba8e26f 387 if (line_no < 0)
c906108c 388 line = 0;
6ba8e26f 389 else if (force_display)
ef5eab5a
MS
390 { /* If we must display regs (force_display is true), then
391 make sure that we don't display off the end of the
392 registers. */
6ba8e26f 393 if (line_no >= tui_last_regs_line_no ())
c906108c 394 {
55fb0713 395 if ((line = tui_line_from_reg_element_no (
21e1c91e 396 TUI_DATA_WIN->regs_content.size () - 1)) < 0)
c906108c
SS
397 line = 0;
398 }
399 else
6ba8e26f 400 line = line_no;
c906108c
SS
401 }
402 else
6ba8e26f 403 line = line_no;
c906108c 404
6ba8e26f 405 element_no = tui_first_reg_element_no_inline (line);
21e1c91e 406 if (element_no < TUI_DATA_WIN->regs_content.size ())
6ba8e26f 407 tui_display_reg_element_at_line (element_no, line);
c906108c
SS
408 else
409 line = (-1);
410
411 return line;
412 }
413
1cc6d956 414 return (-1); /* Nothing was displayed. */
55fb0713 415}
c906108c
SS
416
417
55fb0713
AC
418/* This function check all displayed registers for changes in values,
419 given a particular frame. If the values have changed, they are
420 updated with the new value and highlighted. */
c906108c 421void
55fb0713 422tui_check_register_values (struct frame_info *frame)
c906108c 423{
e5908723 424 if (TUI_DATA_WIN != NULL
cb2ce893 425 && TUI_DATA_WIN->is_visible)
c906108c 426 {
21e1c91e 427 if (TUI_DATA_WIN->regs_content.empty ()
238eb706
TT
428 && TUI_DATA_WIN->display_regs)
429 tui_show_registers (TUI_DATA_WIN->current_group);
c906108c
SS
430 else
431 {
21e1c91e 432 for (auto &&data_item_win_ptr : TUI_DATA_WIN->regs_content)
c906108c 433 {
6ba8e26f 434 int was_hilighted;
c906108c 435
41bcff7f 436 was_hilighted = data_item_win_ptr->highlight;
10f59415 437
21e1c91e 438 tui_get_register (frame, data_item_win_ptr.get (),
41bcff7f
TT
439 data_item_win_ptr->item_no,
440 &data_item_win_ptr->highlight);
10f59415 441
41bcff7f 442 if (data_item_win_ptr->highlight || was_hilighted)
21e1c91e 443 tui_display_register (data_item_win_ptr.get ());
c906108c
SS
444 }
445 }
446 }
55fb0713 447}
c906108c 448
1cc6d956
MS
449/* Display a register in a window. If hilite is TRUE, then the value
450 will be displayed in reverse video. */
10f59415 451static void
41bcff7f 452tui_display_register (struct tui_data_item_window *data)
10f59415 453{
41bcff7f 454 if (data->handle != NULL)
10f59415
SC
455 {
456 int i;
c906108c 457
10f59415 458 if (data->highlight)
cae3f17b
JB
459 /* We ignore the return value, casting it to void in order to avoid
460 a compiler warning. The warning itself was introduced by a patch
461 to ncurses 5.7 dated 2009-08-29, changing this macro to expand
462 to code that causes the compiler to generate an unused-value
463 warning. */
41bcff7f 464 (void) wstandout (data->handle);
10f59415 465
41bcff7f
TT
466 wmove (data->handle, 0, 0);
467 for (i = 1; i < data->width; i++)
468 waddch (data->handle, ' ');
469 wmove (data->handle, 0, 0);
10f59415 470 if (data->content)
41bcff7f 471 waddstr (data->handle, data->content);
10f59415
SC
472
473 if (data->highlight)
cae3f17b
JB
474 /* We ignore the return value, casting it to void in order to avoid
475 a compiler warning. The warning itself was introduced by a patch
476 to ncurses 5.7 dated 2009-08-29, changing this macro to expand
477 to code that causes the compiler to generate an unused-value
478 warning. */
41bcff7f
TT
479 (void) wstandend (data->handle);
480 data->refresh_window ();
10f59415
SC
481 }
482}
483
51f0e40d
AB
484/* Helper for "tui reg next", wraps a call to REGGROUP_NEXT, but adds wrap
485 around behaviour. Returns the next register group, or NULL if the
486 register window is not currently being displayed. */
487
488static struct reggroup *
489tui_reg_next (struct gdbarch *gdbarch)
c906108c 490{
51f0e40d 491 struct reggroup *group = NULL;
e17c207e 492
b75c69bb 493 if (TUI_DATA_WIN != NULL)
10f59415 494 {
238eb706 495 group = TUI_DATA_WIN->current_group;
e17c207e 496 group = reggroup_next (gdbarch, group);
b75c69bb
AB
497 if (group == NULL)
498 group = reggroup_next (gdbarch, NULL);
10f59415 499 }
51f0e40d 500 return group;
10f59415
SC
501}
502
51f0e40d
AB
503/* Helper for "tui reg prev", wraps a call to REGGROUP_PREV, but adds wrap
504 around behaviour. Returns the previous register group, or NULL if the
505 register window is not currently being displayed. */
55b40027 506
51f0e40d
AB
507static struct reggroup *
508tui_reg_prev (struct gdbarch *gdbarch)
55b40027 509{
51f0e40d 510 struct reggroup *group = NULL;
55b40027
AB
511
512 if (TUI_DATA_WIN != NULL)
513 {
238eb706 514 group = TUI_DATA_WIN->current_group;
55b40027
AB
515 group = reggroup_prev (gdbarch, group);
516 if (group == NULL)
517 group = reggroup_prev (gdbarch, NULL);
55b40027 518 }
51f0e40d 519 return group;
55b40027
AB
520}
521
51f0e40d
AB
522/* Implement the 'tui reg' command. Changes the register group displayed
523 in the tui register window. Displays the tui register window if it is
524 not already on display. */
c906108c 525
10f59415 526static void
e2d8ae16 527tui_reg_command (const char *args, int from_tty)
10f59415 528{
51f0e40d 529 struct gdbarch *gdbarch = get_current_arch ();
c906108c 530
51f0e40d
AB
531 if (args != NULL)
532 {
533 struct reggroup *group, *match = NULL;
534 size_t len = strlen (args);
535
536 /* Make sure the curses mode is enabled. */
537 tui_enable ();
538
539 /* Make sure the register window is visible. If not, select an
540 appropriate layout. We need to do this before trying to run the
541 'next' or 'prev' commands. */
cb2ce893 542 if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->is_visible)
51f0e40d
AB
543 tui_set_layout_by_name (DATA_NAME);
544
545 if (strncmp (args, "next", len) == 0)
546 match = tui_reg_next (gdbarch);
547 else if (strncmp (args, "prev", len) == 0)
548 match = tui_reg_prev (gdbarch);
549
550 /* This loop matches on the initial part of a register group
551 name. If this initial part in ARGS matches only one register
552 group then the switch is made. */
553 for (group = reggroup_next (gdbarch, NULL);
554 group != NULL;
555 group = reggroup_next (gdbarch, group))
556 {
557 if (strncmp (reggroup_name (group), args, len) == 0)
558 {
559 if (match != NULL)
560 error (_("ambiguous register group name '%s'"), args);
561 match = group;
562 }
563 }
564
565 if (match == NULL)
566 error (_("unknown register group '%s'"), args);
567
568 tui_show_registers (match);
569 }
570 else
571 {
572 struct reggroup *group;
573 int first;
574
575 printf_unfiltered (_("\"tui reg\" must be followed by the name of "
576 "either a register group,\nor one of 'next' "
577 "or 'prev'. Known register groups are:\n"));
578
579 for (first = 1, group = reggroup_next (gdbarch, NULL);
580 group != NULL;
581 first = 0, group = reggroup_next (gdbarch, group))
582 {
583 if (!first)
584 printf_unfiltered (", ");
585 printf_unfiltered ("%s", reggroup_name (group));
586 }
587
588 printf_unfiltered ("\n");
589 }
10f59415
SC
590}
591
51f0e40d
AB
592/* Complete names of register groups, and add the special "prev" and "next"
593 names. */
c906108c 594
eb3ff9a5 595static void
51f0e40d 596tui_reggroup_completer (struct cmd_list_element *ignore,
eb3ff9a5 597 completion_tracker &tracker,
51f0e40d 598 const char *text, const char *word)
10f59415 599{
51f0e40d
AB
600 static const char *extra[] = { "next", "prev", NULL };
601 size_t len = strlen (word);
602 const char **tmp;
603
eb3ff9a5 604 reggroup_completer (ignore, tracker, text, word);
51f0e40d 605
eb3ff9a5 606 /* XXXX use complete_on_enum instead? */
51f0e40d
AB
607 for (tmp = extra; *tmp != NULL; ++tmp)
608 {
609 if (strncmp (word, *tmp, len) == 0)
b02f78f9 610 tracker.add_completion (make_unique_xstrdup (*tmp));
51f0e40d 611 }
10f59415 612}
c906108c
SS
613
614void
6ba8e26f 615_initialize_tui_regs (void)
c906108c 616{
51f0e40d 617 struct cmd_list_element **tuicmd, *cmd;
10f59415
SC
618
619 tuicmd = tui_get_cmd_list ();
620
51f0e40d
AB
621 cmd = add_cmd ("reg", class_tui, tui_reg_command, _("\
622TUI command to control the register window."), tuicmd);
623 set_cmd_completer (cmd, tui_reggroup_completer);
41783295 624}
c906108c
SS
625
626
627/*****************************************
628** STATIC LOCAL FUNCTIONS **
629******************************************/
630
6eed1678
PA
631/* Get the register from the frame and return a printable
632 representation of it. */
633
634static char *
635tui_register_format (struct frame_info *frame, int regnum)
c906108c 636{
5eccfcc2 637 struct gdbarch *gdbarch = get_frame_arch (frame);
d20c1c3f 638
d7e74731
PA
639 string_file stream;
640
31b68d4a
TT
641 scoped_restore save_pagination
642 = make_scoped_restore (&pagination_enabled, 0);
643 scoped_restore save_stdout
644 = make_scoped_restore (&gdb_stdout, &stream);
645
d7e74731 646 gdbarch_print_registers_info (gdbarch, &stream, frame, regnum, 1);
c46cc7df
SC
647
648 /* Remove the possible \n. */
d7e74731
PA
649 std::string &str = stream.string ();
650 if (!str.empty () && str.back () == '\n')
651 str.resize (str.size () - 1);
c46cc7df 652
312809f8 653 /* Expand tabs into spaces, since ncurses on MS-Windows doesn't. */
31b68d4a 654 return tui_expand_tabs (str.c_str (), 0);
c46cc7df 655}
c906108c 656
1cc6d956
MS
657/* Get the register value from the given frame and format it for the
658 display. When changep is set, check if the new register value has
659 changed with respect to the previous call. */
22940a24 660static enum tui_status
5eccfcc2 661tui_get_register (struct frame_info *frame,
41bcff7f
TT
662 struct tui_data_item_window *data,
663 int regnum, bool *changedp)
c906108c 664{
22940a24 665 enum tui_status ret = TUI_FAILURE;
c906108c 666
10f59415 667 if (changedp)
41bcff7f 668 *changedp = false;
c906108c
SS
669 if (target_has_registers)
670 {
6eed1678 671 char *prev_content = data->content;
10f59415 672
6eed1678 673 data->content = tui_register_format (frame, regnum);
9c5ea4d9 674
6eed1678
PA
675 if (changedp != NULL
676 && strcmp (prev_content, data->content) != 0)
41bcff7f 677 *changedp = true;
d20c1c3f 678
6eed1678 679 xfree (prev_content);
9c5ea4d9
UW
680
681 ret = TUI_SUCCESS;
c906108c 682 }
c906108c 683 return ret;
6ba8e26f 684}
This page took 2.178587 seconds and 4 git commands to generate.