edi: Fix debugging on OpenBSD.

This commit is contained in:
Alastair Poole 2020-01-03 13:40:57 +00:00
parent c40b46455a
commit 44a0ebad3f
2 changed files with 44 additions and 1 deletions

View File

@ -9,6 +9,14 @@
#include <sys/user.h>
#endif
#if defined(__OpenBSD__)
# include <kvm.h>
# include <limits.h>
# include <sys/proc.h>
# include <sys/param.h>
# include <sys/resource.h>
#endif
#if defined(__linux__)
# include <sys/types.h>
# include <dirent.h>
@ -150,6 +158,41 @@ int edi_debug_process_id(Edi_Debug *debugger)
closedir(dir);
return child_pid;
#elif defined(__OpenBSD__)
kvm_t *kern;
struct kinfo_proc *kp;
char errbuf[4096];
int pid_count;
kern = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
if (!kern) return -1;
kp = kvm_getprocs(kern, KERN_PROC_ALL, 0, sizeof(*kp), &pid_count);
if (!kp) return -1;
for (int i = 0; i < pid_count; i++)
{
p = edi_process_stats_by_pid(kp[i].p_pid);
if (!p) continue;
if (p->ppid == debugger_pid)
{
if (!strcmp(debugger->program_name, p->command))
{
child_pid = p->pid;
if (!strcmp(p->state, "RUN") ||!strcmp(p->state, "SLEEP"))
debugger->state = EDI_DEBUG_PROCESS_ACTIVE;
else
debugger->state = EDI_DEBUG_PROCESS_SLEEPING;
}
}
free(p);
}
kvm_close(kern);
return child_pid;
#endif

View File

@ -42,7 +42,7 @@ if get_option('libclang') == true
endif
executable('edi', src,
dependencies : deps,
dependencies : [deps, deps_os],
include_directories : incls,
install : true
)