Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI display registers in window. |
f33c6cbf | 2 | |
618f726f | 3 | Copyright (C) 1998-2016 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 |
50 | static void |
51 | tui_display_register (struct tui_data_element *data, | |
52 | struct tui_gen_win_info *win_info); | |
c906108c | 53 | |
5eccfcc2 UW |
54 | static enum tui_status tui_show_register_group (struct reggroup *group, |
55 | struct frame_info *frame, | |
56 | int refresh_values_only); | |
57 | ||
58 | static 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 | 70 | int |
55fb0713 | 71 | tui_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 | 90 | int |
6ba8e26f | 91 | tui_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 | 116 | int |
6ba8e26f | 117 | tui_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 | 131 | void |
10f59415 | 132 | tui_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 | |
188 | static enum tui_status | |
5eccfcc2 | 189 | tui_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; | |
f57d151a | 209 | for (regnum = 0; |
5eccfcc2 UW |
210 | regnum < gdbarch_num_regs (gdbarch) |
211 | + gdbarch_num_pseudo_regs (gdbarch); | |
f57d151a | 212 | regnum++) |
10f59415 | 213 | { |
d20c1c3f PA |
214 | const char *name; |
215 | ||
216 | /* Must be in the group. */ | |
217 | if (!gdbarch_register_reggroup_p (gdbarch, regnum, group)) | |
218 | continue; | |
219 | ||
220 | /* If the register name is empty, it is undefined for this | |
221 | processor, so don't display anything. */ | |
222 | name = gdbarch_register_name (gdbarch, regnum); | |
223 | if (name == 0 || *name == '\0') | |
224 | continue; | |
225 | ||
226 | nr_regs++; | |
10f59415 SC |
227 | } |
228 | ||
229 | if (display_info->regs_content_count > 0 && !refresh_values_only) | |
230 | { | |
231 | tui_free_data_content (display_info->regs_content, | |
232 | display_info->regs_content_count); | |
233 | display_info->regs_content_count = 0; | |
234 | } | |
235 | ||
236 | if (display_info->regs_content_count <= 0) | |
237 | { | |
238 | display_info->regs_content = tui_alloc_content (nr_regs, DATA_WIN); | |
239 | allocated_here = TRUE; | |
240 | refresh_values_only = FALSE; | |
241 | } | |
242 | ||
243 | if (display_info->regs_content != (tui_win_content) NULL) | |
244 | { | |
245 | if (!refresh_values_only || allocated_here) | |
246 | { | |
e65b5245 | 247 | TUI_DATA_WIN->generic.content = NULL; |
10f59415 SC |
248 | TUI_DATA_WIN->generic.content_size = 0; |
249 | tui_add_content_elements (&TUI_DATA_WIN->generic, nr_regs); | |
250 | display_info->regs_content | |
251 | = (tui_win_content) TUI_DATA_WIN->generic.content; | |
252 | display_info->regs_content_count = nr_regs; | |
253 | } | |
254 | ||
1cc6d956 | 255 | /* Now set the register names and values. */ |
10f59415 | 256 | pos = 0; |
f57d151a | 257 | for (regnum = 0; |
5eccfcc2 UW |
258 | regnum < gdbarch_num_regs (gdbarch) |
259 | + gdbarch_num_pseudo_regs (gdbarch); | |
f57d151a | 260 | regnum++) |
10f59415 SC |
261 | { |
262 | struct tui_gen_win_info *data_item_win; | |
263 | struct tui_data_element *data; | |
264 | const char *name; | |
265 | ||
d20c1c3f | 266 | /* Must be in the group. */ |
10f59415 SC |
267 | if (!gdbarch_register_reggroup_p (gdbarch, regnum, group)) |
268 | continue; | |
269 | ||
d20c1c3f PA |
270 | /* If the register name is empty, it is undefined for this |
271 | processor, so don't display anything. */ | |
272 | name = gdbarch_register_name (gdbarch, regnum); | |
273 | if (name == 0 || *name == '\0') | |
274 | continue; | |
10f59415 SC |
275 | |
276 | data_item_win = | |
277 | &display_info->regs_content[pos]->which_element.data_window; | |
63ed8182 | 278 | data = &data_item_win->content[0]->which_element.data; |
10f59415 SC |
279 | if (data) |
280 | { | |
281 | if (!refresh_values_only) | |
282 | { | |
283 | data->item_no = regnum; | |
284 | data->name = name; | |
285 | data->highlight = FALSE; | |
286 | } | |
5eccfcc2 | 287 | tui_get_register (frame, data, regnum, 0); |
10f59415 SC |
288 | } |
289 | pos++; | |
290 | } | |
291 | ||
292 | TUI_DATA_WIN->generic.content_size = | |
293 | display_info->regs_content_count + display_info->data_content_count; | |
294 | ret = TUI_SUCCESS; | |
295 | } | |
296 | ||
297 | return ret; | |
298 | } | |
299 | ||
55fb0713 | 300 | /* Function to display the registers in the content from |
6ba8e26f | 301 | 'start_element_no' until the end of the register content or the end |
55fb0713 AC |
302 | of the display height. No checking for displaying past the end of |
303 | the registers is done here. */ | |
c906108c | 304 | void |
6ba8e26f | 305 | tui_display_registers_from (int start_element_no) |
c906108c | 306 | { |
10f59415 SC |
307 | struct tui_data_info *display_info = &TUI_DATA_WIN->detail.data_display_info; |
308 | ||
e5908723 MS |
309 | if (display_info->regs_content != (tui_win_content) NULL |
310 | && display_info->regs_content_count > 0) | |
c906108c | 311 | { |
d02c80cd | 312 | int i = start_element_no; |
0043e6a5 | 313 | int j, item_win_width, cur_y; |
10f59415 SC |
314 | |
315 | int max_len = 0; | |
316 | for (i = 0; i < display_info->regs_content_count; i++) | |
317 | { | |
318 | struct tui_data_element *data; | |
319 | struct tui_gen_win_info *data_item_win; | |
320 | char *p; | |
321 | int len; | |
322 | ||
9a2b4c1b MS |
323 | data_item_win |
324 | = &display_info->regs_content[i]->which_element.data_window; | |
63ed8182 | 325 | data = &data_item_win->content[0]->which_element.data; |
10f59415 SC |
326 | len = 0; |
327 | p = data->content; | |
328 | if (p != 0) | |
329 | while (*p) | |
330 | { | |
331 | if (*p++ == '\t') | |
332 | len = 8 * ((len / 8) + 1); | |
333 | else | |
334 | len++; | |
335 | } | |
336 | ||
337 | if (len > max_len) | |
338 | max_len = len; | |
339 | } | |
340 | item_win_width = max_len + 1; | |
341 | i = start_element_no; | |
342 | ||
343 | display_info->regs_column_count = | |
344 | (TUI_DATA_WIN->generic.width - 2) / item_win_width; | |
345 | if (display_info->regs_column_count == 0) | |
346 | display_info->regs_column_count = 1; | |
347 | item_win_width = | |
348 | (TUI_DATA_WIN->generic.width - 2) / display_info->regs_column_count; | |
349 | ||
ef5eab5a MS |
350 | /* Now create each data "sub" window, and write the display into |
351 | it. */ | |
6ba8e26f | 352 | cur_y = 1; |
e5908723 MS |
353 | while (i < display_info->regs_content_count |
354 | && cur_y <= TUI_DATA_WIN->generic.viewport_height) | |
c906108c SS |
355 | { |
356 | for (j = 0; | |
e5908723 MS |
357 | j < display_info->regs_column_count |
358 | && i < display_info->regs_content_count; | |
359 | j++) | |
c906108c | 360 | { |
5b6fe301 MS |
361 | struct tui_gen_win_info *data_item_win; |
362 | struct tui_data_element *data_element_ptr; | |
c906108c | 363 | |
1cc6d956 | 364 | /* Create the window if necessary. */ |
10f59415 SC |
365 | data_item_win = &display_info->regs_content[i] |
366 | ->which_element.data_window; | |
63ed8182 | 367 | data_element_ptr = &data_item_win->content[0]->which_element.data; |
10f59415 SC |
368 | if (data_item_win->handle != (WINDOW*) NULL |
369 | && (data_item_win->height != 1 | |
370 | || data_item_win->width != item_win_width | |
371 | || data_item_win->origin.x != (item_win_width * j) + 1 | |
372 | || data_item_win->origin.y != cur_y)) | |
373 | { | |
374 | tui_delete_win (data_item_win->handle); | |
375 | data_item_win->handle = 0; | |
376 | } | |
377 | ||
6ba8e26f | 378 | if (data_item_win->handle == (WINDOW *) NULL) |
c906108c | 379 | { |
6ba8e26f | 380 | data_item_win->height = 1; |
10f59415 | 381 | data_item_win->width = item_win_width; |
6ba8e26f AC |
382 | data_item_win->origin.x = (item_win_width * j) + 1; |
383 | data_item_win->origin.y = cur_y; | |
384 | tui_make_window (data_item_win, DONT_BOX_WINDOW); | |
385 | scrollok (data_item_win->handle, FALSE); | |
c906108c | 386 | } |
6ba8e26f | 387 | touchwin (data_item_win->handle); |
fea14702 | 388 | |
10f59415 SC |
389 | /* Get the printable representation of the register |
390 | and display it. */ | |
391 | tui_display_register (data_element_ptr, data_item_win); | |
1cc6d956 | 392 | i++; /* Next register. */ |
c906108c | 393 | } |
1cc6d956 | 394 | cur_y++; /* Next row. */ |
c906108c SS |
395 | } |
396 | } | |
55fb0713 | 397 | } |
c906108c SS |
398 | |
399 | ||
6ba8e26f AC |
400 | /* Function to display the registers in the content from |
401 | 'start_element_no' on 'start_line_no' until the end of the register | |
402 | content or the end of the display height. This function checks | |
403 | that we won't display off the end of the register display. */ | |
2c0b251b | 404 | static void |
08ef48c5 MS |
405 | tui_display_reg_element_at_line (int start_element_no, |
406 | int start_line_no) | |
c906108c | 407 | { |
9a2b4c1b MS |
408 | if (TUI_DATA_WIN->detail.data_display_info.regs_content |
409 | != (tui_win_content) NULL | |
e5908723 | 410 | && TUI_DATA_WIN->detail.data_display_info.regs_content_count > 0) |
c906108c | 411 | { |
d02c80cd | 412 | int element_no = start_element_no; |
c906108c | 413 | |
6ba8e26f | 414 | if (start_element_no != 0 && start_line_no != 0) |
c906108c | 415 | { |
d02c80cd | 416 | int last_line_no, first_line_on_last_page; |
c906108c | 417 | |
6ba8e26f | 418 | last_line_no = tui_last_regs_line_no (); |
9a2b4c1b MS |
419 | first_line_on_last_page |
420 | = last_line_no - (TUI_DATA_WIN->generic.height - 2); | |
6ba8e26f AC |
421 | if (first_line_on_last_page < 0) |
422 | first_line_on_last_page = 0; | |
ef5eab5a MS |
423 | |
424 | /* If there is no other data displayed except registers, and | |
425 | the element_no causes us to scroll past the end of the | |
426 | registers, adjust what element to really start the | |
427 | display at. */ | |
e5908723 MS |
428 | if (TUI_DATA_WIN->detail.data_display_info.data_content_count <= 0 |
429 | && start_line_no > first_line_on_last_page) | |
9a2b4c1b MS |
430 | element_no |
431 | = tui_first_reg_element_no_inline (first_line_on_last_page); | |
c906108c | 432 | } |
6ba8e26f | 433 | tui_display_registers_from (element_no); |
c906108c | 434 | } |
6ba8e26f | 435 | } |
c906108c SS |
436 | |
437 | ||
438 | ||
6ba8e26f | 439 | /* Function to display the registers starting at line line_no in the |
55fb0713 AC |
440 | data window. Answers the line number that the display actually |
441 | started from. If nothing is displayed (-1) is returned. */ | |
c906108c | 442 | int |
08ef48c5 MS |
443 | tui_display_registers_from_line (int line_no, |
444 | int force_display) | |
c906108c | 445 | { |
6d012f14 | 446 | if (TUI_DATA_WIN->detail.data_display_info.regs_content_count > 0) |
c906108c | 447 | { |
6ba8e26f | 448 | int line, element_no; |
c906108c | 449 | |
6ba8e26f | 450 | if (line_no < 0) |
c906108c | 451 | line = 0; |
6ba8e26f | 452 | else if (force_display) |
ef5eab5a MS |
453 | { /* If we must display regs (force_display is true), then |
454 | make sure that we don't display off the end of the | |
455 | registers. */ | |
6ba8e26f | 456 | if (line_no >= tui_last_regs_line_no ()) |
c906108c | 457 | { |
55fb0713 | 458 | if ((line = tui_line_from_reg_element_no ( |
6d012f14 | 459 | TUI_DATA_WIN->detail.data_display_info.regs_content_count - 1)) < 0) |
c906108c SS |
460 | line = 0; |
461 | } | |
462 | else | |
6ba8e26f | 463 | line = line_no; |
c906108c SS |
464 | } |
465 | else | |
6ba8e26f | 466 | line = line_no; |
c906108c | 467 | |
6ba8e26f | 468 | element_no = tui_first_reg_element_no_inline (line); |
9a2b4c1b MS |
469 | if (element_no |
470 | < TUI_DATA_WIN->detail.data_display_info.regs_content_count) | |
6ba8e26f | 471 | tui_display_reg_element_at_line (element_no, line); |
c906108c SS |
472 | else |
473 | line = (-1); | |
474 | ||
475 | return line; | |
476 | } | |
477 | ||
1cc6d956 | 478 | return (-1); /* Nothing was displayed. */ |
55fb0713 | 479 | } |
c906108c SS |
480 | |
481 | ||
55fb0713 AC |
482 | /* This function check all displayed registers for changes in values, |
483 | given a particular frame. If the values have changed, they are | |
484 | updated with the new value and highlighted. */ | |
c906108c | 485 | void |
55fb0713 | 486 | tui_check_register_values (struct frame_info *frame) |
c906108c | 487 | { |
e5908723 MS |
488 | if (TUI_DATA_WIN != NULL |
489 | && TUI_DATA_WIN->generic.is_visible) | |
c906108c | 490 | { |
10f59415 SC |
491 | struct tui_data_info *display_info |
492 | = &TUI_DATA_WIN->detail.data_display_info; | |
493 | ||
e5908723 MS |
494 | if (display_info->regs_content_count <= 0 |
495 | && display_info->display_regs) | |
10f59415 | 496 | tui_show_registers (display_info->current_group); |
c906108c SS |
497 | else |
498 | { | |
0043e6a5 | 499 | int i; |
c906108c | 500 | |
10f59415 | 501 | for (i = 0; (i < display_info->regs_content_count); i++) |
c906108c | 502 | { |
10f59415 SC |
503 | struct tui_data_element *data; |
504 | struct tui_gen_win_info *data_item_win_ptr; | |
6ba8e26f | 505 | int was_hilighted; |
c906108c | 506 | |
10f59415 SC |
507 | data_item_win_ptr = &display_info->regs_content[i]-> |
508 | which_element.data_window; | |
63ed8182 | 509 | data = &data_item_win_ptr->content[0]->which_element.data; |
10f59415 SC |
510 | was_hilighted = data->highlight; |
511 | ||
5eccfcc2 | 512 | tui_get_register (frame, data, |
10f59415 SC |
513 | data->item_no, &data->highlight); |
514 | ||
515 | if (data->highlight || was_hilighted) | |
c906108c | 516 | { |
10f59415 | 517 | tui_display_register (data, data_item_win_ptr); |
c906108c SS |
518 | } |
519 | } | |
520 | } | |
521 | } | |
55fb0713 | 522 | } |
c906108c | 523 | |
1cc6d956 MS |
524 | /* Display a register in a window. If hilite is TRUE, then the value |
525 | will be displayed in reverse video. */ | |
10f59415 SC |
526 | static void |
527 | tui_display_register (struct tui_data_element *data, | |
528 | struct tui_gen_win_info *win_info) | |
529 | { | |
530 | if (win_info->handle != (WINDOW *) NULL) | |
531 | { | |
532 | int i; | |
c906108c | 533 | |
10f59415 | 534 | if (data->highlight) |
cae3f17b JB |
535 | /* We ignore the return value, casting it to void in order to avoid |
536 | a compiler warning. The warning itself was introduced by a patch | |
537 | to ncurses 5.7 dated 2009-08-29, changing this macro to expand | |
538 | to code that causes the compiler to generate an unused-value | |
539 | warning. */ | |
ae3bccd4 | 540 | (void) wstandout (win_info->handle); |
10f59415 SC |
541 | |
542 | wmove (win_info->handle, 0, 0); | |
543 | for (i = 1; i < win_info->width; i++) | |
544 | waddch (win_info->handle, ' '); | |
545 | wmove (win_info->handle, 0, 0); | |
546 | if (data->content) | |
547 | waddstr (win_info->handle, data->content); | |
548 | ||
549 | if (data->highlight) | |
cae3f17b JB |
550 | /* We ignore the return value, casting it to void in order to avoid |
551 | a compiler warning. The warning itself was introduced by a patch | |
552 | to ncurses 5.7 dated 2009-08-29, changing this macro to expand | |
553 | to code that causes the compiler to generate an unused-value | |
554 | warning. */ | |
ae3bccd4 | 555 | (void) wstandend (win_info->handle); |
10f59415 SC |
556 | tui_refresh_win (win_info); |
557 | } | |
558 | } | |
559 | ||
51f0e40d AB |
560 | /* Helper for "tui reg next", wraps a call to REGGROUP_NEXT, but adds wrap |
561 | around behaviour. Returns the next register group, or NULL if the | |
562 | register window is not currently being displayed. */ | |
563 | ||
564 | static struct reggroup * | |
565 | tui_reg_next (struct gdbarch *gdbarch) | |
c906108c | 566 | { |
51f0e40d | 567 | struct reggroup *group = NULL; |
e17c207e | 568 | |
b75c69bb | 569 | if (TUI_DATA_WIN != NULL) |
10f59415 | 570 | { |
51f0e40d | 571 | group = TUI_DATA_WIN->detail.data_display_info.current_group; |
e17c207e | 572 | group = reggroup_next (gdbarch, group); |
b75c69bb AB |
573 | if (group == NULL) |
574 | group = reggroup_next (gdbarch, NULL); | |
10f59415 | 575 | } |
51f0e40d | 576 | return group; |
10f59415 SC |
577 | } |
578 | ||
51f0e40d AB |
579 | /* Helper for "tui reg prev", wraps a call to REGGROUP_PREV, but adds wrap |
580 | around behaviour. Returns the previous register group, or NULL if the | |
581 | register window is not currently being displayed. */ | |
55b40027 | 582 | |
51f0e40d AB |
583 | static struct reggroup * |
584 | tui_reg_prev (struct gdbarch *gdbarch) | |
55b40027 | 585 | { |
51f0e40d | 586 | struct reggroup *group = NULL; |
55b40027 AB |
587 | |
588 | if (TUI_DATA_WIN != NULL) | |
589 | { | |
51f0e40d | 590 | group = TUI_DATA_WIN->detail.data_display_info.current_group; |
55b40027 AB |
591 | group = reggroup_prev (gdbarch, group); |
592 | if (group == NULL) | |
593 | group = reggroup_prev (gdbarch, NULL); | |
55b40027 | 594 | } |
51f0e40d | 595 | return group; |
55b40027 AB |
596 | } |
597 | ||
51f0e40d AB |
598 | /* Implement the 'tui reg' command. Changes the register group displayed |
599 | in the tui register window. Displays the tui register window if it is | |
600 | not already on display. */ | |
c906108c | 601 | |
10f59415 | 602 | static void |
51f0e40d | 603 | tui_reg_command (char *args, int from_tty) |
10f59415 | 604 | { |
51f0e40d | 605 | struct gdbarch *gdbarch = get_current_arch (); |
c906108c | 606 | |
51f0e40d AB |
607 | if (args != NULL) |
608 | { | |
609 | struct reggroup *group, *match = NULL; | |
610 | size_t len = strlen (args); | |
611 | ||
612 | /* Make sure the curses mode is enabled. */ | |
613 | tui_enable (); | |
614 | ||
615 | /* Make sure the register window is visible. If not, select an | |
616 | appropriate layout. We need to do this before trying to run the | |
617 | 'next' or 'prev' commands. */ | |
618 | if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->generic.is_visible) | |
619 | tui_set_layout_by_name (DATA_NAME); | |
620 | ||
621 | if (strncmp (args, "next", len) == 0) | |
622 | match = tui_reg_next (gdbarch); | |
623 | else if (strncmp (args, "prev", len) == 0) | |
624 | match = tui_reg_prev (gdbarch); | |
625 | ||
626 | /* This loop matches on the initial part of a register group | |
627 | name. If this initial part in ARGS matches only one register | |
628 | group then the switch is made. */ | |
629 | for (group = reggroup_next (gdbarch, NULL); | |
630 | group != NULL; | |
631 | group = reggroup_next (gdbarch, group)) | |
632 | { | |
633 | if (strncmp (reggroup_name (group), args, len) == 0) | |
634 | { | |
635 | if (match != NULL) | |
636 | error (_("ambiguous register group name '%s'"), args); | |
637 | match = group; | |
638 | } | |
639 | } | |
640 | ||
641 | if (match == NULL) | |
642 | error (_("unknown register group '%s'"), args); | |
643 | ||
644 | tui_show_registers (match); | |
645 | } | |
646 | else | |
647 | { | |
648 | struct reggroup *group; | |
649 | int first; | |
650 | ||
651 | printf_unfiltered (_("\"tui reg\" must be followed by the name of " | |
652 | "either a register group,\nor one of 'next' " | |
653 | "or 'prev'. Known register groups are:\n")); | |
654 | ||
655 | for (first = 1, group = reggroup_next (gdbarch, NULL); | |
656 | group != NULL; | |
657 | first = 0, group = reggroup_next (gdbarch, group)) | |
658 | { | |
659 | if (!first) | |
660 | printf_unfiltered (", "); | |
661 | printf_unfiltered ("%s", reggroup_name (group)); | |
662 | } | |
663 | ||
664 | printf_unfiltered ("\n"); | |
665 | } | |
10f59415 SC |
666 | } |
667 | ||
51f0e40d AB |
668 | /* Complete names of register groups, and add the special "prev" and "next" |
669 | names. */ | |
c906108c | 670 | |
51f0e40d AB |
671 | static VEC (char_ptr) * |
672 | tui_reggroup_completer (struct cmd_list_element *ignore, | |
673 | const char *text, const char *word) | |
10f59415 | 674 | { |
51f0e40d AB |
675 | VEC (char_ptr) *result = NULL; |
676 | static const char *extra[] = { "next", "prev", NULL }; | |
677 | size_t len = strlen (word); | |
678 | const char **tmp; | |
679 | ||
680 | result = reggroup_completer (ignore, text, word); | |
681 | ||
682 | for (tmp = extra; *tmp != NULL; ++tmp) | |
683 | { | |
684 | if (strncmp (word, *tmp, len) == 0) | |
685 | VEC_safe_push (char_ptr, result, xstrdup (*tmp)); | |
686 | } | |
687 | ||
688 | return result; | |
10f59415 | 689 | } |
c906108c | 690 | |
2c0b251b PA |
691 | /* Provide a prototype to silence -Wmissing-prototypes. */ |
692 | extern initialize_file_ftype _initialize_tui_regs; | |
693 | ||
c906108c | 694 | void |
6ba8e26f | 695 | _initialize_tui_regs (void) |
c906108c | 696 | { |
51f0e40d | 697 | struct cmd_list_element **tuicmd, *cmd; |
10f59415 SC |
698 | |
699 | tuicmd = tui_get_cmd_list (); | |
700 | ||
51f0e40d AB |
701 | cmd = add_cmd ("reg", class_tui, tui_reg_command, _("\ |
702 | TUI command to control the register window."), tuicmd); | |
703 | set_cmd_completer (cmd, tui_reggroup_completer); | |
41783295 | 704 | } |
c906108c SS |
705 | |
706 | ||
707 | /***************************************** | |
708 | ** STATIC LOCAL FUNCTIONS ** | |
709 | ******************************************/ | |
710 | ||
c46cc7df SC |
711 | static void |
712 | tui_restore_gdbout (void *ui) | |
713 | { | |
714 | ui_file_delete (gdb_stdout); | |
715 | gdb_stdout = (struct ui_file*) ui; | |
716 | pagination_enabled = 1; | |
717 | } | |
c906108c | 718 | |
6eed1678 PA |
719 | /* Get the register from the frame and return a printable |
720 | representation of it. */ | |
721 | ||
722 | static char * | |
723 | tui_register_format (struct frame_info *frame, int regnum) | |
c906108c | 724 | { |
5eccfcc2 | 725 | struct gdbarch *gdbarch = get_frame_arch (frame); |
d9fcf2fb | 726 | struct ui_file *stream; |
c46cc7df | 727 | struct ui_file *old_stdout; |
c46cc7df | 728 | struct cleanup *cleanups; |
10f59415 | 729 | char *p, *s; |
6eed1678 | 730 | char *ret; |
d20c1c3f | 731 | |
c46cc7df SC |
732 | pagination_enabled = 0; |
733 | old_stdout = gdb_stdout; | |
10f59415 | 734 | stream = tui_sfileopen (256); |
c46cc7df SC |
735 | gdb_stdout = stream; |
736 | cleanups = make_cleanup (tui_restore_gdbout, (void*) old_stdout); | |
b30aa278 | 737 | gdbarch_print_registers_info (gdbarch, stream, frame, regnum, 1); |
10f59415 SC |
738 | |
739 | /* Save formatted output in the buffer. */ | |
740 | p = tui_file_get_strbuf (stream); | |
c46cc7df SC |
741 | |
742 | /* Remove the possible \n. */ | |
10f59415 SC |
743 | s = strrchr (p, '\n'); |
744 | if (s && s[1] == 0) | |
745 | *s = 0; | |
c46cc7df | 746 | |
312809f8 EZ |
747 | /* Expand tabs into spaces, since ncurses on MS-Windows doesn't. */ |
748 | ret = tui_expand_tabs (p, 0); | |
749 | ||
c46cc7df | 750 | do_cleanups (cleanups); |
6eed1678 PA |
751 | |
752 | return ret; | |
c46cc7df | 753 | } |
c906108c | 754 | |
1cc6d956 MS |
755 | /* Get the register value from the given frame and format it for the |
756 | display. When changep is set, check if the new register value has | |
757 | changed with respect to the previous call. */ | |
22940a24 | 758 | static enum tui_status |
5eccfcc2 | 759 | tui_get_register (struct frame_info *frame, |
08ef48c5 MS |
760 | struct tui_data_element *data, |
761 | int regnum, int *changedp) | |
c906108c | 762 | { |
22940a24 | 763 | enum tui_status ret = TUI_FAILURE; |
c906108c | 764 | |
10f59415 SC |
765 | if (changedp) |
766 | *changedp = FALSE; | |
c906108c SS |
767 | if (target_has_registers) |
768 | { | |
6eed1678 | 769 | char *prev_content = data->content; |
10f59415 | 770 | |
6eed1678 | 771 | data->content = tui_register_format (frame, regnum); |
9c5ea4d9 | 772 | |
6eed1678 PA |
773 | if (changedp != NULL |
774 | && strcmp (prev_content, data->content) != 0) | |
775 | *changedp = 1; | |
d20c1c3f | 776 | |
6eed1678 | 777 | xfree (prev_content); |
9c5ea4d9 UW |
778 | |
779 | ret = TUI_SUCCESS; | |
c906108c | 780 | } |
c906108c | 781 | return ret; |
6ba8e26f | 782 | } |