[Lldb-commits] [lldb] [lldb] Fix redundant condition in compression type check (NFC) (PR #94841)
https://github.com/xgupta updated https://github.com/llvm/llvm-project/pull/94841 >From 5451d769f36528e9640e665d4124103a6c34bf20 Mon Sep 17 00:00:00 2001 From: Shivam Gupta Date: Sat, 8 Jun 2024 11:14:06 +0530 Subject: [PATCH 1/2] [lldb] Fix redundant condition in compression type check (NFC) The `else if` condition for checking `m_compression_type` is redundant as it matches with a previous `if` condition, making the expression always false. Reported by cppcheck as a possible cut-and-paste error. Caught by cppcheck - lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp:543:35: style: Expression is always false because 'else if' condition matches previous condition at line 535. [multiCondition] Fix #91222 --- .../Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 8a47eed3d7cbe..52bf8533bbd8a 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -540,8 +540,6 @@ bool GDBRemoteCommunication::DecompressPacket() { scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_ZLIB); else if (m_compression_type == CompressionType::LZMA) scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZMA); - else if (m_compression_type == CompressionType::LZFSE) -scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZFSE); if (scratchbuf_size > 0) { m_decompression_scratch = (void*) malloc (scratchbuf_size); m_decompression_scratch_type = m_compression_type; >From dd6b3b57a509088565cb7df178fd3e9d55c7e55e Mon Sep 17 00:00:00 2001 From: Shivam Gupta Date: Sat, 8 Jun 2024 11:24:58 +0530 Subject: [PATCH 2/2] clang format --- .../Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 52bf8533bbd8a..187370eb36cae 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -539,7 +539,8 @@ bool GDBRemoteCommunication::DecompressPacket() { else if (m_compression_type == CompressionType::ZlibDeflate) scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_ZLIB); else if (m_compression_type == CompressionType::LZMA) -scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZMA); +scratchbuf_size = +compression_decode_scratch_buffer_size(COMPRESSION_LZMA); if (scratchbuf_size > 0) { m_decompression_scratch = (void*) malloc (scratchbuf_size); m_decompression_scratch_type = m_compression_type; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Remove redundant condition in watch mask check (NFC) (PR #94842)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Shivam Gupta (xgupta) Changes This issue is reported by cppcheck as a pointless test in the watch mask check. The `else if` condition is opposite to the previous `if` condition, making the expression always true. Caught by cppcheck - lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp:509:25: style: Expression is always true because 'else if' condition is opposite to previous condition at line 505. [multiCondition] Fix #91223 --- Full diff: https://github.com/llvm/llvm-project/pull/94842.diff 1 Files Affected: - (modified) lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp (+1-1) ``diff diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp index 5ad2f7a8e9455..4668c25eab083 100644 --- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp @@ -506,7 +506,7 @@ uint32_t NativeRegisterContextLinux_arm::SetHardwareWatchpoint( return LLDB_INVALID_INDEX32; else if (watch_mask <= 0x02) size = 2; -else if (watch_mask <= 0x04) +else size = 4; addr = addr & (~0x03); `` https://github.com/llvm/llvm-project/pull/94842 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Remove redundant condition in watch mask check (NFC) (PR #94842)
https://github.com/xgupta created https://github.com/llvm/llvm-project/pull/94842 This issue is reported by cppcheck as a pointless test in the watch mask check. The `else if` condition is opposite to the previous `if` condition, making the expression always true. Caught by cppcheck - lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp:509:25: style: Expression is always true because 'else if' condition is opposite to previous condition at line 505. [multiCondition] Fix #91223 >From 12821eca107f3b1b29c5e6d65919322579f8dba8 Mon Sep 17 00:00:00 2001 From: Shivam Gupta Date: Sat, 8 Jun 2024 11:19:45 +0530 Subject: [PATCH] [lldb] Remove redundant condition in watch mask check (NFC) This issue is reported by cppcheck as a pointless test in the watch mask check. The `else if` condition is opposite to the previous `if` condition, making the expression always true. Caught by cppcheck - lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp:509:25: style: Expression is always true because 'else if' condition is opposite to previous condition at line 505. [multiCondition] Fix #91223 --- .../Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp| 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp index 5ad2f7a8e9455..4668c25eab083 100644 --- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp @@ -506,7 +506,7 @@ uint32_t NativeRegisterContextLinux_arm::SetHardwareWatchpoint( return LLDB_INVALID_INDEX32; else if (watch_mask <= 0x02) size = 2; -else if (watch_mask <= 0x04) +else size = 4; addr = addr & (~0x03); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix redundant condition in compression type check (NFC) (PR #94841)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff ac404632f991fc6e7dc75ef553a99676ba8002ce 5451d769f36528e9640e665d4124103a6c34bf20 -- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp `` View the diff from clang-format here. ``diff diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 52bf8533bb..187370eb36 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -539,7 +539,8 @@ bool GDBRemoteCommunication::DecompressPacket() { else if (m_compression_type == CompressionType::ZlibDeflate) scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_ZLIB); else if (m_compression_type == CompressionType::LZMA) -scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZMA); +scratchbuf_size = +compression_decode_scratch_buffer_size(COMPRESSION_LZMA); if (scratchbuf_size > 0) { m_decompression_scratch = (void*) malloc (scratchbuf_size); m_decompression_scratch_type = m_compression_type; `` https://github.com/llvm/llvm-project/pull/94841 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix redundant condition in compression type check (NFC) (PR #94841)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Shivam Gupta (xgupta) Changes The `else if` condition for checking `m_compression_type` is redundant as it matches with a previous `if` condition, making the expression always false. Reported by cppcheck as a possible cut-and-paste error. Caught by cppcheck - lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp:543:35: style: Expression is always false because 'else if' condition matches previous condition at line 535. [multiCondition] Fix #91222 --- Full diff: https://github.com/llvm/llvm-project/pull/94841.diff 1 Files Affected: - (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (-2) ``diff diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 8a47eed3d7cbe..52bf8533bbd8a 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -540,8 +540,6 @@ bool GDBRemoteCommunication::DecompressPacket() { scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_ZLIB); else if (m_compression_type == CompressionType::LZMA) scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZMA); - else if (m_compression_type == CompressionType::LZFSE) -scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZFSE); if (scratchbuf_size > 0) { m_decompression_scratch = (void*) malloc (scratchbuf_size); m_decompression_scratch_type = m_compression_type; `` https://github.com/llvm/llvm-project/pull/94841 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix redundant condition in compression type check (NFC) (PR #94841)
https://github.com/xgupta created https://github.com/llvm/llvm-project/pull/94841 The `else if` condition for checking `m_compression_type` is redundant as it matches with a previous `if` condition, making the expression always false. Reported by cppcheck as a possible cut-and-paste error. Caught by cppcheck - lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp:543:35: style: Expression is always false because 'else if' condition matches previous condition at line 535. [multiCondition] Fix #91222 >From 5451d769f36528e9640e665d4124103a6c34bf20 Mon Sep 17 00:00:00 2001 From: Shivam Gupta Date: Sat, 8 Jun 2024 11:14:06 +0530 Subject: [PATCH] [lldb] Fix redundant condition in compression type check (NFC) The `else if` condition for checking `m_compression_type` is redundant as it matches with a previous `if` condition, making the expression always false. Reported by cppcheck as a possible cut-and-paste error. Caught by cppcheck - lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp:543:35: style: Expression is always false because 'else if' condition matches previous condition at line 535. [multiCondition] Fix #91222 --- .../Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 8a47eed3d7cbe..52bf8533bbd8a 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -540,8 +540,6 @@ bool GDBRemoteCommunication::DecompressPacket() { scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_ZLIB); else if (m_compression_type == CompressionType::LZMA) scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZMA); - else if (m_compression_type == CompressionType::LZFSE) -scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZFSE); if (scratchbuf_size > 0) { m_decompression_scratch = (void*) malloc (scratchbuf_size); m_decompression_scratch_type = m_compression_type; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [llvm] Add support for using foreign type units in .debug_names. (PR #87740)
https://github.com/clayborg edited https://github.com/llvm/llvm-project/pull/87740 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [llvm] Add support for using foreign type units in .debug_names. (PR #87740)
@@ -657,6 +657,42 @@ std::optional DWARFDebugNames::Entry::getLocalTUOffset() const { return NameIdx->getLocalTUOffset(*Index); } +std::optional +DWARFDebugNames::Entry::getForeignTUTypeSignature() const { + std::optional Index = getLocalTUIndex(); + const uint32_t NumLocalTUs = NameIdx->getLocalTUCount(); + if (!Index || *Index < NumLocalTUs) +return std::nullopt; // Invalid TU index or TU index is for a local TU + // The foreign TU index is the TU index minus the number of local TUs. + const uint64_t ForeignTUIndex = *Index - NumLocalTUs; + if (ForeignTUIndex >= NameIdx->getForeignTUCount()) +return std::nullopt; // Invalid foreign TU index. + return NameIdx->getForeignTUSignature(ForeignTUIndex); +} + +std::optional +DWARFDebugNames::Entry::getForeignTUSkeletonCUOffset() const { + // Must have a DW_IDX_type_unit and it must be a foreign type unit. + if (!getForeignTUTypeSignature()) clayborg wrote: Spec states: ``` 6.1.1.4.2 List of CUs The list of CUs immediately follows the header. Each entry in the list is an offset of the corresponding compilation unit in the .debug_info section. In the DWARF-32 format, a section offset is 4 bytes, while in the DWARF-64 format, a section offset is 8 bytes. The total number of entries in the list is given by comp_unit_count. There must be at least one CU. ``` https://github.com/llvm/llvm-project/pull/87740 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)
https://github.com/temyurchenko updated https://github.com/llvm/llvm-project/pull/93913 >From 410c7ba9fb7667dabdfbc48fdbda427401ca8df0 Mon Sep 17 00:00:00 2001 From: Artem Yurchenko <44875844+temyurche...@users.noreply.github.com> Date: Thu, 30 May 2024 16:18:47 -0400 Subject: [PATCH 1/2] [clang][AST] fix ast-print of `extern ` with >=2 declarators (#93131) Problem: the printer used to ignore all but the first declarator for unbraced language linkage declarators. Furthemore, that one would be printed without the final semicolon. Solution: for unbraced case we traverse all declarators via `VisitDeclContext`. Furthermore, in appropriate visitors we query for whether they are a part of the unbraced extern language linkage spec, and if so, print appropriately. --- clang/lib/AST/DeclPrinter.cpp | 55 ++- clang/test/AST/ast-print-language-linkage.cpp | 31 +++ 2 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 clang/test/AST/ast-print-language-linkage.cpp diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 0cf4e64f83b8d..9250a7f6eceb2 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -633,7 +633,7 @@ static void printExplicitSpecifier(ExplicitSpecifier ES, llvm::raw_ostream , Out << Proto; } -static void MaybePrintTagKeywordIfSupressingScopes(PrintingPolicy , +static void maybePrintTagKeywordIfSupressingScopes(PrintingPolicy , QualType T, llvm::raw_ostream ) { StringRef prefix = T->isClassType() ? "class " @@ -643,6 +643,22 @@ static void MaybePrintTagKeywordIfSupressingScopes(PrintingPolicy , Out << prefix; } +/// Return the language of the linkage spec of `D`, if applicable. +/// +/// \Return - "C" if `D` has been declared with unbraced `extern "C"` +/// - "C++" if `D` has been declared with unbraced `extern "C++"` +/// - nullptr in any other case +static const char *tryGetUnbracedLinkageLanguage(const Decl *D) { + const auto *SD = dyn_cast(D->getDeclContext()); + if (!SD || SD->hasBraces()) +return nullptr; + if (SD->getLanguage() == LinkageSpecLanguageIDs::C) +return "C"; + assert(SD->getLanguage() == LinkageSpecLanguageIDs::CXX && + "unknown language in linkage specification"); + return "C++"; +} + void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { if (!D->getDescribedFunctionTemplate() && !D->isFunctionTemplateSpecialization()) { @@ -662,6 +678,11 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { CXXConversionDecl *ConversionDecl = dyn_cast(D); CXXDeductionGuideDecl *GuideDecl = dyn_cast(D); if (!Policy.SuppressSpecifiers) { +if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) { + // the "extern" specifier is implicit + assert(D->getStorageClass() == SC_None); + Out << "extern \"" << Lang << "\" "; +} switch (D->getStorageClass()) { case SC_None: break; case SC_Extern: Out << "extern "; break; @@ -807,7 +828,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { } if (!Policy.SuppressTagKeyword && Policy.SuppressScope && !Policy.SuppressUnwrittenScope) -MaybePrintTagKeywordIfSupressingScopes(Policy, AFT->getReturnType(), +maybePrintTagKeywordIfSupressingScopes(Policy, AFT->getReturnType(), Out); AFT->getReturnType().print(Out, Policy, Proto); Proto.clear(); @@ -932,6 +953,11 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { : D->getASTContext().getUnqualifiedObjCPointerType(D->getType()); if (!Policy.SuppressSpecifiers) { +if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) { + // the "extern" specifier is implicit + assert(D->getStorageClass() == SC_None); + Out << "extern \"" << Lang << "\" "; +} StorageClass SC = D->getStorageClass(); if (SC != SC_None) Out << VarDecl::getStorageClassSpecifierString(SC) << " "; @@ -961,7 +987,7 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { if (!Policy.SuppressTagKeyword && Policy.SuppressScope && !Policy.SuppressUnwrittenScope) -MaybePrintTagKeywordIfSupressingScopes(Policy, T, Out); +maybePrintTagKeywordIfSupressingScopes(Policy, T, Out); printDeclType(T, (isa(D) && Policy.CleanUglifiedParameters && D->getIdentifier()) @@ -1064,6 +1090,8 @@ void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) { prettyPrintAttributes(D); + if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) +Out << "extern \"" << Lang << "\";"; } void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { @@ -1136,22 +1164,21 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { } void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { - const
[Lldb-commits] [lldb] [llvm] Add support for using foreign type units in .debug_names. (PR #87740)
@@ -657,6 +657,42 @@ std::optional DWARFDebugNames::Entry::getLocalTUOffset() const { return NameIdx->getLocalTUOffset(*Index); } +std::optional +DWARFDebugNames::Entry::getForeignTUTypeSignature() const { + std::optional Index = getLocalTUIndex(); + const uint32_t NumLocalTUs = NameIdx->getLocalTUCount(); + if (!Index || *Index < NumLocalTUs) +return std::nullopt; // Invalid TU index or TU index is for a local TU + // The foreign TU index is the TU index minus the number of local TUs. + const uint64_t ForeignTUIndex = *Index - NumLocalTUs; + if (ForeignTUIndex >= NameIdx->getForeignTUCount()) +return std::nullopt; // Invalid foreign TU index. + return NameIdx->getForeignTUSignature(ForeignTUIndex); +} + +std::optional +DWARFDebugNames::Entry::getForeignTUSkeletonCUOffset() const { + // Must have a DW_IDX_type_unit and it must be a foreign type unit. + if (!getForeignTUTypeSignature()) clayborg wrote: How can you end up with a .debug_names table that contains only one type unit? If this can happen, I can modify getForeignTUTypeSignature() to do the right thing. But file would need to have a single foreign or local TU only, and no CUs at all? https://github.com/llvm/llvm-project/pull/87740 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use const reference for range variables to improve performance (NFC) (PR #94840)
https://github.com/xgupta edited https://github.com/llvm/llvm-project/pull/94840 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use const reference for range variables to improve performance (NFC) (PR #94840)
https://github.com/xgupta updated https://github.com/llvm/llvm-project/pull/94840 >From ebfb9d81ccc9d54a03e33b73143753a6d0f008bb Mon Sep 17 00:00:00 2001 From: Shivam Gupta Date: Sat, 8 Jun 2024 10:43:01 +0530 Subject: [PATCH] [lldb] Use const reference for range variables to improve performance (NFC) Cppcheck recommends using a const reference for range variables in a for-each loop. This avoids unnecessary copying of elements, improving performance. Caught by cppcheck - lldb/source/API/SBBreakpoint.cpp:717:22: performance: Range variable 'name' should be declared as const reference. [iterateByValue] lldb/source/API/SBTarget.cpp:1150:15: performance: Range variable 'name' should be declared as const reference. [iterateByValue] lldb/source/Breakpoint/Breakpoint.cpp:888:26: performance: Range variable 'name' should be declared as const reference. [iterateByValue] lldb/source/Breakpoint/BreakpointIDList.cpp:262:26: performance: Range variable 'name' should be declared as const reference. [iterateByValue] Fix #91213 Fix #91217 Fix #91219 Fix #91220 --- lldb/source/API/SBBreakpoint.cpp| 2 +- lldb/source/API/SBTarget.cpp| 2 +- lldb/source/Breakpoint/Breakpoint.cpp | 2 +- lldb/source/Breakpoint/BreakpointIDList.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp index f1fb6f904f5f0..3d908047f9455 100644 --- a/lldb/source/API/SBBreakpoint.cpp +++ b/lldb/source/API/SBBreakpoint.cpp @@ -714,7 +714,7 @@ void SBBreakpoint::GetNames(SBStringList ) { bkpt_sp->GetTarget().GetAPIMutex()); std::vector names_vec; bkpt_sp->GetNames(names_vec); -for (std::string name : names_vec) { +for (const std::string : names_vec) { names.AppendString(name.c_str()); } } diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 962ce9ba83cc7..adb9e645610ba 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -1147,7 +1147,7 @@ void SBTarget::GetBreakpointNames(SBStringList ) { std::vector name_vec; target_sp->GetBreakpointNames(name_vec); -for (auto name : name_vec) +for (const auto : name_vec) names.AppendString(name.c_str()); } } diff --git a/lldb/source/Breakpoint/Breakpoint.cpp b/lldb/source/Breakpoint/Breakpoint.cpp index ae845e92762b9..dc80d435ad444 100644 --- a/lldb/source/Breakpoint/Breakpoint.cpp +++ b/lldb/source/Breakpoint/Breakpoint.cpp @@ -885,7 +885,7 @@ void Breakpoint::GetDescription(Stream *s, lldb::DescriptionLevel level, s->Printf("Names:"); s->EOL(); s->IndentMore(); -for (std::string name : m_name_list) { +for (const std::string : m_name_list) { s->Indent(); s->Printf("%s\n", name.c_str()); } diff --git a/lldb/source/Breakpoint/BreakpointIDList.cpp b/lldb/source/Breakpoint/BreakpointIDList.cpp index 97af1d40eb7a5..5fc9f95a75db1 100644 --- a/lldb/source/Breakpoint/BreakpointIDList.cpp +++ b/lldb/source/Breakpoint/BreakpointIDList.cpp @@ -259,7 +259,7 @@ llvm::Error BreakpointIDList::FindAndReplaceIDRanges( if (!names_found.empty()) { for (BreakpointSP bkpt_sp : target->GetBreakpointList().Breakpoints()) { -for (std::string name : names_found) { +for (const std::string : names_found) { if (bkpt_sp->MatchesName(name.c_str())) { StreamString canonical_id_str; BreakpointID::GetCanonicalReference( ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)
https://github.com/temyurchenko updated https://github.com/llvm/llvm-project/pull/93913 >From f1951f3f2dd322123a1c49221c4252f4ea932242 Mon Sep 17 00:00:00 2001 From: Artem Yurchenko <44875844+temyurche...@users.noreply.github.com> Date: Thu, 30 May 2024 16:18:47 -0400 Subject: [PATCH 1/2] [clang][AST] fix ast-print of `extern ` with >=2 declarators (#93131) Problem: the printer used to ignore all but the first declarator for unbraced language linkage declarators. Furthemore, that one would be printed without the final semicolon. Solution: when there is more than one declarator, we print them in a braced `extern ` block. If the original declaration was unbraced and there is one or less declarator, we omit the braces, but add the semicolon. **N.B.** We are printing braces which were, in some cases, absent from the original CST. If that's an issue, I'll work on it. See the tests for the examples. --- clang/lib/AST/DeclPrinter.cpp | 55 ++- clang/test/AST/ast-print-language-linkage.cpp | 31 +++ 2 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 clang/test/AST/ast-print-language-linkage.cpp diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 0cf4e64f83b8d..9250a7f6eceb2 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -633,7 +633,7 @@ static void printExplicitSpecifier(ExplicitSpecifier ES, llvm::raw_ostream , Out << Proto; } -static void MaybePrintTagKeywordIfSupressingScopes(PrintingPolicy , +static void maybePrintTagKeywordIfSupressingScopes(PrintingPolicy , QualType T, llvm::raw_ostream ) { StringRef prefix = T->isClassType() ? "class " @@ -643,6 +643,22 @@ static void MaybePrintTagKeywordIfSupressingScopes(PrintingPolicy , Out << prefix; } +/// Return the language of the linkage spec of `D`, if applicable. +/// +/// \Return - "C" if `D` has been declared with unbraced `extern "C"` +/// - "C++" if `D` has been declared with unbraced `extern "C++"` +/// - nullptr in any other case +static const char *tryGetUnbracedLinkageLanguage(const Decl *D) { + const auto *SD = dyn_cast(D->getDeclContext()); + if (!SD || SD->hasBraces()) +return nullptr; + if (SD->getLanguage() == LinkageSpecLanguageIDs::C) +return "C"; + assert(SD->getLanguage() == LinkageSpecLanguageIDs::CXX && + "unknown language in linkage specification"); + return "C++"; +} + void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { if (!D->getDescribedFunctionTemplate() && !D->isFunctionTemplateSpecialization()) { @@ -662,6 +678,11 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { CXXConversionDecl *ConversionDecl = dyn_cast(D); CXXDeductionGuideDecl *GuideDecl = dyn_cast(D); if (!Policy.SuppressSpecifiers) { +if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) { + // the "extern" specifier is implicit + assert(D->getStorageClass() == SC_None); + Out << "extern \"" << Lang << "\" "; +} switch (D->getStorageClass()) { case SC_None: break; case SC_Extern: Out << "extern "; break; @@ -807,7 +828,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { } if (!Policy.SuppressTagKeyword && Policy.SuppressScope && !Policy.SuppressUnwrittenScope) -MaybePrintTagKeywordIfSupressingScopes(Policy, AFT->getReturnType(), +maybePrintTagKeywordIfSupressingScopes(Policy, AFT->getReturnType(), Out); AFT->getReturnType().print(Out, Policy, Proto); Proto.clear(); @@ -932,6 +953,11 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { : D->getASTContext().getUnqualifiedObjCPointerType(D->getType()); if (!Policy.SuppressSpecifiers) { +if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) { + // the "extern" specifier is implicit + assert(D->getStorageClass() == SC_None); + Out << "extern \"" << Lang << "\" "; +} StorageClass SC = D->getStorageClass(); if (SC != SC_None) Out << VarDecl::getStorageClassSpecifierString(SC) << " "; @@ -961,7 +987,7 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { if (!Policy.SuppressTagKeyword && Policy.SuppressScope && !Policy.SuppressUnwrittenScope) -MaybePrintTagKeywordIfSupressingScopes(Policy, T, Out); +maybePrintTagKeywordIfSupressingScopes(Policy, T, Out); printDeclType(T, (isa(D) && Policy.CleanUglifiedParameters && D->getIdentifier()) @@ -1064,6 +1090,8 @@ void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) { prettyPrintAttributes(D); + if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) +Out << "extern \"" << Lang << "\";"; } void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { @@ -1136,22
[Lldb-commits] [lldb] [lldb] Use const reference for range variables to improve performance (NFC) (PR #94840)
https://github.com/xgupta edited https://github.com/llvm/llvm-project/pull/94840 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Remove redundant c_str() calls in stream output (NFC) (PR #94839)
https://github.com/clayborg approved this pull request. https://github.com/llvm/llvm-project/pull/94839 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use const reference for range variables to improve performance (NFC) (PR #94840)
https://github.com/xgupta updated https://github.com/llvm/llvm-project/pull/94840 >From 25fb87d4bb4af55e642ec386f104412b39065a83 Mon Sep 17 00:00:00 2001 From: Shivam Gupta Date: Sat, 8 Jun 2024 10:43:01 +0530 Subject: [PATCH] [lldb] Use const reference for range variables to improve performance (NFC) Cppcheck recommends using a const reference for range variables in a for-each loop. This avoids unnecessary copying of elements, improving performance. Caught by cppcheck - lldb/source/API/SBBreakpoint.cpp:717:22: performance: Range variable 'name' should be declared as const reference. [iterateByValue] lldb/source/API/SBTarget.cpp:1150:15: performance: Range variable 'name' should be declared as const reference. [iterateByValue] lldb/source/Breakpoint/Breakpoint.cpp:888:26: performance: Range variable 'name' should be declared as const reference. [iterateByValue] Fix #91213 Fix #91217 Fix #91219 --- lldb/source/API/SBBreakpoint.cpp | 2 +- lldb/source/API/SBTarget.cpp | 2 +- lldb/source/Breakpoint/Breakpoint.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp index f1fb6f904f5f0..3d908047f9455 100644 --- a/lldb/source/API/SBBreakpoint.cpp +++ b/lldb/source/API/SBBreakpoint.cpp @@ -714,7 +714,7 @@ void SBBreakpoint::GetNames(SBStringList ) { bkpt_sp->GetTarget().GetAPIMutex()); std::vector names_vec; bkpt_sp->GetNames(names_vec); -for (std::string name : names_vec) { +for (const std::string : names_vec) { names.AppendString(name.c_str()); } } diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 962ce9ba83cc7..adb9e645610ba 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -1147,7 +1147,7 @@ void SBTarget::GetBreakpointNames(SBStringList ) { std::vector name_vec; target_sp->GetBreakpointNames(name_vec); -for (auto name : name_vec) +for (const auto : name_vec) names.AppendString(name.c_str()); } } diff --git a/lldb/source/Breakpoint/Breakpoint.cpp b/lldb/source/Breakpoint/Breakpoint.cpp index ae845e92762b9..dc80d435ad444 100644 --- a/lldb/source/Breakpoint/Breakpoint.cpp +++ b/lldb/source/Breakpoint/Breakpoint.cpp @@ -885,7 +885,7 @@ void Breakpoint::GetDescription(Stream *s, lldb::DescriptionLevel level, s->Printf("Names:"); s->EOL(); s->IndentMore(); -for (std::string name : m_name_list) { +for (const std::string : m_name_list) { s->Indent(); s->Printf("%s\n", name.c_str()); } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use const reference for range variables to improve performance (NFC) (PR #94840)
https://github.com/clayborg approved this pull request. https://github.com/llvm/llvm-project/pull/94840 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use const reference for range variables to improve performance (NFC) (PR #94840)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Shivam Gupta (xgupta) Changes Cppcheck recommends using a const reference for range variables in a for-each loop. This avoids unnecessary copying of elements, improving performance. Caught by cppcheck - lldb/source/API/SBBreakpoint.cpp:717:22: performance: Range variable 'name' should be declared as const reference. [iterateByValue] Fix #91213 --- Full diff: https://github.com/llvm/llvm-project/pull/94840.diff 1 Files Affected: - (modified) lldb/source/API/SBBreakpoint.cpp (+1-1) ``diff diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp index f1fb6f904f5f0..3d908047f9455 100644 --- a/lldb/source/API/SBBreakpoint.cpp +++ b/lldb/source/API/SBBreakpoint.cpp @@ -714,7 +714,7 @@ void SBBreakpoint::GetNames(SBStringList ) { bkpt_sp->GetTarget().GetAPIMutex()); std::vector names_vec; bkpt_sp->GetNames(names_vec); -for (std::string name : names_vec) { +for (const std::string : names_vec) { names.AppendString(name.c_str()); } } `` https://github.com/llvm/llvm-project/pull/94840 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use const reference for range variables to improve performance (NFC) (PR #94840)
https://github.com/xgupta created https://github.com/llvm/llvm-project/pull/94840 Cppcheck recommends using a const reference for range variables in a for-each loop. This avoids unnecessary copying of elements, improving performance. Caught by cppcheck - lldb/source/API/SBBreakpoint.cpp:717:22: performance: Range variable 'name' should be declared as const reference. [iterateByValue] Fix #91213 >From 2206c6ec4f540b191b0dbf827a58836e35d19174 Mon Sep 17 00:00:00 2001 From: Shivam Gupta Date: Sat, 8 Jun 2024 10:43:01 +0530 Subject: [PATCH] [lldb] Use const reference for range variables to improve performance (NFC) Cppcheck recommends using a const reference for range variables in a for-each loop. This avoids unnecessary copying of elements, improving performance. Caught by cppcheck - lldb/source/API/SBBreakpoint.cpp:717:22: performance: Range variable 'name' should be declared as const reference. [iterateByValue] Fix #91213 --- lldb/source/API/SBBreakpoint.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp index f1fb6f904f5f0..3d908047f9455 100644 --- a/lldb/source/API/SBBreakpoint.cpp +++ b/lldb/source/API/SBBreakpoint.cpp @@ -714,7 +714,7 @@ void SBBreakpoint::GetNames(SBStringList ) { bkpt_sp->GetTarget().GetAPIMutex()); std::vector names_vec; bkpt_sp->GetNames(names_vec); -for (std::string name : names_vec) { +for (const std::string : names_vec) { names.AppendString(name.c_str()); } } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Remove redundant c_str() calls in stream output (NFC) (PR #94839)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Shivam Gupta (xgupta) Changes Passing the result of c_str() to a stream is slow and redundant. This change removes unnecessary c_str() calls and uses the string object directly. Caught by cppcheck - lldb/tools/debugserver/source/JSON.cpp:398:19: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] lldb/tools/debugserver/source/JSON.cpp:408:64: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] lldb/tools/debugserver/source/JSON.cpp:420:54: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] lldb/tools/debugserver/source/JSON.cpp:46:13: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] Fix #91212 --- Full diff: https://github.com/llvm/llvm-project/pull/94839.diff 1 Files Affected: - (modified) lldb/tools/debugserver/source/JSON.cpp (+4-5) ``diff diff --git a/lldb/tools/debugserver/source/JSON.cpp b/lldb/tools/debugserver/source/JSON.cpp index 315c52aafc932..5453d857cb214 100644 --- a/lldb/tools/debugserver/source/JSON.cpp +++ b/lldb/tools/debugserver/source/JSON.cpp @@ -43,7 +43,7 @@ JSONString::JSONString(const std::string ) : JSONValue(JSONValue::Kind::String), m_data(s) {} void JSONString::Write(std::ostream ) { - s << "\"" << json_string_quote_metachars(m_data).c_str() << "\""; + s << "\"" << json_string_quote_metachars(m_data) << "\""; } uint64_t JSONNumber::GetAsUnsigned() const { @@ -395,7 +395,7 @@ JSONParser::Token JSONParser::GetToken(std::string ) { } else { error << "error: got exponent character but no exponent digits at " "offset in float value \"" - << value.c_str() << "\""; + << value << "\""; value = error.str(); return Token::Status; } @@ -405,8 +405,7 @@ JSONParser::Token JSONParser::GetToken(std::string ) { if (got_frac_digits) { return Token::Float; } else { -error << "error: no digits after decimal point \"" << value.c_str() - << "\""; +error << "error: no digits after decimal point \"" << value << "\""; value = error.str(); return Token::Status; } @@ -417,7 +416,7 @@ JSONParser::Token JSONParser::GetToken(std::string ) { // We need at least some integer digits to make an integer return Token::Integer; } else { - error << "error: no digits negate sign \"" << value.c_str() << "\""; + error << "error: no digits negate sign \"" << value << "\""; value = error.str(); return Token::Status; } `` https://github.com/llvm/llvm-project/pull/94839 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Remove redundant c_str() calls in stream output (NFC) (PR #94839)
https://github.com/xgupta created https://github.com/llvm/llvm-project/pull/94839 Passing the result of c_str() to a stream is slow and redundant. This change removes unnecessary c_str() calls and uses the string object directly. Caught by cppcheck - lldb/tools/debugserver/source/JSON.cpp:398:19: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] lldb/tools/debugserver/source/JSON.cpp:408:64: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] lldb/tools/debugserver/source/JSON.cpp:420:54: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] lldb/tools/debugserver/source/JSON.cpp:46:13: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] Fix #91212 >From 530ef9052731a97cec38d5833a3b8c064c70d3da Mon Sep 17 00:00:00 2001 From: Shivam Gupta Date: Sat, 8 Jun 2024 10:31:44 +0530 Subject: [PATCH] [lldb] Remove redundant c_str() calls in stream output (NFC) Passing the result of c_str() to a stream is slow and redundant. This change removes unnecessary c_str() calls and uses the string object directly. Caught by cppcheck - lldb/tools/debugserver/source/JSON.cpp:398:19: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] lldb/tools/debugserver/source/JSON.cpp:408:64: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] lldb/tools/debugserver/source/JSON.cpp:420:54: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] lldb/tools/debugserver/source/JSON.cpp:46:13: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] Fix #91212 --- lldb/tools/debugserver/source/JSON.cpp | 9 - 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lldb/tools/debugserver/source/JSON.cpp b/lldb/tools/debugserver/source/JSON.cpp index 315c52aafc932..5453d857cb214 100644 --- a/lldb/tools/debugserver/source/JSON.cpp +++ b/lldb/tools/debugserver/source/JSON.cpp @@ -43,7 +43,7 @@ JSONString::JSONString(const std::string ) : JSONValue(JSONValue::Kind::String), m_data(s) {} void JSONString::Write(std::ostream ) { - s << "\"" << json_string_quote_metachars(m_data).c_str() << "\""; + s << "\"" << json_string_quote_metachars(m_data) << "\""; } uint64_t JSONNumber::GetAsUnsigned() const { @@ -395,7 +395,7 @@ JSONParser::Token JSONParser::GetToken(std::string ) { } else { error << "error: got exponent character but no exponent digits at " "offset in float value \"" - << value.c_str() << "\""; + << value << "\""; value = error.str(); return Token::Status; } @@ -405,8 +405,7 @@ JSONParser::Token JSONParser::GetToken(std::string ) { if (got_frac_digits) { return Token::Float; } else { -error << "error: no digits after decimal point \"" << value.c_str() - << "\""; +error << "error: no digits after decimal point \"" << value << "\""; value = error.str(); return Token::Status; } @@ -417,7 +416,7 @@ JSONParser::Token JSONParser::GetToken(std::string ) { // We need at least some integer digits to make an integer return Token::Integer; } else { - error << "error: no digits negate sign \"" << value.c_str() << "\""; + error << "error: no digits negate sign \"" << value << "\""; value = error.str(); return Token::Status; } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix string truncation method when substring is the prefix of string (NFC) (PR #94785)
https://github.com/xgupta edited https://github.com/llvm/llvm-project/pull/94785 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix string truncation method when substring is the prefix of string (NFC) (PR #94785)
https://github.com/xgupta edited https://github.com/llvm/llvm-project/pull/94785 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Correct format specifier for sscanf to prevent buffer overflow (NFC) (PR #94783)
https://github.com/xgupta edited https://github.com/llvm/llvm-project/pull/94783 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Correct format specifier for sscanf to prevent buffer overflow (NFC) (PR #94783)
https://github.com/xgupta edited https://github.com/llvm/llvm-project/pull/94783 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix incorrect logical operator in 'if' condition check (NFC) (PR #94779)
https://github.com/xgupta edited https://github.com/llvm/llvm-project/pull/94779 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix incorrect logical operator in 'if' condition check (NFC) (PR #94779)
https://github.com/xgupta edited https://github.com/llvm/llvm-project/pull/94779 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Remove dead code block (NFC) (PR #94775)
https://github.com/xgupta edited https://github.com/llvm/llvm-project/pull/94775 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Remove dead code block (NFC) (PR #94775)
https://github.com/xgupta edited https://github.com/llvm/llvm-project/pull/94775 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
@@ -140,12 +140,16 @@ static cl::opt ClDebugMin("memprof-debug-min", cl::desc("Debug min inst"), static cl::opt ClDebugMax("memprof-debug-max", cl::desc("Debug max inst"), cl::Hidden, cl::init(-1)); +static cl::opt ClHistogram("memprof-histogram", mattweingarten wrote: Use global variable `__memprof_histogram` in IR to set flag in runtime, and got rid of runtime flag. https://github.com/llvm/llvm-project/pull/94264 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
https://github.com/mattweingarten updated https://github.com/llvm/llvm-project/pull/94264 error: too big or took too long to generate ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add the ability for Script based commands to specify their "repeat command" (PR #94823)
https://github.com/jimingham updated https://github.com/llvm/llvm-project/pull/94823 >From c2fea75364a0017be5e59020467d661bd00122ba Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Fri, 7 Jun 2024 17:36:34 -0700 Subject: [PATCH 1/2] Add the ability for Script based commands to specify their "repeat command". Among other things, returning an empty string as the repeat command disables auto-repeat, which can be useful for state-changing commands. --- lldb/bindings/python/python-wrapper.swig | 23 lldb/examples/python/cmdtemplate.py | 6 +- lldb/include/lldb/Interpreter/CommandObject.h | 4 ++ .../lldb/Interpreter/ScriptInterpreter.h | 5 ++ .../source/Commands/CommandObjectCommands.cpp | 26 - lldb/source/Commands/CommandObjectThread.cpp | 2 +- .../Python/SWIGPythonBridge.h | 4 ++ .../Python/ScriptInterpreterPython.cpp| 27 + .../Python/ScriptInterpreterPythonImpl.h | 14 +++-- .../script/add/TestAddParsedCommand.py| 55 +++ .../command/script/add/test_commands.py | 25 - .../Python/PythonTestSuite.cpp| 6 ++ 12 files changed, 187 insertions(+), 10 deletions(-) diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig index 1370afc885d43..bb3c9433e2032 100644 --- a/lldb/bindings/python/python-wrapper.swig +++ b/lldb/bindings/python/python-wrapper.swig @@ -831,6 +831,29 @@ bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommandObject( return true; } +std::optional +lldb_private::python::SWIGBridge::LLDBSwigPythonGetRepeatCommandForScriptedCommand(PyObject *implementor, + std::string ) { + PyErr_Cleaner py_err_cleaner(true); + + PythonObject self(PyRefType::Borrowed, implementor); + auto pfunc = self.ResolveName("get_repeat_command"); + // If not implemented, repeat the exact command. + if (!pfunc.IsAllocated()) +return std::nullopt; + + PythonObject result; + PythonString command_str(command); + result = pfunc(command_str); + + // A return of None is the equivalent of nullopt - means repeat + // the command as is: + if (result.IsNone()) +return std::nullopt; + + return result.Str().GetString().str(); +} + #include "lldb/Interpreter/CommandReturnObject.h" bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallParsedCommandObject( diff --git a/lldb/examples/python/cmdtemplate.py b/lldb/examples/python/cmdtemplate.py index 49a08365268f8..9a96888508b6f 100644 --- a/lldb/examples/python/cmdtemplate.py +++ b/lldb/examples/python/cmdtemplate.py @@ -19,7 +19,7 @@ class FrameStatCommand(ParsedCommand): @classmethod def register_lldb_command(cls, debugger, module_name): -ParsedCommandBase.do_register_cmd(cls, debugger, module_name) +ParsedCommand.do_register_cmd(cls, debugger, module_name) print( 'The "{0}" command has been installed, type "help {0}" or "{0} ' '--help" for detailed help.'.format(cls.program) @@ -72,6 +72,10 @@ def setup_command_definition(self): default = True, ) +def get_repeat_command(self, args): +"""As an example, make the command not auto-repeat:""" +return "" + def get_short_help(self): return "Example command for use in debugging" diff --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h index a641a468b49d2..727ea0d963734 100644 --- a/lldb/include/lldb/Interpreter/CommandObject.h +++ b/lldb/include/lldb/Interpreter/CommandObject.h @@ -296,6 +296,10 @@ class CommandObject : public std::enable_shared_from_this { /// /// \param[in] current_command_args ///The command arguments. + /// + /// \param[in] index + ///This is for internal use - it is how the completion request is tracked + ///in CommandObjectMultiword, and should otherwise be ignored. /// /// \return /// std::nullopt if there is no special repeat command - it will use the diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h b/lldb/include/lldb/Interpreter/ScriptInterpreter.h index 932eaa8b8a4a2..934fd1837fcc0 100644 --- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h +++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h @@ -480,6 +480,11 @@ class ScriptInterpreter : public PluginInterface { const lldb_private::ExecutionContext _ctx) { return false; } + + virtual std::optional GetRepeatCommandForScriptedCommand( + StructuredData::GenericSP impl_obj_sp, Args ) { +return std::nullopt; + } virtual bool RunScriptFormatKeyword(const char *impl_function, Process *process, std::string , diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index f4903e373b086..4144876c0751f 100644 ---
[Lldb-commits] [lldb] Add the ability for Script based commands to specify their "repeat command" (PR #94823)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 435dd9746107e13c2ad019be3bd34815f7d2360d c2fea75364a0017be5e59020467d661bd00122ba -- lldb/include/lldb/Interpreter/CommandObject.h lldb/include/lldb/Interpreter/ScriptInterpreter.h lldb/source/Commands/CommandObjectCommands.cpp lldb/source/Commands/CommandObjectThread.cpp lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp `` View the diff from clang-format here. ``diff diff --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h index 727ea0d963..d48dbcdd5a 100644 --- a/lldb/include/lldb/Interpreter/CommandObject.h +++ b/lldb/include/lldb/Interpreter/CommandObject.h @@ -296,7 +296,7 @@ public: /// /// \param[in] current_command_args ///The command arguments. - /// + /// /// \param[in] index ///This is for internal use - it is how the completion request is tracked ///in CommandObjectMultiword, and should otherwise be ignored. diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h b/lldb/include/lldb/Interpreter/ScriptInterpreter.h index 934fd1837f..ff3306b853 100644 --- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h +++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h @@ -480,9 +480,10 @@ public: const lldb_private::ExecutionContext _ctx) { return false; } - - virtual std::optional GetRepeatCommandForScriptedCommand( - StructuredData::GenericSP impl_obj_sp, Args ) { + + virtual std::optional + GetRepeatCommandForScriptedCommand(StructuredData::GenericSP impl_obj_sp, + Args ) { return std::nullopt; } diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index 4144876c07..c63445b7c8 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -1142,11 +1142,12 @@ public: ScriptedCommandSynchronicity GetSynchronicity() { return m_synchro; } - std::optional GetRepeatCommand(Args , uint32_t index) override { + std::optional GetRepeatCommand(Args , + uint32_t index) override { ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter(); if (!scripter) return std::nullopt; - + return scripter->GetRepeatCommandForScriptedCommand(m_cmd_obj_sp, args); } @@ -1596,9 +1597,9 @@ private: options.ForEach(add_element); return error; } - + size_t GetNumOptions() { return m_num_options; } - + private: struct EnumValueStorage { EnumValueStorage() { @@ -1837,14 +1838,15 @@ public: ScriptedCommandSynchronicity GetSynchronicity() { return m_synchro; } - std::optional GetRepeatCommand(Args , uint32_t index) override { + std::optional GetRepeatCommand(Args , + uint32_t index) override { ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter(); if (!scripter) return std::nullopt; - + return scripter->GetRepeatCommandForScriptedCommand(m_cmd_obj_sp, args); } - + llvm::StringRef GetHelp() override { if (m_fetched_help_short) return CommandObjectParsed::GetHelp(); @@ -1875,16 +1877,15 @@ public: SetHelpLong(docstring); return CommandObjectParsed::GetHelpLong(); } - + Options *GetOptions() override { // CommandObjectParsed requires that a command with no options return // nullptr. if (m_options.GetNumOptions() == 0) return nullptr; -return _options; +return _options; } - protected: void DoExecute(Args , CommandReturnObject ) override { diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h index c94fa7d82a..7ee5dc5b04 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h @@ -219,10 +219,10 @@ public: StructuredDataImpl _impl, lldb_private::CommandReturnObject _retobj, lldb::ExecutionContextRefSP exe_ctx_ref_sp); - + static std::optional LLDBSwigPythonGetRepeatCommandForScriptedCommand(PyObject *implementor, - std::string ); + std::string ); static bool
[Lldb-commits] [lldb] Add the ability for Script based commands to specify their "repeat command" (PR #94823)
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 435dd9746107e13c2ad019be3bd34815f7d2360d...c2fea75364a0017be5e59020467d661bd00122ba lldb/examples/python/cmdtemplate.py lldb/test/API/commands/command/script/add/TestAddParsedCommand.py lldb/test/API/commands/command/script/add/test_commands.py `` View the diff from darker here. ``diff --- test/API/commands/command/script/add/TestAddParsedCommand.py 2024-06-08 00:36:34.00 + +++ test/API/commands/command/script/add/TestAddParsedCommand.py 2024-06-08 00:46:28.088059 + @@ -38,37 +38,38 @@ self.expect("help " + cmd_name, substrs=substrs) def run_one_repeat(self, commands, expected_num_errors): with open(self.stdin_path, "w") as input_handle: input_handle.write(commands) - + in_fileH = open(self.stdin_path, "r") self.dbg.SetInputFileHandle(in_fileH, False) - + out_fileH = open(self.stdout_path, "w") self.dbg.SetOutputFileHandle(out_fileH, False) self.dbg.SetErrorFileHandle(out_fileH, False) - + options = lldb.SBCommandInterpreterRunOptions() options.SetEchoCommands(False) options.SetPrintResults(True) options.SetPrintErrors(True) options.SetAllowRepeats(True) - + n_errors, quit_requested, has_crashed = self.dbg.RunCommandInterpreter( -True, False, options, 0, False, False) - +True, False, options, 0, False, False +) + in_fileH.close() out_fileH.close() - + results = None with open(self.stdout_path, "r") as out_fileH: results = out_fileH.read() print(f"RESULTS:\n{results}\nDONE") self.assertEqual(n_errors, expected_num_errors) - + return results def pycmd_tests(self): source_dir = self.getSourceDir() test_file_path = os.path.join(source_dir, "test_commands.py") @@ -245,10 +246,12 @@ results = self.run_one_repeat("one-arg-no-opt ONE_ARG\n\n", 0) self.assertEqual(results.count("ONE_ARG"), 2, "We did a normal repeat") # two-args adds an argument: results = self.run_one_repeat("two-args FIRST_ARG SECOND_ARG\n\n", 0) -self.assertEqual(results.count("FIRST_ARG"), 2, "Passed first arg to both commands") -self.assertEqual(results.count("SECOND_ARG"), 2, "Passed second arg to both commands") +self.assertEqual( +results.count("FIRST_ARG"), 2, "Passed first arg to both commands" +) +self.assertEqual( +results.count("SECOND_ARG"), 2, "Passed second arg to both commands" +) self.assertEqual(results.count("THIRD_ARG"), 1, "Passed third arg in repeat") - - --- test/API/commands/command/script/add/test_commands.py 2024-06-08 00:36:34.00 + +++ test/API/commands/command/script/add/test_commands.py 2024-06-08 00:46:28.168289 + @@ -207,11 +207,11 @@ def get_repeat_command(self, command): global two_arg_repeat two_arg_repeat = command return command + " THIRD_ARG" - + def get_short_help(self): return "This is my short help string" def get_long_help(self): return self.help_string `` https://github.com/llvm/llvm-project/pull/94823 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add the ability for Script based commands to specify their "repeat command" (PR #94823)
https://github.com/jimingham created https://github.com/llvm/llvm-project/pull/94823 Among other things, returning an empty string as the repeat command disables auto-repeat, which can be useful for state-changing commands. There's one remaining refinement to this setup, which is that for parsed script commands, it should be possible to change an option value, or add a new option value that wasn't originally specified, then ask lldb "make this back into a command string". That would make doing fancy things with repeat commands easier. That capability isn't present in the lldb_private side either, however. So that's for a next iteration. I haven't added this to the docs on adding commands yet. I wanted to make sure this was an acceptable approach before I spend the time to do that. >From c2fea75364a0017be5e59020467d661bd00122ba Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Fri, 7 Jun 2024 17:36:34 -0700 Subject: [PATCH] Add the ability for Script based commands to specify their "repeat command". Among other things, returning an empty string as the repeat command disables auto-repeat, which can be useful for state-changing commands. --- lldb/bindings/python/python-wrapper.swig | 23 lldb/examples/python/cmdtemplate.py | 6 +- lldb/include/lldb/Interpreter/CommandObject.h | 4 ++ .../lldb/Interpreter/ScriptInterpreter.h | 5 ++ .../source/Commands/CommandObjectCommands.cpp | 26 - lldb/source/Commands/CommandObjectThread.cpp | 2 +- .../Python/SWIGPythonBridge.h | 4 ++ .../Python/ScriptInterpreterPython.cpp| 27 + .../Python/ScriptInterpreterPythonImpl.h | 14 +++-- .../script/add/TestAddParsedCommand.py| 55 +++ .../command/script/add/test_commands.py | 25 - .../Python/PythonTestSuite.cpp| 6 ++ 12 files changed, 187 insertions(+), 10 deletions(-) diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig index 1370afc885d43..bb3c9433e2032 100644 --- a/lldb/bindings/python/python-wrapper.swig +++ b/lldb/bindings/python/python-wrapper.swig @@ -831,6 +831,29 @@ bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommandObject( return true; } +std::optional +lldb_private::python::SWIGBridge::LLDBSwigPythonGetRepeatCommandForScriptedCommand(PyObject *implementor, + std::string ) { + PyErr_Cleaner py_err_cleaner(true); + + PythonObject self(PyRefType::Borrowed, implementor); + auto pfunc = self.ResolveName("get_repeat_command"); + // If not implemented, repeat the exact command. + if (!pfunc.IsAllocated()) +return std::nullopt; + + PythonObject result; + PythonString command_str(command); + result = pfunc(command_str); + + // A return of None is the equivalent of nullopt - means repeat + // the command as is: + if (result.IsNone()) +return std::nullopt; + + return result.Str().GetString().str(); +} + #include "lldb/Interpreter/CommandReturnObject.h" bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallParsedCommandObject( diff --git a/lldb/examples/python/cmdtemplate.py b/lldb/examples/python/cmdtemplate.py index 49a08365268f8..9a96888508b6f 100644 --- a/lldb/examples/python/cmdtemplate.py +++ b/lldb/examples/python/cmdtemplate.py @@ -19,7 +19,7 @@ class FrameStatCommand(ParsedCommand): @classmethod def register_lldb_command(cls, debugger, module_name): -ParsedCommandBase.do_register_cmd(cls, debugger, module_name) +ParsedCommand.do_register_cmd(cls, debugger, module_name) print( 'The "{0}" command has been installed, type "help {0}" or "{0} ' '--help" for detailed help.'.format(cls.program) @@ -72,6 +72,10 @@ def setup_command_definition(self): default = True, ) +def get_repeat_command(self, args): +"""As an example, make the command not auto-repeat:""" +return "" + def get_short_help(self): return "Example command for use in debugging" diff --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h index a641a468b49d2..727ea0d963734 100644 --- a/lldb/include/lldb/Interpreter/CommandObject.h +++ b/lldb/include/lldb/Interpreter/CommandObject.h @@ -296,6 +296,10 @@ class CommandObject : public std::enable_shared_from_this { /// /// \param[in] current_command_args ///The command arguments. + /// + /// \param[in] index + ///This is for internal use - it is how the completion request is tracked + ///in CommandObjectMultiword, and should otherwise be ignored. /// /// \return /// std::nullopt if there is no special repeat command - it will use the diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h b/lldb/include/lldb/Interpreter/ScriptInterpreter.h index 932eaa8b8a4a2..934fd1837fcc0 100644 ---
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
https://github.com/jimingham closed https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 435dd97 - Add AllowRepeats to SBCommandInterpreterRunOptions. (#94786)
Author: jimingham Date: 2024-06-07T17:05:29-07:00 New Revision: 435dd9746107e13c2ad019be3bd34815f7d2360d URL: https://github.com/llvm/llvm-project/commit/435dd9746107e13c2ad019be3bd34815f7d2360d DIFF: https://github.com/llvm/llvm-project/commit/435dd9746107e13c2ad019be3bd34815f7d2360d.diff LOG: Add AllowRepeats to SBCommandInterpreterRunOptions. (#94786) This is useful if you have a transcript of a user session and want to rerun those commands with RunCommandInterpreter. The same functionality is also useful in testing. I'm adding it primarily for the second reason. In a subsequent patch, I'm adding the ability to Python based commands to provide their "auto-repeat" command. Among other things, that will allow potentially state destroying user commands to prevent auto-repeat. Testing this with Shell or pexpect tests is not nearly as accurate or convenient as using RunCommandInterpreter, but to use that I need to allow auto-repeat. I think for consistency's sake, having interactive sessions always do auto-repeats is the right choice, though that's a lightly held opinion... Added: Modified: lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i lldb/include/lldb/API/SBCommandInterpreterRunOptions.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/API/SBCommandInterpreterRunOptions.cpp lldb/source/Interpreter/CommandInterpreter.cpp lldb/test/API/python_api/interpreter/TestRunCommandInterpreterAPI.py Removed: diff --git a/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i b/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i index b37da0535d18a..a4398d95ed0d1 100644 --- a/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i +++ b/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i @@ -10,5 +10,8 @@ A default SBCommandInterpreterRunOptions object has: * PrintResults: true * PrintErrors:true * AddToHistory: true +* AllowRepeatsfalse +Interactive debug sessions always allow repeats, the AllowRepeats +run option only affects non-interactive sessions. ") lldb::SBCommandInterpreterRunOptions; diff --git a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h index 69b969267e755..0f248c926d454 100644 --- a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h +++ b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h @@ -72,6 +72,14 @@ class LLDB_API SBCommandInterpreterRunOptions { void SetSpawnThread(bool); + bool GetAllowRepeats() const; + + /// By default, RunCommandInterpreter will discard repeats if the + /// IOHandler being used is not interactive. Setting AllowRepeats to true + /// will override this behavior and always process empty lines in the input + /// as a repeat command. + void SetAllowRepeats(bool); + private: lldb_private::CommandInterpreterRunOptions *get() const; diff --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h index 8863523b2e31f..48f6618ab0e39 100644 --- a/lldb/include/lldb/Interpreter/CommandInterpreter.h +++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -93,15 +93,20 @@ class CommandInterpreterRunOptions { /// \param[in] add_to_history ///If \b true add the commands to the command history. If \b false, don't ///add them. + /// \param[in] handle_repeats + ///If \b true then treat empty lines as repeat commands even if the + ///interpreter is non-interactive. CommandInterpreterRunOptions(LazyBool stop_on_continue, LazyBool stop_on_error, LazyBool stop_on_crash, LazyBool echo_commands, LazyBool echo_comments, LazyBool print_results, LazyBool print_errors, - LazyBool add_to_history) + LazyBool add_to_history, + LazyBool handle_repeats) : m_stop_on_continue(stop_on_continue), m_stop_on_error(stop_on_error), m_stop_on_crash(stop_on_crash), m_echo_commands(echo_commands), m_echo_comment_commands(echo_comments), m_print_results(print_results), -m_print_errors(print_errors), m_add_to_history(add_to_history) {} +m_print_errors(print_errors), m_add_to_history(add_to_history), +m_allow_repeats(handle_repeats) {} CommandInterpreterRunOptions() = default; @@ -183,6 +188,12 @@ class CommandInterpreterRunOptions { m_spawn_thread = spawn_thread ? eLazyBoolYes : eLazyBoolNo; } + bool GetAllowRepeats() const { return DefaultToNo(m_allow_repeats); } + + void SetAllowRepeats(bool allow_repeats) { +m_allow_repeats = allow_repeats ? eLazyBoolYes : eLazyBoolNo; + } + LazyBool m_stop_on_continue = eLazyBoolCalculate; LazyBool
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
@@ -182,6 +187,11 @@ class CommandInterpreterRunOptions { void SetSpawnThread(bool spawn_thread) { m_spawn_thread = spawn_thread ? eLazyBoolYes : eLazyBoolNo; } + bool GetAllowRepeats() const { return DefaultToNo(m_allow_repeats); } jimingham wrote: done https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
https://github.com/jimingham updated https://github.com/llvm/llvm-project/pull/94786 >From bcd8c81c5fbc249886c53d8a2d1bc21a3f9e1ffd Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Fri, 7 Jun 2024 11:17:26 -0700 Subject: [PATCH 1/4] Add AllowRepeats to SBCommandInterpreterRunOptions. This is useful if you have a transcript of a user session and want to rerun those commands with RunCommandInterpreter. The same functionality is also useful in testing. --- ...SBCommandInterpreterRunOptionsDocstrings.i | 3 + .../lldb/API/SBCommandInterpreterRunOptions.h | 8 +++ .../lldb/Interpreter/CommandInterpreter.h | 14 - .../API/SBCommandInterpreterRunOptions.cpp| 12 .../source/Interpreter/CommandInterpreter.cpp | 13 - .../TestRunCommandInterpreterAPI.py | 57 +++ 6 files changed, 91 insertions(+), 16 deletions(-) diff --git a/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i b/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i index b37da0535d18a..a4398d95ed0d1 100644 --- a/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i +++ b/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i @@ -10,5 +10,8 @@ A default SBCommandInterpreterRunOptions object has: * PrintResults: true * PrintErrors:true * AddToHistory: true +* AllowRepeatsfalse +Interactive debug sessions always allow repeats, the AllowRepeats +run option only affects non-interactive sessions. ") lldb::SBCommandInterpreterRunOptions; diff --git a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h index 69b969267e755..b32a8ca51cd08 100644 --- a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h +++ b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h @@ -71,6 +71,14 @@ class LLDB_API SBCommandInterpreterRunOptions { bool GetSpawnThread() const; void SetSpawnThread(bool); + + bool GetAllowRepeats() const; + + // By default, RunCommandInterpreter will discard repeats if the + // IOHandler being used is not interactive. Setting AllowRepeats to true + // will override this behavior and always process empty lines in the input + // as a repeat command. + void SetAllowRepeats(bool); private: lldb_private::CommandInterpreterRunOptions *get() const; diff --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h index 8863523b2e31f..5c2bcd99681a4 100644 --- a/lldb/include/lldb/Interpreter/CommandInterpreter.h +++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -93,15 +93,19 @@ class CommandInterpreterRunOptions { /// \param[in] add_to_history ///If \b true add the commands to the command history. If \b false, don't ///add them. + /// \param[in] process_repeats + ///If \b true then process empty lines as repeat commands even if the + ///interpreter is non-interactive. CommandInterpreterRunOptions(LazyBool stop_on_continue, LazyBool stop_on_error, LazyBool stop_on_crash, LazyBool echo_commands, LazyBool echo_comments, LazyBool print_results, LazyBool print_errors, - LazyBool add_to_history) + LazyBool add_to_history, LazyBool process_repeats) : m_stop_on_continue(stop_on_continue), m_stop_on_error(stop_on_error), m_stop_on_crash(stop_on_crash), m_echo_commands(echo_commands), m_echo_comment_commands(echo_comments), m_print_results(print_results), -m_print_errors(print_errors), m_add_to_history(add_to_history) {} +m_print_errors(print_errors), m_add_to_history(add_to_history), +m_allow_repeats(process_repeats) {} CommandInterpreterRunOptions() = default; @@ -182,6 +186,11 @@ class CommandInterpreterRunOptions { void SetSpawnThread(bool spawn_thread) { m_spawn_thread = spawn_thread ? eLazyBoolYes : eLazyBoolNo; } + bool GetAllowRepeats() const { return DefaultToNo(m_allow_repeats); } + + void SetAllowRepeats(bool allow_repeats) { +m_allow_repeats = allow_repeats ? eLazyBoolYes : eLazyBoolNo; + } LazyBool m_stop_on_continue = eLazyBoolCalculate; LazyBool m_stop_on_error = eLazyBoolCalculate; @@ -193,6 +202,7 @@ class CommandInterpreterRunOptions { LazyBool m_add_to_history = eLazyBoolCalculate; LazyBool m_auto_handle_events; LazyBool m_spawn_thread; + LazyBool m_allow_repeats = eLazyBoolCalculate; private: static bool DefaultToYes(LazyBool flag) { diff --git a/lldb/source/API/SBCommandInterpreterRunOptions.cpp b/lldb/source/API/SBCommandInterpreterRunOptions.cpp index 6c6b2aa15a792..0c7581d6f1f5b 100644 --- a/lldb/source/API/SBCommandInterpreterRunOptions.cpp +++ b/lldb/source/API/SBCommandInterpreterRunOptions.cpp @@ -164,6 +164,18 @@ void SBCommandInterpreterRunOptions::SetSpawnThread(bool
[Lldb-commits] [lldb] [llvm] Add support for using foreign type units in .debug_names. (PR #87740)
@@ -657,6 +657,42 @@ std::optional DWARFDebugNames::Entry::getLocalTUOffset() const { return NameIdx->getLocalTUOffset(*Index); } +std::optional +DWARFDebugNames::Entry::getForeignTUTypeSignature() const { + std::optional Index = getLocalTUIndex(); + const uint32_t NumLocalTUs = NameIdx->getLocalTUCount(); + if (!Index || *Index < NumLocalTUs) +return std::nullopt; // Invalid TU index or TU index is for a local TU + // The foreign TU index is the TU index minus the number of local TUs. + const uint64_t ForeignTUIndex = *Index - NumLocalTUs; + if (ForeignTUIndex >= NameIdx->getForeignTUCount()) +return std::nullopt; // Invalid foreign TU index. + return NameIdx->getForeignTUSignature(ForeignTUIndex); +} + +std::optional +DWARFDebugNames::Entry::getForeignTUSkeletonCUOffset() const { + // Must have a DW_IDX_type_unit and it must be a foreign type unit. + if (!getForeignTUTypeSignature()) ayermolo wrote: I think according to spec if there is only one TU DW_IDX_type_unit is not needed. Just like if there is only one CU. https://github.com/llvm/llvm-project/pull/87740 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [llvm] Add support for using foreign type units in .debug_names. (PR #87740)
clayborg wrote: All feedback has been addressed and this now supports loading accelerator table entries from .dwo files for foreign type units as well. https://github.com/llvm/llvm-project/pull/87740 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [llvm] Add support for using foreign type units in .debug_names. (PR #87740)
https://github.com/clayborg updated https://github.com/llvm/llvm-project/pull/87740 >From c364215cef4d383bf5cb51bf61d442a5bc9fbfe9 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Sat, 30 Mar 2024 10:50:34 -0700 Subject: [PATCH 1/7] Add support for using foreign type units in .debug_names. This patch adds support for the new foreign type unit support in .debug_names. Features include: - don't manually index foreign TUs if we have info for them - only use the type unit entries that match the .dwo files when we have a .dwp file - fix crashers that happen due to PeekDIEName() using wrong offsets --- .../SymbolFile/DWARF/DWARFDebugInfo.cpp | 18 .../Plugins/SymbolFile/DWARF/DWARFDebugInfo.h | 2 + .../SymbolFile/DWARF/DebugNamesDWARFIndex.cpp | 65 - .../SymbolFile/DWARF/DebugNamesDWARFIndex.h | 6 +- .../SymbolFile/DWARF/ManualDWARFIndex.cpp | 6 +- .../SymbolFile/DWARF/ManualDWARFIndex.h | 7 +- .../SymbolFile/DWARF/SymbolFileDWARF.cpp | 66 -- .../SymbolFile/DWARF/SymbolFileDWARF.h| 9 ++ .../DWARF/x86/dwp-foreign-type-units.cpp | 91 +++ .../DebugInfo/DWARF/DWARFAcceleratorTable.h | 11 +++ .../DebugInfo/DWARF/DWARFAcceleratorTable.cpp | 13 +++ 11 files changed, 257 insertions(+), 37 deletions(-) create mode 100644 lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp index c37cc91e08ed1..056c6d4b0605f 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -222,6 +222,20 @@ DWARFUnit *DWARFDebugInfo::GetUnitAtOffset(DIERef::Section section, return result; } +DWARFUnit *DWARFDebugInfo::GetUnit(const DIERef _ref) { + // Make sure we get the correct SymbolFileDWARF from the DIERef before + // asking for information from a debug info object. We might start with the + // DWARFDebugInfo for the main executable in a split DWARF and the DIERef + // might be pointing to a specific .dwo file or to the .dwp file. So this + // makes sure we get the right SymbolFileDWARF instance before finding the + // DWARFUnit that contains the offset. If we just use this object to do the + // search, we might be using the wrong .debug_info section from the wrong + // file with an offset meant for a different section. + SymbolFileDWARF *dwarf = m_dwarf.GetDIERefSymbolFile(die_ref); + return dwarf->DebugInfo().GetUnitContainingDIEOffset(die_ref.section(), + die_ref.die_offset()); +} + DWARFUnit * DWARFDebugInfo::GetUnitContainingDIEOffset(DIERef::Section section, dw_offset_t die_offset) { @@ -232,6 +246,10 @@ DWARFDebugInfo::GetUnitContainingDIEOffset(DIERef::Section section, return result; } +const std::shared_ptr DWARFDebugInfo::GetDwpSymbolFile() { + return m_dwarf.GetDwpSymbolFile(); +} + DWARFTypeUnit *DWARFDebugInfo::GetTypeUnitForHash(uint64_t hash) { auto pos = llvm::lower_bound(m_type_hash_to_unit_index, std::make_pair(hash, 0u), llvm::less_first()); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h index 4706b55d38ea9..4d4555a338252 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h @@ -52,6 +52,8 @@ class DWARFDebugInfo { const DWARFDebugAranges (); + const std::shared_ptr GetDwpSymbolFile(); + protected: typedef std::vector UnitColl; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp index 56717bab1ecd8..a07c454ea7ee3 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -34,6 +34,18 @@ DebugNamesDWARFIndex::Create(Module , DWARFDataExtractor debug_names, module, std::move(index_up), debug_names, debug_str, dwarf)); } + +llvm::DenseSet +DebugNamesDWARFIndex::GetTypeUnitSigs(const DebugNames _names) { + llvm::DenseSet result; + for (const DebugNames::NameIndex : debug_names) { +const uint32_t num_tus = ni.getForeignTUCount(); +for (uint32_t tu = 0; tu < num_tus; ++tu) + result.insert(ni.getForeignTUSignature(tu)); + } + return result; +} + llvm::DenseSet DebugNamesDWARFIndex::GetUnits(const DebugNames _names) { llvm::DenseSet result; @@ -48,17 +60,22 @@ DebugNamesDWARFIndex::GetUnits(const DebugNames _names) { return result; } +DWARFTypeUnit * +DebugNamesDWARFIndex::GetForeignTypeUnit(const DebugNames::Entry ) const { + std::optional type_sig = entry.getForeignTUTypeSignature(); + if (type_sig) +if (auto dwp_sp = m_debug_info.GetDwpSymbolFile()) + return
[Lldb-commits] [lldb] [llvm] Add support for using foreign type units in .debug_names. (PR #87740)
https://github.com/clayborg updated https://github.com/llvm/llvm-project/pull/87740 >From c364215cef4d383bf5cb51bf61d442a5bc9fbfe9 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Sat, 30 Mar 2024 10:50:34 -0700 Subject: [PATCH 1/5] Add support for using foreign type units in .debug_names. This patch adds support for the new foreign type unit support in .debug_names. Features include: - don't manually index foreign TUs if we have info for them - only use the type unit entries that match the .dwo files when we have a .dwp file - fix crashers that happen due to PeekDIEName() using wrong offsets --- .../SymbolFile/DWARF/DWARFDebugInfo.cpp | 18 .../Plugins/SymbolFile/DWARF/DWARFDebugInfo.h | 2 + .../SymbolFile/DWARF/DebugNamesDWARFIndex.cpp | 65 - .../SymbolFile/DWARF/DebugNamesDWARFIndex.h | 6 +- .../SymbolFile/DWARF/ManualDWARFIndex.cpp | 6 +- .../SymbolFile/DWARF/ManualDWARFIndex.h | 7 +- .../SymbolFile/DWARF/SymbolFileDWARF.cpp | 66 -- .../SymbolFile/DWARF/SymbolFileDWARF.h| 9 ++ .../DWARF/x86/dwp-foreign-type-units.cpp | 91 +++ .../DebugInfo/DWARF/DWARFAcceleratorTable.h | 11 +++ .../DebugInfo/DWARF/DWARFAcceleratorTable.cpp | 13 +++ 11 files changed, 257 insertions(+), 37 deletions(-) create mode 100644 lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp index c37cc91e08ed1..056c6d4b0605f 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -222,6 +222,20 @@ DWARFUnit *DWARFDebugInfo::GetUnitAtOffset(DIERef::Section section, return result; } +DWARFUnit *DWARFDebugInfo::GetUnit(const DIERef _ref) { + // Make sure we get the correct SymbolFileDWARF from the DIERef before + // asking for information from a debug info object. We might start with the + // DWARFDebugInfo for the main executable in a split DWARF and the DIERef + // might be pointing to a specific .dwo file or to the .dwp file. So this + // makes sure we get the right SymbolFileDWARF instance before finding the + // DWARFUnit that contains the offset. If we just use this object to do the + // search, we might be using the wrong .debug_info section from the wrong + // file with an offset meant for a different section. + SymbolFileDWARF *dwarf = m_dwarf.GetDIERefSymbolFile(die_ref); + return dwarf->DebugInfo().GetUnitContainingDIEOffset(die_ref.section(), + die_ref.die_offset()); +} + DWARFUnit * DWARFDebugInfo::GetUnitContainingDIEOffset(DIERef::Section section, dw_offset_t die_offset) { @@ -232,6 +246,10 @@ DWARFDebugInfo::GetUnitContainingDIEOffset(DIERef::Section section, return result; } +const std::shared_ptr DWARFDebugInfo::GetDwpSymbolFile() { + return m_dwarf.GetDwpSymbolFile(); +} + DWARFTypeUnit *DWARFDebugInfo::GetTypeUnitForHash(uint64_t hash) { auto pos = llvm::lower_bound(m_type_hash_to_unit_index, std::make_pair(hash, 0u), llvm::less_first()); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h index 4706b55d38ea9..4d4555a338252 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h @@ -52,6 +52,8 @@ class DWARFDebugInfo { const DWARFDebugAranges (); + const std::shared_ptr GetDwpSymbolFile(); + protected: typedef std::vector UnitColl; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp index 56717bab1ecd8..a07c454ea7ee3 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -34,6 +34,18 @@ DebugNamesDWARFIndex::Create(Module , DWARFDataExtractor debug_names, module, std::move(index_up), debug_names, debug_str, dwarf)); } + +llvm::DenseSet +DebugNamesDWARFIndex::GetTypeUnitSigs(const DebugNames _names) { + llvm::DenseSet result; + for (const DebugNames::NameIndex : debug_names) { +const uint32_t num_tus = ni.getForeignTUCount(); +for (uint32_t tu = 0; tu < num_tus; ++tu) + result.insert(ni.getForeignTUSignature(tu)); + } + return result; +} + llvm::DenseSet DebugNamesDWARFIndex::GetUnits(const DebugNames _names) { llvm::DenseSet result; @@ -48,17 +60,22 @@ DebugNamesDWARFIndex::GetUnits(const DebugNames _names) { return result; } +DWARFTypeUnit * +DebugNamesDWARFIndex::GetForeignTypeUnit(const DebugNames::Entry ) const { + std::optional type_sig = entry.getForeignTUTypeSignature(); + if (type_sig) +if (auto dwp_sp = m_debug_info.GetDwpSymbolFile()) + return
[Lldb-commits] [lldb] [lldb][api-test] Add API test for SBCommandInterpreter::CommandOverrideCallback (PR #94518)
https://github.com/chelcassanova updated https://github.com/llvm/llvm-project/pull/94518 >From 4e40f07e424458be6e44cc41d333f38763a0d0fb Mon Sep 17 00:00:00 2001 From: Chelsea Cassanova Date: Wed, 5 Jun 2024 11:24:01 -0700 Subject: [PATCH] [lldb][api-test] Add API test for SBCommandInterpreter::CommandOverrideCallback `SBCommandInterpreter::CommandOverrideCallback` was not being exposed to the Python API has no coverage in the API test suite, so this commits exposes and adds a test for it. Doing this involves also adding a typemap for the callback used for this function so that it matches the functionality of other callback functions that are exposed to Python. --- lldb/bindings/python/python-typemaps.swig | 18 ++- lldb/bindings/python/python-wrapper.swig | 22 + lldb/include/lldb/API/SBCommandInterpreter.h | 2 -- .../TestCommandOverrideCallback.py| 31 +++ 4 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py diff --git a/lldb/bindings/python/python-typemaps.swig b/lldb/bindings/python/python-typemaps.swig index 8d4b740e5f35c..c39594c7df041 100644 --- a/lldb/bindings/python/python-typemaps.swig +++ b/lldb/bindings/python/python-typemaps.swig @@ -427,7 +427,6 @@ template <> bool SetNumberFromPyObject(double , PyObject *obj) { free($1); } - // For Log::LogOutputCallback %typemap(in) (lldb::LogOutputCallback log_callback, void *baton) { if (!($input == Py_None || @@ -476,6 +475,23 @@ template <> bool SetNumberFromPyObject(double , PyObject *obj) { $1 = $1 || PyCallable_Check(reinterpret_cast($input)); } +%typemap(in) (lldb::CommandOverrideCallback callback, void *baton) { + if (!($input == Py_None || +PyCallable_Check(reinterpret_cast($input { +PyErr_SetString(PyExc_TypeError, "Need a callable object or None!"); +SWIG_fail; + } + + // Don't lose the callback reference. + Py_INCREF($input); + $1 = LLDBSwigPythonCallPythonSBCommandInterpreterSetCommandOverrideCallback; + $2 = $input; +} +%typemap(typecheck) (lldb::CommandOverrideCallback callback, void *baton) { + $1 = $input == Py_None; + $1 = $1 || PyCallable_Check(reinterpret_cast($input)); +} + %typemap(in) lldb::FileSP { PythonFile py_file(PyRefType::Borrowed, $input); if (!py_file) { diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig index 1370afc885d43..bd3de8ce5d46c 100644 --- a/lldb/bindings/python/python-wrapper.swig +++ b/lldb/bindings/python/python-wrapper.swig @@ -1099,6 +1099,28 @@ static void LLDBSwigPythonCallPythonSBDebuggerTerminateCallback(lldb::user_id_t } } +static bool LLDBSwigPythonCallPythonSBCommandInterpreterSetCommandOverrideCallback(void *baton, const char **argv) { + bool ret_val = false; + if (baton != Py_None) { +SWIG_PYTHON_THREAD_BEGIN_BLOCK; +// Create a PyList of items since we're going to pass it to the callback as a tuple +// of arguments. +PyObject *py_argv = PyList_New(0); +for (const char **arg = argv; arg && *arg; arg++) { + std::string arg_string = *arg; + PyObject *py_string = PyUnicode_FromStringAndSize(arg_string.c_str(), arg_string.size()); + PyList_Append(py_argv, py_string); +} + +PyObject *result = PyObject_CallObject( +reinterpret_cast(baton), PyList_AsTuple(py_argv)); +ret_val = result ? PyObject_IsTrue(result) : false; +Py_XDECREF(result); +SWIG_PYTHON_THREAD_END_BLOCK; + } + return ret_val; +} + static SBError LLDBSwigPythonCallLocateModuleCallback( void *callback_baton, const SBModuleSpec _spec_sb, SBFileSpec _file_spec_sb, SBFileSpec _file_spec_sb) { diff --git a/lldb/include/lldb/API/SBCommandInterpreter.h b/lldb/include/lldb/API/SBCommandInterpreter.h index 8ac36344b3a79..084b6d9adb703 100644 --- a/lldb/include/lldb/API/SBCommandInterpreter.h +++ b/lldb/include/lldb/API/SBCommandInterpreter.h @@ -265,11 +265,9 @@ class SBCommandInterpreter { // Catch commands before they execute by registering a callback that will get // called when the command gets executed. This allows GUI or command line // interfaces to intercept a command and stop it from happening -#ifndef SWIG bool SetCommandOverrideCallback(const char *command_name, lldb::CommandOverrideCallback callback, void *baton); -#endif /// Return true if the command interpreter is the active IO handler. /// diff --git a/lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py b/lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py new file mode 100644 index 0..a593feb0012d9 --- /dev/null +++ b/lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py @@ -0,0 +1,31 @@ +from typing_extensions import override +import lldb +from lldbsuite.test.decorators import * +from
[Lldb-commits] [lldb] [lldb][api-test] Add API test for SBCommandInterpreter::CommandOverrideCallback (PR #94518)
https://github.com/chelcassanova updated https://github.com/llvm/llvm-project/pull/94518 >From a7215585f55617a41f7c8e566088d3f50203fe55 Mon Sep 17 00:00:00 2001 From: Chelsea Cassanova Date: Wed, 5 Jun 2024 11:24:01 -0700 Subject: [PATCH] [lldb][api-test] Add API test for SBCommandInterpreter::CommandOverrideCallback `SBCommandInterpreter::CommandOverrideCallback` was not being exposed to the Python API has no coverage in the API test suite, so this commits exposes and adds a test for it. Doing this involves also adding a typemap for the callback used for this function so that it matches the functionality of other callback functions that are exposed to Python. --- lldb/bindings/python/python-typemaps.swig | 18 ++- lldb/bindings/python/python-wrapper.swig | 22 ++ lldb/include/lldb/API/SBCommandInterpreter.h | 2 -- .../TestCommandOverrideCallback.py| 30 +++ 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py diff --git a/lldb/bindings/python/python-typemaps.swig b/lldb/bindings/python/python-typemaps.swig index 8d4b740e5f35c..c39594c7df041 100644 --- a/lldb/bindings/python/python-typemaps.swig +++ b/lldb/bindings/python/python-typemaps.swig @@ -427,7 +427,6 @@ template <> bool SetNumberFromPyObject(double , PyObject *obj) { free($1); } - // For Log::LogOutputCallback %typemap(in) (lldb::LogOutputCallback log_callback, void *baton) { if (!($input == Py_None || @@ -476,6 +475,23 @@ template <> bool SetNumberFromPyObject(double , PyObject *obj) { $1 = $1 || PyCallable_Check(reinterpret_cast($input)); } +%typemap(in) (lldb::CommandOverrideCallback callback, void *baton) { + if (!($input == Py_None || +PyCallable_Check(reinterpret_cast($input { +PyErr_SetString(PyExc_TypeError, "Need a callable object or None!"); +SWIG_fail; + } + + // Don't lose the callback reference. + Py_INCREF($input); + $1 = LLDBSwigPythonCallPythonSBCommandInterpreterSetCommandOverrideCallback; + $2 = $input; +} +%typemap(typecheck) (lldb::CommandOverrideCallback callback, void *baton) { + $1 = $input == Py_None; + $1 = $1 || PyCallable_Check(reinterpret_cast($input)); +} + %typemap(in) lldb::FileSP { PythonFile py_file(PyRefType::Borrowed, $input); if (!py_file) { diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig index 1370afc885d43..bd3de8ce5d46c 100644 --- a/lldb/bindings/python/python-wrapper.swig +++ b/lldb/bindings/python/python-wrapper.swig @@ -1099,6 +1099,28 @@ static void LLDBSwigPythonCallPythonSBDebuggerTerminateCallback(lldb::user_id_t } } +static bool LLDBSwigPythonCallPythonSBCommandInterpreterSetCommandOverrideCallback(void *baton, const char **argv) { + bool ret_val = false; + if (baton != Py_None) { +SWIG_PYTHON_THREAD_BEGIN_BLOCK; +// Create a PyList of items since we're going to pass it to the callback as a tuple +// of arguments. +PyObject *py_argv = PyList_New(0); +for (const char **arg = argv; arg && *arg; arg++) { + std::string arg_string = *arg; + PyObject *py_string = PyUnicode_FromStringAndSize(arg_string.c_str(), arg_string.size()); + PyList_Append(py_argv, py_string); +} + +PyObject *result = PyObject_CallObject( +reinterpret_cast(baton), PyList_AsTuple(py_argv)); +ret_val = result ? PyObject_IsTrue(result) : false; +Py_XDECREF(result); +SWIG_PYTHON_THREAD_END_BLOCK; + } + return ret_val; +} + static SBError LLDBSwigPythonCallLocateModuleCallback( void *callback_baton, const SBModuleSpec _spec_sb, SBFileSpec _file_spec_sb, SBFileSpec _file_spec_sb) { diff --git a/lldb/include/lldb/API/SBCommandInterpreter.h b/lldb/include/lldb/API/SBCommandInterpreter.h index 8ac36344b3a79..084b6d9adb703 100644 --- a/lldb/include/lldb/API/SBCommandInterpreter.h +++ b/lldb/include/lldb/API/SBCommandInterpreter.h @@ -265,11 +265,9 @@ class SBCommandInterpreter { // Catch commands before they execute by registering a callback that will get // called when the command gets executed. This allows GUI or command line // interfaces to intercept a command and stop it from happening -#ifndef SWIG bool SetCommandOverrideCallback(const char *command_name, lldb::CommandOverrideCallback callback, void *baton); -#endif /// Return true if the command interpreter is the active IO handler. /// diff --git a/lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py b/lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py new file mode 100644 index 0..9ff16efd82859 --- /dev/null +++ b/lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py @@ -0,0 +1,30 @@ +from typing_extensions import override +import lldb +from lldbsuite.test.decorators import * +from
[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)
@@ -0,0 +1,202 @@ +""" +Test lldb-dap "port" configuration to "attach" request +""" + + +import dap_server +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil +from lldbsuite.test import lldbplatformutil +import lldbdap_testcase +import os +import shutil +import subprocess +import tempfile +import threading +import sys +import socket +import select + + +# A class representing a pipe for communicating with debug server. +# This class includes menthods to open the pipe and read the port number from it. +class Pipe(object): +def __init__(self, prefix): +self.name = os.path.join(prefix, "stub_port_number") +os.mkfifo(self.name) +self._fd = os.open(self.name, os.O_RDONLY | os.O_NONBLOCK) + +def finish_connection(self, timeout): +pass + +def read(self, size, timeout): +(readers, _, _) = select.select([self._fd], [], [], timeout) +if self._fd not in readers: +raise TimeoutError +return os.read(self._fd, size) + +def close(self): +os.close(self._fd) + + +class TestDAP_attachByPortNum(lldbdap_testcase.DAPTestCaseBase): +default_timeout = 20 + +def set_and_hit_breakpoint(self, continueToExit=True): +source = "main.c" +main_source_path = os.path.join(os.getcwd(), source) +breakpoint1_line = line_number(main_source_path, "// breakpoint 1") +lines = [breakpoint1_line] +# Set breakpoint in the thread function so we can step the threads +breakpoint_ids = self.set_source_breakpoints(main_source_path, lines) +self.assertEqual( +len(breakpoint_ids), len(lines), "expect correct number of breakpoints" +) +self.continue_to_breakpoints(breakpoint_ids) +if continueToExit: +self.continue_to_exit() + +def get_debug_server_command_line_args(self): +args = [] +if lldbplatformutil.getPlatform() == "linux": +args = ["gdbserver"] +elif lldbplatformutil.getPlatform() == "macosx": +args = ["--listen"] +if lldb.remote_platform: +args += ["*:0"] +else: +args += ["localhost:0"] +return args + +def get_debug_server_pipe(self): +pipe = Pipe(self.getBuildDir()) +self.addTearDownHook(lambda: pipe.close()) +pipe.finish_connection(self.default_timeout) +return pipe + +@skipIfWindows +@skipIfNetBSD +def test_by_port(self): +""" +Tests attaching to a process by port. +""" +self.build_and_create_debug_adaptor() +program = self.getBuildArtifact("a.out") + +debug_server_tool = self.getBuiltinDebugServerTool() + +pipe = self.get_debug_server_pipe() +args = self.get_debug_server_command_line_args() +args += [program] +args += ["--named-pipe", pipe.name] + +self.process = self.spawnSubprocess( +debug_server_tool, args, install_remote=False +) + +# Read the port number from the debug server pipe. +port = pipe.read(10, self.default_timeout) +# Trim null byte, convert to int +port = int(port[:-1]) +self.assertIsNotNone( +port, " Failed to read the port number from debug server pipe" +) + +self.attach(program=program, gdbRemotePort=port, sourceInitFile=True) +self.set_and_hit_breakpoint(continueToExit=True) +self.process.terminate() + +@skipIfWindows +@skipIfNetBSD +def test_by_port_and_pid(self): +""" +Tests attaching to a process by process ID and port number. +""" +self.build_and_create_debug_adaptor() +program = self.getBuildArtifact("a.out") + +debug_server_tool = self.getBuiltinDebugServerTool() +pipe = self.get_debug_server_pipe() +args = self.get_debug_server_command_line_args() +args += [program] +args += ["--named-pipe", pipe.name] + +self.process = self.spawnSubprocess( +debug_server_tool, args, install_remote=False +) + +# Read the port number from the debug server pipe. +port = pipe.read(10, self.default_timeout) +# Trim null byte, convert to int +port = int(port[:-1]) santhoshe447 wrote: Even if I remove that it does not impact much. https://github.com/llvm/llvm-project/pull/91570 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)
https://github.com/santhoshe447 updated https://github.com/llvm/llvm-project/pull/91570 >From 960351c9abf51f42d92604ac6297aa5b76ddfba5 Mon Sep 17 00:00:00 2001 From: Santhosh Kumar Ellendula Date: Fri, 17 Nov 2023 15:09:10 +0530 Subject: [PATCH 01/14] [lldb][test] Add the ability to extract the variable value out of the summary. --- .../Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index 9d79872b029a3..0cf9d4fde4948 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -195,6 +195,9 @@ def collect_console(self, duration): def get_local_as_int(self, name, threadId=None): value = self.dap_server.get_local_variable_value(name, threadId=threadId) +# 'value' may have the variable value and summary. +# Extract the variable value since summary can have nonnumeric characters. +value = value.split(" ")[0] if value.startswith("0x"): return int(value, 16) elif value.startswith("0"): >From ab44a6991c5bc8ac5764c3f71cbe3acc747b3776 Mon Sep 17 00:00:00 2001 From: Santhosh Kumar Ellendula Date: Fri, 3 May 2024 02:47:05 -0700 Subject: [PATCH 02/14] [lldb-dap] Added "port" property to vscode "attach" command. Adding a "port" property to the VsCode "attach" command likely extends the functionality of the debugger configuratiuon to allow attaching to a process using PID or PORT number. Currently, the "Attach" configuration lets the user specify a pid. We tell the user to use the attachCommands property to run "gdb-remote ". Followed the below conditions for "attach" command with "port" and "pid" We should add a "port" property. If port is specified and pid is not, use that port to attach. If both port and pid are specified, return an error saying that the user can't specify both pid and port. Ex - launch.json { "version": "0.2.0", "configurations": [ { "name": "lldb-dap Debug", "type": "lldb-dap", "request": "attach", "port":1234, "program": "${workspaceFolder}/a.out", "args": [], "stopOnEntry": false, "cwd": "${workspaceFolder}", "env": [], } ] } --- lldb/include/lldb/lldb-defines.h | 1 + .../Python/lldbsuite/test/lldbtest.py | 9 ++ .../test/tools/lldb-dap/dap_server.py | 6 + .../test/tools/lldb-dap/lldbdap_testcase.py | 20 +++ .../attach/TestDAP_attachByPortNum.py | 120 ++ lldb/tools/lldb-dap/lldb-dap.cpp | 36 +- lldb/tools/lldb-dap/package.json | 11 ++ 7 files changed, 199 insertions(+), 4 deletions(-) create mode 100644 lldb/test/API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py diff --git a/lldb/include/lldb/lldb-defines.h b/lldb/include/lldb/lldb-defines.h index c7bd019c5c90e..a1e6ee2ce468c 100644 --- a/lldb/include/lldb/lldb-defines.h +++ b/lldb/include/lldb/lldb-defines.h @@ -96,6 +96,7 @@ #define LLDB_INVALID_QUEUE_ID 0 #define LLDB_INVALID_CPU_ID UINT32_MAX #define LLDB_INVALID_WATCHPOINT_RESOURCE_ID UINT32_MAX +#define LLDB_INVALID_PORT_NUMBER 0 /// CPU Type definitions #define LLDB_ARCH_DEFAULT "systemArch" diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py index 5fd686c143e9f..fb3cd22959df2 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -1572,6 +1572,15 @@ def findBuiltClang(self): return os.environ["CC"] +def getBuiltServerTool(self, server_tool): +# Tries to find simulation/lldb-server/gdbserver tool at the same folder as the lldb. +lldb_dir = os.path.dirname(lldbtest_config.lldbExec) +path = shutil.which(server_tool, path=lldb_dir) +if path is not None: +return path + +return "" + def yaml2obj(self, yaml_path, obj_path, max_size=None): """ Create an object file at the given path from a yaml file. diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py index 5838281bcb1a1..96d312565f953 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py @@ -568,6 +568,8 @@ def request_attach( coreFile=None, postRunCommands=None, sourceMap=None, +port=None, +hostname=None ): args_dict = {} if pid is not None: @@ -597,6 +599,10 @@ def request_attach( args_dict["postRunCommands"] =
[Lldb-commits] [lldb] [lldb][api-test] Add API test for SBCommandInterpreter::CommandOverrideCallback (PR #94518)
@@ -0,0 +1,27 @@ +from typing_extensions import override +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class CommandOverrideCallback(TestBase): +def setUp(self): +TestBase.setUp(self) +self.line = line_number("main.c", "Hello world.") + +def test_command_override_callback(self): +self.build() +exe = self.getBuildArtifact("a.out") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +ci = self.dbg.GetCommandInterpreter() +self.assertTrue(ci, VALID_COMMAND_INTERPRETER) + +def foo(*command_args): +pass + +self.assertTrue(ci.SetCommandOverrideCallback("breakpoint set", foo)) +self.expect("breakpoint set -n main", substrs=["Breakpoint"]) JDevlieghere wrote: This doesn't test the baton or the fact that the function was called. You should have the foo callback modify a variable or something and verify that the function has been called. https://github.com/llvm/llvm-project/pull/94518 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][api-test] Add API test for SBCommandInterpreter::CommandOverrideCallback (PR #94518)
@@ -476,6 +475,23 @@ template <> bool SetNumberFromPyObject(double , PyObject *obj) { $1 = $1 || PyCallable_Check(reinterpret_cast($input)); } +%typemap(in) (lldb::CommandOverrideCallback callback, void *baton) { + if (!($input == Py_None || +PyCallable_Check(reinterpret_cast($input { +PyErr_SetString(PyExc_TypeError, "Need a callable object or None!"); +SWIG_fail; + } + + // Don't lose the callback reference JDevlieghere wrote: Nit: missing period. https://github.com/llvm/llvm-project/pull/94518 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][api-test] Add API test for SBCommandInterpreter::CommandOverrideCallback (PR #94518)
https://github.com/JDevlieghere requested changes to this pull request. https://github.com/llvm/llvm-project/pull/94518 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][api-test] Add API test for SBCommandInterpreter::CommandOverrideCallback (PR #94518)
https://github.com/JDevlieghere edited https://github.com/llvm/llvm-project/pull/94518 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)
@@ -749,9 +755,27 @@ void request_attach(const llvm::json::Object ) { // Disable async events so the attach will be successful when we return from // the launch call and the launch will happen synchronously g_dap.debugger.SetAsync(false); -if (core_file.empty()) - g_dap.target.Attach(attach_info, error); -else +if (core_file.empty()) { + if ((pid != LLDB_INVALID_PROCESS_ID) && + (gdb_remote_port != invalid_port)) { +// If both pid and port numbers are specified. +error.SetErrorString("The user can't specify both pid and port"); + } else if (gdb_remote_port != invalid_port) { +// If port is specified and pid is not. +lldb::SBListener listener = g_dap.debugger.GetListener(); + +// If the user hasn't provided the hostname property, default localhost +// being used. +std::string connect_url = +llvm::formatv("connect://{0}:", gdb_remote_hostname.data()); +connect_url += std::to_string(gdb_remote_port); clayborg wrote: Probably best to format this all in one go and think the llvm::formatv supports std:strings already, so you might be able to remove the `.data()` and then format the port in the same call: ``` std::string connect_url = llvm::formatv("connect://{0}:{1}", gdb_remote_hostname, gdb_remote_port); ``` https://github.com/llvm/llvm-project/pull/91570 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)
@@ -672,9 +672,14 @@ void request_attach(const llvm::json::Object ) { lldb::SBError error; FillResponse(request, response); lldb::SBAttachInfo attach_info; + const int invalid_port = 0; auto arguments = request.getObject("arguments"); const lldb::pid_t pid = GetUnsigned(arguments, "pid", LLDB_INVALID_PROCESS_ID); + const auto gdb_remote_port = + GetUnsigned(arguments, "gdb-remote-port", invalid_port); + llvm::StringRef gdb_remote_hostname = + GetString(arguments, "gdb-remote-hostname", "localhost"); clayborg wrote: I know in the past we have used `127.0.0.1` instead of `localhost`. The reason is people can modify their config files in their environment and `localhost` can be aliased to something else. Not sure if this is an issue https://github.com/llvm/llvm-project/pull/91570 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)
https://github.com/clayborg commented: The code looks good, a few nits in comments. @labath: did we resolve the port race condition testing issue? We really don't want this to be a flaky test on overloaded systems. It would be nice to make sure this is solid before getting this in. https://github.com/llvm/llvm-project/pull/91570 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)
https://github.com/clayborg edited https://github.com/llvm/llvm-project/pull/91570 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use `Address` to setup breakpoint (PR #94794)
@@ -90,17 +90,9 @@ void InstrumentationRuntimeASanLibsanitizers::Activate() { if (!process_sp) return; - lldb::ModuleSP module_sp = GetRuntimeModuleSP(); - Breakpoint *breakpoint = ReportRetriever::SetupBreakpoint( - module_sp, process_sp, ConstString("sanitizers_address_on_report")); - - if (!breakpoint) { -breakpoint = ReportRetriever::SetupBreakpoint( -module_sp, process_sp, -ConstString("_Z22raise_sanitizers_error23sanitizer_error_context")); usama54321 wrote: Yes that should be fine https://github.com/llvm/llvm-project/pull/94794 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)
@@ -0,0 +1,202 @@ +""" +Test lldb-dap "port" configuration to "attach" request +""" + + +import dap_server +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil +from lldbsuite.test import lldbplatformutil +import lldbdap_testcase +import os +import shutil +import subprocess +import tempfile +import threading +import sys +import socket +import select + + +# A class representing a pipe for communicating with debug server. +# This class includes menthods to open the pipe and read the port number from it. +class Pipe(object): +def __init__(self, prefix): +self.name = os.path.join(prefix, "stub_port_number") +os.mkfifo(self.name) +self._fd = os.open(self.name, os.O_RDONLY | os.O_NONBLOCK) + +def finish_connection(self, timeout): +pass + +def read(self, size, timeout): +(readers, _, _) = select.select([self._fd], [], [], timeout) +if self._fd not in readers: +raise TimeoutError +return os.read(self._fd, size) + +def close(self): +os.close(self._fd) santhoshe447 wrote: If I make it common it will create more confusion. https://github.com/llvm/llvm-project/pull/91570 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [llvm] [lldb] Encode operands and arity in Dwarf.def and use them in LLDB. (PR #94679)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/94679 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 96d01a3 - [lldb] Encode operands and arity in Dwarf.def and use them in LLDB. (#94679)
Author: Jonas Devlieghere Date: 2024-06-07T13:48:17-07:00 New Revision: 96d01a350ce9875a8f893ecdc1d470caf7ed5bcd URL: https://github.com/llvm/llvm-project/commit/96d01a350ce9875a8f893ecdc1d470caf7ed5bcd DIFF: https://github.com/llvm/llvm-project/commit/96d01a350ce9875a8f893ecdc1d470caf7ed5bcd.diff LOG: [lldb] Encode operands and arity in Dwarf.def and use them in LLDB. (#94679) This PR extends Dwarf.def to include the number of operands and the arity (the number of entries on the DWARF stack). - The arity is used in LLDB's DWARF expression evaluator. - The number of operands is unused, but is present in the table to avoid confusing the arity with the operands. Keeping the latter up to date should be straightforward as it maps directly to a table present in the DWARF standard. Added: Modified: lldb/source/Expression/DWARFExpression.cpp llvm/include/llvm/BinaryFormat/Dwarf.def llvm/include/llvm/BinaryFormat/Dwarf.h llvm/include/llvm/ObjectYAML/DWARFYAML.h llvm/lib/BinaryFormat/Dwarf.cpp Removed: diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp index 05767a8d02ff2..444e44b392891 100644 --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -888,6 +888,14 @@ llvm::Expected DWARFExpression::Evaluate( DW_OP_value_to_name(op)); } +if (std::optional arity = +llvm::dwarf::OperationArity(static_cast(op))) { + if (stack.size() < *arity) +return llvm::createStringError( +"%s needs at least %d stack entries (stack has %d entries)", +DW_OP_value_to_name(op), *arity, stack.size()); +} + switch (op) { // The DW_OP_addr operation has a single operand that encodes a machine // address and whose size is the size of an address on the target machine. @@ -1253,11 +1261,7 @@ llvm::Expected DWARFExpression::Evaluate( // DESCRIPTION: Duplicates the entry currently second in the stack at // the top of the stack. case DW_OP_over: - if (stack.size() < 2) { -return llvm::createStringError( -"expression stack needs at least 2 items for DW_OP_over"); - } else -stack.push_back(stack[stack.size() - 2]); + stack.push_back(stack[stack.size() - 2]); break; // OPCODE: DW_OP_pick @@ -1280,14 +1284,9 @@ llvm::Expected DWARFExpression::Evaluate( // of the stack becomes the second stack entry, and the second entry // becomes the top of the stack case DW_OP_swap: - if (stack.size() < 2) { -return llvm::createStringError( -"expression stack needs at least 2 items for DW_OP_swap"); - } else { -tmp = stack.back(); -stack.back() = stack[stack.size() - 2]; -stack[stack.size() - 2] = tmp; - } + tmp = stack.back(); + stack.back() = stack[stack.size() - 2]; + stack[stack.size() - 2] = tmp; break; // OPCODE: DW_OP_rot @@ -1296,18 +1295,13 @@ llvm::Expected DWARFExpression::Evaluate( // the top of the stack becomes the third stack entry, the second entry // becomes the top of the stack, and the third entry becomes the second // entry. -case DW_OP_rot: - if (stack.size() < 3) { -return llvm::createStringError( -"expression stack needs at least 3 items for DW_OP_rot"); - } else { -size_t last_idx = stack.size() - 1; -Value old_top = stack[last_idx]; -stack[last_idx] = stack[last_idx - 1]; -stack[last_idx - 1] = stack[last_idx - 2]; -stack[last_idx - 2] = old_top; - } - break; +case DW_OP_rot: { + size_t last_idx = stack.size() - 1; + Value old_top = stack[last_idx]; + stack[last_idx] = stack[last_idx - 1]; + stack[last_idx - 1] = stack[last_idx - 2]; + stack[last_idx - 2] = old_top; +} break; // OPCODE: DW_OP_abs // OPERANDS: none @@ -1315,10 +1309,7 @@ llvm::Expected DWARFExpression::Evaluate( // value and pushes its absolute value. If the absolute value can not be // represented, the result is undefined. case DW_OP_abs: - if (stack.empty()) { -return llvm::createStringError( -"expression stack needs at least 1 item for DW_OP_abs"); - } else if (!stack.back().ResolveValue(exe_ctx).AbsoluteValue()) { + if (!stack.back().ResolveValue(exe_ctx).AbsoluteValue()) { return llvm::createStringError( "failed to take the absolute value of the first stack item"); } @@ -1329,15 +1320,10 @@ llvm::Expected DWARFExpression::Evaluate( // DESCRIPTION: pops the top two stack values, performs a bitwise and // operation on the two, and pushes the result. case DW_OP_and: - if (stack.size() < 2) { -return llvm::createStringError(
[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)
@@ -0,0 +1,202 @@ +""" +Test lldb-dap "port" configuration to "attach" request +""" + + +import dap_server +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil +from lldbsuite.test import lldbplatformutil +import lldbdap_testcase +import os +import shutil +import subprocess +import tempfile +import threading +import sys +import socket +import select + + +# A class representing a pipe for communicating with debug server. +# This class includes menthods to open the pipe and read the port number from it. +class Pipe(object): +def __init__(self, prefix): +self.name = os.path.join(prefix, "stub_port_number") +os.mkfifo(self.name) +self._fd = os.open(self.name, os.O_RDONLY | os.O_NONBLOCK) + +def finish_connection(self, timeout): +pass + +def read(self, size, timeout): +(readers, _, _) = select.select([self._fd], [], [], timeout) +if self._fd not in readers: +raise TimeoutError +return os.read(self._fd, size) + +def close(self): +os.close(self._fd) + + +class TestDAP_attachByPortNum(lldbdap_testcase.DAPTestCaseBase): +default_timeout = 20 + +def set_and_hit_breakpoint(self, continueToExit=True): +source = "main.c" +main_source_path = os.path.join(os.getcwd(), source) +breakpoint1_line = line_number(main_source_path, "// breakpoint 1") +lines = [breakpoint1_line] +# Set breakpoint in the thread function so we can step the threads +breakpoint_ids = self.set_source_breakpoints(main_source_path, lines) +self.assertEqual( +len(breakpoint_ids), len(lines), "expect correct number of breakpoints" +) +self.continue_to_breakpoints(breakpoint_ids) +if continueToExit: +self.continue_to_exit() + +def get_debug_server_command_line_args(self): +args = [] +if lldbplatformutil.getPlatform() == "linux": +args = ["gdbserver"] +elif lldbplatformutil.getPlatform() == "macosx": +args = ["--listen"] +if lldb.remote_platform: +args += ["*:0"] +else: +args += ["localhost:0"] +return args + +def get_debug_server_pipe(self): +pipe = Pipe(self.getBuildDir()) +self.addTearDownHook(lambda: pipe.close()) +pipe.finish_connection(self.default_timeout) +return pipe + +@skipIfWindows +@skipIfNetBSD +def test_by_port(self): +""" +Tests attaching to a process by port. +""" +self.build_and_create_debug_adaptor() +program = self.getBuildArtifact("a.out") + +debug_server_tool = self.getBuiltinDebugServerTool() + +pipe = self.get_debug_server_pipe() +args = self.get_debug_server_command_line_args() +args += [program] +args += ["--named-pipe", pipe.name] + +self.process = self.spawnSubprocess( +debug_server_tool, args, install_remote=False +) + +# Read the port number from the debug server pipe. +port = pipe.read(10, self.default_timeout) +# Trim null byte, convert to int +port = int(port[:-1]) +self.assertIsNotNone( +port, " Failed to read the port number from debug server pipe" +) + +self.attach(program=program, gdbRemotePort=port, sourceInitFile=True) +self.set_and_hit_breakpoint(continueToExit=True) +self.process.terminate() + +@skipIfWindows +@skipIfNetBSD +def test_by_port_and_pid(self): +""" +Tests attaching to a process by process ID and port number. +""" +self.build_and_create_debug_adaptor() +program = self.getBuildArtifact("a.out") + +debug_server_tool = self.getBuiltinDebugServerTool() +pipe = self.get_debug_server_pipe() +args = self.get_debug_server_command_line_args() +args += [program] +args += ["--named-pipe", pipe.name] + +self.process = self.spawnSubprocess( +debug_server_tool, args, install_remote=False +) + +# Read the port number from the debug server pipe. +port = pipe.read(10, self.default_timeout) +# Trim null byte, convert to int +port = int(port[:-1]) santhoshe447 wrote: Yes, you are right but I winna test with complete cycle. I will change this if its required. https://github.com/llvm/llvm-project/pull/91570 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)
@@ -0,0 +1,202 @@ +""" +Test lldb-dap "port" configuration to "attach" request +""" + + +import dap_server +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil +from lldbsuite.test import lldbplatformutil +import lldbdap_testcase +import os +import shutil +import subprocess +import tempfile +import threading +import sys +import socket +import select + + +# A class representing a pipe for communicating with debug server. +# This class includes menthods to open the pipe and read the port number from it. +class Pipe(object): +def __init__(self, prefix): +self.name = os.path.join(prefix, "stub_port_number") +os.mkfifo(self.name) +self._fd = os.open(self.name, os.O_RDONLY | os.O_NONBLOCK) + +def finish_connection(self, timeout): +pass + +def read(self, size, timeout): +(readers, _, _) = select.select([self._fd], [], [], timeout) +if self._fd not in readers: +raise TimeoutError +return os.read(self._fd, size) + +def close(self): +os.close(self._fd) santhoshe447 wrote: I agree but the specific class is defined based on the host platform. If the host platform is windows, it uses the same Pipe class with different APIs, and for other platforms, it behaves differently. Therefore, I did not place Pipe class in a common location. Ref: lldb/test/API/tools/lldb-server/commandline/TestGdbRemoteConnection.py https://github.com/llvm/llvm-project/pull/91570 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
@@ -3129,14 +3130,19 @@ void CommandInterpreter::IOHandlerInputComplete(IOHandler _handler, return; const bool is_interactive = io_handler.GetIsInteractive(); - if (!is_interactive) { + bool allow_repeats = JDevlieghere wrote: nit: `const bool` for consistency with the line above. https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
https://github.com/JDevlieghere approved this pull request. LGMT modulo nits. https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
https://github.com/JDevlieghere edited https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
@@ -182,6 +187,11 @@ class CommandInterpreterRunOptions { void SetSpawnThread(bool spawn_thread) { m_spawn_thread = spawn_thread ? eLazyBoolYes : eLazyBoolNo; } + bool GetAllowRepeats() const { return DefaultToNo(m_allow_repeats); } JDevlieghere wrote: Nit: newline between `SetSpawnThread` and `GetAllowRepeats`? https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
@@ -72,6 +72,14 @@ class LLDB_API SBCommandInterpreterRunOptions { void SetSpawnThread(bool); + bool GetAllowRepeats() const; + + // By default, RunCommandInterpreter will discard repeats if the + // IOHandler being used is not interactive. Setting AllowRepeats to true + // will override this behavior and always process empty lines in the input + // as a repeat command. JDevlieghere wrote: These should be `///` so they get picked up by Doxygen. https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][api-test] Add API test for SBCommandInterpreter::CommandOverrideCallback (PR #94518)
https://github.com/chelcassanova updated https://github.com/llvm/llvm-project/pull/94518 >From 44e8cab5d45a87eb1ea2076c498abe5be423eb1c Mon Sep 17 00:00:00 2001 From: Chelsea Cassanova Date: Wed, 5 Jun 2024 11:24:01 -0700 Subject: [PATCH] [lldb][api-test] Add API test for SBCommandInterpreter::CommandOverrideCallback `SBCommandInterpreter::CommandOverrideCallback` was not being exposed to the Python API has no coverage in the API test suite, so this commits exposes and adds a test for it. Doing this involves also adding a typemap for the callback used for this function so that it matches the functionality of other callback functions that are exposed to Python. --- lldb/bindings/python/python-typemaps.swig | 18 - lldb/bindings/python/python-wrapper.swig | 22 +++ lldb/include/lldb/API/SBCommandInterpreter.h | 2 -- .../TestCommandOverrideCallback.py| 27 +++ 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py diff --git a/lldb/bindings/python/python-typemaps.swig b/lldb/bindings/python/python-typemaps.swig index 8d4b740e5f35c..ff698907568c8 100644 --- a/lldb/bindings/python/python-typemaps.swig +++ b/lldb/bindings/python/python-typemaps.swig @@ -427,7 +427,6 @@ template <> bool SetNumberFromPyObject(double , PyObject *obj) { free($1); } - // For Log::LogOutputCallback %typemap(in) (lldb::LogOutputCallback log_callback, void *baton) { if (!($input == Py_None || @@ -476,6 +475,23 @@ template <> bool SetNumberFromPyObject(double , PyObject *obj) { $1 = $1 || PyCallable_Check(reinterpret_cast($input)); } +%typemap(in) (lldb::CommandOverrideCallback callback, void *baton) { + if (!($input == Py_None || +PyCallable_Check(reinterpret_cast($input { +PyErr_SetString(PyExc_TypeError, "Need a callable object or None!"); +SWIG_fail; + } + + // Don't lose the callback reference + Py_INCREF($input); + $1 = LLDBSwigPythonCallPythonSBCommandInterpreterSetCommandOverrideCallback; + $2 = $input; +} +%typemap(typecheck) (lldb::CommandOverrideCallback callback, void *baton) { + $1 = $input == Py_None; + $1 = $1 || PyCallable_Check(reinterpret_cast($input)); +} + %typemap(in) lldb::FileSP { PythonFile py_file(PyRefType::Borrowed, $input); if (!py_file) { diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig index 1370afc885d43..bd3de8ce5d46c 100644 --- a/lldb/bindings/python/python-wrapper.swig +++ b/lldb/bindings/python/python-wrapper.swig @@ -1099,6 +1099,28 @@ static void LLDBSwigPythonCallPythonSBDebuggerTerminateCallback(lldb::user_id_t } } +static bool LLDBSwigPythonCallPythonSBCommandInterpreterSetCommandOverrideCallback(void *baton, const char **argv) { + bool ret_val = false; + if (baton != Py_None) { +SWIG_PYTHON_THREAD_BEGIN_BLOCK; +// Create a PyList of items since we're going to pass it to the callback as a tuple +// of arguments. +PyObject *py_argv = PyList_New(0); +for (const char **arg = argv; arg && *arg; arg++) { + std::string arg_string = *arg; + PyObject *py_string = PyUnicode_FromStringAndSize(arg_string.c_str(), arg_string.size()); + PyList_Append(py_argv, py_string); +} + +PyObject *result = PyObject_CallObject( +reinterpret_cast(baton), PyList_AsTuple(py_argv)); +ret_val = result ? PyObject_IsTrue(result) : false; +Py_XDECREF(result); +SWIG_PYTHON_THREAD_END_BLOCK; + } + return ret_val; +} + static SBError LLDBSwigPythonCallLocateModuleCallback( void *callback_baton, const SBModuleSpec _spec_sb, SBFileSpec _file_spec_sb, SBFileSpec _file_spec_sb) { diff --git a/lldb/include/lldb/API/SBCommandInterpreter.h b/lldb/include/lldb/API/SBCommandInterpreter.h index 8ac36344b3a79..084b6d9adb703 100644 --- a/lldb/include/lldb/API/SBCommandInterpreter.h +++ b/lldb/include/lldb/API/SBCommandInterpreter.h @@ -265,11 +265,9 @@ class SBCommandInterpreter { // Catch commands before they execute by registering a callback that will get // called when the command gets executed. This allows GUI or command line // interfaces to intercept a command and stop it from happening -#ifndef SWIG bool SetCommandOverrideCallback(const char *command_name, lldb::CommandOverrideCallback callback, void *baton); -#endif /// Return true if the command interpreter is the active IO handler. /// diff --git a/lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py b/lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py new file mode 100644 index 0..e8d374987fc90 --- /dev/null +++ b/lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py @@ -0,0 +1,27 @@ +from typing_extensions import override +import lldb +from lldbsuite.test.decorators import * +from
[Lldb-commits] [lldb] [llvm] [lldb] Encode operands and arity in Dwarf.def and use them in LLDB. (PR #94679)
https://github.com/clayborg approved this pull request. https://github.com/llvm/llvm-project/pull/94679 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use `Address` to setup breakpoint (PR #94794)
https://github.com/yln updated https://github.com/llvm/llvm-project/pull/94794 >From 40fd912a328cd9f7918a9f9c12f8cfd97094fc2f Mon Sep 17 00:00:00 2001 From: Julian Lettner Date: Fri, 7 Jun 2024 09:20:23 -0700 Subject: [PATCH 1/2] [lldb] Use `Address` to setup breakpoint Use `Address` (instead of `addr_t`) to setup breakpoint in `ReportRetriever::SetupBreakpoint`. This is cleaner and the breakpoint should now survive re-running of the binary. rdar://124399066 --- .../Utility/ReportRetriever.cpp | 15 --- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp b/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp index 298b63bc716fc..6fd11c5e43150 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp +++ b/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp @@ -219,7 +219,6 @@ bool ReportRetriever::NotifyBreakpointHit(ProcessSP process_sp, return true; // Return true to stop the target } -// FIXME: Setup the breakpoint using a less fragile SPI. rdar://124399066 Breakpoint *ReportRetriever::SetupBreakpoint(ModuleSP module_sp, ProcessSP process_sp, ConstString symbol_name) { @@ -235,19 +234,13 @@ Breakpoint *ReportRetriever::SetupBreakpoint(ModuleSP module_sp, if (!symbol->ValueIsAddress() || !symbol->GetAddressRef().IsValid()) return nullptr; - Target = process_sp->GetTarget(); - addr_t symbol_address = symbol->GetAddressRef().GetOpcodeLoadAddress(); - - if (symbol_address == LLDB_INVALID_ADDRESS) -return nullptr; - + const Address = symbol->GetAddressRef(); const bool internal = true; const bool hardware = false; - Breakpoint *breakpoint = - process_sp->GetTarget() - .CreateBreakpoint(symbol_address, internal, hardware) - .get(); + Breakpoint *breakpoint = process_sp->GetTarget() + .CreateBreakpoint(address, internal, hardware) + .get(); return breakpoint; } >From 484f913a20b18364dd949f32e3f9c2c6404c8304 Mon Sep 17 00:00:00 2001 From: Julian Lettner Date: Fri, 7 Jun 2024 09:33:06 -0700 Subject: [PATCH 2/2] [lldb] Stop using legacy breakpoint symbol --- .../InstrumentationRuntimeASanLibsanitizers.cpp | 12 ++-- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp b/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp index cd91f4a6ff1bc..b1151febb7cc4 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp +++ b/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp @@ -90,17 +90,9 @@ void InstrumentationRuntimeASanLibsanitizers::Activate() { if (!process_sp) return; - lldb::ModuleSP module_sp = GetRuntimeModuleSP(); - Breakpoint *breakpoint = ReportRetriever::SetupBreakpoint( - module_sp, process_sp, ConstString("sanitizers_address_on_report")); - - if (!breakpoint) { -breakpoint = ReportRetriever::SetupBreakpoint( -module_sp, process_sp, -ConstString("_Z22raise_sanitizers_error23sanitizer_error_context")); - } - + GetRuntimeModuleSP(), process_sp, + ConstString("sanitizers_address_on_report")); if (!breakpoint) return; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use `Address` to setup breakpoint (PR #94794)
@@ -235,18 +234,13 @@ Breakpoint *ReportRetriever::SetupBreakpoint(ModuleSP module_sp, if (!symbol->ValueIsAddress() || !symbol->GetAddressRef().IsValid()) return nullptr; - Target = process_sp->GetTarget(); - addr_t symbol_address = symbol->GetAddressRef().GetOpcodeLoadAddress(); - - if (symbol_address == LLDB_INVALID_ADDRESS) -return nullptr; - + const Address = symbol->GetAddressRef(); const bool internal = true; const bool hardware = false; Breakpoint *breakpoint = process_sp->GetTarget() - .CreateBreakpoint(symbol_address, internal, hardware) + .CreateBreakpoint(address, internal, hardware) yln wrote: Cleanup suggested by @jimingham here: https://github.com/llvm/llvm-project/pull/84583#issuecomment-1986590436 > you could set it by Address, in which case it would survive re-running, but > instead it converts the Address to an addr_t - the most fragile way to set a > breakpoint So we are using the `CreateBreakpoint` overload that takes `Address` instead of `addr_t` now and Jim mentioned that this survives re-running. Are we concerned at all about this change in behavior? For example, could we get into a situation where we keep adding superfluous breakpoints because the old ones survive? @jimingham @usama54321 https://github.com/llvm/llvm-project/pull/94794 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use `Address` to setup breakpoint (PR #94794)
@@ -90,17 +90,9 @@ void InstrumentationRuntimeASanLibsanitizers::Activate() { if (!process_sp) return; - lldb::ModuleSP module_sp = GetRuntimeModuleSP(); - Breakpoint *breakpoint = ReportRetriever::SetupBreakpoint( - module_sp, process_sp, ConstString("sanitizers_address_on_report")); - - if (!breakpoint) { -breakpoint = ReportRetriever::SetupBreakpoint( -module_sp, process_sp, -ConstString("_Z22raise_sanitizers_error23sanitizer_error_context")); yln wrote: @usama54321 it's now safe to ignore the legacy symbol, right? https://github.com/llvm/llvm-project/pull/94794 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use `Address` to setup breakpoint (PR #94794)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff b01ac5137c28fa5e1b44a5d850cb7a6ace7d8799 dd02ca52d3cdad42c549bf66b4c05aca8fa93f62 -- lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp `` View the diff from clang-format here. ``diff diff --git a/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp b/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp index 4e382005f8..6fd11c5e43 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp +++ b/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp @@ -238,10 +238,9 @@ Breakpoint *ReportRetriever::SetupBreakpoint(ModuleSP module_sp, const bool internal = true; const bool hardware = false; - Breakpoint *breakpoint = - process_sp->GetTarget() - .CreateBreakpoint(address, internal, hardware) - .get(); + Breakpoint *breakpoint = process_sp->GetTarget() + .CreateBreakpoint(address, internal, hardware) + .get(); return breakpoint; } `` https://github.com/llvm/llvm-project/pull/94794 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)
https://github.com/temyurchenko updated https://github.com/llvm/llvm-project/pull/93913 >From 9b18a5c4132cf093fc9b32f6b4dcfe406d485e3d Mon Sep 17 00:00:00 2001 From: Artem Yurchenko Date: Thu, 6 Jun 2024 20:20:19 -0400 Subject: [PATCH] enforce the unbraced `extern ` invariant Quoting 9.11.8: > A declaration directly contained in a linkage-specification is > treated as if it contains the extern specifier (9.2.2) for the > purpose of determining the linkage of the declared name and whether > it is a definition. Such a declaration shall not specify a storage > class. So, the invariant is that function and variable declarations within an unbraced language linkage specification have `StorageClass` set to `SC_None`. Problem: in several places the invariant was broken. Solution: remove the explicit `SC_Extern` specification. Note, that my changes result in the `extern` being implicit in some functions that are not contained in a language linkage specification. --- clang/lib/AST/Decl.cpp| 26 --- clang/lib/Sema/SemaDecl.cpp | 2 +- clang/lib/Sema/SemaExpr.cpp | 2 +- .../Clang/ClangExpressionParser.cpp | 2 +- .../Clang/NameSearchContext.cpp | 3 ++- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 1f19dadafa44e..ebaeed0e818e1 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -576,13 +576,19 @@ template static bool isFirstInExternCContext(T *D) { return First->isInExternCContext(); } -static bool isSingleLineLanguageLinkage(const Decl ) { - if (const auto *SD = dyn_cast(D.getDeclContext())) +static bool isUnbracedLanguageLinkage(const DeclContext *DC) { + if (!DC) +return false; + if (const auto *SD = dyn_cast(DC)) if (!SD->hasBraces()) return true; return false; } +static bool hasUnbracedLanguageLinkage(const Decl ) { + return isUnbracedLanguageLinkage(D.getDeclContext()); +} + static bool isDeclaredInModuleInterfaceOrPartition(const NamedDecl *D) { if (auto *M = D->getOwningModule()) return M->isInterfaceOrPartition(); @@ -644,7 +650,7 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D, if (Var->getStorageClass() != SC_Extern && Var->getStorageClass() != SC_PrivateExtern && - !isSingleLineLanguageLinkage(*Var)) + !hasUnbracedLanguageLinkage(*Var)) return LinkageInfo::internal(); } @@ -2133,6 +2139,12 @@ VarDecl::VarDecl(Kind DK, ASTContext , DeclContext *DC, "ParmVarDeclBitfields too large!"); static_assert(sizeof(NonParmVarDeclBitfields) <= sizeof(unsigned), "NonParmVarDeclBitfields too large!"); + + // The unbraced `extern "C"` invariant is that the storage class + // specifier is omitted in the source code, i.e. SC_None (but is, + // implicitly, `extern`). + assert(!isUnbracedLanguageLinkage(DC) || SC == SC_None); + AllBits = 0; VarDeclBits.SClass = SC; // Everything else is implicitly initialized to false. @@ -2316,7 +2328,7 @@ VarDecl::isThisDeclarationADefinition(ASTContext ) const { // A declaration directly contained in a linkage-specification is treated // as if it contains the extern specifier for the purpose of determining // the linkage of the declared name and whether it is a definition. - if (isSingleLineLanguageLinkage(*this)) + if (hasUnbracedLanguageLinkage(*this)) return DeclarationOnly; // C99 6.9.2p2: @@ -3041,6 +3053,12 @@ FunctionDecl::FunctionDecl(Kind DK, ASTContext , DeclContext *DC, DeclContext(DK), redeclarable_base(C), Body(), ODRHash(0), EndRangeLoc(NameInfo.getEndLoc()), DNLoc(NameInfo.getInfo()) { assert(T.isNull() || T->isFunctionType()); + + // The unbraced `extern "C"` invariant is that the storage class + // specifier is omitted in the source code, i.e. SC_None (but is, + // implicitly, `extern`). + assert(!isUnbracedLanguageLinkage(DC) || S == SC_None); + FunctionDeclBits.SClass = S; FunctionDeclBits.IsInline = isInlineSpecified; FunctionDeclBits.IsInlineSpecified = isInlineSpecified; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 4b9b735f1cfb4..4e2f02ba7007a 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2380,7 +2380,7 @@ FunctionDecl *Sema::CreateBuiltin(IdentifierInfo *II, QualType Type, } FunctionDecl *New = FunctionDecl::Create(Context, Parent, Loc, Loc, II, Type, - /*TInfo=*/nullptr, SC_Extern, + /*TInfo=*/nullptr, SC_None, getCurFPFeatures().isFPConstrained(), false, Type->isFunctionProtoType()); New->setImplicit(); diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index
[Lldb-commits] [lldb] [lldb] Use `Address` to setup breakpoint (PR #94794)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Julian Lettner (yln) Changes Use `Address` (instead of `addr_t`) to setup breakpoint in `ReportRetriever::SetupBreakpoint`. This is cleaner and the breakpoint should now survive re-running of the binary. rdar://124399066 --- Full diff: https://github.com/llvm/llvm-project/pull/94794.diff 2 Files Affected: - (modified) lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp (+2-10) - (modified) lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp (+2-8) ``diff diff --git a/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp b/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp index cd91f4a6ff1bc..b1151febb7cc4 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp +++ b/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp @@ -90,17 +90,9 @@ void InstrumentationRuntimeASanLibsanitizers::Activate() { if (!process_sp) return; - lldb::ModuleSP module_sp = GetRuntimeModuleSP(); - Breakpoint *breakpoint = ReportRetriever::SetupBreakpoint( - module_sp, process_sp, ConstString("sanitizers_address_on_report")); - - if (!breakpoint) { -breakpoint = ReportRetriever::SetupBreakpoint( -module_sp, process_sp, -ConstString("_Z22raise_sanitizers_error23sanitizer_error_context")); - } - + GetRuntimeModuleSP(), process_sp, + ConstString("sanitizers_address_on_report")); if (!breakpoint) return; diff --git a/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp b/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp index 298b63bc716fc..4e382005f8c2b 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp +++ b/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp @@ -219,7 +219,6 @@ bool ReportRetriever::NotifyBreakpointHit(ProcessSP process_sp, return true; // Return true to stop the target } -// FIXME: Setup the breakpoint using a less fragile SPI. rdar://124399066 Breakpoint *ReportRetriever::SetupBreakpoint(ModuleSP module_sp, ProcessSP process_sp, ConstString symbol_name) { @@ -235,18 +234,13 @@ Breakpoint *ReportRetriever::SetupBreakpoint(ModuleSP module_sp, if (!symbol->ValueIsAddress() || !symbol->GetAddressRef().IsValid()) return nullptr; - Target = process_sp->GetTarget(); - addr_t symbol_address = symbol->GetAddressRef().GetOpcodeLoadAddress(); - - if (symbol_address == LLDB_INVALID_ADDRESS) -return nullptr; - + const Address = symbol->GetAddressRef(); const bool internal = true; const bool hardware = false; Breakpoint *breakpoint = process_sp->GetTarget() - .CreateBreakpoint(symbol_address, internal, hardware) + .CreateBreakpoint(address, internal, hardware) .get(); return breakpoint; `` https://github.com/llvm/llvm-project/pull/94794 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use `Address` to setup breakpoint (PR #94794)
https://github.com/yln created https://github.com/llvm/llvm-project/pull/94794 Use `Address` (instead of `addr_t`) to setup breakpoint in `ReportRetriever::SetupBreakpoint`. This is cleaner and the breakpoint should now survive re-running of the binary. rdar://124399066 >From 988d184eb52824810f47aab27915c1644c5ce4ae Mon Sep 17 00:00:00 2001 From: Julian Lettner Date: Fri, 7 Jun 2024 09:20:23 -0700 Subject: [PATCH 1/2] [lldb] Use `Address` to setup breakpoint Use `Address` (instead of `addr_t`) to setup breakpoint in `ReportRetriever::SetupBreakpoint`. This is cleaner and the breakpoint should now survive re-running of the binary. rdar://124399066 --- .../InstrumentationRuntime/Utility/ReportRetriever.cpp | 10 ++ 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp b/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp index 298b63bc716fc..4e382005f8c2b 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp +++ b/lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp @@ -219,7 +219,6 @@ bool ReportRetriever::NotifyBreakpointHit(ProcessSP process_sp, return true; // Return true to stop the target } -// FIXME: Setup the breakpoint using a less fragile SPI. rdar://124399066 Breakpoint *ReportRetriever::SetupBreakpoint(ModuleSP module_sp, ProcessSP process_sp, ConstString symbol_name) { @@ -235,18 +234,13 @@ Breakpoint *ReportRetriever::SetupBreakpoint(ModuleSP module_sp, if (!symbol->ValueIsAddress() || !symbol->GetAddressRef().IsValid()) return nullptr; - Target = process_sp->GetTarget(); - addr_t symbol_address = symbol->GetAddressRef().GetOpcodeLoadAddress(); - - if (symbol_address == LLDB_INVALID_ADDRESS) -return nullptr; - + const Address = symbol->GetAddressRef(); const bool internal = true; const bool hardware = false; Breakpoint *breakpoint = process_sp->GetTarget() - .CreateBreakpoint(symbol_address, internal, hardware) + .CreateBreakpoint(address, internal, hardware) .get(); return breakpoint; >From dd02ca52d3cdad42c549bf66b4c05aca8fa93f62 Mon Sep 17 00:00:00 2001 From: Julian Lettner Date: Fri, 7 Jun 2024 09:33:06 -0700 Subject: [PATCH 2/2] [lldb] Stop using legacy breakpoint symbol --- .../InstrumentationRuntimeASanLibsanitizers.cpp | 12 ++-- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp b/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp index cd91f4a6ff1bc..b1151febb7cc4 100644 --- a/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp +++ b/lldb/source/Plugins/InstrumentationRuntime/ASanLibsanitizers/InstrumentationRuntimeASanLibsanitizers.cpp @@ -90,17 +90,9 @@ void InstrumentationRuntimeASanLibsanitizers::Activate() { if (!process_sp) return; - lldb::ModuleSP module_sp = GetRuntimeModuleSP(); - Breakpoint *breakpoint = ReportRetriever::SetupBreakpoint( - module_sp, process_sp, ConstString("sanitizers_address_on_report")); - - if (!breakpoint) { -breakpoint = ReportRetriever::SetupBreakpoint( -module_sp, process_sp, -ConstString("_Z22raise_sanitizers_error23sanitizer_error_context")); - } - + GetRuntimeModuleSP(), process_sp, + ConstString("sanitizers_address_on_report")); if (!breakpoint) return; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
@@ -93,15 +93,20 @@ class CommandInterpreterRunOptions { /// \param[in] add_to_history ///If \b true add the commands to the command history. If \b false, don't ///add them. + /// \param[in] process_repeats + ///If \b true then process empty lines as repeat commands even if the + ///interpreter is non-interactive. CommandInterpreterRunOptions(LazyBool stop_on_continue, LazyBool stop_on_error, LazyBool stop_on_crash, LazyBool echo_commands, LazyBool echo_comments, LazyBool print_results, LazyBool print_errors, - LazyBool add_to_history) + LazyBool add_to_history, + LazyBool process_repeats) jimingham wrote: Sure. https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
https://github.com/jimingham updated https://github.com/llvm/llvm-project/pull/94786 >From bcd8c81c5fbc249886c53d8a2d1bc21a3f9e1ffd Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Fri, 7 Jun 2024 11:17:26 -0700 Subject: [PATCH 1/3] Add AllowRepeats to SBCommandInterpreterRunOptions. This is useful if you have a transcript of a user session and want to rerun those commands with RunCommandInterpreter. The same functionality is also useful in testing. --- ...SBCommandInterpreterRunOptionsDocstrings.i | 3 + .../lldb/API/SBCommandInterpreterRunOptions.h | 8 +++ .../lldb/Interpreter/CommandInterpreter.h | 14 - .../API/SBCommandInterpreterRunOptions.cpp| 12 .../source/Interpreter/CommandInterpreter.cpp | 13 - .../TestRunCommandInterpreterAPI.py | 57 +++ 6 files changed, 91 insertions(+), 16 deletions(-) diff --git a/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i b/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i index b37da0535d18a..a4398d95ed0d1 100644 --- a/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i +++ b/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i @@ -10,5 +10,8 @@ A default SBCommandInterpreterRunOptions object has: * PrintResults: true * PrintErrors:true * AddToHistory: true +* AllowRepeatsfalse +Interactive debug sessions always allow repeats, the AllowRepeats +run option only affects non-interactive sessions. ") lldb::SBCommandInterpreterRunOptions; diff --git a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h index 69b969267e755..b32a8ca51cd08 100644 --- a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h +++ b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h @@ -71,6 +71,14 @@ class LLDB_API SBCommandInterpreterRunOptions { bool GetSpawnThread() const; void SetSpawnThread(bool); + + bool GetAllowRepeats() const; + + // By default, RunCommandInterpreter will discard repeats if the + // IOHandler being used is not interactive. Setting AllowRepeats to true + // will override this behavior and always process empty lines in the input + // as a repeat command. + void SetAllowRepeats(bool); private: lldb_private::CommandInterpreterRunOptions *get() const; diff --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h index 8863523b2e31f..5c2bcd99681a4 100644 --- a/lldb/include/lldb/Interpreter/CommandInterpreter.h +++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -93,15 +93,19 @@ class CommandInterpreterRunOptions { /// \param[in] add_to_history ///If \b true add the commands to the command history. If \b false, don't ///add them. + /// \param[in] process_repeats + ///If \b true then process empty lines as repeat commands even if the + ///interpreter is non-interactive. CommandInterpreterRunOptions(LazyBool stop_on_continue, LazyBool stop_on_error, LazyBool stop_on_crash, LazyBool echo_commands, LazyBool echo_comments, LazyBool print_results, LazyBool print_errors, - LazyBool add_to_history) + LazyBool add_to_history, LazyBool process_repeats) : m_stop_on_continue(stop_on_continue), m_stop_on_error(stop_on_error), m_stop_on_crash(stop_on_crash), m_echo_commands(echo_commands), m_echo_comment_commands(echo_comments), m_print_results(print_results), -m_print_errors(print_errors), m_add_to_history(add_to_history) {} +m_print_errors(print_errors), m_add_to_history(add_to_history), +m_allow_repeats(process_repeats) {} CommandInterpreterRunOptions() = default; @@ -182,6 +186,11 @@ class CommandInterpreterRunOptions { void SetSpawnThread(bool spawn_thread) { m_spawn_thread = spawn_thread ? eLazyBoolYes : eLazyBoolNo; } + bool GetAllowRepeats() const { return DefaultToNo(m_allow_repeats); } + + void SetAllowRepeats(bool allow_repeats) { +m_allow_repeats = allow_repeats ? eLazyBoolYes : eLazyBoolNo; + } LazyBool m_stop_on_continue = eLazyBoolCalculate; LazyBool m_stop_on_error = eLazyBoolCalculate; @@ -193,6 +202,7 @@ class CommandInterpreterRunOptions { LazyBool m_add_to_history = eLazyBoolCalculate; LazyBool m_auto_handle_events; LazyBool m_spawn_thread; + LazyBool m_allow_repeats = eLazyBoolCalculate; private: static bool DefaultToYes(LazyBool flag) { diff --git a/lldb/source/API/SBCommandInterpreterRunOptions.cpp b/lldb/source/API/SBCommandInterpreterRunOptions.cpp index 6c6b2aa15a792..0c7581d6f1f5b 100644 --- a/lldb/source/API/SBCommandInterpreterRunOptions.cpp +++ b/lldb/source/API/SBCommandInterpreterRunOptions.cpp @@ -164,6 +164,18 @@ void SBCommandInterpreterRunOptions::SetSpawnThread(bool
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
https://github.com/medismailben edited https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
@@ -93,15 +93,20 @@ class CommandInterpreterRunOptions { /// \param[in] add_to_history ///If \b true add the commands to the command history. If \b false, don't ///add them. + /// \param[in] process_repeats + ///If \b true then process empty lines as repeat commands even if the + ///interpreter is non-interactive. CommandInterpreterRunOptions(LazyBool stop_on_continue, LazyBool stop_on_error, LazyBool stop_on_crash, LazyBool echo_commands, LazyBool echo_comments, LazyBool print_results, LazyBool print_errors, - LazyBool add_to_history) + LazyBool add_to_history, + LazyBool process_repeats) medismailben wrote: > tell RunCommandInterpreter to process any repeat commands Oh, `process` is a verb here --' when I read it I thought you were talking about the `Process` class which confused me a little ^^ https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
@@ -93,15 +93,20 @@ class CommandInterpreterRunOptions { /// \param[in] add_to_history ///If \b true add the commands to the command history. If \b false, don't ///add them. + /// \param[in] process_repeats + ///If \b true then process empty lines as repeat commands even if the + ///interpreter is non-interactive. CommandInterpreterRunOptions(LazyBool stop_on_continue, LazyBool stop_on_error, LazyBool stop_on_crash, LazyBool echo_commands, LazyBool echo_comments, LazyBool print_results, LazyBool print_errors, - LazyBool add_to_history) + LazyBool add_to_history, + LazyBool process_repeats) jimingham wrote: Internally in lldb we call the handling of newlines in the interactive interpreter as "repeat commands", and at the the CommandInterpreterRunOptions setting option was "AllowRepeats". https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
@@ -93,15 +93,20 @@ class CommandInterpreterRunOptions { /// \param[in] add_to_history ///If \b true add the commands to the command history. If \b false, don't ///add them. + /// \param[in] process_repeats + ///If \b true then process empty lines as repeat commands even if the + ///interpreter is non-interactive. CommandInterpreterRunOptions(LazyBool stop_on_continue, LazyBool stop_on_error, LazyBool stop_on_crash, LazyBool echo_commands, LazyBool echo_comments, LazyBool print_results, LazyBool print_errors, - LazyBool add_to_history) + LazyBool add_to_history, + LazyBool process_repeats) jimingham wrote: I was trying to stay in line with the other parameter names in this function. So for instance, add_to_history says commands should be added to the history. The option I'm adding is to tell RunCommandInterpreter to process any repeat commands in the input stream. https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)
temyurchenko wrote: > Hmm... I don't have a great idea. Is using it not enough to get it to be > emitted? I see here we don't seem to cause them to be emitted: > https://godbolt.org/z/nYzMca7Te Yes, I get the same result. I also tried adding a test in `DeclPrinterTest`, but it doesn't lookup builtins. https://github.com/llvm/llvm-project/pull/93913 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)
erichkeane wrote: > > I see the 2nds commit doesn't add any tests! Please make it do so > > I've tried and I'm not quite sure how to do it. The issue is we need to test > AST printing of «implicitly declared» functions, such as builtins and > functions instrumented by lldb, such as `log` for logging; which seems > contradictory. Do you have any suggestions? > > Furthermore, the second commit adds an assertion of an invariant and then > fixes the places in the code where the invariant breaks. Is it fair to say > that the codebase itself is the test for the invariant? If any codepath would > break the invariant, the assertion would be triggered. Not on a release build > though, I imagine. Hmm... I don't have a great idea. Is using it not enough to get it to be emitted? I see here we don't seem to cause them to be emitted: https://godbolt.org/z/nYzMca7Te Perhaps @AaronBallman has an idea. https://github.com/llvm/llvm-project/pull/93913 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
https://github.com/medismailben edited https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
https://github.com/medismailben approved this pull request. LGTM with nit. https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
@@ -93,15 +93,20 @@ class CommandInterpreterRunOptions { /// \param[in] add_to_history ///If \b true add the commands to the command history. If \b false, don't ///add them. + /// \param[in] process_repeats + ///If \b true then process empty lines as repeat commands even if the + ///interpreter is non-interactive. CommandInterpreterRunOptions(LazyBool stop_on_continue, LazyBool stop_on_error, LazyBool stop_on_crash, LazyBool echo_commands, LazyBool echo_comments, LazyBool print_results, LazyBool print_errors, - LazyBool add_to_history) + LazyBool add_to_history, + LazyBool process_repeats) medismailben wrote: nit: not sure what you mean by `process_repeats`, may be `command_repeats` would be make more sense here. https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)
https://github.com/temyurchenko updated https://github.com/llvm/llvm-project/pull/93913 >From a54036c0fdc1a875f40a274d502dd96651a35ae3 Mon Sep 17 00:00:00 2001 From: Artem Yurchenko Date: Thu, 6 Jun 2024 20:20:19 -0400 Subject: [PATCH] enforce the unbraced `extern ` invariant Quoting 9.11.8: > A declaration directly contained in a linkage-specification is > treated as if it contains the extern specifier (9.2.2) for the > purpose of determining the linkage of the declared name and whether > it is a definition. Such a declaration shall not specify a storage > class. So, the invariant is that function and variable declarations within an unbraced language linkage specification have `StorageClass` set to `SC_None`. Problem: in several places the invariant was broken. Solution: remove the explicit `SC_Extern` specification. Note, that my changes result in the `extern` being implicit in some functions that are not contained in a language linkage specification. --- clang/lib/AST/Decl.cpp| 26 --- clang/lib/Sema/SemaDecl.cpp | 2 +- .../Clang/ClangExpressionParser.cpp | 2 +- .../Clang/NameSearchContext.cpp | 3 ++- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 1f19dadafa44e..ebaeed0e818e1 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -576,13 +576,19 @@ template static bool isFirstInExternCContext(T *D) { return First->isInExternCContext(); } -static bool isSingleLineLanguageLinkage(const Decl ) { - if (const auto *SD = dyn_cast(D.getDeclContext())) +static bool isUnbracedLanguageLinkage(const DeclContext *DC) { + if (!DC) +return false; + if (const auto *SD = dyn_cast(DC)) if (!SD->hasBraces()) return true; return false; } +static bool hasUnbracedLanguageLinkage(const Decl ) { + return isUnbracedLanguageLinkage(D.getDeclContext()); +} + static bool isDeclaredInModuleInterfaceOrPartition(const NamedDecl *D) { if (auto *M = D->getOwningModule()) return M->isInterfaceOrPartition(); @@ -644,7 +650,7 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D, if (Var->getStorageClass() != SC_Extern && Var->getStorageClass() != SC_PrivateExtern && - !isSingleLineLanguageLinkage(*Var)) + !hasUnbracedLanguageLinkage(*Var)) return LinkageInfo::internal(); } @@ -2133,6 +2139,12 @@ VarDecl::VarDecl(Kind DK, ASTContext , DeclContext *DC, "ParmVarDeclBitfields too large!"); static_assert(sizeof(NonParmVarDeclBitfields) <= sizeof(unsigned), "NonParmVarDeclBitfields too large!"); + + // The unbraced `extern "C"` invariant is that the storage class + // specifier is omitted in the source code, i.e. SC_None (but is, + // implicitly, `extern`). + assert(!isUnbracedLanguageLinkage(DC) || SC == SC_None); + AllBits = 0; VarDeclBits.SClass = SC; // Everything else is implicitly initialized to false. @@ -2316,7 +2328,7 @@ VarDecl::isThisDeclarationADefinition(ASTContext ) const { // A declaration directly contained in a linkage-specification is treated // as if it contains the extern specifier for the purpose of determining // the linkage of the declared name and whether it is a definition. - if (isSingleLineLanguageLinkage(*this)) + if (hasUnbracedLanguageLinkage(*this)) return DeclarationOnly; // C99 6.9.2p2: @@ -3041,6 +3053,12 @@ FunctionDecl::FunctionDecl(Kind DK, ASTContext , DeclContext *DC, DeclContext(DK), redeclarable_base(C), Body(), ODRHash(0), EndRangeLoc(NameInfo.getEndLoc()), DNLoc(NameInfo.getInfo()) { assert(T.isNull() || T->isFunctionType()); + + // The unbraced `extern "C"` invariant is that the storage class + // specifier is omitted in the source code, i.e. SC_None (but is, + // implicitly, `extern`). + assert(!isUnbracedLanguageLinkage(DC) || S == SC_None); + FunctionDeclBits.SClass = S; FunctionDeclBits.IsInline = isInlineSpecified; FunctionDeclBits.IsInlineSpecified = isInlineSpecified; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 4b9b735f1cfb4..4e2f02ba7007a 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2380,7 +2380,7 @@ FunctionDecl *Sema::CreateBuiltin(IdentifierInfo *II, QualType Type, } FunctionDecl *New = FunctionDecl::Create(Context, Parent, Loc, Loc, II, Type, - /*TInfo=*/nullptr, SC_Extern, + /*TInfo=*/nullptr, SC_None, getCurFPFeatures().isFPConstrained(), false, Type->isFunctionProtoType()); New->setImplicit(); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
[Lldb-commits] [clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)
temyurchenko wrote: > I see the 2nds commit doesn't add any tests! Please make it do so I've tried and I'm not quite sure how to do it. The issue is we need to test AST printing of «implicitly declared» functions, such as builtins and functions instrumented by lldb, such as `log` for logging; which seems contradictory. Do you have any suggestions? Furthermore, the second commit adds an assertion of an invariant and then fixes the places in the code where the invariant breaks. Is it fair to say that the codebase itself is the test for the invariant? If any codepath would break the invariant, the assertion would be triggered. Not on a release build though, I imagine. https://github.com/llvm/llvm-project/pull/93913 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
https://github.com/jimingham updated https://github.com/llvm/llvm-project/pull/94786 >From bcd8c81c5fbc249886c53d8a2d1bc21a3f9e1ffd Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Fri, 7 Jun 2024 11:17:26 -0700 Subject: [PATCH 1/2] Add AllowRepeats to SBCommandInterpreterRunOptions. This is useful if you have a transcript of a user session and want to rerun those commands with RunCommandInterpreter. The same functionality is also useful in testing. --- ...SBCommandInterpreterRunOptionsDocstrings.i | 3 + .../lldb/API/SBCommandInterpreterRunOptions.h | 8 +++ .../lldb/Interpreter/CommandInterpreter.h | 14 - .../API/SBCommandInterpreterRunOptions.cpp| 12 .../source/Interpreter/CommandInterpreter.cpp | 13 - .../TestRunCommandInterpreterAPI.py | 57 +++ 6 files changed, 91 insertions(+), 16 deletions(-) diff --git a/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i b/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i index b37da0535d18a..a4398d95ed0d1 100644 --- a/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i +++ b/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i @@ -10,5 +10,8 @@ A default SBCommandInterpreterRunOptions object has: * PrintResults: true * PrintErrors:true * AddToHistory: true +* AllowRepeatsfalse +Interactive debug sessions always allow repeats, the AllowRepeats +run option only affects non-interactive sessions. ") lldb::SBCommandInterpreterRunOptions; diff --git a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h index 69b969267e755..b32a8ca51cd08 100644 --- a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h +++ b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h @@ -71,6 +71,14 @@ class LLDB_API SBCommandInterpreterRunOptions { bool GetSpawnThread() const; void SetSpawnThread(bool); + + bool GetAllowRepeats() const; + + // By default, RunCommandInterpreter will discard repeats if the + // IOHandler being used is not interactive. Setting AllowRepeats to true + // will override this behavior and always process empty lines in the input + // as a repeat command. + void SetAllowRepeats(bool); private: lldb_private::CommandInterpreterRunOptions *get() const; diff --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h index 8863523b2e31f..5c2bcd99681a4 100644 --- a/lldb/include/lldb/Interpreter/CommandInterpreter.h +++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -93,15 +93,19 @@ class CommandInterpreterRunOptions { /// \param[in] add_to_history ///If \b true add the commands to the command history. If \b false, don't ///add them. + /// \param[in] process_repeats + ///If \b true then process empty lines as repeat commands even if the + ///interpreter is non-interactive. CommandInterpreterRunOptions(LazyBool stop_on_continue, LazyBool stop_on_error, LazyBool stop_on_crash, LazyBool echo_commands, LazyBool echo_comments, LazyBool print_results, LazyBool print_errors, - LazyBool add_to_history) + LazyBool add_to_history, LazyBool process_repeats) : m_stop_on_continue(stop_on_continue), m_stop_on_error(stop_on_error), m_stop_on_crash(stop_on_crash), m_echo_commands(echo_commands), m_echo_comment_commands(echo_comments), m_print_results(print_results), -m_print_errors(print_errors), m_add_to_history(add_to_history) {} +m_print_errors(print_errors), m_add_to_history(add_to_history), +m_allow_repeats(process_repeats) {} CommandInterpreterRunOptions() = default; @@ -182,6 +186,11 @@ class CommandInterpreterRunOptions { void SetSpawnThread(bool spawn_thread) { m_spawn_thread = spawn_thread ? eLazyBoolYes : eLazyBoolNo; } + bool GetAllowRepeats() const { return DefaultToNo(m_allow_repeats); } + + void SetAllowRepeats(bool allow_repeats) { +m_allow_repeats = allow_repeats ? eLazyBoolYes : eLazyBoolNo; + } LazyBool m_stop_on_continue = eLazyBoolCalculate; LazyBool m_stop_on_error = eLazyBoolCalculate; @@ -193,6 +202,7 @@ class CommandInterpreterRunOptions { LazyBool m_add_to_history = eLazyBoolCalculate; LazyBool m_auto_handle_events; LazyBool m_spawn_thread; + LazyBool m_allow_repeats = eLazyBoolCalculate; private: static bool DefaultToYes(LazyBool flag) { diff --git a/lldb/source/API/SBCommandInterpreterRunOptions.cpp b/lldb/source/API/SBCommandInterpreterRunOptions.cpp index 6c6b2aa15a792..0c7581d6f1f5b 100644 --- a/lldb/source/API/SBCommandInterpreterRunOptions.cpp +++ b/lldb/source/API/SBCommandInterpreterRunOptions.cpp @@ -164,6 +164,18 @@ void SBCommandInterpreterRunOptions::SetSpawnThread(bool
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
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 b653357141030620ce3e70ea939efbcb71d40657...bcd8c81c5fbc249886c53d8a2d1bc21a3f9e1ffd lldb/test/API/python_api/interpreter/TestRunCommandInterpreterAPI.py `` View the diff from darker here. ``diff --- TestRunCommandInterpreterAPI.py 2024-06-07 18:17:26.00 + +++ TestRunCommandInterpreterAPI.py 2024-06-07 18:29:38.709767 + @@ -46,22 +46,27 @@ def setUp(self): TestBase.setUp(self) self.stdin_path = self.getBuildArtifact("stdin.txt") self.stdout_path = self.getBuildArtifact("stdout.txt") -def run_commands_string(self, command_string, options = lldb.SBCommandInterpreterRunOptions()): + +def run_commands_string( +self, command_string, options=lldb.SBCommandInterpreterRunOptions() +): """Run the commands in command_string through RunCommandInterpreter. - Returns (n_errors, quit_requested, has_crashed, result_string).""" - +Returns (n_errors, quit_requested, has_crashed, result_string).""" + with open(self.stdin_path, "w") as input_handle: input_handle.write(command_string) n_errors = 0 quit_requested = False has_crashed = False - -with open(self.stdin_path, "r") as in_fileH, open(self.stdout_path, "w") as out_fileH: + +with open(self.stdin_path, "r") as in_fileH, open( +self.stdout_path, "w" +) as out_fileH: self.dbg.SetInputFile(in_fileH) self.dbg.SetOutputFile(out_fileH) self.dbg.SetErrorFile(out_fileH) @@ -73,36 +78,38 @@ with open(self.stdout_path, "r") as out_fileH: result_string = out_fileH.read() print(f"Command: '{command_string}'\nResult:\n{result_string}") return (n_errors, quit_requested, has_crashed, result_string) - def test_run_session_with_error_and_quit(self): """Run non-existing and quit command returns appropriate values""" n_errors, quit_requested, has_crashed, _ = self.run_commands_string( -"nonexistingcommand\nquit\n") +"nonexistingcommand\nquit\n" +) self.assertGreater(n_errors, 0) self.assertTrue(quit_requested) self.assertFalse(has_crashed) def test_allow_repeat(self): """Try auto-repeat of process launch - the command will fail and - the auto-repeat will fail because of no auto-repeat.""" +the auto-repeat will fail because of no auto-repeat.""" options = lldb.SBCommandInterpreterRunOptions() options.SetEchoCommands(False) options.SetAllowRepeats(True) - + n_errors, quit_requested, has_crashed, result_str = self.run_commands_string( -"process launch\n\n", options) +"process launch\n\n", options +) self.assertEqual(n_errors, 2) self.assertFalse(quit_requested) self.assertFalse(has_crashed) self.assertIn("invalid target", result_str) -self.assertIn("No auto repeat", result_str) +self.assertIn("No auto repeat", result_str) + class SBCommandInterpreterRunOptionsCase(TestBase): NO_DEBUG_INFO_TESTCASE = True def test_command_interpreter_run_options(self): `` https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff b653357141030620ce3e70ea939efbcb71d40657 bcd8c81c5fbc249886c53d8a2d1bc21a3f9e1ffd -- lldb/include/lldb/API/SBCommandInterpreterRunOptions.h lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/API/SBCommandInterpreterRunOptions.cpp lldb/source/Interpreter/CommandInterpreter.cpp `` View the diff from clang-format here. ``diff diff --git a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h index b32a8ca51c..c11bf5e404 100644 --- a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h +++ b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h @@ -71,14 +71,14 @@ public: bool GetSpawnThread() const; void SetSpawnThread(bool); - + bool GetAllowRepeats() const; - + // By default, RunCommandInterpreter will discard repeats if the // IOHandler being used is not interactive. Setting AllowRepeats to true // will override this behavior and always process empty lines in the input // as a repeat command. - void SetAllowRepeats(bool); + void SetAllowRepeats(bool); private: lldb_private::CommandInterpreterRunOptions *get() const; diff --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h index 5c2bcd9968..665336fbf8 100644 --- a/lldb/include/lldb/Interpreter/CommandInterpreter.h +++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -100,7 +100,8 @@ public: LazyBool stop_on_error, LazyBool stop_on_crash, LazyBool echo_commands, LazyBool echo_comments, LazyBool print_results, LazyBool print_errors, - LazyBool add_to_history, LazyBool process_repeats) + LazyBool add_to_history, + LazyBool process_repeats) : m_stop_on_continue(stop_on_continue), m_stop_on_error(stop_on_error), m_stop_on_crash(stop_on_crash), m_echo_commands(echo_commands), m_echo_comment_commands(echo_comments), m_print_results(print_results), diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 95b9bb491a..d82662fae9 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -2708,7 +2708,7 @@ enum { eHandleCommandFlagPrintResult = (1u << 4), eHandleCommandFlagPrintErrors = (1u << 5), eHandleCommandFlagStopOnCrash = (1u << 6), - eHandleCommandFlagAllowRepeats = (1u << 7) + eHandleCommandFlagAllowRepeats = (1u << 7) }; void CommandInterpreter::HandleCommandsFromFile( @@ -3130,8 +3130,9 @@ void CommandInterpreter::IOHandlerInputComplete(IOHandler _handler, return; const bool is_interactive = io_handler.GetIsInteractive(); - bool allow_repeats = io_handler.GetFlags().Test(eHandleCommandFlagAllowRepeats); - + bool allow_repeats = + io_handler.GetFlags().Test(eHandleCommandFlagAllowRepeats); + if (!is_interactive && !allow_repeats) { // When we are not interactive, don't execute blank lines. This will happen // sourcing a commands file. We don't want blank lines to repeat the `` https://github.com/llvm/llvm-project/pull/94786 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: None (jimingham) Changes This is useful if you have a transcript of a user session and want to rerun those commands with RunCommandInterpreter. The same functionality is also useful in testing. I'm adding it primarily for the second reason. In a subsequent patch, I'm adding the ability to Python based commands to provide their "auto-repeat" command. Among other things, that will allow potentially state destroying user commands to prevent auto-repeat. Testing this with Shell or pexpect tests is not nearly as accurate or convenient as using RunCommandInterpreter, but to use that I need to allow auto-repeat. I think for consistency's sake, having interactive sessions always do auto-repeats is the right choice, though that's a lightly held opinion... --- Full diff: https://github.com/llvm/llvm-project/pull/94786.diff 6 Files Affected: - (modified) lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i (+3) - (modified) lldb/include/lldb/API/SBCommandInterpreterRunOptions.h (+8) - (modified) lldb/include/lldb/Interpreter/CommandInterpreter.h (+12-2) - (modified) lldb/source/API/SBCommandInterpreterRunOptions.cpp (+12) - (modified) lldb/source/Interpreter/CommandInterpreter.cpp (+10-3) - (modified) lldb/test/API/python_api/interpreter/TestRunCommandInterpreterAPI.py (+46-11) ``diff diff --git a/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i b/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i index b37da0535d18a..a4398d95ed0d1 100644 --- a/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i +++ b/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i @@ -10,5 +10,8 @@ A default SBCommandInterpreterRunOptions object has: * PrintResults: true * PrintErrors:true * AddToHistory: true +* AllowRepeatsfalse +Interactive debug sessions always allow repeats, the AllowRepeats +run option only affects non-interactive sessions. ") lldb::SBCommandInterpreterRunOptions; diff --git a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h index 69b969267e755..b32a8ca51cd08 100644 --- a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h +++ b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h @@ -71,6 +71,14 @@ class LLDB_API SBCommandInterpreterRunOptions { bool GetSpawnThread() const; void SetSpawnThread(bool); + + bool GetAllowRepeats() const; + + // By default, RunCommandInterpreter will discard repeats if the + // IOHandler being used is not interactive. Setting AllowRepeats to true + // will override this behavior and always process empty lines in the input + // as a repeat command. + void SetAllowRepeats(bool); private: lldb_private::CommandInterpreterRunOptions *get() const; diff --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h index 8863523b2e31f..5c2bcd99681a4 100644 --- a/lldb/include/lldb/Interpreter/CommandInterpreter.h +++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -93,15 +93,19 @@ class CommandInterpreterRunOptions { /// \param[in] add_to_history ///If \b true add the commands to the command history. If \b false, don't ///add them. + /// \param[in] process_repeats + ///If \b true then process empty lines as repeat commands even if the + ///interpreter is non-interactive. CommandInterpreterRunOptions(LazyBool stop_on_continue, LazyBool stop_on_error, LazyBool stop_on_crash, LazyBool echo_commands, LazyBool echo_comments, LazyBool print_results, LazyBool print_errors, - LazyBool add_to_history) + LazyBool add_to_history, LazyBool process_repeats) : m_stop_on_continue(stop_on_continue), m_stop_on_error(stop_on_error), m_stop_on_crash(stop_on_crash), m_echo_commands(echo_commands), m_echo_comment_commands(echo_comments), m_print_results(print_results), -m_print_errors(print_errors), m_add_to_history(add_to_history) {} +m_print_errors(print_errors), m_add_to_history(add_to_history), +m_allow_repeats(process_repeats) {} CommandInterpreterRunOptions() = default; @@ -182,6 +186,11 @@ class CommandInterpreterRunOptions { void SetSpawnThread(bool spawn_thread) { m_spawn_thread = spawn_thread ? eLazyBoolYes : eLazyBoolNo; } + bool GetAllowRepeats() const { return DefaultToNo(m_allow_repeats); } + + void SetAllowRepeats(bool allow_repeats) { +m_allow_repeats = allow_repeats ? eLazyBoolYes : eLazyBoolNo; + } LazyBool m_stop_on_continue = eLazyBoolCalculate; LazyBool m_stop_on_error = eLazyBoolCalculate; @@ -193,6 +202,7 @@ class CommandInterpreterRunOptions { LazyBool m_add_to_history = eLazyBoolCalculate;
[Lldb-commits] [lldb] Add AllowRepeats to SBCommandInterpreterRunOptions. (PR #94786)
https://github.com/jimingham created https://github.com/llvm/llvm-project/pull/94786 This is useful if you have a transcript of a user session and want to rerun those commands with RunCommandInterpreter. The same functionality is also useful in testing. I'm adding it primarily for the second reason. In a subsequent patch, I'm adding the ability to Python based commands to provide their "auto-repeat" command. Among other things, that will allow potentially state destroying user commands to prevent auto-repeat. Testing this with Shell or pexpect tests is not nearly as accurate or convenient as using RunCommandInterpreter, but to use that I need to allow auto-repeat. I think for consistency's sake, having interactive sessions always do auto-repeats is the right choice, though that's a lightly held opinion... >From bcd8c81c5fbc249886c53d8a2d1bc21a3f9e1ffd Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Fri, 7 Jun 2024 11:17:26 -0700 Subject: [PATCH] Add AllowRepeats to SBCommandInterpreterRunOptions. This is useful if you have a transcript of a user session and want to rerun those commands with RunCommandInterpreter. The same functionality is also useful in testing. --- ...SBCommandInterpreterRunOptionsDocstrings.i | 3 + .../lldb/API/SBCommandInterpreterRunOptions.h | 8 +++ .../lldb/Interpreter/CommandInterpreter.h | 14 - .../API/SBCommandInterpreterRunOptions.cpp| 12 .../source/Interpreter/CommandInterpreter.cpp | 13 - .../TestRunCommandInterpreterAPI.py | 57 +++ 6 files changed, 91 insertions(+), 16 deletions(-) diff --git a/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i b/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i index b37da0535d18a..a4398d95ed0d1 100644 --- a/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i +++ b/lldb/bindings/interface/SBCommandInterpreterRunOptionsDocstrings.i @@ -10,5 +10,8 @@ A default SBCommandInterpreterRunOptions object has: * PrintResults: true * PrintErrors:true * AddToHistory: true +* AllowRepeatsfalse +Interactive debug sessions always allow repeats, the AllowRepeats +run option only affects non-interactive sessions. ") lldb::SBCommandInterpreterRunOptions; diff --git a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h index 69b969267e755..b32a8ca51cd08 100644 --- a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h +++ b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h @@ -71,6 +71,14 @@ class LLDB_API SBCommandInterpreterRunOptions { bool GetSpawnThread() const; void SetSpawnThread(bool); + + bool GetAllowRepeats() const; + + // By default, RunCommandInterpreter will discard repeats if the + // IOHandler being used is not interactive. Setting AllowRepeats to true + // will override this behavior and always process empty lines in the input + // as a repeat command. + void SetAllowRepeats(bool); private: lldb_private::CommandInterpreterRunOptions *get() const; diff --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h index 8863523b2e31f..5c2bcd99681a4 100644 --- a/lldb/include/lldb/Interpreter/CommandInterpreter.h +++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -93,15 +93,19 @@ class CommandInterpreterRunOptions { /// \param[in] add_to_history ///If \b true add the commands to the command history. If \b false, don't ///add them. + /// \param[in] process_repeats + ///If \b true then process empty lines as repeat commands even if the + ///interpreter is non-interactive. CommandInterpreterRunOptions(LazyBool stop_on_continue, LazyBool stop_on_error, LazyBool stop_on_crash, LazyBool echo_commands, LazyBool echo_comments, LazyBool print_results, LazyBool print_errors, - LazyBool add_to_history) + LazyBool add_to_history, LazyBool process_repeats) : m_stop_on_continue(stop_on_continue), m_stop_on_error(stop_on_error), m_stop_on_crash(stop_on_crash), m_echo_commands(echo_commands), m_echo_comment_commands(echo_comments), m_print_results(print_results), -m_print_errors(print_errors), m_add_to_history(add_to_history) {} +m_print_errors(print_errors), m_add_to_history(add_to_history), +m_allow_repeats(process_repeats) {} CommandInterpreterRunOptions() = default; @@ -182,6 +186,11 @@ class CommandInterpreterRunOptions { void SetSpawnThread(bool spawn_thread) { m_spawn_thread = spawn_thread ? eLazyBoolYes : eLazyBoolNo; } + bool GetAllowRepeats() const { return DefaultToNo(m_allow_repeats); } + + void SetAllowRepeats(bool allow_repeats) { +m_allow_repeats = allow_repeats ? eLazyBoolYes : eLazyBoolNo; + }
[Lldb-commits] [lldb] [llvm] [lldb] Encode operands and arity in Dwarf.def and use them in LLDB. (PR #94679)
https://github.com/adrian-prantl approved this pull request. https://github.com/llvm/llvm-project/pull/94679 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] [NFC] Fix a cppcheck warning in lldb/source/Utility/Scalar.cpp (PR #94775)
xgupta wrote: > The change LGTM, but I have a few suggestions regarding the title and > description: > > * Retitle the PR to something like "[lldb] Remove dead code block (NFC)" > or something that conveys the intent/outcome. The modified file and line > number are already part of the commit and are just redundant. You could > mention it was found by `cppcheck` if you think that's useful. > > * Update the description to explain why this code block is dead. > Something along the lines of "The check that `max_bit_pos == sign_bit_pos` > conflicts with the check that `sign_bit_pos < max_bit_pos` in the block > surrounding it" or something like that. Definitely mention the issue but > don't just repeat the warning without enough context to make sense of it. Thanks, will update other PR also as your suggested. https://github.com/llvm/llvm-project/pull/94775 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Fix a cppcheck warning in Platform/Android/PlatformAndroid.cpp (PR #94785)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Shivam Gupta (xgupta) Changes lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp:290:19: performance: Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr] Fix #91211 --- Full diff: https://github.com/llvm/llvm-project/pull/94785.diff 1 Files Affected: - (modified) lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp (+1-1) ``diff diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp index e177c134fea20..6367763dd8b4a 100644 --- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp +++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp @@ -287,7 +287,7 @@ Status PlatformAndroid::DownloadModuleSlice(const FileSpec _file_spec, static constexpr llvm::StringLiteral k_zip_separator("!/"); size_t pos = source_file.find(k_zip_separator); if (pos != std::string::npos) -source_file = source_file.substr(0, pos); +source_file = source_file.resize(0, pos); Status error; AdbClientUP adb(GetAdbClient(error)); `` https://github.com/llvm/llvm-project/pull/94785 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Fix a cppcheck warning in Platform/Android/PlatformAndroid.cpp (PR #94785)
https://github.com/xgupta edited https://github.com/llvm/llvm-project/pull/94785 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Fix a cppcheck warning in Platform/Android/PlatformAndroid.cpp (PR #94785)
https://github.com/xgupta created https://github.com/llvm/llvm-project/pull/94785 Fix #91211 >From 6ec5b1a005b7551f2857b30e2461d297e7febfa3 Mon Sep 17 00:00:00 2001 From: Shivam Gupta Date: Fri, 7 Jun 2024 23:44:49 +0530 Subject: [PATCH] [LLDB][NFC] Fix a cppcheck warning in Platform/Android/PlatformAndroid.cpp Fix #91211 --- lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp index e177c134fea20..6367763dd8b4a 100644 --- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp +++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp @@ -287,7 +287,7 @@ Status PlatformAndroid::DownloadModuleSlice(const FileSpec _file_spec, static constexpr llvm::StringLiteral k_zip_separator("!/"); size_t pos = source_file.find(k_zip_separator); if (pos != std::string::npos) -source_file = source_file.substr(0, pos); +source_file = source_file.resize(0, pos); Status error; AdbClientUP adb(GetAdbClient(error)); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Fix a cppcheck warning in lldb/source/Host/linux/Host.cpp (PR #94783)
https://github.com/JDevlieghere requested changes to this pull request. Similar concern as https://github.com/llvm/llvm-project/pull/94775#issuecomment-2155285000 https://github.com/llvm/llvm-project/pull/94783 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Fix a cppcheck warning in Python/Interfaces/ScriptedPythonInterface.h (PR #94779)
https://github.com/JDevlieghere requested changes to this pull request. Similar comment as https://github.com/llvm/llvm-project/pull/94775#issuecomment-2155285000 https://github.com/llvm/llvm-project/pull/94779 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits