From 9f90710f3b430fab77c5647dbac4947a93ea6737 Mon Sep 17 00:00:00 2001 From: rginda Date: Mon, 5 Apr 2010 15:22:44 -0700 Subject: [PATCH] A pair of scripts to make it easier to run and debug 32 bit executables on 64 bit systems For Example: # run the 32 bit binary located ad ../platform/foo/a.out $ run_32bit.sh ../platform/foo/a.out # run a.out from the current directory, and pass it the --verbose=3 command line option $ ../../scripts/run_32bit.sh -- a.out --verbose=3 # debug a.out from the current directory, include ../v8 in the library search path $ LIB_PATHS='../v8/' ../../scripts/debug_32bit.sh a.out run_32bit.sh runs a 32bit executable, debug_32bit.sh starts up gdb so that it's ready to debug a 32bit target. Both scripts work from in or out of the chroot. If you're running from outside the chroot, you can pass a --chroot command line option to locate the chroot, otherwise a default is computed through the normal mechanism. Pass the 32 bit target as the parameter to either of these scripts. If you need to provide additional parameters to your command, then you should use -- to signify the end of *_32bit.sh parameters. These could be useful to people developing parts of chromeos that can be easily isolated from the rest of the system. If your code doesn't NEED to run on a chromeos device it can be a bit easier to try it out on your owm machine during dev/test. Review URL: http://codereview.chromium.org/1131002 --- debug_32bit.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ run_32bit.sh | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100755 debug_32bit.sh create mode 100755 run_32bit.sh diff --git a/debug_32bit.sh b/debug_32bit.sh new file mode 100755 index 0000000000..7ae6969ed5 --- /dev/null +++ b/debug_32bit.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# Copyright (c) 2009 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Debug a 32 bit binary on 64 bit linux. Can be run from inside or outside +# the chroot. If inside, then the 32 bit gdb from the chroot is used, otherwise +# the system's 64 bit gdb is used. + +. "$(dirname "$0")/common.sh" + +# Command line options +DEFINE_string chroot "$DEFAULT_CHROOT_DIR" "Location of chroot" + +# Parse command line and update positional args +FLAGS "$@" || exit 1 +eval set -- "${FLAGS_ARGV}" + + # Die on any errors +set -e + +if [ -z "$SYSROOT" ]; then + if [ $INSIDE_CHROOT == 1 ]; then + SYSROOT=/build/x86-generic + else + SYSROOT=$FLAGS_chroot/build/x86-generic + fi +fi + +if [ -z "$CHOST" ]; then + CHOST="x86-generic" +fi + +SYSROOT="$FLAGS_chroot/build/$CHOST" +LIB_PATHS="/lib32:/usr/lib32:$LIB_PATHS:$SYSROOT/usr/lib:$SYSROOT/lib:." +LIB_PATHS="$LIB_PATHS:$SYSROOT/opt/google/chrome/chromeos" + +if [ $INSIDE_CHROOT == 1 ]; then + # if we're inside the chroot, the we'll be running a 32 bit gdb, so we'll + # need the same library path as the target + export LD_LIBRARY_PATH=$LIB_PATHS + GDB="$SYSROOT/usr/bin/gdb" +else + GDB="gdb" +fi + +exec $GDB \ + --eval-command "set environment LD_LIBRARY_PATH=$LIB_PATHS" \ + --eval-command "set sysroot $SYSROOT " \ + --eval-command "set prompt (cros-gdb) " \ + --args "$@" diff --git a/run_32bit.sh b/run_32bit.sh new file mode 100755 index 0000000000..4fcc82b082 --- /dev/null +++ b/run_32bit.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Copyright (c) 2009 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Run a 32 bit binary on 64 bit linux, can be run from inside or outside +# the chroot. + +. "$(dirname "$0")/common.sh" + +# Command line options +DEFINE_string chroot "$DEFAULT_CHROOT_DIR" "Location of chroot" + +# Parse command line and update positional args +FLAGS "$@" || exit 1 +eval set -- "${FLAGS_ARGV}" + + # Die on any errors +set -e + +if [ -z "$SYSROOT" ]; then + if [ $INSIDE_CHROOT == 1 ]; then + SYSROOT=/build/x86-generic + else + SYSROOT=$FLAGS_chroot/build/x86-generic + fi +fi + +if [ -z "$CHOST" ]; then + CHOST=i686-pc-linux-gnu +fi + +LIB_PATHS="/lib32:/usr/lib32:$LIB_PATHS:$SYSROOT/usr/lib:$SYSROOT/lib:." +LIB_PATHS="$LIB_PATHS:$SYSROOT/opt/google/chrome/chromeos" +export LD_LIBRARY_PATH=$LIB_PATHS + +exec "$@"