• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

Automate getting the dbx trace information

发布: 2007-6-08 22:43 | 作者: seanhe | 来源: Blog.ChinaUnix.net

软件测试论坛讨论

领测软件测试网

#!/bin/ksh

# Automate getting the dbx trace information
# --------------------------------------------------------
# AIX V4 32bit max thread limit in sys/thread.h
# Customer can adjust this value to max of target process
# --------------------------------------------------------
.

#!/bin/ksh

# Automate getting the dbx trace information
# --------------------------------------------------------
# AIX V4 32bit max thread limit in sys/thread.h
# Customer can adjust this value to max of target process
# --------------------------------------------------------
integer MAXTHREADS=512
integer MINTHREADS=1 
integer THREAD_NUM=$MINTHREADS

#
# Usage
#

PROGNAME=$(basename )
function Usage {
        print "$(basename ): Automate getting dbx trace information " 1>&2
        print "" 1>&2
        print "For core files:" 1>&2
 print "    Usage:   $PROGNAME [executable] [core]" 1>&2
 print "      or :   $PROGNAME -c corefile" 1>&2
 print "    Example: $PROGNAME /usr/jdk_base/bin/aix/native_threads/java core"  1>&2
        print "    (Please make sure you use the java executable and not the java script)" 1>&2
        print "" 1>&2
        print "To attach to a running or hung process" 1>&2
 print "    Usage:   $PROGNAME -a PID"  1>&2
 print "    Example: $PROGNAME -a 1234"  1>&2
 exit -1
}

#
# Parse command lime arguments
#
typeset PID
EXECUTABLE=/usr/jdk_base/bin/aix/native_threads/java
CORE_FILE=core

if [[ $# > 0 ]]
then
    if [[ = "-a" ]]
    then
       if [[ $# -eq 2 ]]
       then
           PID=
       else
           Usage
       fi
    elif [[ = "-c" ]]
    then
       if [[ $# -eq 2 ]]
       then
           CORE_FILE=
       else
           Usage
       fi
    else
        EXECUTABLE=
        if [[ $# -eq 2 ]]
        then
            CORE_FILE=
        fi
    fi
fi

#
# Check command lime arguments
#     then set the appropriate dbx commands
#
if [[ $PID. -eq . ]]
then
    if [[ ! ( -f $EXECUTABLE ) ]]
    then
 print "executable file: $EXECUTABLE does not exist" 1>&2
 Usage
    fi

    if [[ ! ( -x $EXECUTABLE ) ]]
    then
 print "executable file: $EXECUTABLE is not executable" 1>&2
 Usage
    fi

    if [[ ! ( -f $CORE_FILE ) ]]
    then
 print "core file: $CORE_FILE does not exist" 1>&2
 Usage
    fi
    if [[ $CORE_FILE = core ]]
    then
        print "******************************************" 1>&2
        print "* Failure of this script or dbx may      *" 1>&2
        print "* overwrite your existing core file.     *" 1>&2
        print "* It is recomended that you rename your  *" 1>&2
        print "* existing core file and use the -c flag *" 1>&2
        read Y_OR_N?"* Do you wish to continue (y/n): " 1>&2
        print "******************************************" 1>&2
        if [[ $Y_OR_N. != y. ]] && [[ $Y_OR_N. != Y. ]]
        then
            exit 0
        fi
    fi
    typeset -r DBX_COMMAND="/usr/bin/dbx $EXECUTABLE $CORE_FILE"
    typeset -r DETACH="quit"
else
    ps $PID > /dev/null 2>&1
    if [[ $? != "0" ]]
    then
        print "Process ID : $PID does not exist" 1>&2
 Usage
    fi
    typeset -r DBX_COMMAND="/usr/bin/dbx -a $PID"
    typeset -r DETACH="detach"
fi

#---------------------------------------------------------
# Prepare a command file to get all the thread information
#---------------------------------------------------------
# $DBX_COMMAND
# ---- Loop from 1 to MAXTHREADS ----
# > thread current THREAD_NUM
# > where
# ----------------------------
# > $DETACH

typeset THREAD_SUB_COMMAND
typeset -r WHERE="where"
typeset -r DIVIDER="-----------------------------------------------------------------"

# Create thread sub command statements
print "Creating subcommand file...." 1>&2
typeset -r COMMAND_FILE=./dbx_commands.$$
awk -v thread_num=$THREAD_NUM -v max_threads=$MAXTHREADS -vdivider=$DIVIDER -vpid=$PID \
' BEGIN {
    print "thread"
    print "print \"\""
    print "thread info"
    print "print \"" divider "\""
    print "print \"Register Dump and Instruction trace follows\""
    print "unset $noflregs"
    print "registers"
    print "where"
    print "print \"listi .-40,.+40 \""
    print "listi .-40,.+40"
    print "print \"" divider "\""
    while (thread_num <= max_threads) {
      print "thread " thread_num
      print "thread current " thread_num
      print "where"
      print "print \"" divider "\""
      thread_num++
    }
#    if (pid != 0 ) { # if attaching then capture javacore.txt
#      print "sh kill -QUIT " pid
#    }
  }
' < /dev/null >> $COMMAND_FILE
echo "$DETACH" >> $COMMAND_FILE

# Remove the tail end information about non existant threads
typeset -r REMOVE_MISSING_THREADS="/^['][$]t[0-9]*['] is not an existing thread./,/^$DIVIDER/d"
typeset -r REMOVE_BAD_LINES="/^program is not active$/d"

print "Running dbx..." 1>&2
$DBX_COMMAND < $COMMAND_FILE 2>&1 | sed -e "$REMOVE_MISSING_THREADS" -e "$REMOVE_BAD_LINES"

rm $COMMAND_FILE
if [[ $? != "0" ]]
then
    print "failed to remove $COMMAND_FILE" 1>&2
fi
print "dbx has ended with RC=$?" 1>&2

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网