From patchwork Thu Mar 3 01:09:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Feiner X-Patchwork-Id: 8487081 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 EB03C9F372 for ; Thu, 3 Mar 2016 01:10:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 29A45201FE for ; Thu, 3 Mar 2016 01:10:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 388F82021F for ; Thu, 3 Mar 2016 01:10:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755152AbcCCBKB (ORCPT ); Wed, 2 Mar 2016 20:10:01 -0500 Received: from mail-pa0-f44.google.com ([209.85.220.44]:32852 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754735AbcCCBJ7 (ORCPT ); Wed, 2 Mar 2016 20:09:59 -0500 Received: by mail-pa0-f44.google.com with SMTP id fl4so4211176pad.0 for ; Wed, 02 Mar 2016 17:09:59 -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; bh=BjmwgBCRs/ayfH8Qu/qEwg7umGr2uRncsPLPYwPSkxg=; b=hMiUhQmMOZkl6Uptms9fDUIKbOyDtmbVhdrJCta1E04Lgw8Zh3nLgK7LTRS7C04Dca U1t93tXkO8VDAjt2TqlsC1qMhLoFxC+gcxVG7kNGdzW6lNhqXfjdjDJIfq6s8ccKtPJ0 iRFrZ8ydVY4/T4XpX7PlV4HwyjR3WXKfSGVLJ2srlxOUS52o7O5oP6aYwbnlp8gXIidD ba3V2K0SzTJraLyWNoLcJs+Ye1+YVBS5n3jTA21gXrH9IhJ+GM8PnoIRErEVtON/i6MR btWa1PTHJMUv2ZNH12o5R0ZBf1c1k+IerI9Mqqt62b8T6qtizF4KR9QH/sqGdDfNsmzm Wluw== 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; bh=BjmwgBCRs/ayfH8Qu/qEwg7umGr2uRncsPLPYwPSkxg=; b=O1JlJVQX6roXk7L8zPPrNt3TQnmn5aZpftOjjq08xkVnHYQChQiur6rowQ6t1dV37X bUAJ2lpxN8NNwdvtqJO6bDzW1F+xzVmZQK15ulvj+6jJuJ+07oQdwEN85vgUBodyPzx4 VU0r8f7Wn4+9wEv82fzL4bATsOLAick0opqfxs4qhTt8maXktoQg7Bv/T1v1GUjktjqr DPQLfkJeXXqs6t7VOYzfmrNwPuSQT4UBhcEwEwrxCJuFy3ts82qjOKrLq7yBd2uHY5zR sAA05fmrDZ3abnMEmZGlxDuKIqyMXyJSiVmZ5siCDAZL96/U0I49N0QpOVHcwm1l8Rbn 81EQ== X-Gm-Message-State: AD7BkJKiVJCPW7+/Rfovz7xKs+VKY9TwZR4dk+iEIKBWRLnJFrnU9rJsBTDPp5SWVSb64ztF X-Received: by 10.66.139.199 with SMTP id ra7mr43067090pab.74.1456967398869; Wed, 02 Mar 2016 17:09:58 -0800 (PST) Received: from localhost ([2620:0:1009:3:10b2:1b3a:febc:1b15]) by smtp.gmail.com with ESMTPSA id r87sm55694482pfa.61.2016.03.02.17.09.56 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 02 Mar 2016 17:09:57 -0800 (PST) From: Peter Feiner To: kvm@vger.kernel.org, drjones@redhat.com, pbonzini@redhat.com Cc: pfeiner@google.com Subject: [kvm-unit-tests v2 6/8] x86: lib: debug dump on unhandled exceptions Date: Wed, 2 Mar 2016 17:09:36 -0800 Message-Id: <1456967378-6367-7-git-send-email-pfeiner@google.com> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: <1456967378-6367-1-git-send-email-pfeiner@google.com> References: <1456867658-10937-1-git-send-email-pfeiner@google.com> <1456967378-6367-1-git-send-email-pfeiner@google.com> 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=unavailable 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 1a80c01..59c34b7 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_stack(regs->rip, 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 %d\n", regs->vector); - exit(7); + 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 %d\n", regs->vector); - if (regs->vector == 14) - printf("PF at %p addr %p\n", regs->rip, read_cr2()); - exit(7); + unhandled_exception(regs, true); } #define EX(NAME, N) extern char NAME##_fault; \