1 /* TUI display source/assembly window.
3 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation,
6 Contributed by Hewlett-Packard Company.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* FIXME: cagney/2002-02-28: The GDB coding standard indicates that
26 "defs.h" should be included first. Unfortunatly some systems
27 (currently Debian GNU/Linux) include the <stdbool.h> via <curses.h>
28 and they clash with "bfd.h"'s definiton of true/false. The correct
29 fix is to remove true/false from "bfd.h", however, until that
30 happens, hack around it by including "config.h" and <curses.h>
46 #include "breakpoint.h"
53 #include "tuiGeneralWin.h"
54 #include "tuiSourceWin.h"
55 #include "tuiSource.h"
56 #include "tuiDisassem.h"
59 /*****************************************
60 ** EXTERNAL FUNCTION DECLS **
61 ******************************************/
63 /*****************************************
64 ** EXTERNAL DATA DECLS **
65 ******************************************/
66 extern int current_source_line
;
67 extern struct symtab
*current_source_symtab
;
70 ** tuiDisplayMainFunction().
71 ** Function to display the "main" routine"
74 tuiDisplayMainFunction (void)
76 if ((sourceWindows ())->count
> 0)
80 addr
= parse_and_eval_address ("main");
81 if (addr
== (CORE_ADDR
) 0)
82 addr
= parse_and_eval_address ("MAIN");
83 if (addr
!= (CORE_ADDR
) 0)
85 struct symtab_and_line sal
;
87 tuiUpdateSourceWindowsWithAddr (addr
);
88 sal
= find_pc_line (addr
, 0);
89 tuiSwitchFilename (sal
.symtab
->filename
);
94 } /* tuiDisplayMainFunction */
99 ** tuiUpdateSourceWindow().
100 ** Function to display source in the source window. This function
101 ** initializes the horizontal scroll to 0.
104 tuiUpdateSourceWindow (TuiWinInfoPtr winInfo
, struct symtab
*s
,
105 TuiLineOrAddress lineOrAddr
, int noerror
)
107 winInfo
->detail
.sourceInfo
.horizontalOffset
= 0;
108 tuiUpdateSourceWindowAsIs (winInfo
, s
, lineOrAddr
, noerror
);
111 } /* tuiUpdateSourceWindow */
115 ** tuiUpdateSourceWindowAsIs().
116 ** Function to display source in the source/asm window. This
117 ** function shows the source as specified by the horizontal offset.
120 tuiUpdateSourceWindowAsIs (TuiWinInfoPtr winInfo
, struct symtab
*s
,
121 TuiLineOrAddress lineOrAddr
, int noerror
)
125 if (winInfo
->generic
.type
== SRC_WIN
)
126 ret
= tuiSetSourceContent (s
, lineOrAddr
.lineNo
, noerror
);
128 ret
= tuiSetDisassemContent (s
, lineOrAddr
.addr
);
130 if (ret
== TUI_FAILURE
)
132 tuiClearSourceContent (winInfo
, EMPTY_SOURCE_PROMPT
);
133 tuiClearExecInfoContent (winInfo
);
137 tuiEraseSourceContent (winInfo
, NO_EMPTY_SOURCE_PROMPT
);
138 tuiShowSourceContent (winInfo
);
139 tuiUpdateExecInfo (winInfo
);
140 if (winInfo
->generic
.type
== SRC_WIN
)
142 current_source_line
= lineOrAddr
.lineNo
+
143 (winInfo
->generic
.contentSize
- 2);
144 current_source_symtab
= s
;
146 ** If the focus was in the asm win, put it in the src
147 ** win if we don't have a split layout
149 if (tuiWinWithFocus () == disassemWin
&&
150 currentLayout () != SRC_DISASSEM_COMMAND
)
151 tuiSetWinFocusTo (srcWin
);
157 } /* tuiUpdateSourceWindowAsIs */
161 ** tuiUpdateSourceWindowsWithAddr().
162 ** Function to ensure that the source and/or disassemly windows
163 ** reflect the input address.
166 tuiUpdateSourceWindowsWithAddr (CORE_ADDR addr
)
170 struct symtab_and_line sal
;
173 switch (currentLayout ())
175 case DISASSEM_COMMAND
:
176 case DISASSEM_DATA_COMMAND
:
177 tuiShowDisassem (addr
);
179 case SRC_DISASSEM_COMMAND
:
180 tuiShowDisassemAndUpdateSource (addr
);
183 sal
= find_pc_line (addr
, 0);
185 tuiShowSource (sal
.symtab
, l
, FALSE
);
193 for (i
= 0; i
< (sourceWindows ())->count
; i
++)
195 TuiWinInfoPtr winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[i
];
197 tuiClearSourceContent (winInfo
, EMPTY_SOURCE_PROMPT
);
198 tuiClearExecInfoContent (winInfo
);
203 } /* tuiUpdateSourceWindowsWithAddr */
206 ** tuiUpdateSourceWindowsWithLine().
207 ** Function to ensure that the source and/or disassemly windows
208 ** reflect the input address.
211 tuiUpdateSourceWindowsWithLine (struct symtab
*s
, int line
)
216 switch (currentLayout ())
218 case DISASSEM_COMMAND
:
219 case DISASSEM_DATA_COMMAND
:
220 find_line_pc (s
, line
, &pc
);
221 tuiUpdateSourceWindowsWithAddr (pc
);
225 tuiShowSource (s
, l
, FALSE
);
226 if (currentLayout () == SRC_DISASSEM_COMMAND
)
228 find_line_pc (s
, line
, &pc
);
229 tuiShowDisassem (pc
);
235 } /* tuiUpdateSourceWindowsWithLine */
238 ** tuiClearSourceContent().
241 tuiClearSourceContent (TuiWinInfoPtr winInfo
, int displayPrompt
)
243 if (m_winPtrNotNull (winInfo
))
247 winInfo
->generic
.contentInUse
= FALSE
;
248 tuiEraseSourceContent (winInfo
, displayPrompt
);
249 for (i
= 0; i
< winInfo
->generic
.contentSize
; i
++)
251 TuiWinElementPtr element
=
252 (TuiWinElementPtr
) winInfo
->generic
.content
[i
];
253 element
->whichElement
.source
.hasBreak
= FALSE
;
254 element
->whichElement
.source
.isExecPoint
= FALSE
;
259 } /* tuiClearSourceContent */
263 ** tuiEraseSourceContent().
266 tuiEraseSourceContent (TuiWinInfoPtr winInfo
, int displayPrompt
)
269 int halfWidth
= (winInfo
->generic
.width
- 2) / 2;
271 if (winInfo
->generic
.handle
!= (WINDOW
*) NULL
)
273 werase (winInfo
->generic
.handle
);
274 checkAndDisplayHighlightIfNeeded (winInfo
);
275 if (displayPrompt
== EMPTY_SOURCE_PROMPT
)
279 if (winInfo
->generic
.type
== SRC_WIN
)
280 noSrcStr
= NO_SRC_STRING
;
282 noSrcStr
= NO_DISASSEM_STRING
;
283 if (strlen (noSrcStr
) >= halfWidth
)
286 xPos
= halfWidth
- strlen (noSrcStr
);
287 mvwaddstr (winInfo
->generic
.handle
,
288 (winInfo
->generic
.height
/ 2),
292 /* elz: added this function call to set the real contents of
293 the window to what is on the screen, so that later calls
294 to refresh, do display
295 the correct stuff, and not the old image */
297 tuiSetSourceContentNil (winInfo
, noSrcStr
);
299 tuiRefreshWin (&winInfo
->generic
);
302 } /* tuiEraseSourceContent */
305 /* Redraw the complete line of a source or disassembly window. */
307 tui_show_source_line (TuiWinInfoPtr winInfo
, int lineno
)
309 TuiWinElementPtr line
;
312 line
= (TuiWinElementPtr
) winInfo
->generic
.content
[lineno
- 1];
313 if (line
->whichElement
.source
.isExecPoint
)
314 wattron (winInfo
->generic
.handle
, A_STANDOUT
);
316 mvwaddstr (winInfo
->generic
.handle
, lineno
, 1,
317 line
->whichElement
.source
.line
);
318 if (line
->whichElement
.source
.isExecPoint
)
319 wattroff (winInfo
->generic
.handle
, A_STANDOUT
);
321 /* Clear to end of line but stop before the border. */
322 getyx (winInfo
->generic
.handle
, y
, x
);
323 while (x
+ 1 < winInfo
->generic
.width
)
325 waddch (winInfo
->generic
.handle
, ' ');
326 getyx (winInfo
->generic
.handle
, y
, x
);
331 ** tuiShowSourceContent().
334 tuiShowSourceContent (TuiWinInfoPtr winInfo
)
336 if (winInfo
->generic
.contentSize
> 0)
340 for (lineno
= 1; lineno
<= winInfo
->generic
.contentSize
; lineno
++)
341 tui_show_source_line (winInfo
, lineno
);
344 tuiEraseSourceContent (winInfo
, TRUE
);
346 checkAndDisplayHighlightIfNeeded (winInfo
);
347 tuiRefreshWin (&winInfo
->generic
);
348 winInfo
->generic
.contentInUse
= TRUE
;
353 ** tuiHorizontalSourceScroll().
354 ** Scroll the source forward or backward horizontally
357 tuiHorizontalSourceScroll (TuiWinInfoPtr winInfo
,
358 TuiScrollDirection direction
,
361 if (winInfo
->generic
.content
!= (OpaquePtr
) NULL
)
366 if (current_source_symtab
== (struct symtab
*) NULL
)
367 s
= find_pc_symtab (selected_frame
->pc
);
369 s
= current_source_symtab
;
371 if (direction
== LEFT_SCROLL
)
372 offset
= winInfo
->detail
.sourceInfo
.horizontalOffset
+ numToScroll
;
376 winInfo
->detail
.sourceInfo
.horizontalOffset
- numToScroll
) < 0)
379 winInfo
->detail
.sourceInfo
.horizontalOffset
= offset
;
380 tuiUpdateSourceWindowAsIs (
384 winInfo
->generic
.content
[0])->whichElement
.source
.lineOrAddr
,
389 } /* tuiHorizontalSourceScroll */
393 ** tuiSetHasExecPointAt().
394 ** Set or clear the hasBreak flag in the line whose line is lineNo.
397 tuiSetIsExecPointAt (TuiLineOrAddress l
, TuiWinInfoPtr winInfo
)
400 TuiWinContent content
= (TuiWinContent
) winInfo
->generic
.content
;
403 while (i
< winInfo
->generic
.contentSize
)
405 if (content
[i
]->whichElement
.source
.lineOrAddr
.addr
== l
.addr
)
406 content
[i
]->whichElement
.source
.isExecPoint
= TRUE
;
408 content
[i
]->whichElement
.source
.isExecPoint
= FALSE
;
413 } /* tuiSetIsExecPointAt */
416 ** tuiSetHasBreakAt().
417 ** Set or clear the hasBreak flag in the line whose line is lineNo.
420 tuiSetHasBreakAt (struct breakpoint
*bp
, TuiWinInfoPtr winInfo
, int hasBreak
)
423 TuiWinContent content
= (TuiWinContent
) winInfo
->generic
.content
;
426 while (i
< winInfo
->generic
.contentSize
)
429 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
431 if (winInfo
== srcWin
)
433 TuiSourceInfoPtr src
= &winInfo
->detail
.sourceInfo
;
435 gotIt
= (src
->filename
!= (char *) NULL
&&
436 bp
->source_file
!= NULL
&&
437 (strcmp (bp
->source_file
, src
->filename
) == 0) &&
438 content
[i
]->whichElement
.source
.lineOrAddr
.lineNo
==
442 gotIt
= (content
[i
]->whichElement
.source
.lineOrAddr
.addr
446 content
[i
]->whichElement
.source
.hasBreak
= hasBreak
;
453 } /* tuiSetHasBreakAt */
457 ** tuiAllSetHasBreakAt().
458 ** Set or clear the hasBreak flag in all displayed source windows.
461 tuiAllSetHasBreakAt (struct breakpoint
*bp
, int hasBreak
)
465 for (i
= 0; i
< (sourceWindows ())->count
; i
++)
466 tuiSetHasBreakAt (bp
,
467 (TuiWinInfoPtr
) (sourceWindows ())->list
[i
], hasBreak
);
470 } /* tuiAllSetHasBreakAt */
473 /*********************************
474 ** EXECUTION INFO FUNCTIONS **
475 *********************************/
478 ** tuiSetExecInfoContent().
479 ** Function to initialize the content of the execution info window,
480 ** based upon the input window which is either the source or
481 ** disassembly window.
484 tuiSetExecInfoContent (TuiWinInfoPtr winInfo
)
486 TuiStatus ret
= TUI_SUCCESS
;
488 if (winInfo
->detail
.sourceInfo
.executionInfo
!= (TuiGenWinInfoPtr
) NULL
)
490 TuiGenWinInfoPtr execInfoPtr
= winInfo
->detail
.sourceInfo
.executionInfo
;
492 if (execInfoPtr
->content
== (OpaquePtr
) NULL
)
493 execInfoPtr
->content
=
494 (OpaquePtr
) allocContent (winInfo
->generic
.height
,
496 if (execInfoPtr
->content
!= (OpaquePtr
) NULL
)
500 for (i
= 0; i
< winInfo
->generic
.contentSize
; i
++)
502 TuiWinElementPtr element
;
503 TuiWinElementPtr srcElement
;
505 element
= (TuiWinElementPtr
) execInfoPtr
->content
[i
];
506 srcElement
= (TuiWinElementPtr
) winInfo
->generic
.content
[i
];
508 ** First check to see if we have a breakpoint that is
509 ** temporary. If so, and this is our current execution point,
510 ** then clear the break indicator.
512 if (srcElement
->whichElement
.source
.hasBreak
&&
513 srcElement
->whichElement
.source
.isExecPoint
)
515 struct breakpoint
*bp
;
517 extern struct breakpoint
*breakpoint_chain
;
519 for (bp
= breakpoint_chain
;
520 (bp
!= (struct breakpoint
*) NULL
&& !found
);
524 (winInfo
== srcWin
&&
526 srcElement
->whichElement
.source
.lineOrAddr
.lineNo
) ||
527 (winInfo
== disassemWin
&&
528 bp
->address
== (CORE_ADDR
)
529 srcElement
->whichElement
.source
.lineOrAddr
.addr
);
531 srcElement
->whichElement
.source
.hasBreak
=
532 (bp
->disposition
!= disp_del
|| bp
->hit_count
<= 0);
535 srcElement
->whichElement
.source
.hasBreak
= FALSE
;
538 ** Now update the exec info content based upon the state
539 ** of each line as indicated by the source content.
541 if (srcElement
->whichElement
.source
.hasBreak
&&
542 srcElement
->whichElement
.source
.isExecPoint
)
543 element
->whichElement
.simpleString
= breakLocationStr ();
544 else if (srcElement
->whichElement
.source
.hasBreak
)
545 element
->whichElement
.simpleString
= breakStr ();
546 else if (srcElement
->whichElement
.source
.isExecPoint
)
547 element
->whichElement
.simpleString
= locationStr ();
549 element
->whichElement
.simpleString
= blankStr ();
551 execInfoPtr
->contentSize
= winInfo
->generic
.contentSize
;
558 } /* tuiSetExecInfoContent */
562 ** tuiShowExecInfoContent().
565 tuiShowExecInfoContent (TuiWinInfoPtr winInfo
)
567 TuiGenWinInfoPtr execInfo
= winInfo
->detail
.sourceInfo
.executionInfo
;
570 werase (execInfo
->handle
);
571 tuiRefreshWin (execInfo
);
572 for (curLine
= 1; (curLine
<= execInfo
->contentSize
); curLine
++)
573 mvwaddstr (execInfo
->handle
,
577 execInfo
->content
[curLine
- 1])->whichElement
.simpleString
);
578 tuiRefreshWin (execInfo
);
579 execInfo
->contentInUse
= TRUE
;
582 } /* tuiShowExecInfoContent */
586 ** tuiEraseExecInfoContent().
589 tuiEraseExecInfoContent (TuiWinInfoPtr winInfo
)
591 TuiGenWinInfoPtr execInfo
= winInfo
->detail
.sourceInfo
.executionInfo
;
593 werase (execInfo
->handle
);
594 tuiRefreshWin (execInfo
);
597 } /* tuiEraseExecInfoContent */
600 ** tuiClearExecInfoContent().
603 tuiClearExecInfoContent (TuiWinInfoPtr winInfo
)
605 winInfo
->detail
.sourceInfo
.executionInfo
->contentInUse
= FALSE
;
606 tuiEraseExecInfoContent (winInfo
);
609 } /* tuiClearExecInfoContent */
612 ** tuiUpdateExecInfo().
613 ** Function to update the execution info window
616 tuiUpdateExecInfo (TuiWinInfoPtr winInfo
)
618 tuiSetExecInfoContent (winInfo
);
619 tuiShowExecInfoContent (winInfo
);
620 } /* tuiUpdateExecInfo */
624 ** tuiUpdateAllExecInfos()
627 tuiUpdateAllExecInfos (void)
631 for (i
= 0; i
< (sourceWindows ())->count
; i
++)
632 tuiUpdateExecInfo ((TuiWinInfoPtr
) (sourceWindows ())->list
[i
]);
635 } /* tuiUpdateAllExecInfos */
638 tuiAllocSourceBuffer (TuiWinInfoPtr winInfo
)
640 register char *srcLineBuf
;
641 register int i
, lineWidth
, maxLines
;
642 TuiStatus ret
= TUI_FAILURE
;
644 maxLines
= winInfo
->generic
.height
; /* less the highlight box */
645 lineWidth
= winInfo
->generic
.width
- 1;
647 ** Allocate the buffer for the source lines. Do this only once since they
648 ** will be re-used for all source displays. The only other time this will
649 ** be done is when a window's size changes.
651 if (winInfo
->generic
.content
== (OpaquePtr
) NULL
)
653 srcLineBuf
= (char *) xmalloc ((maxLines
* lineWidth
) * sizeof (char));
654 if (srcLineBuf
== (char *) NULL
)
656 "Unable to Allocate Memory for Source or Disassembly Display.\n",
660 /* allocate the content list */
661 if ((winInfo
->generic
.content
=
662 (OpaquePtr
) allocContent (maxLines
, SRC_WIN
)) == (OpaquePtr
) NULL
)
664 tuiFree (srcLineBuf
);
665 srcLineBuf
= (char *) NULL
;
667 "Unable to Allocate Memory for Source or Disassembly Display.\n",
671 for (i
= 0; i
< maxLines
; i
++)
673 winInfo
->generic
.content
[i
])->whichElement
.source
.line
=
674 srcLineBuf
+ (lineWidth
* i
);
681 } /* tuiAllocSourceBuffer */
685 ** tuiLineIsDisplayed().
686 ** Answer whether the a particular line number or address is displayed
687 ** in the current source window.
690 tuiLineIsDisplayed (int line
, TuiWinInfoPtr winInfo
,
693 int isDisplayed
= FALSE
;
697 threshold
= SCROLL_THRESHOLD
;
701 while (i
< winInfo
->generic
.contentSize
- threshold
&& !isDisplayed
)
703 isDisplayed
= (((TuiWinElementPtr
)
704 winInfo
->generic
.content
[i
])->whichElement
.source
.lineOrAddr
.lineNo
710 } /* tuiLineIsDisplayed */
714 ** tuiLineIsDisplayed().
715 ** Answer whether the a particular line number or address is displayed
716 ** in the current source window.
719 tuiAddrIsDisplayed (CORE_ADDR addr
, TuiWinInfoPtr winInfo
,
722 int isDisplayed
= FALSE
;
726 threshold
= SCROLL_THRESHOLD
;
730 while (i
< winInfo
->generic
.contentSize
- threshold
&& !isDisplayed
)
732 isDisplayed
= (((TuiWinElementPtr
)
733 winInfo
->generic
.content
[i
])->whichElement
.source
.lineOrAddr
.addr
742 /*****************************************
743 ** STATIC LOCAL FUNCTIONS **
744 ******************************************/