Skip to content

Commit 9d9827f

Browse files
authored
Merge pull request #16 from rjpdasilva/feature/build_allow_overriding_call_stack_limit_via_cmake
build: Allow changing call stack limit using `HU_MAX_CALL_STACK` in CMake
2 parents 8ec6a6a + 819afde commit 9d9827f

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
cmake_minimum_required(VERSION 3.0...3.22 FATAL_ERROR)
33
project(heapusage VERSION 1.0 LANGUAGES C CXX)
44

5+
set(HU_MAX_CALL_STACK "20" CACHE STRING
6+
"Maximum call stack captured by heapusage, in number of entries (20 by default).")
7+
58
set(COMMON_FLAGS "-funwind-tables -g -Wall -Wextra -Wpedantic -Wshadow \
69
-Wpointer-arith -Wcast-qual -Wno-missing-braces \
710
-Wswitch-default -Wcast-align -Wunreachable-code \
@@ -28,6 +31,11 @@ set_target_properties(heapusage PROPERTIES PUBLIC_HEADER "src/heapusage.h")
2831
target_compile_features(heapusage PRIVATE cxx_variadic_templates)
2932
install(TARGETS heapusage LIBRARY DESTINATION lib PUBLIC_HEADER DESTINATION include)
3033
target_link_libraries(heapusage pthread dl)
34+
# Pre-processor defines that can be overriden with CMake variables:
35+
# - HU_MAX_CALL_STACK for overriding MAX_CALL_STACK.
36+
if (DEFINED HU_MAX_CALL_STACK)
37+
target_compile_definitions(heapusage PRIVATE MAX_CALL_STACK=${HU_MAX_CALL_STACK})
38+
endif()
3139

3240
# Dependency backward-cpp providing more detailed stacktraces on Linux, when
3341
# either of the following is present (only ONE needed):

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ Note that on-demand reporting will reflect the state when they are used, and
185185
will thus report memory currently in use that might still be released before
186186
the program exits, and therefore not necessarily constitute a memory leak.
187187

188+
Heapusage uses a default call stack limit of 20 frames per call stack. It is
189+
possible to change this value at build time by using the `HU_MAX_CALL_STACK`
190+
CMake variable.
191+
188192
Technical Details
189193
=================
190194
Heapusage intercepts calls to malloc/free/calloc/realloc and logs each memory

src/hulog.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737

3838

3939
/* ----------- Defines ------------------------------------------- */
40+
/* Can be externally overridden. */
41+
#if !defined(MAX_CALL_STACK)
4042
#define MAX_CALL_STACK 20 /* Limits the callstack depth to store */
43+
#endif
4144

4245

4346
/* ----------- Types --------------------------------------------- */

0 commit comments

Comments
 (0)