xref: /openbsd-src/gnu/llvm/lldb/docs/resources/build.rst (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1Building
2========
3
4.. contents::
5   :local:
6
7Getting the Sources
8-------------------
9
10Please refer to the `LLVM Getting Started Guide
11<https://llvm.org/docs/GettingStarted.html#getting-started-with-llvm>`_ for
12general instructions on how to check out the LLVM monorepo, which contains the
13LLDB sources.
14
15Git browser: https://github.com/llvm/llvm-project/tree/main/lldb
16
17Preliminaries
18-------------
19
20LLDB relies on many of the technologies developed by the larger LLVM project.
21In particular, it requires both Clang and LLVM itself in order to build. Due to
22this tight integration the Getting Started guides for both of these projects
23come as prerequisite reading:
24
25* `LLVM <https://llvm.org/docs/GettingStarted.html>`_
26* `Clang <http://clang.llvm.org/get_started.html>`_
27
28The following requirements are shared on all platforms.
29
30* `CMake <https://cmake.org>`_
31* `Ninja <https://ninja-build.org>`_ (strongly recommended)
32
33If you want to run the test suite, you'll need to build LLDB with Python
34scripting support.
35
36* `Python <http://www.python.org/>`_
37* `SWIG <http://swig.org/>`_ 3 or later.
38
39Optional Dependencies
40*********************
41
42Although the following dependencies are optional, they have a big impact on
43LLDB's functionality. It is strongly encouraged to build LLDB with these
44dependencies enabled.
45
46By default they are auto-detected: if CMake can find the dependency it will be
47used. It is possible to override this behavior by setting the corresponding
48CMake flag to ``On`` or ``Off`` to force the dependency to be enabled or
49disabled. When a dependency is set to ``On`` and can't be found it will cause a
50CMake configuration error.
51
52+-------------------+------------------------------------------------------+--------------------------+
53| Feature           | Description                                          | CMake Flag               |
54+===================+======================================================+==========================+
55| Editline          | Generic line editing, history, Emacs and Vi bindings | ``LLDB_ENABLE_LIBEDIT``  |
56+-------------------+------------------------------------------------------+--------------------------+
57| Curses            | Text user interface                                  | ``LLDB_ENABLE_CURSES``   |
58+-------------------+------------------------------------------------------+--------------------------+
59| LZMA              | Lossless data compression                            | ``LLDB_ENABLE_LZMA``     |
60+-------------------+------------------------------------------------------+--------------------------+
61| Libxml2           | XML                                                  | ``LLDB_ENABLE_LIBXML2``  |
62+-------------------+------------------------------------------------------+--------------------------+
63| Python            | Python scripting                                     | ``LLDB_ENABLE_PYTHON``   |
64+-------------------+------------------------------------------------------+--------------------------+
65| Lua               | Lua scripting                                        | ``LLDB_ENABLE_LUA``      |
66+-------------------+------------------------------------------------------+--------------------------+
67
68Depending on your platform and package manager, one might run any of the
69commands below.
70
71::
72
73  $ yum install libedit-devel libxml2-devel ncurses-devel python-devel swig
74  $ sudo apt-get install build-essential swig python3-dev libedit-dev libncurses5-dev
75  $ pkg install swig python
76  $ pkgin install swig python36 cmake ninja-build
77  $ brew install swig cmake ninja
78
79Note that there's an `incompatibility
80<https://github.com/swig/swig/issues/1321>`_ between Python version 3.7 and later
81and swig versions older than 4.0.0 which makes builds of LLDB using debug
82versions of python unusable. This primarily affects Windows, as debug builds of
83LLDB must use debug python as well.
84
85
86Windows
87*******
88
89* Visual Studio 2019.
90* The latest Windows SDK.
91* The Active Template Library (ATL).
92* `GnuWin32 <http://gnuwin32.sourceforge.net/>`_ for CoreUtils and Make.
93* `Python 3 <https://www.python.org/downloads/windows/>`_.  Make sure to (1) get
94  the x64 variant if that's what you're targetting and (2) install the debug
95  library if you want to build a debug lldb. The standalone installer is the
96  easiest way to get the debug library.
97* `Python Tools for Visual Studio
98  <https://github.com/Microsoft/PTVS/>`_. If you plan to debug test failures
99  or even write new tests at all, PTVS is an indispensable debugging
100  extension to VS that enables full editing and debugging support for Python
101  (including mixed native/managed debugging).
102* `SWIG for Windows <http://www.swig.org/download.html>`_
103
104The steps outlined here describes how to set up your system and install the
105required dependencies such that they can be found when needed during the build
106process. They only need to be performed once.
107
108#. Install Visual Studio with the "Desktop Development with C++" workload and
109   the "Python Development" workload.
110#. Install GnuWin32, making sure ``<GnuWin32 install dir>\bin`` is added to
111   your PATH environment variable. Verify that utilities like ``dirname`` and
112   ``make`` are available from your terminal.
113#. Install SWIG for Windows, making sure ``<SWIG install dir>`` is added to
114   your PATH environment variable. Verify that ``swig`` is available from your
115   terminal.
116#. Install Python 3 from the standalone installer and include the debug libraries
117   in the install, making sure the Python install path is added to your PATH
118   environment variable.
119#. Register the Debug Interface Access DLLs with the Registry from a privileged
120   terminal.
121
122::
123
124> regsvr32 "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\DIA SDK\bin\msdia140.dll"
125> regsvr32 "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\DIA SDK\bin\amd64\msdia140.dll"
126
127Any command prompt from which you build LLDB should have a valid Visual Studio
128environment setup. This means you should open an appropriate `Developer Command
129Prompt for VS <https://docs.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell?view=vs-2019>`_
130corresponding to the version you wish to use or run ``vcvarsall.bat`` or
131``VsDevCmd.bat``.
132
133macOS
134*****
135
136* To use the in-tree debug server on macOS, lldb needs to be code signed. For
137  more information see :ref:`CodeSigning` below.
138* If you are building both Clang and LLDB together, be sure to also check out
139  libc++, which is a required for testing on macOS.
140
141Building LLDB with CMake
142------------------------
143
144The LLVM project is migrating to a single monolithic repository for LLVM and
145its subprojects. This is the recommended way to build LLDB. Check out the
146source-tree with git:
147
148::
149
150  $ git clone https://github.com/llvm/llvm-project.git
151
152CMake is a cross-platform build-generator tool. CMake does not build the
153project, it generates the files needed by your build tool. The recommended
154build tool for LLVM is Ninja, but other generators like Xcode or Visual Studio
155may be used as well. Please also read `Building LLVM with CMake
156<https://llvm.org/docs/CMake.html>`_.
157
158Regular in-tree builds
159**********************
160
161Create a new directory for your build-tree. From there run CMake and point it
162to the ``llvm`` directory in the source-tree:
163
164::
165
166  $ cmake -G Ninja -DLLVM_ENABLE_PROJECTS="clang;lldb" [<cmake options>] path/to/llvm-project/llvm
167
168We used the ``LLVM_ENABLE_PROJECTS`` option here to tell the build-system which
169subprojects to build in addition to LLVM (for more options see
170:ref:`CommonCMakeOptions` and :ref:`CMakeCaches`). Parts of the LLDB test suite
171require ``lld``. Add it to the list in order to run all tests. Once CMake is done,
172run ninja to perform the actual build.
173
174::
175
176  $ ninja lldb lldb-server
177
178If you only want lldb, or are on a platform where lldb-server is not supported,
179you can pass just ``lldb``. Ninja will only build what is necessary to run the
180lldb driver:
181
182::
183
184  $ ninja lldb
185
186Standalone builds
187*****************
188
189This is another way to build LLDB. We can use the same source-tree as we
190checked out above, but now we will have multiple build-trees:
191
192* the main build-tree for LLDB in ``/path/to/lldb-build``
193* one or more provided build-trees for LLVM and Clang; for simplicity we use a
194  single one in ``/path/to/llvm-build``
195
196Run CMake with ``-B`` pointing to a new directory for the provided
197build-tree\ :sup:`1` and the positional argument pointing to the ``llvm``
198directory in the source-tree. Note that we leave out LLDB here and only include
199Clang. Then we build the ``ALL`` target with ninja:
200
201::
202
203  $ cmake -B /path/to/llvm-build -G Ninja \
204          -DLLVM_ENABLE_PROJECTS=clang \
205          [<more cmake options>] /path/to/llvm-project/llvm
206  $ ninja
207
208Now run CMake a second time with ``-B`` pointing to a new directory for the
209main build-tree and the positional argument pointing to the ``lldb`` directory
210in the source-tree. In order to find the provided build-tree, the build system
211looks for the path to its CMake modules in ``LLVM_DIR``. If you use a separate
212build directory for Clang, remember to pass its module path via ``Clang_DIR``
213(CMake variables are case-sensitive!):
214
215::
216
217  $ cmake -B /path/to/lldb-build -G Ninja \
218          -DLLVM_DIR=/path/to/llvm-build/lib/cmake/llvm \
219          [<more cmake options>] /path/to/llvm-project/lldb
220  $ ninja lldb lldb-server
221
222If you do not require or cannot build ``lldb-server`` on your platform, simply
223remove it from the Ninja command.
224
225.. note::
226
227   #. The ``-B`` argument was undocumented for a while and is only officially
228      supported since `CMake version 3.14
229      <https://cmake.org/cmake/help/v3.14/release/3.14.html#command-line>`_
230
231.. _CommonCMakeOptions:
232
233Common CMake options
234********************
235
236Following is a description of some of the most important CMake variables which
237you are likely to encounter. A variable FOO is set by adding ``-DFOO=value`` to
238the CMake command line.
239
240If you want to debug the lldb that you're building -- that is, build it with
241debug info enabled -- pass two additional arguments to cmake before running
242ninja:
243
244::
245
246  $ cmake -G Ninja \
247      -DLLDB_EXPORT_ALL_SYMBOLS=1 \
248      -DCMAKE_BUILD_TYPE=Debug
249      <path to root of llvm source tree>
250
251If you want to run the test suite, you will need a compiler to build the test
252programs. If you have Clang checked out, that will be used by default.
253Alternatively, you can specify a C and C++ compiler to be used by the test
254suite.
255
256::
257
258  $ cmake -G Ninja \
259      -DLLDB_TEST_COMPILER=<path to C compiler> \
260      <path to root of llvm source tree>
261
262It is strongly recommend to use a release build for the compiler to speed up
263test execution.
264
265Windows
266^^^^^^^
267
268On Windows the LLDB test suite requires lld. Either add ``lld`` to
269``LLVM_ENABLE_PROJECTS`` or disable the test suite with
270``LLDB_INCLUDE_TESTS=OFF``.
271
272Although the following CMake variables are by no means Windows specific, they
273are commonly used on Windows.
274
275* ``LLDB_TEST_DEBUG_TEST_CRASHES`` (Default=0): If set to 1, will cause Windows
276  to generate a crash dialog whenever lldb.exe or the python extension module
277  crashes while running the test suite. If set to 0, LLDB will silently crash.
278  Setting to 1 allows a developer to attach a JIT debugger at the time of a
279  crash, rather than having to reproduce a failure or use a crash dump.
280* ``PYTHON_HOME`` (Required): Path to the folder where the Python distribution
281  is installed. For example, ``C:\Python35``.
282* ``LLDB_RELOCATABLE_PYTHON`` (Default=0): When this is 0, LLDB will bind
283  statically to the location specified in the ``PYTHON_HOME`` CMake variable,
284  ignoring any value of ``PYTHONHOME`` set in the environment. This is most
285  useful for developers who simply want to run LLDB after they build it. If you
286  wish to move a build of LLDB to a different machine where Python will be in a
287  different location, setting ``LLDB_RELOCATABLE_PYTHON`` to 1 will cause
288  Python to use its default mechanism for finding the python installation at
289  runtime (looking for installed Pythons, or using the ``PYTHONHOME``
290  environment variable if it is specified).
291
292Sample command line:
293
294::
295
296  $ cmake -G Ninja^
297      -DLLDB_TEST_DEBUG_TEST_CRASHES=1^
298      -DPYTHON_HOME=C:\Python35^
299      -DLLDB_TEST_COMPILER=d:\src\llvmbuild\ninja_release\bin\clang.exe^
300      <path to root of llvm source tree>
301
302
303Building with ninja is both faster and simpler than building with Visual Studio,
304but chances are you still want to debug LLDB with an IDE. One solution is to run
305cmake twice and generate the output into two different folders. One for
306compiling (the ninja folder), and one for editing, browsing and debugging.
307
308Follow the previous instructions in one directory, and generate a Visual Studio
309project in another directory.
310
311::
312
313  $ cmake -G "Visual Studio 16 2019" -A x64 -T host=x64 <cmake variables> <path to root of llvm source tree>
314
315Then you can open the .sln file in Visual Studio, set lldb as the startup
316project, and use F5 to run it. You need only edit the project settings to set
317the executable and the working directory to point to binaries inside of the
318ninja tree.
319
320
321macOS
322^^^^^
323
324On macOS the LLDB test suite requires libc++. Either add
325``LLVM_ENABLE_RUNTIMES="libcxx;libcxxabi"`` or disable the test suite with
326``LLDB_INCLUDE_TESTS=OFF``. Further useful options:
327
328* ``LLDB_BUILD_FRAMEWORK:BOOL``: Builds the LLDB.framework.
329* ``LLDB_CODESIGN_IDENTITY:STRING``: Set the identity to use for code-signing
330  all executables. If not explicitly specified, only ``debugserver`` will be
331  code-signed with identity ``lldb_codesign`` (see :ref:`CodeSigning`).
332* ``LLDB_USE_SYSTEM_DEBUGSERVER:BOOL``: Use the system's debugserver, so lldb is
333  functional without setting up code-signing.
334
335
336.. _CMakeCaches:
337
338CMake caches
339************
340
341CMake caches allow to store common sets of configuration options in the form of
342CMake scripts and can be useful to reproduce builds for particular use-cases
343(see by analogy `usage in LLVM and Clang <https://llvm.org/docs/AdvancedBuilds.html>`_).
344A cache is passed to CMake with the ``-C`` flag, following the absolute path to
345the file on disk. Subsequent ``-D`` options are still allowed. Please find the
346currently available caches in the `lldb/cmake/caches/
347<https://github.com/llvm/llvm-project/tree/main/lldb/cmake/caches>`_
348directory.
349
350Common configurations on macOS
351^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
352
353Build, test and install a distribution of LLDB from the `monorepo
354<https://github.com/llvm/llvm-project>`_ (see also `Building a Distribution of
355LLVM <https://llvm.org/docs/BuildingADistribution.html>`_):
356
357::
358
359  $ git clone https://github.com/llvm/llvm-project
360
361  $ cmake -B /path/to/lldb-build -G Ninja \
362          -C /path/to/llvm-project/lldb/cmake/caches/Apple-lldb-macOS.cmake \
363          -DLLVM_ENABLE_PROJECTS="clang;lldb" \
364          -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
365          llvm-project/llvm
366
367  $ DESTDIR=/path/to/lldb-install ninja -C /path/to/lldb-build check-lldb install-distribution
368
369.. _CMakeGeneratedXcodeProject:
370
371Build LLDB standalone for development with Xcode:
372
373::
374
375  $ git clone https://github.com/llvm/llvm-project
376
377  $ cmake -B /path/to/llvm-build -G Ninja \
378          -C /path/to/llvm-project/lldb/cmake/caches/Apple-lldb-base.cmake \
379          -DLLVM_ENABLE_PROJECTS="clang" \
380          -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
381          llvm-project/llvm
382  $ ninja -C /path/to/llvm-build
383
384  $ cmake -B /path/to/lldb-build \
385          -C /path/to/llvm-project/lldb/cmake/caches/Apple-lldb-Xcode.cmake \
386          -DLLVM_DIR=/path/to/llvm-build/lib/cmake/llvm \
387          llvm-project/lldb
388  $ open lldb.xcodeproj
389  $ cmake --build /path/to/lldb-build --target check-lldb
390
391.. note::
392
393   The ``-B`` argument was undocumented for a while and is only officially
394   supported since `CMake version 3.14
395   <https://cmake.org/cmake/help/v3.14/release/3.14.html#command-line>`_
396
397
398Building the Documentation
399--------------------------
400
401If you wish to build the optional (reference) documentation, additional
402dependencies are required:
403
404* Sphinx (for the website and the Python API reference)
405* Graphviz (for the 'dot' tool)
406* doxygen (if you wish to build the C++ API reference)
407
408To install the prerequisites for building the documentation (on Debian/Ubuntu)
409do:
410
411::
412
413  $ sudo apt-get install doxygen graphviz python3-sphinx
414
415To build the documentation, configure with ``LLVM_ENABLE_SPHINX=ON`` and build the desired target(s).
416
417::
418
419  $ ninja docs-lldb-html
420  $ ninja docs-lldb-man
421  $ ninja lldb-cpp-doc
422
423Cross-compiling LLDB
424--------------------
425
426In order to debug remote targets running different architectures than your
427host, you will need to compile LLDB (or at least the server component) for the
428target. While the easiest solution is to just compile it locally on the target,
429this is often not feasible, and in these cases you will need to cross-compile
430LLDB on your host.
431
432Cross-compilation is often a daunting task and has a lot of quirks which depend
433on the exact host and target architectures, so it is not possible to give a
434universal guide which will work on all platforms. However, here we try to
435provide an overview of the cross-compilation process along with the main things
436you should look out for.
437
438First, you will need a working toolchain which is capable of producing binaries
439for the target architecture. Since you already have a checkout of clang and
440lldb, you can compile a host version of clang in a separate folder and use
441that. Alternatively you can use system clang or even cross-gcc if your
442distribution provides such packages (e.g., ``g++-aarch64-linux-gnu`` on
443Ubuntu).
444
445Next, you will need a copy of the required target headers and libraries on your
446host. The libraries can be usually obtained by copying from the target machine,
447however the headers are often not found there, especially in case of embedded
448platforms. In this case, you will need to obtain them from another source,
449either a cross-package if one is available, or cross-compiling the respective
450library from source. Fortunately the list of LLDB dependencies is not big and
451if you are only interested in the server component, you can reduce this even
452further by passing the appropriate cmake options, such as:
453
454::
455
456  -DLLDB_ENABLE_PYTHON=0
457  -DLLDB_ENABLE_LIBEDIT=0
458  -DLLDB_ENABLE_CURSES=0
459  -DLLVM_ENABLE_TERMINFO=0
460
461In this case you, will often not need anything other than the standard C and
462C++ libraries.
463
464Once all of the dependencies are in place, it's just a matter of configuring
465the build system with the locations and arguments of all the necessary tools.
466The most important cmake options here are:
467
468* ``CMAKE_CROSSCOMPILING`` : Set to 1 to enable cross-compilation.
469* ``CMAKE_LIBRARY_ARCHITECTURE`` : Affects the cmake search path when looking
470  for libraries. You may need to set this to your architecture triple if you do
471  not specify all your include and library paths explicitly.
472* ``CMAKE_C_COMPILER``, ``CMAKE_CXX_COMPILER`` : C and C++ compilers for the
473  target architecture
474* ``CMAKE_C_FLAGS``, ``CMAKE_CXX_FLAGS`` : The flags for the C and C++ target
475  compilers. You may need to specify the exact target cpu and abi besides the
476  include paths for the target headers.
477* ``CMAKE_EXE_LINKER_FLAGS`` : The flags to be passed to the linker. Usually
478  just a list of library search paths referencing the target libraries.
479* ``LLVM_TABLEGEN``, ``CLANG_TABLEGEN`` : Paths to llvm-tblgen and clang-tblgen
480  for the host architecture. If you already have built clang for the host, you
481  can point these variables to the executables in your build directory. If not,
482  you will need to build the llvm-tblgen and clang-tblgen host targets at
483  least.
484* ``LLVM_HOST_TRIPLE`` : The triple of the system that lldb (or lldb-server)
485  will run on. Not setting this (or setting it incorrectly) can cause a lot of
486  issues with remote debugging as a lot of the choices lldb makes depend on the
487  triple reported by the remote platform.
488
489You can of course also specify the usual cmake options like
490``CMAKE_BUILD_TYPE``, etc.
491
492Example 1: Cross-compiling for linux arm64 on Ubuntu host
493*********************************************************
494
495Ubuntu already provides the packages necessary to cross-compile LLDB for arm64.
496It is sufficient to install packages ``gcc-aarch64-linux-gnu``,
497``g++-aarch64-linux-gnu``, ``binutils-aarch64-linux-gnu``. Then it is possible
498to prepare the cmake build with the following parameters:
499
500::
501
502  -DCMAKE_CROSSCOMPILING=1 \
503  -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \
504  -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \
505  -DLLVM_HOST_TRIPLE=aarch64-unknown-linux-gnu \
506  -DLLVM_TABLEGEN=<path-to-host>/bin/llvm-tblgen \
507  -DCLANG_TABLEGEN=<path-to-host>/bin/clang-tblgen \
508  -DLLDB_ENABLE_PYTHON=0 \
509  -DLLDB_ENABLE_LIBEDIT=0 \
510  -DLLDB_ENABLE_CURSES=0
511
512An alternative (and recommended) way to compile LLDB is with clang.
513Unfortunately, clang is not able to find all the include paths necessary for a
514successful cross-compile, so we need to help it with a couple of CFLAGS
515options. In my case it was sufficient to add the following arguments to
516``CMAKE_C_FLAGS`` and ``CMAKE_CXX_FLAGS`` (in addition to changing
517``CMAKE_C(XX)_COMPILER`` to point to clang compilers):
518
519::
520
521  -target aarch64-linux-gnu \
522  -I /usr/aarch64-linux-gnu/include/c++/4.8.2/aarch64-linux-gnu \
523  -I /usr/aarch64-linux-gnu/include
524
525If you wanted to build a full version of LLDB and avoid passing
526``-DLLDB_ENABLE_PYTHON=0`` and other options, you would need to obtain the
527target versions of the respective libraries. The easiest way to achieve this is
528to use the qemu-debootstrap utility, which can prepare a system image using
529qemu and chroot to simulate the target environment. Then you can install the
530necessary packages in this environment (python-dev, libedit-dev, etc.) and
531point your compiler to use them using the correct -I and -L arguments.
532
533Example 2: Cross-compiling for Android on Linux
534***********************************************
535
536In the case of Android, the toolchain and all required headers and libraries
537are available in the Android NDK.
538
539The NDK also contains a cmake toolchain file, which makes configuring the build
540much simpler. The compiler, include and library paths will be configured by the
541toolchain file and all you need to do is to select the architecture
542(ANDROID_ABI) and platform level (``ANDROID_PLATFORM``, should be at least 21).
543You will also need to set ``ANDROID_ALLOW_UNDEFINED_SYMBOLS=On``, as the
544toolchain file defaults to "no undefined symbols in shared libraries", which is
545not compatible with some llvm libraries. The first version of NDK which
546supports this approach is r14.
547
548For example, the following arguments are sufficient to configure an android
549arm64 build:
550
551::
552
553  -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \
554  -DANDROID_ABI=arm64-v8a \
555  -DANDROID_PLATFORM=android-21 \
556  -DANDROID_ALLOW_UNDEFINED_SYMBOLS=On \
557  -DLLVM_HOST_TRIPLE=aarch64-unknown-linux-android \
558  -DCROSS_TOOLCHAIN_FLAGS_NATIVE='-DCMAKE_C_COMPILER=cc;-DCMAKE_CXX_COMPILER=c++'
559
560Note that currently only lldb-server is functional on android. The lldb client
561is not supported and unlikely to work.
562
563Verifying Python Support
564------------------------
565
566LLDB has a Python scripting capability and supplies its own Python module named
567lldb. If a script is run inside the command line lldb application, the Python
568module is made available automatically. However, if a script is to be run by a
569Python interpreter outside the command line application, the ``PYTHONPATH``
570environment variable can be used to let the Python interpreter find the lldb
571module.
572
573The correct path can be obtained by invoking the command line lldb tool with
574the -P flag:
575
576::
577
578  $ export PYTHONPATH=`$llvm/build/Debug+Asserts/bin/lldb -P`
579
580If you used a different build directory or made a release build, you may need
581to adjust the above to suit your needs. To test that the lldb Python module is
582built correctly and is available to the default Python interpreter, run:
583
584::
585
586  $ python -c 'import lldb'
587
588
589Make sure you're using the Python interpreter that matches the Python library
590you linked against. For more details please refer to the :ref:`caveats
591<python_caveat>`.
592
593.. _CodeSigning:
594
595Code Signing on macOS
596---------------------
597
598To use the in-tree debug server on macOS, lldb needs to be code signed. The
599Debug, DebugClang and Release builds are set to code sign using a code signing
600certificate named ``lldb_codesign``.
601
602Automatic setup, run:
603
604* ``scripts/macos-setup-codesign.sh``
605
606Note that it's possible to build and use lldb on macOS without setting up code
607signing by using the system's debug server. To configure lldb in this way with
608cmake, specify ``-DLLDB_USE_SYSTEM_DEBUGSERVER=ON``.
609
610If you have re-installed a new OS, please delete all old ``lldb_codesign`` items
611from your keychain. There will be a code signing certification and a public
612and private key. Reboot after deleting them. You will also need to delete and
613build folders that contained old signed items. The darwin kernel will cache
614code signing using the executable's file system node, so you will need to
615delete the file so the kernel clears its cache.
616
617When you build your LLDB for the first time, the Xcode GUI will prompt you for
618permission to use the ``lldb_codesign`` keychain. Be sure to click "Always
619Allow" on your first build. From here on out, the ``lldb_codesign`` will be
620trusted and you can build from the command line without having to authorize.
621Also the first time you debug using a LLDB that was built with this code
622signing certificate, you will need to authenticate once.
623