Memory detection and memory detection tools
In the debugging mode, TBOX memory allocation can detect memory leakage and out-of-bounds, and precisely locate the memory allocation location where the problem occurs, and function call stack.
1. Memory leakage detection
The memory leak detection is performed only when tb_exit () is called one minute before the program exits. If the program is leaked, details will be output to the terminal.
tb_void_t tb_demo_leak() { tb_pointer_t data = tb_malloc0(10); }
Output: [tbox]: [error]: leak: 0x7f9d5b058908 at least (): 735, memory/impl/static_fixed_pool.c [tbox]: [error]: data: from: tb_demo_leak (): 43, memory/check. c [tbox]: [error]: [0x000001050e742a]: 0 demo. B 0x00000001050e742a tb_fixed_pool_malloc0 _ + 186 [tbox]: [error]: [0x000001050f972b]: 1 demo. B 0x00000001050f972b tb_small_pool_malloc0 _ + 507 [tbox]: [error]: [0x000001050f593c]: 2 Demo. B 0x00000001050f593c tb_pool_malloc0 _ + 540 [tbox]: [error]: [0x00000105063cd7]: 3 demo. B 0x0000000105063cd7 tb_demo_leak + 55 [tbox]: [error]: [0x00000105063e44]: 4 demo. B 0x0000000105063e44 tb_demo_memory_check_main + 20 [tbox]: [error]: [0x0000010505b08e]: 5 demo. B 0x000000010505b08e main + 878 [tbox]: [error]: [0x007fff8c95a5fd]: 6 libdyld. dylib 0x00007fff8c95a5fd start + 1 [tbox]: [erro R]: [0x00000000000002]: 7 ??? 0x0000000000000002 0x0 + 2 [tbox]: [error]: data: 0x7f9d5b058908, size: 10, patch: cc
2. Out-of-boundary memory Detection
Cross-border overflow detection is completed in real time, and libc is also inserted. Therefore, common use of strcpy and memset is checked back.
tb_void_t tb_demo_overflow() { tb_pointer_t data = tb_malloc0(10); if (data) { tb_memset(data, 0, 11); tb_free(data); } }
Output: [tbox]: [memset]: [overflow]: [0x0x11] => [0x7f950b044508, 10] [tbox]: [memset]: [overflow]: [0x0000010991a1c7]: 0 demo. B 0x000000010991a1c7 tb_memset + 151 [tbox]: [memset]: [overflow]: [0x000001098a2d01]: 1 demo. B 0x00000001098a2d01 tb_demo_overflow + 97 [tbox]: [memset]: [overflow]: [0x000001098a3044]: 2 demo. B 0x00000001098a3044 tb_demo_memory_check_main + 20 [tbox]: [memset]: [overflow]: [0x00000000089a28e]: 3 demo. B 0x0000000000089a28e main + 878 [tbox]: [memset]: [overflow]: [0x007fff8c95a5fd]: 4 libdyld. dylib 0x00007fff8c95a5fd start + 1 [tbox]: [memset]: [overflow]: [0x00000000000002]: 5 ??? 0x0000000000000002 0x0 + 2 [tbox]: [malloc]: [from]: data: from: tb_demo_overflow (): 12, memory/check. c [tbox]: [malloc]: [from]: [0x00000000092662a]: 0 demo. B 0x0000000000092662a tb_fixed_pool_malloc0 _ + 186 [tbox]: [malloc]: [from]: [0x0000010993892b]: 1 demo. B 0x000000010993892b tb_small_pool_malloc0 _ + 507 [tbox]: [malloc]: [from]: [0x00000109934b3c]: 2 demo. B 0x0000000109934b3c tb_pool_malloc0 _ + 540 [tbox]: [malloc]: [from]: [0x000001098a2cd7]: 3 demo. B 0x00000001098a2cd7 tb_demo_overflow + 55 [tbox]: [malloc]: [from]: [0x000001098a3044]: 4 demo. B 0x00000001098a3044 tb_demo_memory_check_main + 20 [tbox]: [malloc]: [from]: [0x00000000089a28e]: 5 demo. B 0x0000000000089a28e main + 878 [tbox]: [malloc]: [from]: [0x007fff8c95a5fd]: 6 libdyld. dylib 0x00007fff8c95a5fd start + 1 [tbox]: [malloc]: [From]: [0x00000000000002]: 7 ??? 0x0000000000000002 0x0 + 2 [tbox]: [malloc]: [from]: data: 0x7f950b044508, size: 10, patch: cc [tbox]: [malloc]: [from]: data: first 10-bytes: [tbox]: ========================================================== ========================================================== ========================================================== ====================================== [tbox]: 00000000 00 00 00 00 00 00 00 00 00 .......... [tbox]: [error]: abort at tb_memset (): 255, libc/string/memset. c
3. Memory overlay Detection
If the copy of the two pieces of memory overlaps, some data may be overwritten, resulting in a bug, so TBOX also performs some checks.
tb_void_t tb_demo_overlap() { tb_pointer_t data = tb_malloc(10); if (data) { tb_memcpy(data, (tb_byte_t const*)data + 1, 5); tb_free(data); } }
Output [tbox]: [memcpy]: [overlap]: [0x7fe9b503859, 5] => [0x7fe9b503858, 5] [tbox]: [memcpy]: [overlap]: [0x000001094403b8]: 0 demo. B 0x00000001094403b8 tb_memcpy + 632 [tbox]: [memcpy]: [overlap]: [0x000001093c99f9]: 1 demo. B 0x00000001093c99f9 tb_demo_overlap + 105 [tbox]: [memcpy]: [overlap]: [0x000001093c9a44]: 2 demo. B 0x00000001093c9a44 tb_demo_memory_check_main + 20 [tbox]: [memcpy]: [overlap ]: [0x000001093c0c8e]: 3 demo. B 0x00000001093c0c8e main + 878 [tbox]: [memcpy]: [overlap]: [0x007fff8c95a5fd]: 4 libdyld. dylib 0x00007fff8c95a5fd start + 1 [tbox]: [memcpy]: [overlap]: [0x00000000000002]: 5 ??? 0x0000000000000002 0x0 + 2 [tbox]: [malloc]: [from]: data: from: tb_demo_overlap (): 58, memory/check. c [tbox]: [malloc]: [from]: [0x00000000045eadb]: 0 demo. B 0x0000000000045eadb tb_small_pool_malloc _ + 507 [tbox]: [malloc]: [from]: [0x00000000045b23c]: 1 demo. B 0x0000000000045b23c tb_pool_malloc _ + 540 [tbox]: [malloc]: [from]: [0x000001093c99c7]: 2 demo. B 0x00000001093c99c7 tb_demo_overlap + 55 [tbo X]: [malloc]: [from]: [0x000001093c9a44]: 3 demo. B 0x00000001093c9a44 tb_demo_memory_check_main + 20 [tbox]: [malloc]: [from]: [0x000001093c0c8e]: 4 demo. B 0x00000001093c0c8e main + 878 [tbox]: [malloc]: [from]: [0x007fff8c95a5fd]: 5 libdyld. dylib 0x00007fff8c95a5fd start + 1 [tbox]: [malloc]: [from]: [0x00000000000002]: 6 ??? 0x0000000000000002 0x0 + 2 [tbox]: [malloc]: [from]: data: 0x7fe9b502138, size: 10, patch: cc [tbox]: [malloc]: [from]: data: first 10-bytes: [tbox]: ========================================================== ========================================================== ========================================================== ====================================== [tbox]: 00000000 CC .......... [tbox]: [error]: abort at tb_memcpy (): 125, libc/string/memcpy. c
4. Dual memory release Detection
tb_void_t tb_demo_free2() { tb_pointer_t data = tb_malloc0(10); if (data) { tb_free(data); tb_free(data); } }
Output [tbox]: [assert]: expr [(impl-> used_info) [(index)> 3] & (0x1 <(index) & 7)]: double free data: 0x7fd931_c708 at least (): 612, memory/impl/static_fixed_pool.c [tbox]: [0x0000010c9f553c]: 0 demo. B 0x000000010c9f553c tb_static_fixed_pool_free + 972 [tbox]: [0x0000010c9ee7a9]: 1 demo. B 0x000000010c9ee7a9 tb_fixed_pool_free _ + 713 [tbox]: [0x0000010ca01ff5]: 2 demo. B 0x000 201710ca01ff5 tb_small_pool_free _ + 885 [tbox]: [0x0000010c9fdb4f]: 3 demo. B 0x000000010c9fdb4f tb_pool_free _ + 751 [tbox]: [0x0000010c96ac8e]: 4 demo. B 0x000000010c96ac8e tb_demo_free2 + 158 [tbox]: [0x0000010c96ae44]: 5 demo. B 0x000000010c96ae44 tb_demo_memory_check_main + 20 [tbox]: [0x0000010c96208e]: 6 demo. B 0x000000010c96208e main + 878 [tbox]: [0x007fff8c95a5fd]: 7 libdyld. dylib 0x00007fff 8c95a5fd start + 1 [tbox]: [0x00000000000002]: 8 ??? 0x0000000000000002 0x0 + 2 [tbox]: [error]: free (0x7fd93386c708) failed! At tb_demo_free2 (): 37, memory/check. c at tb_static_fixed_pool_free (): 649, memory/impl/static_fixed_pool.c [tbox]: [error]: data: from: tb_demo_free2 (): 33, memory/check. c [tbox]: [error]: [0x0000010c9ee42a]: 0 demo. B 0x000000010c9ee42a tb_fixed_pool_malloc0 _ + 186 [tbox]: [error]: [0x0000010ca0072b]: 1 demo. B 0x000000010ca0072b tb_small_pool_malloc0 _ + 507 [tbox]: [error]: [0x0000010c9fc93c]: 2 Demo. B 0x000000010c9fc93c tb_pool_malloc0 _ + 540 [tbox]: [error]: [0x0000010c96ac27]: 3 demo. B 0x000000010c96ac27 tb_demo_free2 + 55 [tbox]: [error]: [0x0000010c96ae44]: 4 demo. B 0x000000010c96ae44 tb_demo_memory_check_main + 20 [tbox]: [error]: [0x0000010c96208e]: 5 demo. B 0x000000010c96208e main + 878 [tbox]: [error]: [0x007fff8c95a5fd]: 6 libdyld. dylib 0x00007fff8c95a5fd start + 1 [tbox]: [erro R]: [0x00000000000002]: 7 ??? 0x0000000000000002 0x0 + 2 [tbox]: [error]: data: 0x7fd93386c708, size: 10, patch: cc [tbox]: [error]: data: first 10-bytes: [tbox]: ========================================================== ========================================================== ========================================================== ====================================== [tbox]: 00000000 00 00 00 00 00 00 00 00 00 .......... [tbox]: [error]: abort at tb_static_fixed_pool_free (): 655, memory/impl/static_fixed_pool.c
How to Use the memory detection tool?
The testing principle of this software is to constantly read and write the memory, so as to find an error area in the memory. Although it is a memory testing software, it also tests the CPU. When you run it, you will find the CPU core occupied by the software (if your computer is multi-core) the usage rate reaches. In this case, if your computer is single-core, it will only run one MEMTEST, and it will not run much faster. If your computer is multi-core, open one more. I personally think it is highly efficient to run a few processors at the same time. When you only run one task, the memory size is set to your physical memory size, for example, your 768 MB. By the way, sometimes there may be situations where the memory cannot be allocated. Open two test programs and fill in the test memory smaller. If your computer is dual-core or even multi-core, open a few more tests at the same time, so that each test program can test the memory with less efficiency. Generally, when a few programs are opened, the memory is evenly divided into several parts for testing. This ensures that the memory is fully tested and the speed is taken into account. For example, if you run three MEMTEST programs, divide your memory into three parts, and each program allocates MB of memory for testing. Note that no matter how many memtests you run, the total memory allocated to all test programs can be slightly larger than the physical memory size, but not too large, otherwise, it will test the virtual memory, but this is not what we need. Don't worry about it after the test starts. If a memory read/write error occurs, it will report an error. Generally, the test time is recommended to be at least 20 minutes, which is not so absolute. Of course, the test time will also be related to the memory size and read/write speed. There is a progress indicator under the software, expressed in percentage, representing the amount of memory you allocated to test. In my opinion, at least 200% of every program is required. That is to say, the memory should be tested twice. Especially when the connection is not completed, do not rush to the conclusion that the memory is normal.
How to use memory Detection
There are two modes for the memory diagnostic test status: 17 tests, such as MB of memory, with the entire process taking about one hour;
1. extended tests extended memory test mode. There are 6 tests, which are continuous loops. You only need to test one Pass. When Pass: 2 is displayed, you can press "T" to enter another mode.
Extended memory test modes: MATS +, INVC, LRAND, STRIDE6, WMATS +, WINVC
2. standard tests standard memory test mode. There are 11 tests, which are also cyclical. You only need to test one Pass. When Pass: 2 is displayed, you can press the "T" key to enter another mode, or press the "X" key to exit and complete the test.
There are a total of 17 tests. If one of the tests cannot be Succeeded, if your memory is two or more, you can switch the memory arrangement and try again. Make sure all the tests are Succeeded, otherwise, you have to change the memory (or the memory slot is broken). If the device crashes during the test, it indicates that your CPU is faulty or the overclock speed is too high.
Succeeded = successful Active = Active indicates no problem
STANDARD mode test content: MATS +, INVC, LRAND, STRIDE6, WMATS +, WINVC, MATS +, STRIDE38, WSTRIDE-6, ERAND (a long time), there should be a not noted down.
Note: This software will not be automatically stopped. You can check its data when you exit using X.
English description of memory detection software
Pass progress through process
Test progress test process
Ran progress Execution Process
MATS + succeeded MATS + successful
INVC
STRIDE6
WMATS +
WINVC
LRAND active processes)
There are two modes for the memory diagnostic test status: 17 tests, such as MB of memory, with the entire process taking about one hour;
1. extended tests extended memory test mode. There are 6 tests, which are continuous loops. You only need to test one Pass. When Pass: 2 is displayed, you can press "T" to enter
In another mode:
2. standard tests standard memory test mode. There are 11 tests, which are also cyclical. You only need to test one Pass. When Pass: 2 is displayed, you can press "T"
Press the "X" key to exit and complete the test.
A total of 17 tests are performed. If one of the tests cannot be Succeeded, if your memory is two or more, you can switch the memory arrangement order and try again.
Succeeded. Otherwise, the memory will be changed (or the memory slot is broken). If the device crashes during the test, it indicates that your CPU is faulty or the overclock speed is too high.
Succeeded = successful Active = Active indicates no problem
Note: This software will not be automatically stopped. You can check its data when you exit using X.