Skip to content

Instantly share code, notes, and snippets.

nikhilm /
Last active Feb 15, 2019
Retrieving function arguments while unwinding the stack

When a debugger, profiler or crash reporter is unwinding the call stack, can it reliably retrieve the function arguments of every function in the stack?

I originally intended for this to be a later part of the [Sampling Profilers]({{< ref "/post/2018/sampling-profiler-internals-introduction" >}}) series, but a recent discussion with Ben Frederickson, and his [subsequent py-spy implementation][] helped crystallize my thoughts and I figured I'd write it down separately.

nikhilm / opencloseunlinksnoop
Created Aug 4, 2017
opencloseunlinksnoop - modified from opensnoop on OSX to also track unlink() and close()
View opencloseunlinksnoop
# #!/usr/bin/sh
# opensnoop - snoop file opens as they occur.
# Written using DTrace (Solaris 10 3/05).
# 12-Jan-2006, ver 1.60
# USAGE: opensnoop [-a|-A|-ceghstvxZ] [-f pathname] [-n name] [-p PID]
View output
2016/11/12 00:29:20 Pinged successfully
&{d4d32563d909d603a6b1d604d6902b942c922e10d838ca5683ca48f4f5c23234 [treeder/hello:latest] 94f30c9c34c2234448f1f8abf62b256fdbde30542b526fa2ee9cdba3ecba28b5 2016-10-06 00:00:00.264 +0000 UTC {4c573a7cf4a3 0 0 0 0 0 [] map[] [PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin] [/bin/sh -c #(nop) ENTRYPOINT ["sh" ""]] <nil> [] sha256:a52e7dd7e1b87c43a90db766ebe79563a38cff39a0d14ccfdad0069e741d612e map[] /app [sh] [] [] [] map[] false false false false false false false false } 1.9.0 0xc420348000 amd64 0 0 [] <nil>} <nil>
pull <nil>
Create <nil> API error (500): (InternalError) Internal error (0f9925f0-a86f-11e6-a25b-37d5ab1798cf)
View mgo#254 test case.go
// This is a reduced test case for
// What it does is to overload DialServer() and return a custom net.Conn.
// Some of these custom connections timeout _once_ after the first 1000 bytes are read.
// It seems like DialServer() is called more times than the PoolLimit, which is
// set to 5, and not all these sockets are used, so for convenience, we pick
// every third connection to automatically time out once.
// It is still possible for this test to be slightly flaky, you may have to run it more than once.
// Remember to edit the Dial URL and the database name in insert to something valid.
nikhilm / index.js
Last active Apr 7, 2016 Lambda support example.
View index.js
var im = require('imagemagick');
var fs = require('fs');
var postProcessResource = function(resource, fn) {
var ret = null;
if (resource) {
if (fn) {
ret = fn(resource);
View index.html
// Does not handle fetch event.
nikhilm / tryjsil.cs
Created Apr 11, 2013 — forked from TryJSIL/tryjsil.cs
Simple Unsafe Structs
View tryjsil.cs
using System;
using System.Runtime.InteropServices;
public static class Program {
public static unsafe void Main (string[] args) {
var bytes = new byte[8];
fixed (byte* pBytes = bytes) {
var pStruct = (MyStruct*)pBytes;
*pStruct = new MyStruct {
nikhilm / js
Created Nov 13, 2012
fire event
View js
XHRSampleListener::FireOnResultEvent(const nsAString &response)
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");
nsresult rv;
nsCOMPtr<nsIDOMEvent> event;
rv = NS_NewDOMEvent(getter_AddRefs(event), nullptr, nullptr);
nikhilm /
Created Aug 24, 2012
Paraphrased from "Why nerds are unpopular" by Paul Graham -

I'm suspicious of this theory that thirteen-year-old kids are intrinsically messed up. If it's physiological, it should be universal. Are Mongol nomads all nihilists at thirteen? I've read a lot of history, and I have not seen a single reference to this supposedly universal fact before the twentieth century. Teenage apprentices in the Renaissance seem to have been cheerful and eager. They got in fights and played tricks on one another of course (Michelangelo had his nose broken by a bully), but they weren't crazy.

As far as I can tell, the concept of the hormone-crazed teenager is coeval with suburbia. I don't think this is a coincidence. I think teenagers are driven crazy by the life they're made to lead. Teenage apprentices in the Renaissance were working dogs. Teenagers now are neurotic lapdogs. Their craziness is the craziness of the idle everywhere.

When I was in school, suicide was a constant topic among the smarter kids. No one I knew did it, but several planned to, and some may have tried. Mostly

nikhilm / jscrush-compress-pseudo.js
Created Apr 15, 2012
JSCrush 'reverse engineering'
View jscrush-compress-pseudo.js
segmentLengthBound = ... // B, originally set to s.length/2
counter = {} // o
bestSavings = 0 // M
maxRepetitions = 0 // N
bestSegment = 0 // e
longestSegmentLength = 0 // Z
segmentLength = 0 // t
while (segmentLength <= segmentLengthBound) {
start = 1;
You can’t perform that action at this time.