Files
clang-p2996/lldb/test/API/functionalities/breakpoint/breakpoint_options/TestBreakpointOptions.py
bvlgah ece2c25ab9 [LLDB][Test] Fix the test case of listing verbose break info on Windows (#85200)
I noticed a failure of [running LLDB test suites on Windows
AArch64](https://lab.llvm.org/buildbot/#/builders/219/builds/9849). The
failed test case is about
checking output of command `breakpoint list -v -L c++`, and an mismatch
on the demangled
name of a function occurred. The test case expects `ns::func(void)`, but
on Windows it is `int ns::func(void)`.
It results from the different mangling scheme used by MSVC, and the
comparison is as follows:

| Scheme | Mangled | Demangled (fully) | Note |
| --- | --- | --- | --- |
| MSVC | `?func@ns@@YAHXZ` | `int __cdecl ns::func(void)` |
[Godbolt](https://godbolt.org/z/5ns8c7xW3) (I have no available Windows
device) |
| Itanium | `_ZN2ns4funcEv` | `ns::func()` | |

According to the current use of MSVC demangling,


8f68022f8e/lldb/source/Core/Mangled.cpp (L128-L143)

the `__cdecl` specifier is not part of the name. However, the function's
parameter types should be present
as ` llvm::MSDF_NoVariableType` [does not affect a symbol for
functions](8f68022f8e/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp (L417-L453)).

Therefore, it is inappropriate to assume the demangled name are the same
on all platforms. Instead of tweaking the
existing code of demangling to get the same (demangled) name, I think it
is more reasonable to modify the test case.
2024-03-14 09:11:37 +00:00

138 lines
4.3 KiB
Python

"""
Test breakpoint command for different options.
"""
import lldb
from lldbsuite.test.lldbtest import *
import lldbsuite.test.lldbutil as lldbutil
class BreakpointOptionsTestCase(TestBase):
def test(self):
"""Test breakpoint command for different options."""
self.build()
self.breakpoint_options_test()
self.breakpoint_options_language_test()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break inside main().
self.line = line_number("main.cpp", "// Set break point at this line.")
def breakpoint_options_test(self):
"""Test breakpoint command for different options."""
exe = self.getBuildArtifact("a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# This should create a breakpoint with 1 locations.
lldbutil.run_break_set_by_file_and_line(
self, "main.cpp", self.line, extra_options="-K 1", num_expected_locations=1
)
lldbutil.run_break_set_by_file_and_line(
self, "main.cpp", self.line, extra_options="-K 0", num_expected_locations=1
)
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
# Stopped once.
self.expect(
"thread backtrace",
STOPPED_DUE_TO_BREAKPOINT,
substrs=["stop reason = breakpoint 2."],
)
# Check the list of breakpoint.
self.expect(
"breakpoint list -f",
"Breakpoint locations shown correctly",
substrs=[
"1: file = 'main.cpp', line = %d, exact_match = 0, locations = 1"
% self.line,
"2: file = 'main.cpp', line = %d, exact_match = 0, locations = 1"
% self.line,
],
)
# Continue the program, there should be another stop.
self.runCmd("process continue")
# Stopped again.
self.expect(
"thread backtrace",
STOPPED_DUE_TO_BREAKPOINT,
substrs=["stop reason = breakpoint 1."],
)
# Continue the program, we should exit.
self.runCmd("process continue")
# We should exit.
self.expect(
"process status",
"Process exited successfully",
patterns=["^Process [0-9]+ exited with status = 0"],
)
def breakpoint_options_language_test(self):
"""Test breakpoint command for language option."""
exe = self.getBuildArtifact("a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# This should create a breakpoint with 1 locations.
bp_id = lldbutil.run_break_set_by_symbol(
self,
"ns::func",
sym_exact=False,
extra_options="-L c++",
num_expected_locations=1,
)
location = self.target().FindBreakpointByID(bp_id).GetLocationAtIndex(0)
function = location.GetAddress().GetFunction()
self.expect(
"breakpoint list -v",
"Verbose breakpoint list contains mangled names",
# The demangled function name is system-dependent, e.g.
# 'int ns::func(void)' on Windows and 'ns::func()' on Linux.
substrs=[
f"function = {function.GetName()}",
f"mangled function = {function.GetMangledName()}",
],
)
# This should create a breakpoint with 0 locations.
lldbutil.run_break_set_by_symbol(
self,
"ns::func",
sym_exact=False,
extra_options="-L c",
num_expected_locations=0,
)
self.runCmd("settings set target.language c")
lldbutil.run_break_set_by_symbol(
self, "ns::func", sym_exact=False, num_expected_locations=0
)
# Run the program.
self.runCmd("run", RUN_SUCCEEDED)
# Stopped once.
self.expect(
"thread backtrace",
STOPPED_DUE_TO_BREAKPOINT,
substrs=["stop reason = breakpoint 1."],
)
# Continue the program, we should exit.
self.runCmd("process continue")
# We should exit.
self.expect(
"process status",
"Process exited successfully",
patterns=["^Process [0-9]+ exited with status = 0"],
)