libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
ForeignTracee.cxx
1// cosmos
2#include <cosmos/error/ApiError.hxx>
3#include <cosmos/io/ILogger.hxx>
4#include <cosmos/proc/process.hxx>
5
6// clues
7#include <clues/ForeignTracee.hxx>
8#include <clues/logger.hxx>
9
10namespace clues {
11
13 TraceePtr sibling) :
14 Tracee{engine, consumer, sibling} {
15 /*
16 * NOTE: the approach using `sibling` for keeping track of process
17 * data sharing is relatively simple at the moment but doesn't
18 * necessarily cover all situations.
19 * An application might explicitly add two threads of the same process
20 * to an Engine instance, in which case the process sharing
21 * relationship is lost. It's questionable whether such use cases
22 * should be supported at all, though.
23 *
24 * Another approach would be to parse the Tgid from each new Tracee's
25 * /proc/<pid>/status file. This involves a lot of additional
26 * complexity, however:
27 *
28 * - parsing the file can fail (e.g. the tracee disappeared in the
29 * meanwhile).
30 * - parsing the file for each an every tracee adds additional
31 * overhead (an file I/O for each attach could be especially
32 * problematic).
33 * - the Engine would need to keep track of all existing thread groups
34 * and their members, more data that can get out of sync.
35 *
36 * Thus, for the moment, stick to the simple `sibling` approach which
37 * should work well enough for most scenarios.
38 */
39}
40
41void ForeignTracee::configure(const cosmos::ProcessID tracee) {
42 setPID(tracee);
43}
44
45ForeignTracee::~ForeignTracee() {
46 try {
47 detach();
48 } catch (const cosmos::CosmosError &ce) {
49 LOG_DEBUG("Couldn't detach from PID " << cosmos::to_integral(m_ptrace.pid()) << ":\n\n" << ce.what());
50 }
51}
52
53} // end ns
Callback interface for consumers of tracing events.
void configure(const cosmos::ProcessID tracee)
Sets the given process ID as the process to be traced.
ForeignTracee(Engine &engine, EventConsumer &consumer, TraceePtr sibling=nullptr)
Create a traced process object by attaching to the given process ID.
void setPID(const cosmos::ProcessID tracee)
Sets the tracee PID.
Definition Tracee.cxx:129
bool detach()
Attempt to detach the Tracee.
Definition Tracee.cxx:177
Tracee(Engine &engine, EventConsumer &consumer, TraceePtr sibling=nullptr)
Definition Tracee.cxx:100
cosmos::Tracee m_ptrace
libcosmos API for the Tracee.
Definition Tracee.hxx:444