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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libdrgn/drgn.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,10 @@ struct drgn_error *drgn_program_from_pid(pid_t pid, struct drgn_program **ret);
/** Get the set of @ref drgn_program_flags applying to a @ref drgn_program. */
enum drgn_program_flags drgn_program_flags(struct drgn_program *prog);

/** Set the set of @ref drgn_program_flags applying to a @ref drgn_program. */
void drgn_program_set_flags(struct drgn_program *prog,
enum drgn_program_flags flags);

/**
* Get the platform of a @ref drgn_program.
*
Expand Down
6 changes: 6 additions & 0 deletions libdrgn/program.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ drgn_program_flags(struct drgn_program *prog)
return prog->flags;
}

LIBDRGN_PUBLIC void drgn_program_set_flags(struct drgn_program *prog,
enum drgn_program_flags flags)
{
prog->flags = flags;
}

LIBDRGN_PUBLIC const struct drgn_platform *
drgn_program_platform(struct drgn_program *prog)
{
Expand Down
25 changes: 24 additions & 1 deletion libdrgn/python/program.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,29 @@ static PyObject *Program_get_flags(Program *self, void *arg)
(unsigned long)self->prog.flags);
}

static int Program_set_flags(Program *self, PyObject *value, void *arg)
{
PyObject *value_attr;
unsigned long flags;

if (!PyObject_IsInstance(value, ProgramFlags_class)) {
PyErr_SetString(PyExc_TypeError, "flags must be ProgramFlags");
return -1;
}

value_attr = PyObject_GetAttrString(value, "value");
if (!value_attr)
return -1;

flags = PyLong_AsUint64Mask(value_attr);

drgn_program_set_flags(&self->prog, flags);

Py_DECREF(value_attr);

return 0;
}

static PyObject *Program_get_platform(Program *self, void *arg)
{
const struct drgn_platform *platform;
Expand Down Expand Up @@ -1089,7 +1112,7 @@ static PyMemberDef Program_members[] = {
};

static PyGetSetDef Program_getset[] = {
{"flags", (getter)Program_get_flags, NULL, drgn_Program_flags_DOC},
{"flags", (getter)Program_get_flags, (setter)Program_set_flags, drgn_Program_flags_DOC},
{"platform", (getter)Program_get_platform, NULL,
drgn_Program_platform_DOC},
{"language", (getter)Program_get_language, (setter)Program_set_language,
Expand Down