From: "Theodore Ts'o" <tytso@mit.edu>
To: Ralph Corderoy <ralph@inputplus.co.uk>
Cc: coff@tuhs.org
Subject: [COFF] Re: Conditions, AKA exceptions.
Date: Sat, 11 Mar 2023 23:23:48 -0500 [thread overview]
Message-ID: <20230312042348.GJ860405@mit.edu> (raw)
In-Reply-To: <20230311112849.22C0920145@orac.inputplus.co.uk>
On Sat, Mar 11, 2023 at 11:28:49AM +0000, Ralph Corderoy wrote:
> Hi Larry,
>
> > cmd = aprintf("gdb -batch -ex backtrace '%s/bk' %u 1>&%d 2>&%d",
> > bin, getpid(), fileno(f), fileno(f));
> >
> > system(cmd);
>
> I also came up with this, probably on an SGI Iris Indigo, and got it
> added to the Unix Programming FAQ. :-)
>
> 6.5 How can I generate a stack dump from within a running program?
> http://www.faqs.org/faqs/unix-faq/programmer/faq/
>
> It works surprisingly often, i.e. the process is healthy enough to run
> system(3).
On Linux (or some other system using glibc) a limited facility is
built into the C library. So you can just do somthing like this:
{
void *stack_syms[32];
int frames;
frames = backtrace(stack_syms, 32);
backtrace_symbols_fd(stack_syms, frames, 2);
}
This is convenient if you want a stack trace, but the binary might be
on a rescue floppy which doesn't have space for gdb, or the user might
not have gdb installed. I use this for the fsck for ext4, and the
nice thing is that even with a stripped binary.
For example:
Signal (7) SIGBUS (sent from pid 4261) si_code=SI_USER
e2fsck(+0x36691)[0x564da1ed2691]
/lib/x86_64-linux-gnu/libc.so.6(+0x3bf90)[0x7f6e21c0bf90]
/lib/x86_64-linux-gnu/libc.so.6(read+0xd)[0x7f6e21cc80ed]
e2fsck(ask_yn+0x1de)[0x564da1ec90de]
e2fsck(fix_problem+0xfc0)[0x564da1ecc7b0]
e2fsck(+0x235b3)[0x564da1ebf5b3]
e2fsck(+0x252d3)[0x564da1ec12d3]
/lib/x86_64-linux-gnu/libext2fs.so.2(ext2fs_dblist_iterate3+0x5f)[0x7f6e21e430cf]
e2fsck(e2fsck_pass2+0x18b)[0x564da1ebdd7b]
e2fsck(e2fsck_run+0x5a)[0x564da1eb0c3a]
e2fsck(main+0x16cb)[0x564da1eacdbb]
/lib/x86_64-linux-gnu/libc.so.6(+0x2718a)[0x7f6e21bf718a]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x85)[0x7f6e21bf7245]
e2fsck(_start+0x21)[0x564da1eaefc1]
For more information see:
https://github.com/tytso/e2fsprogs/blob/master/e2fsck/sigcatcher.c#L379
- Ted
next prev parent reply other threads:[~2023-03-12 4:24 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-10 17:11 [COFF] Re: [TUHS] Re: Conditions, AKA exceptions. (Was: I can't drive 55: "GOTO considered harmful" 55th anniversary) Bakul Shah
2023-03-10 17:28 ` segaloco via COFF
2023-03-10 17:34 ` Larry McVoy
2023-03-10 17:35 ` Bakul Shah
2023-03-10 17:42 ` Larry McVoy
2023-03-11 11:28 ` [COFF] Conditions, AKA exceptions Ralph Corderoy
2023-03-12 4:23 ` Theodore Ts'o [this message]
2023-03-12 10:44 ` [COFF] " Ralph Corderoy
2023-03-12 16:46 ` Paul Winalski
2023-03-12 16:53 ` Larry McVoy
2023-03-10 17:43 ` [COFF] Re: [TUHS] Re: Conditions, AKA exceptions. (Was: I can't drive 55: "GOTO considered harmful" 55th anniversary) segaloco via COFF
2023-03-10 18:03 ` Dan Cross
2023-03-10 18:57 ` Bakul Shah
2023-03-10 19:57 ` Marshall Conover
2023-03-13 16:47 ` [COFF] Conditions, AKA exceptions Ralph Corderoy
2023-03-13 17:10 ` [COFF] " Paul Winalski
2023-03-13 21:12 ` Dave Horsfall
2023-03-10 17:47 ` [COFF] Re: [TUHS] Re: Conditions, AKA exceptions. (Was: I can't drive 55: "GOTO considered harmful" 55th anniversary) Bakul Shah
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=20230312042348.GJ860405@mit.edu \
--to=tytso@mit.edu \
--cc=coff@tuhs.org \
--cc=ralph@inputplus.co.uk \
/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;
as well as URLs for NNTP newsgroup(s).