This patch is a proof of concept that shows how a scripted process could be used with real process to perform interactive debugging. In this example, we run a process that spawns 10 threads. Then, we create a intermediary scripted process who's job will be to wrap the real process while intercepting it's process events and dispatching them back either to the real process or to other child scripted processes. In this example, we have 2 child scripted processes, with even and odd thread indices. The goal is to be able to do thread filtering and explore the various interactive debugging approaches, by letting a child process running when stopping the other process and inspecting it. Another approach would be to have the child processes execution in-sync to force running every child process when one of them starts running. Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
36 lines
698 B
C++
36 lines
698 B
C++
#include <iostream>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
void spawn_thread(int index) {
|
|
std::string name = "I'm thread " + std::to_string(index) + " !";
|
|
bool done = false;
|
|
std::string state = "Started execution!";
|
|
while (true) {
|
|
if (done) // also break here
|
|
break;
|
|
}
|
|
|
|
state = "Stopped execution!";
|
|
}
|
|
|
|
int main() {
|
|
size_t num_threads = 10;
|
|
std::vector<std::thread> threads;
|
|
|
|
for (size_t i = 0; i < num_threads; i++) {
|
|
threads.push_back(std::thread(spawn_thread, i));
|
|
}
|
|
|
|
std::cout << "Spawned " << threads.size() << " threads!"; // Break here
|
|
|
|
for (auto &t : threads) {
|
|
if (t.joinable())
|
|
t.join();
|
|
}
|
|
|
|
return 0;
|
|
}
|