Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion DebuggerFeaturePkg/DebuggerFeaturePkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@
# { bf004bc2-da8c-4e44-b470-d69c286d712d }
DebuggerFeaturePkgTokenSpaceGuid = { 0xbf004bc2, 0xda8c, 0x4e44, {0xb4, 0x70, 0xd6, 0x9c, 0x28, 0x6d, 0x71, 0x2d }}

## Debugget Control Data Hob Guid
## Debugger Control Data Hob Guid
#
gDebuggerControlHobGuid = { 0x96ad286c, 0xac0f, 0x4ba1, {0x97, 0x34, 0x6c, 0x9f, 0x3c, 0xad, 0x90, 0x4c }}

## Debugger Variables
# { 9478feba-dfd5-4f7c-8ea2-fc51969e5416 }
gDebuggerVariableGuid = {0x9478feba, 0xdfd5, 0x4f7c, {0x8e, 0xa2, 0xfc, 0x51, 0x96, 0x9e, 0x54, 0x16}}

[PcdsFixedAtBuild]
## Controls the debug configuration flags.
# Bit 0 - Controls whether the debugger will break in on initialization.
Expand Down
53 changes: 53 additions & 0 deletions DebuggerFeaturePkg/Library/DebugAgent/DebugAgentDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <Library/BaseMemoryLib.h>
#include <Library/DebugAgentLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/PeCoffGetEntryPointLib.h>
#include <Library/CpuExceptionHandlerLib.h>
Expand Down Expand Up @@ -62,6 +63,7 @@ STATIC EFI_EVENT mTimerEvent;
STATIC EFI_EVENT mCpuArchEvent;
STATIC EFI_EVENT mLoadedImageEvent;
STATIC EFI_EVENT mExitBootServicesEvent;
STATIC EFI_EVENT mEndOfDxeEvent;
STATIC BOOLEAN mDebuggerInitialized;
STATIC BOOLEAN mDisablePolling;
STATIC CHAR8 mDbgBreakOnModuleLoadString[64] = { 0 };
Expand Down Expand Up @@ -153,6 +155,40 @@ OnExitBootServices (
return;
}

/**
This routine handles the END_OF_DXE notification, and terminates
the debugger

@param Event Not used.
@param Context Not used.

**/
VOID
EFIAPI
OnEndOfDxe (
EFI_EVENT Event,
VOID *Context
)
{
EFI_STATUS Status;
UINT8 Value;

Value = 1;
Status = gRT->SetVariable (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is might be a nit for the usecase:

Volatile variable that is Boot services access only, runs at end of dxe, before 3rd party code runs, and is un protected. Is it a problem that 3rd party code could change this value, and the boot loader wouldn't be aware of it anymore?

Is there a more standard way that presence of a debugger could be detected?

L"UefiDebuggerActive",
&gDebuggerVariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof (Value),
&Value
);

if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Failed to set UefiDebuggerActive variable. %r\n", __FUNCTION__, Status));
}

return;
}

/**
Cpu Arch Protocol notification.

Expand Down Expand Up @@ -660,6 +696,23 @@ DxeDebugSetupCallbacks (
DEBUG ((DEBUG_ERROR, "%a: failed to create Exit Boot Services callback\n", __FUNCTION__));
}

//
// Register for READY_TO_BOOT notification, to set a variable for OS loaders to check for debugger enablement.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You say RTB, but do EOD. I would have thought RTB would be the more natural place, right before we load a bootloader?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's somewhat arbitrary, and I have no strong preference. I can change to RTB.

//

Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
OnEndOfDxe,
NULL,
&gEfiEndOfDxeEventGroupGuid,
&mEndOfDxeEvent
);

if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to create End of Dxe callback\n", __FUNCTION__));
}

return EFI_SUCCESS;
}

Expand Down
2 changes: 2 additions & 0 deletions DebuggerFeaturePkg/Library/DebugAgent/DebugAgentDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@

[Guids]
gEfiEventExitBootServicesGuid
gEfiEndOfDxeEventGroupGuid
gDebuggerControlHobGuid
gDebuggerVariableGuid

[Pcd.common]
DebuggerFeaturePkgTokenSpaceGuid.PcdForceEnableDebugger ## CONSUMES
Expand Down