run_gdb 3.07 KB
Newer Older
1
#!/bin/bash
2 3 4 5 6
#/*
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements.  See the NOTICE file distributed with
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
7
# * the OAI Public License, Version 1.1  (the "License"); you may not use this file
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# * except in compliance with the License.
# * You may obtain a copy of the License at
# *
# *      http://www.openairinterface.org/?page_id=698
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *-------------------------------------------------------------------------------
# * For more information about the OpenAirInterface (OAI) Software Alliance:
# *      contact@openairinterface.org
# */

# \author Navid Nikaein, Rohit Gupta

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

#arg0 -> Name of executable
#args[1...N] -> arguments to be passed to executable
if [ -z "$OPENAIR_DIR" ]
then
    echo "OPENAIR_DIR environment not set. Exiting.."
    exit
fi 

source $OPENAIR_DIR/cmake_targets/tools/build_helper

args=($*)
exec_name=${args[0]}
exe_args=(${args[@]:1})
gdb_file=$OPENAIR_DIR/targets/bin/gdb_file
gdb_log=$OPENAIR_DIR/targets/bin/gdb_log.bt

echo "args = ${args[@]}"
echo "exec_name = $exec_name"
echo "exe_args = ${exe_args[@]}"
echo "gdb log file = $gdb_log"

$SUDO rm -fr $gdb_file $gdb_log
$SUDO touch $gdb_file $gdb_log 
$SUDO chmod 777  $gdb_file $gdb_log

$SUDO echo "file $exec_name"                  >> $gdb_file
$SUDO echo "set args ${exe_args[@]}"          >> $gdb_file
$SUDO echo "run"                              >> $gdb_file
$SUDO echo "set logging overwrite on"         >> $gdb_file
$SUDO echo "set logging file $gdb_log"        >> $gdb_file
$SUDO echo "set logging on"                   >> $gdb_file
$SUDO echo "set pagination off"               >> $gdb_file
$SUDO echo "handle SIG33 pass nostop noprint" >> $gdb_file
$SUDO echo "echo backtrace:\n"                >> $gdb_file
$SUDO echo "backtrace full"                   >> $gdb_file
61 62 63 64
$SUDO echo "echo \n\nVariables:\n"            >> $gdb_file
$SUDO echo "info variables"                   >> $gdb_file
$SUDO echo "echo \n\nlocals:\n"               >> $gdb_file
$SUDO echo "info locals"                      >> $gdb_file
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
$SUDO echo "echo \n\nregisters:\n"            >> $gdb_file
$SUDO echo "info registers"                   >> $gdb_file
$SUDO echo "echo \n\ncurrent instructions:\n" >> $gdb_file 
$SUDO echo "x/16i \$pc"                       >> $gdb_file
$SUDO echo "echo \n\nthreads backtrace:\n"    >> $gdb_file
$SUDO echo "thread apply all backtrace"       >> $gdb_file
$SUDO echo "set logging off"                  >> $gdb_file
$SUDO echo "quit"                             >> $gdb_file

echo "Contents of gdb_file...start"
$SUDO cat $gdb_file
echo "Contents of gdb_file...finish"

$SUDO gdb -n -x $gdb_file 2>&1