public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "kelly at 219design dot com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug cli/27125] New: unwanted interaction of [-ex "bt"] with [-batch -return-child-result]. used to work in gdb 8.1
Date: Tue, 29 Dec 2020 01:22:01 +0000	[thread overview]
Message-ID: <bug-27125-4717@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=27125

            Bug ID: 27125
           Summary: unwanted interaction of [-ex "bt"] with [-batch
                    -return-child-result]. used to work in gdb 8.1
           Product: gdb
           Version: 9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: cli
          Assignee: unassigned at sourceware dot org
          Reporter: kelly at 219design dot com
  Target Milestone: ---

Steps to reproduce.

Use gdb 9.2

Mine:
    gdb --version
    GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2

Try both the following at the command line:

gdb -n -batch -return-child-result -ex "set args /tmp/hork" -ex "run" -ex "bt"
/bin/touch

    [Inferior 1 (process 2728) exited normally]
    No stack.


gdb -n -batch -return-child-result -ex "set args /hork_root" -ex "run" -ex "bt"
/bin/touch

    /bin/touch: cannot touch '/hork_root': Permission denied
    [Inferior 1 (process 2764) exited with code 01]
    No stack.

Note that in the second invocation, gdb prints "inferior... exited with code
01".  That is accurate.  In the first invocation, the inferior exit code is
zero (as expected), and in the second invocation, the inferior exit code is
non-zero (as expected).

What's wrong?

In both invocations, the exit code of the gdb process itself is 1. This is
surprising and unwanted, since I am invoking gdb with the
"-return-child-result" option.

What do I expect?

When using "-return-child-result", I expect the gdb process to exit 1
if-and-only-if the inferior exits with 1, and I expect the gdb process to exit
0 if-and-only-if the inferior exits with 0.

What I just described as expected behavior is also the actual observed behavior
when using gdb 8.1.

The problem can be (in part) alleviated by removing [-ex "bt"]

These return 0 and 1, respectively:

gdb -n -batch -return-child-result -ex "set args /tmp/hork" -ex "run" 
/bin/touch

gdb -n -batch -return-child-result -ex "set args /hork_root" -ex "run" 
/bin/touch


I have been using batch gdb in the manner described above as part of various
continuous integration jobs.

The benefit of using -return-child-result is so that I can use "bash -e" in the
continuous integration wrapper, and the job will fail fast if the process
launched under gdb does not exit successfully. The benefit of using [-ex "bt"]
is so that if the process under gdb crashes, then the continuous integration
log will contain a stack trace of the crash. This has been useful in capturing
stack traces of crashes that happen only rarely.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2020-12-29  1:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-29  1:22 kelly at 219design dot com [this message]
2020-12-29  4:56 ` [Bug cli/27125] " kelly at 219design dot com
2020-12-29  4:58 ` kelly at 219design dot com
2020-12-29  5:11 ` kelly at 219design dot com
2020-12-29  5:15 ` kelly at 219design dot com
2020-12-29 18:38 ` kelly at 219design dot com
2021-01-05 13:51 ` cbiesinger at google dot com

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=bug-27125-4717@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).