Skip to content

Instantly share code, notes, and snippets.

$ drgn
...
>>> for cpu in for_each_present_cpu():
... task = per_cpu(prog["runqueues"], cpu).idle
... print(task.comm, task.pid)
...
(char [16])"swapper/0" (pid_t)0
(char [16])"swapper/1" (pid_t)0
(char [16])"swapper/2" (pid_t)0
(char [16])"swapper/3" (pid_t)0
#define _GNU_SOURCE
#include <fcntl.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
static const int NUM_KEEP = 5;
"""
Prototype implementation of x86-64 page table walking in drgn. Doesn't handle
huge pages or 5-level page tables. Probably wrong in other ways.
"""
from drgn import cast, reinterpret
from drgn.helpers.linux.mm import page_to_virt, pfn_to_page
def pgd_val(pgd):
#!/usr/bin/env python3
import bcc
import collections
import ctypes
import functools
import sys
bpf_text = r"""
#include <uapi/linux/ptrace.h>
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
.section .data
potato:
.byte 65, 66, 10
.section .text
.globl _start
_start:
movq $1, %rbx
movq $potato, %rcx