summaryrefslogtreecommitdiff
path: root/src/debug/di/shimdatatarget.h
blob: 1fabad4778fd5aafb2e68b69e3685d3218937b86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
//*****************************************************************************
// ShimDataTarget.h
// 

// 
// header for liveproc data targets
//*****************************************************************************

#ifndef SHIMDATATARGET_H_
#define SHIMDATATARGET_H_


// Function to invoke for 
typedef HRESULT (*FPContinueStatusChanged)(void * pUserData, DWORD dwThreadId, CORDB_CONTINUE_STATUS dwContinueStatus);


//---------------------------------------------------------------------------------------
// Data target for a live process. This is used by Shim. 
// 
class ShimDataTarget : public ICorDebugMutableDataTarget
{
public:
    virtual ~ShimDataTarget() {}

    // Allow hooking an implementation for ContinueStatusChanged.
    void HookContinueStatusChanged(FPContinueStatusChanged fpContinueStatusChanged, void * pUserData);

    // Release any resources. Also called by destructor.
    virtual void Dispose() = 0;

    // Set data-target into an error mode. This can be used to mark that the process
    // is unavailable because it's running
    void SetError(HRESULT hr);

    // Get the OS Process ID that this DataTarget is for.
    DWORD GetPid();

    //
    // IUnknown.
    //
    virtual HRESULT STDMETHODCALLTYPE QueryInterface(
        REFIID InterfaceId,
        PVOID* Interface);
    
    virtual ULONG STDMETHODCALLTYPE AddRef();

    virtual ULONG STDMETHODCALLTYPE Release();

    //
    // ICorDebugMutableDataTarget.
    //

    virtual HRESULT STDMETHODCALLTYPE GetPlatform( 
        CorDebugPlatform * pPlatform) = 0;

    virtual HRESULT STDMETHODCALLTYPE ReadVirtual( 
        CORDB_ADDRESS address,
        BYTE * pBuffer,
        ULONG32 request,
        ULONG32 * pcbRead) = 0;

    virtual HRESULT STDMETHODCALLTYPE WriteVirtual( 
        CORDB_ADDRESS address,
        const BYTE * pBuffer,
        ULONG32 request) = 0;

    virtual HRESULT STDMETHODCALLTYPE GetThreadContext(
        DWORD dwThreadID,
        ULONG32 contextFlags,
        ULONG32 contextSize,
        BYTE * context) = 0;

    virtual HRESULT STDMETHODCALLTYPE SetThreadContext(
        DWORD dwThreadID,
        ULONG32 contextSize,
        const BYTE * context) = 0;

    virtual HRESULT STDMETHODCALLTYPE ContinueStatusChanged(
        DWORD dwThreadId,
        CORDB_CONTINUE_STATUS dwContinueStatus) = 0;

    // @dbgtodo - add Native Patch Table support

protected:
    // Pid of the target process.
    DWORD m_processId;

    // If this HRESULT != S_OK, then all interface methods will return this.
    // This provides a way to mark the debugggee as stopped / dead.
    HRESULT m_hr;

    FPContinueStatusChanged m_fpContinueStatusChanged;
    void * m_pContinueStatusChangedUserData;

    // Reference count.
    LONG m_ref;
};

//---------------------------------------------------------------------------------------
//
// Construction method for data-target
//
// Arguments:
//      machineInfo - used for Mac debugging; uniquely identifies the debugger proxy on the remote machine
//      processId - (input) live OS process ID to build a data-target for.
//      ppDataTarget - (output) new data-target instance. This gets addreffed.
//
// Return Value:
//    S_OK on success.
//
// Assumptions:
//    pid must be for local, same architecture, process.
//    Caller must have security permissions for OpenProcess()
//    Caller must release *ppDataTarget.
//

HRESULT BuildPlatformSpecificDataTarget(MachineInfo machineInfo,
                                        DWORD processId, 
                                        ShimDataTarget ** ppDataTarget);

#endif //  SHIMDATATARGET_H_