Skip to content

Commit 8d6b9cc

Browse files
authored
Allow attaching to the sidecar via gdb (#687)
It worked when DD_SPAWN_WORKER_USE_EXEC=1 was set, but not generally. Having a /proc/<pid>/X path will tell gdb exactly where to find it, instead of a /proc/self/fd/X which is pointing into gdbs own process from the perspective of gdb. This also prevented sidecar core dumps from being opened with gdb, which was rather ugly. Signed-off-by: Bob Weinand <[email protected]>
1 parent 7224cd1 commit 8d6b9cc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

spawn_worker/src/trampoline.c

+10
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ int main(int argc, char *argv[]) {
6767
unlink_next = true;
6868
continue;
6969
}
70+
#ifndef _WIN32
71+
char buf[30];
72+
// Redirect the symlinked /proc/self/X to the actual /proc/<pid>/X - as otherwise debugging tooling may try to read it
73+
// And reading /proc/self from the debugging tooling will usually lead to it reading from itself, which may be flatly wrong
74+
// E.g. gdb will just hang up for e.g. /proc/self/fd/4, which is an open pipe...
75+
if (strncmp(lib_path, "/proc/self/", strlen("/proc/self/")) == 0 && strlen(lib_path) < 20) {
76+
sprintf(buf, "/proc/%d/%s", getpid(), lib_path + strlen("/proc/self/"));
77+
lib_path = buf;
78+
}
79+
#endif
7080
if (!(handles[additional_shared_libraries_count++] = dlopen(lib_path, RTLD_LAZY | RTLD_GLOBAL))) {
7181
fputs(dlerror(), error_fd());
7282
return 9;

trace-utils/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ path = "benches/main.rs"
1616

1717
[dependencies]
1818
anyhow = "1.0"
19-
hyper = { version = "0.14", features = ["client", "server", "backports", "deprecated"] }
19+
hyper = { version = "0.14", features = ["client", "server", "runtime", "backports", "deprecated"] }
2020
hyper-proxy = { version = "0.9.1", default-features = false, features = ["rustls"], optional = true }
2121
hyper-rustls = {version = "0.27", default-features = false, features = ["native-tokio", "http1", "tls12"]}
2222
serde = { version = "1.0.145", features = ["derive"] }

0 commit comments

Comments
 (0)