From patchwork Tue Mar 1 21:27: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: 8470641 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 8BE0FC0553 for ; Tue, 1 Mar 2016 21:27:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9B7122034E for ; Tue, 1 Mar 2016 21:27:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AFA352034C for ; Tue, 1 Mar 2016 21:27:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752698AbcCAV1t (ORCPT ); Tue, 1 Mar 2016 16:27:49 -0500 Received: from mail-pf0-f173.google.com ([209.85.192.173]:35434 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752730AbcCAV1q (ORCPT ); Tue, 1 Mar 2016 16:27:46 -0500 Received: by mail-pf0-f173.google.com with SMTP id w128so75217036pfb.2 for ; Tue, 01 Mar 2016 13:27:46 -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=ViyTeiW2REXEK/lwXzhnaytl2k1NGO0votGZiFaLlDWflJsdShuMqfQoDCLsVqA5sP HUO+Vi+AWsrz17GFEvEPrS+3LHAq9xZ3TShrnjltJzC5sdrAZoIIwmYh1aH4qZ5c5pgt j9718UBqL+UyRp6q73eZi+p1AESK0cXfSmuxsBNSBwGspLlnU0MLsXZBuvmq4u1ketbJ 99SWOoHY0QfQSOE+iFyYMLzZ0uaLivd+LfiCOl9mnSgr9vegUttj/dn4KWzhXjO5vsac GNGnlU/HyeRwpWdJ+mx04NGAyz+BkGkzVlTuL2TjD3g5R8W7EQoRaDLgrHKkfY4eYXeo qf4w== 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=CrXRvOE27D52l405tgsLtY6LsagLfahYVXIXFDoCwrTjmtLR5IWJ2+vJxlap7L7cGG alUDkZhNeS01VcOX3bCz1TRiEB70izNaWOArwe3NYsL927KYPeoM3/rfNjsan9UpGJS6 cWdsQt5rnBEFaA4WSzYjq8JfJVzcQw2iN6eeR3X5lxNBFP88W0NGJLDEoqeIzKegkSVd e4hj2cfNGW9XOaZTb5KUIJSijqKhfP6sdSgDHX1xMVvztgJwN2bI5ljNqBcKE+7tWLqo MtVM0P0uqxpCh4rDXcPEZx0wS9FRgIMTqJCm1RSLmlhN6cBY50Ndwm2gIWanQNw75mIm ESPQ== X-Gm-Message-State: AD7BkJLLvu7nA37+KfLAnFsCACQtPzrKoEKo+CXQkUBjcAmdHaHZmmKzSxibhvhWWNK2uFpJ X-Received: by 10.98.14.68 with SMTP id w65mr33587909pfi.144.1456867665991; Tue, 01 Mar 2016 13:27:45 -0800 (PST) Received: from localhost ([2620:0:1009:3:b1e9:1d95:1ce5:e70c]) by smtp.gmail.com with ESMTPSA id k14sm47694475pfj.0.2016.03.01.13.27.45 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 01 Mar 2016 13:27:45 -0800 (PST) From: Peter Feiner To: kvm@vger.kernel.org, drjones@redhat.com, pbonzini@redhat.com Cc: pfeiner@google.com Subject: [kvm-unit-tests 3/5] x86: lib: debug dump on unhandled exceptions Date: Tue, 1 Mar 2016 13:27:36 -0800 Message-Id: <1456867658-10937-4-git-send-email-pfeiner@google.com> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: <1456867658-10937-1-git-send-email-pfeiner@google.com> References: <1456867658-10937-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; \