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

#include <DisassembleCommand.hh>

Inheritance diagram for DisassembleCommand:
Inheritance graph
Collaboration diagram for DisassembleCommand:
Collaboration graph

Public Member Functions

 DisassembleCommand ()
 
virtual ~DisassembleCommand ()
 
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 "disassemble" command of the Simulator Control Language.

Definition at line 48 of file DisassembleCommand.hh.

Constructor & Destructor Documentation

◆ DisassembleCommand()

DisassembleCommand::DisassembleCommand ( )

Constructor.

Sets the name of the command to the base class.

Definition at line 58 of file DisassembleCommand.cc.

58  :
59  SimControlLanguageCommand("disassemble") {
60 }

◆ ~DisassembleCommand()

DisassembleCommand::~DisassembleCommand ( )
virtual

Destructor.

Does nothing.

Definition at line 67 of file DisassembleCommand.cc.

67  {
68 }

Member Function Documentation

◆ execute()

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

Executes the "disassemble" command.

Prints a range of meory addresses as machine instructions. When two arguments addr1, addr2 are given, addr1 specifies the first address of the range to display, and addr2 specifies the last address (not displayed). If only one argument, addr1, is given, then the function that contains addr1 is disassembled. If no argument is given, the default memory range is the function surrounding the program counter of the selected frame.

Parameters
argumentsThe range of instruction memory to disassemble.
Returns
Always true if arguments are valid.

Implements CustomCommand.

Definition at line 84 of file DisassembleCommand.cc.

84  {
85  assert(interpreter() != NULL);
86 
87  if (!checkArgumentCount(arguments.size() - 1, 0, 2)) {
88  return false;
89  }
90 
91  if (!checkProgramLoaded()) {
92  return false;
93  }
94 
95  SimulatorInterpreterContext& interpreterContext =
96  dynamic_cast<SimulatorInterpreterContext&>(interpreter()->context());
97 
98  SimulatorFrontend& simFront = interpreterContext.simulatorFrontend();
99 
100  int firstAddress = -1;
101  int lastAddress = -1;
102 
103  const int programLastAddress =
104  simFront.program().lastProcedure().endAddress().location() - 1;
105 
106  if (arguments.size() > 1) {
107  try {
108  firstAddress = parseInstructionAddressExpression(
109  arguments[1].stringValue());
110 
111  if (arguments.size() == 3) {
112  lastAddress = parseInstructionAddressExpression(
113  arguments[2].stringValue());
114  }
115  } catch (const IllegalParameters&) {
116  return false;
117  }
118  }
119 
120  if (firstAddress > programLastAddress) {
121  firstAddress = programLastAddress;
122  }
123 
124 
125  for (auto addr : { firstAddress, lastAddress }) {
126  try {
127  if (addr != -1)
128  simFront.program().instructionAt(addr);
129  } catch (KeyNotFound& e) {
130  interpreter()->setError("No instruction at address "
131  + std::to_string(addr) + ".");
132  return false;
133  }
134  }
135 
136  if (firstAddress == -1 && lastAddress == -1) {
137  firstAddress = simFront.currentProcedure().startAddress().location();
138  lastAddress =
140  } else if (firstAddress != -1 && lastAddress == -1) {
141  const Procedure& procedureAtAddress =
142  dynamic_cast<const Procedure&>(
143  simFront.program().instructionAt(firstAddress).parent());
144  firstAddress = procedureAtAddress.startAddress().location();
145  lastAddress =
146  procedureAtAddress.lastInstruction().address().location();
147  }
148 
149  if (lastAddress < 0) {
150  lastAddress = 0;
151  }
152 
153  if (lastAddress > programLastAddress) {
154  lastAddress = programLastAddress;
155  }
156 
157  if (lastAddress < firstAddress) {
158  lastAddress = firstAddress;
159  }
160 
161  try {
162  for (; firstAddress <= lastAddress; firstAddress +=
163  simFront.program().instructionAt(firstAddress).size()) {
164  outputStream() << simFront.disassembleInstruction(firstAddress)
165  << std::endl;
166  }
167  } catch (KeyNotFound& e) {
168  interpreter()->setError("No instruction at address "
169  + std::to_string(firstAddress) + ".");
170  return false;
171  }
172 
173  return true;
174 }

References TTAProgram::Instruction::address(), assert, CustomCommand::checkArgumentCount(), SimControlLanguageCommand::checkProgramLoaded(), ScriptInterpreter::context(), SimulatorFrontend::currentProcedure(), SimulatorFrontend::disassembleInstruction(), TTAProgram::CodeSnippet::endAddress(), TTAProgram::Program::instructionAt(), CustomCommand::interpreter(), TTAProgram::CodeSnippet::lastInstruction(), TTAProgram::Program::lastProcedure(), TTAProgram::Address::location(), SimControlLanguageCommand::outputStream(), TTAProgram::Instruction::parent(), SimControlLanguageCommand::parseInstructionAddressExpression(), SimulatorFrontend::program(), ScriptInterpreter::setError(), SimulatorInterpreterContext::simulatorFrontend(), TTAProgram::Instruction::size(), and TTAProgram::CodeSnippet::startAddress().

Here is the call graph for this function:

◆ helpText()

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

Returns the help text for this command.

Help text is searched from SimulatorTextGenerator.

Returns
The help text.
Todo:
Use SimulatorTextGenerator to get the help text.

Implements CustomCommand.

Definition at line 185 of file DisassembleCommand.cc.

185  {
188 }

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

Here is the call graph for this function:

The documentation for this class was generated from the following files:
SimulatorInterpreterContext
Definition: SimulatorInterpreterContext.hh:45
CustomCommand::checkArgumentCount
bool checkArgumentCount(int argumentCount, int minimum, int maximum)
Definition: CustomCommand.cc:82
SimControlLanguageCommand::outputStream
virtual std::ostream & outputStream()
Definition: SimControlLanguageCommand.cc:351
SimulatorFrontend::program
const TTAProgram::Program & program() const
Definition: SimulatorFrontend.cc:276
Texts::TXT_INTERP_HELP_DISASSEMBLE
@ TXT_INTERP_HELP_DISASSEMBLE
Help text for command "disassemble" of the CLI.
Definition: SimulatorTextGenerator.hh:67
SimControlLanguageCommand::checkProgramLoaded
bool checkProgramLoaded()
Definition: SimControlLanguageCommand.cc:180
SimulatorInterpreterContext::simulatorFrontend
SimulatorFrontend & simulatorFrontend()
Definition: SimulatorInterpreterContext.cc:61
TTAProgram::CodeSnippet::startAddress
virtual Address startAddress() const
Definition: CodeSnippet.cc:780
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
assert
#define assert(condition)
Definition: Application.hh:86
TTAProgram::Program::instructionAt
Instruction & instructionAt(InstructionAddress address) const
Definition: Program.cc:374
SimControlLanguageCommand::SimControlLanguageCommand
SimControlLanguageCommand(const std::string &name)
Definition: SimControlLanguageCommand.cc:67
IllegalParameters
Definition: Exception.hh:113
SimControlLanguageCommand::parseInstructionAddressExpression
InstructionAddress parseInstructionAddressExpression(const std::string &expression)
Definition: SimControlLanguageCommand.cc:378
SimulatorToolbox::textGenerator
static SimulatorTextGenerator & textGenerator()
Definition: SimulatorToolbox.cc:75
TTAProgram::Instruction::parent
CodeSnippet & parent() const
Definition: Instruction.cc:109
TTAProgram::CodeSnippet::lastInstruction
virtual Instruction & lastInstruction() const
Definition: CodeSnippet.cc:387
TTAProgram::Address::location
InstructionAddress location() const
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
SimulatorFrontend::currentProcedure
const TTAProgram::Procedure & currentProcedure() const
Definition: SimulatorFrontend.cc:1210
TTAProgram::Instruction::size
short size() const
Definition: Instruction.cc:365
SimulatorFrontend::disassembleInstruction
std::string disassembleInstruction(UIntWord instructionAddress) const
Definition: SimulatorFrontend.cc:1073
TTAProgram::CodeSnippet::endAddress
virtual Address endAddress() const
Definition: CodeSnippet.cc:788
ScriptInterpreter::setError
virtual void setError(bool state)
Definition: ScriptInterpreter.cc:205
KeyNotFound
Definition: Exception.hh:285
TTAProgram::Program::lastProcedure
Procedure & lastProcedure() const
Definition: Program.cc:230
TTAProgram::Procedure
Definition: Procedure.hh:55
SimulatorFrontend
Definition: SimulatorFrontend.hh:89
ScriptInterpreter::context
virtual InterpreterContext & context() const =0
TTAProgram::Instruction::address
Address address() const
Definition: Instruction.cc:327