You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/03/24 15:34:05 UTC

[GitHub] [incubator-nuttx] pkarashchenko commented on a change in pull request #5836: tools:use dump log creat a gdbsever to debug

pkarashchenko commented on a change in pull request #5836:
URL: https://github.com/apache/incubator-nuttx/pull/5836#discussion_r834444659



##########
File path: tools/minidumpserver.py
##########
@@ -0,0 +1,530 @@
+#!/usr/bin/env python3
+# tools/minidumpserver.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 binascii
+import logging
+import os
+import re
+import socket
+import struct
+import sys
+
+import elftools
+from elftools.elf.elffile import ELFFile
+
+# ELF section flags
+SHF_WRITE = 0x1
+SHF_ALLOC = 0x2
+SHF_EXEC = 0x4
+SHF_WRITE_ALLOC = SHF_WRITE | SHF_ALLOC
+SHF_ALLOC_EXEC = SHF_ALLOC | SHF_EXEC
+
+
+logger = logging.getLogger()
+
+
+class dump_elf_file:
+    """
+    Class to parse ELF file for memory content in various sections.
+    There are read-only sections (e.g. text and rodata) where
+    the memory content does not need to be dumped via coredump
+    and can be retrived from the ELF file.
+    """
+
+    def __init__(self, elffile):
+        self.elffile = elffile
+        self.fd = None
+        self.elf = None
+        self.memories = list()
+
+    def open(self):
+        self.fd = open(self.elffile, "rb")
+        self.elf = ELFFile(self.fd)
+
+    def close(self):
+        self.fd.close()
+
+    def parse(self):
+        if self.fd is None:
+            self.open()
+
+        for section in self.elf.iter_sections():
+            # REALLY NEED to match exact type as all other sections
+            # (debug, text, etc.) are descendants where
+            # isinstance() would match.
+            if (
+                type(section) is not elftools.elf.sections.Section
+            ):  # pylint: disable=unidiomatic-typecheck
+                continue
+
+            size = section["sh_size"]
+            flags = section["sh_flags"]
+            start = section["sh_addr"]
+            end = start + size - 1
+
+            store = False
+            desc = "?"
+
+            if section["sh_type"] == "SHT_PROGBITS":
+                if (flags & SHF_ALLOC_EXEC) == SHF_ALLOC_EXEC:
+                    # Text section
+                    store = True
+                    desc = "text"
+                elif (flags & SHF_WRITE_ALLOC) == SHF_WRITE_ALLOC:
+                    # Data section
+                    #
+                    # Running app changes the content so no need
+                    # to store
+                    pass
+                elif (flags & SHF_ALLOC) == SHF_ALLOC:
+                    # Read only data section
+                    store = True
+                    desc = "read-only data"
+
+            if store:
+                memory = {"start": start, "end": end, "data": section.data()}
+                logger.info(
+                    "ELF Section: 0x%x to 0x%x of size %d (%s)"
+                    % (memory["start"], memory["end"], len(memory["data"]), desc)
+                )
+
+                self.memories.append(memory)
+
+        return True
+
+
+reg_table = {
+    "arm": {
+        "R0": 0,
+        "R1": 1,
+        "R2": 2,
+        "R3": 3,
+        "R4": 4,
+        "R5": 5,
+        "R6": 6,
+        "FP": 7,
+        "R8": 8,
+        "SB": 9,
+        "SL": 10,
+        "R11": 11,
+        "IP": 12,
+        "SP": 13,
+        "LR": 14,
+        "SL": 10,
+        "R11": 11,
+        "IP": 12,
+        "SP": 13,
+        "LR": 14,
+        "SL": 10,
+        "R11": 11,
+        "IP": 12,
+        "SP": 13,
+        "LR": 14,

Review comment:
       why do we need to have those lines repeated 3 times?




-- 
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