3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
13 #include <ksimpleconfig.h>
15 #include "dbgdriver.h" /* memory dump formats */
17 MemoryWindow::MemoryWindow(QWidget
* parent
, const char* name
) :
18 QWidget(parent
, name
),
20 m_expression(true, this, "expression"),
21 m_memory(this, "memory"),
23 m_format(MDTword
| MDThex
)
25 QSize minSize
= m_expression
.sizeHint();
26 m_expression
.setMinimumSize(minSize
);
27 m_expression
.setInsertionPolicy(QComboBox::NoInsertion
);
28 m_expression
.setMaxCount(15);
30 m_memory
.addColumn(i18n("Address"), 80);
31 m_memory
.addColumn(i18n("Contents"), 200);
32 m_memory
.setSorting(-1); /* don't sort */
33 m_memory
.setAllColumnsShowFocus(true);
34 m_memory
.header()->setClickEnabled(false);
37 m_layout
.addWidget(&m_expression
, 0);
38 m_layout
.addWidget(&m_memory
, 10);
42 connect(&m_expression
, SIGNAL(activated(const char*)),
43 this, SLOT(slotNewExpression(const char*)));
45 connect(&m_expression
, SIGNAL(activated(const QString
&)),
46 this, SLOT(slotNewExpression(const QString
&)));
50 m_popup
.insertItem(i18n("B&ytes"), MDTbyte
);
51 m_popup
.insertItem(i18n("Halfwords (&2 Bytes)"), MDThalfword
);
52 m_popup
.insertItem(i18n("Words (&4 Bytes)"), MDTword
);
53 m_popup
.insertItem(i18n("Giantwords (&8 Bytes)"), MDTgiantword
);
54 m_popup
.insertSeparator();
55 m_popup
.insertItem(i18n("He&xadecimal"), MDThex
);
56 m_popup
.insertItem(i18n("Signed &decimal"), MDTsigned
);
57 m_popup
.insertItem(i18n("&Unsigned decimal"), MDTunsigned
);
58 m_popup
.insertItem(i18n("&Octal"), MDToctal
);
59 m_popup
.insertItem(i18n("&Binary"), MDTbinary
);
60 m_popup
.insertItem(i18n("&Addresses"), MDTaddress
);
61 m_popup
.insertItem(i18n("&Character"), MDTchar
);
62 m_popup
.insertItem(i18n("&Floatingpoint"), MDTfloat
);
63 m_popup
.insertItem(i18n("&Strings"), MDTstring
);
64 m_popup
.insertItem(i18n("&Instructions"), MDTinsn
);
65 connect(&m_popup
, SIGNAL(activated(int)), this, SLOT(slotTypeChange(int)));
68 * Handle right mouse button. Signal righteButtonClicked cannot be
69 * used, because it works only over items, not over the blank window.
71 m_memory
.viewport()->installEventFilter(this);
73 m_formatCache
.setAutoDelete(true);
76 MemoryWindow::~MemoryWindow()
81 # define MOUSEPRESS Event_MouseButtonPress
83 # define MOUSEPRESS QEvent::MouseButtonPress
86 bool MemoryWindow::eventFilter(QObject
* o
, QEvent
* ev
)
88 if (ev
->type() == MOUSEPRESS
) {
89 handlePopup(static_cast<QMouseEvent
*>(ev
));
95 void MemoryWindow::handlePopup(QMouseEvent
* ev
)
97 if (ev
->button() == RightButton
)
100 if (m_popup
.isVisible())
106 m_popup
.popup(mapToGlobal(ev
->pos()));
112 // this slot is only needed for Qt 1.44
113 void MemoryWindow::slotNewExpression(const char* newText
)
115 slotNewExpression(QString(newText
));
118 void MemoryWindow::slotNewExpression(const QString
& newText
)
120 QString text
= newText
.simplifyWhiteSpace();
122 // see if the string is in the list
123 // (note: must count downwards because of removeItem!)
124 for (int i
= m_expression
.count()-1; i
>= 0; i
--)
126 if (m_expression
.text(i
) == text
) {
128 // look up the format that was used last time for this expr
129 unsigned* pFormat
= m_formatCache
[text
];
132 m_debugger
->setMemoryFormat(m_format
);
134 // remove this text, will be inserted at the top
135 m_expression
.removeItem(i
);
138 m_expression
.insertItem(text
, 0);
140 if (text
.isEmpty()) {
141 // if format was not in the cache, insert it
142 if (m_formatCache
[text
] == 0) {
143 m_formatCache
.insert(text
, new unsigned(m_format
));
148 displayNewExpression(text
);
151 void MemoryWindow::displayNewExpression(const QString
& expr
)
153 m_debugger
->setMemoryExpression(expr
);
154 m_expression
.setEditText(expr
);
156 // clear memory dump if no dump wanted
157 if (expr
.isEmpty()) {
162 void MemoryWindow::slotTypeChange(int id
)
165 if (id
& MDTsizemask
)
166 m_format
= (m_format
& ~MDTsizemask
) | id
;
167 if (id
& MDTformatmask
)
168 m_format
= (m_format
& ~MDTformatmask
) | id
;
169 m_debugger
->setMemoryFormat(m_format
);
171 // change the format in the cache
172 QString expr
= m_expression
.currentText();
173 expr
= expr
.simplifyWhiteSpace();
174 unsigned* pFormat
= m_formatCache
[expr
];
179 displayNewExpression(expr
);
182 void MemoryWindow::slotNewMemoryDump(const QString
& msg
, QList
<MemoryDump
>& memdump
)
185 if (!msg
.isEmpty()) {
186 new QListViewItem(&m_memory
, QString(), msg
);
190 QListViewItem
* after
= 0;
191 MemoryDump
* md
= memdump
.first();
192 for (; md
!= 0; md
= memdump
.next()) {
193 QString addr
= md
->address
.asString() + " " + md
->address
.fnoffs
;
194 after
= new QListViewItem(&m_memory
, after
, addr
, md
->dump
);
198 static const char MemoryGroup
[] = "Memory";
199 static const char NumExprs
[] = "NumExprs";
200 static const char ExpressionFmt
[] = "Expression%d";
201 static const char FormatFmt
[] = "Format%d";
202 static const char ColumnWidths
[] = "ColumnWidths";
204 void MemoryWindow::saveProgramSpecific(KSimpleConfig
* config
)
206 KConfigGroupSaver
s(config
, MemoryGroup
);
208 int numEntries
= m_expression
.count();
209 config
->writeEntry(NumExprs
, numEntries
);
212 for (int i
= 0; i
< numEntries
;) {
213 QString text
= m_expression
.text(i
);
214 i
++; /* entries are counted 1-based */
215 exprEntry
.sprintf(ExpressionFmt
, i
);
216 fmtEntry
.sprintf(FormatFmt
, i
);
217 config
->writeEntry(exprEntry
, text
);
218 unsigned* pFormat
= m_formatCache
[text
];
219 unsigned fmt
= pFormat
!= 0 ? *pFormat
: MDTword
| MDThex
;
220 config
->writeEntry(fmtEntry
, fmt
);
226 for (int i
= 0; i
< 2; i
++) {
227 int w
= m_memory
.columnWidth(i
);
231 config
->writeEntry(ColumnWidths
, widths
);
234 void MemoryWindow::restoreProgramSpecific(KSimpleConfig
* config
)
236 KConfigGroupSaver
s(config
, MemoryGroup
);
238 int numEntries
= config
->readNumEntry(NumExprs
, 0);
239 m_expression
.clear();
243 // entries are counted 1-based
244 for (int i
= 1; i
<= numEntries
; i
++) {
245 exprEntry
.sprintf(ExpressionFmt
, i
);
246 fmtEntry
.sprintf(FormatFmt
, i
);
247 QString expr
= config
->readEntry(exprEntry
);
248 unsigned fmt
= config
->readNumEntry(fmtEntry
, MDTword
| MDThex
);
249 m_expression
.insertItem(expr
);
250 m_formatCache
.replace(expr
, new unsigned(fmt
& (MDTsizemask
| MDTformatmask
)));
253 // initialize with top expression
254 if (numEntries
> 0) {
255 m_expression
.setCurrentItem(0);
256 QString expr
= m_expression
.text(0);
257 m_format
= *m_formatCache
[expr
];
258 m_debugger
->setMemoryFormat(m_format
);
259 displayNewExpression(expr
);
264 int n
= config
->readListEntry(ColumnWidths
, widths
);
267 for (int i
= 0; i
< n
; i
++) {
268 QString wStr
= widths
.at(i
);
270 int w
= wStr
.toInt(&ok
);
272 m_memory
.setColumnWidth(i
, w
);
277 #include "memwindow.moc"