]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Move x86 selector code into x86-windows-nat.c
authorHannes Domani <ssbssa@yahoo.de>
Fri, 23 Jan 2026 19:07:04 +0000 (20:07 +0100)
committerHannes Domani <ssbssa@yahoo.de>
Fri, 23 Jan 2026 19:07:04 +0000 (20:07 +0100)
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Christina Schimpe <christina.schimpe@intel.com>
gdb/windows-nat.c
gdb/x86-windows-nat.c

index fd6a02670b0def6711b8b47ffc9aa4e9d169cbeb..a8698c15c883cc2908049859ee4d7302d043e034 100644 (file)
@@ -684,127 +684,6 @@ windows_per_inferior::handle_output_debug_string
   return retval;
 }
 
-static int
-display_selector (HANDLE thread, DWORD sel)
-{
-  LDT_ENTRY info;
-  BOOL ret = windows_process->with_context (nullptr, [&] (auto *context)
-    {
-      return get_thread_selector_entry (context, thread, sel, &info);
-    });
-  if (ret)
-    {
-      int base, limit;
-      gdb_printf ("0x%03x: ", (unsigned) sel);
-      if (!info.HighWord.Bits.Pres)
-       {
-         gdb_puts ("Segment not present\n");
-         return 0;
-       }
-      base = (info.HighWord.Bits.BaseHi << 24) +
-            (info.HighWord.Bits.BaseMid << 16)
-            + info.BaseLow;
-      limit = (info.HighWord.Bits.LimitHi << 16) + info.LimitLow;
-      if (info.HighWord.Bits.Granularity)
-       limit = (limit << 12) | 0xfff;
-      gdb_printf ("base=0x%08x limit=0x%08x", base, limit);
-      if (info.HighWord.Bits.Default_Big)
-       gdb_puts(" 32-bit ");
-      else
-       gdb_puts(" 16-bit ");
-      switch ((info.HighWord.Bits.Type & 0xf) >> 1)
-       {
-       case 0:
-         gdb_puts ("Data (Read-Only, Exp-up");
-         break;
-       case 1:
-         gdb_puts ("Data (Read/Write, Exp-up");
-         break;
-       case 2:
-         gdb_puts ("Unused segment (");
-         break;
-       case 3:
-         gdb_puts ("Data (Read/Write, Exp-down");
-         break;
-       case 4:
-         gdb_puts ("Code (Exec-Only, N.Conf");
-         break;
-       case 5:
-         gdb_puts ("Code (Exec/Read, N.Conf");
-         break;
-       case 6:
-         gdb_puts ("Code (Exec-Only, Conf");
-         break;
-       case 7:
-         gdb_puts ("Code (Exec/Read, Conf");
-         break;
-       default:
-         gdb_printf ("Unknown type 0x%lx",
-                     (unsigned long) info.HighWord.Bits.Type);
-       }
-      if ((info.HighWord.Bits.Type & 0x1) == 0)
-       gdb_puts(", N.Acc");
-      gdb_puts (")\n");
-      if ((info.HighWord.Bits.Type & 0x10) == 0)
-       gdb_puts("System selector ");
-      gdb_printf ("Privilege level = %ld. ",
-                 (unsigned long) info.HighWord.Bits.Dpl);
-      if (info.HighWord.Bits.Granularity)
-       gdb_puts ("Page granular.\n");
-      else
-       gdb_puts ("Byte granular.\n");
-      return 1;
-    }
-  else
-    {
-      DWORD err = GetLastError ();
-      if (err == ERROR_NOT_SUPPORTED)
-       gdb_printf ("Function not supported\n");
-      else
-       gdb_printf ("Invalid selector 0x%x.\n", (unsigned) sel);
-      return 0;
-    }
-}
-
-static void
-display_selectors (const char * args, int from_tty)
-{
-  if (inferior_ptid == null_ptid)
-    {
-      gdb_puts ("Impossible to display selectors now.\n");
-      return;
-    }
-
-  windows_thread_info *current_windows_thread
-    = windows_process->thread_rec (inferior_ptid, DONT_INVALIDATE_CONTEXT);
-
-  if (!args)
-    {
-      windows_process->with_context (current_windows_thread, [&] (auto *context)
-       {
-         gdb_puts ("Selector $cs\n");
-         display_selector (current_windows_thread->h, context->SegCs);
-         gdb_puts ("Selector $ds\n");
-         display_selector (current_windows_thread->h, context->SegDs);
-         gdb_puts ("Selector $es\n");
-         display_selector (current_windows_thread->h, context->SegEs);
-         gdb_puts ("Selector $ss\n");
-         display_selector (current_windows_thread->h, context->SegSs);
-         gdb_puts ("Selector $fs\n");
-         display_selector (current_windows_thread->h, context->SegFs);
-         gdb_puts ("Selector $gs\n");
-         display_selector (current_windows_thread->h, context->SegGs);
-       });
-    }
-  else
-    {
-      int sel;
-      sel = parse_and_eval_long (args);
-      gdb_printf ("Selector \"%s\"\n",args);
-      display_selector (current_windows_thread->h, sel);
-    }
-}
-
 /* See nat/windows-nat.h.  */
 
 bool
@@ -2726,10 +2605,6 @@ Show whether to display kernel exceptions in child process."), NULL,
 
   init_w32_command_list ();
 
-  add_cmd ("selector", class_info, display_selectors,
-          _("Display selectors infos."),
-          &info_w32_cmdlist);
-
   if (!initialize_loadable ())
     {
       /* This will probably fail on Windows 9x/Me.  Let the user know
index 356097ac363fe2bc49d4f7a5e4213195f44801c1..4e38181c55cba143e659e975b811ed5a22cc2bc8 100644 (file)
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+#include "windows-tdep.h"
 #include "windows-nat.h"
 #include "regcache.h"
 #include "gdbarch.h"
+#include "inferior.h"
 
 #include "x86-nat.h"
 
@@ -333,6 +335,127 @@ cygwin_get_dr7 (void)
   return (unsigned long) x86_windows_process.dr[7];
 }
 
+static int
+display_selector (HANDLE thread, DWORD sel)
+{
+  LDT_ENTRY info;
+  BOOL ret = windows_process->with_context (nullptr, [&] (auto *context)
+    {
+      return get_thread_selector_entry (context, thread, sel, &info);
+    });
+  if (ret)
+    {
+      int base, limit;
+      gdb_printf ("0x%03x: ", (unsigned) sel);
+      if (!info.HighWord.Bits.Pres)
+       {
+         gdb_puts ("Segment not present\n");
+         return 0;
+       }
+      base = (info.HighWord.Bits.BaseHi << 24) +
+            (info.HighWord.Bits.BaseMid << 16)
+            + info.BaseLow;
+      limit = (info.HighWord.Bits.LimitHi << 16) + info.LimitLow;
+      if (info.HighWord.Bits.Granularity)
+       limit = (limit << 12) | 0xfff;
+      gdb_printf ("base=0x%08x limit=0x%08x", base, limit);
+      if (info.HighWord.Bits.Default_Big)
+       gdb_puts(" 32-bit ");
+      else
+       gdb_puts(" 16-bit ");
+      switch ((info.HighWord.Bits.Type & 0xf) >> 1)
+       {
+       case 0:
+         gdb_puts ("Data (Read-Only, Exp-up");
+         break;
+       case 1:
+         gdb_puts ("Data (Read/Write, Exp-up");
+         break;
+       case 2:
+         gdb_puts ("Unused segment (");
+         break;
+       case 3:
+         gdb_puts ("Data (Read/Write, Exp-down");
+         break;
+       case 4:
+         gdb_puts ("Code (Exec-Only, N.Conf");
+         break;
+       case 5:
+         gdb_puts ("Code (Exec/Read, N.Conf");
+         break;
+       case 6:
+         gdb_puts ("Code (Exec-Only, Conf");
+         break;
+       case 7:
+         gdb_puts ("Code (Exec/Read, Conf");
+         break;
+       default:
+         gdb_printf ("Unknown type 0x%lx",
+                     (unsigned long) info.HighWord.Bits.Type);
+       }
+      if ((info.HighWord.Bits.Type & 0x1) == 0)
+       gdb_puts(", N.Acc");
+      gdb_puts (")\n");
+      if ((info.HighWord.Bits.Type & 0x10) == 0)
+       gdb_puts("System selector ");
+      gdb_printf ("Privilege level = %ld. ",
+                 (unsigned long) info.HighWord.Bits.Dpl);
+      if (info.HighWord.Bits.Granularity)
+       gdb_puts ("Page granular.\n");
+      else
+       gdb_puts ("Byte granular.\n");
+      return 1;
+    }
+  else
+    {
+      DWORD err = GetLastError ();
+      if (err == ERROR_NOT_SUPPORTED)
+       gdb_printf ("Function not supported\n");
+      else
+       gdb_printf ("Invalid selector 0x%x.\n", (unsigned) sel);
+      return 0;
+    }
+}
+
+static void
+display_selectors (const char * args, int from_tty)
+{
+  if (inferior_ptid == null_ptid)
+    {
+      gdb_puts ("Impossible to display selectors now.\n");
+      return;
+    }
+
+  windows_thread_info *current_windows_thread
+    = windows_process->thread_rec (inferior_ptid, DONT_INVALIDATE_CONTEXT);
+
+  if (!args)
+    {
+      windows_process->with_context (current_windows_thread, [&] (auto *context)
+       {
+         gdb_puts ("Selector $cs\n");
+         display_selector (current_windows_thread->h, context->SegCs);
+         gdb_puts ("Selector $ds\n");
+         display_selector (current_windows_thread->h, context->SegDs);
+         gdb_puts ("Selector $es\n");
+         display_selector (current_windows_thread->h, context->SegEs);
+         gdb_puts ("Selector $ss\n");
+         display_selector (current_windows_thread->h, context->SegSs);
+         gdb_puts ("Selector $fs\n");
+         display_selector (current_windows_thread->h, context->SegFs);
+         gdb_puts ("Selector $gs\n");
+         display_selector (current_windows_thread->h, context->SegGs);
+       });
+    }
+  else
+    {
+      int sel;
+      sel = parse_and_eval_long (args);
+      gdb_printf ("Selector \"%s\"\n",args);
+      display_selector (current_windows_thread->h, sel);
+    }
+}
+
 INIT_GDB_FILE (x86_windows_nat)
 {
   x86_dr_low.set_control = cygwin_set_dr7;
@@ -350,4 +473,8 @@ INIT_GDB_FILE (x86_windows_nat)
   add_inf_child_target (new x86_windows_nat_target);
 
   windows_process = &x86_windows_process;
+
+  add_cmd ("selector", class_info, display_selectors,
+          _("Display selectors infos."),
+          &info_w32_cmdlist);
 }