1 /* Disassembly display.
3 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation,
6 Contributed by Hewlett-Packard Company.
8 This file is part of GDB.
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.
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.
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. */
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>
44 #include "breakpoint.h"
51 #include "tuiLayout.h"
52 #include "tuiSourceWin.h"
57 /*****************************************
58 ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
59 ******************************************/
61 static struct breakpoint
*_hasBreak (CORE_ADDR
);
64 /*****************************************
65 ** PUBLIC FUNCTIONS **
66 ******************************************/
69 ** tuiSetDisassemContent().
70 ** Function to set the disassembly window's content.
73 tuiSetDisassemContent (struct symtab
*s
, CORE_ADDR startAddr
)
75 TuiStatus ret
= TUI_FAILURE
;
76 struct ui_file
*gdb_dis_out
;
82 if ((ret
= tuiAllocSourceBuffer (disassemWin
)) == TUI_SUCCESS
)
84 register int offset
= disassemWin
->detail
.sourceInfo
.horizontalOffset
;
85 register int threshold
, curLine
= 0, lineWidth
, maxLines
;
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);
92 int tab_len
= tuiDefaultTabLen ();
94 maxLines
= disassemWin
->generic
.height
- 2; /* account for hilite */
95 lineWidth
= disassemWin
->generic
.width
- 1;
96 threshold
= (lineWidth
- 1) + offset
;
98 /* now init the ui_file structure */
99 gdb_dis_out
= tui_sfileopen (threshold
);
101 asmInfo
= tm_print_insn_info
;
102 asmInfo
.stream
= gdb_dis_out
;
104 disassemWin
->detail
.sourceInfo
.startLineOrAddr
.addr
= startAddr
;
106 /* Now construct each line */
107 for (curLine
= 0, pc
= startAddr
; (curLine
< maxLines
);)
109 TuiWinElementPtr element
= (TuiWinElementPtr
) disassemWin
->generic
.content
[curLine
];
110 struct breakpoint
*bp
;
112 print_address (pc
, gdb_dis_out
);
114 curLen
= strlen (tui_file_get_strbuf (gdb_dis_out
));
115 i
= curLen
- ((curLen
/ tab_len
) * tab_len
);
117 /* adjust buffer length if necessary */
118 tui_file_adjust_strbuf ((tab_len
- i
> 0) ? (tab_len
- i
) : 0, gdb_dis_out
);
120 /* Add spaces to make the instructions start onthe same column */
123 tui_file_get_strbuf (gdb_dis_out
)[curLen
] = ' ';
127 tui_file_get_strbuf (gdb_dis_out
)[curLen
] = '\0';
129 newpc
= pc
+ ((*tm_print_insn
) (pc
, &asmInfo
));
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
]));
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
);
141 element
->whichElement
.source
.hasBreak
=
142 (bp
!= (struct breakpoint
*) NULL
&&
143 (!element
->whichElement
.source
.isExecPoint
||
144 (bp
->disposition
!= disp_del
|| bp
->hit_count
<= 0)));
147 /* reset the buffer to empty */
148 tui_file_get_strbuf (gdb_dis_out
)[0] = '\0';
150 ui_file_delete (gdb_dis_out
);
152 disassemWin
->generic
.contentSize
= curLine
;
158 } /* tuiSetDisassemContent */
162 ** tuiShowDisassem().
163 ** Function to display the disassembly window with disassembled code.
166 tuiShowDisassem (CORE_ADDR startAddr
)
168 struct symtab
*s
= find_pc_symtab (startAddr
);
169 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
170 TuiLineOrAddress val
;
172 val
.addr
= startAddr
;
173 tuiAddWinToLayout (DISASSEM_WIN
);
174 tuiUpdateSourceWindow (disassemWin
, s
, val
, FALSE
);
176 ** if the focus was in the src win, put it in the asm win, if the
177 ** source view isn't split
179 if (currentLayout () != SRC_DISASSEM_COMMAND
&& winWithFocus
== srcWin
)
180 tuiSetWinFocusTo (disassemWin
);
183 } /* tuiShowDisassem */
187 ** tuiShowDisassemAndUpdateSource().
188 ** Function to display the disassembly window.
191 tuiShowDisassemAndUpdateSource (CORE_ADDR startAddr
)
193 struct symtab_and_line sal
;
195 tuiShowDisassem (startAddr
);
196 if (currentLayout () == SRC_DISASSEM_COMMAND
)
198 TuiLineOrAddress val
;
199 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
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
204 sal
= find_pc_line (startAddr
, 0);
205 val
.lineNo
= sal
.line
;
206 tuiUpdateSourceWindow (srcWin
, sal
.symtab
, val
, TRUE
);
209 current_source_symtab
= sal
.symtab
;
210 tuiUpdateLocatorFilename (sal
.symtab
->filename
);
213 tuiUpdateLocatorFilename ("?");
217 } /* tuiShowDisassemAndUpdateSource */
220 ** tuiGetBeginAsmAddress().
223 tuiGetBeginAsmAddress (void)
225 TuiGenWinInfoPtr locator
;
226 TuiLocatorElementPtr element
;
229 locator
= locatorWinInfoPtr ();
230 element
= &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
;
232 if (element
->addr
== 0)
234 /*the target is not executing, because the pc is 0 */
236 addr
= parse_and_eval_address ("main");
239 addr
= parse_and_eval_address ("MAIN");
242 else /* the target is executing */
243 addr
= element
->addr
;
246 } /* tuiGetBeginAsmAddress */
250 ** tuiVerticalDisassemScroll().
251 ** Scroll the disassembly forward or backward vertically
254 tuiVerticalDisassemScroll (TuiScrollDirection scrollDirection
,
257 if (disassemWin
->generic
.content
!= (OpaquePtr
) NULL
)
259 CORE_ADDR pc
, lowAddr
;
260 TuiWinContent content
;
263 content
= (TuiWinContent
) disassemWin
->generic
.content
;
264 if (current_source_symtab
== (struct symtab
*) NULL
)
265 s
= find_pc_symtab (selected_frame
->pc
);
267 s
= current_source_symtab
;
269 pc
= content
[0]->whichElement
.source
.lineOrAddr
.addr
;
270 if (find_pc_partial_function (pc
, (char **) NULL
, &lowAddr
,
272 error ("No function contains program counter for selected frame.\n");
275 register int line
= 0;
276 register CORE_ADDR newLow
;
278 TuiLineOrAddress val
;
281 if (scrollDirection
== FORWARD_SCROLL
)
283 for (; line
< numToScroll
; line
++)
284 newLow
+= sizeof (bfd_getb32 (buffer
));
288 for (; newLow
!= 0 && line
< numToScroll
; line
++)
289 newLow
-= sizeof (bfd_getb32 (buffer
));
292 tuiUpdateSourceWindowAsIs (disassemWin
, s
, val
, FALSE
);
297 } /* tuiVerticalDisassemScroll */
301 /*****************************************
302 ** STATIC LOCAL FUNCTIONS **
303 ******************************************/
306 ** Answer whether there is a break point at the input line in the
307 ** source file indicated
309 static struct breakpoint
*
310 _hasBreak (CORE_ADDR addr
)
312 struct breakpoint
*bpWithBreak
= (struct breakpoint
*) NULL
;
313 struct breakpoint
*bp
;
314 extern struct breakpoint
*breakpoint_chain
;
317 for (bp
= breakpoint_chain
;
318 (bp
!= (struct breakpoint
*) NULL
&&
319 bpWithBreak
== (struct breakpoint
*) NULL
);
321 if (addr
== bp
->address
)