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