Skip to content
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

[lldb] Show target.debug-file-search-paths setting from python SBDebugger #131683

Merged
merged 5 commits into from
Mar 21, 2025

Conversation

da-viper
Copy link
Contributor

Fixes #110756

@llvmbot
Copy link
Member

llvmbot commented Mar 17, 2025

@llvm/pr-subscribers-lldb

Author: Ebuka Ezike (da-viper)

Changes

Fixes #110756


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

5 Files Affected:

  • (modified) lldb/include/lldb/Interpreter/OptionValueFileSpecList.h (+2)
  • (modified) lldb/include/lldb/Utility/FileSpec.h (+13-6)
  • (modified) lldb/source/Interpreter/OptionValueFileSpecList.cpp (+10)
  • (modified) lldb/source/Utility/FileSpec.cpp (+46-39)
  • (modified) lldb/tools/lldb-dap/Transport.cpp (+2-2)
diff --git a/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h b/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h
index bda6b5071d599..200ce701cb922 100644
--- a/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h
+++ b/lldb/include/lldb/Interpreter/OptionValueFileSpecList.h
@@ -33,6 +33,8 @@ class OptionValueFileSpecList
   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
                  uint32_t dump_mask) override;
 
+  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override;
+
   Status
   SetValueFromString(llvm::StringRef value,
                      VarSetOperationType op = eVarSetOperationAssign) override;
diff --git a/lldb/include/lldb/Utility/FileSpec.h b/lldb/include/lldb/Utility/FileSpec.h
index 2e867b2b40b94..adb544b5e09d7 100644
--- a/lldb/include/lldb/Utility/FileSpec.h
+++ b/lldb/include/lldb/Utility/FileSpec.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/JSON.h"
 #include "llvm/Support/Path.h"
 
 #include <cstddef>
@@ -214,6 +215,17 @@ class FileSpec {
   ///     The stream to which to dump the object description.
   void Dump(llvm::raw_ostream &s) const;
 
+  ///
+  /// Convert the filespec object to a json value.
+  ///
+  /// Convert the filespec object to a json value. If the object contains a
+  /// valid directory name, it will be displayed followed by a directory
+  /// delimiter, and the filename.
+  ///
+  /// \return
+  ///     A json value representation of a filespec.
+  llvm::json::Value ToJSON() const;
+
   Style GetPathStyle() const;
 
   /// Directory string const get accessor.
@@ -232,7 +244,6 @@ class FileSpec {
   /// Clear the directory in this object.
   void ClearDirectory();
 
-
   /// Filename string const get accessor.
   ///
   /// \return
@@ -413,11 +424,7 @@ class FileSpec {
   /// state in this object.
   void PathWasModified() { m_absolute = Absolute::Calculate; }
 
-  enum class Absolute : uint8_t {
-    Calculate,
-    Yes,
-    No
-  };
+  enum class Absolute : uint8_t { Calculate, Yes, No };
 
   /// The unique'd directory path.
   ConstString m_directory;
diff --git a/lldb/source/Interpreter/OptionValueFileSpecList.cpp b/lldb/source/Interpreter/OptionValueFileSpecList.cpp
index 98f4938fc6c19..9877d5033a88f 100644
--- a/lldb/source/Interpreter/OptionValueFileSpecList.cpp
+++ b/lldb/source/Interpreter/OptionValueFileSpecList.cpp
@@ -41,6 +41,16 @@ void OptionValueFileSpecList::DumpValue(const ExecutionContext *exe_ctx,
   }
 }
 
+llvm::json::Value
+OptionValueFileSpecList::ToJSON(const ExecutionContext *exe_ctx) {
+  std::lock_guard<std::recursive_mutex> lock(m_mutex);
+  llvm::json::Array spec_list;
+  for (const auto &file_spec : m_current_value) {
+    spec_list.emplace_back(file_spec.ToJSON());
+  }
+  return spec_list;
+}
+
 Status OptionValueFileSpecList::SetValueFromString(llvm::StringRef value,
                                                    VarSetOperationType op) {
   std::lock_guard<std::recursive_mutex> lock(m_mutex);
diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp
index 4bebbc9ff175f..1ad08546a97a3 100644
--- a/lldb/source/Utility/FileSpec.cpp
+++ b/lldb/source/Utility/FileSpec.cpp
@@ -118,53 +118,55 @@ bool needsNormalization(const llvm::StringRef &path) {
     return true;
   for (auto i = path.find_first_of("\\/"); i != llvm::StringRef::npos;
        i = path.find_first_of("\\/", i + 1)) {
-    const auto next = safeCharAtIndex(path, i+1);
+    const auto next = safeCharAtIndex(path, i + 1);
     switch (next) {
+    case 0:
+      // path separator char at the end of the string which should be
+      // stripped unless it is the one and only character
+      return i > 0;
+    case '/':
+    case '\\':
+      // two path separator chars in the middle of a path needs to be
+      // normalized
+      if (i > 0)
+        return true;
+      ++i;
+      break;
+
+    case '.': {
+      const auto next_next = safeCharAtIndex(path, i + 2);
+      switch (next_next) {
+      default:
+        break;
       case 0:
-        // path separator char at the end of the string which should be
-        // stripped unless it is the one and only character
-        return i > 0;
+        return true; // ends with "/."
       case '/':
       case '\\':
-        // two path separator chars in the middle of a path needs to be
-        // normalized
-        if (i > 0)
-          return true;
-        ++i;
-        break;
-
+        return true; // contains "/./"
       case '.': {
-          const auto next_next = safeCharAtIndex(path, i+2);
-          switch (next_next) {
-            default: break;
-            case 0: return true; // ends with "/."
-            case '/':
-            case '\\':
-              return true; // contains "/./"
-            case '.': {
-              const auto next_next_next = safeCharAtIndex(path, i+3);
-              switch (next_next_next) {
-                default: break;
-                case 0: return true; // ends with "/.."
-                case '/':
-                case '\\':
-                  return true; // contains "/../"
-              }
-              break;
-            }
-          }
+        const auto next_next_next = safeCharAtIndex(path, i + 3);
+        switch (next_next_next) {
+        default:
+          break;
+        case 0:
+          return true; // ends with "/.."
+        case '/':
+        case '\\':
+          return true; // contains "/../"
         }
         break;
+      }
+      }
+    } break;
 
-      default:
-        break;
+    default:
+      break;
     }
   }
   return false;
 }
 
-
-}
+} // namespace
 
 void FileSpec::SetFile(llvm::StringRef pathname) { SetFile(pathname, m_style); }
 
@@ -199,11 +201,11 @@ void FileSpec::SetFile(llvm::StringRef pathname, Style style) {
   // Split path into filename and directory. We rely on the underlying char
   // pointer to be nullptr when the components are empty.
   llvm::StringRef filename = llvm::sys::path::filename(resolved, m_style);
-  if(!filename.empty())
+  if (!filename.empty())
     m_filename.SetString(filename);
 
   llvm::StringRef directory = llvm::sys::path::parent_path(resolved, m_style);
-  if(!directory.empty())
+  if (!directory.empty())
     m_directory.SetString(directory);
 }
 
@@ -330,6 +332,13 @@ void FileSpec::Dump(llvm::raw_ostream &s) const {
     s << path_separator;
 }
 
+llvm::json::Value FileSpec::ToJSON() const {
+  std::string file_spec{};
+  llvm::raw_string_ostream stream(file_spec);
+  this->Dump(stream);
+  return llvm::json::Value(std::move(file_spec));
+}
+
 FileSpec::Style FileSpec::GetPathStyle() const { return m_style; }
 
 void FileSpec::SetDirectory(ConstString directory) {
@@ -504,9 +513,7 @@ bool FileSpec::IsSourceImplementationFile() const {
   return g_source_file_regex.Execute(extension);
 }
 
-bool FileSpec::IsRelative() const {
-  return !IsAbsolute();
-}
+bool FileSpec::IsRelative() const { return !IsAbsolute(); }
 
 bool FileSpec::IsAbsolute() const {
   // Check if we have cached if this path is absolute to avoid recalculating.
diff --git a/lldb/tools/lldb-dap/Transport.cpp b/lldb/tools/lldb-dap/Transport.cpp
index db2d7228d3fb7..a721662a345eb 100644
--- a/lldb/tools/lldb-dap/Transport.cpp
+++ b/lldb/tools/lldb-dap/Transport.cpp
@@ -103,7 +103,7 @@ Expected<std::optional<Message>> Transport::Read() {
   if (raw_json->length() != length)
     return createStringError("unexpected EOF parse DAP message body");
 
-  DAP_LOG(m_log, "<-- ({0}) {1}", m_client_name, *raw_json);
+  DAP_LOG(m_log, "--> ({0}) {1}", m_client_name, *raw_json);
 
   return json::parse<Message>(*raw_json);
 }
@@ -114,7 +114,7 @@ Error Transport::Write(const Message &message) {
 
   std::string json = formatv("{0}", toJSON(message)).str();
 
-  DAP_LOG(m_log, "--> ({0}) {1}", m_client_name, json);
+  DAP_LOG(m_log, "<-- ({0}) {1}", m_client_name, json);
 
   std::string Output;
   raw_string_ostream OS(Output);

@da-viper da-viper force-pushed the show-sbdebugger-setting-for-filepath branch from 0cd2218 to adaf8ad Compare March 17, 2025 22:07
@da-viper
Copy link
Contributor Author

For the test I wanted to confirm this goes into the the path /path/to/llvmproject/lldb/test/API/python_api/debugger/TestDebuggerAPI.py

Add a `ToJSON` method in FileSpec and OptionValueFileSpecList to enable JSON serialization.
@da-viper da-viper force-pushed the show-sbdebugger-setting-for-filepath branch from adaf8ad to 6d9b82b Compare March 17, 2025 23:55
da-viper and others added 2 commits March 17, 2025 23:57
Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
Copy link

github-actions bot commented Mar 18, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@JDevlieghere
Copy link
Member

This will need a test.

Signed-off-by: Ebuka Ezike <yerimyah1@gmail.com>
@da-viper da-viper merged commit 4b41984 into llvm:main Mar 21, 2025
10 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 21, 2025

LLVM Buildbot has detected a new failure on builder lldb-remote-linux-win running on as-builder-10 while building lldb at step 17 "test-check-lldb-api".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/197/builds/2978

Here is the relevant piece of the build log for the reference
Step 17 (test-check-lldb-api) failure: Test just built components: check-lldb-api completed (failure)
******************** TEST 'lldb-api :: commands/settings/TestSettings.py' FAILED ********************
Script:
--
C:/Python312/python.exe C:/buildbot/as-builder-10/lldb-x-aarch64/llvm-project/lldb\test\API\dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=C:/buildbot/as-builder-10/lldb-x-aarch64/build/./lib --env LLVM_INCLUDE_DIR=C:/buildbot/as-builder-10/lldb-x-aarch64/build/include --env LLVM_TOOLS_DIR=C:/buildbot/as-builder-10/lldb-x-aarch64/build/./bin --arch aarch64 --build-dir C:/buildbot/as-builder-10/lldb-x-aarch64/build/lldb-test-build.noindex --lldb-module-cache-dir C:/buildbot/as-builder-10/lldb-x-aarch64/build/lldb-test-build.noindex/module-cache-lldb\lldb-api --clang-module-cache-dir C:/buildbot/as-builder-10/lldb-x-aarch64/build/lldb-test-build.noindex/module-cache-clang\lldb-api --executable C:/buildbot/as-builder-10/lldb-x-aarch64/build/./bin/lldb.exe --compiler C:/buildbot/as-builder-10/lldb-x-aarch64/build/./bin/clang.exe --dsymutil C:/buildbot/as-builder-10/lldb-x-aarch64/build/./bin/dsymutil.exe --make C:/ninja/make.exe --llvm-tools-dir C:/buildbot/as-builder-10/lldb-x-aarch64/build/./bin --lldb-obj-root C:/buildbot/as-builder-10/lldb-x-aarch64/build/tools/lldb --lldb-libs-dir C:/buildbot/as-builder-10/lldb-x-aarch64/build/./lib --platform-url connect://jetson-agx-0086.lab.llvm.org:1234 --platform-working-dir /home/ubuntu/lldb-tests --sysroot c:/buildbot/fs/jetson-agx-ubuntu --env ARCH_CFLAGS=-mcpu=cortex-a78 --platform-name remote-linux --skip-category=lldb-server C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\test\API\commands\settings -p TestSettings.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 4b419840c883b0de03ae72c7d352c37f24c1932c)
  clang revision 4b419840c883b0de03ae72c7d352c37f24c1932c
  llvm revision 4b419840c883b0de03ae72c7d352c37f24c1932c
Setting up remote platform 'remote-linux'

Connecting to remote platform 'remote-linux' at 'connect://jetson-agx-0086.lab.llvm.org:1234'...

Connected.

Setting remote platform working directory to '/home/ubuntu/lldb-tests'...

Skipping the following test categories: ['lldb-server', 'dsym', 'gmodules', 'debugserver', 'objc', 'lldb-dap']


--
Command Output (stderr):
--
PASS: LLDB (C:\buildbot\as-builder-10\lldb-x-aarch64\build\bin\clang.exe-aarch64) :: test_all_settings_exist (TestSettings.SettingsCommandTestCase.test_all_settings_exist)

PASS: LLDB (C:\buildbot\as-builder-10\lldb-x-aarch64\build\bin\clang.exe-aarch64) :: test_append_target_env_vars (TestSettings.SettingsCommandTestCase.test_append_target_env_vars)

PASS: LLDB (C:\buildbot\as-builder-10\lldb-x-aarch64\build\bin\clang.exe-aarch64) :: test_apropos_should_also_search_settings_description (TestSettings.SettingsCommandTestCase.test_apropos_should_also_search_settings_description)

UNSUPPORTED: LLDB (C:\buildbot\as-builder-10\lldb-x-aarch64\build\bin\clang.exe-aarch64) :: test_disassembler_settings (TestSettings.SettingsCommandTestCase.test_disassembler_settings) (skipping due to the following parameter(s): architecture) 

PASS: LLDB (C:\buildbot\as-builder-10\lldb-x-aarch64\build\bin\clang.exe-aarch64) :: test_experimental_settings (TestSettings.SettingsCommandTestCase.test_experimental_settings)

PASS: LLDB (C:\buildbot\as-builder-10\lldb-x-aarch64\build\bin\clang.exe-aarch64) :: test_global_option (TestSettings.SettingsCommandTestCase.test_global_option)

PASS: LLDB (C:\buildbot\as-builder-10\lldb-x-aarch64\build\bin\clang.exe-aarch64) :: test_insert_before_and_after_target_run_args (TestSettings.SettingsCommandTestCase.test_insert_before_and_after_target_run_args)

PASS: LLDB (C:\buildbot\as-builder-10\lldb-x-aarch64\build\bin\clang.exe-aarch64) :: test_launchsimple_args_and_env_vars (TestSettings.SettingsCommandTestCase.test_launchsimple_args_and_env_vars)

UNSUPPORTED: LLDB (C:\buildbot\as-builder-10\lldb-x-aarch64\build\bin\clang.exe-aarch64) :: test_pass_host_env_vars (TestSettings.SettingsCommandTestCase.test_pass_host_env_vars) (skip on remote platform) 

PASS: LLDB (C:\buildbot\as-builder-10\lldb-x-aarch64\build\bin\clang.exe-aarch64) :: test_print_array_setting (TestSettings.SettingsCommandTestCase.test_print_array_setting)

PASS: LLDB (C:\buildbot\as-builder-10\lldb-x-aarch64\build\bin\clang.exe-aarch64) :: test_print_dictionary_setting (TestSettings.SettingsCommandTestCase.test_print_dictionary_setting)

PASS: LLDB (C:\buildbot\as-builder-10\lldb-x-aarch64\build\bin\clang.exe-aarch64) :: test_replace_target_run_args (TestSettings.SettingsCommandTestCase.test_replace_target_run_args)

...

da-viper added a commit that referenced this pull request Mar 21, 2025
…y. (#132392)

The build bot was failing when running remote test from windows to
linux.

From  #131683

---------

Signed-off-by: Ebuka Ezike <yerimyah1@gmail.com>
Co-authored-by: Pavel Labath <pavel@labath.sk>
@slydiman
Copy link
Contributor

@da-viper
Copy link
Contributor Author

Sent the commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lldb python scripting: unable to show target.debug-file-search-paths value using SBDebugger::GetSetting
5 participants