TianoCore EDK2 master
Loading...
Searching...
No Matches
EdbCmdBranch.c
Go to the documentation of this file.
1
9#include "Edb.h"
10
11CHAR16 *mBranchTypeStr[] = {
12 L"(CALL)",
13 L"(CALLEX)",
14 L"(RET)",
15 L"(JMP)",
16 L"(JMP8)",
17};
18
28CHAR16 *
30 IN EFI_DEBUGGER_BRANCH_TYPE Type
31 )
32{
33 if ((Type < 0) || (Type >= EfiDebuggerBranchTypeEbcMax)) {
34 return L"(Unknown Type)";
35 }
36
37 return mBranchTypeStr[Type];
38}
39
52EFI_DEBUG_STATUS
54 IN CHAR16 *CommandArg,
55 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
56 IN EFI_EXCEPTION_TYPE ExceptionType,
57 IN OUT EFI_SYSTEM_CONTEXT SystemContext
58 )
59{
60 INTN Index;
61 UINTN SubIndex;
62 CHAR8 *FuncName;
63 EFI_DEBUGGER_CALLSTACK_CONTEXT *CallStackEntry;
64 BOOLEAN ShowParameter;
65 UINTN ParameterNumber;
66
67 ShowParameter = FALSE;
68 ParameterNumber = EFI_DEBUGGER_CALL_DEFAULT_PARAMETER;
69
70 //
71 // Check argument
72 //
73 if (CommandArg != NULL) {
74 if (StriCmp (CommandArg, L"c") == 0) {
75 //
76 // Clear Call-Stack
77 //
78 DebuggerPrivate->CallStackEntryCount = 0;
79 ZeroMem (DebuggerPrivate->CallStackEntry, sizeof (DebuggerPrivate->CallStackEntry));
80 EDBPrint (L"Call-Stack is cleared\n");
81 return EFI_DEBUG_CONTINUE;
82 } else if (StriCmp (CommandArg, L"p") == 0) {
83 //
84 // Print Call-Stack with parameter
85 //
86 ShowParameter = TRUE;
87 CommandArg = StrGetNextTokenLine (L" ");
88 if (CommandArg != NULL) {
89 //
90 // Try to get the parameter number
91 //
92 ParameterNumber = Atoi (CommandArg);
93 if (ParameterNumber > 16) {
94 EDBPrint (L"Call-Stack argument Invalid\n");
95 return EFI_DEBUG_CONTINUE;
96 }
97 }
98 } else {
99 EDBPrint (L"Call-Stack argument Invalid\n");
100 return EFI_DEBUG_CONTINUE;
101 }
102 }
103
104 //
105 // Check CallStack Entry Count
106 //
107 if (DebuggerPrivate->CallStackEntryCount == 0) {
108 EDBPrint (L"No Call-Stack\n");
109 return EFI_DEBUG_CONTINUE;
110 } else if (DebuggerPrivate->CallStackEntryCount > EFI_DEBUGGER_CALLSTACK_MAX) {
111 EDBPrint (L"Call-Stack Crash, re-initialize!\n");
112 DebuggerPrivate->CallStackEntryCount = 0;
113 return EFI_DEBUG_CONTINUE;
114 }
115
116 //
117 // Go through each CallStack entry and print
118 //
119 EDBPrint (L"Call-Stack (TOP):\n");
120 EDBPrint (L" Caller Callee Name\n");
121 EDBPrint (L" ================== ================== ========\n");
122 // EDBPrint (L" 0x00000000FFFFFFFF 0xFFFFFFFF00000000 EfiMain\n");
123 for (Index = (INTN)(DebuggerPrivate->CallStackEntryCount - 1); Index >= 0; Index--) {
124 //
125 // Get CallStack and print
126 //
127 CallStackEntry = &DebuggerPrivate->CallStackEntry[Index];
128 EDBPrint (
129 L" 0x%016lx 0x%016lx",
130 CallStackEntry->SourceAddress,
131 CallStackEntry->DestAddress
132 );
133 FuncName = FindSymbolStr ((UINTN)CallStackEntry->DestAddress);
134 if (FuncName != NULL) {
135 EDBPrint (L" %a()", FuncName);
136 }
137
138 EDBPrint (L"\n");
139
140 if (ShowParameter) {
141 //
142 // Print parameter
143 //
144 if (sizeof (UINTN) == sizeof (UINT64)) {
145 EDBPrint (
146 L" Parameter Address (0x%016lx) (\n",
147 CallStackEntry->ParameterAddr
148 );
149 if (ParameterNumber == 0) {
150 EDBPrint (L" )\n");
151 continue;
152 }
153
154 //
155 // Print each parameter
156 //
157 for (SubIndex = 0; SubIndex < ParameterNumber - 1; SubIndex++) {
158 if (SubIndex % 2 == 0) {
159 EDBPrint (L" ");
160 }
161
162 EDBPrint (
163 L"0x%016lx, ",
164 CallStackEntry->Parameter[SubIndex]
165 );
166 if (SubIndex % 2 == 1) {
167 EDBPrint (L"\n");
168 }
169 }
170
171 if (SubIndex % 2 == 0) {
172 EDBPrint (L" ");
173 }
174
175 EDBPrint (
176 L"0x%016lx\n",
177 CallStackEntry->Parameter[SubIndex]
178 );
179 EDBPrint (L" )\n");
180 //
181 // break only for parameter
182 //
183 if ((((DebuggerPrivate->CallStackEntryCount - Index) % (16 / ParameterNumber)) == 0) &&
184 (Index != 0))
185 {
186 if (SetPageBreak ()) {
187 break;
188 }
189 }
190 } else {
191 EDBPrint (
192 L" Parameter Address (0x%08x) (\n",
193 CallStackEntry->ParameterAddr
194 );
195 if (ParameterNumber == 0) {
196 EDBPrint (L" )\n");
197 continue;
198 }
199
200 //
201 // Print each parameter
202 //
203 for (SubIndex = 0; SubIndex < ParameterNumber - 1; SubIndex++) {
204 if (SubIndex % 4 == 0) {
205 EDBPrint (L" ");
206 }
207
208 EDBPrint (
209 L"0x%08x, ",
210 CallStackEntry->Parameter[SubIndex]
211 );
212 if (SubIndex % 4 == 3) {
213 EDBPrint (L"\n");
214 }
215 }
216
217 if (SubIndex % 4 == 0) {
218 EDBPrint (L" ");
219 }
220
221 EDBPrint (
222 L"0x%08x\n",
223 CallStackEntry->Parameter[SubIndex]
224 );
225 EDBPrint (L" )\n");
226 //
227 // break only for parameter
228 //
229 if ((((DebuggerPrivate->CallStackEntryCount - Index) % (32 / ParameterNumber)) == 0) &&
230 (Index != 0))
231 {
232 if (SetPageBreak ()) {
233 break;
234 }
235 }
236 }
237 }
238 }
239
240 //
241 // Done
242 //
243 return EFI_DEBUG_CONTINUE;
244}
245
258EFI_DEBUG_STATUS
260 IN CHAR16 *CommandArg,
261 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
262 IN EFI_EXCEPTION_TYPE ExceptionType,
263 IN OUT EFI_SYSTEM_CONTEXT SystemContext
264 )
265{
266 UINTN Index;
267
268 //
269 // Check argument
270 //
271 if (CommandArg != NULL) {
272 if (StriCmp (CommandArg, L"c") == 0) {
273 //
274 // Clear Trace
275 //
276 DebuggerPrivate->TraceEntryCount = 0;
277 ZeroMem (DebuggerPrivate->TraceEntry, sizeof (DebuggerPrivate->TraceEntry));
278 EDBPrint (L"Instruction Trace is cleared\n");
279 } else {
280 EDBPrint (L"Trace argument Invalid\n");
281 }
282
283 return EFI_DEBUG_CONTINUE;
284 }
285
286 //
287 // Check Trace Entry Count
288 //
289 if (DebuggerPrivate->TraceEntryCount == 0) {
290 EDBPrint (L"No Instruction Trace\n");
291 return EFI_DEBUG_CONTINUE;
292 } else if (DebuggerPrivate->TraceEntryCount > EFI_DEBUGGER_TRACE_MAX) {
293 EDBPrint (L"Instruction Trace Crash, re-initialize!\n");
294 DebuggerPrivate->TraceEntryCount = 0;
295 return EFI_DEBUG_CONTINUE;
296 }
297
298 //
299 // Go through each Trace entry and print
300 //
301 EDBPrint (L"Instruction Trace (->Latest):\n");
302 EDBPrint (L" Source Addr Destination Addr Type\n");
303 EDBPrint (L" ================== ================== ========\n");
304 // EDBPrint (L" 0x00000000FFFFFFFF 0xFFFFFFFF00000000 (CALLEX)\n");
305 for (Index = 0; Index < DebuggerPrivate->TraceEntryCount; Index++) {
306 EDBPrint (
307 L" 0x%016lx 0x%016lx %s\n",
308 DebuggerPrivate->TraceEntry[Index].SourceAddress,
309 DebuggerPrivate->TraceEntry[Index].DestAddress,
310 EdbBranchTypeToStr (DebuggerPrivate->TraceEntry[Index].Type)
311 );
312 }
313
314 //
315 // Done
316 //
317 return EFI_DEBUG_CONTINUE;
318}
UINT64 UINTN
INT64 INTN
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_DEBUG_STATUS DebuggerInstructionBranch(IN CHAR16 *CommandArg, IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
Definition: EdbCmdBranch.c:259
CHAR16 * EdbBranchTypeToStr(IN EFI_DEBUGGER_BRANCH_TYPE Type)
Definition: EdbCmdBranch.c:29
EFI_DEBUG_STATUS DebuggerCallStack(IN CHAR16 *CommandArg, IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
Definition: EdbCmdBranch.c:53
BOOLEAN EFIAPI SetPageBreak(VOID)
Definition: EdbSupportUI.c:605
CHAR16 *EFIAPI StrGetNextTokenLine(IN CHAR16 *CharSet)
UINTN EFIAPI Atoi(CHAR16 *Str)
UINTN EFIAPI EDBPrint(IN CONST CHAR16 *Format,...)
Definition: EdbSupportUI.c:683
INTN EFIAPI StriCmp(IN CHAR16 *String, IN CHAR16 *String2)
CHAR8 * FindSymbolStr(IN UINTN Address)
Definition: EdbSymbol.c:1733
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
INTN EFI_EXCEPTION_TYPE
Definition: DebugSupport.h:35