From: Keith Owens <kaos@ocs.com.au>
To: Linux Kernel List <linux-kernel@vger.kernel.org>
Subject: Re: Functions with Large Stack Usage
Date: Wed, 28 Aug 2002 13:56:17 +1000 [thread overview]
Message-ID: <4003.1030506977@kao2.melbourne.sgi.com> (raw)
In-Reply-To: Your message of "27 Aug 2002 14:08:24 -0400." <1030471704.1610.47.camel@wiley>
On 27 Aug 2002 14:08:24 -0400,
Danny Cox <danscox@mindspring.com> wrote:
> After having read of the stack overflow "issues" awhile back, a couple
>of ideas gelled, with this script as a result. The script finds
>functions that use a large (changeable) amount of stack space. Note:
>it's heuristic, it's static, it only looks at compiled-in functions, and
>says nothing about the dynamic system. It DOES point out functions that
>may (MAY) need to be examined closer.
>...
> How it works: With Keith Owens' KDB patch, one may compile the kernel
>with frame pointers. With the Disassemble::X86 Perl module from CPAN
>(http://search.cpan.org/author/BOBMATH/Disassemble-X86-0.12/X86.pm),
>it's easy. It requires the vmlinux and System.map files, and for each
>function looks at the first 10 instructions for the 'sub esp,N'. The N
>is the number of bytes of stack used.
No need for frame pointers, or Perl. Run as
kernel.stack vmlinux $(/sbin/modprobe -l)
#!/bin/bash
#
# Run a compiled ix86 kernel and print large local stack usage.
#
# />:/{s/[<>:]*//g; h; } On lines that contain '>:' (headings like
# c0100000 <_stext>:), remove <, > and : and hold the line. Identifies
# the procedure and its start address.
#
# /subl\?.*\$0x[^,][^,][^,].*,%esp/{ Select lines containing
# subl\?...0x...,%esp but only if there are at least 3 digits between 0x and
# ,%esp. These are local stacks of at least 0x100 bytes.
#
# s/.*$0x\([^,]*\).*/\1/; Extract just the stack adjustment
# /^[89a-f].......$/d; Ignore line with 8 digit offsets that are
# negative. Some compilers adjust the stack on exit, seems to be related
# to goto statements
# G; Append the held line (procedure and start address).
# s/\(.*\)\n.* \(.*\)/\1 \2/; Remove the newline and procedure start
# address. Leaves just stack size and procedure name.
# p; }; Print stack size and procedure name.
#
# /subl\?.*%.*,%esp/{ Selects adjustment of %esp by register, dynamic
# arrays on stack.
# G; Append the held line (procedure and start address).
# s/\(.*\)\n\(.*\)/Dynamic \2 \1/; Reformat to "Dynamic", procedure
# start address, procedure name and the instruction that adjusts the
# stack, including its offset within the proc.
# p; }; Print the dynamic line.
#
#
# Leading spaces in the sed string are required.
#
objdump --disassemble "$@" | \
sed -ne '/>:/{s/[<>:]*//g; h; }
/subl\?.*\$0x[^,][^,][^,].*,%esp/{
s/.*\$0x\([^,]*\).*/\1/; /^[89a-f].......$/d; G; s/\(.*\)\n.* \(.*\)/\1 \2/; p; };
/subl\?.*%.*,%esp/{ G; s/\(.*\)\n\(.*\)/Dynamic \2 \1/; p; }; ' | \
sort
prev parent reply other threads:[~2002-08-28 3:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-27 18:08 Functions with Large Stack Usage Danny Cox
2002-08-28 3:56 ` Keith Owens [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4003.1030506977@kao2.melbourne.sgi.com \
--to=kaos@ocs.com.au \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox