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: Questions on commit 6c95b8df7fef5273da71c34775918c554aae0ea8


On 09/20/2014 07:39 PM, Doug Evans wrote:
> [Ugh, bad To address on first try.]
> 
> Hi.
> 
> While looking into removing lwp_list from gdb (akin to what I did for
> gdbserver) I found that several bits of target code are calling
> init_thread_list
> (grep init_thread_list *.c).
> Maybe there's the odd case where target code would need to do this,
> but normally when should target code *ever* do this?

> To try to assist you with getting a handle on my confusion, consider
> remote.c:extended_remote_create_inferior_1 from gdb 6.8:
> 
>   /* Clean up from the last time we were running.  */
>   init_thread_list ();
>   init_wait_for_inferior ();
> 
> Now look at what's there today:
> 
>   if (!have_inferiors ())
>     {
>       /* Clean up from the last time we ran, before we mark the target
>          running again.  This will mark breakpoints uninserted, and
>          get_offsets may insert breakpoints.  */
>       init_thread_list ();
>       init_wait_for_inferior ();
>     }

> 
> I think(!) there may be multiple ways to look at all of this as being
> wrong, so pick your favorite, but here's one way: What does it matter
> whether there are other inferiors as to whether
> remote.c:extended_remote_create_inferior has to "clean up from the
> last time we were running"?
> 
> Obviously we can't call init_thread_list if there are other inferiors,
> but why are we calling init_thread_list here at all?  Why isn't this
> state being managed by gdb itself (inf*.c or some such)?  I can
> imagine one can look at this as just being still a work in progress on
> the way to proper multi-target support.  It's stil a bit odd though to
> have taken this step this way, so I'm hoping for some clarification.

Really not sure what sort of answer you're looking for.

I don't really recall history on that level of detail,
but, before 6c95b8df, the only kind of multi-process GDB supported,
was the model used by DICOS.  On that platform, we didn't use
"run" at all, only "attach" and all programs shared the program
space.  Well, before 6c95b8df, GDB didn't even have the
concept of a program space, but it didn't matter; even now that
it does, a single program space is the model that best fits.

So when we got to making GDB's multi-process fit for Linux,
which was the point of that patch, we must have stumbled on that
init_thread_list call in remote.c:extended_remote_create_inferior_1,
as soon as we did two "run"s in a row.  So the change in that
patch just looks like the conservative change.

The comment change you show wasn't done by that patch.
A trivial git blame 6c95b8df^ points at:

commit 45280a5259f209ba74ed8255674a3fd345307a55
Author:     Daniel Jacobowitz <drow@false.org>
AuthorDate: Thu May 8 16:08:10 2008 +0000

        * remote.c (extended_remote_create_inferior_1): Clean up
        before marking the target running.

I didn't dig deeper than that, but git blame further will
probably point out something ancient.

> Another related question I have is: Why does remote-sim.c:gdbsim_create_inferior
> call init_wait_for_inferior unconditionally whereas the above code
> conditions the call on !have_inferiors()? 

Most probably because nobody has ever tried making remote sim work
with multiple processes at the same time, so nobody ever stumbled
on that.

> Maybe it's a simple
> oversight, but I think (emphasis on THINK, I could certainly be
> missing something) we need to take a step back and ask why this code
> is there at all.  Putting this code in target routines gives us a lot
> of flexibility, but the cost is more mental load (for lack of a better
> phrase) and more touch points when trying to fix/improve core gdb, and
> I'm getting the impression that the pendulum has swung too far towards
> putting general housekeeping operations in target code.

Huh?  I think you're getting this backwards.  You make it sound like
we've been adding more of this stuff in target code ("putting"),
while instead these are _ancient_ code that over the years we've
been cleaning up.

Why not just git blame on that one?  It shows:

40b92220 (Jim Kingdon          1993-09-17 17:27:43 +0000  467)
8501c742 (Stu Grossman         1996-08-13 00:01:37 +0000  468)   gdbsim_kill ();
40b92220 (Jim Kingdon          1993-09-17 17:27:43 +0000  469)   remove_breakpoints ();
ec25d19b (Steve Chamberlain    1993-01-03 22:36:04 +0000  470)   init_wait_for_inferior ();
ec25d19b (Steve Chamberlain    1993-01-03 22:36:04 +0000  471)

Thanks,
Pedro Alves


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