Move source window common to code to tui-winsource.[ch]
[deliverable/binutils-gdb.git] / gdb / tui / tui-winsource.c
CommitLineData
f377b406 1/* TUI display source/assembly window.
f33c6cbf 2
42a4f53d 3 Copyright (C) 1998-2019 Free Software Foundation, Inc.
f33c6cbf 4
f377b406
SC
5 Contributed by Hewlett-Packard Company.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
f377b406
SC
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
21
22#include "defs.h"
23#include <ctype.h>
24#include "symtab.h"
25#include "frame.h"
26#include "breakpoint.h"
fd0407d6 27#include "value.h"
52575520 28#include "source.h"
13274fc3 29#include "objfiles.h"
a7417d46 30#include "filenames.h"
c906108c 31
d7b2e967
AC
32#include "tui/tui.h"
33#include "tui/tui-data.h"
62f29fda 34#include "tui/tui-io.h"
d7b2e967
AC
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"
6a83354a 41#include "gdb_curses.h"
c906108c 42
1f393769 43/* Function to display the "main" routine. */
c906108c 44void
b4eb2452 45tui_display_main ()
c906108c 46{
b4eb2452 47 if (!tui_source_windows ().empty ())
c906108c 48 {
13274fc3 49 struct gdbarch *gdbarch;
c906108c
SS
50 CORE_ADDR addr;
51
13274fc3 52 tui_get_begin_asm_address (&gdbarch, &addr);
c774cec6 53 if (addr != (CORE_ADDR) 0)
c906108c 54 {
34248c3a 55 struct symtab *s;
c906108c 56
13274fc3 57 tui_update_source_windows_with_addr (gdbarch, addr);
34248c3a
DE
58 s = find_pc_line_symtab (addr);
59 if (s != NULL)
60 tui_update_locator_fullname (symtab_to_fullname (s));
2e17b763 61 else
56d397a3 62 tui_update_locator_fullname ("??");
c906108c
SS
63 }
64 }
2e17b763 65}
c906108c
SS
66
67
68
f80bda8e
AC
69/* Function to display source in the source window. This function
70 initializes the horizontal scroll to 0. */
c906108c 71void
be4da588 72tui_update_source_window (struct tui_source_window_base *win_info,
13274fc3 73 struct gdbarch *gdbarch,
08ef48c5
MS
74 struct symtab *s,
75 struct tui_line_or_address line_or_addr,
76 int noerror)
c906108c 77{
be4da588 78 win_info->horizontal_offset = 0;
13274fc3 79 tui_update_source_window_as_is (win_info, gdbarch, s, line_or_addr, noerror);
c906108c
SS
80
81 return;
f80bda8e 82}
c906108c
SS
83
84
f80bda8e
AC
85/* Function to display source in the source/asm window. This function
86 shows the source as specified by the horizontal offset. */
c906108c 87void
be4da588 88tui_update_source_window_as_is (struct tui_source_window_base *win_info,
13274fc3 89 struct gdbarch *gdbarch,
08ef48c5
MS
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
cb2ce893 96 if (win_info->type == SRC_WIN)
5813316f
TT
97 ret = tui_set_source_content (win_info, s, line_or_addr.u.line_no,
98 noerror);
c906108c 99 else
9d391078 100 ret = tui_set_disassem_content (win_info, gdbarch, line_or_addr.u.addr);
c906108c
SS
101
102 if (ret == TUI_FAILURE)
103 {
caf0bc4e 104 tui_clear_source_content (win_info);
6d012f14 105 tui_clear_exec_info_content (win_info);
c906108c
SS
106 }
107 else
108 {
0807ab7b 109 tui_update_breakpoint_info (win_info, nullptr, false);
6d012f14
AC
110 tui_show_source_content (win_info);
111 tui_update_exec_info (win_info);
cb2ce893 112 if (win_info->type == SRC_WIN)
c906108c 113 {
51abb421
PA
114 symtab_and_line sal;
115
362c05fe 116 sal.line = line_or_addr.u.line_no +
53e7cdba 117 (win_info->content.size () - 2);
52575520 118 sal.symtab = s;
eb822aa6 119 sal.pspace = SYMTAB_PSPACE (s);
51abb421 120 set_current_source_symtab_and_line (sal);
ef5eab5a
MS
121 /* If the focus was in the asm win, put it in the src win if
122 we don't have a split layout. */
e5908723
MS
123 if (tui_win_with_focus () == TUI_DISASM_WIN
124 && tui_current_layout () != SRC_DISASSEM_COMMAND)
5813316f 125 tui_set_win_focus_to (win_info);
c906108c
SS
126 }
127 }
128
129
130 return;
f80bda8e 131}
c906108c
SS
132
133
f80bda8e
AC
134/* Function to ensure that the source and/or disassemly windows
135 reflect the input address. */
c906108c 136void
13274fc3 137tui_update_source_windows_with_addr (struct gdbarch *gdbarch, CORE_ADDR addr)
c906108c 138{
c774cec6 139 if (addr != 0)
c906108c
SS
140 {
141 struct symtab_and_line sal;
362c05fe 142 struct tui_line_or_address l;
a4b99e53 143
dd1abb8c 144 switch (tui_current_layout ())
c906108c
SS
145 {
146 case DISASSEM_COMMAND:
147 case DISASSEM_DATA_COMMAND:
13274fc3 148 tui_show_disassem (gdbarch, addr);
c906108c
SS
149 break;
150 case SRC_DISASSEM_COMMAND:
13274fc3 151 tui_show_disassem_and_update_source (gdbarch, addr);
c906108c
SS
152 break;
153 default:
c774cec6 154 sal = find_pc_line (addr, 0);
362c05fe
AS
155 l.loa = LOA_LINE;
156 l.u.line_no = sal.line;
5813316f 157 tui_show_symtab_source (TUI_SRC_WIN, gdbarch, sal.symtab, l, FALSE);
c906108c
SS
158 break;
159 }
160 }
161 else
162 {
ad54d15b 163 for (struct tui_source_window_base *win_info : tui_source_windows ())
c906108c 164 {
caf0bc4e 165 tui_clear_source_content (win_info);
6d012f14 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 173void
f80bda8e 174tui_update_source_windows_with_line (struct symtab *s, int line)
c906108c 175{
13274fc3 176 struct gdbarch *gdbarch;
84b1e7c7 177 CORE_ADDR pc;
362c05fe 178 struct tui_line_or_address l;
13274fc3
UW
179
180 if (!s)
181 return;
182
eb822aa6 183 gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
13274fc3 184
dd1abb8c 185 switch (tui_current_layout ())
c906108c
SS
186 {
187 case DISASSEM_COMMAND:
188 case DISASSEM_DATA_COMMAND:
84b1e7c7 189 find_line_pc (s, line, &pc);
13274fc3 190 tui_update_source_windows_with_addr (gdbarch, pc);
c906108c
SS
191 break;
192 default:
362c05fe
AS
193 l.loa = LOA_LINE;
194 l.u.line_no = line;
5813316f 195 tui_show_symtab_source (TUI_SRC_WIN, gdbarch, s, l, FALSE);
dd1abb8c 196 if (tui_current_layout () == SRC_DISASSEM_COMMAND)
84b1e7c7
SC
197 {
198 find_line_pc (s, line, &pc);
13274fc3 199 tui_show_disassem (gdbarch, pc);
84b1e7c7 200 }
c906108c
SS
201 break;
202 }
203
204 return;
f80bda8e 205}
c906108c 206
c906108c 207void
caf0bc4e 208tui_clear_source_content (struct tui_source_window_base *win_info)
c906108c 209{
6d012f14 210 if (win_info != NULL)
c906108c 211 {
d02c80cd 212 int i;
c906108c 213
caf0bc4e 214 tui_erase_source_content (win_info);
53e7cdba 215 for (i = 0; i < win_info->content.size (); i++)
c906108c 216 {
53e7cdba 217 struct tui_source_element *element = &win_info->content[i];
1c5313c5 218
0598af48 219 element->break_mode = 0;
53e7cdba 220 element->is_exec_point = false;
c906108c
SS
221 }
222 }
6ba8e26f 223}
c906108c
SS
224
225
c906108c 226void
caf0bc4e 227tui_erase_source_content (struct tui_source_window_base *win_info)
c906108c 228{
6ba8e26f 229 int x_pos;
cb2ce893 230 int half_width = (win_info->width - 2) / 2;
c906108c 231
cb2ce893 232 if (win_info->handle != NULL)
c906108c 233 {
cb2ce893 234 werase (win_info->handle);
6d012f14 235 tui_check_and_display_highlight_if_needed (win_info);
caf0bc4e
TT
236
237 const char *no_src_str;
238
239 if (win_info->type == SRC_WIN)
240 no_src_str = NO_SRC_STRING;
241 else
242 no_src_str = NO_DISASSEM_STRING;
243 if (strlen (no_src_str) >= half_width)
244 x_pos = 1;
245 else
246 x_pos = half_width - strlen (no_src_str);
247 mvwaddstr (win_info->handle,
248 (win_info->height / 2),
249 x_pos,
250 (char *) no_src_str);
251
f31ec9af 252 win_info->content.clear ();
5b81daba 253 win_info->refresh_window ();
c906108c 254 }
6ba8e26f 255}
c906108c
SS
256
257
bc712bbf
SC
258/* Redraw the complete line of a source or disassembly window. */
259static void
53e7cdba 260tui_show_source_line (struct tui_source_window_base *win_info, int lineno)
bc712bbf 261{
53e7cdba 262 struct tui_source_element *line;
798e1c30 263 int x;
bc712bbf 264
53e7cdba
TT
265 line = &win_info->content[lineno - 1];
266 if (line->is_exec_point)
cb2ce893 267 tui_set_reverse_mode (win_info->handle, true);
bc712bbf 268
cb2ce893 269 wmove (win_info->handle, lineno, 1);
53e7cdba 270 tui_puts (line->line,
cb2ce893 271 win_info->handle);
53e7cdba 272 if (line->is_exec_point)
cb2ce893 273 tui_set_reverse_mode (win_info->handle, false);
bc712bbf
SC
274
275 /* Clear to end of line but stop before the border. */
cb2ce893
TT
276 x = getcurx (win_info->handle);
277 while (x + 1 < win_info->width)
798e1c30 278 {
cb2ce893
TT
279 waddch (win_info->handle, ' ');
280 x = getcurx (win_info->handle);
798e1c30 281 }
bc712bbf
SC
282}
283
c906108c 284void
7908abbf 285tui_show_source_content (struct tui_source_window_base *win_info)
c906108c 286{
53e7cdba 287 if (!win_info->content.empty ())
c906108c 288 {
bc712bbf
SC
289 int lineno;
290
53e7cdba 291 for (lineno = 1; lineno <= win_info->content.size (); lineno++)
6d012f14 292 tui_show_source_line (win_info, lineno);
c906108c 293 }
bc712bbf 294 else
caf0bc4e 295 tui_erase_source_content (win_info);
bc712bbf 296
6d012f14 297 tui_check_and_display_highlight_if_needed (win_info);
5b81daba 298 win_info->refresh_window ();
bc712bbf 299}
c906108c 300
ad54d15b 301/* See tui-data.h. */
6f11e682 302
5104fe36
TT
303void
304tui_source_window_base::clear_detail ()
305{
306 gdbarch = NULL;
307 start_line_or_addr.loa = LOA_ADDRESS;
308 start_line_or_addr.u.addr = 0;
309 horizontal_offset = 0;
310}
311
312tui_source_window_base::tui_source_window_base (enum tui_win_type type)
313 : tui_win_info (type),
314 execution_info (new tui_exec_info_window ())
315{
316 gdb_assert (type == SRC_WIN || type == DISASSEM_WIN);
317 start_line_or_addr.loa = LOA_ADDRESS;
318 start_line_or_addr.u.addr = 0;
319}
320
321
322tui_source_window_base::~tui_source_window_base ()
323{
324 xfree (fullname);
325 delete execution_info;
326}
327
328void
329tui_source_window_base::reset (int height, int width,
330 int origin_x, int origin_y)
331{
332 tui_gen_win_info::reset (height, width - 3,
333 origin_x + 3, origin_y);
334 execution_info->reset (height, 3, origin_x, origin_y);
335}
336
337/* See tui-data.h. */
338
339void
340tui_source_window_base::refresh_all ()
341{
342 tui_show_source_content (this);
343 tui_check_and_display_highlight_if_needed (this);
344 tui_erase_exec_info_content (this);
345 tui_update_exec_info (this);
346}
347
348/* See tui-data.h. */
349
350void
351tui_source_window_base::update_tab_width ()
352{
353 /* We don't really change the height of any windows, but
354 calling these 2 functions causes a complete regeneration
355 and redisplay of the window's contents, which will take
356 the new tab width into account. */
357 make_invisible_and_set_new_height (height);
358 make_visible_with_new_height ();
359}
360
361/* See tui-data.h. */
362
363void
364tui_source_window_base::set_new_height (int height)
365{
366 execution_info->make_visible (false);
367 execution_info->height = height;
368 execution_info->origin.y = origin.y;
369 if (height > 1)
370 execution_info->viewport_height = height - 1;
371 else
372 execution_info->viewport_height = height;
373 execution_info->viewport_height--;
374
375 if (m_has_locator)
376 {
377 tui_locator_window *gen_win_info = tui_locator_win_info_ptr ();
378 gen_win_info->make_visible (false);
379 gen_win_info->origin.y = origin.y + height;
380 }
381}
382
383/* See tui-data.h. */
384
385void
386tui_source_window_base::do_make_visible_with_new_height ()
387{
388 execution_info->make_visible (true);
389 if (!content.empty ())
390 {
391 struct tui_line_or_address line_or_addr;
392 struct symtab_and_line cursal
393 = get_current_source_symtab_and_line ();
394
395 line_or_addr = start_line_or_addr;
396 tui_update_source_window (this, gdbarch,
397 cursal.symtab, line_or_addr, TRUE);
398 }
399 else if (deprecated_safe_get_selected_frame () != NULL)
400 {
401 struct tui_line_or_address line;
402 struct symtab_and_line cursal
403 = get_current_source_symtab_and_line ();
404 struct frame_info *frame = deprecated_safe_get_selected_frame ();
405 struct gdbarch *gdbarch = get_frame_arch (frame);
406
407 struct symtab *s = find_pc_line_symtab (get_frame_pc (frame));
408 if (type == SRC_WIN)
409 {
410 line.loa = LOA_LINE;
411 line.u.line_no = cursal.line;
412 }
413 else
414 {
415 line.loa = LOA_ADDRESS;
416 find_line_pc (s, cursal.line, &line.u.addr);
417 }
418 tui_update_source_window (this, gdbarch, s, line, TRUE);
419 }
420 if (m_has_locator)
421 {
422 tui_locator_win_info_ptr ()->make_visible (true);
423 tui_show_locator_content ();
424 }
425}
426
427/* See tui-data.h. */
428
429void
430tui_source_window_base::make_visible (bool visible)
431{
432 execution_info->make_visible (visible);
433 tui_win_info::make_visible (visible);
434}
435
436/* See tui-data.h. */
437
438void
439tui_source_window_base::refresh_window ()
440{
441 execution_info->refresh_window ();
442 tui_win_info::refresh_window ();
443}
444
445/* See tui-data.h. */
446
6f11e682 447void
ad54d15b 448tui_source_window_base::refill ()
6f11e682
TT
449{
450 symtab *s = nullptr;
451
cb2ce893 452 if (type == SRC_WIN)
6f11e682
TT
453 {
454 symtab_and_line cursal = get_current_source_symtab_and_line ();
455 s = (cursal.symtab == NULL
456 ? find_pc_line_symtab (get_frame_pc (get_selected_frame (NULL)))
457 : cursal.symtab);
458 }
459
ad54d15b 460 tui_update_source_window_as_is (this, gdbarch, s,
53e7cdba 461 content[0].line_or_addr,
6f11e682
TT
462 FALSE);
463}
c906108c 464
f80bda8e 465/* Scroll the source forward or backward horizontally. */
6f11e682 466
c906108c 467void
c3bd716f 468tui_source_window_base::do_scroll_horizontal (int num_to_scroll)
c906108c 469{
53e7cdba 470 if (!content.empty ())
c906108c 471 {
c3bd716f
TT
472 int offset = horizontal_offset + num_to_scroll;
473 if (offset < 0)
474 offset = 0;
e6e41501 475 horizontal_offset = offset;
ad54d15b 476 refill ();
c906108c 477 }
6ba8e26f 478}
c906108c
SS
479
480
0598af48 481/* Set or clear the is_exec_point flag in the line whose line is
1cc6d956
MS
482 line_no. */
483
c906108c 484void
ad54d15b 485tui_source_window_base::set_is_exec_point_at (struct tui_line_or_address l)
c906108c 486{
02c28df0 487 bool changed = false;
c906108c 488 int i;
c906108c
SS
489
490 i = 0;
53e7cdba 491 while (i < content.size ())
c906108c 492 {
02c28df0 493 bool new_state;
362c05fe 494 struct tui_line_or_address content_loa =
53e7cdba 495 content[i].line_or_addr;
362c05fe
AS
496
497 gdb_assert (l.loa == LOA_ADDRESS || l.loa == LOA_LINE);
498 gdb_assert (content_loa.loa == LOA_LINE
499 || content_loa.loa == LOA_ADDRESS);
500 if (content_loa.loa == l.loa
501 && ((l.loa == LOA_LINE && content_loa.u.line_no == l.u.line_no)
f7952c57 502 || (l.loa == LOA_ADDRESS && content_loa.u.addr == l.u.addr)))
02c28df0 503 new_state = true;
c906108c 504 else
02c28df0 505 new_state = false;
53e7cdba 506 if (new_state != content[i].is_exec_point)
00b90ae2 507 {
02c28df0 508 changed = true;
53e7cdba 509 content[i].is_exec_point = new_state;
ad54d15b 510 tui_show_source_line (this, i + 1);
00b90ae2 511 }
c906108c
SS
512 i++;
513 }
00b90ae2 514 if (changed)
ad54d15b 515 refill ();
00b90ae2 516}
c906108c 517
0807ab7b
TT
518/* See tui-winsource.h. */
519
c906108c 520void
0807ab7b 521tui_update_all_breakpoint_info (struct breakpoint *being_deleted)
c906108c 522{
ad54d15b 523 for (tui_source_window_base *win : tui_source_windows ())
c906108c 524 {
0807ab7b 525 if (tui_update_breakpoint_info (win, being_deleted, false))
00b2bad4 526 {
f80bda8e 527 tui_update_exec_info (win);
00b2bad4 528 }
c906108c 529 }
00b2bad4 530}
c906108c
SS
531
532
0807ab7b 533/* Scan the source window and the breakpoints to update the break_mode
1cc6d956
MS
534 information for each line.
535
0807ab7b 536 Returns true if something changed and the execution window must be
1cc6d956
MS
537 refreshed. */
538
0807ab7b
TT
539bool
540tui_update_breakpoint_info (struct tui_source_window_base *win,
541 struct breakpoint *being_deleted,
542 bool current_only)
c906108c
SS
543{
544 int i;
0807ab7b 545 bool need_refresh = false;
c906108c 546
53e7cdba 547 for (i = 0; i < win->content.size (); i++)
00b2bad4
SC
548 {
549 struct breakpoint *bp;
550 extern struct breakpoint *breakpoint_chain;
5b6fe301 551 struct tui_source_element *line;
00b2bad4 552
53e7cdba 553 line = &win->content[i];
6d012f14 554 if (current_only && !line->is_exec_point)
00b2bad4
SC
555 continue;
556
557 /* Scan each breakpoint to see if the current line has something to
558 do with it. Identify enable/disabled breakpoints as well as
559 those that we already hit. */
0598af48 560 tui_bp_flags mode = 0;
00b2bad4 561 for (bp = breakpoint_chain;
cafb3438 562 bp != NULL;
00b2bad4
SC
563 bp = bp->next)
564 {
f8eba3c6
TT
565 struct bp_location *loc;
566
362c05fe
AS
567 gdb_assert (line->line_or_addr.loa == LOA_LINE
568 || line->line_or_addr.loa == LOA_ADDRESS);
f8eba3c6 569
0807ab7b
TT
570 if (bp == being_deleted)
571 continue;
572
f8eba3c6
TT
573 for (loc = bp->loc; loc != NULL; loc = loc->next)
574 {
c2cd8994 575 if (win->location_matches_p (loc, i))
f8eba3c6
TT
576 {
577 if (bp->enable_state == bp_disabled)
578 mode |= TUI_BP_DISABLED;
579 else
580 mode |= TUI_BP_ENABLED;
581 if (bp->hit_count)
582 mode |= TUI_BP_HIT;
583 if (bp->loc->cond)
584 mode |= TUI_BP_CONDITIONAL;
585 if (bp->type == bp_hardware_breakpoint)
586 mode |= TUI_BP_HARDWARE;
587 }
588 }
00b2bad4 589 }
0598af48 590 if (line->break_mode != mode)
00b2bad4 591 {
0598af48
TT
592 line->break_mode = mode;
593 need_refresh = true;
00b2bad4
SC
594 }
595 }
596 return need_refresh;
597}
c906108c 598
489e9d8b
TT
599/* See tui-data.h. */
600
601tui_exec_info_content *
602tui_exec_info_window::maybe_allocate_content (int n_elements)
603{
604 if (m_content == nullptr)
605 m_content = XNEWVEC (tui_exec_info_content, n_elements);
606 return m_content;
607}
608
c906108c 609
6ba8e26f
AC
610/* Function to initialize the content of the execution info window,
611 based upon the input window which is either the source or
612 disassembly window. */
73fbdc65 613void
21c32dca 614tui_set_exec_info_content (struct tui_source_window_base *win_info)
c906108c 615{
098f9ed4
TT
616 tui_exec_info_content *content
617 = win_info->execution_info->maybe_allocate_content (win_info->height);
c906108c 618
098f9ed4
TT
619 tui_update_breakpoint_info (win_info, nullptr, true);
620 for (int i = 0; i < win_info->content.size (); i++)
621 {
622 tui_exec_info_content &element = content[i];
623 struct tui_source_element *src_element;
624 tui_bp_flags mode;
625
626 src_element = &win_info->content[i];
627
628 memset (element, ' ', sizeof (tui_exec_info_content));
629 element[TUI_EXECINFO_SIZE - 1] = 0;
630
631 /* Now update the exec info content based upon the state
632 of each line as indicated by the source content. */
633 mode = src_element->break_mode;
634 if (mode & TUI_BP_HIT)
635 element[TUI_BP_HIT_POS] = (mode & TUI_BP_HARDWARE) ? 'H' : 'B';
636 else if (mode & (TUI_BP_ENABLED | TUI_BP_DISABLED))
637 element[TUI_BP_HIT_POS] = (mode & TUI_BP_HARDWARE) ? 'h' : 'b';
638
639 if (mode & TUI_BP_ENABLED)
640 element[TUI_BP_BREAK_POS] = '+';
641 else if (mode & TUI_BP_DISABLED)
642 element[TUI_BP_BREAK_POS] = '-';
643
644 if (src_element->is_exec_point)
645 element[TUI_EXEC_POS] = '>';
c906108c 646 }
00b2bad4 647}
c906108c
SS
648
649
c906108c 650void
21c32dca 651tui_show_exec_info_content (struct tui_source_window_base *win_info)
c906108c 652{
489e9d8b
TT
653 struct tui_exec_info_window *exec_info = win_info->execution_info;
654 const tui_exec_info_content *content = exec_info->get_content ();
6ba8e26f
AC
655
656 werase (exec_info->handle);
53e7cdba 657 for (int cur_line = 1; cur_line <= win_info->content.size (); cur_line++)
6ba8e26f
AC
658 mvwaddstr (exec_info->handle,
659 cur_line,
c906108c 660 0,
489e9d8b 661 content[cur_line - 1]);
5b81daba 662 exec_info->refresh_window ();
f80bda8e 663}
c906108c
SS
664
665
c906108c 666void
21c32dca 667tui_erase_exec_info_content (struct tui_source_window_base *win_info)
c906108c 668{
21c32dca 669 struct tui_gen_win_info *exec_info = win_info->execution_info;
c906108c 670
6ba8e26f 671 werase (exec_info->handle);
5b81daba 672 exec_info->refresh_window ();
f80bda8e 673}
c906108c 674
c906108c 675void
21c32dca 676tui_clear_exec_info_content (struct tui_source_window_base *win_info)
c906108c 677{
6d012f14 678 tui_erase_exec_info_content (win_info);
f80bda8e 679}
c906108c 680
f80bda8e 681/* Function to update the execution info window. */
c906108c 682void
21c32dca 683tui_update_exec_info (struct tui_source_window_base *win_info)
c906108c 684{
6ba8e26f
AC
685 tui_set_exec_info_content (win_info);
686 tui_show_exec_info_content (win_info);
687}
c906108c 688
29d2c474 689void
53e7cdba 690tui_alloc_source_buffer (struct tui_source_window_base *win_info)
c906108c 691{
d02c80cd 692 int i, line_width, max_lines;
c906108c 693
7bc2c8b8
AA
694 /* The window width/height includes the highlight box. Determine actual
695 content dimensions, including string null-terminators. */
cb2ce893
TT
696 max_lines = win_info->height - 2;
697 line_width = win_info->width - 2 + 1;
7bc2c8b8 698
62f29fda 699 /* Allocate the buffer for the source lines. */
53e7cdba
TT
700 win_info->content.resize (max_lines);
701 for (i = 0; i < max_lines; i++)
c906108c 702 {
53e7cdba
TT
703 if (win_info->content[i].line == nullptr)
704 win_info->content[i].line = (char *) xmalloc (line_width);
c906108c 705 }
6ba8e26f 706}
c906108c
SS
707
708
766062f6 709/* Answer whether a particular line number or address is displayed
f80bda8e 710 in the current source window. */
c906108c 711int
08ef48c5 712tui_line_is_displayed (int line,
53e7cdba 713 struct tui_source_window_base *win_info,
6ba8e26f 714 int check_threshold)
c906108c 715{
6ba8e26f 716 int is_displayed = FALSE;
c906108c
SS
717 int i, threshold;
718
6ba8e26f 719 if (check_threshold)
c906108c
SS
720 threshold = SCROLL_THRESHOLD;
721 else
722 threshold = 0;
723 i = 0;
53e7cdba 724 while (i < win_info->content.size () - threshold
e5908723 725 && !is_displayed)
c906108c 726 {
63ed8182 727 is_displayed
53e7cdba
TT
728 = win_info->content[i].line_or_addr.loa == LOA_LINE
729 && win_info->content[i].line_or_addr.u.line_no == line;
c906108c
SS
730 i++;
731 }
732
6ba8e26f 733 return is_displayed;
f80bda8e 734}
c906108c
SS
735
736
766062f6 737/* Answer whether a particular line number or address is displayed
f80bda8e 738 in the current source window. */
a4b99e53 739int
08ef48c5 740tui_addr_is_displayed (CORE_ADDR addr,
53e7cdba 741 struct tui_source_window_base *win_info,
08ef48c5 742 int check_threshold)
a4b99e53 743{
6ba8e26f 744 int is_displayed = FALSE;
a4b99e53
SC
745 int i, threshold;
746
6ba8e26f 747 if (check_threshold)
a4b99e53
SC
748 threshold = SCROLL_THRESHOLD;
749 else
750 threshold = 0;
751 i = 0;
53e7cdba 752 while (i < win_info->content.size () - threshold
e5908723 753 && !is_displayed)
a4b99e53 754 {
63ed8182 755 is_displayed
53e7cdba
TT
756 = win_info->content[i].line_or_addr.loa == LOA_ADDRESS
757 && win_info->content[i].line_or_addr.u.addr == addr;
a4b99e53
SC
758 i++;
759 }
760
6ba8e26f 761 return is_displayed;
a4b99e53 762}
This page took 2.435094 seconds and 4 git commands to generate.