From 9805d333ea5e616cde084b27c2d47814551b587b Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Thu, 19 Apr 2018 08:01:01 +0100 Subject: [PATCH] tc: create helper to access toolchain tools --- README.adoc | 9 ++++----- build | 1 - common | 1 + run | 1 - rungdb | 1 - rungdb-user | 4 +--- rungdbserver | 1 - runtc | 28 ++++++++++++++++++++++++++++ trace-boot | 2 +- 9 files changed, 35 insertions(+), 13 deletions(-) create mode 100755 runtc diff --git a/README.adoc b/README.adoc index eef1df4..3c1a21f 100644 --- a/README.adoc +++ b/README.adoc @@ -924,8 +924,7 @@ so it is close to the failing `0xbf0000cc`. `readelf`: .... -./out/x86_64/buildroot/host/usr/bin/x86_64-buildroot-linux-uclibc-readelf \ --s ./out/x86_64/buildroot/build/kernel_module-1.0/hello.ko +./runtc readelf -s ./out/x86_64/buildroot/build/kernel_module-1.0/hello.ko .... does not give any interesting hits at `cc`, no symbol was placed that far. @@ -998,7 +997,7 @@ The base address shows on terminal: Now let's find the offset of `myinit`: .... -./out/x86_64/buildroot/host/usr/bin/x86_64-buildroot-linux-uclibc-readelf \ +./runtc readelf \ -s ./out/x86_64/buildroot/build/kernel_module-1.0/fops.ko | \ grep myinit .... @@ -1295,7 +1294,7 @@ Cannot access memory at address 0x10604 We have also double checked the address with: .... -./out/arm/buildroot/host/bin/arm-buildroot-linux-uclibcgnueabi-readelf-s \ +./runtc -a arm readelf \ ./out/arm/buildroot/build/kernel_module-1.0/user/hello.out | \ grep main .... @@ -2737,7 +2736,7 @@ Notes: It can be found from: + .... -readelf -e out/x86_64/buildroot/build/linux-*/vmlinux | grep Entry +./runtc readelf -e out/x86_64/buildroot/build/linux-*/vmlinux | grep Entry .... + TODO confirm further. If I try to break there with: diff --git a/build b/build index a73b2fe..8777791 100755 --- a/build +++ b/build @@ -9,7 +9,6 @@ touch "$br2_cli_file" configure=true config_fragments="${root_dir}/br2" extra_make_args= -gem5=false j="$(nproc)" linux_reconfigure=false linux_kernel_custom_config_file= diff --git a/common b/common index 6906a88..6eec8b0 100644 --- a/common +++ b/common @@ -49,3 +49,4 @@ if [ -f "$f" ]; then fi # Default arch. arch=x86_64 +gem5=false diff --git a/run b/run index ed28ce6..67e29e3 100755 --- a/run +++ b/run @@ -18,7 +18,6 @@ extra_append='console_msg_format=syslog nokaslr norandmaps printk.devkmsg=on pri extra_append_after_dash= extra_flags= extra_flags_qemu= -gem5=false gem5opts= lkmc_eval= initrd=false diff --git a/rungdb b/rungdb index 21059bf..4a46d00 100755 --- a/rungdb +++ b/rungdb @@ -4,7 +4,6 @@ set -eu set -- ${cli_rungdb:-} "$@" after= before= -gem5=false lx_symbols="-ex 'lx-symbols ../kernel_module-1.0/' \\ " kgdb=false diff --git a/rungdb-user b/rungdb-user index 387107e..1438b23 100755 --- a/rungdb-user +++ b/rungdb-user @@ -3,7 +3,6 @@ set -eu . common set -- ${cli_rungdb_user:-} "$@" usage="$0 []" -gem5=false gem5_opt= while getopts a:gh OPT; do case "$OPT" in @@ -34,8 +33,7 @@ else fi set_common_vars "$arch" "$gem5" executable="${build_dir}/${executable_rel}" -readelf="${host_dir}/usr/bin/${arch}-linux-readelf" -addr="$("$readelf" -h "$executable" | awk '/Entry/{ print $NF }' )" +addr="$("${root_dir}/runtc" readelf -h "$executable" | awk '/Entry/{ print $NF }' )" ex="-ex \"add-symbol-file $executable $addr\"" # -L or else lx-symbols throws for arm: # gdb.MemoryError: Cannot access memory at address 0xbf0040cc diff --git a/rungdbserver b/rungdbserver index 0f54cbe..5e26bda 100755 --- a/rungdbserver +++ b/rungdbserver @@ -2,7 +2,6 @@ set -eu . common set -- ${cli_rungdbserver:-} "$@" -gem5=false while getopts a:g OPT; do case "$OPT" in a) diff --git a/runtc b/runtc new file mode 100755 index 0000000..4adf51c --- /dev/null +++ b/runtc @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -eu +. common +set -- ${cli_tc:-} "$@" +while getopts a:gh OPT; do + case "$OPT" in + a) + arch="$OPTARG" + ;; + g) + gem5=true + ;; + h) + printf "Usage: $0 TOOL [TOOL_ARGS]... +Call a built ToolChain tool. Example: + + $0 -a arm readelf -h +" 2>&1 + exit 0 + ;; + esac +done +shift "$(($OPTIND - 1))" +tool="$1" +shift +set_common_vars "$arch" "$gem5" +"${buildroot_out_dir}/host/bin/"*-buildroot-*"${tool}" "$@" +exit "$?" diff --git a/trace-boot b/trace-boot index 8b42a21..2662677 100755 --- a/trace-boot +++ b/trace-boot @@ -17,7 +17,7 @@ time ./qemu-trace2txt -a "$arch" # We could put this on a separate script, but it just adds more arch boilerplate to a new script. # So let's just leave it here for now since it did not add a significant processing time. echo "instructions $(wc -l "${qemu_trace_txt_file}" | cut -d' ' -f1)" -entry_addr=$("${host_dir}"/bin/*-buildroot-*-readelf -h "${build_dir}/linux-custom/vmlinux" | grep 'Entry point address' | sed -E 's/.*: *//') +entry_addr=$("${root_dir}/runtc" readelf -h "${build_dir}/linux-custom/vmlinux" | grep 'Entry point address' | sed -E 's/.*: *//') echo "entry_address ${entry_addr}" sed "/${entry_addr}/q" "${qemu_trace_txt_file}" >"${qemu_out_dir}/trace-boot.txt" echo "instructions_firmware $(wc -l "${qemu_out_dir}/trace-boot.txt" | cut -d' ' -f1)"