Project

General

Profile

Devtools » History » Revision 11

Revision 10 (laforge, 05/11/2018 10:31 AM) → Revision 11/12 (laforge, 12/31/2020 01:00 PM)

h1. Development tools 

 h2. C tools 

 * @Lindent@ (from kernel source), reformat C code to the Linux kernel (and osmocom) coding standards 
 * @cflow@ to generate flow-graphs from source code 

 h2. Patches 

 * @git format-patch -1@, generate a patch 
 * @checkpatch.pl@, check patches for common errors (Ignore x-signed-off-by) 
 * @make distcheck@ catches quite a few errors, run it before sending patches. 
 * @git send-email -1@ Send a patch to the mailing list (after configuration) 

 

 h2. Testing 

 * @make check@: run it and don't introduce regressions 
 * @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 
 * Our extensive [[Titan_TTCN3_Testsuites]] 

 h2. AddressSanitizer 

 All Osmocom CNI projects support building iwth @./configure --enable-sanitize@, which enables support for "AddressSanitizer":https://github.com/google/sanitizers/wiki/AddressSanitizer 

 This is extremely useful in finding a variety of problems, such as use-after-free. 

 h3. meaniungful backtraces 

 Often    the backtraces you get from asan are too short to figure out where an allocation/free has happened, like: 

 <pre> 
 0x612000000eb8 is located 248 bytes inside of 296-byte region [0x612000000dc0,0x612000000ee8) 
 freed by thread T0 here: 
     #0 0x7f42477d9b6f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:123 
     #1 0x7f4246b2678a in _tc_free_internal ../../talloc.c:1221 

 previously allocated by thread T0 here: 
     #0 0x7f42477d9e8f in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 
     #1 0x7f4246b28ecb in __talloc_with_prefix ../../talloc.c:782 
 </pre> 

 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: 

 <pre> 
 0x612000000eb8 is located 248 bytes inside of 296-byte region [0x612000000dc0,0x612000000ee8) 
 freed by thread T0 here: 
     #0 0x7f5c3e64bb6f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:123 
     #1 0x7f5c3d99878a in _tc_free_internal ../../talloc.c:1221 
     #2 0x7f5c3daa648e in fsm_free_or_steal /space/home/laforge/projects/git/libosmocore/src/fsm.c:116 
     #3 0x7f5c3daa648e in osmo_fsm_inst_free /space/home/laforge/projects/git/libosmocore/src/fsm.c:574 
     #4 0x7f5c3daab8ef in _osmo_fsm_inst_term /space/home/laforge/projects/git/libosmocore/src/fsm.c:959 
     #5 0x7f5c3daadb09 in fsm_tmr_cb /space/home/laforge/projects/git/libosmocore/src/fsm.c:337 
     #6 0x7f5c3da893a6 in osmo_timers_update /space/home/laforge/projects/git/libosmocore/src/timer.c:273 
     #7 0x7f5c3da8cf62 in _osmo_select_main /space/home/laforge/projects/git/libosmocore/src/select.c:373 
     #8 0x7f5c3da8d548 in osmo_select_main /space/home/laforge/projects/git/libosmocore/src/select.c:417 
     #9 0x55b16ce4705c in main /space/home/laforge/projects/git/osmo-cbc/src/cbc_main.c:216 
     #10 0x7f5c3cd63d09 in __libc_start_main ../csu/libc-start.c:308 
     #11 0x55b16ce47649 in _start (/space/home/laforge/projects/git/osmo-cbc/src/osmo-cbc+0x2a649) 

 previously allocated by thread T0 here: 
     #0 0x7f5c3e64be8f in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 
     #1 0x7f5c3d99aecb in __talloc_with_prefix ../../talloc.c:782 
     #2 0x7f5c3d99b8a6 in __talloc ../../talloc.c:824 
     #3 0x7f5c3d99b8a6 in _talloc_named_const ../../talloc.c:981 
     #4 0x7f5c3d99b8a6 in _talloc_zero ../../talloc.c:2422 
     #5 0x7f5c3daa4fcd in osmo_fsm_inst_alloc /space/home/laforge/projects/git/libosmocore/src/fsm.c:445 
     #6 0x55b16ce4c3c8 in cbsp_cbc_accept_cb /space/home/laforge/projects/git/osmo-cbc/src/cbsp_server.c:127 
     #7 0x7f5c3d931288 in osmo_stream_srv_fd_cb /space/home/laforge/projects/git/libosmo-netif/src/stream.c:880 
     #8 0x7f5c3da8d1b1 in poll_disp_fds /space/home/laforge/projects/git/libosmocore/src/select.c:350 
     #9 0x7f5c3da8d1b1 in _osmo_select_main /space/home/laforge/projects/git/libosmocore/src/select.c:378 
     #10 0x7f5c3da8d548 in osmo_select_main /space/home/laforge/projects/git/libosmocore/src/select.c:417 
     #11 0x55b16ce4705c in main /space/home/laforge/projects/git/osmo-cbc/src/cbc_main.c:216 
     #12 0x7f5c3cd63d09 in __libc_start_main ../csu/libc-start.c:308 
     #13 0x55b16ce47649 in _start (/space/home/laforge/projects/git/osmo-cbc/src/osmo-cbc+0x2a649) 
 </pre> 

 

 h2. Misc 

 * pahole (dwarves), http://www.ohloh.net/p/pahole See the memory layout of structures 
 * gdb, debugging 
 * valgrind, http://valgrind.org/, dynamic analysis of memory management/threading 
 * mudflap (gcc option), check array/pointer accesses. See http://zecke.blogspot.com/2012/10/know-your-tools-mudflap.html 


 h2. Python tools 

 h3. Formatting 

 * pep8, https://pypi.python.org/pypi/pep8 Check formatting for pep8 compliance 
 * autopep8, https://github.com/hhatto/autopep8 Reformat code to be pep8-complient 

 h3. Checking/analysis 

 * pyflakes, https://pypi.python.org/pypi/pyflakes Statically find some errors
Add picture from clipboard (Maximum size: 48.8 MB)