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