Skip to content

crashlog.py: Improve regular expressions #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions lldb/examples/python/crashlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,22 @@ class CrashLog(symbolication.Symbolicator):
thread_regex = re.compile('^Thread ([0-9]+)([^:]*):(.*)')
app_backtrace_regex = re.compile(
'^Application Specific Backtrace ([0-9]+)([^:]*):(.*)')
frame_regex = re.compile('^([0-9]+)\s+(.+?)\s+(0x[0-9a-fA-F]{7}[0-9a-fA-F]+) +(.*)')
null_frame_regex = re.compile('^([0-9]+)\s+\?\?\?\s+(0{7}0+) +(.*)')
image_regex_uuid = re.compile(
'(0x[0-9a-fA-F]+)[-\s]+(0x[0-9a-fA-F]+)\s+[+]?(.+?)\s+(\(.+\))?\s?(<([-0-9a-fA-F]+)>)? (.*)')
version = r'(\(.+\)|(arm|x86_)[0-9a-z]+)\s+'
frame_regex = re.compile(r'^([0-9]+)' r'\s' # id
r'+(.+?)' r'\s+' # img_name
r'(' +version+ r')?' # img_version
r'(0x[0-9a-fA-F]{7}[0-9a-fA-F]+)' # addr
r' +(.*)' # offs
)
null_frame_regex = re.compile(r'^([0-9]+)\s+\?\?\?\s+(0{7}0+) +(.*)')
image_regex_uuid = re.compile(r'(0x[0-9a-fA-F]+)' # img_lo
r'\s+' '-' r'\s+' # -
r'(0x[0-9a-fA-F]+)' r'\s+' # img_hi
r'[+]?(.+?)' r'\s+' # img_name
r'(' +version+ ')?' # img_version
r'(<([-0-9a-fA-F]+)>\s+)?' # img_uuid
r'(/.*)' # img_path
)
empty_line_regex = re.compile('^$')

class Thread:
Expand Down Expand Up @@ -489,18 +501,20 @@ def __init__(self, path, verbose):
continue
frame_match = self.frame_regex.search(line)
if frame_match:
ident = frame_match.group(2)
(frame_id, frame_img_name, _, frame_img_version, _,
frame_addr, frame_ofs) = frame_match.groups()
ident = frame_img_name
thread.add_ident(ident)
if ident not in self.idents:
self.idents.append(ident)
thread.frames.append(CrashLog.Frame(int(frame_match.group(1)), int(
frame_match.group(3), 0), frame_match.group(4)))
thread.frames.append(CrashLog.Frame(int(frame_id), int(
frame_addr, 0), frame_ofs))
else:
print('error: frame regex failed for line: "%s"' % line)
elif parse_mode == PARSE_MODE_IMAGES:
image_match = self.image_regex_uuid.search(line)
if image_match:
(img_lo, img_hi, img_name, img_version,
(img_lo, img_hi, img_name, _, img_version, _,
_, img_uuid, img_path) = image_match.groups()
image = CrashLog.DarwinImage(int(img_lo, 0), int(img_hi, 0),
img_name.strip(),
Expand Down
135 changes: 135 additions & 0 deletions lldb/test/Shell/Python/crashlog.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# -*- python -*-
# REQUIRES: system-darwin
# DEBUG: cd %S/../../../examples/python && cat %s | %lldb && false
# RUN: cd %S/../../../examples/python && cat %s | %lldb | FileCheck %s
# CHECK-LABEL: {{S}}KIP BEYOND CHECKS
script
import crashlog
cl = crashlog.CrashLog
images = [
"0x10b60b000 - 0x10f707fff com.apple.LLDB.framework (1.1000.11.38.2 - 1000.11.38.2) <96E36F5C-1A83-39A1-8713-5FDD9701C3F1> /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/LLDB",
# CHECK: 0x10b60b000
# CHECK: 0x10f707fff
# CHECK: com.apple.LLDB.framework
# CHECK: 96E36F5C-1A83-39A1-8713-5FDD9701C3F1
# CHECK: /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/LLDB

"0x104591000 - 0x1055cfff7 +llvm-dwarfdump (0) <B104CFA1-046A-36A6-8EB4-07DDD7CC2DF3> /Users/USER 1/Documents/*/llvm-dwarfdump",
# CHECK: 0x104591000
# CHECK: 0x1055cfff7
# CHECK: llvm-dwarfdump
# CHECK: (0)
# CHECK: B104CFA1-046A-36A6-8EB4-07DDD7CC2DF3
# CHECK: /Users/USER 1/Documents/*/llvm-dwarfdump

"0x7fff63f20000 - 0x7fff63f77ff7 libc++.1.dylib (400.9.4) <D4AB366F-48A9-3C7D-91BD-41198F69DD57> /usr/lib/libc++.1.dylib",
# CHECK: 0x7fff63f20000
# CHECK: 0x7fff63f77ff7
# CHECK: libc++.1.dylib
# CHECK: (400.9.4)
# CHECK: D4AB366F-48A9-3C7D-91BD-41198F69DD57
# CHECK: /usr/lib/libc++.1.dylib

"0x1111111 - 0x22222 +MyApp Pro arm64 <01234> /tmp/MyApp Pro.app/MyApp Pro",
# CHECK: 0x1111111
# CHECK: 0x22222
# CHECK: MyApp Pro
# CHECK: arm64
# CHECK: 01234
# CHECK: /tmp/MyApp Pro.app/MyApp Pro

"0x1111111 - 0x22222 +MyApp Pro (0) <01234> /tmp/MyApp Pro.app/MyApp Pro",
# CHECK: 0x1111111
# CHECK: 0x22222
# CHECK: MyApp Pro
# CHECK: (0)
# CHECK: 01234
# CHECK: /tmp/MyApp Pro.app/MyApp Pro

"0x1111111 - 0x2222222 MyFramework Plus.dylib (1.11 - MyFramework 1.11) <01234> /tmp/MyFramework Plus.dylib",
# CHECK: 0x1111111
# CHECK: 0x2222222
# CHECK: MyFramework Plus.dylib
# CHECK: ({{.*}}
# CHECK: 1.11 - MyFramework 1.11
# CHECK: <{{.*}}
# CHECK: 01234
# CHECK: /tmp/MyFramework Plus.dylib

"0x1111111 - 0x2222222 MyFramework-dev.dylib (1.0.0svn - 1.0.0svn) <01234> /MyFramework-dev.dylib",
# CHECK: 0x1111111
# CHECK: 0x2222222
# CHECK: MyFramework-dev.dylib
# CHECK: ({{.*}}
# CHECK: 1.0.0svn - 1.0.0svn
# CHECK: <{{.*}}
# CHECK: 01234
# CHECK: /MyFramework-dev.dylib

"0x7fff63f20000 - 0x7fff63f77ff7 libc++.1.dylib (400.9.4) /usr/lib/libc++.1.dylib",
# CHECK: 0x7fff63f20000
# CHECK: 0x7fff63f77ff7
# CHECK: libc++.1.dylib
# CHECK: ({{.*}}
# CHECK: 400.9.4
# CHECK: None
# CHECK: None
# CHECK: /usr/lib/libc++.1.dylib

"0x1047b8000 - 0x10481ffff dyld arm64e <cfa789d10da63f9a8996daf84ed9d04f> /usr/lib/dyld"
# CHECK: 0x1047b8000
# CHECK: 0x10481ffff
# CHECK: dyld
# CHECK: {{.*}}
# CHECK: arm64e
# CHECK: <{{.*}}
# CHECK: cfa789d10da63f9a8996daf84ed9d04f
# CHECK: /usr/lib/dyld
]
# CHECK-LABEL: FRAMES
frames = [
"0 libsystem_kernel.dylib 0x00007fff684b78a6 read + 10",
# CHECK: 0
# CHECK: libsystem_kernel.dylib
# CHECK: 0x00007fff684b78a6
# CHECK: read + 10
"1 com.apple.LLDB.framework 0x000000010f7954af lldb_private::HostNativeThreadBase::ThreadCreateTrampoline(void*) + 105",
# CHECK: 1
# CHECK: com.apple.LLDB.framework
# CHECK: 0x000000010f7954af
# CHECK: lldb_private{{.*}} + 105
"2 MyApp Pro arm64 0x000000019b0db3a8 foo + 72",
# CHECK: 2
# CHECK: MyApp Pro
# CHECK: a
# CHECK: arm64
# CHECK: a
# CHECK: 0x000000019b0db3a8
# CHECK: foo + 72
"3 He 0x1 0x000000019b0db3a8 foo + 72"
# CHECK: 3
# CHECK: He 0x1
# CHECK: 0x000000019b0db3a8
# CHECK: foo + 72
]


# Avoid matching the text inside the input.
print("SKIP BEYOND CHECKS")
for image in images:
print('"%s"'%image)
print("--------------")
match = cl.image_regex_uuid.search(image)
for group in match.groups():
print(group)

print("FRAMES")
for frame in frames:
print('"%s"'%frame)
print("--------------")
match = cl.frame_regex.search(frame)
for group in match.groups():
print(group)

exit()
quit