-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.cpp
More file actions
38 lines (31 loc) · 1.07 KB
/
Copy pathcontroller.cpp
File metadata and controls
38 lines (31 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "PCProcess.h"
#include "Event.h"
#include <iostream>
#include <string>
using namespace Dyninst;
using namespace ProcControlAPI;
using namespace std;
Process::cb_ret_t on_thread_create(Event::const_ptr ev)
{
// Callback when the target process creates a thread.
EventNewThread::const_ptr new_thrd_ev = ev->getEventNewThread();
Thread::const_ptr new_thrd = new_thrd_ev->getNewThread();
cout << "Got a new thread with LWP " << new_thrd->getLWP() << endl;
return Process::cbDefault;
}
int main(int argc, char *argv[]) {
vector<string> args;
// Create a new target process
string exec = argv[1];
for (unsigned i=1; i<argc; i++)
args.push_back(std::string(argv[i]));
Process::ptr proc = Process::createProcess(exec, args);
assert (proc != NULL && "Proc cannot be NULL!");
// Tell ProcControlAPI about our callback function
Process::registerEventCallback(EventType::ThreadCreate, on_thread_create);
// Run the process and wait for it to terminate.
proc->continueProc();
while (!proc->isTerminated())
Process::handleEvents(true);
return 0;
}