OpenASIP  2.0
BackTraceCommand.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2010 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file BackTraceCommand.cc
26  *
27  * Implementation of BackTraceCommand class
28  *
29  * @author Pekka Jääskeläinen 2010
30  * @note rating: red
31  */
32 
33 #include "BackTraceCommand.hh"
35 #include "CallPathTracker.hh"
36 #include "Procedure.hh"
37 #include "Program.hh"
38 #include "Instruction.hh"
39 
41 }
42 
44 }
45 
46 bool
47 BackTraceCommand::execute(const std::vector<DataObject>& arguments) {
48  if (!checkArgumentCount(arguments.size() - 1, 0, 0)) {
49  return false;
50  }
51 
52  if (!checkSimulationStopped()) {
53  return false;
54  }
55 
56  SimulatorInterpreterContext& interpreterContext =
57  dynamic_cast<SimulatorInterpreterContext&>(interpreter()->context());
58 
60  interpreterContext.simulatorFrontend();
61 
64  "Call history logging not enabled.\n"
65  "Use 'setting call_history_length' to enable.");
66  return false;
67  }
68 
70 
71 #if 0
72  // move this to a separate call_path command or similar
73  const CallPathTracker::ProcedureTransferQueue& callHistory =
74  cpt.transfers();
75 
76  for (CallPathTracker::ProcedureTransferQueue::const_iterator i =
77  callHistory.begin(); i != callHistory.end(); ++i) {
79  TCEString procName =
80  dynamic_cast<const TTAProgram::Procedure&>(
82  parent()).name();
83  if (tr.isEntry) {
84  outputStream()
85  << "called ";
86  } else {
87  outputStream()
88  << "returned to ";
89  }
90  outputStream()
91  << procName << "@" << tr.sourceAddress << std::endl;
92  }
93 #endif
94 
96  cpt.backTrace();
97  int callLevel = 0;
98  CallPathTracker::ProcedureTransferQueue::const_iterator i =
99  calls.begin();
100  for (; i != calls.end(); ++i) {
102  TCEString procName =
103  dynamic_cast<const TTAProgram::Procedure&>(
105  parent()).name();
106  assert(tr.isEntry);
107  outputStream()
108  << "#" << callLevel << " called "
109  << procName << "@" << tr.sourceAddress << std::endl;
110  ++callLevel;
111  }
112 
113  return true;
114 }
115 
116 std::string
118  return std::string(
119  "Prints the current call stack (back trace).\n"
120  "Requires call history saving to be on.\n"
121  "See 'setting call_history_length'.");
122 }
123 
SimulatorFrontend::callPathTracker
const CallPathTracker & callPathTracker(int core=-1) const
Definition: SimulatorFrontend.cc:2393
CallPathTracker.hh
BackTraceCommand.hh
SimulatorInterpreterContext
Definition: SimulatorInterpreterContext.hh:45
CustomCommand::checkArgumentCount
bool checkArgumentCount(int argumentCount, int minimum, int maximum)
Definition: CustomCommand.cc:82
CustomCommand::name
std::string name() const
SimControlLanguageCommand::outputStream
virtual std::ostream & outputStream()
Definition: SimControlLanguageCommand.cc:351
SimControlLanguageCommand::checkSimulationStopped
bool checkSimulationStopped()
Definition: SimControlLanguageCommand.cc:135
SimulatorFrontend::program
const TTAProgram::Program & program() const
Definition: SimulatorFrontend.cc:276
SimulatorInterpreterContext.hh
CallPathTracker::ProcedureTransfer::sourceAddress
InstructionAddress sourceAddress
Definition: CallPathTracker.hh:56
SimulatorFrontend::callHistoryLength
std::size_t callHistoryLength() const
Definition: SimulatorFrontend.hh:267
Procedure.hh
CallPathTracker::transfers
const ProcedureTransferQueue & transfers() const
Definition: CallPathTracker.hh:76
SimulatorInterpreterContext::simulatorFrontend
SimulatorFrontend & simulatorFrontend()
Definition: SimulatorInterpreterContext.cc:61
CallPathTracker::ProcedureTransferQueue
std::deque< ProcedureTransfer > ProcedureTransferQueue
Definition: CallPathTracker.hh:60
CallPathTracker
Definition: CallPathTracker.hh:51
SimControlLanguageCommand::setErrorMessage
void setErrorMessage(const TCEString &errorMsg)
Definition: SimControlLanguageCommand.cc:738
assert
#define assert(condition)
Definition: Application.hh:86
CallPathTracker::ProcedureTransfer::address
InstructionAddress address
Definition: CallPathTracker.hh:55
TTAProgram::Program::instructionAt
Instruction & instructionAt(InstructionAddress address) const
Definition: Program.cc:374
Instruction.hh
BackTraceCommand::~BackTraceCommand
virtual ~BackTraceCommand()
Definition: BackTraceCommand.cc:43
BackTraceCommand::BackTraceCommand
BackTraceCommand()
Definition: BackTraceCommand.cc:40
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
CallPathTracker::ProcedureTransfer
Definition: CallPathTracker.hh:53
BackTraceCommand::helpText
virtual std::string helpText() const
Definition: BackTraceCommand.cc:117
BackTraceCommand::execute
virtual bool execute(const std::vector< DataObject > &arguments)
Definition: BackTraceCommand.cc:47
Program.hh
TCEString
Definition: TCEString.hh:53
CallPathTracker::ProcedureTransfer::isEntry
bool isEntry
Definition: CallPathTracker.hh:57
CallPathTracker::backTrace
const ProcedureTransferQueue backTrace() const
Definition: CallPathTracker.cc:54
SimControlLanguageCommand
Definition: SimControlLanguageCommand.hh:63
SimControlLanguageCommand::simulatorFrontend
SimulatorFrontend & simulatorFrontend()
Definition: SimControlLanguageCommand.cc:214
TTAProgram::Procedure
Definition: Procedure.hh:55
SimulatorFrontend
Definition: SimulatorFrontend.hh:89
ScriptInterpreter::context
virtual InterpreterContext & context() const =0