int start_erl(int argc, char **argv) { union SIGNAL *sig; PROCESS erts_; OSENTRYPOINT erts; if(hunt("erts", 0, NULL, NULL)) { erl_dbg_fprintf(stderr, "ERROR: erts already running\n"); return 0; } erl_block = get_bid(erl_tmp_); erl_dbg_fprintf(stdout, "Erlang block id: %li\n", (unsigned long)erl_block); fflush(stderr); /* initialise DNS service, needed for distributed Erlang */ config_dns(); erl_argc = argc; erl_argv = argv; /* so that erts may copy the struct */ /* used by erts to detect shutdown of ose shell (interactive mode only) */ erlang_starter_ = current_process(); /* create and start the erlang emulator as ose process "erts" */ erts_ = create_process(OS_BG_PROC, /* processtype */ "erts", /* name */ erts, /* entrypoint */ 524288, /* stacksize */ 20, /* priority (if OS_PRI_PROC) */ 0, /* timeslice */ erl_block, /* block */ NULL,0,0); /* not used */ set_fsem((OSFSEMVAL) 0, current_process()); efs_clone(erts_); start(erts_); /* sync with erts, this function must not return until erts has copied argv */ wait_fsem((OSFSEMVAL) 1); /* in interactive mode the ose shell will "hang", waiting for erts to terminate */ if(!start_detached) { static const SIGSELECT recv_attach_sig[2] = {1, OS_ATTACH_SIG}; erl_dbg_fprintf(stdout, "erts started in interactive mode\n"); attach(NULL, erts_); sig = receive((SIGSELECT*)recv_attach_sig); erl_dbg_fprintf(stderr, "\n*** Erlang finished ***\n"); free_buf(&sig); } return 0; }
// FEEL FREE TO MODIFY ACCORDING TO delayed_send, the following modifications were only made to suit console handling process/uart i-process // Process receives a message from sender void * k_receive_message (uint32_t *sender_ID) { envelope *envel = (current_process())->m_envelope; if (envel == 0) return 0; /*while (envel == 0) { move_to_blocked((current_process())->m_pid, MSG_BLOCKED); k_release_processor(); envel = (current_process())->m_envelope; }*/ dequeue_envelope((current_process())->m_pid, envel); return envel->info->message; }
static struct breakpoint * set_breakpoint (enum bkpt_type type, enum raw_bkpt_type raw_type, CORE_ADDR where, int size, int (*handler) (CORE_ADDR), int *err) { struct process_info *proc = current_process (); struct breakpoint *bp; struct raw_breakpoint *raw; raw = set_raw_breakpoint_at (raw_type, where, size, err); if (raw == NULL) { /* warn? */ return NULL; } bp = xcalloc (1, sizeof (struct breakpoint)); bp->type = type; bp->raw = raw; bp->handler = handler; bp->next = proc->breakpoints; proc->breakpoints = bp; return bp; }
void reinsert_breakpoints_at (CORE_ADDR pc) { struct process_info *proc = current_process (); struct raw_breakpoint *bp; int found = 0; for (bp = proc->raw_breakpoints; bp != NULL; bp = bp->next) if ((bp->raw_type == raw_bkpt_type_sw || bp->raw_type == raw_bkpt_type_hw) && bp->pc == pc) { found = 1; reinsert_raw_breakpoint (bp); } if (!found) { /* This can happen when we remove all breakpoints while handling a step-over. */ if (debug_threads) debug_printf ("Could not find raw breakpoint at 0x%s " "in list (reinserting).\n", paddress (pc)); } }
/* * getenv_int: */ static char *getenv_int(const char *name) { #ifdef __OSE__ return get_env(get_bid(current_process()),name); #else return getenv(name); #endif }
static void aarch64_arch_setup (void) { current_process ()->tdesc = aarch64_linux_read_description (); aarch64_linux_get_debug_reg_capacity (lwpid_of (current_thread)); }
static void lynx_resume (struct thread_resume *resume_info, size_t n) { ptid_t ptid = resume_info[0].thread; const int request = (resume_info[0].kind == resume_step ? (n == 1 ? PTRACE_SINGLESTEP_ONE : PTRACE_SINGLESTEP) : PTRACE_CONT); const int signal = resume_info[0].sig; /* If given a minus_one_ptid, then try using the current_process' private->last_wait_event_ptid. On most LynxOS versions, using any of the process' thread works well enough, but LynxOS 178 is a little more sensitive, and triggers some unexpected signals (Eg SIG61) when we resume the inferior using a different thread. */ if (ptid_equal (ptid, minus_one_ptid)) ptid = current_process()->priv->last_wait_event_ptid; /* The ptid might still be minus_one_ptid; this can happen between the moment we create the inferior or attach to a process, and the moment we resume its execution for the first time. It is fine to use the current_thread's ptid in those cases. */ if (ptid_equal (ptid, minus_one_ptid)) ptid = thread_to_gdb_id (current_thread); regcache_invalidate (); errno = 0; lynx_ptrace (request, ptid, 1, signal, 0); if (errno) perror_with_name ("ptrace"); }
struct breakpoint * set_breakpoint_at (CORE_ADDR where, int (*handler) (CORE_ADDR)) { struct process_info *proc = current_process (); struct breakpoint *bp; struct raw_breakpoint *raw; raw = set_raw_breakpoint_at (where); if (raw == NULL) { /* warn? */ return NULL; } bp = xcalloc (1, sizeof (struct breakpoint)); bp->type = other_breakpoint; bp->raw = raw; bp->handler = handler; bp->next = proc->breakpoints; proc->breakpoints = bp; return bp; }
void check_breakpoints (CORE_ADDR stop_pc) { struct process_info *proc = current_process (); struct breakpoint *bp, **bp_link; bp = proc->breakpoints; bp_link = &proc->breakpoints; while (bp) { if (bp->raw->pc == stop_pc) { if (!bp->raw->inserted) { warning ("Hit a removed breakpoint?"); return; } if (bp->handler != NULL && (*bp->handler) (stop_pc)) { *bp_link = bp->next; release_breakpoint (proc, bp); bp = *bp_link; continue; } } bp_link = &bp->next; bp = *bp_link; } }
static void tile_arch_setup (void) { int pid = pid_of (current_thread); unsigned int machine; int is_elf64 = linux_pid_exe_is_elf_64_file (pid, &machine); if (sizeof (void *) == 4) if (is_elf64 > 0) error (_("Can't debug 64-bit process with 32-bit GDBserver")); if (!is_elf64) current_process ()->tdesc = tdesc_tilegx32; else current_process ()->tdesc = tdesc_tilegx; }
int thread_db_init (void) { struct process_info *proc = current_process (); /* FIXME drow/2004-10-16: This is the "overall process ID", which GNU/Linux calls tgid, "thread group ID". When we support attaching to threads, the original thread may not be the correct thread. We would have to get the process ID from /proc for NPTL. This isn't the only place in gdbserver that assumes that the first process in the list is the thread group leader. */ if (thread_db_load_search ()) { /* It's best to avoid td_ta_thr_iter if possible. That walks data structures in the inferior's address space that may be corrupted, or, if the target is running, the list may change while we walk it. In the latter case, it's possible that a thread exits just at the exact time that causes GDBserver to get stuck in an infinite loop. As the kernel supports clone events and /proc/PID/task/ exists, then we already know about all threads in the process. When we need info out of thread_db on a given thread (e.g., for TLS), we'll use find_one_thread then. That uses thread_db entry points that do not walk libpthread's thread list, so should be safe, as well as more efficient. */ if (!linux_proc_task_list_dir_exists (pid_of (proc))) thread_db_find_new_threads (); thread_db_look_up_symbols (); return 1; } return 0; }
static int attach_thread (const td_thrhandle_t *th_p, td_thrinfo_t *ti_p) { struct process_info *proc = current_process (); int pid = pid_of (proc); ptid_t ptid = ptid_build (pid, ti_p->ti_lid, 0); struct lwp_info *lwp; int err; if (debug_threads) debug_printf ("Attaching to thread %ld (LWP %d)\n", (unsigned long) ti_p->ti_tid, ti_p->ti_lid); err = linux_attach_lwp (ptid); if (err != 0) { warning ("Could not attach to thread %ld (LWP %d): %s\n", (unsigned long) ti_p->ti_tid, ti_p->ti_lid, linux_ptrace_attach_fail_reason_string (ptid, err)); return 0; } lwp = find_lwp_pid (ptid); gdb_assert (lwp != NULL); lwp->thread_known = 1; lwp->th = *th_p; return 1; }
/* error_logf() * Prints the arguments to stderr or syslog * Works like printf (see vfprintf) */ void erts_run_erl_log_error(int priority, int line, const char *format, ...) { va_list args; va_start(args, format); #ifdef HAVE_SYSLOG_H if (RUN_DAEMON) { vsyslog(priority,format,args); } else #endif #ifdef __OSE__ if (RUN_DAEMON) { char *buff = malloc(sizeof(char)*1024); vsnprintf(buff,1024,format, args); ramlog_printf(buff); } else #endif { time_t now = time(NULL); fprintf(stderr, "run_erl:%d [%d] %s", line, #ifdef __OSE__ (int)current_process(), #else (int)getpid(), #endif ctime(&now)); vfprintf(stderr, format, args); } va_end(args); }
static int thread_db_create_event (CORE_ADDR where) { td_event_msg_t msg; td_err_e err; struct lwp_info *lwp; struct thread_db *thread_db = current_process ()->priv->thread_db; gdb_assert (thread_db->td_ta_event_getmsg_p != NULL); if (debug_threads) debug_printf ("Thread creation event.\n"); /* FIXME: This assumes we don't get another event. In the LinuxThreads implementation, this is safe, because all events come from the manager thread (except for its own creation, of course). */ err = thread_db->td_ta_event_getmsg_p (thread_db->thread_agent, &msg); if (err != TD_OK) fprintf (stderr, "thread getmsg err: %s\n", thread_db_err_str (err)); /* If we do not know about the main thread yet, this would be a good time to find it. We need to do this to pick up the main thread before any newly created threads. */ lwp = get_thread_lwp (current_thread); if (lwp->thread_known == 0) find_one_thread (current_thread->entry.id); /* msg.event == TD_EVENT_CREATE */ find_new_threads_callback (msg.th_p, NULL); return 0; }
static struct aarch64_debug_reg_state * aarch64_get_debug_reg_state () { struct process_info *proc; proc = current_process (); return &proc->priv->arch_private->debug_reg_state; }
void delete_all_breakpoints (void) { struct process_info *proc = current_process (); while (proc->breakpoints) delete_breakpoint_1 (proc, proc->breakpoints); }
const struct target_desc * current_target_desc (void) { if (current_thread == NULL) return &default_description; return current_process ()->tdesc; }
void syscall_env( struct syscall_packet *scp ) { struct process *proc = NULL; scp->rc = SMK_UNKNOWN_SYSCALL; switch (scp->opcode) { case OP( ENV, ONE ): proc = checkout_process( getpid(), WRITER ); assert( proc != NULL ); scp->rc = set_environment( current_process(), scp->name, scp->ptr, scp->size ); commit_process( proc ); break; case OP( ENV, TWO ): proc = checkout_process( getpid(), READER ); assert( proc != NULL ); scp->rc = get_environment( current_process(), scp->name, scp->ptr, &(scp->size) ); commit_process( proc ); break; case OP( ENV, THREE ): proc = checkout_process( getpid(), READER ); assert( proc != NULL ); scp->rc = get_environment_size( current_process(), scp->name, &(scp->size) ); commit_process( proc ); break; case OP( ENV, FOUR ): proc = checkout_process( getpid(), READER ); assert( proc != NULL ); scp->rc = get_environment_information( current_process(), scp->id, scp->name, &(scp->size) ); commit_process( proc ); break; case OP( ENV, FIVE ): proc = checkout_process( getpid(), WRITER ); assert( proc != NULL ); scp->rc = remove_environment( current_process(), scp->name ); commit_process( proc ); break; } }
/* *=========================================================================== * ipcom_getenv *=========================================================================== * Description: * Parameters: * Returns: * */ IP_PUBLIC char * ipcom_getenv(const char *name) { #if IPCOM_USE_ENV == IPCOM_ENV_IPCOM Ip_err retval; Ipcom_proc *proc; Ipcom_env_entry *env; char *value = IP_NULL; proc = ipcom_proc_self(); ip_assert(proc != IP_NULL); retval = ipcom_once(&proc->env_once, ipcom_env_init, proc); if (retval != IPCOM_SUCCESS) { IP_PANIC(); return IP_NULL; } ipcom_mutex_lock(proc->env_mutex); env = ipcom_hash_get(proc->env_tree, name); if (env != IP_NULL) value = (char *)env->value; ipcom_mutex_unlock(proc->env_mutex); return value; #elif IPCOM_USE_ENV == IPCOM_ENV_NATIVE && (defined(IP_PORT_OSE) || defined(IP_PORT_OSE5)) char *env; static char buf[256]; env = get_env(current_process(), name); if (env != IP_NULL) { ipcom_strncpy(buf, env, sizeof(buf)); free_buf((union SIGNAL **)&env); return (char *)buf; } return IP_NULL; #elif IPCOM_USE_ENV == IPCOM_ENV_NATIVE return getenv(name); #elif defined(IPCOM_USE_SYSVAR) && IPCOM_VR_MAX == 1 static char buf[256]; Ip_size_t buf_size = sizeof(buf); return ipcom_sysvar_get(name, buf, &buf_size); #else return IP_NULL; #endif /* #if IPCOM_USE_ENV == IPCOM_ENV_IPCOM */ }
static struct raw_breakpoint * set_raw_breakpoint_at (CORE_ADDR where) { struct process_info *proc = current_process (); struct raw_breakpoint *bp; int err; unsigned char buf[MAX_BREAKPOINT_LEN]; if (breakpoint_data == NULL) error ("Target does not support breakpoints."); bp = find_raw_breakpoint_at (where); if (bp != NULL) { bp->refcount++; return bp; } bp = xcalloc (1, sizeof (*bp)); bp->pc = where; bp->refcount = 1; /* Note that there can be fast tracepoint jumps installed in the same memory range, so to get at the original memory, we need to use read_inferior_memory, which masks those out. */ err = read_inferior_memory (where, buf, breakpoint_len); if (err != 0) { if (debug_threads) fprintf (stderr, "Failed to read shadow memory of" " breakpoint at 0x%s (%s).\n", paddress (where), strerror (err)); free (bp); return NULL; } memcpy (bp->old_data, buf, breakpoint_len); err = (*the_target->write_memory) (where, breakpoint_data, breakpoint_len); if (err != 0) { if (debug_threads) fprintf (stderr, "Failed to insert breakpoint at 0x%s (%s).\n", paddress (where), strerror (err)); free (bp); return NULL; } /* Link the breakpoint in. */ bp->inserted = 1; bp->next = proc->raw_breakpoints; proc->raw_breakpoints = bp; return bp; }
static int find_one_thread (ptid_t ptid) { td_thrhandle_t th; td_thrinfo_t ti; td_err_e err; struct thread_info *inferior; struct lwp_info *lwp; struct thread_db *thread_db = current_process ()->priv->thread_db; int lwpid = ptid_get_lwp (ptid); inferior = (struct thread_info *) find_inferior_id (&all_threads, ptid); lwp = get_thread_lwp (inferior); if (lwp->thread_known) return 1; /* Get information about this thread. */ err = thread_db->td_ta_map_lwp2thr_p (thread_db->thread_agent, lwpid, &th); if (err != TD_OK) error ("Cannot get thread handle for LWP %d: %s", lwpid, thread_db_err_str (err)); err = thread_db->td_thr_get_info_p (&th, &ti); if (err != TD_OK) error ("Cannot get thread info for LWP %d: %s", lwpid, thread_db_err_str (err)); if (debug_threads) debug_printf ("Found thread %ld (LWP %d)\n", ti.ti_tid, ti.ti_lid); if (lwpid != ti.ti_lid) { warning ("PID mismatch! Expected %ld, got %ld", (long) lwpid, (long) ti.ti_lid); return 0; } if (thread_db_use_events) { err = thread_db->td_thr_event_enable_p (&th, 1); if (err != TD_OK) error ("Cannot enable thread event reporting for %d: %s", ti.ti_lid, thread_db_err_str (err)); } /* If the new thread ID is zero, a final thread ID will be available later. Do not enable thread debugging yet. */ if (ti.ti_tid == 0) return 0; lwp->thread_known = 1; lwp->th = th; return 1; }
int ethr_assert_failed(const char *file, int line, const char *func, char *a) { fprintf(stderr, "%s:%d: %s(): Assertion failed: %s\n", file, line, func, a); #ifdef __OSE__ ramlog_printf("%d: %s:%d: %s(): Assertion failed: %s\n", current_process(),file, line, func, a); #endif ethr_abort__(); return 0; }
void write_reg(int pid, int reg, int value, int type) { MKNode *lroot = root; while( ((Process *) lroot->value)-> pid != pid ) lroot = lroot->next; ((Process *) lroot->value)->shared_regs[reg] = value; ((Process *) lroot->value)->type[reg] = type; ((Process *) lroot->value)->genesis[reg] = current_process(); lroot = NULL; mkfree(lroot); }
void reinsert_all_breakpoints (void) { struct process_info *proc = current_process (); struct raw_breakpoint *bp; for (bp = proc->raw_breakpoints; bp != NULL; bp = bp->next) if (!bp->inserted) reinsert_raw_breakpoint (bp); }
static const struct regs_info * arm_regs_info (void) { const struct target_desc *tdesc = current_process ()->tdesc; if (have_ptrace_getregset == 1 && (tdesc == tdesc_arm_with_neon || tdesc == tdesc_arm_with_vfpv3)) return ®s_info_aarch32; else return ®s_info_arm; }
int read_reg(int reg) { int pid = current_process(); int r_reg; MKNode *lroot = root; while( ((Process *) lroot->value)-> pid != pid ) lroot = lroot->next; r_reg = ((Process *) lroot->value)->shared_regs[reg]; lroot = NULL; mkfree(lroot); return r_reg; }
int read_type(int reg) { int pid = current_process(); int r_type; MKNode *lroot = root; while( ((Process *) lroot->value)-> pid != pid ) lroot = lroot->next; r_type = ((Process *) lroot->value)->type[reg]; lroot = NULL; mkfree(lroot); return r_type; }
int read_genesis(int reg) { int pid = current_process(); int r_genesis; MKNode *lroot = root; while( ((Process *) lroot->value)-> pid != pid ) lroot = lroot->next; r_genesis = ((Process *) lroot->value)->genesis[reg]; lroot = NULL; mkfree(lroot); return r_genesis; }
struct breakpoint * find_gdb_breakpoint_at (CORE_ADDR where) { struct process_info *proc = current_process (); struct breakpoint *bp; for (bp = proc->breakpoints; bp != NULL; bp = bp->next) if (bp->type == gdb_breakpoint && bp->raw->pc == where) return bp; return NULL; }
static struct fast_tracepoint_jump * find_fast_tracepoint_jump_at (CORE_ADDR where) { struct process_info *proc = current_process (); struct fast_tracepoint_jump *jp; for (jp = proc->fast_tracepoint_jumps; jp != NULL; jp = jp->next) if (jp->pc == where) return jp; return NULL; }