Skip to content

Conversation

@kastiglione
Copy link
Contributor

@kastiglione kastiglione commented Aug 20, 2025

Follow up to #128712

@llvmbot
Copy link
Member

llvmbot commented Aug 20, 2025

@llvm/pr-subscribers-lldb

Author: Dave Lee (kastiglione)

Changes

Follow up to #128712


Full diff: https://github.com/llvm/llvm-project/pull/154574.diff

1 Files Affected:

  • (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (+3-2)
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 9958af26379b9..163cc19943683 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -8,6 +8,7 @@
 
 #include "SymbolFileDWARF.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/DebugInfo/DWARF/DWARFAddressRange.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
 #include "llvm/Support/Casting.h"
@@ -998,12 +999,12 @@ XcodeSDK SymbolFileDWARF::ParseXcodeSDK(CompileUnit &comp_unit) {
   const char *sdk = cu_die.GetAttributeValueAsString(DW_AT_APPLE_sdk, nullptr);
   if (!sdk)
     return {};
-  std::string sysroot =
+  llvm::StringRef sysroot =
       cu_die.GetAttributeValueAsString(DW_AT_LLVM_sysroot, "");
 
   // RegisterXcodeSDK calls into xcrun which is not aware of CLT, which is
   // expensive.
-  if (sysroot.find("/Library/Developer/CommandLineTools/SDKs") != 0) {
+  if (!sysroot.starts_with("/Library/Developer/CommandLineTools/SDKs")) {
     // Register the sysroot path remapping with the module belonging to
     // the CU as well as the one belonging to the symbol file. The two
     // would be different if this is an OSO object and module is the

Copy link
Member

@bulbazord bulbazord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)

Copy link
Member

@Michael137 Michael137 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

if (!sdk)
return {};
std::string sysroot =
llvm::StringRef sysroot =
Copy link
Member

@Michael137 Michael137 Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this is a StringRef we don't need the move down on line 1021. Though I'd double-check that the lifetimes make sense. I'm speculating because i dont have the source in front of me, but suspect I used a std::string+move here just because FileSpec takes a std::string in its constructor? Either way, it doesn't buy us much so the readability win here is worth it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for pointing out the move.

double-check that the lifetimes make sense

It appears fine, and the tests pass. Is that enough or should we test this more in some way?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked and FileSpec takes a StringRef anyway, so we're good

@kastiglione kastiglione merged commit dacabc1 into llvm:main Aug 21, 2025
9 checks passed
@kastiglione kastiglione deleted the lldb-Tweak-check-for-CommandLineTools-in-ParseXcodeSDK branch August 21, 2025 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants