Skip to content

Commit

Permalink
Block debugger attach after any ApplyUpdate changes (#50200)
Browse files Browse the repository at this point in the history
* Block debugger attach after any ApplyUpdate changes

* Add better error message for ApplyUpdate while debugging

* Code review feedback

* Fix arm32/arm64 builds

* Code review feedback

* Code review feedback
  • Loading branch information
mikem8361 authored Mar 26, 2021
1 parent ec2fedc commit e503be0
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/coreclr/debug/daccess/dacdbiimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4253,6 +4253,16 @@ HRESULT DacDbiInterfaceImpl::IsModuleMapped(VMPTR_Module pModule, OUT BOOL *isMo
return hr;
}

bool DacDbiInterfaceImpl::MetadataUpdatesApplied()
{
DD_ENTER_MAY_THROW;
#ifdef EnC_SUPPORTED
return g_metadataUpdatesApplied;
#else
return false;
#endif
}

// Helper to intialize a TargetBuffer from a MemoryRange
//
// Arguments:
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/debug/daccess/dacdbiimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ class DacDbiInterfaceImpl :

HRESULT IsModuleMapped(VMPTR_Module pModule, OUT BOOL *isModuleMapped);

bool MetadataUpdatesApplied();

// retrieves the list of COM interfaces implemented by vmObject, as it is known at
// the time of the call (the list may change as new interface types become available
// in the runtime)
Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/debug/di/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14019,6 +14019,13 @@ void CordbWin32EventThread::AttachProcess()

EX_TRY
{
// Don't allow attach if any metadata/IL updates have been applied
if (pProcess->GetDAC()->MetadataUpdatesApplied())
{
hr = CORDBG_E_ASSEMBLY_UPDATES_APPLIED;
goto LExit;
}

// Mark interop-debugging
if (m_actionData.attachData.IsInteropDebugging())
{
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/debug/inc/dacdbiinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -2736,6 +2736,9 @@ class IDacDbiInterface
virtual
HRESULT IsModuleMapped(VMPTR_Module pModule, OUT BOOL *isModuleMapped) = 0;

virtual
bool MetadataUpdatesApplied() = 0;

// The following tag tells the DD-marshalling tool to stop scanning.
// END_MARSHAL

Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/inc/corerror.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,12 @@
<Comment>The delegate contains a delegate currently not supported by the API.</Comment>
</HRESULT>

<HRESULT NumericValue="0x80131c69">
<SymbolicName>CORDBG_E_ASSEMBLY_UPDATES_APPLIED</SymbolicName>
<Message>"The operation is not supported because assembly updates have been applied."</Message>
<Comment>The operation is not supported because assembly updates have been applied.</Comment>
</HRESULT>

<HRESULT NumericValue="0x80131d02">
<SymbolicName>PEFMT_E_64BIT</SymbolicName>
<Message>"File is PE32+."</Message>
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/inc/dacvars.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,9 @@ DEFINE_DACVAR(ULONG, TADDR, dac__g_MiniMetaDataBuffAddress, ::g_MiniMetaDataBuff

DEFINE_DACVAR(ULONG, SIZE_T, dac__g_clrNotificationArguments, ::g_clrNotificationArguments)

#ifdef EnC_SUPPORTED
DEFINE_DACVAR(ULONG, bool, dac__g_metadataUpdatesApplied, ::g_metadataUpdatesApplied)
#endif

#undef DEFINE_DACVAR
#undef DEFINE_DACVAR_NO_DUMP
1 change: 1 addition & 0 deletions src/coreclr/pal/prebuilt/inc/corerror.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
#define CORDBG_E_DATA_TARGET_ERROR EMAKEHR(0x1c61)
#define CORDBG_E_NO_IMAGE_AVAILABLE EMAKEHR(0x1c64)
#define CORDBG_E_UNSUPPORTED_DELEGATE EMAKEHR(0x1c68)
#define CORDBG_E_ASSEMBLY_UPDATES_APPLIED EMAKEHR(0x1c69)
#define PEFMT_E_64BIT EMAKEHR(0x1d02)
#define PEFMT_E_32BIT EMAKEHR(0x1d0b)
#define CLDB_E_INTERNALERROR EMAKEHR(0x1fff)
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/vm/assemblynative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ void QCALLTYPE AssemblyNative::ApplyUpdate(
{
if (CORDebuggerAttached())
{
COMPlusThrow(kNotSupportedException);
COMPlusThrow(kNotSupportedException, W("NotSupported_DebuggerAttached"));
}
Module* pModule = assembly->GetDomainAssembly()->GetModule();
if (!pModule->IsEditAndContinueEnabled())
Expand All @@ -1447,6 +1447,7 @@ void QCALLTYPE AssemblyNative::ApplyUpdate(
{
COMPlusThrow(kInvalidOperationException, W("InvalidOperation_EditFailed"));
}
g_metadataUpdatesApplied = true;
}
#else
COMPlusThrow(kNotImplementedException);
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/vm/vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ bool g_fEEInit = false;
// code:IsAtProcessExit to read this.
GVAL_IMPL(bool, g_fProcessDetach);

#ifdef EnC_SUPPORTED
GVAL_IMPL_INIT(bool, g_metadataUpdatesApplied, false);
#endif

GVAL_IMPL_INIT(DWORD, g_fEEShutDown, 0);

#ifndef TARGET_UNIX
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/vm/vars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ EXTERN DWORD g_fFastExitProcess;
EXTERN BOOL g_fFatalErrorOccurredOnGCThread;
EXTERN Volatile<LONG> g_fForbidEnterEE;
GVAL_DECL(bool, g_fProcessDetach);
#ifdef EnC_SUPPORTED
GVAL_DECL(bool, g_metadataUpdatesApplied);
#endif
EXTERN bool g_fManagedAttach;
EXTERN bool g_fNoExceptions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3682,6 +3682,9 @@
<data name="InvalidOperation_EditFailed" xml:space="preserve">
<value>The assembly update failed.</value>
</data>
<data name="NotSupported_DebuggerAttached" xml:space="preserve">
<value>Assembly updates cannot be applied while a debugger is attached.</value>
</data>
<data name="NotSupported_MethodBodyReplacement" xml:space="preserve">
<value>Method body replacement not supported in this runtime.</value>
</data>
Expand Down

0 comments on commit e503be0

Please sign in to comment.