From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id DEAF0385DC23 for ; Wed, 15 Apr 2020 15:08:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DEAF0385DC23 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-263-R67YQFUsMvibaxW34mfjtw-1; Wed, 15 Apr 2020 11:08:23 -0400 X-MC-Unique: R67YQFUsMvibaxW34mfjtw-1 Received: by mail-ed1-f71.google.com with SMTP id c2so3179303edx.16 for ; Wed, 15 Apr 2020 08:08:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=7yZ6RNA7IkJwzH8VrFmuoymGeP+o/pi/o7T3QC7whUc=; b=bj9tKLSnLlqhD52fmCRTlAyyL/LtVNRHOgJ+9TRDiB1xYHULubI6uhSbe8ijKakNKs wjY//Q5cnajr1eBAcCnl3M7byfe4yIq3QTHXOYVqFuIctcGSjY/W/dRvd0u0q7cVtr6+ a3Kw24ORVCQeaBUcMO9tHfCJto3xpcGKrril6Q3K6eA/R7FpFAhZcl91+g25a7xNhGco U1JA9EY2sBBwH8RNKbl5QlxO0nB0MeDjiVOJj0IoHxwy/7aZrSAH50I1kMNOsb06/1Nf z/PyMOcAQG3xbSRE4xs5ye5yMFUy1SsMMl6pbWzxhcQGlMXKfoYhzg4bFo30SbUhivii nnmg== X-Gm-Message-State: AGi0PubhQfEwIh3lCnpm7VIVXfU1oOHfrlRy8PSoj8T+DMUw4lZxuGbh N+zGjxiG55feVNq7IaX4+6jDjDVvgSck/xxnWLHgu3vWs/HM75lK4QO1c+yeRbn6cHthkc7fpPF uz4jpqVAZmhMq0493PvrOuw== X-Received: by 2002:a17:906:614a:: with SMTP id p10mr5647817ejl.88.1586963302357; Wed, 15 Apr 2020 08:08:22 -0700 (PDT) X-Google-Smtp-Source: APiQypL7yehFF2g3hVaGcBevlTNuXROhEN6lMW4S5Vgf8c6IwKbqnrILfVB7sUFD2188sahOdQn7UA== X-Received: by 2002:a17:906:614a:: with SMTP id p10mr5647793ejl.88.1586963302089; Wed, 15 Apr 2020 08:08:22 -0700 (PDT) Received: from ?IPv6:2001:8a0:f909:7b00:56ee:75ff:fe8d:232b? ([2001:8a0:f909:7b00:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id k24sm2654062ejs.80.2020.04.15.08.08.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Apr 2020 08:08:21 -0700 (PDT) Subject: Re: [PATCH 25/28] Don't write to inferior_ptid in windows-nat.c, part II To: Hannes Domani , Gdb-patches References: <20200414175434.8047-1-palves@redhat.com> <20200414175434.8047-26-palves@redhat.com> <1253231843.1175283.1586904073822@mail.yahoo.com> From: Pedro Alves Message-ID: Date: Wed, 15 Apr 2020 16:08:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <1253231843.1175283.1586904073822@mail.yahoo.com> Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-24.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Apr 2020 15:08:27 -0000 On 4/14/20 11:41 PM, Hannes Domani via Gdb-patches wrote: > The removal of these lines breaks debugging on Windows, right on startup = I get: >=20 > (gdb) r > Starting program: C:\qiewer\heob\heob64.exe > C:/src/repos/binutils-gdb.git/gdb/thread.c:86: internal-error: thread_inf= o* inferior_thread(): Assertion `tp' failed. >=20 > Full stacktrace of the assertion failure: >=20 > (gdb) bt > #0=C2=A0 internal_error (file=3D0xa713a8 "C:/src/repos/binutils-gdb.git/gdb/thread.c", line=3D86, > =C2=A0=C2=A0=C2=A0 fmt=3D0xa71388 "%s: = Assertion `%s' failed.") at C:/src/repos/binutils-gdb.git/gdbsupport/errors= .cc:51 > #1=C2=A0 0x000000000066cfd9 in inferior_thread () at C:/src/repos/binutil= s-gdb.git/gdb/thread.c:86 > #2=C2=A0 inferior_thread () at C:/src/repos/binutils-gdb.git/gdb/thread.c= :83 > #3=C2=A0 0x00000000005603a0 in post_create_inferior (target=3D0x999ba0 , from_tty=3Dfrom_tty@entry=3D0) > =C2=A0=C2=A0=C2=A0 at C:/src/repos/binutils-gdb.git/gdb/infcmd.c:444 > #4=C2=A0 0x0000000000563727 in run_command_1 (args=3D, fro= m_tty=3D1, run_how=3DRUN_NORMAL) at C:/src/repos/binutils-gdb.git/gdb/infcm= d.c:670 > Btw., I think this variable in get_windows_debug_event is no longer usefu= l: > static windows_thread_info dummy_thread_info (0, 0, 0); >=20 Thanks for pointing that out. >=20 > This replacement works fine for me so far: Does this instead work for you? This adds a single switch_to_thread at the end of the initialization. >From 00648f5a0bd7b8d85a2bdf49a2d8f71087826062 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 15 Apr 2020 15:52:32 +0100 Subject: [PATCH] Fix Windows --- gdb/windows-nat.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 78e7e31c67..dd15fa1fab 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -358,6 +358,8 @@ struct windows_nat_target final : public x86_nat_target= const char *thread_name (struct thread_info *) override; =20 int get_windows_debug_event (int pid, struct target_waitstatus *ourstatu= s); + + void do_initial_windows_stuff (DWORD pid, bool attaching); }; =20 static windows_nat_target the_windows_nat_target; @@ -1508,8 +1510,6 @@ windows_nat_target::get_windows_debug_event (int pid, { BOOL debug_event; DWORD continue_status, event_code; - windows_thread_info *th; - static windows_thread_info dummy_thread_info (0, 0, 0); DWORD thread_id =3D 0; =20 /* If there is a relevant pending stop, report it now. See the @@ -1522,7 +1522,7 @@ windows_nat_target::get_windows_debug_event (int pid, *ourstatus =3D stop->status; =20 ptid_t ptid (current_event.dwProcessId, thread_id); - th =3D thread_rec (ptid, INVALIDATE_CONTEXT); + windows_thread_info *th =3D thread_rec (ptid, INVALIDATE_CONTEXT); th->reload_context =3D 1; =20 return thread_id; @@ -1537,7 +1537,6 @@ windows_nat_target::get_windows_debug_event (int pid, =20 event_code =3D current_event.dwDebugEventCode; ourstatus->kind =3D TARGET_WAITKIND_SPURIOUS; - th =3D NULL; have_saved_context =3D 0; =20 switch (event_code) @@ -1563,7 +1562,7 @@ windows_nat_target::get_windows_debug_event (int pid, =09} /* Record the existence of this thread. */ thread_id =3D current_event.dwThreadId; - th =3D windows_add_thread + windows_add_thread (ptid_t (current_event.dwProcessId, current_event.dwThreadId, 0), =09 current_event.u.CreateThread.hThread, =09 current_event.u.CreateThread.lpThreadLocalBase, @@ -1580,7 +1579,6 @@ windows_nat_target::get_windows_debug_event (int pid, =09=09=09=09 current_event.dwThreadId, 0), =09=09=09 current_event.u.ExitThread.dwExitCode, =09=09=09 false /* main_thread_p */); - th =3D &dummy_thread_info; break; =20 case CREATE_PROCESS_DEBUG_EVENT: @@ -1594,7 +1592,7 @@ windows_nat_target::get_windows_debug_event (int pid, =20 current_process_handle =3D current_event.u.CreateProcessInfo.hProces= s; /* Add the main thread. */ - th =3D windows_add_thread + windows_add_thread (ptid_t (current_event.dwProcessId, =09=09 current_event.dwThreadId, 0), =09 current_event.u.CreateProcessInfo.hThread, @@ -1731,7 +1729,7 @@ windows_nat_target::get_windows_debug_event (int pid, =09 && windows_initialization_done) =09{ =09 ptid_t ptid =3D ptid_t (current_event.dwProcessId, thread_id, 0); -=09 th =3D thread_rec (ptid, INVALIDATE_CONTEXT); +=09 windows_thread_info *th =3D thread_rec (ptid, INVALIDATE_CONTEXT); =09 th->stopped_at_software_breakpoint =3D true; =09} pending_stops.push_back ({thread_id, *ourstatus, current_event}); @@ -1944,8 +1942,8 @@ windows_add_all_dlls (void) } } =20 -static void -do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching= ) +void +windows_nat_target::do_initial_windows_stuff (DWORD pid, bool attaching) { int i; struct inferior *inf; @@ -1961,8 +1959,8 @@ do_initial_windows_stuff (struct target_ops *ops, DWO= RD pid, int attaching) #endif current_event.dwProcessId =3D pid; memset (¤t_event, 0, sizeof (current_event)); - if (!target_is_pushed (ops)) - push_target (ops); + if (!target_is_pushed (this)) + push_target (this); disable_breakpoints_in_shlibs (); windows_clear_solib (); clear_proceed_status (0); @@ -1992,11 +1990,13 @@ do_initial_windows_stuff (struct target_ops *ops, D= WORD pid, int attaching) =20 windows_initialization_done =3D 0; =20 + ptid_t last_ptid; + while (1) { struct target_waitstatus status; =20 - ops->wait (minus_one_ptid, &status, 0); + last_ptid =3D this->wait (minus_one_ptid, &status, 0); =20 /* Note windows_wait returns TARGET_WAITKIND_SPURIOUS for thread =09 events. */ @@ -2004,9 +2004,11 @@ do_initial_windows_stuff (struct target_ops *ops, DW= ORD pid, int attaching) =09 && status.kind !=3D TARGET_WAITKIND_SPURIOUS) =09break; =20 - ops->resume (minus_one_ptid, 0, GDB_SIGNAL_0); + this->resume (minus_one_ptid, 0, GDB_SIGNAL_0); } =20 + switch_to_thread (find_thread_ptid (this, last_ptid)); + /* Now that the inferior has been started and all DLLs have been mapped, we can iterate over all DLLs and load them in. =20 @@ -2138,7 +2140,7 @@ windows_nat_target::attach (const char *args, int fro= m_tty) } #endif =20 - do_initial_windows_stuff (this, pid, 1); + do_initial_windows_stuff (pid, 1); target_terminal::ours (); } =20 @@ -2978,9 +2980,8 @@ windows_nat_target::create_inferior (const char *exec= _file, else saw_create =3D 0; =20 - do_initial_windows_stuff (this, pi.dwProcessId, 0); + do_initial_windows_stuff (pi.dwProcessId, 0); =20 /* windows_continue (DBG_CONTINUE, -1, 0); */ } --=20 2.14.5