[Lldb-commits] [PATCH] D157043: [lldb/crashlog] Make TextCrashLogParser more resilient to new lines

2023-08-12 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere reopened this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

Test?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157043/new/

https://reviews.llvm.org/D157043

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D157137: [lldb/crashlog] Skip images with empty path and 0 UUID from loading

2023-08-12 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere reopened this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

Test?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157137/new/

https://reviews.llvm.org/D157137

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D157764: [LLDB] Allow expression evaluators to set arbitrary timeouts

2023-08-12 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.

The motivation behind this change was that the IRInterpreter wasn't 
interruptible, which means that if you interpret an infinite loop, you'd be 
stuck forever. I fixed that in 61af957aeaa3 
 so I 
think that's less of a concern today. I'm fine with going back to allowing an 
infinite timeout as long as there's no code path in LLDB that sets it to zero 
by default.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157764/new/

https://reviews.llvm.org/D157764

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D157654: [lldb] Fix data race in PipePosix

2023-08-12 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157654/new/

https://reviews.llvm.org/D157654

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2023-08-12 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG75bed9655a54: [lldb/crashlog] Fix sticky image parsing logic 
(authored by mib).

Changed prior to commit:
  https://reviews.llvm.org/D157044?vs=547015&id=549579#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157044/new/

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 = 0x
 
 @classmethod
Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -549,8 +549,6 @@
 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 @@
 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 @@
 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 @@
 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 @@
 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 @@
 )
 exception_extra_regex = re.compile(r"^Exception\s+.*:\s+(.*)")
 
-
 class CrashLogParseMode:
 NORMAL = 0
 THREAD = 1
@@ -1209,7 +1206,6 @@
 "address": symbol["address"] - int(img_lo, 0),
 }
 
-self.images.append(image)
 self.crashlog.images.append(image)
 return True
 else:


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 = 0x
 
 @classmethod
Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -549,8 +549,6 @@
 def __init__(self, debugger, path, options):
 self.path = os.path.expanduser(path)
 self.options = options
-

[Lldb-commits] [PATCH] D157137: [lldb/crashlog] Skip images with empty path and 0 UUID from loading

2023-08-12 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG706e875da3a2: [lldb/crashlog] Skip images with empty path 
and 0 UUID from loading (authored by mib).

Changed prior to commit:
  https://reviews.llvm.org/D157137?vs=549560&id=549580#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157137/new/

https://reviews.llvm.org/D157137

Files:
  lldb/examples/python/symbolication.py


Index: lldb/examples/python/symbolication.py
===
--- lldb/examples/python/symbolication.py
+++ lldb/examples/python/symbolication.py
@@ -396,6 +396,9 @@
 
 def add_module(self, target, obj_dir=None):
 """Add the Image described in this object to "target" and load the 
sections if "load" is True."""
+if not self.path and self.uuid == uuid.UUID(int=0):
+return "error: invalid image"
+
 if target:
 # Try and find using UUID only first so that paths need not match
 # up


Index: lldb/examples/python/symbolication.py
===
--- lldb/examples/python/symbolication.py
+++ lldb/examples/python/symbolication.py
@@ -396,6 +396,9 @@
 
 def add_module(self, target, obj_dir=None):
 """Add the Image described in this object to "target" and load the sections if "load" is True."""
+if not self.path and self.uuid == uuid.UUID(int=0):
+return "error: invalid image"
+
 if target:
 # Try and find using UUID only first so that paths need not match
 # up
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156919: [lldb/crashlog] Make register output match lldb ordering in legacy mode

2023-08-12 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf043e66e9883: [lldb/crashlog] Make register output match 
lldb ordering in legacy mode (authored by mib).

Changed prior to commit:
  https://reviews.llvm.org/D156919?vs=547010&id=549577#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156919/new/

https://reviews.llvm.org/D156919

Files:
  lldb/examples/python/crashlog.py

Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -71,6 +71,7 @@
 sys.exit(1)
 
 from lldb.utils import symbolication
+from lldb.plugins.scripted_process import INTEL64_GPR, ARM64_GPR
 
 
 def read_plist(s):
@@ -84,7 +85,7 @@
 class Thread:
 """Class that represents a thread in a darwin crash log"""
 
-def __init__(self, index, app_specific_backtrace):
+def __init__(self, index, app_specific_backtrace, arch):
 self.index = index
 self.id = index
 self.images = list()
@@ -96,8 +97,56 @@
 self.queue = None
 self.crashed = False
 self.app_specific_backtrace = app_specific_backtrace
+self.arch = arch
+
+def dump_registers(self, prefix=""):
+registers_info = None
+sorted_registers = {}
+
+def sort_dict(d):
+sorted_keys = list(d.keys())
+sorted_keys.sort()
+return {k: d[k] for k in sorted_keys}
+
+if self.arch:
+if "x86_64" == self.arch:
+registers_info = INTEL64_GPR
+elif "arm64" in self.arch:
+registers_info = ARM64_GPR
+else:
+print("unknown target architecture: %s" % self.arch)
+return
 
-def dump(self, prefix):
+# Add registers available in the register information dictionary.
+for reg_info in registers_info:
+reg_name = None
+if reg_info["name"] in self.registers:
+reg_name = reg_info["name"]
+elif (
+"generic" in reg_info and reg_info["generic"] in self.registers
+):
+reg_name = reg_info["generic"]
+else:
+# Skip register that are present in the register information dictionary but not present in the report.
+continue
+
+reg_val = self.registers[reg_name]
+sorted_registers[reg_name] = reg_val
+
+unknown_parsed_registers = {}
+for reg_name in self.registers:
+if reg_name not in sorted_registers:
+unknown_parsed_registers[reg_name] = self.registers[reg_name]
+
+sorted_registers.update(sort_dict(unknown_parsed_registers))
+
+else:
+sorted_registers = sort_dict(self.registers)
+
+for reg_name, reg_val in sorted_registers.items():
+print("%s%-8s = %#16.16x" % (prefix, reg_name, reg_val))
+
+def dump(self, prefix=""):
 if self.app_specific_backtrace:
 print(
 "%Application Specific Backtrace[%u] %s"
@@ -111,8 +160,7 @@
 frame.dump(prefix + "")
 if self.registers:
 print("%s  Registers:" % (prefix))
-for reg in self.registers.keys():
-print("%s%-8s = %#16.16x" % (prefix, reg, self.registers[reg]))
+self.dump_registers(prefix)
 
 def dump_symbolicated(self, crash_log, options):
 this_thread_crashed = self.app_specific_backtrace
@@ -194,8 +242,7 @@
 print(frame)
 if self.registers:
 print()
-for reg in self.registers.keys():
-print("%-8s = %#16.16x" % (reg, self.registers[reg]))
+self.dump_registers()
 elif self.crashed:
 print()
 print("No thread state (register information) available")
@@ -655,7 +702,7 @@
 def parse_threads(self, json_threads):
 idx = 0
 for json_thread in json_threads:
-thread = self.crashlog.Thread(idx, False)
+thread = self.crashlog.Thread(idx, False, self.crashlog.process_arch)
 if "name" in json_thread:
 thread.name = json_thread["name"]
 thread.reason = json_thread["name"]
@@ -749,7 +796,7 @@
 
 def parse_app_specific_backtraces(self, json_app_specific_bts):
 for idx, backtrace in enumerate(json_app_specific_bts):
-thread = self.crashlog.Thread(idx, True)
+thread 

[Lldb-commits] [PATCH] D157043: [lldb/crashlog] Make TextCrashLogParser more resilient to new lines

2023-08-12 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8f75c4d01eff: [lldb/crashlog] Make TextCrashLogParser more 
resilient to new lines (authored by mib).

Changed prior to commit:
  https://reviews.llvm.org/D157043?vs=547013&id=549578#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157043/new/

https://reviews.llvm.org/D157043

Files:
  lldb/examples/python/crashlog.py

Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -537,21 +537,21 @@
 
 class CrashLogParser:
 @staticmethod
-def create(debugger, path, verbose):
+def create(debugger, path, options):
 data = JSONCrashLogParser.is_valid_json(path)
 if data:
-parser = JSONCrashLogParser(debugger, path, verbose)
+parser = JSONCrashLogParser(debugger, path, options)
 parser.data = data
 return parser
 else:
-return TextCrashLogParser(debugger, path, verbose)
+return TextCrashLogParser(debugger, path, options)
 
-def __init__(self, debugger, path, verbose):
+def __init__(self, debugger, path, options):
 self.path = os.path.expanduser(path)
-self.verbose = verbose
+self.options = options
 # List of DarwinImages sorted by their index.
 self.images = list()
-self.crashlog = CrashLog(debugger, self.path, self.verbose)
+self.crashlog = CrashLog(debugger, self.path, self.options.verbose)
 
 @abc.abstractmethod
 def parse(self):
@@ -577,8 +577,8 @@
 except:
 return None
 
-def __init__(self, debugger, path, verbose):
-super().__init__(debugger, path, verbose)
+def __init__(self, debugger, path, options):
+super().__init__(debugger, path, options)
 
 def parse(self):
 try:
@@ -639,7 +639,7 @@
 path = json_image["path"] if "path" in json_image else ""
 version = ""
 darwin_image = self.crashlog.DarwinImage(
-low, high, name, version, img_uuid, path, self.verbose
+low, high, name, version, img_uuid, path, self.options.verbose
 )
 if "arch" in json_image:
 darwin_image.arch = json_image["arch"]
@@ -898,8 +898,8 @@
 )
 exception_extra_regex = re.compile(r"^Exception\s+.*:\s+(.*)")
 
-def __init__(self, debugger, path, verbose):
-super().__init__(debugger, path, verbose)
+def __init__(self, debugger, path, options):
+super().__init__(debugger, path, options)
 self.thread = None
 self.app_specific_backtrace = False
 self.parse_mode = CrashLogParseMode.NORMAL
@@ -917,8 +917,15 @@
 with open(self.path, "r", encoding="utf-8") as f:
 lines = f.read().splitlines()
 
-for line in lines:
+idx = 0
+lines_count = len(lines)
+while True:
+if idx >= lines_count:
+break
+
+line = lines[idx]
 line_len = len(line)
+
 if line_len == 0:
 if self.thread:
 if self.parse_mode == CrashLogParseMode.THREAD:
@@ -935,22 +942,36 @@
 else:
 self.crashlog.threads.append(self.thread)
 self.thread = None
-else:
-# only append an extra empty line if the previous line
-# in the info_lines wasn't empty
-if len(self.crashlog.info_lines) > 0 and len(
-self.crashlog.info_lines[-1]
-):
-self.crashlog.info_lines.append(line)
+
+empty_lines = 1
+while (
+idx + empty_lines < lines_count
+and len(lines[idx + empty_lines]) == 0
+):
+empty_lines = empty_lines + 1
+
+if (
+empty_lines == 1
+and idx + empty_lines < lines_count - 1
+and self.parse_mode != CrashLogParseMode.NORMAL
+):
+# check if next line can be parsed with the current parse mode
+next_line_idx = idx + empty_lines
+if self.parsers[self.parse_mode](lines[next_line_idx]):
+# If that suceeded, skip the empty line and the next line.
+idx = next_line_idx + 1
+continue
 self.parse_mode = CrashLogParseMode.NORMAL
-else:
-self.parsers[self.parse_mode](line)
+
+self.parsers[self.parse_mode](line)
+
+idx = idx + 1
 
 return self.crashlog
 
 def parse_exception(self, line):
 

[Lldb-commits] [lldb] 706e875 - [lldb/crashlog] Skip images with empty path and 0 UUID from loading

2023-08-12 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-08-11T23:59:42-07:00
New Revision: 706e875da3a21f2d6ba612ca991dbdbccb339327

URL: 
https://github.com/llvm/llvm-project/commit/706e875da3a21f2d6ba612ca991dbdbccb339327
DIFF: 
https://github.com/llvm/llvm-project/commit/706e875da3a21f2d6ba612ca991dbdbccb339327.diff

LOG: [lldb/crashlog] Skip images with empty path and 0 UUID from loading

This patch skips images with an empty path or a 0 UUID from loading as a
SymbolFileJSON.

rdar://112107986

Differential Revision: https://reviews.llvm.org/D157137

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/examples/python/symbolication.py

Removed: 




diff  --git a/lldb/examples/python/symbolication.py 
b/lldb/examples/python/symbolication.py
index 467675e1d98453..f6dcc8b9a79437 100755
--- a/lldb/examples/python/symbolication.py
+++ b/lldb/examples/python/symbolication.py
@@ -396,6 +396,9 @@ def load_module(self, target):
 
 def add_module(self, target, obj_dir=None):
 """Add the Image described in this object to "target" and load the 
sections if "load" is True."""
+if not self.path and self.uuid == uuid.UUID(int=0):
+return "error: invalid image"
+
 if target:
 # Try and find using UUID only first so that paths need not match
 # up



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 75bed96 - [lldb/crashlog] Fix sticky image parsing logic

2023-08-12 Thread Med Ismail Bennani via lldb-commits

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 

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

[Lldb-commits] [lldb] 4677041 - [lldb/crashlog] Move CrashLogParseMode into TextCrashLogParser (NFC)

2023-08-12 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-08-11T23:59:42-07:00
New Revision: 4677041d61dbe929e886649a97e4d3f49572b0ca

URL: 
https://github.com/llvm/llvm-project/commit/4677041d61dbe929e886649a97e4d3f49572b0ca
DIFF: 
https://github.com/llvm/llvm-project/commit/4677041d61dbe929e886649a97e4d3f49572b0ca.diff

LOG: [lldb/crashlog] Move CrashLogParseMode into TextCrashLogParser (NFC)

This patch moves CrashLogParseMode into TextCrashLogParser since it's
the only class using it.

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/examples/python/crashlog.py

Removed: 




diff  --git a/lldb/examples/python/crashlog.py 
b/lldb/examples/python/crashlog.py
index 7f1a43b435689f..869d055a5812e3 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -829,16 +829,6 @@ def parse_errors(self, json_data):
 if "reportNotes" in json_data:
 self.crashlog.errors = json_data["reportNotes"]
 
-
-class CrashLogParseMode:
-NORMAL = 0
-THREAD = 1
-IMAGES = 2
-THREGS = 3
-SYSTEM = 4
-INSTRS = 5
-
-
 class TextCrashLogParser(CrashLogParser):
 parent_process_regex = re.compile(r"^Parent Process:\s*(.*)\[(\d+)\]")
 thread_state_regex = re.compile(r"^Thread \d+ crashed with")
@@ -898,18 +888,27 @@ def get(cls):
 )
 exception_extra_regex = re.compile(r"^Exception\s+.*:\s+(.*)")
 
+
+class CrashLogParseMode:
+NORMAL = 0
+THREAD = 1
+IMAGES = 2
+THREGS = 3
+SYSTEM = 4
+INSTRS = 5
+
 def __init__(self, debugger, path, options):
 super().__init__(debugger, path, options)
 self.thread = None
 self.app_specific_backtrace = False
-self.parse_mode = CrashLogParseMode.NORMAL
+self.parse_mode = self.CrashLogParseMode.NORMAL
 self.parsers = {
-CrashLogParseMode.NORMAL: self.parse_normal,
-CrashLogParseMode.THREAD: self.parse_thread,
-CrashLogParseMode.IMAGES: self.parse_images,
-CrashLogParseMode.THREGS: self.parse_thread_registers,
-CrashLogParseMode.SYSTEM: self.parse_system,
-CrashLogParseMode.INSTRS: self.parse_instructions,
+self.CrashLogParseMode.NORMAL: self.parse_normal,
+self.CrashLogParseMode.THREAD: self.parse_thread,
+self.CrashLogParseMode.IMAGES: self.parse_images,
+self.CrashLogParseMode.THREGS: self.parse_thread_registers,
+self.CrashLogParseMode.SYSTEM: self.parse_system,
+self.CrashLogParseMode.INSTRS: self.parse_instructions,
 }
 self.symbols = {}
 
@@ -928,7 +927,7 @@ def parse(self):
 
 if line_len == 0:
 if self.thread:
-if self.parse_mode == CrashLogParseMode.THREAD:
+if self.parse_mode == self.CrashLogParseMode.THREAD:
 if self.thread.index == 
self.crashlog.crashed_thread_idx:
 self.thread.reason = ""
 if hasattr(self.crashlog, "thread_exception"):
@@ -953,7 +952,7 @@ def parse(self):
 if (
 empty_lines == 1
 and idx + empty_lines < lines_count - 1
-and self.parse_mode != CrashLogParseMode.NORMAL
+and self.parse_mode != self.CrashLogParseMode.NORMAL
 ):
 # check if next line can be parsed with the current parse 
mode
 next_line_idx = idx + empty_lines
@@ -961,7 +960,7 @@ def parse(self):
 # If that suceeded, skip the empty line and the next 
line.
 idx = next_line_idx + 1
 continue
-self.parse_mode = CrashLogParseMode.NORMAL
+self.parse_mode = self.CrashLogParseMode.NORMAL
 
 self.parsers[self.parse_mode](line)
 
@@ -1047,7 +1046,7 @@ def parse_normal(self, line):
 self.crashlog.version = int(line[15:].strip())
 return
 elif line.startswith("System Profile:"):
-self.parse_mode = CrashLogParseMode.SYSTEM
+self.parse_mode = self.CrashLogParseMode.SYSTEM
 return
 elif (
 line.startswith("Interval Since Last Report:")
@@ -1065,17 +1064,17 @@ def parse_normal(self, line):
 self.app_specific_backtrace = False
 thread_state_match = self.thread_regex.search(line)
 thread_idx = int(thread_state_match.group(1))
-self.parse_mode = CrashLogParseMode.THREGS
+self.parse_mode = self.CrashLogParseMode.THREGS
 self.thread = self.crashlog.threads[thread_idx]
 return
 thread_insts_match = self.thread_instrs_regex.search(line)
 if thread_insts_match:
-   

[Lldb-commits] [lldb] 8f75c4d - [lldb/crashlog] Make TextCrashLogParser more resilient to new lines

2023-08-12 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-08-11T23:59:42-07:00
New Revision: 8f75c4d01eff3c65d7ae40bfd05582de7dffa590

URL: 
https://github.com/llvm/llvm-project/commit/8f75c4d01eff3c65d7ae40bfd05582de7dffa590
DIFF: 
https://github.com/llvm/llvm-project/commit/8f75c4d01eff3c65d7ae40bfd05582de7dffa590.diff

LOG: [lldb/crashlog] Make TextCrashLogParser more resilient to new lines

This patch changes the parsing logic for the legacy crash report format
to avoid interrupting the parsing if there are new lines in the middle
of a section.

To do, the parser starts to skip all consecutive empty lines. If the
number of lines skipped is greater than 1, the parser considers that it
reached a new setion of the report and should reset the parsing mode to
back to normal.

Otherwise, it tries to parse the next line in the current parsing mode.
If it succeeds, the parser will also skip that line since it has already
been parsed and continue the parsing.

rdar://107022595

Differential Revision: https://reviews.llvm.org/D157043

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/examples/python/crashlog.py

Removed: 




diff  --git a/lldb/examples/python/crashlog.py 
b/lldb/examples/python/crashlog.py
index ccf3fb1aa9146a..7f1a43b435689f 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -537,21 +537,21 @@ class InteractiveCrashLogException(Exception):
 
 class CrashLogParser:
 @staticmethod
-def create(debugger, path, verbose):
+def create(debugger, path, options):
 data = JSONCrashLogParser.is_valid_json(path)
 if data:
-parser = JSONCrashLogParser(debugger, path, verbose)
+parser = JSONCrashLogParser(debugger, path, options)
 parser.data = data
 return parser
 else:
-return TextCrashLogParser(debugger, path, verbose)
+return TextCrashLogParser(debugger, path, options)
 
-def __init__(self, debugger, path, verbose):
+def __init__(self, debugger, path, options):
 self.path = os.path.expanduser(path)
-self.verbose = verbose
+self.options = options
 # List of DarwinImages sorted by their index.
 self.images = list()
-self.crashlog = CrashLog(debugger, self.path, self.verbose)
+self.crashlog = CrashLog(debugger, self.path, self.options.verbose)
 
 @abc.abstractmethod
 def parse(self):
@@ -577,8 +577,8 @@ def parse_json(buffer):
 except:
 return None
 
-def __init__(self, debugger, path, verbose):
-super().__init__(debugger, path, verbose)
+def __init__(self, debugger, path, options):
+super().__init__(debugger, path, options)
 
 def parse(self):
 try:
@@ -639,7 +639,7 @@ def parse_images(self, json_images):
 path = json_image["path"] if "path" in json_image else ""
 version = ""
 darwin_image = self.crashlog.DarwinImage(
-low, high, name, version, img_uuid, path, self.verbose
+low, high, name, version, img_uuid, path, self.options.verbose
 )
 if "arch" in json_image:
 darwin_image.arch = json_image["arch"]
@@ -898,8 +898,8 @@ def get(cls):
 )
 exception_extra_regex = re.compile(r"^Exception\s+.*:\s+(.*)")
 
-def __init__(self, debugger, path, verbose):
-super().__init__(debugger, path, verbose)
+def __init__(self, debugger, path, options):
+super().__init__(debugger, path, options)
 self.thread = None
 self.app_specific_backtrace = False
 self.parse_mode = CrashLogParseMode.NORMAL
@@ -917,8 +917,15 @@ def parse(self):
 with open(self.path, "r", encoding="utf-8") as f:
 lines = f.read().splitlines()
 
-for line in lines:
+idx = 0
+lines_count = len(lines)
+while True:
+if idx >= lines_count:
+break
+
+line = lines[idx]
 line_len = len(line)
+
 if line_len == 0:
 if self.thread:
 if self.parse_mode == CrashLogParseMode.THREAD:
@@ -935,22 +942,36 @@ def parse(self):
 else:
 self.crashlog.threads.append(self.thread)
 self.thread = None
-else:
-# only append an extra empty line if the previous line
-# in the info_lines wasn't empty
-if len(self.crashlog.info_lines) > 0 and len(
-self.crashlog.info_lines[-1]
-):
-self.crashlog.info_lines.append(line)
+
+empty_lines = 1
+while (
+idx + empty_lines < lines_count
+and len(lines[idx + empty_lines]) == 0
+):
+

[Lldb-commits] [lldb] f043e66 - [lldb/crashlog] Make register output match lldb ordering in legacy mode

2023-08-12 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-08-11T23:59:41-07:00
New Revision: f043e66e98836e3acf3c978fd0dc429f74b228da

URL: 
https://github.com/llvm/llvm-project/commit/f043e66e98836e3acf3c978fd0dc429f74b228da
DIFF: 
https://github.com/llvm/llvm-project/commit/f043e66e98836e3acf3c978fd0dc429f74b228da.diff

LOG: [lldb/crashlog] Make register output match lldb ordering in legacy mode

This patch changes the way we dump the registers from the legacy
crashlog command to make sure that the ordering matches the one from lldb.

rdar://109172073

Differential Revision: https://reviews.llvm.org/D156919

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/examples/python/crashlog.py

Removed: 




diff  --git a/lldb/examples/python/crashlog.py 
b/lldb/examples/python/crashlog.py
index 709dda714eb346..ccf3fb1aa9146a 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -71,6 +71,7 @@
 sys.exit(1)
 
 from lldb.utils import symbolication
+from lldb.plugins.scripted_process import INTEL64_GPR, ARM64_GPR
 
 
 def read_plist(s):
@@ -84,7 +85,7 @@ class CrashLog(symbolication.Symbolicator):
 class Thread:
 """Class that represents a thread in a darwin crash log"""
 
-def __init__(self, index, app_specific_backtrace):
+def __init__(self, index, app_specific_backtrace, arch):
 self.index = index
 self.id = index
 self.images = list()
@@ -96,8 +97,56 @@ def __init__(self, index, app_specific_backtrace):
 self.queue = None
 self.crashed = False
 self.app_specific_backtrace = app_specific_backtrace
+self.arch = arch
+
+def dump_registers(self, prefix=""):
+registers_info = None
+sorted_registers = {}
+
+def sort_dict(d):
+sorted_keys = list(d.keys())
+sorted_keys.sort()
+return {k: d[k] for k in sorted_keys}
+
+if self.arch:
+if "x86_64" == self.arch:
+registers_info = INTEL64_GPR
+elif "arm64" in self.arch:
+registers_info = ARM64_GPR
+else:
+print("unknown target architecture: %s" % self.arch)
+return
 
-def dump(self, prefix):
+# Add registers available in the register information 
dictionary.
+for reg_info in registers_info:
+reg_name = None
+if reg_info["name"] in self.registers:
+reg_name = reg_info["name"]
+elif (
+"generic" in reg_info and reg_info["generic"] in 
self.registers
+):
+reg_name = reg_info["generic"]
+else:
+# Skip register that are present in the register 
information dictionary but not present in the report.
+continue
+
+reg_val = self.registers[reg_name]
+sorted_registers[reg_name] = reg_val
+
+unknown_parsed_registers = {}
+for reg_name in self.registers:
+if reg_name not in sorted_registers:
+unknown_parsed_registers[reg_name] = 
self.registers[reg_name]
+
+sorted_registers.update(sort_dict(unknown_parsed_registers))
+
+else:
+sorted_registers = sort_dict(self.registers)
+
+for reg_name, reg_val in sorted_registers.items():
+print("%s%-8s = %#16.16x" % (prefix, reg_name, reg_val))
+
+def dump(self, prefix=""):
 if self.app_specific_backtrace:
 print(
 "%Application Specific Backtrace[%u] %s"
@@ -111,8 +160,7 @@ def dump(self, prefix):
 frame.dump(prefix + "")
 if self.registers:
 print("%s  Registers:" % (prefix))
-for reg in self.registers.keys():
-print("%s%-8s = %#16.16x" % (prefix, reg, 
self.registers[reg]))
+self.dump_registers(prefix)
 
 def dump_symbolicated(self, crash_log, options):
 this_thread_crashed = self.app_specific_backtrace
@@ -194,8 +242,7 @@ def dump_symbolicated(self, crash_log, options):
 print(frame)
 if self.registers:
 print()
-for reg in self.registers.keys():
-print("%-8s = %#16.16x" % (reg, self.registers[reg]))
+self.dump_registers()
 elif self.crashed:
 print()
 print("No thread state (register information) available")
@@ -655,7 +702,7 @@ def parse_frames(self, thread, json_frames):
 def parse_threads(self, json_threads):