diff --git a/README.md b/README.md index 0ceb2f4..270cd8b 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Supported Platforms Stackusage is primarily developed and tested on Linux, but basic functionality should work in macOS / OS X as well. Current version has been tested on: -- macOS Big Sur 11.0 +- macOS Monterey 12.1 - Ubuntu 20.04 LTS Limitation: On macOS / OS X this tool relies on code injection using diff --git a/make.sh b/make.sh index af0ac59..51aaee9 100755 --- a/make.sh +++ b/make.sh @@ -95,7 +95,7 @@ fi # tests if [[ "${TESTS}" == "1" ]]; then - cd build && ctest -C unit --output-on-failure && ctest -C perf --verbose && cd .. || exiterr "tests failed, exiting." + cd build && ctest --output-on-failure && cd .. || exiterr "tests failed, exiting." fi # doc diff --git a/src/stackusage b/src/stackusage index fd0db8d..a7f294c 100755 --- a/src/stackusage +++ b/src/stackusage @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (C) 2015-2021 Kristofer Berggren +# Copyright (C) 2015-2022 Kristofer Berggren # All rights reserved. # # stackusage is distributed under the BSD 3-Clause license, see LICENSE for details. @@ -43,9 +43,9 @@ showusage() showversion() { - echo "stackusage v1.15" + echo "stackusage v1.16" echo "" - echo "Copyright (C) 2015-2021 Kristofer Berggren" + echo "Copyright (C) 2015-2022 Kristofer Berggren" echo "" echo "stackusage is distributed under the BSD 3-Clause license." echo "" @@ -182,7 +182,6 @@ while [ "${LIBPATHS[CNT]}" != "" ]; do SU_SIGNO="${SIGNO}" \ LD_PRELOAD="${LIBPATH}" \ DYLD_INSERT_LIBRARIES="${LIBPATH}" \ - DYLD_FORCE_FLAT_NAMESPACE=1 \ "${@:1}" else LLDBCMDPATH="${TMP}/lldb.cmd" @@ -190,7 +189,6 @@ while [ "${LIBPATHS[CNT]}" != "" ]; do echo "env SU_SIGNO=\"${SIGNO}\"" >> "${LLDBCMDPATH}" echo "env LD_PRELOAD=\"${LIBPATH}\"" >> "${LLDBCMDPATH}" echo "env DYLD_INSERT_LIBRARIES=\"${LIBPATH}\"" >> "${LLDBCMDPATH}" - echo "env DYLD_FORCE_FLAT_NAMESPACE=1" >> "${LLDBCMDPATH}" echo "run ${@:2}" >> "${LLDBCMDPATH}" lldb "${1}" -s "${LLDBCMDPATH}" fi diff --git a/src/stackusage.1 b/src/stackusage.1 index cdd22f8..925aca5 100644 --- a/src/stackusage.1 +++ b/src/stackusage.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man. -.TH STACKUSAGE "1" "December 2021" "stackusage v1.15" "User Commands" +.TH STACKUSAGE "1" "January 2022" "stackusage v1.16" "User Commands" .SH NAME stackusage \- measure stack usage in applications .SH SYNOPSIS @@ -57,6 +57,6 @@ Written by Kristofer Berggren .SH "REPORTING BUGS" Report bugs at https://github.com/d99kris/stackusage .SH COPYRIGHT -Copyright \(co 2015\-2021 Kristofer Berggren +Copyright \(co 2015\-2022 Kristofer Berggren .PP stackusage is distributed under the BSD 3\-Clause license. diff --git a/src/sumain.c b/src/sumain.c index 8023a93..6df2477 100644 --- a/src/sumain.c +++ b/src/sumain.c @@ -1,7 +1,7 @@ /* * sumain.c * - * Copyright (C) 2015-2018 Kristofer Berggren + * Copyright (C) 2015-2022 Kristofer Berggren * All rights reserved. * * stackusage is distributed under the BSD 3-Clause license, see LICENSE for details. @@ -50,6 +50,13 @@ #define SU_LOG_WARN SU_LOG("%s (pid %d): %s:%d warning\n", \ su_name, getpid(), __FUNCTION__, __LINE__) +#if defined(__APPLE__) +#define DYLD_INTERPOSE(_newfun, _orgfun) \ +__attribute__((used)) static struct{ const void *newfun; const void *orgfun; } _interpose_##_orgfun \ +__attribute__ ((section ("__DATA,__interpose"))) = { (const void *)(unsigned long)&_newfun, \ + (const void *)(unsigned long)&_orgfun } +#endif + /* ----------- Types --------------------------------------------- */ typedef struct @@ -168,20 +175,32 @@ void signal_handler(int num) } +#if defined(__APPLE__) +int pthread_create_wrap(pthread_t *thread, const pthread_attr_t *attr, + void *(*start_routine) (void *), void *arg); + +int pthread_create_wrap(pthread_t *thread, const pthread_attr_t *attr, + void *(*start_routine) (void *), void *arg) +#else int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg) +#endif { int rv = -1; su_threadstart_t *tstart = NULL; if(real_pthread_create == NULL) { +#if defined(__APPLE__) + real_pthread_create = pthread_create; +#else /* Get function ptr to real pthread_create */ real_pthread_create = dlsym(RTLD_NEXT, "pthread_create"); if(real_pthread_create == NULL) { SU_LOG_ERR; } +#endif /* Initialize thread key with callback at thread termination */ pthread_key_create(&threadkey, su_thread_fini); @@ -225,6 +244,9 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr, return rv; } +#if defined(__APPLE__) +DYLD_INTERPOSE(pthread_create_wrap, pthread_create); +#endif /* ----------- Local Functions ----------------------------------- */