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