qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 3/5] target/i386: convert to use format_state instead of dump


From: Daniel P . Berrangé
Subject: Re: [PATCH 3/5] target/i386: convert to use format_state instead of dump_state
Date: Thu, 9 Sep 2021 10:55:14 +0100
User-agent: Mutt/2.0.7 (2021-05-04)

On Wed, Sep 08, 2021 at 11:06:33PM +0100, Daniel P. Berrangé wrote:
> On Wed, Sep 08, 2021 at 01:05:13PM -0500, Eric Blake wrote:
> > On Wed, Sep 08, 2021 at 11:37:09AM +0100, Daniel P. Berrangé wrote:
> > > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > > ---
> > >  target/i386/cpu-dump.c | 325 ++++++++++++++++++++++-------------------
> > >  target/i386/cpu.c      |   2 +-
> > >  target/i386/cpu.h      |   2 +-
> > >  3 files changed, 174 insertions(+), 155 deletions(-)
> > > 
> > > diff --git a/target/i386/cpu-dump.c b/target/i386/cpu-dump.c
> > > index 02b635a52c..8e19485a20 100644
> > > --- a/target/i386/cpu-dump.c
> > > +++ b/target/i386/cpu-dump.c
> > > @@ -94,41 +94,45 @@ static const char *cc_op_str[CC_OP_NB] = {
> > >  };
> > >  
> > >  static void
> > > -cpu_x86_dump_seg_cache(CPUX86State *env, FILE *f,
> > > +cpu_x86_dump_seg_cache(CPUX86State *env, GString *buf,
> > >                         const char *name, struct SegmentCache *sc)
> > >  {
> > >  #ifdef TARGET_X86_64
> > >      if (env->hflags & HF_CS64_MASK) {
> > > -        qemu_fprintf(f, "%-3s=%04x %016" PRIx64 " %08x %08x", name,
> > > -                     sc->selector, sc->base, sc->limit,
> > > -                     sc->flags & 0x00ffff00);
> > > +        g_string_append_printf(buf, "%-3s=%04x %016" PRIx64 " %08x 
> > > %08x", name,
> > > +                               sc->selector, sc->base, sc->limit,
> > > +                               sc->flags & 0x00ffff00);
> > 
> > Did you consider using open_memstream() to get a FILE* that can then
> > be passed into these callbacks unchanged, rather than rewriting all
> > the callbacks to a new signature?
> 
> That is certainly an option, but it wouldn't eliminate the need to do
> a rewrite. I would still want to replace qemu_fprintf with fprintf in
> that scenario. It is desirable to be able to eliminate the QEMU
> specific printf wrappers which only exist because they need to treat
> a NULL FILE* object as an indication to output to the HMP chardev.
> Admittedly that would result in shorter lines than today.
> 
> > Then again, I like the GString signature better than FILE*, even if it
> > makes for longer lines.
> 
> Yes, the verbosity is not ideal. I like the GString API as a general
> purpose API for formatting text output to a buffer overall.
> 
> I don't feel too strongly either way though, as long as we get to a place
> where we eliminate the custom QEMU printf wrappers that integrate with
> the monitor APIs.

I forgot that open_memstream is not portable. The portable alternative
is fmemopen but that needs to know the buffer size upfront which is
too unpleasant to use.  So GString is the better portable option.


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




reply via email to

[Prev in Thread] Current Thread [Next in Thread]