AnotherMemCheck/README.md

69 lines
2.3 KiB
Markdown
Raw Normal View History

2024-06-04 03:13:12 +00:00
# AnotherMemCheck
This software was created as an alternative to valgrind/memcheck.
2024-06-04 03:21:59 +00:00
## How to Build
1. Install cmake.
2. Run `cmake -S <AnotherMemCheck_project_dir> -B buildDebug`.
3. Run `make -C buildDebug`. The output library should be in the buildDebug/
directory.
If a release build is desired, use `cmake -S <project_dir> -B buildRelease
-DCMAKE_BUILD_TYPE=Release`. (Note that the "build directory" was changed to
"buildRelease" in the preceeding command.)
2024-06-04 03:13:12 +00:00
## Usage
1. Build this software with cmake.
2. Assuming the output library is called `libAnotherMemCheck.so`, run your
program with the `LD_PRELOAD` environment variable set to this library.
LD_PRELOAD=path/libAnotherMemCheck.so ./myProgram
3. When the program exits, there should be diagnostic output from this library
2024-06-04 06:50:00 +00:00
showing all memory that has been `malloc`ed or `calloc`ed and not `free`ed.
Note that some memory will always be shown as having been not `free`ed (e.g.
initializing heap stuff for the program at start).
2024-06-04 03:15:46 +00:00
2024-11-12 11:05:42 +00:00
## With gdb
1. Start the debugger
```
2024-11-12 11:05:42 +00:00
gdb ./my_program
```
2024-11-12 11:05:42 +00:00
2. Set the env variable to use AnotherMemCheck.
```
2024-11-12 11:05:42 +00:00
set environment LD_PRELOAD ./path/to/libAnotherMemCheck.so
```
2024-11-12 11:05:42 +00:00
3. Set debug breakpoints if you want to step through things
```
2024-11-12 11:05:42 +00:00
b my_source_file.c:123
```
2024-11-12 11:05:42 +00:00
4. Run it
```
2024-11-12 11:05:42 +00:00
r --my-arg-one --my-arg-two
```
2024-11-12 11:05:42 +00:00
AnotherMemCheck should output when memory is handled as the debugger runs, even
when stepping through from breakpoints.
2024-06-04 03:15:46 +00:00
## Other Notes
2024-06-06 06:44:47 +00:00
As mentioned earlier, there probably is memory that is always allocated at the
start of a program that never gets free'd, but this should be ok because the OS
should reclaim all allocated memory from a stopped process.
Also, if one wants to prevent this software from printing every
malloc/calloc/free call, one can set the `ANOTHER_MEMCHECK_QUIET=1` environment
variable so that it only prints unfree'd memory at program execution end.
2024-06-04 03:15:46 +00:00
Since this is relatively newly written software (as of middle of 2024), there
might be a memory leak within this software when keeping track of memory. Thus,
2024-06-04 03:24:29 +00:00
this software may be revised later on. If you are interested in verifying
whether there is a memory leak or not, you may check the source and submit an
issue/pull-request if there is any discovered issue with the software.