OpenASIP  2.0
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
StopPointManager Class Reference

#include <StopPointManager.hh>

Inheritance diagram for StopPointManager:
Inheritance graph
Collaboration diagram for StopPointManager:
Collaboration graph

Public Member Functions

 StopPointManager (TTASimulationController &controller, SimulationEventHandler &eventHandler)
 
virtual ~StopPointManager ()
 
unsigned int add (const StopPoint &stopPoint)
 
void deleteStopPoint (unsigned int handle)
 
void deleteAll ()
 
void enable (unsigned int handle)
 
void enableAll ()
 
void enableOnceAndDelete (unsigned int handle)
 
void enableOnceAndDisable (unsigned int handle)
 
void disable (unsigned int handle)
 
void disableAll ()
 
const StopPointstopPointWithHandleConst (unsigned int handle) const
 
unsigned int stopPointHandle (unsigned int index)
 
unsigned int stopPointCount ()
 
void setIgnore (unsigned int handle, unsigned int count)
 
void setCondition (unsigned int handle, const ConditionScript &condition)
 
void removeCondition (unsigned int handle)
 
unsigned int stopCausingStopPoint (unsigned int index) const
 
unsigned int stopCausingStopPointCount () const
 
void handleEvent ()
 
- Public Member Functions inherited from Listener
 Listener ()
 
virtual ~Listener ()
 
virtual void handleEvent (int event)
 

Private Types

typedef std::map< unsigned int, StopPoint * > StopPointIndex
 The breakpoint storage. More...
 
typedef std::vector< unsigned int > HandleContainer
 The handle storage. More...
 

Private Member Functions

StopPointfindStopPoint (unsigned int handle)
 

Private Attributes

StopPointIndex stopPoints_
 The stop points. More...
 
HandleContainer handles_
 The stop point handles. More...
 
unsigned int handleCount_
 Represents the next free handle. More...
 
ClockCycleCount lastStopCycle_
 The clock cycle in which simulation was stopped last. More...
 
TTASimulationControllercontroller_
 The simulation controller to use to stop the simulation. More...
 
SimulationEventHandlereventHandler_
 The event handler to use to register stop points to. More...
 

Detailed Description

Keeps book of user-set simulation stop points.

Definition at line 50 of file StopPointManager.hh.

Member Typedef Documentation

◆ HandleContainer

typedef std::vector<unsigned int> StopPointManager::HandleContainer
private

The handle storage.

Definition at line 88 of file StopPointManager.hh.

◆ StopPointIndex

typedef std::map<unsigned int, StopPoint*> StopPointManager::StopPointIndex
private

The breakpoint storage.

Definition at line 86 of file StopPointManager.hh.

Constructor & Destructor Documentation

◆ StopPointManager()

StopPointManager::StopPointManager ( TTASimulationController controller,
SimulationEventHandler eventHandler 
)

Constructor.

Parameters
controllerThe simulation controller the stop points should use to stop the simulation.

Definition at line 56 of file StopPointManager.cc.

58  :
59  handleCount_(0), lastStopCycle_(0), controller_(controller),
60  eventHandler_(eventHandler) {
61 }

◆ ~StopPointManager()

StopPointManager::~StopPointManager ( )
virtual

Destructor.

Definition at line 67 of file StopPointManager.cc.

References MapTools::deleteAllValues(), and stopPoints_.

Here is the call graph for this function:

Member Function Documentation

◆ add()

unsigned int StopPointManager::add ( const StopPoint stopPoint)

Function that adds a new stop point.

Copies the given stop point.

Parameters
stopPointThe stop point to be added.
Returns
Handle for the added stop point.

Definition at line 81 of file StopPointManager.cc.

81  {
82 
83  StopPoint* toAdd = stopPoint.copy();
84 
85  ++handleCount_;
86 
87  stopPoints_.insert(make_pair(handleCount_, toAdd));
88  handles_.push_back(handleCount_);
89 
90  toAdd->setEnabled(true);
91 
92  if (stopPoints_.size() == 1) {
93  // this is the first added stop point, enable event
94  // listening
97  }
98  return handleCount_;
99 }

References StopPoint::copy(), eventHandler_, handleCount_, handles_, Informer::registerListener(), SimulationEventHandler::SE_NEW_INSTRUCTION, StopPoint::setEnabled(), and stopPoints_.

Referenced by BPCommand::execute(), WatchCommand::execute(), and TBPCommand::execute().

Here is the call graph for this function:

◆ deleteAll()

void StopPointManager::deleteAll ( )

Removes all stop points.

Definition at line 136 of file StopPointManager.cc.

136  {
137  while (handles_.size() > 0) {
138  deleteStopPoint(handles_.at(0));
139  }
140 }

References deleteStopPoint(), and handles_.

Referenced by DeleteBPCommand::execute().

Here is the call graph for this function:

◆ deleteStopPoint()

void StopPointManager::deleteStopPoint ( unsigned int  handle)

Remove a stop point by the given handle.

Parameters
handleThe handle of the stop point to be removed.

Definition at line 108 of file StopPointManager.cc.

108  {
109  StopPoint* stopPoint = findStopPoint(handle);
110 
111  StopPointIndex::iterator findResult = stopPoints_.find(handle);
112  stopPoints_.erase(findResult);
113 
114  for (HandleContainer::iterator i = handles_.begin(); i != handles_.end();
115  i++) {
116  if ((*i) == handle) {
117  handles_.erase(i);
118  break;
119  }
120  }
121 
122  delete stopPoint;
123  stopPoint = NULL;
124 
125  if (stopPoints_.size() == 0) {
126  // this was the last stop point, disable event listening
129  }
130 }

References eventHandler_, findStopPoint(), handles_, SimulationEventHandler::SE_NEW_INSTRUCTION, stopPoints_, and Informer::unregisterListener().

Referenced by deleteAll(), DeleteBPCommand::execute(), handleEvent(), ProximBreakpointWindow::onDeleteBreakpoint(), and ProximBreakpointWindow::onDeleteWatch().

Here is the call graph for this function:

◆ disable()

void StopPointManager::disable ( unsigned int  handle)

Disables the stop point by the given handle.

Parameters
handleThe handle for the stop point.

Definition at line 200 of file StopPointManager.cc.

200  {
201  findStopPoint(handle)->setEnabled(false);
202 }

References findStopPoint(), and StopPoint::setEnabled().

Referenced by disableAll(), and DisableBPCommand::execute().

Here is the call graph for this function:

◆ disableAll()

void StopPointManager::disableAll ( )

Disables all stop oints.

Definition at line 208 of file StopPointManager.cc.

208  {
209  for (unsigned int i = 0; i < handles_.size(); i++) {
210  disable(handles_.at(i));
211  }
212 }

References disable(), and handles_.

Here is the call graph for this function:

◆ enable()

void StopPointManager::enable ( unsigned int  handle)

Enables the stop point by the given handle.

Parameters
handleThe handle to identify the stop point.

Definition at line 149 of file StopPointManager.cc.

149  {
150  findStopPoint(handle)->setEnabled(true);
151 }

References findStopPoint(), and StopPoint::setEnabled().

Referenced by enableAll(), and EnableBPCommand::execute().

Here is the call graph for this function:

◆ enableAll()

void StopPointManager::enableAll ( )

Enables all stop points.

Definition at line 157 of file StopPointManager.cc.

157  {
158  for (unsigned int i = 0; i < handles_.size(); i++) {
159  enable(handles_.at(i));
160  }
161 }

References enable(), and handles_.

Here is the call graph for this function:

◆ enableOnceAndDelete()

void StopPointManager::enableOnceAndDelete ( unsigned int  handle)

Enables the stop point by the given handle and sets it to be deleted after being triggered.

Parameters
handleThe handle for the stop point.
Exceptions
InstanceNotFoundif the given handle cannot be found.

Definition at line 172 of file StopPointManager.cc.

172  {
173  StopPoint* stopPoint = findStopPoint(handle);
174 
175  stopPoint->setEnabled(true);
176  stopPoint->setDeletedAfterTriggered(true);
177 }

References findStopPoint(), StopPoint::setDeletedAfterTriggered(), and StopPoint::setEnabled().

Referenced by EnableBPCommand::execute().

Here is the call graph for this function:

◆ enableOnceAndDisable()

void StopPointManager::enableOnceAndDisable ( unsigned int  handle)

Enables the stop point by the given handle and sets it to be disabled after being triggered.

Parameters
handleThe handle for the stop point.
Exceptions
InstanceNotFoundif the given handle cannot be found.

Definition at line 187 of file StopPointManager.cc.

187  {
188  StopPoint* stopPoint = findStopPoint(handle);
189 
190  stopPoint->setEnabled(true);
191  stopPoint->setDisabledAfterTriggered(true);
192 }

References findStopPoint(), StopPoint::setDisabledAfterTriggered(), and StopPoint::setEnabled().

Referenced by EnableBPCommand::execute().

Here is the call graph for this function:

◆ findStopPoint()

StopPoint * StopPointManager::findStopPoint ( unsigned int  handle)
private

Tries to find a stop point by the given handle. If no such stop point is found, throws an exception.

Parameters
handleThe handle for the stop point.
Exceptions
InstanceNotFoundIf no stop point with given handle is found.
Todo:
textgenerator, to be displayed in the UI.

Definition at line 320 of file StopPointManager.cc.

320  {
321  StopPointIndex::iterator containerEnd = stopPoints_.end();
322  StopPointIndex::iterator findResult = stopPoints_.find(handle);
323 
324  if (findResult == containerEnd) {
325  /// @todo textgenerator, to be displayed in the UI.
326  string msg = "No stop point found by the given handle.";
327  throw InstanceNotFound(__FILE__, __LINE__, __func__, msg);
328  } else {
329  return findResult->second;
330  }
331 }

References __func__, and stopPoints_.

Referenced by deleteStopPoint(), disable(), enable(), enableOnceAndDelete(), enableOnceAndDisable(), removeCondition(), setCondition(), and setIgnore().

◆ handleEvent()

void StopPointManager::handleEvent ( )
virtual

Stops simulation if there is at least one stop point requesting it.

Receives SE_NEW_INSTRUCTION events.

Reimplemented from Listener.

Definition at line 388 of file StopPointManager.cc.

388  {
389 
390  // find all the stop points watching the new instruction address
391  StopPointIndex::iterator i = stopPoints_.begin();
392  HandleContainer toBeDeletedStopPoints;
393  while (i != stopPoints_.end()) {
394 
395  StopPoint& stopPoint = *(*i).second;
396  const int handle = (*i).first;
397  if (stopPoint.isEnabled() && stopPoint.isTriggered()) {
398  // we found a stop point that is triggered at this clock cycle
399 
400  if (stopPoint.ignoreCount() == 0 && stopPoint.isConditionOK()) {
401 
404  if (stopPoint.isDisabledAfterTriggered()) {
405  stopPoint.setEnabled(false);
406  }
407 
408  if (stopPoint.isDeletedAfterTriggered()) {
409  toBeDeletedStopPoints.push_back(handle);
410  }
411 
412  } else if (stopPoint.isConditionOK()) {
413  // decrease the ignore count only if the (possible) condition
414  // of the breakpoint is also true
415  stopPoint.decreaseIgnoreCount();
416  }
417  }
418  ++i;
419  }
420 
421  // delete stop points that wanted to be deleted after triggered
422  for (size_t i = 0; i < toBeDeletedStopPoints.size(); ++i) {
423  deleteStopPoint(toBeDeletedStopPoints[i]);
424  }
425 }

References TTASimulationController::clockCount(), controller_, StopPoint::decreaseIgnoreCount(), deleteStopPoint(), StopPoint::ignoreCount(), StopPoint::isConditionOK(), StopPoint::isDeletedAfterTriggered(), StopPoint::isDisabledAfterTriggered(), StopPoint::isEnabled(), StopPoint::isTriggered(), lastStopCycle_, TTASimulationController::prepareToStop(), StopPoint::setEnabled(), SRE_BREAKPOINT, and stopPoints_.

Here is the call graph for this function:

◆ removeCondition()

void StopPointManager::removeCondition ( unsigned int  handle)

Removes the condition of triggering of the stop point by the given handle.

Parameters
handleThe handle for the stop point.
Exceptions
InstanceNotFoundIf no stop point with given handle is found.

Definition at line 308 of file StopPointManager.cc.

308  {
309  findStopPoint(handle)->removeCondition();
310 }

References findStopPoint(), and StopPoint::removeCondition().

Referenced by ConditionCommand::execute().

Here is the call graph for this function:

◆ setCondition()

void StopPointManager::setCondition ( unsigned int  handle,
const ConditionScript condition 
)

Sets the condition of triggering for the stop point by the given handle.

Parameters
handleThe handle for the stop point.
conditionThe condition to be used to determine if the stop point should be fired.
Exceptions
InstanceNotFoundIf no stop point with given handle is found.

Definition at line 296 of file StopPointManager.cc.

297  {
298  findStopPoint(handle)->setCondition(condition);
299 }

References findStopPoint(), and StopPoint::setCondition().

Referenced by ConditionCommand::execute().

Here is the call graph for this function:

◆ setIgnore()

void StopPointManager::setIgnore ( unsigned int  handle,
unsigned int  count 
)

Sets the number of times the stop point by the given handle should not be triggered when the condition is met.

Parameters
handleThe handle for the stop point.
countThe number of times the stop point should be ignored.
Exceptions
InstanceNotFoundIf no stop point with given handle is found.

Definition at line 283 of file StopPointManager.cc.

283  {
284  findStopPoint(handle)->setIgnoreCount(count);
285 }

References findStopPoint(), and StopPoint::setIgnoreCount().

Referenced by IgnoreCommand::execute().

Here is the call graph for this function:

◆ stopCausingStopPoint()

unsigned int StopPointManager::stopCausingStopPoint ( unsigned int  index) const

Returns the handle of a stop causing stop point with given index in the container of stop causing stop points.

Stop causing stop point is a stop point that caused the latest stop of simulator.

Parameters
indexIndex of the stop point in the container.
Returns
the handle of the stop point.
Exceptions
OutOfRange

Definition at line 345 of file StopPointManager.cc.

345  {
346  unsigned int count = 0;
347  for (StopPointIndex::const_iterator i = stopPoints_.begin();
348  i != stopPoints_.end(); ++i) {
349  if ((*i).second->isTriggered()) {
350  if (count == index)
351  return (*i).first;
352  ++count;
353  }
354  }
355  throw OutOfRange(
356  __FILE__, __LINE__, __func__, "Stop point index out of range.");
357 }

References __func__, and stopPoints_.

Referenced by SimControlLanguageCommand::printStopReasons().

◆ stopCausingStopPointCount()

unsigned int StopPointManager::stopCausingStopPointCount ( ) const

Returns the count of stop causing stop points.

Stop causing stop point is a stop point that caused the latest stop of simulator.

Returns
the count of stop points.

Definition at line 368 of file StopPointManager.cc.

368  {
370  return 0;
371  }
372  std::size_t count = 0;
373  for (StopPointIndex::const_iterator i = stopPoints_.begin();
374  i != stopPoints_.end(); ++i) {
375  if ((*i).second->isTriggered())
376  ++count;
377  }
378  return count;
379 }

References TTASimulationController::clockCount(), controller_, lastStopCycle_, and stopPoints_.

Referenced by SimControlLanguageCommand::printStopReasons().

Here is the call graph for this function:

◆ stopPointCount()

unsigned int StopPointManager::stopPointCount ( )

Returns the current number of stop points in the manager.

Can be used to access all stop points in the manager.

Returns
The number of stop points in the manager.

Definition at line 269 of file StopPointManager.cc.

269  {
270  return handles_.size();
271 }

References handles_.

Referenced by InfoBreakpointsCommand::execute(), ProximDisassemblyGridTable::GetValue(), ProximDisassemblyWindow::onRightClick(), ProximBreakpointWindow::refreshStopPoints(), and stopPointHandle().

◆ stopPointHandle()

unsigned int StopPointManager::stopPointHandle ( unsigned int  index)

Returns the handle of the stop point by the given index.

The index is not a direct index to the container used to store stop points, but more just a way to go through all of the stop points in the manager. A stop point may not have the same index every call.

All of the stop points can be accessed by going through the stop points with the indices between 0 and stopPointCount - 1, inclusive. The stop points are in no particular order.

Parameters
indexThe index.
Returns
A Copy of the stop point by the given index.
Exceptions
OutOfRangeIf there is no stop point by the given index.
Todo:
textgenerator, to be displayed in the UI.

Definition at line 231 of file StopPointManager.cc.

231  {
232  if (index < stopPointCount()) {
233  return handles_.at(index);
234  } else {
235  /// @todo textgenerator, to be displayed in the UI.
236  string msg = "No stop point found by the given index.";
237  throw OutOfRange(__FILE__, __LINE__, __func__, msg);
238  }
239 }

References __func__, handles_, and stopPointCount().

Referenced by InfoBreakpointsCommand::execute(), ProximDisassemblyGridTable::GetValue(), ProximDisassemblyWindow::onRightClick(), and ProximBreakpointWindow::refreshStopPoints().

Here is the call graph for this function:

◆ stopPointWithHandleConst()

const StopPoint & StopPointManager::stopPointWithHandleConst ( unsigned int  handle) const

Returns the stop point with the given handle.

Parameters
handleThe handle.
Returns
Stop point with the given handle,
Exceptions
InstanceNotFoundIf there is no stop point with the given handle.
Todo:
textgenerator, to be displayed in the UI.

Definition at line 248 of file StopPointManager.cc.

248  {
249  StopPointIndex::const_iterator containerEnd = stopPoints_.end();
250  StopPointIndex::const_iterator findResult = stopPoints_.find(handle);
251 
252  if (findResult == containerEnd) {
253  /// @todo textgenerator, to be displayed in the UI.
254  std::string msg = "No stop point found by the given handle.";
255  throw InstanceNotFound(__FILE__, __LINE__, __func__, msg);
256  } else {
257  return *findResult->second;
258  }
259 }

References __func__, and stopPoints_.

Referenced by ConditionCommand::execute(), IgnoreCommand::execute(), ProximDisassemblyGridTable::GetValue(), ProximBreakpointWindow::onBreakpointLookup(), ProximDisassemblyWindow::onRightClick(), SimControlLanguageCommand::printBreakpointInfo(), SimControlLanguageCommand::printStopReasons(), ProximBreakpointWindow::refreshStopPoints(), WatchPropertiesDialog::TransferDataToWindow(), BreakpointPropertiesDialog::TransferDataToWindow(), and SimControlLanguageCommand::verifyBreakpointHandles().

Member Data Documentation

◆ controller_

TTASimulationController& StopPointManager::controller_
private

The simulation controller to use to stop the simulation.

Definition at line 101 of file StopPointManager.hh.

Referenced by handleEvent(), and stopCausingStopPointCount().

◆ eventHandler_

SimulationEventHandler& StopPointManager::eventHandler_
private

The event handler to use to register stop points to.

Definition at line 103 of file StopPointManager.hh.

Referenced by add(), and deleteStopPoint().

◆ handleCount_

unsigned int StopPointManager::handleCount_
private

Represents the next free handle.

Definition at line 97 of file StopPointManager.hh.

Referenced by add().

◆ handles_

HandleContainer StopPointManager::handles_
private

The stop point handles.

Definition at line 95 of file StopPointManager.hh.

Referenced by add(), deleteAll(), deleteStopPoint(), disableAll(), enableAll(), stopPointCount(), and stopPointHandle().

◆ lastStopCycle_

ClockCycleCount StopPointManager::lastStopCycle_
private

The clock cycle in which simulation was stopped last.

Definition at line 99 of file StopPointManager.hh.

Referenced by handleEvent(), and stopCausingStopPointCount().

◆ stopPoints_

StopPointIndex StopPointManager::stopPoints_
private

The documentation for this class was generated from the following files:
StopPointManager::handleCount_
unsigned int handleCount_
Represents the next free handle.
Definition: StopPointManager.hh:97
StopPoint::setEnabled
virtual void setEnabled(bool flag)
Definition: StopPoint.cc:63
StopPointManager::controller_
TTASimulationController & controller_
The simulation controller to use to stop the simulation.
Definition: StopPointManager.hh:101
StopPoint::setIgnoreCount
virtual void setIgnoreCount(unsigned int count)
Definition: StopPoint.cc:182
StopPoint::setDisabledAfterTriggered
virtual void setDisabledAfterTriggered(bool flag)
Definition: StopPoint.cc:85
StopPointManager::eventHandler_
SimulationEventHandler & eventHandler_
The event handler to use to register stop points to.
Definition: StopPointManager.hh:103
StopPointManager::stopPoints_
StopPointIndex stopPoints_
The stop points.
Definition: StopPointManager.hh:93
OutOfRange
Definition: Exception.hh:320
StopPoint::isDeletedAfterTriggered
virtual bool isDeletedAfterTriggered() const
Definition: StopPoint.cc:119
MapTools::deleteAllValues
static void deleteAllValues(MapType &aMap)
StopPoint::ignoreCount
virtual unsigned int ignoreCount() const
Definition: StopPoint.cc:193
StopPointManager::deleteStopPoint
void deleteStopPoint(unsigned int handle)
Definition: StopPointManager.cc:108
TTASimulationController::prepareToStop
virtual void prepareToStop(StopReason reason)
Definition: TTASimulationController.cc:90
StopPointManager::lastStopCycle_
ClockCycleCount lastStopCycle_
The clock cycle in which simulation was stopped last.
Definition: StopPointManager.hh:99
StopPoint::copy
virtual StopPoint * copy() const =0
StopPointManager::stopPointCount
unsigned int stopPointCount()
Definition: StopPointManager.cc:269
StopPoint
Definition: StopPoint.hh:53
Informer::unregisterListener
virtual bool unregisterListener(int event, Listener *listener)
Definition: Informer.cc:104
StopPointManager::enable
void enable(unsigned int handle)
Definition: StopPointManager.cc:149
StopPointManager::HandleContainer
std::vector< unsigned int > HandleContainer
The handle storage.
Definition: StopPointManager.hh:88
__func__
#define __func__
Definition: Application.hh:67
Informer::registerListener
virtual bool registerListener(int event, Listener *listener)
Definition: Informer.cc:87
SRE_BREAKPOINT
@ SRE_BREAKPOINT
Stopped because of at least one breakpoint.
Definition: SimulatorConstants.hh:65
StopPoint::isDisabledAfterTriggered
virtual bool isDisabledAfterTriggered() const
Definition: StopPoint.cc:97
StopPointManager::disable
void disable(unsigned int handle)
Definition: StopPointManager.cc:200
StopPoint::isConditionOK
virtual bool isConditionOK()
Definition: StopPoint.cc:215
StopPoint::isEnabled
virtual bool isEnabled() const
Definition: StopPoint.cc:73
TTASimulationController::clockCount
virtual ClockCycleCount clockCount() const
Definition: TTASimulationController.cc:161
StopPoint::isTriggered
virtual bool isTriggered() const =0
StopPoint::removeCondition
virtual void removeCondition()
Definition: StopPoint.cc:142
StopPointManager::handles_
HandleContainer handles_
The stop point handles.
Definition: StopPointManager.hh:95
StopPoint::setDeletedAfterTriggered
virtual void setDeletedAfterTriggered(bool flag)
Definition: StopPoint.cc:107
StopPoint::setCondition
virtual void setCondition(const ConditionScript &condition)
Definition: StopPoint.cc:131
InstanceNotFound
Definition: Exception.hh:304
StopPointManager::findStopPoint
StopPoint * findStopPoint(unsigned int handle)
Definition: StopPointManager.cc:320
StopPoint::decreaseIgnoreCount
virtual void decreaseIgnoreCount()
Definition: StopPoint.cc:201
SimulationEventHandler::SE_NEW_INSTRUCTION
@ SE_NEW_INSTRUCTION
Generated before executing a new instructon.
Definition: SimulationEventHandler.hh:48