Skip to content

[lldb] fix(lldb/**.py): fix invalid escape sequences #94034

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 1 commit into from
Feb 28, 2025
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
8 changes: 4 additions & 4 deletions lldb/examples/python/crashlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class DarwinImage(symbolication.Image):
except:
dsymForUUIDBinary = ""

dwarfdump_uuid_regex = re.compile("UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*")
dwarfdump_uuid_regex = re.compile(r"UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*")

def __init__(
self, text_addr_lo, text_addr_hi, identifier, version, uuid, path, verbose
Expand Down Expand Up @@ -501,7 +501,7 @@ def find_image_with_identifier(self, identifier):
for image in self.images:
if image.identifier == identifier:
return image
regex_text = "^.*\.%s$" % (re.escape(identifier))
regex_text = r"^.*\.%s$" % (re.escape(identifier))
regex = re.compile(regex_text)
for image in self.images:
if regex.match(image.identifier):
Expand Down Expand Up @@ -925,7 +925,7 @@ def get(cls):
version = r"(?:" + super().version + r"\s+)?"
address = r"(0x[0-9a-fA-F]{4,})" # 4 digits or more

symbol = """
symbol = r"""
(?:
[ ]+
(?P<symbol>.+)
Expand Down Expand Up @@ -1095,7 +1095,7 @@ def parse_normal(self, line):
self.crashlog.process_identifier = line[11:].strip()
elif line.startswith("Version:"):
version_string = line[8:].strip()
matched_pair = re.search("(.+)\((.+)\)", version_string)
matched_pair = re.search(r"(.+)\((.+)\)", version_string)
if matched_pair:
self.crashlog.process_version = matched_pair.group(1)
self.crashlog.process_compatability_version = matched_pair.group(2)
Expand Down
2 changes: 1 addition & 1 deletion lldb/examples/python/delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def parse_log_file(file, options):
print("# Log file: '%s'" % file)
print("#----------------------------------------------------------------------")

timestamp_regex = re.compile("(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
timestamp_regex = re.compile(r"(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")

base_time = 0.0
last_time = 0.0
Expand Down
4 changes: 2 additions & 2 deletions lldb/examples/python/gdbremote.py
Original file line number Diff line number Diff line change
Expand Up @@ -1537,12 +1537,12 @@ def parse_gdb_log(file, options):
a long time during a preset set of debugger commands."""

tricky_commands = ["qRegisterInfo"]
timestamp_regex = re.compile("(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
timestamp_regex = re.compile(r"(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
packet_name_regex = re.compile("([A-Za-z_]+)[^a-z]")
packet_transmit_name_regex = re.compile(
"(?P<direction>send|read) packet: (?P<packet>.*)"
)
packet_contents_name_regex = re.compile("\$([^#]*)#[0-9a-fA-F]{2}")
packet_contents_name_regex = re.compile(r"\$([^#]*)#[0-9a-fA-F]{2}")
packet_checksum_regex = re.compile(".*#[0-9a-fA-F]{2}$")
packet_names_regex_str = "(" + "|".join(gdb_remote_commands.keys()) + ")(.*)"
packet_names_regex = re.compile(packet_names_regex_str)
Expand Down
6 changes: 3 additions & 3 deletions lldb/examples/python/jump.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def parse_linespec(linespec, frame, result):
)

if not matched:
mo = re.match("^\+([0-9]+)$", linespec)
mo = re.match(r"^\+([0-9]+)$", linespec)
if mo is not None:
matched = True
# print "Matched +<count>"
Expand All @@ -54,7 +54,7 @@ def parse_linespec(linespec, frame, result):
)

if not matched:
mo = re.match("^\-([0-9]+)$", linespec)
mo = re.match(r"^\-([0-9]+)$", linespec)
if mo is not None:
matched = True
# print "Matched -<count>"
Expand All @@ -79,7 +79,7 @@ def parse_linespec(linespec, frame, result):
breakpoint = target.BreakpointCreateByLocation(file_name, line_number)

if not matched:
mo = re.match("\*((0x)?([0-9a-f]+))$", linespec)
mo = re.match(r"\*((0x)?([0-9a-f]+))$", linespec)
if mo is not None:
matched = True
# print "Matched <address-expression>"
Expand Down
2 changes: 1 addition & 1 deletion lldb/examples/python/performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def __init__(self, pid):

def Measure(self):
output = subprocess.getoutput(self.command).split("\n")[-1]
values = re.split("[-+\s]+", output)
values = re.split(r"[-+\s]+", output)
for idx, stat in enumerate(values):
multiplier = 1
if stat:
Expand Down
6 changes: 3 additions & 3 deletions lldb/examples/python/symbolication.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ class Section:
"""Class that represents an load address range"""

sect_info_regex = re.compile("(?P<name>[^=]+)=(?P<range>.*)")
addr_regex = re.compile("^\s*(?P<start>0x[0-9A-Fa-f]+)\s*$")
addr_regex = re.compile(r"^\s*(?P<start>0x[0-9A-Fa-f]+)\s*$")
range_regex = re.compile(
"^\s*(?P<start>0x[0-9A-Fa-f]+)\s*(?P<op>[-+])\s*(?P<end>0x[0-9A-Fa-f]+)\s*$"
r"^\s*(?P<start>0x[0-9A-Fa-f]+)\s*(?P<op>[-+])\s*(?P<end>0x[0-9A-Fa-f]+)\s*$"
)

def __init__(self, start_addr=None, end_addr=None, name=None):
Expand Down Expand Up @@ -557,7 +557,7 @@ def find_images_with_identifier(self, identifier):
if image.identifier == identifier:
images.append(image)
if len(images) == 0:
regex_text = "^.*\.%s$" % (re.escape(identifier))
regex_text = r"^.*\.%s$" % (re.escape(identifier))
regex = re.compile(regex_text)
for image in self.images:
if regex.match(image.identifier):
Expand Down
2 changes: 1 addition & 1 deletion lldb/packages/Python/lldbsuite/test/lldbpexpect.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ def cursor_forward_escape_seq(self, chars_to_move):
Returns the escape sequence to move the cursor forward/right
by a certain amount of characters.
"""
return b"\x1b\[" + str(chars_to_move).encode("utf-8") + b"C"
return b"\x1b\\[" + str(chars_to_move).encode("utf-8") + b"C"
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def timeout_to_seconds(timeout):


class ProcessHelper(object):
"""Provides an interface for accessing process-related functionality.
r"""Provides an interface for accessing process-related functionality.

This class provides a factory method that gives the caller a
platform-specific implementation instance of the class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def test_backticks_in_alias(self):
interp = self.dbg.GetCommandInterpreter()
result = lldb.SBCommandReturnObject()
interp.HandleCommand(
"command alias _test-argv-cmd expression -Z \`argc\` -- argv", result
r"command alias _test-argv-cmd expression -Z \`argc\` -- argv", result
)
self.assertCommandReturn(result, "Made the alias")
interp.HandleCommand("_test-argv-cmd", result)
self.assertCommandReturn(result, "The alias worked")

# Now try a harder case where we create this using an alias:
interp.HandleCommand(
"command alias _test-argv-parray-cmd parray \`argc\` argv", result
r"command alias _test-argv-parray-cmd parray \`argc\` argv", result
)
self.assertCommandReturn(result, "Made the alias")
interp.HandleCommand("_test-argv-parray-cmd", result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test(self):
alloc0 = re.search("^.*IRMemoryMap::Malloc.+?0xdead0000.*$", log, re.MULTILINE)
# Malloc adds additional bytes to allocation size, hence 10007
alloc1 = re.search(
"^.*IRMemoryMap::Malloc\s*?\(10007.+?0xdead1000.*$", log, re.MULTILINE
r"^.*IRMemoryMap::Malloc\s*?\(10007.+?0xdead1000.*$", log, re.MULTILINE
)
self.assertTrue(alloc0, "Couldn't find an allocation at a given address.")
self.assertTrue(
Expand Down
2 changes: 1 addition & 1 deletion lldb/test/API/commands/expression/test/TestExprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def build_and_run(self):
def test_floating_point_expr_commands(self):
self.build_and_run()

self.expect("expression 2.234f", patterns=["\(float\) \$.* = 2\.234"])
self.expect("expression 2.234f", patterns=[r"\(float\) \$.* = 2\.234"])
# (float) $2 = 2.234

def test_many_expr_commands(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_gui(self):
self.child.expect_exact("Threads")

# The main thread should be expanded.
self.child.expect("#\d+: main")
self.child.expect(r"#\d+: main")

# Quit the GUI
self.child.send(escape_key)
Expand Down
6 changes: 3 additions & 3 deletions lldb/test/API/commands/help/TestHelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,13 @@ def test_help_show_tags(self):
self.expect(
"help memory read",
patterns=[
"--show-tags\n\s+Include memory tags in output "
"\(does not apply to binary output\)."
"--show-tags\n\\s+Include memory tags in output "
"\\(does not apply to binary output\\)."
],
)
self.expect(
"help memory find",
patterns=["--show-tags\n\s+Include memory tags in output."],
patterns=["--show-tags\n\\s+Include memory tags in output."],
)

@no_debug_info_test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test(self):

self.runCmd("process kill")

self.runCmd("process launch -X true -w %s -- foo\ bar" % (self.getBuildDir()))
self.runCmd(r"process launch -X true -w %s -- foo\ bar" % (self.getBuildDir()))

process = self.process()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ def test_unavailable_registers(self):
"register read --all",
patterns=[
"(?sm)^general purpose registers:\n"
"^\s+rdx = 0x5555555555555555\n"
"^\\s+rdx = 0x5555555555555555\n"
".*"
"^3 registers were unavailable.\n"
"\n"
"^supplementary registers:\n"
"^\s+edx = 0x55555555\n"
"^\\s+edx = 0x55555555\n"
".*"
"^12 registers were unavailable."
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,14 +662,14 @@ def test_register_read_fields(self):
# N/Z/C/V bits will always be present, so check only for those.
self.expect(
"register read cpsr",
patterns=["= \(N = [0|1], Z = [0|1], C = [0|1], V = [0|1]"],
patterns=[r"= \(N = [0|1], Z = [0|1], C = [0|1], V = [0|1]"],
)
self.expect(
"register read fpsr", patterns=["= \(QC = [0|1], IDC = [0|1], IXC = [0|1]"]
"register read fpsr", patterns=[r"= \(QC = [0|1], IDC = [0|1], IXC = [0|1]"]
)
# AHP/DN/FZ always present, others may vary.
self.expect(
"register read fpcr", patterns=["= \(AHP = [0|1], DN = [0|1], FZ = [0|1]"]
"register read fpcr", patterns=[r"= \(AHP = [0|1], DN = [0|1], FZ = [0|1]"]
)

# Should get enumerator descriptions for RMode.
Expand Down
12 changes: 6 additions & 6 deletions lldb/test/API/commands/settings/TestSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ def cleanup():
self.addTearDownHook(cleanup)

self.runCmd("settings show frame-format")
m = re.match('^frame-format \(format-string\) = "(.*)"$', self.res.GetOutput())
m = re.match(r'^frame-format \(format-string\) = "(.*)"$', self.res.GetOutput())
self.assertTrue(m, "Bad settings string")
self.format_string = m.group(1)

# Change the default format to print function.name rather than
# function.name-with-args
format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}\`${function.name}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}{, lang=${language}}\n"
format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}\\`${function.name}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}{, lang=${language}}\n"
self.runCmd("settings set frame-format %s" % format_string)

# Immediately test the setting.
Expand Down Expand Up @@ -724,7 +724,7 @@ def test_settings_with_trailing_whitespace(self):
)
self.runCmd("settings set target.run-args 1 2 3") # Set to known value
# Set to new value with trailing whitespaces
self.runCmd("settings set target.run-args 3 \ \ ")
self.runCmd(r"settings set target.run-args 3 \ \ ")
self.expect(
"settings show target.run-args",
SETTING_MSG("target.run-args"),
Expand Down Expand Up @@ -846,11 +846,11 @@ def test_settings_clear_all(self):
# Check that settings have their default values after clearing.
self.expect(
"settings show target.env-vars",
patterns=["^target.env-vars \(dictionary of strings\) =\s*$"],
patterns=[r"^target.env-vars \(dictionary of strings\) =\s*$"],
)
self.expect(
"settings show target.run-args",
patterns=["^target.run-args \(arguments\) =\s*$"],
patterns=[r"^target.run-args \(arguments\) =\s*$"],
)
self.expect("settings show auto-confirm", substrs=["false"])
self.expect("settings show tab-size", substrs=["2"])
Expand Down Expand Up @@ -947,7 +947,7 @@ def test_experimental_settings(self):
# showing & setting an undefined .experimental. setting should generate no errors.
self.expect(
"settings show target.experimental.setting-which-does-not-exist",
patterns=["^\s$"],
patterns=[r"^\s$"],
error=False,
)
self.expect(
Expand Down
2 changes: 1 addition & 1 deletion lldb/test/API/commands/target/basic/TestTargetCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def do_target_command(self):
# Find the largest index of the existing list.
import re

pattern = re.compile("target #(\d+):")
pattern = re.compile(r"target #(\d+):")
for line in reversed(output.split(os.linesep)):
match = pattern.search(line)
if match:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ def test_dwos_loaded_table_output(self):
self.expect(
"target modules dump separate-debug-info",
patterns=[
"Symbol file: .*?a\.out",
r"Symbol file: .*?a\.out",
'Type: "dwo"',
"Dwo ID\s+Err\s+Dwo Path",
"0x[a-zA-Z0-9]{16}\s+.*main\.dwo",
"0x[a-zA-Z0-9]{16}\s+.*foo\.dwo",
r"Dwo ID\s+Err\s+Dwo Path",
r"0x[a-zA-Z0-9]{16}\s+.*main\.dwo",
r"0x[a-zA-Z0-9]{16}\s+.*foo\.dwo",
],
)

Expand All @@ -118,11 +118,11 @@ def test_dwos_not_loaded_table_output(self):
self.expect(
"target modules dump separate-debug-info",
patterns=[
"Symbol file: .*?a\.out",
r"Symbol file: .*?a\.out",
'Type: "dwo"',
"Dwo ID\s+Err\s+Dwo Path",
"0x[a-zA-Z0-9]{16}\s+E\s+.*main\.dwo",
"0x[a-zA-Z0-9]{16}\s+E\s+.*foo\.dwo",
r"Dwo ID\s+Err\s+Dwo Path",
r"0x[a-zA-Z0-9]{16}\s+E\s+.*main\.dwo",
r"0x[a-zA-Z0-9]{16}\s+E\s+.*foo\.dwo",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ def test_shows_oso_loaded_table_output(self):
self.expect(
"target modules dump separate-debug-info",
patterns=[
"Symbol file: .*?a\.out",
r"Symbol file: .*?a\.out",
'Type: "oso"',
"Mod Time\s+Err\s+Oso Path",
"0x[a-zA-Z0-9]{16}\s+.*main\.o",
"0x[a-zA-Z0-9]{16}\s+.*foo\.o",
r"Mod Time\s+Err\s+Oso Path",
r"0x[a-zA-Z0-9]{16}\s+.*main\.o",
r"0x[a-zA-Z0-9]{16}\s+.*foo\.o",
],
)

Expand All @@ -119,11 +119,11 @@ def test_shows_oso_not_loaded_table_output(self):
self.expect(
"target modules dump separate-debug-info",
patterns=[
"Symbol file: .*?a\.out",
r"Symbol file: .*?a\.out",
'Type: "oso"',
"Mod Time\s+Err\s+Oso Path",
"0x[a-zA-Z0-9]{16}\s+E\s+.*main\.o",
"0x[a-zA-Z0-9]{16}\s+E\s+.*foo\.o",
r"Mod Time\s+Err\s+Oso Path",
r"0x[a-zA-Z0-9]{16}\s+E\s+.*main\.o",
r"0x[a-zA-Z0-9]{16}\s+E\s+.*foo\.o",
],
)

Expand Down
2 changes: 1 addition & 1 deletion lldb/test/API/commands/trace/TestTraceDumpInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def testDumpRawTraceSize(self):
hardware disabled tracing: 4
trace synchronization point: 1""",
],
patterns=["Decoding instructions: \d.\d\ds"],
patterns=[r"Decoding instructions: \d.\d\ds"],
)

def testDumpRawTraceSizeJSON(self):
Expand Down
4 changes: 2 additions & 2 deletions lldb/test/API/commands/trace/TestTraceEvents.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def testPauseEvents(self):
self.expect(
"thread trace dump instructions -e -f",
patterns=[
f"""thread #1: tid = .*
rf"""thread #1: tid = .*
0: \(event\) trace synchronization point \[offset \= 0x0xec0\]
1: \(event\) hardware disabled tracing
a.out`main \+ 23 at main.cpp:12
Expand Down Expand Up @@ -102,7 +102,7 @@ def testPauseEvents(self):
self.expect(
"thread trace dump instructions -e --id 18",
patterns=[
f"""thread #1: tid = .*
rf"""thread #1: tid = .*
a.out`symbol stub for: foo\(\)
18: {ADDRESS_REGEX} jmpq .*
17: \(event\) software disabled tracing
Expand Down
Loading