aboutsummaryrefslogtreecommitdiff
path: root/libc/malloc_debug/DebugData.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Refactor malloc debug.Christopher Ferris2018-04-021-34/+13
| | | | | | | | | | | | | | | | | | | | | | | | Changes - Refactor the code so that only guards require creating a special header for every pointer allocated. - Store only a single copy of every backtrace. This saves memory so that turning on the backtrace option doesn't result in 10X memory usage. - Added new option track_allocs that only verifies pointers are valid for free/malloc_usable_size/realloc. - Remove suffix from test names. - Add the TRACK_ALLOCS options to all guard options. - Add new option verify_pointers that is a lightweight way to verify pointers that are passed to allocation routines. - Do auto-formatting of the code. - Updated documentation for all of these changes. Bug: 74361929 Test: Ran unit tests. Test: Ran libmemunreachable unit tests. Test: Ran an app with backtrace enabled. Change-Id: I3246c48ae4f9811f64622d90d0a9b4d9d818702c
* malloc debug: reset FreeTrackData mutex after forkDenis Hsu2018-01-161-0/+9
| | | | | | | | | | Lock the FreeTrackData mutex during fork and reset it in the child. Ensures that the FreeTrackData is consistent when forking from a multi-threaded process, and that the mutex is in a defined state in the child. Test: 89hours MTBF test Change-Id: I5e5892832a733ea85727ec65abc7094d95a725ef
* Add a legacy inline for mmap64.Dan Albert2017-10-051-1/+1
| | | | | | | | | | | | | While this was never an inline, this function alone has caused most of the bug reports related to _FILE_OFFSET_BITS=64. Providing an inline for it should allow a lot more code to build with _FILE_OFFSET_BITS=64 when targeting pre-L. Test: make checkbuild Test: built trivial cc_binary for LP32 against API 14 with _FILE_OFFSET_BITS=64 set Bug: lots Change-Id: I8479d34af4da358c11423bee43d45b59e9d4143e
* Refactor Config from a struct to a class.Christopher Ferris2017-04-061-11/+11
| | | | | | | | | | | This should make it easier to add new options, and to add options that are complex. For example, I want to modify the behavior of record_allocs_file so that it also enables record_allocs to a default state. Test: All unit tests pass. Test: Enable the backtrace option and restart. Change-Id: Idf5cdeed06ade3bc2c8ae39d228734bf65209b4f
* Enable malloc debug using environment variablesTamas Berghammer2016-11-171-2/+2
| | | | | | | | | | | | | | | | | | Previously malloc debug can be enabled only using global settings accessible to the root user only. This CL adds a new option to enable it using environment variables making it possible to use it with pure native (shell) applications on production builds (from shell user) and prepares it for using it from logwrapper on production devices. Remove the old environment variable and property since they are not necessary. Test: Enable malloc debug using environment variable and verify Test: that it only affects the commands launched from the shell. Test: Enable malloc debug using the property variable and verify Test: that it affects all commands. Test: Run all unit tests in 32 bit and 64 bit. Change-Id: Iecb75a3471552f619f196ad550c5f41fcd9ce8e5
* Add the record alloc option.Christopher Ferris2016-07-081-0/+7
| | | | | | | | | | | | This option adds the ability to record all of the allocation requests and dump them to a file when a signal is sent to the process. Included in this change, redo the option processing to add a new string option. Bug: 27747898 Change-Id: Ida043362e38b5eb1d459c99db9c2581015dab366
* Small refactor.Christopher Ferris2016-04-121-6/+6
| | | | | | | | | | | | | - Move all ScopedDisableDebugCalls into the debug_XXX calls. This avoids any issues that might arise where every part of the code needs to properly guard anything that might allocate. Instead everything is already guarded. - Add a pointer to debug_data in all of the XXData classes. This avoids calling individual functions passing in the debug_data pointer. - Flip the NO_HEADER_OPTIONS to an explicit HEADER_OPTIONS list since fewer options actually require a header. - Move the extern of g_debug to the DebugData.h header. Change-Id: Ia213a391b4a44d9ce122a709d09fe4f1b5426f36
* Merge "malloc_debug: reset TrackData mutex after fork"Colin Cross2016-02-171-0/+18
|\
| * malloc_debug: reset TrackData mutex after forkColin Cross2016-02-121-0/+18
| | | | | | | | | | | | | | | | | | Add a pthread_atfork handler to malloc_debug to lock the TrackData mutex during fork and reset it in the child. Ensures that the TrackData is consistent when forking from a multi-threaded process, and that the mutex is in a defined state in the child. Change-Id: I0dfed30045a28551217ceac227d33b2e18894932
* | Fix the default alignment of the allocations.Christopher Ferris2016-02-121-1/+1
|/ | | | | | | | | | | | | | | | In order to enforce this constraint: The pointer returned if the allocation succeeds shall be suitably aligned so that it may be assigned to a pointer to any type of object and then used to access such an object in the space allocated. Force all allocations on 32 bit systems to have 8 byte alignment, and all allocations on 64 bit systems to have 16 byte alignment. Add a test to verify that the allocator returns the correct alignments. Bug: 26739265 Change-Id: I9af53279617408676b94e4ec6481b3ed7ffafc6a
* Malloc debug rewrite.Christopher Ferris2016-01-251-0/+84
The major components of the rewrite: - Completely remove the qemu shared library code. Nobody was using it and it appears to have broken at some point. - Adds the ability to enable/disable different options independently. - Adds a new option that can enable the backtrace on alloc/free when a process gets a specific signal. - Adds a new way to enable malloc debug. If a special property is set, and the process has an environment variable set, then debug malloc will be enabled. This allows something that might be a derivative of app_process to be started with an environment variable being enabled. - get_malloc_leak_info() used to return one element for each pointer that had the exact same backtrace. The new version returns information for every one of the pointers with same backtrace. It turns out ddms already automatically coalesces these, so the old method simply hid the fact that there where multiple pointers with the same amount of backtrace. - Moved all of the malloc debug specific code into the library. Nothing related to the malloc debug data structures remains in libc. - Removed the calls to the debug malloc cleanup routine. Instead, I added an atexit call with the debug malloc cleanup routine. This gets around most problems related to the timing of doing the cleanup. The new properties and environment variables: libc.debug.malloc.options Set by option name (such as "backtrace"). Setting this to a bad value will cause a usage statement to be printed to the log. libc.debug.malloc.program Same as before. If this is set, then only the program named will be launched with malloc debug enabled. This is not a complete match, but if any part of the property is in the program name, malloc debug is enabled. libc.debug.malloc.env_enabled If set, then malloc debug is only enabled if the running process has the environment variable LIBC_DEBUG_MALLOC_ENABLE set. Bug: 19145921 Change-Id: I7b0e58cc85cc6d4118173fe1f8627a391b64c0d7