Skip to content

Commit

Permalink
Migrate ReplayTask::cast_or_null to Task::as_replay.
Browse files Browse the repository at this point in the history
  • Loading branch information
khuey committed Apr 18, 2024
1 parent 6c7c961 commit 1883109
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/GdbServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ReplayCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 0 additions & 7 deletions src/ReplayTask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReplayTask*>(t);
}
return nullptr;
}

const ExtraRegisters& ReplayTask::extra_regs() {
if (!extra_regs_fallible()) {
ASSERT(this, false) << "Can't find task for infallible extra_regs";
Expand Down
2 changes: 0 additions & 2 deletions src/ReplayTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ class ReplayTask final : public Task {
return name_;
}

static ReplayTask* cast_or_null(Task* t);

private:
template <typename Arch> void init_buffers_arch();

Expand Down
6 changes: 3 additions & 3 deletions src/RerunCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>(regs.sp().as_int() & ~uintptr_t(0xf)) - 1;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down
9 changes: 8 additions & 1 deletion src/Task.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReplayTask*>(this);
}
return nullptr;
}

void Task::detach() {
LOG(debug) << "detaching from Task " << tid << " (rec:" << rec_tid << ")";

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class Task {
public:
typedef std::vector<WatchConfig> HardwareWatchpoints;

ReplayTask* as_replay();

/**
* Ptrace-detach the task.
*/
Expand Down

0 comments on commit 1883109

Please sign in to comment.