Coverage Report

Created: 2024-10-17 06:29

/src/hbfa-fl/HBFA/UefiHostTestPkg/Library/DebugLibHost/DebugLibHost.c
Line
Count
Source (jump to first uncovered line)
1
/** @file
2
3
Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
4
SPDX-License-Identifier: BSD-2-Clause-Patent
5
6
**/
7
8
#include <stdio.h>
9
#include <stdlib.h>
10
#include <string.h>
11
#include <assert.h>
12
#include <stdarg.h>
13
14
#include <Uefi.h>
15
#include <Library/BaseLib.h>
16
#include <Library/PrintLib.h>
17
18
#ifndef HOST_DEBUG_MESSAGE
19
#define HOST_DEBUG_MESSAGE 0
20
#endif
21
22
//
23
// Define the maximum debug and assert message length that this library supports
24
//
25
#define MAX_DEBUG_MESSAGE_LENGTH  0x100
26
27
VOID
28
EFIAPI
29
DebugAssert (
30
  IN CONST CHAR8  *FileName,
31
  IN UINTN        LineNumber,
32
  IN CONST CHAR8  *Description
33
  )
34
0
{
35
0
#ifndef TEST_WITH_KLEE
36
0
  printf ("ASSERT: %s(%d): %s\n", FileName, (INT32)(UINT32)LineNumber, Description);
37
0
  CpuBreakpoint ();
38
0
#endif
39
0
}
40
41
BOOLEAN
42
EFIAPI
43
DebugAssertEnabled (
44
  VOID
45
  )
46
310k
{
47
310k
  return TRUE;
48
310k
}
49
50
VOID
51
PatchFormat (
52
  IN  CONST CHAR8  *Format,
53
  IN        CHAR8  *MyFormat
54
  )
55
0
{
56
0
  UINTN  Index;
57
0
  UINTN  MyIndex;
58
59
0
  Index = 0;
60
0
  MyIndex = 0;
61
0
  while (Format[Index] != 0) {
62
0
    MyFormat[MyIndex] = Format[Index];
63
0
    if (Format[Index] == '%') {
64
0
      Index++;
65
0
      MyIndex++;
66
0
      switch (Format[Index]) {
67
0
      case 'a':
68
0
        MyFormat[MyIndex] = 's';
69
0
        break;
70
0
      case 's':
71
0
        MyFormat[MyIndex] = 'w';
72
0
        MyIndex++;
73
0
        MyFormat[MyIndex] = 's';
74
0
        break;
75
0
      case 'g':
76
0
      case 't':
77
0
        MyFormat[MyIndex] = 'p';
78
0
        break;
79
0
      case 'r':
80
0
        MyFormat[MyIndex] = 'x';
81
0
        break;
82
0
      case 'L':
83
0
      case 'l':
84
0
        MyFormat[MyIndex] = 'I';
85
0
        MyIndex++;
86
0
        MyFormat[MyIndex] = '6';
87
0
        MyIndex++;
88
0
        MyFormat[MyIndex] = '4';
89
0
        break;
90
0
      case '0':
91
0
        MyFormat[MyIndex] = Format[Index];
92
0
        if (Format[Index + 1] == '1') {
93
0
          Index++;
94
0
          MyIndex++;
95
0
          MyFormat[MyIndex] = Format[Index];
96
0
        }
97
0
      case '1':
98
0
        MyFormat[MyIndex] = Format[Index];
99
0
        if (Format[Index + 1] == '6') {
100
0
          Index++;
101
0
          MyIndex++;
102
0
          MyFormat[MyIndex] = Format[Index];
103
0
        }
104
0
        if (Format[Index + 1] == 'l') {
105
0
          Index++;
106
0
          MyIndex++;
107
0
          MyFormat[MyIndex] = 'I';
108
0
          MyIndex++;
109
0
          MyFormat[MyIndex] = '6';
110
0
          MyIndex++;
111
0
          MyFormat[MyIndex] = '4';
112
0
        }
113
0
        if (Format[Index + 1] == 'l') {
114
0
          Index++;
115
0
        }
116
0
        break;
117
0
      default:
118
0
        MyFormat[MyIndex] = Format[Index];
119
0
        break;
120
0
      }
121
0
    }
122
0
    Index++;
123
0
    MyIndex++;
124
0
  }
125
0
  MyFormat[MyIndex] = 0;
126
0
}
127
128
VOID
129
EFIAPI
130
DebugPrint (
131
  IN  UINTN        ErrorLevel,
132
  IN  CONST CHAR8  *Format,
133
  ...
134
  )
135
4.62M
{
136
4.62M
#ifndef TEST_WITH_KLEE
137
#if HOST_DEBUG_MESSAGE
138
  CHAR8    Buffer[MAX_DEBUG_MESSAGE_LENGTH];
139
  CHAR8    MyFormat[MAX_DEBUG_MESSAGE_LENGTH];
140
  VA_LIST  Marker;
141
142
  VA_START (Marker, Format);
143
144
  if (0) {
145
    PatchFormat (Format, MyFormat);
146
    vsprintf (Buffer, MyFormat, Marker);
147
  } else {
148
    AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);
149
  }
150
  VA_END (Marker);
151
152
  printf ("%s", Buffer);
153
#endif
154
4.62M
#endif
155
4.62M
}
156
157
BOOLEAN
158
EFIAPI
159
DebugPrintEnabled (
160
  VOID
161
  )
162
4.62M
{
163
4.62M
  return TRUE;
164
4.62M
}
165
166
BOOLEAN
167
EFIAPI
168
DebugPrintLevelEnabled (
169
  IN  CONST UINTN        ErrorLevel
170
  )
171
4.62M
{
172
4.62M
  return TRUE;
173
4.62M
}
174
175
BOOLEAN
176
EFIAPI
177
DebugCodeEnabled (
178
  VOID
179
  )
180
474
{
181
474
  return TRUE;
182
474
}