├── .github ├── scripts │ └── clang-format.sh └── workflows │ └── ci.yml ├── .gitignore ├── CMakeLists.txt ├── LICENSE.TXT ├── README.md ├── src ├── CMakeLists.txt ├── MICmdArgContext.cpp ├── MICmdArgContext.h ├── MICmdArgSet.cpp ├── MICmdArgSet.h ├── MICmdArgValBase.cpp ├── MICmdArgValBase.h ├── MICmdArgValConsume.cpp ├── MICmdArgValConsume.h ├── MICmdArgValFile.cpp ├── MICmdArgValFile.h ├── MICmdArgValListBase.cpp ├── MICmdArgValListBase.h ├── MICmdArgValListOfN.cpp ├── MICmdArgValListOfN.h ├── MICmdArgValNumber.cpp ├── MICmdArgValNumber.h ├── MICmdArgValOptionLong.cpp ├── MICmdArgValOptionLong.h ├── MICmdArgValOptionShort.cpp ├── MICmdArgValOptionShort.h ├── MICmdArgValPrintValues.cpp ├── MICmdArgValPrintValues.h ├── MICmdArgValString.cpp ├── MICmdArgValString.h ├── MICmdArgValText.cpp ├── MICmdArgValText.h ├── MICmdArgValThreadGrp.cpp ├── MICmdArgValThreadGrp.h ├── MICmdBase.cpp ├── MICmdBase.h ├── MICmdCmd.cpp ├── MICmdCmd.h ├── MICmdCmdBreak.cpp ├── MICmdCmdBreak.h ├── MICmdCmdData.cpp ├── MICmdCmdData.h ├── MICmdCmdEnviro.cpp ├── MICmdCmdEnviro.h ├── MICmdCmdExec.cpp ├── MICmdCmdExec.h ├── MICmdCmdFile.cpp ├── MICmdCmdFile.h ├── MICmdCmdGdbInfo.cpp ├── MICmdCmdGdbInfo.h ├── MICmdCmdGdbSet.cpp ├── MICmdCmdGdbSet.h ├── MICmdCmdGdbShow.cpp ├── MICmdCmdGdbShow.h ├── MICmdCmdGdbThread.cpp ├── MICmdCmdGdbThread.h ├── MICmdCmdMiscellanous.cpp ├── MICmdCmdMiscellanous.h ├── MICmdCmdStack.cpp ├── MICmdCmdStack.h ├── MICmdCmdSupportInfo.cpp ├── MICmdCmdSupportInfo.h ├── MICmdCmdSupportList.cpp ├── MICmdCmdSupportList.h ├── MICmdCmdSymbol.cpp ├── MICmdCmdSymbol.h ├── MICmdCmdTarget.cpp ├── MICmdCmdTarget.h ├── MICmdCmdThread.cpp ├── MICmdCmdThread.h ├── MICmdCmdTrace.cpp ├── MICmdCmdTrace.h ├── MICmdCmdVar.cpp ├── MICmdCmdVar.h ├── MICmdCommands.cpp ├── MICmdCommands.h ├── MICmdData.cpp ├── MICmdData.h ├── MICmdFactory.cpp ├── MICmdFactory.h ├── MICmdInterpreter.cpp ├── MICmdInterpreter.h ├── MICmdInvoker.cpp ├── MICmdInvoker.h ├── MICmdMgr.cpp ├── MICmdMgr.h ├── MICmdMgrSetCmdDeleteCallback.cpp ├── MICmdMgrSetCmdDeleteCallback.h ├── MICmnBase.cpp ├── MICmnBase.h ├── MICmnConfig.h ├── MICmnLLDBBroadcaster.cpp ├── MICmnLLDBBroadcaster.h ├── MICmnLLDBDebugSessionInfo.cpp ├── MICmnLLDBDebugSessionInfo.h ├── MICmnLLDBDebugSessionInfoVarObj.cpp ├── MICmnLLDBDebugSessionInfoVarObj.h ├── MICmnLLDBDebugger.cpp ├── MICmnLLDBDebugger.h ├── MICmnLLDBDebuggerHandleEvents.cpp ├── MICmnLLDBDebuggerHandleEvents.h ├── MICmnLLDBProxySBValue.cpp ├── MICmnLLDBProxySBValue.h ├── MICmnLLDBUtilSBValue.cpp ├── MICmnLLDBUtilSBValue.h ├── MICmnLog.cpp ├── MICmnLog.h ├── MICmnLogMediumFile.cpp ├── MICmnLogMediumFile.h ├── MICmnMIOutOfBandRecord.cpp ├── MICmnMIOutOfBandRecord.h ├── MICmnMIResultRecord.cpp ├── MICmnMIResultRecord.h ├── MICmnMIValue.cpp ├── MICmnMIValue.h ├── MICmnMIValueConst.cpp ├── MICmnMIValueConst.h ├── MICmnMIValueList.cpp ├── MICmnMIValueList.h ├── MICmnMIValueResult.cpp ├── MICmnMIValueResult.h ├── MICmnMIValueTuple.cpp ├── MICmnMIValueTuple.h ├── MICmnResources.cpp ├── MICmnResources.h ├── MICmnStreamStderr.cpp ├── MICmnStreamStderr.h ├── MICmnStreamStdin.cpp ├── MICmnStreamStdin.h ├── MICmnStreamStdout.cpp ├── MICmnStreamStdout.h ├── MICmnThreadMgrStd.cpp ├── MICmnThreadMgrStd.h ├── MIDataTypes.h ├── MIDriver.cpp ├── MIDriver.h ├── MIDriverBase.cpp ├── MIDriverBase.h ├── MIDriverMain.cpp ├── MIDriverMgr.cpp ├── MIDriverMgr.h ├── MIExtensions.txt ├── MIReadMe.txt ├── MIUtilDateTimeStd.cpp ├── MIUtilDateTimeStd.h ├── MIUtilDebug.cpp ├── MIUtilDebug.h ├── MIUtilFileStd.cpp ├── MIUtilFileStd.h ├── MIUtilMapIdToVariant.cpp ├── MIUtilMapIdToVariant.h ├── MIUtilSingletonBase.h ├── MIUtilSingletonHelper.h ├── MIUtilString.cpp ├── MIUtilString.h ├── MIUtilThreadBaseStd.cpp ├── MIUtilThreadBaseStd.h ├── MIUtilVariant.cpp ├── MIUtilVariant.h ├── Platform.h ├── lldb-Info.plist ├── lldb-mi.exports └── module.modulemap └── test ├── CMakeLists.txt └── unittests ├── CMakeLists.txt └── arguments ├── CMakeLists.txt └── TestMICmdArgValString.cpp /.github/scripts/clang-format.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | echo "Checking clang-format" 6 | find -name *.h -or -name *.cpp | xargs clang-format -i -style=llvm 7 | git diff --exit-code 8 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: LLDB-MI CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build_and_test: 7 | name: Build LLDB-MI and run the testsuite 8 | 9 | env: 10 | # CMake build type 11 | BUILD_TYPE: Release 12 | 13 | BUILD_PATH: "'${{github.workspace}}/build'" 14 | 15 | runs-on: ${{matrix.os}} 16 | strategy: 17 | matrix: 18 | os: [ubuntu-latest, macos-latest, windows-latest] 19 | 20 | steps: 21 | - name: Install Ninja, LLVM, Clang and LLDB (Ubuntu) 22 | run: | 23 | sudo apt-get install -y ninja-build clang-format clang libclang-dev liblldb-dev lldb llvm-dev llvm 24 | echo "LLVM_CONFIG_PATH=$(llvm-config --cmakedir)" >> $GITHUB_ENV 25 | if: matrix.os == 'ubuntu-latest' 26 | 27 | - name: Checkout sources 28 | uses: actions/checkout@v3 29 | 30 | - name: Check format (Ubuntu) 31 | run: ${{github.workspace}}/.github/scripts/clang-format.sh 32 | if: matrix.os == 'ubuntu-latest' 33 | 34 | - name: Install Ninja, LLVM, Clang and LLDB (Mac OS) 35 | run: | 36 | brew install ninja llvm 37 | echo "LLVM_CONFIG_PATH=$(brew --cellar llvm)/$(brew list --versions llvm | sed -E 's/llvm (.*)/\1/g')/lib/cmake/llvm" >> $GITHUB_ENV 38 | if: matrix.os == 'macos-latest' 39 | 40 | - name: Install Ninja (Windows) 41 | run: choco install -y --no-progress ninja 42 | if: matrix.os == 'windows-latest' 43 | 44 | - name: Download LLVM binaries (Windows) 45 | # Using not yet released feature 'check_artifacts'. 46 | uses: dawidd6/action-download-artifact@master 47 | with: 48 | workflow: ci.yml 49 | workflow_conclusion: success 50 | repo: sunshaoce/install-llvm 51 | # Get the last available artifact. 52 | check_artifacts: true 53 | if: matrix.os == 'windows-latest' 54 | 55 | # Required to find cl.exe 56 | - name: Setup devcmd (Windows) 57 | uses: ilammy/msvc-dev-cmd@v1 58 | with: 59 | arch: x86 60 | if: matrix.os == 'windows-latest' 61 | 62 | - name: Set up environment (Windows) 63 | run: | 64 | $LLVM_CONFIG_PATH = ("${{github.workspace}}").Replace("\", "/") + "/llvm-inst/lib/cmake/llvm" 65 | echo "LLVM_CONFIG_PATH='$LLVM_CONFIG_PATH'" >> $env:GITHUB_ENV 66 | 67 | $CC = (gcm "cl.exe" | select-object -ExpandProperty Definition) 68 | echo "CC='$CC'" >> $env:GITHUB_ENV 69 | echo "CXX='$CC'" >> $env:GITHUB_ENV 70 | if: matrix.os == 'windows-latest' 71 | 72 | - name: Configure CMake project 73 | run: | 74 | export LLVM_DIR=${{env.LLVM_CONFIG_PATH}} 75 | cmake -GNinja -B ${{env.BUILD_PATH}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DINCLUDE_TESTS=ON 76 | shell: bash 77 | 78 | - name: Build 79 | run: cmake --build ${{env.BUILD_PATH}} --config ${{env.BUILD_TYPE}} 80 | 81 | - name: Run testsuite 82 | run: | 83 | cd ${{env.BUILD_PATH}} 84 | ctest -V -C ${{env.BUILD_TYPE}} 85 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build*/ 2 | .vscode/ 3 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.20.0) 2 | 3 | if(POLICY CMP0077) 4 | cmake_policy(SET CMP0077 NEW) 5 | endif() 6 | 7 | project(lldb-mi) 8 | 9 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 10 | 11 | if (USE_LLDB_FRAMEWORK AND !APPLE) 12 | message(FATAL_ERROR "USE_LLDB_FRAMEWORK is only avaliable on Darwin") 13 | endif() 14 | 15 | find_package(LLVM REQUIRED CONFIG) 16 | 17 | message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") 18 | message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") 19 | 20 | list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR}) 21 | include(HandleLLVMStdlib) 22 | include(HandleLLVMOptions) 23 | 24 | include_directories(${LLVM_INCLUDE_DIRS}) 25 | if(LLVM_BUILD_MAIN_SRC_DIR) 26 | include_directories(${LLVM_BUILD_MAIN_SRC_DIR}/../lldb/include) 27 | include_directories(${LLVM_BUILD_BINARY_DIR}/tools/lldb/include) 28 | endif() 29 | 30 | separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS}) 31 | add_definitions(${LLVM_DEFINITIONS_LIST}) 32 | 33 | if (NOT LLVM_ENABLE_EH) 34 | if(LLVM_COMPILER_IS_GCC_COMPATIBLE) 35 | add_compile_options("-fno-exceptions") 36 | elseif(MSVC) 37 | add_compile_options("/EHs-c-") 38 | add_definitions("-D_HAS_EXCEPTIONS=0") 39 | endif() 40 | endif() 41 | 42 | if(MSVC) 43 | #Disable warning "multiple copy constructors specified". 44 | add_compile_options("/wd4521") 45 | endif() 46 | 47 | # https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling 48 | # use, i.e. don't skip, the full RPATH for the build tree 49 | SET(CMAKE_SKIP_BUILD_RPATH FALSE CACHE BOOL "") 50 | # when building, don't use the install RPATH already 51 | # (but later on when installing) 52 | SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE CACHE BOOL "") 53 | SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "") 54 | # add the automatically determined parts of the RPATH 55 | # which point to directories outside the build tree to the install RPATH 56 | SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "") 57 | # the RPATH to be used when installing, but only if it's not a system directory 58 | LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) 59 | IF("${isSystemDir}" STREQUAL "-1") 60 | SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "") 61 | ENDIF("${isSystemDir}" STREQUAL "-1") 62 | 63 | add_subdirectory(src) 64 | 65 | SET(INCLUDE_TESTS CACHE BOOL FALSE) 66 | if (INCLUDE_TESTS AND WIN32) 67 | message(WARNING "Not supported on Windows due to a bug: https://gitlab.kitware.com/cmake/cmake/-/issues/22659. Testing will be disabled.") 68 | SET(INCLUDE_TESTS FALSE) 69 | endif() 70 | 71 | if (INCLUDE_TESTS) 72 | include(CTest) 73 | add_subdirectory(test) 74 | endif() 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lldb-mi 2 | 3 | LLDB's machine interface driver. 4 | 5 | # Build 6 | 7 | lldb-mi uses CMake to build. The only dependencies needed for lldb-mi are a C++17 (since LLVM 16) compiler and LLDB itself (including its dependencies: Clang and LLVM). These dependencies should be installed in a way that they can be found via CMake's [`find_package`](https://cmake.org/cmake/help/latest/command/find_package.html) functionality. You need both the LLDB/Clang/LLVM headers and their compiled libraries for the build to work, but not the respective source files. 8 | 9 | # Building against system LLDB 10 | 11 | If your distribution or operating system already ships a correctly configured LLDB/Clang/LLVM installation, lldb-mi can be built by simply running: 12 | 13 | 14 | ```bash 15 | cmake . 16 | cmake --build . 17 | ``` 18 | 19 | # Building against custom LLDB 20 | 21 | You can also build lldb-mi against a LLDB that you compiled yourself. For that, compile LLDB as described [here](https://lldb.llvm.org/resources/build.html) but set `CMAKE_INSTALL_PREFIX` to a local directory and build the LLVM shared library by passing `-DLLVM_BUILD_LLVM_DYLIB=On` to CMake. Afterwards point towards that prefix directory when building lldb-mi by setting `CMAKE_PREFIX_PATH` (e.g. `cmake -DCMAKE_PREFIX_PATH=/home/yourname/lldb-mi/install`). 22 | 23 | This example script should build LLVM and lldb-mi on an average UNIX system in the `~/buildspace` subfolder: 24 | ``` 25 | cd 26 | mkdir buildspace 27 | 28 | # Download LLVM/Clang/LLDB and build them. 29 | git clone https://github.com/llvm/llvm-project.git 30 | mkdir llvm-inst 31 | mkdir llvm-build 32 | cd llvm-build 33 | 34 | cmake -DLLVM_ENABLE_PROJECTS="clang;lldb" -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" -DCMAKE_INSTALL_PREFIX=~/buildspace/llvm-inst/ -GNinja ../llvm-project/llvm 35 | ninja 36 | ninja install 37 | 38 | # Download lldb-mi and build it against our custom installation. 39 | cd ~/buildspace 40 | git clone https://github.com/lldb-tools/lldb-mi 41 | cd lldb-mi 42 | 43 | # Create a separate build directory for building lldb-mi. 44 | mkdir build 45 | cd build 46 | cmake -DCMAKE_PREFIX_PATH=~/buildspace/llvm-inst/ -GNinja .. 47 | ninja 48 | ``` 49 | 50 | # Building against custom LLDB.framework (Darwin Only) 51 | 52 | You can also build lldb-mi against a LLDB.framework that you compiled yourself. You follow the same instructions as above but build the LLVM framework by passing `-DLLDB_BUILD_FRAMEWORK=1` to CMake instead of using the shared library. Then build lldb-mi with `-DUSE_LLDB_FRAMEWORK=1` 53 | 54 | The snippets below change the CMake calls from the above script. 55 | ``` 56 | // Building llvm-project 57 | cmake -DLLVM_ENABLE_PROJECTS="clang;lldb;libcxx;libcxxabi" -DCMAKE_INSTALL_PREFIX=~/buildspace/llvm-inst/ -DLLDB_BUILD_FRAMEWORK=1 -GNinja ../llvm-project/llvm 58 | ``` 59 | 60 | ``` 61 | // Building lldb-mi 62 | cmake -DCMAKE_PREFIX_PATH=~/buildspace/llvm-inst/ -DUSE_LLDB_FRAMEWORK=1 -GNinja .. 63 | 64 | ``` 65 | 66 | # Notes 67 | 68 | On some architectures (e.g. Linux, x86-64), LLDB dynamic library fails to determine its location. That results in the inability to locate a gdbserver stub: 69 | ```bash 70 | process launch failed: unable to locate lldb-server 71 | ``` 72 | 73 | The workaround is to set `LLDB_DEBUGSERVER_PATH` environment variable before running lldb-mi. 74 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(lldb-mi 2 | MICmdArgContext.cpp 3 | MICmdArgSet.cpp 4 | MICmdArgValBase.cpp 5 | MICmdArgValConsume.cpp 6 | MICmdArgValFile.cpp 7 | MICmdArgValListBase.cpp 8 | MICmdArgValListOfN.cpp 9 | MICmdArgValNumber.cpp 10 | MICmdArgValOptionLong.cpp 11 | MICmdArgValOptionShort.cpp 12 | MICmdArgValPrintValues.cpp 13 | MICmdArgValString.cpp 14 | MICmdArgValText.cpp 15 | MICmdArgValThreadGrp.cpp 16 | MICmdBase.cpp 17 | MICmdCommands.cpp 18 | MICmdCmd.cpp 19 | MICmdCmdBreak.cpp 20 | MICmdCmdData.cpp 21 | MICmdCmdEnviro.cpp 22 | MICmdCmdExec.cpp 23 | MICmdCmdFile.cpp 24 | MICmdCmdGdbInfo.cpp 25 | MICmdCmdGdbSet.cpp 26 | MICmdCmdGdbShow.cpp 27 | MICmdCmdGdbThread.cpp 28 | MICmdCmdMiscellanous.cpp 29 | MICmdCmdStack.cpp 30 | MICmdCmdSupportInfo.cpp 31 | MICmdCmdSupportList.cpp 32 | MICmdCmdSymbol.cpp 33 | MICmdCmdTarget.cpp 34 | MICmdCmdThread.cpp 35 | MICmdCmdTrace.cpp 36 | MICmdCmdVar.cpp 37 | MICmdData.cpp 38 | MICmdFactory.cpp 39 | MICmdInterpreter.cpp 40 | MICmdInvoker.cpp 41 | MICmdMgr.cpp 42 | MICmdMgrSetCmdDeleteCallback.cpp 43 | MICmnBase.cpp 44 | MICmnLLDBBroadcaster.cpp 45 | MICmnLLDBDebugger.cpp 46 | MICmnLLDBDebuggerHandleEvents.cpp 47 | MICmnLLDBDebugSessionInfo.cpp 48 | MICmnLLDBDebugSessionInfoVarObj.cpp 49 | MICmnLLDBProxySBValue.cpp 50 | MICmnLLDBUtilSBValue.cpp 51 | MICmnLog.cpp 52 | MICmnLogMediumFile.cpp 53 | MICmnMIOutOfBandRecord.cpp 54 | MICmnMIResultRecord.cpp 55 | MICmnMIValue.cpp 56 | MICmnMIValueConst.cpp 57 | MICmnMIValueList.cpp 58 | MICmnMIValueResult.cpp 59 | MICmnMIValueTuple.cpp 60 | MICmnResources.cpp 61 | MICmnStreamStderr.cpp 62 | MICmnStreamStdin.cpp 63 | MICmnStreamStdout.cpp 64 | MICmnThreadMgrStd.cpp 65 | MIDriver.cpp 66 | MIDriverBase.cpp 67 | MIDriverMain.cpp 68 | MIDriverMgr.cpp 69 | MIUtilDateTimeStd.cpp 70 | MIUtilDebug.cpp 71 | MIUtilFileStd.cpp 72 | MIUtilMapIdToVariant.cpp 73 | MIUtilString.cpp 74 | MIUtilThreadBaseStd.cpp 75 | MIUtilVariant.cpp 76 | ) 77 | 78 | set(llvm_deps "") 79 | 80 | set_property(TARGET lldb-mi PROPERTY CXX_STANDARD 17) 81 | 82 | if (USE_LLDB_FRAMEWORK) 83 | find_library(lib_lldb NAMES LLDB PATHS ${LLVM_BINARY_DIR}/Library/Frameworks) 84 | else() 85 | find_library(lib_lldb NAMES lldb liblldb HINTS ${LLVM_LIBRARY_DIRS}) 86 | endif() 87 | 88 | find_library(lib_llvm_shared LLVM HINTS ${LLVM_LIBRARY_DIRS}) 89 | 90 | if (lib_llvm_shared) 91 | set(lib_llvm "${lib_llvm_shared}") 92 | else() 93 | message(STATUS "Can't find LLVM shared library, falling back to static linking LLVMSupport") 94 | llvm_map_components_to_libnames(lib_llvm support) 95 | 96 | if (LLVM_ENABLE_TERMINFO AND NOT WIN32) 97 | find_library(TERMINFO_LIB NAMES terminfo tinfo curses ncurses ncursesw) 98 | if (TERMINFO_LIB) 99 | list(APPEND llvm_deps "${TERMINFO_LIB}") 100 | endif() 101 | endif() 102 | endif() 103 | 104 | list(APPEND llvm_deps "${LLVM_PTHREAD_LIB}") 105 | 106 | target_link_libraries(lldb-mi ${lib_lldb} ${lib_llvm} ${llvm_deps}) 107 | install(TARGETS lldb-mi 108 | RUNTIME DESTINATION bin) 109 | -------------------------------------------------------------------------------- /src/MICmdArgContext.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgContext.h ---------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MIUtilString.h" 13 | 14 | //++ 15 | //============================================================================ 16 | // Details: MI common code class. Command arguments and options string. Holds 17 | // the context string. 18 | // Based on the Interpreter pattern. 19 | //-- 20 | class CMICmdArgContext { 21 | // Methods: 22 | public: 23 | /* ctor */ CMICmdArgContext(); 24 | /* ctor */ CMICmdArgContext(const CMIUtilString &vrCmdLineArgsRaw); 25 | // 26 | const CMIUtilString &GetArgsLeftToParse() const; 27 | size_t GetNumberArgsPresent() const; 28 | CMIUtilString::VecString_t GetArgs() const; 29 | bool IsEmpty() const; 30 | bool RemoveArg(const CMIUtilString &vArg); 31 | bool RemoveArgAtPos(const CMIUtilString &vArg, size_t nArgIndex); 32 | // 33 | CMICmdArgContext &operator=(const CMICmdArgContext &vOther); 34 | 35 | // Overridden: 36 | public: 37 | // From CMIUtilString 38 | /* dtor */ virtual ~CMICmdArgContext(); 39 | 40 | // Attributes: 41 | private: 42 | CMIUtilString m_strCmdArgsAndOptions; 43 | }; 44 | -------------------------------------------------------------------------------- /src/MICmdArgValBase.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgValBase.cpp -------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #include "MICmdArgValBase.h" 10 | #include "MICmdArgContext.h" 11 | #include "MIUtilString.h" 12 | 13 | //++ 14 | // Details: CMICmdArgValBase constructor. 15 | // Type: Method. 16 | // Args: None. 17 | // Return: None. 18 | // Throws: None. 19 | //-- 20 | CMICmdArgValBase::CMICmdArgValBase() 21 | : m_bFound(false), m_bValid(false), m_bMandatory(false), m_bHandled(false), 22 | m_bIsMissingOptions(false) {} 23 | 24 | //++ 25 | // Details: CMICmdArgValBase constructor. 26 | // Type: Method. 27 | // Args: vrArgName - (R) Argument's name to search by. 28 | // vbMandatory - (R) True = Yes must be present, false = optional 29 | // argument. 30 | // vbHandleByCmd - (R) True = Command processes *this option, false = 31 | // not handled. 32 | // Return: None. 33 | // Throws: None. 34 | //-- 35 | CMICmdArgValBase::CMICmdArgValBase(const CMIUtilString &vrArgName, 36 | const bool vbMandatory, 37 | const bool vbHandleByCmd) 38 | : m_bFound(false), m_bValid(false), m_bMandatory(vbMandatory), 39 | m_strArgName(vrArgName), m_bHandled(vbHandleByCmd), 40 | m_bIsMissingOptions(false) {} 41 | 42 | //++ 43 | // Details: Retrieve the state flag of whether the argument is handled by the 44 | // command or 45 | // not. 46 | // Type: Method. 47 | // Args: None. 48 | // Return: True - Command needs more information. 49 | // False - All information is present as expected. 50 | // Throws: None. 51 | //-- 52 | bool CMICmdArgValBase::GetIsMissingOptions() const { 53 | return m_bIsMissingOptions; 54 | } 55 | 56 | //++ 57 | // Details: Retrieve the state flag of whether the argument is handled by the 58 | // command or 59 | // not. 60 | // Type: Method. 61 | // Args: None. 62 | // Return: True - Command handles *this argument or option. 63 | // False - Not handled (argument specified but ignored). 64 | // Throws: None. 65 | //-- 66 | bool CMICmdArgValBase::GetIsHandledByCmd() const { return m_bHandled; } 67 | 68 | //++ 69 | // Details: Retrieve the name of *this argument. 70 | // Type: Method. 71 | // Args: None. 72 | // Return: CMIUtilString & - Return the text name. 73 | // Throws: None. 74 | //-- 75 | const CMIUtilString &CMICmdArgValBase::GetName() const { return m_strArgName; } 76 | 77 | //++ 78 | // Details: Retrieve the state flag of whether the argument was found in the 79 | // command's 80 | // argument / options string. 81 | // Type: Method. 82 | // Args: None. 83 | // Return: True - Argument found. 84 | // False - Argument not found. 85 | // Throws: None. 86 | //-- 87 | bool CMICmdArgValBase::GetFound() const { return m_bFound; } 88 | 89 | //++ 90 | // Details: Retrieve the state flag indicating whether the value was obtained 91 | // from the 92 | // text arguments string and is valid. 93 | // Type: Method. 94 | // Args: None. 95 | // Return: True - Argument valid. 96 | // False - Argument not valid. 97 | // Throws: None. 98 | //-- 99 | bool CMICmdArgValBase::GetValid() const { return m_bValid; } 100 | 101 | //++ 102 | // Details: Retrieve the state flag indicating whether *this argument is a 103 | // mandatory 104 | // argument for the command or is optional to be present. 105 | // Type: Method. 106 | // Args: None. 107 | // Return: True - Mandatory. 108 | // False - Optional. 109 | // Throws: None. 110 | //-- 111 | bool CMICmdArgValBase::GetIsMandatory() const { return m_bMandatory; } 112 | 113 | //++ 114 | // Details: Parse the command's argument options string and try to extract the 115 | // value *this 116 | // argument is looking for. 117 | // Type: Overrideable. 118 | // Args: vArgContext - (RW) The command's argument options string. 119 | // Return: MIstatus::success - Functional succeeded. 120 | // MIstatus::failure - Functional failed. 121 | // Throws: None. 122 | //-- 123 | bool CMICmdArgValBase::Validate(CMICmdArgContext &vwArgContext) { 124 | MIunused(vwArgContext); 125 | 126 | // Override to implement 127 | 128 | return MIstatus::failure; 129 | } 130 | -------------------------------------------------------------------------------- /src/MICmdArgValConsume.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgValConsume.cpp ----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // In-house headers: 10 | #include "MICmdArgValConsume.h" 11 | #include "MICmdArgContext.h" 12 | 13 | //++ 14 | // Details: CMICmdArgValConsume constructor. 15 | // Type: Method. 16 | // Args: None. 17 | // Return: None. 18 | // Throws: None. 19 | //-- 20 | CMICmdArgValConsume::CMICmdArgValConsume() {} 21 | 22 | //++ 23 | // Details: CMICmdArgValConsume constructor. 24 | // Type: Method. 25 | // Args: vrArgName - (R) Argument's name to search by. 26 | // vbMandatory - (R) True = Yes must be present, false = optional 27 | // argument. 28 | // Return: None. 29 | // Throws: None. 30 | //-- 31 | CMICmdArgValConsume::CMICmdArgValConsume(const CMIUtilString &vrArgName, 32 | const bool vbMandatory) 33 | : CMICmdArgValBaseTemplate(vrArgName, vbMandatory, true) {} 34 | 35 | //++ 36 | // Details: CMICmdArgValConsume destructor. 37 | // Type: Overidden. 38 | // Args: None. 39 | // Return: None. 40 | // Throws: None. 41 | //-- 42 | CMICmdArgValConsume::~CMICmdArgValConsume() {} 43 | 44 | //++ 45 | // Details: Parse the command's argument options string and try to extract the 46 | // value *this 47 | // argument is looking for. 48 | // Type: Overridden. 49 | // Args: vwArgContext - (R) The command's argument options string. 50 | // Return: MIstatus::success - Functional succeeded. 51 | // MIstatus::failure - Functional failed. 52 | // Throws: None. 53 | //-- 54 | bool CMICmdArgValConsume::Validate(CMICmdArgContext &vwArgContext) { 55 | if (vwArgContext.IsEmpty()) 56 | return m_bMandatory ? MIstatus::failure : MIstatus::success; 57 | 58 | // Consume the optional file, line, linenum arguments till the mode '--' 59 | // argument 60 | const CMIUtilString::VecString_t vecOptions(vwArgContext.GetArgs()); 61 | CMIUtilString::VecString_t::const_iterator it = vecOptions.begin(); 62 | while (it != vecOptions.end()) { 63 | const CMIUtilString &rTxt(*it); 64 | 65 | if (rTxt == "--") { 66 | m_bFound = true; 67 | m_bValid = true; 68 | if (!vwArgContext.RemoveArg(rTxt)) 69 | return MIstatus::failure; 70 | return MIstatus::success; 71 | } 72 | // Next 73 | ++it; 74 | } 75 | 76 | return MIstatus::failure; 77 | } 78 | 79 | //++ 80 | // Details: Nothing to examine as we just want to consume the argument or option 81 | // (ignore 82 | // it). 83 | // Type: Method. 84 | // Args: None. 85 | // Return: bool - True = yes ok, false = not ok. 86 | // Throws: None. 87 | //-- 88 | bool CMICmdArgValConsume::IsOk() const { return true; } 89 | -------------------------------------------------------------------------------- /src/MICmdArgValConsume.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgValConsume.h ------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmdArgValBase.h" 13 | 14 | // Declarations: 15 | class CMICmdArgContext; 16 | 17 | //++ 18 | //============================================================================ 19 | // Details: MI common code class. Command argument class. Arguments object 20 | // needing specialization derived from the CMICmdArgValBase class. 21 | // An argument knows what type of argument it is and how it is to 22 | // interpret the options (context) string to find and validate a 23 | // matching 24 | // argument. This type having recognised its argument name just 25 | // consumes 26 | // that argument or option (ignores it). This is the so the validation 27 | // process can then ask if all arguments or options have been 28 | // recognised 29 | // other an error will occurred "argument not recognised". For example 30 | // this can be used to consume the "--" text which is not an argument 31 | // in 32 | // itself. Normally the GetValue() function (in base class) would 33 | // return 34 | // a value for the argument but is not the case for *this argument type 35 | // object. 36 | // Based on the Interpreter pattern. 37 | //-- 38 | class CMICmdArgValConsume : public CMICmdArgValBaseTemplate { 39 | // Methods: 40 | public: 41 | /* ctor */ CMICmdArgValConsume(); 42 | /* ctor */ CMICmdArgValConsume(const CMIUtilString &vrArgName, 43 | const bool vbMandatory); 44 | // 45 | bool IsOk() const; 46 | 47 | // Overridden: 48 | public: 49 | // From CMICmdArgValBase 50 | /* dtor */ ~CMICmdArgValConsume() override; 51 | // From CMICmdArgSet::IArg 52 | bool Validate(CMICmdArgContext &vwArgContext) override; 53 | }; 54 | -------------------------------------------------------------------------------- /src/MICmdArgValFile.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgValFile.h ---------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmdArgValBase.h" 13 | 14 | // Declarations: 15 | class CMICmdArgContext; 16 | 17 | //++ 18 | //============================================================================ 19 | // Details: MI common code class. Command argument class. Arguments object 20 | // needing specialization derived from the CMICmdArgValBase class. 21 | // An argument knows what type of argument it is and how it is to 22 | // interpret the options (context) string to find and validate a 23 | // matching 24 | // argument and so extract a value from it . 25 | // Based on the Interpreter pattern. 26 | //-- 27 | class CMICmdArgValFile : public CMICmdArgValBaseTemplate { 28 | // Methods: 29 | public: 30 | /* ctor */ CMICmdArgValFile(); 31 | /* ctor */ CMICmdArgValFile(const CMIUtilString &vrArgName, 32 | const bool vbMandatory, const bool vbHandleByCmd); 33 | // 34 | bool IsFilePath(const CMIUtilString &vrFileNamePath) const; 35 | CMIUtilString GetFileNamePath(const CMIUtilString &vrTxt) const; 36 | 37 | // Overridden: 38 | public: 39 | // From CMICmdArgValBase 40 | /* dtor */ ~CMICmdArgValFile() override; 41 | // From CMICmdArgSet::IArg 42 | bool Validate(CMICmdArgContext &vwArgContext) override; 43 | 44 | // Methods: 45 | private: 46 | bool IsValidChars(const CMIUtilString &vrText) const; 47 | }; 48 | -------------------------------------------------------------------------------- /src/MICmdArgValListBase.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgValListBase.h -----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // Third party headers: 12 | #include 13 | 14 | // In-house headers: 15 | #include "MICmdArgValBase.h" 16 | 17 | // Declarations: 18 | class CMICmdArgContext; 19 | 20 | //++ 21 | //============================================================================ 22 | // Details: MI common code class. Command argument with addition options class. 23 | // For example --recurse 1 2 4 [group ...]. Arguments object that 24 | // require a list of options associated with them derive from the 25 | // CMICmdArgValListBase class. Additional options are also extracted 26 | // from 27 | // the command arguments text string. 28 | // An argument knows what type of argument it is and how it is to 29 | // interpret the options (context) string to find and validate a 30 | // matching 31 | // options and so extract a values from it . 32 | // The CMICmdArgValBase objects are added to the derived argument 33 | // class's 34 | // container. The option arguments belong to that derived class and 35 | // will 36 | // be deleted that object goes out of scope. 37 | // Based on the Interpreter pattern. 38 | //-- 39 | class CMICmdArgValListBase 40 | : public CMICmdArgValBaseTemplate> { 41 | // Typedef: 42 | public: 43 | typedef std::vector VecArgObjPtr_t; 44 | 45 | // Enums: 46 | public: 47 | //++ 48 | // Details: CMICmdArgValListBase needs to know what type of argument to look 49 | // for in 50 | // the command options text. It also needs to create argument objects 51 | // of 52 | // a specific type. 53 | //-- 54 | enum ArgValType_e { 55 | eArgValType_File = 0, 56 | eArgValType_Consume, 57 | eArgValType_Number, 58 | eArgValType_OptionLong, 59 | eArgValType_OptionShort, 60 | eArgValType_String, 61 | eArgValType_StringQuoted, 62 | eArgValType_StringQuotedNumber, 63 | eArgValType_StringQuotedNumberPath, 64 | eArgValType_StringAnything, // Accept any words for a string 'type' even if 65 | // they look like --longOptions for example 66 | eArgValType_ThreadGrp, 67 | eArgValType_count, // Always the last one 68 | eArgValType_invalid 69 | }; 70 | 71 | // Methods: 72 | public: 73 | /* ctor */ CMICmdArgValListBase(); 74 | /* ctor */ CMICmdArgValListBase(const CMIUtilString &vrArgName, 75 | const bool vbMandatory, 76 | const bool vbHandleByCmd); 77 | /* ctor */ CMICmdArgValListBase(const CMIUtilString &vrArgName, 78 | const bool vbMandatory, 79 | const bool vbHandleByCmd, 80 | const ArgValType_e veType); 81 | 82 | // Overridden: 83 | public: 84 | // From CMICmdArgValBase 85 | /* dtor */ ~CMICmdArgValListBase() override; 86 | 87 | // Methods: 88 | protected: 89 | bool IsExpectedCorrectType(const CMIUtilString &vrTxt, 90 | const ArgValType_e veType) const; 91 | CMICmdArgValBase *CreationObj(const CMIUtilString &vrTxt, 92 | const ArgValType_e veType) const; 93 | 94 | // Attributes: 95 | protected: 96 | ArgValType_e m_eArgType; 97 | 98 | // Methods: 99 | private: 100 | void Destroy(); 101 | }; 102 | -------------------------------------------------------------------------------- /src/MICmdArgValListOfN.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgValListOfN.h ------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // Third party headers: 12 | #include 13 | 14 | // In-house headers: 15 | #include "MICmdArgValListBase.h" 16 | 17 | // Declarations: 18 | class CMICmdArgContext; 19 | 20 | //++ 21 | //============================================================================ 22 | // Details: MI common code class. Command argument class. Arguments object 23 | // needing specialization derived from the CMICmdArgValBase class. 24 | // An argument knows what type of argument it is and how it is to 25 | // interpret the options (context) string to find and validate a 26 | // matching 27 | // argument and so extract a value from it . 28 | // The CMICmdArgValBase objects added to *this ListOfN container belong 29 | // to this container and will be deleted when *this object goes out of 30 | // scope. 31 | // To parse arguments like 'thread-id ...' i.e. 1 10 12 13 ... 32 | // If vbMandatory argument is true it takes on the (...)+ specification 33 | // otherwise assumed to be (...)* specification. 34 | // Based on the Interpreter pattern. 35 | //-- 36 | class CMICmdArgValListOfN : public CMICmdArgValListBase { 37 | // Methods: 38 | public: 39 | /* ctor */ CMICmdArgValListOfN(); 40 | /* ctor */ CMICmdArgValListOfN(const CMIUtilString &vrArgName, 41 | const bool vbMandatory, 42 | const bool vbHandleByCmd, 43 | const ArgValType_e veType); 44 | // 45 | const VecArgObjPtr_t &GetExpectedOptions() const; 46 | template 47 | bool GetExpectedOption(T2 &vrwValue, 48 | const VecArgObjPtr_t::size_type vnAt = 0) const; 49 | 50 | // Overridden: 51 | public: 52 | // From CMICmdArgValBase 53 | /* dtor */ ~CMICmdArgValListOfN() override; 54 | // From CMICmdArgSet::IArg 55 | bool Validate(CMICmdArgContext &vArgContext) override; 56 | 57 | // Methods: 58 | private: 59 | bool IsListOfN(const CMIUtilString &vrTxt) const; 60 | bool CreateList(const CMIUtilString &vrTxt); 61 | }; 62 | 63 | //++ 64 | // Details: Retrieve the first argument or option value from the list of 1 or 65 | // more options 66 | // parsed from the command's options string. 67 | // Type: Template method. 68 | // Args: vrwValue - (W) Templated type return value. 69 | // vnAt - (R) Value at the specific position. 70 | // T1 - The argument value's class type of the data hold in 71 | // the list of options. 72 | // T2 - The type pf the variable which holds the value wanted. 73 | // Return: MIstatus::success - Functional succeeded. 74 | // MIstatus::failure - Functional failed. List of object was empty. 75 | // Throws: None. 76 | //-- 77 | template 78 | bool CMICmdArgValListOfN::GetExpectedOption( 79 | T2 &vrwValue, const VecArgObjPtr_t::size_type vnAt) const { 80 | const VecArgObjPtr_t &rVecOptions(GetExpectedOptions()); 81 | if (rVecOptions.size() <= vnAt) 82 | return MIstatus::failure; 83 | 84 | VecArgObjPtr_t::const_iterator it2 = rVecOptions.begin() + vnAt; 85 | if (it2 != rVecOptions.end()) { 86 | const T1 *pOption = static_cast(*it2); 87 | vrwValue = pOption->GetValue(); 88 | return MIstatus::success; 89 | } 90 | 91 | return MIstatus::failure; 92 | } 93 | -------------------------------------------------------------------------------- /src/MICmdArgValNumber.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgValNumber.h -------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmdArgValBase.h" 13 | 14 | // Declarations: 15 | class CMICmdArgContext; 16 | 17 | //++ 18 | //============================================================================ 19 | // Details: MI common code class. Command argument class. Arguments object 20 | // needing specialization derived from the CMICmdArgValBase class. 21 | // An argument knows what type of argument it is and how it is to 22 | // interpret the options (context) string to find and validate a 23 | // matching 24 | // argument and so extract a value from it . 25 | // Based on the Interpreter pattern. 26 | //-- 27 | class CMICmdArgValNumber : public CMICmdArgValBaseTemplate { 28 | // Enums: 29 | public: 30 | //++ 31 | // Details: CMICmdArgValNumber needs to know what format of argument to look 32 | // for in 33 | // the command options text. 34 | //-- 35 | enum ArgValNumberFormat_e { 36 | eArgValNumberFormat_Decimal = (1u << 0), 37 | eArgValNumberFormat_Hexadecimal = (1u << 1), 38 | eArgValNumberFormat_Auto = 39 | ((eArgValNumberFormat_Hexadecimal << 1) - 40 | 1u) ///< Indicates to try and lookup everything up during a query. 41 | }; 42 | 43 | // Methods: 44 | public: 45 | /* ctor */ CMICmdArgValNumber(); 46 | /* ctor */ CMICmdArgValNumber( 47 | const CMIUtilString &vrArgName, const bool vbMandatory, 48 | const bool vbHandleByCmd, 49 | const MIuint vnNumberFormatMask = eArgValNumberFormat_Decimal); 50 | // 51 | bool IsArgNumber(const CMIUtilString &vrTxt) const; 52 | 53 | // Overridden: 54 | public: 55 | // From CMICmdArgValBase 56 | /* dtor */ ~CMICmdArgValNumber() override; 57 | // From CMICmdArgSet::IArg 58 | bool Validate(CMICmdArgContext &vwArgContext) override; 59 | 60 | // Methods: 61 | private: 62 | bool ExtractNumber(const CMIUtilString &vrTxt); 63 | MIint64 GetNumber() const; 64 | 65 | // Attributes: 66 | private: 67 | MIuint m_nNumberFormatMask; 68 | MIint64 m_nNumber; 69 | }; 70 | -------------------------------------------------------------------------------- /src/MICmdArgValOptionLong.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgValOptionLong.h ---------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmdArgValListBase.h" 13 | 14 | // Declarations: 15 | class CMICmdArgContext; 16 | class CMIUtilString; 17 | 18 | //++ 19 | //============================================================================ 20 | // Details: MI common code class. Command argument class. Arguments object 21 | // needing specialization derived from the CMICmdArgValBase class. 22 | // An argument knows what type of argument it is and how it is to 23 | // interpret the options (context) string to find and validate a 24 | // matching 25 | // argument and so extract a value from it. 26 | // If *this argument has expected options following it the option 27 | // objects 28 | // created to hold each of those option's values belong to *this 29 | // argument 30 | // object and so are deleted when *this object goes out of scope. 31 | // Based on the Interpreter pattern. 32 | //-- 33 | class CMICmdArgValOptionLong : public CMICmdArgValListBase { 34 | // Methods: 35 | public: 36 | /* ctor */ CMICmdArgValOptionLong(); 37 | /* ctor */ CMICmdArgValOptionLong(const CMIUtilString &vrArgName, 38 | const bool vbMandatory, 39 | const bool vbHandleByCmd); 40 | /* ctor */ CMICmdArgValOptionLong(const CMIUtilString &vrArgName, 41 | const bool vbMandatory, 42 | const bool vbHandleByCmd, 43 | const ArgValType_e veType, 44 | const MIuint vnExpectingNOptions); 45 | // 46 | bool IsArgLongOption(const CMIUtilString &vrTxt) const; 47 | const VecArgObjPtr_t &GetExpectedOptions() const; 48 | template bool GetExpectedOption(T2 &vrwValue) const; 49 | 50 | // Overridden: 51 | public: 52 | // From CMICmdArgValBase 53 | /* dtor */ ~CMICmdArgValOptionLong() override; 54 | // From CMICmdArgSet::IArg 55 | bool Validate(CMICmdArgContext &vArgContext) override; 56 | 57 | // Methods: 58 | protected: 59 | bool ExtractExpectedOptions(CMICmdArgContext &vrwTxt, const MIuint nArgIndex); 60 | 61 | // Overrideable: 62 | protected: 63 | virtual bool IsArgOptionCorrect(const CMIUtilString &vrTxt) const; 64 | virtual bool ArgNameMatch(const CMIUtilString &vrTxt) const; 65 | 66 | // Methods: 67 | private: 68 | void Destroy(); 69 | 70 | // Attributes: 71 | private: 72 | MIuint m_nExpectingNOptions; // The number of options expected to read 73 | // following *this argument 74 | VecArgObjPtr_t m_vecArgsExpected; // The option objects holding the value 75 | // extracted following *this argument 76 | ArgValType_e m_eExpectingOptionType; // The type of options expected to read 77 | // following *this argument 78 | }; 79 | 80 | //++ 81 | // Details: Retrieve the first argument or option value from the list of 1 or 82 | // more options 83 | // parsed from the command's options string. 84 | // Type: Template method. 85 | // Args: vrwValue - (W) Templated type return value. 86 | // T1 - The argument value's class type of the data hold in 87 | // the list of options. 88 | // T2 - The type pf the variable which holds the value wanted. 89 | // Return: MIstatus::success - Functional succeeded. 90 | // MIstatus::failure - Functional failed. List of object was empty. 91 | // Throws: None. 92 | //-- 93 | template 94 | bool CMICmdArgValOptionLong::GetExpectedOption(T2 &vrwValue) const { 95 | const VecArgObjPtr_t &rVecOptions(GetExpectedOptions()); 96 | VecArgObjPtr_t::const_iterator it2 = rVecOptions.begin(); 97 | if (it2 != rVecOptions.end()) { 98 | const T1 *pOption = static_cast(*it2); 99 | vrwValue = pOption->GetValue(); 100 | return MIstatus::success; 101 | } 102 | 103 | return MIstatus::failure; 104 | } 105 | -------------------------------------------------------------------------------- /src/MICmdArgValOptionShort.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgValOptionShort.cpp ------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // In-house headers: 10 | #include "MICmdArgValOptionShort.h" 11 | #include "MICmdArgContext.h" 12 | 13 | //++ 14 | // Details: CMICmdArgValOptionShort constructor. 15 | // Type: Method. 16 | // Args: None. 17 | // Return: None. 18 | // Throws: None. 19 | //-- 20 | CMICmdArgValOptionShort::CMICmdArgValOptionShort() {} 21 | 22 | //++ 23 | // Details: CMICmdArgValOptionShort constructor. 24 | // Type: Method. 25 | // Args: vrArgName - (R) Argument's name to search by. 26 | // vbMandatory - (R) True = Yes must be present, false = optional 27 | // argument. 28 | // vbHandleByCmd - (R) True = Command processes *this option, false = 29 | // not handled. 30 | // Return: None. 31 | // Throws: None. 32 | //-- 33 | CMICmdArgValOptionShort::CMICmdArgValOptionShort(const CMIUtilString &vrArgName, 34 | const bool vbMandatory, 35 | const bool vbHandleByCmd) 36 | : CMICmdArgValOptionLong(vrArgName, vbMandatory, vbHandleByCmd) {} 37 | 38 | //++ 39 | // Details: CMICmdArgValOptionLong constructor. 40 | // Type: Method. 41 | // Args: vrArgName - (R) Argument's name to search by. 42 | // vbMandatory - (R) True = Yes must be present, false = 43 | // optional argument. 44 | // vbHandleByCmd - (R) True = Command processes *this option, 45 | // false = not handled. 46 | // veType - (R) The type of argument to look for and 47 | // create argument object of a certain type. 48 | // vnExpectingNOptions - (R) The number of options expected to read 49 | // following *this argument. 50 | // Return: None. 51 | // Throws: None. 52 | //-- 53 | CMICmdArgValOptionShort::CMICmdArgValOptionShort( 54 | const CMIUtilString &vrArgName, const bool vbMandatory, 55 | const bool vbHandleByCmd, const ArgValType_e veType, 56 | const MIuint vnExpectingNOptions) 57 | : CMICmdArgValOptionLong(vrArgName, vbMandatory, vbHandleByCmd, veType, 58 | vnExpectingNOptions) {} 59 | 60 | //++ 61 | // Details: CMICmdArgValOptionShort destructor. 62 | // Type: Overridden. 63 | // Args: None. 64 | // Return: None. 65 | // Throws: None. 66 | //-- 67 | CMICmdArgValOptionShort::~CMICmdArgValOptionShort() {} 68 | 69 | //++ 70 | // Details: Examine the string and determine if it is a valid short type option 71 | // argument. 72 | // Type: Method. 73 | // Args: vrTxt - (R) Some text. 74 | // Return: bool - True = yes valid arg, false = no. 75 | // Throws: None. 76 | //-- 77 | bool CMICmdArgValOptionShort::IsArgShortOption( 78 | const CMIUtilString &vrTxt) const { 79 | // Look for --someLongOption 80 | MIint nPos = vrTxt.find("--"); 81 | if (nPos == 0) 82 | return false; 83 | 84 | // Look for -f short option 85 | nPos = vrTxt.find('-'); 86 | if (nPos != 0) 87 | return false; 88 | 89 | if (vrTxt.length() > 2) 90 | return false; 91 | 92 | return true; 93 | } 94 | 95 | //++ 96 | // Details: Examine the string and determine if it is a valid short type option 97 | // argument. 98 | // Long type argument looks like -f some short option. 99 | // Type: Overridden. 100 | // Args: vrTxt - (R) Some text. 101 | // Return: bool - True = yes valid arg, false = no. 102 | // Throws: None. 103 | //-- 104 | bool CMICmdArgValOptionShort::IsArgOptionCorrect( 105 | const CMIUtilString &vrTxt) const { 106 | return IsArgShortOption(vrTxt); 107 | } 108 | 109 | //++ 110 | // Details: Does the argument name of the argument being parsed ATM match the 111 | // name of 112 | // *this argument object. 113 | // Type: Overridden. 114 | // Args: vrTxt - (R) Some text. 115 | // Return: bool - True = yes arg name matched, false = no. 116 | // Throws: None. 117 | //-- 118 | bool CMICmdArgValOptionShort::ArgNameMatch(const CMIUtilString &vrTxt) const { 119 | const CMIUtilString strArg = vrTxt.substr(1); 120 | return (strArg == GetName()); 121 | } 122 | -------------------------------------------------------------------------------- /src/MICmdArgValOptionShort.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgValOptionShort.h --------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmdArgValOptionLong.h" 13 | 14 | // Declarations: 15 | class CMICmdArgContext; 16 | class CMIUtilString; 17 | 18 | //++ 19 | //============================================================================ 20 | // Details: MI common code class. Command argument class. Arguments object 21 | // needing specialization derived from the CMICmdArgValOptionLong 22 | // class. 23 | // An argument knows what type of argument it is and how it is to 24 | // interpret the options (context) string to find and validate a 25 | // matching 26 | // argument and so extract a value from it. 27 | // If *this argument has expected options following it the option 28 | // objects 29 | // created to hold each of those option's values belong to *this 30 | // argument 31 | // object and so are deleted when *this object goes out of scope. 32 | // Based on the Interpreter pattern. 33 | //-- 34 | class CMICmdArgValOptionShort : public CMICmdArgValOptionLong { 35 | // Methods: 36 | public: 37 | /* ctor */ CMICmdArgValOptionShort(); 38 | /* ctor */ CMICmdArgValOptionShort(const CMIUtilString &vrArgName, 39 | const bool vbMandatory, 40 | const bool vbHandleByCmd); 41 | /* ctor */ CMICmdArgValOptionShort(const CMIUtilString &vrArgName, 42 | const bool vbMandatory, 43 | const bool vbHandleByCmd, 44 | const ArgValType_e veType, 45 | const MIuint vnExpectingNOptions); 46 | // 47 | bool IsArgShortOption(const CMIUtilString &vrTxt) const; 48 | 49 | // Overridden: 50 | public: 51 | // From CMICmdArgValBase 52 | /* dtor */ ~CMICmdArgValOptionShort() override; 53 | 54 | // Overridden: 55 | private: 56 | // From CMICmdArgValOptionLong 57 | bool IsArgOptionCorrect(const CMIUtilString &vrTxt) const override; 58 | bool ArgNameMatch(const CMIUtilString &vrTxt) const override; 59 | }; 60 | -------------------------------------------------------------------------------- /src/MICmdArgValPrintValues.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgValPrintValues.h --------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmdArgValBase.h" 13 | 14 | // Declarations: 15 | class CMICmdArgContext; 16 | 17 | //++ 18 | //============================================================================ 19 | // Details: MI common code class. Command argument class. Arguments object 20 | // needing specialization derived from the CMICmdArgValBase class. 21 | // An argument knows what type of argument it is and how it is to 22 | // interpret the options (context) string to find and validate a 23 | // matching 24 | // argument and so extract a value from it. The print-values looks 25 | // like: 26 | // 0 or --no-values 27 | // 1 or --all-values 28 | // 2 or --simple-values 29 | // Based on the Interpreter pattern. 30 | //-- 31 | class CMICmdArgValPrintValues : public CMICmdArgValBaseTemplate { 32 | // Methods: 33 | public: 34 | /* ctor */ CMICmdArgValPrintValues(); 35 | /* ctor */ CMICmdArgValPrintValues(const CMIUtilString &vrArgName, 36 | const bool vbMandatory, 37 | const bool vbHandleByCmd); 38 | // 39 | bool IsArgPrintValues(const CMIUtilString &vrTxt) const; 40 | 41 | // Overridden: 42 | public: 43 | // From CMICmdArgValBase 44 | /* dtor */ ~CMICmdArgValPrintValues() override; 45 | // From CMICmdArgSet::IArg 46 | bool Validate(CMICmdArgContext &vArgContext) override; 47 | 48 | // Methods: 49 | private: 50 | bool ExtractPrintValues(const CMIUtilString &vrTxt); 51 | MIuint GetPrintValues() const; 52 | 53 | // Attributes: 54 | private: 55 | MIuint m_nPrintValues; 56 | }; 57 | -------------------------------------------------------------------------------- /src/MICmdArgValString.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgValString.h -------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmdArgValText.h" 13 | 14 | // Declarations: 15 | class CMICmdArgContext; 16 | 17 | //++ 18 | //============================================================================ 19 | // Details: MI common code class. Command argument class. Arguments object 20 | // needing specialization derived from the CMICmdArgValBase class. 21 | // An argument knows what type of argument it is and how it is to 22 | // interpret the options (context) string to find and validate a 23 | // matching 24 | // argument and so extract a value from it . 25 | // Based on the Interpreter pattern. 26 | //-- 27 | class CMICmdArgValString : public CMICmdArgValText { 28 | // Methods: 29 | public: 30 | /* ctor */ CMICmdArgValString(); 31 | /* ctor */ CMICmdArgValString(const bool vbHandleQuotes, 32 | const bool vbAcceptNumbers, 33 | const bool vbHandleDirPaths); 34 | /* ctor */ CMICmdArgValString(const CMIUtilString &vrArgName, 35 | const bool vbMandatory, 36 | const bool vbHandleByCmd, 37 | const bool vbHandleQuotes = false, 38 | const bool vbAcceptNumbers = false); 39 | /* ctor */ CMICmdArgValString(const CMIUtilString &vrArgName, 40 | const bool vbMandatory, 41 | const bool vbHandleByCmd, 42 | const bool vbHandleQuotes, 43 | const bool vbAcceptNumbers, 44 | const bool vbHandleDirPaths); 45 | // 46 | bool IsStringArg(const CMIUtilString &vrTxt) const; 47 | 48 | // Overridden: 49 | public: 50 | // From CMICmdArgValBase 51 | /* dtor */ ~CMICmdArgValString() override; 52 | // From CMICmdArgSet::IArg 53 | bool Validate(CMICmdArgContext &vrwArgContext) override; 54 | 55 | // Methods: 56 | private: 57 | bool ValidateSingleText(CMICmdArgContext &vrwArgContext); 58 | bool ValidateQuotedText(CMICmdArgContext &vrwArgContext); 59 | bool IsStringArgSingleText(const CMIUtilString &vrTxt) const; 60 | bool IsStringArgQuotedText(const CMIUtilString &vrTxt) const; 61 | 62 | // Attribute: 63 | private: 64 | bool m_bHandleQuotedString; // True = Parse a string surrounded by quotes 65 | // spaces are not delimiters, false = only text up 66 | // to next 67 | // delimiting space character 68 | bool m_bAcceptNumbers; // True = Parse a string and accept as a number if 69 | // number, false = numbers not recognised as string 70 | // types 71 | bool m_bHandleDirPaths; // True = Parse a string and accept directory file 72 | // style string if present, false = directory file 73 | // path not 74 | // accepted 75 | }; 76 | -------------------------------------------------------------------------------- /src/MICmdArgValText.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgValText.cpp -------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // In-house headers: 10 | #include "MICmdArgValText.h" 11 | #include "MICmdArgContext.h" 12 | 13 | //++ 14 | // Details: Parse the command's argument options string and try to extract the 15 | // value *this argument is looking for. 16 | // Type: Overridden. 17 | // Args: vwArgContext - (R) The command's argument options string. 18 | // Return: MIstatus::success - Functional succeeded. 19 | // MIstatus::failure - Functional failed. 20 | // Throws: None. 21 | //-- 22 | bool CMICmdArgValText::Validate(CMICmdArgContext &vwrArgContext) { 23 | if (vwrArgContext.IsEmpty()) 24 | return m_bMandatory ? MIstatus::failure : MIstatus::success; 25 | 26 | auto &&args = vwrArgContext.GetArgs(); 27 | 28 | auto it = args.begin(); 29 | if (it == args.end()) 30 | return MIstatus::failure; 31 | 32 | const CMIUtilString &rExpr(*it); 33 | 34 | return ConsumeArgument(vwrArgContext, rExpr); 35 | } 36 | 37 | //++ 38 | // Details: Remove the given argument from the context and store it as the 39 | // value of this argument. 40 | // Type: Overridden. 41 | // Args: vwArgContext - (R) The command's argument options string. 42 | // vrArg - (R) The argument to consume 43 | // Return: MIstatus::success - Functional succeeded. 44 | // MIstatus::failure - Functional failed. 45 | // Throws: None. 46 | //-- 47 | bool CMICmdArgValText::ConsumeArgument(CMICmdArgContext &vwrArgContext, 48 | const CMIUtilString &vrArg) { 49 | // We must do it before removing because reference can become invalid 50 | auto &&rArgValue = vrArg.Trim().Trim('"').StripSlashes(); 51 | 52 | if (vwrArgContext.RemoveArg(vrArg)) { 53 | m_bValid = true; 54 | m_argValue = rArgValue; 55 | return MIstatus::success; 56 | } 57 | 58 | return MIstatus::failure; 59 | } 60 | -------------------------------------------------------------------------------- /src/MICmdArgValText.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgValText.h ---------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmdArgValBase.h" 13 | 14 | // Declarations: 15 | class CMICmdArgContext; 16 | 17 | //++ 18 | //============================================================================ 19 | // Details: MI common code class. Command argument class. Arguments object 20 | // needing specialization derived from the CMICmdArgValBase class. 21 | // An argument knows what type of argument it is and how it is to 22 | // interpret the options (context) string to find and validate a 23 | // matching argument and so extract a value from it. 24 | // 25 | // Extracts an argument as is removing only surrounding quotes. 26 | // 27 | // Based on the Interpreter pattern. 28 | //-- 29 | class CMICmdArgValText : public CMICmdArgValBaseTemplate { 30 | // Methods: 31 | public: 32 | using CMICmdArgValBaseTemplate::CMICmdArgValBaseTemplate; 33 | // Overridden: 34 | public: 35 | // From CMICmdArgValBase 36 | /* dtor */ ~CMICmdArgValText() override = default; 37 | // From CMICmdArgSet::IArg 38 | bool Validate(CMICmdArgContext &vwrArgContext) override; 39 | 40 | // Utilities: 41 | protected: 42 | bool ConsumeArgument(CMICmdArgContext &vwrArgContext, 43 | const CMIUtilString &vrArg); 44 | }; 45 | -------------------------------------------------------------------------------- /src/MICmdArgValThreadGrp.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdArgValThreadGrp.h ----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmdArgValBase.h" 13 | 14 | // Declarations: 15 | class CMICmdArgContext; 16 | 17 | //++ 18 | //============================================================================ 19 | // Details: MI common code class. Command argument class. Arguments object 20 | // needing specialization derived from the CMICmdArgValBase class. 21 | // An argument knows what type of argument it is and how it is to 22 | // interpret the options (context) string to find and validate a 23 | // matching 24 | // argument and so extract a value from it. Thread group looks like 25 | // "i1" in the options text. 26 | // Based on the Interpreter pattern. 27 | //-- 28 | class CMICmdArgValThreadGrp : public CMICmdArgValBaseTemplate { 29 | // Methods: 30 | public: 31 | /* ctor */ CMICmdArgValThreadGrp(); 32 | /* ctor */ CMICmdArgValThreadGrp(const CMIUtilString &vrArgName, 33 | const bool vbMandatory, 34 | const bool vbHandleByCmd); 35 | // 36 | bool IsArgThreadGrp(const CMIUtilString &vrTxt) const; 37 | 38 | // Overridden: 39 | public: 40 | // From CMICmdArgValBase 41 | /* dtor */ ~CMICmdArgValThreadGrp() override; 42 | // From CMICmdArgSet::IArg 43 | bool Validate(CMICmdArgContext &vArgContext) override; 44 | 45 | // Methods: 46 | private: 47 | bool ExtractNumber(const CMIUtilString &vrTxt); 48 | MIuint GetNumber() const; 49 | 50 | // Attributes: 51 | private: 52 | MIuint m_nThreadGrp; 53 | }; 54 | -------------------------------------------------------------------------------- /src/MICmdCmd.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmd.h ----------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdEnablePrettyPrinting interface. 10 | // CMICmdCmdSource interface. 11 | // 12 | // To implement new MI commands derive a new command class from the 13 | // command base 14 | // class. To enable the new command for interpretation add the new 15 | // command class 16 | // to the command factory. The files of relevance are: 17 | // MICmdCommands.cpp 18 | // MICmdBase.h / .cpp 19 | // MICmdCmd.h / .cpp 20 | // For an introduction to adding a new command see 21 | // CMICmdCmdSupportInfoMiCmdQuery 22 | // command class as an example. 23 | 24 | /* 25 | MI commands implemented are: 26 | See MICmdCommands.cpp 27 | */ 28 | 29 | #pragma once 30 | 31 | // Third party headers: 32 | #include "lldb/API/SBBreakpoint.h" 33 | #include "lldb/API/SBCommandReturnObject.h" 34 | #include 35 | 36 | // In-house headers: 37 | #include "MICmdBase.h" 38 | #include "MICmnMIValueList.h" 39 | #include "MICmnMIValueTuple.h" 40 | 41 | //++ 42 | //============================================================================ 43 | // Details: MI command class. MI commands derived from the command base class. 44 | // *this class implements MI command "enable-pretty-printing". 45 | // Enables Python base pretty printing. 46 | // Ref: 47 | // http://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Variable-Objects.html 48 | //-- 49 | class CMICmdCmdEnablePrettyPrinting : public CMICmdBase { 50 | // Statics: 51 | public: 52 | // Required by the CMICmdFactory when registering *this command 53 | static CMICmdBase *CreateSelf(); 54 | 55 | // Methods: 56 | public: 57 | /* ctor */ CMICmdCmdEnablePrettyPrinting(); 58 | 59 | // Overridden: 60 | public: 61 | // From CMICmdInvoker::ICmd 62 | bool Execute() override; 63 | bool Acknowledge() override; 64 | // From CMICmnBase 65 | /* dtor */ ~CMICmdCmdEnablePrettyPrinting() override; 66 | }; 67 | 68 | //++ 69 | //============================================================================ 70 | // Details: MI command class. MI commands derived from the command base class. 71 | // *this class implements MI command "source". 72 | //-- 73 | class CMICmdCmdSource : public CMICmdBase { 74 | // Statics: 75 | public: 76 | // Required by the CMICmdFactory when registering *this command 77 | static CMICmdBase *CreateSelf(); 78 | 79 | // Methods: 80 | public: 81 | /* ctor */ CMICmdCmdSource(); 82 | 83 | // Overridden: 84 | public: 85 | // From CMICmdInvoker::ICmd 86 | bool Execute() override; 87 | bool Acknowledge() override; 88 | // From CMICmnBase 89 | /* dtor */ ~CMICmdCmdSource() override; 90 | }; 91 | -------------------------------------------------------------------------------- /src/MICmdCmdEnviro.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmdEnviro.h ----------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdEnvironmentCd interface. 10 | // 11 | // To implement new MI commands derive a new command class from the 12 | // command base 13 | // class. To enable the new command for interpretation add the new 14 | // command class 15 | // to the command factory. The files of relevance are: 16 | // MICmdCommands.cpp 17 | // MICmdBase.h / .cpp 18 | // MICmdCmd.h / .cpp 19 | // For an introduction to adding a new command see 20 | // CMICmdCmdSupportInfoMiCmdQuery 21 | // command class as an example. 22 | 23 | #pragma once 24 | 25 | // In-house headers: 26 | #include "MICmdBase.h" 27 | #include "MICmnMIValueList.h" 28 | #include "MICmnMIValueTuple.h" 29 | 30 | //++ 31 | //============================================================================ 32 | // Details: MI command class. MI commands derived from the command base class. 33 | // *this class implements MI command "environment-cd". 34 | //-- 35 | class CMICmdCmdEnvironmentCd : public CMICmdBase { 36 | // Statics: 37 | public: 38 | // Required by the CMICmdFactory when registering *this command 39 | static CMICmdBase *CreateSelf(); 40 | 41 | // Methods: 42 | public: 43 | /* ctor */ CMICmdCmdEnvironmentCd(); 44 | 45 | // Overridden: 46 | public: 47 | // From CMICmdInvoker::ICmd 48 | bool Execute() override; 49 | bool Acknowledge() override; 50 | bool ParseArgs() override; 51 | // From CMICmnBase 52 | /* dtor */ ~CMICmdCmdEnvironmentCd() override; 53 | 54 | // Attributes: 55 | private: 56 | const CMIUtilString m_constStrArgNamePathDir; 57 | }; 58 | -------------------------------------------------------------------------------- /src/MICmdCmdFile.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmdFile.h ------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdFileExecAndSymbols interface. 10 | // 11 | // To implement new MI commands derive a new command class from the 12 | // command base 13 | // class. To enable the new command for interpretation add the new 14 | // command class 15 | // to the command factory. The files of relevance are: 16 | // MICmdCommands.cpp 17 | // MICmdBase.h / .cpp 18 | // MICmdCmd.h / .cpp 19 | // For an introduction to adding a new command see 20 | // CMICmdCmdSupportInfoMiCmdQuery 21 | // command class as an example. 22 | 23 | #pragma once 24 | 25 | // In-house headers: 26 | #include "MICmdBase.h" 27 | #include "MICmnMIValueList.h" 28 | #include "MICmnMIValueTuple.h" 29 | 30 | //++ 31 | //============================================================================ 32 | // Details: MI command class. MI commands derived from the command base class. 33 | // *this class implements MI command "file-exec-and-symbols". 34 | // This command does not follow the MI documentation exactly. 35 | // Gotchas: This command has additional flags that were not available in GDB MI. 36 | // See MIextensions.txt for details. 37 | //-- 38 | class CMICmdCmdFileExecAndSymbols : public CMICmdBase { 39 | // Statics: 40 | public: 41 | // Required by the CMICmdFactory when registering *this command 42 | static CMICmdBase *CreateSelf(); 43 | 44 | // Methods: 45 | public: 46 | /* ctor */ CMICmdCmdFileExecAndSymbols(); 47 | 48 | // Overridden: 49 | public: 50 | // From CMICmdInvoker::ICmd 51 | bool Execute() override; 52 | bool Acknowledge() override; 53 | bool ParseArgs() override; 54 | // From CMICmnBase 55 | /* dtor */ ~CMICmdCmdFileExecAndSymbols() override; 56 | bool GetExitAppOnCommandFailure() const override; 57 | 58 | // Attributes: 59 | private: 60 | const CMIUtilString m_constStrArgNameFile; 61 | const CMIUtilString 62 | m_constStrArgNamedPlatformName; // Added to support iOS platform selection 63 | const CMIUtilString m_constStrArgNamedRemotePath; // Added to support iOS 64 | // device remote file 65 | // location 66 | }; 67 | -------------------------------------------------------------------------------- /src/MICmdCmdGdbInfo.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmdGdbInfo.h ---------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdGdbInfo interface. 10 | // 11 | // To implement new MI commands derive a new command class from the 12 | // command base 13 | // class. To enable the new command for interpretation add the new 14 | // command class 15 | // to the command factory. The files of relevance are: 16 | // MICmdCommands.cpp 17 | // MICmdBase.h / .cpp 18 | // MICmdCmd.h / .cpp 19 | // For an introduction to adding a new command see 20 | // CMICmdCmdSupportInfoMiCmdQuery 21 | // command class as an example. 22 | 23 | #pragma once 24 | 25 | // Third party headers: 26 | #include 27 | 28 | // In-house headers: 29 | #include "MICmdBase.h" 30 | 31 | //++ 32 | //============================================================================ 33 | // Details: MI command class. MI commands derived from the command base class. 34 | // *this class implements GDB command "info". 35 | // The design of matching the info request to a request action (or 36 | // command) is very simple. The request function which carries out 37 | // the task of information gathering and printing to stdout is part of 38 | // *this class. Should the request function become more complicated 39 | // then 40 | // that request should really reside in a command type class. Then this 41 | // class instantiates a request info command for a matching request. 42 | // The 43 | // design/code of *this class then does not then become bloated. Use a 44 | // lightweight version of the current MI command system. 45 | //-- 46 | class CMICmdCmdGdbInfo : public CMICmdBase { 47 | // Statics: 48 | public: 49 | // Required by the CMICmdFactory when registering *this command 50 | static CMICmdBase *CreateSelf(); 51 | 52 | // Methods: 53 | public: 54 | /* ctor */ CMICmdCmdGdbInfo(); 55 | 56 | // Overridden: 57 | public: 58 | // From CMICmdInvoker::ICmd 59 | bool Execute() override; 60 | bool Acknowledge() override; 61 | bool ParseArgs() override; 62 | // From CMICmnBase 63 | /* dtor */ ~CMICmdCmdGdbInfo() override; 64 | 65 | // Typedefs: 66 | private: 67 | typedef bool (CMICmdCmdGdbInfo::*FnPrintPtr)(); 68 | typedef std::map MapPrintFnNameToPrintFn_t; 69 | 70 | // Methods: 71 | private: 72 | bool GetPrintFn(const CMIUtilString &vrPrintFnName, FnPrintPtr &vrwpFn) const; 73 | bool PrintFnSharedLibrary(); 74 | 75 | // Attributes: 76 | private: 77 | const static MapPrintFnNameToPrintFn_t ms_mapPrintFnNameToPrintFn; 78 | // 79 | const CMIUtilString m_constStrArgNamedPrint; 80 | bool m_bPrintFnRecognised; // True = This command has a function with a name 81 | // that matches the Print argument, false = not 82 | // found 83 | bool m_bPrintFnSuccessful; // True = The print function completed its task ok, 84 | // false = function failed for some reason 85 | CMIUtilString m_strPrintFnName; 86 | CMIUtilString m_strPrintFnError; 87 | }; 88 | -------------------------------------------------------------------------------- /src/MICmdCmdGdbShow.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmdGdbShow.h ---------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdGdbShow interface. 10 | // 11 | // To implement new MI commands, derive a new command class from 12 | // the command base 13 | // class. To enable the new command for interpretation add the new 14 | // command class 15 | // to the command factory. The files of relevance are: 16 | // MICmdCommands.cpp 17 | // MICmdBase.h / .cpp 18 | // MICmdCmd.h / .cpp 19 | // For an introduction to adding a new command see 20 | // CMICmdCmdSupportInfoMiCmdQuery 21 | // command class as an example. 22 | 23 | #pragma once 24 | 25 | // In-house headers: 26 | #include "MICmdBase.h" 27 | 28 | //++ 29 | //============================================================================ 30 | // Details: MI command class. MI commands derived from the command base class. 31 | // *this class implements MI command "gdb-show". 32 | // This command does not follow the MI documentation exactly. While 33 | // *this 34 | // command is implemented it does not do anything with the gdb-set 35 | // variable past in. 36 | // The design of matching the info request to a request action (or 37 | // command) is very simple. The request function which carries out 38 | // the task of information gathering and printing to stdout is part of 39 | // *this class. Should the request function become more complicated 40 | // then 41 | // that request should really reside in a command type class. Then this 42 | // class instantiates a request info command for a matching request. 43 | // The 44 | // design/code of *this class then does not then become bloated. Use a 45 | // lightweight version of the current MI command system. 46 | //-- 47 | class CMICmdCmdGdbShow : public CMICmdBase { 48 | // Statics: 49 | public: 50 | // Required by the CMICmdFactory when registering *this command 51 | static CMICmdBase *CreateSelf(); 52 | 53 | // Methods: 54 | public: 55 | /* ctor */ CMICmdCmdGdbShow(); 56 | 57 | // Overridden: 58 | public: 59 | // From CMICmdInvoker::ICmd 60 | bool Execute() override; 61 | bool Acknowledge() override; 62 | bool ParseArgs() override; 63 | // From CMICmnBase 64 | /* dtor */ ~CMICmdCmdGdbShow() override; 65 | 66 | // Typedefs: 67 | private: 68 | typedef bool (CMICmdCmdGdbShow::*FnGdbOptionPtr)( 69 | const CMIUtilString::VecString_t &vrWords); 70 | typedef std::map 71 | MapGdbOptionNameToFnGdbOptionPtr_t; 72 | 73 | // Methods: 74 | private: 75 | bool GetOptionFn(const CMIUtilString &vrGdbOptionName, 76 | FnGdbOptionPtr &vrwpFn) const; 77 | bool OptionFnTargetAsync(const CMIUtilString::VecString_t &vrWords); 78 | bool OptionFnPrint(const CMIUtilString::VecString_t &vrWords); 79 | bool OptionFnLanguage(const CMIUtilString::VecString_t &vrWords); 80 | bool OptionFnDisassemblyFlavor(const CMIUtilString::VecString_t &vrWords); 81 | bool OptionFnFallback(const CMIUtilString::VecString_t &vrWords); 82 | bool OptionFnBreakpoint(const CMIUtilString::VecString_t &vrWords); 83 | 84 | // Attributes: 85 | private: 86 | const static MapGdbOptionNameToFnGdbOptionPtr_t 87 | ms_mapGdbOptionNameToFnGdbOptionPtr; 88 | 89 | const CMIUtilString m_constStrArgNamedGdbOption; 90 | bool m_bGdbOptionRecognised; // True = This command has a function with a name 91 | // that matches the Print argument, false = not 92 | // found 93 | bool m_bGdbOptionFnSuccessful; // True = The print function completed its task 94 | // ok, false = function failed for some reason 95 | bool m_bGbbOptionFnHasError; // True = The option function has an error 96 | // condition (not the command!), false = option 97 | // function ok. 98 | CMIUtilString m_strGdbOptionName; 99 | CMIUtilString m_strGdbOptionFnError; 100 | CMIUtilString m_strValue; 101 | }; 102 | -------------------------------------------------------------------------------- /src/MICmdCmdGdbThread.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmdGdbThread.cpp -----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdGdbThread implementation. 10 | 11 | // In-house headers: 12 | #include "MICmdCmdGdbThread.h" 13 | #include "MICmnMIResultRecord.h" 14 | #include "MICmnMIValueConst.h" 15 | 16 | //++ 17 | // Details: CMICmdCmdGdbThread constructor. 18 | // Type: Method. 19 | // Args: None. 20 | // Return: None. 21 | // Throws: None. 22 | //-- 23 | CMICmdCmdGdbThread::CMICmdCmdGdbThread() { 24 | // Command factory matches this name with that received from the stdin stream 25 | m_strMiCmd = "thread"; 26 | 27 | // Required by the CMICmdFactory when registering *this command 28 | m_pSelfCreatorFn = &CMICmdCmdGdbThread::CreateSelf; 29 | } 30 | 31 | //++ 32 | // Details: CMICmdCmdThread destructor. 33 | // Type: Overrideable. 34 | // Args: None. 35 | // Return: None. 36 | // Throws: None. 37 | //-- 38 | CMICmdCmdGdbThread::~CMICmdCmdGdbThread() {} 39 | 40 | //++ 41 | // Details: The invoker requires this function. The command does work in this 42 | // function. 43 | // The command is likely to communicate with the LLDB SBDebugger in 44 | // here. 45 | // Type: Overridden. 46 | // Args: None. 47 | // Return: MIstatus::success - Functional succeeded. 48 | // MIstatus::failure - Functional failed. 49 | // Throws: None. 50 | //-- 51 | bool CMICmdCmdGdbThread::Execute() { 52 | // Do nothing 53 | 54 | return MIstatus::success; 55 | } 56 | 57 | //++ 58 | // Details: The invoker requires this function. The command prepares a MI Record 59 | // Result 60 | // for the work carried out in the Execute(). 61 | // Type: Overridden. 62 | // Args: None. 63 | // Return: MIstatus::success - Functional succeeded. 64 | // MIstatus::failure - Functional failed. 65 | // Throws: None. 66 | //-- 67 | bool CMICmdCmdGdbThread::Acknowledge() { 68 | const CMICmnMIValueConst miValueConst(MIRSRC(IDS_WORD_NOT_IMPLEMENTED)); 69 | const CMICmnMIValueResult miValueResult("msg", miValueConst); 70 | const CMICmnMIResultRecord miRecordResult( 71 | m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, 72 | miValueResult); 73 | m_miResultRecord = miRecordResult; 74 | 75 | return MIstatus::success; 76 | } 77 | 78 | //++ 79 | // Details: Required by the CMICmdFactory when registering *this command. The 80 | // factory 81 | // calls this function to create an instance of *this command. 82 | // Type: Static method. 83 | // Args: None. 84 | // Return: CMICmdBase * - Pointer to a new command. 85 | // Throws: None. 86 | //-- 87 | CMICmdBase *CMICmdCmdGdbThread::CreateSelf() { 88 | return new CMICmdCmdGdbThread(); 89 | } 90 | -------------------------------------------------------------------------------- /src/MICmdCmdGdbThread.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmdGdbThread.h -------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdGdbThread interface. 10 | // 11 | // To implement new MI commands derive a new command class from the 12 | // command base 13 | // class. To enable the new command for interpretation add the new 14 | // command class 15 | // to the command factory. The files of relevance are: 16 | // MICmdCommands.cpp 17 | // MICmdBase.h / .cpp 18 | // MICmdCmd.h / .cpp 19 | // For an introduction to adding a new command see 20 | // CMICmdCmdSupportInfoMiCmdQuery 21 | // command class as an example. 22 | 23 | #pragma once 24 | 25 | // In-house headers: 26 | #include "MICmdBase.h" 27 | 28 | //++ 29 | //============================================================================ 30 | // Details: MI command class. MI commands derived from the command base class. 31 | // *this class implements GDB command "thread". 32 | //-- 33 | class CMICmdCmdGdbThread : public CMICmdBase { 34 | // Statics: 35 | public: 36 | // Required by the CMICmdFactory when registering *this command 37 | static CMICmdBase *CreateSelf(); 38 | 39 | // Methods: 40 | public: 41 | /* ctor */ CMICmdCmdGdbThread(); 42 | 43 | // Overridden: 44 | public: 45 | // From CMICmdInvoker::ICmd 46 | bool Execute() override; 47 | bool Acknowledge() override; 48 | // From CMICmnBase 49 | /* dtor */ ~CMICmdCmdGdbThread() override; 50 | }; 51 | -------------------------------------------------------------------------------- /src/MICmdCmdSupportInfo.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmdSupportInfo.cpp ---------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdSupportInfoMiCmdQuery implementation. 10 | 11 | // In-house headers: 12 | #include "MICmdCmdSupportInfo.h" 13 | #include "MICmdArgValString.h" 14 | #include "MICmdFactory.h" 15 | #include "MICmnMIResultRecord.h" 16 | #include "MICmnMIValueConst.h" 17 | #include "MICmnMIValueTuple.h" 18 | 19 | //++ 20 | // Details: CMICmdCmdSupportInfoMiCmdQuery constructor. 21 | // Type: Method. 22 | // Args: None. 23 | // Return: None. 24 | // Throws: None. 25 | //-- 26 | CMICmdCmdSupportInfoMiCmdQuery::CMICmdCmdSupportInfoMiCmdQuery() 27 | : m_bCmdFound(false), m_constStrArgCmdName("cmd_name") { 28 | // Command factory matches this name with that received from the stdin stream 29 | m_strMiCmd = "info-gdb-mi-command"; 30 | 31 | // Required by the CMICmdFactory when registering *this command 32 | m_pSelfCreatorFn = &CMICmdCmdSupportInfoMiCmdQuery::CreateSelf; 33 | } 34 | 35 | //++ 36 | // Details: CMICmdCmdSupportInfoMiCmdQuery destructor. 37 | // Type: Overrideable. 38 | // Args: None. 39 | // Return: None. 40 | // Throws: None. 41 | //-- 42 | CMICmdCmdSupportInfoMiCmdQuery::~CMICmdCmdSupportInfoMiCmdQuery() {} 43 | 44 | //++ 45 | // Details: The invoker requires this function. The parses the command line 46 | // options 47 | // arguments to extract values for each of those arguments. 48 | // Type: Overridden. 49 | // Args: None. 50 | // Return: MIstatus::success - Functional succeeded. 51 | // MIstatus::failure - Functional failed. 52 | // Throws: None. 53 | //-- 54 | bool CMICmdCmdSupportInfoMiCmdQuery::ParseArgs() { 55 | m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgCmdName, true, true)); 56 | return ParseValidateCmdOptions(); 57 | } 58 | 59 | //++ 60 | // Details: The invoker requires this function. The command does work in this 61 | // function. 62 | // The command is likely to communicate with the LLDB SBDebugger in 63 | // here. 64 | // Type: Overridden. 65 | // Args: None. 66 | // Return: MIstatus::success - Functional succeeded. 67 | // MIstatus::failure - Functional failed. 68 | // Throws: None. 69 | //-- 70 | bool CMICmdCmdSupportInfoMiCmdQuery::Execute() { 71 | CMICMDBASE_GETOPTION(pArgNamedCmdName, String, m_constStrArgCmdName); 72 | const CMIUtilString &rCmdToQuery(pArgNamedCmdName->GetValue()); 73 | const MIuint nLen = rCmdToQuery.length(); 74 | const CMICmdFactory &rCmdFactory = CMICmdFactory::Instance(); 75 | if ((nLen > 1) && (rCmdToQuery[0] == '-')) 76 | m_bCmdFound = rCmdFactory.CmdExist(rCmdToQuery.substr(1, nLen - 1).c_str()); 77 | else 78 | m_bCmdFound = rCmdFactory.CmdExist(rCmdToQuery); 79 | 80 | return MIstatus::success; 81 | } 82 | 83 | //++ 84 | // Details: The invoker requires this function. The command prepares a MI Record 85 | // Result 86 | // for the work carried out in the Execute(). 87 | // Type: Overridden. 88 | // Args: None. 89 | // Return: MIstatus::success - Functional succeeded. 90 | // MIstatus::failure - Functional failed. 91 | // Throws: None. 92 | //-- 93 | bool CMICmdCmdSupportInfoMiCmdQuery::Acknowledge() { 94 | const CMICmnMIValueConst miValueConst(m_bCmdFound ? "true" : "false"); 95 | const CMICmnMIValueResult miValueResult("exists", miValueConst); 96 | const CMICmnMIValueTuple miValueTuple(miValueResult); 97 | const CMICmnMIValueResult miValueResult2("command", miValueTuple); 98 | const CMICmnMIResultRecord miRecordResult( 99 | m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, 100 | miValueResult2); 101 | m_miResultRecord = miRecordResult; 102 | 103 | return MIstatus::success; 104 | } 105 | 106 | //++ 107 | // Details: Required by the CMICmdFactory when registering *this command. The 108 | // factory 109 | // calls this function to create an instance of *this command. 110 | // Type: Static method. 111 | // Args: None. 112 | // Return: CMICmdBase * - Pointer to a new command. 113 | // Throws: None. 114 | //-- 115 | CMICmdBase *CMICmdCmdSupportInfoMiCmdQuery::CreateSelf() { 116 | return new CMICmdCmdSupportInfoMiCmdQuery(); 117 | } 118 | -------------------------------------------------------------------------------- /src/MICmdCmdSupportInfo.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmdSupportInfo.h -----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdSupportInfoMiCmdQuery interface. 10 | // 11 | // To implement new MI commands derive a new command class from the 12 | // command base 13 | // class. To enable the new command for interpretation add the new 14 | // command class 15 | // to the command factory. The files of relevance are: 16 | // MICmdCommands.cpp 17 | // MICmdBase.h / .cpp 18 | // MICmdCmd.h / .cpp 19 | // For an introduction to adding a new command see 20 | // CMICmdCmdSupportInfoMiCmdQuery 21 | // command class as an example. 22 | 23 | #pragma once 24 | 25 | // In-house headers: 26 | #include "MICmdBase.h" 27 | 28 | //++ 29 | //============================================================================ 30 | // Details: MI command class. MI commands derived from the command base class. 31 | // *this class implements MI command "info-gdb-mi-command". 32 | // This command does not follow the MI documentation exactly. 33 | //-- 34 | class CMICmdCmdSupportInfoMiCmdQuery : public CMICmdBase { 35 | // Statics: 36 | public: 37 | // Required by the CMICmdFactory when registering *this command 38 | static CMICmdBase *CreateSelf(); 39 | 40 | // Methods: 41 | public: 42 | /* ctor */ CMICmdCmdSupportInfoMiCmdQuery(); 43 | 44 | // Overridden: 45 | public: 46 | // From CMICmdInvoker::ICmd 47 | bool Execute() override; 48 | bool Acknowledge() override; 49 | bool ParseArgs() override; 50 | // From CMICmnBase 51 | /* dtor */ ~CMICmdCmdSupportInfoMiCmdQuery() override; 52 | 53 | // Attributes: 54 | private: 55 | bool m_bCmdFound; // True = query for the command in command factory found, 56 | // false = not found not recognised 57 | const CMIUtilString m_constStrArgCmdName; 58 | }; 59 | -------------------------------------------------------------------------------- /src/MICmdCmdSupportList.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmdSupportList.cpp ---------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdSupportListFeatures implementation. 10 | 11 | // In-house headers: 12 | #include "MICmdCmdSupportList.h" 13 | #include "MICmnMIResultRecord.h" 14 | #include "MICmnMIValueConst.h" 15 | #include "MICmnMIValueList.h" 16 | 17 | //++ 18 | // Details: CMICmdCmdSupportListFeatures constructor. 19 | // Type: Method. 20 | // Args: None. 21 | // Return: None. 22 | // Throws: None. 23 | //-- 24 | CMICmdCmdSupportListFeatures::CMICmdCmdSupportListFeatures() { 25 | // Command factory matches this name with that received from the stdin stream 26 | m_strMiCmd = "list-features"; 27 | 28 | // Required by the CMICmdFactory when registering *this command 29 | m_pSelfCreatorFn = &CMICmdCmdSupportListFeatures::CreateSelf; 30 | } 31 | 32 | //++ 33 | // Details: CMICmdCmdSupportListFeatures destructor. 34 | // Type: Overrideable. 35 | // Args: None. 36 | // Return: None. 37 | // Throws: None. 38 | //-- 39 | CMICmdCmdSupportListFeatures::~CMICmdCmdSupportListFeatures() {} 40 | 41 | //++ 42 | // Details: The invoker requires this function. The command does work in this 43 | // function. 44 | // The command is likely to communicate with the LLDB SBDebugger in 45 | // here. 46 | // Type: Overridden. 47 | // Args: None. 48 | // Return: MIstatus::success - Functional succeeded. 49 | // MIstatus::failure - Functional failed. 50 | // Throws: None. 51 | //-- 52 | bool CMICmdCmdSupportListFeatures::Execute() { 53 | // Do nothing 54 | 55 | return MIstatus::success; 56 | } 57 | 58 | //++ 59 | // Details: The invoker requires this function. The command prepares a MI Record 60 | // Result 61 | // for the work carried out in the Execute(). 62 | // Type: Overridden. 63 | // Args: None. 64 | // Return: MIstatus::success - Functional succeeded. 65 | // MIstatus::failure - Functional failed. 66 | // Throws: None. 67 | //-- 68 | bool CMICmdCmdSupportListFeatures::Acknowledge() { 69 | // Declare supported features here 70 | const CMICmnMIValueConst miValueConst1("data-read-memory-bytes"); 71 | const CMICmnMIValueConst miValueConst2("exec-run-start-option"); 72 | const CMICmnMIValueConst miValueConst3("pending-breakpoints"); 73 | // Some features may depend on host and/or target, decide what to add below 74 | CMICmnMIValueList miValueList(true); 75 | miValueList.Add(miValueConst1); 76 | miValueList.Add(miValueConst2); 77 | miValueList.Add(miValueConst3); 78 | const CMICmnMIValueResult miValueResult("features", miValueList); 79 | const CMICmnMIResultRecord miRecordResult( 80 | m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, 81 | miValueResult); 82 | m_miResultRecord = miRecordResult; 83 | 84 | return MIstatus::success; 85 | } 86 | 87 | //++ 88 | // Details: Required by the CMICmdFactory when registering *this command. The 89 | // factory 90 | // calls this function to create an instance of *this command. 91 | // Type: Static method. 92 | // Args: None. 93 | // Return: CMICmdBase * - Pointer to a new command. 94 | // Throws: None. 95 | //-- 96 | CMICmdBase *CMICmdCmdSupportListFeatures::CreateSelf() { 97 | return new CMICmdCmdSupportListFeatures(); 98 | } 99 | -------------------------------------------------------------------------------- /src/MICmdCmdSupportList.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmdSupportList.h -----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdSupportListFeatures interface. 10 | // 11 | // To implement new MI commands derive a new command class from the 12 | // command base 13 | // class. To enable the new command for interpretation add the new 14 | // command class 15 | // to the command factory. The files of relevance are: 16 | // MICmdCommands.cpp 17 | // MICmdBase.h / .cpp 18 | // MICmdCmd.h / .cpp 19 | // For an introduction to adding a new command see 20 | // CMICmdCmdSupportInfoMiCmdQuery 21 | // command class as an example. 22 | 23 | #pragma once 24 | 25 | // In-house headers: 26 | #include "MICmdBase.h" 27 | 28 | //++ 29 | //============================================================================ 30 | // Details: MI command class. MI commands derived from the command base class. 31 | // *this class implements MI command "list-features". 32 | // This command does not follow the MI documentation exactly. 33 | //-- 34 | class CMICmdCmdSupportListFeatures : public CMICmdBase { 35 | // Statics: 36 | public: 37 | // Required by the CMICmdFactory when registering *this command 38 | static CMICmdBase *CreateSelf(); 39 | 40 | // Methods: 41 | public: 42 | /* ctor */ CMICmdCmdSupportListFeatures(); 43 | 44 | // Overridden: 45 | public: 46 | // From CMICmdInvoker::ICmd 47 | bool Execute() override; 48 | bool Acknowledge() override; 49 | // From CMICmnBase 50 | /* dtor */ ~CMICmdCmdSupportListFeatures() override; 51 | }; 52 | -------------------------------------------------------------------------------- /src/MICmdCmdSymbol.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmdSymbol.h ----------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdSymbolListLines interface. 10 | // 11 | // To implement new MI commands derive a new command class from the 12 | // command base 13 | // class. To enable the new command for interpretation add the new 14 | // command class 15 | // to the command factory. The files of relevance are: 16 | // MICmdCommands.cpp 17 | // MICmdBase.h / .cpp 18 | // MICmdCmd.h / .cpp 19 | // For an introduction to adding a new command see 20 | // CMICmdCmdSupportInfoMiCmdQuery 21 | // command class as an example. 22 | 23 | #pragma once 24 | 25 | // Third party headers: 26 | 27 | // In-house headers: 28 | #include "MICmdBase.h" 29 | #include "MICmnMIValueList.h" 30 | 31 | //++ 32 | //============================================================================ 33 | // Details: MI command class. MI commands derived from the command base class. 34 | // *this class implements MI command "symbol-list-lines". 35 | //-- 36 | class CMICmdCmdSymbolListLines : public CMICmdBase { 37 | // Statics: 38 | public: 39 | // Required by the CMICmdFactory when registering *this command 40 | static CMICmdBase *CreateSelf(); 41 | 42 | // Methods: 43 | public: 44 | /* ctor */ CMICmdCmdSymbolListLines(); 45 | 46 | // Overridden: 47 | public: 48 | // From CMICmdInvoker::ICmd 49 | bool Execute() override; 50 | bool Acknowledge() override; 51 | bool ParseArgs() override; 52 | // From CMICmnBase 53 | /* dtor */ ~CMICmdCmdSymbolListLines() override; 54 | 55 | // Attributes: 56 | private: 57 | CMICmnMIValueList m_resultList; 58 | const CMIUtilString m_constStrArgNameFile; 59 | }; 60 | -------------------------------------------------------------------------------- /src/MICmdCmdTarget.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmdTarget.h ----------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdTargetSelect interface. 10 | // 11 | // To implement new MI commands derive a new command class from the 12 | // command base 13 | // class. To enable the new command for interpretation add the new 14 | // command class 15 | // to the command factory. The files of relevance are: 16 | // MICmdCommands.cpp 17 | // MICmdBase.h / .cpp 18 | // MICmdCmd.h / .cpp 19 | // For an introduction to adding a new command see 20 | // CMICmdCmdSupportInfoMiCmdQuery 21 | // command class as an example. 22 | 23 | #pragma once 24 | 25 | // In-house headers: 26 | #include "MICmdBase.h" 27 | #include "MICmnMIValueList.h" 28 | #include "MICmnMIValueTuple.h" 29 | 30 | //++ 31 | //============================================================================ 32 | // Details: MI command class. MI commands derived from the command base class. 33 | // *this class implements MI command "target-select". 34 | // http://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Target-Manipulation.html#GDB_002fMI-Target-Manipulation 35 | //-- 36 | class CMICmdCmdTargetSelect : public CMICmdBase { 37 | // Statics: 38 | public: 39 | // Required by the CMICmdFactory when registering *this command 40 | static CMICmdBase *CreateSelf(); 41 | 42 | // Methods: 43 | public: 44 | /* ctor */ CMICmdCmdTargetSelect(); 45 | 46 | // Overridden: 47 | public: 48 | // From CMICmdInvoker::ICmd 49 | bool Execute() override; 50 | bool Acknowledge() override; 51 | bool ParseArgs() override; 52 | // From CMICmnBase 53 | /* dtor */ ~CMICmdCmdTargetSelect() override; 54 | 55 | // Attributes: 56 | private: 57 | const CMIUtilString m_constStrArgNamedType; 58 | const CMIUtilString m_constStrArgNamedParameters; 59 | }; 60 | 61 | //++ 62 | //============================================================================ 63 | // Details: MI command class. MI commands derived from the command base class. 64 | // *this class implements MI command "target-attach". 65 | // http://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Target-Manipulation.html#GDB_002fMI-Target-Manipulation 66 | //-- 67 | class CMICmdCmdTargetAttach : public CMICmdBase { 68 | // Statics: 69 | public: 70 | // Required by the CMICmdFactory when registering *this command 71 | static CMICmdBase *CreateSelf(); 72 | 73 | // Methods: 74 | public: 75 | /* ctor */ CMICmdCmdTargetAttach(); 76 | 77 | // Overridden: 78 | public: 79 | // From CMICmdInvoker::ICmd 80 | bool Execute() override; 81 | bool Acknowledge() override; 82 | bool ParseArgs() override; 83 | // From CMICmnBase 84 | /* dtor */ ~CMICmdCmdTargetAttach() override; 85 | 86 | // Attributes: 87 | private: 88 | const CMIUtilString m_constStrArgPid; 89 | const CMIUtilString m_constStrArgNamedFile; 90 | const CMIUtilString m_constStrArgWaitFor; 91 | }; 92 | 93 | //++ 94 | //============================================================================ 95 | // Details: MI command class. MI commands derived from the command base class. 96 | // *this class implements MI command "target-attach". 97 | // http://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Target-Manipulation.html#GDB_002fMI-Target-Manipulation 98 | //-- 99 | class CMICmdCmdTargetDetach : public CMICmdBase { 100 | // Statics: 101 | public: 102 | // Required by the CMICmdFactory when registering *this command 103 | static CMICmdBase *CreateSelf(); 104 | 105 | // Methods: 106 | public: 107 | /* ctor */ CMICmdCmdTargetDetach(); 108 | 109 | // Overridden: 110 | public: 111 | // From CMICmdInvoker::ICmd 112 | bool Execute() override; 113 | bool Acknowledge() override; 114 | bool ParseArgs() override; 115 | // From CMICmnBase 116 | /* dtor */ ~CMICmdCmdTargetDetach() override; 117 | }; 118 | -------------------------------------------------------------------------------- /src/MICmdCmdThread.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmdThread.h ----------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdThreadInfo interface. 10 | // 11 | // To implement new MI commands derive a new command class from the 12 | // command base 13 | // class. To enable the new command for interpretation add the new 14 | // command class 15 | // to the command factory. The files of relevance are: 16 | // MICmdCommands.cpp 17 | // MICmdBase.h / .cpp 18 | // MICmdCmd.h / .cpp 19 | // For an introduction to adding a new command see 20 | // CMICmdCmdSupportInfoMiCmdQuery 21 | // command class as an example. 22 | 23 | #pragma once 24 | 25 | // In-house headers: 26 | #include "MICmdBase.h" 27 | #include "MICmnMIValueList.h" 28 | #include "MICmnMIValueTuple.h" 29 | 30 | //++ 31 | //============================================================================ 32 | // Details: MI command class. MI commands derived from the command base class. 33 | // *this class implements MI command "thread-info". 34 | //-- 35 | class CMICmdCmdThreadInfo : public CMICmdBase { 36 | // Statics: 37 | public: 38 | // Required by the CMICmdFactory when registering *this command 39 | static CMICmdBase *CreateSelf(); 40 | 41 | // Methods: 42 | public: 43 | /* ctor */ CMICmdCmdThreadInfo(); 44 | 45 | // Overridden: 46 | public: 47 | // From CMICmdInvoker::ICmd 48 | bool Execute() override; 49 | bool Acknowledge() override; 50 | bool ParseArgs() override; 51 | // From CMICmnBase 52 | /* dtor */ ~CMICmdCmdThreadInfo() override; 53 | 54 | // Typedefs: 55 | private: 56 | typedef std::vector VecMIValueTuple_t; 57 | 58 | // Attributes: 59 | private: 60 | CMICmnMIValueTuple m_miValueTupleThread; 61 | bool m_bSingleThread; // True = yes single thread, false = multiple threads 62 | bool m_bThreadInvalid; // True = invalid, false = ok 63 | VecMIValueTuple_t m_vecMIValueTuple; 64 | const CMIUtilString m_constStrArgNamedThreadId; 65 | 66 | // mi value of current-thread-id if multiple threads are requested 67 | bool m_bHasCurrentThread; 68 | CMICmnMIValue m_miValueCurrThreadId; 69 | }; 70 | -------------------------------------------------------------------------------- /src/MICmdCmdTrace.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmdTrace.cpp ---------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdTraceStatus implementation. 10 | 11 | // In-house headers: 12 | #include "MICmdCmdTrace.h" 13 | #include "MICmnMIResultRecord.h" 14 | #include "MICmnMIValueConst.h" 15 | 16 | //++ 17 | // Details: CMICmdCmdTraceStatus constructor. 18 | // Type: Method. 19 | // Args: None. 20 | // Return: None. 21 | // Throws: None. 22 | //-- 23 | CMICmdCmdTraceStatus::CMICmdCmdTraceStatus() { 24 | // Command factory matches this name with that received from the stdin stream 25 | m_strMiCmd = "trace-status"; 26 | 27 | // Required by the CMICmdFactory when registering *this command 28 | m_pSelfCreatorFn = &CMICmdCmdTraceStatus::CreateSelf; 29 | } 30 | 31 | //++ 32 | // Details: CMICmdCmdTraceStatus destructor. 33 | // Type: Overrideable. 34 | // Args: None. 35 | // Return: None. 36 | // Throws: None. 37 | //-- 38 | CMICmdCmdTraceStatus::~CMICmdCmdTraceStatus() {} 39 | 40 | //++ 41 | // Details: The invoker requires this function. The command does work in this 42 | // function. 43 | // The command is likely to communicate with the LLDB SBDebugger in 44 | // here. 45 | // Type: Overridden. 46 | // Args: None. 47 | // Return: MIstatus::success - Functional succeeded. 48 | // MIstatus::failure - Functional failed. 49 | // Throws: None. 50 | //-- 51 | bool CMICmdCmdTraceStatus::Execute() { 52 | // Do nothing 53 | return MIstatus::success; 54 | } 55 | 56 | //++ 57 | // Details: The invoker requires this function. The command prepares a MI Record 58 | // Result 59 | // for the work carried out in the Execute(). 60 | // Type: Overridden. 61 | // Args: None. 62 | // Return: MIstatus::success - Functional succeeded. 63 | // MIstatus::failure - Functional failed. 64 | // Throws: None. 65 | //-- 66 | bool CMICmdCmdTraceStatus::Acknowledge() { 67 | const CMICmnMIValueConst miValueConst(MIRSRC(IDS_CMD_ERR_NOT_IMPLEMENTED)); 68 | const CMICmnMIValueResult miValueResult("msg", miValueConst); 69 | const CMICmnMIResultRecord miRecordResult( 70 | m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, 71 | miValueResult); 72 | m_miResultRecord = miRecordResult; 73 | 74 | return MIstatus::success; 75 | } 76 | 77 | //++ 78 | // Details: Required by the CMICmdFactory when registering *this command. The 79 | // factory 80 | // calls this function to create an instance of *this command. 81 | // Type: Static method. 82 | // Args: None. 83 | // Return: CMICmdBase * - Pointer to a new command. 84 | // Throws: None. 85 | //-- 86 | CMICmdBase *CMICmdCmdTraceStatus::CreateSelf() { 87 | return new CMICmdCmdTraceStatus(); 88 | } 89 | -------------------------------------------------------------------------------- /src/MICmdCmdTrace.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdCmdTrace.h -----------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: CMICmdCmdTraceStatus interface. 10 | // 11 | // To implement new MI commands derive a new command class from the 12 | // command base 13 | // class. To enable the new command for interpretation add the new 14 | // command class 15 | // to the command factory. The files of relevance are: 16 | // MICmdCommands.cpp 17 | // MICmdBase.h / .cpp 18 | // MICmdCmd.h / .cpp 19 | // For an introduction to adding a new command see 20 | // CMICmdCmdSupportInfoMiCmdQuery 21 | // command class as an example. 22 | 23 | #pragma once 24 | 25 | // In-house headers: 26 | #include "MICmdBase.h" 27 | 28 | //++ 29 | //============================================================================ 30 | // Details: MI command class. MI commands derived from the command base class. 31 | // *this class implements MI command "trace-status". 32 | //-- 33 | class CMICmdCmdTraceStatus : public CMICmdBase { 34 | // Statics: 35 | public: 36 | // Required by the CMICmdFactory when registering *this command 37 | static CMICmdBase *CreateSelf(); 38 | 39 | // Methods: 40 | public: 41 | /* ctor */ CMICmdCmdTraceStatus(); 42 | 43 | // Overridden: 44 | public: 45 | // From CMICmdInvoker::ICmd 46 | bool Execute() override; 47 | bool Acknowledge() override; 48 | // From CMICmnBase 49 | /* dtor */ ~CMICmdCmdTraceStatus() override; 50 | }; 51 | -------------------------------------------------------------------------------- /src/MICmdCommands.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdCommands.h -----------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | namespace MICmnCommands { 12 | 13 | //++ 14 | //============================================================================ 15 | // Details: MI Command are instantiated and registered automatically with the 16 | // Command Factory 17 | //-- 18 | bool RegisterAll(); 19 | } // namespace MICmnCommands 20 | -------------------------------------------------------------------------------- /src/MICmdData.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmdData.cpp -------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // In-house headers: 10 | #include "MICmdData.h" 11 | -------------------------------------------------------------------------------- /src/MICmdData.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdData.h ---------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmnResources.h" 13 | 14 | //++ 15 | //============================================================================ 16 | // Details: MI command metadata. Holds the command's name, MI number and options 17 | // as found on stdin. Holds the command's MI output (written to 18 | // stdout). 19 | //-- 20 | struct SMICmdData { 21 | SMICmdData() 22 | : id(0), bCmdValid(false), bCmdExecutedSuccessfully(false), 23 | bMIOldStyle(false), bHasResultRecordExtra(false) {} 24 | 25 | MIuint id; // A command's unique ID i.e. GUID 26 | CMIUtilString strMiCmdToken; // The command's MI token (a number) 27 | CMIUtilString strMiCmd; // The command's name 28 | CMIUtilString strMiCmdOption; // The command's arguments or options 29 | CMIUtilString strMiCmdAll; // The text as received from the client 30 | CMIUtilString 31 | strMiCmdResultRecord; // Each command forms 1 response to its input 32 | CMIUtilString strMiCmdResultRecordExtra; // Hack command produce more response 33 | // text to help the client because of 34 | // using LLDB 35 | bool bCmdValid; // True = Valid MI format command, false = invalid 36 | bool bCmdExecutedSuccessfully; // True = Command finished successfully, false 37 | // = Did not start/did not complete 38 | CMIUtilString strErrorDescription; // Command failed this is why 39 | bool bMIOldStyle; // True = format "3thread", false = format "3-thread" 40 | bool bHasResultRecordExtra; // True = Yes command produced additional MI 41 | // output to its 1 line response, false = no extra 42 | // MI output formed 43 | 44 | void Clear() { 45 | id = 0; 46 | strMiCmdToken.clear(); 47 | strMiCmd = MIRSRC(IDS_CMD_ERR_CMD_RUN_BUT_NO_ACTION); 48 | strMiCmdOption.clear(); 49 | strMiCmdAll.clear(); 50 | strMiCmdResultRecord.clear(); 51 | strMiCmdResultRecordExtra.clear(); 52 | bCmdValid = false; 53 | bCmdExecutedSuccessfully = false; 54 | strErrorDescription.clear(); 55 | bMIOldStyle = false; 56 | bHasResultRecordExtra = false; 57 | } 58 | }; 59 | -------------------------------------------------------------------------------- /src/MICmdFactory.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdFactory.h ------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // Third party headers 12 | #include 13 | 14 | // In-house headers: 15 | #include "MICmnBase.h" 16 | #include "MIUtilSingletonBase.h" 17 | 18 | // Declarations: 19 | class CMICmdBase; 20 | struct SMICmdData; 21 | 22 | //++ 23 | //============================================================================ 24 | // Details: MI Command Factory. Holds a list of registered MI commands that 25 | // MI application understands to interpret. Creates commands objects. 26 | // The Command Factory is carried out in the main thread. 27 | // A singleton class. 28 | //-- 29 | class CMICmdFactory : public CMICmnBase, public MI::ISingleton { 30 | friend class MI::ISingleton; 31 | 32 | // Typedefs: 33 | public: 34 | typedef CMICmdBase *(*CmdCreatorFnPtr)(); 35 | 36 | // Class: 37 | public: 38 | //++ 39 | // Description: Command's factory's interface for commands to implement. 40 | //-- 41 | class ICmd { 42 | public: 43 | virtual const CMIUtilString &GetMiCmd() const = 0; 44 | virtual CmdCreatorFnPtr GetCmdCreatorFn() const = 0; 45 | // virtual CMICmdBase * CreateSelf( void ) = 0; // Not 46 | // possible as require a static creator 47 | // function in the command class, here for awareness 48 | 49 | /* dtor */ virtual ~ICmd() {} 50 | }; 51 | 52 | // Methods: 53 | public: 54 | bool Initialize() override; 55 | bool Shutdown() override; 56 | bool CmdRegister(const CMIUtilString &vMiCmd, CmdCreatorFnPtr vCmdCreateFn); 57 | bool CmdCreate(const CMIUtilString &vMiCmd, const SMICmdData &vCmdData, 58 | CMICmdBase *&vpNewCmd); 59 | bool CmdExist(const CMIUtilString &vMiCmd) const; 60 | 61 | // Methods: 62 | private: 63 | /* ctor */ CMICmdFactory(); 64 | /* ctor */ CMICmdFactory(const CMICmdFactory &); 65 | void operator=(const CMICmdFactory &); 66 | 67 | bool HaveAlready(const CMIUtilString &vMiCmd) const; 68 | bool IsValid(const CMIUtilString &vMiCmd) const; 69 | 70 | // Overridden: 71 | private: 72 | // From CMICmnBase 73 | /* dtor */ ~CMICmdFactory() override; 74 | 75 | // Typedefs: 76 | private: 77 | typedef std::map MapMiCmdToCmdCreatorFn_t; 78 | typedef std::pair 79 | MapPairMiCmdToCmdCreatorFn_t; 80 | 81 | // Attributes: 82 | private: 83 | MapMiCmdToCmdCreatorFn_t m_mapMiCmdToCmdCreatorFn; 84 | }; 85 | -------------------------------------------------------------------------------- /src/MICmdInterpreter.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdInterpreter.h --------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmdData.h" 13 | #include "MICmnBase.h" 14 | #include "MIUtilSingletonBase.h" 15 | 16 | // Declarations: 17 | class CMICmdFactory; 18 | 19 | //++ 20 | //============================================================================ 21 | // Details: MI command interpreter. It takes text data from the MI driver 22 | // (which got it from Stdin singleton) and validate the text to see if 23 | // matches Machine Interface (MI) format and commands defined in the 24 | // MI application. 25 | // A singleton class. 26 | //-- 27 | class CMICmdInterpreter : public CMICmnBase, 28 | public MI::ISingleton { 29 | friend MI::ISingleton; 30 | 31 | // Methods: 32 | public: 33 | // Methods: 34 | public: 35 | bool Initialize() override; 36 | bool Shutdown() override; 37 | bool ValidateIsMi(const CMIUtilString &vTextLine, bool &vwbYesValid, 38 | bool &vwbCmdNotInCmdFactor, SMICmdData &rwCmdData); 39 | 40 | // Methods: 41 | private: 42 | /* ctor */ CMICmdInterpreter(); 43 | /* ctor */ CMICmdInterpreter(const CMICmdInterpreter &); 44 | void operator=(const CMICmdInterpreter &); 45 | 46 | bool HasCmdFactoryGotMiCmd(const SMICmdData &vCmdData) const; 47 | bool MiHasCmdTokenEndingHyphen(const CMIUtilString &vTextLine); 48 | bool MiHasCmdTokenEndingAlpha(const CMIUtilString &vTextLine); 49 | bool MiHasCmd(const CMIUtilString &vTextLine); 50 | bool MiHasCmdTokenPresent(const CMIUtilString &vTextLine); 51 | const SMICmdData &MiGetCmdData() const; 52 | 53 | // Overridden: 54 | private: 55 | // From CMICmnBase 56 | /* dtor */ ~CMICmdInterpreter() override; 57 | 58 | // Attributes: 59 | private: 60 | SMICmdData m_miCmdData; // Filled in on each new line being interpreted 61 | CMICmdFactory &m_rCmdFactory; 62 | }; 63 | -------------------------------------------------------------------------------- /src/MICmdInvoker.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdInvoker.h ------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // Third party headers 12 | #include 13 | 14 | // In-house headers: 15 | #include "MICmdData.h" 16 | #include "MICmdMgrSetCmdDeleteCallback.h" 17 | #include "MICmnBase.h" 18 | #include "MIUtilSingletonBase.h" 19 | 20 | // Declarations: 21 | class CMICmdBase; 22 | class CMICmnStreamStdout; 23 | 24 | //++ 25 | //============================================================================ 26 | // Details: MI Command Invoker. The Invoker works on the command pattern design. 27 | // There two main jobs; action command Execute() function, followed by 28 | // the command's Acknowledge() function. When a command has finished 29 | // its 30 | // execute function it returns to the invoker. The invoker then calls 31 | // the 32 | // command's Acknowledge() function to do more work, form and give 33 | // back a MI result. In the meantime the Command Monitor is monitoring 34 | // the each command doing their Execute() function work so they do not 35 | // exceed a time limit which if it exceeds informs the command(s) to 36 | // stop work. 37 | // The work by the Invoker is carried out in the main thread. 38 | // The Invoker takes ownership of any commands created which means it 39 | // is the only object to delete them when a command is finished 40 | // working. 41 | // A singleton class. 42 | //-- 43 | class CMICmdInvoker : public CMICmnBase, 44 | public CMICmdMgrSetCmdDeleteCallback::ICallback, 45 | public MI::ISingleton { 46 | friend class MI::ISingleton; 47 | 48 | // Class: 49 | public: 50 | //++ 51 | // Description: Invoker's interface for commands to implement. 52 | //-- 53 | class ICmd { 54 | public: 55 | virtual bool Acknowledge() = 0; 56 | virtual bool Execute() = 0; 57 | virtual bool ParseArgs() = 0; 58 | virtual void SetCmdData(const SMICmdData &vCmdData) = 0; 59 | virtual const SMICmdData &GetCmdData() const = 0; 60 | virtual const CMIUtilString &GetErrorDescription() const = 0; 61 | virtual void CmdFinishedTellInvoker() const = 0; 62 | virtual const CMIUtilString &GetMIResultRecord() const = 0; 63 | virtual const CMIUtilString &GetMIResultRecordExtra() const = 0; 64 | virtual bool HasMIResultRecordExtra() const = 0; 65 | 66 | /* dtor */ virtual ~ICmd() {} 67 | }; 68 | 69 | // Methods: 70 | public: 71 | bool Initialize() override; 72 | bool Shutdown() override; 73 | bool CmdExecute(CMICmdBase &vCmd); 74 | bool CmdExecuteFinished(CMICmdBase &vCmd); 75 | 76 | // Typedefs: 77 | private: 78 | typedef std::map MapCmdIdToCmd_t; 79 | typedef std::pair MapPairCmdIdToCmd_t; 80 | 81 | // Methods: 82 | private: 83 | /* ctor */ CMICmdInvoker(); 84 | /* ctor */ CMICmdInvoker(const CMICmdInvoker &); 85 | void operator=(const CMICmdInvoker &); 86 | void CmdDeleteAll(); 87 | bool CmdDelete(const MIuint vCmdId, const bool vbYesDeleteCmd = false); 88 | bool CmdAdd(const CMICmdBase &vCmd); 89 | bool CmdStdout(const SMICmdData &vCmdData) const; 90 | void CmdCauseAppExit(const CMICmdBase &vCmd) const; 91 | 92 | // Overridden: 93 | private: 94 | // From CMICmnBase 95 | /* dtor */ ~CMICmdInvoker() override; 96 | // From CMICmdMgrSetCmdDeleteCallback::ICallback 97 | void Delete(SMICmdData &vCmd) override; 98 | 99 | // Attributes: 100 | private: 101 | MapCmdIdToCmd_t m_mapCmdIdToCmd; 102 | CMICmnStreamStdout &m_rStreamOut; 103 | }; 104 | -------------------------------------------------------------------------------- /src/MICmdMgr.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdMgr.h ----------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // Third party headers 12 | #include 13 | 14 | // In-house headers: 15 | #include "MICmdBase.h" 16 | #include "MICmdMgrSetCmdDeleteCallback.h" 17 | #include "MICmnBase.h" 18 | #include "MIUtilSingletonBase.h" 19 | 20 | // Declarations: 21 | class CMICmdInterpreter; 22 | class CMICmdFactory; 23 | class CMICmdInvoker; 24 | class CMICmdBase; 25 | 26 | //++ 27 | //============================================================================ 28 | // Details: MI command manager. Oversees command operations, controls command 29 | // production and the running of commands. 30 | // Command Invoker, Command Factory and Command Monitor while 31 | // independent 32 | // units are overseen/managed by *this manager. 33 | // A singleton class. 34 | //-- 35 | class CMICmdMgr : public CMICmnBase, public MI::ISingleton { 36 | friend class MI::ISingleton; 37 | 38 | // Methods: 39 | public: 40 | bool Initialize() override; 41 | bool Shutdown() override; 42 | 43 | bool CmdInterpret(const CMIUtilString &vTextLine, bool &vwbYesValid, 44 | bool &vwbCmdNotInCmdFactor, SMICmdData &rwCmdData); 45 | bool CmdExecute(const SMICmdData &vCmdData); 46 | bool CmdDelete(SMICmdData vCmdData); 47 | bool CmdRegisterForDeleteNotification( 48 | CMICmdMgrSetCmdDeleteCallback::ICallback &vObject); 49 | bool CmdUnregisterForDeleteNotification( 50 | CMICmdMgrSetCmdDeleteCallback::ICallback &vObject); 51 | 52 | // Methods: 53 | private: 54 | /* ctor */ CMICmdMgr(); 55 | /* ctor */ CMICmdMgr(const CMICmdMgr &); 56 | void operator=(const CMICmdMgr &); 57 | 58 | // Overridden: 59 | public: 60 | // From CMICmnBase 61 | /* dtor */ ~CMICmdMgr() override; 62 | 63 | // Attributes: 64 | private: 65 | CMICmdInterpreter &m_interpretor; 66 | CMICmdFactory &m_factory; 67 | CMICmdInvoker &m_invoker; 68 | CMICmdMgrSetCmdDeleteCallback::CSetClients m_setCmdDeleteCallback; 69 | }; 70 | -------------------------------------------------------------------------------- /src/MICmdMgrSetCmdDeleteCallback.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmdMgrSetCmdDeleteCallback.cpp ------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // In-house headers: 10 | #include "MICmdMgrSetCmdDeleteCallback.h" 11 | 12 | namespace CMICmdMgrSetCmdDeleteCallback { 13 | 14 | //++ 15 | // Details: CSetClients constructor. 16 | // Type: Method. 17 | // Args: None. 18 | // Return: None. 19 | // Throws: None. 20 | //-- 21 | CSetClients::CSetClients() : m_bClientUnregistered(false) {} 22 | 23 | //++ 24 | // Details: CSetClients destructor. 25 | // Type: Method. 26 | // Args: None. 27 | // Return: None. 28 | // Throws: None. 29 | //-- 30 | CSetClients::~CSetClients() {} 31 | 32 | //++ 33 | // Details: Register an object to be called when a command object is deleted. 34 | // Type: Method. 35 | // Args: vObject - (R) A new interested client. 36 | // Return: MIstatus::success - Functional succeeded. 37 | // MIstatus::failure - Functional failed. 38 | // Throws: None. 39 | //-- 40 | bool CSetClients::Register(ICallback &vObject) { 41 | insert(&vObject); 42 | 43 | return MIstatus::success; 44 | } 45 | 46 | //++ 47 | // Details: Unregister an object from being called when a command object is 48 | // deleted. 49 | // Type: Method. 50 | // Args: vObject - (R) The was interested client. 51 | // Return: MIstatus::success - Functional succeeded. 52 | // MIstatus::failure - Functional failed. 53 | // Throws: None. 54 | //-- 55 | bool CSetClients::Unregister(ICallback &vObject) { 56 | m_bClientUnregistered = true; 57 | erase(&vObject); 58 | 59 | return MIstatus::success; 60 | } 61 | 62 | //++ 63 | // Details: Iterate all interested clients and tell them a command is being 64 | // deleted. 65 | // Type: Method. 66 | // Args: vCmd - (RW) The command to be deleted. 67 | // Return: MIstatus::success - Functional succeeded. 68 | // MIstatus::failure - Functional failed. 69 | // Throws: None. 70 | //-- 71 | void CSetClients::Delete(SMICmdData &vCmd) { 72 | m_bClientUnregistered = false; // Reset 73 | iterator it = begin(); 74 | while (it != end()) { 75 | ICallback *pObj = *it; 76 | pObj->Delete(vCmd); 77 | 78 | if (m_bClientUnregistered) { 79 | m_bClientUnregistered = false; // Reset 80 | it = begin(); 81 | } else 82 | // Next 83 | ++it; 84 | } 85 | } 86 | 87 | } // namespace CMICmdMgrSetCmdDeleteCallback 88 | -------------------------------------------------------------------------------- /src/MICmdMgrSetCmdDeleteCallback.h: -------------------------------------------------------------------------------- 1 | //===-- MICmdMgrSetCmdDeleteCallback.h --------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | //-- 9 | 10 | #pragma once 11 | 12 | // Third party headers: 13 | #include 14 | 15 | // In-house headers: 16 | #include "MICmnBase.h" 17 | 18 | // Declarations: 19 | struct SMICmdData; 20 | 21 | namespace CMICmdMgrSetCmdDeleteCallback { 22 | 23 | //++ 24 | //============================================================================ 25 | // Details: MI Command Manager interface for client call back. 26 | // Objects that want to be notified of a command being deleted 27 | // inherit this interface and register interest in command object 28 | // deletion. An object deleting a command must not do it itself but 29 | // call 30 | // the Command Manager CmdDelete() function to delete a command object. 31 | //-- 32 | class ICallback { 33 | public: 34 | virtual void Delete(SMICmdData &vCmd) = 0; 35 | 36 | /* dtor */ virtual ~ICallback() {} 37 | }; 38 | 39 | //++ 40 | //============================================================================ 41 | // Details: MI Command Manager container for clients registered interest in 42 | // command 43 | // objects being deleted. Objects register an interest so when a 44 | // command 45 | // is to be deleted that object wanting the delete calls the Command 46 | // Manager to delete the command object. In so do all other registered 47 | // objects get called to about the deletion including the object 48 | // wanting 49 | // to do the delete in the first place. 50 | //-- 51 | class CSetClients : public std::set, public CMICmnBase { 52 | // Methods: 53 | public: 54 | /* ctor */ CSetClients(); 55 | 56 | bool Register(class ICallback &vObject); 57 | bool Unregister(class ICallback &vObject); 58 | void Delete(SMICmdData &vCmdData); 59 | 60 | // Overridden: 61 | public: 62 | // From CMICmnBase 63 | /* dtor */ ~CSetClients() override; 64 | 65 | // Attributes: 66 | private: 67 | bool m_bClientUnregistered; // True = yes while deleting a client 68 | // unregistered, false = no client unregistered 69 | // during deletion 70 | }; 71 | 72 | } // namespace CMICmdMgrSetCmdDeleteCallback 73 | -------------------------------------------------------------------------------- /src/MICmnBase.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmnBase.cpp -------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Third party headers 10 | #include 11 | 12 | // In-house headers: 13 | #include "MICmnBase.h" 14 | #include "MICmnLog.h" 15 | #include "MICmnStreamStderr.h" 16 | 17 | //++ 18 | // Details: CMICmnBase constructor. 19 | // Type: Method. 20 | // Args: None. 21 | // Return: None. 22 | // Throws: None. 23 | //-- 24 | CMICmnBase::CMICmnBase() 25 | : m_strMILastErrorDescription(CMIUtilString()), m_bInitialized(false), 26 | m_pLog(&CMICmnLog::Instance()), m_clientUsageRefCnt(0) {} 27 | 28 | //++ 29 | // Details: CMICmnBase destructor. 30 | // Type: Overrideable. 31 | // Args: None. 32 | // Return: None. 33 | // Throws: None. 34 | //-- 35 | CMICmnBase::~CMICmnBase() { m_pLog = nullptr; } 36 | 37 | //++ 38 | // Details: Retrieve whether *this object has an error description set. 39 | // Type: Method. 40 | // Args: None. 41 | // Return: bool - True = Yes already defined, false = empty description. 42 | // Throws: None. 43 | //-- 44 | bool CMICmnBase::HaveErrorDescription() const { 45 | return m_strMILastErrorDescription.empty(); 46 | } 47 | 48 | //++ 49 | // Details: Retrieve MI's last error condition. 50 | // Type: Method. 51 | // Args: None. 52 | // Return: CMIUtilString & - Text description. 53 | // Throws: None. 54 | //-- 55 | const CMIUtilString &CMICmnBase::GetErrorDescription() const { 56 | return m_strMILastErrorDescription; 57 | } 58 | 59 | //++ 60 | // Details: Set MI's error condition description. This may be accessed by 61 | // clients and 62 | // seen by users. Message is available to the client using the server 63 | // and sent 64 | // to the Logger. 65 | // Type: Method. 66 | // Args: vrTxt - (R) Text description. 67 | // Return: None. 68 | // Throws: None. 69 | //-- 70 | void CMICmnBase::SetErrorDescription(const CMIUtilString &vrTxt) const { 71 | m_strMILastErrorDescription = vrTxt; 72 | if (!vrTxt.empty()) { 73 | const CMIUtilString txt(CMIUtilString::Format("Error: %s", vrTxt.c_str())); 74 | CMICmnStreamStderr::Instance().Write(txt); 75 | } 76 | } 77 | 78 | //++ 79 | // Details: Set MI's error condition description. This may be accessed by 80 | // clients and 81 | // seen by users. Message is available to the client using the server 82 | // and sent 83 | // to the Logger. 84 | // Type: Method. 85 | // Args: vrTxt - (R) Text description. 86 | // Return: None. 87 | // Throws: None. 88 | //-- 89 | void CMICmnBase::SetErrorDescriptionNoLog(const CMIUtilString &vrTxt) const { 90 | m_strMILastErrorDescription = vrTxt; 91 | } 92 | 93 | //++ 94 | // Details: Clear MI's error condition description. 95 | // Type: Method. 96 | // Args: None. 97 | // Return: None. 98 | // Throws: None. 99 | //-- 100 | void CMICmnBase::ClrErrorDescription() const { 101 | m_strMILastErrorDescription.clear(); 102 | } 103 | 104 | //++ 105 | // Details: Set MI's error condition description. This may be accessed by 106 | // clients and 107 | // seen by users. Message is available to the client using the server 108 | // and sent 109 | // to the Logger. 110 | // Type: Method. 111 | // Args: vFormat - (R) Format string. 112 | // ... - (R) Variable number of CMIUtilString type objects. 113 | // Return: None. 114 | // Throws: None. 115 | //-- 116 | void CMICmnBase::SetErrorDescriptionn(const char *vFormat, ...) const { 117 | va_list args; 118 | va_start(args, vFormat); 119 | CMIUtilString strResult = CMIUtilString::FormatValist(vFormat, args); 120 | va_end(args); 121 | 122 | SetErrorDescription(strResult); 123 | } 124 | -------------------------------------------------------------------------------- /src/MICmnBase.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnBase.h ---------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MIDataTypes.h" 13 | #include "MIUtilString.h" 14 | 15 | // Declarations: 16 | class CMICmnLog; 17 | 18 | //++ 19 | //============================================================================ 20 | // Details: MI common code implementation base class. 21 | //-- 22 | class CMICmnBase { 23 | // Methods: 24 | public: 25 | /* ctor */ CMICmnBase(); 26 | 27 | bool HaveErrorDescription() const; 28 | const CMIUtilString &GetErrorDescription() const; 29 | void SetErrorDescription(const CMIUtilString &vrTxt) const; 30 | void SetErrorDescriptionn(const char *vFormat, ...) const; 31 | void SetErrorDescriptionNoLog(const CMIUtilString &vrTxt) const; 32 | void ClrErrorDescription() const; 33 | 34 | // Overrideable: 35 | public: 36 | /* dtor */ virtual ~CMICmnBase(); 37 | 38 | // Attributes: 39 | protected: 40 | mutable CMIUtilString m_strMILastErrorDescription; 41 | bool m_bInitialized; // True = yes successfully initialized, false = no yet or 42 | // failed 43 | CMICmnLog *m_pLog; // Allow all derived classes to use the logger 44 | MIint m_clientUsageRefCnt; // Count of client using *this object so not 45 | // shutdown() object to early 46 | }; 47 | -------------------------------------------------------------------------------- /src/MICmnConfig.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnConfig.h -------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | //-- 9 | #pragma once 10 | 11 | // 1 = Show debug process attach modal dialog, 0 = do not show 12 | // For windows only ATM, other OS's code is an infinite loop which a debugger 13 | // must change a value to continue 14 | #define MICONFIG_DEBUG_SHOW_ATTACH_DBG_DLG 0 15 | 16 | // 1 = Write to MI's Log file warnings about commands that did not handle 17 | // arguments or 18 | // options present to them by the driver's client, 0 = no warnings given 19 | #define MICONFIG_GIVE_WARNING_CMD_ARGS_NOT_HANDLED 1 20 | -------------------------------------------------------------------------------- /src/MICmnLLDBBroadcaster.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmnLLDBBroadcaster.cpp --------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // In-house headers: 10 | #include "MICmnLLDBBroadcaster.h" 11 | 12 | //++ 13 | // Details: CMICmnLLDBBroadcaster constructor. 14 | // Type: Method. 15 | // Args: None. 16 | // Return: None. 17 | // Throws: None. 18 | //-- 19 | CMICmnLLDBBroadcaster::CMICmnLLDBBroadcaster() 20 | : lldb::SBBroadcaster("MI driver") {} 21 | 22 | //++ 23 | // Details: CMICmnLLDBBroadcaster destructor. 24 | // Type: Overridable. 25 | // Args: None. 26 | // Return: None. 27 | // Throws: None. 28 | //-- 29 | CMICmnLLDBBroadcaster::~CMICmnLLDBBroadcaster() { Shutdown(); } 30 | 31 | //++ 32 | // Details: Initialize resources for *this broadcaster object. 33 | // Type: Method. 34 | // Args: None. 35 | // Return: MIstatus::success - Functionality succeeded. 36 | // MIstatus::failure - Functionality failed. 37 | // Throws: None. 38 | //-- 39 | bool CMICmnLLDBBroadcaster::Initialize() { 40 | m_clientUsageRefCnt++; 41 | 42 | if (m_bInitialized) 43 | return MIstatus::success; 44 | 45 | m_bInitialized = MIstatus::success; 46 | 47 | return m_bInitialized; 48 | } 49 | 50 | //++ 51 | // Details: Release resources for *this broadcaster object. 52 | // Type: Method. 53 | // Args: None. 54 | // Return: MIstatus::success - Functionality succeeded. 55 | // MIstatus::failure - Functionality failed. 56 | // Throws: None. 57 | //-- 58 | bool CMICmnLLDBBroadcaster::Shutdown() { 59 | if (--m_clientUsageRefCnt > 0) 60 | return MIstatus::success; 61 | 62 | if (!m_bInitialized) 63 | return MIstatus::success; 64 | 65 | m_bInitialized = false; 66 | 67 | return MIstatus::success; 68 | } 69 | -------------------------------------------------------------------------------- /src/MICmnLLDBBroadcaster.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnLLDBBroadcaster.h ----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmnBase.h" 13 | #include "MIUtilSingletonBase.h" 14 | #include "lldb/API/SBBroadcaster.h" 15 | 16 | //++ 17 | //============================================================================ 18 | // Details: MI derived class from LLDB SBBroadcaster API. 19 | // 20 | // *** This class (files) is a place holder until we know we need it or 21 | // *** not 22 | // 23 | // A singleton class. 24 | //-- 25 | class CMICmnLLDBBroadcaster : public CMICmnBase, 26 | public lldb::SBBroadcaster, 27 | public MI::ISingleton { 28 | friend MI::ISingleton; 29 | 30 | // Methods: 31 | public: 32 | bool Initialize() override; 33 | bool Shutdown() override; 34 | // Methods: 35 | private: 36 | /* ctor */ CMICmnLLDBBroadcaster(); 37 | /* ctor */ CMICmnLLDBBroadcaster(const CMICmnLLDBBroadcaster &); 38 | void operator=(const CMICmnLLDBBroadcaster &); 39 | 40 | // Overridden: 41 | private: 42 | // From CMICmnBase 43 | /* dtor */ ~CMICmnLLDBBroadcaster() override; 44 | }; 45 | -------------------------------------------------------------------------------- /src/MICmnLLDBProxySBValue.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnLLDBProxySBValue.h ---------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // Third Party Headers: 12 | #include "lldb/API/SBValue.h" 13 | 14 | // In-house headers: 15 | #include "MIDataTypes.h" 16 | 17 | // Declarations: 18 | class CMIUtilString; 19 | 20 | //++ 21 | //============================================================================ 22 | // Details: MI proxy wrapper class to lldb::SBValue. The class provides 23 | // functionality 24 | // to assist in the use of SBValue's particular function usage. 25 | //-- 26 | class CMICmnLLDBProxySBValue { 27 | // Statics: 28 | public: 29 | static bool GetValueAsSigned(const lldb::SBValue &vrValue, MIint64 &vwValue); 30 | static bool GetValueAsUnsigned(const lldb::SBValue &vrValue, 31 | MIuint64 &vwValue); 32 | static bool GetCString(const lldb::SBValue &vrValue, 33 | CMIUtilString &vwCString); 34 | }; 35 | -------------------------------------------------------------------------------- /src/MICmnLLDBUtilSBValue.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnLLDBUtilSBValue.h ----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // Third Party Headers: 12 | #include "lldb/API/SBValue.h" 13 | 14 | // In-house headers: 15 | #include "MICmnMIValueTuple.h" 16 | #include "MIDataTypes.h" 17 | 18 | // Declarations: 19 | class CMIUtilString; 20 | 21 | //++ 22 | //============================================================================ 23 | // Details: Utility helper class to lldb::SBValue. Using a lldb::SBValue extract 24 | // value object information to help form verbose debug information. 25 | //-- 26 | class CMICmnLLDBUtilSBValue { 27 | // Methods: 28 | public: 29 | /* ctor */ CMICmnLLDBUtilSBValue(const lldb::SBValue &vrValue, 30 | const bool vbHandleCharType = false, 31 | const bool vbHandleArrayType = true); 32 | /* dtor */ ~CMICmnLLDBUtilSBValue(); 33 | // 34 | CMIUtilString GetName() const; 35 | CMIUtilString GetValue(const bool vbExpandAggregates = false) const; 36 | CMIUtilString GetTypeName() const; 37 | CMIUtilString GetTypeNameDisplay() const; 38 | bool IsCharType() const; 39 | bool IsFirstChildCharType() const; 40 | bool IsPointeeCharType() const; 41 | bool IsIntegerType() const; 42 | bool IsPointerType() const; 43 | bool IsArrayType() const; 44 | bool IsLLDBVariable() const; 45 | bool IsNameUnknown() const; 46 | bool IsValueUnknown() const; 47 | bool IsValid() const; 48 | bool HasName() const; 49 | 50 | // Methods: 51 | private: 52 | template 53 | CMIUtilString 54 | ReadCStringFromHostMemory(lldb::SBValue &vrValue, 55 | const MIuint vnMaxLen = UINT32_MAX) const; 56 | bool GetSimpleValue(const bool vbHandleArrayType, 57 | CMIUtilString &vrValue) const; 58 | bool GetCompositeValue(const bool vbPrintFieldNames, 59 | CMICmnMIValueTuple &vwrMiValueTuple, 60 | const MIuint vnDepth = 1) const; 61 | CMIUtilString 62 | GetValueSummary(bool valueOnly, 63 | const CMIUtilString &failVal = CMIUtilString()) const; 64 | 65 | // Statics: 66 | private: 67 | static bool IsCharBasicType(lldb::BasicType eType); 68 | 69 | // Attributes: 70 | private: 71 | lldb::SBValue &m_rValue; 72 | bool m_bValidSBValue; // True = SBValue is a valid object, false = not valid. 73 | bool m_bHandleCharType; // True = Yes return text molding to char type, false 74 | // = just return data. 75 | bool m_bHandleArrayType; // True = Yes return special stub for array type, 76 | // false = just return data. 77 | }; 78 | -------------------------------------------------------------------------------- /src/MICmnLogMediumFile.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnLogMediumFile.h ------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmnBase.h" 13 | #include "MICmnLog.h" 14 | #include "MIUtilDateTimeStd.h" 15 | #include "MIUtilFileStd.h" 16 | #include "MIUtilString.h" 17 | 18 | //++ 19 | //============================================================================ 20 | // Details: MI common code implementation class. Logs application fn 21 | // trace/message/ 22 | // error messages to a file. Used as part of the CMICmnLog Logger 23 | // system. When instantiated *this object is register with the Logger 24 | // which the Logger when given data to write to registered medium comes 25 | // *this medium. 26 | // Singleton class. 27 | //-- 28 | class CMICmnLogMediumFile : public CMICmnBase, public CMICmnLog::IMedium { 29 | // Statics: 30 | public: 31 | static CMICmnLogMediumFile &Instance(); 32 | 33 | // Methods: 34 | public: 35 | bool SetHeaderTxt(const CMIUtilString &vText); 36 | bool SetVerbosity(const MIuint veType); 37 | MIuint GetVerbosity() const; 38 | const CMIUtilString &GetFileName() const; 39 | const CMIUtilString &GetFileNamePath() const; 40 | bool IsOk() const; 41 | bool IsFileExist() const; 42 | const CMIUtilString &GetLineReturn() const; 43 | bool SetDirectory(const CMIUtilString &vPath); 44 | 45 | // Overridden: 46 | public: 47 | // From CMICmnBase 48 | /* dtor */ ~CMICmnLogMediumFile() override; 49 | // From CMICmnLog::IMedium 50 | bool Initialize() override; 51 | const CMIUtilString &GetName() const override; 52 | bool Write(const CMIUtilString &vData, 53 | const CMICmnLog::ELogVerbosity veType) override; 54 | const CMIUtilString &GetError() const override; 55 | bool Shutdown() override; 56 | 57 | // Methods: 58 | private: 59 | /* ctor */ CMICmnLogMediumFile(); 60 | /* ctor */ CMICmnLogMediumFile(const CMICmnLogMediumFile &); 61 | void operator=(const CMICmnLogMediumFile &); 62 | 63 | bool FileWriteEnglish(const CMIUtilString &vData); 64 | bool FileFormFileNamePath(); 65 | CMIUtilString MassagedData(const CMIUtilString &vData, 66 | const CMICmnLog::ELogVerbosity veType); 67 | bool FileWriteHeader(); 68 | char ConvertLogVerbosityTypeToId(const CMICmnLog::ELogVerbosity veType) const; 69 | CMIUtilString ConvertCr(const CMIUtilString &vData) const; 70 | 71 | // Attributes: 72 | private: 73 | const CMIUtilString m_constThisMediumName; 74 | const CMIUtilString m_constMediumFileNameFormat; 75 | // 76 | CMIUtilString m_strMediumFileName; 77 | CMIUtilString m_strMediumFileDirectory; 78 | CMIUtilString m_fileNamePath; 79 | MIuint m_eVerbosityType; 80 | CMIUtilString m_strDate; 81 | CMIUtilString m_fileHeaderTxt; 82 | CMIUtilFileStd m_file; 83 | CMIUtilDateTimeStd m_dateTime; 84 | }; 85 | -------------------------------------------------------------------------------- /src/MICmnMIOutOfBandRecord.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnMIOutOfBandRecord.h --------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmnBase.h" 13 | #include "MICmnMIValueConst.h" 14 | #include "MICmnMIValueResult.h" 15 | #include "MIUtilString.h" 16 | 17 | //++ 18 | //============================================================================ 19 | // Details: MI common code MI Out-of-band (Async) Record class. A class that 20 | // encapsulates 21 | // MI result record data and the forming/format of data added to it. 22 | // Out-of-band records are used to notify the GDB/MI client of 23 | // additional 24 | // changes that have occurred. Those changes can either be a 25 | // consequence 26 | // of GDB/MI (e.g., a breakpoint modified) or a result of target 27 | // activity 28 | // (e.g., target stopped). 29 | // The syntax is as follows: 30 | // "*" type ( "," result )* 31 | // type ==> running | stopped 32 | // 33 | // The Out-of-band record can be retrieve at any time *this object is 34 | // instantiated so unless work is done on *this Out-of-band record then 35 | // it is 36 | // possible to return a malformed Out-of-band record. If nothing has 37 | // been set 38 | // or added to *this MI Out-of-band record object then text "" 39 | // will 40 | // be returned. 41 | // 42 | // More information see: 43 | // http://ftp.gnu.org/old-gnu/Manuals/gdb-5.1.1/html_chapter/gdb_22.html// 44 | //-- 45 | class CMICmnMIOutOfBandRecord : public CMICmnBase { 46 | // Enumerations: 47 | public: 48 | //++ 49 | // Details: Enumeration of the type of Out-of-band for *this Out-of-band 50 | // record 51 | //-- 52 | enum OutOfBand_e { 53 | eOutOfBand_Running = 0, 54 | eOutOfBand_Stopped, 55 | eOutOfBand_BreakPointCreated, 56 | eOutOfBand_BreakPointModified, 57 | eOutOfBand_Thread, 58 | eOutOfBand_ThreadGroupAdded, 59 | eOutOfBand_ThreadGroupExited, 60 | eOutOfBand_ThreadGroupRemoved, 61 | eOutOfBand_ThreadGroupStarted, 62 | eOutOfBand_ThreadCreated, 63 | eOutOfBand_ThreadExited, 64 | eOutOfBand_ThreadSelected, 65 | eOutOfBand_TargetModuleLoaded, 66 | eOutOfBand_TargetModuleUnloaded, 67 | eOutOfBand_TargetStreamOutput, 68 | eOutOfBand_ConsoleStreamOutput, 69 | eOutOfBand_LogStreamOutput 70 | }; 71 | 72 | // Methods: 73 | public: 74 | /* ctor */ CMICmnMIOutOfBandRecord(); 75 | /* ctor */ CMICmnMIOutOfBandRecord(OutOfBand_e veType); 76 | /* ctor */ CMICmnMIOutOfBandRecord(OutOfBand_e veType, 77 | const CMICmnMIValueConst &vConst); 78 | /* ctor */ CMICmnMIOutOfBandRecord(OutOfBand_e veType, 79 | const CMICmnMIValueResult &vResult); 80 | // 81 | const CMIUtilString &GetString() const; 82 | void Add(const CMICmnMIValueResult &vResult); 83 | 84 | // Overridden: 85 | public: 86 | // From CMICmnBase 87 | /* dtor */ ~CMICmnMIOutOfBandRecord() override; 88 | 89 | // Attributes: 90 | private: 91 | CMIUtilString 92 | m_strAsyncRecord; // Holds the text version of the result record to date 93 | }; 94 | -------------------------------------------------------------------------------- /src/MICmnMIResultRecord.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnMIResultRecord.h -----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmnBase.h" 13 | #include "MICmnMIValueResult.h" 14 | #include "MIUtilString.h" 15 | 16 | //++ 17 | //============================================================================ 18 | // Details: MI common code MI Result Record class. A class that encapsulates 19 | // MI result record data and the forming/format of data added to it. 20 | // The syntax is as follows: 21 | // result-record ==> [ token ] "^" result-class ( "," result )* nl 22 | // token = any sequence of digits 23 | // * = 0 to many 24 | // nl = CR | CR_LF 25 | // result-class ==> "done" | "running" | "connected" | "error" | "exit" 26 | // result ==> variable "=" value 27 | // value ==> const | tuple | list 28 | // const ==> c-string (7 bit iso c string content) i.e. "all" inc 29 | // quotes 30 | // tuple ==> "{}" | "{" result ( "," result )* "}" 31 | // list ==> "[]" | "[" value ( "," value )* "]" | "[" result ( "," 32 | // result )* "]" 33 | // 34 | // The result record can be retrieve at any time *this object is 35 | // instantiated so unless work is done on *this result record then it 36 | // is 37 | // possible to return a malformed result record. If nothing has been 38 | // set 39 | // or added to *this MI result record object then text "" will 40 | // be returned. 41 | // More information see: 42 | // http://ftp.gnu.org/old-gnu/Manuals/gdb-5.1.1/html_chapter/gdb_22.html 43 | //-- 44 | class CMICmnMIResultRecord : public CMICmnBase { 45 | // Enumerations: 46 | public: 47 | //++ 48 | // Details: Enumeration of the result class for *this result record 49 | //-- 50 | enum ResultClass_e { 51 | eResultClass_Done = 0, 52 | eResultClass_Running, 53 | eResultClass_Connected, 54 | eResultClass_Error, 55 | eResultClass_Exit 56 | }; 57 | 58 | // Methods: 59 | public: 60 | /* ctor */ CMICmnMIResultRecord(); 61 | /* ctor */ CMICmnMIResultRecord(const CMIUtilString &vrToken, 62 | ResultClass_e veType); 63 | /* ctor */ CMICmnMIResultRecord(const CMIUtilString &vrToken, 64 | ResultClass_e veType, 65 | const CMICmnMIValueResult &vValue); 66 | // 67 | const CMIUtilString &GetString() const; 68 | void Add(const CMICmnMIValue &vMIValue); 69 | 70 | // Overridden: 71 | public: 72 | // From CMICmnBase 73 | /* dtor */ ~CMICmnMIResultRecord() override; 74 | 75 | // Attributes: 76 | private: 77 | CMIUtilString 78 | m_strResultRecord; // Holds the text version of the result record to date 79 | }; 80 | -------------------------------------------------------------------------------- /src/MICmnMIValue.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmnMIValue.cpp ----------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // In-house headers: 10 | #include "MICmnMIValue.h" 11 | #include "MICmnResources.h" 12 | 13 | //++ 14 | // Details: CMICmnMIValue constructor. 15 | // Type: Method. 16 | // Args: None. 17 | // Return: None. 18 | // Throws: None. 19 | //-- 20 | CMICmnMIValue::CMICmnMIValue() 21 | : m_strValue(MIRSRC(IDS_WORD_INVALIDBRKTS)), m_bJustConstructed(true) {} 22 | 23 | //++ 24 | // Details: CMICmnMIValue destructor. 25 | // Type: Overrideable. 26 | // Args: None. 27 | // Return: None. 28 | // Throws: None. 29 | //-- 30 | CMICmnMIValue::~CMICmnMIValue() {} 31 | 32 | //++ 33 | // Details: Return the MI value as a string. The string is a direct result of 34 | // work done on *this value so if not enough data is added then it is 35 | // possible to return a malformed value. If nothing has been set or 36 | // added to *this MI value object then text "" will be 37 | // returned. 38 | // Type: Method. 39 | // Args: None. 40 | // Return: CMIUtilString & - MI output text. 41 | // Throws: None. 42 | //-- 43 | const CMIUtilString &CMICmnMIValue::GetString() const { return m_strValue; } 44 | -------------------------------------------------------------------------------- /src/MICmnMIValue.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnMIValue.h ------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmnBase.h" 13 | 14 | //++ 15 | //============================================================================ 16 | // Details: MI common code MI Result class. Part of the CMICmnMIValueRecord 17 | // set of objects. 18 | // The syntax is as follows: 19 | // result-record ==> [ token ] "^" result-class ( "," result )* nl 20 | // token = any sequence of digits 21 | // * = 0 to many 22 | // nl = CR | CR_LF 23 | // result-class ==> "done" | "running" | "connected" | "error" | "exit" 24 | // result ==> variable "=" value 25 | // value ==> const | tuple | list 26 | // const ==> c-string (7 bit iso c string content) 27 | // tuple ==> "{}" | "{" result ( "," result )* "}" 28 | // list ==> "[]" | "[" value ( "," value )* "]" | "[" result ( "," 29 | // result )* "]" 30 | // More information see: 31 | // http://ftp.gnu.org/old-gnu/Manuals/gdb-5.1.1/html_chapter/gdb_22.html 32 | //-- 33 | class CMICmnMIValue : public CMICmnBase { 34 | // Methods: 35 | public: 36 | /* ctor */ CMICmnMIValue(); 37 | // 38 | const CMIUtilString &GetString() const; 39 | 40 | // Overridden: 41 | public: 42 | // From CMICmnBase 43 | /* dtor */ ~CMICmnMIValue() override; 44 | 45 | // Attributes: 46 | protected: 47 | CMIUtilString m_strValue; 48 | bool m_bJustConstructed; // True = *this just constructed with no value, false 49 | // = *this has had value added to it 50 | }; 51 | -------------------------------------------------------------------------------- /src/MICmnMIValueConst.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmnMIValueConst.cpp -----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // In-house headers: 10 | #include "MICmnMIValueConst.h" 11 | 12 | // Instantiations: 13 | const CMIUtilString CMICmnMIValueConst::ms_constStrDblQuote("\""); 14 | 15 | //++ 16 | // Details: CMICmnMIValueConst constructor. 17 | // Type: Method. 18 | // Args: vString - (R) MI Const c-string value. 19 | // Return: None. 20 | // Throws: None. 21 | //-- 22 | CMICmnMIValueConst::CMICmnMIValueConst(const CMIUtilString &vString) 23 | : m_strPartConst(vString), m_bNoQuotes(false) { 24 | BuildConst(); 25 | } 26 | 27 | //++ 28 | // Details: CMICmnMIValueConst constructor. 29 | // Type: Method. 30 | // Args: vString - (R) MI Const c-string value. 31 | // vbNoQuotes - (R) True = return string not surrounded with quotes, 32 | // false = use quotes. 33 | // Return: None. 34 | // Throws: None. 35 | //-- 36 | CMICmnMIValueConst::CMICmnMIValueConst(const CMIUtilString &vString, 37 | const bool vbNoQuotes) 38 | : m_strPartConst(vString), m_bNoQuotes(vbNoQuotes) { 39 | BuildConst(); 40 | } 41 | 42 | //++ 43 | // Details: CMICmnMIValueConst destructor. 44 | // Type: Overrideable. 45 | // Args: None. 46 | // Return: None. 47 | // Throws: None. 48 | //-- 49 | CMICmnMIValueConst::~CMICmnMIValueConst() {} 50 | 51 | //++ 52 | // Details: Build the Value Const data. 53 | // Type: Method. 54 | // Args: None. 55 | // Return: MIstatus::success - Functional succeeded. 56 | // MIstatus::failure - Functional failed. 57 | // Throws: None. 58 | //-- 59 | bool CMICmnMIValueConst::BuildConst() { 60 | if (m_strPartConst.length() != 0) { 61 | const CMIUtilString strValue(m_strPartConst.StripCREndOfLine()); 62 | if (m_bNoQuotes) { 63 | m_strValue = strValue; 64 | } else { 65 | const char *pFormat = "%s%s%s"; 66 | m_strValue = 67 | CMIUtilString::Format(pFormat, ms_constStrDblQuote.c_str(), 68 | strValue.c_str(), ms_constStrDblQuote.c_str()); 69 | } 70 | } else { 71 | const char *pFormat = "%s%s"; 72 | m_strValue = CMIUtilString::Format(pFormat, ms_constStrDblQuote.c_str(), 73 | ms_constStrDblQuote.c_str()); 74 | } 75 | 76 | return MIstatus::success; 77 | } 78 | -------------------------------------------------------------------------------- /src/MICmnMIValueConst.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnMIValueConst.h -------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmnMIValue.h" 13 | 14 | //++ 15 | //============================================================================ 16 | // Details: MI common code MI Result class. Part of the CMICmnMIValueConstRecord 17 | // set of objects. 18 | // The syntax is as follows: 19 | // result-record ==> [ token ] "^" result-class ( "," result )* nl 20 | // token = any sequence of digits 21 | // * = 0 to many 22 | // nl = CR | CR_LF 23 | // result-class ==> "done" | "running" | "connected" | "error" | "exit" 24 | // result ==> variable "=" value 25 | // value ==> const | tuple | list 26 | // const ==> c-string (7 bit iso c string content) 27 | // tuple ==> "{}" | "{" result ( "," result )* "}" 28 | // list ==> "[]" | "[" value ( "," value )* "]" | "[" result ( "," 29 | // result )* "]" 30 | // More information see: 31 | // http://ftp.gnu.org/old-gnu/Manuals/gdb-5.1.1/html_chapter/gdb_22.html 32 | // 33 | // The text formed in *this Result class is stripped of any '\n' 34 | // characters. 35 | //-- 36 | class CMICmnMIValueConst : public CMICmnMIValue { 37 | // Methods: 38 | public: 39 | /* ctor */ CMICmnMIValueConst(const CMIUtilString &vString); 40 | /* ctor */ CMICmnMIValueConst(const CMIUtilString &vString, 41 | const bool vbNoQuotes); 42 | 43 | // Overridden: 44 | public: 45 | // From CMICmnBase 46 | /* dtor */ ~CMICmnMIValueConst() override; 47 | 48 | // Methods: 49 | private: 50 | bool BuildConst(); 51 | 52 | // Attributes: 53 | private: 54 | static const CMIUtilString ms_constStrDblQuote; 55 | // 56 | CMIUtilString m_strPartConst; 57 | bool m_bNoQuotes; // True = return string not surrounded with quotes, false = 58 | // use quotes 59 | }; 60 | -------------------------------------------------------------------------------- /src/MICmnMIValueList.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnMIValueList.h --------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmnMIValue.h" 13 | #include "MICmnMIValueResult.h" 14 | 15 | //++ 16 | //============================================================================ 17 | // Details: MI common code MI Result class. Part of the CMICmnMIValueListRecord 18 | // set of objects. 19 | // The syntax is as follows: 20 | // result-record ==> [ token ] "^" result-class ( "," result )* nl 21 | // token = any sequence of digits 22 | // * = 0 to many 23 | // nl = CR | CR_LF 24 | // result-class ==> "done" | "running" | "connected" | "error" | "exit" 25 | // result ==> variable "=" value 26 | // value ==> const | tuple | list 27 | // const ==> c-string (7 bit iso c string content) 28 | // tuple ==> "{}" | "{" result ( "," result )* "}" 29 | // list ==> "[]" | "[" value ( "," value )* "]" | "[" result ( "," 30 | // result )* "]" 31 | // More information see: 32 | // http://ftp.gnu.org/old-gnu/Manuals/gdb-5.1.1/html_chapter/gdb_22.html 33 | //-- 34 | class CMICmnMIValueList : public CMICmnMIValue { 35 | // Methods: 36 | public: 37 | /* ctor */ CMICmnMIValueList(const bool vbValueTypeList); 38 | /* ctor */ CMICmnMIValueList(const CMICmnMIValueResult &vResult); 39 | /* ctor */ CMICmnMIValueList(const CMICmnMIValue &vValue); 40 | // 41 | void Add(const CMICmnMIValueResult &vResult); 42 | void Add(const CMICmnMIValue &vValue); 43 | CMIUtilString ExtractContentNoBrackets() const; 44 | 45 | // Overridden: 46 | public: 47 | // From CMICmnBase 48 | /* dtor */ ~CMICmnMIValueList() override; 49 | 50 | // Methods: 51 | private: 52 | void BuildList(); 53 | void BuildList(const CMICmnMIValueResult &vResult); 54 | void BuildList(const CMICmnMIValue &vResult); 55 | }; 56 | -------------------------------------------------------------------------------- /src/MICmnMIValueResult.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmnMIValueResult.cpp ----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // In-house headers: 10 | #include "MICmnMIValueResult.h" 11 | #include "MICmnResources.h" 12 | 13 | // Instantiations: 14 | const CMIUtilString CMICmnMIValueResult::ms_constStrEqual("="); 15 | 16 | //++ 17 | // Details: CMICmnMIValueResult constructor. 18 | // Type: Method. 19 | // Args: None. 20 | // Return: None. 21 | // Throws: None. 22 | //-- 23 | CMICmnMIValueResult::CMICmnMIValueResult() : m_bEmptyConstruction(true) {} 24 | 25 | //++ 26 | // Details: CMICmnMIValueResult constructor. 27 | // Type: Method. 28 | // Args: vrVariable - (R) MI value's name. 29 | // vrValue - (R) The MI value. 30 | // Return: None. 31 | // Throws: None. 32 | //-- 33 | CMICmnMIValueResult::CMICmnMIValueResult(const CMIUtilString &vrVariable, 34 | const CMICmnMIValue &vrValue) 35 | : m_strPartVariable(vrVariable), m_partMIValue(vrValue), 36 | m_bEmptyConstruction(false), m_bUseSpacing(false) { 37 | BuildResult(); 38 | } 39 | 40 | //++ 41 | // Details: CMICmnMIValueResult constructor. 42 | // Type: Method. 43 | // Args: vrVariable - (R) MI value's name. 44 | // vrValue - (R) The MI value. 45 | // vbUseSpacing - (R) True = put space separators into the string, 46 | // false = no spaces used. 47 | // Return: None. 48 | // Throws: None. 49 | //-- 50 | CMICmnMIValueResult::CMICmnMIValueResult(const CMIUtilString &vrVariable, 51 | const CMICmnMIValue &vrValue, 52 | const bool vbUseSpacing) 53 | : m_strPartVariable(vrVariable), m_partMIValue(vrValue), 54 | m_bEmptyConstruction(false), m_bUseSpacing(vbUseSpacing) { 55 | BuildResult(); 56 | } 57 | 58 | //++ 59 | // Details: CMICmnMIValueResult destructor. 60 | // Type: Overrideable. 61 | // Args: None. 62 | // Return: None. 63 | // Throws: None. 64 | //-- 65 | CMICmnMIValueResult::~CMICmnMIValueResult() {} 66 | 67 | //++ 68 | // Details: Build the MI value result string. 69 | // Type: Method. 70 | // Args: None. 71 | // Return: None. 72 | // Throws: None. 73 | //-- 74 | void CMICmnMIValueResult::BuildResult() { 75 | const char *pFormat = m_bUseSpacing ? "%s %s %s" : "%s%s%s"; 76 | m_strValue = CMIUtilString::Format(pFormat, m_strPartVariable.c_str(), 77 | ms_constStrEqual.c_str(), 78 | m_partMIValue.GetString().c_str()); 79 | } 80 | 81 | //++ 82 | // Details: Build the MI value result string. 83 | // Type: Method. 84 | // Args: vrVariable - (R) MI value's name. 85 | // vrValue - (R) The MI value. 86 | // Return: None. 87 | // Throws: None. 88 | //-- 89 | void CMICmnMIValueResult::BuildResult(const CMIUtilString &vVariable, 90 | const CMICmnMIValue &vValue) { 91 | const char *pFormat = m_bUseSpacing ? "%s, %s %s %s" : "%s,%s%s%s"; 92 | m_strValue = CMIUtilString::Format( 93 | pFormat, m_strValue.c_str(), vVariable.c_str(), ms_constStrEqual.c_str(), 94 | vValue.GetString().c_str()); 95 | } 96 | 97 | //++ 98 | // Details: Append another MI value object to *this MI value result. 99 | // Type: Method. 100 | // Args: vrVariable - (R) MI value's name. 101 | // vrValue - (R) The MI value. 102 | // Return: MIstatus::success - Functional succeeded. 103 | // MIstatus::failure - Functional failed. 104 | // Throws: None. 105 | //-- 106 | void CMICmnMIValueResult::Add(const CMIUtilString &vrVariable, 107 | const CMICmnMIValue &vrValue) { 108 | if (!m_bEmptyConstruction) 109 | BuildResult(vrVariable, vrValue); 110 | else { 111 | m_bEmptyConstruction = false; 112 | m_strPartVariable = vrVariable; 113 | m_partMIValue = vrValue; 114 | BuildResult(); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/MICmnMIValueResult.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnMIValueResult.h ------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmnMIValue.h" 13 | 14 | //++ 15 | //============================================================================ 16 | // Details: MI common code MI Result class. Part of the 17 | // CMICmnMIValueResultRecord 18 | // set of objects. 19 | // The syntax is as follows: 20 | // result-record ==> [ token ] "^" result-class ( "," result )* nl 21 | // token = any sequence of digits 22 | // * = 0 to many 23 | // nl = CR | CR_LF 24 | // result-class ==> "done" | "running" | "connected" | "error" | "exit" 25 | // result ==> variable "=" value 26 | // value ==> const | tuple | list 27 | // const ==> c-string (7 bit iso c string content) 28 | // tuple ==> "{}" | "{" result ( "," result )* "}" 29 | // list ==> "[]" | "[" value ( "," value )* "]" | "[" result ( "," 30 | // result )* "]" 31 | // More information see: 32 | // http://ftp.gnu.org/old-gnu/Manuals/gdb-5.1.1/html_chapter/gdb_22.html 33 | //-- 34 | class CMICmnMIValueResult : public CMICmnMIValue { 35 | // Methods: 36 | public: 37 | /* ctor */ CMICmnMIValueResult(); 38 | /* ctor */ CMICmnMIValueResult(const CMIUtilString &vVariable, 39 | const CMICmnMIValue &vValue); 40 | /* ctor */ CMICmnMIValueResult(const CMIUtilString &vVariable, 41 | const CMICmnMIValue &vValue, 42 | const bool vbUseSpacing); 43 | // 44 | void Add(const CMIUtilString &vVariable, const CMICmnMIValue &vValue); 45 | 46 | // Overridden: 47 | public: 48 | // From CMICmnBase 49 | /* dtor */ ~CMICmnMIValueResult() override; 50 | 51 | // Methods: 52 | private: 53 | void BuildResult(); 54 | void BuildResult(const CMIUtilString &vVariable, const CMICmnMIValue &vValue); 55 | 56 | // Attributes: 57 | private: 58 | static const CMIUtilString ms_constStrEqual; 59 | // 60 | CMIUtilString m_strPartVariable; 61 | CMICmnMIValue m_partMIValue; 62 | bool m_bEmptyConstruction; // True = *this object used constructor with no 63 | // parameters, false = constructor with parameters 64 | bool m_bUseSpacing; // True = put space separators into the string, false = no 65 | // spaces used 66 | }; 67 | -------------------------------------------------------------------------------- /src/MICmnMIValueTuple.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnMIValueTuple.h -------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmnMIValue.h" 13 | #include "MICmnMIValueConst.h" 14 | #include "MICmnMIValueResult.h" 15 | 16 | //++ 17 | //============================================================================ 18 | // Details: MI common code MI Result class. Part of the CMICmnMIValueTupleRecord 19 | // set of objects. 20 | // The syntax is as follows: 21 | // result-record ==> [ token ] "^" result-class ( "," result )* nl 22 | // token = any sequence of digits 23 | // * = 0 to many 24 | // nl = CR | CR_LF 25 | // result-class ==> "done" | "running" | "connected" | "error" | "exit" 26 | // result ==> variable "=" value 27 | // value ==> const | tuple | list 28 | // const ==> c-string (7 bit iso c string content) 29 | // tuple ==> "{}" | "{" result ( "," result )* "}" 30 | // list ==> "[]" | "[" value ( "," value )* "]" | "[" result ( "," 31 | // result )* "]" 32 | // More information see: 33 | // http://ftp.gnu.org/old-gnu/Manuals/gdb-5.1.1/html_chapter/gdb_22.html 34 | //-- 35 | class CMICmnMIValueTuple : public CMICmnMIValue { 36 | // Methods: 37 | public: 38 | /* ctor */ CMICmnMIValueTuple(); 39 | /* ctor */ CMICmnMIValueTuple(const CMICmnMIValueResult &vResult); 40 | /* ctor */ CMICmnMIValueTuple(const CMICmnMIValueResult &vResult, 41 | const bool vbUseSpacing); 42 | // 43 | void Add(const CMICmnMIValueResult &vResult); 44 | void Add(const CMICmnMIValueResult &vResult, const bool vbUseSpacing); 45 | void Add(const CMICmnMIValueConst &vValue, const bool vbUseSpacing); 46 | CMIUtilString ExtractContentNoBrackets() const; 47 | 48 | // Overridden: 49 | public: 50 | // From CMICmnBase 51 | /* dtor */ ~CMICmnMIValueTuple() override; 52 | 53 | // Methods: 54 | private: 55 | void BuildTuple(); 56 | void BuildTuple(const CMICmnMIValueResult &vResult); 57 | void BuildTuple(const CMIUtilString &vValue); 58 | 59 | // Attributes: 60 | private: 61 | bool m_bSpaceAfterComma; // True = put space separators into the string, false 62 | // = no spaces used 63 | }; 64 | -------------------------------------------------------------------------------- /src/MICmnStreamStderr.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnStreamStderr.h -------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmnBase.h" 13 | #include "MIUtilSingletonBase.h" 14 | #include "MIUtilString.h" 15 | #include "MIUtilThreadBaseStd.h" 16 | 17 | //++ 18 | //============================================================================ 19 | // Details: MI common code class. The MI driver requires this object. 20 | // CMICmnStreamStderr sets up and tears downs stderr for the driver. 21 | // 22 | // Singleton class. 23 | //-- 24 | class CMICmnStreamStderr : public CMICmnBase, 25 | public MI::ISingleton { 26 | friend class MI::ISingleton; 27 | 28 | // Statics: 29 | public: 30 | static bool TextToStderr(const CMIUtilString &vrTxt); 31 | static bool LLDBMsgToConsole(const CMIUtilString &vrTxt); 32 | 33 | // Methods: 34 | public: 35 | bool Initialize() override; 36 | bool Shutdown() override; 37 | // 38 | bool Lock(); 39 | bool Unlock(); 40 | bool Write(const CMIUtilString &vText, const bool vbSendToLog = true); 41 | bool WriteLLDBMsg(const CMIUtilString &vText, const bool vbSendToLog = true); 42 | 43 | // Methods: 44 | private: 45 | /* ctor */ CMICmnStreamStderr(); 46 | /* ctor */ CMICmnStreamStderr(const CMICmnStreamStderr &); 47 | void operator=(const CMICmnStreamStderr &); 48 | // 49 | bool WritePriv(const CMIUtilString &vText, 50 | const CMIUtilString &vTxtForLogFile, 51 | const bool vbSendToLog = true); 52 | 53 | // Overridden: 54 | private: 55 | // From CMICmnBase 56 | /* dtor */ ~CMICmnStreamStderr() override; 57 | 58 | // Attributes: 59 | private: 60 | CMIUtilThreadMutex m_mutex; // Mutex object for sync during Write() 61 | }; 62 | -------------------------------------------------------------------------------- /src/MICmnStreamStdin.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnStreamStdin.h --------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmnBase.h" 13 | #include "MIUtilSingletonBase.h" 14 | #include "MIUtilString.h" 15 | #include "MIUtilThreadBaseStd.h" 16 | 17 | //++ 18 | //============================================================================ 19 | // Details: MI common code class. Used to handle stream data from Stdin. 20 | // Singleton class using the Visitor pattern. A driver using the 21 | // interface 22 | // provide can receive callbacks when a new line of data is received. 23 | // Each line is determined by a carriage return. 24 | // A singleton class. 25 | //-- 26 | class CMICmnStreamStdin : public CMICmnBase, 27 | public MI::ISingleton { 28 | // Give singleton access to private constructors 29 | friend MI::ISingleton; 30 | 31 | // Methods: 32 | public: 33 | bool Initialize() override; 34 | bool Shutdown() override; 35 | // 36 | const CMIUtilString &GetPrompt() const; 37 | bool SetPrompt(const CMIUtilString &vNewPrompt); 38 | void SetEnablePrompt(const bool vbYes); 39 | bool GetEnablePrompt() const; 40 | const char *ReadLine(CMIUtilString &vwErrMsg); 41 | 42 | // Methods: 43 | private: 44 | /* ctor */ CMICmnStreamStdin(); 45 | /* ctor */ CMICmnStreamStdin(const CMICmnStreamStdin &); 46 | void operator=(const CMICmnStreamStdin &); 47 | 48 | // Overridden: 49 | private: 50 | // From CMICmnBase 51 | /* dtor */ ~CMICmnStreamStdin() override; 52 | 53 | // Attributes: 54 | private: 55 | CMIUtilString m_strPromptCurrent; // Command line prompt as shown to the user 56 | bool m_bShowPrompt; // True = Yes prompt is shown/output to the user (stdout), 57 | // false = no prompt 58 | std::string m_pCmdString; 59 | }; 60 | -------------------------------------------------------------------------------- /src/MICmnStreamStdout.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnStreamStdout.h -------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmnBase.h" 13 | #include "MIUtilSingletonBase.h" 14 | #include "MIUtilString.h" 15 | #include "MIUtilThreadBaseStd.h" 16 | 17 | //++ 18 | //============================================================================ 19 | // Details: MI common code class. The MI driver requires this object. 20 | // CMICmnStreamStdout sets up and tears downs stdout for the driver. 21 | // 22 | // Singleton class. 23 | //-- 24 | class CMICmnStreamStdout : public CMICmnBase, 25 | public MI::ISingleton { 26 | friend class MI::ISingleton; 27 | 28 | // Statics: 29 | public: 30 | static bool TextToStdout(const CMIUtilString &vrTxt); 31 | static bool WritePrompt(); 32 | 33 | // Methods: 34 | public: 35 | bool Initialize() override; 36 | bool Shutdown() override; 37 | // 38 | bool Lock(); 39 | bool Unlock(); 40 | bool Write(const CMIUtilString &vText, const bool vbSendToLog = true); 41 | bool WriteMIResponse(const CMIUtilString &vText, 42 | const bool vbSendToLog = true); 43 | 44 | // Methods: 45 | private: 46 | /* ctor */ CMICmnStreamStdout(); 47 | /* ctor */ CMICmnStreamStdout(const CMICmnStreamStdout &); 48 | void operator=(const CMICmnStreamStdout &); 49 | // 50 | bool WritePriv(const CMIUtilString &vText, 51 | const CMIUtilString &vTxtForLogFile, 52 | const bool vbSendToLog = true); 53 | 54 | // Overridden: 55 | private: 56 | // From CMICmnBase 57 | /* dtor */ ~CMICmnStreamStdout() override; 58 | 59 | // Attributes: 60 | private: 61 | CMIUtilThreadMutex m_mutex; // Mutex object for sync during writing to stream 62 | }; 63 | -------------------------------------------------------------------------------- /src/MICmnThreadMgrStd.cpp: -------------------------------------------------------------------------------- 1 | //===-- MICmnThreadMgrStd.cpp -----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // In-house headers: 10 | #include "MICmnThreadMgrStd.h" 11 | #include "MICmnLog.h" 12 | #include "MICmnResources.h" 13 | #include "MIUtilSingletonHelper.h" 14 | 15 | //++ 16 | // Details: CMICmnThreadMgr constructor. 17 | // Type: Method. 18 | // Args: None. 19 | // Return: None. 20 | // Throws: None. 21 | //-- 22 | CMICmnThreadMgrStd::CMICmnThreadMgrStd() {} 23 | 24 | //++ 25 | // Details: CMICmnThreadMgr destructor. 26 | // Type: Method. 27 | // Args: None. 28 | // Return: None. 29 | // Throws: None. 30 | //-- 31 | CMICmnThreadMgrStd::~CMICmnThreadMgrStd() { Shutdown(); } 32 | 33 | //++ 34 | // Details: Initialise resources for *this thread manager. 35 | // Type: Method. 36 | // Args: None. 37 | // Return: MIstatus::success - Functional succeeded. 38 | // MIstatus::failure - Functional failed. 39 | // Throws: None. 40 | //-- 41 | bool CMICmnThreadMgrStd::Initialize() { 42 | m_clientUsageRefCnt++; 43 | 44 | if (m_bInitialized) 45 | return MIstatus::success; 46 | 47 | bool bOk = MIstatus::success; 48 | 49 | ClrErrorDescription(); 50 | CMIUtilString errMsg; 51 | 52 | // Note initialisation order is important here as some resources depend on 53 | // previous 54 | MI::ModuleInit(IDS_MI_INIT_ERR_LOG, bOk, errMsg); 55 | MI::ModuleInit(IDS_MI_INIT_ERR_RESOURCES, bOk, errMsg); 56 | 57 | m_bInitialized = bOk; 58 | 59 | if (!bOk) { 60 | CMIUtilString strInitError(CMIUtilString::Format( 61 | MIRSRC(IDS_MI_INIT_ERR_THREADMGR), errMsg.c_str())); 62 | SetErrorDescription(strInitError); 63 | return MIstatus::failure; 64 | } 65 | 66 | return bOk; 67 | } 68 | 69 | //++ 70 | // Details: Release resources for *this thread manager. 71 | // Type: Method. 72 | // Args: None. 73 | // Return: MIstatus::success - Functional succeeded. 74 | // MIstatus::failure - Functional failed. 75 | // Throws: None. 76 | //-- 77 | bool CMICmnThreadMgrStd::Shutdown() { 78 | if (--m_clientUsageRefCnt > 0) 79 | return MIstatus::success; 80 | 81 | if (!m_bInitialized) 82 | return MIstatus::success; 83 | 84 | m_bInitialized = false; 85 | 86 | ClrErrorDescription(); 87 | 88 | bool bOk = MIstatus::success; 89 | CMIUtilString errMsg; 90 | 91 | // Tidy up 92 | ThreadAllTerminate(); 93 | 94 | // Note shutdown order is important here 95 | MI::ModuleShutdown(IDE_MI_SHTDWN_ERR_RESOURCES, bOk, errMsg); 96 | MI::ModuleShutdown(IDS_MI_SHTDWN_ERR_LOG, bOk, errMsg); 97 | 98 | if (!bOk) { 99 | SetErrorDescriptionn(MIRSRC(IDS_MI_SHUTDOWN_ERR), errMsg.c_str()); 100 | } 101 | 102 | return bOk; 103 | } 104 | 105 | //++ 106 | // Details: Ask the thread manager to kill all threads and wait until they have 107 | // died 108 | // Type: Method. 109 | // Args: None. 110 | // Return: MIstatus::success - Functional succeeded. 111 | // MIstatus::failure - Functional failed. 112 | // Throws: None. 113 | //-- 114 | bool CMICmnThreadMgrStd::ThreadAllTerminate() { 115 | ThreadList_t::const_iterator it = m_threadList.begin(); 116 | for (; it != m_threadList.end(); ++it) { 117 | // If the thread is still running 118 | CMIUtilThreadActiveObjBase *pThread = *it; 119 | if (pThread->ThreadIsActive()) { 120 | // Ask this thread to kill itself 121 | pThread->ThreadKill(); 122 | 123 | // Wait for this thread to die 124 | pThread->ThreadJoin(); 125 | } 126 | } 127 | 128 | return MIstatus::success; 129 | } 130 | 131 | //++ 132 | // Details: Add a thread object to *this manager's list of thread objects. The 133 | // list to 134 | // used to manage thread objects centrally. 135 | // Type: Method. 136 | // Args: vrObj - (R) A thread object. 137 | // Return: MIstatus::success - Functional succeeded. 138 | // MIstatus::failure - Functional failed. 139 | // Throws: None. 140 | //-- 141 | bool CMICmnThreadMgrStd::AddThread(const CMIUtilThreadActiveObjBase &vrObj) { 142 | m_threadList.push_back(const_cast(&vrObj)); 143 | 144 | return MIstatus::success; 145 | } 146 | -------------------------------------------------------------------------------- /src/MICmnThreadMgrStd.h: -------------------------------------------------------------------------------- 1 | //===-- MICmnThreadMgrStd.h -------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // Third party headers: 12 | #include 13 | 14 | // In-house headers: 15 | #include "MICmnBase.h" 16 | #include "MICmnResources.h" 17 | #include "MIUtilSingletonBase.h" 18 | #include "MIUtilThreadBaseStd.h" 19 | 20 | //++ 21 | //============================================================================ 22 | // Details: MI's worker thread (active thread) manager. 23 | // The manager creates threads and behalf of clients. Client are 24 | // responsible for their threads and can delete them when necessary. 25 | // This manager will stop and delete all threads on *this manager's 26 | // shutdown. 27 | // Singleton class. 28 | //-- 29 | class CMICmnThreadMgrStd : public CMICmnBase, 30 | public MI::ISingleton { 31 | friend MI::ISingleton; 32 | 33 | // Methods: 34 | public: 35 | bool Initialize() override; 36 | bool Shutdown() override; 37 | bool ThreadAllTerminate(); // Ask all threads to stop (caution) 38 | template // Ask the thread manager to start and stop threads on 39 | // our behalf 40 | bool ThreadStart(T &vrwObject); 41 | 42 | // Typedef: 43 | private: 44 | typedef std::vector ThreadList_t; 45 | 46 | // Methods: 47 | private: 48 | /* ctor */ CMICmnThreadMgrStd(); 49 | /* ctor */ CMICmnThreadMgrStd(const CMICmnThreadMgrStd &); 50 | void operator=(const CMICmnThreadMgrStd &); 51 | // 52 | bool AddThread(const CMIUtilThreadActiveObjBase & 53 | vrObj); // Add a thread for monitoring by the threadmanager 54 | 55 | // Overridden: 56 | private: 57 | // From CMICmnBase 58 | /* dtor */ ~CMICmnThreadMgrStd() override; 59 | 60 | // Attributes: 61 | private: 62 | CMIUtilThreadMutex m_mutex; 63 | ThreadList_t m_threadList; 64 | }; 65 | 66 | //++ 67 | // Details: Given a thread object start its (worker) thread to do work. The 68 | // object is 69 | // added to the *this manager for housekeeping and deletion of all 70 | // thread objects. 71 | // Type: Template method. 72 | // Args: vrwThreadObj - (RW) A CMIUtilThreadActiveObjBase derived 73 | // object. 74 | // Return: MIstatus::success - Functional succeeded. 75 | // MIstatus::failure - Functional failed. 76 | // Throws: None. 77 | //-- 78 | template bool CMICmnThreadMgrStd::ThreadStart(T &vrwThreadObj) { 79 | bool bOk = MIstatus::success; 80 | 81 | // Grab a reference to the base object type 82 | CMIUtilThreadActiveObjBase &rObj = 83 | static_cast(vrwThreadObj); 84 | 85 | // Add to the thread managers internal database 86 | bOk &= AddThread(rObj); 87 | if (!bOk) { 88 | const CMIUtilString errMsg( 89 | CMIUtilString::Format(MIRSRC(IDS_THREADMGR_ERR_THREAD_FAIL_CREATE), 90 | vrwThreadObj.ThreadGetName().c_str())); 91 | SetErrorDescription(errMsg); 92 | return MIstatus::failure; 93 | } 94 | 95 | // Grab a reference on behalf of the caller 96 | bOk &= vrwThreadObj.Acquire(); 97 | if (!bOk) { 98 | const CMIUtilString errMsg( 99 | CMIUtilString::Format(MIRSRC(IDS_THREADMGR_ERR_THREAD_FAIL_CREATE), 100 | vrwThreadObj.ThreadGetName().c_str())); 101 | SetErrorDescription(errMsg); 102 | return MIstatus::failure; 103 | } 104 | 105 | // Thread is already started 106 | // This call must come after the reference count increment 107 | if (vrwThreadObj.ThreadIsActive()) { 108 | // Early exit on thread already running condition 109 | return MIstatus::success; 110 | } 111 | 112 | // Start the thread running 113 | bOk &= vrwThreadObj.ThreadExecute(); 114 | if (!bOk) { 115 | const CMIUtilString errMsg( 116 | CMIUtilString::Format(MIRSRC(IDS_THREADMGR_ERR_THREAD_FAIL_CREATE), 117 | vrwThreadObj.ThreadGetName().c_str())); 118 | SetErrorDescription(errMsg); 119 | return MIstatus::failure; 120 | } 121 | 122 | return MIstatus::success; 123 | } 124 | -------------------------------------------------------------------------------- /src/MIDataTypes.h: -------------------------------------------------------------------------------- 1 | //===-- MIDataTypes.h -------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Overview: Common global switches, macros, etc. 10 | // 11 | // This file contains common data types required by applications 12 | // generally. If supported by the compiler, this file should be 13 | // #include'd as part of the project's PCH (precompiled header). 14 | 15 | #pragma once 16 | 17 | // Windows headers: 18 | #ifdef _WIN32 19 | 20 | #include "Platform.h" 21 | 22 | // Debugging: 23 | #ifdef _DEBUG 24 | #include 25 | #endif // _DEBUG 26 | 27 | #endif // _WIN32 28 | 29 | // Common definitions: 30 | 31 | // Function return status 32 | namespace MIstatus { 33 | const bool success = true; 34 | const bool failure = false; 35 | } // namespace MIstatus 36 | 37 | // Use to avoid "unused parameter" compiler warnings: 38 | #define MIunused(x) (void)x; 39 | 40 | // Portability issues 41 | #ifdef _WIN64 42 | typedef unsigned __int64 size_t; 43 | typedef __int64 MIint; 44 | typedef unsigned __int64 MIuint; 45 | #else 46 | #ifdef _WIN32 47 | typedef unsigned int size_t; 48 | typedef int MIint; 49 | typedef unsigned int MIuint; 50 | #else 51 | typedef int MIint; 52 | typedef unsigned int MIuint; 53 | 54 | #define MAX_PATH 4096 55 | #endif // _WIN32 56 | #endif // _WIN64 57 | 58 | // Common types: 59 | 60 | // Fundamentals: 61 | typedef long long MIint64; // 64bit signed integer. 62 | typedef unsigned long long MIuint64; // 64bit unsigned integer. 63 | -------------------------------------------------------------------------------- /src/MIDriverBase.h: -------------------------------------------------------------------------------- 1 | //===-- MIDriverBase.h ------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // Third party headers: 12 | #include "lldb/API/SBBroadcaster.h" 13 | #include "lldb/API/SBDebugger.h" 14 | 15 | // In-house headers: 16 | #include "MIUtilString.h" 17 | 18 | // Declarations: 19 | namespace lldb { 20 | class SBBroadcaster; 21 | } 22 | 23 | //++ 24 | //============================================================================ 25 | // Details: MI driver base implementation class. This class has been created so 26 | // not have to edit the lldb::SBBroadcaster class code. Functionality 27 | // and attributes need to be common to the LLDB Driver class and the 28 | // MI Driver class (derived from lldb::SBBroadcaster) so they can call 29 | // upon each other for functionality fall through and allow the 30 | // CDriverMgr to manage either (any) driver to be operated on. 31 | // Each driver instance (the CMIDriver, LLDB::Driver) has its own 32 | // LLDB::SBDebugger object. 33 | //-- 34 | class CMIDriverBase { 35 | // Methods: 36 | public: 37 | /* ctor */ CMIDriverBase(); 38 | 39 | CMIDriverBase *GetDriverToFallThruTo() const; 40 | CMIDriverBase *GetDriversParent() const; 41 | 42 | // Overrideable: 43 | public: 44 | /* dtor */ virtual ~CMIDriverBase(); 45 | 46 | virtual bool DoFallThruToAnotherDriver(const CMIUtilString &vCmd, 47 | CMIUtilString &vwErrMsg); 48 | virtual bool SetDriverToFallThruTo(const CMIDriverBase &vrOtherDriver); 49 | virtual bool SetDriverParent(const CMIDriverBase &vrOtherDriver); 50 | virtual const CMIUtilString &GetDriverName() const = 0; 51 | virtual const CMIUtilString &GetDriverId() const = 0; 52 | virtual void SetExitApplicationFlag(const bool vbForceExit); 53 | 54 | // MI provide information for the pass through (child) assigned driver 55 | virtual FILE *GetStdin() const; 56 | virtual FILE *GetStdout() const; 57 | virtual FILE *GetStderr() const; 58 | 59 | // Attributes: 60 | protected: 61 | CMIDriverBase *m_pDriverFallThru; // Child driver to use should *this driver 62 | // not be able to handle client input 63 | CMIDriverBase *m_pDriverParent; // The parent driver who passes work to *this 64 | // driver to do work 65 | CMIUtilString m_strDriverId; 66 | bool m_bExitApp; // True = Yes, exit application, false = continue execution 67 | }; 68 | -------------------------------------------------------------------------------- /src/MIReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | The MI Driver - LLDB Machine Interface V2 (MI) Project Overview 3 | ======================================================================== 4 | 5 | The MI Driver is a stand alone executable that either be used via a 6 | client i.e. Eclipse or directly from the command line. 7 | 8 | For help information on using the MI driver type at the command line: 9 | 10 | lldb-mi --interpreter --help 11 | 12 | A blog about the MI Driver is available on CodePlay's website. Although it may not be 13 | completely accurate after the recent changes in lldb-mi. 14 | http://www.codeplay.com/portal/lldb-mi-driver---part-1-introduction 15 | 16 | In MI mode and invoked with --log option, lldb-mi generates lldb-mi-log.txt 17 | This file keeps a history of the MI Driver's activity for one session. It is 18 | used to aid the debugging of the MI Driver. It also gives warnings about 19 | command's which do not support certain argument or options. 20 | 21 | Note any command or text sent to the MI Driver in MI mode that is not a command 22 | registered in the MI Driver's Command Factory will be rejected and an error message 23 | will be generated. 24 | 25 | All the files prefix with MI are specifically for the MI driver code only. 26 | File MIDriverMain.cpp contains the executables main() function. 27 | 28 | ========================================================================= 29 | Current limitations: 30 | 1. Not all commands and their options have been implemented. Please see 31 | the source code for details. 32 | 2. LLDB-MI may have additional arguments not used in GDB MI. Please see 33 | MIExtensions.txt 34 | 35 | ========================================================================= 36 | The MI Driver build configuration: 37 | MICmnConfig.h defines various preprocessor build options. 38 | -------------------------------------------------------------------------------- /src/MIUtilDateTimeStd.cpp: -------------------------------------------------------------------------------- 1 | //===-- MIUtilDateTimeStd.cpp -----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // In-house headers: 10 | #include "MIUtilDateTimeStd.h" 11 | #include "MICmnResources.h" 12 | 13 | //++ 14 | // Details: CMIUtilDateTimeStd constructor. 15 | // Type: Method. 16 | // Args: None. 17 | // Return: None. 18 | // Throws: None. 19 | //-- 20 | CMIUtilDateTimeStd::CMIUtilDateTimeStd() {} 21 | 22 | //++ 23 | // Details: CMIUtilDateTimeStd destructor. 24 | // Type: Method. 25 | // Args: None. 26 | // Return: None. 27 | // Throws: None. 28 | //-- 29 | CMIUtilDateTimeStd::~CMIUtilDateTimeStd() {} 30 | 31 | //++ 32 | // Details: Retrieve system local current date. Format is MM/DD/YYYY. 33 | // Type: Method. 34 | // Args: None. 35 | // Return: CMIUtilString - Text description. 36 | // Throws: None. 37 | //-- 38 | CMIUtilString CMIUtilDateTimeStd::GetDate() { 39 | CMIUtilString strDate(MIRSRC(IDS_WORD_INVALIDBRKTS)); 40 | 41 | std::time(&m_rawTime); 42 | const std::tm *pTi = std::localtime(&m_rawTime); 43 | if (std::strftime(&m_pScratch[0], sizeof(m_pScratch), "%d/%m/%y", pTi) > 0) 44 | strDate = m_pScratch; 45 | 46 | return strDate; 47 | } 48 | 49 | //++ 50 | // Details: Retrieve system local current time. Format is HH:MM:SS 24 hour 51 | // clock. 52 | // Type: Method. 53 | // Args: None. 54 | // Return: CMIUtilString - Text description. 55 | // Throws: None. 56 | //-- 57 | CMIUtilString CMIUtilDateTimeStd::GetTime() { 58 | std::time(&m_rawTime); 59 | const std::tm *pTi = std::localtime(&m_rawTime); 60 | const CMIUtilString seconds(CMIUtilString::Format("%d", pTi->tm_sec)); 61 | const CMIUtilString zero((seconds.length() == 1) ? "0" : ""); 62 | const CMIUtilString strTime(CMIUtilString::Format( 63 | "%d:%d:%s%s", pTi->tm_hour, pTi->tm_min, zero.c_str(), seconds.c_str())); 64 | 65 | return strTime; 66 | } 67 | 68 | //++ 69 | // Details: Retrieve system local current date and time in yyyy-MM-dd--HH-mm-ss 70 | // format for log file names. 71 | // Type: Method. 72 | // Args: None. 73 | // Return: CMIUtilString - Text description. 74 | // Throws: None. 75 | //-- 76 | CMIUtilString CMIUtilDateTimeStd::GetDateTimeLogFilename() { 77 | std::time(&m_rawTime); 78 | const std::tm *pTi = std::localtime(&m_rawTime); 79 | const CMIUtilString strTime(CMIUtilString::Format( 80 | "%d%02d%02d%02d%02d%02d", pTi->tm_year + 1900, pTi->tm_mon, pTi->tm_mday, 81 | pTi->tm_hour, pTi->tm_min, pTi->tm_sec)); 82 | 83 | return strTime; 84 | } 85 | -------------------------------------------------------------------------------- /src/MIUtilDateTimeStd.h: -------------------------------------------------------------------------------- 1 | //===-- MIUtilDateTimeStd.h -------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // Third party headers 12 | #include 13 | 14 | // In-house headers: 15 | #include "MIUtilString.h" 16 | 17 | //++ 18 | //============================================================================ 19 | // Details: MI common code utility class. Used to retrieve system local date 20 | // time. 21 | //-- 22 | class CMIUtilDateTimeStd { 23 | // Methods: 24 | public: 25 | /* ctor */ CMIUtilDateTimeStd(); 26 | 27 | CMIUtilString GetDate(); 28 | CMIUtilString GetTime(); 29 | CMIUtilString GetDateTimeLogFilename(); 30 | 31 | // Overrideable: 32 | public: 33 | // From CMICmnBase 34 | /* dtor */ virtual ~CMIUtilDateTimeStd(); 35 | 36 | // Attributes: 37 | private: 38 | std::time_t m_rawTime; 39 | char m_pScratch[16]; 40 | }; 41 | -------------------------------------------------------------------------------- /src/MIUtilDebug.cpp: -------------------------------------------------------------------------------- 1 | //===-- MIUtilDebug.cpp -----------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Third party headers: 10 | #ifdef _WIN32 11 | #include "Platform.h" 12 | #endif 13 | 14 | // In-house headers: 15 | #include "MICmnLog.h" 16 | #include "MIDriver.h" 17 | #include "MIUtilDebug.h" 18 | 19 | //++ 20 | // Details: CMIUtilDebug constructor. 21 | // Type: Method. 22 | // Args: None. 23 | // Return: None. 24 | // Throws: None. 25 | //-- 26 | CMIUtilDebug::CMIUtilDebug() {} 27 | 28 | //++ 29 | // Details: CMIUtilDebug destructor. 30 | // Type: Method. 31 | // Args: None. 32 | // Return: None. 33 | // Throws: None. 34 | //-- 35 | CMIUtilDebug::~CMIUtilDebug() {} 36 | 37 | //++ 38 | // Details: Temporarily stall the process/application to give the programmer the 39 | // opportunity to attach a debugger. How to use: Put a break in the 40 | // programmer 41 | // where you want to visit, run the application then attach your 42 | // debugger to the 43 | // application. Hit the debugger's pause button and the debugger should 44 | // should 45 | // show this loop. Change the i variable value to break out of the loop 46 | // and 47 | // visit your break point. 48 | // Type: Static method. 49 | // Args: None. 50 | // Return: None. 51 | // Throws: None. 52 | //-- 53 | void CMIUtilDebug::WaitForDbgAttachInfinteLoop() { 54 | MIuint i = 0; 55 | while (i == 0) { 56 | const std::chrono::milliseconds time(100); 57 | std::this_thread::sleep_for(time); 58 | } 59 | } 60 | 61 | // Instantiations: 62 | CMICmnLog &CMIUtilDebugFnTrace::ms_rLog = CMICmnLog::Instance(); 63 | MIuint CMIUtilDebugFnTrace::ms_fnDepthCnt = 0; 64 | 65 | //++ 66 | // Details: CMIUtilDebugFnTrace constructor. 67 | // Type: Method. 68 | // Args: vFnName - (R) The text to insert into the log. 69 | // Return: None. 70 | // Throws: None. 71 | //-- 72 | CMIUtilDebugFnTrace::CMIUtilDebugFnTrace(const CMIUtilString &vFnName) 73 | : m_strFnName(vFnName) { 74 | const CMIUtilString txt( 75 | CMIUtilString::Format("%d>%s", ++ms_fnDepthCnt, m_strFnName.c_str())); 76 | ms_rLog.Write(txt, CMICmnLog::eLogVerbosity_FnTrace); 77 | } 78 | 79 | //++ 80 | // Details: CMIUtilDebugFnTrace destructor. 81 | // Type: Method. 82 | // Args: None. 83 | // Return: None. 84 | // Throws: None. 85 | //-- 86 | CMIUtilDebugFnTrace::~CMIUtilDebugFnTrace() { 87 | const CMIUtilString txt( 88 | CMIUtilString::Format("%d<%s", ms_fnDepthCnt--, m_strFnName.c_str())); 89 | ms_rLog.Write(txt, CMICmnLog::eLogVerbosity_FnTrace); 90 | } 91 | -------------------------------------------------------------------------------- /src/MIUtilDebug.h: -------------------------------------------------------------------------------- 1 | //===-- MIUtilDebug.h -------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | #define MI_USE_DEBUG_TRACE_FN // Undefine to compile out fn trace code 12 | 13 | // In-house headers: 14 | #include "MIUtilString.h" 15 | 16 | // Declarations: 17 | class CMICmnLog; 18 | 19 | //++ 20 | //============================================================================ 21 | // Details: MI debugging aid utility class. 22 | //-- 23 | class CMIUtilDebug { 24 | // Statics: 25 | public: 26 | static void WaitForDbgAttachInfinteLoop(); 27 | 28 | // Methods: 29 | public: 30 | /* ctor */ CMIUtilDebug(); 31 | 32 | // Overrideable: 33 | public: 34 | // From CMICmnBase 35 | /* dtor */ virtual ~CMIUtilDebug(); 36 | }; 37 | 38 | //++ 39 | //============================================================================ 40 | // Details: MI debug utility class. Used to indicate the current function 41 | // depth in the call stack. It uses the CMIlCmnLog logger to output 42 | // the current fn trace information. 43 | // Use macro MI_TRACEFN( "Some fn name" ) and implement the scope of 44 | // the functions you wish to build up a trace off. 45 | // Use preprocessor definition MI_USE_DEBUG_TRACE_FN to turn off or on 46 | // tracing code. 47 | //-- 48 | class CMIUtilDebugFnTrace { 49 | // Methods: 50 | public: 51 | /* ctor */ CMIUtilDebugFnTrace(const CMIUtilString &vFnName); 52 | 53 | // Overrideable: 54 | public: 55 | // From CMICmnBase 56 | /* dtor */ virtual ~CMIUtilDebugFnTrace(); 57 | 58 | // Attributes: 59 | private: 60 | const CMIUtilString m_strFnName; 61 | 62 | static CMICmnLog &ms_rLog; 63 | static MIuint ms_fnDepthCnt; // Increment count as fn depth increases, 64 | // decrement count as fn stack pops off 65 | }; 66 | 67 | //++ 68 | //============================================================================ 69 | // Details: Take the given text and send it to the server's Logger to output to 70 | // the 71 | // trace file. 72 | // Type: Compile preprocess. 73 | // Args: x - (R) Message (may be seen by user). 74 | //-- 75 | #ifdef MI_USE_DEBUG_TRACE_FN 76 | #define MI_TRACEFN(x) CMIUtilDebugFnTrace __MITrace(x) 77 | #else 78 | #define MI_TRACEFN(x) 79 | #endif // MI_USE_DEBUG_TRACE_FN 80 | -------------------------------------------------------------------------------- /src/MIUtilFileStd.h: -------------------------------------------------------------------------------- 1 | //===-- MIUtilFileStd.h -----------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In-house headers: 12 | #include "MICmnBase.h" 13 | #include "MIUtilString.h" 14 | 15 | //++ 16 | //============================================================================ 17 | // Details: MI common code utility class. File handling. 18 | //-- 19 | class CMIUtilFileStd : public CMICmnBase { 20 | // Static: 21 | public: 22 | static char GetSlash(); 23 | 24 | // Methods: 25 | public: 26 | /* ctor */ CMIUtilFileStd(); 27 | // 28 | bool CreateWrite(const CMIUtilString &vFileNamePath, bool &vwrbNewCreated); 29 | bool Write(const CMIUtilString &vData); 30 | bool Write(const char *vpData, const MIuint vCharCnt); 31 | void Close(); 32 | bool IsOk() const; 33 | bool IsFileExist(const CMIUtilString &vFileNamePath) const; 34 | const CMIUtilString &GetLineReturn() const; 35 | static CMIUtilString StripOffFileName(const CMIUtilString &vDirectoryPath); 36 | 37 | // Overridden: 38 | public: 39 | // From CMICmnBase 40 | /* dtor */ ~CMIUtilFileStd() override; 41 | 42 | // Attributes: 43 | private: 44 | CMIUtilString m_fileNamePath; 45 | FILE *m_pFileHandle; 46 | CMIUtilString m_constCharNewLine; 47 | bool m_bFileError; // True = have a file error ATM, false = all ok 48 | }; 49 | -------------------------------------------------------------------------------- /src/MIUtilMapIdToVariant.cpp: -------------------------------------------------------------------------------- 1 | //===-- MIUtilMapIdToVariant.cpp --------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // In-house headers: 10 | #include "MIUtilMapIdToVariant.h" 11 | 12 | //++ 13 | // Details: CMIUtilMapIdToVariant constructor. 14 | // Type: Method. 15 | // Args: None. 16 | // Return: None. 17 | // Throws: None. 18 | //-- 19 | CMIUtilMapIdToVariant::CMIUtilMapIdToVariant() {} 20 | 21 | //++ 22 | // Details: CMIUtilMapIdToVariant destructor. 23 | // Type: Method. 24 | // Args: None. 25 | // Return: None. 26 | // Throws: None. 27 | //-- 28 | CMIUtilMapIdToVariant::~CMIUtilMapIdToVariant() {} 29 | 30 | //++ 31 | // Details: Remove at the data from *this container. 32 | // Type: Method. 33 | // Args: None. 34 | // Return: None. 35 | // Throws: None. 36 | //-- 37 | void CMIUtilMapIdToVariant::Clear() { m_mapKeyToVariantValue.clear(); } 38 | 39 | //++ 40 | // Details: Check an ID is present already in *this container. 41 | // Type: Method. 42 | // Args: vId - (R) Unique ID i.e. GUID. 43 | // Return: True - registered. 44 | // False - not found. 45 | // Throws: None. 46 | //-- 47 | bool CMIUtilMapIdToVariant::HaveAlready(const CMIUtilString &vId) const { 48 | const MapKeyToVariantValue_t::const_iterator it = 49 | m_mapKeyToVariantValue.find(vId); 50 | return it != m_mapKeyToVariantValue.end(); 51 | } 52 | 53 | //++ 54 | // Details: Determine if *this container is currently holding any data. 55 | // Type: Method. 56 | // Args: None. 57 | // Return: bool - True - Yes empty, false - one or more data object present. 58 | // Throws: None. 59 | //-- 60 | bool CMIUtilMapIdToVariant::IsEmpty() const { 61 | return m_mapKeyToVariantValue.empty(); 62 | } 63 | 64 | //++ 65 | // Details: Check the ID is valid to be registered. 66 | // Type: Method. 67 | // Args: vId - (R) Unique ID i.e. GUID. 68 | // Return: True - valid. 69 | // False - not valid. 70 | // Throws: None. 71 | //-- 72 | bool CMIUtilMapIdToVariant::IsValid(const CMIUtilString &vId) const { 73 | bool bValid = true; 74 | 75 | if (vId.empty()) 76 | bValid = false; 77 | 78 | return bValid; 79 | } 80 | 81 | //++ 82 | // Details: Remove from *this contain a data object specified by ID. The data 83 | // object 84 | // when removed also calls its destructor should it have one. 85 | // Type: Method. 86 | // Args: vId - (R) Unique ID i.e. GUID. 87 | // Return: MIstatus::success - Functional succeeded. 88 | // MIstatus::failure - Functional failed. 89 | // Throws: None. 90 | //-- 91 | bool CMIUtilMapIdToVariant::Remove(const CMIUtilString &vId) { 92 | const MapKeyToVariantValue_t::const_iterator it = 93 | m_mapKeyToVariantValue.find(vId); 94 | if (it != m_mapKeyToVariantValue.end()) { 95 | m_mapKeyToVariantValue.erase(it); 96 | } 97 | 98 | return MIstatus::success; 99 | } 100 | -------------------------------------------------------------------------------- /src/MIUtilSingletonBase.h: -------------------------------------------------------------------------------- 1 | //===-- MIUtilSingletonBase.h -----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | namespace MI { 12 | 13 | // MI::ISingleton base class usage: 14 | // 15 | // class CMIDerivedClass 16 | // : public MI::ISingleton< CMIDerivedClass > 17 | // { 18 | // friend MI::ISingleton< CMIDerivedClass >; 19 | // 20 | // // Overridden: 21 | // public: 22 | // // From MI::ISingleton 23 | // bool Initialize() override; 24 | // bool Shutdown() override; 25 | // }; 26 | 27 | //++ 28 | //============================================================================ 29 | // Details: Base class for the singleton pattern. 30 | // Gotchas: Derived class must specify MI::ISingleton<> as a friend class. 31 | //-- 32 | template class ISingleton { 33 | // Statics: 34 | public: 35 | // Return an instance of the derived class 36 | static T &Instance() { 37 | // This will fail if the derived class has not 38 | // declared itself to be a friend of MI::ISingleton 39 | static T instance; 40 | 41 | return instance; 42 | } 43 | 44 | // Overrideable: 45 | public: 46 | virtual bool Initialize() = 0; 47 | virtual bool Shutdown() = 0; 48 | // 49 | /* dtor */ virtual ~ISingleton() {} 50 | }; 51 | 52 | } // namespace MI 53 | -------------------------------------------------------------------------------- /src/MIUtilSingletonHelper.h: -------------------------------------------------------------------------------- 1 | //===-- MIUtilSingletonHelper.h ---------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // In house headers: 12 | #include "MICmnResources.h" 13 | #include "MIUtilString.h" 14 | 15 | namespace MI { 16 | 17 | //++ 18 | //============================================================================ 19 | // Details: Short cut helper function to simplify repeated initialisation of 20 | // MI components (singletons) required by a client module. 21 | // Type: Template method. 22 | // Args: vErrorResrcId - (R) The string resource ID error message 23 | // identifier to place in errMsg. 24 | // vwrbOk - (RW) On input True = Try to initialize MI driver 25 | // module. 26 | // On output True = MI driver module initialise 27 | // successfully. 28 | // vwrErrMsg - (W) MI driver module initialise error description 29 | // on failure. 30 | // Return: MIstatus::success - Functional succeeded. 31 | // MIstatus::failure - Functional failed. 32 | //-- 33 | template 34 | bool ModuleInit(const MIint vErrorResrcId, bool &vwrbOk, 35 | CMIUtilString &vwrErrMsg) { 36 | if (vwrbOk && !T::Instance().Initialize()) { 37 | vwrbOk = MIstatus::failure; 38 | vwrErrMsg = CMIUtilString::Format( 39 | MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str()); 40 | } 41 | 42 | return vwrbOk; 43 | } 44 | 45 | //++ 46 | //============================================================================ 47 | // Details: Short cut helper function to simplify repeated shutdown of 48 | // MI components (singletons) required by a client module. 49 | // Type: Template method. 50 | // Args: vErrorResrcId - (R) The string resource ID error message 51 | // identifier 52 | // to place in errMsg. 53 | // vwrbOk - (W) If not already false make false on module 54 | // shutdown failure. 55 | // vwrErrMsg - (RW) Append to existing error description string 56 | // MI 57 | // driver module initialise error description on 58 | // failure. 59 | // Return: True - Module shutdown succeeded. 60 | // False - Module shutdown failed. 61 | //-- 62 | template 63 | bool ModuleShutdown(const MIint vErrorResrcId, bool &vwrbOk, 64 | CMIUtilString &vwrErrMsg) { 65 | bool bOk = MIstatus::success; 66 | 67 | if (!T::Instance().Shutdown()) { 68 | const bool bMoreThanOneError(!vwrErrMsg.empty()); 69 | bOk = MIstatus::failure; 70 | if (bMoreThanOneError) 71 | vwrErrMsg += ", "; 72 | vwrErrMsg += CMIUtilString::Format( 73 | MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str()); 74 | } 75 | 76 | vwrbOk = bOk ? vwrbOk : MIstatus::failure; 77 | 78 | return bOk; 79 | } 80 | 81 | } // namespace MI 82 | -------------------------------------------------------------------------------- /src/MIUtilString.h: -------------------------------------------------------------------------------- 1 | //===-- MIUtilString.h ------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #pragma once 10 | 11 | // Third party headers: 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | // In-house headers: 18 | #include "MIDataTypes.h" 19 | 20 | //++ 21 | //============================================================================ 22 | // Details: MI common code utility class. Used to help handle text. 23 | // Derived from std::string 24 | //-- 25 | class CMIUtilString : public std::string { 26 | // Typedefs: 27 | public: 28 | typedef std::vector VecString_t; 29 | 30 | // Static method: 31 | public: 32 | static CMIUtilString Format(const char *vFormating, ...); 33 | static CMIUtilString FormatBinary(const MIuint64 vnDecimal); 34 | static CMIUtilString FormatValist(const CMIUtilString &vrFormating, 35 | va_list vArgs); 36 | static bool IsAllValidAlphaAndNumeric(const char *vpText); 37 | static const char *WithNullAsEmpty(const char *vpText) { 38 | return vpText ? vpText : ""; 39 | } 40 | static bool Compare(const CMIUtilString &vrLhs, const CMIUtilString &vrRhs); 41 | static CMIUtilString ConvertToPrintableASCII(const char vChar, 42 | bool bEscapeQuotes = false); 43 | static CMIUtilString ConvertToPrintableASCII(const char16_t vChar16, 44 | bool bEscapeQuotes = false); 45 | static CMIUtilString ConvertToPrintableASCII(const char32_t vChar32, 46 | bool bEscapeQuotes = false); 47 | 48 | // Methods: 49 | public: 50 | /* ctor */ CMIUtilString(); 51 | /* ctor */ CMIUtilString(const char *vpData); 52 | /* ctor */ CMIUtilString(const std::string &vrStr); 53 | // 54 | bool ExtractNumber(MIint64 &vwrNumber) const; 55 | CMIUtilString FindAndReplace(const CMIUtilString &vFind, 56 | const CMIUtilString &vReplaceWith) const; 57 | bool IsNumber() const; 58 | bool IsHexadecimalNumber() const; 59 | bool IsQuoted() const; 60 | CMIUtilString RemoveRepeatedCharacters(const char vChar); 61 | size_t Split(const CMIUtilString &vDelimiter, VecString_t &vwVecSplits) const; 62 | size_t SplitConsiderQuotes(const CMIUtilString &vDelimiter, 63 | VecString_t &vwVecSplits) const; 64 | size_t SplitLines(VecString_t &vwVecSplits) const; 65 | CMIUtilString StripCREndOfLine() const; 66 | CMIUtilString StripCRAll() const; 67 | CMIUtilString Trim() const; 68 | CMIUtilString Trim(const char vChar) const; 69 | size_t FindFirst(const CMIUtilString &vrPattern, size_t vnPos = 0) const; 70 | size_t FindFirst(const CMIUtilString &vrPattern, bool vbSkipQuotedText, 71 | bool &vrwbNotFoundClosedQuote, size_t vnPos = 0) const; 72 | size_t FindFirstNot(const CMIUtilString &vrPattern, size_t vnPos = 0) const; 73 | CMIUtilString Escape(bool vbEscapeQuotes = false) const; 74 | CMIUtilString AddSlashes() const; 75 | CMIUtilString StripSlashes() const; 76 | // 77 | CMIUtilString &operator=(const char *vpRhs); 78 | CMIUtilString &operator=(const std::string &vrRhs); 79 | 80 | // Overrideable: 81 | public: 82 | /* dtor */ virtual ~CMIUtilString(); 83 | 84 | // Static method: 85 | private: 86 | static CMIUtilString FormatPriv(const CMIUtilString &vrFormat, va_list vArgs); 87 | static CMIUtilString ConvertCharValueToPrintableASCII(char vChar, 88 | bool bEscapeQuotes); 89 | 90 | // Methods: 91 | private: 92 | bool ExtractNumberFromHexadecimal(MIint64 &vwrNumber) const; 93 | CMIUtilString RemoveRepeatedCharacters(size_t vnPos, const char vChar); 94 | size_t FindFirstQuote(size_t vnPos) const; 95 | }; 96 | -------------------------------------------------------------------------------- /src/Platform.h: -------------------------------------------------------------------------------- 1 | //===-- Platform.h ----------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | #pragma once 9 | 10 | #if defined(_WIN32) 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "lldb/Host/HostGetOpt.h" 17 | #include "lldb/Host/windows/PosixApi.h" 18 | #include "lldb/Host/windows/windows.h" 19 | 20 | struct winsize { 21 | long ws_col; 22 | }; 23 | 24 | typedef unsigned char cc_t; 25 | typedef unsigned int speed_t; 26 | typedef unsigned int tcflag_t; 27 | 28 | // fcntl.h // This is not used by MI 29 | #ifndef O_NOCTTY 30 | #define O_NOCTTY 0400 31 | #endif 32 | 33 | // ioctls.h 34 | #define TIOCGWINSZ 0x5413 35 | 36 | // tcsetattr arguments 37 | #define TCSANOW 0 38 | 39 | #define NCCS 32 40 | struct termios { 41 | tcflag_t c_iflag; // input mode flags 42 | tcflag_t c_oflag; // output mode flags 43 | tcflag_t c_cflag; // control mode flags 44 | tcflag_t c_lflag; // local mode flags 45 | cc_t c_line; // line discipline 46 | cc_t c_cc[NCCS]; // control characters 47 | speed_t c_ispeed; // input speed 48 | speed_t c_ospeed; // output speed 49 | }; 50 | 51 | #define STDIN_FILENO 0 52 | #ifndef PATH_MAX 53 | #define PATH_MAX 32768 54 | #endif 55 | #define snprintf _snprintf 56 | 57 | extern int ioctl(int d, int request, ...); 58 | extern int kill(pid_t pid, int sig); 59 | extern int tcsetattr(int fd, int optional_actions, 60 | const struct termios *termios_p); 61 | extern int tcgetattr(int fildes, struct termios *termios_p); 62 | 63 | // signal handler function pointer type 64 | typedef void (*sighandler_t)(int); 65 | 66 | // CODETAG_IOR_SIGNALS 67 | // signal.h 68 | #define SIGQUIT 3 // Terminal quit signal 69 | #define SIGKILL 9 // Kill (cannot be caught or ignored) 70 | #define SIGPIPE 13 // Write on a pipe with no one to read it 71 | #define SIGCONT 18 // Continue executing, if stopped. 72 | #define SIGTSTP 20 // Terminal stop signal 73 | #ifndef SIGSTOP 74 | #define SIGSTOP 23 // Stop executing (cannot be caught or ignored) 75 | #endif 76 | #define SIGWINCH 28 // (== SIGVTALRM) 77 | 78 | #else 79 | 80 | #include 81 | #include 82 | 83 | #include 84 | #include 85 | #include 86 | #include 87 | #include 88 | 89 | #include 90 | #include 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /src/lldb-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleIdentifier 8 | com.apple.lldb 9 | CFBundleInfoDictionaryVersion 10 | 6.0 11 | CFBundleName 12 | lldb-mi 13 | CFBundleVersion 14 | 2 15 | SecTaskAccess 16 | 17 | allowed 18 | debug 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/lldb-mi.exports: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lldb-tools/lldb-mi/f1fea743bf06a99b6e7f74085bd8c8db47999df5/src/lldb-mi.exports -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(unittests) 2 | -------------------------------------------------------------------------------- /test/unittests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | include(FetchContent) 4 | FetchContent_Declare(gtest 5 | QUIET 6 | URL https://github.com/google/googletest/releases/download/v1.16.0/googletest-1.16.0.tar.gz 7 | ) 8 | 9 | # Prevent overriding the parent project's linker settings, for Windows. 10 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 11 | 12 | # GTest uses default label in switch which covers all enumeration values and 13 | # Clang issues an error in this case. Let it be just a warning. 14 | if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") 15 | add_compile_options("-Wno-error=covered-switch-default") 16 | endif() 17 | 18 | FetchContent_MakeAvailable(gtest) 19 | 20 | include(GoogleTest) 21 | 22 | include_directories(../../src) 23 | 24 | set(UNITTESTS_ROOT ${CMAKE_CURRENT_LIST_DIR}) 25 | set(SOURCE_DIR ${UNITTESTS_ROOT}/../../src) 26 | 27 | function(add_lldb_mi_test NAME TEST) 28 | cmake_parse_arguments( 29 | ARG 30 | "" 31 | "" 32 | "SOURCES" 33 | ${ARGN} 34 | ) 35 | 36 | set(SOURCES_RELATIVE "") 37 | foreach(SRC ${ARG_SOURCES}) 38 | list(APPEND SOURCES_RELATIVE ${SOURCE_DIR}/${SRC}) 39 | endforeach(SRC) 40 | 41 | add_executable(${NAME} ${TEST} ${SOURCES_RELATIVE}) 42 | target_link_libraries(${NAME} gtest_main) 43 | set_target_properties(${NAME} PROPERTIES FOLDER "unittests") 44 | 45 | gtest_discover_tests(${NAME}) 46 | endfunction(add_lldb_mi_test) 47 | 48 | add_subdirectory(arguments) 49 | -------------------------------------------------------------------------------- /test/unittests/arguments/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_lldb_mi_test(TestMICmdArgValString 2 | TestMICmdArgValString.cpp 3 | 4 | SOURCES 5 | MICmdArgValString.cpp 6 | MICmdArgValText.cpp 7 | MICmdArgValBase.cpp 8 | MIUtilString.cpp 9 | MICmdArgContext.cpp 10 | ) 11 | -------------------------------------------------------------------------------- /test/unittests/arguments/TestMICmdArgValString.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | TEST(TestMICmdArgValString, HandlesQuotedStringWithAnySpecialContent) { 6 | for (uint8_t flags = 0; flags < 1 << 4; flags++) { 7 | CMICmdArgValString arg("arg", flags & 1, flags & 2, true, flags & 4, 8 | flags & 8); 9 | 10 | CMICmdArgContext context("\"a/b\" \"i1\" \"10\" \"--option\""); 11 | 12 | EXPECT_TRUE(arg.Validate(context)); 13 | EXPECT_EQ("a/b", arg.GetValue()); 14 | 15 | EXPECT_TRUE(arg.Validate(context)); 16 | EXPECT_EQ("i1", arg.GetValue()); 17 | 18 | EXPECT_TRUE(arg.Validate(context)); 19 | EXPECT_EQ("10", arg.GetValue()); 20 | 21 | EXPECT_TRUE(arg.Validate(context)); 22 | EXPECT_EQ("--option", arg.GetValue()); 23 | } 24 | } 25 | 26 | TEST(TestMICmdArgValString, HandlesQuotedStringsWithQuotes) { 27 | CMICmdArgValString arg("arg", true, true, true, false, false); 28 | 29 | CMICmdArgContext context("\"a \"b\" c\""); 30 | EXPECT_TRUE(arg.Validate(context)); 31 | } 32 | 33 | TEST(TestMICmdArgValString, HandlesEmbeddedQuotedStringsWithSlashes) { 34 | CMICmdArgValString arg("arg", true, true, true, false, false); 35 | 36 | CMICmdArgContext context("\"a \\\"b c\\\" d\""); 37 | EXPECT_TRUE(arg.Validate(context)); 38 | } 39 | 40 | TEST(TestMICmdArgValString, DoesNotHandleSlashedQuotedStrings) { 41 | CMICmdArgValString arg("arg", true, true, true, false, false); 42 | 43 | CMICmdArgContext context("\\\"a\\\""); 44 | EXPECT_FALSE(arg.Validate(context)); 45 | } 46 | 47 | TEST(TestMICmdArgValString, SkipsSpecialContentIfDoesNotHandleQuotes) { 48 | CMICmdArgValString arg("arg", true, true, false); 49 | 50 | CMICmdArgContext context("--option i1 10 a/b c"); 51 | EXPECT_TRUE(arg.Validate(context)); 52 | EXPECT_EQ("c", arg.GetValue()); 53 | } 54 | 55 | TEST(TestMICmdArgValString, DoesNotSkipSpecialContentIfHandlesQuotes) { 56 | CMICmdArgValString arg("arg", true, true, true); 57 | 58 | CMICmdArgContext context("--option c"); 59 | EXPECT_FALSE(arg.Validate(context)); 60 | 61 | context = CMICmdArgContext("i1 c"); 62 | EXPECT_FALSE(arg.Validate(context)); 63 | 64 | context = CMICmdArgContext("10 c"); 65 | EXPECT_FALSE(arg.Validate(context)); 66 | 67 | context = CMICmdArgContext("a/b c"); 68 | EXPECT_FALSE(arg.Validate(context)); 69 | } 70 | 71 | TEST(TestMICmdArgValString, HandlesPathsIfNeeded) { 72 | CMICmdArgValString arg("arg", true, true, true, false, true); 73 | CMICmdArgContext context("a/b"); 74 | EXPECT_TRUE(arg.Validate(context)); 75 | EXPECT_EQ("a/b", arg.GetValue()); 76 | 77 | arg = CMICmdArgValString("arg", true, true, true, false, false); 78 | context = CMICmdArgContext("a/b"); 79 | EXPECT_FALSE(arg.Validate(context)); 80 | } 81 | 82 | TEST(TestMICmdArgValString, HandlesNumbersIfNeeded) { 83 | CMICmdArgValString arg("arg", true, true, true, true, false); 84 | CMICmdArgContext context("10"); 85 | EXPECT_TRUE(arg.Validate(context)); 86 | EXPECT_EQ("10", arg.GetValue()); 87 | 88 | arg = CMICmdArgValString("arg", true, true, true, false, false); 89 | context = CMICmdArgContext("10"); 90 | EXPECT_FALSE(arg.Validate(context)); 91 | } 92 | --------------------------------------------------------------------------------