* tuiDisassem.c (tuiGetBeginAsmAddress): Use lookup_minimal_symbol
[deliverable/binutils-gdb.git] / gdb / tui / tuiDisassem.c
CommitLineData
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 61static 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 72TuiStatus
c774cec6 73tuiSetDisassemContent (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
89extern void strcat_address (CORE_ADDR, char *, int);
90extern 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 165void
c774cec6 166tuiShowDisassem (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 190void
c774cec6 191tuiShowDisassemAndUpdateSource (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 222CORE_ADDR
c906108c 223tuiGetBeginAsmAddress (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 {
0510ab86
SC
234 struct minimal_symbol *main_symbol;
235
236 /* Find address of the start of program.
237 Note: this should be language specific. */
238 main_symbol = lookup_minimal_symbol ("main", NULL, NULL);
239 if (main_symbol == 0)
240 main_symbol = lookup_minimal_symbol ("MAIN", NULL, NULL);
241 if (main_symbol == 0)
242 main_symbol = lookup_minimal_symbol ("_start", NULL, NULL);
243 if (main_symbol)
244 addr = SYMBOL_VALUE_ADDRESS (main_symbol);
245 else
246 addr = 0;
c906108c
SS
247 }
248 else /* the target is executing */
249 addr = element->addr;
250
251 return addr;
0510ab86 252}
c906108c
SS
253
254
255/*
c5aa993b
JM
256 ** tuiVerticalDisassemScroll().
257 ** Scroll the disassembly forward or backward vertically
258 */
c906108c 259void
eca6576c
SC
260tuiVerticalDisassemScroll (TuiScrollDirection scrollDirection,
261 int numToScroll)
c906108c
SS
262{
263 if (disassemWin->generic.content != (OpaquePtr) NULL)
264 {
3024f13a 265 CORE_ADDR pc, lowAddr;
c906108c
SS
266 TuiWinContent content;
267 struct symtab *s;
268
269 content = (TuiWinContent) disassemWin->generic.content;
270 if (current_source_symtab == (struct symtab *) NULL)
271 s = find_pc_symtab (selected_frame->pc);
272 else
273 s = current_source_symtab;
274
275 pc = content[0]->whichElement.source.lineOrAddr.addr;
3024f13a
SC
276 if (find_pc_partial_function (pc, (char **) NULL, &lowAddr,
277 (CORE_ADDR) 0) == 0)
278 error ("No function contains program counter for selected frame.\n");
c906108c
SS
279 else
280 {
281 register int line = 0;
3024f13a 282 register CORE_ADDR newLow;
c906108c 283 bfd_byte buffer[4];
a4b99e53 284 TuiLineOrAddress val;
c906108c
SS
285
286 newLow = pc;
287 if (scrollDirection == FORWARD_SCROLL)
288 {
289 for (; line < numToScroll; line++)
290 newLow += sizeof (bfd_getb32 (buffer));
291 }
292 else
293 {
a4b99e53 294 for (; newLow != 0 && line < numToScroll; line++)
c906108c
SS
295 newLow -= sizeof (bfd_getb32 (buffer));
296 }
a4b99e53
SC
297 val.addr = newLow;
298 tuiUpdateSourceWindowAsIs (disassemWin, s, val, FALSE);
c906108c
SS
299 }
300 }
301
302 return;
303} /* tuiVerticalDisassemScroll */
304
305
306
307/*****************************************
308** STATIC LOCAL FUNCTIONS **
309******************************************/
310/*
c5aa993b
JM
311 ** _hasBreak().
312 ** Answer whether there is a break point at the input line in the
313 ** source file indicated
314 */
c906108c 315static struct breakpoint *
eca6576c 316_hasBreak (CORE_ADDR addr)
c906108c
SS
317{
318 struct breakpoint *bpWithBreak = (struct breakpoint *) NULL;
319 struct breakpoint *bp;
320 extern struct breakpoint *breakpoint_chain;
321
322
323 for (bp = breakpoint_chain;
324 (bp != (struct breakpoint *) NULL &&
325 bpWithBreak == (struct breakpoint *) NULL);
326 bp = bp->next)
327 if (addr == bp->address)
328 bpWithBreak = bp;
329
330 return bpWithBreak;
331} /* _hasBreak */
This page took 0.253766 seconds and 4 git commands to generate.