中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 操作系统 > AIX
Automate getting the dbx trace information
作者:未知 时间:2005-09-13 22:57 出处:Blog.ChinaUnix.net 责编:chinaitpower
              摘要:Automate getting the dbx trace information

#!/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

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有