3 ** This module contains functions for handling disassembly display.
9 #include "breakpoint.h"
14 #include "tuiLayout.h"
15 #include "tuiSourceWin.h"
19 /*****************************************
20 ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
21 ******************************************/
23 static struct breakpoint
*_hasBreak
PARAMS ((CORE_ADDR
));
26 /*****************************************
27 ** PUBLIC FUNCTIONS **
28 ******************************************/
31 ** tuiSetDisassemContent().
32 ** Function to set the disassembly window's content.
36 tuiSetDisassemContent (
40 tuiSetDisassemContent (s
, startAddr
)
45 TuiStatus ret
= TUI_FAILURE
;
46 GDB_FILE
*gdb_dis_out
;
48 if (startAddr
!= (Opaque
) NULL
)
52 if ((ret
= tuiAllocSourceBuffer (disassemWin
)) == TUI_SUCCESS
)
54 register int offset
= disassemWin
->detail
.sourceInfo
.horizontalOffset
;
55 register int threshold
, curLine
= 0, lineWidth
, maxLines
;
57 disassemble_info asmInfo
;
58 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
59 extern void strcat_address
PARAMS ((CORE_ADDR
, char *, int));
60 extern void strcat_address_numeric
PARAMS ((CORE_ADDR
, int, char *, int));
62 int tab_len
= tuiDefaultTabLen ();
64 maxLines
= disassemWin
->generic
.height
- 2; /* account for hilite */
65 lineWidth
= disassemWin
->generic
.width
- 1;
66 threshold
= (lineWidth
- 1) + offset
;
68 /* now init the gdb_file structure */
69 gdb_dis_out
= tui_sfileopen (threshold
);
71 INIT_DISASSEMBLE_INFO_NO_ARCH (asmInfo
, gdb_dis_out
, (fprintf_ftype
) fprintf_filtered
);
72 asmInfo
.read_memory_func
= dis_asm_read_memory
;
73 asmInfo
.memory_error_func
= dis_asm_memory_error
;
75 disassemWin
->detail
.sourceInfo
.startLineOrAddr
.addr
= startAddr
;
77 /* Now construct each line */
78 for (curLine
= 0, pc
= (CORE_ADDR
) startAddr
; (curLine
< maxLines
);)
80 TuiWinElementPtr element
= (TuiWinElementPtr
) disassemWin
->generic
.content
[curLine
];
81 struct breakpoint
*bp
;
83 print_address (pc
, gdb_dis_out
);
85 curLen
= strlen (tui_file_get_strbuf (gdb_dis_out
));
86 i
= curLen
- ((curLen
/ tab_len
) * tab_len
);
88 /* adjust buffer length if necessary */
89 tui_file_adjust_strbuf ((tab_len
- i
> 0) ? (tab_len
- i
) : 0, gdb_dis_out
);
91 /* Add spaces to make the instructions start onthe same column */
94 tui_file_get_strbuf (gdb_dis_out
)[curLen
] = ' ';
98 tui_file_get_strbuf (gdb_dis_out
)[curLen
] = '\0';
100 newpc
= pc
+ ((*tm_print_insn
) (pc
, &asmInfo
));
102 /* Now copy the line taking the offset into account */
103 if (strlen (tui_file_get_strbuf (gdb_dis_out
)) > offset
)
104 strcpy (element
->whichElement
.source
.line
,
105 &(tui_file_get_strbuf (gdb_dis_out
)[offset
]));
107 element
->whichElement
.source
.line
[0] = '\0';
108 element
->whichElement
.source
.lineOrAddr
.addr
= (Opaque
) pc
;
109 element
->whichElement
.source
.isExecPoint
=
110 (pc
== (CORE_ADDR
) ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.addr
);
112 element
->whichElement
.source
.hasBreak
=
113 (bp
!= (struct breakpoint
*) NULL
&&
114 (!element
->whichElement
.source
.isExecPoint
||
115 (bp
->disposition
!= del
|| bp
->hit_count
<= 0)));
118 /* reset the buffer to empty */
119 tui_file_get_strbuf (gdb_dis_out
)[0] = '\0';
121 gdb_file_delete (gdb_dis_out
);
123 disassemWin
->generic
.contentSize
= curLine
;
129 } /* tuiSetDisassemContent */
133 ** tuiShowDisassem().
134 ** Function to display the disassembly window with disassembled code.
141 tuiShowDisassem (startAddr
)
145 struct symtab
*s
= find_pc_symtab ((CORE_ADDR
) startAddr
);
146 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
148 tuiAddWinToLayout (DISASSEM_WIN
);
149 tuiUpdateSourceWindow (disassemWin
, s
, startAddr
, FALSE
);
151 ** if the focus was in the src win, put it in the asm win, if the
152 ** source view isn't split
154 if (currentLayout () != SRC_DISASSEM_COMMAND
&& winWithFocus
== srcWin
)
155 tuiSetWinFocusTo (disassemWin
);
158 } /* tuiShowDisassem */
162 ** tuiShowDisassemAndUpdateSource().
163 ** Function to display the disassembly window.
167 tuiShowDisassemAndUpdateSource (
170 tuiShowDisassemAndUpdateSource (startAddr
)
174 struct symtab_and_line sal
;
176 tuiShowDisassem (startAddr
);
177 if (currentLayout () == SRC_DISASSEM_COMMAND
)
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 ((CORE_ADDR
) startAddr
, 0);
185 current_source_symtab
= sal
.symtab
;
186 tuiUpdateSourceWindow (srcWin
, sal
.symtab
, (Opaque
) sal
.line
, TRUE
);
187 tuiUpdateLocatorFilename (sal
.symtab
->filename
);
191 } /* tuiShowDisassemAndUpdateSource */
195 ** tuiShowDisassemAsIs().
196 ** Function to display the disassembly window. This function shows
197 ** the disassembly as specified by the horizontal offset.
201 tuiShowDisassemAsIs (
204 tuiShowDisassemAsIs (addr
)
208 tuiAddWinToLayout (DISASSEM_WIN
);
209 tuiUpdateSourceWindowAsIs (disassemWin
, (struct symtab
*) NULL
, addr
, FALSE
);
211 ** Update what is in the source window if it is displayed too, not that it
212 ** follows what is in the disassembly window and visa-versa
214 if (currentLayout () == SRC_DISASSEM_COMMAND
)
215 tuiShowSourceContent (srcWin
); /*???? Need to do more? */
218 } /* tuiShowDisassem */
222 ** tuiGetBeginAsmAddress().
226 tuiGetBeginAsmAddress (void)
228 tuiGetBeginAsmAddress ()
231 TuiGenWinInfoPtr locator
;
232 TuiLocatorElementPtr element
;
235 locator
= locatorWinInfoPtr ();
236 element
= &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
;
238 if (element
->addr
== (Opaque
) 0)
240 /*the target is not executing, because the pc is 0 */
242 addr
= (Opaque
) parse_and_eval_address ("main");
244 if (addr
== (Opaque
) 0)
245 addr
= (Opaque
) parse_and_eval_address ("MAIN");
248 else /* the target is executing */
249 addr
= element
->addr
;
252 } /* tuiGetBeginAsmAddress */
256 ** tuiVerticalDisassemScroll().
257 ** Scroll the disassembly forward or backward vertically
261 tuiVerticalDisassemScroll (
262 TuiScrollDirection scrollDirection
,
265 tuiVerticalDisassemScroll (scrollDirection
, numToScroll
)
266 TuiScrollDirection scrollDirection
;
270 if (disassemWin
->generic
.content
!= (OpaquePtr
) NULL
)
273 TuiWinContent content
;
276 content
= (TuiWinContent
) disassemWin
->generic
.content
;
277 if (current_source_symtab
== (struct symtab
*) NULL
)
278 s
= find_pc_symtab (selected_frame
->pc
);
280 s
= current_source_symtab
;
282 pc
= content
[0]->whichElement
.source
.lineOrAddr
.addr
;
283 if (find_pc_partial_function ((CORE_ADDR
) pc
,
285 (CORE_ADDR
*) & lowAddr
,
286 (CORE_ADDR
) NULL
) == 0)
287 error ("No function contains prgram counter for selected frame.\n");
290 register int line
= 0;
291 register Opaque newLow
;
295 if (scrollDirection
== FORWARD_SCROLL
)
297 for (; line
< numToScroll
; line
++)
298 newLow
+= sizeof (bfd_getb32 (buffer
));
302 for (; newLow
>= (Opaque
) 0 && line
< numToScroll
; line
++)
303 newLow
-= sizeof (bfd_getb32 (buffer
));
305 tuiUpdateSourceWindowAsIs (disassemWin
, s
, newLow
, FALSE
);
310 } /* tuiVerticalDisassemScroll */
314 /*****************************************
315 ** STATIC LOCAL FUNCTIONS **
316 ******************************************/
319 ** Answer whether there is a break point at the input line in the
320 ** source file indicated
322 static struct breakpoint
*
331 struct breakpoint
*bpWithBreak
= (struct breakpoint
*) NULL
;
332 struct breakpoint
*bp
;
333 extern struct breakpoint
*breakpoint_chain
;
336 for (bp
= breakpoint_chain
;
337 (bp
!= (struct breakpoint
*) NULL
&&
338 bpWithBreak
== (struct breakpoint
*) NULL
);
340 if (addr
== bp
->address
)