453fa7c1b04595ad7e7d1c55d62ba71d3f700a44
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
24 #include "debugger/localbrowser.h"
26 #include "debugger/DBGManager.h"
28 #include "m68000/m68kinterface.h"
32 LocalBrowserWindow::LocalBrowserWindow(QWidget
* parent
/*= 0*/) : QWidget(parent
, Qt::Dialog
),
33 layout(new QVBoxLayout
),
34 #ifdef LOCAL_LAYOUTTEXTS
35 text(new QTextBrowser
),
37 TableView(new QTableView
),
38 model(new QStandardItemModel
),
41 FuncName((char *)calloc(1, 1)),
43 statusbar(new QStatusBar
)
45 setWindowTitle(tr("Locals"));
48 QFont
fixedFont("Lucida Console", 8, QFont::Normal
);
49 fixedFont
.setStyleHint(QFont::TypeWriter
);
51 #ifdef LOCAL_LAYOUTTEXTS
52 // Set original layout
53 text
->setFont(fixedFont
);
54 layout
->addWidget(text
);
56 // Set the new layout with proper identation and readibility
57 model
->setColumnCount(3);
58 model
->setHeaderData(0, Qt::Horizontal
, QObject::tr("Name"));
59 model
->setHeaderData(1, Qt::Horizontal
, QObject::tr("Value"));
60 model
->setHeaderData(2, Qt::Horizontal
, QObject::tr("Type"));
62 TableView
->setModel(model
);
63 TableView
->setEditTriggers(QAbstractItemView::NoEditTriggers
);
64 TableView
->setShowGrid(0);
65 TableView
->setFont(fixedFont
);
66 TableView
->verticalHeader()->setDefaultSectionSize(TableView
->verticalHeader()->minimumSectionSize());
67 TableView
->verticalHeader()->setDefaultAlignment(Qt::AlignRight
);
68 layout
->addWidget(TableView
);
72 layout
->addWidget(statusbar
);
78 LocalBrowserWindow::~LocalBrowserWindow(void)
86 bool LocalBrowserWindow::UpdateInfos(void)
91 if (NbLocal
= DBGManager_GetNbLocalVariables(Adr
= m68k_get_reg(NULL
, M68K_REG_PC
)))
93 if (Ptr
= DBGManager_GetFunctionName(Adr
))
95 if (strcmp(FuncName
, Ptr
))
97 if (FuncName
= (char *)realloc(FuncName
, strlen(Ptr
) + 1))
99 strcpy(FuncName
, Ptr
);
101 if (LocalInfo
= (WatchInfo
*)realloc(LocalInfo
, (sizeof(WatchInfo
) * NbLocal
)))
103 for (size_t i
= 0; i
< NbLocal
; i
++)
105 // Get local variable name and his information
106 if (LocalInfo
[i
].PtrVariableName
= DBGManager_GetLocalVariableName(Adr
, i
+ 1))
108 LocalInfo
[i
].Op
= DBGManager_GetLocalVariableOp(Adr
, i
+ 1);
109 LocalInfo
[i
].Adr
= NULL
;
110 LocalInfo
[i
].PtrCPURegisterName
= NULL
;
111 LocalInfo
[i
].TypeTag
= DBGManager_GetLocalVariableTypeTag(Adr
, i
+ 1);
112 LocalInfo
[i
].PtrVariableBaseTypeName
= DBGManager_GetLocalVariableTypeName(Adr
, i
+ 1);
113 LocalInfo
[i
].TypeEncoding
= DBGManager_GetLocalVariableTypeEncoding(Adr
, i
+ 1);
114 LocalInfo
[i
].TypeByteSize
= DBGManager_GetLocalVariableTypeByteSize(Adr
, i
+ 1);
115 LocalInfo
[i
].Offset
= DBGManager_GetLocalVariableOffset(Adr
, i
+ 1);
133 void LocalBrowserWindow::RefreshContents(void)
135 #ifdef LOCAL_LAYOUTTEXTS
138 size_t Error
= LOCAL_NOERROR
;
142 #ifdef LOCAL_SUPPORTARRAY
147 const char *CPURegName
[] = { "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7" };
151 #ifndef LOCAL_LAYOUTTEXTS
152 model
->setRowCount(0);
156 for (size_t i
= 0; i
< NbLocal
; i
++)
158 if (LocalInfo
[i
].PtrVariableName
)
160 memset(Value1
, 0, sizeof(Value1
));
161 #ifdef LOCAL_LAYOUTTEXTS
164 Local
+= QString("<br>");
169 // Local or parameters variables
170 if (((LocalInfo
[i
].Op
>= DBG_OP_breg0
) && (LocalInfo
[i
].Op
<= DBG_OP_breg31
)) || (LocalInfo
[i
].Op
== DBG_OP_fbreg
))
172 LocalInfo
[i
].Adr
= m68k_get_reg(NULL
, M68K_REG_A6
) + LocalInfo
[i
].Offset
;
174 if ((LocalInfo
[i
].Op
== DBG_OP_fbreg
))
176 LocalInfo
[i
].Adr
+= 8;
179 if ((LocalInfo
[i
].Adr
>= 0) && (LocalInfo
[i
].Adr
< vjs
.DRAM_size
))
181 if ((LocalInfo
[i
].TypeTag
& (DBG_TAG_TYPE_array
| DBG_TAG_TYPE_structure
)))
183 #if defined(LOCAL_SUPPORTARRAY) || defined(LOCAL_SUPPORTSTRUCTURE)
184 //memcpy(Value1, &jaguarMainRAM[LocalInfo[i].Adr], 20);
185 #ifdef LOCAL_LAYOUTTEXTS
186 //sprintf(Value, "\"%s\"", Value1);
188 //sprintf(Value, "0x%06X, \"%s\"", LocalInfo[i].Adr, Value1);
198 PtrValue
= DBGManager_GetVariableValueFromAdr(LocalInfo
[i
].Adr
, LocalInfo
[i
].TypeEncoding
, LocalInfo
[i
].TypeByteSize
);
208 // Value from CPU register
209 if ((LocalInfo
[i
].Op
>= DBG_OP_reg0
) && (LocalInfo
[i
].Op
<= DBG_OP_reg31
))
211 LocalInfo
[i
].PtrCPURegisterName
= (char *)CPURegName
[(LocalInfo
[i
].Op
- DBG_OP_reg0
)];
212 sprintf(Value1
, "%d", m68k_get_reg(NULL
, (m68k_register_t
)((size_t)M68K_REG_D0
+ (LocalInfo
[i
].Op
- DBG_OP_reg0
))));
221 #ifndef LOCAL_LAYOUTTEXTS
222 model
->setItem(i
, 0, new QStandardItem(QString("%1").arg(LocalInfo
[i
].PtrVariableName
)));
224 // Check if the local variable is use by the code
225 if (!LocalInfo
[i
].Op
)
227 #ifdef LOCAL_LAYOUTTEXTS
228 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
);
234 #ifndef LOCAL_LAYOUTTEXTS
235 model
->setItem(i
, 1, new QStandardItem(QString("%1").arg(PtrValue
)));
237 sprintf(string
, "%i : %s | %s | ", (i
+ 1), (LocalInfo
[i
].PtrVariableBaseTypeName
? LocalInfo
[i
].PtrVariableBaseTypeName
: (char *)"<font color='#ff0000'>N/A</font>"), LocalInfo
[i
].PtrVariableName
);
238 Local
+= QString(string
);
240 if ((unsigned int)LocalInfo
[i
].Adr
)
242 sprintf(string
, "0x%06X", (unsigned int)LocalInfo
[i
].Adr
);
246 if (LocalInfo
[i
].PtrCPURegisterName
)
248 sprintf(string
, "<font color='#0000FF'>%s</font>", LocalInfo
[i
].PtrCPURegisterName
);
252 sprintf(string
, "%s", (char *)"<font color='#ff0000'>N/A</font>");
256 Local
+= QString(string
);
257 sprintf(string
, " | %s", (!PtrValue
? (char *)"<font color='#ff0000'>N/A</font>" : PtrValue
));
260 #ifndef LOCAL_LAYOUTTEXTS
261 model
->setItem(i
, 2, new QStandardItem(QString("%1").arg((LocalInfo
[i
].PtrVariableBaseTypeName
? LocalInfo
[i
].PtrVariableBaseTypeName
: (char *)"<font color='#ff0000'>N/A</font>"))));
263 Local
+= QString(string
);
268 MSG
+= QString("Ready");
269 #ifdef LOCAL_LAYOUTTEXTS
271 text
->setText(Local
);
277 MSG
+= QString("No locals");
278 Error
= LOCAL_NOLOCALS
;
279 #ifdef LOCAL_LAYOUTTEXTS
284 // Display status bar
287 if ((Error
& LOCAL_WARNING
))
289 statusbar
->setStyleSheet("background-color: lightyellow; font: bold");
293 statusbar
->setStyleSheet("background-color: tomato; font: bold");
298 statusbar
->setStyleSheet("background-color: lightgreen; font: bold");
300 statusbar
->showMessage(MSG
);
306 void LocalBrowserWindow::keyPressEvent(QKeyEvent
* e
)
308 if (e
->key() == Qt::Key_Escape
)