Merge pull request #10727 from hqueue/typo/doc_ryujit
[platform/upstream/coreclr.git] / src / debug / di / dbgtransportmanager.h
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5
6 #ifndef __DBG_TRANSPORT_MANAGER_INCLUDED
7 #define __DBG_TRANSPORT_MANAGER_INCLUDED
8
9 #ifdef FEATURE_DBGIPC_TRANSPORT_DI
10
11 #include "coreclrremotedebugginginterfaces.h"
12
13
14 // TODO: Ideally we'd like to remove this class and don't do any process related book keeping in DBI.
15
16 // This is a registry of all the processes a debugger knows about, different components call it in order to  
17 // obtain right instance of DbgTransportSession for a given PID. It keeps list of processes and transports for them.
18 // It also handles things like creating and killing a process.
19
20 // Usual lifecycle looks like this:
21 // Debug a new process:
22 // * CreateProcess(&pid)
23 // * GetTransportForProcess(pid, &transport) 
24 // * ReleaseTransport(transport)
25 // * KillProcess(pid)
26
27 // Attach to an existing process:
28 // * Obtain pid from a user
29 // * GetTransportForProcess(pid, &transport) 
30 // * ReleaseTransport(transport)
31
32 class DbgTransportTarget
33 {
34 public:
35     DbgTransportTarget();
36
37     // Given a PID attempt to find or create a DbgTransportSession instance to manage a connection to a
38     // runtime in that process. Returns E_UNEXPECTED if the process can't be found. Also returns a handle that
39     // can be waited on for process termination.
40     HRESULT GetTransportForProcess(DWORD dwPID, DbgTransportSession **ppTransport, HANDLE *phProcessHandle);
41
42     // Give back a previously acquired transport (if nobody else is using the transport it will close down the
43     // connection at this point).
44     void ReleaseTransport(DbgTransportSession *pTransport);
45
46     // When and if the process starts the runtime will be told to halt and wait for a debugger attach.
47     HRESULT CreateProcess(LPCWSTR lpApplicationName,
48                           LPCWSTR lpCommandLine,
49                           LPSECURITY_ATTRIBUTES lpProcessAttributes,
50                           LPSECURITY_ATTRIBUTES lpThreadAttributes,
51                           BOOL bInheritHandles,
52                           DWORD dwCreationFlags,
53                           LPVOID lpEnvironment,
54                           LPCWSTR lpCurrentDirectory,
55                           LPSTARTUPINFOW lpStartupInfo,
56                           LPPROCESS_INFORMATION lpProcessInformation);    
57
58     // Kill the process identified by PID.
59     void KillProcess(DWORD dwPID);
60
61     HRESULT Init();
62     void Shutdown();
63
64 private:
65     struct ProcessEntry
66     {
67         ProcessEntry           *m_pNext;            // Next entry in the list
68         DWORD                   m_dwPID;            // Process ID for this entry
69         HANDLE                  m_hProcess;         // Process handle
70         DbgTransportSession    *m_transport;        // Debugger's connection to the process
71         DWORD                   m_cProcessRef;      // Ref count
72
73         ~ProcessEntry();
74     };
75
76     ProcessEntry           *m_pProcessList;         // Head of list of currently alive processes (unsorted)
77     RSLock                  m_sLock;                // Lock protecting read and write access to the target list
78
79     // Locate a process entry by PID. Assumes the lock is already held.
80     ProcessEntry *LocateProcessByPID(DWORD dwPID);
81 };
82
83 extern DbgTransportTarget *g_pDbgTransportTarget;
84
85 #endif // FEATURE_DBGIPC_TRANSPORT_DI
86
87 #endif // __DBG_TRANSPORT_MANAGER_INCLUDED