From: "Douglas Evans" <dje@google.com>
To: gdb@sourceware.org
Subject: Re: linux-thread-db.c not only caller of add_thread, -> gdb segv
Date: Sat, 10 Nov 2007 05:20:00 -0000 [thread overview]
Message-ID: <e394668d0711092120t4164db7dw94d4ac58f3740c1d@mail.gmail.com> (raw)
In-Reply-To: <e394668d0711091940n7ec01450g8b82e5c3163e4690@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1321 bytes --]
On Nov 9, 2007 7:40 PM, Douglas Evans <dje@google.com> wrote:
> I suspect it's a matter of degrees (so to speak) or word choice (apologies).
> Until MAY_FOLLOW_EXEC is true for linux I'd expect gdb to return control
> to the user when an exec() happens.
> Am I wrong in thinking gdb will lose control across the exec()?
I guess what gdb does for an exec() when MAY_FOLLOW_EXEC==0 is at
least partially a matter of taste or definition. Running some
experiments I can see that I can control (e.g. single step) the "new"
process after the exec but the symbol info is all wrong if I exec() a
different program.
It didn't take much to get gdb to follow the exec'ing of toy programs.
So setting aside a discussion of what MAY_FOLLOW_EXEC==0 really means
on linux, how much work remains to support MAY_FOLLOW_EXEC==1?
With this patch I can step across the exec from test-exec1.c to test-exec2.c.
IWBN if gdb remembered the original program so that if I run it again,
gdb reruns test-exec1.x and not test-exec2.x.
This is not a real patch, just an experiment. I had to comment out
the call to target_mourn_inferior to avoid a hang in gdb (and even a
hang in gdb of gdb). Perhaps some aspect of mourning is required
here, but just not a full-blown one.
Any ideas what it would take to properly support MAY_FOLLOW_EXEC==1?
[-- Attachment #2: may-follow-exec-play.txt --]
[-- Type: text/plain, Size: 3106 bytes --]
Index: infrun.c
===================================================================
RCS file: /cvs/src/src/gdb/infrun.c,v
retrieving revision 1.250
diff -u -p -r1.250 infrun.c
--- infrun.c 2 Nov 2007 14:47:28 -0000 1.250
+++ infrun.c 10 Nov 2007 04:58:10 -0000
@@ -108,6 +108,7 @@ static ptid_t previous_inferior_ptid;
/* This is true for configurations that may follow through execl() and
similar functions. At present this is only true for HP-UX native. */
+#define MAY_FOLLOW_EXEC 1
#ifndef MAY_FOLLOW_EXEC
#define MAY_FOLLOW_EXEC (0)
#endif
@@ -396,7 +397,9 @@ follow_exec (int pid, char *execd_pathna
error (_("Could find run target to save before following exec"));
gdb_flush (gdb_stdout);
+#if 0
target_mourn_inferior ();
+#endif
inferior_ptid = pid_to_ptid (saved_pid);
/* Because mourn_inferior resets inferior_ptid. */
push_target (tgt);
[dje@seba gdb]$ cat test-exec1.c
#include <stdio.h>
#include <unistd.h>
int
main (int argc, char *argv[])
{
printf ("this is %s\n", argv[0]);
if (argc == 1)
execl ("./test-exec2.x", "./test-exec2.x", "second", NULL);
return 0;
}
[dje@seba gdb]$ cat test-exec2.c
#include <stdio.h>
#include <unistd.h>
static void
second ()
{
printf ("second\n");
}
int
main (int argc, char *argv[])
{
printf ("this is %s\n", argv[0]);
if (argc == 1)
execl (argv[0], argv[0], "second", NULL);
second ();
return 0;
}
[dje@seba gdb]$ gcc test-exec1.c -o test-exec1.x -g
[dje@seba gdb]$ gcc test-exec2.c -o test-exec2.x -g
[dje@seba gdb]$ ./gdb test-exec1.x
GNU gdb 6.7.50.20071110-cvs
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) b main
Breakpoint 1 at 0x80483c8: file test-exec1.c, line 7.
(gdb) r
Starting program: /home/dje/gnu/sourceware/head/obj/gdb/test-exec1.x
Breakpoint 1, main (argc=
1, argv=0xbfff2e64) at test-exec1.c:7
7 printf ("this is %s\n", argv[0]);
(gdb) n
this is /home/dje/gnu/sourceware/head/obj/gdb/test-exec1.x
8 if (argc == 1)
(gdb)
9 execl ("./test-exec2.x", "./test-exec2.x", "second", NULL);
(gdb)
Executing new program: /home/dje/gnu/sourceware/head/obj/gdb/test-exec2.x
warning: Temporarily disabling breakpoints for unloaded shared library "/lib/libc.so.6"
Breakpoint 1, main (argc=
2, argv=0xbf848ef4) at test-exec2.c:13
13 printf ("this is %s\n", argv[0]);
(gdb)
this is ./test-exec2.x
14 if (argc == 1)
(gdb)
16 second ();
(gdb)
second
17 return 0;
(gdb) c
Continuing.
Program exited normally.
(gdb) r
Starting program: /home/dje/gnu/sourceware/head/obj/gdb/test-exec2.x
Breakpoint 1, main (argc=
1, argv=0xbf9da854) at test-exec2.c:13
13 printf ("this is %s\n", argv[0]);
(gdb) n
this is /home/dje/gnu/sourceware/head/obj/gdb/test-exec2.x
14 if (argc == 1)
(gdb) q
The program is running. Exit anyway? (y or n) y
[dje@seba gdb]$
next prev parent reply other threads:[~2007-11-10 5:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-09 4:38 Douglas Evans
2007-11-09 14:02 ` Daniel Jacobowitz
2007-11-10 1:27 ` Douglas Evans
2007-11-10 3:26 ` Daniel Jacobowitz
2007-11-10 3:40 ` Douglas Evans
2007-11-10 5:20 ` Douglas Evans [this message]
2007-11-10 16:00 ` Daniel Jacobowitz
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=e394668d0711092120t4164db7dw94d4ac58f3740c1d@mail.gmail.com \
--to=dje@google.com \
--cc=gdb@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