Skip to content

Commit d33eec8

Browse files
committed
[lldb/cmake] Plugin layering enforcement mechanism
1 parent 66d6964 commit d33eec8

File tree

31 files changed

+163
-0
lines changed

31 files changed

+163
-0
lines changed

lldb/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ endif()
3737

3838
include(LLDBConfig)
3939
include(AddLLDB)
40+
include(LLDBLayeringCheck)
4041

4142
set(LLDB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
4243

@@ -127,6 +128,8 @@ add_subdirectory(source)
127128
add_subdirectory(tools)
128129
add_subdirectory(docs)
129130

131+
check_lldb_plugin_layering()
132+
130133
if (LLDB_ENABLE_PYTHON)
131134
if(LLDB_BUILD_FRAMEWORK)
132135
set(lldb_python_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python/lldb")
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
define_property(DIRECTORY PROPERTY LLDB_PLUGIN_KIND)
2+
define_property(TARGET PROPERTY LLDB_PLUGIN_KIND INHERITED)
3+
4+
define_property(DIRECTORY PROPERTY LLDB_ACCEPTABLE_PLUGIN_DEPENDENCIES)
5+
define_property(TARGET PROPERTY LLDB_ACCEPTABLE_PLUGIN_DEPENDENCIES INHERITED)
6+
7+
define_property(DIRECTORY PROPERTY LLDB_TOLERATED_PLUGIN_DEPENDENCIES)
8+
define_property(TARGET PROPERTY LLDB_TOLERATED_PLUGIN_DEPENDENCIES INHERITED)
9+
10+
option(LLDB_GENERATE_PLUGIN_DEP_GRAPH OFF)
11+
12+
function(check_lldb_plugin_layering)
13+
get_property(plugins GLOBAL PROPERTY LLDB_PLUGINS)
14+
foreach(plugin ${plugins})
15+
get_property(plugin_kind TARGET ${plugin} PROPERTY LLDB_PLUGIN_KIND)
16+
get_property(acceptable_deps TARGET ${plugin}
17+
PROPERTY LLDB_ACCEPTABLE_PLUGIN_DEPENDENCIES)
18+
get_property(tolerated_deps TARGET ${plugin}
19+
PROPERTY LLDB_TOLERATED_PLUGIN_DEPENDENCIES)
20+
21+
# A plugin is always permitted to depend on its own kind for the purposes
22+
# subclassing. Ideally the intra-kind dependencies should not form a loop,
23+
# but we're not checking that here.
24+
list(APPEND acceptable_deps ${plugin_kind})
25+
26+
list(APPEND all_plugin_kinds ${plugin_kind})
27+
28+
get_property(link_libs TARGET ${plugin} PROPERTY LINK_LIBRARIES)
29+
foreach(link_lib ${link_libs})
30+
if(link_lib IN_LIST plugins)
31+
get_property(lib_kind TARGET ${link_lib} PROPERTY LLDB_PLUGIN_KIND)
32+
if (lib_kind)
33+
if (lib_kind IN_LIST acceptable_deps)
34+
set(dep_kind green)
35+
elseif (lib_kind IN_LIST tolerated_deps)
36+
set(dep_kind yellow)
37+
else()
38+
set(dep_kind red)
39+
message(SEND_ERROR "Plugin ${plugin} cannot depend on ${lib_kind} "
40+
"plugin ${link_lib}")
41+
endif()
42+
list(APPEND dep_${dep_kind}_${plugin_kind}_${lib_kind} ${plugin})
43+
endif()
44+
endif()
45+
endforeach()
46+
endforeach()
47+
48+
if (LLDB_GENERATE_PLUGIN_DEP_GRAPH)
49+
set(dep_graph "digraph Plugins {\n")
50+
list(REMOVE_DUPLICATES all_plugin_kinds)
51+
foreach (from ${all_plugin_kinds})
52+
foreach (to ${all_plugin_kinds})
53+
foreach (dep_kind green yellow red)
54+
if (dep_${dep_kind}_${from}_${to})
55+
list(REMOVE_DUPLICATES dep_${dep_kind}_${from}_${to})
56+
string(REGEX REPLACE "lldbPlugin|${from}" "" short_deps
57+
"${dep_${dep_kind}_${from}_${to}}")
58+
string(JOIN "\n" plugins ${short_deps})
59+
string(APPEND dep_graph
60+
" ${from}->${to}[color=\"${dep_kind}\" label=\"${plugins}\"];\n")
61+
endif()
62+
endforeach()
63+
endforeach()
64+
endforeach()
65+
string(APPEND dep_graph "}\n")
66+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/lldb-plugin-deps.dot" "${dep_graph}")
67+
endif()
68+
endfunction()

lldb/source/Plugins/ABI/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
set_property(DIRECTORY PROPERTY LLDB_PLUGIN_KIND ABI)
2+
set_property(DIRECTORY PROPERTY LLDB_TOLERATED_PLUGIN_DEPENDENCIES
3+
ProcessUtility
4+
TypeSystem
5+
)
6+
17
foreach(target AArch64 ARM ARC Hexagon LoongArch Mips MSP430 PowerPC RISCV SystemZ X86)
28
if (${target} IN_LIST LLVM_TARGETS_TO_BUILD)
39
add_subdirectory(${target})

lldb/source/Plugins/Architecture/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
set_property(DIRECTORY PROPERTY LLDB_PLUGIN_KIND Architecture)
2+
13
add_subdirectory(Arm)
24
add_subdirectory(Mips)
35
add_subdirectory(PPC64)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
set_property(DIRECTORY PROPERTY LLDB_PLUGIN_KIND Disassembler)
2+
13
add_subdirectory(LLVMC)

lldb/source/Plugins/DynamicLoader/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
set_property(DIRECTORY PROPERTY LLDB_PLUGIN_KIND DynamicLoader)
2+
set_property(DIRECTORY PROPERTY LLDB_ACCEPTABLE_PLUGIN_DEPENDENCIES ObjectFile)
3+
set_property(DIRECTORY PROPERTY LLDB_TOLERATED_PLUGIN_DEPENDENCIES
4+
Process # part of a loop (Process<->DynamicLoader).
5+
TypeSystem
6+
)
7+
18
add_subdirectory(Darwin-Kernel)
29
add_subdirectory(FreeBSD-Kernel)
310
add_subdirectory(MacOSX-DYLD)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
set_property(DIRECTORY PROPERTY LLDB_PLUGIN_KIND ExpressionParser)
2+
13
add_subdirectory(Clang)

lldb/source/Plugins/Instruction/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
set_property(DIRECTORY PROPERTY LLDB_PLUGIN_KIND Instruction)
2+
13
add_subdirectory(ARM)
24
add_subdirectory(ARM64)
35
add_subdirectory(LoongArch)

lldb/source/Plugins/InstrumentationRuntime/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
set_property(DIRECTORY PROPERTY LLDB_PLUGIN_KIND InstrumentationRuntime)
2+
13
add_subdirectory(ASan)
24
add_subdirectory(ASanLibsanitizers)
35
add_subdirectory(MainThreadChecker)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
set_property(DIRECTORY PROPERTY LLDB_PLUGIN_KIND JITLoader)
2+
set_property(DIRECTORY PROPERTY LLDB_TOLERATED_PLUGIN_DEPENDENCIES ObjectFile)
3+
14
add_subdirectory(GDB)

0 commit comments

Comments
 (0)