Skip to content

Commit

Permalink
DLPX-88975 update-package failed with a merge conflict in the drgn br…
Browse files Browse the repository at this point in the history
  • Loading branch information
manoj-joseph committed Nov 30, 2023
2 parents e41ce0d + 29ad057 commit 1cc659e
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 33 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,21 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Check Python version for pre-commit
# Only run pre-commit / mypy on upstream supported Python versions
run: |
if [[ "${{ matrix.python-version }}" =~ ^3\.([89]|[0-9][0-9])$ ]]; then
echo USE_PRE_COMMIT=1 >> $GITHUB_ENV
fi
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install dwarves libelf-dev libdw-dev qemu-kvm zstd ${{ matrix.cc == 'clang' && 'libomp-$(clang --version | sed -rn "s/.*clang version ([0-9]+).*/\\1/p")-dev' || '' }}
pip install pyroute2 pre-commit
pip install pyroute2 ${USE_PRE_COMMIT/1/pre-commit}
- name: Generate version.py
run: python setup.py --version
- name: Check with mypy
if: ${{ env.USE_PRE_COMMIT == '1' }}
run: pre-commit run --all-files mypy
- name: Build and test with ${{ matrix.cc }}
run: CONFIGURE_FLAGS="--enable-compiler-warnings=error" python setup.py test -K
Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ instructions <README.rst#from-source>`_, then run:
$ CONFIGURE_FLAGS="--enable-compiler-warnings=error" python3 setup.py build_ext -i
$ python3 -m drgn --help
Drgn can build, run, and pass its test suite on Python 3.6 or later. However,
many of the tools used as part of the development workflow do not support Python
versions once they have reached their end-of-life. Thus, your main drgn
development environment should use a Python version which is actively supported
upstream. In particular, the drgn development workflow no longer supported on
Python 3.6.

Testing
-------

Expand Down Expand Up @@ -67,6 +74,9 @@ Or you can run them manually:
$ pre-commit run --all-files
Please remember that these pre-commit hooks do not support Python 3.6; they
require a Python major version which is actively supported upstream.

Coding Guidelines
-----------------

Expand Down
2 changes: 1 addition & 1 deletion docs/support_matrix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ currently fully supported are:

.. Keep this in sync with vmtest/config.py.
- 6.0-6.6
- 6.0-6.7
- 5.10-5.19
- 5.4
- 4.19
Expand Down
4 changes: 2 additions & 2 deletions drgn/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def _main() -> None:
try:
script_type = _identify_script(args.script[0])
except OSError as e:
sys.exit(e)
sys.exit(str(e))
if script_type == "core":
sys.exit(
f"error: {args.script[0]} is a core dump\n"
Expand Down Expand Up @@ -280,7 +280,7 @@ def _main() -> None:
else:
prog.set_core_dump(open_via_sudo("/proc/kcore", os.O_RDONLY))
except OSError as e:
sys.exit(e)
sys.exit(str(e))
except ValueError as e:
# E.g., "not an ELF core file"
sys.exit(f"error: {e}")
Expand Down
2 changes: 1 addition & 1 deletion drgn/helpers/common/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def number_in_binary_units(n: SupportsFloat, precision: int = 1) -> str:
for prefix in ("", "K", "M", "G", "T", "P", "E", "Z"):
if abs(n) < 1024:
break
n /= 1024
n /= 1024.0
else:
prefix = "Y"
if n.is_integer():
Expand Down
12 changes: 8 additions & 4 deletions drgn/helpers/linux/mm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,9 +1320,9 @@ def access_remote_vm(mm: Object, address: IntegerLike, size: IntegerLike) -> byt
return _linux_helper_read_vm(mm.prog_, mm.pgd, address, size)


def cmdline(task: Object) -> List[bytes]:
def cmdline(task: Object) -> Optional[List[bytes]]:
"""
Get the list of command line arguments of a task.
Get the list of command line arguments of a task, or ``None`` for kernel tasks.
>>> cmdline(find_task(prog, 1495216))
[b'vim', b'drgn/helpers/linux/mm.py']
Expand All @@ -1335,14 +1335,16 @@ def cmdline(task: Object) -> List[bytes]:
:param task: ``struct task_struct *``
"""
mm = task.mm.read_()
if not mm:
return None
arg_start = mm.arg_start.value_()
arg_end = mm.arg_end.value_()
return access_remote_vm(mm, arg_start, arg_end - arg_start).split(b"\0")[:-1]


def environ(task: Object) -> List[bytes]:
def environ(task: Object) -> Optional[List[bytes]]:
"""
Get the list of environment variables of a task.
Get the list of environment variables of a task, or ``None`` for kernel tasks.
>>> environ(find_task(prog, 1497797))
[b'HOME=/root', b'PATH=/usr/local/sbin:/usr/local/bin:/usr/bin', b'LOGNAME=root']
Expand All @@ -1357,6 +1359,8 @@ def environ(task: Object) -> List[bytes]:
:param task: ``struct task_struct *``
"""
mm = task.mm.read_()
if not mm:
return None
env_start = mm.env_start.value_()
env_end = mm.env_end.value_()
return access_remote_vm(mm, env_start, env_end - env_start).split(b"\0")[:-1]
Expand Down
10 changes: 3 additions & 7 deletions drgn/helpers/linux/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ def for_each_net(prog: Program) -> Iterator[Object]:
:return: Iterator of ``struct net *`` objects.
"""
for net in list_for_each_entry(
return list_for_each_entry(
"struct net", prog["net_namespace_list"].address_of_(), "list"
):
yield net
)


_CLONE_NEWNET = 0x40000000
Expand Down Expand Up @@ -237,10 +236,7 @@ def sk_nulls_for_each(head: Object) -> Iterator[Object]:
:param head: ``struct hlist_nulls_head *``
:return: Iterator of ``struct sock *`` objects.
"""
for sk in hlist_nulls_for_each_entry(
"struct sock", head, "__sk_common.skc_nulls_node"
):
yield sk
return hlist_nulls_for_each_entry("struct sock", head, "__sk_common.skc_nulls_node")


def skb_shinfo(skb: Object) -> Object:
Expand Down
3 changes: 1 addition & 2 deletions drgn/helpers/linux/nodemask.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def for_each_node_state(prog: Program, state: IntegerLike) -> Iterator[int]:
:param state: ``enum node_states`` (e.g., ``N_NORMAL_MEMORY``)
"""
mask = prog["node_states"][state]
return for_each_node_mask(mask)
return for_each_node_mask(prog["node_states"][state])


def for_each_node(prog: Program) -> Iterator[int]:
Expand Down
5 changes: 2 additions & 3 deletions drgn/helpers/linux/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def for_each_user(prog: Program) -> Iterator[Object]:
:return: Iterator of ``struct user_struct *`` objects.
"""
for hash_entry in prog["uidhash_table"]:
for user in hlist_for_each_entry(
yield from hlist_for_each_entry(
"struct user_struct", hash_entry, "uidhash_node"
):
yield user
)
5 changes: 5 additions & 0 deletions libdrgn/kdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ struct drgn_error *drgn_program_set_kdump(struct drgn_program *prog)
}

ks = kdump_set_number_attr(ctx, KDUMP_ATTR_FILE_FD, prog->core_fd);
if (ks == KDUMP_ERR_NOTIMPL) {
err = drgn_error_format(DRGN_ERROR_INVALID_ARGUMENT,
"%s", kdump_get_err(ctx));
goto err;
}
if (ks != KDUMP_OK) {
err = drgn_error_format(DRGN_ERROR_OTHER,
"kdump_set_number_attr(KDUMP_ATTR_FILE_FD): %s",
Expand Down
26 changes: 14 additions & 12 deletions libdrgn/program.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "helpers.h"
#include "io.h"
#include "language.h"
#include "log.h"
#include "linux_kernel.h"
#include "memory_reader.h"
#include "minmax.h"
Expand Down Expand Up @@ -215,23 +216,24 @@ drgn_program_check_initialized(struct drgn_program *prog)
return NULL;
}

static struct drgn_error *has_kdump_signature(const char *path, int fd,
bool *ret)
static struct drgn_error *
has_kdump_signature(struct drgn_program *prog, const char *path, bool *ret)
{
char signature[max_iconst(KDUMP_SIG_LEN, FLATTENED_SIG_LEN)];
ssize_t r = pread_all(fd, signature, sizeof(signature), 0);
ssize_t r = pread_all(prog->core_fd, signature, sizeof(signature), 0);
if (r < 0)
return drgn_error_create_os("pread", errno, path);
*ret = false;
if (r >= FLATTENED_SIG_LEN
&& memcmp(signature, FLATTENED_SIGNATURE, FLATTENED_SIG_LEN) == 0) {
return drgn_error_create(DRGN_ERROR_INVALID_ARGUMENT,
"the given file is in the makedumpfile flattened "
"format, which drgn does not support; use "
"'makedumpfile -R newfile <oldfile' to reassemble "
"the file into a format drgn can read");
}
*ret = (r >= KDUMP_SIG_LEN
&& memcmp(signature, KDUMP_SIGNATURE, KDUMP_SIG_LEN) == 0);
drgn_log_warning(prog,
"the given file is in the makedumpfile flattened "
"format; if open fails or is too slow, reassemble "
"it with 'makedumpfile -R newfile <oldfile'");
*ret = true;
} else if (r >= KDUMP_SIG_LEN
&& memcmp(signature, KDUMP_SIGNATURE, KDUMP_SIG_LEN) == 0)
*ret = true;
return NULL;
}

Expand All @@ -252,7 +254,7 @@ drgn_program_set_core_dump_fd_internal(struct drgn_program *prog, int fd,
bool have_nt_taskstruct = false, is_proc_kcore;

prog->core_fd = fd;
err = has_kdump_signature(path, prog->core_fd, &is_kdump);
err = has_kdump_signature(prog, path, &is_kdump);
if (err)
goto out_fd;
if (is_kdump) {
Expand Down
6 changes: 6 additions & 0 deletions tests/linux_kernel/helpers/test_mm.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,19 @@ def test_cmdline(self):
task = find_task(self.prog, os.getpid())
self.assertEqual(cmdline(task), proc_cmdline)

def test_cmdline_kernel_thread(self):
self.assertIsNone(cmdline(find_task(self.prog, 2)))

@skip_unless_have_full_mm_support
def test_environ(self):
with open("/proc/self/environ", "rb") as f:
proc_environ = f.read().split(b"\0")[:-1]
task = find_task(self.prog, os.getpid())
self.assertEqual(environ(task), proc_environ)

def test_environ_kernel_thread(self):
self.assertIsNone(environ(find_task(self.prog, 2)))

def test_for_each_vma(self):
with fork_and_sigwait() as pid:
self.assertEqual(
Expand Down
1 change: 1 addition & 0 deletions vmtest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# Kernel versions that we run tests on and therefore support. Keep this in sync
# with docs/support_matrix.rst.
SUPPORTED_KERNEL_VERSIONS = (
"6.7",
"6.6",
"6.5",
"6.4",
Expand Down

0 comments on commit 1cc659e

Please sign in to comment.