Skip to content

Instantly share code, notes, and snippets.

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 November 8, 2019 00:19
Steps involved in clang installing the llvm SIGPIPE handler after signal(SIGPIPE, SIG_IGN) in lldb
=== 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 June 21, 2018 19:19
Script to check whether an opt invocation is debug info invariant
#!/bin/bash
OPT=$1
shift 1
TEST_FILE=$1
shift 1
strip_cmd() {
$OPT -disable-verify -strip -strip-dead-prototypes -strip-named-metadata -o - $*
// 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 March 8, 2016 23:32 — forked from socantre/foil_optimizer.cpp
CppCon 2015: Chandler Carruth "Tuning C++: Benchmarks, and CPUs, and Compilers! Oh My!" functions to disable compiler optimization
static void escape(void *p) {
asm volatile("" : : "g"(p) : "memory");
}
static void clobber() {
asm volatile("" : : : "memory");
}
@vedantk
vedantk / tagged_ptr.rs
Created September 7, 2015 22:58
A safe version of tagged pointers in rust
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 July 21, 2013 03:51
AVL tree in python, no deletions
#!/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 June 2, 2013 18:47
Frequency count: hard mode.
#!/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 April 25, 2013 10:37
A pushup counter using sonar and the arduino uno
#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 March 20, 2013 08:14
Gray codes in c++
#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"));