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
= gdb_file_init_astring (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 (gdb_file_get_strbuf (gdb_dis_out
));
86 i
= curLen
- ((curLen
/ tab_len
) * tab_len
);
88 /* adjust buffer length if necessary */
89 gdb_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 gdb_file_get_strbuf (gdb_dis_out
)[curLen
] = ' ';
98 gdb_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 (gdb_file_get_strbuf (gdb_dis_out
)) > offset
)
104 strcpy (element
->whichElement
.source
.line
,
105 &(gdb_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 gdb_file_get_strbuf (gdb_dis_out
)[0] = '\0';
121 gdb_file_deallocate (&gdb_dis_out
);
122 disassemWin
->generic
.contentSize
= curLine
;
128 } /* tuiSetDisassemContent */
132 ** tuiShowDisassem().
133 ** Function to display the disassembly window with disassembled code.
140 tuiShowDisassem (startAddr
)
144 struct symtab
*s
= find_pc_symtab ((CORE_ADDR
) startAddr
);
145 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
147 tuiAddWinToLayout (DISASSEM_WIN
);
148 tuiUpdateSourceWindow (disassemWin
, s
, startAddr
, FALSE
);
150 ** if the focus was in the src win, put it in the asm win, if the
151 ** source view isn't split
153 if (currentLayout () != SRC_DISASSEM_COMMAND
&& winWithFocus
== srcWin
)
154 tuiSetWinFocusTo (disassemWin
);
157 } /* tuiShowDisassem */
161 ** tuiShowDisassemAndUpdateSource().
162 ** Function to display the disassembly window.
166 tuiShowDisassemAndUpdateSource (
169 tuiShowDisassemAndUpdateSource (startAddr
)
173 struct symtab_and_line sal
;
175 tuiShowDisassem (startAddr
);
176 if (currentLayout () == SRC_DISASSEM_COMMAND
)
178 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
180 ** Update what is in the source window if it is displayed too,
181 ** note that it follows what is in the disassembly window and visa-versa
183 sal
= find_pc_line ((CORE_ADDR
) startAddr
, 0);
184 current_source_symtab
= sal
.symtab
;
185 tuiUpdateSourceWindow (srcWin
, sal
.symtab
, (Opaque
) sal
.line
, TRUE
);
186 tuiUpdateLocatorFilename (sal
.symtab
->filename
);
190 } /* tuiShowDisassemAndUpdateSource */
194 ** tuiShowDisassemAsIs().
195 ** Function to display the disassembly window. This function shows
196 ** the disassembly as specified by the horizontal offset.
200 tuiShowDisassemAsIs (
203 tuiShowDisassemAsIs (addr
)
207 tuiAddWinToLayout (DISASSEM_WIN
);
208 tuiUpdateSourceWindowAsIs (disassemWin
, (struct symtab
*) NULL
, addr
, FALSE
);
210 ** Update what is in the source window if it is displayed too, not that it
211 ** follows what is in the disassembly window and visa-versa
213 if (currentLayout () == SRC_DISASSEM_COMMAND
)
214 tuiShowSourceContent (srcWin
); /*???? Need to do more? */
217 } /* tuiShowDisassem */
221 ** tuiGetBeginAsmAddress().
225 tuiGetBeginAsmAddress (void)
227 tuiGetBeginAsmAddress ()
230 TuiGenWinInfoPtr locator
;
231 TuiLocatorElementPtr element
;
234 locator
= locatorWinInfoPtr ();
235 element
= &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
;
237 if (element
->addr
== (Opaque
) 0)
239 /*the target is not executing, because the pc is 0*/
241 addr
= (Opaque
) parse_and_eval_address ("main");
243 if (addr
== (Opaque
) 0)
244 addr
= (Opaque
) parse_and_eval_address ("MAIN");
247 else /* the target is executing */
248 addr
= element
->addr
;
251 } /* tuiGetBeginAsmAddress */
255 ** tuiVerticalDisassemScroll().
256 ** Scroll the disassembly forward or backward vertically
260 tuiVerticalDisassemScroll (
261 TuiScrollDirection scrollDirection
,
264 tuiVerticalDisassemScroll (scrollDirection
, numToScroll
)
265 TuiScrollDirection scrollDirection
;
269 if (disassemWin
->generic
.content
!= (OpaquePtr
) NULL
)
272 TuiWinContent content
;
275 content
= (TuiWinContent
) disassemWin
->generic
.content
;
276 if (current_source_symtab
== (struct symtab
*) NULL
)
277 s
= find_pc_symtab (selected_frame
->pc
);
279 s
= current_source_symtab
;
281 pc
= content
[0]->whichElement
.source
.lineOrAddr
.addr
;
282 if (find_pc_partial_function ((CORE_ADDR
) pc
,
284 (CORE_ADDR
*) & lowAddr
,
285 (CORE_ADDR
) NULL
) == 0)
286 error ("No function contains prgram counter for selected frame.\n");
289 register int line
= 0;
290 register Opaque newLow
;
294 if (scrollDirection
== FORWARD_SCROLL
)
296 for (; line
< numToScroll
; line
++)
297 newLow
+= sizeof (bfd_getb32 (buffer
));
301 for (; newLow
>= (Opaque
) 0 && line
< numToScroll
; line
++)
302 newLow
-= sizeof (bfd_getb32 (buffer
));
304 tuiUpdateSourceWindowAsIs (disassemWin
, s
, newLow
, FALSE
);
309 } /* tuiVerticalDisassemScroll */
313 /*****************************************
314 ** STATIC LOCAL FUNCTIONS **
315 ******************************************/
318 ** Answer whether there is a break point at the input line in the
319 ** source file indicated
321 static struct breakpoint
*
330 struct breakpoint
*bpWithBreak
= (struct breakpoint
*) NULL
;
331 struct breakpoint
*bp
;
332 extern struct breakpoint
*breakpoint_chain
;
335 for (bp
= breakpoint_chain
;
336 (bp
!= (struct breakpoint
*) NULL
&&
337 bpWithBreak
== (struct breakpoint
*) NULL
);
339 if (addr
== bp
->address
)