3 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 CHAR16
*mBranchTypeStr
[] = {
27 Comvert Branch Type to string.
29 @param Type Branch Type
31 @retval String string of Branch Type.
36 IN EFI_DEBUGGER_BRANCH_TYPE Type
39 if (Type
< 0 || Type
>= EfiDebuggerBranchTypeEbcMax
) {
40 return L
"(Unknown Type)";
43 return mBranchTypeStr
[Type
];
48 DebuggerCommand - CallStack.
50 @param CommandArg The argument for this command
51 @param DebuggerPrivate EBC Debugger private data structure
52 @param ExceptionType Exception type.
53 @param SystemContext EBC system context.
55 @retval EFI_DEBUG_CONTINUE formal return value
60 IN CHAR16
*CommandArg
,
61 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
62 IN EFI_EXCEPTION_TYPE ExceptionType
,
63 IN OUT EFI_SYSTEM_CONTEXT SystemContext
69 EFI_DEBUGGER_CALLSTACK_CONTEXT
*CallStackEntry
;
70 BOOLEAN ShowParameter
;
71 UINTN ParameterNumber
;
73 ShowParameter
= FALSE
;
74 ParameterNumber
= EFI_DEBUGGER_CALL_DEFAULT_PARAMETER
;
79 if (CommandArg
!= NULL
) {
80 if (StriCmp (CommandArg
, L
"c") == 0) {
84 DebuggerPrivate
->CallStackEntryCount
= 0;
85 ZeroMem (DebuggerPrivate
->CallStackEntry
, sizeof(DebuggerPrivate
->CallStackEntry
));
86 EDBPrint (L
"Call-Stack is cleared\n");
87 return EFI_DEBUG_CONTINUE
;
88 } else if (StriCmp (CommandArg
, L
"p") == 0) {
90 // Print Call-Stack with parameter
93 CommandArg
= StrGetNextTokenLine (L
" ");
94 if (CommandArg
!= NULL
) {
96 // Try to get the parameter number
98 ParameterNumber
= Atoi (CommandArg
);
99 if (ParameterNumber
> 16) {
100 EDBPrint (L
"Call-Stack argument Invalid\n");
101 return EFI_DEBUG_CONTINUE
;
105 EDBPrint (L
"Call-Stack argument Invalid\n");
106 return EFI_DEBUG_CONTINUE
;
111 // Check CallStack Entry Count
113 if (DebuggerPrivate
->CallStackEntryCount
== 0) {
114 EDBPrint (L
"No Call-Stack\n");
115 return EFI_DEBUG_CONTINUE
;
116 } else if (DebuggerPrivate
->CallStackEntryCount
> EFI_DEBUGGER_CALLSTACK_MAX
) {
117 EDBPrint (L
"Call-Stack Crash, re-initialize!\n");
118 DebuggerPrivate
->CallStackEntryCount
= 0;
119 return EFI_DEBUG_CONTINUE
;
123 // Go through each CallStack entry and print
125 EDBPrint (L
"Call-Stack (TOP):\n");
126 EDBPrint (L
" Caller Callee Name\n");
127 EDBPrint (L
" ================== ================== ========\n");
128 //EDBPrint (L" 0x00000000FFFFFFFF 0xFFFFFFFF00000000 EfiMain\n");
129 for (Index
= (INTN
)(DebuggerPrivate
->CallStackEntryCount
- 1); Index
>= 0; Index
--) {
131 // Get CallStack and print
133 CallStackEntry
= &DebuggerPrivate
->CallStackEntry
[Index
];
135 L
" 0x%016lx 0x%016lx",
136 CallStackEntry
->SourceAddress
,
137 CallStackEntry
->DestAddress
139 FuncName
= FindSymbolStr ((UINTN
)CallStackEntry
->DestAddress
);
140 if (FuncName
!= NULL
) {
141 EDBPrint (L
" %a()", FuncName
);
149 if (sizeof(UINTN
) == sizeof(UINT64
)) {
151 L
" Parameter Address (0x%016lx) (\n",
152 CallStackEntry
->ParameterAddr
154 if (ParameterNumber
== 0) {
159 // Print each parameter
161 for (SubIndex
= 0; SubIndex
< ParameterNumber
- 1; SubIndex
++) {
162 if (SubIndex
% 2 == 0) {
167 CallStackEntry
->Parameter
[SubIndex
]
169 if (SubIndex
% 2 == 1) {
173 if (SubIndex
% 2 == 0) {
178 CallStackEntry
->Parameter
[SubIndex
]
182 // break only for parameter
184 if ((((DebuggerPrivate
->CallStackEntryCount
- Index
) % (16 / ParameterNumber
)) == 0) &&
186 if (SetPageBreak ()) {
192 L
" Parameter Address (0x%08x) (\n",
193 CallStackEntry
->ParameterAddr
195 if (ParameterNumber
== 0) {
200 // Print each parameter
202 for (SubIndex
= 0; SubIndex
< ParameterNumber
- 1; SubIndex
++) {
203 if (SubIndex
% 4 == 0) {
208 CallStackEntry
->Parameter
[SubIndex
]
210 if (SubIndex
% 4 == 3) {
214 if (SubIndex
% 4 == 0) {
219 CallStackEntry
->Parameter
[SubIndex
]
223 // break only for parameter
225 if ((((DebuggerPrivate
->CallStackEntryCount
- Index
) % (32 / ParameterNumber
)) == 0) &&
227 if (SetPageBreak ()) {
238 return EFI_DEBUG_CONTINUE
;
243 DebuggerCommand - InstructionBranch.
245 @param CommandArg The argument for this command
246 @param DebuggerPrivate EBC Debugger private data structure
247 @param ExceptionType Exception type.
248 @param SystemContext EBC system context.
250 @retval EFI_DEBUG_CONTINUE formal return value
254 DebuggerInstructionBranch (
255 IN CHAR16
*CommandArg
,
256 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
257 IN EFI_EXCEPTION_TYPE ExceptionType
,
258 IN OUT EFI_SYSTEM_CONTEXT SystemContext
266 if (CommandArg
!= NULL
) {
267 if (StriCmp (CommandArg
, L
"c") == 0) {
271 DebuggerPrivate
->TraceEntryCount
= 0;
272 ZeroMem (DebuggerPrivate
->TraceEntry
, sizeof(DebuggerPrivate
->TraceEntry
));
273 EDBPrint (L
"Instruction Trace is cleared\n");
275 EDBPrint (L
"Trace argument Invalid\n");
277 return EFI_DEBUG_CONTINUE
;
281 // Check Trace Entry Count
283 if (DebuggerPrivate
->TraceEntryCount
== 0) {
284 EDBPrint (L
"No Instruction Trace\n");
285 return EFI_DEBUG_CONTINUE
;
286 } else if (DebuggerPrivate
->TraceEntryCount
> EFI_DEBUGGER_TRACE_MAX
) {
287 EDBPrint (L
"Instruction Trace Crash, re-initialize!\n");
288 DebuggerPrivate
->TraceEntryCount
= 0;
289 return EFI_DEBUG_CONTINUE
;
293 // Go through each Trace entry and print
295 EDBPrint (L
"Instruction Trace (->Latest):\n");
296 EDBPrint (L
" Source Addr Destination Addr Type\n");
297 EDBPrint (L
" ================== ================== ========\n");
298 //EDBPrint (L" 0x00000000FFFFFFFF 0xFFFFFFFF00000000 (CALLEX)\n");
299 for (Index
= 0; Index
< DebuggerPrivate
->TraceEntryCount
; Index
++) {
301 L
" 0x%016lx 0x%016lx %s\n",
302 DebuggerPrivate
->TraceEntry
[Index
].SourceAddress
,
303 DebuggerPrivate
->TraceEntry
[Index
].DestAddress
,
304 EdbBranchTypeToStr (DebuggerPrivate
->TraceEntry
[Index
].Type
)
311 return EFI_DEBUG_CONTINUE
;