mirror of
https://github.com/intel/llvm.git
synced 2026-01-24 08:30:34 +08:00
This patch extends ScriptedFrame to work with real (non-scripted) threads, enabling frame providers to synthesize frames for native processes. Previously, ScriptedFrame only worked within ScriptedProcess/ScriptedThread contexts. This patch decouples ScriptedFrame from ScriptedThread, allowing users to augment or replace stack frames in real debugging sessions for use cases like custom calling conventions, reconstructing corrupted frames from core files, or adding diagnostic frames. Key changes: - ScriptedFrame::Create() now accepts ThreadSP instead of requiring ScriptedThread, extracting architecture from the target triple rather than ScriptedProcess.arch - Added SBTarget::RegisterScriptedFrameProvider() and ClearScriptedFrameProvider() APIs, with Target storing a SyntheticFrameProviderDescriptor template for new threads - Added "target frame-provider register/clear" commands for CLI access - Thread class gains LoadScriptedFrameProvider(), ClearScriptedFrameProvider(), and GetFrameProvider() methods for per-thread frame provider management - New SyntheticStackFrameList overrides FetchFramesUpTo() to lazily provide frames from either the frame provider or the real stack This enables practical use of the SyntheticFrameProvider infrastructure in real debugging workflows. rdar://161834688 Signed-off-by: Med Ismail Bennani <ismail@bennani.ma> Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
56 lines
1.2 KiB
C++
56 lines
1.2 KiB
C++
// Multi-threaded test program for testing frame providers.
|
|
|
|
#include <condition_variable>
|
|
#include <iostream>
|
|
#include <mutex>
|
|
#include <thread>
|
|
|
|
std::mutex mtx;
|
|
std::condition_variable cv;
|
|
int ready_count = 0;
|
|
constexpr int NUM_THREADS = 2;
|
|
|
|
void thread_func(int thread_num) {
|
|
std::cout << "Thread " << thread_num << " started\n";
|
|
|
|
{
|
|
std::unique_lock<std::mutex> lock(mtx);
|
|
ready_count++;
|
|
if (ready_count == NUM_THREADS + 1) {
|
|
cv.notify_all();
|
|
} else {
|
|
cv.wait(lock, [] { return ready_count == NUM_THREADS + 1; });
|
|
}
|
|
}
|
|
|
|
std::cout << "Thread " << thread_num << " at breakpoint\n"; // Break here
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
std::thread threads[NUM_THREADS];
|
|
|
|
for (int i = 0; i < NUM_THREADS; i++) {
|
|
threads[i] = std::thread(thread_func, i);
|
|
}
|
|
|
|
{
|
|
std::unique_lock<std::mutex> lock(mtx);
|
|
ready_count++;
|
|
if (ready_count == NUM_THREADS + 1) {
|
|
cv.notify_all();
|
|
} else {
|
|
cv.wait(lock, [] { return ready_count == NUM_THREADS + 1; });
|
|
}
|
|
}
|
|
|
|
std::cout << "Main thread at barrier\n";
|
|
|
|
// Join threads
|
|
for (int i = 0; i < NUM_THREADS; i++) {
|
|
threads[i].join();
|
|
}
|
|
|
|
std::cout << "All threads completed\n";
|
|
return 0;
|
|
}
|