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