1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "gdbengine.h"
35 #include "abstractgdbadapter.h"
36 #include "debuggeractions.h"
37 #include "debuggercore.h"
38 #include "debuggerstringutils.h"
39 #include "debuggertooltipmanager.h"
41 #include "breakhandler.h"
42 #include "watchhandler.h"
43 #include "stackhandler.h"
45 #include <utils/qtcassert.h>
47 #define PRECONDITION QTC_ASSERT(hasPython(), /**/)
48 #define CB(callback) &GdbEngine::callback, STRINGIFY(callback)
54 void GdbEngine::updateLocalsPython(bool tryPartial, const QByteArray &varList)
57 m_processedNames.clear();
58 watchHandler()->beginCycle(!tryPartial);
59 //m_toolTipExpression.clear();
60 WatchHandler *handler = watchHandler();
62 QByteArray expanded = "expanded:" + handler->expansionRequests() + ' ';
63 expanded += "typeformats:" + handler->typeFormatRequests() + ' ';
64 expanded += "formats:" + handler->individualFormatRequests();
67 const QString fileName = stackHandler()->currentFrame().file;
68 const QString function = stackHandler()->currentFrame().function;
69 if (!fileName.isEmpty()) {
70 QStringList expressions =
71 DebuggerToolTipManager::instance()->treeWidgetExpressions(fileName, objectName(), function);
72 const QString currentExpression = tooltipExpression();
73 if (!currentExpression.isEmpty() && !expressions.contains(currentExpression))
74 expressions.push_back(currentExpression);
75 foreach (const QString &te, expressions) {
76 if (!watchers.isEmpty())
78 watchers += te.toLatin1();
80 watchers += tooltipIName(te);
84 QHash<QByteArray, int> watcherNames = handler->watcherNames();
85 QHashIterator<QByteArray, int> it(watcherNames);
86 while (it.hasNext()) {
88 if (!watchers.isEmpty())
90 watchers += it.key() + "#watch." + QByteArray::number(it.value());
94 if (debuggerCore()->boolSetting(UseDebuggingHelpers))
96 if (debuggerCore()->boolSetting(AutoDerefPointers))
97 options += "autoderef,";
98 if (!qgetenv("QTC_DEBUGGER_PYTHON_VERBOSE").isEmpty())
100 if (options.isEmpty())
101 options += "defaults,";
103 options += "partial,";
106 QByteArray resultVar;
107 if (!m_resultVarName.isEmpty())
108 resultVar = "resultvarname:" + m_resultVarName + ' ';
110 postCommand("bb options:" + options + " vars:" + varList + ' '
111 + resultVar + expanded + " watchers:" + watchers.toHex(),
112 WatchUpdate, CB(handleStackFramePython), QVariant(tryPartial));
115 void GdbEngine::handleStackListLocalsPython(const GdbResponse &response)
118 if (response.resultClass == GdbResultDone) {
119 // 44^done,data={locals=[name="model",name="backString",...]}
120 QByteArray varList = "vars"; // Dummy entry, will be stripped by dumper.
121 foreach (const GdbMi &child, response.data.findChild("locals").children()) {
123 varList.append(child.data());
125 updateLocalsPython(false, varList);
129 void GdbEngine::handleStackFramePython(const GdbResponse &response)
132 if (response.resultClass == GdbResultDone) {
133 const bool partial = response.cookie.toBool();
134 //qDebug() << "READING " << (partial ? "PARTIAL" : "FULL");
135 QByteArray out = response.data.findChild("consolestreamoutput").data();
136 while (out.endsWith(' ') || out.endsWith('\n'))
138 //qDebug() << "SECOND CHUNK: " << out;
139 int pos = out.indexOf("data=");
141 showMessage(_("DISCARDING JUNK AT BEGIN OF RESPONSE: "
146 all.fromStringMultiple(out);
147 //qDebug() << "ALL: " << all.toString();
149 GdbMi data = all.findChild("data");
150 QList<WatchData> list;
151 foreach (const GdbMi &child, data.children()) {
153 dummy.iname = child.findChild("iname").data();
154 GdbMi wname = child.findChild("wname");
155 if (wname.isValid()) {
156 // Happens (only) for watched expressions. They are encoded as.
157 // base64 encoded 8 bit data, without quotes
158 dummy.name = decodeData(wname.data(), 5);
159 dummy.exp = dummy.name.toUtf8();
161 dummy.name = _(child.findChild("name").data());
163 //qDebug() << "CHILD: " << child.toString();
164 parseWatchData(watchHandler()->expandedINames(), dummy, child, &list);
166 watchHandler()->insertBulkData(list);
167 //for (int i = 0; i != list.size(); ++i)
168 // qDebug() << "LOCAL: " << list.at(i).toString();
171 data = all.findChild("bkpts");
172 if (data.isValid()) {
173 BreakHandler *handler = breakHandler();
174 foreach (const GdbMi &child, data.children()) {
175 int bpNumber = child.findChild("number").data().toInt();
176 int found = handler->findBreakpoint(bpNumber);
178 BreakpointData *bp = handler->at(found);
179 GdbMi addr = child.findChild("addr");
180 if (addr.isValid()) {
181 bp->bpAddress = child.findChild("addr").data();
184 bp->bpAddress = "<PENDING>";
187 bp->bpFuncName = child.findChild("func").data();
188 bp->bpLineNumber = child.findChild("line").data();
189 bp->bpFileName = child.findChild("file").data();
190 bp->markerLineNumber = bp->bpLineNumber.toInt();
191 bp->markerFileName = bp->bpFileName;
192 // Happens with moved/symlinked sources.
193 if (!bp->fileName.isEmpty()
194 && !bp->bpFileName.isEmpty()
195 && bp->fileName != bp->bpFileName)
196 bp->markerFileName = bp->fileName;
198 QTC_ASSERT(false, qDebug() << child.toString() << bpNumber);
199 //bp->bpNumber = "<unavailable>";
202 handler->updateMarkers();
206 //PENDING_DEBUG("AFTER handleStackFrame()");
207 // FIXME: This should only be used when updateLocals() was
208 // triggered by expanding an item in the view.
209 if (m_pendingWatchRequests <= 0) {
210 //PENDING_DEBUG("\n\n .... AND TRIGGERS MODEL UPDATE\n");
214 emit stackFrameCompleted();
216 showMessage(_("DUMPER FAILED: " + response.toString()));
220 // Called from CoreAdapter and AttachAdapter
221 void GdbEngine::updateAllPython()
224 //PENDING_DEBUG("UPDATING ALL\n");
225 QTC_ASSERT(state() == InferiorUnrunnable || state() == InferiorStopOk, /**/);
226 reloadModulesInternal();
227 postCommand("-stack-list-frames", CB(handleStackListFrames),
228 QVariant::fromValue<StackCookie>(StackCookie(false, true)));
229 stackHandler()->setCurrentIndex(0);
230 if (m_gdbAdapter->isTrkAdapter())
231 m_gdbAdapter->trkReloadThreads();
233 postCommand("-thread-list-ids", CB(handleThreadListIds), 0);
238 } // namespace Internal
239 } // namespace Debugger