Project has switched to libdwarf 20210305
[clinton/Virtual-Jaguar-Rx.git] / src / debugger / NewFnctBreakpointWin.cpp
1 //
2 // NewFnctBreakpointsWin.cpp - New function breakpoint
3 //
4 // by Jean-Paul Mari
5 //
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
7 //
8 // Who When What
9 // --- ---------- -----------------------------------------------------------
10 // JPM 10/19/2018 Created this file
11 //
12
13 // STILL TO DO:
14 // Set information (name, etc.) for the asm function
15 // Find a way to refresh the breakpoints list window
16 //
17
18 #include "debugger/NewFnctBreakpointWin.h"
19 #include "jaguar.h"
20 #include "debugger/DBGManager.h"
21 #include "m68000/m68kinterface.h"
22 #include "settings.h"
23
24
25 //
26 NewFnctBreakpointWindow::NewFnctBreakpointWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog),
27 layout(new QVBoxLayout),
28 address(new QLineEdit),
29 add(new QPushButton(tr("Add")))
30 {
31 setWindowTitle(tr("New function breakpoint"));
32
33 address->setPlaceholderText("0x<value>, decimal value or symbol name");
34
35 QHBoxLayout * hbox1 = new QHBoxLayout;
36 hbox1->addWidget(address);
37 hbox1->addWidget(add);
38
39 layout->addLayout(hbox1);
40 setLayout(layout);
41
42 connect(add, SIGNAL(clicked()), this, SLOT(AddBreakpointAddress()));
43 }
44
45
46 //
47 void NewFnctBreakpointWindow::keyPressEvent(QKeyEvent * e)
48 {
49 if (e->key() == Qt::Key_Escape)
50 {
51 hide();
52 }
53 else
54 {
55 if (e->key() == Qt::Key_Return)
56 {
57 AddBreakpointAddress();
58 }
59 }
60 }
61
62
63 // Add a breakpoint to the address
64 // Address can be an hexa, decimal or a symbol name
65 void NewFnctBreakpointWindow::AddBreakpointAddress(void)
66 {
67 bool ok;
68 size_t len;
69 QString newAddress;
70 size_t adr;
71 S_BrkInfo Brk;
72
73 memset(&Brk, 0, sizeof(Brk));
74 QPalette p = address->palette();
75 newAddress = address->text();
76
77 if ((len = newAddress.size()))
78 {
79 if ((len > 1) && (newAddress.at(0) == QChar('0')) && (newAddress.at(1) == QChar('x')))
80 {
81 adr = newAddress.toUInt(&ok, 16);
82 }
83 else
84 {
85 if (!(adr = DBGManager_GetAdrFromSymbolName(newAddress.toLatin1().data())))
86 {
87 adr = newAddress.toUInt(&ok, 10);
88 }
89 else
90 {
91 ok = true;
92 }
93 }
94
95 // Check validity address
96 if (ok && (adr < 0xffffff))
97 {
98 // Set information based on address
99 Brk.Name = DBGManager_GetSymbolNameFromAdr(adr);
100 Brk.Filename = DBGManager_GetFullSourceFilenameFromAdr(adr, NULL);
101 Brk.NumLine = DBGManager_GetNumLineFromAdr(adr, DBG_TAG_subprogram);
102 Brk.LineSrc = DBGManager_GetLineSrcFromAdrNumLine(adr, Brk.NumLine);
103
104 // In all cases, consider address as valid
105 Brk.Adr = adr;
106
107 // Add the breakpoint
108 if (m68k_brk_add(&Brk))
109 {
110 p.setColor(QPalette::Text, Qt::black);
111 }
112 else
113 {
114 p.setColor(QPalette::Text, Qt::darkYellow);
115 }
116 }
117 else
118 {
119 // Address is not valid
120 p.setColor(QPalette::Text, Qt::red);
121 }
122
123 address->setPalette(p);
124 }
125 }