Add FIXME explaining include problem.
[deliverable/binutils-gdb.git] / gdb / tui / tuiDisassem.c
1 /* Disassembly display.
2
3 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation,
4 Inc.
5
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. */
24
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
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
42 #include "defs.h"
43 #include "symtab.h"
44 #include "breakpoint.h"
45 #include "frame.h"
46 #include "value.h"
47
48 #include "tui.h"
49 #include "tuiData.h"
50 #include "tuiWin.h"
51 #include "tuiLayout.h"
52 #include "tuiSourceWin.h"
53 #include "tuiStack.h"
54 #include "tui-file.h"
55
56
57 /*****************************************
58 ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
59 ******************************************/
60
61 static struct breakpoint *_hasBreak (CORE_ADDR);
62
63
64 /*****************************************
65 ** PUBLIC FUNCTIONS **
66 ******************************************/
67
68 /*
69 ** tuiSetDisassemContent().
70 ** Function to set the disassembly window's content.
71 */
72 TuiStatus
73 tuiSetDisassemContent (struct symtab *s, CORE_ADDR startAddr)
74 {
75 TuiStatus ret = TUI_FAILURE;
76 struct ui_file *gdb_dis_out;
77
78 if (startAddr != 0)
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 ();
89 extern void strcat_address (CORE_ADDR, char *, int);
90 extern void strcat_address_numeric (CORE_ADDR, int, char *, int);
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
98 /* now init the ui_file structure */
99 gdb_dis_out = tui_sfileopen (threshold);
100
101 asmInfo = tm_print_insn_info;
102 asmInfo.stream = gdb_dis_out;
103
104 disassemWin->detail.sourceInfo.startLineOrAddr.addr = startAddr;
105
106 /* Now construct each line */
107 for (curLine = 0, pc = startAddr; (curLine < maxLines);)
108 {
109 TuiWinElementPtr element = (TuiWinElementPtr) disassemWin->generic.content[curLine];
110 struct breakpoint *bp;
111
112 print_address (pc, gdb_dis_out);
113
114 curLen = strlen (tui_file_get_strbuf (gdb_dis_out));
115 i = curLen - ((curLen / tab_len) * tab_len);
116
117 /* adjust buffer length if necessary */
118 tui_file_adjust_strbuf ((tab_len - i > 0) ? (tab_len - i) : 0, gdb_dis_out);
119
120 /* Add spaces to make the instructions start onthe same column */
121 while (i < tab_len)
122 {
123 tui_file_get_strbuf (gdb_dis_out)[curLen] = ' ';
124 i++;
125 curLen++;
126 }
127 tui_file_get_strbuf (gdb_dis_out)[curLen] = '\0';
128
129 newpc = pc + ((*tm_print_insn) (pc, &asmInfo));
130
131 /* Now copy the line taking the offset into account */
132 if (strlen (tui_file_get_strbuf (gdb_dis_out)) > offset)
133 strcpy (element->whichElement.source.line,
134 &(tui_file_get_strbuf (gdb_dis_out)[offset]));
135 else
136 element->whichElement.source.line[0] = '\0';
137 element->whichElement.source.lineOrAddr.addr = pc;
138 element->whichElement.source.isExecPoint =
139 (pc == (CORE_ADDR) ((TuiWinElementPtr) locator->content[0])->whichElement.locator.addr);
140 bp = _hasBreak (pc);
141 element->whichElement.source.hasBreak =
142 (bp != (struct breakpoint *) NULL &&
143 (!element->whichElement.source.isExecPoint ||
144 (bp->disposition != disp_del || bp->hit_count <= 0)));
145 curLine++;
146 pc = newpc;
147 /* reset the buffer to empty */
148 tui_file_get_strbuf (gdb_dis_out)[0] = '\0';
149 }
150 ui_file_delete (gdb_dis_out);
151 gdb_dis_out = NULL;
152 disassemWin->generic.contentSize = curLine;
153 ret = TUI_SUCCESS;
154 }
155 }
156
157 return ret;
158 } /* tuiSetDisassemContent */
159
160
161 /*
162 ** tuiShowDisassem().
163 ** Function to display the disassembly window with disassembled code.
164 */
165 void
166 tuiShowDisassem (CORE_ADDR startAddr)
167 {
168 struct symtab *s = find_pc_symtab (startAddr);
169 TuiWinInfoPtr winWithFocus = tuiWinWithFocus ();
170 TuiLineOrAddress val;
171
172 val.addr = startAddr;
173 tuiAddWinToLayout (DISASSEM_WIN);
174 tuiUpdateSourceWindow (disassemWin, s, val, FALSE);
175 /*
176 ** if the focus was in the src win, put it in the asm win, if the
177 ** source view isn't split
178 */
179 if (currentLayout () != SRC_DISASSEM_COMMAND && winWithFocus == srcWin)
180 tuiSetWinFocusTo (disassemWin);
181
182 return;
183 } /* tuiShowDisassem */
184
185
186 /*
187 ** tuiShowDisassemAndUpdateSource().
188 ** Function to display the disassembly window.
189 */
190 void
191 tuiShowDisassemAndUpdateSource (CORE_ADDR startAddr)
192 {
193 struct symtab_and_line sal;
194
195 tuiShowDisassem (startAddr);
196 if (currentLayout () == SRC_DISASSEM_COMMAND)
197 {
198 TuiLineOrAddress val;
199 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
200 /*
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 */
204 sal = find_pc_line (startAddr, 0);
205 val.lineNo = sal.line;
206 tuiUpdateSourceWindow (srcWin, sal.symtab, val, TRUE);
207 if (sal.symtab)
208 {
209 current_source_symtab = sal.symtab;
210 tuiUpdateLocatorFilename (sal.symtab->filename);
211 }
212 else
213 tuiUpdateLocatorFilename ("?");
214 }
215
216 return;
217 } /* tuiShowDisassemAndUpdateSource */
218
219 /*
220 ** tuiGetBeginAsmAddress().
221 */
222 CORE_ADDR
223 tuiGetBeginAsmAddress (void)
224 {
225 TuiGenWinInfoPtr locator;
226 TuiLocatorElementPtr element;
227 CORE_ADDR addr;
228
229 locator = locatorWinInfoPtr ();
230 element = &((TuiWinElementPtr) locator->content[0])->whichElement.locator;
231
232 if (element->addr == 0)
233 {
234 /*the target is not executing, because the pc is 0 */
235
236 addr = parse_and_eval_address ("main");
237
238 if (addr == 0)
239 addr = parse_and_eval_address ("MAIN");
240
241 }
242 else /* the target is executing */
243 addr = element->addr;
244
245 return addr;
246 } /* tuiGetBeginAsmAddress */
247
248
249 /*
250 ** tuiVerticalDisassemScroll().
251 ** Scroll the disassembly forward or backward vertically
252 */
253 void
254 tuiVerticalDisassemScroll (TuiScrollDirection scrollDirection,
255 int numToScroll)
256 {
257 if (disassemWin->generic.content != (OpaquePtr) NULL)
258 {
259 CORE_ADDR pc, lowAddr;
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;
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");
273 else
274 {
275 register int line = 0;
276 register CORE_ADDR newLow;
277 bfd_byte buffer[4];
278 TuiLineOrAddress val;
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 {
288 for (; newLow != 0 && line < numToScroll; line++)
289 newLow -= sizeof (bfd_getb32 (buffer));
290 }
291 val.addr = newLow;
292 tuiUpdateSourceWindowAsIs (disassemWin, s, val, FALSE);
293 }
294 }
295
296 return;
297 } /* tuiVerticalDisassemScroll */
298
299
300
301 /*****************************************
302 ** STATIC LOCAL FUNCTIONS **
303 ******************************************/
304 /*
305 ** _hasBreak().
306 ** Answer whether there is a break point at the input line in the
307 ** source file indicated
308 */
309 static struct breakpoint *
310 _hasBreak (CORE_ADDR addr)
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 */
This page took 0.038699 seconds and 4 git commands to generate.