├── .gitattributes ├── .gitignore ├── Documentation ├── ColabSupportHistory.md ├── ColabSupportSunsets.png ├── ForumThreadComments.md ├── GoogleDriveIntegration.md ├── HardwareAcceleration.md ├── JupyterDisplay.md ├── LanguageModes.md ├── MagicCommands.md ├── RuntimeErrors.md └── SyntaxColoring.md ├── LICENSE ├── README.md ├── Sources ├── JupyterKernel │ ├── CreateKernel.swift │ ├── ErrorTypes.swift │ ├── RegisterKernel.swift │ ├── SwiftKernel │ │ ├── DoExecute.swift │ │ ├── FormatErrors.swift │ │ ├── HandleIO.swift │ │ ├── InitSwift.swift │ │ ├── KernelContext.swift │ │ └── PreprocessAndExecute.swift │ ├── SwiftPMEngine │ │ ├── PackageContext.swift │ │ ├── ProcessInstallDirectives.swift │ │ ├── ProcessInstalls.swift │ │ └── ProcessTests.swift │ ├── SwiftShell.swift │ └── third_party │ │ ├── PythonKit │ │ ├── LICENSE.txt │ │ ├── NumpyConversion.swift │ │ ├── Python.swift │ │ ├── PythonLibrary+Symbols.swift │ │ └── PythonLibrary.swift │ │ └── TensorFlow │ │ └── Core │ │ └── Threading.swift ├── LLDBProcess │ ├── LLDBProcess.cpp │ └── include │ │ └── LLDB │ │ ├── LLDB.h │ │ ├── SBAddress.h │ │ ├── SBAttachInfo.h │ │ ├── SBBlock.h │ │ ├── SBBreakpoint.h │ │ ├── SBBreakpointLocation.h │ │ ├── SBBreakpointName.h │ │ ├── SBBroadcaster.h │ │ ├── SBCommandInterpreter.h │ │ ├── SBCommandInterpreterRunOptions.h │ │ ├── SBCommandReturnObject.h │ │ ├── SBCommunication.h │ │ ├── SBCompileUnit.h │ │ ├── SBData.h │ │ ├── SBDebugger.h │ │ ├── SBDeclaration.h │ │ ├── SBDefines.h │ │ ├── SBEnvironment.h │ │ ├── SBError.h │ │ ├── SBEvent.h │ │ ├── SBExecutionContext.h │ │ ├── SBExpressionOptions.h │ │ ├── SBFile.h │ │ ├── SBFileSpec.h │ │ ├── SBFileSpecList.h │ │ ├── SBFrame.h │ │ ├── SBFunction.h │ │ ├── SBHostOS.h │ │ ├── SBInstruction.h │ │ ├── SBInstructionList.h │ │ ├── SBLanguageRuntime.h │ │ ├── SBLaunchInfo.h │ │ ├── SBLineEntry.h │ │ ├── SBListener.h │ │ ├── SBMemoryRegionInfo.h │ │ ├── SBMemoryRegionInfoList.h │ │ ├── SBModule.h │ │ ├── SBModuleSpec.h │ │ ├── SBPlatform.h │ │ ├── SBProcess.h │ │ ├── SBProcessInfo.h │ │ ├── SBQueue.h │ │ ├── SBQueueItem.h │ │ ├── SBReproducer.h │ │ ├── SBSection.h │ │ ├── SBSourceManager.h │ │ ├── SBStream.h │ │ ├── SBStringList.h │ │ ├── SBStructuredData.h │ │ ├── SBSymbol.h │ │ ├── SBSymbolContext.h │ │ ├── SBSymbolContextList.h │ │ ├── SBTarget.h │ │ ├── SBThread.h │ │ ├── SBThreadCollection.h │ │ ├── SBThreadPlan.h │ │ ├── SBTrace.h │ │ ├── SBTraceOptions.h │ │ ├── SBType.h │ │ ├── SBTypeCategory.h │ │ ├── SBTypeEnumMember.h │ │ ├── SBTypeFilter.h │ │ ├── SBTypeFormat.h │ │ ├── SBTypeNameSpecifier.h │ │ ├── SBTypeSummary.h │ │ ├── SBTypeSynthetic.h │ │ ├── SBUnixSignals.h │ │ ├── SBValue.h │ │ ├── SBValueList.h │ │ ├── SBVariablesOptions.h │ │ ├── SBWatchpoint.h │ │ ├── lldb-defines.h │ │ ├── lldb-enumerations.h │ │ ├── lldb-forward.h │ │ ├── lldb-public.h │ │ ├── lldb-types.h │ │ └── lldb-versioning.h └── include │ ├── EnableIPythonDisplay.swift │ └── KernelCommunicator.swift └── install_swift.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | Sources/LLDBProcess/include/LLDB/** linguist-vendored 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Hidden Files 2 | .* 3 | !.gitignore 4 | !.gitkeep 5 | !.github 6 | !.travis.yml 7 | 8 | # Swift 9 | /build/ 10 | /Package.resolved 11 | 12 | # Python 13 | *.pyc 14 | 15 | # Temporary Items 16 | *.tmp 17 | *.tmp.* 18 | 19 | # Virtual Environments 20 | /venv*/ 21 | 22 | # Configuration Override 23 | *.override.* 24 | 25 | # Extra Directories 26 | /Assets/ 27 | /Extra/ 28 | 29 | # Xcode 30 | xcuserdata/ 31 | *.xcscmblueprint 32 | *.xccheckout 33 | -------------------------------------------------------------------------------- /Documentation/ColabSupportHistory.md: -------------------------------------------------------------------------------- 1 | # History of Swift Support in Google Colab 2 | 3 | In the last meeting of the original Swift for TensorFlow team (accessed from the [Open Design Meeting Notes](https://docs.google.com/document/d/1Fm56p5rV1t2Euh6WLtBFKGqI43ozC3EIjReyLk-LCLU/edit)), there was a Google Slides presentation titled ["S4TF History - The [Incomplete] Insider Edition"](https://drive.google.com/file/d/1vxSIRq7KEmrFNAV_E0Wr7Pivn728Wcvs/view). On slide 21, they announced that "Swift support in Colab will sunset over the next few weeks". The presentation occurred on February 12, which means support likely ended in March 2021. 4 | 5 | 6 | ![Screenshot of the last official S4TF presentation, highlighting the statement indicating an end to Swift support on Colab](./ColabSupportSunsets.png) 7 | 8 | The official Swift support came from a built-in Jupyter kernel, cloned from [google/swift-jupyter](https://github.com/google/swift-jupyter). Based on that repository's README, Google may have pre-installed the latest custom S4TF toolchain on their Colab servers, ready to be accessed by the kernel. Once the Jupyter kernel was removed, Colab could not execute notebooks written in Swift. Instead, it attempted to run them using the Python kernel. 9 | 10 | When Swift [came back](https://forums.swift.org/t/swift-for-tensorflow-resurrection-swift-running-on-colab-again/54158) to Colab in January 2022, it used a new Jupyter kernel written in Swift, hosted at [philipturner/swift-colab](https://github.com/philipturner/swift-colab). Fine-tuned for its primary use case (Google Colaboratory), the kernel dropped support for Docker and non-Linux platforms. Since the repository compiled itself using the downloaded toolchain, it was optimized for JIT compilation. 11 | 12 | The initial release of Swift-Colab suffered from a long startup time because it downloaded unnecessary dependencies. In addition, it was a literal translation of the Python code in [google/swift-jupyter](https://github.com/google/swift-jupyter), with very few optimizations or changes to functionality. In April 2022, Swift-Colab was rewritten from scratch using the [philipturner/swift-colab-dev](https://github.com/philipturner/swift-colab-dev) repository. 13 | 14 | Swift-Colab 2.0 made several enhancements to the user experience. It slashed startup time almost in half, from 54 to 31 seconds. The user could switch between the Swift kernel and the built-in Python kernel - something required for [mounting a Google Drive](https://github.com/google/swift-jupyter/issues/100) into the file system. Toolchains and package build products could be cached, allowing someone to restart a notebook without downloading anything twice. The new kernel permitted execution of `%install` directives in any notebook cell, linking Swift packages dynamically at runtime. 15 | 16 | In the future, Swift-Colab could gain more features. As discussed on a [Swift Forums thread](https://forums.swift.org/t/violet-python-vm-written-in-swift/56945/7), Swift packages could be pre-compiled in TAR files and downloaded by the Jupyter kernel. This feature could make using S4TF easier, as it takes 3 minutes to compile under default build options. Compiled packages would be hosted in the "releases" section of the [s4tf/s4tf](https://github.com/s4tf/s4tf) repository, where development continues after Google stopped contributing. This repository could also run on [Docker and JupyterLab](https://github.com/philipturner/swift-colab/issues/16), which are more ergonomic than Colab for some data science use cases. 17 | -------------------------------------------------------------------------------- /Documentation/ColabSupportSunsets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philipturner/swift-colab/cbbd10da5bedc39b5ffdb1efbfc75f10e274eed7/Documentation/ColabSupportSunsets.png -------------------------------------------------------------------------------- /Documentation/ForumThreadComments.md: -------------------------------------------------------------------------------- 1 | # Forum Thread Comments 2 | 3 | These were transfered from the Swift-Colab [Swift Forums thread](https://forums.swift.org/t/swift-for-tensorflow-resurrection-swift-running-on-colab-again/54158) to improve organization and convenience of viewing. 4 | 5 | ## Preceding Comment 6 | 7 | It is possible to set up a semi-automated test... 8 | 9 | ## Dec 23, '21 10:10 AM 10 | 11 | I got `libSwiftPythonBridge.so` and `libPythonKit.so` to successfully link to a Swift script, then compiled and executed that script. Soon, I should be able to replace the Shell command for compiling a Swift string with a call into SwiftPythonBridge's C-compatible interface from Python. This might make the output from `print(...)` in Swift synchronize with the Jupyter kernel. 12 | 13 | ## Dec 23, '21 5:51 PM 14 | 15 | I got around a major bug with the Global Interpreter Lock, which had me really scared for a moment (I need to use `PyDLL` instead of `CDLL` in `ctypes`). I can now execute a Swift script by calling directly into the dynamic library's C interface. However, every call to `print(...)` goes to a hidden system output, instead of the Jupyter notebook's output. Previously, this is what happened, but I manually extracted that output and logged it to Jupyter's output. 16 | 17 | Edit: Using [Wurlitzer](https://github.com/minrk/wurlitzer), I can restore output synchronization to how it was before, although you still have to wait until all of the code executes before reading any output. 18 | 19 | ## Dec 24, '21 4:06 PM 20 | 21 | I can now subclass Python objects and coordinate the logic of their methods to Swift ([repository save point #3](https://github.com/philipturner/swift-colab/tree/save-3)). The next step will be subclassing the Jupyter kernel and finding what restrictions Google added to it in March. 22 | 23 | https://colab.research.google.com/drive/113MmiKUsd2ObeHwBOzA1STmclqazRom0?usp=sharing 24 | 25 | Python code temporarily included in the `swift` Python package: 26 | ```python 27 | class SwiftInteropTestSuperclass: 28 | pass 29 | 30 | class SwiftInteropTest(SwiftInteropTestSuperclass): 31 | def __init__(self): 32 | self.swift_delegate = SwiftDelegate() 33 | 34 | def example_func(self, string_param): 35 | return self.swift_delegate.call("example_func", [self, string_param]) 36 | 37 | def example_func_2(self, string_param): 38 | return self.swift_delegate.call("example_func_2", { string_param: self }) 39 | ``` 40 | 41 | Swift counterpart: 42 | ```swift 43 | import PythonKit 44 | import SwiftPythonBridge // this module is internal to Swift-Colab 45 | let swiftModule = Python.import("swift") 46 | 47 | let interopTest = swiftModule.SwiftInteropTest() 48 | 49 | interopTest.registerFunction(name: "example_func") { param -> Void in 50 | print("example_func called from Python with param \(param)") 51 | } 52 | 53 | interopTest.registerFunction(name: "example_func_2") { param -> PythonConvertible in 54 | print("example_func_2 called from Python with param \(param)") 55 | return String("return value") 56 | } 57 | 58 | print(interopTest.example_func("Input string for example_func")) 59 | print(interopTest.example_func_2("Input string for example_func_2")) 60 | ``` 61 | 62 | Output: 63 | ``` 64 | example_func called from Python with param [, 'Input string for example_func'] 65 | None 66 | example_func_2 called from Python with param {'Input string for example_func_2': } 67 | return value 68 | ``` 69 | 70 | ## Dec 25, '21 12:40 PM 71 | 72 | I translated the `register.py` file in [google/swift-jupyter](https://github.com/google/swift-jupyter) to Swift and it runs without crashing. I still need to translate `swift_kernel.py`, which is larger and likely what's affected by Google's restrictions. 73 | 74 | ## Dec 25, '21 4:50 PM 75 | 76 | I got to the point where I can alter the behavior of Google Colab, making it output whatever the code cell puts as input. I had to manually overwrite some Python code, then restart the Jupyter runtime. Now that I got to this point, I'm very confident I can follow through all the way and bring back Swift support to its state before the death of S4TF. Code completion, syntax coloring, everything. 77 | 78 | ## Dec 25, '21 6:37 PM 79 | 80 | Syntax coloring is working. All I had to do was clone an S4TF tutorial, inspect its metadata, and copy that over to a blank notebook. 81 | 82 | Open the notebook template in Colab, and the text is syntax-colored like Swift instead of Python. For example, an `import` statement is blue and green (Swift) instead of purple and white (Python). 83 | 84 | ## Dec 25, '21 9:14 PM 85 | 86 | Swift on Google Colab has entered the beta stage! Executing code is still in the works, but you can follow the steps of side-loading and prepare for when it's feature-complete. Check out the [README](https://github.com/philipturner/swift-colab) or the Colab notebook: 87 | 88 | https://colab.research.google.com/drive/1EACIWrk9IWloUckRm3wu973bKUBXQDKR?usp=sharing 89 | 90 | ## Dec 26, '21 9:01 PM 91 | 92 | Translated the `StdoutHandler` from the original Jupyter kernel's `swift_kernel.py` to Swift (won't get around to testing it for quite a while): 93 | 94 | https://github.com/philipturner/swift-colab/blob/main/Sources/SwiftColab/JupyterKernel/StdoutHandler/RunStdoutHandler.swift 95 | 96 | ## Dec 28, '21 1:45 PM 97 | 98 | Just finished translating the entire Swift kernel from Python to Swift. Now, it's time for heavy testing and experiencing many painful bugs :frowning:. 99 | 100 | ## Dec 28, '21 7:12 PM 101 | 102 | The S4TF team was right. There were major restrictions on LLDB, but I just bypassed them! 103 | 104 | ## Dec 28, '21 8:59 PM 105 | 106 | Due to some major additions to the Swift Package manager since S4TF died, I need to rework the Jupyter kernel's Swift package loader. I'm aiming to remove the restriction that you can't execute % commands outside of the first cell. 107 | 108 | By the way, I got a very basic line of Swift code to execute in Colab. 109 | ```swift 110 | Int.bitWidth 111 | ``` 112 | ```swift 113 | 64 114 | ``` 115 | 116 | ## Continuation of Discussion 117 | 118 | Swift-Colab is complete! Several tutorials... 119 | -------------------------------------------------------------------------------- /Documentation/GoogleDriveIntegration.md: -------------------------------------------------------------------------------- 1 | # Google Drive Integration 2 | 3 | > This documentation page is a work in progress. 4 | 5 | 6 | # Warning 7 | 8 | Do not hyperlink to this file. It will be deleted soon and transformed into a tutorial notebook. 9 | 10 | 37 | -------------------------------------------------------------------------------- /Documentation/HardwareAcceleration.md: -------------------------------------------------------------------------------- 1 | # Hardware Acceleration 2 | 3 | > This documentation page is a work in progress. 4 | 5 | Connecting to accelerators does not actually erase the runtime - look at `Runtime > Manage sessions`. 6 | 7 | S4TF SwiftPM test suite in Python mode notebook: 8 | - CPU: 19 seconds 9 | - GPU: 46 seconds 10 | - TPU: 20 seconds (likely that every op just went on CPU) -> ??? seconds with new test suite 11 | -------------------------------------------------------------------------------- /Documentation/JupyterDisplay.md: -------------------------------------------------------------------------------- 1 | # Jupyter Display 2 | 3 | > This documentation page is a work in progress. 4 | 5 | History of this, once had `JupyterDisplay.swift`, why it doesn't now 6 | 7 | How it works, using IPython to marshal data 8 | 9 | Does the Pandas DataFrame bug have something to do with this? 10 | 11 | SwiftPlot integration 12 | 13 | Try making a non-plot image from pure base64EncodedPNG 14 | -------------------------------------------------------------------------------- /Documentation/LanguageModes.md: -------------------------------------------------------------------------------- 1 | # Language Modes 2 | 3 | > This documentation page is a work in progress. 4 | 5 | Best explanation I currently have: https://forums.fast.ai/t/python-textfield-output-not-working/51000/14 6 | 7 | Why there needs to be a language mode. Ergonomics when building Swift-Colab, not getting self kicked off of Colab, being able to cache the toolchain and not disconnect and delete the runtime. 8 | 9 | Switch modes when restart runtime, but saves the files 10 | 11 | Hidden `--swift-colab-dev` mode switches between language modes on every runtime restart. Otherwise, you must change what's in `/opt/swift/runtime` to the desired language. 12 | 13 | ## Swift 14 | 15 | `/opt/swift/runtime` accepts: 16 | 17 | After you execute `install_swift.sh` in the Swift-Colab installation command, it instructs you to restart the runtime. Then, it will automatically be in Swift mode. 18 | 19 | ## Python 20 | 21 | `/opt/swift/runtime` accepts: 22 | 23 | Needed for Google Drive integration (link to doc file), overcoming a possible bug with Pandas DataFrame presentation (link to doc file about inline graphs) 24 | 25 | Include content from this: https://github.com/philipturner/swift-colab/pull/19#issuecomment-1173280812 26 | 27 | Change the words saying "Python mode" in the explanation of Colab's free tier, making it a hyperlink to this page. 28 | -------------------------------------------------------------------------------- /Documentation/RuntimeErrors.md: -------------------------------------------------------------------------------- 1 | # Runtime Errors 2 | 3 | > This documentation page is a work in progress. 4 | 5 | How Swift-Colab handles errors 6 | 7 | ## Runtime Crash 8 | 9 | Improvement to stack trace happened (here), see (thread). Could still be improved by removing what's at top, but difficult because it required parsing the output at a high level, and could technically remove output that isn't part of the extraneous trace. 10 | 11 | The above text is no longer accurate. Swift-Colab's error handling was overhauled in v2.1. 12 | -------------------------------------------------------------------------------- /Documentation/SyntaxColoring.md: -------------------------------------------------------------------------------- 1 | # Syntax Coloring 2 | 3 | > This documentation page is a work in progress. 4 | 5 | Swift-Colab works with any Jupyter notebook, but Swift ones are better. All code samples in docs aim to use Swift syntax coloring, even if in another language, because it mirrors what you will see in the notebook. 6 | 7 | ## Swift 8 | 9 | Comes from Monaco editor "client-side" (link) 10 | 11 | ## Shell 12 | 13 | Use parentheses when dealing with strings or numbers that are arguments, use parentheses liberally 14 | 15 | ## Python 16 | 17 | This may be easier on the eyes: 18 | 19 | ```swift 20 | #/* 21 | from google.colab import drive 22 | drive.mount(...) 23 | #*/ 24 | ``` 25 | 26 | vs 27 | 28 | ```swift 29 | from google.colab import drive 30 | drive.mount(...) 31 | ``` 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Philip Turner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Sources/JupyterKernel/CreateKernel.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | @_cdecl("JupyterKernel_createSwiftKernel") 4 | public func JupyterKernel_createSwiftKernel() { 5 | let fm = FileManager.default 6 | func read(path: String) -> String { 7 | let data = fm.contents(atPath: path)! 8 | return String(data: data, encoding: .utf8)!.lowercased() 9 | } 10 | 11 | let currentRuntime = read(path: "/opt/swift/runtime") 12 | let currentMode = read(path: "/opt/swift/mode") 13 | 14 | // Whether to automatically alternate between runtimes. 15 | let isRelease = currentMode.contains("release") 16 | let runtime1 = isRelease ? "python3" : "swift" 17 | let runtime2 = isRelease ? "swift" : "python3" 18 | 19 | let nextRuntime = currentRuntime.contains("python") ? runtime1 : runtime2 20 | fm.createFile( 21 | atPath: "/opt/swift/runtime", contents: nextRuntime.data(using: .utf8)!) 22 | 23 | // In dev mode, switch back into Python mode on the next runtime restart. This 24 | // makes debugging a lot easier and decreases the chance my main account will 25 | // be kicked off of Colab for excessive restarts/downloads. 26 | if currentRuntime.contains("python") { 27 | activatePythonKernel() 28 | } else { 29 | activateSwiftKernel() 30 | } 31 | } 32 | 33 | // A stored reference to the SwiftKernel type object, used as a workaround for 34 | // the fact that it must be initialized in Python code. 35 | fileprivate var preservedSwiftKernelRef: PythonObject! 36 | 37 | @_cdecl("JupyterKernel_constructSwiftKernelClass") 38 | public func JupyterKernel_constructSwiftKernelClass(_ classObj: OpaquePointer) { 39 | let SwiftKernel = PythonObject(OwnedPyObjectPointer(classObj)) 40 | preservedSwiftKernelRef = SwiftKernel 41 | 42 | SwiftKernel.implementation = "swift" 43 | SwiftKernel.implementation_version = "0.1" 44 | SwiftKernel.banner = "" 45 | 46 | SwiftKernel.language_info = [ 47 | "name": "swift", 48 | "mimetype": "text/x-swift", 49 | "file_extension": ".swift", 50 | "version": "" 51 | ] 52 | 53 | SwiftKernel.do_execute = PythonInstanceMethod { args in 54 | if !KernelContext.debuggerInitialized { 55 | KernelContext.kernel = args[0] 56 | try initSwift() 57 | KernelContext.debuggerInitialized = true 58 | KernelContext.log("finished initSwift") 59 | } 60 | 61 | let code = String(args[1])! 62 | let allowStdin = Bool(args[5])! 63 | let response = try doExecute(code: code, allowStdin: allowStdin) 64 | return response ?? [ 65 | "status": "ok", 66 | "execution_count": PythonObject(KernelContext.cellID), 67 | "payload": [], 68 | "user_expressions": [:], 69 | ] 70 | }.pythonObject 71 | } 72 | 73 | fileprivate func activateSwiftKernel() { 74 | print("=== Activating Swift kernel ===") 75 | 76 | // Jupyter sends us SIGINT when the user requests execution interruption. 77 | // Here, we block all threads from receiving the SIGINT, so that we can 78 | // handle it in a specific handler thread. 79 | let signal = Python.import("signal") 80 | signal.pthread_sigmask(signal.SIG_BLOCK, [signal.SIGINT]) 81 | 82 | // Must create this from a Python script declaration. Using the built-in 83 | // `type(_:_:_:)` method makes it `traitlets.traitlets.SwiftKernel` 84 | // instead of `__main__.SwiftKernel`. 85 | PyRun_SimpleString(""" 86 | from ctypes import *; from ipykernel.kernelbase import Kernel 87 | class SwiftKernel(Kernel): 88 | def __init__(self, **kwargs): 89 | super().__init__(**kwargs) 90 | 91 | func = PyDLL("/opt/swift/lib/libJupyterKernel.so").JupyterKernel_constructSwiftKernelClass 92 | func.argtypes = [c_void_p]; func(c_void_p(id(SwiftKernel))) 93 | """) 94 | 95 | let IPKernelApp = Python.import("ipykernel.kernelapp").IPKernelApp 96 | 97 | // We pass the kernel name as a command-line arg, since Jupyter gives those 98 | // highest priority (in particular overriding any system-wide config). 99 | IPKernelApp.launch_instance( 100 | argv: CommandLine.arguments + ["--IPKernelApp.kernel_class=__main__.SwiftKernel"]) 101 | } 102 | 103 | // The original Python kernel. There is no way to get it run besides 104 | // passing a string into the Python interpreter. No component of this 105 | // string can be extracted into Swift. 106 | fileprivate func activatePythonKernel() { 107 | print("=== Activating Python kernel ===") 108 | 109 | // Remove the CWD from sys.path while we load stuff. 110 | // This is added back by InteractiveShellApp.init_path() 111 | PyRun_SimpleString(""" 112 | import sys; from ipykernel import kernelapp as app 113 | if sys.path[0] == "": 114 | del sys.path[0] 115 | 116 | app.launch_new_instance() 117 | """) 118 | } 119 | -------------------------------------------------------------------------------- /Sources/JupyterKernel/ErrorTypes.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// Protocol for the result of executing code. 4 | protocol ExecutionResult: CustomStringConvertible { 5 | var description: String { get } 6 | } 7 | 8 | /// Protocol for an error from preprocessing code. 9 | protocol PreprocessorError: LocalizedError { 10 | static var label: String { get } 11 | var lineIndex: Int { get } 12 | } 13 | 14 | /// Protocol for the result of successfully executing code. 15 | protocol ExecutionResultSuccess: ExecutionResult {} 16 | 17 | /// Protocol for the result of unsuccessfully executing code. 18 | protocol ExecutionResultError: ExecutionResult {} 19 | 20 | /// The code executed successfully, and did not produce a value. 21 | struct SuccessWithoutValue: ExecutionResultSuccess { 22 | var description: String { "" } 23 | } 24 | 25 | /// The code executed successfully, and produced a value. 26 | struct SuccessWithValue: ExecutionResultSuccess { 27 | var description: String 28 | } 29 | 30 | /// There was a compile or runtime error. 31 | struct SwiftError: ExecutionResultError { 32 | var description: String 33 | } 34 | 35 | struct Exception: LocalizedError { 36 | var errorDescription: String? 37 | init(_ message: String) { errorDescription = message } 38 | } 39 | 40 | struct InterruptException: LocalizedError { 41 | var errorDescription: String? 42 | init(_ message: String) { errorDescription = message } 43 | } 44 | 45 | struct PreprocessorException: PreprocessorError { 46 | static let label = "Preprocessing error" 47 | var lineIndex: Int 48 | var errorDescription: String? 49 | init(lineIndex: Int, message: String) { 50 | self.lineIndex = lineIndex 51 | self.errorDescription = message 52 | } 53 | } 54 | 55 | struct PackageInstallException: PreprocessorError { 56 | static let label = "Package installation error" 57 | var lineIndex: Int 58 | var errorDescription: String? 59 | init(lineIndex: Int, message: String) { 60 | self.lineIndex = lineIndex 61 | self.errorDescription = message 62 | } 63 | } 64 | 65 | struct PackageTestException: PreprocessorError { 66 | static let label = "Package testing error" 67 | var lineIndex: Int 68 | var errorDescription: String? 69 | init(lineIndex: Int, message: String) { 70 | self.lineIndex = lineIndex 71 | self.errorDescription = message 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Sources/JupyterKernel/RegisterKernel.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | fileprivate let ipykernel_launcher = Python.import("ipykernel_launcher") 3 | fileprivate let KernelSpecManager = Python.import("jupyter_client").kernelspec.KernelSpecManager 4 | 5 | @_cdecl("JupyterKernel_registerSwiftKernel") 6 | public func JupyterKernel_registerSwiftKernel() { 7 | print("Registering Swift Jupyter kernel") 8 | 9 | let fm = FileManager.default 10 | let jupyterKernelFolder = "/opt/swift/internal-modules/JupyterKernel" 11 | 12 | // Cannot be a Swift script because that causes a crash. 13 | let pythonScript = """ 14 | from ctypes import PyDLL 15 | if __name__ == "__main__": 16 | PyDLL("/opt/swift/lib/libJupyterKernel.so").JupyterKernel_createSwiftKernel() 17 | """ 18 | 19 | let swiftKernelPath = "\(jupyterKernelFolder)/swift_kernel" 20 | try? fm.removeItem(atPath: swiftKernelPath) 21 | fm.createFile( 22 | atPath: swiftKernelPath, contents: pythonScript.data(using: .utf8)!) 23 | 24 | // Create kernel spec. 25 | let kernelSpec = """ 26 | { 27 | "argv": [ 28 | "/usr/bin/python3", 29 | "\(swiftKernelPath)", 30 | "-f", 31 | "{connection_file}" 32 | ], 33 | "display_name": "Swift", 34 | "language": "swift", 35 | "env": {} 36 | } 37 | """ 38 | 39 | let kernelSpecPath = "\(jupyterKernelFolder)/kernel.json" 40 | try? fm.removeItem(atPath: kernelSpecPath) 41 | 42 | fm.createFile( 43 | atPath: kernelSpecPath, contents: kernelSpec.data(using: .utf8)!) 44 | KernelSpecManager().install_kernel_spec(jupyterKernelFolder, "swift") 45 | 46 | // Overwrite Python kernel script. 47 | let activeKernelPath = String(ipykernel_launcher.__file__)! 48 | if !fm.contentsEqual(atPath: swiftKernelPath, andPath: activeKernelPath) { 49 | try! fm.copyItem(atPath: swiftKernelPath, toPath: activeKernelPath) 50 | } else { 51 | print("Swift Jupyter kernel was already registered") 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Sources/JupyterKernel/SwiftKernel/InitSwift.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | fileprivate struct CEnvironment { 4 | var envp: OpaquePointer 5 | 6 | init(environment: [String: String]) { 7 | var envArray: [String] = [] 8 | for (key, value) in environment { 9 | envArray.append("\(key)=\(value)") 10 | } 11 | 12 | typealias EnvPointer = UnsafeMutablePointer?> 13 | let envPointer = EnvPointer.allocate(capacity: envArray.count + 1) 14 | envPointer[envArray.count] = nil 15 | for i in 0.. 18 | .allocate(capacity: originalStr.count + 1) 19 | _ = originalStr.withCString { 20 | memcpy(strPointer, $0, originalStr.count + 1) 21 | } 22 | envPointer[i] = strPointer 23 | } 24 | envp = OpaquePointer(envPointer) 25 | } 26 | } 27 | 28 | func initSwift() throws { 29 | KernelPipe.resetPipes() 30 | KernelPipe.fetchPipes(currentProcess: .jupyterKernel) 31 | _ = KernelContext.mutex 32 | 33 | try initReplProcess() 34 | try initKernelCommunicator() 35 | try initConcurrency() 36 | try initSIGINTHandler() 37 | } 38 | 39 | fileprivate func initReplProcess() throws { 40 | let environment = ProcessInfo.processInfo.environment 41 | let cEnvironment = CEnvironment(environment: environment) 42 | 43 | let error = KernelContext.init_repl_process( 44 | cEnvironment.envp, FileManager.default.currentDirectoryPath) 45 | if error != 0 { 46 | throw Exception("Got error code \(error) from 'init_repl_process'") 47 | } 48 | } 49 | 50 | fileprivate func initKernelCommunicator() throws { 51 | var result = try preprocessAndExecute(code: """ 52 | %include "KernelCommunicator.swift" 53 | """) 54 | if result is ExecutionResultError { 55 | throw Exception("Error initializing KernelCommunicator: \(result)") 56 | } 57 | 58 | let session = KernelContext.kernel.session 59 | let id = String(session.session)! 60 | let key = String(session.key.decode("utf8"))! 61 | let username = String(session.username)! 62 | 63 | result = try preprocessAndExecute(code: """ 64 | enum JupyterKernel { 65 | static var communicator = KernelCommunicator( 66 | jupyterSession: KernelCommunicator.JupyterSession( 67 | id: "\(id)", key: "\(key)", username: "\(username)")) 68 | } 69 | """) 70 | if result is ExecutionResultError { 71 | throw Exception("Error declaring JupyterKernel: \(result)") 72 | } 73 | } 74 | 75 | fileprivate func initConcurrency() throws { 76 | // If this is a pre-concurrency Swift version, the import is a no-op. 77 | let result = execute(code: """ 78 | import _Concurrency 79 | """) 80 | if result is ExecutionResultError { 81 | throw Exception("Error importing _Concurrency: \(result)") 82 | } 83 | } 84 | 85 | fileprivate func initSIGINTHandler() throws { 86 | DispatchQueue.global().async { 87 | while true { 88 | var signal_set = sigset_t() 89 | sigemptyset(&signal_set) 90 | sigaddset(&signal_set, SIGINT) 91 | 92 | var sig: Int32 = 0 93 | sigwait(&signal_set, &sig) 94 | 95 | _ = KernelContext.mutex.acquire() 96 | _ = KernelContext.async_interrupt_process() 97 | _ = KernelContext.mutex.release() 98 | KernelContext.isInterrupted = true 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Sources/JupyterKernel/SwiftPMEngine/PackageContext.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | fileprivate let shlex = Python.import("shlex") 3 | fileprivate let string = Python.import("string") 4 | 5 | struct PackageContext { 6 | static var installLocation = "/opt/swift/packages" 7 | static var swiftPMFlags: [String] = [] 8 | 9 | static func sendStdout(_ message: String, insertNewLine: Bool = true) { 10 | KernelContext.sendResponse("stream", [ 11 | "name": "stdout", 12 | "text": "\(message)\(insertNewLine ? "\n" : "")" 13 | ]) 14 | } 15 | 16 | static func shlexSplit( 17 | _ arguments: PythonConvertible, _ lineIndex: Int 18 | ) throws -> [String] { 19 | let split = shlex[dynamicMember: "split"].throwing 20 | do { 21 | let output = try split.dynamicallyCall(withArguments: arguments) 22 | return [String](output)! 23 | } catch let error as PythonError { 24 | throw PreprocessorException(lineIndex: lineIndex, message: """ 25 | Could not parse shell arguments: \(arguments) 26 | \(error) 27 | """) 28 | } 29 | } 30 | 31 | static func substituteCwd( 32 | _ template: String, _ lineIndex: Int 33 | ) throws -> String { 34 | do { 35 | let output = try string.Template(template).substitute.throwing 36 | .dynamicallyCall(withArguments: [ 37 | "cwd": FileManager.default.currentDirectoryPath 38 | ]) 39 | return String(output)! 40 | } catch { 41 | throw handleTemplateError(error, lineIndex) 42 | } 43 | } 44 | 45 | static func handleTemplateError( 46 | _ anyError: Error, _ lineIndex: Int 47 | ) -> Error { 48 | guard let pythonError = anyError as? PythonError else { 49 | return anyError 50 | } 51 | switch pythonError { 52 | case .exception(let error, _): 53 | return PreprocessorException(lineIndex: lineIndex, message: 54 | "Invalid template argument \(error)") 55 | default: 56 | return pythonError 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Sources/JupyterKernel/SwiftPMEngine/ProcessTests.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | //===----------------------------------------------------------------------===// 4 | // Test Swift Packages (%test) 5 | //===----------------------------------------------------------------------===// 6 | 7 | func processTest( 8 | restOfLine: String, lineIndex: Int 9 | ) throws { 10 | let parsed = try PackageContext.shlexSplit(restOfLine, lineIndex) 11 | if parsed.count != 1 { 12 | var sentence: String 13 | if parsed.count == 0 { 14 | sentence = "Please enter a specification." 15 | } else { 16 | sentence = "Do not enter anything after the specification." 17 | } 18 | throw PreprocessorException(lineIndex: lineIndex, message: """ 19 | Usage: %test SPEC 20 | \(sentence) For more guidance, visit: 21 | https://github.com/philipturner/swift-colab/blob/main/Documentation/MagicCommands.md#test 22 | """) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Sources/JupyterKernel/third_party/TensorFlow/Core/Threading.swift: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) 16 | import Darwin 17 | #elseif os(Windows) 18 | import ucrt 19 | import WinSDK 20 | #else 21 | import Glibc 22 | #endif 23 | 24 | /// A portable mutex for synchronization of a shared resource. 25 | class Mutex { 26 | #if os(Windows) 27 | typealias MutexType = SRWLOCK 28 | #else 29 | typealias MutexType = pthread_mutex_t 30 | #endif 31 | 32 | var _mutex: MutexType 33 | 34 | init() { 35 | _mutex = MutexType() 36 | #if os(Windows) 37 | InitializeSRWLock(&_mutex) 38 | #else 39 | pthread_mutex_init(&_mutex, nil) 40 | #endif 41 | } 42 | 43 | deinit { 44 | #if os(Windows) 45 | // SRWLOCKs do not need explicit destruction 46 | #else 47 | pthread_mutex_destroy(&_mutex) 48 | #endif 49 | } 50 | 51 | // Acquire the mutex. 52 | // 53 | // Calling this function will block until it is safe to access the resource 54 | // that the mutex is protecting, locking the mutex indicating ownership of 55 | // the shared resource. 56 | // 57 | // Returns 0 on success. 58 | func acquire() -> Int32 { 59 | #if os(Windows) 60 | AcquireSRWLockExclusive(&_mutex) 61 | return 0 62 | #else 63 | return pthread_mutex_lock(&_mutex) 64 | #endif 65 | } 66 | 67 | // Release the mutex. 68 | // 69 | // Calling this function unlocks the mutex, relinquishing control of the 70 | // shared resource. 71 | // 72 | // Returns 0 on success. 73 | func release() -> Int32 { 74 | #if os(Windows) 75 | ReleaseSRWLockExclusive(&_mutex) 76 | return 0 77 | #else 78 | return pthread_mutex_unlock(&_mutex) 79 | #endif 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/LLDB.h: -------------------------------------------------------------------------------- 1 | //===-- LLDB.h --------------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_LLDB_H 10 | #define LLDB_API_LLDB_H 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 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 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | #include 72 | #include 73 | #include 74 | #include 75 | #include 76 | #include 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | 83 | #endif // LLDB_API_LLDB_H 84 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBAddress.h: -------------------------------------------------------------------------------- 1 | //===-- SBAddress.h ---------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBADDRESS_H 10 | #define LLDB_API_SBADDRESS_H 11 | 12 | #include 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBAddress { 18 | public: 19 | SBAddress(); 20 | 21 | SBAddress(const lldb::SBAddress &rhs); 22 | 23 | SBAddress(lldb::SBSection section, lldb::addr_t offset); 24 | 25 | // Create an address by resolving a load address using the supplied target 26 | SBAddress(lldb::addr_t load_addr, lldb::SBTarget &target); 27 | 28 | ~SBAddress(); 29 | 30 | const lldb::SBAddress &operator=(const lldb::SBAddress &rhs); 31 | 32 | explicit operator bool() const; 33 | 34 | // operator== is a free function 35 | 36 | bool operator!=(const SBAddress &rhs) const; 37 | 38 | bool IsValid() const; 39 | 40 | void Clear(); 41 | 42 | addr_t GetFileAddress() const; 43 | 44 | addr_t GetLoadAddress(const lldb::SBTarget &target) const; 45 | 46 | void SetAddress(lldb::SBSection section, lldb::addr_t offset); 47 | 48 | void SetLoadAddress(lldb::addr_t load_addr, lldb::SBTarget &target); 49 | bool OffsetAddress(addr_t offset); 50 | 51 | bool GetDescription(lldb::SBStream &description); 52 | 53 | // The following queries can lookup symbol information for a given address. 54 | // An address might refer to code or data from an existing module, or it 55 | // might refer to something on the stack or heap. The following functions 56 | // will only return valid values if the address has been resolved to a code 57 | // or data address using "void SBAddress::SetLoadAddress(...)" or 58 | // "lldb::SBAddress SBTarget::ResolveLoadAddress (...)". 59 | lldb::SBSymbolContext GetSymbolContext(uint32_t resolve_scope); 60 | 61 | // The following functions grab individual objects for a given address and 62 | // are less efficient if you want more than one symbol related objects. Use 63 | // one of the following when you want multiple debug symbol related objects 64 | // for an address: 65 | // lldb::SBSymbolContext SBAddress::GetSymbolContext (uint32_t 66 | // resolve_scope); 67 | // lldb::SBSymbolContext SBTarget::ResolveSymbolContextForAddress (const 68 | // SBAddress &addr, uint32_t resolve_scope); 69 | // One or more bits from the SymbolContextItem enumerations can be logically 70 | // OR'ed together to more efficiently retrieve multiple symbol objects. 71 | 72 | lldb::SBSection GetSection(); 73 | 74 | lldb::addr_t GetOffset(); 75 | 76 | lldb::SBModule GetModule(); 77 | 78 | lldb::SBCompileUnit GetCompileUnit(); 79 | 80 | lldb::SBFunction GetFunction(); 81 | 82 | lldb::SBBlock GetBlock(); 83 | 84 | lldb::SBSymbol GetSymbol(); 85 | 86 | lldb::SBLineEntry GetLineEntry(); 87 | 88 | protected: 89 | friend class SBBlock; 90 | friend class SBBreakpoint; 91 | friend class SBBreakpointLocation; 92 | friend class SBFrame; 93 | friend class SBFunction; 94 | friend class SBLineEntry; 95 | friend class SBInstruction; 96 | friend class SBModule; 97 | friend class SBSection; 98 | friend class SBSymbol; 99 | friend class SBSymbolContext; 100 | friend class SBTarget; 101 | friend class SBThread; 102 | friend class SBThreadPlan; 103 | friend class SBValue; 104 | friend class SBQueueItem; 105 | 106 | lldb_private::Address *operator->(); 107 | 108 | const lldb_private::Address *operator->() const; 109 | 110 | friend bool LLDB_API operator==(const SBAddress &lhs, const SBAddress &rhs); 111 | 112 | lldb_private::Address *get(); 113 | 114 | lldb_private::Address &ref(); 115 | 116 | const lldb_private::Address &ref() const; 117 | 118 | SBAddress(const lldb_private::Address &address); 119 | 120 | void SetAddress(const lldb_private::Address &address); 121 | 122 | private: 123 | std::unique_ptr m_opaque_up; 124 | }; 125 | 126 | bool LLDB_API operator==(const SBAddress &lhs, const SBAddress &rhs); 127 | 128 | } // namespace lldb 129 | 130 | #endif // LLDB_API_SBADDRESS_H 131 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBBlock.h: -------------------------------------------------------------------------------- 1 | //===-- SBBlock.h -----------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBBLOCK_H 10 | #define LLDB_API_SBBLOCK_H 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace lldb { 18 | 19 | class LLDB_API SBBlock { 20 | public: 21 | SBBlock(); 22 | 23 | SBBlock(const lldb::SBBlock &rhs); 24 | 25 | ~SBBlock(); 26 | 27 | const lldb::SBBlock &operator=(const lldb::SBBlock &rhs); 28 | 29 | bool IsInlined() const; 30 | 31 | explicit operator bool() const; 32 | 33 | bool IsValid() const; 34 | 35 | const char *GetInlinedName() const; 36 | 37 | lldb::SBFileSpec GetInlinedCallSiteFile() const; 38 | 39 | uint32_t GetInlinedCallSiteLine() const; 40 | 41 | uint32_t GetInlinedCallSiteColumn() const; 42 | 43 | lldb::SBBlock GetParent(); 44 | 45 | lldb::SBBlock GetSibling(); 46 | 47 | lldb::SBBlock GetFirstChild(); 48 | 49 | uint32_t GetNumRanges(); 50 | 51 | lldb::SBAddress GetRangeStartAddress(uint32_t idx); 52 | 53 | lldb::SBAddress GetRangeEndAddress(uint32_t idx); 54 | 55 | uint32_t GetRangeIndexForBlockAddress(lldb::SBAddress block_addr); 56 | 57 | lldb::SBValueList GetVariables(lldb::SBFrame &frame, bool arguments, 58 | bool locals, bool statics, 59 | lldb::DynamicValueType use_dynamic); 60 | 61 | lldb::SBValueList GetVariables(lldb::SBTarget &target, bool arguments, 62 | bool locals, bool statics); 63 | /// Get the inlined block that contains this block. 64 | /// 65 | /// \return 66 | /// If this block is inlined, it will return this block, else 67 | /// parent blocks will be searched to see if any contain this 68 | /// block and are themselves inlined. An invalid SBBlock will 69 | /// be returned if this block nor any parent blocks are inlined 70 | /// function blocks. 71 | lldb::SBBlock GetContainingInlinedBlock(); 72 | 73 | bool GetDescription(lldb::SBStream &description); 74 | 75 | private: 76 | friend class SBAddress; 77 | friend class SBFrame; 78 | friend class SBFunction; 79 | friend class SBSymbolContext; 80 | 81 | lldb_private::Block *GetPtr(); 82 | 83 | void SetPtr(lldb_private::Block *lldb_object_ptr); 84 | 85 | SBBlock(lldb_private::Block *lldb_object_ptr); 86 | 87 | void AppendVariables(bool can_create, bool get_parent_variables, 88 | lldb_private::VariableList *var_list); 89 | 90 | lldb_private::Block *m_opaque_ptr; 91 | }; 92 | 93 | } // namespace lldb 94 | 95 | #endif // LLDB_API_SBBLOCK_H 96 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBBreakpoint.h: -------------------------------------------------------------------------------- 1 | //===-- SBBreakpoint.h ------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBBREAKPOINT_H 10 | #define LLDB_API_SBBREAKPOINT_H 11 | 12 | #include 13 | 14 | class SBBreakpointListImpl; 15 | 16 | namespace lldb { 17 | 18 | class LLDB_API SBBreakpoint { 19 | public: 20 | 21 | SBBreakpoint(); 22 | 23 | SBBreakpoint(const lldb::SBBreakpoint &rhs); 24 | 25 | SBBreakpoint(const lldb::BreakpointSP &bp_sp); 26 | 27 | ~SBBreakpoint(); 28 | 29 | const lldb::SBBreakpoint &operator=(const lldb::SBBreakpoint &rhs); 30 | 31 | // Tests to see if the opaque breakpoint object in this object matches the 32 | // opaque breakpoint object in "rhs". 33 | bool operator==(const lldb::SBBreakpoint &rhs); 34 | 35 | bool operator!=(const lldb::SBBreakpoint &rhs); 36 | 37 | break_id_t GetID() const; 38 | 39 | explicit operator bool() const; 40 | 41 | bool IsValid() const; 42 | 43 | void ClearAllBreakpointSites(); 44 | 45 | lldb::SBTarget GetTarget() const; 46 | 47 | lldb::SBBreakpointLocation FindLocationByAddress(lldb::addr_t vm_addr); 48 | 49 | lldb::break_id_t FindLocationIDByAddress(lldb::addr_t vm_addr); 50 | 51 | lldb::SBBreakpointLocation FindLocationByID(lldb::break_id_t bp_loc_id); 52 | 53 | lldb::SBBreakpointLocation GetLocationAtIndex(uint32_t index); 54 | 55 | void SetEnabled(bool enable); 56 | 57 | bool IsEnabled(); 58 | 59 | void SetOneShot(bool one_shot); 60 | 61 | bool IsOneShot() const; 62 | 63 | bool IsInternal(); 64 | 65 | uint32_t GetHitCount() const; 66 | 67 | void SetIgnoreCount(uint32_t count); 68 | 69 | uint32_t GetIgnoreCount() const; 70 | 71 | void SetCondition(const char *condition); 72 | 73 | const char *GetCondition(); 74 | 75 | void SetAutoContinue(bool auto_continue); 76 | 77 | bool GetAutoContinue(); 78 | 79 | void SetThreadID(lldb::tid_t sb_thread_id); 80 | 81 | lldb::tid_t GetThreadID(); 82 | 83 | void SetThreadIndex(uint32_t index); 84 | 85 | uint32_t GetThreadIndex() const; 86 | 87 | void SetThreadName(const char *thread_name); 88 | 89 | const char *GetThreadName() const; 90 | 91 | void SetQueueName(const char *queue_name); 92 | 93 | const char *GetQueueName() const; 94 | 95 | void SetCallback(SBBreakpointHitCallback callback, void *baton); 96 | 97 | void SetScriptCallbackFunction(const char *callback_function_name); 98 | 99 | SBError SetScriptCallbackFunction(const char *callback_function_name, 100 | SBStructuredData &extra_args); 101 | 102 | void SetCommandLineCommands(SBStringList &commands); 103 | 104 | bool GetCommandLineCommands(SBStringList &commands); 105 | 106 | SBError SetScriptCallbackBody(const char *script_body_text); 107 | 108 | bool AddName(const char *new_name); 109 | 110 | SBError AddNameWithErrorHandling(const char *new_name); 111 | 112 | void RemoveName(const char *name_to_remove); 113 | 114 | bool MatchesName(const char *name); 115 | 116 | void GetNames(SBStringList &names); 117 | 118 | size_t GetNumResolvedLocations() const; 119 | 120 | size_t GetNumLocations() const; 121 | 122 | bool GetDescription(lldb::SBStream &description); 123 | 124 | bool GetDescription(lldb::SBStream &description, bool include_locations); 125 | 126 | static bool EventIsBreakpointEvent(const lldb::SBEvent &event); 127 | 128 | static lldb::BreakpointEventType 129 | GetBreakpointEventTypeFromEvent(const lldb::SBEvent &event); 130 | 131 | static lldb::SBBreakpoint GetBreakpointFromEvent(const lldb::SBEvent &event); 132 | 133 | static lldb::SBBreakpointLocation 134 | GetBreakpointLocationAtIndexFromEvent(const lldb::SBEvent &event, 135 | uint32_t loc_idx); 136 | 137 | static uint32_t 138 | GetNumBreakpointLocationsFromEvent(const lldb::SBEvent &event_sp); 139 | 140 | bool IsHardware() const; 141 | 142 | // Can only be called from a ScriptedBreakpointResolver... 143 | SBError 144 | AddLocation(SBAddress &address); 145 | 146 | SBStructuredData SerializeToStructuredData(); 147 | 148 | private: 149 | friend class SBBreakpointList; 150 | friend class SBBreakpointLocation; 151 | friend class SBBreakpointName; 152 | friend class SBTarget; 153 | 154 | lldb::BreakpointSP GetSP() const; 155 | 156 | lldb::BreakpointWP m_opaque_wp; 157 | }; 158 | 159 | class LLDB_API SBBreakpointList { 160 | public: 161 | SBBreakpointList(SBTarget &target); 162 | 163 | ~SBBreakpointList(); 164 | 165 | size_t GetSize() const; 166 | 167 | SBBreakpoint GetBreakpointAtIndex(size_t idx); 168 | 169 | SBBreakpoint FindBreakpointByID(lldb::break_id_t); 170 | 171 | void Append(const SBBreakpoint &sb_bkpt); 172 | 173 | bool AppendIfUnique(const SBBreakpoint &sb_bkpt); 174 | 175 | void AppendByID(lldb::break_id_t id); 176 | 177 | void Clear(); 178 | 179 | protected: 180 | friend class SBTarget; 181 | 182 | void CopyToBreakpointIDList(lldb_private::BreakpointIDList &bp_id_list); 183 | 184 | private: 185 | std::shared_ptr m_opaque_sp; 186 | }; 187 | 188 | } // namespace lldb 189 | 190 | #endif // LLDB_API_SBBREAKPOINT_H 191 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBBreakpointLocation.h: -------------------------------------------------------------------------------- 1 | //===-- SBBreakpointLocation.h ----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBBREAKPOINTLOCATION_H 10 | #define LLDB_API_SBBREAKPOINTLOCATION_H 11 | 12 | #include 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBBreakpointLocation { 18 | public: 19 | SBBreakpointLocation(); 20 | 21 | SBBreakpointLocation(const lldb::SBBreakpointLocation &rhs); 22 | 23 | ~SBBreakpointLocation(); 24 | 25 | const lldb::SBBreakpointLocation & 26 | operator=(const lldb::SBBreakpointLocation &rhs); 27 | 28 | break_id_t GetID(); 29 | 30 | explicit operator bool() const; 31 | 32 | bool IsValid() const; 33 | 34 | lldb::SBAddress GetAddress(); 35 | 36 | lldb::addr_t GetLoadAddress(); 37 | 38 | void SetEnabled(bool enabled); 39 | 40 | bool IsEnabled(); 41 | 42 | uint32_t GetHitCount(); 43 | 44 | uint32_t GetIgnoreCount(); 45 | 46 | void SetIgnoreCount(uint32_t n); 47 | 48 | void SetCondition(const char *condition); 49 | 50 | const char *GetCondition(); 51 | 52 | void SetAutoContinue(bool auto_continue); 53 | 54 | bool GetAutoContinue(); 55 | 56 | void SetScriptCallbackFunction(const char *callback_function_name); 57 | 58 | SBError SetScriptCallbackFunction(const char *callback_function_name, 59 | lldb::SBStructuredData &extra_args); 60 | 61 | SBError SetScriptCallbackBody(const char *script_body_text); 62 | 63 | void SetCommandLineCommands(lldb::SBStringList &commands); 64 | 65 | bool GetCommandLineCommands(lldb::SBStringList &commands); 66 | 67 | void SetThreadID(lldb::tid_t sb_thread_id); 68 | 69 | lldb::tid_t GetThreadID(); 70 | 71 | void SetThreadIndex(uint32_t index); 72 | 73 | uint32_t GetThreadIndex() const; 74 | 75 | void SetThreadName(const char *thread_name); 76 | 77 | const char *GetThreadName() const; 78 | 79 | void SetQueueName(const char *queue_name); 80 | 81 | const char *GetQueueName() const; 82 | 83 | bool IsResolved(); 84 | 85 | bool GetDescription(lldb::SBStream &description, DescriptionLevel level); 86 | 87 | SBBreakpoint GetBreakpoint(); 88 | 89 | SBBreakpointLocation(const lldb::BreakpointLocationSP &break_loc_sp); 90 | 91 | private: 92 | friend class SBBreakpoint; 93 | friend class SBBreakpointCallbackBaton; 94 | 95 | void SetLocation(const lldb::BreakpointLocationSP &break_loc_sp); 96 | BreakpointLocationSP GetSP() const; 97 | 98 | lldb::BreakpointLocationWP m_opaque_wp; 99 | }; 100 | 101 | } // namespace lldb 102 | 103 | #endif // LLDB_API_SBBREAKPOINTLOCATION_H 104 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBBreakpointName.h: -------------------------------------------------------------------------------- 1 | //===-- SBBreakpointName.h ------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBBREAKPOINTNAME_H 10 | #define LLDB_API_SBBREAKPOINTNAME_H 11 | 12 | #include 13 | 14 | class SBBreakpointNameImpl; 15 | 16 | namespace lldb { 17 | 18 | class LLDB_API SBBreakpointName { 19 | public: 20 | // typedef bool (*BreakpointHitCallback)(void *baton, SBProcess &process, 21 | // SBThread &thread, 22 | // lldb::SBBreakpointLocation &location); 23 | 24 | SBBreakpointName(); 25 | 26 | SBBreakpointName(SBTarget &target, const char *name); 27 | 28 | SBBreakpointName(SBBreakpoint &bkpt, const char *name); 29 | 30 | SBBreakpointName(const lldb::SBBreakpointName &rhs); 31 | 32 | ~SBBreakpointName(); 33 | 34 | const lldb::SBBreakpointName &operator=(const lldb::SBBreakpointName &rhs); 35 | 36 | // Tests to see if the opaque breakpoint object in this object matches the 37 | // opaque breakpoint object in "rhs". 38 | bool operator==(const lldb::SBBreakpointName &rhs); 39 | 40 | bool operator!=(const lldb::SBBreakpointName &rhs); 41 | 42 | explicit operator bool() const; 43 | 44 | bool IsValid() const; 45 | 46 | const char *GetName() const; 47 | 48 | void SetEnabled(bool enable); 49 | 50 | bool IsEnabled(); 51 | 52 | void SetOneShot(bool one_shot); 53 | 54 | bool IsOneShot() const; 55 | 56 | void SetIgnoreCount(uint32_t count); 57 | 58 | uint32_t GetIgnoreCount() const; 59 | 60 | void SetCondition(const char *condition); 61 | 62 | const char *GetCondition(); 63 | 64 | void SetAutoContinue(bool auto_continue); 65 | 66 | bool GetAutoContinue(); 67 | 68 | void SetThreadID(lldb::tid_t sb_thread_id); 69 | 70 | lldb::tid_t GetThreadID(); 71 | 72 | void SetThreadIndex(uint32_t index); 73 | 74 | uint32_t GetThreadIndex() const; 75 | 76 | void SetThreadName(const char *thread_name); 77 | 78 | const char *GetThreadName() const; 79 | 80 | void SetQueueName(const char *queue_name); 81 | 82 | const char *GetQueueName() const; 83 | 84 | void SetCallback(SBBreakpointHitCallback callback, void *baton); 85 | 86 | void SetScriptCallbackFunction(const char *callback_function_name); 87 | 88 | SBError SetScriptCallbackFunction(const char *callback_function_name, 89 | SBStructuredData &extra_args); 90 | 91 | void SetCommandLineCommands(lldb::SBStringList &commands); 92 | 93 | bool GetCommandLineCommands(lldb::SBStringList &commands); 94 | 95 | SBError SetScriptCallbackBody(const char *script_body_text); 96 | 97 | const char *GetHelpString() const; 98 | void SetHelpString(const char *help_string); 99 | 100 | bool GetAllowList() const; 101 | void SetAllowList(bool value); 102 | 103 | bool GetAllowDelete(); 104 | void SetAllowDelete(bool value); 105 | 106 | bool GetAllowDisable(); 107 | void SetAllowDisable(bool value); 108 | 109 | bool GetDescription(lldb::SBStream &description); 110 | 111 | private: 112 | friend class SBTarget; 113 | 114 | lldb_private::BreakpointName *GetBreakpointName() const; 115 | void UpdateName(lldb_private::BreakpointName &bp_name); 116 | 117 | std::unique_ptr m_impl_up; 118 | }; 119 | 120 | } // namespace lldb 121 | 122 | #endif // LLDB_API_SBBREAKPOINTNAME_H 123 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBBroadcaster.h: -------------------------------------------------------------------------------- 1 | //===-- SBBroadcaster.h -----------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBBROADCASTER_H 10 | #define LLDB_API_SBBROADCASTER_H 11 | 12 | #include 13 | 14 | namespace lldb { 15 | 16 | class LLDB_API SBBroadcaster { 17 | public: 18 | SBBroadcaster(); 19 | 20 | SBBroadcaster(const char *name); 21 | 22 | SBBroadcaster(const SBBroadcaster &rhs); 23 | 24 | const SBBroadcaster &operator=(const SBBroadcaster &rhs); 25 | 26 | ~SBBroadcaster(); 27 | 28 | explicit operator bool() const; 29 | 30 | bool IsValid() const; 31 | 32 | void Clear(); 33 | 34 | void BroadcastEventByType(uint32_t event_type, bool unique = false); 35 | 36 | void BroadcastEvent(const lldb::SBEvent &event, bool unique = false); 37 | 38 | void AddInitialEventsToListener(const lldb::SBListener &listener, 39 | uint32_t requested_events); 40 | 41 | uint32_t AddListener(const lldb::SBListener &listener, uint32_t event_mask); 42 | 43 | const char *GetName() const; 44 | 45 | bool EventTypeHasListeners(uint32_t event_type); 46 | 47 | bool RemoveListener(const lldb::SBListener &listener, 48 | uint32_t event_mask = UINT32_MAX); 49 | 50 | // This comparison is checking if the internal opaque pointer value is equal 51 | // to that in "rhs". 52 | bool operator==(const lldb::SBBroadcaster &rhs) const; 53 | 54 | // This comparison is checking if the internal opaque pointer value is not 55 | // equal to that in "rhs". 56 | bool operator!=(const lldb::SBBroadcaster &rhs) const; 57 | 58 | // This comparison is checking if the internal opaque pointer value is less 59 | // than that in "rhs" so SBBroadcaster objects can be contained in ordered 60 | // containers. 61 | bool operator<(const lldb::SBBroadcaster &rhs) const; 62 | 63 | protected: 64 | friend class SBCommandInterpreter; 65 | friend class SBCommunication; 66 | friend class SBEvent; 67 | friend class SBListener; 68 | friend class SBProcess; 69 | friend class SBTarget; 70 | 71 | SBBroadcaster(lldb_private::Broadcaster *broadcaster, bool owns); 72 | 73 | lldb_private::Broadcaster *get() const; 74 | 75 | void reset(lldb_private::Broadcaster *broadcaster, bool owns); 76 | 77 | private: 78 | lldb::BroadcasterSP m_opaque_sp; 79 | lldb_private::Broadcaster *m_opaque_ptr; 80 | }; 81 | 82 | } // namespace lldb 83 | 84 | #endif // LLDB_API_SBBROADCASTER_H 85 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBCommandInterpreterRunOptions.h: -------------------------------------------------------------------------------- 1 | //===-- SBCommandInterpreterRunOptions.h ------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBCOMMANDINTERPRETERRUNOPTIONS_H 10 | #define LLDB_API_SBCOMMANDINTERPRETERRUNOPTIONS_H 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace lldb_private { 17 | class CommandInterpreterRunOptions; 18 | class CommandInterpreterRunResult; 19 | } // namespace lldb_private 20 | 21 | namespace lldb { 22 | 23 | class LLDB_API SBCommandInterpreterRunOptions { 24 | friend class SBDebugger; 25 | friend class SBCommandInterpreter; 26 | 27 | public: 28 | SBCommandInterpreterRunOptions(); 29 | SBCommandInterpreterRunOptions(const SBCommandInterpreterRunOptions &rhs); 30 | ~SBCommandInterpreterRunOptions(); 31 | 32 | SBCommandInterpreterRunOptions & 33 | operator=(const SBCommandInterpreterRunOptions &rhs); 34 | 35 | bool GetStopOnContinue() const; 36 | 37 | void SetStopOnContinue(bool); 38 | 39 | bool GetStopOnError() const; 40 | 41 | void SetStopOnError(bool); 42 | 43 | bool GetStopOnCrash() const; 44 | 45 | void SetStopOnCrash(bool); 46 | 47 | bool GetEchoCommands() const; 48 | 49 | void SetEchoCommands(bool); 50 | 51 | bool GetEchoCommentCommands() const; 52 | 53 | void SetEchoCommentCommands(bool echo); 54 | 55 | bool GetPrintResults() const; 56 | 57 | void SetPrintResults(bool); 58 | 59 | bool GetPrintErrors() const; 60 | 61 | void SetPrintErrors(bool); 62 | 63 | bool GetAddToHistory() const; 64 | 65 | void SetAddToHistory(bool); 66 | 67 | bool GetAutoHandleEvents() const; 68 | 69 | void SetAutoHandleEvents(bool); 70 | 71 | bool GetSpawnThread() const; 72 | 73 | void SetSpawnThread(bool); 74 | 75 | private: 76 | lldb_private::CommandInterpreterRunOptions *get() const; 77 | 78 | lldb_private::CommandInterpreterRunOptions &ref() const; 79 | 80 | // This is set in the constructor and will always be valid. 81 | mutable std::unique_ptr 82 | m_opaque_up; 83 | }; 84 | 85 | class LLDB_API SBCommandInterpreterRunResult { 86 | friend class SBDebugger; 87 | friend class SBCommandInterpreter; 88 | 89 | public: 90 | SBCommandInterpreterRunResult(); 91 | SBCommandInterpreterRunResult(const SBCommandInterpreterRunResult &rhs); 92 | ~SBCommandInterpreterRunResult(); 93 | 94 | SBCommandInterpreterRunResult & 95 | operator=(const SBCommandInterpreterRunResult &rhs); 96 | 97 | int GetNumberOfErrors() const; 98 | lldb::CommandInterpreterResult GetResult() const; 99 | 100 | private: 101 | SBCommandInterpreterRunResult( 102 | const lldb_private::CommandInterpreterRunResult &rhs); 103 | 104 | // This is set in the constructor and will always be valid. 105 | std::unique_ptr m_opaque_up; 106 | }; 107 | 108 | } // namespace lldb 109 | 110 | #endif // LLDB_API_SBCOMMANDINTERPRETERRUNOPTIONS_H 111 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBCommandReturnObject.h: -------------------------------------------------------------------------------- 1 | //===-- SBCommandReturnObject.h ---------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBCOMMANDRETURNOBJECT_H 10 | #define LLDB_API_SBCOMMANDRETURNOBJECT_H 11 | 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace lldb_private { 19 | class SBCommandReturnObjectImpl; 20 | } 21 | 22 | namespace lldb { 23 | 24 | class LLDB_API SBCommandReturnObject { 25 | public: 26 | SBCommandReturnObject(); 27 | 28 | SBCommandReturnObject(lldb_private::CommandReturnObject &ref); 29 | 30 | // rvalue ctor+assignment are incompatible with Reproducers. 31 | 32 | SBCommandReturnObject(const lldb::SBCommandReturnObject &rhs); 33 | 34 | ~SBCommandReturnObject(); 35 | 36 | lldb::SBCommandReturnObject & 37 | operator=(const lldb::SBCommandReturnObject &rhs); 38 | 39 | explicit operator bool() const; 40 | 41 | bool IsValid() const; 42 | 43 | const char *GetOutput(); 44 | 45 | const char *GetError(); 46 | 47 | size_t PutOutput(FILE *fh); // DEPRECATED 48 | 49 | size_t PutOutput(SBFile file); 50 | 51 | size_t PutOutput(FileSP file); 52 | 53 | size_t GetOutputSize(); 54 | 55 | size_t GetErrorSize(); 56 | 57 | size_t PutError(FILE *fh); // DEPRECATED 58 | 59 | size_t PutError(SBFile file); 60 | 61 | size_t PutError(FileSP file); 62 | 63 | void Clear(); 64 | 65 | lldb::ReturnStatus GetStatus(); 66 | 67 | void SetStatus(lldb::ReturnStatus status); 68 | 69 | bool Succeeded(); 70 | 71 | bool HasResult(); 72 | 73 | void AppendMessage(const char *message); 74 | 75 | void AppendWarning(const char *message); 76 | 77 | bool GetDescription(lldb::SBStream &description); 78 | 79 | void SetImmediateOutputFile(FILE *fh); // DEPRECATED 80 | 81 | void SetImmediateErrorFile(FILE *fh); // DEPRECATED 82 | 83 | void SetImmediateOutputFile(FILE *fh, bool transfer_ownership); // DEPRECATED 84 | 85 | void SetImmediateErrorFile(FILE *fh, bool transfer_ownership); // DEPRECATED 86 | 87 | void SetImmediateOutputFile(SBFile file); 88 | 89 | void SetImmediateErrorFile(SBFile file); 90 | 91 | void SetImmediateOutputFile(FileSP file); 92 | 93 | void SetImmediateErrorFile(FileSP file); 94 | 95 | void PutCString(const char *string, int len = -1); 96 | 97 | size_t Printf(const char *format, ...) __attribute__((format(printf, 2, 3))); 98 | 99 | const char *GetOutput(bool only_if_no_immediate); 100 | 101 | const char *GetError(bool only_if_no_immediate); 102 | 103 | void SetError(lldb::SBError &error, 104 | const char *fallback_error_cstr = nullptr); 105 | 106 | void SetError(const char *error_cstr); 107 | 108 | // ref() is internal for LLDB only. 109 | lldb_private::CommandReturnObject &ref() const; 110 | 111 | protected: 112 | friend class SBCommandInterpreter; 113 | friend class SBOptions; 114 | 115 | lldb_private::CommandReturnObject *operator->() const; 116 | 117 | lldb_private::CommandReturnObject *get() const; 118 | 119 | lldb_private::CommandReturnObject &operator*() const; 120 | 121 | private: 122 | std::unique_ptr m_opaque_up; 123 | }; 124 | 125 | } // namespace lldb 126 | 127 | #endif // LLDB_API_SBCOMMANDRETURNOBJECT_H 128 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBCommunication.h: -------------------------------------------------------------------------------- 1 | //===-- SBCommunication.h ---------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBCOMMUNICATION_H 10 | #define LLDB_API_SBCOMMUNICATION_H 11 | 12 | #include 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBCommunication { 18 | public: 19 | FLAGS_ANONYMOUS_ENUM(){ 20 | eBroadcastBitDisconnected = 21 | (1 << 0), ///< Sent when the communications connection is lost. 22 | eBroadcastBitReadThreadGotBytes = 23 | (1 << 1), ///< Sent by the read thread when bytes become available. 24 | eBroadcastBitReadThreadDidExit = 25 | (1 26 | << 2), ///< Sent by the read thread when it exits to inform clients. 27 | eBroadcastBitReadThreadShouldExit = 28 | (1 << 3), ///< Sent by clients that need to cancel the read thread. 29 | eBroadcastBitPacketAvailable = 30 | (1 << 4), ///< Sent when data received makes a complete packet. 31 | eAllEventBits = 0xffffffff}; 32 | 33 | typedef void (*ReadThreadBytesReceived)(void *baton, const void *src, 34 | size_t src_len); 35 | 36 | SBCommunication(); 37 | SBCommunication(const char *broadcaster_name); 38 | ~SBCommunication(); 39 | 40 | explicit operator bool() const; 41 | 42 | bool IsValid() const; 43 | 44 | lldb::SBBroadcaster GetBroadcaster(); 45 | 46 | static const char *GetBroadcasterClass(); 47 | 48 | lldb::ConnectionStatus AdoptFileDesriptor(int fd, bool owns_fd); 49 | 50 | lldb::ConnectionStatus Connect(const char *url); 51 | 52 | lldb::ConnectionStatus Disconnect(); 53 | 54 | bool IsConnected() const; 55 | 56 | bool GetCloseOnEOF(); 57 | 58 | void SetCloseOnEOF(bool b); 59 | 60 | size_t Read(void *dst, size_t dst_len, uint32_t timeout_usec, 61 | lldb::ConnectionStatus &status); 62 | 63 | size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status); 64 | 65 | bool ReadThreadStart(); 66 | 67 | bool ReadThreadStop(); 68 | 69 | bool ReadThreadIsRunning(); 70 | 71 | bool SetReadThreadBytesReceivedCallback(ReadThreadBytesReceived callback, 72 | void *callback_baton); 73 | 74 | private: 75 | SBCommunication(const SBCommunication &) = delete; 76 | const SBCommunication &operator=(const SBCommunication &) = delete; 77 | 78 | lldb_private::Communication *m_opaque; 79 | bool m_opaque_owned; 80 | }; 81 | 82 | } // namespace lldb 83 | 84 | #endif // LLDB_API_SBCOMMUNICATION_H 85 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBCompileUnit.h: -------------------------------------------------------------------------------- 1 | //===-- SBCompileUnit.h -----------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBCOMPILEUNIT_H 10 | #define LLDB_API_SBCOMPILEUNIT_H 11 | 12 | #include 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBCompileUnit { 18 | public: 19 | SBCompileUnit(); 20 | 21 | SBCompileUnit(const lldb::SBCompileUnit &rhs); 22 | 23 | ~SBCompileUnit(); 24 | 25 | const lldb::SBCompileUnit &operator=(const lldb::SBCompileUnit &rhs); 26 | 27 | explicit operator bool() const; 28 | 29 | bool IsValid() const; 30 | 31 | lldb::SBFileSpec GetFileSpec() const; 32 | 33 | uint32_t GetNumLineEntries() const; 34 | 35 | lldb::SBLineEntry GetLineEntryAtIndex(uint32_t idx) const; 36 | 37 | uint32_t FindLineEntryIndex(uint32_t start_idx, uint32_t line, 38 | lldb::SBFileSpec *inline_file_spec) const; 39 | 40 | uint32_t FindLineEntryIndex(uint32_t start_idx, uint32_t line, 41 | lldb::SBFileSpec *inline_file_spec, 42 | bool exact) const; 43 | 44 | SBFileSpec GetSupportFileAtIndex(uint32_t idx) const; 45 | 46 | uint32_t GetNumSupportFiles() const; 47 | 48 | uint32_t FindSupportFileIndex(uint32_t start_idx, const SBFileSpec &sb_file, 49 | bool full); 50 | 51 | /// Get all types matching \a type_mask from debug info in this 52 | /// compile unit. 53 | /// 54 | /// \param[in] type_mask 55 | /// A bitfield that consists of one or more bits logically OR'ed 56 | /// together from the lldb::TypeClass enumeration. This allows 57 | /// you to request only structure types, or only class, struct 58 | /// and union types. Passing in lldb::eTypeClassAny will return 59 | /// all types found in the debug information for this compile 60 | /// unit. 61 | /// 62 | /// \return 63 | /// A list of types in this compile unit that match \a type_mask 64 | lldb::SBTypeList GetTypes(uint32_t type_mask = lldb::eTypeClassAny); 65 | 66 | lldb::LanguageType GetLanguage(); 67 | 68 | bool operator==(const lldb::SBCompileUnit &rhs) const; 69 | 70 | bool operator!=(const lldb::SBCompileUnit &rhs) const; 71 | 72 | bool GetDescription(lldb::SBStream &description); 73 | 74 | private: 75 | friend class SBAddress; 76 | friend class SBFrame; 77 | friend class SBSymbolContext; 78 | friend class SBModule; 79 | 80 | SBCompileUnit(lldb_private::CompileUnit *lldb_object_ptr); 81 | 82 | const lldb_private::CompileUnit *operator->() const; 83 | 84 | const lldb_private::CompileUnit &operator*() const; 85 | 86 | lldb_private::CompileUnit *get(); 87 | 88 | void reset(lldb_private::CompileUnit *lldb_object_ptr); 89 | 90 | lldb_private::CompileUnit *m_opaque_ptr; 91 | }; 92 | 93 | } // namespace lldb 94 | 95 | #endif // LLDB_API_SBCOMPILEUNIT_H 96 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBData.h: -------------------------------------------------------------------------------- 1 | //===-- SBData.h -----------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBDATA_H 10 | #define LLDB_API_SBDATA_H 11 | 12 | #include 13 | 14 | namespace lldb { 15 | 16 | class LLDB_API SBData { 17 | public: 18 | SBData(); 19 | 20 | SBData(const SBData &rhs); 21 | 22 | const SBData &operator=(const SBData &rhs); 23 | 24 | ~SBData(); 25 | 26 | uint8_t GetAddressByteSize(); 27 | 28 | void SetAddressByteSize(uint8_t addr_byte_size); 29 | 30 | void Clear(); 31 | 32 | explicit operator bool() const; 33 | 34 | bool IsValid(); 35 | 36 | size_t GetByteSize(); 37 | 38 | lldb::ByteOrder GetByteOrder(); 39 | 40 | void SetByteOrder(lldb::ByteOrder endian); 41 | 42 | float GetFloat(lldb::SBError &error, lldb::offset_t offset); 43 | 44 | double GetDouble(lldb::SBError &error, lldb::offset_t offset); 45 | 46 | long double GetLongDouble(lldb::SBError &error, lldb::offset_t offset); 47 | 48 | lldb::addr_t GetAddress(lldb::SBError &error, lldb::offset_t offset); 49 | 50 | uint8_t GetUnsignedInt8(lldb::SBError &error, lldb::offset_t offset); 51 | 52 | uint16_t GetUnsignedInt16(lldb::SBError &error, lldb::offset_t offset); 53 | 54 | uint32_t GetUnsignedInt32(lldb::SBError &error, lldb::offset_t offset); 55 | 56 | uint64_t GetUnsignedInt64(lldb::SBError &error, lldb::offset_t offset); 57 | 58 | int8_t GetSignedInt8(lldb::SBError &error, lldb::offset_t offset); 59 | 60 | int16_t GetSignedInt16(lldb::SBError &error, lldb::offset_t offset); 61 | 62 | int32_t GetSignedInt32(lldb::SBError &error, lldb::offset_t offset); 63 | 64 | int64_t GetSignedInt64(lldb::SBError &error, lldb::offset_t offset); 65 | 66 | const char *GetString(lldb::SBError &error, lldb::offset_t offset); 67 | 68 | size_t ReadRawData(lldb::SBError &error, lldb::offset_t offset, void *buf, 69 | size_t size); 70 | 71 | bool GetDescription(lldb::SBStream &description, 72 | lldb::addr_t base_addr = LLDB_INVALID_ADDRESS); 73 | 74 | // it would be nice to have SetData(SBError, const void*, size_t) when 75 | // endianness and address size can be inferred from the existing 76 | // DataExtractor, but having two SetData() signatures triggers a SWIG bug 77 | // where the typemap isn't applied before resolving the overload, and thus 78 | // the right function never gets called 79 | void SetData(lldb::SBError &error, const void *buf, size_t size, 80 | lldb::ByteOrder endian, uint8_t addr_size); 81 | 82 | // see SetData() for why we don't have Append(const void* buf, size_t size) 83 | bool Append(const SBData &rhs); 84 | 85 | static lldb::SBData CreateDataFromCString(lldb::ByteOrder endian, 86 | uint32_t addr_byte_size, 87 | const char *data); 88 | 89 | // in the following CreateData*() and SetData*() prototypes, the two 90 | // parameters array and array_len should not be renamed or rearranged, 91 | // because doing so will break the SWIG typemap 92 | static lldb::SBData CreateDataFromUInt64Array(lldb::ByteOrder endian, 93 | uint32_t addr_byte_size, 94 | uint64_t *array, 95 | size_t array_len); 96 | 97 | static lldb::SBData CreateDataFromUInt32Array(lldb::ByteOrder endian, 98 | uint32_t addr_byte_size, 99 | uint32_t *array, 100 | size_t array_len); 101 | 102 | static lldb::SBData CreateDataFromSInt64Array(lldb::ByteOrder endian, 103 | uint32_t addr_byte_size, 104 | int64_t *array, 105 | size_t array_len); 106 | 107 | static lldb::SBData CreateDataFromSInt32Array(lldb::ByteOrder endian, 108 | uint32_t addr_byte_size, 109 | int32_t *array, 110 | size_t array_len); 111 | 112 | static lldb::SBData CreateDataFromDoubleArray(lldb::ByteOrder endian, 113 | uint32_t addr_byte_size, 114 | double *array, 115 | size_t array_len); 116 | 117 | bool SetDataFromCString(const char *data); 118 | 119 | bool SetDataFromUInt64Array(uint64_t *array, size_t array_len); 120 | 121 | bool SetDataFromUInt32Array(uint32_t *array, size_t array_len); 122 | 123 | bool SetDataFromSInt64Array(int64_t *array, size_t array_len); 124 | 125 | bool SetDataFromSInt32Array(int32_t *array, size_t array_len); 126 | 127 | bool SetDataFromDoubleArray(double *array, size_t array_len); 128 | 129 | protected: 130 | // Mimic shared pointer... 131 | lldb_private::DataExtractor *get() const; 132 | 133 | lldb_private::DataExtractor *operator->() const; 134 | 135 | lldb::DataExtractorSP &operator*(); 136 | 137 | const lldb::DataExtractorSP &operator*() const; 138 | 139 | SBData(const lldb::DataExtractorSP &data_sp); 140 | 141 | void SetOpaque(const lldb::DataExtractorSP &data_sp); 142 | 143 | private: 144 | friend class SBInstruction; 145 | friend class SBProcess; 146 | friend class SBSection; 147 | friend class SBTarget; 148 | friend class SBValue; 149 | 150 | lldb::DataExtractorSP m_opaque_sp; 151 | }; 152 | 153 | } // namespace lldb 154 | 155 | #endif // LLDB_API_SBDATA_H 156 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBDeclaration.h: -------------------------------------------------------------------------------- 1 | //===-- SBDeclaration.h -------------------------------------------*- C++ 2 | //-*-===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLDB_API_SBDECLARATION_H 11 | #define LLDB_API_SBDECLARATION_H 12 | 13 | #include 14 | #include 15 | 16 | namespace lldb { 17 | 18 | class LLDB_API SBDeclaration { 19 | public: 20 | SBDeclaration(); 21 | 22 | SBDeclaration(const lldb::SBDeclaration &rhs); 23 | 24 | ~SBDeclaration(); 25 | 26 | const lldb::SBDeclaration &operator=(const lldb::SBDeclaration &rhs); 27 | 28 | explicit operator bool() const; 29 | 30 | bool IsValid() const; 31 | 32 | lldb::SBFileSpec GetFileSpec() const; 33 | 34 | uint32_t GetLine() const; 35 | 36 | uint32_t GetColumn() const; 37 | 38 | void SetFileSpec(lldb::SBFileSpec filespec); 39 | 40 | void SetLine(uint32_t line); 41 | 42 | void SetColumn(uint32_t column); 43 | 44 | bool operator==(const lldb::SBDeclaration &rhs) const; 45 | 46 | bool operator!=(const lldb::SBDeclaration &rhs) const; 47 | 48 | bool GetDescription(lldb::SBStream &description); 49 | 50 | protected: 51 | lldb_private::Declaration *get(); 52 | 53 | private: 54 | friend class SBValue; 55 | 56 | const lldb_private::Declaration *operator->() const; 57 | 58 | lldb_private::Declaration &ref(); 59 | 60 | const lldb_private::Declaration &ref() const; 61 | 62 | SBDeclaration(const lldb_private::Declaration *lldb_object_ptr); 63 | 64 | void SetDeclaration(const lldb_private::Declaration &lldb_object_ref); 65 | 66 | std::unique_ptr m_opaque_up; 67 | }; 68 | 69 | } // namespace lldb 70 | 71 | #endif // LLDB_API_SBDECLARATION_H 72 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBDefines.h: -------------------------------------------------------------------------------- 1 | //===-- SBDefines.h ---------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBDEFINES_H 10 | #define LLDB_API_SBDEFINES_H 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | // Forward Declarations 19 | namespace lldb { 20 | 21 | class LLDB_API SBAddress; 22 | class LLDB_API SBBlock; 23 | class LLDB_API SBBreakpoint; 24 | class LLDB_API SBBreakpointLocation; 25 | class LLDB_API SBBreakpointName; 26 | class LLDB_API SBBreakpointNameImpl; 27 | class LLDB_API SBBroadcaster; 28 | class LLDB_API SBCommand; 29 | class LLDB_API SBCommandInterpreter; 30 | class LLDB_API SBCommandInterpreterRunOptions; 31 | class LLDB_API SBCommandInterpreterRunResult; 32 | class LLDB_API SBCommandPluginInterface; 33 | class LLDB_API SBCommandReturnObject; 34 | class LLDB_API SBCommunication; 35 | class LLDB_API SBCompileUnit; 36 | class LLDB_API SBData; 37 | class LLDB_API SBDebugger; 38 | class LLDB_API SBDeclaration; 39 | class LLDB_API SBEnvironment; 40 | class LLDB_API SBError; 41 | class LLDB_API SBEvent; 42 | class LLDB_API SBEventList; 43 | class LLDB_API SBExecutionContext; 44 | class LLDB_API SBExpressionOptions; 45 | class LLDB_API SBFile; 46 | class LLDB_API SBFileSpec; 47 | class LLDB_API SBFileSpecList; 48 | class LLDB_API SBFrame; 49 | class LLDB_API SBFunction; 50 | class LLDB_API SBHostOS; 51 | class LLDB_API SBInstruction; 52 | class LLDB_API SBInstructionList; 53 | class LLDB_API SBLanguageRuntime; 54 | class LLDB_API SBLaunchInfo; 55 | class LLDB_API SBLineEntry; 56 | class LLDB_API SBListener; 57 | class LLDB_API SBMemoryRegionInfo; 58 | class LLDB_API SBMemoryRegionInfoList; 59 | class LLDB_API SBModule; 60 | class LLDB_API SBModuleSpec; 61 | class LLDB_API SBModuleSpecList; 62 | class LLDB_API SBProcess; 63 | class LLDB_API SBProcessInfo; 64 | class LLDB_API SBQueue; 65 | class LLDB_API SBQueueItem; 66 | class LLDB_API SBSection; 67 | class LLDB_API SBSourceManager; 68 | class LLDB_API SBStream; 69 | class LLDB_API SBStringList; 70 | class LLDB_API SBStructuredData; 71 | class LLDB_API SBSymbol; 72 | class LLDB_API SBSymbolContext; 73 | class LLDB_API SBSymbolContextList; 74 | class LLDB_API SBTarget; 75 | class LLDB_API SBThread; 76 | class LLDB_API SBThreadCollection; 77 | class LLDB_API SBThreadPlan; 78 | class LLDB_API SBTrace; 79 | class LLDB_API SBTraceOptions; 80 | class LLDB_API SBType; 81 | class LLDB_API SBTypeCategory; 82 | class LLDB_API SBTypeEnumMember; 83 | class LLDB_API SBTypeEnumMemberList; 84 | class LLDB_API SBTypeFilter; 85 | class LLDB_API SBTypeFormat; 86 | class LLDB_API SBTypeMemberFunction; 87 | class LLDB_API SBTypeNameSpecifier; 88 | class LLDB_API SBTypeSummary; 89 | class LLDB_API SBTypeSummaryOptions; 90 | class LLDB_API SBTypeSynthetic; 91 | class LLDB_API SBTypeList; 92 | class LLDB_API SBValue; 93 | class LLDB_API SBValueList; 94 | class LLDB_API SBVariablesOptions; 95 | class LLDB_API SBWatchpoint; 96 | class LLDB_API SBUnixSignals; 97 | 98 | typedef bool (*SBBreakpointHitCallback)(void *baton, SBProcess &process, 99 | SBThread &thread, 100 | lldb::SBBreakpointLocation &location); 101 | } 102 | 103 | #endif // LLDB_API_SBDEFINES_H 104 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBEnvironment.h: -------------------------------------------------------------------------------- 1 | //===-- SBEnvironment.h -----------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBENVIRONMENT_H 10 | #define LLDB_API_SBENVIRONMENT_H 11 | 12 | #include 13 | 14 | namespace lldb { 15 | 16 | class LLDB_API SBEnvironment { 17 | public: 18 | SBEnvironment(); 19 | 20 | SBEnvironment(const lldb::SBEnvironment &rhs); 21 | 22 | ~SBEnvironment(); 23 | 24 | const lldb::SBEnvironment &operator=(const lldb::SBEnvironment &rhs); 25 | 26 | /// Return the value of a given environment variable. 27 | /// 28 | /// \param [in] name 29 | /// The name of the environment variable. 30 | /// 31 | /// \return 32 | /// The value of the environment variable or null if not present. 33 | /// If the environment variable has no value but is present, a valid 34 | /// pointer to an empty string will be returned. 35 | const char *Get(const char *name); 36 | 37 | /// \return 38 | /// The number of environment variables. 39 | size_t GetNumValues(); 40 | 41 | /// Return the name of the environment variable at a given index from the 42 | /// internal list of environment variables. 43 | /// 44 | /// \param [in] index 45 | /// The index of the environment variable in the internal list. 46 | /// 47 | /// \return 48 | /// The name at the given index or null if the index is invalid. 49 | const char *GetNameAtIndex(size_t index); 50 | 51 | /// Return the value of the environment variable at a given index from the 52 | /// internal list of environment variables. 53 | /// 54 | /// \param [in] index 55 | /// The index of the environment variable in the internal list. 56 | /// 57 | /// \return 58 | /// The value at the given index or null if the index is invalid. 59 | /// If the environment variable has no value but is present, a valid 60 | /// pointer to an empty string will be returned. 61 | const char *GetValueAtIndex(size_t index); 62 | 63 | /// Return all environment variables contained in this object. Each variable 64 | /// is returned as a string with the following format 65 | /// name=value 66 | /// 67 | /// \return 68 | /// Return an lldb::SBStringList object with the environment variables. 69 | SBStringList GetEntries(); 70 | 71 | /// Add or replace an existing environment variable. The input must be a 72 | /// string with the format 73 | /// name=value 74 | /// 75 | /// \param [in] name_and_value 76 | /// The entry to set which conforms to the format mentioned above. 77 | void PutEntry(const char *name_and_value); 78 | 79 | /// Update this object with the given environment variables. The input is a 80 | /// list of entries with the same format required by SBEnvironment::PutEntry. 81 | /// 82 | /// If append is false, the provided environment will replace the existing 83 | /// environment. Otherwise, existing values will be updated of left untouched 84 | /// accordingly. 85 | /// 86 | /// \param [in] entries 87 | /// The environment variable entries. 88 | /// 89 | /// \param [in] append 90 | /// Flag that controls whether to replace the existing environment. 91 | void SetEntries(const SBStringList &entries, bool append); 92 | 93 | /// Set the value of a given environment variable. 94 | /// If the variable exists, its value is updated only if overwrite is true. 95 | /// 96 | /// \param [in] name 97 | /// The name of the environment variable to set. 98 | /// 99 | /// \param [in] value 100 | /// The value of the environment variable to set. 101 | /// 102 | /// \param [in] overwrite 103 | /// Flag that indicates whether to overwrite an existing environment 104 | /// variable. 105 | /// 106 | /// \return 107 | /// Return whether the variable was added or modified. 108 | bool Set(const char *name, const char *value, bool overwrite); 109 | 110 | /// Unset an environment variable if exists. 111 | /// 112 | /// \param [in] name 113 | /// The name of the environment variable to unset. 114 | /// 115 | /// \return 116 | /// Return whether a variable was actually unset. 117 | bool Unset(const char *name); 118 | 119 | /// Delete all the environment variables. 120 | void Clear(); 121 | 122 | protected: 123 | friend class SBPlatform; 124 | friend class SBTarget; 125 | friend class SBLaunchInfo; 126 | 127 | SBEnvironment(lldb_private::Environment rhs); 128 | 129 | lldb_private::Environment &ref() const; 130 | 131 | private: 132 | std::unique_ptr m_opaque_up; 133 | }; 134 | 135 | } // namespace lldb 136 | 137 | #endif // LLDB_API_SBENVIRONMENT_H 138 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBError.h: -------------------------------------------------------------------------------- 1 | //===-- SBError.h -----------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBERROR_H 10 | #define LLDB_API_SBERROR_H 11 | 12 | #include 13 | 14 | namespace lldb { 15 | 16 | class LLDB_API SBError { 17 | public: 18 | SBError(); 19 | 20 | SBError(const lldb::SBError &rhs); 21 | 22 | ~SBError(); 23 | 24 | const SBError &operator=(const lldb::SBError &rhs); 25 | 26 | const char *GetCString() const; 27 | 28 | void Clear(); 29 | 30 | bool Fail() const; 31 | 32 | bool Success() const; 33 | 34 | uint32_t GetError() const; 35 | 36 | lldb::ErrorType GetType() const; 37 | 38 | void SetError(uint32_t err, lldb::ErrorType type); 39 | 40 | void SetErrorToErrno(); 41 | 42 | void SetErrorToGenericError(); 43 | 44 | void SetErrorString(const char *err_str); 45 | 46 | int SetErrorStringWithFormat(const char *format, ...) 47 | __attribute__((format(printf, 2, 3))); 48 | 49 | explicit operator bool() const; 50 | 51 | bool IsValid() const; 52 | 53 | bool GetDescription(lldb::SBStream &description); 54 | 55 | protected: 56 | friend class SBBreakpoint; 57 | friend class SBBreakpointLocation; 58 | friend class SBBreakpointName; 59 | friend class SBCommandReturnObject; 60 | friend class SBCommunication; 61 | friend class SBData; 62 | friend class SBDebugger; 63 | friend class SBHostOS; 64 | friend class SBModule; 65 | friend class SBPlatform; 66 | friend class SBProcess; 67 | friend class SBReproducer; 68 | friend class SBStructuredData; 69 | friend class SBTarget; 70 | friend class SBThread; 71 | friend class SBTrace; 72 | friend class SBValue; 73 | friend class SBWatchpoint; 74 | friend class SBFile; 75 | 76 | lldb_private::Status *get(); 77 | 78 | lldb_private::Status *operator->(); 79 | 80 | const lldb_private::Status &operator*() const; 81 | 82 | lldb_private::Status &ref(); 83 | 84 | void SetError(const lldb_private::Status &lldb_error); 85 | 86 | private: 87 | std::unique_ptr m_opaque_up; 88 | 89 | void CreateIfNeeded(); 90 | }; 91 | 92 | } // namespace lldb 93 | 94 | #endif // LLDB_API_SBERROR_H 95 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBEvent.h: -------------------------------------------------------------------------------- 1 | //===-- SBEvent.h -----------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBEVENT_H 10 | #define LLDB_API_SBEVENT_H 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace lldb { 18 | 19 | class SBBroadcaster; 20 | 21 | class LLDB_API SBEvent { 22 | public: 23 | SBEvent(); 24 | 25 | SBEvent(const lldb::SBEvent &rhs); 26 | 27 | // Make an event that contains a C string. 28 | SBEvent(uint32_t event, const char *cstr, uint32_t cstr_len); 29 | 30 | SBEvent(lldb::EventSP &event_sp); 31 | 32 | SBEvent(lldb_private::Event *event_sp); 33 | 34 | ~SBEvent(); 35 | 36 | const SBEvent &operator=(const lldb::SBEvent &rhs); 37 | 38 | explicit operator bool() const; 39 | 40 | bool IsValid() const; 41 | 42 | const char *GetDataFlavor(); 43 | 44 | uint32_t GetType() const; 45 | 46 | lldb::SBBroadcaster GetBroadcaster() const; 47 | 48 | const char *GetBroadcasterClass() const; 49 | 50 | bool BroadcasterMatchesPtr(const lldb::SBBroadcaster *broadcaster); 51 | 52 | bool BroadcasterMatchesRef(const lldb::SBBroadcaster &broadcaster); 53 | 54 | void Clear(); 55 | 56 | static const char *GetCStringFromEvent(const lldb::SBEvent &event); 57 | 58 | bool GetDescription(lldb::SBStream &description); 59 | 60 | bool GetDescription(lldb::SBStream &description) const; 61 | 62 | protected: 63 | friend class SBListener; 64 | friend class SBBroadcaster; 65 | friend class SBBreakpoint; 66 | friend class SBDebugger; 67 | friend class SBProcess; 68 | friend class SBTarget; 69 | friend class SBThread; 70 | friend class SBWatchpoint; 71 | 72 | lldb::EventSP &GetSP() const; 73 | 74 | void reset(lldb::EventSP &event_sp); 75 | 76 | void reset(lldb_private::Event *event); 77 | 78 | lldb_private::Event *get() const; 79 | 80 | private: 81 | mutable lldb::EventSP m_event_sp; 82 | mutable lldb_private::Event *m_opaque_ptr; 83 | }; 84 | 85 | } // namespace lldb 86 | 87 | #endif // LLDB_API_SBEVENT_H 88 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBExecutionContext.h: -------------------------------------------------------------------------------- 1 | //===-- SBExecutionContext.h -----------------------------------------*- C++ 2 | //-*-===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLDB_API_SBEXECUTIONCONTEXT_H 11 | #define LLDB_API_SBEXECUTIONCONTEXT_H 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | namespace lldb { 19 | 20 | class LLDB_API SBExecutionContext { 21 | friend class SBCommandInterpreter; 22 | 23 | public: 24 | SBExecutionContext(); 25 | 26 | SBExecutionContext(const lldb::SBExecutionContext &rhs); 27 | 28 | SBExecutionContext(lldb::ExecutionContextRefSP exe_ctx_ref_sp); 29 | 30 | SBExecutionContext(const lldb::SBTarget &target); 31 | 32 | SBExecutionContext(const lldb::SBProcess &process); 33 | 34 | SBExecutionContext(lldb::SBThread thread); // can't be a const& because 35 | // SBThread::get() isn't itself a 36 | // const function 37 | 38 | SBExecutionContext(const lldb::SBFrame &frame); 39 | 40 | ~SBExecutionContext(); 41 | 42 | const SBExecutionContext &operator=(const lldb::SBExecutionContext &rhs); 43 | 44 | SBTarget GetTarget() const; 45 | 46 | SBProcess GetProcess() const; 47 | 48 | SBThread GetThread() const; 49 | 50 | SBFrame GetFrame() const; 51 | 52 | protected: 53 | void reset(lldb::ExecutionContextRefSP &event_sp); 54 | 55 | lldb_private::ExecutionContextRef *get() const; 56 | 57 | private: 58 | mutable lldb::ExecutionContextRefSP m_exe_ctx_sp; 59 | }; 60 | 61 | } // namespace lldb 62 | 63 | #endif // LLDB_API_SBEXECUTIONCONTEXT_H 64 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBExpressionOptions.h: -------------------------------------------------------------------------------- 1 | //===-- SBExpressionOptions.h -----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBEXPRESSIONOPTIONS_H 10 | #define LLDB_API_SBEXPRESSIONOPTIONS_H 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace lldb { 17 | 18 | class LLDB_API SBExpressionOptions { 19 | public: 20 | SBExpressionOptions(); 21 | 22 | SBExpressionOptions(const lldb::SBExpressionOptions &rhs); 23 | 24 | ~SBExpressionOptions(); 25 | 26 | const SBExpressionOptions &operator=(const lldb::SBExpressionOptions &rhs); 27 | 28 | bool GetCoerceResultToId() const; 29 | 30 | void SetCoerceResultToId(bool coerce = true); 31 | 32 | bool GetUnwindOnError() const; 33 | 34 | void SetUnwindOnError(bool unwind = true); 35 | 36 | bool GetIgnoreBreakpoints() const; 37 | 38 | void SetIgnoreBreakpoints(bool ignore = true); 39 | 40 | lldb::DynamicValueType GetFetchDynamicValue() const; 41 | 42 | void SetFetchDynamicValue( 43 | lldb::DynamicValueType dynamic = lldb::eDynamicCanRunTarget); 44 | 45 | uint32_t GetTimeoutInMicroSeconds() const; 46 | 47 | // Set the timeout for the expression, 0 means wait forever. 48 | void SetTimeoutInMicroSeconds(uint32_t timeout = 0); 49 | 50 | uint32_t GetOneThreadTimeoutInMicroSeconds() const; 51 | 52 | // Set the timeout for running on one thread, 0 means use the default 53 | // behavior. If you set this higher than the overall timeout, you'll get an 54 | // error when you try to run the expression. 55 | void SetOneThreadTimeoutInMicroSeconds(uint32_t timeout = 0); 56 | 57 | bool GetTryAllThreads() const; 58 | 59 | void SetTryAllThreads(bool run_others = true); 60 | 61 | bool GetStopOthers() const; 62 | 63 | void SetStopOthers(bool stop_others = true); 64 | 65 | bool GetTrapExceptions() const; 66 | 67 | void SetTrapExceptions(bool trap_exceptions = true); 68 | 69 | void SetLanguage(lldb::LanguageType language); 70 | 71 | void SetCancelCallback(lldb::ExpressionCancelCallback callback, void *baton); 72 | 73 | bool GetPlaygroundTransformEnabled() const; 74 | 75 | void SetPlaygroundTransformEnabled(bool enable_playground_transform = true); 76 | 77 | bool GetREPLMode() const; 78 | 79 | void SetREPLMode(bool enable_repl_mode = true); 80 | 81 | bool GetGenerateDebugInfo(); 82 | 83 | void SetGenerateDebugInfo(bool b = true); 84 | 85 | bool GetSuppressPersistentResult(); 86 | 87 | void SetSuppressPersistentResult(bool b = false); 88 | 89 | const char *GetPrefix() const; 90 | 91 | void SetPrefix(const char *prefix); 92 | 93 | void SetAutoApplyFixIts(bool b = true); 94 | 95 | bool GetAutoApplyFixIts(); 96 | 97 | void SetRetriesWithFixIts(uint64_t retries); 98 | 99 | uint64_t GetRetriesWithFixIts(); 100 | 101 | bool GetTopLevel(); 102 | 103 | void SetTopLevel(bool b = true); 104 | 105 | // Gets whether we will JIT an expression if it cannot be interpreted 106 | bool GetAllowJIT(); 107 | 108 | // Sets whether we will JIT an expression if it cannot be interpreted 109 | void SetAllowJIT(bool allow); 110 | 111 | protected: 112 | lldb_private::EvaluateExpressionOptions *get() const; 113 | 114 | lldb_private::EvaluateExpressionOptions &ref() const; 115 | 116 | friend class SBFrame; 117 | friend class SBValue; 118 | friend class SBTarget; 119 | 120 | private: 121 | // This auto_pointer is made in the constructor and is always valid. 122 | mutable std::unique_ptr m_opaque_up; 123 | }; 124 | 125 | } // namespace lldb 126 | 127 | #endif // LLDB_API_SBEXPRESSIONOPTIONS_H 128 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBFile.h: -------------------------------------------------------------------------------- 1 | //===-- SBFile.h --------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBFILE_H 10 | #define LLDB_API_SBFILE_H 11 | 12 | #include 13 | 14 | namespace lldb { 15 | 16 | class LLDB_API SBFile { 17 | friend class SBInstruction; 18 | friend class SBInstructionList; 19 | friend class SBDebugger; 20 | friend class SBCommandReturnObject; 21 | friend class SBProcess; 22 | 23 | public: 24 | SBFile(); 25 | SBFile(FileSP file_sp); 26 | SBFile(const SBFile &rhs); 27 | SBFile(FILE *file, bool transfer_ownership); 28 | SBFile(int fd, const char *mode, bool transfer_ownership); 29 | ~SBFile(); 30 | 31 | SBFile &operator=(const SBFile &rhs); 32 | 33 | SBError Read(uint8_t *buf, size_t num_bytes, size_t *bytes_read); 34 | SBError Write(const uint8_t *buf, size_t num_bytes, size_t *bytes_written); 35 | SBError Flush(); 36 | bool IsValid() const; 37 | SBError Close(); 38 | 39 | operator bool() const; 40 | bool operator!() const; 41 | 42 | FileSP GetFile() const; 43 | 44 | private: 45 | FileSP m_opaque_sp; 46 | }; 47 | 48 | } // namespace lldb 49 | 50 | #endif // LLDB_API_SBFILE_H 51 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBFileSpec.h: -------------------------------------------------------------------------------- 1 | //===-- SBFileSpec.h --------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBFILESPEC_H 10 | #define LLDB_API_SBFILESPEC_H 11 | 12 | #include 13 | 14 | namespace lldb { 15 | 16 | class LLDB_API SBFileSpec { 17 | public: 18 | SBFileSpec(); 19 | 20 | SBFileSpec(const lldb::SBFileSpec &rhs); 21 | 22 | SBFileSpec(const char *path); // Deprecated, use SBFileSpec (const char *path, 23 | // bool resolve) 24 | 25 | SBFileSpec(const char *path, bool resolve); 26 | 27 | ~SBFileSpec(); 28 | 29 | const SBFileSpec &operator=(const lldb::SBFileSpec &rhs); 30 | 31 | explicit operator bool() const; 32 | 33 | bool operator==(const SBFileSpec &rhs) const; 34 | 35 | bool operator!=(const SBFileSpec &rhs) const; 36 | 37 | bool IsValid() const; 38 | 39 | bool Exists() const; 40 | 41 | bool ResolveExecutableLocation(); 42 | 43 | const char *GetFilename() const; 44 | 45 | const char *GetDirectory() const; 46 | 47 | void SetFilename(const char *filename); 48 | 49 | void SetDirectory(const char *directory); 50 | 51 | uint32_t GetPath(char *dst_path, size_t dst_len) const; 52 | 53 | static int ResolvePath(const char *src_path, char *dst_path, size_t dst_len); 54 | 55 | bool GetDescription(lldb::SBStream &description) const; 56 | 57 | void AppendPathComponent(const char *file_or_directory); 58 | 59 | private: 60 | friend class SBAttachInfo; 61 | friend class SBBlock; 62 | friend class SBCommandInterpreter; 63 | friend class SBCompileUnit; 64 | friend class SBDeclaration; 65 | friend class SBFileSpecList; 66 | friend class SBHostOS; 67 | friend class SBLaunchInfo; 68 | friend class SBLineEntry; 69 | friend class SBModule; 70 | friend class SBModuleSpec; 71 | friend class SBPlatform; 72 | friend class SBProcess; 73 | friend class SBProcessInfo; 74 | friend class SBSourceManager; 75 | friend class SBTarget; 76 | friend class SBThread; 77 | 78 | SBFileSpec(const lldb_private::FileSpec &fspec); 79 | 80 | void SetFileSpec(const lldb_private::FileSpec &fspec); 81 | 82 | const lldb_private::FileSpec *operator->() const; 83 | 84 | const lldb_private::FileSpec *get() const; 85 | 86 | const lldb_private::FileSpec &operator*() const; 87 | 88 | const lldb_private::FileSpec &ref() const; 89 | 90 | std::unique_ptr m_opaque_up; 91 | }; 92 | 93 | } // namespace lldb 94 | 95 | #endif // LLDB_API_SBFILESPEC_H 96 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBFileSpecList.h: -------------------------------------------------------------------------------- 1 | //===-- SBFileSpecList.h --------------------------------------------*- C++ 2 | //-*-===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLDB_API_SBFILESPECLIST_H 11 | #define LLDB_API_SBFILESPECLIST_H 12 | 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBFileSpecList { 18 | public: 19 | SBFileSpecList(); 20 | 21 | SBFileSpecList(const lldb::SBFileSpecList &rhs); 22 | 23 | ~SBFileSpecList(); 24 | 25 | const SBFileSpecList &operator=(const lldb::SBFileSpecList &rhs); 26 | 27 | uint32_t GetSize() const; 28 | 29 | bool GetDescription(SBStream &description) const; 30 | 31 | void Append(const SBFileSpec &sb_file); 32 | 33 | bool AppendIfUnique(const SBFileSpec &sb_file); 34 | 35 | void Clear(); 36 | 37 | uint32_t FindFileIndex(uint32_t idx, const SBFileSpec &sb_file, bool full); 38 | 39 | const SBFileSpec GetFileSpecAtIndex(uint32_t idx) const; 40 | 41 | private: 42 | friend class SBTarget; 43 | 44 | const lldb_private::FileSpecList *operator->() const; 45 | 46 | const lldb_private::FileSpecList *get() const; 47 | 48 | const lldb_private::FileSpecList &operator*() const; 49 | 50 | const lldb_private::FileSpecList &ref() const; 51 | 52 | std::unique_ptr m_opaque_up; 53 | }; 54 | 55 | } // namespace lldb 56 | 57 | #endif // LLDB_API_SBFILESPECLIST_H 58 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBFunction.h: -------------------------------------------------------------------------------- 1 | //===-- SBFunction.h --------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBFUNCTION_H 10 | #define LLDB_API_SBFUNCTION_H 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace lldb { 17 | 18 | class LLDB_API SBFunction { 19 | public: 20 | SBFunction(); 21 | 22 | SBFunction(const lldb::SBFunction &rhs); 23 | 24 | const lldb::SBFunction &operator=(const lldb::SBFunction &rhs); 25 | 26 | ~SBFunction(); 27 | 28 | explicit operator bool() const; 29 | 30 | bool IsValid() const; 31 | 32 | const char *GetName() const; 33 | 34 | const char *GetDisplayName() const; 35 | 36 | const char *GetMangledName() const; 37 | 38 | lldb::SBInstructionList GetInstructions(lldb::SBTarget target); 39 | 40 | lldb::SBInstructionList GetInstructions(lldb::SBTarget target, 41 | const char *flavor); 42 | 43 | lldb::SBAddress GetStartAddress(); 44 | 45 | lldb::SBAddress GetEndAddress(); 46 | 47 | const char *GetArgumentName(uint32_t arg_idx); 48 | 49 | uint32_t GetPrologueByteSize(); 50 | 51 | lldb::SBType GetType(); 52 | 53 | lldb::SBBlock GetBlock(); 54 | 55 | lldb::LanguageType GetLanguage(); 56 | 57 | bool GetIsOptimized(); 58 | 59 | bool GetCanThrow(); 60 | 61 | bool operator==(const lldb::SBFunction &rhs) const; 62 | 63 | bool operator!=(const lldb::SBFunction &rhs) const; 64 | 65 | bool GetDescription(lldb::SBStream &description); 66 | 67 | protected: 68 | lldb_private::Function *get(); 69 | 70 | void reset(lldb_private::Function *lldb_object_ptr); 71 | 72 | private: 73 | friend class SBAddress; 74 | friend class SBFrame; 75 | friend class SBSymbolContext; 76 | 77 | SBFunction(lldb_private::Function *lldb_object_ptr); 78 | 79 | lldb_private::Function *m_opaque_ptr; 80 | }; 81 | 82 | } // namespace lldb 83 | 84 | #endif // LLDB_API_SBFUNCTION_H 85 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBHostOS.h: -------------------------------------------------------------------------------- 1 | //===-- SBHostOS.h ----------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBHOSTOS_H 10 | #define LLDB_API_SBHOSTOS_H 11 | 12 | #include 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBHostOS { 18 | public: 19 | static lldb::SBFileSpec GetProgramFileSpec(); 20 | 21 | static lldb::SBFileSpec GetLLDBPythonPath(); 22 | 23 | static lldb::SBFileSpec GetLLDBPath(lldb::PathType path_type); 24 | 25 | static lldb::SBFileSpec GetUserHomeDirectory(); 26 | 27 | static void ThreadCreated(const char *name); 28 | 29 | static lldb::thread_t ThreadCreate(const char *name, 30 | lldb::thread_func_t thread_function, 31 | void *thread_arg, lldb::SBError *err); 32 | 33 | static bool ThreadCancel(lldb::thread_t thread, lldb::SBError *err); 34 | 35 | static bool ThreadDetach(lldb::thread_t thread, lldb::SBError *err); 36 | static bool ThreadJoin(lldb::thread_t thread, lldb::thread_result_t *result, 37 | lldb::SBError *err); 38 | 39 | private: 40 | }; 41 | 42 | } // namespace lldb 43 | 44 | #endif // LLDB_API_SBHOSTOS_H 45 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBInstruction.h: -------------------------------------------------------------------------------- 1 | //===-- SBInstruction.h -----------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBINSTRUCTION_H 10 | #define LLDB_API_SBINSTRUCTION_H 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | // There's a lot to be fixed here, but need to wait for underlying insn 18 | // implementation to be revised & settle down first. 19 | 20 | class InstructionImpl; 21 | 22 | namespace lldb { 23 | 24 | class LLDB_API SBInstruction { 25 | public: 26 | SBInstruction(); 27 | 28 | SBInstruction(const SBInstruction &rhs); 29 | 30 | const SBInstruction &operator=(const SBInstruction &rhs); 31 | 32 | ~SBInstruction(); 33 | 34 | explicit operator bool() const; 35 | 36 | bool IsValid(); 37 | 38 | SBAddress GetAddress(); 39 | 40 | const char *GetMnemonic(lldb::SBTarget target); 41 | 42 | const char *GetOperands(lldb::SBTarget target); 43 | 44 | const char *GetComment(lldb::SBTarget target); 45 | 46 | lldb::SBData GetData(lldb::SBTarget target); 47 | 48 | size_t GetByteSize(); 49 | 50 | bool DoesBranch(); 51 | 52 | bool HasDelaySlot(); 53 | 54 | bool CanSetBreakpoint(); 55 | 56 | void Print(FILE *out); 57 | 58 | void Print(SBFile out); 59 | 60 | void Print(FileSP out); 61 | 62 | bool GetDescription(lldb::SBStream &description); 63 | 64 | bool EmulateWithFrame(lldb::SBFrame &frame, uint32_t evaluate_options); 65 | 66 | bool DumpEmulation(const char *triple); // triple is to specify the 67 | // architecture, e.g. 'armv6' or 68 | // 'armv7-apple-ios' 69 | 70 | bool TestEmulation(lldb::SBStream &output_stream, const char *test_file); 71 | 72 | protected: 73 | friend class SBInstructionList; 74 | 75 | SBInstruction(const lldb::DisassemblerSP &disasm_sp, 76 | const lldb::InstructionSP &inst_sp); 77 | 78 | void SetOpaque(const lldb::DisassemblerSP &disasm_sp, 79 | const lldb::InstructionSP &inst_sp); 80 | 81 | lldb::InstructionSP GetOpaque(); 82 | 83 | private: 84 | std::shared_ptr m_opaque_sp; 85 | }; 86 | 87 | } // namespace lldb 88 | 89 | #endif // LLDB_API_SBINSTRUCTION_H 90 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBInstructionList.h: -------------------------------------------------------------------------------- 1 | //===-- SBInstructionList.h -------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBINSTRUCTIONLIST_H 10 | #define LLDB_API_SBINSTRUCTIONLIST_H 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace lldb { 17 | 18 | class LLDB_API SBInstructionList { 19 | public: 20 | SBInstructionList(); 21 | 22 | SBInstructionList(const SBInstructionList &rhs); 23 | 24 | const SBInstructionList &operator=(const SBInstructionList &rhs); 25 | 26 | ~SBInstructionList(); 27 | 28 | explicit operator bool() const; 29 | 30 | bool IsValid() const; 31 | 32 | size_t GetSize(); 33 | 34 | lldb::SBInstruction GetInstructionAtIndex(uint32_t idx); 35 | 36 | // Returns the number of instructions between the start and end address. If 37 | // canSetBreakpoint is true then the count will be the number of 38 | // instructions on which a breakpoint can be set. 39 | size_t GetInstructionsCount(const SBAddress &start, 40 | const SBAddress &end, 41 | bool canSetBreakpoint = false); 42 | 43 | void Clear(); 44 | 45 | void AppendInstruction(lldb::SBInstruction inst); 46 | 47 | void Print(FILE *out); 48 | 49 | void Print(SBFile out); 50 | 51 | void Print(FileSP out); 52 | 53 | bool GetDescription(lldb::SBStream &description); 54 | 55 | bool DumpEmulationForAllInstructions(const char *triple); 56 | 57 | protected: 58 | friend class SBFunction; 59 | friend class SBSymbol; 60 | friend class SBTarget; 61 | 62 | void SetDisassembler(const lldb::DisassemblerSP &opaque_sp); 63 | bool GetDescription(lldb_private::Stream &description); 64 | 65 | 66 | private: 67 | lldb::DisassemblerSP m_opaque_sp; 68 | }; 69 | 70 | } // namespace lldb 71 | 72 | #endif // LLDB_API_SBINSTRUCTIONLIST_H 73 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBLanguageRuntime.h: -------------------------------------------------------------------------------- 1 | //===-- SBLanguageRuntime.h -------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBLANGUAGERUNTIME_H 10 | #define LLDB_API_SBLANGUAGERUNTIME_H 11 | 12 | #include 13 | 14 | namespace lldb { 15 | 16 | class SBLanguageRuntime { 17 | public: 18 | static lldb::LanguageType GetLanguageTypeFromString(const char *string); 19 | 20 | static const char *GetNameForLanguageType(lldb::LanguageType language); 21 | }; 22 | 23 | } // namespace lldb 24 | 25 | #endif // LLDB_API_SBLANGUAGERUNTIME_H 26 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBLineEntry.h: -------------------------------------------------------------------------------- 1 | //===-- SBLineEntry.h -------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBLINEENTRY_H 10 | #define LLDB_API_SBLINEENTRY_H 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace lldb { 17 | 18 | class LLDB_API SBLineEntry { 19 | public: 20 | SBLineEntry(); 21 | 22 | SBLineEntry(const lldb::SBLineEntry &rhs); 23 | 24 | ~SBLineEntry(); 25 | 26 | const lldb::SBLineEntry &operator=(const lldb::SBLineEntry &rhs); 27 | 28 | lldb::SBAddress GetStartAddress() const; 29 | 30 | lldb::SBAddress GetEndAddress() const; 31 | 32 | explicit operator bool() const; 33 | 34 | bool IsValid() const; 35 | 36 | lldb::SBFileSpec GetFileSpec() const; 37 | 38 | uint32_t GetLine() const; 39 | 40 | uint32_t GetColumn() const; 41 | 42 | void SetFileSpec(lldb::SBFileSpec filespec); 43 | 44 | void SetLine(uint32_t line); 45 | 46 | void SetColumn(uint32_t column); 47 | 48 | bool operator==(const lldb::SBLineEntry &rhs) const; 49 | 50 | bool operator!=(const lldb::SBLineEntry &rhs) const; 51 | 52 | bool GetDescription(lldb::SBStream &description); 53 | 54 | protected: 55 | lldb_private::LineEntry *get(); 56 | 57 | private: 58 | friend class SBAddress; 59 | friend class SBCompileUnit; 60 | friend class SBFrame; 61 | friend class SBSymbolContext; 62 | 63 | const lldb_private::LineEntry *operator->() const; 64 | 65 | lldb_private::LineEntry &ref(); 66 | 67 | const lldb_private::LineEntry &ref() const; 68 | 69 | SBLineEntry(const lldb_private::LineEntry *lldb_object_ptr); 70 | 71 | void SetLineEntry(const lldb_private::LineEntry &lldb_object_ref); 72 | 73 | std::unique_ptr m_opaque_up; 74 | }; 75 | 76 | } // namespace lldb 77 | 78 | #endif // LLDB_API_SBLINEENTRY_H 79 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBListener.h: -------------------------------------------------------------------------------- 1 | //===-- SBListener.h --------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBLISTENER_H 10 | #define LLDB_API_SBLISTENER_H 11 | 12 | #include 13 | 14 | namespace lldb { 15 | 16 | class LLDB_API SBListener { 17 | public: 18 | SBListener(); 19 | 20 | SBListener(const char *name); 21 | 22 | SBListener(const SBListener &rhs); 23 | 24 | ~SBListener(); 25 | 26 | const lldb::SBListener &operator=(const lldb::SBListener &rhs); 27 | 28 | void AddEvent(const lldb::SBEvent &event); 29 | 30 | void Clear(); 31 | 32 | explicit operator bool() const; 33 | 34 | bool IsValid() const; 35 | 36 | uint32_t StartListeningForEventClass(SBDebugger &debugger, 37 | const char *broadcaster_class, 38 | uint32_t event_mask); 39 | 40 | bool StopListeningForEventClass(SBDebugger &debugger, 41 | const char *broadcaster_class, 42 | uint32_t event_mask); 43 | 44 | uint32_t StartListeningForEvents(const lldb::SBBroadcaster &broadcaster, 45 | uint32_t event_mask); 46 | 47 | bool StopListeningForEvents(const lldb::SBBroadcaster &broadcaster, 48 | uint32_t event_mask); 49 | 50 | // Returns true if an event was received, false if we timed out. 51 | bool WaitForEvent(uint32_t num_seconds, lldb::SBEvent &event); 52 | 53 | bool WaitForEventForBroadcaster(uint32_t num_seconds, 54 | const lldb::SBBroadcaster &broadcaster, 55 | lldb::SBEvent &sb_event); 56 | 57 | bool WaitForEventForBroadcasterWithType( 58 | uint32_t num_seconds, const lldb::SBBroadcaster &broadcaster, 59 | uint32_t event_type_mask, lldb::SBEvent &sb_event); 60 | 61 | bool PeekAtNextEvent(lldb::SBEvent &sb_event); 62 | 63 | bool PeekAtNextEventForBroadcaster(const lldb::SBBroadcaster &broadcaster, 64 | lldb::SBEvent &sb_event); 65 | 66 | bool 67 | PeekAtNextEventForBroadcasterWithType(const lldb::SBBroadcaster &broadcaster, 68 | uint32_t event_type_mask, 69 | lldb::SBEvent &sb_event); 70 | 71 | bool GetNextEvent(lldb::SBEvent &sb_event); 72 | 73 | bool GetNextEventForBroadcaster(const lldb::SBBroadcaster &broadcaster, 74 | lldb::SBEvent &sb_event); 75 | 76 | bool 77 | GetNextEventForBroadcasterWithType(const lldb::SBBroadcaster &broadcaster, 78 | uint32_t event_type_mask, 79 | lldb::SBEvent &sb_event); 80 | 81 | bool HandleBroadcastEvent(const lldb::SBEvent &event); 82 | 83 | protected: 84 | friend class SBAttachInfo; 85 | friend class SBBroadcaster; 86 | friend class SBCommandInterpreter; 87 | friend class SBDebugger; 88 | friend class SBLaunchInfo; 89 | friend class SBTarget; 90 | 91 | SBListener(const lldb::ListenerSP &listener_sp); 92 | 93 | lldb::ListenerSP GetSP(); 94 | 95 | private: 96 | lldb_private::Listener *operator->() const; 97 | 98 | lldb_private::Listener *get() const; 99 | 100 | void reset(lldb::ListenerSP listener_sp); 101 | 102 | lldb::ListenerSP m_opaque_sp; 103 | lldb_private::Listener *m_unused_ptr; 104 | }; 105 | 106 | } // namespace lldb 107 | 108 | #endif // LLDB_API_SBLISTENER_H 109 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBMemoryRegionInfo.h: -------------------------------------------------------------------------------- 1 | //===-- SBMemoryRegionInfo.h ------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBMEMORYREGIONINFO_H 10 | #define LLDB_API_SBMEMORYREGIONINFO_H 11 | 12 | #include 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBMemoryRegionInfo { 18 | public: 19 | SBMemoryRegionInfo(); 20 | 21 | SBMemoryRegionInfo(const lldb::SBMemoryRegionInfo &rhs); 22 | 23 | ~SBMemoryRegionInfo(); 24 | 25 | const lldb::SBMemoryRegionInfo & 26 | operator=(const lldb::SBMemoryRegionInfo &rhs); 27 | 28 | void Clear(); 29 | 30 | /// Get the base address of this memory range. 31 | /// 32 | /// \return 33 | /// The base address of this memory range. 34 | lldb::addr_t GetRegionBase(); 35 | 36 | /// Get the end address of this memory range. 37 | /// 38 | /// \return 39 | /// The base address of this memory range. 40 | lldb::addr_t GetRegionEnd(); 41 | 42 | /// Check if this memory address is marked readable to the process. 43 | /// 44 | /// \return 45 | /// true if this memory address is marked readable 46 | bool IsReadable(); 47 | 48 | /// Check if this memory address is marked writable to the process. 49 | /// 50 | /// \return 51 | /// true if this memory address is marked writable 52 | bool IsWritable(); 53 | 54 | /// Check if this memory address is marked executable to the process. 55 | /// 56 | /// \return 57 | /// true if this memory address is marked executable 58 | bool IsExecutable(); 59 | 60 | /// Check if this memory address is mapped into the process address 61 | /// space. 62 | /// 63 | /// \return 64 | /// true if this memory address is in the process address space. 65 | bool IsMapped(); 66 | 67 | /// Returns the name of the memory region mapped at the given 68 | /// address. 69 | /// 70 | /// \return 71 | /// In case of memory mapped files it is the absolute path of 72 | /// the file otherwise it is a name associated with the memory 73 | /// region. If no name can be determined the returns nullptr. 74 | const char *GetName(); 75 | 76 | bool operator==(const lldb::SBMemoryRegionInfo &rhs) const; 77 | 78 | bool operator!=(const lldb::SBMemoryRegionInfo &rhs) const; 79 | 80 | bool GetDescription(lldb::SBStream &description); 81 | 82 | private: 83 | friend class SBProcess; 84 | friend class SBMemoryRegionInfoList; 85 | 86 | lldb_private::MemoryRegionInfo &ref(); 87 | 88 | const lldb_private::MemoryRegionInfo &ref() const; 89 | 90 | // Unused. 91 | SBMemoryRegionInfo(const lldb_private::MemoryRegionInfo *lldb_object_ptr); 92 | 93 | lldb::MemoryRegionInfoUP m_opaque_up; 94 | }; 95 | 96 | } // namespace lldb 97 | 98 | #endif // LLDB_API_SBMEMORYREGIONINFO_H 99 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBMemoryRegionInfoList.h: -------------------------------------------------------------------------------- 1 | //===-- SBMemoryRegionInfoList.h --------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBMEMORYREGIONINFOLIST_H 10 | #define LLDB_API_SBMEMORYREGIONINFOLIST_H 11 | 12 | #include 13 | 14 | class MemoryRegionInfoListImpl; 15 | 16 | namespace lldb { 17 | 18 | class LLDB_API SBMemoryRegionInfoList { 19 | public: 20 | SBMemoryRegionInfoList(); 21 | 22 | SBMemoryRegionInfoList(const lldb::SBMemoryRegionInfoList &rhs); 23 | 24 | const SBMemoryRegionInfoList &operator=(const SBMemoryRegionInfoList &rhs); 25 | 26 | ~SBMemoryRegionInfoList(); 27 | 28 | uint32_t GetSize() const; 29 | 30 | bool GetMemoryRegionAtIndex(uint32_t idx, SBMemoryRegionInfo ®ion_info); 31 | 32 | void Append(lldb::SBMemoryRegionInfo ®ion); 33 | 34 | void Append(lldb::SBMemoryRegionInfoList ®ion_list); 35 | 36 | void Clear(); 37 | 38 | protected: 39 | const MemoryRegionInfoListImpl *operator->() const; 40 | 41 | const MemoryRegionInfoListImpl &operator*() const; 42 | 43 | private: 44 | friend class SBProcess; 45 | 46 | lldb_private::MemoryRegionInfos &ref(); 47 | 48 | const lldb_private::MemoryRegionInfos &ref() const; 49 | 50 | std::unique_ptr m_opaque_up; 51 | }; 52 | 53 | } // namespace lldb 54 | 55 | #endif // LLDB_API_SBMEMORYREGIONINFOLIST_H 56 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBModuleSpec.h: -------------------------------------------------------------------------------- 1 | //===-- SBModuleSpec.h ------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBMODULESPEC_H 10 | #define LLDB_API_SBMODULESPEC_H 11 | 12 | #include 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBModuleSpec { 18 | public: 19 | SBModuleSpec(); 20 | 21 | SBModuleSpec(const SBModuleSpec &rhs); 22 | 23 | ~SBModuleSpec(); 24 | 25 | const SBModuleSpec &operator=(const SBModuleSpec &rhs); 26 | 27 | explicit operator bool() const; 28 | 29 | bool IsValid() const; 30 | 31 | void Clear(); 32 | 33 | /// Get const accessor for the module file. 34 | /// 35 | /// This function returns the file for the module on the host system 36 | /// that is running LLDB. This can differ from the path on the 37 | /// platform since we might be doing remote debugging. 38 | /// 39 | /// \return 40 | /// A const reference to the file specification object. 41 | lldb::SBFileSpec GetFileSpec(); 42 | 43 | void SetFileSpec(const lldb::SBFileSpec &fspec); 44 | 45 | /// Get accessor for the module platform file. 46 | /// 47 | /// Platform file refers to the path of the module as it is known on 48 | /// the remote system on which it is being debugged. For local 49 | /// debugging this is always the same as Module::GetFileSpec(). But 50 | /// remote debugging might mention a file '/usr/lib/liba.dylib' 51 | /// which might be locally downloaded and cached. In this case the 52 | /// platform file could be something like: 53 | /// '/tmp/lldb/platform-cache/remote.host.computer/usr/lib/liba.dylib' 54 | /// The file could also be cached in a local developer kit directory. 55 | /// 56 | /// \return 57 | /// A const reference to the file specification object. 58 | lldb::SBFileSpec GetPlatformFileSpec(); 59 | 60 | void SetPlatformFileSpec(const lldb::SBFileSpec &fspec); 61 | 62 | lldb::SBFileSpec GetSymbolFileSpec(); 63 | 64 | void SetSymbolFileSpec(const lldb::SBFileSpec &fspec); 65 | 66 | const char *GetObjectName(); 67 | 68 | void SetObjectName(const char *name); 69 | 70 | const char *GetTriple(); 71 | 72 | void SetTriple(const char *triple); 73 | 74 | const uint8_t *GetUUIDBytes(); 75 | 76 | size_t GetUUIDLength(); 77 | 78 | bool SetUUIDBytes(const uint8_t *uuid, size_t uuid_len); 79 | 80 | bool GetDescription(lldb::SBStream &description); 81 | 82 | private: 83 | friend class SBModuleSpecList; 84 | friend class SBModule; 85 | friend class SBTarget; 86 | 87 | std::unique_ptr m_opaque_up; 88 | }; 89 | 90 | class SBModuleSpecList { 91 | public: 92 | SBModuleSpecList(); 93 | 94 | SBModuleSpecList(const SBModuleSpecList &rhs); 95 | 96 | ~SBModuleSpecList(); 97 | 98 | SBModuleSpecList &operator=(const SBModuleSpecList &rhs); 99 | 100 | static SBModuleSpecList GetModuleSpecifications(const char *path); 101 | 102 | void Append(const SBModuleSpec &spec); 103 | 104 | void Append(const SBModuleSpecList &spec_list); 105 | 106 | SBModuleSpec FindFirstMatchingSpec(const SBModuleSpec &match_spec); 107 | 108 | SBModuleSpecList FindMatchingSpecs(const SBModuleSpec &match_spec); 109 | 110 | size_t GetSize(); 111 | 112 | SBModuleSpec GetSpecAtIndex(size_t i); 113 | 114 | bool GetDescription(lldb::SBStream &description); 115 | 116 | private: 117 | std::unique_ptr m_opaque_up; 118 | }; 119 | 120 | } // namespace lldb 121 | 122 | #endif // LLDB_API_SBMODULESPEC_H 123 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBPlatform.h: -------------------------------------------------------------------------------- 1 | //===-- SBPlatform.h --------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBPLATFORM_H 10 | #define LLDB_API_SBPLATFORM_H 11 | 12 | #include 13 | 14 | #include 15 | 16 | struct PlatformConnectOptions; 17 | struct PlatformShellCommand; 18 | 19 | namespace lldb { 20 | 21 | class SBLaunchInfo; 22 | 23 | class LLDB_API SBPlatformConnectOptions { 24 | public: 25 | SBPlatformConnectOptions(const char *url); 26 | 27 | SBPlatformConnectOptions(const SBPlatformConnectOptions &rhs); 28 | 29 | ~SBPlatformConnectOptions(); 30 | 31 | SBPlatformConnectOptions &operator=(const SBPlatformConnectOptions &rhs); 32 | 33 | const char *GetURL(); 34 | 35 | void SetURL(const char *url); 36 | 37 | bool GetRsyncEnabled(); 38 | 39 | void EnableRsync(const char *options, const char *remote_path_prefix, 40 | bool omit_remote_hostname); 41 | 42 | void DisableRsync(); 43 | 44 | const char *GetLocalCacheDirectory(); 45 | 46 | void SetLocalCacheDirectory(const char *path); 47 | 48 | protected: 49 | PlatformConnectOptions *m_opaque_ptr; 50 | }; 51 | 52 | class LLDB_API SBPlatformShellCommand { 53 | public: 54 | SBPlatformShellCommand(const char *shell, const char *shell_command); 55 | SBPlatformShellCommand(const char *shell_command); 56 | 57 | SBPlatformShellCommand(const SBPlatformShellCommand &rhs); 58 | 59 | SBPlatformShellCommand &operator=(const SBPlatformShellCommand &rhs); 60 | 61 | ~SBPlatformShellCommand(); 62 | 63 | void Clear(); 64 | 65 | const char *GetShell(); 66 | 67 | void SetShell(const char *shell); 68 | 69 | const char *GetCommand(); 70 | 71 | void SetCommand(const char *shell_command); 72 | 73 | const char *GetWorkingDirectory(); 74 | 75 | void SetWorkingDirectory(const char *path); 76 | 77 | uint32_t GetTimeoutSeconds(); 78 | 79 | void SetTimeoutSeconds(uint32_t sec); 80 | 81 | int GetSignal(); 82 | 83 | int GetStatus(); 84 | 85 | const char *GetOutput(); 86 | 87 | protected: 88 | friend class SBPlatform; 89 | 90 | PlatformShellCommand *m_opaque_ptr; 91 | }; 92 | 93 | class LLDB_API SBPlatform { 94 | public: 95 | SBPlatform(); 96 | 97 | SBPlatform(const char *platform_name); 98 | 99 | SBPlatform(const SBPlatform &rhs); 100 | 101 | SBPlatform &operator=(const SBPlatform &rhs); 102 | 103 | ~SBPlatform(); 104 | 105 | static SBPlatform GetHostPlatform(); 106 | 107 | explicit operator bool() const; 108 | 109 | bool IsValid() const; 110 | 111 | void Clear(); 112 | 113 | const char *GetWorkingDirectory(); 114 | 115 | bool SetWorkingDirectory(const char *path); 116 | 117 | const char *GetName(); 118 | 119 | SBError ConnectRemote(SBPlatformConnectOptions &connect_options); 120 | 121 | void DisconnectRemote(); 122 | 123 | bool IsConnected(); 124 | 125 | // The following functions will work if the platform is connected 126 | const char *GetTriple(); 127 | 128 | const char *GetHostname(); 129 | 130 | const char *GetOSBuild(); 131 | 132 | const char *GetOSDescription(); 133 | 134 | uint32_t GetOSMajorVersion(); 135 | 136 | uint32_t GetOSMinorVersion(); 137 | 138 | uint32_t GetOSUpdateVersion(); 139 | 140 | SBError Put(SBFileSpec &src, SBFileSpec &dst); 141 | 142 | SBError Get(SBFileSpec &src, SBFileSpec &dst); 143 | 144 | SBError Install(SBFileSpec &src, SBFileSpec &dst); 145 | 146 | SBError Run(SBPlatformShellCommand &shell_command); 147 | 148 | SBError Launch(SBLaunchInfo &launch_info); 149 | 150 | SBError Kill(const lldb::pid_t pid); 151 | 152 | SBError 153 | MakeDirectory(const char *path, 154 | uint32_t file_permissions = eFilePermissionsDirectoryDefault); 155 | 156 | uint32_t GetFilePermissions(const char *path); 157 | 158 | SBError SetFilePermissions(const char *path, uint32_t file_permissions); 159 | 160 | SBUnixSignals GetUnixSignals() const; 161 | 162 | /// Return the environment variables of the remote platform connection 163 | /// process. 164 | /// 165 | /// \return 166 | /// An lldb::SBEnvironment object which is a copy of the platform's 167 | /// environment. 168 | SBEnvironment GetEnvironment(); 169 | 170 | protected: 171 | friend class SBDebugger; 172 | friend class SBTarget; 173 | 174 | lldb::PlatformSP GetSP() const; 175 | 176 | void SetSP(const lldb::PlatformSP &platform_sp); 177 | 178 | SBError ExecuteConnected( 179 | const std::function 180 | &func); 181 | 182 | lldb::PlatformSP m_opaque_sp; 183 | }; 184 | 185 | } // namespace lldb 186 | 187 | #endif // LLDB_API_SBPLATFORM_H 188 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBProcessInfo.h: -------------------------------------------------------------------------------- 1 | //===-- SBProcessInfo.h -----------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBPROCESSINFO_H 10 | #define LLDB_API_SBPROCESSINFO_H 11 | 12 | #include 13 | 14 | namespace lldb { 15 | 16 | class LLDB_API SBProcessInfo { 17 | public: 18 | SBProcessInfo(); 19 | SBProcessInfo(const SBProcessInfo &rhs); 20 | 21 | ~SBProcessInfo(); 22 | 23 | SBProcessInfo &operator=(const SBProcessInfo &rhs); 24 | 25 | explicit operator bool() const; 26 | 27 | bool IsValid() const; 28 | 29 | const char *GetName(); 30 | 31 | SBFileSpec GetExecutableFile(); 32 | 33 | lldb::pid_t GetProcessID(); 34 | 35 | uint32_t GetUserID(); 36 | 37 | uint32_t GetGroupID(); 38 | 39 | bool UserIDIsValid(); 40 | 41 | bool GroupIDIsValid(); 42 | 43 | uint32_t GetEffectiveUserID(); 44 | 45 | uint32_t GetEffectiveGroupID(); 46 | 47 | bool EffectiveUserIDIsValid(); 48 | 49 | bool EffectiveGroupIDIsValid(); 50 | 51 | lldb::pid_t GetParentProcessID(); 52 | 53 | private: 54 | friend class SBProcess; 55 | 56 | lldb_private::ProcessInstanceInfo &ref(); 57 | 58 | void SetProcessInfo(const lldb_private::ProcessInstanceInfo &proc_info_ref); 59 | 60 | std::unique_ptr m_opaque_up; 61 | }; 62 | 63 | } // namespace lldb 64 | 65 | #endif // LLDB_API_SBPROCESSINFO_H 66 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBQueue.h: -------------------------------------------------------------------------------- 1 | //===-- SBQueue.h -----------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBQUEUE_H 10 | #define LLDB_API_SBQUEUE_H 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace lldb { 18 | 19 | class LLDB_API SBQueue { 20 | public: 21 | SBQueue(); 22 | 23 | SBQueue(const QueueSP &queue_sp); 24 | 25 | SBQueue(const SBQueue &rhs); 26 | 27 | const SBQueue &operator=(const lldb::SBQueue &rhs); 28 | 29 | ~SBQueue(); 30 | 31 | explicit operator bool() const; 32 | 33 | bool IsValid() const; 34 | 35 | void Clear(); 36 | 37 | lldb::SBProcess GetProcess(); 38 | 39 | lldb::queue_id_t GetQueueID() const; 40 | 41 | const char *GetName() const; 42 | 43 | uint32_t GetIndexID() const; 44 | 45 | uint32_t GetNumThreads(); 46 | 47 | lldb::SBThread GetThreadAtIndex(uint32_t); 48 | 49 | uint32_t GetNumPendingItems(); 50 | 51 | lldb::SBQueueItem GetPendingItemAtIndex(uint32_t); 52 | 53 | uint32_t GetNumRunningItems(); 54 | 55 | lldb::QueueKind GetKind(); 56 | 57 | protected: 58 | friend class SBProcess; 59 | friend class SBThread; 60 | 61 | void SetQueue(const lldb::QueueSP &queue_sp); 62 | 63 | private: 64 | std::shared_ptr m_opaque_sp; 65 | }; 66 | 67 | } // namespace lldb 68 | 69 | #endif // LLDB_API_SBQUEUE_H 70 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBQueueItem.h: -------------------------------------------------------------------------------- 1 | //===-- SBQueueItem.h -------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBQUEUEITEM_H 10 | #define LLDB_API_SBQUEUEITEM_H 11 | 12 | #include 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBQueueItem { 18 | public: 19 | SBQueueItem(); 20 | 21 | SBQueueItem(const lldb::QueueItemSP &queue_item_sp); 22 | 23 | ~SBQueueItem(); 24 | 25 | explicit operator bool() const; 26 | 27 | bool IsValid() const; 28 | 29 | void Clear(); 30 | 31 | lldb::QueueItemKind GetKind() const; 32 | 33 | void SetKind(lldb::QueueItemKind kind); 34 | 35 | lldb::SBAddress GetAddress() const; 36 | 37 | void SetAddress(lldb::SBAddress addr); 38 | 39 | void SetQueueItem(const lldb::QueueItemSP &queue_item_sp); 40 | 41 | SBThread GetExtendedBacktraceThread(const char *type); 42 | 43 | private: 44 | lldb::QueueItemSP m_queue_item_sp; 45 | }; 46 | 47 | } // namespace lldb 48 | 49 | #endif // LLDB_API_SBQUEUEITEM_H 50 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBReproducer.h: -------------------------------------------------------------------------------- 1 | //===-- SBReproducer.h ------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBREPRODUCER_H 10 | #define LLDB_API_SBREPRODUCER_H 11 | 12 | #include 13 | 14 | namespace lldb_private { 15 | namespace repro { 16 | struct ReplayOptions; 17 | } 18 | } // namespace lldb_private 19 | 20 | namespace lldb { 21 | 22 | class LLDB_API SBReplayOptions { 23 | public: 24 | SBReplayOptions(); 25 | SBReplayOptions(const SBReplayOptions &rhs); 26 | ~SBReplayOptions(); 27 | 28 | SBReplayOptions &operator=(const SBReplayOptions &rhs); 29 | 30 | void SetVerify(bool verify); 31 | bool GetVerify() const; 32 | 33 | void SetCheckVersion(bool check); 34 | bool GetCheckVersion() const; 35 | 36 | private: 37 | std::unique_ptr m_opaque_up; 38 | }; 39 | 40 | /// The SBReproducer class is special because it bootstraps the capture and 41 | /// replay of SB API calls. As a result we cannot rely on any other SB objects 42 | /// in the interface or implementation of this class. 43 | class LLDB_API SBReproducer { 44 | public: 45 | static const char *Capture(); 46 | static const char *Capture(const char *path); 47 | static const char *Replay(const char *path); 48 | static const char *Replay(const char *path, bool skip_version_check); 49 | static const char *Replay(const char *path, const SBReplayOptions &options); 50 | static const char *PassiveReplay(const char *path); 51 | static const char *Finalize(const char *path); 52 | static const char *GetPath(); 53 | static bool SetAutoGenerate(bool b); 54 | static bool Generate(); 55 | 56 | /// The working directory is set to the current working directory when the 57 | /// reproducers are initialized. This method allows setting a different 58 | /// working directory. This is used by the API test suite which temporarily 59 | /// changes the directory to where the test lives. This is a NO-OP in every 60 | /// mode but capture. 61 | static void SetWorkingDirectory(const char *path); 62 | }; 63 | 64 | } // namespace lldb 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBSection.h: -------------------------------------------------------------------------------- 1 | //===-- SBSection.h ---------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBSECTION_H 10 | #define LLDB_API_SBSECTION_H 11 | 12 | #include 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBSection { 18 | public: 19 | SBSection(); 20 | 21 | SBSection(const lldb::SBSection &rhs); 22 | 23 | ~SBSection(); 24 | 25 | const lldb::SBSection &operator=(const lldb::SBSection &rhs); 26 | 27 | explicit operator bool() const; 28 | 29 | bool IsValid() const; 30 | 31 | const char *GetName(); 32 | 33 | lldb::SBSection GetParent(); 34 | 35 | lldb::SBSection FindSubSection(const char *sect_name); 36 | 37 | size_t GetNumSubSections(); 38 | 39 | lldb::SBSection GetSubSectionAtIndex(size_t idx); 40 | 41 | lldb::addr_t GetFileAddress(); 42 | 43 | lldb::addr_t GetLoadAddress(lldb::SBTarget &target); 44 | 45 | lldb::addr_t GetByteSize(); 46 | 47 | uint64_t GetFileOffset(); 48 | 49 | uint64_t GetFileByteSize(); 50 | 51 | lldb::SBData GetSectionData(); 52 | 53 | lldb::SBData GetSectionData(uint64_t offset, uint64_t size); 54 | 55 | SectionType GetSectionType(); 56 | 57 | /// Gets the permissions (RWX) of the section of the object file 58 | /// 59 | /// Returns a mask of bits of enum lldb::Permissions for this section. 60 | /// Sections for which permissions are not defined, 0 is returned for 61 | /// them. The binary representation of this value corresponds to [XRW] 62 | /// i.e. for a section having read and execute permissions, the value 63 | /// returned is 6 64 | /// 65 | /// \return 66 | /// Returns an unsigned value for Permissions for the section. 67 | uint32_t 68 | GetPermissions() const; 69 | 70 | /// Return the size of a target's byte represented by this section 71 | /// in numbers of host bytes. Note that certain architectures have 72 | /// varying minimum addressable unit (i.e. byte) size for their 73 | /// CODE or DATA buses. 74 | /// 75 | /// \return 76 | /// The number of host (8-bit) bytes needed to hold a target byte 77 | uint32_t GetTargetByteSize(); 78 | 79 | bool operator==(const lldb::SBSection &rhs); 80 | 81 | bool operator!=(const lldb::SBSection &rhs); 82 | 83 | bool GetDescription(lldb::SBStream &description); 84 | 85 | private: 86 | friend class SBAddress; 87 | friend class SBModule; 88 | friend class SBTarget; 89 | 90 | SBSection(const lldb::SectionSP §ion_sp); 91 | 92 | lldb::SectionSP GetSP() const; 93 | 94 | void SetSP(const lldb::SectionSP §ion_sp); 95 | 96 | lldb::SectionWP m_opaque_wp; 97 | }; 98 | 99 | } // namespace lldb 100 | 101 | #endif // LLDB_API_SBSECTION_H 102 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBSourceManager.h: -------------------------------------------------------------------------------- 1 | //===-- SBSourceManager.h ---------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBSOURCEMANAGER_H 10 | #define LLDB_API_SBSOURCEMANAGER_H 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace lldb { 17 | 18 | class LLDB_API SBSourceManager { 19 | public: 20 | SBSourceManager(const SBDebugger &debugger); 21 | SBSourceManager(const SBTarget &target); 22 | SBSourceManager(const SBSourceManager &rhs); 23 | 24 | ~SBSourceManager(); 25 | 26 | const lldb::SBSourceManager &operator=(const lldb::SBSourceManager &rhs); 27 | 28 | size_t DisplaySourceLinesWithLineNumbers( 29 | const lldb::SBFileSpec &file, uint32_t line, uint32_t context_before, 30 | uint32_t context_after, const char *current_line_cstr, lldb::SBStream &s); 31 | 32 | size_t DisplaySourceLinesWithLineNumbersAndColumn( 33 | const lldb::SBFileSpec &file, uint32_t line, uint32_t column, 34 | uint32_t context_before, uint32_t context_after, 35 | const char *current_line_cstr, lldb::SBStream &s); 36 | 37 | protected: 38 | friend class SBCommandInterpreter; 39 | friend class SBDebugger; 40 | 41 | private: 42 | std::unique_ptr m_opaque_up; 43 | }; 44 | 45 | } // namespace lldb 46 | 47 | #endif // LLDB_API_SBSOURCEMANAGER_H 48 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBStream.h: -------------------------------------------------------------------------------- 1 | //===-- SBStream.h ----------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBSTREAM_H 10 | #define LLDB_API_SBSTREAM_H 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace lldb { 17 | 18 | class LLDB_API SBStream { 19 | public: 20 | SBStream(); 21 | 22 | SBStream(SBStream &&rhs); 23 | 24 | ~SBStream(); 25 | 26 | explicit operator bool() const; 27 | 28 | bool IsValid() const; 29 | 30 | // If this stream is not redirected to a file, it will maintain a local cache 31 | // for the stream data which can be accessed using this accessor. 32 | const char *GetData(); 33 | 34 | // If this stream is not redirected to a file, it will maintain a local cache 35 | // for the stream output whose length can be accessed using this accessor. 36 | size_t GetSize(); 37 | 38 | void Printf(const char *format, ...) __attribute__((format(printf, 2, 3))); 39 | 40 | void Print(const char *str); 41 | 42 | void RedirectToFile(const char *path, bool append); 43 | 44 | void RedirectToFile(lldb::SBFile file); 45 | 46 | void RedirectToFile(lldb::FileSP file); 47 | 48 | void RedirectToFileHandle(FILE *fh, bool transfer_fh_ownership); 49 | 50 | void RedirectToFileDescriptor(int fd, bool transfer_fh_ownership); 51 | 52 | // If the stream is redirected to a file, forget about the file and if 53 | // ownership of the file was transferred to this object, close the file. If 54 | // the stream is backed by a local cache, clear this cache. 55 | void Clear(); 56 | 57 | protected: 58 | friend class SBAddress; 59 | friend class SBBlock; 60 | friend class SBBreakpoint; 61 | friend class SBBreakpointLocation; 62 | friend class SBBreakpointName; 63 | friend class SBCommandReturnObject; 64 | friend class SBCompileUnit; 65 | friend class SBData; 66 | friend class SBDebugger; 67 | friend class SBDeclaration; 68 | friend class SBEvent; 69 | friend class SBFileSpec; 70 | friend class SBFileSpecList; 71 | friend class SBFrame; 72 | friend class SBFunction; 73 | friend class SBInstruction; 74 | friend class SBInstructionList; 75 | friend class SBLineEntry; 76 | friend class SBMemoryRegionInfo; 77 | friend class SBModule; 78 | friend class SBModuleSpec; 79 | friend class SBModuleSpecList; 80 | friend class SBProcess; 81 | friend class SBSection; 82 | friend class SBSourceManager; 83 | friend class SBStructuredData; 84 | friend class SBSymbol; 85 | friend class SBSymbolContext; 86 | friend class SBSymbolContextList; 87 | friend class SBTarget; 88 | friend class SBThread; 89 | friend class SBThreadPlan; 90 | friend class SBType; 91 | friend class SBTypeEnumMember; 92 | friend class SBTypeMemberFunction; 93 | friend class SBTypeMember; 94 | friend class SBValue; 95 | friend class SBWatchpoint; 96 | 97 | lldb_private::Stream *operator->(); 98 | 99 | lldb_private::Stream *get(); 100 | 101 | lldb_private::Stream &ref(); 102 | 103 | private: 104 | SBStream(const SBStream &) = delete; 105 | const SBStream &operator=(const SBStream &) = delete; 106 | std::unique_ptr m_opaque_up; 107 | bool m_is_file; 108 | }; 109 | 110 | } // namespace lldb 111 | 112 | #endif // LLDB_API_SBSTREAM_H 113 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBStringList.h: -------------------------------------------------------------------------------- 1 | //===-- SBStringList.h ------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBSTRINGLIST_H 10 | #define LLDB_API_SBSTRINGLIST_H 11 | 12 | #include 13 | 14 | namespace lldb { 15 | 16 | class LLDB_API SBStringList { 17 | public: 18 | SBStringList(); 19 | 20 | SBStringList(const lldb::SBStringList &rhs); 21 | 22 | const SBStringList &operator=(const SBStringList &rhs); 23 | 24 | ~SBStringList(); 25 | 26 | explicit operator bool() const; 27 | 28 | bool IsValid() const; 29 | 30 | void AppendString(const char *str); 31 | 32 | void AppendList(const char **strv, int strc); 33 | 34 | void AppendList(const lldb::SBStringList &strings); 35 | 36 | uint32_t GetSize() const; 37 | 38 | const char *GetStringAtIndex(size_t idx); 39 | 40 | const char *GetStringAtIndex(size_t idx) const; 41 | 42 | void Clear(); 43 | 44 | protected: 45 | friend class SBCommandInterpreter; 46 | friend class SBDebugger; 47 | friend class SBBreakpoint; 48 | friend class SBBreakpointLocation; 49 | friend class SBBreakpointName; 50 | 51 | SBStringList(const lldb_private::StringList *lldb_strings); 52 | 53 | void AppendList(const lldb_private::StringList &strings); 54 | 55 | const lldb_private::StringList *operator->() const; 56 | 57 | const lldb_private::StringList &operator*() const; 58 | 59 | private: 60 | std::unique_ptr m_opaque_up; 61 | }; 62 | 63 | } // namespace lldb 64 | 65 | #endif // LLDB_API_SBSTRINGLIST_H 66 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBStructuredData.h: -------------------------------------------------------------------------------- 1 | //===-- SBStructuredData.h --------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBSTRUCTUREDDATA_H 10 | #define LLDB_API_SBSTRUCTUREDDATA_H 11 | 12 | #include 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class SBStructuredData { 18 | public: 19 | SBStructuredData(); 20 | 21 | SBStructuredData(const lldb::SBStructuredData &rhs); 22 | 23 | SBStructuredData(const lldb::EventSP &event_sp); 24 | 25 | SBStructuredData(lldb_private::StructuredDataImpl *impl); 26 | 27 | ~SBStructuredData(); 28 | 29 | lldb::SBStructuredData &operator=(const lldb::SBStructuredData &rhs); 30 | 31 | explicit operator bool() const; 32 | 33 | bool IsValid() const; 34 | 35 | lldb::SBError SetFromJSON(lldb::SBStream &stream); 36 | 37 | void Clear(); 38 | 39 | lldb::SBError GetAsJSON(lldb::SBStream &stream) const; 40 | 41 | lldb::SBError GetDescription(lldb::SBStream &stream) const; 42 | 43 | /// Return the type of data in this data structure 44 | lldb::StructuredDataType GetType() const; 45 | 46 | /// Return the size (i.e. number of elements) in this data structure 47 | /// if it is an array or dictionary type. For other types, 0 will be 48 | // returned. 49 | size_t GetSize() const; 50 | 51 | /// Fill keys with the keys in this object and return true if this data 52 | /// structure is a dictionary. Returns false otherwise. 53 | bool GetKeys(lldb::SBStringList &keys) const; 54 | 55 | /// Return the value corresponding to a key if this data structure 56 | /// is a dictionary type. 57 | lldb::SBStructuredData GetValueForKey(const char *key) const; 58 | 59 | /// Return the value corresponding to an index if this data structure 60 | /// is array. 61 | lldb::SBStructuredData GetItemAtIndex(size_t idx) const; 62 | 63 | /// Return the integer value if this data structure is an integer type. 64 | uint64_t GetIntegerValue(uint64_t fail_value = 0) const; 65 | 66 | /// Return the floating point value if this data structure is a floating 67 | /// type. 68 | double GetFloatValue(double fail_value = 0.0) const; 69 | 70 | /// Return the boolean value if this data structure is a boolean type. 71 | bool GetBooleanValue(bool fail_value = false) const; 72 | 73 | /// Provides the string value if this data structure is a string type. 74 | /// 75 | /// \param[out] dst 76 | /// pointer where the string value will be written. In case it is null, 77 | /// nothing will be written at \a dst. 78 | /// 79 | /// \param[in] dst_len 80 | /// max number of characters that can be written at \a dst. In case it is 81 | /// zero, nothing will be written at \a dst. If this length is not enough 82 | /// to write the complete string value, (\a dst_len - 1) bytes of the 83 | /// string value will be written at \a dst followed by a null character. 84 | /// 85 | /// \return 86 | /// Returns the byte size needed to completely write the string value at 87 | /// \a dst in all cases. 88 | size_t GetStringValue(char *dst, size_t dst_len) const; 89 | 90 | protected: 91 | friend class SBTraceOptions; 92 | friend class SBDebugger; 93 | friend class SBTarget; 94 | friend class SBProcess; 95 | friend class SBThread; 96 | friend class SBThreadPlan; 97 | friend class SBBreakpoint; 98 | friend class SBBreakpointLocation; 99 | friend class SBBreakpointName; 100 | 101 | StructuredDataImplUP m_impl_up; 102 | }; 103 | } // namespace lldb 104 | 105 | #endif // LLDB_API_SBSTRUCTUREDDATA_H 106 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBSymbol.h: -------------------------------------------------------------------------------- 1 | //===-- SBSymbol.h ----------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBSYMBOL_H 10 | #define LLDB_API_SBSYMBOL_H 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace lldb { 18 | 19 | class LLDB_API SBSymbol { 20 | public: 21 | SBSymbol(); 22 | 23 | ~SBSymbol(); 24 | 25 | SBSymbol(const lldb::SBSymbol &rhs); 26 | 27 | const lldb::SBSymbol &operator=(const lldb::SBSymbol &rhs); 28 | 29 | explicit operator bool() const; 30 | 31 | bool IsValid() const; 32 | 33 | const char *GetName() const; 34 | 35 | const char *GetDisplayName() const; 36 | 37 | const char *GetMangledName() const; 38 | 39 | lldb::SBInstructionList GetInstructions(lldb::SBTarget target); 40 | 41 | lldb::SBInstructionList GetInstructions(lldb::SBTarget target, 42 | const char *flavor_string); 43 | 44 | SBAddress GetStartAddress(); 45 | 46 | SBAddress GetEndAddress(); 47 | 48 | uint32_t GetPrologueByteSize(); 49 | 50 | SymbolType GetType(); 51 | 52 | bool operator==(const lldb::SBSymbol &rhs) const; 53 | 54 | bool operator!=(const lldb::SBSymbol &rhs) const; 55 | 56 | bool GetDescription(lldb::SBStream &description); 57 | 58 | // Returns true if the symbol is externally visible in the module that it is 59 | // defined in 60 | bool IsExternal(); 61 | 62 | // Returns true if the symbol was synthetically generated from something 63 | // other than the actual symbol table itself in the object file. 64 | bool IsSynthetic(); 65 | 66 | protected: 67 | lldb_private::Symbol *get(); 68 | 69 | void reset(lldb_private::Symbol *); 70 | 71 | private: 72 | friend class SBAddress; 73 | friend class SBFrame; 74 | friend class SBModule; 75 | friend class SBSymbolContext; 76 | 77 | SBSymbol(lldb_private::Symbol *lldb_object_ptr); 78 | 79 | void SetSymbol(lldb_private::Symbol *lldb_object_ptr); 80 | 81 | lldb_private::Symbol *m_opaque_ptr; 82 | }; 83 | 84 | } // namespace lldb 85 | 86 | #endif // LLDB_API_SBSYMBOL_H 87 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBSymbolContext.h: -------------------------------------------------------------------------------- 1 | //===-- SBSymbolContext.h ---------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBSYMBOLCONTEXT_H 10 | #define LLDB_API_SBSYMBOLCONTEXT_H 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace lldb { 21 | 22 | class LLDB_API SBSymbolContext { 23 | public: 24 | SBSymbolContext(); 25 | 26 | SBSymbolContext(const lldb::SBSymbolContext &rhs); 27 | 28 | SBSymbolContext(const lldb_private::SymbolContext *sc_ptr); 29 | 30 | ~SBSymbolContext(); 31 | 32 | explicit operator bool() const; 33 | 34 | bool IsValid() const; 35 | 36 | const lldb::SBSymbolContext &operator=(const lldb::SBSymbolContext &rhs); 37 | 38 | lldb::SBModule GetModule(); 39 | lldb::SBCompileUnit GetCompileUnit(); 40 | lldb::SBFunction GetFunction(); 41 | lldb::SBBlock GetBlock(); 42 | lldb::SBLineEntry GetLineEntry(); 43 | lldb::SBSymbol GetSymbol(); 44 | 45 | void SetModule(lldb::SBModule module); 46 | void SetCompileUnit(lldb::SBCompileUnit compile_unit); 47 | void SetFunction(lldb::SBFunction function); 48 | void SetBlock(lldb::SBBlock block); 49 | void SetLineEntry(lldb::SBLineEntry line_entry); 50 | void SetSymbol(lldb::SBSymbol symbol); 51 | 52 | SBSymbolContext GetParentOfInlinedScope(const SBAddress &curr_frame_pc, 53 | SBAddress &parent_frame_addr) const; 54 | 55 | bool GetDescription(lldb::SBStream &description); 56 | 57 | protected: 58 | friend class SBAddress; 59 | friend class SBFrame; 60 | friend class SBModule; 61 | friend class SBThread; 62 | friend class SBTarget; 63 | friend class SBSymbolContextList; 64 | 65 | lldb_private::SymbolContext *operator->() const; 66 | 67 | lldb_private::SymbolContext &operator*(); 68 | 69 | lldb_private::SymbolContext &ref(); 70 | 71 | const lldb_private::SymbolContext &operator*() const; 72 | 73 | lldb_private::SymbolContext *get() const; 74 | 75 | void SetSymbolContext(const lldb_private::SymbolContext *sc_ptr); 76 | 77 | private: 78 | std::unique_ptr m_opaque_up; 79 | }; 80 | 81 | } // namespace lldb 82 | 83 | #endif // LLDB_API_SBSYMBOLCONTEXT_H 84 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBSymbolContextList.h: -------------------------------------------------------------------------------- 1 | //===-- SBSymbolContextList.h -----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBSYMBOLCONTEXTLIST_H 10 | #define LLDB_API_SBSYMBOLCONTEXTLIST_H 11 | 12 | #include 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBSymbolContextList { 18 | public: 19 | SBSymbolContextList(); 20 | 21 | SBSymbolContextList(const lldb::SBSymbolContextList &rhs); 22 | 23 | ~SBSymbolContextList(); 24 | 25 | const lldb::SBSymbolContextList & 26 | operator=(const lldb::SBSymbolContextList &rhs); 27 | 28 | explicit operator bool() const; 29 | 30 | bool IsValid() const; 31 | 32 | uint32_t GetSize() const; 33 | 34 | lldb::SBSymbolContext GetContextAtIndex(uint32_t idx); 35 | 36 | bool GetDescription(lldb::SBStream &description); 37 | 38 | void Append(lldb::SBSymbolContext &sc); 39 | 40 | void Append(lldb::SBSymbolContextList &sc_list); 41 | 42 | void Clear(); 43 | 44 | protected: 45 | friend class SBModule; 46 | friend class SBTarget; 47 | 48 | lldb_private::SymbolContextList *operator->() const; 49 | 50 | lldb_private::SymbolContextList &operator*() const; 51 | 52 | private: 53 | std::unique_ptr m_opaque_up; 54 | }; 55 | 56 | } // namespace lldb 57 | 58 | #endif // LLDB_API_SBSYMBOLCONTEXTLIST_H 59 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBThreadCollection.h: -------------------------------------------------------------------------------- 1 | //===-- SBThreadCollection.h ------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBTHREADCOLLECTION_H 10 | #define LLDB_API_SBTHREADCOLLECTION_H 11 | 12 | #include 13 | 14 | namespace lldb { 15 | 16 | class LLDB_API SBThreadCollection { 17 | public: 18 | SBThreadCollection(); 19 | 20 | SBThreadCollection(const SBThreadCollection &rhs); 21 | 22 | const SBThreadCollection &operator=(const SBThreadCollection &rhs); 23 | 24 | ~SBThreadCollection(); 25 | 26 | explicit operator bool() const; 27 | 28 | bool IsValid() const; 29 | 30 | size_t GetSize(); 31 | 32 | lldb::SBThread GetThreadAtIndex(size_t idx); 33 | 34 | protected: 35 | // Mimic shared pointer... 36 | lldb_private::ThreadCollection *get() const; 37 | 38 | lldb_private::ThreadCollection *operator->() const; 39 | 40 | lldb::ThreadCollectionSP &operator*(); 41 | 42 | const lldb::ThreadCollectionSP &operator*() const; 43 | 44 | SBThreadCollection(const lldb::ThreadCollectionSP &threads); 45 | 46 | void SetOpaque(const lldb::ThreadCollectionSP &threads); 47 | 48 | private: 49 | friend class SBProcess; 50 | friend class SBThread; 51 | 52 | lldb::ThreadCollectionSP m_opaque_sp; 53 | }; 54 | 55 | } // namespace lldb 56 | 57 | #endif // LLDB_API_SBTHREADCOLLECTION_H 58 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBThreadPlan.h: -------------------------------------------------------------------------------- 1 | //===-- SBThreadPlan.h ------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBTHREADPLAN_H 10 | #define LLDB_API_SBTHREADPLAN_H 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace lldb { 17 | 18 | class LLDB_API SBThreadPlan { 19 | 20 | friend class lldb_private::ThreadPlan; 21 | 22 | public: 23 | SBThreadPlan(); 24 | 25 | SBThreadPlan(const lldb::SBThreadPlan &threadPlan); 26 | 27 | SBThreadPlan(const lldb::ThreadPlanSP &lldb_object_sp); 28 | 29 | SBThreadPlan(lldb::SBThread &thread, const char *class_name); 30 | 31 | SBThreadPlan(lldb::SBThread &thread, const char *class_name, 32 | lldb::SBStructuredData &args_data); 33 | 34 | ~SBThreadPlan(); 35 | 36 | explicit operator bool() const; 37 | 38 | bool IsValid() const; 39 | 40 | void Clear(); 41 | 42 | lldb::StopReason GetStopReason(); 43 | 44 | /// Get the number of words associated with the stop reason. 45 | /// See also GetStopReasonDataAtIndex(). 46 | size_t GetStopReasonDataCount(); 47 | 48 | /// Get information associated with a stop reason. 49 | /// 50 | /// Breakpoint stop reasons will have data that consists of pairs of 51 | /// breakpoint IDs followed by the breakpoint location IDs (they always come 52 | /// in pairs). 53 | /// 54 | /// Stop Reason Count Data Type 55 | /// ======================== ===== ========================================= 56 | /// eStopReasonNone 0 57 | /// eStopReasonTrace 0 58 | /// eStopReasonBreakpoint N duple: {breakpoint id, location id} 59 | /// eStopReasonWatchpoint 1 watchpoint id 60 | /// eStopReasonSignal 1 unix signal number 61 | /// eStopReasonException N exception data 62 | /// eStopReasonExec 0 63 | /// eStopReasonPlanComplete 0 64 | uint64_t GetStopReasonDataAtIndex(uint32_t idx); 65 | 66 | SBThread GetThread() const; 67 | 68 | const lldb::SBThreadPlan &operator=(const lldb::SBThreadPlan &rhs); 69 | 70 | bool GetDescription(lldb::SBStream &description) const; 71 | 72 | void SetPlanComplete(bool success); 73 | 74 | bool IsPlanComplete(); 75 | 76 | bool IsPlanStale(); 77 | 78 | bool IsValid(); 79 | 80 | bool GetStopOthers(); 81 | 82 | void SetStopOthers(bool stop_others); 83 | 84 | // This section allows an SBThreadPlan to push another of the common types of 85 | // plans... 86 | SBThreadPlan QueueThreadPlanForStepOverRange(SBAddress &start_address, 87 | lldb::addr_t range_size); 88 | SBThreadPlan QueueThreadPlanForStepOverRange(SBAddress &start_address, 89 | lldb::addr_t range_size, 90 | SBError &error); 91 | 92 | SBThreadPlan QueueThreadPlanForStepInRange(SBAddress &start_address, 93 | lldb::addr_t range_size); 94 | SBThreadPlan QueueThreadPlanForStepInRange(SBAddress &start_address, 95 | lldb::addr_t range_size, 96 | SBError &error); 97 | 98 | SBThreadPlan QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to, 99 | bool first_insn = false); 100 | SBThreadPlan QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to, 101 | bool first_insn, SBError &error); 102 | 103 | SBThreadPlan QueueThreadPlanForRunToAddress(SBAddress address); 104 | SBThreadPlan QueueThreadPlanForRunToAddress(SBAddress address, 105 | SBError &error); 106 | 107 | SBThreadPlan QueueThreadPlanForStepScripted(const char *script_class_name); 108 | SBThreadPlan QueueThreadPlanForStepScripted(const char *script_class_name, 109 | SBError &error); 110 | SBThreadPlan QueueThreadPlanForStepScripted(const char *script_class_name, 111 | lldb::SBStructuredData &args_data, 112 | SBError &error); 113 | 114 | private: 115 | friend class SBBreakpoint; 116 | friend class SBBreakpointLocation; 117 | friend class SBFrame; 118 | friend class SBProcess; 119 | friend class SBDebugger; 120 | friend class SBValue; 121 | friend class lldb_private::QueueImpl; 122 | friend class SBQueueItem; 123 | 124 | lldb::ThreadPlanSP GetSP() const { return m_opaque_wp.lock(); } 125 | lldb_private::ThreadPlan *get() const { return GetSP().get(); } 126 | void SetThreadPlan(const lldb::ThreadPlanSP &lldb_object_sp); 127 | 128 | lldb::ThreadPlanWP m_opaque_wp; 129 | }; 130 | 131 | } // namespace lldb 132 | 133 | #endif // LLDB_API_SBTHREADPLAN_H 134 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBTrace.h: -------------------------------------------------------------------------------- 1 | //===-- SBTrace.h -----------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBTRACE_H 10 | #define LLDB_API_SBTRACE_H 11 | 12 | #include 13 | #include 14 | 15 | class TraceImpl; 16 | 17 | namespace lldb { 18 | 19 | class LLDB_API SBTrace { 20 | public: 21 | SBTrace(); 22 | /// Obtain the trace data as raw bytes. 23 | /// 24 | /// \param[out] error 25 | /// An error explaining what went wrong. 26 | /// 27 | /// \param[in] buf 28 | /// Buffer to write the trace data to. 29 | /// 30 | /// \param[in] size 31 | /// The size of the buffer used to read the data. This is 32 | /// also the size of the data intended to read. It is also 33 | /// possible to partially read the trace data for some trace 34 | /// technologies by specifying a smaller buffer. 35 | /// 36 | /// \param[in] offset 37 | /// The start offset to begin reading the trace data. 38 | /// 39 | /// \param[in] thread_id 40 | /// Tracing could be started for the complete process or a 41 | /// single thread, in the first case the traceid obtained would 42 | /// map to all the threads existing within the process and the 43 | /// ones spawning later. The thread_id parameter can be used in 44 | /// such a scenario to select the trace data for a specific 45 | /// thread. 46 | /// 47 | /// \return 48 | /// The size of the trace data effectively read by the API call. 49 | size_t GetTraceData(SBError &error, void *buf, size_t size, size_t offset = 0, 50 | lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID); 51 | 52 | /// Obtain any meta data as raw bytes for the tracing instance. 53 | /// The input parameter definition is similar to the previous 54 | /// function. 55 | size_t GetMetaData(SBError &error, void *buf, size_t size, size_t offset = 0, 56 | lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID); 57 | 58 | /// Stop the tracing instance. Stopping the trace will also 59 | /// lead to deletion of any gathered trace data. 60 | /// 61 | /// \param[out] error 62 | /// An error explaining what went wrong. 63 | /// 64 | /// \param[in] thread_id 65 | /// The trace id could map to a tracing instance for a thread 66 | /// or could also map to a group of threads being traced with 67 | /// the same trace options. A thread_id is normally optional 68 | /// except in the case of tracing a complete process and tracing 69 | /// needs to switched off on a particular thread. 70 | /// A situation could occur where initially a thread (lets say 71 | /// thread A) is being individually traced with a particular 72 | /// trace id and then tracing is started on the complete 73 | /// process, in this case thread A will continue without any 74 | /// change. All newly spawned threads would be traced with the 75 | /// trace id of the process. 76 | /// Now if the StopTrace API is called for the whole process, 77 | /// thread A will not be stopped and must be stopped separately. 78 | void StopTrace(SBError &error, 79 | lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID); 80 | 81 | /// Get the trace configuration being used for the trace instance. 82 | /// The threadid in the SBTraceOptions needs to be set when the 83 | /// configuration used by a specific thread is being requested. 84 | /// 85 | /// \param[out] options 86 | /// The trace options actually used by the trace instance 87 | /// would be filled by the API. 88 | /// 89 | /// \param[out] error 90 | /// An error explaining what went wrong. 91 | void GetTraceConfig(SBTraceOptions &options, SBError &error); 92 | 93 | lldb::user_id_t GetTraceUID(); 94 | 95 | explicit operator bool() const; 96 | 97 | bool IsValid(); 98 | 99 | protected: 100 | typedef std::shared_ptr TraceImplSP; 101 | 102 | friend class SBProcess; 103 | 104 | void SetTraceUID(lldb::user_id_t uid); 105 | 106 | TraceImplSP m_trace_impl_sp; 107 | 108 | lldb::ProcessSP GetSP() const; 109 | 110 | void SetSP(const ProcessSP &process_sp); 111 | 112 | lldb::ProcessWP m_opaque_wp; 113 | }; 114 | } // namespace lldb 115 | 116 | #endif // LLDB_API_SBTRACE_H 117 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBTraceOptions.h: -------------------------------------------------------------------------------- 1 | //===-- SBTraceOptions ------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBTRACEOPTIONS_H 10 | #define LLDB_API_SBTRACEOPTIONS_H 11 | 12 | #include 13 | 14 | namespace lldb { 15 | 16 | class LLDB_API SBTraceOptions { 17 | public: 18 | SBTraceOptions(); 19 | 20 | lldb::TraceType getType() const; 21 | 22 | uint64_t getTraceBufferSize() const; 23 | 24 | /// The trace parameters consist of any custom parameters 25 | /// apart from the generic parameters such as 26 | /// TraceType, trace_buffer_size and meta_data_buffer_size. 27 | /// The returned parameters would be formatted as a JSON Dictionary. 28 | lldb::SBStructuredData getTraceParams(lldb::SBError &error); 29 | 30 | uint64_t getMetaDataBufferSize() const; 31 | 32 | /// SBStructuredData is meant to hold any custom parameters 33 | /// apart from meta buffer size and trace size. They should 34 | /// be formatted as a JSON Dictionary. 35 | void setTraceParams(lldb::SBStructuredData ¶ms); 36 | 37 | void setType(lldb::TraceType type); 38 | 39 | void setTraceBufferSize(uint64_t size); 40 | 41 | void setMetaDataBufferSize(uint64_t size); 42 | 43 | void setThreadID(lldb::tid_t thread_id); 44 | 45 | lldb::tid_t getThreadID(); 46 | 47 | explicit operator bool() const; 48 | 49 | bool IsValid(); 50 | 51 | protected: 52 | friend class SBProcess; 53 | friend class SBTrace; 54 | 55 | lldb::TraceOptionsSP m_traceoptions_sp; 56 | }; 57 | } 58 | 59 | #endif // LLDB_API_SBTRACEOPTIONS_H 60 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBTypeCategory.h: -------------------------------------------------------------------------------- 1 | //===-- SBTypeCategory.h --------------------------------------------*- C++ 2 | //-*-===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLDB_API_SBTYPECATEGORY_H 11 | #define LLDB_API_SBTYPECATEGORY_H 12 | 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBTypeCategory { 18 | public: 19 | SBTypeCategory(); 20 | 21 | SBTypeCategory(const lldb::SBTypeCategory &rhs); 22 | 23 | ~SBTypeCategory(); 24 | 25 | explicit operator bool() const; 26 | 27 | bool IsValid() const; 28 | 29 | bool GetEnabled(); 30 | 31 | void SetEnabled(bool); 32 | 33 | const char *GetName(); 34 | 35 | lldb::LanguageType GetLanguageAtIndex(uint32_t idx); 36 | 37 | uint32_t GetNumLanguages(); 38 | 39 | void AddLanguage(lldb::LanguageType language); 40 | 41 | bool GetDescription(lldb::SBStream &description, 42 | lldb::DescriptionLevel description_level); 43 | 44 | uint32_t GetNumFormats(); 45 | 46 | uint32_t GetNumSummaries(); 47 | 48 | uint32_t GetNumFilters(); 49 | 50 | uint32_t GetNumSynthetics(); 51 | 52 | SBTypeNameSpecifier GetTypeNameSpecifierForFilterAtIndex(uint32_t); 53 | 54 | SBTypeNameSpecifier GetTypeNameSpecifierForFormatAtIndex(uint32_t); 55 | 56 | SBTypeNameSpecifier GetTypeNameSpecifierForSummaryAtIndex(uint32_t); 57 | 58 | SBTypeNameSpecifier GetTypeNameSpecifierForSyntheticAtIndex(uint32_t); 59 | 60 | SBTypeFilter GetFilterForType(SBTypeNameSpecifier); 61 | 62 | SBTypeFormat GetFormatForType(SBTypeNameSpecifier); 63 | 64 | SBTypeSummary GetSummaryForType(SBTypeNameSpecifier); 65 | 66 | SBTypeSynthetic GetSyntheticForType(SBTypeNameSpecifier); 67 | 68 | SBTypeFilter GetFilterAtIndex(uint32_t); 69 | 70 | SBTypeFormat GetFormatAtIndex(uint32_t); 71 | 72 | SBTypeSummary GetSummaryAtIndex(uint32_t); 73 | 74 | SBTypeSynthetic GetSyntheticAtIndex(uint32_t); 75 | 76 | bool AddTypeFormat(SBTypeNameSpecifier, SBTypeFormat); 77 | 78 | bool DeleteTypeFormat(SBTypeNameSpecifier); 79 | 80 | bool AddTypeSummary(SBTypeNameSpecifier, SBTypeSummary); 81 | 82 | bool DeleteTypeSummary(SBTypeNameSpecifier); 83 | 84 | bool AddTypeFilter(SBTypeNameSpecifier, SBTypeFilter); 85 | 86 | bool DeleteTypeFilter(SBTypeNameSpecifier); 87 | 88 | bool AddTypeSynthetic(SBTypeNameSpecifier, SBTypeSynthetic); 89 | 90 | bool DeleteTypeSynthetic(SBTypeNameSpecifier); 91 | 92 | lldb::SBTypeCategory &operator=(const lldb::SBTypeCategory &rhs); 93 | 94 | bool operator==(lldb::SBTypeCategory &rhs); 95 | 96 | bool operator!=(lldb::SBTypeCategory &rhs); 97 | 98 | protected: 99 | friend class SBDebugger; 100 | 101 | lldb::TypeCategoryImplSP GetSP(); 102 | 103 | void SetSP(const lldb::TypeCategoryImplSP &typecategory_impl_sp); 104 | 105 | TypeCategoryImplSP m_opaque_sp; 106 | 107 | SBTypeCategory(const lldb::TypeCategoryImplSP &); 108 | 109 | SBTypeCategory(const char *); 110 | 111 | bool IsDefaultCategory(); 112 | }; 113 | 114 | } // namespace lldb 115 | 116 | #endif // LLDB_API_SBTYPECATEGORY_H 117 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBTypeEnumMember.h: -------------------------------------------------------------------------------- 1 | 2 | //===-- SBTypeEnumMember.h --------------------------------------*- C++ -*-===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLDB_API_SBTYPEENUMMEMBER_H 11 | #define LLDB_API_SBTYPEENUMMEMBER_H 12 | 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBTypeEnumMember { 18 | public: 19 | SBTypeEnumMember(); 20 | 21 | SBTypeEnumMember(const SBTypeEnumMember &rhs); 22 | 23 | ~SBTypeEnumMember(); 24 | 25 | SBTypeEnumMember &operator=(const SBTypeEnumMember &rhs); 26 | 27 | explicit operator bool() const; 28 | 29 | bool IsValid() const; 30 | 31 | int64_t GetValueAsSigned(); 32 | 33 | uint64_t GetValueAsUnsigned(); 34 | 35 | const char *GetName(); 36 | 37 | lldb::SBType GetType(); 38 | 39 | bool GetDescription(lldb::SBStream &description, 40 | lldb::DescriptionLevel description_level); 41 | 42 | protected: 43 | friend class SBType; 44 | friend class SBTypeEnumMemberList; 45 | 46 | void reset(lldb_private::TypeEnumMemberImpl *); 47 | 48 | lldb_private::TypeEnumMemberImpl &ref(); 49 | 50 | const lldb_private::TypeEnumMemberImpl &ref() const; 51 | 52 | lldb::TypeEnumMemberImplSP m_opaque_sp; 53 | 54 | SBTypeEnumMember(const lldb::TypeEnumMemberImplSP &); 55 | }; 56 | 57 | class SBTypeEnumMemberList { 58 | public: 59 | SBTypeEnumMemberList(); 60 | 61 | SBTypeEnumMemberList(const SBTypeEnumMemberList &rhs); 62 | 63 | ~SBTypeEnumMemberList(); 64 | 65 | SBTypeEnumMemberList &operator=(const SBTypeEnumMemberList &rhs); 66 | 67 | explicit operator bool() const; 68 | 69 | bool IsValid(); 70 | 71 | void Append(SBTypeEnumMember entry); 72 | 73 | SBTypeEnumMember GetTypeEnumMemberAtIndex(uint32_t index); 74 | 75 | uint32_t GetSize(); 76 | 77 | private: 78 | std::unique_ptr m_opaque_up; 79 | }; 80 | 81 | } // namespace lldb 82 | 83 | #endif // LLDB_API_SBTYPEENUMMEMBER_H 84 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBTypeFilter.h: -------------------------------------------------------------------------------- 1 | //===-- SBTypeFilter.h --------------------------------------------*- C++ 2 | //-*-===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLDB_API_SBTYPEFILTER_H 11 | #define LLDB_API_SBTYPEFILTER_H 12 | 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBTypeFilter { 18 | public: 19 | SBTypeFilter(); 20 | 21 | SBTypeFilter(uint32_t options); // see lldb::eTypeOption values 22 | 23 | SBTypeFilter(const lldb::SBTypeFilter &rhs); 24 | 25 | ~SBTypeFilter(); 26 | 27 | explicit operator bool() const; 28 | 29 | bool IsValid() const; 30 | 31 | uint32_t GetNumberOfExpressionPaths(); 32 | 33 | const char *GetExpressionPathAtIndex(uint32_t i); 34 | 35 | bool ReplaceExpressionPathAtIndex(uint32_t i, const char *item); 36 | 37 | void AppendExpressionPath(const char *item); 38 | 39 | void Clear(); 40 | 41 | uint32_t GetOptions(); 42 | 43 | void SetOptions(uint32_t); 44 | 45 | bool GetDescription(lldb::SBStream &description, 46 | lldb::DescriptionLevel description_level); 47 | 48 | lldb::SBTypeFilter &operator=(const lldb::SBTypeFilter &rhs); 49 | 50 | bool IsEqualTo(lldb::SBTypeFilter &rhs); 51 | 52 | bool operator==(lldb::SBTypeFilter &rhs); 53 | 54 | bool operator!=(lldb::SBTypeFilter &rhs); 55 | 56 | protected: 57 | friend class SBDebugger; 58 | friend class SBTypeCategory; 59 | friend class SBValue; 60 | 61 | lldb::TypeFilterImplSP GetSP(); 62 | 63 | void SetSP(const lldb::TypeFilterImplSP &typefilter_impl_sp); 64 | 65 | lldb::TypeFilterImplSP m_opaque_sp; 66 | 67 | SBTypeFilter(const lldb::TypeFilterImplSP &); 68 | 69 | bool CopyOnWrite_Impl(); 70 | }; 71 | 72 | } // namespace lldb 73 | 74 | #endif // LLDB_API_SBTYPEFILTER_H 75 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBTypeFormat.h: -------------------------------------------------------------------------------- 1 | //===-- SBTypeFormat.h --------------------------------------------*- C++ 2 | //-*-===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLDB_API_SBTYPEFORMAT_H 11 | #define LLDB_API_SBTYPEFORMAT_H 12 | 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBTypeFormat { 18 | public: 19 | SBTypeFormat(); 20 | 21 | SBTypeFormat(lldb::Format format, 22 | uint32_t options = 0); // see lldb::eTypeOption values 23 | 24 | SBTypeFormat(const char *type, 25 | uint32_t options = 0); // see lldb::eTypeOption values 26 | 27 | SBTypeFormat(const lldb::SBTypeFormat &rhs); 28 | 29 | ~SBTypeFormat(); 30 | 31 | explicit operator bool() const; 32 | 33 | bool IsValid() const; 34 | 35 | lldb::Format GetFormat(); 36 | 37 | const char *GetTypeName(); 38 | 39 | uint32_t GetOptions(); 40 | 41 | void SetFormat(lldb::Format); 42 | 43 | void SetTypeName(const char *); 44 | 45 | void SetOptions(uint32_t); 46 | 47 | bool GetDescription(lldb::SBStream &description, 48 | lldb::DescriptionLevel description_level); 49 | 50 | lldb::SBTypeFormat &operator=(const lldb::SBTypeFormat &rhs); 51 | 52 | bool IsEqualTo(lldb::SBTypeFormat &rhs); 53 | 54 | bool operator==(lldb::SBTypeFormat &rhs); 55 | 56 | bool operator!=(lldb::SBTypeFormat &rhs); 57 | 58 | protected: 59 | friend class SBDebugger; 60 | friend class SBTypeCategory; 61 | friend class SBValue; 62 | 63 | lldb::TypeFormatImplSP GetSP(); 64 | 65 | void SetSP(const lldb::TypeFormatImplSP &typeformat_impl_sp); 66 | 67 | lldb::TypeFormatImplSP m_opaque_sp; 68 | 69 | SBTypeFormat(const lldb::TypeFormatImplSP &); 70 | 71 | enum class Type { eTypeKeepSame, eTypeFormat, eTypeEnum }; 72 | 73 | bool CopyOnWrite_Impl(Type); 74 | }; 75 | 76 | } // namespace lldb 77 | 78 | #endif // LLDB_API_SBTYPEFORMAT_H 79 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBTypeNameSpecifier.h: -------------------------------------------------------------------------------- 1 | //===-- SBTypeNameSpecifier.h --------------------------------------*- C++ 2 | //-*-===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLDB_API_SBTYPENAMESPECIFIER_H 11 | #define LLDB_API_SBTYPENAMESPECIFIER_H 12 | 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBTypeNameSpecifier { 18 | public: 19 | SBTypeNameSpecifier(); 20 | 21 | SBTypeNameSpecifier(const char *name, bool is_regex = false); 22 | 23 | SBTypeNameSpecifier(SBType type); 24 | 25 | SBTypeNameSpecifier(const lldb::SBTypeNameSpecifier &rhs); 26 | 27 | ~SBTypeNameSpecifier(); 28 | 29 | explicit operator bool() const; 30 | 31 | bool IsValid() const; 32 | 33 | const char *GetName(); 34 | 35 | SBType GetType(); 36 | 37 | bool IsRegex(); 38 | 39 | bool GetDescription(lldb::SBStream &description, 40 | lldb::DescriptionLevel description_level); 41 | 42 | lldb::SBTypeNameSpecifier &operator=(const lldb::SBTypeNameSpecifier &rhs); 43 | 44 | bool IsEqualTo(lldb::SBTypeNameSpecifier &rhs); 45 | 46 | bool operator==(lldb::SBTypeNameSpecifier &rhs); 47 | 48 | bool operator!=(lldb::SBTypeNameSpecifier &rhs); 49 | 50 | protected: 51 | friend class SBDebugger; 52 | friend class SBTypeCategory; 53 | 54 | lldb::TypeNameSpecifierImplSP GetSP(); 55 | 56 | void SetSP(const lldb::TypeNameSpecifierImplSP &type_namespec_sp); 57 | 58 | lldb::TypeNameSpecifierImplSP m_opaque_sp; 59 | 60 | SBTypeNameSpecifier(const lldb::TypeNameSpecifierImplSP &); 61 | }; 62 | 63 | } // namespace lldb 64 | 65 | #endif // LLDB_API_SBTYPENAMESPECIFIER_H 66 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBTypeSummary.h: -------------------------------------------------------------------------------- 1 | //===-- SBTypeSummary.h -------------------------------------------*- C++ 2 | //-*-===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLDB_API_SBTYPESUMMARY_H 11 | #define LLDB_API_SBTYPESUMMARY_H 12 | 13 | #include 14 | 15 | namespace lldb { 16 | class LLDB_API SBTypeSummaryOptions { 17 | public: 18 | SBTypeSummaryOptions(); 19 | 20 | SBTypeSummaryOptions(const lldb::SBTypeSummaryOptions &rhs); 21 | 22 | SBTypeSummaryOptions(const lldb_private::TypeSummaryOptions *lldb_object_ptr); 23 | 24 | ~SBTypeSummaryOptions(); 25 | 26 | explicit operator bool() const; 27 | 28 | bool IsValid(); 29 | 30 | lldb::LanguageType GetLanguage(); 31 | 32 | lldb::TypeSummaryCapping GetCapping(); 33 | 34 | void SetLanguage(lldb::LanguageType); 35 | 36 | void SetCapping(lldb::TypeSummaryCapping); 37 | 38 | protected: 39 | friend class SBValue; 40 | 41 | lldb_private::TypeSummaryOptions *operator->(); 42 | 43 | const lldb_private::TypeSummaryOptions *operator->() const; 44 | 45 | lldb_private::TypeSummaryOptions *get(); 46 | 47 | lldb_private::TypeSummaryOptions &ref(); 48 | 49 | const lldb_private::TypeSummaryOptions &ref() const; 50 | 51 | void SetOptions(const lldb_private::TypeSummaryOptions *lldb_object_ptr); 52 | 53 | private: 54 | std::unique_ptr m_opaque_up; 55 | }; 56 | 57 | class SBTypeSummary { 58 | public: 59 | SBTypeSummary(); 60 | 61 | // Native function summary formatter callback 62 | typedef bool (*FormatCallback)(SBValue, SBTypeSummaryOptions, SBStream &); 63 | 64 | static SBTypeSummary 65 | CreateWithSummaryString(const char *data, 66 | uint32_t options = 0); // see lldb::eTypeOption values 67 | 68 | static SBTypeSummary 69 | CreateWithFunctionName(const char *data, 70 | uint32_t options = 0); // see lldb::eTypeOption values 71 | 72 | static SBTypeSummary 73 | CreateWithScriptCode(const char *data, 74 | uint32_t options = 0); // see lldb::eTypeOption values 75 | 76 | static SBTypeSummary CreateWithCallback(FormatCallback cb, 77 | uint32_t options = 0, 78 | const char *description = nullptr); 79 | 80 | SBTypeSummary(const lldb::SBTypeSummary &rhs); 81 | 82 | ~SBTypeSummary(); 83 | 84 | explicit operator bool() const; 85 | 86 | bool IsValid() const; 87 | 88 | bool IsFunctionCode(); 89 | 90 | bool IsFunctionName(); 91 | 92 | bool IsSummaryString(); 93 | 94 | const char *GetData(); 95 | 96 | void SetSummaryString(const char *data); 97 | 98 | void SetFunctionName(const char *data); 99 | 100 | void SetFunctionCode(const char *data); 101 | 102 | uint32_t GetOptions(); 103 | 104 | void SetOptions(uint32_t); 105 | 106 | bool GetDescription(lldb::SBStream &description, 107 | lldb::DescriptionLevel description_level); 108 | 109 | lldb::SBTypeSummary &operator=(const lldb::SBTypeSummary &rhs); 110 | 111 | bool DoesPrintValue(lldb::SBValue value); 112 | 113 | bool IsEqualTo(lldb::SBTypeSummary &rhs); 114 | 115 | bool operator==(lldb::SBTypeSummary &rhs); 116 | 117 | bool operator!=(lldb::SBTypeSummary &rhs); 118 | 119 | protected: 120 | friend class SBDebugger; 121 | friend class SBTypeCategory; 122 | friend class SBValue; 123 | 124 | lldb::TypeSummaryImplSP GetSP(); 125 | 126 | void SetSP(const lldb::TypeSummaryImplSP &typefilter_impl_sp); 127 | 128 | lldb::TypeSummaryImplSP m_opaque_sp; 129 | 130 | SBTypeSummary(const lldb::TypeSummaryImplSP &); 131 | 132 | bool CopyOnWrite_Impl(); 133 | 134 | bool ChangeSummaryType(bool want_script); 135 | }; 136 | 137 | } // namespace lldb 138 | 139 | #endif // LLDB_API_SBTYPESUMMARY_H 140 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBTypeSynthetic.h: -------------------------------------------------------------------------------- 1 | //===-- SBTypeSynthetic.h -----------------------------------------*- C++ 2 | //-*-===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLDB_API_SBTYPESYNTHETIC_H 11 | #define LLDB_API_SBTYPESYNTHETIC_H 12 | 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBTypeSynthetic { 18 | public: 19 | SBTypeSynthetic(); 20 | 21 | static SBTypeSynthetic 22 | CreateWithClassName(const char *data, 23 | uint32_t options = 0); // see lldb::eTypeOption values 24 | 25 | static SBTypeSynthetic 26 | CreateWithScriptCode(const char *data, 27 | uint32_t options = 0); // see lldb::eTypeOption values 28 | 29 | SBTypeSynthetic(const lldb::SBTypeSynthetic &rhs); 30 | 31 | ~SBTypeSynthetic(); 32 | 33 | explicit operator bool() const; 34 | 35 | bool IsValid() const; 36 | 37 | bool IsClassCode(); 38 | 39 | bool IsClassName(); 40 | 41 | const char *GetData(); 42 | 43 | void SetClassName(const char *data); 44 | 45 | void SetClassCode(const char *data); 46 | 47 | uint32_t GetOptions(); 48 | 49 | void SetOptions(uint32_t); 50 | 51 | bool GetDescription(lldb::SBStream &description, 52 | lldb::DescriptionLevel description_level); 53 | 54 | lldb::SBTypeSynthetic &operator=(const lldb::SBTypeSynthetic &rhs); 55 | 56 | bool IsEqualTo(lldb::SBTypeSynthetic &rhs); 57 | 58 | bool operator==(lldb::SBTypeSynthetic &rhs); 59 | 60 | bool operator!=(lldb::SBTypeSynthetic &rhs); 61 | 62 | protected: 63 | friend class SBDebugger; 64 | friend class SBTypeCategory; 65 | friend class SBValue; 66 | 67 | lldb::ScriptedSyntheticChildrenSP GetSP(); 68 | 69 | void SetSP(const lldb::ScriptedSyntheticChildrenSP &typefilter_impl_sp); 70 | 71 | lldb::ScriptedSyntheticChildrenSP m_opaque_sp; 72 | 73 | SBTypeSynthetic(const lldb::ScriptedSyntheticChildrenSP &); 74 | 75 | bool CopyOnWrite_Impl(); 76 | }; 77 | 78 | } // namespace lldb 79 | 80 | #endif // LLDB_API_SBTYPESYNTHETIC_H 81 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBUnixSignals.h: -------------------------------------------------------------------------------- 1 | //===-- SBUnixSignals.h -----------------------------------------------*- C++ 2 | //-*-===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLDB_API_SBUNIXSIGNALS_H 11 | #define LLDB_API_SBUNIXSIGNALS_H 12 | 13 | #include 14 | 15 | namespace lldb { 16 | 17 | class LLDB_API SBUnixSignals { 18 | public: 19 | SBUnixSignals(); 20 | 21 | SBUnixSignals(const lldb::SBUnixSignals &rhs); 22 | 23 | ~SBUnixSignals(); 24 | 25 | const SBUnixSignals &operator=(const lldb::SBUnixSignals &rhs); 26 | 27 | void Clear(); 28 | 29 | explicit operator bool() const; 30 | 31 | bool IsValid() const; 32 | 33 | const char *GetSignalAsCString(int32_t signo) const; 34 | 35 | int32_t GetSignalNumberFromName(const char *name) const; 36 | 37 | bool GetShouldSuppress(int32_t signo) const; 38 | 39 | bool SetShouldSuppress(int32_t signo, bool value); 40 | 41 | bool GetShouldStop(int32_t signo) const; 42 | 43 | bool SetShouldStop(int32_t signo, bool value); 44 | 45 | bool GetShouldNotify(int32_t signo) const; 46 | 47 | bool SetShouldNotify(int32_t signo, bool value); 48 | 49 | int32_t GetNumSignals() const; 50 | 51 | int32_t GetSignalAtIndex(int32_t index) const; 52 | 53 | protected: 54 | friend class SBProcess; 55 | friend class SBPlatform; 56 | 57 | SBUnixSignals(lldb::ProcessSP &process_sp); 58 | 59 | SBUnixSignals(lldb::PlatformSP &platform_sp); 60 | 61 | lldb::UnixSignalsSP GetSP() const; 62 | 63 | void SetSP(const lldb::UnixSignalsSP &signals_sp); 64 | 65 | private: 66 | lldb::UnixSignalsWP m_opaque_wp; 67 | }; 68 | 69 | } // namespace lldb 70 | 71 | #endif // LLDB_API_SBUNIXSIGNALS_H 72 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBValueList.h: -------------------------------------------------------------------------------- 1 | //===-- SBValueList.h -------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBVALUELIST_H 10 | #define LLDB_API_SBVALUELIST_H 11 | 12 | #include 13 | 14 | class ValueListImpl; 15 | 16 | namespace lldb { 17 | 18 | class LLDB_API SBValueList { 19 | public: 20 | SBValueList(); 21 | 22 | SBValueList(const lldb::SBValueList &rhs); 23 | 24 | ~SBValueList(); 25 | 26 | explicit operator bool() const; 27 | 28 | bool IsValid() const; 29 | 30 | void Clear(); 31 | 32 | void Append(const lldb::SBValue &val_obj); 33 | 34 | void Append(const lldb::SBValueList &value_list); 35 | 36 | uint32_t GetSize() const; 37 | 38 | lldb::SBValue GetValueAtIndex(uint32_t idx) const; 39 | 40 | lldb::SBValue GetFirstValueByName(const char *name) const; 41 | 42 | lldb::SBValue FindValueObjectByUID(lldb::user_id_t uid); 43 | 44 | const lldb::SBValueList &operator=(const lldb::SBValueList &rhs); 45 | 46 | protected: 47 | // only useful for visualizing the pointer or comparing two SBValueLists to 48 | // see if they are backed by the same underlying Impl. 49 | void *opaque_ptr(); 50 | 51 | private: 52 | friend class SBFrame; 53 | 54 | SBValueList(const ValueListImpl *lldb_object_ptr); 55 | 56 | void Append(lldb::ValueObjectSP &val_obj_sp); 57 | 58 | void CreateIfNeeded(); 59 | 60 | ValueListImpl *operator->(); 61 | 62 | ValueListImpl &operator*(); 63 | 64 | const ValueListImpl *operator->() const; 65 | 66 | const ValueListImpl &operator*() const; 67 | 68 | ValueListImpl &ref(); 69 | 70 | std::unique_ptr m_opaque_up; 71 | }; 72 | 73 | } // namespace lldb 74 | 75 | #endif // LLDB_API_SBVALUELIST_H 76 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBVariablesOptions.h: -------------------------------------------------------------------------------- 1 | //===-- SBVariablesOptions.h ------------------------------------------*- C++ 2 | //-*-===// 3 | // 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 | // See https://llvm.org/LICENSE.txt for license information. 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLDB_API_SBVARIABLESOPTIONS_H 11 | #define LLDB_API_SBVARIABLESOPTIONS_H 12 | 13 | #include 14 | 15 | class VariablesOptionsImpl; 16 | 17 | namespace lldb { 18 | 19 | class LLDB_API SBVariablesOptions { 20 | public: 21 | SBVariablesOptions(); 22 | 23 | SBVariablesOptions(const SBVariablesOptions &options); 24 | 25 | SBVariablesOptions &operator=(const SBVariablesOptions &options); 26 | 27 | ~SBVariablesOptions(); 28 | 29 | explicit operator bool() const; 30 | 31 | bool IsValid() const; 32 | 33 | bool GetIncludeArguments() const; 34 | 35 | void SetIncludeArguments(bool); 36 | 37 | bool GetIncludeRecognizedArguments(const lldb::SBTarget &) const; 38 | 39 | void SetIncludeRecognizedArguments(bool); 40 | 41 | bool GetIncludeLocals() const; 42 | 43 | void SetIncludeLocals(bool); 44 | 45 | bool GetIncludeStatics() const; 46 | 47 | void SetIncludeStatics(bool); 48 | 49 | bool GetInScopeOnly() const; 50 | 51 | void SetInScopeOnly(bool); 52 | 53 | bool GetIncludeRuntimeSupportValues() const; 54 | 55 | void SetIncludeRuntimeSupportValues(bool); 56 | 57 | lldb::DynamicValueType GetUseDynamic() const; 58 | 59 | void SetUseDynamic(lldb::DynamicValueType); 60 | 61 | protected: 62 | VariablesOptionsImpl *operator->(); 63 | 64 | const VariablesOptionsImpl *operator->() const; 65 | 66 | VariablesOptionsImpl *get(); 67 | 68 | VariablesOptionsImpl &ref(); 69 | 70 | const VariablesOptionsImpl &ref() const; 71 | 72 | SBVariablesOptions(VariablesOptionsImpl *lldb_object_ptr); 73 | 74 | void SetOptions(VariablesOptionsImpl *lldb_object_ptr); 75 | 76 | private: 77 | std::unique_ptr m_opaque_up; 78 | }; 79 | 80 | } // namespace lldb 81 | 82 | #endif // LLDB_API_SBVARIABLESOPTIONS_H 83 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/SBWatchpoint.h: -------------------------------------------------------------------------------- 1 | //===-- SBWatchpoint.h ----------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_API_SBWATCHPOINT_H 10 | #define LLDB_API_SBWATCHPOINT_H 11 | 12 | #include 13 | 14 | namespace lldb { 15 | 16 | class LLDB_API SBWatchpoint { 17 | public: 18 | SBWatchpoint(); 19 | 20 | SBWatchpoint(const lldb::SBWatchpoint &rhs); 21 | 22 | SBWatchpoint(const lldb::WatchpointSP &wp_sp); 23 | 24 | ~SBWatchpoint(); 25 | 26 | const lldb::SBWatchpoint &operator=(const lldb::SBWatchpoint &rhs); 27 | 28 | explicit operator bool() const; 29 | 30 | bool operator==(const SBWatchpoint &rhs) const; 31 | 32 | bool operator!=(const SBWatchpoint &rhs) const; 33 | 34 | bool IsValid() const; 35 | 36 | SBError GetError(); 37 | 38 | watch_id_t GetID(); 39 | 40 | /// With -1 representing an invalid hardware index. 41 | int32_t GetHardwareIndex(); 42 | 43 | lldb::addr_t GetWatchAddress(); 44 | 45 | size_t GetWatchSize(); 46 | 47 | void SetEnabled(bool enabled); 48 | 49 | bool IsEnabled(); 50 | 51 | uint32_t GetHitCount(); 52 | 53 | uint32_t GetIgnoreCount(); 54 | 55 | void SetIgnoreCount(uint32_t n); 56 | 57 | const char *GetCondition(); 58 | 59 | void SetCondition(const char *condition); 60 | 61 | bool GetDescription(lldb::SBStream &description, DescriptionLevel level); 62 | 63 | void Clear(); 64 | 65 | lldb::WatchpointSP GetSP() const; 66 | 67 | void SetSP(const lldb::WatchpointSP &sp); 68 | 69 | static bool EventIsWatchpointEvent(const lldb::SBEvent &event); 70 | 71 | static lldb::WatchpointEventType 72 | GetWatchpointEventTypeFromEvent(const lldb::SBEvent &event); 73 | 74 | static lldb::SBWatchpoint GetWatchpointFromEvent(const lldb::SBEvent &event); 75 | 76 | private: 77 | friend class SBTarget; 78 | friend class SBValue; 79 | 80 | std::weak_ptr m_opaque_wp; 81 | }; 82 | 83 | } // namespace lldb 84 | 85 | #endif // LLDB_API_SBWATCHPOINT_H 86 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/lldb-defines.h: -------------------------------------------------------------------------------- 1 | //===-- lldb-defines.h ------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_LLDB_DEFINES_H 10 | #define LLDB_LLDB_DEFINES_H 11 | 12 | #include 13 | 14 | #if defined(_WIN32) 15 | #if defined(EXPORT_LIBLLDB) 16 | #define LLDB_API __declspec(dllexport) 17 | #elif defined(IMPORT_LIBLLDB) 18 | #define LLDB_API __declspec(dllimport) 19 | #else 20 | #define LLDB_API 21 | #endif 22 | #else // defined (_WIN32) 23 | #define LLDB_API 24 | #endif 25 | 26 | #if !defined(INT32_MAX) 27 | #define INT32_MAX 2147483647 28 | #endif 29 | 30 | #if !defined(UINT32_MAX) 31 | #define UINT32_MAX 4294967295U 32 | #endif 33 | 34 | #if !defined(UINT64_MAX) 35 | #define UINT64_MAX 18446744073709551615ULL 36 | #endif 37 | 38 | // LLDB version 39 | // 40 | // A build script phase can modify this version number if needed. 41 | #define LLDB_VERSION 10.0.0git 42 | #define LLDB_REVISION 10.0.0git 43 | #define LLDB_VERSION_STRING "10.0.0git" 44 | 45 | // LLDB defines 46 | #define LLDB_GENERIC_ERROR UINT32_MAX 47 | 48 | // Breakpoints 49 | #define LLDB_INVALID_BREAK_ID 0 50 | #define LLDB_DEFAULT_BREAK_SIZE 0 51 | #define LLDB_BREAK_ID_IS_VALID(bid) ((bid) != (LLDB_INVALID_BREAK_ID)) 52 | #define LLDB_BREAK_ID_IS_INTERNAL(bid) ((bid) < 0) 53 | 54 | // Watchpoints 55 | #define LLDB_INVALID_WATCH_ID 0 56 | #define LLDB_WATCH_ID_IS_VALID(uid) ((uid) != (LLDB_INVALID_WATCH_ID)) 57 | #define LLDB_WATCH_TYPE_READ (1u << 0) 58 | #define LLDB_WATCH_TYPE_WRITE (1u << 1) 59 | #define LLDB_WATCH_TYPE_IS_VALID(type) \ 60 | ((type | LLDB_WATCH_TYPE_READ) || (type | LLDB_WATCH_TYPE_WRITE)) 61 | 62 | // Generic Register Numbers 63 | #define LLDB_REGNUM_GENERIC_PC 0 // Program Counter 64 | #define LLDB_REGNUM_GENERIC_SP 1 // Stack Pointer 65 | #define LLDB_REGNUM_GENERIC_FP 2 // Frame Pointer 66 | #define LLDB_REGNUM_GENERIC_RA 3 // Return Address 67 | #define LLDB_REGNUM_GENERIC_FLAGS 4 // Processor flags register 68 | #define LLDB_REGNUM_GENERIC_ARG1 \ 69 | 5 // The register that would contain pointer size or less argument 1 (if any) 70 | #define LLDB_REGNUM_GENERIC_ARG2 \ 71 | 6 // The register that would contain pointer size or less argument 2 (if any) 72 | #define LLDB_REGNUM_GENERIC_ARG3 \ 73 | 7 // The register that would contain pointer size or less argument 3 (if any) 74 | #define LLDB_REGNUM_GENERIC_ARG4 \ 75 | 8 // The register that would contain pointer size or less argument 4 (if any) 76 | #define LLDB_REGNUM_GENERIC_ARG5 \ 77 | 9 // The register that would contain pointer size or less argument 5 (if any) 78 | #define LLDB_REGNUM_GENERIC_ARG6 \ 79 | 10 // The register that would contain pointer size or less argument 6 (if any) 80 | #define LLDB_REGNUM_GENERIC_ARG7 \ 81 | 11 // The register that would contain pointer size or less argument 7 (if any) 82 | #define LLDB_REGNUM_GENERIC_ARG8 \ 83 | 12 // The register that would contain pointer size or less argument 8 (if any) 84 | /// Invalid value definitions 85 | #define LLDB_INVALID_ADDRESS UINT64_MAX 86 | #define LLDB_INVALID_INDEX32 UINT32_MAX 87 | #define LLDB_INVALID_IVAR_OFFSET UINT32_MAX 88 | #define LLDB_INVALID_IMAGE_TOKEN UINT32_MAX 89 | #define LLDB_INVALID_MODULE_VERSION UINT32_MAX 90 | #define LLDB_INVALID_REGNUM UINT32_MAX 91 | #define LLDB_INVALID_UID UINT64_MAX 92 | #define LLDB_INVALID_PROCESS_ID 0 93 | #define LLDB_INVALID_THREAD_ID 0 94 | #define LLDB_INVALID_FRAME_ID UINT32_MAX 95 | #define LLDB_INVALID_SIGNAL_NUMBER INT32_MAX 96 | #define LLDB_INVALID_OFFSET UINT64_MAX // Must match max of lldb::offset_t 97 | #define LLDB_INVALID_LINE_NUMBER UINT32_MAX 98 | #define LLDB_INVALID_COLUMN_NUMBER 0 99 | #define LLDB_INVALID_QUEUE_ID 0 100 | 101 | /// CPU Type definitions 102 | #define LLDB_ARCH_DEFAULT "systemArch" 103 | #define LLDB_ARCH_DEFAULT_32BIT "systemArch32" 104 | #define LLDB_ARCH_DEFAULT_64BIT "systemArch64" 105 | #define LLDB_INVALID_CPUTYPE (0xFFFFFFFEu) 106 | 107 | /// Option Set definitions 108 | // FIXME: I'm sure there's some #define magic that can create all 32 sets on the 109 | // fly. That would have the added benefit of making this unreadable. 110 | #define LLDB_MAX_NUM_OPTION_SETS 32 111 | #define LLDB_OPT_SET_ALL 0xFFFFFFFFU 112 | #define LLDB_OPT_SET_1 (1U << 0) 113 | #define LLDB_OPT_SET_2 (1U << 1) 114 | #define LLDB_OPT_SET_3 (1U << 2) 115 | #define LLDB_OPT_SET_4 (1U << 3) 116 | #define LLDB_OPT_SET_5 (1U << 4) 117 | #define LLDB_OPT_SET_6 (1U << 5) 118 | #define LLDB_OPT_SET_7 (1U << 6) 119 | #define LLDB_OPT_SET_8 (1U << 7) 120 | #define LLDB_OPT_SET_9 (1U << 8) 121 | #define LLDB_OPT_SET_10 (1U << 9) 122 | #define LLDB_OPT_SET_11 (1U << 10) 123 | #define LLDB_OPT_SET_12 (1U << 11) 124 | #define LLDB_OPT_SET_FROM_TO(A, B) \ 125 | (((1U << (B)) - 1) ^ (((1U << (A)) - 1) >> 1)) 126 | 127 | #if defined(_WIN32) && !defined(MAX_PATH) 128 | #define MAX_PATH 260 129 | #endif 130 | 131 | // ignore GCC function attributes 132 | #if defined(_MSC_VER) && !defined(__clang__) 133 | #define __attribute__(X) 134 | #endif 135 | 136 | #define UNUSED_IF_ASSERT_DISABLED(x) ((void)(x)) 137 | 138 | #endif // LLDB_LLDB_DEFINES_H 139 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/lldb-public.h: -------------------------------------------------------------------------------- 1 | //===-- lldb-public.h -------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_LLDB_PUBLIC_H 10 | #define LLDB_LLDB_PUBLIC_H 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #endif // LLDB_LLDB_PUBLIC_H 18 | -------------------------------------------------------------------------------- /Sources/LLDBProcess/include/LLDB/lldb-types.h: -------------------------------------------------------------------------------- 1 | //===-- lldb-types.h --------------------------------------------*- C++ -*-===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #ifndef LLDB_LLDB_TYPES_H 10 | #define LLDB_LLDB_TYPES_H 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | // All host systems must define: 18 | // lldb::thread_t The native thread type for spawned threads on the 19 | // system 20 | // lldb::thread_arg_t The type of the one any only thread creation 21 | // argument for the host system 22 | // lldb::thread_result_t The return type that gets returned when a thread 23 | // finishes. 24 | // lldb::thread_func_t The function prototype used to spawn a thread on the 25 | // host system. 26 | // #define LLDB_INVALID_PROCESS_ID ... 27 | // #define LLDB_INVALID_THREAD_ID ... 28 | // #define LLDB_INVALID_HOST_THREAD ... 29 | 30 | // TODO: Add a bunch of ifdefs to determine the host system and what 31 | // things should be defined. Currently MacOSX is being assumed by default since 32 | // that is what lldb was first developed for. 33 | 34 | #ifdef _WIN32 35 | 36 | #include 37 | 38 | namespace lldb { 39 | typedef void *rwlock_t; 40 | typedef void *process_t; // Process type is HANDLE 41 | typedef void *thread_t; // Host thread type 42 | typedef void *file_t; // Host file type 43 | typedef unsigned int __w64 socket_t; // Host socket type 44 | typedef void *thread_arg_t; // Host thread argument type 45 | typedef unsigned thread_result_t; // Host thread result type 46 | typedef thread_result_t (*thread_func_t)(void *); // Host thread function type 47 | typedef void *pipe_t; // Host pipe type is HANDLE 48 | } // namespace lldb 49 | 50 | #else 51 | 52 | #include 53 | 54 | namespace lldb { 55 | // MacOSX Types 56 | typedef pthread_rwlock_t rwlock_t; 57 | typedef uint64_t process_t; // Process type is just a pid. 58 | typedef pthread_t thread_t; // Host thread type 59 | typedef int file_t; // Host file type 60 | typedef int socket_t; // Host socket type 61 | typedef void *thread_arg_t; // Host thread argument type 62 | typedef void *thread_result_t; // Host thread result type 63 | typedef void *(*thread_func_t)(void *); // Host thread function type 64 | typedef int pipe_t; // Host pipe type 65 | } // namespace lldb 66 | 67 | #endif 68 | 69 | namespace lldb { 70 | typedef void (*LogOutputCallback)(const char *, void *baton); 71 | typedef bool (*CommandOverrideCallback)(void *baton, const char **argv); 72 | typedef bool (*CommandOverrideCallbackWithResult)( 73 | void *baton, const char **argv, lldb_private::CommandReturnObject &result); 74 | typedef bool (*ExpressionCancelCallback)(ExpressionEvaluationPhase phase, 75 | void *baton); 76 | } // namespace lldb 77 | 78 | #define LLDB_INVALID_PROCESS ((lldb::process_t)-1) 79 | #define LLDB_INVALID_HOST_THREAD ((lldb::thread_t)NULL) 80 | #define LLDB_INVALID_PIPE ((lldb::pipe_t)-1) 81 | 82 | namespace lldb { 83 | typedef uint64_t addr_t; 84 | typedef uint64_t user_id_t; 85 | typedef uint64_t pid_t; 86 | typedef uint64_t tid_t; 87 | typedef uint64_t offset_t; 88 | typedef int32_t break_id_t; 89 | typedef int32_t watch_id_t; 90 | typedef void *opaque_compiler_type_t; 91 | typedef uint64_t queue_id_t; 92 | } // namespace lldb 93 | 94 | #endif // LLDB_LLDB_TYPES_H 95 | -------------------------------------------------------------------------------- /Sources/include/EnableIPythonDisplay.swift: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #if canImport(PythonKit) 16 | import PythonKit 17 | 18 | // These symbols disappear from the Swift interpreter after the file finishes 19 | // executing. 20 | import func Glibc.dlopen 21 | import func Glibc.dlsym 22 | 23 | /// Hooks IPython to the KernelCommunicator, so that it can send display 24 | /// messages to Jupyter. 25 | enum IPythonDisplay { 26 | static var socket: PythonObject = Python.None 27 | static var shell: PythonObject = Python.None 28 | } 29 | 30 | extension IPythonDisplay { 31 | private static func bytes(_ py: PythonObject) -> KernelCommunicator.BytesReference { 32 | guard let bytes = PythonBytes(py) else { 33 | fatalError("Could not convert object \(py) to `PythonBytes`.") 34 | } 35 | let address = bytes.withUnsafeBytes { $0 }.bindMemory(to: CChar.self) 36 | return KernelCommunicator.BytesReference(address) 37 | } 38 | 39 | private static func updateParentMessage(to parentMessage: KernelCommunicator.ParentMessage) { 40 | let json = Python.import("json") 41 | IPythonDisplay.shell.set_parent(json.loads(parentMessage.json)) 42 | } 43 | 44 | private static func consumeDisplayMessages() -> [KernelCommunicator.JupyterDisplayMessage] { 45 | let displayMessages = IPythonDisplay.socket.messages.map { 46 | KernelCommunicator.JupyterDisplayMessage(parts: $0.map(bytes)) 47 | } 48 | IPythonDisplay.socket.messages = [] 49 | return displayMessages 50 | } 51 | 52 | static func enable() { 53 | if IPythonDisplay.shell != Python.None { 54 | print("Warning: IPython display already enabled.") 55 | return 56 | } 57 | 58 | let /*Glibc.*/RTLD_LAZY = Int32(1) 59 | let libAddress = dlopen("/opt/swift/lib/libJupyterKernel.so", RTLD_LAZY) 60 | let funcAddress = dlsym(libAddress, "create_shell") 61 | let create_shell = unsafeBitCast(funcAddress, to: (@convention(c) ( 62 | UnsafePointer, UnsafePointer, UnsafePointer) -> Int64 63 | ).self) 64 | 65 | let session = JupyterKernel.communicator.jupyterSession 66 | let socketAndShellID = create_shell( 67 | session.username, session.id, session.key 68 | ) 69 | 70 | let _ctypes = Python.import("_ctypes") 71 | let socketAndShell = _ctypes.PyObj_FromPtr(socketAndShellID) 72 | IPythonDisplay.socket = socketAndShell[0] 73 | IPythonDisplay.shell = socketAndShell[1] 74 | } 75 | } 76 | 77 | // This workaround stops the debugger from duplicating the symbol `display` 78 | // while processing the code inside `Plot.display(size:)` 79 | extension IPythonDisplay { 80 | static func display(base64EncodedPNG: String) { 81 | let display = Python.import("IPython.display") 82 | let codecs = Python.import("codecs") 83 | let Image = display.Image 84 | 85 | let imageData = codecs.decode( 86 | Python.bytes(base64EncodedPNG, encoding: "utf8"), encoding: "base64") 87 | display.display(Image(data: imageData, format: "png")) 88 | } 89 | } 90 | 91 | // Global function for displaying base64 images in the notebook. 92 | func display(base64EncodedPNG: String) { 93 | IPythonDisplay.display(base64EncodedPNG: base64EncodedPNG) 94 | } 95 | 96 | #if canImport(SwiftPlot) && canImport(AGGRenderer) 97 | import SwiftPlot 98 | import AGGRenderer 99 | 100 | // Extend `Plot` to create an instance member that utilizes `Plot.drawGraph`. 101 | extension Plot { 102 | func display(size: Size = Size(width: 1000, height: 660)) { 103 | let renderer = AGGRenderer() 104 | self.drawGraph(size: size, renderer: renderer) 105 | 106 | IPythonDisplay.display(base64EncodedPNG: renderer.base64Png()) 107 | } 108 | } 109 | #endif 110 | 111 | IPythonDisplay.enable() 112 | #endif 113 | -------------------------------------------------------------------------------- /Sources/include/KernelCommunicator.swift: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // These symbols disappear from the Swift interpreter after the file finishes 16 | // executing. 17 | import func Glibc.dlopen 18 | import func Glibc.dlsym 19 | 20 | /// A struct with functions that the kernel and the code running inside the 21 | /// kernel use to talk to each other. 22 | /// 23 | /// Note that it would be more Jupyter-y for the communication to happen over 24 | /// ZeroMQ. This is not currently possible, because ZeroMQ sends messages 25 | /// asynchronously using IO threads, and LLDB pauses those IO threads, which 26 | /// prevents them from sending the messages. 27 | struct KernelCommunicator { 28 | let jupyterSession: JupyterSession 29 | 30 | private var previousDisplayMessages: [JupyterDisplayMessage]? 31 | 32 | private let libJupyterKernel = dlopen( 33 | "/opt/swift/lib/libJupyterKernel.so", /*RTLD_LAZY*/Int32(1))! 34 | 35 | init(jupyterSession: JupyterSession) { 36 | self.jupyterSession = jupyterSession 37 | 38 | // See "Sources/JupyterKernel/SwiftShell.swift" for an explanation of this 39 | // workaround. 40 | callSymbol("prevent_numpy_import_hang") 41 | 42 | // Fetch pipes before executing any other Swift code for safe measure. This 43 | // may not be needed. 44 | callSymbol("fetch_pipes") 45 | 46 | // Overwrite implementation of `google.colab._message.blocking_request`. 47 | callSymbol("redirect_stdin") 48 | } 49 | 50 | private func callSymbol(_ name: String) { 51 | let address = dlsym(libJupyterKernel, name)! 52 | let symbol = unsafeBitCast(address, to: (@convention(c) () -> Void).self) 53 | symbol() 54 | } 55 | 56 | func fetchPipes() { 57 | callSymbol("fetch_pipes") 58 | } 59 | 60 | /// The kernel calls this when the parent message changes. 61 | mutating func updateParentMessage(to parentMessage: ParentMessage) { 62 | let address = dlsym(libJupyterKernel, "update_parent_message")! 63 | let symbol = unsafeBitCast(address, to: (@convention(c) ( 64 | UnsafePointer) -> Void 65 | ).self) 66 | symbol(parentMessage.json) 67 | } 68 | 69 | /// A single serialized display message for the Jupyter client. 70 | /// Corresponds to a ZeroMQ "multipart message". 71 | struct JupyterDisplayMessage { 72 | let parts: [BytesReference] 73 | } 74 | 75 | /// A reference to memory containing bytes. 76 | /// 77 | /// As long as there is a strong reference to an instance, that instance's 78 | /// `unsafeBufferPointer` refers to memory containing the bytes passed to 79 | /// that instance's constructor. 80 | /// 81 | /// We use this so that we can give the kernel a memory location that it can 82 | /// read bytes from. 83 | class BytesReference { 84 | private var bytes: ContiguousArray 85 | 86 | init(_ bytes: UnsafeBufferPointer) { 87 | // Construct our own array and copy `bytes` into it, so that no one 88 | // else aliases the underlying memory. 89 | self.bytes = [] 90 | self.bytes.append(contentsOf: bytes) 91 | } 92 | 93 | var unsafeBufferPointer: UnsafeBufferPointer { 94 | // We have tried very hard to make the pointer stay valid outside the 95 | // closure: 96 | // - No one else aliases the underlying memory. 97 | // - The comment on this class reminds users that the memory may become 98 | // invalid after all references to the BytesReference instance are 99 | // released. 100 | return bytes.withUnsafeBufferPointer { $0 } 101 | } 102 | } 103 | 104 | /// ParentMessage identifies the request that causes things to happen. 105 | /// This lets Jupyter, for example, know which cell to display graphics 106 | /// messages in. 107 | struct ParentMessage { 108 | let json: String 109 | } 110 | 111 | /// The data necessary to identify and sign outgoing jupyter messages. 112 | struct JupyterSession { 113 | let id: String 114 | let key: String 115 | let username: String 116 | } 117 | } 118 | --------------------------------------------------------------------------------