public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug cli/27125] New: unwanted interaction of [-ex "bt"] with [-batch -return-child-result]. used to work in gdb 8.1
@ 2020-12-29  1:22 kelly at 219design dot com
  2020-12-29  4:56 ` [Bug cli/27125] " kelly at 219design dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: kelly at 219design dot com @ 2020-12-29  1:22 UTC (permalink / raw)
  To: gdb-prs

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-01-05 13:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-29  1:22 [Bug cli/27125] New: unwanted interaction of [-ex "bt"] with [-batch -return-child-result]. used to work in gdb 8.1 kelly at 219design dot com
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

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).