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