[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)
taalhaataahir0102 wrote: Hi David! I've updated the feedback. I got your point of somehow embedding the use-color and name in a single argument. Now we're doing the following: In the very first function (`LookupSymbolInModule`) which calls other dump: ``` bool use_color = interpreter.GetDebugger().GetUseColor(); if (name && use_color){ DumpAddress( interpreter.GetExecutionContext().GetBestExecutionContextScope(), symbol->GetAddressRef(), verbose, all_ranges, strm, name); } else{ DumpAddress( interpreter.GetExecutionContext().GetBestExecutionContextScope(), symbol->GetAddressRef(), verbose, all_ranges, strm); } ``` As the program should only go inside the re-pattern (new name of printRed ;-) function if use-color is true and name is not null. Hence if this condition `if (name && use_color)` is not true, I'm using the Dump function which has `nullptr` as the default value of variable name. Plus I've also updated the test cases and re-pattern function according to the feedback. Just 2 things are left: 1. Writing a test case for no symbol match. > Also just for sanity checking, add one where you don't match anything at all. > It shouldn't do any matching or even attempt to, so the test would just > ensure that it doesn't try and end up crashing. > > The classic "nothing in, nothing out" test case. So it will match 0 symbols > but that's what we expect. Was facing some issues while checking for empty string using: ``` # RUN: %lldb %t -b -o 'settings set use-color true' -o 'image lookup -r -s .*o132we$' | FileCheck %s --check-prefix CHECK5 # CHECK5-EMPTY: ``` But getting this error: ``` error: found non-empty check string for empty check with prefix 'CHECK5:' # CHECK5-EMPTY: ``` 2. Avoiding string copy in re-pattern function > You can avoid some string copies by: > > 1. Passing the StringRef to this function, instead of converting it to > std::string and then getting a char* from that. > 2. Then using StringRef's `.begin` and `.end` in the `next` iterator. If it > doesn't like the type you can build the begin/end from `.bytes_begin` and > `.bytes_end` instead. Those give you char* instead. > > Basically StringRef is a "view" onto a string, so as long as we know where it > ends we can iterate over that instead of a new copy of it. Was having issues while using both `.begin()` and `.bytes_begin()` But I'll look into both of these remaining things. For the test case maybe I will try to check the length of the output to be zero and for String reference I'll look more in to the `begin` and `bytes_begin` functions. Will update you shortly on these two. Other than that can you please provide feedback on this commit and any other stuff which needs to be done :) https://github.com/llvm/llvm-project/pull/69422 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)
taalhaataahir0102 wrote: Added the wrong test case in the previous commit by mistake. Have removed it in the new one :/ Sorry for the inconvenience https://github.com/llvm/llvm-project/pull/69422 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [clang][DebugInfo] Emit global variable definitions for static data members with constant initializers (PR #70639)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/70639 >From 81bd54091451eb2021007bc10b8a7c6965178800 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Fri, 27 Oct 2023 16:19:47 +0100 Subject: [PATCH 1/8] [clang][DebugInfo] Emit global variable definitions for static data members with constant initializers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When an LLDB user asks for the value of a static data member, LLDB starts by searching the Names accelerator table for the corresponding variable definition DIE. For static data members with out-of-class definitions that works fine, because those get represented as global variables with a location and making them eligible to be added to the Names table. However, in-class definitions won’t get indexed because we usually don't emit global variables for them. So in DWARF we end up with a single `DW_TAG_member` that usually holds the constant initializer. But we don't get a corresponding CU-level `DW_TAG_variable` like we do for out-of-class definitions. To make it more convenient for debuggers to get to the value of inline static data members, this patch makes sure we emit definitions for static variables with constant initializers the same way we do for other static variables. This also aligns Clang closer to GCC, which produces CU-level definitions for inline statics and also emits these into `.debug_pubnames`. The implementation keeps track of newly created static data members. Then in `CGDebugInfo::finalize`, we emit a global `DW_TAG_variable` with a `DW_AT_const_value` for any of those declarations that didn't end up with a definition in the `DeclCache`. The newly emitted `DW_TAG_variable` will look as follows: ``` 0x007b: DW_TAG_structure_type DW_AT_calling_convention(DW_CC_pass_by_value) DW_AT_name ("Foo") ... 0x008d: DW_TAG_member DW_AT_name("i") DW_AT_type(0x0062 "const int") DW_AT_external(true) DW_AT_declaration (true) DW_AT_const_value (4) Newly added v 0x009a: DW_TAG_variable DW_AT_specification (0x008d "i") DW_AT_const_value (4) DW_AT_linkage_name ("_ZN2t2IiE1iIfEE") ``` --- clang/lib/CodeGen/CGDebugInfo.cpp | 46 +++ clang/lib/CodeGen/CGDebugInfo.h | 6 ++ clang/test/CodeGenCXX/debug-info-class.cpp| 13 ++- .../debug-info-static-inline-member.cpp | 79 +++ .../TestConstStaticIntegralMember.py | 7 +- 5 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 clang/test/CodeGenCXX/debug-info-static-inline-member.cpp diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 84a166d3ac3659c..167cc92a62c2d84 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1693,6 +1693,7 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, llvm::DIType *RecordTy, llvm::DIDerivedType *GV = DBuilder.createStaticMemberType( RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Align); StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV); + StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl()); return GV; } @@ -5596,6 +5597,39 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) { TemplateParameters, Align)); } +void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) { + assert(VD->hasInit()); + assert(CGM.getCodeGenOpts().hasReducedDebugInfo()); + if (VD->hasAttr()) +return; + + auto &GV = DeclCache[VD]; + if (GV) +return; + + auto const *InitVal = VD->evaluateValue(); + if (!InitVal) +return; + + llvm::DIFile *Unit = nullptr; + llvm::DIScope *DContext = nullptr; + unsigned LineNo; + StringRef DeclName, LinkageName; + QualType T; + llvm::MDTuple *TemplateParameters = nullptr; + collectVarDeclProps(VD, Unit, LineNo, T, DeclName, LinkageName, + TemplateParameters, DContext); + + auto Align = getDeclAlignIfRequired(VD, CGM.getContext()); + llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(VD); + llvm::DIExpression *InitExpr = createConstantValueExpression(VD, *InitVal); + + GV.reset(DBuilder.createGlobalVariableExpression( + TheCU, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit), + true, true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VD), + TemplateParameters, Align, Annotations)); +} + void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var, const VarDecl *D) { assert(CGM.getCodeGenOpts().hasReducedDebugInfo()); @@ -5866,6 +5900,18 @@ void CGDebugInfo::finalize() {
[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)
DavidSpickett wrote: > Was facing some issues while checking for empty string using: You don't need to check for an empty string here. You're checking that it found 0 symbols, that's the string you want (which will be colourless of course). The check for this is not "check my functions did the right thing" it's more "check that this RUN put lldb into the state I think they should do". What the test wants to see is that lldb did not crash because it tried to add colours to 0 symbols. The CHECK is case in future this RUN starts finding a symbol. If it found a symbol, it wouldn't be testing the case where your code is not run. Or rather, should not be run, but if you had made a mistake, it might be. Again, this is a "nop" test, no symbols in, no coloured output out. Seems like you wouldn't need to test it, but we all make silly mistakes sometimes so it's nice to have. https://github.com/llvm/llvm-project/pull/69422 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 4909814 - [clang][DebugInfo] Emit global variable definitions for static data members with constant initializers (#70639)
Author: Michael Buch Date: 2023-11-06T10:23:26Z New Revision: 4909814c08fdf4ec8bd9dad4f157d03de7c3c800 URL: https://github.com/llvm/llvm-project/commit/4909814c08fdf4ec8bd9dad4f157d03de7c3c800 DIFF: https://github.com/llvm/llvm-project/commit/4909814c08fdf4ec8bd9dad4f157d03de7c3c800.diff LOG: [clang][DebugInfo] Emit global variable definitions for static data members with constant initializers (#70639) When an LLDB user asks for the value of a static data member, LLDB starts by searching the Names accelerator table for the corresponding variable definition DIE. For static data members with out-of-class definitions that works fine, because those get represented as global variables with a location and making them eligible to be added to the Names table. However, in-class definitions won’t get indexed because we usually don't emit global variables for them. So in DWARF we end up with a single `DW_TAG_member` that usually holds the constant initializer. But we don't get a corresponding CU-level `DW_TAG_variable` like we do for out-of-class definitions. To make it more convenient for debuggers to get to the value of inline static data members, this patch makes sure we emit definitions for static variables with constant initializers the same way we do for other static variables. This also aligns Clang closer to GCC, which produces CU-level definitions for inline statics and also emits these into `.debug_pubnames`. The implementation keeps track of newly created static data members. Then in `CGDebugInfo::finalize`, we emit a global `DW_TAG_variable` with a `DW_AT_const_value` for any of those declarations that didn't end up with a definition in the `DeclCache`. The newly emitted `DW_TAG_variable` will look as follows: ``` 0x007b: DW_TAG_structure_type DW_AT_calling_convention(DW_CC_pass_by_value) DW_AT_name ("Foo") ... 0x008d: DW_TAG_member DW_AT_name("i") DW_AT_type(0x0062 "const int") DW_AT_external(true) DW_AT_declaration (true) DW_AT_const_value (4) Newly added v 0x009a: DW_TAG_variable DW_AT_specification (0x008d "i") DW_AT_const_value (4) DW_AT_linkage_name ("_ZN2t2IiE1iIfEE") ``` This patch also drops the `DW_AT_const_value` off of the declaration since we now always have it on the definition. This ensures that the `DWARFParallelLinker` can type-merge class with static members where we couldn't attach the constant on the declaration in some CUs. Added: clang/test/CodeGenCXX/debug-info-static-inline-member.cpp Modified: clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CGDebugInfo.h clang/test/CodeGenCXX/debug-info-class.cpp clang/test/CodeGenCXX/debug-info-static-member.cpp lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py Removed: diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 84a166d3ac3659c..410c8f522b1017f 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1677,22 +1677,13 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, llvm::DIType *RecordTy, unsigned LineNumber = getLineNumber(Var->getLocation()); StringRef VName = Var->getName(); - llvm::Constant *C = nullptr; - if (Var->getInit()) { -const APValue *Value = Var->evaluateValue(); -if (Value) { - if (Value->isInt()) -C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt()); - if (Value->isFloat()) -C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat()); -} - } llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD); auto Align = getDeclAlignIfRequired(Var, CGM.getContext()); llvm::DIDerivedType *GV = DBuilder.createStaticMemberType( - RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Align); + RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr, Align); StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV); + StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl()); return GV; } @@ -5596,6 +5587,39 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) { TemplateParameters, Align)); } +void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) { + assert(VD->hasInit()); + assert(CGM.getCodeGenOpts().hasReducedDebugInfo()); + if (VD->hasAttr()) +return; + + auto &GV = DeclCache[VD]; + if (GV) +return; + + auto const *InitVal = VD->evaluateValue(); + if (!InitVal) +return; + + llvm::DIFile *Unit = nullptr; + llv
[Lldb-commits] [lldb] [clang] [clang][DebugInfo] Emit global variable definitions for static data members with constant initializers (PR #70639)
https://github.com/Michael137 closed https://github.com/llvm/llvm-project/pull/70639 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 934c573 - [lldb][test] Add FindGlobalVariables tests for C++ inline static data members (#70641)
Author: Michael Buch Date: 2023-11-06T10:23:47Z New Revision: 934c573b7d24327fafea916a1d0e9a9fc88f87ab URL: https://github.com/llvm/llvm-project/commit/934c573b7d24327fafea916a1d0e9a9fc88f87ab DIFF: https://github.com/llvm/llvm-project/commit/934c573b7d24327fafea916a1d0e9a9fc88f87ab.diff LOG: [lldb][test] Add FindGlobalVariables tests for C++ inline static data members (#70641) Tests that LLDB can find inline static data members. Relies on the debug-info change in: https://github.com/llvm/llvm-project/pull/70639 Added: Modified: lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py Removed: diff --git a/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py b/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py index 78ea23ac8f70610..eb679b24b8fcc36 100644 --- a/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py +++ b/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py @@ -114,6 +114,39 @@ def test_class_with_only_const_static(self): self.expect_expr("ClassWithOnlyConstStatic::member", result_value="3") +def check_global_var(self, name: str, expect_type, expect_val): +var_list = self.target().FindGlobalVariables(name, lldb.UINT32_MAX) +self.assertEqual(len(var_list), 1) +varobj = var_list[0] +self.assertEqual(varobj.type.name, expect_type) +self.assertEqual(varobj.value, expect_val) + +# For debug-info produced by older versions of clang, inline static data members +# wouldn't get indexed into the Names accelerator table preventing LLDB from finding +# them. +@expectedFailureAll(compiler=["clang"], compiler_version=["<", "18.0"]) +@expectedFailureAll(debug_info=no_match(["dsym"])) +def test_inline_static_members(self): +self.build() +lldbutil.run_to_source_breakpoint( +self, "// break here", lldb.SBFileSpec("main.cpp") +) + +self.check_global_var("A::int_val", "const int", "1") +self.check_global_var("A::int_val_with_address", "const int", "2") +self.check_global_var("A::bool_val", "const bool", "true") +self.check_global_var("A::enum_val", "Enum", "enum_case2") +self.check_global_var("A::enum_bool_val", "EnumBool", "enum_bool_case1") +self.check_global_var("A::scoped_enum_val", "ScopedEnum", "scoped_enum_case2") + +self.check_global_var("ClassWithOnlyConstStatic::member", "const int", "3") + +self.check_global_var("ClassWithConstexprs::member", "const int", "2") +self.check_global_var("ClassWithConstexprs::enum_val", "Enum", "enum_case2") +self.check_global_var( +"ClassWithConstexprs::scoped_enum_val", "ScopedEnum", "scoped_enum_case2" +) + # With older versions of Clang, LLDB fails to evaluate classes with only # constexpr members when dsymutil is enabled @expectedFailureAll( ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][test] Add FindGlobalVariables tests for C++ inline static data members (PR #70641)
https://github.com/Michael137 closed https://github.com/llvm/llvm-project/pull/70641 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] ef3feba - [lldb][DWARFASTParserClang] Fetch constant value from variable defintion if available (#71004)
Author: Michael Buch Date: 2023-11-06T10:24:05Z New Revision: ef3febadf606c2fc4f1ad8d85a7ecdde16e4cbb3 URL: https://github.com/llvm/llvm-project/commit/ef3febadf606c2fc4f1ad8d85a7ecdde16e4cbb3 DIFF: https://github.com/llvm/llvm-project/commit/ef3febadf606c2fc4f1ad8d85a7ecdde16e4cbb3.diff LOG: [lldb][DWARFASTParserClang] Fetch constant value from variable defintion if available (#71004) https://github.com/llvm/llvm-project/pull/70639 proposes moving the `DW_AT_const_value` on inline static members from the declaration DIE to the definition DIE. This patch makes sure the LLDB's expression evaluator can continue to support static initialisers even if the declaration doesn't have a `DW_AT_const_value` anymore. Previously the expression evaluator would find the constant for a VarDecl from its declaration `DW_TAG_member` DIE. In cases where the initialiser was specified out-of-class, LLDB could find it during symbol resolution. However, neither of those will work for constants, since we don't have a constant attribute on the declaration anymore and we don't have constants in the symbol table. **Testing** * If https://github.com/llvm/llvm-project/pull/70639 were to land without this patch then most of the `TestConstStaticIntegralMember.py` would start failing Added: Modified: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py lldb/test/API/lang/cpp/const_static_integral_member/main.cpp Removed: diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index 3174c18c97d888c..4e41858674467a3 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -31,6 +31,7 @@ #include "lldb/Symbol/SymbolFile.h" #include "lldb/Symbol/TypeList.h" #include "lldb/Symbol/TypeMap.h" +#include "lldb/Symbol/VariableList.h" #include "lldb/Target/Language.h" #include "lldb/Utility/LLDBAssert.h" #include "lldb/Utility/Log.h" @@ -133,6 +134,54 @@ static lldb::ModuleSP GetContainingClangModule(const DWARFDIE &die) { return lldb::ModuleSP(); } +std::optional +DWARFASTParserClang::FindConstantOnVariableDefinition(DWARFDIE die) { + assert(die.Tag() == llvm::dwarf::DW_TAG_member); + + auto *dwarf = die.GetDWARF(); + if (!dwarf) +return {}; + + ConstString name{die.GetName()}; + if (!name) +return {}; + + auto *CU = die.GetCU(); + if (!CU) +return {}; + + DWARFASTParser *dwarf_ast = dwarf->GetDWARFParser(*CU); + auto parent_decl_ctx = dwarf_ast->GetDeclContextContainingUIDFromDWARF(die); + + // Make sure we populate the GetDieToVariable cache. + VariableList variables; + dwarf->FindGlobalVariables(name, parent_decl_ctx, UINT_MAX, variables); + + // The cache contains the variable definition whose DW_AT_specification + // points to our declaration DIE. Look up that definition using our + // declaration. + auto const &die_to_var = dwarf->GetDIEToVariable(); + auto it = die_to_var.find(die.GetDIE()); + if (it == die_to_var.end()) +return {}; + + auto var_sp = it->getSecond(); + assert(var_sp != nullptr); + + if (!var_sp->GetLocationIsConstantValueData()) +return {}; + + auto def = dwarf->GetDIE(var_sp->GetID()); + auto def_attrs = def.GetAttributes(); + DWARFFormValue form_value; + if (!def_attrs.ExtractFormValueAtIndex( + def_attrs.FindAttributeIndex(llvm::dwarf::DW_AT_const_value), + form_value)) +return {}; + + return form_value; +} + TypeSP DWARFASTParserClang::ParseTypeFromClangModule(const SymbolContext &sc, const DWARFDIE &die, Log *log) { @@ -2906,9 +2955,21 @@ void DWARFASTParserClang::ParseSingleMember( bool unused; // TODO: Support float/double static members as well. - if (!attrs.const_value_form || !ct.IsIntegerOrEnumerationType(unused)) + if (!ct.IsIntegerOrEnumerationType(unused)) return; + // Newer versions of Clang don't emit the DW_AT_const_value + // on the declaration of an inline static data member. Instead + // it's attached to the definition DIE. If that's the case, + // try and fetch it. + if (!attrs.const_value_form) { +auto maybe_form_value = FindConstantOnVariableDefinition(die); +if (!maybe_form_value) + return; + +attrs.const_value_form = *maybe_form_value; + } + llvm::Expected const_value_or_err = ExtractIntFromFormValue(ct, *attrs.const_value_form); if (!const_value_or_err) { diff --git a/lldb/source/Plugins/S
[Lldb-commits] [lldb] [lldb][DWARFASTParserClang] Fetch constant value from variable defintion if available (PR #71004)
https://github.com/Michael137 closed https://github.com/llvm/llvm-project/pull/71004 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][test] TestVTableValue.py: skip test for older versions of clang (PR #71372)
https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/71372 This fails on the matrix build bot for Clang versions < 9.0 https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake-matrix/7309/execution/node/102/log/?consoleFull ``` FAIL: LLDB :: test_vtable (TestVTableValue.TestVTableValue) : success == FAIL: test_base_class_ptr (TestVTableValue.TestVTableValue) -- Traceback (most recent call last): File "lldb/test/API/functionalities/vtable/TestVTableValue.py", line 90, in test_base_class_ptr self.assertEquals(shape_ptr_vtable.GetNumChildren(), 5) AssertionError: 6 != 5 == FAIL: test_vtable (TestVTableValue.TestVTableValue) -- Traceback (most recent call last): File "lldb/test/API/functionalities/vtable/TestVTableValue.py", line 67, in test_vtable self.assertEquals(vtable.GetNumChildren(), 5) AssertionError: 6 != 5 -- Ran 4 tests in 2.799s RESULT: FAILED (2 passes, 2 failures, 0 errors, 0 skipped, 0 expected failures, 0 unexpected successes) ``` >From 9c8f75c500ccfb8ad2585124c05d2137f7dd9fd6 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 6 Nov 2023 10:28:49 + Subject: [PATCH] [lldb][test] TestVTableValue.py: skip test for older versions of clang This fails on the matrix build bot for Clang versions < 9.0 --- lldb/test/API/functionalities/vtable/TestVTableValue.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lldb/test/API/functionalities/vtable/TestVTableValue.py b/lldb/test/API/functionalities/vtable/TestVTableValue.py index 1c238ad60739bd9..ff1dc7a6cdba189 100644 --- a/lldb/test/API/functionalities/vtable/TestVTableValue.py +++ b/lldb/test/API/functionalities/vtable/TestVTableValue.py @@ -14,6 +14,7 @@ class TestVTableValue(TestBase): # each debug info format. NO_DEBUG_INFO_TESTCASE = True +@skipIf(compiler="clang", compiler_version=["<", "9.0"]) @skipUnlessPlatform(["linux", "macosx"]) def test_vtable(self): self.build() ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][test] TestVTableValue.py: skip test for older versions of clang (PR #71372)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) Changes This fails on the matrix build bot for Clang versions < 9.0 https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake-matrix/7309/execution/node/102/log/?consoleFull ``` FAIL: LLDB :: test_vtable (TestVTableValue.TestVTableValue): success == FAIL: test_base_class_ptr (TestVTableValue.TestVTableValue) -- Traceback (most recent call last): File "lldb/test/API/functionalities/vtable/TestVTableValue.py", line 90, in test_base_class_ptr self.assertEquals(shape_ptr_vtable.GetNumChildren(), 5) AssertionError: 6 != 5 == FAIL: test_vtable (TestVTableValue.TestVTableValue) -- Traceback (most recent call last): File "lldb/test/API/functionalities/vtable/TestVTableValue.py", line 67, in test_vtable self.assertEquals(vtable.GetNumChildren(), 5) AssertionError: 6 != 5 -- Ran 4 tests in 2.799s RESULT: FAILED (2 passes, 2 failures, 0 errors, 0 skipped, 0 expected failures, 0 unexpected successes) ``` --- Full diff: https://github.com/llvm/llvm-project/pull/71372.diff 1 Files Affected: - (modified) lldb/test/API/functionalities/vtable/TestVTableValue.py (+1) ``diff diff --git a/lldb/test/API/functionalities/vtable/TestVTableValue.py b/lldb/test/API/functionalities/vtable/TestVTableValue.py index 1c238ad60739bd9..ff1dc7a6cdba189 100644 --- a/lldb/test/API/functionalities/vtable/TestVTableValue.py +++ b/lldb/test/API/functionalities/vtable/TestVTableValue.py @@ -14,6 +14,7 @@ class TestVTableValue(TestBase): # each debug info format. NO_DEBUG_INFO_TESTCASE = True +@skipIf(compiler="clang", compiler_version=["<", "9.0"]) @skipUnlessPlatform(["linux", "macosx"]) def test_vtable(self): self.build() `` https://github.com/llvm/llvm-project/pull/71372 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][DWARFASTParserClang] Fetch constant value from variable defintion if available (PR #71004)
Michael137 wrote: Looks like this caused a build test failure on linux for `lang/cpp/symbols/TestSymbols.test_dwo`: ``` make VPATH=/home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/lang/cpp/symbols -C /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/lang/cpp/symbols/TestSymbols.test_dwo -I /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/lang/cpp/symbols -I /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/packages/Python/lldbsuite/test/make -f /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/lang/cpp/symbols/TestSymbols.test_dwo/Makefile MAKE_DSYM=NO MAKE_DWO=YES all ARCH=x86_64 'CC="/home/worker/2.0.1/lldb-x86_64-debian/build/bin/clang"' CLANG_MODULE_CACHE_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/module-cache-clang/lldb-api make: Entering directory '/home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/lang/cpp/symbols/TestSymbols.test_dwo' "/home/worker/2.0.1/lldb-x86_64-debian/build/bin/clang" -std=c++11 -std=c++11 -g -O0 -m64 -I/home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../../include -I/home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/lang/cpp/symbols/TestSymbols.test_dwo -I/home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/packages/Python/lldbsuite/test/make -include /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h -fno-limit-debug-info -gsplit-dwarf--driver-mode=g++ -MT main.o -MD -MP -MF main.d -c -o main.o /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/lang/cpp/symbols/main.cpp "/home/worker/2.0.1/lldb-x86_64-debian/build/bin/clang" main.o -g -O0 -m64 -I/home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../../include -I/home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/lang/cpp/symbols/TestSymbols.test_dwo -I/home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/packages/Python/lldbsuite/test/make -include /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h -fno-limit-debug-info -gsplit-dwarf--driver-mode=g++ -o "a.out" make: Leaving directory '/home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/lang/cpp/symbols/TestSymbols.test_dwo' runCmd: expression -- D::i PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. HandleCommand(command = "expression -- D::i") 1. :1:4: current parser token 'i' 2. :44:1: parsing function body '$__lldb_expr' 3. :44:1: in compound statement ('{}') Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it): 0 _lldb.cpython-39-x86_64-linux-gnu.so 0x7fbcfcb08b87 1 _lldb.cpython-39-x86_64-linux-gnu.so 0x7fbcfcb067ae 2 _lldb.cpython-39-x86_64-linux-gnu.so 0x7fbcfcb0923f 3 libpthread.so.0 0x7fbd07ab7140 ``` https://github.com/llvm/llvm-project/pull/71004 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [compiler-rt] [llvm] [clang-tools-extra] [clang] [lldb] [libcxx] [libc] [flang] [sanitizer][msan] fix AArch64 vararg support for KMSAN (PR #70660)
https://github.com/ramosian-glider updated https://github.com/llvm/llvm-project/pull/70660 >From 3be71f474ee11326567458c8145c3b4e56031189 Mon Sep 17 00:00:00 2001 From: Alexander Potapenko Date: Mon, 30 Oct 2023 12:18:47 +0100 Subject: [PATCH 1/2] [sanitizer][msan] fix AArch64 vararg support for KMSAN Cast StackSaveAreaPtr, GrRegSaveAreaPtr, VrRegSaveAreaPtr to pointers to fix assertions in getShadowOriginPtrKernel(). Fixes: https://github.com/llvm/llvm-project/issues/69738 Patch by Mark Johnston. --- .../Instrumentation/MemorySanitizer.cpp | 10 ++-- .../MemorySanitizer/AArch64/vararg-kmsan.ll | 51 +++ .../MemorySanitizer/X86/vararg.ll | 1 + 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg-kmsan.ll diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index e72db2d9d770eef..315d7c96ec65390 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -5258,21 +5258,25 @@ struct VarArgAArch64Helper : public VarArgHelper { // we need to adjust the offset for both GR and VR fields based on // the __{gr,vr}_offs value (since they are stores based on incoming // named arguments). + Type *RegSaveAreaPtrTy = IRB.getInt8PtrTy(); // Read the stack pointer from the va_list. - Value *StackSaveAreaPtr = getVAField64(IRB, VAListTag, 0); + Value *StackSaveAreaPtr = + IRB.CreateIntToPtr(getVAField64(IRB, VAListTag, 0), RegSaveAreaPtrTy); // Read both the __gr_top and __gr_off and add them up. Value *GrTopSaveAreaPtr = getVAField64(IRB, VAListTag, 8); Value *GrOffSaveArea = getVAField32(IRB, VAListTag, 24); - Value *GrRegSaveAreaPtr = IRB.CreateAdd(GrTopSaveAreaPtr, GrOffSaveArea); + Value *GrRegSaveAreaPtr = IRB.CreateIntToPtr( + IRB.CreateAdd(GrTopSaveAreaPtr, GrOffSaveArea), RegSaveAreaPtrTy); // Read both the __vr_top and __vr_off and add them up. Value *VrTopSaveAreaPtr = getVAField64(IRB, VAListTag, 16); Value *VrOffSaveArea = getVAField32(IRB, VAListTag, 28); - Value *VrRegSaveAreaPtr = IRB.CreateAdd(VrTopSaveAreaPtr, VrOffSaveArea); + Value *VrRegSaveAreaPtr = IRB.CreateIntToPtr( + IRB.CreateAdd(VrTopSaveAreaPtr, VrOffSaveArea), RegSaveAreaPtrTy); // It does not know how many named arguments is being used and, on the // callsite all the arguments were saved. Since __gr_off is defined as diff --git a/llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg-kmsan.ll b/llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg-kmsan.ll new file mode 100644 index 000..2189424cd76faaf --- /dev/null +++ b/llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg-kmsan.ll @@ -0,0 +1,51 @@ +; RUN: opt < %s -S -passes=msan -msan-kernel=1 2>&1 | FileCheck %s + +target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128" +target triple = "aarch64-unknown-linux-gnu" + +%struct.__va_list = type { ptr, ptr, ptr, i32, i32 } + +define i32 @foo(i32 %guard, ...) { + %vl = alloca %struct.__va_list, align 8 + call void @llvm.lifetime.start.p0(i64 32, ptr %vl) + call void @llvm.va_start(ptr %vl) + call void @llvm.va_end(ptr %vl) + call void @llvm.lifetime.end.p0(i64 32, ptr %vl) + ret i32 0 +} + +; First check if the variadic shadow values are saved in stack with correct +; size (192 is total of general purpose registers size, 64, plus total of +; floating-point registers size, 128). + +; CHECK-LABEL: @foo +; CHECK: [[A:%.*]] = load {{.*}} ptr %va_arg_overflow_size +; CHECK: [[B:%.*]] = add i64 192, [[A]] +; CHECK: alloca {{.*}} [[B]] + +; We expect three memcpy operations: one for the general purpose registers, +; one for floating-point/SIMD ones, and one for thre remaining arguments. + +; Propagate the GR shadow values on for the va_list::__gp_top, adjust the +; offset in the __msan_va_arg_tls based on va_list:__gp_off, and finally +; issue the memcpy. +; CHECK: [[GRP:%.*]] = getelementptr inbounds i8, ptr {{%.*}}, i64 {{%.*}} +; CHECK: [[GRSIZE:%.*]] = sub i64 64, {{%.*}} +; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 {{%.*}}, ptr align 8 [[GRP]], i64 [[GRSIZE]], i1 false) + +; Propagate the VR shadow values on for the va_list::__vr_top, adjust the +; offset in the __msan_va_arg_tls based on va_list:__vr_off, and finally +; issue the memcpy. +; CHECK: [[VRP:%.*]] = getelementptr inbounds i8, ptr {{%.*}}, i64 {{%.*}} +; CHECK: [[VRSIZE:%.*]] = sub i64 128, {{%.*}} +; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 {{%.*}}, ptr align 8 [[VRP]], i64 [[VRSIZE]], i1 false) + +; Copy the remaining shadow values on the va_list::__stack position (it is +; on the constant offset of 192 from __msan_va_arg_tls). +; CHECK: [[STACK:%.*]] = getelementptr inbounds i8, ptr {{%.*}}, i32 192 +; C
[Lldb-commits] [lldb] Revert "[lldb][test] Add FindGlobalVariables tests for C++ inline static data members (#70641) (PR #71378)
https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/71378 This reverts commit 934c573b7d24327fafea916a1d0e9a9fc88f87ab. We had to revert dependencies of this patch due to test failures on Linux: ``` 4909814c08fdf4ec8bd9dad4f157d03de7c3c800 ef3febadf606c2fc4f1ad8d85a7ecdde16e4cbb3 ``` >From 947a32aed8eba20022a2bf4b1678937310de019f Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 6 Nov 2023 10:55:27 + Subject: [PATCH] Revert "[lldb][test] Add FindGlobalVariables tests for C++ inline static data members (#70641)" This reverts commit 934c573b7d24327fafea916a1d0e9a9fc88f87ab. We had to revert dependencies of this patch due to test failures on Linux: ``` 4909814c08fdf4ec8bd9dad4f157d03de7c3c800 ef3febadf606c2fc4f1ad8d85a7ecdde16e4cbb3 ``` --- .../TestConstStaticIntegralMember.py | 33 --- 1 file changed, 33 deletions(-) diff --git a/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py b/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py index bf656aa2266fdc7..555ff750b97c9fb 100644 --- a/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py +++ b/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py @@ -114,39 +114,6 @@ def test_class_with_only_const_static(self): self.expect_expr("ClassWithOnlyConstStatic::member", result_value="3") -def check_global_var(self, name: str, expect_type, expect_val): -var_list = self.target().FindGlobalVariables(name, lldb.UINT32_MAX) -self.assertEqual(len(var_list), 1) -varobj = var_list[0] -self.assertEqual(varobj.type.name, expect_type) -self.assertEqual(varobj.value, expect_val) - -# For debug-info produced by older versions of clang, inline static data members -# wouldn't get indexed into the Names accelerator table preventing LLDB from finding -# them. -@expectedFailureAll(compiler=["clang"], compiler_version=["<", "18.0"]) -@expectedFailureAll(debug_info=no_match(["dsym"])) -def test_inline_static_members(self): -self.build() -lldbutil.run_to_source_breakpoint( -self, "// break here", lldb.SBFileSpec("main.cpp") -) - -self.check_global_var("A::int_val", "const int", "1") -self.check_global_var("A::int_val_with_address", "const int", "2") -self.check_global_var("A::bool_val", "const bool", "true") -self.check_global_var("A::enum_val", "Enum", "enum_case2") -self.check_global_var("A::enum_bool_val", "EnumBool", "enum_bool_case1") -self.check_global_var("A::scoped_enum_val", "ScopedEnum", "scoped_enum_case2") - -self.check_global_var("ClassWithOnlyConstStatic::member", "const int", "3") - -self.check_global_var("ClassWithConstexprs::member", "const int", "2") -self.check_global_var("ClassWithConstexprs::enum_val", "Enum", "enum_case2") -self.check_global_var( -"ClassWithConstexprs::scoped_enum_val", "ScopedEnum", "scoped_enum_case2" -) - # With older versions of Clang, LLDB fails to evaluate classes with only # constexpr members when dsymutil is enabled @expectedFailureAll( ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Revert "[lldb][test] Add FindGlobalVariables tests for C++ inline static data members (#70641) (PR #71378)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) Changes This reverts commit 934c573b7d24327fafea916a1d0e9a9fc88f87ab. We had to revert dependencies of this patch due to test failures on Linux: ``` 4909814c08fdf4ec8bd9dad4f157d03de7c3c800 ef3febadf606c2fc4f1ad8d85a7ecdde16e4cbb3 ``` --- Full diff: https://github.com/llvm/llvm-project/pull/71378.diff 1 Files Affected: - (modified) lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py (-33) ``diff diff --git a/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py b/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py index bf656aa2266fdc7..555ff750b97c9fb 100644 --- a/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py +++ b/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py @@ -114,39 +114,6 @@ def test_class_with_only_const_static(self): self.expect_expr("ClassWithOnlyConstStatic::member", result_value="3") -def check_global_var(self, name: str, expect_type, expect_val): -var_list = self.target().FindGlobalVariables(name, lldb.UINT32_MAX) -self.assertEqual(len(var_list), 1) -varobj = var_list[0] -self.assertEqual(varobj.type.name, expect_type) -self.assertEqual(varobj.value, expect_val) - -# For debug-info produced by older versions of clang, inline static data members -# wouldn't get indexed into the Names accelerator table preventing LLDB from finding -# them. -@expectedFailureAll(compiler=["clang"], compiler_version=["<", "18.0"]) -@expectedFailureAll(debug_info=no_match(["dsym"])) -def test_inline_static_members(self): -self.build() -lldbutil.run_to_source_breakpoint( -self, "// break here", lldb.SBFileSpec("main.cpp") -) - -self.check_global_var("A::int_val", "const int", "1") -self.check_global_var("A::int_val_with_address", "const int", "2") -self.check_global_var("A::bool_val", "const bool", "true") -self.check_global_var("A::enum_val", "Enum", "enum_case2") -self.check_global_var("A::enum_bool_val", "EnumBool", "enum_bool_case1") -self.check_global_var("A::scoped_enum_val", "ScopedEnum", "scoped_enum_case2") - -self.check_global_var("ClassWithOnlyConstStatic::member", "const int", "3") - -self.check_global_var("ClassWithConstexprs::member", "const int", "2") -self.check_global_var("ClassWithConstexprs::enum_val", "Enum", "enum_case2") -self.check_global_var( -"ClassWithConstexprs::scoped_enum_val", "ScopedEnum", "scoped_enum_case2" -) - # With older versions of Clang, LLDB fails to evaluate classes with only # constexpr members when dsymutil is enabled @expectedFailureAll( `` https://github.com/llvm/llvm-project/pull/71378 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Revert "[lldb][test] Add FindGlobalVariables tests for C++ inline static data members (#70641) (PR #71378)
https://github.com/Michael137 closed https://github.com/llvm/llvm-project/pull/71378 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 947a32a - Revert "[lldb][test] Add FindGlobalVariables tests for C++ inline static data members (#70641)"
Author: Michael Buch Date: 2023-11-06T10:55:27Z New Revision: 947a32aed8eba20022a2bf4b1678937310de019f URL: https://github.com/llvm/llvm-project/commit/947a32aed8eba20022a2bf4b1678937310de019f DIFF: https://github.com/llvm/llvm-project/commit/947a32aed8eba20022a2bf4b1678937310de019f.diff LOG: Revert "[lldb][test] Add FindGlobalVariables tests for C++ inline static data members (#70641)" This reverts commit 934c573b7d24327fafea916a1d0e9a9fc88f87ab. We had to revert dependencies of this patch due to test failures on Linux: ``` 4909814c08fdf4ec8bd9dad4f157d03de7c3c800 ef3febadf606c2fc4f1ad8d85a7ecdde16e4cbb3 ``` Added: Modified: lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py Removed: diff --git a/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py b/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py index bf656aa2266fdc7..555ff750b97c9fb 100644 --- a/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py +++ b/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py @@ -114,39 +114,6 @@ def test_class_with_only_const_static(self): self.expect_expr("ClassWithOnlyConstStatic::member", result_value="3") -def check_global_var(self, name: str, expect_type, expect_val): -var_list = self.target().FindGlobalVariables(name, lldb.UINT32_MAX) -self.assertEqual(len(var_list), 1) -varobj = var_list[0] -self.assertEqual(varobj.type.name, expect_type) -self.assertEqual(varobj.value, expect_val) - -# For debug-info produced by older versions of clang, inline static data members -# wouldn't get indexed into the Names accelerator table preventing LLDB from finding -# them. -@expectedFailureAll(compiler=["clang"], compiler_version=["<", "18.0"]) -@expectedFailureAll(debug_info=no_match(["dsym"])) -def test_inline_static_members(self): -self.build() -lldbutil.run_to_source_breakpoint( -self, "// break here", lldb.SBFileSpec("main.cpp") -) - -self.check_global_var("A::int_val", "const int", "1") -self.check_global_var("A::int_val_with_address", "const int", "2") -self.check_global_var("A::bool_val", "const bool", "true") -self.check_global_var("A::enum_val", "Enum", "enum_case2") -self.check_global_var("A::enum_bool_val", "EnumBool", "enum_bool_case1") -self.check_global_var("A::scoped_enum_val", "ScopedEnum", "scoped_enum_case2") - -self.check_global_var("ClassWithOnlyConstStatic::member", "const int", "3") - -self.check_global_var("ClassWithConstexprs::member", "const int", "2") -self.check_global_var("ClassWithConstexprs::enum_val", "Enum", "enum_case2") -self.check_global_var( -"ClassWithConstexprs::scoped_enum_val", "ScopedEnum", "scoped_enum_case2" -) - # With older versions of Clang, LLDB fails to evaluate classes with only # constexpr members when dsymutil is enabled @expectedFailureAll( ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 5f86b49 - Revert "[lldb][DWARFASTParserClang] Fetch constant value from variable defintion if available (#71004)"
Author: Michael Buch Date: 2023-11-06T10:56:49Z New Revision: 5f86b49146902a37ea93470b5992206b20665128 URL: https://github.com/llvm/llvm-project/commit/5f86b49146902a37ea93470b5992206b20665128 DIFF: https://github.com/llvm/llvm-project/commit/5f86b49146902a37ea93470b5992206b20665128.diff LOG: Revert "[lldb][DWARFASTParserClang] Fetch constant value from variable defintion if available (#71004)" This reverts commit ef3febadf606c2fc4f1ad8d85a7ecdde16e4cbb3. This caused an LLDB test failure on Linux for `lang/cpp/symbols/TestSymbols.test_dwo`: ``` make: Leaving directory '/home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/lang/cpp/symbols/TestSymbols.test_dwo' runCmd: expression -- D::i PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. HandleCommand(command = "expression -- D::i") 1. :1:4: current parser token 'i' 2. :44:1: parsing function body '$__lldb_expr' 3. :44:1: in compound statement ('{}') Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it): 0 _lldb.cpython-39-x86_64-linux-gnu.so 0x7fbcfcb08b87 1 _lldb.cpython-39-x86_64-linux-gnu.so 0x7fbcfcb067ae 2 _lldb.cpython-39-x86_64-linux-gnu.so 0x7fbcfcb0923f 3 libpthread.so.0 0x7fbd07ab7140 ``` And a failure in `TestCallStdStringFunction.py` on Linux aarch64: ``` -- Exit Code: -11 Command Output (stdout): -- lldb version 18.0.0git (https://github.com/llvm/llvm-project.git revision ef3febadf606c2fc4f1ad8d85a7ecdde16e4cbb3) clang revision ef3febadf606c2fc4f1ad8d85a7ecdde16e4cbb3 llvm revision ef3febadf606c2fc4f1ad8d85a7ecdde16e4cbb3 -- Command Output (stderr): -- PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. HandleCommand(command = "expression str") 1. :45:34: current parser token ';' 2. :44:1: parsing function body '$__lldb_expr' 3. :44:1: in compound statement ('{}') #0 0xb72a149c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_[lldb.cpython-38-aarch64-linux-gnu.so](http://lldb.cpython-38-aarch64-linux-gnu.so/)+0x58c749c) #1 0xb729f458 llvm::sys::RunSignalHandlers() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_[lldb.cpython-38-aarch64-linux-gnu.so](http://lldb.cpython-38-aarch64-linux-gnu.so/)+0x58c5458) #2 0xb72a1bd0 SignalHandler(int) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_[lldb.cpython-38-aarch64-linux-gnu.so](http://lldb.cpython-38-aarch64-linux-gnu.so/)+0x58c7bd0) #3 0xbdd9e7dc (linux-vdso.so.1+0x7dc) #4 0xb71799d8 lldb_private::plugin::dwarf::SymbolFileDWARF::FindGlobalVariables(lldb_private::ConstString, lldb_private::CompilerDeclContext const&, unsigned int, lldb_private::VariableList&) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_[lldb.cpython-38-aarch64-linux-gnu.so](http://lldb.cpython-38-aarch64-linux-gnu.so/)+0x579f9d8) #5 0xb7197508 DWARFASTParserClang::FindConstantOnVariableDefinition(lldb_private::plugin::dwarf::DWARFDIE) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_[lldb.cpython-38-aarch64-linux-gnu.so](http://lldb.cpython-38-aarch64-linux-gnu.so/)+0x57bd508) ``` Added: Modified: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py lldb/test/API/lang/cpp/const_static_integral_member/main.cpp Removed: diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index 4e41858674467a3..3174c18c97d888c 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -31,7 +31,6 @@ #include "lldb/Symbol/SymbolFile.h" #include "lldb/Symbol/TypeList.h" #include "lldb/Symbol/TypeMap.h" -#include "lldb/Symbol/VariableList.h" #include "lldb/Target/Language.h" #include "lldb/Utility/LLDBAssert.h" #include "lldb/Utility/Log.h" @@ -134,54 +133,6 @@ static lldb::ModuleSP GetContainingClangModule(const DWARFDIE &die) { return lldb::ModuleSP(); } -std::optional -DWARFASTParserClang::FindConstantOnVariableDefinition(DWARFDIE die) { - assert(die.Tag() == llvm::dwarf::DW_TAG_member); - - auto *dwarf = die.GetDWARF(); - if (!dwarf) -return {}; - - ConstString name{die.GetName()
[Lldb-commits] [lldb] 333124c - Revert "[clang][DebugInfo] Emit global variable definitions for static data members with constant initializers (#70639)"
Author: Michael Buch Date: 2023-11-06T10:58:02Z New Revision: 333124cfd6dfa413294e80f9be75460b9a9314f9 URL: https://github.com/llvm/llvm-project/commit/333124cfd6dfa413294e80f9be75460b9a9314f9 DIFF: https://github.com/llvm/llvm-project/commit/333124cfd6dfa413294e80f9be75460b9a9314f9.diff LOG: Revert "[clang][DebugInfo] Emit global variable definitions for static data members with constant initializers (#70639)" This reverts commit 4909814c08fdf4ec8bd9dad4f157d03de7c3c800. Following LLDB patch had to be reverted due to Linux test failures: ``` ef3febadf606c2fc4f1ad8d85a7ecdde16e4cbb3 ``` Since without that LLDB patch the LLDB tests would fail, revert this clang patch for now. Added: Modified: clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CGDebugInfo.h clang/test/CodeGenCXX/debug-info-class.cpp clang/test/CodeGenCXX/debug-info-static-member.cpp lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py Removed: clang/test/CodeGenCXX/debug-info-static-inline-member.cpp diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 410c8f522b1017f..84a166d3ac3659c 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1677,13 +1677,22 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, llvm::DIType *RecordTy, unsigned LineNumber = getLineNumber(Var->getLocation()); StringRef VName = Var->getName(); + llvm::Constant *C = nullptr; + if (Var->getInit()) { +const APValue *Value = Var->evaluateValue(); +if (Value) { + if (Value->isInt()) +C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt()); + if (Value->isFloat()) +C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat()); +} + } llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD); auto Align = getDeclAlignIfRequired(Var, CGM.getContext()); llvm::DIDerivedType *GV = DBuilder.createStaticMemberType( - RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr, Align); + RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Align); StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV); - StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl()); return GV; } @@ -5587,39 +5596,6 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) { TemplateParameters, Align)); } -void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) { - assert(VD->hasInit()); - assert(CGM.getCodeGenOpts().hasReducedDebugInfo()); - if (VD->hasAttr()) -return; - - auto &GV = DeclCache[VD]; - if (GV) -return; - - auto const *InitVal = VD->evaluateValue(); - if (!InitVal) -return; - - llvm::DIFile *Unit = nullptr; - llvm::DIScope *DContext = nullptr; - unsigned LineNo; - StringRef DeclName, LinkageName; - QualType T; - llvm::MDTuple *TemplateParameters = nullptr; - collectVarDeclProps(VD, Unit, LineNo, T, DeclName, LinkageName, - TemplateParameters, DContext); - - auto Align = getDeclAlignIfRequired(VD, CGM.getContext()); - llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(VD); - llvm::DIExpression *InitExpr = createConstantValueExpression(VD, *InitVal); - - GV.reset(DBuilder.createGlobalVariableExpression( - TheCU, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit), - true, true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VD), - TemplateParameters, Align, Annotations)); -} - void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var, const VarDecl *D) { assert(CGM.getCodeGenOpts().hasReducedDebugInfo()); @@ -5890,18 +5866,6 @@ void CGDebugInfo::finalize() { DBuilder.replaceTemporary(std::move(FwdDecl), cast(Repl)); } - for (auto const *VD : StaticDataMemberDefinitionsToEmit) { -assert(VD->isStaticDataMember()); - -if (DeclCache.contains(VD)) - continue; - -if (!VD->hasInit()) - continue; - -EmitGlobalVariable(VD); - } - // We keep our own list of retained types, because we need to look // up the final type in the type cache. for (auto &RT : RetainedTypes) diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 3e4c133b7f2b9f1..7b60e94555d0608 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -161,9 +161,6 @@ class CGDebugInfo { llvm::DenseMap> StaticDataMemberCache; - /// Keeps track of static data members for which we should emit a definition. - std::vector StaticDataMemberDefinitionsToEmit; - using ParamDecl2StmtTy = llvm::DenseMap; using Param2DILocTy = llvm::DenseMap; @@ -529,9 +526,6 @@ class CGDebugInfo { /// Emit a constant global variable's
[Lldb-commits] [lldb] 3f5fd4b - [lldb][AArch64] Move register info reconfigure into architecture plugin (#70950)
Author: David Spickett Date: 2023-11-06T11:30:19Z New Revision: 3f5fd4b3c1d670649b59f3631287b6f54c6b85ee URL: https://github.com/llvm/llvm-project/commit/3f5fd4b3c1d670649b59f3631287b6f54c6b85ee DIFF: https://github.com/llvm/llvm-project/commit/3f5fd4b3c1d670649b59f3631287b6f54c6b85ee.diff LOG: [lldb][AArch64] Move register info reconfigure into architecture plugin (#70950) This removes AArch64 specific code from the GDB* classes. To do this I've added 2 new methods to Architecture: * RegisterWriteCausesReconfigure to check if what you are about to do will trash the register info. * ReconfigureRegisterInfo to do the reconfiguring. This tells you if anything changed so that we only invalidate registers when needed. So that ProcessGDBRemote can call ReconfigureRegisterInfo in SetThreadStopInfo, I've added forwarding calls to GDBRemoteRegisterContext and the base class RegisterContext. (which removes a slightly sketchy static cast as well) RegisterContext defaults to doing nothing for both the methods so anything other than GDBRemoteRegisterContext will do nothing. Added: Modified: lldb/include/lldb/Core/Architecture.h lldb/include/lldb/Target/DynamicRegisterInfo.h lldb/include/lldb/Target/RegisterContext.h lldb/source/Plugins/Architecture/AArch64/ArchitectureAArch64.cpp lldb/source/Plugins/Architecture/AArch64/ArchitectureAArch64.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Removed: diff --git a/lldb/include/lldb/Core/Architecture.h b/lldb/include/lldb/Core/Architecture.h index b68bf27ae0df888..b6fc1a20e1e6967 100644 --- a/lldb/include/lldb/Core/Architecture.h +++ b/lldb/include/lldb/Core/Architecture.h @@ -10,6 +10,7 @@ #define LLDB_CORE_ARCHITECTURE_H #include "lldb/Core/PluginInterface.h" +#include "lldb/Target/DynamicRegisterInfo.h" #include "lldb/Target/MemoryTagManager.h" namespace lldb_private { @@ -109,6 +110,25 @@ class Architecture : public PluginInterface { virtual const MemoryTagManager *GetMemoryTagManager() const { return nullptr; } + + // This returns true if a write to the named register should cause lldb to + // reconfigure its register information. For example on AArch64 writing to vg + // to change the vector length means lldb has to change the size of registers. + virtual bool + RegisterWriteCausesReconfigure(const llvm::StringRef name) const { +return false; + } + + // Call this after writing a register for which RegisterWriteCausesReconfigure + // returns true. This method will update the layout of registers according to + // the new state e.g. the new length of scalable vector registers. + // Returns true if anything changed, which means existing register values must + // be invalidated. + virtual bool ReconfigureRegisterInfo(DynamicRegisterInfo ®_info, + DataExtractor ®_data, + RegisterContext ®_context) const { +return false; + } }; } // namespace lldb_private diff --git a/lldb/include/lldb/Target/DynamicRegisterInfo.h b/lldb/include/lldb/Target/DynamicRegisterInfo.h index fb22885e713d672..0e175a99eb7d58a 100644 --- a/lldb/include/lldb/Target/DynamicRegisterInfo.h +++ b/lldb/include/lldb/Target/DynamicRegisterInfo.h @@ -93,6 +93,10 @@ class DynamicRegisterInfo { return llvm::iterator_range(m_regs); } + llvm::iterator_range registers_mutable() { +return llvm::iterator_range(m_regs); + } + void ConfigureOffsets(); protected: diff --git a/lldb/include/lldb/Target/RegisterContext.h b/lldb/include/lldb/Target/RegisterContext.h index 893569a98dbd8b3..309e231b2321e77 100644 --- a/lldb/include/lldb/Target/RegisterContext.h +++ b/lldb/include/lldb/Target/RegisterContext.h @@ -51,6 +51,12 @@ class RegisterContext : public std::enable_shared_from_this, return false; } + virtual bool RegisterWriteCausesReconfigure(const llvm::StringRef name) { +return false; + } + + virtual bool ReconfigureRegisterInfo() { return false; } + // These two functions are used to implement "push" and "pop" of register // states. They are used primarily for expression evaluation, where we need // to push a new state (storing the old one in data_sp) and then restoring diff --git a/lldb/source/Plugins/Architecture/AArch64/ArchitectureAArch64.cpp b/lldb/source/Plugins/Architecture/AArch64/ArchitectureAArch64.cpp index 1b2b41ee8758758..2954eaa2083af08 100644 --- a/lldb/source/Plugins/Architecture/AArch64/ArchitectureAArch64.cpp +++ b/lldb/source/Plugins/Architecture/AArch64/ArchitectureAArch64.cpp @@ -8,7 +8,10 @@ #include "Plugins/Architecture/AArch64/ArchitectureAArch64.h" #include "lldb/Core/PluginManager.h" +#include "lldb/Target/RegisterCont
[Lldb-commits] [lldb] [lldb][AArch64] Move register info reconfigure into architecture plugin (PR #70950)
https://github.com/DavidSpickett closed https://github.com/llvm/llvm-project/pull/70950 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add LLDB_ASSERT_OR_RETURN macro and make use of it (PR #71175)
https://github.com/DavidSpickett updated https://github.com/llvm/llvm-project/pull/71175 >From e14805de814d60f15a2671dd739caf10d19f2ea6 Mon Sep 17 00:00:00 2001 From: David Spickett Date: Fri, 3 Nov 2023 10:58:15 + Subject: [PATCH] [lldb] Replace some register handling asserts with lldbassert These asserts are important if they fail, but using assert meant there was no checking in a release build. lldbassert does the check and reports any failure but doesn't crash the debugger. I know we're not supposed to be adding new lldbasserts, but it's exactly what's needed here. --- .../Linux/NativeRegisterContextLinux_arm.cpp | 12 +++-- .../NativeRegisterContextLinux_arm64.cpp | 52 --- ...NativeRegisterContextLinux_loongarch64.cpp | 9 ++-- .../NativeRegisterContextLinux_riscv64.cpp| 10 ++-- .../RegisterContextPOSIXCore_arm64.cpp| 16 +++--- 5 files changed, 60 insertions(+), 39 deletions(-) diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp index 5ad2f7a8e9455b1..47c91a2cc8fb5c6 100644 --- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp @@ -143,7 +143,8 @@ NativeRegisterContextLinux_arm::ReadRegister(const RegisterInfo *reg_info, // Get pointer to m_fpr variable and set the data from it. uint32_t fpr_offset = CalculateFprOffset(reg_info); - assert(fpr_offset < sizeof m_fpr); + lldbassert(fpr_offset < sizeof m_fpr && + "Invalid fpr offset for register read"); uint8_t *src = (uint8_t *)&m_fpr + fpr_offset; switch (reg_info->byte_size) { case 2: @@ -186,7 +187,8 @@ NativeRegisterContextLinux_arm::WriteRegister(const RegisterInfo *reg_info, if (IsFPR(reg_index)) { // Get pointer to m_fpr variable and set the data to it. uint32_t fpr_offset = CalculateFprOffset(reg_info); -assert(fpr_offset < sizeof m_fpr); +lldbassert(fpr_offset < sizeof m_fpr && + "Invalid fpr offset for register read"); uint8_t *dst = (uint8_t *)&m_fpr + fpr_offset; ::memcpy(dst, reg_value.GetBytes(), reg_info->byte_size); @@ -794,7 +796,8 @@ Status NativeRegisterContextLinux_arm::DoReadRegisterValue( // read out the full GPR register set instead. This approach is about 4 times // slower but the performance overhead is negligible in comparison to // processing time in lldb-server. - assert(offset % 4 == 0 && "Try to write a register with unaligned offset"); + lldbassert(offset % 4 == 0 && + "Trying to read a register with unaligned offset"); if (offset + sizeof(uint32_t) > sizeof(m_gpr_arm)) return Status("Register isn't fit into the size of the GPR area"); @@ -813,7 +816,8 @@ Status NativeRegisterContextLinux_arm::DoWriteRegisterValue( // read out the full GPR register set, modify the requested register and // write it back. This approach is about 4 times slower but the performance // overhead is negligible in comparison to processing time in lldb-server. - assert(offset % 4 == 0 && "Try to write a register with unaligned offset"); + lldbassert(offset % 4 == 0 && + "Try to write a register with unaligned offset"); if (offset + sizeof(uint32_t) > sizeof(m_gpr_arm)) return Status("Register isn't fit into the size of the GPR area"); diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp index e23165933c221cf..9e08f31034fbde2 100644 --- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp @@ -242,7 +242,7 @@ NativeRegisterContextLinux_arm64::ReadRegister(const RegisterInfo *reg_info, return error; offset = reg_info->byte_offset; -assert(offset < GetGPRSize()); +lldbassert(offset < GetGPRSize() && "Invalid GPR register read offset"); src = (uint8_t *)GetGPRBuffer() + offset; } else if (IsFPR(reg)) { @@ -253,7 +253,7 @@ NativeRegisterContextLinux_arm64::ReadRegister(const RegisterInfo *reg_info, return error; offset = CalculateFprOffset(reg_info); - assert(offset < GetFPRSize()); + lldbassert(offset < GetFPRSize() && "Invalid FPR register read offset"); src = (uint8_t *)GetFPRBuffer() + offset; } else { // SVE or SSVE enabled, we will read and cache SVE ptrace data. @@ -288,7 +288,8 @@ NativeRegisterContextLinux_arm64::ReadRegister(const RegisterInfo *reg_info, offset = CalculateSVEOffset(GetRegisterInfoAtIndex(sve_reg_num)); } - assert(offset < GetSVEBufferSize()); + lldbassert(offset < GetSVEBufferSize() && + "Invalid SVE FPR register read offset"); src = (uint8_t *)GetSVEBuffer() + offset; } } else if (IsTLS(reg)) { @@ -297,
[Lldb-commits] [lldb] [lldb] Replace some register handling asserts with lldbassert (PR #71175)
https://github.com/DavidSpickett edited https://github.com/llvm/llvm-project/pull/71175 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Replace some register handling asserts with lldbassert (PR #71175)
https://github.com/DavidSpickett edited https://github.com/llvm/llvm-project/pull/71175 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Replace some register handling asserts with lldbassert (PR #71175)
DavidSpickett wrote: `report_fatal_error` goes against not crashing the debugger, so despite what the docs say, `lldbassert` does fit here I think. https://github.com/llvm/llvm-project/pull/71175 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add template method for getting const or mutable regs from DynamicRegisterInfo (PR #71402)
https://github.com/DavidSpickett created https://github.com/llvm/llvm-project/pull/71402 GDBRemoteRegisterContext only needs to iterate them, ArchitectureAArch64 needs to mutate them if scalable registers change size. >From 8b074aa5024deadfb74db6c10a812e5a474c6f1a Mon Sep 17 00:00:00 2001 From: David Spickett Date: Mon, 6 Nov 2023 15:02:29 + Subject: [PATCH] [lldb] Add template method for getting const or mutable regs from DynamicRegisterInfo GDBRemoteRegisterContext only needs to iterate them, ArchitectureAArch64 needs to mutate them if scalable registers change size. --- .../include/lldb/Target/DynamicRegisterInfo.h | 14 + .../AArch64/ArchitectureAArch64.cpp | 21 --- .../gdb-remote/GDBRemoteRegisterContext.cpp | 4 +++- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lldb/include/lldb/Target/DynamicRegisterInfo.h b/lldb/include/lldb/Target/DynamicRegisterInfo.h index 0e175a99eb7d58a..6dc1380e22059f1 100644 --- a/lldb/include/lldb/Target/DynamicRegisterInfo.h +++ b/lldb/include/lldb/Target/DynamicRegisterInfo.h @@ -89,12 +89,18 @@ class DynamicRegisterInfo { GetRegisterInfo(llvm::StringRef reg_name) const; typedef std::vector reg_collection; - llvm::iterator_range registers() const { -return llvm::iterator_range(m_regs); + + template T registers(); + + typedef llvm::iterator_range + reg_collection_const_range; + template <> reg_collection_const_range registers() { +return reg_collection_const_range(m_regs); } - llvm::iterator_range registers_mutable() { -return llvm::iterator_range(m_regs); + typedef llvm::iterator_range reg_collection_range; + template <> reg_collection_range registers() { +return reg_collection_range(m_regs); } void ConfigureOffsets(); diff --git a/lldb/source/Plugins/Architecture/AArch64/ArchitectureAArch64.cpp b/lldb/source/Plugins/Architecture/AArch64/ArchitectureAArch64.cpp index 2954eaa2083af08..181ba4e7d877216 100644 --- a/lldb/source/Plugins/Architecture/AArch64/ArchitectureAArch64.cpp +++ b/lldb/source/Plugins/Architecture/AArch64/ArchitectureAArch64.cpp @@ -38,11 +38,9 @@ ArchitectureAArch64::Create(const ArchSpec &arch) { return std::unique_ptr(new ArchitectureAArch64()); } -static void UpdateARM64SVERegistersInfos( -llvm::iterator_range< -lldb_private::DynamicRegisterInfo::reg_collection::iterator> -regs, -uint64_t vg) { +static void +UpdateARM64SVERegistersInfos(DynamicRegisterInfo::reg_collection_range regs, + uint64_t vg) { // SVE Z register size is vg x 8 bytes. uint32_t z_reg_byte_size = vg * 8; @@ -62,11 +60,9 @@ static void UpdateARM64SVERegistersInfos( } } -static void UpdateARM64SMERegistersInfos( -llvm::iterator_range< -lldb_private::DynamicRegisterInfo::reg_collection::iterator> -regs, -uint64_t svg) { +static void +UpdateARM64SMERegistersInfos(DynamicRegisterInfo::reg_collection_range regs, + uint64_t svg) { for (auto ® : regs) { if (strcmp(reg.name, "za") == 0) { // ZA is a register with size (svg*8) * (svg*8). A square essentially. @@ -108,10 +104,11 @@ bool ArchitectureAArch64::ReconfigureRegisterInfo(DynamicRegisterInfo ®_info, if (!vg_reg_value && !svg_reg_value) return false; + auto regs = reg_info.registers(); if (vg_reg_value) -UpdateARM64SVERegistersInfos(reg_info.registers_mutable(), *vg_reg_value); +UpdateARM64SVERegistersInfos(regs, *vg_reg_value); if (svg_reg_value) -UpdateARM64SMERegistersInfos(reg_info.registers_mutable(), *svg_reg_value); +UpdateARM64SMERegistersInfos(regs, *svg_reg_value); // At this point if we have updated any registers, their offsets will all be // invalid. If we did, we need to update them all. diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp index e35983f0e7fbd40..e9bd65fad1502bf 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp @@ -228,7 +228,9 @@ bool GDBRemoteRegisterContext::ReadRegisterBytes(const RegisterInfo *reg_info) { SetAllRegisterValid(true); return true; } else if (buffer_sp->GetByteSize() > 0) { - for (auto x : llvm::enumerate(m_reg_info_sp->registers())) { + for (auto x : llvm::enumerate( + m_reg_info_sp->registers< + DynamicRegisterInfo::reg_collection_const_range>())) { const struct RegisterInfo ®info = x.value(); m_reg_valid[x.index()] = (reginfo.byte_offset + reginfo.byte_size <= ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add template method for getting const or mutable regs from DynamicRegisterInfo (PR #71402)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: David Spickett (DavidSpickett) Changes GDBRemoteRegisterContext only needs to iterate them, ArchitectureAArch64 needs to mutate them if scalable registers change size. --- Full diff: https://github.com/llvm/llvm-project/pull/71402.diff 3 Files Affected: - (modified) lldb/include/lldb/Target/DynamicRegisterInfo.h (+10-4) - (modified) lldb/source/Plugins/Architecture/AArch64/ArchitectureAArch64.cpp (+9-12) - (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp (+3-1) ``diff diff --git a/lldb/include/lldb/Target/DynamicRegisterInfo.h b/lldb/include/lldb/Target/DynamicRegisterInfo.h index 0e175a99eb7d58a..6dc1380e22059f1 100644 --- a/lldb/include/lldb/Target/DynamicRegisterInfo.h +++ b/lldb/include/lldb/Target/DynamicRegisterInfo.h @@ -89,12 +89,18 @@ class DynamicRegisterInfo { GetRegisterInfo(llvm::StringRef reg_name) const; typedef std::vector reg_collection; - llvm::iterator_range registers() const { -return llvm::iterator_range(m_regs); + + template T registers(); + + typedef llvm::iterator_range + reg_collection_const_range; + template <> reg_collection_const_range registers() { +return reg_collection_const_range(m_regs); } - llvm::iterator_range registers_mutable() { -return llvm::iterator_range(m_regs); + typedef llvm::iterator_range reg_collection_range; + template <> reg_collection_range registers() { +return reg_collection_range(m_regs); } void ConfigureOffsets(); diff --git a/lldb/source/Plugins/Architecture/AArch64/ArchitectureAArch64.cpp b/lldb/source/Plugins/Architecture/AArch64/ArchitectureAArch64.cpp index 2954eaa2083af08..181ba4e7d877216 100644 --- a/lldb/source/Plugins/Architecture/AArch64/ArchitectureAArch64.cpp +++ b/lldb/source/Plugins/Architecture/AArch64/ArchitectureAArch64.cpp @@ -38,11 +38,9 @@ ArchitectureAArch64::Create(const ArchSpec &arch) { return std::unique_ptr(new ArchitectureAArch64()); } -static void UpdateARM64SVERegistersInfos( -llvm::iterator_range< -lldb_private::DynamicRegisterInfo::reg_collection::iterator> -regs, -uint64_t vg) { +static void +UpdateARM64SVERegistersInfos(DynamicRegisterInfo::reg_collection_range regs, + uint64_t vg) { // SVE Z register size is vg x 8 bytes. uint32_t z_reg_byte_size = vg * 8; @@ -62,11 +60,9 @@ static void UpdateARM64SVERegistersInfos( } } -static void UpdateARM64SMERegistersInfos( -llvm::iterator_range< -lldb_private::DynamicRegisterInfo::reg_collection::iterator> -regs, -uint64_t svg) { +static void +UpdateARM64SMERegistersInfos(DynamicRegisterInfo::reg_collection_range regs, + uint64_t svg) { for (auto ® : regs) { if (strcmp(reg.name, "za") == 0) { // ZA is a register with size (svg*8) * (svg*8). A square essentially. @@ -108,10 +104,11 @@ bool ArchitectureAArch64::ReconfigureRegisterInfo(DynamicRegisterInfo ®_info, if (!vg_reg_value && !svg_reg_value) return false; + auto regs = reg_info.registers(); if (vg_reg_value) -UpdateARM64SVERegistersInfos(reg_info.registers_mutable(), *vg_reg_value); +UpdateARM64SVERegistersInfos(regs, *vg_reg_value); if (svg_reg_value) -UpdateARM64SMERegistersInfos(reg_info.registers_mutable(), *svg_reg_value); +UpdateARM64SMERegistersInfos(regs, *svg_reg_value); // At this point if we have updated any registers, their offsets will all be // invalid. If we did, we need to update them all. diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp index e35983f0e7fbd40..e9bd65fad1502bf 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp @@ -228,7 +228,9 @@ bool GDBRemoteRegisterContext::ReadRegisterBytes(const RegisterInfo *reg_info) { SetAllRegisterValid(true); return true; } else if (buffer_sp->GetByteSize() > 0) { - for (auto x : llvm::enumerate(m_reg_info_sp->registers())) { + for (auto x : llvm::enumerate( + m_reg_info_sp->registers< + DynamicRegisterInfo::reg_collection_const_range>())) { const struct RegisterInfo ®info = x.value(); m_reg_valid[x.index()] = (reginfo.byte_offset + reginfo.byte_size <= `` https://github.com/llvm/llvm-project/pull/71402 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)
@@ -1548,14 +1566,29 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter, Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]); if (symbol) { if (symbol->ValueIsAddress()) { + // Using the new dump function to add colors in the summary. + if (name && use_color){ DumpAddress( + interpreter.GetExecutionContext().GetBestExecutionContextScope(), + symbol->GetAddressRef(), verbose, all_ranges, strm, name); + } + else{ +DumpAddress( interpreter.GetExecutionContext().GetBestExecutionContextScope(), symbol->GetAddressRef(), verbose, all_ranges, strm); + } DavidSpickett wrote: This can be simplified to: ``` DumpAddress( interpreter.GetExecutionContext().GetBestExecutionContextScope(), symbol->GetAddressRef(), verbose, all_ranges, strm, name && use_color ? name : nullptr); ``` If you haven't seen it before, the "in line if" is called the "ternary operator". https://www.w3schools.com/cpp/cpp_conditions_shorthand.asp What you could even do is very early in the function say "if no colour, set name to nullptr". Then any subsequent call using `name`, can just be passed `name` not `name && use_color ? name : nullptr`. ``` // If color is disabled, we have no use for the search pattern. name = use_color && name ? name : nullptr; ``` https://github.com/llvm/llvm-project/pull/69422 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)
@@ -403,9 +407,48 @@ bool Address::GetDescription(Stream &s, Target &target, return false; } +//== + +// Function to print the searched symbol in red color +void Address::re_pattern(Stream *strm, const char *text, const char *name) { DavidSpickett wrote: We're moving away from PrintRed, that's good. I suggest you name this something like `DumpName` to fit the rest of the class style. Then below in Address::dump all it has to do is call DumpName (and anyone calling Address:dump externally does the same). One way to make sure this has been done is to make Address::re_pattern / Address::DumpName private. Then you'll get a compiler error if someone is calling it directly. Also, the parameters are confusingly named now. What this function does it dump the name of the symbol but the name is passed as `text` and then there's the regex pattern as `name`. `text` is fine, but I think `name` should be `pattern` or `re_pattern`, whatever makes it clear to you that this is a pattern we will use to match things, not some plain text to dump. https://github.com/llvm/llvm-project/pull/69422 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)
@@ -253,9 +264,20 @@ void Symbol::GetDescription(Stream *s, lldb::DescriptionLevel level, m_addr_range.GetBaseAddress().GetOffset()); } ConstString demangled = GetMangled().GetDemangledName(); - if (demangled) + + // Checking if the name (i.e., searched symbol is passed as an argument to the function) + // In that case, we use the re_pattern function to colorize the symbol. + if (demangled && name){ +s->Printf(", name="); +Address::re_pattern(s, demangled.AsCString(), name); + } + else if(demangled && name == nullptr) s->Printf(", name=\"%s\"", demangled.AsCString()); - if (m_mangled.GetMangledName()) + if (m_mangled.GetMangledName() && name){ +s->Printf(", mangled="); +Address::re_pattern(s, m_mangled.GetMangledName().AsCString(), name); + } + else if(m_mangled.GetMangledName() && name == nullptr) DavidSpickett wrote: The `if (m_mangled.GetMangledName..` should be the outer if. Within that, you can see if you have a name/pattern to use. Also, you can do this trick to simplify things: ``` if (auto mangled_name = m_mangled.GetMangledName()) { // If you get here then bool(m_mangled_name.GetMangledName()) is True so you can use it. do_stuff(m_mangled_name); } else { // it was false } ``` (which is more the code being from before that feature existed than anything you're doing wrong) https://github.com/llvm/llvm-project/pull/69422 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)
@@ -163,6 +175,12 @@ bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope, dumped_something = true; if (symbol->GetType() == eSymbolTypeTrampoline) s->PutCString("symbol stub for: "); + + // Similar here, Using re_pattern if the function is called by regex symbol search command + if(name){ +Address::re_pattern(s, symbol->GetName().GetStringRef().str().c_str(), name); + } + else symbol->GetName().Dump(s); DavidSpickett wrote: Here is a place where it would be good to just be able to call .Dump() one way instead of having this if. If the colouring function was part of lldb utility, that might work. Perhaps in the same area as `lldb_private::ansi::FormatAnsiTerminalCodes`. Then all the `Dump` for various things that want colours can be implemented using it. https://github.com/llvm/llvm-project/pull/69422 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)
@@ -793,8 +852,10 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, } } } -if (fallback_style != DumpStyleInvalid) +if (fallback_style != DumpStyleInvalid && !name) return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size); +else if(fallback_style != DumpStyleInvalid && name) + return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, name); DavidSpickett wrote: Single call that always passes `name`. https://github.com/llvm/llvm-project/pull/69422 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)
@@ -762,8 +818,11 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, } } } else { - if (fallback_style != DumpStyleInvalid) + if (fallback_style != DumpStyleInvalid && !name) return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size); + else if(fallback_style != DumpStyleInvalid && name){ +return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size, false, name); + } DavidSpickett wrote: Make this a single call that always passes `name`. https://github.com/llvm/llvm-project/pull/69422 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)
@@ -680,21 +729,28 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, if (show_stop_context) { // We have a function or a symbol from the same sections as this // address. - sc.DumpStopContext(s, exe_scope, *this, show_fullpaths, - show_module, show_inlined_frames, - show_function_arguments, show_function_name); + // Using the same logic, hecking if searched symbol passed to this function or if it using the defualt nullptr + if(name) +sc.DumpStopContext(s, exe_scope, *this, show_fullpaths, + show_module, show_inlined_frames, + show_function_arguments, show_function_name, name); + else +sc.DumpStopContext(s, exe_scope, *this, show_fullpaths, + show_module, show_inlined_frames, DavidSpickett wrote: Again here we can do one call that passes on `name` always. If it's nullptr, that's fine just pass it on and no colouring is done. https://github.com/llvm/llvm-project/pull/69422 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][test] TestVTableValue.py: skip test for older versions of clang (PR #71372)
https://github.com/bulbazord approved this pull request. https://github.com/llvm/llvm-project/pull/71372 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][split-dwarf] implement GetSeparateDebugInfo for SymbolFileOnDemand (PR #71230)
@@ -130,3 +130,29 @@ def test_dwos_not_loaded_table_output(self): "0x[a-zA-Z0-9]{16}\s+E\s+.*foo\.dwo", ], ) + +@skipIfRemote +@skipIfDarwin +@skipIfWindows bulbazord wrote: The TestDumpOso is good, but I was more concerned about testing the DWO path on Darwin (and Windows, although I'm a little less concerned about that one for... reasons). What I want to avoid is a change being made on a Darwin host that breaks the DWO case and a change being made on a Linux host that breaks OSO debugging. LLVM has tests that build DWO files for Linux/Android platforms and I bet we could get Mach-O Objects with DWARF embedded in them in a similar fashion. https://github.com/llvm/llvm-project/pull/71230 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
@@ -26,6 +26,10 @@ class ScriptedPlatformInterface : virtual public ScriptedInterface { return {llvm::make_error()}; } + llvm::SmallVector GetAbstractMethods() const override { +return {}; + } bulbazord wrote: This is probably a gap in my understanding, why do we instantiate `ScriptedPlatformInterface` instead of something like `ScriptedPythonPlatform`? The `Interface` at the end of `ScriptedPlatformInterface` to me feels like we shouldn't be creating objects of that type at all. https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
@@ -60,6 +60,52 @@ def move_blueprint_to_dsym(self, blueprint_name): ) shutil.copy(blueprint_origin_path, blueprint_destination_path) +def test_missing_methods_scripted_register_context(self): +"""Test that we only instanciate scripted processes if they implement bulbazord wrote: Nevermind, apparently this is also an accepted English spelling. No need to change it. https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
@@ -663,6 +663,18 @@ bool PythonDictionary::Check(PyObject *py_obj) { return PyDict_Check(py_obj); } +bool PythonDictionary::HasKey(const llvm::Twine &key) const { bulbazord wrote: You could avoid a potential allocation with the creation of the `PythonString` entirely with a `StringRef` parameter. Right now, line 669 invokes `key.str()` to create a `std::string` from the `key` parameter. In the worst case, this is a memory allocation just to give the `PythonString` constructor a `StringRef`. This doesn't have to be the case though, because `Twine` has a method to check if it is representable by a single `StringRef`, and if so, you can use a different method to get that `StringRef`. That would look something like this pseudocode: ``` if (key is representable as single StringRef) PythonString key_object(key.GetStringRefRepresentation()); else PythonString key_object(key.str()); ``` But that's just more complicated. If `key` was a `StringRef` parameter, you could do `PythonString key_object(key);` and have no potential for additional allocations. https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 10ec3bc - [TraceIntelPT]Migrate to new function template for TraceIntelPT (#71258)
Author: GeorgeHuyubo Date: 2023-11-06T09:49:29-08:00 New Revision: 10ec3bc9773e7e31255d5d3997f3966354a67d0d URL: https://github.com/llvm/llvm-project/commit/10ec3bc9773e7e31255d5d3997f3966354a67d0d DIFF: https://github.com/llvm/llvm-project/commit/10ec3bc9773e7e31255d5d3997f3966354a67d0d.diff LOG: [TraceIntelPT]Migrate to new function template for TraceIntelPT (#71258) Easy change. Migrate to new template function call. More context: https://github.com/llvm/llvm-project/commit/6f8b33f6dfd0a0f8d2522b6c832bd6298ae2f3f3 Added: Modified: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp Removed: diff --git a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp index 015faa89fcfada8..72e9948ffe8148f 100644 --- a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp +++ b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp @@ -60,14 +60,14 @@ TraceIntelPT::PluginProperties::PluginProperties() : Properties() { uint64_t TraceIntelPT::PluginProperties::GetInfiniteDecodingLoopVerificationThreshold() { const uint32_t idx = ePropertyInfiniteDecodingLoopVerificationThreshold; - return m_collection_sp->GetPropertyAtIndexAsUInt64( - nullptr, idx, g_traceintelpt_properties[idx].default_uint_value); + return GetPropertyAtIndexAs( + idx, g_traceintelpt_properties[idx].default_uint_value); } uint64_t TraceIntelPT::PluginProperties::GetExtremelyLargeDecodingThreshold() { const uint32_t idx = ePropertyExtremelyLargeDecodingThreshold; - return m_collection_sp->GetPropertyAtIndexAsUInt64( - nullptr, idx, g_traceintelpt_properties[idx].default_uint_value); + return GetPropertyAtIndexAs( + idx, g_traceintelpt_properties[idx].default_uint_value); } TraceIntelPT::PluginProperties &TraceIntelPT::GetGlobalProperties() { ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [TraceIntelPT]Migrate to new function template for TraceIntelPT (PR #71258)
https://github.com/GeorgeHuyubo closed https://github.com/llvm/llvm-project/pull/71258 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add template method for getting const or mutable regs from DynamicRegisterInfo (PR #71402)
@@ -228,7 +228,9 @@ bool GDBRemoteRegisterContext::ReadRegisterBytes(const RegisterInfo *reg_info) { SetAllRegisterValid(true); return true; } else if (buffer_sp->GetByteSize() > 0) { - for (auto x : llvm::enumerate(m_reg_info_sp->registers())) { + for (auto x : llvm::enumerate( medismailben wrote: Same here https://github.com/llvm/llvm-project/pull/71402 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add template method for getting const or mutable regs from DynamicRegisterInfo (PR #71402)
@@ -108,10 +104,11 @@ bool ArchitectureAArch64::ReconfigureRegisterInfo(DynamicRegisterInfo ®_info, if (!vg_reg_value && !svg_reg_value) return false; + auto regs = reg_info.registers(); medismailben wrote: nit: If you specify the type of `regs` (instead of using `auto`), you shouldn't have to specify the template argument, and just call `reg_info.registers()`. https://github.com/llvm/llvm-project/pull/71402 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add template method for getting const or mutable regs from DynamicRegisterInfo (PR #71402)
https://github.com/medismailben approved this pull request. Nice! Looks good to me! Left some comments but it's mostly a matter of style. Pick what approach you like the most :) https://github.com/llvm/llvm-project/pull/71402 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add template method for getting const or mutable regs from DynamicRegisterInfo (PR #71402)
https://github.com/medismailben edited https://github.com/llvm/llvm-project/pull/71402 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
@@ -26,6 +26,10 @@ class ScriptedPlatformInterface : virtual public ScriptedInterface { return {llvm::make_error()}; } + llvm::SmallVector GetAbstractMethods() const override { +return {}; + } medismailben wrote: The same way we instantiate a base `ScriptInterpreter` instance if we don't link with python. Because we use dynamic dispatch to get the right scripting interface from the script interpreter, we cannot make any of the Scripted affordance class abstract because we won't be able to instantiate them and hence, won't be able to implement `ScriptInterpreter::CreateScripted{Platform,Process,Thread}Interface`. Another approach, that I'm not particularly keen on doing, is making them abstract and assert in the `ScriptInterpreter::CreateScripted{Platform,Process,Thread}Interface` methods. @JDevlieghere any thoughts ? https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][test] TestVTableValue.py: skip test for older versions of clang (PR #71372)
https://github.com/clayborg approved this pull request. https://github.com/llvm/llvm-project/pull/71372 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
@@ -32,6 +32,42 @@ class ScriptedPythonInterface : virtual public ScriptedInterface { ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter); ~ScriptedPythonInterface() override = default; + enum class AbstractMethodCheckerCases { +eNotImplemented, +eNotAllocated, +eNotCallable, +eValid + }; + + llvm::Expected> + CheckAbstractMethodImplementation( + const python::PythonDictionary &class_dict) const { + +using namespace python; + +std::map checker; +#define HANDLE_ERROR(method_name, error) \ + { \ +checker[method_name] = error; \ +continue; \ + } + +for (const llvm::StringLiteral &method_name : GetAbstractMethods()) { + if (!class_dict.HasKey(method_name)) +HANDLE_ERROR(method_name, AbstractMethodCheckerCases::eNotImplemented) + auto callable_or_err = class_dict.GetItem(method_name); + if (!callable_or_err) +HANDLE_ERROR(method_name, AbstractMethodCheckerCases::eNotAllocated) + if (!PythonCallable::Check(callable_or_err.get().get())) JDevlieghere wrote: ~So you never check the error? Doesn't this assert in a debug build?~ nvm you do on line 60. https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
https://github.com/JDevlieghere commented: Is there any way we could avoid ever having to instantiate a `Scripted{.*}Interface`? https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
https://github.com/JDevlieghere edited https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
@@ -32,27 +32,66 @@ class ScriptedPythonInterface : virtual public ScriptedInterface { ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter); ~ScriptedPythonInterface() override = default; + enum class AbstractMethodCheckerCases { +eNotImplemented, +eNotAllocated, +eNotCallable, +eValid + }; + + llvm::Expected> + CheckAbstractMethodImplementation( + const python::PythonDictionary &class_dict) const { + +using namespace python; + +std::map checker; +#define SET_ERROR_AND_CONTINUE(method_name, error) \ + { \ +checker[method_name] = error; \ +continue; \ + } JDevlieghere wrote: Can this be a lambda? https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
@@ -26,6 +26,10 @@ class ScriptedPlatformInterface : virtual public ScriptedInterface { return {llvm::make_error()}; } + llvm::SmallVector GetAbstractMethods() const override { +return {}; + } JDevlieghere wrote: I think I asked something similar in a previous PR (and forgot the answer). Give that this has come up repeatedly, it would be good to document this somewhere (for example in the relevant classes). https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
@@ -99,25 +135,87 @@ class ScriptedPythonInterface : virtual public ScriptedInterface { } llvm::Expected expected_return_object = - llvm::createStringError(llvm::inconvertibleErrorCode(), - "Resulting object is not initialized."); + create_error("Resulting object is not initialized."); std::apply( - [&method, &expected_return_object](auto &&...args) { + [&init, &expected_return_object](auto &&...args) { llvm::consumeError(expected_return_object.takeError()); -expected_return_object = method(args...); +expected_return_object = init(args...); }, transformed_args); - if (llvm::Error e = expected_return_object.takeError()) -return std::move(e); - result = std::move(expected_return_object.get()); + if (!expected_return_object) +return expected_return_object.takeError(); + result = expected_return_object.get(); } if (!result.IsValid()) - return llvm::createStringError( - llvm::inconvertibleErrorCode(), - "Resulting object is not a valid Python Object."); + return create_error("Resulting object is not a valid Python Object."); +if (!result.HasAttribute("__class__")) + return create_error("Resulting object doesn't have '__class__' member."); + +PythonObject obj_class = result.GetAttributeValue("__class__"); +if (!obj_class.IsValid()) + return create_error("Resulting class object is not a valid."); +if (!obj_class.HasAttribute("__name__")) + return create_error( + "Resulting object class doesn't have '__name__' member."); +PythonString obj_class_name = +obj_class.GetAttributeValue("__name__").AsType(); + +PythonObject object_class_mapping_proxy = +obj_class.GetAttributeValue("__dict__"); +if (!obj_class.HasAttribute("__dict__")) + return create_error( + "Resulting object class doesn't have '__dict__' member."); + +PythonCallable dict_converter = PythonModule::BuiltinsModule() +.ResolveName("dict") +.AsType(); +if (!dict_converter.IsAllocated()) + return create_error( + "Python 'builtins' module doesn't have 'dict' class."); + +PythonDictionary object_class_dict = +dict_converter(object_class_mapping_proxy).AsType(); +if (!object_class_dict.IsAllocated()) + return create_error("Coudn't create dictionary from resulting object " + "class mapping proxy object."); + +auto checker_or_err = CheckAbstractMethodImplementation(object_class_dict); +if (!checker_or_err) + return checker_or_err.takeError(); + +for (const auto &method_checker : *checker_or_err) + switch (method_checker.second) { + case AbstractMethodCheckerCases::eNotImplemented: +LLDB_LOG(GetLog(LLDBLog::Script), + "❌ Abstract method {0}.{1} not implemented.", + obj_class_name.GetString(), method_checker.first); +break; + case AbstractMethodCheckerCases::eNotAllocated: +LLDB_LOG(GetLog(LLDBLog::Script), + "❌ Abstract method {0}.{1} not allocated.", + obj_class_name.GetString(), method_checker.first); +break; + case AbstractMethodCheckerCases::eNotCallable: +LLDB_LOG(GetLog(LLDBLog::Script), + "❌ Abstract method {0}.{1} not callable.", + obj_class_name.GetString(), method_checker.first); +break; + case AbstractMethodCheckerCases::eValid: +LLDB_LOG(GetLog(LLDBLog::Script), + "✅ Abstract method {0}.{1} implemented & valid.", + obj_class_name.GetString(), method_checker.first); JDevlieghere wrote: As much as I like emojis, I'd very much prefer to keep the logs plain old ASCII. https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Replace some register handling asserts with lldbassert (PR #71175)
https://github.com/clayborg approved this pull request. These asserts are testing that the static representation of register contexts is ok and building and testing with asserts enabled should flush out any issues. `lldbassert()` is perfect for this since it is enabled for debug builds while testing happens. https://github.com/llvm/llvm-project/pull/71175 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
@@ -32,27 +32,66 @@ class ScriptedPythonInterface : virtual public ScriptedInterface { ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter); ~ScriptedPythonInterface() override = default; + enum class AbstractMethodCheckerCases { +eNotImplemented, +eNotAllocated, +eNotCallable, +eValid + }; + + llvm::Expected> + CheckAbstractMethodImplementation( + const python::PythonDictionary &class_dict) const { + +using namespace python; + +std::map checker; +#define SET_ERROR_AND_CONTINUE(method_name, error) \ + { \ +checker[method_name] = error; \ +continue; \ + } medismailben wrote: No because we won't be able to `continue` in the lambda. https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
@@ -99,25 +135,87 @@ class ScriptedPythonInterface : virtual public ScriptedInterface { } llvm::Expected expected_return_object = - llvm::createStringError(llvm::inconvertibleErrorCode(), - "Resulting object is not initialized."); + create_error("Resulting object is not initialized."); std::apply( - [&method, &expected_return_object](auto &&...args) { + [&init, &expected_return_object](auto &&...args) { llvm::consumeError(expected_return_object.takeError()); -expected_return_object = method(args...); +expected_return_object = init(args...); }, transformed_args); - if (llvm::Error e = expected_return_object.takeError()) -return std::move(e); - result = std::move(expected_return_object.get()); + if (!expected_return_object) +return expected_return_object.takeError(); + result = expected_return_object.get(); } if (!result.IsValid()) - return llvm::createStringError( - llvm::inconvertibleErrorCode(), - "Resulting object is not a valid Python Object."); + return create_error("Resulting object is not a valid Python Object."); +if (!result.HasAttribute("__class__")) + return create_error("Resulting object doesn't have '__class__' member."); + +PythonObject obj_class = result.GetAttributeValue("__class__"); +if (!obj_class.IsValid()) + return create_error("Resulting class object is not a valid."); +if (!obj_class.HasAttribute("__name__")) + return create_error( + "Resulting object class doesn't have '__name__' member."); +PythonString obj_class_name = +obj_class.GetAttributeValue("__name__").AsType(); + +PythonObject object_class_mapping_proxy = +obj_class.GetAttributeValue("__dict__"); +if (!obj_class.HasAttribute("__dict__")) + return create_error( + "Resulting object class doesn't have '__dict__' member."); + +PythonCallable dict_converter = PythonModule::BuiltinsModule() +.ResolveName("dict") +.AsType(); +if (!dict_converter.IsAllocated()) + return create_error( + "Python 'builtins' module doesn't have 'dict' class."); + +PythonDictionary object_class_dict = +dict_converter(object_class_mapping_proxy).AsType(); +if (!object_class_dict.IsAllocated()) + return create_error("Coudn't create dictionary from resulting object " + "class mapping proxy object."); + +auto checker_or_err = CheckAbstractMethodImplementation(object_class_dict); +if (!checker_or_err) + return checker_or_err.takeError(); + +for (const auto &method_checker : *checker_or_err) + switch (method_checker.second) { + case AbstractMethodCheckerCases::eNotImplemented: +LLDB_LOG(GetLog(LLDBLog::Script), + "❌ Abstract method {0}.{1} not implemented.", + obj_class_name.GetString(), method_checker.first); +break; + case AbstractMethodCheckerCases::eNotAllocated: +LLDB_LOG(GetLog(LLDBLog::Script), + "❌ Abstract method {0}.{1} not allocated.", + obj_class_name.GetString(), method_checker.first); +break; + case AbstractMethodCheckerCases::eNotCallable: +LLDB_LOG(GetLog(LLDBLog::Script), + "❌ Abstract method {0}.{1} not callable.", + obj_class_name.GetString(), method_checker.first); +break; + case AbstractMethodCheckerCases::eValid: +LLDB_LOG(GetLog(LLDBLog::Script), + "✅ Abstract method {0}.{1} implemented & valid.", + obj_class_name.GetString(), method_checker.first); medismailben wrote: 💔 https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
https://github.com/medismailben edited https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
medismailben wrote: > Is there any way we could avoid ever having to instantiate a > `Scripted{.*}Interface`? @JDevlieghere I actually suggested something here https://github.com/llvm/llvm-project/pull/71260#discussion_r1383748012 https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Replace some register handling asserts with lldbassert (PR #71175)
JDevlieghere wrote: > These asserts are testing that the static representation of register contexts > is ok and building and testing with asserts enabled should flush out any > issues. `lldbassert()` is perfect for this since it is enabled for debug > builds while testing happens. The [contributing guidelines](https://lldb.llvm.org/resources/contributing.html) say: > New code should not be using lldbassert() and existing uses should be > replaced by other means of error handling. This was added (and last discussed) in https://reviews.llvm.org/D59911. It seems like there's enough different opinions on this topic that might warrant a proper RFC. https://github.com/llvm/llvm-project/pull/71175 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 876bd79 - [lldb][test] TestVTableValue.py: skip test for older versions of clang (#71372)
Author: Michael Buch Date: 2023-11-06T19:15:39Z New Revision: 876bd794fc33c74fc8689015699b9fec06dd0580 URL: https://github.com/llvm/llvm-project/commit/876bd794fc33c74fc8689015699b9fec06dd0580 DIFF: https://github.com/llvm/llvm-project/commit/876bd794fc33c74fc8689015699b9fec06dd0580.diff LOG: [lldb][test] TestVTableValue.py: skip test for older versions of clang (#71372) This fails on the matrix build bot for Clang versions < 9.0 https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake-matrix/7309/execution/node/102/log/?consoleFull ``` FAIL: LLDB :: test_vtable (TestVTableValue.TestVTableValue) : success == FAIL: test_base_class_ptr (TestVTableValue.TestVTableValue) -- Traceback (most recent call last): File "lldb/test/API/functionalities/vtable/TestVTableValue.py", line 90, in test_base_class_ptr self.assertEquals(shape_ptr_vtable.GetNumChildren(), 5) AssertionError: 6 != 5 == FAIL: test_vtable (TestVTableValue.TestVTableValue) -- Traceback (most recent call last): File "lldb/test/API/functionalities/vtable/TestVTableValue.py", line 67, in test_vtable self.assertEquals(vtable.GetNumChildren(), 5) AssertionError: 6 != 5 -- Ran 4 tests in 2.799s RESULT: FAILED (2 passes, 2 failures, 0 errors, 0 skipped, 0 expected failures, 0 unexpected successes) ``` Added: Modified: lldb/test/API/functionalities/vtable/TestVTableValue.py Removed: diff --git a/lldb/test/API/functionalities/vtable/TestVTableValue.py b/lldb/test/API/functionalities/vtable/TestVTableValue.py index 1c238ad60739bd9..ff1dc7a6cdba189 100644 --- a/lldb/test/API/functionalities/vtable/TestVTableValue.py +++ b/lldb/test/API/functionalities/vtable/TestVTableValue.py @@ -14,6 +14,7 @@ class TestVTableValue(TestBase): # each debug info format. NO_DEBUG_INFO_TESTCASE = True +@skipIf(compiler="clang", compiler_version=["<", "9.0"]) @skipUnlessPlatform(["linux", "macosx"]) def test_vtable(self): self.build() ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][test] TestVTableValue.py: skip test for older versions of clang (PR #71372)
https://github.com/Michael137 closed https://github.com/llvm/llvm-project/pull/71372 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [mlir] [compiler-rt] [llvm] [clang-tools-extra] [flang] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)
ZequanWu wrote: Ping. https://github.com/llvm/llvm-project/pull/69493 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add field information for the CPSR register (PR #70300)
@@ -0,0 +1,102 @@ +//===-- RegisterFlagsLinux_arm64.cpp --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "RegisterFlagsLinux_arm64.h" +#include "lldb/lldb-private-types.h" + +// This file is built on all systems because it is used by native processes and +// core files, so we manually define the needed HWCAP values here. + +#define HWCAP_DIT (1 << 24) +#define HWCAP_SSBS (1 << 28) + +#define HWCAP2_BTI (1 << 17) +#define HWCAP2_MTE (1 << 18) + +using namespace lldb_private; + +LinuxArm64RegisterFlags::Fields +LinuxArm64RegisterFlags::DetectCPSRFields(uint64_t hwcap, uint64_t hwcap2) { + // The fields here are a combination of the Arm manual's SPSR_EL1, + // plus a few changes where Linux has decided not to make use of them at all, + // or at least not from userspace. + + // Status bits that are always present. + std::vector cpsr_fields{ + {"N", 31}, {"Z", 30}, {"C", 29}, {"V", 28}, + // Bits 27-26 reserved. + }; + + if (hwcap2 & HWCAP2_MTE) +cpsr_fields.push_back({"TCO", 25}); + if (hwcap & HWCAP_DIT) +cpsr_fields.push_back({"DIT", 24}); + + // UAO and PAN are bits 23 and 22 and have no meaning for userspace so + // are treated as reserved by the kernel. + + cpsr_fields.push_back({"SS", 21}); + cpsr_fields.push_back({"IL", 20}); + // Bits 19-14 reserved. + + // Bit 13, ALLINT, requires FEAT_NMI that isn't relevant to userspace, and we + // can't detect either, don't show this field. + if (hwcap & HWCAP_SSBS) +cpsr_fields.push_back({"SSBS", 12}); + if (hwcap2 & HWCAP2_BTI) +cpsr_fields.push_back({"BTYPE", 10, 11}); + + cpsr_fields.push_back({"D", 9}); + cpsr_fields.push_back({"A", 8}); + cpsr_fields.push_back({"I", 7}); + cpsr_fields.push_back({"F", 6}); + // Bit 5 reserved + // Called "M" in the ARMARM. + cpsr_fields.push_back({"nRW", 4}); + // This is a 4 bit field M[3:0] in the ARMARM, we split it into parts. + cpsr_fields.push_back({"EL", 2, 3}); + // Bit 1 is unused and expected to be 0. + cpsr_fields.push_back({"SP", 0}); + + return cpsr_fields; +} + +void LinuxArm64RegisterFlags::DetectFields(uint64_t hwcap, uint64_t hwcap2) { + for (auto ® : m_registers) +reg.m_flags.SetFields(reg.m_detector(hwcap, hwcap2)); + m_has_detected = true; +} + +void LinuxArm64RegisterFlags::UpdateRegisterInfo(const RegisterInfo *reg_info, + uint32_t num_regs) { + assert(m_has_detected && + "Must call DetectFields before updating register info."); + + // Register names will not be duplicated, so we do not want to compare against + // one if it has already been found. Each time we find one, we erase it from + // this list. + std::vector> search_registers; + for (const auto ® : m_registers) { +// It is possible that a register is all extension dependent fields, and +// none of them are present. +if (reg.m_flags.GetFields().size()) + search_registers.push_back({reg.m_name, ®.m_flags}); + } + + uint32_t idx = 0; + for (; idx < num_regs && search_registers.size(); ++idx, ++reg_info) { +auto end = search_registers.cend(); +for (auto it = search_registers.cbegin(); it != end; ++it) { + if (std::strcmp(reg_info->name, it->first) == 0) { +reg_info->flags_type = it->second; +search_registers.erase(it); +break; + } +} + } +} bulbazord wrote: This just removes register information when iterating over `search_registers` right? There are a few things I might be missing, but I would recommend that you write this more succinctly with a use of `remove_if` (either from `std` or `llvm`, I kind of prefer the `llvm` version myself). https://github.com/llvm/llvm-project/pull/70300 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add field information for the CPSR register (PR #70300)
@@ -67,6 +70,21 @@ RegisterContextCorePOSIX_arm64::RegisterContextCorePOSIX_arm64( : RegisterContextPOSIX_arm64(thread, std::move(register_info)) { ::memset(&m_sme_pseudo_regs, 0, sizeof(m_sme_pseudo_regs)); + ProcessElfCore *process = + static_cast(thread.GetProcess().get()); bulbazord wrote: I don't think you need to do this right now, but it would be nice if we could move away from `static_cast` and start using the llvm RTTI support with `llvm::cast` instead... https://github.com/llvm/llvm-project/pull/70300 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add field information for the CPSR register (PR #70300)
@@ -0,0 +1,77 @@ +//===-- RegisterFlagsLinux_arm64.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERFLAGSLINUX_ARM64_H +#define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERFLAGSLINUX_ARM64_H + +#include "lldb/Target/RegisterFlags.h" +#include + +namespace lldb_private { + +struct RegisterInfo; + +/// This class manages the storage and detection of register field information +/// for Arm64 Linux registers. The same register may have different fields on +/// different CPUs. This class abstracts out the field detection process so we +/// can use it on live processes and core files. +/// +/// The general way to use this class is: +/// * Make an instance somewhere that will last as long as the debug session +/// (because your final register info will point to this instance). +/// * Read hardware capabilities from a core note, binary, prctl, etc. +/// * Pass those to DetectFields. +/// * Call UpdateRegisterInfo with your RegisterInfo to add pointers +/// to the detected fields for all registers listed in this class. +/// +/// This must be done in that order, and you should ensure that if multiple +/// threads will reference the information, a mutex is used to make sure only +/// one calls DetectFields. +class LinuxArm64RegisterFlags { +public: + /// For the registers listed in this class, detect which fields are + /// present. Must be called before UpdateRegisterInfos. + /// If called more than once, fields will be redetected each time from + /// scratch. If you do not have access to hwcap, just pass 0 for each one, you + /// will only get unconditional fields. + void DetectFields(uint64_t hwcap, uint64_t hwcap2); + + /// Add the field information of any registers named in this class, + /// to the relevant RegisterInfo instances. Note that this will be done + /// with a pointer to the instance of this class that you call this on, so + /// the lifetime of that instance must be at least that of the register info. + void UpdateRegisterInfo(const RegisterInfo *reg_info, uint32_t num_regs); + + /// Returns true if field detection has been run at least once. + bool HasDetected() const { return m_has_detected; } + +private: + using Fields = std::vector; + using DetectorFn = std::function; + + static Fields DetectCPSRFields(uint64_t hwcap, uint64_t hwcap2); + + struct RegisterEntry { +RegisterEntry(const char *name, unsigned size, DetectorFn detector) +: m_name(name), m_flags(std::string(name) + "_flags", size, {{"", 0}}), bulbazord wrote: If name is `nullptr`, constructing `m_flags` will crash when you try to do `std::string(name) + "_flags"`. Not an issue now, but maybe it will be one day. Maybe `name` can be an `llvm::StringRef` instead? You can't construct an `llvm::StringRef` from nullptr so it would be a compile time issue instead of a runtime issue. https://github.com/llvm/llvm-project/pull/70300 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add template method for getting const or mutable regs from DynamicRegisterInfo (PR #71402)
https://github.com/bulbazord approved this pull request. Works for me. https://github.com/llvm/llvm-project/pull/71402 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add template method for getting const or mutable regs from DynamicRegisterInfo (PR #71402)
https://github.com/bulbazord edited https://github.com/llvm/llvm-project/pull/71402 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add template method for getting const or mutable regs from DynamicRegisterInfo (PR #71402)
@@ -89,12 +89,18 @@ class DynamicRegisterInfo { GetRegisterInfo(llvm::StringRef reg_name) const; typedef std::vector reg_collection; - llvm::iterator_range registers() const { -return llvm::iterator_range(m_regs); + + template T registers(); bulbazord wrote: Maybe explicitly delete the default non-specialized implementation? That would move an incorrect usage from a linker error to a compiler error (which is a little easier to reason about for most folks) https://github.com/llvm/llvm-project/pull/71402 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] f4df0c4 - [lldb][NFCI] Change parameter type in Target::AddNameToBreakpoint (#71241)
Author: Alex Langford Date: 2023-11-06T12:45:02-08:00 New Revision: f4df0c48e912f01abe2ecaad207b469745620c5d URL: https://github.com/llvm/llvm-project/commit/f4df0c48e912f01abe2ecaad207b469745620c5d DIFF: https://github.com/llvm/llvm-project/commit/f4df0c48e912f01abe2ecaad207b469745620c5d.diff LOG: [lldb][NFCI] Change parameter type in Target::AddNameToBreakpoint (#71241) By itself this change does very little, but I plan on refactoring something from StructuredData and it gets much easier with this change. Added: Modified: lldb/include/lldb/Target/Target.h lldb/source/Target/Target.cpp Removed: diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 82045988018b606..c37682e2a03859f 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -763,9 +763,10 @@ class Target : public std::enable_shared_from_this, WatchpointList &GetWatchpointList() { return m_watchpoint_list; } // Manages breakpoint names: - void AddNameToBreakpoint(BreakpointID &id, const char *name, Status &error); + void AddNameToBreakpoint(BreakpointID &id, llvm::StringRef name, + Status &error); - void AddNameToBreakpoint(lldb::BreakpointSP &bp_sp, const char *name, + void AddNameToBreakpoint(lldb::BreakpointSP &bp_sp, llvm::StringRef name, Status &error); void RemoveNameFromBreakpoint(lldb::BreakpointSP &bp_sp, ConstString name); diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 5f8756c57675c95..a6d7148c84e20be 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -727,7 +727,7 @@ void Target::AddBreakpoint(lldb::BreakpointSP bp_sp, bool internal) { } } -void Target::AddNameToBreakpoint(BreakpointID &id, const char *name, +void Target::AddNameToBreakpoint(BreakpointID &id, llvm::StringRef name, Status &error) { BreakpointSP bp_sp = m_breakpoint_list.FindBreakpointByID(id.GetBreakpointID()); @@ -740,7 +740,7 @@ void Target::AddNameToBreakpoint(BreakpointID &id, const char *name, AddNameToBreakpoint(bp_sp, name, error); } -void Target::AddNameToBreakpoint(BreakpointSP &bp_sp, const char *name, +void Target::AddNameToBreakpoint(BreakpointSP &bp_sp, llvm::StringRef name, Status &error) { if (!bp_sp) return; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFCI] Change parameter type in Target::AddNameToBreakpoint (PR #71241)
https://github.com/bulbazord closed https://github.com/llvm/llvm-project/pull/71241 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Change Breakpoint::AddName return value (PR #71236)
bulbazord wrote: @jimingham Does this work for you? https://github.com/llvm/llvm-project/pull/71236 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Change Breakpoint::AddName return value (PR #71236)
https://github.com/medismailben approved this pull request. https://github.com/llvm/llvm-project/pull/71236 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [llvm] DEBUGINFOD based DWP acquisition for LLDB (PR #70996)
JDevlieghere wrote: FWIW the "plugin-ification" has landed so this should be able to move forward as a plugin. https://github.com/llvm/llvm-project/pull/70996 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
@@ -663,6 +663,18 @@ bool PythonDictionary::Check(PyObject *py_obj) { return PyDict_Check(py_obj); } +bool PythonDictionary::HasKey(const llvm::Twine &key) const { medismailben wrote: Done! https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [llvm] [mlir] [compiler-rt] [lldb] [clang] [libcxxabi] [libcxx] Adding Separate OpenMP Offloading Backend to `libcxx/include/__algorithm/pstl_backends` (PR #66968)
@@ -330,6 +330,23 @@ def getStdFlag(cfg, std): default=f"{shlex.quote(sys.executable)} {shlex.quote(str(Path(__file__).resolve().parent.parent.parent / 'run.py'))}", help="Custom executor to use instead of the configured default.", actions=lambda executor: [AddSubstitution("%{executor}", executor)], +), +Parameter( +name="openmp_pstl_backend", +choices=[True, False], +type=bool, +default=False, +help="Enable the OpenMP compilation toolchain if the PSTL backend was set to OpenMP.", +actions=lambda enabled: [ +AddCompileFlag("-fopenmp"), AntonRydahl wrote: I think there is unfortunately no better way of doing this at the moment, except for changing Clang. The problem is that OpenMP might already be shipped with the system, and then a lot of conflicts can happen if the wrong version of the OpenMP target library or the device runtime is picked up. But I agree that this is indeed not very user friendly and that it would be a lot nicer if Clang automatically did this. https://github.com/llvm/llvm-project/pull/66968 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
@@ -26,6 +26,10 @@ class ScriptedPlatformInterface : virtual public ScriptedInterface { return {llvm::make_error()}; } + llvm::SmallVector GetAbstractMethods() const override { +return {}; + } medismailben wrote: Ok, I'll make the the base class abstract, and return a nullptr in `ScriptInterpreter::CreateScripted*Interface` in a follow-up, that should - hopefully - address all the confusion. https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [llvm] [clang-tools-extra] [lldb] [flang] [compiler-rt] [libcxx] [lld] [YAMLParser] Unfold multi-line scalar values (PR #70898)
https://github.com/slinder1 requested changes to this pull request. I don't mean to make existing debt your problem, but if it isn't too much work could you post a pre-patch that just adds the `FileCheck`s to the existing tests where the behavior changes, so the test diff is more self-documenting? I left some comments but not so much about spec compliance as I don't have the time right now to work through it right now. Either way, thank you for the work, and I'm happy to see the parser move towards more compliant parsing! https://github.com/llvm/llvm-project/pull/70898 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang-tools-extra] [llvm] [lld] [compiler-rt] [libcxx] [flang] [lldb] [clang] [YAMLParser] Unfold multi-line scalar values (PR #70898)
@@ -2030,187 +2030,219 @@ bool Node::failed() const { } StringRef ScalarNode::getValue(SmallVectorImpl &Storage) const { - // TODO: Handle newlines properly. We need to remove leading whitespace. - if (Value[0] == '"') { // Double quoted. -// Pull off the leading and trailing "s. -StringRef UnquotedValue = Value.substr(1, Value.size() - 2); -// Search for characters that would require unescaping the value. -StringRef::size_type i = UnquotedValue.find_first_of("\\\r\n"); -if (i != StringRef::npos) - return unescapeDoubleQuoted(UnquotedValue, i, Storage); + if (Value[0] == '"') +return getDoubleQuotedValue(Value, Storage); + if (Value[0] == '\'') +return getSingleQuotedValue(Value, Storage); + return getPlainValue(Value, Storage); +} + +static StringRef +parseScalarValue(StringRef UnquotedValue, SmallVectorImpl &Storage, + StringRef LookupChars, + std::function &)> + UnescapeCallback) { + size_t I = UnquotedValue.find_first_of(LookupChars); + if (I == StringRef::npos) return UnquotedValue; - } else if (Value[0] == '\'') { // Single quoted. -// Pull off the leading and trailing 's. -StringRef UnquotedValue = Value.substr(1, Value.size() - 2); -StringRef::size_type i = UnquotedValue.find('\''); -if (i != StringRef::npos) { - // We're going to need Storage. - Storage.clear(); - Storage.reserve(UnquotedValue.size()); - for (; i != StringRef::npos; i = UnquotedValue.find('\'')) { -StringRef Valid(UnquotedValue.begin(), i); -llvm::append_range(Storage, Valid); -Storage.push_back('\''); -UnquotedValue = UnquotedValue.substr(i + 2); - } - llvm::append_range(Storage, UnquotedValue); - return StringRef(Storage.begin(), Storage.size()); -} -return UnquotedValue; - } - // Plain. - // Trim whitespace ('b-char' and 's-white'). - // NOTE: Alternatively we could change the scanner to not include whitespace - // here in the first place. - return Value.rtrim("\x0A\x0D\x20\x09"); -} -StringRef ScalarNode::unescapeDoubleQuoted( StringRef UnquotedValue - , StringRef::size_type i - , SmallVectorImpl &Storage) - const { - // Use Storage to build proper value. Storage.clear(); Storage.reserve(UnquotedValue.size()); - for (; i != StringRef::npos; i = UnquotedValue.find_first_of("\\\r\n")) { -// Insert all previous chars into Storage. -StringRef Valid(UnquotedValue.begin(), i); -llvm::append_range(Storage, Valid); -// Chop off inserted chars. -UnquotedValue = UnquotedValue.substr(i); - -assert(!UnquotedValue.empty() && "Can't be empty!"); - -// Parse escape or line break. -switch (UnquotedValue[0]) { -case '\r': -case '\n': - Storage.push_back('\n'); - if ( UnquotedValue.size() > 1 - && (UnquotedValue[1] == '\r' || UnquotedValue[1] == '\n')) -UnquotedValue = UnquotedValue.substr(1); - UnquotedValue = UnquotedValue.substr(1); - break; -default: - if (UnquotedValue.size() == 1) { -Token T; -T.Range = StringRef(UnquotedValue.begin(), 1); -setError("Unrecognized escape code", T); -return ""; - } - UnquotedValue = UnquotedValue.substr(1); - switch (UnquotedValue[0]) { - default: { - Token T; - T.Range = StringRef(UnquotedValue.begin(), 1); - setError("Unrecognized escape code", T); - return ""; -} - case '\r': - case '\n': -// Remove the new line. -if ( UnquotedValue.size() > 1 -&& (UnquotedValue[1] == '\r' || UnquotedValue[1] == '\n')) - UnquotedValue = UnquotedValue.substr(1); -// If this was just a single byte newline, it will get skipped -// below. -break; - case '0': -Storage.push_back(0x00); -break; - case 'a': -Storage.push_back(0x07); -break; - case 'b': -Storage.push_back(0x08); -break; - case 't': - case 0x09: -Storage.push_back(0x09); -break; - case 'n': -Storage.push_back(0x0A); -break; - case 'v': -Storage.push_back(0x0B); -break; - case 'f': -Storage.push_back(0x0C); -break; - case 'r': -Storage.push_back(0x0D); -break; - case 'e': -Storage.push_back(0x1B); -break; + char LastNewLineAddedAs = '\0'; + for (; I != StringRef::npos; I = UnquotedValue.find_first_of(LookupChars)) { +if (UnquotedValue[I] != '\x0D' && UnquotedValue[I] != '\x0A') { + llvm::append_range(Storage, UnquotedValue.take_front(I)); + UnquotedValue = UnescapeCallback(UnquotedValue.drop_front(I), Storage); + LastNewLineAddedAs = '\0'; + contin
[Lldb-commits] [clang-tools-extra] [clang] [libcxx] [llvm] [flang] [lldb] [compiler-rt] [lld] [YAMLParser] Unfold multi-line scalar values (PR #70898)
@@ -2030,187 +2030,219 @@ bool Node::failed() const { } StringRef ScalarNode::getValue(SmallVectorImpl &Storage) const { - // TODO: Handle newlines properly. We need to remove leading whitespace. - if (Value[0] == '"') { // Double quoted. -// Pull off the leading and trailing "s. -StringRef UnquotedValue = Value.substr(1, Value.size() - 2); -// Search for characters that would require unescaping the value. -StringRef::size_type i = UnquotedValue.find_first_of("\\\r\n"); -if (i != StringRef::npos) - return unescapeDoubleQuoted(UnquotedValue, i, Storage); + if (Value[0] == '"') +return getDoubleQuotedValue(Value, Storage); + if (Value[0] == '\'') +return getSingleQuotedValue(Value, Storage); + return getPlainValue(Value, Storage); +} + +static StringRef +parseScalarValue(StringRef UnquotedValue, SmallVectorImpl &Storage, + StringRef LookupChars, + std::function &)> + UnescapeCallback) { + size_t I = UnquotedValue.find_first_of(LookupChars); + if (I == StringRef::npos) return UnquotedValue; - } else if (Value[0] == '\'') { // Single quoted. -// Pull off the leading and trailing 's. -StringRef UnquotedValue = Value.substr(1, Value.size() - 2); -StringRef::size_type i = UnquotedValue.find('\''); -if (i != StringRef::npos) { - // We're going to need Storage. - Storage.clear(); - Storage.reserve(UnquotedValue.size()); - for (; i != StringRef::npos; i = UnquotedValue.find('\'')) { -StringRef Valid(UnquotedValue.begin(), i); -llvm::append_range(Storage, Valid); -Storage.push_back('\''); -UnquotedValue = UnquotedValue.substr(i + 2); - } - llvm::append_range(Storage, UnquotedValue); - return StringRef(Storage.begin(), Storage.size()); -} -return UnquotedValue; - } - // Plain. - // Trim whitespace ('b-char' and 's-white'). - // NOTE: Alternatively we could change the scanner to not include whitespace - // here in the first place. - return Value.rtrim("\x0A\x0D\x20\x09"); -} -StringRef ScalarNode::unescapeDoubleQuoted( StringRef UnquotedValue - , StringRef::size_type i - , SmallVectorImpl &Storage) - const { - // Use Storage to build proper value. Storage.clear(); Storage.reserve(UnquotedValue.size()); - for (; i != StringRef::npos; i = UnquotedValue.find_first_of("\\\r\n")) { -// Insert all previous chars into Storage. -StringRef Valid(UnquotedValue.begin(), i); -llvm::append_range(Storage, Valid); -// Chop off inserted chars. -UnquotedValue = UnquotedValue.substr(i); - -assert(!UnquotedValue.empty() && "Can't be empty!"); - -// Parse escape or line break. -switch (UnquotedValue[0]) { -case '\r': -case '\n': - Storage.push_back('\n'); - if ( UnquotedValue.size() > 1 - && (UnquotedValue[1] == '\r' || UnquotedValue[1] == '\n')) -UnquotedValue = UnquotedValue.substr(1); - UnquotedValue = UnquotedValue.substr(1); - break; -default: - if (UnquotedValue.size() == 1) { -Token T; -T.Range = StringRef(UnquotedValue.begin(), 1); -setError("Unrecognized escape code", T); -return ""; - } - UnquotedValue = UnquotedValue.substr(1); - switch (UnquotedValue[0]) { - default: { - Token T; - T.Range = StringRef(UnquotedValue.begin(), 1); - setError("Unrecognized escape code", T); - return ""; -} - case '\r': - case '\n': -// Remove the new line. -if ( UnquotedValue.size() > 1 -&& (UnquotedValue[1] == '\r' || UnquotedValue[1] == '\n')) - UnquotedValue = UnquotedValue.substr(1); -// If this was just a single byte newline, it will get skipped -// below. -break; - case '0': -Storage.push_back(0x00); -break; - case 'a': -Storage.push_back(0x07); -break; - case 'b': -Storage.push_back(0x08); -break; - case 't': - case 0x09: -Storage.push_back(0x09); -break; - case 'n': -Storage.push_back(0x0A); -break; - case 'v': -Storage.push_back(0x0B); -break; - case 'f': -Storage.push_back(0x0C); -break; - case 'r': -Storage.push_back(0x0D); -break; - case 'e': -Storage.push_back(0x1B); -break; + char LastNewLineAddedAs = '\0'; + for (; I != StringRef::npos; I = UnquotedValue.find_first_of(LookupChars)) { +if (UnquotedValue[I] != '\x0D' && UnquotedValue[I] != '\x0A') { + llvm::append_range(Storage, UnquotedValue.take_front(I)); + UnquotedValue = UnescapeCallback(UnquotedValue.drop_front(I), Storage); + LastNewLineAddedAs = '\0'; + contin
[Lldb-commits] [libcxx] [flang] [compiler-rt] [clang-tools-extra] [lldb] [llvm] [lld] [clang] [YAMLParser] Unfold multi-line scalar values (PR #70898)
https://github.com/slinder1 edited https://github.com/llvm/llvm-project/pull/70898 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [flang] [lldb] [clang] [llvm] [lld] [clang-tools-extra] [libcxx] [compiler-rt] [YAMLParser] Unfold multi-line scalar values (PR #70898)
@@ -2030,187 +2030,219 @@ bool Node::failed() const { } StringRef ScalarNode::getValue(SmallVectorImpl &Storage) const { - // TODO: Handle newlines properly. We need to remove leading whitespace. - if (Value[0] == '"') { // Double quoted. -// Pull off the leading and trailing "s. -StringRef UnquotedValue = Value.substr(1, Value.size() - 2); -// Search for characters that would require unescaping the value. -StringRef::size_type i = UnquotedValue.find_first_of("\\\r\n"); -if (i != StringRef::npos) - return unescapeDoubleQuoted(UnquotedValue, i, Storage); + if (Value[0] == '"') +return getDoubleQuotedValue(Value, Storage); + if (Value[0] == '\'') +return getSingleQuotedValue(Value, Storage); + return getPlainValue(Value, Storage); +} + +static StringRef +parseScalarValue(StringRef UnquotedValue, SmallVectorImpl &Storage, + StringRef LookupChars, + std::function &)> + UnescapeCallback) { + size_t I = UnquotedValue.find_first_of(LookupChars); + if (I == StringRef::npos) return UnquotedValue; - } else if (Value[0] == '\'') { // Single quoted. -// Pull off the leading and trailing 's. -StringRef UnquotedValue = Value.substr(1, Value.size() - 2); -StringRef::size_type i = UnquotedValue.find('\''); -if (i != StringRef::npos) { - // We're going to need Storage. - Storage.clear(); - Storage.reserve(UnquotedValue.size()); - for (; i != StringRef::npos; i = UnquotedValue.find('\'')) { -StringRef Valid(UnquotedValue.begin(), i); -llvm::append_range(Storage, Valid); -Storage.push_back('\''); -UnquotedValue = UnquotedValue.substr(i + 2); - } - llvm::append_range(Storage, UnquotedValue); - return StringRef(Storage.begin(), Storage.size()); -} -return UnquotedValue; - } - // Plain. - // Trim whitespace ('b-char' and 's-white'). - // NOTE: Alternatively we could change the scanner to not include whitespace - // here in the first place. - return Value.rtrim("\x0A\x0D\x20\x09"); -} -StringRef ScalarNode::unescapeDoubleQuoted( StringRef UnquotedValue - , StringRef::size_type i - , SmallVectorImpl &Storage) - const { - // Use Storage to build proper value. Storage.clear(); Storage.reserve(UnquotedValue.size()); - for (; i != StringRef::npos; i = UnquotedValue.find_first_of("\\\r\n")) { -// Insert all previous chars into Storage. -StringRef Valid(UnquotedValue.begin(), i); -llvm::append_range(Storage, Valid); -// Chop off inserted chars. -UnquotedValue = UnquotedValue.substr(i); - -assert(!UnquotedValue.empty() && "Can't be empty!"); - -// Parse escape or line break. -switch (UnquotedValue[0]) { -case '\r': -case '\n': - Storage.push_back('\n'); - if ( UnquotedValue.size() > 1 - && (UnquotedValue[1] == '\r' || UnquotedValue[1] == '\n')) -UnquotedValue = UnquotedValue.substr(1); - UnquotedValue = UnquotedValue.substr(1); - break; -default: - if (UnquotedValue.size() == 1) { -Token T; -T.Range = StringRef(UnquotedValue.begin(), 1); -setError("Unrecognized escape code", T); -return ""; - } - UnquotedValue = UnquotedValue.substr(1); - switch (UnquotedValue[0]) { - default: { - Token T; - T.Range = StringRef(UnquotedValue.begin(), 1); - setError("Unrecognized escape code", T); - return ""; -} - case '\r': - case '\n': -// Remove the new line. -if ( UnquotedValue.size() > 1 -&& (UnquotedValue[1] == '\r' || UnquotedValue[1] == '\n')) - UnquotedValue = UnquotedValue.substr(1); -// If this was just a single byte newline, it will get skipped -// below. -break; - case '0': -Storage.push_back(0x00); -break; - case 'a': -Storage.push_back(0x07); -break; - case 'b': -Storage.push_back(0x08); -break; - case 't': - case 0x09: -Storage.push_back(0x09); -break; - case 'n': -Storage.push_back(0x0A); -break; - case 'v': -Storage.push_back(0x0B); -break; - case 'f': -Storage.push_back(0x0C); -break; - case 'r': -Storage.push_back(0x0D); -break; - case 'e': -Storage.push_back(0x1B); -break; + char LastNewLineAddedAs = '\0'; + for (; I != StringRef::npos; I = UnquotedValue.find_first_of(LookupChars)) { +if (UnquotedValue[I] != '\x0D' && UnquotedValue[I] != '\x0A') { slinder1 wrote: Is there a reason to change from the "mnemonic" escape to a codepoint value one? E.g. is there a case where `'\r' != '\x0D'`, or is this just a stylistic c
[Lldb-commits] [clang-tools-extra] [clang] [libcxx] [compiler-rt] [llvm] [lldb] [flang] [lld] [YAMLParser] Unfold multi-line scalar values (PR #70898)
@@ -2030,187 +2030,219 @@ bool Node::failed() const { } StringRef ScalarNode::getValue(SmallVectorImpl &Storage) const { - // TODO: Handle newlines properly. We need to remove leading whitespace. - if (Value[0] == '"') { // Double quoted. -// Pull off the leading and trailing "s. -StringRef UnquotedValue = Value.substr(1, Value.size() - 2); -// Search for characters that would require unescaping the value. -StringRef::size_type i = UnquotedValue.find_first_of("\\\r\n"); -if (i != StringRef::npos) - return unescapeDoubleQuoted(UnquotedValue, i, Storage); + if (Value[0] == '"') +return getDoubleQuotedValue(Value, Storage); + if (Value[0] == '\'') +return getSingleQuotedValue(Value, Storage); + return getPlainValue(Value, Storage); +} + +static StringRef +parseScalarValue(StringRef UnquotedValue, SmallVectorImpl &Storage, + StringRef LookupChars, slinder1 wrote: That "\x0A\x0D" must be a part of `LookupChars` but cannot be handled by `UnescapeCallback` (or at least those characters will never reach the callback) is probably worthy of a comment, as it didn't follow for me immediately upon a first read. https://github.com/llvm/llvm-project/pull/70898 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
https://github.com/medismailben updated https://github.com/llvm/llvm-project/pull/71260 >From 4f15a3dfa7fdf600f76e434dc93879de910b317b Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Mon, 6 Nov 2023 14:15:12 -0800 Subject: [PATCH] [lldb] Check for abstract methods implementation in Scripted Plugin Objects This patch enforces that every scripted object implements all the necessary abstract methods. Every scripted affordance language interface can implement a list of abstract methods name that checked when the object is instanciated. Since some scripting affordances implementations can be derived from template base classes, we can't check the object dictionary since it will contain the definition of the base class, so instead, this checks the scripting class dictionary. Previously, for the various python interfaces, we used `ABC.abstractmethod` decorators but this is too language specific and doesn't work for scripting affordances that are not derived from template base classes (i.e OperatingSystem, ScriptedThreadPlan, ...), so this patch provides generic/language-agnostic checks for every scripted affordance. Signed-off-by: Med Ismail Bennani --- .../Interfaces/ScriptedInterface.h| 2 + .../Interfaces/ScriptedPlatformInterface.h| 4 + .../Interfaces/ScriptedProcessInterface.h | 4 + .../Interfaces/ScriptedThreadInterface.h | 4 + .../OperatingSystemPythonInterface.h | 7 + .../ScriptedPlatformPythonInterface.h | 6 + .../ScriptedProcessPythonInterface.h | 5 + .../Interfaces/ScriptedPythonInterface.h | 156 ++ .../ScriptedThreadPythonInterface.h | 5 + .../Python/PythonDataObjects.cpp | 14 ++ .../Python/PythonDataObjects.h| 2 + .../scripted_process/TestScriptedProcess.py | 49 ++ .../missing_methods_scripted_process.py | 19 +++ .../Python/PythonDataObjectsTests.cpp | 3 + 14 files changed, 251 insertions(+), 29 deletions(-) create mode 100644 lldb/test/API/functionalities/scripted_process/missing_methods_scripted_process.py diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h index e4816352daa5db6..9753a916243b7be 100644 --- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h +++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h @@ -30,6 +30,8 @@ class ScriptedInterface { return m_object_instance_sp; } + virtual llvm::SmallVector GetAbstractMethods() const = 0; + template static Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg, Status &error, diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h b/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h index 2dcbb47ffa6de85..e73565db88b0ce0 100644 --- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h +++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h @@ -26,6 +26,10 @@ class ScriptedPlatformInterface : virtual public ScriptedInterface { return {llvm::make_error()}; } + llvm::SmallVector GetAbstractMethods() const override { +return {}; + } + virtual StructuredData::DictionarySP ListProcesses() { return {}; } virtual StructuredData::DictionarySP GetProcessInfo(lldb::pid_t) { diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedProcessInterface.h b/lldb/include/lldb/Interpreter/Interfaces/ScriptedProcessInterface.h index a429cacd862f121..767ad50ba0978e2 100644 --- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedProcessInterface.h +++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedProcessInterface.h @@ -28,6 +28,10 @@ class ScriptedProcessInterface : virtual public ScriptedInterface { return {llvm::make_error()}; } + llvm::SmallVector GetAbstractMethods() const override { +return {}; + } + virtual StructuredData::DictionarySP GetCapabilities() { return {}; } virtual Status Attach(const ProcessAttachInfo &attach_info) { diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadInterface.h b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadInterface.h index 107e593b5561ef7..17bf8bc42490e84 100644 --- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadInterface.h +++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadInterface.h @@ -27,6 +27,10 @@ class ScriptedThreadInterface : virtual public ScriptedInterface { return {llvm::make_error()}; } + llvm::SmallVector GetAbstractMethods() const override { +return {}; + } + virtual lldb::tid_t GetThreadID() { return LLDB_INVALID_THREAD_ID; } virtual std::optional GetName() { return std::nullopt; } diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfa
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
https://github.com/JDevlieghere approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)
https://github.com/bulbazord approved this pull request. I'm on board https://github.com/llvm/llvm-project/pull/71260 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] walter/fix (PR #71455)
https://github.com/walter-erquinigo created https://github.com/llvm/llvm-project/pull/71455 - [LLDB][easy] Fix a bug in DummySyntheticFrontEnd - [LLDB] Don't forcefully initialize the process trace plugin >From 57d19fdd476b293a87f1c14b743ba636350af7a1 Mon Sep 17 00:00:00 2001 From: walter erquinigo Date: Fri, 3 Nov 2023 00:50:36 -0400 Subject: [PATCH 1/2] [LLDB][easy] Fix a bug in DummySyntheticFrontEnd DummySyntheticFrontEnd is implementing correctly CalculateNumChildren but not MightHaveChildren, where instead of delegating its action, it was returning true. This fixes that simple bug. --- lldb/source/Core/ValueObjectSyntheticFilter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Core/ValueObjectSyntheticFilter.cpp b/lldb/source/Core/ValueObjectSyntheticFilter.cpp index 59ed780b654f3af..43bc532c4a0410b 100644 --- a/lldb/source/Core/ValueObjectSyntheticFilter.cpp +++ b/lldb/source/Core/ValueObjectSyntheticFilter.cpp @@ -41,7 +41,7 @@ class DummySyntheticFrontEnd : public SyntheticChildrenFrontEnd { return m_backend.GetIndexOfChildWithName(name); } - bool MightHaveChildren() override { return true; } + bool MightHaveChildren() override { return m_backend.MightHaveChildren(); } bool Update() override { return false; } }; >From 6655ac4547f4aea53ffa3576359abc8545d41cc7 Mon Sep 17 00:00:00 2001 From: walter erquinigo Date: Mon, 6 Nov 2023 17:57:45 -0500 Subject: [PATCH 2/2] [LLDB] Don't forcefully initialize the process trace plugin This was causing some process to wrongfully be handled by ProcessTrace. The only place this was being used is in the intel pt plugin, but it doesn't even build anymore, so I'm sure no one is using it. --- lldb/source/API/SystemInitializerFull.cpp| 3 --- .../Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp | 9 + 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lldb/source/API/SystemInitializerFull.cpp b/lldb/source/API/SystemInitializerFull.cpp index 27319debc858288..c48466f25ede81b 100644 --- a/lldb/source/API/SystemInitializerFull.cpp +++ b/lldb/source/API/SystemInitializerFull.cpp @@ -68,9 +68,6 @@ llvm::Error SystemInitializerFull::Initialize() { #define LLDB_PLUGIN(p) LLDB_PLUGIN_INITIALIZE(p); #include "Plugins/Plugins.def" - // Initialize plug-ins in core LLDB - ProcessTrace::Initialize(); - // Scan for any system or user LLDB plug-ins PluginManager::Initialize(); diff --git a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp index 6bed78fd83f0b70..bd9cca675f2d747 100644 --- a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp +++ b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp @@ -103,10 +103,11 @@ TraceIntelPTBundleLoader::CreateEmptyProcess(lldb::pid_t pid, ParsedProcess parsed_process; parsed_process.target_sp = target_sp; - ProcessSP process_sp = target_sp->CreateProcess( - /*listener*/ nullptr, "trace", - /*crash_file*/ nullptr, - /*can_connect*/ false); + // This should instead try to directly create an instance of ProcessTrace. + // ProcessSP process_sp = target_sp->CreateProcess( + ///*listener*/ nullptr, "trace", + ///*crash_file*/ nullptr, + ///*can_connect*/ false); process_sp->SetID(static_cast(pid)); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] walter/fix (PR #71455)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Walter Erquinigo (walter-erquinigo) Changes - [LLDB][easy] Fix a bug in DummySyntheticFrontEnd - [LLDB] Don't forcefully initialize the process trace plugin --- Full diff: https://github.com/llvm/llvm-project/pull/71455.diff 3 Files Affected: - (modified) lldb/source/API/SystemInitializerFull.cpp (-3) - (modified) lldb/source/Core/ValueObjectSyntheticFilter.cpp (+1-1) - (modified) lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp (+5-4) ``diff diff --git a/lldb/source/API/SystemInitializerFull.cpp b/lldb/source/API/SystemInitializerFull.cpp index 27319debc858288..c48466f25ede81b 100644 --- a/lldb/source/API/SystemInitializerFull.cpp +++ b/lldb/source/API/SystemInitializerFull.cpp @@ -68,9 +68,6 @@ llvm::Error SystemInitializerFull::Initialize() { #define LLDB_PLUGIN(p) LLDB_PLUGIN_INITIALIZE(p); #include "Plugins/Plugins.def" - // Initialize plug-ins in core LLDB - ProcessTrace::Initialize(); - // Scan for any system or user LLDB plug-ins PluginManager::Initialize(); diff --git a/lldb/source/Core/ValueObjectSyntheticFilter.cpp b/lldb/source/Core/ValueObjectSyntheticFilter.cpp index 59ed780b654f3af..43bc532c4a0410b 100644 --- a/lldb/source/Core/ValueObjectSyntheticFilter.cpp +++ b/lldb/source/Core/ValueObjectSyntheticFilter.cpp @@ -41,7 +41,7 @@ class DummySyntheticFrontEnd : public SyntheticChildrenFrontEnd { return m_backend.GetIndexOfChildWithName(name); } - bool MightHaveChildren() override { return true; } + bool MightHaveChildren() override { return m_backend.MightHaveChildren(); } bool Update() override { return false; } }; diff --git a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp index 6bed78fd83f0b70..bd9cca675f2d747 100644 --- a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp +++ b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp @@ -103,10 +103,11 @@ TraceIntelPTBundleLoader::CreateEmptyProcess(lldb::pid_t pid, ParsedProcess parsed_process; parsed_process.target_sp = target_sp; - ProcessSP process_sp = target_sp->CreateProcess( - /*listener*/ nullptr, "trace", - /*crash_file*/ nullptr, - /*can_connect*/ false); + // This should instead try to directly create an instance of ProcessTrace. + // ProcessSP process_sp = target_sp->CreateProcess( + ///*listener*/ nullptr, "trace", + ///*crash_file*/ nullptr, + ///*can_connect*/ false); process_sp->SetID(static_cast(pid)); `` https://github.com/llvm/llvm-project/pull/71455 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] walter/fix (PR #71455)
https://github.com/walter-erquinigo updated https://github.com/llvm/llvm-project/pull/71455 >From d877ef80bbaa62afed2c7656c5ff6e84a8628786 Mon Sep 17 00:00:00 2001 From: walter erquinigo Date: Mon, 6 Nov 2023 17:57:45 -0500 Subject: [PATCH] [LLDB] Don't forcefully initialize the process trace plugin This was causing some process to wrongfully be handled by ProcessTrace. The only place this was being used is in the intel pt plugin, but it doesn't even build anymore, so I'm sure no one is using it. --- lldb/source/API/SystemInitializerFull.cpp| 3 --- .../Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp | 9 + 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lldb/source/API/SystemInitializerFull.cpp b/lldb/source/API/SystemInitializerFull.cpp index 27319debc858288..c48466f25ede81b 100644 --- a/lldb/source/API/SystemInitializerFull.cpp +++ b/lldb/source/API/SystemInitializerFull.cpp @@ -68,9 +68,6 @@ llvm::Error SystemInitializerFull::Initialize() { #define LLDB_PLUGIN(p) LLDB_PLUGIN_INITIALIZE(p); #include "Plugins/Plugins.def" - // Initialize plug-ins in core LLDB - ProcessTrace::Initialize(); - // Scan for any system or user LLDB plug-ins PluginManager::Initialize(); diff --git a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp index 6bed78fd83f0b70..bd9cca675f2d747 100644 --- a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp +++ b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp @@ -103,10 +103,11 @@ TraceIntelPTBundleLoader::CreateEmptyProcess(lldb::pid_t pid, ParsedProcess parsed_process; parsed_process.target_sp = target_sp; - ProcessSP process_sp = target_sp->CreateProcess( - /*listener*/ nullptr, "trace", - /*crash_file*/ nullptr, - /*can_connect*/ false); + // This should instead try to directly create an instance of ProcessTrace. + // ProcessSP process_sp = target_sp->CreateProcess( + ///*listener*/ nullptr, "trace", + ///*crash_file*/ nullptr, + ///*can_connect*/ false); process_sp->SetID(static_cast(pid)); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Don't forcefully initialize the process trace plugin (PR #71455)
https://github.com/walter-erquinigo edited https://github.com/llvm/llvm-project/pull/71455 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Don't forcefully initialize the process trace plugin (PR #71455)
https://github.com/walter-erquinigo edited https://github.com/llvm/llvm-project/pull/71455 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Don't forcefully initialize the process trace plugin (PR #71455)
https://github.com/walter-erquinigo edited https://github.com/llvm/llvm-project/pull/71455 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add Checksum class to lldbUtility (PR #71456)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/71456 This commit adds an MD5 checksum (`Checksum`) class to LLDB. Its purpose is to store the MD5 hash added to the DWARF 5 line table. >From 5ba3f9d6cd795bc091bacae75b7c51d815138d5b Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 6 Nov 2023 14:39:26 -0800 Subject: [PATCH] [lldb] Add Checksum class to lldbUtility This commit adds an MD5 checksum (`Checksum`) class to LLDB. Its purpose is to store the MD5 hash added to the DWARF 5 line table. --- lldb/include/lldb/Utility/Checksum.h| 36 lldb/source/Utility/CMakeLists.txt | 1 + lldb/source/Utility/Checksum.cpp| 46 lldb/unittests/Utility/CMakeLists.txt | 1 + lldb/unittests/Utility/ChecksumTest.cpp | 57 + 5 files changed, 141 insertions(+) create mode 100644 lldb/include/lldb/Utility/Checksum.h create mode 100644 lldb/source/Utility/Checksum.cpp create mode 100644 lldb/unittests/Utility/ChecksumTest.cpp diff --git a/lldb/include/lldb/Utility/Checksum.h b/lldb/include/lldb/Utility/Checksum.h new file mode 100644 index 000..90a579b247636ac --- /dev/null +++ b/lldb/include/lldb/Utility/Checksum.h @@ -0,0 +1,36 @@ +//===-- Checksum.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLDB_UTILITY_CHECKSUM_H +#define LLDB_UTILITY_CHECKSUM_H + +#include "llvm/Support/MD5.h" + +namespace lldb_private { +class Checksum { +public: + static llvm::MD5::MD5Result sentinel; + + Checksum(llvm::MD5::MD5Result md5 = sentinel); + Checksum(const Checksum &checksum); + Checksum &operator=(const Checksum &checksum); + + explicit operator bool() const; + bool operator==(const Checksum &checksum) const; + bool operator!=(const Checksum &checksum) const; + + std::string digest() const; + +private: + void SetMD5(llvm::MD5::MD5Result); + + llvm::MD5::MD5Result m_checksum; +}; +} // namespace lldb_private + +#endif // LLDB_UTILITY_CHECKSUM_H diff --git a/lldb/source/Utility/CMakeLists.txt b/lldb/source/Utility/CMakeLists.txt index 16afab1113a970c..a3b0a405b4133f6 100644 --- a/lldb/source/Utility/CMakeLists.txt +++ b/lldb/source/Utility/CMakeLists.txt @@ -29,6 +29,7 @@ add_lldb_library(lldbUtility NO_INTERNAL_DEPENDENCIES Args.cpp Baton.cpp Broadcaster.cpp + Checksum.cpp CompletionRequest.cpp Connection.cpp ConstString.cpp diff --git a/lldb/source/Utility/Checksum.cpp b/lldb/source/Utility/Checksum.cpp new file mode 100644 index 000..70167e497a526c4 --- /dev/null +++ b/lldb/source/Utility/Checksum.cpp @@ -0,0 +1,46 @@ +//===-- Checksum.cpp --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "lldb/Utility/Checksum.h" +#include "llvm/ADT/SmallString.h" + +using namespace lldb_private; + +Checksum::Checksum(llvm::MD5::MD5Result md5) { SetMD5(md5); } + +Checksum::Checksum(const Checksum &checksum) { SetMD5(checksum.m_checksum); } + +Checksum &Checksum::operator=(const Checksum &checksum) { + SetMD5(checksum.m_checksum); + return *this; +} + +void Checksum::SetMD5(llvm::MD5::MD5Result md5) { + std::uninitialized_copy_n(md5.begin(), 16, m_checksum.begin()); +} + +Checksum::operator bool() const { + return !std::equal(m_checksum.begin(), m_checksum.end(), sentinel.begin()); +} + +bool Checksum::operator==(const Checksum &checksum) const { + return std::equal(m_checksum.begin(), m_checksum.end(), +checksum.m_checksum.begin()); +} + +bool Checksum::operator!=(const Checksum &checksum) const { + return !std::equal(m_checksum.begin(), m_checksum.end(), + checksum.m_checksum.begin()); +} + +std::string Checksum::digest() const { + return std::string(m_checksum.digest().str()); +} + +llvm::MD5::MD5Result Checksum::sentinel = {0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0}; diff --git a/lldb/unittests/Utility/CMakeLists.txt b/lldb/unittests/Utility/CMakeLists.txt index 5c7003a156813dc..097dae860b15911 100644 --- a/lldb/unittests/Utility/CMakeLists.txt +++ b/lldb/unittests/Utility/CMakeLists.txt @@ -4,6 +4,7 @@ add_lldb_unittest(UtilityTests OptionsWithRawTest.cpp ArchSpecTest.cpp BroadcasterTest.cpp + ChecksumTest.cpp ConstStringTest.cpp CompletionRequestTest.cpp DataBufferTest.cpp diff --git a/lldb/unittests/Utility/Checks
[Lldb-commits] [lldb] [lldb] Add Checksum class to lldbUtility (PR #71456)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes This commit adds an MD5 checksum (`Checksum`) class to LLDB. Its purpose is to store the MD5 hash added to the DWARF 5 line table. --- Full diff: https://github.com/llvm/llvm-project/pull/71456.diff 5 Files Affected: - (added) lldb/include/lldb/Utility/Checksum.h (+36) - (modified) lldb/source/Utility/CMakeLists.txt (+1) - (added) lldb/source/Utility/Checksum.cpp (+46) - (modified) lldb/unittests/Utility/CMakeLists.txt (+1) - (added) lldb/unittests/Utility/ChecksumTest.cpp (+57) ``diff diff --git a/lldb/include/lldb/Utility/Checksum.h b/lldb/include/lldb/Utility/Checksum.h new file mode 100644 index 000..90a579b247636ac --- /dev/null +++ b/lldb/include/lldb/Utility/Checksum.h @@ -0,0 +1,36 @@ +//===-- Checksum.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLDB_UTILITY_CHECKSUM_H +#define LLDB_UTILITY_CHECKSUM_H + +#include "llvm/Support/MD5.h" + +namespace lldb_private { +class Checksum { +public: + static llvm::MD5::MD5Result sentinel; + + Checksum(llvm::MD5::MD5Result md5 = sentinel); + Checksum(const Checksum &checksum); + Checksum &operator=(const Checksum &checksum); + + explicit operator bool() const; + bool operator==(const Checksum &checksum) const; + bool operator!=(const Checksum &checksum) const; + + std::string digest() const; + +private: + void SetMD5(llvm::MD5::MD5Result); + + llvm::MD5::MD5Result m_checksum; +}; +} // namespace lldb_private + +#endif // LLDB_UTILITY_CHECKSUM_H diff --git a/lldb/source/Utility/CMakeLists.txt b/lldb/source/Utility/CMakeLists.txt index 16afab1113a970c..a3b0a405b4133f6 100644 --- a/lldb/source/Utility/CMakeLists.txt +++ b/lldb/source/Utility/CMakeLists.txt @@ -29,6 +29,7 @@ add_lldb_library(lldbUtility NO_INTERNAL_DEPENDENCIES Args.cpp Baton.cpp Broadcaster.cpp + Checksum.cpp CompletionRequest.cpp Connection.cpp ConstString.cpp diff --git a/lldb/source/Utility/Checksum.cpp b/lldb/source/Utility/Checksum.cpp new file mode 100644 index 000..70167e497a526c4 --- /dev/null +++ b/lldb/source/Utility/Checksum.cpp @@ -0,0 +1,46 @@ +//===-- Checksum.cpp --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "lldb/Utility/Checksum.h" +#include "llvm/ADT/SmallString.h" + +using namespace lldb_private; + +Checksum::Checksum(llvm::MD5::MD5Result md5) { SetMD5(md5); } + +Checksum::Checksum(const Checksum &checksum) { SetMD5(checksum.m_checksum); } + +Checksum &Checksum::operator=(const Checksum &checksum) { + SetMD5(checksum.m_checksum); + return *this; +} + +void Checksum::SetMD5(llvm::MD5::MD5Result md5) { + std::uninitialized_copy_n(md5.begin(), 16, m_checksum.begin()); +} + +Checksum::operator bool() const { + return !std::equal(m_checksum.begin(), m_checksum.end(), sentinel.begin()); +} + +bool Checksum::operator==(const Checksum &checksum) const { + return std::equal(m_checksum.begin(), m_checksum.end(), +checksum.m_checksum.begin()); +} + +bool Checksum::operator!=(const Checksum &checksum) const { + return !std::equal(m_checksum.begin(), m_checksum.end(), + checksum.m_checksum.begin()); +} + +std::string Checksum::digest() const { + return std::string(m_checksum.digest().str()); +} + +llvm::MD5::MD5Result Checksum::sentinel = {0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0}; diff --git a/lldb/unittests/Utility/CMakeLists.txt b/lldb/unittests/Utility/CMakeLists.txt index 5c7003a156813dc..097dae860b15911 100644 --- a/lldb/unittests/Utility/CMakeLists.txt +++ b/lldb/unittests/Utility/CMakeLists.txt @@ -4,6 +4,7 @@ add_lldb_unittest(UtilityTests OptionsWithRawTest.cpp ArchSpecTest.cpp BroadcasterTest.cpp + ChecksumTest.cpp ConstStringTest.cpp CompletionRequestTest.cpp DataBufferTest.cpp diff --git a/lldb/unittests/Utility/ChecksumTest.cpp b/lldb/unittests/Utility/ChecksumTest.cpp new file mode 100644 index 000..7537d30b5ff5b84 --- /dev/null +++ b/lldb/unittests/Utility/ChecksumTest.cpp @@ -0,0 +1,57 @@ +//===-- ChecksumTest.cpp --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identif
[Lldb-commits] [lldb] [lldb] Add Checksum to FileSpec (PR #71457)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/71457 Store a Checksum in FileSpec. Its purpose is to store the MD5 hash added to the DWARF 5 line table. >From 5ba3f9d6cd795bc091bacae75b7c51d815138d5b Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 6 Nov 2023 14:39:26 -0800 Subject: [PATCH 1/2] [lldb] Add Checksum class to lldbUtility This commit adds an MD5 checksum (`Checksum`) class to LLDB. Its purpose is to store the MD5 hash added to the DWARF 5 line table. --- lldb/include/lldb/Utility/Checksum.h| 36 lldb/source/Utility/CMakeLists.txt | 1 + lldb/source/Utility/Checksum.cpp| 46 lldb/unittests/Utility/CMakeLists.txt | 1 + lldb/unittests/Utility/ChecksumTest.cpp | 57 + 5 files changed, 141 insertions(+) create mode 100644 lldb/include/lldb/Utility/Checksum.h create mode 100644 lldb/source/Utility/Checksum.cpp create mode 100644 lldb/unittests/Utility/ChecksumTest.cpp diff --git a/lldb/include/lldb/Utility/Checksum.h b/lldb/include/lldb/Utility/Checksum.h new file mode 100644 index 000..90a579b247636ac --- /dev/null +++ b/lldb/include/lldb/Utility/Checksum.h @@ -0,0 +1,36 @@ +//===-- Checksum.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLDB_UTILITY_CHECKSUM_H +#define LLDB_UTILITY_CHECKSUM_H + +#include "llvm/Support/MD5.h" + +namespace lldb_private { +class Checksum { +public: + static llvm::MD5::MD5Result sentinel; + + Checksum(llvm::MD5::MD5Result md5 = sentinel); + Checksum(const Checksum &checksum); + Checksum &operator=(const Checksum &checksum); + + explicit operator bool() const; + bool operator==(const Checksum &checksum) const; + bool operator!=(const Checksum &checksum) const; + + std::string digest() const; + +private: + void SetMD5(llvm::MD5::MD5Result); + + llvm::MD5::MD5Result m_checksum; +}; +} // namespace lldb_private + +#endif // LLDB_UTILITY_CHECKSUM_H diff --git a/lldb/source/Utility/CMakeLists.txt b/lldb/source/Utility/CMakeLists.txt index 16afab1113a970c..a3b0a405b4133f6 100644 --- a/lldb/source/Utility/CMakeLists.txt +++ b/lldb/source/Utility/CMakeLists.txt @@ -29,6 +29,7 @@ add_lldb_library(lldbUtility NO_INTERNAL_DEPENDENCIES Args.cpp Baton.cpp Broadcaster.cpp + Checksum.cpp CompletionRequest.cpp Connection.cpp ConstString.cpp diff --git a/lldb/source/Utility/Checksum.cpp b/lldb/source/Utility/Checksum.cpp new file mode 100644 index 000..70167e497a526c4 --- /dev/null +++ b/lldb/source/Utility/Checksum.cpp @@ -0,0 +1,46 @@ +//===-- Checksum.cpp --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "lldb/Utility/Checksum.h" +#include "llvm/ADT/SmallString.h" + +using namespace lldb_private; + +Checksum::Checksum(llvm::MD5::MD5Result md5) { SetMD5(md5); } + +Checksum::Checksum(const Checksum &checksum) { SetMD5(checksum.m_checksum); } + +Checksum &Checksum::operator=(const Checksum &checksum) { + SetMD5(checksum.m_checksum); + return *this; +} + +void Checksum::SetMD5(llvm::MD5::MD5Result md5) { + std::uninitialized_copy_n(md5.begin(), 16, m_checksum.begin()); +} + +Checksum::operator bool() const { + return !std::equal(m_checksum.begin(), m_checksum.end(), sentinel.begin()); +} + +bool Checksum::operator==(const Checksum &checksum) const { + return std::equal(m_checksum.begin(), m_checksum.end(), +checksum.m_checksum.begin()); +} + +bool Checksum::operator!=(const Checksum &checksum) const { + return !std::equal(m_checksum.begin(), m_checksum.end(), + checksum.m_checksum.begin()); +} + +std::string Checksum::digest() const { + return std::string(m_checksum.digest().str()); +} + +llvm::MD5::MD5Result Checksum::sentinel = {0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0}; diff --git a/lldb/unittests/Utility/CMakeLists.txt b/lldb/unittests/Utility/CMakeLists.txt index 5c7003a156813dc..097dae860b15911 100644 --- a/lldb/unittests/Utility/CMakeLists.txt +++ b/lldb/unittests/Utility/CMakeLists.txt @@ -4,6 +4,7 @@ add_lldb_unittest(UtilityTests OptionsWithRawTest.cpp ArchSpecTest.cpp BroadcasterTest.cpp + ChecksumTest.cpp ConstStringTest.cpp CompletionRequestTest.cpp DataBufferTest.cpp diff --git a/lldb/unittests/Utility/ChecksumTest.cpp b/lldb/unittests
[Lldb-commits] [lldb] [lldb] Add Checksum to FileSpec (PR #71457)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes Store a Checksum in FileSpec. Its purpose is to store the MD5 hash added to the DWARF 5 line table. --- Full diff: https://github.com/llvm/llvm-project/pull/71457.diff 8 Files Affected: - (added) lldb/include/lldb/Utility/Checksum.h (+36) - (modified) lldb/include/lldb/Utility/FileSpec.h (+17-2) - (modified) lldb/source/Utility/CMakeLists.txt (+1) - (added) lldb/source/Utility/Checksum.cpp (+46) - (modified) lldb/source/Utility/FileSpec.cpp (+6-3) - (modified) lldb/unittests/Utility/CMakeLists.txt (+1) - (added) lldb/unittests/Utility/ChecksumTest.cpp (+57) - (modified) lldb/unittests/Utility/FileSpecTest.cpp (+21-37) ``diff diff --git a/lldb/include/lldb/Utility/Checksum.h b/lldb/include/lldb/Utility/Checksum.h new file mode 100644 index 000..90a579b247636ac --- /dev/null +++ b/lldb/include/lldb/Utility/Checksum.h @@ -0,0 +1,36 @@ +//===-- Checksum.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLDB_UTILITY_CHECKSUM_H +#define LLDB_UTILITY_CHECKSUM_H + +#include "llvm/Support/MD5.h" + +namespace lldb_private { +class Checksum { +public: + static llvm::MD5::MD5Result sentinel; + + Checksum(llvm::MD5::MD5Result md5 = sentinel); + Checksum(const Checksum &checksum); + Checksum &operator=(const Checksum &checksum); + + explicit operator bool() const; + bool operator==(const Checksum &checksum) const; + bool operator!=(const Checksum &checksum) const; + + std::string digest() const; + +private: + void SetMD5(llvm::MD5::MD5Result); + + llvm::MD5::MD5Result m_checksum; +}; +} // namespace lldb_private + +#endif // LLDB_UTILITY_CHECKSUM_H diff --git a/lldb/include/lldb/Utility/FileSpec.h b/lldb/include/lldb/Utility/FileSpec.h index f06a8543a056e87..29506b01c56d40b 100644 --- a/lldb/include/lldb/Utility/FileSpec.h +++ b/lldb/include/lldb/Utility/FileSpec.h @@ -13,15 +13,18 @@ #include #include +#include "lldb/Utility/Checksum.h" #include "lldb/Utility/ConstString.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FormatVariadic.h" +#include "llvm/Support/MD5.h" #include "llvm/Support/Path.h" #include #include +#include namespace lldb_private { class Stream; @@ -72,7 +75,8 @@ class FileSpec { /// The style of the path /// /// \see FileSpec::SetFile (const char *path) - explicit FileSpec(llvm::StringRef path, Style style = Style::native); + explicit FileSpec(llvm::StringRef path, Style style = Style::native, +const Checksum &checksum = {}); explicit FileSpec(llvm::StringRef path, const llvm::Triple &triple); @@ -362,7 +366,11 @@ class FileSpec { /// /// \param[in] style /// The style for the given path. - void SetFile(llvm::StringRef path, Style style); + /// + /// \param[in] checksum + /// The checksum for the given path. + void SetFile(llvm::StringRef path, Style style, + const Checksum &checksum = {}); /// Change the file specified with a new path. /// @@ -420,6 +428,9 @@ class FileSpec { /// The lifetime of the StringRefs is tied to the lifetime of the FileSpec. std::vector GetComponents() const; + /// Return the checksum for this FileSpec or all zeros if there is none. + const Checksum &GetChecksum() const { return m_checksum; }; + protected: // Convenience method for setting the file without changing the style. void SetFile(llvm::StringRef path); @@ -427,6 +438,7 @@ class FileSpec { /// Called anytime m_directory or m_filename is changed to clear any cached /// state in this object. void PathWasModified() { +m_checksum = Checksum(); m_is_resolved = false; m_absolute = Absolute::Calculate; } @@ -443,6 +455,9 @@ class FileSpec { /// The unique'd filename path. ConstString m_filename; + /// The optional MD5 checksum of the file. + Checksum m_checksum; + /// True if this path has been resolved. mutable bool m_is_resolved = false; diff --git a/lldb/source/Utility/CMakeLists.txt b/lldb/source/Utility/CMakeLists.txt index 16afab1113a970c..a3b0a405b4133f6 100644 --- a/lldb/source/Utility/CMakeLists.txt +++ b/lldb/source/Utility/CMakeLists.txt @@ -29,6 +29,7 @@ add_lldb_library(lldbUtility NO_INTERNAL_DEPENDENCIES Args.cpp Baton.cpp Broadcaster.cpp + Checksum.cpp CompletionRequest.cpp Connection.cpp ConstString.cpp diff --git a/lldb/source/Utility/Checksum.cpp b/lldb/source/Utility/Checksum.cpp new file mode 100644 index 000..70167e497a526c4 --- /dev/null +++ b/lldb/source/Utility/Checksum.cpp @@ -0,0 +1,46 @@ +//=
[Lldb-commits] [lldb] [lldb] Add Checksum to FileSpec (PR #71457)
JDevlieghere wrote: Depends on #71456. I considered an alternative where we don't store the `Checksum` in the `FileSpec` but create a new `SupportFile` class that wraps a `Checksum` and a `FileSpec`. The reason I didn't got with this approach is because of the `FileSpecList`. The latter has helper functions that are used in the context of "support files" which would have to duplicated in a `SupportFileList` and I wasn't sure we weren't vending a `FileSpecList` through the SB API that would now become a `SupportFileList`. A checksum is 16 bytes. Please let me know if you think that the overhead of that is too much and outweighs the churn and code duplication to adopt a `SupportFile` and `SupportFileList`. https://github.com/llvm/llvm-project/pull/71457 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Read Checksum from DWARF line tables (PR #71458)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/71458 Read the MD5 checksum from DWARF line tables and store it in the corresponding support files. >From 5ba3f9d6cd795bc091bacae75b7c51d815138d5b Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 6 Nov 2023 14:39:26 -0800 Subject: [PATCH 1/3] [lldb] Add Checksum class to lldbUtility This commit adds an MD5 checksum (`Checksum`) class to LLDB. Its purpose is to store the MD5 hash added to the DWARF 5 line table. --- lldb/include/lldb/Utility/Checksum.h| 36 lldb/source/Utility/CMakeLists.txt | 1 + lldb/source/Utility/Checksum.cpp| 46 lldb/unittests/Utility/CMakeLists.txt | 1 + lldb/unittests/Utility/ChecksumTest.cpp | 57 + 5 files changed, 141 insertions(+) create mode 100644 lldb/include/lldb/Utility/Checksum.h create mode 100644 lldb/source/Utility/Checksum.cpp create mode 100644 lldb/unittests/Utility/ChecksumTest.cpp diff --git a/lldb/include/lldb/Utility/Checksum.h b/lldb/include/lldb/Utility/Checksum.h new file mode 100644 index 000..90a579b247636ac --- /dev/null +++ b/lldb/include/lldb/Utility/Checksum.h @@ -0,0 +1,36 @@ +//===-- Checksum.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLDB_UTILITY_CHECKSUM_H +#define LLDB_UTILITY_CHECKSUM_H + +#include "llvm/Support/MD5.h" + +namespace lldb_private { +class Checksum { +public: + static llvm::MD5::MD5Result sentinel; + + Checksum(llvm::MD5::MD5Result md5 = sentinel); + Checksum(const Checksum &checksum); + Checksum &operator=(const Checksum &checksum); + + explicit operator bool() const; + bool operator==(const Checksum &checksum) const; + bool operator!=(const Checksum &checksum) const; + + std::string digest() const; + +private: + void SetMD5(llvm::MD5::MD5Result); + + llvm::MD5::MD5Result m_checksum; +}; +} // namespace lldb_private + +#endif // LLDB_UTILITY_CHECKSUM_H diff --git a/lldb/source/Utility/CMakeLists.txt b/lldb/source/Utility/CMakeLists.txt index 16afab1113a970c..a3b0a405b4133f6 100644 --- a/lldb/source/Utility/CMakeLists.txt +++ b/lldb/source/Utility/CMakeLists.txt @@ -29,6 +29,7 @@ add_lldb_library(lldbUtility NO_INTERNAL_DEPENDENCIES Args.cpp Baton.cpp Broadcaster.cpp + Checksum.cpp CompletionRequest.cpp Connection.cpp ConstString.cpp diff --git a/lldb/source/Utility/Checksum.cpp b/lldb/source/Utility/Checksum.cpp new file mode 100644 index 000..70167e497a526c4 --- /dev/null +++ b/lldb/source/Utility/Checksum.cpp @@ -0,0 +1,46 @@ +//===-- Checksum.cpp --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "lldb/Utility/Checksum.h" +#include "llvm/ADT/SmallString.h" + +using namespace lldb_private; + +Checksum::Checksum(llvm::MD5::MD5Result md5) { SetMD5(md5); } + +Checksum::Checksum(const Checksum &checksum) { SetMD5(checksum.m_checksum); } + +Checksum &Checksum::operator=(const Checksum &checksum) { + SetMD5(checksum.m_checksum); + return *this; +} + +void Checksum::SetMD5(llvm::MD5::MD5Result md5) { + std::uninitialized_copy_n(md5.begin(), 16, m_checksum.begin()); +} + +Checksum::operator bool() const { + return !std::equal(m_checksum.begin(), m_checksum.end(), sentinel.begin()); +} + +bool Checksum::operator==(const Checksum &checksum) const { + return std::equal(m_checksum.begin(), m_checksum.end(), +checksum.m_checksum.begin()); +} + +bool Checksum::operator!=(const Checksum &checksum) const { + return !std::equal(m_checksum.begin(), m_checksum.end(), + checksum.m_checksum.begin()); +} + +std::string Checksum::digest() const { + return std::string(m_checksum.digest().str()); +} + +llvm::MD5::MD5Result Checksum::sentinel = {0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0}; diff --git a/lldb/unittests/Utility/CMakeLists.txt b/lldb/unittests/Utility/CMakeLists.txt index 5c7003a156813dc..097dae860b15911 100644 --- a/lldb/unittests/Utility/CMakeLists.txt +++ b/lldb/unittests/Utility/CMakeLists.txt @@ -4,6 +4,7 @@ add_lldb_unittest(UtilityTests OptionsWithRawTest.cpp ArchSpecTest.cpp BroadcasterTest.cpp + ChecksumTest.cpp ConstStringTest.cpp CompletionRequestTest.cpp DataBufferTest.cpp diff --git a/lldb/unittests/Utility/ChecksumTest.cpp b/lldb/unittests/Utili
[Lldb-commits] [lldb] [lldb] Read Checksum from DWARF line tables (PR #71458)
JDevlieghere wrote: Depends on #71457. https://github.com/llvm/llvm-project/pull/71458 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Read Checksum from DWARF line tables (PR #71458)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes Read the MD5 checksum from DWARF line tables and store it in the corresponding support files. --- Full diff: https://github.com/llvm/llvm-project/pull/71458.diff 9 Files Affected: - (added) lldb/include/lldb/Utility/Checksum.h (+36) - (modified) lldb/include/lldb/Utility/FileSpec.h (+17-2) - (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (+8-1) - (modified) lldb/source/Utility/CMakeLists.txt (+1) - (added) lldb/source/Utility/Checksum.cpp (+46) - (modified) lldb/source/Utility/FileSpec.cpp (+6-3) - (modified) lldb/unittests/Utility/CMakeLists.txt (+1) - (added) lldb/unittests/Utility/ChecksumTest.cpp (+57) - (modified) lldb/unittests/Utility/FileSpecTest.cpp (+21-37) ``diff diff --git a/lldb/include/lldb/Utility/Checksum.h b/lldb/include/lldb/Utility/Checksum.h new file mode 100644 index 000..90a579b247636ac --- /dev/null +++ b/lldb/include/lldb/Utility/Checksum.h @@ -0,0 +1,36 @@ +//===-- Checksum.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLDB_UTILITY_CHECKSUM_H +#define LLDB_UTILITY_CHECKSUM_H + +#include "llvm/Support/MD5.h" + +namespace lldb_private { +class Checksum { +public: + static llvm::MD5::MD5Result sentinel; + + Checksum(llvm::MD5::MD5Result md5 = sentinel); + Checksum(const Checksum &checksum); + Checksum &operator=(const Checksum &checksum); + + explicit operator bool() const; + bool operator==(const Checksum &checksum) const; + bool operator!=(const Checksum &checksum) const; + + std::string digest() const; + +private: + void SetMD5(llvm::MD5::MD5Result); + + llvm::MD5::MD5Result m_checksum; +}; +} // namespace lldb_private + +#endif // LLDB_UTILITY_CHECKSUM_H diff --git a/lldb/include/lldb/Utility/FileSpec.h b/lldb/include/lldb/Utility/FileSpec.h index f06a8543a056e87..29506b01c56d40b 100644 --- a/lldb/include/lldb/Utility/FileSpec.h +++ b/lldb/include/lldb/Utility/FileSpec.h @@ -13,15 +13,18 @@ #include #include +#include "lldb/Utility/Checksum.h" #include "lldb/Utility/ConstString.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FormatVariadic.h" +#include "llvm/Support/MD5.h" #include "llvm/Support/Path.h" #include #include +#include namespace lldb_private { class Stream; @@ -72,7 +75,8 @@ class FileSpec { /// The style of the path /// /// \see FileSpec::SetFile (const char *path) - explicit FileSpec(llvm::StringRef path, Style style = Style::native); + explicit FileSpec(llvm::StringRef path, Style style = Style::native, +const Checksum &checksum = {}); explicit FileSpec(llvm::StringRef path, const llvm::Triple &triple); @@ -362,7 +366,11 @@ class FileSpec { /// /// \param[in] style /// The style for the given path. - void SetFile(llvm::StringRef path, Style style); + /// + /// \param[in] checksum + /// The checksum for the given path. + void SetFile(llvm::StringRef path, Style style, + const Checksum &checksum = {}); /// Change the file specified with a new path. /// @@ -420,6 +428,9 @@ class FileSpec { /// The lifetime of the StringRefs is tied to the lifetime of the FileSpec. std::vector GetComponents() const; + /// Return the checksum for this FileSpec or all zeros if there is none. + const Checksum &GetChecksum() const { return m_checksum; }; + protected: // Convenience method for setting the file without changing the style. void SetFile(llvm::StringRef path); @@ -427,6 +438,7 @@ class FileSpec { /// Called anytime m_directory or m_filename is changed to clear any cached /// state in this object. void PathWasModified() { +m_checksum = Checksum(); m_is_resolved = false; m_absolute = Absolute::Calculate; } @@ -443,6 +455,9 @@ class FileSpec { /// The unique'd filename path. ConstString m_filename; + /// The optional MD5 checksum of the file. + Checksum m_checksum; + /// True if this path has been resolved. mutable bool m_is_resolved = false; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index aabd83a194932ff..79d44bce3d663b6 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -229,8 +229,15 @@ ParseSupportFilesFromPrologue(const lldb::ModuleSP &module, remapped_file = std::move(*file_path); } +Checksum checksum; +if (prologue.ContentTypes.HasMD5) { + const llvm::DWARFDebugLine::FileNameEnt