OpenASIP 2.2
Loading...
Searching...
No Matches
ProximDebuggerWindow.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2016 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 ProximDebuggerWindow.cc
26 *
27 * Definition of ProximDebuggerWindow class.
28 *
29 * @author Alex Hirvonen 2016 (alex.hirvonen-no.spam-gmail.com)
30 * @note rating: red
31 */
32
33
34#include <wx/sizer.h>
35#include <wx/textctrl.h>
36
38#include "ProximToolbox.hh"
39#include "Proxim.hh"
42#include "Machine.hh"
43#include "Program.hh"
44#include "Instruction.hh"
45#include "Move.hh"
46#include "WxConversion.hh"
47#include "ErrorDialog.hh"
48
49using namespace TTAProgram;
50
54 EVT_CHOICE(ID_SOURCEFILE_CHOICE, ProximDebuggerWindow::onSourceFileChoice)
56
57
59 ProximMainFrame* parent, int id):
60 ProximSimulatorWindow(parent, id, wxDefaultPosition, wxSize(800,600)),
61 currentFile_() {
62
63 createContents(this, true, true);
64 loadProgram(ProximToolbox::program());
65}
66
67
70
71
72/**
73 * Resets the window when a new program or machine is being loaded in the
74 * simulator.
75 */
76void
78 sourceFileList_->Clear();
79 sourceCodeText_->Clear();
80 currentFile_.clear();
81 currentLineNums_.clear();
82}
83
84
85/**
86 * Loads a program model to the window.
87 *
88 * @param program Program to load.
89 */
90void
92 // get list of used source code files for drop-down list
93 for (int i = 0; i < program.moveCount(); i++) {
94
95 const TTAProgram::Move& m = program.moveAt(i);
96
97 if (m.hasSourceFileName()) {
98 wxString sourceFile = WxConversion::toWxString(m.sourceFileName());
99
100 if (sourceFileList_->FindString(sourceFile) == -1) {
101 sourceFileList_->Append(sourceFile);
102 }
103 }
104 }
105
106 // load first file from drop-down list and set hilights
107 if (sourceFileList_->GetCount() > 0) {
108 loadSourceCode(sourceFileList_->GetString(0));
110 } else {
111 ErrorDialog dialog(
112 this, _T("No debugging information available."));
113 dialog.ShowModal();
114 }
115}
116
117
118/**
119 * Parses possible annotations in the current instruction and hilights
120 * source code lines.
121 */
122void
124
125 Word pc = wxGetApp().simulation()->frontend()->programCounter();
126
127 const TTAProgram::Instruction& instruction =
129
130 // check annotations and hilight possible lines
131 for (int i = 0; i < instruction.moveCount(); i++) {
132 const TTAProgram::Move& m = instruction.move(i);
133
134 if (m.hasSourceLineNumber()) {
135 wxString sourceFile = WxConversion::toWxString(m.sourceFileName());
136 if (sourceFile == currentFile_) {
138 }
139 }
140 }
141 // make last higlighted line visible
142 if (currentLineNums_.size() > 0) {
144 }
145}
146
147
148
149/**
150 * Loads source code into the sourceCodeText_ widget
151 *
152 * @param sourceFile Absolute file location as wxString.
153 */
154void
156
157 sourceCodeText_->LoadFile(sourceFile);
158 currentFile_ = sourceFile;
159 sourceFileList_->SetSelection(sourceFileList_->FindString(sourceFile));
160}
161
162
163/**
164 * Sets certain style attributes to the line in sourceCodeText_ widget
165 *
166 * @param lineNum Line number
167 * @param style Style attributes (text color, background color, font, alignment)
168 */
169void
170ProximDebuggerWindow::setLineAttributes(int lineNum, wxTextAttr style) {
171
172 long lineStart = sourceCodeText_->XYToPosition(0, lineNum - 1);
173 long lineEnd = lineStart + sourceCodeText_->GetLineLength(lineNum - 1);
174
175 sourceCodeText_->SetStyle(lineStart, lineEnd, style);
176}
177
178
179/**
180 * Highlights line of code in the sourceCodeText_ widget
181 *
182 * @param lineNum Source code line number.
183 */
184void
186
187 if (std::find(currentLineNums_.begin(), currentLineNums_.end(), lineNum) ==
188 currentLineNums_.end()) {
189
190 currentLineNums_.push_back(lineNum);
191 setLineAttributes(lineNum, wxTextAttr(*wxWHITE, *wxBLUE));
192 }
193}
194
195
196/**
197 * Makes line visible in the sourceCodeText_ widget
198 *
199 * @param lineNum Source code line number.
200 */
201void
203 sourceCodeText_->ShowPosition(sourceCodeText_->XYToPosition(0,lineNum - 1));
204}
205
206
207/**
208 * Event handler which is called when a new program is loaded in the simulator.
209 */
210void
214
215
216/**
217 * Event handler which is called when simulation step ends.
218 */
219void
221 // unhilight old lines
222 for (int lineNum : currentLineNums_) {
223 setLineAttributes(lineNum, wxTextAttr(*wxBLACK, *wxWHITE));
224 }
225 currentLineNums_.clear();
226
228}
229
230
231/**
232 * Event handler for drop-down list selection.
233 *
234 * Loads selected source code from the drop-down list.
235 */
236void
238 loadSourceCode(sourceFileList_->GetString(sourceFileList_->GetSelection()));
239 currentLineNums_.clear();
241}
242
243
244/**
245 * Creates the window contents.
246 *
247 * Code generated by wxDesigner.
248 */
249wxSizer*
251 wxWindow *parent, bool call_fit, bool set_sizer) {
252
253 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
254
255 wxBoxSizer *upperSizer = new wxBoxSizer(wxHORIZONTAL);
256 sourceFileList_ = new wxChoice(
257 parent, ID_SOURCEFILE_CHOICE, wxDefaultPosition, wxDefaultSize);
258
259 upperSizer->Add(sourceFileList_, 1, wxGROW|wxALL, 5);
260 mainSizer->Add(upperSizer, 0, wxGROW|wxALL, 5);
261
262 sourceCodeText_ = new wxTextCtrl(
263 parent, ID_SOURCECODE, wxEmptyString, wxDefaultPosition,
264 wxSize(640, 600), wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP);
265
266 mainSizer->Add(sourceCodeText_, 1, wxGROW|wxALL, 5);
267
268 if (set_sizer)
269 {
270 parent->SetSizer( mainSizer );
271 if (call_fit)
272 mainSizer->SetSizeHints( parent );
273 }
274
275 return mainSizer;
276}
END_EVENT_TABLE() using namespace IDF
find Finds info of the inner loops in the program
#define EVT_SIMULATOR_PROGRAM_LOADED(id, fn)
#define EVT_SIMULATOR_STOP(id, fn)
void setLineAttributes(int lineNum, wxTextAttr style)
void onSourceFileChoice(wxCommandEvent &event)
void loadProgram(const TTAProgram::Program &program)
void highlightLine(int lineNum)
void loadSourceCode(wxString sourceFile)
void onProgramLoaded(const SimulatorEvent &event)
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
std::vector< int > currentLineNums_
void onSimulationStop(const SimulatorEvent &event)
static const TTAProgram::Program & program()
Move & move(int i) const
bool hasSourceLineNumber() const
Definition Move.cc:445
int sourceLineNumber() const
Definition Move.cc:459
bool hasSourceFileName() const
Definition Move.cc:478
std::string sourceFileName() const
Definition Move.cc:488
Instruction & instructionAt(InstructionAddress address) const
Definition Program.cc:374
static wxString toWxString(const std::string &source)