Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI display source/assembly window. |
f33c6cbf | 2 | |
6aba47ca | 3 | Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007 |
48426bc2 | 4 | Free Software Foundation, Inc. |
f33c6cbf | 5 | |
f377b406 SC |
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 | |
88d83552 EZ |
22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 | Boston, MA 02110-1301, USA. */ | |
c906108c SS |
24 | |
25 | #include "defs.h" | |
26 | #include <ctype.h> | |
27 | #include "symtab.h" | |
28 | #include "frame.h" | |
29 | #include "breakpoint.h" | |
fd0407d6 | 30 | #include "value.h" |
52575520 | 31 | #include "source.h" |
c906108c | 32 | |
d7b2e967 AC |
33 | #include "tui/tui.h" |
34 | #include "tui/tui-data.h" | |
35 | #include "tui/tui-stack.h" | |
36 | #include "tui/tui-win.h" | |
37 | #include "tui/tui-wingeneral.h" | |
38 | #include "tui/tui-winsource.h" | |
39 | #include "tui/tui-source.h" | |
40 | #include "tui/tui-disasm.h" | |
c906108c | 41 | |
88289b6e | 42 | #include "gdb_string.h" |
6a83354a | 43 | #include "gdb_curses.h" |
362c05fe | 44 | #include "gdb_assert.h" |
c906108c | 45 | |
1f393769 | 46 | /* Function to display the "main" routine. */ |
c906108c | 47 | void |
1f393769 | 48 | tui_display_main (void) |
c906108c | 49 | { |
dd1abb8c | 50 | if ((tui_source_windows ())->count > 0) |
c906108c SS |
51 | { |
52 | CORE_ADDR addr; | |
53 | ||
65f05602 | 54 | addr = tui_get_begin_asm_address (); |
c774cec6 | 55 | if (addr != (CORE_ADDR) 0) |
c906108c SS |
56 | { |
57 | struct symtab_and_line sal; | |
58 | ||
f80bda8e | 59 | tui_update_source_windows_with_addr (addr); |
c906108c | 60 | sal = find_pc_line (addr, 0); |
2e17b763 | 61 | if (sal.symtab) |
47d3492a | 62 | tui_update_locator_filename (sal.symtab->filename); |
2e17b763 | 63 | else |
47d3492a | 64 | tui_update_locator_filename ("??"); |
c906108c SS |
65 | } |
66 | } | |
2e17b763 | 67 | } |
c906108c SS |
68 | |
69 | ||
70 | ||
f80bda8e AC |
71 | /* Function to display source in the source window. This function |
72 | initializes the horizontal scroll to 0. */ | |
c906108c | 73 | void |
6d012f14 | 74 | tui_update_source_window (struct tui_win_info * win_info, struct symtab *s, |
362c05fe | 75 | struct tui_line_or_address line_or_addr, int noerror) |
c906108c | 76 | { |
6d012f14 | 77 | win_info->detail.source_info.horizontal_offset = 0; |
6ba8e26f | 78 | tui_update_source_window_as_is (win_info, s, line_or_addr, noerror); |
c906108c SS |
79 | |
80 | return; | |
f80bda8e | 81 | } |
c906108c SS |
82 | |
83 | ||
f80bda8e AC |
84 | /* Function to display source in the source/asm window. This function |
85 | shows the source as specified by the horizontal offset. */ | |
c906108c | 86 | void |
6d012f14 | 87 | tui_update_source_window_as_is (struct tui_win_info * win_info, struct symtab *s, |
362c05fe | 88 | struct tui_line_or_address line_or_addr, int noerror) |
c906108c | 89 | { |
22940a24 | 90 | enum tui_status ret; |
c906108c | 91 | |
6d012f14 | 92 | if (win_info->generic.type == SRC_WIN) |
362c05fe | 93 | ret = tui_set_source_content (s, line_or_addr.u.line_no, noerror); |
c906108c | 94 | else |
362c05fe | 95 | ret = tui_set_disassem_content (line_or_addr.u.addr); |
c906108c SS |
96 | |
97 | if (ret == TUI_FAILURE) | |
98 | { | |
6d012f14 AC |
99 | tui_clear_source_content (win_info, EMPTY_SOURCE_PROMPT); |
100 | tui_clear_exec_info_content (win_info); | |
c906108c SS |
101 | } |
102 | else | |
103 | { | |
6d012f14 AC |
104 | tui_update_breakpoint_info (win_info, 0); |
105 | tui_show_source_content (win_info); | |
106 | tui_update_exec_info (win_info); | |
107 | if (win_info->generic.type == SRC_WIN) | |
c906108c | 108 | { |
52575520 EZ |
109 | struct symtab_and_line sal; |
110 | ||
362c05fe | 111 | sal.line = line_or_addr.u.line_no + |
6d012f14 | 112 | (win_info->generic.content_size - 2); |
52575520 EZ |
113 | sal.symtab = s; |
114 | set_current_source_symtab_and_line (&sal); | |
c906108c | 115 | /* |
c5aa993b JM |
116 | ** If the focus was in the asm win, put it in the src |
117 | ** win if we don't have a split layout | |
118 | */ | |
6d012f14 | 119 | if (tui_win_with_focus () == TUI_DISASM_WIN && |
dd1abb8c | 120 | tui_current_layout () != SRC_DISASSEM_COMMAND) |
6d012f14 | 121 | tui_set_win_focus_to (TUI_SRC_WIN); |
c906108c SS |
122 | } |
123 | } | |
124 | ||
125 | ||
126 | return; | |
f80bda8e | 127 | } |
c906108c SS |
128 | |
129 | ||
f80bda8e AC |
130 | /* Function to ensure that the source and/or disassemly windows |
131 | reflect the input address. */ | |
c906108c | 132 | void |
f80bda8e | 133 | tui_update_source_windows_with_addr (CORE_ADDR addr) |
c906108c | 134 | { |
c774cec6 | 135 | if (addr != 0) |
c906108c SS |
136 | { |
137 | struct symtab_and_line sal; | |
362c05fe | 138 | struct tui_line_or_address l; |
a4b99e53 | 139 | |
dd1abb8c | 140 | switch (tui_current_layout ()) |
c906108c SS |
141 | { |
142 | case DISASSEM_COMMAND: | |
143 | case DISASSEM_DATA_COMMAND: | |
65f05602 | 144 | tui_show_disassem (addr); |
c906108c SS |
145 | break; |
146 | case SRC_DISASSEM_COMMAND: | |
65f05602 | 147 | tui_show_disassem_and_update_source (addr); |
c906108c SS |
148 | break; |
149 | default: | |
c774cec6 | 150 | sal = find_pc_line (addr, 0); |
362c05fe AS |
151 | l.loa = LOA_LINE; |
152 | l.u.line_no = sal.line; | |
a358af15 | 153 | tui_show_symtab_source (sal.symtab, l, FALSE); |
c906108c SS |
154 | break; |
155 | } | |
156 | } | |
157 | else | |
158 | { | |
159 | int i; | |
160 | ||
dd1abb8c | 161 | for (i = 0; i < (tui_source_windows ())->count; i++) |
c906108c | 162 | { |
96c1eda2 | 163 | struct tui_win_info * win_info = (tui_source_windows ())->list[i]; |
c906108c | 164 | |
6d012f14 AC |
165 | tui_clear_source_content (win_info, EMPTY_SOURCE_PROMPT); |
166 | tui_clear_exec_info_content (win_info); | |
c906108c SS |
167 | } |
168 | } | |
6ba8e26f | 169 | } |
c906108c | 170 | |
f80bda8e AC |
171 | /* Function to ensure that the source and/or disassemly windows |
172 | reflect the input address. */ | |
c906108c | 173 | void |
f80bda8e | 174 | tui_update_source_windows_with_line (struct symtab *s, int line) |
c906108c | 175 | { |
84b1e7c7 | 176 | CORE_ADDR pc; |
362c05fe | 177 | struct tui_line_or_address l; |
a4b99e53 | 178 | |
dd1abb8c | 179 | switch (tui_current_layout ()) |
c906108c SS |
180 | { |
181 | case DISASSEM_COMMAND: | |
182 | case DISASSEM_DATA_COMMAND: | |
84b1e7c7 | 183 | find_line_pc (s, line, &pc); |
f80bda8e | 184 | tui_update_source_windows_with_addr (pc); |
c906108c SS |
185 | break; |
186 | default: | |
362c05fe AS |
187 | l.loa = LOA_LINE; |
188 | l.u.line_no = line; | |
a358af15 | 189 | tui_show_symtab_source (s, l, FALSE); |
dd1abb8c | 190 | if (tui_current_layout () == SRC_DISASSEM_COMMAND) |
84b1e7c7 SC |
191 | { |
192 | find_line_pc (s, line, &pc); | |
65f05602 | 193 | tui_show_disassem (pc); |
84b1e7c7 | 194 | } |
c906108c SS |
195 | break; |
196 | } | |
197 | ||
198 | return; | |
f80bda8e | 199 | } |
c906108c | 200 | |
c906108c | 201 | void |
6ba8e26f | 202 | tui_clear_source_content (struct tui_win_info * win_info, int display_prompt) |
c906108c | 203 | { |
6d012f14 | 204 | if (win_info != NULL) |
c906108c | 205 | { |
d02c80cd | 206 | int i; |
c906108c | 207 | |
6d012f14 | 208 | win_info->generic.content_in_use = FALSE; |
6ba8e26f | 209 | tui_erase_source_content (win_info, display_prompt); |
6d012f14 | 210 | for (i = 0; i < win_info->generic.content_size; i++) |
c906108c | 211 | { |
2a8854a7 | 212 | struct tui_win_element * element = |
6d012f14 AC |
213 | (struct tui_win_element *) win_info->generic.content[i]; |
214 | element->which_element.source.has_break = FALSE; | |
215 | element->which_element.source.is_exec_point = FALSE; | |
c906108c SS |
216 | } |
217 | } | |
6ba8e26f | 218 | } |
c906108c SS |
219 | |
220 | ||
c906108c | 221 | void |
6ba8e26f | 222 | tui_erase_source_content (struct tui_win_info * win_info, int display_prompt) |
c906108c | 223 | { |
6ba8e26f AC |
224 | int x_pos; |
225 | int half_width = (win_info->generic.width - 2) / 2; | |
c906108c | 226 | |
6d012f14 | 227 | if (win_info->generic.handle != (WINDOW *) NULL) |
c906108c | 228 | { |
6d012f14 AC |
229 | werase (win_info->generic.handle); |
230 | tui_check_and_display_highlight_if_needed (win_info); | |
6ba8e26f | 231 | if (display_prompt == EMPTY_SOURCE_PROMPT) |
c906108c | 232 | { |
6ba8e26f | 233 | char *no_src_str; |
c906108c | 234 | |
6d012f14 | 235 | if (win_info->generic.type == SRC_WIN) |
6ba8e26f | 236 | no_src_str = NO_SRC_STRING; |
c906108c | 237 | else |
6ba8e26f AC |
238 | no_src_str = NO_DISASSEM_STRING; |
239 | if (strlen (no_src_str) >= half_width) | |
240 | x_pos = 1; | |
c906108c | 241 | else |
6ba8e26f | 242 | x_pos = half_width - strlen (no_src_str); |
6d012f14 AC |
243 | mvwaddstr (win_info->generic.handle, |
244 | (win_info->generic.height / 2), | |
6ba8e26f AC |
245 | x_pos, |
246 | no_src_str); | |
c906108c SS |
247 | |
248 | /* elz: added this function call to set the real contents of | |
c5aa993b JM |
249 | the window to what is on the screen, so that later calls |
250 | to refresh, do display | |
251 | the correct stuff, and not the old image */ | |
c906108c | 252 | |
6ba8e26f | 253 | tui_set_source_content_nil (win_info, no_src_str); |
c906108c | 254 | } |
6d012f14 | 255 | tui_refresh_win (&win_info->generic); |
c906108c | 256 | } |
6ba8e26f | 257 | } |
c906108c SS |
258 | |
259 | ||
bc712bbf SC |
260 | /* Redraw the complete line of a source or disassembly window. */ |
261 | static void | |
6d012f14 | 262 | tui_show_source_line (struct tui_win_info * win_info, int lineno) |
bc712bbf | 263 | { |
2a8854a7 | 264 | struct tui_win_element * line; |
bc712bbf SC |
265 | int x, y; |
266 | ||
6d012f14 AC |
267 | line = (struct tui_win_element *) win_info->generic.content[lineno - 1]; |
268 | if (line->which_element.source.is_exec_point) | |
269 | wattron (win_info->generic.handle, A_STANDOUT); | |
bc712bbf | 270 | |
6d012f14 AC |
271 | mvwaddstr (win_info->generic.handle, lineno, 1, |
272 | line->which_element.source.line); | |
273 | if (line->which_element.source.is_exec_point) | |
274 | wattroff (win_info->generic.handle, A_STANDOUT); | |
bc712bbf SC |
275 | |
276 | /* Clear to end of line but stop before the border. */ | |
6d012f14 AC |
277 | getyx (win_info->generic.handle, y, x); |
278 | while (x + 1 < win_info->generic.width) | |
bc712bbf | 279 | { |
6d012f14 AC |
280 | waddch (win_info->generic.handle, ' '); |
281 | getyx (win_info->generic.handle, y, x); | |
bc712bbf SC |
282 | } |
283 | } | |
284 | ||
c906108c | 285 | void |
6d012f14 | 286 | tui_show_source_content (struct tui_win_info * win_info) |
c906108c | 287 | { |
6d012f14 | 288 | if (win_info->generic.content_size > 0) |
c906108c | 289 | { |
bc712bbf SC |
290 | int lineno; |
291 | ||
6d012f14 AC |
292 | for (lineno = 1; lineno <= win_info->generic.content_size; lineno++) |
293 | tui_show_source_line (win_info, lineno); | |
c906108c | 294 | } |
bc712bbf | 295 | else |
6d012f14 | 296 | tui_erase_source_content (win_info, TRUE); |
bc712bbf | 297 | |
6d012f14 AC |
298 | tui_check_and_display_highlight_if_needed (win_info); |
299 | tui_refresh_win (&win_info->generic); | |
300 | win_info->generic.content_in_use = TRUE; | |
bc712bbf | 301 | } |
c906108c SS |
302 | |
303 | ||
f80bda8e | 304 | /* Scroll the source forward or backward horizontally. */ |
c906108c | 305 | void |
6d012f14 | 306 | tui_horizontal_source_scroll (struct tui_win_info * win_info, |
2a8854a7 | 307 | enum tui_scroll_direction direction, |
6ba8e26f | 308 | int num_to_scroll) |
c906108c | 309 | { |
6d012f14 | 310 | if (win_info->generic.content != NULL) |
c906108c SS |
311 | { |
312 | int offset; | |
313 | struct symtab *s; | |
52575520 | 314 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
c906108c | 315 | |
52575520 | 316 | if (cursal.symtab == (struct symtab *) NULL) |
206415a3 | 317 | s = find_pc_symtab (get_frame_pc (get_selected_frame (NULL))); |
c906108c | 318 | else |
52575520 | 319 | s = cursal.symtab; |
c906108c SS |
320 | |
321 | if (direction == LEFT_SCROLL) | |
6ba8e26f | 322 | offset = win_info->detail.source_info.horizontal_offset + num_to_scroll; |
c906108c SS |
323 | else |
324 | { | |
325 | if ((offset = | |
6ba8e26f | 326 | win_info->detail.source_info.horizontal_offset - num_to_scroll) < 0) |
c906108c SS |
327 | offset = 0; |
328 | } | |
6d012f14 AC |
329 | win_info->detail.source_info.horizontal_offset = offset; |
330 | tui_update_source_window_as_is (win_info, s, | |
2a8854a7 | 331 | ((struct tui_win_element *) |
6d012f14 | 332 | win_info->generic.content[0])->which_element.source.line_or_addr, |
f80bda8e | 333 | FALSE); |
c906108c SS |
334 | } |
335 | ||
336 | return; | |
6ba8e26f | 337 | } |
c906108c SS |
338 | |
339 | ||
6d012f14 | 340 | /* Set or clear the has_break flag in the line whose line is line_no. */ |
c906108c | 341 | void |
362c05fe | 342 | tui_set_is_exec_point_at (struct tui_line_or_address l, struct tui_win_info * win_info) |
c906108c | 343 | { |
00b90ae2 | 344 | int changed = 0; |
c906108c | 345 | int i; |
6d012f14 | 346 | tui_win_content content = (tui_win_content) win_info->generic.content; |
c906108c SS |
347 | |
348 | i = 0; | |
6d012f14 | 349 | while (i < win_info->generic.content_size) |
c906108c | 350 | { |
6ba8e26f | 351 | int new_state; |
362c05fe AS |
352 | struct tui_line_or_address content_loa = |
353 | content[i]->which_element.source.line_or_addr; | |
354 | ||
355 | gdb_assert (l.loa == LOA_ADDRESS || l.loa == LOA_LINE); | |
356 | gdb_assert (content_loa.loa == LOA_LINE | |
357 | || content_loa.loa == LOA_ADDRESS); | |
358 | if (content_loa.loa == l.loa | |
359 | && ((l.loa == LOA_LINE && content_loa.u.line_no == l.u.line_no) | |
360 | || (content_loa.u.addr == l.u.addr))) | |
6ba8e26f | 361 | new_state = TRUE; |
c906108c | 362 | else |
6ba8e26f AC |
363 | new_state = FALSE; |
364 | if (new_state != content[i]->which_element.source.is_exec_point) | |
00b90ae2 SC |
365 | { |
366 | changed++; | |
6ba8e26f | 367 | content[i]->which_element.source.is_exec_point = new_state; |
6d012f14 | 368 | tui_show_source_line (win_info, i + 1); |
00b90ae2 | 369 | } |
c906108c SS |
370 | i++; |
371 | } | |
00b90ae2 | 372 | if (changed) |
6d012f14 | 373 | tui_refresh_win (&win_info->generic); |
00b90ae2 | 374 | } |
c906108c | 375 | |
00b2bad4 SC |
376 | /* Update the execution windows to show the active breakpoints. |
377 | This is called whenever a breakpoint is inserted, removed or | |
378 | has its state changed. */ | |
c906108c | 379 | void |
d02c80cd | 380 | tui_update_all_breakpoint_info (void) |
c906108c | 381 | { |
2a8854a7 | 382 | struct tui_list *list = tui_source_windows (); |
c906108c | 383 | int i; |
c906108c | 384 | |
00b2bad4 | 385 | for (i = 0; i < list->count; i++) |
c906108c | 386 | { |
96c1eda2 | 387 | struct tui_win_info * win = list->list[i]; |
c906108c | 388 | |
00b2bad4 SC |
389 | if (tui_update_breakpoint_info (win, FALSE)) |
390 | { | |
f80bda8e | 391 | tui_update_exec_info (win); |
00b2bad4 | 392 | } |
c906108c | 393 | } |
00b2bad4 | 394 | } |
c906108c SS |
395 | |
396 | ||
00b2bad4 | 397 | /* Scan the source window and the breakpoints to update the |
6d012f14 | 398 | has_break information for each line. |
00b2bad4 SC |
399 | Returns 1 if something changed and the execution window |
400 | must be refreshed. */ | |
401 | int | |
2a8854a7 | 402 | tui_update_breakpoint_info (struct tui_win_info * win, int current_only) |
c906108c SS |
403 | { |
404 | int i; | |
00b2bad4 | 405 | int need_refresh = 0; |
6d012f14 | 406 | struct tui_source_info * src = &win->detail.source_info; |
c906108c | 407 | |
6d012f14 | 408 | for (i = 0; i < win->generic.content_size; i++) |
00b2bad4 SC |
409 | { |
410 | struct breakpoint *bp; | |
411 | extern struct breakpoint *breakpoint_chain; | |
412 | int mode; | |
2a8854a7 | 413 | struct tui_source_element* line; |
00b2bad4 | 414 | |
6d012f14 AC |
415 | line = &((struct tui_win_element *) win->generic.content[i])->which_element.source; |
416 | if (current_only && !line->is_exec_point) | |
00b2bad4 SC |
417 | continue; |
418 | ||
419 | /* Scan each breakpoint to see if the current line has something to | |
420 | do with it. Identify enable/disabled breakpoints as well as | |
421 | those that we already hit. */ | |
422 | mode = 0; | |
423 | for (bp = breakpoint_chain; | |
424 | bp != (struct breakpoint *) NULL; | |
425 | bp = bp->next) | |
426 | { | |
362c05fe AS |
427 | gdb_assert (line->line_or_addr.loa == LOA_LINE |
428 | || line->line_or_addr.loa == LOA_ADDRESS); | |
6d012f14 | 429 | if ((win == TUI_SRC_WIN |
00b2bad4 SC |
430 | && bp->source_file |
431 | && (strcmp (src->filename, bp->source_file) == 0) | |
362c05fe AS |
432 | && line->line_or_addr.loa == LOA_LINE |
433 | && bp->line_number == line->line_or_addr.u.line_no) | |
6d012f14 | 434 | || (win == TUI_DISASM_WIN |
362c05fe AS |
435 | && line->line_or_addr.loa == LOA_ADDRESS |
436 | && bp->loc->address == line->line_or_addr.u.addr)) | |
00b2bad4 SC |
437 | { |
438 | if (bp->enable_state == bp_disabled) | |
439 | mode |= TUI_BP_DISABLED; | |
440 | else | |
441 | mode |= TUI_BP_ENABLED; | |
442 | if (bp->hit_count) | |
443 | mode |= TUI_BP_HIT; | |
444 | if (bp->cond) | |
445 | mode |= TUI_BP_CONDITIONAL; | |
446 | if (bp->type == bp_hardware_breakpoint) | |
447 | mode |= TUI_BP_HARDWARE; | |
448 | } | |
449 | } | |
6d012f14 | 450 | if (line->has_break != mode) |
00b2bad4 | 451 | { |
6d012f14 | 452 | line->has_break = mode; |
00b2bad4 SC |
453 | need_refresh = 1; |
454 | } | |
455 | } | |
456 | return need_refresh; | |
457 | } | |
c906108c | 458 | |
c906108c | 459 | |
6ba8e26f AC |
460 | /* Function to initialize the content of the execution info window, |
461 | based upon the input window which is either the source or | |
462 | disassembly window. */ | |
22940a24 | 463 | enum tui_status |
6ba8e26f | 464 | tui_set_exec_info_content (struct tui_win_info * win_info) |
c906108c | 465 | { |
22940a24 | 466 | enum tui_status ret = TUI_SUCCESS; |
c906108c | 467 | |
6d012f14 | 468 | if (win_info->detail.source_info.execution_info != (struct tui_gen_win_info *) NULL) |
c906108c | 469 | { |
6ba8e26f | 470 | struct tui_gen_win_info * exec_info_ptr = win_info->detail.source_info.execution_info; |
c906108c | 471 | |
6ba8e26f AC |
472 | if (exec_info_ptr->content == NULL) |
473 | exec_info_ptr->content = | |
6d012f14 | 474 | (void **) tui_alloc_content (win_info->generic.height, |
6ba8e26f AC |
475 | exec_info_ptr->type); |
476 | if (exec_info_ptr->content != NULL) | |
c906108c SS |
477 | { |
478 | int i; | |
479 | ||
6d012f14 AC |
480 | tui_update_breakpoint_info (win_info, 1); |
481 | for (i = 0; i < win_info->generic.content_size; i++) | |
c906108c | 482 | { |
2a8854a7 | 483 | struct tui_win_element * element; |
6ba8e26f | 484 | struct tui_win_element * src_element; |
00b2bad4 | 485 | int mode; |
c906108c | 486 | |
6ba8e26f AC |
487 | element = (struct tui_win_element *) exec_info_ptr->content[i]; |
488 | src_element = (struct tui_win_element *) win_info->generic.content[i]; | |
00b2bad4 | 489 | |
6d012f14 AC |
490 | memset(element->which_element.simple_string, ' ', |
491 | sizeof(element->which_element.simple_string)); | |
492 | element->which_element.simple_string[TUI_EXECINFO_SIZE - 1] = 0; | |
00b2bad4 SC |
493 | |
494 | /* Now update the exec info content based upon the state | |
495 | of each line as indicated by the source content. */ | |
6ba8e26f | 496 | mode = src_element->which_element.source.has_break; |
00b2bad4 | 497 | if (mode & TUI_BP_HIT) |
6d012f14 | 498 | element->which_element.simple_string[TUI_BP_HIT_POS] = |
00b2bad4 SC |
499 | (mode & TUI_BP_HARDWARE) ? 'H' : 'B'; |
500 | else if (mode & (TUI_BP_ENABLED | TUI_BP_DISABLED)) | |
6d012f14 | 501 | element->which_element.simple_string[TUI_BP_HIT_POS] = |
00b2bad4 SC |
502 | (mode & TUI_BP_HARDWARE) ? 'h' : 'b'; |
503 | ||
504 | if (mode & TUI_BP_ENABLED) | |
6d012f14 | 505 | element->which_element.simple_string[TUI_BP_BREAK_POS] = '+'; |
00b2bad4 | 506 | else if (mode & TUI_BP_DISABLED) |
6d012f14 | 507 | element->which_element.simple_string[TUI_BP_BREAK_POS] = '-'; |
00b2bad4 | 508 | |
6ba8e26f | 509 | if (src_element->which_element.source.is_exec_point) |
6d012f14 | 510 | element->which_element.simple_string[TUI_EXEC_POS] = '>'; |
c906108c | 511 | } |
6ba8e26f | 512 | exec_info_ptr->content_size = win_info->generic.content_size; |
c906108c SS |
513 | } |
514 | else | |
515 | ret = TUI_FAILURE; | |
516 | } | |
517 | ||
518 | return ret; | |
00b2bad4 | 519 | } |
c906108c SS |
520 | |
521 | ||
c906108c | 522 | void |
6ba8e26f | 523 | tui_show_exec_info_content (struct tui_win_info * win_info) |
c906108c | 524 | { |
6ba8e26f AC |
525 | struct tui_gen_win_info * exec_info = win_info->detail.source_info.execution_info; |
526 | int cur_line; | |
527 | ||
528 | werase (exec_info->handle); | |
529 | tui_refresh_win (exec_info); | |
530 | for (cur_line = 1; (cur_line <= exec_info->content_size); cur_line++) | |
531 | mvwaddstr (exec_info->handle, | |
532 | cur_line, | |
c906108c | 533 | 0, |
2a8854a7 | 534 | ((struct tui_win_element *) |
6ba8e26f AC |
535 | exec_info->content[cur_line - 1])->which_element.simple_string); |
536 | tui_refresh_win (exec_info); | |
537 | exec_info->content_in_use = TRUE; | |
f80bda8e | 538 | } |
c906108c SS |
539 | |
540 | ||
c906108c | 541 | void |
6d012f14 | 542 | tui_erase_exec_info_content (struct tui_win_info * win_info) |
c906108c | 543 | { |
6ba8e26f | 544 | struct tui_gen_win_info * exec_info = win_info->detail.source_info.execution_info; |
c906108c | 545 | |
6ba8e26f AC |
546 | werase (exec_info->handle); |
547 | tui_refresh_win (exec_info); | |
f80bda8e | 548 | } |
c906108c | 549 | |
c906108c | 550 | void |
6d012f14 | 551 | tui_clear_exec_info_content (struct tui_win_info * win_info) |
c906108c | 552 | { |
6d012f14 AC |
553 | win_info->detail.source_info.execution_info->content_in_use = FALSE; |
554 | tui_erase_exec_info_content (win_info); | |
c906108c SS |
555 | |
556 | return; | |
f80bda8e | 557 | } |
c906108c | 558 | |
f80bda8e | 559 | /* Function to update the execution info window. */ |
c906108c | 560 | void |
6d012f14 | 561 | tui_update_exec_info (struct tui_win_info * win_info) |
c906108c | 562 | { |
6ba8e26f AC |
563 | tui_set_exec_info_content (win_info); |
564 | tui_show_exec_info_content (win_info); | |
565 | } | |
c906108c | 566 | |
f80bda8e | 567 | enum tui_status |
6d012f14 | 568 | tui_alloc_source_buffer (struct tui_win_info *win_info) |
c906108c | 569 | { |
d02c80cd AC |
570 | char *src_line_buf; |
571 | int i, line_width, max_lines; | |
c906108c | 572 | |
6ba8e26f AC |
573 | max_lines = win_info->generic.height; /* less the highlight box */ |
574 | line_width = win_info->generic.width - 1; | |
c906108c | 575 | /* |
81b7c67a MS |
576 | * Allocate the buffer for the source lines. Do this only once |
577 | * since they will be re-used for all source displays. The only | |
578 | * other time this will be done is when a window's size changes. | |
c5aa993b | 579 | */ |
6d012f14 | 580 | if (win_info->generic.content == NULL) |
c906108c | 581 | { |
81b7c67a MS |
582 | src_line_buf = (char *) |
583 | xmalloc ((max_lines * line_width) * sizeof (char)); | |
6ba8e26f | 584 | if (src_line_buf == (char *) NULL) |
c906108c | 585 | { |
81b7c67a MS |
586 | fputs_unfiltered ("Unable to Allocate Memory for Source or Disassembly Display.\n", |
587 | gdb_stderr); | |
588 | return TUI_FAILURE; | |
589 | } | |
590 | /* allocate the content list */ | |
591 | if ((win_info->generic.content = | |
592 | (void **) tui_alloc_content (max_lines, SRC_WIN)) == NULL) | |
593 | { | |
594 | xfree (src_line_buf); | |
595 | fputs_unfiltered ("Unable to Allocate Memory for Source or Disassembly Display.\n", | |
596 | gdb_stderr); | |
597 | return TUI_FAILURE; | |
c906108c | 598 | } |
6ba8e26f | 599 | for (i = 0; i < max_lines; i++) |
2a8854a7 | 600 | ((struct tui_win_element *) |
6d012f14 | 601 | win_info->generic.content[i])->which_element.source.line = |
6ba8e26f | 602 | src_line_buf + (line_width * i); |
c906108c | 603 | } |
c906108c | 604 | |
81b7c67a | 605 | return TUI_SUCCESS; |
6ba8e26f | 606 | } |
c906108c SS |
607 | |
608 | ||
f80bda8e AC |
609 | /* Answer whether the a particular line number or address is displayed |
610 | in the current source window. */ | |
c906108c | 611 | int |
6d012f14 | 612 | tui_line_is_displayed (int line, struct tui_win_info * win_info, |
6ba8e26f | 613 | int check_threshold) |
c906108c | 614 | { |
6ba8e26f | 615 | int is_displayed = FALSE; |
c906108c SS |
616 | int i, threshold; |
617 | ||
6ba8e26f | 618 | if (check_threshold) |
c906108c SS |
619 | threshold = SCROLL_THRESHOLD; |
620 | else | |
621 | threshold = 0; | |
622 | i = 0; | |
6ba8e26f | 623 | while (i < win_info->generic.content_size - threshold && !is_displayed) |
c906108c | 624 | { |
6ba8e26f | 625 | is_displayed = (((struct tui_win_element *) |
362c05fe AS |
626 | win_info->generic.content[i])->which_element.source.line_or_addr.loa |
627 | == LOA_LINE) | |
628 | && (((struct tui_win_element *) | |
629 | win_info->generic.content[i])->which_element.source.line_or_addr.u.line_no | |
630 | == (int) line); | |
c906108c SS |
631 | i++; |
632 | } | |
633 | ||
6ba8e26f | 634 | return is_displayed; |
f80bda8e | 635 | } |
c906108c SS |
636 | |
637 | ||
f80bda8e AC |
638 | /* Answer whether the a particular line number or address is displayed |
639 | in the current source window. */ | |
a4b99e53 | 640 | int |
6d012f14 | 641 | tui_addr_is_displayed (CORE_ADDR addr, struct tui_win_info * win_info, |
6ba8e26f | 642 | int check_threshold) |
a4b99e53 | 643 | { |
6ba8e26f | 644 | int is_displayed = FALSE; |
a4b99e53 SC |
645 | int i, threshold; |
646 | ||
6ba8e26f | 647 | if (check_threshold) |
a4b99e53 SC |
648 | threshold = SCROLL_THRESHOLD; |
649 | else | |
650 | threshold = 0; | |
651 | i = 0; | |
6ba8e26f | 652 | while (i < win_info->generic.content_size - threshold && !is_displayed) |
a4b99e53 | 653 | { |
6ba8e26f | 654 | is_displayed = (((struct tui_win_element *) |
362c05fe AS |
655 | win_info->generic.content[i])->which_element.source.line_or_addr.loa |
656 | == LOA_ADDRESS) | |
657 | && (((struct tui_win_element *) | |
658 | win_info->generic.content[i])->which_element.source.line_or_addr.u.addr | |
659 | == addr); | |
a4b99e53 SC |
660 | i++; |
661 | } | |
662 | ||
6ba8e26f | 663 | return is_displayed; |
a4b99e53 SC |
664 | } |
665 | ||
666 | ||
c906108c SS |
667 | /***************************************** |
668 | ** STATIC LOCAL FUNCTIONS ** | |
669 | ******************************************/ |