Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
stackcapture_p.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <sonde/sonde_core_export.h>
8
9#include <QtCore/QJsonArray>
10#include <QtCore/QJsonObject>
11#include <QtCore/QString>
12
13#include <array>
14#include <chrono>
15
16namespace Sonde::Detail {
17
20{
22 static constexpr int kCapacity = 64;
23 std::array<quintptr, kCapacity> pcs{ };
24 int count = 0;
29};
30
38{
39public:
43 static QString prepare();
45 static void release();
49 static QString capture(RawStack &out, std::chrono::milliseconds timeout);
51 static int signalNumber();
52};
53
57class SONDE_CORE_EXPORT FrameNamer
58{
59public:
62 QJsonArray frames(const RawStack &stack);
64 QJsonArray modules() const { return m_modules; }
65
66private:
69 int moduleIndex(quintptr pc, quintptr &base);
70
71 QJsonArray m_modules;
72 QList<quintptr> m_bases;
73};
74
77SONDE_CORE_EXPORT QString formatSamples(const QJsonArray &samples, const QJsonArray &modules,
78 int topFrames = 20);
79
80} // namespace Sonde::Detail
Names frames, and collects the modules they are in, for the samples of one event.
Definition stackcapture_p.h:58
QJsonArray m_modules
As modules() returns.
Definition stackcapture_p.h:71
QJsonArray frames(const RawStack &stack)
The frames of stack, as JSON objects: "module" (an index into modules()), "offset",...
Definition stackcapture.cpp:807
QList< quintptr > m_bases
Load address of each entry of m_modules.
Definition stackcapture_p.h:72
QJsonArray modules() const
The modules seen so far: "name", "path", "base" (hex) and "buildId".
Definition stackcapture_p.h:64
Taking samples of one thread's stack from another thread.
Definition stackcapture_p.h:38
static int signalNumber()
The signal used on Linux, or 0.
Definition stackcapture.cpp:433
static void release()
Stops targeting the thread; call it once no capture() can be running.
Definition stackcapture.cpp:431
static QString prepare()
Makes the calling thread the target.
Definition stackcapture.cpp:426
static QString capture(RawStack &out, std::chrono::milliseconds timeout)
Takes a sample of the target's stack into out, waiting at most timeout (Linux: for the signal handler...
Definition stackcapture.cpp:438
QString formatSamples(const QJsonArray &samples, const QJsonArray &modules, int topFrames)
The samples of one stall as text, one frame per line: identical samples folded, the top topFrames fra...
Definition stackcapture.cpp:918
A sample of a thread's stack: return addresses, innermost first.
Definition stackcapture_p.h:20
int count
How many of pcs are set.
Definition stackcapture_p.h:24
std::array< quintptr, kCapacity > pcs
Program counters; [0] is where the thread was.
Definition stackcapture_p.h:23
static constexpr int kCapacity
The most frames kept (design 0016: at most 64 per sample).
Definition stackcapture_p.h:22
int linkRegisterIndex
Index of a frame taken from the link register (arm64 macOS) rather than the stack,...
Definition stackcapture_p.h:28