From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1978 invoked by alias); 12 Nov 2007 02:09:20 -0000 Received: (qmail 1964 invoked by uid 22791); 12 Nov 2007 02:09:19 -0000 X-Spam-Check-By: sourceware.org Received: from ug-out-1314.google.com (HELO ug-out-1314.google.com) (66.249.92.173) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 12 Nov 2007 02:09:13 +0000 Received: by ug-out-1314.google.com with SMTP id o2so756215uge for ; Sun, 11 Nov 2007 18:09:12 -0800 (PST) Received: by 10.66.221.5 with SMTP id t5mr329174ugg.1194833352231; Sun, 11 Nov 2007 18:09:12 -0800 (PST) Received: from ?192.168.0.4? ( [62.169.107.97]) by mx.google.com with ESMTPS id 39sm3976737ugb.2007.11.11.18.09.09 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 11 Nov 2007 18:09:11 -0800 (PST) Message-ID: <4737B5C6.8020701@portugalmail.pt> Date: Mon, 12 Nov 2007 02:09:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pt-BR; rv:1.8.1.6) Gecko/20070728 Thunderbird/2.0.0.6 Mnenhy/0.7.5.0 MIME-Version: 1.0 To: gdb-patches@sourceware.org, Lerele Subject: [gdbserver] (11/11) Windows CE process attaching support Content-Type: multipart/mixed; boundary="------------040806000401020107030606" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-11/txt/msg00224.txt.bz2 This is a multi-part message in MIME format. --------------040806000401020107030606 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 793 Hi, One of the Debug API differences between Windows CE and other versions of Windows, is that the inferior isn't automatically stopped either when running or attaching. On the desktop, Windows arranges for a breakpoint to be set before the entry point is ran, or after reporting the loaded dlls and running threads when attaching. For the run case, I'm already handling it by having gdbserver setting a breakpoing at the entry point, and removing it when it is hit, so gdb never sees it. The attach case wasn't working yet. We can reuse the new interrupt method to stop the inferior when that patch goes in. One quirk is knowing when to stop the inferior. There's a comment in the patch explaining it. It's not perfect, but it has been working here for a while. Cheers, Pedro Alves --------------040806000401020107030606 Content-Type: text/x-diff; name="wince_attach.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="wince_attach.diff" Content-length: 3980 2007-11-12 Pedro Alves * win32-low.c (attaching): New global. (win32_create_inferior): Clear the `attaching' global. (win32_attach): Set the `attaching' global. (get_child_debug_event) [_WIN32_WCE]: Stop the inferior when attaching. Only set a breakpoint at the entry point if not attaching. --- gdb/gdbserver/win32-low.c | 65 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 11 deletions(-) Index: src/gdb/gdbserver/win32-low.c =================================================================== --- src.orig/gdb/gdbserver/win32-low.c 2007-11-12 00:20:38.000000000 +0000 +++ src/gdb/gdbserver/win32-low.c 2007-11-12 00:21:52.000000000 +0000 @@ -65,6 +65,7 @@ int using_threads = 1; /* Globals. */ +static int attaching = 0; static HANDLE current_process_handle = NULL; static DWORD current_process_id = 0; static enum target_signal last_sig = TARGET_SIGNAL_0; @@ -670,6 +671,9 @@ win32_create_inferior (char *program, ch PROCESS_INFORMATION pi; DWORD err; + /* win32_wait needs to know we're not attaching. */ + attaching = 0; + if (!program) error ("No executable specified, specify executable to debug.\n"); @@ -772,6 +776,8 @@ win32_attach (unsigned long pid) if (DebugSetProcessKillOnExit != NULL) DebugSetProcessKillOnExit (FALSE); + /* win32_wait needs to know we're attaching. */ + attaching = 1; current_process_handle = h; current_process_id = pid; do_initial_child_stuff (pid); @@ -1524,11 +1530,44 @@ get_child_debug_event (struct target_wai goto gotevent; } - /* Keep the wait time low enough for confortable remote - interruption, but high enough so gdbserver doesn't become a - bottleneck. */ - if (!WaitForDebugEvent (¤t_event, 250)) - return 0; +#ifndef _WIN32_WCE + attaching = 0; +#else + if (attaching) + { + /* WinCE doesn't set an initial breakpoint automatically. To + stop the inferior, we flush all currently pending debug + events -- the thread list and the dll list are always + reported immediatelly without delay, then, we suspend all + threads and pretend we saw a trap at the current PC of the + main thread. + + Contrary to desktop Windows, Windows CE *does* report the dll + names on LOAD_DLL_DEBUG_EVENTs resulting from a + DebugActiveProcess call. This limits the way we can detect + if all the dlls have already been reported. If we get a real + debug event before leaving attaching, the worst that will + happen is the user will see a spurious breakpoint. */ + + current_event.dwDebugEventCode = 0; + if (!WaitForDebugEvent (¤t_event, 0)) + { + OUTMSG2(("no attach events left\n")); + fake_breakpoint_event (); + attaching = 0; + } + else + OUTMSG2(("got attach event\n")); + } + else +#endif + { + /* Keep the wait time low enough for confortable remote + interruption, but high enough so gdbserver doesn't become a + bottleneck. */ + if (!WaitForDebugEvent (¤t_event, 250)) + return 0; + } gotevent: @@ -1576,12 +1615,16 @@ get_child_debug_event (struct target_wai ourstatus->value.related_pid = current_event.dwThreadId; #ifdef _WIN32_WCE - /* Windows CE doesn't set the initial breakpoint automatically - like the desktop versions of Windows do. We add it explicitly - here. It will be removed as soon as it is hit. */ - set_breakpoint_at ((CORE_ADDR) (long) current_event.u - .CreateProcessInfo.lpStartAddress, - delete_breakpoint_at); + if (!attaching) + { + /* Windows CE doesn't set the initial breakpoint + automatically like the desktop versions of Windows do. + We add it explicitly here. It will be removed as soon as + it is hit. */ + set_breakpoint_at ((CORE_ADDR) (long) current_event.u + .CreateProcessInfo.lpStartAddress, + delete_breakpoint_at); + } #endif break; --------------040806000401020107030606--