| 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 | #include <cstdarg> | 
|---|
| 6 |  | 
|---|
| 7 | class LLDBServices : public ILLDBServices | 
|---|
| 8 | { | 
|---|
| 9 | private: | 
|---|
| 10 | LONG m_ref; | 
|---|
| 11 | lldb::SBDebugger &m_debugger; | 
|---|
| 12 | lldb::SBCommandReturnObject &m_returnObject; | 
|---|
| 13 |  | 
|---|
| 14 | lldb::SBProcess *m_currentProcess; | 
|---|
| 15 | lldb::SBThread *m_currentThread; | 
|---|
| 16 |  | 
|---|
| 17 | void OutputString(ULONG mask, PCSTR str); | 
|---|
| 18 | ULONG64 GetModuleBase(lldb::SBTarget& target, lldb::SBModule& module); | 
|---|
| 19 | DWORD_PTR GetExpression(lldb::SBFrame& frame, lldb::SBError& error, PCSTR exp); | 
|---|
| 20 | void GetContextFromFrame(lldb::SBFrame& frame, DT_CONTEXT *dtcontext); | 
|---|
| 21 | DWORD_PTR GetRegister(lldb::SBFrame& frame, const char *name); | 
|---|
| 22 |  | 
|---|
| 23 | lldb::SBProcess GetCurrentProcess(); | 
|---|
| 24 | lldb::SBThread GetCurrentThread(); | 
|---|
| 25 | lldb::SBFrame GetCurrentFrame(); | 
|---|
| 26 |  | 
|---|
| 27 | public: | 
|---|
| 28 | LLDBServices(lldb::SBDebugger &debugger, lldb::SBCommandReturnObject &returnObject, lldb::SBProcess *process = nullptr, lldb::SBThread *thread = nullptr); | 
|---|
| 29 | ~LLDBServices(); | 
|---|
| 30 |  | 
|---|
| 31 | //---------------------------------------------------------------------------- | 
|---|
| 32 | // IUnknown | 
|---|
| 33 | //---------------------------------------------------------------------------- | 
|---|
| 34 |  | 
|---|
| 35 | HRESULT STDMETHODCALLTYPE QueryInterface( | 
|---|
| 36 | REFIID InterfaceId, | 
|---|
| 37 | PVOID* Interface); | 
|---|
| 38 |  | 
|---|
| 39 | ULONG STDMETHODCALLTYPE AddRef(); | 
|---|
| 40 |  | 
|---|
| 41 | ULONG STDMETHODCALLTYPE Release(); | 
|---|
| 42 |  | 
|---|
| 43 | //---------------------------------------------------------------------------- | 
|---|
| 44 | // ILLDBServices | 
|---|
| 45 | //---------------------------------------------------------------------------- | 
|---|
| 46 |  | 
|---|
| 47 | PCSTR GetCoreClrDirectory(); | 
|---|
| 48 |  | 
|---|
| 49 | DWORD_PTR GetExpression( | 
|---|
| 50 | PCSTR exp); | 
|---|
| 51 |  | 
|---|
| 52 | HRESULT VirtualUnwind( | 
|---|
| 53 | DWORD threadID, | 
|---|
| 54 | ULONG32 contextSize, | 
|---|
| 55 | PBYTE context); | 
|---|
| 56 |  | 
|---|
| 57 | HRESULT SetExceptionCallback( | 
|---|
| 58 | PFN_EXCEPTION_CALLBACK callback); | 
|---|
| 59 |  | 
|---|
| 60 | HRESULT ClearExceptionCallback(); | 
|---|
| 61 |  | 
|---|
| 62 | //---------------------------------------------------------------------------- | 
|---|
| 63 | // IDebugControl2 | 
|---|
| 64 | //---------------------------------------------------------------------------- | 
|---|
| 65 |  | 
|---|
| 66 | HRESULT GetInterrupt(); | 
|---|
| 67 |  | 
|---|
| 68 | HRESULT Output( | 
|---|
| 69 | ULONG mask, | 
|---|
| 70 | PCSTR format, | 
|---|
| 71 | ...); | 
|---|
| 72 |  | 
|---|
| 73 | HRESULT OutputVaList( | 
|---|
| 74 | ULONG mask, | 
|---|
| 75 | PCSTR format, | 
|---|
| 76 | va_list args); | 
|---|
| 77 |  | 
|---|
| 78 | HRESULT ControlledOutput( | 
|---|
| 79 | ULONG outputControl, | 
|---|
| 80 | ULONG mask, | 
|---|
| 81 | PCSTR format, | 
|---|
| 82 | ...); | 
|---|
| 83 |  | 
|---|
| 84 | HRESULT ControlledOutputVaList( | 
|---|
| 85 | ULONG outputControl, | 
|---|
| 86 | ULONG mask, | 
|---|
| 87 | PCSTR format, | 
|---|
| 88 | va_list args); | 
|---|
| 89 |  | 
|---|
| 90 | HRESULT GetDebuggeeType( | 
|---|
| 91 | PULONG debugClass, | 
|---|
| 92 | PULONG qualifier); | 
|---|
| 93 |  | 
|---|
| 94 | HRESULT GetPageSize( | 
|---|
| 95 | PULONG size); | 
|---|
| 96 |  | 
|---|
| 97 | HRESULT GetExecutingProcessorType( | 
|---|
| 98 | PULONG type); | 
|---|
| 99 |  | 
|---|
| 100 | HRESULT Execute( | 
|---|
| 101 | ULONG outputControl, | 
|---|
| 102 | PCSTR command, | 
|---|
| 103 | ULONG flags); | 
|---|
| 104 |  | 
|---|
| 105 | HRESULT GetLastEventInformation( | 
|---|
| 106 | PULONG type, | 
|---|
| 107 | PULONG processId, | 
|---|
| 108 | PULONG threadId, | 
|---|
| 109 | PVOID , | 
|---|
| 110 | ULONG , | 
|---|
| 111 | PULONG , | 
|---|
| 112 | PSTR description, | 
|---|
| 113 | ULONG descriptionSize, | 
|---|
| 114 | PULONG descriptionUsed); | 
|---|
| 115 |  | 
|---|
| 116 | HRESULT Disassemble( | 
|---|
| 117 | ULONG64 offset, | 
|---|
| 118 | ULONG flags, | 
|---|
| 119 | PSTR buffer, | 
|---|
| 120 | ULONG bufferSize, | 
|---|
| 121 | PULONG disassemblySize, | 
|---|
| 122 | PULONG64 endOffset); | 
|---|
| 123 |  | 
|---|
| 124 | //---------------------------------------------------------------------------- | 
|---|
| 125 | // IDebugControl4 | 
|---|
| 126 | //---------------------------------------------------------------------------- | 
|---|
| 127 |  | 
|---|
| 128 | HRESULT | 
|---|
| 129 | GetContextStackTrace( | 
|---|
| 130 | PVOID startContext, | 
|---|
| 131 | ULONG startContextSize, | 
|---|
| 132 | PDEBUG_STACK_FRAME frames, | 
|---|
| 133 | ULONG framesSize, | 
|---|
| 134 | PVOID frameContexts, | 
|---|
| 135 | ULONG frameContextsSize, | 
|---|
| 136 | ULONG frameContextsEntrySize, | 
|---|
| 137 | PULONG framesFilled); | 
|---|
| 138 |  | 
|---|
| 139 | //---------------------------------------------------------------------------- | 
|---|
| 140 | // IDebugDataSpaces | 
|---|
| 141 | //---------------------------------------------------------------------------- | 
|---|
| 142 |  | 
|---|
| 143 | HRESULT ReadVirtual( | 
|---|
| 144 | ULONG64 offset, | 
|---|
| 145 | PVOID buffer, | 
|---|
| 146 | ULONG bufferSize, | 
|---|
| 147 | PULONG bytesRead); | 
|---|
| 148 |  | 
|---|
| 149 | HRESULT WriteVirtual( | 
|---|
| 150 | ULONG64 offset, | 
|---|
| 151 | PVOID buffer, | 
|---|
| 152 | ULONG bufferSize, | 
|---|
| 153 | PULONG bytesWritten); | 
|---|
| 154 |  | 
|---|
| 155 | //---------------------------------------------------------------------------- | 
|---|
| 156 | // IDebugSymbols | 
|---|
| 157 | //---------------------------------------------------------------------------- | 
|---|
| 158 |  | 
|---|
| 159 | HRESULT GetSymbolOptions( | 
|---|
| 160 | PULONG options); | 
|---|
| 161 |  | 
|---|
| 162 | HRESULT GetNameByOffset( | 
|---|
| 163 | ULONG64 offset, | 
|---|
| 164 | PSTR nameBuffer, | 
|---|
| 165 | ULONG nameBufferSize, | 
|---|
| 166 | PULONG nameSize, | 
|---|
| 167 | PULONG64 displacement); | 
|---|
| 168 |  | 
|---|
| 169 | HRESULT GetNumberModules( | 
|---|
| 170 | PULONG loaded, | 
|---|
| 171 | PULONG unloaded); | 
|---|
| 172 |  | 
|---|
| 173 | HRESULT GetModuleByIndex( | 
|---|
| 174 | ULONG index, | 
|---|
| 175 | PULONG64 base); | 
|---|
| 176 |  | 
|---|
| 177 | HRESULT GetModuleByModuleName( | 
|---|
| 178 | PCSTR name, | 
|---|
| 179 | ULONG startIndex, | 
|---|
| 180 | PULONG index, | 
|---|
| 181 | PULONG64 base); | 
|---|
| 182 |  | 
|---|
| 183 | HRESULT GetModuleByOffset( | 
|---|
| 184 | ULONG64 offset, | 
|---|
| 185 | ULONG startIndex, | 
|---|
| 186 | PULONG index, | 
|---|
| 187 | PULONG64 base); | 
|---|
| 188 |  | 
|---|
| 189 | HRESULT GetModuleNames( | 
|---|
| 190 | ULONG index, | 
|---|
| 191 | ULONG64 base, | 
|---|
| 192 | PSTR imageNameBuffer, | 
|---|
| 193 | ULONG imageNameBufferSize, | 
|---|
| 194 | PULONG imageNameSize, | 
|---|
| 195 | PSTR moduleNameBuffer, | 
|---|
| 196 | ULONG moduleNameBufferSize, | 
|---|
| 197 | PULONG moduleNameSize, | 
|---|
| 198 | PSTR loadedImageNameBuffer, | 
|---|
| 199 | ULONG loadedImageNameBufferSize, | 
|---|
| 200 | PULONG loadedImageNameSize); | 
|---|
| 201 |  | 
|---|
| 202 | HRESULT GetLineByOffset( | 
|---|
| 203 | ULONG64 offset, | 
|---|
| 204 | PULONG line, | 
|---|
| 205 | PSTR fileBuffer, | 
|---|
| 206 | ULONG fileBufferSize, | 
|---|
| 207 | PULONG fileSize, | 
|---|
| 208 | PULONG64 displacement); | 
|---|
| 209 |  | 
|---|
| 210 | HRESULT GetSourceFileLineOffsets( | 
|---|
| 211 | PCSTR file, | 
|---|
| 212 | PULONG64 buffer, | 
|---|
| 213 | ULONG bufferLines, | 
|---|
| 214 | PULONG fileLines); | 
|---|
| 215 |  | 
|---|
| 216 | HRESULT FindSourceFile( | 
|---|
| 217 | ULONG startElement, | 
|---|
| 218 | PCSTR file, | 
|---|
| 219 | ULONG flags, | 
|---|
| 220 | PULONG foundElement, | 
|---|
| 221 | PSTR buffer, | 
|---|
| 222 | ULONG bufferSize, | 
|---|
| 223 | PULONG foundSize); | 
|---|
| 224 |  | 
|---|
| 225 | //---------------------------------------------------------------------------- | 
|---|
| 226 | // IDebugSystemObjects | 
|---|
| 227 | //---------------------------------------------------------------------------- | 
|---|
| 228 |  | 
|---|
| 229 | HRESULT GetCurrentProcessId( | 
|---|
| 230 | PULONG id); | 
|---|
| 231 |  | 
|---|
| 232 | HRESULT GetCurrentThreadId( | 
|---|
| 233 | PULONG id); | 
|---|
| 234 |  | 
|---|
| 235 | HRESULT SetCurrentThreadId( | 
|---|
| 236 | ULONG id); | 
|---|
| 237 |  | 
|---|
| 238 | HRESULT GetCurrentThreadSystemId( | 
|---|
| 239 | PULONG sysId); | 
|---|
| 240 |  | 
|---|
| 241 | HRESULT GetThreadIdBySystemId( | 
|---|
| 242 | ULONG sysId, | 
|---|
| 243 | PULONG threadId); | 
|---|
| 244 |  | 
|---|
| 245 | HRESULT GetThreadContextById( | 
|---|
| 246 | ULONG32 threadID, | 
|---|
| 247 | ULONG32 contextFlags, | 
|---|
| 248 | ULONG32 contextSize, | 
|---|
| 249 | PBYTE context); | 
|---|
| 250 |  | 
|---|
| 251 | //---------------------------------------------------------------------------- | 
|---|
| 252 | // IDebugRegisters | 
|---|
| 253 | //---------------------------------------------------------------------------- | 
|---|
| 254 |  | 
|---|
| 255 | HRESULT GetValueByName( | 
|---|
| 256 | PCSTR name, | 
|---|
| 257 | PDWORD_PTR debugValue); | 
|---|
| 258 |  | 
|---|
| 259 | HRESULT GetInstructionOffset( | 
|---|
| 260 | PULONG64 offset); | 
|---|
| 261 |  | 
|---|
| 262 | HRESULT GetStackOffset( | 
|---|
| 263 | PULONG64 offset); | 
|---|
| 264 |  | 
|---|
| 265 | HRESULT GetFrameOffset( | 
|---|
| 266 | PULONG64 offset); | 
|---|
| 267 |  | 
|---|
| 268 | //---------------------------------------------------------------------------- | 
|---|
| 269 | // LLDBServices (internal) | 
|---|
| 270 | //---------------------------------------------------------------------------- | 
|---|
| 271 |  | 
|---|
| 272 | PCSTR GetModuleDirectory( | 
|---|
| 273 | PCSTR name); | 
|---|
| 274 | }; | 
|---|
| 275 |  | 
|---|