Skip to content

Commit ca723f2

Browse files
[lldb][Docs] Document our major differences from the LLVM style (#66345)
Running: $ clang-format -i $(find -regex "\./lldb/.*\.c") $(find -regex "\./lldb/.*\.cpp") $(find -regex "\./lldb/.*\.h") Resulted in: 1602 files changed, 25090 insertions(+), 25849 deletions(-) (note: this includes tests which we wouldn't format, just using this as an example) The vast majority of which were whitespace changes. So as far as formatting we're not deviating from llvm for any reason other than not churning old code. Formatting aside, the major features of lldb (single line if, early return) are all reflected in llvm's style. We differ mainly on variable naming (proposed to change in https://llvm.org/docs/Proposals/VariableNames.html anyway) and use of asserts. Which was already documented.
1 parent 6923a31 commit ca723f2

File tree

1 file changed

+50
-23
lines changed

1 file changed

+50
-23
lines changed

lldb/docs/resources/contributing.rst

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,45 @@ Please refer to the `LLVM Developer Policy
1818
authoring and uploading a patch. LLDB differs from the LLVM Developer
1919
Policy in the following respects.
2020

21-
- **Test infrastructure**: Like LLVM it is important to submit tests with your
22-
patches, but note that LLDB uses a different system for tests. Refer to the
23-
`test documentation <test.html>`_ for more details and the ``lldb/test``
24-
folder on disk for examples.
25-
26-
- **Coding Style**: LLDB's code style differs from
27-
`LLVM's coding style <https://llvm.org/docs/CodingStandards.html>`_.
28-
Unfortunately there is no document describing the differences. Please be
29-
consistent with the existing code.
30-
3121
For anything not explicitly listed here, assume that LLDB follows the LLVM
3222
policy.
3323

24+
Coding Style
25+
++++++++++++
26+
27+
LLDB's code style differs from `LLVM's coding style <https://llvm.org/docs/CodingStandards.html>`_
28+
in a few ways. The 2 main ones are:
29+
30+
* `Variable and function naming <https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly>`_:
31+
32+
* Variables are ``snake_case``.
33+
34+
* Functions and methods are ``UpperCamelCase``.
35+
36+
* Static, global and member variables have ``s_``, ``g_`` and ``_m``
37+
prefixes respectively.
38+
39+
* `Use of asserts <https://llvm.org/docs/CodingStandards.html#assert-liberally>`_:
40+
See the :ref:`section below<Error Handling>`.
41+
42+
For any other contradications, consider the
43+
`golden rule <https://llvm.org/docs/CodingStandards.html#introduction>`_
44+
before choosing to update the style of existing code.
45+
46+
All new code in LLDB should be formatted with clang-format. Existing code may
47+
not conform and should be updated prior to being modified. Bulk reformatting
48+
is discouraged.
49+
50+
Test Infrastructure
51+
+++++++++++++++++++
52+
53+
Like LLVM it is important to submit tests with your patches, but note that a
54+
subset of LLDB tests (the API tests) use a different system. Refer to the
55+
`test documentation <test.html>`_ for more details and the
56+
`lldb/test <https://github.com/llvm/llvm-project/tree/main/lldb/test>`_ folder
57+
for examples.
58+
59+
.. _Error handling:
3460

3561
Error handling and use of assertions in LLDB
3662
--------------------------------------------
@@ -42,14 +68,13 @@ be extra thoughtful about how to handle errors. Below are a couple
4268
rules of thumb:
4369

4470
* Invalid input. To deal with invalid input, such as malformed DWARF,
45-
missing object files, or otherwise inconsistent debug info, LLVM's
71+
missing object files, or otherwise inconsistent debug info,
4672
error handling types such as `llvm::Expected<T>
4773
<https://llvm.org/doxygen/classllvm_1_1Expected.html>`_ or
48-
`std::optional<T>
49-
<https://llvm.org/doxygen/classllvm_1_1Optional.html>`_ should be
50-
used. Functions that may fail should return their result using these
51-
wrapper types instead of using a bool to indicate success. Returning
52-
a default value when an error occurred is also discouraged.
74+
``std::optional<T>`` should be used. Functions that may fail
75+
should return their result using these wrapper types instead of
76+
using a bool to indicate success. Returning a default value when an
77+
error occurred is also discouraged.
5378

5479
* Assertions. Assertions (from ``assert.h``) should be used liberally
5580
to assert internal consistency. Assertions shall **never** be
@@ -71,16 +96,18 @@ rules of thumb:
7196
behaves like ``assert()``. When asserts are disabled, it will print a
7297
warning and encourage the user to file a bug report, similar to
7398
LLVM's crash handler, and then return execution. Use these sparingly
74-
and only if error handling is not otherwise feasible. Specifically,
75-
new code should not be using ``lldbassert()`` and existing
76-
uses should be replaced by other means of error handling.
99+
and only if error handling is not otherwise feasible.
100+
101+
.. note::
102+
103+
New code should not be using ``lldbassert()`` and existing uses should
104+
be replaced by other means of error handling.
77105

78106
* Fatal errors. Aborting LLDB's process using
79107
``llvm::report_fatal_error()`` or ``abort()`` should be avoided at all
80-
costs. It's acceptable to use `llvm_unreachable()
81-
<https://llvm.org/doxygen/Support_2ErrorHandling_8h.html>`_ for
82-
actually unreachable code such as the default in an otherwise
83-
exhaustive switch statement.
108+
costs. It's acceptable to use ``llvm_unreachable()`` for actually
109+
unreachable code such as the default in an otherwise exhaustive
110+
switch statement.
84111

85112
Overall, please keep in mind that the debugger is often used as a last
86113
resort, and a crash in the debugger is rarely appreciated by the

0 commit comments

Comments
 (0)