[2/4] Simplify windows-nat.c:windows_make_so #ifdefery

Message ID 20240322190424.1231540-3-pedro@palves.net
State New
Headers
Series Down with SO_NAME_MAX_PATH_SIZE and windows_make_so spring cleaning |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply

Commit Message

Pedro Alves March 22, 2024, 7:04 p.m. UTC
  There are two separate #ifndef __CYGWIN__/#else/#endif sections in the
windows_make_so function with 3 lines of shared code separating them.
I find this makes the code harder to understand than necessary.
AFAICS, there is no reason those three shared lines need to be after
the first #ifdef block.  There is no early return, nor are 'load_addr'
nor 'name' modified.

This commit moves that shared code to the top of the function, and
then combines the two #ifndef sections.

Change-Id: If2678b52836b1c3134a5e9f9fdaee74448d8b7bc
---
 gdb/windows-nat.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
  

Patch

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index a90388922e2..a01011248c1 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -826,6 +826,10 @@  windows_nat_target::store_registers (struct regcache *regcache, int r)
 static windows_solib *
 windows_make_so (const char *name, LPVOID load_addr)
 {
+  windows_solib *so = &windows_process.solibs.emplace_back ();
+  so->load_addr = load_addr;
+  so->original_name = name;
+
 #ifndef __CYGWIN__
   char *p;
   char buf[__PMAX];
@@ -854,6 +858,8 @@  windows_make_so (const char *name, LPVOID load_addr)
       GetSystemDirectory (buf, sizeof (buf));
       strcat (buf, "\\ntdll.dll");
     }
+
+  so->name = buf;
 #else
   wchar_t buf[__PMAX];
 
@@ -866,13 +872,6 @@  windows_make_so (const char *name, LPVOID load_addr)
 	  wcscat (buf, L"\\ntdll.dll");
 	}
     }
-#endif
-  windows_solib *so = &windows_process.solibs.emplace_back ();
-  so->load_addr = load_addr;
-  so->original_name = name;
-#ifndef __CYGWIN__
-  so->name = buf;
-#else
   if (buf[0])
     {
       char cname[SO_NAME_MAX_PATH_SIZE];