Skip to content

Instantly share code, notes, and snippets.

View stepper.py
from __future__ import print_function
import lldb
def doit(dbg, cmd):
print('::', cmd)
dbg.HandleCommand(cmd)
def should_stop_stepping(process):
state = process.GetState()
@vedantk
vedantk / gist:2d0cc1df9bea9f0fa74ee101d240b82c
Created Nov 8, 2019
Steps involved in clang installing the llvm SIGPIPE handler after signal(SIGPIPE, SIG_IGN) in lldb
View gist:2d0cc1df9bea9f0fa74ee101d240b82c
=== Really doing llvm handler registration ===
0 lldb 0x0000000107b0fe98 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 lldb 0x0000000107b0f858 RegisterHandlers() + 328
2 lldb 0x0000000107b04d3e llvm::EnablePrettyStackTrace() + 46
3 lldb 0x0000000107b04103 llvm::InitLLVM::InitLLVM(int&, char const**&) + 147
4 lldb 0x0000000107aeaa9f main + 47
5 libdyld.dylib 0x00007fff722ba3d5 start + 1
6 libdyld.dylib 0x000000000000000e start + 18446603338600700986
=== (in lldb) Should have installed llvm handlers ^ ===
=== (in lldb) Blocking SIGPIPE ===
@vedantk
vedantk / opt-check-dbg-invar.sh
Created Jun 21, 2018
Script to check whether an opt invocation is debug info invariant
View opt-check-dbg-invar.sh
#!/bin/bash
OPT=$1
shift 1
TEST_FILE=$1
shift 1
strip_cmd() {
$OPT -disable-verify -strip -strip-dead-prototypes -strip-named-metadata -o - $*
View oflow.cc
// Test driver for https://reviews.llvm.org/D41149
#include <cstdint>
#include <limits>
#include <iostream>
#include <vector>
// Instructions:
// - Compile this program with a baseline compiler and a patched compiler.
// - Check that the output of the two executables is the same.
@vedantk
vedantk / foil_optimizer.cpp
Created Mar 8, 2016 — forked from socantre/foil_optimizer.cpp
CppCon 2015: Chandler Carruth "Tuning C++: Benchmarks, and CPUs, and Compilers! Oh My!" functions to disable compiler optimization
View foil_optimizer.cpp
static void escape(void *p) {
asm volatile("" : : "g"(p) : "memory");
}
static void clobber() {
asm volatile("" : : : "memory");
}
@vedantk
vedantk / tagged_ptr.rs
Created Sep 7, 2015
A safe version of tagged pointers in rust
View tagged_ptr.rs
use std::mem;
use std::ops::{Deref, DerefMut};
#[derive(Copy, Clone, Debug)]
struct Tagged<'a, T: 'a> {
pointer: &'a T
}
impl<'a, T> Tagged<'a, T> {
fn tag(&'a mut self) -> &'a mut Tagged<'a, T> {
@vedantk
vedantk / avl.py
Created Jul 21, 2013
AVL tree in python, no deletions
View avl.py
#!/usr/local/bin/python3
class AVLTree:
def __init__(self, data):
self.data = data
self.lhs = None
self.rhs = None
def insert(self, data):
if data == self.data:
@vedantk
vedantk / accum.sh
Created Jun 2, 2013
Frequency count: hard mode.
View accum.sh
#!/bin/zsh
# Find each struct's usage frequency in each subsystem. In each search, discard
# the files that have no matches, get rid of the directory prefix, only keep
# the subsystem, and then pipe the information out to a temporary file. Loop
# through every (Subsystem Of File, Count) tuple and sum up the contribution
# from each subsystem to that struct's frequency.
for line in $(cat structs.txt); do
echo ">"$line
@vedantk
vedantk / PushupCounter.c
Created Apr 25, 2013
A pushup counter using sonar and the arduino uno
View PushupCounter.c
#define trigPin 13
#define echoPin 12
#define delayMilis 100
/* 0: Noisy state.
* 1: You went below the low threshold.
* 2: You went above the low threshold.
* 3: You went above the high threshold.
* 4: You went below the high threshold, pushup done.
*/
@vedantk
vedantk / gray.cc
Created Mar 20, 2013
Gray codes in c++
View gray.cc
#include <vector>
#include <string>
#include <iostream>
using namespace std;
void gray(int n, vector<string>& code) {
if (n == 1) {
code.push_back(string("0"));
code.push_back(string("1"));