You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "xiaoxiang781216 (via GitHub)" <gi...@apache.org> on 2023/02/13 06:55:12 UTC

[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #8515: tools: Extract a valid trace line and resolve the address to a function name

xiaoxiang781216 commented on code in PR #8515:
URL: https://github.com/apache/nuttx/pull/8515#discussion_r1104051559


##########
tools/parsetrace.py:
##########
@@ -0,0 +1,202 @@
+#!python3
+############################################################################
+# tools/parsetrace.py
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you 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 argparse
+import bisect
+import os
+import re
+from typing import Union
+
+import cxxfilt
+import parse
+from elftools.elf.elffile import ELFFile
+from elftools.elf.sections import SymbolTableSection
+from pydantic import BaseModel
+
+
+class SymbolTables(object):
+    def __init__(self, file):
+        elffile = open(file, "rb")
+        self.elffile = ELFFile(elffile)
+        self.symbol_dict = dict()
+        self.addr_list = list()
+
+    def __symbol_filter(self, symbol):
+        if symbol["st_info"]["type"] != "STT_FUNC":
+            return None
+        if symbol["st_info"]["bind"] == "STB_WEAK":
+            return None
+        if symbol["st_shndx"] == "SHN_UNDEF":
+            return None
+        return symbol
+
+    def __get_symtable(self):
+        symbol_tables = [
+            (idx, s)
+            for idx, s in enumerate(self.elffile.iter_sections())
+            if isinstance(s, SymbolTableSection)
+        ]
+
+        if not symbol_tables and self.elffile.num_sections() == 0:

Review Comment:
   why need check num_sections



##########
tools/parsetrace.py:
##########
@@ -0,0 +1,202 @@
+#!python3
+############################################################################
+# tools/parsetrace.py
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you 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 argparse
+import bisect
+import os
+import re
+from typing import Union
+
+import cxxfilt
+import parse
+from elftools.elf.elffile import ELFFile
+from elftools.elf.sections import SymbolTableSection
+from pydantic import BaseModel
+
+
+class SymbolTables(object):
+    def __init__(self, file):
+        elffile = open(file, "rb")
+        self.elffile = ELFFile(elffile)
+        self.symbol_dict = dict()
+        self.addr_list = list()
+
+    def __symbol_filter(self, symbol):
+        if symbol["st_info"]["type"] != "STT_FUNC":
+            return None
+        if symbol["st_info"]["bind"] == "STB_WEAK":
+            return None
+        if symbol["st_shndx"] == "SHN_UNDEF":
+            return None
+        return symbol
+
+    def __get_symtable(self):
+        symbol_tables = [
+            (idx, s)
+            for idx, s in enumerate(self.elffile.iter_sections())
+            if isinstance(s, SymbolTableSection)
+        ]
+
+        if not symbol_tables and self.elffile.num_sections() == 0:
+            return
+
+        for section_index, section in symbol_tables:
+            if not isinstance(section, SymbolTableSection):

Review Comment:
   why check again



##########
tools/parsetrace.py:
##########
@@ -0,0 +1,202 @@
+#!python3
+############################################################################
+# tools/parsetrace.py
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you 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 argparse
+import bisect
+import os
+import re
+from typing import Union
+
+import cxxfilt
+import parse
+from elftools.elf.elffile import ELFFile
+from elftools.elf.sections import SymbolTableSection
+from pydantic import BaseModel
+
+
+class SymbolTables(object):
+    def __init__(self, file):
+        elffile = open(file, "rb")
+        self.elffile = ELFFile(elffile)
+        self.symbol_dict = dict()
+        self.addr_list = list()
+
+    def __symbol_filter(self, symbol):
+        if symbol["st_info"]["type"] != "STT_FUNC":
+            return None
+        if symbol["st_info"]["bind"] == "STB_WEAK":
+            return None
+        if symbol["st_shndx"] == "SHN_UNDEF":
+            return None
+        return symbol
+
+    def __get_symtable(self):
+        symbol_tables = [
+            (idx, s)
+            for idx, s in enumerate(self.elffile.iter_sections())
+            if isinstance(s, SymbolTableSection)
+        ]
+
+        if not symbol_tables and self.elffile.num_sections() == 0:
+            return
+
+        for section_index, section in symbol_tables:
+            if not isinstance(section, SymbolTableSection):
+                continue
+
+            if section["sh_entsize"] == 0 or section.name != ".symtab":

Review Comment:
   why not check at line 55 too



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org