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.
6 #ifndef __DBG_TRANSPORT_MANAGER_INCLUDED
7 #define __DBG_TRANSPORT_MANAGER_INCLUDED
9 #ifdef FEATURE_DBGIPC_TRANSPORT_DI
11 #include "coreclrremotedebugginginterfaces.h"
14 // TODO: Ideally we'd like to remove this class and don't do any process related book keeping in DBI.
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.
20 // Usual lifecycle looks like this:
21 // Debug a new process:
22 // * CreateProcess(&pid)
23 // * GetTransportForProcess(pid, &transport)
24 // * ReleaseTransport(transport)
27 // Attach to an existing process:
28 // * Obtain pid from a user
29 // * GetTransportForProcess(pid, &transport)
30 // * ReleaseTransport(transport)
32 class DbgTransportTarget
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);
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);
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,
52 DWORD dwCreationFlags,
54 LPCWSTR lpCurrentDirectory,
55 LPSTARTUPINFOW lpStartupInfo,
56 LPPROCESS_INFORMATION lpProcessInformation);
58 // Kill the process identified by PID.
59 void KillProcess(DWORD dwPID);
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
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
79 // Locate a process entry by PID. Assumes the lock is already held.
80 ProcessEntry *LocateProcessByPID(DWORD dwPID);
83 extern DbgTransportTarget *g_pDbgTransportTarget;
85 #endif // FEATURE_DBGIPC_TRANSPORT_DI
87 #endif // __DBG_TRANSPORT_MANAGER_INCLUDED