Index: include/lldb/Core/ConstString.h =================================================================== --- include/lldb/Core/ConstString.h +++ include/lldb/Core/ConstString.h @@ -291,6 +291,33 @@ } //------------------------------------------------------------------ + /// Equal to operator + /// + /// Returns true if this string is equal to the string in \a rhs. + /// If case sensitive equality is tested, this operation is very + /// fast as it results in a pointer comparison since all strings + /// are in a uniqued in a global string pool. + /// + /// @param[in] rhs + /// The Left Hand Side const ConstString object reference. + /// + /// @param[in] rhs + /// The Right Hand Side const ConstString object reference. + /// + /// @param[in] case_sensitive + /// Case sensitivity. If true, case sensitive equality + /// will be tested, otherwise character case will be ignored + /// + /// @return + /// @li \b true if this object is equal to \a rhs. + /// @li \b false if this object is not equal to \a rhs. + //------------------------------------------------------------------ + static bool + Equals (const ConstString& lhs, + const ConstString& rhs, + const bool case_sensitive = true); + + //------------------------------------------------------------------ /// Compare two string objects. /// /// Compares the C string values contained in \a lhs and \a rhs and @@ -307,13 +334,19 @@ /// @param[in] rhs /// The Right Hand Side const ConstString object reference. /// + /// @param[in] case_sensitive + /// Case sensitivity of compare. If true, case sensitive compare + /// will be performed, otherwise character case will be ignored + /// /// @return /// @li -1 if lhs < rhs /// @li 0 if lhs == rhs /// @li 1 if lhs > rhs //------------------------------------------------------------------ static int - Compare (const ConstString& lhs, const ConstString& rhs); + Compare (const ConstString& lhs, + const ConstString& rhs, + const bool case_sensitive = true); //------------------------------------------------------------------ /// Dump the object description to a stream. Index: packages/Python/lldbsuite/test/dotest.py =================================================================== --- packages/Python/lldbsuite/test/dotest.py +++ packages/Python/lldbsuite/test/dotest.py @@ -284,7 +284,14 @@ if args.d: sys.stdout.write("Suspending the process %d to wait for debugger to attach...\n" % os.getpid()) sys.stdout.flush() - os.kill(os.getpid(), signal.SIGSTOP) + + if sys.platform.startswith('win32'): + import ctypes, time + while not ctypes.windll.kernel32.IsDebuggerPresent(): + time.sleep(0.5) + ctypes.windll.kernel32.DebugBreak() + else: + os.kill(os.getpid(), signal.SIGSTOP) if args.f: if any([x.startswith('-') for x in args.f]): Index: packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_case_sensitivity/Makefile =================================================================== --- /dev/null +++ packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_case_sensitivity/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../../make + +C_SOURCES := main.c +CFLAGS_EXTRAS += -std=c99 + +include $(LEVEL)/Makefile.rules Index: packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_case_sensitivity/TestBreakpointCaseSensitivity.py =================================================================== --- /dev/null +++ packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_case_sensitivity/TestBreakpointCaseSensitivity.py @@ -0,0 +1,109 @@ +""" +Test case sensitivity of paths on Windows / POSIX +llvm.org/pr22667 +""" + +import os +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbplatform, lldbplatformutil + +class BreakpointCaseSensitivityTestCase(TestBase): + mydir = TestBase.compute_mydir(__file__) + BREAKPOINT_TEXT = 'Set a breakpoint here' + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + self.line = line_number('main.c', self.BREAKPOINT_TEXT) + + def test_case_sensitivity_breakpoint(self): + """Set breakpoint on file, should match files with different case on Windows""" + self.build() + self.case_sensitivity_breakpoint() + + def case_sensitivity_breakpoint(self): + """Set breakpoint on file, should match files with different case on Windows""" + + # if breakpoint should hit when file path is case modified + should_hit_modified_case = lldbplatformutil.getHostPlatform() == "windows" + + # use different case on Windows + if should_hit_modified_case: + exe = os.path.join(os.getcwd(), "A.OUT") + else: + exe = os.path.join(os.getcwd(), "a.out") + + # Create a target by the debugger. + self.target = self.dbg.CreateTarget(exe) + self.assertTrue(self.target, VALID_TARGET) + cwd = self.get_process_working_directory(); + + # try both BreakpointCreateByLocation and BreakpointCreateBySourceRegex + for regex in [False, True]: + self.check_breakpoint('main.c', regex, True) + self.check_breakpoint(os.path.join(cwd, 'main.c'), regex, True) + # different case for directory + self.check_breakpoint(os.path.join(cwd.upper(), 'main.c'), + regex, + should_hit_modified_case) + # different case for file + self.check_breakpoint('Main.c', + regex, + should_hit_modified_case) + # different case for both + self.check_breakpoint(os.path.join(cwd.upper(), 'Main.c'), + regex, + should_hit_modified_case) + + def check_breakpoint(self, file, source_regex, should_hit): + """ + Check breakpoint hit at given file set by given method + + file: + File where insert the breakpoint + + source_regex: + True for testing using BreakpointCreateBySourceRegex, + False for BreakpointCreateByLocation + + should_hit: + True if the breakpoint should hit, False otherwise + """ + + desc = ' file %s set by %s' % (file, 'regex' if source_regex else 'location') + if source_regex: + breakpoint = self.target.BreakpointCreateBySourceRegex(self.BREAKPOINT_TEXT, + lldb.SBFileSpec(file)) + else: + breakpoint = self.target.BreakpointCreateByLocation(file, self.line) + + self.assertEqual(breakpoint and breakpoint.GetNumLocations() == 1, + should_hit, + VALID_BREAKPOINT + desc) + + # Get the breakpoint location from breakpoint after we verified that, + # indeed, it has one location. + location = breakpoint.GetLocationAtIndex(0) + self.assertEqual(location and location.IsEnabled(), + should_hit, + VALID_BREAKPOINT_LOCATION + desc) + + # not needed to spawn the process when break is not set + if not should_hit: + self.target.BreakpointDelete(breakpoint.GetID()) + return + + process = self.target.LaunchSimple(None, None, self.get_process_working_directory()) + self.assertTrue(process, PROCESS_IS_VALID + desc) + + # Did we hit our breakpoint? + from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint + threads = get_threads_stopped_at_breakpoint (process, breakpoint) + self.assertTrue(len(threads) == 1, "There should be a thread stopped at breakpoint" + desc) + # The hit count for the breakpoint should be 1. + self.assertTrue(breakpoint.GetHitCount() == 1) + + # clean after ourself + process.Kill() + self.target.BreakpointDelete(breakpoint.GetID()) \ No newline at end of file Index: packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_case_sensitivity/main.c =================================================================== --- /dev/null +++ packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_case_sensitivity/main.c @@ -0,0 +1,8 @@ +#include + +int +main() +{ + printf ("Set a breakpoint here.\n"); + return 0; +} Index: source/Core/ConstString.cpp =================================================================== --- source/Core/ConstString.cpp +++ source/Core/ConstString.cpp @@ -265,8 +265,23 @@ return StringPool().GetConstCStringLength (m_string); } +bool +ConstString::Equals (const ConstString& lhs, const ConstString& rhs, const bool case_sensitive) +{ + if (lhs.m_string == rhs.m_string) + return true; + + if (case_sensitive) + return false; + + // perform case insensitive equality test + llvm::StringRef lhs_string_ref (lhs.m_string, StringPool().GetConstCStringLength (lhs.m_string)); + llvm::StringRef rhs_string_ref (rhs.m_string, StringPool().GetConstCStringLength (rhs.m_string)); + return lhs_string_ref.equals_lower(rhs_string_ref); +} + int -ConstString::Compare (const ConstString& lhs, const ConstString& rhs) +ConstString::Compare (const ConstString& lhs, const ConstString& rhs, const bool case_sensitive) { // If the iterators are the same, this is the same string const char *lhs_cstr = lhs.m_string; @@ -277,8 +292,16 @@ { llvm::StringRef lhs_string_ref (lhs_cstr, StringPool().GetConstCStringLength (lhs_cstr)); llvm::StringRef rhs_string_ref (rhs_cstr, StringPool().GetConstCStringLength (rhs_cstr)); - return lhs_string_ref.compare(rhs_string_ref); - } + + if (case_sensitive) + { + return lhs_string_ref.compare(rhs_string_ref); + } + else + { + return lhs_string_ref.compare_lower(rhs_string_ref); + } + } if (lhs_cstr) return +1; // LHS isn't NULL but RHS is Index: source/Core/FileSpecList.cpp =================================================================== --- source/Core/FileSpecList.cpp +++ source/Core/FileSpecList.cpp @@ -119,7 +119,9 @@ { if (compare_filename_only) { - if (m_files[idx].GetFilename() == file_spec.GetFilename()) + if (ConstString::Equals(m_files[idx].GetFilename(), + file_spec.GetFilename(), + file_spec.GetPathSyntax() != FileSpec::ePathSyntaxWindows)) return idx; } else Index: source/Host/common/FileSpec.cpp =================================================================== --- source/Host/common/FileSpec.cpp +++ source/Host/common/FileSpec.cpp @@ -396,9 +396,12 @@ bool FileSpec::operator== (const FileSpec& rhs) const { - if (m_filename == rhs.m_filename) + // case sensitivity of file check + const bool case_sensitive = m_syntax != ePathSyntaxWindows; + + if (ConstString::Equals(m_filename, rhs.m_filename, case_sensitive)) { - if (m_directory == rhs.m_directory) + if (ConstString::Equals(m_directory, rhs.m_directory, case_sensitive)) return true; // TODO: determine if we want to keep this code in here. @@ -447,7 +450,7 @@ // If we reach this point in the code we were able to resolve both paths // and since we only resolve the paths if the basenames are equal, then // we can just check if both directories are equal... - return resolved_lhs.GetDirectory() == resolved_rhs.GetDirectory(); + return ConstString::Equals(m_directory, rhs.m_directory, case_sensitive); } return false; } @@ -516,32 +519,32 @@ if (full || (a.m_directory && b.m_directory)) { - result = ConstString::Compare(a.m_directory, b.m_directory); + result = ConstString::Compare(a.m_directory, b.m_directory, a.m_syntax != ePathSyntaxWindows); if (result) return result; } - return ConstString::Compare (a.m_filename, b.m_filename); + return ConstString::Compare (a.m_filename, b.m_filename, a.m_syntax != ePathSyntaxWindows); } bool FileSpec::Equal (const FileSpec& a, const FileSpec& b, bool full, bool remove_backups) { if (!full && (a.GetDirectory().IsEmpty() || b.GetDirectory().IsEmpty())) - return a.m_filename == b.m_filename; + return ConstString::Equals(a.m_filename, b.m_filename, a.m_syntax != ePathSyntaxWindows); else if (remove_backups == false) return a == b; else { - if (a.m_filename != b.m_filename) + if (!ConstString::Equals(a.m_filename, b.m_filename, a.m_syntax != ePathSyntaxWindows)) return false; - if (a.m_directory == b.m_directory) + if (ConstString::Equals(a.m_directory, b.m_directory, a.m_syntax != ePathSyntaxWindows)) return true; ConstString a_without_dots; ConstString b_without_dots; RemoveBackupDots (a.m_directory, a_without_dots); RemoveBackupDots (b.m_directory, b_without_dots); - return a_without_dots == b_without_dots; + return ConstString::Equals(a_without_dots, b_without_dots, a.m_syntax != ePathSyntaxWindows); } }