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