[Lldb-commits] [PATCH] D139249: [lldb] Add Debugger & ScriptedMetadata reference to Platform::CreateInstance
mib updated this revision to Diff 481842. mib added a reviewer: bulbazord. mib added a comment. Addressed @jingham @bulbazord comments: - Add docstring to swig interface - Add comment on `nullptr` arguments @bulbazord Having a `PlatformSpec` object is a good idea but I don't think it's necessary quite yet since there are only 2 arguments passed to the `Platform::CreateInstance` CHANGES SINCE LAST ACTION https://reviews.llvm.org/D139249/new/ https://reviews.llvm.org/D139249 Files: lldb/bindings/interface/SBPlatform.i lldb/include/lldb/API/SBDebugger.h lldb/include/lldb/API/SBPlatform.h lldb/include/lldb/API/SBStructuredData.h lldb/include/lldb/Interpreter/OptionGroupPlatform.h lldb/include/lldb/Target/Platform.h lldb/include/lldb/lldb-private-interfaces.h lldb/source/API/SBDebugger.cpp lldb/source/API/SBPlatform.cpp lldb/source/Commands/CommandObjectPlatform.cpp lldb/source/Commands/CommandObjectPlatform.h lldb/source/Core/Debugger.cpp lldb/source/Interpreter/OptionGroupPlatform.cpp lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp lldb/source/Plugins/Platform/Android/PlatformAndroid.h lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp lldb/source/Plugins/Platform/Linux/PlatformLinux.h lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.cpp lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.h lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.h lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.h lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp lldb/source/Plugins/Platform/Windows/PlatformWindows.h lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h lldb/source/Target/Platform.cpp lldb/source/Target/Process.cpp lldb/source/Target/Target.cpp lldb/source/Target/TargetList.cpp lldb/unittests/Platform/PlatformTest.cpp Index: lldb/unittests/Platform/PlatformTest.cpp === --- lldb/unittests/Platform/PlatformTest.cpp +++ lldb/unittests/Platform/PlatformTest.cpp @@ -59,7 +59,9 @@ PluginManager::UnregisterPlugin(PlatformThumb::CreateInstance); } - static PlatformSP CreateInstance(bool force, const ArchSpec *arch) { + static PlatformSP CreateInstance(bool force, const ArchSpec *arch, + const Debugger *debugger, + const ScriptedMetadata *metadata) { return std::make_shared(); } Index: lldb/source/Target/TargetList.cpp === --- lldb/source/Target/TargetList.cpp +++ lldb/source/Target/TargetList.cpp @@ -184,8 +184,9 @@ std::vector archs; for (const ModuleSpec &spec : module_specs.ModuleSpecs()) archs.push_back(spec.GetArchitecture()); -if (PlatformSP platform_for_archs_sp = -platform_list.GetOrCreate(archs, {}, candidates)) { +if (PlatformSP platform_for_archs_sp = platform_list.GetOrCreate( +archs, /*process_host_arch = */ {}, candidates, +/*metadata = */ nullptr)) { platform_sp = platform_for_archs_sp; } else if (candidates.empty()) { error.SetErrorString("no matching platforms found for this file"); @@ -218,7 +219,9 @@ if (!prefer_platform_arch && arch.IsValid()) { if (!platform_sp->IsCompatibleArchitecture( arch, {}, ArchSpec::CompatibleMatch, nullptr)) { - platform_sp = platform_list.GetOrCrea
[Lldb-commits] [PATCH] D139250: [lldb] Add ScriptedPlatform python implementation
mib updated this revision to Diff 481844. mib marked 3 inline comments as done. mib added a comment. Address @bulbazord comments CHANGES SINCE LAST ACTION https://reviews.llvm.org/D139250/new/ https://reviews.llvm.org/D139250 Files: lldb/bindings/python/CMakeLists.txt lldb/bindings/python/python-wrapper.swig lldb/examples/python/scripted_process/scripted_platform.py lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h lldb/test/API/functionalities/scripted_platform/my_scripted_platform.py lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp Index: lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp === --- lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp +++ lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp @@ -213,6 +213,12 @@ return python::PythonObject(); } +python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedPlatform( +const char *python_class_name, const char *session_dictionary_name, +const StructuredDataImpl &args_impl, std::string &error_string) { + return python::PythonObject(); +} + python::PythonObject lldb_private::LLDBSWIGPython_CreateFrameRecognizer( const char *python_class_name, const char *session_dictionary_name) { return python::PythonObject(); Index: lldb/test/API/functionalities/scripted_platform/my_scripted_platform.py === --- /dev/null +++ lldb/test/API/functionalities/scripted_platform/my_scripted_platform.py @@ -0,0 +1,38 @@ +import os + +import lldb +from lldb.plugins.scripted_platform import ScriptedPlatform + +class MyScriptedPlatform(ScriptedPlatform): + +def __init__(self, args): +self.processes = {} + +proc = {} +proc['name'] = 'a.out' +proc['arch'] = 'arm64-apple-macosx' +proc['pid'] = 420 +proc['parent'] = 42 +proc['uid'] = 501 +proc['gid'] = 20 +self.processes[420] = proc + +def list_processes(self): +return self.processes + +def get_process_info(self, pid): +return self.processes[pid] + +def launch_process(self, launch_info): +return lldb.SBError() + +def kill_process(self, pid): +return lldb.SBError() + +def __lldb_init_module(debugger, dict): +if not 'SKIP_SCRIPTED_PLATFORM_SELECT' in os.environ: +debugger.HandleCommand( +"platform select scripted-platform -C %s.%s" % (__name__, MyScriptedPlatform.__name__)) +else: +print("Name of the class that will manage the scripted platform: '%s.%s'" +% (__name__, MyScriptedPlatform.__name__)) Index: lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h === --- lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h +++ lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h @@ -105,6 +105,10 @@ const lldb::ProcessSP &process_sp, const StructuredDataImpl &args_impl, std::string &error_string); +python::PythonObject LLDBSwigPythonCreateScriptedPlatform( +const char *python_class_name, const char *session_dictionary_name, +const StructuredDataImpl &args_impl, std::string &error_string); + llvm::Expected LLDBSwigPythonBreakpointCallbackFunction( const char *python_function_name, const char *session_dictionary_name, const lldb::StackFrameSP &sb_frame, Index: lldb/examples/python/scripted_process/scripted_platform.py === --- /dev/null +++ lldb/examples/python/scripted_process/scripted_platform.py @@ -0,0 +1,83 @@ +from abc import ABCMeta, abstractmethod + +import lldb + +class ScriptedPlatform(metaclass=ABCMeta): + +""" +The base class for a scripted platform. + +Most of the base class methods are `@abstractmethod` that need to be +overwritten by the inheriting class. + +DISCLAIMER: THIS INTERFACE IS STILL UNDER DEVELOPMENT AND NOT STABLE. +THE METHODS EXPOSED MIGHT CHANGE IN THE FUTURE. +""" + +processes = None + +@abstractmethod +def __init__(self, args): +""" Construct a scripted platform. + +Args: +args (lldb.SBStructuredData): A Dictionary holding arbitrary +key/value pairs used by the scripted platform. +""" +processes = [] + +@abstractmethod +def list_processes(self): +""" Get a list of processes that can be ran on the platform. + +processes = { +420: { +name: a.out, +arch: aarch64, +pid: 420, +parent_pid: 42 (optional), +uid: 0 (optional), +gid: 0 (optional), +}, +} + +Returns: +Dict: The processes represented as a dictionary, with at least the +
[Lldb-commits] [PATCH] D139251: [lldb/Interpreter] Introduce ScriptedPlatform{, Python}Interface
mib updated this revision to Diff 481848. mib marked 4 inline comments as done. mib added a comment. Address @bulbazord comments CHANGES SINCE LAST ACTION https://reviews.llvm.org/D139251/new/ https://reviews.llvm.org/D139251 Files: lldb/include/lldb/Interpreter/ScriptInterpreter.h lldb/include/lldb/Interpreter/ScriptedPlatformInterface.h lldb/include/lldb/lldb-forward.h lldb/source/Interpreter/ScriptInterpreter.cpp lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h === --- /dev/null +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.h @@ -0,0 +1,42 @@ +//===-- ScriptedPlatformPythonInterface.h ---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H +#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H + +#include "lldb/Host/Config.h" + +#if LLDB_ENABLE_PYTHON + +#include "ScriptedPythonInterface.h" +#include "lldb/Interpreter/ScriptedPlatformInterface.h" + +namespace lldb_private { +class ScriptedPlatformPythonInterface : public ScriptedPlatformInterface, +public ScriptedPythonInterface { +public: + ScriptedPlatformPythonInterface(ScriptInterpreterPythonImpl &interpreter); + + StructuredData::GenericSP + CreatePluginObject(const llvm::StringRef class_name, + ExecutionContext &exe_ctx, + StructuredData::DictionarySP args_sp, + StructuredData::Generic *script_obj = nullptr) override; + + StructuredData::DictionarySP ListProcesses() override; + + StructuredData::DictionarySP GetProcessInfo(lldb::pid_t) override; + + Status LaunchProcess() override; + + Status KillProcess(lldb::pid_t pid) override; +}; +} // namespace lldb_private + +#endif // LLDB_ENABLE_PYTHON +#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp === --- /dev/null +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp @@ -0,0 +1,97 @@ +//===-- ScriptedPlatformPythonInterface.cpp ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "lldb/Host/Config.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/Status.h" +#include "lldb/lldb-enumerations.h" + +#if LLDB_ENABLE_PYTHON + +// LLDB Python header must be included first +#include "lldb-python.h" + +#include "SWIGPythonBridge.h" +#include "ScriptInterpreterPythonImpl.h" +#include "ScriptedPlatformPythonInterface.h" + +using namespace lldb; +using namespace lldb_private; +using namespace lldb_private::python; +using Locker = ScriptInterpreterPythonImpl::Locker; + +ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface( +ScriptInterpreterPythonImpl &interpreter) +: ScriptedPlatformInterface(), ScriptedPythonInterface(interpreter) {} + +StructuredData::GenericSP ScriptedPlatformPythonInterface::CreatePluginObject( +llvm::StringRef class_name, ExecutionContext &exe_ctx, +StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) { + if (class_name.empty()) +return {}; + + StructuredDataImpl args_impl(args_sp); + std::string error_string; + + Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN, + Locker::FreeLock); + + PythonObject ret_val = LLDBSwigPythonCreateScriptedPlatform( + class_name.str().c_str(), m_interpreter.GetDictionaryName(), args_impl, + error_string); + + m_object_instance_sp = + StructuredData::GenericSP(new StructuredPythonObject(std::move(ret_val))); + + return m_object_instance_sp; +} + +StructuredData::DictionarySP ScriptedPlatformPythonInterface::ListProcesses() { + Status error; + StructuredData::DictionarySP dict_sp = + Dispatch("list_processes", error); + + if (!dict_sp || !dict_sp->IsValid() || error.Fail()) { +return ScriptedInterface::Erro
[Lldb-commits] [PATCH] D139740: [lldb] Disable macro redefinition warnings in expression wrapper
Michael137 accepted this revision. Michael137 added a comment. This revision is now accepted and ready to land. LGTM thanks! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D139740/new/ https://reviews.llvm.org/D139740 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D139740: [lldb] Disable macro redefinition warnings in expression wrapper
Michael137 added inline comments. Comment at: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp:150 + stream << "#pragma clang diagnostic push\n"; + stream << "#pragma clang diagnostic ignored \"-Wmacro-redefined\"\n"; + auto pop_warning = llvm::make_scope_exit([&stream](){ You might want to also add `-Wbuiltin-macro-redefined` Just tried this change on my Ubuntu VM with gcc-11 and it gets rid of most diagnostics apart from one: ``` (lldb) p alksjdh error: expression failed to parse: warning: :252:9: redefining builtin macro #define __FLT_EVAL_METHOD__ 0 ^ error: :1:1: use of undeclared identifier 'alksjdh' alksjdh ^ ``` Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D139740/new/ https://reviews.llvm.org/D139740 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 8b5c302 - [lldb] Use std::optional instead of None in comments (NFC)
Author: Kazu Hirata Date: 2022-12-10T17:06:43-08:00 New Revision: 8b5c302efb26634126bb57c20727a13ec2237558 URL: https://github.com/llvm/llvm-project/commit/8b5c302efb26634126bb57c20727a13ec2237558 DIFF: https://github.com/llvm/llvm-project/commit/8b5c302efb26634126bb57c20727a13ec2237558.diff LOG: [lldb] Use std::optional instead of None in comments (NFC) This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716 Added: Modified: lldb/include/lldb/Target/TraceCursor.h lldb/include/lldb/Target/UnixSignals.h lldb/include/lldb/Utility/Predicate.h lldb/include/lldb/Utility/TraceGDBRemotePackets.h lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp lldb/source/Plugins/Process/Linux/IntelPTProcessTrace.h lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.h lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleSaver.cpp lldb/source/Plugins/Trace/intel-pt/TraceIntelPTMultiCpuDecoder.h lldb/source/Plugins/TraceExporter/common/TraceHTR.h lldb/source/Target/TraceDumper.cpp Removed: diff --git a/lldb/include/lldb/Target/TraceCursor.h b/lldb/include/lldb/Target/TraceCursor.h index ee5014f375beb..dfb113fa8b900 100644 --- a/lldb/include/lldb/Target/TraceCursor.h +++ b/lldb/include/lldb/Target/TraceCursor.h @@ -278,7 +278,8 @@ class TraceCursor { /// /// \return /// A string representing some metadata associated with a - /// \a eTraceEventSyncPoint event. \b None if no metadata is available. + /// \a eTraceEventSyncPoint event. \b std::nullopt if no metadata is + /// available. virtual llvm::Optional GetSyncPointMetadata() const = 0; /// \} diff --git a/lldb/include/lldb/Target/UnixSignals.h b/lldb/include/lldb/Target/UnixSignals.h index 34f4e30d13505..6646078d78352 100644 --- a/lldb/include/lldb/Target/UnixSignals.h +++ b/lldb/include/lldb/Target/UnixSignals.h @@ -101,8 +101,8 @@ class UnixSignals { uint64_t GetVersion() const; // Returns a vector of signals that meet criteria provided in arguments. Each - // should_[suppress|stop|notify] flag can be None - no filtering by this - // flag true - only signals that have it set to true are returned false - + // should_[suppress|stop|notify] flag can be std::nullopt - no filtering by + // this flag true - only signals that have it set to true are returned false - // only signals that have it set to true are returned std::vector GetFilteredSignals(llvm::Optional should_suppress, llvm::Optional should_stop, diff --git a/lldb/include/lldb/Utility/Predicate.h b/lldb/include/lldb/Utility/Predicate.h index 3496aff8ee95c..9b65ec1a0094e 100644 --- a/lldb/include/lldb/Utility/Predicate.h +++ b/lldb/include/lldb/Utility/Predicate.h @@ -116,7 +116,8 @@ template class Predicate { /// How long to wait for the condition to hold. /// /// \return - /// m_value if Cond(m_value) is true, None otherwise (timeout occurred). + /// m_value if Cond(m_value) is true, std::nullopt otherwise (timeout + /// occurred). template llvm::Optional WaitFor(C Cond, const Timeout &timeout) { std::unique_lock lock(m_mutex); @@ -177,7 +178,8 @@ template class Predicate { /// How long to wait for the condition to hold. /// /// \return - /// m_value if m_value != value, None otherwise (timeout occurred). + /// m_value if m_value != value, std::nullopt otherwise (timeout + /// occurred). llvm::Optional WaitForValueNotEqualTo(T value, const Timeout &timeout = std::nullopt) { diff --git a/lldb/include/lldb/Utility/TraceGDBRemotePackets.h b/lldb/include/lldb/Utility/TraceGDBRemotePackets.h index bfa68219ab4ef..1b35b051e438e 100644 --- a/lldb/include/lldb/Utility/TraceGDBRemotePackets.h +++ b/lldb/include/lldb/Utility/TraceGDBRemotePackets.h @@ -49,7 +49,7 @@ struct TraceStartRequest { llvm::Optional> tids; /// \return - /// \b true if \a tids is \a None, i.e. whole process tracing. + /// \b true if \a tids is \a std::nullopt, i.e. whole process tracing. bool IsProcessTracing() const; }; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp index 65ad74862467a..36ecc592547e9 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp @@ -46,7 +46,7 @@ getTargetIncludePaths(const llvm::Triple &triple) { } /// Returns the include path matching the given pattern for the given file -/// path (