From owner-svn-src-head@freebsd.org Tue Mar 14 16:06:58 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CA0E4D0CC77; Tue, 14 Mar 2017 16:06:58 +0000 (UTC) (envelope-from fabient@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8ABA6F9C; Tue, 14 Mar 2017 16:06:58 +0000 (UTC) (envelope-from fabient@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2EG6vaH022436; Tue, 14 Mar 2017 16:06:57 GMT (envelope-from fabient@FreeBSD.org) Received: (from fabient@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2EG6vDf022435; Tue, 14 Mar 2017 16:06:57 GMT (envelope-from fabient@FreeBSD.org) Message-Id: <201703141606.v2EG6vDf022435@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: fabient set sender to fabient@FreeBSD.org using -f From: Fabien Thomas Date: Tue, 14 Mar 2017 16:06:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r315270 - in head/sys: arm/include dev/hwpmc X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Mar 2017 16:06:58 -0000 Author: fabient Date: Tue Mar 14 16:06:57 2017 New Revision: 315270 URL: https://svnweb.freebsd.org/changeset/base/315270 Log: Fix arm stack frame walking support: - Adjust stack offset for Clang - Correctly fill registers for fake stack frame (soft PMC) MFC after: 1 week Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D7396 Modified: head/sys/arm/include/pmc_mdep.h head/sys/dev/hwpmc/hwpmc_arm.c Modified: head/sys/arm/include/pmc_mdep.h ============================================================================== --- head/sys/arm/include/pmc_mdep.h Tue Mar 14 16:01:36 2017 (r315269) +++ head/sys/arm/include/pmc_mdep.h Tue Mar 14 16:06:57 2017 (r315270) @@ -70,7 +70,9 @@ union pmc_md_pmc { /* Build a fake kernel trapframe from current instruction pointer. */ #define PMC_FAKE_TRAPFRAME(TF) \ do { \ + (TF)->tf_spsr = PSR_SVC32_MODE; \ __asm __volatile("mov %0, pc" : "=r" ((TF)->tf_pc)); \ + __asm __volatile("mov %0, r11" : "=r" ((TF)->tf_r11)); \ } while (0) /* Modified: head/sys/dev/hwpmc/hwpmc_arm.c ============================================================================== --- head/sys/dev/hwpmc/hwpmc_arm.c Tue Mar 14 16:01:36 2017 (r315269) +++ head/sys/dev/hwpmc/hwpmc_arm.c Tue Mar 14 16:06:57 2017 (r315270) @@ -42,6 +42,17 @@ __FBSDID("$FreeBSD$"); #include #include +/* XXX: Userland code compiled with gcc will need an heuristic + * to be correctly detected. + */ +#ifdef __clang__ +#define PC_OFF 1 +#define FP_OFF 0 +#else +#define PC_OFF -1 +#define FP_OFF -3 +#endif + struct pmc_mdep * pmc_md_initialize() { @@ -100,7 +111,7 @@ pmc_save_kernel_callchain(uintptr_t *cc, for (count = 1; count < maxsamples; count++) { /* Use saved lr as pc. */ - r = fp - sizeof(uintptr_t); + r = fp + PC_OFF * sizeof(uintptr_t); if (!PMC_IN_KERNEL_STACK(r, stackstart, stackend)) break; pc = *(uintptr_t *)r; @@ -110,7 +121,7 @@ pmc_save_kernel_callchain(uintptr_t *cc, *cc++ = pc; /* Switch to next frame up */ - r = fp - 3 * sizeof(uintptr_t); + r = fp + FP_OFF * sizeof(uintptr_t); if (!PMC_IN_KERNEL_STACK(r, stackstart, stackend)) break; fp = *(uintptr_t *)r; @@ -147,7 +158,7 @@ pmc_save_user_callchain(uintptr_t *cc, i for (count = 1; count < maxsamples; count++) { /* Use saved lr as pc. */ - r = fp - sizeof(uintptr_t); + r = fp + PC_OFF * sizeof(uintptr_t); if (copyin((void *)r, &pc, sizeof(pc)) != 0) break; if (!PMC_IN_USERSPACE(pc)) @@ -157,7 +168,7 @@ pmc_save_user_callchain(uintptr_t *cc, i /* Switch to next frame up */ oldfp = fp; - r = fp - 3 * sizeof(uintptr_t); + r = fp + FP_OFF * sizeof(uintptr_t); if (copyin((void *)r, &fp, sizeof(fp)) != 0) break; if (fp < oldfp || !PMC_IN_USERSPACE(fp))