From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 65480 invoked by alias); 31 Oct 2016 23:24:23 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 65430 invoked by uid 89); 31 Oct 2016 23:24:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=BAYES_00,KAM_ASCII_DIVIDERS,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=jonas-devlists@watlock.be, jonasdevlistswatlockbe, H*F:D*apple.com, (unknown) X-HELO: mail-in6.apple.com Received: from mail-out6.apple.com (HELO mail-in6.apple.com) (17.151.62.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 31 Oct 2016 23:24:00 +0000 Received: from relay3.apple.com (relay3.apple.com [17.128.113.83]) by mail-in6.apple.com (Apple Secure Mail Relay) with SMTP id E3.3F.16908.E82D7185; Mon, 31 Oct 2016 16:23:58 -0700 (PDT) Received: from moleja3.apple.com (moleja3.apple.com [17.212.144.40]) (using TLS with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by relay3.apple.com (Apple SCV relay) with SMTP id 74.C2.13773.E82D7185; Mon, 31 Oct 2016 16:23:58 -0700 (PDT) From: Jason Molenda Message-Id: <1116E788-F7A1-4BA4-AD07-CB5BBCCC5B7F@apple.com> Content-Type: multipart/mixed; boundary="Apple-Mail=_F14A57BC-2785-43D9-AED3-BA1C3952ED4B" Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3253\)) Subject: Re: gdb on macOS 10.12 "Sierra" Date: Mon, 31 Oct 2016 23:24:00 -0000 In-Reply-To: <581730F0.6000106@watlock.be> Cc: Tristan Gingold , gdb@sourceware.org, "Tedeschi, Walfred" To: Jonas Maebe References: <20161001140850.Horde.5Pxfey2wqn5X76dSpncV3uA@mail.elis.ugent.be> <581730F0.6000106@watlock.be> X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg00062.txt.bz2 --Apple-Mail=_F14A57BC-2785-43D9-AED3-BA1C3952ED4B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Content-length: 271 Hi Jonas, there was a change in macOS 10.12.1 that may be impacting gdb. A= fter an exec, you need to refresh the task port that gdb uses in its mach c= alls. You can see the lldb change here: http://llvm.org/viewvc/llvm-project?view=3Drevision&revision=3D282632 or --Apple-Mail=_F14A57BC-2785-43D9-AED3-BA1C3952ED4B Content-Disposition: attachment; filename=patch.txt Content-Type: text/plain; x-unix-mode=0644; name="patch.txt" Content-Transfer-Encoding: quoted-printable Content-length: 4319 ------------------------------------------------------------------------ r282632 | gclayton | 2016-09-28 14:07:34 -0700 (Wed, 28 Sep 2016) | 4 lines Add the ability for the task port to change when a process execs. ------------------------------------------------------------------------ Index: source/MacOSX/MachException.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- source/MacOSX/MachException.cpp (revision 282631) +++ source/MacOSX/MachException.cpp (revision 282632) @@ -106,15 +106,30 @@ catch_mach_exception_raise(mach_port_t exc_port, m (uint64_t)(exc_data_count > 0 ? exc_data[0] : 0xBADDBAD= D), (uint64_t)(exc_data_count > 1 ? exc_data[1] : 0xBADDBAD= D)); } + g_message->exc_type =3D 0; + g_message->exc_data.clear(); =20 if (task_port =3D=3D g_message->task_port) { g_message->task_port =3D task_port; g_message->thread_port =3D thread_port; g_message->exc_type =3D exc_type; - g_message->exc_data.resize(exc_data_count); - ::memcpy(&g_message->exc_data[0], exc_data, - g_message->exc_data.size() * sizeof(mach_exception_data_type_= t)); + for (mach_msg_type_number_t i=3D0; iexc_data.push_back(exc_data[i]); return KERN_SUCCESS; + } else if (!MachTask::IsValid(g_message->task_port)) { + // Our original exception port isn't valid anymore check for a SIGTRAP + if (exc_type =3D=3D EXC_SOFTWARE && exc_data_count =3D=3D 2 && + exc_data[0] =3D=3D EXC_SOFT_SIGNAL && exc_data[1] =3D=3D SIGTRAP) { + // We got a SIGTRAP which indicates we might have exec'ed and possib= ly + // lost our old task port during the exec, so we just need to switch= over + // to using this new task port + g_message->task_port =3D task_port; + g_message->thread_port =3D thread_port; + g_message->exc_type =3D exc_type; + for (mach_msg_type_number_t i=3D0; iexc_data.push_back(exc_data[i]); + return KERN_SUCCESS; + } } return KERN_FAILURE; } Index: source/MacOSX/MachTask.mm =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- source/MacOSX/MachTask.mm (revision 282631) +++ source/MacOSX/MachTask.mm (revision 282632) @@ -867,6 +867,16 @@ void *MachTask::ExceptionThread(void *arg) { // TODO: notify of error? } else { if (exception_message.CatchExceptionRaise(task)) { + if (exception_message.state.task_port !=3D task) { + if (exception_message.state.IsValid()) { + // We exec'ed and our task port changed on us. + DNBLogThreadedIf(LOG_EXCEPTIONS, + "task port changed from 0x%4.4x to 0x%4.4x", + task, exception_message.state.task_port); + task =3D exception_message.state.task_port; + mach_task->TaskPortChanged(exception_message.state.task_port); + } + } ++num_exceptions_received; mach_proc->ExceptionMessageReceived(exception_message); } @@ -984,3 +994,8 @@ nub_bool_t MachTask::DeallocateMemory(nub_addr_t a } =20 nub_size_t MachTask::PageSize() { return m_vm_memory.PageSize(m_task); } + +void MachTask::TaskPortChanged(task_t task) +{ + m_task =3D task; +} Index: source/MacOSX/MachTask.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- source/MacOSX/MachTask.h (revision 282631) +++ source/MacOSX/MachTask.h (revision 282632) @@ -82,6 +82,7 @@ class MachTask { bool IsValid() const; static bool IsValid(task_t task); static void *ExceptionThread(void *arg); + void TaskPortChanged(task_t task); task_t TaskPort() const { return m_task; } task_t TaskPortForProcessID(DNBError &err, bool force =3D false); static task_t TaskPortForProcessID(pid_t pid, DNBError &err, --Apple-Mail=_F14A57BC-2785-43D9-AED3-BA1C3952ED4B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Content-length: 1483 I skimmed this email thread and someone said that disabling launch-with-she= ll worked around the issue. That would be in line with this OS change. Jason > On Oct 31, 2016, at 4:54 AM, Jonas Maebe wrot= e: >=20 > Tristan Gingold wrote: >>> On 01 Oct 2016, at 14:08, Jonas Maebe wrote: >>>=20 >>> Has anyone succeeded yet in getting gdb to work on macOS 10.12? Reporte= dly, it works when you disable SIP (which is understandable, given https://= developer.apple.com/library/content/documentation/Security/Conceptual/Syste= m_Integrity_Protection_Guide/RuntimeProtections/RuntimeProtections.html ), = but plain code signing no longer seems to cut it. >>=20 >> No, I haven't tried yet. Did you investigate if lldb has updated its bu= ild instructions ? >=20 > I finally got time to look into this. lldb's codesigning instructions > are at > https://llvm.org/svn/llvm-project/lldb/trunk/docs/code-signing.txt . > They have not been updated recently, but they do differ from gdb's. > However, the result is exactly the same: SIG113. >=20 > I've also asked on the darwin-dev@apple list, but did not get any > replies there. >=20 > ... >=20 > I've now tried building lldb, and regardless of whether I use the GDB or > LLDB-style codesigning certificate to sign debugserver (lldb itself does > not need codesigning), it works. So it seems like the problem is not > necessarily related to codesigning per se. >=20 >=20 > Jonas --Apple-Mail=_F14A57BC-2785-43D9-AED3-BA1C3952ED4B--