[Lldb-commits] [lldb] 49b3c33 - [lldb][x86_64] Support fs_base/gs_base register in Linux
Author: Jeffrey Tan Date: 2023-07-20T16:32:47-07:00 New Revision: 49b3c3355f9c36a023e04bba509ac89d15da6ff9 URL: https://github.com/llvm/llvm-project/commit/49b3c3355f9c36a023e04bba509ac89d15da6ff9 DIFF: https://github.com/llvm/llvm-project/commit/49b3c3355f9c36a023e04bba509ac89d15da6ff9.diff LOG: [lldb][x86_64] Support fs_base/gs_base register in Linux Summary: [lldb][x86_64] This patch adds fs_base/gs_base support for Linux x86_64. Originally, I plan to split the diff into two parts, one to refactoring lldb_xxx_x86_64 => x86_64::lldb_xxx across code base and the other one for adding fs_base/gs_base, but it turns out to be a non-trivial effort to split and very error prone so I decided to keep a single diff to get feedback. GDB supports fs_base/gs_base registers while LLDB does not. Since both linux coredump note section and ptrace supports them it is a missing feature. For context, this is a required feature to support getting pthread pointer on linux from both live and dump debugging. See thread below for details: https://discourse.llvm.org/t/how-to-get-pthread-pointer-from-lldb/70542/2?u=jeffreytan81 Implementation wise, we have initially tried `#ifdef` approach to reuse the code but it is introducing very tricky bugs and proves hard to maintain. Instead the diff completely separates the registers between x86_64 and x86_64_with_base so that non-linux related implementations can use x86_64 registers while linux uses x86_64_with_base. Here are the list of changes done in the patch: * Registers in lldb-x86-register-enums.h are separated into two: x86_64 and x86_64_with_base * fs_base/gs_base are added into x86_64_with_base * All linux files are change to use x86_64::lldb_xxx => x86_64_with_base::lldb_xxx * Support linux elf-core: * A new RegisterContextLinuxCore_x86_64 class is added for ThreadElfCore * RegisterContextLinuxCore_x86_64 overrides and uses its own register set supports fs_base/gs_base * RegisterInfos_x86_64_with_base/RegisterInfos_x86_64_with_base_shared ared added to provide g_contained_XXX/g_invalidate_XXX and RegInfo related code sharing. * `RegisterContextPOSIX_x86 ::m_gpr_x86_64` seems to be unused so I removed it. * `NativeRegisterContextDBReg_x86::GetDR()` is overridden in `NativeRegisterContextLinux_x86_64` to make watchpoint work. Reviewers:clayborg,labath,jingham,jdoerfert,JDevlieghere,kusmour,GeorgeHuyubo Subscribers: Tasks: Tags: Differential Revision: https://reviews.llvm.org/D155256 Added: lldb/source/Plugins/Process/Utility/RegisterInfos_x86_64_with_base.h lldb/source/Plugins/Process/Utility/RegisterInfos_x86_64_with_base_shared.cpp lldb/source/Plugins/Process/Utility/RegisterInfos_x86_64_with_base_shared.h lldb/source/Plugins/Process/elf-core/RegisterContextLinuxCore_x86_64.cpp lldb/source/Plugins/Process/elf-core/RegisterContextLinuxCore_x86_64.h Modified: lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h lldb/source/Plugins/Process/Utility/CMakeLists.txt lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_x86.h lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.h lldb/source/Plugins/Process/Utility/RegisterContext_x86.h lldb/source/Plugins/Process/Utility/lldb-x86-register-enums.h lldb/source/Plugins/Process/elf-core/CMakeLists.txt lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp lldb/test/API/commands/register/register/register_command/TestRegisters.py lldb/test/API/functionalities/postmortem/elf-core/thread_crash/TestLinuxCoreThreads.py Removed: diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp index e81ef3301f1f13..f0e295b5900867 100644 --- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp @@ -100,96 +100,97 @@ static_assert((sizeof(g_mpx_regnums_i386) / sizeof(g_mpx_regnums_i386[0])) - // x86 64-bit general purpose registers. static const uint32_t g_gpr_regnums_x86_64[] = { -lldb_rax_x86_64,lldb_rbx_x86_64,lldb_rcx_x86_64, lldb_rdx_x86_64, -lldb_rdi_x86_64,lldb_rsi_x86_64,lldb_rbp_x86_64, lldb_rsp_x86_64, -lldb_r8_x86_64, lldb_r9_x86_64, lldb_r10_x86_64, lldb_r11_x86_64, -lldb_r12_x86_64,lldb_r13_x86_64,lldb_r14_x86_64, lldb_r15_x86_64, -lldb_rip_x86_64,lldb_rflags_x86_64, lldb_cs_x86_64, lldb_fs_x86_64, -lldb_gs_x86_64, lldb_ss_x86_64, lldb_ds_x86_64, lldb_es_x86_64, -lldb_eax_x86_64,lldb_ebx_x86_64,lldb_ecx_x86
[Lldb-commits] [lldb] ca84935 - Fix lldb-vscode frame id integer overflow
Author: Jeffrey Tan Date: 2023-07-26T16:12:41-07:00 New Revision: ca849352936dadadd232cf9ec74ac006ce410f51 URL: https://github.com/llvm/llvm-project/commit/ca849352936dadadd232cf9ec74ac006ce410f51 DIFF: https://github.com/llvm/llvm-project/commit/ca849352936dadadd232cf9ec74ac006ce410f51.diff LOG: Fix lldb-vscode frame id integer overflow This patch fixes a 32bit integer overflow in lldb-vscode. The current implementation of frame_id does `(thread_index << 19 | frame_index)`. Since thread_index is a 32 bit integer this leaves only 32 - 19 == 13 bits available for the thread_index. As a result, lldb-vscode can only handle 2^13 == 8192 threads. Normally, this would be sufficient, but we have seen crazy process having +12000 threads, causing the frame_id algorithm above to integer overflow during casting. The patch fixes the overflow by up casting to 64 bit integer first before bit shifiting. Differential Revision: https://reviews.llvm.org/D156375 Added: Modified: lldb/tools/lldb-vscode/LLDBUtils.cpp Removed: diff --git a/lldb/tools/lldb-vscode/LLDBUtils.cpp b/lldb/tools/lldb-vscode/LLDBUtils.cpp index 621f4ec37c83da..464195bdc6444c 100644 --- a/lldb/tools/lldb-vscode/LLDBUtils.cpp +++ b/lldb/tools/lldb-vscode/LLDBUtils.cpp @@ -79,8 +79,8 @@ uint32_t GetLLDBFrameID(uint64_t dap_frame_id) { } int64_t MakeVSCodeFrameID(lldb::SBFrame &frame) { - return (int64_t)(frame.GetThread().GetIndexID() << THREAD_INDEX_SHIFT | - frame.GetFrameID()); + return ((int64_t)frame.GetThread().GetIndexID() << THREAD_INDEX_SHIFT) | + frame.GetFrameID(); } } // namespace lldb_vscode ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 5cbf516 - Refactor protected virtual functions from SymbolFile into new SymbolFileCommon class.
Author: Jeffrey Tan Date: 2022-04-25T18:33:47-07:00 New Revision: 5cbf516cb79fa27395dabb33002ab20243b1ee5d URL: https://github.com/llvm/llvm-project/commit/5cbf516cb79fa27395dabb33002ab20243b1ee5d DIFF: https://github.com/llvm/llvm-project/commit/5cbf516cb79fa27395dabb33002ab20243b1ee5d.diff LOG: Refactor protected virtual functions from SymbolFile into new SymbolFileCommon class. This is a preparatory patch for https://reviews.llvm.org/D121631. It refactors protected virtual members of SymbolFile into a new SymbolFileCommon class per suggestion in: https://reviews.llvm.org/D121631 This will avoid the friendship declaration in that patch. Differential Revision: https://reviews.llvm.org/D124110 Added: Modified: lldb/include/lldb/Symbol/SymbolFile.h lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h lldb/source/Symbol/SymbolFile.cpp Removed: diff --git a/lldb/include/lldb/Symbol/SymbolFile.h b/lldb/include/lldb/Symbol/SymbolFile.h index c7bb6c16f0398..c9be5dbd2b256 100644 --- a/lldb/include/lldb/Symbol/SymbolFile.h +++ b/lldb/include/lldb/Symbol/SymbolFile.h @@ -36,6 +36,12 @@ namespace lldb_private { +/// Provides public interface for all SymbolFiles. Any protected +/// virtual members should go into SymbolFileCommon; most SymbolFile +/// implementations should inherit from SymbolFileCommon to override +/// the behaviors except SymbolFileOnDemand which inherits +/// public interfaces from SymbolFile and forward to underlying concrete +/// SymbolFile implementation. class SymbolFile : public PluginInterface { /// LLVM RTTI support. static char ID; @@ -67,8 +73,7 @@ class SymbolFile : public PluginInterface { static SymbolFile *FindPlugin(lldb::ObjectFileSP objfile_sp); // Constructors and Destructors - SymbolFile(lldb::ObjectFileSP objfile_sp) - : m_objfile_sp(std::move(objfile_sp)) {} + SymbolFile() = default; ~SymbolFile() override = default; @@ -99,15 +104,7 @@ class SymbolFile : public PluginInterface { /// A uint32_t mask containing bits from the SymbolFile::Abilities /// enumeration. Any bits that are set represent an ability that /// this symbol plug-in can parse from the object file. - uint32_t GetAbilities() { -if (!m_calculated_abilities) { - m_abilities = CalculateAbilities(); - m_calculated_abilities = true; -} - -return m_abilities; - } - + virtual uint32_t GetAbilities() = 0; virtual uint32_t CalculateAbilities() = 0; /// Symbols file subclasses should override this to return the Module that @@ -125,10 +122,10 @@ class SymbolFile : public PluginInterface { // Compile Unit function calls // Approach 1 - iterator - uint32_t GetNumCompileUnits(); - lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx); + virtual uint32_t GetNumCompileUnits() = 0; + virtual lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) = 0; - Symtab *GetSymtab(); + virtual Symtab *GetSymtab() = 0; virtual lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) = 0; /// Return the Xcode SDK comp_unit was compiled against. @@ -256,16 +253,16 @@ class SymbolFile : public PluginInterface { virtual void PreloadSymbols(); virtual llvm::Expected - GetTypeSystemForLanguage(lldb::LanguageType language); + GetTypeSystemForLanguage(lldb::LanguageType language) = 0; virtual CompilerDeclContext FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx) { return CompilerDeclContext(); } - ObjectFile *GetObjectFile() { return m_objfile_sp.get(); } - const ObjectFile *GetObjectFile() const { return m_objfile_sp.get(); } - ObjectFile *GetMainObjectFile(); + virtual ObjectFile *GetObjectFile() = 0; + virtual const ObjectFile *GetObjectFile() const = 0; + virtual ObjectFile *GetMainObjectFile() = 0; virtual std::vector> ParseCallEdgesInFunction(UserID func_id) { @@ -276,7 +273,7 @@ class SymbolFile : public PluginInterface { /// Notify the SymbolFile that the file addresses in the Sections /// for this module have been changed. - virtual void SectionFileAddressesChanged(); + virtual void SectionFileAddressesChanged() = 0; struct RegisterInfoResolver { virtual ~RegisterInfoResolver(); // anchor @@ -297,7 +294,7
[Lldb-commits] [lldb] 7b81192 - Introduce new symbol on-demand for debug info
Author: Jeffrey Tan Date: 2022-04-26T10:42:06-07:00 New Revision: 7b81192d462bbd8031d5c665e29cd6b4c0c6887a URL: https://github.com/llvm/llvm-project/commit/7b81192d462bbd8031d5c665e29cd6b4c0c6887a DIFF: https://github.com/llvm/llvm-project/commit/7b81192d462bbd8031d5c665e29cd6b4c0c6887a.diff LOG: Introduce new symbol on-demand for debug info This diff introduces a new symbol on-demand which skips loading a module's debug info unless explicitly asked on demand. This provides significant performance improvement for application with dynamic linking mode which has large number of modules. The feature can be turned on with: "settings set symbols.load-on-demand true" The feature works by creating a new SymbolFileOnDemand class for each module which wraps the actual SymbolFIle subclass as member variable. By default, most virtual methods on SymbolFileOnDemand are skipped so that it looks like there is no debug info for that module. But once the module's debug info is explicitly requested to be enabled (in the conditions mentioned below) SymbolFileOnDemand will allow all methods to pass through and forward to the actual SymbolFile which would hydrate module's debug info on-demand. In an internal benchmark, we are seeing more than 95% improvement for a 3000 modules application. Currently we are providing several ways to on demand hydrate a module's debug info: * Source line breakpoint: matching in supported files * Stack trace: resolving symbol context for an address * Symbolic breakpoint: symbol table match guided promotion * Global variable: symbol table match guided promotion In all above situations the module's debug info will be on-demand parsed and indexed. Some follow-ups for this feature: * Add a command that allows users to load debug info explicitly while using a new or existing command when this feature is enabled * Add settings for "never load any of these executables in Symbols On Demand" that takes a list of globs * Add settings for "always load the the debug info for executables in Symbols On Demand" that takes a list of globs * Add a new column in "image list" that shows up by default when Symbols On Demand is enable to show the status for each shlib like "not enabled for this", "debug info off" and "debug info on" (with a single character to short string, not the ones I just typed) Differential Revision: https://reviews.llvm.org/D121631 Added: lldb/docs/use/ondemand.rst lldb/include/lldb/Symbol/SymbolFileOnDemand.h lldb/source/Symbol/SymbolFileOnDemand.cpp lldb/test/API/symbol_ondemand/breakpoint_language/Makefile lldb/test/API/symbol_ondemand/breakpoint_language/TestBreakpointLanguageOnDemand.py lldb/test/API/symbol_ondemand/breakpoint_language/c_lang.c lldb/test/API/symbol_ondemand/breakpoint_language/cpp_lang.cpp lldb/test/API/symbol_ondemand/breakpoint_language/main.cpp lldb/test/API/symbol_ondemand/breakpoint_source_regex/Makefile lldb/test/API/symbol_ondemand/breakpoint_source_regex/TestSourceTextRegexBreakpoint.py lldb/test/API/symbol_ondemand/breakpoint_source_regex/main.cpp lldb/test/API/symbol_ondemand/shared_library/Makefile lldb/test/API/symbol_ondemand/shared_library/TestSharedLib.py lldb/test/API/symbol_ondemand/shared_library/foo.c lldb/test/API/symbol_ondemand/shared_library/foo.h lldb/test/API/symbol_ondemand/shared_library/shared.c lldb/test/Shell/SymbolFile/OnDemand/Inputs/basic.cpp lldb/test/Shell/SymbolFile/OnDemand/source-breakpoint.test lldb/test/Shell/SymbolFile/OnDemand/symbolic-breakpoint.test Modified: lldb/include/lldb/Core/ModuleList.h lldb/include/lldb/Symbol/SymbolFile.h lldb/include/lldb/Target/Statistics.h lldb/include/lldb/Utility/LLDBLog.h lldb/source/Core/CoreProperties.td lldb/source/Core/Module.cpp lldb/source/Core/ModuleList.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp lldb/source/Symbol/CMakeLists.txt lldb/source/Symbol/CompileUnit.cpp lldb/source/Symbol/SymbolFile.cpp lldb/source/Target/Statistics.cpp lldb/source/Utility/LLDBLog.cpp Removed: diff --git a/lldb/docs/use/ondemand.rst b/lldb/docs/use/ondemand.rst new file mode 100644 index 0..e5aaee8889d5f --- /dev/null +++ b/lldb/docs/use/ondemand.rst @@ -0,0 +1,158 @@ +On Demand Symbols += + +On demand symbols can be enabled in LLDB for projects that generate debug info +for more than what is required by a normal debug session. Some build systems +enable debug information for all binaries and can end up producing many +gigabytes of debug information. This amount of debug information can greatly +increase debug session load times and can slow develo
[Lldb-commits] [lldb] d738d47 - Disable symbol on-demand feature for Windows
Author: Jeffrey Tan Date: 2022-04-26T13:35:34-07:00 New Revision: d738d4717f6da88494683da62648f91f04f7c8ce URL: https://github.com/llvm/llvm-project/commit/d738d4717f6da88494683da62648f91f04f7c8ce DIFF: https://github.com/llvm/llvm-project/commit/d738d4717f6da88494683da62648f91f04f7c8ce.diff LOG: Disable symbol on-demand feature for Windows Symbol on-demand feature is never tested on Windows so it is not a surprise that we are getting Buildbot failure from Windows: https://lab.llvm.org/buildbot/#/builders/83/builds/18228 This patch disables symbol on-demand feature on Windows. I will find a Windows machine to test and re-enable symbol on-demand feature as follow-up. Differential Revision: https://reviews.llvm.org/D124471 Added: Modified: lldb/test/API/symbol_ondemand/breakpoint_language/TestBreakpointLanguageOnDemand.py lldb/test/API/symbol_ondemand/breakpoint_source_regex/TestSourceTextRegexBreakpoint.py lldb/test/API/symbol_ondemand/shared_library/TestSharedLib.py lldb/test/Shell/SymbolFile/OnDemand/source-breakpoint.test lldb/test/Shell/SymbolFile/OnDemand/symbolic-breakpoint.test Removed: diff --git a/lldb/test/API/symbol_ondemand/breakpoint_language/TestBreakpointLanguageOnDemand.py b/lldb/test/API/symbol_ondemand/breakpoint_language/TestBreakpointLanguageOnDemand.py index 263dccdc5ed70..1a1d3643a6481 100644 --- a/lldb/test/API/symbol_ondemand/breakpoint_language/TestBreakpointLanguageOnDemand.py +++ b/lldb/test/API/symbol_ondemand/breakpoint_language/TestBreakpointLanguageOnDemand.py @@ -20,6 +20,7 @@ def check_location_file(self, bp, loc, test_name): comp_name = comp_unit.GetFileSpec().GetFilename() return comp_name == test_name +@skipIfWindows def test_regex_breakpoint_language(self): """Test that the name regex breakpoint commands obey the language filter.""" @@ -65,6 +66,7 @@ def test_regex_breakpoint_language(self): objc_bp.GetNumLocations(), 0, "No ObjC symbol matches") +@skipIfWindows def test_by_name_breakpoint_language(self): """Test that the name regex breakpoint commands obey the language filter.""" diff --git a/lldb/test/API/symbol_ondemand/breakpoint_source_regex/TestSourceTextRegexBreakpoint.py b/lldb/test/API/symbol_ondemand/breakpoint_source_regex/TestSourceTextRegexBreakpoint.py index 13490cc8cd19c..4fd3bbf74bf07 100644 --- a/lldb/test/API/symbol_ondemand/breakpoint_source_regex/TestSourceTextRegexBreakpoint.py +++ b/lldb/test/API/symbol_ondemand/breakpoint_source_regex/TestSourceTextRegexBreakpoint.py @@ -13,6 +13,7 @@ class TestSourceTextRegexBreakpoint(TestBase): mydir = TestBase.compute_mydir(__file__) +@skipIfWindows def test_with_run_command(self): self.build() diff --git a/lldb/test/API/symbol_ondemand/shared_library/TestSharedLib.py b/lldb/test/API/symbol_ondemand/shared_library/TestSharedLib.py index 51a8e3a79fb3b..dd14594159474 100644 --- a/lldb/test/API/symbol_ondemand/shared_library/TestSharedLib.py +++ b/lldb/test/API/symbol_ondemand/shared_library/TestSharedLib.py @@ -38,6 +38,7 @@ def common_setup(self): ctx = self.platformContext self.shared_lib_name = ctx.shlib_prefix + "foo." + ctx.shlib_extension +@skipIfWindows def test_source_line_breakpoint(self): self.build() self.common_setup() @@ -75,6 +76,7 @@ def test_source_line_breakpoint(self): ) self.assertEqual(7, parent_frame.GetLineEntry().GetLine()) +@skipIfWindows def test_symbolic_breakpoint(self): self.build() self.common_setup() @@ -112,6 +114,7 @@ def test_symbolic_breakpoint(self): ) self.assertEqual(7, parent_frame.GetLineEntry().GetLine()) +@skipIfWindows def test_global_variable_hydration(self): self.build() self.common_setup() diff --git a/lldb/test/Shell/SymbolFile/OnDemand/source-breakpoint.test b/lldb/test/Shell/SymbolFile/OnDemand/source-breakpoint.test index 465a6e1f322cf..8c1f086ebc0c7 100644 --- a/lldb/test/Shell/SymbolFile/OnDemand/source-breakpoint.test +++ b/lldb/test/Shell/SymbolFile/OnDemand/source-breakpoint.test @@ -1,5 +1,6 @@ # Test shows that source line breakpoint works with LLDB on demand symbol loading. +# UNSUPPORTED: system-windows # RUN: mkdir -p %t # RUN: cd %t # RUN: %build %p/Inputs/basic.cpp -o basic.out diff --git a/lldb/test/Shell/SymbolFile/OnDemand/symbolic-breakpoint.test b/lldb/test/Shell/SymbolFile/OnDemand/symbolic-breakpoint.test index d8f61aad4c45a..69513aab0e239 100644 --- a/lldb/test/Shell/SymbolFile/OnDemand/symbolic-breakpoint.test +++ b/lldb/test/Shell/SymbolFile/OnDemand/symbolic-breakpoint.test @@ -1,5 +1,6 @@ # Test shows that symbolic function breakpoint works with LLDB on demand symbol loading. +# UNSUPPORTED: system-windows # RUN: mkdir -p %t #
[Lldb-commits] [lldb] 0ffcec4 - Fix missing import for test
Author: Jeffrey Tan Date: 2022-04-26T16:40:45-07:00 New Revision: 0ffcec418e45210a9c25632e7fe0a3ef0629b652 URL: https://github.com/llvm/llvm-project/commit/0ffcec418e45210a9c25632e7fe0a3ef0629b652 DIFF: https://github.com/llvm/llvm-project/commit/0ffcec418e45210a9c25632e7fe0a3ef0629b652.diff LOG: Fix missing import for test The last fix missed an import in one test file causing skipIfWindows attribute can't be recognized. I feel embarrassed to miss it. I have run all tests on Mac to make sure them passing in this patch. Differential Revision: https://reviews.llvm.org/D124479 Added: Modified: lldb/test/API/symbol_ondemand/breakpoint_language/TestBreakpointLanguageOnDemand.py Removed: diff --git a/lldb/test/API/symbol_ondemand/breakpoint_language/TestBreakpointLanguageOnDemand.py b/lldb/test/API/symbol_ondemand/breakpoint_language/TestBreakpointLanguageOnDemand.py index 1a1d3643a6481..38d438648c557 100644 --- a/lldb/test/API/symbol_ondemand/breakpoint_language/TestBreakpointLanguageOnDemand.py +++ b/lldb/test/API/symbol_ondemand/breakpoint_language/TestBreakpointLanguageOnDemand.py @@ -5,6 +5,7 @@ import lldb +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * import lldbsuite.test.lldbutil as lldbutil ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 46c1f77 - Add [opt] suffix to optimized stack frame in lldb-vscode
Author: Jeffrey Tan Date: 2022-05-23T10:03:13-07:00 New Revision: 46c1f77e160a63726e312c0550157ee451bacd46 URL: https://github.com/llvm/llvm-project/commit/46c1f77e160a63726e312c0550157ee451bacd46 DIFF: https://github.com/llvm/llvm-project/commit/46c1f77e160a63726e312c0550157ee451bacd46.diff LOG: Add [opt] suffix to optimized stack frame in lldb-vscode To help user identify optimized code This diff adds a "[opt]" suffix to optimized stack frames in lldb-vscode. This provides consistent experience as command line lldb. It also adds a new "optimized" attribute to DAP stack frame object so that it is easy to identify from telemetry than parsing trailing "[opt]". Differential Revision: https://reviews.llvm.org/D126013 Added: lldb/test/API/tools/lldb-vscode/optimized/Makefile lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py lldb/test/API/tools/lldb-vscode/optimized/main.cpp Modified: lldb/tools/lldb-vscode/JSONUtils.cpp Removed: diff --git a/lldb/test/API/tools/lldb-vscode/optimized/Makefile b/lldb/test/API/tools/lldb-vscode/optimized/Makefile new file mode 100644 index ..685b2606b55a --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/optimized/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp +CXXFLAGS_EXTRAS := -O3 -glldb +include Makefile.rules diff --git a/lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py b/lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py new file mode 100644 index ..862fe632a51b --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py @@ -0,0 +1,35 @@ +""" +Test lldb-vscode variables/stackTrace request for optimized code +""" + +from __future__ import print_function + +import unittest2 +import vscode +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil +import lldbvscode_testcase + + +class TestVSCode_optimized(lldbvscode_testcase.VSCodeTestCaseBase): +mydir = TestBase.compute_mydir(__file__) + +@skipIfWindows +@skipIfRemote +def test_stack_frame_name(self): +''' Test optimized frame has special name suffix. +''' +program = self.getBuildArtifact("a.out") +self.build_and_launch(program) +source = 'main.cpp' +breakpoint_line = line_number(source, '// breakpoint 1') +lines = [breakpoint_line] +breakpoint_ids = self.set_source_breakpoints(source, lines) +self.assertEqual(len(breakpoint_ids), len(lines), +"expect correct number of breakpoints") +self.continue_to_breakpoints(breakpoint_ids) +leaf_frame = self.vscode.get_stackFrame(frameIndex=0) +self.assertTrue(leaf_frame['name'].endswith(' [opt]')) +parent_frame = self.vscode.get_stackFrame(frameIndex=1) +self.assertTrue(parent_frame['name'].endswith(' [opt]')) diff --git a/lldb/test/API/tools/lldb-vscode/optimized/main.cpp b/lldb/test/API/tools/lldb-vscode/optimized/main.cpp new file mode 100644 index ..24ace4e4196f --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/optimized/main.cpp @@ -0,0 +1,16 @@ +#include +#include + +int foo(int x, int y) { + printf("Got input %d, %d\n", x, y); + return x + y + 3; // breakpoint 1 +} + +int main(int argc, char const *argv[]) { + int optimized = argc > 1 ? std::stoi(argv[1]) : 0; + + printf("argc: %d, optimized: %d\n", argc, optimized); + int result = foo(argc, 20); + printf("result: %d\n", result); // breakpoint 2 + return 0; +} diff --git a/lldb/tools/lldb-vscode/JSONUtils.cpp b/lldb/tools/lldb-vscode/JSONUtils.cpp index 55d734e65fb5..cd8d8861d98a 100644 --- a/lldb/tools/lldb-vscode/JSONUtils.cpp +++ b/lldb/tools/lldb-vscode/JSONUtils.cpp @@ -751,7 +751,19 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame) { llvm::json::Object object; int64_t frame_id = MakeVSCodeFrameID(frame); object.try_emplace("id", frame_id); - EmplaceSafeString(object, "name", frame.GetFunctionName()); + + std::string frame_name; + const char *func_name = frame.GetFunctionName(); + if (func_name) +frame_name = func_name; + else +frame_name = ""; + bool is_optimized = frame.GetFunction().GetIsOptimized(); + if (is_optimized) +frame_name += " [opt]"; + EmplaceSafeString(object, "name", frame_name); + object.try_emplace("optimized", is_optimized); + int64_t disasm_line = 0; object.try_emplace("source", CreateSource(frame, disasm_line)); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 0fe220a - Show error message for optimized variables
Author: Jeffrey Tan Date: 2022-05-23T10:04:58-07:00 New Revision: 0fe220a33179723b7b366c2b398bac3c3b4216ec URL: https://github.com/llvm/llvm-project/commit/0fe220a33179723b7b366c2b398bac3c3b4216ec DIFF: https://github.com/llvm/llvm-project/commit/0fe220a33179723b7b366c2b398bac3c3b4216ec.diff LOG: Show error message for optimized variables This fixes an issue that optimized variable error message is not shown to end users in lldb-vscode. Differential Revision: https://reviews.llvm.org/D126014 Added: Modified: lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py lldb/tools/lldb-vscode/JSONUtils.cpp Removed: diff --git a/lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py b/lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py index 862fe632a51b..a5e40d03abe4 100644 --- a/lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py +++ b/lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py @@ -33,3 +33,22 @@ def test_stack_frame_name(self): self.assertTrue(leaf_frame['name'].endswith(' [opt]')) parent_frame = self.vscode.get_stackFrame(frameIndex=1) self.assertTrue(parent_frame['name'].endswith(' [opt]')) + +@skipIfWindows +@skipIfRemote +def test_optimized_variable(self): +''' Test optimized variable value contains error. +''' +program = self.getBuildArtifact("a.out") +self.build_and_launch(program) +source = 'main.cpp' +breakpoint_line = line_number(source, '// breakpoint 2') +lines = [breakpoint_line] +# Set breakpoint in the thread function so we can step the threads +breakpoint_ids = self.set_source_breakpoints(source, lines) +self.assertEqual(len(breakpoint_ids), len(lines), +"expect correct number of breakpoints") +self.continue_to_breakpoints(breakpoint_ids) +optimized_variable = self.vscode.get_local_variable('optimized') + +self.assertTrue(optimized_variable['value'].startswith('"; + } else if (!value.empty()) { strm << value; if (!summary.empty()) strm << ' ' << summary; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] a1d4903 - Fix lldb-vscode frame test failure
Author: Jeffrey Tan Date: 2022-05-23T14:04:37-07:00 New Revision: a1d490319a9e2196786f6504e0c447ee0a1dad71 URL: https://github.com/llvm/llvm-project/commit/a1d490319a9e2196786f6504e0c447ee0a1dad71 DIFF: https://github.com/llvm/llvm-project/commit/a1d490319a9e2196786f6504e0c447ee0a1dad71.diff LOG: Fix lldb-vscode frame test failure Previous patch (https://reviews.llvm.org/D126013) added a new "optimized" attribute to DAP stack frame this caused some tests, like lldb-vscode/coreFile/TestVSCode_coreFile.py to fail because the tests explicitly check for all attributes. To fix the test failure I decided to remove this attribute. Differential Revision: https://reviews.llvm.org/D126225 Added: Modified: lldb/tools/lldb-vscode/JSONUtils.cpp Removed: diff --git a/lldb/tools/lldb-vscode/JSONUtils.cpp b/lldb/tools/lldb-vscode/JSONUtils.cpp index 1fb4c00a8255..4bc965e61b81 100644 --- a/lldb/tools/lldb-vscode/JSONUtils.cpp +++ b/lldb/tools/lldb-vscode/JSONUtils.cpp @@ -765,7 +765,6 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame) { if (is_optimized) frame_name += " [opt]"; EmplaceSafeString(object, "name", frame_name); - object.try_emplace("optimized", is_optimized); int64_t disasm_line = 0; object.try_emplace("source", CreateSource(frame, disasm_line)); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 8c6e138 - Support logpoints in lldb-vscode
Author: Jeffrey Tan Date: 2022-06-20T16:22:12-07:00 New Revision: 8c6e138aa893bb88fc3d5d449e42082741f0e2a2 URL: https://github.com/llvm/llvm-project/commit/8c6e138aa893bb88fc3d5d449e42082741f0e2a2 DIFF: https://github.com/llvm/llvm-project/commit/8c6e138aa893bb88fc3d5d449e42082741f0e2a2.diff LOG: Support logpoints in lldb-vscode This patch implements VSCode DAP logpoints feature (also called tracepoint in other VS debugger). This will provide a convenient way for user to do printf style logging debugging without pausing debuggee. Differential Revision: https://reviews.llvm.org/D127702 Added: lldb/test/API/tools/lldb-vscode/breakpoint/TestVSCode_logpoints.py Modified: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py lldb/test/API/tools/lldb-vscode/breakpoint/TestVSCode_setBreakpoints.py lldb/test/API/tools/lldb-vscode/breakpoint/main.cpp lldb/tools/lldb-vscode/BreakpointBase.cpp lldb/tools/lldb-vscode/BreakpointBase.h lldb/tools/lldb-vscode/FunctionBreakpoint.cpp lldb/tools/lldb-vscode/SourceBreakpoint.cpp lldb/tools/lldb-vscode/lldb-vscode.cpp Removed: diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py index b0fb17ffa9719..90d90d959592d 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py @@ -22,13 +22,15 @@ def build_and_create_debug_adaptor(self, lldbVSCodeEnv=None): self.build() self.create_debug_adaptor(lldbVSCodeEnv) -def set_source_breakpoints(self, source_path, lines, condition=None, - hitCondition=None): +def set_source_breakpoints(self, source_path, lines, data=None): '''Sets source breakpoints and returns an array of strings containing the breakpoint IDs ("1", "2") for each breakpoint that was set. + Parameter data is array of data objects for breakpoints. + Each object in data is 1:1 mapping with the entry in lines. + It contains optional location/hitCondition/logMessage parameters. ''' response = self.vscode.request_setBreakpoints( -source_path, lines, condition=condition, hitCondition=hitCondition) +source_path, lines, data) if response is None: return [] breakpoints = response['body']['breakpoints'] diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py index 603b1545cd714..8a871732f7a61 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py @@ -750,8 +750,11 @@ def request_scopes(self, frameId): } return self.send_recv(command_dict) -def request_setBreakpoints(self, file_path, line_array, condition=None, - hitCondition=None): +def request_setBreakpoints(self, file_path, line_array, data=None): +''' data is array of parameters for breakpoints in line_array. +Each parameter object is 1:1 mapping with entries in line_entry. +It contains optional location/hitCondition/logMessage parameters. +''' (dir, base) = os.path.split(file_path) source_dict = { 'name': base, @@ -764,12 +767,18 @@ def request_setBreakpoints(self, file_path, line_array, condition=None, if line_array is not None: args_dict['lines'] = '%s' % line_array breakpoints = [] -for line in line_array: +for i, line in enumerate(line_array): +breakpoint_data = None +if data is not None and i < len(data): +breakpoint_data = data[i] bp = {'line': line} -if condition is not None: -bp['condition'] = condition -if hitCondition is not None: -bp['hitCondition'] = hitCondition +if breakpoint_data is not None: +if 'condition' in breakpoint_data and breakpoint_data['condition']: +bp['condition'] = breakpoint_data['condition'] +if 'hitCondition' in breakpoint_data and breakpoint_data['hitCondition']: +bp['hitCondition'] = breakpoint_data['hitCondition'] +if 'logMessage' in breakpoint_data and breakpoint_data['logMessage']: +bp['logMessage'] = breakpoint_data['logMessage'] breakpoints.append(bp) args_dict['breakpoints'] =
[Lldb-commits] [lldb] 5109de2 - Fix build break introduced by https://reviews.llvm.org/D127702
Author: Jeffrey Tan Date: 2022-06-20T17:31:26-07:00 New Revision: 5109de2da2e2b2321bd2bc504a3ddcedce51c0f8 URL: https://github.com/llvm/llvm-project/commit/5109de2da2e2b2321bd2bc504a3ddcedce51c0f8 DIFF: https://github.com/llvm/llvm-project/commit/5109de2da2e2b2321bd2bc504a3ddcedce51c0f8.diff LOG: Fix build break introduced by https://reviews.llvm.org/D127702 Fix build break introduced by https://reviews.llvm.org/D127702 Differential Revision: https://reviews.llvm.org/D128234 Added: Modified: lldb/tools/lldb-vscode/BreakpointBase.cpp lldb/tools/lldb-vscode/BreakpointBase.h Removed: diff --git a/lldb/tools/lldb-vscode/BreakpointBase.cpp b/lldb/tools/lldb-vscode/BreakpointBase.cpp index 14d279dfd660..0637637b84e5 100644 --- a/lldb/tools/lldb-vscode/BreakpointBase.cpp +++ b/lldb/tools/lldb-vscode/BreakpointBase.cpp @@ -103,7 +103,8 @@ void BreakpointBase::SetLogMessage() { last_raw_text_start = curly_braces_range.second + 1; } // Trailing raw text after close curly brace. - if (logMessage.size() > last_raw_text_start) + assert(last_raw_text_start >= 0); + if (logMessage.size() > (size_t)last_raw_text_start) logMessageParts.emplace_back( llvm::StringRef(logMessage.c_str() + last_raw_text_start, logMessage.size() - last_raw_text_start), @@ -127,7 +128,8 @@ bool BreakpointBase::BreakpointHitCallback( if (messagePart.is_expr) { // Try local frame variables first before fall back to expression // evaluation - const char *expr = messagePart.text.str().c_str(); + std::string expr_str = messagePart.text.str(); + const char *expr = expr_str.c_str(); lldb::SBValue value = frame.GetValueForVariablePath(expr, lldb::eDynamicDontRunTarget); if (value.GetError().Fail()) diff --git a/lldb/tools/lldb-vscode/BreakpointBase.h b/lldb/tools/lldb-vscode/BreakpointBase.h index 321c8adfbfb9..4becd4aa8196 100644 --- a/lldb/tools/lldb-vscode/BreakpointBase.h +++ b/lldb/tools/lldb-vscode/BreakpointBase.h @@ -20,6 +20,8 @@ namespace lldb_vscode { struct BreakpointBase { // logMessage part can be either a raw text or an expression. struct LogMessagePart { +LogMessagePart(llvm::StringRef text, bool is_expr) +: text(text), is_expr(is_expr) {} llvm::StringRef text; bool is_expr; }; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 83263ae - Add HitCount into Breakpoint statistics
Author: Jeffrey Tan Date: 2023-03-03T10:28:56-08:00 New Revision: 83263aeceb8e89709a5da417db753a02bb5a0fbd URL: https://github.com/llvm/llvm-project/commit/83263aeceb8e89709a5da417db753a02bb5a0fbd DIFF: https://github.com/llvm/llvm-project/commit/83263aeceb8e89709a5da417db753a02bb5a0fbd.diff LOG: Add HitCount into Breakpoint statistics Turns out breakpoint statistics is missing hitCount. This patches adds the hitCount field. Differential Revision: https://reviews.llvm.org/D145203 Added: Modified: lldb/source/Breakpoint/Breakpoint.cpp lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py Removed: diff --git a/lldb/source/Breakpoint/Breakpoint.cpp b/lldb/source/Breakpoint/Breakpoint.cpp index aad01a2e6fb67..bdaf3c905d042 100644 --- a/lldb/source/Breakpoint/Breakpoint.cpp +++ b/lldb/source/Breakpoint/Breakpoint.cpp @@ -532,12 +532,12 @@ void Breakpoint::ModulesChanged(ModuleList &module_list, bool load, locations_with_no_section.Add(break_loc_sp); continue; } - + if (!break_loc_sp->IsEnabled()) continue; - + SectionSP section_sp(section_addr.GetSection()); - + // If we don't have a Section, that means this location is a raw // address that we haven't resolved to a section yet. So we'll have to // look in all the new modules to resolve this location. Otherwise, if @@ -554,9 +554,9 @@ void Breakpoint::ModulesChanged(ModuleList &module_list, bool load, } } } - + size_t num_to_delete = locations_with_no_section.GetSize(); - + for (size_t i = 0; i < num_to_delete; i++) m_locations.RemoveLocation(locations_with_no_section.GetByIndex(i)); @@ -1132,12 +1132,13 @@ json::Value Breakpoint::GetStatistics() { bp.try_emplace("resolveTime", m_resolve_time.get().count()); bp.try_emplace("numLocations", (int64_t)GetNumLocations()); bp.try_emplace("numResolvedLocations", (int64_t)GetNumResolvedLocations()); + bp.try_emplace("hitCount", (int64_t)GetHitCount()); bp.try_emplace("internal", IsInternal()); if (!m_kind_description.empty()) bp.try_emplace("kindDescription", m_kind_description); // Put the full structured data for reproducing this breakpoint in a key/value // pair named "details". This allows the breakpoint's details to be visible - // in the stats in case we need to reproduce a breakpoint that has long + // in the stats in case we need to reproduce a breakpoint that has long // resolve times StructuredData::ObjectSP bp_data_sp = SerializeToStructuredData(); if (bp_data_sp) { diff --git a/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py b/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py index 36860ecb29482..95d2a633d24e5 100644 --- a/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py +++ b/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py @@ -423,7 +423,6 @@ def test_add_commands_by_breakpoint_name(self): patterns=["bktptcmd.function"]) - def test_breakpoint_delete_disabled(self): """Test 'break delete --disabled' works""" self.build() @@ -548,3 +547,26 @@ def test_breakpoints_auto_source_map_relative(self): source_map_json = self.get_source_map_json() self.assertEquals(len(source_map_json), 0, "source map should not be deduced") + + +def test_breakpoint_statistics_hitcount(self): +"""Test breakpoints statistics have hitCount field.""" +self.build() +target = self.createTestTarget() + +lldbutil.run_break_set_by_file_and_line( +self, "main.c", self.line, num_expected_locations=1, loc_exact=True) + +stream = lldb.SBStream() +res = target.GetStatistics().GetAsJSON(stream) +self.assertTrue(res.Success()) +debug_stats = json.loads(stream.GetData()) +self.assertEqual('targets' in debug_stats, True, +'Make sure the "targets" key in in target.GetStatistics()') +target_stats = debug_stats['targets'][0] +self.assertNotEqual(target_stats, None) + +breakpoints_stats = target_stats['breakpoints'] +self.assertNotEqual(breakpoints_stats, None) +for breakpoint_stats in breakpoints_stats: +self.assertIn("hitCount", breakpoint_stats) ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] b461398 - Add a new SBDebugger::SetDestroyCallback() API
Author: Jeffrey Tan Date: 2023-03-07T14:48:15-08:00 New Revision: b461398f1ce307ec80708b7eb50f3bc82b76ed3f URL: https://github.com/llvm/llvm-project/commit/b461398f1ce307ec80708b7eb50f3bc82b76ed3f DIFF: https://github.com/llvm/llvm-project/commit/b461398f1ce307ec80708b7eb50f3bc82b76ed3f.diff LOG: Add a new SBDebugger::SetDestroyCallback() API Adding a new SBDebugger::SetDestroyCallback() API. This API can be used by any client to query for statistics/metrics before exiting debug sessions. Differential Revision: https://reviews.llvm.org/D143520 Added: Modified: lldb/bindings/python/python-typemaps.swig lldb/bindings/python/python-wrapper.swig lldb/include/lldb/API/SBDebugger.h lldb/include/lldb/API/SBDefines.h lldb/include/lldb/Core/Debugger.h lldb/include/lldb/lldb-private-types.h lldb/source/API/SBDebugger.cpp lldb/source/Core/Debugger.cpp lldb/test/API/python_api/debugger/TestDebuggerAPI.py Removed: diff --git a/lldb/bindings/python/python-typemaps.swig b/lldb/bindings/python/python-typemaps.swig index 1b1f2e1fe2664..b3e7dd4ee265a 100644 --- a/lldb/bindings/python/python-typemaps.swig +++ b/lldb/bindings/python/python-typemaps.swig @@ -384,6 +384,29 @@ template <> bool SetNumberFromPyObject(double &number, PyObject *obj) { $1 = $1 || PyCallable_Check(reinterpret_cast($input)); } +// For lldb::SBDebuggerDestroyCallback +%typemap(in) (lldb::SBDebuggerDestroyCallback destroy_callback, void *baton) { + if (!($input == Py_None || +PyCallable_Check(reinterpret_cast($input { +PyErr_SetString(PyExc_TypeError, "Need a callable object or None!"); +SWIG_fail; + } + + // FIXME (filcab): We can't currently check if our callback is already + // LLDBSwigPythonCallPythonSBDebuggerTerminateCallback (to DECREF the previous + // baton) nor can we just remove all traces of a callback, if we want to + // revert to a file logging mechanism. + + // Don't lose the callback reference + Py_INCREF($input); + $1 = LLDBSwigPythonCallPythonSBDebuggerTerminateCallback; + $2 = $input; +} + +%typemap(typecheck) (lldb::SBDebuggerDestroyCallback destroy_callback, void *baton) { + $1 = $input == Py_None; + $1 = $1 || PyCallable_Check(reinterpret_cast($input)); +} %typemap(in) lldb::FileSP { PythonFile py_file(PyRefType::Borrowed, $input); diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig index 26f79266538a5..d82c2dace18f3 100644 --- a/lldb/bindings/python/python-wrapper.swig +++ b/lldb/bindings/python/python-wrapper.swig @@ -1062,4 +1062,16 @@ static void LLDBSwigPythonCallPythonLogOutputCallback(const char *str, SWIG_PYTHON_THREAD_END_BLOCK; } } + +// For DebuggerTerminateCallback functions +static void LLDBSwigPythonCallPythonSBDebuggerTerminateCallback(lldb::user_id_t debugger_id, + void *baton) { + if (baton != Py_None) { +SWIG_PYTHON_THREAD_BEGIN_BLOCK; +PyObject *result = PyObject_CallFunction( +reinterpret_cast(baton), const_cast("l"), debugger_id); +Py_XDECREF(result); +SWIG_PYTHON_THREAD_END_BLOCK; + } +} %} diff --git a/lldb/include/lldb/API/SBDebugger.h b/lldb/include/lldb/API/SBDebugger.h index 80f76480363f3..8e8e1b61e08fb 100644 --- a/lldb/include/lldb/API/SBDebugger.h +++ b/lldb/include/lldb/API/SBDebugger.h @@ -316,6 +316,9 @@ class LLDB_API SBDebugger { void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton); + void SetDestroyCallback(lldb::SBDebuggerDestroyCallback destroy_callback, + void *baton); + // DEPRECATED #ifndef SWIG void DispatchInput(void *baton, const void *data, size_t data_len); diff --git a/lldb/include/lldb/API/SBDefines.h b/lldb/include/lldb/API/SBDefines.h index 848480d4f5e01..e7f8ca7b35f0d 100644 --- a/lldb/include/lldb/API/SBDefines.h +++ b/lldb/include/lldb/API/SBDefines.h @@ -110,6 +110,10 @@ class LLDB_API SBUnixSignals; typedef bool (*SBBreakpointHitCallback)(void *baton, SBProcess &process, SBThread &thread, lldb::SBBreakpointLocation &location); + +typedef void (*SBDebuggerDestroyCallback)(lldb::user_id_t debugger_id, + void *baton); + typedef void *ScriptedObject; } diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h index 9f83a37bc75cc..07d9cf28beebf 100644 --- a/lldb/include/lldb/Core/Debugger.h +++ b/lldb/include/lldb/Core/Debugger.h @@ -450,6 +450,10 @@ class Debugger : public std::enable_shared_from_this, static void ReportSymbolChange(const ModuleSpec &module_spec); + void + SetDestroyCallback(lldb_private::DebuggerDestroyCallback destroy_callback, + void *baton); + protected: friend class CommandInterprete
[Lldb-commits] [lldb] 46c2e4c - Refactor ObjectFilePlaceholder for sharing
Author: Jeffrey Tan Date: 2023-03-13T11:09:05-07:00 New Revision: 46c2e4c4f347038179e21e027128f5f2914fb980 URL: https://github.com/llvm/llvm-project/commit/46c2e4c4f347038179e21e027128f5f2914fb980 DIFF: https://github.com/llvm/llvm-project/commit/46c2e4c4f347038179e21e027128f5f2914fb980.diff LOG: Refactor ObjectFilePlaceholder for sharing This patch refactors PlaceholderObjectFile into ObjectFile plugin directory so that we can reuse it for other cases like coredump debugging with NT_FILE notes. PlaceholderObjectFile is also renamed to ObjectFilePlaceholder to be consistent with ObjectFile plugin naming convention. Differential Revision: https://reviews.llvm.org/D145955 Added: lldb/source/Plugins/ObjectFile/Placeholder/CMakeLists.txt lldb/source/Plugins/ObjectFile/Placeholder/ObjectFilePlaceholder.cpp lldb/source/Plugins/ObjectFile/Placeholder/ObjectFilePlaceholder.h Modified: lldb/source/Plugins/ObjectFile/CMakeLists.txt lldb/source/Plugins/Process/minidump/CMakeLists.txt lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp Removed: diff --git a/lldb/source/Plugins/ObjectFile/CMakeLists.txt b/lldb/source/Plugins/ObjectFile/CMakeLists.txt index 5cc1240e0768b..6b5ec86399117 100644 --- a/lldb/source/Plugins/ObjectFile/CMakeLists.txt +++ b/lldb/source/Plugins/ObjectFile/CMakeLists.txt @@ -6,4 +6,5 @@ add_subdirectory(Mach-O) add_subdirectory(Minidump) add_subdirectory(PDB) add_subdirectory(PECOFF) +add_subdirectory(Placeholder) add_subdirectory(wasm) diff --git a/lldb/source/Plugins/ObjectFile/Placeholder/CMakeLists.txt b/lldb/source/Plugins/ObjectFile/Placeholder/CMakeLists.txt new file mode 100644 index 0..d7f8762581016 --- /dev/null +++ b/lldb/source/Plugins/ObjectFile/Placeholder/CMakeLists.txt @@ -0,0 +1,12 @@ +add_lldb_library(lldbPluginObjectFilePlaceholder PLUGIN + ObjectFilePlaceholder.cpp + + LINK_LIBS +lldbCore +lldbHost +lldbSymbol +lldbTarget + LINK_COMPONENTS +Object +Support + ) diff --git a/lldb/source/Plugins/ObjectFile/Placeholder/ObjectFilePlaceholder.cpp b/lldb/source/Plugins/ObjectFile/Placeholder/ObjectFilePlaceholder.cpp new file mode 100644 index 0..ec1f3f61892d3 --- /dev/null +++ b/lldb/source/Plugins/ObjectFile/Placeholder/ObjectFilePlaceholder.cpp @@ -0,0 +1,70 @@ +//===-- ObjectFilePlaceholder.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 "ObjectFilePlaceholder.h" + +#include "lldb/Core/Module.h" +#include "lldb/Core/ModuleSpec.h" +#include "lldb/Core/PluginManager.h" +#include "lldb/Core/Section.h" +#include "lldb/Target/SectionLoadList.h" +#include "lldb/Target/Target.h" + +#include + +using namespace lldb; +using namespace lldb_private; + +LLDB_PLUGIN_DEFINE(ObjectFilePlaceholder) + +ObjectFilePlaceholder::ObjectFilePlaceholder( +const lldb::ModuleSP &module_sp, +const lldb_private::ModuleSpec &module_spec, lldb::addr_t base, +lldb::addr_t size) +: ObjectFile(module_sp, &module_spec.GetFileSpec(), /*file_offset*/ 0, + /*length*/ 0, /*data_sp*/ nullptr, /*data_offset*/ 0), + m_arch(module_spec.GetArchitecture()), m_uuid(module_spec.GetUUID()), + m_base(base), m_size(size) { + m_symtab_up = std::make_unique(this); +} + +void ObjectFilePlaceholder::CreateSections( +lldb_private::SectionList &unified_section_list) { + m_sections_up = std::make_unique(); + auto section_sp = std::make_shared( + GetModule(), this, /*sect_id*/ 0, + lldb_private::ConstString(".module_image"), eSectionTypeOther, m_base, + m_size, /*file_offset*/ 0, /*file_size*/ 0, + /*log2align*/ 0, /*flags*/ 0); + section_sp->SetPermissions(ePermissionsReadable | ePermissionsExecutable); + m_sections_up->AddSection(section_sp); + unified_section_list.AddSection(std::move(section_sp)); +} + +lldb_private::Address ObjectFilePlaceholder::GetBaseAddress() { + return lldb_private::Address(m_sections_up->GetSectionAtIndex(0), 0); +} + +bool ObjectFilePlaceholder::SetLoadAddress(Target &target, addr_t value, + bool value_is_offset) { + assert(!value_is_offset); + assert(value == m_base); + + // Create sections if they haven't been created already. + GetModule()->GetSectionList(); + assert(m_sections_up->GetNumSections(0) == 1); + + target.GetSectionLoadList().SetSectionLoadAddress( + m_sections_up->GetSectionAtIndex(0), m_base); + return true; +} + +void ObjectFilePlaceholder::Dump(lldb_private::Stream *s) { + s->Format("Placeholder object file for {0} loaded at [{1:x}-{2:x})\n", +GetFileSpec(
[Lldb-commits] [lldb] 25159ee - Fix libstdc++ data formatter for reference/pointer to std::string
Author: Jeffrey Tan Date: 2023-05-12T10:09:58-07:00 New Revision: 25159ee3af5cd1c05c010ea195b4b359df3fe820 URL: https://github.com/llvm/llvm-project/commit/25159ee3af5cd1c05c010ea195b4b359df3fe820 DIFF: https://github.com/llvm/llvm-project/commit/25159ee3af5cd1c05c010ea195b4b359df3fe820.diff LOG: Fix libstdc++ data formatter for reference/pointer to std::string This patch fixes libstdc++ data formatter for reference/pointer to std::string. The failure testcases are added which succeed with the patch. Differential Revision: https://reviews.llvm.org/D150313 Added: Modified: lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp Removed: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp index 90976fa053b8a..c7f1c79422246 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp @@ -233,8 +233,15 @@ bool lldb_private::formatters::LibStdcppStringSummaryProvider( ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) { const bool scalar_is_load_addr = true; AddressType addr_type; - lldb::addr_t addr_of_string = - valobj.GetAddressOf(scalar_is_load_addr, &addr_type); + lldb::addr_t addr_of_string = LLDB_INVALID_ADDRESS; + if (valobj.IsPointerOrReferenceType()) { +Status error; +ValueObjectSP pointee_sp = valobj.Dereference(error); +if (pointee_sp && error.Success()) + addr_of_string = pointee_sp->GetAddressOf(scalar_is_load_addr, &addr_type); + } else +addr_of_string = +valobj.GetAddressOf(scalar_is_load_addr, &addr_type); if (addr_of_string != LLDB_INVALID_ADDRESS) { switch (addr_type) { case eAddressTypeLoad: { diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py index 6ce7235ff015d..34d39ee3e6b09 100644 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py @@ -57,6 +57,11 @@ def cleanup(): var_empty = self.frame().FindVariable('empty') var_q = self.frame().FindVariable('q') var_Q = self.frame().FindVariable('Q') +var_rq = self.frame().FindVariable('rq') +var_rQ = self.frame().FindVariable('rQ') +var_pq = self.frame().FindVariable('pq') +var_pQ = self.frame().FindVariable('pQ') + var_uchar = self.frame().FindVariable('uchar') self.assertEqual(var_wempty.GetSummary(), 'L""', "wempty summary wrong") @@ -75,6 +80,18 @@ def cleanup(): var_Q.GetSummary(), '"quite a long std::strin with lots of info inside it"', "Q summary wrong") self.assertEqual(var_uchar.GetSummary(), '"a"', "u summary wrong") +self.assertEqual( +var_rq.GetSummary(), '"hello world"', +"rq summary wrong") +self.assertEqual( +var_rQ.GetSummary(), '"quite a long std::strin with lots of info inside it"', +"rQ summary wrong") +self.assertEqual( +var_pq.GetSummary(), '"hello world"', +"pq summary wrong") +self.assertEqual( +var_pQ.GetSummary(), '"quite a long std::strin with lots of info inside it"', +"pQ summary wrong") self.runCmd("next") diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp index 73519197d8c1a..930f8c2afef21 100644 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp @@ -10,6 +10,8 @@ int main() std::string q("hello world"); std::string Q("quite a long std::strin with lots of info inside it"); std::basic_string uchar(5, 'a'); +auto &rq = q, &rQ = Q; +std::string *pq = &q, *pQ = &Q; S.assign(L"!"); // Set break point at this line. return 0; } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] d5f5475 - Add SBDebugger::GetSetting() public APIs
Author: Jeffrey Tan Date: 2022-09-11T20:50:03-07:00 New Revision: d5f54751048b59cc101125e03dabc57536fc1d2d URL: https://github.com/llvm/llvm-project/commit/d5f54751048b59cc101125e03dabc57536fc1d2d DIFF: https://github.com/llvm/llvm-project/commit/d5f54751048b59cc101125e03dabc57536fc1d2d.diff LOG: Add SBDebugger::GetSetting() public APIs This patch adds new SBDebugger::GetSetting() API which enables client to access settings as SBStructedData. Implementation wise, a new ToJSON() virtual function is added to OptionValue class so that each concrete child class can override and provides its own JSON representation. This patch aims to define the APIs and implement a common set of OptionValue child classes, leaving the remaining for future patches. This patch is used later by auto deduce source map from source line breakpoint feature for testing generated source map entries. Differential Revision: https://reviews.llvm.org/D133038 Added: Modified: lldb/bindings/interface/SBDebugger.i lldb/include/lldb/API/SBDebugger.h lldb/include/lldb/Core/UserSettingsController.h lldb/include/lldb/Interpreter/OptionValue.h lldb/include/lldb/Interpreter/OptionValueArray.h lldb/include/lldb/Interpreter/OptionValueBoolean.h lldb/include/lldb/Interpreter/OptionValueChar.h lldb/include/lldb/Interpreter/OptionValueDictionary.h lldb/include/lldb/Interpreter/OptionValueFileSpec.h lldb/include/lldb/Interpreter/OptionValueFormat.h lldb/include/lldb/Interpreter/OptionValueFormatEntity.h lldb/include/lldb/Interpreter/OptionValueLanguage.h lldb/include/lldb/Interpreter/OptionValuePathMappings.h lldb/include/lldb/Interpreter/OptionValueProperties.h lldb/include/lldb/Interpreter/OptionValueRegex.h lldb/include/lldb/Interpreter/OptionValueSInt64.h lldb/include/lldb/Interpreter/OptionValueString.h lldb/include/lldb/Interpreter/OptionValueUInt64.h lldb/include/lldb/Interpreter/OptionValueUUID.h lldb/include/lldb/Target/PathMappingList.h lldb/source/API/SBDebugger.cpp lldb/source/Core/UserSettingsController.cpp lldb/source/Interpreter/OptionValueArray.cpp lldb/source/Interpreter/OptionValueDictionary.cpp lldb/source/Interpreter/OptionValueFormat.cpp lldb/source/Interpreter/OptionValueFormatEntity.cpp lldb/source/Interpreter/OptionValueLanguage.cpp lldb/source/Interpreter/OptionValuePathMappings.cpp lldb/source/Interpreter/OptionValueProperties.cpp lldb/source/Target/PathMappingList.cpp lldb/test/API/commands/settings/TestSettings.py lldb/test/API/functionalities/source-map/TestTargetSourceMap.py Removed: diff --git a/lldb/bindings/interface/SBDebugger.i b/lldb/bindings/interface/SBDebugger.i index 5d51a6ac20d2f..e82ce2aa8e7c7 100644 --- a/lldb/bindings/interface/SBDebugger.i +++ b/lldb/bindings/interface/SBDebugger.i @@ -225,6 +225,8 @@ public: } } +lldb::SBStructuredData GetSetting(const char *setting = nullptr); + SBError SetInputString (const char* data); diff --git a/lldb/include/lldb/API/SBDebugger.h b/lldb/include/lldb/API/SBDebugger.h index b9a9b593d0ad4..d3de61caeb811 100644 --- a/lldb/include/lldb/API/SBDebugger.h +++ b/lldb/include/lldb/API/SBDebugger.h @@ -115,6 +115,21 @@ class LLDB_API SBDebugger { void Clear(); + /// Getting a specific setting value into SBStructuredData format. + /// Client can specify empty string or null to get all settings. + /// + /// Example usages: + /// lldb::SBStructuredData settings = debugger.GetSetting(); + /// lldb::SBStructuredData settings = debugger.GetSetting(nullptr); + /// lldb::SBStructuredData settings = debugger.GetSetting(""); + /// lldb::SBStructuredData settings = debugger.GetSetting("target.arg0"); + /// lldb::SBStructuredData settings = debugger.GetSetting("target"); + /// + /// \param[out] setting + /// Property setting path to retrieve values. e.g "target.source-map" + /// + lldb::SBStructuredData GetSetting(const char *setting = nullptr); + void SetAsync(bool b); bool GetAsync(); diff --git a/lldb/include/lldb/Core/UserSettingsController.h b/lldb/include/lldb/Core/UserSettingsController.h index 3f08c351d..8afef06359738 100644 --- a/lldb/include/lldb/Core/UserSettingsController.h +++ b/lldb/include/lldb/Core/UserSettingsController.h @@ -57,10 +57,11 @@ class Properties { virtual Status DumpPropertyValue(const ExecutionContext *exe_ctx, Stream &strm, llvm::StringRef property_path, - uint32_t dump_mask); + uint32_t dump_mask, bool is_json = false); virtual void DumpAllPropertyValues(const ExecutionContext *exe_ctx, - Stream &strm, uint32_t dump_mask); + Stream &strm, uint32_t dump_mask, +
[Lldb-commits] [lldb] dc9e6c5 - Add auto deduce source map setting
Author: Jeffrey Tan Date: 2022-09-19T13:40:22-07:00 New Revision: dc9e6c52f3d805ab454bcf2a4502037d15fb2b8c URL: https://github.com/llvm/llvm-project/commit/dc9e6c52f3d805ab454bcf2a4502037d15fb2b8c DIFF: https://github.com/llvm/llvm-project/commit/dc9e6c52f3d805ab454bcf2a4502037d15fb2b8c.diff LOG: Add auto deduce source map setting This patch adds a new "target.auto-source-map-relative" setting. If enabled, this setting may auto deduce a source map entry based on requested breakpoint path and the original path stored in debug info for resolved breakpoint. As an example, if debug info contains "./a/b/c/main.cpp", user sets a source breakpoint at "/root/repo/x/y/z/a/b/c/main.cpp". The breakpoint will resolve correctly now with Greg's patch https://reviews.llvm.org/D130401. However, the resolved breakpoint will use "./a/b/c/main.cpp" to locate source file during stop event which would fail most of the time. With the new "target.auto-source-map-relative" setting enabled, a auto deduced source map entry "." => "/root/repo/x/y/z" will be added. This new mapping will help lldb to map resolved breakpoint path "./a/b/c/main.cpp" back to "/root/repo/x/y/z/a/b/c/main.cpp" and locate it on disk. If an existing source map entry is used the patch also concatenates the auto deduced entry with any stripped reverse mapping prefix (see example below). As a second example, debug info contains "./a/b/c/main.cpp" and user sets breakpoint at "/root/repo/x/y/z/a/b/c/main.cpp". Let's say there is an existing source map entry "." => "/root/repo"; this mapping would strip the prefix out of "/root/repo/x/y/z/a/b/c/main.cpp" and use "x/y/z/a/b/c/main.cpp" to resolve breakpoint. "target.auto-source-map-relative" setting would auto deduce a new potential mapping of "." => "x/y/z", then it detects that there is a stripped prefix from reverse mapping and concatenates it as the new mapping: "." => "/root/repo/x/y/z" which would correct map "./a/b/c/main.cpp" path to new path in disk. This patches depends on https://reviews.llvm.org/D130401 to use new added SBDebugger::GetSetting() API for testing. Differential Revision: https://reviews.llvm.org/D133042 Added: Modified: lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h lldb/include/lldb/Target/PathMappingList.h lldb/include/lldb/Target/Target.h lldb/source/Breakpoint/BreakpointResolverFileLine.cpp lldb/source/Target/PathMappingList.cpp lldb/source/Target/Target.cpp lldb/source/Target/TargetProperties.td lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py lldb/unittests/Target/PathMappingListTest.cpp Removed: diff --git a/lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h b/lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h index e73632aad6a85..bc1fdff92b8db 100644 --- a/lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h +++ b/lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h @@ -21,9 +21,10 @@ namespace lldb_private { class BreakpointResolverFileLine : public BreakpointResolver { public: - BreakpointResolverFileLine(const lldb::BreakpointSP &bkpt, - lldb::addr_t offset, bool skip_prologue, - const SourceLocationSpec &location_spec); + BreakpointResolverFileLine( + const lldb::BreakpointSP &bkpt, lldb::addr_t offset, bool skip_prologue, + const SourceLocationSpec &location_spec, + llvm::Optional removed_prefix_opt = llvm::None); static BreakpointResolver * CreateFromStructuredData(const lldb::BreakpointSP &bkpt, @@ -57,10 +58,14 @@ class BreakpointResolverFileLine : public BreakpointResolver { protected: void FilterContexts(SymbolContextList &sc_list); + void DeduceSourceMapping(SymbolContextList &sc_list); friend class Breakpoint; SourceLocationSpec m_location_spec; bool m_skip_prologue; + // Any previously removed file path prefix by reverse source mapping. + // This is used to auto deduce source map if needed. + llvm::Optional m_removed_prefix_opt; private: BreakpointResolverFileLine(const BreakpointResolverFileLine &) = delete; diff --git a/lldb/include/lldb/Target/PathMappingList.h b/lldb/include/lldb/Target/PathMappingList.h index badbe3e0f8c63..413809ba3f5d2 100644 --- a/lldb/include/lldb/Target/PathMappingList.h +++ b/lldb/include/lldb/Target/PathMappingList.h @@ -37,6 +37,9 @@ class PathMappingList { void Append(const PathMappingList &rhs, bool notify); + void AppendUnique(llvm::StringRef path, llvm::StringRef replacement, +bool notify); + void Clear(bool notify); // By default, dump all pairs. @@ -88,7 +91,22 @@ class PathMappingList { bool only_if_exists = false) co
[Lldb-commits] [lldb] c5073ed - Add auto source map deduce count statistics
Author: Jeffrey Tan Date: 2022-09-22T14:52:58-07:00 New Revision: c5073ed5f92900bbbe9f6a30bbfc9507df54749d URL: https://github.com/llvm/llvm-project/commit/c5073ed5f92900bbbe9f6a30bbfc9507df54749d DIFF: https://github.com/llvm/llvm-project/commit/c5073ed5f92900bbbe9f6a30bbfc9507df54749d.diff LOG: Add auto source map deduce count statistics This patch adds auto source map deduce count as a target level statistics. This will help telemetry to track how many debug sessions benefit from this feature. Differential Revision: https://reviews.llvm.org/D134483 Added: Modified: lldb/include/lldb/Target/PathMappingList.h lldb/include/lldb/Target/Statistics.h lldb/source/Breakpoint/BreakpointResolverFileLine.cpp lldb/source/Target/PathMappingList.cpp lldb/source/Target/Statistics.cpp lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py Removed: diff --git a/lldb/include/lldb/Target/PathMappingList.h b/lldb/include/lldb/Target/PathMappingList.h index 413809ba3f5d2..2f7ee535de3a7 100644 --- a/lldb/include/lldb/Target/PathMappingList.h +++ b/lldb/include/lldb/Target/PathMappingList.h @@ -37,7 +37,9 @@ class PathMappingList { void Append(const PathMappingList &rhs, bool notify); - void AppendUnique(llvm::StringRef path, llvm::StringRef replacement, + /// Append pair without duplication. + /// \return whether appending suceeds without duplication or not. + bool AppendUnique(llvm::StringRef path, llvm::StringRef replacement, bool notify); void Clear(bool notify); diff --git a/lldb/include/lldb/Target/Statistics.h b/lldb/include/lldb/Target/Statistics.h index 9c0b3ea5ec053..2a8fc5be0e05f 100644 --- a/lldb/include/lldb/Target/Statistics.h +++ b/lldb/include/lldb/Target/Statistics.h @@ -133,6 +133,7 @@ class TargetStats { void SetLaunchOrAttachTime(); void SetFirstPrivateStopTime(); void SetFirstPublicStopTime(); + void IncreaseSourceMapDeduceCount(); StatsDuration &GetCreateTime() { return m_create_time; } StatsSuccessFail &GetExpressionStats() { return m_expr_eval; } @@ -146,6 +147,7 @@ class TargetStats { StatsSuccessFail m_expr_eval{"expressionEvaluation"}; StatsSuccessFail m_frame_var{"frameVariable"}; std::vector m_module_identifiers; + uint32_t m_source_map_deduce_count = 0; void CollectStats(Target &target); }; diff --git a/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp b/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp index 7c94cde9d85ca..f911697f5ddc5 100644 --- a/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp +++ b/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp @@ -261,8 +261,10 @@ void BreakpointResolverFileLine::DeduceSourceMapping( if (!new_mapping_from.empty() && !new_mapping_to.empty()) { LLDB_LOG(log, "generating auto source map from {0} to {1}", new_mapping_from, new_mapping_to); - target.GetSourcePathMap().AppendUnique(new_mapping_from, new_mapping_to, - /*notify*/ true); + if (target.GetSourcePathMap().AppendUnique(new_mapping_from, + new_mapping_to, + /*notify*/ true)) +target.GetStatistics().IncreaseSourceMapDeduceCount(); } } } diff --git a/lldb/source/Target/PathMappingList.cpp b/lldb/source/Target/PathMappingList.cpp index 8cd59d8fefe40..d2d60822b237e 100644 --- a/lldb/source/Target/PathMappingList.cpp +++ b/lldb/source/Target/PathMappingList.cpp @@ -76,16 +76,17 @@ void PathMappingList::Append(const PathMappingList &rhs, bool notify) { } } -void PathMappingList::AppendUnique(llvm::StringRef path, +bool PathMappingList::AppendUnique(llvm::StringRef path, llvm::StringRef replacement, bool notify) { auto normalized_path = NormalizePath(path); auto normalized_replacement = NormalizePath(replacement); for (const auto &pair : m_pairs) { if (pair.first.GetStringRef().equals(normalized_path) && pair.second.GetStringRef().equals(normalized_replacement)) - return; + return false; } Append(path, replacement, notify); + return true; } void PathMappingList::Insert(llvm::StringRef path, llvm::StringRef replacement, diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp index b8ad25e71f064..894552cecc516 100644 --- a/lldb/source/Target/Statistics.cpp +++ b/lldb/source/Target/Statistics.cpp @@ -136,6 +136,7 @@ json::Value TargetStats::ToJSON(Target &target) { target_metrics_json.try_emplace("breakpoints", std::move(breakpoints_array)); target_metrics_json.try_emplace("totalBreakpointResolveTime", totalBreakpointResolveTime); + target_metrics_json.try_emplace("sourceMapDeduceCount", m_source_map_dedu
[Lldb-commits] [lldb] ef25a21 - Prevent lldb-vscode tests from source lldbinit file
Author: Jeffrey Tan Date: 2022-10-11T15:43:35-07:00 New Revision: ef25a217266aaf3b6df68ac155537e3a1171dccf URL: https://github.com/llvm/llvm-project/commit/ef25a217266aaf3b6df68ac155537e3a1171dccf DIFF: https://github.com/llvm/llvm-project/commit/ef25a217266aaf3b6df68ac155537e3a1171dccf.diff LOG: Prevent lldb-vscode tests from source lldbinit file lldb-vscode is hard-coded to source .lldbinit file which causes some tests to fail on my machine. This patch adds a new option to control this: 1. vscode.py and lldb-vscode tests will not source .lldbinit by default 2. lldb-vscode will source .lldbinit in production if not specified otherwise Differential Revision: https://reviews.llvm.org/D135620 Added: Modified: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py lldb/tools/lldb-vscode/lldb-vscode.cpp Removed: diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py index 90d90d959592d..8ba8e0e4bf3b4 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py @@ -253,7 +253,7 @@ def attach(self, program=None, pid=None, waitFor=None, trace=None, initCommands=None, preRunCommands=None, stopCommands=None, exitCommands=None, attachCommands=None, coreFile=None, disconnectAutomatically=True, terminateCommands=None, - postRunCommands=None, sourceMap=None): + postRunCommands=None, sourceMap=None, sourceInitFile=False): '''Build the default Makefile target, create the VSCode debug adaptor, and attach to the process. ''' @@ -267,7 +267,7 @@ def cleanup(): # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) # Initialize and launch the program -self.vscode.request_initialize() +self.vscode.request_initialize(sourceInitFile) response = self.vscode.request_attach( program=program, pid=pid, waitFor=waitFor, trace=trace, initCommands=initCommands, preRunCommands=preRunCommands, @@ -284,7 +284,7 @@ def launch(self, program=None, args=None, cwd=None, env=None, disableSTDIO=False, shellExpandArguments=False, trace=False, initCommands=None, preRunCommands=None, stopCommands=None, exitCommands=None, terminateCommands=None, - sourcePath=None, debuggerRoot=None, launchCommands=None, + sourcePath=None, debuggerRoot=None, sourceInitFile=False, launchCommands=None, sourceMap=None, disconnectAutomatically=True, runInTerminal=False, expectFailure=False, postRunCommands=None): '''Sending launch request to vscode @@ -301,7 +301,7 @@ def cleanup(): self.addTearDownHook(cleanup) # Initialize and launch the program -self.vscode.request_initialize() +self.vscode.request_initialize(sourceInitFile) response = self.vscode.request_launch( program, args=args, @@ -344,7 +344,7 @@ def build_and_launch(self, program, args=None, cwd=None, env=None, trace=False, initCommands=None, preRunCommands=None, stopCommands=None, exitCommands=None, terminateCommands=None, sourcePath=None, - debuggerRoot=None, runInTerminal=False, + debuggerRoot=None, sourceInitFile=False, runInTerminal=False, disconnectAutomatically=True, postRunCommands=None, lldbVSCodeEnv=None): '''Build the default Makefile target, create the VSCode debug adaptor, @@ -356,6 +356,7 @@ def build_and_launch(self, program, args=None, cwd=None, env=None, return self.launch(program, args, cwd, env, stopOnEntry, disableASLR, disableSTDIO, shellExpandArguments, trace, initCommands, preRunCommands, stopCommands, exitCommands, -terminateCommands, sourcePath, debuggerRoot, runInTerminal=runInTerminal, +terminateCommands, sourcePath, debuggerRoot, sourceInitFile, +runInTerminal=runInTerminal, disconnectAutomatically=disconnectAutomatically, postRunCommands=postRunCommands) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py index 0996d8696cd25..d6a6abca53e38 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py +++ b/ll
[Lldb-commits] [lldb] 51effa5 - Fix exception description in lldb-vscode
Author: Jeffrey Tan Date: 2022-10-25T13:24:22-07:00 New Revision: 51effa57818bf937fb7c889b8f567c146bb4eefe URL: https://github.com/llvm/llvm-project/commit/51effa57818bf937fb7c889b8f567c146bb4eefe DIFF: https://github.com/llvm/llvm-project/commit/51effa57818bf937fb7c889b8f567c146bb4eefe.diff LOG: Fix exception description in lldb-vscode There is a bug in lldb-vscode that only shows stop reason ("exception") in stopped event without showing the stop description of thrown exception. This causes VSCode UI to only show "Paused on Exception" general message in callstack window UI. This patch fixes the bug so that VSCode callstack will show the detailed exceptioni description, like "signal SIGABRT" or "EXC_BAD_ACCESS..." which aligns with command line lldb experience. I use C++ exception in testcase because the hardware exception description is platform dependent and hard to verify. Differential Revision: https://reviews.llvm.org/D136295 Added: lldb/test/API/tools/lldb-vscode/exception/Makefile lldb/test/API/tools/lldb-vscode/exception/TestVSCode_exception.py lldb/test/API/tools/lldb-vscode/exception/main.cpp Modified: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py lldb/tools/lldb-vscode/JSONUtils.cpp Removed: diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py index 8ba8e0e4bf3b4..a91f3b2b8feff 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py @@ -93,10 +93,10 @@ def verify_breakpoint_hit(self, breakpoint_ids): return self.assertTrue(False, "breakpoint not hit") -def verify_exception_breakpoint_hit(self, filter_label): +def verify_stop_exception_info(self, expected_description): '''Wait for the process we are debugging to stop, and verify the stop reason is 'exception' and that the description matches - 'filter_label' + 'expected_description' ''' stopped_events = self.vscode.wait_for_stopped() for stopped_event in stopped_events: @@ -109,7 +109,7 @@ def verify_exception_breakpoint_hit(self, filter_label): if 'description' not in body: continue description = body['description'] -if filter_label == description: +if expected_description == description: return True return False @@ -236,7 +236,7 @@ def continue_to_breakpoints(self, breakpoint_ids): def continue_to_exception_breakpoint(self, filter_label): self.vscode.request_continue() -self.assertTrue(self.verify_exception_breakpoint_hit(filter_label), +self.assertTrue(self.verify_stop_exception_info(filter_label), 'verify we got "%s"' % (filter_label)) def continue_to_exit(self, exitCode=0): diff --git a/lldb/test/API/tools/lldb-vscode/exception/Makefile b/lldb/test/API/tools/lldb-vscode/exception/Makefile new file mode 100644 index 0..8b20bcb05 --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/exception/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/lldb/test/API/tools/lldb-vscode/exception/TestVSCode_exception.py b/lldb/test/API/tools/lldb-vscode/exception/TestVSCode_exception.py new file mode 100644 index 0..2fc0d9c638c3a --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/exception/TestVSCode_exception.py @@ -0,0 +1,24 @@ +""" +Test exception behavior in VSCode +""" + + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +import lldbvscode_testcase + + +class TestVSCode_exception(lldbvscode_testcase.VSCodeTestCaseBase): + +@skipIfWindows +def test_stopped_description(self): +''' +Test that exception description is shown correctly in stopped +event. +''' +program = self.getBuildArtifact("a.out") +print("test_stopped_description called", flush=True) +self.build_and_launch(program) + +self.vscode.request_continue() +self.assertTrue(self.verify_stop_exception_info("signal SIGABRT")) diff --git a/lldb/test/API/tools/lldb-vscode/exception/main.cpp b/lldb/test/API/tools/lldb-vscode/exception/main.cpp new file mode 100644 index 0..b940d07c6f2bb --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/exception/main.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + raise(SIGABRT); + return 0; +} diff --git a/lldb/tools/lldb-vscode/JSONUtils.cpp b/lldb/tools/lldb-vscode/JSONUtils.cpp index 4bc965e61b81e..baeed2a81105c 100644 --- a/lldb/tools/lldb-vscode/JSONUtils.cpp +++ b/lldb/tools/ll
[Lldb-commits] [lldb] 6c89956 - Add formatting support for VSCode logpoints message
Author: Jeffrey Tan Date: 2022-11-01T08:43:30-07:00 New Revision: 6c8995649afac04a9eb0e71affd997e493c9b93a URL: https://github.com/llvm/llvm-project/commit/6c8995649afac04a9eb0e71affd997e493c9b93a DIFF: https://github.com/llvm/llvm-project/commit/6c8995649afac04a9eb0e71affd997e493c9b93a.diff LOG: Add formatting support for VSCode logpoints message https://reviews.llvm.org/D127702 adds the initial logpoints support in lldb-vscode. This patch further improves it by: 1. Adding a newline at the end of each log message 2. Support most of the format specifiers like \t, \n, \x etc.. The implementation is borrowed from FormatEntity::ParseInternal(). Future patch should merge these two implementations. Differential Revision: https://reviews.llvm.org/D136697 Added: Modified: lldb/test/API/tools/lldb-vscode/breakpoint/TestVSCode_logpoints.py lldb/tools/lldb-vscode/BreakpointBase.cpp lldb/tools/lldb-vscode/BreakpointBase.h Removed: diff --git a/lldb/test/API/tools/lldb-vscode/breakpoint/TestVSCode_logpoints.py b/lldb/test/API/tools/lldb-vscode/breakpoint/TestVSCode_logpoints.py index a63ea01384c2d..9f47d3c07ae9f 100644 --- a/lldb/test/API/tools/lldb-vscode/breakpoint/TestVSCode_logpoints.py +++ b/lldb/test/API/tools/lldb-vscode/breakpoint/TestVSCode_logpoints.py @@ -49,8 +49,7 @@ def test_logmessage_basic(self): # 1. First at the loop line with logMessage # 2. Second guard breakpoint at a line after loop logMessage_prefix = "This is log message for { -- " -# Trailing newline is needed for splitlines() -logMessage = logMessage_prefix + "{i + 3}\n" +logMessage = logMessage_prefix + "{i + 3}" [loop_breakpoint_id, post_loop_breakpoint_id] = self.set_source_breakpoints( self.main_path, [loop_line, after_loop_line], @@ -109,8 +108,7 @@ def test_logmessage_advanced(self): # 1. First at the loop line with logMessage # 2. Second guard breakpoint at a line after loop logMessage_prefix = "This is log message for { -- " -# Trailing newline is needed for splitlines() -logMessage = logMessage_prefix + "{int y = 0; if (i % 3 == 0) { y = i + 3;} else {y = i * 3;} y}\n" +logMessage = logMessage_prefix + "{int y = 0; if (i % 3 == 0) { y = i + 3;} else {y = i * 3;} y}" [loop_breakpoint_id, post_loop_breakpoint_id] = self.set_source_breakpoints( self.main_path, [loop_line, after_loop_line], @@ -138,3 +136,130 @@ def test_logmessage_advanced(self): for idx, logMessage_line in enumerate(logMessage_output): result = idx + 3 if idx % 3 == 0 else idx * 3 self.assertEqual(logMessage_line, logMessage_prefix + str(result)) + +@skipIfWindows +@skipIfRemote +def test_logmessage_format(self): +''' +Tests breakpoint logmessage functionality with format. +''' +before_loop_line = line_number('main.cpp', '// before loop') +loop_line = line_number('main.cpp', '// break loop') +after_loop_line = line_number('main.cpp', '// after loop') + +program = self.getBuildArtifact("a.out") +self.build_and_launch(program) + +# Set a breakpoint at a line before loop +before_loop_breakpoint_ids = self.set_source_breakpoints( +self.main_path, +[before_loop_line]) +self.assertEquals(len(before_loop_breakpoint_ids), 1, "expect one breakpoint") + +self.vscode.request_continue() + +# Verify we hit the breakpoint before loop line +self.verify_breakpoint_hit(before_loop_breakpoint_ids) + +# Swallow old console output +self.get_console() + +# Set two breakpoints: +# 1. First at the loop line with logMessage +# 2. Second guard breakpoint at a line after loop +logMessage_prefix = "This is log message for -- " +logMessage_with_format = "part1\tpart2\bpart3\x64part4" +logMessage_with_format_raw = r"part1\tpart2\bpart3\x64part4" +logMessage = logMessage_prefix + logMessage_with_format_raw + "{i - 1}" +[loop_breakpoint_id, post_loop_breakpoint_id] = self.set_source_breakpoints( +self.main_path, +[loop_line, after_loop_line], +[{'logMessage': logMessage}, {}] +) + +# Continue to trigger the breakpoint with log messages +self.vscode.request_continue() + +# Verify we hit the breakpoint after loop line +self.verify_breakpoint_hit([post_loop_breakpoint_id]) + +output = self.get_console() +lines = output.splitlines() +logMessage_output = [] +for line in lines: +if line.startswith(logMessage_prefix): +logMessage_output.append(line) + +# Verify logMessage count +loop_count = 10 +
[Lldb-commits] [lldb] f0c16f8 - Add runToBinaryEntry option for lldb-vscode
Author: Jeffrey Tan Date: 2022-11-22T13:52:45-08:00 New Revision: f0c16f89124f2dc0630162ff9ea23934f5b2b75b URL: https://github.com/llvm/llvm-project/commit/f0c16f89124f2dc0630162ff9ea23934f5b2b75b DIFF: https://github.com/llvm/llvm-project/commit/f0c16f89124f2dc0630162ff9ea23934f5b2b75b.diff LOG: Add runToBinaryEntry option for lldb-vscode This patch adds a new runToBinaryEntry option which sets a one-shot breakpoint at program entry. This option is useful for synchronizing module loading with dynamic loader to measure debugger startup performance: when program entry one-short breakpoint hits most of the dependency modules should have been loaded so this provides a good sample point for debugger startup time. More explicitly for lldb-vscode, when this option is enabled, "Initialized" DAP event is synchronously sent after most dependency modules are loaded. Differential Revision: https://reviews.llvm.org/D135798 Added: Modified: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py lldb/test/API/tools/lldb-vscode/launch/TestVSCode_launch.py lldb/tools/lldb-vscode/VSCode.cpp lldb/tools/lldb-vscode/VSCode.h lldb/tools/lldb-vscode/lldb-vscode.cpp lldb/tools/lldb-vscode/package.json Removed: diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py index a91f3b2b8feff..99baad59dc12d 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py @@ -286,7 +286,7 @@ def launch(self, program=None, args=None, cwd=None, env=None, stopCommands=None, exitCommands=None, terminateCommands=None, sourcePath=None, debuggerRoot=None, sourceInitFile=False, launchCommands=None, sourceMap=None, disconnectAutomatically=True, runInTerminal=False, - expectFailure=False, postRunCommands=None): + expectFailure=False, postRunCommands=None, runToBinaryEntry=False): '''Sending launch request to vscode ''' @@ -323,7 +323,8 @@ def cleanup(): sourceMap=sourceMap, runInTerminal=runInTerminal, expectFailure=expectFailure, -postRunCommands=postRunCommands) +postRunCommands=postRunCommands, +runToBinaryEntry=runToBinaryEntry) if expectFailure: return response @@ -346,7 +347,7 @@ def build_and_launch(self, program, args=None, cwd=None, env=None, terminateCommands=None, sourcePath=None, debuggerRoot=None, sourceInitFile=False, runInTerminal=False, disconnectAutomatically=True, postRunCommands=None, - lldbVSCodeEnv=None): + lldbVSCodeEnv=None, runToBinaryEntry=False): '''Build the default Makefile target, create the VSCode debug adaptor, and launch the process. ''' @@ -359,4 +360,5 @@ def build_and_launch(self, program, args=None, cwd=None, env=None, terminateCommands, sourcePath, debuggerRoot, sourceInitFile, runInTerminal=runInTerminal, disconnectAutomatically=disconnectAutomatically, -postRunCommands=postRunCommands) +postRunCommands=postRunCommands, +runToBinaryEntry=runToBinaryEntry) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py index c2de4ad5c7d9a..f5f9ae30bbd46 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py @@ -650,7 +650,7 @@ def request_launch(self, program, args=None, cwd=None, env=None, terminateCommands=None ,sourcePath=None, debuggerRoot=None, launchCommands=None, sourceMap=None, runInTerminal=False, expectFailure=False, - postRunCommands=None): + postRunCommands=None, runToBinaryEntry=False): args_dict = { 'program': program } @@ -662,6 +662,8 @@ def request_launch(self, program, args=None, cwd=None, env=None, args_dict['env'] = env if stopOnEntry: args_dict['stopOnEntry'] = stopOnEntry +if runToBinaryEntry: +args_dict['runToBinaryEntry'] = runToBinaryEntry if disableASLR: args_dict['disableASLR'] = disableASLR if disableSTDIO: diff --git a/lldb/test/API/tools/lldb-vscode/launch/TestVSCode
[Lldb-commits] [lldb] b9139ac - Fix expression evaluation result expansion in lldb-vscode
Author: Jeffrey Tan Date: 2021-08-03T15:24:44-07:00 New Revision: b9139acb85a4e5203364838e47b2e1ee90055ad3 URL: https://github.com/llvm/llvm-project/commit/b9139acb85a4e5203364838e47b2e1ee90055ad3 DIFF: https://github.com/llvm/llvm-project/commit/b9139acb85a4e5203364838e47b2e1ee90055ad3.diff LOG: Fix expression evaluation result expansion in lldb-vscode VScode now sends a "scopes" DAP request immediately after any expression evaluation. This scopes request would clear and invalidate any non-scoped expandable variables in g_vsc.variables, causing later "variables" request to return empty result. The symptom is that any expandable variables in VScode watch window/debug console UI to return empty content. This diff fixes this issue by only clearing the expandable variables at process continue time. To achieve this, we have to repopulate all scoped variables during context switch for each "scopes" request without clearing global expandable variables. So the PR puts the scoped variables into its own locals/globals/registers; and all expandable variables into separate "expandableVariables" list. Also, instead of using the variable index for "variableReference", it generates a new variableReference id each time as the key of "expandableVariables". As a further new feature, this PR adds a new "expandablePermanentVariables" which has the lifetime of debug session. Any expandable variables from debug console are added into this list. This enables users to snapshot expanable old variable in debug console and compare with new variables if desire. Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D105166 Added: Modified: lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py lldb/tools/lldb-vscode/VSCode.cpp lldb/tools/lldb-vscode/VSCode.h lldb/tools/lldb-vscode/lldb-vscode.cpp Removed: diff --git a/lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py b/lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py index 765cfbe6ed5a..092d96edf4eb 100644 --- a/lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py +++ b/lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py @@ -23,7 +23,7 @@ class TestVSCode_variables(lldbvscode_testcase.VSCodeTestCaseBase): mydir = TestBase.compute_mydir(__file__) -def verify_values(self, verify_dict, actual, varref_dict=None): +def verify_values(self, verify_dict, actual, varref_dict=None, expression=None): if 'equals' in verify_dict: verify = verify_dict['equals'] for key in verify: @@ -48,9 +48,13 @@ def verify_values(self, verify_dict, actual, varref_dict=None): if hasVariablesReference: # Remember variable references in case we want to test further # by using the evaluate name. -varRef = actual['variablesReference'] +varRef = actual["variablesReference"] if varRef != 0 and varref_dict is not None: -varref_dict[actual['evaluateName']] = varRef +if expression is None: +evaluateName = actual["evaluateName"] +else: +evaluateName = expression +varref_dict[evaluateName] = varRef if ('hasVariablesReference' in verify_dict and verify_dict['hasVariablesReference']): self.assertTrue(hasVariablesReference, @@ -282,3 +286,111 @@ def test_scopes_variables_setVariable_evaluate(self): self.assertNotIn('x @ main.cpp:21', names) self.verify_variables(verify_locals, locals) + +@skipIfWindows +@skipIfRemote +def test_scopes_and_evaluate_expansion(self): +""" +Tests the evaluated expression expands successfully after "scopes" packets +and permanent expressions persist. +""" +program = self.getBuildArtifact("a.out") +self.build_and_launch(program) +source = "main.cpp" +breakpoint1_line = line_number(source, "// breakpoint 1") +lines = [breakpoint1_line] +# Set breakpoint in the thread function so we can step the threads +breakpoint_ids = self.set_source_breakpoints(source, lines) +self.assertEqual( +len(breakpoint_ids), len(lines), "expect correct number of breakpoints" +) +self.continue_to_breakpoints(breakpoint_ids) + +# Verify locals +locals = self.vscode.get_local_variables() +buffer_children = make_buffer_verify_dict(0, 32) +verify_locals = { +"argc": {"equals": {"type": "int", "value": "1"}}, +"argv": { +"equals": {"type": "const char **"}, +"startswith": {"value": "0x"}, +"hasVariablesReference": True, +}, +"pt": { +"equals": {"t