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