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