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

#include <MemDumpCommand.hh>

Inheritance diagram for MemDumpCommand:
Inheritance graph
Collaboration diagram for MemDumpCommand:
Collaboration graph

Public Member Functions

 MemDumpCommand ()
 
virtual ~MemDumpCommand ()
 
virtual bool execute (const std::vector< DataObject > &arguments)
 
virtual std::string helpText () const
 
- Public Member Functions inherited from SimControlLanguageCommand
 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
 
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)
 

Additional Inherited Members

- Protected Member Functions inherited from SimControlLanguageCommand
bool setMemoryAddress (const std::string &addressString, std::string &addressSpaceName, std::size_t &memoryAddress)
 
bool setMemoryPointer (MemorySystem::MemoryPtr &memory, const std::string &addressSpaceName)
 

Detailed Description

Implementation of the "x" command of the Simulator Control Language.

Definition at line 47 of file MemDumpCommand.hh.

Constructor & Destructor Documentation

◆ MemDumpCommand()

MemDumpCommand::MemDumpCommand ( )

Constructor.

Sets the name of the command to the base class.

Definition at line 52 of file MemDumpCommand.cc.

52  :
54 }

◆ ~MemDumpCommand()

MemDumpCommand::~MemDumpCommand ( )
virtual

Destructor.

Does nothing.

Definition at line 61 of file MemDumpCommand.cc.

61  {
62 }

Member Function Documentation

◆ execute()

bool MemDumpCommand::execute ( const std::vector< DataObject > &  arguments)
virtual

Executes the "x" command.

This low-level command prints the data in memory starting at specified addresses addr.

Parameters
argumentsThe address to print.
Returns
True in case simulation is initialized and arguments are ok.
Exceptions
NumberFormatExceptionIs never thrown by this command.

Implements CustomCommand.

Definition at line 75 of file MemDumpCommand.cc.

75  {
76  static size_t displayedCount = 1;
77  static size_t lastDisplayedAddress = 0;
78  static size_t MAUsToDisplay = 1;
79 
80  const int argumentCount = arguments.size() - 1;
81  if (!checkArgumentCount(argumentCount, 0, 9)) {
82  return false;
83  }
84 
85  if (!checkProgramLoaded()) {
86  return false;
87  }
88 
89  bool illegalArguments = false;
90  size_t newDisplayedCount = displayedCount;
91  size_t newMAUCount = MAUsToDisplay;
92  size_t newDisplayedAddress = lastDisplayedAddress + MAUsToDisplay;
93  std::string addressSpaceName = "";
94  std::string fileName = "";
95  for (size_t i = 1; i < arguments.size(); ++i) {
96  if (StringTools::ciEqual(arguments.at(i).stringValue(), "/n")) {
97  if (i == arguments.size() - 1 ||
98  !checkUnsignedIntegerArgument(arguments.at(i + 1))) {
99  illegalArguments = true;
100  break;
101  }
102  newDisplayedCount =
103  static_cast<size_t>(arguments.at(i + 1).integerValue());
104  ++i;
105  } else if (StringTools::ciEqual(arguments.at(i).stringValue(), "/u")) {
106  if (i == arguments.size() - 1) {
107  illegalArguments = true;
108  break;
109  }
110  const std::string size = arguments.at(i + 1).stringValue();
111  if (StringTools::ciEqual(size, "b")) {
112  newMAUCount = 1;
113  } else if (StringTools::ciEqual(size, "h")) {
114  newMAUCount = 2;
115  } else if (StringTools::ciEqual(size, "w")) {
116  newMAUCount = 4;
117  } else {
118  illegalArguments = true;
119  break;
120  }
121  ++i;
122  } else if (StringTools::ciEqual(arguments.at(i).stringValue(), "/a")) {
123  if (i == arguments.size() - 1) {
124  illegalArguments = true;
125  break;
126  }
127  addressSpaceName = arguments.at(i + 1).stringValue();
128  ++i;
129  } else if (StringTools::ciEqual(arguments.at(i).stringValue(), "/f")) {
130  if (i == arguments.size() - 1) {
131  illegalArguments = true;
132  break;
133  }
134  fileName = arguments.at(i + 1).stringValue();
135  ++i;
136  } else if (i == arguments.size() - 1) {
137  const std::string addressString = arguments.at(i).stringValue();
138  if (!setMemoryAddress(
139  addressString, addressSpaceName, newDisplayedAddress)) {
140  return false;
141  }
142  } else {
143  illegalArguments = true;
144  break;
145  }
146  }
147 
148  if (illegalArguments) {
152  interpreter()->setError(true);
153  return false;
154  }
155 
156  displayedCount = newDisplayedCount;
157  lastDisplayedAddress = newDisplayedAddress;
158 
160  if (!setMemoryPointer(memory, addressSpaceName)) {
161  return false;
162  }
163 
164  size_t MAUSize;
165  if (simulatorFrontend().memorySystem().memoryCount() == 1) {
167  } else {
168  MAUSize =
170  addressSpace(addressSpaceName).width();
171  }
172 
173  if (MAUSize*newMAUCount > SIMULATOR_MAX_INTWORD_BITWIDTH) {
175  (boost::format("Maximum printable integer size %d.") %
177  interpreter()->setError(true);
178  return false;
179  }
180 
181  std::ofstream* out = NULL;
182  const bool dumpToFile = fileName != "";
183  if (dumpToFile) {
184  if (MAUSize != sizeof(char)*8) {
186  (boost::format(
187  "Can only dump 8 bit memories to files. The given "
188  "address space is %d.") % MAUSize).str());
189  interpreter()->setError(true);
190  return false;
191  }
192  newMAUCount = 1;
193  out = new std::ofstream(fileName.c_str(), std::ios::binary);
194  }
195 
196  MAUsToDisplay = newMAUCount;
197  DataObject* result = new DataObject("");
198  // read the wanted number (given with /n) of chunks of data to the result
199  while (newDisplayedCount > 0) {
200 
201  ULongWord data = 0;
202  try {
203  memory->read(newDisplayedAddress, MAUsToDisplay, data);
204  } catch (const OutOfRange&) {
208  interpreter()->setError(true);
209  return false;
210  }
211 
212 
213  newDisplayedCount--;
214  newDisplayedAddress += MAUsToDisplay;
215 
216  if (!dumpToFile) {
217  const int HEX_DIGITS = MAUSize*newMAUCount/4;
218  result->setString(
219  result->stringValue() +
220  Conversion::toHexString(data, HEX_DIGITS));
221 
222  if (newDisplayedCount > 0) {
223  result->setString(result->stringValue() + " ");
224  }
225  } else {
226  *out << (char)data;
227  }
228  }
229 
230  if (dumpToFile) {
231  out->close();
232  delete out;
233  out = NULL;
234  }
235  interpreter()->setResult(result);
236  return true;
237 }

References MemorySystem::addressSpace(), CustomCommand::checkArgumentCount(), SimControlLanguageCommand::checkProgramLoaded(), CustomCommand::checkUnsignedIntegerArgument(), StringTools::ciEqual(), CustomCommand::interpreter(), SimulatorFrontend::memorySystem(), ScriptInterpreter::setError(), SimControlLanguageCommand::setMemoryAddress(), SimControlLanguageCommand::setMemoryPointer(), ScriptInterpreter::setResult(), DataObject::setString(), SIMULATOR_MAX_INTWORD_BITWIDTH, SimControlLanguageCommand::simulatorFrontend(), DataObject::stringValue(), SimulatorToolbox::textGenerator(), Conversion::toHexString(), Texts::TXT_ADDRESS_OUT_OF_RANGE, Texts::TXT_ILLEGAL_ARGUMENTS, and TTAMachine::AddressSpace::width().

Here is the call graph for this function:

◆ helpText()

std::string MemDumpCommand::helpText ( ) const
virtual

Returns the help text for this command.

Help text is searched from SimulatorTextGenerator.

Returns
The help text.

Implements CustomCommand.

Definition at line 247 of file MemDumpCommand.cc.

247  {
250 }

References Texts::TextGenerator::text(), SimulatorToolbox::textGenerator(), and Texts::TXT_INTERP_HELP_X.

Here is the call graph for this function:

The documentation for this class was generated from the following files:
CustomCommand::checkArgumentCount
bool checkArgumentCount(int argumentCount, int minimum, int maximum)
Definition: CustomCommand.cc:82
DataObject
Definition: DataObject.hh:50
DataObject::stringValue
virtual std::string stringValue() const
Definition: DataObject.cc:344
SimControlLanguageCommand::setMemoryPointer
bool setMemoryPointer(MemorySystem::MemoryPtr &memory, const std::string &addressSpaceName)
Definition: SimControlLanguageCommand.cc:780
SIMULATOR_MAX_INTWORD_BITWIDTH
#define SIMULATOR_MAX_INTWORD_BITWIDTH
Definition: SimValue.hh:248
OutOfRange
Definition: Exception.hh:320
Texts::TXT_ADDRESS_OUT_OF_RANGE
@ TXT_ADDRESS_OUT_OF_RANGE
Definition: SimulatorTextGenerator.hh:192
SimControlLanguageCommand::checkProgramLoaded
bool checkProgramLoaded()
Definition: SimControlLanguageCommand.cc:180
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
SimControlLanguageCommand::setMemoryAddress
bool setMemoryAddress(const std::string &addressString, std::string &addressSpaceName, std::size_t &memoryAddress)
Definition: SimControlLanguageCommand.cc:753
MemorySystem::MemoryPtr
boost::shared_ptr< Memory > MemoryPtr
Definition: MemorySystem.hh:57
Texts::TXT_INTERP_HELP_X
@ TXT_INTERP_HELP_X
Help text for command "x" of the CLI.
Definition: SimulatorTextGenerator.hh:105
SimControlLanguageCommand::SimControlLanguageCommand
SimControlLanguageCommand(const std::string &name)
Definition: SimControlLanguageCommand.cc:67
Texts::TXT_ILLEGAL_ARGUMENTS
@ TXT_ILLEGAL_ARGUMENTS
Definition: TextGenerator.hh:67
CustomCommand::checkUnsignedIntegerArgument
bool checkUnsignedIntegerArgument(const DataObject &argument)
Definition: CustomCommand.cc:164
SimulatorToolbox::textGenerator
static SimulatorTextGenerator & textGenerator()
Definition: SimulatorToolbox.cc:75
StringTools::ciEqual
static bool ciEqual(const std::string &a, const std::string &b)
Definition: StringTools.cc:240
Conversion::toHexString
static std::string toHexString(T source, std::size_t digits=0, bool include0x=true)
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition: ScriptInterpreter.cc:128
TTAMachine::AddressSpace::width
virtual int width() const
Definition: AddressSpace.cc:155
SimulatorFrontend::memorySystem
MemorySystem & memorySystem(int coreId=-1)
Definition: SimulatorFrontend.cc:2121
ULongWord
unsigned long ULongWord
Definition: BaseType.hh:51
ScriptInterpreter::setError
virtual void setError(bool state)
Definition: ScriptInterpreter.cc:205
DataObject::setString
virtual void setString(std::string value)
Definition: DataObject.cc:130
SimControlLanguageCommand::simulatorFrontend
SimulatorFrontend & simulatorFrontend()
Definition: SimControlLanguageCommand.cc:214
MemorySystem::addressSpace
const TTAMachine::AddressSpace & addressSpace(unsigned int i)
Definition: MemorySystem.cc:261