Skip to content

Commit 38af44d

Browse files
Copilotrcj1
andauthored
[cDAC] Add simple Debugger DacDbi APIs (#127037)
Add `RequestSyncAtEvent`, ` SetSendExceptionsOutsideOfJMC`, `GetDebuggerControlBlockAddress` and `EnableGCNotificationEvents` DacDbi cDAC APIs, as well as APIs on Debugger contract of the same name, and unit tests. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rcj1 <rachel.jarvi@gmail.com> Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
1 parent 044805c commit 38af44d

18 files changed

Lines changed: 452 additions & 49 deletions

File tree

docs/design/datacontracts/Debugger.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ record struct DebuggerData(uint DefinesBitField, uint MDStructuresVersion);
1212
bool TryGetDebuggerData(out DebuggerData data);
1313
int GetAttachStateFlags();
1414
bool MetadataUpdatesApplied();
15+
void RequestSyncAtEvent();
16+
void SetSendExceptionsOutsideOfJMC(bool sendExceptionsOutsideOfJMC);
17+
TargetPointer GetDebuggerControlBlockAddress();
18+
void EnableGCNotificationEvents(bool fEnable);
1519
```
1620

1721
## Version 1
@@ -31,6 +35,11 @@ The contract additionally depends on these data descriptors
3135
| `Debugger` | `LeftSideInitialized` | Whether the left-side debugger infrastructure is initialized |
3236
| `Debugger` | `Defines` | Bitfield of compile-time debugger feature defines |
3337
| `Debugger` | `MDStructuresVersion` | Version of metadata data structures |
38+
| `Debugger` | `RCThread` | Pointer to `DebuggerRCThread` |
39+
| `Debugger` | `RSRequestedSync` | Sync-at-event request flag |
40+
| `Debugger` | `SendExceptionsOutsideOfJMC` | Exception delivery policy flag |
41+
| `Debugger` | `GCNotificationEventsEnabled` | Whether GC notification events are enabled |
42+
| `DebuggerRCThread` | `DCB` | Pointer to `DebuggerIPCControlBlock` |
3443

3544
```csharp
3645
bool TryGetDebuggerData(out DebuggerData data)
@@ -65,4 +74,44 @@ bool MetadataUpdatesApplied()
6574
return target.Read<byte>(addr) != 0;
6675
return false;
6776
}
77+
78+
void RequestSyncAtEvent()
79+
{
80+
if (!TryGetDebuggerAddress(out TargetPointer debuggerAddress))
81+
return;
82+
83+
target.Write<int>(debuggerAddress + /* Debugger::RSRequestedSync offset */, 1);
84+
}
85+
86+
void SetSendExceptionsOutsideOfJMC(bool sendExceptionsOutsideOfJMC)
87+
{
88+
if (!TryGetDebuggerAddress(out TargetPointer debuggerAddress))
89+
return;
90+
91+
target.Write<int>(
92+
debuggerAddress + /* Debugger::SendExceptionsOutsideOfJMC offset */,
93+
sendExceptionsOutsideOfJMC ? 1 : 0);
94+
}
95+
96+
TargetPointer GetDebuggerControlBlockAddress()
97+
{
98+
if (!TryGetDebuggerAddress(out TargetPointer debuggerAddress))
99+
return TargetPointer.Null;
100+
101+
TargetPointer rcThread = target.ReadPointer(debuggerAddress + /* Debugger::RCThread offset */);
102+
if (rcThread == TargetPointer.Null)
103+
return TargetPointer.Null;
104+
105+
return target.ReadPointer(rcThread + /* DebuggerRCThread::DCB offset */);
106+
}
107+
108+
void EnableGCNotificationEvents(bool fEnable)
109+
{
110+
if (!TryGetDebuggerAddress(out TargetPointer debuggerAddress))
111+
return;
112+
113+
target.Write<int>(
114+
debuggerAddress + /* Debugger::GCNotificationEventsEnabled offset */,
115+
fEnable ? 1 : 0);
116+
}
68117
```

src/coreclr/debug/ee/debugger.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "dllimportcallback.h"
4747

4848
#include "canary.h"
49+
#include "cdacdata.h"
4950

5051
#undef ASSERT
5152
#define CRASH(x) _ASSERTE(!(x))
@@ -901,6 +902,7 @@ class DebuggerRCThread
901902

902903

903904
friend class Debugger;
905+
friend struct ::cdac_data<DebuggerRCThread>;
904906
Debugger* m_debugger;
905907

906908
// IPC_TARGET_* define default targets - if we ever want to do
@@ -2892,6 +2894,7 @@ class Debugger : public DebugInterface
28922894

28932895
// DacDbiInterfaceImpl needs to be able to write to private fields in the debugger class.
28942896
friend class DacDbiInterfaceImpl;
2897+
friend struct ::cdac_data<Debugger>;
28952898

28962899
// Set OOP by RS to request a sync after a debug event.
28972900
// Clear by LS when we sync.
@@ -3884,6 +3887,21 @@ HANDLE OpenWin32EventOrThrow(
38843887
// Include all of the inline stuff now.
38853888
#include "debugger.inl"
38863889

3890+
template<>
3891+
struct cdac_data<Debugger>
3892+
{
3893+
static constexpr size_t RCThread = offsetof(Debugger, m_pRCThread);
3894+
static constexpr size_t RSRequestedSync = offsetof(Debugger, m_RSRequestedSync);
3895+
static constexpr size_t SendExceptionsOutsideOfJMC = offsetof(Debugger, m_sendExceptionsOutsideOfJMC);
3896+
static constexpr size_t GCNotificationEventsEnabled = offsetof(Debugger, m_isGarbageCollectionEventsEnabled);
3897+
};
3898+
3899+
template<>
3900+
struct cdac_data<DebuggerRCThread>
3901+
{
3902+
static constexpr size_t DCB = offsetof(DebuggerRCThread, m_pDCB);
3903+
};
3904+
38873905

38883906
//
38893907
//

src/coreclr/gc/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ endif (CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_AMD64)
4141

4242
if (CLR_CMAKE_TARGET_WIN32)
4343
set(GC_HEADERS
44-
env/cdacdata.h
4544
env/common.h
4645
env/etmdummy.h
4746
env/gcenv.base.h

src/coreclr/gc/gc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Module Name:
3030
#endif // BUILD_AS_STANDALONE
3131
#include "gcconfig.h"
3232

33-
#include "cdacdata.h"
33+
#include "../inc/cdacdata.h"
3434

3535
/*
3636
* Promotion Function Prototypes

src/coreclr/inc/patchpointinfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <clrtypes.h>
99

10-
#include "../vm/cdacdata.h"
10+
#include "cdacdata.h"
1111

1212
#ifndef _PATCHPOINTINFO_H_
1313
#define _PATCHPOINTINFO_H_

src/coreclr/inc/shash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "clrtypes.h"
1010
#include "check.h"
1111
#include "iterator.h"
12-
#include "../vm/cdacdata.h"
12+
#include "cdacdata.h"
1313

1414
// SHash is a templated closed chaining hash table of pointers. It provides
1515
// for multiple entries under the same key, and also for deleting elements.

src/coreclr/interop/inc/interoplibabi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <stddef.h>
88
#include <interoplib.h>
9-
#include "../../vm/cdacdata.h"
9+
#include "cdacdata.h"
1010

1111
namespace InteropLib
1212
{

src/coreclr/vm/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ set(VM_HEADERS_WKS
410410
cachelinealloc.h
411411
callhelpers.h
412412
callconvbuilder.hpp
413-
cdacdata.h
414413
ceemain.h
415414
clrconfignative.h
416415
clrex.h

src/coreclr/vm/cdacdata.h

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)