mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 07:13:54 -06:00
Add scripts directory
Move build and user scripts into scripts directory. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
This commit is contained in:
parent
8e5977e5f5
commit
4c3b5a4891
16 changed files with 23 additions and 23 deletions
103
scripts/create_config
Executable file
103
scripts/create_config
Executable file
|
@ -0,0 +1,103 @@
|
|||
#!/bin/sh
|
||||
|
||||
echo "/* Automatically generated by create_config - do not modify */"
|
||||
|
||||
while read line; do
|
||||
|
||||
case $line in
|
||||
VERSION=*) # configuration
|
||||
version=${line#*=}
|
||||
echo "#define QEMU_VERSION \"$version\""
|
||||
;;
|
||||
PKGVERSION=*) # configuration
|
||||
pkgversion=${line#*=}
|
||||
echo "#define QEMU_PKGVERSION \"$pkgversion\""
|
||||
;;
|
||||
prefix=* | [a-z]*dir=*) # directory configuration
|
||||
name=${line%=*}
|
||||
value=${line#*=}
|
||||
define_name=`echo $name | tr '[:lower:]' '[:upper:]'`
|
||||
eval "define_value=\"$value\""
|
||||
echo "#define CONFIG_QEMU_$define_name \"$define_value\""
|
||||
# save for the next definitions
|
||||
eval "$name=\$define_value"
|
||||
;;
|
||||
CONFIG_AUDIO_DRIVERS=*)
|
||||
drivers=${line#*=}
|
||||
echo "#define CONFIG_AUDIO_DRIVERS \\"
|
||||
for drv in $drivers; do
|
||||
echo " &${drv}_audio_driver,\\"
|
||||
done
|
||||
echo ""
|
||||
;;
|
||||
CONFIG_BDRV_WHITELIST=*)
|
||||
echo "#define CONFIG_BDRV_WHITELIST \\"
|
||||
for drv in ${line#*=}; do
|
||||
echo " \"${drv}\",\\"
|
||||
done
|
||||
echo " NULL"
|
||||
;;
|
||||
CONFIG_*=y) # configuration
|
||||
name=${line%=*}
|
||||
echo "#define $name 1"
|
||||
;;
|
||||
CONFIG_*=*) # configuration
|
||||
name=${line%=*}
|
||||
value=${line#*=}
|
||||
echo "#define $name $value"
|
||||
;;
|
||||
ARCH=*) # configuration
|
||||
arch=${line#*=}
|
||||
arch_name=`echo $arch | tr '[:lower:]' '[:upper:]'`
|
||||
echo "#define HOST_$arch_name 1"
|
||||
;;
|
||||
HOST_USB=*)
|
||||
# do nothing
|
||||
;;
|
||||
HOST_CC=*)
|
||||
# do nothing
|
||||
;;
|
||||
HOST_*=y) # configuration
|
||||
name=${line%=*}
|
||||
echo "#define $name 1"
|
||||
;;
|
||||
HOST_*=*) # configuration
|
||||
name=${line%=*}
|
||||
value=${line#*=}
|
||||
echo "#define $name $value"
|
||||
;;
|
||||
TARGET_ARCH=*) # configuration
|
||||
target_arch=${line#*=}
|
||||
echo "#define TARGET_ARCH \"$target_arch\""
|
||||
;;
|
||||
TARGET_BASE_ARCH=*) # configuration
|
||||
target_base_arch=${line#*=}
|
||||
if [ "$target_base_arch" != "$target_arch" ]; then
|
||||
base_arch_name=`echo $target_base_arch | tr '[:lower:]' '[:upper:]'`
|
||||
echo "#define TARGET_$base_arch_name 1"
|
||||
fi
|
||||
;;
|
||||
TARGET_XML_FILES=*)
|
||||
# do nothing
|
||||
;;
|
||||
TARGET_ABI_DIR=*)
|
||||
# do nothing
|
||||
;;
|
||||
TARGET_ARCH2=*)
|
||||
# do nothing
|
||||
;;
|
||||
TARGET_DIRS=*)
|
||||
# do nothing
|
||||
;;
|
||||
TARGET_*=y) # configuration
|
||||
name=${line%=*}
|
||||
echo "#define $name 1"
|
||||
;;
|
||||
TARGET_*=*) # configuration
|
||||
name=${line%=*}
|
||||
value=${line#*=}
|
||||
echo "#define $name $value"
|
||||
;;
|
||||
esac
|
||||
|
||||
done # read
|
75
scripts/feature_to_c.sh
Normal file
75
scripts/feature_to_c.sh
Normal file
|
@ -0,0 +1,75 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Convert text files to compilable C arrays.
|
||||
#
|
||||
# Copyright (C) 2007 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is part of GDB.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
output=$1
|
||||
shift
|
||||
|
||||
if test -z "$output" || test -z "$1"; then
|
||||
echo "Usage: $0 OUTPUTFILE INPUTFILE..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if test -e "$output"; then
|
||||
echo "Output file \"$output\" already exists; refusing to overwrite."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for input; do
|
||||
arrayname=xml_feature_`echo $input | sed 's,.*/,,; s/[-.]/_/g'`
|
||||
|
||||
${AWK:-awk} 'BEGIN { n = 0
|
||||
print "static const char '$arrayname'[] = {"
|
||||
for (i = 0; i < 255; i++)
|
||||
_ord_[sprintf("%c", i)] = i
|
||||
} {
|
||||
split($0, line, "");
|
||||
printf " "
|
||||
for (i = 1; i <= length($0); i++) {
|
||||
c = line[i]
|
||||
if (c == "'\''") {
|
||||
printf "'\''\\'\'''\'', "
|
||||
} else if (c == "\\") {
|
||||
printf "'\''\\\\'\'', "
|
||||
} else if (_ord_[c] >= 32 && _ord_[c] < 127) {
|
||||
printf "'\''%s'\'', ", c
|
||||
} else {
|
||||
printf "'\''\\%03o'\'', ", _ord_[c]
|
||||
}
|
||||
if (i % 10 == 0)
|
||||
printf "\n "
|
||||
}
|
||||
printf "'\''\\n'\'', \n"
|
||||
} END {
|
||||
print " 0 };"
|
||||
}' < $input >> $output
|
||||
done
|
||||
|
||||
echo >> $output
|
||||
echo "const char *const xml_builtin[][2] = {" >> $output
|
||||
|
||||
for input; do
|
||||
basename=`echo $input | sed 's,.*/,,'`
|
||||
arrayname=xml_feature_`echo $input | sed 's,.*/,,; s/[-.]/_/g'`
|
||||
echo " { \"$basename\", $arrayname }," >> $output
|
||||
done
|
||||
|
||||
echo " { (char *)0, (char *)0 }" >> $output
|
||||
echo "};" >> $output
|
102
scripts/hxtool
Normal file
102
scripts/hxtool
Normal file
|
@ -0,0 +1,102 @@
|
|||
#!/bin/sh
|
||||
|
||||
hxtoh()
|
||||
{
|
||||
flag=1
|
||||
while read -r str; do
|
||||
case $str in
|
||||
HXCOMM*)
|
||||
;;
|
||||
STEXI*|ETEXI*|SQMP*|EQMP*) flag=$(($flag^1))
|
||||
;;
|
||||
*)
|
||||
test $flag -eq 1 && printf "%s\n" "$str"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
hxtotexi()
|
||||
{
|
||||
flag=0
|
||||
line=1
|
||||
while read -r str; do
|
||||
case "$str" in
|
||||
HXCOMM*)
|
||||
;;
|
||||
STEXI*)
|
||||
if test $flag -eq 1 ; then
|
||||
echo "line $line: syntax error: expected ETEXI, found $str" >&2
|
||||
exit 1
|
||||
fi
|
||||
flag=1
|
||||
;;
|
||||
ETEXI*)
|
||||
if test $flag -ne 1 ; then
|
||||
echo "line $line: syntax error: expected STEXI, found $str" >&2
|
||||
exit 1
|
||||
fi
|
||||
flag=0
|
||||
;;
|
||||
SQMP*|EQMP*)
|
||||
if test $flag -eq 1 ; then
|
||||
echo "line $line: syntax error: expected ETEXI, found $str" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
DEFHEADING*)
|
||||
echo "$(expr "$str" : "DEFHEADING(\(.*\))")"
|
||||
;;
|
||||
*)
|
||||
test $flag -eq 1 && echo "$str"
|
||||
;;
|
||||
esac
|
||||
line=$((line+1))
|
||||
done
|
||||
}
|
||||
|
||||
hxtoqmp()
|
||||
{
|
||||
IFS=
|
||||
flag=0
|
||||
line=1
|
||||
while read -r str; do
|
||||
case "$str" in
|
||||
HXCOMM*)
|
||||
;;
|
||||
SQMP*)
|
||||
if test $flag -eq 1 ; then
|
||||
echo "line $line: syntax error: expected EQMP, found $str" >&2
|
||||
exit 1
|
||||
fi
|
||||
flag=1
|
||||
;;
|
||||
EQMP*)
|
||||
if test $flag -ne 1 ; then
|
||||
echo "line $line: syntax error: expected SQMP, found $str" >&2
|
||||
exit 1
|
||||
fi
|
||||
flag=0
|
||||
;;
|
||||
STEXI*|ETEXI*)
|
||||
if test $flag -eq 1 ; then
|
||||
echo "line $line: syntax error: expected EQMP, found $str" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
test $flag -eq 1 && echo "$str"
|
||||
;;
|
||||
esac
|
||||
line=$((line+1))
|
||||
done
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
"-h") hxtoh ;;
|
||||
"-t") hxtotexi ;;
|
||||
"-q") hxtoqmp ;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
|
||||
exit 0
|
28
scripts/make_device_config.sh
Normal file
28
scripts/make_device_config.sh
Normal file
|
@ -0,0 +1,28 @@
|
|||
#! /bin/sh
|
||||
# Construct a target device config file from a default, pulling in any
|
||||
# files from include directives.
|
||||
|
||||
dest=$1.tmp
|
||||
dep=$1.d
|
||||
src=$2
|
||||
src_dir=`dirname $src`
|
||||
all_includes=
|
||||
|
||||
process_includes () {
|
||||
cat $1 | grep '^include' | \
|
||||
while read include file ; do
|
||||
all_includes="$all_includes $src_dir/$file"
|
||||
process_includes $src_dir/$file
|
||||
done
|
||||
}
|
||||
|
||||
f=$src
|
||||
while [ -n "$f" ] ; do
|
||||
f=`tr -d '\r' < $f | awk '/^include / {printf "'$src_dir'/%s", $2}'`
|
||||
[ $? = 0 ] || exit 1
|
||||
all_includes="$all_includes $f"
|
||||
done
|
||||
process_includes $src > $dest
|
||||
|
||||
cat $src $all_includes | grep -v '^include' > $dest
|
||||
echo "$1: $all_includes" > $dep
|
66
scripts/qemu-binfmt-conf.sh
Normal file
66
scripts/qemu-binfmt-conf.sh
Normal file
|
@ -0,0 +1,66 @@
|
|||
#!/bin/sh
|
||||
# enable automatic i386/ARM/M68K/MIPS/SPARC/PPC program execution by the kernel
|
||||
|
||||
# load the binfmt_misc module
|
||||
if [ ! -d /proc/sys/fs/binfmt_misc ]; then
|
||||
/sbin/modprobe binfmt_misc
|
||||
fi
|
||||
if [ ! -f /proc/sys/fs/binfmt_misc/register ]; then
|
||||
mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
|
||||
fi
|
||||
|
||||
# probe cpu type
|
||||
cpu=`uname -m`
|
||||
case "$cpu" in
|
||||
i386|i486|i586|i686|i86pc|BePC|x86_64)
|
||||
cpu="i386"
|
||||
;;
|
||||
m68k)
|
||||
cpu="m68k"
|
||||
;;
|
||||
mips*)
|
||||
cpu="mips"
|
||||
;;
|
||||
"Power Macintosh"|ppc|ppc64)
|
||||
cpu="ppc"
|
||||
;;
|
||||
armv[4-9]*)
|
||||
cpu="arm"
|
||||
;;
|
||||
esac
|
||||
|
||||
# register the interpreter for each cpu except for the native one
|
||||
if [ $cpu != "i386" ] ; then
|
||||
echo ':i386:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-i386:' > /proc/sys/fs/binfmt_misc/register
|
||||
echo ':i486:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-i386:' > /proc/sys/fs/binfmt_misc/register
|
||||
fi
|
||||
if [ $cpu != "alpha" ] ; then
|
||||
echo ':alpha:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-alpha:' > /proc/sys/fs/binfmt_misc/register
|
||||
fi
|
||||
if [ $cpu != "arm" ] ; then
|
||||
echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-arm:' > /proc/sys/fs/binfmt_misc/register
|
||||
echo ':armeb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-armeb:' > /proc/sys/fs/binfmt_misc/register
|
||||
fi
|
||||
if [ $cpu != "sparc" ] ; then
|
||||
echo ':sparc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-sparc:' > /proc/sys/fs/binfmt_misc/register
|
||||
fi
|
||||
if [ $cpu != "ppc" ] ; then
|
||||
echo ':ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-ppc:' > /proc/sys/fs/binfmt_misc/register
|
||||
fi
|
||||
if [ $cpu != "m68k" ] ; then
|
||||
echo 'Please check cpu value and header information for m68k!'
|
||||
echo ':m68k:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-m68k:' > /proc/sys/fs/binfmt_misc/register
|
||||
fi
|
||||
if [ $cpu != "mips" ] ; then
|
||||
# FIXME: We could use the other endianness on a MIPS host.
|
||||
echo ':mips:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips:' > /proc/sys/fs/binfmt_misc/register
|
||||
echo ':mipsel:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mipsel:' > /proc/sys/fs/binfmt_misc/register
|
||||
echo ':mipsn32:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mipsn32:' > /proc/sys/fs/binfmt_misc/register
|
||||
echo ':mipsn32el:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mipsn32el:' > /proc/sys/fs/binfmt_misc/register
|
||||
echo ':mips64:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips64:' > /proc/sys/fs/binfmt_misc/register
|
||||
echo ':mips64el:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mips64el:' > /proc/sys/fs/binfmt_misc/register
|
||||
fi
|
||||
if [ $cpu != "sh" ] ; then
|
||||
echo ':sh4:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-sh4:' > /proc/sys/fs/binfmt_misc/register
|
||||
echo ':sh4eb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-sh4eb:' > /proc/sys/fs/binfmt_misc/register
|
||||
fi
|
45
scripts/signrom.sh
Executable file
45
scripts/signrom.sh
Executable file
|
@ -0,0 +1,45 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Option ROM Signing utility
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Copyright Novell Inc, 2009
|
||||
# Authors: Alexander Graf <agraf@suse.de>
|
||||
#
|
||||
# Syntax: signrom.sh <input> <output>
|
||||
|
||||
# did we get proper arguments?
|
||||
test "$1" -a "$2" || exit 1
|
||||
|
||||
sum=0
|
||||
|
||||
# find out the file size
|
||||
x=`dd if="$1" bs=1 count=1 skip=2 2>/dev/null | od -t u1 -A n`
|
||||
#size=`expr $x \* 512 - 1`
|
||||
size=$(( $x * 512 - 1 ))
|
||||
|
||||
# now get the checksum
|
||||
nums=`od -A n -t u1 -v -N $size "$1"`
|
||||
for i in ${nums}; do
|
||||
# add each byte's value to sum
|
||||
sum=`expr \( $sum + $i \) % 256`
|
||||
done
|
||||
|
||||
sum=$(( (256 - $sum) % 256 ))
|
||||
sum_octal=$( printf "%o" $sum )
|
||||
|
||||
# and write the output file
|
||||
cp "$1" "$2"
|
||||
printf "\\$sum_octal" | dd of="$2" bs=1 count=1 seek=$size conv=notrunc 2>/dev/null
|
93
scripts/simpletrace.py
Executable file
93
scripts/simpletrace.py
Executable file
|
@ -0,0 +1,93 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Pretty-printer for simple trace backend binary trace files
|
||||
#
|
||||
# Copyright IBM, Corp. 2010
|
||||
#
|
||||
# This work is licensed under the terms of the GNU GPL, version 2. See
|
||||
# the COPYING file in the top-level directory.
|
||||
#
|
||||
# For help see docs/tracing.txt
|
||||
|
||||
import sys
|
||||
import struct
|
||||
import re
|
||||
|
||||
header_event_id = 0xffffffffffffffff
|
||||
header_magic = 0xf2b177cb0aa429b4
|
||||
header_version = 0
|
||||
|
||||
trace_fmt = '=QQQQQQQQ'
|
||||
trace_len = struct.calcsize(trace_fmt)
|
||||
event_re = re.compile(r'(disable\s+)?([a-zA-Z0-9_]+)\(([^)]*)\).*')
|
||||
|
||||
def err(msg):
|
||||
sys.stderr.write(msg + '\n')
|
||||
sys.exit(1)
|
||||
|
||||
def parse_events(fobj):
|
||||
"""Parse a trace-events file."""
|
||||
|
||||
def get_argnames(args):
|
||||
"""Extract argument names from a parameter list."""
|
||||
return tuple(arg.split()[-1].lstrip('*') for arg in args.split(','))
|
||||
|
||||
events = {}
|
||||
event_num = 0
|
||||
for line in fobj:
|
||||
m = event_re.match(line.strip())
|
||||
if m is None:
|
||||
continue
|
||||
|
||||
disable, name, args = m.groups()
|
||||
events[event_num] = (name,) + get_argnames(args)
|
||||
event_num += 1
|
||||
return events
|
||||
|
||||
def read_record(fobj):
|
||||
"""Deserialize a trace record from a file."""
|
||||
s = fobj.read(trace_len)
|
||||
if len(s) != trace_len:
|
||||
return None
|
||||
return struct.unpack(trace_fmt, s)
|
||||
|
||||
def read_trace_file(fobj):
|
||||
"""Deserialize trace records from a file."""
|
||||
header = read_record(fobj)
|
||||
if header is None or \
|
||||
header[0] != header_event_id or \
|
||||
header[1] != header_magic or \
|
||||
header[2] != header_version:
|
||||
err('not a trace file or incompatible version')
|
||||
|
||||
while True:
|
||||
rec = read_record(fobj)
|
||||
if rec is None:
|
||||
break
|
||||
|
||||
yield rec
|
||||
|
||||
class Formatter(object):
|
||||
def __init__(self, events):
|
||||
self.events = events
|
||||
self.last_timestamp = None
|
||||
|
||||
def format_record(self, rec):
|
||||
if self.last_timestamp is None:
|
||||
self.last_timestamp = rec[1]
|
||||
delta_ns = rec[1] - self.last_timestamp
|
||||
self.last_timestamp = rec[1]
|
||||
|
||||
event = self.events[rec[0]]
|
||||
fields = [event[0], '%0.3f' % (delta_ns / 1000.0)]
|
||||
for i in xrange(1, len(event)):
|
||||
fields.append('%s=0x%x' % (event[i], rec[i + 1]))
|
||||
return ' '.join(fields)
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
err('usage: %s <trace-events> <trace-file>' % sys.argv[0])
|
||||
|
||||
events = parse_events(open(sys.argv[1], 'r'))
|
||||
formatter = Formatter(events)
|
||||
for rec in read_trace_file(open(sys.argv[2], 'rb')):
|
||||
print formatter.format_record(rec)
|
477
scripts/texi2pod.pl
Executable file
477
scripts/texi2pod.pl
Executable file
|
@ -0,0 +1,477 @@
|
|||
#! /usr/bin/perl -w
|
||||
|
||||
# Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
|
||||
|
||||
# This file is part of GCC.
|
||||
|
||||
# GCC is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
|
||||
# GCC is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with GCC; see the file COPYING. If not,
|
||||
# see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# This does trivial (and I mean _trivial_) conversion of Texinfo
|
||||
# markup to Perl POD format. It's intended to be used to extract
|
||||
# something suitable for a manpage from a Texinfo document.
|
||||
|
||||
$output = 0;
|
||||
$skipping = 0;
|
||||
%sects = ();
|
||||
$section = "";
|
||||
@icstack = ();
|
||||
@endwstack = ();
|
||||
@skstack = ();
|
||||
@instack = ();
|
||||
$shift = "";
|
||||
%defs = ();
|
||||
$fnno = 1;
|
||||
$inf = "";
|
||||
$ibase = "";
|
||||
@ipath = ();
|
||||
|
||||
while ($_ = shift) {
|
||||
if (/^-D(.*)$/) {
|
||||
if ($1 ne "") {
|
||||
$flag = $1;
|
||||
} else {
|
||||
$flag = shift;
|
||||
}
|
||||
$value = "";
|
||||
($flag, $value) = ($flag =~ /^([^=]+)(?:=(.+))?/);
|
||||
die "no flag specified for -D\n"
|
||||
unless $flag ne "";
|
||||
die "flags may only contain letters, digits, hyphens, dashes and underscores\n"
|
||||
unless $flag =~ /^[a-zA-Z0-9_-]+$/;
|
||||
$defs{$flag} = $value;
|
||||
} elsif (/^-I(.*)$/) {
|
||||
if ($1 ne "") {
|
||||
$flag = $1;
|
||||
} else {
|
||||
$flag = shift;
|
||||
}
|
||||
push (@ipath, $flag);
|
||||
} elsif (/^-/) {
|
||||
usage();
|
||||
} else {
|
||||
$in = $_, next unless defined $in;
|
||||
$out = $_, next unless defined $out;
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (defined $in) {
|
||||
$inf = gensym();
|
||||
open($inf, "<$in") or die "opening \"$in\": $!\n";
|
||||
$ibase = $1 if $in =~ m|^(.+)/[^/]+$|;
|
||||
} else {
|
||||
$inf = \*STDIN;
|
||||
}
|
||||
|
||||
if (defined $out) {
|
||||
open(STDOUT, ">$out") or die "opening \"$out\": $!\n";
|
||||
}
|
||||
|
||||
while(defined $inf) {
|
||||
while(<$inf>) {
|
||||
# Certain commands are discarded without further processing.
|
||||
/^\@(?:
|
||||
[a-z]+index # @*index: useful only in complete manual
|
||||
|need # @need: useful only in printed manual
|
||||
|(?:end\s+)?group # @group .. @end group: ditto
|
||||
|page # @page: ditto
|
||||
|node # @node: useful only in .info file
|
||||
|(?:end\s+)?ifnottex # @ifnottex .. @end ifnottex: use contents
|
||||
)\b/x and next;
|
||||
|
||||
chomp;
|
||||
|
||||
# Look for filename and title markers.
|
||||
/^\@setfilename\s+([^.]+)/ and $fn = $1, next;
|
||||
/^\@settitle\s+([^.]+)/ and $tl = postprocess($1), next;
|
||||
|
||||
# Identify a man title but keep only the one we are interested in.
|
||||
/^\@c\s+man\s+title\s+([A-Za-z0-9-]+)\s+(.+)/ and do {
|
||||
if (exists $defs{$1}) {
|
||||
$fn = $1;
|
||||
$tl = postprocess($2);
|
||||
}
|
||||
next;
|
||||
};
|
||||
|
||||
# Look for blocks surrounded by @c man begin SECTION ... @c man end.
|
||||
# This really oughta be @ifman ... @end ifman and the like, but such
|
||||
# would require rev'ing all other Texinfo translators.
|
||||
/^\@c\s+man\s+begin\s+([A-Z]+)\s+([A-Za-z0-9-]+)/ and do {
|
||||
$output = 1 if exists $defs{$2};
|
||||
$sect = $1;
|
||||
next;
|
||||
};
|
||||
/^\@c\s+man\s+begin\s+([A-Z]+)/ and $sect = $1, $output = 1, next;
|
||||
/^\@c\s+man\s+end/ and do {
|
||||
$sects{$sect} = "" unless exists $sects{$sect};
|
||||
$sects{$sect} .= postprocess($section);
|
||||
$section = "";
|
||||
$output = 0;
|
||||
next;
|
||||
};
|
||||
|
||||
# handle variables
|
||||
/^\@set\s+([a-zA-Z0-9_-]+)\s*(.*)$/ and do {
|
||||
$defs{$1} = $2;
|
||||
next;
|
||||
};
|
||||
/^\@clear\s+([a-zA-Z0-9_-]+)/ and do {
|
||||
delete $defs{$1};
|
||||
next;
|
||||
};
|
||||
|
||||
next unless $output;
|
||||
|
||||
# Discard comments. (Can't do it above, because then we'd never see
|
||||
# @c man lines.)
|
||||
/^\@c\b/ and next;
|
||||
|
||||
# End-block handler goes up here because it needs to operate even
|
||||
# if we are skipping.
|
||||
/^\@end\s+([a-z]+)/ and do {
|
||||
# Ignore @end foo, where foo is not an operation which may
|
||||
# cause us to skip, if we are presently skipping.
|
||||
my $ended = $1;
|
||||
next if $skipping && $ended !~ /^(?:ifset|ifclear|ignore|menu|iftex|copying)$/;
|
||||
|
||||
die "\@end $ended without \@$ended at line $.\n" unless defined $endw;
|
||||
die "\@$endw ended by \@end $ended at line $.\n" unless $ended eq $endw;
|
||||
|
||||
$endw = pop @endwstack;
|
||||
|
||||
if ($ended =~ /^(?:ifset|ifclear|ignore|menu|iftex)$/) {
|
||||
$skipping = pop @skstack;
|
||||
next;
|
||||
} elsif ($ended =~ /^(?:example|smallexample|display)$/) {
|
||||
$shift = "";
|
||||
$_ = ""; # need a paragraph break
|
||||
} elsif ($ended =~ /^(?:itemize|enumerate|[fv]?table)$/) {
|
||||
$_ = "\n=back\n";
|
||||
$ic = pop @icstack;
|
||||
} elsif ($ended eq "multitable") {
|
||||
$_ = "\n=back\n";
|
||||
} else {
|
||||
die "unknown command \@end $ended at line $.\n";
|
||||
}
|
||||
};
|
||||
|
||||
# We must handle commands which can cause skipping even while we
|
||||
# are skipping, otherwise we will not process nested conditionals
|
||||
# correctly.
|
||||
/^\@ifset\s+([a-zA-Z0-9_-]+)/ and do {
|
||||
push @endwstack, $endw;
|
||||
push @skstack, $skipping;
|
||||
$endw = "ifset";
|
||||
$skipping = 1 unless exists $defs{$1};
|
||||
next;
|
||||
};
|
||||
|
||||
/^\@ifclear\s+([a-zA-Z0-9_-]+)/ and do {
|
||||
push @endwstack, $endw;
|
||||
push @skstack, $skipping;
|
||||
$endw = "ifclear";
|
||||
$skipping = 1 if exists $defs{$1};
|
||||
next;
|
||||
};
|
||||
|
||||
/^\@(ignore|menu|iftex|copying)\b/ and do {
|
||||
push @endwstack, $endw;
|
||||
push @skstack, $skipping;
|
||||
$endw = $1;
|
||||
$skipping = 1;
|
||||
next;
|
||||
};
|
||||
|
||||
next if $skipping;
|
||||
|
||||
# Character entities. First the ones that can be replaced by raw text
|
||||
# or discarded outright:
|
||||
s/\@copyright\{\}/(c)/g;
|
||||
s/\@dots\{\}/.../g;
|
||||
s/\@enddots\{\}/..../g;
|
||||
s/\@([.!? ])/$1/g;
|
||||
s/\@[:-]//g;
|
||||
s/\@bullet(?:\{\})?/*/g;
|
||||
s/\@TeX\{\}/TeX/g;
|
||||
s/\@pounds\{\}/\#/g;
|
||||
s/\@minus(?:\{\})?/-/g;
|
||||
s/\\,/,/g;
|
||||
|
||||
# Now the ones that have to be replaced by special escapes
|
||||
# (which will be turned back into text by unmunge())
|
||||
s/&/&/g;
|
||||
s/\@\{/{/g;
|
||||
s/\@\}/}/g;
|
||||
s/\@\@/&at;/g;
|
||||
|
||||
# Inside a verbatim block, handle @var specially.
|
||||
if ($shift ne "") {
|
||||
s/\@var\{([^\}]*)\}/<$1>/g;
|
||||
}
|
||||
|
||||
# POD doesn't interpret E<> inside a verbatim block.
|
||||
if ($shift eq "") {
|
||||
s/</</g;
|
||||
s/>/>/g;
|
||||
} else {
|
||||
s/</</g;
|
||||
s/>/>/g;
|
||||
}
|
||||
|
||||
# Single line command handlers.
|
||||
|
||||
/^\@include\s+(.+)$/ and do {
|
||||
push @instack, $inf;
|
||||
$inf = gensym();
|
||||
$file = postprocess($1);
|
||||
|
||||
# Try cwd and $ibase, then explicit -I paths.
|
||||
$done = 0;
|
||||
foreach $path ("", $ibase, @ipath) {
|
||||
$mypath = $file;
|
||||
$mypath = $path . "/" . $mypath if ($path ne "");
|
||||
open($inf, "<" . $mypath) and ($done = 1, last);
|
||||
}
|
||||
die "cannot find $file" if !$done;
|
||||
next;
|
||||
};
|
||||
|
||||
/^\@(?:section|unnumbered|unnumberedsec|center)\s+(.+)$/
|
||||
and $_ = "\n=head2 $1\n";
|
||||
/^\@subsection\s+(.+)$/
|
||||
and $_ = "\n=head3 $1\n";
|
||||
/^\@subsubsection\s+(.+)$/
|
||||
and $_ = "\n=head4 $1\n";
|
||||
|
||||
# Block command handlers:
|
||||
/^\@itemize(?:\s+(\@[a-z]+|\*|-))?/ and do {
|
||||
push @endwstack, $endw;
|
||||
push @icstack, $ic;
|
||||
if (defined $1) {
|
||||
$ic = $1;
|
||||
} else {
|
||||
$ic = '*';
|
||||
}
|
||||
$_ = "\n=over 4\n";
|
||||
$endw = "itemize";
|
||||
};
|
||||
|
||||
/^\@enumerate(?:\s+([a-zA-Z0-9]+))?/ and do {
|
||||
push @endwstack, $endw;
|
||||
push @icstack, $ic;
|
||||
if (defined $1) {
|
||||
$ic = $1 . ".";
|
||||
} else {
|
||||
$ic = "1.";
|
||||
}
|
||||
$_ = "\n=over 4\n";
|
||||
$endw = "enumerate";
|
||||
};
|
||||
|
||||
/^\@multitable\s.*/ and do {
|
||||
push @endwstack, $endw;
|
||||
$endw = "multitable";
|
||||
$_ = "\n=over 4\n";
|
||||
};
|
||||
|
||||
/^\@([fv]?table)\s+(\@[a-z]+)/ and do {
|
||||
push @endwstack, $endw;
|
||||
push @icstack, $ic;
|
||||
$endw = $1;
|
||||
$ic = $2;
|
||||
$ic =~ s/\@(?:samp|strong|key|gcctabopt|option|env)/B/;
|
||||
$ic =~ s/\@(?:code|kbd)/C/;
|
||||
$ic =~ s/\@(?:dfn|var|emph|cite|i)/I/;
|
||||
$ic =~ s/\@(?:file)/F/;
|
||||
$_ = "\n=over 4\n";
|
||||
};
|
||||
|
||||
/^\@((?:small)?example|display)/ and do {
|
||||
push @endwstack, $endw;
|
||||
$endw = $1;
|
||||
$shift = "\t";
|
||||
$_ = ""; # need a paragraph break
|
||||
};
|
||||
|
||||
/^\@item\s+(.*\S)\s*$/ and $endw eq "multitable" and do {
|
||||
@columns = ();
|
||||
for $column (split (/\s*\@tab\s*/, $1)) {
|
||||
# @strong{...} is used a @headitem work-alike
|
||||
$column =~ s/^\@strong{(.*)}$/$1/;
|
||||
push @columns, $column;
|
||||
}
|
||||
$_ = "\n=item ".join (" : ", @columns)."\n";
|
||||
};
|
||||
|
||||
/^\@itemx?\s*(.+)?$/ and do {
|
||||
if (defined $1) {
|
||||
# Entity escapes prevent munging by the <> processing below.
|
||||
$_ = "\n=item $ic\<$1\>\n";
|
||||
} else {
|
||||
$_ = "\n=item $ic\n";
|
||||
$ic =~ y/A-Ya-y/B-Zb-z/;
|
||||
$ic =~ s/(\d+)/$1 + 1/eg;
|
||||
}
|
||||
};
|
||||
|
||||
$section .= $shift.$_."\n";
|
||||
}
|
||||
# End of current file.
|
||||
close($inf);
|
||||
$inf = pop @instack;
|
||||
}
|
||||
|
||||
die "No filename or title\n" unless defined $fn && defined $tl;
|
||||
|
||||
$sects{NAME} = "$fn \- $tl\n";
|
||||
$sects{FOOTNOTES} .= "=back\n" if exists $sects{FOOTNOTES};
|
||||
|
||||
for $sect (qw(NAME SYNOPSIS DESCRIPTION OPTIONS ENVIRONMENT FILES
|
||||
BUGS NOTES FOOTNOTES SEEALSO AUTHOR COPYRIGHT)) {
|
||||
if(exists $sects{$sect}) {
|
||||
$head = $sect;
|
||||
$head =~ s/SEEALSO/SEE ALSO/;
|
||||
print "=head1 $head\n\n";
|
||||
print scalar unmunge ($sects{$sect});
|
||||
print "\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub usage
|
||||
{
|
||||
die "usage: $0 [-D toggle...] [infile [outfile]]\n";
|
||||
}
|
||||
|
||||
sub postprocess
|
||||
{
|
||||
local $_ = $_[0];
|
||||
|
||||
# @value{foo} is replaced by whatever 'foo' is defined as.
|
||||
while (m/(\@value\{([a-zA-Z0-9_-]+)\})/g) {
|
||||
if (! exists $defs{$2}) {
|
||||
print STDERR "Option $2 not defined\n";
|
||||
s/\Q$1\E//;
|
||||
} else {
|
||||
$value = $defs{$2};
|
||||
s/\Q$1\E/$value/;
|
||||
}
|
||||
}
|
||||
|
||||
# Formatting commands.
|
||||
# Temporary escape for @r.
|
||||
s/\@r\{([^\}]*)\}/R<$1>/g;
|
||||
s/\@(?:dfn|var|emph|cite|i)\{([^\}]*)\}/I<$1>/g;
|
||||
s/\@(?:code|kbd)\{([^\}]*)\}/C<$1>/g;
|
||||
s/\@(?:gccoptlist|samp|strong|key|option|env|command|b)\{([^\}]*)\}/B<$1>/g;
|
||||
s/\@sc\{([^\}]*)\}/\U$1/g;
|
||||
s/\@file\{([^\}]*)\}/F<$1>/g;
|
||||
s/\@w\{([^\}]*)\}/S<$1>/g;
|
||||
s/\@(?:dmn|math)\{([^\}]*)\}/$1/g;
|
||||
|
||||
# keep references of the form @ref{...}, print them bold
|
||||
s/\@(?:ref)\{([^\}]*)\}/B<$1>/g;
|
||||
|
||||
# Change double single quotes to double quotes.
|
||||
s/''/"/g;
|
||||
s/``/"/g;
|
||||
|
||||
# Cross references are thrown away, as are @noindent and @refill.
|
||||
# (@noindent is impossible in .pod, and @refill is unnecessary.)
|
||||
# @* is also impossible in .pod; we discard it and any newline that
|
||||
# follows it. Similarly, our macro @gol must be discarded.
|
||||
|
||||
s/\(?\@xref\{(?:[^\}]*)\}(?:[^.<]|(?:<[^<>]*>))*\.\)?//g;
|
||||
s/\s+\(\@pxref\{(?:[^\}]*)\}\)//g;
|
||||
s/;\s+\@pxref\{(?:[^\}]*)\}//g;
|
||||
s/\@noindent\s*//g;
|
||||
s/\@refill//g;
|
||||
s/\@gol//g;
|
||||
s/\@\*\s*\n?//g;
|
||||
|
||||
# Anchors are thrown away
|
||||
s/\@anchor\{(?:[^\}]*)\}//g;
|
||||
|
||||
# @uref can take one, two, or three arguments, with different
|
||||
# semantics each time. @url and @email are just like @uref with
|
||||
# one argument, for our purposes.
|
||||
s/\@(?:uref|url|email)\{([^\},]*)\}/<B<$1>>/g;
|
||||
s/\@uref\{([^\},]*),([^\},]*)\}/$2 (C<$1>)/g;
|
||||
s/\@uref\{([^\},]*),([^\},]*),([^\},]*)\}/$3/g;
|
||||
|
||||
# Un-escape <> at this point.
|
||||
s/</</g;
|
||||
s/>/>/g;
|
||||
|
||||
# Now un-nest all B<>, I<>, R<>. Theoretically we could have
|
||||
# indefinitely deep nesting; in practice, one level suffices.
|
||||
1 while s/([BIR])<([^<>]*)([BIR])<([^<>]*)>/$1<$2>$3<$4>$1</g;
|
||||
|
||||
# Replace R<...> with bare ...; eliminate empty markup, B<>;
|
||||
# shift white space at the ends of [BI]<...> expressions outside
|
||||
# the expression.
|
||||
s/R<([^<>]*)>/$1/g;
|
||||
s/[BI]<>//g;
|
||||
s/([BI])<(\s+)([^>]+)>/$2$1<$3>/g;
|
||||
s/([BI])<([^>]+?)(\s+)>/$1<$2>$3/g;
|
||||
|
||||
# Extract footnotes. This has to be done after all other
|
||||
# processing because otherwise the regexp will choke on formatting
|
||||
# inside @footnote.
|
||||
while (/\@footnote/g) {
|
||||
s/\@footnote\{([^\}]+)\}/[$fnno]/;
|
||||
add_footnote($1, $fnno);
|
||||
$fnno++;
|
||||
}
|
||||
|
||||
return $_;
|
||||
}
|
||||
|
||||
sub unmunge
|
||||
{
|
||||
# Replace escaped symbols with their equivalents.
|
||||
local $_ = $_[0];
|
||||
|
||||
s/</E<lt>/g;
|
||||
s/>/E<gt>/g;
|
||||
s/{/\{/g;
|
||||
s/}/\}/g;
|
||||
s/&at;/\@/g;
|
||||
s/&/&/g;
|
||||
return $_;
|
||||
}
|
||||
|
||||
sub add_footnote
|
||||
{
|
||||
unless (exists $sects{FOOTNOTES}) {
|
||||
$sects{FOOTNOTES} = "\n=over 4\n\n";
|
||||
}
|
||||
|
||||
$sects{FOOTNOTES} .= "=item $fnno.\n\n"; $fnno++;
|
||||
$sects{FOOTNOTES} .= $_[0];
|
||||
$sects{FOOTNOTES} .= "\n\n";
|
||||
}
|
||||
|
||||
# stolen from Symbol.pm
|
||||
{
|
||||
my $genseq = 0;
|
||||
sub gensym
|
||||
{
|
||||
my $name = "GEN" . $genseq++;
|
||||
my $ref = \*{$name};
|
||||
delete $::{$name};
|
||||
return $ref;
|
||||
}
|
||||
}
|
573
scripts/tracetool
Executable file
573
scripts/tracetool
Executable file
|
@ -0,0 +1,573 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Code generator for trace events
|
||||
#
|
||||
# Copyright IBM, Corp. 2010
|
||||
#
|
||||
# This work is licensed under the terms of the GNU GPL, version 2. See
|
||||
# the COPYING file in the top-level directory.
|
||||
|
||||
# Disable pathname expansion, makes processing text with '*' characters simpler
|
||||
set -f
|
||||
|
||||
usage()
|
||||
{
|
||||
cat >&2 <<EOF
|
||||
usage: $0 [--nop | --simple | --ust] [-h | -c]
|
||||
Generate tracing code for a file on stdin.
|
||||
|
||||
Backends:
|
||||
--nop Tracing disabled
|
||||
--simple Simple built-in backend
|
||||
--ust LTTng User Space Tracing backend
|
||||
--dtrace DTrace/SystemTAP backend
|
||||
|
||||
Output formats:
|
||||
-h Generate .h file
|
||||
-c Generate .c file
|
||||
-d Generate .d file (DTrace only)
|
||||
--stap Generate .stp file (DTrace with SystemTAP only)
|
||||
|
||||
Options:
|
||||
--binary [path] Full path to QEMU binary
|
||||
--target-arch [arch] QEMU emulator target arch
|
||||
--target-type [type] QEMU emulator target type ('system' or 'user')
|
||||
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Get the name of a trace event
|
||||
get_name()
|
||||
{
|
||||
echo ${1%%\(*}
|
||||
}
|
||||
|
||||
# Get the argument list of a trace event, including types and names
|
||||
get_args()
|
||||
{
|
||||
local args
|
||||
args=${1#*\(}
|
||||
args=${args%\)*}
|
||||
echo "$args"
|
||||
}
|
||||
|
||||
# Get the argument name list of a trace event
|
||||
get_argnames()
|
||||
{
|
||||
local nfields field name sep
|
||||
nfields=0
|
||||
sep="$2"
|
||||
for field in $(get_args "$1"); do
|
||||
nfields=$((nfields + 1))
|
||||
|
||||
# Drop pointer star
|
||||
field=${field#\*}
|
||||
|
||||
# Only argument names have commas at the end
|
||||
name=${field%,}
|
||||
test "$field" = "$name" && continue
|
||||
|
||||
printf "%s%s " $name $sep
|
||||
done
|
||||
|
||||
# Last argument name
|
||||
if [ "$nfields" -gt 1 ]
|
||||
then
|
||||
printf "%s" "$name"
|
||||
fi
|
||||
}
|
||||
|
||||
# Get the number of arguments to a trace event
|
||||
get_argc()
|
||||
{
|
||||
local name argc
|
||||
argc=0
|
||||
for name in $(get_argnames "$1", ","); do
|
||||
argc=$((argc + 1))
|
||||
done
|
||||
echo $argc
|
||||
}
|
||||
|
||||
# Get the format string for a trace event
|
||||
get_fmt()
|
||||
{
|
||||
local fmt
|
||||
fmt=${1#*\"}
|
||||
fmt=${fmt%\"*}
|
||||
echo "$fmt"
|
||||
}
|
||||
|
||||
# Get the state of a trace event
|
||||
get_state()
|
||||
{
|
||||
local str disable state
|
||||
str=$(get_name "$1")
|
||||
disable=${str##disable }
|
||||
if [ "$disable" = "$str" ] ; then
|
||||
state=1
|
||||
else
|
||||
state=0
|
||||
fi
|
||||
echo "$state"
|
||||
}
|
||||
|
||||
linetoh_begin_nop()
|
||||
{
|
||||
return
|
||||
}
|
||||
|
||||
linetoh_nop()
|
||||
{
|
||||
local name args
|
||||
name=$(get_name "$1")
|
||||
args=$(get_args "$1")
|
||||
|
||||
# Define an empty function for the trace event
|
||||
cat <<EOF
|
||||
static inline void trace_$name($args)
|
||||
{
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
linetoh_end_nop()
|
||||
{
|
||||
return
|
||||
}
|
||||
|
||||
linetoc_begin_nop()
|
||||
{
|
||||
return
|
||||
}
|
||||
|
||||
linetoc_nop()
|
||||
{
|
||||
# No need for function definitions in nop backend
|
||||
return
|
||||
}
|
||||
|
||||
linetoc_end_nop()
|
||||
{
|
||||
return
|
||||
}
|
||||
|
||||
linetoh_begin_simple()
|
||||
{
|
||||
cat <<EOF
|
||||
#include "simpletrace.h"
|
||||
EOF
|
||||
|
||||
simple_event_num=0
|
||||
}
|
||||
|
||||
cast_args_to_uint64_t()
|
||||
{
|
||||
local arg
|
||||
for arg in $(get_argnames "$1", ","); do
|
||||
printf "%s" "(uint64_t)(uintptr_t)$arg"
|
||||
done
|
||||
}
|
||||
|
||||
linetoh_simple()
|
||||
{
|
||||
local name args argc trace_args state
|
||||
name=$(get_name "$1")
|
||||
args=$(get_args "$1")
|
||||
argc=$(get_argc "$1")
|
||||
state=$(get_state "$1")
|
||||
if [ "$state" = "0" ]; then
|
||||
name=${name##disable }
|
||||
fi
|
||||
|
||||
trace_args="$simple_event_num"
|
||||
if [ "$argc" -gt 0 ]
|
||||
then
|
||||
trace_args="$trace_args, $(cast_args_to_uint64_t "$1")"
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
static inline void trace_$name($args)
|
||||
{
|
||||
trace$argc($trace_args);
|
||||
}
|
||||
EOF
|
||||
|
||||
simple_event_num=$((simple_event_num + 1))
|
||||
}
|
||||
|
||||
linetoh_end_simple()
|
||||
{
|
||||
cat <<EOF
|
||||
#define NR_TRACE_EVENTS $simple_event_num
|
||||
extern TraceEvent trace_list[NR_TRACE_EVENTS];
|
||||
EOF
|
||||
}
|
||||
|
||||
linetoc_begin_simple()
|
||||
{
|
||||
cat <<EOF
|
||||
#include "trace.h"
|
||||
|
||||
TraceEvent trace_list[] = {
|
||||
EOF
|
||||
simple_event_num=0
|
||||
|
||||
}
|
||||
|
||||
linetoc_simple()
|
||||
{
|
||||
local name state
|
||||
name=$(get_name "$1")
|
||||
state=$(get_state "$1")
|
||||
if [ "$state" = "0" ] ; then
|
||||
name=${name##disable }
|
||||
fi
|
||||
cat <<EOF
|
||||
{.tp_name = "$name", .state=$state},
|
||||
EOF
|
||||
simple_event_num=$((simple_event_num + 1))
|
||||
}
|
||||
|
||||
linetoc_end_simple()
|
||||
{
|
||||
cat <<EOF
|
||||
};
|
||||
EOF
|
||||
}
|
||||
|
||||
# Clean up after UST headers which pollute the namespace
|
||||
ust_clean_namespace() {
|
||||
cat <<EOF
|
||||
#undef mutex_lock
|
||||
#undef mutex_unlock
|
||||
#undef inline
|
||||
#undef wmb
|
||||
EOF
|
||||
}
|
||||
|
||||
linetoh_begin_ust()
|
||||
{
|
||||
echo "#include <ust/tracepoint.h>"
|
||||
ust_clean_namespace
|
||||
}
|
||||
|
||||
linetoh_ust()
|
||||
{
|
||||
local name args argnames
|
||||
name=$(get_name "$1")
|
||||
args=$(get_args "$1")
|
||||
argnames=$(get_argnames "$1", ",")
|
||||
|
||||
cat <<EOF
|
||||
DECLARE_TRACE(ust_$name, TP_PROTO($args), TP_ARGS($argnames));
|
||||
#define trace_$name trace_ust_$name
|
||||
EOF
|
||||
}
|
||||
|
||||
linetoh_end_ust()
|
||||
{
|
||||
return
|
||||
}
|
||||
|
||||
linetoc_begin_ust()
|
||||
{
|
||||
cat <<EOF
|
||||
#include <ust/marker.h>
|
||||
$(ust_clean_namespace)
|
||||
#include "trace.h"
|
||||
EOF
|
||||
}
|
||||
|
||||
linetoc_ust()
|
||||
{
|
||||
local name args argnames fmt
|
||||
name=$(get_name "$1")
|
||||
args=$(get_args "$1")
|
||||
argnames=$(get_argnames "$1", ",")
|
||||
fmt=$(get_fmt "$1")
|
||||
|
||||
cat <<EOF
|
||||
DEFINE_TRACE(ust_$name);
|
||||
|
||||
static void ust_${name}_probe($args)
|
||||
{
|
||||
trace_mark(ust, $name, "$fmt", $argnames);
|
||||
}
|
||||
EOF
|
||||
|
||||
# Collect names for later
|
||||
names="$names $name"
|
||||
}
|
||||
|
||||
linetoc_end_ust()
|
||||
{
|
||||
cat <<EOF
|
||||
static void __attribute__((constructor)) trace_init(void)
|
||||
{
|
||||
EOF
|
||||
|
||||
for name in $names; do
|
||||
cat <<EOF
|
||||
register_trace_ust_$name(ust_${name}_probe);
|
||||
EOF
|
||||
done
|
||||
|
||||
echo "}"
|
||||
}
|
||||
|
||||
linetoh_begin_dtrace()
|
||||
{
|
||||
cat <<EOF
|
||||
#include "trace-dtrace.h"
|
||||
EOF
|
||||
}
|
||||
|
||||
linetoh_dtrace()
|
||||
{
|
||||
local name args argnames state nameupper
|
||||
name=$(get_name "$1")
|
||||
args=$(get_args "$1")
|
||||
argnames=$(get_argnames "$1", ",")
|
||||
state=$(get_state "$1")
|
||||
if [ "$state" = "0" ] ; then
|
||||
name=${name##disable }
|
||||
fi
|
||||
|
||||
nameupper=`echo $name | tr '[:lower:]' '[:upper:]'`
|
||||
|
||||
# Define an empty function for the trace event
|
||||
cat <<EOF
|
||||
static inline void trace_$name($args) {
|
||||
if (QEMU_${nameupper}_ENABLED()) {
|
||||
QEMU_${nameupper}($argnames);
|
||||
}
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
linetoh_end_dtrace()
|
||||
{
|
||||
return
|
||||
}
|
||||
|
||||
linetoc_begin_dtrace()
|
||||
{
|
||||
return
|
||||
}
|
||||
|
||||
linetoc_dtrace()
|
||||
{
|
||||
# No need for function definitions in dtrace backend
|
||||
return
|
||||
}
|
||||
|
||||
linetoc_end_dtrace()
|
||||
{
|
||||
return
|
||||
}
|
||||
|
||||
linetod_begin_dtrace()
|
||||
{
|
||||
cat <<EOF
|
||||
provider qemu {
|
||||
EOF
|
||||
}
|
||||
|
||||
linetod_dtrace()
|
||||
{
|
||||
local name args state
|
||||
name=$(get_name "$1")
|
||||
args=$(get_args "$1")
|
||||
state=$(get_state "$1")
|
||||
if [ "$state" = "0" ] ; then
|
||||
name=${name##disable }
|
||||
fi
|
||||
|
||||
# DTrace provider syntax expects foo() for empty
|
||||
# params, not foo(void)
|
||||
if [ "$args" = "void" ]; then
|
||||
args=""
|
||||
fi
|
||||
|
||||
# Define prototype for probe arguments
|
||||
cat <<EOF
|
||||
probe $name($args);
|
||||
EOF
|
||||
}
|
||||
|
||||
linetod_end_dtrace()
|
||||
{
|
||||
cat <<EOF
|
||||
};
|
||||
EOF
|
||||
}
|
||||
|
||||
linetostap_begin_dtrace()
|
||||
{
|
||||
return
|
||||
}
|
||||
|
||||
linetostap_dtrace()
|
||||
{
|
||||
local i arg name args arglist state
|
||||
name=$(get_name "$1")
|
||||
args=$(get_args "$1")
|
||||
arglist=$(get_argnames "$1", "")
|
||||
state=$(get_state "$1")
|
||||
if [ "$state" = "0" ] ; then
|
||||
name=${name##disable }
|
||||
fi
|
||||
|
||||
# Define prototype for probe arguments
|
||||
cat <<EOF
|
||||
probe qemu.$targettype.$targetarch.$name = process("$binary").mark("$name")
|
||||
{
|
||||
EOF
|
||||
|
||||
i=1
|
||||
for arg in $arglist
|
||||
do
|
||||
# 'limit' is a reserved keyword
|
||||
if [ "$arg" = "limit" ]; then
|
||||
arg="_limit"
|
||||
fi
|
||||
cat <<EOF
|
||||
$arg = \$arg$i;
|
||||
EOF
|
||||
i="$((i+1))"
|
||||
done
|
||||
|
||||
cat <<EOF
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
linetostap_end_dtrace()
|
||||
{
|
||||
return
|
||||
}
|
||||
|
||||
# Process stdin by calling begin, line, and end functions for the backend
|
||||
convert()
|
||||
{
|
||||
local begin process_line end str disable
|
||||
begin="lineto$1_begin_$backend"
|
||||
process_line="lineto$1_$backend"
|
||||
end="lineto$1_end_$backend"
|
||||
|
||||
"$begin"
|
||||
|
||||
while read -r str; do
|
||||
# Skip comments and empty lines
|
||||
test -z "${str%%#*}" && continue
|
||||
|
||||
# Process the line. The nop backend handles disabled lines.
|
||||
disable=${str%%disable *}
|
||||
echo
|
||||
if test -z "$disable"; then
|
||||
# Pass the disabled state as an arg for the simple
|
||||
# or DTrace backends which handle it dynamically.
|
||||
# For all other backends, call lineto$1_nop()
|
||||
if [ $backend = "simple" -o "$backend" = "dtrace" ]; then
|
||||
"$process_line" "$str"
|
||||
else
|
||||
"lineto$1_nop" "${str##disable }"
|
||||
fi
|
||||
else
|
||||
"$process_line" "$str"
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
"$end"
|
||||
}
|
||||
|
||||
tracetoh()
|
||||
{
|
||||
cat <<EOF
|
||||
#ifndef TRACE_H
|
||||
#define TRACE_H
|
||||
|
||||
/* This file is autogenerated by tracetool, do not edit. */
|
||||
|
||||
#include "qemu-common.h"
|
||||
EOF
|
||||
convert h
|
||||
echo "#endif /* TRACE_H */"
|
||||
}
|
||||
|
||||
tracetoc()
|
||||
{
|
||||
echo "/* This file is autogenerated by tracetool, do not edit. */"
|
||||
convert c
|
||||
}
|
||||
|
||||
tracetod()
|
||||
{
|
||||
if [ $backend != "dtrace" ]; then
|
||||
echo "DTrace probe generator not applicable to $backend backend"
|
||||
exit 1
|
||||
fi
|
||||
echo "/* This file is autogenerated by tracetool, do not edit. */"
|
||||
convert d
|
||||
}
|
||||
|
||||
tracetostap()
|
||||
{
|
||||
if [ $backend != "dtrace" ]; then
|
||||
echo "SystemTAP tapset generator not applicable to $backend backend"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$binary" ]; then
|
||||
echo "--binary is required for SystemTAP tapset generator"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$targettype" ]; then
|
||||
echo "--target-type is required for SystemTAP tapset generator"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$targetarch" ]; then
|
||||
echo "--target-arch is required for SystemTAP tapset generator"
|
||||
exit 1
|
||||
fi
|
||||
echo "/* This file is autogenerated by tracetool, do not edit. */"
|
||||
convert stap
|
||||
}
|
||||
|
||||
|
||||
backend=
|
||||
output=
|
||||
binary=
|
||||
targettype=
|
||||
targetarch=
|
||||
|
||||
|
||||
until [ -z "$1" ]
|
||||
do
|
||||
case "$1" in
|
||||
"--nop" | "--simple" | "--ust" | "--dtrace") backend="${1#--}" ;;
|
||||
|
||||
"--binary") shift ; binary="$1" ;;
|
||||
"--target-arch") shift ; targetarch="$1" ;;
|
||||
"--target-type") shift ; targettype="$1" ;;
|
||||
|
||||
"-h" | "-c" | "-d") output="${1#-}" ;;
|
||||
"--stap") output="${1#--}" ;;
|
||||
|
||||
"--check-backend") exit 0 ;; # used by ./configure to test for backend
|
||||
|
||||
*)
|
||||
usage;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ "$backend" = "" -o "$output" = "" ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
gen="traceto$output"
|
||||
"$gen"
|
||||
|
||||
exit 0
|
Loading…
Add table
Add a link
Reference in a new issue