[Lldb-commits] [PATCH] D157044: [lldb/crashlog] Fix sticky image parsing logic

Med Ismail Bennani via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 3 15:07:35 PDT 2023


mib created this revision.
mib added reviewers: JDevlieghere, bulbazord.
mib added a project: LLDB.
Herald added a project: All.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

Prior to this patch, when a user loaded multiple crash report in lldb,
they could get in a situation where all the targets would keep the same
architecture and executable path as the first one that we've created.

The reason behind this was that even if we created a new CrashLog
object, which is derived from a Symbolicator class that has a newly
constructoted image list as a default argument, because that default
argument is only created once when the function is defined, every CrashLog
object would share the same list.

That will cause use to append newly parsed  images to the same
Symbolicator image list accross multiple CrashLog objects.

To address this, this patch changes the default argument value for the
image parameter to `None` and only initialize it as an empty list when
no argument was passed.

This also removes the image list stored in each CrashLog parsers since
they shouldn't have any state and should be re-usable. So now, the only
source of truth is stored in the CrashLog object.

rdar://84984949

Signed-off-by: Med Ismail Bennani <ismail at bennani.ma>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157044

Files:
  lldb/examples/python/crashlog.py
  lldb/examples/python/symbolication.py


Index: lldb/examples/python/symbolication.py
===================================================================
--- lldb/examples/python/symbolication.py
+++ lldb/examples/python/symbolication.py
@@ -501,7 +501,7 @@
 
 
 class Symbolicator:
-    def __init__(self, debugger=None, target=None, images=list()):
+    def __init__(self, debugger=None, target=None, images=None):
         """A class the represents the information needed to symbolicate
         addresses in a program.
 
@@ -510,7 +510,8 @@
         """
         self.debugger = debugger
         self.target = target
-        self.images = images  # a list of images to be used when symbolicating
+        # a list of images to be used when symbolicating
+        self.images = images if images else list()
         self.addr_mask = 0xFFFFFFFFFFFFFFFF
 
     @classmethod
Index: lldb/examples/python/crashlog.py
===================================================================
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -531,8 +531,6 @@
     def __init__(self, debugger, path, verbose):
         self.path = os.path.expanduser(path)
         self.verbose = verbose
-        # List of DarwinImages sorted by their index.
-        self.images = list()
         self.crashlog = CrashLog(debugger, self.path, self.verbose)
 
     @abc.abstractmethod
@@ -627,7 +625,6 @@
                 darwin_image.arch = json_image["arch"]
                 if path == self.crashlog.process_path:
                     self.crashlog.process_arch = darwin_image.arch
-            self.images.append(darwin_image)
             self.crashlog.images.append(darwin_image)
 
     def parse_main_image(self, json_data):
@@ -654,7 +651,7 @@
                 location = 0
                 if "symbolLocation" in json_frame and json_frame["symbolLocation"]:
                     location = int(json_frame["symbolLocation"])
-                image = self.images[image_id]
+                image = self.crashlog.images[image_id]
                 image.symbols[symbol] = {
                     "name": symbol,
                     "type": "code",
@@ -1197,7 +1194,6 @@
                         "address": symbol["address"] - int(img_lo, 0),
                     }
 
-            self.images.append(image)
             self.crashlog.images.append(image)
             return True
         else:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157044.547015.patch
Type: text/x-patch
Size: 2361 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230803/c34ef58c/attachment-0001.bin>


More information about the lldb-commits mailing list