From patchwork Fri Mar 4 19:33:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Feiner X-Patchwork-Id: 8507151 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 795109F38C for ; Fri, 4 Mar 2016 19:34:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 86DFD201F2 for ; Fri, 4 Mar 2016 19:34:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 95F5920254 for ; Fri, 4 Mar 2016 19:34:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760008AbcCDTeX (ORCPT ); Fri, 4 Mar 2016 14:34:23 -0500 Received: from mail-pf0-f172.google.com ([209.85.192.172]:36414 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759976AbcCDTeV (ORCPT ); Fri, 4 Mar 2016 14:34:21 -0500 Received: by mail-pf0-f172.google.com with SMTP id 63so40126302pfe.3 for ; Fri, 04 Mar 2016 11:34:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=V06D36z6HRA/vnkQ8gTMIEcTr9abd12cL3DJWfcrw10=; b=Z+Zbyv1wtPKPssBPUSJfTY9YFqtPbe5fJiOy5f+otWbxVhk/J5QLK9PchBavuBq/+D 0+TB4ao4L/UNw71Gn9/5Wzh4XxDmjFoeWUOMra/I5auhoOzNqifrEP6y2IIqV3HpDq9g fofcK1qYDLeJTJZeJc0QeXG9Fck3PIB7TVp22L3f1ognlYtfbuOvxy6EaBogdeR7x6HY PpC/O6sh1tAbAwMm7enn4GXoyYkL8fUDB7tLODYAMgs5QgZVuhgTmQIfRMHhoyCkwE6C 7ECnukPXBXsbsE7nKgTtJth0uqSa0XAtGic3ZKqIXKacNrf8usYgGcU7p6+yERlE4vb6 HdIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=V06D36z6HRA/vnkQ8gTMIEcTr9abd12cL3DJWfcrw10=; b=EUJghtpyxSPBjIMmBaEXW0YUwL+MisExXoo+eMsLwg1Rpg9IvnfI0VtWt/6xHTwrPJ 9pwg6m0zaq+WfBBBK3rQXUCP0Yqk+xHFiAIEjSzxX2/0RYnE2CT/XnMIKdhSsovtrSC/ fIXfcHP5/YTZ8Qk7MYlw+GbdHaEtBOpKaT54hi03P+q4N5eLxBHcj/0lmSaMRb12NxkN 6blnYNrutJ2tQBQpXFkpvdWiDbXDIvDIg4GsXliYpyoDvOOYnkib/1gOwtgfztw1FjrW q5PeZRT4o6UCzU81wrGxjrzyNbinn/D7Vvk8KwuHSdk+zkOoM/RosmrVitjd3yfxBA1y 5Fqg== X-Gm-Message-State: AD7BkJKFV2DhLhXX/w/kstmP7s2v8NN0g+/yGkgukT4WFuZfJvXU+qENK6abmmZDeHfWci3Y X-Received: by 10.98.0.71 with SMTP id 68mr14609672pfa.156.1457120060201; Fri, 04 Mar 2016 11:34:20 -0800 (PST) Received: from localhost ([2620:0:1009:3:90d6:d6fe:49e8:86b0]) by smtp.gmail.com with ESMTPSA id p9sm7318240pfa.11.2016.03.04.11.34.18 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 04 Mar 2016 11:34:19 -0800 (PST) From: Peter Feiner To: kvm@vger.kernel.org, drjones@redhat.com, pbonzini@redhat.com Cc: Peter Feiner Subject: [PATCH kvm-unit-tests v4 2/5] x86: lib: debug dump on unhandled exceptions Date: Fri, 4 Mar 2016 11:33:58 -0800 Message-Id: <79a2157c4a66929f04c61a5ffcd6a1f21f9cd979.1457119891.git.pfeiner@google.com> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: References: In-Reply-To: References: Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Prints the stack trace and registers. Signed-off-by: Peter Feiner --- lib/x86/desc.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/lib/x86/desc.c b/lib/x86/desc.c index 16cbba5..75765ef 100644 --- a/lib/x86/desc.c +++ b/lib/x86/desc.c @@ -38,6 +38,67 @@ struct ex_record { extern struct ex_record exception_table_start, exception_table_end; +static const char* exception_mnemonic(int vector) +{ + switch(vector) { + case 0: return "#DE"; + case 1: return "#DB"; + case 2: return "#NMI"; + case 3: return "#BP"; + case 4: return "#OF"; + case 5: return "#BR"; + case 6: return "#UD"; + case 7: return "#NM"; + case 8: return "#DF"; + case 10: return "#TS"; + case 11: return "#NP"; + case 12: return "#SS"; + case 13: return "#GP"; + case 14: return "#PF"; + case 16: return "#MF"; + case 17: return "#AC"; + case 18: return "#MC"; + case 19: return "#XM"; + default: return "#??"; + } +} + +static void unhandled_exception(struct ex_regs *regs, bool cpu) +{ + printf("Unhandled %sexception %ld %s at ip %016lx\n", + cpu ? "cpu " : "", regs->vector, + exception_mnemonic(regs->vector), regs->rip); + if (regs->vector == 14) + printf("PF at 0x%lx addr 0x%lx\n", regs->rip, read_cr2()); + + printf("error_code=%04lx rflags=%08lx cs=%08lx\n" + "rax=%016lx rcx=%016lx rdx=%016lx rbx=%016lx\n" + "rbp=%016lx rsi=%016lx rdi=%016lx\n" +#ifdef __x86_64__ + " r8=%016lx r9=%016lx r10=%016lx r11=%016lx\n" + "r12=%016lx r13=%016lx r14=%016lx r15=%016lx\n" +#endif + "cr0=%016lx cr2=%016lx cr3=%016lx cr4=%016lx\n" +#ifdef __x86_64__ + "cr8=%016lx\n" +#endif + , + regs->error_code, regs->rflags, regs->cs, + regs->rax, regs->rcx, regs->rdx, regs->rbx, + regs->rbp, regs->rsi, regs->rdi, +#ifdef __x86_64__ + regs->r8, regs->r9, regs->r10, regs->r11, + regs->r12, regs->r13, regs->r14, regs->r15, +#endif + read_cr0(), read_cr2(), read_cr3(), read_cr4() +#ifdef __x86_64__ + , read_cr8() +#endif + ); + dump_frame_stack((void*) regs->rip, (void*) regs->rbp); + exit(7); +} + static void check_exception_table(struct ex_regs *regs) { struct ex_record *ex; @@ -53,8 +114,7 @@ static void check_exception_table(struct ex_regs *regs) return; } } - printf("unhandled exception %lu\n", regs->vector); - abort(); + unhandled_exception(regs, false); } static void (*exception_handlers[32])(struct ex_regs *regs); @@ -75,10 +135,7 @@ void do_handle_exception(struct ex_regs *regs) exception_handlers[regs->vector](regs); return; } - printf("unhandled cpu exception %lu\n", regs->vector); - if (regs->vector == 14) - printf("PF at 0x%lx addr 0x%lx\n", regs->rip, read_cr2()); - abort(); + unhandled_exception(regs, true); } #define EX(NAME, N) extern char NAME##_fault; \