]>
Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* Disassembly display. |
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 "symtab.h" | |
44 | #include "breakpoint.h" | |
45 | #include "frame.h" | |
fd0407d6 | 46 | #include "value.h" |
c906108c SS |
47 | |
48 | #include "tui.h" | |
49 | #include "tuiData.h" | |
a8080b7f | 50 | #include "tuiWin.h" |
c906108c SS |
51 | #include "tuiLayout.h" |
52 | #include "tuiSourceWin.h" | |
53 | #include "tuiStack.h" | |
a8080b7f | 54 | #include "tui-file.h" |
c906108c SS |
55 | |
56 | ||
57 | /***************************************** | |
58 | ** STATIC LOCAL FUNCTIONS FORWARD DECLS ** | |
59 | ******************************************/ | |
60 | ||
a14ed312 | 61 | static struct breakpoint *_hasBreak (CORE_ADDR); |
c906108c SS |
62 | |
63 | ||
64 | /***************************************** | |
65 | ** PUBLIC FUNCTIONS ** | |
66 | ******************************************/ | |
67 | ||
68 | /* | |
c5aa993b JM |
69 | ** tuiSetDisassemContent(). |
70 | ** Function to set the disassembly window's content. | |
71 | */ | |
c906108c | 72 | TuiStatus |
c774cec6 | 73 | tuiSetDisassemContent (struct symtab *s, CORE_ADDR startAddr) |
c906108c SS |
74 | { |
75 | TuiStatus ret = TUI_FAILURE; | |
d9fcf2fb | 76 | struct ui_file *gdb_dis_out; |
c906108c | 77 | |
c774cec6 | 78 | if (startAddr != 0) |
c906108c SS |
79 | { |
80 | register int i, desc; | |
81 | ||
82 | if ((ret = tuiAllocSourceBuffer (disassemWin)) == TUI_SUCCESS) | |
83 | { | |
84 | register int offset = disassemWin->detail.sourceInfo.horizontalOffset; | |
85 | register int threshold, curLine = 0, lineWidth, maxLines; | |
86 | CORE_ADDR newpc, pc; | |
87 | disassemble_info asmInfo; | |
88 | TuiGenWinInfoPtr locator = locatorWinInfoPtr (); | |
a14ed312 KB |
89 | extern void strcat_address (CORE_ADDR, char *, int); |
90 | extern void strcat_address_numeric (CORE_ADDR, int, char *, int); | |
c906108c SS |
91 | int curLen = 0; |
92 | int tab_len = tuiDefaultTabLen (); | |
93 | ||
94 | maxLines = disassemWin->generic.height - 2; /* account for hilite */ | |
95 | lineWidth = disassemWin->generic.width - 1; | |
96 | threshold = (lineWidth - 1) + offset; | |
97 | ||
d9fcf2fb | 98 | /* now init the ui_file structure */ |
11cf8741 | 99 | gdb_dis_out = tui_sfileopen (threshold); |
c906108c | 100 | |
a8080b7f SC |
101 | asmInfo = tm_print_insn_info; |
102 | asmInfo.stream = gdb_dis_out; | |
c906108c SS |
103 | |
104 | disassemWin->detail.sourceInfo.startLineOrAddr.addr = startAddr; | |
105 | ||
106 | /* Now construct each line */ | |
c774cec6 | 107 | for (curLine = 0, pc = startAddr; (curLine < maxLines);) |
c906108c | 108 | { |
c5aa993b | 109 | TuiWinElementPtr element = (TuiWinElementPtr) disassemWin->generic.content[curLine]; |
c906108c SS |
110 | struct breakpoint *bp; |
111 | ||
112 | print_address (pc, gdb_dis_out); | |
113 | ||
11cf8741 | 114 | curLen = strlen (tui_file_get_strbuf (gdb_dis_out)); |
c906108c SS |
115 | i = curLen - ((curLen / tab_len) * tab_len); |
116 | ||
c5aa993b | 117 | /* adjust buffer length if necessary */ |
11cf8741 | 118 | tui_file_adjust_strbuf ((tab_len - i > 0) ? (tab_len - i) : 0, gdb_dis_out); |
c5aa993b | 119 | |
c906108c SS |
120 | /* Add spaces to make the instructions start onthe same column */ |
121 | while (i < tab_len) | |
122 | { | |
11cf8741 | 123 | tui_file_get_strbuf (gdb_dis_out)[curLen] = ' '; |
c906108c SS |
124 | i++; |
125 | curLen++; | |
126 | } | |
11cf8741 | 127 | tui_file_get_strbuf (gdb_dis_out)[curLen] = '\0'; |
c906108c SS |
128 | |
129 | newpc = pc + ((*tm_print_insn) (pc, &asmInfo)); | |
130 | ||
131 | /* Now copy the line taking the offset into account */ | |
11cf8741 | 132 | if (strlen (tui_file_get_strbuf (gdb_dis_out)) > offset) |
c906108c | 133 | strcpy (element->whichElement.source.line, |
11cf8741 | 134 | &(tui_file_get_strbuf (gdb_dis_out)[offset])); |
c906108c SS |
135 | else |
136 | element->whichElement.source.line[0] = '\0'; | |
a4b99e53 | 137 | element->whichElement.source.lineOrAddr.addr = pc; |
c906108c | 138 | element->whichElement.source.isExecPoint = |
c5aa993b | 139 | (pc == (CORE_ADDR) ((TuiWinElementPtr) locator->content[0])->whichElement.locator.addr); |
c906108c SS |
140 | bp = _hasBreak (pc); |
141 | element->whichElement.source.hasBreak = | |
142 | (bp != (struct breakpoint *) NULL && | |
143 | (!element->whichElement.source.isExecPoint || | |
b5de0fa7 | 144 | (bp->disposition != disp_del || bp->hit_count <= 0))); |
c906108c SS |
145 | curLine++; |
146 | pc = newpc; | |
c5aa993b | 147 | /* reset the buffer to empty */ |
11cf8741 | 148 | tui_file_get_strbuf (gdb_dis_out)[0] = '\0'; |
c906108c | 149 | } |
d9fcf2fb | 150 | ui_file_delete (gdb_dis_out); |
11cf8741 | 151 | gdb_dis_out = NULL; |
c906108c SS |
152 | disassemWin->generic.contentSize = curLine; |
153 | ret = TUI_SUCCESS; | |
154 | } | |
155 | } | |
156 | ||
157 | return ret; | |
158 | } /* tuiSetDisassemContent */ | |
159 | ||
160 | ||
161 | /* | |
c5aa993b JM |
162 | ** tuiShowDisassem(). |
163 | ** Function to display the disassembly window with disassembled code. | |
164 | */ | |
c906108c | 165 | void |
c774cec6 | 166 | tuiShowDisassem (CORE_ADDR startAddr) |
c906108c | 167 | { |
c774cec6 | 168 | struct symtab *s = find_pc_symtab (startAddr); |
c906108c | 169 | TuiWinInfoPtr winWithFocus = tuiWinWithFocus (); |
a4b99e53 | 170 | TuiLineOrAddress val; |
c906108c | 171 | |
a4b99e53 | 172 | val.addr = startAddr; |
c906108c | 173 | tuiAddWinToLayout (DISASSEM_WIN); |
a4b99e53 | 174 | tuiUpdateSourceWindow (disassemWin, s, val, FALSE); |
c906108c | 175 | /* |
c5aa993b JM |
176 | ** if the focus was in the src win, put it in the asm win, if the |
177 | ** source view isn't split | |
178 | */ | |
c906108c SS |
179 | if (currentLayout () != SRC_DISASSEM_COMMAND && winWithFocus == srcWin) |
180 | tuiSetWinFocusTo (disassemWin); | |
181 | ||
182 | return; | |
183 | } /* tuiShowDisassem */ | |
184 | ||
185 | ||
186 | /* | |
c5aa993b JM |
187 | ** tuiShowDisassemAndUpdateSource(). |
188 | ** Function to display the disassembly window. | |
189 | */ | |
c906108c | 190 | void |
c774cec6 | 191 | tuiShowDisassemAndUpdateSource (CORE_ADDR startAddr) |
c906108c SS |
192 | { |
193 | struct symtab_and_line sal; | |
194 | ||
195 | tuiShowDisassem (startAddr); | |
196 | if (currentLayout () == SRC_DISASSEM_COMMAND) | |
197 | { | |
a4b99e53 | 198 | TuiLineOrAddress val; |
c906108c SS |
199 | TuiGenWinInfoPtr locator = locatorWinInfoPtr (); |
200 | /* | |
c5aa993b JM |
201 | ** Update what is in the source window if it is displayed too, |
202 | ** note that it follows what is in the disassembly window and visa-versa | |
203 | */ | |
c774cec6 | 204 | sal = find_pc_line (startAddr, 0); |
a4b99e53 SC |
205 | val.lineNo = sal.line; |
206 | tuiUpdateSourceWindow (srcWin, sal.symtab, val, TRUE); | |
3024f13a SC |
207 | if (sal.symtab) |
208 | { | |
209 | current_source_symtab = sal.symtab; | |
210 | tuiUpdateLocatorFilename (sal.symtab->filename); | |
211 | } | |
212 | else | |
213 | tuiUpdateLocatorFilename ("?"); | |
c906108c SS |
214 | } |
215 | ||
216 | return; | |
217 | } /* tuiShowDisassemAndUpdateSource */ | |
218 | ||
c906108c | 219 | /* |
c5aa993b JM |
220 | ** tuiGetBeginAsmAddress(). |
221 | */ | |
c774cec6 | 222 | CORE_ADDR |
c906108c | 223 | tuiGetBeginAsmAddress (void) |
c906108c SS |
224 | { |
225 | TuiGenWinInfoPtr locator; | |
226 | TuiLocatorElementPtr element; | |
c774cec6 | 227 | CORE_ADDR addr; |
c906108c SS |
228 | |
229 | locator = locatorWinInfoPtr (); | |
230 | element = &((TuiWinElementPtr) locator->content[0])->whichElement.locator; | |
231 | ||
c774cec6 | 232 | if (element->addr == 0) |
c906108c | 233 | { |
c5aa993b | 234 | /*the target is not executing, because the pc is 0 */ |
c906108c | 235 | |
c774cec6 | 236 | addr = parse_and_eval_address ("main"); |
c906108c | 237 | |
c774cec6 SC |
238 | if (addr == 0) |
239 | addr = parse_and_eval_address ("MAIN"); | |
c906108c SS |
240 | |
241 | } | |
242 | else /* the target is executing */ | |
243 | addr = element->addr; | |
244 | ||
245 | return addr; | |
246 | } /* tuiGetBeginAsmAddress */ | |
247 | ||
248 | ||
249 | /* | |
c5aa993b JM |
250 | ** tuiVerticalDisassemScroll(). |
251 | ** Scroll the disassembly forward or backward vertically | |
252 | */ | |
c906108c | 253 | void |
eca6576c SC |
254 | tuiVerticalDisassemScroll (TuiScrollDirection scrollDirection, |
255 | int numToScroll) | |
c906108c SS |
256 | { |
257 | if (disassemWin->generic.content != (OpaquePtr) NULL) | |
258 | { | |
3024f13a | 259 | CORE_ADDR pc, lowAddr; |
c906108c SS |
260 | TuiWinContent content; |
261 | struct symtab *s; | |
262 | ||
263 | content = (TuiWinContent) disassemWin->generic.content; | |
264 | if (current_source_symtab == (struct symtab *) NULL) | |
265 | s = find_pc_symtab (selected_frame->pc); | |
266 | else | |
267 | s = current_source_symtab; | |
268 | ||
269 | pc = content[0]->whichElement.source.lineOrAddr.addr; | |
3024f13a SC |
270 | if (find_pc_partial_function (pc, (char **) NULL, &lowAddr, |
271 | (CORE_ADDR) 0) == 0) | |
272 | error ("No function contains program counter for selected frame.\n"); | |
c906108c SS |
273 | else |
274 | { | |
275 | register int line = 0; | |
3024f13a | 276 | register CORE_ADDR newLow; |
c906108c | 277 | bfd_byte buffer[4]; |
a4b99e53 | 278 | TuiLineOrAddress val; |
c906108c SS |
279 | |
280 | newLow = pc; | |
281 | if (scrollDirection == FORWARD_SCROLL) | |
282 | { | |
283 | for (; line < numToScroll; line++) | |
284 | newLow += sizeof (bfd_getb32 (buffer)); | |
285 | } | |
286 | else | |
287 | { | |
a4b99e53 | 288 | for (; newLow != 0 && line < numToScroll; line++) |
c906108c SS |
289 | newLow -= sizeof (bfd_getb32 (buffer)); |
290 | } | |
a4b99e53 SC |
291 | val.addr = newLow; |
292 | tuiUpdateSourceWindowAsIs (disassemWin, s, val, FALSE); | |
c906108c SS |
293 | } |
294 | } | |
295 | ||
296 | return; | |
297 | } /* tuiVerticalDisassemScroll */ | |
298 | ||
299 | ||
300 | ||
301 | /***************************************** | |
302 | ** STATIC LOCAL FUNCTIONS ** | |
303 | ******************************************/ | |
304 | /* | |
c5aa993b JM |
305 | ** _hasBreak(). |
306 | ** Answer whether there is a break point at the input line in the | |
307 | ** source file indicated | |
308 | */ | |
c906108c | 309 | static struct breakpoint * |
eca6576c | 310 | _hasBreak (CORE_ADDR addr) |
c906108c SS |
311 | { |
312 | struct breakpoint *bpWithBreak = (struct breakpoint *) NULL; | |
313 | struct breakpoint *bp; | |
314 | extern struct breakpoint *breakpoint_chain; | |
315 | ||
316 | ||
317 | for (bp = breakpoint_chain; | |
318 | (bp != (struct breakpoint *) NULL && | |
319 | bpWithBreak == (struct breakpoint *) NULL); | |
320 | bp = bp->next) | |
321 | if (addr == bp->address) | |
322 | bpWithBreak = bp; | |
323 | ||
324 | return bpWithBreak; | |
325 | } /* _hasBreak */ |