1
1
Developer Notes
2
2
===============
3
3
4
+ <!-- markdown-toc start -->
5
+ ** Table of Contents**
6
+
7
+ - [ Developer Notes] ( #developer-notes )
8
+ - [ Coding Style] ( #coding-style )
9
+ - [ Doxygen comments] ( #doxygen-comments )
10
+ - [ Development tips and tricks] ( #development-tips-and-tricks )
11
+ - [ Compiling for debugging] ( #compiling-for-debugging )
12
+ - [ Compiling for gprof profiling] ( #compiling-for-gprof-profiling )
13
+ - [ debug.log] ( #debuglog )
14
+ - [ Testnet and Regtest modes] ( #testnet-and-regtest-modes )
15
+ - [ DEBUG_LOCKORDER] ( #debug_lockorder )
16
+ - [ Valgrind suppressions file] ( #valgrind-suppressions-file )
17
+ - [ Compiling for test coverage] ( #compiling-for-test-coverage )
18
+ - [ Locking/mutex usage notes] ( #lockingmutex-usage-notes )
19
+ - [ Threads] ( #threads )
20
+ - [ Ignoring IDE/editor files] ( #ignoring-ideeditor-files )
21
+ - [ Development guidelines] ( #development-guidelines )
22
+ - [ General Bitcoin Core] ( #general-bitcoin-core )
23
+ - [ Wallet] ( #wallet )
24
+ - [ General C++] ( #general-c )
25
+ - [ C++ data structures] ( #c-data-structures )
26
+ - [ Strings and formatting] ( #strings-and-formatting )
27
+ - [ Variable names] ( #variable-names )
28
+ - [ Threads and synchronization] ( #threads-and-synchronization )
29
+ - [ Source code organization] ( #source-code-organization )
30
+ - [ GUI] ( #gui )
31
+ - [ Subtrees] ( #subtrees )
32
+ - [ Git and GitHub tips] ( #git-and-github-tips )
33
+ - [ Scripted diffs] ( #scripted-diffs )
34
+ - [ RPC interface guidelines] ( #rpc-interface-guidelines )
35
+
36
+ <!-- markdown-toc end -->
37
+
38
+ Coding Style
39
+ ---------------
40
+
4
41
Various coding styles have been used during the history of the codebase,
5
42
and the result is not very consistent. However, we're now trying to converge to
6
43
a single style, which is specified below. When writing patches, favor the new
@@ -138,43 +175,44 @@ Documentation can be generated with `make docs` and cleaned up with `make clean-
138
175
Development tips and tricks
139
176
---------------------------
140
177
141
- ** compiling for debugging**
178
+ ### Compiling for debugging
142
179
143
- Run configure with the --enable-debug option, then make. Or run configure with
144
- CXXFLAGS="-g -ggdb -O0" or whatever debug flags you need .
180
+ Run configure with ` --enable-debug ` to add additional compiler flags that
181
+ produce better debugging builds .
145
182
146
- ** compiling for gprof profiling**
183
+ ### Compiling for gprof profiling
147
184
148
- Run configure with the --enable-gprof option, then make.
185
+ Run configure with the ` --enable-gprof ` option, then make.
149
186
150
- ** debug.log**
187
+ ### debug.log
151
188
152
189
If the code is behaving strangely, take a look in the debug.log file in the data directory;
153
190
error and debugging messages are written there.
154
191
155
- The -debug=... command-line option controls debugging; running with just -debug or -debug=1 will turn
192
+ The ` -debug=... ` command-line option controls debugging; running with just ` -debug ` or ` -debug=1 ` will turn
156
193
on all categories (and give you a very large debug.log file).
157
194
158
- The Qt code routes qDebug() output to debug.log under category "qt": run with -debug=qt
195
+ The Qt code routes ` qDebug() ` output to debug.log under category "qt": run with ` -debug=qt `
159
196
to see it.
160
197
161
- ** testnet and regtest modes**
198
+ ### Testnet and Regtest modes
162
199
163
- Run with the -testnet option to run with "play bitcoins" on the test network, if you
200
+ Run with the ` -testnet ` option to run with "play bitcoins" on the test network, if you
164
201
are testing multi-machine code that needs to operate across the internet.
165
202
166
- If you are testing something that can run on one machine, run with the -regtest option.
167
- In regression test mode, blocks can be created on-demand; see test/functional/ for tests
168
- that run in -regtest mode.
203
+ If you are testing something that can run on one machine, run with the ` -regtest ` option.
204
+ In regression test mode, blocks can be created on-demand; see [ test/functional/] ( /test/functional ) for tests
205
+ that run in ` -regtest ` mode.
169
206
170
- ** DEBUG_LOCKORDER**
207
+ ### DEBUG_LOCKORDER
171
208
172
- Bitcoin Core is a multithreaded application, and deadlocks or other multithreading bugs
173
- can be very difficult to track down. Compiling with -DDEBUG_LOCKORDER (configure
174
- CXXFLAGS="-DDEBUG_LOCKORDER -g") inserts run-time checks to keep track of which locks
175
- are held, and adds warnings to the debug.log file if inconsistencies are detected.
209
+ Bitcoin Core is a multi-threaded application, and deadlocks or other
210
+ multi-threading bugs can be very difficult to track down. The ` --enable-debug `
211
+ configure option adds ` -DDEBUG_LOCKORDER ` to the compiler flags. This inserts
212
+ run-time checks to keep track of which locks are held, and adds warnings to the
213
+ debug.log file if inconsistencies are detected.
176
214
177
- ** Valgrind suppressions file**
215
+ ### Valgrind suppressions file
178
216
179
217
Valgrind is a programming tool for memory debugging, memory leak detection, and
180
218
profiling. The repo contains a Valgrind suppressions file
@@ -189,7 +227,7 @@ $ valgrind --suppressions=contrib/valgrind.supp --leak-check=full \
189
227
$ valgrind -v --leak-check=full src/bitcoind -printtoconsole
190
228
```
191
229
192
- ** compiling for test coverage**
230
+ ### Compiling for test coverage
193
231
194
232
LCOV can be used to generate a test coverage report based upon ` make check `
195
233
execution. LCOV must be installed on your system (e.g. the ` lcov ` package
@@ -209,18 +247,18 @@ Locking/mutex usage notes
209
247
-------------------------
210
248
211
249
The code is multi-threaded, and uses mutexes and the
212
- LOCK/ TRY_LOCK macros to protect data structures.
250
+ ` LOCK ` and ` TRY_LOCK ` macros to protect data structures.
213
251
214
- Deadlocks due to inconsistent lock ordering (thread 1 locks cs_main
215
- and then cs_wallet, while thread 2 locks them in the opposite order:
216
- result, deadlock as each waits for the other to release its lock) are
217
- a problem. Compile with -DDEBUG_LOCKORDER to get lock order
218
- inconsistencies reported in the debug.log file.
252
+ Deadlocks due to inconsistent lock ordering (thread 1 locks ` cs_main ` and then
253
+ ` cs_wallet ` , while thread 2 locks them in the opposite order: result, deadlock
254
+ as each waits for the other to release its lock) are a problem. Compile with
255
+ ` -DDEBUG_LOCKORDER ` (or use ` --enable-debug ` ) to get lock order inconsistencies
256
+ reported in the debug.log file.
219
257
220
258
Re-architecting the core code so there are better-defined interfaces
221
259
between the various components is a goal, with any necessary locking
222
- done by the components (e.g. see the self-contained CBasicKeyStore class
223
- and its cs_KeyStore lock for example).
260
+ done by the components (e.g. see the self-contained ` CBasicKeyStore ` class
261
+ and its ` cs_KeyStore ` lock for example).
224
262
225
263
Threads
226
264
-------
0 commit comments