提交 660b314f 编写于 作者: H Hongjin Li

style: string format in python

Signed-off-by: NHongjin Li <lihongjin1@huawei.com>
Change-Id: Ie84a97ca5e0250991aa774b737eb7787e27d80af
上级 44ec1994
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<licensefile></licensefile> <licensefile></licensefile>
<policylist> <policylist>
<policy name="projectPolicy" desc=""> <policy name="projectPolicy" desc="">
<policyitem type="copyright" name="Huawei Technologies Co., Ltd. All rights reserved." path=".*" desc="original liteos copyright"/>
<policyitem type="copyright" name="Huawei Device Co., Ltd. All rights reserved." path=".*" desc="original liteos copyright"/> <policyitem type="copyright" name="Huawei Device Co., Ltd. All rights reserved." path=".*" desc="original liteos copyright"/>
<policyitem type="license" name="BSD-3-Clause" path=".*" desc="Liteos kernel use bsd3 license"/> <policyitem type="license" name="BSD-3-Clause" path=".*" desc="Liteos kernel use bsd3 license"/>
</policy> </policy>
......
...@@ -44,6 +44,6 @@ if [ -d "${BIN_DIR}" ] && [ "$(ls -A "${BIN_DIR}")" != "" ]; then ...@@ -44,6 +44,6 @@ if [ -d "${BIN_DIR}" ] && [ "$(ls -A "${BIN_DIR}")" != "" ]; then
fi fi
cp -f ${LIB_DIR}/* ${ROOTFS_DIR}/lib cp -f ${LIB_DIR}/* ${ROOTFS_DIR}/lib
if [ -e ${ETC_DIR}/.mkshrc ]; then if [ -e "${ETC_DIR}"/.mkshrc ]; then
cp -f ${ETC_DIR}/.mkshrc ${ROOTFS_DIR}/etc cp -f ${ETC_DIR}/.mkshrc ${ROOTFS_DIR}/etc
fi fi
#!/usr/bin/env python2 #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. # Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without modification, # Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met: # are permitted provided that the following conditions are met:
...@@ -66,47 +66,43 @@ def parse_string_line(excinfo_file, string): ...@@ -66,47 +66,43 @@ def parse_string_line(excinfo_file, string):
def parse_kernel_pc_klr(excinfo_file, ohos_image_file, string, addr2line_cmd, objdump_cmd): def parse_kernel_pc_klr(excinfo_file, ohos_image_file, string, addr2line_cmd, objdump_cmd):
#parse pc #parse pc
f = open(excinfo_file, 'r+') with open(excinfo_file, 'r+') as f:
start = 0 start = 0
for lines in f.readlines(): for lines in f.readlines():
if 'excFrom: kernel' in lines: if 'excFrom: kernel' in lines:
if start == 1: if start == 1:
break break
start = 1 start = 1
if start and string in lines: if start and string in lines:
lines = lines[lines.find(string):] lines = lines[lines.find(string):]
strlist = lines.split() strlist = lines.split()
cmd = objdump_cmd + ohos_image_file + ' | grep ' + strlist[2][2:] + ': -B 10 -A 5 -w' cmd = "%s%s | grep %s: -B 10 -A 5 -w" % (objdump_cmd, ohos_image_file, strlist[2][2:])
ret = commands.getoutput(cmd) ret = commands.getoutput(cmd)
print(ret) print(ret)
cmd = addr2line_cmd + ohos_image_file + ' ' + strlist[2] cmd = "%s%s %s" % (addr2line_cmd, ohos_image_file, strlist[2])
ret = commands.getoutput(cmd) ret = commands.getoutput(cmd)
ret = ret.split('\n') ret = ret.split('\n')
print('<' + string + '>' + ret[0] + ' <' + strlist[2] + '>\n') print("<%s>%s<%s>\n") % (string, ret[0], strlist[2])
f.close() return 0
return 0
f.close()
return -1 return -1
def parse_kernel_lr(excinfo_file, ohos_image_file, addr2line_cmd): def parse_kernel_lr(excinfo_file, ohos_image_file, addr2line_cmd):
f = open(excinfo_file, 'r+') with open(excinfo_file, 'r+') as f:
start = 0 start = 0
index = 1 index = 1
for lines in f.readlines(): for lines in f.readlines():
if 'excFrom: kernel' in lines: if 'excFrom: kernel' in lines:
if start == 1: if start == 1:
break break
start = 1 start = 1
if start and 'lr =' in lines: if start and 'lr =' in lines:
lines = lines[lines.find('lr ='):] lines = lines[lines.find('lr ='):]
strlist = lines.split() strlist = lines.split()
cmd = addr2line_cmd + ohos_image_file + ' ' + strlist[2] cmd = "%s%s %s" % (addr2line_cmd, ohos_image_file, strlist[2])
ret = commands.getoutput(cmd) ret = commands.getoutput(cmd)
ret = ret.split('\n') ret = ret.split('\n')
print('<%.2d'%index + '>' + ret[0] + ' <' + strlist[2] + '>') print("<%.2d>%s<%s>" % (index, ret[0], strlist[2]))
index = index + 1 index = index + 1
f.close()
def parse_kernel_exc(excinfo_file, ohos_image_file, addr2line_cmd, objdump_cmd): def parse_kernel_exc(excinfo_file, ohos_image_file, addr2line_cmd, objdump_cmd):
#parse pc, klr #parse pc, klr
...@@ -118,56 +114,50 @@ def parse_kernel_exc(excinfo_file, ohos_image_file, addr2line_cmd, objdump_cmd): ...@@ -118,56 +114,50 @@ def parse_kernel_exc(excinfo_file, ohos_image_file, addr2line_cmd, objdump_cmd):
def parse_user_pc_ulr(excinfo_file, rootfs_dir, string, addr2line_cmd, objdump_cmd): def parse_user_pc_ulr(excinfo_file, rootfs_dir, string, addr2line_cmd, objdump_cmd):
#parse pc #parse pc
f = open(excinfo_file, 'r+') with open(excinfo_file, 'r+') as f:
start = 0 start = 0
for lines in f.readlines(): for lines in f.readlines():
if 'excFrom: User' in lines: if 'excFrom: User' in lines:
if start == 1: if start == 1:
break break
start = 1 start = 1
if start and string in lines: if start and string in lines:
lines = lines[lines.find(string):] lines = lines[lines.find(string):]
strlist = lines.split() strlist = lines.split()
if len(strlist) < 7: if len(strlist) < 7:
print('%s is error'%string) print('%s is error'%string)
f.close() return 0
cmd = "%s%s%s | grep %s: -B 10 -A 5 -w" % (objdump_cmd, rootfs_dir, strlist[4], strlist[6][2:])
ret = commands.getoutput(cmd)
print(ret)
cmd = "%s%s%s %s" % (addr2line_cmd, rootfs_dir, strlist[4], strlist[6])
#print(cmd)
ret = commands.getoutput(cmd)
ret = ret.split('\n')
print("<%s>%s<%s><%s>\n" % (string, ret[0], strlist[6], strlist[4]))
return 0 return 0
cmd = objdump_cmd + rootfs_dir + strlist[4] + ' | grep ' + strlist[6][2:] + ': -B 10 -A 5 -w'
ret = commands.getoutput(cmd)
print(ret)
cmd = addr2line_cmd + rootfs_dir + strlist[4] + ' ' + strlist[6]
#print(cmd)
ret = commands.getoutput(cmd)
ret = ret.split('\n')
print('<' + string + '>' + ret[0] + ' <' + strlist[6] + '>' + '<' + strlist[4] + '>\n')
f.close()
return 0
f.close()
return -1 return -1
def parse_user_lr(excinfo_file, rootfs_dir, addr2line_cmd): def parse_user_lr(excinfo_file, rootfs_dir, addr2line_cmd):
f = open(excinfo_file, 'r+') with open(excinfo_file, 'r+') as f:
start = 0 start = 0
index = 1 index = 1
for lines in f.readlines(): for lines in f.readlines():
if 'excFrom: User' in lines: if 'excFrom: User' in lines:
if start == 1: if start == 1:
break break
start = 1 start = 1
if start and 'lr =' in lines: if start and 'lr =' in lines:
lines = lines[lines.find('lr ='):] lines = lines[lines.find('lr ='):]
strlist = lines.split() strlist = lines.split()
if len(strlist) < 11: if len(strlist) < 11:
print('%s is error'%strlist) print('%s is error' % strlist)
f.close() return
return cmd = "%s%s%s %s" % (addr2line_cmd, rootfs_dir, strlist[8], strlist[10])
cmd = addr2line_cmd + rootfs_dir + strlist[8] + ' ' + strlist[10] res = commands.getoutput(cmd)
res = commands.getoutput(cmd) res = res.split('\n')
res = res.split('\n') print("<%.2d>%s<%s><%s>" % (index, res[0], strlist[10], strlist[8]))
print('<%.2d>'%index + res[0] + ' <' + strlist[10] + '>' + '<' + strlist[8] + '>') index = index + 1
index = index + 1
f.close()
def parse_user_exc(excinfo_file, rootfs_dir, addr2line_cmd, objdump_cmd): def parse_user_exc(excinfo_file, rootfs_dir, addr2line_cmd, objdump_cmd):
#parse pc ulr #parse pc ulr
...@@ -178,30 +168,29 @@ def parse_user_exc(excinfo_file, rootfs_dir, addr2line_cmd, objdump_cmd): ...@@ -178,30 +168,29 @@ def parse_user_exc(excinfo_file, rootfs_dir, addr2line_cmd, objdump_cmd):
return ret1 and ret2 return ret1 and ret2
def parse_backtrace(backtrace_file, ohos_image_file, addr2line_cmd): def parse_backtrace(backtrace_file, ohos_image_file, addr2line_cmd):
f = open(backtrace_file, 'r+') with open(backtrace_file, 'r+') as f:
find = -1 find = -1
start = 0 start = 0
index = 1 index = 1
for lines in f.readlines(): for lines in f.readlines():
if 'backtrace begin' in lines: if 'backtrace begin' in lines:
if start == 1: if start == 1:
break break
start = 1 start = 1
if start and 'lr =' in lines: if start and 'lr =' in lines:
lines = lines[lines.find('lr ='):] lines = lines[lines.find('lr ='):]
strlist = lines.split() strlist = lines.split()
cmd = addr2line_cmd + ohos_image_file + ' ' + strlist[2] cmd = "%s%s %s" % (addr2line_cmd, ohos_image_file, strlist[2])
ret = commands.getoutput(cmd) ret = commands.getoutput(cmd)
ret = ret.split('\n') ret = ret.split('\n')
print('\n<%.2d'%index + '>' + ret[0] + ' <' + strlist[2] + '>') print("\n<%.2d>%s<%s>" % (index, ret[0], strlist[2]))
index = index + 1 index = index + 1
find = 0 find = 0
f.close()
return find return find
def parse_excinfo(excinfo_file, ohos_image_file, rootfs_dir, addr2line_cmd, objdump_cmd): def parse_excinfo(excinfo_file, ohos_image_file, rootfs_dir, addr2line_cmd, objdump_cmd):
cmd = 'dos2unix ' + excinfo_file cmd = "dos2unix %s" % (excinfo_file)
commands.getoutput(cmd) commands.getoutput(cmd)
kernel_exc = is_kernel_exc(excinfo_file) kernel_exc = is_kernel_exc(excinfo_file)
user_exc = is_user_exc(excinfo_file) user_exc = is_user_exc(excinfo_file)
...@@ -225,7 +214,7 @@ def parse_compiler(compiler): ...@@ -225,7 +214,7 @@ def parse_compiler(compiler):
addr2line_cmd = '' addr2line_cmd = ''
objdump = '' objdump = ''
objdump_cmd = '' objdump_cmd = ''
cmd = 'which ' + compiler cmd = "which %s" % (compiler)
ret = commands.getoutput(cmd) ret = commands.getoutput(cmd)
if ret == '': if ret == '':
print('%s is not exist'%compiler) print('%s is not exist'%compiler)
......
#!/bin/bash #!/bin/bash
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. # Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without modification, # Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met: # are permitted provided that the following conditions are met:
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set -e
LOAD_BASE="0x2000000" LOAD_BASE="0x2000000"
LLVM_ADDR2LINE=llvm-addr2line LLVM_ADDR2LINE=llvm-addr2line
...@@ -36,12 +37,12 @@ GCC_ADDR2LINE=addr2line ...@@ -36,12 +37,12 @@ GCC_ADDR2LINE=addr2line
get_line() get_line()
{ {
SYM_ADDR=$(echo $1 | awk '{print $2}') SYM_ADDR=$(echo $1 | awk '{print $2}')
ELF_OFFSET=`echo ${SYM_ADDR} | cut -d '[' -f2 | cut -d ']' -f1` ELF_OFFSET=$(echo ${SYM_ADDR} | cut -d '[' -f2 | cut -d ']' -f1)
FILE_LINE=`${ADDR2LINE} -f -e $2 ${ELF_OFFSET} | awk 'NR==2'` FILE_LINE=$(${ADDR2LINE} -f -e $2 ${ELF_OFFSET} | awk 'NR==2'`)
if [[ "${FILE_LINE}" == *"?"* ]]; then if [[ "${FILE_LINE}" == *"?"* ]]; then
typeset ELF_OFFSET=$((ELF_OFFSET+LOAD_BASE)) typeset ELF_OFFSET=$((ELF_OFFSET+LOAD_BASE))
ELF_OFFSET=$(echo "obase=16;${ELF_OFFSET}" | bc) ELF_OFFSET=$(echo "obase=16;${ELF_OFFSET}" | bc)
FILE_LINE=`${ADDR2LINE} -f -e $2 ${ELF_OFFSET} | awk 'NR==2'` FILE_LINE=$(${ADDR2LINE} -f -e $2 ${ELF_OFFSET} | awk 'NR==2')
fi fi
echo ${FILE_LINE} echo ${FILE_LINE}
} }
...@@ -58,12 +59,12 @@ parse_line() ...@@ -58,12 +59,12 @@ parse_line()
echo "Error: no such file: $i" echo "Error: no such file: $i"
exit 1 exit 1
fi fi
FILE_LINE=`get_line "$1" $i` FILE_LINE=$(get_line "$1" $i)
if [[ "${FILE_LINE}" == *"?"* ]] || [ -z "${FILE_LINE}" ]; then if [[ "${FILE_LINE}" == *"?"* ]] || [ -z "${FILE_LINE}" ]; then
echo " * Error: you need ensure whether file: "$i" was compiled with -g or not! *" echo " * Error: you need ensure whether file: "$i" was compiled with -g or not! *"
exit 1 exit 1
fi fi
LINE=`echo $1 | tr -d '\r'` LINE=$(echo $1 | tr -d '\r')
LINE=$(echo ${LINE} | awk '{print $1,$2}') LINE=$(echo ${LINE} | awk '{print $1,$2}')
echo " "${LINE}" at "${FILE_LINE} echo " "${LINE}" at "${FILE_LINE}
FLAG=true FLAG=true
...@@ -81,7 +82,7 @@ if [ $# -le 1 ]; then ...@@ -81,7 +82,7 @@ if [ $# -le 1 ]; then
fi fi
read -n5 -p "Compiler is [gcc/llvm]: " ANSWER read -n5 -p "Compiler is [gcc/llvm]: " ANSWER
case ${ANSWER} in case "${ANSWER}" in
(gcc | GCC) (gcc | GCC)
which ${GCC_ADDR2LINE} >/dev/null 2>&1 which ${GCC_ADDR2LINE} >/dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册