OpenASIP  2.0
Public Member Functions | Protected Member Functions | List of all members
SimControlLanguageCommand Class Reference

#include <SimControlLanguageCommand.hh>

Inheritance diagram for SimControlLanguageCommand:
Inheritance graph
Collaboration diagram for SimControlLanguageCommand:
Collaboration graph

Public Member Functions

 SimControlLanguageCommand (const std::string &name)
 
virtual ~SimControlLanguageCommand ()
 
SimulatorFrontendsimulatorFrontend ()
 
const SimulatorFrontendsimulatorFrontendConst ()
 
virtual void printNextInstruction ()
 
virtual void printStopInformation ()
 
virtual void printStopReasons ()
 
virtual bool printBreakpointInfo (unsigned int breakpointHandle)
 
virtual void printSimulationTime ()
 
virtual std::ostream & outputStream ()
 
bool checkSimulationInitialized ()
 
bool checkSimulationNotAlreadyRunning ()
 
bool checkSimulationStopped ()
 
bool checkSimulationEnded ()
 
bool checkProgramLoaded ()
 
bool checkMachineLoaded ()
 
InstructionAddress parseInstructionAddressExpression (const std::string &expression)
 
TTAProgram::Address parseDataAddressExpression (const std::string &expression)
 
bool parseBreakpoint (const std::vector< DataObject > &arguments, Breakpoint &target)
 
bool askConditionFromUser (TclConditionScript &target)
 
bool askExpressionFromUser (ExpressionScript &target)
 
bool verifyBreakpointHandles (const std::vector< DataObject > &arguments, std::size_t startIndex=1)
 
void setErrorMessage (const TCEString &errorMsg)
 
- Public Member Functions inherited from CustomCommand
 CustomCommand (std::string name)
 
 CustomCommand (const CustomCommand &cmd)
 
virtual ~CustomCommand ()
 
std::string name () const
 
void setContext (InterpreterContext *context)
 
InterpreterContextcontext () const
 
void setInterpreter (ScriptInterpreter *si)
 
ScriptInterpreterinterpreter () const
 
virtual bool execute (const std::vector< DataObject > &arguments)=0
 
virtual std::string helpText () const =0
 
bool checkArgumentCount (int argumentCount, int minimum, int maximum)
 
bool checkIntegerArgument (const DataObject &argument)
 
bool checkPositiveIntegerArgument (const DataObject &argument)
 
bool checkUnsignedIntegerArgument (const DataObject &argument)
 
bool checkDoubleArgument (const DataObject &argument)
 

Protected Member Functions

bool setMemoryAddress (const std::string &addressString, std::string &addressSpaceName, std::size_t &memoryAddress)
 
bool setMemoryPointer (MemorySystem::MemoryPtr &memory, const std::string &addressSpaceName)
 

Detailed Description

This is a base class for Simulator Control Language commands.

Provides services command and useful for all Simulator Control Language commands.

Definition at line 63 of file SimControlLanguageCommand.hh.

Constructor & Destructor Documentation

◆ SimControlLanguageCommand()

SimControlLanguageCommand::SimControlLanguageCommand ( const std::string &  name)

Constructor.

Sets the name of the command to the base class.

Parameters
nameName of the command to add.

Definition at line 67 of file SimControlLanguageCommand.cc.

68  :
70 }

◆ ~SimControlLanguageCommand()

SimControlLanguageCommand::~SimControlLanguageCommand ( )
virtual

Destructor.

Does nothing.

Definition at line 77 of file SimControlLanguageCommand.cc.

77  {
78 }

Member Function Documentation

◆ askConditionFromUser()

bool SimControlLanguageCommand::askConditionFromUser ( TclConditionScript target)

Prompts for a condition script from the user.

Also test runs the condition script. Returns false and sets interpreter error if the entered condition is illegal. If an empty condition script is entered, the condition script is set to always true "1" condition.

Parameters
targetThe target to put the condition script in.
Returns
false in case the script produces error when executed.

Definition at line 513 of file SimControlLanguageCommand.cc.

513  {
514 
515  std::string conditionScript =
517  interpreter()->lineReader()->readLine(
520 
521  if (StringTools::trim(conditionScript) == "") {
522  conditionScript = "1";
523  }
524 
525  TclConditionScript testCondition(
526  dynamic_cast<TclInterpreter*>(interpreter()), conditionScript);
527 
528  // try the condition
529  try {
530  testCondition.execute();
531  interpreter()->setResult("");
532  target = testCondition;
533  } catch (const ScriptExecutionFailure& sef) {
534  interpreter()->setError(true);
535  return false;
536  }
537  return true;
538 }

References Script::execute(), CustomCommand::interpreter(), ScriptInterpreter::setError(), ScriptInterpreter::setResult(), SimulatorToolbox::textGenerator(), StringTools::trim(), and Texts::TXT_INTERP_ENTER_CONDITION_PROMPT.

Referenced by ConditionCommand::execute(), and parseBreakpoint().

Here is the call graph for this function:

◆ askExpressionFromUser()

bool SimControlLanguageCommand::askExpressionFromUser ( ExpressionScript target)

Prompts for an expression script from the user.

Also test runs the expression script. Returns false and sets interpreter error if the entered expression is illegal. If an empty expression script is entered, returns false and sets interpreter error.

Parameters
targetThe target to put the expression script in.
Returns
false in case the script produces error when executed or it's empty.

Definition at line 551 of file SimControlLanguageCommand.cc.

551  {
552 
553  std::string expressionScript =
555  interpreter()->lineReader()->readLine(
558 
559  if (StringTools::trim(expressionScript) == "") {
563  return false;
564  }
565 
566  ExpressionScript testExpression(
567  dynamic_cast<TclInterpreter*>(interpreter()), expressionScript);
568 
569  // try the condition
570  try {
571  testExpression.execute();
572  interpreter()->setResult("");
573  target = testExpression;
574  return true;
575  } catch (const ScriptExecutionFailure& sef) {
576  interpreter()->setError(true);
577  return false;
578  }
579 }

References Script::execute(), CustomCommand::interpreter(), ScriptInterpreter::setError(), ScriptInterpreter::setResult(), SimulatorToolbox::textGenerator(), StringTools::trim(), Texts::TXT_EXPRESSION_EMPTY, and Texts::TXT_INTERP_ENTER_EXPRESSION_PROMPT.

Referenced by WatchCommand::execute().

Here is the call graph for this function:

◆ checkMachineLoaded()

bool SimControlLanguageCommand::checkMachineLoaded ( )

Checks that the simulated machine has been loaded successfully.

Returns
True if machine has been loaded.

Definition at line 199 of file SimControlLanguageCommand.cc.

199  {
200  if (!simulatorFrontend().isMachineLoaded()) {
201  interpreter()->setError(std::string("No machine loaded."));
202  return false;
203  }
204  return true;
205 }

References CustomCommand::interpreter(), ScriptInterpreter::setError(), and simulatorFrontend().

Here is the call graph for this function:

◆ checkProgramLoaded()

bool SimControlLanguageCommand::checkProgramLoaded ( )

Checks that the simulated program has been loaded successfully.

Returns
True if program has been loaded.

Definition at line 180 of file SimControlLanguageCommand.cc.

180  {
181 
182  if (!simulatorFrontend().isProgramLoaded()) {
186 
187  return false;
188  }
189  return true;
190 }

References CustomCommand::interpreter(), ScriptInterpreter::setError(), simulatorFrontend(), SimulatorToolbox::textGenerator(), and Texts::TXT_NO_PROGRAM_LOADED.

Referenced by MemDumpCommand::execute(), SymbolAddressCommand::execute(), MemWriteCommand::execute(), and DisassembleCommand::execute().

Here is the call graph for this function:

◆ checkSimulationEnded()

bool SimControlLanguageCommand::checkSimulationEnded ( )

Checks that the simulation has ended.

Sets errors message and returns false if simulation has not ended.

Returns
True if simulation has ended.

Definition at line 158 of file SimControlLanguageCommand.cc.

158  {
159 
160  DataObject* result = new DataObject();
161  if (!simulatorFrontend().hasSimulationEnded()) {
162  result->setString(
165  interpreter()->setResult(result);
166  return false;
167  }
168 
169  interpreter()->setResult(result);
170  return true;
171 }

References CustomCommand::interpreter(), ScriptInterpreter::setResult(), DataObject::setString(), simulatorFrontend(), SimulatorToolbox::textGenerator(), and Texts::TXT_INTERP_SIMULATION_NOT_ENDED.

Referenced by KillCommand::execute().

Here is the call graph for this function:

◆ checkSimulationInitialized()

bool SimControlLanguageCommand::checkSimulationInitialized ( )

Checks that the simulation is initialized and ready to run.

Sets errors message and returns false if simulation is not initialized.

Returns
True if simulation is initialized.

Definition at line 88 of file SimControlLanguageCommand.cc.

88  {
89 
90  DataObject* result = new DataObject();
91  if (!simulatorFrontend().isSimulationInitialized()) {
92  result->setString(
95  interpreter()->setResult(result);
96  return false;
97  }
98 
99  interpreter()->setResult(result);
100  return true;
101 }

References CustomCommand::interpreter(), ScriptInterpreter::setResult(), DataObject::setString(), simulatorFrontend(), SimulatorToolbox::textGenerator(), and Texts::TXT_INTERP_SIMULATION_NOT_INITIALIZED.

Referenced by ConditionCommand::execute(), UntilCommand::execute(), StepiCommand::execute(), DeleteBPCommand::execute(), RunCommand::execute(), NextiCommand::execute(), IgnoreCommand::execute(), EnableBPCommand::execute(), DisableBPCommand::execute(), and parseBreakpoint().

Here is the call graph for this function:

◆ checkSimulationNotAlreadyRunning()

bool SimControlLanguageCommand::checkSimulationNotAlreadyRunning ( )

Checks that the simulation is not already running.

Sets errors message and returns false if simulation is running.

Returns
True if simulation is not running.

Definition at line 111 of file SimControlLanguageCommand.cc.

111  {
112 
113  DataObject* result = new DataObject();
114  if (simulatorFrontend().isSimulationRunning() ||
115  simulatorFrontend().isSimulationStopped()) {
116  result->setString(
119  interpreter()->setResult(result);
120  return false;
121  }
122  interpreter()->setResult(result);
123  return true;
124 }

References CustomCommand::interpreter(), ScriptInterpreter::setResult(), DataObject::setString(), simulatorFrontend(), SimulatorToolbox::textGenerator(), and Texts::TXT_INTERP_SIMULATION_ALREDY_RUNNING.

Referenced by RunCommand::execute().

Here is the call graph for this function:

◆ checkSimulationStopped()

bool SimControlLanguageCommand::checkSimulationStopped ( )

Checks that the simulation is stopped.

Sets errors message and returns false if simulation is not stopped by the user.

Returns
True if simulation is stopped.

Definition at line 135 of file SimControlLanguageCommand.cc.

135  {
136 
137  DataObject* result = new DataObject();
138  if (!simulatorFrontend().isSimulationStopped()) {
139  result->setString(
142  interpreter()->setResult(result);
143  return false;
144  }
145 
146  interpreter()->setResult(result);
147  return true;
148 }

References CustomCommand::interpreter(), ScriptInterpreter::setResult(), DataObject::setString(), simulatorFrontend(), SimulatorToolbox::textGenerator(), and Texts::TXT_INTERP_SIMULATION_NOT_RUNNING.

Referenced by KillCommand::execute(), UntilCommand::execute(), StepiCommand::execute(), ConditionCommand::execute(), ResumeCommand::execute(), DisableBPCommand::execute(), DeleteBPCommand::execute(), IgnoreCommand::execute(), EnableBPCommand::execute(), NextiCommand::execute(), BackTraceCommand::execute(), and parseBreakpoint().

Here is the call graph for this function:

◆ outputStream()

std::ostream & SimControlLanguageCommand::outputStream ( )
virtual

Returns the output stream which can be used to print information to the user.

Uses the same output stream as the linereader to make the information texts printed to the same stream as confirmations of the linereader.

Returns
The output stream.

Definition at line 351 of file SimControlLanguageCommand.cc.

351  {
352  return interpreter()->lineReader()->outputStream();
353 }

References CustomCommand::interpreter(), ScriptInterpreter::lineReader(), and LineReader::outputStream().

Referenced by HelpCommand::execute(), ProgCommand::execute(), BackTraceCommand::execute(), CommandsCommand::execute(), DisassembleCommand::execute(), SettingCommand::execute(), InfoProcCommand::execute(), InfoProgramCommand::execute(), printBreakpointInfo(), printNextInstruction(), printSimulationTime(), and printStopReasons().

Here is the call graph for this function:

◆ parseBreakpoint()

bool SimControlLanguageCommand::parseBreakpoint ( const std::vector< DataObject > &  arguments,
Breakpoint target 
)

Parses breakpoint data from the given arguments.

This is a refactoring of common functionality used in 'bp' and 'tbp' commands. Sets the error message to the interpreter and returns false if there was an error while parsing or simulation is in wrong state.

Parameters
argumentsas passed to the execute() of the command.
targetthe breakpoint instance to put the parsed data to.
Returns
true if the breakpoint was parsed succesfully.
Todo:
set the condition, if any

Definition at line 593 of file SimControlLanguageCommand.cc.

594  {
595 
597  return false;
598  }
599 
600  // how many arguments there are in the condition part
601  size_t conditionArgumentCount = 0;
602  for (size_t i = 0; i < arguments.size(); ++i) {
603  if (StringTools::stringToLower(arguments[i].stringValue()) ==
604  "if") {
605 
606  if (i != arguments.size() - 1) {
610  return false;
611  }
612  conditionArgumentCount = 1;
613  break;
614  }
615  }
616 
617  if (conditionArgumentCount > 0) {
618  TclConditionScript condition(NULL, "");
619  if (!askConditionFromUser(condition)) {
620  return false;
621  }
622  assert(condition.script().size() > 0);
623  if (condition.script().at(0) == "1") {
624  target.removeCondition();
625  } else {
626  target.setCondition(condition);
627  }
628  }
629 
630  const int argumentsBeforeCondition =
631  arguments.size() - 1 - conditionArgumentCount;
632 
633  InstructionAddress theAddress = 0;
634 
635  if (argumentsBeforeCondition == 0 || argumentsBeforeCondition == 1) {
636 
637  const std::string argument =
638  ((argumentsBeforeCondition == 0)?
639  (""):(arguments[1].stringValue()));
640  try {
641  theAddress =
643  } catch (const IllegalParameters&) {
644  // the helper function has set the error string to
645  // the interpreter
646  return false;
647  }
648 
649  } else {
653  return false;
654  }
655 
656  /// @todo set the condition, if any
657 
658  target.setAddress(theAddress);
659  return true;
660 }

References askConditionFromUser(), assert, checkSimulationInitialized(), checkSimulationStopped(), CustomCommand::interpreter(), parseInstructionAddressExpression(), StopPoint::removeCondition(), TclConditionScript::script(), Breakpoint::setAddress(), StopPoint::setCondition(), ScriptInterpreter::setError(), StringTools::stringToLower(), SimulatorToolbox::textGenerator(), and Texts::TXT_ILLEGAL_ARGUMENTS.

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

Here is the call graph for this function:

◆ parseDataAddressExpression()

TTAProgram::Address SimControlLanguageCommand::parseDataAddressExpression ( const std::string &  expression)

Parses a data address expression string.

Expression string can be given by the user to, for example, 'x' command. Resolves symbol.

Supported address expression strings are currently:

*address An absolute address reference, can be an integer or a label string. In case of a label string, the return value contains also the address space of the address expression.

Parameters
expressionThe expression to parse.
Returns
The parsed instruction address and its address space, if given. In case address space could not be found, the address space field points to NullAddressSpace.
Exceptions
IllegalParameterswhen expression could not be parsed to an address.

Definition at line 471 of file SimControlLanguageCommand.cc.

472  {
473  std::string expr = StringTools::trim(expression);
474  const std::string errorMessage = "Illegal argument.";
475 
476  InstructionAddress theAddress = 0;
477 
478  // check if it's an integer, that is, a direct address reference
479  const std::string addressString = expression;
480  try {
481  theAddress = Conversion::toUnsignedInt(expression);
482  } catch (const NumberFormatException&) {
483  // it was not an integer, check if a label with given string
484  // is found in the global scope
485  const GlobalScope& globalScope =
487 
488  try {
489  return globalScope.dataLabel(expression).address();
490  } catch (const KeyNotFound&) {
491  // couldn't evaluate the label
495  throw IllegalParameters(
496  __FILE__, __LINE__, __func__, errorMessage);
497  }
498  }
499  return Address(theAddress, TTAMachine::NullAddressSpace::instance());
500 }

References __func__, TTAProgram::Label::address(), TTAProgram::Scope::dataLabel(), TTAProgram::Program::globalScopeConst(), TTAMachine::NullAddressSpace::instance(), CustomCommand::interpreter(), SimulatorFrontend::program(), ScriptInterpreter::setError(), simulatorFrontend(), SimulatorToolbox::textGenerator(), Conversion::toUnsignedInt(), StringTools::trim(), and Texts::TXT_LABEL_NOT_FOUND.

Referenced by setMemoryAddress().

Here is the call graph for this function:

◆ parseInstructionAddressExpression()

InstructionAddress SimControlLanguageCommand::parseInstructionAddressExpression ( const std::string &  expression)

Parses an instruction address expression string.

Expression string can be given by the user to, for example, 'break' or 'until' commands. This function also does range checking, when the address is lower than the first address of the program, it sets the address to the lowest address, when the address is bigger than the last address of the program, it sets the address to the last address.

Supported address expression strings are currently:

[empty] Address of the instruction following the current instruction. *address An absolute instruction address reference, can be an integer or a label string.

Parameters
expressionThe expression to parse.
Returns
The parsed instruction address.
Exceptions
IllegalParameterswhen expression could not be parsed to an address.

Definition at line 378 of file SimControlLanguageCommand.cc.

379  {
380  std::string expr = StringTools::trim(expression);
381  const std::string errorMessage = "Illegal argument.";
382 
383  InstructionAddress theAddress = 0;
384  if (expr.size() == 0) {
385  theAddress = simulatorFrontend().programCounter() + 1;
386  } else {
387  // the argument is an absolute address, try to evaluate it to an
388  // instruction address
389 
390  // check if it's an integer, that is, a direct instruction address
391  // reference
392  const std::string address = expression;
393  try {
394  theAddress = Conversion::toUnsignedInt(address);
395  } catch (const NumberFormatException&) {
396  // check if a label with given string is found in the
397  // global scope
398  const GlobalScope& globalScope =
400 
401  try {
402  theAddress =
403  globalScope.codeLabel(address).address().location();
404  } catch (const KeyNotFound&) {
405  try {
406  // check if it's a reference to a function
407  theAddress =
408  simulatorFrontend().program().procedure(address).
409  startAddress().location();
410  } catch (const KeyNotFound&) {
411  try {
412  // check if user forgot the leading "_"
413  theAddress =
415  std::string("_") + address).
416  startAddress().location();
417  } catch (const KeyNotFound&) {
418  // couldn't evaluate the label
422 
423  throw IllegalParameters(
424  __FILE__, __LINE__, __func__, errorMessage);
425  }
426  }
427  }
428  }
429  }
430 
431  // check the boundaries of the instruction address and fix it, if necessary
432  const InstructionAddress programLastAddress =
434  - 1;
435 
436  const InstructionAddress programFirstAddress =
438  location();
439 
440  if (theAddress > programLastAddress) {
441  theAddress = programLastAddress;
442  } else if (theAddress < programFirstAddress) {
443  theAddress = programFirstAddress;
444  }
445 
446  return theAddress;
447 }

References __func__, TTAProgram::CodeLabel::address(), TTAProgram::Scope::codeLabel(), TTAProgram::CodeSnippet::endAddress(), TTAProgram::Program::firstProcedure(), TTAProgram::Program::globalScopeConst(), CustomCommand::interpreter(), TTAProgram::Program::lastProcedure(), TTAProgram::Address::location(), TTAProgram::Program::procedure(), SimulatorFrontend::program(), SimulatorFrontend::programCounter(), ScriptInterpreter::setError(), simulatorFrontend(), TTAProgram::CodeSnippet::startAddress(), SimulatorToolbox::textGenerator(), Conversion::toUnsignedInt(), StringTools::trim(), and Texts::TXT_LABEL_NOT_FOUND.

Referenced by UntilCommand::execute(), DisassembleCommand::execute(), and parseBreakpoint().

Here is the call graph for this function:

◆ printBreakpointInfo()

bool SimControlLanguageCommand::printBreakpointInfo ( unsigned int  breakpointHandle)
virtual

Prints information of a breakpoint.

If breakpoint with the given handle could not be found, sets error to the interpreter and returns false.

Parameters
breakpointHandleThe handle of the breakpoint to be printed.
Returns
true If breakpoint could be printed.

Definition at line 678 of file SimControlLanguageCommand.cc.

679  {
680 
681  try {
682  const StopPoint& stopPoint =
684  breakpointHandle);
685 
686  outputStream()
687  << std::right << std::setw(BPINFO_HANDLE_COL_WIDTH)
688  << breakpointHandle << ": " << stopPoint.description()
689  << std::endl;
690 
691  return true;
692  } catch (const InstanceNotFound&) {
696  return false;
697  }
698 }

References BPINFO_HANDLE_COL_WIDTH, StopPoint::description(), CustomCommand::interpreter(), outputStream(), ScriptInterpreter::setError(), simulatorFrontend(), SimulatorFrontend::stopPointManager(), StopPointManager::stopPointWithHandleConst(), SimulatorToolbox::textGenerator(), and Texts::TXT_BREAKPOINT_NOT_FOUND.

Referenced by BPCommand::execute(), WatchCommand::execute(), TBPCommand::execute(), ConditionCommand::execute(), IgnoreCommand::execute(), EnableBPCommand::execute(), DisableBPCommand::execute(), and InfoBreakpointsCommand::execute().

Here is the call graph for this function:

◆ printNextInstruction()

void SimControlLanguageCommand::printNextInstruction ( )
virtual

Prints the next simulated instruction to the simulator console.

Definition at line 228 of file SimControlLanguageCommand.cc.

228  {
229 
230  if (simulatorFrontend().nextInstructionPrinting())
232  << std::endl;
233 }

References outputStream(), SimulatorFrontend::programLocationDescription(), and simulatorFrontend().

Referenced by NextiCommand::execute(), UntilCommand::execute(), StepiCommand::execute(), and printStopInformation().

Here is the call graph for this function:

◆ printSimulationTime()

void SimControlLanguageCommand::printSimulationTime ( )
virtual

Prints the simulation time in minutes and seconds in case it's enabled.

Also prints out the frequency in MHz

Definition at line 322 of file SimControlLanguageCommand.cc.

322  {
323 
324  if (!simulatorFrontend().simulationTimeStatistics())
325  return;
326 
328  double time = simulatorFrontend().lastRunTime();
329 
330  double minutes = 0.0;
331  double seconds = modf(time / 60.0 , &minutes) * 60.0;
332  double frequency = (static_cast<double>(cycleCount) / time) / 1000000;
333 
334 
335  outputStream()
336  << minutes << " min "
337  << seconds << " s "
338  << frequency << " MHz" << std::endl;
339 }

References SimulatorFrontend::lastRunCycleCount(), SimulatorFrontend::lastRunTime(), outputStream(), and simulatorFrontend().

Referenced by StepiCommand::execute(), UntilCommand::execute(), and printStopInformation().

Here is the call graph for this function:

◆ printStopInformation()

void SimControlLanguageCommand::printStopInformation ( )
virtual

Prints information that should be printed after simulation is stopped.

These should be printed when the control is returned back to user after running simulation with "run" or "resume" commands and being stopped due to simulation finish or a breakpoint.

Definition at line 243 of file SimControlLanguageCommand.cc.

243  {
244 
248 }

References printNextInstruction(), printSimulationTime(), and printStopReasons().

Referenced by ResumeCommand::execute(), and RunCommand::execute().

Here is the call graph for this function:

◆ printStopReasons()

void SimControlLanguageCommand::printStopReasons ( )
virtual

Prints the reasons why simulation has been stopped.

Todo:
the stop reason code to string conversion should be externalized to another function.

Definition at line 257 of file SimControlLanguageCommand.cc.

257  {
258  for (unsigned int i = 0; i < simulatorFrontend().stopReasonCount(); ++i) {
259  switch (simulatorFrontend().stopReason(i)) {
260  case SRE_AFTER_STEPPING:
261  outputStream()
263  Texts::TXT_STOPREASON_STEPPING).str() << std::endl;
264  break;
265  case SRE_AFTER_UNTIL:
266  outputStream()
268  Texts::TXT_STOPREASON_UNTIL).str() << std::endl;
269  break;
270  case SRE_AFTER_TIMEOUT:
271  outputStream()
273  Texts::TXT_STOPREASON_TIMEOUT).str() << std::endl;
274  break;
275  case SRE_USER_REQUESTED:
276  outputStream()
278  Texts::TXT_STOPREASON_USERREQUEST).str() << std::endl;
279  break;
280  case SRE_RUNTIME_ERROR:
281  outputStream()
283  Texts::TXT_STOPREASON_RUNTIME_ERROR).str() << std::endl;
284  break;
285  case SRE_BREAKPOINT: {
286  StopPointManager& stopPointManager =
288  for (unsigned int i = 0;
289  i < stopPointManager.stopCausingStopPointCount(); ++i) {
290  try {
291  // test that the breakpoint is not deleted
292  stopPointManager.stopPointWithHandleConst(
293  stopPointManager.stopCausingStopPoint(i));
294  outputStream()
297  stopPointManager.stopCausingStopPoint(i)).str()
298  << std::endl;
299  } catch (const InstanceNotFound&) {
300  outputStream()
303  << std::endl;
304  }
305  }
306  break;
307  }
308  default:
309  outputStream()
310  << "Stopped because of an unknown reason." << std::endl;
311  break;
312  }
313  }
314 }

References outputStream(), simulatorFrontend(), SRE_AFTER_STEPPING, SRE_AFTER_TIMEOUT, SRE_AFTER_UNTIL, SRE_BREAKPOINT, SRE_RUNTIME_ERROR, SRE_USER_REQUESTED, StopPointManager::stopCausingStopPoint(), StopPointManager::stopCausingStopPointCount(), SimulatorFrontend::stopPointManager(), StopPointManager::stopPointWithHandleConst(), SimulatorFrontend::stopReason(), SimulatorFrontend::stopReasonCount(), Texts::TextGenerator::text(), SimulatorToolbox::textGenerator(), Texts::TXT_STOPREASON_BREAKPOINT, Texts::TXT_STOPREASON_DELETED_BREAKPOINT, Texts::TXT_STOPREASON_RUNTIME_ERROR, Texts::TXT_STOPREASON_STEPPING, Texts::TXT_STOPREASON_TIMEOUT, Texts::TXT_STOPREASON_UNTIL, and Texts::TXT_STOPREASON_USERREQUEST.

Referenced by InfoProgramCommand::execute(), and printStopInformation().

Here is the call graph for this function:

◆ setErrorMessage()

void SimControlLanguageCommand::setErrorMessage ( const TCEString errorMsg)

Definition at line 738 of file SimControlLanguageCommand.cc.

738  {
739  DataObject* errorMessage = new DataObject();
740  errorMessage->setString(errorMsg);
741  interpreter()->setResult(errorMessage);
742 }

References CustomCommand::interpreter(), ScriptInterpreter::setResult(), and DataObject::setString().

Referenced by BackTraceCommand::execute().

Here is the call graph for this function:

◆ setMemoryAddress()

bool SimControlLanguageCommand::setMemoryAddress ( const std::string &  addressString,
std::string &  addressSpaceName,
std::size_t &  memoryAddress 
)
protected

Parses the address string to corresponding memory address and address space.

Parameters
addressStringMemory address command string to parse.
addressSpaceNameAddress space name to be set.
memoryAddressMemory address to be set.
Returns
true on success.

Definition at line 753 of file SimControlLanguageCommand.cc.

756  {
757 
758  try {
759  const TTAProgram::Address& parsedAddress =
760  parseDataAddressExpression(addressString);
761  if (&parsedAddress.space() !=
763  addressSpaceName = parsedAddress.space().name();
764  }
765  memoryAddress = parsedAddress.location();
766  } catch(const IllegalParameters& n) {
767  return false;
768  }
769  return true;
770 }

References TTAMachine::NullAddressSpace::instance(), TTAProgram::Address::location(), TTAMachine::Component::name(), parseDataAddressExpression(), and TTAProgram::Address::space().

Referenced by MemDumpCommand::execute(), and MemWriteCommand::execute().

Here is the call graph for this function:

◆ setMemoryPointer()

bool SimControlLanguageCommand::setMemoryPointer ( MemorySystem::MemoryPtr memory,
const std::string &  addressSpaceName 
)
protected

Sets memory instance from a given AddressSpaceName to given memory.

Parameters
memoryMemory pointer to be set
addressSpaceNameThe name of the address space.
Returns
true on success.

must have the address space defined

Definition at line 780 of file SimControlLanguageCommand.cc.

782  {
783 
784  if (simulatorFrontend().memorySystem().memoryCount() < 1) {
788  return false;
789  } else if (simulatorFrontend().memorySystem().memoryCount() == 1) {
790  memory = simulatorFrontend().memorySystem().memory(0);
791  } else {
792  /// must have the address space defined
793  if (addressSpaceName == "") {
797  return false;
798  }
799  try {
800  memory =
801  simulatorFrontend().memorySystem().memory(addressSpaceName);
802  } catch (const InstanceNotFound&) {
806  return false;
807  }
808  }
809  return true;
810 }

References CustomCommand::interpreter(), MemorySystem::memory(), SimulatorFrontend::memorySystem(), ScriptInterpreter::setError(), simulatorFrontend(), SimulatorToolbox::textGenerator(), Texts::TXT_ADDRESS_SPACE_NOT_FOUND, and Texts::TXT_NO_ADDRESS_SPACE_GIVEN.

Referenced by MemDumpCommand::execute(), and MemWriteCommand::execute().

Here is the call graph for this function:

◆ simulatorFrontend()

SimulatorFrontend & SimControlLanguageCommand::simulatorFrontend ( )

Returns the SimulatorFrontend instance stored in the context.

Returns
The SimulatorFrontend instance.

Definition at line 214 of file SimControlLanguageCommand.cc.

214  {
215 
216  assert(interpreter() != NULL);
217 
218  SimulatorInterpreterContext& interpreterContext =
219  dynamic_cast<SimulatorInterpreterContext&>(interpreter()->context());
220 
221  return interpreterContext.simulatorFrontend();
222 }

References assert, ScriptInterpreter::context(), CustomCommand::interpreter(), and SimulatorInterpreterContext::simulatorFrontend().

Referenced by checkMachineLoaded(), checkProgramLoaded(), checkSimulationEnded(), checkSimulationInitialized(), checkSimulationNotAlreadyRunning(), checkSimulationStopped(), ProgCommand::execute(), KillCommand::execute(), WatchCommand::execute(), DeleteBPCommand::execute(), BackTraceCommand::execute(), DisableBPCommand::execute(), StepiCommand::execute(), MemDumpCommand::execute(), BPCommand::execute(), UntilCommand::execute(), NextiCommand::execute(), ConditionCommand::execute(), ResumeCommand::execute(), RunCommand::execute(), EnableBPCommand::execute(), IgnoreCommand::execute(), TBPCommand::execute(), SymbolAddressCommand::execute(), SettingCommand::execute(), InfoRegistersCommand::execute(), InfoImmediatesCommand::execute(), InfoRegFilesCommand::execute(), InfoIunitsCommand::execute(), InfoBussesCommand::execute(), InfoPortsCommand::execute(), InfoSegmentsCommand::execute(), InfoFunitsCommand::execute(), InfoProcCommand::execute(), InfoStatsCommand::execute(), InfoProgramCommand::execute(), InfoBreakpointsCommand::execute(), parseDataAddressExpression(), parseInstructionAddressExpression(), printBreakpointInfo(), printNextInstruction(), printSimulationTime(), printStopReasons(), setMemoryPointer(), and verifyBreakpointHandles().

Here is the call graph for this function:

◆ simulatorFrontendConst()

const SimulatorFrontend& SimControlLanguageCommand::simulatorFrontendConst ( )

◆ verifyBreakpointHandles()

bool SimControlLanguageCommand::verifyBreakpointHandles ( const std::vector< DataObject > &  arguments,
std::size_t  startIndex = 1 
)

Verifies that the list of breakpoint ids are valid breakpoint handles.

A refactoring for error checking of the {enable,disable,delete}bp commands. Sets interpreter error in case invalid handles are found and returns false.

Parameters
argumentsThe arguments as given to the execute() of the command.
startIndexThe first argument to check.
Returns
true if all handles are valid.

Definition at line 712 of file SimControlLanguageCommand.cc.

714  {
715 
716  // verify that the breakpoints are found
717  for (size_t i = startIndex; i < arguments.size(); ++i) {
718  if (!checkPositiveIntegerArgument(arguments[i])) {
719  return false;
720  }
721  const unsigned int breakpointHandle = arguments[i].integerValue();
722  try {
723  StopPointManager& stopPointManager =
725  // just check that breakpoint is found with the handle
726  stopPointManager.stopPointWithHandleConst(breakpointHandle);
727  } catch (const InstanceNotFound&) {
731  return false;
732  }
733  }
734  return true;
735 }

References CustomCommand::checkPositiveIntegerArgument(), CustomCommand::interpreter(), ScriptInterpreter::setError(), simulatorFrontend(), SimulatorFrontend::stopPointManager(), StopPointManager::stopPointWithHandleConst(), SimulatorToolbox::textGenerator(), and Texts::TXT_BREAKPOINT_NOT_FOUND.

Referenced by DeleteBPCommand::execute(), EnableBPCommand::execute(), and DisableBPCommand::execute().

Here is the call graph for this function:

The documentation for this class was generated from the following files:
TTAMachine::NullAddressSpace::instance
static NullAddressSpace & instance()
Definition: NullAddressSpace.cc:62
SimulatorInterpreterContext
Definition: SimulatorInterpreterContext.hh:45
Texts::TXT_BREAKPOINT_NOT_FOUND
@ TXT_BREAKPOINT_NOT_FOUND
Definition: SimulatorTextGenerator.hh:186
TTAProgram::Scope::codeLabel
const CodeLabel & codeLabel(const std::string &name) const
Definition: Scope.cc:233
CustomCommand::name
std::string name() const
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
Breakpoint::setAddress
virtual void setAddress(InstructionAddress newAddress)
Definition: Breakpoint.cc:96
SimControlLanguageCommand::outputStream
virtual std::ostream & outputStream()
Definition: SimControlLanguageCommand.cc:351
SimControlLanguageCommand::checkSimulationStopped
bool checkSimulationStopped()
Definition: SimControlLanguageCommand.cc:135
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
NumberFormatException
Definition: Exception.hh:421
SimulatorFrontend::program
const TTAProgram::Program & program() const
Definition: SimulatorFrontend.cc:276
TTAProgram::Address
Definition: Address.hh:51
TTAProgram::Program::firstProcedure
Procedure & firstProcedure() const
Definition: Program.cc:213
Texts::TXT_STOPREASON_BREAKPOINT
@ TXT_STOPREASON_BREAKPOINT
Stop reason: breakpoint.
Definition: SimulatorTextGenerator.hh:170
SRE_USER_REQUESTED
@ SRE_USER_REQUESTED
User requested the simulation to stop explicitly, e.g., by pressing ctrl-c in the CLI.
Definition: SimulatorConstants.hh:66
Texts::TXT_STOPREASON_DELETED_BREAKPOINT
@ TXT_STOPREASON_DELETED_BREAKPOINT
Stop reason: temporary breakpoint.
Definition: SimulatorTextGenerator.hh:172
DataObject
Definition: DataObject.hh:50
SRE_AFTER_TIMEOUT
@ SRE_AFTER_TIMEOUT
Stopped after simulation timeout instruction.
Definition: SimulatorConstants.hh:63
SimControlLanguageCommand::parseDataAddressExpression
TTAProgram::Address parseDataAddressExpression(const std::string &expression)
Definition: SimControlLanguageCommand.cc:471
TclInterpreter
Definition: TclInterpreter.hh:52
SimControlLanguageCommand::printNextInstruction
virtual void printNextInstruction()
Definition: SimControlLanguageCommand.cc:228
Texts::TXT_ADDRESS_SPACE_NOT_FOUND
@ TXT_ADDRESS_SPACE_NOT_FOUND
Definition: SimulatorTextGenerator.hh:193
ExpressionScript
Definition: ExpressionScript.hh:44
Texts::TXT_EXPRESSION_EMPTY
@ TXT_EXPRESSION_EMPTY
Definition: SimulatorTextGenerator.hh:189
CustomCommand::checkPositiveIntegerArgument
bool checkPositiveIntegerArgument(const DataObject &argument)
Definition: CustomCommand.cc:134
TTAProgram::Address::space
const TTAMachine::AddressSpace & space() const
SimulatorInterpreterContext::simulatorFrontend
SimulatorFrontend & simulatorFrontend()
Definition: SimulatorInterpreterContext.cc:61
TTAProgram::CodeSnippet::startAddress
virtual Address startAddress() const
Definition: CodeSnippet.cc:780
TclConditionScript
Definition: TclConditionScript.hh:50
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
TTAProgram::CodeLabel::address
virtual Address address() const
Definition: CodeLabel.cc:101
Texts::TXT_STOPREASON_USERREQUEST
@ TXT_STOPREASON_USERREQUEST
Stop reason: user requested.
Definition: SimulatorTextGenerator.hh:180
SimulatorFrontend::stopReasonCount
unsigned int stopReasonCount() const
Definition: SimulatorFrontend.cc:1344
SimControlLanguageCommand::printStopReasons
virtual void printStopReasons()
Definition: SimControlLanguageCommand.cc:257
Texts::TXT_INTERP_ENTER_CONDITION_PROMPT
@ TXT_INTERP_ENTER_CONDITION_PROMPT
Definition: SimulatorTextGenerator.hh:187
TTAProgram::Program::globalScopeConst
const GlobalScope & globalScopeConst() const
Definition: Program.cc:192
assert
#define assert(condition)
Definition: Application.hh:86
SimulatorFrontend::programCounter
InstructionAddress programCounter() const
Definition: SimulatorFrontend.cc:1169
StopPointManager::stopCausingStopPoint
unsigned int stopCausingStopPoint(unsigned int index) const
Definition: StopPointManager.cc:345
Texts::TXT_STOPREASON_RUNTIME_ERROR
@ TXT_STOPREASON_RUNTIME_ERROR
Stop reason: user requested.
Definition: SimulatorTextGenerator.hh:182
BPINFO_HANDLE_COL_WIDTH
const int BPINFO_HANDLE_COL_WIDTH
widths of the columns of the break point info table widths don't include the spaces between columns t...
Definition: SimControlLanguageCommand.cc:666
IllegalParameters
Definition: Exception.hh:113
Texts::TXT_INTERP_SIMULATION_NOT_RUNNING
@ TXT_INTERP_SIMULATION_NOT_RUNNING
Text to be printed when simulation is not running and it should be.
Definition: SimulatorTextGenerator.hh:137
StopPointManager::stopPointWithHandleConst
const StopPoint & stopPointWithHandleConst(unsigned int handle) const
Definition: StopPointManager.cc:248
Texts::TXT_INTERP_ENTER_EXPRESSION_PROMPT
@ TXT_INTERP_ENTER_EXPRESSION_PROMPT
Definition: SimulatorTextGenerator.hh:188
StopPoint
Definition: StopPoint.hh:53
SimControlLanguageCommand::parseInstructionAddressExpression
InstructionAddress parseInstructionAddressExpression(const std::string &expression)
Definition: SimControlLanguageCommand.cc:378
CustomCommand::CustomCommand
CustomCommand(std::string name)
Definition: CustomCommand.cc:48
SimControlLanguageCommand::askConditionFromUser
bool askConditionFromUser(TclConditionScript &target)
Definition: SimControlLanguageCommand.cc:513
StopPointManager
Definition: StopPointManager.hh:50
Texts::TXT_STOPREASON_STEPPING
@ TXT_STOPREASON_STEPPING
Stop reason: stepping.
Definition: SimulatorTextGenerator.hh:178
Texts::TXT_INTERP_SIMULATION_NOT_INITIALIZED
@ TXT_INTERP_SIMULATION_NOT_INITIALIZED
Text to be printed when simulation is not initialized and it should be.
Definition: SimulatorTextGenerator.hh:131
Texts::TXT_LABEL_NOT_FOUND
@ TXT_LABEL_NOT_FOUND
Definition: SimulatorTextGenerator.hh:184
Texts::TXT_ILLEGAL_ARGUMENTS
@ TXT_ILLEGAL_ARGUMENTS
Definition: TextGenerator.hh:67
Texts::TXT_STOPREASON_UNTIL
@ TXT_STOPREASON_UNTIL
Stop reason: until.
Definition: SimulatorTextGenerator.hh:174
__func__
#define __func__
Definition: Application.hh:67
SimulatorToolbox::textGenerator
static SimulatorTextGenerator & textGenerator()
Definition: SimulatorToolbox.cc:75
Texts::TXT_NO_PROGRAM_LOADED
@ TXT_NO_PROGRAM_LOADED
Definition: SimulatorTextGenerator.hh:202
StopPointManager::stopCausingStopPointCount
unsigned int stopCausingStopPointCount() const
Definition: StopPointManager.cc:368
Texts::TXT_INTERP_SIMULATION_NOT_ENDED
@ TXT_INTERP_SIMULATION_NOT_ENDED
Text to be printed when simulation has not ended and it should be.
Definition: SimulatorTextGenerator.hh:140
TTAProgram::GlobalScope
Definition: GlobalScope.hh:47
TTAProgram::Address::location
InstructionAddress location() const
SRE_RUNTIME_ERROR
@ SRE_RUNTIME_ERROR
A fatal runtime error occured in the simulated program.
Definition: SimulatorConstants.hh:68
SRE_BREAKPOINT
@ SRE_BREAKPOINT
Stopped because of at least one breakpoint.
Definition: SimulatorConstants.hh:65
SimControlLanguageCommand::checkSimulationInitialized
bool checkSimulationInitialized()
Definition: SimControlLanguageCommand.cc:88
SRE_AFTER_UNTIL
@ SRE_AFTER_UNTIL
Stopped after running to the wanted.
Definition: SimulatorConstants.hh:62
TTAProgram::Label::address
virtual Address address() const
Definition: Label.cc:84
LineReader::outputStream
virtual std::ostream & outputStream()
Definition: LineReader.cc:102
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
Texts::TXT_NO_ADDRESS_SPACE_GIVEN
@ TXT_NO_ADDRESS_SPACE_GIVEN
Definition: SimulatorTextGenerator.hh:197
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition: ScriptInterpreter.cc:128
StringTools::trim
static std::string trim(const std::string &source)
Definition: StringTools.cc:55
Conversion::toUnsignedInt
static unsigned int toUnsignedInt(const T &source)
Texts::TXT_INTERP_SIMULATION_ALREDY_RUNNING
@ TXT_INTERP_SIMULATION_ALREDY_RUNNING
Text to be printed when simulation is already running and it should not be.
Definition: SimulatorTextGenerator.hh:134
SimulatorFrontend::memorySystem
MemorySystem & memorySystem(int coreId=-1)
Definition: SimulatorFrontend.cc:2121
ScriptExecutionFailure
Definition: Exception.hh:657
SRE_AFTER_STEPPING
@ SRE_AFTER_STEPPING
Stopped after stepping the given count.
Definition: SimulatorConstants.hh:61
SimulatorFrontend::lastRunCycleCount
CycleCount lastRunCycleCount() const
Definition: SimulatorFrontend.cc:2276
MemorySystem::memory
MemoryPtr memory(const TTAMachine::AddressSpace &as)
Definition: MemorySystem.cc:170
TTAProgram::Scope::dataLabel
const DataLabel & dataLabel(const std::string &name) const
Definition: Scope.cc:251
SimulatorFrontend::stopReason
StopReason stopReason(unsigned int index) const
Definition: SimulatorFrontend.cc:1356
SimulatorFrontend::lastRunTime
double lastRunTime() const
Definition: SimulatorFrontend.cc:2289
TTAProgram::CodeSnippet::endAddress
virtual Address endAddress() const
Definition: CodeSnippet.cc:788
ClockCycleCount
CycleCount ClockCycleCount
Alias for ClockCycleCount.
Definition: SimulatorConstants.hh:57
SimulatorFrontend::programLocationDescription
std::string programLocationDescription() const
Definition: SimulatorFrontend.cc:1108
StopPoint::removeCondition
virtual void removeCondition()
Definition: StopPoint.cc:142
ScriptInterpreter::setError
virtual void setError(bool state)
Definition: ScriptInterpreter.cc:205
KeyNotFound
Definition: Exception.hh:285
Texts::TXT_STOPREASON_TIMEOUT
@ TXT_STOPREASON_TIMEOUT
Stop reason: timeout
Definition: SimulatorTextGenerator.hh:176
StopPoint::description
virtual std::string description() const =0
Definition: StopPoint.cc:239
TTAProgram::Program::lastProcedure
Procedure & lastProcedure() const
Definition: Program.cc:230
DataObject::setString
virtual void setString(std::string value)
Definition: DataObject.cc:130
SimControlLanguageCommand::simulatorFrontend
SimulatorFrontend & simulatorFrontend()
Definition: SimControlLanguageCommand.cc:214
TTAProgram::Program::procedure
Procedure & procedure(int index) const
Definition: Program.cc:622
ScriptInterpreter::lineReader
virtual LineReader * lineReader() const
Definition: ScriptInterpreter.cc:367
ScriptInterpreter::context
virtual InterpreterContext & context() const =0
StopPoint::setCondition
virtual void setCondition(const ConditionScript &condition)
Definition: StopPoint.cc:131
StringTools::stringToLower
static std::string stringToLower(const std::string &source)
Definition: StringTools.cc:160
SimulatorFrontend::stopPointManager
StopPointManager & stopPointManager()
Definition: SimulatorFrontend.cc:2108
InstanceNotFound
Definition: Exception.hh:304
SimControlLanguageCommand::printSimulationTime
virtual void printSimulationTime()
Definition: SimControlLanguageCommand.cc:322