* tuiWin.c (tuiStrDup): Remove, replaced by xstrdup.
[deliverable/binutils-gdb.git] / gdb / tui / tuiSourceWin.c
CommitLineData
f377b406
SC
1/* TUI display source/assembly window.
2 Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Hewlett-Packard Company.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
c906108c
SS
21
22#include "defs.h"
23#include <ctype.h>
24#include "symtab.h"
25#include "frame.h"
26#include "breakpoint.h"
27
28#include "tui.h"
29#include "tuiData.h"
30#include "tuiStack.h"
c774cec6
SC
31#include "tuiWin.h"
32#include "tuiGeneralWin.h"
c906108c
SS
33#include "tuiSourceWin.h"
34#include "tuiSource.h"
35#include "tuiDisassem.h"
36
37
38/*****************************************
39** EXTERNAL FUNCTION DECLS **
40******************************************/
41
42/*****************************************
43** EXTERNAL DATA DECLS **
44******************************************/
45extern int current_source_line;
46extern struct symtab *current_source_symtab;
47
48
49/*****************************************
50** STATIC LOCAL FUNCTIONS FORWARD DECLS **
51******************************************/
52
53/*****************************************
54** STATIC LOCAL DATA **
55******************************************/
56
57
58/*****************************************
59** PUBLIC FUNCTIONS **
60******************************************/
61
62/*********************************
63** SOURCE/DISASSEM FUNCTIONS **
64*********************************/
65
66/*
c5aa993b
JM
67 ** tuiSrcWinIsDisplayed().
68 */
c906108c 69int
c906108c 70tuiSrcWinIsDisplayed (void)
c906108c
SS
71{
72 return (m_winPtrNotNull (srcWin) && srcWin->generic.isVisible);
73} /* tuiSrcWinIsDisplayed */
74
75
76/*
c5aa993b
JM
77 ** tuiAsmWinIsDisplayed().
78 */
c906108c 79int
c906108c 80tuiAsmWinIsDisplayed (void)
c906108c
SS
81{
82 return (m_winPtrNotNull (disassemWin) && disassemWin->generic.isVisible);
83} /* tuiAsmWinIsDisplayed */
84
85
86/*
c5aa993b
JM
87 ** tuiDisplayMainFunction().
88 ** Function to display the "main" routine"
89 */
c906108c 90void
c906108c 91tuiDisplayMainFunction (void)
c906108c
SS
92{
93 if ((sourceWindows ())->count > 0)
94 {
95 CORE_ADDR addr;
96
97 addr = parse_and_eval_address ("main");
c774cec6 98 if (addr == (CORE_ADDR) 0)
c906108c 99 addr = parse_and_eval_address ("MAIN");
c774cec6 100 if (addr != (CORE_ADDR) 0)
c906108c
SS
101 {
102 struct symtab_and_line sal;
103
c774cec6 104 tuiUpdateSourceWindowsWithAddr (addr);
c906108c
SS
105 sal = find_pc_line (addr, 0);
106 tuiSwitchFilename (sal.symtab->filename);
107 }
108 }
109
110 return;
111} /* tuiDisplayMainFunction */
112
113
114
115/*
c5aa993b
JM
116 ** tuiUpdateSourceWindow().
117 ** Function to display source in the source window. This function
118 ** initializes the horizontal scroll to 0.
119 */
c906108c 120void
eca6576c
SC
121tuiUpdateSourceWindow (TuiWinInfoPtr winInfo, struct symtab *s,
122 Opaque lineOrAddr, int noerror)
c906108c
SS
123{
124 winInfo->detail.sourceInfo.horizontalOffset = 0;
125 tuiUpdateSourceWindowAsIs (winInfo, s, lineOrAddr, noerror);
126
127 return;
128} /* tuiUpdateSourceWindow */
129
130
131/*
c5aa993b
JM
132 ** tuiUpdateSourceWindowAsIs().
133 ** Function to display source in the source/asm window. This
134 ** function shows the source as specified by the horizontal offset.
135 */
c906108c 136void
eca6576c
SC
137tuiUpdateSourceWindowAsIs (TuiWinInfoPtr winInfo, struct symtab *s,
138 Opaque lineOrAddr, int noerror)
c906108c
SS
139{
140 TuiStatus ret;
141
142 if (winInfo->generic.type == SRC_WIN)
143 ret = tuiSetSourceContent (s, (int) lineOrAddr, noerror);
144 else
145 ret = tuiSetDisassemContent (s, (Opaque) lineOrAddr);
146
147 if (ret == TUI_FAILURE)
148 {
149 tuiClearSourceContent (winInfo, EMPTY_SOURCE_PROMPT);
150 tuiClearExecInfoContent (winInfo);
151 }
152 else
153 {
154 tuiEraseSourceContent (winInfo, NO_EMPTY_SOURCE_PROMPT);
155 tuiShowSourceContent (winInfo);
156 tuiUpdateExecInfo (winInfo);
157 if (winInfo->generic.type == SRC_WIN)
158 {
159 current_source_line = (int) lineOrAddr +
160 (winInfo->generic.contentSize - 2);
161 current_source_symtab = s;
162 /*
c5aa993b
JM
163 ** If the focus was in the asm win, put it in the src
164 ** win if we don't have a split layout
165 */
c906108c
SS
166 if (tuiWinWithFocus () == disassemWin &&
167 currentLayout () != SRC_DISASSEM_COMMAND)
168 tuiSetWinFocusTo (srcWin);
169 }
170 }
171
172
173 return;
174} /* tuiUpdateSourceWindowAsIs */
175
176
177/*
c5aa993b
JM
178 ** tuiUpdateSourceWindowsWithAddr().
179 ** Function to ensure that the source and/or disassemly windows
180 ** reflect the input address.
181 */
c906108c 182void
c774cec6 183tuiUpdateSourceWindowsWithAddr (CORE_ADDR addr)
c906108c 184{
c774cec6 185 if (addr != 0)
c906108c
SS
186 {
187 struct symtab_and_line sal;
188
189 switch (currentLayout ())
190 {
191 case DISASSEM_COMMAND:
192 case DISASSEM_DATA_COMMAND:
193 tuiShowDisassem (addr);
194 break;
195 case SRC_DISASSEM_COMMAND:
196 tuiShowDisassemAndUpdateSource (addr);
197 break;
198 default:
c774cec6
SC
199 sal = find_pc_line (addr, 0);
200 tuiShowSource (sal.symtab, sal.line, FALSE);
c906108c
SS
201 break;
202 }
203 }
204 else
205 {
206 int i;
207
208 for (i = 0; i < (sourceWindows ())->count; i++)
209 {
210 TuiWinInfoPtr winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
211
212 tuiClearSourceContent (winInfo, EMPTY_SOURCE_PROMPT);
213 tuiClearExecInfoContent (winInfo);
214 }
215 }
216
217 return;
218} /* tuiUpdateSourceWindowsWithAddr */
219
220
221/*
c5aa993b
JM
222 ** tui_vUpdateSourceWindowsWithAddr()
223 ** Update the source window with the address in a va_list
224 */
c906108c 225void
eca6576c 226tui_vUpdateSourceWindowsWithAddr (va_list args)
c906108c
SS
227{
228 Opaque addr = va_arg (args, Opaque);
229
230 tuiUpdateSourceWindowsWithAddr (addr);
231
232 return;
233} /* tui_vUpdateSourceWindowsWithAddr */
234
235
236/*
c5aa993b
JM
237 ** tuiUpdateSourceWindowsWithLine().
238 ** Function to ensure that the source and/or disassemly windows
239 ** reflect the input address.
240 */
c906108c 241void
eca6576c 242tuiUpdateSourceWindowsWithLine (struct symtab *s, int line)
c906108c 243{
84b1e7c7
SC
244 CORE_ADDR pc;
245
c906108c
SS
246 switch (currentLayout ())
247 {
248 case DISASSEM_COMMAND:
249 case DISASSEM_DATA_COMMAND:
84b1e7c7 250 find_line_pc (s, line, &pc);
c774cec6 251 tuiUpdateSourceWindowsWithAddr (pc);
c906108c
SS
252 break;
253 default:
c774cec6 254 tuiShowSource (s, line, FALSE);
c906108c 255 if (currentLayout () == SRC_DISASSEM_COMMAND)
84b1e7c7
SC
256 {
257 find_line_pc (s, line, &pc);
c774cec6 258 tuiShowDisassem (pc);
84b1e7c7 259 }
c906108c
SS
260 break;
261 }
262
263 return;
264} /* tuiUpdateSourceWindowsWithLine */
265
266
267/*
c5aa993b
JM
268 ** tui_vUpdateSourceWindowsWithLine()
269 ** Update the source window with the line number in a va_list
270 */
c906108c 271void
eca6576c 272tui_vUpdateSourceWindowsWithLine (va_list args)
c906108c
SS
273{
274 struct symtab *s = va_arg (args, struct symtab *);
275 int line = va_arg (args, int);
276
277 tuiUpdateSourceWindowsWithLine (s, line);
278
279 return;
280} /* tui_vUpdateSourceWindowsWithLine */
281
282
283/*
c5aa993b
JM
284 ** tuiClearSourceContent().
285 */
c906108c 286void
eca6576c 287tuiClearSourceContent (TuiWinInfoPtr winInfo, int displayPrompt)
c906108c
SS
288{
289 if (m_winPtrNotNull (winInfo))
290 {
291 register int i;
292
293 winInfo->generic.contentInUse = FALSE;
294 tuiEraseSourceContent (winInfo, displayPrompt);
295 for (i = 0; i < winInfo->generic.contentSize; i++)
296 {
297 TuiWinElementPtr element =
298 (TuiWinElementPtr) winInfo->generic.content[i];
299 element->whichElement.source.hasBreak = FALSE;
300 element->whichElement.source.isExecPoint = FALSE;
301 }
302 }
303
304 return;
305} /* tuiClearSourceContent */
306
307
308/*
c5aa993b
JM
309 ** tuiClearAllSourceWinsContent().
310 */
c906108c 311void
eca6576c 312tuiClearAllSourceWinsContent (int displayPrompt)
c906108c
SS
313{
314 int i;
315
316 for (i = 0; i < (sourceWindows ())->count; i++)
317 tuiClearSourceContent ((TuiWinInfoPtr) (sourceWindows ())->list[i],
318 displayPrompt);
319
320 return;
321} /* tuiClearAllSourceWinsContent */
322
323
324/*
c5aa993b
JM
325 ** tuiEraseSourceContent().
326 */
c906108c 327void
eca6576c 328tuiEraseSourceContent (TuiWinInfoPtr winInfo, int displayPrompt)
c906108c
SS
329{
330 int xPos;
331 int halfWidth = (winInfo->generic.width - 2) / 2;
332
333 if (winInfo->generic.handle != (WINDOW *) NULL)
334 {
335 werase (winInfo->generic.handle);
336 checkAndDisplayHighlightIfNeeded (winInfo);
337 if (displayPrompt == EMPTY_SOURCE_PROMPT)
338 {
339 char *noSrcStr;
340
341 if (winInfo->generic.type == SRC_WIN)
342 noSrcStr = NO_SRC_STRING;
343 else
344 noSrcStr = NO_DISASSEM_STRING;
345 if (strlen (noSrcStr) >= halfWidth)
346 xPos = 1;
347 else
348 xPos = halfWidth - strlen (noSrcStr);
349 mvwaddstr (winInfo->generic.handle,
350 (winInfo->generic.height / 2),
351 xPos,
352 noSrcStr);
353
354 /* elz: added this function call to set the real contents of
c5aa993b
JM
355 the window to what is on the screen, so that later calls
356 to refresh, do display
357 the correct stuff, and not the old image */
c906108c
SS
358
359 tuiSetSourceContentNil (winInfo, noSrcStr);
360 }
361 tuiRefreshWin (&winInfo->generic);
362 }
363 return;
364} /* tuiEraseSourceContent */
365
366
367/*
c5aa993b
JM
368 ** tuiEraseAllSourceContent().
369 */
c906108c 370void
eca6576c 371tuiEraseAllSourceWinsContent (int displayPrompt)
c906108c
SS
372{
373 int i;
374
375 for (i = 0; i < (sourceWindows ())->count; i++)
376 tuiEraseSourceContent ((TuiWinInfoPtr) (sourceWindows ())->list[i],
377 displayPrompt);
378
379 return;
380} /* tuiEraseAllSourceWinsContent */
381
382
383/*
c5aa993b
JM
384 ** tuiShowSourceContent().
385 */
c906108c 386void
eca6576c 387tuiShowSourceContent (TuiWinInfoPtr winInfo)
c906108c
SS
388{
389 int curLine, i, curX;
390
391 tuiEraseSourceContent (winInfo, (winInfo->generic.contentSize <= 0));
392 if (winInfo->generic.contentSize > 0)
393 {
394 char *line;
395
396 for (curLine = 1; (curLine <= winInfo->generic.contentSize); curLine++)
397 mvwaddstr (
398 winInfo->generic.handle,
399 curLine,
400 1,
401 ((TuiWinElementPtr)
402 winInfo->generic.content[curLine - 1])->whichElement.source.line);
403 }
404 checkAndDisplayHighlightIfNeeded (winInfo);
405 tuiRefreshWin (&winInfo->generic);
406 winInfo->generic.contentInUse = TRUE;
407
408 return;
409} /* tuiShowSourceContent */
410
411
412/*
c5aa993b
JM
413 ** tuiShowAllSourceWinsContent()
414 */
c906108c 415void
c906108c 416tuiShowAllSourceWinsContent (void)
c906108c
SS
417{
418 int i;
419
420 for (i = 0; i < (sourceWindows ())->count; i++)
421 tuiShowSourceContent ((TuiWinInfoPtr) (sourceWindows ())->list[i]);
422
423 return;
424} /* tuiShowAllSourceWinsContent */
425
426
427/*
c5aa993b
JM
428 ** tuiHorizontalSourceScroll().
429 ** Scroll the source forward or backward horizontally
430 */
c906108c 431void
eca6576c
SC
432tuiHorizontalSourceScroll (TuiWinInfoPtr winInfo,
433 TuiScrollDirection direction,
434 int numToScroll)
c906108c
SS
435{
436 if (winInfo->generic.content != (OpaquePtr) NULL)
437 {
438 int offset;
439 struct symtab *s;
440
441 if (current_source_symtab == (struct symtab *) NULL)
442 s = find_pc_symtab (selected_frame->pc);
443 else
444 s = current_source_symtab;
445
446 if (direction == LEFT_SCROLL)
447 offset = winInfo->detail.sourceInfo.horizontalOffset + numToScroll;
448 else
449 {
450 if ((offset =
451 winInfo->detail.sourceInfo.horizontalOffset - numToScroll) < 0)
452 offset = 0;
453 }
454 winInfo->detail.sourceInfo.horizontalOffset = offset;
455 tuiUpdateSourceWindowAsIs (
456 winInfo,
457 s,
458 ((winInfo == srcWin) ?
459 (Opaque) ((TuiWinElementPtr)
460 winInfo->generic.content[0])->whichElement.source.lineOrAddr.lineNo :
461 (Opaque) ((TuiWinElementPtr)
462 winInfo->generic.content[0])->whichElement.source.lineOrAddr.addr),
463 (int) FALSE);
464 }
465
466 return;
467} /* tuiHorizontalSourceScroll */
468
469
470/*
c5aa993b
JM
471 ** tuiSetHasExecPointAt().
472 ** Set or clear the hasBreak flag in the line whose line is lineNo.
473 */
c906108c 474void
eca6576c 475tuiSetIsExecPointAt (Opaque lineOrAddr, TuiWinInfoPtr winInfo)
c906108c
SS
476{
477 int i;
478 TuiWinContent content = (TuiWinContent) winInfo->generic.content;
479
480 i = 0;
481 while (i < winInfo->generic.contentSize)
482 {
483 if (content[i]->whichElement.source.lineOrAddr.addr == lineOrAddr)
484 content[i]->whichElement.source.isExecPoint = TRUE;
485 else
486 content[i]->whichElement.source.isExecPoint = FALSE;
487 i++;
488 }
489
490 return;
491} /* tuiSetIsExecPointAt */
492
493
494/*
c5aa993b
JM
495 ** tuiSetHasBreakAt().
496 ** Set or clear the hasBreak flag in the line whose line is lineNo.
497 */
c906108c 498void
eca6576c 499tuiSetHasBreakAt (struct breakpoint *bp, TuiWinInfoPtr winInfo, int hasBreak)
c906108c
SS
500{
501 int i;
502 TuiWinContent content = (TuiWinContent) winInfo->generic.content;
503
504 i = 0;
505 while (i < winInfo->generic.contentSize)
506 {
507 int gotIt;
508 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
509
510 if (winInfo == srcWin)
511 {
512 char *fileNameDisplayed = (char *) NULL;
513
514 if (((TuiWinElementPtr)
515 locator->content[0])->whichElement.locator.fileName !=
516 (char *) NULL)
517 fileNameDisplayed = ((TuiWinElementPtr)
518 locator->content[0])->whichElement.locator.fileName;
519 else if (current_source_symtab != (struct symtab *) NULL)
520 fileNameDisplayed = current_source_symtab->filename;
521
522 gotIt = (fileNameDisplayed != (char *) NULL &&
84b1e7c7 523 bp->source_file != NULL &&
c906108c
SS
524 (strcmp (bp->source_file, fileNameDisplayed) == 0) &&
525 content[i]->whichElement.source.lineOrAddr.lineNo ==
526 bp->line_number);
527 }
528 else
529 gotIt = (content[i]->whichElement.source.lineOrAddr.addr
c774cec6 530 == bp->address);
c906108c
SS
531 if (gotIt)
532 {
533 content[i]->whichElement.source.hasBreak = hasBreak;
534 break;
535 }
536 i++;
537 }
538
539 return;
540} /* tuiSetHasBreakAt */
541
542
543/*
c5aa993b
JM
544 ** tuiAllSetHasBreakAt().
545 ** Set or clear the hasBreak flag in all displayed source windows.
546 */
c906108c 547void
eca6576c 548tuiAllSetHasBreakAt (struct breakpoint *bp, int hasBreak)
c906108c
SS
549{
550 int i;
551
552 for (i = 0; i < (sourceWindows ())->count; i++)
553 tuiSetHasBreakAt (bp,
554 (TuiWinInfoPtr) (sourceWindows ())->list[i], hasBreak);
555
556 return;
557} /* tuiAllSetHasBreakAt */
558
559
560/*
c5aa993b
JM
561 ** tui_vAllSetHasBreakAt()
562 ** Set or clear the hasBreak flag in all displayed source windows,
563 ** with params in a va_list
564 */
c906108c 565void
eca6576c 566tui_vAllSetHasBreakAt (va_list args)
c906108c
SS
567{
568 struct breakpoint *bp = va_arg (args, struct breakpoint *);
569 int hasBreak = va_arg (args, int);
570
571 tuiAllSetHasBreakAt (bp, hasBreak);
572
573 return;
574} /* tui_vAllSetHasBreakAt */
575
576
577
578/*********************************
579** EXECUTION INFO FUNCTIONS **
580*********************************/
581
582/*
c5aa993b
JM
583 ** tuiSetExecInfoContent().
584 ** Function to initialize the content of the execution info window,
585 ** based upon the input window which is either the source or
586 ** disassembly window.
587 */
c906108c 588TuiStatus
eca6576c 589tuiSetExecInfoContent (TuiWinInfoPtr winInfo)
c906108c
SS
590{
591 TuiStatus ret = TUI_SUCCESS;
592
593 if (winInfo->detail.sourceInfo.executionInfo != (TuiGenWinInfoPtr) NULL)
594 {
595 TuiGenWinInfoPtr execInfoPtr = winInfo->detail.sourceInfo.executionInfo;
596
597 if (execInfoPtr->content == (OpaquePtr) NULL)
598 execInfoPtr->content =
599 (OpaquePtr) allocContent (winInfo->generic.height,
600 execInfoPtr->type);
601 if (execInfoPtr->content != (OpaquePtr) NULL)
602 {
603 int i;
604
605 for (i = 0; i < winInfo->generic.contentSize; i++)
606 {
607 TuiWinElementPtr element;
608 TuiWinElementPtr srcElement;
609
610 element = (TuiWinElementPtr) execInfoPtr->content[i];
611 srcElement = (TuiWinElementPtr) winInfo->generic.content[i];
612 /*
c5aa993b
JM
613 ** First check to see if we have a breakpoint that is
614 ** temporary. If so, and this is our current execution point,
615 ** then clear the break indicator.
616 */
c906108c
SS
617 if (srcElement->whichElement.source.hasBreak &&
618 srcElement->whichElement.source.isExecPoint)
619 {
620 struct breakpoint *bp;
621 int found = FALSE;
622 extern struct breakpoint *breakpoint_chain;
623
624 for (bp = breakpoint_chain;
625 (bp != (struct breakpoint *) NULL && !found);
626 bp = bp->next)
627 {
628 found =
629 (winInfo == srcWin &&
630 bp->line_number ==
631 srcElement->whichElement.source.lineOrAddr.lineNo) ||
632 (winInfo == disassemWin &&
633 bp->address == (CORE_ADDR)
634 srcElement->whichElement.source.lineOrAddr.addr);
635 if (found)
636 srcElement->whichElement.source.hasBreak =
637 (bp->disposition != del || bp->hit_count <= 0);
638 }
639 if (!found)
640 srcElement->whichElement.source.hasBreak = FALSE;
641 }
642 /*
c5aa993b
JM
643 ** Now update the exec info content based upon the state
644 ** of each line as indicated by the source content.
645 */
c906108c
SS
646 if (srcElement->whichElement.source.hasBreak &&
647 srcElement->whichElement.source.isExecPoint)
648 element->whichElement.simpleString = breakLocationStr ();
649 else if (srcElement->whichElement.source.hasBreak)
650 element->whichElement.simpleString = breakStr ();
651 else if (srcElement->whichElement.source.isExecPoint)
652 element->whichElement.simpleString = locationStr ();
653 else
654 element->whichElement.simpleString = blankStr ();
655 }
656 execInfoPtr->contentSize = winInfo->generic.contentSize;
657 }
658 else
659 ret = TUI_FAILURE;
660 }
661
662 return ret;
663} /* tuiSetExecInfoContent */
664
665
666/*
c5aa993b
JM
667 ** tuiShowExecInfoContent().
668 */
c906108c 669void
eca6576c 670tuiShowExecInfoContent (TuiWinInfoPtr winInfo)
c906108c
SS
671{
672 TuiGenWinInfoPtr execInfo = winInfo->detail.sourceInfo.executionInfo;
673 int curLine;
674
675 werase (execInfo->handle);
676 tuiRefreshWin (execInfo);
677 for (curLine = 1; (curLine <= execInfo->contentSize); curLine++)
678 mvwaddstr (execInfo->handle,
679 curLine,
680 0,
681 ((TuiWinElementPtr)
682 execInfo->content[curLine - 1])->whichElement.simpleString);
683 tuiRefreshWin (execInfo);
684 execInfo->contentInUse = TRUE;
685
686 return;
687} /* tuiShowExecInfoContent */
688
689
690/*
c5aa993b
JM
691 ** tuiShowAllExecInfosContent()
692 */
c906108c 693void
c906108c 694tuiShowAllExecInfosContent (void)
c906108c
SS
695{
696 int i;
697
698 for (i = 0; i < (sourceWindows ())->count; i++)
699 tuiShowExecInfoContent ((TuiWinInfoPtr) (sourceWindows ())->list[i]);
700
701 return;
702} /* tuiShowAllExecInfosContent */
703
704
705/*
c5aa993b
JM
706 ** tuiEraseExecInfoContent().
707 */
c906108c 708void
eca6576c 709tuiEraseExecInfoContent (TuiWinInfoPtr winInfo)
c906108c
SS
710{
711 TuiGenWinInfoPtr execInfo = winInfo->detail.sourceInfo.executionInfo;
712
713 werase (execInfo->handle);
714 tuiRefreshWin (execInfo);
715
716 return;
717} /* tuiEraseExecInfoContent */
718
719
720/*
c5aa993b
JM
721 ** tuiEraseAllExecInfosContent()
722 */
c906108c 723void
c906108c 724tuiEraseAllExecInfosContent (void)
c906108c
SS
725{
726 int i;
727
728 for (i = 0; i < (sourceWindows ())->count; i++)
729 tuiEraseExecInfoContent ((TuiWinInfoPtr) (sourceWindows ())->list[i]);
730
731 return;
732} /* tuiEraseAllExecInfosContent */
733
734
735/*
c5aa993b
JM
736 ** tuiClearExecInfoContent().
737 */
c906108c 738void
eca6576c 739tuiClearExecInfoContent (TuiWinInfoPtr winInfo)
c906108c
SS
740{
741 winInfo->detail.sourceInfo.executionInfo->contentInUse = FALSE;
742 tuiEraseExecInfoContent (winInfo);
743
744 return;
745} /* tuiClearExecInfoContent */
746
747
748/*
c5aa993b
JM
749 ** tuiClearAllExecInfosContent()
750 */
c906108c 751void
c906108c 752tuiClearAllExecInfosContent (void)
c906108c
SS
753{
754 int i;
755
756 for (i = 0; i < (sourceWindows ())->count; i++)
757 tuiClearExecInfoContent ((TuiWinInfoPtr) (sourceWindows ())->list[i]);
758
759 return;
760} /* tuiClearAllExecInfosContent */
761
762
763/*
c5aa993b
JM
764 ** tuiUpdateExecInfo().
765 ** Function to update the execution info window
766 */
c906108c 767void
eca6576c 768tuiUpdateExecInfo (TuiWinInfoPtr winInfo)
c906108c
SS
769{
770 tuiSetExecInfoContent (winInfo);
771 tuiShowExecInfoContent (winInfo);
772} /* tuiUpdateExecInfo
773
774
c5aa993b
JM
775 /*
776 ** tuiUpdateAllExecInfos()
777 */
c906108c 778void
c906108c 779tuiUpdateAllExecInfos (void)
c906108c
SS
780{
781 int i;
782
783 for (i = 0; i < (sourceWindows ())->count; i++)
784 tuiUpdateExecInfo ((TuiWinInfoPtr) (sourceWindows ())->list[i]);
785
786 return;
c5aa993b 787} /* tuiUpdateAllExecInfos */
c906108c
SS
788
789
790
791/* tuiUpdateOnEnd()
c5aa993b
JM
792 ** elz: This function clears the execution info from the source windows
793 ** and resets the locator to display no line info, procedure info, pc
794 ** info. It is called by stack_publish_stopped_with_no_frame, which
795 ** is called then the target terminates execution
796 */
c906108c 797void
c906108c 798tuiUpdateOnEnd (void)
c906108c
SS
799{
800 int i;
801 TuiGenWinInfoPtr locator;
802 char *filename;
803 TuiWinInfoPtr winInfo;
804
805 locator = locatorWinInfoPtr ();
806
807 /* for all the windows (src, asm) */
808 for (i = 0; i < (sourceWindows ())->count; i++)
809 {
810 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
811
812 tuiSetIsExecPointAt ((Opaque) - 1, winInfo); /* the target is'n running */
813 /* -1 should not match any line number or pc */
c5aa993b
JM
814 tuiSetExecInfoContent (winInfo); /*set winInfo so that > is'n displayed */
815 tuiShowExecInfoContent (winInfo); /* display the new contents */
c906108c
SS
816 }
817
c5aa993b 818 /*now update the locator */
c906108c
SS
819 tuiClearLocatorDisplay ();
820 tuiGetLocatorFilename (locator, &filename);
821 tuiSetLocatorInfo (
822 filename,
823 (char *) NULL,
824 0,
825 (Opaque) NULL,
826 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
827 tuiShowLocatorContent ();
828
829 return;
830} /* tuiUpdateOnEnd */
831
832
833
834TuiStatus
eca6576c 835tuiAllocSourceBuffer (TuiWinInfoPtr winInfo)
c906108c
SS
836{
837 register char *srcLine, *srcLineBuf;
838 register int i, lineWidth, c, maxLines;
839 TuiStatus ret = TUI_FAILURE;
840
841 maxLines = winInfo->generic.height; /* less the highlight box */
842 lineWidth = winInfo->generic.width - 1;
843 /*
c5aa993b
JM
844 ** Allocate the buffer for the source lines. Do this only once since they
845 ** will be re-used for all source displays. The only other time this will
846 ** be done is when a window's size changes.
847 */
c906108c
SS
848 if (winInfo->generic.content == (OpaquePtr) NULL)
849 {
850 srcLineBuf = (char *) xmalloc ((maxLines * lineWidth) * sizeof (char));
851 if (srcLineBuf == (char *) NULL)
852 fputs_unfiltered (
853 "Unable to Allocate Memory for Source or Disassembly Display.\n",
854 gdb_stderr);
855 else
856 {
857 /* allocate the content list */
858 if ((winInfo->generic.content =
859 (OpaquePtr) allocContent (maxLines, SRC_WIN)) == (OpaquePtr) NULL)
860 {
861 tuiFree (srcLineBuf);
862 srcLineBuf = (char *) NULL;
863 fputs_unfiltered (
864 "Unable to Allocate Memory for Source or Disassembly Display.\n",
865 gdb_stderr);
866 }
867 }
868 for (i = 0; i < maxLines; i++)
869 ((TuiWinElementPtr)
870 winInfo->generic.content[i])->whichElement.source.line =
871 srcLineBuf + (lineWidth * i);
872 ret = TUI_SUCCESS;
873 }
874 else
875 ret = TUI_SUCCESS;
876
877 return ret;
878} /* tuiAllocSourceBuffer */
879
880
881/*
c5aa993b
JM
882 ** tuiLineIsDisplayed().
883 ** Answer whether the a particular line number or address is displayed
884 ** in the current source window.
885 */
c906108c 886int
eca6576c
SC
887tuiLineIsDisplayed (Opaque lineNoOrAddr, TuiWinInfoPtr winInfo,
888 int checkThreshold)
c906108c
SS
889{
890 int isDisplayed = FALSE;
891 int i, threshold;
892
893 if (checkThreshold)
894 threshold = SCROLL_THRESHOLD;
895 else
896 threshold = 0;
897 i = 0;
898 while (i < winInfo->generic.contentSize - threshold && !isDisplayed)
899 {
900 if (winInfo == srcWin)
901 isDisplayed = (((TuiWinElementPtr)
902 winInfo->generic.content[i])->whichElement.source.lineOrAddr.lineNo
903 == (int) lineNoOrAddr);
904 else
905 isDisplayed = (((TuiWinElementPtr)
906 winInfo->generic.content[i])->whichElement.source.lineOrAddr.addr
907 == lineNoOrAddr);
908 i++;
909 }
910
911 return isDisplayed;
912} /* tuiLineIsDisplayed */
913
914
915/*****************************************
916** STATIC LOCAL FUNCTIONS **
917******************************************/
This page took 0.165088 seconds and 4 git commands to generate.