Changeset View
Changeset View
Standalone View
Standalone View
debuggers/gdb/gdbframestackmodel.cpp
Show All 18 Lines | |||||
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "gdbframestackmodel.h" | 22 | #include "gdbframestackmodel.h" | ||
23 | #include "gdbcommand.h" | 23 | #include "gdbcommand.h" | ||
24 | 24 | | |||
25 | #include <KLocalizedString> | 25 | #include <KLocalizedString> | ||
26 | 26 | | |||
27 | #include <algorithm> | ||||
28 | | ||||
27 | using namespace KDevelop; | 29 | using namespace KDevelop; | ||
28 | 30 | | |||
29 | QString getFunctionOrAddress(const GDBMI::Value &frame) | 31 | QString getFunctionOrAddress(const GDBMI::Value &frame) | ||
30 | { | 32 | { | ||
31 | if (frame.hasField("func")) | 33 | if (frame.hasField("func")) | ||
32 | return frame["func"].literal(); | 34 | return frame["func"].literal(); | ||
33 | else | 35 | else | ||
34 | return frame["addr"].literal(); | 36 | return frame["addr"].literal(); | ||
Show All 19 Lines | 55 | new GDBCommand(GDBMI::ThreadInfo, "", | |||
54 | this, | 56 | this, | ||
55 | &GdbFrameStackModel::handleThreadInfo)); | 57 | &GdbFrameStackModel::handleThreadInfo)); | ||
56 | } | 58 | } | ||
57 | 59 | | |||
58 | void GdbFrameStackModel::handleThreadInfo(const GDBMI::ResultRecord& r) | 60 | void GdbFrameStackModel::handleThreadInfo(const GDBMI::ResultRecord& r) | ||
59 | { | 61 | { | ||
60 | const GDBMI::Value& threads = r["threads"]; | 62 | const GDBMI::Value& threads = r["threads"]; | ||
61 | 63 | | |||
62 | // Traverse GDB threads in backward order -- since GDB | 64 | QList<FrameStackModel::ThreadItem> threadsList; | ||
63 | // reports them in backward order. We want UI to | 65 | for (int i = 0; i!= threads.size(); ++i) { | ||
64 | // show thread IDs in the natural order. | 66 | const auto &threadMI = threads[i]; | ||
65 | // FIXME: make the code independent of whatever craziness | 67 | FrameStackModel::ThreadItem threadItem; | ||
66 | // gdb might have tomorrow. | 68 | threadItem.nr = threadMI["id"].toInt(); | ||
67 | | ||||
68 | QList<KDevelop::FrameStackModel::ThreadItem> threadsList; | | |||
69 | int gidx = threads.size()-1; | | |||
70 | for (; gidx >= 0; --gidx) { | | |||
71 | KDevelop::FrameStackModel::ThreadItem i; | | |||
72 | const GDBMI::Value & threadMI = threads[gidx]; | | |||
73 | i.nr = threadMI["id"].toInt(); | | |||
74 | if (threadMI["state"].literal() == "stopped") { | 69 | if (threadMI["state"].literal() == "stopped") { | ||
75 | i.name = getFunctionOrAddress(threads[gidx]["frame"]); | 70 | threadItem.name = getFunctionOrAddress(threadMI["frame"]); | ||
76 | } else { | 71 | } else { | ||
77 | i.name = i18n("(running)"); | 72 | i18n("(running)"); | ||
78 | } | 73 | } | ||
79 | threadsList << i; | 74 | threadsList << threadItem; | ||
80 | } | 75 | } | ||
76 | // Sort the list by id, some old version of GDB | ||||
77 | // reports them in backward order. We want UI to | ||||
78 | // show thread IDs in the natural order. | ||||
79 | std::sort(threadsList.begin(), threadsList.end(), | ||||
80 | [](const FrameStackModel::ThreadItem &a, const FrameStackModel::ThreadItem &b){ | ||||
81 | return a.nr < b.nr; | ||||
82 | }); | ||||
83 | | ||||
81 | setThreads(threadsList); | 84 | setThreads(threadsList); | ||
82 | if (r.hasField("current-thread-id")) { | 85 | if (r.hasField("current-thread-id")) { | ||
83 | int currentThreadId = r["current-thread-id"].toInt(); | 86 | int currentThreadId = r["current-thread-id"].toInt(); | ||
84 | 87 | | |||
85 | setCurrentThread(currentThreadId); | 88 | setCurrentThread(currentThreadId); | ||
86 | 89 | | |||
87 | if (session()->hasCrashed()) { | 90 | if (session()->hasCrashed()) { | ||
88 | setCrashedThreadIndex(currentThreadId); | 91 | setCrashedThreadIndex(currentThreadId); | ||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |