From cf649b741acce4fb6f6728d76cc2528fad5b06e0 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Thu, 29 Jun 2023 13:27:16 -0700 Subject: [PATCH] Add DRGN_PROGRAM_IS_LOCAL flag Currently, when drgn is used to debug a running program, we assume it to be running on the local machine. However, with remote debugging, this will no longer be the case. To accommodate remote debugging, introduce a flag DRGN_PROGRAM_IS_LOCAL, and use it to decide whether to use /sys/module. Signed-off-by: Peter Collingbourne --- _drgn.pyi | 5 +++++ libdrgn/drgn.h.in | 2 ++ libdrgn/linux_kernel.c | 2 +- libdrgn/program.c | 5 +++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/_drgn.pyi b/_drgn.pyi index 35af2772b..82eb4d067 100644 --- a/_drgn.pyi +++ b/_drgn.pyi @@ -837,6 +837,11 @@ class ProgramFlags(enum.Flag): kernel or a running process). """ + IS_LOCAL = ... + """ + The program is running on the local machine. + """ + class FindObjectFlags(enum.Flag): """ ``FindObjectFlags`` are flags for :meth:`Program.object()`. These can be diff --git a/libdrgn/drgn.h.in b/libdrgn/drgn.h.in index 7dccce30d..ea1afa793 100644 --- a/libdrgn/drgn.h.in +++ b/libdrgn/drgn.h.in @@ -507,6 +507,8 @@ enum drgn_program_flags { DRGN_PROGRAM_IS_LINUX_KERNEL = (1 << 0), /** The program is currently running. */ DRGN_PROGRAM_IS_LIVE = (1 << 1), + /** The program is running on the local machine. */ + DRGN_PROGRAM_IS_LOCAL = (1 << 2), }; /** diff --git a/libdrgn/linux_kernel.c b/libdrgn/linux_kernel.c index 187de5676..19eddc9d0 100644 --- a/libdrgn/linux_kernel.c +++ b/libdrgn/linux_kernel.c @@ -1566,7 +1566,7 @@ report_kernel_modules(struct drgn_debug_info_load_state *load, * /sys/module/$module/sections. */ bool use_sys_module = false; - if (prog->flags & DRGN_PROGRAM_IS_LIVE) { + if (prog->flags & DRGN_PROGRAM_IS_LOCAL) { char *env = getenv("DRGN_USE_SYS_MODULE"); use_sys_module = !env || atoi(env); } diff --git a/libdrgn/program.c b/libdrgn/program.c index 48b97d5ab..d86790772 100644 --- a/libdrgn/program.c +++ b/libdrgn/program.c @@ -550,7 +550,8 @@ drgn_program_set_core_dump_fd_internal(struct drgn_program *prog, int fd, goto out_segments; } prog->flags |= (DRGN_PROGRAM_IS_LINUX_KERNEL | - DRGN_PROGRAM_IS_LIVE); + DRGN_PROGRAM_IS_LIVE | + DRGN_PROGRAM_IS_LOCAL); elf_end(prog->core); prog->core = NULL; } else if (vmcoreinfo_note) { @@ -674,7 +675,7 @@ drgn_program_set_pid(struct drgn_program *prog, pid_t pid) goto out_segments; prog->pid = pid; - prog->flags |= DRGN_PROGRAM_IS_LIVE; + prog->flags |= DRGN_PROGRAM_IS_LIVE | DRGN_PROGRAM_IS_LOCAL; return NULL; out_segments: