int tracer(pid_t child, int printSystemCalls, int stopAfterEachCall, int sort){ changeBehaviour(); int status; ptrace(PTRACE_SETOPTIONS, child, 0, PTRACE_O_TRACESYSGOOD); int firstCall = 1; while(1){ waitpid(child, &status, 0); if(WIFEXITED(status)) break; if(firstCall){ struct user_regs_struct regs; ptrace(PTRACE_GETREGS, child, NULL, ®s); int syscall = regs.orig_rax; int retVal = regs.rax; countBySystemCall[syscall].count++; countBySystemCall[syscall].syscall = syscall; if(printSystemCalls){ printSysCall(child, retVal, regs); if(stopAfterEachCall){ pauseProgramAnyKey(); } } firstCall = 0; }else{ firstCall = 1; } ptrace(PTRACE_SYSCALL, child, NULL, NULL); } fprintf(stderr, "exit_group(0) = ?\n"); int x; if(sort){ qsort(countBySystemCall, 500, sizeof(struct counter), cmpfunc); } fprintf(stderr, "\n---------------%s---------------\n", "Accumulative Table"); fprintf(stderr, "------------------------------------------------\n\n"); fprintf(stderr, "%15s %15s\n", "Syscall", "calls"); for(x = 0; x < 500; x++){ if(countBySystemCall[x].count){ int syscall = countBySystemCall[x].syscall; fprintf(stderr, "%15s %15d\n", callname(syscall), countBySystemCall[x].count); } } fprintf(stderr, "\n------------------------------------------------\n\n"); restartBehaviour(); }
/*! @brief Updates the many button related variables */ void BehaviourProvider::updateButtonValues() { m_chest_previous_state = m_chest_state; m_left_previous_state = m_left_state; m_right_previous_state = m_right_state; // Get the button state values m_data->getButton(NUSensorsData::MainButton, m_chest_state); m_data->getButton(NUSensorsData::LeftButton, m_left_state); m_data->getButton(NUSensorsData::RightButton, m_right_state); // update the circular buffers on negative edges if (m_chest_state < m_chest_previous_state) { m_chest_times.push_back(m_current_time); float chest_duration; if (m_data->getButtonDuration(NUSensorsData::MainButton, chest_duration)) m_chest_durations.push_back(chest_duration); } if (m_left_state < m_left_previous_state) { m_left_times.push_back(m_current_time); float left_duration; if (m_data->getButtonDuration(NUSensorsData::LeftButton, left_duration)) m_left_durations.push_back(left_duration); } if (m_right_state < m_right_previous_state) { m_right_times.push_back(m_current_time); float right_duration; if (m_data->getButtonDuration(NUSensorsData::RightButton, right_duration)) m_right_durations.push_back(right_duration); } // A double chest click always starts saving images not matter which behaviour //if (doubleChestClick()) if(singleLeftBumperClick()) { m_saving_images = not m_saving_images; m_jobs->addVisionJob(new SaveImagesJob(m_saving_images, false)); } // A triple chest click always removes the stiffness if (tripleChestClick()) removeStiffness(); // A quad chect click always restarts behaviour if (quadChestClick()) restartBehaviour(); }