[PATCH] Implement debugging of WOW64 processes

Simon Marchi simark@simark.ca
Tue Mar 3 21:31:00 GMT 2020


On 2020-03-03 4:12 p.m., Hannes Domani via gdb-patches wrote:
> I'm not very fond of the code duplication either.
> The only way I can think of, is to refactor it into template functions that
> can accept both CONTEXT or WOW64_CONTEXT.
> Is this what you had in mind also, or do you have a better idea?

I didn't really have something specific in mind.

However, I'm thinking that sprinkling the code with if/else such as:

  /* Do something */
#ifdef __x86_64__
  if (wow64_process)
    {
      ...
    }
#endif
  else
    {
      ...
    }

... does not help with readability and maintenance.  To address that, we could have an interface
with two concrete implementations (one for "standard" processes and one for WOW64 processes).  We
would choose and instantiate the right implementation at runtime (at the place where you currently
set the wow64_process variable), so the code above would become:

  /* Do something */
  impl->do_something ();

where the actual code is in each of the implementations' do_something methods.

That itself wouldn't reduce the code duplication.  But it would keep the specificities of dealing
with a standard process vs a WOW64 process at a single place.

To reduce code duplication, if there is any chance of sharing code between the two implementations,
it could be done by having helper methods in the base class and / or using templates, as you said.

Simon



More information about the Gdb-patches mailing list