diff options
Diffstat (limited to 'source/API')
-rw-r--r-- | source/API/CMakeLists.txt | 60 | ||||
-rw-r--r-- | source/API/SBBreakpoint.cpp | 87 | ||||
-rw-r--r-- | source/API/SBBreakpointLocation.cpp | 57 | ||||
-rw-r--r-- | source/API/SBBreakpointName.cpp | 685 | ||||
-rw-r--r-- | source/API/SBBreakpointOptionCommon.cpp | 85 | ||||
-rw-r--r-- | source/API/SBBreakpointOptionCommon.h | 37 | ||||
-rw-r--r-- | source/API/SBCommandInterpreter.cpp | 4 | ||||
-rw-r--r-- | source/API/SBDebugger.cpp | 84 | ||||
-rw-r--r-- | source/API/SBInstruction.cpp | 7 | ||||
-rw-r--r-- | source/API/SBPlatform.cpp | 2 | ||||
-rw-r--r-- | source/API/SBProcess.cpp | 10 | ||||
-rw-r--r-- | source/API/SBProcessInfo.cpp | 145 | ||||
-rw-r--r-- | source/API/SBTarget.cpp | 46 | ||||
-rw-r--r-- | source/API/SBType.cpp | 28 | ||||
-rw-r--r-- | source/API/SystemInitializerFull.cpp | 6 |
15 files changed, 1244 insertions, 99 deletions
diff --git a/source/API/CMakeLists.txt b/source/API/CMakeLists.txt index 9dd21bcf2aaf6..c96e59be5a44a 100644 --- a/source/API/CMakeLists.txt +++ b/source/API/CMakeLists.txt @@ -2,10 +2,6 @@ if ( CMAKE_SYSTEM_NAME MATCHES "Windows" ) add_definitions( -DEXPORT_LIBLLDB ) endif() -# Include this so that add_lldb_library() has the list of dependencies -# for liblldb to link against -include(${LLDB_PROJECT_ROOT}/cmake/LLDBDependencies.cmake) - option(LLDB_BUILD_FRAMEWORK "Build the Darwin LLDB.framework" Off) if(LLDB_BUILD_FRAMEWORK AND CMAKE_VERSION VERSION_LESS 3.7) @@ -24,6 +20,8 @@ add_lldb_library(liblldb SHARED SBBlock.cpp SBBreakpoint.cpp SBBreakpointLocation.cpp + SBBreakpointName.cpp + SBBreakpointOptionCommon.cpp SBBroadcaster.cpp SBCommandInterpreter.cpp SBCommandReturnObject.cpp @@ -53,6 +51,7 @@ add_lldb_library(liblldb SHARED SBModuleSpec.cpp SBPlatform.cpp SBProcess.cpp + SBProcessInfo.cpp SBQueue.cpp SBQueueItem.cpp SBSection.cpp @@ -109,9 +108,17 @@ if (LLVM_ENABLE_WERROR) set_property(SOURCE ${LLDB_WRAP_PYTHON} APPEND_STRING PROPERTY COMPILE_FLAGS " -w") endif() endif() +set_source_files_properties(${LLDB_WRAP_PYTHON} PROPERTIES GENERATED 1) +if (CLANG_CL) + set_property(SOURCE ${LLDB_WRAP_PYTHON} APPEND_STRING + PROPERTY COMPILE_FLAGS " -Wno-unused-function") +endif() +if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND + NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") + set_property(SOURCE ${LLDB_WRAP_PYTHON} APPEND_STRING + PROPERTY COMPILE_FLAGS " -Wno-sequence-point -Wno-cast-qual") +endif () -# This should not be part of LLDBDependencies.cmake, because we don't -# want every single library taking a dependency on the script interpreters. target_link_libraries(liblldb PRIVATE lldbPluginScriptInterpreterNone lldbPluginScriptInterpreterPython @@ -153,22 +160,45 @@ endif() if (LLDB_WRAP_PYTHON) add_dependencies(liblldb swig_wrapper) endif() -target_link_libraries(liblldb PRIVATE ${LLDB_SYSTEM_LIBS}) if(LLDB_BUILD_FRAMEWORK) - file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h) + file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h + ${LLDB_SOURCE_DIR}/include/lldb/lldb-*.h) + file(GLOB root_public_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-*.h) + file(GLOB root_private_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h) + list(REMOVE_ITEM root_public_headers ${root_private_headers}) + + foreach(header ${public_headers} ${root_public_headers} ${LLDB_SOURCE_DIR}/include/lldb/Utility/SharingPtr.h) + get_filename_component(basename ${header} NAME) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders/${basename} + DEPENDS ${header} + COMMAND ${CMAKE_COMMAND} -E copy ${header} ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders/${basename}) + list(APPEND framework_headers ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders/${basename}) + endforeach() + + add_custom_target(lldb-framework-headers DEPENDS ${framework_headers} + COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.sh ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders ${LLDB_VERSION}) + add_dependencies(liblldb lldb-framework-headers) + set_target_properties(liblldb PROPERTIES OUTPUT_NAME LLDB FRAMEWORK On FRAMEWORK_VERSION ${LLDB_FRAMEWORK_VERSION} LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${LLDB_FRAMEWORK_INSTALL_DIR} - PUBLIC_HEADER "${public_headers}") + PUBLIC_HEADER "${framework_headers}") + + if(NOT IOS) + add_custom_command(TARGET liblldb POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders $<TARGET_FILE_DIR:liblldb>/Headers + COMMAND ${CMAKE_COMMAND} -E create_symlink Versions/Current/Headers ${CMAKE_BINARY_DIR}/${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Headers + COMMAND ${CMAKE_COMMAND} -E create_symlink ${LLDB_FRAMEWORK_VERSION} ${CMAKE_BINARY_DIR}/${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Versions/Current + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/clang/${LLDB_VERSION} $<TARGET_FILE_DIR:liblldb>/Resources/Clang + ) + else() + add_custom_command(TARGET liblldb POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders $<TARGET_FILE_DIR:liblldb>/Headers + ) + endif() - add_custom_command(TARGET liblldb POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:liblldb>/Versions/${LLDB_FRAMEWORK_VERSION} - COMMAND ${CMAKE_COMMAND} -E copy_directory ${LLDB_SOURCE_DIR}/include/lldb/API $<TARGET_FILE_DIR:liblldb>/Headers - COMMAND ${CMAKE_COMMAND} -E create_symlink Versions/Current/Headers ${CMAKE_BINARY_DIR}/${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Headers - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/clang/${LLDB_VERSION} $<TARGET_FILE_DIR:liblldb>/Resources/Clang - ) endif() diff --git a/source/API/SBBreakpoint.cpp b/source/API/SBBreakpoint.cpp index bf9603248d71f..6a0ff9536c2c2 100644 --- a/source/API/SBBreakpoint.cpp +++ b/source/API/SBBreakpoint.cpp @@ -37,6 +37,8 @@ #include "lldb/Utility/Log.h" #include "lldb/Utility/Stream.h" +#include "SBBreakpointOptionCommon.h" + #include "lldb/lldb-enumerations.h" #include "llvm/ADT/STLExtras.h" @@ -44,21 +46,6 @@ using namespace lldb; using namespace lldb_private; -struct CallbackData { - SBBreakpoint::BreakpointHitCallback callback; - void *callback_baton; -}; - -class SBBreakpointCallbackBaton : public TypedBaton<CallbackData> { -public: - SBBreakpointCallbackBaton(SBBreakpoint::BreakpointHitCallback callback, - void *baton) - : TypedBaton(llvm::make_unique<CallbackData>()) { - getItem()->callback = callback; - getItem()->callback_baton = baton; - } -}; - SBBreakpoint::SBBreakpoint() {} SBBreakpoint::SBBreakpoint(const SBBreakpoint &rhs) @@ -264,6 +251,25 @@ const char *SBBreakpoint::GetCondition() { return nullptr; } +void SBBreakpoint::SetAutoContinue(bool auto_continue) { + BreakpointSP bkpt_sp = GetSP(); + if (bkpt_sp) { + std::lock_guard<std::recursive_mutex> guard( + bkpt_sp->GetTarget().GetAPIMutex()); + bkpt_sp->SetAutoContinue(auto_continue); + } +} + +bool SBBreakpoint::GetAutoContinue() { + BreakpointSP bkpt_sp = GetSP(); + if (bkpt_sp) { + std::lock_guard<std::recursive_mutex> guard( + bkpt_sp->GetTarget().GetAPIMutex()); + return bkpt_sp->IsAutoContinue(); + } + return false; +} + uint32_t SBBreakpoint::GetHitCount() const { uint32_t count = 0; BreakpointSP bkpt_sp = GetSP(); @@ -481,37 +487,9 @@ bool SBBreakpoint::GetDescription(SBStream &s, bool include_locations) { return false; } -bool SBBreakpoint::PrivateBreakpointHitCallback(void *baton, - StoppointCallbackContext *ctx, - lldb::user_id_t break_id, - lldb::user_id_t break_loc_id) { - ExecutionContext exe_ctx(ctx->exe_ctx_ref); - BreakpointSP bp_sp( - exe_ctx.GetTargetRef().GetBreakpointList().FindBreakpointByID(break_id)); - if (baton && bp_sp) { - CallbackData *data = (CallbackData *)baton; - lldb_private::Breakpoint *bp = bp_sp.get(); - if (bp && data->callback) { - Process *process = exe_ctx.GetProcessPtr(); - if (process) { - SBProcess sb_process(process->shared_from_this()); - SBThread sb_thread; - SBBreakpointLocation sb_location; - assert(bp_sp); - sb_location.SetLocation(bp_sp->FindLocationByID(break_loc_id)); - Thread *thread = exe_ctx.GetThreadPtr(); - if (thread) - sb_thread.SetThread(thread->shared_from_this()); - - return data->callback(data->callback_baton, sb_process, sb_thread, - sb_location); - } - } - } - return true; // Return true if we should stop at this breakpoint -} - -void SBBreakpoint::SetCallback(BreakpointHitCallback callback, void *baton) { +void SBBreakpoint + ::SetCallback(SBBreakpointHitCallback callback, + void *baton) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); BreakpointSP bkpt_sp = GetSP(); LLDB_LOG(log, "breakpoint = {0}, callback = {1}, baton = {2}", bkpt_sp.get(), @@ -521,7 +499,8 @@ void SBBreakpoint::SetCallback(BreakpointHitCallback callback, void *baton) { std::lock_guard<std::recursive_mutex> guard( bkpt_sp->GetTarget().GetAPIMutex()); BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton)); - bkpt_sp->SetCallback(SBBreakpoint::PrivateBreakpointHitCallback, baton_sp, + bkpt_sp->SetCallback(SBBreakpointCallbackBaton + ::PrivateBreakpointHitCallback, baton_sp, false); } } @@ -580,10 +559,17 @@ bool SBBreakpoint::AddName(const char *new_name) { bkpt_sp->GetTarget().GetAPIMutex()); Status error; // Think I'm just going to swallow the error here, it's // probably more annoying to have to provide it. - return bkpt_sp->AddName(new_name, error); + bkpt_sp->GetTarget().AddNameToBreakpoint(bkpt_sp, new_name, error); + if (error.Fail()) + { + if (log) + log->Printf("Failed to add name: '%s' to breakpoint: %s", + new_name, error.AsCString()); + return false; + } } - return false; + return true; } void SBBreakpoint::RemoveName(const char *name_to_remove) { @@ -594,7 +580,8 @@ void SBBreakpoint::RemoveName(const char *name_to_remove) { if (bkpt_sp) { std::lock_guard<std::recursive_mutex> guard( bkpt_sp->GetTarget().GetAPIMutex()); - bkpt_sp->RemoveName(name_to_remove); + bkpt_sp->GetTarget().RemoveNameFromBreakpoint(bkpt_sp, + ConstString(name_to_remove)); } } diff --git a/source/API/SBBreakpointLocation.cpp b/source/API/SBBreakpointLocation.cpp index dc9c00d8dd57e..99ac0277e7000 100644 --- a/source/API/SBBreakpointLocation.cpp +++ b/source/API/SBBreakpointLocation.cpp @@ -12,6 +12,7 @@ #include "lldb/API/SBDebugger.h" #include "lldb/API/SBDefines.h" #include "lldb/API/SBStream.h" +#include "lldb/API/SBStringList.h" #include "lldb/Breakpoint/Breakpoint.h" #include "lldb/Breakpoint/BreakpointLocation.h" @@ -100,6 +101,16 @@ bool SBBreakpointLocation::IsEnabled() { return false; } +uint32_t SBBreakpointLocation::GetHitCount() { + BreakpointLocationSP loc_sp = GetSP(); + if (loc_sp) { + std::lock_guard<std::recursive_mutex> guard( + loc_sp->GetTarget().GetAPIMutex()); + return loc_sp->GetHitCount(); + } else + return 0; +} + uint32_t SBBreakpointLocation::GetIgnoreCount() { BreakpointLocationSP loc_sp = GetSP(); if (loc_sp) { @@ -138,6 +149,25 @@ const char *SBBreakpointLocation::GetCondition() { return NULL; } +void SBBreakpointLocation::SetAutoContinue(bool auto_continue) { + BreakpointLocationSP loc_sp = GetSP(); + if (loc_sp) { + std::lock_guard<std::recursive_mutex> guard( + loc_sp->GetTarget().GetAPIMutex()); + loc_sp->SetAutoContinue(auto_continue); + } +} + +bool SBBreakpointLocation::GetAutoContinue() { + BreakpointLocationSP loc_sp = GetSP(); + if (loc_sp) { + std::lock_guard<std::recursive_mutex> guard( + loc_sp->GetTarget().GetAPIMutex()); + return loc_sp->IsAutoContinue(); + } + return false; +} + void SBBreakpointLocation::SetScriptCallbackFunction( const char *callback_function_name) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); @@ -185,6 +215,33 @@ SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) { return sb_error; } +void SBBreakpointLocation::SetCommandLineCommands(SBStringList &commands) { + BreakpointLocationSP loc_sp = GetSP(); + if (!loc_sp) + return; + if (commands.GetSize() == 0) + return; + + std::lock_guard<std::recursive_mutex> guard( + loc_sp->GetTarget().GetAPIMutex()); + std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up( + new BreakpointOptions::CommandData(*commands, eScriptLanguageNone)); + + loc_sp->GetLocationOptions()->SetCommandDataCallback(cmd_data_up); +} + +bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) { + BreakpointLocationSP loc_sp = GetSP(); + if (!loc_sp) + return false; + StringList command_list; + bool has_commands = + loc_sp->GetLocationOptions()->GetCommandLineCallbacks(command_list); + if (has_commands) + commands.AppendList(command_list); + return has_commands; +} + void SBBreakpointLocation::SetThreadID(tid_t thread_id) { BreakpointLocationSP loc_sp = GetSP(); if (loc_sp) { diff --git a/source/API/SBBreakpointName.cpp b/source/API/SBBreakpointName.cpp new file mode 100644 index 0000000000000..2205280b9e5f2 --- /dev/null +++ b/source/API/SBBreakpointName.cpp @@ -0,0 +1,685 @@ +//===-- SBBreakpointName.cpp ----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/API/SBBreakpointName.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBError.h" +#include "lldb/API/SBStream.h" +#include "lldb/API/SBStringList.h" +#include "lldb/API/SBTarget.h" + +#include "lldb/Breakpoint/BreakpointName.h" +#include "lldb/Breakpoint/StoppointCallbackContext.h" +#include "lldb/Core/Debugger.h" +#include "lldb/Interpreter/CommandInterpreter.h" +#include "lldb/Interpreter/ScriptInterpreter.h" +#include "lldb/Target/Target.h" +#include "lldb/Target/ThreadSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/Stream.h" + +#include "SBBreakpointOptionCommon.h" + +using namespace lldb; +using namespace lldb_private; + +namespace lldb +{ +class SBBreakpointNameImpl { +public: + SBBreakpointNameImpl(TargetSP target_sp, const char *name) { + if (!name || name[0] == '\0') + return; + m_name.assign(name); + + if (!target_sp) + return; + + m_target_wp = target_sp; + } + + SBBreakpointNameImpl(SBTarget &sb_target, const char *name); + bool operator==(const SBBreakpointNameImpl &rhs); + bool operator!=(const SBBreakpointNameImpl &rhs); + + // For now we take a simple approach and only keep the name, and relook + // up the location when we need it. + + TargetSP GetTarget() const { + return m_target_wp.lock(); + } + + const char *GetName() const { + return m_name.c_str(); + } + + bool IsValid() const { + return !m_name.empty() && m_target_wp.lock(); + } + + lldb_private::BreakpointName *GetBreakpointName() const; + +private: + TargetWP m_target_wp; + std::string m_name; +}; + +SBBreakpointNameImpl::SBBreakpointNameImpl(SBTarget &sb_target, + const char *name) { + if (!name || name[0] == '\0') + return; + m_name.assign(name); + + if (!sb_target.IsValid()) + return; + + TargetSP target_sp = sb_target.GetSP(); + if (!target_sp) + return; + + m_target_wp = target_sp; +} + +bool SBBreakpointNameImpl::operator==(const SBBreakpointNameImpl &rhs) { + return m_name == rhs.m_name && m_target_wp.lock() == rhs.m_target_wp.lock(); +} + +bool SBBreakpointNameImpl::operator!=(const SBBreakpointNameImpl &rhs) { + return m_name != rhs.m_name || m_target_wp.lock() != rhs.m_target_wp.lock(); +} + +lldb_private::BreakpointName *SBBreakpointNameImpl::GetBreakpointName() const { + if (!IsValid()) + return nullptr; + TargetSP target_sp = GetTarget(); + if (!target_sp) + return nullptr; + Status error; + return target_sp->FindBreakpointName(ConstString(m_name), true, error); +} + +} // namespace lldb + +SBBreakpointName::SBBreakpointName() {} + +SBBreakpointName::SBBreakpointName(SBTarget &sb_target, const char *name) +{ + m_impl_up.reset(new SBBreakpointNameImpl(sb_target, name)); + // Call FindBreakpointName here to make sure the name is valid, reset if + // not: + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + m_impl_up.reset(); +} + +SBBreakpointName::SBBreakpointName(SBBreakpoint &sb_bkpt, const char *name) +{ + if (!sb_bkpt.IsValid()) { + m_impl_up.reset(); + return; + } + BreakpointSP bkpt_sp = sb_bkpt.GetSP(); + Target &target = bkpt_sp->GetTarget(); + + m_impl_up.reset(new SBBreakpointNameImpl(target.shared_from_this(), name)); + + // Call FindBreakpointName here to make sure the name is valid, reset if + // not: + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) { + m_impl_up.reset(); + return; + } + + // Now copy over the breakpoint's options: + target.ConfigureBreakpointName(*bp_name, *bkpt_sp->GetOptions(), + BreakpointName::Permissions()); +} + +SBBreakpointName::SBBreakpointName(const SBBreakpointName &rhs) +{ + if (!rhs.m_impl_up) + return; + else + m_impl_up.reset(new SBBreakpointNameImpl(rhs.m_impl_up->GetTarget(), + rhs.m_impl_up->GetName())); +} + +SBBreakpointName::~SBBreakpointName() = default; + +const SBBreakpointName &SBBreakpointName::operator=(const SBBreakpointName &rhs) +{ + if (!rhs.m_impl_up) { + m_impl_up.reset(); + return *this; + } + + m_impl_up.reset(new SBBreakpointNameImpl(rhs.m_impl_up->GetTarget(), + rhs.m_impl_up->GetName())); + return *this; +} + +bool SBBreakpointName::operator==(const lldb::SBBreakpointName &rhs) { + return *m_impl_up.get() == *rhs.m_impl_up.get(); +} + +bool SBBreakpointName::operator!=(const lldb::SBBreakpointName &rhs) { + return *m_impl_up.get() != *rhs.m_impl_up.get(); +} + +bool SBBreakpointName::IsValid() const { + if (!m_impl_up) + return false; + return m_impl_up->IsValid(); +} + +const char *SBBreakpointName::GetName() const { + if (!m_impl_up) + return "<Invalid Breakpoint Name Object>"; + return m_impl_up->GetName(); +} + +void SBBreakpointName::SetEnabled(bool enable) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + + LLDB_LOG(log, "Name: {0} enabled: {1}\n", bp_name->GetName(), enable); + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + bp_name->GetOptions().SetEnabled(enable); +} + +void SBBreakpointName::UpdateName(BreakpointName &bp_name) { + if (!IsValid()) + return; + + TargetSP target_sp = m_impl_up->GetTarget(); + if (!target_sp) + return; + target_sp->ApplyNameToBreakpoints(bp_name); + +} + +bool SBBreakpointName::IsEnabled() { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return false; + + LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + return bp_name->GetOptions().IsEnabled(); +} + +void SBBreakpointName::SetOneShot(bool one_shot) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + + LLDB_LOG(log, "Name: {0} one_shot: {1}\n", bp_name->GetName(), one_shot); + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + bp_name->GetOptions().SetOneShot(one_shot); + UpdateName(*bp_name); +} + +bool SBBreakpointName::IsOneShot() const { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + const BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return false; + + LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + return bp_name->GetOptions().IsOneShot(); +} + +void SBBreakpointName::SetIgnoreCount(uint32_t count) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + + LLDB_LOG(log, "Name: {0} one_shot: {1}\n", bp_name->GetName(), count); + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + bp_name->GetOptions().SetIgnoreCount(count); + UpdateName(*bp_name); +} + +uint32_t SBBreakpointName::GetIgnoreCount() const { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return false; + + LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + return bp_name->GetOptions().GetIgnoreCount(); +} + +void SBBreakpointName::SetCondition(const char *condition) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + + LLDB_LOG(log, "Name: {0} one_shot: {1}\n", bp_name->GetName(), + condition ? condition : "<NULL>"); + + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + bp_name->GetOptions().SetCondition(condition); + UpdateName(*bp_name); +} + +const char *SBBreakpointName::GetCondition() { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return nullptr; + + LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + return bp_name->GetOptions().GetConditionText(); +} + +void SBBreakpointName::SetAutoContinue(bool auto_continue) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + + LLDB_LOG(log, "Name: {0} auto-continue: {1}\n", bp_name->GetName(), auto_continue); + + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + bp_name->GetOptions().SetAutoContinue(auto_continue); + UpdateName(*bp_name); +} + +bool SBBreakpointName::GetAutoContinue() { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return false; + + LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + return bp_name->GetOptions().IsAutoContinue(); +} + +void SBBreakpointName::SetThreadID(tid_t tid) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + + LLDB_LOG(log, "Name: {0} tid: {1:x}\n", bp_name->GetName(), tid); + + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + bp_name->GetOptions().SetThreadID(tid); + UpdateName(*bp_name); +} + +tid_t SBBreakpointName::GetThreadID() { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return LLDB_INVALID_THREAD_ID; + + LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + return bp_name->GetOptions().GetThreadSpec()->GetTID(); +} + +void SBBreakpointName::SetThreadIndex(uint32_t index) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + + LLDB_LOG(log, "Name: {0} thread index: {1}\n", bp_name->GetName(), index); + + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + bp_name->GetOptions().GetThreadSpec()->SetIndex(index); + UpdateName(*bp_name); +} + +uint32_t SBBreakpointName::GetThreadIndex() const { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return LLDB_INVALID_THREAD_ID; + + LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + return bp_name->GetOptions().GetThreadSpec()->GetIndex(); +} + +void SBBreakpointName::SetThreadName(const char *thread_name) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + + LLDB_LOG(log, "Name: {0} thread name: {1}\n", bp_name->GetName(), thread_name); + + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + bp_name->GetOptions().GetThreadSpec()->SetName(thread_name); + UpdateName(*bp_name); +} + +const char *SBBreakpointName::GetThreadName() const { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return nullptr; + + LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + return bp_name->GetOptions().GetThreadSpec()->GetName(); +} + +void SBBreakpointName::SetQueueName(const char *queue_name) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + + LLDB_LOG(log, "Name: {0} queue name: {1}\n", bp_name->GetName(), queue_name); + + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + bp_name->GetOptions().GetThreadSpec()->SetQueueName(queue_name); + UpdateName(*bp_name); +} + +const char *SBBreakpointName::GetQueueName() const { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return nullptr; + + LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + return bp_name->GetOptions().GetThreadSpec()->GetQueueName(); +} + +void SBBreakpointName::SetCommandLineCommands(SBStringList &commands) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + if (commands.GetSize() == 0) + return; + + LLDB_LOG(log, "Name: {0} commands\n", bp_name->GetName()); + + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up( + new BreakpointOptions::CommandData(*commands, eScriptLanguageNone)); + + bp_name->GetOptions().SetCommandDataCallback(cmd_data_up); + UpdateName(*bp_name); +} + +bool SBBreakpointName::GetCommandLineCommands(SBStringList &commands) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return false; + + LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); + StringList command_list; + bool has_commands = + bp_name->GetOptions().GetCommandLineCallbacks(command_list); + if (has_commands) + commands.AppendList(command_list); + return has_commands; +} + +const char *SBBreakpointName::GetHelpString() const { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return ""; + + LLDB_LOG(log, "Help: {0}\n", bp_name->GetHelp()); + return bp_name->GetHelp(); +} + +void SBBreakpointName::SetHelpString(const char *help_string) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + + LLDB_LOG(log, "Name: {0} help: {1}\n", bp_name->GetName(), help_string); + + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + bp_name->SetHelp(help_string); +} + +bool SBBreakpointName::GetDescription(SBStream &s) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + { + s.Printf("No value"); + return false; + } + + LLDB_LOG(log, "Name: {0}\n", bp_name->GetName()); + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + bp_name->GetDescription(s.get(), eDescriptionLevelFull); + return true; +} + +void SBBreakpointName::SetCallback(SBBreakpointHitCallback callback, + void *baton) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + LLDB_LOG(log, "callback = {1}, baton = {2}", callback, baton); + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton)); + bp_name->GetOptions().SetCallback(SBBreakpointCallbackBaton + ::PrivateBreakpointHitCallback, + baton_sp, + false); + UpdateName(*bp_name); +} + +void SBBreakpointName::SetScriptCallbackFunction( + const char *callback_function_name) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + + LLDB_LOG(log, "Name: {0} callback: {1}\n", bp_name->GetName(), + callback_function_name); + + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + BreakpointOptions &bp_options = bp_name->GetOptions(); + m_impl_up->GetTarget() + ->GetDebugger() + .GetCommandInterpreter() + .GetScriptInterpreter() + ->SetBreakpointCommandCallbackFunction(&bp_options, + callback_function_name); + UpdateName(*bp_name); +} + +SBError SBBreakpointName::SetScriptCallbackBody(const char *callback_body_text) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + SBError sb_error; + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return sb_error; + + LLDB_LOG(log, "Name: {0} callback: {1}\n", bp_name->GetName(), + callback_body_text); + + std::lock_guard<std::recursive_mutex> guard( + m_impl_up->GetTarget()->GetAPIMutex()); + + BreakpointOptions &bp_options = bp_name->GetOptions(); + Status error = + m_impl_up->GetTarget() + ->GetDebugger() + .GetCommandInterpreter() + .GetScriptInterpreter() + ->SetBreakpointCommandCallback(&bp_options, callback_body_text); + sb_error.SetError(error); + if (!sb_error.Fail()) + UpdateName(*bp_name); + + return sb_error; +} + +bool SBBreakpointName::GetAllowList() const +{ + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return false; + return bp_name->GetPermissions().GetAllowList(); +} + +void SBBreakpointName::SetAllowList(bool value) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + if (log) + log->Printf("Setting allow list to %u for %s.", value, + bp_name->GetName().AsCString()); + bp_name->GetPermissions().SetAllowList(value); +} + +bool SBBreakpointName::GetAllowDelete() +{ + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return false; + return bp_name->GetPermissions().GetAllowDelete(); +} + +void SBBreakpointName::SetAllowDelete(bool value) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + if (log) + log->Printf("Setting allow delete to %u for %s.", value, + bp_name->GetName().AsCString()); + bp_name->GetPermissions().SetAllowDelete(value); +} + +bool SBBreakpointName::GetAllowDisable() +{ + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return false; + return bp_name->GetPermissions().GetAllowDisable(); +} + +void SBBreakpointName::SetAllowDisable(bool value) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + BreakpointName *bp_name = GetBreakpointName(); + if (!bp_name) + return; + if (log) + log->Printf("Setting allow disable to %u for %s.", value, + bp_name->GetName().AsCString()); + bp_name->GetPermissions().SetAllowDisable(value); +} + +lldb_private::BreakpointName *SBBreakpointName::GetBreakpointName() const +{ + if (!IsValid()) + return nullptr; + return m_impl_up->GetBreakpointName(); +} + diff --git a/source/API/SBBreakpointOptionCommon.cpp b/source/API/SBBreakpointOptionCommon.cpp new file mode 100644 index 0000000000000..569b860a4235a --- /dev/null +++ b/source/API/SBBreakpointOptionCommon.cpp @@ -0,0 +1,85 @@ +//===-- SBBreakpointName.cpp ----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/API/SBBreakpointName.h" +#include "lldb/API/SBBreakpointLocation.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBEvent.h" +#include "lldb/API/SBProcess.h" +#include "lldb/API/SBStream.h" +#include "lldb/API/SBStringList.h" +#include "lldb/API/SBThread.h" + +#include "lldb/Breakpoint/BreakpointName.h" +#include "lldb/Breakpoint/StoppointCallbackContext.h" +#include "lldb/Core/Address.h" +#include "lldb/Core/Debugger.h" +#include "lldb/Core/StreamFile.h" +#include "lldb/Interpreter/CommandInterpreter.h" +#include "lldb/Interpreter/ScriptInterpreter.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/Target.h" +#include "lldb/Target/Thread.h" +#include "lldb/Target/ThreadSpec.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/Stream.h" + +#include "lldb/lldb-enumerations.h" + +#include "SBBreakpointOptionCommon.h" + +#include "llvm/ADT/STLExtras.h" + +using namespace lldb; +using namespace lldb_private; + +SBBreakpointCallbackBaton::SBBreakpointCallbackBaton(SBBreakpointHitCallback + callback, + void *baton) + : TypedBaton(llvm::make_unique<CallbackData>()) { + getItem()->callback = callback; + getItem()->callback_baton = baton; + } + + bool SBBreakpointCallbackBaton::PrivateBreakpointHitCallback(void *baton, + StoppointCallbackContext *ctx, + lldb::user_id_t break_id, + lldb::user_id_t break_loc_id) +{ + ExecutionContext exe_ctx(ctx->exe_ctx_ref); + BreakpointSP bp_sp( + exe_ctx.GetTargetRef().GetBreakpointList().FindBreakpointByID(break_id)); + if (baton && bp_sp) { + CallbackData *data = (CallbackData *)baton; + lldb_private::Breakpoint *bp = bp_sp.get(); + if (bp && data->callback) { + Process *process = exe_ctx.GetProcessPtr(); + if (process) { + SBProcess sb_process(process->shared_from_this()); + SBThread sb_thread; + SBBreakpointLocation sb_location; + assert(bp_sp); + sb_location.SetLocation(bp_sp->FindLocationByID(break_loc_id)); + Thread *thread = exe_ctx.GetThreadPtr(); + if (thread) + sb_thread.SetThread(thread->shared_from_this()); + + return data->callback(data->callback_baton, sb_process, sb_thread, + sb_location); + } + } + } + return true; // Return true if we should stop at this breakpoint +} + +SBBreakpointCallbackBaton::~SBBreakpointCallbackBaton() = default; diff --git a/source/API/SBBreakpointOptionCommon.h b/source/API/SBBreakpointOptionCommon.h new file mode 100644 index 0000000000000..fe276ac636fef --- /dev/null +++ b/source/API/SBBreakpointOptionCommon.h @@ -0,0 +1,37 @@ +//===-- SBBreakpointOptionCommon.h ------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_SBBreakpointOptionCommons_h_ +#define LLDB_SBBreakpointOptionCommons_h_ + +#include "lldb/API/SBDefines.h" +#include "lldb/Utility/Baton.h" + +namespace lldb +{ +struct CallbackData { + SBBreakpointHitCallback callback; + void *callback_baton; +}; + +class SBBreakpointCallbackBaton : public lldb_private::TypedBaton<CallbackData> { +public: + SBBreakpointCallbackBaton(SBBreakpointHitCallback callback, + void *baton); + + ~SBBreakpointCallbackBaton(); + + static bool PrivateBreakpointHitCallback(void *baton, + lldb_private::StoppointCallbackContext *ctx, + lldb::user_id_t break_id, + lldb::user_id_t break_loc_id); +}; + +} // namespace lldb +#endif // LLDB_SBBreakpointOptionCommons_h_ diff --git a/source/API/SBCommandInterpreter.cpp b/source/API/SBCommandInterpreter.cpp index aa4953999b84e..c9bb8f65fa2e9 100644 --- a/source/API/SBCommandInterpreter.cpp +++ b/source/API/SBCommandInterpreter.cpp @@ -161,6 +161,10 @@ bool SBCommandInterpreter::IsActive() { return (IsValid() ? m_opaque_ptr->IsActive() : false); } +bool SBCommandInterpreter::WasInterrupted() const { + return (IsValid() ? m_opaque_ptr->WasInterrupted() : false); +} + const char *SBCommandInterpreter::GetIOHandlerControlSequence(char ch) { return (IsValid() ? m_opaque_ptr->GetDebugger() diff --git a/source/API/SBDebugger.cpp b/source/API/SBDebugger.cpp index 3cdb6bbfd5f99..d3294dab582de 100644 --- a/source/API/SBDebugger.cpp +++ b/source/API/SBDebugger.cpp @@ -26,6 +26,7 @@ #include "lldb/API/SBSourceManager.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBStringList.h" +#include "lldb/API/SBStructuredData.h" #include "lldb/API/SBTarget.h" #include "lldb/API/SBThread.h" #include "lldb/API/SBTypeCategory.h" @@ -37,8 +38,10 @@ #include "lldb/API/SystemInitializerFull.h" #include "lldb/Core/Debugger.h" +#include "lldb/Core/PluginManager.h" #include "lldb/Core/State.h" #include "lldb/Core/StreamFile.h" +#include "lldb/Core/StructuredDataImpl.h" #include "lldb/DataFormatters/DataVisualization.h" #include "lldb/Initialization/SystemLifetimeManager.h" #include "lldb/Interpreter/Args.h" @@ -69,7 +72,7 @@ static llvm::sys::DynamicLibrary LoadPlugin(const lldb::DebuggerSP &debugger_sp, // TODO: mangle this differently for your system - on OSX, the first // underscore needs to be removed and the second one stays LLDBCommandPluginInit init_func = - (LLDBCommandPluginInit)dynlib.getAddressOfSymbol( + (LLDBCommandPluginInit)(uintptr_t)dynlib.getAddressOfSymbol( "_ZN4lldb16PluginInitializeENS_10SBDebuggerE"); if (init_func) { if (init_func(debugger_sb)) @@ -619,6 +622,20 @@ SBTarget SBDebugger::CreateTarget(const char *filename) { return sb_target; } +SBTarget SBDebugger::GetDummyTarget() { + SBTarget sb_target; + if (m_opaque_sp) { + sb_target.SetSP(m_opaque_sp->GetDummyTarget()->shared_from_this()); + } + Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf( + "SBDebugger(%p)::GetDummyTarget() => SBTarget(%p)", + static_cast<void *>(m_opaque_sp.get()), + static_cast<void *>(sb_target.GetSP().get())); + return sb_target; +} + bool SBDebugger::DeleteTarget(lldb::SBTarget &target) { bool result = false; if (m_opaque_sp) { @@ -677,8 +694,8 @@ SBTarget SBDebugger::FindTargetWithFileAndArch(const char *filename, SBTarget sb_target; if (m_opaque_sp && filename && filename[0]) { // No need to lock, the target list is thread safe - ArchSpec arch(arch_name, - m_opaque_sp->GetPlatformList().GetSelectedPlatform().get()); + ArchSpec arch = Platform::GetAugmentedArchSpec( + m_opaque_sp->GetPlatformList().GetSelectedPlatform().get(), arch_name); TargetSP target_sp( m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture( FileSpec(filename, false), arch_name ? &arch : nullptr)); @@ -774,6 +791,67 @@ void SBDebugger::SetSelectedPlatform(SBPlatform &sb_platform) { sb_platform.GetName()); } +uint32_t SBDebugger::GetNumPlatforms() { + if (m_opaque_sp) { + // No need to lock, the platform list is thread safe + return m_opaque_sp->GetPlatformList().GetSize(); + } + return 0; +} + +SBPlatform SBDebugger::GetPlatformAtIndex(uint32_t idx) { + SBPlatform sb_platform; + if (m_opaque_sp) { + // No need to lock, the platform list is thread safe + sb_platform.SetSP(m_opaque_sp->GetPlatformList().GetAtIndex(idx)); + } + return sb_platform; +} + +uint32_t SBDebugger::GetNumAvailablePlatforms() { + uint32_t idx = 0; + while (true) { + if (!PluginManager::GetPlatformPluginNameAtIndex(idx)) { + break; + } + ++idx; + } + // +1 for the host platform, which should always appear first in the list. + return idx + 1; +} + +SBStructuredData SBDebugger::GetAvailablePlatformInfoAtIndex(uint32_t idx) { + SBStructuredData data; + auto platform_dict = llvm::make_unique<StructuredData::Dictionary>(); + llvm::StringRef name_str("name"), desc_str("description"); + + if (idx == 0) { + PlatformSP host_platform_sp(Platform::GetHostPlatform()); + platform_dict->AddStringItem( + name_str, host_platform_sp->GetPluginName().GetStringRef()); + platform_dict->AddStringItem( + desc_str, llvm::StringRef(host_platform_sp->GetDescription())); + } else if (idx > 0) { + const char *plugin_name = + PluginManager::GetPlatformPluginNameAtIndex(idx - 1); + if (!plugin_name) { + return data; + } + platform_dict->AddStringItem(name_str, llvm::StringRef(plugin_name)); + + const char *plugin_desc = + PluginManager::GetPlatformPluginDescriptionAtIndex(idx - 1); + if (!plugin_desc) { + return data; + } + platform_dict->AddStringItem(desc_str, llvm::StringRef(plugin_desc)); + } + + data.m_impl_up->SetObjectSP( + StructuredData::ObjectSP(platform_dict.release())); + return data; +} + void SBDebugger::DispatchInput(void *baton, const void *data, size_t data_len) { DispatchInput(data, data_len); } diff --git a/source/API/SBInstruction.cpp b/source/API/SBInstruction.cpp index 8b7deb7011be7..1cca8db2afe8d 100644 --- a/source/API/SBInstruction.cpp +++ b/source/API/SBInstruction.cpp @@ -14,15 +14,15 @@ #include "lldb/API/SBInstruction.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBTarget.h" - -#include "lldb/Core/ArchSpec.h" #include "lldb/Core/Disassembler.h" #include "lldb/Core/EmulateInstruction.h" #include "lldb/Core/Module.h" #include "lldb/Core/StreamFile.h" +#include "lldb/Host/HostInfo.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/ArchSpec.h" #include "lldb/Utility/DataBufferHeap.h" #include "lldb/Utility/DataExtractor.h" @@ -259,8 +259,7 @@ bool SBInstruction::EmulateWithFrame(lldb::SBFrame &frame, bool SBInstruction::DumpEmulation(const char *triple) { lldb::InstructionSP inst_sp(GetOpaque()); if (inst_sp && triple) { - lldb_private::ArchSpec arch(triple, NULL); - return inst_sp->DumpEmulation(arch); + return inst_sp->DumpEmulation(HostInfo::GetAugmentedArchSpec(triple)); } return false; } diff --git a/source/API/SBPlatform.cpp b/source/API/SBPlatform.cpp index 87cbc4537a3c8..7ec43f13021f3 100644 --- a/source/API/SBPlatform.cpp +++ b/source/API/SBPlatform.cpp @@ -12,11 +12,11 @@ #include "lldb/API/SBFileSpec.h" #include "lldb/API/SBLaunchInfo.h" #include "lldb/API/SBUnixSignals.h" -#include "lldb/Core/ArchSpec.h" #include "lldb/Host/File.h" #include "lldb/Interpreter/Args.h" #include "lldb/Target/Platform.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/ArchSpec.h" #include "lldb/Utility/Status.h" #include "llvm/Support/FileSystem.h" diff --git a/source/API/SBProcess.cpp b/source/API/SBProcess.cpp index caf07dbe3ce88..e08a7f4b08e0b 100644 --- a/source/API/SBProcess.cpp +++ b/source/API/SBProcess.cpp @@ -1369,3 +1369,13 @@ lldb::SBMemoryRegionInfoList SBProcess::GetMemoryRegions() { } return sb_region_list; } + +lldb::SBProcessInfo SBProcess::GetProcessInfo() { + lldb::SBProcessInfo sb_proc_info; + ProcessSP process_sp(GetSP()); + ProcessInstanceInfo proc_info; + if (process_sp && process_sp->GetProcessInfo(proc_info)) { + sb_proc_info.SetProcessInfo(proc_info); + } + return sb_proc_info; +} diff --git a/source/API/SBProcessInfo.cpp b/source/API/SBProcessInfo.cpp new file mode 100644 index 0000000000000..38f6c1d1e699d --- /dev/null +++ b/source/API/SBProcessInfo.cpp @@ -0,0 +1,145 @@ +//===-- SBProcessInfo.cpp ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/API/SBProcessInfo.h" + +#include "lldb/API/SBFileSpec.h" +#include "lldb/Target/Process.h" + +using namespace lldb; +using namespace lldb_private; + +SBProcessInfo::SBProcessInfo() : m_opaque_ap() {} + +SBProcessInfo::SBProcessInfo(const SBProcessInfo &rhs) : m_opaque_ap() { + if (rhs.IsValid()) { + ref() = *rhs.m_opaque_ap; + } +} + +SBProcessInfo::~SBProcessInfo() {} + +SBProcessInfo &SBProcessInfo::operator=(const SBProcessInfo &rhs) { + if (this != &rhs) { + if (rhs.IsValid()) + ref() = *rhs.m_opaque_ap; + else + m_opaque_ap.reset(); + } + return *this; +} + +ProcessInstanceInfo &SBProcessInfo::ref() { + if (m_opaque_ap.get() == nullptr) { + m_opaque_ap.reset(new ProcessInstanceInfo()); + } + return *m_opaque_ap; +} + +void SBProcessInfo::SetProcessInfo(const ProcessInstanceInfo &proc_info_ref) { + ref() = proc_info_ref; +} + +bool SBProcessInfo::IsValid() const { return m_opaque_ap.get() != nullptr; } + +const char *SBProcessInfo::GetName() { + const char *name = nullptr; + if (m_opaque_ap) { + name = m_opaque_ap->GetName(); + } + return name; +} + +SBFileSpec SBProcessInfo::GetExecutableFile() { + SBFileSpec file_spec; + if (m_opaque_ap) { + file_spec.SetFileSpec(m_opaque_ap->GetExecutableFile()); + } + return file_spec; +} + +lldb::pid_t SBProcessInfo::GetProcessID() { + lldb::pid_t proc_id = LLDB_INVALID_PROCESS_ID; + if (m_opaque_ap) { + proc_id = m_opaque_ap->GetProcessID(); + } + return proc_id; +} + +uint32_t SBProcessInfo::GetUserID() { + uint32_t user_id = UINT32_MAX; + if (m_opaque_ap) { + user_id = m_opaque_ap->GetUserID(); + } + return user_id; +} + +uint32_t SBProcessInfo::GetGroupID() { + uint32_t group_id = UINT32_MAX; + if (m_opaque_ap) { + group_id = m_opaque_ap->GetGroupID(); + } + return group_id; +} + +bool SBProcessInfo::UserIDIsValid() { + bool is_valid = false; + if (m_opaque_ap) { + is_valid = m_opaque_ap->UserIDIsValid(); + } + return is_valid; +} + +bool SBProcessInfo::GroupIDIsValid() { + bool is_valid = false; + if (m_opaque_ap) { + is_valid = m_opaque_ap->GroupIDIsValid(); + } + return is_valid; +} + +uint32_t SBProcessInfo::GetEffectiveUserID() { + uint32_t user_id = UINT32_MAX; + if (m_opaque_ap) { + user_id = m_opaque_ap->GetEffectiveUserID(); + } + return user_id; +} + +uint32_t SBProcessInfo::GetEffectiveGroupID() { + uint32_t group_id = UINT32_MAX; + if (m_opaque_ap) { + group_id = m_opaque_ap->GetEffectiveGroupID(); + } + return group_id; +} + +bool SBProcessInfo::EffectiveUserIDIsValid() { + bool is_valid = false; + if (m_opaque_ap) { + is_valid = m_opaque_ap->EffectiveUserIDIsValid(); + } + return is_valid; +} + +bool SBProcessInfo::EffectiveGroupIDIsValid() { + bool is_valid = false; + if (m_opaque_ap) { + is_valid = m_opaque_ap->EffectiveGroupIDIsValid(); + } + return is_valid; +} + +lldb::pid_t SBProcessInfo::GetParentProcessID() { + lldb::pid_t proc_id = LLDB_INVALID_PROCESS_ID; + if (m_opaque_ap) { + proc_id = m_opaque_ap->GetParentProcessID(); + } + return proc_id; +} diff --git a/source/API/SBTarget.cpp b/source/API/SBTarget.cpp index c706344ee4a39..2c1c6bcac71b6 100644 --- a/source/API/SBTarget.cpp +++ b/source/API/SBTarget.cpp @@ -31,7 +31,6 @@ #include "lldb/Core/Address.h" #include "lldb/Core/AddressResolver.h" #include "lldb/Core/AddressResolverName.h" -#include "lldb/Core/ArchSpec.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/Disassembler.h" #include "lldb/Core/Module.h" @@ -58,6 +57,7 @@ #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" #include "lldb/Target/TargetList.h" +#include "lldb/Utility/ArchSpec.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/RegularExpression.h" @@ -414,16 +414,6 @@ lldb::SBProcess SBTarget::Attach(SBAttachInfo &sb_attach_info, SBError &error) { return sb_process; } -#if defined(__APPLE__) - -lldb::SBProcess SBTarget::AttachToProcessWithID(SBListener &listener, - ::pid_t pid, - lldb::SBError &error) { - return AttachToProcessWithID(listener, (lldb::pid_t)pid, error); -} - -#endif // #if defined(__APPLE__) - lldb::SBProcess SBTarget::AttachToProcessWithID( SBListener &listener, lldb::pid_t pid, // The process ID to attach to @@ -1097,11 +1087,35 @@ bool SBTarget::FindBreakpointsByName(const char *name, return true; } +void SBTarget::GetBreakpointNames(SBStringList &names) +{ + names.Clear(); + + TargetSP target_sp(GetSP()); + if (target_sp) { + std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); + + std::vector<std::string> name_vec; + target_sp->GetBreakpointNames(name_vec); + for (auto name : name_vec) + names.AppendString(name.c_str()); + } +} + +void SBTarget::DeleteBreakpointName(const char *name) +{ + TargetSP target_sp(GetSP()); + if (target_sp) { + std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); + target_sp->DeleteBreakpointName(ConstString(name)); + } +} + bool SBTarget::EnableAllBreakpoints() { TargetSP target_sp(GetSP()); if (target_sp) { std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); - target_sp->EnableAllBreakpoints(); + target_sp->EnableAllowedBreakpoints(); return true; } return false; @@ -1111,7 +1125,7 @@ bool SBTarget::DisableAllBreakpoints() { TargetSP target_sp(GetSP()); if (target_sp) { std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); - target_sp->DisableAllBreakpoints(); + target_sp->DisableAllowedBreakpoints(); return true; } return false; @@ -1121,7 +1135,7 @@ bool SBTarget::DeleteAllBreakpoints() { TargetSP target_sp(GetSP()); if (target_sp) { std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); - target_sp->RemoveAllBreakpoints(); + target_sp->RemoveAllowedBreakpoints(); return true; } return false; @@ -1428,8 +1442,8 @@ lldb::SBModule SBTarget::AddModule(const char *path, const char *triple, module_spec.GetUUID().SetFromCString(uuid_cstr); if (triple) - module_spec.GetArchitecture().SetTriple(triple, - target_sp->GetPlatform().get()); + module_spec.GetArchitecture() = Platform::GetAugmentedArchSpec( + target_sp->GetPlatform().get(), triple); else module_spec.GetArchitecture() = target_sp->GetArchitecture(); diff --git a/source/API/SBType.cpp b/source/API/SBType.cpp index e2ef07cf5c478..80d48754c89b2 100644 --- a/source/API/SBType.cpp +++ b/source/API/SBType.cpp @@ -415,21 +415,31 @@ uint32_t SBType::GetNumberOfTemplateArguments() { } lldb::SBType SBType::GetTemplateArgumentType(uint32_t idx) { - if (IsValid()) { - TemplateArgumentKind kind = eTemplateArgumentKindNull; - CompilerType template_arg_type = - m_opaque_sp->GetCompilerType(false).GetTemplateArgument(idx, kind); - if (template_arg_type.IsValid()) - return SBType(template_arg_type); + if (!IsValid()) + return SBType(); + + CompilerType type; + switch(GetTemplateArgumentKind(idx)) { + case eTemplateArgumentKindType: + type = m_opaque_sp->GetCompilerType(false).GetTypeTemplateArgument(idx); + break; + case eTemplateArgumentKindIntegral: + type = m_opaque_sp->GetCompilerType(false) + .GetIntegralTemplateArgument(idx) + ->type; + break; + default: + break; } + if (type.IsValid()) + return SBType(type); return SBType(); } lldb::TemplateArgumentKind SBType::GetTemplateArgumentKind(uint32_t idx) { - TemplateArgumentKind kind = eTemplateArgumentKindNull; if (IsValid()) - m_opaque_sp->GetCompilerType(false).GetTemplateArgument(idx, kind); - return kind; + return m_opaque_sp->GetCompilerType(false).GetTemplateArgumentKind(idx); + return eTemplateArgumentKindNull; } SBTypeList::SBTypeList() : m_opaque_ap(new TypeListImpl()) {} diff --git a/source/API/SystemInitializerFull.cpp b/source/API/SystemInitializerFull.cpp index c505f61e42a68..977ebe62353ec 100644 --- a/source/API/SystemInitializerFull.cpp +++ b/source/API/SystemInitializerFull.cpp @@ -42,6 +42,7 @@ #include "Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h" #include "Plugins/ABI/SysV-s390x/ABISysV_s390x.h" #include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h" +#include "Plugins/Architecture/Arm/ArchitectureArm.h" #include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h" #include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h" #include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h" @@ -50,9 +51,9 @@ #include "Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h" #include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h" #include "Plugins/InstrumentationRuntime/ASan/ASanRuntime.h" +#include "Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.h" #include "Plugins/InstrumentationRuntime/TSan/TSanRuntime.h" #include "Plugins/InstrumentationRuntime/UBSan/UBSanRuntime.h" -#include "Plugins/InstrumentationRuntime/MainThreadChecker/MainThreadCheckerRuntime.h" #include "Plugins/JITLoader/GDB/JITLoaderGDB.h" #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" #include "Plugins/Language/Go/GoLanguage.h" @@ -304,6 +305,9 @@ void SystemInitializerFull::Initialize() { ABISysV_mips::Initialize(); ABISysV_mips64::Initialize(); ABISysV_s390x::Initialize(); + + ArchitectureArm::Initialize(); + DisassemblerLLVMC::Initialize(); JITLoaderGDB::Initialize(); |