Received: from eggs.gnu.org ([2001:4830:134:3::10]:53821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4sU5-00042V-LJ for qemu-devel@nongnu.org; Tue, 16 Jun 2015 11:09:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z4sU4-00047O-IQ for qemu-devel@nongnu.org; Tue, 16 Jun 2015 11:09:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40987) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4sU3-00047A-P9 for qemu-devel@nongnu.org; Tue, 16 Jun 2015 11:09:04 -0400 From: Markus Armbruster References: Date: Tue, 16 Jun 2015 17:09:00 +0200 In-Reply-To: (Peter Crosthwaite's message of "Sun, 24 May 2015 14:20:40 -0700") Message-ID: <87lhfjk7w3.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 1/2] monitor: Split mon_get_cpu fn to remove ENV_GET_CPU List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Crosthwaite Cc: rth@twiddle.net, lcapitulino@redhat.com, qemu-devel@nongnu.org, afaerber@suse.de, Peter Crosthwaite Peter Crosthwaite writes: > The monitor currently has one helper, mon_get_cpu() which will return > an env pointer. The target specific users of this API want an env, but > all the target agnostic users really just want the cpu pointer. These > users then need to use the target-specifically defined ENV_GET_CPU to > navigate back up to the CPU from the ENV. Split the API for the two > uses cases to remove all need for ENV_GET_CPU. > > Reviewed-by: Richard Henderson > Reviewed-by: Andreas F=C3=A4rber > Signed-off-by: Peter Crosthwaite > --- > Changed since v1: > s/mon_get_env/mon_get_cpu_env (Andreas review) > Avoid C99 declaration (RH review) > --- > monitor.c | 65 ++++++++++++++++++++++++++++-----------------------------= ------ > 1 file changed, 29 insertions(+), 36 deletions(-) > [...] > @@ -1208,16 +1203,14 @@ static void monitor_printc(Monitor *mon, int c) > static void memory_dump(Monitor *mon, int count, int format, int wsize, > hwaddr addr, int is_physical) > { > - CPUArchState *env; > int l, line_size, i, max_digits, len; > uint8_t buf[16]; > uint64_t v; >=20=20 > if (format =3D=3D 'i') { > - int flags; > - flags =3D 0; > - env =3D mon_get_cpu(); > + int flags =3D 0; > #ifdef TARGET_I386 > + CPUArchState *env =3D mon_get_cpu_env(); > if (wsize =3D=3D 2) { > flags =3D 1; > } else if (wsize =3D=3D 4) { > @@ -1238,10 +1231,11 @@ static void memory_dump(Monitor *mon, int count, = int format, int wsize, > } > #endif > #ifdef TARGET_PPC > + CPUArchState *env =3D mon_get_cpu_env(); > flags =3D msr_le << 16; > flags |=3D env->bfd_mach; > #endif > - monitor_disas(mon, env, addr, count, is_physical, flags); > + monitor_disas(mon, mon_get_cpu_env(), addr, count, is_physical, = flags); > return; > } >=20=20 > @@ -1280,8 +1274,7 @@ static void memory_dump(Monitor *mon, int count, in= t format, int wsize, > if (is_physical) { > cpu_physical_memory_read(addr, buf, l); > } else { > - env =3D mon_get_cpu(); > - if (cpu_memory_rw_debug(ENV_GET_CPU(env), addr, buf, l, 0) <= 0) { > + if (cpu_memory_rw_debug(mon_get_cpu(), addr, buf, l, 0) < 0)= { > monitor_printf(mon, " Cannot access memory\n"); > break; > } You call mon_get_cpu_env() and mon_get_cpu() multiple times in this function, and declare CPUArchState *env twice (which rang my shadowing alarm bell; fortunately the two are under mutually exclusive #ifdef). Why not simply do CPUState *cpu =3D mon_get_cpu(); CPUArchState *env =3D mon_get_cpu_env(); right at the beginning and be done with it? Not a big deal, I'm willing to take this patch through my tree as is. [...]