2 // SourcesWin.cpp - Sources tracing window
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
9 // --- ---------- -------------------------------------------------------------
10 // JPM 08/23/2019 Created this file
17 #include "DBGManager.h"
18 #include "debugger/SourceCWin.h"
19 #include "debugger/SourcesWin.h"
20 #include "m68000/m68kinterface.h"
24 SourcesWindow::SourcesWindow(QWidget
* parent
/*= 0*/) : QWidget(parent
, Qt::Dialog
),
25 layout(new QVBoxLayout
),
26 sourcestabWidget(new QTabWidget
),
31 OldCurrentNumLineSrc(0),
36 sourcestabWidget
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Expanding
);
37 sourcestabWidget
->setTabsClosable(true);
38 layout
->addWidget(sourcestabWidget
);
43 // Connect the signals
44 connect(sourcestabWidget
, SIGNAL(currentChanged(const int)), this, SLOT(SelectTab(const int)));
45 connect(sourcestabWidget
, SIGNAL(tabCloseRequested(const int)), this, SLOT(CloseTab(const int)));
50 void SourcesWindow::CloseTab(const int)
57 void SourcesWindow::SelectTab(const int)
61 QString t
= sourcestabWidget
->tabText(index
);
62 while ((i
< NbSourcesInfos
) && strcmp(sourcesinfostab
[i
++].Filename
, t
.toLatin1().data()));
64 if ((i
!= NbSourcesInfos
) && (sourcesinfostab
[i
- 1].IndexTab
!= -1) && (CurrentTab
== (i
- 1)))
66 sourcesinfostab
[(i
- 1)].sourceCtab
->RefreshContents();
72 // Sources initialisation
73 void SourcesWindow::Init(void)
78 // Get number of sources
79 NbSourcesInfos
= DBGManager_GetNbSources();
82 // Alloc structure for the source informations
83 sourcesinfostab
= (SourcesInfos
*)calloc(NbSourcesInfos
, sizeof(SourcesInfos
));
85 // Fill sources information
86 for (i
= 0; i
< NbSourcesInfos
; i
++)
88 // Get source filename without misguiding information
89 Ptr
= DBGManager_GetNumSourceFilename(i
);
90 Ptr1
= sourcesinfostab
[i
].Filename
= (char *)malloc(strlen(Ptr
) + 1);
91 while (((*Ptr
== '.') || ((*Ptr
== '/') || (*Ptr
== '\\'))) && Ptr
++);
93 // Get texts dedicated information
94 for (j
= 0; j
< 2; j
++)
96 sourcesinfostab
[i
].NbLinesText
[j
] = DBGManager_GetSrcNbListPtrFromIndex(i
, j
);
98 sourcesinfostab
[i
].NumLinesUsed
= DBGManager_GetSrcNumLinesPtrFromIndex(i
, true);
99 sourcesinfostab
[i
].SourceText
= DBGManager_GetSrcListPtrFromIndex(i
, false);
100 // Get remaining information
101 sourcesinfostab
[i
].Language
= DBGManager_GetSrcLanguageFromIndex(i
);
102 sourcesinfostab
[i
].IndexTab
= -1;
108 // Get the tracing status
109 bool SourcesWindow::GetTraceStatus(void)
113 switch (sourcesinfostab
[CurrentTab
].Language
)
115 case DBG_LANG_VASM_Assembler
:
128 // Check if line has changed
129 bool SourcesWindow::CheckChangeLine(void)
133 if (NumLine
= DBGManager_GetNumLineFromAdr(m68k_get_reg(NULL
, M68K_REG_PC
), DBG_NO_TAG
))
135 if (OldCurrentTab
== CurrentTab
)
137 if (OldCurrentNumLineSrc
!= NumLine
)
139 OldCurrentNumLineSrc
= NumLine
;
145 OldCurrentTab
= CurrentTab
;
146 OldCurrentNumLineSrc
= 0;
156 void SourcesWindow::RefreshContents(void)
158 size_t m68kPC
= m68k_get_reg(NULL
, M68K_REG_PC
);
165 if (m68kPC
&& NbSourcesInfos
)
167 // Get source filename pointed by PC address
168 Filename
= DBGManager_GetFullSourceFilenameFromAdr(m68kPC
, &Status
);
169 if (!Status
&& Filename
)
171 // Look for a new tab
172 for (i
= 0; i
< NbSourcesInfos
; i
++, !index
)
174 if (sourcesinfostab
[i
].Filename
)
176 if (strstr(Filename
, sourcesinfostab
[i
].Filename
))
178 // Open a new tab for a source code
179 if (sourcesinfostab
[i
].IndexTab
== -1)
181 sourcesinfostab
[i
].IndexTab
= index
= sourcestabWidget
->addTab(sourcesinfostab
[i
].sourceCtab
= new(SourceCWindow
), tr(sourcesinfostab
[i
].Filename
));
182 sourcesinfostab
[i
].sourceCtab
->FillTab(i
, sourcesinfostab
[i
].SourceText
, sourcesinfostab
[i
].NbLinesText
, sourcesinfostab
[i
].NumLinesUsed
);
185 sourcestabWidget
->setCurrentIndex(sourcesinfostab
[i
].IndexTab
);
186 sourcesinfostab
[CurrentTab
].sourceCtab
->SetCursorTrace(sourcesinfostab
[CurrentTab
].CurrentNumLineSrc
, true);
187 sourcesinfostab
[i
].sourceCtab
->SetCursorTrace(sourcesinfostab
[i
].CurrentNumLineSrc
= (int)DBGManager_GetNumLineFromAdr(m68kPC
, DBG_NO_TAG
), false);
188 sourcesinfostab
[i
].sourceCtab
->RefreshContents();
196 // Source file doesn't exist
197 if (indexErrorTab
== -1)
199 indexErrorTab
= sourcestabWidget
->addTab(sourceErrorTab
= new(SourceCWindow
), tr("Source file not available"));
200 //sourceErrorTab->hide();
202 sourcestabWidget
->setCurrentIndex(indexErrorTab
);
208 // Close / Remove current tab
209 void SourcesWindow::CloseCurrentTab(void)
213 QString t
= sourcestabWidget
->tabText((Index
= sourcestabWidget
->currentIndex()));
215 // Check error tab presence
216 if (indexErrorTab
== Index
)
218 // Close the error tab
223 // Close source code text tab
224 while ((i
< NbSourcesInfos
) && strcmp(sourcesinfostab
[i
++].Filename
, t
.toLatin1().data()));
225 sourcesinfostab
[(i
- 1)].IndexTab
= -1;
229 sourcestabWidget
->removeTab(Index
);
234 void SourcesWindow::keyPressEvent(QKeyEvent
* e
)
236 // Close/Remove the current tab
237 if (e
->key() == Qt::Key_Escape
)
245 void SourcesWindow::Reset(void)
248 sourcestabWidget
->clear();
250 // Clear tab information
251 while (NbSourcesInfos
)
253 free(sourcesinfostab
[--NbSourcesInfos
].Filename
);
255 free(sourcesinfostab
);
260 void SourcesWindow::Close(void)