From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sonic313-21.consmr.mail.ir2.yahoo.com (sonic313-21.consmr.mail.ir2.yahoo.com [77.238.179.188]) by sourceware.org (Postfix) with ESMTPS id EB0FE398B877 for ; Thu, 17 Sep 2020 18:04:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EB0FE398B877 X-YMail-OSG: LtFsP8wVM1khPO5Wa9lKTlbTDxmCgQKt0rizSvsXQ_EjafypkjRuE.mkiXLfSJP Ow9HTn2.SIbvKKAu_k8CPh4Hu8vqdGhiSsIlmFT_UBeRB2IsfaXxZ0falcSz_B7Ub3JS8msocoLI F7Lr7YLgxddblV40ngnWzyDNWWYXDk8.tzPwtQZIGIomnTWF66lYCFluzj41_qVgrrqIeBI3hatg BbZf12Rlm96rKanbnurXs8_yA2RJXD8SumPpeM8X._ogAISvNMT5QDMq_osepH2Em1SjQ7.kDhHk eJT.beT368V9Y1F.SRgka9La5th0fsqVeUkrJ_qwJZDCWlbuku7tKD8DP3_pTUk7PjbX.7BcD9OW 2iYEYOELDPTewb3pfLHjHZErz.GplcDFtZRIa5dh1MVy03UwJ2pd7Jw2n3NJPT4dorNYBWB9RECL 3obw9JzZEfjQ3R2cGFCx75PlYAzThjWNfTEI_b5DGHHkGz3yVs2m5NYbQxLYCbfPQelydjQjiLj_ gpeF8bJwPsezN1AOQ0eg7mcBOzD8ftwuU3Vi882erJQG65Mjk2FXjp_vSEs4KP1mSm_vb8Xh5kAT YdE3_PHxdsyhEhrzYLAIQEKz2lPupQ2pMSbwIZ4OxMzz2UYsRYQ2hWpFYdsUfG8BtfSz7jcJ7AP4 PrDy9oFdU48svIYLojovleF.Bkcr0O6B5ERnm6Cq.jGbshqCb1.bL7VPpSe219Epgz7ZGYZAbD_j wSHz2LaHt6A5HwWkRHxX_wDoV_0NedZau3G6Z4fQCE0oURHyjYjgbrZODWoxEkYlrpxejfUGaz31 cwyKOmn.43NBFF8g6tXX_mqVAVswH9W_Fu40NNbl.b8uaN8IsNVo7WO3zOk2SC5k9mz2WCGjZlEL .TtVdXa2H.tw33RCHGZsmzY9Zy4powQQ6MBI2orH9N_KavGdDJk8alw2wrWGvBXPEf4tmTHPyTSJ UaLnMHYhkgcp3Ayg.nVtT.hsfGdl9vRJ_quUEqmnvQPf0Oel3_tb5e7Vlsc_sw3M11ApCuuhGZ2F xs2JHc9jqxna4pBLmvO5_0WNUCR.qyTehKbYPPv3bsLIJrqfZnNGbh64OcWhij5DAZTtjNAcBycP YzeHlswImFV5ihA8gUPQEMSpyw6VNQgYJbJa.apEUn5jezJnEAQt0Ulg1RfzNrqRIhK9pvtDA6CJ 0pTAziYmtWqK14Kxp3ZjynesEU6.WaRQXU0E2ElLtTR6ISa45lz_SKZKgekWGvCstTgpZSta3KmQ HWDsDzAR8U3Ff1o_PBxp9kcpx5ToxRl7mjMWn9erFhDjqXYTWtKoW7Vt3E5F8UDCBClk8nSCzchO R_YnkgN6ICXlBjvcg3q2CZmjT9OOqE2.mo.IerAkOtgkSEwNJres8MjX8wwytxrfK0fkg3wV8BLh 6UP5d5Xh5FUBM7rqEAkSGuz1b.ApXvCMPbt4pxXeAGeEMltm9aQaDlg3pxA8ncy8.TbNmQer3JHs v2Ivfx_F4Hr7emTCXEXTvptxOMsaY9i2JJwauiZbLe7df.YDs6a723BADip9pRa1danR.gAFMdw- - Received: from sonic.gate.mail.ne1.yahoo.com by sonic313.consmr.mail.ir2.yahoo.com with HTTP; Thu, 17 Sep 2020 18:04:06 +0000 Received: by smtp414.mail.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 1d54d9f27471fd42b6b913e5ed74ab66; Thu, 17 Sep 2020 18:04:06 +0000 (UTC) From: Hannes Domani To: gdb-patches@sourceware.org Subject: [PATCH] Fix ctrl-c when debugging WOW64 processes Date: Thu, 17 Sep 2020 20:03:37 +0200 Message-Id: <20200917180337.1984-1-ssbssa@yahoo.de> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Antivirus: Avast (VPS 200917-4, 09/17/2020), Outbound message X-Antivirus-Status: Clean References: <20200917180337.1984-1-ssbssa.ref@yahoo.de> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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: Thu, 17 Sep 2020 18:04:09 -0000 DebugBreakProcess starts a new thread in the target process with the entry point DbgUiRemoteBreakin, where an int3 triggers a breakpoint exception for gdb. But this uses DbgUiRemoteBreakin of the 64bit ntdll.dll even for WOW64 processes. It stops in 64bit code, Wow64GetThreadContext reports a wrong pc without the int3, and gdb lets the target process continue. So this uses DbgUiRemoteBreakin of the 32bit ntdll.dll as the thread entry point for WOW64 processes instead. gdb/ChangeLog: 2020-09-17 Hannes Domani * windows-nat.c (ctrl_c_handler): Use 32bit DbgUiRemoteBreakin for WOW64 processes. --- gdb/windows-nat.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 188a920cbb..284c529b9c 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -71,6 +71,7 @@ #include "gdbsupport/pathstuff.h" #include "gdbsupport/gdb_wait.h" #include "nat/windows-nat.h" +#include "gdbsupport/symbol.h" using namespace windows_nat; @@ -235,6 +236,7 @@ static int saw_create; static int open_process_used = 0; #ifdef __x86_64__ static bool wow64_process = false; +static void *wow64_dbgbreak; #endif /* User options. */ @@ -1522,9 +1524,36 @@ ctrl_c_handler (DWORD event_type) if (!new_console && !attach_flag) return TRUE; - if (!DebugBreakProcess (current_process_handle)) - warning (_("Could not interrupt program. " - "Press Ctrl-c in the program console.")); +#ifdef __x86_64__ + if (wow64_process) + { + /* Call DbgUiRemoteBreakin of the 32bit ntdll.dll in the target process. + DebugBreakProcess would call the one of the 64bit ntdll.dll, which + can't be correctly handled by gdb. */ + if (!wow64_dbgbreak) + { + CORE_ADDR addr; + if (!find_minimal_symbol_address ("ntdll!DbgUiRemoteBreakin", + &addr, 0)) + wow64_dbgbreak = (void *) addr; + } + + if (wow64_dbgbreak) + { + HANDLE thread = CreateRemoteThread (current_process_handle, NULL, + 0, (LPTHREAD_START_ROUTINE) + wow64_dbgbreak, NULL, 0, NULL); + if (thread) + CloseHandle (thread); + } + } + else +#endif + { + if (!DebugBreakProcess (current_process_handle)) + warning (_("Could not interrupt program. " + "Press Ctrl-c in the program console.")); + } /* Return true to tell that Ctrl-C has been handled. */ return TRUE; -- 2.27.0