diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:04:10 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:04:10 +0000 |
commit | 74a628f776edb588bff8f8f5cc16eac947c9d631 (patch) | |
tree | dc32e010ac4902621e5a279bfeb48628f7f0e166 /source/Plugins | |
parent | afed7be32164a598f8172282c249af7266c48b46 (diff) | |
download | src-74a628f776edb588bff8f8f5cc16eac947c9d631.tar.gz src-74a628f776edb588bff8f8f5cc16eac947c9d631.zip |
Vendor import of lldb trunk r300422:vendor/lldb/lldb-trunk-r300422
Notes
Notes:
svn path=/vendor/lldb/dist/; revision=317027
svn path=/vendor/lldb/lldb-trunk-r300422/; revision=317028; tag=vendor/lldb/lldb-trunk-r300422
Diffstat (limited to 'source/Plugins')
455 files changed, 10255 insertions, 7110 deletions
diff --git a/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp b/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp index 969c7d3c071e..dc1c8dcf4ab0 100644 --- a/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp +++ b/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp @@ -18,8 +18,6 @@ #include "llvm/ADT/Triple.h" // Project includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/Error.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" @@ -31,6 +29,8 @@ #include "lldb/Target/RegisterContext.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Error.h" #include "Plugins/Process/Utility/ARMDefines.h" #include "Utility/ARM_DWARF_Registers.h" diff --git a/source/Plugins/ABI/MacOSX-arm/CMakeLists.txt b/source/Plugins/ABI/MacOSX-arm/CMakeLists.txt index ea8b011b1984..b41814f3237b 100644 --- a/source/Plugins/ABI/MacOSX-arm/CMakeLists.txt +++ b/source/Plugins/ABI/MacOSX-arm/CMakeLists.txt @@ -1,3 +1,11 @@ -add_lldb_library(lldbPluginABIMacOSX_arm +add_lldb_library(lldbPluginABIMacOSX_arm PLUGIN ABIMacOSX_arm.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + lldbPluginProcessUtility + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp b/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp index ee27a7e8d9b3..c5e53361bf99 100644 --- a/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp +++ b/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp @@ -17,9 +17,6 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Triple.h" -#include "lldb/Core/ConstString.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" @@ -32,6 +29,9 @@ #include "lldb/Target/RegisterContext.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" #include "Utility/ARM64_DWARF_Registers.h" diff --git a/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h b/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h index e0978116a730..93a548a79682 100644 --- a/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h +++ b/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h @@ -14,8 +14,8 @@ // C++ Includes // Other libraries and framework includes // Project includes -#include "lldb/Core/ConstString.h" #include "lldb/Target/ABI.h" +#include "lldb/Utility/ConstString.h" #include "lldb/lldb-private.h" class ABIMacOSX_arm64 : public lldb_private::ABI { diff --git a/source/Plugins/ABI/MacOSX-arm64/CMakeLists.txt b/source/Plugins/ABI/MacOSX-arm64/CMakeLists.txt index 498bb7218637..f769d63bcdac 100644 --- a/source/Plugins/ABI/MacOSX-arm64/CMakeLists.txt +++ b/source/Plugins/ABI/MacOSX-arm64/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginABIMacOSX_arm64 +add_lldb_library(lldbPluginABIMacOSX_arm64 PLUGIN ABIMacOSX_arm64.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp b/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp index 6eead6f35e3b..bbaec25b37b8 100644 --- a/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp +++ b/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp @@ -18,8 +18,6 @@ #include "llvm/ADT/Triple.h" // Project includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/Error.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" @@ -30,6 +28,8 @@ #include "lldb/Target/RegisterContext.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Error.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/ABI/MacOSX-i386/CMakeLists.txt b/source/Plugins/ABI/MacOSX-i386/CMakeLists.txt index f6a543a66da7..21f153d36e08 100644 --- a/source/Plugins/ABI/MacOSX-i386/CMakeLists.txt +++ b/source/Plugins/ABI/MacOSX-i386/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginABIMacOSX_i386 +add_lldb_library(lldbPluginABIMacOSX_i386 PLUGIN ABIMacOSX_i386.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp b/source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp index ebd0d17cf8ab..3df225cc895d 100644 --- a/source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp +++ b/source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp @@ -18,8 +18,6 @@ #include "llvm/ADT/Triple.h" // Project includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/Error.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" @@ -31,6 +29,8 @@ #include "lldb/Target/RegisterContext.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Error.h" #include "Plugins/Process/Utility/ARMDefines.h" #include "Utility/ARM_DWARF_Registers.h" diff --git a/source/Plugins/ABI/SysV-arm/CMakeLists.txt b/source/Plugins/ABI/SysV-arm/CMakeLists.txt index c25ce5a1c633..c5979046d36c 100644 --- a/source/Plugins/ABI/SysV-arm/CMakeLists.txt +++ b/source/Plugins/ABI/SysV-arm/CMakeLists.txt @@ -1,3 +1,11 @@ -add_lldb_library(lldbPluginABISysV_arm +add_lldb_library(lldbPluginABISysV_arm PLUGIN ABISysV_arm.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + lldbPluginProcessUtility + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp b/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp index 5e2179212be9..04df0065d7bc 100644 --- a/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp +++ b/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp @@ -18,9 +18,6 @@ #include "llvm/ADT/Triple.h" // Project includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" @@ -32,6 +29,9 @@ #include "lldb/Target/RegisterContext.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" #include "Utility/ARM64_DWARF_Registers.h" @@ -1697,7 +1697,7 @@ bool ABISysV_arm64::PrepareTrivialCall(Thread &thread, addr_t sp, if (log) { StreamString s; - s.Printf("ABISysV_x86_64::PrepareTrivialCall (tid = 0x%" PRIx64 + s.Printf("ABISysV_arm64::PrepareTrivialCall (tid = 0x%" PRIx64 ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64 ", return_addr = 0x%" PRIx64, thread.GetID(), (uint64_t)sp, (uint64_t)func_addr, diff --git a/source/Plugins/ABI/SysV-arm64/CMakeLists.txt b/source/Plugins/ABI/SysV-arm64/CMakeLists.txt index 0ddb37043ace..077b394823c6 100644 --- a/source/Plugins/ABI/SysV-arm64/CMakeLists.txt +++ b/source/Plugins/ABI/SysV-arm64/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginABISysV_arm64 +add_lldb_library(lldbPluginABISysV_arm64 PLUGIN ABISysV_arm64.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.cpp b/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.cpp index 649f19b0b831..0b024dbac07d 100644 --- a/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.cpp +++ b/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.cpp @@ -16,10 +16,6 @@ #include "llvm/IR/DerivedTypes.h" // Project includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/DataExtractor.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" @@ -33,6 +29,10 @@ #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/ABI/SysV-hexagon/CMakeLists.txt b/source/Plugins/ABI/SysV-hexagon/CMakeLists.txt index b8fbb0744719..a857fff12399 100644 --- a/source/Plugins/ABI/SysV-hexagon/CMakeLists.txt +++ b/source/Plugins/ABI/SysV-hexagon/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginABISysV_hexagon +add_lldb_library(lldbPluginABISysV_hexagon PLUGIN ABISysV_hexagon.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp b/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp index 701db184dfce..aee102c16ba1 100644 --- a/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp +++ b/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp @@ -16,10 +16,6 @@ #include "llvm/ADT/Triple.h" // Project includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/DataExtractor.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" @@ -33,6 +29,10 @@ #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/ABI/SysV-i386/CMakeLists.txt b/source/Plugins/ABI/SysV-i386/CMakeLists.txt index 3528f01ad75e..598b3d03c0f3 100644 --- a/source/Plugins/ABI/SysV-i386/CMakeLists.txt +++ b/source/Plugins/ABI/SysV-i386/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginABISysV_i386 +add_lldb_library(lldbPluginABISysV_i386 PLUGIN ABISysV_i386.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp b/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp index b97fffe3efa3..69725e30b063 100644 --- a/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp +++ b/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp @@ -16,10 +16,6 @@ #include "llvm/ADT/Triple.h" // Project includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/DataExtractor.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" @@ -33,6 +29,10 @@ #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/ABI/SysV-mips/CMakeLists.txt b/source/Plugins/ABI/SysV-mips/CMakeLists.txt index 0db3e5c1c7e0..a3266a75ae73 100644 --- a/source/Plugins/ABI/SysV-mips/CMakeLists.txt +++ b/source/Plugins/ABI/SysV-mips/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginABISysV_mips +add_lldb_library(lldbPluginABISysV_mips PLUGIN ABISysV_mips.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp b/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp index bb83dec5d9df..bbcf2e575825 100644 --- a/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp +++ b/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp @@ -16,10 +16,6 @@ #include "llvm/ADT/Triple.h" // Project includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/DataExtractor.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" @@ -33,6 +29,10 @@ #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/ABI/SysV-mips64/CMakeLists.txt b/source/Plugins/ABI/SysV-mips64/CMakeLists.txt index 099464821edd..5eddfb539f05 100644 --- a/source/Plugins/ABI/SysV-mips64/CMakeLists.txt +++ b/source/Plugins/ABI/SysV-mips64/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginABISysV_mips64 +add_lldb_library(lldbPluginABISysV_mips64 PLUGIN ABISysV_mips64.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp b/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp index 3e563c2b5d9c..2dff0d203611 100644 --- a/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp +++ b/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp @@ -16,10 +16,6 @@ #include "llvm/ADT/Triple.h" // Project includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/DataExtractor.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" @@ -33,6 +29,10 @@ #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/ABI/SysV-ppc/CMakeLists.txt b/source/Plugins/ABI/SysV-ppc/CMakeLists.txt index a7784195f771..63bfc4a96cdf 100644 --- a/source/Plugins/ABI/SysV-ppc/CMakeLists.txt +++ b/source/Plugins/ABI/SysV-ppc/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginABISysV_ppc +add_lldb_library(lldbPluginABISysV_ppc PLUGIN ABISysV_ppc.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp b/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp index 4ffcba377345..59430caa6e37 100644 --- a/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp +++ b/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp @@ -16,10 +16,6 @@ #include "llvm/ADT/Triple.h" // Project includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/DataExtractor.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" @@ -33,6 +29,10 @@ #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/ABI/SysV-ppc64/CMakeLists.txt b/source/Plugins/ABI/SysV-ppc64/CMakeLists.txt index 7a33d2922047..b31182dd0f78 100644 --- a/source/Plugins/ABI/SysV-ppc64/CMakeLists.txt +++ b/source/Plugins/ABI/SysV-ppc64/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginABISysV_ppc64 +add_lldb_library(lldbPluginABISysV_ppc64 PLUGIN ABISysV_ppc64.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp b/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp index 7e6506bb1f44..a899b24cea5c 100644 --- a/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp +++ b/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp @@ -16,10 +16,6 @@ #include "llvm/ADT/Triple.h" // Project includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/DataExtractor.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" @@ -33,6 +29,10 @@ #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/ABI/SysV-s390x/CMakeLists.txt b/source/Plugins/ABI/SysV-s390x/CMakeLists.txt index c3992db023e6..f670f0157a6b 100644 --- a/source/Plugins/ABI/SysV-s390x/CMakeLists.txt +++ b/source/Plugins/ABI/SysV-s390x/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginABISysV_s390x +add_lldb_library(lldbPluginABISysV_s390x PLUGIN ABISysV_s390x.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp b/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp index 2019db2bfd17..42bb9d057e61 100644 --- a/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp +++ b/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp @@ -16,10 +16,6 @@ #include "llvm/ADT/Triple.h" // Project includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/DataExtractor.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" @@ -33,6 +29,10 @@ #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/ABI/SysV-x86_64/CMakeLists.txt b/source/Plugins/ABI/SysV-x86_64/CMakeLists.txt index a2b62d7240fd..17644d74ac2f 100644 --- a/source/Plugins/ABI/SysV-x86_64/CMakeLists.txt +++ b/source/Plugins/ABI/SysV-x86_64/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginABISysV_x86_64 +add_lldb_library(lldbPluginABISysV_x86_64 PLUGIN ABISysV_x86_64.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/Disassembler/llvm/CMakeLists.txt b/source/Plugins/Disassembler/llvm/CMakeLists.txt index ada81dc55e97..a25a436d498e 100644 --- a/source/Plugins/Disassembler/llvm/CMakeLists.txt +++ b/source/Plugins/Disassembler/llvm/CMakeLists.txt @@ -1,3 +1,14 @@ -add_lldb_library(lldbPluginDisassemblerLLVM +add_lldb_library(lldbPluginDisassemblerLLVM PLUGIN DisassemblerLLVMC.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + LINK_COMPONENTS + ${LLVM_TARGETS_TO_BUILD} + MC + MCDisassembler + RuntimeDyld + Support ) diff --git a/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp b/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp index b7415b42c60e..e144ef18b413 100644 --- a/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp +++ b/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp @@ -31,10 +31,7 @@ #include "DisassemblerLLVMC.h" #include "lldb/Core/Address.h" -#include "lldb/Core/DataExtractor.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" -#include "lldb/Core/Stream.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Process.h" @@ -42,8 +39,11 @@ #include "lldb/Target/SectionLoadList.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/Stream.h" -#include "lldb/Core/RegularExpression.h" +#include "lldb/Utility/RegularExpression.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/DynamicLoader/Darwin-Kernel/CMakeLists.txt b/source/Plugins/DynamicLoader/Darwin-Kernel/CMakeLists.txt index 02752b78a4c7..ffc797b7475b 100644 --- a/source/Plugins/DynamicLoader/Darwin-Kernel/CMakeLists.txt +++ b/source/Plugins/DynamicLoader/Darwin-Kernel/CMakeLists.txt @@ -1,3 +1,13 @@ -add_lldb_library(lldbPluginDynamicLoaderDarwinKernel +add_lldb_library(lldbPluginDynamicLoaderDarwinKernel PLUGIN DynamicLoaderDarwinKernel.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbHost + lldbInterpreter + lldbSymbol + lldbTarget + lldbUtility + lldbPluginPlatformMacOSX ) diff --git a/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp index b7010303bcaa..80f3f6857fd4 100644 --- a/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp +++ b/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp @@ -12,10 +12,7 @@ #include "Plugins/Platform/MacOSX/PlatformDarwinKernel.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" -#include "lldb/Core/DataBuffer.h" -#include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" @@ -25,11 +22,15 @@ #include "lldb/Host/Symbols.h" #include "lldb/Interpreter/OptionValueProperties.h" #include "lldb/Symbol/ObjectFile.h" +#include "lldb/Target/OperatingSystem.h" #include "lldb/Target/RegisterContext.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadPlanRunToAddress.h" +#include "lldb/Utility/DataBuffer.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Log.h" #include "DynamicLoaderDarwinKernel.h" @@ -1026,6 +1027,12 @@ void DynamicLoaderDarwinKernel::LoadKernelModuleIfNeeded() { m_kernel.LoadImageAtFileAddress(m_process); } } + + // The operating system plugin gets loaded and initialized in + // LoadImageUsingMemoryModule when we discover the kernel dSYM. For a + // core file in particular, that's the wrong place to do this, since + // we haven't fixed up the section addresses yet. So let's redo it here. + LoadOperatingSystemPlugin(false); if (m_kernel.IsLoaded() && m_kernel.GetModule()) { static ConstString kext_summary_symbol("gLoadedKextSummaries"); diff --git a/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h b/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h index 695a4eaf881a..7ca9bada1a1f 100644 --- a/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h +++ b/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h @@ -18,10 +18,10 @@ // Other libraries and framework includes // Project includes -#include "lldb/Core/UUID.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/Process.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/UUID.h" class DynamicLoaderDarwinKernel : public lldb_private::DynamicLoader { public: diff --git a/source/Plugins/DynamicLoader/Hexagon-DYLD/CMakeLists.txt b/source/Plugins/DynamicLoader/Hexagon-DYLD/CMakeLists.txt index af15f284118f..c590457d0a54 100644 --- a/source/Plugins/DynamicLoader/Hexagon-DYLD/CMakeLists.txt +++ b/source/Plugins/DynamicLoader/Hexagon-DYLD/CMakeLists.txt @@ -1,4 +1,10 @@ -add_lldb_library(lldbPluginDynamicLoaderHexagonDYLD +add_lldb_library(lldbPluginDynamicLoaderHexagonDYLD PLUGIN HexagonDYLDRendezvous.cpp DynamicLoaderHexagonDYLD.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbSymbol + lldbTarget ) diff --git a/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp b/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp index 3c64b2ffed3c..25bf6e9a7296 100644 --- a/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp +++ b/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp @@ -11,7 +11,6 @@ // C++ Includes // Other libraries and framework includes #include "lldb/Breakpoint/BreakpointLocation.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" @@ -21,6 +20,7 @@ #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadPlanRunToAddress.h" +#include "lldb/Utility/Log.h" #include "DynamicLoaderHexagonDYLD.h" diff --git a/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp b/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp index da0edc870f86..f22644aec107 100644 --- a/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp +++ b/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp @@ -11,13 +11,13 @@ // C++ Includes // Other libraries and framework includes #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Symbol/Symbol.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Target/Process.h" diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/CMakeLists.txt b/source/Plugins/DynamicLoader/MacOSX-DYLD/CMakeLists.txt index 7dc3e98e6a57..515c82dcaca9 100644 --- a/source/Plugins/DynamicLoader/MacOSX-DYLD/CMakeLists.txt +++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/CMakeLists.txt @@ -1,5 +1,16 @@ -add_lldb_library(lldbPluginDynamicLoaderMacOSXDYLD +add_lldb_library(lldbPluginDynamicLoaderMacOSXDYLD PLUGIN DynamicLoaderMacOSXDYLD.cpp DynamicLoaderMacOS.cpp DynamicLoaderDarwin.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbExpression + lldbHost + lldbSymbol + lldbTarget + lldbUtility + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp index bd0e772f7783..4ffd216e98a7 100644 --- a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp +++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp @@ -10,10 +10,7 @@ #include "DynamicLoaderDarwin.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" -#include "lldb/Core/DataBuffer.h" -#include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" @@ -32,6 +29,9 @@ #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadPlanCallFunction.h" #include "lldb/Target/ThreadPlanRunToAddress.h" +#include "lldb/Utility/DataBuffer.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Log.h" //#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN #ifdef ENABLE_DEBUG_PRINTF @@ -542,6 +542,10 @@ void DynamicLoaderDarwin::UpdateSpecialBinariesFromNewImageInfos( dyld_idx = i; } } + else { + // catch-all for any other environment -- trust that dyld is actually dyld + dyld_idx = i; + } } else if (image_infos[i].header.filetype == llvm::MachO::MH_EXECUTE) { exe_idx = i; } diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h index 2daa58de0cf6..fdfe45b663c1 100644 --- a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h +++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h @@ -19,11 +19,11 @@ // Other libraries and framework includes // Project includes #include "lldb/Core/StructuredData.h" -#include "lldb/Core/UUID.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/Process.h" +#include "lldb/Utility/FileSpec.h" #include "lldb/Utility/SafeMachO.h" +#include "lldb/Utility/UUID.h" #include "llvm/ADT/Triple.h" diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp index 7b027de783ed..20260ee5b5c3 100644 --- a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp +++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp @@ -9,7 +9,6 @@ #include "lldb/Breakpoint/StoppointCallbackContext.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Section.h" @@ -21,6 +20,7 @@ #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/Log.h" #include "DynamicLoaderDarwin.h" #include "DynamicLoaderMacOS.h" @@ -139,6 +139,7 @@ bool DynamicLoaderMacOS::DidSetNotificationBreakpoint() { void DynamicLoaderMacOS::ClearNotificationBreakpoint() { if (LLDB_BREAK_ID_IS_VALID(m_break_id)) { m_process->GetTarget().RemoveBreakpointByID(m_break_id); + m_break_id = LLDB_INVALID_BREAK_ID; } } @@ -151,6 +152,11 @@ void DynamicLoaderMacOS::ClearNotificationBreakpoint() { void DynamicLoaderMacOS::DoInitialImageFetch() { Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); + // Remove any binaries we pre-loaded in the Target before launching/attaching. + // If the same binaries are present in the process, we'll get them from the + // shared module cache, we won't need to re-load them from disk. + UnloadAllImages(); + StructuredData::ObjectSP all_image_info_json_sp( m_process->GetLoadedDynamicLibrariesInfos()); ImageInfo::collection image_infos; diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h index 93273b13bb73..60c4beed383b 100644 --- a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h +++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h @@ -26,11 +26,11 @@ // Other libraries and framework includes // Project includes #include "lldb/Core/StructuredData.h" -#include "lldb/Core/UUID.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/Process.h" +#include "lldb/Utility/FileSpec.h" #include "lldb/Utility/SafeMachO.h" +#include "lldb/Utility/UUID.h" #include "DynamicLoaderDarwin.h" diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp index 9c5f1bce3bd3..46742c1f9b5e 100644 --- a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -8,10 +8,7 @@ //===----------------------------------------------------------------------===// #include "lldb/Breakpoint/StoppointCallbackContext.h" -#include "lldb/Core/DataBuffer.h" -#include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" @@ -27,6 +24,9 @@ #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadPlanRunToAddress.h" +#include "lldb/Utility/DataBuffer.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Log.h" #include "DynamicLoaderDarwin.h" #include "DynamicLoaderMacOSXDYLD.h" diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h index 25ccf702e965..d5f1b51e508a 100644 --- a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h +++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h @@ -29,11 +29,11 @@ // Other libraries and framework includes // Project includes #include "lldb/Core/StructuredData.h" -#include "lldb/Core/UUID.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/Process.h" +#include "lldb/Utility/FileSpec.h" #include "lldb/Utility/SafeMachO.h" +#include "lldb/Utility/UUID.h" #include "DynamicLoaderDarwin.h" diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp b/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp index ec655c6f9b32..d385b78e0ec4 100644 --- a/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp +++ b/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp @@ -14,10 +14,10 @@ // C++ Includes // Other libraries and framework includes -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/DataExtractor.h" -#include "lldb/Core/Log.h" #include "lldb/Target/Process.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Log.h" #if defined(__linux__) || defined(__FreeBSD__) #include "Plugins/Process/elf-core/ProcessElfCore.h" diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/CMakeLists.txt b/source/Plugins/DynamicLoader/POSIX-DYLD/CMakeLists.txt index b302997794a0..409ba92a0e19 100644 --- a/source/Plugins/DynamicLoader/POSIX-DYLD/CMakeLists.txt +++ b/source/Plugins/DynamicLoader/POSIX-DYLD/CMakeLists.txt @@ -1,5 +1,15 @@ -add_lldb_library(lldbPluginDynamicLoaderPosixDYLD +add_lldb_library(lldbPluginDynamicLoaderPosixDYLD PLUGIN AuxVector.cpp DYLDRendezvous.cpp DynamicLoaderPOSIXDYLD.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbHost + lldbSymbol + lldbTarget + lldbPluginProcessElfCore + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp b/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp index 136bf6561a21..c4917c08fa90 100644 --- a/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp +++ b/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp @@ -11,8 +11,6 @@ // C++ Includes // Other libraries and framework includes #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/Symbol.h" @@ -20,6 +18,8 @@ #include "lldb/Target/Platform.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" #include "llvm/Support/Path.h" @@ -379,12 +379,13 @@ bool DYLDRendezvous::RemoveSOEntries() { } bool DYLDRendezvous::SOEntryIsMainExecutable(const SOEntry &entry) { - // On Linux the executable is indicated by an empty path in the entry. On - // FreeBSD and on Android it is the full path to the executable. + // On some systes the executable is indicated by an empty path in the entry. + // On others it is the full path to the executable. auto triple = m_process->GetTarget().GetArchitecture().GetTriple(); switch (triple.getOS()) { case llvm::Triple::FreeBSD: + case llvm::Triple::NetBSD: return entry.file_spec == m_exe_file_spec; case llvm::Triple::Linux: if (triple.isAndroid()) diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h b/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h index 55b8bd7fb49e..295ae55e1b85 100644 --- a/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h +++ b/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h @@ -16,7 +16,7 @@ #include <string> // Other libraries and framework includes -#include "lldb/Host/FileSpec.h" +#include "lldb/Utility/FileSpec.h" #include "lldb/lldb-defines.h" #include "lldb/lldb-types.h" diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp b/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp index fc225eebe605..c809d2c77834 100644 --- a/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp +++ b/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp @@ -15,7 +15,6 @@ // Other libraries and framework includes #include "lldb/Breakpoint/BreakpointLocation.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" @@ -27,6 +26,7 @@ #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadPlanRunToAddress.h" +#include "lldb/Utility/Log.h" // C++ Includes // C Includes @@ -63,8 +63,9 @@ DynamicLoader *DynamicLoaderPOSIXDYLD::CreateInstance(Process *process, if (!create) { const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple(); - if (triple_ref.getOS() == llvm::Triple::Linux || - triple_ref.getOS() == llvm::Triple::FreeBSD) + if (triple_ref.getOS() == llvm::Triple::FreeBSD || + triple_ref.getOS() == llvm::Triple::Linux || + triple_ref.getOS() == llvm::Triple::NetBSD) create = true; } diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h b/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h index 1e8333fb099a..8e4be1d4a06a 100644 --- a/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h +++ b/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h @@ -12,6 +12,9 @@ // C Includes // C++ Includes +#include <map> +#include <memory> + // Other libraries and framework includes // Project includes #include "lldb/Breakpoint/StoppointCallbackContext.h" diff --git a/source/Plugins/DynamicLoader/Static/CMakeLists.txt b/source/Plugins/DynamicLoader/Static/CMakeLists.txt index 274f6bac3697..be54a3053470 100644 --- a/source/Plugins/DynamicLoader/Static/CMakeLists.txt +++ b/source/Plugins/DynamicLoader/Static/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginDynamicLoaderStatic +add_lldb_library(lldbPluginDynamicLoaderStatic PLUGIN DynamicLoaderStatic.cpp + + LINK_LIBS + lldbCore + lldbHost + lldbSymbol + lldbTarget + lldbUtility ) diff --git a/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h b/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h index c6122edf50cf..413ad80a2fd9 100644 --- a/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h +++ b/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h @@ -14,10 +14,10 @@ // C++ Includes // Other libraries and framework includes // Project includes -#include "lldb/Core/UUID.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/Process.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/UUID.h" class DynamicLoaderStatic : public lldb_private::DynamicLoader { public: diff --git a/source/Plugins/DynamicLoader/Windows-DYLD/CMakeLists.txt b/source/Plugins/DynamicLoader/Windows-DYLD/CMakeLists.txt index ee768057bcd5..7557ada51466 100644 --- a/source/Plugins/DynamicLoader/Windows-DYLD/CMakeLists.txt +++ b/source/Plugins/DynamicLoader/Windows-DYLD/CMakeLists.txt @@ -1,3 +1,9 @@ -add_lldb_library(lldbPluginDynamicLoaderWindowsDYLD +add_lldb_library(lldbPluginDynamicLoaderWindowsDYLD PLUGIN DynamicLoaderWindowsDYLD.cpp + + LINK_LIBS + lldbCore + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp b/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp index c74f1474e7be..0d619e4174e0 100644 --- a/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp +++ b/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp @@ -9,10 +9,10 @@ #include "ASTDumper.h" -#include "lldb/Core/Log.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/ClangUtil.h" #include "lldb/Symbol/CompilerType.h" +#include "lldb/Utility/Log.h" #include "llvm/Support/raw_ostream.h" diff --git a/source/Plugins/ExpressionParser/Clang/ASTDumper.h b/source/Plugins/ExpressionParser/Clang/ASTDumper.h index 9a72fb64e537..58ba19739e5b 100644 --- a/source/Plugins/ExpressionParser/Clang/ASTDumper.h +++ b/source/Plugins/ExpressionParser/Clang/ASTDumper.h @@ -13,7 +13,7 @@ #include "clang/AST/DeclVisitor.h" #include "clang/AST/TypeVisitor.h" -#include "lldb/Core/Stream.h" +#include "lldb/Utility/Stream.h" #include "llvm/ADT/DenseSet.h" namespace lldb_private { diff --git a/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp b/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp index f60587ed2fff..9e6a2f3acafe 100644 --- a/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp +++ b/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp @@ -11,11 +11,11 @@ #include "ClangPersistentVariables.h" -#include "lldb/Core/Log.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/ClangASTImporter.h" #include "lldb/Target/Target.h" #include "lldb/Utility/LLDBAssert.h" +#include "lldb/Utility/Log.h" #include "stdlib.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" diff --git a/source/Plugins/ExpressionParser/Clang/ASTStructExtractor.cpp b/source/Plugins/ExpressionParser/Clang/ASTStructExtractor.cpp index 7bb784e8f9ad..2faeecdf724e 100644 --- a/source/Plugins/ExpressionParser/Clang/ASTStructExtractor.cpp +++ b/source/Plugins/ExpressionParser/Clang/ASTStructExtractor.cpp @@ -9,7 +9,7 @@ #include "ASTStructExtractor.h" -#include "lldb/Core/Log.h" +#include "lldb/Utility/Log.h" #include "stdlib.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" diff --git a/source/Plugins/ExpressionParser/Clang/CMakeLists.txt b/source/Plugins/ExpressionParser/Clang/CMakeLists.txt index 64559d20bb4e..a780e7d597b1 100644 --- a/source/Plugins/ExpressionParser/Clang/CMakeLists.txt +++ b/source/Plugins/ExpressionParser/Clang/CMakeLists.txt @@ -2,7 +2,7 @@ if(NOT LLDB_BUILT_STANDALONE) set(tablegen_deps intrinsics_gen) endif() -add_lldb_library(lldbPluginExpressionParserClang +add_lldb_library(lldbPluginExpressionParserClang PLUGIN ASTDumper.cpp ASTResultSynthesizer.cpp ASTStructExtractor.cpp @@ -19,4 +19,30 @@ add_lldb_library(lldbPluginExpressionParserClang DEPENDS ${tablegen_deps} + + LINK_LIBS + clangAST + clangCodeGen + clangEdit + clangFrontend + clangLex + clangParse + clangRewrite + clangRewriteFrontend + clangSema + clangSerialization + lldbCore + lldbExpression + lldbHost + lldbInterpreter + lldbSymbol + lldbTarget + lldbUtility + lldbPluginCPlusPlusLanguage + LINK_COMPONENTS + Core + ExecutionEngine + ipo + MCJIT + Support ) diff --git a/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp index 0f08dd330e90..3c3a2cd9c3fc 100644 --- a/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp +++ b/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp @@ -12,7 +12,6 @@ #include "ASTDumper.h" #include "ClangModulesDeclVendor.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" #include "lldb/Symbol/ClangASTContext.h" @@ -24,6 +23,7 @@ #include "lldb/Symbol/TaggedASTType.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/Log.h" #include "clang/AST/ASTContext.h" #include "clang/AST/RecordLayout.h" @@ -139,6 +139,7 @@ bool ClangASTSource::FindExternalVisibleDeclsByName( case DeclarationName::CXXConstructorName: case DeclarationName::CXXDestructorName: case DeclarationName::CXXConversionFunctionName: + case DeclarationName::CXXDeductionGuideName: SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); return false; } diff --git a/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp index c1470c5aeb28..70c77e9cde33 100644 --- a/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -15,15 +15,12 @@ #include "ClangPersistentVariables.h" #include "lldb/Core/Address.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/RegisterValue.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/Core/ValueObjectVariable.h" #include "lldb/Expression/Materializer.h" -#include "lldb/Host/Endian.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/CompilerDecl.h" @@ -45,6 +42,9 @@ #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" #include "lldb/lldb-private.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" diff --git a/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp index a75e60ff63c1..6c923ced1ec2 100644 --- a/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp +++ b/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp @@ -35,7 +35,6 @@ #include "clang/Rewrite/Core/Rewriter.h" #include "clang/Rewrite/Frontend/FrontendActions.h" #include "clang/Sema/SemaConsumer.h" -#include "clang/StaticAnalyzer/Frontend/FrontendActions.h" #include "llvm/ADT/StringRef.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" @@ -68,15 +67,10 @@ #include "IRForTarget.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/Disassembler.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/StreamFile.h" -#include "lldb/Core/StreamString.h" -#include "lldb/Core/StringList.h" #include "lldb/Expression/IRDynamicChecks.h" #include "lldb/Expression/IRExecutionUnit.h" #include "lldb/Expression/IRInterpreter.h" @@ -90,7 +84,12 @@ #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" #include "lldb/Target/ThreadPlanCallFunction.h" +#include "lldb/Utility/DataBufferHeap.h" #include "lldb/Utility/LLDBAssert.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/Stream.h" +#include "lldb/Utility/StreamString.h" +#include "lldb/Utility/StringList.h" using namespace clang; using namespace llvm; @@ -340,16 +339,16 @@ ClangExpressionParser::ClangExpressionParser(ExecutionContextScope *exe_scope, lang_rt->GetOverrideExprOptions(m_compiler->getTargetOpts()); if (overridden_target_opts) - if (log) { - log->Debug( - "Using overridden target options for the expression evaluation"); + if (log && log->GetVerbose()) { + LLDB_LOGV( + log, "Using overridden target options for the expression evaluation"); auto opts = m_compiler->getTargetOpts(); - log->Debug("Triple: '%s'", opts.Triple.c_str()); - log->Debug("CPU: '%s'", opts.CPU.c_str()); - log->Debug("FPMath: '%s'", opts.FPMath.c_str()); - log->Debug("ABI: '%s'", opts.ABI.c_str()); - log->Debug("LinkerVersion: '%s'", opts.LinkerVersion.c_str()); + LLDB_LOGV(log, "Triple: '{0}'", opts.Triple); + LLDB_LOGV(log, "CPU: '{0}'", opts.CPU); + LLDB_LOGV(log, "FPMath: '{0}'", opts.FPMath); + LLDB_LOGV(log, "ABI: '{0}'", opts.ABI); + LLDB_LOGV(log, "LinkerVersion: '{0}'", opts.LinkerVersion); StringList::LogDump(log, opts.FeaturesAsWritten, "FeaturesAsWritten"); StringList::LogDump(log, opts.Features, "Features"); StringList::LogDump(log, opts.Reciprocals, "Reciprocals"); diff --git a/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h b/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h index 3f01156c6ded..f0203f36e59b 100644 --- a/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h +++ b/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h @@ -12,9 +12,9 @@ #include "lldb/Core/ArchSpec.h" #include "lldb/Core/ClangForward.h" -#include "lldb/Core/Error.h" #include "lldb/Expression/DiagnosticManager.h" #include "lldb/Expression/ExpressionParser.h" +#include "lldb/Utility/Error.h" #include "lldb/lldb-public.h" #include <string> diff --git a/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp b/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp index 44594ccebfa3..624cbf2a1a4f 100644 --- a/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp +++ b/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp @@ -9,13 +9,13 @@ #include "ClangExpressionVariable.h" -#include "lldb/Core/ConstString.h" -#include "lldb/Core/DataExtractor.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/Value.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Process.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Stream.h" #include "clang/AST/ASTContext.h" using namespace lldb_private; diff --git a/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h b/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h index c894506a227b..baa80d7ba0d4 100644 --- a/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h +++ b/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h @@ -25,10 +25,10 @@ // Project includes #include "lldb/Core/ClangForward.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/Value.h" #include "lldb/Expression/ExpressionVariable.h" #include "lldb/Symbol/TaggedASTType.h" +#include "lldb/Utility/ConstString.h" #include "lldb/lldb-public.h" namespace llvm { diff --git a/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp b/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp index 8151993717de..a26ceda82d5f 100644 --- a/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp +++ b/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp @@ -26,8 +26,6 @@ #include "llvm/IR/Module.h" // Project includes -#include "lldb/Core/DataExtractor.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/State.h" #include "lldb/Core/ValueObject.h" @@ -44,6 +42,8 @@ #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadPlan.h" #include "lldb/Target/ThreadPlanCallFunction.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Log.h" using namespace lldb_private; diff --git a/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp b/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp index 64b303c4f735..696bdf7e030d 100644 --- a/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp +++ b/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp @@ -20,19 +20,21 @@ #include "clang/Parse/Parser.h" #include "clang/Sema/Lookup.h" #include "clang/Serialization/ASTReader.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" +#include "llvm/Support/Threading.h" // Project includes #include "ClangModulesDeclVendor.h" -#include "lldb/Core/Log.h" -#include "lldb/Core/StreamString.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/FileSpec.h" #include "lldb/Utility/LLDBAssert.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" using namespace lldb_private; @@ -143,9 +145,9 @@ void StoringDiagnosticConsumer::DumpDiagnostics(Stream &error_stream) { static FileSpec GetResourceDir() { static FileSpec g_cached_resource_dir; - static std::once_flag g_once_flag; + static llvm::once_flag g_once_flag; - std::call_once(g_once_flag, []() { + llvm::call_once(g_once_flag, []() { HostInfo::GetLLDBPath(lldb::ePathTypeClangDir, g_cached_resource_dir); }); @@ -605,7 +607,7 @@ ClangModulesDeclVendor::Create(Target &target) { { FileSpec clang_resource_dir = GetResourceDir(); - if (clang_resource_dir.IsDirectory()) { + if (llvm::sys::fs::is_directory(clang_resource_dir.GetPath())) { compiler_invocation_arguments.push_back("-resource-dir"); compiler_invocation_arguments.push_back(clang_resource_dir.GetPath()); } diff --git a/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp b/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp index 4d30956177da..8ebf78409a03 100644 --- a/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp +++ b/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp @@ -9,10 +9,10 @@ #include "ClangPersistentVariables.h" -#include "lldb/Core/DataExtractor.h" -#include "lldb/Core/Log.h" -#include "lldb/Core/StreamString.h" #include "lldb/Core/Value.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" #include "clang/AST/Decl.h" diff --git a/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp index 5abad71b84a7..95d81db12801 100644 --- a/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp +++ b/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp @@ -25,12 +25,9 @@ #include "ClangModulesDeclVendor.h" #include "ClangPersistentVariables.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/StreamFile.h" -#include "lldb/Core/StreamString.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/Expression/ExpressionSourceCode.h" #include "lldb/Expression/IRExecutionUnit.h" @@ -51,6 +48,9 @@ #include "lldb/Target/Target.h" #include "lldb/Target/ThreadPlan.h" #include "lldb/Target/ThreadPlanCallUserExpression.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" @@ -609,7 +609,7 @@ bool ClangUserExpression::AddArguments(ExecutionContext &exe_ctx, if (!object_ptr_error.Success()) { exe_ctx.GetTargetRef().GetDebugger().GetAsyncOutputStream()->Printf( - "warning: `%s' is not accessible (subsituting 0)\n", + "warning: `%s' is not accessible (substituting 0)\n", object_name.AsCString()); object_ptr = 0; } diff --git a/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp b/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp index 73d37516ff77..a54ab4a2267a 100644 --- a/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp +++ b/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp @@ -19,16 +19,16 @@ // C++ Includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/StreamFile.h" #include "lldb/Expression/ExpressionSourceCode.h" #include "lldb/Expression/IRExecutionUnit.h" #include "lldb/Host/Host.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/Stream.h" using namespace lldb_private; diff --git a/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp b/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp index 356e2e7eba24..68a214ee4683 100644 --- a/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp +++ b/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp @@ -25,18 +25,18 @@ #include "clang/AST/ASTContext.h" -#include "lldb/Core/ConstString.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Scalar.h" -#include "lldb/Core/StreamString.h" #include "lldb/Core/dwarf.h" #include "lldb/Expression/IRExecutionUnit.h" #include "lldb/Expression/IRInterpreter.h" -#include "lldb/Host/Endian.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/ClangUtil.h" #include "lldb/Symbol/CompilerType.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" #include <map> @@ -512,11 +512,9 @@ bool IRForTarget::RewriteObjCConstString(llvm::GlobalVariable *ns_str, break; default: encoding_flags = 0x0600; /* fall back to 0x0600, kCFStringEncodingASCII */ - if (log) { - log->Format("Encountered an Objective-C constant string with unusual " + LLDB_LOG(log, "Encountered an Objective-C constant string with unusual " "element size {0}", - string_array->getElementByteSize()); - } + string_array->getElementByteSize()); } Constant *encoding_arg = ConstantInt::get(i32_ty, encoding_flags, false); Constant *isExternal_arg = @@ -1855,9 +1853,9 @@ bool IRForTarget::ReplaceVariables(Function &llvm_function) { if (!m_decl_map->GetStructInfo(num_elements, size, alignment)) return false; - Function::arg_iterator iter(llvm_function.getArgumentList().begin()); + Function::arg_iterator iter(llvm_function.arg_begin()); - if (iter == llvm_function.getArgumentList().end()) { + if (iter == llvm_function.arg_end()) { m_error_stream.Printf("Internal error [IRForTarget]: Wrapper takes no " "arguments (should take at least a struct pointer)"); @@ -1869,7 +1867,7 @@ bool IRForTarget::ReplaceVariables(Function &llvm_function) { if (argument->getName().equals("this")) { ++iter; - if (iter == llvm_function.getArgumentList().end()) { + if (iter == llvm_function.arg_end()) { m_error_stream.Printf("Internal error [IRForTarget]: Wrapper takes only " "'this' argument (should take a struct pointer " "too)"); @@ -1881,7 +1879,7 @@ bool IRForTarget::ReplaceVariables(Function &llvm_function) { } else if (argument->getName().equals("self")) { ++iter; - if (iter == llvm_function.getArgumentList().end()) { + if (iter == llvm_function.arg_end()) { m_error_stream.Printf("Internal error [IRForTarget]: Wrapper takes only " "'self' argument (should take '_cmd' and a struct " "pointer too)"); @@ -1899,7 +1897,7 @@ bool IRForTarget::ReplaceVariables(Function &llvm_function) { ++iter; - if (iter == llvm_function.getArgumentList().end()) { + if (iter == llvm_function.arg_end()) { m_error_stream.Printf("Internal error [IRForTarget]: Wrapper takes only " "'self' and '_cmd' arguments (should take a struct " "pointer too)"); diff --git a/source/Plugins/ExpressionParser/Clang/IRForTarget.h b/source/Plugins/ExpressionParser/Clang/IRForTarget.h index 20b1d1a13226..eb52730f3a87 100644 --- a/source/Plugins/ExpressionParser/Clang/IRForTarget.h +++ b/source/Plugins/ExpressionParser/Clang/IRForTarget.h @@ -11,11 +11,11 @@ #ifndef liblldb_IRForTarget_h_ #define liblldb_IRForTarget_h_ -#include "lldb/Core/ConstString.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Stream.h" -#include "lldb/Core/StreamString.h" #include "lldb/Symbol/TaggedASTType.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Stream.h" +#include "lldb/Utility/StreamString.h" #include "lldb/lldb-public.h" #include "llvm/Pass.h" diff --git a/source/Plugins/ExpressionParser/Go/CMakeLists.txt b/source/Plugins/ExpressionParser/Go/CMakeLists.txt index f59f51e76489..3d552aafa0d7 100644 --- a/source/Plugins/ExpressionParser/Go/CMakeLists.txt +++ b/source/Plugins/ExpressionParser/Go/CMakeLists.txt @@ -1,5 +1,13 @@ -add_lldb_library(lldbPluginExpressionParserGo +add_lldb_library(lldbPluginExpressionParserGo PLUGIN GoLexer.cpp GoParser.cpp GoUserExpression.cpp + + LINK_LIBS + lldbCore + lldbExpression + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ExpressionParser/Go/GoParser.cpp b/source/Plugins/ExpressionParser/Go/GoParser.cpp index 327b9df43db3..0bae4a4574d9 100644 --- a/source/Plugins/ExpressionParser/Go/GoParser.cpp +++ b/source/Plugins/ExpressionParser/Go/GoParser.cpp @@ -12,7 +12,7 @@ #include "GoParser.h" #include "Plugins/ExpressionParser/Go/GoAST.h" -#include "lldb/Core/Error.h" +#include "lldb/Utility/Error.h" #include "llvm/ADT/SmallString.h" using namespace lldb_private; diff --git a/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp b/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp index a448da683e36..50d45a1ad1e7 100644 --- a/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp +++ b/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp @@ -26,14 +26,8 @@ // Project includes #include "GoUserExpression.h" -#include "lldb/Core/ConstString.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/DataEncoder.h" -#include "lldb/Core/DataExtractor.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/StreamFile.h" -#include "lldb/Core/StreamString.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/Core/ValueObjectRegister.h" #include "lldb/Expression/DiagnosticManager.h" @@ -49,6 +43,12 @@ #include "lldb/Target/Target.h" #include "lldb/Target/ThreadPlan.h" #include "lldb/Target/ThreadPlanCallUserExpression.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/DataEncoder.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" #include "lldb/lldb-private.h" #include "Plugins/ExpressionParser/Go/GoAST.h" diff --git a/source/Plugins/Instruction/ARM/CMakeLists.txt b/source/Plugins/Instruction/ARM/CMakeLists.txt index dc547a57306b..24f803db3d0e 100644 --- a/source/Plugins/Instruction/ARM/CMakeLists.txt +++ b/source/Plugins/Instruction/ARM/CMakeLists.txt @@ -1,4 +1,14 @@ -add_lldb_library(lldbPluginInstructionARM +add_lldb_library(lldbPluginInstructionARM PLUGIN EmulateInstructionARM.cpp EmulationStateARM.cpp + + LINK_LIBS + lldbCore + lldbHost + lldbInterpreter + lldbSymbol + lldbTarget + lldbPluginProcessUtility + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp b/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp index 99caca99074b..d0ef688f0773 100644 --- a/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp +++ b/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp @@ -13,13 +13,13 @@ #include "EmulationStateARM.h" #include "lldb/Core/Address.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/Stream.h" #include "lldb/Host/PosixApi.h" #include "lldb/Interpreter/OptionValueArray.h" #include "lldb/Interpreter/OptionValueDictionary.h" #include "lldb/Symbol/UnwindPlan.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Stream.h" #include "Plugins/Process/Utility/ARMDefines.h" #include "Plugins/Process/Utility/ARMUtils.h" @@ -44,6 +44,563 @@ using namespace lldb_private; // //---------------------------------------------------------------------- +static bool GetARMDWARFRegisterInfo(unsigned reg_num, RegisterInfo ®_info) { + ::memset(®_info, 0, sizeof(RegisterInfo)); + ::memset(reg_info.kinds, LLDB_INVALID_REGNUM, sizeof(reg_info.kinds)); + + if (reg_num >= dwarf_q0 && reg_num <= dwarf_q15) { + reg_info.byte_size = 16; + reg_info.format = eFormatVectorOfUInt8; + reg_info.encoding = eEncodingVector; + } + + if (reg_num >= dwarf_d0 && reg_num <= dwarf_d31) { + reg_info.byte_size = 8; + reg_info.format = eFormatFloat; + reg_info.encoding = eEncodingIEEE754; + } else if (reg_num >= dwarf_s0 && reg_num <= dwarf_s31) { + reg_info.byte_size = 4; + reg_info.format = eFormatFloat; + reg_info.encoding = eEncodingIEEE754; + } else if (reg_num >= dwarf_f0 && reg_num <= dwarf_f7) { + reg_info.byte_size = 12; + reg_info.format = eFormatFloat; + reg_info.encoding = eEncodingIEEE754; + } else { + reg_info.byte_size = 4; + reg_info.format = eFormatHex; + reg_info.encoding = eEncodingUint; + } + + reg_info.kinds[eRegisterKindDWARF] = reg_num; + + switch (reg_num) { + case dwarf_r0: + reg_info.name = "r0"; + break; + case dwarf_r1: + reg_info.name = "r1"; + break; + case dwarf_r2: + reg_info.name = "r2"; + break; + case dwarf_r3: + reg_info.name = "r3"; + break; + case dwarf_r4: + reg_info.name = "r4"; + break; + case dwarf_r5: + reg_info.name = "r5"; + break; + case dwarf_r6: + reg_info.name = "r6"; + break; + case dwarf_r7: + reg_info.name = "r7"; + reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_FP; + break; + case dwarf_r8: + reg_info.name = "r8"; + break; + case dwarf_r9: + reg_info.name = "r9"; + break; + case dwarf_r10: + reg_info.name = "r10"; + break; + case dwarf_r11: + reg_info.name = "r11"; + break; + case dwarf_r12: + reg_info.name = "r12"; + break; + case dwarf_sp: + reg_info.name = "sp"; + reg_info.alt_name = "r13"; + reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_SP; + break; + case dwarf_lr: + reg_info.name = "lr"; + reg_info.alt_name = "r14"; + reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_RA; + break; + case dwarf_pc: + reg_info.name = "pc"; + reg_info.alt_name = "r15"; + reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_PC; + break; + case dwarf_cpsr: + reg_info.name = "cpsr"; + reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_FLAGS; + break; + + case dwarf_s0: + reg_info.name = "s0"; + break; + case dwarf_s1: + reg_info.name = "s1"; + break; + case dwarf_s2: + reg_info.name = "s2"; + break; + case dwarf_s3: + reg_info.name = "s3"; + break; + case dwarf_s4: + reg_info.name = "s4"; + break; + case dwarf_s5: + reg_info.name = "s5"; + break; + case dwarf_s6: + reg_info.name = "s6"; + break; + case dwarf_s7: + reg_info.name = "s7"; + break; + case dwarf_s8: + reg_info.name = "s8"; + break; + case dwarf_s9: + reg_info.name = "s9"; + break; + case dwarf_s10: + reg_info.name = "s10"; + break; + case dwarf_s11: + reg_info.name = "s11"; + break; + case dwarf_s12: + reg_info.name = "s12"; + break; + case dwarf_s13: + reg_info.name = "s13"; + break; + case dwarf_s14: + reg_info.name = "s14"; + break; + case dwarf_s15: + reg_info.name = "s15"; + break; + case dwarf_s16: + reg_info.name = "s16"; + break; + case dwarf_s17: + reg_info.name = "s17"; + break; + case dwarf_s18: + reg_info.name = "s18"; + break; + case dwarf_s19: + reg_info.name = "s19"; + break; + case dwarf_s20: + reg_info.name = "s20"; + break; + case dwarf_s21: + reg_info.name = "s21"; + break; + case dwarf_s22: + reg_info.name = "s22"; + break; + case dwarf_s23: + reg_info.name = "s23"; + break; + case dwarf_s24: + reg_info.name = "s24"; + break; + case dwarf_s25: + reg_info.name = "s25"; + break; + case dwarf_s26: + reg_info.name = "s26"; + break; + case dwarf_s27: + reg_info.name = "s27"; + break; + case dwarf_s28: + reg_info.name = "s28"; + break; + case dwarf_s29: + reg_info.name = "s29"; + break; + case dwarf_s30: + reg_info.name = "s30"; + break; + case dwarf_s31: + reg_info.name = "s31"; + break; + + // FPA Registers 0-7 + case dwarf_f0: + reg_info.name = "f0"; + break; + case dwarf_f1: + reg_info.name = "f1"; + break; + case dwarf_f2: + reg_info.name = "f2"; + break; + case dwarf_f3: + reg_info.name = "f3"; + break; + case dwarf_f4: + reg_info.name = "f4"; + break; + case dwarf_f5: + reg_info.name = "f5"; + break; + case dwarf_f6: + reg_info.name = "f6"; + break; + case dwarf_f7: + reg_info.name = "f7"; + break; + + // Intel wireless MMX general purpose registers 0 - 7 + // XScale accumulator register 0 - 7 (they do overlap with wCGR0 - wCGR7) + case dwarf_wCGR0: + reg_info.name = "wCGR0/ACC0"; + break; + case dwarf_wCGR1: + reg_info.name = "wCGR1/ACC1"; + break; + case dwarf_wCGR2: + reg_info.name = "wCGR2/ACC2"; + break; + case dwarf_wCGR3: + reg_info.name = "wCGR3/ACC3"; + break; + case dwarf_wCGR4: + reg_info.name = "wCGR4/ACC4"; + break; + case dwarf_wCGR5: + reg_info.name = "wCGR5/ACC5"; + break; + case dwarf_wCGR6: + reg_info.name = "wCGR6/ACC6"; + break; + case dwarf_wCGR7: + reg_info.name = "wCGR7/ACC7"; + break; + + // Intel wireless MMX data registers 0 - 15 + case dwarf_wR0: + reg_info.name = "wR0"; + break; + case dwarf_wR1: + reg_info.name = "wR1"; + break; + case dwarf_wR2: + reg_info.name = "wR2"; + break; + case dwarf_wR3: + reg_info.name = "wR3"; + break; + case dwarf_wR4: + reg_info.name = "wR4"; + break; + case dwarf_wR5: + reg_info.name = "wR5"; + break; + case dwarf_wR6: + reg_info.name = "wR6"; + break; + case dwarf_wR7: + reg_info.name = "wR7"; + break; + case dwarf_wR8: + reg_info.name = "wR8"; + break; + case dwarf_wR9: + reg_info.name = "wR9"; + break; + case dwarf_wR10: + reg_info.name = "wR10"; + break; + case dwarf_wR11: + reg_info.name = "wR11"; + break; + case dwarf_wR12: + reg_info.name = "wR12"; + break; + case dwarf_wR13: + reg_info.name = "wR13"; + break; + case dwarf_wR14: + reg_info.name = "wR14"; + break; + case dwarf_wR15: + reg_info.name = "wR15"; + break; + + case dwarf_spsr: + reg_info.name = "spsr"; + break; + case dwarf_spsr_fiq: + reg_info.name = "spsr_fiq"; + break; + case dwarf_spsr_irq: + reg_info.name = "spsr_irq"; + break; + case dwarf_spsr_abt: + reg_info.name = "spsr_abt"; + break; + case dwarf_spsr_und: + reg_info.name = "spsr_und"; + break; + case dwarf_spsr_svc: + reg_info.name = "spsr_svc"; + break; + + case dwarf_r8_usr: + reg_info.name = "r8_usr"; + break; + case dwarf_r9_usr: + reg_info.name = "r9_usr"; + break; + case dwarf_r10_usr: + reg_info.name = "r10_usr"; + break; + case dwarf_r11_usr: + reg_info.name = "r11_usr"; + break; + case dwarf_r12_usr: + reg_info.name = "r12_usr"; + break; + case dwarf_r13_usr: + reg_info.name = "r13_usr"; + break; + case dwarf_r14_usr: + reg_info.name = "r14_usr"; + break; + case dwarf_r8_fiq: + reg_info.name = "r8_fiq"; + break; + case dwarf_r9_fiq: + reg_info.name = "r9_fiq"; + break; + case dwarf_r10_fiq: + reg_info.name = "r10_fiq"; + break; + case dwarf_r11_fiq: + reg_info.name = "r11_fiq"; + break; + case dwarf_r12_fiq: + reg_info.name = "r12_fiq"; + break; + case dwarf_r13_fiq: + reg_info.name = "r13_fiq"; + break; + case dwarf_r14_fiq: + reg_info.name = "r14_fiq"; + break; + case dwarf_r13_irq: + reg_info.name = "r13_irq"; + break; + case dwarf_r14_irq: + reg_info.name = "r14_irq"; + break; + case dwarf_r13_abt: + reg_info.name = "r13_abt"; + break; + case dwarf_r14_abt: + reg_info.name = "r14_abt"; + break; + case dwarf_r13_und: + reg_info.name = "r13_und"; + break; + case dwarf_r14_und: + reg_info.name = "r14_und"; + break; + case dwarf_r13_svc: + reg_info.name = "r13_svc"; + break; + case dwarf_r14_svc: + reg_info.name = "r14_svc"; + break; + + // Intel wireless MMX control register in co-processor 0 - 7 + case dwarf_wC0: + reg_info.name = "wC0"; + break; + case dwarf_wC1: + reg_info.name = "wC1"; + break; + case dwarf_wC2: + reg_info.name = "wC2"; + break; + case dwarf_wC3: + reg_info.name = "wC3"; + break; + case dwarf_wC4: + reg_info.name = "wC4"; + break; + case dwarf_wC5: + reg_info.name = "wC5"; + break; + case dwarf_wC6: + reg_info.name = "wC6"; + break; + case dwarf_wC7: + reg_info.name = "wC7"; + break; + + // VFP-v3/Neon + case dwarf_d0: + reg_info.name = "d0"; + break; + case dwarf_d1: + reg_info.name = "d1"; + break; + case dwarf_d2: + reg_info.name = "d2"; + break; + case dwarf_d3: + reg_info.name = "d3"; + break; + case dwarf_d4: + reg_info.name = "d4"; + break; + case dwarf_d5: + reg_info.name = "d5"; + break; + case dwarf_d6: + reg_info.name = "d6"; + break; + case dwarf_d7: + reg_info.name = "d7"; + break; + case dwarf_d8: + reg_info.name = "d8"; + break; + case dwarf_d9: + reg_info.name = "d9"; + break; + case dwarf_d10: + reg_info.name = "d10"; + break; + case dwarf_d11: + reg_info.name = "d11"; + break; + case dwarf_d12: + reg_info.name = "d12"; + break; + case dwarf_d13: + reg_info.name = "d13"; + break; + case dwarf_d14: + reg_info.name = "d14"; + break; + case dwarf_d15: + reg_info.name = "d15"; + break; + case dwarf_d16: + reg_info.name = "d16"; + break; + case dwarf_d17: + reg_info.name = "d17"; + break; + case dwarf_d18: + reg_info.name = "d18"; + break; + case dwarf_d19: + reg_info.name = "d19"; + break; + case dwarf_d20: + reg_info.name = "d20"; + break; + case dwarf_d21: + reg_info.name = "d21"; + break; + case dwarf_d22: + reg_info.name = "d22"; + break; + case dwarf_d23: + reg_info.name = "d23"; + break; + case dwarf_d24: + reg_info.name = "d24"; + break; + case dwarf_d25: + reg_info.name = "d25"; + break; + case dwarf_d26: + reg_info.name = "d26"; + break; + case dwarf_d27: + reg_info.name = "d27"; + break; + case dwarf_d28: + reg_info.name = "d28"; + break; + case dwarf_d29: + reg_info.name = "d29"; + break; + case dwarf_d30: + reg_info.name = "d30"; + break; + case dwarf_d31: + reg_info.name = "d31"; + break; + + // NEON 128-bit vector registers (overlays the d registers) + case dwarf_q0: + reg_info.name = "q0"; + break; + case dwarf_q1: + reg_info.name = "q1"; + break; + case dwarf_q2: + reg_info.name = "q2"; + break; + case dwarf_q3: + reg_info.name = "q3"; + break; + case dwarf_q4: + reg_info.name = "q4"; + break; + case dwarf_q5: + reg_info.name = "q5"; + break; + case dwarf_q6: + reg_info.name = "q6"; + break; + case dwarf_q7: + reg_info.name = "q7"; + break; + case dwarf_q8: + reg_info.name = "q8"; + break; + case dwarf_q9: + reg_info.name = "q9"; + break; + case dwarf_q10: + reg_info.name = "q10"; + break; + case dwarf_q11: + reg_info.name = "q11"; + break; + case dwarf_q12: + reg_info.name = "q12"; + break; + case dwarf_q13: + reg_info.name = "q13"; + break; + case dwarf_q14: + reg_info.name = "q14"; + break; + case dwarf_q15: + reg_info.name = "q15"; + break; + + default: + return false; + } + return true; +} + // A8.6.50 // Valid return values are {1, 2, 3, 4}, with 0 signifying an error condition. static uint32_t CountITSize(uint32_t ITMask) { diff --git a/source/Plugins/Instruction/ARM/EmulateInstructionARM.h b/source/Plugins/Instruction/ARM/EmulateInstructionARM.h index 1bfc4cb398fb..40a31169ecd8 100644 --- a/source/Plugins/Instruction/ARM/EmulateInstructionARM.h +++ b/source/Plugins/Instruction/ARM/EmulateInstructionARM.h @@ -11,9 +11,9 @@ #define lldb_EmulateInstructionARM_h_ #include "Plugins/Process/Utility/ARMDefines.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/EmulateInstruction.h" -#include "lldb/Core/Error.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Error.h" namespace lldb_private { diff --git a/source/Plugins/Instruction/ARM/EmulationStateARM.cpp b/source/Plugins/Instruction/ARM/EmulationStateARM.cpp index 9ceeb76c6f5e..5e90965c1881 100644 --- a/source/Plugins/Instruction/ARM/EmulationStateARM.cpp +++ b/source/Plugins/Instruction/ARM/EmulationStateARM.cpp @@ -66,7 +66,7 @@ bool EmulationStateARM::LoadPseudoRegistersFromFrame(StackFrame &frame) { bool EmulationStateARM::StorePseudoRegisterValue(uint32_t reg_num, uint64_t value) { - if ((dwarf_r0 <= reg_num) && (reg_num <= dwarf_cpsr)) + if (reg_num <= dwarf_cpsr) m_gpr[reg_num - dwarf_r0] = (uint32_t)value; else if ((dwarf_s0 <= reg_num) && (reg_num <= dwarf_s31)) { uint32_t idx = reg_num - dwarf_s0; @@ -89,7 +89,7 @@ uint64_t EmulationStateARM::ReadPseudoRegisterValue(uint32_t reg_num, uint64_t value = 0; success = true; - if ((dwarf_r0 <= reg_num) && (reg_num <= dwarf_cpsr)) + if (reg_num <= dwarf_cpsr) value = m_gpr[reg_num - dwarf_r0]; else if ((dwarf_s0 <= reg_num) && (reg_num <= dwarf_s31)) { uint32_t idx = reg_num - dwarf_s0; @@ -192,15 +192,18 @@ size_t EmulationStateARM::WritePseudoMemory( EmulationStateARM *pseudo_state = (EmulationStateARM *)baton; if (length <= 4) { - uint32_t value = *((const uint32_t *)dst); + uint32_t value; + memcpy (&value, dst, sizeof (uint32_t)); if (endian::InlHostByteOrder() == lldb::eByteOrderBig) value = llvm::ByteSwap_32(value); pseudo_state->StoreToPseudoAddress(addr, value); return length; } else if (length == 8) { - uint32_t value1 = ((const uint32_t *)dst)[0]; - uint32_t value2 = ((const uint32_t *)dst)[1]; + uint32_t value1; + uint32_t value2; + memcpy (&value1, dst, sizeof (uint32_t)); + memcpy (&value2, (uint8_t *) dst + sizeof (uint32_t), sizeof (uint32_t)); if (endian::InlHostByteOrder() == lldb::eByteOrderBig) { value1 = llvm::ByteSwap_32(value1); value2 = llvm::ByteSwap_32(value2); diff --git a/source/Plugins/Instruction/ARM64/CMakeLists.txt b/source/Plugins/Instruction/ARM64/CMakeLists.txt index 9f8ee0848984..effe0e3bfe66 100644 --- a/source/Plugins/Instruction/ARM64/CMakeLists.txt +++ b/source/Plugins/Instruction/ARM64/CMakeLists.txt @@ -1,3 +1,11 @@ -add_lldb_library(lldbPluginInstructionARM64 +add_lldb_library(lldbPluginInstructionARM64 PLUGIN EmulateInstructionARM64.cpp + + LINK_LIBS + lldbCore + lldbInterpreter + lldbSymbol + lldbPluginProcessUtility + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp b/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp index 43f23097c0d9..655fada3a4b3 100644 --- a/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp +++ b/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp @@ -13,10 +13,11 @@ #include "lldb/Core/Address.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/Stream.h" +#include "lldb/Core/RegisterValue.h" #include "lldb/Symbol/UnwindPlan.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Stream.h" #include "Plugins/Process/Utility/ARMDefines.h" #include "Plugins/Process/Utility/ARMUtils.h" diff --git a/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.h b/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.h index 1da330497b33..475410ab2d13 100644 --- a/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.h +++ b/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.h @@ -16,8 +16,8 @@ // Project includes #include "Plugins/Process/Utility/ARMDefines.h" #include "lldb/Core/EmulateInstruction.h" -#include "lldb/Core/Error.h" #include "lldb/Interpreter/OptionValue.h" +#include "lldb/Utility/Error.h" class EmulateInstructionARM64 : public lldb_private::EmulateInstruction { public: diff --git a/source/Plugins/Instruction/MIPS/CMakeLists.txt b/source/Plugins/Instruction/MIPS/CMakeLists.txt index dc6707336939..b2fe0ee8813f 100644 --- a/source/Plugins/Instruction/MIPS/CMakeLists.txt +++ b/source/Plugins/Instruction/MIPS/CMakeLists.txt @@ -1,3 +1,18 @@ -add_lldb_library(lldbPluginInstructionMIPS +if(Mips IN_LIST LLVM_TARGETS_TO_BUILD) + set(mips_target Mips) +endif() + +add_lldb_library(lldbPluginInstructionMIPS PLUGIN EmulateInstructionMIPS.cpp + + LINK_LIBS + lldbCore + lldbInterpreter + lldbSymbol + lldbTarget + lldbPluginProcessUtility + LINK_COMPONENTS + MC + Support + ${mips_target} ) diff --git a/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp b/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp index 8cc34c171c72..aa7c6e5d1fe0 100644 --- a/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp +++ b/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp @@ -1,5 +1,4 @@ -//===-- EmulateInstructionMIPS.cpp -------------------------------*- C++ -//-*-===// +//===-- EmulateInstructionMIPS.cpp -------------------------------*- C++-*-===// // // The LLVM Compiler Infrastructure // @@ -14,13 +13,14 @@ #include "lldb/Core/Address.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/ConstString.h" -#include "lldb/Core/DataExtractor.h" #include "lldb/Core/Opcode.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/Stream.h" +#include "lldb/Core/RegisterValue.h" #include "lldb/Symbol/UnwindPlan.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Stream.h" #include "llvm-c/Disassembler.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" diff --git a/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.h b/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.h index 82c6a0a31e81..0375056f87c7 100644 --- a/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.h +++ b/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.h @@ -22,8 +22,8 @@ class MCInst; } #include "lldb/Core/EmulateInstruction.h" -#include "lldb/Core/Error.h" #include "lldb/Interpreter/OptionValue.h" +#include "lldb/Utility/Error.h" class EmulateInstructionMIPS : public lldb_private::EmulateInstruction { public: diff --git a/source/Plugins/Instruction/MIPS64/CMakeLists.txt b/source/Plugins/Instruction/MIPS64/CMakeLists.txt index 25c919c4edb6..ddb964bf50a5 100644 --- a/source/Plugins/Instruction/MIPS64/CMakeLists.txt +++ b/source/Plugins/Instruction/MIPS64/CMakeLists.txt @@ -1,3 +1,18 @@ -add_lldb_library(lldbPluginInstructionMIPS64 +if(Mips IN_LIST LLVM_TARGETS_TO_BUILD) + set(mips_target Mips) +endif() + +add_lldb_library(lldbPluginInstructionMIPS64 PLUGIN EmulateInstructionMIPS64.cpp + + LINK_LIBS + lldbCore + lldbHost + lldbInterpreter + lldbSymbol + lldbPluginProcessUtility + LINK_COMPONENTS + MC + Support + ${mips_target} ) diff --git a/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp b/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp index c054760be8a0..4c90a1901da7 100644 --- a/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp +++ b/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp @@ -1,5 +1,4 @@ -//===-- EmulateInstructionMIPS64.cpp -------------------------------*- C++ -//-*-===// +//===-- EmulateInstructionMIPS64.cpp -----------------------------*- C++-*-===// // // The LLVM Compiler Infrastructure // @@ -14,13 +13,14 @@ #include "lldb/Core/Address.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/ConstString.h" -#include "lldb/Core/DataExtractor.h" #include "lldb/Core/Opcode.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/Stream.h" +#include "lldb/Core/RegisterValue.h" #include "lldb/Host/PosixApi.h" #include "lldb/Symbol/UnwindPlan.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Stream.h" #include "llvm-c/Disassembler.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" diff --git a/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h b/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h index 5543615efade..1e5be516d130 100644 --- a/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h +++ b/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h @@ -15,8 +15,8 @@ // Other libraries and framework includes // Project includes #include "lldb/Core/EmulateInstruction.h" -#include "lldb/Core/Error.h" #include "lldb/Interpreter/OptionValue.h" +#include "lldb/Utility/Error.h" namespace llvm { class MCDisassembler; diff --git a/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp b/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp index db626b066152..96370528f260 100644 --- a/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp +++ b/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp @@ -14,8 +14,6 @@ #include "lldb/Core/Module.h" #include "lldb/Core/PluginInterface.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/RegularExpression.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/StreamFile.h" #include "lldb/Core/ValueObject.h" #include "lldb/Expression/UserExpression.h" @@ -25,6 +23,8 @@ #include "lldb/Target/StopInfo.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/RegularExpression.h" +#include "lldb/Utility/Stream.h" #include "llvm/ADT/StringSwitch.h" diff --git a/source/Plugins/InstrumentationRuntime/AddressSanitizer/CMakeLists.txt b/source/Plugins/InstrumentationRuntime/AddressSanitizer/CMakeLists.txt index 77e7d15caa7c..1adfc6ba5322 100644 --- a/source/Plugins/InstrumentationRuntime/AddressSanitizer/CMakeLists.txt +++ b/source/Plugins/InstrumentationRuntime/AddressSanitizer/CMakeLists.txt @@ -1,3 +1,13 @@ -add_lldb_library(lldbPluginInstrumentationRuntimeAddressSanitizer +add_lldb_library(lldbPluginInstrumentationRuntimeAddressSanitizer PLUGIN AddressSanitizerRuntime.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbExpression + lldbInterpreter + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/InstrumentationRuntime/ThreadSanitizer/CMakeLists.txt b/source/Plugins/InstrumentationRuntime/ThreadSanitizer/CMakeLists.txt index 6ef79433d67a..db7c4a2518a1 100644 --- a/source/Plugins/InstrumentationRuntime/ThreadSanitizer/CMakeLists.txt +++ b/source/Plugins/InstrumentationRuntime/ThreadSanitizer/CMakeLists.txt @@ -1,3 +1,12 @@ -add_lldb_library(lldbPluginInstrumentationRuntimeThreadSanitizer +add_lldb_library(lldbPluginInstrumentationRuntimeThreadSanitizer PLUGIN ThreadSanitizerRuntime.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbExpression + lldbInterpreter + lldbSymbol + lldbTarget + lldbPluginProcessUtility ) diff --git a/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp b/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp index d8a46e5d4550..cbc77ebe9987 100644 --- a/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp +++ b/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp @@ -15,8 +15,6 @@ #include "lldb/Core/Module.h" #include "lldb/Core/PluginInterface.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/RegularExpression.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/StreamFile.h" #include "lldb/Core/ValueObject.h" #include "lldb/Expression/UserExpression.h" @@ -30,6 +28,8 @@ #include "lldb/Target/StopInfo.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/RegularExpression.h" +#include "lldb/Utility/Stream.h" using namespace lldb; using namespace lldb_private; @@ -85,6 +85,10 @@ extern "C" int *running, const char **name, int *parent_tid, void **trace, unsigned long trace_size); int __tsan_get_report_unique_tid(void *report, unsigned long idx, int *tid); + + // TODO: dlsym won't work on Windows. + void *dlsym(void* handle, const char* symbol); + int (*ptr__tsan_get_report_loc_object_type)(void *report, unsigned long idx, const char **object_type); } const int REPORT_TRACE_SIZE = 128; @@ -125,6 +129,7 @@ struct data { int fd; int suppressable; void *trace[REPORT_TRACE_SIZE]; + const char *object_type; } locs[REPORT_ARRAY_SIZE]; int mutex_count; @@ -158,6 +163,8 @@ struct data { const char *thread_sanitizer_retrieve_report_data_command = R"( data t = {0}; +ptr__tsan_get_report_loc_object_type = (typeof(ptr__tsan_get_report_loc_object_type))(void *)dlsym((void*)-2 /*RTLD_DEFAULT*/, "__tsan_get_report_loc_object_type"); + t.report = __tsan_get_current_report(); __tsan_get_report_data(t.report, &t.description, &t.report_count, &t.stack_count, &t.mop_count, &t.loc_count, &t.mutex_count, &t.thread_count, &t.unique_tid_count, t.sleep_trace, REPORT_TRACE_SIZE); @@ -177,6 +184,8 @@ if (t.loc_count > REPORT_ARRAY_SIZE) t.loc_count = REPORT_ARRAY_SIZE; for (int i = 0; i < t.loc_count; i++) { t.locs[i].idx = i; __tsan_get_report_loc(t.report, i, &t.locs[i].type, &t.locs[i].addr, &t.locs[i].start, &t.locs[i].size, &t.locs[i].tid, &t.locs[i].fd, &t.locs[i].suppressable, t.locs[i].trace, REPORT_TRACE_SIZE); + if (ptr__tsan_get_report_loc_object_type) + ptr__tsan_get_report_loc_object_type(t.report, i, &t.locs[i].object_type); } if (t.mutex_count > REPORT_ARRAY_SIZE) t.mutex_count = REPORT_ARRAY_SIZE; @@ -409,6 +418,8 @@ ThreadSanitizerRuntime::RetrieveReportData(ExecutionContextRef exe_ctx_ref) { o->GetValueForExpressionPath(".suppressable") ->GetValueAsUnsigned(0)); dict->AddItem("trace", StructuredData::ObjectSP(CreateStackTrace(o))); + dict->AddStringItem("object_type", + RetrieveString(o, process_sp, ".object_type")); }); dict->AddItem("locs", StructuredData::ObjectSP(locs)); @@ -511,6 +522,10 @@ ThreadSanitizerRuntime::FormatDescription(StructuredData::ObjectSP report) { return "Overwrite of errno in a signal handler"; } else if (description == "lock-order-inversion") { return "Lock order inversion (potential deadlock)"; + } else if (description == "external-race") { + return "Race on a library object"; + } else if (description == "swift-access-race") { + return "Swift access race"; } // for unknown report codes just show the code @@ -568,27 +583,31 @@ static void GetSymbolDeclarationFromAddress(ProcessSP process_sp, addr_t addr, } addr_t ThreadSanitizerRuntime::GetFirstNonInternalFramePc( - StructuredData::ObjectSP trace) { + StructuredData::ObjectSP trace, bool skip_one_frame) { ProcessSP process_sp = GetProcessSP(); ModuleSP runtime_module_sp = GetRuntimeModuleSP(); - addr_t result = 0; - trace->GetAsArray()->ForEach([process_sp, runtime_module_sp, - &result](StructuredData::Object *o) -> bool { - addr_t addr = o->GetIntegerValue(); + StructuredData::Array *trace_array = trace->GetAsArray(); + for (int i = 0; i < trace_array->GetSize(); i++) { + if (skip_one_frame && i == 0) + continue; + + addr_t addr; + if (!trace_array->GetItemAtIndexAsInteger(i, addr)) + continue; + lldb_private::Address so_addr; if (!process_sp->GetTarget().GetSectionLoadList().ResolveLoadAddress( addr, so_addr)) - return true; + continue; if (so_addr.GetModule() == runtime_module_sp) - return true; + continue; - result = addr; - return false; - }); + return addr; + } - return result; + return 0; } std::string @@ -599,6 +618,10 @@ ThreadSanitizerRuntime::GenerateSummary(StructuredData::ObjectSP report) { ->GetValueForKey("description") ->GetAsString() ->GetValue(); + bool skip_one_frame = + report->GetObjectForDotSeparatedPath("issue_type")->GetStringValue() == + "external-race"; + addr_t pc = 0; if (report->GetAsDictionary() ->GetValueForKey("mops") @@ -609,7 +632,8 @@ ThreadSanitizerRuntime::GenerateSummary(StructuredData::ObjectSP report) { ->GetAsArray() ->GetItemAtIndex(0) ->GetAsDictionary() - ->GetValueForKey("trace")); + ->GetValueForKey("trace"), + skip_one_frame); if (report->GetAsDictionary() ->GetValueForKey("stacks") @@ -620,7 +644,8 @@ ThreadSanitizerRuntime::GenerateSummary(StructuredData::ObjectSP report) { ->GetAsArray() ->GetItemAtIndex(0) ->GetAsDictionary() - ->GetValueForKey("trace")); + ->GetValueForKey("trace"), + skip_one_frame); if (pc != 0) { summary = summary + " in " + GetSymbolNameFromAddress(process_sp, pc); @@ -634,6 +659,13 @@ ThreadSanitizerRuntime::GenerateSummary(StructuredData::ObjectSP report) { ->GetValueForKey("locs") ->GetAsArray() ->GetItemAtIndex(0); + std::string object_type = loc->GetAsDictionary() + ->GetValueForKey("object_type") + ->GetAsString() + ->GetValue(); + if (!object_type.empty()) { + summary = "Race on " + object_type + " object"; + } addr_t addr = loc->GetAsDictionary() ->GetValueForKey("address") ->GetAsInteger() @@ -726,8 +758,17 @@ std::string ThreadSanitizerRuntime::GetLocationDescription( ->GetValueForKey("size") ->GetAsInteger() ->GetValue(); - result = - Sprintf("Location is a %ld-byte heap object at 0x%llx", size, addr); + std::string object_type = loc->GetAsDictionary() + ->GetValueForKey("object_type") + ->GetAsString() + ->GetValue(); + if (!object_type.empty()) { + result = Sprintf("Location is a %ld-byte %s object at 0x%llx", size, + object_type.c_str(), addr); + } else { + result = + Sprintf("Location is a %ld-byte heap object at 0x%llx", size, addr); + } } else if (type == "stack") { int tid = loc->GetAsDictionary() ->GetValueForKey("thread_id") @@ -920,9 +961,18 @@ static std::string GenerateThreadName(const std::string &path, addr_string = ""; } - result = Sprintf("%s%s of size %d%s by thread %d", - is_atomic ? "atomic " : "", is_write ? "write" : "read", - size, addr_string.c_str(), thread_id); + if (main_info->GetObjectForDotSeparatedPath("issue_type") + ->GetStringValue() == "external-race") { + result = Sprintf("%s access by thread %d", + is_write ? "mutating" : "read-only", thread_id); + } else if (main_info->GetObjectForDotSeparatedPath("issue_type") + ->GetStringValue() == "swift-access-race") { + result = Sprintf("modifying access by thread %d", thread_id); + } else { + result = Sprintf("%s%s of size %d%s by thread %d", + is_atomic ? "atomic " : "", is_write ? "write" : "read", + size, addr_string.c_str(), thread_id); + } } if (path == "threads") { diff --git a/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.h b/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.h index 9b07ca64e32b..2a10582b65d2 100644 --- a/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.h +++ b/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.h @@ -77,7 +77,8 @@ private: std::string &global_name, std::string &filename, uint32_t &line); - lldb::addr_t GetFirstNonInternalFramePc(StructuredData::ObjectSP trace); + lldb::addr_t GetFirstNonInternalFramePc(StructuredData::ObjectSP trace, + bool skip_one_frame = false); }; } // namespace lldb_private diff --git a/source/Plugins/JITLoader/GDB/CMakeLists.txt b/source/Plugins/JITLoader/GDB/CMakeLists.txt index bcf714dca593..25e8d1ee231f 100644 --- a/source/Plugins/JITLoader/GDB/CMakeLists.txt +++ b/source/Plugins/JITLoader/GDB/CMakeLists.txt @@ -1,6 +1,16 @@ include_directories(.) -add_lldb_library(lldbPluginJITLoaderGDB +add_lldb_library(lldbPluginJITLoaderGDB PLUGIN JITLoaderGDB.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbInterpreter + lldbSymbol + lldbTarget + lldbUtility + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp b/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp index bbb445a1fbc4..b97d67a0bb42 100644 --- a/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp +++ b/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp @@ -12,20 +12,22 @@ #include "llvm/Support/MathExtras.h" #include "lldb/Breakpoint/Breakpoint.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Section.h" -#include "lldb/Core/StreamString.h" #include "lldb/Interpreter/OptionValueProperties.h" +#include "lldb/Symbol/ObjectFile.h" +#include "lldb/Symbol/Symbol.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Symbol/SymbolVendor.h" #include "lldb/Target/Process.h" #include "lldb/Target/SectionLoadList.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBufferHeap.h" #include "lldb/Utility/LLDBAssert.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" #include "JITLoaderGDB.h" diff --git a/source/Plugins/Language/CPlusPlus/CMakeLists.txt b/source/Plugins/Language/CPlusPlus/CMakeLists.txt index 5e105aa19b6b..8f769c499987 100644 --- a/source/Plugins/Language/CPlusPlus/CMakeLists.txt +++ b/source/Plugins/Language/CPlusPlus/CMakeLists.txt @@ -1,6 +1,7 @@ -add_lldb_library(lldbPluginCPlusPlusLanguage +add_lldb_library(lldbPluginCPlusPlusLanguage PLUGIN BlockPointer.cpp CPlusPlusLanguage.cpp + CPlusPlusNameParser.cpp CxxStringTypes.cpp LibCxx.cpp LibCxxAtomic.cpp @@ -12,4 +13,14 @@ add_lldb_library(lldbPluginCPlusPlusLanguage LibStdcpp.cpp LibStdcppTuple.cpp LibStdcppUniquePointer.cpp + + LINK_LIBS + lldbCore + lldbDataFormatters + lldbHost + lldbSymbol + lldbTarget + lldbUtility + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp index b5527edacd13..fe42a5ed9214 100644 --- a/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp +++ b/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp @@ -23,18 +23,19 @@ #include "llvm/ADT/StringRef.h" // Project includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/FastDemangle.h" -#include "lldb/Core/Log.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/RegularExpression.h" #include "lldb/Core/UniqueCStringMap.h" #include "lldb/DataFormatters/CXXFunctionPointer.h" #include "lldb/DataFormatters/DataVisualization.h" #include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/DataFormatters/VectorType.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/FastDemangle.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/RegularExpression.h" #include "BlockPointer.h" +#include "CPlusPlusNameParser.h" #include "CxxStringTypes.h" #include "LibCxx.h" #include "LibCxxAtomic.h" @@ -84,15 +85,14 @@ void CPlusPlusLanguage::MethodName::Clear() { m_context = llvm::StringRef(); m_arguments = llvm::StringRef(); m_qualifiers = llvm::StringRef(); - m_type = eTypeInvalid; m_parsed = false; m_parse_error = false; } -bool ReverseFindMatchingChars(const llvm::StringRef &s, - const llvm::StringRef &left_right_chars, - size_t &left_pos, size_t &right_pos, - size_t pos = llvm::StringRef::npos) { +static bool ReverseFindMatchingChars(const llvm::StringRef &s, + const llvm::StringRef &left_right_chars, + size_t &left_pos, size_t &right_pos, + size_t pos = llvm::StringRef::npos) { assert(left_right_chars.size() == 2); left_pos = llvm::StringRef::npos; const char left_char = left_right_chars[0]; @@ -118,10 +118,9 @@ bool ReverseFindMatchingChars(const llvm::StringRef &s, return false; } -static bool IsValidBasename(const llvm::StringRef &basename) { - // Check that the basename matches with the following regular expression or is - // an operator name: - // "^~?([A-Za-z_][A-Za-z_0-9]*)(<.*>)?$" +static bool IsTrivialBasename(const llvm::StringRef &basename) { + // Check that the basename matches with the following regular expression + // "^~?([A-Za-z_][A-Za-z_0-9]*)$" // We are using a hand written implementation because it is significantly more // efficient then // using the general purpose regular expression library. @@ -148,100 +147,69 @@ static bool IsValidBasename(const llvm::StringRef &basename) { if (idx == basename.size()) return true; - // Check for basename with template arguments - // TODO: Improve the quality of the validation with validating the template - // arguments - if (basename[idx] == '<' && basename.back() == '>') - return true; + return false; +} - // Check if the basename is a vaild C++ operator name - if (!basename.startswith("operator")) - return false; +bool CPlusPlusLanguage::MethodName::TrySimplifiedParse() { + // This method tries to parse simple method definitions + // which are presumably most comman in user programs. + // Definitions that can be parsed by this function don't have return types + // and templates in the name. + // A::B::C::fun(std::vector<T> &) const + size_t arg_start, arg_end; + llvm::StringRef full(m_full.GetCString()); + llvm::StringRef parens("()", 2); + if (ReverseFindMatchingChars(full, parens, arg_start, arg_end)) { + m_arguments = full.substr(arg_start, arg_end - arg_start + 1); + if (arg_end + 1 < full.size()) + m_qualifiers = full.substr(arg_end + 1).ltrim(); + + if (arg_start == 0) + return false; + size_t basename_end = arg_start; + size_t context_start = 0; + size_t context_end = full.rfind(':', basename_end); + if (context_end == llvm::StringRef::npos) + m_basename = full.substr(0, basename_end); + else { + if (context_start < context_end) + m_context = full.substr(context_start, context_end - 1 - context_start); + const size_t basename_begin = context_end + 1; + m_basename = full.substr(basename_begin, basename_end - basename_begin); + } - static RegularExpression g_operator_regex( - llvm::StringRef("^(operator)( " - "?)([A-Za-z_][A-Za-z_0-9]*|\\(\\)|" - "\\[\\]|[\\^<>=!\\/" - "*+-]+)(<.*>)?(\\[\\])?$")); - std::string basename_str(basename.str()); - return g_operator_regex.Execute(basename_str, nullptr); + if (IsTrivialBasename(m_basename)) { + return true; + } else { + // The C++ basename doesn't match our regular expressions so this can't + // be a valid C++ method, clear everything out and indicate an error + m_context = llvm::StringRef(); + m_basename = llvm::StringRef(); + m_arguments = llvm::StringRef(); + m_qualifiers = llvm::StringRef(); + return false; + } + } + return false; } void CPlusPlusLanguage::MethodName::Parse() { if (!m_parsed && m_full) { - // ConstString mangled; - // m_full.GetMangledCounterpart(mangled); - // printf ("\n parsing = '%s'\n", m_full.GetCString()); - // if (mangled) - // printf (" mangled = '%s'\n", mangled.GetCString()); - m_parse_error = false; - m_parsed = true; - llvm::StringRef full(m_full.GetCString()); - - size_t arg_start, arg_end; - llvm::StringRef parens("()", 2); - if (ReverseFindMatchingChars(full, parens, arg_start, arg_end)) { - m_arguments = full.substr(arg_start, arg_end - arg_start + 1); - if (arg_end + 1 < full.size()) - m_qualifiers = full.substr(arg_end + 1); - if (arg_start > 0) { - size_t basename_end = arg_start; - size_t context_start = 0; - size_t context_end = llvm::StringRef::npos; - if (basename_end > 0 && full[basename_end - 1] == '>') { - // TODO: handle template junk... - // Templated function - size_t template_start, template_end; - llvm::StringRef lt_gt("<>", 2); - if (ReverseFindMatchingChars(full, lt_gt, template_start, - template_end, basename_end)) { - // Check for templated functions that include return type like: - // 'void foo<Int>()' - context_start = full.rfind(' ', template_start); - if (context_start == llvm::StringRef::npos) - context_start = 0; - else - ++context_start; - - context_end = full.rfind(':', template_start); - if (context_end == llvm::StringRef::npos || - context_end < context_start) - context_end = context_start; - } else { - context_end = full.rfind(':', basename_end); - } - } else if (context_end == llvm::StringRef::npos) { - context_end = full.rfind(':', basename_end); - } - - if (context_end == llvm::StringRef::npos) - m_basename = full.substr(0, basename_end); - else { - if (context_start < context_end) - m_context = - full.substr(context_start, context_end - 1 - context_start); - const size_t basename_begin = context_end + 1; - m_basename = - full.substr(basename_begin, basename_end - basename_begin); - } - m_type = eTypeUnknownMethod; + if (TrySimplifiedParse()) { + m_parse_error = false; + } else { + CPlusPlusNameParser parser(m_full.GetStringRef()); + if (auto function = parser.ParseAsFunctionDefinition()) { + m_basename = function.getValue().name.basename; + m_context = function.getValue().name.context; + m_arguments = function.getValue().arguments; + m_qualifiers = function.getValue().qualifiers; + m_parse_error = false; } else { m_parse_error = true; - return; - } - - if (!IsValidBasename(m_basename)) { - // The C++ basename doesn't match our regular expressions so this can't - // be a valid C++ method, clear everything out and indicate an error - m_context = llvm::StringRef(); - m_basename = llvm::StringRef(); - m_arguments = llvm::StringRef(); - m_qualifiers = llvm::StringRef(); - m_parse_error = true; } - } else { - m_parse_error = true; } + m_parsed = true; } } @@ -272,14 +240,13 @@ llvm::StringRef CPlusPlusLanguage::MethodName::GetQualifiers() { std::string CPlusPlusLanguage::MethodName::GetScopeQualifiedName() { if (!m_parsed) Parse(); - if (m_basename.empty() || m_context.empty()) - return std::string(); + if (m_context.empty()) + return m_basename; std::string res; res += m_context; res += "::"; res += m_basename; - return res; } @@ -295,13 +262,10 @@ bool CPlusPlusLanguage::IsCPPMangledName(const char *name) { bool CPlusPlusLanguage::ExtractContextAndIdentifier( const char *name, llvm::StringRef &context, llvm::StringRef &identifier) { - static RegularExpression g_basename_regex(llvm::StringRef( - "^(([A-Za-z_][A-Za-z_0-9]*::)*)(~?[A-Za-z_~][A-Za-z_0-9]*)$")); - RegularExpression::Match match(4); - if (g_basename_regex.Execute(llvm::StringRef::withNullAsEmpty(name), - &match)) { - match.GetMatchAtIndex(name, 1, context); - match.GetMatchAtIndex(name, 3, identifier); + CPlusPlusNameParser parser(name); + if (auto full_name = parser.ParseAsFullName()) { + identifier = full_name.getValue().basename; + context = full_name.getValue().context; return true; } return false; @@ -596,13 +560,6 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) { AddCXXSynthetic( cpp_category_sp, - lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEndCreator, - "libc++ std::vector<bool> synthetic children", - ConstString( - "^std::__(ndk)?1::vector<bool, std::__(ndk)?1::allocator<bool> >$"), - stl_synth_flags, true); - AddCXXSynthetic( - cpp_category_sp, lldb_private::formatters::LibcxxStdVectorSyntheticFrontEndCreator, "libc++ std::vector synthetic children", ConstString("^std::__(ndk)?1::vector<.+>(( )?&)?$"), stl_synth_flags, @@ -620,19 +577,6 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) { true); AddCXXSynthetic( cpp_category_sp, - lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEndCreator, - "libc++ std::vector<bool> synthetic children", - ConstString("std::__(ndk)?1::vector<std::__(ndk)?1::allocator<bool> >"), - stl_synth_flags); - AddCXXSynthetic( - cpp_category_sp, - lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEndCreator, - "libc++ std::vector<bool> synthetic children", - ConstString( - "std::__(ndk)?1::vector<bool, std::__(ndk)?1::allocator<bool> >"), - stl_synth_flags); - AddCXXSynthetic( - cpp_category_sp, lldb_private::formatters::LibcxxStdMapSyntheticFrontEndCreator, "libc++ std::set synthetic children", ConstString("^std::__(ndk)?1::set<.+> >(( )?&)?$"), stl_synth_flags, @@ -689,12 +633,6 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) { stl_summary_flags.SetDontShowChildren(false); stl_summary_flags.SetSkipPointers(false); - AddCXXSummary( - cpp_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider, - "libc++ std::vector<bool> summary provider", - ConstString( - "std::__(ndk)?1::vector<bool, std::__(ndk)?1::allocator<bool> >"), - stl_summary_flags, true); AddCXXSummary(cpp_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::vector summary provider", @@ -759,12 +697,6 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) { "std::vector iterator synthetic children", ConstString("^std::__(ndk)?1::__wrap_iter<.+>$"), stl_synth_flags, true); - AddCXXSummary( - cpp_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider, - "libc++ std::vector<bool> summary provider", - ConstString( - "std::__(ndk)?1::vector<bool, std::__(ndk)?1::allocator<bool> >"), - stl_summary_flags); AddCXXSynthetic( cpp_category_sp, lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEndCreator, @@ -775,7 +707,7 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) { AddCXXSynthetic( cpp_category_sp, lldb_private::formatters::LibcxxFunctionFrontEndCreator, "std::function synthetic value provider", - ConstString("^std::__1::function<.+>$"), stl_synth_flags, true); + ConstString("^std::__(ndk)?1::function<.+>$"), stl_synth_flags, true); #endif } @@ -1036,10 +968,10 @@ std::unique_ptr<Language::TypeScavenger> CPlusPlusLanguage::GetTypeScavenger() { } lldb::TypeCategoryImplSP CPlusPlusLanguage::GetFormatters() { - static std::once_flag g_initialize; + static llvm::once_flag g_initialize; static TypeCategoryImplSP g_category; - std::call_once(g_initialize, [this]() -> void { + llvm::call_once(g_initialize, [this]() -> void { DataVisualization::Categories::GetCategory(GetPluginName(), g_category); if (g_category) { LoadLibCxxFormatters(g_category); @@ -1052,11 +984,11 @@ lldb::TypeCategoryImplSP CPlusPlusLanguage::GetFormatters() { HardcodedFormatters::HardcodedSummaryFinder CPlusPlusLanguage::GetHardcodedSummaries() { - static std::once_flag g_initialize; + static llvm::once_flag g_initialize; static ConstString g_vectortypes("VectorTypes"); static HardcodedFormatters::HardcodedSummaryFinder g_formatters; - std::call_once(g_initialize, []() -> void { + llvm::call_once(g_initialize, []() -> void { g_formatters.push_back( [](lldb_private::ValueObject &valobj, lldb::DynamicValueType, FormatManager &) -> TypeSummaryImpl::SharedPointer { @@ -1116,11 +1048,11 @@ CPlusPlusLanguage::GetHardcodedSummaries() { HardcodedFormatters::HardcodedSyntheticFinder CPlusPlusLanguage::GetHardcodedSynthetics() { - static std::once_flag g_initialize; + static llvm::once_flag g_initialize; static ConstString g_vectortypes("VectorTypes"); static HardcodedFormatters::HardcodedSyntheticFinder g_formatters; - std::call_once(g_initialize, []() -> void { + llvm::call_once(g_initialize, []() -> void { g_formatters.push_back([](lldb_private::ValueObject &valobj, lldb::DynamicValueType, FormatManager & diff --git a/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h b/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h index be5cbae57de2..056cced2808a 100644 --- a/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h +++ b/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h @@ -19,8 +19,8 @@ #include "llvm/ADT/StringRef.h" // Project includes -#include "lldb/Core/ConstString.h" #include "lldb/Target/Language.h" +#include "lldb/Utility/ConstString.h" #include "lldb/lldb-private.h" namespace lldb_private { @@ -29,20 +29,13 @@ class CPlusPlusLanguage : public Language { public: class MethodName { public: - enum Type { - eTypeInvalid, - eTypeUnknownMethod, - eTypeClassMethod, - eTypeInstanceMethod - }; - MethodName() : m_full(), m_basename(), m_context(), m_arguments(), m_qualifiers(), - m_type(eTypeInvalid), m_parsed(false), m_parse_error(false) {} + m_parsed(false), m_parse_error(false) {} MethodName(const ConstString &s) : m_full(s), m_basename(), m_context(), m_arguments(), m_qualifiers(), - m_type(eTypeInvalid), m_parsed(false), m_parse_error(false) {} + m_parsed(false), m_parse_error(false) {} void Clear(); @@ -51,13 +44,9 @@ public: Parse(); if (m_parse_error) return false; - if (m_type == eTypeInvalid) - return false; return (bool)m_full; } - Type GetType() const { return m_type; } - const ConstString &GetFullName() const { return m_full; } std::string GetScopeQualifiedName(); @@ -72,6 +61,7 @@ public: protected: void Parse(); + bool TrySimplifiedParse(); ConstString m_full; // Full name: // "lldb::SBTarget::GetBreakpointAtIndex(unsigned int) @@ -80,7 +70,6 @@ public: llvm::StringRef m_context; // Decl context: "lldb::SBTarget" llvm::StringRef m_arguments; // Arguments: "(unsigned int)" llvm::StringRef m_qualifiers; // Qualifiers: "const" - Type m_type; bool m_parsed; bool m_parse_error; }; @@ -121,7 +110,7 @@ public: // If the name is a lone C identifier (e.g. C) or a qualified C identifier // (e.g. A::B::C) it will return true, // and identifier will be the identifier (C and C respectively) and the - // context will be "" and "A::B::" respectively. + // context will be "" and "A::B" respectively. // If the name fails the heuristic matching for a qualified or unqualified // C/C++ identifier, then it will return false // and identifier and context will be unchanged. diff --git a/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp b/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp new file mode 100644 index 000000000000..5f0596cc9ad2 --- /dev/null +++ b/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp @@ -0,0 +1,630 @@ +//===-- CPlusPlusNameParser.cpp ---------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "CPlusPlusNameParser.h" + +#include "clang/Basic/IdentifierTable.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/Support/Threading.h" + +using namespace lldb; +using namespace lldb_private; +using llvm::Optional; +using llvm::None; +using ParsedFunction = lldb_private::CPlusPlusNameParser::ParsedFunction; +using ParsedName = lldb_private::CPlusPlusNameParser::ParsedName; +namespace tok = clang::tok; + +Optional<ParsedFunction> CPlusPlusNameParser::ParseAsFunctionDefinition() { + m_next_token_index = 0; + Optional<ParsedFunction> result(None); + + // Try to parse the name as function without a return type specified + // e.g. main(int, char*[]) + { + Bookmark start_position = SetBookmark(); + result = ParseFunctionImpl(false); + if (result && !HasMoreTokens()) + return result; + } + + // Try to parse the name as function with function pointer return type + // e.g. void (*get_func(const char*))() + result = ParseFuncPtr(true); + if (result) + return result; + + // Finally try to parse the name as a function with non-function return type + // e.g. int main(int, char*[]) + result = ParseFunctionImpl(true); + if (HasMoreTokens()) + return None; + return result; +} + +Optional<ParsedName> CPlusPlusNameParser::ParseAsFullName() { + m_next_token_index = 0; + Optional<ParsedNameRanges> name_ranges = ParseFullNameImpl(); + if (!name_ranges) + return None; + if (HasMoreTokens()) + return None; + ParsedName result; + result.basename = GetTextForRange(name_ranges.getValue().basename_range); + result.context = GetTextForRange(name_ranges.getValue().context_range); + return result; +} + +bool CPlusPlusNameParser::HasMoreTokens() { + return m_next_token_index < m_tokens.size(); +} + +void CPlusPlusNameParser::Advance() { ++m_next_token_index; } + +void CPlusPlusNameParser::TakeBack() { --m_next_token_index; } + +bool CPlusPlusNameParser::ConsumeToken(tok::TokenKind kind) { + if (!HasMoreTokens()) + return false; + + if (!Peek().is(kind)) + return false; + + Advance(); + return true; +} + +template <typename... Ts> bool CPlusPlusNameParser::ConsumeToken(Ts... kinds) { + if (!HasMoreTokens()) + return false; + + if (!Peek().isOneOf(kinds...)) + return false; + + Advance(); + return true; +} + +CPlusPlusNameParser::Bookmark CPlusPlusNameParser::SetBookmark() { + return Bookmark(m_next_token_index); +} + +size_t CPlusPlusNameParser::GetCurrentPosition() { return m_next_token_index; } + +clang::Token &CPlusPlusNameParser::Peek() { + assert(HasMoreTokens()); + return m_tokens[m_next_token_index]; +} + +Optional<ParsedFunction> +CPlusPlusNameParser::ParseFunctionImpl(bool expect_return_type) { + Bookmark start_position = SetBookmark(); + if (expect_return_type) { + // Consume return type if it's expected. + if (!ConsumeTypename()) + return None; + } + + auto maybe_name = ParseFullNameImpl(); + if (!maybe_name) { + return None; + } + + size_t argument_start = GetCurrentPosition(); + if (!ConsumeArguments()) { + return None; + } + + size_t qualifiers_start = GetCurrentPosition(); + SkipFunctionQualifiers(); + size_t end_position = GetCurrentPosition(); + + ParsedFunction result; + result.name.basename = GetTextForRange(maybe_name.getValue().basename_range); + result.name.context = GetTextForRange(maybe_name.getValue().context_range); + result.arguments = GetTextForRange(Range(argument_start, qualifiers_start)); + result.qualifiers = GetTextForRange(Range(qualifiers_start, end_position)); + start_position.Remove(); + return result; +} + +Optional<ParsedFunction> +CPlusPlusNameParser::ParseFuncPtr(bool expect_return_type) { + Bookmark start_position = SetBookmark(); + if (expect_return_type) { + // Consume return type. + if (!ConsumeTypename()) + return None; + } + + if (!ConsumeToken(tok::l_paren)) + return None; + if (!ConsumePtrsAndRefs()) + return None; + + { + Bookmark before_inner_function_pos = SetBookmark(); + auto maybe_inner_function_name = ParseFunctionImpl(false); + if (maybe_inner_function_name) + if (ConsumeToken(tok::r_paren)) + if (ConsumeArguments()) { + SkipFunctionQualifiers(); + start_position.Remove(); + before_inner_function_pos.Remove(); + return maybe_inner_function_name; + } + } + + auto maybe_inner_function_ptr_name = ParseFuncPtr(false); + if (maybe_inner_function_ptr_name) + if (ConsumeToken(tok::r_paren)) + if (ConsumeArguments()) { + SkipFunctionQualifiers(); + start_position.Remove(); + return maybe_inner_function_ptr_name; + } + return None; +} + +bool CPlusPlusNameParser::ConsumeArguments() { + return ConsumeBrackets(tok::l_paren, tok::r_paren); +} + +bool CPlusPlusNameParser::ConsumeTemplateArgs() { + Bookmark start_position = SetBookmark(); + if (!HasMoreTokens() || Peek().getKind() != tok::less) + return false; + Advance(); + + // Consuming template arguments is a bit trickier than consuming function + // arguments, because '<' '>' brackets are not always trivially balanced. + // In some rare cases tokens '<' and '>' can appear inside template arguments + // as arithmetic or shift operators not as template brackets. + // Examples: std::enable_if<(10u)<(64), bool> + // f<A<operator<(X,Y)::Subclass>> + // Good thing that compiler makes sure that really ambiguous cases of + // '>' usage should be enclosed within '()' brackets. + int template_counter = 1; + bool can_open_template = false; + while (HasMoreTokens() && template_counter > 0) { + tok::TokenKind kind = Peek().getKind(); + switch (kind) { + case tok::greatergreater: + template_counter -= 2; + can_open_template = false; + Advance(); + break; + case tok::greater: + --template_counter; + can_open_template = false; + Advance(); + break; + case tok::less: + // '<' is an attempt to open a subteamplte + // check if parser is at the point where it's actually possible, + // otherwise it's just a part of an expression like 'sizeof(T)<(10)'. + // No need to do the same for '>' because compiler actually makes sure + // that '>' always surrounded by brackets to avoid ambiguity. + if (can_open_template) + ++template_counter; + can_open_template = false; + Advance(); + break; + case tok::kw_operator: // C++ operator overloading. + if (!ConsumeOperator()) + return false; + can_open_template = true; + break; + case tok::raw_identifier: + can_open_template = true; + Advance(); + break; + case tok::l_square: + if (!ConsumeBrackets(tok::l_square, tok::r_square)) + return false; + can_open_template = false; + break; + case tok::l_paren: + if (!ConsumeArguments()) + return false; + can_open_template = false; + break; + default: + can_open_template = false; + Advance(); + break; + } + } + + assert(template_counter >= 0); + if (template_counter > 0) { + return false; + } + start_position.Remove(); + return true; +} + +bool CPlusPlusNameParser::ConsumeAnonymousNamespace() { + Bookmark start_position = SetBookmark(); + if (!ConsumeToken(tok::l_paren)) { + return false; + } + constexpr llvm::StringLiteral g_anonymous("anonymous"); + if (HasMoreTokens() && Peek().is(tok::raw_identifier) && + Peek().getRawIdentifier() == g_anonymous) { + Advance(); + } else { + return false; + } + + if (!ConsumeToken(tok::kw_namespace)) { + return false; + } + + if (!ConsumeToken(tok::r_paren)) { + return false; + } + start_position.Remove(); + return true; +} + +bool CPlusPlusNameParser::ConsumeBrackets(tok::TokenKind left, + tok::TokenKind right) { + Bookmark start_position = SetBookmark(); + if (!HasMoreTokens() || Peek().getKind() != left) + return false; + Advance(); + + int counter = 1; + while (HasMoreTokens() && counter > 0) { + tok::TokenKind kind = Peek().getKind(); + if (kind == right) + --counter; + else if (kind == left) + ++counter; + Advance(); + } + + assert(counter >= 0); + if (counter > 0) { + return false; + } + start_position.Remove(); + return true; +} + +bool CPlusPlusNameParser::ConsumeOperator() { + Bookmark start_position = SetBookmark(); + if (!ConsumeToken(tok::kw_operator)) + return false; + + if (!HasMoreTokens()) { + return false; + } + + const auto &token = Peek(); + switch (token.getKind()) { + case tok::kw_new: + case tok::kw_delete: + // This is 'new' or 'delete' operators. + Advance(); + // Check for array new/delete. + if (HasMoreTokens() && Peek().is(tok::l_square)) { + // Consume the '[' and ']'. + if (!ConsumeBrackets(tok::l_square, tok::r_square)) + return false; + } + break; + +#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \ + case tok::Token: \ + Advance(); \ + break; +#define OVERLOADED_OPERATOR_MULTI(Name, Spelling, Unary, Binary, MemberOnly) +#include "clang/Basic/OperatorKinds.def" +#undef OVERLOADED_OPERATOR +#undef OVERLOADED_OPERATOR_MULTI + + case tok::l_paren: + // Call operator consume '(' ... ')'. + if (ConsumeBrackets(tok::l_paren, tok::r_paren)) + break; + return false; + + case tok::l_square: + // This is a [] operator. + // Consume the '[' and ']'. + if (ConsumeBrackets(tok::l_square, tok::r_square)) + break; + return false; + + default: + // This might be a cast operator. + if (ConsumeTypename()) + break; + return false; + } + start_position.Remove(); + return true; +} + +void CPlusPlusNameParser::SkipTypeQualifiers() { + while (ConsumeToken(tok::kw_const, tok::kw_volatile)) + ; +} + +void CPlusPlusNameParser::SkipFunctionQualifiers() { + while (ConsumeToken(tok::kw_const, tok::kw_volatile, tok::amp, tok::ampamp)) + ; +} + +bool CPlusPlusNameParser::ConsumeBuiltinType() { + bool result = false; + bool continue_parsing = true; + // Built-in types can be made of a few keywords + // like 'unsigned long long int'. This function + // consumes all built-in type keywords without + // checking if they make sense like 'unsigned char void'. + while (continue_parsing && HasMoreTokens()) { + switch (Peek().getKind()) { + case tok::kw_short: + case tok::kw_long: + case tok::kw___int64: + case tok::kw___int128: + case tok::kw_signed: + case tok::kw_unsigned: + case tok::kw_void: + case tok::kw_char: + case tok::kw_int: + case tok::kw_half: + case tok::kw_float: + case tok::kw_double: + case tok::kw___float128: + case tok::kw_wchar_t: + case tok::kw_bool: + case tok::kw_char16_t: + case tok::kw_char32_t: + result = true; + Advance(); + break; + default: + continue_parsing = false; + break; + } + } + return result; +} + +void CPlusPlusNameParser::SkipPtrsAndRefs() { + // Ignoring result. + ConsumePtrsAndRefs(); +} + +bool CPlusPlusNameParser::ConsumePtrsAndRefs() { + bool found = false; + SkipTypeQualifiers(); + while (ConsumeToken(tok::star, tok::amp, tok::ampamp, tok::kw_const, + tok::kw_volatile)) { + found = true; + SkipTypeQualifiers(); + } + return found; +} + +bool CPlusPlusNameParser::ConsumeDecltype() { + Bookmark start_position = SetBookmark(); + if (!ConsumeToken(tok::kw_decltype)) + return false; + + if (!ConsumeArguments()) + return false; + + start_position.Remove(); + return true; +} + +bool CPlusPlusNameParser::ConsumeTypename() { + Bookmark start_position = SetBookmark(); + SkipTypeQualifiers(); + if (!ConsumeBuiltinType() && !ConsumeDecltype()) { + if (!ParseFullNameImpl()) + return false; + } + SkipPtrsAndRefs(); + start_position.Remove(); + return true; +} + +Optional<CPlusPlusNameParser::ParsedNameRanges> +CPlusPlusNameParser::ParseFullNameImpl() { + // Name parsing state machine. + enum class State { + Beginning, // start of the name + AfterTwoColons, // right after :: + AfterIdentifier, // right after alphanumerical identifier ([a-z0-9_]+) + AfterTemplate, // right after template brackets (<something>) + AfterOperator, // right after name of C++ operator + }; + + Bookmark start_position = SetBookmark(); + State state = State::Beginning; + bool continue_parsing = true; + Optional<size_t> last_coloncolon_position = None; + + while (continue_parsing && HasMoreTokens()) { + const auto &token = Peek(); + switch (token.getKind()) { + case tok::raw_identifier: // Just a name. + if (state != State::Beginning && state != State::AfterTwoColons) { + continue_parsing = false; + break; + } + Advance(); + state = State::AfterIdentifier; + break; + case tok::l_paren: { + if (state == State::Beginning || state == State::AfterTwoColons) { + // (anonymous namespace) + if (ConsumeAnonymousNamespace()) { + state = State::AfterIdentifier; + break; + } + } + + // Type declared inside a function 'func()::Type' + if (state != State::AfterIdentifier && state != State::AfterTemplate && + state != State::AfterOperator) { + continue_parsing = false; + break; + } + Bookmark l_paren_position = SetBookmark(); + // Consume the '(' ... ') [const]'. + if (!ConsumeArguments()) { + continue_parsing = false; + break; + } + SkipFunctionQualifiers(); + + // Consume '::' + size_t coloncolon_position = GetCurrentPosition(); + if (!ConsumeToken(tok::coloncolon)) { + continue_parsing = false; + break; + } + l_paren_position.Remove(); + last_coloncolon_position = coloncolon_position; + state = State::AfterTwoColons; + break; + } + case tok::coloncolon: // Type nesting delimiter. + if (state != State::Beginning && state != State::AfterIdentifier && + state != State::AfterTemplate) { + continue_parsing = false; + break; + } + last_coloncolon_position = GetCurrentPosition(); + Advance(); + state = State::AfterTwoColons; + break; + case tok::less: // Template brackets. + if (state != State::AfterIdentifier && state != State::AfterOperator) { + continue_parsing = false; + break; + } + if (!ConsumeTemplateArgs()) { + continue_parsing = false; + break; + } + state = State::AfterTemplate; + break; + case tok::kw_operator: // C++ operator overloading. + if (state != State::Beginning && state != State::AfterTwoColons) { + continue_parsing = false; + break; + } + if (!ConsumeOperator()) { + continue_parsing = false; + break; + } + state = State::AfterOperator; + break; + case tok::tilde: // Destructor. + if (state != State::Beginning && state != State::AfterTwoColons) { + continue_parsing = false; + break; + } + Advance(); + if (ConsumeToken(tok::raw_identifier)) { + state = State::AfterIdentifier; + } else { + TakeBack(); + continue_parsing = false; + } + break; + default: + continue_parsing = false; + break; + } + } + + if (state == State::AfterIdentifier || state == State::AfterOperator || + state == State::AfterTemplate) { + ParsedNameRanges result; + if (last_coloncolon_position) { + result.context_range = Range(start_position.GetSavedPosition(), + last_coloncolon_position.getValue()); + result.basename_range = + Range(last_coloncolon_position.getValue() + 1, GetCurrentPosition()); + } else { + result.basename_range = + Range(start_position.GetSavedPosition(), GetCurrentPosition()); + } + start_position.Remove(); + return result; + } else { + return None; + } +} + +llvm::StringRef CPlusPlusNameParser::GetTextForRange(const Range &range) { + if (range.empty()) + return llvm::StringRef(); + assert(range.begin_index < range.end_index); + assert(range.begin_index < m_tokens.size()); + assert(range.end_index <= m_tokens.size()); + clang::Token &first_token = m_tokens[range.begin_index]; + clang::Token &last_token = m_tokens[range.end_index - 1]; + clang::SourceLocation start_loc = first_token.getLocation(); + clang::SourceLocation end_loc = last_token.getLocation(); + unsigned start_pos = start_loc.getRawEncoding(); + unsigned end_pos = end_loc.getRawEncoding() + last_token.getLength(); + return m_text.take_front(end_pos).drop_front(start_pos); +} + +static const clang::LangOptions &GetLangOptions() { + static clang::LangOptions g_options; + static llvm::once_flag g_once_flag; + llvm::call_once(g_once_flag, []() { + g_options.LineComment = true; + g_options.C99 = true; + g_options.C11 = true; + g_options.CPlusPlus = true; + g_options.CPlusPlus11 = true; + g_options.CPlusPlus14 = true; + g_options.CPlusPlus1z = true; + }); + return g_options; +} + +static const llvm::StringMap<tok::TokenKind> &GetKeywordsMap() { + static llvm::StringMap<tok::TokenKind> g_map{ +#define KEYWORD(Name, Flags) {llvm::StringRef(#Name), tok::kw_##Name}, +#include "clang/Basic/TokenKinds.def" +#undef KEYWORD + }; + return g_map; +} + +void CPlusPlusNameParser::ExtractTokens() { + clang::Lexer lexer(clang::SourceLocation(), GetLangOptions(), m_text.data(), + m_text.data(), m_text.data() + m_text.size()); + const auto &kw_map = GetKeywordsMap(); + clang::Token token; + for (lexer.LexFromRawLexer(token); !token.is(clang::tok::eof); + lexer.LexFromRawLexer(token)) { + if (token.is(clang::tok::raw_identifier)) { + auto it = kw_map.find(token.getRawIdentifier()); + if (it != kw_map.end()) { + token.setKind(it->getValue()); + } + } + + m_tokens.push_back(token); + } +} diff --git a/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.h b/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.h new file mode 100644 index 000000000000..f936fb787c94 --- /dev/null +++ b/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.h @@ -0,0 +1,179 @@ +//===-- CPlusPlusNameParser.h -----------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_CPlusPlusNameParser_h_ +#define liblldb_CPlusPlusNameParser_h_ + +// C Includes +// C++ Includes + +// Other libraries and framework includes +#include "clang/Lex/Lexer.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" + +// Project includes +#include "lldb/Utility/ConstString.h" +#include "lldb/lldb-private.h" + +namespace lldb_private { + +// Helps to validate and obtain various parts of C++ definitions. +class CPlusPlusNameParser { +public: + CPlusPlusNameParser(llvm::StringRef text) : m_text(text) { ExtractTokens(); } + + struct ParsedName { + llvm::StringRef basename; + llvm::StringRef context; + }; + + struct ParsedFunction { + ParsedName name; + llvm::StringRef arguments; + llvm::StringRef qualifiers; + }; + + // Treats given text as a function definition and parses it. + // Function definition might or might not have a return type and this should + // change parsing result. + // Examples: + // main(int, chat const*) + // T fun(int, bool) + // std::vector<int>::push_back(int) + // int& map<int, pair<short, int>>::operator[](short) const + // int (*get_function(const chat *))() + llvm::Optional<ParsedFunction> ParseAsFunctionDefinition(); + + // Treats given text as a potentially nested name of C++ entity (function, + // class, field) and parses it. + // Examples: + // main + // fun + // std::vector<int>::push_back + // map<int, pair<short, int>>::operator[] + // func<C>(int, C&)::nested_class::method + llvm::Optional<ParsedName> ParseAsFullName(); + +private: + // A C++ definition to parse. + llvm::StringRef m_text; + // Tokens extracted from m_text. + llvm::SmallVector<clang::Token, 30> m_tokens; + // Index of the next token to look at from m_tokens. + size_t m_next_token_index = 0; + + // Range of tokens saved in m_next_token_index. + struct Range { + size_t begin_index = 0; + size_t end_index = 0; + + Range() {} + Range(size_t begin, size_t end) : begin_index(begin), end_index(end) { + assert(end >= begin); + } + + size_t size() const { return end_index - begin_index; } + + bool empty() const { return size() == 0; } + }; + + struct ParsedNameRanges { + Range basename_range; + Range context_range; + }; + + // Bookmark automatically restores parsing position (m_next_token_index) + // when destructed unless it's manually removed with Remove(). + class Bookmark { + public: + Bookmark(size_t &position) + : m_position(position), m_position_value(position) {} + Bookmark(const Bookmark &) = delete; + Bookmark(Bookmark &&b) + : m_position(b.m_position), m_position_value(b.m_position_value), + m_restore(b.m_restore) { + b.Remove(); + } + Bookmark &operator=(Bookmark &&) = delete; + Bookmark &operator=(const Bookmark &) = delete; + + void Remove() { m_restore = false; } + size_t GetSavedPosition() { return m_position_value; } + ~Bookmark() { + if (m_restore) { + m_position = m_position_value; + } + } + + private: + size_t &m_position; + size_t m_position_value; + bool m_restore = true; + }; + + bool HasMoreTokens(); + void Advance(); + void TakeBack(); + bool ConsumeToken(clang::tok::TokenKind kind); + template <typename... Ts> bool ConsumeToken(Ts... kinds); + Bookmark SetBookmark(); + size_t GetCurrentPosition(); + clang::Token &Peek(); + bool ConsumeBrackets(clang::tok::TokenKind left, clang::tok::TokenKind right); + + llvm::Optional<ParsedFunction> ParseFunctionImpl(bool expect_return_type); + + // Parses functions returning function pointers 'string (*f(int x))(float y)' + llvm::Optional<ParsedFunction> ParseFuncPtr(bool expect_return_type); + + // Consumes function arguments enclosed within '(' ... ')' + bool ConsumeArguments(); + + // Consumes template arguments enclosed within '<' ... '>' + bool ConsumeTemplateArgs(); + + // Consumes '(anonymous namespace)' + bool ConsumeAnonymousNamespace(); + + // Consumes operator declaration like 'operator *' or 'operator delete []' + bool ConsumeOperator(); + + // Skips 'const' and 'volatile' + void SkipTypeQualifiers(); + + // Skips 'const', 'volatile', '&', '&&' in the end of the function. + void SkipFunctionQualifiers(); + + // Consumes built-in types like 'int' or 'unsigned long long int' + bool ConsumeBuiltinType(); + + // Consumes types defined via decltype keyword. + bool ConsumeDecltype(); + + // Skips 'const' and 'volatile' + void SkipPtrsAndRefs(); + + // Consumes things like 'const * const &' + bool ConsumePtrsAndRefs(); + + // Consumes full type name like 'Namespace::Class<int>::Method()::InnerClass' + bool ConsumeTypename(); + + llvm::Optional<ParsedNameRanges> ParseFullNameImpl(); + llvm::StringRef GetTextForRange(const Range &range); + + // Populate m_tokens by calling clang lexer on m_text. + void ExtractTokens(); +}; + +} // namespace lldb_private + +#endif // liblldb_CPlusPlusNameParser_h_ diff --git a/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp b/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp index 346ea0bbd519..b69b69530428 100644 --- a/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp +++ b/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp @@ -11,21 +11,21 @@ #include "llvm/Support/ConvertUTF.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/DataFormatters/StringPrinter.h" #include "lldb/DataFormatters/TypeSummary.h" -#include "lldb/Host/Endian.h" #include "lldb/Host/Time.h" #include "lldb/Symbol/ClangASTContext.h" +#include "lldb/Target/ProcessStructReader.h" #include "lldb/Target/SectionLoadList.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" -#include "lldb/Utility/ProcessStructReader.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Stream.h" #include <algorithm> diff --git a/source/Plugins/Language/CPlusPlus/CxxStringTypes.h b/source/Plugins/Language/CPlusPlus/CxxStringTypes.h index 0bee3bd3b0f2..8e2ec44dc71c 100644 --- a/source/Plugins/Language/CPlusPlus/CxxStringTypes.h +++ b/source/Plugins/Language/CPlusPlus/CxxStringTypes.h @@ -11,9 +11,9 @@ #ifndef liblldb_CxxStringTypes_h_ #define liblldb_CxxStringTypes_h_ -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/TypeSummary.h" +#include "lldb/Utility/Stream.h" namespace lldb_private { namespace formatters { diff --git a/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/source/Plugins/Language/CPlusPlus/LibCxx.cpp index 82441a69b1d4..72d99671612c 100644 --- a/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -13,21 +13,21 @@ // C++ Includes // Other libraries and framework includes // Project includes -#include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Error.h" #include "lldb/Core/FormatEntity.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/DataFormatters/StringPrinter.h" #include "lldb/DataFormatters/TypeSummary.h" #include "lldb/DataFormatters/VectorIterator.h" -#include "lldb/Host/Endian.h" #include "lldb/Symbol/ClangASTContext.h" +#include "lldb/Target/ProcessStructReader.h" #include "lldb/Target/Target.h" -#include "lldb/Utility/ProcessStructReader.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Stream.h" using namespace lldb; using namespace lldb_private; @@ -76,155 +76,6 @@ bool lldb_private::formatters::LibcxxSmartPointerSummaryProvider( return true; } -lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd:: - LibcxxVectorBoolSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp) - : SyntheticChildrenFrontEnd(*valobj_sp), m_bool_type(), m_exe_ctx_ref(), - m_count(0), m_base_data_address(0), m_children() { - if (valobj_sp) { - Update(); - m_bool_type = - valobj_sp->GetCompilerType().GetBasicTypeFromAST(lldb::eBasicTypeBool); - } -} - -size_t lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd:: - CalculateNumChildren() { - return m_count; -} - -lldb::ValueObjectSP -lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::GetChildAtIndex( - size_t idx) { - auto iter = m_children.find(idx), end = m_children.end(); - if (iter != end) - return iter->second; - if (idx >= m_count) - return ValueObjectSP(); - if (m_base_data_address == 0 || m_count == 0) - return ValueObjectSP(); - if (!m_bool_type) - return ValueObjectSP(); - size_t byte_idx = (idx >> 3); // divide by 8 to get byte index - size_t bit_index = (idx & 7); // efficient idx % 8 for bit index - lldb::addr_t byte_location = m_base_data_address + byte_idx; - ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP()); - if (!process_sp) - return ValueObjectSP(); - uint8_t byte = 0; - uint8_t mask = 0; - Error err; - size_t bytes_read = process_sp->ReadMemory(byte_location, &byte, 1, err); - if (err.Fail() || bytes_read == 0) - return ValueObjectSP(); - switch (bit_index) { - case 0: - mask = 1; - break; - case 1: - mask = 2; - break; - case 2: - mask = 4; - break; - case 3: - mask = 8; - break; - case 4: - mask = 16; - break; - case 5: - mask = 32; - break; - case 6: - mask = 64; - break; - case 7: - mask = 128; - break; - default: - return ValueObjectSP(); - } - bool bit_set = ((byte & mask) != 0); - DataBufferSP buffer_sp( - new DataBufferHeap(m_bool_type.GetByteSize(nullptr), 0)); - if (bit_set && buffer_sp && buffer_sp->GetBytes()) - *(buffer_sp->GetBytes()) = - 1; // regardless of endianness, anything non-zero is true - StreamString name; - name.Printf("[%" PRIu64 "]", (uint64_t)idx); - ValueObjectSP retval_sp(CreateValueObjectFromData( - name.GetString(), DataExtractor(buffer_sp, process_sp->GetByteOrder(), - process_sp->GetAddressByteSize()), - m_exe_ctx_ref, m_bool_type)); - if (retval_sp) - m_children[idx] = retval_sp; - return retval_sp; -} - -/*(std::__1::vector<std::__1::allocator<bool> >) vBool = { - __begin_ = 0x00000001001000e0 - __size_ = 56 - __cap_alloc_ = { - std::__1::__libcpp_compressed_pair_imp<unsigned long, - std::__1::allocator<unsigned long> > = { - __first_ = 1 - } - } - }*/ - -bool lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::Update() { - m_children.clear(); - ValueObjectSP valobj_sp = m_backend.GetSP(); - if (!valobj_sp) - return false; - m_exe_ctx_ref = valobj_sp->GetExecutionContextRef(); - ValueObjectSP size_sp( - valobj_sp->GetChildMemberWithName(ConstString("__size_"), true)); - if (!size_sp) - return false; - m_count = size_sp->GetValueAsUnsigned(0); - if (!m_count) - return true; - ValueObjectSP begin_sp( - valobj_sp->GetChildMemberWithName(ConstString("__begin_"), true)); - if (!begin_sp) { - m_count = 0; - return false; - } - m_base_data_address = begin_sp->GetValueAsUnsigned(0); - if (!m_base_data_address) { - m_count = 0; - return false; - } - return false; -} - -bool lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd:: - MightHaveChildren() { - return true; -} - -size_t lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd:: - GetIndexOfChildWithName(const ConstString &name) { - if (!m_count || !m_base_data_address) - return UINT32_MAX; - const char *item_name = name.GetCString(); - uint32_t idx = ExtractIndexFromString(item_name); - if (idx < UINT32_MAX && idx >= CalculateNumChildren()) - return UINT32_MAX; - return idx; -} - -lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd:: - ~LibcxxVectorBoolSyntheticFrontEnd() = default; - -SyntheticChildrenFrontEnd * -lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEndCreator( - CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) { - return (valobj_sp ? new LibcxxVectorBoolSyntheticFrontEnd(valobj_sp) - : nullptr); -} - /* (lldb) fr var ibeg --raw --ptr-depth 1 (std::__1::__map_iterator<std::__1::__tree_iterator<std::__1::pair<int, diff --git a/source/Plugins/Language/CPlusPlus/LibCxx.h b/source/Plugins/Language/CPlusPlus/LibCxx.h index a8638513376c..7610212b4245 100644 --- a/source/Plugins/Language/CPlusPlus/LibCxx.h +++ b/source/Plugins/Language/CPlusPlus/LibCxx.h @@ -11,10 +11,10 @@ #ifndef liblldb_LibCxx_h_ #define liblldb_LibCxx_h_ -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/TypeSummary.h" #include "lldb/DataFormatters/TypeSynthetic.h" +#include "lldb/Utility/Stream.h" namespace lldb_private { namespace formatters { @@ -32,30 +32,6 @@ bool LibcxxSmartPointerSummaryProvider( const TypeSummaryOptions &options); // libc++ std::shared_ptr<> and std::weak_ptr<> -class LibcxxVectorBoolSyntheticFrontEnd : public SyntheticChildrenFrontEnd { -public: - LibcxxVectorBoolSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp); - - size_t CalculateNumChildren() override; - - lldb::ValueObjectSP GetChildAtIndex(size_t idx) override; - - bool Update() override; - - bool MightHaveChildren() override; - - size_t GetIndexOfChildWithName(const ConstString &name) override; - - ~LibcxxVectorBoolSyntheticFrontEnd() override; - -private: - CompilerType m_bool_type; - ExecutionContextRef m_exe_ctx_ref; - uint64_t m_count; - lldb::addr_t m_base_data_address; - std::map<size_t, lldb::ValueObjectSP> m_children; -}; - SyntheticChildrenFrontEnd * LibcxxVectorBoolSyntheticFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP); diff --git a/source/Plugins/Language/CPlusPlus/LibCxxAtomic.h b/source/Plugins/Language/CPlusPlus/LibCxxAtomic.h index e2cc01150a2e..a9d948bf189c 100644 --- a/source/Plugins/Language/CPlusPlus/LibCxxAtomic.h +++ b/source/Plugins/Language/CPlusPlus/LibCxxAtomic.h @@ -11,10 +11,10 @@ #ifndef liblldb_LibCxxAtomic_h_ #define liblldb_LibCxxAtomic_h_ -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/TypeSummary.h" #include "lldb/DataFormatters/TypeSynthetic.h" +#include "lldb/Utility/Stream.h" namespace lldb_private { namespace formatters { diff --git a/source/Plugins/Language/CPlusPlus/LibCxxInitializerList.cpp b/source/Plugins/Language/CPlusPlus/LibCxxInitializerList.cpp index b7aa70c0d2e7..4e839532afb7 100644 --- a/source/Plugins/Language/CPlusPlus/LibCxxInitializerList.cpp +++ b/source/Plugins/Language/CPlusPlus/LibCxxInitializerList.cpp @@ -13,9 +13,9 @@ // Project includes #include "LibCxx.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/FormattersHelpers.h" +#include "lldb/Utility/ConstString.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/Language/CPlusPlus/LibCxxList.cpp b/source/Plugins/Language/CPlusPlus/LibCxxList.cpp index 16bd631a6c2f..4ad3df3d6038 100644 --- a/source/Plugins/Language/CPlusPlus/LibCxxList.cpp +++ b/source/Plugins/Language/CPlusPlus/LibCxxList.cpp @@ -13,15 +13,15 @@ // Project includes #include "LibCxx.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" -#include "lldb/Host/Endian.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Stream.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp b/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp index 759a7008d3f3..50d4510ec5f9 100644 --- a/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp +++ b/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp @@ -13,15 +13,15 @@ // Project includes #include "LibCxx.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" -#include "lldb/Host/Endian.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Stream.h" using namespace lldb; using namespace lldb_private; @@ -406,7 +406,7 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex( case 1: { auto child0_sp = potential_child_sp->GetChildAtIndex(0, true); if (child0_sp && child0_sp->GetName() == g___cc) - potential_child_sp = child0_sp; + potential_child_sp = child0_sp->Clone(ConstString(name.GetString())); break; } case 2: { @@ -414,11 +414,10 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex( auto child1_sp = potential_child_sp->GetChildAtIndex(1, true); if (child0_sp && child0_sp->GetName() == g___cc && child1_sp && child1_sp->GetName() == g___nc) - potential_child_sp = child0_sp; + potential_child_sp = child0_sp->Clone(ConstString(name.GetString())); break; } } - potential_child_sp->SetName(ConstString(name.GetString())); } m_iterators[idx] = iterator; return potential_child_sp; diff --git a/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp b/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp index 5fe4b3a9fc9e..c3566b7c6bfb 100644 --- a/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp +++ b/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp @@ -13,15 +13,15 @@ // Project includes #include "LibCxx.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" -#include "lldb/Host/Endian.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Stream.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp b/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp index b5c9b6d0f11e..2843201e2ed9 100644 --- a/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp +++ b/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp @@ -13,9 +13,9 @@ // Project includes #include "LibCxx.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/FormattersHelpers.h" +#include "lldb/Utility/ConstString.h" using namespace lldb; using namespace lldb_private; @@ -45,6 +45,29 @@ private: CompilerType m_element_type; uint32_t m_element_size; }; + +class LibcxxVectorBoolSyntheticFrontEnd : public SyntheticChildrenFrontEnd { +public: + LibcxxVectorBoolSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp); + + size_t CalculateNumChildren() override; + + lldb::ValueObjectSP GetChildAtIndex(size_t idx) override; + + bool Update() override; + + bool MightHaveChildren() override { return true; } + + size_t GetIndexOfChildWithName(const ConstString &name) override; + +private: + CompilerType m_bool_type; + ExecutionContextRef m_exe_ctx_ref; + uint64_t m_count; + lldb::addr_t m_base_data_address; + std::map<size_t, lldb::ValueObjectSP> m_children; +}; + } // namespace formatters } // namespace lldb_private @@ -133,9 +156,126 @@ size_t lldb_private::formatters::LibcxxStdVectorSyntheticFrontEnd:: return ExtractIndexFromString(name.GetCString()); } +lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd:: + LibcxxVectorBoolSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp) + : SyntheticChildrenFrontEnd(*valobj_sp), m_bool_type(), m_exe_ctx_ref(), + m_count(0), m_base_data_address(0), m_children() { + if (valobj_sp) { + Update(); + m_bool_type = + valobj_sp->GetCompilerType().GetBasicTypeFromAST(lldb::eBasicTypeBool); + } +} + +size_t lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd:: + CalculateNumChildren() { + return m_count; +} + +lldb::ValueObjectSP +lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::GetChildAtIndex( + size_t idx) { + auto iter = m_children.find(idx), end = m_children.end(); + if (iter != end) + return iter->second; + if (idx >= m_count) + return ValueObjectSP(); + if (m_base_data_address == 0 || m_count == 0) + return ValueObjectSP(); + if (!m_bool_type) + return ValueObjectSP(); + size_t byte_idx = (idx >> 3); // divide by 8 to get byte index + size_t bit_index = (idx & 7); // efficient idx % 8 for bit index + lldb::addr_t byte_location = m_base_data_address + byte_idx; + ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP()); + if (!process_sp) + return ValueObjectSP(); + uint8_t byte = 0; + uint8_t mask = 0; + Error err; + size_t bytes_read = process_sp->ReadMemory(byte_location, &byte, 1, err); + if (err.Fail() || bytes_read == 0) + return ValueObjectSP(); + mask = 1 << bit_index; + bool bit_set = ((byte & mask) != 0); + DataBufferSP buffer_sp( + new DataBufferHeap(m_bool_type.GetByteSize(nullptr), 0)); + if (bit_set && buffer_sp && buffer_sp->GetBytes()) { + // regardless of endianness, anything non-zero is true + *(buffer_sp->GetBytes()) = 1; + } + StreamString name; + name.Printf("[%" PRIu64 "]", (uint64_t)idx); + ValueObjectSP retval_sp(CreateValueObjectFromData( + name.GetString(), + DataExtractor(buffer_sp, process_sp->GetByteOrder(), + process_sp->GetAddressByteSize()), + m_exe_ctx_ref, m_bool_type)); + if (retval_sp) + m_children[idx] = retval_sp; + return retval_sp; +} + +/*(std::__1::vector<std::__1::allocator<bool> >) vBool = { + __begin_ = 0x00000001001000e0 + __size_ = 56 + __cap_alloc_ = { + std::__1::__libcpp_compressed_pair_imp<unsigned long, + std::__1::allocator<unsigned long> > = { + __first_ = 1 + } + } + }*/ + +bool lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::Update() { + m_children.clear(); + ValueObjectSP valobj_sp = m_backend.GetSP(); + if (!valobj_sp) + return false; + m_exe_ctx_ref = valobj_sp->GetExecutionContextRef(); + ValueObjectSP size_sp( + valobj_sp->GetChildMemberWithName(ConstString("__size_"), true)); + if (!size_sp) + return false; + m_count = size_sp->GetValueAsUnsigned(0); + if (!m_count) + return true; + ValueObjectSP begin_sp( + valobj_sp->GetChildMemberWithName(ConstString("__begin_"), true)); + if (!begin_sp) { + m_count = 0; + return false; + } + m_base_data_address = begin_sp->GetValueAsUnsigned(0); + if (!m_base_data_address) { + m_count = 0; + return false; + } + return false; +} + +size_t lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd:: + GetIndexOfChildWithName(const ConstString &name) { + if (!m_count || !m_base_data_address) + return UINT32_MAX; + const char *item_name = name.GetCString(); + uint32_t idx = ExtractIndexFromString(item_name); + if (idx < UINT32_MAX && idx >= CalculateNumChildren()) + return UINT32_MAX; + return idx; +} + lldb_private::SyntheticChildrenFrontEnd * lldb_private::formatters::LibcxxStdVectorSyntheticFrontEndCreator( CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) { - return (valobj_sp ? new LibcxxStdVectorSyntheticFrontEnd(valobj_sp) - : nullptr); + if (!valobj_sp) + return nullptr; + CompilerType type = valobj_sp->GetCompilerType(); + if (!type.IsValid() || type.GetNumTemplateArguments() == 0) + return nullptr; + TemplateArgumentKind kind; + CompilerType arg_type = type.GetTemplateArgument(0, kind); + if (arg_type.GetTypeName() == ConstString("bool")) + return new LibcxxVectorBoolSyntheticFrontEnd(valobj_sp); + return new LibcxxStdVectorSyntheticFrontEnd(valobj_sp); } diff --git a/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp b/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp index f931a8d6a046..a4633db8157e 100644 --- a/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp +++ b/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp @@ -13,16 +13,16 @@ // C++ Includes // Other libraries and framework includes // Project includes -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/StringPrinter.h" #include "lldb/DataFormatters/VectorIterator.h" -#include "lldb/Host/Endian.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Stream.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/Language/CPlusPlus/LibStdcpp.h b/source/Plugins/Language/CPlusPlus/LibStdcpp.h index 72e169f50395..1400477dcd0d 100644 --- a/source/Plugins/Language/CPlusPlus/LibStdcpp.h +++ b/source/Plugins/Language/CPlusPlus/LibStdcpp.h @@ -10,10 +10,10 @@ #ifndef liblldb_LibStdCpp_h_ #define liblldb_LibStdCpp_h_ -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/TypeSummary.h" #include "lldb/DataFormatters/TypeSynthetic.h" +#include "lldb/Utility/Stream.h" namespace lldb_private { namespace formatters { diff --git a/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp b/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp index c4a6e3d227b0..943af6ee81e4 100644 --- a/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp +++ b/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp @@ -9,10 +9,10 @@ #include "LibStdcpp.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/DataFormatters/TypeSynthetic.h" +#include "lldb/Utility/ConstString.h" #include <memory> #include <vector> @@ -73,9 +73,7 @@ bool LibStdcppTupleSyntheticFrontEnd::Update() { if (value_sp) { StreamString name; name.Printf("[%zd]", m_members.size()); - value_sp->SetName(ConstString(name.GetString())); - - m_members.push_back(value_sp); + m_members.push_back(value_sp->Clone(ConstString(name.GetString()))); } } } diff --git a/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp b/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp index 4eb3b95afb4e..7693961cae17 100644 --- a/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp +++ b/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp @@ -9,10 +9,10 @@ #include "LibStdcpp.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/DataFormatters/TypeSynthetic.h" +#include "lldb/Utility/ConstString.h" #include <memory> #include <vector> @@ -70,19 +70,19 @@ bool LibStdcppUniquePtrSyntheticFrontEnd::Update() { std::unique_ptr<SyntheticChildrenFrontEnd> tuple_frontend( LibStdcppTupleSyntheticFrontEndCreator(nullptr, tuple_sp)); - m_ptr_obj = tuple_frontend->GetChildAtIndex(0); - if (m_ptr_obj) - m_ptr_obj->SetName(ConstString("pointer")); + ValueObjectSP ptr_obj = tuple_frontend->GetChildAtIndex(0); + if (ptr_obj) + m_ptr_obj = ptr_obj->Clone(ConstString("pointer")); - m_del_obj = tuple_frontend->GetChildAtIndex(1); - if (m_del_obj) - m_del_obj->SetName(ConstString("deleter")); + ValueObjectSP del_obj = tuple_frontend->GetChildAtIndex(1); + if (del_obj) + m_del_obj = del_obj->Clone(ConstString("deleter")); if (m_ptr_obj) { Error error; - m_obj_obj = m_ptr_obj->Dereference(error); + ValueObjectSP obj_obj = m_ptr_obj->Dereference(error); if (error.Success()) { - m_obj_obj->SetName(ConstString("object")); + m_obj_obj = obj_obj->Clone(ConstString("object")); } } @@ -94,29 +94,28 @@ bool LibStdcppUniquePtrSyntheticFrontEnd::MightHaveChildren() { return true; } lldb::ValueObjectSP LibStdcppUniquePtrSyntheticFrontEnd::GetChildAtIndex(size_t idx) { if (idx == 0) - return m_obj_obj; + return m_ptr_obj; if (idx == 1) return m_del_obj; if (idx == 2) - return m_ptr_obj; + return m_obj_obj; return lldb::ValueObjectSP(); } size_t LibStdcppUniquePtrSyntheticFrontEnd::CalculateNumChildren() { if (m_del_obj) return 2; - if (m_ptr_obj && m_ptr_obj->GetValueAsUnsigned(0) != 0) - return 1; - return 0; + return 1; } size_t LibStdcppUniquePtrSyntheticFrontEnd::GetIndexOfChildWithName( const ConstString &name) { - if (name == ConstString("obj") || name == ConstString("object")) + if (name == ConstString("ptr") || name == ConstString("pointer")) return 0; if (name == ConstString("del") || name == ConstString("deleter")) return 1; - if (name == ConstString("ptr") || name == ConstString("pointer")) + if (name == ConstString("obj") || name == ConstString("object") || + name == ConstString("$$dereference$$")) return 2; return UINT32_MAX; } diff --git a/source/Plugins/Language/Go/CMakeLists.txt b/source/Plugins/Language/Go/CMakeLists.txt index f3a9c12b7523..793e417a618a 100644 --- a/source/Plugins/Language/Go/CMakeLists.txt +++ b/source/Plugins/Language/Go/CMakeLists.txt @@ -1,4 +1,13 @@ -add_lldb_library(lldbPluginGoLanguage +add_lldb_library(lldbPluginGoLanguage PLUGIN GoLanguage.cpp GoFormatterFunctions.cpp + + LINK_LIBS + clangAST + lldbCore + lldbDataFormatters + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/Language/Go/GoFormatterFunctions.h b/source/Plugins/Language/Go/GoFormatterFunctions.h index 596eb2ae71f6..1bf1892d6669 100644 --- a/source/Plugins/Language/Go/GoFormatterFunctions.h +++ b/source/Plugins/Language/Go/GoFormatterFunctions.h @@ -21,12 +21,12 @@ // Project includes #include "lldb/lldb-forward.h" -#include "lldb/Core/ConstString.h" #include "lldb/DataFormatters/FormatClasses.h" #include "lldb/DataFormatters/TypeSynthetic.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/ConstString.h" namespace lldb_private { namespace formatters { diff --git a/source/Plugins/Language/Go/GoLanguage.cpp b/source/Plugins/Language/Go/GoLanguage.cpp index 85c41d1fe917..66b4530abc76 100644 --- a/source/Plugins/Language/Go/GoLanguage.cpp +++ b/source/Plugins/Language/Go/GoLanguage.cpp @@ -15,14 +15,15 @@ // Other libraries and framework includes #include "llvm/ADT/StringRef.h" +#include "llvm/Support/Threading.h" // Project includes #include "GoLanguage.h" #include "Plugins/Language/Go/GoFormatterFunctions.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/PluginManager.h" #include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/Symbol/GoASTContext.h" +#include "lldb/Utility/ConstString.h" using namespace lldb; using namespace lldb_private; @@ -62,10 +63,10 @@ Language *GoLanguage::CreateInstance(lldb::LanguageType language) { HardcodedFormatters::HardcodedSummaryFinder GoLanguage::GetHardcodedSummaries() { - static std::once_flag g_initialize; + static llvm::once_flag g_initialize; static HardcodedFormatters::HardcodedSummaryFinder g_formatters; - std::call_once(g_initialize, []() -> void { + llvm::call_once(g_initialize, []() -> void { g_formatters.push_back( [](lldb_private::ValueObject &valobj, lldb::DynamicValueType, FormatManager &) -> TypeSummaryImpl::SharedPointer { @@ -104,10 +105,10 @@ GoLanguage::GetHardcodedSummaries() { HardcodedFormatters::HardcodedSyntheticFinder GoLanguage::GetHardcodedSynthetics() { - static std::once_flag g_initialize; + static llvm::once_flag g_initialize; static HardcodedFormatters::HardcodedSyntheticFinder g_formatters; - std::call_once(g_initialize, []() -> void { + llvm::call_once(g_initialize, []() -> void { g_formatters.push_back( [](lldb_private::ValueObject &valobj, lldb::DynamicValueType, FormatManager &fmt_mgr) -> SyntheticChildren::SharedPointer { diff --git a/source/Plugins/Language/Go/GoLanguage.h b/source/Plugins/Language/Go/GoLanguage.h index 4dc8ed0745c4..ebec1d7205fa 100644 --- a/source/Plugins/Language/Go/GoLanguage.h +++ b/source/Plugins/Language/Go/GoLanguage.h @@ -18,8 +18,8 @@ #include "llvm/ADT/StringRef.h" // Project includes -#include "lldb/Core/ConstString.h" #include "lldb/Target/Language.h" +#include "lldb/Utility/ConstString.h" #include "lldb/lldb-private.h" namespace lldb_private { diff --git a/source/Plugins/Language/Java/CMakeLists.txt b/source/Plugins/Language/Java/CMakeLists.txt index 80f7b08e7b65..f0cbcd8d3f59 100644 --- a/source/Plugins/Language/Java/CMakeLists.txt +++ b/source/Plugins/Language/Java/CMakeLists.txt @@ -1,4 +1,12 @@ -add_lldb_library(lldbPluginJavaLanguage +add_lldb_library(lldbPluginJavaLanguage PLUGIN JavaFormatterFunctions.cpp JavaLanguage.cpp + + LINK_LIBS + lldbCore + lldbDataFormatters + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/Language/Java/JavaLanguage.cpp b/source/Plugins/Language/Java/JavaLanguage.cpp index f58b51f53e76..b17862f0b6a2 100644 --- a/source/Plugins/Language/Java/JavaLanguage.cpp +++ b/source/Plugins/Language/Java/JavaLanguage.cpp @@ -15,15 +15,16 @@ // Other libraries and framework includes #include "llvm/ADT/StringRef.h" +#include "llvm/Support/Threading.h" // Project includes #include "JavaFormatterFunctions.h" #include "JavaLanguage.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/PluginManager.h" #include "lldb/DataFormatters/DataVisualization.h" #include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/Symbol/JavaASTContext.h" +#include "lldb/Utility/ConstString.h" using namespace lldb; using namespace lldb_private; @@ -64,10 +65,10 @@ bool JavaLanguage::IsNilReference(ValueObject &valobj) { } lldb::TypeCategoryImplSP JavaLanguage::GetFormatters() { - static std::once_flag g_initialize; + static llvm::once_flag g_initialize; static TypeCategoryImplSP g_category; - std::call_once(g_initialize, [this]() -> void { + llvm::call_once(g_initialize, [this]() -> void { DataVisualization::Categories::GetCategory(GetPluginName(), g_category); if (g_category) { llvm::StringRef array_regexp("^.*\\[\\]&?$"); diff --git a/source/Plugins/Language/Java/JavaLanguage.h b/source/Plugins/Language/Java/JavaLanguage.h index 6cf27ab5ffa4..5b652502a3d1 100644 --- a/source/Plugins/Language/Java/JavaLanguage.h +++ b/source/Plugins/Language/Java/JavaLanguage.h @@ -18,8 +18,8 @@ #include "llvm/ADT/StringRef.h" // Project includes -#include "lldb/Core/ConstString.h" #include "lldb/Target/Language.h" +#include "lldb/Utility/ConstString.h" #include "lldb/lldb-private.h" namespace lldb_private { diff --git a/source/Plugins/Language/OCaml/CMakeLists.txt b/source/Plugins/Language/OCaml/CMakeLists.txt index e969618d5e0c..e779ae2acd08 100644 --- a/source/Plugins/Language/OCaml/CMakeLists.txt +++ b/source/Plugins/Language/OCaml/CMakeLists.txt @@ -1,4 +1,12 @@ -add_lldb_library(lldbPluginOCamlLanguage +add_lldb_library(lldbPluginOCamlLanguage PLUGIN OCamlLanguage.cpp + + LINK_LIBS + lldbCore + lldbDataFormatters + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/Language/OCaml/OCamlLanguage.cpp b/source/Plugins/Language/OCaml/OCamlLanguage.cpp index ef9f2b567929..ec24a36fe8f3 100644 --- a/source/Plugins/Language/OCaml/OCamlLanguage.cpp +++ b/source/Plugins/Language/OCaml/OCamlLanguage.cpp @@ -19,11 +19,11 @@ // Project includes #include "OCamlLanguage.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/PluginManager.h" #include "lldb/DataFormatters/DataVisualization.h" #include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/Symbol/OCamlASTContext.h" +#include "lldb/Utility/ConstString.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/Language/OCaml/OCamlLanguage.h b/source/Plugins/Language/OCaml/OCamlLanguage.h index f7dc6398eafe..21837fe5add4 100644 --- a/source/Plugins/Language/OCaml/OCamlLanguage.h +++ b/source/Plugins/Language/OCaml/OCamlLanguage.h @@ -19,8 +19,8 @@ #include "llvm/ADT/StringRef.h" // Project includes -#include "lldb/Core/ConstString.h" #include "lldb/Target/Language.h" +#include "lldb/Utility/ConstString.h" #include "lldb/lldb-private.h" namespace lldb_private { diff --git a/source/Plugins/Language/ObjC/CF.cpp b/source/Plugins/Language/ObjC/CF.cpp index f67db465f72c..a75c034afa9f 100644 --- a/source/Plugins/Language/ObjC/CF.cpp +++ b/source/Plugins/Language/ObjC/CF.cpp @@ -10,18 +10,18 @@ #include "CF.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" -#include "lldb/Host/Endian.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/Language.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Stream.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/Language/ObjC/CF.h b/source/Plugins/Language/ObjC/CF.h index ea47267db939..6945f9e8c9b1 100644 --- a/source/Plugins/Language/ObjC/CF.h +++ b/source/Plugins/Language/ObjC/CF.h @@ -10,9 +10,9 @@ #ifndef liblldb_CF_h_ #define liblldb_CF_h_ -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/TypeSummary.h" +#include "lldb/Utility/Stream.h" namespace lldb_private { namespace formatters { diff --git a/source/Plugins/Language/ObjC/CMakeLists.txt b/source/Plugins/Language/ObjC/CMakeLists.txt index 5c480a1aed11..7cc93c7b0558 100644 --- a/source/Plugins/Language/ObjC/CMakeLists.txt +++ b/source/Plugins/Language/ObjC/CMakeLists.txt @@ -1,4 +1,4 @@ -add_lldb_library(lldbPluginObjCLanguage +add_lldb_library(lldbPluginObjCLanguage PLUGIN ObjCLanguage.cpp CF.cpp Cocoa.cpp @@ -10,4 +10,15 @@ add_lldb_library(lldbPluginObjCLanguage NSIndexPath.cpp NSSet.cpp NSString.cpp + + LINK_LIBS + clangAST + lldbCore + lldbDataFormatters + lldbExpression + lldbHost + lldbSymbol + lldbTarget + lldbUtility + lldbPluginAppleObjCRuntime ) diff --git a/source/Plugins/Language/ObjC/Cocoa.cpp b/source/Plugins/Language/ObjC/Cocoa.cpp index b2ad8c375833..0fc690606d16 100644 --- a/source/Plugins/Language/ObjC/Cocoa.cpp +++ b/source/Plugins/Language/ObjC/Cocoa.cpp @@ -13,22 +13,23 @@ // Project includes #include "Cocoa.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Error.h" #include "lldb/Core/Mangled.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/DataFormatters/StringPrinter.h" #include "lldb/DataFormatters/TypeSummary.h" -#include "lldb/Host/Endian.h" +#include "lldb/Host/Time.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/Language.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/Target/Process.h" +#include "lldb/Target/ProcessStructReader.h" #include "lldb/Target/Target.h" -#include "lldb/Utility/ProcessStructReader.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Stream.h" #include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h" diff --git a/source/Plugins/Language/ObjC/Cocoa.h b/source/Plugins/Language/ObjC/Cocoa.h index 491a1196e63d..10ff3bce3b98 100644 --- a/source/Plugins/Language/ObjC/Cocoa.h +++ b/source/Plugins/Language/ObjC/Cocoa.h @@ -11,11 +11,11 @@ #ifndef liblldb_Cocoa_h_ #define liblldb_Cocoa_h_ -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/TypeSummary.h" #include "lldb/DataFormatters/TypeSynthetic.h" #include "lldb/Target/ObjCLanguageRuntime.h" +#include "lldb/Utility/Stream.h" namespace lldb_private { namespace formatters { diff --git a/source/Plugins/Language/ObjC/CoreMedia.cpp b/source/Plugins/Language/ObjC/CoreMedia.cpp index dacbf78755e0..cbc38c907953 100644 --- a/source/Plugins/Language/ObjC/CoreMedia.cpp +++ b/source/Plugins/Language/ObjC/CoreMedia.cpp @@ -10,7 +10,8 @@ #include "CoreMedia.h" -#include "lldb/Core/Flags.h" +#include "lldb/Utility/Flags.h" + #include "lldb/Symbol/TypeSystem.h" #include "lldb/Target/Target.h" #include <inttypes.h> diff --git a/source/Plugins/Language/ObjC/CoreMedia.h b/source/Plugins/Language/ObjC/CoreMedia.h index 20de792fc96c..98561efbf7ed 100644 --- a/source/Plugins/Language/ObjC/CoreMedia.h +++ b/source/Plugins/Language/ObjC/CoreMedia.h @@ -11,9 +11,9 @@ #ifndef liblldb_CoreMedia_h_ #define liblldb_CoreMedia_h_ -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/TypeSummary.h" +#include "lldb/Utility/Stream.h" namespace lldb_private { namespace formatters { diff --git a/source/Plugins/Language/ObjC/NSArray.cpp b/source/Plugins/Language/ObjC/NSArray.cpp index 6ab6d537bb21..79773fdf1d15 100644 --- a/source/Plugins/Language/ObjC/NSArray.cpp +++ b/source/Plugins/Language/ObjC/NSArray.cpp @@ -16,18 +16,18 @@ #include "Cocoa.h" #include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/Expression/FunctionCaller.h" -#include "lldb/Host/Endian.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/Language.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Stream.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/Language/ObjC/NSDictionary.cpp b/source/Plugins/Language/ObjC/NSDictionary.cpp index 5cc52c820b65..672cc1a26f4e 100644 --- a/source/Plugins/Language/ObjC/NSDictionary.cpp +++ b/source/Plugins/Language/ObjC/NSDictionary.cpp @@ -17,18 +17,18 @@ // Project includes #include "NSDictionary.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" -#include "lldb/Host/Endian.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/Language.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Stream.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/Language/ObjC/NSDictionary.h b/source/Plugins/Language/ObjC/NSDictionary.h index 10318a5bf621..6ec9a8eebe13 100644 --- a/source/Plugins/Language/ObjC/NSDictionary.h +++ b/source/Plugins/Language/ObjC/NSDictionary.h @@ -11,11 +11,11 @@ #ifndef liblldb_NSDictionary_h_ #define liblldb_NSDictionary_h_ -#include "lldb/Core/ConstString.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/TypeSummary.h" #include "lldb/DataFormatters/TypeSynthetic.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Stream.h" #include <map> #include <memory> diff --git a/source/Plugins/Language/ObjC/NSError.cpp b/source/Plugins/Language/ObjC/NSError.cpp index bad22b13a005..e8044d3b0013 100644 --- a/source/Plugins/Language/ObjC/NSError.cpp +++ b/source/Plugins/Language/ObjC/NSError.cpp @@ -15,18 +15,17 @@ // Project includes #include "Cocoa.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" -#include "lldb/Host/Endian.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/ObjCLanguageRuntime.h" +#include "lldb/Target/ProcessStructReader.h" #include "lldb/Target/Target.h" - -#include "lldb/Utility/ProcessStructReader.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Stream.h" #include "Plugins/Language/ObjC/NSString.h" diff --git a/source/Plugins/Language/ObjC/NSException.cpp b/source/Plugins/Language/ObjC/NSException.cpp index 1609048d432c..aa86e207783d 100644 --- a/source/Plugins/Language/ObjC/NSException.cpp +++ b/source/Plugins/Language/ObjC/NSException.cpp @@ -15,18 +15,17 @@ // Project includes #include "Cocoa.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" -#include "lldb/Host/Endian.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/ObjCLanguageRuntime.h" +#include "lldb/Target/ProcessStructReader.h" #include "lldb/Target/Target.h" - -#include "lldb/Utility/ProcessStructReader.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Stream.h" #include "Plugins/Language/ObjC/NSString.h" diff --git a/source/Plugins/Language/ObjC/NSSet.cpp b/source/Plugins/Language/ObjC/NSSet.cpp index 9757c5877782..adefba902b61 100644 --- a/source/Plugins/Language/ObjC/NSSet.cpp +++ b/source/Plugins/Language/ObjC/NSSet.cpp @@ -13,17 +13,17 @@ // Project includes #include "NSSet.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" -#include "lldb/Host/Endian.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/Language.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Stream.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/Language/ObjC/NSSet.h b/source/Plugins/Language/ObjC/NSSet.h index dbc5dfa7e659..00451be6c7f3 100644 --- a/source/Plugins/Language/ObjC/NSSet.h +++ b/source/Plugins/Language/ObjC/NSSet.h @@ -11,11 +11,11 @@ #ifndef liblldb_NSSet_h_ #define liblldb_NSSet_h_ -#include "lldb/Core/ConstString.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/TypeSummary.h" #include "lldb/DataFormatters/TypeSynthetic.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Stream.h" namespace lldb_private { namespace formatters { diff --git a/source/Plugins/Language/ObjC/NSString.cpp b/source/Plugins/Language/ObjC/NSString.cpp index 4f1addccecaa..d0258be8211e 100644 --- a/source/Plugins/Language/ObjC/NSString.cpp +++ b/source/Plugins/Language/ObjC/NSString.cpp @@ -10,18 +10,18 @@ #include "NSString.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/DataFormatters/StringPrinter.h" -#include "lldb/Host/Endian.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Target/Language.h" +#include "lldb/Target/ProcessStructReader.h" #include "lldb/Target/Target.h" -#include "lldb/Utility/ProcessStructReader.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Endian.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Stream.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/Language/ObjC/NSString.h b/source/Plugins/Language/ObjC/NSString.h index df8480ad6cd8..3a923c2be6ac 100644 --- a/source/Plugins/Language/ObjC/NSString.h +++ b/source/Plugins/Language/ObjC/NSString.h @@ -11,10 +11,10 @@ #ifndef liblldb_NSString_h_ #define liblldb_NSString_h_ -#include "lldb/Core/Stream.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/TypeSummary.h" #include "lldb/Target/ObjCLanguageRuntime.h" +#include "lldb/Utility/Stream.h" namespace lldb_private { namespace formatters { diff --git a/source/Plugins/Language/ObjC/ObjCLanguage.cpp b/source/Plugins/Language/ObjC/ObjCLanguage.cpp index 6e59a8be3fea..193c5864d01f 100644 --- a/source/Plugins/Language/ObjC/ObjCLanguage.cpp +++ b/source/Plugins/Language/ObjC/ObjCLanguage.cpp @@ -15,9 +15,7 @@ // Project includes #include "ObjCLanguage.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/StreamString.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/DataVisualization.h" #include "lldb/DataFormatters/FormattersHelpers.h" @@ -25,6 +23,10 @@ #include "lldb/Symbol/CompilerType.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/StreamString.h" + +#include "llvm/Support/Threading.h" #include "CF.h" #include "Cocoa.h" @@ -857,10 +859,10 @@ static void LoadCoreMediaFormatters(TypeCategoryImplSP objc_category_sp) { } lldb::TypeCategoryImplSP ObjCLanguage::GetFormatters() { - static std::once_flag g_initialize; + static llvm::once_flag g_initialize; static TypeCategoryImplSP g_category; - std::call_once(g_initialize, [this]() -> void { + llvm::call_once(g_initialize, [this]() -> void { DataVisualization::Categories::GetCategory(GetPluginName(), g_category); if (g_category) { LoadCoreMediaFormatters(g_category); diff --git a/source/Plugins/Language/ObjC/ObjCLanguage.h b/source/Plugins/Language/ObjC/ObjCLanguage.h index b458b58998b6..9782c5da0d67 100644 --- a/source/Plugins/Language/ObjC/ObjCLanguage.h +++ b/source/Plugins/Language/ObjC/ObjCLanguage.h @@ -17,8 +17,8 @@ // Other libraries and framework includes // Project includes -#include "lldb/Core/ConstString.h" #include "lldb/Target/Language.h" +#include "lldb/Utility/ConstString.h" #include "lldb/lldb-private.h" namespace lldb_private { diff --git a/source/Plugins/Language/ObjCPlusPlus/CMakeLists.txt b/source/Plugins/Language/ObjCPlusPlus/CMakeLists.txt index ef80af74107b..75df9794d75d 100644 --- a/source/Plugins/Language/ObjCPlusPlus/CMakeLists.txt +++ b/source/Plugins/Language/ObjCPlusPlus/CMakeLists.txt @@ -1,3 +1,7 @@ -add_lldb_library(lldbPluginObjCPlusPlusLanguage +add_lldb_library(lldbPluginObjCPlusPlusLanguage PLUGIN ObjCPlusPlusLanguage.cpp + + LINK_LIBS + lldbCore + lldbTarget ) diff --git a/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.cpp b/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.cpp index cb73eef54682..bfc22c9ee650 100644 --- a/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.cpp +++ b/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.cpp @@ -10,8 +10,8 @@ #include "ObjCPlusPlusLanguage.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/PluginManager.h" +#include "lldb/Utility/ConstString.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/CMakeLists.txt b/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/CMakeLists.txt index d25215d0a613..14d1f46caebb 100644 --- a/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/CMakeLists.txt +++ b/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginCXXItaniumABI +add_lldb_library(lldbPluginCXXItaniumABI PLUGIN ItaniumABILanguageRuntime.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbInterpreter + lldbSymbol + lldbTarget ) diff --git a/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp b/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp index ddfbd864e92c..e308747378d3 100644 --- a/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp +++ b/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp @@ -11,9 +11,6 @@ #include "ItaniumABILanguageRuntime.h" #include "lldb/Breakpoint/BreakpointLocation.h" -#include "lldb/Core/ConstString.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Mangled.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" @@ -33,6 +30,9 @@ #include "lldb/Target/StopInfo.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" #include <vector> diff --git a/source/Plugins/LanguageRuntime/Go/CMakeLists.txt b/source/Plugins/LanguageRuntime/Go/CMakeLists.txt index 7c9166a94cbe..16756d5c985a 100644 --- a/source/Plugins/LanguageRuntime/Go/CMakeLists.txt +++ b/source/Plugins/LanguageRuntime/Go/CMakeLists.txt @@ -1,5 +1,13 @@ set(LLVM_NO_RTTI 1) -add_lldb_library(lldbPluginLanguageRuntimeGo +add_lldb_library(lldbPluginLanguageRuntimeGo PLUGIN GoLanguageRuntime.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.cpp b/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.cpp index 1450835298e6..c52fc1e121d8 100644 --- a/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.cpp +++ b/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.cpp @@ -11,9 +11,6 @@ #include "GoLanguageRuntime.h" #include "lldb/Breakpoint/BreakpointLocation.h" -#include "lldb/Core/ConstString.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Scalar.h" @@ -29,6 +26,9 @@ #include "lldb/Target/StopInfo.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" #include "llvm/ADT/Twine.h" #include <vector> diff --git a/source/Plugins/LanguageRuntime/Java/CMakeLists.txt b/source/Plugins/LanguageRuntime/Java/CMakeLists.txt index 4cfd71c2e242..ec87718752e7 100644 --- a/source/Plugins/LanguageRuntime/Java/CMakeLists.txt +++ b/source/Plugins/LanguageRuntime/Java/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginLanguageRuntimeJava +add_lldb_library(lldbPluginLanguageRuntimeJava PLUGIN JavaLanguageRuntime.cpp + + LINK_LIBS + lldbCore + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp index 131f31f69a9f..6b5e6b1eb764 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp @@ -10,8 +10,8 @@ #include "AppleObjCClassDescriptorV2.h" -#include "lldb/Core/Log.h" #include "lldb/Expression/FunctionCaller.h" +#include "lldb/Utility/Log.h" using namespace lldb; using namespace lldb_private; @@ -501,10 +501,8 @@ void ClassDescriptorV2::iVarsStorage::fill(AppleObjCRuntimeV2 &runtime, if (m_filled) return; std::lock_guard<std::recursive_mutex> guard(m_mutex); - Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES | LIBLLDB_LOG_VERBOSE)); - if (log) - log->Printf("[ClassDescriptorV2::iVarsStorage::fill] class_name = %s", - descriptor.GetClassName().AsCString("<unknown")); + Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES)); + LLDB_LOGV(log, "class_name = {0}", descriptor.GetClassName()); m_filled = true; ObjCLanguageRuntime::EncodingToTypeSP encoding_to_type_sp( runtime.GetEncodingToType()); @@ -519,19 +517,15 @@ void ClassDescriptorV2::iVarsStorage::fill(AppleObjCRuntimeV2 &runtime, uint64_t size) -> bool { const bool for_expression = false; const bool stop_loop = false; - if (log) - log->Printf("[ClassDescriptorV2::iVarsStorage::fill] name = %s, encoding " - "= %s, offset_ptr = %" PRIx64 ", size = %" PRIu64, - name, type, offset_ptr, size); + LLDB_LOGV(log, "name = {0}, encoding = {1}, offset_ptr = {2:x}, size = {3}", + name, type, offset_ptr, size); CompilerType ivar_type = encoding_to_type_sp->RealizeType(type, for_expression); if (ivar_type) { - if (log) - log->Printf("[ClassDescriptorV2::iVarsStorage::fill] name = %s, " - "encoding = %s, offset_ptr = %" PRIx64 ", size = %" PRIu64 - " , type_size = %" PRIu64, - name, type, offset_ptr, size, - ivar_type.GetByteSize(nullptr)); + LLDB_LOGV(log, + "name = {0}, encoding = {1}, offset_ptr = {2:x}, size = " + "{3}, type_size = {4}", + name, type, offset_ptr, size, ivar_type.GetByteSize(nullptr)); Scalar offset_scalar; Error error; const int offset_ptr_size = 4; @@ -539,18 +533,13 @@ void ClassDescriptorV2::iVarsStorage::fill(AppleObjCRuntimeV2 &runtime, size_t read = process->ReadScalarIntegerFromMemory( offset_ptr, offset_ptr_size, is_signed, offset_scalar, error); if (error.Success() && 4 == read) { - if (log) - log->Printf( - "[ClassDescriptorV2::iVarsStorage::fill] offset_ptr = %" PRIx64 - " --> %" PRIu32, - offset_ptr, offset_scalar.SInt()); + LLDB_LOGV(log, "offset_ptr = {0:x} --> {1}", offset_ptr, + offset_scalar.SInt()); m_ivars.push_back( {ConstString(name), ivar_type, size, offset_scalar.SInt()}); - } else if (log) - log->Printf( - "[ClassDescriptorV2::iVarsStorage::fill] offset_ptr = %" PRIx64 - " --> read fail, read = %zu", - offset_ptr, read); + } else + LLDB_LOGV(log, "offset_ptr = {0:x} --> read fail, read = %{1}", + offset_ptr, read); } return stop_loop; }); diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp index 922d192c333c..07b4ae5e0add 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp @@ -10,13 +10,13 @@ #include "AppleObjCDeclVendor.h" #include "Plugins/ExpressionParser/Clang/ASTDumper.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Symbol/ClangExternalASTSourceCommon.h" #include "lldb/Symbol/ClangUtil.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/Log.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclObjC.h" diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp index 4a90f5c16633..6b27009a0727 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp @@ -14,15 +14,11 @@ #include "clang/AST/Type.h" #include "lldb/Breakpoint/BreakpointLocation.h" -#include "lldb/Core/ConstString.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Scalar.h" #include "lldb/Core/Section.h" -#include "lldb/Core/StreamString.h" #include "lldb/Core/ValueObject.h" #include "lldb/Expression/DiagnosticManager.h" #include "lldb/Expression/FunctionCaller.h" @@ -34,6 +30,10 @@ #include "lldb/Target/StopInfo.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" #include <vector> diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp index 13bd245a33b4..2c92b922b9df 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp @@ -15,13 +15,9 @@ #include "clang/AST/Type.h" #include "lldb/Breakpoint/BreakpointLocation.h" -#include "lldb/Core/ConstString.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Scalar.h" -#include "lldb/Core/StreamString.h" #include "lldb/Expression/FunctionCaller.h" #include "lldb/Expression/UtilityFunction.h" #include "lldb/Symbol/ClangASTContext.h" @@ -31,6 +27,10 @@ #include "lldb/Target/RegisterContext.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" #include <vector> @@ -127,7 +127,7 @@ struct BufStruct { UtilityFunction *AppleObjCRuntimeV1::CreateObjectChecker(const char *name) { std::unique_ptr<BufStruct> buf(new BufStruct); - assert(snprintf(&buf->contents[0], sizeof(buf->contents), + int strformatsize = snprintf(&buf->contents[0], sizeof(buf->contents), "struct __objc_class " " \n" "{ " @@ -169,7 +169,8 @@ UtilityFunction *AppleObjCRuntimeV1::CreateObjectChecker(const char *name) { " \n" "} " " \n", - name) < (int)sizeof(buf->contents)); + name); + assert(strformatsize < (int)sizeof(buf->contents)); Error error; return GetTargetRef().GetUtilityFunctionForLanguage( diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index e9958a5ef759..42c5fe9248f6 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -20,26 +20,21 @@ // Project includes #include "lldb/Core/ClangForward.h" +#include "lldb/Host/OptionParser.h" #include "lldb/Symbol/CompilerType.h" #include "lldb/lldb-enumerations.h" #include "lldb/Core/ClangForward.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Scalar.h" #include "lldb/Core/Section.h" -#include "lldb/Core/Stream.h" -#include "lldb/Core/StreamString.h" #include "lldb/Core/Timer.h" #include "lldb/Core/ValueObjectVariable.h" #include "lldb/Expression/DiagnosticManager.h" #include "lldb/Expression/FunctionCaller.h" #include "lldb/Expression/UtilityFunction.h" -#include "lldb/Host/StringConvert.h" #include "lldb/Interpreter/CommandObject.h" #include "lldb/Interpreter/CommandObjectMultiword.h" #include "lldb/Interpreter/CommandReturnObject.h" @@ -55,6 +50,11 @@ #include "lldb/Target/RegisterContext.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/Stream.h" +#include "lldb/Utility/StreamString.h" #include "AppleObjCClassDescriptorV2.h" #include "AppleObjCDeclVendor.h" @@ -600,14 +600,12 @@ protected: } iterator->second->Describe( nullptr, - [objc_runtime, &std_out](const char *name, - const char *type) -> bool { + [&std_out](const char *name, const char *type) -> bool { std_out.Printf(" instance method name = %s type = %s\n", name, type); return false; }, - [objc_runtime, &std_out](const char *name, - const char *type) -> bool { + [&std_out](const char *name, const char *type) -> bool { std_out.Printf(" class method name = %s type = %s\n", name, type); return false; @@ -895,6 +893,7 @@ UtilityFunction *AppleObjCRuntimeV2::CreateObjectChecker(const char *name) { } assert(len < (int)sizeof(check_function_code)); + UNUSED_IF_ASSERT_DISABLED(len); Error error; return GetTargetRef().GetUtilityFunctionForLanguage( @@ -1396,8 +1395,13 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapDynamic( arguments.GetValueAtIndex(0)->GetScalar() = hash_table.GetTableLoadAddress(); arguments.GetValueAtIndex(1)->GetScalar() = class_infos_addr; arguments.GetValueAtIndex(2)->GetScalar() = class_infos_byte_size; - arguments.GetValueAtIndex(3)->GetScalar() = - (GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES) == nullptr ? 0 : 1); + + // Only dump the runtime classes from the expression evaluation if the + // log is verbose: + Log *type_log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES); + bool dump_log = type_log && type_log->GetVerbose(); + + arguments.GetValueAtIndex(3)->GetScalar() = dump_log ? 1 : 0; bool success = false; @@ -1640,8 +1644,12 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() { arguments.GetValueAtIndex(0)->GetScalar() = objc_opt_ptr; arguments.GetValueAtIndex(1)->GetScalar() = class_infos_addr; arguments.GetValueAtIndex(2)->GetScalar() = class_infos_byte_size; - arguments.GetValueAtIndex(3)->GetScalar() = - (GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES) == nullptr ? 0 : 1); + // Only dump the runtime classes from the expression evaluation if the + // log is verbose: + Log *type_log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES); + bool dump_log = type_log && type_log->GetVerbose(); + + arguments.GetValueAtIndex(3)->GetScalar() = dump_log ? 1 : 0; bool success = false; diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp index 1dc20c11567e..8ce65b07684f 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp @@ -17,9 +17,7 @@ #include "AppleThreadPlanStepThroughObjCTrampoline.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/StreamFile.h" #include "lldb/Core/Value.h" @@ -27,7 +25,6 @@ #include "lldb/Expression/FunctionCaller.h" #include "lldb/Expression/UserExpression.h" #include "lldb/Expression/UtilityFunction.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/Symbol.h" #include "lldb/Target/ABI.h" @@ -38,6 +35,9 @@ #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadPlanRunToAddress.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" #include "llvm/ADT/STLExtras.h" diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp index e49269532329..a295d1b4ce76 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp @@ -14,7 +14,6 @@ // Project includes #include "AppleThreadPlanStepThroughObjCTrampoline.h" #include "AppleObjCTrampolineHandler.h" -#include "lldb/Core/Log.h" #include "lldb/Expression/DiagnosticManager.h" #include "lldb/Expression/FunctionCaller.h" #include "lldb/Expression/UtilityFunction.h" @@ -24,6 +23,7 @@ #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadPlanRunToAddress.h" #include "lldb/Target/ThreadPlanStepOut.h" +#include "lldb/Utility/Log.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/CMakeLists.txt b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/CMakeLists.txt index 13fde3d181fa..18f3ae1c5b1e 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/CMakeLists.txt +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/CMakeLists.txt @@ -1,4 +1,4 @@ -add_lldb_library(lldbPluginAppleObjCRuntime +add_lldb_library(lldbPluginAppleObjCRuntime PLUGIN AppleObjCRuntime.cpp AppleObjCRuntimeV1.cpp AppleObjCRuntimeV2.cpp @@ -7,4 +7,18 @@ add_lldb_library(lldbPluginAppleObjCRuntime AppleThreadPlanStepThroughObjCTrampoline.cpp AppleObjCClassDescriptorV2.cpp AppleObjCTypeEncodingParser.cpp + + LINK_LIBS + clangAST + lldbBreakpoint + lldbCore + lldbExpression + lldbHost + lldbInterpreter + lldbSymbol + lldbTarget + lldbUtility + lldbPluginExpressionParserClang + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/CMakeLists.txt b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/CMakeLists.txt index cd08f14137dc..1a6c49946134 100644 --- a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/CMakeLists.txt +++ b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/CMakeLists.txt @@ -3,7 +3,7 @@ if(NOT LLDB_BUILT_STANDALONE) endif() -add_lldb_library(lldbPluginRenderScriptRuntime +add_lldb_library(lldbPluginRenderScriptRuntime PLUGIN RenderScriptRuntime.cpp RenderScriptExpressionOpts.cpp RenderScriptx86ABIFixups.cpp @@ -11,4 +11,20 @@ add_lldb_library(lldbPluginRenderScriptRuntime DEPENDS ${tablegen_deps} + + LINK_LIBS + clangBasic + lldbBreakpoint + lldbCore + lldbDataFormatters + lldbExpression + lldbHost + lldbInterpreter + lldbSymbol + lldbTarget + LINK_COMPONENTS + Core + IRReader + Support + Target ) diff --git a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptExpressionOpts.cpp b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptExpressionOpts.cpp index b05618634868..654ac9abfcab 100644 --- a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptExpressionOpts.cpp +++ b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptExpressionOpts.cpp @@ -25,9 +25,9 @@ #include "clang/Basic/TargetOptions.h" // Project includes -#include "lldb/Core/Log.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/Log.h" #include "RenderScriptExpressionOpts.h" #include "RenderScriptRuntime.h" diff --git a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp index ae907ac8dfbb..638112b9ebde 100644 --- a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp +++ b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp @@ -17,15 +17,14 @@ #include "RenderScriptScriptGroup.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" +#include "lldb/Core/DumpDataExtractor.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/RegularExpression.h" +#include "lldb/Core/RegisterValue.h" #include "lldb/Core/ValueObjectVariable.h" #include "lldb/DataFormatters/DumpValueObjectOptions.h" #include "lldb/Expression/UserExpression.h" +#include "lldb/Host/OptionParser.h" #include "lldb/Host/StringConvert.h" #include "lldb/Interpreter/Args.h" #include "lldb/Interpreter/CommandInterpreter.h" @@ -41,6 +40,11 @@ #include "lldb/Target/SectionLoadList.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/DataBufferLLVM.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/RegularExpression.h" using namespace lldb; using namespace lldb_private; @@ -2535,7 +2539,7 @@ bool RenderScriptRuntime::LoadAllocation(Stream &strm, const uint32_t alloc_id, } // Read file into data buffer - DataBufferSP data_sp(file.ReadFileContents()); + auto data_sp = DataBufferLLVM::CreateFromPath(file.GetPath()); // Cast start of buffer to FileHeader and use pointer to read metadata void *file_buf = data_sp->GetBytes(); @@ -3073,7 +3077,7 @@ bool RSModuleDescriptor::ParseRSInfo() { const addr_t size = info_sym->GetByteSize(); const FileSpec fs = m_module->GetFileSpec(); - const DataBufferSP buffer = fs.ReadFileContents(addr, size); + auto buffer = DataBufferLLVM::CreateSliceFromPath(fs.GetPath(), size, addr); if (!buffer) return false; @@ -3128,9 +3132,8 @@ bool RSModuleDescriptor::ParseRSInfo() { // in numeric fields at the moment uint64_t n_lines; if (val.getAsInteger(10, n_lines)) { - if (log) - log->Debug("Failed to parse non-numeric '.rs.info' section %s", - line->str().c_str()); + LLDB_LOGV(log, "Failed to parse non-numeric '.rs.info' section {0}", + line->str()); continue; } if (info_lines.end() - (line + 1) < (ptrdiff_t)n_lines) @@ -3410,8 +3413,9 @@ bool RenderScriptRuntime::DumpAllocation(Stream &strm, StackFrame *frame_ptr, // Print the results to our stream. expr_result->Dump(strm, expr_options); } else { - alloc_data.Dump(&strm, offset, format, data_size - padding, 1, 1, - LLDB_INVALID_ADDRESS, 0, 0); + DumpDataExtractor(alloc_data, &strm, offset, format, + data_size - padding, 1, 1, LLDB_INVALID_ADDRESS, 0, + 0); } offset += data_size; } diff --git a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptScriptGroup.cpp b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptScriptGroup.cpp index a8202dd08814..9ca8fb4444c0 100644 --- a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptScriptGroup.cpp +++ b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptScriptGroup.cpp @@ -8,12 +8,8 @@ //===----------------------------------------------------------------------===// #include "lldb/Breakpoint/StoppointCallbackContext.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Host/StringConvert.h" #include "lldb/Interpreter/Args.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandObjectMultiword.h" @@ -24,6 +20,9 @@ #include "lldb/Symbol/VariableList.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" #include "RenderScriptRuntime.h" #include "RenderScriptScriptGroup.h" diff --git a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp index aaca04582676..3ceda5ff67e9 100644 --- a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp +++ b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp @@ -24,8 +24,8 @@ #include "llvm/Pass.h" // Project includes -#include "lldb/Core/Log.h" #include "lldb/Target/Process.h" +#include "lldb/Utility/Log.h" using namespace lldb_private; namespace { @@ -182,8 +182,10 @@ bool fixupX86StructRetCalls(llvm::Module &module) { // we pass a pointer to this allocation as the StructRet param, and then // copy its // value into the lldb return value + const llvm::DataLayout &DL = module.getDataLayout(); llvm::AllocaInst *return_value_alloc = new llvm::AllocaInst( - func->getReturnType(), "var_vector_return_alloc", call_inst); + func->getReturnType(), DL.getAllocaAddrSpace(), "var_vector_return_alloc", + call_inst); // use the new allocation as the new first argument new_call_args.emplace(new_call_args.begin(), llvm::cast<llvm::Value>(return_value_alloc)); @@ -194,7 +196,8 @@ bool fixupX86StructRetCalls(llvm::Module &module) { llvm::Instruction::BitCast, func, new_func_ptr_type); // create an allocation for a new function pointer llvm::AllocaInst *new_func_ptr = - new llvm::AllocaInst(new_func_ptr_type, "new_func_ptr", call_inst); + new llvm::AllocaInst(new_func_ptr_type, DL.getAllocaAddrSpace(), + "new_func_ptr", call_inst); // store the new_func_cast to the newly allocated space (new llvm::StoreInst(new_func_cast, new_func_ptr, call_inst)) ->setName("new_func_ptr_load_cast"); @@ -248,7 +251,7 @@ bool fixupRSAllocationStructByValCalls(llvm::Module &module) { rs_functions.insert(call_inst->getCalledFunction()); // get the function attributes - llvm::AttributeSet call_attribs = call_inst->getAttributes(); + llvm::AttributeList call_attribs = call_inst->getAttributes(); // iterate over the argument attributes for (size_t i = 1; i <= call_attribs.getNumSlots(); ++i) { @@ -261,16 +264,12 @@ bool fixupRSAllocationStructByValCalls(llvm::Module &module) { } } - llvm::AttributeSet attr_byval = - llvm::AttributeSet::get(module.getContext(), 1u, llvm::Attribute::ByVal); - // for all called function decls for (auto func : rs_functions) { // inspect all of the arguments in the call - llvm::SymbolTableList<llvm::Argument> &arg_list = func->getArgumentList(); - for (auto &arg : arg_list) { + for (auto &arg : func->args()) { if (arg.hasByValAttr()) { - arg.removeAttr(attr_byval); + arg.removeAttr(llvm::Attribute::ByVal); changed = true; } } diff --git a/source/Plugins/MemoryHistory/asan/CMakeLists.txt b/source/Plugins/MemoryHistory/asan/CMakeLists.txt index 8bfe95e3680e..08deb75aabb1 100644 --- a/source/Plugins/MemoryHistory/asan/CMakeLists.txt +++ b/source/Plugins/MemoryHistory/asan/CMakeLists.txt @@ -1,3 +1,9 @@ -add_lldb_library(lldbPluginMemoryHistoryASan +add_lldb_library(lldbPluginMemoryHistoryASan PLUGIN MemoryHistoryASan.cpp + + LINK_LIBS + lldbCore + lldbExpression + lldbTarget + lldbPluginProcessUtility ) diff --git a/source/Plugins/ObjectContainer/BSD-Archive/CMakeLists.txt b/source/Plugins/ObjectContainer/BSD-Archive/CMakeLists.txt index 68ebe885e3e9..acc13d31ca25 100644 --- a/source/Plugins/ObjectContainer/BSD-Archive/CMakeLists.txt +++ b/source/Plugins/ObjectContainer/BSD-Archive/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginObjectContainerBSDArchive +add_lldb_library(lldbPluginObjectContainerBSDArchive PLUGIN ObjectContainerBSDArchive.cpp + + LINK_LIBS + lldbCore + lldbHost + lldbSymbol + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp b/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp index 5bca1de89fbd..b74da3300170 100644 --- a/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp +++ b/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp @@ -28,14 +28,16 @@ typedef struct ar_hdr { #endif #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/DataBuffer.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/Timer.h" #include "lldb/Host/FileSystem.h" #include "lldb/Symbol/ObjectFile.h" +#include "lldb/Utility/DataBufferLLVM.h" +#include "lldb/Utility/Stream.h" + +#include "llvm/Support/MemoryBuffer.h" using namespace lldb; using namespace lldb_private; @@ -290,62 +292,65 @@ ObjectContainer *ObjectContainerBSDArchive::CreateInstance( lldb::offset_t data_offset, const FileSpec *file, lldb::offset_t file_offset, lldb::offset_t length) { ConstString object_name(module_sp->GetObjectName()); - if (object_name) { - if (data_sp) { - // We have data, which means this is the first 512 bytes of the file - // Check to see if the magic bytes match and if they do, read the entire - // table of contents for the archive and cache it - DataExtractor data; - data.SetData(data_sp, data_offset, length); - if (file && data_sp && ObjectContainerBSDArchive::MagicBytesMatch(data)) { - Timer scoped_timer( - LLVM_PRETTY_FUNCTION, - "ObjectContainerBSDArchive::CreateInstance (module = %s, file = " - "%p, file_offset = 0x%8.8" PRIx64 ", file_size = 0x%8.8" PRIx64 ")", - module_sp->GetFileSpec().GetPath().c_str(), - static_cast<const void *>(file), static_cast<uint64_t>(file_offset), - static_cast<uint64_t>(length)); - - // Map the entire .a file to be sure that we don't lose any data if the - // file - // gets updated by a new build while this .a file is being used for - // debugging - DataBufferSP archive_data_sp( - file->MemoryMapFileContentsIfLocal(file_offset, length)); - lldb::offset_t archive_data_offset = 0; - - Archive::shared_ptr archive_sp(Archive::FindCachedArchive( - *file, module_sp->GetArchitecture(), - module_sp->GetModificationTime(), file_offset)); - std::unique_ptr<ObjectContainerBSDArchive> container_ap( - new ObjectContainerBSDArchive(module_sp, archive_data_sp, - archive_data_offset, file, - file_offset, length)); - - if (container_ap.get()) { - if (archive_sp) { - // We already have this archive in our cache, use it - container_ap->SetArchive(archive_sp); - return container_ap.release(); - } else if (container_ap->ParseHeader()) - return container_ap.release(); - } - } - } else { - // No data, just check for a cached archive + if (!object_name) + return nullptr; + + if (data_sp) { + // We have data, which means this is the first 512 bytes of the file + // Check to see if the magic bytes match and if they do, read the entire + // table of contents for the archive and cache it + DataExtractor data; + data.SetData(data_sp, data_offset, length); + if (file && data_sp && ObjectContainerBSDArchive::MagicBytesMatch(data)) { + Timer scoped_timer( + LLVM_PRETTY_FUNCTION, + "ObjectContainerBSDArchive::CreateInstance (module = %s, file = " + "%p, file_offset = 0x%8.8" PRIx64 ", file_size = 0x%8.8" PRIx64 ")", + module_sp->GetFileSpec().GetPath().c_str(), + static_cast<const void *>(file), static_cast<uint64_t>(file_offset), + static_cast<uint64_t>(length)); + + // Map the entire .a file to be sure that we don't lose any data if the + // file gets updated by a new build while this .a file is being used for + // debugging + DataBufferSP archive_data_sp = + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset); + if (!archive_data_sp) + return nullptr; + + lldb::offset_t archive_data_offset = 0; + Archive::shared_ptr archive_sp(Archive::FindCachedArchive( *file, module_sp->GetArchitecture(), module_sp->GetModificationTime(), file_offset)); - if (archive_sp) { - std::unique_ptr<ObjectContainerBSDArchive> container_ap( - new ObjectContainerBSDArchive(module_sp, data_sp, data_offset, file, - file_offset, length)); + std::unique_ptr<ObjectContainerBSDArchive> container_ap( + new ObjectContainerBSDArchive(module_sp, archive_data_sp, + archive_data_offset, file, file_offset, + length)); - if (container_ap.get()) { + if (container_ap.get()) { + if (archive_sp) { // We already have this archive in our cache, use it container_ap->SetArchive(archive_sp); return container_ap.release(); - } + } else if (container_ap->ParseHeader()) + return container_ap.release(); + } + } + } else { + // No data, just check for a cached archive + Archive::shared_ptr archive_sp(Archive::FindCachedArchive( + *file, module_sp->GetArchitecture(), module_sp->GetModificationTime(), + file_offset)); + if (archive_sp) { + std::unique_ptr<ObjectContainerBSDArchive> container_ap( + new ObjectContainerBSDArchive(module_sp, data_sp, data_offset, file, + file_offset, length)); + + if (container_ap.get()) { + // We already have this archive in our cache, use it + container_ap->SetArchive(archive_sp); + return container_ap.release(); } } } @@ -453,63 +458,64 @@ size_t ObjectContainerBSDArchive::GetModuleSpecifications( // table of contents for the archive and cache it DataExtractor data; data.SetData(data_sp, data_offset, data_sp->GetByteSize()); - if (file && data_sp && ObjectContainerBSDArchive::MagicBytesMatch(data)) { - const size_t initial_count = specs.GetSize(); - llvm::sys::TimePoint<> file_mod_time = - FileSystem::GetModificationTime(file); - Archive::shared_ptr archive_sp(Archive::FindCachedArchive( - file, ArchSpec(), file_mod_time, file_offset)); - bool set_archive_arch = false; - if (!archive_sp) { - set_archive_arch = true; - DataBufferSP data_sp( - file.MemoryMapFileContentsIfLocal(file_offset, file_size)); + if (!file || !data_sp || !ObjectContainerBSDArchive::MagicBytesMatch(data)) + return 0; + + const size_t initial_count = specs.GetSize(); + llvm::sys::TimePoint<> file_mod_time = FileSystem::GetModificationTime(file); + Archive::shared_ptr archive_sp( + Archive::FindCachedArchive(file, ArchSpec(), file_mod_time, file_offset)); + bool set_archive_arch = false; + if (!archive_sp) { + set_archive_arch = true; + data_sp = + DataBufferLLVM::CreateSliceFromPath(file.GetPath(), file_size, file_offset); + if (data_sp) { data.SetData(data_sp, 0, data_sp->GetByteSize()); archive_sp = Archive::ParseAndCacheArchiveForFile( file, ArchSpec(), file_mod_time, file_offset, data); } + } - if (archive_sp) { - const size_t num_objects = archive_sp->GetNumObjects(); - for (size_t idx = 0; idx < num_objects; ++idx) { - const Object *object = archive_sp->GetObjectAtIndex(idx); - if (object) { - const lldb::offset_t object_file_offset = - file_offset + object->ar_file_offset; - if (object->ar_file_offset < file_size && - file_size > object_file_offset) { - if (ObjectFile::GetModuleSpecifications( - file, object_file_offset, file_size - object_file_offset, - specs)) { - ModuleSpec &spec = - specs.GetModuleSpecRefAtIndex(specs.GetSize() - 1); - llvm::sys::TimePoint<> object_mod_time( - std::chrono::seconds(object->ar_date)); - spec.GetObjectName() = object->ar_name; - spec.SetObjectOffset(object_file_offset); - spec.SetObjectSize(file_size - object_file_offset); - spec.GetObjectModificationTime() = object_mod_time; - } + if (archive_sp) { + const size_t num_objects = archive_sp->GetNumObjects(); + for (size_t idx = 0; idx < num_objects; ++idx) { + const Object *object = archive_sp->GetObjectAtIndex(idx); + if (object) { + const lldb::offset_t object_file_offset = + file_offset + object->ar_file_offset; + if (object->ar_file_offset < file_size && + file_size > object_file_offset) { + if (ObjectFile::GetModuleSpecifications( + file, object_file_offset, file_size - object_file_offset, + specs)) { + ModuleSpec &spec = + specs.GetModuleSpecRefAtIndex(specs.GetSize() - 1); + llvm::sys::TimePoint<> object_mod_time( + std::chrono::seconds(object->ar_date)); + spec.GetObjectName() = object->ar_name; + spec.SetObjectOffset(object_file_offset); + spec.SetObjectSize(file_size - object_file_offset); + spec.GetObjectModificationTime() = object_mod_time; } } } } - const size_t end_count = specs.GetSize(); - size_t num_specs_added = end_count - initial_count; - if (set_archive_arch && num_specs_added > 0) { - // The archive was created but we didn't have an architecture - // so we need to set it - for (size_t i = initial_count; i < end_count; ++i) { - ModuleSpec module_spec; - if (specs.GetModuleSpecAtIndex(i, module_spec)) { - if (module_spec.GetArchitecture().IsValid()) { - archive_sp->SetArchitecture(module_spec.GetArchitecture()); - break; - } + } + const size_t end_count = specs.GetSize(); + size_t num_specs_added = end_count - initial_count; + if (set_archive_arch && num_specs_added > 0) { + // The archive was created but we didn't have an architecture + // so we need to set it + for (size_t i = initial_count; i < end_count; ++i) { + ModuleSpec module_spec; + if (specs.GetModuleSpecAtIndex(i, module_spec)) { + if (module_spec.GetArchitecture().IsValid()) { + archive_sp->SetArchitecture(module_spec.GetArchitecture()); + break; } } } - return num_specs_added; } - return 0; + return num_specs_added; } diff --git a/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h b/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h index de0f24e3bfcc..0e10d47f2ce4 100644 --- a/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h +++ b/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h @@ -12,16 +12,18 @@ // Project includes #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/ConstString.h" #include "lldb/Core/UniqueCStringMap.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Symbol/ObjectContainer.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/FileSpec.h" // Other libraries and framework includes #include "llvm/Support/Chrono.h" // C Includes // C++ Includes +#include <map> +#include <memory> #include <mutex> class ObjectContainerBSDArchive : public lldb_private::ObjectContainer { diff --git a/source/Plugins/ObjectContainer/Universal-Mach-O/CMakeLists.txt b/source/Plugins/ObjectContainer/Universal-Mach-O/CMakeLists.txt index b4553868bf94..9f173cf4c004 100644 --- a/source/Plugins/ObjectContainer/Universal-Mach-O/CMakeLists.txt +++ b/source/Plugins/ObjectContainer/Universal-Mach-O/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginObjectContainerMachOArchive +add_lldb_library(lldbPluginObjectContainerMachOArchive PLUGIN ObjectContainerUniversalMachO.cpp + + LINK_LIBS + lldbCore + lldbHost + lldbSymbol + lldbTarget + lldbUtility ) diff --git a/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp b/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp index a412254e1eb0..31eb17873f3e 100644 --- a/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp +++ b/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp @@ -9,13 +9,13 @@ #include "ObjectContainerUniversalMachO.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/DataBuffer.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/Stream.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBuffer.h" +#include "lldb/Utility/Stream.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h b/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h index 36542559e082..d3c0a080a6f9 100644 --- a/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h +++ b/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h @@ -14,8 +14,8 @@ // C++ Includes // Other libraries and framework includes // Project includes -#include "lldb/Host/FileSpec.h" #include "lldb/Symbol/ObjectContainer.h" +#include "lldb/Utility/FileSpec.h" #include "lldb/Utility/SafeMachO.h" class ObjectContainerUniversalMachO : public lldb_private::ObjectContainer { diff --git a/source/Plugins/ObjectFile/ELF/CMakeLists.txt b/source/Plugins/ObjectFile/ELF/CMakeLists.txt index 69ec80c62bf0..a941b8d55848 100644 --- a/source/Plugins/ObjectFile/ELF/CMakeLists.txt +++ b/source/Plugins/ObjectFile/ELF/CMakeLists.txt @@ -1,4 +1,12 @@ -add_lldb_library(lldbPluginObjectFileELF +add_lldb_library(lldbPluginObjectFileELF PLUGIN ELFHeader.cpp ObjectFileELF.cpp + + LINK_LIBS + lldbCore + lldbHost + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ObjectFile/ELF/ELFHeader.cpp b/source/Plugins/ObjectFile/ELF/ELFHeader.cpp index a3e82390d262..39ea49208700 100644 --- a/source/Plugins/ObjectFile/ELF/ELFHeader.cpp +++ b/source/Plugins/ObjectFile/ELF/ELFHeader.cpp @@ -9,9 +9,9 @@ #include <cstring> -#include "lldb/Core/DataExtractor.h" #include "lldb/Core/Section.h" -#include "lldb/Core/Stream.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Stream.h" #include "ELFHeader.h" @@ -81,6 +81,39 @@ ByteOrder ELFHeader::GetByteOrder() const { return eByteOrderInvalid; } +bool ELFHeader::HasHeaderExtension() const { + bool result = false; + + // Check if any of these values looks like sentinel. + result |= e_phnum_hdr == 0xFFFF; // PN_XNUM + result |= e_shnum_hdr == SHN_UNDEF; + result |= e_shstrndx_hdr == SHN_XINDEX; + + // If header extension is present, the section offset cannot be null. + result &= e_shoff != 0; + + // Done. + return result; +} + +void ELFHeader::ParseHeaderExtension(lldb_private::DataExtractor &data) { + // Extract section #0 header. + ELFSectionHeader section_zero; + lldb::offset_t offset = 0; + lldb_private::DataExtractor sh_data(data, e_shoff, e_shentsize); + bool ok = section_zero.Parse(sh_data, &offset); + + // If we succeeded, fix the header. + if (ok) { + if (e_phnum_hdr == 0xFFFF) // PN_XNUM + e_phnum = section_zero.sh_info; + if (e_shnum_hdr == SHN_UNDEF) + e_shnum = section_zero.sh_size; + if (e_shstrndx_hdr == SHN_XINDEX) + e_shstrndx = section_zero.sh_link; + } +} + bool ELFHeader::Parse(lldb_private::DataExtractor &data, lldb::offset_t *offset) { // Read e_ident. This provides byte order and address size info. @@ -112,6 +145,16 @@ bool ELFHeader::Parse(lldb_private::DataExtractor &data, if (data.GetU16(offset, &e_ehsize, 6) == NULL) return false; + // Initialize e_phnum, e_shnum, and e_shstrndx with the values + // read from the header. + e_phnum = e_phnum_hdr; + e_shnum = e_shnum_hdr; + e_shstrndx = e_shstrndx_hdr; + + // See if we have extended header in section #0. + if (HasHeaderExtension()) + ParseHeaderExtension(data); + return true; } diff --git a/source/Plugins/ObjectFile/ELF/ELFHeader.h b/source/Plugins/ObjectFile/ELF/ELFHeader.h index 71b200f1c16b..e6738a1ecb2b 100644 --- a/source/Plugins/ObjectFile/ELF/ELFHeader.h +++ b/source/Plugins/ObjectFile/ELF/ELFHeader.h @@ -24,6 +24,7 @@ #include "llvm/Support/ELF.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-types.h" namespace lldb_private { class DataExtractor; @@ -65,10 +66,17 @@ struct ELFHeader { elf_half e_machine; ///< Target architecture. elf_half e_ehsize; ///< Byte size of the ELF header. elf_half e_phentsize; ///< Size of a program header table entry. - elf_half e_phnum; ///< Number of program header entries. + elf_half e_phnum_hdr; ///< Number of program header entries. elf_half e_shentsize; ///< Size of a section header table entry. - elf_half e_shnum; ///< Number of section header entries. - elf_half e_shstrndx; ///< String table section index. + elf_half e_shnum_hdr; ///< Number of section header entries. + elf_half e_shstrndx_hdr; ///< String table section index. + + // In some cases these numbers do not fit in 16 bits and they are + // stored outside of the header in section #0. Here are the actual + // values. + elf_word e_phnum; ///< Number of program header entries. + elf_word e_shnum; ///< Number of section header entries. + elf_word e_shstrndx; ///< String table section index. ELFHeader(); @@ -102,6 +110,14 @@ struct ELFHeader { unsigned GetRelocationJumpSlotType() const; //-------------------------------------------------------------------------- + /// Check if there should be header extension in section header #0 + /// + /// @return + /// True if parsing the ELFHeader requires reading header extension + /// and false otherwise. + bool HasHeaderExtension() const; + + //-------------------------------------------------------------------------- /// Parse an ELFHeader entry starting at position \p offset and /// update the data extractor with the address size and byte order /// attributes as defined by the header. @@ -137,6 +153,16 @@ struct ELFHeader { /// The number of bytes forming an address in the ELF file (either 4 or /// 8), else zero if the address size could not be determined. static unsigned AddressSizeInBytes(const uint8_t *magic); + +private: + + //-------------------------------------------------------------------------- + /// Parse an ELFHeader header extension entry. This method is called + /// by Parse(). + /// + /// @param[in] data + /// The DataExtractor to read from. + void ParseHeaderExtension(lldb_private::DataExtractor &data); }; //------------------------------------------------------------------------------ diff --git a/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index eb983154618b..6e2001b21630 100644 --- a/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -14,25 +14,26 @@ #include <unordered_map> #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/DataBuffer.h" -#include "lldb/Core/Error.h" #include "lldb/Core/FileSpecList.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Section.h" -#include "lldb/Core/Stream.h" #include "lldb/Core/Timer.h" #include "lldb/Symbol/DWARFCallFrameInfo.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Target/SectionLoadList.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBufferLLVM.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/Stream.h" #include "llvm/ADT/PointerUnion.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/ARMBuildAttributes.h" #include "llvm/Support/MathExtras.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/MipsABIFlags.h" #define CASE_AND_STREAM(s, def, width) \ @@ -51,6 +52,7 @@ namespace { const char *const LLDB_NT_OWNER_FREEBSD = "FreeBSD"; const char *const LLDB_NT_OWNER_GNU = "GNU"; const char *const LLDB_NT_OWNER_NETBSD = "NetBSD"; +const char *const LLDB_NT_OWNER_OPENBSD = "OpenBSD"; const char *const LLDB_NT_OWNER_CSR = "csr"; const char *const LLDB_NT_OWNER_ANDROID = "Android"; const char *const LLDB_NT_OWNER_CORE = "CORE"; @@ -286,10 +288,26 @@ static uint32_t kalimbaVariantFromElfFlags(const elf::elf_word e_flags) { return kal_arch_variant; } -static uint32_t mipsVariantFromElfFlags(const elf::elf_word e_flags, - uint32_t endian) { - const uint32_t mips_arch = e_flags & llvm::ELF::EF_MIPS_ARCH; +static uint32_t mipsVariantFromElfFlags (const elf::ELFHeader &header) { + const uint32_t mips_arch = header.e_flags & llvm::ELF::EF_MIPS_ARCH; + uint32_t endian = header.e_ident[EI_DATA]; uint32_t arch_variant = ArchSpec::eMIPSSubType_unknown; + uint32_t fileclass = header.e_ident[EI_CLASS]; + + // If there aren't any elf flags available (e.g core elf file) then return default + // 32 or 64 bit arch (without any architecture revision) based on object file's class. + if (header.e_type == ET_CORE) { + switch (fileclass) { + case llvm::ELF::ELFCLASS32: + return (endian == ELFDATA2LSB) ? ArchSpec::eMIPSSubType_mips32el + : ArchSpec::eMIPSSubType_mips32; + case llvm::ELF::ELFCLASS64: + return (endian == ELFDATA2LSB) ? ArchSpec::eMIPSSubType_mips64el + : ArchSpec::eMIPSSubType_mips64; + default: + return arch_variant; + } + } switch (mips_arch) { case llvm::ELF::EF_MIPS_ARCH_1: @@ -324,7 +342,7 @@ static uint32_t mipsVariantFromElfFlags(const elf::elf_word e_flags, static uint32_t subTypeFromElfHeader(const elf::ELFHeader &header) { if (header.e_machine == llvm::ELF::EM_MIPS) - return mipsVariantFromElfFlags(header.e_flags, header.e_ident[EI_DATA]); + return mipsVariantFromElfFlags(header); return llvm::ELF::EM_CSR_KALIMBA == header.e_machine ? kalimbaVariantFromElfFlags(header.e_flags) @@ -386,31 +404,42 @@ ObjectFile *ObjectFileELF::CreateInstance(const lldb::ModuleSP &module_sp, lldb::offset_t file_offset, lldb::offset_t length) { if (!data_sp) { - data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length); + data_sp = + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset); + if (!data_sp) + return nullptr; data_offset = 0; } - if (data_sp && - data_sp->GetByteSize() > (llvm::ELF::EI_NIDENT + data_offset)) { - const uint8_t *magic = data_sp->GetBytes() + data_offset; - if (ELFHeader::MagicBytesMatch(magic)) { - // Update the data to contain the entire file if it doesn't already - if (data_sp->GetByteSize() < length) { - data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length); - data_offset = 0; - magic = data_sp->GetBytes(); - } - unsigned address_size = ELFHeader::AddressSizeInBytes(magic); - if (address_size == 4 || address_size == 8) { - std::unique_ptr<ObjectFileELF> objfile_ap(new ObjectFileELF( - module_sp, data_sp, data_offset, file, file_offset, length)); - ArchSpec spec; - if (objfile_ap->GetArchitecture(spec) && - objfile_ap->SetModulesArchitecture(spec)) - return objfile_ap.release(); - } - } + assert(data_sp); + + if (data_sp->GetByteSize() <= (llvm::ELF::EI_NIDENT + data_offset)) + return nullptr; + + const uint8_t *magic = data_sp->GetBytes() + data_offset; + if (!ELFHeader::MagicBytesMatch(magic)) + return nullptr; + + // Update the data to contain the entire file if it doesn't already + if (data_sp->GetByteSize() < length) { + data_sp = + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset); + if (!data_sp) + return nullptr; + data_offset = 0; + magic = data_sp->GetBytes(); } + + unsigned address_size = ELFHeader::AddressSizeInBytes(magic); + if (address_size == 4 || address_size == 8) { + std::unique_ptr<ObjectFileELF> objfile_ap(new ObjectFileELF( + module_sp, data_sp, data_offset, file, file_offset, length)); + ArchSpec spec; + if (objfile_ap->GetArchitecture(spec) && + objfile_ap->SetModulesArchitecture(spec)) + return objfile_ap.release(); + } + return NULL; } @@ -610,7 +639,8 @@ size_t ObjectFileELF::GetModuleSpecifications( DataExtractor data; data.SetData(data_sp); elf::ELFHeader header; - if (header.Parse(data, &data_offset)) { + lldb::offset_t header_offset = data_offset; + if (header.Parse(data, &header_offset)) { if (data_sp) { ModuleSpec spec(file); @@ -632,6 +662,7 @@ size_t ObjectFileELF::GetModuleSpecifications( // SetArchitecture should have set the vendor to unknown vendor = spec.GetArchitecture().GetTriple().getVendor(); assert(vendor == llvm::Triple::UnknownVendor); + UNUSED_IF_ASSERT_DISABLED(vendor); // // Validate it is ok to remove GetOsFromOSABI @@ -644,15 +675,31 @@ size_t ObjectFileELF::GetModuleSpecifications( __FUNCTION__, file.GetPath().c_str()); } + // In case there is header extension in the section #0, the header + // we parsed above could have sentinel values for e_phnum, e_shnum, + // and e_shstrndx. In this case we need to reparse the header + // with a bigger data source to get the actual values. + size_t section_header_end = header.e_shoff + header.e_shentsize; + if (header.HasHeaderExtension() && + section_header_end > data_sp->GetByteSize()) { + data_sp = DataBufferLLVM::CreateSliceFromPath( + file.GetPath(), section_header_end, file_offset); + if (data_sp) { + data.SetData(data_sp); + lldb::offset_t header_offset = data_offset; + header.Parse(data, &header_offset); + } + } + // Try to get the UUID from the section list. Usually that's at the - // end, so - // map the file in if we don't have it already. - size_t section_header_end = + // end, so map the file in if we don't have it already. + section_header_end = header.e_shoff + header.e_shnum * header.e_shentsize; if (section_header_end > data_sp->GetByteSize()) { - data_sp = file.MemoryMapFileContentsIfLocal(file_offset, - section_header_end); - data.SetData(data_sp); + data_sp = DataBufferLLVM::CreateSliceFromPath( + file.GetPath(), section_header_end, file_offset); + if (data_sp) + data.SetData(data_sp); } uint32_t gnu_debuglink_crc = 0; @@ -687,17 +734,17 @@ size_t ObjectFileELF::GetModuleSpecifications( (file.GetByteSize() - file_offset) / 1024); // For core files - which usually don't happen to have a - // gnu_debuglink, - // and are pretty bulky - calculating whole contents crc32 would - // be too much of luxury. - // Thus we will need to fallback to something simpler. + // gnu_debuglink, and are pretty bulky - calculating whole + // contents crc32 would be too much of luxury. Thus we will need + // to fallback to something simpler. if (header.e_type == llvm::ELF::ET_CORE) { size_t program_headers_end = header.e_phoff + header.e_phnum * header.e_phentsize; if (program_headers_end > data_sp->GetByteSize()) { - data_sp = file.MemoryMapFileContentsIfLocal( - file_offset, program_headers_end); - data.SetData(data_sp); + data_sp = DataBufferLLVM::CreateSliceFromPath( + file.GetPath(), program_headers_end, file_offset); + if (data_sp) + data.SetData(data_sp); } ProgramHeaderColl program_headers; GetProgramHeaderInfo(program_headers, set_data, header); @@ -710,20 +757,23 @@ size_t ObjectFileELF::GetModuleSpecifications( } if (segment_data_end > data_sp->GetByteSize()) { - data_sp = file.MemoryMapFileContentsIfLocal(file_offset, - segment_data_end); - data.SetData(data_sp); + data_sp = DataBufferLLVM::CreateSliceFromPath( + file.GetPath(), segment_data_end, file_offset); + if (data_sp) + data.SetData(data_sp); } core_notes_crc = CalculateELFNotesSegmentsCRC32(program_headers, data); } else { // Need to map entire file into memory to calculate the crc. - data_sp = - file.MemoryMapFileContentsIfLocal(file_offset, SIZE_MAX); - data.SetData(data_sp); - gnu_debuglink_crc = calc_gnu_debuglink_crc32( - data.GetDataStart(), data.GetByteSize()); + data_sp = DataBufferLLVM::CreateSliceFromPath(file.GetPath(), -1, + file_offset); + if (data_sp) { + data.SetData(data_sp); + gnu_debuglink_crc = calc_gnu_debuglink_crc32( + data.GetDataStart(), data.GetByteSize()); + } } } if (gnu_debuglink_crc) { @@ -799,7 +849,7 @@ bool ObjectFileELF::SetLoadAddress(Target &target, lldb::addr_t value, if (section_list) { if (!value_is_offset) { bool found_offset = false; - for (size_t i = 0, count = GetProgramHeaderCount(); i < count; ++i) { + for (size_t i = 1, count = GetProgramHeaderCount(); i <= count; ++i) { const elf::ELFProgramHeader *header = GetProgramHeaderByIndex(i); if (header == nullptr) continue; @@ -1315,6 +1365,10 @@ ObjectFileELF::RefineModuleDetailsFromNote(lldb_private::DataExtractor &data, } break; } + if (arch_spec.IsMIPS() && + arch_spec.GetTriple().getOS() == llvm::Triple::OSType::UnknownOS) + // The note.n_name == LLDB_NT_OWNER_GNU is valid for Linux platform + arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux); } // Process NetBSD ELF notes. else if ((note.n_name == LLDB_NT_OWNER_NETBSD) && @@ -1336,6 +1390,12 @@ ObjectFileELF::RefineModuleDetailsFromNote(lldb_private::DataExtractor &data, "ObjectFileELF::%s detected NetBSD, min version constant %" PRIu32, __FUNCTION__, version_info); } + // Process OpenBSD ELF notes. + else if (note.n_name == LLDB_NT_OWNER_OPENBSD) { + // Set the elf OS version to OpenBSD. Also clear the vendor. + arch_spec.GetTriple().setOS(llvm::Triple::OSType::OpenBSD); + arch_spec.GetTriple().setVendor(llvm::Triple::VendorType::UnknownVendor); + } // Process CSR kalimba notes else if ((note.n_type == LLDB_NT_GNU_ABI_TAG) && (note.n_name == LLDB_NT_OWNER_CSR)) { @@ -1410,6 +1470,12 @@ ObjectFileELF::RefineModuleDetailsFromNote(lldb_private::DataExtractor &data, break; } } + if (arch_spec.IsMIPS() && + arch_spec.GetTriple().getOS() == llvm::Triple::OSType::UnknownOS) + // In case of MIPSR6, the LLDB_NT_OWNER_GNU note is missing + // for some cases (e.g. compile with -nostdlib) + // Hence set OS to Linux + arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux); } } @@ -1524,6 +1590,7 @@ size_t ObjectFileELF::GetSectionHeaderInfo(SectionHeaderColl §ion_headers, GetOsFromOSABI(header.e_ident[EI_OSABI], ostype); spec_ostype = arch_spec.GetTriple().getOS(); assert(spec_ostype == ostype); + UNUSED_IF_ASSERT_DISABLED(spec_ostype); } if (arch_spec.GetMachine() == llvm::Triple::mips || @@ -3065,10 +3132,10 @@ void ObjectFileELF::DumpELFHeader(Stream *s, const ELFHeader &header) { s->Printf("e_flags = 0x%8.8x\n", header.e_flags); s->Printf("e_ehsize = 0x%4.4x\n", header.e_ehsize); s->Printf("e_phentsize = 0x%4.4x\n", header.e_phentsize); - s->Printf("e_phnum = 0x%4.4x\n", header.e_phnum); + s->Printf("e_phnum = 0x%8.8x\n", header.e_phnum); s->Printf("e_shentsize = 0x%4.4x\n", header.e_shentsize); - s->Printf("e_shnum = 0x%4.4x\n", header.e_shnum); - s->Printf("e_shstrndx = 0x%4.4x\n", header.e_shstrndx); + s->Printf("e_shnum = 0x%8.8x\n", header.e_shnum); + s->Printf("e_shstrndx = 0x%8.8x\n", header.e_shstrndx); } //---------------------------------------------------------------------- @@ -3315,7 +3382,7 @@ bool ObjectFileELF::GetArchitecture(ArchSpec &arch) { // headers // that might shed more light on the architecture if (ParseProgramHeaders()) { - for (size_t i = 0, count = GetProgramHeaderCount(); i < count; ++i) { + for (size_t i = 1, count = GetProgramHeaderCount(); i <= count; ++i) { const elf::ELFProgramHeader *header = GetProgramHeaderByIndex(i); if (header && header->p_type == PT_NOTE && header->p_offset != 0 && header->p_filesz > 0) { diff --git a/source/Plugins/ObjectFile/ELF/ObjectFileELF.h b/source/Plugins/ObjectFile/ELF/ObjectFileELF.h index 4ce5648cfed5..98bd9abb1932 100644 --- a/source/Plugins/ObjectFile/ELF/ObjectFileELF.h +++ b/source/Plugins/ObjectFile/ELF/ObjectFileELF.h @@ -20,9 +20,9 @@ // Other libraries and framework includes // Project includes #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/UUID.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Symbol/ObjectFile.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/UUID.h" #include "lldb/lldb-private.h" #include "ELFHeader.h" diff --git a/source/Plugins/ObjectFile/JIT/CMakeLists.txt b/source/Plugins/ObjectFile/JIT/CMakeLists.txt index 979724bac5ad..fd575532db4c 100644 --- a/source/Plugins/ObjectFile/JIT/CMakeLists.txt +++ b/source/Plugins/ObjectFile/JIT/CMakeLists.txt @@ -1,3 +1,11 @@ -add_lldb_library(lldbPluginObjectFileJIT +add_lldb_library(lldbPluginObjectFileJIT PLUGIN ObjectFileJIT.cpp + + LINK_LIBS + lldbCore + lldbHost + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp b/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp index b5b5e38e1f6f..055a8219f154 100644 --- a/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp +++ b/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp @@ -12,27 +12,27 @@ #include "ObjectFileJIT.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/DataBuffer.h" -#include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/FileSpecList.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RangeMap.h" #include "lldb/Core/Section.h" #include "lldb/Core/StreamFile.h" -#include "lldb/Core/StreamString.h" #include "lldb/Core/Timer.h" -#include "lldb/Core/UUID.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/Host.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Target/Platform.h" #include "lldb/Target/Process.h" #include "lldb/Target/SectionLoadList.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBuffer.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" +#include "lldb/Utility/UUID.h" #ifndef __APPLE__ #include "Utility/UuidCompatibility.h" diff --git a/source/Plugins/ObjectFile/Mach-O/CMakeLists.txt b/source/Plugins/ObjectFile/Mach-O/CMakeLists.txt index 45d45860b9e5..d39b93768ae7 100644 --- a/source/Plugins/ObjectFile/Mach-O/CMakeLists.txt +++ b/source/Plugins/ObjectFile/Mach-O/CMakeLists.txt @@ -1,3 +1,13 @@ -add_lldb_library(lldbPluginObjectFileMachO +add_lldb_library(lldbPluginObjectFileMachO PLUGIN ObjectFileMachO.cpp + + LINK_LIBS + lldbCore + lldbHost + lldbSymbol + lldbTarget + lldbUtility + lldbPluginProcessUtility + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 9ef4e9c3c9b1..84ecfdc67bee 100644 --- a/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -18,21 +18,16 @@ #include "Plugins/Process/Utility/RegisterContextDarwin_i386.h" #include "Plugins/Process/Utility/RegisterContextDarwin_x86_64.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/DataBuffer.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Error.h" #include "lldb/Core/FileSpecList.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RangeMap.h" +#include "lldb/Core/RegisterValue.h" #include "lldb/Core/Section.h" #include "lldb/Core/StreamFile.h" -#include "lldb/Core/StreamString.h" #include "lldb/Core/Timer.h" -#include "lldb/Core/UUID.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/Host.h" #include "lldb/Symbol/DWARFCallFrameInfo.h" #include "lldb/Symbol/ObjectFile.h" @@ -44,9 +39,17 @@ #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadList.h" +#include "lldb/Utility/DataBufferLLVM.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" +#include "lldb/Utility/UUID.h" #include "lldb/Utility/SafeMachO.h" +#include "llvm/Support/MemoryBuffer.h" + #include "ObjectFileMachO.h" #if defined(__APPLE__) && \ @@ -57,6 +60,8 @@ #ifndef __APPLE__ #include "Utility/UuidCompatibility.h" +#else +#include <uuid/uuid.h> #endif #define THUMB_ADDRESS_BIT_MASK 0xfffffffffffffffeull @@ -857,22 +862,30 @@ ObjectFile *ObjectFileMachO::CreateInstance(const lldb::ModuleSP &module_sp, lldb::offset_t file_offset, lldb::offset_t length) { if (!data_sp) { - data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length); + data_sp = + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset); + if (!data_sp) + return nullptr; data_offset = 0; } - if (ObjectFileMachO::MagicBytesMatch(data_sp, data_offset, length)) { - // Update the data to contain the entire file if it doesn't already - if (data_sp->GetByteSize() < length) { - data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length); - data_offset = 0; - } - std::unique_ptr<ObjectFile> objfile_ap(new ObjectFileMachO( - module_sp, data_sp, data_offset, file, file_offset, length)); - if (objfile_ap.get() && objfile_ap->ParseHeader()) - return objfile_ap.release(); + if (!ObjectFileMachO::MagicBytesMatch(data_sp, data_offset, length)) + return nullptr; + + // Update the data to contain the entire file if it doesn't already + if (data_sp->GetByteSize() < length) { + data_sp = + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset); + if (!data_sp) + return nullptr; + data_offset = 0; } - return NULL; + auto objfile_ap = llvm::make_unique<ObjectFileMachO>( + module_sp, data_sp, data_offset, file, file_offset, length); + if (!objfile_ap || !objfile_ap->ParseHeader()) + return nullptr; + + return objfile_ap.release(); } ObjectFile *ObjectFileMachO::CreateMemoryInstance( @@ -901,7 +914,8 @@ size_t ObjectFileMachO::GetModuleSpecifications( size_t header_and_load_cmds = header.sizeofcmds + MachHeaderSizeFromMagic(header.magic); if (header_and_load_cmds >= data_sp->GetByteSize()) { - data_sp = file.ReadFileContents(file_offset, header_and_load_cmds); + data_sp = DataBufferLLVM::CreateSliceFromPath( + file.GetPath(), header_and_load_cmds, file_offset); data.SetData(data_sp); data_offset = MachHeaderSizeFromMagic(header.magic); } @@ -1113,8 +1127,8 @@ bool ObjectFileMachO::ParseHeader() { ReadMemory(process_sp, m_memory_addr, header_and_lc_size); } else { // Read in all only the load command data from the file on disk - data_sp = - m_file.ReadFileContents(m_file_offset, header_and_lc_size); + data_sp = DataBufferLLVM::CreateSliceFromPath( + m_file.GetPath(), header_and_lc_size, m_file_offset); if (data_sp->GetByteSize() != header_and_lc_size) return false; } @@ -2085,22 +2099,23 @@ UUID ObjectFileMachO::GetSharedCacheUUID(FileSpec dyld_shared_cache, const ByteOrder byte_order, const uint32_t addr_byte_size) { UUID dsc_uuid; - DataBufferSP dsc_data_sp = dyld_shared_cache.MemoryMapFileContentsIfLocal( - 0, sizeof(struct lldb_copy_dyld_cache_header_v1)); - if (dsc_data_sp) { - DataExtractor dsc_header_data(dsc_data_sp, byte_order, addr_byte_size); - - char version_str[7]; - lldb::offset_t offset = 0; - memcpy(version_str, dsc_header_data.GetData(&offset, 6), 6); - version_str[6] = '\0'; - if (strcmp(version_str, "dyld_v") == 0) { - offset = offsetof(struct lldb_copy_dyld_cache_header_v1, uuid); - uint8_t uuid_bytes[sizeof(uuid_t)]; - memcpy(uuid_bytes, dsc_header_data.GetData(&offset, sizeof(uuid_t)), - sizeof(uuid_t)); - dsc_uuid.SetBytes(uuid_bytes); - } + DataBufferSP DscData = DataBufferLLVM::CreateSliceFromPath( + dyld_shared_cache.GetPath(), + sizeof(struct lldb_copy_dyld_cache_header_v1), 0); + if (!DscData) + return dsc_uuid; + DataExtractor dsc_header_data(DscData, byte_order, addr_byte_size); + + char version_str[7]; + lldb::offset_t offset = 0; + memcpy(version_str, dsc_header_data.GetData(&offset, 6), 6); + version_str[6] = '\0'; + if (strcmp(version_str, "dyld_v") == 0) { + offset = offsetof(struct lldb_copy_dyld_cache_header_v1, uuid); + uint8_t uuid_bytes[sizeof(uuid_t)]; + memcpy(uuid_bytes, dsc_header_data.GetData(&offset, sizeof(uuid_t)), + sizeof(uuid_t)); + dsc_uuid.SetBytes(uuid_bytes); } return dsc_uuid; } @@ -2692,8 +2707,9 @@ size_t ObjectFileMachO::ParseSymtab() { // Process the dyld shared cache header to find the unmapped symbols - DataBufferSP dsc_data_sp = dsc_filespec.MemoryMapFileContentsIfLocal( - 0, sizeof(struct lldb_copy_dyld_cache_header_v1)); + DataBufferSP dsc_data_sp = DataBufferLLVM::CreateSliceFromPath( + dsc_filespec.GetPath(), sizeof(struct lldb_copy_dyld_cache_header_v1), + 0); if (!dsc_uuid.IsValid()) { dsc_uuid = GetSharedCacheUUID(dsc_filespec, byte_order, addr_byte_size); } @@ -2726,9 +2742,11 @@ size_t ObjectFileMachO::ParseSymtab() { mappingOffset >= sizeof(struct lldb_copy_dyld_cache_header_v1)) { DataBufferSP dsc_mapping_info_data_sp = - dsc_filespec.MemoryMapFileContentsIfLocal( - mappingOffset, - sizeof(struct lldb_copy_dyld_cache_mapping_info)); + DataBufferLLVM::CreateSliceFromPath( + dsc_filespec.GetPath(), + sizeof(struct lldb_copy_dyld_cache_mapping_info), + mappingOffset); + DataExtractor dsc_mapping_info_data(dsc_mapping_info_data_sp, byte_order, addr_byte_size); offset = 0; @@ -2750,9 +2768,12 @@ size_t ObjectFileMachO::ParseSymtab() { if (localSymbolsOffset && localSymbolsSize) { // Map the local symbols - if (DataBufferSP dsc_local_symbols_data_sp = - dsc_filespec.MemoryMapFileContentsIfLocal( - localSymbolsOffset, localSymbolsSize)) { + DataBufferSP dsc_local_symbols_data_sp = + DataBufferLLVM::CreateSliceFromPath(dsc_filespec.GetPath(), + localSymbolsSize, + localSymbolsOffset); + + if (dsc_local_symbols_data_sp) { DataExtractor dsc_local_symbols_data(dsc_local_symbols_data_sp, byte_order, addr_byte_size); @@ -5034,6 +5055,7 @@ uint32_t ObjectFileMachO::GetDependentModules(FileSpecList &files) { lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic); std::vector<std::string> rpath_paths; std::vector<std::string> rpath_relative_paths; + std::vector<std::string> at_exec_relative_paths; const bool resolve_path = false; // Don't resolve the dependent file paths // since they may not reside on this system uint32_t i; @@ -5059,6 +5081,10 @@ uint32_t ObjectFileMachO::GetDependentModules(FileSpecList &files) { if (path[0] == '@') { if (strncmp(path, "@rpath", strlen("@rpath")) == 0) rpath_relative_paths.push_back(path + strlen("@rpath")); + else if (strncmp(path, "@executable_path", + strlen("@executable_path")) == 0) + at_exec_relative_paths.push_back(path + + strlen("@executable_path")); } else { FileSpec file_spec(path, resolve_path); if (files.AppendIfUnique(file_spec)) @@ -5074,10 +5100,11 @@ uint32_t ObjectFileMachO::GetDependentModules(FileSpecList &files) { offset = cmd_offset + load_cmd.cmdsize; } + FileSpec this_file_spec(m_file); + this_file_spec.ResolvePath(); + if (!rpath_paths.empty()) { // Fixup all LC_RPATH values to be absolute paths - FileSpec this_file_spec(m_file); - this_file_spec.ResolvePath(); std::string loader_path("@loader_path"); std::string executable_path("@executable_path"); for (auto &rpath : rpath_paths) { @@ -5107,6 +5134,23 @@ uint32_t ObjectFileMachO::GetDependentModules(FileSpecList &files) { } } } + + // We may have @executable_paths but no RPATHS. Figure those out here. + // Only do this if this object file is the executable. We have no way to + // get back to the actual executable otherwise, so we won't get the right + // path. + if (!at_exec_relative_paths.empty() && CalculateType() == eTypeExecutable) { + FileSpec exec_dir = this_file_spec.CopyByRemovingLastPathComponent(); + for (const auto &at_exec_relative_path : at_exec_relative_paths) { + FileSpec file_spec = + exec_dir.CopyByAppendingPathComponent(at_exec_relative_path); + file_spec = file_spec.GetNormalizedPath(); + if (file_spec.Exists() && files.AppendIfUnique(file_spec)) { + count++; + break; + } + } + } } return count; } @@ -5312,6 +5356,136 @@ uint32_t ObjectFileMachO::GetNumThreadContexts() { return m_thread_context_offsets.GetSize(); } +std::string ObjectFileMachO::GetIdentifierString() { + std::string result; + ModuleSP module_sp(GetModule()); + if (module_sp) { + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); + + // First, look over the load commands for an LC_NOTE load command + // with data_owner string "kern ver str" & use that if found. + lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic); + for (uint32_t i = 0; i < m_header.ncmds; ++i) { + const uint32_t cmd_offset = offset; + load_command lc; + if (m_data.GetU32(&offset, &lc.cmd, 2) == NULL) + break; + if (lc.cmd == LC_NOTE) + { + char data_owner[17]; + m_data.CopyData (offset, 16, data_owner); + data_owner[16] = '\0'; + offset += 16; + uint64_t fileoff = m_data.GetU64_unchecked (&offset); + uint64_t size = m_data.GetU64_unchecked (&offset); + + // "kern ver str" has a uint32_t version and then a + // nul terminated c-string. + if (strcmp ("kern ver str", data_owner) == 0) + { + offset = fileoff; + uint32_t version; + if (m_data.GetU32 (&offset, &version, 1) != nullptr) + { + if (version == 1) + { + uint32_t strsize = size - sizeof (uint32_t); + char *buf = (char*) malloc (strsize); + if (buf) + { + m_data.CopyData (offset, strsize, buf); + buf[strsize - 1] = '\0'; + result = buf; + if (buf) + free (buf); + return result; + } + } + } + } + } + offset = cmd_offset + lc.cmdsize; + } + + // Second, make a pass over the load commands looking for an + // obsolete LC_IDENT load command. + offset = MachHeaderSizeFromMagic(m_header.magic); + for (uint32_t i = 0; i < m_header.ncmds; ++i) { + const uint32_t cmd_offset = offset; + struct ident_command ident_command; + if (m_data.GetU32(&offset, &ident_command, 2) == NULL) + break; + if (ident_command.cmd == LC_IDENT && ident_command.cmdsize != 0) { + char *buf = (char *) malloc (ident_command.cmdsize); + if (buf != nullptr + && m_data.CopyData (offset, ident_command.cmdsize, buf) == ident_command.cmdsize) { + buf[ident_command.cmdsize - 1] = '\0'; + result = buf; + } + if (buf) + free (buf); + } + offset = cmd_offset + ident_command.cmdsize; + } + + } + return result; +} + +bool ObjectFileMachO::GetCorefileMainBinaryInfo (addr_t &address, UUID &uuid) { + address = LLDB_INVALID_ADDRESS; + uuid.Clear(); + ModuleSP module_sp(GetModule()); + if (module_sp) { + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); + lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic); + for (uint32_t i = 0; i < m_header.ncmds; ++i) { + const uint32_t cmd_offset = offset; + load_command lc; + if (m_data.GetU32(&offset, &lc.cmd, 2) == NULL) + break; + if (lc.cmd == LC_NOTE) + { + char data_owner[17]; + memset (data_owner, 0, sizeof (data_owner)); + m_data.CopyData (offset, 16, data_owner); + offset += 16; + uint64_t fileoff = m_data.GetU64_unchecked (&offset); + uint64_t size = m_data.GetU64_unchecked (&offset); + + // "main bin spec" (main binary specification) data payload is formatted: + // uint32_t version [currently 1] + // uint32_t type [0 == unspecified, 1 == kernel, 2 == user process] + // uint64_t address [ UINT64_MAX if address not specified ] + // uuid_t uuid [ all zero's if uuid not specified ] + // uint32_t log2_pagesize [ process page size in log base 2, e.g. 4k pages are 12. 0 for unspecified ] + + if (strcmp ("main bin spec", data_owner) == 0 && size >= 32) + { + offset = fileoff; + uint32_t version; + if (m_data.GetU32 (&offset, &version, 1) != nullptr && version == 1) + { + uint32_t type = 0; + uuid_t raw_uuid; + memset (raw_uuid, 0, sizeof (uuid_t)); + + if (m_data.GetU32 (&offset, &type, 1) + && m_data.GetU64 (&offset, &address, 1) + && m_data.CopyData (offset, sizeof (uuid_t), raw_uuid) != 0 + && uuid.SetBytes (raw_uuid, sizeof (uuid_t))) + { + return true; + } + } + } + } + offset = cmd_offset + lc.cmdsize; + } + } + return false; +} + lldb::RegisterContextSP ObjectFileMachO::GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread) { diff --git a/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h b/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h index cac176fe2ca6..96379a4db411 100644 --- a/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h +++ b/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h @@ -17,9 +17,10 @@ #include "lldb/Core/Address.h" #include "lldb/Core/FileSpecList.h" #include "lldb/Core/RangeMap.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Symbol/ObjectFile.h" +#include "lldb/Utility/FileSpec.h" #include "lldb/Utility/SafeMachO.h" +#include "lldb/Utility/UUID.h" //---------------------------------------------------------------------- // This class needs to be hidden as eventually belongs in a plugin that @@ -111,6 +112,10 @@ public: uint32_t GetNumThreadContexts() override; + std::string GetIdentifierString() override; + + bool GetCorefileMainBinaryInfo (lldb::addr_t &address, lldb_private::UUID &uuid) override; + lldb::RegisterContextSP GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread) override; diff --git a/source/Plugins/ObjectFile/PECOFF/CMakeLists.txt b/source/Plugins/ObjectFile/PECOFF/CMakeLists.txt index 5c7c488f362f..1e8fb85c72c9 100644 --- a/source/Plugins/ObjectFile/PECOFF/CMakeLists.txt +++ b/source/Plugins/ObjectFile/PECOFF/CMakeLists.txt @@ -1,4 +1,12 @@ -add_lldb_library(lldbPluginObjectFilePECOFF +add_lldb_library(lldbPluginObjectFilePECOFF PLUGIN ObjectFilePECOFF.cpp WindowsMiniDump.cpp + + LINK_LIBS + lldbCore + lldbHost + lldbSymbol + lldbTarget + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp index f0647e02158b..c89383a7b7ba 100644 --- a/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp +++ b/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp @@ -13,22 +13,24 @@ #include "llvm/Support/COFF.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/DataBuffer.h" -#include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/FileSpecList.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Section.h" #include "lldb/Core/StreamFile.h" -#include "lldb/Core/StreamString.h" #include "lldb/Core/Timer.h" -#include "lldb/Core/UUID.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Target/Process.h" #include "lldb/Target/SectionLoadList.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/DataBufferLLVM.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/StreamString.h" +#include "lldb/Utility/UUID.h" + +#include "llvm/Support/MemoryBuffer.h" #define IMAGE_DOS_SIGNATURE 0x5A4D // MZ #define IMAGE_NT_SIGNATURE 0x00004550 // PE00 @@ -65,20 +67,30 @@ ObjectFile *ObjectFilePECOFF::CreateInstance(const lldb::ModuleSP &module_sp, lldb::offset_t file_offset, lldb::offset_t length) { if (!data_sp) { - data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length); + data_sp = + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset); + if (!data_sp) + return nullptr; data_offset = 0; } - if (ObjectFilePECOFF::MagicBytesMatch(data_sp)) { - // Update the data to contain the entire file if it doesn't already - if (data_sp->GetByteSize() < length) - data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length); - std::unique_ptr<ObjectFile> objfile_ap(new ObjectFilePECOFF( - module_sp, data_sp, data_offset, file, file_offset, length)); - if (objfile_ap.get() && objfile_ap->ParseHeader()) - return objfile_ap.release(); + if (!ObjectFilePECOFF::MagicBytesMatch(data_sp)) + return nullptr; + + // Update the data to contain the entire file if it doesn't already + if (data_sp->GetByteSize() < length) { + data_sp = + DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset); + if (!data_sp) + return nullptr; } - return NULL; + + auto objfile_ap = llvm::make_unique<ObjectFilePECOFF>( + module_sp, data_sp, data_offset, file, file_offset, length); + if (!objfile_ap || !objfile_ap->ParseHeader()) + return nullptr; + + return objfile_ap.release(); } ObjectFile *ObjectFilePECOFF::CreateMemoryInstance( @@ -418,7 +430,10 @@ bool ObjectFilePECOFF::ParseCOFFOptionalHeader(lldb::offset_t *offset_ptr) { DataExtractor ObjectFilePECOFF::ReadImageData(uint32_t offset, size_t size) { if (m_file) { - DataBufferSP buffer_sp(m_file.ReadFileContents(offset, size)); + // A bit of a hack, but we intend to write to this buffer, so we can't + // mmap it. + auto buffer_sp = + DataBufferLLVM::CreateSliceFromPath(m_file.GetPath(), size, offset, true); return DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()); } ProcessSP process_sp(m_process_wp.lock()); diff --git a/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp b/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp index 3fd6cdc5c9a7..094e258a7a03 100644 --- a/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp +++ b/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp @@ -11,7 +11,7 @@ // collisions with WinAPI preprocessor macros. #include "WindowsMiniDump.h" -#include "lldb/Host/FileSpec.h" +#include "lldb/Utility/FileSpec.h" #include "llvm/Support/ConvertUTF.h" #ifdef _WIN32 diff --git a/source/Plugins/OperatingSystem/Go/CMakeLists.txt b/source/Plugins/OperatingSystem/Go/CMakeLists.txt index 1ca82c462069..27e952a84dfc 100644 --- a/source/Plugins/OperatingSystem/Go/CMakeLists.txt +++ b/source/Plugins/OperatingSystem/Go/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginOSGo +add_lldb_library(lldbPluginOSGo PLUGIN OperatingSystemGo.cpp + + LINK_LIBS + lldbCore + lldbInterpreter + lldbSymbol + lldbTarget + lldbPluginProcessUtility ) diff --git a/source/Plugins/OperatingSystem/Go/OperatingSystemGo.cpp b/source/Plugins/OperatingSystem/Go/OperatingSystemGo.cpp index c5a3ddee4843..1a0c32729865 100644 --- a/source/Plugins/OperatingSystem/Go/OperatingSystemGo.cpp +++ b/source/Plugins/OperatingSystem/Go/OperatingSystemGo.cpp @@ -18,13 +18,11 @@ #include "Plugins/Process/Utility/DynamicRegisterInfo.h" #include "Plugins/Process/Utility/RegisterContextMemory.h" #include "Plugins/Process/Utility/ThreadMemory.h" -#include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" #include "lldb/Core/Section.h" -#include "lldb/Core/StreamString.h" #include "lldb/Core/ValueObjectVariable.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/OptionGroupBoolean.h" @@ -40,6 +38,8 @@ #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadList.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/StreamString.h" using namespace lldb; using namespace lldb_private; @@ -319,7 +319,7 @@ bool OperatingSystemGo::UpdateThreadList(ThreadList &old_thread_list, for (uint64_t i = 0; i < allglen; ++i) { goroutines.push_back(CreateGoroutineAtIndex(i, err)); if (err.Fail()) { - err.PutToLog(log, "OperatingSystemGo::UpdateThreadList"); + LLDB_LOG(log, "error: {0}", err); return new_thread_list.GetSize(false) > 0; } } diff --git a/source/Plugins/OperatingSystem/Python/CMakeLists.txt b/source/Plugins/OperatingSystem/Python/CMakeLists.txt index 7188e6f67ba0..e8b0f31d3736 100644 --- a/source/Plugins/OperatingSystem/Python/CMakeLists.txt +++ b/source/Plugins/OperatingSystem/Python/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginOSPython +add_lldb_library(lldbPluginOSPython PLUGIN OperatingSystemPython.cpp + + LINK_LIBS + lldbCore + lldbInterpreter + lldbSymbol + lldbTarget + lldbPluginProcessUtility ) diff --git a/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp b/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp index 69826a0f638c..dbbb55e474f8 100644 --- a/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp +++ b/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp @@ -18,12 +18,10 @@ #include "Plugins/Process/Utility/RegisterContextMemory.h" #include "Plugins/Process/Utility/ThreadMemory.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" -#include "lldb/Core/StreamString.h" #include "lldb/Core/StructuredData.h" #include "lldb/Core/ValueObjectVariable.h" #include "lldb/Interpreter/CommandInterpreter.h" @@ -35,6 +33,8 @@ #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadList.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/StreamString.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/Platform/Android/AdbClient.cpp b/source/Plugins/Platform/Android/AdbClient.cpp index eb684ad0fbc0..2060bd1de735 100644 --- a/source/Plugins/Platform/Android/AdbClient.cpp +++ b/source/Plugins/Platform/Android/AdbClient.cpp @@ -15,15 +15,16 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/FileUtilities.h" -#include "lldb/Core/DataBuffer.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/DataEncoder.h" -#include "lldb/Core/DataExtractor.h" -#include "lldb/Core/StreamString.h" #include "lldb/Host/ConnectionFileDescriptor.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/PosixApi.h" +#include "lldb/Utility/DataBuffer.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/DataEncoder.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/StreamString.h" +#include "lldb/Utility/Timeout.h" #include <limits.h> @@ -402,13 +403,14 @@ Error AdbClient::ShellToFile(const char *command, milliseconds timeout, return error; const auto output_filename = output_file_spec.GetPath(); - std::ofstream dst(output_filename, std::ios::out | std::ios::binary); - if (!dst.is_open()) + std::error_code EC; + llvm::raw_fd_ostream dst(output_filename, EC, llvm::sys::fs::F_None); + if (EC) return Error("Unable to open local file %s", output_filename.c_str()); dst.write(&output_buffer[0], output_buffer.size()); dst.close(); - if (!dst) + if (dst.has_error()) return Error("Failed to write file %s", output_filename.c_str()); return Error(); } @@ -428,8 +430,9 @@ Error AdbClient::SyncService::internalPullFile(const FileSpec &remote_file, const auto local_file_path = local_file.GetPath(); llvm::FileRemover local_file_remover(local_file_path); - std::ofstream dst(local_file_path, std::ios::out | std::ios::binary); - if (!dst.is_open()) + std::error_code EC; + llvm::raw_fd_ostream dst(local_file_path, EC, llvm::sys::fs::F_None); + if (EC) return Error("Unable to open local file %s", local_file_path.c_str()); const auto remote_file_path = remote_file.GetPath(false); @@ -447,6 +450,9 @@ Error AdbClient::SyncService::internalPullFile(const FileSpec &remote_file, if (!eof) dst.write(&chunk[0], chunk.size()); } + dst.close(); + if (dst.has_error()) + return Error("Failed to write file %s", local_file_path.c_str()); local_file_remover.releaseFile(); return error; diff --git a/source/Plugins/Platform/Android/AdbClient.h b/source/Plugins/Platform/Android/AdbClient.h index 169a0b5a4e3e..9e8726c93b61 100644 --- a/source/Plugins/Platform/Android/AdbClient.h +++ b/source/Plugins/Platform/Android/AdbClient.h @@ -10,7 +10,7 @@ #ifndef liblldb_AdbClient_h_ #define liblldb_AdbClient_h_ -#include "lldb/Core/Error.h" +#include "lldb/Utility/Error.h" #include <chrono> #include <functional> #include <list> diff --git a/source/Plugins/Platform/Android/CMakeLists.txt b/source/Plugins/Platform/Android/CMakeLists.txt index e831a33a4b6d..5abb51a0b94a 100644 --- a/source/Plugins/Platform/Android/CMakeLists.txt +++ b/source/Plugins/Platform/Android/CMakeLists.txt @@ -1,5 +1,13 @@ -add_lldb_library(lldbPluginPlatformAndroid +add_lldb_library(lldbPluginPlatformAndroid PLUGIN AdbClient.cpp PlatformAndroid.cpp PlatformAndroidRemoteGDBServer.cpp + + LINK_LIBS + lldbCore + lldbHost + lldbPluginPlatformLinux + lldbPluginPlatformGDB + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/Platform/Android/PlatformAndroid.cpp b/source/Plugins/Platform/Android/PlatformAndroid.cpp index 64a320f8c3fc..ad3918d4e202 100644 --- a/source/Plugins/Platform/Android/PlatformAndroid.cpp +++ b/source/Plugins/Platform/Android/PlatformAndroid.cpp @@ -7,11 +7,6 @@ // //===----------------------------------------------------------------------===// -// C Includes -// C++ Includes -// Other libraries and framework includes -#include "Utility/UriParser.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Scalar.h" @@ -19,6 +14,8 @@ #include "lldb/Core/ValueObject.h" #include "lldb/Host/HostInfo.h" #include "lldb/Host/StringConvert.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/UriParser.h" // Project includes #include "AdbClient.h" @@ -336,7 +333,7 @@ Error PlatformAndroid::DownloadSymbolFile(const lldb::ModuleSP &module_sp, // Create file remover for the temporary directory created on the device std::unique_ptr<std::string, std::function<void(std::string *)>> - tmpdir_remover(&tmpdir, [this, &adb](std::string *s) { + tmpdir_remover(&tmpdir, [&adb](std::string *s) { StreamString command; command.Printf("rm -rf %s", s->c_str()); Error error = adb.Shell(command.GetData(), seconds(5), nullptr); diff --git a/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp b/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp index cabb3ffb1c15..0c5e478d470e 100644 --- a/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp +++ b/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp @@ -8,13 +8,13 @@ //===----------------------------------------------------------------------===// // Other libraries and framework includes -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Host/ConnectionFileDescriptor.h" #include "lldb/Host/common/TCPSocket.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/UriParser.h" #include "PlatformAndroidRemoteGDBServer.h" -#include "Utility/UriParser.h" #include <sstream> diff --git a/source/Plugins/Platform/CMakeLists.txt b/source/Plugins/Platform/CMakeLists.txt index 2e3a3f7c1b2e..ddb71212ce48 100644 --- a/source/Plugins/Platform/CMakeLists.txt +++ b/source/Plugins/Platform/CMakeLists.txt @@ -4,6 +4,8 @@ add_subdirectory(FreeBSD) #elseif (CMAKE_SYSTEM_NAME MATCHES "NetBSD") add_subdirectory(NetBSD) +#elseif (CMAKE_SYSTEM_NAME MATCHES "OpenBSD") + add_subdirectory(OpenBSD) #elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin") add_subdirectory(MacOSX) #elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") diff --git a/source/Plugins/Platform/FreeBSD/CMakeLists.txt b/source/Plugins/Platform/FreeBSD/CMakeLists.txt index 57153969c3b4..1c27e1b7adaa 100644 --- a/source/Plugins/Platform/FreeBSD/CMakeLists.txt +++ b/source/Plugins/Platform/FreeBSD/CMakeLists.txt @@ -1,3 +1,9 @@ -add_lldb_library(lldbPluginPlatformFreeBSD +add_lldb_library(lldbPluginPlatformFreeBSD PLUGIN PlatformFreeBSD.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbHost + lldbTarget ) diff --git a/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp b/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp index 9ea97a5f70ba..2a150b5d452b 100644 --- a/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp +++ b/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp @@ -22,22 +22,34 @@ #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Breakpoint/BreakpointSite.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Module.h" -#include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Host/Host.h" +#include "lldb/Core/State.h" #include "lldb/Host/HostInfo.h" #include "lldb/Target/Process.h" +#include "lldb/Target/Target.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" + +// Define these constants from FreeBSD mman.h for use when targeting +// remote FreeBSD systems even when host has different values. +#define MAP_PRIVATE 0x0002 +#define MAP_ANON 0x1000 using namespace lldb; using namespace lldb_private; using namespace lldb_private::platform_freebsd; +static uint32_t g_initialize_count = 0; + +//------------------------------------------------------------------ + PlatformSP PlatformFreeBSD::CreateInstance(bool force, const ArchSpec *arch) { - // The only time we create an instance is when we are creating a remote - // freebsd platform - const bool is_host = false; + Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); + LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force, + arch ? arch->GetArchitectureName() : "<null>", + arch ? arch->GetTriple().getTriple() : "<null>"); bool create = force; if (create == false && arch && arch->IsValid()) { @@ -47,7 +59,7 @@ PlatformSP PlatformFreeBSD::CreateInstance(bool force, const ArchSpec *arch) { create = true; break; -#if defined(__FreeBSD__) || defined(__OpenBSD__) +#if defined(__FreeBSD__) // Only accept "unknown" for the OS if the host is BSD and // it "unknown" wasn't specified (it was just returned because it // was NOT specified) @@ -59,8 +71,10 @@ PlatformSP PlatformFreeBSD::CreateInstance(bool force, const ArchSpec *arch) { break; } } - if (create) - return PlatformSP(new PlatformFreeBSD(is_host)); + LLDB_LOG(log, "create = {0}", create); + if (create) { + return PlatformSP(new PlatformFreeBSD(false)); + } return PlatformSP(); } @@ -74,369 +88,51 @@ ConstString PlatformFreeBSD::GetPluginNameStatic(bool is_host) { } } -const char *PlatformFreeBSD::GetDescriptionStatic(bool is_host) { +const char *PlatformFreeBSD::GetPluginDescriptionStatic(bool is_host) { if (is_host) return "Local FreeBSD user platform plug-in."; else return "Remote FreeBSD user platform plug-in."; } -static uint32_t g_initialize_count = 0; +ConstString PlatformFreeBSD::GetPluginName() { + return GetPluginNameStatic(IsHost()); +} void PlatformFreeBSD::Initialize() { Platform::Initialize(); if (g_initialize_count++ == 0) { #if defined(__FreeBSD__) - // Force a host flag to true for the default platform object. PlatformSP default_platform_sp(new PlatformFreeBSD(true)); default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture()); Platform::SetHostPlatform(default_platform_sp); #endif - PluginManager::RegisterPlugin(PlatformFreeBSD::GetPluginNameStatic(false), - PlatformFreeBSD::GetDescriptionStatic(false), - PlatformFreeBSD::CreateInstance); + PluginManager::RegisterPlugin( + PlatformFreeBSD::GetPluginNameStatic(false), + PlatformFreeBSD::GetPluginDescriptionStatic(false), + PlatformFreeBSD::CreateInstance, nullptr); } } void PlatformFreeBSD::Terminate() { - if (g_initialize_count > 0 && --g_initialize_count == 0) - PluginManager::UnregisterPlugin(PlatformFreeBSD::CreateInstance); - - Platform::Terminate(); -} - -bool PlatformFreeBSD::GetModuleSpec(const FileSpec &module_file_spec, - const ArchSpec &arch, - ModuleSpec &module_spec) { - if (m_remote_platform_sp) - return m_remote_platform_sp->GetModuleSpec(module_file_spec, arch, - module_spec); - - return Platform::GetModuleSpec(module_file_spec, arch, module_spec); -} - -Error PlatformFreeBSD::RunShellCommand(const char *command, - const FileSpec &working_dir, - int *status_ptr, int *signo_ptr, - std::string *command_output, - uint32_t timeout_sec) { - if (IsHost()) - return Host::RunShellCommand(command, working_dir, status_ptr, signo_ptr, - command_output, timeout_sec); - else { - if (m_remote_platform_sp) - return m_remote_platform_sp->RunShellCommand(command, working_dir, - status_ptr, signo_ptr, - command_output, timeout_sec); - else - return Error("unable to run a remote command without a platform"); - } -} - -Error PlatformFreeBSD::ResolveExecutable( - const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp, - const FileSpecList *module_search_paths_ptr) { - Error error; - // Nothing special to do here, just use the actual file and architecture - - char exe_path[PATH_MAX]; - ModuleSpec resolved_module_spec(module_spec); - - if (IsHost()) { - // If we have "ls" as the module_spec's file, resolve the executable - // location based on - // the current path variables - if (!resolved_module_spec.GetFileSpec().Exists()) { - module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path)); - resolved_module_spec.GetFileSpec().SetFile(exe_path, true); - } - - if (!resolved_module_spec.GetFileSpec().Exists()) - resolved_module_spec.GetFileSpec().ResolveExecutableLocation(); - - if (resolved_module_spec.GetFileSpec().Exists()) - error.Clear(); - else { - error.SetErrorStringWithFormat( - "unable to find executable for '%s'", - resolved_module_spec.GetFileSpec().GetPath().c_str()); - } - } else { - if (m_remote_platform_sp) { - error = - GetCachedExecutable(resolved_module_spec, exe_module_sp, - module_search_paths_ptr, *m_remote_platform_sp); - } else { - // We may connect to a process and use the provided executable (Don't use - // local $PATH). - - // Resolve any executable within a bundle on MacOSX - Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec()); - - if (resolved_module_spec.GetFileSpec().Exists()) { - error.Clear(); - } else { - error.SetErrorStringWithFormat( - "the platform is not currently connected, and '%s' doesn't exist " - "in the system root.", - resolved_module_spec.GetFileSpec().GetPath().c_str()); - } + if (g_initialize_count > 0) { + if (--g_initialize_count == 0) { + PluginManager::UnregisterPlugin(PlatformFreeBSD::CreateInstance); } } - if (error.Success()) { - if (resolved_module_spec.GetArchitecture().IsValid()) { - error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, - module_search_paths_ptr, NULL, NULL); - - if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL) { - exe_module_sp.reset(); - error.SetErrorStringWithFormat( - "'%s' doesn't contain the architecture %s", - resolved_module_spec.GetFileSpec().GetPath().c_str(), - resolved_module_spec.GetArchitecture().GetArchitectureName()); - } - } else { - // No valid architecture was specified, ask the platform for - // the architectures that we should be using (in the correct order) - // and see if we can find a match that way - StreamString arch_names; - for (uint32_t idx = 0; GetSupportedArchitectureAtIndex( - idx, resolved_module_spec.GetArchitecture()); - ++idx) { - error = - ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, - module_search_paths_ptr, NULL, NULL); - // Did we find an executable using one of the - if (error.Success()) { - if (exe_module_sp && exe_module_sp->GetObjectFile()) - break; - else - error.SetErrorToGenericError(); - } - - if (idx > 0) - arch_names.PutCString(", "); - arch_names.PutCString( - resolved_module_spec.GetArchitecture().GetArchitectureName()); - } - - if (error.Fail() || !exe_module_sp) { - if (resolved_module_spec.GetFileSpec().Readable()) { - error.SetErrorStringWithFormat( - "'%s' doesn't contain any '%s' platform architectures: %s", - resolved_module_spec.GetFileSpec().GetPath().c_str(), - GetPluginName().GetCString(), arch_names.GetData()); - } else { - error.SetErrorStringWithFormat( - "'%s' is not readable", - resolved_module_spec.GetFileSpec().GetPath().c_str()); - } - } - } - } - - return error; -} - -// From PlatformMacOSX only -Error PlatformFreeBSD::GetFileWithUUID(const FileSpec &platform_file, - const UUID *uuid_ptr, - FileSpec &local_file) { - if (IsRemote()) { - if (m_remote_platform_sp) - return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr, - local_file); - } - - // Default to the local case - local_file = platform_file; - return Error(); + PlatformPOSIX::Terminate(); } //------------------------------------------------------------------ /// Default Constructor //------------------------------------------------------------------ PlatformFreeBSD::PlatformFreeBSD(bool is_host) - : Platform(is_host), m_remote_platform_sp() {} - -//------------------------------------------------------------------ -/// Destructor. -/// -/// The destructor is virtual since this class is designed to be -/// inherited from by the plug-in instance. -//------------------------------------------------------------------ -PlatformFreeBSD::~PlatformFreeBSD() {} - -// TODO:VK: inherit PlatformPOSIX - -bool PlatformFreeBSD::GetRemoteOSVersion() { - if (m_remote_platform_sp) - return m_remote_platform_sp->GetOSVersion( - m_major_os_version, m_minor_os_version, m_update_os_version); - return false; -} - -bool PlatformFreeBSD::GetRemoteOSBuildString(std::string &s) { - if (m_remote_platform_sp) - return m_remote_platform_sp->GetRemoteOSBuildString(s); - s.clear(); - return false; -} - -bool PlatformFreeBSD::GetRemoteOSKernelDescription(std::string &s) { - if (m_remote_platform_sp) - return m_remote_platform_sp->GetRemoteOSKernelDescription(s); - s.clear(); - return false; -} - -// Remote Platform subclasses need to override this function -ArchSpec PlatformFreeBSD::GetRemoteSystemArchitecture() { - if (m_remote_platform_sp) - return m_remote_platform_sp->GetRemoteSystemArchitecture(); - return ArchSpec(); -} - -const char *PlatformFreeBSD::GetHostname() { - if (IsHost()) - return Platform::GetHostname(); - - if (m_remote_platform_sp) - return m_remote_platform_sp->GetHostname(); - return NULL; -} - -bool PlatformFreeBSD::IsConnected() const { - if (IsHost()) - return true; - else if (m_remote_platform_sp) - return m_remote_platform_sp->IsConnected(); - return false; -} + : PlatformPOSIX(is_host) // This is the local host platform +{} -Error PlatformFreeBSD::ConnectRemote(Args &args) { - Error error; - if (IsHost()) { - error.SetErrorStringWithFormat( - "can't connect to the host platform '%s', always connected", - GetPluginName().GetCString()); - } else { - if (!m_remote_platform_sp) - m_remote_platform_sp = - Platform::Create(ConstString("remote-gdb-server"), error); - - if (m_remote_platform_sp) { - if (error.Success()) { - if (m_remote_platform_sp) { - error = m_remote_platform_sp->ConnectRemote(args); - } else { - error.SetErrorString( - "\"platform connect\" takes a single argument: <connect-url>"); - } - } - } else - error.SetErrorString("failed to create a 'remote-gdb-server' platform"); - - if (error.Fail()) - m_remote_platform_sp.reset(); - } - - return error; -} - -Error PlatformFreeBSD::DisconnectRemote() { - Error error; - - if (IsHost()) { - error.SetErrorStringWithFormat( - "can't disconnect from the host platform '%s', always connected", - GetPluginName().GetCString()); - } else { - if (m_remote_platform_sp) - error = m_remote_platform_sp->DisconnectRemote(); - else - error.SetErrorString("the platform is not currently connected"); - } - return error; -} - -bool PlatformFreeBSD::GetProcessInfo(lldb::pid_t pid, - ProcessInstanceInfo &process_info) { - bool success = false; - if (IsHost()) { - success = Platform::GetProcessInfo(pid, process_info); - } else if (m_remote_platform_sp) { - success = m_remote_platform_sp->GetProcessInfo(pid, process_info); - } - return success; -} - -uint32_t -PlatformFreeBSD::FindProcesses(const ProcessInstanceInfoMatch &match_info, - ProcessInstanceInfoList &process_infos) { - uint32_t match_count = 0; - if (IsHost()) { - // Let the base class figure out the host details - match_count = Platform::FindProcesses(match_info, process_infos); - } else { - // If we are remote, we can only return results if we are connected - if (m_remote_platform_sp) - match_count = - m_remote_platform_sp->FindProcesses(match_info, process_infos); - } - return match_count; -} - -const char *PlatformFreeBSD::GetUserName(uint32_t uid) { - // Check the cache in Platform in case we have already looked this uid up - const char *user_name = Platform::GetUserName(uid); - if (user_name) - return user_name; - - if (IsRemote() && m_remote_platform_sp) - return m_remote_platform_sp->GetUserName(uid); - return NULL; -} - -const char *PlatformFreeBSD::GetGroupName(uint32_t gid) { - const char *group_name = Platform::GetGroupName(gid); - if (group_name) - return group_name; - - if (IsRemote() && m_remote_platform_sp) - return m_remote_platform_sp->GetGroupName(gid); - return NULL; -} - -Error PlatformFreeBSD::GetSharedModule( - const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp, - const FileSpecList *module_search_paths_ptr, ModuleSP *old_module_sp_ptr, - bool *did_create_ptr) { - Error error; - module_sp.reset(); - - if (IsRemote()) { - // If we have a remote platform always, let it try and locate - // the shared module first. - if (m_remote_platform_sp) { - error = m_remote_platform_sp->GetSharedModule( - module_spec, process, module_sp, module_search_paths_ptr, - old_module_sp_ptr, did_create_ptr); - } - } - - if (!module_sp) { - // Fall back to the local platform and find the file locally - error = Platform::GetSharedModule(module_spec, process, module_sp, - module_search_paths_ptr, - old_module_sp_ptr, did_create_ptr); - } - if (module_sp) - module_sp->SetPlatformFileSpec(module_spec.GetFileSpec()); - return error; -} +PlatformFreeBSD::~PlatformFreeBSD() = default; bool PlatformFreeBSD::GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) { @@ -507,26 +203,23 @@ bool PlatformFreeBSD::GetSupportedArchitectureAtIndex(uint32_t idx, } void PlatformFreeBSD::GetStatus(Stream &strm) { -#ifndef LLDB_DISABLE_POSIX - struct utsname un; - - strm << " Host: "; + Platform::GetStatus(strm); - ::memset(&un, 0, sizeof(utsname)); - if (uname(&un) == -1) - strm << "FreeBSD" << '\n'; +#ifndef LLDB_DISABLE_POSIX + // Display local kernel information only when we are running in host mode. + // Otherwise, we would end up printing non-FreeBSD information (when running + // on Mac OS for example). + if (IsHost()) { + struct utsname un; - strm << un.sysname << ' ' << un.release; - if (un.nodename[0] != '\0') - strm << " (" << un.nodename << ')'; - strm << '\n'; + if (uname(&un)) + return; - // Dump a common information about the platform status. - strm << "Host: " << un.sysname << ' ' << un.release << ' ' << un.version - << '\n'; + strm.Printf(" Kernel: %s\n", un.sysname); + strm.Printf(" Release: %s\n", un.release); + strm.Printf(" Version: %s\n", un.version); + } #endif - - Platform::GetStatus(strm); } size_t @@ -549,6 +242,12 @@ PlatformFreeBSD::GetSoftwareBreakpointTrapOpcode(Target &target, // FreeBSD kernel as of 10.x, does not support thumb breakpoints return 0; } + + static const uint8_t g_arm_breakpoint_opcode[] = {0xFE, 0xDE, 0xFF, 0xE7}; + size_t trap_opcode_size = sizeof(g_arm_breakpoint_opcode); + assert(bp_site); + if (bp_site->SetTrapOpcode(g_arm_breakpoint_opcode, trap_opcode_size)) + return trap_opcode_size; } LLVM_FALLTHROUGH; default: @@ -556,10 +255,6 @@ PlatformFreeBSD::GetSoftwareBreakpointTrapOpcode(Target &target, } } -void PlatformFreeBSD::CalculateTrapHandlerSymbolNames() { - m_trap_handlers.push_back(ConstString("_sigtramp")); -} - Error PlatformFreeBSD::LaunchProcess(ProcessLaunchInfo &launch_info) { Error error; if (IsHost()) { @@ -609,3 +304,23 @@ lldb::ProcessSP PlatformFreeBSD::Attach(ProcessAttachInfo &attach_info, } return process_sp; } + +// FreeBSD processes cannot yet be launched by spawning and attaching. +bool PlatformFreeBSD::CanDebugProcess() { + return false; +} + +void PlatformFreeBSD::CalculateTrapHandlerSymbolNames() { + m_trap_handlers.push_back(ConstString("_sigtramp")); +} + +uint64_t PlatformFreeBSD::ConvertMmapFlagsToPlatform(const ArchSpec &arch, + unsigned flags) { + uint64_t flags_platform = 0; + + if (flags & eMmapFlagsPrivate) + flags_platform |= MAP_PRIVATE; + if (flags & eMmapFlagsAnon) + flags_platform |= MAP_ANON; + return flags_platform; +} diff --git a/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h b/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h index f0ebfbcae701..c8ac7b29f3a2 100644 --- a/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h +++ b/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h @@ -10,116 +10,59 @@ #ifndef liblldb_PlatformFreeBSD_h_ #define liblldb_PlatformFreeBSD_h_ -// C Includes -// C++ Includes -// Other libraries and framework includes -// Project includes -#include "lldb/Target/Platform.h" +#include "Plugins/Platform/POSIX/PlatformPOSIX.h" namespace lldb_private { namespace platform_freebsd { -class PlatformFreeBSD : public Platform { +class PlatformFreeBSD : public PlatformPOSIX { public: PlatformFreeBSD(bool is_host); ~PlatformFreeBSD() override; - //------------------------------------------------------------ - // Class functions - //------------------------------------------------------------ - static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch); - static void Initialize(); static void Terminate(); - static ConstString GetPluginNameStatic(bool is_host); - - static const char *GetDescriptionStatic(bool is_host); - //------------------------------------------------------------ // lldb_private::PluginInterface functions //------------------------------------------------------------ - ConstString GetPluginName() override { return GetPluginNameStatic(IsHost()); } + static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch); - uint32_t GetPluginVersion() override { return 1; } + static ConstString GetPluginNameStatic(bool is_host); - const char *GetDescription() override { - return GetDescriptionStatic(IsHost()); - } + static const char *GetPluginDescriptionStatic(bool is_host); + + ConstString GetPluginName() override; + + uint32_t GetPluginVersion() override { return 1; } //------------------------------------------------------------ // lldb_private::Platform functions //------------------------------------------------------------ - bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, - ModuleSpec &module_spec) override; + const char *GetDescription() override { + return GetPluginDescriptionStatic(IsHost()); + } - Error RunShellCommand(const char *command, const FileSpec &working_dir, - int *status_ptr, int *signo_ptr, - std::string *command_output, - uint32_t timeout_sec) override; + void GetStatus(Stream &strm) override; + + bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override; - Error ResolveExecutable(const ModuleSpec &module_spec, - lldb::ModuleSP &module_sp, - const FileSpecList *module_search_paths_ptr) override; + bool CanDebugProcess() override; size_t GetSoftwareBreakpointTrapOpcode(Target &target, BreakpointSite *bp_site) override; - bool GetRemoteOSVersion() override; - - bool GetRemoteOSBuildString(std::string &s) override; - - bool GetRemoteOSKernelDescription(std::string &s) override; - - // Remote Platform subclasses need to override this function - ArchSpec GetRemoteSystemArchitecture() override; - - bool IsConnected() const override; - - Error ConnectRemote(Args &args) override; - - Error DisconnectRemote() override; - - const char *GetHostname() override; - - const char *GetUserName(uint32_t uid) override; - - const char *GetGroupName(uint32_t gid) override; - - bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override; - - uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, - ProcessInstanceInfoList &process_infos) override; - Error LaunchProcess(ProcessLaunchInfo &launch_info) override; lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger, Target *target, Error &error) override; - // FreeBSD processes can not be launched by spawning and attaching. - bool CanDebugProcess() override { return false; } - - // Only on PlatformMacOSX: - Error GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid, - FileSpec &local_file) override; - - Error GetSharedModule(const ModuleSpec &module_spec, Process *process, - lldb::ModuleSP &module_sp, - const FileSpecList *module_search_paths_ptr, - lldb::ModuleSP *old_module_sp_ptr, - bool *did_create_ptr) override; - - bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override; - - void GetStatus(Stream &strm) override; - void CalculateTrapHandlerSymbolNames() override; -protected: - lldb::PlatformSP m_remote_platform_sp; // Allow multiple ways to connect to a - // remote freebsd OS + uint64_t ConvertMmapFlagsToPlatform(const ArchSpec &arch, + unsigned flags) override; private: DISALLOW_COPY_AND_ASSIGN(PlatformFreeBSD); diff --git a/source/Plugins/Platform/Kalimba/CMakeLists.txt b/source/Plugins/Platform/Kalimba/CMakeLists.txt index df0bf9761a00..02f1827f9a48 100644 --- a/source/Plugins/Platform/Kalimba/CMakeLists.txt +++ b/source/Plugins/Platform/Kalimba/CMakeLists.txt @@ -1,3 +1,8 @@ -add_lldb_library(lldbPluginPlatformKalimba +add_lldb_library(lldbPluginPlatformKalimba PLUGIN PlatformKalimba.cpp + + LINK_LIBS + lldbCore + lldbHost + lldbTarget ) diff --git a/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp b/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp index ac3fe6eafd52..08a3a6aa6c26 100644 --- a/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp +++ b/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp @@ -15,16 +15,16 @@ // Other libraries and framework includes // Project includes #include "lldb/Core/Debugger.h" -#include "lldb/Core/Error.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/StreamString.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/HostInfo.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/StreamString.h" using namespace lldb; using namespace lldb_private; @@ -84,104 +84,6 @@ void PlatformKalimba::Terminate() { Platform::Terminate(); } -Error PlatformKalimba::ResolveExecutable( - const ModuleSpec &ms, lldb::ModuleSP &exe_module_sp, - const FileSpecList *module_search_paths_ptr) { - Error error; - char exe_path[PATH_MAX]; - ModuleSpec resolved_module_spec(ms); - - if (!resolved_module_spec.GetFileSpec().Exists()) { - resolved_module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path)); - error.SetErrorStringWithFormat("unable to find executable for '%s'", - exe_path); - } - - if (error.Success()) { - if (resolved_module_spec.GetArchitecture().IsValid()) { - error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, - NULL, NULL, NULL); - if (error.Fail()) { - // If we failed, it may be because the vendor and os aren't known. If - // that is the - // case, try setting them to the host architecture and give it another - // try. - llvm::Triple &module_triple = - resolved_module_spec.GetArchitecture().GetTriple(); - bool is_vendor_specified = - (module_triple.getVendor() != llvm::Triple::UnknownVendor); - bool is_os_specified = - (module_triple.getOS() != llvm::Triple::UnknownOS); - if (!is_vendor_specified || !is_os_specified) { - const llvm::Triple &host_triple = - HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple(); - - if (!is_vendor_specified) - module_triple.setVendorName(host_triple.getVendorName()); - if (!is_os_specified) - module_triple.setOSName(host_triple.getOSName()); - - error = ModuleList::GetSharedModule(resolved_module_spec, - exe_module_sp, NULL, NULL, NULL); - } - } - - // TODO find out why exe_module_sp might be NULL - if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL) { - exe_module_sp.reset(); - error.SetErrorStringWithFormat( - "'%s' doesn't contain the architecture %s", - resolved_module_spec.GetFileSpec().GetPath().c_str(), - resolved_module_spec.GetArchitecture().GetArchitectureName()); - } - } else { - // No valid architecture was specified, ask the platform for - // the architectures that we should be using (in the correct order) - // and see if we can find a match that way - StreamString arch_names; - for (uint32_t idx = 0; GetSupportedArchitectureAtIndex( - idx, resolved_module_spec.GetArchitecture()); - ++idx) { - error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, - NULL, NULL, NULL); - // Did we find an executable using one of the - if (error.Success()) { - if (exe_module_sp && exe_module_sp->GetObjectFile()) - break; - else - error.SetErrorToGenericError(); - } - - if (idx > 0) - arch_names.PutCString(", "); - arch_names.PutCString( - resolved_module_spec.GetArchitecture().GetArchitectureName()); - } - - if (error.Fail() || !exe_module_sp) { - if (resolved_module_spec.GetFileSpec().Readable()) { - error.SetErrorStringWithFormat( - "'%s' doesn't contain any '%s' platform architectures: %s", - resolved_module_spec.GetFileSpec().GetPath().c_str(), - GetPluginName().GetCString(), arch_names.GetData()); - } else { - error.SetErrorStringWithFormat( - "'%s' is not readable", - resolved_module_spec.GetFileSpec().GetPath().c_str()); - } - } - } - } - - return error; -} - -Error PlatformKalimba::GetFileWithUUID(const FileSpec & /*platform_file*/, - const UUID * /*uuid_ptr*/, - FileSpec & /*local_file*/) { - return Error(); -} - //------------------------------------------------------------------ /// Default Constructor //------------------------------------------------------------------ @@ -197,18 +99,6 @@ PlatformKalimba::PlatformKalimba(bool is_host) //------------------------------------------------------------------ PlatformKalimba::~PlatformKalimba() {} -bool PlatformKalimba::GetProcessInfo(lldb::pid_t pid, - ProcessInstanceInfo &process_info) { - bool success = false; - if (IsHost()) { - success = false; - } else { - if (m_remote_platform_sp) - success = m_remote_platform_sp->GetProcessInfo(pid, process_info); - } - return success; -} - bool PlatformKalimba::GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) { if (idx == 0) { diff --git a/source/Plugins/Platform/Kalimba/PlatformKalimba.h b/source/Plugins/Platform/Kalimba/PlatformKalimba.h index 76e6d41e8716..0c94ec9ec8f7 100644 --- a/source/Plugins/Platform/Kalimba/PlatformKalimba.h +++ b/source/Plugins/Platform/Kalimba/PlatformKalimba.h @@ -45,21 +45,12 @@ public: //------------------------------------------------------------ // lldb_private::Platform functions //------------------------------------------------------------ - Error ResolveExecutable(const lldb_private::ModuleSpec &module_spec, - lldb::ModuleSP &module_sp, - const FileSpecList *module_search_paths_ptr) override; - const char *GetDescription() override { return GetPluginDescriptionStatic(IsHost()); } void GetStatus(Stream &strm) override; - Error GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid, - FileSpec &local_file) override; - - bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override; - bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override; size_t GetSoftwareBreakpointTrapOpcode(Target &target, diff --git a/source/Plugins/Platform/Linux/CMakeLists.txt b/source/Plugins/Platform/Linux/CMakeLists.txt index 4a9eb1460e38..bad039d0ad50 100644 --- a/source/Plugins/Platform/Linux/CMakeLists.txt +++ b/source/Plugins/Platform/Linux/CMakeLists.txt @@ -1,3 +1,11 @@ -add_lldb_library(lldbPluginPlatformLinux +add_lldb_library(lldbPluginPlatformLinux PLUGIN PlatformLinux.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbHost + lldbInterpreter + lldbTarget + lldbPluginPlatformPOSIX ) diff --git a/source/Plugins/Platform/Linux/PlatformLinux.cpp b/source/Plugins/Platform/Linux/PlatformLinux.cpp index 036c0f1be835..4dd5398fcfa3 100644 --- a/source/Plugins/Platform/Linux/PlatformLinux.cpp +++ b/source/Plugins/Platform/Linux/PlatformLinux.cpp @@ -19,22 +19,16 @@ // C++ Includes // Other libraries and framework includes // Project includes -#include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" -#include "lldb/Core/Module.h" -#include "lldb/Core/ModuleList.h" -#include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/State.h" -#include "lldb/Core/StreamString.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/HostInfo.h" -#include "lldb/Interpreter/OptionValueProperties.h" -#include "lldb/Interpreter/Property.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" // Define these constants from Linux mman.h for use when targeting // remote linux systems even when host has different values. @@ -48,79 +42,12 @@ using namespace lldb_private::platform_linux; static uint32_t g_initialize_count = 0; //------------------------------------------------------------------ -/// Code to handle the PlatformLinux settings -//------------------------------------------------------------------ - -namespace { -class PlatformLinuxProperties : public Properties { -public: - PlatformLinuxProperties(); - - ~PlatformLinuxProperties() override = default; - - static ConstString &GetSettingName(); - -private: - static const PropertyDefinition *GetStaticPropertyDefinitions(); -}; - -typedef std::shared_ptr<PlatformLinuxProperties> PlatformLinuxPropertiesSP; - -} // anonymous namespace - -PlatformLinuxProperties::PlatformLinuxProperties() : Properties() { - m_collection_sp.reset(new OptionValueProperties(GetSettingName())); - m_collection_sp->Initialize(GetStaticPropertyDefinitions()); -} - -ConstString &PlatformLinuxProperties::GetSettingName() { - static ConstString g_setting_name("linux"); - return g_setting_name; -} - -const PropertyDefinition * -PlatformLinuxProperties::GetStaticPropertyDefinitions() { - static PropertyDefinition g_properties[] = { - {NULL, OptionValue::eTypeInvalid, false, 0, NULL, NULL, NULL}}; - - return g_properties; -} - -static const PlatformLinuxPropertiesSP &GetGlobalProperties() { - static PlatformLinuxPropertiesSP g_settings_sp; - if (!g_settings_sp) - g_settings_sp.reset(new PlatformLinuxProperties()); - return g_settings_sp; -} - -void PlatformLinux::DebuggerInitialize(Debugger &debugger) { - if (!PluginManager::GetSettingForPlatformPlugin( - debugger, PlatformLinuxProperties::GetSettingName())) { - const bool is_global_setting = true; - PluginManager::CreateSettingForPlatformPlugin( - debugger, GetGlobalProperties()->GetValueProperties(), - ConstString("Properties for the PlatformLinux plug-in."), - is_global_setting); - } -} - -//------------------------------------------------------------------ PlatformSP PlatformLinux::CreateInstance(bool force, const ArchSpec *arch) { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); - if (log) { - const char *arch_name; - if (arch && arch->GetArchitectureName()) - arch_name = arch->GetArchitectureName(); - else - arch_name = "<null>"; - - const char *triple_cstr = - arch ? arch->GetTriple().getTriple().c_str() : "<null>"; - - log->Printf("PlatformLinux::%s(force=%s, arch={%s,%s})", __FUNCTION__, - force ? "true" : "false", arch_name, triple_cstr); - } + LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force, + arch ? arch->GetArchitectureName() : "<null>", + arch ? arch->GetTriple().getTriple() : "<null>"); bool create = force; if (create == false && arch && arch->IsValid()) { @@ -143,18 +70,10 @@ PlatformSP PlatformLinux::CreateInstance(bool force, const ArchSpec *arch) { } } + LLDB_LOG(log, "create = {0}", create); if (create) { - if (log) - log->Printf("PlatformLinux::%s() creating remote-linux platform", - __FUNCTION__); return PlatformSP(new PlatformLinux(false)); } - - if (log) - log->Printf( - "PlatformLinux::%s() aborting creation of remote-linux platform", - __FUNCTION__); - return PlatformSP(); } @@ -191,7 +110,7 @@ void PlatformLinux::Initialize() { PluginManager::RegisterPlugin( PlatformLinux::GetPluginNameStatic(false), PlatformLinux::GetPluginDescriptionStatic(false), - PlatformLinux::CreateInstance, PlatformLinux::DebuggerInitialize); + PlatformLinux::CreateInstance, nullptr); } } @@ -205,145 +124,6 @@ void PlatformLinux::Terminate() { PlatformPOSIX::Terminate(); } -Error PlatformLinux::ResolveExecutable( - const ModuleSpec &ms, lldb::ModuleSP &exe_module_sp, - const FileSpecList *module_search_paths_ptr) { - Error error; - // Nothing special to do here, just use the actual file and architecture - - char exe_path[PATH_MAX]; - ModuleSpec resolved_module_spec(ms); - - if (IsHost()) { - // If we have "ls" as the exe_file, resolve the executable location based on - // the current path variables - if (!resolved_module_spec.GetFileSpec().Exists()) { - resolved_module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path)); - resolved_module_spec.GetFileSpec().SetFile(exe_path, true); - } - - if (!resolved_module_spec.GetFileSpec().Exists()) - resolved_module_spec.GetFileSpec().ResolveExecutableLocation(); - - if (resolved_module_spec.GetFileSpec().Exists()) - error.Clear(); - else { - error.SetErrorStringWithFormat( - "unable to find executable for '%s'", - resolved_module_spec.GetFileSpec().GetPath().c_str()); - } - } else { - if (m_remote_platform_sp) { - error = - GetCachedExecutable(resolved_module_spec, exe_module_sp, - module_search_paths_ptr, *m_remote_platform_sp); - } else { - // We may connect to a process and use the provided executable (Don't use - // local $PATH). - - if (resolved_module_spec.GetFileSpec().Exists()) - error.Clear(); - else - error.SetErrorStringWithFormat("the platform is not currently " - "connected, and '%s' doesn't exist in " - "the system root.", - exe_path); - } - } - - if (error.Success()) { - if (resolved_module_spec.GetArchitecture().IsValid()) { - error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, - NULL, NULL, NULL); - if (error.Fail()) { - // If we failed, it may be because the vendor and os aren't known. If - // that is the - // case, try setting them to the host architecture and give it another - // try. - llvm::Triple &module_triple = - resolved_module_spec.GetArchitecture().GetTriple(); - bool is_vendor_specified = - (module_triple.getVendor() != llvm::Triple::UnknownVendor); - bool is_os_specified = - (module_triple.getOS() != llvm::Triple::UnknownOS); - if (!is_vendor_specified || !is_os_specified) { - const llvm::Triple &host_triple = - HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple(); - - if (!is_vendor_specified) - module_triple.setVendorName(host_triple.getVendorName()); - if (!is_os_specified) - module_triple.setOSName(host_triple.getOSName()); - - error = ModuleList::GetSharedModule(resolved_module_spec, - exe_module_sp, NULL, NULL, NULL); - } - } - - // TODO find out why exe_module_sp might be NULL - if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL) { - exe_module_sp.reset(); - error.SetErrorStringWithFormat( - "'%s' doesn't contain the architecture %s", - resolved_module_spec.GetFileSpec().GetPath().c_str(), - resolved_module_spec.GetArchitecture().GetArchitectureName()); - } - } else { - // No valid architecture was specified, ask the platform for - // the architectures that we should be using (in the correct order) - // and see if we can find a match that way - StreamString arch_names; - for (uint32_t idx = 0; GetSupportedArchitectureAtIndex( - idx, resolved_module_spec.GetArchitecture()); - ++idx) { - error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, - NULL, NULL, NULL); - // Did we find an executable using one of the - if (error.Success()) { - if (exe_module_sp && exe_module_sp->GetObjectFile()) - break; - else - error.SetErrorToGenericError(); - } - - if (idx > 0) - arch_names.PutCString(", "); - arch_names.PutCString( - resolved_module_spec.GetArchitecture().GetArchitectureName()); - } - - if (error.Fail() || !exe_module_sp) { - if (resolved_module_spec.GetFileSpec().Readable()) { - error.SetErrorStringWithFormat( - "'%s' doesn't contain any '%s' platform architectures: %s", - resolved_module_spec.GetFileSpec().GetPath().c_str(), - GetPluginName().GetCString(), arch_names.GetData()); - } else { - error.SetErrorStringWithFormat( - "'%s' is not readable", - resolved_module_spec.GetFileSpec().GetPath().c_str()); - } - } - } - } - - return error; -} - -Error PlatformLinux::GetFileWithUUID(const FileSpec &platform_file, - const UUID *uuid_ptr, - FileSpec &local_file) { - if (IsRemote()) { - if (m_remote_platform_sp) - return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr, - local_file); - } - - // Default to the local case - local_file = platform_file; - return Error(); -} - //------------------------------------------------------------------ /// Default Constructor //------------------------------------------------------------------ @@ -351,42 +131,8 @@ PlatformLinux::PlatformLinux(bool is_host) : PlatformPOSIX(is_host) // This is the local host platform {} -//------------------------------------------------------------------ -/// Destructor. -/// -/// The destructor is virtual since this class is designed to be -/// inherited from by the plug-in instance. -//------------------------------------------------------------------ PlatformLinux::~PlatformLinux() = default; -bool PlatformLinux::GetProcessInfo(lldb::pid_t pid, - ProcessInstanceInfo &process_info) { - bool success = false; - if (IsHost()) { - success = Platform::GetProcessInfo(pid, process_info); - } else { - if (m_remote_platform_sp) - success = m_remote_platform_sp->GetProcessInfo(pid, process_info); - } - return success; -} - -uint32_t -PlatformLinux::FindProcesses(const ProcessInstanceInfoMatch &match_info, - ProcessInstanceInfoList &process_infos) { - uint32_t match_count = 0; - if (IsHost()) { - // Let the base class figure out the host details - match_count = Platform::FindProcesses(match_info, process_infos); - } else { - // If we are remote, we can only return results if we are connected - if (m_remote_platform_sp) - match_count = - m_remote_platform_sp->FindProcesses(match_info, process_infos); - } - return match_count; -} - bool PlatformLinux::GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) { if (IsHost()) { @@ -526,19 +272,15 @@ bool PlatformLinux::CanDebugProcess() { } // For local debugging, Linux will override the debug logic to use llgs-launch -// rather than -// lldb-launch, llgs-attach. This differs from current lldb-launch, -// debugserver-attach -// approach on MacOSX. +// rather than lldb-launch, llgs-attach. This differs from current lldb-launch, +// debugserver-attach approach on MacOSX. lldb::ProcessSP PlatformLinux::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, Target *target, // Can be NULL, if NULL create a new // target, else use existing one Error &error) { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); - if (log) - log->Printf("PlatformLinux::%s entered (target %p)", __FUNCTION__, - static_cast<void *>(target)); + LLDB_LOG(log, "target {0}", target); // If we're a remote host, use standard behavior from parent class. if (!IsHost()) @@ -561,61 +303,42 @@ PlatformLinux::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, // Ensure we have a target. if (target == nullptr) { - if (log) - log->Printf("PlatformLinux::%s creating new target", __FUNCTION__); - + LLDB_LOG(log, "creating new target"); TargetSP new_target_sp; error = debugger.GetTargetList().CreateTarget(debugger, "", "", false, nullptr, new_target_sp); if (error.Fail()) { - if (log) - log->Printf("PlatformLinux::%s failed to create new target: %s", - __FUNCTION__, error.AsCString()); + LLDB_LOG(log, "failed to create new target: {0}", error); return process_sp; } target = new_target_sp.get(); if (!target) { error.SetErrorString("CreateTarget() returned nullptr"); - if (log) - log->Printf("PlatformLinux::%s failed: %s", __FUNCTION__, - error.AsCString()); + LLDB_LOG(log, "error: {0}", error); return process_sp; } - } else { - if (log) - log->Printf("PlatformLinux::%s using provided target", __FUNCTION__); } // Mark target as currently selected target. debugger.GetTargetList().SetSelectedTarget(target); // Now create the gdb-remote process. - if (log) - log->Printf( - "PlatformLinux::%s having target create process with gdb-remote plugin", - __FUNCTION__); + LLDB_LOG(log, "having target create process with gdb-remote plugin"); process_sp = target->CreateProcess( launch_info.GetListenerForProcess(debugger), "gdb-remote", nullptr); if (!process_sp) { error.SetErrorString("CreateProcess() failed for gdb-remote process"); - if (log) - log->Printf("PlatformLinux::%s failed: %s", __FUNCTION__, - error.AsCString()); + LLDB_LOG(log, "error: {0}", error); return process_sp; - } else { - if (log) - log->Printf("PlatformLinux::%s successfully created process", - __FUNCTION__); } + LLDB_LOG(log, "successfully created process"); // Adjust launch for a hijacker. ListenerSP listener_sp; if (!launch_info.GetHijackListener()) { - if (log) - log->Printf("PlatformLinux::%s setting up hijacker", __FUNCTION__); - + LLDB_LOG(log, "setting up hijacker"); listener_sp = Listener::MakeListener("lldb.PlatformLinux.DebugProcess.hijack"); launch_info.SetHijackListener(listener_sp); @@ -624,16 +347,13 @@ PlatformLinux::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, // Log file actions. if (log) { - log->Printf( - "PlatformLinux::%s launching process with the following file actions:", - __FUNCTION__); - + LLDB_LOG(log, "launching process with the following file actions:"); StreamString stream; size_t i = 0; const FileAction *file_action; while ((file_action = launch_info.GetFileActionAtIndex(i++)) != nullptr) { file_action->Dump(stream); - log->PutCString(stream.GetData()); + LLDB_LOG(log, "{0}", stream.GetData()); stream.Clear(); } } @@ -646,16 +366,7 @@ PlatformLinux::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, const StateType state = process_sp->WaitForProcessToStop( llvm::None, NULL, false, listener_sp); - if (state == eStateStopped) { - if (log) - log->Printf("PlatformLinux::%s pid %" PRIu64 " state %s\n", - __FUNCTION__, process_sp->GetID(), StateAsCString(state)); - } else { - if (log) - log->Printf("PlatformLinux::%s pid %" PRIu64 - " state is not stopped - %s\n", - __FUNCTION__, process_sp->GetID(), StateAsCString(state)); - } + LLDB_LOG(log, "pid {0} state {0}", process_sp->GetID(), state); } // Hook up process PTY if we have one (which we should for local debugging @@ -663,20 +374,11 @@ PlatformLinux::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor(); if (pty_fd != lldb_utility::PseudoTerminal::invalid_fd) { process_sp->SetSTDIOFileDescriptor(pty_fd); - if (log) - log->Printf("PlatformLinux::%s pid %" PRIu64 - " hooked up STDIO pty to process", - __FUNCTION__, process_sp->GetID()); - } else { - if (log) - log->Printf("PlatformLinux::%s pid %" PRIu64 - " not using process STDIO pty", - __FUNCTION__, process_sp->GetID()); - } + LLDB_LOG(log, "hooked up STDIO pty to process"); + } else + LLDB_LOG(log, "not using process STDIO pty"); } else { - if (log) - log->Printf("PlatformLinux::%s process launch failed: %s", __FUNCTION__, - error.AsCString()); + LLDB_LOG(log, "process launch failed: {0}", error); // FIXME figure out appropriate cleanup here. Do we delete the target? Do // we delete the process? Does our caller do that? } @@ -707,11 +409,3 @@ uint64_t PlatformLinux::ConvertMmapFlagsToPlatform(const ArchSpec &arch, return flags_platform; } -ConstString PlatformLinux::GetFullNameForDylib(ConstString basename) { - if (basename.IsEmpty()) - return basename; - - StreamString stream; - stream.Printf("lib%s.so", basename.GetCString()); - return ConstString(stream.GetString()); -} diff --git a/source/Plugins/Platform/Linux/PlatformLinux.h b/source/Plugins/Platform/Linux/PlatformLinux.h index f98c3e988cd1..f1386d1e4fe5 100644 --- a/source/Plugins/Platform/Linux/PlatformLinux.h +++ b/source/Plugins/Platform/Linux/PlatformLinux.h @@ -10,10 +10,6 @@ #ifndef liblldb_PlatformLinux_h_ #define liblldb_PlatformLinux_h_ -// C Includes -// C++ Includes -// Other libraries and framework includes -// Project includes #include "Plugins/Platform/POSIX/PlatformPOSIX.h" namespace lldb_private { @@ -25,8 +21,6 @@ public: ~PlatformLinux() override; - static void DebuggerInitialize(Debugger &debugger); - static void Initialize(); static void Terminate(); @@ -47,24 +41,12 @@ public: //------------------------------------------------------------ // lldb_private::Platform functions //------------------------------------------------------------ - Error ResolveExecutable(const ModuleSpec &module_spec, - lldb::ModuleSP &module_sp, - const FileSpecList *module_search_paths_ptr) override; - const char *GetDescription() override { return GetPluginDescriptionStatic(IsHost()); } void GetStatus(Stream &strm) override; - Error GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid, - FileSpec &local_file) override; - - bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override; - - uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, - ProcessInstanceInfoList &process_infos) override; - bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override; int32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) override; @@ -80,8 +62,6 @@ public: uint64_t ConvertMmapFlagsToPlatform(const ArchSpec &arch, unsigned flags) override; - ConstString GetFullNameForDylib(ConstString basename) override; - private: DISALLOW_COPY_AND_ASSIGN(PlatformLinux); }; diff --git a/source/Plugins/Platform/MacOSX/CMakeLists.txt b/source/Plugins/Platform/MacOSX/CMakeLists.txt index 02566ab3db06..449db7cd0612 100644 --- a/source/Plugins/Platform/MacOSX/CMakeLists.txt +++ b/source/Plugins/Platform/MacOSX/CMakeLists.txt @@ -24,4 +24,19 @@ else() ${PLUGIN_PLATFORM_MACOSX_DARWIN_ONLY_SOURCES}) endif() -add_lldb_library(lldbPluginPlatformMacOSX ${PLUGIN_PLATFORM_MACOSX_SOURCES}) +add_lldb_library(lldbPluginPlatformMacOSX PLUGIN + ${PLUGIN_PLATFORM_MACOSX_SOURCES} + + LINK_LIBS + clangBasic + lldbBreakpoint + lldbCore + lldbHost + lldbInterpreter + lldbSymbol + lldbTarget + lldbUtility + lldbPluginPlatformPOSIX + LINK_COMPONENTS + Support + ) diff --git a/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp b/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp index e6da63e8af6a..478d482eb024 100644 --- a/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp +++ b/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp @@ -19,11 +19,12 @@ #include <thread> // Other libraries and framework includes // Project includes -#include "lldb/Core/Error.h" -#include "lldb/Core/StreamString.h" +#include "lldb/Host/PseudoTerminal.h" #include "lldb/Target/Process.h" +#include "lldb/Utility/Error.h" #include "lldb/Utility/LLDBAssert.h" -#include "lldb/Utility/PseudoTerminal.h" +#include "lldb/Utility/StreamString.h" +#include "llvm/Support/Threading.h" using namespace lldb; using namespace lldb_private; @@ -242,8 +243,8 @@ FileSpec PlatformAppleSimulator::GetCoreSimulatorPath() { void PlatformAppleSimulator::LoadCoreSimulator() { #if defined(__APPLE__) - static std::once_flag g_load_core_sim_flag; - std::call_once(g_load_core_sim_flag, [this] { + static llvm::once_flag g_load_core_sim_flag; + llvm::call_once(g_load_core_sim_flag, [this] { const std::string core_sim_path(GetCoreSimulatorPath().GetPath()); if (core_sim_path.size()) dlopen(core_sim_path.c_str(), RTLD_LAZY); diff --git a/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h b/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h index 04bc28842c39..34f2ba2d9bfb 100644 --- a/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h +++ b/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h @@ -18,7 +18,7 @@ // Project includes #include "PlatformDarwin.h" #include "PlatformiOSSimulatorCoreSimulatorSupport.h" -#include "lldb/Host/FileSpec.h" +#include "lldb/Utility/FileSpec.h" #include "llvm/ADT/Optional.h" diff --git a/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp b/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp index 968ce5f9767b..38fe412c8574 100644 --- a/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp +++ b/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp @@ -15,18 +15,20 @@ // Project includes #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/StreamString.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" + +#include "llvm/Support/FileSystem.h" using namespace lldb; using namespace lldb_private; @@ -246,9 +248,9 @@ Error PlatformAppleTVSimulator::ResolveExecutable( } static FileSpec::EnumerateDirectoryResult -EnumerateDirectoryCallback(void *baton, FileSpec::FileType file_type, +EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { - if (file_type == FileSpec::eFileTypeDirectory) { + if (ft == llvm::sys::fs::file_type::directory_file) { const char *filename = file_spec.GetFilename().GetCString(); if (filename && strncmp(filename, "AppleTVSimulator", strlen("AppleTVSimulator")) == diff --git a/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp b/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp index 291f58607597..1ffdc1ab7c8e 100644 --- a/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp +++ b/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp @@ -15,18 +15,18 @@ // Project includes #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/StreamString.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" using namespace lldb; using namespace lldb_private; @@ -248,9 +248,9 @@ Error PlatformAppleWatchSimulator::ResolveExecutable( } static FileSpec::EnumerateDirectoryResult -EnumerateDirectoryCallback(void *baton, FileSpec::FileType file_type, +EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { - if (file_type == FileSpec::eFileTypeDirectory) { + if (ft == llvm::sys::fs::file_type::directory_file) { const char *filename = file_spec.GetFilename().GetCString(); if (filename && strncmp(filename, "AppleWatchSimulator", diff --git a/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 184912046706..7c90f87189a7 100644 --- a/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -22,15 +22,11 @@ #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Breakpoint/BreakpointSite.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/Timer.h" -#include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" -#include "lldb/Host/StringConvert.h" #include "lldb/Host/Symbols.h" #include "lldb/Host/XML.h" #include "lldb/Interpreter/CommandInterpreter.h" @@ -39,7 +35,12 @@ #include "lldb/Symbol/SymbolVendor.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBufferLLVM.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Threading.h" #if defined(__APPLE__) #include <TargetConditionals.h> // for TARGET_OS_TV, TARGET_OS_WATCH @@ -194,127 +195,20 @@ FileSpecList PlatformDarwin::LocateExecutableScriptingResources( return file_list; } -Error PlatformDarwin::ResolveExecutable( - const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp, - const FileSpecList *module_search_paths_ptr) { - Error error; - // Nothing special to do here, just use the actual file and architecture - - char exe_path[PATH_MAX]; - ModuleSpec resolved_module_spec(module_spec); - - if (IsHost()) { - // If we have "ls" as the exe_file, resolve the executable loation based on - // the current path variables - if (!resolved_module_spec.GetFileSpec().Exists()) { - module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path)); - resolved_module_spec.GetFileSpec().SetFile(exe_path, true); - } - - if (!resolved_module_spec.GetFileSpec().Exists()) - resolved_module_spec.GetFileSpec().ResolveExecutableLocation(); - - // Resolve any executable within a bundle on MacOSX - Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec()); - - if (resolved_module_spec.GetFileSpec().Exists()) - error.Clear(); - else { - const uint32_t permissions = - resolved_module_spec.GetFileSpec().GetPermissions(); - if (permissions && (permissions & eFilePermissionsEveryoneR) == 0) - error.SetErrorStringWithFormat( - "executable '%s' is not readable", - resolved_module_spec.GetFileSpec().GetPath().c_str()); - else - error.SetErrorStringWithFormat( - "unable to find executable for '%s'", - resolved_module_spec.GetFileSpec().GetPath().c_str()); - } - } else { - if (m_remote_platform_sp) { - error = - GetCachedExecutable(resolved_module_spec, exe_module_sp, - module_search_paths_ptr, *m_remote_platform_sp); - } else { - // We may connect to a process and use the provided executable (Don't use - // local $PATH). - - // Resolve any executable within a bundle on MacOSX - Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec()); - - if (resolved_module_spec.GetFileSpec().Exists()) - error.Clear(); - else - error.SetErrorStringWithFormat( - "the platform is not currently connected, and '%s' doesn't exist " - "in the system root.", - resolved_module_spec.GetFileSpec().GetFilename().AsCString("")); - } - } - - if (error.Success()) { - if (resolved_module_spec.GetArchitecture().IsValid()) { - error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, - module_search_paths_ptr, NULL, NULL); - - if (error.Fail() || exe_module_sp.get() == NULL || - exe_module_sp->GetObjectFile() == NULL) { - exe_module_sp.reset(); - error.SetErrorStringWithFormat( - "'%s' doesn't contain the architecture %s", - resolved_module_spec.GetFileSpec().GetPath().c_str(), - resolved_module_spec.GetArchitecture().GetArchitectureName()); - } - } else { - // No valid architecture was specified, ask the platform for - // the architectures that we should be using (in the correct order) - // and see if we can find a match that way - StreamString arch_names; - for (uint32_t idx = 0; GetSupportedArchitectureAtIndex( - idx, resolved_module_spec.GetArchitecture()); - ++idx) { - error = GetSharedModule(resolved_module_spec, NULL, exe_module_sp, - module_search_paths_ptr, NULL, NULL); - // Did we find an executable using one of the - if (error.Success()) { - if (exe_module_sp && exe_module_sp->GetObjectFile()) - break; - else - error.SetErrorToGenericError(); - } - - if (idx > 0) - arch_names.PutCString(", "); - arch_names.PutCString( - resolved_module_spec.GetArchitecture().GetArchitectureName()); - } - - if (error.Fail() || !exe_module_sp) { - if (resolved_module_spec.GetFileSpec().Readable()) { - error.SetErrorStringWithFormat( - "'%s' doesn't contain any '%s' platform architectures: %s", - resolved_module_spec.GetFileSpec().GetPath().c_str(), - GetPluginName().GetCString(), arch_names.GetData()); - } else { - error.SetErrorStringWithFormat( - "'%s' is not readable", - resolved_module_spec.GetFileSpec().GetPath().c_str()); - } - } - } - } - - return error; -} - Error PlatformDarwin::ResolveSymbolFile(Target &target, const ModuleSpec &sym_spec, FileSpec &sym_file) { Error error; sym_file = sym_spec.GetSymbolFileSpec(); - if (sym_file.Exists()) { - if (sym_file.GetFileType() == FileSpec::eFileTypeDirectory) { + + llvm::sys::fs::file_status st; + if (status(sym_file.GetPath(), st, false)) { + error.SetErrorString("Could not stat file!"); + return error; + } + + if (exists(st)) { + if (is_directory(st)) { sym_file = Symbols::FindSymbolFileInBundle( sym_file, sym_spec.GetUUIDPtr(), sym_spec.GetArchitecturePtr()); } @@ -329,8 +223,7 @@ static lldb_private::Error MakeCacheFolderForFile(const FileSpec &module_cache_spec) { FileSpec module_cache_folder = module_cache_spec.CopyByRemovingLastPathComponent(); - return FileSystem::MakeDirectory(module_cache_folder, - eFilePermissionsDirectoryDefault); + return llvm::sys::fs::create_directory(module_cache_folder.GetPath()); } static lldb_private::Error @@ -402,11 +295,14 @@ lldb_private::Error PlatformDarwin::GetSharedModuleWithLocalCache( // get the local and remote MD5 and compare if (m_remote_platform_sp) { // when going over the *slow* GDB remote transfer mechanism we first - // check - // the hashes of the files - and only do the actual transfer if they - // differ + // check the hashes of the files - and only do the actual transfer if + // they differ uint64_t high_local, high_remote, low_local, low_remote; - FileSystem::CalculateMD5(module_cache_spec, low_local, high_local); + auto MD5 = llvm::sys::fs::md5_contents(module_cache_spec.GetPath()); + if (!MD5) + return Error(MD5.getError()); + std::tie(high_local, low_local) = MD5->words(); + m_remote_platform_sp->CalculateMD5(module_spec.GetFileSpec(), low_remote, high_remote); if (low_local != low_remote || high_local != high_remote) { @@ -603,34 +499,6 @@ PlatformDarwin::GetSoftwareBreakpointTrapOpcode(Target &target, return 0; } -bool PlatformDarwin::GetProcessInfo(lldb::pid_t pid, - ProcessInstanceInfo &process_info) { - bool success = false; - if (IsHost()) { - success = Platform::GetProcessInfo(pid, process_info); - } else { - if (m_remote_platform_sp) - success = m_remote_platform_sp->GetProcessInfo(pid, process_info); - } - return success; -} - -uint32_t -PlatformDarwin::FindProcesses(const ProcessInstanceInfoMatch &match_info, - ProcessInstanceInfoList &process_infos) { - uint32_t match_count = 0; - if (IsHost()) { - // Let the base class figure out the host details - match_count = Platform::FindProcesses(match_info, process_infos); - } else { - // If we are remote, we can only return results if we are connected - if (m_remote_platform_sp) - match_count = - m_remote_platform_sp->FindProcesses(match_info, process_infos); - } - return match_count; -} - bool PlatformDarwin::ModuleIsExcludedForUnconstrainedSearches( lldb_private::Target &target, const lldb::ModuleSP &module_sp) { if (!module_sp) @@ -1295,13 +1163,16 @@ const char *PlatformDarwin::GetDeveloperDirectory() { xcode_dir_path.append(xcode_select_prefix_dir); xcode_dir_path.append("/usr/share/xcode-select/xcode_dir_path"); temp_file_spec.SetFile(xcode_dir_path, false); - size_t bytes_read = temp_file_spec.ReadFileContents( - 0, developer_dir_path, sizeof(developer_dir_path), NULL); - if (bytes_read > 0) { - developer_dir_path[bytes_read] = '\0'; - while (developer_dir_path[bytes_read - 1] == '\r' || - developer_dir_path[bytes_read - 1] == '\n') - developer_dir_path[--bytes_read] = '\0'; + auto dir_buffer = + DataBufferLLVM::CreateFromPath(temp_file_spec.GetPath(), true); + if (dir_buffer && dir_buffer->GetByteSize() > 0) { + llvm::StringRef path_ref(dir_buffer->GetChars()); + // Trim tailing newlines and make sure there is enough room for a null + // terminator. + path_ref = + path_ref.rtrim("\r\n").take_front(sizeof(developer_dir_path) - 1); + ::memcpy(developer_dir_path, path_ref.data(), path_ref.size()); + developer_dir_path[path_ref.size()] = '\0'; developer_dir_path_valid = true; } } @@ -1331,7 +1202,7 @@ const char *PlatformDarwin::GetDeveloperDirectory() { developer_dir_path[i] = '\0'; FileSpec devel_dir(developer_dir_path, false); - if (devel_dir.Exists() && devel_dir.IsDirectory()) { + if (llvm::sys::fs::is_directory(devel_dir.GetPath())) { developer_dir_path_valid = true; } } @@ -1452,8 +1323,8 @@ static FileSpec CheckPathForXcode(const FileSpec &fspec) { static FileSpec GetXcodeContentsPath() { static FileSpec g_xcode_filespec; - static std::once_flag g_once_flag; - std::call_once(g_once_flag, []() { + static llvm::once_flag g_once_flag; + llvm::call_once(g_once_flag, []() { FileSpec fspec; @@ -1576,9 +1447,8 @@ bool PlatformDarwin::SDKSupportsModules(SDKType desired_type, return false; } -FileSpec::EnumerateDirectoryResult -PlatformDarwin::DirectoryEnumerator(void *baton, FileSpec::FileType file_type, - const FileSpec &spec) { +FileSpec::EnumerateDirectoryResult PlatformDarwin::DirectoryEnumerator( + void *baton, llvm::sys::fs::file_type file_type, const FileSpec &spec) { SDKEnumeratorInfo *enumerator_info = static_cast<SDKEnumeratorInfo *>(baton); if (SDKSupportsModules(enumerator_info->sdk_type, spec)) { @@ -1593,8 +1463,9 @@ FileSpec PlatformDarwin::FindSDKInXcodeForModules(SDKType sdk_type, const FileSpec &sdks_spec) { // Look inside Xcode for the required installed iOS SDK version - if (!sdks_spec.IsDirectory()) + if (!llvm::sys::fs::is_directory(sdks_spec.GetPath())) { return FileSpec(); + } const bool find_directories = true; const bool find_files = false; @@ -1608,7 +1479,7 @@ FileSpec PlatformDarwin::FindSDKInXcodeForModules(SDKType sdk_type, find_files, find_other, DirectoryEnumerator, &enumerator_info); - if (enumerator_info.found_path.IsDirectory()) + if (llvm::sys::fs::is_directory(enumerator_info.found_path.GetPath())) return enumerator_info.found_path; else return FileSpec(); @@ -1767,7 +1638,7 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( sysroot_spec = GetSDKDirectoryForModules(sdk_type); } - if (sysroot_spec.IsDirectory()) { + if (llvm::sys::fs::is_directory(sysroot_spec.GetPath())) { options.push_back("-isysroot"); options.push_back(sysroot_spec.GetPath()); } @@ -1835,8 +1706,8 @@ lldb_private::FileSpec PlatformDarwin::LocateExecutable(const char *basename) { // Find the global list of directories that we will search for // executables once so we don't keep doing the work over and over. - static std::once_flag g_once_flag; - std::call_once(g_once_flag, []() { + static llvm::once_flag g_once_flag; + llvm::call_once(g_once_flag, []() { // When locating executables, trust the DEVELOPER_DIR first if it is set FileSpec xcode_contents_dir = GetXcodeContentsPath(); diff --git a/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/source/Plugins/Platform/MacOSX/PlatformDarwin.h index 2abff92fa906..9430c269c27e 100644 --- a/source/Plugins/Platform/MacOSX/PlatformDarwin.h +++ b/source/Plugins/Platform/MacOSX/PlatformDarwin.h @@ -16,8 +16,9 @@ // Other libraries and framework includes // Project includes #include "Plugins/Platform/POSIX/PlatformPOSIX.h" -#include "lldb/Host/FileSpec.h" +#include "lldb/Utility/FileSpec.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/FileSystem.h" #include <string> #include <tuple> @@ -31,10 +32,6 @@ public: //------------------------------------------------------------ // lldb_private::Platform functions //------------------------------------------------------------ - lldb_private::Error ResolveExecutable( - const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp, - const lldb_private::FileSpecList *module_search_paths_ptr) override; - lldb_private::Error ResolveSymbolFile(lldb_private::Target &target, const lldb_private::ModuleSpec &sym_spec, @@ -55,16 +52,9 @@ public: lldb_private::Target &target, lldb_private::BreakpointSite *bp_site) override; - bool GetProcessInfo(lldb::pid_t pid, - lldb_private::ProcessInstanceInfo &proc_info) override; - lldb::BreakpointSP SetThreadCreationBreakpoint(lldb_private::Target &target) override; - uint32_t - FindProcesses(const lldb_private::ProcessInstanceInfoMatch &match_info, - lldb_private::ProcessInstanceInfoList &process_infos) override; - bool ModuleIsExcludedForUnconstrainedSearches( lldb_private::Target &target, const lldb::ModuleSP &module_sp) override; @@ -123,7 +113,7 @@ protected: }; static lldb_private::FileSpec::EnumerateDirectoryResult - DirectoryEnumerator(void *baton, lldb_private::FileSpec::FileType file_type, + DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type, const lldb_private::FileSpec &spec); static lldb_private::FileSpec diff --git a/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp b/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp index f4fd9c694000..7116dca65911 100644 --- a/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp +++ b/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp @@ -19,14 +19,10 @@ // Project includes #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/StreamString.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/Host.h" #include "lldb/Interpreter/OptionValueFileSpecList.h" #include "lldb/Interpreter/OptionValueProperties.h" @@ -35,6 +31,12 @@ #include "lldb/Target/Platform.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" + +#include "llvm/Support/FileSystem.h" #include <CoreFoundation/CoreFoundation.h> @@ -381,7 +383,7 @@ void PlatformDarwinKernel::CollectKextAndKernelDirectories() { // Add simple directory /Applications/Xcode.app/Contents/Developer/../Symbols FileSpec possible_dir(developer_dir + "/../Symbols", true); - if (possible_dir.Exists() && possible_dir.IsDirectory()) + if (llvm::sys::fs::is_directory(possible_dir.GetPath())) m_search_directories.push_back(possible_dir); // Add simple directory of the current working directory @@ -396,7 +398,7 @@ void PlatformDarwinKernel::GetUserSpecifiedDirectoriesToSearch() { for (uint32_t i = 0; i < user_dirs_count; i++) { FileSpec dir = user_dirs.GetFileSpecAtIndex(i); dir.ResolvePath(); - if (dir.Exists() && dir.IsDirectory()) { + if (llvm::sys::fs::is_directory(dir.GetPath())) { m_search_directories.push_back(dir); } } @@ -412,7 +414,7 @@ void PlatformDarwinKernel::AddRootSubdirsToSearchPaths( nullptr}; for (int i = 0; subdirs[i] != nullptr; i++) { FileSpec testdir(dir + subdirs[i], true); - if (testdir.Exists() && testdir.IsDirectory()) + if (llvm::sys::fs::is_directory(testdir.GetPath())) thisp->m_search_directories.push_back(testdir); } @@ -435,12 +437,12 @@ void PlatformDarwinKernel::AddSDKSubdirsToSearchPaths(const std::string &dir) { // Helper function to find *.sdk and *.kdk directories in a given directory. FileSpec::EnumerateDirectoryResult PlatformDarwinKernel::FindKDKandSDKDirectoriesInDirectory( - void *baton, FileSpec::FileType file_type, const FileSpec &file_spec) { + void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { static ConstString g_sdk_suffix = ConstString("sdk"); static ConstString g_kdk_suffix = ConstString("kdk"); PlatformDarwinKernel *thisp = (PlatformDarwinKernel *)baton; - if (file_type == FileSpec::eFileTypeDirectory && + if (ft == llvm::sys::fs::file_type::directory_file && (file_spec.GetFileNameExtension() == g_sdk_suffix || file_spec.GetFileNameExtension() == g_kdk_suffix)) { AddRootSubdirsToSearchPaths(thisp, file_spec.GetPath()); @@ -486,20 +488,19 @@ void PlatformDarwinKernel::SearchForKextsAndKernelsRecursively() { FileSpec::EnumerateDirectoryResult PlatformDarwinKernel::GetKernelsAndKextsInDirectoryWithRecursion( - void *baton, FileSpec::FileType file_type, const FileSpec &file_spec) { - return GetKernelsAndKextsInDirectoryHelper(baton, file_type, file_spec, true); + void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { + return GetKernelsAndKextsInDirectoryHelper(baton, ft, file_spec, true); } FileSpec::EnumerateDirectoryResult PlatformDarwinKernel::GetKernelsAndKextsInDirectoryNoRecursion( - void *baton, FileSpec::FileType file_type, const FileSpec &file_spec) { - return GetKernelsAndKextsInDirectoryHelper(baton, file_type, file_spec, - false); + void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { + return GetKernelsAndKextsInDirectoryHelper(baton, ft, file_spec, false); } FileSpec::EnumerateDirectoryResult PlatformDarwinKernel::GetKernelsAndKextsInDirectoryHelper( - void *baton, FileSpec::FileType file_type, const FileSpec &file_spec, + void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec, bool recurse) { static ConstString g_kext_suffix = ConstString("kext"); static ConstString g_dsym_suffix = ConstString("dSYM"); @@ -512,8 +513,8 @@ PlatformDarwinKernel::GetKernelsAndKextsInDirectoryHelper( file_spec.GetPath().c_str()); PlatformDarwinKernel *thisp = (PlatformDarwinKernel *)baton; - if (file_type == FileSpec::eFileTypeRegular || - file_type == FileSpec::eFileTypeSymbolicLink) { + if (ft == llvm::sys::fs::file_type::regular_file || + ft == llvm::sys::fs::file_type::symlink_file) { ConstString filename = file_spec.GetFilename(); if ((strncmp(filename.GetCString(), "kernel", 6) == 0 || strncmp(filename.GetCString(), "mach", 4) == 0) && @@ -524,17 +525,17 @@ PlatformDarwinKernel::GetKernelsAndKextsInDirectoryHelper( thisp->m_kernel_binaries_without_dsyms.push_back(file_spec); return FileSpec::eEnumerateDirectoryResultNext; } - } else if (file_type == FileSpec::eFileTypeDirectory && + } else if (ft == llvm::sys::fs::file_type::directory_file && file_spec_extension == g_kext_suffix) { AddKextToMap(thisp, file_spec); // Look to see if there is a PlugIns subdir with more kexts FileSpec contents_plugins(file_spec.GetPath() + "/Contents/PlugIns", false); std::string search_here_too; - if (contents_plugins.Exists() && contents_plugins.IsDirectory()) { + if (llvm::sys::fs::is_directory(contents_plugins.GetPath())) { search_here_too = contents_plugins.GetPath(); } else { FileSpec plugins(file_spec.GetPath() + "/PlugIns", false); - if (plugins.Exists() && plugins.IsDirectory()) { + if (llvm::sys::fs::is_directory(plugins.GetPath())) { search_here_too = plugins.GetPath(); } } @@ -591,7 +592,7 @@ bool PlatformDarwinKernel::KextHasdSYMSibling( std::string filename = dsym_fspec.GetFilename().AsCString(); filename += ".dSYM"; dsym_fspec.GetFilename() = ConstString(filename); - if (dsym_fspec.Exists() && dsym_fspec.IsDirectory()) { + if (llvm::sys::fs::is_directory(dsym_fspec.GetPath())) { return true; } // Should probably get the CFBundleExecutable here or call @@ -605,7 +606,7 @@ bool PlatformDarwinKernel::KextHasdSYMSibling( deep_bundle_str += executable_name.AsCString(); deep_bundle_str += ".dSYM"; dsym_fspec.SetFile(deep_bundle_str, true); - if (dsym_fspec.Exists() && dsym_fspec.IsDirectory()) { + if (llvm::sys::fs::is_directory(dsym_fspec.GetPath())) { return true; } @@ -615,7 +616,7 @@ bool PlatformDarwinKernel::KextHasdSYMSibling( shallow_bundle_str += executable_name.AsCString(); shallow_bundle_str += ".dSYM"; dsym_fspec.SetFile(shallow_bundle_str, true); - if (dsym_fspec.Exists() && dsym_fspec.IsDirectory()) { + if (llvm::sys::fs::is_directory(dsym_fspec.GetPath())) { return true; } return false; @@ -629,7 +630,7 @@ bool PlatformDarwinKernel::KernelHasdSYMSibling(const FileSpec &kernel_binary) { std::string filename = kernel_binary.GetFilename().AsCString(); filename += ".dSYM"; kernel_dsym.GetFilename() = ConstString(filename); - if (kernel_dsym.Exists() && kernel_dsym.IsDirectory()) { + if (llvm::sys::fs::is_directory(kernel_dsym.GetPath())) { return true; } return false; diff --git a/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h b/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h index 2010c4860309..6ee5916e613a 100644 --- a/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h +++ b/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h @@ -10,7 +10,7 @@ #ifndef liblldb_PlatformDarwinKernel_h_ #define liblldb_PlatformDarwinKernel_h_ -#include "lldb/Core/ConstString.h" +#include "lldb/Utility/ConstString.h" #if defined(__APPLE__) // This Plugin uses the Mac-specific // source/Host/macosx/cfcpp utilities @@ -18,7 +18,9 @@ // C Includes // C++ Includes // Other libraries and framework includes -#include "lldb/Host/FileSpec.h" +#include "lldb/Utility/FileSpec.h" + +#include "llvm/Support/FileSystem.h" // Project includes #include "PlatformDarwin.h" @@ -105,26 +107,25 @@ protected: void AddSDKSubdirsToSearchPaths(const std::string &dir); static lldb_private::FileSpec::EnumerateDirectoryResult - FindKDKandSDKDirectoriesInDirectory( - void *baton, lldb_private::FileSpec::FileType file_type, - const lldb_private::FileSpec &file_spec); + FindKDKandSDKDirectoriesInDirectory(void *baton, llvm::sys::fs::file_type ft, + const lldb_private::FileSpec &file_spec); void SearchForKextsAndKernelsRecursively(); static lldb_private::FileSpec::EnumerateDirectoryResult GetKernelsAndKextsInDirectoryWithRecursion( - void *baton, lldb_private::FileSpec::FileType file_type, + void *baton, llvm::sys::fs::file_type ft, const lldb_private::FileSpec &file_spec); static lldb_private::FileSpec::EnumerateDirectoryResult GetKernelsAndKextsInDirectoryNoRecursion( - void *baton, lldb_private::FileSpec::FileType file_type, + void *baton, llvm::sys::fs::file_type ft, const lldb_private::FileSpec &file_spec); static lldb_private::FileSpec::EnumerateDirectoryResult - GetKernelsAndKextsInDirectoryHelper( - void *baton, lldb_private::FileSpec::FileType file_type, - const lldb_private::FileSpec &file_spec, bool recurse); + GetKernelsAndKextsInDirectoryHelper(void *baton, llvm::sys::fs::file_type ft, + const lldb_private::FileSpec &file_spec, + bool recurse); static void AddKextToMap(PlatformDarwinKernel *thisp, const lldb_private::FileSpec &file_spec); diff --git a/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp b/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp index 0e7df95b5337..11d0457a783e 100644 --- a/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp +++ b/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp @@ -17,21 +17,20 @@ // Other libraries and framework includes // Project includes #include "lldb/Breakpoint/BreakpointLocation.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/StreamString.h" -#include "lldb/Host/FileSpec.h" -#include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" using namespace lldb; using namespace lldb_private; @@ -279,8 +278,7 @@ PlatformMacOSX::GetFileWithUUID(const lldb_private::FileSpec &platform_file, FileSpec module_cache_folder = module_cache_spec.CopyByRemovingLastPathComponent(); // try to make the local directory first - Error err = FileSystem::MakeDirectory(module_cache_folder, - eFilePermissionsDirectoryDefault); + Error err(llvm::sys::fs::create_directory(module_cache_folder.GetPath())); if (err.Fail()) return err; err = GetFile(platform_file, module_cache_spec); diff --git a/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp b/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp index 47b1c8f07dfa..05d1bd49dafe 100644 --- a/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp +++ b/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp @@ -18,17 +18,17 @@ #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/StreamString.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/Host.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" using namespace lldb; using namespace lldb_private; @@ -250,7 +250,7 @@ Error PlatformRemoteAppleTV::ResolveExecutable( FileSpec::EnumerateDirectoryResult PlatformRemoteAppleTV::GetContainedFilesIntoVectorOfStringsCallback( - void *baton, FileSpec::FileType file_type, const FileSpec &file_spec) { + void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { ((PlatformRemoteAppleTV::SDKDirectoryInfoCollection *)baton) ->push_back(PlatformRemoteAppleTV::SDKDirectoryInfo(file_spec)); return FileSpec::eEnumerateDirectoryResultNext; @@ -497,18 +497,15 @@ const char *PlatformRemoteAppleTV::GetDeviceSupportDirectoryForOSVersion() { uint32_t PlatformRemoteAppleTV::FindFileInAllSDKs(const char *platform_file_path, FileSpecList &file_list) { - Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST | - LIBLLDB_LOG_VERBOSE); + Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); if (platform_file_path && platform_file_path[0] && UpdateSDKDirectoryInfosIfNeeded()) { const uint32_t num_sdk_infos = m_sdk_directory_infos.size(); lldb_private::FileSpec local_file; // First try for an exact match of major, minor and update for (uint32_t sdk_idx = 0; sdk_idx < num_sdk_infos; ++sdk_idx) { - if (log) { - log->Printf("Searching for %s in sdk path %s", platform_file_path, - m_sdk_directory_infos[sdk_idx].directory.GetPath().c_str()); - } + LLDB_LOGV(log, "Searching for {0} in sdk path {1}", platform_file_path, + m_sdk_directory_infos[sdk_idx].directory); if (GetFileInSDK(platform_file_path, sdk_idx, local_file)) { file_list.Append(local_file); } @@ -619,8 +616,7 @@ Error PlatformRemoteAppleTV::GetSharedModule( // then we attempt to get a shared module for the right architecture // with the right UUID. const FileSpec &platform_file = module_spec.GetFileSpec(); - Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST | - LIBLLDB_LOG_VERBOSE); + Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); Error error; char platform_file_path[PATH_MAX]; @@ -637,12 +633,8 @@ Error PlatformRemoteAppleTV::GetSharedModule( // using the OS build. const uint32_t connected_sdk_idx = GetConnectedSDKIndex(); if (connected_sdk_idx < num_sdk_infos) { - if (log) { - log->Printf("Searching for %s in sdk path %s", platform_file_path, - m_sdk_directory_infos[connected_sdk_idx] - .directory.GetPath() - .c_str()); - } + LLDB_LOGV(log, "Searching for {0} in sdk path {1}", platform_file, + m_sdk_directory_infos[connected_sdk_idx].directory); if (GetFileInSDK(platform_file_path, connected_sdk_idx, platform_module_spec.GetFileSpec())) { module_sp.reset(); @@ -658,12 +650,8 @@ Error PlatformRemoteAppleTV::GetSharedModule( // Try the last SDK index if it is set as most files from an SDK // will tend to be valid in that same SDK. if (m_last_module_sdk_idx < num_sdk_infos) { - if (log) { - log->Printf("Searching for %s in sdk path %s", platform_file_path, - m_sdk_directory_infos[m_last_module_sdk_idx] - .directory.GetPath() - .c_str()); - } + LLDB_LOGV(log, "Searching for {0} in sdk path {1}", platform_file_path, + m_sdk_directory_infos[m_last_module_sdk_idx].directory); if (GetFileInSDK(platform_file_path, m_last_module_sdk_idx, platform_module_spec.GetFileSpec())) { module_sp.reset(); @@ -682,10 +670,8 @@ Error PlatformRemoteAppleTV::GetSharedModule( // it above continue; } - if (log) { - log->Printf("Searching for %s in sdk path %s", platform_file_path, - m_sdk_directory_infos[sdk_idx].directory.GetPath().c_str()); - } + LLDB_LOGV(log, "Searching for {0} in sdk path {1}", platform_file_path, + m_sdk_directory_infos[sdk_idx].directory); if (GetFileInSDK(platform_file_path, sdk_idx, platform_module_spec.GetFileSpec())) { // printf ("sdk[%u]: '%s'\n", sdk_idx, local_file.GetPath().c_str()); diff --git a/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h b/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h index 388ea578d06b..beae827edba4 100644 --- a/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h +++ b/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h @@ -16,7 +16,9 @@ // Other libraries and framework includes // Project includes -#include "lldb/Host/FileSpec.h" +#include "lldb/Utility/FileSpec.h" + +#include "llvm/Support/FileSystem.h" #include "PlatformDarwin.h" @@ -116,7 +118,7 @@ protected: static lldb_private::FileSpec::EnumerateDirectoryResult GetContainedFilesIntoVectorOfStringsCallback( - void *baton, lldb_private::FileSpec::FileType file_type, + void *baton, llvm::sys::fs::file_type ft, const lldb_private::FileSpec &file_spec); uint32_t FindFileInAllSDKs(const char *platform_file_path, diff --git a/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp b/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp index f12fcab3b713..139364a82b98 100644 --- a/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp +++ b/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp @@ -18,17 +18,17 @@ #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/StreamString.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/Host.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" using namespace lldb; using namespace lldb_private; @@ -260,7 +260,7 @@ Error PlatformRemoteAppleWatch::ResolveExecutable( FileSpec::EnumerateDirectoryResult PlatformRemoteAppleWatch::GetContainedFilesIntoVectorOfStringsCallback( - void *baton, FileSpec::FileType file_type, const FileSpec &file_spec) { + void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { ((PlatformRemoteAppleWatch::SDKDirectoryInfoCollection *)baton) ->push_back(PlatformRemoteAppleWatch::SDKDirectoryInfo(file_spec)); return FileSpec::eEnumerateDirectoryResultNext; @@ -511,18 +511,15 @@ const char *PlatformRemoteAppleWatch::GetDeviceSupportDirectoryForOSVersion() { uint32_t PlatformRemoteAppleWatch::FindFileInAllSDKs(const char *platform_file_path, FileSpecList &file_list) { - Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST | - LIBLLDB_LOG_VERBOSE); + Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); if (platform_file_path && platform_file_path[0] && UpdateSDKDirectoryInfosIfNeeded()) { const uint32_t num_sdk_infos = m_sdk_directory_infos.size(); lldb_private::FileSpec local_file; // First try for an exact match of major, minor and update for (uint32_t sdk_idx = 0; sdk_idx < num_sdk_infos; ++sdk_idx) { - if (log) { - log->Printf("Searching for %s in sdk path %s", platform_file_path, - m_sdk_directory_infos[sdk_idx].directory.GetPath().c_str()); - } + LLDB_LOGV(log, "Searching for {0} in sdk path {1}", platform_file_path, + m_sdk_directory_infos[sdk_idx].directory); if (GetFileInSDK(platform_file_path, sdk_idx, local_file)) { file_list.Append(local_file); } @@ -633,8 +630,7 @@ Error PlatformRemoteAppleWatch::GetSharedModule( // then we attempt to get a shared module for the right architecture // with the right UUID. const FileSpec &platform_file = module_spec.GetFileSpec(); - Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST | - LIBLLDB_LOG_VERBOSE); + Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); Error error; char platform_file_path[PATH_MAX]; @@ -651,12 +647,8 @@ Error PlatformRemoteAppleWatch::GetSharedModule( // using the OS build. const uint32_t connected_sdk_idx = GetConnectedSDKIndex(); if (connected_sdk_idx < num_sdk_infos) { - if (log) { - log->Printf("Searching for %s in sdk path %s", platform_file_path, - m_sdk_directory_infos[connected_sdk_idx] - .directory.GetPath() - .c_str()); - } + LLDB_LOGV(log, "Searching for {0} in sdk path {1}", platform_file, + m_sdk_directory_infos[connected_sdk_idx].directory); if (GetFileInSDK(platform_file_path, connected_sdk_idx, platform_module_spec.GetFileSpec())) { module_sp.reset(); @@ -672,12 +664,8 @@ Error PlatformRemoteAppleWatch::GetSharedModule( // Try the last SDK index if it is set as most files from an SDK // will tend to be valid in that same SDK. if (m_last_module_sdk_idx < num_sdk_infos) { - if (log) { - log->Printf("Searching for %s in sdk path %s", platform_file_path, - m_sdk_directory_infos[m_last_module_sdk_idx] - .directory.GetPath() - .c_str()); - } + LLDB_LOGV(log, "Searching for {0} in sdk path {1}", platform_file, + m_sdk_directory_infos[m_last_module_sdk_idx].directory); if (GetFileInSDK(platform_file_path, m_last_module_sdk_idx, platform_module_spec.GetFileSpec())) { module_sp.reset(); @@ -696,10 +684,8 @@ Error PlatformRemoteAppleWatch::GetSharedModule( // it above continue; } - if (log) { - log->Printf("Searching for %s in sdk path %s", platform_file_path, - m_sdk_directory_infos[sdk_idx].directory.GetPath().c_str()); - } + LLDB_LOGV(log, "Searching for {0} in sdk path {1}", platform_file, + m_sdk_directory_infos[sdk_idx].directory); if (GetFileInSDK(platform_file_path, sdk_idx, platform_module_spec.GetFileSpec())) { // printf ("sdk[%u]: '%s'\n", sdk_idx, local_file.GetPath().c_str()); diff --git a/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h b/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h index 0b388af329a5..d6c91140171b 100644 --- a/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h +++ b/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h @@ -17,10 +17,12 @@ // Other libraries and framework includes // Project includes -#include "lldb/Host/FileSpec.h" +#include "lldb/Utility/FileSpec.h" #include "PlatformDarwin.h" +#include "llvm/Support/FileSystem.h" + class PlatformRemoteAppleWatch : public PlatformDarwin { public: PlatformRemoteAppleWatch(); @@ -118,7 +120,7 @@ protected: static lldb_private::FileSpec::EnumerateDirectoryResult GetContainedFilesIntoVectorOfStringsCallback( - void *baton, lldb_private::FileSpec::FileType file_type, + void *baton, llvm::sys::fs::file_type ft, const lldb_private::FileSpec &file_spec); uint32_t FindFileInAllSDKs(const char *platform_file_path, diff --git a/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp b/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp index cf4f88d90107..9d47b2464a27 100644 --- a/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp +++ b/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp @@ -15,17 +15,17 @@ // Project includes #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/StreamString.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/Host.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" using namespace lldb; using namespace lldb_private; @@ -255,7 +255,7 @@ Error PlatformRemoteiOS::ResolveExecutable( FileSpec::EnumerateDirectoryResult PlatformRemoteiOS::GetContainedFilesIntoVectorOfStringsCallback( - void *baton, FileSpec::FileType file_type, const FileSpec &file_spec) { + void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { ((PlatformRemoteiOS::SDKDirectoryInfoCollection *)baton) ->push_back(PlatformRemoteiOS::SDKDirectoryInfo(file_spec)); return FileSpec::eEnumerateDirectoryResultNext; @@ -481,18 +481,15 @@ const char *PlatformRemoteiOS::GetDeviceSupportDirectoryForOSVersion() { uint32_t PlatformRemoteiOS::FindFileInAllSDKs(const char *platform_file_path, FileSpecList &file_list) { - Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST | - LIBLLDB_LOG_VERBOSE); + Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); if (platform_file_path && platform_file_path[0] && UpdateSDKDirectoryInfosIfNeeded()) { const uint32_t num_sdk_infos = m_sdk_directory_infos.size(); lldb_private::FileSpec local_file; // First try for an exact match of major, minor and update for (uint32_t sdk_idx = 0; sdk_idx < num_sdk_infos; ++sdk_idx) { - if (log) { - log->Printf("Searching for %s in sdk path %s", platform_file_path, - m_sdk_directory_infos[sdk_idx].directory.GetPath().c_str()); - } + LLDB_LOGV(log, "Searching for {0} in sdk path {1}", platform_file_path, + m_sdk_directory_infos[sdk_idx].directory); if (GetFileInSDK(platform_file_path, sdk_idx, local_file)) { file_list.Append(local_file); } @@ -605,8 +602,7 @@ Error PlatformRemoteiOS::GetSharedModule( // then we attempt to get a shared module for the right architecture // with the right UUID. const FileSpec &platform_file = module_spec.GetFileSpec(); - Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST | - LIBLLDB_LOG_VERBOSE); + Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); Error error; char platform_file_path[PATH_MAX]; @@ -623,12 +619,8 @@ Error PlatformRemoteiOS::GetSharedModule( // using the OS build. const uint32_t connected_sdk_idx = GetConnectedSDKIndex(); if (connected_sdk_idx < num_sdk_infos) { - if (log) { - log->Printf("Searching for %s in sdk path %s", platform_file_path, - m_sdk_directory_infos[connected_sdk_idx] - .directory.GetPath() - .c_str()); - } + LLDB_LOGV(log, "Searching for {0} in sdk path {1}", platform_file, + m_sdk_directory_infos[connected_sdk_idx].directory); if (GetFileInSDK(platform_file_path, connected_sdk_idx, platform_module_spec.GetFileSpec())) { module_sp.reset(); @@ -644,12 +636,8 @@ Error PlatformRemoteiOS::GetSharedModule( // Try the last SDK index if it is set as most files from an SDK // will tend to be valid in that same SDK. if (m_last_module_sdk_idx < num_sdk_infos) { - if (log) { - log->Printf("Searching for %s in sdk path %s", platform_file_path, - m_sdk_directory_infos[m_last_module_sdk_idx] - .directory.GetPath() - .c_str()); - } + LLDB_LOGV(log, "Searching for {0} in sdk path {1}", platform_file, + m_sdk_directory_infos[m_last_module_sdk_idx].directory); if (GetFileInSDK(platform_file_path, m_last_module_sdk_idx, platform_module_spec.GetFileSpec())) { module_sp.reset(); @@ -670,11 +658,8 @@ Error PlatformRemoteiOS::GetSharedModule( GetSDKIndexBySDKDirectoryInfo(current_sdk_info); if (current_sdk_idx < num_sdk_infos && current_sdk_idx != m_last_module_sdk_idx) { - if (log) { - log->Printf( - "Searching for %s in sdk path %s", platform_file_path, - m_sdk_directory_infos[current_sdk_idx].directory.GetPath().c_str()); - } + LLDB_LOGV(log, "Searching for {0} in sdk path {1}", platform_file, + m_sdk_directory_infos[current_sdk_idx].directory); if (GetFileInSDK(platform_file_path, current_sdk_idx, platform_module_spec.GetFileSpec())) { module_sp.reset(); @@ -694,10 +679,8 @@ Error PlatformRemoteiOS::GetSharedModule( // it above continue; } - if (log) { - log->Printf("Searching for %s in sdk path %s", platform_file_path, - m_sdk_directory_infos[sdk_idx].directory.GetPath().c_str()); - } + LLDB_LOGV(log, "Searching for {0} in sdk path {1}", platform_file, + m_sdk_directory_infos[sdk_idx].directory); if (GetFileInSDK(platform_file_path, sdk_idx, platform_module_spec.GetFileSpec())) { // printf ("sdk[%u]: '%s'\n", sdk_idx, local_file.GetPath().c_str()); @@ -749,10 +732,8 @@ Error PlatformRemoteiOS::GetSharedModule( size_t num_module_search_paths = module_search_paths_ptr->GetSize(); for (size_t i = 0; i < num_module_search_paths; ++i) { - Log *log_verbose = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST | - LIBLLDB_LOG_VERBOSE); - if (log_verbose) - log_verbose->Printf ("PlatformRemoteiOS::GetSharedModule searching for binary in search-path %s", module_search_paths_ptr->GetFileSpecAtIndex(i).GetPath().c_str()); + LLDB_LOGV(log, "searching for binary in search-path {0}", + module_search_paths_ptr->GetFileSpecAtIndex(i)); // Create a new FileSpec with this module_search_paths_ptr // plus just the filename ("UIFoundation"), then the parent // dir plus filename ("UIFoundation.framework/UIFoundation") diff --git a/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h b/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h index 4d88a9e4103a..ccdce9874762 100644 --- a/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h +++ b/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h @@ -17,7 +17,9 @@ // Other libraries and framework includes // Project includes #include "PlatformDarwin.h" -#include "lldb/Host/FileSpec.h" +#include "lldb/Utility/FileSpec.h" + +#include "llvm/Support/FileSystem.h" class PlatformRemoteiOS : public PlatformDarwin { public: @@ -114,7 +116,7 @@ protected: static lldb_private::FileSpec::EnumerateDirectoryResult GetContainedFilesIntoVectorOfStringsCallback( - void *baton, lldb_private::FileSpec::FileType file_type, + void *baton, llvm::sys::fs::file_type ft, const lldb_private::FileSpec &file_spec); uint32_t FindFileInAllSDKs(const char *platform_file_path, diff --git a/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp b/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp index b4ce0830598b..9a082c701f02 100644 --- a/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp +++ b/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp @@ -16,18 +16,20 @@ // Project includes #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/ArchSpec.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/StreamString.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" + +#include "llvm/Support/FileSystem.h" using namespace lldb; using namespace lldb_private; @@ -252,9 +254,9 @@ Error PlatformiOSSimulator::ResolveExecutable( } static FileSpec::EnumerateDirectoryResult -EnumerateDirectoryCallback(void *baton, FileSpec::FileType file_type, +EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { - if (file_type == FileSpec::eFileTypeDirectory) { + if (ft == llvm::sys::fs::file_type::directory_file) { const char *filename = file_spec.GetFilename().GetCString(); if (filename && strncmp(filename, "iPhoneSimulator", strlen("iPhoneSimulator")) == 0) { diff --git a/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.h b/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.h index c132dc6fa433..2a2a6f73a0e1 100644 --- a/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.h +++ b/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.h @@ -24,10 +24,10 @@ typedef void *id; #endif // Project includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/Error.h" #include "lldb/Interpreter/Args.h" #include "lldb/Target/ProcessLaunchInfo.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Error.h" #include "llvm/ADT/Optional.h" diff --git a/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.mm b/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.mm index 233c548eb37b..de92aa0de7aa 100644 --- a/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.mm +++ b/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.mm @@ -16,8 +16,8 @@ #include <CoreFoundation/CoreFoundation.h> #include <Foundation/Foundation.h> // Project includes +#include "lldb/Host/PseudoTerminal.h" #include "lldb/Target/FileAction.h" -#include "lldb/Utility/PseudoTerminal.h" #include "llvm/ADT/StringRef.h" diff --git a/source/Plugins/Platform/NetBSD/CMakeLists.txt b/source/Plugins/Platform/NetBSD/CMakeLists.txt index c70b419b98b4..5e63f1098067 100644 --- a/source/Plugins/Platform/NetBSD/CMakeLists.txt +++ b/source/Plugins/Platform/NetBSD/CMakeLists.txt @@ -1,3 +1,9 @@ -add_lldb_library(lldbPluginPlatformNetBSD +add_lldb_library(lldbPluginPlatformNetBSD PLUGIN PlatformNetBSD.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbHost + lldbTarget ) diff --git a/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp b/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp index bc4bfd32aad7..409f12deefca 100644 --- a/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp +++ b/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp @@ -19,25 +19,45 @@ // C++ Includes // Other libraries and framework includes // Project includes -#include "lldb/Breakpoint/BreakpointLocation.h" -#include "lldb/Breakpoint/BreakpointSite.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Module.h" -#include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Host/Host.h" +#include "lldb/Core/State.h" #include "lldb/Host/HostInfo.h" #include "lldb/Target/Process.h" +#include "lldb/Target/Target.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" + +// Define these constants from NetBSD mman.h for use when targeting +// remote netbsd systems even when host has different values. +#define MAP_PRIVATE 0x0002 +#define MAP_ANON 0x1000 using namespace lldb; using namespace lldb_private; using namespace lldb_private::platform_netbsd; +static uint32_t g_initialize_count = 0; + +//------------------------------------------------------------------ + PlatformSP PlatformNetBSD::CreateInstance(bool force, const ArchSpec *arch) { - // The only time we create an instance is when we are creating a remote - // netbsd platform - const bool is_host = false; + Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); + if (log) { + const char *arch_name; + if (arch && arch->GetArchitectureName()) + arch_name = arch->GetArchitectureName(); + else + arch_name = "<null>"; + + const char *triple_cstr = + arch ? arch->GetTriple().getTriple().c_str() : "<null>"; + + log->Printf("PlatformNetBSD::%s(force=%s, arch={%s,%s})", __FUNCTION__, + force ? "true" : "false", arch_name, triple_cstr); + } bool create = force; if (create == false && arch && arch->IsValid()) { @@ -51,8 +71,19 @@ PlatformSP PlatformNetBSD::CreateInstance(bool force, const ArchSpec *arch) { break; } } - if (create) - return PlatformSP(new PlatformNetBSD(is_host)); + + if (create) { + if (log) + log->Printf("PlatformNetBSD::%s() creating remote-netbsd platform", + __FUNCTION__); + return PlatformSP(new PlatformNetBSD(false)); + } + + if (log) + log->Printf( + "PlatformNetBSD::%s() aborting creation of remote-netbsd platform", + __FUNCTION__); + return PlatformSP(); } @@ -66,359 +97,51 @@ ConstString PlatformNetBSD::GetPluginNameStatic(bool is_host) { } } -const char *PlatformNetBSD::GetDescriptionStatic(bool is_host) { +const char *PlatformNetBSD::GetPluginDescriptionStatic(bool is_host) { if (is_host) return "Local NetBSD user platform plug-in."; else return "Remote NetBSD user platform plug-in."; } -static uint32_t g_initialize_count = 0; +ConstString PlatformNetBSD::GetPluginName() { + return GetPluginNameStatic(IsHost()); +} void PlatformNetBSD::Initialize() { - Platform::Initialize(); + PlatformPOSIX::Initialize(); if (g_initialize_count++ == 0) { #if defined(__NetBSD__) - // Force a host flag to true for the default platform object. PlatformSP default_platform_sp(new PlatformNetBSD(true)); default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture()); Platform::SetHostPlatform(default_platform_sp); #endif - PluginManager::RegisterPlugin(PlatformNetBSD::GetPluginNameStatic(false), - PlatformNetBSD::GetDescriptionStatic(false), - PlatformNetBSD::CreateInstance); + PluginManager::RegisterPlugin( + PlatformNetBSD::GetPluginNameStatic(false), + PlatformNetBSD::GetPluginDescriptionStatic(false), + PlatformNetBSD::CreateInstance, nullptr); } } void PlatformNetBSD::Terminate() { - if (g_initialize_count > 0 && --g_initialize_count == 0) - PluginManager::UnregisterPlugin(PlatformNetBSD::CreateInstance); - - Platform::Terminate(); -} - -bool PlatformNetBSD::GetModuleSpec(const FileSpec &module_file_spec, - const ArchSpec &arch, - ModuleSpec &module_spec) { - if (m_remote_platform_sp) - return m_remote_platform_sp->GetModuleSpec(module_file_spec, arch, - module_spec); - - return Platform::GetModuleSpec(module_file_spec, arch, module_spec); -} - -Error PlatformNetBSD::RunShellCommand(const char *command, - const FileSpec &working_dir, - int *status_ptr, int *signo_ptr, - std::string *command_output, - uint32_t timeout_sec) { - if (IsHost()) - return Host::RunShellCommand(command, working_dir, status_ptr, signo_ptr, - command_output, timeout_sec); - else { - if (m_remote_platform_sp) - return m_remote_platform_sp->RunShellCommand(command, working_dir, - status_ptr, signo_ptr, - command_output, timeout_sec); - else - return Error("unable to run a remote command without a platform"); - } -} - -Error PlatformNetBSD::ResolveExecutable( - const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp, - const FileSpecList *module_search_paths_ptr) { - Error error; - // Nothing special to do here, just use the actual file and architecture - - char exe_path[PATH_MAX]; - ModuleSpec resolved_module_spec(module_spec); - - if (IsHost()) { - // If we have "ls" as the module_spec's file, resolve the executable - // location based on - // the current path variables - if (!resolved_module_spec.GetFileSpec().Exists()) { - module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path)); - resolved_module_spec.GetFileSpec().SetFile(exe_path, true); - } - - if (!resolved_module_spec.GetFileSpec().Exists()) - resolved_module_spec.GetFileSpec().ResolveExecutableLocation(); - - if (resolved_module_spec.GetFileSpec().Exists()) - error.Clear(); - else { - error.SetErrorStringWithFormat( - "unable to find executable for '%s'", - resolved_module_spec.GetFileSpec().GetPath().c_str()); - } - } else { - if (m_remote_platform_sp) { - error = - GetCachedExecutable(resolved_module_spec, exe_module_sp, - module_search_paths_ptr, *m_remote_platform_sp); - } else { - // We may connect to a process and use the provided executable (Don't use - // local $PATH). - - // Resolve any executable within a bundle on MacOSX - Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec()); - - if (resolved_module_spec.GetFileSpec().Exists()) { - error.Clear(); - } else { - error.SetErrorStringWithFormat( - "the platform is not currently connected, and '%s' doesn't exist " - "in the system root.", - resolved_module_spec.GetFileSpec().GetPath().c_str()); - } - } - } - - if (error.Success()) { - if (resolved_module_spec.GetArchitecture().IsValid()) { - error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, - module_search_paths_ptr, NULL, NULL); - - if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL) { - exe_module_sp.reset(); - error.SetErrorStringWithFormat( - "'%s' doesn't contain the architecture %s", - resolved_module_spec.GetFileSpec().GetPath().c_str(), - resolved_module_spec.GetArchitecture().GetArchitectureName()); - } - } else { - // No valid architecture was specified, ask the platform for - // the architectures that we should be using (in the correct order) - // and see if we can find a match that way - StreamString arch_names; - for (uint32_t idx = 0; GetSupportedArchitectureAtIndex( - idx, resolved_module_spec.GetArchitecture()); - ++idx) { - error = - ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, - module_search_paths_ptr, NULL, NULL); - // Did we find an executable using one of the - if (error.Success()) { - if (exe_module_sp && exe_module_sp->GetObjectFile()) - break; - else - error.SetErrorToGenericError(); - } - - if (idx > 0) - arch_names.PutCString(", "); - arch_names.PutCString( - resolved_module_spec.GetArchitecture().GetArchitectureName()); - } - - if (error.Fail() || !exe_module_sp) { - if (resolved_module_spec.GetFileSpec().Readable()) { - error.SetErrorStringWithFormat( - "'%s' doesn't contain any '%s' platform architectures: %s", - resolved_module_spec.GetFileSpec().GetPath().c_str(), - GetPluginName().GetCString(), arch_names.GetData()); - } else { - error.SetErrorStringWithFormat( - "'%s' is not readable", - resolved_module_spec.GetFileSpec().GetPath().c_str()); - } - } + if (g_initialize_count > 0) { + if (--g_initialize_count == 0) { + PluginManager::UnregisterPlugin(PlatformNetBSD::CreateInstance); } } - return error; -} - -// From PlatformMacOSX only -Error PlatformNetBSD::GetFileWithUUID(const FileSpec &platform_file, - const UUID *uuid_ptr, - FileSpec &local_file) { - if (IsRemote()) { - if (m_remote_platform_sp) - return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr, - local_file); - } - - // Default to the local case - local_file = platform_file; - return Error(); + PlatformPOSIX::Terminate(); } //------------------------------------------------------------------ /// Default Constructor //------------------------------------------------------------------ PlatformNetBSD::PlatformNetBSD(bool is_host) - : Platform(is_host), m_remote_platform_sp() {} - -bool PlatformNetBSD::GetRemoteOSVersion() { - if (m_remote_platform_sp) - return m_remote_platform_sp->GetOSVersion( - m_major_os_version, m_minor_os_version, m_update_os_version); - return false; -} - -bool PlatformNetBSD::GetRemoteOSBuildString(std::string &s) { - if (m_remote_platform_sp) - return m_remote_platform_sp->GetRemoteOSBuildString(s); - s.clear(); - return false; -} - -bool PlatformNetBSD::GetRemoteOSKernelDescription(std::string &s) { - if (m_remote_platform_sp) - return m_remote_platform_sp->GetRemoteOSKernelDescription(s); - s.clear(); - return false; -} - -// Remote Platform subclasses need to override this function -ArchSpec PlatformNetBSD::GetRemoteSystemArchitecture() { - if (m_remote_platform_sp) - return m_remote_platform_sp->GetRemoteSystemArchitecture(); - return ArchSpec(); -} - -const char *PlatformNetBSD::GetHostname() { - if (IsHost()) - return Platform::GetHostname(); - - if (m_remote_platform_sp) - return m_remote_platform_sp->GetHostname(); - return NULL; -} - -bool PlatformNetBSD::IsConnected() const { - if (IsHost()) - return true; - else if (m_remote_platform_sp) - return m_remote_platform_sp->IsConnected(); - return false; -} - -Error PlatformNetBSD::ConnectRemote(Args &args) { - Error error; - if (IsHost()) { - error.SetErrorStringWithFormat( - "can't connect to the host platform '%s', always connected", - GetPluginName().GetCString()); - } else { - if (!m_remote_platform_sp) - m_remote_platform_sp = - Platform::Create(ConstString("remote-gdb-server"), error); - - if (m_remote_platform_sp) { - if (error.Success()) { - if (m_remote_platform_sp) { - error = m_remote_platform_sp->ConnectRemote(args); - } else { - error.SetErrorString( - "\"platform connect\" takes a single argument: <connect-url>"); - } - } - } else - error.SetErrorString("failed to create a 'remote-gdb-server' platform"); - - if (error.Fail()) - m_remote_platform_sp.reset(); - } - - return error; -} - -Error PlatformNetBSD::DisconnectRemote() { - Error error; + : PlatformPOSIX(is_host) // This is the local host platform +{} - if (IsHost()) { - error.SetErrorStringWithFormat( - "can't disconnect from the host platform '%s', always connected", - GetPluginName().GetCString()); - } else { - if (m_remote_platform_sp) - error = m_remote_platform_sp->DisconnectRemote(); - else - error.SetErrorString("the platform is not currently connected"); - } - return error; -} - -bool PlatformNetBSD::GetProcessInfo(lldb::pid_t pid, - ProcessInstanceInfo &process_info) { - bool success = false; - if (IsHost()) { - success = Platform::GetProcessInfo(pid, process_info); - } else if (m_remote_platform_sp) { - success = m_remote_platform_sp->GetProcessInfo(pid, process_info); - } - return success; -} - -uint32_t -PlatformNetBSD::FindProcesses(const ProcessInstanceInfoMatch &match_info, - ProcessInstanceInfoList &process_infos) { - uint32_t match_count = 0; - if (IsHost()) { - // Let the base class figure out the host details - match_count = Platform::FindProcesses(match_info, process_infos); - } else { - // If we are remote, we can only return results if we are connected - if (m_remote_platform_sp) - match_count = - m_remote_platform_sp->FindProcesses(match_info, process_infos); - } - return match_count; -} - -const char *PlatformNetBSD::GetUserName(uint32_t uid) { - // Check the cache in Platform in case we have already looked this uid up - const char *user_name = Platform::GetUserName(uid); - if (user_name) - return user_name; - - if (IsRemote() && m_remote_platform_sp) - return m_remote_platform_sp->GetUserName(uid); - return NULL; -} - -const char *PlatformNetBSD::GetGroupName(uint32_t gid) { - const char *group_name = Platform::GetGroupName(gid); - if (group_name) - return group_name; - - if (IsRemote() && m_remote_platform_sp) - return m_remote_platform_sp->GetGroupName(gid); - return NULL; -} - -Error PlatformNetBSD::GetSharedModule( - const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp, - const FileSpecList *module_search_paths_ptr, ModuleSP *old_module_sp_ptr, - bool *did_create_ptr) { - Error error; - module_sp.reset(); - - if (IsRemote()) { - // If we have a remote platform always, let it try and locate - // the shared module first. - if (m_remote_platform_sp) { - error = m_remote_platform_sp->GetSharedModule( - module_spec, process, module_sp, module_search_paths_ptr, - old_module_sp_ptr, did_create_ptr); - } - } - - if (!module_sp) { - // Fall back to the local platform and find the file locally - error = Platform::GetSharedModule(module_spec, process, module_sp, - module_search_paths_ptr, - old_module_sp_ptr, did_create_ptr); - } - if (module_sp) - module_sp->SetPlatformFileSpec(module_spec.GetFileSpec()); - return error; -} +PlatformNetBSD::~PlatformNetBSD() = default; bool PlatformNetBSD::GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) { @@ -471,79 +194,239 @@ bool PlatformNetBSD::GetSupportedArchitectureAtIndex(uint32_t idx, } void PlatformNetBSD::GetStatus(Stream &strm) { + Platform::GetStatus(strm); + #ifndef LLDB_DISABLE_POSIX - struct ::utsname un; + // Display local kernel information only when we are running in host mode. + // Otherwise, we would end up printing non-NetBSD information (when running + // on Mac OS for example). + if (IsHost()) { + struct utsname un; - strm << " Host: "; + if (uname(&un)) + return; - ::memset(&un, 0, sizeof(utsname)); - if (::uname(&un) == -1) { - strm << "NetBSD" << '\n'; - } else { - strm << un.sysname << ' ' << un.release; - if (un.nodename[0] != '\0') - strm << " (" << un.nodename << ')'; - strm << '\n'; - - // Dump a common information about the platform status. - strm << "Host: " << un.sysname << ' ' << un.release << ' ' << un.version - << '\n'; + strm.Printf(" Kernel: %s\n", un.sysname); + strm.Printf(" Release: %s\n", un.release); + strm.Printf(" Version: %s\n", un.version); } #endif - - Platform::GetStatus(strm); } -void PlatformNetBSD::CalculateTrapHandlerSymbolNames() { - m_trap_handlers.push_back(ConstString("_sigtramp")); +int32_t +PlatformNetBSD::GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) { + int32_t resume_count = 0; + + // Always resume past the initial stop when we use eLaunchFlagDebug + if (launch_info.GetFlags().Test(eLaunchFlagDebug)) { + // Resume past the stop for the final exec into the true inferior. + ++resume_count; + } + + // If we're not launching a shell, we're done. + const FileSpec &shell = launch_info.GetShell(); + if (!shell) + return resume_count; + + std::string shell_string = shell.GetPath(); + // We're in a shell, so for sure we have to resume past the shell exec. + ++resume_count; + + // Figure out what shell we're planning on using. + const char *shell_name = strrchr(shell_string.c_str(), '/'); + if (shell_name == NULL) + shell_name = shell_string.c_str(); + else + shell_name++; + + if (strcmp(shell_name, "csh") == 0 || strcmp(shell_name, "tcsh") == 0 || + strcmp(shell_name, "zsh") == 0 || strcmp(shell_name, "sh") == 0) { + // These shells seem to re-exec themselves. Add another resume. + ++resume_count; + } + + return resume_count; } -Error PlatformNetBSD::LaunchProcess(ProcessLaunchInfo &launch_info) { - Error error; +bool PlatformNetBSD::CanDebugProcess() { if (IsHost()) { - error = Platform::LaunchProcess(launch_info); + return true; } else { - if (m_remote_platform_sp) - error = m_remote_platform_sp->LaunchProcess(launch_info); - else - error.SetErrorString("the platform is not currently connected"); + // If we're connected, we can debug. + return IsConnected(); } - return error; } -lldb::ProcessSP PlatformNetBSD::Attach(ProcessAttachInfo &attach_info, - Debugger &debugger, Target *target, - Error &error) { - lldb::ProcessSP process_sp; - if (IsHost()) { - if (target == NULL) { - TargetSP new_target_sp; - ArchSpec emptyArchSpec; - - error = debugger.GetTargetList().CreateTarget(debugger, "", emptyArchSpec, - false, m_remote_platform_sp, - new_target_sp); - target = new_target_sp.get(); - } else - error.Clear(); - - if (target && error.Success()) { - debugger.GetTargetList().SetSelectedTarget(target); - // The netbsd always currently uses the GDB remote debugger plug-in - // so even when debugging locally we are debugging remotely! - // Just like the darwin plugin. - process_sp = target->CreateProcess( - attach_info.GetListenerForProcess(debugger), "gdb-remote", NULL); - - if (process_sp) - error = process_sp->Attach(attach_info); +// For local debugging, NetBSD will override the debug logic to use llgs-launch +// rather than +// lldb-launch, llgs-attach. This differs from current lldb-launch, +// debugserver-attach +// approach on MacOSX. +lldb::ProcessSP +PlatformNetBSD::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, + Target *target, // Can be NULL, if NULL create a new + // target, else use existing one + Error &error) { + Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); + if (log) + log->Printf("PlatformNetBSD::%s entered (target %p)", __FUNCTION__, + static_cast<void *>(target)); + + // If we're a remote host, use standard behavior from parent class. + if (!IsHost()) + return PlatformPOSIX::DebugProcess(launch_info, debugger, target, error); + + // + // For local debugging, we'll insist on having ProcessGDBRemote create the + // process. + // + + ProcessSP process_sp; + + // Make sure we stop at the entry point + launch_info.GetFlags().Set(eLaunchFlagDebug); + + // We always launch the process we are going to debug in a separate process + // group, since then we can handle ^C interrupts ourselves w/o having to worry + // about the target getting them as well. + launch_info.SetLaunchInSeparateProcessGroup(true); + + // Ensure we have a target. + if (target == nullptr) { + if (log) + log->Printf("PlatformNetBSD::%s creating new target", __FUNCTION__); + + TargetSP new_target_sp; + error = debugger.GetTargetList().CreateTarget(debugger, "", "", false, + nullptr, new_target_sp); + if (error.Fail()) { + if (log) + log->Printf("PlatformNetBSD::%s failed to create new target: %s", + __FUNCTION__, error.AsCString()); + return process_sp; + } + + target = new_target_sp.get(); + if (!target) { + error.SetErrorString("CreateTarget() returned nullptr"); + if (log) + log->Printf("PlatformNetBSD::%s failed: %s", __FUNCTION__, + error.AsCString()); + return process_sp; } } else { - if (m_remote_platform_sp) - process_sp = - m_remote_platform_sp->Attach(attach_info, debugger, target, error); - else - error.SetErrorString("the platform is not currently connected"); + if (log) + log->Printf("PlatformNetBSD::%s using provided target", __FUNCTION__); + } + + // Mark target as currently selected target. + debugger.GetTargetList().SetSelectedTarget(target); + + // Now create the gdb-remote process. + if (log) + log->Printf( + "PlatformNetBSD::%s having target create process with gdb-remote plugin", + __FUNCTION__); + process_sp = target->CreateProcess( + launch_info.GetListenerForProcess(debugger), "gdb-remote", nullptr); + + if (!process_sp) { + error.SetErrorString("CreateProcess() failed for gdb-remote process"); + if (log) + log->Printf("PlatformNetBSD::%s failed: %s", __FUNCTION__, + error.AsCString()); + return process_sp; + } else { + if (log) + log->Printf("PlatformNetBSD::%s successfully created process", + __FUNCTION__); } + + // Adjust launch for a hijacker. + ListenerSP listener_sp; + if (!launch_info.GetHijackListener()) { + if (log) + log->Printf("PlatformNetBSD::%s setting up hijacker", __FUNCTION__); + + listener_sp = + Listener::MakeListener("lldb.PlatformNetBSD.DebugProcess.hijack"); + launch_info.SetHijackListener(listener_sp); + process_sp->HijackProcessEvents(listener_sp); + } + + // Log file actions. + if (log) { + log->Printf( + "PlatformNetBSD::%s launching process with the following file actions:", + __FUNCTION__); + + StreamString stream; + size_t i = 0; + const FileAction *file_action; + while ((file_action = launch_info.GetFileActionAtIndex(i++)) != nullptr) { + file_action->Dump(stream); + log->PutCString(stream.GetData()); + stream.Clear(); + } + } + + // Do the launch. + error = process_sp->Launch(launch_info); + if (error.Success()) { + // Handle the hijacking of process events. + if (listener_sp) { + const StateType state = process_sp->WaitForProcessToStop( + llvm::None, NULL, false, listener_sp); + + if (state == eStateStopped) { + if (log) + log->Printf("PlatformNetBSD::%s pid %" PRIu64 " state %s\n", + __FUNCTION__, process_sp->GetID(), StateAsCString(state)); + } else { + if (log) + log->Printf("PlatformNetBSD::%s pid %" PRIu64 + " state is not stopped - %s\n", + __FUNCTION__, process_sp->GetID(), StateAsCString(state)); + } + } + + // Hook up process PTY if we have one (which we should for local debugging + // with llgs). + int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor(); + if (pty_fd != lldb_utility::PseudoTerminal::invalid_fd) { + process_sp->SetSTDIOFileDescriptor(pty_fd); + if (log) + log->Printf("PlatformNetBSD::%s pid %" PRIu64 + " hooked up STDIO pty to process", + __FUNCTION__, process_sp->GetID()); + } else { + if (log) + log->Printf("PlatformNetBSD::%s pid %" PRIu64 + " not using process STDIO pty", + __FUNCTION__, process_sp->GetID()); + } + } else { + if (log) + log->Printf("PlatformNetBSD::%s process launch failed: %s", __FUNCTION__, + error.AsCString()); + // FIXME figure out appropriate cleanup here. Do we delete the target? Do + // we delete the process? Does our caller do that? + } + return process_sp; } + +void PlatformNetBSD::CalculateTrapHandlerSymbolNames() { + m_trap_handlers.push_back(ConstString("_sigtramp")); +} + +uint64_t PlatformNetBSD::ConvertMmapFlagsToPlatform(const ArchSpec &arch, + unsigned flags) { + uint64_t flags_platform = 0; + + if (flags & eMmapFlagsPrivate) + flags_platform |= MAP_PRIVATE; + if (flags & eMmapFlagsAnon) + flags_platform |= MAP_ANON; + return flags_platform; +} diff --git a/source/Plugins/Platform/NetBSD/PlatformNetBSD.h b/source/Plugins/Platform/NetBSD/PlatformNetBSD.h index ddca5eb5be3e..500c61dab970 100644 --- a/source/Plugins/Platform/NetBSD/PlatformNetBSD.h +++ b/source/Plugins/Platform/NetBSD/PlatformNetBSD.h @@ -10,113 +10,57 @@ #ifndef liblldb_PlatformNetBSD_h_ #define liblldb_PlatformNetBSD_h_ -// C Includes -// C++ Includes -// Other libraries and framework includes -// Project includes -#include "lldb/Target/Platform.h" +#include "Plugins/Platform/POSIX/PlatformPOSIX.h" namespace lldb_private { namespace platform_netbsd { -class PlatformNetBSD : public Platform { +class PlatformNetBSD : public PlatformPOSIX { public: PlatformNetBSD(bool is_host); - ~PlatformNetBSD() override = default; - - //------------------------------------------------------------ - // Class functions - //------------------------------------------------------------ - static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch); + ~PlatformNetBSD() override; static void Initialize(); static void Terminate(); - static ConstString GetPluginNameStatic(bool is_host); - - static const char *GetDescriptionStatic(bool is_host); - //------------------------------------------------------------ // lldb_private::PluginInterface functions //------------------------------------------------------------ - ConstString GetPluginName() override { return GetPluginNameStatic(IsHost()); } + static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch); - uint32_t GetPluginVersion() override { return 1; } + static ConstString GetPluginNameStatic(bool is_host); - const char *GetDescription() override { - return GetDescriptionStatic(IsHost()); - } + static const char *GetPluginDescriptionStatic(bool is_host); + + ConstString GetPluginName() override; + + uint32_t GetPluginVersion() override { return 1; } //------------------------------------------------------------ // lldb_private::Platform functions //------------------------------------------------------------ - bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, - ModuleSpec &module_spec) override; - - Error RunShellCommand(const char *command, const FileSpec &working_dir, - int *status_ptr, int *signo_ptr, - std::string *command_output, - uint32_t timeout_sec) override; - - Error ResolveExecutable(const ModuleSpec &module_spec, - lldb::ModuleSP &module_sp, - const FileSpecList *module_search_paths_ptr) override; - - bool GetRemoteOSVersion() override; - - bool GetRemoteOSBuildString(std::string &s) override; - - bool GetRemoteOSKernelDescription(std::string &s) override; - - // Remote Platform subclasses need to override this function - ArchSpec GetRemoteSystemArchitecture() override; - - bool IsConnected() const override; - - Error ConnectRemote(Args &args) override; - - Error DisconnectRemote() override; - - const char *GetHostname() override; - - const char *GetUserName(uint32_t uid) override; - - const char *GetGroupName(uint32_t gid) override; - - bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override; - - uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, - ProcessInstanceInfoList &process_infos) override; - - Error LaunchProcess(ProcessLaunchInfo &launch_info) override; - - lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger, - Target *target, Error &error) override; + const char *GetDescription() override { + return GetPluginDescriptionStatic(IsHost()); + } - // NetBSD processes can not be launched by spawning and attaching. - bool CanDebugProcess() override { return false; } + void GetStatus(Stream &strm) override; - // Only on PlatformMacOSX: - Error GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid, - FileSpec &local_file) override; + bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override; - Error GetSharedModule(const ModuleSpec &module_spec, Process *process, - lldb::ModuleSP &module_sp, - const FileSpecList *module_search_paths_ptr, - lldb::ModuleSP *old_module_sp_ptr, - bool *did_create_ptr) override; + int32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) override; - bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override; + bool CanDebugProcess() override; - void GetStatus(Stream &strm) override; + lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info, + Debugger &debugger, Target *target, + Error &error) override; void CalculateTrapHandlerSymbolNames() override; -protected: - lldb::PlatformSP m_remote_platform_sp; // Allow multiple ways to connect to a - // remote netbsd OS + uint64_t ConvertMmapFlagsToPlatform(const ArchSpec &arch, + unsigned flags) override; private: DISALLOW_COPY_AND_ASSIGN(PlatformNetBSD); diff --git a/source/Plugins/Platform/OpenBSD/CMakeLists.txt b/source/Plugins/Platform/OpenBSD/CMakeLists.txt new file mode 100644 index 000000000000..8d49e7c4f196 --- /dev/null +++ b/source/Plugins/Platform/OpenBSD/CMakeLists.txt @@ -0,0 +1,9 @@ +add_lldb_library(lldbPluginPlatformOpenBSD PLUGIN + PlatformOpenBSD.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbHost + lldbTarget + ) diff --git a/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp b/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp new file mode 100644 index 000000000000..e3816d0276b2 --- /dev/null +++ b/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp @@ -0,0 +1,223 @@ +//===-- PlatformOpenBSD.cpp -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "PlatformOpenBSD.h" +#include "lldb/Host/Config.h" + +// C Includes +#include <stdio.h> +#ifndef LLDB_DISABLE_POSIX +#include <sys/utsname.h> +#endif + +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Core/Debugger.h" +#include "lldb/Core/PluginManager.h" +#include "lldb/Core/State.h" +#include "lldb/Host/HostInfo.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/Target.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" + +// Define these constants from OpenBSD mman.h for use when targeting +// remote openbsd systems even when host has different values. +#define MAP_PRIVATE 0x0002 +#define MAP_ANON 0x1000 + +using namespace lldb; +using namespace lldb_private; +using namespace lldb_private::platform_openbsd; + +static uint32_t g_initialize_count = 0; + +//------------------------------------------------------------------ + +PlatformSP PlatformOpenBSD::CreateInstance(bool force, const ArchSpec *arch) { + Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); + LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force, + arch ? arch->GetArchitectureName() : "<null>", + arch ? arch->GetTriple().getTriple() : "<null>"); + + bool create = force; + if (create == false && arch && arch->IsValid()) { + const llvm::Triple &triple = arch->GetTriple(); + switch (triple.getOS()) { + case llvm::Triple::OpenBSD: + create = true; + break; + +#if defined(__OpenBSD__) + // Only accept "unknown" for the OS if the host is BSD and + // it "unknown" wasn't specified (it was just returned because it + // was NOT specified) + case llvm::Triple::OSType::UnknownOS: + create = !arch->TripleOSWasSpecified(); + break; +#endif + default: + break; + } + } + LLDB_LOG(log, "create = {0}", create); + if (create) { + return PlatformSP(new PlatformOpenBSD(false)); + } + return PlatformSP(); +} + +ConstString PlatformOpenBSD::GetPluginNameStatic(bool is_host) { + if (is_host) { + static ConstString g_host_name(Platform::GetHostPlatformName()); + return g_host_name; + } else { + static ConstString g_remote_name("remote-openbsd"); + return g_remote_name; + } +} + +const char *PlatformOpenBSD::GetPluginDescriptionStatic(bool is_host) { + if (is_host) + return "Local OpenBSD user platform plug-in."; + else + return "Remote OpenBSD user platform plug-in."; +} + +ConstString PlatformOpenBSD::GetPluginName() { + return GetPluginNameStatic(IsHost()); +} + +void PlatformOpenBSD::Initialize() { + Platform::Initialize(); + + if (g_initialize_count++ == 0) { +#if defined(__OpenBSD__) + PlatformSP default_platform_sp(new PlatformOpenBSD(true)); + default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture()); + Platform::SetHostPlatform(default_platform_sp); +#endif + PluginManager::RegisterPlugin( + PlatformOpenBSD::GetPluginNameStatic(false), + PlatformOpenBSD::GetPluginDescriptionStatic(false), + PlatformOpenBSD::CreateInstance, nullptr); + } +} + +void PlatformOpenBSD::Terminate() { + if (g_initialize_count > 0) { + if (--g_initialize_count == 0) { + PluginManager::UnregisterPlugin(PlatformOpenBSD::CreateInstance); + } + } + + PlatformPOSIX::Terminate(); +} + +//------------------------------------------------------------------ +/// Default Constructor +//------------------------------------------------------------------ +PlatformOpenBSD::PlatformOpenBSD(bool is_host) + : PlatformPOSIX(is_host) // This is the local host platform +{} + +PlatformOpenBSD::~PlatformOpenBSD() = default; + +bool PlatformOpenBSD::GetSupportedArchitectureAtIndex(uint32_t idx, + ArchSpec &arch) { + if (IsHost()) { + ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault); + if (hostArch.GetTriple().isOSOpenBSD()) { + if (idx == 0) { + arch = hostArch; + return arch.IsValid(); + } + } + } else { + if (m_remote_platform_sp) + return m_remote_platform_sp->GetSupportedArchitectureAtIndex(idx, arch); + + llvm::Triple triple; + // Set the OS to OpenBSD + triple.setOS(llvm::Triple::OpenBSD); + // Set the architecture + switch (idx) { + case 0: + triple.setArchName("x86_64"); + break; + case 1: + triple.setArchName("i386"); + break; + case 2: + triple.setArchName("aarch64"); + break; + case 3: + triple.setArchName("arm"); + break; + default: + return false; + } + // Leave the vendor as "llvm::Triple:UnknownVendor" and don't specify the + // vendor by + // calling triple.SetVendorName("unknown") so that it is a "unspecified + // unknown". + // This means when someone calls triple.GetVendorName() it will return an + // empty string + // which indicates that the vendor can be set when two architectures are + // merged + + // Now set the triple into "arch" and return true + arch.SetTriple(triple); + return true; + } + return false; +} + +void PlatformOpenBSD::GetStatus(Stream &strm) { + Platform::GetStatus(strm); + +#ifndef LLDB_DISABLE_POSIX + // Display local kernel information only when we are running in host mode. + // Otherwise, we would end up printing non-OpenBSD information (when running + // on Mac OS for example). + if (IsHost()) { + struct utsname un; + + if (uname(&un)) + return; + + strm.Printf(" Kernel: %s\n", un.sysname); + strm.Printf(" Release: %s\n", un.release); + strm.Printf(" Version: %s\n", un.version); + } +#endif +} + +// OpenBSD processes cannot yet be launched by spawning and attaching. +bool PlatformOpenBSD::CanDebugProcess() { + return false; +} + +void PlatformOpenBSD::CalculateTrapHandlerSymbolNames() { + m_trap_handlers.push_back(ConstString("_sigtramp")); +} + +uint64_t PlatformOpenBSD::ConvertMmapFlagsToPlatform(const ArchSpec &arch, + unsigned flags) { + uint64_t flags_platform = 0; + + if (flags & eMmapFlagsPrivate) + flags_platform |= MAP_PRIVATE; + if (flags & eMmapFlagsAnon) + flags_platform |= MAP_ANON; + return flags_platform; +} diff --git a/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h b/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h new file mode 100644 index 000000000000..55f6451e236e --- /dev/null +++ b/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h @@ -0,0 +1,66 @@ +//===-- PlatformOpenBSD.h ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_PlatformOpenBSD_h_ +#define liblldb_PlatformOpenBSD_h_ + +#include "Plugins/Platform/POSIX/PlatformPOSIX.h" + +namespace lldb_private { +namespace platform_openbsd { + +class PlatformOpenBSD : public PlatformPOSIX { +public: + PlatformOpenBSD(bool is_host); + + ~PlatformOpenBSD() override; + + static void Initialize(); + + static void Terminate(); + + //------------------------------------------------------------ + // lldb_private::PluginInterface functions + //------------------------------------------------------------ + static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch); + + static ConstString GetPluginNameStatic(bool is_host); + + static const char *GetPluginDescriptionStatic(bool is_host); + + ConstString GetPluginName() override; + + uint32_t GetPluginVersion() override { return 1; } + + //------------------------------------------------------------ + // lldb_private::Platform functions + //------------------------------------------------------------ + const char *GetDescription() override { + return GetPluginDescriptionStatic(IsHost()); + } + + void GetStatus(Stream &strm) override; + + bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override; + + bool CanDebugProcess() override; + + void CalculateTrapHandlerSymbolNames() override; + + uint64_t ConvertMmapFlagsToPlatform(const ArchSpec &arch, + unsigned flags) override; + +private: + DISALLOW_COPY_AND_ASSIGN(PlatformOpenBSD); +}; + +} // namespace platform_openbsd +} // namespace lldb_private + +#endif // liblldb_PlatformOpenBSD_h_ diff --git a/source/Plugins/Platform/POSIX/CMakeLists.txt b/source/Plugins/Platform/POSIX/CMakeLists.txt index c23e68155c2b..749407d63d5c 100644 --- a/source/Plugins/Platform/POSIX/CMakeLists.txt +++ b/source/Plugins/Platform/POSIX/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginPlatformPOSIX +add_lldb_library(lldbPluginPlatformPOSIX PLUGIN PlatformPOSIX.cpp + + LINK_LIBS + lldbCore + lldbExpression + lldbHost + lldbInterpreter + lldbTarget ) diff --git a/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp index e51029c3630b..0032c804987c 100644 --- a/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ b/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -14,23 +14,25 @@ // Other libraries and framework includes // Project includes -#include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" -#include "lldb/Core/StreamString.h" +#include "lldb/Core/ModuleSpec.h" #include "lldb/Core/ValueObject.h" #include "lldb/Expression/UserExpression.h" #include "lldb/Host/File.h" #include "lldb/Host/FileCache.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" +#include "lldb/Host/HostInfo.h" #include "lldb/Target/DynamicLoader.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Process.h" #include "lldb/Target/ProcessLaunchInfo.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" using namespace lldb; using namespace lldb_private; @@ -111,6 +113,175 @@ lldb_private::Error PlatformPOSIX::RunShellCommand( } } +Error PlatformPOSIX::ResolveExecutable(const ModuleSpec &module_spec, + lldb::ModuleSP &exe_module_sp, + const FileSpecList *module_search_paths_ptr) { + Error error; + // Nothing special to do here, just use the actual file and architecture + + char exe_path[PATH_MAX]; + ModuleSpec resolved_module_spec(module_spec); + + if (IsHost()) { + // If we have "ls" as the exe_file, resolve the executable location based on + // the current path variables + if (!resolved_module_spec.GetFileSpec().Exists()) { + resolved_module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path)); + resolved_module_spec.GetFileSpec().SetFile(exe_path, true); + } + + if (!resolved_module_spec.GetFileSpec().Exists()) + resolved_module_spec.GetFileSpec().ResolveExecutableLocation(); + + // Resolve any executable within a bundle on MacOSX + Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec()); + + if (resolved_module_spec.GetFileSpec().Exists()) + error.Clear(); + else { + const uint32_t permissions = + resolved_module_spec.GetFileSpec().GetPermissions(); + if (permissions && (permissions & eFilePermissionsEveryoneR) == 0) + error.SetErrorStringWithFormat( + "executable '%s' is not readable", + resolved_module_spec.GetFileSpec().GetPath().c_str()); + else + error.SetErrorStringWithFormat( + "unable to find executable for '%s'", + resolved_module_spec.GetFileSpec().GetPath().c_str()); + } + } else { + if (m_remote_platform_sp) { + error = + GetCachedExecutable(resolved_module_spec, exe_module_sp, + module_search_paths_ptr, *m_remote_platform_sp); + } else { + // We may connect to a process and use the provided executable (Don't use + // local $PATH). + + // Resolve any executable within a bundle on MacOSX + Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec()); + + if (resolved_module_spec.GetFileSpec().Exists()) + error.Clear(); + else + error.SetErrorStringWithFormat("the platform is not currently " + "connected, and '%s' doesn't exist in " + "the system root.", + exe_path); + } + } + + if (error.Success()) { + if (resolved_module_spec.GetArchitecture().IsValid()) { + error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, + module_search_paths_ptr, nullptr, nullptr); + if (error.Fail()) { + // If we failed, it may be because the vendor and os aren't known. If + // that is the case, try setting them to the host architecture and give + // it another try. + llvm::Triple &module_triple = + resolved_module_spec.GetArchitecture().GetTriple(); + bool is_vendor_specified = + (module_triple.getVendor() != llvm::Triple::UnknownVendor); + bool is_os_specified = + (module_triple.getOS() != llvm::Triple::UnknownOS); + if (!is_vendor_specified || !is_os_specified) { + const llvm::Triple &host_triple = + HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple(); + + if (!is_vendor_specified) + module_triple.setVendorName(host_triple.getVendorName()); + if (!is_os_specified) + module_triple.setOSName(host_triple.getOSName()); + + error = ModuleList::GetSharedModule(resolved_module_spec, + exe_module_sp, module_search_paths_ptr, nullptr, nullptr); + } + } + + // TODO find out why exe_module_sp might be NULL + if (error.Fail() || !exe_module_sp || !exe_module_sp->GetObjectFile()) { + exe_module_sp.reset(); + error.SetErrorStringWithFormat( + "'%s' doesn't contain the architecture %s", + resolved_module_spec.GetFileSpec().GetPath().c_str(), + resolved_module_spec.GetArchitecture().GetArchitectureName()); + } + } else { + // No valid architecture was specified, ask the platform for + // the architectures that we should be using (in the correct order) + // and see if we can find a match that way + StreamString arch_names; + for (uint32_t idx = 0; GetSupportedArchitectureAtIndex( + idx, resolved_module_spec.GetArchitecture()); + ++idx) { + error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, + module_search_paths_ptr, nullptr, nullptr); + // Did we find an executable using one of the + if (error.Success()) { + if (exe_module_sp && exe_module_sp->GetObjectFile()) + break; + else + error.SetErrorToGenericError(); + } + + if (idx > 0) + arch_names.PutCString(", "); + arch_names.PutCString( + resolved_module_spec.GetArchitecture().GetArchitectureName()); + } + + if (error.Fail() || !exe_module_sp) { + if (resolved_module_spec.GetFileSpec().Readable()) { + error.SetErrorStringWithFormat( + "'%s' doesn't contain any '%s' platform architectures: %s", + resolved_module_spec.GetFileSpec().GetPath().c_str(), + GetPluginName().GetCString(), arch_names.GetData()); + } else { + error.SetErrorStringWithFormat( + "'%s' is not readable", + resolved_module_spec.GetFileSpec().GetPath().c_str()); + } + } + } + } + + return error; +} + +Error PlatformPOSIX::GetFileWithUUID(const FileSpec &platform_file, + const UUID *uuid_ptr, + FileSpec &local_file) { + if (IsRemote() && m_remote_platform_sp) + return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr, + local_file); + + // Default to the local case + local_file = platform_file; + return Error(); +} + +bool PlatformPOSIX::GetProcessInfo(lldb::pid_t pid, + ProcessInstanceInfo &process_info) { + if (IsHost()) + return Platform::GetProcessInfo(pid, process_info); + if (m_remote_platform_sp) + return m_remote_platform_sp->GetProcessInfo(pid, process_info); + return false; +} + +uint32_t +PlatformPOSIX::FindProcesses(const ProcessInstanceInfoMatch &match_info, + ProcessInstanceInfoList &process_infos) { + if (IsHost()) + return Platform::FindProcesses(match_info, process_infos); + if (m_remote_platform_sp) + return + m_remote_platform_sp->FindProcesses(match_info, process_infos); + return 0; +} + Error PlatformPOSIX::MakeDirectory(const FileSpec &file_spec, uint32_t file_permissions) { if (m_remote_platform_sp) @@ -264,9 +435,12 @@ PlatformPOSIX::PutFile(const lldb_private::FileSpec &source, } lldb::user_id_t PlatformPOSIX::GetFileSize(const FileSpec &file_spec) { - if (IsHost()) - return FileSystem::GetFileSize(file_spec); - else if (m_remote_platform_sp) + if (IsHost()) { + uint64_t Size; + if (llvm::sys::fs::file_size(file_spec.GetPath(), Size)) + return 0; + return Size; + } else if (m_remote_platform_sp) return m_remote_platform_sp->GetFileSize(file_spec); else return Platform::GetFileSize(file_spec); @@ -292,7 +466,7 @@ bool PlatformPOSIX::GetFileExists(const FileSpec &file_spec) { Error PlatformPOSIX::Unlink(const FileSpec &file_spec) { if (IsHost()) - return FileSystem::Unlink(file_spec); + return llvm::sys::fs::remove(file_spec.GetPath()); else if (m_remote_platform_sp) return m_remote_platform_sp->Unlink(file_spec); else @@ -864,3 +1038,12 @@ size_t PlatformPOSIX::ConnectToWaitingProcesses(Debugger &debugger, return m_remote_platform_sp->ConnectToWaitingProcesses(debugger, error); return Platform::ConnectToWaitingProcesses(debugger, error); } + +ConstString PlatformPOSIX::GetFullNameForDylib(ConstString basename) { + if (basename.IsEmpty()) + return basename; + + StreamString stream; + stream.Printf("lib%s.so", basename.GetCString()); + return ConstString(stream.GetString()); +} diff --git a/source/Plugins/Platform/POSIX/PlatformPOSIX.h b/source/Plugins/Platform/POSIX/PlatformPOSIX.h index 93213b295ca1..6c5c62797a6e 100644 --- a/source/Plugins/Platform/POSIX/PlatformPOSIX.h +++ b/source/Plugins/Platform/POSIX/PlatformPOSIX.h @@ -101,6 +101,18 @@ public: uint32_t timeout_sec) override; // Timeout in seconds to wait for shell program to finish + lldb_private::Error ResolveExecutable(const lldb_private::ModuleSpec &module_spec, + lldb::ModuleSP &module_sp, + const lldb_private::FileSpecList *module_search_paths_ptr) override; + + lldb_private::Error GetFileWithUUID(const lldb_private::FileSpec &platform_file, const lldb_private::UUID *uuid, + lldb_private::FileSpec &local_file) override; + + bool GetProcessInfo(lldb::pid_t pid, lldb_private::ProcessInstanceInfo &proc_info) override; + + uint32_t FindProcesses(const lldb_private::ProcessInstanceInfoMatch &match_info, + lldb_private::ProcessInstanceInfoList &process_infos) override; + lldb_private::Error MakeDirectory(const lldb_private::FileSpec &file_spec, uint32_t mode) override; @@ -165,6 +177,8 @@ public: size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger, lldb_private::Error &error) override; + lldb_private::ConstString GetFullNameForDylib(lldb_private::ConstString basename) override; + protected: std::unique_ptr<lldb_private::OptionGroupPlatformRSync> m_option_group_platform_rsync; diff --git a/source/Plugins/Platform/Windows/CMakeLists.txt b/source/Plugins/Platform/Windows/CMakeLists.txt index 09fbc11d33f2..49a197cdaff3 100644 --- a/source/Plugins/Platform/Windows/CMakeLists.txt +++ b/source/Plugins/Platform/Windows/CMakeLists.txt @@ -1,3 +1,9 @@ -add_lldb_library(lldbPluginPlatformWindows +add_lldb_library(lldbPluginPlatformWindows PLUGIN PlatformWindows.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbHost + lldbTarget ) diff --git a/source/Plugins/Platform/Windows/PlatformWindows.cpp b/source/Plugins/Platform/Windows/PlatformWindows.cpp index 290d8eab792f..f57842ee6e51 100644 --- a/source/Plugins/Platform/Windows/PlatformWindows.cpp +++ b/source/Plugins/Platform/Windows/PlatformWindows.cpp @@ -22,12 +22,12 @@ #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Breakpoint/BreakpointSite.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Error.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" #include "lldb/Host/HostInfo.h" #include "lldb/Target/Process.h" +#include "lldb/Utility/Error.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/Platform/gdb-server/CMakeLists.txt b/source/Plugins/Platform/gdb-server/CMakeLists.txt index b0b669e5b8b7..2e3302590b44 100644 --- a/source/Plugins/Platform/gdb-server/CMakeLists.txt +++ b/source/Plugins/Platform/gdb-server/CMakeLists.txt @@ -1,3 +1,10 @@ -add_lldb_library(lldbPluginPlatformGDB +add_lldb_library(lldbPluginPlatformGDB PLUGIN PlatformRemoteGDBServer.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbHost + lldbTarget + lldbPluginProcessUtility ) diff --git a/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp index 43f7a53d0f7c..218c62860114 100644 --- a/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ b/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -15,23 +15,21 @@ // Project includes #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/StreamFile.h" -#include "lldb/Core/StreamString.h" #include "lldb/Host/ConnectionFileDescriptor.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" -#include "lldb/Host/StringConvert.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" - -#include "Utility/UriParser.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" +#include "lldb/Utility/UriParser.h" #include "Plugins/Process/Utility/GDBRemoteSignals.h" diff --git a/source/Plugins/Process/CMakeLists.txt b/source/Plugins/Process/CMakeLists.txt index defa493088b6..62abd75a43b6 100644 --- a/source/Plugins/Process/CMakeLists.txt +++ b/source/Plugins/Process/CMakeLists.txt @@ -1,18 +1,19 @@ -if (CMAKE_SYSTEM_NAME MATCHES "Linux") +if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android") add_subdirectory(Linux) add_subdirectory(POSIX) elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") add_subdirectory(FreeBSD) add_subdirectory(POSIX) elseif (CMAKE_SYSTEM_NAME MATCHES "NetBSD") + add_subdirectory(NetBSD) add_subdirectory(POSIX) elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") add_subdirectory(Windows/Common) elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin") add_subdirectory(MacOSX-Kernel) + add_subdirectory(mach-core) endif() add_subdirectory(gdb-remote) add_subdirectory(Utility) -add_subdirectory(mach-core) add_subdirectory(elf-core) add_subdirectory(minidump) diff --git a/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp b/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp index 63b1ae6da968..feb7a11584f8 100644 --- a/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp +++ b/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp @@ -30,11 +30,11 @@ // LLDB includes #include "lldb/lldb-enumerations.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" -#include "lldb/Core/StreamString.h" +#include "lldb/Host/PseudoTerminal.h" #include "lldb/Target/ProcessLaunchInfo.h" -#include "lldb/Utility/PseudoTerminal.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" #include "CFBundle.h" #include "CFString.h" diff --git a/source/Plugins/Process/Darwin/MachException.cpp b/source/Plugins/Process/Darwin/MachException.cpp index 81706441494a..5a97a4b01be3 100644 --- a/source/Plugins/Process/Darwin/MachException.cpp +++ b/source/Plugins/Process/Darwin/MachException.cpp @@ -22,11 +22,11 @@ #include <mutex> // LLDB includes -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" -#include "lldb/Core/Stream.h" #include "lldb/Target/UnixSignals.h" +#include "lldb/Utility/Error.h" #include "lldb/Utility/LLDBAssert.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/Stream.h" using namespace lldb; using namespace lldb_private; diff --git a/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp b/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp index e56375ebaa49..65ab12fe1adf 100644 --- a/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp +++ b/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp @@ -19,11 +19,11 @@ // C++ includes // LLDB includes -#include "lldb/Core/Log.h" #include "lldb/Core/State.h" -#include "lldb/Core/StreamString.h" +#include "lldb/Host/PseudoTerminal.h" #include "lldb/Target/ProcessLaunchInfo.h" -#include "lldb/Utility/PseudoTerminal.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" #include "CFBundle.h" #include "CFString.h" @@ -31,6 +31,8 @@ #include "MachException.h" +#include "llvm/Support/FileSystem.h" + using namespace lldb; using namespace lldb_private; using namespace lldb_private::process_darwin; @@ -63,7 +65,7 @@ Error NativeProcessProtocol::Launch( FileSpec working_dir(launch_info.GetWorkingDirectory()); if (working_dir && (!working_dir.ResolvePath() || - working_dir.GetFileType() != FileSpec::eFileTypeDirectory)) { + !llvm::sys::fs::is_directory(working_dir.GetPath())) { error.SetErrorStringWithFormat("No such file or directory: %s", working_dir.GetCString()); return error; diff --git a/source/Plugins/Process/Darwin/NativeProcessDarwin.h b/source/Plugins/Process/Darwin/NativeProcessDarwin.h index 69c1b8d9e4cc..01fdd64b1273 100644 --- a/source/Plugins/Process/Darwin/NativeProcessDarwin.h +++ b/source/Plugins/Process/Darwin/NativeProcessDarwin.h @@ -24,11 +24,11 @@ // Other libraries and framework includes #include "lldb/Core/ArchSpec.h" #include "lldb/Host/Debug.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/HostThread.h" #include "lldb/Host/Pipe.h" #include "lldb/Host/common/NativeProcessProtocol.h" #include "lldb/Target/MemoryRegionInfo.h" +#include "lldb/Utility/FileSpec.h" #include "lldb/lldb-types.h" #include "LaunchFlavor.h" diff --git a/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp b/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp index 5e7f9ae7e6f9..b04f9053136b 100644 --- a/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp +++ b/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp @@ -13,7 +13,7 @@ #include <libproc.h> // LLDB includes -#include "lldb/Core/Stream.h" +#include "lldb/Utility/Stream.h" #include "NativeProcessDarwin.h" diff --git a/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp b/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp index aa9b04157658..fa06fb8b2a5f 100644 --- a/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp +++ b/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp @@ -20,9 +20,9 @@ #include <sys/sysctl.h> // LLDB includes -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" -#include "lldb/Core/Stream.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/Stream.h" #include "lldb/lldb-enumerations.h" #include "NativeProcessDarwin.h" diff --git a/source/Plugins/Process/FreeBSD/CMakeLists.txt b/source/Plugins/Process/FreeBSD/CMakeLists.txt index c0e3374fef89..63855992d708 100644 --- a/source/Plugins/Process/FreeBSD/CMakeLists.txt +++ b/source/Plugins/Process/FreeBSD/CMakeLists.txt @@ -2,7 +2,7 @@ include_directories(.) include_directories(../POSIX) include_directories(../Utility) -add_lldb_library(lldbPluginProcessFreeBSD +add_lldb_library(lldbPluginProcessFreeBSD PLUGIN ProcessFreeBSD.cpp FreeBSDThread.cpp ProcessMonitor.cpp @@ -13,4 +13,16 @@ add_lldb_library(lldbPluginProcessFreeBSD RegisterContextPOSIXProcessMonitor_powerpc.cpp RegisterContextPOSIXProcessMonitor_x86.cpp RegisterContextPOSIXProcessMonitor_mips64.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + lldbHost + lldbSymbol + lldbTarget + lldbUtility + lldbPluginProcessUtility + lldbPluginProcessPOSIX + LINK_COMPONENTS + Support ) diff --git a/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp b/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp index 0b09296cb7fd..bd8e5abe2255 100644 --- a/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp +++ b/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp @@ -9,6 +9,12 @@ // C Includes #include <errno.h> +#include <pthread.h> +#include <pthread_np.h> +#include <stdlib.h> +#include <sys/sysctl.h> +#include <sys/types.h> +#include <sys/user.h> // C++ Includes // Other libraries and framework includes @@ -18,16 +24,16 @@ // Project includes #include "FreeBSDThread.h" #include "POSIXStopInfo.h" -#include "Plugins/Process/Utility/RegisterContextFreeBSD_arm.h" +#include "Plugins/Process/POSIX/ProcessPOSIXLog.h" #include "Plugins/Process/Utility/RegisterContextFreeBSD_i386.h" #include "Plugins/Process/Utility/RegisterContextFreeBSD_mips64.h" #include "Plugins/Process/Utility/RegisterContextFreeBSD_powerpc.h" #include "Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.h" +#include "Plugins/Process/Utility/RegisterInfoPOSIX_arm.h" #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h" #include "Plugins/Process/Utility/UnwindLLDB.h" #include "ProcessFreeBSD.h" #include "ProcessMonitor.h" -#include "ProcessPOSIXLog.h" #include "RegisterContextPOSIXProcessMonitor_arm.h" #include "RegisterContextPOSIXProcessMonitor_arm64.h" #include "RegisterContextPOSIXProcessMonitor_mips64.h" @@ -53,8 +59,7 @@ FreeBSDThread::FreeBSDThread(Process &process, lldb::tid_t tid) : Thread(process, tid), m_frame_ap(), m_breakpoint(), m_thread_name_valid(false), m_thread_name(), m_posix_thread(NULL) { Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD)); - if (log && log->GetMask().Test(POSIX_LOG_VERBOSE)) - log->Printf("FreeBSDThread::%s (tid = %" PRIi64 ")", __FUNCTION__, tid); + LLDB_LOGV(log, "tid = {0}", tid); // Set the current watchpoints for this thread. Target &target = GetProcess()->GetTarget(); @@ -114,9 +119,41 @@ void FreeBSDThread::SetName(const char *name) { const char *FreeBSDThread::GetName() { if (!m_thread_name_valid) { - llvm::SmallString<32> thread_name; - HostNativeThread::GetName(GetID(), thread_name); - m_thread_name = thread_name.c_str(); + m_thread_name.clear(); + int pid = GetProcess()->GetID(); + + struct kinfo_proc *kp = nullptr, *nkp; + size_t len = 0; + int error; + int ctl[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD, + pid}; + + while (1) { + error = sysctl(ctl, 4, kp, &len, nullptr, 0); + if (kp == nullptr || (error != 0 && errno == ENOMEM)) { + // Add extra space in case threads are added before next call. + len += sizeof(*kp) + len / 10; + nkp = (struct kinfo_proc *)realloc(kp, len); + if (nkp == nullptr) { + free(kp); + return nullptr; + } + kp = nkp; + continue; + } + if (error != 0) + len = 0; + break; + } + + for (size_t i = 0; i < len / sizeof(*kp); i++) { + if (kp[i].ki_tid == (lwpid_t)GetID()) { + m_thread_name.append(kp[i].ki_tdname, + kp[i].ki_tdname + strlen(kp[i].ki_tdname)); + break; + } + } + free(kp); m_thread_name_valid = true; } @@ -138,7 +175,7 @@ lldb::RegisterContextSP FreeBSDThread::GetRegisterContext() { reg_interface = new RegisterInfoPOSIX_arm64(target_arch); break; case llvm::Triple::arm: - reg_interface = new RegisterContextFreeBSD_arm(target_arch); + reg_interface = new RegisterInfoPOSIX_arm(target_arch); break; case llvm::Triple::ppc: #ifndef __powerpc64__ @@ -215,8 +252,7 @@ FreeBSDThread::CreateRegisterContextForFrame(lldb_private::StackFrame *frame) { uint32_t concrete_frame_idx = 0; Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD)); - if (log && log->GetMask().Test(POSIX_LOG_VERBOSE)) - log->Printf("FreeBSDThread::%s ()", __FUNCTION__); + LLDB_LOGV(log, "called"); if (frame) concrete_frame_idx = frame->GetConcreteFrameIndex(); diff --git a/source/Plugins/Process/FreeBSD/POSIXStopInfo.h b/source/Plugins/Process/FreeBSD/POSIXStopInfo.h index 1ee16dd5f8f4..e51fc08d74cc 100644 --- a/source/Plugins/Process/FreeBSD/POSIXStopInfo.h +++ b/source/Plugins/Process/FreeBSD/POSIXStopInfo.h @@ -10,15 +10,9 @@ #ifndef liblldb_POSIXStopInfo_H_ #define liblldb_POSIXStopInfo_H_ -// C Includes -// C++ Includes -// Other libraries and framework includes -// Project includes -#include "lldb/Target/StopInfo.h" - -#include "CrashReason.h" #include "FreeBSDThread.h" - +#include "Plugins/Process/POSIX/CrashReason.h" +#include "lldb/Target/StopInfo.h" #include <string> //===----------------------------------------------------------------------===// diff --git a/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp b/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp index 82e45a5d5fc1..93d294fd040a 100644 --- a/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp +++ b/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp @@ -10,12 +10,21 @@ // C Includes #include <errno.h> +#include <pthread.h> +#include <pthread_np.h> +#include <stdlib.h> +#include <sys/sysctl.h> +#include <sys/types.h> +#include <sys/user.h> +#include <machine/elf.h> // C++ Includes #include <mutex> +#include <unordered_map> // Other libraries and framework includes #include "lldb/Core/PluginManager.h" |