Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: unbounded recursive call in a shell script crashes zsh
- X-seq: zsh-workers 40963
- From: Jérémie Roquet <jroquet@xxxxxxxxxxxxx>
- To: Kamil Dudka <kdudka@xxxxxxxxxx>
- Subject: Re: unbounded recursive call in a shell script crashes zsh
- Date: Thu, 13 Apr 2017 17:21:08 +0200
- Cc: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=oXf09Yl8KORI0slbEvYlXrQo1nE4fBOIlmhSUccS1yU=; b=GQne4RVnbJ58ldVQKBCEbeB7J7j4rc3UlZH3bQNAs0EAvDuGVTd0spQB3aJj96Kdyg k9aQIWxqedifdY8tbxIMqqGHnLCj/5MDr1GQqtaAkKwG6PF9D5ASBuODDA5QHNaF9hb2 /IyDmrH5ab0MpNZ7Z1eXsqWu2I3QqN2nOgrVAMRX17FiTtxR1mKehSYsrv4ynHh60x1n fQjHMTgUlCTeNQ9LCGkvvrMsodWtcyHLgtZHwvhZJ9+sWTVT382UI0Tri0ifTxJ+S4sF H1bNoLNc8V4huDFqfysxuAViWzhxzKAaZXgSerT5ZWywQJmIH9YDgIhhrhiOITf8bdne No6Q==
- In-reply-to: <2350280.olGvC23INb@kdudka-nb>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <2960832.nVDpiBkaWZ@kdudka-nb> <2420758.31stuSQeAV@kdudka-nb> <CAH+w=7atHK+_7fdzxCB4gRkWiKW8zCcTvW-qHM-0fUjH=OsPDQ@mail.gmail.com> <2350280.olGvC23INb@kdudka-nb>
- Sender: arkanosis@xxxxxxxxx
2017-04-13 16:30 GMT+02:00 Kamil Dudka <kdudka@xxxxxxxxxx>:
> I was trying to reduce the stack usage of zsh but was not really successful,
> mainly because I do not know how to efficiently find the automatic variables
> that consumed the biggest portion of the stack. […] Do you have any
> estimation about where else the stack allocation could be reduced?
We get some useful information if we link without the “-s” flag (and
it can help to compile with “-O0 -ggdb” as well).
Then, using gdb's “backtrace” we get that the stack is being consumed
by recursion throught the following 13 frames:
#18596 0x0000000000464733 in execif (state=0x7fffffffc9f0, do_exec=0)
at loop.c:572
#18597 0x00000000004360e8 in execcmd_exec (state=0x7fffffffc9f0,
eparams=0x7fffffffc5e0, input=0, output=0, how=18, last1=2) at
exec.c:3705
#18598 0x00000000004307ea in execpline2 (state=0x7fffffffc9f0,
pcode=67, how=18, input=0, output=0, last1=0) at exec.c:1872
#18599 0x000000000042f505 in execpline (state=0x7fffffffc9f0,
slcode=13314, how=18, last1=0) at exec.c:1602
#18600 0x000000000042e859 in execlist (state=0x7fffffffc9f0,
dont_change_job=1, exiting=0) at exec.c:1360
#18601 0x000000000042df2f in execode (p=0x7019e0, dont_change_job=1,
exiting=0, context=0x4ba7a8 "shfunc") at exec.c:1141
#18602 0x000000000043ae92 in runshfunc (prog=0x7019e0, wrap=0x0,
name=0x7ffff7fe7028 "foo") at exec.c:5675
#18603 0x000000000043a763 in doshfunc (shfunc=0x701a70,
doshargs=0x7ffff7ff2568, noreturnval=0) at exec.c:5539
#18604 0x000000000043979f in execshfunc (shf=0x701a70,
args=0x7ffff7ff2568) at exec.c:5113
#18605 0x00000000004362c3 in execcmd_exec (state=0x7fffffffd830,
eparams=0x7fffffffd420, input=0, output=0, how=18, last1=1) at
exec.c:3757
#18606 0x00000000004307ea in execpline2 (state=0x7fffffffd830,
pcode=131, how=18, input=0, output=0, last1=1) at exec.c:1872
#18607 0x000000000042f505 in execpline (state=0x7fffffffd830,
slcode=3074, how=18, last1=1) at exec.c:1602
#18608 0x000000000042e859 in execlist (state=0x7fffffffd830,
dont_change_job=0, exiting=1) at exec.c:1360
And using gdb's “info frame” on each frame and looking at “frame at”
and “called by frame at”, we get:
execlist: 416 bytes
execpline: 464 bytes
execpline2: 208 bytes
execcmd_exec: 1056 bytes
execshfunc: 336 bytes
doshfunc: 736 bytes
runshfunc: 336 bytes
execode: 96 bytes
execlist: 416 bytes
execpline: 464 bytes
execpline2: 208 bytes
execcmd_exec: 1056 bytes
execif: 64 bytes
If we aggregate, it gives us:
execcmd_exec: 2112 bytes
execpline: 928 bytes
execlist: 832 bytes
doshfunc: 736 bytes
execpline2: 416 bytes
execshfunc: 336 bytes
runshfunc: 336 bytes
execode: 96 bytes
execif: 64 bytes
Hence a total of 5856 bytes per recursion, or 5719 kiB for 10000 recursions.
Best regards,
--
Jérémie
Messages sorted by:
Reverse Date,
Date,
Thread,
Author