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