2 // localbrowser.cpp - Local variables
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
7 // RG = Richard Goedeken
10 // --- ---------- -----------------------------------------------------------
11 // JPM 11/03/2017 Created this file
12 // JPM Sept./2018 Added a status bar and better status report, and set information values in a tab
13 // RG Jan./2021 Linux build fixes
17 // Feature to list the pointer(s) in the code using the allocation
18 // To set the information display at the right
19 // To support the array
20 // To support the static variables
26 #include "debugger/localbrowser.h"
28 #include "debugger/DBGManager.h"
30 #include "m68000/m68kinterface.h"
34 LocalBrowserWindow::LocalBrowserWindow(QWidget
* parent
/*= 0*/) : QWidget(parent
, Qt::Dialog
),
35 layout(new QVBoxLayout
),
36 #ifdef LOCAL_LAYOUTTEXTS
37 text(new QTextBrowser
),
39 TableView(new QTableView
),
40 model(new QStandardItemModel
),
43 FuncName((char *)calloc(1, 1)),
45 statusbar(new QStatusBar
)
47 setWindowTitle(tr("Locals"));
50 QFont
fixedFont("Lucida Console", 8, QFont::Normal
);
51 fixedFont
.setStyleHint(QFont::TypeWriter
);
53 #ifdef LOCAL_LAYOUTTEXTS
54 // Set original layout
55 text
->setFont(fixedFont
);
56 layout
->addWidget(text
);
58 // Set the new layout with proper identation and readibility
59 model
->setColumnCount(3);
60 model
->setHeaderData(0, Qt::Horizontal
, QObject::tr("Name"));
61 model
->setHeaderData(1, Qt::Horizontal
, QObject::tr("Value"));
62 model
->setHeaderData(2, Qt::Horizontal
, QObject::tr("Type"));
64 TableView
->setModel(model
);
65 TableView
->setEditTriggers(QAbstractItemView::NoEditTriggers
);
66 TableView
->setShowGrid(0);
67 TableView
->setFont(fixedFont
);
68 TableView
->verticalHeader()->setDefaultSectionSize(TableView
->verticalHeader()->minimumSectionSize());
69 TableView
->verticalHeader()->setDefaultAlignment(Qt::AlignRight
);
70 layout
->addWidget(TableView
);
74 layout
->addWidget(statusbar
);
80 LocalBrowserWindow::~LocalBrowserWindow(void)
88 bool LocalBrowserWindow::UpdateInfos(void)
93 if (NbLocal
= DBGManager_GetNbLocalVariables(Adr
= m68k_get_reg(NULL
, M68K_REG_PC
)))
95 if (Ptr
= DBGManager_GetFunctionName(Adr
))
97 if (strcmp(FuncName
, Ptr
))
99 if (FuncName
= (char *)realloc(FuncName
, strlen(Ptr
) + 1))
101 strcpy(FuncName
, Ptr
);
103 if (LocalInfo
= (WatchInfo
*)realloc(LocalInfo
, (sizeof(WatchInfo
) * NbLocal
)))
105 for (size_t i
= 0; i
< NbLocal
; i
++)
107 // Get local variable name and his information
108 if (LocalInfo
[i
].PtrVariableName
= DBGManager_GetLocalVariableName(Adr
, i
+ 1))
110 LocalInfo
[i
].Op
= DBGManager_GetLocalVariableOp(Adr
, i
+ 1);
111 LocalInfo
[i
].Adr
= NULL
;
112 LocalInfo
[i
].PtrCPURegisterName
= NULL
;
113 LocalInfo
[i
].TypeTag
= DBGManager_GetLocalVariableTypeTag(Adr
, i
+ 1);
114 LocalInfo
[i
].PtrVariableBaseTypeName
= DBGManager_GetLocalVariableTypeName(Adr
, i
+ 1);
115 LocalInfo
[i
].TypeEncoding
= DBGManager_GetLocalVariableTypeEncoding(Adr
, i
+ 1);
116 LocalInfo
[i
].TypeByteSize
= DBGManager_GetLocalVariableTypeByteSize(Adr
, i
+ 1);
117 LocalInfo
[i
].Offset
= DBGManager_GetLocalVariableOffset(Adr
, i
+ 1);
135 void LocalBrowserWindow::RefreshContents(void)
137 #ifdef LOCAL_LAYOUTTEXTS
140 size_t Error
= LOCAL_NOERROR
;
144 #ifdef LOCAL_SUPPORTARRAY
149 const char *CPURegName
[] = { "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7" };
153 #ifndef LOCAL_LAYOUTTEXTS
154 model
->setRowCount(0);
158 for (size_t i
= 0; i
< NbLocal
; i
++)
160 if (LocalInfo
[i
].PtrVariableName
)
162 memset(Value1
, 0, sizeof(Value1
));
163 #ifdef LOCAL_LAYOUTTEXTS
166 Local
+= QString("<br>");
171 // Local or parameters variables
172 if (((LocalInfo
[i
].Op
>= DBG_OP_breg0
) && (LocalInfo
[i
].Op
<= DBG_OP_breg31
)) || (LocalInfo
[i
].Op
== DBG_OP_fbreg
))
174 LocalInfo
[i
].Adr
= m68k_get_reg(NULL
, M68K_REG_A6
) + LocalInfo
[i
].Offset
;
176 if ((LocalInfo
[i
].Op
== DBG_OP_fbreg
))
178 LocalInfo
[i
].Adr
+= 8;
181 if ((LocalInfo
[i
].Adr
>= 0) && (LocalInfo
[i
].Adr
< vjs
.DRAM_size
))
183 if ((LocalInfo
[i
].TypeTag
& (DBG_TAG_TYPE_array
| DBG_TAG_TYPE_structure
)))
185 #if defined(LOCAL_SUPPORTARRAY) || defined(LOCAL_SUPPORTSTRUCTURE)
186 //memcpy(Value1, &jaguarMainRAM[LocalInfo[i].Adr], 20);
187 #ifdef LOCAL_LAYOUTTEXTS
188 //sprintf(Value, "\"%s\"", Value1);
190 //sprintf(Value, "0x%06X, \"%s\"", LocalInfo[i].Adr, Value1);
200 PtrValue
= DBGManager_GetVariableValueFromAdr(LocalInfo
[i
].Adr
, LocalInfo
[i
].TypeEncoding
, LocalInfo
[i
].TypeByteSize
);
210 // Value from CPU register
211 if ((LocalInfo
[i
].Op
>= DBG_OP_reg0
) && (LocalInfo
[i
].Op
<= DBG_OP_reg31
))
213 LocalInfo
[i
].PtrCPURegisterName
= (char *)CPURegName
[(LocalInfo
[i
].Op
- DBG_OP_reg0
)];
214 sprintf(Value1
, "%d", m68k_get_reg(NULL
, (m68k_register_t
)((size_t)M68K_REG_D0
+ (LocalInfo
[i
].Op
- DBG_OP_reg0
))));
223 #ifndef LOCAL_LAYOUTTEXTS
224 model
->setItem(i
, 0, new QStandardItem(QString("%1").arg(LocalInfo
[i
].PtrVariableName
)));
226 // Check if the local variable is use by the code
227 if (!LocalInfo
[i
].Op
)
229 #ifdef LOCAL_LAYOUTTEXTS
230 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
);
236 #ifndef LOCAL_LAYOUTTEXTS
237 model
->setItem(i
, 1, new QStandardItem(QString("%1").arg(PtrValue
)));
239 sprintf(string
, "%i : %s | %s | ", (i
+ 1), (LocalInfo
[i
].PtrVariableBaseTypeName
? LocalInfo
[i
].PtrVariableBaseTypeName
: (char *)"<font color='#ff0000'>N/A</font>"), LocalInfo
[i
].PtrVariableName
);
240 Local
+= QString(string
);
242 if ((unsigned int)LocalInfo
[i
].Adr
)
244 sprintf(string
, "0x%06X", (unsigned int)LocalInfo
[i
].Adr
);
248 if (LocalInfo
[i
].PtrCPURegisterName
)
250 sprintf(string
, "<font color='#0000FF'>%s</font>", LocalInfo
[i
].PtrCPURegisterName
);
254 sprintf(string
, "%s", (char *)"<font color='#ff0000'>N/A</font>");
258 Local
+= QString(string
);
259 sprintf(string
, " | %s", (!PtrValue
? (char *)"<font color='#ff0000'>N/A</font>" : PtrValue
));
262 #ifndef LOCAL_LAYOUTTEXTS
263 model
->setItem(i
, 2, new QStandardItem(QString("%1").arg((LocalInfo
[i
].PtrVariableBaseTypeName
? LocalInfo
[i
].PtrVariableBaseTypeName
: (char *)"<font color='#ff0000'>N/A</font>"))));
265 Local
+= QString(string
);
270 MSG
+= QString("Ready");
271 #ifdef LOCAL_LAYOUTTEXTS
273 text
->setText(Local
);
279 MSG
+= QString("No locals");
280 Error
= LOCAL_NOLOCALS
;
281 #ifdef LOCAL_LAYOUTTEXTS
286 // Display status bar
289 if ((Error
& LOCAL_WARNING
))
291 statusbar
->setStyleSheet("background-color: lightyellow; font: bold");
295 statusbar
->setStyleSheet("background-color: tomato; font: bold");
300 statusbar
->setStyleSheet("background-color: lightgreen; font: bold");
302 statusbar
->showMessage(MSG
);
308 void LocalBrowserWindow::keyPressEvent(QKeyEvent
* e
)
310 if (e
->key() == Qt::Key_Escape
)