#!/bin/sh
#
#
# Debugger interface for radare
#
# author: pancake
#

A=$1
[ -z "$A" ] && A="-h"
if [ "$A" = "-h" ]; then
	echo "Usage: rsc radaredbg [-h] [file] argv"
	exit 1
fi
if [ -z "`radare -L | grep ptrace`" ]; then
	echo "radare was compiled without ptrace support\n"
	exit 1
fi

PRG=$A
if [ -n "`echo $PRG| grep '^./'`" ]; then
	PRG="$PWD/$PRG"
fi

shift
while [ -n "$1" ] ; do
	PRG="$PRG $1"
	shift
done

if [ "0x0" = "`xc $A`" ]; then
	echo "$ radare -wu \"dbg://$PRG\""
	eval "radare -wu \"dbg://$PRG\""
else
	echo "Ataching to pid $1..."
	eval "radare -wu pid://$1"
fi
