[Lldb-commits] [PATCH] D13667: cmake: provide flag that enables 'log enable --stack' to provide useful file/line info on POSIX systems
Todd Fiala via lldb-commits
lldb-commits at lists.llvm.org
Mon Oct 12 12:59:14 PDT 2015
tfiala created this revision.
tfiala added reviewers: emaste, chaoren.
tfiala added subscribers: lldb-commits, labath.
This change addresses:
https://llvm.org/bugs/show_bug.cgi?id=25133
On Linux (and likely other GNU ld-based systems), the llvm backtrace utility used by 'log enable --stack' cannot walk through private symbols in liblldb.so. This makes the --stack option useless just about everywhere but OS X. This change provides a way to address that.
By default, nothing changes. However, if the cmake -DLLDB_EXPORT_ALL_SYMBOLS=TRUE option is provided (also a CACHE variable, so can be set via UI), then on non-Windows systems, we'll drop exporting a named list of symbols, and tell the linker to export all symbols. This allows the backtrace mechanism used by 'log enable --stack' to find file/line number info, and makes introspection of source code within lldb much more productive.
The change is a do-nothing operation on Windows.
On OS X cmake builds, the additional linker option is not needed (nor is it supported by the linker).
Google folks - feel free to adjust the Linux-side reviewers. Just looking for representation.
Ed - I'd guess FreeBSD was in the same boat as Linux here.
http://reviews.llvm.org/D13667
Files:
cmake/modules/AddLLDB.cmake
cmake/modules/LLDBConfig.cmake
source/API/CMakeLists.txt
Index: source/API/CMakeLists.txt
===================================================================
--- source/API/CMakeLists.txt
+++ source/API/CMakeLists.txt
@@ -82,7 +82,21 @@
)
if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
- add_llvm_symbol_exports(liblldb ${CMAKE_CURRENT_SOURCE_DIR}/liblldb.exports)
+ if (NOT LLDB_EXPORT_ALL_SYMBOLS)
+ # If we're not exporting all symbols, we'll want to explicitly set
+ # the exported symbols here. This prevents 'log enable --stack ...'
+ # from working on some systems but limits the liblldb size.
+ MESSAGE("-- Symbols (liblldb): only exporting liblldb.exports symbols")
+ add_llvm_symbol_exports(liblldb ${CMAKE_CURRENT_SOURCE_DIR}/liblldb.exports)
+ else()
+ # Don't use an explicit export. Instead, tell the linker to
+ # export all symbols.
+ MESSAGE("-- Symbols (liblldb): exporting all symbols")
+ # Darwin linker doesn't need this extra step.
+ if (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ lldb_append_link_flags(liblldb "-Wl,--export-dynamic")
+ endif()
+ endif()
endif()
if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
Index: cmake/modules/LLDBConfig.cmake
===================================================================
--- cmake/modules/LLDBConfig.cmake
+++ cmake/modules/LLDBConfig.cmake
@@ -29,6 +29,15 @@
set(LLDB_RELOCATABLE_PYTHON 0 CACHE BOOL
"Causes LLDB to use the PYTHONHOME environment variable to locate Python.")
+if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
+ set(LLDB_EXPORT_ALL_SYMBOLS 0 CACHE BOOL
+ "Causes lldb to export all symbols when building liblldb.")
+else()
+ # Windows doesn't support toggling this, so don't bother making it a
+ # cache variable.
+ set(LLDB_EXPORT_ALL_SYMBOLS 0)
+endif()
+
if ((NOT MSVC) OR MSVC12)
add_definitions( -DHAVE_ROUND )
endif()
Index: cmake/modules/AddLLDB.cmake
===================================================================
--- cmake/modules/AddLLDB.cmake
+++ cmake/modules/AddLLDB.cmake
@@ -96,3 +96,19 @@
add_llvm_executable(${name} ${ARGN})
set_target_properties(${name} PROPERTIES FOLDER "lldb executables")
endmacro(add_lldb_executable)
+
+# Support appending linker flags to an existing target.
+# This will preserve the existing linker flags on the
+# target, if there are any.
+function(lldb_append_link_flags target_name new_link_flags)
+ # Retrieve existing linker flags.
+ get_target_property(current_link_flags ${target_name} LINK_FLAGS)
+
+ # If we had any linker flags, include them first in the new linker flags.
+ if(current_link_flags)
+ set(new_link_flags "${current_link_flags} ${new_link_flags}")
+ endif()
+
+ # Now set them onto the target.
+ set_target_properties(${target_name} PROPERTIES LINK_FLAGS ${new_link_flags})
+endfunction()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13667.37150.patch
Type: text/x-patch
Size: 2767 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20151012/a96f8aaf/attachment.bin>
More information about the lldb-commits
mailing list