Author: Med Ismail Bennani Date: 2023-08-11T23:59:42-07:00 New Revision: 75bed9655a54c82e0485b28026605cb8e1f7c78a
URL: https://github.com/llvm/llvm-project/commit/75bed9655a54c82e0485b28026605cb8e1f7c78a DIFF: https://github.com/llvm/llvm-project/commit/75bed9655a54c82e0485b28026605cb8e1f7c78a.diff LOG: [lldb/crashlog] Fix sticky image parsing logic 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 Differential Revision: https://reviews.llvm.org/D157044 Signed-off-by: Med Ismail Bennani <ism...@bennani.ma> Added: Modified: lldb/examples/python/crashlog.py lldb/examples/python/symbolication.py Removed: ################################################################################ diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py index 869d055a5812e3..1413c702f9163f 100755 --- a/lldb/examples/python/crashlog.py +++ b/lldb/examples/python/crashlog.py @@ -549,8 +549,6 @@ def create(debugger, path, options): def __init__(self, debugger, path, options): self.path = os.path.expanduser(path) self.options = options - # List of DarwinImages sorted by their index. - self.images = list() self.crashlog = CrashLog(debugger, self.path, self.options.verbose) @abc.abstractmethod @@ -645,7 +643,6 @@ def parse_images(self, json_images): 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): @@ -672,7 +669,7 @@ def parse_frames(self, thread, json_frames): 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", @@ -780,7 +777,7 @@ def parse_asi_backtrace(self, thread, bt): if frame_offset: description += " + " + frame_offset frame_offset_value = int(frame_offset, 0) - for image in self.images: + for image in self.crashlog.images: if image.identifier == frame_img_name: image.symbols[frame_symbol] = { "name": frame_symbol, @@ -829,6 +826,7 @@ def parse_errors(self, json_data): if "reportNotes" in json_data: self.crashlog.errors = json_data["reportNotes"] + class TextCrashLogParser(CrashLogParser): parent_process_regex = re.compile(r"^Parent Process:\s*(.*)\[(\d+)\]") thread_state_regex = re.compile(r"^Thread \d+ crashed with") @@ -888,7 +886,6 @@ def get(cls): ) exception_extra_regex = re.compile(r"^Exception\s+.*:\s+(.*)") - class CrashLogParseMode: NORMAL = 0 THREAD = 1 @@ -1209,7 +1206,6 @@ def parse_images(self, line): "address": symbol["address"] - int(img_lo, 0), } - self.images.append(image) self.crashlog.images.append(image) return True else: diff --git a/lldb/examples/python/symbolication.py b/lldb/examples/python/symbolication.py index 736ad5c794451d..467675e1d98453 100755 --- a/lldb/examples/python/symbolication.py +++ b/lldb/examples/python/symbolication.py @@ -501,7 +501,7 @@ def create_target(self, debugger): 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 @@ def __init__(self, debugger=None, target=None, images=list()): """ 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 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits