| 1 | /* TUI display registers in window. |
| 2 | |
| 3 | Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software |
| 4 | Foundation, Inc. |
| 5 | |
| 6 | Contributed by Hewlett-Packard Company. |
| 7 | |
| 8 | This file is part of GDB. |
| 9 | |
| 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. */ |
| 24 | |
| 25 | #include "defs.h" |
| 26 | #include "tui/tui.h" |
| 27 | #include "tui/tui-data.h" |
| 28 | #include "symtab.h" |
| 29 | #include "gdbtypes.h" |
| 30 | #include "gdbcmd.h" |
| 31 | #include "frame.h" |
| 32 | #include "regcache.h" |
| 33 | #include "inferior.h" |
| 34 | #include "target.h" |
| 35 | #include "gdb_string.h" |
| 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" |
| 41 | #include "reggroups.h" |
| 42 | |
| 43 | #include "gdb_curses.h" |
| 44 | |
| 45 | |
| 46 | /***************************************** |
| 47 | ** STATIC LOCAL FUNCTIONS FORWARD DECLS ** |
| 48 | ******************************************/ |
| 49 | static void |
| 50 | tui_display_register (struct tui_data_element *data, |
| 51 | struct tui_gen_win_info *win_info); |
| 52 | |
| 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); |
| 56 | |
| 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); |
| 60 | static void tui_register_format |
| 61 | (struct gdbarch *, struct frame_info *, struct tui_data_element*, int); |
| 62 | static void tui_scroll_regs_forward_command (char *, int); |
| 63 | static void tui_scroll_regs_backward_command (char *, int); |
| 64 | |
| 65 | |
| 66 | |
| 67 | /***************************************** |
| 68 | ** PUBLIC FUNCTIONS ** |
| 69 | ******************************************/ |
| 70 | |
| 71 | /* Answer the number of the last line in the regs display. If there |
| 72 | are no registers (-1) is returned. */ |
| 73 | int |
| 74 | tui_last_regs_line_no (void) |
| 75 | { |
| 76 | int num_lines = (-1); |
| 77 | |
| 78 | if (TUI_DATA_WIN->detail.data_display_info.regs_content_count > 0) |
| 79 | { |
| 80 | num_lines = (TUI_DATA_WIN->detail.data_display_info.regs_content_count / |
| 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) |
| 84 | num_lines++; |
| 85 | } |
| 86 | return num_lines; |
| 87 | } |
| 88 | |
| 89 | |
| 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 |
| 92 | there are, -1 is returned. */ |
| 93 | int |
| 94 | tui_line_from_reg_element_no (int element_no) |
| 95 | { |
| 96 | if (element_no < TUI_DATA_WIN->detail.data_display_info.regs_content_count) |
| 97 | { |
| 98 | int i, line = (-1); |
| 99 | |
| 100 | i = 1; |
| 101 | while (line == (-1)) |
| 102 | { |
| 103 | if (element_no < |
| 104 | (TUI_DATA_WIN->detail.data_display_info.regs_column_count * i)) |
| 105 | line = i - 1; |
| 106 | else |
| 107 | i++; |
| 108 | } |
| 109 | |
| 110 | return line; |
| 111 | } |
| 112 | else |
| 113 | return (-1); |
| 114 | } |
| 115 | |
| 116 | |
| 117 | /* Answer the index of the first element in line_no. If line_no is past |
| 118 | the register area (-1) is returned. */ |
| 119 | int |
| 120 | tui_first_reg_element_no_inline (int line_no) |
| 121 | { |
| 122 | if ((line_no * TUI_DATA_WIN->detail.data_display_info.regs_column_count) |
| 123 | <= TUI_DATA_WIN->detail.data_display_info.regs_content_count) |
| 124 | return ((line_no + 1) * |
| 125 | TUI_DATA_WIN->detail.data_display_info.regs_column_count) - |
| 126 | TUI_DATA_WIN->detail.data_display_info.regs_column_count; |
| 127 | else |
| 128 | return (-1); |
| 129 | } |
| 130 | |
| 131 | |
| 132 | /* Answer the index of the last element in line_no. If line_no is |
| 133 | past the register area (-1) is returned. */ |
| 134 | int |
| 135 | tui_last_reg_element_no_in_line (int line_no) |
| 136 | { |
| 137 | if ((line_no * TUI_DATA_WIN->detail.data_display_info.regs_column_count) <= |
| 138 | TUI_DATA_WIN->detail.data_display_info.regs_content_count) |
| 139 | return ((line_no + 1) * |
| 140 | TUI_DATA_WIN->detail.data_display_info.regs_column_count) - 1; |
| 141 | else |
| 142 | return (-1); |
| 143 | } |
| 144 | |
| 145 | /* Show the registers of the given group in the data window |
| 146 | and refresh the window. */ |
| 147 | void |
| 148 | tui_show_registers (struct reggroup *group) |
| 149 | { |
| 150 | enum tui_status ret = TUI_FAILURE; |
| 151 | struct tui_data_info *display_info = &TUI_DATA_WIN->detail.data_display_info; |
| 152 | |
| 153 | if (group == 0) |
| 154 | group = general_reggroup; |
| 155 | |
| 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) |
| 160 | { |
| 161 | ret = tui_show_register_group (current_gdbarch, group, |
| 162 | get_current_frame (), |
| 163 | group == display_info->current_group); |
| 164 | } |
| 165 | if (ret == TUI_FAILURE) |
| 166 | { |
| 167 | display_info->current_group = 0; |
| 168 | tui_erase_data_content (NO_REGS_STRING); |
| 169 | } |
| 170 | else |
| 171 | { |
| 172 | int i; |
| 173 | |
| 174 | /* Clear all notation of changed values */ |
| 175 | for (i = 0; i < display_info->regs_content_count; i++) |
| 176 | { |
| 177 | struct tui_gen_win_info *data_item_win; |
| 178 | struct tui_win_element *win; |
| 179 | |
| 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; |
| 184 | } |
| 185 | display_info->current_group = group; |
| 186 | tui_display_all_data (); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | |
| 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 | |
| 291 | /* Function to display the registers in the content from |
| 292 | 'start_element_no' until the end of the register content or the end |
| 293 | of the display height. No checking for displaying past the end of |
| 294 | the registers is done here. */ |
| 295 | void |
| 296 | tui_display_registers_from (int start_element_no) |
| 297 | { |
| 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) |
| 302 | { |
| 303 | int i = start_element_no; |
| 304 | int j, value_chars_wide, item_win_width, cur_y; |
| 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 | |
| 341 | /* |
| 342 | ** Now create each data "sub" window, and write the display into it. |
| 343 | */ |
| 344 | cur_y = 1; |
| 345 | while (i < display_info->regs_content_count && |
| 346 | cur_y <= TUI_DATA_WIN->generic.viewport_height) |
| 347 | { |
| 348 | for (j = 0; |
| 349 | (j < display_info->regs_column_count && |
| 350 | i < display_info->regs_content_count); j++) |
| 351 | { |
| 352 | struct tui_gen_win_info * data_item_win; |
| 353 | struct tui_data_element * data_element_ptr; |
| 354 | |
| 355 | /* create the window if necessary */ |
| 356 | data_item_win = &display_info->regs_content[i] |
| 357 | ->which_element.data_window; |
| 358 | data_element_ptr = &((struct tui_win_element *) |
| 359 | data_item_win->content[0])->which_element.data; |
| 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 | |
| 370 | if (data_item_win->handle == (WINDOW *) NULL) |
| 371 | { |
| 372 | data_item_win->height = 1; |
| 373 | data_item_win->width = item_win_width; |
| 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); |
| 378 | } |
| 379 | touchwin (data_item_win->handle); |
| 380 | |
| 381 | /* Get the printable representation of the register |
| 382 | and display it. */ |
| 383 | tui_display_register (data_element_ptr, data_item_win); |
| 384 | i++; /* next register */ |
| 385 | } |
| 386 | cur_y++; /* next row; */ |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | |
| 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. */ |
| 396 | void |
| 397 | tui_display_reg_element_at_line (int start_element_no, int start_line_no) |
| 398 | { |
| 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) |
| 401 | { |
| 402 | int element_no = start_element_no; |
| 403 | |
| 404 | if (start_element_no != 0 && start_line_no != 0) |
| 405 | { |
| 406 | int last_line_no, first_line_on_last_page; |
| 407 | |
| 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; |
| 412 | /* |
| 413 | ** If there is no other data displayed except registers, |
| 414 | ** and the element_no causes us to scroll past the end of the |
| 415 | ** registers, adjust what element to really start the display at. |
| 416 | */ |
| 417 | if (TUI_DATA_WIN->detail.data_display_info.data_content_count <= 0 && |
| 418 | start_line_no > first_line_on_last_page) |
| 419 | element_no = tui_first_reg_element_no_inline (first_line_on_last_page); |
| 420 | } |
| 421 | tui_display_registers_from (element_no); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | |
| 426 | |
| 427 | /* Function to display the registers starting at line line_no in the |
| 428 | data window. Answers the line number that the display actually |
| 429 | started from. If nothing is displayed (-1) is returned. */ |
| 430 | int |
| 431 | tui_display_registers_from_line (int line_no, int force_display) |
| 432 | { |
| 433 | if (TUI_DATA_WIN->detail.data_display_info.regs_content_count > 0) |
| 434 | { |
| 435 | int line, element_no; |
| 436 | |
| 437 | if (line_no < 0) |
| 438 | line = 0; |
| 439 | else if (force_display) |
| 440 | { /* |
| 441 | ** If we must display regs (force_display is true), then make |
| 442 | ** sure that we don't display off the end of the registers. |
| 443 | */ |
| 444 | if (line_no >= tui_last_regs_line_no ()) |
| 445 | { |
| 446 | if ((line = tui_line_from_reg_element_no ( |
| 447 | TUI_DATA_WIN->detail.data_display_info.regs_content_count - 1)) < 0) |
| 448 | line = 0; |
| 449 | } |
| 450 | else |
| 451 | line = line_no; |
| 452 | } |
| 453 | else |
| 454 | line = line_no; |
| 455 | |
| 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); |
| 459 | else |
| 460 | line = (-1); |
| 461 | |
| 462 | return line; |
| 463 | } |
| 464 | |
| 465 | return (-1); /* nothing was displayed */ |
| 466 | } |
| 467 | |
| 468 | |
| 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. */ |
| 472 | void |
| 473 | tui_check_register_values (struct frame_info *frame) |
| 474 | { |
| 475 | if (TUI_DATA_WIN != NULL && TUI_DATA_WIN->generic.is_visible) |
| 476 | { |
| 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); |
| 482 | else |
| 483 | { |
| 484 | int i, j; |
| 485 | |
| 486 | for (i = 0; (i < display_info->regs_content_count); i++) |
| 487 | { |
| 488 | struct tui_data_element *data; |
| 489 | struct tui_gen_win_info *data_item_win_ptr; |
| 490 | int was_hilighted; |
| 491 | |
| 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) |
| 502 | { |
| 503 | tui_display_register (data, data_item_win_ptr); |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | |
| 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; |
| 519 | |
| 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) |
| 538 | { |
| 539 | if (TUI_DATA_WIN != 0) |
| 540 | { |
| 541 | struct reggroup *group |
| 542 | = TUI_DATA_WIN->detail.data_display_info.current_group; |
| 543 | |
| 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 | } |
| 558 | |
| 559 | static void |
| 560 | tui_reg_general_command (char *arg, int from_tty) |
| 561 | { |
| 562 | tui_show_registers (general_reggroup); |
| 563 | } |
| 564 | |
| 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; |
| 572 | |
| 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 | } |
| 580 | |
| 581 | void |
| 582 | _initialize_tui_regs (void) |
| 583 | { |
| 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 | |
| 606 | if (xdb_commands) |
| 607 | { |
| 608 | add_com ("fr", class_tui, tui_reg_float_command, |
| 609 | "Display only floating point registers\n"); |
| 610 | add_com ("gr", class_tui, tui_reg_general_command, |
| 611 | "Display only general registers\n"); |
| 612 | add_com ("sr", class_tui, tui_reg_system_command, |
| 613 | "Display only special registers\n"); |
| 614 | add_com ("+r", class_tui, tui_scroll_regs_forward_command, |
| 615 | "Scroll the registers window forward\n"); |
| 616 | add_com ("-r", class_tui, tui_scroll_regs_backward_command, |
| 617 | "Scroll the register window backward\n"); |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | |
| 622 | /***************************************** |
| 623 | ** STATIC LOCAL FUNCTIONS ** |
| 624 | ******************************************/ |
| 625 | |
| 626 | extern int pagination_enabled; |
| 627 | |
| 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 | } |
| 635 | |
| 636 | /* Get the register from the frame and make a printable representation |
| 637 | of it in the data element. */ |
| 638 | static void |
| 639 | tui_register_format (struct gdbarch *gdbarch, struct frame_info *frame, |
| 640 | struct tui_data_element *data_element, int regnum) |
| 641 | { |
| 642 | struct ui_file *stream; |
| 643 | struct ui_file *old_stdout; |
| 644 | const char *name; |
| 645 | struct cleanup *cleanups; |
| 646 | char *p, *s; |
| 647 | int pos; |
| 648 | struct type *type = gdbarch_register_type (gdbarch, regnum); |
| 649 | |
| 650 | name = gdbarch_register_name (gdbarch, regnum); |
| 651 | if (name == 0) |
| 652 | { |
| 653 | return; |
| 654 | } |
| 655 | |
| 656 | pagination_enabled = 0; |
| 657 | old_stdout = gdb_stdout; |
| 658 | stream = tui_sfileopen (256); |
| 659 | gdb_stdout = stream; |
| 660 | cleanups = make_cleanup (tui_restore_gdbout, (void*) old_stdout); |
| 661 | if (TYPE_VECTOR (type) != 0 && 0) |
| 662 | { |
| 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); |
| 670 | } |
| 671 | else |
| 672 | { |
| 673 | gdbarch_print_registers_info (current_gdbarch, stream, |
| 674 | frame, regnum, 1); |
| 675 | } |
| 676 | |
| 677 | /* Save formatted output in the buffer. */ |
| 678 | p = tui_file_get_strbuf (stream); |
| 679 | |
| 680 | /* Remove the possible \n. */ |
| 681 | s = strrchr (p, '\n'); |
| 682 | if (s && s[1] == 0) |
| 683 | *s = 0; |
| 684 | |
| 685 | xfree (data_element->content); |
| 686 | data_element->content = xstrdup (p); |
| 687 | do_cleanups (cleanups); |
| 688 | } |
| 689 | |
| 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. */ |
| 693 | static enum tui_status |
| 694 | tui_get_register (struct gdbarch *gdbarch, struct frame_info *frame, |
| 695 | struct tui_data_element *data, int regnum, int *changedp) |
| 696 | { |
| 697 | enum tui_status ret = TUI_FAILURE; |
| 698 | |
| 699 | if (changedp) |
| 700 | *changedp = FALSE; |
| 701 | if (target_has_registers) |
| 702 | { |
| 703 | char buf[MAX_REGISTER_SIZE]; |
| 704 | |
| 705 | get_frame_register (frame, regnum, buf); |
| 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. */ |
| 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 | } |
| 730 | } |
| 731 | return ret; |
| 732 | } |
| 733 | |
| 734 | static void |
| 735 | tui_scroll_regs_forward_command (char *arg, int from_tty) |
| 736 | { |
| 737 | tui_scroll (FORWARD_SCROLL, TUI_DATA_WIN, 1); |
| 738 | } |
| 739 | |
| 740 | |
| 741 | static void |
| 742 | tui_scroll_regs_backward_command (char *arg, int from_tty) |
| 743 | { |
| 744 | tui_scroll (BACKWARD_SCROLL, TUI_DATA_WIN, 1); |
| 745 | } |