public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "simark at simark dot ca" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug gdb/27745] New: When re-running after an exec, the exec'd file gets executed with the exec'r args
Date: Fri, 16 Apr 2021 19:40:08 +0000	[thread overview]
Message-ID: <bug-27745-4717@http.sourceware.org/bugzilla/> (raw)

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

            Bug ID: 27745
           Summary: When re-running after an exec, the exec'd file gets
                    executed with the exec'r args
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: simark at simark dot ca
  Target Milestone: ---

With these two programs:

execer.c
---8<---
#include <unistd.h>
#include <stdio.h>

int main(int argc, char **argv) {
    printf("I am execer and my argv[1] is: %s\n", argv[1]);
    execl("./execee", "./execee", "arg-for-execee", NULL);
    return 0;
}
--->8---

execee.c
---8<---
#include <stdio.h>

int main(int argc, char **argv) {
    printf("I am execee and my argv[1] is: %s\n", argv[1]);
    return 0;
}
--->8---

Let's try to run in GDB:

$ ./gdb -q -nx --data-directory=data-directory --args ./execer args-for-execer
Reading symbols from ./execer...
(gdb) r
Starting program: /home/simark/build/binutils-gdb/gdb/execer args-for-execer
I am execer and my argv[1] is: args-for-execer
process 1479927 is executing new program:
/home/simark/build/binutils-gdb/gdb/execee
I am execee and my argv[1] is: arg-for-execee
[Inferior 1 (process 1479927) exited normally]
(gdb) 

So far so good, the arguments match the program.  Let's try to run again:

(gdb) r
Starting program: /home/simark/build/binutils-gdb/gdb/execee args-for-execer
I am execee and my argv[1] is: args-for-execer
[Inferior 1 (process 1479957) exited normally]
(gdb) 

Woops, we have executed execee with the arguments for execer.  I think this
behavior is not very useful.

My takeaway is:

- When re-running after an exec, GDB executes the last known program, execee in
this case.  It can be fine in some use cases, where you just want to debug the
execee again and again.  But it should find out the arguments with which the
execee was executed, save them in the inferior, and re-use them when you "run".
- In other use cases, the user could want to start debugging from scratch, that
means re-running execer.  GDB could remember the latest user-specified
executable for the inferior.  There would then be a setting to decide which
executable to run (the latest user-specified executable, execer, or the latest
seen executable, execee)

It is possible to remember the original executable by using "follow-exec-mode
== new", but IMO that's not very practical, the user needs to switch back to
inferior 1 to restart.  And if they restart multiple times, the new inferiors
just pile up.  It would make more sense to be able to re-run from the start
(execer) using a single inferior.

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

             reply	other threads:[~2021-04-16 19:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16 19:40 simark at simark dot ca [this message]
2021-04-17 16:42 ` [Bug gdb/27745] " tromey at sourceware dot org
2021-04-19  1:09 ` simark at simark dot ca
2021-04-21 14:59 ` palves at redhat dot com
2021-05-13 19:29 ` cvs-commit at gcc dot gnu.org

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