1 /* Disassembly display.
2 Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Hewlett-Packard Company.
5 This file is part of GDB.
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.
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.
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. */
24 #include "breakpoint.h"
31 #include "tuiLayout.h"
32 #include "tuiSourceWin.h"
37 /*****************************************
38 ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
39 ******************************************/
41 static struct breakpoint
*_hasBreak (CORE_ADDR
);
44 /*****************************************
45 ** PUBLIC FUNCTIONS **
46 ******************************************/
49 ** tuiSetDisassemContent().
50 ** Function to set the disassembly window's content.
53 tuiSetDisassemContent (struct symtab
*s
, CORE_ADDR startAddr
)
55 TuiStatus ret
= TUI_FAILURE
;
56 struct ui_file
*gdb_dis_out
;
62 if ((ret
= tuiAllocSourceBuffer (disassemWin
)) == TUI_SUCCESS
)
64 register int offset
= disassemWin
->detail
.sourceInfo
.horizontalOffset
;
65 register int threshold
, curLine
= 0, lineWidth
, maxLines
;
67 disassemble_info asmInfo
;
68 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
69 extern void strcat_address (CORE_ADDR
, char *, int);
70 extern void strcat_address_numeric (CORE_ADDR
, int, char *, int);
72 int tab_len
= tuiDefaultTabLen ();
74 maxLines
= disassemWin
->generic
.height
- 2; /* account for hilite */
75 lineWidth
= disassemWin
->generic
.width
- 1;
76 threshold
= (lineWidth
- 1) + offset
;
78 /* now init the ui_file structure */
79 gdb_dis_out
= tui_sfileopen (threshold
);
81 asmInfo
= tm_print_insn_info
;
82 asmInfo
.stream
= gdb_dis_out
;
84 disassemWin
->detail
.sourceInfo
.startLineOrAddr
.addr
= startAddr
;
86 /* Now construct each line */
87 for (curLine
= 0, pc
= startAddr
; (curLine
< maxLines
);)
89 TuiWinElementPtr element
= (TuiWinElementPtr
) disassemWin
->generic
.content
[curLine
];
90 struct breakpoint
*bp
;
92 print_address (pc
, gdb_dis_out
);
94 curLen
= strlen (tui_file_get_strbuf (gdb_dis_out
));
95 i
= curLen
- ((curLen
/ tab_len
) * tab_len
);
97 /* adjust buffer length if necessary */
98 tui_file_adjust_strbuf ((tab_len
- i
> 0) ? (tab_len
- i
) : 0, gdb_dis_out
);
100 /* Add spaces to make the instructions start onthe same column */
103 tui_file_get_strbuf (gdb_dis_out
)[curLen
] = ' ';
107 tui_file_get_strbuf (gdb_dis_out
)[curLen
] = '\0';
109 newpc
= pc
+ ((*tm_print_insn
) (pc
, &asmInfo
));
111 /* Now copy the line taking the offset into account */
112 if (strlen (tui_file_get_strbuf (gdb_dis_out
)) > offset
)
113 strcpy (element
->whichElement
.source
.line
,
114 &(tui_file_get_strbuf (gdb_dis_out
)[offset
]));
116 element
->whichElement
.source
.line
[0] = '\0';
117 element
->whichElement
.source
.lineOrAddr
.addr
= pc
;
118 element
->whichElement
.source
.isExecPoint
=
119 (pc
== (CORE_ADDR
) ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.addr
);
121 element
->whichElement
.source
.hasBreak
=
122 (bp
!= (struct breakpoint
*) NULL
&&
123 (!element
->whichElement
.source
.isExecPoint
||
124 (bp
->disposition
!= disp_del
|| bp
->hit_count
<= 0)));
127 /* reset the buffer to empty */
128 tui_file_get_strbuf (gdb_dis_out
)[0] = '\0';
130 ui_file_delete (gdb_dis_out
);
132 disassemWin
->generic
.contentSize
= curLine
;
138 } /* tuiSetDisassemContent */
142 ** tuiShowDisassem().
143 ** Function to display the disassembly window with disassembled code.
146 tuiShowDisassem (CORE_ADDR startAddr
)
148 struct symtab
*s
= find_pc_symtab (startAddr
);
149 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
150 TuiLineOrAddress val
;
152 val
.addr
= startAddr
;
153 tuiAddWinToLayout (DISASSEM_WIN
);
154 tuiUpdateSourceWindow (disassemWin
, s
, val
, FALSE
);
156 ** if the focus was in the src win, put it in the asm win, if the
157 ** source view isn't split
159 if (currentLayout () != SRC_DISASSEM_COMMAND
&& winWithFocus
== srcWin
)
160 tuiSetWinFocusTo (disassemWin
);
163 } /* tuiShowDisassem */
167 ** tuiShowDisassemAndUpdateSource().
168 ** Function to display the disassembly window.
171 tuiShowDisassemAndUpdateSource (CORE_ADDR startAddr
)
173 struct symtab_and_line sal
;
175 tuiShowDisassem (startAddr
);
176 if (currentLayout () == SRC_DISASSEM_COMMAND
)
178 TuiLineOrAddress val
;
179 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
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
184 sal
= find_pc_line (startAddr
, 0);
185 val
.lineNo
= sal
.line
;
186 tuiUpdateSourceWindow (srcWin
, sal
.symtab
, val
, TRUE
);
189 current_source_symtab
= sal
.symtab
;
190 tuiUpdateLocatorFilename (sal
.symtab
->filename
);
193 tuiUpdateLocatorFilename ("?");
197 } /* tuiShowDisassemAndUpdateSource */
200 ** tuiGetBeginAsmAddress().
203 tuiGetBeginAsmAddress (void)
205 TuiGenWinInfoPtr locator
;
206 TuiLocatorElementPtr element
;
209 locator
= locatorWinInfoPtr ();
210 element
= &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
;
212 if (element
->addr
== 0)
214 /*the target is not executing, because the pc is 0 */
216 addr
= parse_and_eval_address ("main");
219 addr
= parse_and_eval_address ("MAIN");
222 else /* the target is executing */
223 addr
= element
->addr
;
226 } /* tuiGetBeginAsmAddress */
230 ** tuiVerticalDisassemScroll().
231 ** Scroll the disassembly forward or backward vertically
234 tuiVerticalDisassemScroll (TuiScrollDirection scrollDirection
,
237 if (disassemWin
->generic
.content
!= (OpaquePtr
) NULL
)
239 CORE_ADDR pc
, lowAddr
;
240 TuiWinContent content
;
243 content
= (TuiWinContent
) disassemWin
->generic
.content
;
244 if (current_source_symtab
== (struct symtab
*) NULL
)
245 s
= find_pc_symtab (selected_frame
->pc
);
247 s
= current_source_symtab
;
249 pc
= content
[0]->whichElement
.source
.lineOrAddr
.addr
;
250 if (find_pc_partial_function (pc
, (char **) NULL
, &lowAddr
,
252 error ("No function contains program counter for selected frame.\n");
255 register int line
= 0;
256 register CORE_ADDR newLow
;
258 TuiLineOrAddress val
;
261 if (scrollDirection
== FORWARD_SCROLL
)
263 for (; line
< numToScroll
; line
++)
264 newLow
+= sizeof (bfd_getb32 (buffer
));
268 for (; newLow
!= 0 && line
< numToScroll
; line
++)
269 newLow
-= sizeof (bfd_getb32 (buffer
));
272 tuiUpdateSourceWindowAsIs (disassemWin
, s
, val
, FALSE
);
277 } /* tuiVerticalDisassemScroll */
281 /*****************************************
282 ** STATIC LOCAL FUNCTIONS **
283 ******************************************/
286 ** Answer whether there is a break point at the input line in the
287 ** source file indicated
289 static struct breakpoint
*
290 _hasBreak (CORE_ADDR addr
)
292 struct breakpoint
*bpWithBreak
= (struct breakpoint
*) NULL
;
293 struct breakpoint
*bp
;
294 extern struct breakpoint
*breakpoint_chain
;
297 for (bp
= breakpoint_chain
;
298 (bp
!= (struct breakpoint
*) NULL
&&
299 bpWithBreak
== (struct breakpoint
*) NULL
);
301 if (addr
== bp
->address
)