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