From patchwork Mon Mar 7 17:46:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Feiner X-Patchwork-Id: 8521441 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C251EC0553 for ; Mon, 7 Mar 2016 17:47:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BF4C9202A1 for ; Mon, 7 Mar 2016 17:47:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E5F6202D1 for ; Mon, 7 Mar 2016 17:47:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753455AbcCGRrI (ORCPT ); Mon, 7 Mar 2016 12:47:08 -0500 Received: from mail-pa0-f50.google.com ([209.85.220.50]:34571 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753231AbcCGRrD (ORCPT ); Mon, 7 Mar 2016 12:47:03 -0500 Received: by mail-pa0-f50.google.com with SMTP id fy10so81944591pac.1 for ; Mon, 07 Mar 2016 09:47:03 -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=Y97eindHx4J0dNTZiKGsZP3BFpspOAJuL0pwp9lLQe8Hv+tJxi6N5a13ktWiIcGFDU 1MNM/a2okzMZI5buXf0PET1l9ENORR63Lc6m4ZJJylhmS6BZPjqbe0UpqVK5zHQYQp8v x1MP0tzr5P6BbxvErLPDulJHTsMtKajOfcYF2bXfBiJrTmcyjvkxlSE5CneH6qGdgVvL nHLJdyG5qRtoBhuBnXoYoi7/YB3CGFjaZ7CwppsNFhxm0gLeNfKtIQpsYBekzleCdEj5 ORsfY2051PUNOUDf+rwkRTygzGffqwN3G0gxpn4ty0BKXhmdiqbtRDbfR0T93jRW8G/b GYOg== 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=mIR7zBYjFjLOt89QoTy+jEGt6TcuG8vNZDDVbdO48HSw3htSQXXX8T/ddOAsxHHsjW J1qKkjNGxOLmFQUD9SgR2kz1Guy5Nge7UW+yj0uqFRHCIGeyBVkpf93bYyxmGYd2N/Zu eGZJKHFxdBkzV6u9SzGIDarS3Te6G4KzJOVvRKdm1A5tafkjfKzU2rBRckTvzY5b8c9Q WVCp0Y9aqGmSR/sOdGwQwRfmLAKMjTKeQzCAo9JkVvp+PFNo0dlBcSKPKnFNVh9MjWwz JR7Ft5N4DQRrIVuXF2X3Y/WH4F2NtUzUw65cR49sVxPiTWHWf0fMOk9aISQZvrXDfDoX SqfQ== X-Gm-Message-State: AD7BkJLgP6zekSNrd97dwjm0QisuD2ylarPk5DdZzIu6sjhBLC29bDUqvxVDnLHFyqdPA5FK X-Received: by 10.66.55.102 with SMTP id r6mr34908635pap.67.1457372822722; Mon, 07 Mar 2016 09:47:02 -0800 (PST) Received: from localhost ([2620:0:1009:3:d845:64d7:b824:3f90]) by smtp.gmail.com with ESMTPSA id p5sm25433791pfi.94.2016.03.07.09.47.02 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 07 Mar 2016 09:47:02 -0800 (PST) From: Peter Feiner To: kvm@vger.kernel.org, drjones@redhat.com, pbonzini@redhat.com Cc: Peter Feiner Subject: [PATCH kvm-unit-tests v5 2/5] x86: lib: debug dump on unhandled exceptions Date: Mon, 7 Mar 2016 09:46:54 -0800 Message-Id: <79a2157c4a66929f04c61a5ffcd6a1f21f9cd979.1457372594.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; \