Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setter for Program flags #246

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Tim---
Copy link
Contributor

@Tim--- Tim--- commented Jan 25, 2023

The ProgramFlags are set by the program_from_* functions, and cannot be modified. This makes several features of drgn unavailable if used as a library.

This patch adds write access to the program flags.

In practice, I use qemu-system and gdb to debug a vmlinux.
Changing the program flags allows me to use a Program created with the default constructor to use Linux specific functions (eg: getting threads).

import gdb
from drgn import Architecture, Platform, Program, ProgramFlags

def read_mem(address, count, offset, physical):
    return gdb.inferiors()[0].read_memory(address, count)

prog = Program(Platform(Architecture.I386))
prog.flags |= ProgramFlags.IS_LINUX_KERNEL
prog.add_memory_segment(1, (1<<32)-1, read_mem)
prog.load_debug_info(['vmlinux'])

for thread in prog.threads():
    print(thread.object.comm)

The ProgramFlags are set by the program_from_* functions, and cannot be
modified. This makes several features of drgn unavailable if used as a
library.

This patch adds write access to the program flags.

Signed-off-by: Timothée Cocault <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant