Changeset View
Changeset View
Standalone View
Standalone View
debuggers/common/miframestackmodel.cpp
Show All 20 Lines | |||||
21 | 21 | | |||
22 | #include "miframestackmodel.h" | 22 | #include "miframestackmodel.h" | ||
23 | 23 | | |||
24 | #include "midebugsession.h" | 24 | #include "midebugsession.h" | ||
25 | #include "mi/micommand.h" | 25 | #include "mi/micommand.h" | ||
26 | 26 | | |||
27 | #include <KLocalizedString> | 27 | #include <KLocalizedString> | ||
28 | 28 | | |||
29 | #include <algorithm> | ||||
30 | | ||||
29 | using namespace KDevelop; | 31 | using namespace KDevelop; | ||
30 | using namespace KDevMI; | 32 | using namespace KDevMI; | ||
31 | using namespace KDevMI::MI; | 33 | using namespace KDevMI::MI; | ||
32 | 34 | | |||
33 | QString getFunctionOrAddress(const Value &frame) | 35 | QString getFunctionOrAddress(const Value &frame) | ||
34 | { | 36 | { | ||
35 | if (frame.hasField("func")) | 37 | if (frame.hasField("func")) | ||
36 | return frame["func"].literal(); | 38 | return frame["func"].literal(); | ||
Show All 32 Lines | 67 | { | |||
69 | // if it truely is). | 71 | // if it truely is). | ||
70 | session()->addCommand(ThreadInfo, "", this, &MIFrameStackModel::handleThreadInfo); | 72 | session()->addCommand(ThreadInfo, "", this, &MIFrameStackModel::handleThreadInfo); | ||
71 | } | 73 | } | ||
72 | 74 | | |||
73 | void MIFrameStackModel::handleThreadInfo(const ResultRecord& r) | 75 | void MIFrameStackModel::handleThreadInfo(const ResultRecord& r) | ||
74 | { | 76 | { | ||
75 | const Value& threads = r["threads"]; | 77 | const Value& threads = r["threads"]; | ||
76 | 78 | | |||
77 | // Traverse GDB threads in backward order -- since GDB | 79 | QList<FrameStackModel::ThreadItem> threadsList; | ||
78 | // reports them in backward order. We want UI to | 80 | for (int i = 0; i!= threads.size(); ++i) { | ||
79 | // show thread IDs in the natural order. | 81 | const auto &threadMI = threads[i]; | ||
80 | // FIXME: at least GDB 7.11 is reporting in the right order, | 82 | FrameStackModel::ThreadItem threadItem; | ||
81 | // consider sort the list afterwards. | 83 | threadItem.nr = threadMI["id"].toInt(); | ||
82 | | ||||
83 | QList<KDevelop::FrameStackModel::ThreadItem> threadsList; | | |||
84 | int gidx = threads.size()-1; | | |||
85 | for (; gidx >= 0; --gidx) { | | |||
86 | KDevelop::FrameStackModel::ThreadItem i; | | |||
87 | const Value & threadMI = threads[gidx]; | | |||
88 | i.nr = threadMI["id"].toInt(); | | |||
89 | if (threadMI["state"].literal() == "stopped") { | 84 | if (threadMI["state"].literal() == "stopped") { | ||
90 | i.name = getFunctionOrAddress(threads[gidx]["frame"]); | 85 | threadItem.name = getFunctionOrAddress(threadMI["frame"]); | ||
91 | } else { | 86 | } else { | ||
92 | i.name = i18n("(running)"); | 87 | i18n("(running)"); | ||
93 | } | 88 | } | ||
94 | threadsList << i; | 89 | threadsList << threadItem; | ||
95 | } | 90 | } | ||
91 | // Sort the list by id, some old version of GDB | ||||
92 | // reports them in backward order. We want UI to | ||||
93 | // show thread IDs in the natural order. | ||||
94 | std::sort(threadsList.begin(), threadsList.end(), | ||||
95 | [](const FrameStackModel::ThreadItem &a, const FrameStackModel::ThreadItem &b){ | ||||
96 | return a.nr < b.nr; | ||||
97 | }); | ||||
98 | | ||||
96 | setThreads(threadsList); | 99 | setThreads(threadsList); | ||
97 | if (r.hasField("current-thread-id")) { | 100 | if (r.hasField("current-thread-id")) { | ||
98 | int currentThreadId = r["current-thread-id"].toInt(); | 101 | int currentThreadId = r["current-thread-id"].toInt(); | ||
99 | 102 | | |||
100 | setCurrentThread(currentThreadId); | 103 | setCurrentThread(currentThreadId); | ||
101 | 104 | | |||
102 | if (session()->hasCrashed()) { | 105 | if (session()->hasCrashed()) { | ||
103 | setCrashedThreadIndex(currentThreadId); | 106 | setCrashedThreadIndex(currentThreadId); | ||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |