Tools: Move malloc debugging to a separate file
Set our various malloc debugging environment variables in a separate `debug-alloc.env` file and document it in the Developer's Guide.
This commit is contained in:
parent
a1e4aea6ff
commit
1dfdb211b7
|
@ -477,10 +477,11 @@ https://valgrind.org[Valgrind] and can be enabled as follows:
|
|||
$ export WIRESHARK_DEBUG_WMEM_OVERRIDE=simple
|
||||
----
|
||||
|
||||
For memory allocated without wmem but with GLib's GSlice memory allocator,
|
||||
there is a similar `G_SLICE` environment variable that can be set to
|
||||
`always-malloc` (similar to `simple`) or `debug-blocks` (similar to `strict`).
|
||||
Wireshark uses GLib's GSlice memory allocator, either indirectly via wmem or via various GLib API calls.
|
||||
GLib provides a `G_SLICE` environment variable that can be set to `always-malloc` (similar to `simple`) or `debug-blocks` (similar to `strict`).
|
||||
See https://developer-old.gnome.org/glib/stable/glib-running.html for details.
|
||||
The C libraries on FreeBSD, Linux, and macOS also support memory allocation debugging via various environment variables.
|
||||
You can enable many of them by running `source tools/debug-alloc.env` in a POSIX shell.
|
||||
|
||||
If you're encountering memory safety bugs, you might want to build with
|
||||
https://github.com/google/sanitizers/wiki/AddressSanitizer[Address Sanitizer]
|
||||
|
@ -490,6 +491,8 @@ It works with GCC or Clang, provided that the appropriate libraries are installe
|
|||
[source,sh]
|
||||
----
|
||||
$ cmake .. -G Ninja -DENABLE_ASAN=1
|
||||
$ source ../tools/debug-alloc.env
|
||||
$ ./run/tshark ...
|
||||
----
|
||||
|
||||
TIP: ASAN slows things down by a factor of 2 (or more), so having a different
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
##############################################################################
|
||||
### Set up environment variables for testing ###
|
||||
##############################################################################
|
||||
|
||||
# Use the Wmem strict allocator which does canaries and scrubbing etc.
|
||||
export WIRESHARK_DEBUG_WMEM_OVERRIDE=strict
|
||||
# Abort if a dissector adds too many items to the tree
|
||||
export WIRESHARK_ABORT_ON_TOO_MANY_ITEMS=
|
||||
|
||||
# Turn on GLib memory debugging (since 2.13)
|
||||
export G_SLICE=debug-blocks
|
||||
|
||||
# Cause glibc (Linux) to abort() if some memory errors are found
|
||||
export MALLOC_CHECK_=3
|
||||
|
||||
# Cause FreeBSD (and other BSDs) to abort() on allocator warnings and
|
||||
# initialize allocated memory (to 0xa5) and freed memory (to 0x5a). see:
|
||||
# https://www.freebsd.org/cgi/man.cgi?query=malloc&apropos=0&sektion=0&manpath=FreeBSD+8.2-RELEASE&format=html
|
||||
export MALLOC_OPTIONS=AJ
|
||||
|
||||
# macOS options; see https://developer.apple.com/library/archive/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html
|
||||
# Initialize allocated memory to 0xAA and freed memory to 0x55
|
||||
export MallocPreScribble=1
|
||||
export MallocScribble=1
|
||||
# Add guard pages before and after large allocations
|
||||
export MallocGuardEdges=1
|
||||
# Call abort() if heap corruption is detected. Heap is checked every 1000
|
||||
# allocations (may need to be tuned!)
|
||||
export MallocCheckHeapStart=1000
|
||||
export MallocCheckHeapEach=1000
|
||||
export MallocCheckHeapAbort=1
|
||||
# Call abort() if an illegal free() call is made
|
||||
export MallocBadFreeAbort=1
|
|
@ -79,36 +79,7 @@ if [ $NOTFOUND -eq 1 ]; then
|
|||
fi
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
### Set up environment variables for fuzz testing ###
|
||||
##############################################################################
|
||||
# Use the Wmem strict allocator which does canaries and scrubbing etc.
|
||||
export WIRESHARK_DEBUG_WMEM_OVERRIDE=strict
|
||||
# Abort if a dissector adds too many items to the tree
|
||||
export WIRESHARK_ABORT_ON_TOO_MANY_ITEMS=
|
||||
|
||||
# Turn on GLib memory debugging (since 2.13)
|
||||
export G_SLICE=debug-blocks
|
||||
# Cause glibc (Linux) to abort() if some memory errors are found
|
||||
export MALLOC_CHECK_=3
|
||||
# Cause FreeBSD (and other BSDs) to abort() on allocator warnings and
|
||||
# initialize allocated memory (to 0xa5) and freed memory (to 0x5a). see:
|
||||
# https://www.freebsd.org/cgi/man.cgi?query=malloc&apropos=0&sektion=0&manpath=FreeBSD+8.2-RELEASE&format=html
|
||||
export MALLOC_OPTIONS=AJ
|
||||
|
||||
# macOS options; see https://developer.apple.com/library/archive/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html
|
||||
# Initialize allocated memory to 0xAA and freed memory to 0x55
|
||||
export MallocPreScribble=1
|
||||
export MallocScribble=1
|
||||
# Add guard pages before and after large allocations
|
||||
export MallocGuardEdges=1
|
||||
# Call abort() if heap corruption is detected. Heap is checked every 1000
|
||||
# allocations (may need to be tuned!)
|
||||
export MallocCheckHeapStart=1000
|
||||
export MallocCheckHeapEach=1000
|
||||
export MallocCheckHeapAbort=1
|
||||
# Call abort() if an illegal free() call is made
|
||||
export MallocBadFreeAbort=1
|
||||
source "$(dirname "$0")"/debug-alloc.env
|
||||
|
||||
# Address Sanitizer options
|
||||
export ASAN_OPTIONS=detect_leaks=0
|
||||
|
|
Loading…
Reference in New Issue