+2014-10-16  Tristan Gingold  <gingold@adacore.com>
+
+       * i386-darwin-nat.c (i386_darwin_fetch_inferior_registers)
+       (i386_darwin_store_inferior_registers): Sanitize gs and fs values
+       on amd64.
+
 2014-10-15  Pedro Alves  <palves@redhat.com>
 
        * dec-thread.c (dec_thread_count_gdb_threads)
 
                                 (unsigned long) current_thread);
              MACH_CHECK_ERROR (ret);
            }
+
+         /* Some kernels don't sanitize the values.  */
+         gp_regs.uts.ts64.__fs &= 0xffff;
+         gp_regs.uts.ts64.__gs &= 0xffff;
+
          amd64_supply_native_gregset (regcache, &gp_regs.uts, -1);
           fetched++;
         }
 
          amd64_collect_native_gregset (regcache, &gp_regs.uts, regno);
 
+         /* Some kernels don't sanitize the values.  */
+         gp_regs.uts.ts64.__fs &= 0xffff;
+         gp_regs.uts.ts64.__gs &= 0xffff;
+
           ret = thread_set_state (current_thread, x86_THREAD_STATE,
                                   (thread_state_t) &gp_regs,
                                   x86_THREAD_STATE_COUNT);