[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
@@ -1130,13 +1130,33 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( if (target) { if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - auto path_or_err = ResolveSDKPathFromDebugInfo(*exe_module_sp); - if (path_or_err) { -sysroot_spec = FileSpec(*path_or_err); + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); Michael137 wrote: Can we put all of this into a static helper in this file? Maybe call it `ResolveSDKPathFromDebugInfo` too https://github.com/llvm/llvm-project/pull/146062 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
https://github.com/HemangGadhavi updated https://github.com/llvm/llvm-project/pull/145645 >From a85d648ce62b69b870dda306dbdc2d412ed89d33 Mon Sep 17 00:00:00 2001 From: HemangGadhavi Date: Wed, 25 Jun 2025 02:06:05 -0400 Subject: [PATCH 1/3] [lldb][DWARF64] Enable support for DWARF64 format handling --- .../SymbolFile/DWARF/DWARFFormValue.cpp | 47 --- .../Plugins/SymbolFile/DWARF/DWARFUnit.cpp| 15 +- .../Plugins/SymbolFile/DWARF/DWARFUnit.h | 1 + 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp index fd3d45cef4c5e..d0cc5edc6678a 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp @@ -77,7 +77,10 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data, case DW_FORM_strp: case DW_FORM_line_strp: case DW_FORM_sec_offset: - m_value.uval = data.GetMaxU64(offset_ptr, 4); + if (m_unit->GetFormat() == DwarfFormat::DWARF32) +m_value.uval = data.GetMaxU64(offset_ptr, 4); + else if (m_unit->GetFormat() == DwarfFormat::DWARF64) +m_value.uval = data.GetMaxU64(offset_ptr, 8); break; case DW_FORM_addrx1: case DW_FORM_strx1: @@ -121,8 +124,12 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data, assert(m_unit); if (m_unit->GetVersion() <= 2) ref_addr_size = m_unit->GetAddressByteSize(); - else -ref_addr_size = 4; + else { +if (m_unit->GetFormat() == DwarfFormat::DWARF32) + ref_addr_size = 4; +else if (m_unit->GetFormat() == DwarfFormat::DWARF64) + ref_addr_size = 8; + } m_value.uval = data.GetMaxU64(offset_ptr, ref_addr_size); break; case DW_FORM_indirect: @@ -165,17 +172,18 @@ static FormSize g_form_sizes[] = { {1, 1}, // 0x0b DW_FORM_data1 {1, 1}, // 0x0c DW_FORM_flag {0, 0}, // 0x0d DW_FORM_sdata -{1, 4}, // 0x0e DW_FORM_strp +{0, 0}, // 0x0e DW_FORM_strp (4 bytes for DWARF32, 8 bytes for DWARF64) {0, 0}, // 0x0f DW_FORM_udata {0, 0}, // 0x10 DW_FORM_ref_addr (addr size for DWARF2 and earlier, 4 bytes // for DWARF32, 8 bytes for DWARF32 in DWARF 3 and later -{1, 1}, // 0x11 DW_FORM_ref1 -{1, 2}, // 0x12 DW_FORM_ref2 -{1, 4}, // 0x13 DW_FORM_ref4 -{1, 8}, // 0x14 DW_FORM_ref8 -{0, 0}, // 0x15 DW_FORM_ref_udata -{0, 0}, // 0x16 DW_FORM_indirect -{1, 4}, // 0x17 DW_FORM_sec_offset +{1, 1}, // 0x11 DW_FORM_ref1 +{1, 2}, // 0x12 DW_FORM_ref2 +{1, 4}, // 0x13 DW_FORM_ref4 +{1, 8}, // 0x14 DW_FORM_ref8 +{0, 0}, // 0x15 DW_FORM_ref_udata +{0, 0}, // 0x16 DW_FORM_indirect +{0, + 0}, // 0x17 DW_FORM_sec_offset (4 bytes for DWARF32, 8 bytes for DWARF64) {0, 0}, // 0x18 DW_FORM_exprloc {1, 0}, // 0x19 DW_FORM_flag_present {0, 0}, // 0x1a DW_FORM_strx (ULEB128) @@ -183,8 +191,8 @@ static FormSize g_form_sizes[] = { {1, 4}, // 0x1c DW_FORM_ref_sup4 {0, 0}, // 0x1d DW_FORM_strp_sup (4 bytes for DWARF32, 8 bytes for DWARF64) {1, 16}, // 0x1e DW_FORM_data16 -{1, 4}, // 0x1f DW_FORM_line_strp -{1, 8}, // 0x20 DW_FORM_ref_sig8 +{0, 0}, // 0x1f DW_FORM_line_strp (4 bytes for DWARF32, 8 bytes for DWARF64) +{1, 8}, // 0x20 DW_FORM_ref_sig8 }; std::optional DWARFFormValue::GetFixedSize(dw_form_t form, @@ -251,8 +259,12 @@ bool DWARFFormValue::SkipValue(dw_form_t form, // get this wrong if (unit->GetVersion() <= 2) ref_addr_size = unit->GetAddressByteSize(); -else - ref_addr_size = 4; +else { + if (unit->GetFormat() == DwarfFormat::DWARF32) +ref_addr_size = 4; + else if (unit->GetFormat() == DwarfFormat::DWARF64) +ref_addr_size = 8; +} *offset_ptr += ref_addr_size; return true; @@ -288,7 +300,10 @@ bool DWARFFormValue::SkipValue(dw_form_t form, case DW_FORM_sec_offset: case DW_FORM_strp: case DW_FORM_line_strp: - *offset_ptr += 4; + if (unit->GetFormat() == DwarfFormat::DWARF32) +*offset_ptr += 4; + else if (unit->GetFormat() == DwarfFormat::DWARF64) +*offset_ptr += 8; return true; // 4 byte values diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp index ffd6f1dd52aff..f216ab13e8936 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -1073,20 +1073,7 @@ const lldb_private::DWARFDataExtractor &DWARFUnit::GetData() const { : m_dwarf.GetDWARFContext().getOrLoadDebugInfoData(); } -uint32_t DWARFUnit::GetHeaderByteSize() const { - switch (m_header.getUnitType()) { - case llvm::dwarf::DW_UT_compile: - case llvm::dwarf::DW_UT_partial: -ret
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/146062 >From 6ce75177264d47ffedbf0e6ee44831eac1d3ea55 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Fri, 27 Jun 2025 12:49:53 +0100 Subject: [PATCH 1/2] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site --- .../Platform/MacOSX/PlatformDarwin.cpp| 32 +++ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 262a7dc731713..ae46ac63e756a 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1130,13 +1130,33 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( if (target) { if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - auto path_or_err = ResolveSDKPathFromDebugInfo(*exe_module_sp); - if (path_or_err) { -sysroot_spec = FileSpec(*path_or_err); + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); + if (!sym_file) +return; + + XcodeSDK merged_sdk; + for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { +if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { + auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp); + merged_sdk.Merge(cu_sdk); +} + } + + // TODO: The result of this loop is almost equivalent to deriving the SDK + // from the target triple, which would be a lot cheaper. + + if (FileSystem::Instance().Exists(merged_sdk.GetSysroot())) { +sysroot_spec = merged_sdk.GetSysroot(); } else { -LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), - path_or_err.takeError(), - "Failed to resolve SDK path: {0}"); +auto path_or_err = +HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk}); +if (path_or_err) { + sysroot_spec = FileSpec(*path_or_err); +} else { + LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), + path_or_err.takeError(), + "Failed to resolve SDK path: {0}"); +} } } } >From aa2417acc66af5612abb33bf39edc9d2b41478a7 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Mon, 30 Jun 2025 12:22:21 +0100 Subject: [PATCH 2/2] extract to helper method --- .../Platform/MacOSX/PlatformDarwin.cpp| 70 +++ .../Plugins/Platform/MacOSX/PlatformDarwin.h | 3 + 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index ae46ac63e756a..4411c88c97ab2 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1128,37 +1128,8 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( FileSpec sysroot_spec; - if (target) { -if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); - if (!sym_file) -return; - - XcodeSDK merged_sdk; - for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { -if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { - auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp); - merged_sdk.Merge(cu_sdk); -} - } - - // TODO: The result of this loop is almost equivalent to deriving the SDK - // from the target triple, which would be a lot cheaper. - - if (FileSystem::Instance().Exists(merged_sdk.GetSysroot())) { -sysroot_spec = merged_sdk.GetSysroot(); - } else { -auto path_or_err = -HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk}); -if (path_or_err) { - sysroot_spec = FileSpec(*path_or_err); -} else { - LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), - path_or_err.takeError(), - "Failed to resolve SDK path: {0}"); -} - } -} + if (target && ResolveSDKPathFromDebugInfo(target, sysroot_spec)) { +return; } if (!FileSystem::Instance().IsDirectory(sysroot_spec.GetPath())) { @@ -1172,6 +1143,43 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( } } +bool lldb_private::PlatformDarwin::ResolveSDKPathFromDebugInfo( +lldb_private::Target *target, lldb_private::FileSpec &sysroot_spec) { + + ModuleSP exe_module_sp = target->GetExecutableModule(); + if (!exe_module_sp) +return false; + + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); + if (!sym_file) +return true; + + XcodeSDK merged_sdk; + for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { +if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { + auto cu_sdk = sym_file-
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
@@ -0,0 +1,96 @@ +//===-- DWARF64UnitTest.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 "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h" +#include "Plugins/SymbolFile/DWARF/DWARFUnit.h" +#include "TestingSupport/Symbol/YAMLModuleTester.h" + +using namespace lldb_private; +using namespace lldb_private::dwarf; +using namespace lldb_private::plugin::dwarf; + +TEST(DWARF64UnitTest, DWARF64DebugInfoAndCU) { + const char *yamldata = R"( +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data:ELFDATA2LSB + Type:ET_EXEC + Machine: EM_PPC64 +DWARF: + debug_str: +- 'clang version 18.1.8 (clang-18.1.8-1)' +- 'main' + debug_abbrev: +- Table: +- Code:0x1 + Tag: DW_TAG_compile_unit + Children:DW_CHILDREN_yes + Attributes: +- Attribute: DW_AT_producer + Form:DW_FORM_strp +- Attribute: DW_AT_language + Form:DW_FORM_data2 +- Attribute: DW_AT_stmt_list + Form:DW_FORM_sec_offset +- Attribute: DW_AT_low_pc + Form:DW_FORM_addr +- Attribute: DW_AT_high_pc + Form:DW_FORM_data4 +- Code:0x02 + Tag: DW_TAG_subprogram + Children:DW_CHILDREN_no + Attributes: +- Attribute: DW_AT_name + Form:DW_FORM_strp + debug_info: +- Format: DWARF64 + Version: 4 + AbbrOffset: 0x0 + AddrSize:8 + Entries: +- AbbrCode:0x1 + Values: +- Value: 0x0 +- Value: 0x04 +- Value: 0x0 +- Value: 0xdeadbeef +- Value: 0xdeadbeef +- AbbrCode:0x2 + Values: +- Value: 0x1 +- AbbrCode: 0x0 +)"; + + YAMLModuleTester t(yamldata); + auto *symbol_file = + llvm::cast(t.GetModule()->GetSymbolFile()); + DWARFUnit *unit = symbol_file->DebugInfo().GetUnitAtIndex(0); + ASSERT_TRUE(unit); + ASSERT_EQ(unit->GetFormParams().Format, DwarfFormat::DWARF64); + ASSERT_EQ(unit->GetVersion(), 4); + ASSERT_EQ(unit->GetAddressByteSize(), 8); + + DWARFFormValue form_value; + const DWARFDebugInfoEntry *cu_entry = unit->DIE().GetDIE(); + ASSERT_EQ(cu_entry->Tag(), DW_TAG_compile_unit); + ASSERT_EQ(unit->GetProducer(), eProducerClang); + ASSERT_EQ(unit->GetDWARFLanguageType(), DW_LANG_C_plus_plus); + auto attrs = cu_entry->GetAttributes(unit, DWARFDebugInfoEntry::Recurse::yes); + attrs.ExtractFormValueAtIndex(2, form_value); // Validate DW_AT_stmt_list + ASSERT_EQ(form_value.Unsigned(), 0UL); + attrs.ExtractFormValueAtIndex(3, form_value); // Validate DW_AT_low_pc + ASSERT_EQ(form_value.Unsigned(), 0xdeadbeef); + attrs.ExtractFormValueAtIndex(4, form_value); // Validate DW_AT_high_pc + ASSERT_EQ(form_value.Unsigned(), 0xdeadbeef); HemangGadhavi wrote: Thanks @labath I have removed it. If no more comments can you please merge it. I do not have access yet. https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add type summaries for MSVC STL strings (PR #143177)
https://github.com/labath edited https://github.com/llvm/llvm-project/pull/143177 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add type summaries for MSVC STL strings (PR #143177)
https://github.com/labath commented: I think the tests are fine. @Michael137, @jimingham, do you have anything to say about the implementation? https://github.com/llvm/llvm-project/pull/143177 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add type summaries for MSVC STL strings (PR #143177)
@@ -299,6 +299,8 @@ def parseOptionsAndInitTestdirs(): configuration.libcxx_library_dir = args.libcxx_library_dir configuration.cmake_build_type = args.cmake_build_type.lower() +configuration.target_triple = args.target_triple + labath wrote: Yeah, I think it's fine. FWIW, we also don't add any special flags when the compiler is gcc and we're running libstdc++ tests, only that fact is obscured by a lot of ifdefs. https://github.com/llvm/llvm-project/pull/143177 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Optimize identifier lookup in DIL (PR #146094)
labath wrote: > Well, my logic was that it's better to return something than nothing, For a simple variable query, it might be okay since you kind of see the full name in the command output. However, for expressions like `a+b`, it's kind of important to know which `a`s and `b`s are you adding together. I think we should change that... > similar to what current `frame var` does, it just outputs the first thing > that matches the base name, regardless of namespace. Should I make > `DILFindVariable` return a specific error message like "ambiguous name" or > something? ... but if the current implementation does the same thing, then I think it's good enough for now. > I tried doing symbol_context.module_sp->GetSymbolFile()->FindGlobalVariables, > which in turn calls SymbolFileDWARF::FindGlobalVariables, but it searches > through the entire module, not just current CU. CompileUnit class has only > GetVariableList, no search. It looks like getting variable list there does > something different, but I really can't tell if it's any faster. That might depend on the exact use case (number of CUs, number of variables per CU, how many times you're calling this, etc.). If you think it's necessary, we can talk about optimizing this, but I don't think we need to do that now. https://github.com/llvm/llvm-project/pull/146094 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
@@ -1130,13 +1130,33 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( if (target) { if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - auto path_or_err = ResolveSDKPathFromDebugInfo(*exe_module_sp); - if (path_or_err) { -sysroot_spec = FileSpec(*path_or_err); + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); charles-zablit wrote: Extracted and refactored the logic a bit to `ResolveSDKPathFromDebugInfo` 👍 https://github.com/llvm/llvm-project/pull/146062 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
@@ -119,10 +121,7 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data, break; case DW_FORM_ref_addr: assert(m_unit); - if (m_unit->GetVersion() <= 2) -ref_addr_size = m_unit->GetAddressByteSize(); - else -ref_addr_size = 4; + ref_addr_size = m_unit->GetFormParams().getRefAddrByteSize(); HemangGadhavi wrote: I think it used in multiple switch cases, Thats why they have made it common for all the case instead for each switch case. https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
https://github.com/HemangGadhavi edited https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
@@ -119,10 +121,7 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data, break; case DW_FORM_ref_addr: assert(m_unit); - if (m_unit->GetVersion() <= 2) -ref_addr_size = m_unit->GetAddressByteSize(); - else -ref_addr_size = 4; + ref_addr_size = m_unit->GetFormParams().getRefAddrByteSize(); Michael137 wrote: It's reset before it's used in each case though. https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
@@ -119,10 +121,7 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data, break; case DW_FORM_ref_addr: assert(m_unit); - if (m_unit->GetVersion() <= 2) -ref_addr_size = m_unit->GetAddressByteSize(); - else -ref_addr_size = 4; + ref_addr_size = m_unit->GetFormParams().getRefAddrByteSize(); Michael137 wrote: No need to address it in this PR anyway https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
@@ -119,10 +121,7 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data, break; case DW_FORM_ref_addr: assert(m_unit); - if (m_unit->GetVersion() <= 2) -ref_addr_size = m_unit->GetAddressByteSize(); - else -ref_addr_size = 4; + ref_addr_size = m_unit->GetFormParams().getRefAddrByteSize(); HemangGadhavi wrote: Okay Thanks https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Optimize identifier lookup in DIL (PR #146094)
@@ -129,28 +71,22 @@ lldb::ValueObjectSP LookupGlobalIdentifier( target_sp->GetImages().FindGlobalVariables( ConstString(name_ref), std::numeric_limits::max(), modules_var_list); - if (modules_var_list.Empty()) -return nullptr; - for (const lldb::VariableSP &var_sp : modules_var_list) { -std::string qualified_name = llvm::formatv("::{0}", name_ref).str(); -if (var_sp->NameMatches(ConstString(name_ref)) || -var_sp->NameMatches(ConstString(qualified_name))) { + if (!modules_var_list.Empty()) { labath wrote: I'd just delete this check. The function does the right thing when called with an empty list, and I doubt it's going to be faster. https://github.com/llvm/llvm-project/pull/146094 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
https://github.com/HemangGadhavi edited https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
https://github.com/HemangGadhavi updated https://github.com/llvm/llvm-project/pull/145645 >From a85d648ce62b69b870dda306dbdc2d412ed89d33 Mon Sep 17 00:00:00 2001 From: HemangGadhavi Date: Wed, 25 Jun 2025 02:06:05 -0400 Subject: [PATCH 1/3] [lldb][DWARF64] Enable support for DWARF64 format handling --- .../SymbolFile/DWARF/DWARFFormValue.cpp | 47 --- .../Plugins/SymbolFile/DWARF/DWARFUnit.cpp| 15 +- .../Plugins/SymbolFile/DWARF/DWARFUnit.h | 1 + 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp index fd3d45cef4c5e..d0cc5edc6678a 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp @@ -77,7 +77,10 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data, case DW_FORM_strp: case DW_FORM_line_strp: case DW_FORM_sec_offset: - m_value.uval = data.GetMaxU64(offset_ptr, 4); + if (m_unit->GetFormat() == DwarfFormat::DWARF32) +m_value.uval = data.GetMaxU64(offset_ptr, 4); + else if (m_unit->GetFormat() == DwarfFormat::DWARF64) +m_value.uval = data.GetMaxU64(offset_ptr, 8); break; case DW_FORM_addrx1: case DW_FORM_strx1: @@ -121,8 +124,12 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data, assert(m_unit); if (m_unit->GetVersion() <= 2) ref_addr_size = m_unit->GetAddressByteSize(); - else -ref_addr_size = 4; + else { +if (m_unit->GetFormat() == DwarfFormat::DWARF32) + ref_addr_size = 4; +else if (m_unit->GetFormat() == DwarfFormat::DWARF64) + ref_addr_size = 8; + } m_value.uval = data.GetMaxU64(offset_ptr, ref_addr_size); break; case DW_FORM_indirect: @@ -165,17 +172,18 @@ static FormSize g_form_sizes[] = { {1, 1}, // 0x0b DW_FORM_data1 {1, 1}, // 0x0c DW_FORM_flag {0, 0}, // 0x0d DW_FORM_sdata -{1, 4}, // 0x0e DW_FORM_strp +{0, 0}, // 0x0e DW_FORM_strp (4 bytes for DWARF32, 8 bytes for DWARF64) {0, 0}, // 0x0f DW_FORM_udata {0, 0}, // 0x10 DW_FORM_ref_addr (addr size for DWARF2 and earlier, 4 bytes // for DWARF32, 8 bytes for DWARF32 in DWARF 3 and later -{1, 1}, // 0x11 DW_FORM_ref1 -{1, 2}, // 0x12 DW_FORM_ref2 -{1, 4}, // 0x13 DW_FORM_ref4 -{1, 8}, // 0x14 DW_FORM_ref8 -{0, 0}, // 0x15 DW_FORM_ref_udata -{0, 0}, // 0x16 DW_FORM_indirect -{1, 4}, // 0x17 DW_FORM_sec_offset +{1, 1}, // 0x11 DW_FORM_ref1 +{1, 2}, // 0x12 DW_FORM_ref2 +{1, 4}, // 0x13 DW_FORM_ref4 +{1, 8}, // 0x14 DW_FORM_ref8 +{0, 0}, // 0x15 DW_FORM_ref_udata +{0, 0}, // 0x16 DW_FORM_indirect +{0, + 0}, // 0x17 DW_FORM_sec_offset (4 bytes for DWARF32, 8 bytes for DWARF64) {0, 0}, // 0x18 DW_FORM_exprloc {1, 0}, // 0x19 DW_FORM_flag_present {0, 0}, // 0x1a DW_FORM_strx (ULEB128) @@ -183,8 +191,8 @@ static FormSize g_form_sizes[] = { {1, 4}, // 0x1c DW_FORM_ref_sup4 {0, 0}, // 0x1d DW_FORM_strp_sup (4 bytes for DWARF32, 8 bytes for DWARF64) {1, 16}, // 0x1e DW_FORM_data16 -{1, 4}, // 0x1f DW_FORM_line_strp -{1, 8}, // 0x20 DW_FORM_ref_sig8 +{0, 0}, // 0x1f DW_FORM_line_strp (4 bytes for DWARF32, 8 bytes for DWARF64) +{1, 8}, // 0x20 DW_FORM_ref_sig8 }; std::optional DWARFFormValue::GetFixedSize(dw_form_t form, @@ -251,8 +259,12 @@ bool DWARFFormValue::SkipValue(dw_form_t form, // get this wrong if (unit->GetVersion() <= 2) ref_addr_size = unit->GetAddressByteSize(); -else - ref_addr_size = 4; +else { + if (unit->GetFormat() == DwarfFormat::DWARF32) +ref_addr_size = 4; + else if (unit->GetFormat() == DwarfFormat::DWARF64) +ref_addr_size = 8; +} *offset_ptr += ref_addr_size; return true; @@ -288,7 +300,10 @@ bool DWARFFormValue::SkipValue(dw_form_t form, case DW_FORM_sec_offset: case DW_FORM_strp: case DW_FORM_line_strp: - *offset_ptr += 4; + if (unit->GetFormat() == DwarfFormat::DWARF32) +*offset_ptr += 4; + else if (unit->GetFormat() == DwarfFormat::DWARF64) +*offset_ptr += 8; return true; // 4 byte values diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp index ffd6f1dd52aff..f216ab13e8936 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -1073,20 +1073,7 @@ const lldb_private::DWARFDataExtractor &DWARFUnit::GetData() const { : m_dwarf.GetDWARFContext().getOrLoadDebugInfoData(); } -uint32_t DWARFUnit::GetHeaderByteSize() const { - switch (m_header.getUnitType()) { - case llvm::dwarf::DW_UT_compile: - case llvm::dwarf::DW_UT_partial: -ret
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
@@ -288,7 +284,9 @@ bool DWARFFormValue::SkipValue(dw_form_t form, case DW_FORM_sec_offset: case DW_FORM_strp: case DW_FORM_line_strp: - *offset_ptr += 4; + assert(unit); // Unit must be valid HemangGadhavi wrote: Thanks @Michael137 Done https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
@@ -77,7 +77,9 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data, case DW_FORM_strp: case DW_FORM_line_strp: case DW_FORM_sec_offset: - m_value.uval = data.GetMaxU64(offset_ptr, 4); + assert(m_unit); // Unit must be valid HemangGadhavi wrote: Thanks @Michael137 Done https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Optimize identifier lookup in DIL (PR #146094)
https://github.com/labath approved this pull request. https://github.com/llvm/llvm-project/pull/146094 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
@@ -0,0 +1,96 @@ +//===-- DWARF64UnitTest.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 "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h" +#include "Plugins/SymbolFile/DWARF/DWARFUnit.h" +#include "TestingSupport/Symbol/YAMLModuleTester.h" + +using namespace lldb_private; +using namespace lldb_private::dwarf; +using namespace lldb_private::plugin::dwarf; + +TEST(DWARF64UnitTest, DWARF64DebugInfoAndCU) { + const char *yamldata = R"( +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data:ELFDATA2LSB + Type:ET_EXEC + Machine: EM_PPC64 +DWARF: + debug_str: +- 'clang version 18.1.8 (clang-18.1.8-1)' +- 'main' + debug_abbrev: +- Table: +- Code:0x1 + Tag: DW_TAG_compile_unit + Children:DW_CHILDREN_yes + Attributes: +- Attribute: DW_AT_producer + Form:DW_FORM_strp +- Attribute: DW_AT_language + Form:DW_FORM_data2 +- Attribute: DW_AT_stmt_list + Form:DW_FORM_sec_offset +- Attribute: DW_AT_low_pc + Form:DW_FORM_addr +- Attribute: DW_AT_high_pc + Form:DW_FORM_data4 +- Code:0x02 + Tag: DW_TAG_subprogram + Children:DW_CHILDREN_no + Attributes: +- Attribute: DW_AT_name + Form:DW_FORM_strp + debug_info: +- Format: DWARF64 + Version: 4 + AbbrOffset: 0x0 + AddrSize:8 + Entries: +- AbbrCode:0x1 + Values: +- Value: 0x0 +- Value: 0x04 +- Value: 0x0 +- Value: 0xdeadbeef +- Value: 0xdeadbeef +- AbbrCode:0x2 + Values: +- Value: 0x1 +- AbbrCode: 0x0 +)"; + + YAMLModuleTester t(yamldata); + auto *symbol_file = + llvm::cast(t.GetModule()->GetSymbolFile()); + DWARFUnit *unit = symbol_file->DebugInfo().GetUnitAtIndex(0); + ASSERT_TRUE(unit); + ASSERT_EQ(unit->GetFormParams().Format, DwarfFormat::DWARF64); + ASSERT_EQ(unit->GetVersion(), 4); + ASSERT_EQ(unit->GetAddressByteSize(), 8); + + DWARFFormValue form_value; + const DWARFDebugInfoEntry *cu_entry = unit->DIE().GetDIE(); + ASSERT_EQ(cu_entry->Tag(), DW_TAG_compile_unit); + ASSERT_EQ(unit->GetProducer(), eProducerClang); + ASSERT_EQ(unit->GetDWARFLanguageType(), DW_LANG_C_plus_plus); + auto attrs = cu_entry->GetAttributes(unit, DWARFDebugInfoEntry::Recurse::yes); + attrs.ExtractFormValueAtIndex(2, form_value); // Validate DW_AT_stmt_list + ASSERT_EQ(form_value.Unsigned(), 0UL); + attrs.ExtractFormValueAtIndex(3, form_value); // Validate DW_AT_low_pc + ASSERT_EQ(form_value.Unsigned(), 0xdeadbeef); + attrs.ExtractFormValueAtIndex(4, form_value); // Validate DW_AT_high_pc + ASSERT_EQ(form_value.Unsigned(), 0xdeadbeef); labath wrote: It'd be better to choose distinct values for these. .. but maybe you can also delete these as DW_AT_low/high_pc does not depend on dwarf size. https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
https://github.com/labath approved this pull request. https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add type summaries for MSVC STL strings (PR #143177)
@@ -239,122 +240,24 @@ VectorIteratorSyntheticFrontEnd::GetIndexOfChildWithName(ConstString name) { bool lldb_private::formatters::LibStdcppStringSummaryProvider( ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) { - const bool scalar_is_load_addr = true; - auto [addr_of_string, addr_type] = - valobj.IsPointerOrReferenceType() - ? valobj.GetPointerValue() - : valobj.GetAddressOf(scalar_is_load_addr); - if (addr_of_string != LLDB_INVALID_ADDRESS) { -switch (addr_type) { -case eAddressTypeLoad: { - ProcessSP process_sp(valobj.GetProcessSP()); - if (!process_sp) -return false; - - StringPrinter::ReadStringAndDumpToStreamOptions options(valobj); - Status error; - lldb::addr_t addr_of_data = - process_sp->ReadPointerFromMemory(addr_of_string, error); - if (error.Fail() || addr_of_data == 0 || - addr_of_data == LLDB_INVALID_ADDRESS) -return false; - options.SetLocation(addr_of_data); - options.SetTargetSP(valobj.GetTargetSP()); - options.SetStream(&stream); - options.SetNeedsZeroTermination(false); - options.SetBinaryZeroIsTerminator(true); - lldb::addr_t size_of_data = process_sp->ReadPointerFromMemory( - addr_of_string + process_sp->GetAddressByteSize(), error); - if (error.Fail()) -return false; - options.SetSourceSize(size_of_data); - options.SetHasSourceSize(true); - - if (!StringPrinter::ReadStringAndDumpToStream< - StringPrinter::StringElementType::UTF8>(options)) { -stream.Printf("Summary Unavailable"); -return true; - } else -return true; -} break; -case eAddressTypeHost: - break; -case eAddressTypeInvalid: -case eAddressTypeFile: - break; -} - } - return false; + ValueObjectSP ptr = valobj.GetChildAtNamePath({"_M_dataplus", "_M_p"}); + if (!ptr) +return false; + + stream << ptr->GetSummaryAsCString(); + return true; } bool lldb_private::formatters::LibStdcppWStringSummaryProvider( ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) { - const bool scalar_is_load_addr = true; - auto [addr_of_string, addr_type] = valobj.GetAddressOf(scalar_is_load_addr); - if (addr_of_string != LLDB_INVALID_ADDRESS) { -switch (addr_type) { -case eAddressTypeLoad: { - ProcessSP process_sp(valobj.GetProcessSP()); - if (!process_sp) -return false; - - CompilerType wchar_compiler_type = - valobj.GetCompilerType().GetBasicTypeFromAST(lldb::eBasicTypeWChar); - - if (!wchar_compiler_type) -return false; - - // Safe to pass nullptr for exe_scope here. - std::optional size = - llvm::expectedToOptional(wchar_compiler_type.GetBitSize(nullptr)); - if (!size) -return false; - const uint32_t wchar_size = *size; - - StringPrinter::ReadStringAndDumpToStreamOptions options(valobj); - Status error; - lldb::addr_t addr_of_data = - process_sp->ReadPointerFromMemory(addr_of_string, error); - if (error.Fail() || addr_of_data == 0 || - addr_of_data == LLDB_INVALID_ADDRESS) -return false; - options.SetLocation(addr_of_data); - options.SetTargetSP(valobj.GetTargetSP()); - options.SetStream(&stream); - options.SetNeedsZeroTermination(false); - options.SetBinaryZeroIsTerminator(false); - lldb::addr_t size_of_data = process_sp->ReadPointerFromMemory( - addr_of_string + process_sp->GetAddressByteSize(), error); - if (error.Fail()) -return false; - options.SetSourceSize(size_of_data); - options.SetHasSourceSize(true); - options.SetPrefixToken("L"); - - switch (wchar_size) { - case 8: -return StringPrinter::ReadStringAndDumpToStream< -StringPrinter::StringElementType::UTF8>(options); - case 16: -return StringPrinter::ReadStringAndDumpToStream< -StringPrinter::StringElementType::UTF16>(options); - case 32: -return StringPrinter::ReadStringAndDumpToStream< -StringPrinter::StringElementType::UTF32>(options); - default: -stream.Printf("size for wchar_t is not valid"); -return true; - } - return true; -} break; -case eAddressTypeHost: - break; -case eAddressTypeInvalid: -case eAddressTypeFile: - break; -} - } - return false; + ValueObjectSP dataplus = valobj.GetChildMemberWithName("_M_dataplus"); labath wrote: Could this be implemented the same way as `LibStdcppStringSummaryProvider` (maybe even by the same function)? https://github.com/llvm/llvm-project/pull/143177 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
@@ -1128,17 +1128,8 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( FileSpec sysroot_spec; - if (target) { -if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - auto path_or_err = ResolveSDKPathFromDebugInfo(*exe_module_sp); - if (path_or_err) { -sysroot_spec = FileSpec(*path_or_err); - } else { -LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), - path_or_err.takeError(), - "Failed to resolve SDK path: {0}"); - } -} + if (target && ResolveSDKPathFromDebugInfo(target, sysroot_spec)) { +return; Michael137 wrote: Don't think we want to return here? We used to just to log the error. How about we return `llvm::Expected` from `ResolveSDKPathFromDebugInfo` and don't pass the sysroot_spec as an output parameter? https://github.com/llvm/llvm-project/pull/146062 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
HemangGadhavi wrote: @DhruvSrivastavaX can you please merge it https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
@@ -77,7 +77,9 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data, case DW_FORM_strp: case DW_FORM_line_strp: case DW_FORM_sec_offset: - m_value.uval = data.GetMaxU64(offset_ptr, 4); + assert(m_unit); // Unit must be valid Michael137 wrote: ```suggestion assert(m_unit); ``` https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
@@ -288,7 +284,9 @@ bool DWARFFormValue::SkipValue(dw_form_t form, case DW_FORM_sec_offset: case DW_FORM_strp: case DW_FORM_line_strp: - *offset_ptr += 4; + assert(unit); // Unit must be valid Michael137 wrote: ```suggestion assert(unit); ``` https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
DhruvSrivastavaX wrote: @HemangGadhavi , Please check the code format failure and lets me have a check before merging. https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
@@ -119,10 +121,7 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data, break; case DW_FORM_ref_addr: assert(m_unit); - if (m_unit->GetVersion() <= 2) -ref_addr_size = m_unit->GetAddressByteSize(); - else -ref_addr_size = 4; + ref_addr_size = m_unit->GetFormParams().getRefAddrByteSize(); Michael137 wrote: Outside the scope of this PR but seems like we can just make `ref_addr_size` local to the cases that need it. Don't see the point of having it outside the switch https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
@@ -288,7 +284,9 @@ bool DWARFFormValue::SkipValue(dw_form_t form, case DW_FORM_sec_offset: case DW_FORM_strp: case DW_FORM_line_strp: - *offset_ptr += 4; + assert(unit); // Unit must be valid + ref_addr_size = unit->GetFormParams().getDwarfOffsetByteSize(); Michael137 wrote: Same comment re. `ref_addr_size` https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)
https://github.com/labath edited https://github.com/llvm/llvm-project/pull/145621 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)
https://github.com/labath approved this pull request. > I made a sample binary > (https://gist.github.com/ashgti/1649fde8ef28783ace1e414f87a6b680) and it > seems stdin is opened as an anonymous pipe. Got it. Thanks for checking it out. I guess we have no choice, but to create the extra thread. It's unfortunate that windows doesn't allow you to do async I/O if the file handle wasn't created as such. The "just create it the right way from the start" argument makes sense when everything happens within a single process, but this use case (passing a pipe handle from one process to another) is kind of a counterexample to that. I also wouldn't be surprised if we needed to add threads to wait for other kinds of events in the future. One thing that would be occasionally useful to do is to wait for some data to arrive (e.g. a process writes something to a pipe) *OR* for a process to die (e.g. the writing process crashes). Linux can pull that off without threads using a pidfd, but I'm not sure all systems can. It's also reassuring to know that we can avoid the extra thread if we need to for pipes we have create ourselves, but I think we don't need to do that now. I think most of the internal uses of pipes would be better off by switching to `AddPendingCallback` (which internally uses a pipe on posix, but directly signals an event on windows). https://github.com/llvm/llvm-project/pull/145621 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)
@@ -31,6 +34,122 @@ static DWORD ToTimeout(std::optional point) { return ceil(dur).count(); } +namespace { + +class PipeEvent : public MainLoopWindows::IOEvent { +public: + explicit PipeEvent(HANDLE handle) + : IOEvent((IOObject::WaitableHandle)CreateEventW( +NULL, /*bManualReset=*/FALSE, +/*bInitialState=*/FALSE, NULL)), +m_handle(handle), m_ready(CreateEventW(NULL, /*bManualReset=*/FALSE, + /*bInitialState=*/FALSE, NULL)) { +assert(event && ready); + } + + ~PipeEvent() override { +if (m_monitor_thread.joinable()) { + m_stopped = true; + SetEvent(m_ready); + // Keep trying to cancel ReadFile() until the thread exits. + do { +CancelIoEx((HANDLE)m_handle, /*lpOverlapped=*/NULL); + } while (WaitForSingleObject(m_monitor_thread.native_handle(), 1) == + WAIT_TIMEOUT); + m_monitor_thread.join(); +} +CloseHandle((HANDLE)m_event); +CloseHandle(m_ready); + } + + void WillPoll() override { +if (!m_monitor_thread.joinable()) labath wrote: What would you say to creating the thread in the constructor? It would remove the `joinable()` calls, and thing that adding a pipe to the loop is quickly followed by a poll operation anyway. https://github.com/llvm/llvm-project/pull/145621 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)
@@ -79,7 +79,68 @@ TEST_F(MainLoopTest, ReadObject) { ASSERT_EQ(1u, callback_count); } -TEST_F(MainLoopTest, NoSpuriousReads) { +TEST_F(MainLoopTest, ReadPipeObject) { + Pipe pipe; + + ASSERT_TRUE(pipe.CreateNew().Success()); + + MainLoop loop; + + char X = 'X'; + size_t len = sizeof(X); + ASSERT_THAT_EXPECTED(pipe.Write(&X, len), llvm::Succeeded()); labath wrote: ```suggestion ASSERT_THAT_EXPECTED(pipe.Write(&X, len), llvm::HasValue(1)); ``` https://github.com/llvm/llvm-project/pull/145621 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)
@@ -31,6 +34,122 @@ static DWORD ToTimeout(std::optional point) { return ceil(dur).count(); } +namespace { + +class PipeEvent : public MainLoopWindows::IOEvent { +public: + explicit PipeEvent(HANDLE handle) + : IOEvent((IOObject::WaitableHandle)CreateEventW( +NULL, /*bManualReset=*/FALSE, +/*bInitialState=*/FALSE, NULL)), +m_handle(handle), m_ready(CreateEventW(NULL, /*bManualReset=*/FALSE, + /*bInitialState=*/FALSE, NULL)) { +assert(event && ready); labath wrote: ```suggestion assert(m_event && m_ready); ``` https://github.com/llvm/llvm-project/pull/145621 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 24fd343 - [lldb][test] TestMetadataRegisters.py: add missing include
Author: Michael Buch Date: 2025-06-30T10:46:17+01:00 New Revision: 24fd3437c311e42891d117a9c4cf993032561bab URL: https://github.com/llvm/llvm-project/commit/24fd3437c311e42891d117a9c4cf993032561bab DIFF: https://github.com/llvm/llvm-project/commit/24fd3437c311e42891d117a9c4cf993032561bab.diff LOG: [lldb][test] TestMetadataRegisters.py: add missing include The macOS Clang-17 matrix bot was failing with: ``` 07:33:28 /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/test/API/macosx/lc-note/additional-registers/add-lcnote.cpp:79:12: error: implicit instantiation of undefined template 'std::vector' 07:33:28 79 | payload.resize(payload_str->size(), 0); 07:33:28|^ 07:33:28 /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/clang_1706_build/include/c++/v1/iosfwd:133:28: note: template is declared here 07:33:28133 | class _LIBCPP_TEMPLATE_VIS vector; 07:33:28|^ 07:33:28 /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/test/API/macosx/lc-note/additional-registers/add-lcnote.cpp:80:19: error: implicit instantiation of undefined template 'std::vector' 07:33:28 80 | memcpy(payload.data(), payload_str->c_str(), payload_str->size()); 07:33:28| ^ 07:33:28 /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/clang_1706_build/include/c++/v1/iosfwd:133:28: note: template is declared here 07:33:28133 | class _LIBCPP_TEMPLATE_VIS vector; 07:33:28|^ 07:33:28 /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/test/API/macosx/lc-note/additional-registers/add-lcnote.cpp:87:12: error: implicit instantiation of undefined template 'std::vector' 07:33:28 87 | payload.resize(sb.st_size, 0); 07:33:28|^ 07:33:28 /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/clang_1706_build/include/c++/v1/iosfwd:133:28: note: template is declared here 07:33:28133 | class _LIBCPP_TEMPLATE_VIS vector; ``` Added: Modified: lldb/test/API/macosx/lc-note/additional-registers/add-lcnote.cpp Removed: diff --git a/lldb/test/API/macosx/lc-note/additional-registers/add-lcnote.cpp b/lldb/test/API/macosx/lc-note/additional-registers/add-lcnote.cpp index 8d9d550a9ad72..c5ab732c0c7cc 100644 --- a/lldb/test/API/macosx/lc-note/additional-registers/add-lcnote.cpp +++ b/lldb/test/API/macosx/lc-note/additional-registers/add-lcnote.cpp @@ -8,6 +8,7 @@ #include #include #include +#include using namespace std; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)
@@ -44,25 +163,20 @@ MainLoopWindows::~MainLoopWindows() { } llvm::Expected MainLoopWindows::Poll() { - std::vector events; + std::vector events; events.reserve(m_read_fds.size() + 1); - for (auto &[fd, info] : m_read_fds) { -int result = WSAEventSelect(fd, info.event, FD_READ | FD_ACCEPT | FD_CLOSE); -assert(result == 0); -UNUSED_IF_ASSERT_DISABLED(result); - -events.push_back(info.event); + for (auto &[_, fd_info] : m_read_fds) { +fd_info.event->WillPoll(); +events.push_back((HANDLE)fd_info.event->GetHandle()); } events.push_back(m_interrupt_event); DWORD result = WSAWaitForMultipleEvents(events.size(), events.data(), FALSE, ToTimeout(GetNextWakeupTime()), FALSE); - for (auto &fd : m_read_fds) { -int result = WSAEventSelect(fd.first, WSA_INVALID_EVENT, 0); -assert(result == 0); -UNUSED_IF_ASSERT_DISABLED(result); + for (auto &[_, fd_info] : m_read_fds) { +fd_info.event->DidPoll(); } labath wrote: ```suggestion for (auto &[_, fd_info] : m_read_fds) fd_info.event->DidPoll(); ``` https://github.com/llvm/llvm-project/pull/145621 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)
@@ -79,7 +79,68 @@ TEST_F(MainLoopTest, ReadObject) { ASSERT_EQ(1u, callback_count); } -TEST_F(MainLoopTest, NoSpuriousReads) { +TEST_F(MainLoopTest, ReadPipeObject) { + Pipe pipe; + + ASSERT_TRUE(pipe.CreateNew().Success()); + + MainLoop loop; + + char X = 'X'; + size_t len = sizeof(X); + ASSERT_THAT_EXPECTED(pipe.Write(&X, len), llvm::Succeeded()); + + Status error; + auto handle = loop.RegisterReadObject( + std::make_shared(pipe.GetReadFileDescriptor(), + File::eOpenOptionReadOnly, false), + make_callback(), error); + ASSERT_TRUE(error.Success()); + ASSERT_TRUE(handle); + ASSERT_TRUE(loop.Run().Success()); + ASSERT_EQ(1u, callback_count); +} + +TEST_F(MainLoopTest, NoSpuriousPipeReads) { + Pipe pipe; + + ASSERT_TRUE(pipe.CreateNew().Success()); + + char X = 'X'; + size_t len = sizeof(X); + ASSERT_THAT_EXPECTED(pipe.Write(&X, len), llvm::Succeeded()); + + lldb::IOObjectSP r = std::make_shared( + pipe.GetReadFileDescriptor(), File::eOpenOptionReadOnly, false); + + MainLoop loop; + + Status error; + auto handle = loop.RegisterReadObject( + r, + [&](MainLoopBase &) { +if (callback_count == 0) { + // Read the byte back the first time we're called. After that, the + // pipe is empty, and we should not be called anymore. + char X; + size_t len = sizeof(X); + EXPECT_THAT_ERROR(r->Read(&X, len).ToError(), llvm::Succeeded()); + EXPECT_EQ(len, sizeof(X)); labath wrote: ```suggestion EXPECT_THAT_EXPECTED(r->Read(&X, len).ToError(), llvm::HasValue(1)); ``` https://github.com/llvm/llvm-project/pull/145621 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add type summaries for MSVC STL strings (PR #143177)
@@ -299,6 +299,8 @@ def parseOptionsAndInitTestdirs(): configuration.libcxx_library_dir = args.libcxx_library_dir configuration.cmake_build_type = args.cmake_build_type.lower() +configuration.target_triple = args.target_triple + DavidSpickett wrote: > This is why I'm not totally convinced that this is a good idea, though I also > believe that it's important that these tests do get run -- somewhere. If you > can confirm that the tests would run on the existing windows bots (we can > check with bot owners if needed), then maybe this wouldn't be necessary. @labath are you ok with the test predicate as is, knowing that the tests will run on Linaro's buildbot? https://github.com/llvm/llvm-project/pull/143177 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Document MCP support in LLDB (PR #145935)
@@ -0,0 +1,68 @@ +# Model Context Protocol (MCP) + +LLDB supports for the [Model Context Protocol][1] (MCP). This structured, +machine-friendly protocol allows AI models to access and interact with external +tools, such as the debugger. Using MCP, an AI agent can execute LLDB commands +to control the debugger: set breakpoints, inspect memory, step through code. +This can range from helping you run a specific command you can't immediately +remember to a fully agent-driven debugging experiences + +## MCP Server + +To start the MCP server in LLDB, use the `protocol-server start` command. +Specify `MCP` as the protocol and provide a URI to listen on. For example, to +start listening for local TCP connections on port `5`, use the following +command: + +``` +(lldb) protocol-server start MCP listen://localhost:5 +MCP server started with connection listeners: connection://[::1]:5, connection://[127.0.0.1]:5 +``` + +The server will automatically stop when exiting LLDB, or it can be stopped +explicitly with the `protocol-server stop` command. DavidSpickett wrote: And I think the workaround would be to say "run command X and tell me what you think the output means". https://github.com/llvm/llvm-project/pull/145935 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Prevent using an implicit `step-in`. (PR #143644)
labath wrote: Cool. The test case looks good. Someone might want to look at the DAP part. https://github.com/llvm/llvm-project/pull/143644 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Optimize identifier lookup in DIL (PR #146094)
kuilpd wrote: > I'm not sure that's the right thing to do -- if there are multiple matches, > how can we know we picked the one that the user wanted to see? > What might matter for performance is, if returning false/nullptr here causes > the implementation to perform the lookup at a larger (more expensive scope). > If that's the case, then I'd say that the right thing is to _not_ do the > second lookup in case the first one is ambiguous (as that doesn't help in > resolving the ambiguity). So, the function could return one of three results: > found zero, found one, found more than one; and in the last case we would > immediately bail out. Well, my logic was that it's better to return something than nothing, similar to what current `frame var` does, it just outputs the first thing that matches the base name, regardless of namespace. Should I make `DILFindVariable` return a specific error message like "ambiguous name" or something? > That said, I think the search for the current CU has different performance > characteristics (I believe it materializes all globals, and then searches for > the right name), so while I'm not sure if it's necessary (this should be a > one-shot thing), I can imagine implementing the search differently somehow, > so that we can only return the "local globals" with the right name. I tried doing `symbol_context.module_sp->GetSymbolFile()->FindGlobalVariables`, which in turn calls `SymbolFileDWARF::FindGlobalVariables`, but it searches through the entire module, not just current CU. `CompileUnit` class has only `GetVariableList`, no search. It looks like getting variable list there does something different, but I really can't tell if it's any faster. https://github.com/llvm/llvm-project/pull/146094 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][RPC] Upstream lldb-rpc-gen tool (PR #138031)
DavidSpickett wrote: On the same page you view the job results, there is a button top right that says "Re-run Jobs". I just used that here and it is re-running the job, I don't have special permissions that I know of, so it should work for you. https://github.com/llvm/llvm-project/pull/138031 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix a bug in the breakpoint ID verifier in CommandObjectBreakpoint. (PR #145994)
DavidSpickett wrote: > We can't remove the program file while lldb has it open. ``` path_to_exe = self.getBuildArtifact() (target, process, thread, bkpt) = lldbutil.run_to_name_breakpoint(self, "main") # Let the process continue to exit: process.Continue() self.assertEqual(process.GetState(), lldb.eStateExited, "Ran to completion") os.remove(path_to_exe) ``` The interactive equivalent is: ``` target file b main run continue (program exits) ``` You cannot delete the file here because something is still holding onto it. If you exit LLDB completely, then you can delete the file. Over zealous code in the Windows process plugin? Probably, but I wasn't about to go digging for it. https://github.com/llvm/llvm-project/pull/145994 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Document MCP support in LLDB (PR #145935)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/145935 >From 2b6a7e22481761b244e98dff00f905cf32a7d696 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 26 Jun 2025 10:31:09 -0700 Subject: [PATCH 1/3] [lldb] Document MCP support in LLDB --- lldb/docs/index.rst | 1 + lldb/docs/use/mcp.md | 68 2 files changed, 69 insertions(+) create mode 100644 lldb/docs/use/mcp.md diff --git a/lldb/docs/index.rst b/lldb/docs/index.rst index 1ffdb08a1ca2c..d49d0d8d5a733 100644 --- a/lldb/docs/index.rst +++ b/lldb/docs/index.rst @@ -135,6 +135,7 @@ interesting areas to contribute to lldb. use/ondemand use/aarch64-linux use/symbolfilejson + use/mcp use/troubleshooting use/links Man Page diff --git a/lldb/docs/use/mcp.md b/lldb/docs/use/mcp.md new file mode 100644 index 0..a89740545e5f4 --- /dev/null +++ b/lldb/docs/use/mcp.md @@ -0,0 +1,68 @@ +# Model Context Protocol (MCP) + +LLDB supports for the [Model Context Protocol][1] (MCP). This structured, +machine-friendly protocol allows AI models to access and interact with external +tools, such as the debugger. Using MCP, an AI agent can execute LLDB commands +to control the debugger: set breakpoints, inspect memory, step through code. +This can range from helping you run a specific command you can't immediately +remember to a fully agent-driven debugging experiences + +## MCP Server + +To start the MCP server in LLDB, use the `protocol-server start` command. +Specify `MCP` as the protocol and provide a URI to listen on. For example, to +start listening for local TCP connections on port `5`, use the following +command: + +``` +(lldb) protocol-server start MCP listen://localhost:5 +MCP server started with connection listeners: connection://[::1]:5, connection://[127.0.0.1]:5 +``` + +The server will automatically stop when exiting LLDB, or it can be stopped +explicitly with the `protocol-server stop` command. + +``` +(lldb) protocol-server stop MCP +``` + +## MCP Client + +MCP uses standard input/output (stdio) for communication between client and +server. The exact configuration depends on the client, but most applications +allow you to specify an MCP server as a binary and arguments. This means that +you need to use something like `netcat` to connect to LLDB's MCP server and +forward communication over stdio over the network connection. + +Configuration example for [Claude Code][2]: + +``` +{ + "mcpServers": { +"tool": { + "command": "/usr/bin/nc", + "args": ["localhost", "5"] +} + } +} +``` + +Configuration example for [Visual Studio Code][3]: + +``` +{ + "mcp": { +"servers": { + "lldb": { +"type": "stdio", +"command": "/usr/bin/nc", +"args": ["localhost", "5"] + } +} + } +} +``` + +[1]: https://modelcontextprotocol.io +[2]: https://modelcontextprotocol.io/quickstart/user +[3]: https://code.visualstudio.com/docs/copilot/chat/mcp-servers >From 09a1ce5fdf1c96f89a8d41e11d35b37c9da0 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 27 Jun 2025 09:49:15 -0700 Subject: [PATCH 2/3] Address David's feedback --- lldb/docs/use/mcp.md | 39 --- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/lldb/docs/use/mcp.md b/lldb/docs/use/mcp.md index a89740545e5f4..0a85f8ee9203e 100644 --- a/lldb/docs/use/mcp.md +++ b/lldb/docs/use/mcp.md @@ -1,11 +1,12 @@ # Model Context Protocol (MCP) -LLDB supports for the [Model Context Protocol][1] (MCP). This structured, -machine-friendly protocol allows AI models to access and interact with external -tools, such as the debugger. Using MCP, an AI agent can execute LLDB commands -to control the debugger: set breakpoints, inspect memory, step through code. -This can range from helping you run a specific command you can't immediately -remember to a fully agent-driven debugging experiences +LLDB supports the [Model Context Protocol][https://modelcontextprotocol.io] +(MCP). This structured, machine-friendly protocol allows AI models to access +and interact with external tools, for example debuggers. Using MCP, an AI agent +can execute LLDB commands to control the debugger: set breakpoints, inspect +memory, step through code. This can range from helping you run a specific +command you cannot immediately remember, to a fully agent-driven debugging +experience. ## MCP Server @@ -26,6 +27,9 @@ explicitly with the `protocol-server stop` command. (lldb) protocol-server stop MCP ``` +The commands will fail if a server is already running or not running +respectively. + ## MCP Client MCP uses standard input/output (stdio) for communication between client and @@ -34,7 +38,15 @@ allow you to specify an MCP server as a binary and arguments. This means that you need to use something like `netcat` to connect to LLDB's MCP server and forward communication over stdio o
[Lldb-commits] [lldb] [lldb] Document MCP support in LLDB (PR #145935)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/145935 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][RISCV] fix LR/SC atomic sequence handling in lldb-server (PR #146072)
https://github.com/dlav-sc closed https://github.com/llvm/llvm-project/pull/146072 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
https://github.com/JDevlieghere approved this pull request. https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARF64] Enable support for DWARF64 format handling (PR #145645)
@@ -0,0 +1,86 @@ +//===-- DWARF64UnitTest.cpp=---===// JDevlieghere wrote: ```suggestion //===-- DWARF64UnitTest.cpp===// ``` https://github.com/llvm/llvm-project/pull/145645 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][RISCV] fix LR/SC atomic sequence handling in lldb-server (PR #146072)
https://github.com/dlav-sc edited https://github.com/llvm/llvm-project/pull/146072 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Delete unused DWARFDataExtractor methods (PR #146356)
@@ -7,20 +7,10 @@ //===--===// #include "DWARFDataExtractor.h" -#include "llvm/ADT/StringRef.h" labath wrote: yeah, a bit of drive-by header gardening :P https://github.com/llvm/llvm-project/pull/146356 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
@@ -1128,17 +1128,8 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( FileSpec sysroot_spec; - if (target) { -if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - auto path_or_err = ResolveSDKPathFromDebugInfo(*exe_module_sp); - if (path_or_err) { -sysroot_spec = FileSpec(*path_or_err); - } else { -LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), - path_or_err.takeError(), - "Failed to resolve SDK path: {0}"); - } -} + if (target && ResolveSDKPathFromDebugInfo(target, sysroot_spec)) { +return; charles-zablit wrote: I fixed the logic and switched to an `llvm::Expected` return type. The underlying error are logged after the function is called. https://github.com/llvm/llvm-project/pull/146062 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Refactor code extracting timestamp from StructuredData (PR #145954)
https://github.com/oontvoo updated https://github.com/llvm/llvm-project/pull/145954 >From f4092ed5fda4214bfd2c72f288a6c686315bdc3b Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Thu, 26 Jun 2025 15:18:44 -0400 Subject: [PATCH 1/3] [LLDB][NFC] Refactor code extracting timestamp from StructuredData --- lldb/source/Core/Telemetry.cpp | 34 +++--- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp index 6434b11a63ad4..464c1d4071a73 100644 --- a/lldb/source/Core/Telemetry.cpp +++ b/lldb/source/Core/Telemetry.cpp @@ -119,6 +119,19 @@ llvm::Error TelemetryManager::preDispatch(TelemetryInfo *entry) { return llvm::Error::success(); } +// Helper for extracting time field from a Dictionary. +static std::optional +GetAsNanosec(StructuredData::Dictionary *dict, llvm::StringRef key) { + auto value = dict->GetValueForKey(key); + if (!value->IsValid()) { +LLDB_LOG(GetLog(LLDBLog::Object), + "Cannot determine {0} from client-telemetry entry", key); +return std::nullopt; + } + + return std::chrono::nanoseconds(value->GetUnsignedIntegerValue(0)); +} + void TelemetryManager::DispatchClientTelemetry( const lldb_private::StructuredDataImpl &entry, Debugger *debugger) { if (!m_config->enable_client_telemetry) @@ -148,23 +161,14 @@ void TelemetryManager::DispatchClientTelemetry( LLDB_LOG(GetLog(LLDBLog::Object), "Cannot determine client_data from client-telemetry entry"); - int64_t start_time; - if (dict->GetValueForKeyAsInteger("start_time", start_time)) { -client_info.start_time += -std::chrono::nanoseconds(static_cast(start_time)); - } else { -LLDB_LOG(GetLog(LLDBLog::Object), - "Cannot determine start-time from client-telemetry entry"); - } + auto start_time = GetAsNanosec(dict, "start_time"); + if (start_time.has_value()) +client_info.start_time += start_time.value(); - int64_t end_time; - if (dict->GetValueForKeyAsInteger("end_time", end_time)) { + auto end_time = GetAsNanosec(dict, "end_time"); + if (end_time.has_value()) { SteadyTimePoint epoch; -client_info.end_time = -epoch + std::chrono::nanoseconds(static_cast(end_time)); - } else { -LLDB_LOG(GetLog(LLDBLog::Object), - "Cannot determine end-time from client-telemetry entry"); +client_info.end_time = epoch + end_time.value(); } llvm::StringRef error_msg; >From e299d3416f68c08fdfd6dbee6ee99c3225158658 Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Fri, 27 Jun 2025 11:11:02 -0400 Subject: [PATCH 2/3] Update lldb/source/Core/Telemetry.cpp Co-authored-by: Alex Langford --- lldb/source/Core/Telemetry.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp index 464c1d4071a73..5382c0e090b1b 100644 --- a/lldb/source/Core/Telemetry.cpp +++ b/lldb/source/Core/Telemetry.cpp @@ -161,9 +161,8 @@ void TelemetryManager::DispatchClientTelemetry( LLDB_LOG(GetLog(LLDBLog::Object), "Cannot determine client_data from client-telemetry entry"); - auto start_time = GetAsNanosec(dict, "start_time"); - if (start_time.has_value()) -client_info.start_time += start_time.value(); + if (auto maybe_start_time = GetAsNanosec(dict, "start_time")) + client_info.start_time += *maybe_start_time; auto end_time = GetAsNanosec(dict, "end_time"); if (end_time.has_value()) { >From 0365e814bb7442446f55ace76942b581eb4ebc5a Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Mon, 30 Jun 2025 11:03:23 -0400 Subject: [PATCH 3/3] addressed review comment --- lldb/source/Core/Telemetry.cpp | 7 +++ 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp index 5382c0e090b1b..beeac046d0785 100644 --- a/lldb/source/Core/Telemetry.cpp +++ b/lldb/source/Core/Telemetry.cpp @@ -162,12 +162,11 @@ void TelemetryManager::DispatchClientTelemetry( "Cannot determine client_data from client-telemetry entry"); if (auto maybe_start_time = GetAsNanosec(dict, "start_time")) - client_info.start_time += *maybe_start_time; +client_info.start_time += *maybe_start_time; - auto end_time = GetAsNanosec(dict, "end_time"); - if (end_time.has_value()) { + if (auto maybe_end_time = GetAsNanosec(dict, "end_time")) { SteadyTimePoint epoch; -client_info.end_time = epoch + end_time.value(); +client_info.end_time = epoch + maybe_end_time.value(); } llvm::StringRef error_msg; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Refactor code extracting timestamp from StructuredData (PR #145954)
@@ -148,23 +161,14 @@ void TelemetryManager::DispatchClientTelemetry( LLDB_LOG(GetLog(LLDBLog::Object), "Cannot determine client_data from client-telemetry entry"); - int64_t start_time; - if (dict->GetValueForKeyAsInteger("start_time", start_time)) { -client_info.start_time += -std::chrono::nanoseconds(static_cast(start_time)); - } else { -LLDB_LOG(GetLog(LLDBLog::Object), - "Cannot determine start-time from client-telemetry entry"); - } + auto start_time = GetAsNanosec(dict, "start_time"); + if (start_time.has_value()) +client_info.start_time += start_time.value(); - int64_t end_time; - if (dict->GetValueForKeyAsInteger("end_time", end_time)) { + auto end_time = GetAsNanosec(dict, "end_time"); + if (end_time.has_value()) { SteadyTimePoint epoch; -client_info.end_time = -epoch + std::chrono::nanoseconds(static_cast(end_time)); - } else { -LLDB_LOG(GetLog(LLDBLog::Object), - "Cannot determine end-time from client-telemetry entry"); +client_info.end_time = epoch + end_time.value(); oontvoo wrote: done https://github.com/llvm/llvm-project/pull/145954 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 5548f4d - [LLDB][NFC] Refactor code extracting timestamp from StructuredData (#145954)
Author: Vy Nguyen Date: 2025-06-30T14:25:11-04:00 New Revision: 5548f4d5ef6ab7192fe454a497af6f2cfe403339 URL: https://github.com/llvm/llvm-project/commit/5548f4d5ef6ab7192fe454a497af6f2cfe403339 DIFF: https://github.com/llvm/llvm-project/commit/5548f4d5ef6ab7192fe454a497af6f2cfe403339.diff LOG: [LLDB][NFC] Refactor code extracting timestamp from StructuredData (#145954) Co-authored-by: Alex Langford Added: Modified: lldb/source/Core/Telemetry.cpp Removed: diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp index 6434b11a63ad4..2f2e1c1d56d52 100644 --- a/lldb/source/Core/Telemetry.cpp +++ b/lldb/source/Core/Telemetry.cpp @@ -119,6 +119,19 @@ llvm::Error TelemetryManager::preDispatch(TelemetryInfo *entry) { return llvm::Error::success(); } +// Helper for extracting time field from a Dictionary. +static std::optional +GetAsNanosec(StructuredData::Dictionary *dict, llvm::StringRef key) { + auto value = dict->GetValueForKey(key); + if (!value->IsValid()) { +LLDB_LOG(GetLog(LLDBLog::Object), + "Cannot determine {0} from client-telemetry entry", key); +return std::nullopt; + } + + return std::chrono::nanoseconds(value->GetUnsignedIntegerValue(0)); +} + void TelemetryManager::DispatchClientTelemetry( const lldb_private::StructuredDataImpl &entry, Debugger *debugger) { if (!m_config->enable_client_telemetry) @@ -148,23 +161,12 @@ void TelemetryManager::DispatchClientTelemetry( LLDB_LOG(GetLog(LLDBLog::Object), "Cannot determine client_data from client-telemetry entry"); - int64_t start_time; - if (dict->GetValueForKeyAsInteger("start_time", start_time)) { -client_info.start_time += -std::chrono::nanoseconds(static_cast(start_time)); - } else { -LLDB_LOG(GetLog(LLDBLog::Object), - "Cannot determine start-time from client-telemetry entry"); - } + if (auto maybe_start_time = GetAsNanosec(dict, "start_time")) +client_info.start_time += *maybe_start_time; - int64_t end_time; - if (dict->GetValueForKeyAsInteger("end_time", end_time)) { + if (auto maybe_end_time = GetAsNanosec(dict, "end_time")) { SteadyTimePoint epoch; -client_info.end_time = -epoch + std::chrono::nanoseconds(static_cast(end_time)); - } else { -LLDB_LOG(GetLog(LLDBLog::Object), - "Cannot determine end-time from client-telemetry entry"); +client_info.end_time = epoch + *maybe_end_time; } llvm::StringRef error_msg; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Refactor code extracting timestamp from StructuredData (PR #145954)
https://github.com/oontvoo closed https://github.com/llvm/llvm-project/pull/145954 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Document MCP support in LLDB (PR #145935)
https://github.com/DavidSpickett approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/145935 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 25e5010 - [lldb] Delete unused variables in TestLoongArchEmulator.cpp.
Author: James Y Knight Date: 2025-06-30T11:54:36-04:00 New Revision: 25e5010a302f2c93397c56d7c07168e075a15a44 URL: https://github.com/llvm/llvm-project/commit/25e5010a302f2c93397c56d7c07168e075a15a44 DIFF: https://github.com/llvm/llvm-project/commit/25e5010a302f2c93397c56d7c07168e075a15a44.diff LOG: [lldb] Delete unused variables in TestLoongArchEmulator.cpp. These were introduced by d7e23bef6ad497cd5a100126957c381e053dda9b "[lldb][RISCV] fix LR/SC atomic sequence handling in lldb-server" Added: Modified: lldb/unittests/Instruction/LoongArch/TestLoongArchEmulator.cpp Removed: diff --git a/lldb/unittests/Instruction/LoongArch/TestLoongArchEmulator.cpp b/lldb/unittests/Instruction/LoongArch/TestLoongArchEmulator.cpp index 1be0ef2af3c2e..f3b0d65c2cbfe 100644 --- a/lldb/unittests/Instruction/LoongArch/TestLoongArchEmulator.cpp +++ b/lldb/unittests/Instruction/LoongArch/TestLoongArchEmulator.cpp @@ -166,7 +166,6 @@ using EncoderBZcond = uint32_t (*)(uint32_t rj, int32_t offs21); using EncoderBCZcond = uint32_t (*)(uint8_t cj, int32_t offs21); TEST_F(LoongArch64EmulatorTester, testJIRL) { - bool success = false; addr_t old_pc = 0x12000600; WritePC(old_pc); // JIRL r1, r12, 0x10 @@ -184,7 +183,6 @@ TEST_F(LoongArch64EmulatorTester, testJIRL) { } TEST_F(LoongArch64EmulatorTester, testB) { - bool success = false; addr_t old_pc = 0x12000600; WritePC(old_pc); // B 0x10010 @@ -199,7 +197,6 @@ TEST_F(LoongArch64EmulatorTester, testB) { } TEST_F(LoongArch64EmulatorTester, testBL) { - bool success = false; addr_t old_pc = 0x12000600; WritePC(old_pc); // BL 0x10010 @@ -218,7 +215,6 @@ TEST_F(LoongArch64EmulatorTester, testBL) { static void testBcondBranch(LoongArch64EmulatorTester *tester, EncoderBcond encoder, bool branched, uint64_t rj_val, uint64_t rd_val) { - bool success = false; addr_t old_pc = 0x12000600; tester->WritePC(old_pc); tester->gpr.gpr[12] = rj_val; @@ -234,7 +230,6 @@ static void testBcondBranch(LoongArch64EmulatorTester *tester, static void testBZcondBranch(LoongArch64EmulatorTester *tester, EncoderBZcond encoder, bool branched, uint64_t rj_val) { - bool success = false; addr_t old_pc = 0x12000600; tester->WritePC(old_pc); tester->gpr.gpr[4] = rj_val; @@ -249,7 +244,6 @@ static void testBZcondBranch(LoongArch64EmulatorTester *tester, static void testBCZcondBranch(LoongArch64EmulatorTester *tester, EncoderBCZcond encoder, bool branched, uint32_t cj_val) { - bool success = false; addr_t old_pc = 0x12000600; tester->WritePC(old_pc); tester->fpr.fcc = cj_val; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 16dc6f6 - [lldb] Document MCP support in LLDB (#145935)
Author: Jonas Devlieghere Date: 2025-06-30T09:01:15-07:00 New Revision: 16dc6f64ded3f47a6c03098e021ae943714a7663 URL: https://github.com/llvm/llvm-project/commit/16dc6f64ded3f47a6c03098e021ae943714a7663 DIFF: https://github.com/llvm/llvm-project/commit/16dc6f64ded3f47a6c03098e021ae943714a7663.diff LOG: [lldb] Document MCP support in LLDB (#145935) Document how to use MCP support in LLDB. I expect this to change significantly as the feature matures. For now it covers configuring the server and two example clients. Added: lldb/docs/use/mcp.md Modified: lldb/docs/index.rst Removed: diff --git a/lldb/docs/index.rst b/lldb/docs/index.rst index 1ffdb08a1ca2c..d49d0d8d5a733 100644 --- a/lldb/docs/index.rst +++ b/lldb/docs/index.rst @@ -135,6 +135,7 @@ interesting areas to contribute to lldb. use/ondemand use/aarch64-linux use/symbolfilejson + use/mcp use/troubleshooting use/links Man Page diff --git a/lldb/docs/use/mcp.md b/lldb/docs/use/mcp.md new file mode 100644 index 0..e7e78f7a28c7a --- /dev/null +++ b/lldb/docs/use/mcp.md @@ -0,0 +1,85 @@ +# Model Context Protocol (MCP) + +LLDB supports the [Model Context Protocol][https://modelcontextprotocol.io] +(MCP). This structured, machine-friendly protocol allows AI models to access +and interact with external tools, for example debuggers. Using MCP, an AI agent +can execute LLDB commands to control the debugger: set breakpoints, inspect +memory, step through code. This can range from helping you run a specific +command you cannot immediately remember, to a fully agent-driven debugging +experience. + +## MCP Server + +To start the MCP server in LLDB, use the `protocol-server start` command. +Specify `MCP` as the protocol and provide a URI to listen on. For example, to +start listening for local TCP connections on port `5`, use the following +command: + +``` +(lldb) protocol-server start MCP listen://localhost:5 +MCP server started with connection listeners: connection://[::1]:5, connection://[127.0.0.1]:5 +``` + +The server will automatically stop when exiting LLDB, or it can be stopped +explicitly with the `protocol-server stop` command. + +``` +(lldb) protocol-server stop MCP +``` + +The commands will fail if a server is already running or not running +respectively. + +## MCP Client + +MCP uses standard input/output (stdio) for communication between client and +server. The exact configuration depends on the client, but most applications +allow you to specify an MCP server as a binary and arguments. This means that +you need to use something like `netcat` to connect to LLDB's MCP server and +forward communication over stdio over the network connection. + +``` +┌──┐ ┌──┐ ┌──┐ +│ │ │ │ │ │ +│ LLDB ├─socket┤ netcat ├─stdio─┤MCP Client│ +│ │ │ │ │ │ +└──┘ └──┘ └──┘ +``` + +Configuration example for [Claude Code][https://modelcontextprotocol.io/quickstart/user]: + +```json +{ + "mcpServers": { +"tool": { + "command": "/usr/bin/nc", + "args": ["localhost", "5"] +} + } +} +``` + +Configuration example for [Visual Studio Code][https://code.visualstudio.com/docs/copilot/chat/mcp-servers]: + +```json +{ + "mcp": { +"servers": { + "lldb": { +"type": "stdio", +"command": "/usr/bin/nc", +"args": ["localhost", "5"] + } +} + } +} +``` + +### Troubleshooting + +The MCP server uses the `Host` log channel. You can enable logging with the +`log enable` command. + +``` +(lldb) log enable lldb host +``` ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
@@ -1152,6 +1150,46 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( } } +llvm::Expected +lldb_private::PlatformDarwin::ResolveSDKPathFromDebugInfo( +lldb_private::Target *target) { + + ModuleSP exe_module_sp = target->GetExecutableModule(); + if (!exe_module_sp) +return llvm::createStringError( +llvm::inconvertibleErrorCode(), +llvm::formatv("Failed to get module from target")); + + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); + if (!sym_file) +return llvm::createStringError( +llvm::inconvertibleErrorCode(), +llvm::formatv("Failed to get symbol file from module")); + + XcodeSDK merged_sdk; + for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { +if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { + auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp); + merged_sdk.Merge(cu_sdk); +} + } + + // TODO: The result of this loop is almost equivalent to deriving the SDK + // from the target triple, which would be a lot cheaper. + FileSpec sdk_path = merged_sdk.GetSysroot(); + if (FileSystem::Instance().Exists(sdk_path)) { +return sdk_path; + } + auto path_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk}); + if (path_or_err) Michael137 wrote: Minor nit: I would invert this condition and return error if `!path_or_err`. Then return `FileSpec(*path_or_err)` as the last return from this function. So we're consistent with all the other early returns in this function https://github.com/llvm/llvm-project/pull/146062 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
@@ -1152,6 +1150,46 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( } } +llvm::Expected +lldb_private::PlatformDarwin::ResolveSDKPathFromDebugInfo( +lldb_private::Target *target) { + + ModuleSP exe_module_sp = target->GetExecutableModule(); + if (!exe_module_sp) +return llvm::createStringError( +llvm::inconvertibleErrorCode(), +llvm::formatv("Failed to get module from target")); + + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); + if (!sym_file) +return llvm::createStringError( +llvm::inconvertibleErrorCode(), +llvm::formatv("Failed to get symbol file from module")); + + XcodeSDK merged_sdk; + for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { +if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { + auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp); + merged_sdk.Merge(cu_sdk); +} + } + + // TODO: The result of this loop is almost equivalent to deriving the SDK + // from the target triple, which would be a lot cheaper. + FileSpec sdk_path = merged_sdk.GetSysroot(); + if (FileSystem::Instance().Exists(sdk_path)) { +return sdk_path; + } + auto path_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk}); + if (path_or_err) +return FileSpec(*path_or_err); + + return llvm::createStringError( + llvm::inconvertibleErrorCode(), + llvm::formatv("Failed to resolve SDK path: {0}", +llvm::toString(path_or_err.takeError(; Michael137 wrote: ```suggestion return llvm::createStringError( llvm::formatv("Failed to resolve SDK path: {0}", llvm::toString(path_or_err.takeError())); ``` https://github.com/llvm/llvm-project/pull/146062 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
@@ -187,6 +187,9 @@ class PlatformDarwin : public PlatformPOSIX { std::vector &options, XcodeSDK::Type sdk_type); + static llvm::Expected + ResolveSDKPathFromDebugInfo(lldb_private::Target *target); Michael137 wrote: We don't need this to be in the header. We can just make it local to the `.cpp` file https://github.com/llvm/llvm-project/pull/146062 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
https://github.com/Michael137 edited https://github.com/llvm/llvm-project/pull/146062 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
https://github.com/Michael137 approved this pull request. LGTM, just some final stylistic comments https://github.com/llvm/llvm-project/pull/146062 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
@@ -1152,6 +1150,46 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( } } +llvm::Expected +lldb_private::PlatformDarwin::ResolveSDKPathFromDebugInfo( +lldb_private::Target *target) { + + ModuleSP exe_module_sp = target->GetExecutableModule(); + if (!exe_module_sp) +return llvm::createStringError( +llvm::inconvertibleErrorCode(), +llvm::formatv("Failed to get module from target")); Michael137 wrote: ```suggestion return llvm::createStringError("Failed to get module from target"); ``` https://github.com/llvm/llvm-project/pull/146062 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
@@ -1152,6 +1150,46 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( } } +llvm::Expected +lldb_private::PlatformDarwin::ResolveSDKPathFromDebugInfo( +lldb_private::Target *target) { + + ModuleSP exe_module_sp = target->GetExecutableModule(); + if (!exe_module_sp) +return llvm::createStringError( +llvm::inconvertibleErrorCode(), +llvm::formatv("Failed to get module from target")); + + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); + if (!sym_file) +return llvm::createStringError( +llvm::inconvertibleErrorCode(), +llvm::formatv("Failed to get symbol file from module")); Michael137 wrote: ```suggestion return llvm::createStringError("Failed to get symbol file from module"); ``` https://github.com/llvm/llvm-project/pull/146062 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Delete unused DWARFDataExtractor methods (PR #146356)
https://github.com/Michael137 approved this pull request. https://github.com/llvm/llvm-project/pull/146356 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Delete unused DWARFDataExtractor methods (PR #146356)
@@ -7,20 +7,10 @@ //===--===// #include "DWARFDataExtractor.h" -#include "llvm/ADT/StringRef.h" Michael137 wrote: Makes sense to include `ArrayRef` though since it's used in this source file. https://github.com/llvm/llvm-project/pull/146356 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Delete unused DWARFDataExtractor methods (PR #146356)
@@ -7,20 +7,10 @@ //===--===// #include "DWARFDataExtractor.h" -#include "llvm/ADT/StringRef.h" Michael137 wrote: How come this changed? Is this `clangd`? https://github.com/llvm/llvm-project/pull/146356 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Correctly restore the cursor column after resizing the statusline (PR #145823)
JDevlieghere wrote: > Yeah, that would definitely be bad, but I feel like it should be avoidable. I > take it that's a side effect of implementing resize by disabling and > re-enabling the status line. However, does it have to be that way? What if > resize was a separate operation that just involved redrawing the status line > in the new place? In that case, you shouldn't need to do the `\n` thingy > (even if the terminal size is being decreased) because the space was already > reserved by the previous status line (?) There are a few optimization you can do, which may be what you're referring to? I'm not sure there's anything you can do unconditionally to avoid the newline when resizing, as you will have to adjust the scroll window when the terminal height changes. Here's the things I have in mind: - When only the terminal width changes, we don't need to adjust the scroll window. - When the terminal height increases, we don't need to add the newline. - When the terminal height decreases, we don't need to clear the old statusline. https://github.com/llvm/llvm-project/pull/145823 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Correctly restore the cursor column after resizing the statusline (PR #146132)
JDevlieghere wrote: > This looks good. Any chance of a test case? This sounds like something > pexpect should manage to handle. I'm somewhat skeptical of the value, but I can add a test case to check for the escape codes to make sure the new Editline code is called. https://github.com/llvm/llvm-project/pull/146132 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/145621 >From 79c10b6f6630b3ceaa85af45956aeafdf372b5be Mon Sep 17 00:00:00 2001 From: John Harrison Date: Wed, 25 Jun 2025 18:03:39 -0700 Subject: [PATCH 1/7] [lldb] Adding file and pipe support to lldb_private::MainLoopWindows. This updates MainLoopWindows to support events for reading from a file and a socket type. This unifies both handle types using WaitForMultipleEvents which can listen to both sockets and files for change events. This should allow us to unify how we handle watching files/pipes/sockets on Windows and Posix systems. --- lldb/include/lldb/Host/File.h | 2 + lldb/include/lldb/Host/Socket.h | 2 + .../lldb/Host/windows/MainLoopWindows.h | 3 +- lldb/include/lldb/Utility/IOObject.h | 8 +- lldb/source/Host/common/File.cpp | 18 +++ lldb/source/Host/common/Socket.cpp| 49 +++- .../posix/ConnectionFileDescriptorPosix.cpp | 14 ++- lldb/source/Host/windows/MainLoopWindows.cpp | 116 +- lldb/source/Utility/IOObject.cpp | 9 ++ lldb/unittests/Host/FileTest.cpp | 16 ++- lldb/unittests/Host/MainLoopTest.cpp | 26 11 files changed, 190 insertions(+), 73 deletions(-) diff --git a/lldb/include/lldb/Host/File.h b/lldb/include/lldb/Host/File.h index 9e2d0abe0b1af..36cb192281289 100644 --- a/lldb/include/lldb/Host/File.h +++ b/lldb/include/lldb/Host/File.h @@ -127,6 +127,7 @@ class File : public IOObject { /// \return /// a valid handle or IOObject::kInvalidHandleValue WaitableHandle GetWaitableHandle() override; + bool HasReadableData() override; /// Get the file specification for this file, if possible. /// @@ -400,6 +401,7 @@ class NativeFile : public File { Status Write(const void *buf, size_t &num_bytes) override; Status Close() override; WaitableHandle GetWaitableHandle() override; + bool HasReadableData() override; Status GetFileSpec(FileSpec &file_spec) const override; int GetDescriptor() const override; FILE *GetStream() override; diff --git a/lldb/include/lldb/Host/Socket.h b/lldb/include/lldb/Host/Socket.h index 89953ee7fd5b6..6569e9e6ea818 100644 --- a/lldb/include/lldb/Host/Socket.h +++ b/lldb/include/lldb/Host/Socket.h @@ -158,6 +158,7 @@ class Socket : public IOObject { bool IsValid() const override { return m_socket != kInvalidSocketValue; } WaitableHandle GetWaitableHandle() override; + bool HasReadableData() override; static llvm::Expected DecodeHostAndPort(llvm::StringRef host_and_port); @@ -185,6 +186,7 @@ class Socket : public IOObject { SocketProtocol m_protocol; NativeSocket m_socket; + WaitableHandle m_waitable_handle; bool m_should_close_fd; }; diff --git a/lldb/include/lldb/Host/windows/MainLoopWindows.h b/lldb/include/lldb/Host/windows/MainLoopWindows.h index 3937a24645d95..43b7d13a0e445 100644 --- a/lldb/include/lldb/Host/windows/MainLoopWindows.h +++ b/lldb/include/lldb/Host/windows/MainLoopWindows.h @@ -37,11 +37,10 @@ class MainLoopWindows : public MainLoopBase { void Interrupt() override; private: - void ProcessReadObject(IOObject::WaitableHandle handle); llvm::Expected Poll(); struct FdInfo { -void *event; +lldb::IOObjectSP object_sp; Callback callback; }; llvm::DenseMap m_read_fds; diff --git a/lldb/include/lldb/Utility/IOObject.h b/lldb/include/lldb/Utility/IOObject.h index 8cf42992e7be5..48a8a2076581f 100644 --- a/lldb/include/lldb/Utility/IOObject.h +++ b/lldb/include/lldb/Utility/IOObject.h @@ -14,6 +14,7 @@ #include #include "lldb/lldb-private.h" +#include "lldb/lldb-types.h" namespace lldb_private { @@ -24,9 +25,9 @@ class IOObject { eFDTypeSocket, // Socket requiring send/recv }; - // TODO: On Windows this should be a HANDLE, and wait should use - // WaitForMultipleObjects - typedef int WaitableHandle; + // A handle for integrating with the host event loop model. + using WaitableHandle = lldb::file_t; + static const WaitableHandle kInvalidHandleValue; IOObject(FDType type) : m_fd_type(type) {} @@ -40,6 +41,7 @@ class IOObject { FDType GetFdType() const { return m_fd_type; } virtual WaitableHandle GetWaitableHandle() = 0; + virtual bool HasReadableData() = 0; protected: FDType m_fd_type; diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp index 9aa95ffda44cb..2d33f9e2028c4 100644 --- a/lldb/source/Host/common/File.cpp +++ b/lldb/source/Host/common/File.cpp @@ -118,6 +118,8 @@ IOObject::WaitableHandle File::GetWaitableHandle() { return IOObject::kInvalidHandleValue; } +bool File::HasReadableData() { return false; } + Status File::GetFileSpec(FileSpec &file_spec) const { file_spec.Clear(); return std::error_code(ENOTSUP, std::system_category()); @@ -274,7 +276,23 @@ int NativeFile::GetDescriptor() const { } IOObject::WaitableHandle N
[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)
@@ -31,6 +34,122 @@ static DWORD ToTimeout(std::optional point) { return ceil(dur).count(); } +namespace { + +class PipeEvent : public MainLoopWindows::IOEvent { +public: + explicit PipeEvent(HANDLE handle) + : IOEvent((IOObject::WaitableHandle)CreateEventW( +NULL, /*bManualReset=*/FALSE, +/*bInitialState=*/FALSE, NULL)), +m_handle(handle), m_ready(CreateEventW(NULL, /*bManualReset=*/FALSE, + /*bInitialState=*/FALSE, NULL)) { +assert(event && ready); + } + + ~PipeEvent() override { +if (m_monitor_thread.joinable()) { + m_stopped = true; + SetEvent(m_ready); + // Keep trying to cancel ReadFile() until the thread exits. + do { +CancelIoEx((HANDLE)m_handle, /*lpOverlapped=*/NULL); + } while (WaitForSingleObject(m_monitor_thread.native_handle(), 1) == + WAIT_TIMEOUT); + m_monitor_thread.join(); +} +CloseHandle((HANDLE)m_event); +CloseHandle(m_ready); + } + + void WillPoll() override { +if (!m_monitor_thread.joinable()) ashgti wrote: I had this at first but I needed to have an extra ivar for starting the signaling the thread to start in the 'WillPoll', otherwise if you registered a PipeEvent and didn't immediately run the loop it potentially prematurely get a read signal. I tried using the `m_ready` variable for triggering that, but it got complicated if an event fired between polling events because of when we call 'Disarm'. https://github.com/llvm/llvm-project/pull/145621 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/145621 >From 79c10b6f6630b3ceaa85af45956aeafdf372b5be Mon Sep 17 00:00:00 2001 From: John Harrison Date: Wed, 25 Jun 2025 18:03:39 -0700 Subject: [PATCH 1/6] [lldb] Adding file and pipe support to lldb_private::MainLoopWindows. This updates MainLoopWindows to support events for reading from a file and a socket type. This unifies both handle types using WaitForMultipleEvents which can listen to both sockets and files for change events. This should allow us to unify how we handle watching files/pipes/sockets on Windows and Posix systems. --- lldb/include/lldb/Host/File.h | 2 + lldb/include/lldb/Host/Socket.h | 2 + .../lldb/Host/windows/MainLoopWindows.h | 3 +- lldb/include/lldb/Utility/IOObject.h | 8 +- lldb/source/Host/common/File.cpp | 18 +++ lldb/source/Host/common/Socket.cpp| 49 +++- .../posix/ConnectionFileDescriptorPosix.cpp | 14 ++- lldb/source/Host/windows/MainLoopWindows.cpp | 116 +- lldb/source/Utility/IOObject.cpp | 9 ++ lldb/unittests/Host/FileTest.cpp | 16 ++- lldb/unittests/Host/MainLoopTest.cpp | 26 11 files changed, 190 insertions(+), 73 deletions(-) diff --git a/lldb/include/lldb/Host/File.h b/lldb/include/lldb/Host/File.h index 9e2d0abe0b1af..36cb192281289 100644 --- a/lldb/include/lldb/Host/File.h +++ b/lldb/include/lldb/Host/File.h @@ -127,6 +127,7 @@ class File : public IOObject { /// \return /// a valid handle or IOObject::kInvalidHandleValue WaitableHandle GetWaitableHandle() override; + bool HasReadableData() override; /// Get the file specification for this file, if possible. /// @@ -400,6 +401,7 @@ class NativeFile : public File { Status Write(const void *buf, size_t &num_bytes) override; Status Close() override; WaitableHandle GetWaitableHandle() override; + bool HasReadableData() override; Status GetFileSpec(FileSpec &file_spec) const override; int GetDescriptor() const override; FILE *GetStream() override; diff --git a/lldb/include/lldb/Host/Socket.h b/lldb/include/lldb/Host/Socket.h index 89953ee7fd5b6..6569e9e6ea818 100644 --- a/lldb/include/lldb/Host/Socket.h +++ b/lldb/include/lldb/Host/Socket.h @@ -158,6 +158,7 @@ class Socket : public IOObject { bool IsValid() const override { return m_socket != kInvalidSocketValue; } WaitableHandle GetWaitableHandle() override; + bool HasReadableData() override; static llvm::Expected DecodeHostAndPort(llvm::StringRef host_and_port); @@ -185,6 +186,7 @@ class Socket : public IOObject { SocketProtocol m_protocol; NativeSocket m_socket; + WaitableHandle m_waitable_handle; bool m_should_close_fd; }; diff --git a/lldb/include/lldb/Host/windows/MainLoopWindows.h b/lldb/include/lldb/Host/windows/MainLoopWindows.h index 3937a24645d95..43b7d13a0e445 100644 --- a/lldb/include/lldb/Host/windows/MainLoopWindows.h +++ b/lldb/include/lldb/Host/windows/MainLoopWindows.h @@ -37,11 +37,10 @@ class MainLoopWindows : public MainLoopBase { void Interrupt() override; private: - void ProcessReadObject(IOObject::WaitableHandle handle); llvm::Expected Poll(); struct FdInfo { -void *event; +lldb::IOObjectSP object_sp; Callback callback; }; llvm::DenseMap m_read_fds; diff --git a/lldb/include/lldb/Utility/IOObject.h b/lldb/include/lldb/Utility/IOObject.h index 8cf42992e7be5..48a8a2076581f 100644 --- a/lldb/include/lldb/Utility/IOObject.h +++ b/lldb/include/lldb/Utility/IOObject.h @@ -14,6 +14,7 @@ #include #include "lldb/lldb-private.h" +#include "lldb/lldb-types.h" namespace lldb_private { @@ -24,9 +25,9 @@ class IOObject { eFDTypeSocket, // Socket requiring send/recv }; - // TODO: On Windows this should be a HANDLE, and wait should use - // WaitForMultipleObjects - typedef int WaitableHandle; + // A handle for integrating with the host event loop model. + using WaitableHandle = lldb::file_t; + static const WaitableHandle kInvalidHandleValue; IOObject(FDType type) : m_fd_type(type) {} @@ -40,6 +41,7 @@ class IOObject { FDType GetFdType() const { return m_fd_type; } virtual WaitableHandle GetWaitableHandle() = 0; + virtual bool HasReadableData() = 0; protected: FDType m_fd_type; diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp index 9aa95ffda44cb..2d33f9e2028c4 100644 --- a/lldb/source/Host/common/File.cpp +++ b/lldb/source/Host/common/File.cpp @@ -118,6 +118,8 @@ IOObject::WaitableHandle File::GetWaitableHandle() { return IOObject::kInvalidHandleValue; } +bool File::HasReadableData() { return false; } + Status File::GetFileSpec(FileSpec &file_spec) const { file_spec.Clear(); return std::error_code(ENOTSUP, std::system_category()); @@ -274,7 +276,23 @@ int NativeFile::GetDescriptor() const { } IOObject::WaitableHandle N
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/146062 >From 6ce75177264d47ffedbf0e6ee44831eac1d3ea55 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Fri, 27 Jun 2025 12:49:53 +0100 Subject: [PATCH 1/3] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site --- .../Platform/MacOSX/PlatformDarwin.cpp| 32 +++ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 262a7dc731713..ae46ac63e756a 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1130,13 +1130,33 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( if (target) { if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - auto path_or_err = ResolveSDKPathFromDebugInfo(*exe_module_sp); - if (path_or_err) { -sysroot_spec = FileSpec(*path_or_err); + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); + if (!sym_file) +return; + + XcodeSDK merged_sdk; + for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { +if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { + auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp); + merged_sdk.Merge(cu_sdk); +} + } + + // TODO: The result of this loop is almost equivalent to deriving the SDK + // from the target triple, which would be a lot cheaper. + + if (FileSystem::Instance().Exists(merged_sdk.GetSysroot())) { +sysroot_spec = merged_sdk.GetSysroot(); } else { -LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), - path_or_err.takeError(), - "Failed to resolve SDK path: {0}"); +auto path_or_err = +HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk}); +if (path_or_err) { + sysroot_spec = FileSpec(*path_or_err); +} else { + LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), + path_or_err.takeError(), + "Failed to resolve SDK path: {0}"); +} } } } >From aa2417acc66af5612abb33bf39edc9d2b41478a7 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Mon, 30 Jun 2025 12:22:21 +0100 Subject: [PATCH 2/3] extract to helper method --- .../Platform/MacOSX/PlatformDarwin.cpp| 70 +++ .../Plugins/Platform/MacOSX/PlatformDarwin.h | 3 + 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index ae46ac63e756a..4411c88c97ab2 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1128,37 +1128,8 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( FileSpec sysroot_spec; - if (target) { -if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); - if (!sym_file) -return; - - XcodeSDK merged_sdk; - for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { -if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { - auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp); - merged_sdk.Merge(cu_sdk); -} - } - - // TODO: The result of this loop is almost equivalent to deriving the SDK - // from the target triple, which would be a lot cheaper. - - if (FileSystem::Instance().Exists(merged_sdk.GetSysroot())) { -sysroot_spec = merged_sdk.GetSysroot(); - } else { -auto path_or_err = -HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk}); -if (path_or_err) { - sysroot_spec = FileSpec(*path_or_err); -} else { - LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), - path_or_err.takeError(), - "Failed to resolve SDK path: {0}"); -} - } -} + if (target && ResolveSDKPathFromDebugInfo(target, sysroot_spec)) { +return; } if (!FileSystem::Instance().IsDirectory(sysroot_spec.GetPath())) { @@ -1172,6 +1143,43 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( } } +bool lldb_private::PlatformDarwin::ResolveSDKPathFromDebugInfo( +lldb_private::Target *target, lldb_private::FileSpec &sysroot_spec) { + + ModuleSP exe_module_sp = target->GetExecutableModule(); + if (!exe_module_sp) +return false; + + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); + if (!sym_file) +return true; + + XcodeSDK merged_sdk; + for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { +if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { + auto cu_sdk = sym_file-
[Lldb-commits] [lldb] [lldb] Delete unused DWARFDataExtractor methods (PR #146356)
https://github.com/labath created https://github.com/llvm/llvm-project/pull/146356 They are left over from our previous attempt at DWARF64. The new attempt is not using them, and they also don't have equivalents in the llvm DWARFDataExtractor class. >From b2ad70820e53be64e5908c84d8b828369dce9b41 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Mon, 30 Jun 2025 16:18:38 +0200 Subject: [PATCH] [lldb] Delete unused DWARFDataExtractor methods They are left over from our previous attempt at DWARF64. The new attempt is not using them, and they also don't have equivalents in the llvm DWARFDataExtractor class. --- .../Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp | 12 +--- .../Plugins/SymbolFile/DWARF/DWARFDataExtractor.h| 8 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp index c5876502b8f29..a0b8acb585635 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp @@ -7,20 +7,10 @@ //===--===// #include "DWARFDataExtractor.h" -#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/ArrayRef.h" namespace lldb_private { -uint64_t -DWARFDataExtractor::GetDWARFInitialLength(lldb::offset_t *offset_ptr) const { - return GetU32(offset_ptr); -} - -dw_offset_t -DWARFDataExtractor::GetDWARFOffset(lldb::offset_t *offset_ptr) const { - return GetMaxU64(offset_ptr, GetDWARFSizeOfOffset()); -} - llvm::DWARFDataExtractor DWARFDataExtractor::GetAsLLVMDWARF() const { return llvm::DWARFDataExtractor(llvm::ArrayRef(GetDataStart(), GetByteSize()), GetByteOrder() == lldb::eByteOrderLittle, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h index 41b8e9ad0217b..f6bcf9b2d27f7 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h @@ -9,7 +9,6 @@ #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDATAEXTRACTOR_H #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDATAEXTRACTOR_H -#include "lldb/Core/dwarf.h" #include "lldb/Utility/DataExtractor.h" #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h" @@ -23,13 +22,6 @@ class DWARFDataExtractor : public DataExtractor { lldb::offset_t length) : DataExtractor(data, offset, length) {} - uint64_t GetDWARFInitialLength(lldb::offset_t *offset_ptr) const; - - dw_offset_t GetDWARFOffset(lldb::offset_t *offset_ptr) const; - - size_t GetDWARFSizeofInitialLength() const { return 4; } - size_t GetDWARFSizeOfOffset() const { return 4; } - llvm::DWARFDataExtractor GetAsLLVMDWARF() const; llvm::DataExtractor GetAsLLVM() const; }; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Delete unused DWARFDataExtractor methods (PR #146356)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Pavel Labath (labath) Changes They are left over from our previous attempt at DWARF64. The new attempt is not using them, and they also don't have equivalents in the llvm DWARFDataExtractor class. --- Full diff: https://github.com/llvm/llvm-project/pull/146356.diff 2 Files Affected: - (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp (+1-11) - (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h (-8) ``diff diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp index c5876502b8f29..a0b8acb585635 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.cpp @@ -7,20 +7,10 @@ //===--===// #include "DWARFDataExtractor.h" -#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/ArrayRef.h" namespace lldb_private { -uint64_t -DWARFDataExtractor::GetDWARFInitialLength(lldb::offset_t *offset_ptr) const { - return GetU32(offset_ptr); -} - -dw_offset_t -DWARFDataExtractor::GetDWARFOffset(lldb::offset_t *offset_ptr) const { - return GetMaxU64(offset_ptr, GetDWARFSizeOfOffset()); -} - llvm::DWARFDataExtractor DWARFDataExtractor::GetAsLLVMDWARF() const { return llvm::DWARFDataExtractor(llvm::ArrayRef(GetDataStart(), GetByteSize()), GetByteOrder() == lldb::eByteOrderLittle, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h index 41b8e9ad0217b..f6bcf9b2d27f7 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h @@ -9,7 +9,6 @@ #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDATAEXTRACTOR_H #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDATAEXTRACTOR_H -#include "lldb/Core/dwarf.h" #include "lldb/Utility/DataExtractor.h" #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h" @@ -23,13 +22,6 @@ class DWARFDataExtractor : public DataExtractor { lldb::offset_t length) : DataExtractor(data, offset, length) {} - uint64_t GetDWARFInitialLength(lldb::offset_t *offset_ptr) const; - - dw_offset_t GetDWARFOffset(lldb::offset_t *offset_ptr) const; - - size_t GetDWARFSizeofInitialLength() const { return 4; } - size_t GetDWARFSizeOfOffset() const { return 4; } - llvm::DWARFDataExtractor GetAsLLVMDWARF() const; llvm::DataExtractor GetAsLLVM() const; }; `` https://github.com/llvm/llvm-project/pull/146356 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Correctly restore the cursor column after resizing the statusline (PR #146132)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/146132 >From e601025c14fb609635dc6a9adea5b1ae8b8e4540 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 27 Jun 2025 11:08:08 -0700 Subject: [PATCH 1/2] [lldb] Correctly restore the cursor column after resizing the statusline This PR ensures we correctly restore the cursor column after resizing the statusline. To ensure we have space for the statusline, we have to emit a newline to move up everything on screen. The newline causes the cursor to move to the start of the next line, which needs to be undone. Normally, we would use escape codes to save & restore the cursor position, but that doesn't work here, as the cursor position may have (purposely) changed. Instead, we move the cursor up one line using an escape code, but we weren't restoring the column. Interestingly, Editline was able to recover from this issue through the LineInfo struct which contains the buffer and the cursor location, which allows us to compute the column. This PR addresses the bug by having Editline "refresh" the cursor position. Fixes #134064 --- lldb/include/lldb/Core/Debugger.h| 2 ++ lldb/include/lldb/Core/IOHandler.h | 4 lldb/include/lldb/Host/Editline.h| 2 ++ lldb/source/Core/Debugger.cpp| 7 +++ lldb/source/Core/IOHandler.cpp | 7 +++ lldb/source/Core/Statusline.cpp | 19 +++ lldb/source/Host/common/Editline.cpp | 7 +++ 7 files changed, 40 insertions(+), 8 deletions(-) diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h index 2087ef2a11562..504f936fe317a 100644 --- a/lldb/include/lldb/Core/Debugger.h +++ b/lldb/include/lldb/Core/Debugger.h @@ -227,6 +227,8 @@ class Debugger : public std::enable_shared_from_this, const char *GetIOHandlerHelpPrologue(); + void RefreshIOHandler(); + void ClearIOHandlers(); bool EnableLog(llvm::StringRef channel, diff --git a/lldb/include/lldb/Core/IOHandler.h b/lldb/include/lldb/Core/IOHandler.h index 2fb3d7a7c9cc3..2672bbe5da2b3 100644 --- a/lldb/include/lldb/Core/IOHandler.h +++ b/lldb/include/lldb/Core/IOHandler.h @@ -90,6 +90,8 @@ class IOHandler { virtual void TerminalSizeChanged() {} + virtual void Refresh() {} + virtual const char *GetPrompt() { // Prompt support isn't mandatory return nullptr; @@ -404,6 +406,8 @@ class IOHandlerEditline : public IOHandler { void PrintAsync(const char *s, size_t len, bool is_stdout) override; + void Refresh() override; + private: #if LLDB_ENABLE_LIBEDIT bool IsInputCompleteCallback(Editline *editline, StringList &lines); diff --git a/lldb/include/lldb/Host/Editline.h b/lldb/include/lldb/Host/Editline.h index c202a76758e13..947ad3bfe5ec6 100644 --- a/lldb/include/lldb/Host/Editline.h +++ b/lldb/include/lldb/Host/Editline.h @@ -267,6 +267,8 @@ class Editline { size_t GetTerminalHeight() { return m_terminal_height; } + void Refresh(); + private: /// Sets the lowest line number for multi-line editing sessions. A value of /// zero suppresses line number printing in the prompt. diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 445baf1f63785..ed674ee1275c7 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -1445,6 +1445,13 @@ bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) { return true; } +void Debugger::RefreshIOHandler() { + std::lock_guard guard(m_io_handler_stack.GetMutex()); + IOHandlerSP reader_sp(m_io_handler_stack.Top()); + if (reader_sp) +reader_sp->Refresh(); +} + StreamUP Debugger::GetAsyncOutputStream() { return std::make_unique(*this, StreamAsynchronousIO::STDOUT); diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp index 8aac507eaa0c2..f65a1113f3592 100644 --- a/lldb/source/Core/IOHandler.cpp +++ b/lldb/source/Core/IOHandler.cpp @@ -663,3 +663,10 @@ void IOHandlerEditline::PrintAsync(const char *s, size_t len, bool is_stdout) { #endif } } + +void IOHandlerEditline::Refresh() { +#if LLDB_ENABLE_LIBEDIT + if (m_editline_up) +m_editline_up->Refresh(); +#endif +} diff --git a/lldb/source/Core/Statusline.cpp b/lldb/source/Core/Statusline.cpp index 8a8640805cac0..8ec57c9fa5bac 100644 --- a/lldb/source/Core/Statusline.cpp +++ b/lldb/source/Core/Statusline.cpp @@ -103,20 +103,23 @@ void Statusline::UpdateScrollWindow(ScrollWindowMode mode) { (mode == DisableStatusline) ? m_terminal_height : m_terminal_height - 1; LockedStreamFile locked_stream = stream_sp->Lock(); + + if (mode == EnableStatusline) { +// Move everything on the screen up. +locked_stream << '\n'; +locked_stream.Printf(ANSI_UP_ROWS, 1); + } + locked_stream << ANSI_SAVE_CURSOR; locked_stream.Printf(ANSI_SET_SCROLL_ROWS, scroll_height); locked_stream << ANSI_RESTORE_CURSOR; - switch (mode) { - case EnableStatusli
[Lldb-commits] [lldb] [lldb] Correctly restore the cursor column after resizing the statusline (PR #146132)
github-actions[bot] wrote: :warning: Python code formatter, darker found issues in your code. :warning: You can test this locally with the following command: ``bash darker --check --diff -r HEAD~1...HEAD lldb/test/API/functionalities/statusline/TestStatusline.py `` View the diff from darker here. ``diff --- TestStatusline.py 2025-06-30 17:01:06.00 + +++ TestStatusline.py 2025-06-30 17:03:57.611022 + @@ -116,7 +116,5 @@ # Check for the newline followed by the escape code to move the cursor # up one line. self.child.expect(re.escape("\n\x1b[1A")) # Check for the escape code to move the cursor back to column 8. self.child.expect(re.escape("\x1b[8G")) - - `` https://github.com/llvm/llvm-project/pull/146132 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/146062 >From 6ce75177264d47ffedbf0e6ee44831eac1d3ea55 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Fri, 27 Jun 2025 12:49:53 +0100 Subject: [PATCH 1/6] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site --- .../Platform/MacOSX/PlatformDarwin.cpp| 32 +++ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 262a7dc731713..ae46ac63e756a 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1130,13 +1130,33 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( if (target) { if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - auto path_or_err = ResolveSDKPathFromDebugInfo(*exe_module_sp); - if (path_or_err) { -sysroot_spec = FileSpec(*path_or_err); + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); + if (!sym_file) +return; + + XcodeSDK merged_sdk; + for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { +if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { + auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp); + merged_sdk.Merge(cu_sdk); +} + } + + // TODO: The result of this loop is almost equivalent to deriving the SDK + // from the target triple, which would be a lot cheaper. + + if (FileSystem::Instance().Exists(merged_sdk.GetSysroot())) { +sysroot_spec = merged_sdk.GetSysroot(); } else { -LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), - path_or_err.takeError(), - "Failed to resolve SDK path: {0}"); +auto path_or_err = +HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk}); +if (path_or_err) { + sysroot_spec = FileSpec(*path_or_err); +} else { + LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), + path_or_err.takeError(), + "Failed to resolve SDK path: {0}"); +} } } } >From aa2417acc66af5612abb33bf39edc9d2b41478a7 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Mon, 30 Jun 2025 12:22:21 +0100 Subject: [PATCH 2/6] extract to helper method --- .../Platform/MacOSX/PlatformDarwin.cpp| 70 +++ .../Plugins/Platform/MacOSX/PlatformDarwin.h | 3 + 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index ae46ac63e756a..4411c88c97ab2 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1128,37 +1128,8 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( FileSpec sysroot_spec; - if (target) { -if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); - if (!sym_file) -return; - - XcodeSDK merged_sdk; - for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { -if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { - auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp); - merged_sdk.Merge(cu_sdk); -} - } - - // TODO: The result of this loop is almost equivalent to deriving the SDK - // from the target triple, which would be a lot cheaper. - - if (FileSystem::Instance().Exists(merged_sdk.GetSysroot())) { -sysroot_spec = merged_sdk.GetSysroot(); - } else { -auto path_or_err = -HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk}); -if (path_or_err) { - sysroot_spec = FileSpec(*path_or_err); -} else { - LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), - path_or_err.takeError(), - "Failed to resolve SDK path: {0}"); -} - } -} + if (target && ResolveSDKPathFromDebugInfo(target, sysroot_spec)) { +return; } if (!FileSystem::Instance().IsDirectory(sysroot_spec.GetPath())) { @@ -1172,6 +1143,43 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( } } +bool lldb_private::PlatformDarwin::ResolveSDKPathFromDebugInfo( +lldb_private::Target *target, lldb_private::FileSpec &sysroot_spec) { + + ModuleSP exe_module_sp = target->GetExecutableModule(); + if (!exe_module_sp) +return false; + + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); + if (!sym_file) +return true; + + XcodeSDK merged_sdk; + for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { +if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { + auto cu_sdk = sym_file-
[Lldb-commits] [lldb] d7e23be - [lldb][RISCV] fix LR/SC atomic sequence handling in lldb-server (#146072)
Author: dlav-sc Date: 2025-06-30T16:27:44+03:00 New Revision: d7e23bef6ad497cd5a100126957c381e053dda9b URL: https://github.com/llvm/llvm-project/commit/d7e23bef6ad497cd5a100126957c381e053dda9b DIFF: https://github.com/llvm/llvm-project/commit/d7e23bef6ad497cd5a100126957c381e053dda9b.diff LOG: [lldb][RISCV] fix LR/SC atomic sequence handling in lldb-server (#146072) lldb-server had limited support for single-stepping through the lr/sc atomic sequence. This patch enhances that support for all possible atomic sequences. The previous version contained an incorrect regex pattern in the test, causing the riscv-specific test to run on other platforms. This reland fixes the regex (see lldb/test/API/riscv/step/TestSoftwareStep.py) Added: lldb/test/API/riscv/step/Makefile lldb/test/API/riscv/step/TestSoftwareStep.py lldb/test/API/riscv/step/branch.c lldb/test/API/riscv/step/incomplete_sequence_without_lr.c lldb/test/API/riscv/step/incomplete_sequence_without_sc.c lldb/test/API/riscv/step/main.c Modified: lldb/include/lldb/Core/EmulateInstruction.h lldb/source/Core/EmulateInstruction.cpp lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h lldb/source/Plugins/Instruction/LoongArch/EmulateInstructionLoongArch.cpp lldb/source/Plugins/Instruction/LoongArch/EmulateInstructionLoongArch.h lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp lldb/source/Plugins/Process/Utility/NativeProcessSoftwareSingleStep.cpp lldb/source/Plugins/Process/Utility/NativeProcessSoftwareSingleStep.h lldb/unittests/Instruction/LoongArch/TestLoongArchEmulator.cpp Removed: diff --git a/lldb/include/lldb/Core/EmulateInstruction.h b/lldb/include/lldb/Core/EmulateInstruction.h index b459476883fc5..a9fd4543cbbcb 100644 --- a/lldb/include/lldb/Core/EmulateInstruction.h +++ b/lldb/include/lldb/Core/EmulateInstruction.h @@ -22,6 +22,8 @@ #include "lldb/lldb-private-types.h" #include "lldb/lldb-types.h" +#include "llvm/Support/Error.h" + #include #include @@ -32,6 +34,38 @@ class RegisterValue; class Stream; class Target; class UnwindPlan; +class EmulateInstruction; + +using BreakpointLocations = std::vector; + +class SingleStepBreakpointLocationsPredictor { +public: + SingleStepBreakpointLocationsPredictor( + std::unique_ptr emulator_up) + : m_emulator_up{std::move(emulator_up)} {} + + virtual BreakpointLocations GetBreakpointLocations(Status &status); + + virtual llvm::Expected + GetBreakpointSize([[maybe_unused]] lldb::addr_t bp_addr) { +return 4; + } + + virtual ~SingleStepBreakpointLocationsPredictor() = default; + +protected: + // This function retrieves the address of the next instruction as it appears + // in the binary file. Essentially, it reads the value of the PC register, + // determines the size of the current instruction (where the PC is pointing), + // and returns the sum of these two values. + lldb::addr_t GetNextInstructionAddress(Status &error); + + lldb::addr_t GetBreakpointLocationAddress(lldb::addr_t entry_pc, +Status &error); + + std::unique_ptr m_emulator_up; + bool m_emulation_result = false; +}; /// \class EmulateInstruction EmulateInstruction.h /// "lldb/Core/EmulateInstruction.h" @@ -497,7 +531,19 @@ class EmulateInstruction : public PluginInterface { static uint32_t GetInternalRegisterNumber(RegisterContext *reg_ctx, const RegisterInfo ®_info); + static std::unique_ptr + CreateBreakpointLocationPredictor( + std::unique_ptr emulator_up); + + // Helper functions + std::optional ReadPC(); + bool WritePC(lldb::addr_t addr); + protected: + using BreakpointLocationsPredictorCreator = + std::function( + std::unique_ptr)>; + ArchSpec m_arch; void *m_baton = nullptr; ReadMemoryCallback m_read_mem_callback = &ReadMemoryDefault; @@ -508,6 +554,21 @@ class EmulateInstruction : public PluginInterface { Opcode m_opcode; private: + virtual BreakpointLocationsPredictorCreator + GetSingleStepBreakpointLocationsPredictorCreator() { +if (!m_arch.IsMIPS() && !m_arch.GetTriple().isPPC64() && +!m_arch.GetTriple().isLoongArch()) { + // Unsupported architecture + return [](std::unique_ptr emulator_up) { +return nullptr; + }; +} +return [](std::unique_ptr emulator_up) { + return std::make_unique( + std::move(emulator_up)); +}; + } + // For EmulateInstruction only EmulateInstruction(const EmulateInstruction &) = delete; const EmulateInstruction &operator=(const Emulat
[Lldb-commits] [lldb] [lldb] Delete unused DWARFDataExtractor methods (PR #146356)
https://github.com/JDevlieghere approved this pull request. https://github.com/llvm/llvm-project/pull/146356 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/146062 >From b7700480aa7150237f73aa37b0cf39f592ac512d Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Fri, 27 Jun 2025 12:49:53 +0100 Subject: [PATCH 1/6] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site --- .../Platform/MacOSX/PlatformDarwin.cpp| 32 +++ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 262a7dc731713..ae46ac63e756a 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1130,13 +1130,33 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( if (target) { if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - auto path_or_err = ResolveSDKPathFromDebugInfo(*exe_module_sp); - if (path_or_err) { -sysroot_spec = FileSpec(*path_or_err); + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); + if (!sym_file) +return; + + XcodeSDK merged_sdk; + for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { +if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { + auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp); + merged_sdk.Merge(cu_sdk); +} + } + + // TODO: The result of this loop is almost equivalent to deriving the SDK + // from the target triple, which would be a lot cheaper. + + if (FileSystem::Instance().Exists(merged_sdk.GetSysroot())) { +sysroot_spec = merged_sdk.GetSysroot(); } else { -LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), - path_or_err.takeError(), - "Failed to resolve SDK path: {0}"); +auto path_or_err = +HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk}); +if (path_or_err) { + sysroot_spec = FileSpec(*path_or_err); +} else { + LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), + path_or_err.takeError(), + "Failed to resolve SDK path: {0}"); +} } } } >From ae9afb7b786087716fab975dfce2d3b8158f653d Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Mon, 30 Jun 2025 12:22:21 +0100 Subject: [PATCH 2/6] extract to helper method --- .../Platform/MacOSX/PlatformDarwin.cpp| 70 +++ .../Plugins/Platform/MacOSX/PlatformDarwin.h | 3 + 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index ae46ac63e756a..4411c88c97ab2 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1128,37 +1128,8 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( FileSpec sysroot_spec; - if (target) { -if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); - if (!sym_file) -return; - - XcodeSDK merged_sdk; - for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { -if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { - auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp); - merged_sdk.Merge(cu_sdk); -} - } - - // TODO: The result of this loop is almost equivalent to deriving the SDK - // from the target triple, which would be a lot cheaper. - - if (FileSystem::Instance().Exists(merged_sdk.GetSysroot())) { -sysroot_spec = merged_sdk.GetSysroot(); - } else { -auto path_or_err = -HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk}); -if (path_or_err) { - sysroot_spec = FileSpec(*path_or_err); -} else { - LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), - path_or_err.takeError(), - "Failed to resolve SDK path: {0}"); -} - } -} + if (target && ResolveSDKPathFromDebugInfo(target, sysroot_spec)) { +return; } if (!FileSystem::Instance().IsDirectory(sysroot_spec.GetPath())) { @@ -1172,6 +1143,43 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( } } +bool lldb_private::PlatformDarwin::ResolveSDKPathFromDebugInfo( +lldb_private::Target *target, lldb_private::FileSpec &sysroot_spec) { + + ModuleSP exe_module_sp = target->GetExecutableModule(); + if (!exe_module_sp) +return false; + + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); + if (!sym_file) +return true; + + XcodeSDK merged_sdk; + for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { +if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { + auto cu_sdk = sym_file-
[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/145621 >From 79c10b6f6630b3ceaa85af45956aeafdf372b5be Mon Sep 17 00:00:00 2001 From: John Harrison Date: Wed, 25 Jun 2025 18:03:39 -0700 Subject: [PATCH 1/8] [lldb] Adding file and pipe support to lldb_private::MainLoopWindows. This updates MainLoopWindows to support events for reading from a file and a socket type. This unifies both handle types using WaitForMultipleEvents which can listen to both sockets and files for change events. This should allow us to unify how we handle watching files/pipes/sockets on Windows and Posix systems. --- lldb/include/lldb/Host/File.h | 2 + lldb/include/lldb/Host/Socket.h | 2 + .../lldb/Host/windows/MainLoopWindows.h | 3 +- lldb/include/lldb/Utility/IOObject.h | 8 +- lldb/source/Host/common/File.cpp | 18 +++ lldb/source/Host/common/Socket.cpp| 49 +++- .../posix/ConnectionFileDescriptorPosix.cpp | 14 ++- lldb/source/Host/windows/MainLoopWindows.cpp | 116 +- lldb/source/Utility/IOObject.cpp | 9 ++ lldb/unittests/Host/FileTest.cpp | 16 ++- lldb/unittests/Host/MainLoopTest.cpp | 26 11 files changed, 190 insertions(+), 73 deletions(-) diff --git a/lldb/include/lldb/Host/File.h b/lldb/include/lldb/Host/File.h index 9e2d0abe0b1af..36cb192281289 100644 --- a/lldb/include/lldb/Host/File.h +++ b/lldb/include/lldb/Host/File.h @@ -127,6 +127,7 @@ class File : public IOObject { /// \return /// a valid handle or IOObject::kInvalidHandleValue WaitableHandle GetWaitableHandle() override; + bool HasReadableData() override; /// Get the file specification for this file, if possible. /// @@ -400,6 +401,7 @@ class NativeFile : public File { Status Write(const void *buf, size_t &num_bytes) override; Status Close() override; WaitableHandle GetWaitableHandle() override; + bool HasReadableData() override; Status GetFileSpec(FileSpec &file_spec) const override; int GetDescriptor() const override; FILE *GetStream() override; diff --git a/lldb/include/lldb/Host/Socket.h b/lldb/include/lldb/Host/Socket.h index 89953ee7fd5b6..6569e9e6ea818 100644 --- a/lldb/include/lldb/Host/Socket.h +++ b/lldb/include/lldb/Host/Socket.h @@ -158,6 +158,7 @@ class Socket : public IOObject { bool IsValid() const override { return m_socket != kInvalidSocketValue; } WaitableHandle GetWaitableHandle() override; + bool HasReadableData() override; static llvm::Expected DecodeHostAndPort(llvm::StringRef host_and_port); @@ -185,6 +186,7 @@ class Socket : public IOObject { SocketProtocol m_protocol; NativeSocket m_socket; + WaitableHandle m_waitable_handle; bool m_should_close_fd; }; diff --git a/lldb/include/lldb/Host/windows/MainLoopWindows.h b/lldb/include/lldb/Host/windows/MainLoopWindows.h index 3937a24645d95..43b7d13a0e445 100644 --- a/lldb/include/lldb/Host/windows/MainLoopWindows.h +++ b/lldb/include/lldb/Host/windows/MainLoopWindows.h @@ -37,11 +37,10 @@ class MainLoopWindows : public MainLoopBase { void Interrupt() override; private: - void ProcessReadObject(IOObject::WaitableHandle handle); llvm::Expected Poll(); struct FdInfo { -void *event; +lldb::IOObjectSP object_sp; Callback callback; }; llvm::DenseMap m_read_fds; diff --git a/lldb/include/lldb/Utility/IOObject.h b/lldb/include/lldb/Utility/IOObject.h index 8cf42992e7be5..48a8a2076581f 100644 --- a/lldb/include/lldb/Utility/IOObject.h +++ b/lldb/include/lldb/Utility/IOObject.h @@ -14,6 +14,7 @@ #include #include "lldb/lldb-private.h" +#include "lldb/lldb-types.h" namespace lldb_private { @@ -24,9 +25,9 @@ class IOObject { eFDTypeSocket, // Socket requiring send/recv }; - // TODO: On Windows this should be a HANDLE, and wait should use - // WaitForMultipleObjects - typedef int WaitableHandle; + // A handle for integrating with the host event loop model. + using WaitableHandle = lldb::file_t; + static const WaitableHandle kInvalidHandleValue; IOObject(FDType type) : m_fd_type(type) {} @@ -40,6 +41,7 @@ class IOObject { FDType GetFdType() const { return m_fd_type; } virtual WaitableHandle GetWaitableHandle() = 0; + virtual bool HasReadableData() = 0; protected: FDType m_fd_type; diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp index 9aa95ffda44cb..2d33f9e2028c4 100644 --- a/lldb/source/Host/common/File.cpp +++ b/lldb/source/Host/common/File.cpp @@ -118,6 +118,8 @@ IOObject::WaitableHandle File::GetWaitableHandle() { return IOObject::kInvalidHandleValue; } +bool File::HasReadableData() { return false; } + Status File::GetFileSpec(FileSpec &file_spec) const { file_spec.Clear(); return std::error_code(ENOTSUP, std::system_category()); @@ -274,7 +276,23 @@ int NativeFile::GetDescriptor() const { } IOObject::WaitableHandle N
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/146062 >From 6ce75177264d47ffedbf0e6ee44831eac1d3ea55 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Fri, 27 Jun 2025 12:49:53 +0100 Subject: [PATCH 1/4] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site --- .../Platform/MacOSX/PlatformDarwin.cpp| 32 +++ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 262a7dc731713..ae46ac63e756a 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1130,13 +1130,33 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( if (target) { if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - auto path_or_err = ResolveSDKPathFromDebugInfo(*exe_module_sp); - if (path_or_err) { -sysroot_spec = FileSpec(*path_or_err); + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); + if (!sym_file) +return; + + XcodeSDK merged_sdk; + for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { +if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { + auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp); + merged_sdk.Merge(cu_sdk); +} + } + + // TODO: The result of this loop is almost equivalent to deriving the SDK + // from the target triple, which would be a lot cheaper. + + if (FileSystem::Instance().Exists(merged_sdk.GetSysroot())) { +sysroot_spec = merged_sdk.GetSysroot(); } else { -LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), - path_or_err.takeError(), - "Failed to resolve SDK path: {0}"); +auto path_or_err = +HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk}); +if (path_or_err) { + sysroot_spec = FileSpec(*path_or_err); +} else { + LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), + path_or_err.takeError(), + "Failed to resolve SDK path: {0}"); +} } } } >From aa2417acc66af5612abb33bf39edc9d2b41478a7 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Mon, 30 Jun 2025 12:22:21 +0100 Subject: [PATCH 2/4] extract to helper method --- .../Platform/MacOSX/PlatformDarwin.cpp| 70 +++ .../Plugins/Platform/MacOSX/PlatformDarwin.h | 3 + 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index ae46ac63e756a..4411c88c97ab2 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1128,37 +1128,8 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( FileSpec sysroot_spec; - if (target) { -if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); - if (!sym_file) -return; - - XcodeSDK merged_sdk; - for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { -if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { - auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp); - merged_sdk.Merge(cu_sdk); -} - } - - // TODO: The result of this loop is almost equivalent to deriving the SDK - // from the target triple, which would be a lot cheaper. - - if (FileSystem::Instance().Exists(merged_sdk.GetSysroot())) { -sysroot_spec = merged_sdk.GetSysroot(); - } else { -auto path_or_err = -HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk}); -if (path_or_err) { - sysroot_spec = FileSpec(*path_or_err); -} else { - LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), - path_or_err.takeError(), - "Failed to resolve SDK path: {0}"); -} - } -} + if (target && ResolveSDKPathFromDebugInfo(target, sysroot_spec)) { +return; } if (!FileSystem::Instance().IsDirectory(sysroot_spec.GetPath())) { @@ -1172,6 +1143,43 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( } } +bool lldb_private::PlatformDarwin::ResolveSDKPathFromDebugInfo( +lldb_private::Target *target, lldb_private::FileSpec &sysroot_spec) { + + ModuleSP exe_module_sp = target->GetExecutableModule(); + if (!exe_module_sp) +return false; + + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); + if (!sym_file) +return true; + + XcodeSDK merged_sdk; + for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { +if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { + auto cu_sdk = sym_file-
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/146062 >From 6ce75177264d47ffedbf0e6ee44831eac1d3ea55 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Fri, 27 Jun 2025 12:49:53 +0100 Subject: [PATCH 1/5] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site --- .../Platform/MacOSX/PlatformDarwin.cpp| 32 +++ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 262a7dc731713..ae46ac63e756a 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1130,13 +1130,33 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( if (target) { if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - auto path_or_err = ResolveSDKPathFromDebugInfo(*exe_module_sp); - if (path_or_err) { -sysroot_spec = FileSpec(*path_or_err); + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); + if (!sym_file) +return; + + XcodeSDK merged_sdk; + for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { +if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { + auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp); + merged_sdk.Merge(cu_sdk); +} + } + + // TODO: The result of this loop is almost equivalent to deriving the SDK + // from the target triple, which would be a lot cheaper. + + if (FileSystem::Instance().Exists(merged_sdk.GetSysroot())) { +sysroot_spec = merged_sdk.GetSysroot(); } else { -LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), - path_or_err.takeError(), - "Failed to resolve SDK path: {0}"); +auto path_or_err = +HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk}); +if (path_or_err) { + sysroot_spec = FileSpec(*path_or_err); +} else { + LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), + path_or_err.takeError(), + "Failed to resolve SDK path: {0}"); +} } } } >From aa2417acc66af5612abb33bf39edc9d2b41478a7 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Mon, 30 Jun 2025 12:22:21 +0100 Subject: [PATCH 2/5] extract to helper method --- .../Platform/MacOSX/PlatformDarwin.cpp| 70 +++ .../Plugins/Platform/MacOSX/PlatformDarwin.h | 3 + 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index ae46ac63e756a..4411c88c97ab2 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1128,37 +1128,8 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( FileSpec sysroot_spec; - if (target) { -if (ModuleSP exe_module_sp = target->GetExecutableModule()) { - SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); - if (!sym_file) -return; - - XcodeSDK merged_sdk; - for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { -if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { - auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp); - merged_sdk.Merge(cu_sdk); -} - } - - // TODO: The result of this loop is almost equivalent to deriving the SDK - // from the target triple, which would be a lot cheaper. - - if (FileSystem::Instance().Exists(merged_sdk.GetSysroot())) { -sysroot_spec = merged_sdk.GetSysroot(); - } else { -auto path_or_err = -HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk}); -if (path_or_err) { - sysroot_spec = FileSpec(*path_or_err); -} else { - LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), - path_or_err.takeError(), - "Failed to resolve SDK path: {0}"); -} - } -} + if (target && ResolveSDKPathFromDebugInfo(target, sysroot_spec)) { +return; } if (!FileSystem::Instance().IsDirectory(sysroot_spec.GetPath())) { @@ -1172,6 +1143,43 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( } } +bool lldb_private::PlatformDarwin::ResolveSDKPathFromDebugInfo( +lldb_private::Target *target, lldb_private::FileSpec &sysroot_spec) { + + ModuleSP exe_module_sp = target->GetExecutableModule(); + if (!exe_module_sp) +return false; + + SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); + if (!sym_file) +return true; + + XcodeSDK merged_sdk; + for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { +if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { + auto cu_sdk = sym_file-
[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)
@@ -53,6 +54,30 @@ bool DWARFExpressionList::ContainsAddress(lldb::addr_t func_load_addr, return GetExpressionAtAddress(func_load_addr, addr) != nullptr; } +std::optional +DWARFExpressionList::GetExpressionEntryAtAddress(lldb::addr_t func_load_addr, +lldb::addr_t load_addr) const { + if (const DWARFExpression *always = GetAlwaysValidExpr()) { +AddressRange full_range(m_func_file_addr, /*size=*/LLDB_INVALID_ADDRESS); +return DWARFExpressionEntry{full_range, always}; + } + + if (func_load_addr == LLDB_INVALID_ADDRESS) +func_load_addr = m_func_file_addr; + + // translate to file-relative PC adrian-prantl wrote: ```suggestion // Translate to file-relative PC. ``` https://github.com/llvm/llvm-project/pull/144238 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)
@@ -53,6 +54,30 @@ bool DWARFExpressionList::ContainsAddress(lldb::addr_t func_load_addr, return GetExpressionAtAddress(func_load_addr, addr) != nullptr; } +std::optional +DWARFExpressionList::GetExpressionEntryAtAddress(lldb::addr_t func_load_addr, +lldb::addr_t load_addr) const { + if (const DWARFExpression *always = GetAlwaysValidExpr()) { +AddressRange full_range(m_func_file_addr, /*size=*/LLDB_INVALID_ADDRESS); +return DWARFExpressionEntry{full_range, always}; + } + + if (func_load_addr == LLDB_INVALID_ADDRESS) +func_load_addr = m_func_file_addr; + + // translate to file-relative PC + lldb::addr_t file_pc = load_addr - func_load_addr + m_func_file_addr; adrian-prantl wrote: You should be using subOverflow (https://llvm.org/doxygen/MathExtras_8h.html) here to guard against wrap-around. https://github.com/llvm/llvm-project/pull/144238 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
https://github.com/adrian-prantl approved this pull request. LGTM with Michael's comments addressed. https://github.com/llvm/llvm-project/pull/146062 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)
https://github.com/adrian-prantl commented: LGTM with under/overflow checks added. https://github.com/llvm/llvm-project/pull/144238 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][RPC] Upstream lldb-rpc-gen tool (PR #138031)
chelcassanova wrote: `home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/lldb/test/Shell/RPC/Generator/Tests/Output/CheckRPCGenToolByproducts.test.script: line 1: fg: no job control` This means that the test does not recognize the `lldb-rpc-gen` binary. It was working before and the main thing I changed with the last update was to add a CMake option to choose whether or not you'd want to build RPC. This is a cache variable that's set to ON by default, so barring anything else this binary should be built and working. https://github.com/llvm/llvm-project/pull/138031 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Correctly restore the cursor column after resizing the statusline (PR #146132)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/146132 >From e601025c14fb609635dc6a9adea5b1ae8b8e4540 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 27 Jun 2025 11:08:08 -0700 Subject: [PATCH 1/3] [lldb] Correctly restore the cursor column after resizing the statusline This PR ensures we correctly restore the cursor column after resizing the statusline. To ensure we have space for the statusline, we have to emit a newline to move up everything on screen. The newline causes the cursor to move to the start of the next line, which needs to be undone. Normally, we would use escape codes to save & restore the cursor position, but that doesn't work here, as the cursor position may have (purposely) changed. Instead, we move the cursor up one line using an escape code, but we weren't restoring the column. Interestingly, Editline was able to recover from this issue through the LineInfo struct which contains the buffer and the cursor location, which allows us to compute the column. This PR addresses the bug by having Editline "refresh" the cursor position. Fixes #134064 --- lldb/include/lldb/Core/Debugger.h| 2 ++ lldb/include/lldb/Core/IOHandler.h | 4 lldb/include/lldb/Host/Editline.h| 2 ++ lldb/source/Core/Debugger.cpp| 7 +++ lldb/source/Core/IOHandler.cpp | 7 +++ lldb/source/Core/Statusline.cpp | 19 +++ lldb/source/Host/common/Editline.cpp | 7 +++ 7 files changed, 40 insertions(+), 8 deletions(-) diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h index 2087ef2a11562..504f936fe317a 100644 --- a/lldb/include/lldb/Core/Debugger.h +++ b/lldb/include/lldb/Core/Debugger.h @@ -227,6 +227,8 @@ class Debugger : public std::enable_shared_from_this, const char *GetIOHandlerHelpPrologue(); + void RefreshIOHandler(); + void ClearIOHandlers(); bool EnableLog(llvm::StringRef channel, diff --git a/lldb/include/lldb/Core/IOHandler.h b/lldb/include/lldb/Core/IOHandler.h index 2fb3d7a7c9cc3..2672bbe5da2b3 100644 --- a/lldb/include/lldb/Core/IOHandler.h +++ b/lldb/include/lldb/Core/IOHandler.h @@ -90,6 +90,8 @@ class IOHandler { virtual void TerminalSizeChanged() {} + virtual void Refresh() {} + virtual const char *GetPrompt() { // Prompt support isn't mandatory return nullptr; @@ -404,6 +406,8 @@ class IOHandlerEditline : public IOHandler { void PrintAsync(const char *s, size_t len, bool is_stdout) override; + void Refresh() override; + private: #if LLDB_ENABLE_LIBEDIT bool IsInputCompleteCallback(Editline *editline, StringList &lines); diff --git a/lldb/include/lldb/Host/Editline.h b/lldb/include/lldb/Host/Editline.h index c202a76758e13..947ad3bfe5ec6 100644 --- a/lldb/include/lldb/Host/Editline.h +++ b/lldb/include/lldb/Host/Editline.h @@ -267,6 +267,8 @@ class Editline { size_t GetTerminalHeight() { return m_terminal_height; } + void Refresh(); + private: /// Sets the lowest line number for multi-line editing sessions. A value of /// zero suppresses line number printing in the prompt. diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 445baf1f63785..ed674ee1275c7 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -1445,6 +1445,13 @@ bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) { return true; } +void Debugger::RefreshIOHandler() { + std::lock_guard guard(m_io_handler_stack.GetMutex()); + IOHandlerSP reader_sp(m_io_handler_stack.Top()); + if (reader_sp) +reader_sp->Refresh(); +} + StreamUP Debugger::GetAsyncOutputStream() { return std::make_unique(*this, StreamAsynchronousIO::STDOUT); diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp index 8aac507eaa0c2..f65a1113f3592 100644 --- a/lldb/source/Core/IOHandler.cpp +++ b/lldb/source/Core/IOHandler.cpp @@ -663,3 +663,10 @@ void IOHandlerEditline::PrintAsync(const char *s, size_t len, bool is_stdout) { #endif } } + +void IOHandlerEditline::Refresh() { +#if LLDB_ENABLE_LIBEDIT + if (m_editline_up) +m_editline_up->Refresh(); +#endif +} diff --git a/lldb/source/Core/Statusline.cpp b/lldb/source/Core/Statusline.cpp index 8a8640805cac0..8ec57c9fa5bac 100644 --- a/lldb/source/Core/Statusline.cpp +++ b/lldb/source/Core/Statusline.cpp @@ -103,20 +103,23 @@ void Statusline::UpdateScrollWindow(ScrollWindowMode mode) { (mode == DisableStatusline) ? m_terminal_height : m_terminal_height - 1; LockedStreamFile locked_stream = stream_sp->Lock(); + + if (mode == EnableStatusline) { +// Move everything on the screen up. +locked_stream << '\n'; +locked_stream.Printf(ANSI_UP_ROWS, 1); + } + locked_stream << ANSI_SAVE_CURSOR; locked_stream.Printf(ANSI_SET_SCROLL_ROWS, scroll_height); locked_stream << ANSI_RESTORE_CURSOR; - switch (mode) { - case EnableStatusli
[Lldb-commits] [lldb] [lldb] Delete unused DWARFDataExtractor methods (PR #146356)
https://github.com/bulbazord approved this pull request. https://github.com/llvm/llvm-project/pull/146356 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Refactor code extracting timestamp from StructuredData (PR #145954)
https://github.com/bulbazord approved this pull request. https://github.com/llvm/llvm-project/pull/145954 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Refactor code extracting timestamp from StructuredData (PR #145954)
@@ -148,23 +161,12 @@ void TelemetryManager::DispatchClientTelemetry( LLDB_LOG(GetLog(LLDBLog::Object), "Cannot determine client_data from client-telemetry entry"); - int64_t start_time; - if (dict->GetValueForKeyAsInteger("start_time", start_time)) { -client_info.start_time += -std::chrono::nanoseconds(static_cast(start_time)); - } else { -LLDB_LOG(GetLog(LLDBLog::Object), - "Cannot determine start-time from client-telemetry entry"); - } + if (auto maybe_start_time = GetAsNanosec(dict, "start_time")) +client_info.start_time += *maybe_start_time; - int64_t end_time; - if (dict->GetValueForKeyAsInteger("end_time", end_time)) { + if (auto maybe_end_time = GetAsNanosec(dict, "end_time")) { SteadyTimePoint epoch; -client_info.end_time = -epoch + std::chrono::nanoseconds(static_cast(end_time)); - } else { -LLDB_LOG(GetLog(LLDBLog::Object), - "Cannot determine end-time from client-telemetry entry"); +client_info.end_time = epoch + maybe_end_time.value(); bulbazord wrote: ```suggestion client_info.end_time = epoch + *maybe_end_time; ``` https://github.com/llvm/llvm-project/pull/145954 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Refactor code extracting timestamp from StructuredData (PR #145954)
oontvoo wrote: Thanks! https://github.com/llvm/llvm-project/pull/145954 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Refactor code extracting timestamp from StructuredData (PR #145954)
https://github.com/oontvoo updated https://github.com/llvm/llvm-project/pull/145954 >From f4092ed5fda4214bfd2c72f288a6c686315bdc3b Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Thu, 26 Jun 2025 15:18:44 -0400 Subject: [PATCH 1/4] [LLDB][NFC] Refactor code extracting timestamp from StructuredData --- lldb/source/Core/Telemetry.cpp | 34 +++--- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp index 6434b11a63ad4..464c1d4071a73 100644 --- a/lldb/source/Core/Telemetry.cpp +++ b/lldb/source/Core/Telemetry.cpp @@ -119,6 +119,19 @@ llvm::Error TelemetryManager::preDispatch(TelemetryInfo *entry) { return llvm::Error::success(); } +// Helper for extracting time field from a Dictionary. +static std::optional +GetAsNanosec(StructuredData::Dictionary *dict, llvm::StringRef key) { + auto value = dict->GetValueForKey(key); + if (!value->IsValid()) { +LLDB_LOG(GetLog(LLDBLog::Object), + "Cannot determine {0} from client-telemetry entry", key); +return std::nullopt; + } + + return std::chrono::nanoseconds(value->GetUnsignedIntegerValue(0)); +} + void TelemetryManager::DispatchClientTelemetry( const lldb_private::StructuredDataImpl &entry, Debugger *debugger) { if (!m_config->enable_client_telemetry) @@ -148,23 +161,14 @@ void TelemetryManager::DispatchClientTelemetry( LLDB_LOG(GetLog(LLDBLog::Object), "Cannot determine client_data from client-telemetry entry"); - int64_t start_time; - if (dict->GetValueForKeyAsInteger("start_time", start_time)) { -client_info.start_time += -std::chrono::nanoseconds(static_cast(start_time)); - } else { -LLDB_LOG(GetLog(LLDBLog::Object), - "Cannot determine start-time from client-telemetry entry"); - } + auto start_time = GetAsNanosec(dict, "start_time"); + if (start_time.has_value()) +client_info.start_time += start_time.value(); - int64_t end_time; - if (dict->GetValueForKeyAsInteger("end_time", end_time)) { + auto end_time = GetAsNanosec(dict, "end_time"); + if (end_time.has_value()) { SteadyTimePoint epoch; -client_info.end_time = -epoch + std::chrono::nanoseconds(static_cast(end_time)); - } else { -LLDB_LOG(GetLog(LLDBLog::Object), - "Cannot determine end-time from client-telemetry entry"); +client_info.end_time = epoch + end_time.value(); } llvm::StringRef error_msg; >From e299d3416f68c08fdfd6dbee6ee99c3225158658 Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Fri, 27 Jun 2025 11:11:02 -0400 Subject: [PATCH 2/4] Update lldb/source/Core/Telemetry.cpp Co-authored-by: Alex Langford --- lldb/source/Core/Telemetry.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp index 464c1d4071a73..5382c0e090b1b 100644 --- a/lldb/source/Core/Telemetry.cpp +++ b/lldb/source/Core/Telemetry.cpp @@ -161,9 +161,8 @@ void TelemetryManager::DispatchClientTelemetry( LLDB_LOG(GetLog(LLDBLog::Object), "Cannot determine client_data from client-telemetry entry"); - auto start_time = GetAsNanosec(dict, "start_time"); - if (start_time.has_value()) -client_info.start_time += start_time.value(); + if (auto maybe_start_time = GetAsNanosec(dict, "start_time")) + client_info.start_time += *maybe_start_time; auto end_time = GetAsNanosec(dict, "end_time"); if (end_time.has_value()) { >From 0365e814bb7442446f55ace76942b581eb4ebc5a Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Mon, 30 Jun 2025 11:03:23 -0400 Subject: [PATCH 3/4] addressed review comment --- lldb/source/Core/Telemetry.cpp | 7 +++ 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp index 5382c0e090b1b..beeac046d0785 100644 --- a/lldb/source/Core/Telemetry.cpp +++ b/lldb/source/Core/Telemetry.cpp @@ -162,12 +162,11 @@ void TelemetryManager::DispatchClientTelemetry( "Cannot determine client_data from client-telemetry entry"); if (auto maybe_start_time = GetAsNanosec(dict, "start_time")) - client_info.start_time += *maybe_start_time; +client_info.start_time += *maybe_start_time; - auto end_time = GetAsNanosec(dict, "end_time"); - if (end_time.has_value()) { + if (auto maybe_end_time = GetAsNanosec(dict, "end_time")) { SteadyTimePoint epoch; -client_info.end_time = epoch + end_time.value(); +client_info.end_time = epoch + maybe_end_time.value(); } llvm::StringRef error_msg; >From dd52e3dff74e7646366b2e4a745596ea2d9064fd Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Mon, 30 Jun 2025 13:15:45 -0400 Subject: [PATCH 4/4] Update lldb/source/Core/Telemetry.cpp Co-authored-by: Alex Langford --- lldb/source/Core/Telemetry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/C
[Lldb-commits] [lldb] eb904e8 - [lldb] Fix link syntax in docs/use/mcp.md
Author: Jonas Devlieghere Date: 2025-06-30T13:50:32-07:00 New Revision: eb904e857af19abc2ea32ea3be455d96af6902f1 URL: https://github.com/llvm/llvm-project/commit/eb904e857af19abc2ea32ea3be455d96af6902f1 DIFF: https://github.com/llvm/llvm-project/commit/eb904e857af19abc2ea32ea3be455d96af6902f1.diff LOG: [lldb] Fix link syntax in docs/use/mcp.md Added: Modified: lldb/docs/use/mcp.md Removed: diff --git a/lldb/docs/use/mcp.md b/lldb/docs/use/mcp.md index e7e78f7a28c7a..7d4072645966f 100644 --- a/lldb/docs/use/mcp.md +++ b/lldb/docs/use/mcp.md @@ -46,7 +46,7 @@ forward communication over stdio over the network connection. └──┘ └──┘ └──┘ ``` -Configuration example for [Claude Code][https://modelcontextprotocol.io/quickstart/user]: +Configuration example for [Claude Code](https://modelcontextprotocol.io/quickstart/user): ```json { @@ -59,7 +59,7 @@ Configuration example for [Claude Code][https://modelcontextprotocol.io/quicksta } ``` -Configuration example for [Visual Studio Code][https://code.visualstudio.com/docs/copilot/chat/mcp-servers]: +Configuration example for [Visual Studio Code](https://code.visualstudio.com/docs/copilot/chat/mcp-servers): ```json { ___ 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] Fix several bugs in x86_64 Mach-O corefile (PR #146460)
https://github.com/jasonmolenda updated https://github.com/llvm/llvm-project/pull/146460 >From a9b23cc16ca7b3a20ccc7c63e64f840fcbf7da9d Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Mon, 30 Jun 2025 20:26:40 -0700 Subject: [PATCH 1/2] [lldb][Mach-O] Fix several bugs in x86_64 Mach-O corefile reading, and one bug in the new RegisterContextUnifiedCore class. The PR I landed a few days ago to allow Mach-O corefiles to augment their registers with additional per-thread registers in metadata exposed a few bugs in the x86_64 corefile reader when running under different CI environments. It also showed a bug in my RegisterContextUnifiedCore class where I wasn't properly handling lookups of unknown registers (e.g. the LLDB_GENERIC_RA when debugging an intel target). The Mach-O x86_64 corefile support would say that it had fpu & exc registers available in every corefile, regardless of whether they were actually present. It would only read the bytes for the first register flavor in the LC_THREAD, the GPRs, but it read them incorrectly, so sometimes you got more register context than you'd expect. The LC_THREAD register context specifies a flavor and the number of uint32_t words; the ObjectFileMachO method would read that number of uint64_t's, exceeding the GPR register space, but it was followed by FPU and then EXC register space so it didn't crash. If you had a corefile with GPR and EXC register bytes, it would be written into the GPR and then FPU register areas, with zeroes filling out the rest of the context. --- .../ObjectFile/Mach-O/ObjectFileMachO.cpp | 66 --- .../mach-core/RegisterContextUnifiedCore.cpp | 8 ++- 2 files changed, 32 insertions(+), 42 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 4394caf7f31e9..ddb662c374edb 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -184,46 +184,32 @@ class RegisterContextDarwin_x86_64_Mach : public RegisterContextDarwin_x86_64 { SetError(GPRRegSet, Read, -1); SetError(FPURegSet, Read, -1); SetError(EXCRegSet, Read, -1); -bool done = false; -while (!done) { +while (offset < data.GetByteSize()) { int flavor = data.GetU32(&offset); if (flavor == 0) -done = true; - else { -uint32_t i; -uint32_t count = data.GetU32(&offset); -switch (flavor) { -case GPRRegSet: - for (i = 0; i < count; ++i) -(&gpr.rax)[i] = data.GetU64(&offset); - SetError(GPRRegSet, Read, 0); - done = true; - - break; -case FPURegSet: - // TODO: fill in FPU regs - // SetError (FPURegSet, Read, -1); - done = true; - - break; -case EXCRegSet: - exc.trapno = data.GetU32(&offset); - exc.err = data.GetU32(&offset); - exc.faultvaddr = data.GetU64(&offset); - SetError(EXCRegSet, Read, 0); - done = true; - break; -case 7: -case 8: -case 9: - // fancy flavors that encapsulate of the above flavors... - break; - -default: - done = true; - break; -} +break; + uint32_t count = data.GetU32(&offset); + switch (flavor) { + case GPRRegSet: { +uint32_t *gpr_data = reinterpret_cast(&gpr.rax); +for (uint32_t i = 0; i < count; ++i) + gpr_data[i] = data.GetU32(&offset); +SetError(GPRRegSet, Read, 0); + } break; + case FPURegSet: +// TODO: fill in FPU regs +SetError(FPURegSet, Read, -1); +break; + case EXCRegSet: +exc.trapno = data.GetU32(&offset); +exc.err = data.GetU32(&offset); +exc.faultvaddr = data.GetU64(&offset); +SetError(EXCRegSet, Read, 0); +break; + default: +offset += count * 4; +break; } } } @@ -353,11 +339,11 @@ class RegisterContextDarwin_x86_64_Mach : public RegisterContextDarwin_x86_64 { } protected: - int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override { return 0; } + int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) override { return -1; } - int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override { return 0; } + int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) override { return -1; } - int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override { return 0; } + int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) override { return -1; } int DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) override { return 0; diff --git a/lldb/source/Plugins/Process/mach-core/RegisterContextUnifiedCore.cpp b/lldb/source/Plugins/Process/mach-core/RegisterContextUnifiedCore.cpp index 16568f788c202..449f85bc3f52a 100644 --- a/lldb/source/Plugins/Process/m
[Lldb-commits] [lldb] [lldb][Mach-O] Fix several bugs in x86_64 Mach-O corefile (PR #146460)
https://github.com/jasonmolenda closed https://github.com/llvm/llvm-project/pull/146460 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits