diff --git a/README.md b/README.md index 9138efe..0ceb2f4 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,18 @@ stack with a dummy data pattern. It also registers a callback routine to be called upon thread termination. In the callback routine the amount of remaining dummy pattern in the stack is checked, in order to determine the stack usage. +Interception is only possible when stackusage is built for the same +architecture as the program being analyzed. Stackusage tries to determine if +there is a mismatch, if encountered it will output a warning like this: + + warning: libstackusage.so architecture (ELF 64-bit) does not appear + to match architecture (ELF 32-bit), analysis may fail. + +To solve this, simply compile stackusage for the appropriate architecture, for +example by adding `-m32` to CMAKE_C_FLAGS in CMakeLists.txt, example: + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -g -m32 \ + License ======= Stackusage is distributed under the BSD 3-Clause license. See LICENSE file. diff --git a/src/stackusage b/src/stackusage index 2f4d1a4..fd0db8d 100755 --- a/src/stackusage +++ b/src/stackusage @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (C) 2015-2020 Kristofer Berggren +# Copyright (C) 2015-2021 Kristofer Berggren # All rights reserved. # # stackusage is distributed under the BSD 3-Clause license, see LICENSE for details. @@ -43,15 +43,33 @@ showusage() showversion() { - echo "stackusage v1.14" + echo "stackusage v1.15" echo "" - echo "Copyright (C) 2015-2020 Kristofer Berggren" + echo "Copyright (C) 2015-2021 Kristofer Berggren" echo "" echo "stackusage is distributed under the BSD 3-Clause license." echo "" echo "Written by Kristofer Berggren" } +check_arch_compat() +{ + LIBPATH="${1}" + PRGPATH="$(which ${2})" + if [[ "${PRGPATH}" != "" ]]; then + PRGARCH=$(file -b ${PRGPATH} | awk '{print $1 " " $2}') + LIBARCH=$(file -b ${LIBPATH} | awk '{print $1 " " $2}') + PRGBITS=$(file -b ${PRGPATH} | awk '{print $2}' | awk -F'-' '{print $1}') + LIBBITS=$(file -b ${LIBPATH} | awk '{print $2}' | awk -F'-' '{print $1}') + if [[ "${PRGBITS}" =~ ^(32|64)$ ]] && [[ "${LIBBITS}" =~ ^(32|64)$ ]] && \ + [[ "${PRGARCH}" != "${LIBARCH}" ]]; then + echo "warning: $(basename ${LIBPATH}) architecture (${LIBARCH}) does not appear" + echo "to match ${PRGPATH} architecture (${PRGARCH}), analysis may fail." + echo "see https://github.com/d99kris/stackusage#technical-details" + fi + fi +} + if [ "${1}" == "--help" ] ; then showusage exit 0 @@ -155,6 +173,9 @@ while [ "${LIBPATHS[CNT]}" != "" ]; do LIBPATH="${LIBPATHS[CNT]}" if [ -e "${LIBPATH}" ]; then + # Check if libstackusage is compatible with program to analyze + check_arch_compat "${LIBPATH}" "${1}" + # Run program if [ "${DEBUG}" == "0" ]; then SU_FILE="${TMPLOG}${OUTFILE}" \ diff --git a/src/stackusage.1 b/src/stackusage.1 index 554fcc7..cdd22f8 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" "August 2021" "stackusage v1.14" "User Commands" +.TH STACKUSAGE "1" "December 2021" "stackusage v1.15" "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\-2020 Kristofer Berggren +Copyright \(co 2015\-2021 Kristofer Berggren .PP stackusage is distributed under the BSD 3\-Clause license.