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 Sept./2018 Added a status bar and better status report, and set information values in a tab
15 // Feature to list the pointer(s) in the code using the allocation
16 // To set the information display at the right
17 // To support the array
18 // To support the static variables
23 #include "debugger/localbrowser.h"
25 #include "debugger/DBGManager.h"
27 #include "m68000/m68kinterface.h"
31 LocalBrowserWindow::LocalBrowserWindow(QWidget
* parent
/*= 0*/) : QWidget(parent
, Qt::Dialog
),
32 layout(new QVBoxLayout
),
33 #ifdef LOCAL_LAYOUTTEXTS
34 text(new QTextBrowser
),
36 TableView(new QTableView
),
37 model(new QStandardItemModel
),
40 FuncName((char *)calloc(1, 1)),
42 statusbar(new QStatusBar
)
44 setWindowTitle(tr("Locals"));
47 QFont
fixedFont("Lucida Console", 8, QFont::Normal
);
48 fixedFont
.setStyleHint(QFont::TypeWriter
);
50 #ifdef LOCAL_LAYOUTTEXTS
51 // Set original layout
52 text
->setFont(fixedFont
);
53 layout
->addWidget(text
);
55 // Set the new layout with proper identation and readibility
56 model
->setColumnCount(3);
57 model
->setHeaderData(0, Qt::Horizontal
, QObject::tr("Name"));
58 model
->setHeaderData(1, Qt::Horizontal
, QObject::tr("Value"));
59 model
->setHeaderData(2, Qt::Horizontal
, QObject::tr("Type"));
61 TableView
->setModel(model
);
62 TableView
->setEditTriggers(QAbstractItemView::NoEditTriggers
);
63 TableView
->setShowGrid(0);
64 TableView
->setFont(fixedFont
);
65 TableView
->verticalHeader()->setDefaultSectionSize(TableView
->verticalHeader()->minimumSectionSize());
66 TableView
->verticalHeader()->setDefaultAlignment(Qt::AlignRight
);
67 layout
->addWidget(TableView
);
71 layout
->addWidget(statusbar
);
77 LocalBrowserWindow::~LocalBrowserWindow(void)
85 bool LocalBrowserWindow::UpdateInfos(void)
90 if (NbLocal
= DBGManager_GetNbLocalVariables(Adr
= m68k_get_reg(NULL
, M68K_REG_PC
)))
92 if (Ptr
= DBGManager_GetFunctionName(Adr
))
94 if (strcmp(FuncName
, Ptr
))
96 if (FuncName
= (char *)realloc(FuncName
, strlen(Ptr
) + 1))
98 strcpy(FuncName
, Ptr
);
100 if (LocalInfo
= (WatchInfo
*)realloc(LocalInfo
, (sizeof(WatchInfo
) * NbLocal
)))
102 for (size_t i
= 0; i
< NbLocal
; i
++)
104 // Get local variable name and his information
105 if (LocalInfo
[i
].PtrVariableName
= DBGManager_GetLocalVariableName(Adr
, i
+ 1))
107 LocalInfo
[i
].Op
= DBGManager_GetLocalVariableOp(Adr
, i
+ 1);
108 LocalInfo
[i
].Adr
= NULL
;
109 LocalInfo
[i
].PtrCPURegisterName
= NULL
;
110 LocalInfo
[i
].TypeTag
= DBGManager_GetLocalVariableTypeTag(Adr
, i
+ 1);
111 LocalInfo
[i
].PtrVariableBaseTypeName
= DBGManager_GetLocalVariableTypeName(Adr
, i
+ 1);
112 LocalInfo
[i
].TypeEncoding
= DBGManager_GetLocalVariableTypeEncoding(Adr
, i
+ 1);
113 LocalInfo
[i
].TypeByteSize
= DBGManager_GetLocalVariableTypeByteSize(Adr
, i
+ 1);
114 LocalInfo
[i
].Offset
= DBGManager_GetLocalVariableOffset(Adr
, i
+ 1);
132 void LocalBrowserWindow::RefreshContents(void)
134 #ifdef LOCAL_LAYOUTTEXTS
137 size_t Error
= LOCAL_NOERROR
;
141 #ifdef LOCAL_SUPPORTARRAY
146 const char *CPURegName
[] = { "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7" };
150 #ifndef LOCAL_LAYOUTTEXTS
151 model
->setRowCount(0);
155 for (size_t i
= 0; i
< NbLocal
; i
++)
157 if (LocalInfo
[i
].PtrVariableName
)
159 memset(Value1
, 0, sizeof(Value1
));
160 #ifdef LOCAL_LAYOUTTEXTS
163 Local
+= QString("<br>");
168 // Local or parameters variables
169 if (((LocalInfo
[i
].Op
>= DBG_OP_breg0
) && (LocalInfo
[i
].Op
<= DBG_OP_breg31
)) || (LocalInfo
[i
].Op
== DBG_OP_fbreg
))
171 LocalInfo
[i
].Adr
= m68k_get_reg(NULL
, M68K_REG_A6
) + LocalInfo
[i
].Offset
;
173 if ((LocalInfo
[i
].Op
== DBG_OP_fbreg
))
175 LocalInfo
[i
].Adr
+= 8;
178 if ((LocalInfo
[i
].Adr
>= 0) && (LocalInfo
[i
].Adr
< vjs
.DRAM_size
))
180 if ((LocalInfo
[i
].TypeTag
& (DBG_TAG_TYPE_array
| DBG_TAG_TYPE_structure
)))
182 #if defined(LOCAL_SUPPORTARRAY) || defined(LOCAL_SUPPORTSTRUCTURE)
183 //memcpy(Value1, &jaguarMainRAM[LocalInfo[i].Adr], 20);
184 #ifdef LOCAL_LAYOUTTEXTS
185 //sprintf(Value, "\"%s\"", Value1);
187 //sprintf(Value, "0x%06X, \"%s\"", LocalInfo[i].Adr, Value1);
197 PtrValue
= DBGManager_GetVariableValueFromAdr(LocalInfo
[i
].Adr
, LocalInfo
[i
].TypeEncoding
, LocalInfo
[i
].TypeByteSize
);
207 // Value from CPU register
208 if ((LocalInfo
[i
].Op
>= DBG_OP_reg0
) && (LocalInfo
[i
].Op
<= DBG_OP_reg31
))
210 LocalInfo
[i
].PtrCPURegisterName
= (char *)CPURegName
[(LocalInfo
[i
].Op
- DBG_OP_reg0
)];
211 PtrValue
= itoa(m68k_get_reg(NULL
, (m68k_register_t
)((size_t)M68K_REG_D0
+ (LocalInfo
[i
].Op
- DBG_OP_reg0
))), Value1
, 10);
219 #ifndef LOCAL_LAYOUTTEXTS
220 model
->setItem(i
, 0, new QStandardItem(QString("%1").arg(LocalInfo
[i
].PtrVariableName
)));
222 // Check if the local variable is use by the code
223 if (!LocalInfo
[i
].Op
)
225 #ifdef LOCAL_LAYOUTTEXTS
226 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
);
232 #ifndef LOCAL_LAYOUTTEXTS
233 model
->setItem(i
, 1, new QStandardItem(QString("%1").arg(PtrValue
)));
235 sprintf(string
, "%i : %s | %s | ", (i
+ 1), (LocalInfo
[i
].PtrVariableBaseTypeName
? LocalInfo
[i
].PtrVariableBaseTypeName
: (char *)"<font color='#ff0000'>N/A</font>"), LocalInfo
[i
].PtrVariableName
);
236 Local
+= QString(string
);
238 if ((unsigned int)LocalInfo
[i
].Adr
)
240 sprintf(string
, "0x%06X", (unsigned int)LocalInfo
[i
].Adr
);
244 if (LocalInfo
[i
].PtrCPURegisterName
)
246 sprintf(string
, "<font color='#0000FF'>%s</font>", LocalInfo
[i
].PtrCPURegisterName
);
250 sprintf(string
, "%s", (char *)"<font color='#ff0000'>N/A</font>");
254 Local
+= QString(string
);
255 sprintf(string
, " | %s", (!PtrValue
? (char *)"<font color='#ff0000'>N/A</font>" : PtrValue
));
258 #ifndef LOCAL_LAYOUTTEXTS
259 model
->setItem(i
, 2, new QStandardItem(QString("%1").arg((LocalInfo
[i
].PtrVariableBaseTypeName
? LocalInfo
[i
].PtrVariableBaseTypeName
: (char *)"<font color='#ff0000'>N/A</font>"))));
261 Local
+= QString(string
);
266 MSG
+= QString("Ready");
267 #ifdef LOCAL_LAYOUTTEXTS
269 text
->setText(Local
);
275 MSG
+= QString("No locals");
276 Error
= LOCAL_NOLOCALS
;
277 #ifdef LOCAL_LAYOUTTEXTS
282 // Display status bar
285 if ((Error
& LOCAL_WARNING
))
287 statusbar
->setStyleSheet("background-color: lightyellow; font: bold");
291 statusbar
->setStyleSheet("background-color: tomato; font: bold");
296 statusbar
->setStyleSheet("background-color: lightgreen; font: bold");
298 statusbar
->showMessage(MSG
);
304 void LocalBrowserWindow::keyPressEvent(QKeyEvent
* e
)
306 if (e
->key() == Qt::Key_Escape
)