From c2f632b6a187df15c759835d5048dcbef74848a4 Mon Sep 17 00:00:00 2001 From: Chris Fernald Date: Thu, 16 Nov 2023 15:10:54 -0800 Subject: [PATCH 1/2] MdeModulePkg DxeMain: Add late initialization for Debug Agent. Add a late initialize in DxeMain for the debug agent. This is required for the debug agent to be able to setup events to handle image loads, exit boot services, and other important callbacks. Define a reinitialize debug agent. Signed-off-by: Aaron Pop --- MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 5 +++++ MdeModulePkg/Include/Library/DebugAgentLib.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c index 8a877330dd73..4274414d0825 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c +++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c @@ -461,6 +461,11 @@ DxeMain ( Status = CoreInitializeEventServices (); ASSERT_EFI_ERROR (Status); + // + // Give the debug agent a chance to initialize with events. + // + InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_CORE_LATE, HobStart, NULL); + MemoryProfileInstallProtocol (); CoreInitializeMemoryAttributesTable (); diff --git a/MdeModulePkg/Include/Library/DebugAgentLib.h b/MdeModulePkg/Include/Library/DebugAgentLib.h index f44bc5c5635c..c74254ebb771 100644 --- a/MdeModulePkg/Include/Library/DebugAgentLib.h +++ b/MdeModulePkg/Include/Library/DebugAgentLib.h @@ -21,6 +21,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define DEBUG_AGENT_INIT_DXE_LOAD 10 #define DEBUG_AGENT_INIT_DXE_UNLOAD 11 #define DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64 12 +#define DEBUG_AGENT_INIT_REINITIALIZE 13 +#define DEBUG_AGENT_INIT_DXE_CORE_LATE 14 // // Context for DEBUG_AGENT_INIT_POSTMEM_SEC From ca337d4cc2eb16b773e71c96561e84f18b1edfb3 Mon Sep 17 00:00:00 2001 From: Aaron Pop Date: Fri, 6 Sep 2024 16:39:32 -0700 Subject: [PATCH 2/2] SourceLevelDebugPkg DxeDebugAgent: Handle additional initialize cases. Handle both DEBUG_AGENT_INIT_REINITIALIZE and DEBUG_AGENT_INIT_DXE_CORE_LATE InitFlags to prevent an assert. No additional initlization takes place for these cases. Signed-off-by: Aaron Pop --- .../Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c index a41bba2c4ba9..fcb1b631c1ed 100644 --- a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c +++ b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c @@ -2,6 +2,7 @@ Debug Agent library implementation for Dxe Core and Dxr modules. Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -537,6 +538,11 @@ InitializeDebugAgent ( break; + case DEBUG_AGENT_INIT_REINITIALIZE: + case DEBUG_AGENT_INIT_DXE_CORE_LATE: + + break; + default: // // Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this