[PATCH 4/8] gdbserver: Update Haiku support for 16.x

Jérôme Duval
2026-03-12T17:29:09Z

---
gdbserver/haiku-amd64-low.cc | 8 ++++----
gdbserver/haiku-low.cc | 30 ++++++++++++++++++------------
2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/gdbserver/haiku-amd64-low.cc b/gdbserver/haiku-amd64-low.cc
index 0e6e0ade..3503d5ce 100644
--- a/gdbserver/haiku-amd64-low.cc
+++ b/gdbserver/haiku-amd64-low.cc
@@ -155,7 +155,7 @@ haiku_amd64_target::fetch_registers (struct regcache *regcache, int regno)
{
char regs[sizeof (x86_64_debug_cpu_state)];

- if (haiku_nat::get_cpu_state (ptid_of (current_thread), &regs) < 0)
+ if (haiku_nat::get_cpu_state (current_thread->id, &regs) < 0)
{
/* This happens when the inferior is killed by another process
while being stopped. The nub port has been deleted, so we cannot
@@ -196,7 +196,7 @@ haiku_amd64_target::store_registers (struct regcache *regcache, int regno)
{
char regs[sizeof (x86_64_debug_cpu_state)];

- if (haiku_nat::get_cpu_state (ptid_of (current_thread), &regs) < 0)
+ if (haiku_nat::get_cpu_state (current_thread->id, &regs) < 0)
{
haiku_nat_debug_printf ("Failed to get actual CPU state: %s",
strerror (errno));
@@ -220,7 +220,7 @@ haiku_amd64_target::store_registers (struct regcache *regcache, int regno)
}
}

- if (haiku_nat::set_cpu_state (ptid_of (current_thread), &regs) < 0)
+ if (haiku_nat::set_cpu_state (current_thread->id, &regs) < 0)
perror_with_name (("haiku_nat::set_cpu_state"));
}

@@ -248,7 +248,7 @@ haiku_amd64_target::low_arch_setup (process_info *process)
target_desc *tdesc = amd64_create_target_description (X86_XSTATE_AVX_MASK,
false, false, false);

- init_target_desc (tdesc, amd64_expedite_regs);
+ init_target_desc (tdesc, amd64_expedite_regs, GDB_OSABI_HAIKU);

process->tdesc = tdesc;
}
diff --git a/gdbserver/haiku-low.cc b/gdbserver/haiku-low.cc
index 41295d58..b0551b8f 100644
--- a/gdbserver/haiku-low.cc
+++ b/gdbserver/haiku-low.cc
@@ -168,7 +168,7 @@ haiku_process_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,

/* Add at least the child's main thread. Otherwise, gdbserver would
think we have no more inferiors attached and quit. */
- add_thread (ptid_t (pid, 0, pid), nullptr);
+ find_process_pid (pid)->add_thread (ptid_t (pid, 0, pid), nullptr);
};

client_state &cs = get_client_state ();
@@ -193,7 +193,7 @@ haiku_process_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
thread that was not fully initialized during the attach stage. */
if (wptid.tid () != 0 && !find_thread_ptid (wptid)
&& ourstatus->kind () != TARGET_WAITKIND_THREAD_EXITED)
- add_thread (wptid, nullptr);
+ find_process_pid (wptid.pid())->add_thread (wptid, nullptr);

switch (ourstatus->kind ())
{
@@ -247,7 +247,9 @@ haiku_process_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
return wptid;
break;
case TARGET_WAITKIND_THREAD_EXITED:
- remove_thread (find_thread_ptid (wptid));
+ {
+ thread_info *info = find_thread_ptid (wptid);
+ info->process ()->remove_thread (info);

if (cs.report_thread_events)
return wptid;
@@ -255,6 +257,7 @@ haiku_process_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
/* The thread is dead so we cannot resume the the same wptid. */
wptid = ptid;
break;
+ }
default:
gdb_assert_not_reached ("Unknown stopped status");
}
@@ -272,7 +275,7 @@ haiku_process_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
int
haiku_process_target::kill (process_info *process)
{
- if (haiku_nat::kill (pid_of (process)) < 0)
+ if (haiku_nat::kill (process->pid) < 0)
return -1;

mourn (process);
@@ -284,7 +287,7 @@ haiku_process_target::kill (process_info *process)
int
haiku_process_target::detach (process_info *process)
{
- if (haiku_nat::detach (pid_of (process)) < 0)
+ if (haiku_nat::detach (process->pid) < 0)
return -1;

mourn (process);
@@ -296,7 +299,10 @@ haiku_process_target::detach (process_info *process)
void
haiku_process_target::mourn (struct process_info *proc)
{
- for_each_thread (pid_of (proc), remove_thread);
+ proc->for_each_thread ([proc] (thread_info *thread)
+ {
+ proc->remove_thread (thread);
+ });

remove_process (proc);
}
@@ -306,7 +312,7 @@ haiku_process_target::mourn (struct process_info *proc)
void
haiku_process_target::join (int pid)
{
- gdb::handle_eintr (-1, ::waitpid, pid, nullptr, 0);
+ gdb::waitpid (pid, nullptr, 0);
}

/* Implement the thread_alive target_ops method. */
@@ -323,7 +329,7 @@ int
haiku_process_target::read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
int size)
{
- if (haiku_nat::read_memory (pid_of (current_process ()), memaddr, myaddr,
+ if (haiku_nat::read_memory (current_process ()->pid, memaddr, myaddr,
&size)
< 0)
{
@@ -340,7 +346,7 @@ int
haiku_process_target::write_memory (CORE_ADDR memaddr,
const unsigned char *myaddr, int size)
{
- if (haiku_nat::write_memory (pid_of (current_process ()), memaddr, myaddr,
+ if (haiku_nat::write_memory (current_process ()->pid, memaddr, myaddr,
&size)
< 0)
{
@@ -361,7 +367,7 @@ haiku_process_target::request_interrupt ()
if (thread == nullptr)
return;

- ::kill (pid_of (thread), SIGINT);
+ ::kill (thread->id.pid(), SIGINT);
}

/* Implement the read_offsets target_ops method. */
@@ -369,7 +375,7 @@ haiku_process_target::request_interrupt ()
int
haiku_process_target::read_offsets (CORE_ADDR *text, CORE_ADDR *data)
{
- if (haiku_nat::read_offsets (pid_of (current_process ()), text, data) < 0)
+ if (haiku_nat::read_offsets (current_process ()->pid, text, data) < 0)
return 0;
return 1;
}
@@ -438,7 +444,7 @@ haiku_process_target::start_non_stop (bool enable)
bool
haiku_process_target::thread_stopped (thread_info *thread)
{
- return haiku_nat::thread_stopped (ptid_of (thread));
+ return haiku_nat::thread_stopped (thread->id);
}

/* Implement the pid_to_exec_file target_ops method. */
--
2.43.0