2 // localbrowser.cpp - Local variables
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
9 // --- ---------- -----------------------------------------------------------
10 // JPM 11/03/2017 Created this file
11 // JPM 09/08/2018 Added a status bar and better status report
12 // JPM 09/08/2018 Set information values in a tab
16 // Feature to list the pointer(s) in the code using the allocation
17 // To set the information display at the right
18 // To support the array
22 #include "debugger/localbrowser.h"
24 #include "debugger/DBGManager.h"
26 #include "m68000/m68kinterface.h"
30 LocalBrowserWindow::LocalBrowserWindow(QWidget
* parent
/*= 0*/) : QWidget(parent
, Qt::Dialog
),
31 layout(new QVBoxLayout
),
32 #ifdef LOCAL_LAYOUTTEXTS
33 text(new QTextBrowser
),
35 TableView(new QTableView
),
36 model(new QStandardItemModel
),
39 FuncName((char *)calloc(1, 1)),
41 statusbar(new QStatusBar
)
43 setWindowTitle(tr("Locals"));
46 QFont
fixedFont("Lucida Console", 8, QFont::Normal
);
47 fixedFont
.setStyleHint(QFont::TypeWriter
);
49 #ifdef LOCAL_LAYOUTTEXTS
50 // Set original layout
51 text
->setFont(fixedFont
);
52 layout
->addWidget(text
);
54 // Set the new layout with proper identation and readibility
55 model
->setColumnCount(3);
56 model
->setHeaderData(0, Qt::Horizontal
, QObject::tr("Name"));
57 model
->setHeaderData(1, Qt::Horizontal
, QObject::tr("Value"));
58 model
->setHeaderData(2, Qt::Horizontal
, QObject::tr("Type"));
60 TableView
->setModel(model
);
61 TableView
->setEditTriggers(QAbstractItemView::NoEditTriggers
);
62 TableView
->setShowGrid(0);
63 TableView
->setFont(fixedFont
);
64 TableView
->verticalHeader()->setDefaultSectionSize(TableView
->verticalHeader()->minimumSectionSize());
65 TableView
->verticalHeader()->setDefaultAlignment(Qt::AlignRight
);
66 layout
->addWidget(TableView
);
70 layout
->addWidget(statusbar
);
76 LocalBrowserWindow::~LocalBrowserWindow(void)
84 bool LocalBrowserWindow::UpdateInfos(void)
89 if (NbLocal
= DBGManager_GetNbLocalVariables(Adr
= m68k_get_reg(NULL
, M68K_REG_PC
)))
91 if (Ptr
= DBGManager_GetFunctionName(Adr
))
93 if (strcmp(FuncName
, Ptr
))
95 if (FuncName
= (char *)realloc(FuncName
, strlen(Ptr
) + 1))
97 strcpy(FuncName
, Ptr
);
99 if (LocalInfo
= (WatchInfo
*)realloc(LocalInfo
, (sizeof(WatchInfo
) * NbLocal
)))
101 for (size_t i
= 0; i
< NbLocal
; i
++)
103 // Get local variable name and his information
104 if (LocalInfo
[i
].PtrVariableName
= DBGManager_GetLocalVariableName(Adr
, i
+ 1))
106 LocalInfo
[i
].Op
= DBGManager_GetLocalVariableOp(Adr
, i
+ 1);
107 LocalInfo
[i
].Adr
= NULL
;
108 LocalInfo
[i
].PtrCPURegisterName
= NULL
;
109 LocalInfo
[i
].TypeTag
= DBGManager_GetLocalVariableTypeTag(Adr
, i
+ 1);
110 LocalInfo
[i
].PtrVariableBaseTypeName
= DBGManager_GetLocalVariableTypeName(Adr
, i
+ 1);
111 LocalInfo
[i
].TypeEncoding
= DBGManager_GetLocalVariableTypeEncoding(Adr
, i
+ 1);
112 LocalInfo
[i
].TypeByteSize
= DBGManager_GetLocalVariableTypeByteSize(Adr
, i
+ 1);
113 LocalInfo
[i
].Offset
= DBGManager_GetLocalVariableOffset(Adr
, i
+ 1);
131 void LocalBrowserWindow::RefreshContents(void)
133 #ifdef LOCAL_LAYOUTTEXTS
136 size_t Error
= LOCAL_NOERROR
;
140 #ifdef LOCAL_SUPPORTARRAY
145 const char *CPURegName
[] = { "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7" };
149 #ifndef LOCAL_LAYOUTTEXTS
150 model
->setRowCount(0);
154 for (size_t i
= 0; i
< NbLocal
; i
++)
156 if (LocalInfo
[i
].PtrVariableName
)
158 memset(Value1
, 0, sizeof(Value1
));
159 #ifdef LOCAL_LAYOUTTEXTS
162 Local
+= QString("<br>");
167 // Local or parameters variables
168 if (((LocalInfo
[i
].Op
>= DBG_OP_breg0
) && (LocalInfo
[i
].Op
<= DBG_OP_breg31
)) || (LocalInfo
[i
].Op
== DBG_OP_fbreg
))
170 LocalInfo
[i
].Adr
= m68k_get_reg(NULL
, M68K_REG_A6
) + LocalInfo
[i
].Offset
;
172 if ((LocalInfo
[i
].Op
== DBG_OP_fbreg
))
174 LocalInfo
[i
].Adr
+= 8;
177 if ((LocalInfo
[i
].Adr
>= 0) && (LocalInfo
[i
].Adr
< vjs
.DRAM_size
))
179 if ((LocalInfo
[i
].TypeTag
& (DBG_TAG_TYPE_array
| DBG_TAG_TYPE_structure
)))
181 #if defined(LOCAL_SUPPORTARRAY) || defined(LOCAL_SUPPORTSTRUCTURE)
182 //memcpy(Value1, &jaguarMainRAM[LocalInfo[i].Adr], 20);
183 #ifdef LOCAL_LAYOUTTEXTS
184 //sprintf(Value, "\"%s\"", Value1);
186 //sprintf(Value, "0x%06X, \"%s\"", LocalInfo[i].Adr, Value1);
196 PtrValue
= DBGManager_GetVariableValueFromAdr(LocalInfo
[i
].Adr
, LocalInfo
[i
].TypeEncoding
, LocalInfo
[i
].TypeByteSize
);
206 // Value from CPU register
207 if ((LocalInfo
[i
].Op
>= DBG_OP_reg0
) && (LocalInfo
[i
].Op
<= DBG_OP_reg31
))
209 LocalInfo
[i
].PtrCPURegisterName
= (char *)CPURegName
[(LocalInfo
[i
].Op
- DBG_OP_reg0
)];
210 PtrValue
= itoa(m68k_get_reg(NULL
, (m68k_register_t
)((size_t)M68K_REG_D0
+ (LocalInfo
[i
].Op
- DBG_OP_reg0
))), Value1
, 10);
218 #ifndef LOCAL_LAYOUTTEXTS
219 model
->setItem(i
, 0, new QStandardItem(QString("%1").arg(LocalInfo
[i
].PtrVariableName
)));
221 // Check if the local variable is use by the code
222 if (!LocalInfo
[i
].Op
)
224 #ifdef LOCAL_LAYOUTTEXTS
225 sprintf(string
, "<font color='#A52A2A'>%i : %s | %s | [Not used]</font>", (i
+ 1), (LocalInfo
[i
].PtrVariableBaseTypeName
? LocalInfo
[i
].PtrVariableBaseTypeName
: (char *)"<font color='#ff0000'>N/A</font>"), LocalInfo
[i
].PtrVariableName
);
231 #ifndef LOCAL_LAYOUTTEXTS
232 model
->setItem(i
, 1, new QStandardItem(QString("%1").arg(PtrValue
)));
234 sprintf(string
, "%i : %s | %s | ", (i
+ 1), (LocalInfo
[i
].PtrVariableBaseTypeName
? LocalInfo
[i
].PtrVariableBaseTypeName
: (char *)"<font color='#ff0000'>N/A</font>"), LocalInfo
[i
].PtrVariableName
);
235 Local
+= QString(string
);
237 if ((unsigned int)LocalInfo
[i
].Adr
)
239 sprintf(string
, "0x%06X", (unsigned int)LocalInfo
[i
].Adr
);
243 if (LocalInfo
[i
].PtrCPURegisterName
)
245 sprintf(string
, "<font color='#0000FF'>%s</font>", LocalInfo
[i
].PtrCPURegisterName
);
249 sprintf(string
, "%s", (char *)"<font color='#ff0000'>N/A</font>");
253 Local
+= QString(string
);
254 sprintf(string
, " | %s", (!PtrValue
? (char *)"<font color='#ff0000'>N/A</font>" : PtrValue
));
257 #ifndef LOCAL_LAYOUTTEXTS
258 model
->setItem(i
, 2, new QStandardItem(QString("%1").arg((LocalInfo
[i
].PtrVariableBaseTypeName
? LocalInfo
[i
].PtrVariableBaseTypeName
: (char *)"<font color='#ff0000'>N/A</font>"))));
260 Local
+= QString(string
);
265 MSG
+= QString("Ready");
266 #ifdef LOCAL_LAYOUTTEXTS
268 text
->setText(Local
);
274 MSG
+= QString("No locals");
275 Error
= LOCAL_NOLOCALS
;
276 #ifdef LOCAL_LAYOUTTEXTS
281 // Display status bar
284 if ((Error
& LOCAL_WARNING
))
286 statusbar
->setStyleSheet("background-color: lightyellow; font: bold");
290 statusbar
->setStyleSheet("background-color: tomato; font: bold");
295 statusbar
->setStyleSheet("background-color: lightgreen; font: bold");
297 statusbar
->showMessage(MSG
);
303 void LocalBrowserWindow::keyPressEvent(QKeyEvent
* e
)
305 if (e
->key() == Qt::Key_Escape
)