Devtools » History » Version 11
laforge, 12/31/2020 01:00 PM
add note about useful asan option
1 | 8 | laforge | h1. Development tools |
---|---|---|---|
2 | 6 | ||
3 | 7 | laforge | h2. C tools |
4 | 1 | ||
5 | 9 | laforge | * @Lindent@ (from kernel source), reformat C code to the Linux kernel (and osmocom) coding standards |
6 | * @cflow@ to generate flow-graphs from source code |
||
7 | 7 | laforge | |
8 | 1 | h2. Patches |
|
9 | |||
10 | 7 | laforge | * @git format-patch -1@, generate a patch |
11 | * @checkpatch.pl@, check patches for common errors (Ignore x-signed-off-by) |
||
12 | * @make distcheck@ catches quite a few errors, run it before sending patches. |
||
13 | * @git send-email -1@ Send a patch to the mailing list (after configuration) |
||
14 | 1 | ||
15 | 5 | h2. Testing |
|
16 | 1 | ||
17 | 7 | laforge | * @make check@: run it and don't introduce regressions |
18 | 10 | laforge | * @make distcheck@: run it to make sure that @make dist@ contains everything needed and you didn't forget to add any files to Makefile.am |
19 | * Our extensive [[Titan_TTCN3_Testsuites]] |
||
20 | 1 | ||
21 | 11 | laforge | h2. AddressSanitizer |
22 | |||
23 | All Osmocom CNI projects support building iwth @./configure --enable-sanitize@, which enables support for "AddressSanitizer":https://github.com/google/sanitizers/wiki/AddressSanitizer |
||
24 | |||
25 | This is extremely useful in finding a variety of problems, such as use-after-free. |
||
26 | |||
27 | h3. meaniungful backtraces |
||
28 | |||
29 | Often the backtraces you get from asan are too short to figure out where an allocation/free has happened, like: |
||
30 | |||
31 | <pre> |
||
32 | 0x612000000eb8 is located 248 bytes inside of 296-byte region [0x612000000dc0,0x612000000ee8) |
||
33 | freed by thread T0 here: |
||
34 | #0 0x7f42477d9b6f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:123 |
||
35 | #1 0x7f4246b2678a in _tc_free_internal ../../talloc.c:1221 |
||
36 | |||
37 | previously allocated by thread T0 here: |
||
38 | #0 0x7f42477d9e8f in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 |
||
39 | #1 0x7f4246b28ecb in __talloc_with_prefix ../../talloc.c:782 |
||
40 | </pre> |
||
41 | |||
42 | In this case, it is recommended to run with the environment variable @ASAN_OPTIONS="fast_unwind_on_malloc=0"@, which will produce a much more meaningful backtrace. The same bug as the above example now looks like this: |
||
43 | |||
44 | <pre> |
||
45 | 0x612000000eb8 is located 248 bytes inside of 296-byte region [0x612000000dc0,0x612000000ee8) |
||
46 | freed by thread T0 here: |
||
47 | #0 0x7f5c3e64bb6f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:123 |
||
48 | #1 0x7f5c3d99878a in _tc_free_internal ../../talloc.c:1221 |
||
49 | #2 0x7f5c3daa648e in fsm_free_or_steal /space/home/laforge/projects/git/libosmocore/src/fsm.c:116 |
||
50 | #3 0x7f5c3daa648e in osmo_fsm_inst_free /space/home/laforge/projects/git/libosmocore/src/fsm.c:574 |
||
51 | #4 0x7f5c3daab8ef in _osmo_fsm_inst_term /space/home/laforge/projects/git/libosmocore/src/fsm.c:959 |
||
52 | #5 0x7f5c3daadb09 in fsm_tmr_cb /space/home/laforge/projects/git/libosmocore/src/fsm.c:337 |
||
53 | #6 0x7f5c3da893a6 in osmo_timers_update /space/home/laforge/projects/git/libosmocore/src/timer.c:273 |
||
54 | #7 0x7f5c3da8cf62 in _osmo_select_main /space/home/laforge/projects/git/libosmocore/src/select.c:373 |
||
55 | #8 0x7f5c3da8d548 in osmo_select_main /space/home/laforge/projects/git/libosmocore/src/select.c:417 |
||
56 | #9 0x55b16ce4705c in main /space/home/laforge/projects/git/osmo-cbc/src/cbc_main.c:216 |
||
57 | #10 0x7f5c3cd63d09 in __libc_start_main ../csu/libc-start.c:308 |
||
58 | #11 0x55b16ce47649 in _start (/space/home/laforge/projects/git/osmo-cbc/src/osmo-cbc+0x2a649) |
||
59 | |||
60 | previously allocated by thread T0 here: |
||
61 | #0 0x7f5c3e64be8f in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 |
||
62 | #1 0x7f5c3d99aecb in __talloc_with_prefix ../../talloc.c:782 |
||
63 | #2 0x7f5c3d99b8a6 in __talloc ../../talloc.c:824 |
||
64 | #3 0x7f5c3d99b8a6 in _talloc_named_const ../../talloc.c:981 |
||
65 | #4 0x7f5c3d99b8a6 in _talloc_zero ../../talloc.c:2422 |
||
66 | #5 0x7f5c3daa4fcd in osmo_fsm_inst_alloc /space/home/laforge/projects/git/libosmocore/src/fsm.c:445 |
||
67 | #6 0x55b16ce4c3c8 in cbsp_cbc_accept_cb /space/home/laforge/projects/git/osmo-cbc/src/cbsp_server.c:127 |
||
68 | #7 0x7f5c3d931288 in osmo_stream_srv_fd_cb /space/home/laforge/projects/git/libosmo-netif/src/stream.c:880 |
||
69 | #8 0x7f5c3da8d1b1 in poll_disp_fds /space/home/laforge/projects/git/libosmocore/src/select.c:350 |
||
70 | #9 0x7f5c3da8d1b1 in _osmo_select_main /space/home/laforge/projects/git/libosmocore/src/select.c:378 |
||
71 | #10 0x7f5c3da8d548 in osmo_select_main /space/home/laforge/projects/git/libosmocore/src/select.c:417 |
||
72 | #11 0x55b16ce4705c in main /space/home/laforge/projects/git/osmo-cbc/src/cbc_main.c:216 |
||
73 | #12 0x7f5c3cd63d09 in __libc_start_main ../csu/libc-start.c:308 |
||
74 | #13 0x55b16ce47649 in _start (/space/home/laforge/projects/git/osmo-cbc/src/osmo-cbc+0x2a649) |
||
75 | </pre> |
||
76 | |||
77 | 1 | h2. Misc |
|
78 | |||
79 | 7 | laforge | * pahole (dwarves), http://www.ohloh.net/p/pahole See the memory layout of structures |
80 | * gdb, debugging |
||
81 | * valgrind, http://valgrind.org/, dynamic analysis of memory management/threading |
||
82 | * mudflap (gcc option), check array/pointer accesses. See http://zecke.blogspot.com/2012/10/know-your-tools-mudflap.html |
||
83 | 6 | ||
84 | |||
85 | 7 | laforge | h2. Python tools |
86 | 2 | ||
87 | 7 | laforge | h3. Formatting |
88 | 1 | ||
89 | 7 | laforge | * pep8, https://pypi.python.org/pypi/pep8 Check formatting for pep8 compliance |
90 | * autopep8, https://github.com/hhatto/autopep8 Reformat code to be pep8-complient |
||
91 | 6 | ||
92 | 7 | laforge | h3. Checking/analysis |
93 | 3 | ||
94 | 7 | laforge | * pyflakes, https://pypi.python.org/pypi/pyflakes Statically find some errors |