/* Update the locator, with the provided arguments. */ static void tui_set_locator_info (struct gdbarch *gdbarch, const char *fullname, const char *procname, int lineno, CORE_ADDR addr) { struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); struct tui_locator_element *element; /* Allocate the locator content if necessary. */ if (locator->content_size <= 0) { locator->content = (void **) tui_alloc_content (1, locator->type); locator->content_size = 1; } element = &((struct tui_win_element *) locator->content[0])->which_element.locator; element->proc_name[0] = (char) 0; strcat_to_buf (element->proc_name, MAX_LOCATOR_ELEMENT_LEN, procname); element->line_no = lineno; element->addr = addr; element->gdbarch = gdbarch; tui_set_locator_fullname (fullname); }
void tui_show_locator_content (void) { char *string; struct tui_gen_win_info *locator; locator = tui_locator_win_info_ptr (); if (locator != NULL && locator->handle != (WINDOW *) NULL) { struct tui_win_element *element; element = locator->content[0]; string = tui_make_status_line (&element->which_element.locator); wmove (locator->handle, 0, 0); /* We ignore the return value from wstandout and wstandend, casting them to void in order to avoid a compiler warning. The warning itself was introduced by a patch to ncurses 5.7 dated 2009-08-29, changing these macro to expand to code that causes the compiler to generate an unused-value warning. */ (void) wstandout (locator->handle); waddstr (locator->handle, string); wclrtoeol (locator->handle); (void) wstandend (locator->handle); tui_refresh_win (locator); wmove (locator->handle, 0, 0); xfree (string); locator->content_in_use = TRUE; } }
void tui_refresh_all (struct tui_win_info **list) { int type; struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++) { if (list[type] && list[type]->generic.is_visible) { if (type == SRC_WIN || type == DISASSEM_WIN) { touchwin (list[type]->detail.source_info.execution_info->handle); tui_refresh_win (list[type]->detail.source_info.execution_info); } touchwin (list[type]->generic.handle); tui_refresh_win (&list[type]->generic); } } if (locator->is_visible) { touchwin (locator->handle); tui_refresh_win (locator); } }
/* Answer whether the source is currently displayed in the source window. */ int tui_source_is_displayed (char *fname) { return (TUI_SRC_WIN->generic.content_in_use && (strcmp (((struct tui_win_element *) (tui_locator_win_info_ptr ())-> content[0])->which_element.locator.file_name, fname) == 0)); }
/* Delete all curses windows associated with win_info, leaving everything else intact. */ void tui_del_window (struct tui_win_info *win_info) { struct tui_gen_win_info *generic_win; switch (win_info->generic.type) { case SRC_WIN: case DISASSEM_WIN: generic_win = tui_locator_win_info_ptr (); if (generic_win != (struct tui_gen_win_info *) NULL) { tui_delete_win (generic_win->handle); generic_win->handle = NULL; generic_win->is_visible = FALSE; } if (win_info->detail.source_info.fullname) { xfree (win_info->detail.source_info.fullname); win_info->detail.source_info.fullname = NULL; } generic_win = win_info->detail.source_info.execution_info; if (generic_win != (struct tui_gen_win_info *) NULL) { tui_delete_win (generic_win->handle); generic_win->handle = NULL; generic_win->is_visible = FALSE; } break; case DATA_WIN: if (win_info->generic.content != NULL) { tui_del_data_windows (win_info->detail.data_display_info.regs_content, win_info->detail.data_display_info.regs_content_count); tui_del_data_windows (win_info->detail.data_display_info.data_content, win_info->detail.data_display_info.data_content_count); } break; default: break; } if (win_info->generic.handle != (WINDOW *) NULL) { tui_delete_win (win_info->generic.handle); win_info->generic.handle = NULL; win_info->generic.is_visible = FALSE; } }
/* Set the filename portion of the locator. */ static void tui_set_locator_fullname (const char *fullname) { struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); struct tui_locator_element *element; if (locator->content[0] == NULL) { tui_set_locator_info (NULL, fullname, NULL, 0, 0); return; } element = &locator->content[0]->which_element.locator; element->full_name[0] = 0; strcat_to_buf (element->full_name, MAX_LOCATOR_ELEMENT_LEN, fullname); }
/* Show the screen layout defined. */ static void show_layout (enum tui_layout_type layout) { enum tui_layout_type cur_layout = tui_current_layout (); if (layout != cur_layout) { /* Since the new layout may cause changes in window size, we should free the content and reallocate on next display of source/asm. */ tui_free_all_source_wins_content (); tui_clear_source_windows (); if (layout == SRC_DATA_COMMAND || layout == DISASSEM_DATA_COMMAND) { show_data (layout); tui_refresh_all (tui_win_list); } else { /* First make the current layout be invisible. */ tui_make_all_invisible (); tui_make_invisible (tui_locator_win_info_ptr ()); switch (layout) { /* Now show the new layout. */ case SRC_COMMAND: show_source_command (); tui_add_to_source_windows (TUI_SRC_WIN); break; case DISASSEM_COMMAND: show_disasm_command (); tui_add_to_source_windows (TUI_DISASM_WIN); break; case SRC_DISASSEM_COMMAND: show_source_disasm_command (); tui_add_to_source_windows (TUI_SRC_WIN); tui_add_to_source_windows (TUI_DISASM_WIN); break; default: break; } } } }
static int tui_set_locator_info (struct gdbarch *gdbarch, const char *fullname, const char *procname, int lineno, CORE_ADDR addr) { struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); struct tui_locator_element *element; int locator_changed_p = 0; /* Allocate the locator content if necessary. */ if (locator->content_size <= 0) { locator->content = tui_alloc_content (1, LOCATOR_WIN); locator->content_size = 1; locator_changed_p = 1; } if (procname == NULL) procname = ""; if (fullname == NULL) fullname = ""; element = &locator->content[0]->which_element.locator; locator_changed_p |= strncmp (element->proc_name, procname, MAX_LOCATOR_ELEMENT_LEN) != 0; locator_changed_p |= lineno != element->line_no; locator_changed_p |= addr != element->addr; locator_changed_p |= gdbarch != element->gdbarch; locator_changed_p |= strncmp (element->full_name, fullname, MAX_LOCATOR_ELEMENT_LEN) != 0; element->proc_name[0] = (char) 0; strcat_to_buf (element->proc_name, MAX_LOCATOR_ELEMENT_LEN, procname); element->line_no = lineno; element->addr = addr; element->gdbarch = gdbarch; tui_set_locator_fullname (fullname); return locator_changed_p; }
void tui_get_begin_asm_address (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p) { struct tui_gen_win_info *locator; struct tui_locator_element *element; struct gdbarch *gdbarch = get_current_arch (); CORE_ADDR addr; locator = tui_locator_win_info_ptr (); element = &((struct tui_win_element *) locator->content[0])->which_element.locator; if (element->addr == 0) { struct minimal_symbol *main_symbol; /* Find address of the start of program. Note: this should be language specific. */ main_symbol = lookup_minimal_symbol ("main", NULL, NULL); if (main_symbol == 0) main_symbol = lookup_minimal_symbol ("MAIN", NULL, NULL); if (main_symbol == 0) main_symbol = lookup_minimal_symbol ("_start", NULL, NULL); if (main_symbol) addr = SYMBOL_VALUE_ADDRESS (main_symbol); else addr = 0; } else /* The target is executing. */ { gdbarch = element->gdbarch; addr = element->addr; } *gdbarch_p = gdbarch; *addr_p = addr; }
/* Function to print the frame information for the TUI. */ void tui_show_frame_info (struct frame_info *fi) { struct tui_win_info *win_info; int i; if (fi) { int start_line, i; CORE_ADDR low; struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); int source_already_displayed; struct symtab_and_line sal; find_frame_sal (fi, &sal); source_already_displayed = sal.symtab != 0 && tui_source_is_displayed (sal.symtab->filename); tui_set_locator_info (sal.symtab == 0 ? "??" : sal.symtab->filename, tui_get_function_from_frame (fi), sal.line, get_frame_pc (fi)); tui_show_locator_content (); start_line = 0; for (i = 0; i < (tui_source_windows ())->count; i++) { union tui_which_element *item; win_info = (tui_source_windows ())->list[i]; item = &((struct tui_win_element *) locator->content[0])->which_element; if (win_info == TUI_SRC_WIN) { start_line = (item->locator.line_no - (win_info->generic.viewport_height / 2)) + 1; if (start_line <= 0) start_line = 1; } else { if (find_pc_partial_function (get_frame_pc (fi), (char **) NULL, &low, (CORE_ADDR) 0) == 0) error (_("No function contains program counter for selected frame.")); else low = tui_get_low_disassembly_address (low, get_frame_pc (fi)); } if (win_info == TUI_SRC_WIN) { struct tui_line_or_address l; l.loa = LOA_LINE; l.u.line_no = start_line; if (!(source_already_displayed && tui_line_is_displayed (item->locator.line_no, win_info, TRUE))) tui_update_source_window (win_info, sal.symtab, l, TRUE); else { l.u.line_no = item->locator.line_no; tui_set_is_exec_point_at (l, win_info); } } else { if (win_info == TUI_DISASM_WIN) { struct tui_line_or_address a; a.loa = LOA_ADDRESS; a.u.addr = low; if (!tui_addr_is_displayed (item->locator.addr, win_info, TRUE)) tui_update_source_window (win_info, sal.symtab, a, TRUE); else { a.u.addr = item->locator.addr; tui_set_is_exec_point_at (a, win_info); } } } tui_update_exec_info (win_info); } } else { tui_set_locator_info (NULL, NULL, 0, (CORE_ADDR) 0); tui_show_locator_content (); for (i = 0; i < (tui_source_windows ())->count; i++) { win_info = (tui_source_windows ())->list[i]; tui_clear_source_content (win_info, EMPTY_SOURCE_PROMPT); tui_update_exec_info (win_info); } } }
/* Show the Source/Data/Command or the Dissassembly/Data/Command layout. */ static void show_data (enum tui_layout_type new_layout) { int total_height = (tui_term_height () - TUI_CMD_WIN->generic.height); int src_height, data_height; enum tui_win_type win_type; struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); data_height = total_height / 2; src_height = total_height - data_height; tui_make_all_invisible (); tui_make_invisible (locator); make_data_window (&TUI_DATA_WIN, data_height, 0); TUI_DATA_WIN->can_highlight = TRUE; if (new_layout == SRC_DATA_COMMAND) win_type = SRC_WIN; else win_type = DISASSEM_WIN; if (tui_win_list[win_type] == NULL) { if (win_type == SRC_WIN) make_source_window (&tui_win_list[win_type], src_height, data_height - 1); else make_disasm_window (&tui_win_list[win_type], src_height, data_height - 1); locator = init_and_make_win (locator, LOCATOR_WIN, 2 /* 1 */ , tui_term_width (), 0, total_height - 1, DONT_BOX_WINDOW); } else { init_gen_win_info (&tui_win_list[win_type]->generic, tui_win_list[win_type]->generic.type, src_height, tui_win_list[win_type]->generic.width, tui_win_list[win_type]->detail.source_info.execution_info->width, data_height - 1); init_gen_win_info (tui_win_list[win_type]->detail.source_info.execution_info, EXEC_INFO_WIN, src_height, 3, 0, data_height - 1); tui_make_visible (&tui_win_list[win_type]->generic); tui_make_visible (tui_win_list[win_type]->detail.source_info.execution_info); init_gen_win_info (locator, LOCATOR_WIN, 2 /* 1 */ , tui_term_width (), 0, total_height - 1); } tui_win_list[win_type]->detail.source_info.has_locator = TRUE; tui_make_visible (locator); tui_show_locator_content (); tui_add_to_source_windows (tui_win_list[win_type]); tui_set_current_layout_to (new_layout); }
/* Show the Source/Disassem/Command layout. */ static void show_source_disasm_command (void) { if (tui_current_layout () != SRC_DISASSEM_COMMAND) { int cmd_height, src_height, asm_height; if (TUI_CMD_WIN != NULL) cmd_height = TUI_CMD_WIN->generic.height; else cmd_height = tui_term_height () / 3; src_height = (tui_term_height () - cmd_height) / 2; asm_height = tui_term_height () - (src_height + cmd_height); if (TUI_SRC_WIN == NULL) make_source_window (&TUI_SRC_WIN, src_height, 0); else { init_gen_win_info (&TUI_SRC_WIN->generic, TUI_SRC_WIN->generic.type, src_height, TUI_SRC_WIN->generic.width, TUI_SRC_WIN->detail.source_info.execution_info->width, 0); TUI_SRC_WIN->can_highlight = TRUE; init_gen_win_info (TUI_SRC_WIN->detail.source_info.execution_info, EXEC_INFO_WIN, src_height, 3, 0, 0); tui_make_visible (&TUI_SRC_WIN->generic); tui_make_visible (TUI_SRC_WIN->detail.source_info.execution_info); TUI_SRC_WIN->detail.source_info.has_locator = FALSE;; } if (TUI_SRC_WIN != NULL) { struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); tui_show_source_content (TUI_SRC_WIN); if (TUI_DISASM_WIN == NULL) { make_disasm_window (&TUI_DISASM_WIN, asm_height, src_height - 1); locator = init_and_make_win (locator, LOCATOR_WIN, 2 /* 1 */ , tui_term_width (), 0, (src_height + asm_height) - 1, DONT_BOX_WINDOW); } else { init_gen_win_info (locator, LOCATOR_WIN, 2 /* 1 */ , tui_term_width (), 0, (src_height + asm_height) - 1); TUI_DISASM_WIN->detail.source_info.has_locator = TRUE; init_gen_win_info (&TUI_DISASM_WIN->generic, TUI_DISASM_WIN->generic.type, asm_height, TUI_DISASM_WIN->generic.width, TUI_DISASM_WIN->detail.source_info.execution_info->width, src_height - 1); init_gen_win_info (TUI_DISASM_WIN->detail.source_info.execution_info, EXEC_INFO_WIN, asm_height, 3, 0, src_height - 1); TUI_DISASM_WIN->can_highlight = TRUE; tui_make_visible (&TUI_DISASM_WIN->generic); tui_make_visible (TUI_DISASM_WIN->detail.source_info.execution_info); } if (TUI_DISASM_WIN != NULL) { TUI_SRC_WIN->detail.source_info.has_locator = FALSE; TUI_DISASM_WIN->detail.source_info.has_locator = TRUE; tui_make_visible (locator); tui_show_locator_content (); tui_show_source_content (TUI_DISASM_WIN); if (TUI_CMD_WIN == NULL) make_command_window (&TUI_CMD_WIN, cmd_height, tui_term_height () - cmd_height); else { init_gen_win_info (&TUI_CMD_WIN->generic, TUI_CMD_WIN->generic.type, TUI_CMD_WIN->generic.height, TUI_CMD_WIN->generic.width, 0, TUI_CMD_WIN->generic.origin.y); TUI_CMD_WIN->can_highlight = FALSE; tui_make_visible (&TUI_CMD_WIN->generic); } if (TUI_CMD_WIN != NULL) tui_refresh_win (&TUI_CMD_WIN->generic); } } tui_set_current_layout_to (SRC_DISASSEM_COMMAND); } }
/* Function to set the disassembly window's content. */ enum tui_status tui_set_disassem_content (CORE_ADDR pc) { enum tui_status ret = TUI_FAILURE; int i; int offset = TUI_DISASM_WIN->detail.source_info.horizontal_offset; int line_width, max_lines; CORE_ADDR cur_pc; struct tui_gen_win_info * locator = tui_locator_win_info_ptr (); int tab_len = tui_default_tab_len (); struct tui_asm_line* asm_lines; int insn_pos; int addr_size, max_size; char* line; if (pc == 0) return TUI_FAILURE; ret = tui_alloc_source_buffer (TUI_DISASM_WIN); if (ret != TUI_SUCCESS) return ret; TUI_DISASM_WIN->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS; TUI_DISASM_WIN->detail.source_info.start_line_or_addr.u.addr = pc; cur_pc = (CORE_ADDR) (((struct tui_win_element *) locator->content[0])->which_element.locator.addr); max_lines = TUI_DISASM_WIN->generic.height - 2; /* account for hilite */ /* Get temporary table that will hold all strings (addr & insn). */ asm_lines = (struct tui_asm_line*) alloca (sizeof (struct tui_asm_line) * max_lines); memset (asm_lines, 0, sizeof (struct tui_asm_line) * max_lines); line_width = TUI_DISASM_WIN->generic.width - 1; tui_disassemble (asm_lines, pc, max_lines); /* See what is the maximum length of an address and of a line. */ addr_size = 0; max_size = 0; for (i = 0; i < max_lines; i++) { size_t len = strlen (asm_lines[i].addr_string); if (len > addr_size) addr_size = len; len = strlen (asm_lines[i].insn) + tab_len; if (len > max_size) max_size = len; } max_size += addr_size + tab_len; /* Allocate memory to create each line. */ line = (char*) alloca (max_size); insn_pos = (1 + (addr_size / tab_len)) * tab_len; /* Now construct each line */ for (i = 0; i < max_lines; i++) { struct tui_win_element * element; struct tui_source_element* src; int cur_len; element = (struct tui_win_element *) TUI_DISASM_WIN->generic.content[i]; src = &element->which_element.source; strcpy (line, asm_lines[i].addr_string); cur_len = strlen (line); /* Add spaces to make the instructions start on the same column */ while (cur_len < insn_pos) { strcat (line, " "); cur_len++; } strcat (line, asm_lines[i].insn); /* Now copy the line taking the offset into account */ if (strlen (line) > offset) strcpy (src->line, &line[offset]); else src->line[0] = '\0'; src->line_or_addr.loa = LOA_ADDRESS; src->line_or_addr.u.addr = asm_lines[i].addr; src->is_exec_point = asm_lines[i].addr == cur_pc; /* See whether there is a breakpoint installed. */ src->has_break = (!src->is_exec_point && breakpoint_here_p (pc) != no_breakpoint_here); xfree (asm_lines[i].addr_string); xfree (asm_lines[i].insn); } TUI_DISASM_WIN->generic.content_size = i; return TUI_SUCCESS; }
void tui_free_window (struct tui_win_info * win_info) { struct tui_gen_win_info * generic_win; switch (win_info->generic.type) { case SRC_WIN: case DISASSEM_WIN: generic_win = tui_locator_win_info_ptr (); if (generic_win != (struct tui_gen_win_info *) NULL) { tui_delete_win (generic_win->handle); generic_win->handle = (WINDOW *) NULL; } tui_free_win_content (generic_win); if (win_info->detail.source_info.filename) { xfree (win_info->detail.source_info.filename); win_info->detail.source_info.filename = 0; } generic_win = win_info->detail.source_info.execution_info; if (generic_win != (struct tui_gen_win_info *) NULL) { tui_delete_win (generic_win->handle); generic_win->handle = (WINDOW *) NULL; tui_free_win_content (generic_win); } break; case DATA_WIN: if (win_info->generic.content != NULL) { tui_free_data_content (win_info->detail.data_display_info.regs_content, win_info->detail.data_display_info.regs_content_count); win_info->detail.data_display_info.regs_content = (tui_win_content) NULL; win_info->detail.data_display_info.regs_content_count = 0; tui_free_data_content (win_info->detail.data_display_info.data_content, win_info->detail.data_display_info.data_content_count); win_info->detail.data_display_info.data_content = (tui_win_content) NULL; win_info->detail.data_display_info.data_content_count = 0; win_info->detail.data_display_info.regs_display_type = TUI_UNDEFINED_REGS; win_info->detail.data_display_info.regs_column_count = 1; win_info->detail.data_display_info.display_regs = FALSE; win_info->generic.content = NULL; win_info->generic.content_size = 0; } break; default: break; } if (win_info->generic.handle != (WINDOW *) NULL) { tui_delete_win (win_info->generic.handle); win_info->generic.handle = (WINDOW *) NULL; tui_free_win_content (&win_info->generic); } if (win_info->generic.title) xfree (win_info->generic.title); xfree (win_info); }
/* Function to display source in the source window. */ enum tui_status tui_set_source_content (struct symtab *s, int line_no, int noerror) { enum tui_status ret = TUI_FAILURE; if (s != (struct symtab *) NULL && s->filename != (char *) NULL) { FILE *stream; int i, desc, c, line_width, nlines; char *src_line = 0; if ((ret = tui_alloc_source_buffer (TUI_SRC_WIN)) == TUI_SUCCESS) { line_width = TUI_SRC_WIN->generic.width - 1; /* Take hilite (window border) into account, when calculating the number of lines */ nlines = (line_no + (TUI_SRC_WIN->generic.height - 2)) - line_no; desc = open_source_file (s); if (desc < 0) { if (!noerror) { char *name = alloca (strlen (s->filename) + 100); sprintf (name, "%s:%d", s->filename, line_no); print_sys_errmsg (name, errno); } ret = TUI_FAILURE; } else { if (s->line_charpos == 0) find_source_lines (s, desc); if (line_no < 1 || line_no > s->nlines) { close (desc); printf_unfiltered ( "Line number %d out of range; %s has %d lines.\n", line_no, s->filename, s->nlines); } else if (lseek (desc, s->line_charpos[line_no - 1], 0) < 0) { close (desc); perror_with_name (s->filename); } else { int offset, cur_line_no, cur_line, cur_len, threshold; struct tui_gen_win_info * locator = tui_locator_win_info_ptr (); struct tui_source_info * src = &TUI_SRC_WIN->detail.source_info; if (TUI_SRC_WIN->generic.title) xfree (TUI_SRC_WIN->generic.title); TUI_SRC_WIN->generic.title = xstrdup (s->filename); if (src->filename) xfree (src->filename); src->filename = xstrdup (s->filename); /* Determine the threshold for the length of the line and the offset to start the display. */ offset = src->horizontal_offset; threshold = (line_width - 1) + offset; stream = fdopen (desc, FOPEN_RT); clearerr (stream); cur_line = 0; src->start_line_or_addr.loa = LOA_LINE; cur_line_no = src->start_line_or_addr.u.line_no = line_no; if (offset > 0) src_line = (char *) xmalloc ( (threshold + 1) * sizeof (char)); while (cur_line < nlines) { struct tui_win_element * element = (struct tui_win_element *) TUI_SRC_WIN->generic.content[cur_line]; /* get the first character in the line */ c = fgetc (stream); if (offset == 0) src_line = ((struct tui_win_element *) TUI_SRC_WIN->generic.content[ cur_line])->which_element.source.line; /* Init the line with the line number */ sprintf (src_line, "%-6d", cur_line_no); cur_len = strlen (src_line); i = cur_len - ((cur_len / tui_default_tab_len ()) * tui_default_tab_len ()); while (i < tui_default_tab_len ()) { src_line[cur_len] = ' '; i++; cur_len++; } src_line[cur_len] = (char) 0; /* Set whether element is the execution point and whether there is a break point on it. */ element->which_element.source.line_or_addr.loa = LOA_LINE; element->which_element.source.line_or_addr.u.line_no = cur_line_no; element->which_element.source.is_exec_point = (strcmp (((struct tui_win_element *) locator->content[0])->which_element.locator.file_name, s->filename) == 0 && cur_line_no == ((struct tui_win_element *) locator->content[0])->which_element.locator.line_no); if (c != EOF) { i = strlen (src_line) - 1; do { if ((c != '\n') && (c != '\r') && (++i < threshold)) { if (c < 040 && c != '\t') { src_line[i++] = '^'; src_line[i] = c + 0100; } else if (c == 0177) { src_line[i++] = '^'; src_line[i] = '?'; } else { /* Store the charcter in the line buffer. If it is a tab, then translate to the correct number of chars so we don't overwrite our buffer. */ if (c == '\t') { int j, max_tab_len = tui_default_tab_len (); for (j = i - ( (i / max_tab_len) * max_tab_len); ((j < max_tab_len) && i < threshold); i++, j++) src_line[i] = ' '; i--; } else src_line[i] = c; } src_line[i + 1] = 0; } else { /* If we have not reached EOL, then eat chars until we do */ while (c != EOF && c != '\n' && c != '\r') c = fgetc (stream); } } while (c != EOF && c != '\n' && c != '\r' && i < threshold && (c = fgetc (stream))); } /* Now copy the line taking the offset into account */ if (strlen (src_line) > offset) strcpy (((struct tui_win_element *) TUI_SRC_WIN->generic.content[ cur_line])->which_element.source.line, &src_line[offset]); else ((struct tui_win_element *) TUI_SRC_WIN->generic.content[ cur_line])->which_element.source.line[0] = (char) 0; cur_line++; cur_line_no++; } if (offset > 0) xfree (src_line); fclose (stream); TUI_SRC_WIN->generic.content_size = nlines; ret = TUI_SUCCESS; } } } } return ret; }
int tui_show_frame_info (struct frame_info *fi) { struct tui_win_info *win_info; int locator_changed_p; int i; if (fi) { int start_line, i; CORE_ADDR low; struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); int source_already_displayed; CORE_ADDR pc; symtab_and_line sal = find_frame_sal (fi); source_already_displayed = sal.symtab != 0 && tui_source_is_displayed (symtab_to_fullname (sal.symtab)); if (get_frame_pc_if_available (fi, &pc)) locator_changed_p = tui_set_locator_info (get_frame_arch (fi), (sal.symtab == 0 ? "??" : symtab_to_fullname (sal.symtab)), tui_get_function_from_frame (fi), sal.line, pc); else locator_changed_p = tui_set_locator_info (get_frame_arch (fi), "??", _("<unavailable>"), sal.line, 0); /* If the locator information has not changed, then frame information has not changed. If frame information has not changed, then the windows' contents will not change. So don't bother refreshing the windows. */ if (!locator_changed_p) return 0; tui_show_locator_content (); start_line = 0; for (i = 0; i < (tui_source_windows ())->count; i++) { union tui_which_element *item; win_info = (tui_source_windows ())->list[i]; item = &locator->content[0]->which_element; if (win_info == TUI_SRC_WIN) { start_line = (item->locator.line_no - (win_info->generic.viewport_height / 2)) + 1; if (start_line <= 0) start_line = 1; } else { if (find_pc_partial_function (get_frame_pc (fi), (const char **) NULL, &low, NULL) == 0) { /* There is no symbol available for current PC. There is no safe way how to "disassemble backwards". */ low = get_frame_pc (fi); } else low = tui_get_low_disassembly_address (get_frame_arch (fi), low, get_frame_pc (fi)); } if (win_info == TUI_SRC_WIN) { struct tui_line_or_address l; l.loa = LOA_LINE; l.u.line_no = start_line; if (!(source_already_displayed && tui_line_is_displayed (item->locator.line_no, win_info, TRUE))) tui_update_source_window (win_info, get_frame_arch (fi), sal.symtab, l, TRUE); else { l.u.line_no = item->locator.line_no; tui_set_is_exec_point_at (l, win_info); } } else { if (win_info == TUI_DISASM_WIN) { struct tui_line_or_address a; a.loa = LOA_ADDRESS; a.u.addr = low; if (!tui_addr_is_displayed (item->locator.addr, win_info, TRUE)) tui_update_source_window (win_info, get_frame_arch (fi), sal.symtab, a, TRUE); else { a.u.addr = item->locator.addr; tui_set_is_exec_point_at (a, win_info); } } } tui_update_exec_info (win_info); } return 1; } else { locator_changed_p = tui_set_locator_info (NULL, NULL, NULL, 0, (CORE_ADDR) 0); if (!locator_changed_p) return 0; tui_show_locator_content (); for (i = 0; i < (tui_source_windows ())->count; i++) { win_info = (tui_source_windows ())->list[i]; tui_clear_source_content (win_info, EMPTY_SOURCE_PROMPT); tui_update_exec_info (win_info); } return 1; } }
/* Show the Source/Command or the Disassem layout. */ static void show_source_or_disasm_and_command (enum tui_layout_type layout_type) { if (tui_current_layout () != layout_type) { struct tui_win_info **win_info_ptr; int src_height, cmd_height; struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); if (TUI_CMD_WIN != NULL) cmd_height = TUI_CMD_WIN->generic.height; else cmd_height = tui_term_height () / 3; src_height = tui_term_height () - cmd_height; if (layout_type == SRC_COMMAND) win_info_ptr = &TUI_SRC_WIN; else win_info_ptr = &TUI_DISASM_WIN; if ((*win_info_ptr) == NULL) { if (layout_type == SRC_COMMAND) make_source_window (win_info_ptr, src_height - 1, 0); else make_disasm_window (win_info_ptr, src_height - 1, 0); locator = init_and_make_win (locator, LOCATOR_WIN, 2 /* 1 */ , tui_term_width (), 0, src_height - 1, DONT_BOX_WINDOW); } else { init_gen_win_info (locator, LOCATOR_WIN, 2 /* 1 */ , tui_term_width (), 0, src_height - 1); (*win_info_ptr)->detail.source_info.has_locator = TRUE; init_gen_win_info (&(*win_info_ptr)->generic, (*win_info_ptr)->generic.type, src_height - 1, (*win_info_ptr)->generic.width, (*win_info_ptr)->detail.source_info.execution_info->width, 0); init_gen_win_info ((*win_info_ptr)->detail.source_info.execution_info, EXEC_INFO_WIN, src_height - 1, 3, 0, 0); (*win_info_ptr)->can_highlight = TRUE; tui_make_visible (&(*win_info_ptr)->generic); tui_make_visible ((*win_info_ptr)->detail.source_info.execution_info); } if ((*win_info_ptr) != NULL) { (*win_info_ptr)->detail.source_info.has_locator = TRUE; tui_make_visible (locator); tui_show_locator_content (); tui_show_source_content (*win_info_ptr); if (TUI_CMD_WIN == NULL) { make_command_window (&TUI_CMD_WIN, cmd_height, src_height); tui_refresh_win (&TUI_CMD_WIN->generic); } else { init_gen_win_info (&TUI_CMD_WIN->generic, TUI_CMD_WIN->generic.type, TUI_CMD_WIN->generic.height, TUI_CMD_WIN->generic.width, TUI_CMD_WIN->generic.origin.x, TUI_CMD_WIN->generic.origin.y); TUI_CMD_WIN->can_highlight = FALSE; tui_make_visible (&TUI_CMD_WIN->generic); } } tui_set_current_layout_to (layout_type); } }
/* Function to set the disassembly window's content. */ enum tui_status tui_set_disassem_content (struct gdbarch *gdbarch, CORE_ADDR pc) { enum tui_status ret = TUI_FAILURE; int i; int offset = TUI_DISASM_WIN->detail.source_info.horizontal_offset; int max_lines, line_width; CORE_ADDR cur_pc; struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); int tab_len = tui_tab_width; struct tui_asm_line *asm_lines; int insn_pos; int addr_size, insn_size; char *line; if (pc == 0) return TUI_FAILURE; ret = tui_alloc_source_buffer (TUI_DISASM_WIN); if (ret != TUI_SUCCESS) return ret; TUI_DISASM_WIN->detail.source_info.gdbarch = gdbarch; TUI_DISASM_WIN->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS; TUI_DISASM_WIN->detail.source_info.start_line_or_addr.u.addr = pc; cur_pc = locator->content[0]->which_element.locator.addr; /* Window size, excluding highlight box. */ max_lines = TUI_DISASM_WIN->generic.height - 2; line_width = TUI_DISASM_WIN->generic.width - 2; /* Get temporary table that will hold all strings (addr & insn). */ asm_lines = XALLOCAVEC (struct tui_asm_line, max_lines); memset (asm_lines, 0, sizeof (struct tui_asm_line) * max_lines); tui_disassemble (gdbarch, asm_lines, pc, max_lines); /* Determine maximum address- and instruction lengths. */ addr_size = 0; insn_size = 0; for (i = 0; i < max_lines; i++) { size_t len = strlen (asm_lines[i].addr_string); if (len > addr_size) addr_size = len; len = strlen (asm_lines[i].insn); if (len > insn_size) insn_size = len; } /* Align instructions to the same column. */ insn_pos = (1 + (addr_size / tab_len)) * tab_len; /* Allocate memory to create each line. */ line = (char*) alloca (insn_pos + insn_size + 1); /* Now construct each line. */ for (i = 0; i < max_lines; i++) { struct tui_win_element *element; struct tui_source_element *src; int cur_len; element = TUI_DISASM_WIN->generic.content[i]; src = &element->which_element.source; strcpy (line, asm_lines[i].addr_string); cur_len = strlen (line); memset (line + cur_len, ' ', insn_pos - cur_len); strcpy (line + insn_pos, asm_lines[i].insn); /* Now copy the line taking the offset into account. */ if (strlen (line) > offset) { strncpy (src->line, &line[offset], line_width); src->line[line_width] = '\0'; } else src->line[0] = '\0'; src->line_or_addr.loa = LOA_ADDRESS; src->line_or_addr.u.addr = asm_lines[i].addr; src->is_exec_point = asm_lines[i].addr == cur_pc; /* See whether there is a breakpoint installed. */ src->has_break = (!src->is_exec_point && breakpoint_here_p (current_program_space->aspace, pc) != no_breakpoint_here); xfree (asm_lines[i].addr_string); xfree (asm_lines[i].insn); } TUI_DISASM_WIN->generic.content_size = i; return TUI_SUCCESS; }