| 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 "sosplugin.h" |
| 6 | #include <dlfcn.h> |
| 7 | #include <string.h> |
| 8 | #include <string> |
| 9 | #include <stdlib.h> |
| 10 | #include <limits.h> |
| 11 | |
| 12 | class setsostidCommand : public lldb::SBCommandPluginInterface |
| 13 | { |
| 14 | public: |
| 15 | setsostidCommand() |
| 16 | { |
| 17 | } |
| 18 | |
| 19 | virtual bool |
| 20 | DoExecute(lldb::SBDebugger debugger, |
| 21 | char** arguments, |
| 22 | lldb::SBCommandReturnObject &result) |
| 23 | { |
| 24 | if (arguments[0] == NULL) |
| 25 | { |
| 26 | if (g_currentThreadSystemId == -1 || g_currentThreadIndex == -1) |
| 27 | { |
| 28 | result.Printf("sos OS tid not mapped\n" ); |
| 29 | } |
| 30 | else { |
| 31 | result.Printf("sos OS tid 0x%x mapped to lldb thread index %d\n" , |
| 32 | g_currentThreadSystemId, g_currentThreadIndex); |
| 33 | } |
| 34 | } |
| 35 | else if (strcmp(arguments[0], "-clear" ) == 0) { |
| 36 | g_currentThreadIndex = -1; |
| 37 | g_currentThreadSystemId = -1; |
| 38 | result.Printf("Cleared sos OS tid/index\n" ); |
| 39 | } |
| 40 | else if (arguments[1] == NULL) |
| 41 | { |
| 42 | result.Printf("Need thread index parameter that maps to the OS tid\n" ); |
| 43 | } |
| 44 | else |
| 45 | { |
| 46 | ULONG tid = strtoul(arguments[0], NULL, 16); |
| 47 | g_currentThreadSystemId = tid; |
| 48 | |
| 49 | ULONG index = strtoul(arguments[1], NULL, 16); |
| 50 | g_currentThreadIndex = index; |
| 51 | |
| 52 | result.Printf("Mapped sos OS tid 0x%x to lldb thread index %d\n" , tid, index); |
| 53 | } |
| 54 | return result.Succeeded(); |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | bool |
| 59 | setsostidCommandInitialize(lldb::SBDebugger debugger) |
| 60 | { |
| 61 | lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter(); |
| 62 | lldb::SBCommand command = interpreter.AddCommand("setsostid" , new setsostidCommand(), "Set the current os tid/thread index instead of using the one lldb provides. setsostid <tid> <index>" ); |
| 63 | return true; |
| 64 | } |
| 65 | |