Skip to content

Instantly share code, notes, and snippets.

@jigpu
jigpu / debugging_tips.md
Last active December 10, 2020 22:00
Debugging Tips For A Dummy (Like Me...)

General Tips & Tricks

Using coredumpctl

Most Linux systems use systemd for their init system, and systemd includes a component that automatically saves coredumps for crashed processes. The coredumpctl command can be used to discover crashing processes, obtain backtraces, export coredumps, or launch GDB. Combined with debug symbols it is easy to get information about a crash from users who may not be especially technical.

  1. Replicate the crash

  2. Run coredumpctl list --since "5 minutes ago" to see all crashes logged in the last 5 minutes

  3. Run coredumpctl info to get a basic backtrace of a particular crashed PID or EXE

@jigpu
jigpu / wacom_probe_unprobe_loop.sh
Created September 13, 2017 21:54
Repeatedly loads and unloads the 'wacom' kernel module to find transient bugs
#!/bin/bash
rsleep () { sleep $(awk -vM=$1 -vN=4 'BEGIN{"od -N"N" -tu"N" -A none /dev/urandom"|getline;print M*$0/(2^(8*N)-1)}'); }
WAIT=2
while :; do
rsleep $WAIT
echo -n .
rmmod wacom
echo -n v
@jigpu
jigpu / evemu-live.awk
Last active October 5, 2017 20:59
AWK script to format evemu-record output for live display
# NOTE: When run in an environment which uses 'mawk' (e.g. Ubuntu), it is
# recommended to set the environment variable WHINY_USERS to ensur the
# output is sorted: `sudo evemu-record | WHINY_USERS=1 awk -f evemu-live.awk`
BEGIN {
SUBSEP="\t";
PROCINFO["sorted_in"]="@ind_str_asc";
"tput clear" | getline Clear;
"tput cup 0 0" | getline Home;
@jigpu
jigpu / multimeter.sh
Created November 5, 2017 06:05
Start sampling from a Unit-T UT61E Multimeter over ttyS0
#!/bin/sh
# Start sampling data from a Uni-T UT61E connected over the serial port
# See https://sigrok.org/gitweb/?p=libsigrok.git;a=blob;f=README.devices
#
# For a USB connection, the "-ser" suffix should be removed from the driver
# and the "conn" updated to use the VID:PID of the cable being used (note
# that it isn't simply a serial-to-USB cable)
sigrok-cli --driver=uni-t-ut61e-ser:conn=/dev/ttyS0 --continuous
@jigpu
jigpu / hexundump.sh
Created November 6, 2017 23:19
Convert a space-separated list of hex bytes to a binary
python3 -c 'open(1,"wb").write(bytearray.fromhex(" ".join(open(0).read().split())))'
@jigpu
jigpu / ddc-ftdi.py
Last active June 27, 2022 06:04
Control brightness and contrast of a monitor exposing DDC over an FTDI F232H.
#!/usr/bin/python3
"""Control brightness and contrast of a monitor exposing DDC over an FTDI F232H.
Usage:
ddc-ftdi.py [<brightness> <contrast>]
Arguments:
<brightness> Brightness value to set (0..100)
<contrast> Contrast value to set (0..100)
@jigpu
jigpu / spin.sh
Created January 28, 2018 17:38
Simple script to spin the terminal cursor in various ways.
#!/bin/sh
# Note:
# https://en.wikipedia.org/wiki/ANSI_escape_code
# https://www.fileformat.info/info/unicode/block/block_elements/list.htm
function spin {
CHRS=$1
DELAY=$2
X=0;
@jigpu
jigpu / testbox_session_snap.sh
Created May 22, 2018 15:52
Automatic snapshotting and restoring of test machines
#!/usr/bin/env bash
# Script to handle automatic snapshotting and restoring of test machines.
# This script should be run early in the startup process to see if the
# user wants to continue/create a session or to delete an existing
# session and start over fresh.
set -e
[ $EUID == 0 ] || exec sudo "$0" "$@"
@jigpu
jigpu / sig.patch
Last active November 29, 2018 22:43
diff --git a/4.5/Makefile.in b/4.5/Makefile.in
index 438229b..dd89344 100644
--- a/4.5/Makefile.in
+++ b/4.5/Makefile.in
@@ -22,6 +22,9 @@ DRACUT := $(shell command -v dracut 2>/dev/null)
WCM_KERNEL_DIR := @WCM_KERNEL_DIR@
MODUTS := @MODUTS@
WCM_KERNEL_VER := @WCM_KERNEL_VER@
+MODSIGN_HASHALGO := @MODSIGN_HASHALGO@
+MODSIGN_PRIVFILE := @MODSIGN_PRIVFILE@
@jigpu
jigpu / remap-cintiq.sh
Last active February 12, 2019 17:39
Remap all Cintiq (or other display tablet) devices to the correct monitor
#!/bin/bash
#
# Map all display tablets to the correct monitor.
#
# This script tries to atuomatically determine the correct monitor to
# map every connected tablet to. It uses the tablet size to find a
# best match among the available Wacom-branded monitors. If no match
# is found, then we assume that either the monitor isn't connected or
# the tablet doesn't have a display.