├── .appveyor.yml ├── .circleci └── config.yml ├── .clang-format ├── .clang-tidy ├── .coveralls.yml ├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Definitions ├── ARM.json ├── ARM64.json ├── MIPS32.json ├── MIPS64.json ├── X86.json └── X86_64.json ├── Doxyfile ├── Headers └── DebugServer2 │ ├── Architecture │ ├── ARM │ │ ├── Branching.h │ │ ├── CPUState.h │ │ ├── RegistersDescriptors.h │ │ └── SoftwareSingleStep.h │ ├── ARM64 │ │ ├── CPUState.h │ │ └── RegistersDescriptors.h │ ├── CPUState.h │ ├── RegisterLayout.h │ ├── Registers.h │ ├── RegistersDescriptors.h │ ├── X86 │ │ ├── CPUState.h │ │ ├── RegisterCopy.h │ │ └── RegistersDescriptors.h │ └── X86_64 │ │ ├── CPUState.h │ │ └── RegistersDescriptors.h │ ├── Base.h │ ├── Constants.h │ ├── Core │ ├── BreakpointManager.h │ ├── CPUTypes.h │ ├── ErrorCodes.h │ ├── HardwareBreakpointManager.h │ ├── MessageQueue.h │ ├── SessionThread.h │ └── SoftwareBreakpointManager.h │ ├── GDBRemote │ ├── Base.h │ ├── DebugSessionImpl.h │ ├── DummySessionDelegateImpl.h │ ├── Mixins │ │ ├── FileOperationsMixin.h │ │ └── ProcessLaunchMixin.h │ ├── PacketProcessor.h │ ├── PlatformSessionImpl.h │ ├── ProtocolHelpers.h │ ├── ProtocolInterpreter.h │ ├── Session.h │ ├── SessionBase.h │ ├── SessionDelegate.h │ ├── SlaveSessionImpl.h │ └── Types.h │ ├── Host │ ├── Channel.h │ ├── Darwin │ │ ├── LibProc.h │ │ ├── Mach.h │ │ └── PTrace.h │ ├── File.h │ ├── FreeBSD │ │ ├── PTrace.h │ │ └── ProcStat.h │ ├── Linux │ │ ├── ARM │ │ │ └── HwCaps.h │ │ ├── ARM64 │ │ │ └── Syscalls.h │ │ ├── ExtraWrappers.h │ │ ├── PTrace.h │ │ ├── ProcFS.h │ │ ├── X86 │ │ │ └── Syscalls.h │ │ └── X86_64 │ │ │ └── Syscalls.h │ ├── POSIX │ │ ├── PTrace.h │ │ └── ProcessSpawner.h │ ├── Platform.h │ ├── ProcessSpawner.h │ ├── QueueChannel.h │ ├── Socket.h │ └── Windows │ │ ├── ExtraWrappers.h │ │ └── ProcessSpawner.h │ ├── Support │ └── POSIX │ │ └── ELFSupport.h │ ├── Target │ ├── Darwin │ │ ├── MachOProcess.h │ │ ├── Process.h │ │ └── Thread.h │ ├── FreeBSD │ │ ├── Process.h │ │ └── Thread.h │ ├── Linux │ │ ├── Process.h │ │ └── Thread.h │ ├── POSIX │ │ ├── ELFProcess.h │ │ ├── Process.h │ │ └── Thread.h │ ├── Process.h │ ├── ProcessBase.h │ ├── ProcessDecl.h │ ├── Thread.h │ ├── ThreadBase.h │ └── Windows │ │ ├── Process.h │ │ └── Thread.h │ ├── Types.h │ └── Utils │ ├── Backtrace.h │ ├── Bits.h │ ├── CompilerSupport.h │ ├── Daemon.h │ ├── Enums.h │ ├── HexValues.h │ ├── Log.h │ ├── MPL.h │ ├── OptParse.h │ ├── Paths.h │ ├── ScopedJanitor.h │ ├── String.h │ ├── Stringify.h │ └── SwapEndian.h ├── LICENSE ├── PATENTS ├── README.md ├── Sources ├── Architecture │ ├── ARM │ │ ├── ARMBranchInfo.cpp │ │ ├── RegistersDescriptors.cpp │ │ ├── SoftwareSingleStep.cpp │ │ └── ThumbBranchInfo.cpp │ ├── ARM64 │ │ └── RegistersDescriptors.cpp │ ├── RegisterLayout.cpp │ ├── X86 │ │ └── RegistersDescriptors.cpp │ └── X86_64 │ │ └── RegistersDescriptors.cpp ├── Core │ ├── ARM │ │ ├── HardwareBreakpointManager.cpp │ │ └── SoftwareBreakpointManager.cpp │ ├── BreakpointManager.cpp │ ├── CPUTypes.cpp │ ├── ErrorCodes.cpp │ ├── HardwareBreakpointManager.cpp │ ├── MessageQueue.cpp │ ├── SessionThread.cpp │ ├── SoftwareBreakpointManager.cpp │ └── X86 │ │ ├── HardwareBreakpointManager.cpp │ │ └── SoftwareBreakpointManager.cpp ├── GDBRemote │ ├── DebugSessionImpl.cpp │ ├── DummySessionDelegateImpl.cpp │ ├── Mixins │ │ ├── FileOperationsMixin.hpp │ │ └── ProcessLaunchMixin.hpp │ ├── PacketProcessor.cpp │ ├── PlatformSessionImpl.cpp │ ├── ProtocolInterpreter.cpp │ ├── Session.cpp │ ├── SessionBase.cpp │ ├── SlaveSessionImpl.cpp │ └── Structures.cpp ├── Host │ ├── Common │ │ ├── Channel.cpp │ │ ├── Platform.cpp │ │ ├── QueueChannel.cpp │ │ └── Socket.cpp │ ├── Darwin │ │ ├── LibProc.cpp │ │ ├── Mach.cpp │ │ ├── PTrace.cpp │ │ ├── Platform.cpp │ │ └── X86_64 │ │ │ ├── MachX86_64.cpp │ │ │ └── PTraceX86_64.cpp │ ├── FreeBSD │ │ ├── PTrace.cpp │ │ ├── Platform.cpp │ │ ├── ProcStat.cpp │ │ └── X86_64 │ │ │ └── PTraceX86_64.cpp │ ├── Linux │ │ ├── ARM │ │ │ └── PTraceARM.cpp │ │ ├── ARM64 │ │ │ └── PTraceARM64.cpp │ │ ├── PTrace.cpp │ │ ├── Platform.cpp │ │ ├── ProcFS.cpp │ │ ├── X86 │ │ │ └── PTraceX86.cpp │ │ └── X86_64 │ │ │ └── PTraceX86_64.cpp │ ├── POSIX │ │ ├── File.cpp │ │ ├── PTrace.cpp │ │ ├── Platform.cpp │ │ └── ProcessSpawner.cpp │ └── Windows │ │ ├── File.cpp │ │ ├── Platform.cpp │ │ └── ProcessSpawner.cpp ├── Support │ └── POSIX │ │ └── ELFSupport.cpp ├── Target │ ├── Common │ │ ├── ARM │ │ │ └── ProcessBaseARM.cpp │ │ ├── ARM64 │ │ │ └── ProcessBaseARM64.cpp │ │ ├── ProcessBase.cpp │ │ ├── ThreadBase.cpp │ │ ├── X86 │ │ │ └── ProcessBaseX86.cpp │ │ └── X86_64 │ │ │ └── ProcessBaseX86_64.cpp │ ├── Darwin │ │ ├── MachOProcess.cpp │ │ ├── Process.cpp │ │ ├── Thread.cpp │ │ └── X86_64 │ │ │ ├── ProcessX86_64.cpp │ │ │ └── ThreadX86_64.cpp │ ├── FreeBSD │ │ ├── Process.cpp │ │ ├── Thread.cpp │ │ ├── X86 │ │ │ └── ProcessX86.cpp │ │ └── X86_64 │ │ │ └── ProcessX86_64.cpp │ ├── Linux │ │ ├── ARM │ │ │ └── ProcessARM.cpp │ │ ├── ARM64 │ │ │ └── ProcessARM64.cpp │ │ ├── Process.cpp │ │ ├── Thread.cpp │ │ ├── X86 │ │ │ └── ProcessX86.cpp │ │ └── X86_64 │ │ │ └── ProcessX86_64.cpp │ ├── POSIX │ │ ├── ELFProcess.cpp │ │ ├── Process.cpp │ │ └── Thread.cpp │ └── Windows │ │ ├── ARM │ │ └── ThreadARM.cpp │ │ ├── Process.cpp │ │ ├── Thread.cpp │ │ ├── X86 │ │ └── ThreadX86.cpp │ │ └── X86_64 │ │ └── ThreadX86_64.cpp ├── Utils │ ├── Backtrace.cpp │ ├── Log.cpp │ ├── OptParse.cpp │ ├── POSIX │ │ ├── Daemon.cpp │ │ ├── FaultHandler.cpp │ │ └── Stringify.cpp │ ├── Paths.cpp │ ├── Stringify.cpp │ └── Windows │ │ ├── Daemon.cpp │ │ ├── FaultHandler.cpp │ │ └── Stringify.cpp └── main.cpp ├── Support ├── CMake │ ├── Toolchain-Android-ARM.cmake │ ├── Toolchain-Android-ARM64.cmake │ ├── Toolchain-Android-X86.cmake │ ├── Toolchain-Android-X86_64.cmake │ ├── Toolchain-Darwin-X86_64.cmake │ ├── Toolchain-Linux-ARM.cmake │ ├── Toolchain-Linux-X86-Clang.cmake │ ├── Toolchain-Linux-X86.cmake │ ├── Toolchain-Linux-X86_64-Clang.cmake │ ├── Toolchain-Linux-X86_64.cmake │ ├── Toolchain-MinGW-X86.cmake │ ├── Toolchain-MinGW-X86_64.cmake │ ├── Toolchain-Tizen-ARM.cmake │ ├── Toolchain-Tizen-X86.cmake │ ├── Toolchain-WinStore-ARM.cmake │ ├── Toolchain-WinStore-x86.cmake │ ├── Toolchain-WinStore-x86_64.cmake │ ├── Toolchain-Windows-x86.cmake │ └── Toolchain-Windows-x86_64.cmake ├── Scripts │ ├── build-windows.bat │ ├── common.sh │ ├── ds2-gdb-wrapper.sh │ ├── generate-documentation.sh │ ├── generate-register-descriptors.sh │ ├── install-android-emulator.sh │ ├── prepare-android-ndk.py │ ├── run-gdb-tests.sh │ ├── run-lldb-tests.sh │ ├── start-android-emulator.py │ ├── test-protocol-latency.py │ └── tidy.py └── Testing │ ├── Blacklists │ ├── ds2 │ │ ├── android-arm64.blacklist │ │ ├── android.blacklist │ │ ├── android_invalid_tests.blacklist │ │ ├── centos.blacklist │ │ ├── general.blacklist │ │ ├── platform.blacklist │ │ ├── x86-platform.blacklist │ │ ├── x86.blacklist │ │ ├── x86_64-platform.blacklist │ │ └── x86_64.blacklist │ └── upstream │ │ ├── general.blacklist │ │ ├── non-debugserver-tests.blacklist │ │ ├── platform.blacklist │ │ ├── x86-platform.blacklist │ │ └── x86.blacklist │ ├── CircleCI │ ├── Dockerfile │ └── install-cmake.sh │ ├── Patches │ ├── android-search-paths.patch │ ├── fix-test-suite-path.patch │ ├── gdb │ │ ├── Disable-broken-break-tests.patch │ │ ├── Disable-broken-printcmds-tests.patch │ │ └── Disable-broken-step-bt-tests.patch │ └── getplatform-workaround.patch │ └── Travis │ ├── after-success.sh │ ├── before-install.py │ ├── deploy-key.enc │ ├── install.py │ ├── script.sh │ └── travis-hacks.sh └── Tools ├── JSObjects ├── CMakeLists.txt ├── Headers │ └── JSObjects │ │ └── JSObjects.h └── Sources │ ├── JSObjects.cpp │ └── libjson │ ├── LICENSE_1_0.txt │ ├── json.c │ ├── json_internal.h │ ├── jsoncb.h │ ├── jsontest.c │ ├── parser.y │ ├── qstring.c │ ├── qstring.h │ └── tokenizer.l └── RegsGen2 ├── CMakeLists.txt ├── Constants.h ├── Context.h ├── Definitions.h ├── Definitions.txt ├── FlagSet.cpp ├── FlagSet.h ├── GDBDefinitions.cpp ├── GDBDefinitions.h ├── GDBVectorSet.cpp ├── GDBVectorSet.h ├── KeyValue.h ├── LLDBDefinitions.cpp ├── LLDBDefinitions.h ├── ParseConstants.cpp ├── ParseConstants.h ├── RegisterSet.cpp ├── RegisterSet.h ├── RegisterTemplate.cpp ├── RegisterTemplate.h └── main.cpp /.appveyor.yml: -------------------------------------------------------------------------------- 1 | # Operating system (build VM template) 2 | os: Visual Studio 2017 3 | 4 | version: 0.1-branch-{branch}-build-{build} 5 | 6 | branches: 7 | only: 8 | - master 9 | 10 | environment: 11 | matrix: 12 | - toolchain: "Windows-x86_64" 13 | - toolchain: "Windows-x86" 14 | - toolchain: "WinStore-x86" 15 | - toolchain: "WinStore-x86_64" 16 | - toolchain: "WinStore-ARM" 17 | 18 | clone_folder: c:\projects\ds2 19 | shallow_clone: true 20 | 21 | platform: x64 22 | configuration: Release 23 | 24 | install: 25 | - C:\cygwin\setup-x86.exe 26 | -qnNdO 27 | -R C:/cygwin 28 | -s http://cygwin.mirror.constant.com 29 | -l C:/cygwin/var/cache/setup 30 | -P bison -P flex 31 | 32 | build_script: 33 | - mkdir "C:\projects\ds2\build" 34 | - set PATH=%PATH%;C:\cygwin\bin 35 | - echo Running cmake... 36 | - cd c:\projects\ds2\build 37 | - cmake -G "Visual Studio 15 2017" -DCMAKE_TOOLCHAIN_FILE=../Support/CMake/Toolchain-%toolchain%.cmake .. 38 | - msbuild /p:Configuration=Release ds2.vcxproj 39 | 40 | test: off 41 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | SortIncludes: true 3 | IncludeIsMainRegex: "" 4 | -------------------------------------------------------------------------------- /.clang-tidy: -------------------------------------------------------------------------------- 1 | Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming' 2 | -------------------------------------------------------------------------------- /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-ci 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | build-*/ 3 | html/ 4 | *.swp 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | dist: trusty 12 | sudo: required 13 | language: generic 14 | filter_secrets: false 15 | branches: 16 | only: 17 | - master 18 | 19 | env: 20 | global: 21 | - LINUX_DISTRO="trusty" 22 | 23 | matrix: 24 | fast_finish: true 25 | include: 26 | # Documentation 27 | - os: linux 28 | env: TARGET="Documentation" ENCRYPTION_LABEL="c06a05533acc" 29 | 30 | # Use travis_retry during install to reduce the impact of network failures. 31 | before_install: travis_retry ./Support/Testing/Travis/before-install.py 32 | install: travis_retry ./Support/Testing/Travis/install.py 33 | script: ./Support/Testing/Travis/script.sh 34 | after_success: ./Support/Testing/Travis/after-success.sh 35 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please [read the full text](https://code.facebook.com/codeofconduct) so that you can understand what actions will and will not be tolerated. 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to ds2 2 | 3 | We want to make contributing to this project as easy and transparent as 4 | possible. 5 | 6 | ## Code of Conduct 7 | Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please [read the full text](https://code.facebook.com/codeofconduct) so that you can understand what actions will and will not be tolerated. 8 | 9 | ## Pull Requests 10 | 11 | We actively welcome your pull requests. 12 | 1. Fork the repo and create your branch from `master`. 13 | 2. Make sure your code follows the coding style. 14 | 3. If you haven't already, complete the Contributor License Agreement ("CLA"). 15 | 16 | ## Contributor License Agreement ("CLA") 17 | 18 | In order to accept your pull request, we need you to submit a CLA. You only need 19 | to do this once to work on any of Facebook's open source projects. 20 | 21 | Complete your CLA [here](https://code.facebook.com/cla). 22 | 23 | ## Issues 24 | 25 | We use GitHub issues to track public bugs. Please ensure your description is 26 | clear and has sufficient instructions to be able to reproduce the issue. 27 | 28 | Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe 29 | disclosure of security bugs. In those cases, please go through the process 30 | outlined on that page and do not file a public issue. 31 | 32 | ## Documentation 33 | 34 | We generate documentation for the project using doxygen. See 35 | http://facebook.github.io/ds2/ to learn about the project's internals. 36 | 37 | ## Coding Style 38 | 39 | We follow LLVM's [coding style](http://llvm.org/docs/CodingStandards.html). In 40 | most cases, just running `clang-format` on your code should be enough. 41 | 42 | ## License 43 | 44 | By contributing to ds2, you agree that your contributions will be licensed 45 | under its University of Illinois/NCSA Open Source License. 46 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Architecture/ARM/SoftwareSingleStep.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Architecture/CPUState.h" 14 | #include "DebugServer2/Core/BreakpointManager.h" 15 | #include "DebugServer2/Target/Process.h" 16 | 17 | namespace ds2 { 18 | namespace Architecture { 19 | namespace ARM { 20 | 21 | ErrorCode PrepareThumbSoftwareSingleStep(Target::Process *process, uint32_t pc, 22 | Architecture::CPUState const &state, 23 | bool &link, uint32_t &nextPC, 24 | uint32_t &nextPCSize, 25 | uint32_t &branchPC, 26 | uint32_t &branchPCSize); 27 | 28 | ErrorCode PrepareARMSoftwareSingleStep(Target::Process *process, uint32_t pc, 29 | Architecture::CPUState const &state, 30 | bool &link, uint32_t &nextPC, 31 | uint32_t &nextPCSize, uint32_t &branchPC, 32 | uint32_t &branchPCSize); 33 | 34 | ErrorCode PrepareSoftwareSingleStep(Target::Process *process, 35 | BreakpointManager *manager, 36 | CPUState const &state, 37 | Address const &address); 38 | } // namespace ARM 39 | } // namespace Architecture 40 | } // namespace ds2 41 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Architecture/CPUState.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Types.h" 14 | 15 | #define CPUSTATE_H_INTERNAL 16 | 17 | #if defined(ARCH_ARM) 18 | #include "DebugServer2/Architecture/ARM/CPUState.h" 19 | #elif defined(ARCH_ARM64) 20 | #include "DebugServer2/Architecture/ARM/CPUState.h" 21 | #include "DebugServer2/Architecture/ARM64/CPUState.h" 22 | #elif defined(ARCH_X86) 23 | #include "DebugServer2/Architecture/X86/CPUState.h" 24 | #elif defined(ARCH_X86_64) 25 | #include "DebugServer2/Architecture/X86/CPUState.h" 26 | #include "DebugServer2/Architecture/X86_64/CPUState.h" 27 | #else 28 | #error "Architecture not supported." 29 | #endif 30 | 31 | #undef CPUSTATE_H_INTERNAL 32 | 33 | namespace ds2 { 34 | namespace Architecture { 35 | #if defined(ARCH_ARM) 36 | using ARM::CPUState; 37 | #elif defined(ARCH_ARM64) 38 | using ARM64::CPUState; 39 | #elif defined(ARCH_X86) 40 | using X86::CPUState; 41 | #elif defined(ARCH_X86_64) 42 | using X86_64::CPUState; 43 | #else 44 | #error "Architecture not supported." 45 | #endif 46 | } // namespace Architecture 47 | } // namespace ds2 48 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Architecture/Registers.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Base.h" 14 | 15 | #if defined(ARCH_ARM) 16 | #include "DebugServer2/Architecture/ARM/Registers.h" 17 | #elif defined(ARCH_ARM64) 18 | #include "DebugServer2/Architecture/ARM/Registers.h" 19 | #include "DebugServer2/Architecture/ARM64/Registers.h" 20 | #elif defined(ARCH_X86) 21 | #include "DebugServer2/Architecture/I386/Registers.h" 22 | #elif defined(ARCH_X86_64) 23 | #include "DebugServer2/Architecture/I386/Registers.h" 24 | #include "DebugServer2/Architecture/X86_64/Registers.h" 25 | #else 26 | #error "Architecture not supported." 27 | #endif 28 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Architecture/RegistersDescriptors.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #ifndef __DebugServer2_Architecture_RegistersDescriptors_h 12 | #define __DebugServer2_Architecture_RegistersDescriptors_h 13 | 14 | #include "DebugServer2/Base.h" 15 | 16 | #define USE_DESCRIPTORS(ARCH) \ 17 | namespace ds2 { \ 18 | namespace Architecture { \ 19 | using ds2::Architecture::ARCH::GDB; \ 20 | using ds2::Architecture::ARCH::LLDB; \ 21 | } \ 22 | } 23 | 24 | #if defined(ARCH_ARM) 25 | #include "DebugServer2/Architecture/ARM/RegistersDescriptors.h" 26 | USE_DESCRIPTORS(ARM); 27 | #elif defined(ARCH_ARM64) 28 | #include "DebugServer2/Architecture/ARM64/RegistersDescriptors.h" 29 | USE_DESCRIPTORS(ARM64); 30 | #elif defined(ARCH_X86) 31 | #include "DebugServer2/Architecture/X86/RegistersDescriptors.h" 32 | USE_DESCRIPTORS(X86); 33 | #elif defined(ARCH_X86_64) 34 | #include "DebugServer2/Architecture/X86_64/RegistersDescriptors.h" 35 | USE_DESCRIPTORS(X86_64); 36 | #else 37 | #error "Architecture not supported." 38 | #endif 39 | 40 | #undef USE_DESCRIPTORS 41 | 42 | #endif // !__DebugServer2_Architecture_RegistersDescriptors_h 43 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Constants.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | namespace ds2 { 14 | 15 | // 16 | // Endian 17 | // 18 | 19 | enum Endian { 20 | kEndianUnknown = 0, 21 | kEndianBig = 1, 22 | kEndianLittle = 2, 23 | kEndianPDP = 3, 24 | #if defined(ENDIAN_BIG) 25 | kEndianNative = kEndianBig, 26 | #elif defined(ENDIAN_LITTLE) 27 | kEndianNative = kEndianLittle, 28 | #elif defined(ENDIAN_MIDDLE) 29 | kEndianNative = kEndianPDP, 30 | #else 31 | kEndianNative = kEndianUnknown, 32 | #endif 33 | }; 34 | 35 | // 36 | // Memory Protection 37 | // 38 | 39 | enum /*Protection*/ { 40 | kProtectionNone = 0, 41 | kProtectionExecute = (1 << 0), 42 | kProtectionWrite = (1 << 1), 43 | kProtectionRead = (1 << 2) 44 | }; 45 | 46 | // 47 | // Open flags 48 | // 49 | 50 | enum OpenFlags { 51 | kOpenFlagInvalid = 0, 52 | kOpenFlagRead = (1 << 0), 53 | kOpenFlagWrite = (1 << 1), 54 | kOpenFlagAppend = (1 << 2), 55 | kOpenFlagTruncate = (1 << 3), 56 | kOpenFlagNonBlocking = (1 << 4), 57 | kOpenFlagCreate = (1 << 5), 58 | kOpenFlagNewOnly = (1 << 6), 59 | kOpenFlagNoFollow = (1 << 7), 60 | kOpenFlagCloseOnExec = (1 << 8) 61 | }; 62 | } // namespace ds2 63 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Core/ErrorCodes.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | namespace ds2 { 16 | 17 | // Error Codes as defined by GDB remoting documentation, 18 | // plus some others. 19 | enum ErrorCode { 20 | kSuccess, 21 | kErrorNoPermission = 1, 22 | kErrorNotFound = 2, 23 | kErrorProcessNotFound = 3, 24 | kErrorInterrupted = 4, 25 | kErrorInvalidHandle = 9, 26 | kErrorNoMemory = 12, 27 | kErrorAccessDenied = 13, 28 | kErrorInvalidAddress = 14, 29 | kErrorBusy = 16, 30 | kErrorAlreadyExist = 17, 31 | kErrorNoDevice = 19, 32 | kErrorNotDirectory = 20, 33 | kErrorIsDirectory = 21, 34 | kErrorInvalidArgument = 22, 35 | kErrorTooManySystemFiles = 23, 36 | kErrorTooManyFiles = 24, 37 | kErrorFileTooBig = 27, 38 | kErrorNoSpace = 28, 39 | kErrorInvalidSeek = 29, 40 | kErrorNotWriteable = 30, 41 | kErrorNameTooLong = 91, 42 | kErrorUnknown = 9999, 43 | kErrorUnsupported = 10000 44 | }; 45 | 46 | char const *GetErrorCodeString(ErrorCode err); 47 | 48 | #define CHK_ACTION(C, A) \ 49 | do { \ 50 | auto __CHK_expr_lambda = [&]() { return C; }; \ 51 | static_assert( \ 52 | std::is_same::value, \ 53 | #C " is not an expression of type ErrorCode"); \ 54 | ErrorCode CHK_error = (C); \ 55 | if (CHK_error != kSuccess) { \ 56 | A; \ 57 | } \ 58 | } while (0) 59 | } // namespace ds2 60 | 61 | #define CHK(C) CHK_ACTION(C, return CHK_error) 62 | #define CHKV(C) CHK_ACTION(C, return ) 63 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Core/MessageQueue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Base.h" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace ds2 { 21 | 22 | class MessageQueue { 23 | private: 24 | std::deque _messages; 25 | std::condition_variable _ready; 26 | std::mutex _lock; 27 | bool _terminated; 28 | 29 | public: 30 | MessageQueue(); 31 | 32 | public: 33 | void put(std::string const &message); 34 | std::string get(int wait = -1); // Wait is expressed in milliseconds 35 | 36 | // Wait until the queue is non-empty. Returns false if 37 | // the queue is empty after the timeout, true otherwise. 38 | // (Note that get() may still block after returning if 39 | // another thread pulls from the queue.) 40 | bool wait(int ms = -1); 41 | 42 | public: 43 | void clear(bool terminating); 44 | }; 45 | } // namespace ds2 46 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Core/SessionThread.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #ifndef __SessionThread_h 12 | #define __SessionThread_h 13 | 14 | #include "DebugServer2/GDBRemote/PacketProcessor.h" 15 | #include "DebugServer2/GDBRemote/Session.h" 16 | #include "DebugServer2/Host/QueueChannel.h" 17 | 18 | #include 19 | 20 | class SessionThread : public ds2::GDBRemote::PacketProcessorDelegate { 21 | private: 22 | ds2::Host::QueueChannel *_channel; 23 | ds2::GDBRemote::Session *_session; 24 | ds2::GDBRemote::PacketProcessor _pp; 25 | std::thread _thread; 26 | 27 | public: 28 | SessionThread(ds2::Host::QueueChannel *channel, 29 | ds2::GDBRemote::Session *session); 30 | ~SessionThread(); 31 | 32 | public: 33 | void start(); 34 | 35 | protected: 36 | void onPacketData(std::string const &data, bool valid) override; 37 | void onInvalidData(std::string const &data) override; 38 | 39 | private: 40 | void run(); 41 | }; 42 | 43 | #endif // !__SessionThread_h 44 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Core/SoftwareBreakpointManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Core/BreakpointManager.h" 14 | 15 | namespace ds2 { 16 | class SoftwareBreakpointManager : public BreakpointManager { 17 | private: 18 | std::map _insns; 19 | bool _enabled; 20 | 21 | public: 22 | SoftwareBreakpointManager(Target::ProcessBase *process); 23 | ~SoftwareBreakpointManager() override; 24 | 25 | public: 26 | virtual void clear() override; 27 | 28 | public: 29 | virtual int hit(Target::Thread *thread, Site &site) override; 30 | 31 | protected: 32 | virtual void getOpcode(uint32_t type, ByteVector &opcode) const; 33 | 34 | protected: 35 | virtual ErrorCode enableLocation(Site const &site, 36 | Target::Thread *thread = nullptr) override; 37 | virtual ErrorCode disableLocation(Site const &site, 38 | Target::Thread *thread = nullptr) override; 39 | 40 | public: 41 | void enable(Target::Thread *thread = nullptr) override; 42 | void disable(Target::Thread *thread = nullptr) override; 43 | 44 | protected: 45 | ErrorCode isValid(Address const &address, size_t size, 46 | Mode mode) const override; 47 | size_t chooseBreakpointSize() const override; 48 | 49 | #if defined(ARCH_ARM) || defined(ARCH_ARM64) 50 | public: 51 | virtual void 52 | enumerate(std::function const &cb) const override; 53 | 54 | public: 55 | virtual ErrorCode add(Address const &address, Lifetime lifetime, size_t size, 56 | Mode mode) override; 57 | virtual ErrorCode remove(Address const &address) override; 58 | 59 | public: 60 | virtual bool has(Address const &address) const override; 61 | #endif 62 | 63 | virtual bool enabled(Target::Thread *thread = nullptr) const override; 64 | 65 | public: 66 | virtual bool fillStopInfo(Target::Thread *thread, 67 | StopInfo &stopInfo) override; 68 | }; 69 | } // namespace ds2 70 | -------------------------------------------------------------------------------- /Headers/DebugServer2/GDBRemote/Base.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Types.h" 14 | 15 | namespace ds2 { 16 | namespace GDBRemote { 17 | 18 | enum CompatibilityMode { 19 | kCompatibilityModeGDB, 20 | kCompatibilityModeGDBMultiprocess, 21 | kCompatibilityModeLLDB, 22 | // This is a special case for GDBRemote::ProcessThreadId::encode, 23 | // don't use it anywhere else! 24 | kCompatibilityModeLLDBThread 25 | }; 26 | 27 | enum AttachMode { kAttachNow, kAttachAndWait, kAttachOrWait }; 28 | 29 | enum BreakpointType : unsigned { 30 | kSoftwareBreakpoint = 0, 31 | kHardwareBreakpoint = 1, 32 | kWriteWatchpoint = 2, 33 | kReadWatchpoint = 3, 34 | kAccessWatchpoint = 4, 35 | kBreakpointTypeMax = 5 36 | }; 37 | } // namespace GDBRemote 38 | } // namespace ds2 39 | -------------------------------------------------------------------------------- /Headers/DebugServer2/GDBRemote/Mixins/ProcessLaunchMixin.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/GDBRemote/DummySessionDelegateImpl.h" 14 | #include "DebugServer2/Host/File.h" 15 | #include "DebugServer2/Host/Platform.h" 16 | #include "DebugServer2/Host/ProcessSpawner.h" 17 | #include "DebugServer2/Target/Process.h" 18 | #include "DebugServer2/Target/Thread.h" 19 | 20 | #include 21 | 22 | using ds2::Host::Platform; 23 | 24 | namespace ds2 { 25 | namespace GDBRemote { 26 | 27 | template class ProcessLaunchMixin : public T { 28 | protected: 29 | typedef std::map EnvironmentMap; 30 | 31 | protected: 32 | bool _disableASLR; 33 | std::string _workingDirectory; 34 | EnvironmentMap _environment; 35 | std::string _stdFile[3]; 36 | StringCollection _arguments; 37 | 38 | public: 39 | template 40 | explicit ProcessLaunchMixin(Args &&... args) 41 | : T(std::forward(args)...), _disableASLR(false), 42 | _workingDirectory(Platform::GetWorkingDirectory()) {} 43 | 44 | public: 45 | ErrorCode onDisableASLR(Session &session, bool disable) override; 46 | ErrorCode onSetArchitecture(Session &session, 47 | std::string const &architecture) override; 48 | ErrorCode onSetWorkingDirectory(Session &session, 49 | std::string const &path) override; 50 | ErrorCode onQueryWorkingDirectory(Session &session, 51 | std::string &workingDir) const override; 52 | ErrorCode onSetEnvironmentVariable(Session &session, std::string const &name, 53 | std::string const &value) override; 54 | ErrorCode onSetStdFile(Session &session, int fileno, 55 | std::string const &path) override; 56 | ErrorCode onSetProgramArguments(Session &session, 57 | StringCollection const &args) override; 58 | ErrorCode onQueryLaunchSuccess(Session &session, 59 | ProcessId pid) const override; 60 | }; 61 | } // namespace GDBRemote 62 | } // namespace ds2 63 | 64 | #include "../Sources/GDBRemote/Mixins/ProcessLaunchMixin.hpp" 65 | -------------------------------------------------------------------------------- /Headers/DebugServer2/GDBRemote/PacketProcessor.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Types.h" 14 | 15 | namespace ds2 { 16 | namespace GDBRemote { 17 | 18 | struct PacketProcessorDelegate; 19 | 20 | class PacketProcessor { 21 | public: 22 | virtual ~PacketProcessor() {} 23 | 24 | protected: 25 | std::string _buffer; 26 | size_t _nreqs; 27 | bool _needhash; 28 | PacketProcessorDelegate *_delegate; 29 | 30 | public: 31 | PacketProcessor(); 32 | 33 | public: 34 | inline void setDelegate(PacketProcessorDelegate *delegate) { 35 | _delegate = delegate; 36 | } 37 | inline PacketProcessorDelegate *delegate() const { 38 | return const_cast(this)->_delegate; 39 | } 40 | 41 | public: 42 | void parse(std::string const &data); 43 | 44 | private: 45 | void process(); 46 | 47 | private: 48 | bool validate(); 49 | }; 50 | 51 | struct PacketProcessorDelegate { 52 | virtual ~PacketProcessorDelegate() {} 53 | virtual void onPacketData(std::string const &data, bool valid) = 0; 54 | virtual void onInvalidData(std::string const &data) = 0; 55 | }; 56 | } // namespace GDBRemote 57 | } // namespace ds2 58 | -------------------------------------------------------------------------------- /Headers/DebugServer2/GDBRemote/PlatformSessionImpl.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/GDBRemote/DummySessionDelegateImpl.h" 14 | #include "DebugServer2/GDBRemote/Mixins/FileOperationsMixin.h" 15 | #include "DebugServer2/GDBRemote/Mixins/ProcessLaunchMixin.h" 16 | #include "DebugServer2/Utils/MPL.h" 17 | 18 | namespace ds2 { 19 | namespace GDBRemote { 20 | 21 | class PlatformSessionImplBase : public DummySessionDelegateImpl { 22 | protected: 23 | // a struct to help iterate over the process list for onQueryProcessList 24 | mutable IterationState _processIterationState; 25 | 26 | public: 27 | PlatformSessionImplBase(); 28 | 29 | protected: 30 | ErrorCode onQueryProcessList(Session &session, ProcessInfoMatch const &match, 31 | bool first, ProcessInfo &info) const override; 32 | ErrorCode onQueryProcessInfo(Session &session, ProcessId pid, 33 | ProcessInfo &info) const override; 34 | 35 | ErrorCode onExecuteProgram(Session &session, std::string const &command, 36 | uint32_t timeout, 37 | std::string const &workingDirectory, 38 | ProgramResult &result) override; 39 | 40 | protected: 41 | ErrorCode onQueryUserName(Session &session, UserId const &uid, 42 | std::string &name) const override; 43 | ErrorCode onQueryGroupName(Session &session, GroupId const &gid, 44 | std::string &name) const override; 45 | 46 | protected: 47 | ErrorCode onLaunchDebugServer(Session &session, std::string const &host, 48 | uint16_t &port, ProcessId &pid) override; 49 | 50 | private: 51 | void updateProcesses(ProcessInfoMatch const &match) const; 52 | }; 53 | 54 | using PlatformSessionImpl = 55 | Utils::MixinApply; 57 | } // namespace GDBRemote 58 | } // namespace ds2 59 | -------------------------------------------------------------------------------- /Headers/DebugServer2/GDBRemote/ProtocolHelpers.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Types.h" 14 | #include "DebugServer2/Utils/Log.h" 15 | 16 | #include 17 | #include 18 | 19 | namespace ds2 { 20 | namespace GDBRemote { 21 | 22 | template uint8_t Checksum(T const &data) { 23 | uint8_t csum = 0; 24 | for (char n : data) { 25 | csum += n; 26 | } 27 | return csum; 28 | } 29 | 30 | template std::string Escape(T const &data) { 31 | std::ostringstream ss; 32 | auto first = data.begin(); 33 | auto last = data.begin(); 34 | static std::string const searchStr = "$#}*"; 35 | 36 | while ((last = std::find_first_of(first, data.end(), searchStr.begin(), 37 | searchStr.end())) != data.end()) { 38 | while (first < last) { 39 | ss << *first++; 40 | } 41 | ss << '}' << static_cast(*last - 0x20); 42 | first = ++last; 43 | } 44 | 45 | while (first < data.end()) { 46 | ss << *first++; 47 | } 48 | 49 | return ss.str(); 50 | } 51 | 52 | template std::string Unescape(T const &data) { 53 | std::ostringstream ss; 54 | auto first = data.begin(); 55 | auto last = data.begin(); 56 | 57 | while ((last = std::find(first, data.end(), '}')) != data.end()) { 58 | while (first < last) { 59 | ss << *first++; 60 | } 61 | ss << static_cast(*(last + 1) + 0x20); 62 | last += 2, first = last; 63 | } 64 | 65 | while (first < data.end()) { 66 | ss << *first++; 67 | } 68 | 69 | return ss.str(); 70 | } 71 | } // namespace GDBRemote 72 | } // namespace ds2 73 | -------------------------------------------------------------------------------- /Headers/DebugServer2/GDBRemote/ProtocolInterpreter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/GDBRemote/PacketProcessor.h" 14 | 15 | namespace ds2 { 16 | namespace GDBRemote { 17 | 18 | class SessionBase; 19 | struct ProtocolHandler; 20 | 21 | class ProtocolInterpreter : public PacketProcessorDelegate { 22 | public: 23 | struct Handler { 24 | typedef std::vector Collection; 25 | typedef void (ProtocolHandler::*Callback)(Handler const &handler, 26 | std::string const &data); 27 | 28 | enum Mode { kModeEquals, kModeStartsWith }; 29 | 30 | Mode mode; 31 | std::string command; 32 | ProtocolHandler *handler; 33 | Callback callback; 34 | 35 | int compare(std::string const &command) const; 36 | }; 37 | 38 | private: 39 | SessionBase *_session; 40 | Handler::Collection _handlers; 41 | std::vector _lastCommands; 42 | 43 | public: 44 | ProtocolInterpreter(); 45 | 46 | public: 47 | inline void setSession(SessionBase *session) { _session = session; } 48 | inline SessionBase *session() const { 49 | return const_cast(this)->_session; 50 | } 51 | 52 | public: 53 | void onCommand(std::string const &command, std::string const &arguments); 54 | 55 | public: 56 | bool registerHandler(Handler const &handler); 57 | 58 | template 59 | inline bool 60 | registerHandler(Handler::Mode const &mode, std::string const &command, 61 | ProtocolHandler *handler, CallbackType const &callback) { 62 | Handler _handler = {mode, command, handler, (Handler::Callback)callback}; 63 | return registerHandler(_handler); 64 | } 65 | 66 | private: 67 | Handler const *findHandler(std::string const &command, 68 | size_t &commandLength) const; 69 | 70 | public: 71 | void onPacketData(std::string const &data, bool valid) override; 72 | void onInvalidData(std::string const &data) override; 73 | 74 | public: 75 | inline std::vector const &lastCommands() const { 76 | return _lastCommands; 77 | } 78 | inline void clearLastCommands() { _lastCommands.clear(); } 79 | }; 80 | 81 | struct ProtocolHandler {}; 82 | } // namespace GDBRemote 83 | } // namespace ds2 84 | -------------------------------------------------------------------------------- /Headers/DebugServer2/GDBRemote/SlaveSessionImpl.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/GDBRemote/DebugSessionImpl.h" 14 | 15 | namespace ds2 { 16 | namespace GDBRemote { 17 | 18 | class SlaveSessionImpl : public DebugSessionImpl { 19 | public: 20 | SlaveSessionImpl(); 21 | }; 22 | } // namespace GDBRemote 23 | } // namespace ds2 24 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Host/Channel.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Types.h" 14 | 15 | namespace ds2 { 16 | namespace Host { 17 | 18 | class Channel { 19 | public: 20 | virtual ~Channel() = default; 21 | 22 | public: 23 | virtual void close() = 0; 24 | 25 | public: 26 | virtual bool connected() const = 0; 27 | 28 | public: 29 | virtual bool wait(int ms = -1) = 0; 30 | 31 | public: 32 | virtual ssize_t send(void const *buffer, size_t length) = 0; 33 | virtual ssize_t receive(void *buffer, size_t length) = 0; 34 | 35 | public: 36 | virtual bool send(std::string const &buffer); 37 | virtual bool receive(std::string &buffer); 38 | }; 39 | } // namespace Host 40 | } // namespace ds2 41 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Host/Darwin/LibProc.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015, Jakub Klama 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Target/ThreadBase.h" 14 | #include "DebugServer2/Types.h" 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace ds2 { 25 | namespace Host { 26 | namespace Darwin { 27 | 28 | class LibProc { 29 | public: 30 | static bool GetProcessInfo(ProcessId pid, ProcessInfo &info); 31 | static void 32 | EnumerateProcesses(bool allUsers, UserId const &uid, 33 | std::function const &cb); 34 | static std::string GetThreadName(ProcessThreadId const &ptid); 35 | static const char *GetExecutablePath(ProcessId pid); 36 | }; 37 | } // namespace Darwin 38 | } // namespace Host 39 | } // namespace ds2 40 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Host/Darwin/Mach.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Corentin Derbois 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Architecture/CPUState.h" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace ds2 { 21 | namespace Host { 22 | namespace Darwin { 23 | 24 | class Mach { 25 | public: 26 | virtual ~Mach() = default; 27 | 28 | public: 29 | ErrorCode readMemory(ProcessThreadId const &ptid, Address const &address, 30 | void *buffer, size_t length, size_t *nread = nullptr); 31 | ErrorCode writeMemory(ProcessThreadId const &ptid, Address const &address, 32 | void const *buffer, size_t length, 33 | size_t *nwritten = nullptr); 34 | 35 | public: 36 | ErrorCode readCPUState(ProcessThreadId const &ptid, ProcessInfo const &info, 37 | Architecture::CPUState &state); 38 | ErrorCode writeCPUState(ProcessThreadId const &ptid, ProcessInfo const &info, 39 | Architecture::CPUState const &state); 40 | 41 | public: 42 | ErrorCode suspend(ProcessThreadId const &ptid); 43 | 44 | public: 45 | ErrorCode step(ProcessThreadId const &ptid, ProcessInfo const &pinfo, 46 | int signal = 0, Address const &address = Address()); 47 | ErrorCode resume(ProcessThreadId const &ptid, ProcessInfo const &pinfo, 48 | int signal = 0, Address const &address = Address()); 49 | 50 | public: 51 | ErrorCode getProcessDylbInfo(ProcessId pid, Address &address); 52 | ErrorCode getProcessMemoryRegion(ProcessId pid, Address const &address, 53 | MemoryRegionInfo &info); 54 | 55 | public: 56 | ErrorCode getThreadInfo(ProcessThreadId const &tid, thread_basic_info_t info); 57 | ErrorCode getThreadIdentifierInfo(ProcessThreadId const &tid, 58 | thread_identifier_info_data_t *threadID); 59 | 60 | private: 61 | task_t getMachTask(ProcessId pid); 62 | thread_t getMachThread(ProcessThreadId const &tid); 63 | }; 64 | } // namespace Darwin 65 | } // namespace Host 66 | } // namespace ds2 67 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Host/Darwin/PTrace.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Architecture/CPUState.h" 14 | #include "DebugServer2/Host/POSIX/PTrace.h" 15 | 16 | namespace ds2 { 17 | namespace Host { 18 | namespace Darwin { 19 | 20 | struct PTracePrivateData; 21 | 22 | class PTrace : public POSIX::PTrace { 23 | public: 24 | ErrorCode traceThat(ProcessId pid) override; 25 | 26 | public: 27 | ErrorCode kill(ProcessThreadId const &ptid, int signal) override; 28 | 29 | public: 30 | ErrorCode readString(ProcessThreadId const &ptid, Address const &address, 31 | std::string &str, size_t length, 32 | size_t *nread = nullptr) override; 33 | ErrorCode readMemory(ProcessThreadId const &ptid, Address const &address, 34 | void *buffer, size_t length, 35 | size_t *nread = nullptr) override; 36 | ErrorCode writeMemory(ProcessThreadId const &ptid, Address const &address, 37 | void const *buffer, size_t length, 38 | size_t *nwritten = nullptr) override; 39 | 40 | public: 41 | ErrorCode readCPUState(ProcessThreadId const &ptid, ProcessInfo const &info, 42 | Architecture::CPUState &state) override; 43 | ErrorCode writeCPUState(ProcessThreadId const &ptid, ProcessInfo const &info, 44 | Architecture::CPUState const &state) override; 45 | 46 | public: 47 | ErrorCode suspend(ProcessThreadId const &ptid) override; 48 | 49 | public: 50 | ErrorCode getSigInfo(ProcessThreadId const &ptid, siginfo_t &si) override; 51 | }; 52 | } // namespace Darwin 53 | } // namespace Host 54 | } // namespace ds2 55 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Host/File.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Base.h" 14 | #include "DebugServer2/Constants.h" 15 | #include "DebugServer2/Types.h" 16 | #include "DebugServer2/Utils/Log.h" 17 | 18 | #include 19 | #include 20 | 21 | namespace ds2 { 22 | namespace Host { 23 | 24 | class File { 25 | public: 26 | File(std::string const &path, OpenFlags flags, uint32_t mode); 27 | ~File(); 28 | 29 | public: 30 | File(const File &other) = delete; 31 | File &operator=(const File &other) = delete; 32 | 33 | public: 34 | File(File &&other) : _fd(-1), _lastError(kErrorInvalidHandle) { 35 | *this = std::move(other); 36 | } 37 | 38 | File &operator=(File &&other) { 39 | DS2ASSERT(&other != this); 40 | 41 | std::swap(_fd, other._fd); 42 | std::swap(_lastError, other._lastError); 43 | 44 | return *this; 45 | } 46 | 47 | public: 48 | ErrorCode pread(ByteVector &buf, uint64_t &count, uint64_t offset); 49 | ErrorCode pwrite(ByteVector const &buf, uint64_t &count, uint64_t offset); 50 | 51 | public: 52 | bool valid() const { return (_fd >= 0); } 53 | ErrorCode lastError() const { return _lastError; } 54 | 55 | public: 56 | static ErrorCode chmod(std::string const &path, uint32_t mode); 57 | 58 | public: 59 | static ErrorCode unlink(std::string const &path); 60 | 61 | public: 62 | static ErrorCode createDirectory(std::string const &path, uint32_t flags); 63 | 64 | protected: 65 | int _fd; 66 | ErrorCode _lastError; 67 | }; 68 | } // namespace Host 69 | } // namespace ds2 70 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Host/FreeBSD/PTrace.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Architecture/CPUState.h" 14 | #include "DebugServer2/Host/POSIX/PTrace.h" 15 | 16 | namespace ds2 { 17 | namespace Host { 18 | namespace FreeBSD { 19 | 20 | struct PTracePrivateData; 21 | 22 | class PTrace : public POSIX::PTrace { 23 | public: 24 | virtual ErrorCode traceThat(ProcessId pid); 25 | 26 | public: 27 | virtual ErrorCode kill(ProcessThreadId const &ptid, int signal); 28 | 29 | public: 30 | virtual ErrorCode readString(ProcessThreadId const &ptid, 31 | Address const &address, std::string &str, 32 | size_t length, size_t *nread = nullptr); 33 | virtual ErrorCode readMemory(ProcessThreadId const &ptid, 34 | Address const &address, void *buffer, 35 | size_t length, size_t *nread = nullptr); 36 | virtual ErrorCode writeMemory(ProcessThreadId const &ptid, 37 | Address const &address, void const *buffer, 38 | size_t length, size_t *nwritten = nullptr); 39 | 40 | public: 41 | virtual ErrorCode readCPUState(ProcessThreadId const &ptid, 42 | ProcessInfo const &info, 43 | Architecture::CPUState &state); 44 | virtual ErrorCode writeCPUState(ProcessThreadId const &ptid, 45 | ProcessInfo const &info, 46 | Architecture::CPUState const &state); 47 | 48 | public: 49 | virtual ErrorCode getLwpInfo(ProcessThreadId const &ptid, 50 | struct ptrace_lwpinfo *lwpinfo); 51 | 52 | public: 53 | virtual ErrorCode getSigInfo(ProcessThreadId const &ptid, siginfo_t &si); 54 | }; 55 | } // namespace FreeBSD 56 | } // namespace Host 57 | } // namespace ds2 58 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Host/FreeBSD/ProcStat.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015, Jakub Klama 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Support/POSIX/ELFSupport.h" 14 | #include "DebugServer2/Types.h" 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace ds2 { 25 | namespace Host { 26 | namespace FreeBSD { 27 | 28 | using ds2::Support::ELFSupport; 29 | 30 | enum ProcState { 31 | kProcStateDead = 0, 32 | kProcStateRunning = SRUN, 33 | kProcStateSleeping = SSLEEP, 34 | kProcStateWaiting = SWAIT, 35 | kProcStateLock = SLOCK, 36 | kProcStateStopped = SSTOP, 37 | kProcStateZombie = SZOMB 38 | }; 39 | 40 | class ProcStat { 41 | public: 42 | static bool GetProcessInfo(ProcessId pid, ProcessInfo &info); 43 | static bool GetProcessMap(pid_t pid, std::vector &map); 44 | static bool GetThreadState(pid_t pid, pid_t tid, int &state, int &cpu); 45 | static bool EnumerateAuxiliaryVector( 46 | pid_t pid, 47 | std::function const &cb); 48 | static void 49 | EnumerateProcesses(bool allUsers, UserId const &uid, 50 | std::function const &cb); 51 | static void EnumerateThreads(pid_t pid, 52 | std::function const &cb); 53 | static std::string GetThreadName(ProcessId pid, ThreadId tid); 54 | static std::string GetExecutablePath(ProcessId pid); 55 | }; 56 | } // namespace FreeBSD 57 | } // namespace Host 58 | } // namespace ds2 59 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Host/Linux/ARM/HwCaps.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | namespace ds2 { 14 | namespace Host { 15 | namespace Linux { 16 | namespace ARM { 17 | 18 | enum /* HwCaps */ { 19 | HWCAP_SWP = (1 << 0), 20 | HWCAP_HALF = (1 << 1), 21 | HWCAP_THUMB = (1 << 2), 22 | HWCAP_26BIT = (1 << 3), 23 | HWCAP_FAST_MULT = (1 << 4), 24 | HWCAP_FPA = (1 << 5), 25 | HWCAP_VFP = (1 << 6), 26 | HWCAP_EDSP = (1 << 7), 27 | HWCAP_JAVA = (1 << 8), 28 | HWCAP_IWMMXT = (1 << 9), 29 | HWCAP_CRUNCH = (1 << 10), 30 | HWCAP_THUMBEE = (1 << 11), 31 | HWCAP_NEON = (1 << 12), 32 | HWCAP_VFPv3 = (1 << 13), 33 | HWCAP_VFPv3D16 = (1 << 14), /* also set for VFPv4-D16 */ 34 | HWCAP_TLS = (1 << 15), 35 | HWCAP_VFPv4 = (1 << 16), 36 | HWCAP_IDIVA = (1 << 17), 37 | HWCAP_IDIVT = (1 << 18), 38 | HWCAP_VFPD32 = (1 << 19), /* set if VFP has 32 regs (not 16) */ 39 | HWCAP_IDIV = (HWCAP_IDIVA | HWCAP_IDIVT), 40 | HWCAP_LPAE = (1 << 20) 41 | }; 42 | } 43 | } // namespace Linux 44 | } // namespace Host 45 | } // namespace ds2 46 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Host/Linux/X86/Syscalls.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | namespace ds2 { 16 | namespace Host { 17 | namespace Linux { 18 | namespace X86 { 19 | namespace Syscalls { 20 | 21 | namespace { 22 | static uint8_t const gMmapCode[] = { 23 | 0xb8, 0x00, 0x00, 0x00, 0x00, // 00: movl $sysno, %eax 24 | 0x31, 0xdb, // 05: xorl %ebx, %ebx 25 | 0xb9, 0x00, 0x00, 0x00, 0x00, // 07: movl $XXXXXXXX, %ecx 26 | 0xba, 0x00, 0x00, 0x00, 0x00, // 0c: movl $XXXXXXXX, %edx 27 | 0xbe, 0x00, 0x00, 0x00, 0x00, // 11: movl $XXXXXXXX, %esi 28 | 0xbf, 0xff, 0xff, 0xff, 0xff, // 16: movl $-1, %edi 29 | 0x31, 0xed, // 1b: xorl %ebp, %ebp 30 | 0xcd, 0x80, // 1d: int $0x80 31 | 0xcc // 1f: int3 32 | }; 33 | 34 | static uint8_t const gMunmapCode[] = { 35 | 0xb8, 0x00, 0x00, 0x00, 0x00, // 00: movl $sysno, %eax 36 | 0xbb, 0x00, 0x00, 0x00, 0x00, // 05: movl $XXXXXXXX, %ebx 37 | 0xb9, 0x00, 0x00, 0x00, 0x00, // 0a: movl $XXXXXXXX, %ecx 38 | 0xcd, 0x80, // 0f: int $0x80 39 | 0xcc // 10: int3 40 | }; 41 | } // namespace 42 | 43 | static inline void PrepareMmapCode(size_t size, int protection, 44 | ByteVector &codestr) { 45 | codestr.assign(&gMmapCode[0], &gMmapCode[sizeof(gMmapCode)]); 46 | 47 | uint8_t *code = &codestr[0]; 48 | *reinterpret_cast(code + 0x01) = 192; // __NR_mmap2 49 | *reinterpret_cast(code + 0x08) = size; 50 | *reinterpret_cast(code + 0x0d) = protection; 51 | *reinterpret_cast(code + 0x12) = MAP_ANON | MAP_PRIVATE; 52 | } 53 | 54 | static inline void PrepareMunmapCode(uint32_t address, size_t size, 55 | ByteVector &codestr) { 56 | codestr.assign(&gMunmapCode[0], &gMunmapCode[sizeof(gMunmapCode)]); 57 | 58 | uint8_t *code = &codestr[0]; 59 | *reinterpret_cast(code + 0x01) = 91; // __NR_munmap 60 | *reinterpret_cast(code + 0x06) = address; 61 | *reinterpret_cast(code + 0x0b) = size; 62 | } 63 | } // namespace Syscalls 64 | } // namespace X86 65 | } // namespace Linux 66 | } // namespace Host 67 | } // namespace ds2 68 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Host/Platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Types.h" 14 | 15 | #include 16 | #if defined(OS_DARWIN) 17 | #include 18 | #endif 19 | #include 20 | 21 | namespace ds2 { 22 | namespace Host { 23 | 24 | class Platform { 25 | public: 26 | static void Initialize(); 27 | 28 | public: 29 | static CPUType GetCPUType(); 30 | static CPUSubType GetCPUSubType(); 31 | static Endian GetEndian(); 32 | static size_t GetPointerSize(); 33 | static size_t GetPageSize(); 34 | 35 | public: 36 | static char const *GetHostName(bool fqdn = false); 37 | 38 | public: 39 | static char const *GetOSTypeName(); 40 | static char const *GetOSVendorName(); 41 | static char const *GetOSVersion(); 42 | static char const *GetOSBuild(); 43 | static char const *GetOSKernelPath(); 44 | 45 | public: 46 | static bool GetUserName(UserId const &uid, std::string &name); 47 | static bool GetGroupName(GroupId const &gid, std::string &name); 48 | 49 | public: 50 | static int OpenFile(std::string const &path, uint32_t flags, uint32_t mode); 51 | static bool CloseFile(int fd); 52 | static bool IsFilePresent(std::string const &path); 53 | static std::string GetWorkingDirectory(); 54 | static bool SetWorkingDirectory(std::string const &directory); 55 | 56 | public: 57 | static ProcessId GetCurrentProcessId(); 58 | static const char *GetSelfExecutablePath(); 59 | static bool GetCurrentEnvironment(EnvironmentBlock &env); 60 | 61 | public: 62 | #if defined(OS_POSIX) 63 | static ErrorCode TranslateError(int error); 64 | #elif defined(OS_WIN32) 65 | static ErrorCode TranslateError(DWORD error); 66 | #endif 67 | static ErrorCode TranslateError(); 68 | #if defined(OS_DARWIN) 69 | static ErrorCode TranslateKernError(kern_return_t kret); 70 | #endif 71 | 72 | public: 73 | static bool GetProcessInfo(ProcessId pid, ProcessInfo &info); 74 | static void 75 | EnumerateProcesses(bool allUsers, UserId const &uid, 76 | std::function const &cb); 77 | 78 | public: 79 | static std::string GetThreadName(ProcessId pid, ThreadId tid); 80 | }; 81 | } // namespace Host 82 | } // namespace ds2 83 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Host/ProcessSpawner.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Base.h" 14 | 15 | #if defined(OS_POSIX) 16 | #include "DebugServer2/Host/POSIX/ProcessSpawner.h" 17 | #elif defined(OS_WIN32) 18 | #include "DebugServer2/Host/Windows/ProcessSpawner.h" 19 | #else 20 | #error "Target not supported." 21 | #endif 22 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Host/QueueChannel.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Core/MessageQueue.h" 14 | #include "DebugServer2/Host/Channel.h" 15 | #include "DebugServer2/Types.h" 16 | 17 | #include 18 | 19 | namespace ds2 { 20 | namespace Host { 21 | 22 | class QueueChannel : public Channel { 23 | public: 24 | Channel *_remote; 25 | MessageQueue _queue; 26 | 27 | public: 28 | QueueChannel(Channel *remote); 29 | ~QueueChannel() override; 30 | 31 | public: 32 | inline Channel *remote() const { 33 | return const_cast(this)->_remote; 34 | } 35 | inline MessageQueue &queue() const { 36 | return const_cast(this)->_queue; 37 | } 38 | 39 | public: 40 | void close() override; 41 | 42 | public: 43 | bool connected() const override; 44 | 45 | public: 46 | bool wait(int ms = -1) override; 47 | 48 | public: 49 | ssize_t send(void const *buffer, size_t length) override; 50 | ssize_t receive(void *buffer, size_t length) override; 51 | 52 | public: 53 | bool receive(std::string &buffer) override; 54 | }; 55 | } // namespace Host 56 | } // namespace ds2 57 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Host/Socket.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Host/Channel.h" 14 | 15 | #include 16 | #if defined(OS_WIN32) 17 | #include 18 | #elif defined(OS_POSIX) 19 | #include 20 | #endif 21 | 22 | namespace ds2 { 23 | namespace Host { 24 | 25 | class Socket : public Channel, public make_unique_enabler { 26 | private: 27 | #if defined(OS_WIN32) 28 | typedef int socklen_t; 29 | #elif defined(OS_POSIX) 30 | typedef int SOCKET; 31 | static SOCKET const INVALID_SOCKET = -1; 32 | #endif 33 | 34 | protected: 35 | enum class State { Invalid, Listening, Connected }; 36 | 37 | protected: 38 | SOCKET _handle; 39 | State _state; 40 | int _lastError; 41 | 42 | public: 43 | Socket(); 44 | Socket(SOCKET handle); 45 | ~Socket() override; 46 | 47 | public: 48 | void close() override; 49 | 50 | public: 51 | inline bool valid() const { return (_handle != INVALID_SOCKET); } 52 | 53 | public: 54 | inline bool listening() const { return (_state == State::Listening); } 55 | inline bool connected() const override { 56 | return (_state == State::Connected); 57 | } 58 | 59 | protected: 60 | bool create(int af); 61 | 62 | public: 63 | bool listen(std::string const &address, std::string const &port); 64 | #if defined(OS_POSIX) 65 | bool listen(std::string const &path, bool abstract = false); 66 | #endif 67 | std::unique_ptr accept(); 68 | bool connect(std::string const &host, std::string const &port); 69 | 70 | protected: 71 | bool getSocketInfo(struct sockaddr_storage *ss) const; 72 | 73 | public: 74 | std::string address() const; 75 | std::string port() const; 76 | 77 | public: 78 | std::string error() const; 79 | 80 | public: 81 | bool wait(int ms = -1) override; 82 | 83 | public: 84 | bool setNonBlocking(); 85 | 86 | public: 87 | ssize_t send(void const *buffer, size_t length) override; 88 | ssize_t receive(void *buffer, size_t length) override; 89 | }; 90 | } // namespace Host 91 | } // namespace ds2 92 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Support/POSIX/ELFSupport.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Types.h" 14 | 15 | namespace ds2 { 16 | namespace Support { 17 | 18 | class ELFSupport { 19 | public: 20 | struct AuxiliaryVectorEntry { 21 | uint64_t type; 22 | uint64_t value; 23 | }; 24 | 25 | public: 26 | static bool MachineTypeToCPUType(uint32_t machineType, bool is64Bit, 27 | CPUType &type, CPUSubType &subType); 28 | }; 29 | } // namespace Support 30 | } // namespace ds2 31 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Target/Darwin/MachOProcess.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Host/Darwin/Mach.h" 14 | #include "DebugServer2/Target/POSIX/Process.h" 15 | 16 | namespace ds2 { 17 | namespace Target { 18 | namespace Darwin { 19 | 20 | class MachOProcess : public POSIX::Process { 21 | protected: 22 | std::string _auxiliaryVector; 23 | Address _sharedLibraryInfoAddress; 24 | Host::Darwin::Mach _mach; 25 | 26 | public: 27 | ErrorCode getAuxiliaryVector(std::string &auxv) override; 28 | uint64_t getAuxiliaryVectorValue(uint64_t type) override; 29 | 30 | public: 31 | virtual ErrorCode getSharedLibraryInfoAddress(Address &address); 32 | ErrorCode enumerateSharedLibraries( 33 | std::function const &cb) override; 34 | 35 | public: 36 | Host::Darwin::Mach &mach(); 37 | 38 | protected: 39 | ErrorCode updateInfo() override; 40 | virtual ErrorCode updateAuxiliaryVector(); 41 | }; 42 | } // namespace Darwin 43 | } // namespace Target 44 | } // namespace ds2 45 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Target/Darwin/Process.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Host/Darwin/PTrace.h" 14 | #include "DebugServer2/Target/Darwin/MachOProcess.h" 15 | 16 | namespace ds2 { 17 | namespace Target { 18 | namespace Darwin { 19 | 20 | class Process : public Darwin::MachOProcess { 21 | protected: 22 | Host::Darwin::PTrace _ptrace; 23 | 24 | protected: 25 | ErrorCode attach(int waitStatus) override; 26 | 27 | public: 28 | ErrorCode terminate() override; 29 | 30 | public: 31 | ErrorCode suspend() override; 32 | 33 | public: 34 | ErrorCode getMemoryRegionInfo(Address const &address, 35 | MemoryRegionInfo &info) override; 36 | 37 | public: 38 | ErrorCode allocateMemory(size_t size, uint32_t protection, 39 | uint64_t *address) override; 40 | ErrorCode deallocateMemory(uint64_t address, size_t size) override; 41 | 42 | public: 43 | ErrorCode readString(Address const &address, std::string &str, size_t length, 44 | size_t *count = nullptr) override; 45 | ErrorCode readMemory(Address const &address, void *data, size_t length, 46 | size_t *count = nullptr) override; 47 | ErrorCode writeMemory(Address const &address, void const *data, size_t length, 48 | size_t *count = nullptr) override; 49 | 50 | public: 51 | ErrorCode wait() override; 52 | 53 | public: 54 | Host::POSIX::PTrace &ptrace() const override; 55 | 56 | protected: 57 | ErrorCode updateInfo() override; 58 | ErrorCode updateAuxiliaryVector() override; 59 | 60 | protected: 61 | friend class Thread; 62 | ErrorCode readCPUState(ThreadId tid, Architecture::CPUState &state, 63 | uint32_t flags = 0); 64 | ErrorCode writeCPUState(ThreadId tid, Architecture::CPUState const &state, 65 | uint32_t flags = 0); 66 | 67 | public: 68 | ErrorCode afterResume() override; 69 | 70 | protected: 71 | friend class POSIX::Process; 72 | }; 73 | } // namespace Darwin 74 | } // namespace Target 75 | } // namespace ds2 76 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Target/Darwin/Thread.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Target/POSIX/Thread.h" 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | namespace ds2 { 23 | namespace Target { 24 | namespace Darwin { 25 | 26 | class Thread : public ds2::Target::POSIX::Thread { 27 | protected: 28 | int _lastSyscallNumber; 29 | 30 | protected: 31 | friend class Process; 32 | Thread(Process *process, ThreadId tid); 33 | 34 | protected: 35 | ErrorCode updateStopInfo(int waitStatus) override; 36 | void updateState() override; 37 | 38 | public: 39 | virtual ErrorCode step(int signal, 40 | Address const &address = Address()) override; 41 | 42 | public: 43 | virtual ErrorCode afterResume(); 44 | 45 | public: 46 | virtual ErrorCode readCPUState(Architecture::CPUState &state) override; 47 | virtual ErrorCode writeCPUState(Architecture::CPUState const &state) override; 48 | 49 | private: 50 | void updateState(bool force); 51 | }; 52 | } // namespace Darwin 53 | } // namespace Target 54 | } // namespace ds2 55 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Target/FreeBSD/Process.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Host/FreeBSD/PTrace.h" 14 | #include "DebugServer2/Target/POSIX/ELFProcess.h" 15 | 16 | namespace ds2 { 17 | namespace Target { 18 | namespace FreeBSD { 19 | 20 | class Process : public POSIX::ELFProcess { 21 | protected: 22 | Host::FreeBSD::PTrace _ptrace; 23 | 24 | protected: 25 | ErrorCode attach(int waitStatus) override; 26 | 27 | public: 28 | ErrorCode terminate() override; 29 | 30 | public: 31 | ErrorCode suspend() override; 32 | 33 | public: 34 | ErrorCode getMemoryRegionInfo(Address const &address, 35 | MemoryRegionInfo &info) override; 36 | 37 | public: 38 | ErrorCode allocateMemory(size_t size, uint32_t protection, 39 | uint64_t *address) override; 40 | ErrorCode deallocateMemory(uint64_t address, size_t size) override; 41 | 42 | public: 43 | ErrorCode wait() override; 44 | 45 | public: 46 | Host::POSIX::PTrace &ptrace() const override; 47 | 48 | protected: 49 | ErrorCode updateInfo() override; 50 | ErrorCode updateAuxiliaryVector() override; 51 | ErrorCode enumerateAuxiliaryVector( 52 | std::function const &cb) override; 54 | 55 | protected: 56 | friend class Thread; 57 | ErrorCode readCPUState(ThreadId tid, Architecture::CPUState &state, 58 | uint32_t flags = 0); 59 | ErrorCode writeCPUState(ThreadId tid, Architecture::CPUState const &state, 60 | uint32_t flags = 0); 61 | 62 | protected: 63 | friend class POSIX::Process; 64 | }; 65 | } // namespace FreeBSD 66 | } // namespace Target 67 | } // namespace ds2 68 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Target/FreeBSD/Thread.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Target/POSIX/Thread.h" 14 | 15 | #include 16 | 17 | namespace ds2 { 18 | namespace Target { 19 | namespace FreeBSD { 20 | 21 | class Thread : public ds2::Target::POSIX::Thread { 22 | protected: 23 | int _lastSyscallNumber; 24 | 25 | protected: 26 | friend class Process; 27 | Thread(Process *process, ThreadId tid); 28 | 29 | protected: 30 | ErrorCode updateStopInfo(int waitStatus) override; 31 | void updateState() override; 32 | 33 | private: 34 | void updateState(bool force); 35 | }; 36 | } // namespace FreeBSD 37 | } // namespace Target 38 | } // namespace ds2 39 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Target/Linux/Process.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Host/Linux/PTrace.h" 14 | #include "DebugServer2/Target/POSIX/ELFProcess.h" 15 | 16 | namespace ds2 { 17 | namespace Target { 18 | namespace Linux { 19 | 20 | class Process : public POSIX::ELFProcess { 21 | protected: 22 | Host::Linux::PTrace _ptrace; 23 | 24 | protected: 25 | ErrorCode attach(int waitStatus) override; 26 | 27 | public: 28 | ErrorCode terminate() override; 29 | bool isAlive() const override; 30 | 31 | public: 32 | ErrorCode getMemoryRegionInfo(Address const &address, 33 | MemoryRegionInfo &info) override; 34 | 35 | protected: 36 | ErrorCode executeCode(ByteVector const &codestr, uint64_t &result); 37 | 38 | public: 39 | ErrorCode readMemory(Address const &address, void *data, size_t length, 40 | size_t *count = nullptr) override; 41 | ErrorCode writeMemory(Address const &address, void const *data, size_t length, 42 | size_t *count = nullptr) override; 43 | 44 | public: 45 | ErrorCode allocateMemory(size_t size, uint32_t protection, 46 | uint64_t *address) override; 47 | ErrorCode deallocateMemory(uint64_t address, size_t size) override; 48 | 49 | protected: 50 | ErrorCode checkMemoryErrorCode(uint64_t address); 51 | 52 | public: 53 | ErrorCode wait() override; 54 | 55 | public: 56 | Host::Linux::PTrace &ptrace() const override; 57 | 58 | protected: 59 | ErrorCode updateInfo() override; 60 | ErrorCode updateAuxiliaryVector() override; 61 | 62 | protected: 63 | friend class Thread; 64 | ErrorCode readCPUState(ThreadId tid, Architecture::CPUState &state, 65 | uint32_t flags = 0); 66 | ErrorCode writeCPUState(ThreadId tid, Architecture::CPUState const &state, 67 | uint32_t flags = 0); 68 | 69 | #if defined(ARCH_ARM) 70 | public: 71 | int getMaxBreakpoints() const override; 72 | int getMaxWatchpoints() const override; 73 | int getMaxWatchpointSize() const override; 74 | #endif 75 | 76 | protected: 77 | friend class POSIX::Process; 78 | }; 79 | } // namespace Linux 80 | } // namespace Target 81 | } // namespace ds2 82 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Target/Linux/Thread.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Target/POSIX/Thread.h" 14 | 15 | #include 16 | 17 | namespace ds2 { 18 | namespace Target { 19 | namespace Linux { 20 | 21 | class Thread : public ds2::Target::POSIX::Thread { 22 | protected: 23 | friend class Process; 24 | Thread(Process *process, ThreadId tid); 25 | 26 | protected: 27 | ErrorCode updateStopInfo(int waitStatus) override; 28 | void updateState() override; 29 | }; 30 | } // namespace Linux 31 | } // namespace Target 32 | } // namespace ds2 33 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Target/POSIX/ELFProcess.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Support/POSIX/ELFSupport.h" 14 | #include "DebugServer2/Target/POSIX/Process.h" 15 | 16 | namespace ds2 { 17 | namespace Target { 18 | namespace POSIX { 19 | 20 | class ELFProcess : public POSIX::Process { 21 | protected: 22 | std::string _auxiliaryVector; 23 | Address _sharedLibraryInfoAddress; 24 | 25 | public: 26 | ErrorCode getAuxiliaryVector(std::string &auxv) override; 27 | uint64_t getAuxiliaryVectorValue(uint64_t type) override; 28 | 29 | public: 30 | virtual ErrorCode getSharedLibraryInfoAddress(Address &address); 31 | ErrorCode enumerateSharedLibraries( 32 | std::function const &cb) override; 33 | 34 | public: 35 | virtual ErrorCode enumerateAuxiliaryVector( 36 | std::function< 37 | void(Support::ELFSupport::AuxiliaryVectorEntry const &)> const &cb); 38 | 39 | protected: 40 | ErrorCode updateInfo() override; 41 | virtual ErrorCode updateAuxiliaryVector(); 42 | }; 43 | } // namespace POSIX 44 | } // namespace Target 45 | } // namespace ds2 46 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Target/POSIX/Process.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Host/POSIX/PTrace.h" 14 | #include "DebugServer2/Host/ProcessSpawner.h" 15 | #include "DebugServer2/Target/ProcessBase.h" 16 | 17 | namespace ds2 { 18 | namespace Target { 19 | namespace POSIX { 20 | 21 | class Process : public ds2::Target::ProcessBase { 22 | protected: 23 | std::set _passthruSignals; 24 | 25 | protected: 26 | ErrorCode initialize(ProcessId pid, uint32_t flags) override; 27 | virtual ErrorCode attach(int waitStatus) = 0; 28 | 29 | public: 30 | ErrorCode detach() override; 31 | ErrorCode interrupt() override; 32 | ErrorCode terminate() override; 33 | bool isAlive() const override; 34 | 35 | public: 36 | ErrorCode readString(Address const &address, std::string &str, size_t length, 37 | size_t *count = nullptr) override; 38 | ErrorCode readMemory(Address const &address, void *data, size_t length, 39 | size_t *count = nullptr) override; 40 | ErrorCode writeMemory(Address const &address, void const *data, size_t length, 41 | size_t *count = nullptr) override; 42 | 43 | protected: 44 | int convertMemoryProtectionToPOSIX(uint32_t protection) const; 45 | uint32_t convertMemoryProtectionFromPOSIX(int POSIXProtection) const; 46 | 47 | public: 48 | void resetSignalPass(); 49 | void setSignalPass(int signo, bool set); 50 | 51 | public: 52 | ErrorCode wait() override; 53 | 54 | public: 55 | virtual Host::POSIX::PTrace &ptrace() const = 0; 56 | 57 | public: 58 | static ds2::Target::Process *Create(Host::ProcessSpawner &spawner); 59 | static ds2::Target::Process *Attach(ProcessId pid); 60 | }; 61 | } // namespace POSIX 62 | } // namespace Target 63 | } // namespace ds2 64 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Target/POSIX/Thread.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Target/ThreadBase.h" 14 | 15 | namespace ds2 { 16 | namespace Target { 17 | namespace POSIX { 18 | 19 | class Thread : public ds2::Target::ThreadBase { 20 | protected: 21 | Thread(ds2::Target::Process *process, ThreadId tid); 22 | 23 | public: 24 | ErrorCode readCPUState(Architecture::CPUState &state) override; 25 | ErrorCode writeCPUState(Architecture::CPUState const &state) override; 26 | 27 | public: 28 | ErrorCode terminate() override; 29 | ErrorCode suspend() override; 30 | 31 | public: 32 | ErrorCode step(int signal = 0, Address const &address = Address()) override; 33 | ErrorCode resume(int signal = 0, Address const &address = Address()) override; 34 | 35 | protected: 36 | virtual ErrorCode updateStopInfo(int waitStatus); 37 | }; 38 | } // namespace POSIX 39 | } // namespace Target 40 | } // namespace ds2 41 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Target/Process.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Base.h" 14 | 15 | #if defined(OS_LINUX) 16 | #include "DebugServer2/Target/Linux/Process.h" 17 | #elif defined(OS_WIN32) 18 | #include "DebugServer2/Target/Windows/Process.h" 19 | #elif defined(OS_FREEBSD) 20 | #include "DebugServer2/Target/FreeBSD/Process.h" 21 | #elif defined(OS_DARWIN) 22 | #include "DebugServer2/Target/Darwin/Process.h" 23 | #else 24 | #error "Target not supported." 25 | #endif 26 | 27 | namespace ds2 { 28 | namespace Target { 29 | 30 | #if defined(OS_LINUX) 31 | using Linux::Process; 32 | #elif defined(OS_WIN32) 33 | using Windows::Process; 34 | #elif defined(OS_FREEBSD) 35 | using FreeBSD::Process; 36 | #elif defined(OS_DARWIN) 37 | using Darwin::Process; 38 | #else 39 | #error "Target not supported." 40 | #endif 41 | } // namespace Target 42 | } // namespace ds2 43 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Target/ProcessDecl.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Types.h" 14 | 15 | #define __FORWARD_DECLARE(TARGET, NAME) \ 16 | namespace TARGET { \ 17 | class NAME; \ 18 | } \ 19 | using TARGET::NAME 20 | 21 | namespace ds2 { 22 | namespace Target { 23 | 24 | class ProcessBase; 25 | 26 | #if defined(OS_LINUX) 27 | __FORWARD_DECLARE(Linux, Process); 28 | __FORWARD_DECLARE(Linux, Thread); 29 | #elif defined(OS_WIN32) 30 | __FORWARD_DECLARE(Windows, Process); 31 | __FORWARD_DECLARE(Windows, Thread); 32 | #elif defined(OS_FREEBSD) 33 | __FORWARD_DECLARE(FreeBSD, Process); 34 | __FORWARD_DECLARE(FreeBSD, Thread); 35 | #elif defined(OS_DARWIN) 36 | __FORWARD_DECLARE(Darwin, Process); 37 | __FORWARD_DECLARE(Darwin, Thread); 38 | #else 39 | #error "Target not supported." 40 | #endif 41 | } // namespace Target 42 | } // namespace ds2 43 | 44 | #undef __FORWARD_DECLARE 45 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Target/Thread.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Base.h" 14 | 15 | #if defined(OS_LINUX) 16 | #include "DebugServer2/Target/Linux/Thread.h" 17 | #elif defined(OS_WIN32) 18 | #include "DebugServer2/Target/Windows/Thread.h" 19 | #elif defined(OS_FREEBSD) 20 | #include "DebugServer2/Target/FreeBSD/Thread.h" 21 | #elif defined(OS_DARWIN) 22 | #include "DebugServer2/Target/Darwin/Thread.h" 23 | #else 24 | #error "Target not supported." 25 | #endif 26 | 27 | namespace ds2 { 28 | namespace Target { 29 | 30 | #if defined(OS_LINUX) 31 | using Linux::Thread; 32 | #elif defined(OS_WIN32) 33 | using Windows::Thread; 34 | #elif defined(OS_FREEBSD) 35 | using FreeBSD::Thread; 36 | #elif defined(OS_DARWIN) 37 | using Darwin::Thread; 38 | #else 39 | #error "Target not supported." 40 | #endif 41 | } // namespace Target 42 | } // namespace ds2 43 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Target/ThreadBase.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Architecture/CPUState.h" 14 | #include "DebugServer2/Target/ProcessDecl.h" 15 | #include "DebugServer2/Utils/Log.h" 16 | 17 | #include 18 | 19 | namespace ds2 { 20 | namespace Target { 21 | 22 | class ThreadBase { 23 | public: 24 | enum State { kInvalid, kRunning, kStepped, kStopped, kTerminated }; 25 | 26 | protected: 27 | Process *_process; 28 | ThreadId _tid; 29 | StopInfo _stopInfo; 30 | State _state; 31 | 32 | protected: 33 | ThreadBase(Process *process, ThreadId tid); 34 | 35 | public: 36 | virtual ~ThreadBase() = default; 37 | 38 | public: 39 | inline Process *process() const { return _process; } 40 | inline ThreadId tid() const { return _tid; } 41 | inline StopInfo const &stopInfo() const { return _stopInfo; } 42 | 43 | public: 44 | virtual ErrorCode terminate() = 0; 45 | 46 | public: 47 | virtual ErrorCode suspend() = 0; 48 | 49 | public: 50 | inline State state() const { return _state; } 51 | 52 | public: 53 | virtual ErrorCode step(int signal = 0, 54 | Address const &address = Address()) = 0; 55 | virtual ErrorCode resume(int signal = 0, 56 | Address const &address = Address()) = 0; 57 | 58 | public: 59 | virtual ErrorCode beforeResume(); 60 | 61 | public: 62 | virtual ErrorCode readCPUState(Architecture::CPUState &state) = 0; 63 | virtual ErrorCode writeCPUState(Architecture::CPUState const &state) = 0; 64 | virtual ErrorCode modifyRegisters( 65 | std::function action) final; 66 | 67 | public: 68 | inline uint32_t core() const { return _stopInfo.core; } 69 | 70 | protected: 71 | friend class ProcessBase; 72 | virtual void updateState() = 0; 73 | }; 74 | } // namespace Target 75 | } // namespace ds2 76 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Target/Windows/Thread.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Target/ThreadBase.h" 14 | 15 | namespace ds2 { 16 | namespace Target { 17 | namespace Windows { 18 | 19 | class Thread : public ds2::Target::ThreadBase { 20 | protected: 21 | HANDLE _handle; 22 | 23 | protected: 24 | friend class Process; 25 | Thread(Process *process, ThreadId tid, HANDLE handle); 26 | 27 | public: 28 | virtual ~Thread(); 29 | 30 | public: 31 | virtual ErrorCode terminate() override; 32 | 33 | public: 34 | virtual ErrorCode suspend() override; 35 | 36 | public: 37 | virtual ErrorCode step(int signal = 0, 38 | Address const &address = Address()) override; 39 | virtual ErrorCode resume(int signal = 0, 40 | Address const &address = Address()) override; 41 | 42 | public: 43 | virtual ErrorCode readCPUState(Architecture::CPUState &state) override; 44 | virtual ErrorCode writeCPUState(Architecture::CPUState const &state) override; 45 | 46 | protected: 47 | virtual void updateState() override; 48 | virtual void updateState(DEBUG_EVENT const &de); 49 | }; 50 | } // namespace Windows 51 | } // namespace Target 52 | } // namespace ds2 53 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Utils/Backtrace.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | namespace ds2 { 14 | namespace Utils { 15 | 16 | void PrintBacktrace(); 17 | } 18 | } // namespace ds2 19 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Utils/CompilerSupport.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Base.h" 14 | 15 | #if defined(COMPILER_GCC) || defined(COMPILER_CLANG) 16 | #if defined(PLATFORM_MINGW) 17 | // MinGW uses printf wrappers to provide standard format string behavior on 18 | // Windows. We need to use __MINGW_PRINTF_FORMAT as GCC assumes MS style printf 19 | // arguments with `__format__(printf, ...)`. 20 | #define DS2_ATTRIBUTE_PRINTF(FORMAT, START) \ 21 | __attribute__((__format__(__MINGW_PRINTF_FORMAT, FORMAT, START))) 22 | #else 23 | #define DS2_ATTRIBUTE_PRINTF(FORMAT, START) \ 24 | __attribute__((__format__(printf, FORMAT, START))) 25 | #endif 26 | #else 27 | #define DS2_ATTRIBUTE_PRINTF(FORMAT, START) 28 | #endif 29 | 30 | #if defined(COMPILER_GCC) 31 | #if __GNUC__ > 6 32 | #define DS2_FALLTHROUGH [[fallthrough]] 33 | #else 34 | #define DS2_FALLTHROUGH 35 | #endif 36 | #elif defined(COMPILER_CLANG) 37 | #define DS2_FALLTHROUGH [[clang::fallthrough]] 38 | #else 39 | #define DS2_FALLTHROUGH 40 | #endif 41 | 42 | #if defined(COMPILER_MSVC) 43 | #define DS2_ATTRIBUTE_PACKED "DS2_ATTRIBUTE_PACKED not implemented on MSVC" 44 | #elif defined(COMPILER_GCC) || defined(COMPILER_CLANG) 45 | #define DS2_ATTRIBUTE_PACKED __attribute__((__packed__)) 46 | #endif 47 | 48 | #if defined(COMPILER_MSVC) 49 | #define DS2_ATTRIBUTE_ALIGNED "DS2_ATTRIBUTE_ALIGNED not implemented on MSVC" 50 | #elif defined(COMPILER_GCC) || defined(COMPILER_CLANG) 51 | #define DS2_ATTRIBUTE_ALIGNED(SIZE) __attribute__((__aligned__(SIZE))) 52 | #endif 53 | 54 | #if defined(COMPILER_MSVC) 55 | #define DS2_UNREACHABLE() __assume(0) 56 | #elif defined(COMPILER_GCC) || defined(COMPILER_CLANG) 57 | #define DS2_UNREACHABLE() __builtin_unreachable() 58 | #else 59 | #include 60 | #define DS2_UNREACHABLE() abort() 61 | #endif 62 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Utils/Daemon.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | namespace ds2 { 14 | namespace Utils { 15 | 16 | void Daemonize(); 17 | } // namespace Utils 18 | } // namespace ds2 19 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Utils/Enums.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | template struct EnableBitMaskOperators { 12 | static const bool enable = false; 13 | }; 14 | 15 | template 16 | typename std::enable_if::enable, 17 | Enum>::type constexpr 18 | operator|(Enum lhs, Enum rhs) { 19 | using Underlying = typename std::underlying_type::type; 20 | return static_cast(static_cast(lhs) | 21 | static_cast(rhs)); 22 | } 23 | 24 | template 25 | typename std::enable_if::enable, 26 | Enum>::type constexpr 27 | operator&(Enum lhs, Enum rhs) { 28 | using Underlying = typename std::underlying_type::type; 29 | return static_cast(static_cast(lhs) & 30 | static_cast(rhs)); 31 | } 32 | 33 | template 34 | typename std::enable_if::enable, 35 | Enum>::type constexpr 36 | operator~(Enum e) { 37 | using Underlying = typename std::underlying_type::type; 38 | return static_cast(~static_cast(e)); 39 | } 40 | 41 | template 42 | typename std::enable_if::enable, 43 | Enum>::type constexpr 44 | operator!(Enum e) { 45 | using Underlying = typename std::underlying_type::type; 46 | return static_cast(!static_cast(e)); 47 | } 48 | 49 | #define ENABLE_BITMASK_OPERATORS(x) \ 50 | template <> struct EnableBitMaskOperators { \ 51 | static const bool enable = true; \ 52 | } 53 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Utils/HexValues.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include "DebugServer2/Utils/CompilerSupport.h" 14 | #include "DebugServer2/Utils/Log.h" 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace ds2 { 22 | 23 | static inline char NibbleToHex(uint8_t byte) { 24 | return "0123456789abcdef"[byte & 0x0f]; 25 | } 26 | 27 | static inline uint8_t HexToNibble(char ch) { 28 | if (ch >= '0' && ch <= '9') 29 | return ch - '0'; 30 | else if (ch >= 'a' && ch <= 'f') 31 | return ch - 'a' + 10; 32 | else if (ch >= 'A' && ch <= 'F') 33 | return ch - 'A' + 10; 34 | DS2_UNREACHABLE(); 35 | } 36 | 37 | static inline uint8_t HexToByte(char const *chars) { 38 | return (HexToNibble(chars[0]) << 4) | HexToNibble(chars[1]); 39 | } 40 | 41 | template static inline std::string ToHex(T const &vec) { 42 | std::string result; 43 | for (char n : vec) { 44 | result += NibbleToHex(n >> 4); 45 | result += NibbleToHex(n & 0x0f); 46 | } 47 | return result; 48 | } 49 | 50 | static inline ByteVector HexToByteVector(std::string const &str) { 51 | ByteVector result; 52 | DS2ASSERT(str.size() % 2 == 0); 53 | for (size_t n = 0; n < str.size(); n += 2) { 54 | result.emplace_back(HexToByte(&str[n])); 55 | } 56 | return result; 57 | } 58 | 59 | static inline std::string HexToString(std::string const &str) { 60 | std::string result; 61 | DS2ASSERT(str.size() % 2 == 0); 62 | for (size_t n = 0; n < str.size(); n += 2) { 63 | result += static_cast(HexToByte(&str[n])); 64 | } 65 | return result; 66 | } 67 | } // namespace ds2 68 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Utils/MPL.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | namespace ds2 { 14 | namespace Utils { 15 | 16 | template class... Mixins> class MixinApply; 17 | 18 | template class MixinApply : public Base { 19 | public: 20 | template 21 | explicit MixinApply(Args &&... args) : Base(std::forward(args)...) {} 22 | }; 23 | 24 | template class MixinHead, 25 | template class... MixinTail> 26 | class MixinApply 27 | : public MixinHead> { 28 | public: 29 | template 30 | explicit MixinApply(Args &&... args) 31 | : MixinHead>(std::forward(args)...) { 32 | } 33 | }; 34 | } // namespace Utils 35 | } // namespace ds2 36 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Utils/OptParse.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace ds2 { 18 | 19 | class OptParse { 20 | public: 21 | enum OptionType { 22 | boolOption, 23 | stringOption, 24 | vectorOption, 25 | }; 26 | 27 | public: 28 | void addOption(OptionType type, std::string const &name, char shortName, 29 | std::string const &help = std::string(), bool hidden = false); 30 | void addPositional(std::string const &name, 31 | std::string const &help = std::string(), 32 | bool hidden = false); 33 | 34 | public: 35 | int parse(int argc, char **argv); 36 | 37 | public: 38 | bool getBool(std::string const &name) const; 39 | std::string const &getString(std::string const &name) const; 40 | std::vector const &getVector(std::string const &name) const; 41 | std::string const &getPositional(std::string const &name) const; 42 | 43 | public: 44 | void usageDie(char const *format = nullptr, ...); 45 | 46 | private: 47 | struct OptionStorage { 48 | char shortName; 49 | OptionType type; 50 | struct { 51 | bool boolValue; 52 | std::string stringValue; 53 | std::vector vectorValue; 54 | } values; 55 | std::string help; 56 | bool hidden; 57 | }; 58 | 59 | struct PositionalStorage { 60 | std::string value; 61 | std::string help; 62 | bool hidden; 63 | }; 64 | 65 | typedef std::map OptionCollection; 66 | typedef std::map PositionalCollection; 67 | 68 | private: 69 | OptionCollection _options; 70 | PositionalCollection _positionals; 71 | std::string _runMode; 72 | 73 | private: 74 | OptionCollection::iterator findShortOpt(char shortOption); 75 | OptionStorage const &get(std::string const &name, OptionType type) const; 76 | }; 77 | } // namespace ds2 78 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Utils/Paths.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | namespace ds2 { 16 | namespace Utils { 17 | 18 | std::string Basename(std::string const &path); 19 | } 20 | } // namespace ds2 21 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Utils/ScopedJanitor.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | // This is a dummy implementation of the ScopeGuard idiom. We don't care about 12 | // exceptions here, we just want to run some cleanup code at scope exit. 13 | 14 | #pragma once 15 | 16 | namespace ds2 { 17 | namespace Utils { 18 | 19 | template class ScopedJanitor { 20 | public: 21 | ScopedJanitor(Callable &&c) : _enabled(true), _c(std::forward(c)) {} 22 | ~ScopedJanitor() { 23 | if (_enabled) { 24 | _c(); 25 | } 26 | } 27 | 28 | ScopedJanitor(ScopedJanitor &&rhs) : _c(std::move(rhs._c)) { rhs.disable(); } 29 | 30 | void disable() { _enabled = false; } 31 | 32 | ScopedJanitor(ScopedJanitor const &rhs) = delete; 33 | ScopedJanitor &operator=(ScopedJanitor const &rhs) = delete; 34 | ScopedJanitor &operator=(ScopedJanitor &&rhs) = delete; 35 | 36 | protected: 37 | bool _enabled; 38 | Callable _c; 39 | }; 40 | 41 | template ScopedJanitor MakeJanitor(Callable &&c) { 42 | return ScopedJanitor(std::forward(c)); 43 | } 44 | } // namespace Utils 45 | } // namespace ds2 46 | -------------------------------------------------------------------------------- /Headers/DebugServer2/Utils/SwapEndian.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #pragma once 12 | 13 | namespace ds2 { 14 | 15 | static constexpr uint16_t Swap16(uint16_t x) { return (x >> 8) | (x << 8); } 16 | 17 | static constexpr uint32_t Swap32(uint32_t x) { 18 | return Swap16(x >> 16) | (Swap16(x & 0xffff) << 16); 19 | } 20 | 21 | static constexpr uint64_t Swap64(uint64_t x) { 22 | return Swap32(x >> 32) | 23 | (static_cast(Swap32(x & 0xffffffff)) << 32); 24 | } 25 | } // namespace ds2 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | University of Illinois/NCSA Open Source License 2 | 3 | For ds2 Software 4 | 5 | Copyright (c) 2014 Facebook, Inc. 6 | All rights reserved. 7 | 8 | Developed by: Facebook, Inc. 9 | https://code.facebook.com 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a 12 | copy of this software and associated documentation files (the "Software"), 13 | to deal with the Software without restriction, including without 14 | limitation the rights to use, copy, modify, merge, publish, distribute, 15 | sublicense, and/or sell copies of the Software, and to permit persons to 16 | whom the Software is furnished to do so, subject to the following 17 | conditions: 18 | 19 | * Redistributions of source code must retain the above copyright notice, 20 | this list of conditions and the following disclaimers. 21 | * Redistributions in binary form must reproduce the above copyright 22 | notice, this list of conditions and the following disclaimers in the 23 | documentation and/or other materials provided with the distribution. 24 | * Neither the names of Facebook, Inc., nor the names of its contributors 25 | may be used to endorse or promote products derived from this Software without 26 | specific prior written permission. 27 | 28 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 29 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 31 | THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 32 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 33 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 34 | OTHER DEALINGS WITH THE SOFTWARE. 35 | -------------------------------------------------------------------------------- /PATENTS: -------------------------------------------------------------------------------- 1 | Additional Grant of Patent Rights Version 2 2 | 3 | "Software" means the ds2 software distributed by Facebook, Inc. 4 | 5 | Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software 6 | ("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable 7 | (subject to the termination provision below) license under any Necessary 8 | Claims, to make, have made, use, sell, offer to sell, import, and otherwise 9 | transfer the Software. For avoidance of doubt, no license is granted under 10 | Facebook’s rights in any patent claims that are infringed by (i) modifications 11 | to the Software made by you or any third party or (ii) the Software in 12 | combination with any software or other technology. 13 | 14 | The license granted hereunder will terminate, automatically and without notice, 15 | if you (or any of your subsidiaries, corporate affiliates or agents) initiate 16 | directly or indirectly, or take a direct financial interest in, any Patent 17 | Assertion: (i) against Facebook or any of its subsidiaries or corporate 18 | affiliates, (ii) against any party if such Patent Assertion arises in whole or 19 | in part from any software, technology, product or service of Facebook or any of 20 | its subsidiaries or corporate affiliates, or (iii) against any party relating 21 | to the Software. Notwithstanding the foregoing, if Facebook or any of its 22 | subsidiaries or corporate affiliates files a lawsuit alleging patent 23 | infringement against you in the first instance, and you respond by filing a 24 | patent infringement counterclaim in that lawsuit against that party that is 25 | unrelated to the Software, the license granted hereunder will not terminate 26 | under section (i) of this paragraph due to such counterclaim. 27 | 28 | A "Necessary Claim" is a claim of a patent owned by Facebook that is 29 | necessarily infringed by the Software standing alone. 30 | 31 | A "Patent Assertion" is any lawsuit or other action alleging direct, indirect, 32 | or contributory infringement or inducement to infringe any patent, including a 33 | cross-claim or counterclaim. 34 | -------------------------------------------------------------------------------- /Sources/Core/ARM/HardwareBreakpointManager.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Core/HardwareBreakpointManager.h" 12 | #include "DebugServer2/Target/Process.h" 13 | 14 | #include 15 | 16 | #define super ds2::BreakpointManager 17 | 18 | namespace ds2 { 19 | 20 | int HardwareBreakpointManager::hit(Target::Thread *thread, Site &site) { 21 | return -1; 22 | }; 23 | 24 | ErrorCode HardwareBreakpointManager::enableLocation(Site const &site, int idx, 25 | Target::Thread *thread) { 26 | return kErrorUnsupported; 27 | }; 28 | 29 | ErrorCode HardwareBreakpointManager::disableLocation(int idx, 30 | Target::Thread *thread) { 31 | return kErrorUnsupported; 32 | }; 33 | 34 | size_t HardwareBreakpointManager::maxWatchpoints() { 35 | return _process->getMaxWatchpoints(); 36 | } 37 | 38 | ErrorCode HardwareBreakpointManager::isValid(Address const &address, 39 | size_t size, Mode mode) const { 40 | DS2LOG(Debug, "Trying to set hardware breakpoint on arm"); 41 | return kErrorUnsupported; 42 | } 43 | 44 | size_t HardwareBreakpointManager::chooseBreakpointSize() const { 45 | DS2BUG( 46 | "Choosing a hardware breakpoint size on ARM is an unsupported operation"); 47 | } 48 | } // namespace ds2 49 | -------------------------------------------------------------------------------- /Sources/Core/ErrorCodes.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Core/ErrorCodes.h" 12 | 13 | namespace ds2 { 14 | 15 | char const *GetErrorCodeString(ErrorCode err) { 16 | switch (err) { 17 | case kSuccess: 18 | return "success"; 19 | case kErrorNoPermission: 20 | return "no permission"; 21 | case kErrorNotFound: 22 | return "file not found"; 23 | case kErrorProcessNotFound: 24 | return "process not found"; 25 | case kErrorInterrupted: 26 | return "interrupted"; 27 | case kErrorInvalidHandle: 28 | return "invalid handle"; 29 | case kErrorNoMemory: 30 | return "no memory"; 31 | case kErrorAccessDenied: 32 | return "access denied"; 33 | case kErrorInvalidAddress: 34 | return "invalid address"; 35 | case kErrorBusy: 36 | return "busy"; 37 | case kErrorAlreadyExist: 38 | return "file already exists"; 39 | case kErrorNoDevice: 40 | return "no device"; 41 | case kErrorNotDirectory: 42 | return "not a directory"; 43 | case kErrorIsDirectory: 44 | return "is a directory"; 45 | case kErrorInvalidArgument: 46 | return "invalid argument"; 47 | case kErrorTooManySystemFiles: 48 | return "too many files open in the system"; 49 | case kErrorTooManyFiles: 50 | return "too many files open in the process"; 51 | case kErrorFileTooBig: 52 | return "file too big"; 53 | case kErrorNoSpace: 54 | return "no space available"; 55 | case kErrorInvalidSeek: 56 | return "invalid seek offset"; 57 | case kErrorNotWriteable: 58 | return "not writeable"; 59 | case kErrorNameTooLong: 60 | return "name too long"; 61 | case kErrorUnsupported: 62 | return "operation not supported"; 63 | default: 64 | break; 65 | } 66 | return "unknown"; 67 | } 68 | } // namespace ds2 69 | -------------------------------------------------------------------------------- /Sources/Core/MessageQueue.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Core/MessageQueue.h" 12 | #include "DebugServer2/Utils/Log.h" 13 | 14 | #include 15 | 16 | // FIXME(strager): This class does not handle spurious 17 | // wakeups! See http://en.wikipedia.org/wiki/Spurious_wakeup 18 | 19 | namespace ds2 { 20 | 21 | MessageQueue::MessageQueue() : _terminated(false) {} 22 | 23 | void MessageQueue::put(std::string const &message) { 24 | std::lock_guard guard(_lock); 25 | _messages.push_back(message); 26 | _ready.notify_one(); 27 | } 28 | 29 | std::string MessageQueue::get(int wait) { 30 | std::string message; 31 | 32 | std::unique_lock lock(_lock); 33 | if (_messages.empty()) { 34 | if (_terminated) 35 | return std::string(); 36 | 37 | if (wait < 0) { 38 | _ready.wait(lock); 39 | } else { 40 | if (_ready.wait_for(lock, std::chrono::milliseconds(wait)) == 41 | std::cv_status::timeout) 42 | return std::string(); 43 | } 44 | } 45 | if (!_messages.empty()) { 46 | message = _messages.front(); 47 | _messages.pop_front(); 48 | } 49 | 50 | return message; 51 | } 52 | 53 | bool MessageQueue::wait(int ms) { 54 | std::unique_lock lock(_lock); 55 | if (!_messages.empty()) 56 | return true; 57 | if (_terminated) 58 | return false; 59 | if (ms < 0) { 60 | _ready.wait(lock); 61 | return !_messages.empty(); 62 | } else { 63 | std::chrono::milliseconds duration(ms); 64 | return _ready.wait_for(lock, duration) != std::cv_status::timeout; 65 | } 66 | } 67 | 68 | void MessageQueue::clear(bool terminating) { 69 | std::lock_guard guard(_lock); 70 | _messages.clear(); 71 | if (terminating) { 72 | DS2ASSERT(!_terminated); 73 | _terminated = true; 74 | _ready.notify_one(); 75 | } 76 | } 77 | } // namespace ds2 78 | -------------------------------------------------------------------------------- /Sources/Core/X86/SoftwareBreakpointManager.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Core/SoftwareBreakpointManager.h" 12 | #include "DebugServer2/Target/Thread.h" 13 | #include "DebugServer2/Utils/Log.h" 14 | 15 | #include 16 | 17 | #define super ds2::BreakpointManager 18 | 19 | namespace ds2 { 20 | 21 | int SoftwareBreakpointManager::hit(Target::Thread *thread, Site &site) { 22 | ds2::Architecture::CPUState state; 23 | 24 | // 25 | // Ignore hardware single-stepping. 26 | // 27 | if (thread->state() == Target::Thread::kStepped) 28 | return 0; 29 | 30 | thread->readCPUState(state); 31 | state.setPC(state.pc() - 1); 32 | 33 | if (super::hit(state.pc(), site)) { 34 | // 35 | // Move the PC back to the instruction, INT3 will move 36 | // the instruction pointer to the next byte. 37 | // 38 | if (thread->writeCPUState(state) != kSuccess) 39 | abort(); 40 | 41 | uint64_t ex = state.pc(); 42 | thread->readCPUState(state); 43 | DS2ASSERT(ex == state.pc()); 44 | 45 | return 0; 46 | } 47 | return -1; 48 | } 49 | 50 | void SoftwareBreakpointManager::getOpcode(uint32_t type, 51 | ByteVector &opcode) const { 52 | DS2ASSERT(type == 1); 53 | opcode.clear(); 54 | opcode.push_back('\xcc'); // int 3 55 | } 56 | 57 | ErrorCode SoftwareBreakpointManager::isValid(Address const &address, 58 | size_t size, Mode mode) const { 59 | DS2ASSERT(mode == kModeExec); 60 | if (size != 0 && size != 1) { 61 | DS2LOG(Debug, "Received unsupported breakpoint size %zu", size); 62 | return kErrorInvalidArgument; 63 | } 64 | 65 | return super::isValid(address, size, mode); 66 | } 67 | 68 | size_t SoftwareBreakpointManager::chooseBreakpointSize() const { 69 | // On x86 and x86_64, software breakpoints will always be of size 1 70 | return 1; 71 | } 72 | } // namespace ds2 73 | -------------------------------------------------------------------------------- /Sources/GDBRemote/SlaveSessionImpl.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/GDBRemote/SlaveSessionImpl.h" 12 | 13 | namespace ds2 { 14 | namespace GDBRemote { 15 | 16 | SlaveSessionImpl::SlaveSessionImpl() = default; 17 | } // namespace GDBRemote 18 | } // namespace ds2 19 | -------------------------------------------------------------------------------- /Sources/Host/Common/Channel.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Host/Channel.h" 12 | 13 | namespace ds2 { 14 | namespace Host { 15 | 16 | bool Channel::send(std::string const &buffer) { 17 | if (!connected()) 18 | return false; 19 | 20 | return send(&buffer[0], buffer.size()) == static_cast(buffer.size()); 21 | } 22 | 23 | bool Channel::receive(std::string &buffer) { 24 | if (!connected()) 25 | return false; 26 | 27 | buffer.clear(); 28 | 29 | size_t total = 0; 30 | static size_t const chunk = 1024; 31 | for (;;) { 32 | size_t size = buffer.size(); 33 | buffer.resize(size + chunk); 34 | ssize_t nrecvd = receive(&buffer[size], chunk); 35 | if (nrecvd == 0) 36 | break; 37 | buffer.resize(size + nrecvd); 38 | 39 | total += nrecvd; 40 | } 41 | buffer.resize(total); 42 | return !buffer.empty(); 43 | } 44 | } // namespace Host 45 | } // namespace ds2 46 | -------------------------------------------------------------------------------- /Sources/Host/Common/Platform.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Host/Platform.h" 12 | #include "DebugServer2/Base.h" 13 | 14 | namespace ds2 { 15 | namespace Host { 16 | 17 | ds2::CPUType Platform::GetCPUType() { 18 | #if defined(ARCH_ARM) || defined(ARCH_ARM64) 19 | return (sizeof(void *) == 8) ? kCPUTypeARM64 : kCPUTypeARM; 20 | #elif defined(ARCH_X86) || defined(ARCH_X86_64) 21 | return (sizeof(void *) == 8) ? kCPUTypeX86_64 : kCPUTypeI386; 22 | #else 23 | #error "Architecture not supported." 24 | #endif 25 | } 26 | 27 | ds2::CPUSubType Platform::GetCPUSubType() { 28 | #if defined(ARCH_ARM) 29 | #if defined(__ARM_ARCH_7EM__) 30 | return kCPUSubTypeARM_V7EM; 31 | #elif defined(__ARM_ARCH_7M__) 32 | return kCPUSubTypeARM_V7M; 33 | #elif defined(OS_WIN32) || defined(__ARM_ARCH_7__) || \ 34 | defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) 35 | return kCPUSubTypeARM_V7; 36 | #endif 37 | #endif // ARCH_ARM 38 | return kCPUSubTypeInvalid; 39 | } 40 | 41 | ds2::Endian Platform::GetEndian() { 42 | #if defined(ENDIAN_LITTLE) 43 | return kEndianLittle; 44 | #elif defined(ENDIAN_BIG) 45 | return kEndianBig; 46 | #elif defined(ENDIAN_MIDDLE) 47 | return kEndianPDP; 48 | #else 49 | return kEndianUnknown; 50 | #endif 51 | } 52 | 53 | size_t Platform::GetPointerSize() { return sizeof(void *); } 54 | } // namespace Host 55 | } // namespace ds2 56 | -------------------------------------------------------------------------------- /Sources/Host/Common/QueueChannel.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Host/QueueChannel.h" 12 | 13 | #include 14 | #include 15 | 16 | namespace ds2 { 17 | namespace Host { 18 | 19 | QueueChannel::QueueChannel(Channel *remote) : _remote(remote) {} 20 | 21 | QueueChannel::~QueueChannel() { close(); } 22 | 23 | void QueueChannel::close() { 24 | if (_remote != nullptr) { 25 | _remote = nullptr; 26 | _queue.clear(true); 27 | } 28 | } 29 | 30 | bool QueueChannel::connected() const { 31 | return _remote != nullptr && _remote->connected(); 32 | } 33 | 34 | bool QueueChannel::wait(int ms) { 35 | _queue.wait(ms); 36 | return true; 37 | } 38 | 39 | ssize_t QueueChannel::send(void const *buffer, size_t length) { 40 | // Forward to the remote 41 | if (!connected()) 42 | return -1; 43 | 44 | return _remote->send(buffer, length); 45 | } 46 | 47 | // 48 | // This method is for compatibility, the code should always call 49 | // receive(std::string&) when using a QueueChannel, which is the 50 | // case for DebugServer2. 51 | // 52 | ssize_t QueueChannel::receive(void *buffer, size_t length) { 53 | std::string strbuf; 54 | if (!receive(strbuf)) 55 | return false; 56 | 57 | length = std::min(length, strbuf.size()); 58 | std::memcpy(buffer, strbuf.data(), length); 59 | return length; 60 | } 61 | 62 | bool QueueChannel::receive(std::string &buffer) { 63 | if (!connected()) 64 | return false; 65 | 66 | buffer = _queue.get(0); 67 | return true; 68 | } 69 | } // namespace Host 70 | } // namespace ds2 71 | -------------------------------------------------------------------------------- /Sources/Host/Darwin/LibProc.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015, Jakub Klama 3 | // Copyright (c) 2015, Corentin Derbois 4 | // All rights reserved. 5 | // 6 | // This source code is licensed under the University of Illinois/NCSA Open 7 | // Source License found in the LICENSE file in the root directory of this 8 | // source tree. An additional grant of patent rights can be found in the 9 | // PATENTS file in the same directory. 10 | // 11 | 12 | #include "DebugServer2/Host/Darwin/LibProc.h" 13 | #include "DebugServer2/Host/Darwin/Mach.h" 14 | #include "DebugServer2/Target/ThreadBase.h" 15 | #include "DebugServer2/Utils/Log.h" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | namespace ds2 { 32 | namespace Host { 33 | namespace Darwin { 34 | 35 | bool LibProc::GetProcessInfo(ProcessId pid, ProcessInfo &info) { 36 | struct proc_taskallinfo ti; 37 | int res = proc_pidinfo(pid, PROC_PIDTASKALLINFO, 0, &ti, sizeof(ti)); 38 | if (res <= 0) 39 | return false; 40 | 41 | info.pid = pid; 42 | info.parentPid = ti.pbsd.pbi_ppid; 43 | info.realUid = ti.pbsd.pbi_ruid; 44 | info.effectiveUid = ti.pbsd.pbi_uid; 45 | info.realGid = ti.pbsd.pbi_rgid; 46 | info.effectiveGid = ti.pbsd.pbi_svgid; 47 | info.name = std::string(ti.pbsd.pbi_comm); 48 | 49 | return true; 50 | } 51 | 52 | void LibProc::EnumerateProcesses( 53 | bool allUsers, UserId const &uid, 54 | std::function const &cb) { 55 | DS2BUG("not implemented"); 56 | } 57 | 58 | std::string LibProc::GetThreadName(ProcessThreadId const &ptid) { 59 | static const std::string defaultName = ""; 60 | thread_identifier_info_data_t threadId; 61 | struct proc_threadinfo ti; 62 | Mach mach; 63 | 64 | ErrorCode error = mach.getThreadIdentifierInfo(ptid, &threadId); 65 | if (error != kSuccess) { 66 | return defaultName; 67 | } 68 | 69 | int res = proc_pidinfo(ptid.pid, PROC_PIDTHREADINFO, threadId.thread_handle, 70 | &ti, sizeof(ti)); 71 | if (res <= 0) { 72 | return defaultName; 73 | } 74 | 75 | return ti.pth_name; 76 | } 77 | 78 | const char *LibProc::GetExecutablePath(ProcessId pid) { return "unknown"; } 79 | } // namespace Darwin 80 | } // namespace Host 81 | } // namespace ds2 82 | -------------------------------------------------------------------------------- /Sources/Host/Darwin/X86_64/PTraceX86_64.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // Copyright (c) 2015, Jakub Klama 4 | // All rights reserved. 5 | // 6 | // This source code is licensed under the University of Illinois/NCSA Open 7 | // Source License found in the LICENSE file in the root directory of this 8 | // source tree. An additional grant of patent rights can be found in the 9 | // PATENTS file in the same directory. 10 | // 11 | 12 | #include "DebugServer2/Host/Darwin/PTrace.h" 13 | #include "DebugServer2/Host/Platform.h" 14 | #include "DebugServer2/Utils/Log.h" 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #define super ds2::Host::POSIX::PTrace 21 | 22 | namespace ds2 { 23 | namespace Host { 24 | namespace Darwin { 25 | 26 | ErrorCode PTrace::readCPUState(ProcessThreadId const &ptid, 27 | ProcessInfo const &pinfo, 28 | Architecture::CPUState &state) { 29 | DS2BUG("impossible to use ptrace to %s on Darwin", __FUNCTION__); 30 | } 31 | 32 | ErrorCode PTrace::writeCPUState(ProcessThreadId const &ptid, 33 | ProcessInfo const &pinfo, 34 | Architecture::CPUState const &state) { 35 | DS2BUG("impossible to use ptrace to %s on Darwin", __FUNCTION__); 36 | } 37 | } // namespace Darwin 38 | } // namespace Host 39 | } // namespace ds2 40 | -------------------------------------------------------------------------------- /Sources/Host/FreeBSD/Platform.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015, Jakub Klama 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Host/Platform.h" 12 | #include "DebugServer2/Host/FreeBSD/ProcStat.h" 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace ds2 { 22 | namespace Host { 23 | 24 | char const *Platform::GetOSTypeName() { return "freebsd"; } 25 | 26 | char const *Platform::GetOSVendorName() { return "unknown"; } 27 | 28 | static struct utsname const *GetCachedUTSName() { 29 | static struct utsname sUName = {"", "", "", "", ""}; 30 | if (sUName.release[0] == '\0') { 31 | ::uname(&sUName); 32 | } 33 | return &sUName; 34 | } 35 | 36 | char const *Platform::GetOSVersion() { return GetCachedUTSName()->release; } 37 | 38 | char const *Platform::GetOSBuild() { return GetCachedUTSName()->version; } 39 | 40 | char const *Platform::GetOSKernelPath() { return nullptr; } 41 | 42 | const char *Platform::GetSelfExecutablePath() { 43 | return Host::FreeBSD::ProcStat::GetExecutablePath(getpid()).c_str(); 44 | } 45 | 46 | bool Platform::GetProcessInfo(ProcessId pid, ProcessInfo &info) { 47 | return Host::FreeBSD::ProcStat::GetProcessInfo(pid, info); 48 | } 49 | 50 | void Platform::EnumerateProcesses( 51 | bool allUsers, UserId const &uid, 52 | std::function const &cb) { 53 | Host::FreeBSD::ProcStat::EnumerateProcesses(allUsers, uid, 54 | [&](pid_t pid, uid_t uid) { 55 | ProcessInfo info; 56 | 57 | if (!GetProcessInfo(pid, info)) 58 | return; 59 | 60 | cb(info); 61 | }); 62 | } 63 | 64 | std::string Platform::GetThreadName(ProcessId pid, ThreadId tid) { 65 | return Host::FreeBSD::ProcStat::GetThreadName(pid, tid); 66 | } 67 | } // namespace Host 68 | } // namespace ds2 69 | -------------------------------------------------------------------------------- /Sources/Host/Windows/File.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Host/File.h" 12 | #include "DebugServer2/Host/Platform.h" 13 | #include "DebugServer2/Host/Windows/ExtraWrappers.h" 14 | 15 | namespace ds2 { 16 | namespace Host { 17 | 18 | File::File(std::string const &path, OpenFlags flags, uint32_t mode) 19 | : _fd(-1), _lastError(kErrorUnsupported) {} 20 | 21 | File::~File() = default; 22 | 23 | ErrorCode File::pread(ByteVector &buf, uint64_t &count, uint64_t offset) { 24 | return kErrorUnsupported; 25 | } 26 | 27 | ErrorCode File::pwrite(ByteVector const &buf, uint64_t &count, 28 | uint64_t offset) { 29 | return kErrorUnsupported; 30 | } 31 | 32 | ErrorCode File::chmod(std::string const &path, uint32_t mode) { 33 | return kErrorUnsupported; 34 | } 35 | 36 | ErrorCode File::unlink(std::string const &path) { return kErrorUnsupported; } 37 | 38 | ErrorCode File::createDirectory(std::string const &path, uint32_t flags) { 39 | return kErrorUnsupported; 40 | } 41 | } // namespace Host 42 | } // namespace ds2 43 | -------------------------------------------------------------------------------- /Sources/Support/POSIX/ELFSupport.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Support/POSIX/ELFSupport.h" 12 | 13 | #include 14 | 15 | namespace ds2 { 16 | namespace Support { 17 | 18 | bool ELFSupport::MachineTypeToCPUType(uint32_t machineType, bool is64Bit, 19 | CPUType &type, CPUSubType &subType) { 20 | switch (machineType) { 21 | #if defined(ARCH_X86) || defined(ARCH_X86_64) 22 | case EM_386: 23 | type = kCPUTypeX86; 24 | subType = kCPUSubTypeX86_ALL; 25 | break; 26 | 27 | #if defined(ARCH_X86_64) 28 | case EM_X86_64: 29 | type = kCPUTypeX86_64; 30 | subType = kCPUSubTypeX86_64_ALL; 31 | break; 32 | #endif 33 | 34 | #elif defined(ARCH_ARM) || defined(ARCH_ARM64) 35 | case EM_ARM: 36 | type = kCPUTypeARM; 37 | subType = kCPUSubTypeARM_ALL; 38 | break; 39 | 40 | #if defined(ARCH_ARM64) 41 | case EM_AARCH64: 42 | type = kCPUTypeARM64; 43 | subType = kCPUSubTypeARM64_ALL; 44 | break; 45 | #endif 46 | 47 | #else 48 | #error "Architecture not supported." 49 | #endif 50 | 51 | default: 52 | type = kCPUTypeAny; 53 | subType = kCPUSubTypeInvalid; 54 | return false; 55 | } 56 | return true; 57 | } 58 | } // namespace Support 59 | } // namespace ds2 60 | -------------------------------------------------------------------------------- /Sources/Target/Common/ARM/ProcessBaseARM.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Target/ProcessBase.h" 12 | 13 | using ds2::Architecture::GDBDescriptor; 14 | using ds2::Architecture::LLDBDescriptor; 15 | 16 | namespace ds2 { 17 | namespace Target { 18 | 19 | GDBDescriptor const *ProcessBase::getGDBRegistersDescriptor() const { 20 | return &Architecture::ARM::GDB; 21 | } 22 | 23 | LLDBDescriptor const *ProcessBase::getLLDBRegistersDescriptor() const { 24 | return &Architecture::ARM::LLDB; 25 | } 26 | } // namespace Target 27 | } // namespace ds2 28 | -------------------------------------------------------------------------------- /Sources/Target/Common/ARM64/ProcessBaseARM64.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Target/ProcessBase.h" 12 | 13 | using ds2::Architecture::GDBDescriptor; 14 | using ds2::Architecture::LLDBDescriptor; 15 | 16 | namespace ds2 { 17 | namespace Target { 18 | 19 | GDBDescriptor const *ProcessBase::getGDBRegistersDescriptor() const { 20 | return &Architecture::ARM64::GDB; 21 | } 22 | 23 | LLDBDescriptor const *ProcessBase::getLLDBRegistersDescriptor() const { 24 | return &Architecture::ARM64::LLDB; 25 | } 26 | } // namespace Target 27 | } // namespace ds2 28 | -------------------------------------------------------------------------------- /Sources/Target/Common/ThreadBase.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Target/ThreadBase.h" 12 | #include "DebugServer2/Target/Process.h" 13 | 14 | namespace ds2 { 15 | namespace Target { 16 | 17 | ThreadBase::ThreadBase(Process *process, ThreadId tid) 18 | : _process(process), _tid(tid), _state(kStopped) { 19 | // When threads are created, they're stopped at the entry point waiting for 20 | // the debugger to continue them. 21 | _stopInfo.event = StopInfo::kEventStop; 22 | _stopInfo.reason = StopInfo::kReasonThreadEntry; 23 | _process->insert(this); 24 | } 25 | 26 | ErrorCode ThreadBase::modifyRegisters( 27 | std::function action) { 28 | Architecture::CPUState state; 29 | CHK(readCPUState(state)); 30 | action(state); 31 | return writeCPUState(state); 32 | } 33 | 34 | ErrorCode ThreadBase::beforeResume() { 35 | BreakpointManager *bpm = _process->hardwareBreakpointManager(); 36 | if (bpm != nullptr) { 37 | bpm->enable((Target::Thread *)this); 38 | } 39 | 40 | return kSuccess; 41 | } 42 | } // namespace Target 43 | } // namespace ds2 44 | -------------------------------------------------------------------------------- /Sources/Target/Common/X86/ProcessBaseX86.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Target/ProcessBase.h" 12 | 13 | using ds2::Architecture::GDBDescriptor; 14 | using ds2::Architecture::LLDBDescriptor; 15 | 16 | namespace ds2 { 17 | namespace Target { 18 | 19 | GDBDescriptor const *ProcessBase::getGDBRegistersDescriptor() const { 20 | return &Architecture::X86::GDB; 21 | } 22 | 23 | LLDBDescriptor const *ProcessBase::getLLDBRegistersDescriptor() const { 24 | return &Architecture::X86::LLDB; 25 | } 26 | } // namespace Target 27 | } // namespace ds2 28 | -------------------------------------------------------------------------------- /Sources/Target/Common/X86_64/ProcessBaseX86_64.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Target/ProcessBase.h" 12 | 13 | using ds2::Architecture::GDBDescriptor; 14 | using ds2::Architecture::LLDBDescriptor; 15 | 16 | namespace ds2 { 17 | namespace Target { 18 | 19 | GDBDescriptor const *ProcessBase::getGDBRegistersDescriptor() const { 20 | if (_info.pointerSize == sizeof(uint32_t)) 21 | return &Architecture::X86::GDB; 22 | else 23 | return &Architecture::X86_64::GDB; 24 | } 25 | 26 | LLDBDescriptor const *ProcessBase::getLLDBRegistersDescriptor() const { 27 | if (_info.pointerSize == sizeof(uint32_t)) 28 | return &Architecture::X86::LLDB; 29 | else 30 | return &Architecture::X86_64::LLDB; 31 | } 32 | } // namespace Target 33 | } // namespace ds2 34 | -------------------------------------------------------------------------------- /Sources/Target/Darwin/X86_64/ThreadX86_64.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015, Facebook, Inc. 3 | // Copyright (c) 2015, Corentin Derbois 4 | // All rights reserved. 5 | // 6 | // This source code is licensed under the University of Illinois/NCSA Open 7 | // Source License found in the LICENSE file in the root directory of this 8 | // source tree. An additional grant of patent rights can be found in the 9 | // PATENTS file in the same directory. 10 | // 11 | 12 | #include "DebugServer2/Target/Darwin/Thread.h" 13 | #include "DebugServer2/Architecture/CPUState.h" 14 | 15 | namespace ds2 { 16 | namespace Target { 17 | namespace Darwin { 18 | 19 | ErrorCode Thread::step(int signal, Address const &address) { 20 | // Darwin doesn't have a dedicated single-step call. We have to set the 21 | // single step flag (TF, 8th bit) in eflags and resume the thread. 22 | ErrorCode error = modifyRegisters([](Architecture::CPUState &state) { 23 | state.state64.gp.eflags |= (1 << 8); 24 | }); 25 | if (error != kSuccess) { 26 | return error; 27 | } 28 | return resume(signal, address); 29 | } 30 | 31 | ErrorCode Thread::afterResume() { 32 | return modifyRegisters([](Architecture::CPUState &state) { 33 | state.state64.gp.eflags &= ~(1 << 8); 34 | }); 35 | } 36 | } // namespace Darwin 37 | } // namespace Target 38 | } // namespace ds2 39 | -------------------------------------------------------------------------------- /Sources/Target/Linux/ARM64/ProcessARM64.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Target/Process.h" 12 | #include "DebugServer2/Host/Linux/ARM64/Syscalls.h" 13 | #include "DebugServer2/Target/Thread.h" 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | namespace ARM64Sys = ds2::Host::Linux::ARM64::Syscalls; 20 | 21 | namespace ds2 { 22 | namespace Target { 23 | namespace Linux { 24 | 25 | static bool is32BitProcess(Process *process) { 26 | DS2ASSERT(process != nullptr); 27 | DS2ASSERT(process->currentThread() != nullptr); 28 | 29 | Architecture::CPUState state; 30 | CHK(process->currentThread()->readCPUState(state)); 31 | 32 | return state.isA32; 33 | } 34 | 35 | ErrorCode Process::allocateMemory(size_t size, uint32_t protection, 36 | uint64_t *address) { 37 | if (address == nullptr || size == 0) { 38 | return kErrorInvalidArgument; 39 | } 40 | 41 | // We don't support ARM on ARM64 yet. 42 | DS2ASSERT(!is32BitProcess(this)); 43 | 44 | ByteVector codestr; 45 | ARM64Sys::PrepareMmapCode(size, convertMemoryProtectionToPOSIX(protection), 46 | codestr); 47 | 48 | uint64_t result; 49 | CHK(executeCode(codestr, result)); 50 | CHK(checkMemoryErrorCode(result)); 51 | 52 | *address = result; 53 | return kSuccess; 54 | } 55 | 56 | ErrorCode Process::deallocateMemory(uint64_t address, size_t size) { 57 | return kErrorUnsupported; 58 | } 59 | } // namespace Linux 60 | } // namespace Target 61 | } // namespace ds2 62 | -------------------------------------------------------------------------------- /Sources/Target/Linux/X86/ProcessX86.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Target/Process.h" 12 | #include "DebugServer2/Host/Linux/X86/Syscalls.h" 13 | #include "DebugServer2/Target/Thread.h" 14 | 15 | namespace X86Sys = ds2::Host::Linux::X86::Syscalls; 16 | 17 | namespace ds2 { 18 | namespace Target { 19 | namespace Linux { 20 | 21 | ErrorCode Process::allocateMemory(size_t size, uint32_t protection, 22 | uint64_t *address) { 23 | if (address == nullptr) { 24 | return kErrorInvalidArgument; 25 | } 26 | 27 | ByteVector codestr; 28 | X86Sys::PrepareMmapCode(size, convertMemoryProtectionToPOSIX(protection), 29 | codestr); 30 | 31 | uint64_t result; 32 | CHK(executeCode(codestr, result)); 33 | 34 | // MAP_FAILED is -1. 35 | if (static_cast(result) == -1) { 36 | return kErrorNoMemory; 37 | } 38 | 39 | *address = result; 40 | return kSuccess; 41 | } 42 | 43 | ErrorCode Process::deallocateMemory(uint64_t address, size_t size) { 44 | if (size == 0) { 45 | return kErrorInvalidArgument; 46 | } 47 | 48 | ByteVector codestr; 49 | X86Sys::PrepareMunmapCode(address, size, codestr); 50 | 51 | uint64_t result; 52 | CHK(executeCode(codestr, result)); 53 | 54 | // Negative values returned by the kernel indicate failure. 55 | if (static_cast(result) < 0) { 56 | return kErrorUnknown; 57 | } 58 | 59 | return kSuccess; 60 | } 61 | } // namespace Linux 62 | } // namespace Target 63 | } // namespace ds2 64 | -------------------------------------------------------------------------------- /Sources/Utils/Backtrace.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Utils/Backtrace.h" 12 | #include "DebugServer2/Utils/Log.h" 13 | 14 | #if defined(OS_DARWIN) || defined(__GLIBC__) 15 | #include 16 | #include 17 | #include 18 | #elif defined(OS_WIN32) 19 | #include 20 | #endif 21 | 22 | namespace ds2 { 23 | namespace Utils { 24 | 25 | #if defined(OS_DARWIN) || defined(OS_WIN32) || \ 26 | (defined(__GLIBC__) && !defined(PLATFORM_TIZEN)) 27 | static void PrintBacktraceEntrySimple(void *address) { 28 | DS2LOG(Error, "%" PRI_PTR, PRI_PTR_CAST(address)); 29 | } 30 | #endif 31 | 32 | #if defined(OS_DARWIN) || (defined(__GLIBC__) && !defined(PLATFORM_TIZEN)) 33 | void PrintBacktrace() { 34 | static const int kStackSize = 100; 35 | static void *stack[kStackSize]; 36 | int stackEntries = ::backtrace(stack, kStackSize); 37 | 38 | for (int i = 0; i < stackEntries; ++i) { 39 | Dl_info info; 40 | int res; 41 | 42 | res = ::dladdr(stack[i], &info); 43 | if (res < 0) { 44 | PrintBacktraceEntrySimple(stack[i]); 45 | continue; 46 | } 47 | 48 | char *demangled = nullptr; 49 | const char *name; 50 | if (info.dli_sname != nullptr) { 51 | demangled = abi::__cxa_demangle(info.dli_sname, nullptr, nullptr, &res); 52 | if (res == 0) { 53 | name = demangled; 54 | } else { 55 | name = info.dli_sname; 56 | } 57 | } else { 58 | name = ""; 59 | } 60 | 61 | DS2LOG(Error, "%" PRI_PTR " %s+%#" PRIxPTR " (%s)", PRI_PTR_CAST(stack[i]), 62 | name, 63 | static_cast(stack[i]) - static_cast(info.dli_saddr), 64 | info.dli_fname); 65 | 66 | ::free(demangled); 67 | } 68 | } 69 | #elif defined(OS_WIN32) 70 | void PrintBacktrace() { 71 | static const int kStackSize = 62; 72 | static PVOID stack[kStackSize]; 73 | int stackEntries = CaptureStackBackTrace(0, kStackSize, stack, nullptr); 74 | 75 | for (int i = 0; i < stackEntries; ++i) { 76 | PrintBacktraceEntrySimple(stack[i]); 77 | } 78 | } 79 | #else 80 | void PrintBacktrace() { DS2LOG(Warning, "unable to print backtrace"); } 81 | #endif 82 | } // namespace Utils 83 | } // namespace ds2 84 | -------------------------------------------------------------------------------- /Sources/Utils/POSIX/Daemon.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Utils/Daemon.h" 12 | #include "DebugServer2/Utils/Log.h" 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace ds2 { 21 | namespace Utils { 22 | 23 | void Daemonize() { 24 | pid_t pid; 25 | 26 | pid = ::fork(); 27 | if (pid < 0) { 28 | DS2LOG(Fatal, "cannot fork: %s", ::strerror(errno)); 29 | } else if (pid > 0) { 30 | ::exit(EXIT_SUCCESS); 31 | } 32 | 33 | pid_t sid = ::setsid(); 34 | if (sid < 0) { 35 | DS2LOG(Fatal, "cannot setsid: %s", ::strerror(errno)); 36 | } 37 | 38 | pid = ::fork(); 39 | if (pid < 0) { 40 | DS2LOG(Fatal, "cannot fork: %s", ::strerror(errno)); 41 | } else if (pid > 0) { 42 | ::exit(EXIT_SUCCESS); 43 | } 44 | 45 | close(STDIN_FILENO); 46 | close(STDOUT_FILENO); 47 | close(STDERR_FILENO); 48 | 49 | open("/dev/null", O_RDONLY); 50 | open("/dev/null", O_WRONLY); 51 | open("/dev/null", O_WRONLY); 52 | } 53 | } // namespace Utils 54 | } // namespace ds2 55 | -------------------------------------------------------------------------------- /Sources/Utils/POSIX/FaultHandler.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Utils/Backtrace.h" 12 | #include "DebugServer2/Utils/Log.h" 13 | #include "DebugServer2/Utils/Stringify.h" 14 | 15 | #include 16 | #include 17 | 18 | namespace { 19 | 20 | using ds2::Utils::Stringify; 21 | 22 | class FaultHandler { 23 | private: 24 | static void signalHandler(int sig, siginfo_t *si, void *uc) { 25 | DS2LOG(Error, "received %s with code %s at address %" PRI_PTR ", crashing", 26 | Stringify::Signal(si->si_signo), 27 | Stringify::SignalCode(si->si_signo, si->si_code), 28 | PRI_PTR_CAST(si->si_addr)); 29 | ds2::Utils::PrintBacktrace(); 30 | _exit(si->si_signo); 31 | } 32 | 33 | void installCatcher() { 34 | static char alt[SIGSTKSZ]; 35 | struct sigaction sa; 36 | stack_t ss; 37 | 38 | // Allocate our own signal stack so that fault handlers work even 39 | // when the stack pointer is busted. 40 | ss.ss_sp = alt; 41 | ss.ss_size = sizeof(alt); 42 | ss.ss_flags = 0; 43 | 44 | sa.sa_sigaction = FaultHandler::signalHandler; 45 | sigfillset(&sa.sa_mask); 46 | sa.sa_flags = SA_SIGINFO | SA_ONSTACK; 47 | 48 | sigaltstack(&ss, nullptr); 49 | sigaction(SIGILL, &sa, nullptr); 50 | sigaction(SIGBUS, &sa, nullptr); 51 | sigaction(SIGSEGV, &sa, nullptr); 52 | } 53 | 54 | public: 55 | FaultHandler() { installCatcher(); } 56 | }; 57 | 58 | FaultHandler instance; 59 | } // namespace 60 | -------------------------------------------------------------------------------- /Sources/Utils/Paths.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Utils/Paths.h" 12 | 13 | namespace ds2 { 14 | namespace Utils { 15 | 16 | std::string Basename(std::string const &path) { 17 | #if defined(OS_WIN32) 18 | char sep = '\\'; 19 | #else 20 | char sep = '/'; 21 | #endif 22 | 23 | auto end = path.find_last_not_of(sep); 24 | if (end == std::string::npos) 25 | return std::string(&sep, 1); 26 | 27 | auto begin = path.rfind(sep, end); 28 | if (begin == std::string::npos) { 29 | return path.substr(0, end + 1); 30 | } else { 31 | return path.substr(begin + 1, end - begin); 32 | } 33 | } 34 | } // namespace Utils 35 | } // namespace ds2 36 | -------------------------------------------------------------------------------- /Sources/Utils/Windows/Daemon.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Utils/Daemon.h" 12 | #include "DebugServer2/Utils/Log.h" 13 | 14 | namespace ds2 { 15 | namespace Utils { 16 | 17 | void Daemonize() { DS2BUG("not implemented"); } 18 | } // namespace Utils 19 | } // namespace ds2 20 | -------------------------------------------------------------------------------- /Sources/Utils/Windows/FaultHandler.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #include "DebugServer2/Host/Windows/ExtraWrappers.h" 12 | #include "DebugServer2/Utils/Backtrace.h" 13 | #include "DebugServer2/Utils/Log.h" 14 | #include "DebugServer2/Utils/Stringify.h" 15 | 16 | namespace { 17 | 18 | using ds2::Utils::Stringify; 19 | 20 | class FaultHandler { 21 | private: 22 | static LONG WINAPI exceptionHandler(EXCEPTION_POINTERS *exceptionInfo) { 23 | DS2LOG( 24 | Error, "received exception %s at address %" PRI_PTR ", crashing", 25 | Stringify::ExceptionCode(exceptionInfo->ExceptionRecord->ExceptionCode), 26 | PRI_PTR_CAST(exceptionInfo->ExceptionRecord->ExceptionAddress)); 27 | ds2::Utils::PrintBacktrace(); 28 | _exit(1); 29 | } 30 | 31 | void installCatcher() { SetUnhandledExceptionFilter(exceptionHandler); } 32 | 33 | public: 34 | FaultHandler() { installCatcher(); } 35 | }; 36 | 37 | FaultHandler instance; 38 | } // namespace 39 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-Android-ARM.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME Android) 12 | set(CMAKE_ANDROID_ARCH_ABI armeabi) 13 | set(CMAKE_ANDROID_NDK /tmp/android-ndk) 14 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-Android-ARM64.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME Android) 12 | set(CMAKE_ANDROID_ARCH_ABI arm64-v8a) 13 | set(CMAKE_ANDROID_NDK /tmp/android-ndk) 14 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-Android-X86.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME Android) 12 | set(CMAKE_ANDROID_ARCH_ABI x86) 13 | set(CMAKE_ANDROID_NDK /tmp/android-ndk) 14 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-Android-X86_64.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME Android) 12 | set(CMAKE_ANDROID_ARCH_ABI x86_64) 13 | set(CMAKE_ANDROID_NDK /tmp/android-ndk) 14 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-Darwin-X86_64.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME Darwin) 12 | set(CMAKE_SYSTEM_PROCESSOR X86_64) 13 | 14 | set(CMAKE_C_COMPILER clang) 15 | set(CMAKE_CXX_COMPILER clang++) 16 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-Linux-ARM.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME Linux) 12 | set(CMAKE_SYSTEM_PROCESSOR ARM) 13 | 14 | set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc-4.8) 15 | set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++-4.8) 16 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-Linux-X86-Clang.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME Linux) 12 | set(CMAKE_SYSTEM_PROCESSOR X86) 13 | 14 | set(CMAKE_C_COMPILER clang) 15 | set(CMAKE_CXX_COMPILER clang++) 16 | set(CMAKE_C_COMPILER_ARG1 -m32) 17 | set(CMAKE_CXX_COMPILER_ARG1 -m32) 18 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-Linux-X86.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME Linux) 12 | set(CMAKE_SYSTEM_PROCESSOR X86) 13 | 14 | set(CMAKE_C_COMPILER gcc) 15 | set(CMAKE_CXX_COMPILER g++) 16 | set(CMAKE_C_COMPILER_ARG1 -m32) 17 | set(CMAKE_CXX_COMPILER_ARG1 -m32) 18 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-Linux-X86_64-Clang.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME Linux) 12 | set(CMAKE_SYSTEM_PROCESSOR X86_64) 13 | 14 | set(CMAKE_C_COMPILER clang) 15 | set(CMAKE_CXX_COMPILER clang++) 16 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-Linux-X86_64.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME Linux) 12 | set(CMAKE_SYSTEM_PROCESSOR X86_64) 13 | 14 | set(CMAKE_C_COMPILER gcc) 15 | set(CMAKE_CXX_COMPILER g++) 16 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-MinGW-X86.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME Windows) 12 | set(CMAKE_SYSTEM_PROCESSOR X86) 13 | 14 | set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) 15 | set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) 16 | set(CMAKE_RC_COMPILER i686-w64-mingw32-gcc) 17 | set(CMAKE_C_COMPILER_ARG1 -m32) 18 | set(CMAKE_CXX_COMPILER_ARG1 -m32) 19 | 20 | set(STATIC 1) 21 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-MinGW-X86_64.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME Windows) 12 | set(CMAKE_SYSTEM_PROCESSOR X86_64) 13 | 14 | set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) 15 | set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) 16 | set(CMAKE_RC_COMPILER x86_64-w64-mingw32-gcc) 17 | 18 | set(STATIC 1) 19 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-Tizen-ARM.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME Linux) 12 | set(CMAKE_SYSTEM_PROCESSOR ARM) 13 | 14 | set(CMAKE_C_COMPILER arm-linux-gnueabi-gcc) 15 | set(CMAKE_CXX_COMPILER arm-linux-gnueabi-g++) 16 | 17 | set(TIZEN 1) 18 | set(STATIC 1) 19 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-Tizen-X86.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME Linux) 12 | set(CMAKE_SYSTEM_PROCESSOR X86) 13 | 14 | set(CMAKE_C_COMPILER gcc) 15 | set(CMAKE_CXX_COMPILER g++) 16 | set(CMAKE_C_COMPILER_ARG1 -m32) 17 | set(CMAKE_CXX_COMPILER_ARG1 -m32) 18 | 19 | set(TIZEN 1) 20 | set(STATIC 1) 21 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-WinStore-ARM.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME WindowsStore) 12 | set(CMAKE_SYSTEM_VERSION 10.0) 13 | set(CMAKE_GENERATOR_PLATFORM ARM) 14 | 15 | # For WinStore we build as a library because creating a process seems 16 | # restricted, so we just have a separate process open `ds2.dll` and run `main` 17 | # from it. 18 | set(LIBRARY 1) 19 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-WinStore-x86.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME WindowsStore) 12 | set(CMAKE_SYSTEM_VERSION 10.0) 13 | 14 | # For WinStore we build as a library because creating a process seems 15 | # restricted, so we just have a separate process open `ds2.dll` and run `main` 16 | # from it. 17 | set(LIBRARY 1) 18 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-WinStore-x86_64.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | set(CMAKE_SYSTEM_NAME WindowsStore) 12 | set(CMAKE_SYSTEM_VERSION 10.0) 13 | set(CMAKE_GENERATOR_PLATFORM x64) 14 | 15 | # For WinStore we build as a library because creating a process seems 16 | # restricted, so we just have a separate process open `ds2.dll` and run `main` 17 | # from it. 18 | set(LIBRARY 1) 19 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-Windows-x86.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | 10 | set(CMAKE_SYSTEM_NAME Windows) 11 | set(CMAKE_SYSTEM_VERSION 10.0) 12 | -------------------------------------------------------------------------------- /Support/CMake/Toolchain-Windows-x86_64.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | 10 | set(CMAKE_SYSTEM_NAME Windows) 11 | set(CMAKE_SYSTEM_VERSION 10.0) 12 | set(CMAKE_GENERATOR_PLATFORM x64) 13 | -------------------------------------------------------------------------------- /Support/Scripts/build-windows.bat: -------------------------------------------------------------------------------- 1 | :: 2 | :: Copyright (c) 2014-present, Facebook, Inc. 3 | :: All rights reserved. 4 | :: 5 | :: This source code is licensed under the University of Illinois/NCSA Open 6 | :: Source License found in the LICENSE file in the root directory of this 7 | :: source tree. An additional grant of patent rights can be found in the 8 | :: PATENTS file in the same directory. 9 | :: 10 | 11 | :: After creating a build directory and running cmake, just run this script to 12 | :: build the project with msbuild. If running from powershell, use 13 | :: ..\Support\Scripts\build-windows.bat 14 | 15 | @echo off 16 | 17 | set vs2017devcmd=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\vsdevcmd.bat 18 | if exist "%vs2017devcmd%" ( 19 | call "%vs2017devcmd%" -no_logo 20 | ) else ( 21 | call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\tools\vsvars32.bat" 22 | ) 23 | msbuild /nologo /verbosity:minimal /p:Configuration=Release ds2.vcxproj 24 | -------------------------------------------------------------------------------- /Support/Scripts/common.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## Copyright (c) 2014-present, Facebook, Inc. 4 | ## All rights reserved. 5 | ## 6 | ## This source code is licensed under the University of Illinois/NCSA Open 7 | ## Source License found in the LICENSE file in the root directory of this 8 | ## source tree. An additional grant of patent rights can be found in the 9 | ## PATENTS file in the same directory. 10 | ## 11 | 12 | set -eu 13 | 14 | die() { 15 | echo "error:" "$@" >&2 16 | exit 1 17 | } 18 | 19 | git_clone() { 20 | src="$1" 21 | dst="$2" 22 | branch="${3-}" 23 | 24 | if [ ! -e "$dst" ]; then 25 | clone_command=(git clone --depth 1) 26 | if [ -n "$branch" ]; then 27 | clone_command+=(--branch "$branch") 28 | fi 29 | "${clone_command[@]}" "$src" "$dst" 30 | elif [ -d "$dst/.git" ]; then 31 | cd "$dst" 32 | git reset --hard 33 | if [ -n "$branch" ]; then 34 | git checkout "$branch" 35 | fi 36 | git pull 37 | cd "$OLDPWD" 38 | else 39 | die "'$dst' exists and is not a git repository." 40 | fi 41 | } 42 | 43 | num_cpus() { 44 | case "$(uname)" in 45 | Darwin) num_cpus=$(sysctl -n hw.ncpu);; 46 | Linux) num_cpus=$(grep -c "^processor" /proc/cpuinfo);; 47 | *) die "Unknown OS '$(uname)'.";; 48 | esac 49 | echo $(($num_cpus * 5 / 4)) 50 | } 51 | 52 | realpath() { python -c "import os,sys; print os.path.realpath(sys.argv[1])" "$1"; } 53 | 54 | same_dir() { 55 | [ "$(realpath "$1")" = "$(realpath "$2")" ] 56 | } 57 | 58 | exit_handlers="exit" 59 | exit_handler() { set +e; eval "$exit_handlers"; } 60 | trap exit_handler EXIT 61 | add_exit_handler() { exit_handlers="$*; $exit_handlers"; } 62 | 63 | linux_distribution() { 64 | if [ -r /etc/issue ] && grep -q "Ubuntu" "/etc/issue"; then 65 | echo "ubuntu" 66 | elif [ -s /etc/centos-release ]; then 67 | echo "centos" 68 | else 69 | echo "unknown" 70 | fi 71 | } 72 | 73 | get_host_platform_name() { 74 | case "$(uname)" in 75 | "Linux") echo "linux";; 76 | "Darwin") echo "darwin";; 77 | *) die "This script only works on Linux and macOS.";; 78 | esac 79 | } 80 | 81 | get_android_ndk_dir() { 82 | echo "/tmp/android-ndk" 83 | } 84 | 85 | check_program_exists() { 86 | which "$1" >/dev/null 2>&1 87 | } 88 | 89 | get_program_path() { 90 | local program=$(which $1) || die "$1 not found" 91 | echo "${program}" 92 | } 93 | -------------------------------------------------------------------------------- /Support/Scripts/ds2-gdb-wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | # This script converts gdbserver arguments into a format ds2 can recognize 12 | 13 | ds2_args=("g" "-g") # gdbserver and gdb-compatibility mode 14 | "$(dirname "$0")/../../build/ds2" "${ds2_args[@]}" "$@" 15 | -------------------------------------------------------------------------------- /Support/Scripts/generate-documentation.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## Copyright (c) 2014-present, Facebook, Inc. 4 | ## All rights reserved. 5 | ## 6 | ## This source code is licensed under the University of Illinois/NCSA Open 7 | ## Source License found in the LICENSE file in the root directory of this 8 | ## source tree. An additional grant of patent rights can be found in the 9 | ## PATENTS file in the same directory. 10 | ## 11 | 12 | # This is used to automatically generate documentation for the project and is 13 | # inspired by https://gist.github.com/domenic/ec8b0fc8ab45f39403dd 14 | 15 | source "$(dirname "$0")/common.sh" 16 | 17 | SOURCE_BRANCH="master" 18 | TARGET_BRANCH="gh-pages" 19 | DEPLOY_KEY="Support/Testing/Travis/deploy-key.enc" 20 | TARGET_DIRECTORY="html" 21 | 22 | do_nothing() { 23 | echo "exiting: $1" 24 | exit 0 25 | } 26 | 27 | REPO="$(git config remote.origin.url)" 28 | SSH_REPO="${REPO/https:\/\/github.com\//git@github.com:}" 29 | SHA="$(git rev-parse --verify HEAD)" 30 | CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)" 31 | 32 | while test $# -gt 0; do 33 | case "$1" in 34 | --encryption-label) shift 35 | ENCRYPTION_LABEL="$1";; 36 | *) die "Unknown option \`$1'.";; 37 | esac 38 | shift 39 | done 40 | 41 | git_clone "$REPO" "$TARGET_DIRECTORY" "$TARGET_BRANCH" 42 | cd "$TARGET_DIRECTORY" 43 | 44 | rm -rf * 45 | git config user.name "Stephane Sezer (automated commit)" 46 | git config user.email "sas@fb.com" 47 | 48 | cd "$OLDPWD" 49 | doxygen Doxyfile 50 | cd "$TARGET_DIRECTORY" 51 | 52 | if git diff --name-only --exit-code; then 53 | do_nothing "No changes to the documentation." 54 | fi 55 | 56 | git add --all . 57 | git commit -m "Update documentation." -m "Bump to ${SHA}." 58 | 59 | 60 | if [ "${TRAVIS_PULL_REQUEST-false}" != "false" ]; then 61 | do_nothing "Documentation build on a pull request, not pushing." 62 | fi 63 | 64 | if [ "${TRAVIS_BRANCH-"$CURRENT_BRANCH"}" != "$SOURCE_BRANCH" ]; then 65 | do_nothing "Documentation build on branch '$CURRENT_BRANCH', not pushing." 66 | fi 67 | 68 | if [ -z "${ENCRYPTION_LABEL}" ]; then 69 | do_nothing '$ENCRYPTION_LABEL is not set, not pushing.' 70 | fi 71 | 72 | ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key" 73 | ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv" 74 | ENCRYPTED_KEY="${!ENCRYPTED_KEY_VAR}" 75 | ENCRYPTED_IV="${!ENCRYPTED_IV_VAR}" 76 | KEY="$(umask 077; mktemp /tmp/deploy-key-XXXXXX)" 77 | openssl aes-256-cbc -K "$ENCRYPTED_KEY" -iv "$ENCRYPTED_IV" -in "../$DEPLOY_KEY" -out "$KEY" -d 78 | eval $(ssh-agent) 79 | ssh-add "$KEY" 80 | git push "$SSH_REPO" "$TARGET_BRANCH" 81 | -------------------------------------------------------------------------------- /Support/Scripts/generate-register-descriptors.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## Copyright (c) 2014-present, Facebook, Inc. 4 | ## All rights reserved. 5 | ## 6 | ## This source code is licensed under the University of Illinois/NCSA Open 7 | ## Source License found in the LICENSE file in the root directory of this 8 | ## source tree. An additional grant of patent rights can be found in the 9 | ## PATENTS file in the same directory. 10 | ## 11 | 12 | set -eu 13 | 14 | architectures=("X86" "X86_64" "ARM" "ARM64") 15 | 16 | while test $# -gt 0; do 17 | case "$1" in 18 | --clang-format) shift 19 | CLANG_FORMAT="$1";; 20 | *) die "Unknown option \`$1'.";; 21 | esac 22 | shift 23 | done 24 | 25 | cformat="${CLANG_FORMAT-clang-format}" 26 | 27 | repo_root="$(cd "$(dirname "$0")" && git rev-parse --show-toplevel)" 28 | cd "$repo_root" 29 | 30 | build_dir="Tools/RegsGen2/build" 31 | if [ ! -x "$build_dir/regsgen2" ]; then 32 | echo "regsgen2 not found, building." 33 | mkdir -p "$build_dir" 34 | cd "$build_dir" 35 | cmake -DCMAKE_TOOLCHAIN_FILE="${repo_root}/Support/CMake/Toolchain-Linux-X86_64.cmake" .. 36 | make regsgen2 37 | fi 38 | 39 | cd "$repo_root" 40 | 41 | for a in "${architectures[@]}"; do 42 | header_path="Headers/DebugServer2/Architecture/$a/RegistersDescriptors.h" 43 | source_path="Sources/Architecture/$a/RegistersDescriptors.cpp" 44 | 45 | "$build_dir/regsgen2" \ 46 | -a "linux" \ 47 | -I "DebugServer2/Architecture/RegisterLayout.h" \ 48 | -h -o "$header_path" \ 49 | -f "Definitions/$a.json" 50 | 51 | "$build_dir/regsgen2" \ 52 | -a "linux" \ 53 | -I "DebugServer2/Architecture/$a/RegistersDescriptors.h" \ 54 | -c -o "$source_path" \ 55 | -f "Definitions/$a.json" 56 | 57 | "$cformat" -i -style=LLVM "$header_path" "$source_path" 58 | done 59 | -------------------------------------------------------------------------------- /Support/Scripts/install-android-emulator.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## Copyright (c) 2014-present, Facebook, Inc. 4 | ## All rights reserved. 5 | ## 6 | ## This source code is licensed under the University of Illinois/NCSA Open 7 | ## Source License found in the LICENSE file in the root directory of this 8 | ## source tree. An additional grant of patent rights can be found in the 9 | ## PATENTS file in the same directory. 10 | ## 11 | 12 | source "$(dirname "$0")/common.sh" 13 | 14 | [ $# -le 2 ] || die "usage: $0 [ARCH] [PLATFORM]" 15 | 16 | target_arch="${1-arm}" 17 | 18 | host_platform_name=$(get_host_platform_name) 19 | sdk_dir="/tmp/android-sdk-${host_platform_name}" 20 | sdkmanager="${sdk_dir}/tools/bin/sdkmanager" 21 | avdmanager="${sdk_dir}/tools/bin/avdmanager" 22 | 23 | if [ ! -f "$sdkmanager" ]; then 24 | package_name="sdk-tools-${host_platform_name}-4333796.zip" 25 | wget "https://dl.google.com/android/repository/${package_name}" -P /tmp 26 | unzip -d "${sdk_dir}" "/tmp/${package_name}" 27 | rm -f "/tmp/${package_name}" 28 | fi 29 | 30 | echo "y" | "${sdkmanager}" --update 31 | 32 | case "${target_arch}" in 33 | "arm") emulator_image_arch="armeabi-v7a"; api_level="${2-21}";; 34 | "arm64") emulator_image_arch="arm64-v8a"; api_level="${2-24}";; 35 | "x86") emulator_image_arch="x86"; api_level="${2-21}";; 36 | *) die "Unknown architecture '${target_arch}'.";; 37 | esac 38 | 39 | touch $HOME/.android/repositories.cfg 40 | system_image_package="system-images;android-${api_level};default;${emulator_image_arch}" 41 | echo "y" | "${sdkmanager}" "emulator" 42 | echo "y" | "${sdkmanager}" "platform-tools" 43 | echo "y" | "${sdkmanager}" "platforms;android-${api_level}" 44 | "${sdkmanager}" "${system_image_package}" 45 | echo "no" | "${avdmanager}" create avd \ 46 | --force -n "android-test-${target_arch}" \ 47 | --package "${system_image_package}" \ 48 | --abi "${emulator_image_arch}" 49 | -------------------------------------------------------------------------------- /Support/Scripts/run-gdb-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## Copyright (c) 2014-present, Facebook, Inc. 4 | ## All rights reserved. 5 | ## 6 | ## This source code is licensed under the University of Illinois/NCSA Open 7 | ## Source License found in the LICENSE file in the root directory of this 8 | ## source tree. An additional grant of patent rights can be found in the 9 | ## PATENTS file in the same directory. 10 | ## 11 | 12 | # This script runs parts of the gdb test suite found in the gdb repository 13 | # against ds2. It requires a few hacks in the testing infra to disable 14 | # broken unit tests. 15 | 16 | top="$(git rev-parse --show-toplevel)" 17 | build_dir="$PWD" 18 | 19 | [ "$(uname)" == "Linux" ] || die "The gdb test suite requires a Linux host environment." 20 | [ -x "$build_dir/ds2" ] || die "Unable to find a ds2 binary in the current directory." 21 | 22 | while test $# -gt 0; do 23 | case "$1" in 24 | --gdb-tests) shift 25 | GDB_TESTS="$1";; 26 | *) die "Unknown option \`$1'.";; 27 | esac 28 | shift 29 | done 30 | 31 | source "$top/Support/Scripts/common.sh" 32 | 33 | gdb_ftp_path="https://ftp.gnu.org/gnu/gdb" 34 | gdb_basename="gdb-7.11.1" 35 | gdb_src_path="$build_dir/$gdb_basename" 36 | 37 | wget "$gdb_ftp_path/$gdb_basename.tar.gz" 38 | tar -zxf "$gdb_basename.tar.gz" 39 | rm -f "${gdb_basename}.tar.gz" 40 | 41 | testingPath="$top/Support/Testing" 42 | for p in $testingPath/Patches/gdb/*.patch; do 43 | echo "Applying $p" 44 | patch -d "$gdb_src_path" -p1 <"$p" 45 | done 46 | 47 | cd "$gdb_src_path/gdb/testsuite" 48 | ds2_test_dir="ds2.tests" 49 | mkdir -p "$ds2_test_dir" 50 | 51 | IFS=';' read -ra TEST <<< "$GDB_TESTS" 52 | for test_name in "${TEST[@]}"; do 53 | cp $test_name.exp $ds2_test_dir 54 | cp $test_name*.c $ds2_test_dir 55 | done 56 | 57 | ./configure 58 | 59 | gdb_exe="$(which gdb)" 60 | ds2_wrapper="$top/Support/Scripts/ds2-gdb-wrapper.sh" 61 | make check RUNTESTFLAGS="GDB=$gdb_exe GDBSERVER=$ds2_wrapper -target_board=native-gdbserver" TESTS="$ds2_test_dir/*.exp" 62 | -------------------------------------------------------------------------------- /Support/Testing/Blacklists/ds2/android-arm64.blacklist: -------------------------------------------------------------------------------- 1 | skip 2 | CreateAfterAttachTestCase.test_create_after_attach_with_popen 3 | TestReturnValue.ReturnValueTestCase 4 | TestThreadAPI.ThreadAPITestCase.test_step_out_of_malloc_into_function_b_dwarf 5 | TestNumThreads.NumberOfThreadsTestCase.test_unique_stacks_dwarf 6 | TestVirtual.CppVirtualMadness.test_virtual_madness_dwarf 7 | TestProcessAttach.ProcessAttachTestCase.test_attach_to_process_from_different_dir_by_id 8 | TestNoreturnUnwind.NoreturnUnwind.test_dwarf 9 | TestMemoryFind.MemoryFindTestCase.test_memory_find_dwarf 10 | TestIRInterpreter.IRInterpreterTestCase.test_ir_interpreter_dwarf 11 | TestExprs2.ExprCommands2TestCase.test_more_expr_commands_dwarf 12 | TestSaveJITObjects.SaveJITObjectsTestCase.test_save_jit_objects_dwarf 13 | TestCStrings.CStringsTestCase.test_with_run_command_dwarf 14 | TestCppGlobalOperators.TestCppGlobalOperators.test_equals_operator_dwarf 15 | TestCppGlobalOperators.TestCppGlobalOperators.test_operator_new_dwarf 16 | 17 | xfail 18 | TestIRInterpreter.IRInterpreterTestCase.test_ir_interpreter 19 | TestBreakpointInGlobalConstructor.TestBreakpointInGlobalConstructors.test 20 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_int_type_dwarf 21 | -------------------------------------------------------------------------------- /Support/Testing/Blacklists/ds2/android_invalid_tests.blacklist: -------------------------------------------------------------------------------- 1 | skip 2 | TestWatchpointCommands.WatchpointCommandsTestCase 3 | TestWatchpointConditionCmd.WatchpointConditionCmdTestCase 4 | TestWatchpointCommandPython.WatchpointPythonCommandTestCase 5 | TestWatchpointCommandLLDB.WatchpointLLDBCommandTestCase 6 | TestMyFirstWatchpoint.HelloWatchpointTestCase 7 | TestWatchLocation.HelloWatchLocationTestCase 8 | TestWatchpointDisable.TestWatchpointSetEnable 9 | TestWatchpointEvents.TestWatchpointEvents 10 | TestWatchpointSizes.WatchpointSizeTestCase 11 | TestWatchpointMultipleSlots.WatchpointSlotsTestCase 12 | TestWatchpointMultipleThreads.WatchpointForMultipleThreadsTestCase 13 | TestWatchpointIgnoreCount.WatchpointIgnoreCountTestCase 14 | TestWatchpointIter.WatchpointIteratorTestCase 15 | TestSetWatchpoint.SetWatchpointAPITestCase 16 | TestWatchpointConditionAPI.WatchpointConditionAPITestCase 17 | TestSetWatchlocation.SetWatchlocationAPITestCase 18 | TestTargetWatchAddress.TargetWatchAddressAPITestCase 19 | -------------------------------------------------------------------------------- /Support/Testing/Blacklists/ds2/centos.blacklist: -------------------------------------------------------------------------------- 1 | xfail 2 | TestExprs2.ExprCommands2TestCase.test_more_expr_commands_dwarf 3 | -------------------------------------------------------------------------------- /Support/Testing/Blacklists/ds2/x86-platform.blacklist: -------------------------------------------------------------------------------- 1 | xfail 2 | TestProcessAttach.ProcessAttachTestCase.test_attach_to_process_from_different_dir_by_id 3 | TestFloatTypes.FloatTypesTestCase.test_double_type_dwarf 4 | TestFloatTypes.FloatTypesTestCase.test_float_type_dwarf 5 | TestFloatTypesExpr.FloatTypesExprTestCase.test_double_type_dwarf 6 | TestFloatTypesExpr.FloatTypesExprTestCase.test_float_type_dwarf 7 | TestIntegerTypes.IntegerTypesTestCase.test_char_type_dwarf 8 | TestIntegerTypes.IntegerTypesTestCase.test_int_type_dwarf 9 | TestIntegerTypes.IntegerTypesTestCase.test_long_long_type_dwarf 10 | TestIntegerTypes.IntegerTypesTestCase.test_long_type_dwarf 11 | TestIntegerTypes.IntegerTypesTestCase.test_short_type_dwarf 12 | TestIntegerTypes.IntegerTypesTestCase.test_unsigned_char_type_dwarf 13 | TestIntegerTypes.IntegerTypesTestCase.test_unsigned_int_type_dwarf 14 | TestIntegerTypes.IntegerTypesTestCase.test_unsigned_long_long_type_dwarf 15 | TestIntegerTypes.IntegerTypesTestCase.test_unsigned_long_type_dwarf 16 | TestIntegerTypes.IntegerTypesTestCase.test_unsigned_short_type_dwarf 17 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_char_type_dwarf 18 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_int_type_dwarf 19 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_long_long_type_dwarf 20 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_long_type_dwarf 21 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_short_type_dwarf 22 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_unsigned_char_type_dwarf 23 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_unsigned_int_type_dwarf 24 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_unsigned_long_long_type_dwarf 25 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_unsigned_long_type_dwarf 26 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_unsigned_short_type_dwarf 27 | TestProcessIO.ProcessIOTestCase.test_stderr_redirection_dwarf 28 | TestProcessIO.ProcessIOTestCase.test_stdout_redirection_dwarf 29 | TestProcessIO.ProcessIOTestCase.test_stdout_stderr_redirection_dwarf 30 | 31 | skip 32 | TestTargetSourceMap.TestTargetSourceMap.test_source_map 33 | lldbsuite.test.lldbtest.TestDataFormatterInvalidStdUniquePtr.test 34 | lldbsuite.test.lldbtest.TestGModules.test_dwarf 35 | lldbsuite.test.lldbtest.TestLLVMStyle.test_dwarf 36 | lldbsuite.test.lldbtest.TestNamespaceConflicts.test_dwarf 37 | lldbsuite.test.lldbtest.TestSampleInlineTest.test_dwarf 38 | lldbsuite.test.lldbtest.TestScalarURem.test_dwarf 39 | lldbsuite.test.lldbtest.TestStats.test_dwarf 40 | lldbsuite.test.lldbtest.TestSymbols.test_dwarf 41 | lldbsuite.test.lldbtest.TestVirtualOverload.test_dwarf 42 | -------------------------------------------------------------------------------- /Support/Testing/Blacklists/ds2/x86.blacklist: -------------------------------------------------------------------------------- 1 | xfail 2 | TestLldbGdbServer.LldbGdbServerTestCase.test_p_returns_correct_data_size_for_each_qRegisterInfo_attach_llgs 3 | TestLldbGdbServer.LldbGdbServerTestCase.test_p_returns_correct_data_size_for_each_qRegisterInfo_launch_llgs 4 | TestLoadUsingPaths.LoadUsingPathsTestCase.test_load_using_paths 5 | TestProcessLaunch.ProcessLaunchTestCase.test_set_working_dir_existing 6 | TestLoadUsingPaths.LoadUsingPathsTestCase.test_load_using_paths 7 | TestProcessLaunch.ProcessLaunchTestCase.test_set_working_dir_existing 8 | 9 | skip 10 | TestChangeValueAPI.ChangeValueAPITestCase.test_change_value 11 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_unsigned_int_type 12 | TestReturnValue 13 | TestSettings.SettingsCommandTestCase.test_pass_host_env_vars 14 | TestSettings.SettingsCommandTestCase.test_run_args_and_env_vars 15 | -------------------------------------------------------------------------------- /Support/Testing/Blacklists/ds2/x86_64-platform.blacklist: -------------------------------------------------------------------------------- 1 | skip 2 | TestTargetSourceMap.TestTargetSourceMap.test_source_map 3 | lldbsuite.test.lldbtest.TestDataFormatterInvalidStdUniquePtr.test 4 | lldbsuite.test.lldbtest.TestGModules.test_dwarf 5 | lldbsuite.test.lldbtest.TestLLVMStyle.test_dwarf 6 | lldbsuite.test.lldbtest.TestNamespaceConflicts.test_dwarf 7 | lldbsuite.test.lldbtest.TestSampleInlineTest.test_dwarf 8 | lldbsuite.test.lldbtest.TestScalarURem.test_dwarf 9 | lldbsuite.test.lldbtest.TestStats.test_dwarf 10 | lldbsuite.test.lldbtest.TestSymbols.test_dwarf 11 | lldbsuite.test.lldbtest.TestVirtualOverload.test_dwarf 12 | 13 | xfail 14 | TestFloatTypes.FloatTypesTestCase.test_double_type_dwarf 15 | TestFloatTypes.FloatTypesTestCase.test_float_type_dwarf 16 | TestFloatTypesExpr.FloatTypesExprTestCase.test_double_type_dwarf 17 | TestFloatTypesExpr.FloatTypesExprTestCase.test_float_type_dwarf 18 | TestIntegerTypes.IntegerTypesTestCase.test_char_type_dwarf 19 | TestIntegerTypes.IntegerTypesTestCase.test_int_type_dwarf 20 | TestIntegerTypes.IntegerTypesTestCase.test_long_long_type_dwarf 21 | TestIntegerTypes.IntegerTypesTestCase.test_long_type_dwarf 22 | TestIntegerTypes.IntegerTypesTestCase.test_short_type_dwarf 23 | TestIntegerTypes.IntegerTypesTestCase.test_unsigned_char_type_dwarf 24 | TestIntegerTypes.IntegerTypesTestCase.test_unsigned_int_type_dwarf 25 | TestIntegerTypes.IntegerTypesTestCase.test_unsigned_long_long_type_dwarf 26 | TestIntegerTypes.IntegerTypesTestCase.test_unsigned_long_type_dwarf 27 | TestIntegerTypes.IntegerTypesTestCase.test_unsigned_short_type_dwarf 28 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_char_type_dwarf 29 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_int_type_dwarf 30 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_long_long_type_dwarf 31 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_long_type_dwarf 32 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_short_type_dwarf 33 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_unsigned_char_type_dwarf 34 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_unsigned_int_type_dwarf 35 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_unsigned_long_long_type_dwarf 36 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_unsigned_long_type_dwarf 37 | TestIntegerTypesExpr.IntegerTypesExprTestCase.test_unsigned_short_type_dwarf 38 | TestProcessAttach.ProcessAttachTestCase.test_attach_to_process_from_different_dir_by_id 39 | TestProcessIO.ProcessIOTestCase.test_stderr_redirection_dwarf 40 | TestProcessIO.ProcessIOTestCase.test_stdout_redirection_dwarf 41 | TestProcessIO.ProcessIOTestCase.test_stdout_stderr_redirection_dwarf 42 | -------------------------------------------------------------------------------- /Support/Testing/Blacklists/ds2/x86_64.blacklist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/ds2/eaf83c59b8fff11cc4c218da7b78a983754727ec/Support/Testing/Blacklists/ds2/x86_64.blacklist -------------------------------------------------------------------------------- /Support/Testing/Blacklists/upstream/general.blacklist: -------------------------------------------------------------------------------- 1 | xfail 2 | TestCallUserDefinedFunction.ExprCommandCallUserDefinedFunction 3 | TestConstVariables.ConstVariableTestCase.test_and_run_command 4 | TestDataFormatterCpp.CppDataFormatterTestCase.test_with_run_command 5 | TestDataFormatterSynthVal.DataFormatterSynthValueTestCase.test_with_run_command 6 | TestExprs.BasicExprCommandsTestCase.test_expr_commands_can_handle_quotes 7 | TestFunctionTypes.FunctionTypesTestCase.test_pointers 8 | TestLoadUnload.LoadUnloadTestCase.test_lldb_process_load_and_unload_commands 9 | TestNamespaceDefinitions.NamespaceDefinitionsTestCase.test_expr 10 | TestNestedPersistentTypes.NestedPersistentTypesTestCase.test_persistent_types 11 | TestPersistentTypes.PersistenttypesTestCase.test_persistent_types 12 | TestPrintfAfterUp.Radar9531204TestCase.test_expr_commands 13 | TestRegisterVariables.RegisterVariableTestCase.test_and_run_command 14 | TestStepOverWatchpoint.TestStepOverWatchpoint 15 | TestUnicodeLiterals.UnicodeLiteralsTestCase.test_expr1 16 | TestUnicodeLiterals.UnicodeLiteralsTestCase.test_expr2 17 | TestUnicodeLiterals.UnicodeLiteralsTestCase.test_expr3 18 | 19 | skip 20 | _dwo$ 21 | TestBoundViolation.RegisterCommandsTestCase.test_mpx_boundary_violation 22 | TestLambdas 23 | TestMPXRegisters.RegisterCommandsTestCase.test_mpx_registers_with_example_code 24 | TestMultilineExpressions.MultilineExpressionsTestCase.test_with_run_commands 25 | TestMultithreaded.SBBreakpointCallbackCase.test_sb_api_listener_event_description 26 | TestMultithreaded.SBBreakpointCallbackCase.test_sb_api_listener_event_process_state 27 | TestMultithreaded.SBBreakpointCallbackCase.test_breakpoint_callback 28 | TestStopHookMechanism.StopHookMechanismTestCase 29 | TestTopLevelExprs.TopLevelExpressionsTestCase.test_top_level_expressions 30 | -------------------------------------------------------------------------------- /Support/Testing/Blacklists/upstream/platform.blacklist: -------------------------------------------------------------------------------- 1 | xfail 2 | HelloWorldTestCase.test_with_attach_to_process_with_id_api 3 | -------------------------------------------------------------------------------- /Support/Testing/Blacklists/upstream/x86-platform.blacklist: -------------------------------------------------------------------------------- 1 | xfail 2 | TestCallWithTimeout.ExprCommandWithTimeoutsTestCase 3 | ExprSyscallTestCase.test_setpgid 4 | TestUnwindExpression.UnwindFromExpressionTest.test_unwind_expression 5 | -------------------------------------------------------------------------------- /Support/Testing/Blacklists/upstream/x86.blacklist: -------------------------------------------------------------------------------- 1 | xfail 2 | TestExprHelpExamples.Radar9673644TestCase.test_expr_commands 3 | TestExprs.BasicExprCommandsTestCase.test_evaluate_expression_python 4 | TestExprsChar.ExprCharTestCase.test_default_char 5 | TestExprsChar.ExprCharTestCase.test_signed_char 6 | TestFormatters.ExprFormattersTestCase 7 | TestIRInterpreter.IRInterpreterTestCase.test_ir_interpreter 8 | TestMemoryFind.MemoryFindTestCase.test_memory_find 9 | TestNamespace.NamespaceTestCase.test_with_run_command 10 | TestNamespaceLookup.NamespaceLookupTestCase.test_scope_lookup_before_using_with_run_command 11 | TestOverloadedFunctions.CPPStaticMethodsTestCase.test_with_run_command 12 | TestRegisters.RegisterCommandsTestCase.test_register_expressions 13 | TestRvalueReferences.RvalueReferencesTestCase.test_with_run_command 14 | TestTemplateArgs.TemplateArgsTestCase.test_integer_args 15 | TestVirtual.CppVirtualMadness.test_virtual_madness 16 | -------------------------------------------------------------------------------- /Support/Testing/CircleCI/install-cmake.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## Copyright (c) 2014-present, Facebook, Inc. 4 | ## All rights reserved. 5 | ## 6 | ## This source code is licensed under the University of Illinois/NCSA Open 7 | ## Source License found in the LICENSE file in the root directory of this 8 | ## source tree. An additional grant of patent rights can be found in the 9 | ## PATENTS file in the same directory. 10 | ## 11 | 12 | if [ ! -e "/tmp/cmake.tar.gz" ] ; then 13 | wget --continue --output-document="/tmp/cmake.tar.gz" "https://cmake.org/files/v3.12/cmake-3.12.1-Linux-x86_64.tar.gz" 14 | fi 15 | 16 | tar --strip-components=1 -xf "/tmp/cmake.tar.gz" -C "/usr/local" 17 | -------------------------------------------------------------------------------- /Support/Testing/Patches/android-search-paths.patch: -------------------------------------------------------------------------------- 1 | diff --git a/packages/Python/lldbsuite/test/dotest.py b/packages/Python/lldbsuite/test/dotest.py 2 | index d28c5ef..6f04220 100644 3 | --- a/packages/Python/lldbsuite/test/dotest.py 4 | +++ b/packages/Python/lldbsuite/test/dotest.py 5 | @@ -1244,6 +1244,8 @@ def run_suite(): 6 | 7 | target_platform = lldb.DBG.GetSelectedPlatform().GetTriple().split('-')[2] 8 | 9 | + lldb.DBG.HandleCommand("settings set target.exec-search-paths /tmp/debug-data") 10 | + 11 | checkLibcxxSupport() 12 | checkLibstdcxxSupport() 13 | checkDebugInfoSupport() 14 | -------------------------------------------------------------------------------- /Support/Testing/Patches/fix-test-suite-path.patch: -------------------------------------------------------------------------------- 1 | diff --git a/test/use_lldb_suite.py b/test/use_lldb_suite.py 2 | index 6e24b9d..617af38 100644 3 | --- a/test/use_lldb_suite.py 4 | +++ b/test/use_lldb_suite.py 5 | @@ -4,7 +4,7 @@ import sys 6 | 7 | 8 | def find_lldb_root(): 9 | - lldb_root = os.path.dirname(inspect.getfile(inspect.currentframe())) 10 | + lldb_root = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) 11 | while True: 12 | lldb_root = os.path.dirname(lldb_root) 13 | if lldb_root is None: 14 | -------------------------------------------------------------------------------- /Support/Testing/Patches/gdb/Disable-broken-printcmds-tests.patch: -------------------------------------------------------------------------------- 1 | diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp 2 | index 3996d98..885155c 100644 3 | --- a/gdb/testsuite/gdb.base/printcmds.exp 4 | +++ b/gdb/testsuite/gdb.base/printcmds.exp 5 | @@ -692,10 +692,14 @@ proc test_print_string_constants {} { 6 | gdb_test "p \"abcd\"\[2\]" " = 99 'c'" 7 | gdb_test "p sizeof (\"abcdef\")" " = 7" 8 | gdb_test "ptype \"foo\"" " = char \\\[4\\\]" 9 | + setup_xfail "*-*-*" 10 | gdb_test "p *\"foo\"" " = 102 'f'" 11 | gdb_test "ptype *\"foo\"" " = char" 12 | + setup_xfail "*-*-*" 13 | gdb_test "p &*\"foo\"" " = \"foo\"" 14 | + setup_xfail "*-*-*" 15 | gdb_test "ptype &*\"foo\"" "type = char \\*" 16 | + setup_xfail "*-*-*" 17 | gdb_test "p (char *)\"foo\"" " = \"foo\"" 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Support/Testing/Patches/gdb/Disable-broken-step-bt-tests.patch: -------------------------------------------------------------------------------- 1 | diff --git a/gdb/testsuite/gdb.base/step-bt.exp b/gdb/testsuite/gdb.base/step-bt.exp 2 | index 74d9708..a65f1aa 100644 3 | --- a/gdb/testsuite/gdb.base/step-bt.exp 4 | +++ b/gdb/testsuite/gdb.base/step-bt.exp 5 | @@ -16,6 +16,9 @@ 6 | # The intent of this testcase is to assure that backtrace works while 7 | # single-stepping the instructions that prepare to call a function. 8 | 9 | +# FIXME: We skip tests that flake instead of xfailing them. 10 | +set ds2_skip 1 11 | + 12 | 13 | standard_testfile 14 | 15 | @@ -43,7 +46,9 @@ 16 | ".*" \ 17 | "step second instruction" 18 | 19 | -gdb_test "bt" \ 20 | - "#0 +(0x\[0-9a-z\]+ in )?hello .*#1 +(0x\[0-9a-z\]* in )?main.*" \ 21 | - "backtrace after second instruction step" 22 | +if { !$ds2_skip } then { 23 | + gdb_test "bt" \ 24 | + "#0 +(0x\[0-9a-z\]+ in )?hello .*#1 +(0x\[0-9a-z\]* in )?main.*" \ 25 | + "backtrace after second instruction step" 26 | +} 27 | 28 | -------------------------------------------------------------------------------- /Support/Testing/Patches/getplatform-workaround.patch: -------------------------------------------------------------------------------- 1 | diff --git a/packages/Python/lldbsuite/test/lldbplatformutil.py b/packages/Python/lldbsuite/test/lldbplatformutil.py 2 | index 940b01e..f9d5e07 100644 3 | --- a/packages/Python/lldbsuite/test/lldbplatformutil.py 4 | +++ b/packages/Python/lldbsuite/test/lldbplatformutil.py 5 | @@ -129,6 +129,7 @@ def getDarwinOSTriples(): 6 | 7 | def getPlatform(): 8 | """Returns the target platform which the tests are running on.""" 9 | + return "linux" 10 | platform = lldb.DBG.GetSelectedPlatform().GetTriple().split('-')[2] 11 | if platform.startswith('freebsd'): 12 | platform = 'freebsd' 13 | -------------------------------------------------------------------------------- /Support/Testing/Travis/after-success.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## Copyright (c) 2014-present, Facebook, Inc. 4 | ## All rights reserved. 5 | ## 6 | ## This source code is licensed under the University of Illinois/NCSA Open 7 | ## Source License found in the LICENSE file in the root directory of this 8 | ## source tree. An additional grant of patent rights can be found in the 9 | ## PATENTS file in the same directory. 10 | ## 11 | 12 | set -eu 13 | 14 | if [[ "${TARGET-}" == Darwin-* ]]; then 15 | exit 0 16 | fi 17 | 18 | if [[ "${COVERAGE-}" = "1" ]]; then 19 | top="$(git rev-parse --show-toplevel)" 20 | coveralls_args=("-E" ".*/lib/.*" "-E" ".*/include/.*" "-E" ".*/sys/.*" "-E" ".*/lldb/.*" 21 | "-E" ".*/deps/.*" "-r" "$top" "-b" "$top/build") 22 | if [[ "${CLANG-}" = "1" ]]; then 23 | coveralls_args+=("--gcov" "llvm-cov-5.0" "--gcov-options" "gcov") 24 | else 25 | coveralls_args+=("--gcov" "gcov-5") 26 | fi 27 | PATH=$PATH:"~/.local/bin" coveralls "${coveralls_args[@]}" 28 | fi 29 | -------------------------------------------------------------------------------- /Support/Testing/Travis/before-install.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | ## 3 | ## Copyright (c) 2014-present, Facebook, Inc. 4 | ## All rights reserved. 5 | ## 6 | ## This source code is licensed under the University of Illinois/NCSA Open 7 | ## Source License found in the LICENSE file in the root directory of this 8 | ## source tree. An additional grant of patent rights can be found in the 9 | ## PATENTS file in the same directory. 10 | ## 11 | 12 | import os 13 | import sys 14 | import platform 15 | from subprocess import check_call 16 | 17 | host = os.uname()[0] 18 | target = os.getenv('TARGET') 19 | 20 | here = os.path.dirname(os.path.realpath(__file__)) 21 | check_call(os.path.join(here, 'travis-hacks.sh')) 22 | 23 | if host == 'Darwin': 24 | check_call('brew update', shell=True) 25 | elif host == 'Linux': 26 | repositories = [] 27 | keys = [] 28 | 29 | def add_toolchain_test_repo(): 30 | repositories.append('ppa:ubuntu-toolchain-r/test') 31 | 32 | def add_llvm_repo(): 33 | add_toolchain_test_repo() 34 | dist = os.getenv("LINUX_DISTRO") 35 | keys.append('http://llvm.org/apt/llvm-snapshot.gpg.key') 36 | llvm_url = 'http://llvm.org/apt/' + dist + '/' 37 | repo_name = 'llvm-toolchain-' + dist + '-5.0' 38 | repositories.append('deb ' + llvm_url + ' ' + repo_name + ' main') 39 | 40 | if target in [ 'Style', 'Registers' ]: 41 | add_llvm_repo() 42 | elif target in [ 'Linux-X86', 'Linux-X86_64', 'Tizen-X86' ]: 43 | add_toolchain_test_repo() 44 | 45 | if os.getenv('CLANG') != None or os.getenv('LLDB_TESTS') != None: 46 | add_llvm_repo() 47 | 48 | for r in repositories: 49 | check_call('sudo add-apt-repository -y "%s"' % r, shell=True) 50 | 51 | for k in keys: 52 | check_call('wget -O - "%s" | sudo apt-key add -' % k, shell=True) 53 | 54 | check_call('sudo apt-get update', shell=True) 55 | -------------------------------------------------------------------------------- /Support/Testing/Travis/deploy-key.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/ds2/eaf83c59b8fff11cc4c218da7b78a983754727ec/Support/Testing/Travis/deploy-key.enc -------------------------------------------------------------------------------- /Support/Testing/Travis/travis-hacks.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ## 3 | ## Copyright (c) 2014-present, Facebook, Inc. 4 | ## All right reserved. 5 | ## 6 | ## This source code is licensed under the University of Illinois/NCSA Open 7 | ## Source License found in the LICENSE file in the root directory of this 8 | ## source tree. An additional grant of patent rights can be found in the 9 | ## PATENTS file in the same directory. 10 | 11 | set -eu 12 | 13 | # We're running out of disk space on Travis. This is a dirty hack. We shouldn't 14 | # have to do this. In the home directory, perl5 takes up roughly 1.1GB of space 15 | # and otp takes up roughly 3.0GB. They are protected, but we should be able to 16 | # forcibly remove them with sudo. 17 | sudo rm -rf ~/perl5 18 | sudo rm -rf ~/otp 19 | 20 | # There are some headers present on Travis macOS bots. These conflict with the 21 | # headers that get installed with gcc so we need to remove them. 22 | if [ "$(uname)" == "Darwin" ]; then 23 | sudo rm -rf "/usr/local/include/c++" 24 | fi 25 | -------------------------------------------------------------------------------- /Tools/JSObjects/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | cmake_minimum_required(VERSION 3.3) 12 | 13 | project(JSObjects) 14 | 15 | find_package(BISON) 16 | find_package(FLEX) 17 | 18 | FLEX_TARGET(JSON_SCANNER 19 | ${JSObjects_SOURCE_DIR}/Sources/libjson/tokenizer.l 20 | ${JSObjects_BINARY_DIR}/tokenizer.c 21 | COMPILE_FLAGS "--header-file=${JSObjects_BINARY_DIR}/tokenizer.h \ 22 | --nounistd --batch --never-interactive") 23 | BISON_TARGET(JSON_PARSER 24 | ${JSObjects_SOURCE_DIR}/Sources/libjson/parser.y 25 | ${JSObjects_BINARY_DIR}/parser.c 26 | COMPILE_FLAGS "--no-lines") 27 | ADD_FLEX_BISON_DEPENDENCY(JSON_SCANNER JSON_PARSER) 28 | 29 | set(JSOBJECTS_SOURCES 30 | ${BISON_JSON_PARSER_OUTPUTS} 31 | ${FLEX_JSON_SCANNER_OUTPUTS} 32 | Sources/JSObjects.cpp 33 | Sources/libjson/json.c 34 | Sources/libjson/qstring.c 35 | ) 36 | 37 | add_library(jsobjects STATIC ${JSOBJECTS_SOURCES}) 38 | target_include_directories(jsobjects 39 | PUBLIC ${JSObjects_SOURCE_DIR}/Headers 40 | PRIVATE ${JSObjects_SOURCE_DIR}/Sources/libjson 41 | PRIVATE ${JSObjects_BINARY_DIR}) 42 | set_property(TARGET jsobjects PROPERTY C_STANDARD 99) 43 | set_property(TARGET jsobjects PROPERTY C_EXTENSIONS OFF) 44 | set_property(TARGET jsobjects PROPERTY CXX_STANDARD 11) 45 | set_property(TARGET jsobjects PROPERTY CXX_EXTENSIONS OFF) 46 | if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR 47 | (CMAKE_CXX_COMPILER_ID MATCHES "Clang" 48 | AND NOT CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")) 49 | target_compile_options(jsobjects PRIVATE -Wall -Wextra -Werror) 50 | target_compile_options(jsobjects PRIVATE -Wno-unused-parameter 51 | -Wno-unused-function 52 | -Wno-sign-compare) 53 | target_compile_options( 54 | jsobjects PRIVATE $<$:-D_POSIX_C_SOURCE=200809L>) 55 | elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 56 | target_compile_options(jsobjects PRIVATE /W3 /DSTRICT /wd4996) 57 | target_compile_options(jsobjects PRIVATE /MP) 58 | endif () 59 | -------------------------------------------------------------------------------- /Tools/JSObjects/Sources/libjson/LICENSE_1_0.txt: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /Tools/JSObjects/Sources/libjson/jsoncb.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright Nils Alexander Roemcke 2005. 4 | 5 | Use, modification, and distribution are subject to the Boost Software 6 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | http://www.boost.org/LICENSE_1_0.txt) 8 | */ 9 | 10 | #ifndef JSON_JSON_H_94e2ebdd_cb8c_4331_b448_a416758d0669 11 | #define JSON_JSON_H_94e2ebdd_cb8c_4331_b448_a416758d0669 12 | 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | /* 20 | 21 | Forward declarations 22 | 23 | */ 24 | 25 | struct json_cb_t; 26 | 27 | /************************************ 28 | * 29 | * Handle values in object context 30 | * 31 | */ 32 | 33 | /* 34 | Callbacks 35 | */ 36 | 37 | typedef int json_string_cb(void *obj, const char *m, const char *s); 38 | typedef int json_int_cb(void *obj, const char *m, int i); 39 | typedef int json_double_cb(void *obj, const char *m, double d); 40 | typedef int json_bool_cb(void *obj, const char *m, int b); 41 | typedef int json_null_cb(void *obj, const char *m); 42 | 43 | typedef int json_new_obj_cb(void *obj, const char *m, void **obj_new, 44 | struct json_cb_t **cb); 45 | typedef int json_obj_cb(void *obj, void *o); 46 | 47 | typedef int json_new_array_cb(void *obj, const char *m, void **array_new, 48 | struct json_cb_t **cb); 49 | typedef int json_array_cb(void *obj, void *a); 50 | 51 | typedef void *json_delete_cb(void *obj); 52 | 53 | struct json_cb_t { 54 | json_string_cb *string_cb; 55 | json_int_cb *int_cb; 56 | json_double_cb *double_cb; 57 | json_bool_cb *bool_cb; 58 | json_null_cb *null_cb; 59 | 60 | json_new_obj_cb *new_obj_cb; 61 | json_obj_cb *obj_cb; 62 | 63 | json_new_array_cb *new_array_cb; 64 | json_array_cb *array_cb; 65 | 66 | json_delete_cb *delete_cb; 67 | }; 68 | 69 | /**************************************************** 70 | * 71 | * Error handling 72 | * 73 | */ 74 | typedef int json_err_cb(void *err_data, unsigned int line, unsigned int column, 75 | const char *error); 76 | 77 | /***************************************************** 78 | * 79 | * Parser functions 80 | * 81 | */ 82 | 83 | int json_fparse(FILE *f, struct json_cb_t *vb, void *root, json_err_cb *err_cb, 84 | void *err_data); 85 | 86 | int json_parse(const char *fn, struct json_cb_t *vb, void *root, 87 | json_err_cb *err_cb, void *err_data); 88 | 89 | #ifdef __cplusplus 90 | } 91 | #endif 92 | 93 | #endif /* JSON_JSON_H_94e2ebdd_cb8c_4331_b448_a416758d0669 */ 94 | -------------------------------------------------------------------------------- /Tools/JSObjects/Sources/libjson/jsontest.c: -------------------------------------------------------------------------------- 1 | 2 | #include "jsoncb.h" 3 | 4 | 5 | 6 | 7 | 8 | int 9 | main (int argc, char **argv) 10 | { 11 | json_fparse(stdin, NULL, NULL, NULL, NULL); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Tools/JSObjects/Sources/libjson/qstring.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright Nils Alexander Roemcke 2005. 4 | 5 | Use, modification, and distribution are subject to the Boost Software 6 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | http://www.boost.org/LICENSE_1_0.txt) 8 | */ 9 | 10 | 11 | #include "qstring.h" 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | static int 18 | read_u (char **tmp, const char **str) 19 | { 20 | uint32_t uchar = 0; 21 | unsigned int i; 22 | 23 | for (i = 0; i < 4; i++) 24 | { 25 | char ch = **str; 26 | (*str)++; 27 | uchar <<= 4; 28 | if (ch >= '0' && ch <= '9') 29 | uchar += (ch - '0'); 30 | else if (ch >= 'a' && ch <= 'f') 31 | uchar += 10 + (ch - 'a'); 32 | else if (ch >= 'A' && ch <= 'F') 33 | uchar += 10 + (ch - 'A'); 34 | else 35 | return 0; 36 | } 37 | 38 | return 0; 39 | /* 40 | not implementet yet!! 41 | */ 42 | 43 | 44 | return -1; 45 | } 46 | 47 | 48 | char * 49 | _json_string_unquote(const char *str) 50 | { 51 | char *retval = malloc(strlen(str) - 1); 52 | char *tmp = retval; 53 | 54 | if (!retval) 55 | return NULL; 56 | 57 | 58 | if (*str != '"') 59 | goto failure; 60 | 61 | while(1) 62 | { 63 | str++; 64 | switch (*str) 65 | { 66 | case '\0': 67 | goto failure; 68 | case '"': 69 | *tmp = '\0'; 70 | return retval; 71 | case '\\': 72 | str++; 73 | switch(*str) 74 | { 75 | case 'b': 76 | *tmp = '\b'; 77 | break; 78 | case 'f': 79 | *tmp = '\f'; 80 | break; 81 | case 'n': 82 | *tmp = '\n'; 83 | break; 84 | case 'r': 85 | *tmp = '\r'; 86 | break; 87 | case 't': 88 | *tmp = '\t'; 89 | break; 90 | case 'u': 91 | if (!read_u(&tmp, &str)) 92 | goto failure; 93 | break; 94 | default: 95 | *tmp = *str; 96 | } 97 | break; 98 | 99 | default: 100 | *tmp = *str; 101 | } 102 | tmp++; 103 | } 104 | 105 | 106 | 107 | 108 | failure: 109 | 110 | free(retval); 111 | return 0; 112 | 113 | } 114 | -------------------------------------------------------------------------------- /Tools/JSObjects/Sources/libjson/qstring.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright Nils Alexander Roemcke 2005. 4 | 5 | Use, modification, and distribution are subject to the Boost Software 6 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | http://www.boost.org/LICENSE_1_0.txt) 8 | */ 9 | 10 | #ifndef JSON_QSTRING_H_7b9bb303_f8e4_4537_a301_962d540e2dc5 11 | #define JSON_QSTRING_H_7b9bb303_f8e4_4537_a301_962d540e2dc5 12 | 13 | #ifdef JSON_WITH_XE 14 | #include 15 | #endif 16 | 17 | char *_json_string_unquote(const char *str); 18 | 19 | #endif /* JSON_QSTRING_H_7b9bb303_f8e4_4537_a301_962d540e2dc5 */ 20 | -------------------------------------------------------------------------------- /Tools/RegsGen2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2014-present, Facebook, Inc. 3 | ## All rights reserved. 4 | ## 5 | ## This source code is licensed under the University of Illinois/NCSA Open 6 | ## Source License found in the LICENSE file in the root directory of this 7 | ## source tree. An additional grant of patent rights can be found in the 8 | ## PATENTS file in the same directory. 9 | ## 10 | 11 | cmake_minimum_required(VERSION 3.1.0) 12 | 13 | project(RegsGen2) 14 | 15 | set(REGSGEN2_SOURCES 16 | FlagSet.cpp 17 | GDBDefinitions.cpp 18 | GDBVectorSet.cpp 19 | LLDBDefinitions.cpp 20 | ParseConstants.cpp 21 | RegisterSet.cpp 22 | RegisterTemplate.cpp 23 | main.cpp 24 | ) 25 | 26 | add_executable(regsgen2 ${REGSGEN2_SOURCES}) 27 | set_property(TARGET regsgen2 PROPERTY CXX_STANDARD 11) 28 | target_compile_options(regsgen2 PRIVATE -Wall -Wextra -Wno-unused-parameter -Wno-unused-function) 29 | 30 | add_subdirectory(../JSObjects "${CMAKE_CURRENT_BINARY_DIR}/JSObjects") 31 | target_link_libraries(regsgen2 jsobjects) 32 | -------------------------------------------------------------------------------- /Tools/RegsGen2/Constants.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #ifndef __regsgen_Constants_h 12 | #define __regsgen_Constants_h 13 | 14 | enum Encoding { 15 | kEncodingInvalid, 16 | kEncodingUInteger, 17 | kEncodingSInteger, 18 | kEncodingIEEESingle, 19 | kEncodingIEEEDouble, 20 | kEncodingIEEEExtended 21 | }; 22 | 23 | enum GDBEncoding { 24 | kGDBEncodingInvalid, 25 | kGDBEncodingInt, 26 | kGDBEncodingIEEESingle, 27 | kGDBEncodingIEEEDouble, 28 | kGDBEncodingDataPointer, 29 | kGDBEncodingCodePointer, 30 | kGDBEncodingX87Extension, 31 | kGDBEncodingUInt128, 32 | kGDBEncodingUnion, 33 | kGDBEncodingCustom 34 | }; 35 | 36 | enum Format { 37 | kFormatInvalid, 38 | kFormatBinary, 39 | kFormatDecimal, 40 | kFormatHexadecimal, 41 | kFormatFloat, 42 | kFormatVector 43 | }; 44 | 45 | enum LLDBVectorFormat { 46 | kLLDBVectorFormatNone, 47 | kLLDBVectorFormatUInt8, 48 | kLLDBVectorFormatSInt8, 49 | kLLDBVectorFormatUInt16, 50 | kLLDBVectorFormatSInt16, 51 | kLLDBVectorFormatUInt32, 52 | kLLDBVectorFormatSInt32, 53 | kLLDBVectorFormatUInt64, 54 | kLLDBVectorFormatSInt64, 55 | kLLDBVectorFormatUInt128, 56 | kLLDBVectorFormatFloat32 57 | }; 58 | 59 | #endif // !__regsgen_Constants_h 60 | -------------------------------------------------------------------------------- /Tools/RegsGen2/Context.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #ifndef __regsgen_Context_h 12 | #define __regsgen_Context_h 13 | 14 | #include "RegisterSet.h" 15 | #include "FlagSet.h" 16 | #include "GDBVectorSet.h" 17 | #include "LLDBDefinitions.h" 18 | #include "GDBDefinitions.h" 19 | 20 | struct Context { 21 | std::string Path; 22 | std::string SpecificOSABI; 23 | std::string GenericOSABI; 24 | std::string LongNameOSABI; 25 | std::string Namespace; 26 | std::vector Includes; 27 | JSDictionary const *Root; 28 | FlagSet::name_map FlagSets; 29 | ::GDBVectorSet GDBVectorSet; 30 | Register::set Registers; 31 | Register::name_map PublicRegisters; 32 | RegisterSet::name_map RegisterSets; 33 | LLDBDefinitions LLDBDefs; 34 | GDBDefinitions GDBDefs; 35 | bool HasInvalidatedOrContainerSets; 36 | }; 37 | 38 | #endif // !__regsgen_Context_h 39 | -------------------------------------------------------------------------------- /Tools/RegsGen2/Definitions.txt: -------------------------------------------------------------------------------- 1 | top level 2 | 3 | keyword: "namespace" 4 | type: string 5 | presence: required 6 | definition: 7 | defines the name of the C++ namespace generated, 8 | the resulting namespace will be ds2::Architecture::. 9 | 10 | keyword: "register-sets" 11 | type: dictionary 12 | presence: required 13 | definition: 14 | defines the register sets for the architecture. 15 | 16 | keyword: "flag-sets" 17 | type: dictionary 18 | presence: optional 19 | definition: 20 | defines the flags of a special purpose register (like EFLAGS on x86), 21 | this is required for correct GDB XML generation. 22 | 23 | keyword: "vector-sets" 24 | type: dictionary 25 | presence: optional 26 | definition: 27 | defines the vector register sets, this is required for correct 28 | GDB XML generation. 29 | 30 | keyword: "gdb-defs" 31 | type: dictionary 32 | presence: required 33 | definition: 34 | defines the GDB register layout. 35 | 36 | keyword: "lldb-defs" 37 | type: array 38 | presence: required 39 | definition: 40 | defines the LLDB register layout. 41 | 42 | - "register-defs" 43 | -------------------------------------------------------------------------------- /Tools/RegsGen2/FlagSet.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #ifndef __regsgen_FlagSet_h 12 | #define __regsgen_FlagSet_h 13 | 14 | #include "JSObjects/JSObjects.h" 15 | #include "Definitions.h" 16 | 17 | #include 18 | 19 | class FlagSet { 20 | public: 21 | typedef std::shared_ptr shared_ptr; 22 | typedef std::map name_map; 23 | 24 | private: 25 | ssize_t _size; 26 | std::string _name; 27 | std::string _GDBName; 28 | Flag::vector _flags; 29 | 30 | public: 31 | FlagSet(); 32 | 33 | public: 34 | bool parse(std::string const &name, JSDictionary const *d); 35 | 36 | public: 37 | inline std::string const &name() const { return _name; } 38 | 39 | inline std::string const &GDBName() const { return _GDBName; } 40 | 41 | public: 42 | inline size_t size() const { return _size; } 43 | 44 | public: 45 | inline bool empty() const { return _flags.empty(); } 46 | 47 | inline size_t count() const { return _flags.size(); } 48 | 49 | public: 50 | inline Flag::vector::const_iterator begin() const { return _flags.begin(); } 51 | 52 | inline Flag::vector::const_iterator end() const { return _flags.end(); } 53 | }; 54 | 55 | #endif // !__regsgen_FlagSet_h 56 | -------------------------------------------------------------------------------- /Tools/RegsGen2/GDBDefinitions.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #ifndef __regsgen_GDBDefinitions_h 12 | #define __regsgen_GDBDefinitions_h 13 | 14 | #include "FlagSet.h" 15 | #include "RegisterSet.h" 16 | #include "GDBVectorSet.h" 17 | 18 | struct GDBFeatureEntry { 19 | typedef std::shared_ptr shared_ptr; 20 | typedef std::vector vector; 21 | 22 | enum Type { kTypeNone, kTypeFlagSet, kTypeVectorSet, kTypeRegisterSet }; 23 | 24 | GDBFeatureEntry::Type Type; 25 | 26 | struct { 27 | FlagSet::shared_ptr Flag; 28 | GDBVector::shared_ptr Vector; 29 | RegisterSet::shared_ptr Register; 30 | } Set; 31 | 32 | GDBFeatureEntry() : Type(kTypeNone) {} 33 | }; 34 | 35 | struct GDBFeature { 36 | typedef std::shared_ptr shared_ptr; 37 | typedef std::vector vector; 38 | 39 | std::string FileName; 40 | std::string Identifier; 41 | std::string OSABI; 42 | 43 | GDBFeatureEntry::vector Entries; 44 | }; 45 | 46 | class GDBDefinitions { 47 | private: 48 | std::string _architecture; 49 | GDBFeature::vector _features; 50 | 51 | public: 52 | GDBDefinitions(); 53 | 54 | public: 55 | bool parse(Context &ctx, JSDictionary const *d); 56 | 57 | private: 58 | bool parseFeature(Context &ctx, size_t index, JSDictionary const *d); 59 | 60 | public: 61 | inline bool empty() const { return _features.empty(); } 62 | 63 | public: 64 | inline std::string const &architecture() const { return _architecture; } 65 | 66 | public: 67 | inline GDBFeature::vector const &features() const { return _features; } 68 | }; 69 | 70 | #endif // !__regsgen_GDBDefinitions_h 71 | -------------------------------------------------------------------------------- /Tools/RegsGen2/GDBVectorSet.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #ifndef __regsgen_GDBVectorSet_h 12 | #define __regsgen_GDBVectorSet_h 13 | 14 | #include "JSObjects/JSObjects.h" 15 | #include "Definitions.h" 16 | 17 | class GDBVectorSet { 18 | public: 19 | typedef std::shared_ptr shared_ptr; 20 | 21 | private: 22 | size_t _size; 23 | GDBVector::vector _vectors; 24 | GDBVector::name_map _map; 25 | 26 | public: 27 | GDBVectorSet(); 28 | 29 | public: 30 | bool parse(JSDictionary const *d); 31 | 32 | public: 33 | inline bool empty() const { return _vectors.empty(); } 34 | 35 | public: 36 | inline GDBVector::vector::const_iterator begin() const { 37 | return _vectors.begin(); 38 | } 39 | 40 | inline GDBVector::vector::const_iterator end() const { 41 | return _vectors.end(); 42 | } 43 | }; 44 | 45 | #endif // !__regsgen_GDBVectorSet_h 46 | -------------------------------------------------------------------------------- /Tools/RegsGen2/KeyValue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #ifndef __regsgen_KeyValue_h 12 | #define __regsgen_KeyValue_h 13 | 14 | #include 15 | 16 | template struct KeyValue { 17 | char const *Key; 18 | V Value; 19 | }; 20 | 21 | template 22 | static inline bool FindKeyValue(KeyValue const *kv, std::string const &key, 23 | V &result) { 24 | for (size_t n = 0; kv[n].Key != nullptr; n++) { 25 | if (key == kv[n].Key) { 26 | result = kv[n].Value; 27 | return true; 28 | } 29 | } 30 | return false; 31 | } 32 | 33 | #endif // !__regsgen_KeyValue_h 34 | -------------------------------------------------------------------------------- /Tools/RegsGen2/LLDBDefinitions.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #ifndef __regsgen_LLDBDefinitions_h 12 | #define __regsgen_LLDBDefinitions_h 13 | 14 | #include "RegisterSet.h" 15 | 16 | struct LLDBSet { 17 | typedef std::shared_ptr shared_ptr; 18 | typedef std::vector vector; 19 | 20 | size_t Index; 21 | std::string Description; 22 | RegisterSet::vector RegisterSets; 23 | }; 24 | 25 | class LLDBDefinitions { 26 | private: 27 | LLDBSet::vector _sets; 28 | 29 | public: 30 | LLDBDefinitions(); 31 | 32 | public: 33 | bool parse(Context &ctx, JSArray const *defs); 34 | 35 | public: 36 | inline bool empty() const { return _sets.empty(); } 37 | 38 | inline size_t count() const { return _sets.size(); } 39 | 40 | public: 41 | inline LLDBSet::vector::const_iterator begin() const { return _sets.begin(); } 42 | 43 | inline LLDBSet::vector::const_iterator end() const { return _sets.end(); } 44 | }; 45 | 46 | #endif // !__regsgen_LLDBDefinitions_h 47 | -------------------------------------------------------------------------------- /Tools/RegsGen2/ParseConstants.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #ifndef __regsgen_ParseConstants_h 12 | #define __regsgen_ParseConstants_h 13 | 14 | #include "Constants.h" 15 | 16 | #include 17 | 18 | bool ParseEncodingName(std::string const &name, Encoding &enc); 19 | bool ParseGDBEncodingName(std::string const &name, GDBEncoding &enc, 20 | std::string &cname); 21 | bool ParseFormatName(std::string const &name, Format &fmt); 22 | bool ParseLLDBVectorFormatName(std::string const &name, LLDBVectorFormat &fmt); 23 | 24 | #endif // !__regsgen_ParseConstants_h 25 | -------------------------------------------------------------------------------- /Tools/RegsGen2/RegisterSet.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #ifndef __regsgen_RegisterSet_h 12 | #define __regsgen_RegisterSet_h 13 | 14 | #include "RegisterTemplate.h" 15 | 16 | struct Context; 17 | 18 | class RegisterSet { 19 | public: 20 | typedef std::shared_ptr shared_ptr; 21 | typedef std::vector vector; 22 | typedef std::map name_map; 23 | 24 | private: 25 | std::string _name; 26 | Register::vector _regs; 27 | Register::name_map _map; 28 | 29 | public: 30 | RegisterSet(); 31 | 32 | public: 33 | bool parse(Context &ctx, std::string const &name, JSDictionary const *d); 34 | bool finalize(Context &ctx); 35 | 36 | public: 37 | inline Register::vector::iterator begin() { return _regs.begin(); } 38 | 39 | inline Register::vector::iterator end() { return _regs.end(); } 40 | 41 | public: 42 | inline Register::shared_ptr find(std::string const &name) const { 43 | auto ri = _map.find(name); 44 | if (ri == _map.end()) 45 | return Register::shared_ptr(); 46 | else 47 | return ri->second; 48 | } 49 | 50 | public: 51 | inline std::string const &name() const { return _name; } 52 | }; 53 | 54 | #endif // !__regsgen_RegisterSet_h 55 | -------------------------------------------------------------------------------- /Tools/RegsGen2/RegisterTemplate.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014-present, Facebook, Inc. 3 | // All rights reserved. 4 | // 5 | // This source code is licensed under the University of Illinois/NCSA Open 6 | // Source License found in the LICENSE file in the root directory of this 7 | // source tree. An additional grant of patent rights can be found in the 8 | // PATENTS file in the same directory. 9 | // 10 | 11 | #ifndef __regsgen_RegisterTemplate_h 12 | #define __regsgen_RegisterTemplate_h 13 | 14 | #include "JSObjects/JSObjects.h" 15 | #include "Definitions.h" 16 | 17 | class RegisterTemplate { 18 | private: 19 | class Number { 20 | private: 21 | ssize_t _base; 22 | std::vector _used; 23 | size_t _next; 24 | 25 | public: 26 | Number(); 27 | 28 | public: 29 | void init(size_t base); 30 | 31 | public: 32 | bool mark(size_t index); 33 | 34 | public: 35 | ssize_t next(); 36 | }; 37 | 38 | private: 39 | Register _template; 40 | Number _DWARFRegisterNumber; 41 | Number _ehframeRegisterNumber; 42 | Number _GDBRegisterNumber; 43 | bool _DWARFEhframeAliased; 44 | bool _explicitGDBRegisterNumber; 45 | std::string _specificOSABI; 46 | std::string _genericOSABI; 47 | 48 | public: 49 | RegisterTemplate(std::string const &specificOSABI = std::string(), 50 | std::string const &genericOSABI = std::string()); 51 | 52 | public: 53 | bool parse(JSDictionary const *d); 54 | 55 | public: 56 | // 57 | // Create a register out of the template. 58 | // 59 | Register *make(std::string const &name, JSDictionary const *d); 60 | 61 | // 62 | // Assign the register numbers to the register, call this once 63 | // you have created all the registers in the same creation order. 64 | // 65 | void setRegisterNumbers(Register *reg); 66 | }; 67 | 68 | #endif // !__regsgen_RegisterTemplate_h 69 | --------------------------------------------------------------------------------