• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# coding:utf-8
3# Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import sys,string,re,os
17from ctypes import *
18
19import auto_class as auto_class
20from parse_basic import *
21import json
22
23def _process_g_var(list,result_fp):
24    name=list[0].strip()
25    addr=int(list[1],16)
26    size=list[2]
27    type_name=list[3].strip()
28
29    if hasattr(auto_class, type_name):
30        class_obj=getattr(auto_class, type_name)
31        if class_obj==None:
32            return
33        #if sizeof(class_obj)!=size:
34        #    return
35        obj = parse_memory_2_class(addr,class_obj,sizeof(class_obj))
36        if(obj):
37            uapi_print_ctypes_obj(name,obj,fd=result_fp)
38            print('',file=result_fp)
39
40def _process_g_array_item(name,addr,class_obj,result_fp):
41    pass
42
43def _process_g_array(list,result_fp):
44    name=list[0].strip()
45    addr=int(list[1],16)
46    size=list[2]
47    type_name=list[3].strip()
48    str=list[4].strip()
49    array_list=json.loads(str)
50
51    if hasattr(auto_class, type_name):
52        class_obj=getattr(auto_class, type_name)
53        if class_obj==None:
54            return
55        for n in array_list[::-1]:
56            class_obj=class_obj*n
57        if sizeof(class_obj)!=size:
58            return
59        obj = parse_memory_2_class(addr,class_obj,sizeof(class_obj))
60        if(obj):
61            uapi_print_ctypes_obj(name,obj,fd=result_fp)
62            print('',file=result_fp)
63
64def _process_lines(lines,result_fp):
65    print("----------------------content of 全局变量:----------------------",file=result_fp)
66    for line in lines:
67        line=line.strip()
68        list=line.split('|')
69        if len(list)==4:
70            _process_g_var(list,result_fp)
71        elif len(list)==5:
72            _process_g_array(list,result_fp)
73
74def parse_print_global_var(var_file,result_fp):
75    with open(var_file,'r') as fp:
76        lines=fp.readlines()
77        _process_lines(lines,result_fp)
78    print("parse_print_global_var end!")
79
80
81