OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / tools / misc / asm2gdb
1 #!/bin/sh
2 # Convert an asm source file to gdb commands.
3 # Useful for loading small programs in gdbinit scripts.
4
5 case "$#" in
6 2)      ;;
7 3)      ARCH=$1-
8         shift
9         ;;
10 *)      echo "Usage: $0 [arch] file address" >&2
11         exit 1
12         ;;
13 esac
14
15 INPUT=$1
16 ADDR=$2
17
18 ${ARCH}gcc -nostartfiles -nostdlib -Wl,-Ttext=$ADDR -o /tmp/asm2gdb.elf $INPUT || exit 1
19 ${ARCH}objcopy -O binary /tmp/asm2gdb.elf /tmp/asm2gdb.bin || exit 1
20 od -Ad -tx4 -w4 -v /tmp/asm2gdb.bin | awk "{ if (NF == 2) printf \"set *((unsigned long *) 0x%08x\1) = 0x%s\\n\", $ADDR + \$1, \$2 }"
21 echo "set \$pc = $ADDR"
22