29 #include <sys/procfs.h> 31 #include <sys/iomgr.h> 32 #include <sys/neutrino.h> 47 fprintf (stderr,
"nto:");
48 va_start (arg_list, fmt);
49 vfprintf (stderr, fmt, arg_list);
53 #define TRACE nto_trace 106 TRACE (
"%s: Error: failed to set current thread\n", __func__);
127 for (tid = 1;; ++tid)
129 procfs_status status;
137 if (err != EOK || status.tid == 0)
141 while (tid != status.tid || status.state == STATE_DEAD)
149 TRACE (
"Removing thread %d\n", tid);
152 if (tid == status.tid)
157 if (status.state != STATE_DEAD)
159 TRACE (
"Adding thread %d\n", tid);
172 procfs_status status;
173 struct sigevent event;
196 event.sigev_notify = SIGEV_SIGNAL_THREAD;
197 event.sigev_signo = SIGUSR1;
198 event.sigev_code = 0;
199 event.sigev_value.sival_ptr = NULL;
200 event.sigev_priority = -1;
205 && (status.flags & _DEBUG_FLAG_STOPPED))
211 ptid =
ptid_build (status.pid, status.tid, 0);
215 TRACE (
"Adding thread: pid=%d tid=%ld\n", status.pid,
250 TRACE (
"Error in %s : errno=%d (%s)\n", __func__, e,
strerror (e));
282 unsigned char *myaddr,
287 unsigned int len_read = 0;
305 sizeof (anint), 0) !=
sizeof (anint))
309 data_ofs += (anint + 2) *
sizeof (
void *);
315 (
unsigned char *)&anint,
sizeof (anint), 0)
318 data_ofs +=
sizeof (anint);
322 initial_stack += data_ofs;
325 while (len_read <= len -
sizeof (auxv_t))
327 auxv_t *auxv = (auxv_t *)myaddr;
332 sizeof (auxv_t), 0) ==
sizeof (auxv_t))
334 if (auxv->a_type != AT_NULL)
337 len_read +=
sizeof (auxv_t);
339 if (auxv->a_type == AT_PHNUM)
341 initial_stack +=
sizeof (auxv_t);
346 TRACE (
"auxv: len_read: %d\n", len_read);
357 struct inheritance inherit;
362 TRACE (
"%s %s\n", __func__, program);
364 signal (SIGUSR1, signal (SIGUSR1, SIG_IGN));
367 sigaddset (&
set, SIGUSR1);
368 sigprocmask (SIG_UNBLOCK, &
set, NULL);
370 memset (&inherit, 0,
sizeof (inherit));
371 inherit.flags |= SPAWN_SETGROUP | SPAWN_HOLD;
372 inherit.pgroup = SPAWN_NEWPGROUP;
373 pid = spawnp (program, 0, NULL, &inherit,
374 (
char *) str_program_args.c_str (), 0);
375 sigprocmask (SIG_BLOCK, &
set, NULL);
391 TRACE (
"%s %ld\n", __func__, pid);
393 error (
"Unable to attach to %ld\n", pid);
402 TRACE (
"%s %d\n", __func__, pid);
413 TRACE (
"%s %d\n", __func__, pid);
440 TRACE (
"%s: %s\n", __func__, res ?
"yes" :
"no");
450 procfs_status status;
454 TRACE (
"%s\n", __func__);
456 sigset_t *run_fault = (sigset_t *) (
void *) &run.fault;
460 run.flags = _DEBUG_RUN_FAULT | _DEBUG_RUN_TRACE;
461 if (resume_info->
kind == resume_step)
462 run.flags |= _DEBUG_RUN_STEP;
463 run.flags |= _DEBUG_RUN_ARM;
465 sigemptyset (run_fault);
466 sigaddset (run_fault, FLTBPT);
467 sigaddset (run_fault, FLTTRACE);
468 sigaddset (run_fault, FLTILL);
469 sigaddset (run_fault, FLTPRIV);
470 sigaddset (run_fault, FLTBOUNDS);
471 sigaddset (run_fault, FLTIOVF);
472 sigaddset (run_fault, FLTIZDIV);
473 sigaddset (run_fault, FLTFPE);
474 sigaddset (run_fault, FLTPAGE);
475 sigaddset (run_fault, FLTSTACK);
476 sigaddset (run_fault, FLTACCESS);
478 sigemptyset (&run.trace);
479 if (resume_info->
sig)
485 signal_to_pass = resume_info->
sig;
486 if (status.why & (_DEBUG_WHY_SIGNALLED | _DEBUG_WHY_FAULTED))
488 if (signal_to_pass != status.info.si_signo)
490 kill (status.pid, signal_to_pass);
491 run.flags |= _DEBUG_RUN_CLRFLT | _DEBUG_RUN_CLRSIG;
494 sigdelset (&run.trace, signal_to_pass);
498 run.flags |= _DEBUG_RUN_CLRSIG | _DEBUG_RUN_CLRFLT;
500 sigfillset (&run.trace);
515 struct target_waitstatus *ourstatus,
int target_options)
519 procfs_status status;
520 const int trace_mask = (_DEBUG_FLAG_TRACE_EXEC | _DEBUG_FLAG_TRACE_RD
521 | _DEBUG_FLAG_TRACE_WR | _DEBUG_FLAG_TRACE_MODIFY);
523 TRACE (
"%s\n", __func__);
525 ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
528 sigaddset (&
set, SIGUSR1);
531 while (!(status.flags & _DEBUG_FLAG_ISTOP))
533 sigwaitinfo (&
set, &info);
539 if (status.flags & _DEBUG_FLAG_SSTEP)
542 ourstatus->kind = TARGET_WAITKIND_STOPPED;
543 ourstatus->value.sig = GDB_SIGNAL_TRAP;
546 else if (status.flags & trace_mask)
549 ourstatus->kind = TARGET_WAITKIND_STOPPED;
550 ourstatus->value.sig = GDB_SIGNAL_TRAP;
552 else if (status.flags & _DEBUG_FLAG_ISTOP)
557 case _DEBUG_WHY_SIGNALLED:
558 TRACE (
" SIGNALLED\n");
559 ourstatus->kind = TARGET_WAITKIND_STOPPED;
560 ourstatus->value.sig =
564 case _DEBUG_WHY_FAULTED:
565 TRACE (
" FAULTED\n");
566 ourstatus->kind = TARGET_WAITKIND_STOPPED;
567 if (status.info.si_signo == SIGTRAP)
569 ourstatus->value.sig = 0;
574 ourstatus->value.sig =
580 case _DEBUG_WHY_TERMINATED:
584 TRACE (
" TERMINATED\n");
589 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
595 ourstatus->kind = TARGET_WAITKIND_EXITED;
602 case _DEBUG_WHY_REQUESTED:
603 TRACE (
"REQUESTED\n");
605 ourstatus->kind = TARGET_WAITKIND_STOPPED;
606 ourstatus->value.sig = GDB_SIGNAL_INT;
612 return ptid_build (status.pid, status.tid, 0);
624 TRACE (
"%s (regno=%d)\n", __func__, regno);
630 TRACE (
"current_thread is NULL\n");
644 const unsigned int registeroffset
647 ((
char *)&greg) + registeroffset);
652 const unsigned int registeroffset
654 if (registeroffset == -1)
660 TRACE (
"ERROR reading registers from inferior.\n");
672 TRACE (
"%s (regno:%d)\n", __func__, regno);
676 TRACE (
"current_thread is NULL\n");
683 memset (&greg, 0,
sizeof (greg));
686 const unsigned int regoffset
693 TRACE (
"Error: setting registers.\n");
704 TRACE (
"%s memaddr:0x%08lx, len:%d\n", __func__, memaddr, len);
708 TRACE (
"Failed to read memory\n");
725 TRACE (
"%s memaddr: 0x%08llx len: %d\n", __func__, memaddr, len);
726 if ((len_written =
nto_xfer_memory (memaddr, (
unsigned char *)myaddr, len,
730 TRACE (
"Wanted to write: %d but written: %d\n", len, len_written);
742 TRACE (
"%s\n", __func__);
745 TRACE (
"Error stopping inferior.\n");
759 procfs_info procinfo;
761 TRACE (
"%s\n", __func__);
770 initial_stack = procinfo.initial_stack;
797 int wtype = _DEBUG_BREAK_HW;
799 TRACE (
"%s type:%c addr: 0x%08lx len:%d\n", __func__, (
int)type, addr, size);
803 wtype = _DEBUG_BREAK_EXEC;
806 wtype |= _DEBUG_BREAK_EXEC;
809 wtype |= _DEBUG_BREAK_RW;
812 wtype |= _DEBUG_BREAK_RD;
815 wtype |= _DEBUG_BREAK_RW;
829 int wtype = _DEBUG_BREAK_HW;
831 TRACE (
"%s type:%c addr: 0x%08lx len:%d\n", __func__, (
int)type, addr, size);
835 wtype = _DEBUG_BREAK_EXEC;
838 wtype |= _DEBUG_BREAK_EXEC;
841 wtype |= _DEBUG_BREAK_RW;
844 wtype |= _DEBUG_BREAK_RD;
847 wtype |= _DEBUG_BREAK_RW;
865 TRACE (
"%s\n", __func__);
871 const int watchmask = _DEBUG_FLAG_TRACE_RD | _DEBUG_FLAG_TRACE_WR
872 | _DEBUG_FLAG_TRACE_MODIFY;
873 procfs_status status;
878 if (err == EOK && (status.flags & watchmask))
882 TRACE (
"%s: %s\n", __func__, ret ?
"yes" :
"no");
895 TRACE (
"%s\n", __func__);
902 procfs_status status;
905 sizeof (status), 0) == EOK)
909 TRACE (
"%s: 0x%08lx\n", __func__, ret);
918 TRACE (
"%s\n", __func__);
1017 TRACE (
"%s\n", __func__);
1023 sigaddset (&
set, SIGUSR1);
1024 sigprocmask (SIG_BLOCK, &
set, NULL);
struct thread_info * current_thread
int target_can_do_hardware_single_step(void)
void collect_register(struct regcache *regcache, int n, void *buf)
struct process_info * add_process(int pid, int attached)
struct thread_info * find_thread_ptid(ptid_t ptid)
static int nto_detach(int pid)
static int nto_read_auxv(CORE_ADDR offset, unsigned char *myaddr, unsigned int len)
static int nto_breakpoint(CORE_ADDR addr, int type, int size)
static int nto_write_memory(CORE_ADDR memaddr, const unsigned char *myaddr, int len)
int ptid_get_pid(const ptid_t &ptid)
std::string stringify_argv(const std::vector< char *> &args)
static void do_detach(void)
static int nto_attach(unsigned long pid)
static void nto_resume(struct thread_resume *resume_info, size_t n)
static ptid_t ptid_of(const thread_info *thread)
static CORE_ADDR nto_stopped_data_address(void)
void * memset(T *s, int c, size_t n)=delete
static int nto_create_inferior(const char *program, const std::vector< char *> &program_args)
static void nto_trace(const char *fmt,...)
static void nto_mourn(struct process_info *process)
static void nto_find_new_threads(struct nto_inferior *nto_inferior)
struct linux_target_ops the_low_target
static pid_t do_attach(pid_t pid)
static int nto_insert_point(enum raw_bkpt_type type, CORE_ADDR addr, int size, struct raw_breakpoint *bp)
const struct target_desc * tdesc
static int nto_remove_point(enum raw_bkpt_type type, CORE_ADDR addr, int size, struct raw_breakpoint *bp)
static int nto_read_memory(CORE_ADDR memaddr, unsigned char *myaddr, int len)
ptid_t ptid_build(int pid, long lwp, long tid)
static ptid_t nto_wait(ptid_t ptid, struct target_waitstatus *ourstatus, int target_options)
void regcache_invalidate(void)
static int nto_thread_alive(ptid_t ptid)
static int nto_read_auxv_from_initial_stack(CORE_ADDR initial_stack, unsigned char *myaddr, unsigned int len)
static void nto_request_interrupt(void)
enum gdb_signal gdb_signal_from_host(int)
void remove_process(struct process_info *process)
void set_target_ops(struct target_ops *target)
static int nto_stopped_by_watchpoint(void)
long ptid_get_lwp(const ptid_t &ptid)
char nto_procfs_path[PATH_MAX]
static void nto_store_registers(struct regcache *regcache, int regno)
static int nto_supports_non_stop(void)
void initialize_low(void)
int xsnprintf(char *str, size_t size, const char *format,...)
static int nto_kill(int pid)
void hostio_last_error_from_errno(char *buf)
static int nto_xfer_memory(off_t memaddr, unsigned char *myaddr, int len, int dowrite)
#define Z_PACKET_ACCESS_WP
static void init_nto_inferior(struct nto_inferior *nto_inferior)
void remove_thread(struct thread_info *thread)
int ptid_equal(const ptid_t &ptid1, const ptid_t &ptid2)
constexpr long tid() const
static void nto_fetch_registers(struct regcache *regcache, int regno)
static std::vector< char * > program_args
void supply_register(struct regcache *regcache, int n, const void *buf)
struct thread_info * add_thread(ptid_t ptid, void *target_data)
void error(const char *fmt,...)
static int nto_supports_z_point_type(char z_type)
const struct target_desc * nto_tdesc
#define Z_PACKET_WRITE_WP
static int nto_set_thread(ptid_t ptid)
static const gdb_byte * nto_sw_breakpoint_from_kind(int kind, int *size)