diff --git a/src/GdbServer.cc b/src/GdbServer.cc index f9dfb0a417b..19a7c687614 100644 --- a/src/GdbServer.cc +++ b/src/GdbServer.cc @@ -166,7 +166,7 @@ static WatchType watchpoint_type(GdbRequestType req) { } static void maybe_singlestep_for_event(Task* t, GdbRequest* req) { - ReplayTask* rt = ReplayTask::cast_or_null(t); + ReplayTask* rt = t->as_replay(); if (!rt) { return; } diff --git a/src/ReplayCommand.cc b/src/ReplayCommand.cc index b99eaff4367..7f05f1adca7 100644 --- a/src/ReplayCommand.cc +++ b/src/ReplayCommand.cc @@ -392,7 +392,7 @@ static void serve_replay_no_debugger(const string& trace_dir, replay_session->trace_reader().time() >= flags.singlestep_to_event) { cmd = RUN_SINGLESTEP; fputs("Stepping from: ", stderr); - ReplayTask* t = ReplayTask::cast_or_null(replay_session->current_task()); + ReplayTask* t = replay_session->current_task()->as_replay(); t->regs().print_register_file_compact(stderr); fputc(' ', stderr); t->extra_regs().print_register_file_compact(stderr); diff --git a/src/ReplayTask.cc b/src/ReplayTask.cc index 21c395fa64d..b6fb569f105 100644 --- a/src/ReplayTask.cc +++ b/src/ReplayTask.cc @@ -210,13 +210,6 @@ void ReplayTask::set_real_tid_and_update_serial(pid_t tid) { serial = session().next_task_serial(); } -/* static */ ReplayTask* ReplayTask::cast_or_null(Task* t) { - if (t->session().is_replaying() || t->session().is_diversion()) { - return static_cast(t); - } - return nullptr; -} - const ExtraRegisters& ReplayTask::extra_regs() { if (!extra_regs_fallible()) { ASSERT(this, false) << "Can't find task for infallible extra_regs"; diff --git a/src/ReplayTask.h b/src/ReplayTask.h index 16286479f76..b127a36be47 100644 --- a/src/ReplayTask.h +++ b/src/ReplayTask.h @@ -89,8 +89,6 @@ class ReplayTask final : public Task { return name_; } - static ReplayTask* cast_or_null(Task* t); - private: template void init_buffers_arch(); diff --git a/src/RerunCommand.cc b/src/RerunCommand.cc index 2c4e3d8130a..3412ac24af4 100644 --- a/src/RerunCommand.cc +++ b/src/RerunCommand.cc @@ -587,7 +587,7 @@ static const uint64_t sentinel_ret_address = 9; static void run_diversion_function(ReplaySession& replay, Task* task, const RerunFlags& flags) { DiversionSession::shr_ptr diversion_session = replay.clone_diversion(); - ReplayTask* t = ReplayTask::cast_or_null(diversion_session->find_task(task->tuid())); + ReplayTask* t = diversion_session->find_task(task->tuid())->as_replay(); Registers regs = t->regs(); // align stack auto sp = remote_ptr(regs.sp().as_int() & ~uintptr_t(0xf)) - 1; @@ -670,7 +670,7 @@ static int rerun(const string& trace_dir, const RerunFlags& flags, CommandForChe RunCommand cmd = RUN_CONTINUE; auto old_task_p = replay_session->current_task(); - ReplayTask* old_task = old_task_p ? ReplayTask::cast_or_null(old_task_p) : nullptr; + ReplayTask* old_task = old_task_p ? old_task_p->as_replay() : nullptr; auto old_task_tuid = old_task ? old_task->tuid() : TaskUid(); remote_code_ptr old_ip = old_task ? old_task->ip() : remote_code_ptr(); FrameTime before_time = replay_session->trace_reader().time(); @@ -704,7 +704,7 @@ static int rerun(const string& trace_dir, const RerunFlags& flags, CommandForChe // The old_task may have exited (and been deallocated) in the `replay_session->replay_step(cmd)` above. // So we need to try and obtain it from the session again to make sure it still exists. Task* old_task_p = old_task_tuid.tid() ? replay_session->find_task(old_task_tuid) : nullptr; - ReplayTask* old_task = old_task_p ? ReplayTask::cast_or_null(old_task_p) : nullptr; + ReplayTask* old_task = old_task_p ? old_task_p->as_replay() : nullptr; remote_code_ptr after_ip = old_task ? old_task->ip() : remote_code_ptr(); DEBUG_ASSERT(after_time >= before_time && after_time <= before_time + 1); diff --git a/src/Task.cc b/src/Task.cc index 0cfd104ebe7..8952929dc94 100644 --- a/src/Task.cc +++ b/src/Task.cc @@ -110,6 +110,13 @@ Task::Task(Session& session, pid_t _tid, pid_t _rec_tid, uint32_t serial, memset(&thread_locals, 0, sizeof(thread_locals)); } +ReplayTask* Task::as_replay() { + if (session().is_replaying() || session().is_diversion()) { + return static_cast(this); + } + return nullptr; +} + void Task::detach() { LOG(debug) << "detaching from Task " << tid << " (rec:" << rec_tid << ")"; @@ -2153,7 +2160,7 @@ static bool simulate_transient_error(Task* t) { static FrameTime simulate_error_at_event_ = simulate_error_at_event(); if (simulated_error || !t->session().is_replaying() || - ReplayTask::cast_or_null(t)->session().trace_stream()->time() < simulate_error_at_event_) { + t->as_replay()->session().trace_stream()->time() < simulate_error_at_event_) { return false; } simulated_error = true; diff --git a/src/Task.h b/src/Task.h index cc91b0cca81..0705cb98404 100644 --- a/src/Task.h +++ b/src/Task.h @@ -139,6 +139,8 @@ class Task { public: typedef std::vector HardwareWatchpoints; + ReplayTask* as_replay(); + /** * Ptrace-detach the task. */