]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Reduce WOW64 code duplication
authorHannes Domani <ssbssa@yahoo.de>
Fri, 6 Dec 2024 13:04:00 +0000 (14:04 +0100)
committerHannes Domani <ssbssa@yahoo.de>
Fri, 6 Dec 2024 13:04:04 +0000 (14:04 +0100)
commitb2682eade4db993bc8231007ba94aec4e4728c61
treefab3f6098344cbdea331fabf92734d1ed66e9445
parenta3011beced048e66d200921b2a11c836fae31abf
Reduce WOW64 code duplication

Currently we have duplicate code for each place where
windows_thread_info::context is touched, since for WOW64 processes
it has to do the equivalent with wow64_context instead.

For example this code...:

 #ifdef __x86_64__
   if (windows_process.wow64_process)
     {
       th->wow64_context.ContextFlags = WOW64_CONTEXT_ALL;
       CHECK (Wow64GetThreadContext (th->h, &th->wow64_context));
       ...
     }
   else
 #endif
     {
       th->context.ContextFlags = CONTEXT_DEBUGGER_DR;
       CHECK (GetThreadContext (th->h, &th->context));
       ...
     }

...changes to look like this instead:

   windows_process.with_context (th, [&] (auto *context)
     {
       context->ContextFlags = WindowsContext<decltype(context)>::all;
       CHECK (get_thread_context (th->h, context));
       ...
     }

The actual choice if context or wow64_context are used, is handled by
this new function in windows_process_info:

   template<typename Function>
   auto with_context (windows_thread_info *th, Function function)
   {
 #ifdef __x86_64__
     if (wow64_process)
       return function (th != nullptr ? th->wow64_context : nullptr);
     else
 #endif
       return function (th != nullptr ? th->context : nullptr);
   }

The other parts to make this work are the templated WindowsContext class
which give the appropriate ContextFlags for both types.
And there are also overloaded helper functions, like in the case of
get_thread_context here, call either GetThreadContext or
Wow64GetThreadContext.

According git log --stat, this results in 120 lines less code.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/nat/windows-nat.c
gdb/nat/windows-nat.h
gdb/windows-nat.c
gdbserver/win32-i386-low.cc
gdbserver/win32-low.cc