Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed the bug where continue backwards did nothing. #15

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions ttddbg/include/ttddbg_debugger_manager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ namespace ttddbg
};

protected:
/*!
* \brief maximum steps to simulate backward or forward continuation
*/
static const int m_maxSteps = -2;

/*!
* \brief Current debugger architecture
Expand Down Expand Up @@ -93,13 +97,6 @@ namespace ttddbg
*/
TTD::Position m_nextPosition;

/*!
* \brief Flag holding whether the "next action" should be a Backwards Single Step. If "true",
* instead of doing the normal action, force the TTD engine to go back in time for a single
* instruction. Then, set to "false".
*/
bool m_backwardsSingleStep;

/*!
* \brief Fake process id
*/
Expand Down Expand Up @@ -272,11 +269,6 @@ namespace ttddbg
*/
void requestFullRun() override;

/*!
* \brief Request a single step debugging but in backward way !
*/
void requestBackwardsSingleStep() override;

/*!
* \brief Open the timeline
*/
Expand Down
1 change: 0 additions & 1 deletion ttddbg/include/ttddbg_debugger_manager_interface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ namespace ttddbg

virtual void switchWay() = 0;
virtual void requestFullRun() = 0;
virtual void requestBackwardsSingleStep() = 0;
virtual void openPositionChooser() = 0;
virtual void openTraceChooser() = 0;
virtual void openTraceEventsChooser() = 0;
Expand Down
7 changes: 5 additions & 2 deletions ttddbg/src/ttddbg_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace ttddbg
if (dbg != nullptr)
{
static_cast<ttddbg::Debugger*>(dbg)->getManager().switchWay();
static_cast<ttddbg::Debugger*>(dbg)->getManager().onSetResumeMode(0, resume_mode_t::RESMOD_NONE);
continue_process();
static_cast<ttddbg::Debugger*>(dbg)->getManager().switchWay();
}
Expand All @@ -27,8 +28,10 @@ namespace ttddbg
{
if (dbg != nullptr)
{
static_cast<ttddbg::Debugger*>(dbg)->getManager().requestBackwardsSingleStep();
continue_process();
static_cast<ttddbg::Debugger*>(dbg)->getManager().switchWay();
static_cast<ttddbg::Debugger*>(dbg)->getManager().onSetResumeMode(0, resume_mode_t::RESMOD_INTO);
step_into();
static_cast<ttddbg::Debugger*>(dbg)->getManager().switchWay();
}
return false;
}
Expand Down
64 changes: 21 additions & 43 deletions ttddbg/src/ttddbg_debugger_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace ttddbg

/**********************************************************************/
DebuggerManager::DebuggerManager(std::shared_ptr<ttddbg::Logger> logger, Arch arch, Plugin *plugin)
: m_logger(logger), m_arch{ arch }, m_isForward{ true }, m_resumeMode{ resume_mode_t::RESMOD_NONE }, m_positionChooser(new PositionChooser(m_logger)), m_traceChooser(new TracerTraceChooser()), m_eventChooser(new TracerEventChooser()), m_nextPosition{0}, m_processId(1234), m_backwardsSingleStep(false), m_plugin(plugin)
: m_logger(logger), m_arch{ arch }, m_isForward{ true }, m_resumeMode{ resume_mode_t::RESMOD_NONE }, m_positionChooser(new PositionChooser(m_logger)), m_traceChooser(new TracerTraceChooser()), m_eventChooser(new TracerEventChooser()), m_nextPosition{0}, m_processId(1234), m_plugin(plugin)
{
}

Expand Down Expand Up @@ -267,45 +267,29 @@ namespace ttddbg
this->applyCursor(m_nextPosition);
m_events.addBreakPointEvent(m_processId, m_cursor->GetThreadInfo()[0].threadid, m_cursor->GetProgramCounter());
m_nextPosition = { 0 };
return DRC_OK;
}

if (m_backwardsSingleStep) {
// Special case: if "m_backwardsSingleStep" is true, simulate a "single-step"
// back in time: we force m_isForward to false and "applyCursor(1)", which effectively
// moves back in time of 1 unit
bool old_isForward = m_isForward;
m_isForward = false;
applyCursor(1);
m_isForward = old_isForward;

m_events.addBreakPointEvent(m_processId, m_cursor->GetThreadInfo()[0].threadid, m_cursor->GetProgramCounter());

m_backwardsSingleStep = false;

return DRC_OK;
}

switch (m_resumeMode)
{
case resume_mode_t::RESMOD_NONE:
{
this->applyCursor(-1);
m_events.addBreakPointEvent(m_processId, m_cursor->GetThreadInfo()[0].threadid, m_cursor->GetProgramCounter());
break;
}
case resume_mode_t::RESMOD_INTO:
{
this->applyCursor(1);
m_events.addStepEvent(m_processId, m_cursor->GetThreadInfo()[0].threadid);
break;
}
default:
m_logger->info("unsupported resume mode ", (int)m_resumeMode);
break;
else {
switch (m_resumeMode)
{
case resume_mode_t::RESMOD_NONE:
{
this->applyCursor(m_maxSteps);
m_events.addBreakPointEvent(m_processId, m_cursor->GetThreadInfo()[0].threadid, m_cursor->GetProgramCounter());
break;
}
case resume_mode_t::RESMOD_INTO:
{
this->applyCursor(1);
m_events.addStepEvent(m_processId, m_cursor->GetThreadInfo()[0].threadid);
break;
}
default:
m_logger->info("unsupported resume mode ", (int)m_resumeMode);
break;
}
}
m_resumeMode = resume_mode_t::RESMOD_NONE;
}
m_resumeMode = resume_mode_t::RESMOD_NONE;
return DRC_OK;
}

Expand Down Expand Up @@ -538,12 +522,6 @@ namespace ttddbg
msg("[ttddbg] full run completed\n");
}

/**********************************************************************/
void DebuggerManager::requestBackwardsSingleStep()
{
m_backwardsSingleStep = true;
}

/**********************************************************************/
void DebuggerManager::openPositionChooser() {
if (m_positionChooser != nullptr) {
Expand Down