[Lldb-commits] [lld] [lldb] [llvm] [lit] cleanup unused imports (PR #143930)
mikaelholmen wrote: Hi, With this patch libcxx/test/libcxx/selftest/dsl/dsl.sh.py fails. So if I run ```build-all-builtins/bin/llvm-lit -av build-all-builtins/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/libcxx/test/libcxx/selftest/dsl/dsl.sh.py``` it fails with lots of errors like ``` # | == # | ERROR: test_basic (__main__.TestCompilerMacros) # | -- # | Traceback (most recent call last): # | File "/repo/libcxx/test/libcxx/selftest/dsl/dsl.sh.py", line 75, in setUp # | self.config = lit.TestingConfig.TestingConfig.fromdefaults(self.litConfig) # | AttributeError: module 'lit' has no attribute 'TestingConfig' # | ``` Seen in the build bot in the previous comment as well. https://github.com/llvm/llvm-project/pull/143930 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Implement JSON RPC (newline delimited) Transport (PR #143946)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `lldb-aarch64-windows` running on `linaro-armv8-windows-msvc-05` while building `lldb` at step 6 "test". Full details are available at: https://lab.llvm.org/buildbot/#/builders/141/builds/9422 Here is the relevant piece of the build log for the reference ``` Step 6 (test) failure: build (failure) ... PASS: lldb-unit :: Expression/./ExpressionTests.exe/4/12 (1998 of 2242) PASS: lldb-unit :: Expression/./ExpressionTests.exe/5/12 (1999 of 2242) PASS: lldb-unit :: Expression/./ExpressionTests.exe/6/12 (2000 of 2242) PASS: lldb-unit :: Expression/./ExpressionTests.exe/7/12 (2001 of 2242) PASS: lldb-unit :: Expression/./ExpressionTests.exe/9/12 (2002 of 2242) PASS: lldb-unit :: Expression/./ExpressionTests.exe/8/12 (2003 of 2242) PASS: lldb-unit :: Host/./HostTests.exe/1/11 (2004 of 2242) PASS: lldb-unit :: Host/./HostTests.exe/0/11 (2005 of 2242) PASS: lldb-unit :: Host/./HostTests.exe/10/11 (2006 of 2242) PASS: lldb-unit :: Host/./HostTests.exe/2/11 (2007 of 2242) FAIL: lldb-unit :: Host/./HostTests.exe/4/11 (2008 of 2242) TEST 'lldb-unit :: Host/./HostTests.exe/4/11' FAILED Script(shard): -- GTEST_OUTPUT=json:C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\unittests\Host\.\HostTests.exe-lldb-unit-15752-4-11.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=11 GTEST_SHARD_INDEX=4 C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\unittests\Host\.\HostTests.exe -- Note: This is test shard 5 of 11. [==] Running 8 tests from 7 test suites. [--] Global test environment set-up. [--] 1 test from FileActionTest [ RUN ] FileActionTest.OpenReadOnly [ OK ] FileActionTest.OpenReadOnly (0 ms) [--] 1 test from FileActionTest (0 ms total) [--] 1 test from FileSystemTest [ RUN ] FileSystemTest.EmptyTest [ OK ] FileSystemTest.EmptyTest (0 ms) [--] 1 test from FileSystemTest (0 ms total) [--] 1 test from Host [ RUN ] Host.LaunchProcessSetsArgv0 Note: Google Test filter = Host.LaunchProcessSetsArgv0 ``` https://github.com/llvm/llvm-project/pull/143946 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 622df89 - [lldb/cmake] Remove EXTRA_CXXFLAGS arg (#143731)
Author: Pavel Labath Date: 2025-06-12T15:27:27+02:00 New Revision: 622df892b844749440124167e8eee9e652fba613 URL: https://github.com/llvm/llvm-project/commit/622df892b844749440124167e8eee9e652fba613 DIFF: https://github.com/llvm/llvm-project/commit/622df892b844749440124167e8eee9e652fba613.diff LOG: [lldb/cmake] Remove EXTRA_CXXFLAGS arg (#143731) We have one library using this and three libraries directly calling `target_compile_options`. Might as well standardize on the latter. Added: Modified: lldb/cmake/modules/AddLLDB.cmake lldb/source/Plugins/Language/ObjC/CMakeLists.txt Removed: diff --git a/lldb/cmake/modules/AddLLDB.cmake b/lldb/cmake/modules/AddLLDB.cmake index 0108fb22e5a03..28bf8d816d89a 100644 --- a/lldb/cmake/modules/AddLLDB.cmake +++ b/lldb/cmake/modules/AddLLDB.cmake @@ -41,7 +41,7 @@ function(add_lldb_library name) cmake_parse_arguments(PARAM "MODULE;SHARED;STATIC;OBJECT;PLUGIN;FRAMEWORK;NO_INTERNAL_DEPENDENCIES;NO_PLUGIN_DEPENDENCIES" "INSTALL_PREFIX" -"EXTRA_CXXFLAGS;LINK_LIBS;CLANG_LIBS" +"LINK_LIBS;CLANG_LIBS" ${ARGN}) if(PARAM_NO_INTERNAL_DEPENDENCIES) @@ -130,9 +130,6 @@ function(add_lldb_library name) add_dependencies(${name} clang-tablegen-targets) endif() - # Add in any extra C++ compilation flags for this library. - target_compile_options(${name} PRIVATE ${PARAM_EXTRA_CXXFLAGS}) - if(PARAM_PLUGIN) get_property(parent_dir DIRECTORY PROPERTY PARENT_DIRECTORY) if(EXISTS ${parent_dir}) diff --git a/lldb/source/Plugins/Language/ObjC/CMakeLists.txt b/lldb/source/Plugins/Language/ObjC/CMakeLists.txt index 93c23fd32524b..b9fc5ce754c49 100644 --- a/lldb/source/Plugins/Language/ObjC/CMakeLists.txt +++ b/lldb/source/Plugins/Language/ObjC/CMakeLists.txt @@ -1,13 +1,3 @@ -set(EXTRA_CXXFLAGS "") - -if (CXX_SUPPORTS_NO_GNU_ANONYMOUS_STRUCT) - set(EXTRA_CXXFLAGS ${EXTRA_CXXFLAGS} -Wno-gnu-anonymous-struct) -endif () - -if (CXX_SUPPORTS_NO_NESTED_ANON_TYPES) - set(EXTRA_CXXFLAGS ${EXTRA_CXXFLAGS} -Wno-nested-anon-types) -endif () - add_lldb_library(lldbPluginObjCLanguage PLUGIN ObjCLanguage.cpp CF.cpp @@ -36,6 +26,14 @@ add_lldb_library(lldbPluginObjCLanguage PLUGIN lldbPluginTypeSystemClang CLANG_LIBS clangAST - - EXTRA_CXXFLAGS ${EXTRA_CXXFLAGS} ) + +if (CXX_SUPPORTS_NO_GNU_ANONYMOUS_STRUCT) + target_compile_options(lldbPluginObjCLanguage +PRIVATE -Wno-gnu-anonymous-struct) +endif () + +if (CXX_SUPPORTS_NO_NESTED_ANON_TYPES) + target_compile_options(lldbPluginObjCLanguage +PRIVATE -Wno-nested-anon-types) +endif () ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] make lit use the same Python executable for building and testing (PR #143756)
labath wrote: +1 for %python https://github.com/llvm/llvm-project/pull/143756 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/cmake] Remove EXTRA_CXXFLAGS arg (PR #143731)
https://github.com/labath closed https://github.com/llvm/llvm-project/pull/143731 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][test] Don't call SBDebugger::Terminate if TestMultipleDebuggers times out (PR #143732)
https://github.com/labath approved this pull request. exit() will also run some cleanup functions and could cause things to crash. You could one-up it to _exit(), but ultimately, there's no way to guarantee that misbehaving code will umm... behave in a certain way. https://github.com/llvm/llvm-project/pull/143732 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Improving dotest script flags. (PR #143797)
labath wrote: +1 for removing the option :) https://github.com/llvm/llvm-project/pull/143797 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Commands][NFC] Extract memory find expression evaluation into helpers (PR #143686)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/143686 >From 94a2cae4dfee6d943eaa93bd089e1c0e61b54356 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Wed, 11 Jun 2025 12:02:44 +0100 Subject: [PATCH 1/3] [lldb][Commands][NFC] Extract memory find expression evaluation into helpers This patch factors out the `-e` option logic into two helper functions. The `EvaluateExpression` helper might seem redundant but I'll be adding to it in a follow-up patch to fix and issue when running `memory find -e` for Swift targets. Also adds test coverage for the error cases that were previously untested. rdar://152113525 --- lldb/source/Commands/CommandObjectMemory.cpp | 104 ++ .../memory/find/TestMemoryFind.py | 31 ++ .../API/functionalities/memory/find/main.cpp | 16 +++ 3 files changed, 108 insertions(+), 43 deletions(-) diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 7140333bb3cde..34230df9b2727 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -885,6 +885,55 @@ class CommandObjectMemoryRead : public CommandObjectParsed { #define LLDB_OPTIONS_memory_find #include "CommandOptions.inc" +static llvm::Error CopyExpressionResult(ValueObject &result, +DataBufferHeap &buffer) { + uint64_t value = result.GetValueAsUnsigned(0); + auto size_or_err = result.GetCompilerType().GetByteSize(nullptr); + if (!size_or_err) +return size_or_err.takeError(); + + switch (*size_or_err) { + case 1: { +uint8_t byte = (uint8_t)value; +buffer.CopyData(&byte, 1); + } break; + case 2: { +uint16_t word = (uint16_t)value; +buffer.CopyData(&word, 2); + } break; + case 4: { +uint32_t lword = (uint32_t)value; +buffer.CopyData(&lword, 4); + } break; + case 8: { +buffer.CopyData(&value, 8); + } break; + case 3: + case 5: + case 6: + case 7: +return llvm::createStringError("unknown type. pass a string instead"); + default: +return llvm::createStringError( +"result size larger than 8 bytes. pass a string instead"); + } + + return llvm::Error::success(); +} + +static llvm::Expected +EvaluateExpression(llvm::StringRef expression, StackFrame &frame, + Process &process) { + ValueObjectSP result_sp; + auto status = + process.GetTarget().EvaluateExpression(expression, &frame, result_sp); + if (status != eExpressionCompleted || !result_sp) +return llvm::createStringError( +"expression evaluation failed. pass a string instead"); + + return result_sp; +} + // Find the specified data in memory class CommandObjectMemoryFind : public CommandObjectParsed { public: @@ -1026,49 +1075,18 @@ class CommandObjectMemoryFind : public CommandObjectParsed { } buffer.CopyData(str); } else if (m_memory_options.m_expr.OptionWasSet()) { - StackFrame *frame = m_exe_ctx.GetFramePtr(); - ValueObjectSP result_sp; - if ((eExpressionCompleted == - process->GetTarget().EvaluateExpression( - m_memory_options.m_expr.GetValueAs().value_or( - ""), - frame, result_sp)) && - result_sp) { -uint64_t value = result_sp->GetValueAsUnsigned(0); -std::optional size = llvm::expectedToOptional( -result_sp->GetCompilerType().GetByteSize(nullptr)); -if (!size) - return; -switch (*size) { -case 1: { - uint8_t byte = (uint8_t)value; - buffer.CopyData(&byte, 1); -} break; -case 2: { - uint16_t word = (uint16_t)value; - buffer.CopyData(&word, 2); -} break; -case 4: { - uint32_t lword = (uint32_t)value; - buffer.CopyData(&lword, 4); -} break; -case 8: { - buffer.CopyData(&value, 8); -} break; -case 3: -case 5: -case 6: -case 7: - result.AppendError("unknown type. pass a string instead"); - return; -default: - result.AppendError( - "result size larger than 8 bytes. pass a string instead"); - return; -} - } else { -result.AppendError( -"expression evaluation failed. pass a string instead"); + auto result_or_err = EvaluateExpression( + m_memory_options.m_expr.GetValueAs().value_or(""), + m_exe_ctx.GetFrameRef(), *process); + if (!result_or_err) { +result.AppendError(llvm::toString(result_or_err.takeError())); +return; + } + + ValueObjectSP result_sp = *result_or_err; + + if (auto err = CopyExpressionResult(*result_sp, buffer)) { +result.AppendError(llvm::toString(std::move(err))); return; } } else { diff --git a/lldb/test/API/functionalities/memory/find/TestMemoryFind.py b/lldb/te
[Lldb-commits] [lldb] [lldb][Commands][NFC] Extract memory find expression evaluation into helpers (PR #143686)
https://github.com/adrian-prantl approved this pull request. Anyway, this is good otherwise! https://github.com/llvm/llvm-project/pull/143686 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Commands][NFC] Extract memory find expression evaluation into helpers (PR #143686)
@@ -885,6 +885,55 @@ class CommandObjectMemoryRead : public CommandObjectParsed { #define LLDB_OPTIONS_memory_find #include "CommandOptions.inc" +static llvm::Error CopyExpressionResult(ValueObject &result, +DataBufferHeap &buffer) { + uint64_t value = result.GetValueAsUnsigned(0); + auto size_or_err = result.GetCompilerType().GetByteSize(nullptr); + if (!size_or_err) +return size_or_err.takeError(); + + switch (*size_or_err) { + case 1: { +uint8_t byte = (uint8_t)value; +buffer.CopyData(&byte, 1); + } break; + case 2: { +uint16_t word = (uint16_t)value; +buffer.CopyData(&word, 2); + } break; + case 4: { +uint32_t lword = (uint32_t)value; +buffer.CopyData(&lword, 4); + } break; + case 8: { +buffer.CopyData(&value, 8); + } break; + case 3: + case 5: + case 6: + case 7: +return llvm::createStringError("unknown type. pass a string instead"); + default: +return llvm::createStringError( +"result size larger than 8 bytes. pass a string instead"); + } + + return llvm::Error::success(); +} + +static llvm::Expected +EvaluateExpression(llvm::StringRef expression, StackFrame &frame, + Process &process) { + ValueObjectSP result_sp; + auto status = + process.GetTarget().EvaluateExpression(expression, &frame, result_sp); + if (status != eExpressionCompleted || !result_sp) adrian-prantl wrote: I thought it would be nice to bubble up the error from the expression, but that is presumably attached to result_sp and this condition just catches execution failures, not compiler diagnostics, which should be much rarer. I think this is fine. https://github.com/llvm/llvm-project/pull/143686 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Commands][NFC] Extract memory find expression evaluation into helpers (PR #143686)
@@ -885,6 +885,55 @@ class CommandObjectMemoryRead : public CommandObjectParsed { #define LLDB_OPTIONS_memory_find #include "CommandOptions.inc" +static llvm::Error CopyExpressionResult(ValueObject &result, +DataBufferHeap &buffer) { + uint64_t value = result.GetValueAsUnsigned(0); + auto size_or_err = result.GetCompilerType().GetByteSize(nullptr); + if (!size_or_err) +return size_or_err.takeError(); + + switch (*size_or_err) { + case 1: { +uint8_t byte = (uint8_t)value; +buffer.CopyData(&byte, 1); + } break; + case 2: { +uint16_t word = (uint16_t)value; +buffer.CopyData(&word, 2); + } break; + case 4: { +uint32_t lword = (uint32_t)value; +buffer.CopyData(&lword, 4); + } break; + case 8: { +buffer.CopyData(&value, 8); + } break; + case 3: + case 5: + case 6: + case 7: +return llvm::createStringError("unknown type. pass a string instead"); + default: +return llvm::createStringError( +"result size larger than 8 bytes. pass a string instead"); + } + + return llvm::Error::success(); +} + +static llvm::Expected +EvaluateExpression(llvm::StringRef expression, StackFrame &frame, + Process &process) { + ValueObjectSP result_sp; + auto status = + process.GetTarget().EvaluateExpression(expression, &frame, result_sp); + if (status != eExpressionCompleted || !result_sp) Michael137 wrote: Yea that seems reasonable. Happy to address that in a separate patch (just to keep things simple for this particular fix) https://github.com/llvm/llvm-project/pull/143686 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add optional callback function to `TypeMatcher` (PR #143748)
labath wrote: A low-tech way to support both STL versions would be to do a dispatch inside the data formatter: ``` StdStringSummaryProvider(value) { if (IsGnuSTL(value)) return GnuStringSummaryProvider(value); return MSVCStringSummaryProvider(value); } ``` It's not a complete solution as it doesn't allow for a distributed setup (vendor A writes a formatter for type `Foo`, vendor B writes a formatter for its type `Foo`, user C needs to debug both `Foo` types, so it installs both formatters), but for formatters that are a part of lldb (i.e. STL types), that should work fine. And maybe STL types are the only place where this matters? https://github.com/llvm/llvm-project/pull/143748 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Commands][NFC] Extract memory find expression evaluation into helpers (PR #143686)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/143686 >From 94a2cae4dfee6d943eaa93bd089e1c0e61b54356 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Wed, 11 Jun 2025 12:02:44 +0100 Subject: [PATCH 1/4] [lldb][Commands][NFC] Extract memory find expression evaluation into helpers This patch factors out the `-e` option logic into two helper functions. The `EvaluateExpression` helper might seem redundant but I'll be adding to it in a follow-up patch to fix and issue when running `memory find -e` for Swift targets. Also adds test coverage for the error cases that were previously untested. rdar://152113525 --- lldb/source/Commands/CommandObjectMemory.cpp | 104 ++ .../memory/find/TestMemoryFind.py | 31 ++ .../API/functionalities/memory/find/main.cpp | 16 +++ 3 files changed, 108 insertions(+), 43 deletions(-) diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 7140333bb3cde..34230df9b2727 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -885,6 +885,55 @@ class CommandObjectMemoryRead : public CommandObjectParsed { #define LLDB_OPTIONS_memory_find #include "CommandOptions.inc" +static llvm::Error CopyExpressionResult(ValueObject &result, +DataBufferHeap &buffer) { + uint64_t value = result.GetValueAsUnsigned(0); + auto size_or_err = result.GetCompilerType().GetByteSize(nullptr); + if (!size_or_err) +return size_or_err.takeError(); + + switch (*size_or_err) { + case 1: { +uint8_t byte = (uint8_t)value; +buffer.CopyData(&byte, 1); + } break; + case 2: { +uint16_t word = (uint16_t)value; +buffer.CopyData(&word, 2); + } break; + case 4: { +uint32_t lword = (uint32_t)value; +buffer.CopyData(&lword, 4); + } break; + case 8: { +buffer.CopyData(&value, 8); + } break; + case 3: + case 5: + case 6: + case 7: +return llvm::createStringError("unknown type. pass a string instead"); + default: +return llvm::createStringError( +"result size larger than 8 bytes. pass a string instead"); + } + + return llvm::Error::success(); +} + +static llvm::Expected +EvaluateExpression(llvm::StringRef expression, StackFrame &frame, + Process &process) { + ValueObjectSP result_sp; + auto status = + process.GetTarget().EvaluateExpression(expression, &frame, result_sp); + if (status != eExpressionCompleted || !result_sp) +return llvm::createStringError( +"expression evaluation failed. pass a string instead"); + + return result_sp; +} + // Find the specified data in memory class CommandObjectMemoryFind : public CommandObjectParsed { public: @@ -1026,49 +1075,18 @@ class CommandObjectMemoryFind : public CommandObjectParsed { } buffer.CopyData(str); } else if (m_memory_options.m_expr.OptionWasSet()) { - StackFrame *frame = m_exe_ctx.GetFramePtr(); - ValueObjectSP result_sp; - if ((eExpressionCompleted == - process->GetTarget().EvaluateExpression( - m_memory_options.m_expr.GetValueAs().value_or( - ""), - frame, result_sp)) && - result_sp) { -uint64_t value = result_sp->GetValueAsUnsigned(0); -std::optional size = llvm::expectedToOptional( -result_sp->GetCompilerType().GetByteSize(nullptr)); -if (!size) - return; -switch (*size) { -case 1: { - uint8_t byte = (uint8_t)value; - buffer.CopyData(&byte, 1); -} break; -case 2: { - uint16_t word = (uint16_t)value; - buffer.CopyData(&word, 2); -} break; -case 4: { - uint32_t lword = (uint32_t)value; - buffer.CopyData(&lword, 4); -} break; -case 8: { - buffer.CopyData(&value, 8); -} break; -case 3: -case 5: -case 6: -case 7: - result.AppendError("unknown type. pass a string instead"); - return; -default: - result.AppendError( - "result size larger than 8 bytes. pass a string instead"); - return; -} - } else { -result.AppendError( -"expression evaluation failed. pass a string instead"); + auto result_or_err = EvaluateExpression( + m_memory_options.m_expr.GetValueAs().value_or(""), + m_exe_ctx.GetFrameRef(), *process); + if (!result_or_err) { +result.AppendError(llvm::toString(result_or_err.takeError())); +return; + } + + ValueObjectSP result_sp = *result_or_err; + + if (auto err = CopyExpressionResult(*result_sp, buffer)) { +result.AppendError(llvm::toString(std::move(err))); return; } } else { diff --git a/lldb/test/API/functionalities/memory/find/TestMemoryFind.py b/lldb/te
[Lldb-commits] [lldb] [lldb][Commands][NFC] Extract memory find expression evaluation into helpers (PR #143686)
github-actions[bot] wrote: :warning: Python code formatter, darker found issues in your code. :warning: You can test this locally with the following command: ``bash darker --check --diff -r HEAD~1...HEAD lldb/test/API/functionalities/memory/find/TestMemoryFind.py `` View the diff from darker here. ``diff --- TestMemoryFind.py 2025-06-12 13:53:13.00 + +++ TestMemoryFind.py 2025-06-12 13:56:17.320272 + @@ -81,32 +81,42 @@ ) # Expression results with unsupported result types. self.expect( 'memory find -e "ThreeBytes{}" `&bytedata[0]` `&bytedata[2]`', -substrs=["Only expressions resulting in 1, 2, 4, or 8-byte-sized values are supported"], +substrs=[ +"Only expressions resulting in 1, 2, 4, or 8-byte-sized values are supported" +], error=True, ) self.expect( 'memory find -e "FiveBytes{}" `&bytedata[0]` `&bytedata[2]`', -substrs=["Only expressions resulting in 1, 2, 4, or 8-byte-sized values are supported"], +substrs=[ +"Only expressions resulting in 1, 2, 4, or 8-byte-sized values are supported" +], error=True, ) self.expect( 'memory find -e "SixBytes{}" `&bytedata[0]` `&bytedata[2]`', -substrs=["Only expressions resulting in 1, 2, 4, or 8-byte-sized values are supported"], +substrs=[ +"Only expressions resulting in 1, 2, 4, or 8-byte-sized values are supported" +], error=True, ) self.expect( 'memory find -e "SevenBytes{}" `&bytedata[0]` `&bytedata[2]`', -substrs=["Only expressions resulting in 1, 2, 4, or 8-byte-sized values are supported"], +substrs=[ +"Only expressions resulting in 1, 2, 4, or 8-byte-sized values are supported" +], error=True, ) self.expect( 'memory find -e "NineBytes{}" `&bytedata[0]` `&bytedata[2]`', -substrs=["Only expressions resulting in 1, 2, 4, or 8-byte-sized values are supported"], +substrs=[ +"Only expressions resulting in 1, 2, 4, or 8-byte-sized values are supported" +], error=True, ) `` https://github.com/llvm/llvm-project/pull/143686 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF ParseSymtab handling (PR #141577)
DhruvSrivastavaX wrote: Got it @labath, I have added the updates accordingly. Hope this patch serves the purpose. 🙂 > The code is fine, but you should really add a test for it. You don't need to > wait for lldb-test to grow symtab support. You can write a test that does > something like: > > ``` > # RUN: yaml2obj %s > %t > # RUN: %lldb %t -o "image dump symtab" -o exit | FileCheck %s > # CHECK: symtab contents > ``` > > If you grep for "image dump symtab", you can find some existing tests to > emulate. > > I also feel I need to say something about comments. The most useful kind of > comment is the one that answers the "why" question. Most of your comments try > to answer the "what". Ideally the code should be clear enough that I can tell > _what_ it is doing without reading the comment. The part that's often not > obvious is **why** is it doing that. > > Taking this as an example: > > ``` > // Remove the dot prefix from symbol names before adding to symtab. > '.text' > // -> 'text' > ``` > > The comment is not bad, but it's not that helpful as I can deduce that from > the code. When reading this, the questions I have are: > > * why are we doing that? > * who adds the "." and why? > * what would happen if we didn't do that? > * etc. > > This isn't a hard requirement for the patch, but please keep this in mind. https://github.com/llvm/llvm-project/pull/141577 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][test] Don't call SBDebugger::Terminate if TestMultipleDebuggers times out (PR #143732)
https://github.com/DavidSpickett updated https://github.com/llvm/llvm-project/pull/143732 >From 8ab827fab1dc9fed30b28f03b545f78d96af7946 Mon Sep 17 00:00:00 2001 From: David Spickett Date: Wed, 11 Jun 2025 15:29:29 + Subject: [PATCH 1/2] [lldb][test] Don't call SBDebugger::Terminate if TestMultipleDebuggers times out Fixes #101162 This test did this: * SBDebugger::Initialize * Spawn a bunch of threads that do * SBDebugger::Create * some work * SBDebugger::Destroy * Wait on those threads to finish then call SBDebugger::Terminate, or - * Reach a time limit before all the threads finish, call SBDebugger::Terminate and exit. The problem was that in the timeout case, calling SBDebugger::Terminate destroys data being used by threads that are still running. This test was expecting said threads to be so broken they were probably stuck, but when the machine is just heavily loaded, one of them might read that data before the whole program can exit. This means what should have been a timeout is now a crash. Sometimes. Which explains why we saw both timeouts and various signals on the AArch64 Linux bot. It depends on the timings. So I'm changing it not to call SBDebugger::Terminate in the timeout case. We will have to tweak the timeout value based on what happens on the buildbot. --- lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py | 2 -- lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py b/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py index 1fd4806cd74f4..f0a3893f53aab 100644 --- a/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py +++ b/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py @@ -12,8 +12,6 @@ class TestMultipleSimultaneousDebuggers(TestBase): NO_DEBUG_INFO_TESTCASE = True -# Sometimes times out on Linux, see https://github.com/llvm/llvm-project/issues/101162. -@skipIfLinux @skipIfNoSBHeaders @skipIfWindows @skipIfHostIncompatibleWithTarget diff --git a/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp b/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp index 64728fb7c29a1..fcec9bae0ed9c 100644 --- a/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp +++ b/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp @@ -296,6 +296,8 @@ int main (int argc, char **argv) NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS); } -SBDebugger::Terminate(); +// We do not call SBDebugger::Terminate() here because it will destroy +// data that might be being used by threads that are still running. Which +// would change the timeout into an unrelated crash. exit (1); } >From 102139ca0bb03c7325d95fa26c8c6acaa02a912b Mon Sep 17 00:00:00 2001 From: David Spickett Date: Thu, 12 Jun 2025 14:24:38 + Subject: [PATCH 2/2] _exit --- lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp b/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp index fcec9bae0ed9c..5ad75e3c1e472 100644 --- a/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp +++ b/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp @@ -299,5 +299,6 @@ int main (int argc, char **argv) // We do not call SBDebugger::Terminate() here because it will destroy // data that might be being used by threads that are still running. Which // would change the timeout into an unrelated crash. -exit (1); +// _exit instead of exit, to skip more things that could cause a crash. +_exit(1); } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][test] Don't call SBDebugger::Terminate if TestMultipleDebuggers times out (PR #143732)
https://github.com/DavidSpickett edited https://github.com/llvm/llvm-project/pull/143732 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][test] Don't call SBDebugger::Terminate if TestMultipleDebuggers times out (PR #143732)
DavidSpickett wrote: Then what I'm doing is narrowing the window in which crashes could happen, but not closing it. _exit seems more safe for the timeout situation. If there's a genuine bug then yes anything could happen but at least we'd be rewarded for looking into it when it did. If there's still flakiness, I'll declare this impossible to get 100% right and disable it again. I did think I could send a signal from the main thread, but other threads continue running so that doesn't work. Unless it's SIGSTOP, but you can't catch that, and I don't know what return code we'd end up with. https://github.com/llvm/llvm-project/pull/143732 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 1c1df94 - [lldb][Commands][NFC] Extract memory find expression evaluation into helpers (#143686)
Author: Michael Buch Date: 2025-06-12T16:48:57+01:00 New Revision: 1c1df94d09820959c771cb4aaae4d36cdf5cab5a URL: https://github.com/llvm/llvm-project/commit/1c1df94d09820959c771cb4aaae4d36cdf5cab5a DIFF: https://github.com/llvm/llvm-project/commit/1c1df94d09820959c771cb4aaae4d36cdf5cab5a.diff LOG: [lldb][Commands][NFC] Extract memory find expression evaluation into helpers (#143686) This patch factors out the `-e` option logic into two helper functions. The `EvaluateExpression` helper might seem redundant but I'll be adding to it in a follow-up patch to fix an issue when running `memory find -e` for Swift targets. Also adds test coverage for the error cases that were previously untested. rdar://152113525 Added: Modified: lldb/source/Commands/CommandObjectMemory.cpp lldb/test/API/functionalities/memory/find/TestMemoryFind.py lldb/test/API/functionalities/memory/find/main.cpp Removed: diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 7140333bb3cde..85ae9f8f9e8cb 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -885,6 +885,52 @@ class CommandObjectMemoryRead : public CommandObjectParsed { #define LLDB_OPTIONS_memory_find #include "CommandOptions.inc" +static llvm::Error CopyExpressionResult(ValueObject &result, +DataBufferHeap &buffer) { + uint64_t value = result.GetValueAsUnsigned(0); + auto size_or_err = result.GetCompilerType().GetByteSize(nullptr); + if (!size_or_err) +return size_or_err.takeError(); + + switch (*size_or_err) { + case 1: { +uint8_t byte = (uint8_t)value; +buffer.CopyData(&byte, 1); + } break; + case 2: { +uint16_t word = (uint16_t)value; +buffer.CopyData(&word, 2); + } break; + case 4: { +uint32_t lword = (uint32_t)value; +buffer.CopyData(&lword, 4); + } break; + case 8: { +buffer.CopyData(&value, 8); + } break; + default: +return llvm::createStringError( +"Only expressions resulting in 1, 2, 4, or 8-byte-sized values are " +"supported. For other pattern sizes the --string (-s) option may be " +"used."); + } + + return llvm::Error::success(); +} + +static llvm::Expected +EvaluateExpression(llvm::StringRef expression, StackFrame &frame, + Process &process) { + ValueObjectSP result_sp; + auto status = + process.GetTarget().EvaluateExpression(expression, &frame, result_sp); + if (status != eExpressionCompleted || !result_sp) +return llvm::createStringError( +"expression evaluation failed. pass a string instead"); + + return result_sp; +} + // Find the specified data in memory class CommandObjectMemoryFind : public CommandObjectParsed { public: @@ -1026,49 +1072,18 @@ class CommandObjectMemoryFind : public CommandObjectParsed { } buffer.CopyData(str); } else if (m_memory_options.m_expr.OptionWasSet()) { - StackFrame *frame = m_exe_ctx.GetFramePtr(); - ValueObjectSP result_sp; - if ((eExpressionCompleted == - process->GetTarget().EvaluateExpression( - m_memory_options.m_expr.GetValueAs().value_or( - ""), - frame, result_sp)) && - result_sp) { -uint64_t value = result_sp->GetValueAsUnsigned(0); -std::optional size = llvm::expectedToOptional( -result_sp->GetCompilerType().GetByteSize(nullptr)); -if (!size) - return; -switch (*size) { -case 1: { - uint8_t byte = (uint8_t)value; - buffer.CopyData(&byte, 1); -} break; -case 2: { - uint16_t word = (uint16_t)value; - buffer.CopyData(&word, 2); -} break; -case 4: { - uint32_t lword = (uint32_t)value; - buffer.CopyData(&lword, 4); -} break; -case 8: { - buffer.CopyData(&value, 8); -} break; -case 3: -case 5: -case 6: -case 7: - result.AppendError("unknown type. pass a string instead"); - return; -default: - result.AppendError( - "result size larger than 8 bytes. pass a string instead"); - return; -} - } else { -result.AppendError( -"expression evaluation failed. pass a string instead"); + auto result_or_err = EvaluateExpression( + m_memory_options.m_expr.GetValueAs().value_or(""), + m_exe_ctx.GetFrameRef(), *process); + if (!result_or_err) { +result.AppendError(llvm::toString(result_or_err.takeError())); +return; + } + + ValueObjectSP result_sp = *result_or_err; + + if (auto err = CopyExpressionResult(*result_sp, buffer)) { +result.AppendError(llvm::toString(std::move(err))); return;
[Lldb-commits] [lldb] [lldb][Commands][NFC] Extract memory find expression evaluation into helpers (PR #143686)
https://github.com/Michael137 closed https://github.com/llvm/llvm-project/pull/143686 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Reland "[lldb][headers] Create Python script to fix up framework head… (PR #143945)
https://github.com/chelcassanova created https://github.com/llvm/llvm-project/pull/143945 …ers" (#143941) Reland the script that converts lldb headers to RPC headers. The RPC test was failing due to the incorrect input filepath being used. >From 835528c8926e933ab2c24482c562f5811e0065e4 Mon Sep 17 00:00:00 2001 From: Chelsea Cassanova Date: Thu, 12 Jun 2025 10:46:36 -0700 Subject: [PATCH] Reland "[lldb][headers] Create Python script to fix up framework headers" (#143941) Reland the script that converts lldb headers to RPC headers. The RPC test was failing due to the incorrect input filepath being used. --- lldb/cmake/modules/LLDBFramework.cmake| 42 +++--- lldb/scripts/framework-header-fix.py | 126 ++ .../Shell/Scripts/Inputs/Main/SBAddress.h | 13 ++ .../Shell/Scripts/Inputs/RPC/RPCSBAddress.h | 9 ++ .../Shell/Scripts/TestFrameworkFixScript.test | 11 ++ .../Scripts/TestFrameworkFixUnifdef.test | 12 ++ .../Scripts/TestRPCFrameworkFixScript.test| 14 ++ 7 files changed, 206 insertions(+), 21 deletions(-) create mode 100755 lldb/scripts/framework-header-fix.py create mode 100644 lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h create mode 100644 lldb/test/Shell/Scripts/Inputs/RPC/RPCSBAddress.h create mode 100644 lldb/test/Shell/Scripts/TestFrameworkFixScript.test create mode 100644 lldb/test/Shell/Scripts/TestFrameworkFixUnifdef.test create mode 100644 lldb/test/Shell/Scripts/TestRPCFrameworkFixScript.test diff --git a/lldb/cmake/modules/LLDBFramework.cmake b/lldb/cmake/modules/LLDBFramework.cmake index 8961b1afe93ad..70010ffbf738c 100644 --- a/lldb/cmake/modules/LLDBFramework.cmake +++ b/lldb/cmake/modules/LLDBFramework.cmake @@ -68,24 +68,17 @@ if(NOT APPLE_EMBEDDED) ) endif() -# At configuration time, collect headers for the framework bundle and copy them -# into a staging directory. Later we can copy over the entire folder. -file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h) -set(generated_public_headers ${LLDB_OBJ_DIR}/include/lldb/API/SBLanguages.h) -file(GLOB root_public_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-*.h) -file(GLOB root_private_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h) -list(REMOVE_ITEM root_public_headers ${root_private_headers}) - find_program(unifdef_EXECUTABLE unifdef) -set(lldb_header_staging ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders) -foreach(header -${public_headers} -${generated_public_headers} -${root_public_headers}) +# All necessary header files will be staged in the include directory in the build directory, +# so just copy the files from there into the framework's staging directory. +set(lldb_build_dir_header_staging "${CMAKE_BINARY_DIR}/include/lldb") +set(lldb_framework_header_staging "${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders") +file(GLOB lldb_build_dir_header_staging_list ${lldb_build_dir_header_staging}/*) +foreach(header ${lldb_build_dir_header_staging_list}) get_filename_component(basename ${header} NAME) - set(staged_header ${lldb_header_staging}/${basename}) + set(staged_header ${lldb_framework_header_staging}/${basename}) if(unifdef_EXECUTABLE) # unifdef returns 0 when the file is unchanged and 1 if something was changed. @@ -112,13 +105,20 @@ set_target_properties(liblldb-resource-headers PROPERTIES FOLDER "LLDB/Resources add_dependencies(liblldb-resource-headers liblldb-header-staging) add_dependencies(liblldb liblldb-resource-headers) -# At build time, copy the staged headers into the framework bundle (and do -# some post-processing in-place). -add_custom_command(TARGET liblldb POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory ${lldb_header_staging} $/Headers - COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.sh $/Headers ${LLDB_VERSION} - COMMENT "LLDB.framework: copy framework headers" -) +# Take the headers from the staging directory and fix up their includes for the framework. +# Then write them to the output directory. +# Also, run unifdef to remove any specified guards from the header files. +file(GLOB lldb_framework_header_staging_list ${lldb_framework_header_staging}/*) +foreach(header ${lldb_framework_header_staging_list}) + + set(input_header ${header}) + set(output_header $/Headers/${input_header}) + + add_custom_command(TARGET liblldb POST_BUILD +COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.py -f lldb_main -i ${input_header} -o ${output_header} -p ${unifdef_EXECUTABLE} USWIG +COMMENT "LLDB.framework: Fix up and copy framework headers" + ) +endforeach() # Copy vendor-specific headers from clang (without staging). if(NOT APPLE_EMBEDDED) diff --git a/lldb/scripts/framework-header-fix.py b/lldb/scripts/framework-header-fix.py new file mode 100755 index 0..9e4e5f860a2c0 --- /dev/null +++ b/lldb/scripts/framework-header-fix.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python3 + +""" +Usage: + +This script is used when building LLDB.framework or
[Lldb-commits] [lldb] Reland "[lldb][headers] Create Python script to fix up framework head… (PR #143945)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Chelsea Cassanova (chelcassanova) Changes …ers" (#143941) Reland the script that converts lldb headers to RPC headers. The RPC test was failing due to the incorrect input filepath being used. --- Full diff: https://github.com/llvm/llvm-project/pull/143945.diff 7 Files Affected: - (modified) lldb/cmake/modules/LLDBFramework.cmake (+21-21) - (added) lldb/scripts/framework-header-fix.py (+126) - (added) lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h (+13) - (added) lldb/test/Shell/Scripts/Inputs/RPC/RPCSBAddress.h (+9) - (added) lldb/test/Shell/Scripts/TestFrameworkFixScript.test (+11) - (added) lldb/test/Shell/Scripts/TestFrameworkFixUnifdef.test (+12) - (added) lldb/test/Shell/Scripts/TestRPCFrameworkFixScript.test (+14) ``diff diff --git a/lldb/cmake/modules/LLDBFramework.cmake b/lldb/cmake/modules/LLDBFramework.cmake index 8961b1afe93ad..70010ffbf738c 100644 --- a/lldb/cmake/modules/LLDBFramework.cmake +++ b/lldb/cmake/modules/LLDBFramework.cmake @@ -68,24 +68,17 @@ if(NOT APPLE_EMBEDDED) ) endif() -# At configuration time, collect headers for the framework bundle and copy them -# into a staging directory. Later we can copy over the entire folder. -file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h) -set(generated_public_headers ${LLDB_OBJ_DIR}/include/lldb/API/SBLanguages.h) -file(GLOB root_public_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-*.h) -file(GLOB root_private_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h) -list(REMOVE_ITEM root_public_headers ${root_private_headers}) - find_program(unifdef_EXECUTABLE unifdef) -set(lldb_header_staging ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders) -foreach(header -${public_headers} -${generated_public_headers} -${root_public_headers}) +# All necessary header files will be staged in the include directory in the build directory, +# so just copy the files from there into the framework's staging directory. +set(lldb_build_dir_header_staging "${CMAKE_BINARY_DIR}/include/lldb") +set(lldb_framework_header_staging "${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders") +file(GLOB lldb_build_dir_header_staging_list ${lldb_build_dir_header_staging}/*) +foreach(header ${lldb_build_dir_header_staging_list}) get_filename_component(basename ${header} NAME) - set(staged_header ${lldb_header_staging}/${basename}) + set(staged_header ${lldb_framework_header_staging}/${basename}) if(unifdef_EXECUTABLE) # unifdef returns 0 when the file is unchanged and 1 if something was changed. @@ -112,13 +105,20 @@ set_target_properties(liblldb-resource-headers PROPERTIES FOLDER "LLDB/Resources add_dependencies(liblldb-resource-headers liblldb-header-staging) add_dependencies(liblldb liblldb-resource-headers) -# At build time, copy the staged headers into the framework bundle (and do -# some post-processing in-place). -add_custom_command(TARGET liblldb POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory ${lldb_header_staging} $/Headers - COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.sh $/Headers ${LLDB_VERSION} - COMMENT "LLDB.framework: copy framework headers" -) +# Take the headers from the staging directory and fix up their includes for the framework. +# Then write them to the output directory. +# Also, run unifdef to remove any specified guards from the header files. +file(GLOB lldb_framework_header_staging_list ${lldb_framework_header_staging}/*) +foreach(header ${lldb_framework_header_staging_list}) + + set(input_header ${header}) + set(output_header $/Headers/${input_header}) + + add_custom_command(TARGET liblldb POST_BUILD +COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.py -f lldb_main -i ${input_header} -o ${output_header} -p ${unifdef_EXECUTABLE} USWIG +COMMENT "LLDB.framework: Fix up and copy framework headers" + ) +endforeach() # Copy vendor-specific headers from clang (without staging). if(NOT APPLE_EMBEDDED) diff --git a/lldb/scripts/framework-header-fix.py b/lldb/scripts/framework-header-fix.py new file mode 100755 index 0..9e4e5f860a2c0 --- /dev/null +++ b/lldb/scripts/framework-header-fix.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python3 + +""" +Usage: + +This script is used when building LLDB.framework or LLDBRPC.framework. For each framework, local includes are converted to their respective framework includes. + +This script is used in 2 ways: +1. It is used on header files that are copied into LLDB.framework. For these files, local LLDB includes are converted into framework includes, e.g. #include "lldb/API/SBDefines.h" -> #include . + +2. It is used on header files for LLDBRPC.framework. For these files, includes of RPC common files will be converted to framework includes, e.g. #include -> #include . It will also change local includes to framework includes, e.g. #include "SBAddress.h" -> #include +""" + +import argparse +import os +import re +import shutil +import
[Lldb-commits] [lld] [lldb] [llvm] [lit] cleanup unused imports (PR #143930)
https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/143930 >From 900a01df2892660602c837b0ad0335238337197e Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Thu, 12 Jun 2025 17:36:06 +0100 Subject: [PATCH 1/2] [lit] cleanup unused imports --- lld/test/Unit/lit.cfg.py | 1 - lldb/test/API/lit.cfg.py | 2 -- lldb/test/Shell/lit.cfg.py | 4 lldb/test/lit.cfg.py | 3 --- llvm/utils/lit/lit/LitConfig.py | 6 ++ llvm/utils/lit/lit/TestRunner.py | 6 -- llvm/utils/lit/lit/discovery.py | 2 +- llvm/utils/lit/lit/worker.py | 2 -- 8 files changed, 3 insertions(+), 23 deletions(-) diff --git a/lld/test/Unit/lit.cfg.py b/lld/test/Unit/lit.cfg.py index 1cf890a05cb28..47375db517e96 100644 --- a/lld/test/Unit/lit.cfg.py +++ b/lld/test/Unit/lit.cfg.py @@ -3,7 +3,6 @@ # Configuration file for the 'lit' test runner. import os -import subprocess import lit.formats diff --git a/lldb/test/API/lit.cfg.py b/lldb/test/API/lit.cfg.py index 646a446c86fdb..04b360e8d3307 100644 --- a/lldb/test/API/lit.cfg.py +++ b/lldb/test/API/lit.cfg.py @@ -9,8 +9,6 @@ import subprocess import sys -import lit.formats - # name: The name of this test suite. config.name = "lldb-api" diff --git a/lldb/test/Shell/lit.cfg.py b/lldb/test/Shell/lit.cfg.py index ab6113767187a..02a70c98d86bc 100644 --- a/lldb/test/Shell/lit.cfg.py +++ b/lldb/test/Shell/lit.cfg.py @@ -7,12 +7,8 @@ import shutil import site import subprocess -import sys -import lit.formats from lit.llvm import llvm_config -from lit.llvm.subst import FindTool -from lit.llvm.subst import ToolSubst site.addsitedir(os.path.dirname(__file__)) from helper import toolchain diff --git a/lldb/test/lit.cfg.py b/lldb/test/lit.cfg.py index eefc32aabd16d..6a4255c2627d9 100644 --- a/lldb/test/lit.cfg.py +++ b/lldb/test/lit.cfg.py @@ -2,9 +2,6 @@ import os -import lit.formats -from lit.llvm import llvm_config - # This is the top level configuration. Most of these configuration options will # be overriden by individual lit configuration files in the test # subdirectories. Anything configured here will *not* be loaded when pointing diff --git a/llvm/utils/lit/lit/LitConfig.py b/llvm/utils/lit/lit/LitConfig.py index cb4aef6f72a87..5bb2d3c5c986c 100644 --- a/llvm/utils/lit/lit/LitConfig.py +++ b/llvm/utils/lit/lit/LitConfig.py @@ -1,14 +1,12 @@ from __future__ import absolute_import + import inspect import os -import platform import sys -import lit.Test -import lit.formats -import lit.TestingConfig import lit.util + # LitConfig must be a new style class for properties to work class LitConfig(object): """LitConfig - Configuration data for a 'lit' test runner instance, shared diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py index 73db67aedb739..1d3bf8e4e8df1 100644 --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -1,7 +1,4 @@ from __future__ import absolute_import -import errno -import io -import itertools import getopt import os, signal, subprocess, sys import re @@ -12,11 +9,8 @@ import shutil import tempfile import threading -import typing from typing import Optional, Tuple -import io - try: from StringIO import StringIO except ImportError: diff --git a/llvm/utils/lit/lit/discovery.py b/llvm/utils/lit/lit/discovery.py index 2e7f90c6bb0c9..2e93bacc12368 100644 --- a/llvm/utils/lit/lit/discovery.py +++ b/llvm/utils/lit/lit/discovery.py @@ -6,8 +6,8 @@ import os import sys +from lit import Test, util from lit.TestingConfig import TestingConfig -from lit import LitConfig, Test, util def chooseConfigFileFromDir(dir, config_names): diff --git a/llvm/utils/lit/lit/worker.py b/llvm/utils/lit/lit/worker.py index 8e78bfd45d38b..dbc3ab53bc627 100644 --- a/llvm/utils/lit/lit/worker.py +++ b/llvm/utils/lit/lit/worker.py @@ -12,8 +12,6 @@ import traceback import lit.Test -import lit.util - _lit_config = None _parallelism_semaphores = None >From 33922468cc60623a983d8e98eafdc77a0c989261 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Thu, 12 Jun 2025 19:11:23 +0100 Subject: [PATCH 2/2] fixup! [lit] cleanup unused imports --- lldb/test/Shell/lit.cfg.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lldb/test/Shell/lit.cfg.py b/lldb/test/Shell/lit.cfg.py index 02a70c98d86bc..6f0e017fb7cb9 100644 --- a/lldb/test/Shell/lit.cfg.py +++ b/lldb/test/Shell/lit.cfg.py @@ -8,6 +8,7 @@ import site import subprocess +import lit.util from lit.llvm import llvm_config site.addsitedir(os.path.dirname(__file__)) ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][RPC] Upstream lldb-rpc-gen tool (PR #138031)
@@ -0,0 +1,504 @@ +//===-- RPCCommon.cpp -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "RPCCommon.h" + +#include "clang/AST/AST.h" +#include "clang/AST/Attr.h" +#include "clang/AST/DeclBase.h" +#include "clang/AST/Mangle.h" +#include "clang/Lex/Lexer.h" + +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/raw_ostream.h" + +using namespace clang; + +// We intentionally do not generate some classes because they are currently +// inconvenient, they aren't really used by most consumers, or we're not sure +// why they exist. +static constexpr llvm::StringRef DisallowedClasses[] = { +"SBCommunication", // This class is pretty much unused by consumers, so we + // skip it. +"SBInputReader", // This class is pretty much unused by consumers, so we + // skip it. +"SBCommandPluginInterface", // This class uses virtual functions, and the SB +// API should not have those, so we skip this +// class. +"SBCommand", // There's nothing too difficult about this one, but many of + // its methods take a SBCommandPluginInterface pointer so + // there's no reason to support this. +}; + +// NOTE: In lldb-rpc-gen, we use mangled names when we need to work with +// functions. We do this because we support many functions that have overloads, +// and mangled names have no ambiguity which makes it easier to keep track of. +// This is also possible since the LLDB SB API is stable. + +// We intentionally avoid generating certain methods either because they are +// difficult to support correctly or they aren't really used much from C++. +// NOTE: These methods are marked as deprecated using LLDB_DEPRECATED. +// Normally this macro defines to the deprecated annotation, but this +// functionality is removed in SBDefines.h when generating SWIG bindings which +// we use for testing. Because of this, there is no annotation for the tool to +// pick up on so this list will be used while we have this restriction in +// SBDefines.h. +static constexpr llvm::StringRef DisallowedMethods[] = { +// The threading functionality in SBHostOS is deprecated and thus we do not +// generate them. It would be ideal to add the annotations to the methods +// and then support not generating deprecated methods. However, without +// annotations the generator generates most things correctly. This one is +// problematic because it returns a pointer to an "opaque" structure +// (thread_t) that is not `void *`, so special casing it is more effort than +// it's worth. +"_ZN4lldb8SBHostOS10ThreadJoinEP17_opaque_pthread_tPPvPNS_7SBErrorE", +"_ZN4lldb8SBHostOS12ThreadCancelEP17_opaque_pthread_tPNS_7SBErrorE", +"_ZN4lldb8SBHostOS12ThreadCreateEPKcPFPvS3_ES3_PNS_7SBErrorE", +"_ZN4lldb8SBHostOS12ThreadDetachEP17_opaque_pthread_tPNS_7SBErrorE", +"_ZN4lldb8SBHostOS13ThreadCreatedEPKc", +}; + +static constexpr llvm::StringRef ClassesWithoutDefaultCtor[] = { +"SBHostOS", +"SBReproducer", +}; + +static constexpr llvm::StringRef ClassesWithoutCopyOperations[] = { +"SBHostOS", +"SBReproducer", +"SBStream", +"SBProgress", +}; + +static constexpr llvm::StringRef MethodsWithPointerPlusLen[] = { +"_ZN4lldb6SBData11ReadRawDataERNS_7SBErrorEyPvm", +"_ZN4lldb6SBData7SetDataERNS_7SBErrorEPKvmNS_9ByteOrderEh", +"_ZN4lldb6SBData20SetDataWithOwnershipERNS_7SBErrorEPKvmNS_9ByteOrderEh", +"_ZN4lldb6SBData25CreateDataFromUInt64ArrayENS_9ByteOrderEjPym", +"_ZN4lldb6SBData25CreateDataFromUInt32ArrayENS_9ByteOrderEjPjm", +"_ZN4lldb6SBData25CreateDataFromSInt64ArrayENS_9ByteOrderEjPxm", +"_ZN4lldb6SBData25CreateDataFromSInt32ArrayENS_9ByteOrderEjPim", +"_ZN4lldb6SBData25CreateDataFromDoubleArrayENS_9ByteOrderEjPdm", +"_ZN4lldb6SBData22SetDataFromUInt64ArrayEPym", +"_ZN4lldb6SBData22SetDataFromUInt32ArrayEPjm", +"_ZN4lldb6SBData22SetDataFromSInt64ArrayEPxm", +"_ZN4lldb6SBData22SetDataFromSInt32ArrayEPim", +"_ZN4lldb6SBData22SetDataFromDoubleArrayEPdm", +"_ZN4lldb10SBDebugger22GetDefaultArchitectureEPcm", +"_ZN4lldb10SBDebugger13DispatchInputEPvPKvm", +"_ZN4lldb10SBDebugger13DispatchInputEPKvm", +"_ZN4lldb6SBFile4ReadEPhmPm", +"_ZN4lldb6SBFile5WriteEPKhmPm", +"_ZNK4lldb10SBFileSpec7GetPathEPcm", +"_ZN4lldb10SBFileSpec11ResolvePathEPKcPcm", +"_ZN4lldb8SBModule10GetVersionEPjj", +"_ZN4lldb12SBModuleSpec12SetUUIDBytesEPKhm", +"_ZNK4lldb9SBProcess9Get
[Lldb-commits] [lldb] [lldb] Implement JSON RPC (newline delimited) Transport (PR #143946)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/143946 This PR implements JSON RPC-style (i.e. newline delimited) JSON transport. I moved the existing transport tests from DAP to Host and moved the PipeTest base class into TestingSupport so it can be shared by both. >From 9ebb3986e008cec978c0111557a02a9a8d720838 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 12 Jun 2025 11:19:15 -0700 Subject: [PATCH] [lldb] Implement JSON RPC (newline delimited) Transport This PR implements JSON RPC-style (i.e. newline delimited) JSON transport. I moved the existing transport tests from DAP to Host and moved the PipeTest base class into TestingSupport so it can be shared by both. --- lldb/include/lldb/Host/JSONTransport.h| 15 ++ lldb/source/Host/common/JSONTransport.cpp | 31 +++- lldb/unittests/DAP/CMakeLists.txt | 1 - lldb/unittests/DAP/TestBase.cpp | 7 +- lldb/unittests/DAP/TestBase.h | 13 +- lldb/unittests/DAP/TransportTest.cpp | 98 lldb/unittests/Host/CMakeLists.txt| 1 + lldb/unittests/Host/JSONTransportTest.cpp | 146 ++ .../TestingSupport/Host/PipeTestUtilities.h | 28 9 files changed, 223 insertions(+), 117 deletions(-) delete mode 100644 lldb/unittests/DAP/TransportTest.cpp create mode 100644 lldb/unittests/Host/JSONTransportTest.cpp create mode 100644 lldb/unittests/TestingSupport/Host/PipeTestUtilities.h diff --git a/lldb/include/lldb/Host/JSONTransport.h b/lldb/include/lldb/Host/JSONTransport.h index 4db5e417ea852..f7593750669e1 100644 --- a/lldb/include/lldb/Host/JSONTransport.h +++ b/lldb/include/lldb/Host/JSONTransport.h @@ -121,6 +121,21 @@ class HTTPDelimitedJSONTransport : public JSONTransport { static constexpr llvm::StringLiteral kHeaderSeparator = "\r\n\r\n"; }; +/// A transport class for JSON RPC. +class JSONRPCTransport : public JSONTransport { +public: + JSONRPCTransport(lldb::IOObjectSP input, lldb::IOObjectSP output) + : JSONTransport(input, output) {} + virtual ~JSONRPCTransport() = default; + +protected: + virtual llvm::Error WriteImpl(const std::string &message) override; + virtual llvm::Expected + ReadImpl(const std::chrono::microseconds &timeout) override; + + static constexpr llvm::StringLiteral kMessageSeparator = "\n"; +}; + } // namespace lldb_private #endif diff --git a/lldb/source/Host/common/JSONTransport.cpp b/lldb/source/Host/common/JSONTransport.cpp index 103c76d25daf7..7b925372e0b74 100644 --- a/lldb/source/Host/common/JSONTransport.cpp +++ b/lldb/source/Host/common/JSONTransport.cpp @@ -92,7 +92,7 @@ void JSONTransport::Log(llvm::StringRef message) { Expected HTTPDelimitedJSONTransport::ReadImpl(const std::chrono::microseconds &timeout) { if (!m_input || !m_input->IsValid()) -return createStringError("transport output is closed"); +return llvm::make_error(); IOObject *input = m_input.get(); Expected message_header = @@ -142,6 +142,35 @@ Error HTTPDelimitedJSONTransport::WriteImpl(const std::string &message) { return m_output->Write(Output.data(), num_bytes).takeError(); } +Expected +JSONRPCTransport::ReadImpl(const std::chrono::microseconds &timeout) { + if (!m_input || !m_input->IsValid()) +return make_error(); + + IOObject *input = m_input.get(); + Expected raw_json = + ReadUntil(*input, kMessageSeparator, timeout); + if (!raw_json) +return raw_json.takeError(); + + Log(llvm::formatv("--> {0}", *raw_json).str()); + + return *raw_json; +} + +Error JSONRPCTransport::WriteImpl(const std::string &message) { + if (!m_output || !m_output->IsValid()) +return llvm::make_error(); + + Log(llvm::formatv("<-- {0}", message).str()); + + std::string Output; + llvm::raw_string_ostream OS(Output); + OS << message << kMessageSeparator; + size_t num_bytes = Output.size(); + return m_output->Write(Output.data(), num_bytes).takeError(); +} + char TransportEOFError::ID; char TransportTimeoutError::ID; char TransportClosedError::ID; diff --git a/lldb/unittests/DAP/CMakeLists.txt b/lldb/unittests/DAP/CMakeLists.txt index 37a6a81ad12a0..ee623d341ec69 100644 --- a/lldb/unittests/DAP/CMakeLists.txt +++ b/lldb/unittests/DAP/CMakeLists.txt @@ -7,7 +7,6 @@ add_lldb_unittest(DAPTests LLDBUtilsTest.cpp ProtocolTypesTest.cpp TestBase.cpp - TransportTest.cpp VariablesTest.cpp LINK_COMPONENTS diff --git a/lldb/unittests/DAP/TestBase.cpp b/lldb/unittests/DAP/TestBase.cpp index 4063b34250312..27ad42686fbbf 100644 --- a/lldb/unittests/DAP/TestBase.cpp +++ b/lldb/unittests/DAP/TestBase.cpp @@ -28,13 +28,8 @@ using lldb_private::File; using lldb_private::NativeFile; using lldb_private::Pipe; -void PipeBase::SetUp() { - ASSERT_THAT_ERROR(input.CreateNew(false).ToError(), Succeeded()); - ASSERT_THAT_ERROR(output.CreateNew(false).ToError(), Succeeded()); -} - void TransportBase::SetUp() { - PipeBase::SetUp(); + PipeTest
[Lldb-commits] [lldb] Reland "[lldb][headers] Create Python script to fix up framework head… (PR #143945)
https://github.com/chelcassanova updated https://github.com/llvm/llvm-project/pull/143945 >From 4f873a3ee458009541a7015cfa63a247bc792737 Mon Sep 17 00:00:00 2001 From: Chelsea Cassanova Date: Thu, 12 Jun 2025 10:46:36 -0700 Subject: [PATCH] Reland "[lldb][headers] Create Python script to fix up framework headers" (#143941) Reland the script that converts lldb headers to RPC headers. The RPC test was failing due to the incorrect input filepath being used. --- lldb/cmake/modules/LLDBFramework.cmake| 42 +++--- lldb/scripts/framework-header-fix.py | 126 ++ .../Shell/Scripts/Inputs/Main/SBAddress.h | 13 ++ .../Shell/Scripts/Inputs/RPC/RPCSBAddress.h | 9 ++ .../Shell/Scripts/TestFrameworkFixScript.test | 11 ++ .../Scripts/TestFrameworkFixUnifdef.test | 12 ++ .../Scripts/TestRPCFrameworkFixScript.test| 14 ++ 7 files changed, 206 insertions(+), 21 deletions(-) create mode 100755 lldb/scripts/framework-header-fix.py create mode 100644 lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h create mode 100644 lldb/test/Shell/Scripts/Inputs/RPC/RPCSBAddress.h create mode 100644 lldb/test/Shell/Scripts/TestFrameworkFixScript.test create mode 100644 lldb/test/Shell/Scripts/TestFrameworkFixUnifdef.test create mode 100644 lldb/test/Shell/Scripts/TestRPCFrameworkFixScript.test diff --git a/lldb/cmake/modules/LLDBFramework.cmake b/lldb/cmake/modules/LLDBFramework.cmake index 8961b1afe93ad..70010ffbf738c 100644 --- a/lldb/cmake/modules/LLDBFramework.cmake +++ b/lldb/cmake/modules/LLDBFramework.cmake @@ -68,24 +68,17 @@ if(NOT APPLE_EMBEDDED) ) endif() -# At configuration time, collect headers for the framework bundle and copy them -# into a staging directory. Later we can copy over the entire folder. -file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h) -set(generated_public_headers ${LLDB_OBJ_DIR}/include/lldb/API/SBLanguages.h) -file(GLOB root_public_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-*.h) -file(GLOB root_private_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h) -list(REMOVE_ITEM root_public_headers ${root_private_headers}) - find_program(unifdef_EXECUTABLE unifdef) -set(lldb_header_staging ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders) -foreach(header -${public_headers} -${generated_public_headers} -${root_public_headers}) +# All necessary header files will be staged in the include directory in the build directory, +# so just copy the files from there into the framework's staging directory. +set(lldb_build_dir_header_staging "${CMAKE_BINARY_DIR}/include/lldb") +set(lldb_framework_header_staging "${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders") +file(GLOB lldb_build_dir_header_staging_list ${lldb_build_dir_header_staging}/*) +foreach(header ${lldb_build_dir_header_staging_list}) get_filename_component(basename ${header} NAME) - set(staged_header ${lldb_header_staging}/${basename}) + set(staged_header ${lldb_framework_header_staging}/${basename}) if(unifdef_EXECUTABLE) # unifdef returns 0 when the file is unchanged and 1 if something was changed. @@ -112,13 +105,20 @@ set_target_properties(liblldb-resource-headers PROPERTIES FOLDER "LLDB/Resources add_dependencies(liblldb-resource-headers liblldb-header-staging) add_dependencies(liblldb liblldb-resource-headers) -# At build time, copy the staged headers into the framework bundle (and do -# some post-processing in-place). -add_custom_command(TARGET liblldb POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory ${lldb_header_staging} $/Headers - COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.sh $/Headers ${LLDB_VERSION} - COMMENT "LLDB.framework: copy framework headers" -) +# Take the headers from the staging directory and fix up their includes for the framework. +# Then write them to the output directory. +# Also, run unifdef to remove any specified guards from the header files. +file(GLOB lldb_framework_header_staging_list ${lldb_framework_header_staging}/*) +foreach(header ${lldb_framework_header_staging_list}) + + set(input_header ${header}) + set(output_header $/Headers/${input_header}) + + add_custom_command(TARGET liblldb POST_BUILD +COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.py -f lldb_main -i ${input_header} -o ${output_header} -p ${unifdef_EXECUTABLE} USWIG +COMMENT "LLDB.framework: Fix up and copy framework headers" + ) +endforeach() # Copy vendor-specific headers from clang (without staging). if(NOT APPLE_EMBEDDED) diff --git a/lldb/scripts/framework-header-fix.py b/lldb/scripts/framework-header-fix.py new file mode 100755 index 0..9e4e5f860a2c0 --- /dev/null +++ b/lldb/scripts/framework-header-fix.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python3 + +""" +Usage: + +This script is used when building LLDB.framework or LLDBRPC.framework. For each framework, local includes are converted to their respective framework includes. + +This script is used in 2 ways: +1. It is
[Lldb-commits] [lldb] [lldb] Implement JSON RPC (newline delimited) Transport (PR #143946)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes This PR implements JSON RPC-style (i.e. newline delimited) JSON transport. I moved the existing transport tests from DAP to Host and moved the PipeTest base class into TestingSupport so it can be shared by both. --- Full diff: https://github.com/llvm/llvm-project/pull/143946.diff 9 Files Affected: - (modified) lldb/include/lldb/Host/JSONTransport.h (+15) - (modified) lldb/source/Host/common/JSONTransport.cpp (+30-1) - (modified) lldb/unittests/DAP/CMakeLists.txt (-1) - (modified) lldb/unittests/DAP/TestBase.cpp (+1-6) - (modified) lldb/unittests/DAP/TestBase.h (+2-11) - (removed) lldb/unittests/DAP/TransportTest.cpp (-98) - (modified) lldb/unittests/Host/CMakeLists.txt (+1) - (added) lldb/unittests/Host/JSONTransportTest.cpp (+146) - (added) lldb/unittests/TestingSupport/Host/PipeTestUtilities.h (+28) ``diff diff --git a/lldb/include/lldb/Host/JSONTransport.h b/lldb/include/lldb/Host/JSONTransport.h index 4db5e417ea852..f7593750669e1 100644 --- a/lldb/include/lldb/Host/JSONTransport.h +++ b/lldb/include/lldb/Host/JSONTransport.h @@ -121,6 +121,21 @@ class HTTPDelimitedJSONTransport : public JSONTransport { static constexpr llvm::StringLiteral kHeaderSeparator = "\r\n\r\n"; }; +/// A transport class for JSON RPC. +class JSONRPCTransport : public JSONTransport { +public: + JSONRPCTransport(lldb::IOObjectSP input, lldb::IOObjectSP output) + : JSONTransport(input, output) {} + virtual ~JSONRPCTransport() = default; + +protected: + virtual llvm::Error WriteImpl(const std::string &message) override; + virtual llvm::Expected + ReadImpl(const std::chrono::microseconds &timeout) override; + + static constexpr llvm::StringLiteral kMessageSeparator = "\n"; +}; + } // namespace lldb_private #endif diff --git a/lldb/source/Host/common/JSONTransport.cpp b/lldb/source/Host/common/JSONTransport.cpp index 103c76d25daf7..7b925372e0b74 100644 --- a/lldb/source/Host/common/JSONTransport.cpp +++ b/lldb/source/Host/common/JSONTransport.cpp @@ -92,7 +92,7 @@ void JSONTransport::Log(llvm::StringRef message) { Expected HTTPDelimitedJSONTransport::ReadImpl(const std::chrono::microseconds &timeout) { if (!m_input || !m_input->IsValid()) -return createStringError("transport output is closed"); +return llvm::make_error(); IOObject *input = m_input.get(); Expected message_header = @@ -142,6 +142,35 @@ Error HTTPDelimitedJSONTransport::WriteImpl(const std::string &message) { return m_output->Write(Output.data(), num_bytes).takeError(); } +Expected +JSONRPCTransport::ReadImpl(const std::chrono::microseconds &timeout) { + if (!m_input || !m_input->IsValid()) +return make_error(); + + IOObject *input = m_input.get(); + Expected raw_json = + ReadUntil(*input, kMessageSeparator, timeout); + if (!raw_json) +return raw_json.takeError(); + + Log(llvm::formatv("--> {0}", *raw_json).str()); + + return *raw_json; +} + +Error JSONRPCTransport::WriteImpl(const std::string &message) { + if (!m_output || !m_output->IsValid()) +return llvm::make_error(); + + Log(llvm::formatv("<-- {0}", message).str()); + + std::string Output; + llvm::raw_string_ostream OS(Output); + OS << message << kMessageSeparator; + size_t num_bytes = Output.size(); + return m_output->Write(Output.data(), num_bytes).takeError(); +} + char TransportEOFError::ID; char TransportTimeoutError::ID; char TransportClosedError::ID; diff --git a/lldb/unittests/DAP/CMakeLists.txt b/lldb/unittests/DAP/CMakeLists.txt index 37a6a81ad12a0..ee623d341ec69 100644 --- a/lldb/unittests/DAP/CMakeLists.txt +++ b/lldb/unittests/DAP/CMakeLists.txt @@ -7,7 +7,6 @@ add_lldb_unittest(DAPTests LLDBUtilsTest.cpp ProtocolTypesTest.cpp TestBase.cpp - TransportTest.cpp VariablesTest.cpp LINK_COMPONENTS diff --git a/lldb/unittests/DAP/TestBase.cpp b/lldb/unittests/DAP/TestBase.cpp index 4063b34250312..27ad42686fbbf 100644 --- a/lldb/unittests/DAP/TestBase.cpp +++ b/lldb/unittests/DAP/TestBase.cpp @@ -28,13 +28,8 @@ using lldb_private::File; using lldb_private::NativeFile; using lldb_private::Pipe; -void PipeBase::SetUp() { - ASSERT_THAT_ERROR(input.CreateNew(false).ToError(), Succeeded()); - ASSERT_THAT_ERROR(output.CreateNew(false).ToError(), Succeeded()); -} - void TransportBase::SetUp() { - PipeBase::SetUp(); + PipeTest::SetUp(); to_dap = std::make_unique( "to_dap", nullptr, std::make_shared(input.GetReadFileDescriptor(), diff --git a/lldb/unittests/DAP/TestBase.h b/lldb/unittests/DAP/TestBase.h index 70b3985271a92..25d37013954d5 100644 --- a/lldb/unittests/DAP/TestBase.h +++ b/lldb/unittests/DAP/TestBase.h @@ -8,26 +8,17 @@ #include "DAP.h" #include "Protocol/ProtocolBase.h" +#include "TestingSupport/Host/PipeTestUtilities.h" #include "Transport.h" -#include "lldb/Host/Pipe.h" #include "llvm/ADT/StringRef.h" #include "gmock/gmock.h" #include "gtest/gte
[Lldb-commits] [lldb] [lldb][RPC] Upstream lldb-rpc-gen tool (PR #138031)
@@ -0,0 +1,502 @@ +//===-- RPCCommon.cpp -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "RPCCommon.h" + +#include "clang/AST/AST.h" +#include "clang/AST/Attr.h" +#include "clang/AST/DeclBase.h" +#include "clang/AST/Mangle.h" +#include "clang/Lex/Lexer.h" + +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/raw_ostream.h" + +using namespace clang; + +// We intentionally do not generate some classes because they are currently +// inconvenient, they aren't really used by most consumers, or we're not sure +// why they exist. +static constexpr llvm::StringRef DisallowedClasses[] = { +"SBCommunication", // What is this used for? +"SBInputReader",// What is this used for? +"SBCommandPluginInterface", // This is hard to support, we can do it if +// really needed though. +"SBCommand", // There's nothing too difficult about this one, but many of + // its methods take a SBCommandPluginInterface pointer so + // there's no reason to support this. +}; + +// We intentionally avoid generating certain methods either because they are +// difficult to support correctly or they aren't really used much from C++. +// NOTE: These methods are marked as deprecated using LLDB_DEPRECATED. +// Normally this macro defines to the deprecated annotation, but this +// functionality is removed in SBDefines.h when generating SWIG bindings which +// we use for testing. Because of this, there is no annotation for the tool to +// pick up on so this list will be used while we have this restriction in +// SBDefines.h. +static constexpr llvm::StringRef DisallowedMethods[] = { +// The threading functionality in SBHostOS is deprecated and thus we do not +// generate them. It would be ideal to add the annotations to the methods +// and then support not generating deprecated methods. However, without +// annotations the generator generates most things correctly. This one is +// problematic because it returns a pointer to an "opaque" structure +// (thread_t) that is not `void *`, so special casing it is more effort than +// it's worth. +"_ZN4lldb8SBHostOS10ThreadJoinEP17_opaque_pthread_tPPvPNS_7SBErrorE", +"_ZN4lldb8SBHostOS12ThreadCancelEP17_opaque_pthread_tPNS_7SBErrorE", +"_ZN4lldb8SBHostOS12ThreadCreateEPKcPFPvS3_ES3_PNS_7SBErrorE", +"_ZN4lldb8SBHostOS12ThreadDetachEP17_opaque_pthread_tPNS_7SBErrorE", +"_ZN4lldb8SBHostOS13ThreadCreatedEPKc", +}; + +static constexpr llvm::StringRef ClassesWithoutDefaultCtor[] = { +"SBHostOS", +"SBReproducer", +}; + +static constexpr llvm::StringRef ClassesWithoutCopyOperations[] = { +"SBHostOS", +"SBReproducer", +"SBStream", +"SBProgress", +}; + +static constexpr llvm::StringRef MethodsWithPointerPlusLen[] = { +"_ZN4lldb6SBData11ReadRawDataERNS_7SBErrorEyPvm", +"_ZN4lldb6SBData7SetDataERNS_7SBErrorEPKvmNS_9ByteOrderEh", +"_ZN4lldb6SBData20SetDataWithOwnershipERNS_7SBErrorEPKvmNS_9ByteOrderEh", +"_ZN4lldb6SBData25CreateDataFromUInt64ArrayENS_9ByteOrderEjPym", +"_ZN4lldb6SBData25CreateDataFromUInt32ArrayENS_9ByteOrderEjPjm", +"_ZN4lldb6SBData25CreateDataFromSInt64ArrayENS_9ByteOrderEjPxm", +"_ZN4lldb6SBData25CreateDataFromSInt32ArrayENS_9ByteOrderEjPim", +"_ZN4lldb6SBData25CreateDataFromDoubleArrayENS_9ByteOrderEjPdm", +"_ZN4lldb6SBData22SetDataFromUInt64ArrayEPym", +"_ZN4lldb6SBData22SetDataFromUInt32ArrayEPjm", +"_ZN4lldb6SBData22SetDataFromSInt64ArrayEPxm", +"_ZN4lldb6SBData22SetDataFromSInt32ArrayEPim", +"_ZN4lldb6SBData22SetDataFromDoubleArrayEPdm", +"_ZN4lldb10SBDebugger22GetDefaultArchitectureEPcm", +"_ZN4lldb10SBDebugger13DispatchInputEPvPKvm", +"_ZN4lldb10SBDebugger13DispatchInputEPKvm", +"_ZN4lldb6SBFile4ReadEPhmPm", +"_ZN4lldb6SBFile5WriteEPKhmPm", +"_ZNK4lldb10SBFileSpec7GetPathEPcm", +"_ZN4lldb10SBFileSpec11ResolvePathEPKcPcm", +"_ZN4lldb8SBModule10GetVersionEPjj", +"_ZN4lldb12SBModuleSpec12SetUUIDBytesEPKhm", +"_ZNK4lldb9SBProcess9GetSTDOUTEPcm", +"_ZNK4lldb9SBProcess9GetSTDERREPcm", +"_ZNK4lldb9SBProcess19GetAsyncProfileDataEPcm", +"_ZN4lldb9SBProcess10ReadMemoryEyPvmRNS_7SBErrorE", +"_ZN4lldb9SBProcess11WriteMemoryEyPKvmRNS_7SBErrorE", +"_ZN4lldb9SBProcess21ReadCStringFromMemoryEyPvmRNS_7SBErrorE", +"_ZNK4lldb16SBStructuredData14GetStringValueEPcm", +"_ZN4lldb8SBTarget23BreakpointCreateByNamesEPPKcjjRKNS_" +"14SBFileSpecListES6_", +"_ZN4lldb8SBTarget10ReadMemoryENS_9S
[Lldb-commits] [lldb] [lldb] Implement JSON RPC (newline delimited) Transport (PR #143946)
Jlalond wrote: @JDevlieghere not a review, but any context on for the change? Just curious. https://github.com/llvm/llvm-project/pull/143946 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][headers] Create Python script to fix up framework headers (PR #142051)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `lldb-aarch64-windows` running on `linaro-armv8-windows-msvc-05` while building `lldb` at step 6 "test". Full details are available at: https://lab.llvm.org/buildbot/#/builders/141/builds/9412 Here is the relevant piece of the build log for the reference ``` Step 6 (test) failure: build (failure) ... PASS: lldb-shell :: ScriptInterpreter/Python/command_relative_import.test (1611 of 2241) PASS: lldb-shell :: ScriptInterpreter/Python/eof.test (1612 of 2241) UNSUPPORTED: lldb-shell :: ScriptInterpreter/Python/exit.test (1613 of 2241) PASS: lldb-shell :: ScriptInterpreter/Python/fail_breakpoint_oneline.test (1614 of 2241) PASS: lldb-shell :: ScriptInterpreter/Python/python.test (1615 of 2241) PASS: lldb-shell :: ScriptInterpreter/Python/sb_address_exception.test (1616 of 2241) PASS: lldb-shell :: ScriptInterpreter/Python/sb_function_ranges.s (1617 of 2241) PASS: lldb-shell :: ScriptInterpreter/Python/scripted_breakpoint.test (1618 of 2241) PASS: lldb-shell :: ScriptInterpreter/Python/scripted_breakpoint_lua.test (1619 of 2241) PASS: lldb-shell :: ScriptInterpreter/Python/silent_command_script_import.test (1620 of 2241) FAIL: lldb-shell :: Scripts/TestFrameworkFixScript.test (1621 of 2241) TEST 'lldb-shell :: Scripts/TestFrameworkFixScript.test' FAILED Exit Code: 1 Command Output (stdout): -- # RUN: at line 2 mkdir -p C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Scripts\Output\TestFrameworkFixScript.test.tmp/Outputs # executed command: mkdir -p 'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Scripts\Output\TestFrameworkFixScript.test.tmp/Outputs' # note: command had no output on stdout or stderr # RUN: at line 3 "C:\Users\tcwg\scoop\apps\python\current\python.exe" C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Scripts/../../../scripts/framework-header-fix.py -f lldb_main -i C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Scripts/Inputs/Main/SBAddress.h -o C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Scripts\Output\TestFrameworkFixScript.test.tmp/Outputs/SBAddress.h -p /usr/bin/unifdef USWIG # executed command: 'C:\Users\tcwg\scoop\apps\python\current\python.exe' 'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Scripts/../../../scripts/framework-header-fix.py' -f lldb_main -i 'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Scripts/Inputs/Main/SBAddress.h' -o 'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Scripts\Output\TestFrameworkFixScript.test.tmp/Outputs/SBAddress.h' -p /usr/bin/unifdef USWIG # .---command stdout # | Unable to find unifdef executable. Guards will not be removed from input files. Exiting... # `- # error: command failed with exit status: 1 -- UNSUPPORTED: lldb-shell :: Scripts/TestFrameworkFixUnifdef.test (1622 of 2241) FAIL: lldb-shell :: Scripts/TestRPCFrameworkFixScript.test (1623 of 2241) TEST 'lldb-shell :: Scripts/TestRPCFrameworkFixScript.test' FAILED Exit Code: 1 Command Output (stdout): -- # RUN: at line 2 mkdir -p C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Scripts\Output\TestRPCFrameworkFixScript.test.tmp/Outputs # executed command: mkdir -p 'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Scripts\Output\TestRPCFrameworkFixScript.test.tmp/Outputs' # note: command had no output on stdout or stderr # RUN: at line 3 "C:\Users\tcwg\scoop\apps\python\current\python.exe" C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Scripts/../../../scripts/framework-header-fix.py -f lldb_rpc -i C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Scripts/Inputs/Main/RPCSBAddress.h -o C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Scripts\Output\TestRPCFrameworkFixScript.test.tmp/Outputs/RPCSBAddress.h -p /usr/bin/unifdef USWIG # executed command: 'C:\Users\tcwg\scoop\apps\python\current\python.exe' 'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Scripts/../../../scripts/framework-header-fix.py' -f lldb_rpc -i 'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Scripts/Inputs/Main/RPCSBAddress.h' -o 'C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\tools\lldb\test\Shell\Scripts\Output\TestRPCFrameworkFixScript.test.tmp/Outputs/RPCSBAddress.h' -p /usr/bin/unifdef USWIG # .---command stderr # | Traceback (most recent call last): # | File "C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Scripts/../../../scripts/framework-header-fix.py", line 126, in # | main() ``` https://github.
[Lldb-commits] [lldb] 8a2895a - [lldb] Implement JSON RPC (newline delimited) Transport (#143946)
Author: Jonas Devlieghere Date: 2025-06-12T14:52:43-07:00 New Revision: 8a2895ad89793591cd3f0114bc56cd345f651823 URL: https://github.com/llvm/llvm-project/commit/8a2895ad89793591cd3f0114bc56cd345f651823 DIFF: https://github.com/llvm/llvm-project/commit/8a2895ad89793591cd3f0114bc56cd345f651823.diff LOG: [lldb] Implement JSON RPC (newline delimited) Transport (#143946) This PR implements JSON RPC-style (i.e. newline delimited) JSON transport. I moved the existing transport tests from DAP to Host and moved the PipeTest base class into TestingSupport so it can be shared by both. Added: lldb/unittests/Host/JSONTransportTest.cpp lldb/unittests/TestingSupport/Host/PipeTestUtilities.h Modified: lldb/include/lldb/Host/JSONTransport.h lldb/source/Host/common/JSONTransport.cpp lldb/unittests/DAP/CMakeLists.txt lldb/unittests/DAP/TestBase.cpp lldb/unittests/DAP/TestBase.h lldb/unittests/Host/CMakeLists.txt Removed: lldb/unittests/DAP/TransportTest.cpp diff --git a/lldb/include/lldb/Host/JSONTransport.h b/lldb/include/lldb/Host/JSONTransport.h index 4db5e417ea852..4087cdf2b42f7 100644 --- a/lldb/include/lldb/Host/JSONTransport.h +++ b/lldb/include/lldb/Host/JSONTransport.h @@ -51,17 +51,17 @@ class TransportTimeoutError : public llvm::ErrorInfo { } }; -class TransportClosedError : public llvm::ErrorInfo { +class TransportInvalidError : public llvm::ErrorInfo { public: static char ID; - TransportClosedError() = default; + TransportInvalidError() = default; void log(llvm::raw_ostream &OS) const override { -OS << "transport is closed"; +OS << "transport IO object invalid"; } std::error_code convertToErrorCode() const override { -return llvm::inconvertibleErrorCode(); +return std::make_error_code(std::errc::not_connected); } }; @@ -121,6 +121,21 @@ class HTTPDelimitedJSONTransport : public JSONTransport { static constexpr llvm::StringLiteral kHeaderSeparator = "\r\n\r\n"; }; +/// A transport class for JSON RPC. +class JSONRPCTransport : public JSONTransport { +public: + JSONRPCTransport(lldb::IOObjectSP input, lldb::IOObjectSP output) + : JSONTransport(input, output) {} + virtual ~JSONRPCTransport() = default; + +protected: + virtual llvm::Error WriteImpl(const std::string &message) override; + virtual llvm::Expected + ReadImpl(const std::chrono::microseconds &timeout) override; + + static constexpr llvm::StringLiteral kMessageSeparator = "\n"; +}; + } // namespace lldb_private #endif diff --git a/lldb/source/Host/common/JSONTransport.cpp b/lldb/source/Host/common/JSONTransport.cpp index 103c76d25daf7..1a0851d5c4365 100644 --- a/lldb/source/Host/common/JSONTransport.cpp +++ b/lldb/source/Host/common/JSONTransport.cpp @@ -31,7 +31,7 @@ static Expected ReadFull(IOObject &descriptor, size_t length, std::optional timeout = std::nullopt) { if (!descriptor.IsValid()) -return llvm::make_error(); +return llvm::make_error(); bool timeout_supported = true; // FIXME: SelectHelper does not work with NativeFile on Win32. @@ -92,7 +92,7 @@ void JSONTransport::Log(llvm::StringRef message) { Expected HTTPDelimitedJSONTransport::ReadImpl(const std::chrono::microseconds &timeout) { if (!m_input || !m_input->IsValid()) -return createStringError("transport output is closed"); +return llvm::make_error(); IOObject *input = m_input.get(); Expected message_header = @@ -131,7 +131,7 @@ HTTPDelimitedJSONTransport::ReadImpl(const std::chrono::microseconds &timeout) { Error HTTPDelimitedJSONTransport::WriteImpl(const std::string &message) { if (!m_output || !m_output->IsValid()) -return llvm::make_error(); +return llvm::make_error(); Log(llvm::formatv("<-- {0}", message).str()); @@ -142,6 +142,35 @@ Error HTTPDelimitedJSONTransport::WriteImpl(const std::string &message) { return m_output->Write(Output.data(), num_bytes).takeError(); } +Expected +JSONRPCTransport::ReadImpl(const std::chrono::microseconds &timeout) { + if (!m_input || !m_input->IsValid()) +return make_error(); + + IOObject *input = m_input.get(); + Expected raw_json = + ReadUntil(*input, kMessageSeparator, timeout); + if (!raw_json) +return raw_json.takeError(); + + Log(llvm::formatv("--> {0}", *raw_json).str()); + + return *raw_json; +} + +Error JSONRPCTransport::WriteImpl(const std::string &message) { + if (!m_output || !m_output->IsValid()) +return llvm::make_error(); + + Log(llvm::formatv("<-- {0}", message).str()); + + std::string Output; + llvm::raw_string_ostream OS(Output); + OS << message << kMessageSeparator; + size_t num_bytes = Output.size(); + return m_output->Write(Output.data(), num_bytes).takeError(); +} + char TransportEOFError::ID; char TransportTimeoutError::ID; -char TransportClosedError::ID; +char TransportInvalidError::ID; diff --git a/lldb/unittests
[Lldb-commits] [lldb] [lldb] Implement JSON RPC (newline delimited) Transport (PR #143946)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/143946 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Refactoring DebugCommunication to improve test consistency. (PR #143818)
@@ -76,26 +178,22 @@ def read_packet(f, verbose=False, trace_file=None): if verbose: print('length: "%u"' % (length)) # Skip empty line -line = f.readline() +line = f.readline().decode() if verbose: print('empty: "%s"' % (line)) # Read JSON bytes json_str = f.read(length) if verbose: -print('json: "%s"' % (json_str)) +print('json: "%r"' % (json_str)) JDevlieghere wrote: I think all supported Python versions now support f-strings. ```suggestion print(f'json: "{json_str}"') ``` https://github.com/llvm/llvm-project/pull/143818 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Refactoring DebugCommunication to improve test consistency. (PR #143818)
https://github.com/JDevlieghere commented: This looks fine to me, but I haven't been following this work too closely so I'll defer to the others to sign off. https://github.com/llvm/llvm-project/pull/143818 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 26f9161 - [lit] cleanup unused imports (#143930)
Author: Charles Zablit Date: 2025-06-12T15:13:13-07:00 New Revision: 26f91610011f1a23cb306d61bbc1fafded7d077d URL: https://github.com/llvm/llvm-project/commit/26f91610011f1a23cb306d61bbc1fafded7d077d DIFF: https://github.com/llvm/llvm-project/commit/26f91610011f1a23cb306d61bbc1fafded7d077d.diff LOG: [lit] cleanup unused imports (#143930) Remove imports that are not used in some lit test files. Added: Modified: lld/test/Unit/lit.cfg.py lldb/test/API/lit.cfg.py lldb/test/Shell/lit.cfg.py lldb/test/lit.cfg.py llvm/utils/lit/lit/LitConfig.py llvm/utils/lit/lit/TestRunner.py llvm/utils/lit/lit/discovery.py llvm/utils/lit/lit/worker.py Removed: diff --git a/lld/test/Unit/lit.cfg.py b/lld/test/Unit/lit.cfg.py index 1cf890a05cb28..47375db517e96 100644 --- a/lld/test/Unit/lit.cfg.py +++ b/lld/test/Unit/lit.cfg.py @@ -3,7 +3,6 @@ # Configuration file for the 'lit' test runner. import os -import subprocess import lit.formats diff --git a/lldb/test/API/lit.cfg.py b/lldb/test/API/lit.cfg.py index 646a446c86fdb..04b360e8d3307 100644 --- a/lldb/test/API/lit.cfg.py +++ b/lldb/test/API/lit.cfg.py @@ -9,8 +9,6 @@ import subprocess import sys -import lit.formats - # name: The name of this test suite. config.name = "lldb-api" diff --git a/lldb/test/Shell/lit.cfg.py b/lldb/test/Shell/lit.cfg.py index ab6113767187a..6f0e017fb7cb9 100644 --- a/lldb/test/Shell/lit.cfg.py +++ b/lldb/test/Shell/lit.cfg.py @@ -7,12 +7,9 @@ import shutil import site import subprocess -import sys -import lit.formats +import lit.util from lit.llvm import llvm_config -from lit.llvm.subst import FindTool -from lit.llvm.subst import ToolSubst site.addsitedir(os.path.dirname(__file__)) from helper import toolchain diff --git a/lldb/test/lit.cfg.py b/lldb/test/lit.cfg.py index eefc32aabd16d..6a4255c2627d9 100644 --- a/lldb/test/lit.cfg.py +++ b/lldb/test/lit.cfg.py @@ -2,9 +2,6 @@ import os -import lit.formats -from lit.llvm import llvm_config - # This is the top level configuration. Most of these configuration options will # be overriden by individual lit configuration files in the test # subdirectories. Anything configured here will *not* be loaded when pointing diff --git a/llvm/utils/lit/lit/LitConfig.py b/llvm/utils/lit/lit/LitConfig.py index cb4aef6f72a87..5bb2d3c5c986c 100644 --- a/llvm/utils/lit/lit/LitConfig.py +++ b/llvm/utils/lit/lit/LitConfig.py @@ -1,14 +1,12 @@ from __future__ import absolute_import + import inspect import os -import platform import sys -import lit.Test -import lit.formats -import lit.TestingConfig import lit.util + # LitConfig must be a new style class for properties to work class LitConfig(object): """LitConfig - Configuration data for a 'lit' test runner instance, shared diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py index 73db67aedb739..1d3bf8e4e8df1 100644 --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -1,7 +1,4 @@ from __future__ import absolute_import -import errno -import io -import itertools import getopt import os, signal, subprocess, sys import re @@ -12,11 +9,8 @@ import shutil import tempfile import threading -import typing from typing import Optional, Tuple -import io - try: from StringIO import StringIO except ImportError: diff --git a/llvm/utils/lit/lit/discovery.py b/llvm/utils/lit/lit/discovery.py index 2e7f90c6bb0c9..2e93bacc12368 100644 --- a/llvm/utils/lit/lit/discovery.py +++ b/llvm/utils/lit/lit/discovery.py @@ -6,8 +6,8 @@ import os import sys +from lit import Test, util from lit.TestingConfig import TestingConfig -from lit import LitConfig, Test, util def chooseConfigFileFromDir(dir, config_names): diff --git a/llvm/utils/lit/lit/worker.py b/llvm/utils/lit/lit/worker.py index 8e78bfd45d38b..dbc3ab53bc627 100644 --- a/llvm/utils/lit/lit/worker.py +++ b/llvm/utils/lit/lit/worker.py @@ -12,8 +12,6 @@ import traceback import lit.Test -import lit.util - _lit_config = None _parallelism_semaphores = None ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lld] [lldb] [llvm] [lit] cleanup unused imports (PR #143930)
https://github.com/adrian-prantl closed https://github.com/llvm/llvm-project/pull/143930 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add MCP support to LLDB (PoC) (PR #143628)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/143628 >From 0db4451b1413f16443a7105f4aaa59597b166955 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 4 Jun 2025 23:56:57 -0700 Subject: [PATCH] [lldb] Add MCP support to LLDB (PoC) --- lldb/include/lldb/MCP/MCPError.h | 33 +++ lldb/include/lldb/MCP/Protocol.h | 131 + lldb/include/lldb/MCP/Server.h| 67 + lldb/include/lldb/MCP/Tool.h | 45 lldb/source/CMakeLists.txt| 1 + lldb/source/Commands/CMakeLists.txt | 2 + lldb/source/Commands/CommandObjectMCP.cpp | 162 +++ lldb/source/Commands/CommandObjectMCP.h | 24 ++ .../source/Interpreter/CommandInterpreter.cpp | 2 + lldb/source/MCP/CMakeLists.txt| 13 + lldb/source/MCP/MCPError.cpp | 31 +++ lldb/source/MCP/Protocol.cpp | 180 + lldb/source/MCP/Server.cpp| 251 ++ lldb/source/MCP/Tool.cpp | 28 ++ 14 files changed, 970 insertions(+) create mode 100644 lldb/include/lldb/MCP/MCPError.h create mode 100644 lldb/include/lldb/MCP/Protocol.h create mode 100644 lldb/include/lldb/MCP/Server.h create mode 100644 lldb/include/lldb/MCP/Tool.h create mode 100644 lldb/source/Commands/CommandObjectMCP.cpp create mode 100644 lldb/source/Commands/CommandObjectMCP.h create mode 100644 lldb/source/MCP/CMakeLists.txt create mode 100644 lldb/source/MCP/MCPError.cpp create mode 100644 lldb/source/MCP/Protocol.cpp create mode 100644 lldb/source/MCP/Server.cpp create mode 100644 lldb/source/MCP/Tool.cpp diff --git a/lldb/include/lldb/MCP/MCPError.h b/lldb/include/lldb/MCP/MCPError.h new file mode 100644 index 0..2a76a7b087e20 --- /dev/null +++ b/lldb/include/lldb/MCP/MCPError.h @@ -0,0 +1,33 @@ +//===-- MCPError.h ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "Protocol.h" +#include "llvm/Support/Error.h" +#include + +namespace lldb_private::mcp { + +class MCPError : public llvm::ErrorInfo { +public: + static char ID; + + MCPError(std::string message, int64_t error_code); + + void log(llvm::raw_ostream &OS) const override; + std::error_code convertToErrorCode() const override; + + const std::string &getMessage() const { return m_message; } + + protocol::Error toProtcolError() const; + +private: + std::string m_message; + int64_t m_error_code; +}; + +} // namespace lldb_private::mcp diff --git a/lldb/include/lldb/MCP/Protocol.h b/lldb/include/lldb/MCP/Protocol.h new file mode 100644 index 0..e661c3f7643af --- /dev/null +++ b/lldb/include/lldb/MCP/Protocol.h @@ -0,0 +1,131 @@ +//===- Protocol.h -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLDB_TOOLS_LLDB_MCP_PROTOCOL_H +#define LLDB_TOOLS_LLDB_MCP_PROTOCOL_H + +#include "llvm/Support/JSON.h" +#include +#include + +namespace lldb_private::mcp::protocol { + +static llvm::StringLiteral kProtocolVersion = "2025-03-26"; + +struct Request { + uint64_t id = 0; + std::string method; + std::optional params; +}; + +llvm::json::Value toJSON(const Request &); +bool fromJSON(const llvm::json::Value &, Request &, llvm::json::Path); + +struct Error { + int64_t code = 0; + std::string message; + std::optional data; +}; + +llvm::json::Value toJSON(const Error &); +bool fromJSON(const llvm::json::Value &, Error &, llvm::json::Path); + +struct ProtocolError { + uint64_t id = 0; + Error error; +}; + +llvm::json::Value toJSON(const ProtocolError &); +bool fromJSON(const llvm::json::Value &, ProtocolError &, llvm::json::Path); + +struct Response { + uint64_t id = 0; + std::optional result; + std::optional error; +}; + +llvm::json::Value toJSON(const Response &); +bool fromJSON(const llvm::json::Value &, Response &, llvm::json::Path); + +struct Notification { + std::string method; + std::optional params; +}; + +llvm::json::Value toJSON(const Notification &); +bool fromJSON(const llvm::json::Value &, Notification &, llvm::json::Path); + +struct ToolCapability { + bool listChanged = false; +}; + +llvm::json::Value toJSON(const ToolCapability &); +bool fromJSON(const llvm::json::Value &, ToolCapability &, llvm::json::Path); + +struct Capabilities { + ToolCapability tools; +}; + +llvm::json::Value toJSON(const
[Lldb-commits] [lld] [lldb] [llvm] [lit] cleanup unused imports (PR #143930)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `sanitizer-aarch64-linux-bootstrap-hwasan` running on `sanitizer-buildbot11` while building `lld,lldb,llvm` at step 2 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/55/builds/12717 Here is the relevant piece of the build log for the reference ``` Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure) ... llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/libcxx/utils/libcxx/test/config.py:24: note: (llvm-libc++-shared.cfg.in) Using %{cxx} substitution: '/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build0/bin/clang++' llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/libcxx/utils/libcxx/test/config.py:24: note: (llvm-libc++-shared.cfg.in) Using %{flags} substitution: '-pthread --target=aarch64-unknown-linux-gnu -g -fno-omit-frame-pointer -fsanitize=hwaddress' llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/libcxx/utils/libcxx/test/config.py:24: note: (llvm-libc++-shared.cfg.in) Using %{compile_flags} substitution: '-nostdinc++ -I %{target-include-dir} -I %{include-dir} -I %{libcxx-dir}/test/support -std=c++26 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor -Wshift-negative-value -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move -Wno-nullability-completeness -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety -Wuser-defined-warnings' llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/libcxx/utils/libcxx/test/config.py:24: note: (llvm-libc++-shared.cfg.in) Using %{link_flags} substitution: '-lc++experimental -nostdlib++ -L %{lib-dir} -Wl,-rpath,%{lib-dir} -lc++ -latomic' llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/libcxx/utils/libcxx/test/config.py:24: note: (llvm-libc++-shared.cfg.in) Using %{benchmark_flags} substitution: '-I /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/libcxx_build_hwasan/libcxx/test/benchmarks/google-benchmark/include -L /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/libcxx_build_hwasan/libcxx/test/benchmarks/google-benchmark/lib -L /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/libcxx_build_hwasan/libcxx/test/benchmarks/google-benchmark/lib64 -l benchmark' llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/libcxx/utils/libcxx/test/config.py:24: note: (llvm-libc++-shared.cfg.in) Using %{exec} substitution: '%{executor} --execdir %T -- ' llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/libcxx/utils/libcxx/test/config.py:24: note: (llvm-libc++-shared.cfg.in) All available features: add-latomic-workaround, buildhost=linux, c++26, c++experimental, can-create-symlinks, character-conversion-warnings, clang, clang-21, clang-21.0, clang-21.0.0, diagnose-if-support, enable-benchmarks=no, gcc-style-warnings, glibc-old-ru_RU-decimal-point, has-1024-bit-atomics, has-64-bit-atomics, has-fblocks, has-fconstexpr-steps, has-unix-headers, hwasan, large_tests, libcpp-abi-version=1, libcpp-hardening-mode=none, libcpp-has-no-availability-markup, libcpp-has-thread-api-pthread, linux, lsan, objective-c++, optimization=none, sanitizer-new-delete, std-at-least-c++03, std-at-least-c++11, std-at-least-c++14, std-at-least-c++17, std-at-least-c++20, std-at-least-c++23, std-at-least-c++26, stdlib=libc++, stdlib=llvm-libc++, target=aarch64-unknown-linux-gnu, thread-safety, verify-support llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/main.py:73: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 1500 seconds was requested on the command line. Forcing timeout to be 1500 seconds. -- Testing: 10778 of 10797 tests, 72 workers -- Testing: 0.. 10.. FAIL: llvm-libc++-shared.cfg.in :: libcxx/selftest/dsl/dsl.sh.py (2089 of 10778) TEST 'llvm-libc++-shared.cfg.in :: libcxx/selftest/dsl/dsl.sh.py' FAILED Exit Code: 1 Command Output (stdout): -- # RUN: at line 15 /usr/bin/python3 /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/libcxx/test/libcxx/selftest/dsl/dsl.sh.py x/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-pr
[Lldb-commits] [lldb] [lldb] Add MCP support to LLDB (PoC) (PR #143628)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/143628 >From dee0cc4017bff69879736f39c8cf270a3c867c1c Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 12 Jun 2025 16:33:55 -0700 Subject: [PATCH] [lldb] Add MCP support to LLDB https://discourse.llvm.org/t/rfc-adding-mcp-support-to-lldb/86798 --- lldb/include/lldb/Core/PluginManager.h| 9 + lldb/include/lldb/Core/ProtocolServer.h | 37 +++ lldb/include/lldb/lldb-forward.h | 3 +- lldb/include/lldb/lldb-private-interfaces.h | 2 + lldb/source/Commands/CMakeLists.txt | 1 + lldb/source/Commands/CommandObjectMCP.cpp | 117 lldb/source/Commands/CommandObjectMCP.h | 24 ++ lldb/source/Core/CMakeLists.txt | 1 + lldb/source/Core/PluginManager.cpp| 27 ++ lldb/source/Core/ProtocolServer.cpp | 21 ++ .../source/Interpreter/CommandInterpreter.cpp | 2 + lldb/source/Plugins/CMakeLists.txt| 1 + lldb/source/Plugins/Protocol/CMakeLists.txt | 1 + .../Plugins/Protocol/MCP/CMakeLists.txt | 13 + lldb/source/Plugins/Protocol/MCP/MCPError.cpp | 31 ++ lldb/source/Plugins/Protocol/MCP/MCPError.h | 33 +++ lldb/source/Plugins/Protocol/MCP/Protocol.cpp | 180 +++ lldb/source/Plugins/Protocol/MCP/Protocol.h | 131 .../Protocol/MCP/ProtocolServerMCP.cpp| 280 ++ .../Plugins/Protocol/MCP/ProtocolServerMCP.h | 77 + lldb/source/Plugins/Protocol/MCP/Tool.cpp | 72 + lldb/source/Plugins/Protocol/MCP/Tool.h | 61 22 files changed, 1123 insertions(+), 1 deletion(-) create mode 100644 lldb/include/lldb/Core/ProtocolServer.h create mode 100644 lldb/source/Commands/CommandObjectMCP.cpp create mode 100644 lldb/source/Commands/CommandObjectMCP.h create mode 100644 lldb/source/Core/ProtocolServer.cpp create mode 100644 lldb/source/Plugins/Protocol/CMakeLists.txt create mode 100644 lldb/source/Plugins/Protocol/MCP/CMakeLists.txt create mode 100644 lldb/source/Plugins/Protocol/MCP/MCPError.cpp create mode 100644 lldb/source/Plugins/Protocol/MCP/MCPError.h create mode 100644 lldb/source/Plugins/Protocol/MCP/Protocol.cpp create mode 100644 lldb/source/Plugins/Protocol/MCP/Protocol.h create mode 100644 lldb/source/Plugins/Protocol/MCP/ProtocolServerMCP.cpp create mode 100644 lldb/source/Plugins/Protocol/MCP/ProtocolServerMCP.h create mode 100644 lldb/source/Plugins/Protocol/MCP/Tool.cpp create mode 100644 lldb/source/Plugins/Protocol/MCP/Tool.h diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h index e7b169103..967af598c40ff 100644 --- a/lldb/include/lldb/Core/PluginManager.h +++ b/lldb/include/lldb/Core/PluginManager.h @@ -327,6 +327,15 @@ class PluginManager { static void AutoCompleteProcessName(llvm::StringRef partial_name, CompletionRequest &request); + // Protocol + static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, + ProtocolServerCreateInstance create_callback); + + static bool UnregisterPlugin(ProtocolServerCreateInstance create_callback); + + static ProtocolServerCreateInstance + GetProtocolCreateCallbackForPluginName(llvm::StringRef name); + // Register Type Provider static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, RegisterTypeBuilderCreateInstance create_callback); diff --git a/lldb/include/lldb/Core/ProtocolServer.h b/lldb/include/lldb/Core/ProtocolServer.h new file mode 100644 index 0..ca0210a0bbe72 --- /dev/null +++ b/lldb/include/lldb/Core/ProtocolServer.h @@ -0,0 +1,37 @@ +//===-- ProtocolServer.h --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLDB_CORE_PROTOCOLSERVER_H +#define LLDB_CORE_PROTOCOLSERVER_H + +#include "lldb/Core/PluginInterface.h" +#include "lldb/Host/Socket.h" +#include "lldb/lldb-private-interfaces.h" + +namespace lldb_private { + +class ProtocolServer : public PluginInterface { +public: + ProtocolServer() = default; + virtual ~ProtocolServer() = default; + + static lldb::ProtocolServerSP Create(llvm::StringRef name, + Debugger &debugger); + + struct Connection { +Socket::SocketProtocol protocol; +std::string name; + }; + + virtual llvm::Error Start(Connection connection); + virtual llvm::Error Stop(); +}; + +} // namespace lldb_private + +#endif diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h index c664d1398f74d..558818e8e2309 100644 --- a/lldb/include/lldb/lldb-forward.h
[Lldb-commits] [lldb] [lldb-dap] Refactoring DebugCommunication to improve test consistency. (PR #143818)
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/143818 >From ab4b987aec591491d3805af41c7127ff6698fe0e Mon Sep 17 00:00:00 2001 From: John Harrison Date: Wed, 11 Jun 2025 15:57:16 -0700 Subject: [PATCH 1/2] [lldb-dap] Refactring DebugCommunication to improve test consistency. In DebugCommunication, we currently are using 2 thread to drive lldb-dap. At the moment, they make an attempt at only synchronizing the `recv_packets` between the reader thread and the main test thread. Other stateful properties of the debug session are not guarded by any mutexs. To mitigate this, I am moving any state updates to the main thread inside the `_recv_packet` method to ensure that between calls to `_recv_packet` the state does not change out from under us in a test. This does mean the precise timing of events has changed slightly as a result and I've updated the existing tests that fail for me locally with this new behavior. I think this should result in overall more predictable behavior, even if the test is slow due to the host workload or architecture differences. --- .../test/tools/lldb-dap/dap_server.py | 839 +++--- .../test/tools/lldb-dap/lldbdap_testcase.py | 79 +- .../breakpoint/TestDAP_setBreakpoints.py | 5 +- .../tools/lldb-dap/cancel/TestDAP_cancel.py | 10 +- .../tools/lldb-dap/launch/TestDAP_launch.py | 12 +- .../tools/lldb-dap/module/TestDAP_module.py | 2 +- .../tools/lldb-dap/output/TestDAP_output.py | 4 +- 7 files changed, 568 insertions(+), 383 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py index 9786678aa53f9..20a1b4480df6d 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py @@ -10,17 +10,117 @@ import subprocess import signal import sys +from dataclasses import dataclass import threading import time -from typing import Any, Optional, Union, BinaryIO, TextIO +from typing import ( +IO, +Any, +Callable, +Dict, +List, +Optional, +Tuple, +TypeGuard, +TypeVar, +TypedDict, +Union, +BinaryIO, +TextIO, +Literal, +cast, +) ## DAP type references -Event = dict[str, Any] -Request = dict[str, Any] -Response = dict[str, Any] + +T = TypeVar("T") + + +class Event(TypedDict): +type: Literal["event"] +seq: Literal[0] +event: str +body: Optional[dict] + + +class Request(TypedDict): +type: Literal["request"] +seq: int +command: str +arguments: Optional[dict] + + +class Response(TypedDict): +type: Literal["response"] +seq: Literal[0] +request_seq: int +success: bool +command: str +message: Optional[str] +body: Optional[dict] + + ProtocolMessage = Union[Event, Request, Response] +class AttachOrLaunchArguments(TypedDict, total=False): +stopOnEntry: bool +disableASLR: bool +disableSTDIO: bool +enableAutoVariableSummaries: bool +displayExtendedBacktrace: bool +enableSyntheticChildDebugging: bool +initCommands: List[str] +preRunCommands: List[str] +postRunCommands: List[str] +stopCommands: List[str] +exitCommands: List[str] +terminateCommands: List[str] +sourceMap: Union[List[Tuple[str, str]], Dict[str, str]] +sourcePath: str +debuggerRoot: str +commandEscapePrefix: str +customFrameFormat: str +customThreadFormat: str + + +class LaunchArguments(AttachOrLaunchArguments, total=False): +program: str +args: List[str] +cwd: str +env: Dict[str, str] +shellExpandArguments: bool +runInTerminal: bool +launchCommands: List[str] + + +class AttachArguments(AttachOrLaunchArguments, total=False): +program: str +pid: int +waitFor: bool +attachCommands: List[str] +coreFile: str +gdbRemotePort: int +gdbRemoteHostname: str + + +class BreakpiontData(TypedDict, total=False): +column: int +condition: str +hitCondition: str +logMessage: str +mode: str + + +class SourceBreakpoint(BreakpiontData): +line: int + + +class Breakpoint(TypedDict, total=False): +id: int +verified: bool + + def dump_memory(base_addr, data, num_per_line, outfile): data_len = len(data) hex_string = binascii.hexlify(data) @@ -58,7 +158,9 @@ def dump_memory(base_addr, data, num_per_line, outfile): outfile.write("\n") -def read_packet(f, verbose=False, trace_file=None): +def read_packet( +f: IO[bytes], verbose: bool = False, trace_file: Optional[IO[str]] = None +) -> Optional[ProtocolMessage]: """Decode a JSON packet that starts with the content length and is followed by the JSON bytes from a file 'f'. Returns None on EOF. """ @@ -76,26 +178,22 @@ def read_packet(f, verbose=False, trace_file=None): if verbose: print('length: "%u"' %
[Lldb-commits] [lldb] [lldb-dap] Refactoring DebugCommunication to improve test consistency. (PR #143818)
@@ -76,26 +178,22 @@ def read_packet(f, verbose=False, trace_file=None): if verbose: print('length: "%u"' % (length)) # Skip empty line -line = f.readline() +line = f.readline().decode() if verbose: print('empty: "%s"' % (line)) # Read JSON bytes json_str = f.read(length) if verbose: -print('json: "%s"' % (json_str)) +print('json: "%r"' % (json_str)) ashgti wrote: Done. https://github.com/llvm/llvm-project/pull/143818 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][headers] Create Python script to fix up framework headers (PR #142051)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `lldb-remote-linux-ubuntu` running on `as-builder-9` while building `lldb` at step 17 "test-check-lldb-shell". Full details are available at: https://lab.llvm.org/buildbot/#/builders/195/builds/10363 Here is the relevant piece of the build log for the reference ``` Step 17 (test-check-lldb-shell) failure: Test just built components: check-lldb-shell completed (failure) TEST 'lldb-shell :: Scripts/TestFrameworkFixScript.test' FAILED Exit Code: 1 Command Output (stdout): -- Unable to find unifdef executable. Guards will not be removed from input files. Exiting... -- Command Output (stderr): -- mkdir -p /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/tools/lldb/test/Shell/Scripts/Output/TestFrameworkFixScript.test.tmp/Outputs # RUN: at line 2 + mkdir -p /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/tools/lldb/test/Shell/Scripts/Output/TestFrameworkFixScript.test.tmp/Outputs "/usr/bin/python3.12" /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/Shell/Scripts/../../../scripts/framework-header-fix.py -f lldb_main -i /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h -o /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/tools/lldb/test/Shell/Scripts/Output/TestFrameworkFixScript.test.tmp/Outputs/SBAddress.h -p /usr/bin/unifdef USWIG # RUN: at line 3 + /usr/bin/python3.12 /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/Shell/Scripts/../../../scripts/framework-header-fix.py -f lldb_main -i /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h -o /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/tools/lldb/test/Shell/Scripts/Output/TestFrameworkFixScript.test.tmp/Outputs/SBAddress.h -p /usr/bin/unifdef USWIG -- ``` https://github.com/llvm/llvm-project/pull/142051 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Improving dotest script flags. (PR #143797)
ashgti wrote: Okay, it sounds like I should remove the `-#` from dotest.py since its broken and `-y` since its not used anywhere. I can take a look at lit and see if there is some way to integrate re-running a test there. I'll check if there is a way we could also integrate the failfast flag as well. https://github.com/llvm/llvm-project/pull/143797 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Commands] Fix memory find for Swift expressions (PR #143860)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/143860 >From 953c71de0b3d21309a4ebbe71cab8618c16dd699 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Wed, 11 Jun 2025 12:26:51 +0100 Subject: [PATCH] [lldb][Commands] Fix memory find for Swift expressions There were two issues previously preventing `memory find -e` expressions to succeed when stopped in Swift frames: 1. We weren't getting the dynamic type of the result `ValueObject`. For Swift this would fail when we tried to produce a scalar value out of it because the static VO wasn't sufficient to get to the integer value. Hence we add a call to `GetQualifiedRepresentationIfAvailable` (which is what we do for expressions in `OptionArgParser::ToAddress` too). 2. We weren't passing an `ExecutionContextScope` to `GetByteSize`, which Swift relied on to get the size of the result type. My plan is to add an API test for this on the Apple `swiftlang/llvm-project` fork. I considered an alternative where we use `OptionArgParser::ToAddress` for `memory find -e` expressions, but it got a bit icky when trying to figure out how many bytes we should copy out of the result into the `DataBufferHeap` (currently we rely on the size of the result variable type). This gets even trickier when we were to pass an expression that was actually a hex digit or a number into `ToAddress`. rdar://152113525 --- lldb/source/Commands/CommandObjectMemory.cpp | 13 ++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 85ae9f8f9e8cb..2bcbc4291f7dd 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -886,9 +886,10 @@ class CommandObjectMemoryRead : public CommandObjectParsed { #include "CommandOptions.inc" static llvm::Error CopyExpressionResult(ValueObject &result, -DataBufferHeap &buffer) { +DataBufferHeap &buffer, +ExecutionContextScope *scope) { uint64_t value = result.GetValueAsUnsigned(0); - auto size_or_err = result.GetCompilerType().GetByteSize(nullptr); + auto size_or_err = result.GetCompilerType().GetByteSize(scope); if (!size_or_err) return size_or_err.takeError(); @@ -928,6 +929,11 @@ EvaluateExpression(llvm::StringRef expression, StackFrame &frame, return llvm::createStringError( "expression evaluation failed. pass a string instead"); + result_sp = result_sp->GetQualifiedRepresentationIfAvailable( + result_sp->GetDynamicValueType(), /*synthValue=*/true); + if (!result_sp) +return llvm::createStringError("failed to unwrap expression result type"); + return result_sp; } @@ -1082,7 +1088,8 @@ class CommandObjectMemoryFind : public CommandObjectParsed { ValueObjectSP result_sp = *result_or_err; - if (auto err = CopyExpressionResult(*result_sp, buffer)) { + if (auto err = CopyExpressionResult(*result_sp, buffer, + m_exe_ctx.GetFramePtr())) { result.AppendError(llvm::toString(std::move(err))); return; } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Commands] Fix memory find for Swift expressions (PR #143860)
https://github.com/adrian-prantl approved this pull request. https://github.com/llvm/llvm-project/pull/143860 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Commands] Fix memory find for Swift expressions (PR #143860)
https://github.com/adrian-prantl approved this pull request. https://github.com/llvm/llvm-project/pull/143860 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Improving dotest script flags. (PR #143797)
@@ -204,19 +204,19 @@ def create_parser(): action="append", help='Run "setting set SETTING VALUE" before executing any test.', ) -group.add_argument( -"-y", -type=int, -metavar="count", -help="Specify the iteration count used to collect our benchmarks. An example is the number of times to do 'thread step-over' to measure stepping speed.", -) group.add_argument( "-#", type=int, metavar="sharp", dest="sharp", help="Repeat the test suite for a specified number of times", ) +group.add_argument( +"--failfast", +dest="failfast", +action="store_true", +help="Stop on first fail or error", ashgti wrote: I copied this from python's unittest.main https://github.com/python/cpython/blob/3.13/Lib/unittest/main.py#L177-L179 since thats what I am emulating. I can update the wording though. It does apply to all tests, not just the `-#` runs. https://github.com/llvm/llvm-project/pull/143797 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][headers] Create Python script to fix up framework headers (PR #142051)
https://github.com/JDevlieghere approved this pull request. 🚢 https://github.com/llvm/llvm-project/pull/142051 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lld] [lldb] [llvm] [lit] cleanup unused imports (PR #143930)
https://github.com/JDevlieghere approved this pull request. https://github.com/llvm/llvm-project/pull/143930 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][RPC] Upstream lldb-rpc-gen tool (PR #138031)
https://github.com/chelcassanova updated https://github.com/llvm/llvm-project/pull/138031 >From 33f60654673a9d27ed806334a8803c75b51a7aa5 Mon Sep 17 00:00:00 2001 From: Chelsea Cassanova Date: Wed, 30 Apr 2025 14:15:39 -0700 Subject: [PATCH] [lldb][RPC] Upstream lldb-rpc-gen tool This commit upstreams the `lldb-rpc-gen` tool, a ClangTool that generates the LLDB RPC client and server interfaces. https://discourse.llvm.org/t/rfc-upstreaming-lldb-rpc/85804 --- .../tools/lldb-rpc/lldb-rpc-gen/RPCCommon.cpp | 508 ++ lldb/tools/lldb-rpc/lldb-rpc-gen/RPCCommon.h | 108 .../lldb-rpc/lldb-rpc-gen/lldb-rpc-gen.cpp| 412 ++ 3 files changed, 1028 insertions(+) create mode 100644 lldb/tools/lldb-rpc/lldb-rpc-gen/RPCCommon.cpp create mode 100644 lldb/tools/lldb-rpc/lldb-rpc-gen/RPCCommon.h create mode 100644 lldb/tools/lldb-rpc/lldb-rpc-gen/lldb-rpc-gen.cpp diff --git a/lldb/tools/lldb-rpc/lldb-rpc-gen/RPCCommon.cpp b/lldb/tools/lldb-rpc/lldb-rpc-gen/RPCCommon.cpp new file mode 100644 index 0..0326960ce6a4b --- /dev/null +++ b/lldb/tools/lldb-rpc/lldb-rpc-gen/RPCCommon.cpp @@ -0,0 +1,508 @@ +//===-- RPCCommon.cpp -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "RPCCommon.h" + +#include "clang/AST/AST.h" +#include "clang/AST/Attr.h" +#include "clang/AST/DeclBase.h" +#include "clang/AST/Mangle.h" +#include "clang/Lex/Lexer.h" + +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/raw_ostream.h" + +using namespace clang; + +// We intentionally do not generate some classes because they are currently +// inconvenient, they aren't really used by most consumers, or we're not sure +// why they exist. +static constexpr llvm::StringRef DisallowedClasses[] = { +"SBCommunication", // This class is pretty much unused by consumers, so we + // skip it. +"SBInputReader", // This class is pretty much unused by consumers, so we + // skip it. +"SBCommandPluginInterface", // This class uses virtual functions, and the SB +// API should not have those, so we skip this +// class. +"SBCommand", // There's nothing too difficult about this one, but many of + // its methods take a SBCommandPluginInterface pointer so + // there's no reason to support this. +}; + +// NOTE: In lldb-rpc-gen, we use mangled names when we need to work with +// functions. We do this because we support many functions that have overloads, +// and mangled names have no ambiguity which makes it easier to keep track of. +// This is also possible since the LLDB SB API is stable. + +// We intentionally avoid generating certain methods either because they are +// difficult to support correctly or they aren't really used much from C++. +// NOTE: These methods are marked as deprecated using LLDB_DEPRECATED. +// Normally this macro defines to the deprecated annotation, but this +// functionality is removed in SBDefines.h when generating SWIG bindings which +// we use for testing. Because of this, there is no annotation for the tool to +// pick up on so this list will be used while we have this restriction in +// SBDefines.h. +static constexpr llvm::StringRef DisallowedMethods[] = { +// The threading functionality in SBHostOS is deprecated and thus we do not +// generate them. It would be ideal to add the annotations to the methods +// and then support not generating deprecated methods. However, without +// annotations the generator generates most things correctly. This one is +// problematic because it returns a pointer to an "opaque" structure +// (thread_t) that is not `void *`, so special casing it is more effort than +// it's worth. +"_ZN4lldb8SBHostOS10ThreadJoinEP17_opaque_pthread_tPPvPNS_7SBErrorE", +"_ZN4lldb8SBHostOS12ThreadCancelEP17_opaque_pthread_tPNS_7SBErrorE", +"_ZN4lldb8SBHostOS12ThreadCreateEPKcPFPvS3_ES3_PNS_7SBErrorE", +"_ZN4lldb8SBHostOS12ThreadDetachEP17_opaque_pthread_tPNS_7SBErrorE", +"_ZN4lldb8SBHostOS13ThreadCreatedEPKc", +}; + +static constexpr llvm::StringRef ClassesWithoutDefaultCtor[] = { +"SBHostOS", +"SBReproducer", +}; + +static constexpr llvm::StringRef ClassesWithoutCopyOperations[] = { +"SBHostOS", +"SBReproducer", +"SBStream", +"SBProgress", +}; + +static constexpr llvm::StringRef MethodsWithPointerPlusLen[] = { +"_ZN4lldb6SBData11ReadRawDataERNS_7SBErrorEyPvm", +"_ZN4lldb6SBData7SetDataERNS_7SBErrorEPKvmNS_9ByteOrderEh", +"_ZN4
[Lldb-commits] [lldb] [lldb] Implement JSON RPC (newline delimited) Transport (PR #143946)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/143946 >From 9ebb3986e008cec978c0111557a02a9a8d720838 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 12 Jun 2025 11:19:15 -0700 Subject: [PATCH 1/2] [lldb] Implement JSON RPC (newline delimited) Transport This PR implements JSON RPC-style (i.e. newline delimited) JSON transport. I moved the existing transport tests from DAP to Host and moved the PipeTest base class into TestingSupport so it can be shared by both. --- lldb/include/lldb/Host/JSONTransport.h| 15 ++ lldb/source/Host/common/JSONTransport.cpp | 31 +++- lldb/unittests/DAP/CMakeLists.txt | 1 - lldb/unittests/DAP/TestBase.cpp | 7 +- lldb/unittests/DAP/TestBase.h | 13 +- lldb/unittests/DAP/TransportTest.cpp | 98 lldb/unittests/Host/CMakeLists.txt| 1 + lldb/unittests/Host/JSONTransportTest.cpp | 146 ++ .../TestingSupport/Host/PipeTestUtilities.h | 28 9 files changed, 223 insertions(+), 117 deletions(-) delete mode 100644 lldb/unittests/DAP/TransportTest.cpp create mode 100644 lldb/unittests/Host/JSONTransportTest.cpp create mode 100644 lldb/unittests/TestingSupport/Host/PipeTestUtilities.h diff --git a/lldb/include/lldb/Host/JSONTransport.h b/lldb/include/lldb/Host/JSONTransport.h index 4db5e417ea852..f7593750669e1 100644 --- a/lldb/include/lldb/Host/JSONTransport.h +++ b/lldb/include/lldb/Host/JSONTransport.h @@ -121,6 +121,21 @@ class HTTPDelimitedJSONTransport : public JSONTransport { static constexpr llvm::StringLiteral kHeaderSeparator = "\r\n\r\n"; }; +/// A transport class for JSON RPC. +class JSONRPCTransport : public JSONTransport { +public: + JSONRPCTransport(lldb::IOObjectSP input, lldb::IOObjectSP output) + : JSONTransport(input, output) {} + virtual ~JSONRPCTransport() = default; + +protected: + virtual llvm::Error WriteImpl(const std::string &message) override; + virtual llvm::Expected + ReadImpl(const std::chrono::microseconds &timeout) override; + + static constexpr llvm::StringLiteral kMessageSeparator = "\n"; +}; + } // namespace lldb_private #endif diff --git a/lldb/source/Host/common/JSONTransport.cpp b/lldb/source/Host/common/JSONTransport.cpp index 103c76d25daf7..7b925372e0b74 100644 --- a/lldb/source/Host/common/JSONTransport.cpp +++ b/lldb/source/Host/common/JSONTransport.cpp @@ -92,7 +92,7 @@ void JSONTransport::Log(llvm::StringRef message) { Expected HTTPDelimitedJSONTransport::ReadImpl(const std::chrono::microseconds &timeout) { if (!m_input || !m_input->IsValid()) -return createStringError("transport output is closed"); +return llvm::make_error(); IOObject *input = m_input.get(); Expected message_header = @@ -142,6 +142,35 @@ Error HTTPDelimitedJSONTransport::WriteImpl(const std::string &message) { return m_output->Write(Output.data(), num_bytes).takeError(); } +Expected +JSONRPCTransport::ReadImpl(const std::chrono::microseconds &timeout) { + if (!m_input || !m_input->IsValid()) +return make_error(); + + IOObject *input = m_input.get(); + Expected raw_json = + ReadUntil(*input, kMessageSeparator, timeout); + if (!raw_json) +return raw_json.takeError(); + + Log(llvm::formatv("--> {0}", *raw_json).str()); + + return *raw_json; +} + +Error JSONRPCTransport::WriteImpl(const std::string &message) { + if (!m_output || !m_output->IsValid()) +return llvm::make_error(); + + Log(llvm::formatv("<-- {0}", message).str()); + + std::string Output; + llvm::raw_string_ostream OS(Output); + OS << message << kMessageSeparator; + size_t num_bytes = Output.size(); + return m_output->Write(Output.data(), num_bytes).takeError(); +} + char TransportEOFError::ID; char TransportTimeoutError::ID; char TransportClosedError::ID; diff --git a/lldb/unittests/DAP/CMakeLists.txt b/lldb/unittests/DAP/CMakeLists.txt index 37a6a81ad12a0..ee623d341ec69 100644 --- a/lldb/unittests/DAP/CMakeLists.txt +++ b/lldb/unittests/DAP/CMakeLists.txt @@ -7,7 +7,6 @@ add_lldb_unittest(DAPTests LLDBUtilsTest.cpp ProtocolTypesTest.cpp TestBase.cpp - TransportTest.cpp VariablesTest.cpp LINK_COMPONENTS diff --git a/lldb/unittests/DAP/TestBase.cpp b/lldb/unittests/DAP/TestBase.cpp index 4063b34250312..27ad42686fbbf 100644 --- a/lldb/unittests/DAP/TestBase.cpp +++ b/lldb/unittests/DAP/TestBase.cpp @@ -28,13 +28,8 @@ using lldb_private::File; using lldb_private::NativeFile; using lldb_private::Pipe; -void PipeBase::SetUp() { - ASSERT_THAT_ERROR(input.CreateNew(false).ToError(), Succeeded()); - ASSERT_THAT_ERROR(output.CreateNew(false).ToError(), Succeeded()); -} - void TransportBase::SetUp() { - PipeBase::SetUp(); + PipeTest::SetUp(); to_dap = std::make_unique( "to_dap", nullptr, std::make_shared(input.GetReadFileDescriptor(), diff --git a/lldb/unittests/DAP/TestBase.h b/lldb/unittests/DAP/TestBase.h index 70b39852
[Lldb-commits] [lldb] Reland "[lldb][headers] Create Python script to fix up framework head… (PR #143945)
https://github.com/chelcassanova updated https://github.com/llvm/llvm-project/pull/143945 >From 9a1eedd202a7c5e27bd1ec8a907cc1a650ed4e67 Mon Sep 17 00:00:00 2001 From: Chelsea Cassanova Date: Thu, 12 Jun 2025 10:46:36 -0700 Subject: [PATCH] Reland "[lldb][headers] Create Python script to fix up framework headers" (#143941) Reland the script that converts lldb headers to RPC headers. The RPC test was failing due to the incorrect input filepath being used. --- lldb/cmake/modules/LLDBFramework.cmake| 42 +++--- lldb/scripts/framework-header-fix.py | 126 ++ .../Shell/Scripts/Inputs/Main/SBAddress.h | 13 ++ .../Shell/Scripts/Inputs/RPC/RPCSBAddress.h | 9 ++ .../Shell/Scripts/TestFrameworkFixScript.test | 11 ++ .../Scripts/TestFrameworkFixUnifdef.test | 12 ++ .../Scripts/TestRPCFrameworkFixScript.test| 14 ++ 7 files changed, 206 insertions(+), 21 deletions(-) create mode 100755 lldb/scripts/framework-header-fix.py create mode 100644 lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h create mode 100644 lldb/test/Shell/Scripts/Inputs/RPC/RPCSBAddress.h create mode 100644 lldb/test/Shell/Scripts/TestFrameworkFixScript.test create mode 100644 lldb/test/Shell/Scripts/TestFrameworkFixUnifdef.test create mode 100644 lldb/test/Shell/Scripts/TestRPCFrameworkFixScript.test diff --git a/lldb/cmake/modules/LLDBFramework.cmake b/lldb/cmake/modules/LLDBFramework.cmake index 8961b1afe93ad..70010ffbf738c 100644 --- a/lldb/cmake/modules/LLDBFramework.cmake +++ b/lldb/cmake/modules/LLDBFramework.cmake @@ -68,24 +68,17 @@ if(NOT APPLE_EMBEDDED) ) endif() -# At configuration time, collect headers for the framework bundle and copy them -# into a staging directory. Later we can copy over the entire folder. -file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h) -set(generated_public_headers ${LLDB_OBJ_DIR}/include/lldb/API/SBLanguages.h) -file(GLOB root_public_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-*.h) -file(GLOB root_private_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h) -list(REMOVE_ITEM root_public_headers ${root_private_headers}) - find_program(unifdef_EXECUTABLE unifdef) -set(lldb_header_staging ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders) -foreach(header -${public_headers} -${generated_public_headers} -${root_public_headers}) +# All necessary header files will be staged in the include directory in the build directory, +# so just copy the files from there into the framework's staging directory. +set(lldb_build_dir_header_staging "${CMAKE_BINARY_DIR}/include/lldb") +set(lldb_framework_header_staging "${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders") +file(GLOB lldb_build_dir_header_staging_list ${lldb_build_dir_header_staging}/*) +foreach(header ${lldb_build_dir_header_staging_list}) get_filename_component(basename ${header} NAME) - set(staged_header ${lldb_header_staging}/${basename}) + set(staged_header ${lldb_framework_header_staging}/${basename}) if(unifdef_EXECUTABLE) # unifdef returns 0 when the file is unchanged and 1 if something was changed. @@ -112,13 +105,20 @@ set_target_properties(liblldb-resource-headers PROPERTIES FOLDER "LLDB/Resources add_dependencies(liblldb-resource-headers liblldb-header-staging) add_dependencies(liblldb liblldb-resource-headers) -# At build time, copy the staged headers into the framework bundle (and do -# some post-processing in-place). -add_custom_command(TARGET liblldb POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory ${lldb_header_staging} $/Headers - COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.sh $/Headers ${LLDB_VERSION} - COMMENT "LLDB.framework: copy framework headers" -) +# Take the headers from the staging directory and fix up their includes for the framework. +# Then write them to the output directory. +# Also, run unifdef to remove any specified guards from the header files. +file(GLOB lldb_framework_header_staging_list ${lldb_framework_header_staging}/*) +foreach(header ${lldb_framework_header_staging_list}) + + set(input_header ${header}) + set(output_header $/Headers/${input_header}) + + add_custom_command(TARGET liblldb POST_BUILD +COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.py -f lldb_main -i ${input_header} -o ${output_header} -p ${unifdef_EXECUTABLE} USWIG +COMMENT "LLDB.framework: Fix up and copy framework headers" + ) +endforeach() # Copy vendor-specific headers from clang (without staging). if(NOT APPLE_EMBEDDED) diff --git a/lldb/scripts/framework-header-fix.py b/lldb/scripts/framework-header-fix.py new file mode 100755 index 0..9528fdb7e30bd --- /dev/null +++ b/lldb/scripts/framework-header-fix.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python3 + +""" +Usage: + +This script is used when building LLDB.framework or LLDBRPC.framework. For each framework, local includes are converted to their respective framework includes. + +This script is used in 2 ways: +1. It is
[Lldb-commits] [lldb] Reland "[lldb][headers] Create Python script to fix up framework head… (PR #143945)
https://github.com/chelcassanova edited https://github.com/llvm/llvm-project/pull/143945 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Implement JSON RPC (newline delimited) Transport (PR #143946)
https://github.com/ashgti approved this pull request. LGTM! https://github.com/llvm/llvm-project/pull/143946 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Implement JSON RPC (newline delimited) Transport (PR #143946)
@@ -0,0 +1,146 @@ +//===-- JSONTransportTest.cpp -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "lldb/Host/JSONTransport.h" +#include "TestingSupport/Host/PipeTestUtilities.h" +#include "lldb/Host/File.h" + +using namespace llvm; +using namespace lldb_private; + +namespace { +template class JSONTransportTest : public PipeTest { +protected: + std::unique_ptr transport; + + void SetUp() override { +PipeTest::SetUp(); +transport = std::make_unique( +std::make_shared(input.GetReadFileDescriptor(), + File::eOpenOptionReadOnly, + NativeFile::Unowned), +std::make_shared(output.GetWriteFileDescriptor(), + File::eOpenOptionWriteOnly, + NativeFile::Unowned)); + } +}; + +class HTTPDelimitedJSONTransportTest +: public JSONTransportTest { +public: + using JSONTransportTest::JSONTransportTest; +}; + +class JSONRPCTransportTest : public JSONTransportTest { +public: + using JSONTransportTest::JSONTransportTest; +}; + +struct JSONTestType { + std::string str; +}; + +llvm::json::Value toJSON(const JSONTestType &T) { + return llvm::json::Object{{"str", T.str}}; +} + +bool fromJSON(const llvm::json::Value &V, JSONTestType &T, llvm::json::Path P) { + llvm::json::ObjectMapper O(V, P); + return O && O.map("str", T.str); +} +} // namespace + +TEST_F(HTTPDelimitedJSONTransportTest, MalformedRequests) { + std::string malformed_header = "COnTent-LenGth: -1{}\r\n\r\nnotjosn"; + ASSERT_THAT_EXPECTED( + input.Write(malformed_header.data(), malformed_header.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + FailedWithMessage( + "expected 'Content-Length: ' and got 'COnTent-LenGth: '")); +} + +TEST_F(HTTPDelimitedJSONTransportTest, Read) { + std::string json = R"json({"str": "foo"})json"; + std::string message = + formatv("Content-Length: {0}\r\n\r\n{1}", json.size(), json).str(); + ASSERT_THAT_EXPECTED(input.Write(message.data(), message.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + HasValue(testing::FieldsAre(/*str=*/"foo"))); +} + +TEST_F(HTTPDelimitedJSONTransportTest, ReadWithTimeout) { + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + Failed()); +} + +TEST_F(HTTPDelimitedJSONTransportTest, ReadWithEOF) { + input.CloseWriteFileDescriptor(); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + Failed()); +} + +TEST_F(HTTPDelimitedJSONTransportTest, Write) { + ASSERT_THAT_ERROR(transport->Write(JSONTestType{"foo"}), Succeeded()); + output.CloseWriteFileDescriptor(); + char buf[1024]; + Expected bytes_read = + output.Read(buf, sizeof(buf), std::chrono::milliseconds(1)); + ASSERT_THAT_EXPECTED(bytes_read, Succeeded()); + ASSERT_EQ(StringRef(buf, *bytes_read), StringRef("Content-Length: 13\r\n\r\n" + R"json({"str":"foo"})json")); +} + +TEST_F(JSONRPCTransportTest, MalformedRequests) { + std::string malformed_header = "notjson\n"; + ASSERT_THAT_EXPECTED( + input.Write(malformed_header.data(), malformed_header.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + llvm::Failed()); +} + +TEST_F(JSONRPCTransportTest, Read) { + std::string json = R"json({"str": "foo"})json"; + std::string message = formatv("{0}\n", json).str(); + ASSERT_THAT_EXPECTED(input.Write(message.data(), message.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + HasValue(testing::FieldsAre(/*str=*/"foo"))); +} + +TEST_F(JSONRPCTransportTest, ReadWithTimeout) { + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + Failed()); +} + +TEST_F(JSONRPCTransportTest, ReadWithEOF) { + input.CloseWriteFileDescriptor(); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + Failed()); +} + +TEST_F(JSONRPCTransportTest, Write) { JDevlieghere wrote: Added a test and renamed the error as the current name isn't really accurate: this error occurs when the underlying IO object is invalid. If you close the write side, you get an EOF error, which we have a test for. If you close the read side, then you get a bad file descriptor error, which I've added a new test for too. https://github.com/llvm/llvm-project/pull/143946 _
[Lldb-commits] [lldb] Reland "[lldb][headers] Create Python script to fix up framework head… (PR #143945)
https://github.com/JDevlieghere approved this pull request. https://github.com/llvm/llvm-project/pull/143945 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 1a4cf1d - [lldb][headers] Create Python script to fix up framework headers (#142051)
Author: Chelsea Cassanova Date: 2025-06-12T10:07:45-07:00 New Revision: 1a4cf1d3edff2d4c790f597834301702cfc6dc15 URL: https://github.com/llvm/llvm-project/commit/1a4cf1d3edff2d4c790f597834301702cfc6dc15 DIFF: https://github.com/llvm/llvm-project/commit/1a4cf1d3edff2d4c790f597834301702cfc6dc15.diff LOG: [lldb][headers] Create Python script to fix up framework headers (#142051) This commit replaces the shell script that fixes up includes for the LLDB framework with a Python script. This script will also be used when fixing up includes for the LLDBRPC.framework. Added: lldb/scripts/framework-header-fix.py lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h lldb/test/Shell/Scripts/Inputs/RPC/RPCSBAddress.h lldb/test/Shell/Scripts/TestFrameworkFixScript.test lldb/test/Shell/Scripts/TestFrameworkFixUnifdef.test lldb/test/Shell/Scripts/TestRPCFrameworkFixScript.test Modified: lldb/cmake/modules/LLDBFramework.cmake Removed: diff --git a/lldb/cmake/modules/LLDBFramework.cmake b/lldb/cmake/modules/LLDBFramework.cmake index 8961b1afe93ad..70010ffbf738c 100644 --- a/lldb/cmake/modules/LLDBFramework.cmake +++ b/lldb/cmake/modules/LLDBFramework.cmake @@ -68,24 +68,17 @@ if(NOT APPLE_EMBEDDED) ) endif() -# At configuration time, collect headers for the framework bundle and copy them -# into a staging directory. Later we can copy over the entire folder. -file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h) -set(generated_public_headers ${LLDB_OBJ_DIR}/include/lldb/API/SBLanguages.h) -file(GLOB root_public_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-*.h) -file(GLOB root_private_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h) -list(REMOVE_ITEM root_public_headers ${root_private_headers}) - find_program(unifdef_EXECUTABLE unifdef) -set(lldb_header_staging ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders) -foreach(header -${public_headers} -${generated_public_headers} -${root_public_headers}) +# All necessary header files will be staged in the include directory in the build directory, +# so just copy the files from there into the framework's staging directory. +set(lldb_build_dir_header_staging "${CMAKE_BINARY_DIR}/include/lldb") +set(lldb_framework_header_staging "${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders") +file(GLOB lldb_build_dir_header_staging_list ${lldb_build_dir_header_staging}/*) +foreach(header ${lldb_build_dir_header_staging_list}) get_filename_component(basename ${header} NAME) - set(staged_header ${lldb_header_staging}/${basename}) + set(staged_header ${lldb_framework_header_staging}/${basename}) if(unifdef_EXECUTABLE) # unifdef returns 0 when the file is unchanged and 1 if something was changed. @@ -112,13 +105,20 @@ set_target_properties(liblldb-resource-headers PROPERTIES FOLDER "LLDB/Resources add_dependencies(liblldb-resource-headers liblldb-header-staging) add_dependencies(liblldb liblldb-resource-headers) -# At build time, copy the staged headers into the framework bundle (and do -# some post-processing in-place). -add_custom_command(TARGET liblldb POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory ${lldb_header_staging} $/Headers - COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.sh $/Headers ${LLDB_VERSION} - COMMENT "LLDB.framework: copy framework headers" -) +# Take the headers from the staging directory and fix up their includes for the framework. +# Then write them to the output directory. +# Also, run unifdef to remove any specified guards from the header files. +file(GLOB lldb_framework_header_staging_list ${lldb_framework_header_staging}/*) +foreach(header ${lldb_framework_header_staging_list}) + + set(input_header ${header}) + set(output_header $/Headers/${input_header}) + + add_custom_command(TARGET liblldb POST_BUILD +COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.py -f lldb_main -i ${input_header} -o ${output_header} -p ${unifdef_EXECUTABLE} USWIG +COMMENT "LLDB.framework: Fix up and copy framework headers" + ) +endforeach() # Copy vendor-specific headers from clang (without staging). if(NOT APPLE_EMBEDDED) diff --git a/lldb/scripts/framework-header-fix.py b/lldb/scripts/framework-header-fix.py new file mode 100755 index 0..9e4e5f860a2c0 --- /dev/null +++ b/lldb/scripts/framework-header-fix.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python3 + +""" +Usage: + +This script is used when building LLDB.framework or LLDBRPC.framework. For each framework, local includes are converted to their respective framework includes. + +This script is used in 2 ways: +1. It is used on header files that are copied into LLDB.framework. For these files, local LLDB includes are converted into framework includes, e.g. #include "lldb/API/SBDefines.h" -> #include . + +2. It is used on header files for LLDBRPC.framework. For these files, includes of RPC common files wi
[Lldb-commits] [lldb] [lldb][headers] Create Python script to fix up framework headers (PR #142051)
https://github.com/chelcassanova closed https://github.com/llvm/llvm-project/pull/142051 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Commands] Fix memory find for Swift expressions (PR #143860)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/143860 >From 953c71de0b3d21309a4ebbe71cab8618c16dd699 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Wed, 11 Jun 2025 12:26:51 +0100 Subject: [PATCH 1/2] [lldb][Commands] Fix memory find for Swift expressions There were two issues previously preventing `memory find -e` expressions to succeed when stopped in Swift frames: 1. We weren't getting the dynamic type of the result `ValueObject`. For Swift this would fail when we tried to produce a scalar value out of it because the static VO wasn't sufficient to get to the integer value. Hence we add a call to `GetQualifiedRepresentationIfAvailable` (which is what we do for expressions in `OptionArgParser::ToAddress` too). 2. We weren't passing an `ExecutionContextScope` to `GetByteSize`, which Swift relied on to get the size of the result type. My plan is to add an API test for this on the Apple `swiftlang/llvm-project` fork. I considered an alternative where we use `OptionArgParser::ToAddress` for `memory find -e` expressions, but it got a bit icky when trying to figure out how many bytes we should copy out of the result into the `DataBufferHeap` (currently we rely on the size of the result variable type). This gets even trickier when we were to pass an expression that was actually a hex digit or a number into `ToAddress`. rdar://152113525 --- lldb/source/Commands/CommandObjectMemory.cpp | 13 ++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 85ae9f8f9e8cb..2bcbc4291f7dd 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -886,9 +886,10 @@ class CommandObjectMemoryRead : public CommandObjectParsed { #include "CommandOptions.inc" static llvm::Error CopyExpressionResult(ValueObject &result, -DataBufferHeap &buffer) { +DataBufferHeap &buffer, +ExecutionContextScope *scope) { uint64_t value = result.GetValueAsUnsigned(0); - auto size_or_err = result.GetCompilerType().GetByteSize(nullptr); + auto size_or_err = result.GetCompilerType().GetByteSize(scope); if (!size_or_err) return size_or_err.takeError(); @@ -928,6 +929,11 @@ EvaluateExpression(llvm::StringRef expression, StackFrame &frame, return llvm::createStringError( "expression evaluation failed. pass a string instead"); + result_sp = result_sp->GetQualifiedRepresentationIfAvailable( + result_sp->GetDynamicValueType(), /*synthValue=*/true); + if (!result_sp) +return llvm::createStringError("failed to unwrap expression result type"); + return result_sp; } @@ -1082,7 +1088,8 @@ class CommandObjectMemoryFind : public CommandObjectParsed { ValueObjectSP result_sp = *result_or_err; - if (auto err = CopyExpressionResult(*result_sp, buffer)) { + if (auto err = CopyExpressionResult(*result_sp, buffer, + m_exe_ctx.GetFramePtr())) { result.AppendError(llvm::toString(std::move(err))); return; } >From 566b9576266d2f50e1cc69a6d99f4b737654b030 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Thu, 12 Jun 2025 17:04:48 +0100 Subject: [PATCH 2/2] fixup! improve error message --- lldb/source/Commands/CommandObjectMemory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 2bcbc4291f7dd..ccb06d8ff4d59 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -932,7 +932,7 @@ EvaluateExpression(llvm::StringRef expression, StackFrame &frame, result_sp = result_sp->GetQualifiedRepresentationIfAvailable( result_sp->GetDynamicValueType(), /*synthValue=*/true); if (!result_sp) -return llvm::createStringError("failed to unwrap expression result type"); +return llvm::createStringError("failed to get dynamic result type"); return result_sp; } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Commands] Fix memory find for Swift expressions (PR #143860)
@@ -928,6 +929,11 @@ EvaluateExpression(llvm::StringRef expression, StackFrame &frame, return llvm::createStringError( "expression evaluation failed. pass a string instead"); + result_sp = result_sp->GetQualifiedRepresentationIfAvailable( + result_sp->GetDynamicValueType(), /*synthValue=*/true); + if (!result_sp) +return llvm::createStringError("failed to unwrap expression result type"); Michael137 wrote: ```suggestion return llvm::createStringError("failed to get dynamic result type"); ``` https://github.com/llvm/llvm-project/pull/143860 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] c6da2c8 - [lldb][Commands] Fix memory find for Swift expressions (#143860)
Author: Michael Buch Date: 2025-06-12T17:14:31+01:00 New Revision: c6da2c877cb407c0404e58c5ca257d12036ed164 URL: https://github.com/llvm/llvm-project/commit/c6da2c877cb407c0404e58c5ca257d12036ed164 DIFF: https://github.com/llvm/llvm-project/commit/c6da2c877cb407c0404e58c5ca257d12036ed164.diff LOG: [lldb][Commands] Fix memory find for Swift expressions (#143860) (depends on https://github.com/llvm/llvm-project/pull/143686) There were two issues previously preventing `memory find -e` expressions to succeed when stopped in Swift frames: 1. We weren't getting the dynamic type of the result `ValueObject`. For Swift this would fail when we tried to produce a scalar value out of it because the static VO wasn't sufficient to get to the integer value. Hence we add a call to `GetQualifiedRepresentationIfAvailable` (which is what we do for expressions in `OptionArgParser::ToAddress` too). 2. We weren't passing an `ExecutionContextScope` to `GetByteSize`, which Swift relied on to get the size of the result type. My plan is to add an API test for this on the Apple `swiftlang/llvm-project` fork. I considered an alternative where we use `OptionArgParser::ToAddress` for `memory find -e` expressions, but it got a bit icky when trying to figure out how many bytes we should copy out of the result into the `DataBufferHeap` (currently we rely on the size of the result variable type). This gets even trickier when we were to pass an expression that was actually a hex digit or a number into `ToAddress`. rdar://152113525 Added: Modified: lldb/source/Commands/CommandObjectMemory.cpp Removed: diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 85ae9f8f9e8cb..ccb06d8ff4d59 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -886,9 +886,10 @@ class CommandObjectMemoryRead : public CommandObjectParsed { #include "CommandOptions.inc" static llvm::Error CopyExpressionResult(ValueObject &result, -DataBufferHeap &buffer) { +DataBufferHeap &buffer, +ExecutionContextScope *scope) { uint64_t value = result.GetValueAsUnsigned(0); - auto size_or_err = result.GetCompilerType().GetByteSize(nullptr); + auto size_or_err = result.GetCompilerType().GetByteSize(scope); if (!size_or_err) return size_or_err.takeError(); @@ -928,6 +929,11 @@ EvaluateExpression(llvm::StringRef expression, StackFrame &frame, return llvm::createStringError( "expression evaluation failed. pass a string instead"); + result_sp = result_sp->GetQualifiedRepresentationIfAvailable( + result_sp->GetDynamicValueType(), /*synthValue=*/true); + if (!result_sp) +return llvm::createStringError("failed to get dynamic result type"); + return result_sp; } @@ -1082,7 +1088,8 @@ class CommandObjectMemoryFind : public CommandObjectParsed { ValueObjectSP result_sp = *result_or_err; - if (auto err = CopyExpressionResult(*result_sp, buffer)) { + if (auto err = CopyExpressionResult(*result_sp, buffer, + m_exe_ctx.GetFramePtr())) { result.AppendError(llvm::toString(std::move(err))); return; } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Commands] Fix memory find for Swift expressions (PR #143860)
https://github.com/Michael137 closed https://github.com/llvm/llvm-project/pull/143860 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][headers] Create Python script to fix up framework headers (PR #142051)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `lldb-aarch64-ubuntu` running on `linaro-lldb-aarch64-ubuntu` while building `lldb` at step 6 "test". Full details are available at: https://lab.llvm.org/buildbot/#/builders/59/builds/19255 Here is the relevant piece of the build log for the reference ``` Step 6 (test) failure: build (failure) ... PASS: lldb-shell :: ScriptInterpreter/Python/fail_breakpoint_oneline.test (1609 of 2258) PASS: lldb-shell :: ScriptInterpreter/Python/command_import.test (1610 of 2258) PASS: lldb-shell :: ScriptInterpreter/Python/bytecode.test (1611 of 2258) PASS: lldb-shell :: ScriptInterpreter/Python/sb_address_exception.test (1612 of 2258) PASS: lldb-shell :: Recognizer/verbose_trap.test (1613 of 2258) PASS: lldb-shell :: ScriptInterpreter/Python/scripted_breakpoint.test (1614 of 2258) PASS: lldb-shell :: ScriptInterpreter/Python/sb_function_ranges.s (1615 of 2258) UNSUPPORTED: lldb-shell :: Scripts/TestFrameworkFixUnifdef.test (1616 of 2258) PASS: lldb-shell :: ScriptInterpreter/Python/scripted_breakpoint_lua.test (1617 of 2258) PASS: lldb-shell :: Scripts/TestFrameworkFixScript.test (1618 of 2258) FAIL: lldb-shell :: Scripts/TestRPCFrameworkFixScript.test (1619 of 2258) TEST 'lldb-shell :: Scripts/TestRPCFrameworkFixScript.test' FAILED Exit Code: 1 Command Output (stderr): -- mkdir -p /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/Scripts/Output/TestRPCFrameworkFixScript.test.tmp/Outputs # RUN: at line 2 + mkdir -p /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/Scripts/Output/TestRPCFrameworkFixScript.test.tmp/Outputs "/usr/bin/python3.10" /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/Shell/Scripts/../../../scripts/framework-header-fix.py -f lldb_rpc -i /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/Shell/Scripts/Inputs/Main/RPCSBAddress.h -o /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/Scripts/Output/TestRPCFrameworkFixScript.test.tmp/Outputs/RPCSBAddress.h -p /usr/bin/unifdef USWIG # RUN: at line 3 + /usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/Shell/Scripts/../../../scripts/framework-header-fix.py -f lldb_rpc -i /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/Shell/Scripts/Inputs/Main/RPCSBAddress.h -o /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/test/Shell/Scripts/Output/TestRPCFrameworkFixScript.test.tmp/Outputs/RPCSBAddress.h -p /usr/bin/unifdef USWIG Traceback (most recent call last): File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/Shell/Scripts/../../../scripts/framework-header-fix.py", line 126, in main() File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/Shell/Scripts/../../../scripts/framework-header-fix.py", line 119, in main modify_rpc_includes(input_file_path, output_file_path) File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/Shell/Scripts/../../../scripts/framework-header-fix.py", line 32, in modify_rpc_includes with open(input_file_path, "r") as input_file: FileNotFoundError: [Errno 2] No such file or directory: '/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/Shell/Scripts/Inputs/Main/RPCSBAddress.h' -- PASS: lldb-shell :: Scripts/TestVersionFixScript.test (1620 of 2258) PASS: lldb-shell :: ScriptInterpreter/Python/silent_command_script_import.test (1621 of 2258) PASS: lldb-shell :: Settings/TestCxxFrameFormat.test (1622 of 2258) UNSUPPORTED: lldb-shell :: Settings/TestCxxFrameFormatRecursive.test (1623 of 2258) PASS: lldb-api :: tools/lldb-server/TestNonStop.py (1624 of 2258) PASS: lldb-shell :: Settings/TestDefaultModuleCachePath.test (1625 of 2258) PASS: lldb-shell :: Settings/TestCxxFrameFormatMixedLanguages.test (1626 of 2258) PASS: lldb-shell :: Settings/TestCxxFrameFormatObjC.test (1627 of 2258) PASS: lldb-shell :: Settings/TestDisableColor.test (1628 of 2258) PASS: lldb-shell :: Settings/TestDisassemblyFormat.test (1629 of 2258) PASS: lldb-shell :: Settings/TestCxxFrameFormatPartialFailure.test (1630 of 2258) PASS: lldb-shell :: Settings/TestEchoCommandsQuiet.test (1631 of 2258) PASS: lldb-shell :: ScriptInterpreter/Python/python.test (1632 of 2258) PASS: lldb-shell :: ScriptInterpreter/Python/exit.test (1633 of 2258) PASS: lldb-shell :: Settings/TestEchoCommands.test (1634 of 2258) PASS: lldb-shell :: Settings/TestFrameFormatColor.test (1635 of 2258) PASS: lldb-shell :: Settings/TestFrameFormatFunctionBasenameObjC.test (1636 of 2258) ``` https://github.com/llvm/llvm-project/pull/142051 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Implement JSON RPC (newline delimited) Transport (PR #143946)
@@ -0,0 +1,146 @@ +//===-- JSONTransportTest.cpp -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "lldb/Host/JSONTransport.h" +#include "TestingSupport/Host/PipeTestUtilities.h" +#include "lldb/Host/File.h" + +using namespace llvm; +using namespace lldb_private; + +namespace { +template class JSONTransportTest : public PipeTest { +protected: + std::unique_ptr transport; + + void SetUp() override { +PipeTest::SetUp(); +transport = std::make_unique( +std::make_shared(input.GetReadFileDescriptor(), + File::eOpenOptionReadOnly, + NativeFile::Unowned), +std::make_shared(output.GetWriteFileDescriptor(), + File::eOpenOptionWriteOnly, + NativeFile::Unowned)); + } +}; + +class HTTPDelimitedJSONTransportTest +: public JSONTransportTest { +public: + using JSONTransportTest::JSONTransportTest; +}; + +class JSONRPCTransportTest : public JSONTransportTest { +public: + using JSONTransportTest::JSONTransportTest; +}; + +struct JSONTestType { + std::string str; +}; + +llvm::json::Value toJSON(const JSONTestType &T) { + return llvm::json::Object{{"str", T.str}}; +} + +bool fromJSON(const llvm::json::Value &V, JSONTestType &T, llvm::json::Path P) { + llvm::json::ObjectMapper O(V, P); + return O && O.map("str", T.str); +} +} // namespace + +TEST_F(HTTPDelimitedJSONTransportTest, MalformedRequests) { + std::string malformed_header = "COnTent-LenGth: -1{}\r\n\r\nnotjosn"; + ASSERT_THAT_EXPECTED( + input.Write(malformed_header.data(), malformed_header.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + FailedWithMessage( + "expected 'Content-Length: ' and got 'COnTent-LenGth: '")); +} + +TEST_F(HTTPDelimitedJSONTransportTest, Read) { + std::string json = R"json({"str": "foo"})json"; + std::string message = + formatv("Content-Length: {0}\r\n\r\n{1}", json.size(), json).str(); + ASSERT_THAT_EXPECTED(input.Write(message.data(), message.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + HasValue(testing::FieldsAre(/*str=*/"foo"))); +} + +TEST_F(HTTPDelimitedJSONTransportTest, ReadWithTimeout) { + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + Failed()); +} + +TEST_F(HTTPDelimitedJSONTransportTest, ReadWithEOF) { + input.CloseWriteFileDescriptor(); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + Failed()); +} + +TEST_F(HTTPDelimitedJSONTransportTest, Write) { + ASSERT_THAT_ERROR(transport->Write(JSONTestType{"foo"}), Succeeded()); + output.CloseWriteFileDescriptor(); + char buf[1024]; + Expected bytes_read = + output.Read(buf, sizeof(buf), std::chrono::milliseconds(1)); + ASSERT_THAT_EXPECTED(bytes_read, Succeeded()); + ASSERT_EQ(StringRef(buf, *bytes_read), StringRef("Content-Length: 13\r\n\r\n" + R"json({"str":"foo"})json")); +} + +TEST_F(JSONRPCTransportTest, MalformedRequests) { + std::string malformed_header = "notjson\n"; + ASSERT_THAT_EXPECTED( + input.Write(malformed_header.data(), malformed_header.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + llvm::Failed()); +} + +TEST_F(JSONRPCTransportTest, Read) { + std::string json = R"json({"str": "foo"})json"; + std::string message = formatv("{0}\n", json).str(); + ASSERT_THAT_EXPECTED(input.Write(message.data(), message.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + HasValue(testing::FieldsAre(/*str=*/"foo"))); +} + +TEST_F(JSONRPCTransportTest, ReadWithTimeout) { + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + Failed()); +} ashgti wrote: I've just realized, should this test be skipped on Windows? The lldb `SelectHelper` only works with sockets on Windows and under the hood the `Pipe` is making a named socket, but I'm not sure if we're using the right API to realize that or not. When we create the handle we're using `NativeFile` that may be handling this correctly. This all might be working correctly on Windows, but I'll be honest that I cannot tell for sure. The frustrating (for me) part is that on Windows, stdin/stdout are [anonymous pipes](https://learn.microsoft.com/en-us/windows/win32/ipc/anonymous-pipe-operations) and you cannot use overlapping IO
[Lldb-commits] [lldb] [lldb] Implement JSON RPC (newline delimited) Transport (PR #143946)
@@ -0,0 +1,146 @@ +//===-- JSONTransportTest.cpp -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "lldb/Host/JSONTransport.h" +#include "TestingSupport/Host/PipeTestUtilities.h" +#include "lldb/Host/File.h" + +using namespace llvm; +using namespace lldb_private; + +namespace { +template class JSONTransportTest : public PipeTest { +protected: + std::unique_ptr transport; + + void SetUp() override { +PipeTest::SetUp(); +transport = std::make_unique( +std::make_shared(input.GetReadFileDescriptor(), + File::eOpenOptionReadOnly, + NativeFile::Unowned), +std::make_shared(output.GetWriteFileDescriptor(), + File::eOpenOptionWriteOnly, + NativeFile::Unowned)); + } +}; + +class HTTPDelimitedJSONTransportTest +: public JSONTransportTest { +public: + using JSONTransportTest::JSONTransportTest; +}; + +class JSONRPCTransportTest : public JSONTransportTest { +public: + using JSONTransportTest::JSONTransportTest; +}; + +struct JSONTestType { + std::string str; +}; + +llvm::json::Value toJSON(const JSONTestType &T) { + return llvm::json::Object{{"str", T.str}}; +} + +bool fromJSON(const llvm::json::Value &V, JSONTestType &T, llvm::json::Path P) { + llvm::json::ObjectMapper O(V, P); + return O && O.map("str", T.str); +} +} // namespace + +TEST_F(HTTPDelimitedJSONTransportTest, MalformedRequests) { + std::string malformed_header = "COnTent-LenGth: -1{}\r\n\r\nnotjosn"; + ASSERT_THAT_EXPECTED( + input.Write(malformed_header.data(), malformed_header.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + FailedWithMessage( + "expected 'Content-Length: ' and got 'COnTent-LenGth: '")); +} + +TEST_F(HTTPDelimitedJSONTransportTest, Read) { + std::string json = R"json({"str": "foo"})json"; + std::string message = + formatv("Content-Length: {0}\r\n\r\n{1}", json.size(), json).str(); + ASSERT_THAT_EXPECTED(input.Write(message.data(), message.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + HasValue(testing::FieldsAre(/*str=*/"foo"))); +} + +TEST_F(HTTPDelimitedJSONTransportTest, ReadWithTimeout) { + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + Failed()); +} + +TEST_F(HTTPDelimitedJSONTransportTest, ReadWithEOF) { + input.CloseWriteFileDescriptor(); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + Failed()); +} + +TEST_F(HTTPDelimitedJSONTransportTest, Write) { + ASSERT_THAT_ERROR(transport->Write(JSONTestType{"foo"}), Succeeded()); + output.CloseWriteFileDescriptor(); + char buf[1024]; + Expected bytes_read = + output.Read(buf, sizeof(buf), std::chrono::milliseconds(1)); + ASSERT_THAT_EXPECTED(bytes_read, Succeeded()); + ASSERT_EQ(StringRef(buf, *bytes_read), StringRef("Content-Length: 13\r\n\r\n" + R"json({"str":"foo"})json")); +} + +TEST_F(JSONRPCTransportTest, MalformedRequests) { + std::string malformed_header = "notjson\n"; + ASSERT_THAT_EXPECTED( + input.Write(malformed_header.data(), malformed_header.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + llvm::Failed()); +} + +TEST_F(JSONRPCTransportTest, Read) { + std::string json = R"json({"str": "foo"})json"; + std::string message = formatv("{0}\n", json).str(); + ASSERT_THAT_EXPECTED(input.Write(message.data(), message.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + HasValue(testing::FieldsAre(/*str=*/"foo"))); +} + +TEST_F(JSONRPCTransportTest, ReadWithTimeout) { + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + Failed()); +} + +TEST_F(JSONRPCTransportTest, ReadWithEOF) { + input.CloseWriteFileDescriptor(); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + Failed()); +} + +TEST_F(JSONRPCTransportTest, Write) { ashgti wrote: Should we also have a test where we close the input or output handle before the read/write to trigger the `TransportClosedError`? https://github.com/llvm/llvm-project/pull/143946 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Implement JSON RPC (newline delimited) Transport (PR #143946)
https://github.com/ashgti approved this pull request. https://github.com/llvm/llvm-project/pull/143946 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Implement JSON RPC (newline delimited) Transport (PR #143946)
@@ -0,0 +1,146 @@ +//===-- JSONTransportTest.cpp -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "lldb/Host/JSONTransport.h" +#include "TestingSupport/Host/PipeTestUtilities.h" +#include "lldb/Host/File.h" + +using namespace llvm; +using namespace lldb_private; + +namespace { +template class JSONTransportTest : public PipeTest { +protected: + std::unique_ptr transport; + + void SetUp() override { +PipeTest::SetUp(); +transport = std::make_unique( +std::make_shared(input.GetReadFileDescriptor(), + File::eOpenOptionReadOnly, + NativeFile::Unowned), +std::make_shared(output.GetWriteFileDescriptor(), + File::eOpenOptionWriteOnly, + NativeFile::Unowned)); + } +}; + +class HTTPDelimitedJSONTransportTest +: public JSONTransportTest { +public: + using JSONTransportTest::JSONTransportTest; +}; + +class JSONRPCTransportTest : public JSONTransportTest { +public: + using JSONTransportTest::JSONTransportTest; +}; + +struct JSONTestType { + std::string str; +}; + +llvm::json::Value toJSON(const JSONTestType &T) { + return llvm::json::Object{{"str", T.str}}; +} + +bool fromJSON(const llvm::json::Value &V, JSONTestType &T, llvm::json::Path P) { + llvm::json::ObjectMapper O(V, P); + return O && O.map("str", T.str); +} +} // namespace + +TEST_F(HTTPDelimitedJSONTransportTest, MalformedRequests) { + std::string malformed_header = "COnTent-LenGth: -1{}\r\n\r\nnotjosn"; + ASSERT_THAT_EXPECTED( + input.Write(malformed_header.data(), malformed_header.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + FailedWithMessage( + "expected 'Content-Length: ' and got 'COnTent-LenGth: '")); +} + +TEST_F(HTTPDelimitedJSONTransportTest, Read) { + std::string json = R"json({"str": "foo"})json"; + std::string message = + formatv("Content-Length: {0}\r\n\r\n{1}", json.size(), json).str(); + ASSERT_THAT_EXPECTED(input.Write(message.data(), message.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + HasValue(testing::FieldsAre(/*str=*/"foo"))); +} + +TEST_F(HTTPDelimitedJSONTransportTest, ReadWithTimeout) { + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + Failed()); +} + +TEST_F(HTTPDelimitedJSONTransportTest, ReadWithEOF) { + input.CloseWriteFileDescriptor(); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + Failed()); +} + +TEST_F(HTTPDelimitedJSONTransportTest, Write) { + ASSERT_THAT_ERROR(transport->Write(JSONTestType{"foo"}), Succeeded()); + output.CloseWriteFileDescriptor(); + char buf[1024]; + Expected bytes_read = + output.Read(buf, sizeof(buf), std::chrono::milliseconds(1)); + ASSERT_THAT_EXPECTED(bytes_read, Succeeded()); + ASSERT_EQ(StringRef(buf, *bytes_read), StringRef("Content-Length: 13\r\n\r\n" + R"json({"str":"foo"})json")); +} + +TEST_F(JSONRPCTransportTest, MalformedRequests) { + std::string malformed_header = "notjson\n"; + ASSERT_THAT_EXPECTED( + input.Write(malformed_header.data(), malformed_header.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + llvm::Failed()); +} + +TEST_F(JSONRPCTransportTest, Read) { + std::string json = R"json({"str": "foo"})json"; + std::string message = formatv("{0}\n", json).str(); + ASSERT_THAT_EXPECTED(input.Write(message.data(), message.size()), + Succeeded()); + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + HasValue(testing::FieldsAre(/*str=*/"foo"))); +} + +TEST_F(JSONRPCTransportTest, ReadWithTimeout) { + ASSERT_THAT_EXPECTED( + transport->Read(std::chrono::milliseconds(1)), + Failed()); +} JDevlieghere wrote: Ack, yeah I'm far from an expert myself, but it's good context, thanks. https://github.com/llvm/llvm-project/pull/143946 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Implement JSON RPC (newline delimited) Transport (PR #143946)
JDevlieghere wrote: > @JDevlieghere not a review, but any context on for the change? Just curious. Apologies for not providing more context. This is a continuation of https://github.com/llvm/llvm-project/pull/143806 which is partially motivated by https://discourse.llvm.org/t/rfc-adding-mcp-support-to-lldb/86798. https://github.com/llvm/llvm-project/pull/143946 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Implement JSON RPC (newline delimited) Transport (PR #143946)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/143946 >From 9ebb3986e008cec978c0111557a02a9a8d720838 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 12 Jun 2025 11:19:15 -0700 Subject: [PATCH 1/3] [lldb] Implement JSON RPC (newline delimited) Transport This PR implements JSON RPC-style (i.e. newline delimited) JSON transport. I moved the existing transport tests from DAP to Host and moved the PipeTest base class into TestingSupport so it can be shared by both. --- lldb/include/lldb/Host/JSONTransport.h| 15 ++ lldb/source/Host/common/JSONTransport.cpp | 31 +++- lldb/unittests/DAP/CMakeLists.txt | 1 - lldb/unittests/DAP/TestBase.cpp | 7 +- lldb/unittests/DAP/TestBase.h | 13 +- lldb/unittests/DAP/TransportTest.cpp | 98 lldb/unittests/Host/CMakeLists.txt| 1 + lldb/unittests/Host/JSONTransportTest.cpp | 146 ++ .../TestingSupport/Host/PipeTestUtilities.h | 28 9 files changed, 223 insertions(+), 117 deletions(-) delete mode 100644 lldb/unittests/DAP/TransportTest.cpp create mode 100644 lldb/unittests/Host/JSONTransportTest.cpp create mode 100644 lldb/unittests/TestingSupport/Host/PipeTestUtilities.h diff --git a/lldb/include/lldb/Host/JSONTransport.h b/lldb/include/lldb/Host/JSONTransport.h index 4db5e417ea852..f7593750669e1 100644 --- a/lldb/include/lldb/Host/JSONTransport.h +++ b/lldb/include/lldb/Host/JSONTransport.h @@ -121,6 +121,21 @@ class HTTPDelimitedJSONTransport : public JSONTransport { static constexpr llvm::StringLiteral kHeaderSeparator = "\r\n\r\n"; }; +/// A transport class for JSON RPC. +class JSONRPCTransport : public JSONTransport { +public: + JSONRPCTransport(lldb::IOObjectSP input, lldb::IOObjectSP output) + : JSONTransport(input, output) {} + virtual ~JSONRPCTransport() = default; + +protected: + virtual llvm::Error WriteImpl(const std::string &message) override; + virtual llvm::Expected + ReadImpl(const std::chrono::microseconds &timeout) override; + + static constexpr llvm::StringLiteral kMessageSeparator = "\n"; +}; + } // namespace lldb_private #endif diff --git a/lldb/source/Host/common/JSONTransport.cpp b/lldb/source/Host/common/JSONTransport.cpp index 103c76d25daf7..7b925372e0b74 100644 --- a/lldb/source/Host/common/JSONTransport.cpp +++ b/lldb/source/Host/common/JSONTransport.cpp @@ -92,7 +92,7 @@ void JSONTransport::Log(llvm::StringRef message) { Expected HTTPDelimitedJSONTransport::ReadImpl(const std::chrono::microseconds &timeout) { if (!m_input || !m_input->IsValid()) -return createStringError("transport output is closed"); +return llvm::make_error(); IOObject *input = m_input.get(); Expected message_header = @@ -142,6 +142,35 @@ Error HTTPDelimitedJSONTransport::WriteImpl(const std::string &message) { return m_output->Write(Output.data(), num_bytes).takeError(); } +Expected +JSONRPCTransport::ReadImpl(const std::chrono::microseconds &timeout) { + if (!m_input || !m_input->IsValid()) +return make_error(); + + IOObject *input = m_input.get(); + Expected raw_json = + ReadUntil(*input, kMessageSeparator, timeout); + if (!raw_json) +return raw_json.takeError(); + + Log(llvm::formatv("--> {0}", *raw_json).str()); + + return *raw_json; +} + +Error JSONRPCTransport::WriteImpl(const std::string &message) { + if (!m_output || !m_output->IsValid()) +return llvm::make_error(); + + Log(llvm::formatv("<-- {0}", message).str()); + + std::string Output; + llvm::raw_string_ostream OS(Output); + OS << message << kMessageSeparator; + size_t num_bytes = Output.size(); + return m_output->Write(Output.data(), num_bytes).takeError(); +} + char TransportEOFError::ID; char TransportTimeoutError::ID; char TransportClosedError::ID; diff --git a/lldb/unittests/DAP/CMakeLists.txt b/lldb/unittests/DAP/CMakeLists.txt index 37a6a81ad12a0..ee623d341ec69 100644 --- a/lldb/unittests/DAP/CMakeLists.txt +++ b/lldb/unittests/DAP/CMakeLists.txt @@ -7,7 +7,6 @@ add_lldb_unittest(DAPTests LLDBUtilsTest.cpp ProtocolTypesTest.cpp TestBase.cpp - TransportTest.cpp VariablesTest.cpp LINK_COMPONENTS diff --git a/lldb/unittests/DAP/TestBase.cpp b/lldb/unittests/DAP/TestBase.cpp index 4063b34250312..27ad42686fbbf 100644 --- a/lldb/unittests/DAP/TestBase.cpp +++ b/lldb/unittests/DAP/TestBase.cpp @@ -28,13 +28,8 @@ using lldb_private::File; using lldb_private::NativeFile; using lldb_private::Pipe; -void PipeBase::SetUp() { - ASSERT_THAT_ERROR(input.CreateNew(false).ToError(), Succeeded()); - ASSERT_THAT_ERROR(output.CreateNew(false).ToError(), Succeeded()); -} - void TransportBase::SetUp() { - PipeBase::SetUp(); + PipeTest::SetUp(); to_dap = std::make_unique( "to_dap", nullptr, std::make_shared(input.GetReadFileDescriptor(), diff --git a/lldb/unittests/DAP/TestBase.h b/lldb/unittests/DAP/TestBase.h index 70b39852
[Lldb-commits] [lldb] [lldb] Add support to list/enable/disable remaining plugin types. (PR #143970)
https://github.com/dmpots updated https://github.com/llvm/llvm-project/pull/143970 >From 10f527ddd5b3defc3e7ceef8c5a00ffba9f77b74 Mon Sep 17 00:00:00 2001 From: David Peixotto Date: Thu, 12 Jun 2025 11:17:53 -0700 Subject: [PATCH 1/3] Use PluginInstances instead of vector for Architecuture plugins This was the only plugin type that was not using the PluginInstance wrapper. It needs to use the PluginInstances to hook into the enable/disable support. --- lldb/source/Core/PluginManager.cpp | 15 --- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp index 5d44434033c55..07bbc332b5d10 100644 --- a/lldb/source/Core/PluginManager.cpp +++ b/lldb/source/Core/PluginManager.cpp @@ -407,7 +407,7 @@ ABICreateInstance PluginManager::GetABICreateCallbackAtIndex(uint32_t idx) { #pragma mark Architecture typedef PluginInstance ArchitectureInstance; -typedef std::vector ArchitectureInstances; +typedef PluginInstances ArchitectureInstances; static ArchitectureInstances &GetArchitectureInstances() { static ArchitectureInstances g_instances; @@ -417,25 +417,18 @@ static ArchitectureInstances &GetArchitectureInstances() { void PluginManager::RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ArchitectureCreateInstance create_callback) { - GetArchitectureInstances().push_back({name, description, create_callback}); + GetArchitectureInstances().RegisterPlugin(name, description, create_callback); } void PluginManager::UnregisterPlugin( ArchitectureCreateInstance create_callback) { auto &instances = GetArchitectureInstances(); - - for (auto pos = instances.begin(), end = instances.end(); pos != end; ++pos) { -if (pos->create_callback == create_callback) { - instances.erase(pos); - return; -} - } - llvm_unreachable("Plugin not found"); + instances.UnregisterPlugin(create_callback); } std::unique_ptr PluginManager::CreateArchitectureInstance(const ArchSpec &arch) { - for (const auto &instances : GetArchitectureInstances()) { + for (const auto &instances : GetArchitectureInstances().GetSnapshot()) { if (auto plugin_up = instances.create_callback(arch)) return plugin_up; } >From 07e945682c32e0946d5fe7017ae8d90152136a87 Mon Sep 17 00:00:00 2001 From: David Peixotto Date: Wed, 11 Jun 2025 21:49:39 -0700 Subject: [PATCH 2/3] [lldb] Add support to list/enable/disable remaining plugin types. In #134418 we added support to list/enable/disable SystemRuntime and InstrumentationRuntime plugins. We limited it to those two plugin types to flesh out the idea with a smaller change. This PR adds support for the remaining plugin types. We now support all the plugins that can be registered directly with the plugin manager. Plugins that are added by loading shared objects are still not supported. --- lldb/include/lldb/Core/PluginManager.h| 108 - lldb/source/Core/PluginManager.cpp| 426 -- lldb/test/API/commands/plugin/TestPlugin.py | 62 +++ .../Shell/Commands/command-plugin-list.test | 4 +- 4 files changed, 560 insertions(+), 40 deletions(-) create mode 100644 lldb/test/API/commands/plugin/TestPlugin.py diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h index e7b169103..1d7c976f3c382 100644 --- a/lldb/include/lldb/Core/PluginManager.h +++ b/lldb/include/lldb/Core/PluginManager.h @@ -236,12 +236,6 @@ class PluginManager { static SystemRuntimeCreateInstance GetSystemRuntimeCreateCallbackAtIndex(uint32_t idx); - static std::vector GetSystemRuntimePluginInfo(); - - // Modify the enabled state of a SystemRuntime plugin. - // Returns false if the plugin name is not found. - static bool SetSystemRuntimePluginEnabled(llvm::StringRef name, bool enabled); - // ObjectFile static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, @@ -549,12 +543,6 @@ class PluginManager { static InstrumentationRuntimeCreateInstance GetInstrumentationRuntimeCreateCallbackAtIndex(uint32_t idx); - static std::vector - GetInstrumentationRuntimePluginInfo(); - - static bool SetInstrumentationRuntimePluginEnabled(llvm::StringRef name, - bool enabled); - // TypeSystem static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, TypeSystemCreateInstance create_callback, @@ -690,6 +678,102 @@ class PluginManager { static bool CreateSettingForCPlusPlusLanguagePlugin( Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, llvm::StringRef description, bool is_global_property); + + // + // Plugin Info+Enable Declarations + // + static std::vector GetABIPluginInfo(); + static bool SetABIPluginEnabled(llvm::StringRef name, bool enable); + +
[Lldb-commits] [lldb] [lldb] Add support to list/enable/disable remaining plugin types. (PR #143970)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: David Peixotto (dmpots) Changes In #134418 we added support to list/enable/disable `SystemRuntime` and `InstrumentationRuntime` plugins. We limited it to those two plugin types to flesh out the idea with a smaller change. This PR adds support for the remaining plugin types. We now support all the plugins that can be registered directly with the plugin manager. Plugins that are added by loading shared objects are still not supported. --- Patch is 27.41 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/143970.diff 4 Files Affected: - (modified) lldb/include/lldb/Core/PluginManager.h (+96-12) - (modified) lldb/source/Core/PluginManager.cpp (+404-37) - (added) lldb/test/API/commands/plugin/TestPlugin.py (+62) - (modified) lldb/test/Shell/Commands/command-plugin-list.test (+2-2) ``diff diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h index e7b169103..1d7c976f3c382 100644 --- a/lldb/include/lldb/Core/PluginManager.h +++ b/lldb/include/lldb/Core/PluginManager.h @@ -236,12 +236,6 @@ class PluginManager { static SystemRuntimeCreateInstance GetSystemRuntimeCreateCallbackAtIndex(uint32_t idx); - static std::vector GetSystemRuntimePluginInfo(); - - // Modify the enabled state of a SystemRuntime plugin. - // Returns false if the plugin name is not found. - static bool SetSystemRuntimePluginEnabled(llvm::StringRef name, bool enabled); - // ObjectFile static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, @@ -549,12 +543,6 @@ class PluginManager { static InstrumentationRuntimeCreateInstance GetInstrumentationRuntimeCreateCallbackAtIndex(uint32_t idx); - static std::vector - GetInstrumentationRuntimePluginInfo(); - - static bool SetInstrumentationRuntimePluginEnabled(llvm::StringRef name, - bool enabled); - // TypeSystem static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, TypeSystemCreateInstance create_callback, @@ -690,6 +678,102 @@ class PluginManager { static bool CreateSettingForCPlusPlusLanguagePlugin( Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, llvm::StringRef description, bool is_global_property); + + // + // Plugin Info+Enable Declarations + // + static std::vector GetABIPluginInfo(); + static bool SetABIPluginEnabled(llvm::StringRef name, bool enable); + + static std::vector GetArchitecturePluginInfo(); + static bool SetArchitecturePluginEnabled(llvm::StringRef name, bool enable); + + static std::vector GetDisassemblerPluginInfo(); + static bool SetDisassemblerPluginEnabled(llvm::StringRef name, bool enable); + + static std::vector GetDynamicLoaderPluginInfo(); + static bool SetDynamicLoaderPluginEnabled(llvm::StringRef name, bool enable); + + static std::vector GetEmulateInstructionPluginInfo(); + static bool SetEmulateInstructionPluginEnabled(llvm::StringRef name, + bool enable); + + static std::vector + GetInstrumentationRuntimePluginInfo(); + static bool SetInstrumentationRuntimePluginEnabled(llvm::StringRef name, + bool enable); + + static std::vector GetJITLoaderPluginInfo(); + static bool SetJITLoaderPluginEnabled(llvm::StringRef name, bool enable); + + static std::vector GetLanguagePluginInfo(); + static bool SetLanguagePluginEnabled(llvm::StringRef name, bool enable); + + static std::vector GetLanguageRuntimePluginInfo(); + static bool SetLanguageRuntimePluginEnabled(llvm::StringRef name, + bool enable); + + static std::vector GetMemoryHistoryPluginInfo(); + static bool SetMemoryHistoryPluginEnabled(llvm::StringRef name, bool enable); + + static std::vector GetObjectContainerPluginInfo(); + static bool SetObjectContainerPluginEnabled(llvm::StringRef name, + bool enable); + + static std::vector GetObjectFilePluginInfo(); + static bool SetObjectFilePluginEnabled(llvm::StringRef name, bool enable); + + static std::vector GetOperatingSystemPluginInfo(); + static bool SetOperatingSystemPluginEnabled(llvm::StringRef name, + bool enable); + + static std::vector GetPlatformPluginInfo(); + static bool SetPlatformPluginEnabled(llvm::StringRef name, bool enable); + + static std::vector GetProcessPluginInfo(); + static bool SetProcessPluginEnabled(llvm::StringRef name, bool enable); + + static std::vector GetREPLPluginInfo(); + static bool SetREPLPluginEnabled(llvm::StringRef name, bool enable); + + static std::vector GetRegisterTypeBuilderPluginInfo(); + static bool SetRegisterTypeBuilderPluginEnabled(llvm::StringRef name, +
[Lldb-commits] [lldb] Reland "[lldb][headers] Create Python script to fix up framework head… (PR #143945)
https://github.com/chelcassanova closed https://github.com/llvm/llvm-project/pull/143945 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Implement JSON RPC (newline delimited) Transport (PR #143946)
ashgti wrote: I tried to see if the existing timeout test was working on the Windows buildbot and its not running due to https://github.com/llvm/llvm-project/blob/main/lldb/unittests/CMakeLists.txt#L50 so the timeout tests may need an `#ifdef !_WIN32` around them maybe. https://github.com/llvm/llvm-project/pull/143946 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Properly handle locate module callback when Target change arch (PR #143793)
https://github.com/GeorgeHuyubo closed https://github.com/llvm/llvm-project/pull/143793 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] b1f5e26 - [lldb] Properly handle locate module callback when Target change arch (#143793)
Author: GeorgeHuyubo Date: 2025-06-12T13:23:26-07:00 New Revision: b1f5e26b78a9550a22ee2f24bb3f220d396c452f URL: https://github.com/llvm/llvm-project/commit/b1f5e26b78a9550a22ee2f24bb3f220d396c452f DIFF: https://github.com/llvm/llvm-project/commit/b1f5e26b78a9550a22ee2f24bb3f220d396c452f.diff LOG: [lldb] Properly handle locate module callback when Target change arch (#143793) Since this PR: https://github.com/llvm/llvm-project/pull/141670/ We started to override the Platform/Arch for a target if needed. However we may have already registered locate module callback with the old platform. This PR will move the locate module callback to the new Platform whenever Target changes architecture. Co-authored-by: George Hu Added: Modified: lldb/source/Target/Target.cpp Removed: diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 9660fc97970b0..45a9e1196a049 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1706,6 +1706,8 @@ bool Target::SetArchitecture(const ArchSpec &arch_spec, bool set_platform, if (PlatformSP arch_platform_sp = GetDebugger().GetPlatformList().GetOrCreate(other, {}, &platform_arch)) { + arch_platform_sp->SetLocateModuleCallback( + platform_sp->GetLocateModuleCallback()); SetPlatform(arch_platform_sp); if (platform_arch.IsValid()) other = platform_arch; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][RPC] Upstream lldb-rpc-gen tool (PR #138031)
chelcassanova wrote: @bulbazord I have a auggestion for this patch. I want to have the minimum CMake necessary to let the tool build. To accomplish this, I want to take out all code in this tool that relates to the server/client code, leaving the code that generates the byproducts. I'd then shift the server code in `lldb-rpc-gen.cpp` to the patch that's already up for the server emitter and the client code for the patch for the client emitters. In effect: - This patch would have all RPCCommon code for lldb-rpc-gen - `lldb-rpc-gen.cpp` will be stripped down to the code that generates the byproducts (namely the class names, method names and skipped methods file) - As mentioned above, the code in lldb-rpc-gen.cpp that relates to generating the server code would move to the patch that's up for the server emitters. - A test could be put up to just check that the byproducts files have been emitted in their expected locations. I'd love to get your thoughts on this. https://github.com/llvm/llvm-project/pull/138031 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add support to list/enable/disable remaining plugin types. (PR #143970)
https://github.com/dmpots created https://github.com/llvm/llvm-project/pull/143970 In #134418 we added support to list/enable/disable `SystemRuntime` and `InstrumentationRuntime` plugins. We limited it to those two plugin types to flesh out the idea with a smaller change. This PR adds support for the remaining plugin types. We now support all the plugins that can be registered directly with the plugin manager. Plugins that are added by loading shared objects are still not supported. >From 10f527ddd5b3defc3e7ceef8c5a00ffba9f77b74 Mon Sep 17 00:00:00 2001 From: David Peixotto Date: Thu, 12 Jun 2025 11:17:53 -0700 Subject: [PATCH 1/2] Use PluginInstances instead of vector for Architecuture plugins This was the only plugin type that was not using the PluginInstance wrapper. It needs to use the PluginInstances to hook into the enable/disable support. --- lldb/source/Core/PluginManager.cpp | 15 --- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp index 5d44434033c55..07bbc332b5d10 100644 --- a/lldb/source/Core/PluginManager.cpp +++ b/lldb/source/Core/PluginManager.cpp @@ -407,7 +407,7 @@ ABICreateInstance PluginManager::GetABICreateCallbackAtIndex(uint32_t idx) { #pragma mark Architecture typedef PluginInstance ArchitectureInstance; -typedef std::vector ArchitectureInstances; +typedef PluginInstances ArchitectureInstances; static ArchitectureInstances &GetArchitectureInstances() { static ArchitectureInstances g_instances; @@ -417,25 +417,18 @@ static ArchitectureInstances &GetArchitectureInstances() { void PluginManager::RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ArchitectureCreateInstance create_callback) { - GetArchitectureInstances().push_back({name, description, create_callback}); + GetArchitectureInstances().RegisterPlugin(name, description, create_callback); } void PluginManager::UnregisterPlugin( ArchitectureCreateInstance create_callback) { auto &instances = GetArchitectureInstances(); - - for (auto pos = instances.begin(), end = instances.end(); pos != end; ++pos) { -if (pos->create_callback == create_callback) { - instances.erase(pos); - return; -} - } - llvm_unreachable("Plugin not found"); + instances.UnregisterPlugin(create_callback); } std::unique_ptr PluginManager::CreateArchitectureInstance(const ArchSpec &arch) { - for (const auto &instances : GetArchitectureInstances()) { + for (const auto &instances : GetArchitectureInstances().GetSnapshot()) { if (auto plugin_up = instances.create_callback(arch)) return plugin_up; } >From 07e945682c32e0946d5fe7017ae8d90152136a87 Mon Sep 17 00:00:00 2001 From: David Peixotto Date: Wed, 11 Jun 2025 21:49:39 -0700 Subject: [PATCH 2/2] [lldb] Add support to list/enable/disable remaining plugin types. In #134418 we added support to list/enable/disable SystemRuntime and InstrumentationRuntime plugins. We limited it to those two plugin types to flesh out the idea with a smaller change. This PR adds support for the remaining plugin types. We now support all the plugins that can be registered directly with the plugin manager. Plugins that are added by loading shared objects are still not supported. --- lldb/include/lldb/Core/PluginManager.h| 108 - lldb/source/Core/PluginManager.cpp| 426 -- lldb/test/API/commands/plugin/TestPlugin.py | 62 +++ .../Shell/Commands/command-plugin-list.test | 4 +- 4 files changed, 560 insertions(+), 40 deletions(-) create mode 100644 lldb/test/API/commands/plugin/TestPlugin.py diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h index e7b169103..1d7c976f3c382 100644 --- a/lldb/include/lldb/Core/PluginManager.h +++ b/lldb/include/lldb/Core/PluginManager.h @@ -236,12 +236,6 @@ class PluginManager { static SystemRuntimeCreateInstance GetSystemRuntimeCreateCallbackAtIndex(uint32_t idx); - static std::vector GetSystemRuntimePluginInfo(); - - // Modify the enabled state of a SystemRuntime plugin. - // Returns false if the plugin name is not found. - static bool SetSystemRuntimePluginEnabled(llvm::StringRef name, bool enabled); - // ObjectFile static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, @@ -549,12 +543,6 @@ class PluginManager { static InstrumentationRuntimeCreateInstance GetInstrumentationRuntimeCreateCallbackAtIndex(uint32_t idx); - static std::vector - GetInstrumentationRuntimePluginInfo(); - - static bool SetInstrumentationRuntimePluginEnabled(llvm::StringRef name, - bool enabled); - // TypeSystem static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, TypeSystemCreateInstance create_callback, @
[Lldb-commits] [lldb] [lldb] Add support to list/enable/disable remaining plugin types. (PR #143970)
@@ -690,6 +678,102 @@ class PluginManager { static bool CreateSettingForCPlusPlusLanguagePlugin( Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, llvm::StringRef description, bool is_global_property); + + // + // Plugin Info+Enable Declarations + // + static std::vector GetABIPluginInfo(); dmpots wrote: I moved all of the declarations to support list/enable/disable to the same location to make it easy to generate the code from a script. I can intersperse these back with their respective plugin locations if desired. The code was generated with https://gist.github.com/dmpots/caca58fbb45b8c0f63b19553c5402611. We talked [previously](https://github.com/llvm/llvm-project/pull/134418#discussion_r2029164327) about doing a dynamic registration. I poked around a bit in the td file, but nothing obvious jumped out without a bit of work and I wasn't sure it was worth the effort. I'm happy to discuss alternatives here about how to do the dynamic registration. https://github.com/llvm/llvm-project/pull/143970 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add support to list/enable/disable remaining plugin types. (PR #143970)
@@ -407,7 +569,7 @@ ABICreateInstance PluginManager::GetABICreateCallbackAtIndex(uint32_t idx) { #pragma mark Architecture typedef PluginInstance ArchitectureInstance; -typedef std::vector ArchitectureInstances; +typedef PluginInstances ArchitectureInstances; dmpots wrote: The `ArchitectureInstance` plugins were the only ones using a vector instead of the `PluginInstances` wrapper. The `PluginInstances` is need to support enable/disable. https://github.com/llvm/llvm-project/pull/143970 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add support to list/enable/disable remaining plugin types. (PR #143970)
@@ -10,10 +10,10 @@ # Test plugin list without an argument will list all plugins. plugin list # CHECK-LABEL: plugin list -# CHECK: system-runtime -# CHECK: [+] systemruntime-macosx System runtime plugin for Mac OS X native libraries # CHECK: instrumentation-runtime # CHECK: [+] AddressSanitizer AddressSanitizer instrumentation runtime plugin. +# CHECK: system-runtime dmpots wrote: This changed because the plugins are now listed alphabetically instead of the order they appear in the source code of PluginManager.h. https://github.com/llvm/llvm-project/pull/143970 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add support to list/enable/disable remaining plugin types. (PR #143970)
https://github.com/dmpots commented: Added a few notes and potential points of discussion. https://github.com/llvm/llvm-project/pull/143970 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 8a8ea8f - Reland "[lldb][headers] Create Python script to fix up framework head… (#143945)
Author: Chelsea Cassanova Date: 2025-06-12T13:55:44-07:00 New Revision: 8a8ea8fec063bd64c17e463e7c3eaae5cdb4a645 URL: https://github.com/llvm/llvm-project/commit/8a8ea8fec063bd64c17e463e7c3eaae5cdb4a645 DIFF: https://github.com/llvm/llvm-project/commit/8a8ea8fec063bd64c17e463e7c3eaae5cdb4a645.diff LOG: Reland "[lldb][headers] Create Python script to fix up framework head… (#143945) …ers" (#143941) Reland the script that converts lldb headers to RPC headers. The RPC test was failing due to the incorrect input filepath being used. Original commit message: This commit replaces the shell script that fixes up includes for the LLDB framework with a Python script. This script will also be used when fixing up includes for the LLDBRPC.framework. Added: lldb/scripts/framework-header-fix.py lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h lldb/test/Shell/Scripts/Inputs/RPC/RPCSBAddress.h lldb/test/Shell/Scripts/TestFrameworkFixScript.test lldb/test/Shell/Scripts/TestFrameworkFixUnifdef.test lldb/test/Shell/Scripts/TestRPCFrameworkFixScript.test Modified: lldb/cmake/modules/LLDBFramework.cmake Removed: diff --git a/lldb/cmake/modules/LLDBFramework.cmake b/lldb/cmake/modules/LLDBFramework.cmake index 8961b1afe93ad..70010ffbf738c 100644 --- a/lldb/cmake/modules/LLDBFramework.cmake +++ b/lldb/cmake/modules/LLDBFramework.cmake @@ -68,24 +68,17 @@ if(NOT APPLE_EMBEDDED) ) endif() -# At configuration time, collect headers for the framework bundle and copy them -# into a staging directory. Later we can copy over the entire folder. -file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h) -set(generated_public_headers ${LLDB_OBJ_DIR}/include/lldb/API/SBLanguages.h) -file(GLOB root_public_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-*.h) -file(GLOB root_private_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h) -list(REMOVE_ITEM root_public_headers ${root_private_headers}) - find_program(unifdef_EXECUTABLE unifdef) -set(lldb_header_staging ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders) -foreach(header -${public_headers} -${generated_public_headers} -${root_public_headers}) +# All necessary header files will be staged in the include directory in the build directory, +# so just copy the files from there into the framework's staging directory. +set(lldb_build_dir_header_staging "${CMAKE_BINARY_DIR}/include/lldb") +set(lldb_framework_header_staging "${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders") +file(GLOB lldb_build_dir_header_staging_list ${lldb_build_dir_header_staging}/*) +foreach(header ${lldb_build_dir_header_staging_list}) get_filename_component(basename ${header} NAME) - set(staged_header ${lldb_header_staging}/${basename}) + set(staged_header ${lldb_framework_header_staging}/${basename}) if(unifdef_EXECUTABLE) # unifdef returns 0 when the file is unchanged and 1 if something was changed. @@ -112,13 +105,20 @@ set_target_properties(liblldb-resource-headers PROPERTIES FOLDER "LLDB/Resources add_dependencies(liblldb-resource-headers liblldb-header-staging) add_dependencies(liblldb liblldb-resource-headers) -# At build time, copy the staged headers into the framework bundle (and do -# some post-processing in-place). -add_custom_command(TARGET liblldb POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory ${lldb_header_staging} $/Headers - COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.sh $/Headers ${LLDB_VERSION} - COMMENT "LLDB.framework: copy framework headers" -) +# Take the headers from the staging directory and fix up their includes for the framework. +# Then write them to the output directory. +# Also, run unifdef to remove any specified guards from the header files. +file(GLOB lldb_framework_header_staging_list ${lldb_framework_header_staging}/*) +foreach(header ${lldb_framework_header_staging_list}) + + set(input_header ${header}) + set(output_header $/Headers/${input_header}) + + add_custom_command(TARGET liblldb POST_BUILD +COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.py -f lldb_main -i ${input_header} -o ${output_header} -p ${unifdef_EXECUTABLE} USWIG +COMMENT "LLDB.framework: Fix up and copy framework headers" + ) +endforeach() # Copy vendor-specific headers from clang (without staging). if(NOT APPLE_EMBEDDED) diff --git a/lldb/scripts/framework-header-fix.py b/lldb/scripts/framework-header-fix.py new file mode 100755 index 0..9528fdb7e30bd --- /dev/null +++ b/lldb/scripts/framework-header-fix.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python3 + +""" +Usage: + +This script is used when building LLDB.framework or LLDBRPC.framework. For each framework, local includes are converted to their respective framework includes. + +This script is used in 2 ways: +1. It is used on header files that are copied into LLDB.framework. For these files, local LLDB includes are converte
[Lldb-commits] [lldb] [lldb] Add support to list/enable/disable remaining plugin types. (PR #143970)
https://github.com/dmpots edited https://github.com/llvm/llvm-project/pull/143970 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add MCP support to LLDB (PoC) (PR #143628)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/143628 >From ecc6e9e88e2f5786e7ebd0a454567cd933e60b7f Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 12 Jun 2025 16:33:55 -0700 Subject: [PATCH] [lldb] Add MCP support to LLDB https://discourse.llvm.org/t/rfc-adding-mcp-support-to-lldb/86798 --- lldb/include/lldb/Core/Debugger.h | 6 + lldb/include/lldb/Core/PluginManager.h| 9 + lldb/include/lldb/Core/ProtocolServer.h | 37 +++ .../Interpreter/CommandOptionArgumentTable.h | 1 + lldb/include/lldb/lldb-enumerations.h | 1 + lldb/include/lldb/lldb-forward.h | 3 +- lldb/include/lldb/lldb-private-interfaces.h | 2 + lldb/source/Commands/CMakeLists.txt | 1 + .../Commands/CommandObjectProtocolServer.cpp | 145 + .../Commands/CommandObjectProtocolServer.h| 25 ++ lldb/source/Core/CMakeLists.txt | 1 + lldb/source/Core/Debugger.cpp | 24 ++ lldb/source/Core/PluginManager.cpp| 27 ++ lldb/source/Core/ProtocolServer.cpp | 21 ++ .../source/Interpreter/CommandInterpreter.cpp | 2 + lldb/source/Plugins/CMakeLists.txt| 1 + lldb/source/Plugins/Protocol/CMakeLists.txt | 1 + .../Plugins/Protocol/MCP/CMakeLists.txt | 13 + lldb/source/Plugins/Protocol/MCP/MCPError.cpp | 31 ++ lldb/source/Plugins/Protocol/MCP/MCPError.h | 33 +++ lldb/source/Plugins/Protocol/MCP/Protocol.cpp | 180 +++ lldb/source/Plugins/Protocol/MCP/Protocol.h | 131 .../Protocol/MCP/ProtocolServerMCP.cpp| 280 ++ .../Plugins/Protocol/MCP/ProtocolServerMCP.h | 77 + lldb/source/Plugins/Protocol/MCP/Tool.cpp | 72 + lldb/source/Plugins/Protocol/MCP/Tool.h | 61 26 files changed, 1184 insertions(+), 1 deletion(-) create mode 100644 lldb/include/lldb/Core/ProtocolServer.h create mode 100644 lldb/source/Commands/CommandObjectProtocolServer.cpp create mode 100644 lldb/source/Commands/CommandObjectProtocolServer.h create mode 100644 lldb/source/Core/ProtocolServer.cpp create mode 100644 lldb/source/Plugins/Protocol/CMakeLists.txt create mode 100644 lldb/source/Plugins/Protocol/MCP/CMakeLists.txt create mode 100644 lldb/source/Plugins/Protocol/MCP/MCPError.cpp create mode 100644 lldb/source/Plugins/Protocol/MCP/MCPError.h create mode 100644 lldb/source/Plugins/Protocol/MCP/Protocol.cpp create mode 100644 lldb/source/Plugins/Protocol/MCP/Protocol.h create mode 100644 lldb/source/Plugins/Protocol/MCP/ProtocolServerMCP.cpp create mode 100644 lldb/source/Plugins/Protocol/MCP/ProtocolServerMCP.h create mode 100644 lldb/source/Plugins/Protocol/MCP/Tool.cpp create mode 100644 lldb/source/Plugins/Protocol/MCP/Tool.h diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h index d73aba1e3ce58..0f6659d1a0bf7 100644 --- a/lldb/include/lldb/Core/Debugger.h +++ b/lldb/include/lldb/Core/Debugger.h @@ -598,6 +598,10 @@ class Debugger : public std::enable_shared_from_this, void FlushProcessOutput(Process &process, bool flush_stdout, bool flush_stderr); + void AddProtocolServer(lldb::ProtocolServerSP protocol_server_sp); + void RemoveProtocolServer(lldb::ProtocolServerSP protocol_server_sp); + lldb::ProtocolServerSP GetProtocolServer(llvm::StringRef protocol) const; + SourceManager::SourceFileCache &GetSourceFileCache() { return m_source_file_cache; } @@ -768,6 +772,8 @@ class Debugger : public std::enable_shared_from_this, mutable std::mutex m_progress_reports_mutex; /// @} + llvm::SmallVector m_protocol_servers; + std::mutex m_destroy_callback_mutex; lldb::callback_token_t m_destroy_callback_next_token = 0; struct DestroyCallbackInfo { diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h index e7b169103..967af598c40ff 100644 --- a/lldb/include/lldb/Core/PluginManager.h +++ b/lldb/include/lldb/Core/PluginManager.h @@ -327,6 +327,15 @@ class PluginManager { static void AutoCompleteProcessName(llvm::StringRef partial_name, CompletionRequest &request); + // Protocol + static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, + ProtocolServerCreateInstance create_callback); + + static bool UnregisterPlugin(ProtocolServerCreateInstance create_callback); + + static ProtocolServerCreateInstance + GetProtocolCreateCallbackForPluginName(llvm::StringRef name); + // Register Type Provider static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, RegisterTypeBuilderCreateInstance create_callback); diff --git a/lldb/include/lldb/Core/ProtocolServer.h b/lldb/include/lldb/Core/ProtocolServer.h new file mode 100644 index 0..ca0210a0bbe72 --- /dev/null +++ b/lldb/include/lldb/Core/Pr
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF ParseSymtab handling (PR #141577)
DhruvSrivastavaX wrote: Got it @labath, I have added the updates accordingly. Hope this is good enough. 🙂 > The code is fine, but you should really add a test for it. You don't need to > wait for lldb-test to grow symtab support. You can write a test that does > something like: > > ``` > # RUN: yaml2obj %s > %t > # RUN: %lldb %t -o "image dump symtab" -o exit | FileCheck %s > # CHECK: symtab contents > ``` > > If you grep for "image dump symtab", you can find some existing tests to > emulate. > > I also feel I need to say something about comments. The most useful kind of > comment is the one that answers the "why" question. Most of your comments try > to answer the "what". Ideally the code should be clear enough that I can tell > _what_ it is doing without reading the comment. The part that's often not > obvious is **why** is it doing that. > > Taking this as an example: > > ``` > // Remove the dot prefix from symbol names before adding to symtab. > '.text' > // -> 'text' > ``` > > The comment is not bad, but it's not that helpful as I can deduce that from > the code. When reading this, the questions I have are: > > * why are we doing that? > * who adds the "." and why? > * what would happen if we didn't do that? > * etc. > > This isn't a hard requirement for the patch, but please keep this in mind. https://github.com/llvm/llvm-project/pull/141577 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF ParseSymtab handling (PR #141577)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/141577 >From a62cd7b510f3cf74ee356a95a26e0f9922f4b39c Mon Sep 17 00:00:00 2001 From: DhruvSrivastavaX Date: Tue, 27 May 2025 05:44:55 -0500 Subject: [PATCH 1/5] Added XCOFF ParseSymtab handling --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 66 ++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index e629355cd40b9..7dfe6c362add4 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -188,7 +188,71 @@ AddressClass ObjectFileXCOFF::GetAddressClass(addr_t file_addr) { return AddressClass::eUnknown; } -void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) {} +lldb::SymbolType MapSymbolType(llvm::object::SymbolRef::Type sym_type) { + if (sym_type == llvm::object::SymbolRef::ST_Function) +return lldb::eSymbolTypeCode; + else if (sym_type == llvm::object::SymbolRef::ST_Data) +return lldb::eSymbolTypeData; + else if (sym_type == llvm::object::SymbolRef::ST_File) +return lldb::eSymbolTypeSourceFile; + return lldb::eSymbolTypeInvalid; +} + +void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) { + SectionList *sectionList = GetSectionList(); + + for (const auto &symbol_ref : m_binary->symbols()) { +llvm::object::XCOFFSymbolRef xcoff_sym_ref(symbol_ref); +llvm::Expected name_or_err = xcoff_sym_ref.getName(); +if (!name_or_err) { + consumeError(name_or_err.takeError()); + continue; +} +llvm::StringRef symbolName = name_or_err.get(); +// Remove the dot prefix for demangle +llvm::StringRef symbol_name = +symbolName.starts_with(".") ? symbolName.drop_front() : symbolName; +auto storageClass = xcoff_sym_ref.getStorageClass(); +if (storageClass == XCOFF::C_HIDEXT && symbolName != "TOC") { + if (xcoff_sym_ref.getNumberOfAuxEntries() != 1) +continue; + auto aux_csect_or_err = xcoff_sym_ref.getXCOFFCsectAuxRef(); + if (!aux_csect_or_err) { +consumeError(aux_csect_or_err.takeError()); +continue; + } + const llvm::object::XCOFFCsectAuxRef csect_aux = aux_csect_or_err.get(); + if (csect_aux.getStorageMappingClass() != XCOFF::XMC_PR || + (m_binary->is64Bit() ? (csect_aux.getAuxType64() != XCOFF::AUX_CSECT) + : false)) +continue; +} + +Symbol symbol; +symbol.GetMangled().SetValue(ConstString(symbol_name)); + +int16_t sectionNumber = xcoff_sym_ref.getSectionNumber(); +size_t sectionIndex = static_cast(sectionNumber - 1); +if (sectionNumber > 0 && sectionIndex < sectionList->GetSize()) { + lldb::SectionSP section_sp = + sectionList->GetSectionAtIndex(sectionNumber - 1); + if (!section_sp || section_sp->GetFileAddress() == LLDB_INVALID_ADDRESS) +continue; + lldb::addr_t file_addr = section_sp->GetFileAddress(); + lldb::addr_t symbolValue = xcoff_sym_ref.getValue(); + if (symbolValue < file_addr) +continue; + symbol.GetAddressRef() = Address(section_sp, symbolValue - file_addr); +} + +Expected sym_type_or_err = +symbol_ref.getType(); +symbol.SetType(MapSymbolType(sym_type_or_err.get())); +printf("%s %d\n", symbol.GetName(), *sym_type_or_err); + +lldb_symtab.AddSymbol(symbol); + } +} bool ObjectFileXCOFF::IsStripped() { return false; } >From 21f5a39976457589e2ab9666820c08331aaf4542 Mon Sep 17 00:00:00 2001 From: Dhruv Srivastava Date: Tue, 27 May 2025 16:33:08 +0530 Subject: [PATCH 2/5] cleanup --- lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index 7dfe6c362add4..1e84b86cd6f0a 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -247,8 +247,11 @@ void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) { Expected sym_type_or_err = symbol_ref.getType(); +if (!sym_type_or_err) { + consumeError(sym_type_or_err.takeError()); + continue; +} symbol.SetType(MapSymbolType(sym_type_or_err.get())); -printf("%s %d\n", symbol.GetName(), *sym_type_or_err); lldb_symtab.AddSymbol(symbol); } >From 4d631899cd3ab96ea3819e1ece3ce2851d1f9f6c Mon Sep 17 00:00:00 2001 From: DhruvSrivastavaX Date: Thu, 29 May 2025 07:37:23 -0500 Subject: [PATCH 3/5] Addressed comments --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 27 --- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCO
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF ParseSymtab handling (PR #141577)
DhruvSrivastavaX wrote: Please ignore the above unrelated push logs. It got messed up due to some issues with our team's default branch last week. https://github.com/llvm/llvm-project/pull/141577 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF ParseSymtab handling (PR #141577)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/141577 >From a62cd7b510f3cf74ee356a95a26e0f9922f4b39c Mon Sep 17 00:00:00 2001 From: DhruvSrivastavaX Date: Tue, 27 May 2025 05:44:55 -0500 Subject: [PATCH 1/3] Added XCOFF ParseSymtab handling --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 66 ++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index e629355cd40b9..7dfe6c362add4 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -188,7 +188,71 @@ AddressClass ObjectFileXCOFF::GetAddressClass(addr_t file_addr) { return AddressClass::eUnknown; } -void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) {} +lldb::SymbolType MapSymbolType(llvm::object::SymbolRef::Type sym_type) { + if (sym_type == llvm::object::SymbolRef::ST_Function) +return lldb::eSymbolTypeCode; + else if (sym_type == llvm::object::SymbolRef::ST_Data) +return lldb::eSymbolTypeData; + else if (sym_type == llvm::object::SymbolRef::ST_File) +return lldb::eSymbolTypeSourceFile; + return lldb::eSymbolTypeInvalid; +} + +void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) { + SectionList *sectionList = GetSectionList(); + + for (const auto &symbol_ref : m_binary->symbols()) { +llvm::object::XCOFFSymbolRef xcoff_sym_ref(symbol_ref); +llvm::Expected name_or_err = xcoff_sym_ref.getName(); +if (!name_or_err) { + consumeError(name_or_err.takeError()); + continue; +} +llvm::StringRef symbolName = name_or_err.get(); +// Remove the dot prefix for demangle +llvm::StringRef symbol_name = +symbolName.starts_with(".") ? symbolName.drop_front() : symbolName; +auto storageClass = xcoff_sym_ref.getStorageClass(); +if (storageClass == XCOFF::C_HIDEXT && symbolName != "TOC") { + if (xcoff_sym_ref.getNumberOfAuxEntries() != 1) +continue; + auto aux_csect_or_err = xcoff_sym_ref.getXCOFFCsectAuxRef(); + if (!aux_csect_or_err) { +consumeError(aux_csect_or_err.takeError()); +continue; + } + const llvm::object::XCOFFCsectAuxRef csect_aux = aux_csect_or_err.get(); + if (csect_aux.getStorageMappingClass() != XCOFF::XMC_PR || + (m_binary->is64Bit() ? (csect_aux.getAuxType64() != XCOFF::AUX_CSECT) + : false)) +continue; +} + +Symbol symbol; +symbol.GetMangled().SetValue(ConstString(symbol_name)); + +int16_t sectionNumber = xcoff_sym_ref.getSectionNumber(); +size_t sectionIndex = static_cast(sectionNumber - 1); +if (sectionNumber > 0 && sectionIndex < sectionList->GetSize()) { + lldb::SectionSP section_sp = + sectionList->GetSectionAtIndex(sectionNumber - 1); + if (!section_sp || section_sp->GetFileAddress() == LLDB_INVALID_ADDRESS) +continue; + lldb::addr_t file_addr = section_sp->GetFileAddress(); + lldb::addr_t symbolValue = xcoff_sym_ref.getValue(); + if (symbolValue < file_addr) +continue; + symbol.GetAddressRef() = Address(section_sp, symbolValue - file_addr); +} + +Expected sym_type_or_err = +symbol_ref.getType(); +symbol.SetType(MapSymbolType(sym_type_or_err.get())); +printf("%s %d\n", symbol.GetName(), *sym_type_or_err); + +lldb_symtab.AddSymbol(symbol); + } +} bool ObjectFileXCOFF::IsStripped() { return false; } >From 21f5a39976457589e2ab9666820c08331aaf4542 Mon Sep 17 00:00:00 2001 From: Dhruv Srivastava Date: Tue, 27 May 2025 16:33:08 +0530 Subject: [PATCH 2/3] cleanup --- lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index 7dfe6c362add4..1e84b86cd6f0a 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -247,8 +247,11 @@ void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) { Expected sym_type_or_err = symbol_ref.getType(); +if (!sym_type_or_err) { + consumeError(sym_type_or_err.takeError()); + continue; +} symbol.SetType(MapSymbolType(sym_type_or_err.get())); -printf("%s %d\n", symbol.GetName(), *sym_type_or_err); lldb_symtab.AddSymbol(symbol); } >From 4d631899cd3ab96ea3819e1ece3ce2851d1f9f6c Mon Sep 17 00:00:00 2001 From: DhruvSrivastavaX Date: Thu, 29 May 2025 07:37:23 -0500 Subject: [PATCH 3/3] Addressed comments --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 27 --- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCO
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF ParseSymtab handling (PR #141577)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/141577 >From a62cd7b510f3cf74ee356a95a26e0f9922f4b39c Mon Sep 17 00:00:00 2001 From: DhruvSrivastavaX Date: Tue, 27 May 2025 05:44:55 -0500 Subject: [PATCH 1/3] Added XCOFF ParseSymtab handling --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 66 ++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index e629355cd40b9..7dfe6c362add4 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -188,7 +188,71 @@ AddressClass ObjectFileXCOFF::GetAddressClass(addr_t file_addr) { return AddressClass::eUnknown; } -void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) {} +lldb::SymbolType MapSymbolType(llvm::object::SymbolRef::Type sym_type) { + if (sym_type == llvm::object::SymbolRef::ST_Function) +return lldb::eSymbolTypeCode; + else if (sym_type == llvm::object::SymbolRef::ST_Data) +return lldb::eSymbolTypeData; + else if (sym_type == llvm::object::SymbolRef::ST_File) +return lldb::eSymbolTypeSourceFile; + return lldb::eSymbolTypeInvalid; +} + +void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) { + SectionList *sectionList = GetSectionList(); + + for (const auto &symbol_ref : m_binary->symbols()) { +llvm::object::XCOFFSymbolRef xcoff_sym_ref(symbol_ref); +llvm::Expected name_or_err = xcoff_sym_ref.getName(); +if (!name_or_err) { + consumeError(name_or_err.takeError()); + continue; +} +llvm::StringRef symbolName = name_or_err.get(); +// Remove the dot prefix for demangle +llvm::StringRef symbol_name = +symbolName.starts_with(".") ? symbolName.drop_front() : symbolName; +auto storageClass = xcoff_sym_ref.getStorageClass(); +if (storageClass == XCOFF::C_HIDEXT && symbolName != "TOC") { + if (xcoff_sym_ref.getNumberOfAuxEntries() != 1) +continue; + auto aux_csect_or_err = xcoff_sym_ref.getXCOFFCsectAuxRef(); + if (!aux_csect_or_err) { +consumeError(aux_csect_or_err.takeError()); +continue; + } + const llvm::object::XCOFFCsectAuxRef csect_aux = aux_csect_or_err.get(); + if (csect_aux.getStorageMappingClass() != XCOFF::XMC_PR || + (m_binary->is64Bit() ? (csect_aux.getAuxType64() != XCOFF::AUX_CSECT) + : false)) +continue; +} + +Symbol symbol; +symbol.GetMangled().SetValue(ConstString(symbol_name)); + +int16_t sectionNumber = xcoff_sym_ref.getSectionNumber(); +size_t sectionIndex = static_cast(sectionNumber - 1); +if (sectionNumber > 0 && sectionIndex < sectionList->GetSize()) { + lldb::SectionSP section_sp = + sectionList->GetSectionAtIndex(sectionNumber - 1); + if (!section_sp || section_sp->GetFileAddress() == LLDB_INVALID_ADDRESS) +continue; + lldb::addr_t file_addr = section_sp->GetFileAddress(); + lldb::addr_t symbolValue = xcoff_sym_ref.getValue(); + if (symbolValue < file_addr) +continue; + symbol.GetAddressRef() = Address(section_sp, symbolValue - file_addr); +} + +Expected sym_type_or_err = +symbol_ref.getType(); +symbol.SetType(MapSymbolType(sym_type_or_err.get())); +printf("%s %d\n", symbol.GetName(), *sym_type_or_err); + +lldb_symtab.AddSymbol(symbol); + } +} bool ObjectFileXCOFF::IsStripped() { return false; } >From 21f5a39976457589e2ab9666820c08331aaf4542 Mon Sep 17 00:00:00 2001 From: Dhruv Srivastava Date: Tue, 27 May 2025 16:33:08 +0530 Subject: [PATCH 2/3] cleanup --- lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index 7dfe6c362add4..1e84b86cd6f0a 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -247,8 +247,11 @@ void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) { Expected sym_type_or_err = symbol_ref.getType(); +if (!sym_type_or_err) { + consumeError(sym_type_or_err.takeError()); + continue; +} symbol.SetType(MapSymbolType(sym_type_or_err.get())); -printf("%s %d\n", symbol.GetName(), *sym_type_or_err); lldb_symtab.AddSymbol(symbol); } >From 4d631899cd3ab96ea3819e1ece3ce2851d1f9f6c Mon Sep 17 00:00:00 2001 From: DhruvSrivastavaX Date: Thu, 29 May 2025 07:37:23 -0500 Subject: [PATCH 3/3] Addressed comments --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 27 --- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCO
[Lldb-commits] [lldb] [lldb][AIX] Added XCOFF ParseSymtab handling (PR #141577)
https://github.com/DhruvSrivastavaX updated https://github.com/llvm/llvm-project/pull/141577 >From a62cd7b510f3cf74ee356a95a26e0f9922f4b39c Mon Sep 17 00:00:00 2001 From: DhruvSrivastavaX Date: Tue, 27 May 2025 05:44:55 -0500 Subject: [PATCH 1/4] Added XCOFF ParseSymtab handling --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 66 ++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index e629355cd40b9..7dfe6c362add4 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -188,7 +188,71 @@ AddressClass ObjectFileXCOFF::GetAddressClass(addr_t file_addr) { return AddressClass::eUnknown; } -void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) {} +lldb::SymbolType MapSymbolType(llvm::object::SymbolRef::Type sym_type) { + if (sym_type == llvm::object::SymbolRef::ST_Function) +return lldb::eSymbolTypeCode; + else if (sym_type == llvm::object::SymbolRef::ST_Data) +return lldb::eSymbolTypeData; + else if (sym_type == llvm::object::SymbolRef::ST_File) +return lldb::eSymbolTypeSourceFile; + return lldb::eSymbolTypeInvalid; +} + +void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) { + SectionList *sectionList = GetSectionList(); + + for (const auto &symbol_ref : m_binary->symbols()) { +llvm::object::XCOFFSymbolRef xcoff_sym_ref(symbol_ref); +llvm::Expected name_or_err = xcoff_sym_ref.getName(); +if (!name_or_err) { + consumeError(name_or_err.takeError()); + continue; +} +llvm::StringRef symbolName = name_or_err.get(); +// Remove the dot prefix for demangle +llvm::StringRef symbol_name = +symbolName.starts_with(".") ? symbolName.drop_front() : symbolName; +auto storageClass = xcoff_sym_ref.getStorageClass(); +if (storageClass == XCOFF::C_HIDEXT && symbolName != "TOC") { + if (xcoff_sym_ref.getNumberOfAuxEntries() != 1) +continue; + auto aux_csect_or_err = xcoff_sym_ref.getXCOFFCsectAuxRef(); + if (!aux_csect_or_err) { +consumeError(aux_csect_or_err.takeError()); +continue; + } + const llvm::object::XCOFFCsectAuxRef csect_aux = aux_csect_or_err.get(); + if (csect_aux.getStorageMappingClass() != XCOFF::XMC_PR || + (m_binary->is64Bit() ? (csect_aux.getAuxType64() != XCOFF::AUX_CSECT) + : false)) +continue; +} + +Symbol symbol; +symbol.GetMangled().SetValue(ConstString(symbol_name)); + +int16_t sectionNumber = xcoff_sym_ref.getSectionNumber(); +size_t sectionIndex = static_cast(sectionNumber - 1); +if (sectionNumber > 0 && sectionIndex < sectionList->GetSize()) { + lldb::SectionSP section_sp = + sectionList->GetSectionAtIndex(sectionNumber - 1); + if (!section_sp || section_sp->GetFileAddress() == LLDB_INVALID_ADDRESS) +continue; + lldb::addr_t file_addr = section_sp->GetFileAddress(); + lldb::addr_t symbolValue = xcoff_sym_ref.getValue(); + if (symbolValue < file_addr) +continue; + symbol.GetAddressRef() = Address(section_sp, symbolValue - file_addr); +} + +Expected sym_type_or_err = +symbol_ref.getType(); +symbol.SetType(MapSymbolType(sym_type_or_err.get())); +printf("%s %d\n", symbol.GetName(), *sym_type_or_err); + +lldb_symtab.AddSymbol(symbol); + } +} bool ObjectFileXCOFF::IsStripped() { return false; } >From 21f5a39976457589e2ab9666820c08331aaf4542 Mon Sep 17 00:00:00 2001 From: Dhruv Srivastava Date: Tue, 27 May 2025 16:33:08 +0530 Subject: [PATCH 2/4] cleanup --- lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index 7dfe6c362add4..1e84b86cd6f0a 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -247,8 +247,11 @@ void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) { Expected sym_type_or_err = symbol_ref.getType(); +if (!sym_type_or_err) { + consumeError(sym_type_or_err.takeError()); + continue; +} symbol.SetType(MapSymbolType(sym_type_or_err.get())); -printf("%s %d\n", symbol.GetName(), *sym_type_or_err); lldb_symtab.AddSymbol(symbol); } >From 4d631899cd3ab96ea3819e1ece3ce2851d1f9f6c Mon Sep 17 00:00:00 2001 From: DhruvSrivastavaX Date: Thu, 29 May 2025 07:37:23 -0500 Subject: [PATCH 3/4] Addressed comments --- .../ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 27 --- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCO
[Lldb-commits] [lldb] [LLDB] Add bit extraction to DIL (PR #141422)
kuilpd wrote: @labath @jimingham Just to clarify, do we change `-` to `:` now in this PR or later, after we replace `frame var` with DIL? https://github.com/llvm/llvm-project/pull/141422 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add bit extraction to DIL (PR #141422)
@@ -62,7 +62,7 @@ def test_subscript(self): self.expect( "frame var 'int_arr[-1]'", error=True, -substrs=["unrecognized token"], +substrs=["failed to parse integer constant"], kuilpd wrote: Should I make a separate PR to fix this? https://github.com/llvm/llvm-project/pull/141422 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [Clang][PowerPC] Add __dmr type and DMF integer calculation builtins (PR #142480)
https://github.com/lei137 edited https://github.com/llvm/llvm-project/pull/142480 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [Clang][PowerPC] Add __dmr type and DMF integer calculation builtins (PR #142480)
@@ -30,6 +30,7 @@ #endif +PPC_VECTOR_MMA_TYPE(__dmr1024, VectorDmr1024, 1024) lei137 wrote: Since this is a vector type, maybe we can just keep the same naming convention? ```suggestion PPC_VECTOR_MMA_TYPE(__vector_dmr, VectorDmr, 1024) ``` https://github.com/llvm/llvm-project/pull/142480 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [Clang][PowerPC] Add __dmr type and DMF integer calculation builtins (PR #142480)
@@ -0,0 +1,20 @@ +// RUN: not %clang_cc1 -triple powerpc64le-unknown-linux-gnu -target-cpu future \ lei137 wrote: nit: better not to have "future" in the test case names as "future" is a sliding thing? https://github.com/llvm/llvm-project/pull/142480 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [Clang][PowerPC] Add __dmr type and DMF integer calculation builtins (PR #142480)
@@ -0,0 +1,94 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py lei137 wrote: I might be missing something, what does `mmaplus` imply here? Since this tests mma builtins that uses the dmr registers, maybe `builtins-ppc-mma-dmr.c`? https://github.com/llvm/llvm-project/pull/142480 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [Clang][PowerPC] Add __dmr type and DMF integer calculation builtins (PR #142480)
@@ -0,0 +1,184 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py lei137 wrote: nit: maybe this tests can be renamed to `dmf-types.c`? https://github.com/llvm/llvm-project/pull/142480 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Commands] Fix memory find for Swift expressions (PR #143860)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) Changes (depends on https://github.com/llvm/llvm-project/pull/143686) There were two issues previously preventing `memory find -e` expressions to succeed when stopped in Swift frames: 1. We weren't getting the dynamic type of the result `ValueObject`. For Swift this would fail when we tried to produce a scalar value out of it because the static VO wasn't sufficient to get to the integer value. Hence we add a call to `GetQualifiedRepresentationIfAvailable` (which is what we do for expressions in `OptionArgParser::ToAddress` too). 2. We weren't passing an `ExecutionContextScope` to `GetByteSize`, which Swift relied on to get the size of the result type. My plan is to add an API test for this on the Apple `swiftlang/llvm-project` fork. I considered an alternative where we use `OptionArgParser::ToAddress` for `memory find -e` expressions, but it got a bit icky when trying to figure out how many bytes we should copy out of the result into the `DataBufferHeap` (currently we rely on the size of the result variable type). This gets even trickier when we were to pass an expression that was actually a hex digit or a number into `ToAddress`. rdar://152113525 --- Full diff: https://github.com/llvm/llvm-project/pull/143860.diff 3 Files Affected: - (modified) lldb/source/Commands/CommandObjectMemory.cpp (+68-43) - (modified) lldb/test/API/functionalities/memory/find/TestMemoryFind.py (+31) - (modified) lldb/test/API/functionalities/memory/find/main.cpp (+15) ``diff diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 7140333bb3cde..be9ce5e5a3b6e 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -885,6 +885,61 @@ class CommandObjectMemoryRead : public CommandObjectParsed { #define LLDB_OPTIONS_memory_find #include "CommandOptions.inc" +static llvm::Error CopyExpressionResult(ValueObject &result, +DataBufferHeap &buffer, +ExecutionContextScope *scope) { + uint64_t value = result.GetValueAsUnsigned(0); + auto size_or_err = result.GetCompilerType().GetByteSize(scope); + if (!size_or_err) +return size_or_err.takeError(); + + switch (*size_or_err) { + case 1: { +uint8_t byte = (uint8_t)value; +buffer.CopyData(&byte, 1); + } break; + case 2: { +uint16_t word = (uint16_t)value; +buffer.CopyData(&word, 2); + } break; + case 4: { +uint32_t lword = (uint32_t)value; +buffer.CopyData(&lword, 4); + } break; + case 8: { +buffer.CopyData(&value, 8); + } break; + case 3: + case 5: + case 6: + case 7: +return llvm::createStringError("unknown type. pass a string instead"); + default: +return llvm::createStringError( +"result size larger than 8 bytes. pass a string instead"); + } + + return llvm::Error::success(); +} + +static llvm::Expected +EvaluateExpression(llvm::StringRef expression, StackFrame &frame, + Process &process) { + ValueObjectSP result_sp; + auto status = + process.GetTarget().EvaluateExpression(expression, &frame, result_sp); + if (status != eExpressionCompleted || !result_sp) +return llvm::createStringError( +"expression evaluation failed. pass a string instead"); + + result_sp = result_sp->GetQualifiedRepresentationIfAvailable( + result_sp->GetDynamicValueType(), /*synthValue=*/true); + if (!result_sp) +return llvm::createStringError("failed to unwrap expression result type"); + + return result_sp; +} + // Find the specified data in memory class CommandObjectMemoryFind : public CommandObjectParsed { public: @@ -1026,49 +1081,19 @@ class CommandObjectMemoryFind : public CommandObjectParsed { } buffer.CopyData(str); } else if (m_memory_options.m_expr.OptionWasSet()) { - StackFrame *frame = m_exe_ctx.GetFramePtr(); - ValueObjectSP result_sp; - if ((eExpressionCompleted == - process->GetTarget().EvaluateExpression( - m_memory_options.m_expr.GetValueAs().value_or( - ""), - frame, result_sp)) && - result_sp) { -uint64_t value = result_sp->GetValueAsUnsigned(0); -std::optional size = llvm::expectedToOptional( -result_sp->GetCompilerType().GetByteSize(nullptr)); -if (!size) - return; -switch (*size) { -case 1: { - uint8_t byte = (uint8_t)value; - buffer.CopyData(&byte, 1); -} break; -case 2: { - uint16_t word = (uint16_t)value; - buffer.CopyData(&word, 2); -} break; -case 4: { - uint32_t lword = (uint32_t)value; - buffer.CopyData(&lword, 4); -} break; -case 8: { - buffer.CopyData(&value, 8); -} break; -case
[Lldb-commits] [lldb] [lldb][Commands] Fix memory find for Swift expressions (PR #143860)
https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/143860 (depends on https://github.com/llvm/llvm-project/pull/143686) There were two issues previously preventing `memory find -e` expressions to succeed when stopped in Swift frames: 1. We weren't getting the dynamic type of the result `ValueObject`. For Swift this would fail when we tried to produce a scalar value out of it because the static VO wasn't sufficient to get to the integer value. Hence we add a call to `GetQualifiedRepresentationIfAvailable` (which is what we do for expressions in `OptionArgParser::ToAddress` too). 2. We weren't passing an `ExecutionContextScope` to `GetByteSize`, which Swift relied on to get the size of the result type. My plan is to add an API test for this on the Apple `swiftlang/llvm-project` fork. I considered an alternative where we use `OptionArgParser::ToAddress` for `memory find -e` expressions, but it got a bit icky when trying to figure out how many bytes we should copy out of the result into the `DataBufferHeap` (currently we rely on the size of the result variable type). This gets even trickier when we were to pass an expression that was actually a hex digit or a number into `ToAddress`. rdar://152113525 >From 94a2cae4dfee6d943eaa93bd089e1c0e61b54356 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Wed, 11 Jun 2025 12:02:44 +0100 Subject: [PATCH 1/2] [lldb][Commands][NFC] Extract memory find expression evaluation into helpers This patch factors out the `-e` option logic into two helper functions. The `EvaluateExpression` helper might seem redundant but I'll be adding to it in a follow-up patch to fix and issue when running `memory find -e` for Swift targets. Also adds test coverage for the error cases that were previously untested. rdar://152113525 --- lldb/source/Commands/CommandObjectMemory.cpp | 104 ++ .../memory/find/TestMemoryFind.py | 31 ++ .../API/functionalities/memory/find/main.cpp | 16 +++ 3 files changed, 108 insertions(+), 43 deletions(-) diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 7140333bb3cde..34230df9b2727 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -885,6 +885,55 @@ class CommandObjectMemoryRead : public CommandObjectParsed { #define LLDB_OPTIONS_memory_find #include "CommandOptions.inc" +static llvm::Error CopyExpressionResult(ValueObject &result, +DataBufferHeap &buffer) { + uint64_t value = result.GetValueAsUnsigned(0); + auto size_or_err = result.GetCompilerType().GetByteSize(nullptr); + if (!size_or_err) +return size_or_err.takeError(); + + switch (*size_or_err) { + case 1: { +uint8_t byte = (uint8_t)value; +buffer.CopyData(&byte, 1); + } break; + case 2: { +uint16_t word = (uint16_t)value; +buffer.CopyData(&word, 2); + } break; + case 4: { +uint32_t lword = (uint32_t)value; +buffer.CopyData(&lword, 4); + } break; + case 8: { +buffer.CopyData(&value, 8); + } break; + case 3: + case 5: + case 6: + case 7: +return llvm::createStringError("unknown type. pass a string instead"); + default: +return llvm::createStringError( +"result size larger than 8 bytes. pass a string instead"); + } + + return llvm::Error::success(); +} + +static llvm::Expected +EvaluateExpression(llvm::StringRef expression, StackFrame &frame, + Process &process) { + ValueObjectSP result_sp; + auto status = + process.GetTarget().EvaluateExpression(expression, &frame, result_sp); + if (status != eExpressionCompleted || !result_sp) +return llvm::createStringError( +"expression evaluation failed. pass a string instead"); + + return result_sp; +} + // Find the specified data in memory class CommandObjectMemoryFind : public CommandObjectParsed { public: @@ -1026,49 +1075,18 @@ class CommandObjectMemoryFind : public CommandObjectParsed { } buffer.CopyData(str); } else if (m_memory_options.m_expr.OptionWasSet()) { - StackFrame *frame = m_exe_ctx.GetFramePtr(); - ValueObjectSP result_sp; - if ((eExpressionCompleted == - process->GetTarget().EvaluateExpression( - m_memory_options.m_expr.GetValueAs().value_or( - ""), - frame, result_sp)) && - result_sp) { -uint64_t value = result_sp->GetValueAsUnsigned(0); -std::optional size = llvm::expectedToOptional( -result_sp->GetCompilerType().GetByteSize(nullptr)); -if (!size) - return; -switch (*size) { -case 1: { - uint8_t byte = (uint8_t)value; - buffer.CopyData(&byte, 1); -} break; -case 2: { - uint16_t word = (uint16_t)value; - buffer.CopyData(&word, 2); -} break; -case 4: { -
[Lldb-commits] [lldb] [lldb] Improving dotest script flags. (PR #143797)
DavidSpickett wrote: When I need to do this I always end up on https://stackoverflow.com/questions/12967232/repeatedly-run-a-shell-command-until-it-fails. lit does not have a built in way to do this. I know libcxx has something that will repeat failing tests, but not for running it N times regardless. Unlikely anyone is going to do a big migration effort though so I'd be ok with having fewer broken options. https://github.com/llvm/llvm-project/pull/143797 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits