Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 3bef239

Browse files
author
Mike McLaughlin
committed
Merge pull request #3783 from mikem8361/fixsosbp
Fixed problem with bpmd not working sometimes.
2 parents 6aae434 + 36ac82a commit 3bef239

File tree

6 files changed

+75
-105
lines changed

6 files changed

+75
-105
lines changed

src/ToolBox/SOS/Strike/WatchCmd.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,8 @@ HRESULT WatchCmd::Remove(int index)
9292
HRESULT WatchCmd::Print(int expansionIndex, __in_z WCHAR* expansionPath, __in_z WCHAR* pFilterName)
9393
{
9494
HRESULT Status = S_OK;
95-
if ((Status = CheckEEDll()) != S_OK)
96-
{
97-
EENotLoadedMessage(Status);
98-
return Status;
99-
}
100-
if ((Status = LoadClrDebugDll()) != S_OK)
101-
{
102-
DACMessage(Status);
103-
return Status;
104-
}
95+
INIT_API_EE();
96+
INIT_API_DAC();
10597
EnableDMLHolder dmlHolder(TRUE);
10698
IfFailRet(InitCorDebugInterface());
10799

@@ -214,6 +206,8 @@ HRESULT WatchCmd::RenameList(__in_z WCHAR* pOldName, __in_z WCHAR* pNewName)
214206
HRESULT WatchCmd::SaveList(__in_z WCHAR* pSaveName)
215207
{
216208
HRESULT Status = S_OK;
209+
INIT_API_EE();
210+
INIT_API_DAC();
217211
IfFailRet(InitCorDebugInterface());
218212

219213
RemoveList(pSaveName);

src/ToolBox/SOS/Strike/exts.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,22 @@ HRESULT CheckEEDll();
231231
if ((Status = ExtQuery(client)) != S_OK) return Status; \
232232
if ((Status = ArchQuery()) != S_OK) return Status; \
233233
ControlC = FALSE; \
234-
g_bDacBroken = TRUE;
234+
g_bDacBroken = TRUE; \
235+
g_clrData = NULL; \
236+
g_sos = NULL;
235237

236-
#define INIT_API_NODAC() \
237-
INIT_API_NOEE() \
238+
#define INIT_API_EE() \
238239
if ((Status = CheckEEDll()) != S_OK) \
239240
{ \
240241
EENotLoadedMessage(Status); \
241242
return Status; \
242243
}
243244

244-
#define INIT_API() \
245-
INIT_API_NODAC() \
245+
#define INIT_API_NODAC() \
246+
INIT_API_NOEE() \
247+
INIT_API_EE()
248+
249+
#define INIT_API_DAC() \
246250
if ((Status = LoadClrDebugDll()) != S_OK) \
247251
{ \
248252
DACMessage(Status); \
@@ -255,6 +259,10 @@ HRESULT CheckEEDll();
255259
ToRelease<ISOSDacInterface> spISD(g_sos); \
256260
ResetGlobals();
257261

262+
#define INIT_API() \
263+
INIT_API_NODAC() \
264+
INIT_API_DAC()
265+
258266
// Attempt to initialize DAC and SOS globals, but do not "return" on failure.
259267
// Instead, mark the failure to initialize the DAC by setting g_bDacBroken to TRUE.
260268
// This should be used from extension commands that should work OK even when no
@@ -263,7 +271,6 @@ HRESULT CheckEEDll();
263271
// feature.
264272
#define INIT_API_NO_RET_ON_FAILURE() \
265273
INIT_API_NOEE() \
266-
g_clrData = NULL; \
267274
if ((Status = CheckEEDll()) != S_OK) \
268275
{ \
269276
ExtOut("Failed to find runtime DLL (%s), 0x%08x\n", MAKEDLLNAME_A("coreclr"), Status); \

src/ToolBox/SOS/Strike/strike.cpp

Lines changed: 30 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6319,11 +6319,6 @@ class Breakpoints
63196319
#ifdef FEATURE_PAL
63206320
if (m_breakpoints == NULL)
63216321
{
6322-
ULONG32 flags = 0;
6323-
g_clrData->GetOtherNotificationFlags(&flags);
6324-
flags &= ~(CLRDATA_NOTIFY_ON_MODULE_LOAD | CLRDATA_NOTIFY_ON_MODULE_UNLOAD);
6325-
g_clrData->SetOtherNotificationFlags(flags);
6326-
63276322
g_ExtServices->ClearExceptionCallback();
63286323
}
63296324
#endif
@@ -6652,6 +6647,7 @@ class Breakpoints
66526647

66536648
ToRelease<IXCLRDataMethodDefinition> pMeth = NULL;
66546649
mod->GetMethodDefinitionByToken(pCur->methodToken, &pMeth);
6650+
66556651
// We may not need the code notification. Maybe it was ngen'd and we
66566652
// already have the method?
66576653
// We can delete the current entry if ResolveMethodInstances() set all BPs
@@ -6865,8 +6861,12 @@ class CNotification : public IXCLRDataExceptionNotification4
68656861
if(method->GetRepresentativeEntryAddress(&startAddr) == S_OK)
68666862
{
68676863
CHAR buffer[100];
6864+
#ifndef FEATURE_PAL
68686865
sprintf_s(buffer, _countof(buffer), "bp /1 %p", (void*) (size_t) (startAddr+catcherNativeOffset));
6869-
g_ExtControl->Execute(DEBUG_EXECUTE_NOT_LOGGED, buffer ,0);
6866+
#else
6867+
sprintf_s(buffer, _countof(buffer), "breakpoint set --one-shot --address 0x%p", (void*) (size_t) (startAddr+catcherNativeOffset));
6868+
#endif
6869+
g_ExtControl->Execute(DEBUG_EXECUTE_NOT_LOGGED, buffer, 0);
68706870
}
68716871
g_stopOnNextCatch = FALSE;
68726872
}
@@ -7020,7 +7020,7 @@ HRESULT HandleExceptionNotification(ILLDBServices *client)
70207020

70217021
DECLARE_API(bpmd)
70227022
{
7023-
INIT_API();
7023+
INIT_API_NOEE();
70247024
MINIDUMP_NOT_SUPPORTED();
70257025
int i;
70267026
char buffer[1024];
@@ -7169,9 +7169,6 @@ DECLARE_API(bpmd)
71697169
LPWSTR Filename = (LPWSTR)alloca(MAX_LONGPATH * sizeof(WCHAR));
71707170

71717171
BOOL bNeedNotificationExceptions = FALSE;
7172-
#ifdef FEATURE_PAL
7173-
BOOL bNeedModuleNotificationExceptions = FALSE;
7174-
#endif
71757172

71767173
if (pMD == NULL)
71777174
{
@@ -7190,7 +7187,7 @@ DECLARE_API(bpmd)
71907187
MultiByteToWideChar(CP_ACP, 0, DllName.data, -1, Filename, MAX_LONGPATH);
71917188
}
71927189

7193-
// get modules that may need a breakpoint bound
7190+
// Get modules that may need a breakpoint bound
71947191
if ((Status = CheckEEDll()) == S_OK)
71957192
{
71967193
if ((Status = LoadClrDebugDll()) != S_OK)
@@ -7199,23 +7196,25 @@ DECLARE_API(bpmd)
71997196
DACMessage(Status);
72007197
return Status;
72017198
}
7202-
else
7203-
{
7204-
// get the module list
7205-
moduleList = ModuleFromName(fIsFilename ? NULL : DllName.data, &numModule);
7206-
7207-
// Its OK if moduleList is NULL
7208-
// There is a very normal case when checking for modules after clr is loaded
7209-
// but before any AppDomains or assemblies are created
7210-
// for example:
7211-
// >sxe ld:clr
7212-
// >g
7213-
// ...
7214-
// ModLoad: clr.dll
7215-
// >!bpmd Foo.dll Foo.Bar
7216-
}
7217-
}
7218-
7199+
g_bDacBroken = FALSE; \
7200+
7201+
// Get the module list
7202+
moduleList = ModuleFromName(fIsFilename ? NULL : DllName.data, &numModule);
7203+
7204+
// Its OK if moduleList is NULL
7205+
// There is a very normal case when checking for modules after clr is loaded
7206+
// but before any AppDomains or assemblies are created
7207+
// for example:
7208+
// >sxe ld:clr
7209+
// >g
7210+
// ...
7211+
// ModLoad: clr.dll
7212+
// >!bpmd Foo.dll Foo.Bar
7213+
}
7214+
// If LoadClrDebugDll() succeeded make sure we release g_clrData
7215+
ToRelease<IXCLRDataProcess> spIDP(g_clrData);
7216+
ToRelease<ISOSDacInterface> spISD(g_sos);
7217+
ResetGlobals();
72197218

72207219
// we can get here with EE not loaded => 0 modules
72217220
// EE is loaded => 0 or more modules
@@ -7308,24 +7307,13 @@ DECLARE_API(bpmd)
73087307
g_bpoints.Add(Filename, lineNumber, NULL);
73097308
}
73107309
bNeedNotificationExceptions = TRUE;
7311-
#ifdef FEATURE_PAL
7312-
bNeedModuleNotificationExceptions = TRUE;
7313-
#endif
73147310
}
73157311
}
73167312
else /* We were given a MethodDesc already */
73177313
{
73187314
// if we've got an explicit MD, then we better have CLR and mscordacwks loaded
7319-
if ((Status = CheckEEDll()) != S_OK)
7320-
{
7321-
EENotLoadedMessage(Status);
7322-
return Status;
7323-
}
7324-
if ((Status = LoadClrDebugDll()) != S_OK)
7325-
{
7326-
DACMessage(Status);
7327-
return Status;
7328-
}
7315+
INIT_API_EE()
7316+
INIT_API_DAC();
73297317

73307318
DacpMethodDescData MethodDescData;
73317319
ExtOut("MethodDesc = %p\n", (ULONG64) pMD);
@@ -7371,7 +7359,6 @@ DECLARE_API(bpmd)
73717359
else
73727360
{
73737361
// Must issue a pending breakpoint.
7374-
73757362
if (g_sos->GetMethodDescName(pMD, mdNameLen, FunctionName, NULL) != S_OK)
73767363
{
73777364
ExtOut("Unable to get method name for MethodDesc %p\n", (ULONG64)pMD);
@@ -7394,13 +7381,6 @@ DECLARE_API(bpmd)
73947381
sprintf_s(buffer, _countof(buffer), "sxe -c \"!HandleCLRN\" clrn");
73957382
Status = g_ExtControl->Execute(DEBUG_EXECUTE_NOT_LOGGED, buffer, 0);
73967383
#else
7397-
if (bNeedModuleNotificationExceptions)
7398-
{
7399-
ULONG32 flags = 0;
7400-
g_clrData->GetOtherNotificationFlags(&flags);
7401-
flags |= (CLRDATA_NOTIFY_ON_MODULE_LOAD | CLRDATA_NOTIFY_ON_MODULE_UNLOAD);
7402-
g_clrData->SetOtherNotificationFlags(flags);
7403-
}
74047384
Status = g_ExtServices->SetExceptionCallback(HandleExceptionNotification);
74057385
#endif // FEATURE_PAL
74067386
}
@@ -14099,9 +14079,7 @@ HRESULT SetNGENCompilerFlags(DWORD flags)
1409914079
}
1410014080

1410114081

14102-
1410314082
// This is an internal-only Apollo extension to save breakpoint/watch state
14104-
#ifndef FEATURE_PAL
1410514083
DECLARE_API(SaveState)
1410614084
{
1410714085
INIT_API_NOEE();
@@ -14138,16 +14116,14 @@ DECLARE_API(SaveState)
1413814116
ExtOut("Session breakpoints and watch expressions saved to %s\n", filePath.data);
1413914117
return S_OK;
1414014118
}
14141-
#endif
1414214119

14120+
#endif // FEATURE_PAL
1414314121

1414414122
DECLARE_API(StopOnCatch)
1414514123
{
1414614124
INIT_API();
1414714125
MINIDUMP_NOT_SUPPORTED();
1414814126

14149-
CHAR buffer[100];
14150-
sprintf_s(buffer, _countof(buffer), "sxe -c \"!HandleCLRN\" clrn");
1415114127
g_stopOnNextCatch = TRUE;
1415214128
ULONG32 flags = 0;
1415314129
g_clrData->GetOtherNotificationFlags(&flags);
@@ -14157,7 +14133,6 @@ DECLARE_API(StopOnCatch)
1415714133
return S_OK;
1415814134
}
1415914135

14160-
1416114136
// This is an undocumented SOS extension command intended to help test SOS
1416214137
// It causes the Dml output to be printed to the console uninterpretted so
1416314138
// that a test script can read the commands which are hidden in the markup
@@ -14167,8 +14142,6 @@ DECLARE_API(ExposeDML)
1416714142
return S_OK;
1416814143
}
1416914144

14170-
#endif // FEATURE_PAL
14171-
1417214145
// According to kksharma the Windows debuggers always sign-extend
1417314146
// arguments when calling externally, therefore StackObjAddr
1417414147
// conforms to CLRDATA_ADDRESS contract.

src/ToolBox/SOS/Strike/util.cpp

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ IXCLRDataProcess *g_clrData = NULL;
6262
ISOSDacInterface *g_sos = NULL;
6363
ICorDebugProcess *g_pCorDebugProcess = NULL;
6464

65-
#ifdef FEATURE_PAL
66-
PFN_CLRDataCreateInstance g_pCLRDataCreateInstance = NULL;
67-
#endif // FEATURE_PAL
68-
6965
#ifndef IfFailRet
7066
#define IfFailRet(EXPR) do { Status = (EXPR); if(FAILED(Status)) { return (Status); } } while (0)
7167
#endif
@@ -4156,8 +4152,10 @@ void ResetGlobals(void)
41564152

41574153
HRESULT LoadClrDebugDll(void)
41584154
{
4155+
HRESULT hr = S_OK;
41594156
#ifdef FEATURE_PAL
4160-
if (g_pCLRDataCreateInstance == NULL)
4157+
static IXCLRDataProcess* s_clrDataProcess = NULL;
4158+
if (s_clrDataProcess == NULL)
41614159
{
41624160
int err = PAL_InitializeDLL();
41634161
if(err != 0)
@@ -4173,20 +4171,27 @@ HRESULT LoadClrDebugDll(void)
41734171
{
41744172
return E_FAIL;
41754173
}
4176-
g_pCLRDataCreateInstance = (PFN_CLRDataCreateInstance)GetProcAddress(hdac, "CLRDataCreateInstance");
4177-
if (g_pCLRDataCreateInstance == NULL)
4174+
PFN_CLRDataCreateInstance pCLRDataCreateInstance = (PFN_CLRDataCreateInstance)GetProcAddress(hdac, "CLRDataCreateInstance");
4175+
if (pCLRDataCreateInstance == NULL)
41784176
{
41794177
FreeLibrary(hdac);
41804178
return E_FAIL;
41814179
}
4180+
ICLRDataTarget *target = new DataTarget();
4181+
hr = pCLRDataCreateInstance(__uuidof(IXCLRDataProcess), target, (void**)&s_clrDataProcess);
4182+
if (FAILED(hr))
4183+
{
4184+
s_clrDataProcess = NULL;
4185+
return hr;
4186+
}
4187+
ULONG32 flags = 0;
4188+
s_clrDataProcess->GetOtherNotificationFlags(&flags);
4189+
flags |= (CLRDATA_NOTIFY_ON_MODULE_LOAD | CLRDATA_NOTIFY_ON_MODULE_UNLOAD | CLRDATA_NOTIFY_ON_EXCEPTION);
4190+
s_clrDataProcess->SetOtherNotificationFlags(flags);
41824191
}
4183-
ICLRDataTarget *target = new DataTarget();
4184-
HRESULT hr = g_pCLRDataCreateInstance(__uuidof(IXCLRDataProcess), target, reinterpret_cast<void**>(&g_clrData));
4185-
if (FAILED(hr))
4186-
{
4187-
g_clrData = NULL;
4188-
return hr;
4189-
}
4192+
g_clrData = s_clrDataProcess;
4193+
g_clrData->AddRef();
4194+
g_clrData->Flush();
41904195
#else
41914196
WDBGEXTS_CLR_DATA_INTERFACE Query;
41924197

@@ -4198,13 +4203,12 @@ HRESULT LoadClrDebugDll(void)
41984203

41994204
g_clrData = (IXCLRDataProcess*)Query.Iface;
42004205
#endif
4201-
4202-
if (FAILED(g_clrData->QueryInterface(__uuidof(ISOSDacInterface), (void**)&g_sos)))
4206+
hr = g_clrData->QueryInterface(__uuidof(ISOSDacInterface), (void**)&g_sos);
4207+
if (FAILED(hr))
42034208
{
42044209
g_sos = NULL;
4205-
return E_FAIL;
4210+
return hr;
42064211
}
4207-
42084212
return S_OK;
42094213
}
42104214

@@ -4769,18 +4773,6 @@ HRESULT InitCorDebugInterface()
47694773
UninitCorDebugInterface();
47704774
}
47714775

4772-
// Ensure that CLR and DAC are already loaded
4773-
if ((hr = CheckEEDll()) != S_OK)
4774-
{
4775-
EENotLoadedMessage(hr);
4776-
return hr;
4777-
}
4778-
if ((hr = LoadClrDebugDll()) != S_OK)
4779-
{
4780-
DACMessage(hr);
4781-
return hr;
4782-
}
4783-
47844776
// SOS now has a statically linked version of the loader code that is normally found in mscoree/mscoreei.dll
47854777
// Its not much code and takes a big step towards 0 install dependencies
47864778
// Need to pick the appropriate SKU of CLR to detect

src/debug/daccess/daccess.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7232,6 +7232,10 @@ ClrDataAccess::GetDacGlobals()
72327232
{
72337233
return CORDBG_E_MISSING_DEBUGGER_EXPORTS;
72347234
}
7235+
if (g_dacGlobals.ThreadStore__s_pThreadStore == NULL)
7236+
{
7237+
return CORDBG_E_UNSUPPORTED;
7238+
}
72357239
return S_OK;
72367240
#else
72377241
HRESULT status = E_FAIL;

src/vm/ceemain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,11 +1439,11 @@ HRESULT EEStartup(COINITIEE fFlags)
14391439
PAL_TRY(COINITIEE *, pfFlags, &fFlags)
14401440
{
14411441
#ifndef CROSSGEN_COMPILE
1442+
InitializeClrNotifications();
14421443
#ifdef FEATURE_PAL
1443-
DacGlobals::Initialize();
14441444
InitializeJITNotificationTable();
1445+
DacGlobals::Initialize();
14451446
#endif
1446-
InitializeClrNotifications();
14471447
#endif // CROSSGEN_COMPILE
14481448

14491449
EEStartupHelper(*pfFlags);

0 commit comments

Comments
 (0)