@@ -18,19 +18,45 @@ Please refer to the `LLVM Developer Policy
18
18
authoring and uploading a patch. LLDB differs from the LLVM Developer
19
19
Policy in the following respects.
20
20
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
-
31
21
For anything not explicitly listed here, assume that LLDB follows the LLVM
32
22
policy.
33
23
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 :
34
60
35
61
Error handling and use of assertions in LLDB
36
62
--------------------------------------------
@@ -42,14 +68,13 @@ be extra thoughtful about how to handle errors. Below are a couple
42
68
rules of thumb:
43
69
44
70
* 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,
46
72
error handling types such as `llvm::Expected<T>
47
73
<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.
53
78
54
79
* Assertions. Assertions (from ``assert.h ``) should be used liberally
55
80
to assert internal consistency. Assertions shall **never ** be
@@ -71,16 +96,18 @@ rules of thumb:
71
96
behaves like ``assert() ``. When asserts are disabled, it will print a
72
97
warning and encourage the user to file a bug report, similar to
73
98
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.
77
105
78
106
* Fatal errors. Aborting LLDB's process using
79
107
``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.
84
111
85
112
Overall, please keep in mind that the debugger is often used as a last
86
113
resort, and a crash in the debugger is rarely appreciated by the
0 commit comments