Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos A
提交
d59aad1f
K
Kernel Liteos A
项目概览
OpenHarmony
/
Kernel Liteos A
9 个月 前同步成功
通知
450
Star
414
Fork
55
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
Kernel Liteos A
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d59aad1f
编写于
9月 24, 2021
作者:
O
openharmony_ci
提交者:
Gitee
9月 24, 2021
浏览文件
操作
浏览文件
下载
差异文件
!580 新增解析异常和backtrace信息脚本
Merge pull request !580 from zhangfanfan2/script
上级
de8bd286
7019fdfc
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
263 addition
and
0 deletion
+263
-0
tools/scripts/parse_exc/parse_excinfo.py
tools/scripts/parse_exc/parse_excinfo.py
+263
-0
未找到文件。
tools/scripts/parse_exc/parse_excinfo.py
0 → 100755
浏览文件 @
d59aad1f
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
#
import
sys
import
os
import
argparse
import
commands
import
io
def
find_string
(
excinfo_file
,
string
):
res
=
''
with
open
(
excinfo_file
,
'r+'
)
as
f
:
for
lines
in
f
:
if
string
in
lines
:
res
=
lines
break
return
res
def
is_kernel_exc
(
excinfo_file
):
res
=
find_string
(
excinfo_file
,
'excFrom: kernel'
)
print
(
res
)
return
res
!=
''
def
is_user_exc
(
excinfo_file
):
res
=
find_string
(
excinfo_file
,
'excFrom: User'
)
print
(
res
)
return
res
!=
''
def
parse_string_line
(
excinfo_file
,
string
):
line
=
find_string
(
excinfo_file
,
string
)
if
line
==
''
:
print
(
"%s is not in %s
\n
"
%
(
string
,
excinfo_file
))
return
''
line
=
line
.
replace
(
'
\n
'
,
''
)
strlist
=
line
.
split
(
' '
)
return
strlist
def
parse_kernel_pc_klr
(
excinfo_file
,
ohos_image_file
,
string
,
addr2line_cmd
,
objdump_cmd
):
#parse pc
f
=
open
(
excinfo_file
,
'r+'
)
start
=
0
for
lines
in
f
.
readlines
():
if
'excFrom: kernel'
in
lines
:
if
start
==
1
:
break
start
=
1
if
start
and
string
in
lines
:
lines
=
lines
[
lines
.
find
(
string
):]
strlist
=
lines
.
split
()
cmd
=
objdump_cmd
+
ohos_image_file
+
' | grep '
+
strlist
[
2
][
2
:]
+
': -B 10 -A 5 -w'
ret
=
commands
.
getoutput
(
cmd
)
print
(
ret
)
cmd
=
addr2line_cmd
+
ohos_image_file
+
' '
+
strlist
[
2
]
ret
=
commands
.
getoutput
(
cmd
)
ret
=
ret
.
split
(
'
\n
'
)
print
(
'<'
+
string
+
'>'
+
ret
[
0
]
+
' <'
+
strlist
[
2
]
+
'>
\n
'
)
f
.
close
()
return
0
f
.
close
()
return
-
1
def
parse_kernel_lr
(
excinfo_file
,
ohos_image_file
,
addr2line_cmd
):
f
=
open
(
excinfo_file
,
'r+'
)
start
=
0
index
=
1
for
lines
in
f
.
readlines
():
if
'excFrom: kernel'
in
lines
:
if
start
==
1
:
break
start
=
1
if
start
and
'lr ='
in
lines
:
lines
=
lines
[
lines
.
find
(
'lr ='
):]
strlist
=
lines
.
split
()
cmd
=
addr2line_cmd
+
ohos_image_file
+
' '
+
strlist
[
2
]
ret
=
commands
.
getoutput
(
cmd
)
ret
=
ret
.
split
(
'
\n
'
)
print
(
'<%.2d'
%
index
+
'>'
+
ret
[
0
]
+
' <'
+
strlist
[
2
]
+
'>'
)
index
=
index
+
1
f
.
close
()
def
parse_kernel_exc
(
excinfo_file
,
ohos_image_file
,
addr2line_cmd
,
objdump_cmd
):
#parse pc, klr
ret1
=
parse_kernel_pc_klr
(
excinfo_file
,
ohos_image_file
,
'pc'
,
addr2line_cmd
,
objdump_cmd
)
ret2
=
parse_kernel_pc_klr
(
excinfo_file
,
ohos_image_file
,
'klr'
,
addr2line_cmd
,
objdump_cmd
)
#parse lr
parse_kernel_lr
(
excinfo_file
,
ohos_image_file
,
addr2line_cmd
)
return
ret1
and
ret2
def
parse_user_pc_ulr
(
excinfo_file
,
rootfs_dir
,
string
,
addr2line_cmd
,
objdump_cmd
):
#parse pc
f
=
open
(
excinfo_file
,
'r+'
)
start
=
0
for
lines
in
f
.
readlines
():
if
'excFrom: User'
in
lines
:
if
start
==
1
:
break
start
=
1
if
start
and
string
in
lines
:
lines
=
lines
[
lines
.
find
(
string
):]
strlist
=
lines
.
split
()
if
len
(
strlist
)
<
7
:
print
(
'%s is error'
%
string
)
f
.
close
()
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
def
parse_user_lr
(
excinfo_file
,
rootfs_dir
,
addr2line_cmd
):
f
=
open
(
excinfo_file
,
'r+'
)
start
=
0
index
=
1
for
lines
in
f
.
readlines
():
if
'excFrom: User'
in
lines
:
if
start
==
1
:
break
start
=
1
if
start
and
'lr ='
in
lines
:
lines
=
lines
[
lines
.
find
(
'lr ='
):]
strlist
=
lines
.
split
()
if
len
(
strlist
)
<
11
:
print
(
'%s is error'
%
strlist
)
f
.
close
()
return
cmd
=
addr2line_cmd
+
rootfs_dir
+
strlist
[
8
]
+
' '
+
strlist
[
10
]
res
=
commands
.
getoutput
(
cmd
)
res
=
res
.
split
(
'
\n
'
)
print
(
'<%.2d>'
%
index
+
res
[
0
]
+
' <'
+
strlist
[
10
]
+
'>'
+
'<'
+
strlist
[
8
]
+
'>'
)
index
=
index
+
1
f
.
close
()
def
parse_user_exc
(
excinfo_file
,
rootfs_dir
,
addr2line_cmd
,
objdump_cmd
):
#parse pc ulr
ret1
=
parse_user_pc_ulr
(
excinfo_file
,
rootfs_dir
,
'pc'
,
addr2line_cmd
,
objdump_cmd
)
ret2
=
parse_user_pc_ulr
(
excinfo_file
,
rootfs_dir
,
'ulr'
,
addr2line_cmd
,
objdump_cmd
)
#parse lr
parse_user_lr
(
excinfo_file
,
rootfs_dir
,
addr2line_cmd
)
return
ret1
and
ret2
def
parse_backtrace
(
backtrace_file
,
ohos_image_file
,
addr2line_cmd
):
f
=
open
(
backtrace_file
,
'r+'
)
find
=
-
1
start
=
0
index
=
1
for
lines
in
f
.
readlines
():
if
'backtrace begin'
in
lines
:
if
start
==
1
:
break
start
=
1
if
start
and
'lr ='
in
lines
:
lines
=
lines
[
lines
.
find
(
'lr ='
):]
strlist
=
lines
.
split
()
cmd
=
addr2line_cmd
+
ohos_image_file
+
' '
+
strlist
[
2
]
ret
=
commands
.
getoutput
(
cmd
)
ret
=
ret
.
split
(
'
\n
'
)
print
(
'
\n
<%.2d'
%
index
+
'>'
+
ret
[
0
]
+
' <'
+
strlist
[
2
]
+
'>'
)
index
=
index
+
1
find
=
0
f
.
close
()
return
find
def
parse_excinfo
(
excinfo_file
,
ohos_image_file
,
rootfs_dir
,
addr2line_cmd
,
objdump_cmd
):
cmd
=
'dos2unix '
+
excinfo_file
commands
.
getoutput
(
cmd
)
kernel_exc
=
is_kernel_exc
(
excinfo_file
)
user_exc
=
is_user_exc
(
excinfo_file
)
if
kernel_exc
==
False
and
user_exc
==
False
:
if
parse_backtrace
(
excinfo_file
,
ohos_image_file
,
addr2line_cmd
)
!=
0
:
print
(
"%s is not a excinfo or backtrace file
\n
"
%
excinfo_file
)
return
-
1
else
:
return
0
if
user_exc
:
if
rootfs_dir
!=
None
:
return
parse_user_exc
(
excinfo_file
,
rootfs_dir
,
addr2line_cmd
,
objdump_cmd
)
else
:
print
(
'error: rootfs_dir is none'
)
return
-
1
return
parse_kernel_exc
(
excinfo_file
,
ohos_image_file
,
addr2line_cmd
,
objdump_cmd
)
def
parse_compiler
(
compiler
):
addr2line
=
''
addr2line_cmd
=
''
objdump
=
''
objdump_cmd
=
''
cmd
=
'which '
+
compiler
ret
=
commands
.
getoutput
(
cmd
)
if
ret
==
''
:
print
(
'%s is not exist'
%
compiler
)
return
None
index1
=
ret
.
rfind
(
'gcc'
)
index2
=
ret
.
rfind
(
'clang'
)
if
index1
!=
-
1
:
addr2line
=
ret
[
0
:
index1
]
+
'addr2line'
objdump
=
ret
[
0
:
index1
]
+
'objdump'
elif
index2
!=
-
1
:
index3
=
ret
.
rfind
(
'/'
)
addr2line
=
ret
[
0
:
index3
+
1
]
+
'llvm-addr2line'
objdump
=
ret
[
0
:
index3
+
1
]
+
'llvm-objdump'
else
:
print
(
'%s is not arm-xxx-xxx-gcc or clang'
%
compiler
)
return
None
addr2line_cmd
=
addr2line
+
' -C -f -e '
objdump_cmd
=
objdump
+
' -d '
return
[
addr2line_cmd
,
objdump_cmd
]
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--f'
,
help
=
'excinfo file or backtrace file'
)
parser
.
add_argument
(
'--e'
,
help
=
'elf system image file'
)
parser
.
add_argument
(
'--r'
,
help
=
'the path of rootfs'
)
parser
.
add_argument
(
'--c'
,
help
=
'compiler [arm-xxx-xxx-gcc/clang]'
)
args
=
parser
.
parse_args
()
if
args
.
f
==
None
or
args
.
e
==
None
:
print
(
"input error
\n
"
)
parser
.
print_help
()
return
-
1
excinfo_file
=
args
.
f
ohos_image_file
=
args
.
e
rootfs_dir
=
args
.
r
addr2line_cmd
=
'llvm-addr2line -C -f -e '
objdump_cmd
=
'llvm-objdump -d '
if
args
.
c
!=
None
:
cmd
=
parse_compiler
(
args
.
c
)
if
cmd
==
None
:
return
-
1
addr2line_cmd
=
cmd
[
0
]
objdump_cmd
=
cmd
[
1
]
return
parse_excinfo
(
excinfo_file
,
ohos_image_file
,
rootfs_dir
,
addr2line_cmd
,
objdump_cmd
)
if
__name__
==
"__main__"
:
sys
.
exit
(
main
())
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录