[Lldb-commits] [lldb] [lldb-dap] Implement a MemoryMonitor (PR #129332)
@@ -0,0 +1,110 @@ +//===-- MemoryMonitor.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/MemoryMonitor.h" +#include "lldb/Host/HostThread.h" +#include "lldb/Host/ThreadLauncher.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" +#include "llvm/ADT/ScopeExit.h" +#include "llvm/Support/Error.h" +#include +#include +#include +#include + +#if defined(__linux__) +#include +#include +#include +#endif + +#if defined(_WIN32) +#include +#include +#endif + +using namespace lldb_private; + +class MemoryMonitorPoll : public MemoryMonitor { +public: + using MemoryMonitor::MemoryMonitor; + + lldb::thread_result_t MonitorThread() { +#if defined(__linux__) +struct pollfd fds; +fds.fd = open("/proc/pressure/memory", O_RDWR | O_NONBLOCK); +if (fds.fd < 0) + return {}; +fds.events = POLLPRI; + +auto cleanup = llvm::make_scope_exit([&]() { close(fds.fd); }); + +// Detect a 50ms stall in a 2 second time window. +const char trig[] = "some 5 200"; +if (write(fds.fd, trig, strlen(trig) + 1) < 0) + return {}; + +while (!m_done) { + int n = poll(&fds, 1, g_timeout); + if (n > 0) { +if (fds.revents & POLLERR) walter-erquinigo wrote: if there's an error, is there a way to restart the loop? https://github.com/llvm/llvm-project/pull/129332 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Implement a MemoryMonitor (PR #129332)
@@ -0,0 +1,110 @@ +//===-- MemoryMonitor.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/MemoryMonitor.h" +#include "lldb/Host/HostThread.h" +#include "lldb/Host/ThreadLauncher.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" +#include "llvm/ADT/ScopeExit.h" +#include "llvm/Support/Error.h" +#include +#include +#include +#include + +#if defined(__linux__) +#include +#include +#include +#endif + +#if defined(_WIN32) +#include +#include +#endif + +using namespace lldb_private; + +class MemoryMonitorPoll : public MemoryMonitor { +public: + using MemoryMonitor::MemoryMonitor; + + lldb::thread_result_t MonitorThread() { +#if defined(__linux__) +struct pollfd fds; walter-erquinigo wrote: do you need to zero out this struct? https://github.com/llvm/llvm-project/pull/129332 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Mach-O] Don't read symbol table of specially marked binary (PR #129967)
https://github.com/jasonmolenda created https://github.com/llvm/llvm-project/pull/129967 We have a binary image on Darwin that has no code, only metadata. It has a large symbol table with many external symbol names that will not be needed in the debugger. And it is possible to not have this binary on the debugger system - so lldb must read all of the symbol names out of memory, one at a time, which can be quite slow. We're adding a section __TEXT,__lldb_no_nlist, to this binary to indicate that lldb should not read the nlist symbols for it when we are reading out of memory. If lldb is run with an on-disk version of the binary, we will load the symbol table as we normally would, there's no benefit to handling this binary differently. I added a test where I create a dylib with this specially named section, launch the process. The main binary deletes the dylib from the disk so lldb is forced to read it out of memory. lldb attaches to the binary, confirms that the dylib is present in the process and is a memory Module. If the binary is not present, or lldb found the on-disk copy because it hasn't been deleted yet, we delete the target, flush the Debugger's module cache, sleep and retry, up to ten times. I create the specially named section by compiling an assembly file that puts a byte in the section which makes for a bit of a messy Makefile (the pre-canned actions to build a dylib don't quite handle this case) but I don't think it's much of a problem. This is a purely skipUnlessDarwin test case. rdar://146167816 >From 6e258eb09b13776fc393a161225438baa92e5f87 Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Wed, 5 Mar 2025 17:27:20 -0800 Subject: [PATCH] [lldb][Mach-O] Don't read symbol table of specially marked binary We have a binary image on Darwin that has no code, only metadata. It has a large symbol table with many external symbol names that will not be needed in the debugger. And it is possible to not have this binary on the debugger system - so lldb must read all of the symbol names out of memory, one at a time, which can be quite slow. We're adding a section __TEXT,__lldb_no_nlist, to this binary to indicate that lldb should not read the nlist symbols for it when we are reading out of memory. If lldb is run with an on-disk version of the binary, we will load the symbol table as we normally would, there's no benefit to handling this binary differently. I added a test where I create a dylib with this specially named section, launch the process. The main binary deletes the dylib from the disk so lldb is forced to read it out of memory. lldb attaches to the binary, confirms that the dylib is present in the process and is a memory Module. If the binary is not present, or lldb found the on-disk copy because it hasn't been deleted yet, we delete the target, flush the Debugger's module cache, sleep and retry, up to ten times. I create the specially named section by compiling an assembly file that puts a byte in the section which makes for a bit of a messy Makefile (the pre-canned actions to build a dylib don't quite handle this case) but I don't think it's much of a problem. This is a purely skipUnlessDarwin test case. rdar://146167816 --- .../ObjectFile/Mach-O/ObjectFileMachO.cpp | 68 +++--- .../ObjectFile/Mach-O/ObjectFileMachO.h | 1 + .../macosx/no-nlist-memory-module/Makefile| 15 .../TestNoNlistsDylib.py | 70 +++ .../API/macosx/no-nlist-memory-module/main.c | 37 ++ .../no-nlist-memory-module/no-nlist-sect.s| 3 + .../macosx/no-nlist-memory-module/no-nlists.c | 3 + 7 files changed, 173 insertions(+), 24 deletions(-) create mode 100644 lldb/test/API/macosx/no-nlist-memory-module/Makefile create mode 100644 lldb/test/API/macosx/no-nlist-memory-module/TestNoNlistsDylib.py create mode 100644 lldb/test/API/macosx/no-nlist-memory-module/main.c create mode 100644 lldb/test/API/macosx/no-nlist-memory-module/no-nlist-sect.s create mode 100644 lldb/test/API/macosx/no-nlist-memory-module/no-nlists.c diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index a19322ff1e263..f31b56b9f81e6 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -918,6 +918,11 @@ ConstString ObjectFileMachO::GetSectionNameEHFrame() { return g_section_name_eh_frame; } +ConstString ObjectFileMachO::GetSectionNameLLDBNoNlist() { + static ConstString g_section_name_lldb_no_nlist("__lldb_no_nlist"); + return g_section_name_lldb_no_nlist; +} + bool ObjectFileMachO::MagicBytesMatch(DataBufferSP data_sp, lldb::addr_t data_offset, lldb::addr_t data_length) { @@ -2394,8 +2399,39 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) { uint32_t memory_module_load_
[Lldb-commits] [lldb] [lldb][Mach-O] Don't read symbol table of specially marked binary (PR #129967)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jason Molenda (jasonmolenda) Changes We have a binary image on Darwin that has no code, only metadata. It has a large symbol table with many external symbol names that will not be needed in the debugger. And it is possible to not have this binary on the debugger system - so lldb must read all of the symbol names out of memory, one at a time, which can be quite slow. We're adding a section __TEXT,__lldb_no_nlist, to this binary to indicate that lldb should not read the nlist symbols for it when we are reading out of memory. If lldb is run with an on-disk version of the binary, we will load the symbol table as we normally would, there's no benefit to handling this binary differently. I added a test where I create a dylib with this specially named section, launch the process. The main binary deletes the dylib from the disk so lldb is forced to read it out of memory. lldb attaches to the binary, confirms that the dylib is present in the process and is a memory Module. If the binary is not present, or lldb found the on-disk copy because it hasn't been deleted yet, we delete the target, flush the Debugger's module cache, sleep and retry, up to ten times. I create the specially named section by compiling an assembly file that puts a byte in the section which makes for a bit of a messy Makefile (the pre-canned actions to build a dylib don't quite handle this case) but I don't think it's much of a problem. This is a purely skipUnlessDarwin test case. rdar://146167816 --- Full diff: https://github.com/llvm/llvm-project/pull/129967.diff 7 Files Affected: - (modified) lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (+44-24) - (modified) lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h (+1) - (added) lldb/test/API/macosx/no-nlist-memory-module/Makefile (+15) - (added) lldb/test/API/macosx/no-nlist-memory-module/TestNoNlistsDylib.py (+70) - (added) lldb/test/API/macosx/no-nlist-memory-module/main.c (+37) - (added) lldb/test/API/macosx/no-nlist-memory-module/no-nlist-sect.s (+3) - (added) lldb/test/API/macosx/no-nlist-memory-module/no-nlists.c (+3) ``diff diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index a19322ff1e263..f31b56b9f81e6 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -918,6 +918,11 @@ ConstString ObjectFileMachO::GetSectionNameEHFrame() { return g_section_name_eh_frame; } +ConstString ObjectFileMachO::GetSectionNameLLDBNoNlist() { + static ConstString g_section_name_lldb_no_nlist("__lldb_no_nlist"); + return g_section_name_lldb_no_nlist; +} + bool ObjectFileMachO::MagicBytesMatch(DataBufferSP data_sp, lldb::addr_t data_offset, lldb::addr_t data_length) { @@ -2394,8 +2399,39 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) { uint32_t memory_module_load_level = eMemoryModuleLoadLevelComplete; bool is_shared_cache_image = IsSharedCacheBinary(); bool is_local_shared_cache_image = is_shared_cache_image && !IsInMemory(); + + ConstString g_segment_name_TEXT = GetSegmentNameTEXT(); + ConstString g_segment_name_DATA = GetSegmentNameDATA(); + ConstString g_segment_name_DATA_DIRTY = GetSegmentNameDATA_DIRTY(); + ConstString g_segment_name_DATA_CONST = GetSegmentNameDATA_CONST(); + ConstString g_segment_name_OBJC = GetSegmentNameOBJC(); + ConstString g_section_name_eh_frame = GetSectionNameEHFrame(); + ConstString g_section_name_lldb_no_nlist = GetSectionNameLLDBNoNlist(); + SectionSP text_section_sp( + section_list->FindSectionByName(g_segment_name_TEXT)); + SectionSP data_section_sp( + section_list->FindSectionByName(g_segment_name_DATA)); SectionSP linkedit_section_sp( section_list->FindSectionByName(GetSegmentNameLINKEDIT())); + SectionSP data_dirty_section_sp( + section_list->FindSectionByName(g_segment_name_DATA_DIRTY)); + SectionSP data_const_section_sp( + section_list->FindSectionByName(g_segment_name_DATA_CONST)); + SectionSP objc_section_sp( + section_list->FindSectionByName(g_segment_name_OBJC)); + SectionSP eh_frame_section_sp; + SectionSP lldb_no_nlist_section_sp; + if (text_section_sp.get()) { +eh_frame_section_sp = text_section_sp->GetChildren().FindSectionByName( +g_section_name_eh_frame); +lldb_no_nlist_section_sp = text_section_sp->GetChildren().FindSectionByName( +g_section_name_lldb_no_nlist); + } else { +eh_frame_section_sp = +section_list->FindSectionByName(g_section_name_eh_frame); +lldb_no_nlist_section_sp = +section_list->FindSectionByName(g_section_name_lldb_no_nlist); + } if (process && m_header.filetype != llvm::MachO::MH_OBJECT && !is_local_shared_cache_image) { @@ -2403,6 +2439,14 @@ v
[Lldb-commits] [lldb] [lldb][Mach-O] Don't read symbol table of specially marked binary (PR #129967)
jasonmolenda wrote: The change to ObjectFileMachO looks a little larger than it really is because i moved the SectionSP initializations ~100 lines earlier in ParseSymtab than they were. I'm scanning for this new section the same way we scan for eh_frame. ObjectFileMachO already had "load level" overrides for reading ObjectFiles out of memory, so it was a one line change to use that mechanism for this specially marked binary, once we'd detected the section. https://github.com/llvm/llvm-project/pull/129967 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation (PR #129733)
jimingham wrote: > > You should complete the module -> symbol_context mutatis mutandis. Other > > than that this seems like the right foundation for adding a user way to > > control the symbol lookups. > > I kept the list of preferred contexts as a `ModuleList` in `IRExecutionUnit`. > That's why I kept `Module` in the name where it applies. It made the > implementation of the lookup easier (because `ModuleList` already has the > symbol lookup APIs that we need). I discuss this a bit more in the PR > description. Let me know what you think Makes sense, the other searches happen earlier on in parsing, so that should be okay. But you still have in a couple of places: void SetPreferredModules(SymbolContextList const &modules) { And then it looks really weird when you iterate over `modules` and pull out `m.module_sp`??? https://github.com/llvm/llvm-project/pull/129733 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Restore the override FD used by the output redirect on stop. (PR #129964)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: John Harrison (ashgti) Changes While running lldb-dap over stdin/stdout the `stdout` and `stderr` FD's are replaced with a pipe that is reading the output to forward to the dap client. During shutdown we were not properly restoring those FDs, which means if any component attempted to write to stderr it would trigger a SIGPIPE due to the pipe being closed during the shutdown process. This can happen if we have an error reported from the `DAP::Loop` call that would then log to stderr, such as an error parsing a malformed DAP message or if lldb-dap crashed and it was trying to write the stack trace to stderr. There is one place we were not handling an `llvm::Error` if there was no logging setup that could trigger this condition. To address this, I updated the OutputRedirector to restore the FD to the prior state when `Stop` is called. --- Full diff: https://github.com/llvm/llvm-project/pull/129964.diff 4 Files Affected: - (modified) lldb/test/API/tools/lldb-dap/io/TestDAP_io.py (+13-12) - (modified) lldb/tools/lldb-dap/DAP.cpp (+7-33) - (modified) lldb/tools/lldb-dap/OutputRedirector.cpp (+29-2) - (modified) lldb/tools/lldb-dap/OutputRedirector.h (+4-1) ``diff diff --git a/lldb/test/API/tools/lldb-dap/io/TestDAP_io.py b/lldb/test/API/tools/lldb-dap/io/TestDAP_io.py index a39bd17ceb3b3..04414cd7a3cdf 100644 --- a/lldb/test/API/tools/lldb-dap/io/TestDAP_io.py +++ b/lldb/test/API/tools/lldb-dap/io/TestDAP_io.py @@ -18,18 +18,19 @@ def cleanup(): # If the process is still alive, terminate it. if process.poll() is None: process.terminate() -stdout_data = process.stdout.read() -stderr_data = process.stderr.read() -print("= STDOUT =") -print(stdout_data) -print("= END =") -print("= STDERR =") -print(stderr_data) -print("= END =") -print("= DEBUG ADAPTER PROTOCOL LOGS =") -with open(log_file_path, "r") as file: -print(file.read()) -print("= END =") +process.wait() +stdout_data = process.stdout.read() +stderr_data = process.stderr.read() +print("= STDOUT =") +print(stdout_data) +print("= END =") +print("= STDERR =") +print(stderr_data) +print("= END =") +print("= DEBUG ADAPTER PROTOCOL LOGS =") +with open(log_file_path, "r") as file: +print(file.read()) +print("= END =") # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index b21b83a79aec7..1f7b25e7c5bcc 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -195,34 +195,16 @@ ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const lldb::break_id_t bp_id) { llvm::Error DAP::ConfigureIO(std::FILE *overrideOut, std::FILE *overrideErr) { in = lldb::SBFile(std::fopen(DEV_NULL, "r"), /*transfer_ownership=*/true); - if (auto Error = out.RedirectTo([this](llvm::StringRef output) { + if (auto Error = out.RedirectTo(overrideOut, [this](llvm::StringRef output) { SendOutput(OutputType::Stdout, output); })) return Error; - if (overrideOut) { -auto fd = out.GetWriteFileDescriptor(); -if (auto Error = fd.takeError()) - return Error; - -if (dup2(*fd, fileno(overrideOut)) == -1) - return llvm::errorCodeToError(llvm::errnoAsErrorCode()); - } - - if (auto Error = err.RedirectTo([this](llvm::StringRef output) { + if (auto Error = err.RedirectTo(overrideErr, [this](llvm::StringRef output) { SendOutput(OutputType::Stderr, output); })) return Error; - if (overrideErr) { -auto fd = err.GetWriteFileDescriptor(); -if (auto Error = fd.takeError()) - return Error; - -if (dup2(*fd, fileno(overrideErr)) == -1) - return llvm::errorCodeToError(llvm::errnoAsErrorCode()); - } - return llvm::Error::success(); } @@ -729,15 +711,11 @@ PacketStatus DAP::GetNextObject(llvm::json::Object &object) { llvm::StringRef json_sref(json); llvm::Expected json_value = llvm::json::parse(json_sref); - if (!json_value) { -auto error = json_value.takeError(); -if (log) { - std::string error_str; - llvm::raw_string_ostream strm(error_str); - strm << error; + if (auto error = json_value.takeError()) { +std::string error_str = llvm::toString(std::move(error)); +if (log) *log << "error: failed to parse JSON: " << error_str << std::endl
[Lldb-commits] [lldb] [lldb-dap] Restore the override FD used by the output redirect on stop. (PR #129964)
https://github.com/ashgti ready_for_review https://github.com/llvm/llvm-project/pull/129964 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Restore the override FD used by the output redirect on stop. (PR #129964)
https://github.com/ashgti created https://github.com/llvm/llvm-project/pull/129964 While running lldb-dap over stdin/stdout the `stdout` and `stderr` FD's are replaced with a pipe that is reading the output to forward to the dap client. During shutdown we were not properly restoring those FDs, which means if any component attempted to write to stderr it would trigger a SIGPIPE due to the pipe being closed during the shutdown process. This can happen if we have an error reported from the `DAP::Loop` call that would then log to stderr, such as an error parsing a malformed DAP message or if lldb-dap crashed and it was trying to write the stack trace to stderr. There is one place we were not handling an `llvm::Error` if there was no logging setup that could trigger this condition. To address this, I updated the OutputRedirector to restore the FD to the prior state when `Stop` is called. >From bcecf0c2aa0d398478734f24a9913cb398167e66 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Thu, 6 Mar 2025 02:05:46 +0100 Subject: [PATCH] [lldb-dap] Restore the override FD used by the output redirect on stop. While running lldb-dap over stdin/stdout the `stdout` and `stderr` FD's are replaced with a pipe that is reading the output to forward to the dap client. During shutdown we were not properly restoring those FDs, which means if any component attempted to write to stderr it would trigger a SIGPIPE due to the pipe being closed during the shutdown process. This can happen if we have an error reported from the `DAP::Loop` call that would then log to stderr, such as an error parsing a malformed DAP message or if lldb-dap crashed and it was trying to write the stack trace to stderr. There is one place we were not handling an `llvm::Error` if there was no logging setup that could trigger this condition. To address this, I updated the OutputRedirector to restore the FD to the prior state when `Stop` is called. --- lldb/test/API/tools/lldb-dap/io/TestDAP_io.py | 25 ++-- lldb/tools/lldb-dap/DAP.cpp | 40 --- lldb/tools/lldb-dap/OutputRedirector.cpp | 31 +- lldb/tools/lldb-dap/OutputRedirector.h| 5 ++- 4 files changed, 53 insertions(+), 48 deletions(-) diff --git a/lldb/test/API/tools/lldb-dap/io/TestDAP_io.py b/lldb/test/API/tools/lldb-dap/io/TestDAP_io.py index a39bd17ceb3b3..04414cd7a3cdf 100644 --- a/lldb/test/API/tools/lldb-dap/io/TestDAP_io.py +++ b/lldb/test/API/tools/lldb-dap/io/TestDAP_io.py @@ -18,18 +18,19 @@ def cleanup(): # If the process is still alive, terminate it. if process.poll() is None: process.terminate() -stdout_data = process.stdout.read() -stderr_data = process.stderr.read() -print("= STDOUT =") -print(stdout_data) -print("= END =") -print("= STDERR =") -print(stderr_data) -print("= END =") -print("= DEBUG ADAPTER PROTOCOL LOGS =") -with open(log_file_path, "r") as file: -print(file.read()) -print("= END =") +process.wait() +stdout_data = process.stdout.read() +stderr_data = process.stderr.read() +print("= STDOUT =") +print(stdout_data) +print("= END =") +print("= STDERR =") +print(stderr_data) +print("= END =") +print("= DEBUG ADAPTER PROTOCOL LOGS =") +with open(log_file_path, "r") as file: +print(file.read()) +print("= END =") # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index b21b83a79aec7..1f7b25e7c5bcc 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -195,34 +195,16 @@ ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const lldb::break_id_t bp_id) { llvm::Error DAP::ConfigureIO(std::FILE *overrideOut, std::FILE *overrideErr) { in = lldb::SBFile(std::fopen(DEV_NULL, "r"), /*transfer_ownership=*/true); - if (auto Error = out.RedirectTo([this](llvm::StringRef output) { + if (auto Error = out.RedirectTo(overrideOut, [this](llvm::StringRef output) { SendOutput(OutputType::Stdout, output); })) return Error; - if (overrideOut) { -auto fd = out.GetWriteFileDescriptor(); -if (auto Error = fd.takeError()) - return Error; - -if (dup2(*fd, fileno(overrideOut)) == -1) - return llvm::errorCodeToError(llvm::errnoAsErrorCode()); - } - - if (auto Error = err.RedirectTo([this](llvm::StringRef output) { + if (aut
[Lldb-commits] [lldb] [lldb] Let languages see all SymbolContexts at once when filtering breakpoints (PR #129937)
https://github.com/felipepiovezan edited https://github.com/llvm/llvm-project/pull/129937 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Let languages see all SymbolContexts at once when filtering breakpoints (PR #129937)
https://github.com/felipepiovezan deleted https://github.com/llvm/llvm-project/pull/129937 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [flang] [lldb] [llvm] [mlir] [polly] [IR] Store Triple in Module (NFC) (PR #129868)
https://github.com/dtcxzyw approved this pull request. LGTM. Thank you! https://github.com/llvm/llvm-project/pull/129868 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Restore the override FD used by the output redirect on stop. (PR #129964)
ashgti wrote: Checking this with: ``` $ echo 'Content-Length: 51\r\n\r\n{"command":"disconnect","seq": 1,"type": "request"' > /tmp/partial_message $ lldb lldb-dap (lldb) process handle -s true SIGPIPE (lldb) process launch -i /tmp/partial_message ``` Without the `LLDBDAP_LOG` env set is how I found the crash and the SIGPIPE write error. It was from logging here https://github.com/llvm/llvm-project/blob/12c5a46c300eedb6cafc68b987abb9c1fa913e96/lldb/tools/lldb-dap/lldb-dap.cpp#L596 https://github.com/llvm/llvm-project/pull/129964 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Mach-O] Don't read symbol table of specially marked binary (PR #129967)
https://github.com/jasonmolenda updated https://github.com/llvm/llvm-project/pull/129967 >From 6e258eb09b13776fc393a161225438baa92e5f87 Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Wed, 5 Mar 2025 17:27:20 -0800 Subject: [PATCH 1/2] [lldb][Mach-O] Don't read symbol table of specially marked binary We have a binary image on Darwin that has no code, only metadata. It has a large symbol table with many external symbol names that will not be needed in the debugger. And it is possible to not have this binary on the debugger system - so lldb must read all of the symbol names out of memory, one at a time, which can be quite slow. We're adding a section __TEXT,__lldb_no_nlist, to this binary to indicate that lldb should not read the nlist symbols for it when we are reading out of memory. If lldb is run with an on-disk version of the binary, we will load the symbol table as we normally would, there's no benefit to handling this binary differently. I added a test where I create a dylib with this specially named section, launch the process. The main binary deletes the dylib from the disk so lldb is forced to read it out of memory. lldb attaches to the binary, confirms that the dylib is present in the process and is a memory Module. If the binary is not present, or lldb found the on-disk copy because it hasn't been deleted yet, we delete the target, flush the Debugger's module cache, sleep and retry, up to ten times. I create the specially named section by compiling an assembly file that puts a byte in the section which makes for a bit of a messy Makefile (the pre-canned actions to build a dylib don't quite handle this case) but I don't think it's much of a problem. This is a purely skipUnlessDarwin test case. rdar://146167816 --- .../ObjectFile/Mach-O/ObjectFileMachO.cpp | 68 +++--- .../ObjectFile/Mach-O/ObjectFileMachO.h | 1 + .../macosx/no-nlist-memory-module/Makefile| 15 .../TestNoNlistsDylib.py | 70 +++ .../API/macosx/no-nlist-memory-module/main.c | 37 ++ .../no-nlist-memory-module/no-nlist-sect.s| 3 + .../macosx/no-nlist-memory-module/no-nlists.c | 3 + 7 files changed, 173 insertions(+), 24 deletions(-) create mode 100644 lldb/test/API/macosx/no-nlist-memory-module/Makefile create mode 100644 lldb/test/API/macosx/no-nlist-memory-module/TestNoNlistsDylib.py create mode 100644 lldb/test/API/macosx/no-nlist-memory-module/main.c create mode 100644 lldb/test/API/macosx/no-nlist-memory-module/no-nlist-sect.s create mode 100644 lldb/test/API/macosx/no-nlist-memory-module/no-nlists.c diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index a19322ff1e263..f31b56b9f81e6 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -918,6 +918,11 @@ ConstString ObjectFileMachO::GetSectionNameEHFrame() { return g_section_name_eh_frame; } +ConstString ObjectFileMachO::GetSectionNameLLDBNoNlist() { + static ConstString g_section_name_lldb_no_nlist("__lldb_no_nlist"); + return g_section_name_lldb_no_nlist; +} + bool ObjectFileMachO::MagicBytesMatch(DataBufferSP data_sp, lldb::addr_t data_offset, lldb::addr_t data_length) { @@ -2394,8 +2399,39 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) { uint32_t memory_module_load_level = eMemoryModuleLoadLevelComplete; bool is_shared_cache_image = IsSharedCacheBinary(); bool is_local_shared_cache_image = is_shared_cache_image && !IsInMemory(); + + ConstString g_segment_name_TEXT = GetSegmentNameTEXT(); + ConstString g_segment_name_DATA = GetSegmentNameDATA(); + ConstString g_segment_name_DATA_DIRTY = GetSegmentNameDATA_DIRTY(); + ConstString g_segment_name_DATA_CONST = GetSegmentNameDATA_CONST(); + ConstString g_segment_name_OBJC = GetSegmentNameOBJC(); + ConstString g_section_name_eh_frame = GetSectionNameEHFrame(); + ConstString g_section_name_lldb_no_nlist = GetSectionNameLLDBNoNlist(); + SectionSP text_section_sp( + section_list->FindSectionByName(g_segment_name_TEXT)); + SectionSP data_section_sp( + section_list->FindSectionByName(g_segment_name_DATA)); SectionSP linkedit_section_sp( section_list->FindSectionByName(GetSegmentNameLINKEDIT())); + SectionSP data_dirty_section_sp( + section_list->FindSectionByName(g_segment_name_DATA_DIRTY)); + SectionSP data_const_section_sp( + section_list->FindSectionByName(g_segment_name_DATA_CONST)); + SectionSP objc_section_sp( + section_list->FindSectionByName(g_segment_name_OBJC)); + SectionSP eh_frame_section_sp; + SectionSP lldb_no_nlist_section_sp; + if (text_section_sp.get()) { +eh_frame_section_sp = text_section_sp->GetChildren().FindSectionByName( +g_section_name_eh_frame); +lldb_no_nlist_section_sp =
[Lldb-commits] [lldb] [lldb-dap] Updating the logging of lldb-dap to use existing LLDBLog. (PR #129294)
https://github.com/ashgti closed https://github.com/llvm/llvm-project/pull/129294 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Split test to avoid timeout (PR #129614)
@@ -5,9 +5,9 @@ lldb-server tests run where the lldb-server exe is available. -This class will be broken into smaller test case classes by -gdb remote packet functional areas. For now it contains -the initial set of tests implemented. +The tests are split between the LldbGdbServerTestCase and +LldbGdbServerTestCase2 classes to avoid timeouts in the +test suite. DavidSpickett wrote: Maybe expand this so folks don't get the wrong idea in future. Perhaps: "lit's timeout applies to the whole file, rather than each test_ method, so these tests are split between" https://github.com/llvm/llvm-project/pull/129614 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] fc7482e - [lldb-dap] Return a std::optional from GetBoolean (NFC) (#129818)
Author: Jonas Devlieghere Date: 2025-03-04T23:17:42-08:00 New Revision: fc7482e369cc5aae0e2c4d7082ab8bc060a0bc3c URL: https://github.com/llvm/llvm-project/commit/fc7482e369cc5aae0e2c4d7082ab8bc060a0bc3c DIFF: https://github.com/llvm/llvm-project/commit/fc7482e369cc5aae0e2c4d7082ab8bc060a0bc3c.diff LOG: [lldb-dap] Return a std::optional from GetBoolean (NFC) (#129818) Return a std::optional from GetBoolean so you can distinguish between the value not being present and it being explicitly set to true or false. All existing uses are replaced by calling `value_or(fail_value`). Motivated by #129753 Added: Modified: lldb/tools/lldb-dap/DAP.cpp lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp lldb/tools/lldb-dap/Handler/DisconnectRequestHandler.cpp lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp lldb/tools/lldb-dap/Handler/LaunchRequestHandler.cpp lldb/tools/lldb-dap/Handler/RequestHandler.cpp lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp lldb/tools/lldb-dap/Handler/VariablesRequestHandler.cpp lldb/tools/lldb-dap/JSONUtils.cpp lldb/tools/lldb-dap/JSONUtils.h Removed: diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index 3dc9d6f5ca0a4..c4790414f64f9 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -787,7 +787,7 @@ bool DAP::HandleObject(const llvm::json::Object &object) { response_handler = std::make_unique("", id); // Result should be given, use null if not. -if (GetBoolean(object, "success", false)) { +if (GetBoolean(object, "success").value_or(false)) { llvm::json::Value Result = nullptr; if (auto *B = object.get("body")) { Result = std::move(*B); diff --git a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp index 8b203e0392066..2733f58b74683 100644 --- a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp @@ -61,7 +61,7 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const { GetString(arguments, "gdb-remote-hostname", "localhost"); if (pid != LLDB_INVALID_PROCESS_ID) attach_info.SetProcessID(pid); - const auto wait_for = GetBoolean(arguments, "waitFor", false); + const auto wait_for = GetBoolean(arguments, "waitFor").value_or(false); attach_info.SetWaitForLaunch(wait_for, false /*async*/); dap.init_commands = GetStrings(arguments, "initCommands"); dap.pre_run_commands = GetStrings(arguments, "preRunCommands"); @@ -71,16 +71,17 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const { auto attachCommands = GetStrings(arguments, "attachCommands"); llvm::StringRef core_file = GetString(arguments, "coreFile"); const uint64_t timeout_seconds = GetUnsigned(arguments, "timeout", 30); - dap.stop_at_entry = - core_file.empty() ? GetBoolean(arguments, "stopOnEntry", false) : true; + dap.stop_at_entry = core_file.empty() + ? GetBoolean(arguments, "stopOnEntry").value_or(false) + : true; dap.post_run_commands = GetStrings(arguments, "postRunCommands"); const llvm::StringRef debuggerRoot = GetString(arguments, "debuggerRoot"); dap.enable_auto_variable_summaries = - GetBoolean(arguments, "enableAutoVariableSummaries", false); + GetBoolean(arguments, "enableAutoVariableSummaries").value_or(false); dap.enable_synthetic_child_debugging = - GetBoolean(arguments, "enableSyntheticChildDebugging", false); + GetBoolean(arguments, "enableSyntheticChildDebugging").value_or(false); dap.display_extended_backtrace = - GetBoolean(arguments, "displayExtendedBacktrace", false); + GetBoolean(arguments, "displayExtendedBacktrace").value_or(false); dap.command_escape_prefix = GetString(arguments, "commandEscapePrefix", "`"); dap.SetFrameFormat(GetString(arguments, "customFrameFormat")); dap.SetThreadFormat(GetString(arguments, "customThreadFormat")); diff --git a/lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp index 4c2690d32d3b2..d6ff2a7fd8880 100644 --- a/lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp @@ -123,7 +123,8 @@ void DisassembleRequestHandler::operator()( return; } - const bool resolveSymbols = GetBoolean(arguments, "resolveSymbols", false); + const bool resolveSymbols = + GetBoolean(arguments, "resolveSymbols").value_or(false); llvm::json::Array instructions; const auto num_insts = insts.GetSize(); for (size_t i = 0; i < num_insts; ++i) { diff --git a/lldb/tools/lldb-dap/Handler/DisconnectRequestHandler.cpp b/lldb/tool
[Lldb-commits] [lldb] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation (PR #129733)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/129733 >From da950b7a55c8ee0a35bcfb7e3565fbc11095ab6e Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Tue, 4 Mar 2025 16:14:59 + Subject: [PATCH 1/2] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation --- .../include/lldb/Expression/IRExecutionUnit.h | 6 + lldb/include/lldb/Target/Target.h | 10 lldb/source/Expression/IRExecutionUnit.cpp| 25 ++- .../Clang/ClangExpressionParser.cpp | 3 +++ .../MemoryHistory/asan/MemoryHistoryASan.cpp | 15 +++ 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/lldb/include/lldb/Expression/IRExecutionUnit.h b/lldb/include/lldb/Expression/IRExecutionUnit.h index 58f12bf8b64f5..a0978f9f5063d 100644 --- a/lldb/include/lldb/Expression/IRExecutionUnit.h +++ b/lldb/include/lldb/Expression/IRExecutionUnit.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "llvm/ExecutionEngine/SectionMemoryManager.h" @@ -161,6 +162,10 @@ class IRExecutionUnit : public std::enable_shared_from_this, return m_jitted_global_variables; } + void SetPreferredModules(std::unordered_set modules) { +m_preferred_modules = std::move(modules); + } + private: /// Look up the object in m_address_map that contains a given address, find /// where it was copied to, and return the remote address at the same offset @@ -396,6 +401,7 @@ class IRExecutionUnit : public std::enable_shared_from_this, ///< defining no functions using that variable, would do this.) If this ///< is true, any allocations need to be committed immediately -- no ///< opportunity for relocation. + std::unordered_set m_preferred_modules; }; } // namespace lldb_private diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index f31ac381391b4..369b5633492bb 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -332,6 +332,14 @@ class EvaluateExpressionOptions { m_language = SourceLanguage(language_type); } + void SetPreferredModules(std::unordered_set modules) { +m_preferred_modules = std::move(modules); + } + + const std::unordered_set &GetPreferredModules() const { +return m_preferred_modules; + } + /// Set the language using a pair of language code and version as /// defined by the DWARF 6 specification. /// WARNING: These codes may change until DWARF 6 is finalized. @@ -500,6 +508,8 @@ class EvaluateExpressionOptions { // originates mutable std::string m_pound_line_file; mutable uint32_t m_pound_line_line = 0; + + std::unordered_set m_preferred_modules; }; // Target diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp index c8b4ddf705ec4..8e5f26544c84f 100644 --- a/lldb/source/Expression/IRExecutionUnit.cpp +++ b/lldb/source/Expression/IRExecutionUnit.cpp @@ -52,7 +52,7 @@ IRExecutionUnit::IRExecutionUnit(std::unique_ptr &context_up, m_cpu_features(cpu_features), m_name(name), m_sym_ctx(sym_ctx), m_did_jit(false), m_function_load_addr(LLDB_INVALID_ADDRESS), m_function_end_load_addr(LLDB_INVALID_ADDRESS), - m_reported_allocations(false) {} + m_reported_allocations(false), m_preferred_modules() {} lldb::addr_t IRExecutionUnit::WriteNow(const uint8_t *bytes, size_t size, Status &error) { @@ -785,6 +785,13 @@ IRExecutionUnit::FindInSymbols(const std::vector &names, // We'll process module_sp separately, before the other modules. non_local_images.Remove(sc.module_sp); + ModuleList preferred_images; + // TODO: make m_preferred_modules a ModuleList + for (auto const &m : m_preferred_modules) { +non_local_images.Remove(m); +preferred_images.Append(m); + } + LoadAddressResolver resolver(target, symbol_was_missing_weak); ModuleFunctionSearchOptions function_options; @@ -806,6 +813,14 @@ IRExecutionUnit::FindInSymbols(const std::vector &names, return *load_addr; } +{ + SymbolContextList sc_list; + preferred_images.FindFunctions(name, lldb::eFunctionNameTypeFull, + function_options, sc_list); + if (auto load_addr = resolver.Resolve(sc_list)) +return *load_addr; +} + { SymbolContextList sc_list; non_local_images.FindFunctions(name, lldb::eFunctionNameTypeFull, @@ -822,6 +837,14 @@ IRExecutionUnit::FindInSymbols(const std::vector &names, return *load_addr; } +{ + SymbolContextList sc_list; + preferred_images.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny, + sc_list); + if (auto load_addr = resolver.Resolve(sc_list)) +return *load_addr; +} + { SymbolContextList sc_list; non_local_images.F
[Lldb-commits] [lldb] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation (PR #129733)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/129733 >From da950b7a55c8ee0a35bcfb7e3565fbc11095ab6e Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Tue, 4 Mar 2025 16:14:59 + Subject: [PATCH 1/3] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation --- .../include/lldb/Expression/IRExecutionUnit.h | 6 + lldb/include/lldb/Target/Target.h | 10 lldb/source/Expression/IRExecutionUnit.cpp| 25 ++- .../Clang/ClangExpressionParser.cpp | 3 +++ .../MemoryHistory/asan/MemoryHistoryASan.cpp | 15 +++ 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/lldb/include/lldb/Expression/IRExecutionUnit.h b/lldb/include/lldb/Expression/IRExecutionUnit.h index 58f12bf8b64f5..a0978f9f5063d 100644 --- a/lldb/include/lldb/Expression/IRExecutionUnit.h +++ b/lldb/include/lldb/Expression/IRExecutionUnit.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "llvm/ExecutionEngine/SectionMemoryManager.h" @@ -161,6 +162,10 @@ class IRExecutionUnit : public std::enable_shared_from_this, return m_jitted_global_variables; } + void SetPreferredModules(std::unordered_set modules) { +m_preferred_modules = std::move(modules); + } + private: /// Look up the object in m_address_map that contains a given address, find /// where it was copied to, and return the remote address at the same offset @@ -396,6 +401,7 @@ class IRExecutionUnit : public std::enable_shared_from_this, ///< defining no functions using that variable, would do this.) If this ///< is true, any allocations need to be committed immediately -- no ///< opportunity for relocation. + std::unordered_set m_preferred_modules; }; } // namespace lldb_private diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index f31ac381391b4..369b5633492bb 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -332,6 +332,14 @@ class EvaluateExpressionOptions { m_language = SourceLanguage(language_type); } + void SetPreferredModules(std::unordered_set modules) { +m_preferred_modules = std::move(modules); + } + + const std::unordered_set &GetPreferredModules() const { +return m_preferred_modules; + } + /// Set the language using a pair of language code and version as /// defined by the DWARF 6 specification. /// WARNING: These codes may change until DWARF 6 is finalized. @@ -500,6 +508,8 @@ class EvaluateExpressionOptions { // originates mutable std::string m_pound_line_file; mutable uint32_t m_pound_line_line = 0; + + std::unordered_set m_preferred_modules; }; // Target diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp index c8b4ddf705ec4..8e5f26544c84f 100644 --- a/lldb/source/Expression/IRExecutionUnit.cpp +++ b/lldb/source/Expression/IRExecutionUnit.cpp @@ -52,7 +52,7 @@ IRExecutionUnit::IRExecutionUnit(std::unique_ptr &context_up, m_cpu_features(cpu_features), m_name(name), m_sym_ctx(sym_ctx), m_did_jit(false), m_function_load_addr(LLDB_INVALID_ADDRESS), m_function_end_load_addr(LLDB_INVALID_ADDRESS), - m_reported_allocations(false) {} + m_reported_allocations(false), m_preferred_modules() {} lldb::addr_t IRExecutionUnit::WriteNow(const uint8_t *bytes, size_t size, Status &error) { @@ -785,6 +785,13 @@ IRExecutionUnit::FindInSymbols(const std::vector &names, // We'll process module_sp separately, before the other modules. non_local_images.Remove(sc.module_sp); + ModuleList preferred_images; + // TODO: make m_preferred_modules a ModuleList + for (auto const &m : m_preferred_modules) { +non_local_images.Remove(m); +preferred_images.Append(m); + } + LoadAddressResolver resolver(target, symbol_was_missing_weak); ModuleFunctionSearchOptions function_options; @@ -806,6 +813,14 @@ IRExecutionUnit::FindInSymbols(const std::vector &names, return *load_addr; } +{ + SymbolContextList sc_list; + preferred_images.FindFunctions(name, lldb::eFunctionNameTypeFull, + function_options, sc_list); + if (auto load_addr = resolver.Resolve(sc_list)) +return *load_addr; +} + { SymbolContextList sc_list; non_local_images.FindFunctions(name, lldb::eFunctionNameTypeFull, @@ -822,6 +837,14 @@ IRExecutionUnit::FindInSymbols(const std::vector &names, return *load_addr; } +{ + SymbolContextList sc_list; + preferred_images.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny, + sc_list); + if (auto load_addr = resolver.Resolve(sc_list)) +return *load_addr; +} + { SymbolContextList sc_list; non_local_images.F
[Lldb-commits] [lldb] [lldb] Split test to avoid timeout (PR #129614)
DavidSpickett wrote: Even for a debug build, timeouts aren't a good experience. The sleeps as you say are a minority of the time, and I would rather not disturb them anyway. So I agree with splitting this. How many others are close to the limit that you've found, just this one? https://github.com/llvm/llvm-project/pull/129614 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Fix: disableASLR launch argument not working. (PR #129753)
https://github.com/Da-Viper updated https://github.com/llvm/llvm-project/pull/129753 >From 2f773debb694f5684664ea47e545027aeb6e33db Mon Sep 17 00:00:00 2001 From: Ezike Ebuka Date: Wed, 5 Mar 2025 10:32:16 + Subject: [PATCH] [lldb-dap] Fix: disableASLR launch argument not working. --- .../tools/lldb-dap/Handler/RequestHandler.cpp | 26 ++- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp index d4030965869a1..816397adb26ad 100644 --- a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp @@ -31,7 +31,18 @@ MakeArgv(const llvm::ArrayRef &strs) { return argv; } -// Both attach and launch take a either a sourcePath or sourceMap +static uint32_t SetLaunchFlag(uint32_t flags, const llvm::json::Object *obj, + llvm::StringRef key, lldb::LaunchFlags mask, + bool default_value) { + if (GetBoolean(obj, key).value_or(default_value)) +flags |= mask; + else +flags &= ~mask; + + return flags; +} + +// Both attach and launch take either a sourcePath or a sourceMap // argument (or neither), from which we need to set the target.source-map. void RequestHandler::SetSourceMapFromArguments( const llvm::json::Object &arguments) const { @@ -173,12 +184,13 @@ RequestHandler::LaunchProcess(const llvm::json::Object &request) const { auto flags = launch_info.GetLaunchFlags(); - if (GetBoolean(arguments, "disableASLR").value_or(true)) -flags |= lldb::eLaunchFlagDisableASLR; - if (GetBoolean(arguments, "disableSTDIO").value_or(false)) -flags |= lldb::eLaunchFlagDisableSTDIO; - if (GetBoolean(arguments, "shellExpandArguments").value_or(false)) -flags |= lldb::eLaunchFlagShellExpandArguments; + flags = SetLaunchFlag(flags, arguments, "disableASLR", +lldb::eLaunchFlagDisableASLR, true); + flags = SetLaunchFlag(flags, arguments, "disableSTDIO", +lldb::eLaunchFlagDisableSTDIO, false); + flags = SetLaunchFlag(flags, arguments, "shellExpandArguments", +lldb::eLaunchFlagShellExpandArguments, false); + const bool detachOnError = GetBoolean(arguments, "detachOnError").value_or(false); launch_info.SetDetachOnError(detachOnError); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation (PR #129733)
https://github.com/Michael137 ready_for_review https://github.com/llvm/llvm-project/pull/129733 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation (PR #129733)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) Changes The `TestMemoryHistory.py` is currently failing on the x86 macOS CI. The LLDB ASAN utility expression is failing to run with following error: ``` (lldb) image lookup -n __asan_get_alloc_stack 1 match found in /usr/lib/system/libsystem_sanitizers.dylib: Address: libsystem_sanitizers.dylib[0x7ffd11e673f7] (libsystem_sanitizers.dylib.__TEXT.__text + 11287) Summary: libsystem_sanitizers.dylib`__asan_get_alloc_stack 1 match found in /Users/michaelbuch/Git/lldb-build-main-no-modules/lib/clang/21/lib/darwin/libclang_rt.asan_osx_dynamic.dylib: Address: libclang_rt.asan_osx_dynamic.dylib[0x9ec0] (libclang_rt.asan_osx_dynamic.dylib.__TEXT.__text + 34352) Summary: libclang_rt.asan_osx_dynamic.dylib`::__asan_get_alloc_stack(__sanitizer::uptr, __sanitizer::uptr *, __sanitizer::uptr, __sanitizer::u32 *) at asan_debugging.cpp:132 (lldb) memory history 'pointer' Assertion failed: ((uintptr_t)addr == report.access.address), function __asan_get_alloc_stack, file debugger_abi.cpp, line 62. warning: cannot evaluate AddressSanitizer expression: error: Expression execution was interrupted: signal SIGABRT. The process has been returned to the state before expression evaluation. ``` The reason for this is that the system sanitizer dylib and the locally built libclang_rt contain the same symbol `__asan_get_alloc_stack`, and depending on the order in which they're loaded we pick the one from the wrong dylib. Based on discussion with @wrotki we always want to pick the one that's in the libclang_rt dylib if it was loaded, and libsystem_sanitizers otherwise. This patch addresses this by adding a "preferred lookup context list" to the expression evaluator. Currently this is only exposed in the `EvaluateExpressionOptions`. We make it a `SymbolContextList` in case we want the lookup contexts to be contexts other than modules (e.g., source files, etc.). In `IRExecutionUnit` we make it a `ModuleList` because it makes the symbol lookup implementation simpler and we only do module lookups here anyway. If we ever need it to be a `SymbolContext`, that transformation shouldn't be too difficult. --- Full diff: https://github.com/llvm/llvm-project/pull/129733.diff 5 Files Affected: - (modified) lldb/include/lldb/Expression/IRExecutionUnit.h (+12) - (modified) lldb/include/lldb/Target/Target.h (+14) - (modified) lldb/source/Expression/IRExecutionUnit.cpp (+26-5) - (modified) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (+4) - (modified) lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp (+26) ``diff diff --git a/lldb/include/lldb/Expression/IRExecutionUnit.h b/lldb/include/lldb/Expression/IRExecutionUnit.h index 58f12bf8b64f5..77d53daf80c1b 100644 --- a/lldb/include/lldb/Expression/IRExecutionUnit.h +++ b/lldb/include/lldb/Expression/IRExecutionUnit.h @@ -17,6 +17,7 @@ #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/IR/Module.h" +#include "lldb/Core/ModuleList.h" #include "lldb/Expression/IRMemoryMap.h" #include "lldb/Expression/ObjectFileJIT.h" #include "lldb/Symbol/SymbolContext.h" @@ -161,6 +162,12 @@ class IRExecutionUnit : public std::enable_shared_from_this, return m_jitted_global_variables; } + void SetPreferredModules(SymbolContextList const &modules) { +for (auto const &m : modules) + if (m.module_sp) +m_preferred_modules.Append(m.module_sp); + } + private: /// Look up the object in m_address_map that contains a given address, find /// where it was copied to, and return the remote address at the same offset @@ -396,6 +403,11 @@ class IRExecutionUnit : public std::enable_shared_from_this, ///< defining no functions using that variable, would do this.) If this ///< is true, any allocations need to be committed immediately -- no ///< opportunity for relocation. + + ///< Any Module in this list will be used for symbol/function lookup + ///< before any other module (except for the module corresponding to the + ///< current frame). + ModuleList m_preferred_modules; }; } // namespace lldb_private diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index f31ac381391b4..a4059cdb2a819 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -25,6 +25,7 @@ #include "lldb/Core/UserSettingsController.h" #include "lldb/Expression/Expression.h" #include "lldb/Host/ProcessLaunchInfo.h" +#include "lldb/Symbol/SymbolContext.h" #include "lldb/Symbol/TypeSystem.h" #include "lldb/Target/ExecutionContextScope.h" #include "lldb/Target/PathMappingList.h" @@ -332,6 +333,14 @@ class EvaluateExpressionOptions { m_language = SourceLanguage(language_type); } + void SetPreferredSymbolContexts(SymbolContextList modules) { +m_preferred_lookup_contexts = std::move(modules); + } + + const S
[Lldb-commits] [lldb] Push down the swig module to avoid an import cycle (PR #129135)
dzhidzhoev wrote: > Okay! > > Thank you for reverting! I will run more test and find a solution. It seems that `ScriptInterpreterPython::SharedLibraryDirectoryHelper` can't correctly determine path to liblldb.dll after this change. `SharedLibraryDirectoryHelper("build-lldb\Lib\site-packages\lldb\native\_lldb.cp312-win_amd64.pyd")` returns `build-lldb\Lib\bin\liblldb.dll` instead of `build-lldb\bin\liblldb.dll`. This should help: ``` diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 00d01981c64f..2dc4ad269172 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -310,6 +310,7 @@ void ScriptInterpreterPython::SharedLibraryDirectoryHelper( // does. if (this_file.GetFileNameExtension() == ".pyd") { this_file.RemoveLastPathComponent(); // _lldb.pyd or _lldb_d.pyd +this_file.RemoveLastPathComponent(); // native this_file.RemoveLastPathComponent(); // lldb llvm::StringRef libdir = LLDB_PYTHON_RELATIVE_LIBDIR; for (auto it = llvm::sys::path::begin(libdir), ``` https://github.com/llvm/llvm-project/pull/129135 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 6c4febe - [lldb-dap] Implement a MemoryMonitor (#129332)
Author: Jonas Devlieghere Date: 2025-03-05T08:49:49-08:00 New Revision: 6c4febee2992d206e95e2ed2294fe216739af1cb URL: https://github.com/llvm/llvm-project/commit/6c4febee2992d206e95e2ed2294fe216739af1cb DIFF: https://github.com/llvm/llvm-project/commit/6c4febee2992d206e95e2ed2294fe216739af1cb.diff LOG: [lldb-dap] Implement a MemoryMonitor (#129332) This implements a memory monitor for macOS, Linux and Windows. It registers a callback that invokes `SBDebugger::MemoryPressureDetected` when a low memory event is detected. This is motivated by the new server mode, where the lldb-dap process will live across multiple debug sessions and will use more memory due to caching. Added: lldb/include/lldb/Host/MemoryMonitor.h lldb/source/Host/common/MemoryMonitor.cpp lldb/source/Host/macosx/objcxx/MemoryMonitorMacOSX.mm Modified: lldb/source/Host/CMakeLists.txt lldb/source/Host/macosx/objcxx/CMakeLists.txt lldb/tools/lldb-dap/lldb-dap.cpp Removed: diff --git a/lldb/include/lldb/Host/MemoryMonitor.h b/lldb/include/lldb/Host/MemoryMonitor.h new file mode 100644 index 0..504f5f9cba96b --- /dev/null +++ b/lldb/include/lldb/Host/MemoryMonitor.h @@ -0,0 +1,41 @@ +//===-- MemoryMonitor.h ---===// +// +// 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_HOST_MEMORYMONITOR_H +#define LLDB_HOST_MEMORYMONITOR_H + +#include +#include + +namespace lldb_private { + +class MemoryMonitor { +public: + using Callback = std::function; + + MemoryMonitor(Callback callback) : m_callback(callback) {} + virtual ~MemoryMonitor() = default; + + /// MemoryMonitor is not copyable. + /// @{ + MemoryMonitor(const MemoryMonitor &) = delete; + MemoryMonitor &operator=(const MemoryMonitor &) = delete; + /// @} + + static std::unique_ptr Create(Callback callback); + + virtual void Start() = 0; + virtual void Stop() = 0; + +protected: + Callback m_callback; +}; + +} // namespace lldb_private + +#endif diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt index cdfb6184f2219..f4be151756b3b 100644 --- a/lldb/source/Host/CMakeLists.txt +++ b/lldb/source/Host/CMakeLists.txt @@ -27,6 +27,7 @@ add_host_subdirectory(common common/LockFileBase.cpp common/LZMA.cpp common/MainLoopBase.cpp + common/MemoryMonitor.cpp common/MonitoringProcessLauncher.cpp common/NativeProcessProtocol.cpp common/NativeRegisterContext.cpp @@ -136,7 +137,7 @@ else() elseif (CMAKE_SYSTEM_NAME MATCHES "AIX") add_host_subdirectory(aix aix/HostInfoAIX.cpp - ) + ) endif() endif() diff --git a/lldb/source/Host/common/MemoryMonitor.cpp b/lldb/source/Host/common/MemoryMonitor.cpp new file mode 100644 index 0..932fa9c43a22c --- /dev/null +++ b/lldb/source/Host/common/MemoryMonitor.cpp @@ -0,0 +1,109 @@ +//===-- MemoryMonitor.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/MemoryMonitor.h" +#include "lldb/Host/HostThread.h" +#include "lldb/Host/ThreadLauncher.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" +#include "llvm/ADT/ScopeExit.h" +#include "llvm/Support/Error.h" +#include +#include +#include +#include + +#if defined(__linux__) +#include +#include +#include +#endif + +#if defined(_WIN32) +#include +#endif + +using namespace lldb_private; + +class MemoryMonitorPoll : public MemoryMonitor { +public: + using MemoryMonitor::MemoryMonitor; + + lldb::thread_result_t MonitorThread() { +#if defined(__linux__) +struct pollfd fds; +fds.fd = open("/proc/pressure/memory", O_RDWR | O_NONBLOCK); +if (fds.fd < 0) + return {}; +fds.events = POLLPRI; + +auto cleanup = llvm::make_scope_exit([&]() { close(fds.fd); }); + +// Detect a 50ms stall in a 2 second time window. +const char trig[] = "some 5 200"; +if (write(fds.fd, trig, strlen(trig) + 1) < 0) + return {}; + +while (!m_done) { + int n = poll(&fds, 1, g_timeout); + if (n > 0) { +if (fds.revents & POLLERR) + return {}; +if (fds.revents & POLLPRI) + m_callback(); + } +} +#endif + +#if defined(_WIN32) +HANDLE low_memory_notification = +CreateMemoryResourceNotification(LowMemoryResourceNotification); +if (!low_memory_notification) + re
[Lldb-commits] [lldb] [LLDB][Telemetry]Defind telemetry::CommandInfo (PR #129354)
DavidSpickett wrote: > Defind telemetry... Define? https://github.com/llvm/llvm-project/pull/129354 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Defind telemetry::CommandInfo (PR #129354)
https://github.com/JDevlieghere commented: A few more nits. https://github.com/llvm/llvm-project/pull/129354 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 5d8b4ea - [lldb-dap] Fix: disableASLR launch argument not working. (#129753)
Author: Da-Viper Date: 2025-03-05T09:43:29-08:00 New Revision: 5d8b4ea97b174d6d80dbdeaabf5a3664d99e6a19 URL: https://github.com/llvm/llvm-project/commit/5d8b4ea97b174d6d80dbdeaabf5a3664d99e6a19 DIFF: https://github.com/llvm/llvm-project/commit/5d8b4ea97b174d6d80dbdeaabf5a3664d99e6a19.diff LOG: [lldb-dap] Fix: disableASLR launch argument not working. (#129753) Fixes #94338 Added: Modified: lldb/tools/lldb-dap/Handler/RequestHandler.cpp Removed: diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp index c72cf85a72ee5..e43fa36d25e3f 100644 --- a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp @@ -31,7 +31,19 @@ MakeArgv(const llvm::ArrayRef &strs) { return argv; } -// Both attach and launch take a either a sourcePath or sourceMap +static uint32_t SetLaunchFlag(uint32_t flags, const llvm::json::Object *obj, + llvm::StringRef key, lldb::LaunchFlags mask) { + if (const auto opt_value = GetBoolean(obj, key)) { +if (*opt_value) + flags |= mask; +else + flags &= ~mask; + } + + return flags; +} + +// Both attach and launch take either a sourcePath or a sourceMap // argument (or neither), from which we need to set the target.source-map. void RequestHandler::SetSourceMapFromArguments( const llvm::json::Object &arguments) const { @@ -173,12 +185,13 @@ RequestHandler::LaunchProcess(const llvm::json::Object &request) const { auto flags = launch_info.GetLaunchFlags(); - if (GetBoolean(arguments, "disableASLR").value_or(true)) -flags |= lldb::eLaunchFlagDisableASLR; - if (GetBoolean(arguments, "disableSTDIO").value_or(false)) -flags |= lldb::eLaunchFlagDisableSTDIO; - if (GetBoolean(arguments, "shellExpandArguments").value_or(false)) -flags |= lldb::eLaunchFlagShellExpandArguments; + flags = SetLaunchFlag(flags, arguments, "disableASLR", +lldb::eLaunchFlagDisableASLR); + flags = SetLaunchFlag(flags, arguments, "disableSTDIO", +lldb::eLaunchFlagDisableSTDIO); + flags = SetLaunchFlag(flags, arguments, "shellExpandArguments", +lldb::eLaunchFlagShellExpandArguments); + const bool detachOnError = GetBoolean(arguments, "detachOnError").value_or(false); launch_info.SetDetachOnError(detachOnError); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Fix: disableASLR launch argument not working. (PR #129753)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/129753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Minidump]Update MinidumpFileBuilder to read and write in chunks (PR #129307)
@@ -969,12 +969,83 @@ Status MinidumpFileBuilder::DumpDirectories() const { return error; } -static uint64_t -GetLargestRangeSize(const std::vector &ranges) { - uint64_t max_size = 0; - for (const auto &core_range : ranges) -max_size = std::max(max_size, core_range.range.size()); - return max_size; +Status MinidumpFileBuilder::ReadWriteMemoryInChunks( +const lldb_private::CoreFileMemoryRange &range, uint64_t *bytes_read) { + Log *log = GetLog(LLDBLog::Object); + lldb::addr_t addr = range.range.start(); + lldb::addr_t size = range.range.size(); + // First we set the byte tally to 0, so if we do exit gracefully + // the caller doesn't think the random garbage on the stack is a + // success. + if (bytes_read) +*bytes_read = 0; + + uint64_t bytes_remaining = size; + uint64_t total_bytes_read = 0; + auto data_up = std::make_unique( + std::min(bytes_remaining, MAX_WRITE_CHUNK_SIZE), 0); + Status error; + while (bytes_remaining > 0) { +// Get the next read chunk size as the minimum of the remaining bytes and +// the write chunk max size. +const size_t bytes_to_read = +std::min(bytes_remaining, MAX_WRITE_CHUNK_SIZE); +const size_t bytes_read_for_chunk = +m_process_sp->ReadMemory(range.range.start() + total_bytes_read, + data_up->GetBytes(), bytes_to_read, error); +if (error.Fail() || bytes_read_for_chunk == 0) { + LLDB_LOGF(log, +"Failed to read memory region at: %" PRIx64 +". Bytes read: %zu, error: %s", +addr, bytes_read_for_chunk, error.AsCString()); + // If we've read nothing, and get an error or fail to read + // we can just give up early. + if (total_bytes_read == 0) +return Status(); + + // If we've read some bytes, we stop trying to read more and return + // this best effort attempt + bytes_remaining = 0; +} else if (bytes_read_for_chunk != bytes_to_read) { + LLDB_LOGF( + log, "Memory region at: %" PRIx64 " failed to read %" PRIx64 " bytes", + addr, size); + + // If we've read some bytes, we stop trying to read more and return + // this best effort attempt + bytes_remaining = 0; +} + +// Write to the minidump file with the chunk potentially flushing to disk. +// this is the only place we want to return a true error, so that we can +// fail. If we get an error writing to disk we can't easily gaurauntee +// that we won't corrupt the minidump. +error = AddData(data_up->GetBytes(), bytes_read_for_chunk); +if (error.Fail()) + return error; + +// This check is so we don't overflow when the error code above sets the +// bytes to read to 0 (the graceful exit condition). +if (bytes_remaining > 0) + bytes_remaining -= bytes_read_for_chunk; + +total_bytes_read += bytes_read_for_chunk; +// If the caller wants a tally back of the bytes_read, update it as we +// write. We do this in the loop so if we encounter an error we can +// report the accurate total. +if (bytes_read) + *bytes_read += bytes_read_for_chunk; + +// We clear the heap per loop, without checking if we +// read the expected bytes this is so we don't allocate +// more than the MAX_WRITE_CHUNK_SIZE. But we do check if +// this is even worth clearing before we return and +// destruct the heap. +if (bytes_remaining > 0) + data_up->Clear(); Jlalond wrote: Jeffrey and I talked offline, I erroneously thought that we were giving out a write handle. That was stupid and this should've crashed by corrupting the heap. I've fixed this by dropping `clear()`. As an upside of this logic we only allocate once for each AddMemory_ call, either the size of the largest range, or the chunk size. https://github.com/llvm/llvm-project/pull/129307 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Support expectedFlakey decorator in dotest (PR #129817)
JDevlieghere wrote: I personally don't think we should have such a decorator: test shouldn't be flakey. In my experience, when tests are flakey, they are almost always either poor tests or actual bugs. I'm worried that a decorator like this makes it easy to sweep these issues under the rug. That's not to say that things cannot be flakey sometimes: because of how we test the debugger, we depend on a lot of things, many of which are out of our control and can cause a test to fail. But that's different from a specific test being flakey, which is what this decorator would be used for. https://github.com/llvm/llvm-project/pull/129817 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Upgrade CompilerType::GetBitSize to return llvm::Expected (PR #129601)
https://github.com/adrian-prantl closed https://github.com/llvm/llvm-project/pull/129601 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Creating well defined structures for DAP messages. (PR #129155)
https://github.com/ashgti closed https://github.com/llvm/llvm-project/pull/129155 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Defind telemetry::CommandInfo (PR #129354)
https://github.com/oontvoo updated https://github.com/llvm/llvm-project/pull/129354 >From 5a992aff351a93ff820d15ace3ebc2bea59dd5fc Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Fri, 28 Feb 2025 23:03:35 -0500 Subject: [PATCH 01/17] [LLDB][Telemetry]Defind telemetry::CommandInfo and collect telemetry about a command's execution. --- lldb/include/lldb/Core/Telemetry.h| 127 +- lldb/source/Core/Telemetry.cpp| 14 ++ .../source/Interpreter/CommandInterpreter.cpp | 20 +++ 3 files changed, 158 insertions(+), 3 deletions(-) diff --git a/lldb/include/lldb/Core/Telemetry.h b/lldb/include/lldb/Core/Telemetry.h index b72556ecaf3c9..30b8474156124 100644 --- a/lldb/include/lldb/Core/Telemetry.h +++ b/lldb/include/lldb/Core/Telemetry.h @@ -12,11 +12,14 @@ #include "lldb/Core/StructuredDataImpl.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Utility/StructuredData.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/lldb-forward.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/FunctionExtras.h" #include "llvm/Support/JSON.h" #include "llvm/Telemetry/Telemetry.h" +#include #include #include #include @@ -27,8 +30,16 @@ namespace lldb_private { namespace telemetry { +struct LLDBConfig : public ::llvm::telemetry::Config { + const bool m_collect_original_command; + + explicit LLDBConfig(bool enable_telemetry, bool collect_original_command) + : ::llvm::telemetry::Config(enable_telemetry), m_collect_original_command(collect_original_command) {} +}; + struct LLDBEntryKind : public ::llvm::telemetry::EntryKind { - static const llvm::telemetry::KindType BaseInfo = 0b11000; + static const llvm::telemetry::KindType BaseInfo = 0b1100; + static const llvm::telemetry::KindType CommandInfo = 0b1101; }; /// Defines a convenient type for timestamp of various events. @@ -41,6 +52,7 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { std::optional end_time; // TBD: could add some memory stats here too? + lldb::user_id_t debugger_id = LLDB_INVALID_UID; Debugger *debugger; // For dyn_cast, isa, etc operations. @@ -56,6 +68,42 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { void serialize(llvm::telemetry::Serializer &serializer) const override; }; + +struct CommandInfo : public LLDBBaseTelemetryInfo { + + // If the command is/can be associated with a target entry this field contains + // that target's UUID. otherwise. + std::string target_uuid; + // A unique ID for a command so the manager can match the start entry with + // its end entry. These values only need to be unique within the same session. + // Necessary because we'd send off an entry right before a command's execution + // and another right after. This is to avoid losing telemetry if the command + // does not execute successfully. + int command_id; + + // Eg., "breakpoint set" + std::string command_name; + + // !!NOTE!! These two fields are not collected (upstream) due to PII risks. + // (Downstream impl may add them if needed). + // std::string original_command; + // std::string args; + + lldb::ReturnStatus ret_status; + std::string error_data; + + + CommandInfo() = default; + + llvm::telemetry::KindType getKind() const override { return LLDBEntryKind::CommandInfo; } + + static bool classof(const llvm::telemetry::TelemetryInfo *T) { +return (T->getKind() & LLDBEntryKind::CommandInfo) == LLDBEntryKind::CommandInfo; + } + + void serialize(Serializer &serializer) const override; +}; + /// The base Telemetry manager instance in LLDB. /// This class declares additional instrumentation points /// applicable to LLDB. @@ -63,19 +111,92 @@ class TelemetryManager : public llvm::telemetry::Manager { public: llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override; + int MakeNextCommandId(); + + LLDBConfig* GetConfig() { return m_config.get(); } + virtual llvm::StringRef GetInstanceName() const = 0; static TelemetryManager *getInstance(); protected: - TelemetryManager(std::unique_ptr config); + TelemetryManager(std::unique_ptr config); static void setInstance(std::unique_ptr manger); private: - std::unique_ptr m_config; + std::unique_ptr m_config; + const std::string m_id; + // We assign each command (in the same session) a unique id so that their + // "start" and "end" entries can be matched up. + // These values don't need to be unique across runs (because they are + // secondary-key), hence a simple counter is sufficent. + std::atomic command_id_seed = 0; static std::unique_ptr g_instance; }; +/// Helper RAII class for collecting telemetry. +template struct ScopedDispatcher { + // The debugger pointer is optional because we may not have a debugger yet. + // In that case, caller must set the debugger later. + ScopedDispatcher(Debugger *debugger = nullptr) { +// Sta
[Lldb-commits] [lldb] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation (PR #129733)
https://github.com/Michael137 edited https://github.com/llvm/llvm-project/pull/129733 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Defind telemetry::CommandInfo (PR #129354)
https://github.com/oontvoo updated https://github.com/llvm/llvm-project/pull/129354 >From 5a992aff351a93ff820d15ace3ebc2bea59dd5fc Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Fri, 28 Feb 2025 23:03:35 -0500 Subject: [PATCH 01/18] [LLDB][Telemetry]Defind telemetry::CommandInfo and collect telemetry about a command's execution. --- lldb/include/lldb/Core/Telemetry.h| 127 +- lldb/source/Core/Telemetry.cpp| 14 ++ .../source/Interpreter/CommandInterpreter.cpp | 20 +++ 3 files changed, 158 insertions(+), 3 deletions(-) diff --git a/lldb/include/lldb/Core/Telemetry.h b/lldb/include/lldb/Core/Telemetry.h index b72556ecaf3c9..30b8474156124 100644 --- a/lldb/include/lldb/Core/Telemetry.h +++ b/lldb/include/lldb/Core/Telemetry.h @@ -12,11 +12,14 @@ #include "lldb/Core/StructuredDataImpl.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Utility/StructuredData.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/lldb-forward.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/FunctionExtras.h" #include "llvm/Support/JSON.h" #include "llvm/Telemetry/Telemetry.h" +#include #include #include #include @@ -27,8 +30,16 @@ namespace lldb_private { namespace telemetry { +struct LLDBConfig : public ::llvm::telemetry::Config { + const bool m_collect_original_command; + + explicit LLDBConfig(bool enable_telemetry, bool collect_original_command) + : ::llvm::telemetry::Config(enable_telemetry), m_collect_original_command(collect_original_command) {} +}; + struct LLDBEntryKind : public ::llvm::telemetry::EntryKind { - static const llvm::telemetry::KindType BaseInfo = 0b11000; + static const llvm::telemetry::KindType BaseInfo = 0b1100; + static const llvm::telemetry::KindType CommandInfo = 0b1101; }; /// Defines a convenient type for timestamp of various events. @@ -41,6 +52,7 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { std::optional end_time; // TBD: could add some memory stats here too? + lldb::user_id_t debugger_id = LLDB_INVALID_UID; Debugger *debugger; // For dyn_cast, isa, etc operations. @@ -56,6 +68,42 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { void serialize(llvm::telemetry::Serializer &serializer) const override; }; + +struct CommandInfo : public LLDBBaseTelemetryInfo { + + // If the command is/can be associated with a target entry this field contains + // that target's UUID. otherwise. + std::string target_uuid; + // A unique ID for a command so the manager can match the start entry with + // its end entry. These values only need to be unique within the same session. + // Necessary because we'd send off an entry right before a command's execution + // and another right after. This is to avoid losing telemetry if the command + // does not execute successfully. + int command_id; + + // Eg., "breakpoint set" + std::string command_name; + + // !!NOTE!! These two fields are not collected (upstream) due to PII risks. + // (Downstream impl may add them if needed). + // std::string original_command; + // std::string args; + + lldb::ReturnStatus ret_status; + std::string error_data; + + + CommandInfo() = default; + + llvm::telemetry::KindType getKind() const override { return LLDBEntryKind::CommandInfo; } + + static bool classof(const llvm::telemetry::TelemetryInfo *T) { +return (T->getKind() & LLDBEntryKind::CommandInfo) == LLDBEntryKind::CommandInfo; + } + + void serialize(Serializer &serializer) const override; +}; + /// The base Telemetry manager instance in LLDB. /// This class declares additional instrumentation points /// applicable to LLDB. @@ -63,19 +111,92 @@ class TelemetryManager : public llvm::telemetry::Manager { public: llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override; + int MakeNextCommandId(); + + LLDBConfig* GetConfig() { return m_config.get(); } + virtual llvm::StringRef GetInstanceName() const = 0; static TelemetryManager *getInstance(); protected: - TelemetryManager(std::unique_ptr config); + TelemetryManager(std::unique_ptr config); static void setInstance(std::unique_ptr manger); private: - std::unique_ptr m_config; + std::unique_ptr m_config; + const std::string m_id; + // We assign each command (in the same session) a unique id so that their + // "start" and "end" entries can be matched up. + // These values don't need to be unique across runs (because they are + // secondary-key), hence a simple counter is sufficent. + std::atomic command_id_seed = 0; static std::unique_ptr g_instance; }; +/// Helper RAII class for collecting telemetry. +template struct ScopedDispatcher { + // The debugger pointer is optional because we may not have a debugger yet. + // In that case, caller must set the debugger later. + ScopedDispatcher(Debugger *debugger = nullptr) { +// Sta
[Lldb-commits] [lldb] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation (PR #129733)
Michael137 wrote: Just realized we also need to adjust `ReportRetriever.cpp` to use the preferred module since it runs an ASAN utility expression https://github.com/llvm/llvm-project/pull/129733 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation (PR #129733)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/129733 >From da950b7a55c8ee0a35bcfb7e3565fbc11095ab6e Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Tue, 4 Mar 2025 16:14:59 + Subject: [PATCH 1/4] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation --- .../include/lldb/Expression/IRExecutionUnit.h | 6 + lldb/include/lldb/Target/Target.h | 10 lldb/source/Expression/IRExecutionUnit.cpp| 25 ++- .../Clang/ClangExpressionParser.cpp | 3 +++ .../MemoryHistory/asan/MemoryHistoryASan.cpp | 15 +++ 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/lldb/include/lldb/Expression/IRExecutionUnit.h b/lldb/include/lldb/Expression/IRExecutionUnit.h index 58f12bf8b64f5..a0978f9f5063d 100644 --- a/lldb/include/lldb/Expression/IRExecutionUnit.h +++ b/lldb/include/lldb/Expression/IRExecutionUnit.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "llvm/ExecutionEngine/SectionMemoryManager.h" @@ -161,6 +162,10 @@ class IRExecutionUnit : public std::enable_shared_from_this, return m_jitted_global_variables; } + void SetPreferredModules(std::unordered_set modules) { +m_preferred_modules = std::move(modules); + } + private: /// Look up the object in m_address_map that contains a given address, find /// where it was copied to, and return the remote address at the same offset @@ -396,6 +401,7 @@ class IRExecutionUnit : public std::enable_shared_from_this, ///< defining no functions using that variable, would do this.) If this ///< is true, any allocations need to be committed immediately -- no ///< opportunity for relocation. + std::unordered_set m_preferred_modules; }; } // namespace lldb_private diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index f31ac381391b4..369b5633492bb 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -332,6 +332,14 @@ class EvaluateExpressionOptions { m_language = SourceLanguage(language_type); } + void SetPreferredModules(std::unordered_set modules) { +m_preferred_modules = std::move(modules); + } + + const std::unordered_set &GetPreferredModules() const { +return m_preferred_modules; + } + /// Set the language using a pair of language code and version as /// defined by the DWARF 6 specification. /// WARNING: These codes may change until DWARF 6 is finalized. @@ -500,6 +508,8 @@ class EvaluateExpressionOptions { // originates mutable std::string m_pound_line_file; mutable uint32_t m_pound_line_line = 0; + + std::unordered_set m_preferred_modules; }; // Target diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp index c8b4ddf705ec4..8e5f26544c84f 100644 --- a/lldb/source/Expression/IRExecutionUnit.cpp +++ b/lldb/source/Expression/IRExecutionUnit.cpp @@ -52,7 +52,7 @@ IRExecutionUnit::IRExecutionUnit(std::unique_ptr &context_up, m_cpu_features(cpu_features), m_name(name), m_sym_ctx(sym_ctx), m_did_jit(false), m_function_load_addr(LLDB_INVALID_ADDRESS), m_function_end_load_addr(LLDB_INVALID_ADDRESS), - m_reported_allocations(false) {} + m_reported_allocations(false), m_preferred_modules() {} lldb::addr_t IRExecutionUnit::WriteNow(const uint8_t *bytes, size_t size, Status &error) { @@ -785,6 +785,13 @@ IRExecutionUnit::FindInSymbols(const std::vector &names, // We'll process module_sp separately, before the other modules. non_local_images.Remove(sc.module_sp); + ModuleList preferred_images; + // TODO: make m_preferred_modules a ModuleList + for (auto const &m : m_preferred_modules) { +non_local_images.Remove(m); +preferred_images.Append(m); + } + LoadAddressResolver resolver(target, symbol_was_missing_weak); ModuleFunctionSearchOptions function_options; @@ -806,6 +813,14 @@ IRExecutionUnit::FindInSymbols(const std::vector &names, return *load_addr; } +{ + SymbolContextList sc_list; + preferred_images.FindFunctions(name, lldb::eFunctionNameTypeFull, + function_options, sc_list); + if (auto load_addr = resolver.Resolve(sc_list)) +return *load_addr; +} + { SymbolContextList sc_list; non_local_images.FindFunctions(name, lldb::eFunctionNameTypeFull, @@ -822,6 +837,14 @@ IRExecutionUnit::FindInSymbols(const std::vector &names, return *load_addr; } +{ + SymbolContextList sc_list; + preferred_images.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny, + sc_list); + if (auto load_addr = resolver.Resolve(sc_list)) +return *load_addr; +} + { SymbolContextList sc_list; non_local_images.F
[Lldb-commits] [lldb] [lldb-dap] Fix: disableASLR launch argument not working. (PR #129753)
https://github.com/Da-Viper updated https://github.com/llvm/llvm-project/pull/129753 >From 2f773debb694f5684664ea47e545027aeb6e33db Mon Sep 17 00:00:00 2001 From: Ezike Ebuka Date: Wed, 5 Mar 2025 10:32:16 + Subject: [PATCH 1/2] [lldb-dap] Fix: disableASLR launch argument not working. --- .../tools/lldb-dap/Handler/RequestHandler.cpp | 26 ++- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp index d4030965869a1..816397adb26ad 100644 --- a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp @@ -31,7 +31,18 @@ MakeArgv(const llvm::ArrayRef &strs) { return argv; } -// Both attach and launch take a either a sourcePath or sourceMap +static uint32_t SetLaunchFlag(uint32_t flags, const llvm::json::Object *obj, + llvm::StringRef key, lldb::LaunchFlags mask, + bool default_value) { + if (GetBoolean(obj, key).value_or(default_value)) +flags |= mask; + else +flags &= ~mask; + + return flags; +} + +// Both attach and launch take either a sourcePath or a sourceMap // argument (or neither), from which we need to set the target.source-map. void RequestHandler::SetSourceMapFromArguments( const llvm::json::Object &arguments) const { @@ -173,12 +184,13 @@ RequestHandler::LaunchProcess(const llvm::json::Object &request) const { auto flags = launch_info.GetLaunchFlags(); - if (GetBoolean(arguments, "disableASLR").value_or(true)) -flags |= lldb::eLaunchFlagDisableASLR; - if (GetBoolean(arguments, "disableSTDIO").value_or(false)) -flags |= lldb::eLaunchFlagDisableSTDIO; - if (GetBoolean(arguments, "shellExpandArguments").value_or(false)) -flags |= lldb::eLaunchFlagShellExpandArguments; + flags = SetLaunchFlag(flags, arguments, "disableASLR", +lldb::eLaunchFlagDisableASLR, true); + flags = SetLaunchFlag(flags, arguments, "disableSTDIO", +lldb::eLaunchFlagDisableSTDIO, false); + flags = SetLaunchFlag(flags, arguments, "shellExpandArguments", +lldb::eLaunchFlagShellExpandArguments, false); + const bool detachOnError = GetBoolean(arguments, "detachOnError").value_or(false); launch_info.SetDetachOnError(detachOnError); >From 2486994b4077d333869b0687ee8a85fd5179d504 Mon Sep 17 00:00:00 2001 From: Ezike Ebuka Date: Wed, 5 Mar 2025 16:58:49 + Subject: [PATCH 2/2] [lldb] [lldb-dap] do not set a flag if it is not in json object. --- lldb/tools/lldb-dap/Handler/RequestHandler.cpp | 18 +- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp index 816397adb26ad..36669a0596d34 100644 --- a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp @@ -32,12 +32,12 @@ MakeArgv(const llvm::ArrayRef &strs) { } static uint32_t SetLaunchFlag(uint32_t flags, const llvm::json::Object *obj, - llvm::StringRef key, lldb::LaunchFlags mask, - bool default_value) { - if (GetBoolean(obj, key).value_or(default_value)) -flags |= mask; - else -flags &= ~mask; + llvm::StringRef key, lldb::LaunchFlags mask) { + if (const auto opt_value = GetBoolean(obj, key)) +if (opt_value.value()) + flags |= mask; +else + flags &= ~mask; return flags; } @@ -185,11 +185,11 @@ RequestHandler::LaunchProcess(const llvm::json::Object &request) const { auto flags = launch_info.GetLaunchFlags(); flags = SetLaunchFlag(flags, arguments, "disableASLR", -lldb::eLaunchFlagDisableASLR, true); +lldb::eLaunchFlagDisableASLR); flags = SetLaunchFlag(flags, arguments, "disableSTDIO", -lldb::eLaunchFlagDisableSTDIO, false); +lldb::eLaunchFlagDisableSTDIO); flags = SetLaunchFlag(flags, arguments, "shellExpandArguments", -lldb::eLaunchFlagShellExpandArguments, false); +lldb::eLaunchFlagShellExpandArguments); const bool detachOnError = GetBoolean(arguments, "detachOnError").value_or(false); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Defind telemetry::CommandInfo (PR #129354)
https://github.com/oontvoo updated https://github.com/llvm/llvm-project/pull/129354 >From 5a992aff351a93ff820d15ace3ebc2bea59dd5fc Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Fri, 28 Feb 2025 23:03:35 -0500 Subject: [PATCH 01/19] [LLDB][Telemetry]Defind telemetry::CommandInfo and collect telemetry about a command's execution. --- lldb/include/lldb/Core/Telemetry.h| 127 +- lldb/source/Core/Telemetry.cpp| 14 ++ .../source/Interpreter/CommandInterpreter.cpp | 20 +++ 3 files changed, 158 insertions(+), 3 deletions(-) diff --git a/lldb/include/lldb/Core/Telemetry.h b/lldb/include/lldb/Core/Telemetry.h index b72556ecaf3c9..30b8474156124 100644 --- a/lldb/include/lldb/Core/Telemetry.h +++ b/lldb/include/lldb/Core/Telemetry.h @@ -12,11 +12,14 @@ #include "lldb/Core/StructuredDataImpl.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Utility/StructuredData.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/lldb-forward.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/FunctionExtras.h" #include "llvm/Support/JSON.h" #include "llvm/Telemetry/Telemetry.h" +#include #include #include #include @@ -27,8 +30,16 @@ namespace lldb_private { namespace telemetry { +struct LLDBConfig : public ::llvm::telemetry::Config { + const bool m_collect_original_command; + + explicit LLDBConfig(bool enable_telemetry, bool collect_original_command) + : ::llvm::telemetry::Config(enable_telemetry), m_collect_original_command(collect_original_command) {} +}; + struct LLDBEntryKind : public ::llvm::telemetry::EntryKind { - static const llvm::telemetry::KindType BaseInfo = 0b11000; + static const llvm::telemetry::KindType BaseInfo = 0b1100; + static const llvm::telemetry::KindType CommandInfo = 0b1101; }; /// Defines a convenient type for timestamp of various events. @@ -41,6 +52,7 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { std::optional end_time; // TBD: could add some memory stats here too? + lldb::user_id_t debugger_id = LLDB_INVALID_UID; Debugger *debugger; // For dyn_cast, isa, etc operations. @@ -56,6 +68,42 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { void serialize(llvm::telemetry::Serializer &serializer) const override; }; + +struct CommandInfo : public LLDBBaseTelemetryInfo { + + // If the command is/can be associated with a target entry this field contains + // that target's UUID. otherwise. + std::string target_uuid; + // A unique ID for a command so the manager can match the start entry with + // its end entry. These values only need to be unique within the same session. + // Necessary because we'd send off an entry right before a command's execution + // and another right after. This is to avoid losing telemetry if the command + // does not execute successfully. + int command_id; + + // Eg., "breakpoint set" + std::string command_name; + + // !!NOTE!! These two fields are not collected (upstream) due to PII risks. + // (Downstream impl may add them if needed). + // std::string original_command; + // std::string args; + + lldb::ReturnStatus ret_status; + std::string error_data; + + + CommandInfo() = default; + + llvm::telemetry::KindType getKind() const override { return LLDBEntryKind::CommandInfo; } + + static bool classof(const llvm::telemetry::TelemetryInfo *T) { +return (T->getKind() & LLDBEntryKind::CommandInfo) == LLDBEntryKind::CommandInfo; + } + + void serialize(Serializer &serializer) const override; +}; + /// The base Telemetry manager instance in LLDB. /// This class declares additional instrumentation points /// applicable to LLDB. @@ -63,19 +111,92 @@ class TelemetryManager : public llvm::telemetry::Manager { public: llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override; + int MakeNextCommandId(); + + LLDBConfig* GetConfig() { return m_config.get(); } + virtual llvm::StringRef GetInstanceName() const = 0; static TelemetryManager *getInstance(); protected: - TelemetryManager(std::unique_ptr config); + TelemetryManager(std::unique_ptr config); static void setInstance(std::unique_ptr manger); private: - std::unique_ptr m_config; + std::unique_ptr m_config; + const std::string m_id; + // We assign each command (in the same session) a unique id so that their + // "start" and "end" entries can be matched up. + // These values don't need to be unique across runs (because they are + // secondary-key), hence a simple counter is sufficent. + std::atomic command_id_seed = 0; static std::unique_ptr g_instance; }; +/// Helper RAII class for collecting telemetry. +template struct ScopedDispatcher { + // The debugger pointer is optional because we may not have a debugger yet. + // In that case, caller must set the debugger later. + ScopedDispatcher(Debugger *debugger = nullptr) { +// Sta
[Lldb-commits] [lldb] [LLDB][Telemetry]Define TargetInfo for collecting data about a target (PR #127834)
https://github.com/oontvoo updated https://github.com/llvm/llvm-project/pull/127834 >From 0d6a36d84df50ccb9eef9ef3dd6f59d4299edeac Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Wed, 19 Feb 2025 12:47:57 -0500 Subject: [PATCH 1/9] [LLDB][Telemetry]Define TargetInfo for collecting data about a target --- lldb/include/lldb/Core/Telemetry.h | 86 +- lldb/source/Core/Telemetry.cpp | 99 ++ 2 files changed, 170 insertions(+), 15 deletions(-) diff --git a/lldb/include/lldb/Core/Telemetry.h b/lldb/include/lldb/Core/Telemetry.h index b72556ecaf3c9..4be81951254de 100644 --- a/lldb/include/lldb/Core/Telemetry.h +++ b/lldb/include/lldb/Core/Telemetry.h @@ -13,6 +13,7 @@ #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Utility/StructuredData.h" #include "lldb/lldb-forward.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/JSON.h" @@ -29,6 +30,9 @@ namespace telemetry { struct LLDBEntryKind : public ::llvm::telemetry::EntryKind { static const llvm::telemetry::KindType BaseInfo = 0b11000; + static const KindType TargetInfo = 0b11010; + // There are other entries in between (added in separate PRs) + static const llvm::telemetry::KindType MiscInfo = 0b0; }; /// Defines a convenient type for timestamp of various events. @@ -56,14 +60,88 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { void serialize(llvm::telemetry::Serializer &serializer) const override; }; +/// Describes an exit status. +struct ExitDescription { + int exit_code; + std::string description; +}; + +struct TargetTelemetryInfo : public LldbBaseTelemetryInfo { + lldb::ModuleSP exec_mod; + Target *target_ptr; + + // The same as the executable-module's UUID. + std::string target_uuid; + std::string file_format; + + std::string binary_path; + size_t binary_size; + + std::optional exit_desc; + TargetTelemetryInfo() = default; + + TargetTelemetryInfo(const TargetTelemetryInfo &other) { +exec_mod = other.exec_mod; +target_uuid = other.target_uuid; +file_format = other.file_format; +binary_path = other.binary_path; +binary_size = other.binary_size; +exit_desc = other.exit_desc; + } + + KindType getKind() const override { return LldbEntryKind::TargetInfo; } + + static bool classof(const TelemetryInfo *T) { +if (T == nullptr) + return false; +return T->getKind() == LldbEntryKind::TargetInfo; + } + + void serialize(Serializer &serializer) const override; +}; + +/// The "catch-all" entry to store a set of non-standard data, such as +/// error-messages, etc. +struct MiscTelemetryInfo : public LLDBBaseTelemetryInfo { + /// If the event is/can be associated with a target entry, + /// this field contains that target's UUID. + /// otherwise. + std::string target_uuid; + + /// Set of key-value pairs for any optional (or impl-specific) data + std::map meta_data; + + MiscTelemetryInfo() = default; + + MiscTelemetryInfo(const MiscTelemetryInfo &other) { +target_uuid = other.target_uuid; +meta_data = other.meta_data; + } + + llvm::telemetry::KindType getKind() const override { +return LLDBEntryKind::MiscInfo; + } + + static bool classof(const llvm::telemetry::TelemetryInfo *T) { +return T->getKind() == LLDBEntryKind::MiscInfo; + } + + void serialize(llvm::telemetry::Serializer &serializer) const override; +}; + /// The base Telemetry manager instance in LLDB. /// This class declares additional instrumentation points /// applicable to LLDB. -class TelemetryManager : public llvm::telemetry::Manager { +class TelemetryMager : public llvm::telemetry::Manager { public: llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override; - virtual llvm::StringRef GetInstanceName() const = 0; + const llvm::telemetry::Config *getConfig(); + + virtual void AtMainExecutableLoadStart(TargetInfo * entry); + virtual void AtMainExecutableLoadEnd(TargetInfo *entry); + + virtual llvm::StringRef GetInstanceName() const = 0; static TelemetryManager *getInstance(); protected: @@ -73,6 +151,10 @@ class TelemetryManager : public llvm::telemetry::Manager { private: std::unique_ptr m_config; + // Each debugger is assigned a unique ID (session_id). + // All TelemetryInfo entries emitted for the same debugger instance + // will get the same session_id. + llvm::DenseMap session_ids; static std::unique_ptr g_instance; }; diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp index 5222f76704f91..da7aee01680fc 100644 --- a/lldb/source/Core/Telemetry.cpp +++ b/lldb/source/Core/Telemetry.cpp @@ -10,14 +10,20 @@ #ifdef LLVM_BUILD_TELEMETRY -#include "lldb/Core/Telemetry.h" #include "lldb/Core/Debugger.h" +#include "lldb/Core/Telemetry.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Host/HostInfo.h" +#include "lldb/Target/Process.h" +#include "lld
[Lldb-commits] [lldb] [lldb] Split test to avoid timeout (PR #129614)
https://github.com/dmpots updated https://github.com/llvm/llvm-project/pull/129614 >From bb034b3b8c43dae13d7f596c20863b47ce88e4d4 Mon Sep 17 00:00:00 2001 From: David Peixotto Date: Mon, 3 Mar 2025 15:39:20 -0800 Subject: [PATCH 1/2] Split test to avoid timeout This test is running right up to the 600s timeout limit. Split it in two to avoid hitting a timeout. --- .../tools/lldb-server/TestLldbGdbServer.py| 901 + .../tools/lldb-server/TestLldbGdbServer2.py | 922 ++ 2 files changed, 925 insertions(+), 898 deletions(-) create mode 100644 lldb/test/API/tools/lldb-server/TestLldbGdbServer2.py diff --git a/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py b/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py index 592037db502aa..81639ed96597f 100644 --- a/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py +++ b/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py @@ -5,9 +5,9 @@ lldb-server tests run where the lldb-server exe is available. -This class will be broken into smaller test case classes by -gdb remote packet functional areas. For now it contains -the initial set of tests implemented. +The tests are split between the LldbGdbServerTestCase and +LldbGdbServerTestCase2 classes to avoid timeouts in the +test suite. """ import binascii @@ -602,898 +602,3 @@ def test_Hc_then_Csignal_signals_correct_thread_launch(self): self.Hc_then_Csignal_signals_correct_thread( lldbutil.get_signal_number("SIGSEGV") ) - -@skipIfWindows # No pty support to test any inferior output -def test_m_packet_reads_memory(self): -self.build() -self.set_inferior_startup_launch() -# This is the memory we will write into the inferior and then ensure we -# can read back with $m. -MEMORY_CONTENTS = "Test contents 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz" - -# Start up the inferior. -procs = self.prep_debug_monitor_and_inferior( -inferior_args=[ -"set-message:%s" % MEMORY_CONTENTS, -"get-data-address-hex:g_message", -"sleep:5", -] -) - -# Run the process -self.test_sequence.add_log_lines( -[ -# Start running after initial stop. -"read packet: $c#63", -# Match output line that prints the memory address of the message buffer within the inferior. -# Note we require launch-only testing so we can get inferior otuput. -{ -"type": "output_match", -"regex": self.maybe_strict_output_regex( -r"data address: 0x([0-9a-fA-F]+)\r\n" -), -"capture": {1: "message_address"}, -}, -# Now stop the inferior. -"read packet: {}".format(chr(3)), -# And wait for the stop notification. -{ -"direction": "send", -"regex": r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", -"capture": {1: "stop_signo", 2: "stop_thread_id"}, -}, -], -True, -) - -# Run the packet stream. -context = self.expect_gdbremote_sequence() -self.assertIsNotNone(context) - -# Grab the message address. -self.assertIsNotNone(context.get("message_address")) -message_address = int(context.get("message_address"), 16) - -# Grab contents from the inferior. -self.reset_test_sequence() -self.test_sequence.add_log_lines( -[ -"read packet: $m{0:x},{1:x}#00".format( -message_address, len(MEMORY_CONTENTS) -), -{ -"direction": "send", -"regex": r"^\$(.+)#[0-9a-fA-F]{2}$", -"capture": {1: "read_contents"}, -}, -], -True, -) - -# Run the packet stream. -context = self.expect_gdbremote_sequence() -self.assertIsNotNone(context) - -# Ensure what we read from inferior memory is what we wrote. -self.assertIsNotNone(context.get("read_contents")) -read_contents = seven.unhexlify(context.get("read_contents")) -self.assertEqual(read_contents, MEMORY_CONTENTS) - -def test_qMemoryRegionInfo_is_supported(self): -self.build() -self.set_inferior_startup_launch() -# Start up the inferior. -procs = self.prep_debug_monitor_and_inferior() - -# Ask if it supports $qMemoryRegionInfo. -self.test_sequence.add_log_lines( -["read packet: $qMemoryRegionInfo#00", "send packet: $OK#00"], True -) -self.expect_gdbremote_sequence() - -@skipIfWindows # No pty support to test any inferior
[Lldb-commits] [lldb] [LLDB][Telemetry]Define telemetry::CommandInfo (PR #129354)
https://github.com/oontvoo updated https://github.com/llvm/llvm-project/pull/129354 >From 5a992aff351a93ff820d15ace3ebc2bea59dd5fc Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Fri, 28 Feb 2025 23:03:35 -0500 Subject: [PATCH 01/21] [LLDB][Telemetry]Defind telemetry::CommandInfo and collect telemetry about a command's execution. --- lldb/include/lldb/Core/Telemetry.h| 127 +- lldb/source/Core/Telemetry.cpp| 14 ++ .../source/Interpreter/CommandInterpreter.cpp | 20 +++ 3 files changed, 158 insertions(+), 3 deletions(-) diff --git a/lldb/include/lldb/Core/Telemetry.h b/lldb/include/lldb/Core/Telemetry.h index b72556ecaf3c9..30b8474156124 100644 --- a/lldb/include/lldb/Core/Telemetry.h +++ b/lldb/include/lldb/Core/Telemetry.h @@ -12,11 +12,14 @@ #include "lldb/Core/StructuredDataImpl.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Utility/StructuredData.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/lldb-forward.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/FunctionExtras.h" #include "llvm/Support/JSON.h" #include "llvm/Telemetry/Telemetry.h" +#include #include #include #include @@ -27,8 +30,16 @@ namespace lldb_private { namespace telemetry { +struct LLDBConfig : public ::llvm::telemetry::Config { + const bool m_collect_original_command; + + explicit LLDBConfig(bool enable_telemetry, bool collect_original_command) + : ::llvm::telemetry::Config(enable_telemetry), m_collect_original_command(collect_original_command) {} +}; + struct LLDBEntryKind : public ::llvm::telemetry::EntryKind { - static const llvm::telemetry::KindType BaseInfo = 0b11000; + static const llvm::telemetry::KindType BaseInfo = 0b1100; + static const llvm::telemetry::KindType CommandInfo = 0b1101; }; /// Defines a convenient type for timestamp of various events. @@ -41,6 +52,7 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { std::optional end_time; // TBD: could add some memory stats here too? + lldb::user_id_t debugger_id = LLDB_INVALID_UID; Debugger *debugger; // For dyn_cast, isa, etc operations. @@ -56,6 +68,42 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { void serialize(llvm::telemetry::Serializer &serializer) const override; }; + +struct CommandInfo : public LLDBBaseTelemetryInfo { + + // If the command is/can be associated with a target entry this field contains + // that target's UUID. otherwise. + std::string target_uuid; + // A unique ID for a command so the manager can match the start entry with + // its end entry. These values only need to be unique within the same session. + // Necessary because we'd send off an entry right before a command's execution + // and another right after. This is to avoid losing telemetry if the command + // does not execute successfully. + int command_id; + + // Eg., "breakpoint set" + std::string command_name; + + // !!NOTE!! These two fields are not collected (upstream) due to PII risks. + // (Downstream impl may add them if needed). + // std::string original_command; + // std::string args; + + lldb::ReturnStatus ret_status; + std::string error_data; + + + CommandInfo() = default; + + llvm::telemetry::KindType getKind() const override { return LLDBEntryKind::CommandInfo; } + + static bool classof(const llvm::telemetry::TelemetryInfo *T) { +return (T->getKind() & LLDBEntryKind::CommandInfo) == LLDBEntryKind::CommandInfo; + } + + void serialize(Serializer &serializer) const override; +}; + /// The base Telemetry manager instance in LLDB. /// This class declares additional instrumentation points /// applicable to LLDB. @@ -63,19 +111,92 @@ class TelemetryManager : public llvm::telemetry::Manager { public: llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override; + int MakeNextCommandId(); + + LLDBConfig* GetConfig() { return m_config.get(); } + virtual llvm::StringRef GetInstanceName() const = 0; static TelemetryManager *getInstance(); protected: - TelemetryManager(std::unique_ptr config); + TelemetryManager(std::unique_ptr config); static void setInstance(std::unique_ptr manger); private: - std::unique_ptr m_config; + std::unique_ptr m_config; + const std::string m_id; + // We assign each command (in the same session) a unique id so that their + // "start" and "end" entries can be matched up. + // These values don't need to be unique across runs (because they are + // secondary-key), hence a simple counter is sufficent. + std::atomic command_id_seed = 0; static std::unique_ptr g_instance; }; +/// Helper RAII class for collecting telemetry. +template struct ScopedDispatcher { + // The debugger pointer is optional because we may not have a debugger yet. + // In that case, caller must set the debugger later. + ScopedDispatcher(Debugger *debugger = nullptr) { +// Sta
[Lldb-commits] [lldb] [lldb-dap] Replace Get{Signed, Unsigned} with GetInteger (NFC) (PR #129823)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/129823 >From 313d37f56eae39b1430417683c704880bcedc531 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Tue, 4 Mar 2025 20:41:17 -0800 Subject: [PATCH] [lldb-dap] Replace Get{Signed,Unsigned} with GetInteger (NFC) Replace Get{Signed,Unsigned} with GetInteger and return std::optional so you can distinguish between the value not being present and it being explicitly set to the previous fail_value. All existing uses are replaced by calling value_or(fail_value). Continuation of #129818 --- lldb/tools/lldb-dap/DAP.cpp | 8 ++-- .../lldb-dap/Handler/AttachRequestHandler.cpp | 7 +-- .../Handler/BreakpointLocationsHandler.cpp| 12 +++-- .../lldb-dap/Handler/CompletionsHandler.cpp | 5 +- .../DataBreakpointInfoRequestHandler.cpp | 2 +- .../Handler/DisassembleRequestHandler.cpp | 5 +- .../Handler/LocationsRequestHandler.cpp | 3 +- .../Handler/ReadMemoryRequestHandler.cpp | 5 +- .../tools/lldb-dap/Handler/RequestHandler.cpp | 3 +- .../Handler/SetVariableRequestHandler.cpp | 5 +- .../lldb-dap/Handler/SourceRequestHandler.cpp | 6 ++- .../Handler/StackTraceRequestHandler.cpp | 5 +- .../lldb-dap/Handler/StepInRequestHandler.cpp | 3 +- .../Handler/VariablesRequestHandler.cpp | 6 +-- lldb/tools/lldb-dap/InstructionBreakpoint.cpp | 2 +- lldb/tools/lldb-dap/JSONUtils.cpp | 16 +-- lldb/tools/lldb-dap/JSONUtils.h | 46 --- lldb/tools/lldb-dap/SourceBreakpoint.cpp | 4 +- 18 files changed, 68 insertions(+), 75 deletions(-) diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index c4790414f64f9..b21b83a79aec7 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -526,12 +526,14 @@ ExceptionBreakpoint *DAP::GetExceptionBPFromStopReason(lldb::SBThread &thread) { } lldb::SBThread DAP::GetLLDBThread(const llvm::json::Object &arguments) { - auto tid = GetSigned(arguments, "threadId", LLDB_INVALID_THREAD_ID); + auto tid = GetInteger(arguments, "threadId") + .value_or(LLDB_INVALID_THREAD_ID); return target.GetProcess().GetThreadByID(tid); } lldb::SBFrame DAP::GetLLDBFrame(const llvm::json::Object &arguments) { - const uint64_t frame_id = GetUnsigned(arguments, "frameId", UINT64_MAX); + const uint64_t frame_id = + GetInteger(arguments, "frameId").value_or(UINT64_MAX); lldb::SBProcess process = target.GetProcess(); // Upper 32 bits is the thread index ID lldb::SBThread thread = @@ -771,7 +773,7 @@ bool DAP::HandleObject(const llvm::json::Object &object) { } if (packet_type == "response") { -auto id = GetSigned(object, "request_seq", 0); +auto id = GetInteger(object, "request_seq").value_or(0); std::unique_ptr response_handler; { diff --git a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp index 2733f58b74683..8f42f5b96b937 100644 --- a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp @@ -54,9 +54,9 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const { const int invalid_port = 0; const auto *arguments = request.getObject("arguments"); const lldb::pid_t pid = - GetUnsigned(arguments, "pid", LLDB_INVALID_PROCESS_ID); + GetInteger(arguments, "pid").value_or(LLDB_INVALID_PROCESS_ID); const auto gdb_remote_port = - GetUnsigned(arguments, "gdb-remote-port", invalid_port); + GetInteger(arguments, "gdb-remote-port").value_or(invalid_port); const auto gdb_remote_hostname = GetString(arguments, "gdb-remote-hostname", "localhost"); if (pid != LLDB_INVALID_PROCESS_ID) @@ -70,7 +70,8 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const { dap.terminate_commands = GetStrings(arguments, "terminateCommands"); auto attachCommands = GetStrings(arguments, "attachCommands"); llvm::StringRef core_file = GetString(arguments, "coreFile"); - const uint64_t timeout_seconds = GetUnsigned(arguments, "timeout", 30); + const auto timeout_seconds = + GetInteger(arguments, "timeout").value_or(30); dap.stop_at_entry = core_file.empty() ? GetBoolean(arguments, "stopOnEntry").value_or(false) : true; diff --git a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp index 1b5c8ba307dcb..468dacfe6737e 100644 --- a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp @@ -131,11 +131,13 @@ void BreakpointLocationsRequestHandler::operator()( auto *arguments = request.getObject("arguments"); auto *source = arguments->getObject("source"); std::string path = GetString(source, "path").str(); -
[Lldb-commits] [lldb] [lldb-dap] Fix: disableASLR launch argument not working. (PR #129753)
@@ -32,12 +32,12 @@ MakeArgv(const llvm::ArrayRef &strs) { } static uint32_t SetLaunchFlag(uint32_t flags, const llvm::json::Object *obj, - llvm::StringRef key, lldb::LaunchFlags mask, - bool default_value) { - if (GetBoolean(obj, key).value_or(default_value)) -flags |= mask; - else -flags &= ~mask; + llvm::StringRef key, lldb::LaunchFlags mask) { + if (const auto opt_value = GetBoolean(obj, key)) +if (opt_value.value()) JDevlieghere wrote: Nit: I don't mind using `opt_value.value()` instead of `*opt_value`, but the latter is much more prevalent in llvm & lldb. ```suggestion if (*opt_value) ``` https://github.com/llvm/llvm-project/pull/129753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Fix: disableASLR launch argument not working. (PR #129753)
https://github.com/JDevlieghere approved this pull request. LGTM. Thanks for bearing with me. https://github.com/llvm/llvm-project/pull/129753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Fix: disableASLR launch argument not working. (PR #129753)
https://github.com/JDevlieghere edited https://github.com/llvm/llvm-project/pull/129753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Define telemetry::CommandInfo (PR #129354)
oontvoo wrote: > > Defind telemetry... > > Define? done https://github.com/llvm/llvm-project/pull/129354 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Defind telemetry::CommandInfo (PR #129354)
@@ -66,6 +80,50 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { void serialize(llvm::telemetry::Serializer &serializer) const override; }; +struct CommandInfo : public LLDBBaseTelemetryInfo { + // If the command is/can be associated with a target entry this field contains + // that target's UUID. otherwise. + UUID target_uuid; + // A unique ID for a command so the manager can match the start entry with + // its end entry. These values only need to be unique within the same session. + // Necessary because we'd send off an entry right before a command's execution + // and another right after. This is to avoid losing telemetry if the command + // does not execute successfully. + uint64_t command_id; + // Eg., "breakpoint set" + std::string command_name; + // !!NOTE!! These two fields are not collected by default due to PII risks. oontvoo wrote: done https://github.com/llvm/llvm-project/pull/129354 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Defind telemetry::CommandInfo (PR #129354)
@@ -66,6 +80,50 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { void serialize(llvm::telemetry::Serializer &serializer) const override; }; +struct CommandInfo : public LLDBBaseTelemetryInfo { + // If the command is/can be associated with a target entry this field contains + // that target's UUID. otherwise. oontvoo wrote: done https://github.com/llvm/llvm-project/pull/129354 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Define telemetry::CommandInfo (PR #129354)
https://github.com/oontvoo edited https://github.com/llvm/llvm-project/pull/129354 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Define telemetry::CommandInfo (PR #129354)
https://github.com/oontvoo edited https://github.com/llvm/llvm-project/pull/129354 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Define telemetry::CommandInfo (PR #129354)
@@ -28,6 +29,17 @@ namespace lldb_private { namespace telemetry { +struct LLDBConfig : public ::llvm::telemetry::Config { + // If true, we will collect full details about a debug command (eg., args and + // original command). Note: This may contain PII, hence can only be enabled by + // the vendor while creating the Manager. + const bool m_detailed_command_telemetry; oontvoo wrote: > Ack, I think this is fine as is. Given that this is a struct, please drop the > m_ prefix. done https://github.com/llvm/llvm-project/pull/129354 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Define telemetry::CommandInfo (PR #129354)
https://github.com/oontvoo updated https://github.com/llvm/llvm-project/pull/129354 >From 5a992aff351a93ff820d15ace3ebc2bea59dd5fc Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Fri, 28 Feb 2025 23:03:35 -0500 Subject: [PATCH 01/20] [LLDB][Telemetry]Defind telemetry::CommandInfo and collect telemetry about a command's execution. --- lldb/include/lldb/Core/Telemetry.h| 127 +- lldb/source/Core/Telemetry.cpp| 14 ++ .../source/Interpreter/CommandInterpreter.cpp | 20 +++ 3 files changed, 158 insertions(+), 3 deletions(-) diff --git a/lldb/include/lldb/Core/Telemetry.h b/lldb/include/lldb/Core/Telemetry.h index b72556ecaf3c9..30b8474156124 100644 --- a/lldb/include/lldb/Core/Telemetry.h +++ b/lldb/include/lldb/Core/Telemetry.h @@ -12,11 +12,14 @@ #include "lldb/Core/StructuredDataImpl.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Utility/StructuredData.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/lldb-forward.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/FunctionExtras.h" #include "llvm/Support/JSON.h" #include "llvm/Telemetry/Telemetry.h" +#include #include #include #include @@ -27,8 +30,16 @@ namespace lldb_private { namespace telemetry { +struct LLDBConfig : public ::llvm::telemetry::Config { + const bool m_collect_original_command; + + explicit LLDBConfig(bool enable_telemetry, bool collect_original_command) + : ::llvm::telemetry::Config(enable_telemetry), m_collect_original_command(collect_original_command) {} +}; + struct LLDBEntryKind : public ::llvm::telemetry::EntryKind { - static const llvm::telemetry::KindType BaseInfo = 0b11000; + static const llvm::telemetry::KindType BaseInfo = 0b1100; + static const llvm::telemetry::KindType CommandInfo = 0b1101; }; /// Defines a convenient type for timestamp of various events. @@ -41,6 +52,7 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { std::optional end_time; // TBD: could add some memory stats here too? + lldb::user_id_t debugger_id = LLDB_INVALID_UID; Debugger *debugger; // For dyn_cast, isa, etc operations. @@ -56,6 +68,42 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { void serialize(llvm::telemetry::Serializer &serializer) const override; }; + +struct CommandInfo : public LLDBBaseTelemetryInfo { + + // If the command is/can be associated with a target entry this field contains + // that target's UUID. otherwise. + std::string target_uuid; + // A unique ID for a command so the manager can match the start entry with + // its end entry. These values only need to be unique within the same session. + // Necessary because we'd send off an entry right before a command's execution + // and another right after. This is to avoid losing telemetry if the command + // does not execute successfully. + int command_id; + + // Eg., "breakpoint set" + std::string command_name; + + // !!NOTE!! These two fields are not collected (upstream) due to PII risks. + // (Downstream impl may add them if needed). + // std::string original_command; + // std::string args; + + lldb::ReturnStatus ret_status; + std::string error_data; + + + CommandInfo() = default; + + llvm::telemetry::KindType getKind() const override { return LLDBEntryKind::CommandInfo; } + + static bool classof(const llvm::telemetry::TelemetryInfo *T) { +return (T->getKind() & LLDBEntryKind::CommandInfo) == LLDBEntryKind::CommandInfo; + } + + void serialize(Serializer &serializer) const override; +}; + /// The base Telemetry manager instance in LLDB. /// This class declares additional instrumentation points /// applicable to LLDB. @@ -63,19 +111,92 @@ class TelemetryManager : public llvm::telemetry::Manager { public: llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override; + int MakeNextCommandId(); + + LLDBConfig* GetConfig() { return m_config.get(); } + virtual llvm::StringRef GetInstanceName() const = 0; static TelemetryManager *getInstance(); protected: - TelemetryManager(std::unique_ptr config); + TelemetryManager(std::unique_ptr config); static void setInstance(std::unique_ptr manger); private: - std::unique_ptr m_config; + std::unique_ptr m_config; + const std::string m_id; + // We assign each command (in the same session) a unique id so that their + // "start" and "end" entries can be matched up. + // These values don't need to be unique across runs (because they are + // secondary-key), hence a simple counter is sufficent. + std::atomic command_id_seed = 0; static std::unique_ptr g_instance; }; +/// Helper RAII class for collecting telemetry. +template struct ScopedDispatcher { + // The debugger pointer is optional because we may not have a debugger yet. + // In that case, caller must set the debugger later. + ScopedDispatcher(Debugger *debugger = nullptr) { +// Sta
[Lldb-commits] [lldb] [lldb-dap] Fix: disableASLR launch argument not working. (PR #129753)
https://github.com/Da-Viper updated https://github.com/llvm/llvm-project/pull/129753 >From 2f773debb694f5684664ea47e545027aeb6e33db Mon Sep 17 00:00:00 2001 From: Ezike Ebuka Date: Wed, 5 Mar 2025 10:32:16 + Subject: [PATCH 1/3] [lldb-dap] Fix: disableASLR launch argument not working. --- .../tools/lldb-dap/Handler/RequestHandler.cpp | 26 ++- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp index d4030965869a1..816397adb26ad 100644 --- a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp @@ -31,7 +31,18 @@ MakeArgv(const llvm::ArrayRef &strs) { return argv; } -// Both attach and launch take a either a sourcePath or sourceMap +static uint32_t SetLaunchFlag(uint32_t flags, const llvm::json::Object *obj, + llvm::StringRef key, lldb::LaunchFlags mask, + bool default_value) { + if (GetBoolean(obj, key).value_or(default_value)) +flags |= mask; + else +flags &= ~mask; + + return flags; +} + +// Both attach and launch take either a sourcePath or a sourceMap // argument (or neither), from which we need to set the target.source-map. void RequestHandler::SetSourceMapFromArguments( const llvm::json::Object &arguments) const { @@ -173,12 +184,13 @@ RequestHandler::LaunchProcess(const llvm::json::Object &request) const { auto flags = launch_info.GetLaunchFlags(); - if (GetBoolean(arguments, "disableASLR").value_or(true)) -flags |= lldb::eLaunchFlagDisableASLR; - if (GetBoolean(arguments, "disableSTDIO").value_or(false)) -flags |= lldb::eLaunchFlagDisableSTDIO; - if (GetBoolean(arguments, "shellExpandArguments").value_or(false)) -flags |= lldb::eLaunchFlagShellExpandArguments; + flags = SetLaunchFlag(flags, arguments, "disableASLR", +lldb::eLaunchFlagDisableASLR, true); + flags = SetLaunchFlag(flags, arguments, "disableSTDIO", +lldb::eLaunchFlagDisableSTDIO, false); + flags = SetLaunchFlag(flags, arguments, "shellExpandArguments", +lldb::eLaunchFlagShellExpandArguments, false); + const bool detachOnError = GetBoolean(arguments, "detachOnError").value_or(false); launch_info.SetDetachOnError(detachOnError); >From 2486994b4077d333869b0687ee8a85fd5179d504 Mon Sep 17 00:00:00 2001 From: Ezike Ebuka Date: Wed, 5 Mar 2025 16:58:49 + Subject: [PATCH 2/3] [lldb] [lldb-dap] do not set a flag if it is not in json object. --- lldb/tools/lldb-dap/Handler/RequestHandler.cpp | 18 +- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp index 816397adb26ad..36669a0596d34 100644 --- a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp @@ -32,12 +32,12 @@ MakeArgv(const llvm::ArrayRef &strs) { } static uint32_t SetLaunchFlag(uint32_t flags, const llvm::json::Object *obj, - llvm::StringRef key, lldb::LaunchFlags mask, - bool default_value) { - if (GetBoolean(obj, key).value_or(default_value)) -flags |= mask; - else -flags &= ~mask; + llvm::StringRef key, lldb::LaunchFlags mask) { + if (const auto opt_value = GetBoolean(obj, key)) +if (opt_value.value()) + flags |= mask; +else + flags &= ~mask; return flags; } @@ -185,11 +185,11 @@ RequestHandler::LaunchProcess(const llvm::json::Object &request) const { auto flags = launch_info.GetLaunchFlags(); flags = SetLaunchFlag(flags, arguments, "disableASLR", -lldb::eLaunchFlagDisableASLR, true); +lldb::eLaunchFlagDisableASLR); flags = SetLaunchFlag(flags, arguments, "disableSTDIO", -lldb::eLaunchFlagDisableSTDIO, false); +lldb::eLaunchFlagDisableSTDIO); flags = SetLaunchFlag(flags, arguments, "shellExpandArguments", -lldb::eLaunchFlagShellExpandArguments, false); +lldb::eLaunchFlagShellExpandArguments); const bool detachOnError = GetBoolean(arguments, "detachOnError").value_or(false); >From e5c13128e39c3d24edfa67515b32af8f9fa81e07 Mon Sep 17 00:00:00 2001 From: Ezike Ebuka Date: Wed, 5 Mar 2025 17:05:14 + Subject: [PATCH 3/3] [lldb] [lldb-dap] fix dangling-else warning --- lldb/tools/lldb-dap/Handler/RequestHandler.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp index 36669a0596d34..dc220bee6fefd 100644 --- a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp @@ -33,11 +33,12 @@
[Lldb-commits] [lldb] [lldb-dap] Implement a MemoryMonitor (PR #129332)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/129332 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] b53e757 - [lldb-dap] Replace Get{Signed, Unsigned} with GetInteger (NFC) (#129823)
Author: Jonas Devlieghere Date: 2025-03-05T09:06:14-08:00 New Revision: b53e75711c284d08b7377385c6f2a037842c0d5b URL: https://github.com/llvm/llvm-project/commit/b53e75711c284d08b7377385c6f2a037842c0d5b DIFF: https://github.com/llvm/llvm-project/commit/b53e75711c284d08b7377385c6f2a037842c0d5b.diff LOG: [lldb-dap] Replace Get{Signed,Unsigned} with GetInteger (NFC) (#129823) Replace Get{Signed,Unsigned} with GetInteger and return std::optional so you can distinguish between the value not being present and it being explicitly set to the previous fail_value. All existing uses are replaced by calling value_or(fail_value). Continuation of #129818 Added: Modified: lldb/tools/lldb-dap/DAP.cpp lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp lldb/tools/lldb-dap/Handler/CompletionsHandler.cpp lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp lldb/tools/lldb-dap/Handler/LocationsRequestHandler.cpp lldb/tools/lldb-dap/Handler/ReadMemoryRequestHandler.cpp lldb/tools/lldb-dap/Handler/RequestHandler.cpp lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp lldb/tools/lldb-dap/Handler/VariablesRequestHandler.cpp lldb/tools/lldb-dap/InstructionBreakpoint.cpp lldb/tools/lldb-dap/JSONUtils.cpp lldb/tools/lldb-dap/JSONUtils.h lldb/tools/lldb-dap/SourceBreakpoint.cpp Removed: diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index c4790414f64f9..b21b83a79aec7 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -526,12 +526,14 @@ ExceptionBreakpoint *DAP::GetExceptionBPFromStopReason(lldb::SBThread &thread) { } lldb::SBThread DAP::GetLLDBThread(const llvm::json::Object &arguments) { - auto tid = GetSigned(arguments, "threadId", LLDB_INVALID_THREAD_ID); + auto tid = GetInteger(arguments, "threadId") + .value_or(LLDB_INVALID_THREAD_ID); return target.GetProcess().GetThreadByID(tid); } lldb::SBFrame DAP::GetLLDBFrame(const llvm::json::Object &arguments) { - const uint64_t frame_id = GetUnsigned(arguments, "frameId", UINT64_MAX); + const uint64_t frame_id = + GetInteger(arguments, "frameId").value_or(UINT64_MAX); lldb::SBProcess process = target.GetProcess(); // Upper 32 bits is the thread index ID lldb::SBThread thread = @@ -771,7 +773,7 @@ bool DAP::HandleObject(const llvm::json::Object &object) { } if (packet_type == "response") { -auto id = GetSigned(object, "request_seq", 0); +auto id = GetInteger(object, "request_seq").value_or(0); std::unique_ptr response_handler; { diff --git a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp index 2733f58b74683..8f42f5b96b937 100644 --- a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp @@ -54,9 +54,9 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const { const int invalid_port = 0; const auto *arguments = request.getObject("arguments"); const lldb::pid_t pid = - GetUnsigned(arguments, "pid", LLDB_INVALID_PROCESS_ID); + GetInteger(arguments, "pid").value_or(LLDB_INVALID_PROCESS_ID); const auto gdb_remote_port = - GetUnsigned(arguments, "gdb-remote-port", invalid_port); + GetInteger(arguments, "gdb-remote-port").value_or(invalid_port); const auto gdb_remote_hostname = GetString(arguments, "gdb-remote-hostname", "localhost"); if (pid != LLDB_INVALID_PROCESS_ID) @@ -70,7 +70,8 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const { dap.terminate_commands = GetStrings(arguments, "terminateCommands"); auto attachCommands = GetStrings(arguments, "attachCommands"); llvm::StringRef core_file = GetString(arguments, "coreFile"); - const uint64_t timeout_seconds = GetUnsigned(arguments, "timeout", 30); + const auto timeout_seconds = + GetInteger(arguments, "timeout").value_or(30); dap.stop_at_entry = core_file.empty() ? GetBoolean(arguments, "stopOnEntry").value_or(false) : true; diff --git a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp index 1b5c8ba307dcb..468dacfe6737e 100644 --- a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp @@ -131,11 +131,13 @@ void BreakpointLocationsRequestHandler::operator()( auto *arguments = request.getObject("arguments"); a
[Lldb-commits] [lldb] [lldb-dap] Replace Get{Signed, Unsigned} with GetInteger (NFC) (PR #129823)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/129823 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation (PR #129733)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/129733 >From da950b7a55c8ee0a35bcfb7e3565fbc11095ab6e Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Tue, 4 Mar 2025 16:14:59 + Subject: [PATCH 1/5] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation --- .../include/lldb/Expression/IRExecutionUnit.h | 6 + lldb/include/lldb/Target/Target.h | 10 lldb/source/Expression/IRExecutionUnit.cpp| 25 ++- .../Clang/ClangExpressionParser.cpp | 3 +++ .../MemoryHistory/asan/MemoryHistoryASan.cpp | 15 +++ 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/lldb/include/lldb/Expression/IRExecutionUnit.h b/lldb/include/lldb/Expression/IRExecutionUnit.h index 58f12bf8b64f5..a0978f9f5063d 100644 --- a/lldb/include/lldb/Expression/IRExecutionUnit.h +++ b/lldb/include/lldb/Expression/IRExecutionUnit.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "llvm/ExecutionEngine/SectionMemoryManager.h" @@ -161,6 +162,10 @@ class IRExecutionUnit : public std::enable_shared_from_this, return m_jitted_global_variables; } + void SetPreferredModules(std::unordered_set modules) { +m_preferred_modules = std::move(modules); + } + private: /// Look up the object in m_address_map that contains a given address, find /// where it was copied to, and return the remote address at the same offset @@ -396,6 +401,7 @@ class IRExecutionUnit : public std::enable_shared_from_this, ///< defining no functions using that variable, would do this.) If this ///< is true, any allocations need to be committed immediately -- no ///< opportunity for relocation. + std::unordered_set m_preferred_modules; }; } // namespace lldb_private diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index f31ac381391b4..369b5633492bb 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -332,6 +332,14 @@ class EvaluateExpressionOptions { m_language = SourceLanguage(language_type); } + void SetPreferredModules(std::unordered_set modules) { +m_preferred_modules = std::move(modules); + } + + const std::unordered_set &GetPreferredModules() const { +return m_preferred_modules; + } + /// Set the language using a pair of language code and version as /// defined by the DWARF 6 specification. /// WARNING: These codes may change until DWARF 6 is finalized. @@ -500,6 +508,8 @@ class EvaluateExpressionOptions { // originates mutable std::string m_pound_line_file; mutable uint32_t m_pound_line_line = 0; + + std::unordered_set m_preferred_modules; }; // Target diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp index c8b4ddf705ec4..8e5f26544c84f 100644 --- a/lldb/source/Expression/IRExecutionUnit.cpp +++ b/lldb/source/Expression/IRExecutionUnit.cpp @@ -52,7 +52,7 @@ IRExecutionUnit::IRExecutionUnit(std::unique_ptr &context_up, m_cpu_features(cpu_features), m_name(name), m_sym_ctx(sym_ctx), m_did_jit(false), m_function_load_addr(LLDB_INVALID_ADDRESS), m_function_end_load_addr(LLDB_INVALID_ADDRESS), - m_reported_allocations(false) {} + m_reported_allocations(false), m_preferred_modules() {} lldb::addr_t IRExecutionUnit::WriteNow(const uint8_t *bytes, size_t size, Status &error) { @@ -785,6 +785,13 @@ IRExecutionUnit::FindInSymbols(const std::vector &names, // We'll process module_sp separately, before the other modules. non_local_images.Remove(sc.module_sp); + ModuleList preferred_images; + // TODO: make m_preferred_modules a ModuleList + for (auto const &m : m_preferred_modules) { +non_local_images.Remove(m); +preferred_images.Append(m); + } + LoadAddressResolver resolver(target, symbol_was_missing_weak); ModuleFunctionSearchOptions function_options; @@ -806,6 +813,14 @@ IRExecutionUnit::FindInSymbols(const std::vector &names, return *load_addr; } +{ + SymbolContextList sc_list; + preferred_images.FindFunctions(name, lldb::eFunctionNameTypeFull, + function_options, sc_list); + if (auto load_addr = resolver.Resolve(sc_list)) +return *load_addr; +} + { SymbolContextList sc_list; non_local_images.FindFunctions(name, lldb::eFunctionNameTypeFull, @@ -822,6 +837,14 @@ IRExecutionUnit::FindInSymbols(const std::vector &names, return *load_addr; } +{ + SymbolContextList sc_list; + preferred_images.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny, + sc_list); + if (auto load_addr = resolver.Resolve(sc_list)) +return *load_addr; +} + { SymbolContextList sc_list; non_local_images.F
[Lldb-commits] [lldb] [lldb] Split test to avoid timeout (PR #129614)
@@ -5,9 +5,9 @@ lldb-server tests run where the lldb-server exe is available. -This class will be broken into smaller test case classes by -gdb remote packet functional areas. For now it contains -the initial set of tests implemented. +The tests are split between the LldbGdbServerTestCase and +LldbGdbServerTestCase2 classes to avoid timeouts in the +test suite. dmpots wrote: Good idea. Updated the comment. https://github.com/llvm/llvm-project/pull/129614 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Split test to avoid timeout (PR #129614)
dmpots wrote: > How many others are close to the limit that you've found, just this one? I was only seeing the one timeout in the runs so I had not thought to measure. It's a good idea though. Based on the timings it looks like maybe `TestGdbRemoteFork.py` is worth splitting as well? That one seems to have about 30 tests in it. `llvm-lit -sv lldb/test --time-test` ``` Slowest Tests: -- 574.78s: lldb-api :: tools/lldb-server/TestGdbRemoteFork.py 405.43s: lldb-api :: tools/lldb-server/TestLldbGdbServer2.py 401.09s: lldb-api :: api/multithreaded/TestMultithreaded.py 392.13s: lldb-api :: tools/lldb-server/TestLldbGdbServer.py 356.85s: lldb-api :: functionalities/completion/TestCompletion.py 302.01s: lldb-api :: tools/lldb-server/TestNonStop.py 296.05s: lldb-api :: functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py 277.37s: lldb-api :: tools/lldb-server/TestGdbRemoteForkNonStop.py 268.45s: lldb-api :: functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py 242.04s: lldb-api :: commands/register/register/register_command/TestRegisters.py 240.33s: lldb-api :: functionalities/single-thread-step/TestSingleThreadStepTimeout.py 237.83s: lldb-api :: commands/statistics/basic/TestStats.py 184.74s: lldb-api :: functionalities/thread/state/TestThreadStates.py 183.73s: lldb-api :: commands/settings/TestSettings.py 178.80s: lldb-api :: tools/lldb-server/vCont-threads/TestSignal.py 175.06s: lldb-api :: tools/lldb-server/TestGdbRemote_vCont.py 158.33s: lldb-api :: functionalities/data-formatter/data-formatter-stl/generic/set/TestDataFormatterGenericSet.py 157.08s: lldb-api :: commands/process/attach/TestProcessAttach.py 156.07s: lldb-api :: tools/lldb-server/TestGdbRemoteLaunch.py 155.51s: lldb-api :: tools/lldb-dap/variables/TestDAP_variables.py Tests Times: -- [ Range ] :: [ Percentage ] :: [ Count ] -- [550s,600s) :: [] :: [ 1/2134] [500s,550s) :: [] :: [ 0/2134] [450s,500s) :: [] :: [ 0/2134] [400s,450s) :: [] :: [ 3/2134] [350s,400s) :: [] :: [ 1/2134] [300s,350s) :: [] :: [ 2/2134] [250s,300s) :: [] :: [ 4/2134] [200s,250s) :: [] :: [ 1/2134] [150s,200s) :: [] :: [ 11/2134] [100s,150s) :: [] :: [ 35/2134] [ 50s,100s) :: [] :: [ 52/2134] [ 0s, 50s) :: [* ] :: [2024/2134] -- ``` https://github.com/llvm/llvm-project/pull/129614 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add complete ObjectFileJSON support for sections. (PR #129916)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Greg Clayton (clayborg) Changes Sections now support specifying: - user IDs - file offset/size - alignment - flags - bool values for fake, encrypted and thread specific sections --- Full diff: https://github.com/llvm/llvm-project/pull/129916.diff 4 Files Affected: - (modified) lldb/include/lldb/Core/Section.h (+11) - (modified) lldb/source/Core/Section.cpp (+19-15) - (modified) lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp (+21-22) - (modified) lldb/test/API/functionalities/json/object-file/TestObjectFileJSON.py (+69-6) ``diff diff --git a/lldb/include/lldb/Core/Section.h b/lldb/include/lldb/Core/Section.h index 17b3cb454949f..f0f5a0b3499c0 100644 --- a/lldb/include/lldb/Core/Section.h +++ b/lldb/include/lldb/Core/Section.h @@ -101,14 +101,25 @@ class SectionList { }; struct JSONSection { + std::optional user_id; std::string name; std::optional type; std::optional address; std::optional size; + std::optional file_offset; + std::optional file_size; + std::optional log2align; + std::optional flags; + // Section permissions; std::optional read; std::optional write; std::optional execute; + + std::optional fake; + std::optional encrypted; + std::optional thread_specific; + std::vector subsections; }; diff --git a/lldb/source/Core/Section.cpp b/lldb/source/Core/Section.cpp index 608e2a5fc3093..b3a0814750aa5 100644 --- a/lldb/source/Core/Section.cpp +++ b/lldb/source/Core/Section.cpp @@ -160,10 +160,9 @@ const char *Section::GetTypeAsCString() const { } Section::Section(const ModuleSP &module_sp, ObjectFile *obj_file, - user_id_t sect_id, ConstString name, - SectionType sect_type, addr_t file_addr, addr_t byte_size, - lldb::offset_t file_offset, lldb::offset_t file_size, - uint32_t log2align, uint32_t flags, + user_id_t sect_id, ConstString name, SectionType sect_type, + addr_t file_addr, addr_t byte_size, lldb::offset_t file_offset, + lldb::offset_t file_size, uint32_t log2align, uint32_t flags, uint32_t target_byte_size /*=1*/) : ModuleChild(module_sp), UserID(sect_id), Flags(flags), m_obj_file(obj_file), m_type(sect_type), m_parent_wp(), m_name(name), @@ -171,15 +170,14 @@ Section::Section(const ModuleSP &module_sp, ObjectFile *obj_file, m_file_offset(file_offset), m_file_size(file_size), m_log2align(log2align), m_children(), m_fake(false), m_encrypted(false), m_thread_specific(false), m_readable(false), m_writable(false), - m_executable(false), m_relocated(false), m_target_byte_size(target_byte_size) { -} + m_executable(false), m_relocated(false), + m_target_byte_size(target_byte_size) {} Section::Section(const lldb::SectionSP &parent_section_sp, const ModuleSP &module_sp, ObjectFile *obj_file, - user_id_t sect_id, ConstString name, - SectionType sect_type, addr_t file_addr, addr_t byte_size, - lldb::offset_t file_offset, lldb::offset_t file_size, - uint32_t log2align, uint32_t flags, + user_id_t sect_id, ConstString name, SectionType sect_type, + addr_t file_addr, addr_t byte_size, lldb::offset_t file_offset, + lldb::offset_t file_size, uint32_t log2align, uint32_t flags, uint32_t target_byte_size /*=1*/) : ModuleChild(module_sp), UserID(sect_id), Flags(flags), m_obj_file(obj_file), m_type(sect_type), m_parent_wp(), m_name(name), @@ -187,7 +185,8 @@ Section::Section(const lldb::SectionSP &parent_section_sp, m_file_offset(file_offset), m_file_size(file_size), m_log2align(log2align), m_children(), m_fake(false), m_encrypted(false), m_thread_specific(false), m_readable(false), m_writable(false), - m_executable(false), m_relocated(false), m_target_byte_size(target_byte_size) { + m_executable(false), m_relocated(false), + m_target_byte_size(target_byte_size) { if (parent_section_sp) m_parent_wp = parent_section_sp; } @@ -469,7 +468,6 @@ bool Section::ContainsOnlyDebugInfo() const { return false; } - #pragma mark SectionList SectionList &SectionList::operator=(const SectionList &rhs) { @@ -554,8 +552,7 @@ SectionSP SectionList::GetSectionAtIndex(size_t idx) const { return sect_sp; } -SectionSP -SectionList::FindSectionByName(ConstString section_dstr) const { +SectionSP SectionList::FindSectionByName(ConstString section_dstr) const { SectionSP sect_sp; // Check if we have a valid section string if (section_dstr && !m_sections.empty()) { @@ -693,7 +690,14 @@ bool fromJSON(const llvm::json::Value &value, o.map("address", section.address) && o.map("size", section.size) && o.map("read", section.read) && o.map("write", section.write) && o.map("execute"
[Lldb-commits] [lldb] Add complete ObjectFileJSON support for sections. (PR #129916)
https://github.com/clayborg created https://github.com/llvm/llvm-project/pull/129916 Sections now support specifying: - user IDs - file offset/size - alignment - flags - bool values for fake, encrypted and thread specific sections >From 150bbe0d8c3e2fb4e2dd324a0d9080a462eda156 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Wed, 5 Mar 2025 11:21:40 -0800 Subject: [PATCH] Add complete ObjectFileJSON support for sections. Sections now support specifying: - user IDs - file offset/size - alignment - flags - bool values for fake, encrypted and thread specific sections --- lldb/include/lldb/Core/Section.h | 11 +++ lldb/source/Core/Section.cpp | 34 + .../ObjectFile/JSON/ObjectFileJSON.cpp| 43 ++- .../json/object-file/TestObjectFileJSON.py| 75 +-- 4 files changed, 120 insertions(+), 43 deletions(-) diff --git a/lldb/include/lldb/Core/Section.h b/lldb/include/lldb/Core/Section.h index 17b3cb454949f..f0f5a0b3499c0 100644 --- a/lldb/include/lldb/Core/Section.h +++ b/lldb/include/lldb/Core/Section.h @@ -101,14 +101,25 @@ class SectionList { }; struct JSONSection { + std::optional user_id; std::string name; std::optional type; std::optional address; std::optional size; + std::optional file_offset; + std::optional file_size; + std::optional log2align; + std::optional flags; + // Section permissions; std::optional read; std::optional write; std::optional execute; + + std::optional fake; + std::optional encrypted; + std::optional thread_specific; + std::vector subsections; }; diff --git a/lldb/source/Core/Section.cpp b/lldb/source/Core/Section.cpp index 608e2a5fc3093..b3a0814750aa5 100644 --- a/lldb/source/Core/Section.cpp +++ b/lldb/source/Core/Section.cpp @@ -160,10 +160,9 @@ const char *Section::GetTypeAsCString() const { } Section::Section(const ModuleSP &module_sp, ObjectFile *obj_file, - user_id_t sect_id, ConstString name, - SectionType sect_type, addr_t file_addr, addr_t byte_size, - lldb::offset_t file_offset, lldb::offset_t file_size, - uint32_t log2align, uint32_t flags, + user_id_t sect_id, ConstString name, SectionType sect_type, + addr_t file_addr, addr_t byte_size, lldb::offset_t file_offset, + lldb::offset_t file_size, uint32_t log2align, uint32_t flags, uint32_t target_byte_size /*=1*/) : ModuleChild(module_sp), UserID(sect_id), Flags(flags), m_obj_file(obj_file), m_type(sect_type), m_parent_wp(), m_name(name), @@ -171,15 +170,14 @@ Section::Section(const ModuleSP &module_sp, ObjectFile *obj_file, m_file_offset(file_offset), m_file_size(file_size), m_log2align(log2align), m_children(), m_fake(false), m_encrypted(false), m_thread_specific(false), m_readable(false), m_writable(false), - m_executable(false), m_relocated(false), m_target_byte_size(target_byte_size) { -} + m_executable(false), m_relocated(false), + m_target_byte_size(target_byte_size) {} Section::Section(const lldb::SectionSP &parent_section_sp, const ModuleSP &module_sp, ObjectFile *obj_file, - user_id_t sect_id, ConstString name, - SectionType sect_type, addr_t file_addr, addr_t byte_size, - lldb::offset_t file_offset, lldb::offset_t file_size, - uint32_t log2align, uint32_t flags, + user_id_t sect_id, ConstString name, SectionType sect_type, + addr_t file_addr, addr_t byte_size, lldb::offset_t file_offset, + lldb::offset_t file_size, uint32_t log2align, uint32_t flags, uint32_t target_byte_size /*=1*/) : ModuleChild(module_sp), UserID(sect_id), Flags(flags), m_obj_file(obj_file), m_type(sect_type), m_parent_wp(), m_name(name), @@ -187,7 +185,8 @@ Section::Section(const lldb::SectionSP &parent_section_sp, m_file_offset(file_offset), m_file_size(file_size), m_log2align(log2align), m_children(), m_fake(false), m_encrypted(false), m_thread_specific(false), m_readable(false), m_writable(false), - m_executable(false), m_relocated(false), m_target_byte_size(target_byte_size) { + m_executable(false), m_relocated(false), + m_target_byte_size(target_byte_size) { if (parent_section_sp) m_parent_wp = parent_section_sp; } @@ -469,7 +468,6 @@ bool Section::ContainsOnlyDebugInfo() const { return false; } - #pragma mark SectionList SectionList &SectionList::operator=(const SectionList &rhs) { @@ -554,8 +552,7 @@ SectionSP SectionList::GetSectionAtIndex(size_t idx) const { return sect_sp; } -SectionSP -SectionList::FindSectionByName(ConstString section_dstr) const { +SectionSP SectionList::FindSectionByName(ConstString section_dstr) const { SectionSP sect_sp; // Check if we have a valid section string if (section_dstr
[Lldb-commits] [lldb] [lldb] Upgrade CompilerType::GetBitSize to return llvm::Expected (PR #129601)
@@ -1104,10 +1107,18 @@ bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data, if (encoding == lldb::eEncodingInvalid || count != 1) return false; -std::optional byte_size = GetByteSize(exe_scope); +auto byte_size_or_err = GetByteSize(exe_scope); +if (!byte_size_or_err) { + LLDB_LOG_ERRORV( + GetLog(LLDBLog::Types), byte_size_or_err.takeError(), + "Cannot get value as scalar; cannot determine type size: {0}"); JDevlieghere wrote: ```suggestion "Cannot get value as scalar: cannot determine type size: {0}"); ``` https://github.com/llvm/llvm-project/pull/129601 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Fix: disableASLR launch argument not working. (PR #129753)
Da-Viper wrote: Different timezone, updated the commit with the new changes. https://github.com/llvm/llvm-project/pull/129753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation (PR #129733)
https://github.com/Michael137 edited https://github.com/llvm/llvm-project/pull/129733 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation (PR #129733)
https://github.com/Michael137 edited https://github.com/llvm/llvm-project/pull/129733 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Fix: disableASLR launch argument not working. (PR #129753)
@@ -173,12 +184,13 @@ RequestHandler::LaunchProcess(const llvm::json::Object &request) const { auto flags = launch_info.GetLaunchFlags(); - if (GetBoolean(arguments, "disableASLR").value_or(true)) -flags |= lldb::eLaunchFlagDisableASLR; - if (GetBoolean(arguments, "disableSTDIO").value_or(false)) -flags |= lldb::eLaunchFlagDisableSTDIO; - if (GetBoolean(arguments, "shellExpandArguments").value_or(false)) -flags |= lldb::eLaunchFlagShellExpandArguments; + flags = SetLaunchFlag(flags, arguments, "disableASLR", +lldb::eLaunchFlagDisableASLR, true); + flags = SetLaunchFlag(flags, arguments, "disableSTDIO", +lldb::eLaunchFlagDisableSTDIO, false); + flags = SetLaunchFlag(flags, arguments, "shellExpandArguments", +lldb::eLaunchFlagShellExpandArguments, false); JDevlieghere wrote: ```suggestion flags = SetLaunchFlag(flags, arguments, "disableASLR", lldb::eLaunchFlagDisableASLR); flags = SetLaunchFlag(flags, arguments, "disableSTDIO", lldb::eLaunchFlagDisableSTDIO); flags = SetLaunchFlag(flags, arguments, "shellExpandArguments", lldb::eLaunchFlagShellExpandArguments); ``` https://github.com/llvm/llvm-project/pull/129753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Fix: disableASLR launch argument not working. (PR #129753)
@@ -31,7 +31,18 @@ MakeArgv(const llvm::ArrayRef &strs) { return argv; } -// Both attach and launch take a either a sourcePath or sourceMap +static uint32_t SetLaunchFlag(uint32_t flags, const llvm::json::Object *obj, + llvm::StringRef key, lldb::LaunchFlags mask, + bool default_value) { + if (GetBoolean(obj, key).value_or(default_value)) +flags |= mask; + else +flags &= ~mask; + + return flags; +} JDevlieghere wrote: This still doesn't distinguish between the value not being set and the value being set to `true` or `false`. Here's what I was suggesting: ```suggestion static uint32_t SetLaunchFlag(uint32_t flags, const llvm::json::Object *obj, llvm::StringRef key, lldb::LaunchFlags mask) { if (auto b = GetBoolean(obj, key)) { if (*b) flags |= mask; else flags &= ~mask; } return flags; } ``` https://github.com/llvm/llvm-project/pull/129753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Defind telemetry::CommandInfo (PR #129354)
@@ -66,6 +80,50 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { void serialize(llvm::telemetry::Serializer &serializer) const override; }; +struct CommandInfo : public LLDBBaseTelemetryInfo { + // If the command is/can be associated with a target entry this field contains + // that target's UUID. otherwise. JDevlieghere wrote: These should be Doxygen comments (`///`) https://github.com/llvm/llvm-project/pull/129354 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Defind telemetry::CommandInfo (PR #129354)
@@ -28,6 +29,17 @@ namespace lldb_private { namespace telemetry { +struct LLDBConfig : public ::llvm::telemetry::Config { + // If true, we will collect full details about a debug command (eg., args and + // original command). Note: This may contain PII, hence can only be enabled by + // the vendor while creating the Manager. + const bool m_detailed_command_telemetry; JDevlieghere wrote: Ack, I think this is fine as is. Given that this is a `struct`, please drop the `m_` prefix. ```suggestion // If true, we will collect full details about a debug command (eg., args and // original command). Note: This may contain PII, hence can only be enabled by // the vendor while creating the Manager. const bool detailed_command_telemetry; ``` https://github.com/llvm/llvm-project/pull/129354 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Defind telemetry::CommandInfo (PR #129354)
@@ -66,6 +80,50 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { void serialize(llvm::telemetry::Serializer &serializer) const override; }; +struct CommandInfo : public LLDBBaseTelemetryInfo { + // If the command is/can be associated with a target entry this field contains + // that target's UUID. otherwise. + UUID target_uuid; + // A unique ID for a command so the manager can match the start entry with + // its end entry. These values only need to be unique within the same session. + // Necessary because we'd send off an entry right before a command's execution + // and another right after. This is to avoid losing telemetry if the command + // does not execute successfully. + uint64_t command_id; + // Eg., "breakpoint set" + std::string command_name; + // !!NOTE!! These two fields are not collected by default due to PII risks. JDevlieghere wrote: Drop the `!!NOTE!!`, or use `Note that`. ```suggestion // These two fields are not collected by default due to PII risks. ``` When comments apply to multiple lines, you can use Doxygen groups: ``` /// Comment spanning multiple things /// @{ thing one; thing two; /// @} ``` https://github.com/llvm/llvm-project/pull/129354 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Defind telemetry::CommandInfo (PR #129354)
https://github.com/JDevlieghere edited https://github.com/llvm/llvm-project/pull/129354 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB]Fix test crash (PR #129921)
https://github.com/oontvoo created https://github.com/llvm/llvm-project/pull/129921 Unregister the fake manager at end of test (https://github.com/llvm/llvm-project/issues/129910) >From 38f07a83ff621ae4879e4b0cbc8bd361d0b12a93 Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Wed, 5 Mar 2025 14:45:24 -0500 Subject: [PATCH] [LLDB]Fix test crash Unregister the fake manager at end of test (https://github.com/llvm/llvm-project/issues/129910) --- lldb/unittests/Core/TelemetryTest.cpp | 8 +++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lldb/unittests/Core/TelemetryTest.cpp b/lldb/unittests/Core/TelemetryTest.cpp index 0e9f329110872..5b762ae816362 100644 --- a/lldb/unittests/Core/TelemetryTest.cpp +++ b/lldb/unittests/Core/TelemetryTest.cpp @@ -11,6 +11,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" #include "llvm/Telemetry/Telemetry.h" +#include "TestingSupport/SubsystemRAII.h" #include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" #include @@ -77,8 +78,13 @@ class FakePlugin : public telemetry::TelemetryManager { using namespace lldb_private::telemetry; +class TelemetryTest : public testing::Test { + public: + SubsystemRAII subsystems; +}; + #if LLVM_ENABLE_TELEMETRY -#define TELEMETRY_TEST(suite, test) TEST(suite, test) +#define TELEMETRY_TEST(suite, test) TEST_F(suite, test) #else #define TELEMETRY_TEST(suite, test) TEST(DISABLED_##suite, test) #endif ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB]Fix test crash (PR #129921)
https://github.com/oontvoo edited https://github.com/llvm/llvm-project/pull/129921 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB]Fix test crash (PR #129921)
https://github.com/oontvoo edited https://github.com/llvm/llvm-project/pull/129921 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB]Fix test crash (PR #129921)
https://github.com/oontvoo updated https://github.com/llvm/llvm-project/pull/129921 >From 38f07a83ff621ae4879e4b0cbc8bd361d0b12a93 Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Wed, 5 Mar 2025 14:45:24 -0500 Subject: [PATCH 1/3] [LLDB]Fix test crash Unregister the fake manager at end of test (https://github.com/llvm/llvm-project/issues/129910) --- lldb/unittests/Core/TelemetryTest.cpp | 8 +++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lldb/unittests/Core/TelemetryTest.cpp b/lldb/unittests/Core/TelemetryTest.cpp index 0e9f329110872..5b762ae816362 100644 --- a/lldb/unittests/Core/TelemetryTest.cpp +++ b/lldb/unittests/Core/TelemetryTest.cpp @@ -11,6 +11,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" #include "llvm/Telemetry/Telemetry.h" +#include "TestingSupport/SubsystemRAII.h" #include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" #include @@ -77,8 +78,13 @@ class FakePlugin : public telemetry::TelemetryManager { using namespace lldb_private::telemetry; +class TelemetryTest : public testing::Test { + public: + SubsystemRAII subsystems; +}; + #if LLVM_ENABLE_TELEMETRY -#define TELEMETRY_TEST(suite, test) TEST(suite, test) +#define TELEMETRY_TEST(suite, test) TEST_F(suite, test) #else #define TELEMETRY_TEST(suite, test) TEST(DISABLED_##suite, test) #endif >From 96670f1bf7de08dc5606e3fdf51526fe759a9279 Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Wed, 5 Mar 2025 14:52:55 -0500 Subject: [PATCH 2/3] format --- lldb/unittests/Core/TelemetryTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lldb/unittests/Core/TelemetryTest.cpp b/lldb/unittests/Core/TelemetryTest.cpp index 5b762ae816362..c7edb0f92fde2 100644 --- a/lldb/unittests/Core/TelemetryTest.cpp +++ b/lldb/unittests/Core/TelemetryTest.cpp @@ -5,13 +5,13 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===--===// +#include "lldb/Core/Telemetry.h" +#include "TestingSupport/SubsystemRAII.h" #include "lldb/Core/PluginInterface.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/Telemetry.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" #include "llvm/Telemetry/Telemetry.h" -#include "TestingSupport/SubsystemRAII.h" #include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" #include @@ -79,7 +79,7 @@ class FakePlugin : public telemetry::TelemetryManager { using namespace lldb_private::telemetry; class TelemetryTest : public testing::Test { - public: +public: SubsystemRAII subsystems; }; >From 6161c7fa06e5316ee29a48434af9db54270c762f Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Wed, 5 Mar 2025 14:54:29 -0500 Subject: [PATCH 3/3] qual --- lldb/unittests/Core/TelemetryTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/unittests/Core/TelemetryTest.cpp b/lldb/unittests/Core/TelemetryTest.cpp index c7edb0f92fde2..2865a44654ee5 100644 --- a/lldb/unittests/Core/TelemetryTest.cpp +++ b/lldb/unittests/Core/TelemetryTest.cpp @@ -80,7 +80,7 @@ using namespace lldb_private::telemetry; class TelemetryTest : public testing::Test { public: - SubsystemRAII subsystems; + SubsystemRAII subsystems; }; #if LLVM_ENABLE_TELEMETRY ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Let languages see all SymbolContexts at once when filtering breakpoints (PR #129937)
https://github.com/jimingham approved this pull request. I can't see how this would hurt, and there no guarantee anywhere that these potential hits will be treated strictly independently. So this LGTM. https://github.com/llvm/llvm-project/pull/129937 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation (PR #129733)
@@ -161,6 +162,12 @@ class IRExecutionUnit : public std::enable_shared_from_this, return m_jitted_global_variables; } + void SetPreferredModules(SymbolContextList const &modules) { jimingham wrote: This is called `SetPreferredModules` but is actually `AppendToPreferredModules`. https://github.com/llvm/llvm-project/pull/129733 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation (PR #129733)
@@ -161,6 +162,12 @@ class IRExecutionUnit : public std::enable_shared_from_this, return m_jitted_global_variables; } + void SetPreferredModules(SymbolContextList const &modules) { jimingham wrote: Also, these are no longer `modules` you should change the names to reflect that. https://github.com/llvm/llvm-project/pull/129733 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation (PR #129733)
@@ -396,6 +403,11 @@ class IRExecutionUnit : public std::enable_shared_from_this, ///< defining no functions using that variable, would do this.) If this ///< is true, any allocations need to be committed immediately -- no ///< opportunity for relocation. + + ///< Any Module in this list will be used for symbol/function lookup jimingham wrote: Again, no longer Modules... https://github.com/llvm/llvm-project/pull/129733 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Let languages see all SymbolContexts at once when filtering breakpoints (PR #129937)
@@ -354,14 +354,13 @@ class Language : public PluginInterface { virtual llvm::StringRef GetInstanceVariableName() { return {}; } - /// Returns true if this SymbolContext should be ignored when setting - /// breakpoints by line (number or regex). Helpful for languages that create - /// artificial functions without meaningful user code associated with them - /// (e.g. code that gets expanded in late compilation stages, like by - /// CoroSplitter). - virtual bool IgnoreForLineBreakpoints(const SymbolContext &) const { -return false; - } + /// Given a symbol context list of matches which supposedly represent the + /// same file and line number in a CU, erases those that should be ignored + /// when setting breakpoints by line (number or regex). Helpful for languages + /// that create split a single source-line into many functions (e.g. call + /// sites transformed by CoroSplitter). + virtual void + FilterForLineBreakpoints(llvm::SmallVectorImpl &) const {} felipepiovezan wrote: I suspect because it intends to manipulate the contents of the list heavily (like this method will) https://github.com/llvm/llvm-project/pull/129937 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 275eab9 - [LLDB]Fix test crash (#129921)
Author: Vy Nguyen Date: 2025-03-05T17:36:06-05:00 New Revision: 275eab91edba816b5c98828c53b7f21afd97dbd9 URL: https://github.com/llvm/llvm-project/commit/275eab91edba816b5c98828c53b7f21afd97dbd9 DIFF: https://github.com/llvm/llvm-project/commit/275eab91edba816b5c98828c53b7f21afd97dbd9.diff LOG: [LLDB]Fix test crash (#129921) Use the `SubsystemRAII` to unregister the fake manager at end of tests (Should fix https://github.com/llvm/llvm-project/issues/129910) Added: Modified: lldb/unittests/Core/TelemetryTest.cpp Removed: diff --git a/lldb/unittests/Core/TelemetryTest.cpp b/lldb/unittests/Core/TelemetryTest.cpp index 0e9f329110872..7fc2b3d0264e3 100644 --- a/lldb/unittests/Core/TelemetryTest.cpp +++ b/lldb/unittests/Core/TelemetryTest.cpp @@ -5,9 +5,10 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===--===// +#include "lldb/Core/Telemetry.h" +#include "TestingSupport/SubsystemRAII.h" #include "lldb/Core/PluginInterface.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/Telemetry.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" #include "llvm/Telemetry/Telemetry.h" @@ -77,8 +78,13 @@ class FakePlugin : public telemetry::TelemetryManager { using namespace lldb_private::telemetry; +class TelemetryTest : public testing::Test { +public: + lldb_private::SubsystemRAII subsystems; +}; + #if LLVM_ENABLE_TELEMETRY -#define TELEMETRY_TEST(suite, test) TEST(suite, test) +#define TELEMETRY_TEST(suite, test) TEST_F(suite, test) #else #define TELEMETRY_TEST(suite, test) TEST(DISABLED_##suite, test) #endif ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Use LLDB_INVALID_LINE_NUMBER & LLDB_INVALID_COLUMN_NUMBER (PR #129948)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/129948 Consistently use LLDB_INVALID_LINE_NUMBER & LLDB_INVALID_COLUMN_NUMBER when parsing line and column numbers respectively. >From 886bcf62cca14748bf7978062d310842416f95a0 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 5 Mar 2025 14:24:12 -0800 Subject: [PATCH] [lldb-dap] Use LLDB_INVALID_LINE_NUMBER & LLDB_INVALID_COLUMN_NUMBER Consistently use LLDB_INVALID_LINE_NUMBER & LLDB_INVALID_COLUMN_NUMBER when parsing line and column numbers respectively. --- lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp | 7 --- lldb/tools/lldb-dap/SourceBreakpoint.cpp | 6 -- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp index 468dacfe6737e..d6efd659ae8e0 100644 --- a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp @@ -131,9 +131,10 @@ void BreakpointLocationsRequestHandler::operator()( auto *arguments = request.getObject("arguments"); auto *source = arguments->getObject("source"); std::string path = GetString(source, "path").str(); - const auto start_line = GetInteger(arguments, "line").value_or(0); - const auto start_column = - GetInteger(arguments, "column").value_or(0); + const auto start_line = GetInteger(arguments, "line") + .value_or(LLDB_INVALID_LINE_NUMBER); + const auto start_column = GetInteger(arguments, "column") +.value_or(LLDB_INVALID_COLUMN_NUMBER); const auto end_line = GetInteger(arguments, "endLine").value_or(start_line); const auto end_column = GetInteger(arguments, "endColumn") diff --git a/lldb/tools/lldb-dap/SourceBreakpoint.cpp b/lldb/tools/lldb-dap/SourceBreakpoint.cpp index 37341fa387d40..7742dce2928b5 100644 --- a/lldb/tools/lldb-dap/SourceBreakpoint.cpp +++ b/lldb/tools/lldb-dap/SourceBreakpoint.cpp @@ -27,8 +27,10 @@ namespace lldb_dap { SourceBreakpoint::SourceBreakpoint(DAP &dap, const llvm::json::Object &obj) : Breakpoint(dap, obj), logMessage(std::string(GetString(obj, "logMessage"))), - line(GetInteger(obj, "line").value_or(0)), - column(GetInteger(obj, "column").value_or(0)) {} + line( + GetInteger(obj, "line").value_or(LLDB_INVALID_LINE_NUMBER)), + column(GetInteger(obj, "column") + .value_or(LLDB_INVALID_COLUMN_NUMBER)) {} void SourceBreakpoint::SetBreakpoint(const llvm::StringRef source_path) { lldb::SBFileSpecList module_list; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Use LLDB_INVALID_LINE_NUMBER & LLDB_INVALID_COLUMN_NUMBER (PR #129948)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes Consistently use LLDB_INVALID_LINE_NUMBER & LLDB_INVALID_COLUMN_NUMBER when parsing line and column numbers respectively. --- Full diff: https://github.com/llvm/llvm-project/pull/129948.diff 2 Files Affected: - (modified) lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp (+4-3) - (modified) lldb/tools/lldb-dap/SourceBreakpoint.cpp (+4-2) ``diff diff --git a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp index 468dacfe6737e..d6efd659ae8e0 100644 --- a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp @@ -131,9 +131,10 @@ void BreakpointLocationsRequestHandler::operator()( auto *arguments = request.getObject("arguments"); auto *source = arguments->getObject("source"); std::string path = GetString(source, "path").str(); - const auto start_line = GetInteger(arguments, "line").value_or(0); - const auto start_column = - GetInteger(arguments, "column").value_or(0); + const auto start_line = GetInteger(arguments, "line") + .value_or(LLDB_INVALID_LINE_NUMBER); + const auto start_column = GetInteger(arguments, "column") +.value_or(LLDB_INVALID_COLUMN_NUMBER); const auto end_line = GetInteger(arguments, "endLine").value_or(start_line); const auto end_column = GetInteger(arguments, "endColumn") diff --git a/lldb/tools/lldb-dap/SourceBreakpoint.cpp b/lldb/tools/lldb-dap/SourceBreakpoint.cpp index 37341fa387d40..7742dce2928b5 100644 --- a/lldb/tools/lldb-dap/SourceBreakpoint.cpp +++ b/lldb/tools/lldb-dap/SourceBreakpoint.cpp @@ -27,8 +27,10 @@ namespace lldb_dap { SourceBreakpoint::SourceBreakpoint(DAP &dap, const llvm::json::Object &obj) : Breakpoint(dap, obj), logMessage(std::string(GetString(obj, "logMessage"))), - line(GetInteger(obj, "line").value_or(0)), - column(GetInteger(obj, "column").value_or(0)) {} + line( + GetInteger(obj, "line").value_or(LLDB_INVALID_LINE_NUMBER)), + column(GetInteger(obj, "column") + .value_or(LLDB_INVALID_COLUMN_NUMBER)) {} void SourceBreakpoint::SetBreakpoint(const llvm::StringRef source_path) { lldb::SBFileSpecList module_list; `` https://github.com/llvm/llvm-project/pull/129948 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Let languages see all SymbolContexts at once when filtering breakpoints (PR #129937)
@@ -354,14 +354,13 @@ class Language : public PluginInterface { virtual llvm::StringRef GetInstanceVariableName() { return {}; } - /// Returns true if this SymbolContext should be ignored when setting - /// breakpoints by line (number or regex). Helpful for languages that create - /// artificial functions without meaningful user code associated with them - /// (e.g. code that gets expanded in late compilation stages, like by - /// CoroSplitter). - virtual bool IgnoreForLineBreakpoints(const SymbolContext &) const { -return false; - } + /// Given a symbol context list of matches which supposedly represent the + /// same file and line number in a CU, erases those that should be ignored + /// when setting breakpoints by line (number or regex). Helpful for languages + /// that create split a single source-line into many functions (e.g. call + /// sites transformed by CoroSplitter). + virtual void + FilterForLineBreakpoints(llvm::SmallVectorImpl &) const {} felipepiovezan wrote: The callsite doesn't use that https://github.com/llvm/llvm-project/pull/129937 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB]Fix test crash (PR #129921)
https://github.com/oontvoo closed https://github.com/llvm/llvm-project/pull/129921 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" walter-erquinigo wrote: TIL https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Return optional from json utils (PR #129919)
https://github.com/Da-Viper created https://github.com/llvm/llvm-project/pull/129919 Completion of #129818 Did not want to put `llvm::StringRef()` as the default value instead it was `""` >From 14bd9a79299f2637dc400fa2bf718770674c38b0 Mon Sep 17 00:00:00 2001 From: Ezike Ebuka Date: Wed, 5 Mar 2025 11:15:35 + Subject: [PATCH 1/3] [lldb] [lldb-dap] Return optional values for unsigned json values. --- lldb/tools/lldb-dap/DAP.cpp | 3 ++- .../lldb-dap/Handler/AttachRequestHandler.cpp | 7 --- .../Handler/BreakpointLocationsHandler.cpp | 12 +++- .../DataBreakpointInfoRequestHandler.cpp| 2 +- .../Handler/DisassembleRequestHandler.cpp | 3 ++- .../Handler/LocationsRequestHandler.cpp | 3 ++- .../Handler/ReadMemoryRequestHandler.cpp| 2 +- lldb/tools/lldb-dap/Handler/RequestHandler.cpp | 3 ++- .../Handler/SetVariableRequestHandler.cpp | 4 ++-- .../lldb-dap/Handler/SourceRequestHandler.cpp | 5 +++-- .../Handler/StackTraceRequestHandler.cpp| 4 ++-- .../lldb-dap/Handler/StepInRequestHandler.cpp | 2 +- .../Handler/VariablesRequestHandler.cpp | 2 +- lldb/tools/lldb-dap/JSONUtils.cpp | 17 - lldb/tools/lldb-dap/JSONUtils.h | 10 +- lldb/tools/lldb-dap/SourceBreakpoint.cpp| 4 ++-- 16 files changed, 45 insertions(+), 38 deletions(-) diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index c4790414f64f9..e908e4d7115f7 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -531,7 +531,8 @@ lldb::SBThread DAP::GetLLDBThread(const llvm::json::Object &arguments) { } lldb::SBFrame DAP::GetLLDBFrame(const llvm::json::Object &arguments) { - const uint64_t frame_id = GetUnsigned(arguments, "frameId", UINT64_MAX); + const uint64_t frame_id = + GetUnsigned(arguments, "frameId").value_or(UINT64_MAX); lldb::SBProcess process = target.GetProcess(); // Upper 32 bits is the thread index ID lldb::SBThread thread = diff --git a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp index 2733f58b74683..b2556f7ddff1c 100644 --- a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp @@ -54,9 +54,9 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const { const int invalid_port = 0; const auto *arguments = request.getObject("arguments"); const lldb::pid_t pid = - GetUnsigned(arguments, "pid", LLDB_INVALID_PROCESS_ID); + GetUnsigned(arguments, "pid").value_or(LLDB_INVALID_PROCESS_ID); const auto gdb_remote_port = - GetUnsigned(arguments, "gdb-remote-port", invalid_port); + GetUnsigned(arguments, "gdb-remote-port").value_or(invalid_port); const auto gdb_remote_hostname = GetString(arguments, "gdb-remote-hostname", "localhost"); if (pid != LLDB_INVALID_PROCESS_ID) @@ -70,7 +70,8 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const { dap.terminate_commands = GetStrings(arguments, "terminateCommands"); auto attachCommands = GetStrings(arguments, "attachCommands"); llvm::StringRef core_file = GetString(arguments, "coreFile"); - const uint64_t timeout_seconds = GetUnsigned(arguments, "timeout", 30); + const uint64_t timeout_seconds = + GetUnsigned(arguments, "timeout").value_or(30); dap.stop_at_entry = core_file.empty() ? GetBoolean(arguments, "stopOnEntry").value_or(false) : true; diff --git a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp index 1b5c8ba307dcb..50b530349d0e4 100644 --- a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp @@ -131,11 +131,13 @@ void BreakpointLocationsRequestHandler::operator()( auto *arguments = request.getObject("arguments"); auto *source = arguments->getObject("source"); std::string path = GetString(source, "path").str(); - uint64_t start_line = GetUnsigned(arguments, "line", 0); - uint64_t start_column = GetUnsigned(arguments, "column", 0); - uint64_t end_line = GetUnsigned(arguments, "endLine", start_line); - uint64_t end_column = - GetUnsigned(arguments, "endColumn", std::numeric_limits::max()); + const uint64_t start_line = GetUnsigned(arguments, "line").value_or(0); + const uint64_t start_column = GetUnsigned(arguments, "column").value_or(0); + const uint64_t end_line = + GetUnsigned(arguments, "endLine").value_or(start_line); + const uint64_t end_column = + GetUnsigned(arguments, "endColumn") + .value_or(std::numeric_limits::max()); lldb::SBFileSpec file_spec(path.c_str(), true); lldb::SBSymbolContextList compile_units = diff --git a/lldb/tools/lldb-dap/Handler/DataBreakpointIn
[Lldb-commits] [lldb] Return optional from json utils (PR #129919)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: None (Da-Viper) Changes Completion of #129818 Did not want to put `llvm::StringRef()` as the default value instead it was `""` --- Patch is 34.46 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/129919.diff 25 Files Affected: - (modified) lldb/tools/lldb-dap/BreakpointBase.cpp (+2-2) - (modified) lldb/tools/lldb-dap/DAP.cpp (+12-9) - (modified) lldb/tools/lldb-dap/FunctionBreakpoint.cpp (+2-1) - (modified) lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp (+12-9) - (modified) lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp (+8-6) - (modified) lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp (+2-1) - (modified) lldb/tools/lldb-dap/Handler/CompletionsHandler.cpp (+4-3) - (modified) lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp (+2-2) - (modified) lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp (+5-3) - (modified) lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp (+3-2) - (modified) lldb/tools/lldb-dap/Handler/LaunchRequestHandler.cpp (+6-4) - (modified) lldb/tools/lldb-dap/Handler/LocationsRequestHandler.cpp (+2-1) - (modified) lldb/tools/lldb-dap/Handler/ReadMemoryRequestHandler.cpp (+4-3) - (modified) lldb/tools/lldb-dap/Handler/RequestHandler.cpp (+4-3) - (modified) lldb/tools/lldb-dap/Handler/SetBreakpointsRequestHandler.cpp (+1-1) - (modified) lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp (+4-4) - (modified) lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp (+3-2) - (modified) lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp (+2-2) - (modified) lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp (+1-1) - (modified) lldb/tools/lldb-dap/Handler/VariablesRequestHandler.cpp (+3-3) - (modified) lldb/tools/lldb-dap/InstructionBreakpoint.cpp (+2-1) - (modified) lldb/tools/lldb-dap/JSONUtils.cpp (+30-31) - (modified) lldb/tools/lldb-dap/JSONUtils.h (+16-19) - (modified) lldb/tools/lldb-dap/SourceBreakpoint.cpp (+3-3) - (modified) lldb/tools/lldb-dap/Watchpoint.cpp (+2-2) ``diff diff --git a/lldb/tools/lldb-dap/BreakpointBase.cpp b/lldb/tools/lldb-dap/BreakpointBase.cpp index 1e28c29082a9f..7979bac098766 100644 --- a/lldb/tools/lldb-dap/BreakpointBase.cpp +++ b/lldb/tools/lldb-dap/BreakpointBase.cpp @@ -13,8 +13,8 @@ using namespace lldb_dap; BreakpointBase::BreakpointBase(DAP &d, const llvm::json::Object &obj) -: dap(d), condition(std::string(GetString(obj, "condition"))), - hitCondition(std::string(GetString(obj, "hitCondition"))) {} +: dap(d), condition(std::string(GetString(obj, "condition").value_or(""))), + hitCondition(std::string(GetString(obj, "hitCondition").value_or(""))) {} void BreakpointBase::UpdateBreakpoint(const BreakpointBase &request_bp) { if (condition != request_bp.condition) { diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index c4790414f64f9..435cd0f188d75 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -526,12 +526,13 @@ ExceptionBreakpoint *DAP::GetExceptionBPFromStopReason(lldb::SBThread &thread) { } lldb::SBThread DAP::GetLLDBThread(const llvm::json::Object &arguments) { - auto tid = GetSigned(arguments, "threadId", LLDB_INVALID_THREAD_ID); + auto tid = GetSigned(arguments, "threadId").value_or(LLDB_INVALID_THREAD_ID); return target.GetProcess().GetThreadByID(tid); } lldb::SBFrame DAP::GetLLDBFrame(const llvm::json::Object &arguments) { - const uint64_t frame_id = GetUnsigned(arguments, "frameId", UINT64_MAX); + const uint64_t frame_id = + GetUnsigned(arguments, "frameId").value_or(UINT64_MAX); lldb::SBProcess process = target.GetProcess(); // Upper 32 bits is the thread index ID lldb::SBThread thread = @@ -688,9 +689,11 @@ DAP::CreateTargetFromArguments(const llvm::json::Object &arguments, // enough information to determine correct arch and platform (or ELF can be // omitted at all), so it is good to leave the user an apportunity to specify // those. Any of those three can be left empty. - llvm::StringRef target_triple = GetString(arguments, "targetTriple"); - llvm::StringRef platform_name = GetString(arguments, "platformName"); - llvm::StringRef program = GetString(arguments, "program"); + const llvm::StringRef target_triple = + GetString(arguments, "targetTriple").value_or(""); + const llvm::StringRef platform_name = + GetString(arguments, "platformName").value_or(""); + const llvm::StringRef program = GetString(arguments, "program").value_or(""); auto target = this->debugger.CreateTarget( program.data(), target_triple.data(), platform_name.data(), true, // Add dependent modules. @@ -754,9 +757,9 @@ PacketStatus DAP::GetNextObject(llvm::json::Object &object) { } bool DAP::HandleObject(const llvm::json::Object &object) { - const auto packet_type = GetString(object, "type"); + const auto packet_type =
[Lldb-commits] [lldb] [lldb] Support expectedFlakey decorator in dotest (PR #129817)
dmpots wrote: > That's not to say that things cannot be flakey sometimes: because of how we > test the debugger, we depend on a lot of things, many of which are out of our > control and can cause a test to fail. But that's different from a specific > test being flakey, which is what this decorator would be used for. Thanks, I appreciate your thoughts. For some context here, I am looking to replace some internal scripts that handle failures by re-running tests. I thought we might be able to leverage the built-in features of the dotest to handle some of this. Let me collect some more data to see how much/what kind of flakiness we have. Do you have any suggestions on how we should handle the "expected" flakiness because of how we test the debugger? Do you think this is something we should try to solve as part of the lldb testing framework? https://github.com/llvm/llvm-project/pull/129817 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Avoid force loading symbol files in statistics collection (PR #129593)
@@ -0,0 +1,31 @@ +# RUN: %clang_host -g %S/Inputs/main.c -o %t-main.exe + +# When we enable symbol preload and dump stats there should be a non-zero +# time for parsing symbol tables for the main module. jeffreytan81 wrote: Can you add top level comment explicitly point out that the test tries to only create the main target module without running or loading dependency to avoid any runtime plugin global symbol lookup. This is a key assumption. https://github.com/llvm/llvm-project/pull/129593 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Avoid force loading symbol files in statistics collection (PR #129593)
https://github.com/jeffreytan81 edited https://github.com/llvm/llvm-project/pull/129593 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Avoid force loading symbol files in statistics collection (PR #129593)
https://github.com/jeffreytan81 approved this pull request. Looks good other than one comment. https://github.com/llvm/llvm-project/pull/129593 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB]Fix test crash (PR #129921)
https://github.com/oontvoo updated https://github.com/llvm/llvm-project/pull/129921 >From 38f07a83ff621ae4879e4b0cbc8bd361d0b12a93 Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Wed, 5 Mar 2025 14:45:24 -0500 Subject: [PATCH 1/2] [LLDB]Fix test crash Unregister the fake manager at end of test (https://github.com/llvm/llvm-project/issues/129910) --- lldb/unittests/Core/TelemetryTest.cpp | 8 +++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lldb/unittests/Core/TelemetryTest.cpp b/lldb/unittests/Core/TelemetryTest.cpp index 0e9f329110872..5b762ae816362 100644 --- a/lldb/unittests/Core/TelemetryTest.cpp +++ b/lldb/unittests/Core/TelemetryTest.cpp @@ -11,6 +11,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" #include "llvm/Telemetry/Telemetry.h" +#include "TestingSupport/SubsystemRAII.h" #include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" #include @@ -77,8 +78,13 @@ class FakePlugin : public telemetry::TelemetryManager { using namespace lldb_private::telemetry; +class TelemetryTest : public testing::Test { + public: + SubsystemRAII subsystems; +}; + #if LLVM_ENABLE_TELEMETRY -#define TELEMETRY_TEST(suite, test) TEST(suite, test) +#define TELEMETRY_TEST(suite, test) TEST_F(suite, test) #else #define TELEMETRY_TEST(suite, test) TEST(DISABLED_##suite, test) #endif >From 96670f1bf7de08dc5606e3fdf51526fe759a9279 Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Wed, 5 Mar 2025 14:52:55 -0500 Subject: [PATCH 2/2] format --- lldb/unittests/Core/TelemetryTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lldb/unittests/Core/TelemetryTest.cpp b/lldb/unittests/Core/TelemetryTest.cpp index 5b762ae816362..c7edb0f92fde2 100644 --- a/lldb/unittests/Core/TelemetryTest.cpp +++ b/lldb/unittests/Core/TelemetryTest.cpp @@ -5,13 +5,13 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===--===// +#include "lldb/Core/Telemetry.h" +#include "TestingSupport/SubsystemRAII.h" #include "lldb/Core/PluginInterface.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/Telemetry.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" #include "llvm/Telemetry/Telemetry.h" -#include "TestingSupport/SubsystemRAII.h" #include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" #include @@ -79,7 +79,7 @@ class FakePlugin : public telemetry::TelemetryManager { using namespace lldb_private::telemetry; class TelemetryTest : public testing::Test { - public: +public: SubsystemRAII subsystems; }; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB]Fix test crash (PR #129921)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Vy Nguyen (oontvoo) Changes Unregister the fake manager at end of test (https://github.com/llvm/llvm-project/issues/129910) --- Full diff: https://github.com/llvm/llvm-project/pull/129921.diff 1 Files Affected: - (modified) lldb/unittests/Core/TelemetryTest.cpp (+7-1) ``diff diff --git a/lldb/unittests/Core/TelemetryTest.cpp b/lldb/unittests/Core/TelemetryTest.cpp index 0e9f329110872..5b762ae816362 100644 --- a/lldb/unittests/Core/TelemetryTest.cpp +++ b/lldb/unittests/Core/TelemetryTest.cpp @@ -11,6 +11,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" #include "llvm/Telemetry/Telemetry.h" +#include "TestingSupport/SubsystemRAII.h" #include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" #include @@ -77,8 +78,13 @@ class FakePlugin : public telemetry::TelemetryManager { using namespace lldb_private::telemetry; +class TelemetryTest : public testing::Test { + public: + SubsystemRAII subsystems; +}; + #if LLVM_ENABLE_TELEMETRY -#define TELEMETRY_TEST(suite, test) TEST(suite, test) +#define TELEMETRY_TEST(suite, test) TEST_F(suite, test) #else #define TELEMETRY_TEST(suite, test) TEST(DISABLED_##suite, test) #endif `` https://github.com/llvm/llvm-project/pull/129921 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB-DAP] SBDebugger don't prefix title on progress updates (PR #124648)
https://github.com/clayborg approved this pull request. https://github.com/llvm/llvm-project/pull/124648 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 02f024c - [LLDB-DAP] SBDebugger don't prefix title on progress updates (#124648)
Author: Jacob Lalonde Date: 2025-03-05T12:02:44-08:00 New Revision: 02f024ca97403e8dff55ca4feebe78009d9ea8f3 URL: https://github.com/llvm/llvm-project/commit/02f024ca97403e8dff55ca4feebe78009d9ea8f3 DIFF: https://github.com/llvm/llvm-project/commit/02f024ca97403e8dff55ca4feebe78009d9ea8f3.diff LOG: [LLDB-DAP] SBDebugger don't prefix title on progress updates (#124648) In my last DAP patch (#123837), we piped the DAP update message into the update event. However, we had the title embedded into the update message. This makes sense for progress Start, but makes the update message look pretty wonky.  Instead, we only use the title when it's the first message, removing the duplicate title problem.  Added: Modified: lldb/bindings/interface/SBProgressDocstrings.i lldb/test/API/tools/lldb-dap/progress/Progress_emitter.py lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp Removed: diff --git a/lldb/bindings/interface/SBProgressDocstrings.i b/lldb/bindings/interface/SBProgressDocstrings.i index 5459d1af5155c..7b7e1dc79187c 100644 --- a/lldb/bindings/interface/SBProgressDocstrings.i +++ b/lldb/bindings/interface/SBProgressDocstrings.i @@ -11,7 +11,48 @@ The Progress class helps make sure that progress is correctly reported and will always send an initial progress update, updates when Progress::Increment() is called, and also will make sure that a progress completed update is reported even if the user doesn't explicitly cause one -to be sent.") lldb::SBProgress; +to be sent. + +Progress can either be deterministic, incrementing up to a known total or non-deterministic +with an unbounded total. Deterministic is better if you know the items of work in advance, but non-deterministic +exposes a way to update a user during a long running process that work is taking place. + +For all progresses the details provided in the constructor will be sent until an increment detail +is provided. This detail will also continue to be broadcasted on any subsequent update that doesn't +specify a new detail. Some implementations diff er on throttling updates and this behavior diff ers primarily +if the progress is deterministic or non-deterministic. For DAP, non-deterministic update messages have a higher +throttling rate than deterministic ones. + +Below are examples in Python for deterministic and non-deterministic progresses. + +deterministic_progress1 = lldb.SBProgress('Deterministic Progress', 'Detail', 3, lldb.SBDebugger) +for i in range(3): +deterministic_progress1.Increment(1, f'Update {i}') +# The call to Finalize() is a no-op as we already incremented the right amount of +# times and caused the end event to be sent. +deterministic_progress1.Finalize() + +deterministic_progress2 = lldb.SBProgress('Deterministic Progress', 'Detail', 10, lldb.SBDebugger) +for i in range(3): +deterministic_progress2.Increment(1, f'Update {i}') +# Cause the progress end event to be sent even if we didn't increment the right +# number of times. Real world examples would be in a try-finally block to ensure +# progress clean-up. +deterministic_progress2.Finalize() + +If you don't call Finalize() when the progress is not done, the progress object will eventually get +garbage collected by the Python runtime, the end event will eventually get sent, but it is best not to +rely on the garbage collection when using lldb.SBProgress. + +Non-deterministic progresses behave the same, but omit the total in the constructor. + +non_deterministic_progress = lldb.SBProgress('Non deterministic progress, 'Detail', lldb.SBDebugger) +for i in range(10): +non_deterministic_progress.Increment(1) +# Explicitly send a progressEnd, otherwise this will be sent +# when the python runtime cleans up this object. +non_deterministic_progress.Finalize() +") lldb::SBProgress; %feature("docstring", "Finalize the SBProgress, which will cause a progress end event to be emitted. This diff --git a/lldb/test/API/tools/lldb-dap/progress/Progress_emitter.py b/lldb/test/API/tools/lldb-dap/progress/Progress_emitter.py index 7f4055cab9ddd..e94a09676e067 100644 --- a/lldb/test/API/tools/lldb-dap/progress/Progress_emitter.py +++ b/lldb/test/API/tools/lldb-dap/progress/Progress_emitter.py @@ -37,7 +37,11 @@ def create_options(cls): ) parser.add_option( -"--total", dest="total", help="Total to count up.", type="int" +"--total", +dest="total", +help="Total items in this progress object. When this option is not specified, this will be
[Lldb-commits] [lldb] [LLDB-DAP] SBDebugger don't prefix title on progress updates (PR #124648)
https://github.com/Jlalond closed https://github.com/llvm/llvm-project/pull/124648 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][Telemetry]Define TargetInfo for collecting data about a target (PR #127834)
https://github.com/oontvoo updated https://github.com/llvm/llvm-project/pull/127834 >From 0d6a36d84df50ccb9eef9ef3dd6f59d4299edeac Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Wed, 19 Feb 2025 12:47:57 -0500 Subject: [PATCH 1/9] [LLDB][Telemetry]Define TargetInfo for collecting data about a target --- lldb/include/lldb/Core/Telemetry.h | 86 +- lldb/source/Core/Telemetry.cpp | 99 ++ 2 files changed, 170 insertions(+), 15 deletions(-) diff --git a/lldb/include/lldb/Core/Telemetry.h b/lldb/include/lldb/Core/Telemetry.h index b72556ecaf3c9..4be81951254de 100644 --- a/lldb/include/lldb/Core/Telemetry.h +++ b/lldb/include/lldb/Core/Telemetry.h @@ -13,6 +13,7 @@ #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Utility/StructuredData.h" #include "lldb/lldb-forward.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/JSON.h" @@ -29,6 +30,9 @@ namespace telemetry { struct LLDBEntryKind : public ::llvm::telemetry::EntryKind { static const llvm::telemetry::KindType BaseInfo = 0b11000; + static const KindType TargetInfo = 0b11010; + // There are other entries in between (added in separate PRs) + static const llvm::telemetry::KindType MiscInfo = 0b0; }; /// Defines a convenient type for timestamp of various events. @@ -56,14 +60,88 @@ struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { void serialize(llvm::telemetry::Serializer &serializer) const override; }; +/// Describes an exit status. +struct ExitDescription { + int exit_code; + std::string description; +}; + +struct TargetTelemetryInfo : public LldbBaseTelemetryInfo { + lldb::ModuleSP exec_mod; + Target *target_ptr; + + // The same as the executable-module's UUID. + std::string target_uuid; + std::string file_format; + + std::string binary_path; + size_t binary_size; + + std::optional exit_desc; + TargetTelemetryInfo() = default; + + TargetTelemetryInfo(const TargetTelemetryInfo &other) { +exec_mod = other.exec_mod; +target_uuid = other.target_uuid; +file_format = other.file_format; +binary_path = other.binary_path; +binary_size = other.binary_size; +exit_desc = other.exit_desc; + } + + KindType getKind() const override { return LldbEntryKind::TargetInfo; } + + static bool classof(const TelemetryInfo *T) { +if (T == nullptr) + return false; +return T->getKind() == LldbEntryKind::TargetInfo; + } + + void serialize(Serializer &serializer) const override; +}; + +/// The "catch-all" entry to store a set of non-standard data, such as +/// error-messages, etc. +struct MiscTelemetryInfo : public LLDBBaseTelemetryInfo { + /// If the event is/can be associated with a target entry, + /// this field contains that target's UUID. + /// otherwise. + std::string target_uuid; + + /// Set of key-value pairs for any optional (or impl-specific) data + std::map meta_data; + + MiscTelemetryInfo() = default; + + MiscTelemetryInfo(const MiscTelemetryInfo &other) { +target_uuid = other.target_uuid; +meta_data = other.meta_data; + } + + llvm::telemetry::KindType getKind() const override { +return LLDBEntryKind::MiscInfo; + } + + static bool classof(const llvm::telemetry::TelemetryInfo *T) { +return T->getKind() == LLDBEntryKind::MiscInfo; + } + + void serialize(llvm::telemetry::Serializer &serializer) const override; +}; + /// The base Telemetry manager instance in LLDB. /// This class declares additional instrumentation points /// applicable to LLDB. -class TelemetryManager : public llvm::telemetry::Manager { +class TelemetryMager : public llvm::telemetry::Manager { public: llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override; - virtual llvm::StringRef GetInstanceName() const = 0; + const llvm::telemetry::Config *getConfig(); + + virtual void AtMainExecutableLoadStart(TargetInfo * entry); + virtual void AtMainExecutableLoadEnd(TargetInfo *entry); + + virtual llvm::StringRef GetInstanceName() const = 0; static TelemetryManager *getInstance(); protected: @@ -73,6 +151,10 @@ class TelemetryManager : public llvm::telemetry::Manager { private: std::unique_ptr m_config; + // Each debugger is assigned a unique ID (session_id). + // All TelemetryInfo entries emitted for the same debugger instance + // will get the same session_id. + llvm::DenseMap session_ids; static std::unique_ptr g_instance; }; diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp index 5222f76704f91..da7aee01680fc 100644 --- a/lldb/source/Core/Telemetry.cpp +++ b/lldb/source/Core/Telemetry.cpp @@ -10,14 +10,20 @@ #ifdef LLVM_BUILD_TELEMETRY -#include "lldb/Core/Telemetry.h" #include "lldb/Core/Debugger.h" +#include "lldb/Core/Telemetry.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Host/HostInfo.h" +#include "lldb/Target/Process.h" +#include "lld