OpenASIP 2.2
Loading...
Searching...
No Matches
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.

◆ ~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 =
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 {
109 arguments[1].stringValue());
110
111 if (arguments.size() == 3) {
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}
#define assert(condition)
bool checkArgumentCount(int argumentCount, int minimum, int maximum)
ScriptInterpreter * interpreter() const
virtual InterpreterContext & context() const =0
virtual void setError(bool state)
InstructionAddress parseInstructionAddressExpression(const std::string &expression)
virtual std::ostream & outputStream()
const TTAProgram::Procedure & currentProcedure() const
std::string disassembleInstruction(UIntWord instructionAddress) const
const TTAProgram::Program & program() const
InstructionAddress location() const
virtual Address endAddress() const
virtual Address startAddress() const
virtual Instruction & lastInstruction() const
Address address() const
CodeSnippet & parent() const
Instruction & instructionAt(InstructionAddress address) const
Definition Program.cc:374
Procedure & lastProcedure() const
Definition Program.cc:230

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}
static SimulatorTextGenerator & textGenerator()
virtual boost::format text(int textId)
@ TXT_INTERP_HELP_DISASSEMBLE
Help text for command "disassemble" of the CLI.

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: