Skip to content

Commit 173367b

Browse files
authored
UefiExt: Minor fixes and improvements (#7)
Fixes advlog command for rust and moves a few monitor based command to re-use the monitor command
1 parent 7c5da3f commit 173367b

File tree

4 files changed

+48
-87
lines changed

4 files changed

+48
-87
lines changed

UefiDbgExt/memory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ advlog (
322322
goto Exit;
323323
}
324324
} else if (gUefiEnv == RUST) {
325-
InfoAddress = GetExpression ("adv_logger::logger::DBG_ADV_LOG_BUFFER");
325+
InfoAddress = GetExpression ("patina_adv_logger::logger::DBG_ADV_LOG_BUFFER");
326326
if (InfoAddress == NULL) {
327-
dprintf ("Failed to find adv_logger::logger::DBG_ADV_LOG_BUFFER!\n");
327+
dprintf ("Failed to find patina_adv_logger::logger::DBG_ADV_LOG_BUFFER!\n");
328328
Result = ERROR_NOT_FOUND;
329329
goto Exit;
330330
}

UefiDbgExt/swdebug.cpp

Lines changed: 46 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,67 @@ Module Name:
1717
#include "uefiext.h"
1818

1919
HRESULT CALLBACK
20-
info (
20+
monitor (
2121
PDEBUG_CLIENT4 Client,
2222
PCSTR args
2323
)
2424
{
25+
PSTR Response;
26+
ULONG Len;
27+
const CHAR *TruncateTag = "#T#";
28+
const ULONG TruncateTagLen = sizeof ("#T#") - 1; // Exclude the null terminator.
29+
ULONG Offset;
30+
2531
INIT_API ();
2632

27-
g_ExtControl->Execute (
28-
DEBUG_OUTCTL_ALL_CLIENTS,
29-
".exdicmd target:0:?",
30-
DEBUG_EXECUTE_DEFAULT
31-
);
33+
Offset = 0;
34+
35+
// Loop on the command until the entire response is received.
36+
while (TRUE) {
37+
Response = MonitorCommandWithOutput (Client, args, Offset);
38+
39+
// Strip of the trailing newline character if it exists since this in injected
40+
// by windbg and is not part of the response.
41+
Len = (ULONG)strlen (Response);
42+
if ((Len > 0) && (Response[Len - 1] == '\n')) {
43+
Len--;
44+
}
45+
46+
if (Len > TruncateTagLen) {
47+
if (strncmp (Response + Len - TruncateTagLen, TruncateTag, TruncateTagLen) == 0) {
48+
// The response was truncated, so we need to read more.
49+
Response[Len - TruncateTagLen] = 0; // Remove the truncate tag.
50+
dprintf ("%s", Response);
51+
Offset += Len - TruncateTagLen;
52+
continue;
53+
}
54+
}
55+
56+
break;
57+
}
58+
59+
dprintf ("%s\n", Response);
3260

3361
EXIT_API ();
3462
return S_OK;
3563
}
3664

3765
HRESULT CALLBACK
38-
modulebreak (
66+
info (
3967
PDEBUG_CLIENT4 Client,
4068
PCSTR args
4169
)
4270
{
43-
CHAR Command[512];
44-
4571
INIT_API ();
4672

47-
if (RUST == gUefiEnv) {
48-
sprintf_s (Command, sizeof (Command), ".exdicmd target:0:mod break %s", args);
49-
} else {
50-
sprintf_s (Command, sizeof (Command), ".exdicmd target:0:b%s", args);
51-
}
52-
53-
g_ExtControl->Execute (
54-
DEBUG_OUTCTL_ALL_CLIENTS,
55-
Command,
56-
DEBUG_EXECUTE_DEFAULT
57-
);
73+
monitor (Client, "?");
5874

5975
EXIT_API ();
6076
return S_OK;
6177
}
6278

6379
HRESULT CALLBACK
64-
readmsr (
80+
modulebreak (
6581
PDEBUG_CLIENT4 Client,
6682
PCSTR args
6783
)
@@ -70,23 +86,20 @@ readmsr (
7086

7187
INIT_API ();
7288

73-
if (strlen (args) == 0) {
74-
dprintf ("Must provide MSR index in HEX!");
89+
if (RUST == gUefiEnv) {
90+
sprintf_s (Command, sizeof (Command), "mod break %s", args);
91+
} else {
92+
sprintf_s (Command, sizeof (Command), "b%s", args);
7593
}
7694

77-
sprintf_s (Command, sizeof (Command), ".exdicmd target:0:m%s", args);
78-
g_ExtControl->Execute (
79-
DEBUG_OUTCTL_ALL_CLIENTS,
80-
Command,
81-
DEBUG_EXECUTE_DEFAULT
82-
);
95+
monitor (Client, Command);
8396

8497
EXIT_API ();
8598
return S_OK;
8699
}
87100

88101
HRESULT CALLBACK
89-
readvar (
102+
readmsr (
90103
PDEBUG_CLIENT4 Client,
91104
PCSTR args
92105
)
@@ -96,15 +109,11 @@ readvar (
96109
INIT_API ();
97110

98111
if (strlen (args) == 0) {
99-
dprintf ("Must provide variable name!");
112+
dprintf ("Must provide MSR index in HEX! E.g. 0x1234\n");
100113
}
101114

102-
sprintf_s (Command, sizeof (Command), ".exdicmd target:0:v%s", args);
103-
g_ExtControl->Execute (
104-
DEBUG_OUTCTL_ALL_CLIENTS,
105-
Command,
106-
DEBUG_EXECUTE_DEFAULT
107-
);
115+
sprintf_s (Command, sizeof (Command), "m%s", args);
116+
monitor (Client, Command);
108117

109118
EXIT_API ();
110119
return S_OK;
@@ -143,49 +152,3 @@ reboot (
143152
EXIT_API ();
144153
return S_OK;
145154
}
146-
147-
HRESULT CALLBACK
148-
monitor (
149-
PDEBUG_CLIENT4 Client,
150-
PCSTR args
151-
)
152-
{
153-
PSTR Response;
154-
ULONG Len;
155-
const CHAR *TruncateTag = "#T#";
156-
const ULONG TruncateTagLen = sizeof ("#T#") - 1; // Exclude the null terminator.
157-
ULONG Offset;
158-
159-
INIT_API ();
160-
161-
Offset = 0;
162-
163-
// Loop on the command until the entire response is received.
164-
while (TRUE) {
165-
Response = MonitorCommandWithOutput (Client, args, Offset);
166-
167-
// Strip of the trailing newline character if it exists since this in injected
168-
// by windbg and is not part of the response.
169-
Len = (ULONG)strlen (Response);
170-
if ((Len > 0) && (Response[Len - 1] == '\n')) {
171-
Len--;
172-
}
173-
174-
if (Len > TruncateTagLen) {
175-
if (strncmp (Response + Len - TruncateTagLen, TruncateTag, TruncateTagLen) == 0) {
176-
// The response was truncated, so we need to read more.
177-
Response[Len - TruncateTagLen] = 0; // Remove the truncate tag.
178-
dprintf ("%s", Response);
179-
Offset += Len - TruncateTagLen;
180-
continue;
181-
}
182-
}
183-
184-
break;
185-
}
186-
187-
dprintf ("%s\n", Response);
188-
189-
EXIT_API ();
190-
return S_OK;
191-
}

UefiDbgExt/uefiext.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ help (
169169
" monitor - Sends direct monitor commands\n"
170170
" modulebreak - Sets a break on load for the provided module. e.g. 'shell'\n"
171171
" readmsr - Reads a MSR value (x86 only)\n"
172-
" readvar - Reads a UEFI variable\n"
173172
" reboot - Reboots the system\n"
174173
);
175174

UefiDbgExt/uefiext.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ EXPORTS
2727
pt
2828
protocols
2929
readmsr
30-
readvar
3130
reboot
3231
setenv
3332

0 commit comments

Comments
 (0)