1061da546SpatrickContributing 2061da546Spatrick============ 3061da546Spatrick 4061da546SpatrickGetting Started 5061da546Spatrick--------------- 6061da546Spatrick 7061da546SpatrickPlease refer to the `LLVM Getting Started Guide 8061da546Spatrick<https://llvm.org/docs/GettingStarted.html>`_ for general information on how to 9061da546Spatrickget started on the LLVM project. A detailed explanation on how to build and 10061da546Spatricktest LLDB can be found in the `build instructions <build.html>`_ and `test 11be691f3bSpatrickinstructions <test.html>`_ respectively. 12061da546Spatrick 13061da546SpatrickContributing to LLDB 14061da546Spatrick-------------------- 15061da546Spatrick 16061da546SpatrickPlease refer to the `LLVM Developer Policy 17061da546Spatrick<https://llvm.org/docs/DeveloperPolicy.html>`_ for information about 18061da546Spatrickauthoring and uploading a patch. LLDB differs from the LLVM Developer 19061da546SpatrickPolicy in the following respects. 20061da546Spatrick 21061da546Spatrick - **Test infrastructure**: Like LLVM it is important to submit tests with your 22061da546Spatrick patches, but note that LLDB uses a different system for tests. Refer to the 23be691f3bSpatrick `test documentation <test.html>`_ for more details and the ``lldb/test`` 24061da546Spatrick folder on disk for examples. 25061da546Spatrick 26061da546Spatrick - **Coding Style**: LLDB's code style differs from LLVM's coding style. 27061da546Spatrick Unfortunately there is no document describing the differences. Please be 28061da546Spatrick consistent with the existing code. 29061da546Spatrick 30061da546SpatrickFor anything not explicitly listed here, assume that LLDB follows the LLVM 31061da546Spatrickpolicy. 32061da546Spatrick 33061da546Spatrick 34061da546SpatrickError handling and use of assertions in LLDB 35061da546Spatrick-------------------------------------------- 36061da546Spatrick 37061da546SpatrickContrary to Clang, which is typically a short-lived process, LLDB 38061da546Spatrickdebuggers stay up and running for a long time, often serving multiple 39061da546Spatrickdebug sessions initiated by an IDE. For this reason LLDB code needs to 40061da546Spatrickbe extra thoughtful about how to handle errors. Below are a couple 41061da546Spatrickrules of thumb: 42061da546Spatrick 43061da546Spatrick* Invalid input. To deal with invalid input, such as malformed DWARF, 44061da546Spatrick missing object files, or otherwise inconsistent debug info, LLVM's 45061da546Spatrick error handling types such as `llvm::Expected<T> 46061da546Spatrick <https://llvm.org/doxygen/classllvm_1_1Expected.html>`_ or 47*f6aab3d8Srobert `std::optional<T> 48061da546Spatrick <https://llvm.org/doxygen/classllvm_1_1Optional.html>`_ should be 49061da546Spatrick used. Functions that may fail should return their result using these 50061da546Spatrick wrapper types instead of using a bool to indicate success. Returning 51061da546Spatrick a default value when an error occurred is also discouraged. 52061da546Spatrick 53be691f3bSpatrick* Assertions. Assertions (from ``assert.h``) should be used liberally 54061da546Spatrick to assert internal consistency. Assertions shall **never** be 55061da546Spatrick used to detect invalid user input, such as malformed DWARF. An 56061da546Spatrick assertion should be placed to assert invariants that the developer 57061da546Spatrick is convinced will always hold, regardless what an end-user does with 58061da546Spatrick LLDB. Because assertions are not present in release builds, the 59061da546Spatrick checks in an assertion may be more expensive than otherwise 60061da546Spatrick permissible. In combination with the LLDB test suite, assertions are 61061da546Spatrick what allows us to refactor and evolve the LLDB code base. 62061da546Spatrick 63061da546Spatrick* Logging. LLDB provides a very rich logging API. When recoverable 64061da546Spatrick errors cannot reasonably be surfaced to the end user, the error may 65061da546Spatrick be written to a topical log channel. 66061da546Spatrick 67be691f3bSpatrick* Soft assertions. LLDB provides ``lldb_assert()`` as a soft 68061da546Spatrick alternative to cover the middle ground of situations that indicate a 69be691f3bSpatrick recoverable bug in LLDB. In a Debug configuration ``lldb_assert()`` 70be691f3bSpatrick behaves like ``assert()``. In a Release configuration it will print a 71061da546Spatrick warning and encourage the user to file a bug report, similar to 72061da546Spatrick LLVM's crash handler, and then return execution. Use these sparingly 73061da546Spatrick and only if error handling is not otherwise feasible. Specifically, 74be691f3bSpatrick new code should not be using ``lldb_assert()`` and existing 75061da546Spatrick uses should be replaced by other means of error handling. 76061da546Spatrick 77061da546Spatrick* Fatal errors. Aborting LLDB's process using 78be691f3bSpatrick ``llvm::report_fatal_error()`` or ``abort()`` should be avoided at all 79061da546Spatrick costs. It's acceptable to use `llvm_unreachable() 80061da546Spatrick <https://llvm.org/doxygen/Support_2ErrorHandling_8h.html>`_ for 81061da546Spatrick actually unreachable code such as the default in an otherwise 82061da546Spatrick exhaustive switch statement. 83061da546Spatrick 84061da546SpatrickOverall, please keep in mind that the debugger is often used as a last 85061da546Spatrickresort, and a crash in the debugger is rarely appreciated by the 86061da546Spatrickend-user. 87