Skip to content

[lldb][cmake] Add clang resource dir to LLDB shell tests config #136761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

chelcassanova
Copy link
Contributor

We want to be able to access the Clang resources directory in LLDB shell tests, this commit adds the ability to do this by populating the CLANG_RESOURCE_DIR CMake cache variable and adding it to the LLDB lit config.

@llvmbot
Copy link
Member

llvmbot commented Apr 22, 2025

@llvm/pr-subscribers-lldb

Author: Chelsea Cassanova (chelcassanova)

Changes

We want to be able to access the Clang resources directory in LLDB shell tests, this commit adds the ability to do this by populating the CLANG_RESOURCE_DIR CMake cache variable and adding it to the LLDB lit config.


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

2 Files Affected:

  • (modified) lldb/cmake/modules/LLDBFramework.cmake (+3-1)
  • (modified) lldb/test/Shell/lit.site.cfg.py.in (+1)
diff --git a/lldb/cmake/modules/LLDBFramework.cmake b/lldb/cmake/modules/LLDBFramework.cmake
index 471aeaaad3c0d..2fcc8f2f36f29 100644
--- a/lldb/cmake/modules/LLDBFramework.cmake
+++ b/lldb/cmake/modules/LLDBFramework.cmake
@@ -121,7 +121,7 @@ add_custom_command(TARGET liblldb POST_BUILD
 if(NOT APPLE_EMBEDDED)
   if (TARGET clang-resource-headers)
     add_dependencies(liblldb clang-resource-headers)
-    set(clang_resource_headers_dir $<TARGET_PROPERTY:clang-resource-headers,INTERFACE_INCLUDE_DIRECTORIES>)
+    get_target_property(clang_resource_headers_dir clang-resource-headers INTERFACE_INCLUDE_DIRECTORIES)
   else()
     set(clang_resource_headers_dir ${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}/include)
     if(NOT EXISTS ${clang_resource_headers_dir})
@@ -135,6 +135,8 @@ if(NOT APPLE_EMBEDDED)
             $<TARGET_FILE_DIR:liblldb>/Resources/Clang/include
     COMMENT "LLDB.framework: copy clang vendor-specific headers"
   )
+
+  set(CLANG_RESOURCE_DIR ${clang_resource_headers_dir} CACHE FILEPATH "")
 endif()
 
 # Add an rpath pointing to the directory where LLDB.framework is installed.
diff --git a/lldb/test/Shell/lit.site.cfg.py.in b/lldb/test/Shell/lit.site.cfg.py.in
index 31a6d68618b77..7e03938b12b23 100644
--- a/lldb/test/Shell/lit.site.cfg.py.in
+++ b/lldb/test/Shell/lit.site.cfg.py.in
@@ -35,6 +35,7 @@ config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 # The shell tests use their own module caches.
 config.lldb_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_LLDB@", "lldb-shell")
 config.clang_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_CLANG@", "lldb-shell")
+config.clang_resource_dir = os.path.join("@CLANG_RESOURCE_DIR@")
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)

@@ -135,6 +135,8 @@ if(NOT APPLE_EMBEDDED)
$<TARGET_FILE_DIR:liblldb>/Resources/Clang/include
COMMENT "LLDB.framework: copy clang vendor-specific headers"
)

set(CLANG_RESOURCE_DIR ${clang_resource_headers_dir} CACHE FILEPATH "")
Copy link
Member

Choose a reason for hiding this comment

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

This code path will be taken when we build the LLDB.framework for apple platforms, but it won't work if you do things on Linux. We should find another place to put this logic.

My suggestion would be LLDBConfig.cmake since that handles all of the dependency management. You'll still want to keep the copy step here, but the logic to actually find the clang headers should be moved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looked into this a little and it turns out that the code that handles searching for the clang headers in LLDBFramework.cmake looks to be overlapping with similar code in lldb/source/API/CMakeLists.txt. This should be a good opportunity to clean up that overlap.

@chelcassanova chelcassanova force-pushed the add-clang-resource-dir-to-cmake-cache branch from c7d22d4 to d5760f9 Compare April 24, 2025 20:08
@chelcassanova
Copy link
Contributor Author

I redid this PR to just add the Clang resource dir to the CMake file for the LLDB shell tests so that lit can pick it up since it's not necessary that the variable be in the CMake cache, just the scope that the lit config exists in.

@chelcassanova chelcassanova changed the title [lldb][cmake] Populate Clang resource dir for CMakeCache [lldb][cmake] Add clang resource dir to LLDB shell tests config Apr 24, 2025
@@ -1,6 +1,8 @@
add_custom_target(lldb-shell-test-deps)
set_target_properties(lldb-shell-test-deps PROPERTIES FOLDER "LLDB/Tests")
add_dependencies(lldb-shell-test-deps lldb-test-depends)
get_target_property(clang_resource_headers_dir clang-resource-headers INTERFACE_INCLUDE_DIRECTORIES)
Copy link
Member

Choose a reason for hiding this comment

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

The clang-resource-headers target may not exist if you build LLDB standalone (that is, with a prebuilt LLVM/Clang). See the end of cmake/modules/LLDBStandalone.cmake

Copy link
Member

@bulbazord bulbazord left a comment

Choose a reason for hiding this comment

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

Looking better, but I don't think the shell test's CMake file is the right place to calculate the resource directory. It's already calculated in LLDBStandalone. I think we should hoist this logic into LLDB's configuration more generally (e.g. LLDBConfig.cmake or top-level CMakeLists.txt, somewhere like that).

@@ -1,6 +1,12 @@
add_custom_target(lldb-shell-test-deps)
set_target_properties(lldb-shell-test-deps PROPERTIES FOLDER "LLDB/Tests")
add_dependencies(lldb-shell-test-deps lldb-test-depends)
if(LLDB_BUILT_STANDALONE)
get_target_property(CLANG_RESOURCE_DIR clang-resource-headers INTERFACE_INCLUDE_DIRECTORIES)
set(CLANG_RESOURCE_DIR "${CLANG_RESOURCE_DIR}/..")
Copy link
Member

Choose a reason for hiding this comment

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

Why do you move up a directory here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Getting the directory in a standalone build (using the get_target_property call) gives us this: <prefix>/llvm-build/./lib/../lib/clang/21/include/ whereas getting in a non-standalone build (using the get_clang_resource_dir call) gives us this: <prefix>/lib/clang/21. I'm moving the standalone value up a directory so that both values match regardless of how the build was done. I can add a comment to clarify this.

@@ -1,6 +1,12 @@
add_custom_target(lldb-shell-test-deps)
set_target_properties(lldb-shell-test-deps PROPERTIES FOLDER "LLDB/Tests")
add_dependencies(lldb-shell-test-deps lldb-test-depends)
if(LLDB_BUILT_STANDALONE)
get_target_property(CLANG_RESOURCE_DIR clang-resource-headers INTERFACE_INCLUDE_DIRECTORIES)
Copy link
Member

Choose a reason for hiding this comment

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

In LLDBStandalone.cmake we already compute the clang resource dir and put it into the variable LLDB_EXTERNAL_CLANG_RESOURCE_DIR. You could probably just reference that variable instead of recalculating it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This actually only happens if the clang-resource-dir target doesn't exist. When I built standalone, that target did exist so the LLDB_EXTERNAL_CLANG_RESOURCE_DIR is never populated. I changed it so that if that target doesn't exist when we're trying to set CLANG_RESOURCE_DIR, we use LLDB_EXTERNAL_CLANG_RESOURCE_DIR.

We want to be able to access the Clang resources directory in LLDB shell
tests, this commit adds the ability to do this by adding the
`CLANG_RESOURCE_DIR` CMake variable to the config for LLDB lit tests
@chelcassanova chelcassanova force-pushed the add-clang-resource-dir-to-cmake-cache branch from b073c45 to b8fec72 Compare April 30, 2025 16:19
Copy link
Member

@bulbazord bulbazord left a comment

Choose a reason for hiding this comment

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

I'm alright with this

@chelcassanova chelcassanova merged commit ff8fc5b into llvm:main Apr 30, 2025
7 of 9 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 30, 2025

LLVM Buildbot has detected a new failure on builder lldb-arm-ubuntu running on linaro-lldb-arm-ubuntu while building lldb at step 6 "test".

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

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: test_utils/TestPExpectTest.py (1152 of 3009)
PASS: lldb-api :: test_utils/base/TestBaseTest.py (1153 of 3009)
UNSUPPORTED: lldb-api :: tools/lldb-dap/attach/TestDAP_attach.py (1154 of 3009)
UNSUPPORTED: lldb-api :: tools/lldb-dap/attach/TestDAP_attachByPortNum.py (1155 of 3009)
UNSUPPORTED: lldb-api :: tools/lldb-dap/breakpoint-events/TestDAP_breakpointEvents.py (1156 of 3009)
PASS: lldb-api :: python_api/watchpoint/watchlocation/TestTargetWatchAddress.py (1157 of 3009)
PASS: lldb-api :: tools/lldb-dap/breakpoint/TestDAP_breakpointLocations.py (1158 of 3009)
PASS: lldb-api :: tools/lldb-dap/breakpoint/TestDAP_logpoints.py (1159 of 3009)
PASS: lldb-api :: tools/lldb-dap/breakpoint/TestDAP_setExceptionBreakpoints.py (1160 of 3009)
UNRESOLVED: lldb-api :: tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py (1161 of 3009)
******************** TEST 'lldb-api :: tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py' FAILED ********************
Script:
--
/usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --arch armv8l --build-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/lldb --compiler /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/breakpoint -p TestDAP_setBreakpoints.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision ff8fc5bc45c166d686e485b306fdcdadd5b02637)
  clang revision ff8fc5bc45c166d686e485b306fdcdadd5b02637
  llvm revision ff8fc5bc45c166d686e485b306fdcdadd5b02637
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
FAIL: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_clear_breakpoints_unset_breakpoints (TestDAP_setBreakpoints.TestDAP_setBreakpoints)
========= DEBUG ADAPTER PROTOCOL LOGS =========
1746035536.445734978 --> (stdin/stdout) {"command":"initialize","type":"request","arguments":{"adapterID":"lldb-native","clientID":"vscode","columnsStartAt1":true,"linesStartAt1":true,"locale":"en-us","pathFormat":"path","supportsRunInTerminalRequest":true,"supportsVariablePaging":true,"supportsVariableType":true,"supportsStartDebuggingRequest":true,"supportsProgressReporting":true,"$__lldb_sourceInitFile":false},"seq":1}
1746035536.449244261 <-- (stdin/stdout) {"body":{"$__lldb_version":"lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision ff8fc5bc45c166d686e485b306fdcdadd5b02637)\n  clang revision ff8fc5bc45c166d686e485b306fdcdadd5b02637\n  llvm revision ff8fc5bc45c166d686e485b306fdcdadd5b02637","completionTriggerCharacters":["."," ","\t"],"exceptionBreakpointFilters":[{"default":false,"filter":"cpp_catch","label":"C++ Catch"},{"default":false,"filter":"cpp_throw","label":"C++ Throw"},{"default":false,"filter":"objc_catch","label":"Objective-C Catch"},{"default":false,"filter":"objc_throw","label":"Objective-C Throw"}],"supportTerminateDebuggee":true,"supportsBreakpointLocationsRequest":true,"supportsCancelRequest":true,"supportsCompletionsRequest":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDataBreakpoints":true,"supportsDelayedStackTraceLoading":true,"supportsDisassembleRequest":true,"supportsEvaluateForHovers":true,"supportsExceptionInfoRequest":true,"supportsExceptionOptions":true,"supportsFunctionBreakpoints":true,"supportsHitConditionalBreakpoints":true,"supportsInstructionBreakpoints":true,"supportsLogPoints":true,"supportsModulesRequest":true,"supportsReadMemoryRequest":true,"supportsRestartRequest":true,"supportsSetVariable":true,"supportsStepInTargetsRequest":true,"supportsSteppingGranularity":true,"supportsValueFormattingOptions":true},"command":"initialize","request_seq":1,"seq":0,"success":true,"type":"response"}
1746035536.449787140 --> (stdin/stdout) {"command":"launch","type":"request","arguments":{"program":"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.test_clear_breakpoints_unset_breakpoints/a.out","initCommands":["settings clear --all","settings set symbols.enable-external-lookup false","settings set target.inherit-tcc true","settings set target.disable-aslr false","settings set target.detach-on-error false","settings set target.auto-apply-fixits false","settings set plugin.process.gdb-remote.packet-timeout 60","settings set symbols.clang-modules-cache-path \"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api\"","settings set use-color false","settings set show-statusline false"],"disableASLR":false,"enableAutoVariableSummaries":false,"enableSyntheticChildDebugging":false,"displayExtendedBacktrace":false},"seq":2}
1746035536.450301409 <-- (stdin/stdout) {"body":{"category":"console","output":"Running initCommands:\n"},"event":"output","seq":0,"type":"event"}
1746035536.450516462 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings clear --all\n"},"event":"output","seq":0,"type":"event"}
1746035536.450580835 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set symbols.enable-external-lookup false\n"},"event":"output","seq":0,"type":"event"}
1746035536.450645924 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set target.inherit-tcc true\n"},"event":"output","seq":0,"type":"event"}
1746035536.450696468 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set target.disable-aslr false\n"},"event":"output","seq":0,"type":"event"}
1746035536.450742483 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set target.detach-on-error false\n"},"event":"output","seq":0,"type":"event"}
1746035536.450793505 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set target.auto-apply-fixits false\n"},"event":"output","seq":0,"type":"event"}
1746035536.450854301 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set plugin.process.gdb-remote.packet-timeout 60\n"},"event":"output","seq":0,"type":"event"}
1746035536.450937748 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set symbols.clang-modules-cache-path \"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api\"\n"},"event":"output","seq":0,"type":"event"}
1746035536.451004267 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set use-color false\n"},"event":"output","seq":0,"type":"event"}
1746035536.451061726 <-- (stdin/stdout) {"body":{"category":"console","output":"(lldb) settings set show-statusline false\n"},"event":"output","seq":0,"type":"event"}
1746035536.612586498 <-- (stdin/stdout) {"command":"launch","request_seq":2,"seq":0,"success":true,"type":"response"}
1746035536.612674475 <-- (stdin/stdout) {"body":{"module":{"addressRange":"4152786944","debugInfoSize":"983.3KB","id":"0D794E6C-AF7E-D8CB-B9BA-E385B4F8753F-5A793D65","name":"ld-linux-armhf.so.3","path":"/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3","symbolFilePath":"/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3","symbolStatus":"Symbols loaded."},"reason":"new"},"event":"module","seq":0,"type":"event"}
1746035536.614457130 <-- (stdin/stdout) {"body":{"isLocalProcess":true,"name":"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.test_clear_breakpoints_unset_breakpoints/a.out","startMethod":"launch","systemProcessId":2781838},"event":"process","seq":0,"type":"event"}
1746035536.614528179 <-- (stdin/stdout) {"body":{"module":{"addressRange":"6881280","debugInfoSize":"43.1KB","id":"B4ACF97C","name":"a.out","path":"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.test_clear_breakpoints_unset_breakpoints/a.out","symbolFilePath":"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.test_clear_breakpoints_unset_breakpoints/a.out","symbolStatus":"Symbols loaded."},"reason":"new"},"event":"module","seq":0,"type":"event"}
1746035536.614698410 <-- (stdin/stdout) {"event":"initialized","seq":0,"type":"event"}
1746035536.614965439 --> (stdin/stdout) {"command":"setBreakpoints","type":"request","arguments":{"source":{"name":"main-copy.cpp","path":"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.test_clear_breakpoints_unset_breakpoints/main-copy.cpp"},"sourceModified":false,"lines":[6,10],"breakpoints":[{"line":6},{"line":10}]},"seq":3}

chelcassanova added a commit to chelcassanova/llvm-project that referenced this pull request May 1, 2025
…#136761)

We want to be able to access the Clang resources directory in LLDB shell
tests, this commit adds the ability to do this by populating the
`CLANG_RESOURCE_DIR` variable in LLDBConfig.cmake.

(cherry picked from commit ff8fc5b)
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…#136761)

We want to be able to access the Clang resources directory in LLDB shell
tests, this commit adds the ability to do this by populating the
`CLANG_RESOURCE_DIR` variable in LLDBConfig.cmake.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…#136761)

We want to be able to access the Clang resources directory in LLDB shell
tests, this commit adds the ability to do this by populating the
`CLANG_RESOURCE_DIR` variable in LLDBConfig.cmake.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…#136761)

We want to be able to access the Clang resources directory in LLDB shell
tests, this commit adds the ability to do this by populating the
`CLANG_RESOURCE_DIR` variable in LLDBConfig.cmake.
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
…#136761)

We want to be able to access the Clang resources directory in LLDB shell
tests, this commit adds the ability to do this by populating the
`CLANG_RESOURCE_DIR` variable in LLDBConfig.cmake.
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
…#136761)

We want to be able to access the Clang resources directory in LLDB shell
tests, this commit adds the ability to do this by populating the
`CLANG_RESOURCE_DIR` variable in LLDBConfig.cmake.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants