1 /* TUI display source window.
2 Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Hewlett-Packard Company.
5 This file is part of GDB.
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.
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.
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. */
26 #include "breakpoint.h"
33 #include "tuiSourceWin.h"
34 #include "tuiSource.h"
37 /*****************************************
38 ** EXTERNAL DATA DECLS **
39 ******************************************/
40 extern int current_source_line
;
41 extern struct symtab
*current_source_symtab
;
44 /*****************************************
45 ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
46 ******************************************/
48 static struct breakpoint
*_hasBreak (char *, int);
51 /*****************************************
52 ** STATIC LOCAL DATA **
53 ******************************************/
56 /*****************************************
57 ** PUBLIC FUNCTIONS **
58 ******************************************/
60 /*********************************
61 ** SOURCE/DISASSEM FUNCTIONS **
62 *********************************/
65 ** tuiSetSourceContent().
66 ** Function to display source in the source window.
69 tuiSetSourceContent (struct symtab
*s
, int lineNo
, int noerror
)
71 TuiStatus ret
= TUI_FAILURE
;
73 if (s
!= (struct symtab
*) NULL
&& s
->filename
!= (char *) NULL
)
75 register FILE *stream
;
76 register int i
, desc
, c
, lineWidth
, nlines
;
77 register char *srcLine
;
79 if ((ret
= tuiAllocSourceBuffer (srcWin
)) == TUI_SUCCESS
)
81 lineWidth
= srcWin
->generic
.width
- 1;
83 ** Take hilite (window border) into account, when calculating
84 ** the number of lines
86 nlines
= (lineNo
+ (srcWin
->generic
.height
- 2)) - lineNo
;
87 desc
= open_source_file (s
);
92 char *name
= alloca (strlen (s
->filename
) + 100);
93 sprintf (name
, "%s:%d", s
->filename
, lineNo
);
94 print_sys_errmsg (name
, errno
);
100 if (s
->line_charpos
== 0)
101 find_source_lines (s
, desc
);
103 if (lineNo
< 1 || lineNo
> s
->nlines
)
107 "Line number %d out of range; %s has %d lines.\n",
108 lineNo
, s
->filename
, s
->nlines
);
110 else if (lseek (desc
, s
->line_charpos
[lineNo
- 1], 0) < 0)
113 perror_with_name (s
->filename
);
117 register int offset
, curLineNo
, curLine
, curLen
, threshold
;
118 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
120 ** Determine the threshold for the length of the line
121 ** and the offset to start the display
123 offset
= srcWin
->detail
.sourceInfo
.horizontalOffset
;
124 threshold
= (lineWidth
- 1) + offset
;
125 stream
= fdopen (desc
, FOPEN_RT
);
129 srcWin
->detail
.sourceInfo
.startLineOrAddr
.lineNo
= lineNo
;
131 srcLine
= (char *) xmalloc (
132 (threshold
+ 1) * sizeof (char));
133 while (curLine
< nlines
)
135 TuiWinElementPtr element
= (TuiWinElementPtr
)
136 srcWin
->generic
.content
[curLine
];
137 struct breakpoint
*bp
;
139 /* get the first character in the line */
143 srcLine
= ((TuiWinElementPtr
)
144 srcWin
->generic
.content
[
145 curLine
])->whichElement
.source
.line
;
146 /* Init the line with the line number */
147 sprintf (srcLine
, "%-6d", curLineNo
);
148 curLen
= strlen (srcLine
);
150 ((curLen
/ tuiDefaultTabLen ()) * tuiDefaultTabLen ());
151 while (i
< tuiDefaultTabLen ())
153 srcLine
[curLen
] = ' ';
157 srcLine
[curLen
] = (char) 0;
160 ** Set whether element is the execution point and
161 ** whether there is a break point on it.
163 element
->whichElement
.source
.lineOrAddr
.lineNo
=
165 element
->whichElement
.source
.isExecPoint
=
166 (strcmp (((TuiWinElementPtr
)
167 locator
->content
[0])->whichElement
.locator
.fileName
,
169 && curLineNo
== ((TuiWinElementPtr
)
170 locator
->content
[0])->whichElement
.locator
.lineNo
);
171 bp
= _hasBreak (s
->filename
, curLineNo
);
172 element
->whichElement
.source
.hasBreak
=
173 (bp
!= (struct breakpoint
*) NULL
&&
174 (!element
->whichElement
.source
.isExecPoint
||
175 (bp
->disposition
!= del
|| bp
->hit_count
<= 0)));
178 i
= strlen (srcLine
) - 1;
182 (c
!= '\r') && (++i
< threshold
))
184 if (c
< 040 && c
!= '\t')
187 srcLine
[i
] = c
+ 0100;
196 ** Store the charcter in the line
197 ** buffer. If it is a tab, then
198 ** translate to the correct number of
199 ** chars so we don't overwrite our
204 int j
, maxTabLen
= tuiDefaultTabLen ();
207 (i
/ maxTabLen
) * maxTabLen
);
221 ** if we have not reached EOL, then eat
224 while (c
!= EOF
&& c
!= '\n' && c
!= '\r')
228 while (c
!= EOF
&& c
!= '\n' && c
!= '\r' &&
229 i
< threshold
&& (c
= fgetc (stream
)));
231 /* Now copy the line taking the offset into account */
232 if (strlen (srcLine
) > offset
)
233 strcpy (((TuiWinElementPtr
) srcWin
->generic
.content
[
234 curLine
])->whichElement
.source
.line
,
238 srcWin
->generic
.content
[
239 curLine
])->whichElement
.source
.line
[0] = (char) 0;
246 srcWin
->generic
.contentSize
= nlines
;
253 } /* tuiSetSourceContent */
256 /* elz: this function sets the contents of the source window to empty
257 except for a line in the middle with a warning message about the
258 source not being available. This function is called by
259 tuiEraseSourceContents, which in turn is invoked when the source files
260 cannot be accessed */
263 tuiSetSourceContentNil (TuiWinInfoPtr winInfo
, char *warning_string
)
269 lineWidth
= winInfo
->generic
.width
- 1;
270 nLines
= winInfo
->generic
.height
- 2;
272 /* set to empty each line in the window, except for the one
273 which contains the message */
274 while (curr_line
< winInfo
->generic
.contentSize
)
276 /* set the information related to each displayed line
277 to null: i.e. the line number is 0, there is no bp,
278 it is not where the program is stopped */
280 TuiWinElementPtr element
=
281 (TuiWinElementPtr
) winInfo
->generic
.content
[curr_line
];
282 element
->whichElement
.source
.lineOrAddr
.lineNo
= 0;
283 element
->whichElement
.source
.isExecPoint
= FALSE
;
284 element
->whichElement
.source
.hasBreak
= FALSE
;
286 /* set the contents of the line to blank */
287 element
->whichElement
.source
.line
[0] = (char) 0;
289 /* if the current line is in the middle of the screen, then we want to
290 display the 'no source available' message in it.
291 Note: the 'weird' arithmetic with the line width and height comes from
292 the function tuiEraseSourceContent. We need to keep the screen and the
293 window's actual contents in synch */
295 if (curr_line
== (nLines
/ 2 + 1))
299 int warning_length
= strlen (warning_string
);
302 srcLine
= element
->whichElement
.source
.line
;
304 if (warning_length
>= ((lineWidth
- 1) / 2))
307 xpos
= (lineWidth
- 1) / 2 - warning_length
;
309 for (i
= 0; i
< xpos
; i
++)
312 sprintf (srcLine
+ i
, "%s", warning_string
);
314 for (i
= xpos
+ warning_length
; i
< lineWidth
; i
++)
325 } /*tuiSetSourceContentNil */
332 ** Function to display source in the source window. This function
333 ** initializes the horizontal scroll to 0.
336 tuiShowSource (struct symtab
*s
, TuiLineOrAddress line
, int noerror
)
338 srcWin
->detail
.sourceInfo
.horizontalOffset
= 0;
339 tuiUpdateSourceWindowAsIs(srcWin
, s
, line
, noerror
);
342 } /* tuiShowSource */
346 ** tuiSourceIsDisplayed().
347 ** Answer whether the source is currently displayed in the source window.
350 tuiSourceIsDisplayed (char *fname
)
352 return (srcWin
->generic
.contentInUse
&&
353 (strcmp (((TuiWinElementPtr
) (locatorWinInfoPtr ())->
354 content
[0])->whichElement
.locator
.fileName
, fname
) == 0));
355 } /* tuiSourceIsDisplayed */
359 ** tuiVerticalSourceScroll().
360 ** Scroll the source forward or backward vertically
363 tuiVerticalSourceScroll (TuiScrollDirection scrollDirection
,
366 if (srcWin
->generic
.content
!= (OpaquePtr
) NULL
)
370 TuiWinContent content
= (TuiWinContent
) srcWin
->generic
.content
;
372 if (current_source_symtab
== (struct symtab
*) NULL
)
373 s
= find_pc_symtab (selected_frame
->pc
);
375 s
= current_source_symtab
;
377 if (scrollDirection
== FORWARD_SCROLL
)
379 l
.lineNo
= content
[0]->whichElement
.source
.lineOrAddr
.lineNo
+
381 if (l
.lineNo
> s
->nlines
)
382 /*line = s->nlines - winInfo->generic.contentSize + 1; */
383 /*elz: fix for dts 23398 */
384 l
.lineNo
= content
[0]->whichElement
.source
.lineOrAddr
.lineNo
;
388 l
.lineNo
= content
[0]->whichElement
.source
.lineOrAddr
.lineNo
-
393 if (identify_source_line (s
, l
.lineNo
, 0, -1) == 1)
394 tuiUpdateSourceWindowAsIs (srcWin
, s
, l
, FALSE
);
398 } /* tuiVerticalSourceScroll */
401 /*****************************************
402 ** STATIC LOCAL FUNCTIONS **
403 ******************************************/
407 ** Answer whether there is a break point at the input line in
408 ** the source file indicated
410 static struct breakpoint
*
411 _hasBreak (char *sourceFileName
, int lineNo
)
413 struct breakpoint
*bpWithBreak
= (struct breakpoint
*) NULL
;
414 struct breakpoint
*bp
;
415 extern struct breakpoint
*breakpoint_chain
;
418 for (bp
= breakpoint_chain
;
419 (bp
!= (struct breakpoint
*) NULL
&&
420 bpWithBreak
== (struct breakpoint
*) NULL
);
423 && (strcmp (sourceFileName
, bp
->source_file
) == 0)
424 && (lineNo
== bp
->line_number
))