summaryrefslogtreecommitdiff
path: root/libc/malloc_debug/tests/malloc_debug_config_tests.cpp
AgeCommit message (Collapse)Author
2019-04-02Disable info messages by default for malloc debug.Christopher Ferris
Add a new option verbose for malloc debug that is not enabled by default. This disables all of the info log messages. It turns out these log messages can add a measurable amount of time and can change the boot up. Bug: 129239269 Test: Adjusted unit tests pass. Test: Verified no messages unless verbose option used. Change-Id: I805cb7c8ecb44de88119574e59d784877cacc383
2019-01-22Bionic malloc debug: add a new option "abort_on_error"Iris Chang
This new option causes an abort after malloc debug detects an error. This allows vendors to get process coredumps to analyze memory for corruption. Bug: 123009873 Test: New test cases added for unit tests and config tests. Change-Id: I6b480af7f747d6a82f61e8bf3df204a5f7ba017f
2018-05-25Point to online documentation.Christopher Ferris
Test: Unit tests pass. Change-Id: Ibbdc260bfdf6a6daf091c4a49cdf03e51f6ca6cf
2018-05-24Add support for using the new unwinder.Christopher Ferris
This adds a new option backtrace_full, when it is set, then it will use libunwindstack. Modify the dump to file data to dump the extra information from libunwindstack. Along with the new dump file format, change the version to v1.1. Updated document for new format of file data. Add unit tests for the new functionality. Bug: 74361929 Test: Ran unit tests. Change-Id: I40fff795f5346bba7b9d7fde2e04f269ff4eb7f1
2018-04-02Refactor malloc debug.Christopher Ferris
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
2017-09-05Provide method to dump backtrace heap data.Christopher Ferris
For non-zygote spawned processes, we might want to dump the backtrace data. Provide a method to send a signal to a process and then dump the data to a file. Adds a method to dump the backtrace data on exit. Update documentation and explain format of heap dump data. Test: Ran unit tests, enabled new options and used them. Change-Id: Ie2fa706694160731afe02c1382b037d06df1d069
2017-04-06Refactor Config from a struct to a class.Christopher Ferris
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
2016-11-17Enable malloc debug using environment variablesTamas Berghammer
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
2016-09-07Fix unittests broken by 545808aTamas Berghammer
Change-Id: I590af5958e4dcb772b710be965ed6c99cd1d9234
2016-07-08Add the record alloc option.Christopher Ferris
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
2016-03-14Fix problem where unknown option is not an error.Christopher Ferris
If the first option is found, then any unknown options are simply ignored, but do not produce an error. Fixed this so that each option found is actually verified to exist. Bug: 27620263 Change-Id: If58732df3285eeae72188162c505e0e202fada8c
2016-02-26Move hard-coded values to constants.Christopher Ferris
Change all of the hard-coded config values to be defined constants. Also make sure to use these constants in the usage output. Bug: 26739265 Change-Id: I597a6d71279a2df9cc7e98c42ac70224261bac99
2016-02-22Fix wrong guard values for 64 bit.Christopher Ferris
I added the code to force alignments of 8 for 32 bit and 16 for 64 bit, but I missed a couple of tests that failed due to this change. Fix the failing tests. Bug: 26739265 Change-Id: Ice9932d1419e59c07483c4c9fcdb84970844f0a6
2016-02-12Fix the default alignment of the allocations.Christopher Ferris
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
2016-01-29Add better free tracking.Christopher Ferris
Included in this change: - Change the tag when a pointer is freed so it's easy to detect if an already freed pointer is being used. - Move the free backtrace out of the header. This backtrace is only used under only some circumstances, so no need to allocate space in all headers for it. - Add new option free_track_backtrace_num_frames to specify how many frames to record when the free occurs. This removes the dependency on the backtrace option to get backtraces. Bug: 26739265 Change-Id: I76f5209507dcf46af67ada162a7cb2bf282116f2
2016-01-27Add min/max values for config values.Christopher Ferris
This is to only allow realistic values for some of the options. Bug: 26739265 Change-Id: I172d5401c27e5d638d80f1c93c678c26c4dae0fc
2016-01-25Malloc debug rewrite.Christopher Ferris
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