From patchwork Fri May 4 18:30:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 27116 Received: (qmail 60098 invoked by alias); 4 May 2018 18:30:50 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 59319 invoked by uid 89); 4 May 2018 18:30:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=till, sadly, Share X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 04 May 2018 18:30:20 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 1497C117C83 for ; Fri, 4 May 2018 14:30:06 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id c95f9ODEM8Gq for ; Fri, 4 May 2018 14:30:06 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 052FC117C7B for ; Fri, 4 May 2018 14:30:06 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4233) id 044B4487; Fri, 4 May 2018 14:30:06 -0400 (EDT) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [PATCH 2/3] gdbserver/Windows: Fix "no program to debug" error Date: Fri, 4 May 2018 14:30:02 -0400 Message-Id: <1525458603-33351-3-git-send-email-brobecker@adacore.com> In-Reply-To: <1525458603-33351-1-git-send-email-brobecker@adacore.com> References: <1525458603-33351-1-git-send-email-brobecker@adacore.com> Trying to start a program with GDBserver on Windows yields the following error: $ gdbserver.exe --once :4444 simple_main.exe Killing process(es): 5008 No program to debug Exiting The error itself comes from the following code shortly after create_inferior gets called (in server.c::main): /* Wait till we are at first instruction in program. */ create_inferior (program_path.get (), program_args); [...] if (last_status.kind == TARGET_WAITKIND_EXITED || last_status.kind == TARGET_WAITKIND_SIGNALLED) was_running = 0; else was_running = 1; if (!was_running && !multi_mode) error ("No program to debug"); What happens is that the "last_status" global starts initialized as zeroes, which means last_status.kind == TARGET_WAITKIND_EXITED, and we expect create_inferior to be waiting for the inferior to start until reaching the SIGTRAP, and to set the "last_status" global to match that last event we received. I suspect this is an unintended side-effect of the following change... commit 2090129c36c7e582943b7d300968d19b46160d84 Date: Thu Dec 22 21:11:11 2016 -0500 Subject: Share fork_inferior et al with gdbserver ... which removes some code in server.c that was responsible for starting the inferior in a functin that was named start_inferior, and looked like this: signal_pid = create_inferior (new_argv[0], &new_argv[0]); [...] /* Wait till we are at 1st instruction in program, return new pid (assuming success). */ last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0); The code has been transitioned to using fork_inferior, but sadly, only for the targets that support it. On Windows, the calls to wait setting "last_status" simply disappeared. This patch adds it back in the Windows-specific implementation of create_inferior. gdb/gdbserver/ChangeLog: * win32-low.c (win32_create_inferior): Add call to my_wait setting last_status global. --- gdb/gdbserver/win32-low.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c index db5dd49..7ed5fc5 100644 --- a/gdb/gdbserver/win32-low.c +++ b/gdb/gdbserver/win32-low.c @@ -704,6 +704,10 @@ win32_create_inferior (const char *program, do_initial_child_stuff (pi.hProcess, pi.dwProcessId, 0); + /* Wait till we are at 1st instruction in program, return new pid + (assuming success). */ + last_ptid = win32_wait (pid_to_ptid (current_process_id), &last_status, 0); + return current_process_id; }