From patchwork Tue Mar 22 23:35:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Feiner X-Patchwork-Id: 8646531 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 E2F2B9F294 for ; Tue, 22 Mar 2016 23:35:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 130172039D for ; Tue, 22 Mar 2016 23:35:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 34027203A4 for ; Tue, 22 Mar 2016 23:35:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751961AbcCVXfP (ORCPT ); Tue, 22 Mar 2016 19:35:15 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:34895 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750776AbcCVXfL (ORCPT ); Tue, 22 Mar 2016 19:35:11 -0400 Received: by mail-pf0-f176.google.com with SMTP id n5so330424687pfn.2 for ; Tue, 22 Mar 2016 16:35:11 -0700 (PDT) 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=E8IrWKT191r3zFCITb4CXYhgk9uk36LxyaCA6+pkjWE=; b=DRLO5uCH5A+LjqqQVw+YL1r8dvOszRJDQOLDcG3mVhZ6ajALaWaKGg4kc6gPgIhHfT 90wxF1maQfr0dztbZ0fjRcmRsWWMQv3gXHrAQYVPNlbQigHqY1B2bSxTHutecy7hUg4P QPKFMbu0K9e7UY6JyJp9N+7mRNJ+EpADIGrxnt8Yv0k/lTaaq6vFinHsvAhaMpRAWWXW zzz49zM3o69z5H1Cxa7HEdyJ2ek7PGYjZu99vjyMb4wv/v6RJZmM3ygmhLJeC7EZViuJ E2VaJyxE/1OSIVp7i2RCzF6cOQxVIHN+EV0w4jN3mvcY82THXAYxDFPbN7UdLI/Zgy0a NZlw== 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=E8IrWKT191r3zFCITb4CXYhgk9uk36LxyaCA6+pkjWE=; b=M3VOPJsUP2dXawUo85Yp3VrNWrrFMbFmn0y4fmY4/P8lYQFmDKT9I+EqhULJH/TGWK B6Xrd/vfBrBY1uwPuT2AZef+FCryTxhxhC4IVHbwbhZDVFLA3igb72XvJ6KBmi8nM1cs jCyVCemIGhBuAxxV/yaBF/PeSXQmHcrzkpcPIbdHzvr6bAloN7sxfsULvzcbQaZetbi/ CA8z9c29VpUO9fB4qZNzIT995+D1ewidK5nD3uRUvHfPtbN1iHlDVrssuzccYVxhBX3w b1b3WXxUK1lle4gs5aATP3wzaX8Cb5rbuqgfuCObcjiRzAnSaEpxyhPd5JBRlwNkYOS1 B4dA== X-Gm-Message-State: AD7BkJI3kg6vsdFS3T3TJqC0IxYjEeU5JloGYHz0cE3qNKlVyiywuIwOmEmq4Pcz86oPJNCu X-Received: by 10.66.193.202 with SMTP id hq10mr56722491pac.6.1458689710773; Tue, 22 Mar 2016 16:35:10 -0700 (PDT) Received: from localhost ([2620:0:1009:3:4fb:9875:8ad2:ab82]) by smtp.gmail.com with ESMTPSA id i9sm50770523pfi.95.2016.03.22.16.35.09 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 22 Mar 2016 16:35:10 -0700 (PDT) From: Peter Feiner To: drjones@redhat.com, pbonzini@redhat.com, kvm@vger.kernel.org Cc: pfeiner@google.com Subject: [PATCH kvm-unit-tests v7 2/5] x86: lib: debug dump on unhandled exceptions Date: Tue, 22 Mar 2016 16:35:03 -0700 Message-Id: X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 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,T_DKIM_INVALID,T_RP_MATCHES_RCVD, 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 Reviewed-By: Andrew Jones --- 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; \