static inline int proj_call_rule(Projectile *p, int t) { int result = ACTION_NONE; if(p->timeout > 0 && t >= p->timeout) { result = ACTION_DESTROY; } else if(p->rule != NULL) { result = p->rule(p, t); if(t < 0 && result != ACTION_ACK) { set_debug_info(&p->debug); log_fatal( "Projectile rule didn't acknowledge %s (returned %i, expected %i)", event_name(t), result, ACTION_ACK ); } } if(/*t == 0 ||*/ t == EVENT_BIRTH) { p->prevpos = p->pos; } if(t == 0) { spawn_bullet_spawning_effect(p); } return result; }
void unbindEvent(const std::type_info &event_class) { std::string event_name(event_class.name()); t_handlers_map::iterator found = allocatedHandlers.find(event_name); if(found != allocatedHandlers.end()) { delete found->second; allocatedHandlers.erase(event_name); } return; }
void BaseEventHandler::bind(const std::type_info &event_class) { std::string event_name(event_class.name()); t_handlers_map::iterator found = allocatedHandlers.find(event_name); if(found != allocatedHandlers.end()) { delete found->second; allocatedHandlers.erase(event_name); } allocatedHandlers.insert({ event_name, this }); return; }
const char * context_suspend_reason(Context * ctx) { static char reason[128]; if (EXT(ctx)->end_of_step) return REASON_STEP; if (EXT(ctx)->ptrace_event != 0) { assert(ctx->signal == SIGTRAP); snprintf(reason, sizeof(reason), "Event: %s", event_name(EXT(ctx)->ptrace_event)); return reason; } if (ctx->signal == SIGSTOP || ctx->signal == SIGTRAP) return REASON_USER_REQUEST; snprintf(reason, sizeof(reason), "Signal %d", ctx->signal); return reason; }
void rpl_event::printevent(FILE *out) { char b1[256]; struct tm tm1; struct timeval tmp_alarm_time = alarm_time; gmtime_r(&alarm_time.tv_sec, &tm1); strftime(b1, sizeof(b1), "%Y-%B-%d %r", &tm1); fprintf(out, "event#%u(%s) at (%s)<%u:%u>, type: %s", event_number, mReason, b1, tmp_alarm_time.tv_sec, tmp_alarm_time.tv_usec, event_name()); }
void handleEventWM(WPARAM wParam, LPARAM lParam) { BaseEvent *event = reinterpret_cast<BaseEvent *>(lParam); std::string event_name(typeid(*event).name()); t_handlers_map::iterator found = allocatedHandlers.find(event_name); if(found != allocatedHandlers.end()) { found->second->handleEvent(event); } allocatedEvents.erase(event); delete event; return; }
static int __cmd_evlist(void) { struct perf_session *session; struct perf_evsel *pos; session = perf_session__new(input_name, O_RDONLY, 0, false, NULL); if (session == NULL) return -ENOMEM; list_for_each_entry(pos, &session->evlist->entries, node) printf("%s\n", event_name(pos)); perf_session__delete(session); return 0; }
bool rpl_event::doit(void) { debug->log("invoked doit(%s) on rpl_event (if_name=%s)\n", event_name(), interface ? interface->get_if_name() : "none"); switch(event_type) { case rpl_send_dio: network_interface::send_dio_all(mDag); return true; case rpl_send_dao: if(mDag!=NULL) { debug->log("event send_dao to parent\n"); mDag->send_dao(); } return true; default: debug->log("invalid event %d\n", event_type); break; } return false; }
void JvmtiTrace::initialize() { if (_initialized) { return; } SafeResourceMark rm; const char *very_end; const char *curr; if (TraceJVMTI != NULL) { curr = TraceJVMTI; } else { curr = ""; // hack in fixed tracing here } very_end = curr + strlen(curr); while (curr < very_end) { const char *curr_end = strchr(curr, ','); if (curr_end == NULL) { curr_end = very_end; } const char *op_pos = strchr(curr, '+'); const char *minus_pos = strchr(curr, '-'); if (minus_pos != NULL && (minus_pos < op_pos || op_pos == NULL)) { op_pos = minus_pos; } char op; const char *flags = op_pos + 1; const char *flags_end = curr_end; if (op_pos == NULL || op_pos > curr_end) { flags = "ies"; flags_end = flags + strlen(flags); op_pos = curr_end; op = '+'; } else { op = *op_pos; } jbyte bits = 0; for (; flags < flags_end; ++flags) { switch (*flags) { case 'i': bits |= SHOW_IN; break; case 'I': bits |= SHOW_IN_DETAIL; break; case 'e': bits |= SHOW_ERROR; break; case 'o': bits |= SHOW_OUT; break; case 'O': bits |= SHOW_OUT_DETAIL; break; case 't': bits |= SHOW_EVENT_TRIGGER; break; case 's': bits |= SHOW_EVENT_SENT; break; default: tty->print_cr("Invalid trace flag '%c'", *flags); break; } } const int FUNC = 1; const int EXCLUDE = 2; const int ALL_FUNC = 4; const int EVENT = 8; const int ALL_EVENT = 16; int domain = 0; size_t len = op_pos - curr; if (op_pos == curr) { domain = ALL_FUNC | FUNC | ALL_EVENT | EVENT | EXCLUDE; } else if (len==3 && strncmp(curr, "all", 3)==0) { domain = ALL_FUNC | FUNC | ALL_EVENT | EVENT; } else if (len==7 && strncmp(curr, "allfunc", 7)==0) { domain = ALL_FUNC | FUNC; } else if (len==4 && strncmp(curr, "func", 4)==0) { domain = ALL_FUNC | FUNC | EXCLUDE; } else if (len==8 && strncmp(curr, "allevent", 8)==0) { domain = ALL_EVENT | EVENT; } else if (len==5 && strncmp(curr, "event", 5)==0) { domain = ALL_EVENT | EVENT; } else if (len==2 && strncmp(curr, "ec", 2)==0) { _trace_event_controller = true; tty->print_cr("JVMTI Tracing the event controller"); } else { domain = FUNC | EVENT; // go searching } int exclude_index = 0; if (domain & FUNC) { if (domain & ALL_FUNC) { if (domain & EXCLUDE) { tty->print("JVMTI Tracing all significant functions"); } else { tty->print_cr("JVMTI Tracing all functions"); } } for (int i = 0; i <= _max_function_index; ++i) { if (domain & EXCLUDE && i == _exclude_functions[exclude_index]) { ++exclude_index; } else { bool do_op = false; if (domain & ALL_FUNC) { do_op = true; } else { const char *fname = function_name(i); if (fname != NULL) { size_t fnlen = strlen(fname); if (len==fnlen && strncmp(curr, fname, fnlen)==0) { tty->print_cr("JVMTI Tracing the function: %s", fname); do_op = true; } } } if (do_op) { if (op == '+') { _trace_flags[i] |= bits; } else { _trace_flags[i] &= ~bits; } _on = true; } } } } if (domain & EVENT) { if (domain & ALL_EVENT) { tty->print_cr("JVMTI Tracing all events"); } for (int i = 0; i <= _max_event_index; ++i) { bool do_op = false; if (domain & ALL_EVENT) { do_op = true; } else { const char *ename = event_name(i); if (ename != NULL) { size_t evtlen = strlen(ename); if (len==evtlen && strncmp(curr, ename, evtlen)==0) { tty->print_cr("JVMTI Tracing the event: %s", ename); do_op = true; } } } if (do_op) { if (op == '+') { _event_trace_flags[i] |= bits; } else { _event_trace_flags[i] &= ~bits; } _on = true; } } } if (!_on && (domain & (FUNC|EVENT))) { tty->print_cr("JVMTI Trace domain not found"); } curr = curr_end + 1; } _initialized = true; }
bool BackupRestore::table(const TableS & table){ if (!m_restore && !m_restore_meta) return true; const char * name = table.getTableName(); /** * Ignore blob tables */ if(match_blob(name) >= 0) return true; const NdbTableImpl & tmptab = NdbTableImpl::getImpl(* table.m_dictTable); if ((int) tmptab.m_indexType != (int) NdbDictionary::Index::Undefined){ m_indexes.push_back(table.m_dictTable); return true; } BaseString tmp(name); Vector<BaseString> split; if(tmp.split(split, "/") != 3){ err << "Invalid table name format `" << name << "`" << endl; return false; } m_ndb->setDatabaseName(split[0].c_str()); m_ndb->setSchemaName(split[1].c_str()); NdbDictionary::Dictionary* dict = m_ndb->getDictionary(); if(m_restore_meta) { NdbDictionary::Table copy(*table.m_dictTable); copy.setName(split[2].c_str()); Uint32 id; if (copy.getTablespace(&id)) { debug << "Connecting " << name << " to tablespace oldid: " << id << flush; NdbDictionary::Tablespace* ts = m_tablespaces[id]; debug << " newid: " << ts->getObjectId() << endl; copy.setTablespace(* ts); } if (copy.getDefaultNoPartitionsFlag()) { /* Table was defined with default number of partitions. We can restore it with whatever is the default in this cluster. We use the max_rows parameter in calculating the default number. */ Uint32 no_nodes = m_cluster_connection->no_db_nodes(); copy.setFragmentCount(get_no_fragments(copy.getMaxRows(), no_nodes)); set_default_nodegroups(©); } else { /* Table was defined with specific number of partitions. It should be restored with the same number of partitions. It will either be restored in the same node groups as when backup was taken or by using a node group map supplied to the ndb_restore program. */ Uint16 *ng_array = (Uint16*)copy.getFragmentData(); Uint16 no_parts = copy.getFragmentCount(); if (map_nodegroups(ng_array, no_parts)) { if (translate_frm(©)) { err << "Create table " << table.getTableName() << " failed: "; err << "Translate frm error" << endl; return false; } } copy.setFragmentData((const void *)ng_array, no_parts << 1); } /** * Force of varpart was introduced in 5.1.18, telco 6.1.7 and 6.2.1 * Since default from mysqld is to add force of varpart (disable with * ROW_FORMAT=FIXED) we force varpart onto tables when they are restored * from backups taken with older versions. This will be wrong if * ROW_FORMAT=FIXED was used on original table, however the likelyhood of * this is low, since ROW_FORMAT= was a NOOP in older versions. */ if (table.getBackupVersion() < MAKE_VERSION(5,1,18)) copy.setForceVarPart(true); else if (getMajor(table.getBackupVersion()) == 6 && (table.getBackupVersion() < MAKE_VERSION(6,1,7) || table.getBackupVersion() == MAKE_VERSION(6,2,0))) copy.setForceVarPart(true); /* update min and max rows to reflect the table, this to ensure that memory is allocated properly in the ndb kernel */ copy.setMinRows(table.getNoOfRecords()); if (table.getNoOfRecords() > copy.getMaxRows()) { copy.setMaxRows(table.getNoOfRecords()); } NdbTableImpl &tableImpl = NdbTableImpl::getImpl(copy); if (table.getBackupVersion() < MAKE_VERSION(5,1,0) && !m_no_upgrade){ for(int i= 0; i < copy.getNoOfColumns(); i++) { NdbDictionary::Column::Type t = copy.getColumn(i)->getType(); if (t == NdbDictionary::Column::Varchar || t == NdbDictionary::Column::Varbinary) tableImpl.getColumn(i)->setArrayType(NdbDictionary::Column::ArrayTypeShortVar); if (t == NdbDictionary::Column::Longvarchar || t == NdbDictionary::Column::Longvarbinary) tableImpl.getColumn(i)->setArrayType(NdbDictionary::Column::ArrayTypeMediumVar); } } if (dict->createTable(copy) == -1) { err << "Create table `" << table.getTableName() << "` failed: " << dict->getNdbError() << endl; if (dict->getNdbError().code == 771) { /* The user on the cluster where the backup was created had specified specific node groups for partitions. Some of these node groups didn't exist on this cluster. We will warn the user of this and inform him of his option. */ err << "The node groups defined in the table didn't exist in this"; err << " cluster." << endl << "There is an option to use the"; err << " the parameter ndb-nodegroup-map to define a mapping from"; err << endl << "the old nodegroups to new nodegroups" << endl; } return false; } info << "Successfully restored table `" << table.getTableName() << "`" << endl; } const NdbDictionary::Table* tab = dict->getTable(split[2].c_str()); if(tab == 0){ err << "Unable to find table: `" << split[2].c_str() << "`" << endl; return false; } if(m_restore_meta) { if (tab->getFrmData()) { // a MySQL Server table is restored, thus an event should be created BaseString event_name("REPL$"); event_name.append(split[0].c_str()); event_name.append("/"); event_name.append(split[2].c_str()); NdbDictionary::Event my_event(event_name.c_str()); my_event.setTable(*tab); my_event.addTableEvent(NdbDictionary::Event::TE_ALL); // add all columns to the event bool has_blobs = false; for(int a= 0; a < tab->getNoOfColumns(); a++) { my_event.addEventColumn(a); NdbDictionary::Column::Type t = tab->getColumn(a)->getType(); if (t == NdbDictionary::Column::Blob || t == NdbDictionary::Column::Text) has_blobs = true; } if (has_blobs) my_event.mergeEvents(true); while ( dict->createEvent(my_event) ) // Add event to database { if (dict->getNdbError().classification == NdbError::SchemaObjectExists) { info << "Event for table " << table.getTableName() << " already exists, removing.\n"; if (!dict->dropEvent(my_event.getName())) continue; } err << "Create table event for " << table.getTableName() << " failed: " << dict->getNdbError() << endl; dict->dropTable(split[2].c_str()); return false; } info << "Successfully restored table event " << event_name << endl ; } } const NdbDictionary::Table* null = 0; m_new_tables.fill(table.m_dictTable->getTableId(), null); m_new_tables[table.m_dictTable->getTableId()] = tab; return true; }
void alert_callback(user_t * receiver, event_t * event) { printf("User: %s\n\tReceived massage from: %s\n\n", user_username(receiver), event_name(event)); }
int sandbox_excute(sandbox_t *psbox) { pid_t child; child = fork(); if(child < 0) { psbox->result = INTERNAL_ERROR; __TRACE_LN(__TRACE_KEY, "Error : fork target process failed"); return -1; } else if(child == 0) { _exit(_sandbox_excute(&psbox->task)); } else { __TRACE_LN(__TRACE_DBG, "child pid : %d", child); pid_t wait_result = 0; int wait_status = 0; proc_t proc_data = { 0 }; int in_syscall = 1; event_t e = { 0 }; action_t action = { 0 }; /* Have signals kill the prisoner but not self (if possible). */ /* In fact, I have deleted the '-' before "child" so this may not be necessary */ sig_t terminate_signal; sig_t interrupt_signal; sig_t quit_signal; terminate_signal = signal(SIGTERM, SIG_IGN); interrupt_signal = signal(SIGINT, SIG_IGN); quit_signal = signal(SIGQUIT, SIG_IGN); /* Get wallclock start time */ gettimeofday(&psbox->stat.start_timestamp, NULL); /* get initial resource usage */ wait_result = wait4(child, &wait_status, 0, &psbox->stat.ru); memcpy(&psbox->stat.init_ru, &psbox->stat.ru, sizeof(struct rusage)); /* trace loop */ __TRACE_LN(__TRACE_DBG, "Enter trace loop"); bool internal_error = false; do{ if(!wait_result) /* wait_result == 0 : noting happent */ { goto cont; } memset(&e, 0, sizeof(event_t)); memset(&action, 0, sizeof(action_t)); if(WIFSTOPPED(wait_status)) { switch(WSTOPSIG(wait_status)) { case SIGALRM: POST_EVENT(e, EVENT_QUOTA, QUOTA_WALLCLOCK); break; case SIGXCPU: case SIGPROF: case SIGVTALRM: POST_EVENT(e, EVENT_QUOTA, QUOTA_CPUTIME); break; case SIGML: POST_EVENT(e, EVENT_QUOTA, QUOTA_MEMORY); break; case SIGXFSZ: POST_EVENT(e, EVENT_QUOTA, QUOTA_OUTPUT); break; case SIGTRAP: if(!proc_probe(child, &proc_data)) { /* error */ internal_error = true; psbox->result = INTERNAL_ERROR; kill(child, SIGKILL); __TRACE_LN(__TRACE_KEY, "Internal Error : porc_probe() failed"); break; } if(psbox->stat.vsize_peak < proc_data.vsize) { psbox->stat.vsize_peak = proc_data.vsize; if(psbox->stat.vsize_peak > psbox->task.quota[QUOTA_MEMORY]) { kill(child, SIGML); } } /* system call or system call return */ if(in_syscall) { in_syscall = 0; POST_EVENT(e, EVENT_SYSTEM_CALL_RETURN, SYSCALL_NO(&proc_data), SYSCALL_RETVAL(&proc_data)); } else { in_syscall = 1; POST_EVENT(e, EVENT_SYSTEM_CALL, SYSCALL_NO(&proc_data), SYSCALL_ARG1(&proc_data), SYSCALL_ARG2(&proc_data), SYSCALL_ARG3(&proc_data), SYSCALL_ARG4(&proc_data), SYSCALL_ARG5(&proc_data)); } break; default: POST_EVENT(e, EVENT_SIGNAL, WSTOPSIG(wait_status)); } } else if(WIFSIGNALED(wait_status)) { POST_EVENT(e, EVENT_SIGNAL, WTERMSIG(wait_status)); } else if(WIFEXITED(wait_status)) { psbox->stat.data.exitcode = WEXITSTATUS(wait_status); POST_EVENT(e, EVENT_EXIT, WEXITSTATUS(wait_status)); } /* sink event */ psbox->policy(&e, &action); __TRACE(__TRACE_DBG, "Event type : %s", event_name(e.type)); __TRACE_LN(__TRACE_DBG, "\tEvent data : %ld %ld %ld %ld %ld %ld", e.data._bitmap_.a, e.data._bitmap_.b, e.data._bitmap_.c, e.data._bitmap_.d, e.data._bitmap_.e, e.data._bitmap_.f); __TRACE(__TRACE_DBG, "Action type : %s", action_name(action.type)); __TRACE_LN(__TRACE_DBG, "\tAction data : %ld %ld", action.data._bitmap_.a, action.data._bitmap_.b); /* action */ switch(action.type) { case ACTION_CONTINUE: if(!trace_next(&proc_data)) { internal_error = true; psbox->result = INTERNAL_ERROR; kill(child, SIGKILL); __TRACE_LN(__TRACE_KEY, "Internal Error : trace_next() failed"); break; } goto cont; case ACTION_KILL: trace_kill(&proc_data, 0); psbox->result = action.data._kill.result; if(psbox->result == RUNTIME_ERROR) { psbox->stat.data.signo = action.data._kill.data; } else if(psbox->result == RESTRICTED_FUNCTION) { psbox->stat.data.rf = action.data._kill.data; } kill(child, SIGKILL); break; case ACTION_EXIT: psbox->stat.data.exitcode = action.data._exit.code; if(psbox->stat.data.exitcode) { __TRACE_LN(__TRACE_DBG, "exit code : %ld", psbox->stat.data.exitcode); psbox->result = ABNORMAL_TERMINATION; } /* else { psbox->result = PENDED; } */ break; } break; cont: /* trace infomation */ __TRACE_LN(__TRACE_DBG, "----------------------wait4()----------------------"); }while(!internal_error && (wait_result = wait4(child, &wait_status, 0, &psbox->stat.ru)) >= 0); /* if the sandbox's result is PENDED, the prisoned process is exited nomally */ /* Get wallclock stop time (call a second time to compensate overhead) */ gettimeofday(&psbox->stat.end_timestamp, NULL); /* Restore signal handlers */ signal(SIGTERM, interrupt_signal); signal(SIGINT, interrupt_signal); signal(SIGQUIT, quit_signal); } return 0; }
size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size) { float samples_per_sec = top->samples / top->delay_secs; float ksamples_per_sec = top->kernel_samples / top->delay_secs; float esamples_percent = (100.0 * top->exact_samples) / top->samples; size_t ret = 0; if (!perf_guest) { ret = SNPRINTF(bf, size, " PerfTop:%8.0f irqs/sec kernel:%4.1f%%" " exact: %4.1f%% [", samples_per_sec, 100.0 - (100.0 * ((samples_per_sec - ksamples_per_sec) / samples_per_sec)), esamples_percent); } else { float us_samples_per_sec = top->us_samples / top->delay_secs; float guest_kernel_samples_per_sec = top->guest_kernel_samples / top->delay_secs; float guest_us_samples_per_sec = top->guest_us_samples / top->delay_secs; ret = SNPRINTF(bf, size, " PerfTop:%8.0f irqs/sec kernel:%4.1f%% us:%4.1f%%" " guest kernel:%4.1f%% guest us:%4.1f%%" " exact: %4.1f%% [", samples_per_sec, 100.0 - (100.0 * ((samples_per_sec - ksamples_per_sec) / samples_per_sec)), 100.0 - (100.0 * ((samples_per_sec - us_samples_per_sec) / samples_per_sec)), 100.0 - (100.0 * ((samples_per_sec - guest_kernel_samples_per_sec) / samples_per_sec)), 100.0 - (100.0 * ((samples_per_sec - guest_us_samples_per_sec) / samples_per_sec)), esamples_percent); } if (top->evlist->nr_entries == 1) { struct perf_evsel *first; first = list_entry(top->evlist->entries.next, struct perf_evsel, node); ret += SNPRINTF(bf + ret, size - ret, "%" PRIu64 "%s ", (uint64_t)first->attr.sample_period, top->freq ? "Hz" : ""); } ret += SNPRINTF(bf + ret, size - ret, "%s", event_name(top->sym_evsel)); ret += SNPRINTF(bf + ret, size - ret, "], "); if (top->target_pid != -1) ret += SNPRINTF(bf + ret, size - ret, " (target_pid: %d", top->target_pid); else if (top->target_tid != -1) ret += SNPRINTF(bf + ret, size - ret, " (target_tid: %d", top->target_tid); else ret += SNPRINTF(bf + ret, size - ret, " (all"); if (top->cpu_list) ret += SNPRINTF(bf + ret, size - ret, ", CPU%s: %s)", top->evlist->cpus->nr > 1 ? "s" : "", top->cpu_list); else { if (top->target_tid != -1) ret += SNPRINTF(bf + ret, size - ret, ")"); else ret += SNPRINTF(bf + ret, size - ret, ", %d CPU%s)", top->evlist->cpus->nr, top->evlist->cpus->nr > 1 ? "s" : ""); } return ret; }
int main(int argc, char*argv[]) { initialize(); // SECTION I: SETUP memset(state_list, 0, MAX_EVENTS*sizeof(int)); // The log we want to read if (argc != 3) { usage(); exit(1); } char* input_log = argv[1]; if (input_log == NULL || strlen(input_log) == 0) { printf("Not given: input log (in clog format)\n"); exit(1); } int n = sscanf(argv[2], "%i", &mpi_rank); if (n != 1) { printf("Not given: MPI rank!\n"); exit(1); } timeline[0].timestamp = 0; timeline[0].completions = 0; current++; // SECTION II: READ DEFINITIONS bool success = read_defns(input_log); assert(success); int e1, e2; event_name("ADLB_Finalize", &e1, &e2); ADLB_Finalize_ID = min_integer(e1,e2); // printf("ADLB_Finalize_ID: %i\n", ADLB_Finalize_ID); state_list_init(); // SECTION III: READ EVENTS char buffer[MAX_LINE]; FILE* f = fopen(input_log, "r"); line_number = 0; while (fgets(buffer, MAX_LINE, f) != NULL) { line_number++; chomp(buffer); process_line(buffer); } fclose(f); // SECTION V: OUTPUT for (int i = 0; i < current; i++) { printf("%0.6f %i\n", timeline[i].timestamp, timeline[i].completions); } return 0; }
static void event_pid_stopped(pid_t pid, int signal, int event, int syscall) { int stopped_by_exception = 0; Context * ctx = NULL; trace(LOG_EVENTS, "event: pid %d stopped, signal %d, event %s", pid, signal, event_name(event)); ctx = context_find_from_pid(pid, 1); if (ctx == NULL) { ctx = find_pending(pid); if (ctx != NULL) { Context * prs = ctx; assert(prs->ref_count == 0); ctx = create_context(pid2id(pid, pid)); EXT(ctx)->pid = pid; EXT(ctx)->regs = (REG_SET *)loc_alloc(sizeof(REG_SET)); ctx->pending_intercept = 1; ctx->mem = prs; ctx->parent = prs; ctx->big_endian = prs->big_endian; prs->ref_count++; list_add_last(&ctx->cldl, &prs->children); link_context(prs); link_context(ctx); send_context_created_event(prs); send_context_created_event(ctx); if (EXT(prs)->attach_callback) { EXT(prs)->attach_callback(0, prs, EXT(prs)->attach_data); EXT(prs)->attach_callback = NULL; EXT(prs)->attach_data = NULL; } } } if (ctx == NULL) return; assert(!ctx->exited); assert(!EXT(ctx)->attach_callback); if (signal != SIGSTOP && signal != SIGTRAP) { assert(signal < 32); ctx->pending_signals |= 1 << signal; if ((ctx->sig_dont_stop & (1 << signal)) == 0) { ctx->pending_intercept = 1; stopped_by_exception = 1; } } if (ctx->stopped) { send_context_changed_event(ctx); } else { ContextAddress pc0 = 0; ContextAddress pc1 = 0; assert(!EXT(ctx)->regs_dirty); EXT(ctx)->end_of_step = 0; EXT(ctx)->ptrace_event = event; ctx->signal = signal; ctx->stopped_by_bp = 0; ctx->stopped_by_exception = stopped_by_exception; ctx->stopped = 1; if (EXT(ctx)->regs_error) { release_error_report(EXT(ctx)->regs_error); EXT(ctx)->regs_error = NULL; } else { pc0 = get_regs_PC(ctx); } if (ptrace(PTRACE_GETREGS, EXT(ctx)->pid, 0, (int)EXT(ctx)->regs) < 0) { assert(errno != 0); if (errno == ESRCH) { /* Racing condition: somebody resumed this context while we are handling stop event. * * One possible cause: main thread has exited forcing children to exit too. * I beleive it is a bug in PTRACE implementation - PTRACE should delay exiting of * a context while it is stopped, but it does not, which causes a nasty racing. * * Workaround: Ignore current event, assume context is running. */ ctx->stopped = 0; return; } EXT(ctx)->regs_error = get_error_report(errno); trace(LOG_ALWAYS, "error: ptrace(PTRACE_GETREGS) failed; id %s, error %d %s", ctx->id, errno, errno_to_str(errno)); } else { pc1 = get_regs_PC(ctx); } trace(LOG_EVENTS, "event: pid %d stopped at PC = %#lx", pid, pc1); if (signal == SIGTRAP && event == 0 && !syscall) { size_t break_size = 0; get_break_instruction(ctx, &break_size); ctx->stopped_by_bp = !EXT(ctx)->regs_error && is_breakpoint_address(ctx, pc1 - break_size); EXT(ctx)->end_of_step = !ctx->stopped_by_bp && EXT(ctx)->pending_step; if (ctx->stopped_by_bp) set_regs_PC(ctx, pc1 - break_size); } EXT(ctx)->pending_step = 0; send_context_stopped_event(ctx); } }
void handle_event(XEvent *ev) { client *c = owner(ev->xany.window); #ifdef DEBUG_EVENTS if(ev->type != Expose && ev->type != MotionNotify && !(ev->type == ConfigureNotify && ev->xconfigure.window != root)) /* this makes the output slightly more manageable */ printf(NAME ": handle_event(): got %s\n\twindow: 0x%X (%s)\n", event_name(ev), (unsigned int) ev->xany.window, c ? c->name : ((ev->xany.window == root) ? "root" : "unknown")); #endif if((evh && evh(ev)) || button_handle_event(ev) || ewmh_handle_event(ev) || screens_handle_event(ev)) { #ifdef DEBUG_EVENTS if(ev->type != Expose && ev->type != MotionNotify && (ev->type != ConfigureNotify && ev->xconfigure.window != root)) printf(NAME ": handle_event(): external event handler claimed last event\n"); #endif return; } if(c) { if(!has_child(c->parent, c->window) && ev->type != DestroyNotify && ev->type != UnmapNotify) return; switch(ev->type) { case UnmapNotify: if(c->window == ev->xunmap.window) { #ifdef DEBUG_EVENTS printf(NAME ": handle_event(): handling UnmapNotify event\n\twindow: 0x%X (%s)\n", (unsigned int) c->window, c->name); #endif if(has_child(c->parent, c->window)) { client_deparent(c); set_wm_state(c->window, WithdrawnState); } client_remove(c); ewmh_update_clist(); } return; case PropertyNotify: if(ev->xproperty.atom == XA_WM_NAME) { #ifdef DEBUG_EVENTS printf(NAME ": handle_event(): handling PropertyNotify event\n\twindow: 0x%X (%s)\n\tproperty: XA_WM_NAME\n", (unsigned int) c->window, c->name); #endif if(c->name != no_title) XFree(c->name); #ifdef USE_XFT if(xftfont) XftDrawDestroy(c->title_draw); #endif XFreePixmap(dpy, c->title_pixmap); XFetchName(dpy, c->window, &c->name); client_update_name(c); XClearWindow(dpy, c->title); if(evh == wlist_handle_event) { XClearWindow(dpy, c->wlist_item); wlist_item_draw(c); } } if(ev->xproperty.atom == XA_WM_NORMAL_HINTS) { #ifdef DEBUG_EVENTS printf(NAME ": handle_event(): handling PropertyNotify event\n\twindow: 0x%X (%s)\n\tproperty: XA_WM_NORMAL_HINTS\n", (unsigned int) c->window, c->name); #endif get_normal_hints(c); } return; case ClientMessage: if(ev->xclient.message_type == xa_wm_change_state && ev->xclient.data.l[0] == IconicState) { #ifdef DEBUG_EVENTS printf(NAME ": handling ClientMessage event\n\twindow: 0x%X (%s)\n", (unsigned int) c->window, c->name); #endif client_iconify(c); return; } break; /* we might later need this event */ case EnterNotify: if(c != current && !(c->flags & CLICK_FOCUS) && !click_focus && ev->xcrossing.mode != NotifyGrab && ev->xcrossing.mode != NotifyUngrab && ev->xcrossing.detail != NotifyInferior && (ev->xcrossing.window == c->parent || ev->xcrossing.window == c->wlist_item) && ev->xcrossing.send_event == False) { #ifdef DEBUG_EVENTS printf(NAME ": handle_event(): handling EnterNotify event\n\twindow: 0x%X (%s)\n", (unsigned int) c->window, c->name); #endif client_focus(c, true); } return; case Expose: if(ev->xexpose.count == 0 && evh == wlist_handle_event && c && ev->xexpose.window == c->wlist_item) wlist_item_draw(c); return; case ButtonPress: #ifdef DEBUG_EVENTS printf(NAME ": handle_event(): handling ButtonPress event\n\twindow: 0x%X (%s)\n", (unsigned int) c->window, c->name); #endif if(c != current) client_focus(c, true); XAllowEvents(dpy, ReplayPointer, CurrentTime); if(ev->xbutton.window != c->window) { if(lastclick + doubleclick_time > ev->xbutton.time && lastbutton == ev->xbutton.button && lastclick_client == c) { client_action(c, buttonaction(ev->xbutton.button, true), ev); lastclick = 0; lastclick_client = NULL; lastbutton = None; return; } lastclick = ev->xbutton.time; lastclick_client = c; lastbutton = ev->xbutton.button; client_action(c, buttonaction(ev->xbutton.button, false), ev); } else if(click_raise) client_raise(c); return; case FocusIn: /* we ignore pointer events, these happen if the input focus is on the root window */ if(allow_focus_stealing && c != current && ev->xfocus.mode != NotifyGrab && ev->xfocus.mode != NotifyUngrab && ev->xfocus.detail != NotifyPointer) { #ifdef DEBUG_EVENTS printf(NAME ": handle_event(): handling FocusIn event\n\twindow: 0x%X (%s)\n", (unsigned int) c->window, c->name); #endif client_focus(c, false); } return; case FocusOut: if(c == current && ev->xfocus.mode != NotifyGrab && ev->xfocus.mode != NotifyUngrab && ev->xfocus.detail != NotifyInferior) { #ifdef DEBUG_EVENTS printf(NAME ": handle_event(): handling FocusOut event\n\twindow: 0x%X (%s)\n", (unsigned int) c->window, c->name); #endif if(allow_focus_stealing && ev->xfocus.detail != NotifyAncestor) { #ifdef DEBUG_EVENTS printf("\tfocus lost\n"); #endif client_focus(NULL, false); /* we do this so windows that aren't managed can take focus */ } else { #ifdef DEBUG_EVENTS printf("\tre-focussing this window\n"); #endif take_focus(c); } } return; #ifdef USE_SHAPE default: if(ev->type == shape_event) { #ifdef DEBUG_EVENTS printf(NAME ": handle_event(): handling ShapeNotify event\n\twindow 0x%X (%s)\n", (unsigned int) c->window, c->name); #endif set_shape(c); return; } #endif } } switch(ev->type) { case MapRequest: c = owner(ev->xmaprequest.window); #ifdef DEBUG_EVENTS printf(NAME ": handle_event(): handling MapRequest event\n\twindow: 0x%X (%s)\n", (unsigned int) ev->xmaprequest.window, c ? c->name : "unknown"); #endif if(c) { if(c->flags & ICONIC && has_child(c->parent, c->window)) { client_restore(c); if(focus_new) client_focus(c, true); } } else if(has_child(root, ev->xmaprequest.window)) client_add(ev->xmaprequest.window, false); return; case DestroyNotify: c = owner(ev->xdestroywindow.window); if(c) if(c->window == ev->xdestroywindow.window) { #ifdef DEBUG_EVENTS printf(NAME ": handle_event(): handling DestroyNotify event\n\twindow 0x%X (%s)\n", (unsigned int) c->window, c->name); #endif client_remove(c); } return; case ConfigureRequest: c = owner(ev->xconfigurerequest.window); #ifdef DEBUG_EVENTS printf(NAME ": handle_event(): handling ConfigureRequest event\n\twindow 0x%X (%s)\n", (unsigned int) ev->xconfigurerequest.window, c ? c->name : "unknown"); #endif if(correct_center) screens_correct_center(&ev->xconfigurerequest.x, &ev->xconfigurerequest.y, &ev->xconfigurerequest.width, &ev->xconfigurerequest.height); if(c) { if(!has_child(c->parent, c->window)) return; if(ev->xconfigurerequest.value_mask & CWX) c->x = ev->xconfigurerequest.x - gxo(c, false); if(ev->xconfigurerequest.value_mask & CWY) c->y = ev->xconfigurerequest.y - gyo(c, false); if(ev->xconfigurerequest.value_mask & CWWidth) c->width = ev->xconfigurerequest.width; if(ev->xconfigurerequest.value_mask & CWHeight) c->height = ev->xconfigurerequest.height; client_update(c); #ifdef DEBUG printf(NAME ": handle_event(): reconfigured client 0x%X (%s) to %ix%i+%i+%i\n", (unsigned int) c->window, c->name, c->width, c->height, c->x, c->y); #endif } else if(has_child(root, ev->xconfigurerequest.window)) { XWindowChanges wc; wc.sibling = ev->xconfigurerequest.above; wc.stack_mode = ev->xconfigurerequest.detail; wc.x = ev->xconfigurerequest.x; wc.y = ev->xconfigurerequest.y; wc.width = ev->xconfigurerequest.width; wc.height = ev->xconfigurerequest.height; XConfigureWindow(dpy, ev->xconfigurerequest.window, ev->xconfigurerequest.value_mask, &wc); } return; case MapNotify: if(correct_center_unmanaged && ev->xany.window == root && !owner(ev->xmap.window)) { #ifdef DEBUG_EVENTS printf(NAME ": handle_event(): handling MapNotify event\n\twindow 0x%X (unknown)\n", (unsigned int) ev->xmap.window); #endif window_correct_center(ev->xmap.window); } return; case MappingNotify: if(ev->xmapping.request != MappingPointer) { #ifdef DEBUG_EVENTS printf(NAME ": handle_event(): handling MappingNotify event\n"); #endif keys_ungrab(); XRefreshKeyboardMapping(&ev->xmapping); keys_update(); } return; case KeyPress: #ifdef DEBUG_EVENTS printf(NAME ": handle_event(): handling KeyPress event\n"); #endif client_action(current, keyaction(ev), ev); return; case ButtonPress: if(ev->xbutton.window != root) return; #ifdef DEBUG_EVENTS printf(NAME ": handle_event(): handling ButtonPress event\n"); #endif if(lastclick + doubleclick_time > ev->xbutton.time && lastbutton == ev->xbutton.button && lastclick_client == NULL) { client_action(current, root_buttonaction(ev->xbutton.button, true), ev); lastclick = 0; lastclick_client = NULL; lastbutton = None; return; } lastclick = ev->xbutton.time; lastclick_client = NULL; lastbutton = ev->xbutton.button; client_action(current, root_buttonaction(ev->xbutton.button, false), ev); return; case ClientMessage: if(ev->xclient.message_type == xa_internal_message) { if(((Atom) ev->xclient.data.l[0]) == xa_quit) { #ifdef DEBUG printf(NAME ": handle_event(): quit message received\n"); #endif exit(0); } if(((Atom) ev->xclient.data.l[0]) == xa_reinit) { #ifdef DEBUG printf(NAME ": handle_event(): reinitialize message received\n"); #endif cfg_reinitialize(); } } } }