1 /******************************************************************************
3 * Module Name: utdebug - Debug print/trace routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2017, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define EXPORT_ACPI_INTERFACES
50 #define _COMPONENT ACPI_UTILITIES
51 ACPI_MODULE_NAME ("utdebug")
54 #ifdef ACPI_DEBUG_OUTPUT
56 static ACPI_THREAD_ID AcpiGbl_PreviousThreadId
= (ACPI_THREAD_ID
) 0xFFFFFFFF;
57 static const char *AcpiGbl_FunctionEntryPrefix
= "----Entry";
58 static const char *AcpiGbl_FunctionExitPrefix
= "----Exit-";
61 /*******************************************************************************
63 * FUNCTION: AcpiUtInitStackPtrTrace
69 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
71 ******************************************************************************/
74 AcpiUtInitStackPtrTrace (
80 AcpiGbl_EntryStackPointer
= &CurrentSp
;
84 /*******************************************************************************
86 * FUNCTION: AcpiUtTrackStackPtr
92 * DESCRIPTION: Save the current CPU stack pointer
94 ******************************************************************************/
103 if (&CurrentSp
< AcpiGbl_LowestStackPointer
)
105 AcpiGbl_LowestStackPointer
= &CurrentSp
;
108 if (AcpiGbl_NestingLevel
> AcpiGbl_DeepestNesting
)
110 AcpiGbl_DeepestNesting
= AcpiGbl_NestingLevel
;
115 /*******************************************************************************
117 * FUNCTION: AcpiUtTrimFunctionName
119 * PARAMETERS: FunctionName - Ascii string containing a procedure name
121 * RETURN: Updated pointer to the function name
123 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
124 * This allows compiler macros such as __FUNCTION__ to be used
125 * with no change to the debug output.
127 ******************************************************************************/
130 AcpiUtTrimFunctionName (
131 const char *FunctionName
)
134 /* All Function names are longer than 4 chars, check is safe */
136 if (*(ACPI_CAST_PTR (UINT32
, FunctionName
)) == ACPI_PREFIX_MIXED
)
138 /* This is the case where the original source has not been modified */
140 return (FunctionName
+ 4);
143 if (*(ACPI_CAST_PTR (UINT32
, FunctionName
)) == ACPI_PREFIX_LOWER
)
145 /* This is the case where the source has been 'linuxized' */
147 return (FunctionName
+ 5);
150 return (FunctionName
);
154 /*******************************************************************************
156 * FUNCTION: AcpiDebugPrint
158 * PARAMETERS: RequestedDebugLevel - Requested debug print level
159 * LineNumber - Caller's line number (for error output)
160 * FunctionName - Caller's procedure name
161 * ModuleName - Caller's module name
162 * ComponentId - Caller's component ID
163 * Format - Printf format field
164 * ... - Optional printf arguments
168 * DESCRIPTION: Print error message with prefix consisting of the module name,
169 * line number, and component ID.
171 ******************************************************************************/
173 void ACPI_INTERNAL_VAR_XFACE
175 UINT32 RequestedDebugLevel
,
177 const char *FunctionName
,
178 const char *ModuleName
,
183 ACPI_THREAD_ID ThreadId
;
185 #ifdef ACPI_APPLICATION
189 /* Check if debug output enabled */
191 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel
, ComponentId
))
197 * Thread tracking and context switch notification
199 ThreadId
= AcpiOsGetThreadId ();
200 if (ThreadId
!= AcpiGbl_PreviousThreadId
)
202 if (ACPI_LV_THREADS
& AcpiDbgLevel
)
205 "\n**** Context Switch from TID %u to TID %u ****\n\n",
206 (UINT32
) AcpiGbl_PreviousThreadId
, (UINT32
) ThreadId
);
209 AcpiGbl_PreviousThreadId
= ThreadId
;
210 AcpiGbl_NestingLevel
= 0;
214 * Display the module name, current line number, thread ID (if requested),
215 * current procedure nesting level, and the current procedure name
217 AcpiOsPrintf ("%9s-%04ld ", ModuleName
, LineNumber
);
219 #ifdef ACPI_APPLICATION
221 * For AcpiExec/iASL only, emit the thread ID and nesting level.
222 * Note: nesting level is really only useful during a single-thread
223 * execution. Otherwise, multiple threads will keep resetting the
226 if (ACPI_LV_THREADS
& AcpiDbgLevel
)
228 AcpiOsPrintf ("[%u] ", (UINT32
) ThreadId
);
231 FillCount
= 48 - AcpiGbl_NestingLevel
-
232 strlen (AcpiUtTrimFunctionName (FunctionName
));
238 AcpiOsPrintf ("[%02ld] %*s",
239 AcpiGbl_NestingLevel
, AcpiGbl_NestingLevel
+ 1, " ");
240 AcpiOsPrintf ("%s%*s: ",
241 AcpiUtTrimFunctionName (FunctionName
), FillCount
, " ");
244 AcpiOsPrintf ("%-22.22s: ", AcpiUtTrimFunctionName (FunctionName
));
247 va_start (args
, Format
);
248 AcpiOsVprintf (Format
, args
);
252 ACPI_EXPORT_SYMBOL (AcpiDebugPrint
)
255 /*******************************************************************************
257 * FUNCTION: AcpiDebugPrintRaw
259 * PARAMETERS: RequestedDebugLevel - Requested debug print level
260 * LineNumber - Caller's line number
261 * FunctionName - Caller's procedure name
262 * ModuleName - Caller's module name
263 * ComponentId - Caller's component ID
264 * Format - Printf format field
265 * ... - Optional printf arguments
269 * DESCRIPTION: Print message with no headers. Has same interface as
270 * DebugPrint so that the same macros can be used.
272 ******************************************************************************/
274 void ACPI_INTERNAL_VAR_XFACE
276 UINT32 RequestedDebugLevel
,
278 const char *FunctionName
,
279 const char *ModuleName
,
287 /* Check if debug output enabled */
289 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel
, ComponentId
))
294 va_start (args
, Format
);
295 AcpiOsVprintf (Format
, args
);
299 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw
)
302 /*******************************************************************************
304 * FUNCTION: AcpiUtTrace
306 * PARAMETERS: LineNumber - Caller's line number
307 * FunctionName - Caller's procedure name
308 * ModuleName - Caller's module name
309 * ComponentId - Caller's component ID
313 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
316 ******************************************************************************/
321 const char *FunctionName
,
322 const char *ModuleName
,
326 AcpiGbl_NestingLevel
++;
327 AcpiUtTrackStackPtr ();
329 /* Check if enabled up-front for performance */
331 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
333 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
334 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
335 "%s\n", AcpiGbl_FunctionEntryPrefix
);
339 ACPI_EXPORT_SYMBOL (AcpiUtTrace
)
342 /*******************************************************************************
344 * FUNCTION: AcpiUtTracePtr
346 * PARAMETERS: LineNumber - Caller's line number
347 * FunctionName - Caller's procedure name
348 * ModuleName - Caller's module name
349 * ComponentId - Caller's component ID
350 * Pointer - Pointer to display
354 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
357 ******************************************************************************/
362 const char *FunctionName
,
363 const char *ModuleName
,
368 AcpiGbl_NestingLevel
++;
369 AcpiUtTrackStackPtr ();
371 /* Check if enabled up-front for performance */
373 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
375 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
376 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
377 "%s %p\n", AcpiGbl_FunctionEntryPrefix
, Pointer
);
382 /*******************************************************************************
384 * FUNCTION: AcpiUtTraceStr
386 * PARAMETERS: LineNumber - Caller's line number
387 * FunctionName - Caller's procedure name
388 * ModuleName - Caller's module name
389 * ComponentId - Caller's component ID
390 * String - Additional string to display
394 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
397 ******************************************************************************/
402 const char *FunctionName
,
403 const char *ModuleName
,
408 AcpiGbl_NestingLevel
++;
409 AcpiUtTrackStackPtr ();
411 /* Check if enabled up-front for performance */
413 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
415 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
416 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
417 "%s %s\n", AcpiGbl_FunctionEntryPrefix
, String
);
422 /*******************************************************************************
424 * FUNCTION: AcpiUtTraceU32
426 * PARAMETERS: LineNumber - Caller's line number
427 * FunctionName - Caller's procedure name
428 * ModuleName - Caller's module name
429 * ComponentId - Caller's component ID
430 * Integer - Integer to display
434 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
437 ******************************************************************************/
442 const char *FunctionName
,
443 const char *ModuleName
,
448 AcpiGbl_NestingLevel
++;
449 AcpiUtTrackStackPtr ();
451 /* Check if enabled up-front for performance */
453 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
455 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
456 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
457 "%s %08X\n", AcpiGbl_FunctionEntryPrefix
, Integer
);
462 /*******************************************************************************
464 * FUNCTION: AcpiUtExit
466 * PARAMETERS: LineNumber - Caller's line number
467 * FunctionName - Caller's procedure name
468 * ModuleName - Caller's module name
469 * ComponentId - Caller's component ID
473 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
476 ******************************************************************************/
481 const char *FunctionName
,
482 const char *ModuleName
,
486 /* Check if enabled up-front for performance */
488 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
490 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
491 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
492 "%s\n", AcpiGbl_FunctionExitPrefix
);
495 if (AcpiGbl_NestingLevel
)
497 AcpiGbl_NestingLevel
--;
501 ACPI_EXPORT_SYMBOL (AcpiUtExit
)
504 /*******************************************************************************
506 * FUNCTION: AcpiUtStatusExit
508 * PARAMETERS: LineNumber - Caller's line number
509 * FunctionName - Caller's procedure name
510 * ModuleName - Caller's module name
511 * ComponentId - Caller's component ID
512 * Status - Exit status code
516 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
517 * set in DebugLevel. Prints exit status also.
519 ******************************************************************************/
524 const char *FunctionName
,
525 const char *ModuleName
,
530 /* Check if enabled up-front for performance */
532 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
534 if (ACPI_SUCCESS (Status
))
536 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
537 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
538 "%s %s\n", AcpiGbl_FunctionExitPrefix
,
539 AcpiFormatException (Status
));
543 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
544 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
545 "%s ****Exception****: %s\n", AcpiGbl_FunctionExitPrefix
,
546 AcpiFormatException (Status
));
550 if (AcpiGbl_NestingLevel
)
552 AcpiGbl_NestingLevel
--;
556 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit
)
559 /*******************************************************************************
561 * FUNCTION: AcpiUtValueExit
563 * PARAMETERS: LineNumber - Caller's line number
564 * FunctionName - Caller's procedure name
565 * ModuleName - Caller's module name
566 * ComponentId - Caller's component ID
567 * Value - Value to be printed with exit msg
571 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
572 * set in DebugLevel. Prints exit value also.
574 ******************************************************************************/
579 const char *FunctionName
,
580 const char *ModuleName
,
585 /* Check if enabled up-front for performance */
587 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
589 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
590 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
591 "%s %8.8X%8.8X\n", AcpiGbl_FunctionExitPrefix
,
592 ACPI_FORMAT_UINT64 (Value
));
595 if (AcpiGbl_NestingLevel
)
597 AcpiGbl_NestingLevel
--;
601 ACPI_EXPORT_SYMBOL (AcpiUtValueExit
)
604 /*******************************************************************************
606 * FUNCTION: AcpiUtPtrExit
608 * PARAMETERS: LineNumber - Caller's line number
609 * FunctionName - Caller's procedure name
610 * ModuleName - Caller's module name
611 * ComponentId - Caller's component ID
612 * Ptr - Pointer to display
616 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
617 * set in DebugLevel. Prints exit value also.
619 ******************************************************************************/
624 const char *FunctionName
,
625 const char *ModuleName
,
630 /* Check if enabled up-front for performance */
632 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
634 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
635 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
636 "%s %p\n", AcpiGbl_FunctionExitPrefix
, Ptr
);
639 if (AcpiGbl_NestingLevel
)
641 AcpiGbl_NestingLevel
--;
646 /*******************************************************************************
648 * FUNCTION: AcpiUtStrExit
650 * PARAMETERS: LineNumber - Caller's line number
651 * FunctionName - Caller's procedure name
652 * ModuleName - Caller's module name
653 * ComponentId - Caller's component ID
654 * String - String to display
658 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
659 * set in DebugLevel. Prints exit value also.
661 ******************************************************************************/
666 const char *FunctionName
,
667 const char *ModuleName
,
672 /* Check if enabled up-front for performance */
674 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
676 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
677 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
678 "%s %s\n", AcpiGbl_FunctionExitPrefix
, String
);
681 if (AcpiGbl_NestingLevel
)
683 AcpiGbl_NestingLevel
--;
688 /*******************************************************************************
690 * FUNCTION: AcpiTracePoint
692 * PARAMETERS: Type - Trace event type
693 * Begin - TRUE if before execution
694 * Aml - Executed AML address
695 * Pathname - Object path
696 * Pointer - Pointer to the related object
700 * DESCRIPTION: Interpreter execution trace.
702 ******************************************************************************/
706 ACPI_TRACE_EVENT_TYPE Type
,
712 ACPI_FUNCTION_ENTRY ();
714 AcpiExTracePoint (Type
, Begin
, Aml
, Pathname
);
716 #ifdef ACPI_USE_SYSTEM_TRACER
717 AcpiOsTracePoint (Type
, Begin
, Aml
, Pathname
);
721 ACPI_EXPORT_SYMBOL (AcpiTracePoint
)