From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH] [RFC][PATCH] kvm: kvmtrace: kvmtrace_format for supporting big_endian Date: Tue, 20 May 2008 19:22:44 +0300 Message-ID: <4832FAD4.2040908@qumranet.com> References: <08DF4D958216244799FC84F3514D70F0015B1B58@pdsmsx415.ccr.corp.intel.com> <200805141637.03442.hollisb@us.ibm.com> <08DF4D958216244799FC84F3514D70F00164BF05@pdsmsx415.ccr.corp.intel.com> <08DF4D958216244799FC84F3514D70F00164BF20@pdsmsx415.ccr.corp.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: "Tan, Li" Return-path: Received: from bzq-179-150-194.static.bezeqint.net ([212.179.150.194]:40529 "EHLO il.qumranet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752039AbYETQWq (ORCPT ); Tue, 20 May 2008 12:22:46 -0400 In-Reply-To: <08DF4D958216244799FC84F3514D70F00164BF20@pdsmsx415.ccr.corp.intel.com> Sender: kvm-owner@vger.kernel.org List-ID: Tan, Li wrote: > From 9d39264bdfb00a1a717074e486a948a578547c50 Mon Sep 17 00:00:00 2001 > From: Tan Li > Date: Tue, 20 May 2008 09:14:41 +0800 > Subject: [PATCH] [RFC][PATCH] kvm: kvmtrace: kvmtrace_format for > supporting big_endian > > Currently kvmtrace is not portable, and prevent from copying a trace > file from big-endian target to little-endian workstation for analysis. > > In the patch, kvmtrace_format reads and checks the magic number from > trace log. if needed, then change bytes order of all fields in records > followed. > > > +def reverse_bytes(origin, bytes_cnt): > + i = 0 > + rtn = 0L > + while i < bytes_cnt: > + i = i + 1 > + b = origin & 0xff > + origin = origin >> 8 > + rtn = (rtn << 8) + b > + return rtn > + > +def reverse_int(origin): > + return reverse_bytes(origin, 4) > + > +def reverse_qword(origin): > + return reverse_bytes(origin, 8) > + > def sighand(x,y): > global interrupted > interrupted = 1 > @@ -100,18 +116,40 @@ D2REC = "II" > D3REC = "III" > D4REC = "IIII" > D5REC = "IIIII" > +KMAGIC = "I" > The python struct module supports reading big-endian and little-endian data. So you can simply switch the format strings if you have the wrong endianness. -- error compiling committee.c: too many arguments to function