+++ /dev/null
-//===-- CleanUp.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 liblldb_CleanUp_h_
-#define liblldb_CleanUp_h_
-
-#include "lldb/lldb-public.h"
-#include <functional>
-
-namespace lldb_private {
-
-/// Run a cleanup function on scope exit unless it's explicitly disabled.
-class CleanUp {
- std::function<void()> Clean;
-
-public:
- /// Register a cleanup function which applies \p Func to a list of arguments.
- /// Use caution with arguments which are references: they will be copied.
- template <typename F, typename... Args>
- CleanUp(F &&Func, Args &&... args)
- : Clean(std::bind(std::forward<F>(Func), std::forward<Args>(args)...)) {}
-
- ~CleanUp() {
- if (Clean)
- Clean();
- }
-
- /// Disable the cleanup.
- void disable() { Clean = nullptr; }
-
- // Prevent cleanups from being run more than once.
- DISALLOW_COPY_AND_ASSIGN(CleanUp);
-};
-
-} // namespace lldb_private
-
-#endif // #ifndef liblldb_CleanUp_h_
#include "lldb/Host/ProcessLaunchInfo.h"
#include "lldb/Host/ThreadLauncher.h"
#include "lldb/Utility/ArchSpec.h"
-#include "lldb/Utility/CleanUp.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/DataExtractor.h"
#include "lldb/Utility/Endian.h"
#include "lldb/Utility/StructuredData.h"
#include "lldb/lldb-defines.h"
-#include "llvm/Support/FileSystem.h"
+#include "llvm/ADT/ScopeExit.h"
#include "llvm/Support/Errno.h"
+#include "llvm/Support/FileSystem.h"
#include "../cfcpp/CFCBundle.h"
#include "../cfcpp/CFCMutableArray.h"
}
// Make sure we clean up the posix spawn attributes before exiting this scope.
- CleanUp cleanup_attr(posix_spawnattr_destroy, &attr);
+ auto cleanup_attr =
+ llvm::make_scope_exit([&]() { posix_spawnattr_destroy(&attr); });
sigset_t no_signals;
sigset_t all_signals;
}
// Make sure we clean up the posix file actions before exiting this scope.
- CleanUp cleanup_fileact(posix_spawn_file_actions_destroy, &file_actions);
+ auto cleanup_fileact = llvm::make_scope_exit(
+ [&]() { posix_spawn_file_actions_destroy(&file_actions); });
for (size_t i = 0; i < num_file_actions; ++i) {
const FileAction *launch_file_action =
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Thread.h"
-#include "lldb/Utility/CleanUp.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/StreamString.h"
+#include "llvm/ADT/ScopeExit.h"
using namespace lldb;
using namespace lldb_private;
"for path: %s", utility_error.AsCString());
return LLDB_INVALID_IMAGE_TOKEN;
}
-
+
// Make sure we deallocate the input string memory:
- CleanUp path_cleanup([process, path_addr] {
- process->DeallocateMemory(path_addr);
+ auto path_cleanup = llvm::make_scope_exit([process, path_addr] {
+ // Deallocate the buffer.
+ process->DeallocateMemory(path_addr);
});
-
+
process->WriteMemory(path_addr, path.c_str(), path_len, utility_error);
if (utility_error.Fail()) {
error.SetErrorStringWithFormat("dlopen error: could not write path string:"
}
// Make sure we deallocate the result structure memory
- CleanUp return_cleanup([process, return_addr] {
- process->DeallocateMemory(return_addr);
+ auto return_cleanup = llvm::make_scope_exit([process, return_addr] {
+ // Deallocate the buffer
+ process->DeallocateMemory(return_addr);
});
-
+
// This will be the address of the storage for paths, if we are using them,
// or nullptr to signal we aren't.
lldb::addr_t path_array_addr = 0x0;
- llvm::Optional<CleanUp> path_array_cleanup;
+ llvm::Optional<llvm::detail::scope_exit<std::function<void()>>>
+ path_array_cleanup;
// This is the address to a buffer large enough to hold the largest path
// conjoined with the library name we're passing in. This is a convenience
// to avoid having to call malloc in the dlopen function.
lldb::addr_t buffer_addr = 0x0;
- llvm::Optional<CleanUp> buffer_cleanup;
-
+ llvm::Optional<llvm::detail::scope_exit<std::function<void()>>>
+ buffer_cleanup;
+
// Set the values into our args and write them to the target:
if (paths != nullptr) {
// First insert the paths into the target. This is expected to be a
}
// Make sure we deallocate the paths array.
- path_array_cleanup.emplace([process, path_array_addr] {
- process->DeallocateMemory(path_array_addr);
+ path_array_cleanup.emplace([process, path_array_addr]() {
+ // Deallocate the path array.
+ process->DeallocateMemory(path_array_addr);
});
process->WriteMemory(path_array_addr, path_array.data(),
}
// Make sure we deallocate the buffer memory:
- buffer_cleanup.emplace([process, buffer_addr] {
- process->DeallocateMemory(buffer_addr);
+ buffer_cleanup.emplace([process, buffer_addr]() {
+ // Deallocate the buffer.
+ process->DeallocateMemory(buffer_addr);
});
}
// Make sure we clean up the args structure. We can't reuse it because the
// Platform lives longer than the process and the Platforms don't get a
// signal to clean up cached data when a process goes away.
- CleanUp args_cleanup([do_dlopen_function, &exe_ctx, func_args_addr] {
- do_dlopen_function->DeallocateFunctionResults(exe_ctx, func_args_addr);
- });
-
+ auto args_cleanup =
+ llvm::make_scope_exit([do_dlopen_function, &exe_ctx, func_args_addr] {
+ do_dlopen_function->DeallocateFunctionResults(exe_ctx, func_args_addr);
+ });
+
// Now run the caller:
EvaluateExpressionOptions options;
options.SetExecutionPolicy(eExecutionPolicyAlways);
#include "lldb/Target/TargetList.h"
#include "lldb/Target/ThreadPlanCallFunction.h"
#include "lldb/Utility/Args.h"
-#include "lldb/Utility/CleanUp.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Reproducer.h"
#include "lldb/Utility/State.h"
#include "lldb/Host/Host.h"
#include "lldb/Utility/StringExtractorGDBRemote.h"
+#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/Threading.h"
#include "llvm/Support/raw_ostream.h"
int our_socket = sockets[0];
int gdb_socket = sockets[1];
- CleanUp cleanup_our(close, our_socket);
- CleanUp cleanup_gdb(close, gdb_socket);
+ auto cleanup_our = llvm::make_scope_exit([&]() { close(our_socket); });
+ auto cleanup_gdb = llvm::make_scope_exit([&]() { close(gdb_socket); });
// Don't let any child processes inherit our communication socket
SetCloexecFlag(our_socket);
#ifdef USE_SOCKETPAIR_FOR_LOCAL_CONNECTION
// Our process spawned correctly, we can now set our connection to use
// our end of the socket pair
- cleanup_our.disable();
+ cleanup_our.release();
m_gdb_comm.SetConnection(new ConnectionFileDescriptor(our_socket, true));
#endif
StartAsyncThread();
#include "lldb/Host/Host.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Utility/ArchSpec.h"
-#include "lldb/Utility/CleanUp.h"
#include "lldb/Utility/DataBuffer.h"
#include "lldb/Utility/DataExtractor.h"
#include "lldb/Utility/Endian.h"
#include "lldb/Utility/UUID.h"
#include "mach/machine.h"
+#include "llvm/ADT/ScopeExit.h"
#include "llvm/Support/FileSystem.h"
using namespace lldb;
return {};
// Make sure we close the directory before exiting this scope.
- CleanUp cleanup_dir(closedir, dirp);
+ auto cleanup_dir = llvm::make_scope_exit([&]() { closedir(dirp); });
FileSpec dsym_fspec;
dsym_fspec.GetDirectory().SetCString(path);
#include "lldb/Target/Language.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
-#include "lldb/Utility/CleanUp.h"
#include "lldb/Utility/DataExtractor.h"
#include "lldb/Utility/State.h"
#include "lldb/Utility/StreamString.h"
#include "llvm/ADT/IntervalMap.h"
+#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
return 1;
}
- CleanUp TerminateDebugger([&] { DebuggerLifetime.Terminate(); });
+ auto TerminateDebugger =
+ llvm::make_scope_exit([&] { DebuggerLifetime.Terminate(); });
auto Dbg = lldb_private::Debugger::CreateInstance();
ModuleList::GetGlobalModuleListProperties().SetEnableExternalLookup(false);
OptionsWithRawTest.cpp
ArchSpecTest.cpp
BroadcasterTest.cpp
- CleanUpTest.cpp
ConstStringTest.cpp
CompletionRequestTest.cpp
DataExtractorTest.cpp
+++ /dev/null
-//===-- CleanUpTest.cpp -----------------------------------------*- 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Utility/CleanUp.h"
-#include "gtest/gtest.h"
-
-using namespace lldb_private;
-
-TEST(CleanUpTest, no_args) {
- bool f = false;
- {
- CleanUp cleanup([&] { f = true; });
- }
- ASSERT_TRUE(f);
-}
-
-TEST(CleanUpTest, multiple_args) {
- bool f1 = false;
- bool f2 = false;
- bool f3 = false;
- {
- CleanUp cleanup(
- [](bool arg1, bool *arg2, bool &arg3) {
- ASSERT_FALSE(arg1);
- *arg2 = true;
- arg3 = true;
- },
- f1, &f2, f3);
- }
- ASSERT_TRUE(f2);
- ASSERT_FALSE(f3);
-}
-
-TEST(CleanUpTest, disable) {
- bool f = false;
- {
- CleanUp cleanup([&] { f = true; });
- cleanup.disable();
- }
- ASSERT_FALSE(f);
-}