This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v3] Enable 'set print inferior-events' and improve detach/fork/kill/exit messages


On 03/09/2018 09:55 PM, Sergio Durigan Junior wrote:

> But if we use 'add_thread_silent' (with the same configuration as
> before):
> 
>   (gdb) run
>   Starting program: a.out
>   [Attaching after process 26807 fork to child process 26807.]
>   [New inferior 26811]
>   [Detaching after fork from child process 26811.]
>   [Inferior 26807 detached]
>   [Inferior 2 (process 26811) exited normally]

I still think the "inferior PID" messages are misleading,
because PID is not the inferior number.  I think it would be
better if they read something like:

    [Attaching after process 26807 fork to child process 26807.]
-   [New inferior 26811]
+   [New inferior 2 (process 26811)]
    [Detaching after fork from child process 26811.]
-   [Inferior 26807 detached]
+   [Inferior 1 (process 26807) detached]
    [Inferior 2 (process 26811) exited normally]

I.e.:

    [Attaching after process 26807 fork to child process 26807.]
    [New inferior 2 (process 26811)]
    [Detaching after fork from child process 26811.]
    [Inferior 1 (process 26807) detached]
    [Inferior 2 (process 26811) exited normally]

Please consider fixing that at the same time.

> @@ -2598,8 +2598,14 @@ kill_command (const char *arg, int from_tty)
>      error (_("The program is not being run."));
>    if (!query (_("Kill the program being debugged? ")))
>      error (_("Not confirmed."));
> +  pid_t pid = ptid_get_pid (inferior_ptid);
> +  int infnum = current_inferior ()->num;
>    target_kill ();
>  
> +  if (print_inferior_events)
> +    printf_unfiltered (_("[Inferior %d (process %d) has been killed]\n"),
> +		       infnum, pid);

The "process %d" part should be using target_pid_to_str instead.
Not all targets have the concept of a "process" (e.g., when remote
debugging a bare metal system), or have access to the actual pid
number (older gdbservers).  In such case, the above prints
the fake internal magic process id (magic_null_ptid).  E.g.:

 $ ./gdb -q --batch -ex "set remote multiprocess-feature-packet off" -ex "tar rem :9999" -ex "info inferiors" -ex "kill"
   Num  Description       Executable        
 * 1    Remote target     gdb/binutils-gdb/build/gdb/gdbserver/gdbserver
        ^^^^^^^^^^^^^
 Kill the program being debugged? (y or n)
 [Inferior 1 (process 42000) has been killed]
              ^^^^^^^^^^^^^

You'll need to capture the target_pid_to_str output
before killing, otherwise after target_kill the target
might no longer be pushed on the target stack.

This pattern appears in several places in the patch.  

The fork-related paths should be fine to print inf->pid directly,
since fork implies support for multiple processes.

> diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp
> index 2a8bf27e5c..20fa041155 100644
> --- a/gdb/testsuite/gdb.base/catch-syscall.exp
> +++ b/gdb/testsuite/gdb.base/catch-syscall.exp
> @@ -179,7 +179,7 @@ proc check_for_program_end {} {
>      # Deleting the catchpoints
>      delete_breakpoints
>  
> -    gdb_continue_to_end
> +    gdb_continue_to_end "" continue 1

Changes like this appear several times in the patch -- can you
expand on why they're needed?


> +
> +if { [use_gdb_stub] } {
> +    untested "not supported on gdbserver"

There should be a comment above this mentioning what
wouldn't work with gdbserver, since it's not obvious to
me.  (I think we may have gone through that in a previous
iteration, but it'd be better if the reason was written
down here).

Note: it's not "on gdbserver", it's on "target remote" stubs.
gdbserver+extended-remote works.  And there are stubs others
than gdbserver.

> diff --git a/gdb/testsuite/gdb.threads/process-dies-while-detaching.c b/gdb/testsuite/gdb.threads/process-dies-while-detaching.c
> index b0fd84b483..1871f6cf81 100644
> --- a/gdb/testsuite/gdb.threads/process-dies-while-detaching.c
> +++ b/gdb/testsuite/gdb.threads/process-dies-while-detaching.c
> @@ -80,6 +80,8 @@ parent_function (pid_t child)
>    alarm (300);
>  
>    ret = waitpid (child, &status, 0);
> +  /* Give a chance to GDB print its messages.  */
> +  usleep (100);
>  

This is probably racy and I'd a prefer a better fix that
avoids it.  Why did you need it?  What/how does the failure
look like without this?  Why does it happen?

>    if (ret == -1)
>      {
Thanks,
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]