Skip to content

Commit

Permalink
Add DRGN_PROGRAM_IS_LOCAL flag
Browse files Browse the repository at this point in the history
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 <pcc@google.com>
  • Loading branch information
pcc authored and osandov committed Oct 6, 2023
1 parent 31bb9c0 commit cf649b7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions _drgn.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions libdrgn/drgn.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};

/**
Expand Down
2 changes: 1 addition & 1 deletion libdrgn/linux_kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions libdrgn/program.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit cf649b7

Please sign in to comment.