[Lldb-commits] [PATCH] D154730: [lldb] Consider TAG_imported_declaration in DebugNamesIndex

2023-07-07 Thread Michael Buch via Phabricator via lldb-commits
Michael137 accepted this revision.
Michael137 added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154730/new/

https://reviews.llvm.org/D154730

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156020: [lldb][PlatformDarwin] Parse SDK path for module compilation from debug-info

2023-07-22 Thread Michael Buch via Phabricator via lldb-commits
Michael137 created this revision.
Michael137 added a reviewer: aprantl.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

When we build the Clang module compilation command (e.g., when
a user requests import of a module via `expression @import Foundation`),
LLDB will try to determine which SDK directory to use as the `sysroot`.
However, it currently does so by simply enumerating the `SDKs` directory
and picking the last one that's appropriate for module compilation
(see `PlatformDarwin::GetSDKDirectoryForModules`). That means if we have
multiple platform SDKs installed (e.g., a public and internal one), we
may pick the wrong one by chance.

On Darwin platforms we emit the SDK path that a object
file was compiled against into DWARF (using `DW_AT_LLVM_sysroot`
and `DW_AT_APPLE_sdk`). For Swift debugging, we already parse the SDK
path from debug-info if we can.

This patch mimicks the Swift behaviour for non-Swift languages. I.e.,
if we can get the SDK path from debug-info, do so. Otherwise, fall back
to the old heuristic.

rdar://110407148


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156020

Files:
  lldb/include/lldb/Target/Platform.h
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Target/Platform.cpp
  lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -12,6 +12,7 @@
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/PluginManager.h"
+#include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -72,4 +73,174 @@
   ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
   ASSERT_EQ(module->GetSourceMappingList().GetSize(), 1u);
 }
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InternalAndPublicSDK) {
+  // Tests that we can parse the SDK path from debug-info.
+  // In the presence of multiple compile units, one of which
+  // points to an internal SDK, we should pick the internal SDK.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+- Attribute:   DW_AT_LLVM_sysroot
+  Form:DW_FORM_string
+- Code:0x0002
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+- Attribute:   DW_AT_LLVM_sysroot
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"MacOSX10.9.sdk"
+- CStr:"/Library/Developer/CommandLineTools/SDKs/MacOSX10.9.sdk"
+- AbbrCode:0x
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0002
+  Values:
+- Value:   0x0010
+- CStr:"iPhoneOS14.0.Internal.sdk"
+- CStr:"/Library/Developer/CommandLineTools/SDKs/iPhoneOS14.0.Internal.sdk"
+- AbbrCode:0x
+...
+)";
+
+  YAMLModuleTester t(yamldata);
+  DWARFUnit *dwarf_unit = t.GetDwarfUnit();
+  auto *dwarf_cu = llvm::cast(dwarf_unit);
+  ASSERT_TRUE(static_cast(dwarf_cu));
+  SymbolFileDWARF &sym_file = dwarf_cu->GetSymbolFileDWARF();
+  ASSERT_EQ(sym_file.GetNumCompileUnits(), 2U);
+  ModuleSP module = t.GetModule();
+  ASSERT_NE(module, nullptr);
+
+  auto path_or_err = Platform::GetSDKPathFromDebugInfo(*module);
+  ASSERT_TRUE(!!path_or_err);
+
+  auto [sdk_path, found_internal, found_public] = *path_or_err;
+
+  ASSERT_TRUE(found_internal);
+  ASSERT_TRUE(found_public);
+  ASSERT_NE(sdk_path.find("Internal.sdk"), std::string::npos);
+}
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InvalidSDKPath) {
+  // Tests that parsing a CU with an invalid SDK directory 

[Lldb-commits] [PATCH] D156020: [lldb][PlatformDarwin] Parse SDK path for module compilation from debug-info

2023-07-22 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added inline comments.
Herald added a subscriber: JDevlieghere.



Comment at: lldb/include/lldb/Target/Platform.h:492
+  static llvm::Expected
+  GetSDKPathFromDebugInfo(Module &module);
+

I'm open to suggestions on where to put this API. `Platform` seems a bit too 
generic. But the intention is to share it with the Swift plugin. I could put it 
into `PlatformDarwin`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156020/new/

https://reviews.llvm.org/D156020

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156020: [lldb][PlatformDarwin] Parse SDK path for module compilation from debug-info

2023-07-22 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 543160.
Michael137 added a comment.

- Remove redundant headers


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156020/new/

https://reviews.llvm.org/D156020

Files:
  lldb/include/lldb/Target/Platform.h
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Target/Platform.cpp
  lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -12,6 +12,7 @@
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/PluginManager.h"
+#include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -72,4 +73,174 @@
   ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
   ASSERT_EQ(module->GetSourceMappingList().GetSize(), 1u);
 }
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InternalAndPublicSDK) {
+  // Tests that we can parse the SDK path from debug-info.
+  // In the presence of multiple compile units, one of which
+  // points to an internal SDK, we should pick the internal SDK.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+- Attribute:   DW_AT_LLVM_sysroot
+  Form:DW_FORM_string
+- Code:0x0002
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+- Attribute:   DW_AT_LLVM_sysroot
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"MacOSX10.9.sdk"
+- CStr:"/Library/Developer/CommandLineTools/SDKs/MacOSX10.9.sdk"
+- AbbrCode:0x
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0002
+  Values:
+- Value:   0x0010
+- CStr:"iPhoneOS14.0.Internal.sdk"
+- CStr:"/Library/Developer/CommandLineTools/SDKs/iPhoneOS14.0.Internal.sdk"
+- AbbrCode:0x
+...
+)";
+
+  YAMLModuleTester t(yamldata);
+  DWARFUnit *dwarf_unit = t.GetDwarfUnit();
+  auto *dwarf_cu = llvm::cast(dwarf_unit);
+  ASSERT_TRUE(static_cast(dwarf_cu));
+  SymbolFileDWARF &sym_file = dwarf_cu->GetSymbolFileDWARF();
+  ASSERT_EQ(sym_file.GetNumCompileUnits(), 2U);
+  ModuleSP module = t.GetModule();
+  ASSERT_NE(module, nullptr);
+
+  auto path_or_err = Platform::GetSDKPathFromDebugInfo(*module);
+  ASSERT_TRUE(!!path_or_err);
+
+  auto [sdk_path, found_internal, found_public] = *path_or_err;
+
+  ASSERT_TRUE(found_internal);
+  ASSERT_TRUE(found_public);
+  ASSERT_NE(sdk_path.find("Internal.sdk"), std::string::npos);
+}
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InvalidSDKPath) {
+  // Tests that parsing a CU with an invalid SDK directory name fails.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"1abc@defgh2"
+- AbbrCode:0x
+...
+)";
+
+  YAMLModuleTester t(yamldata);
+  ModuleSP module = t.GetModule();
+  ASSERT_NE(module, nullptr);
+
+  auto p

[Lldb-commits] [PATCH] D156020: [lldb][PlatformDarwin] Parse SDK path for module compilation from debug-info

2023-07-22 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added inline comments.



Comment at: lldb/include/lldb/Target/Platform.h:492
+  static llvm::Expected
+  GetSDKPathFromDebugInfo(Module &module);
+

Michael137 wrote:
> I'm open to suggestions on where to put this API. `Platform` seems a bit too 
> generic. But the intention is to share it with the Swift plugin. I could put 
> it into `PlatformDarwin`.
See how I intend to use it from the Swift plugin [[ 
https://github.com/apple/llvm-project/pull/7094/files#diff-35515cd82b78e2f7bbeff1d175f83a9dbe48066615f29cd377bd9cbf4591cb70
 | here ]]


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156020/new/

https://reviews.llvm.org/D156020

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156020: [lldb][PlatformDarwin] Parse SDK path for module compilation from debug-info

2023-07-24 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added inline comments.



Comment at: lldb/include/lldb/Target/Platform.h:479
+/// to an internal SDK
+bool found_internal_sdk = false;
+

aprantl wrote:
> These flags really only make sense in the context of an XcodeSDK, so why not 
> just return an XcodeSDK or XcodeSDK::Info object here? Otherwise we'll 
> probably introduce subtle bugs due to a lossy translation between the flags.
Yup I think that'd be better. That'll also make it easier to use from the Swift 
plugin


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156020/new/

https://reviews.llvm.org/D156020

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156020: [lldb][PlatformDarwin] Parse SDK path for module compilation from debug-info

2023-07-25 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 543870.
Michael137 added a comment.

- Move into `PlatformDarwin`
- Return `XcodeSDK` from `GetSDKPathFromDebugInfo` so it's easier to re-use 
from Swift plugin
- Introduce `ResolveSDKPathFromDebugInfo` to be used from `PlatformDarwin`
- Adjust tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156020/new/

https://reviews.llvm.org/D156020

Files:
  lldb/include/lldb/Target/Platform.h
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
  lldb/source/Target/Platform.cpp
  lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -12,6 +12,7 @@
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/PluginManager.h"
+#include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -72,4 +73,169 @@
   ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
   ASSERT_EQ(module->GetSourceMappingList().GetSize(), 1u);
 }
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InternalAndPublicSDK) {
+  // Tests that we can parse the SDK path from debug-info.
+  // In the presence of multiple compile units, one of which
+  // points to an internal SDK, we should pick the internal SDK.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+- Attribute:   DW_AT_LLVM_sysroot
+  Form:DW_FORM_string
+- Code:0x0002
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+- Attribute:   DW_AT_LLVM_sysroot
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"MacOSX10.9.sdk"
+- CStr:"/Library/Developer/CommandLineTools/SDKs/MacOSX10.9.sdk"
+- AbbrCode:0x
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0002
+  Values:
+- Value:   0x0010
+- CStr:"iPhoneOS14.0.Internal.sdk"
+- CStr:"/Library/Developer/CommandLineTools/SDKs/iPhoneOS14.0.Internal.sdk"
+- AbbrCode:0x
+...
+)";
+
+  YAMLModuleTester t(yamldata);
+  DWARFUnit *dwarf_unit = t.GetDwarfUnit();
+  auto *dwarf_cu = llvm::cast(dwarf_unit);
+  ASSERT_TRUE(static_cast(dwarf_cu));
+  SymbolFileDWARF &sym_file = dwarf_cu->GetSymbolFileDWARF();
+  ASSERT_EQ(sym_file.GetNumCompileUnits(), 2U);
+  ModuleSP module = t.GetModule();
+  ASSERT_NE(module, nullptr);
+
+  auto sdk_or_err = PlatformDarwin::GetSDKPathFromDebugInfo(*module);
+  ASSERT_TRUE(static_cast(sdk_or_err));
+
+  ASSERT_TRUE(sdk_or_err->IsAppleInternalSDK());
+  ASSERT_NE(sdk_or_err->GetString().find("Internal.sdk"), std::string::npos);
+}
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InvalidSDKPath) {
+  // Tests that parsing a CU with an invalid SDK directory name fails.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+  

[Lldb-commits] [PATCH] D156020: [lldb][PlatformDarwin] Parse SDK path for module compilation from debug-info

2023-07-25 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 543874.
Michael137 added a comment.

- Remove redundant header


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156020/new/

https://reviews.llvm.org/D156020

Files:
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
  lldb/source/Target/Platform.cpp
  lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -12,6 +12,7 @@
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/PluginManager.h"
+#include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -72,4 +73,169 @@
   ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
   ASSERT_EQ(module->GetSourceMappingList().GetSize(), 1u);
 }
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InternalAndPublicSDK) {
+  // Tests that we can parse the SDK path from debug-info.
+  // In the presence of multiple compile units, one of which
+  // points to an internal SDK, we should pick the internal SDK.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+- Attribute:   DW_AT_LLVM_sysroot
+  Form:DW_FORM_string
+- Code:0x0002
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+- Attribute:   DW_AT_LLVM_sysroot
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"MacOSX10.9.sdk"
+- CStr:"/Library/Developer/CommandLineTools/SDKs/MacOSX10.9.sdk"
+- AbbrCode:0x
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0002
+  Values:
+- Value:   0x0010
+- CStr:"iPhoneOS14.0.Internal.sdk"
+- CStr:"/Library/Developer/CommandLineTools/SDKs/iPhoneOS14.0.Internal.sdk"
+- AbbrCode:0x
+...
+)";
+
+  YAMLModuleTester t(yamldata);
+  DWARFUnit *dwarf_unit = t.GetDwarfUnit();
+  auto *dwarf_cu = llvm::cast(dwarf_unit);
+  ASSERT_TRUE(static_cast(dwarf_cu));
+  SymbolFileDWARF &sym_file = dwarf_cu->GetSymbolFileDWARF();
+  ASSERT_EQ(sym_file.GetNumCompileUnits(), 2U);
+  ModuleSP module = t.GetModule();
+  ASSERT_NE(module, nullptr);
+
+  auto sdk_or_err = PlatformDarwin::GetSDKPathFromDebugInfo(*module);
+  ASSERT_TRUE(static_cast(sdk_or_err));
+
+  ASSERT_TRUE(sdk_or_err->IsAppleInternalSDK());
+  ASSERT_NE(sdk_or_err->GetString().find("Internal.sdk"), std::string::npos);
+}
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InvalidSDKPath) {
+  // Tests that parsing a CU with an invalid SDK directory name fails.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"1abc@defgh2"
+- AbbrCode:0x
+...
+)";
+
+  YAMLModuleTester t(yamldata);
+  ModuleSP module = t.GetModule();
+  ASSERT_NE(module, nullptr);
+
+  auto path_or_err = PlatformDarwin::Reso

[Lldb-commits] [PATCH] D156020: [lldb][PlatformDarwin] Parse SDK path for module compilation from debug-info

2023-07-25 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 543875.
Michael137 added a comment.

- Remove more headers


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156020/new/

https://reviews.llvm.org/D156020

Files:
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
  lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -12,6 +12,7 @@
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/PluginManager.h"
+#include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -72,4 +73,169 @@
   ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
   ASSERT_EQ(module->GetSourceMappingList().GetSize(), 1u);
 }
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InternalAndPublicSDK) {
+  // Tests that we can parse the SDK path from debug-info.
+  // In the presence of multiple compile units, one of which
+  // points to an internal SDK, we should pick the internal SDK.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+- Attribute:   DW_AT_LLVM_sysroot
+  Form:DW_FORM_string
+- Code:0x0002
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+- Attribute:   DW_AT_LLVM_sysroot
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"MacOSX10.9.sdk"
+- CStr:"/Library/Developer/CommandLineTools/SDKs/MacOSX10.9.sdk"
+- AbbrCode:0x
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0002
+  Values:
+- Value:   0x0010
+- CStr:"iPhoneOS14.0.Internal.sdk"
+- CStr:"/Library/Developer/CommandLineTools/SDKs/iPhoneOS14.0.Internal.sdk"
+- AbbrCode:0x
+...
+)";
+
+  YAMLModuleTester t(yamldata);
+  DWARFUnit *dwarf_unit = t.GetDwarfUnit();
+  auto *dwarf_cu = llvm::cast(dwarf_unit);
+  ASSERT_TRUE(static_cast(dwarf_cu));
+  SymbolFileDWARF &sym_file = dwarf_cu->GetSymbolFileDWARF();
+  ASSERT_EQ(sym_file.GetNumCompileUnits(), 2U);
+  ModuleSP module = t.GetModule();
+  ASSERT_NE(module, nullptr);
+
+  auto sdk_or_err = PlatformDarwin::GetSDKPathFromDebugInfo(*module);
+  ASSERT_TRUE(static_cast(sdk_or_err));
+
+  ASSERT_TRUE(sdk_or_err->IsAppleInternalSDK());
+  ASSERT_NE(sdk_or_err->GetString().find("Internal.sdk"), std::string::npos);
+}
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InvalidSDKPath) {
+  // Tests that parsing a CU with an invalid SDK directory name fails.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"1abc@defgh2"
+- AbbrCode:0x
+...
+)";
+
+  YAMLModuleTester t(yamldata);
+  ModuleSP module = t.GetModule();
+  ASSERT_NE(module, nullptr);
+
+  auto path_or_err = PlatformDarwin::ResolveSDKPathFromDebugInfo(*module);
+  A

[Lldb-commits] [PATCH] D156020: [lldb][PlatformDarwin] Parse SDK path for module compilation from debug-info

2023-07-25 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added inline comments.



Comment at: lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp:1363
+  XcodeSDK sdk;
+  for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i)
+if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i))

Only remaining question is whether we want to limit this to just Objective-C 
and Swift. Going through each compile unit for C++ seems like a lot of work for 
something that we won't use

@aprantl 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156020/new/

https://reviews.llvm.org/D156020

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156020: [lldb][PlatformDarwin] Parse SDK path for module compilation from debug-info

2023-07-25 Thread Michael Buch via Phabricator via lldb-commits
Michael137 marked 2 inline comments as not done.
Michael137 added inline comments.



Comment at: lldb/include/lldb/Target/Platform.h:479
+/// to an internal SDK
+bool found_internal_sdk = false;
+

Michael137 wrote:
> aprantl wrote:
> > These flags really only make sense in the context of an XcodeSDK, so why 
> > not just return an XcodeSDK or XcodeSDK::Info object here? Otherwise we'll 
> > probably introduce subtle bugs due to a lossy translation between the flags.
> Yup I think that'd be better. That'll also make it easier to use from the 
> Swift plugin
Actually on second look, the `XcodeSDK` and `XcodeSDK::Info` objects represent 
information about a single (possibly parsed) SDK path. Whereas what the 
intention here was is to let the caller know whether we encountered a 
public/internal SDK while scanning all the CUs. Since we only return a single 
`XcodeSDK` (not all the ones we looked at) in my opinion it isn't quite right 
to store that information in it.

This is all really only used to [[ 
https://github.com/apple/llvm-project/blob/6c39bfc9d521dd8af03ca5e9e6ec7d5d4a6e5e6e/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp#L1700-L1704
 | print a Swift health ]]. Maybe we could instead just log this to 
`LLDBLog::Types`? Then we don't need to worry about returning any of this 
information. @aprantl 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156020/new/

https://reviews.llvm.org/D156020

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156020: [lldb][PlatformDarwin] Parse SDK path for module compilation from debug-info

2023-07-25 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 543967.
Michael137 marked an inline comment as not done.
Michael137 added a comment.

- Update unit-tests
- Expand function docs


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156020/new/

https://reviews.llvm.org/D156020

Files:
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
  lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -12,6 +12,7 @@
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/PluginManager.h"
+#include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -72,4 +73,181 @@
   ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
   ASSERT_EQ(module->GetSourceMappingList().GetSize(), 1u);
 }
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InternalAndPublicSDK) {
+  // Tests that we can parse the SDK path from debug-info.
+  // In the presence of multiple compile units, one of which
+  // points to an internal SDK, we should pick the internal SDK.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+- Attribute:   DW_AT_LLVM_sysroot
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"MacOSX10.9.sdk"
+- CStr:"/Library/Developer/CommandLineTools/SDKs/MacOSX10.9.sdk"
+- AbbrCode:0x
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x0010
+- CStr:"something.invalid.sdk"
+- CStr:"/invalid/path/to/something.invalid.sdk"
+- AbbrCode:0x
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x0010
+- CStr:"iPhoneOS14.0.Internal.sdk"
+- CStr:"/Library/Developer/CommandLineTools/SDKs/iPhoneOS14.0.Internal.sdk"
+- AbbrCode:0x
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"MacOSX10.9.sdk"
+- CStr:"/Library/Developer/CommandLineTools/SDKs/MacOSX10.9.sdk"
+- AbbrCode:0x
+...
+)";
+
+  YAMLModuleTester t(yamldata);
+  DWARFUnit *dwarf_unit = t.GetDwarfUnit();
+  auto *dwarf_cu = llvm::cast(dwarf_unit);
+  ASSERT_TRUE(static_cast(dwarf_cu));
+  SymbolFileDWARF &sym_file = dwarf_cu->GetSymbolFileDWARF();
+  ASSERT_EQ(sym_file.GetNumCompileUnits(), 4U);
+  ModuleSP module = t.GetModule();
+  ASSERT_NE(module, nullptr);
+
+  auto sdk_or_err = PlatformDarwin::GetSDKPathFromDebugInfo(*module);
+  ASSERT_TRUE(static_cast(sdk_or_err));
+
+  ASSERT_TRUE(sdk_or_err->IsAppleInternalSDK());
+  ASSERT_NE(sdk_or_err->GetString().find("Internal.sdk"), std::string::npos);
+}
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InvalidSDKPath) {
+  // Tests that parsing a CU with an invalid SDK directory name fails.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  Ab

[Lldb-commits] [PATCH] D156020: [lldb][PlatformDarwin] Parse SDK path for module compilation from debug-info

2023-07-26 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 544350.
Michael137 added a comment.

- Parameterize tests
- Return bool to indicate SDK mismatch


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156020/new/

https://reviews.llvm.org/D156020

Files:
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
  lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -12,6 +12,8 @@
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/PluginManager.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/Path.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -23,8 +25,55 @@
 class XcodeSDKModuleTests : public testing::Test {
   SubsystemRAII subsystems;
 };
-} // namespace
 
+struct SDKPathParsingTestData {
+  /// Each path will be put into a new CU's
+  /// DW_AT_LLVM_sysroot.
+  std::vector input_sdk_paths;
+
+  /// 'true' if we expect \ref GetSDKPathFromDebugInfo
+  /// to notify us about an SDK mismatch.
+  bool expect_mismatch;
+
+  /// 'true if the test expects the parsed SDK to
+  /// be an internal one.
+  bool expect_internal_sdk;
+
+  /// A substring that the final parsed sdk
+  /// is expected to contain.
+  llvm::StringRef expect_sdk_path_pattern;
+};
+
+struct SDKPathParsingMultiparamTests
+: public XcodeSDKModuleTests,
+  public testing::WithParamInterface {
+  std::vector
+  createCompileUnits(std::vector const &sdk_paths) {
+std::vector compile_units;
+
+for (auto sdk_path : sdk_paths) {
+  compile_units.emplace_back(llvm::formatv(
+  R"(
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:{0}
+- CStr:{1}
+- AbbrCode:0x
+)",
+  llvm::sys::path::filename(sdk_path, llvm::sys::path::Style::posix),
+  sdk_path));
+}
+
+return compile_units;
+  }
+};
+} // namespace
 
 TEST_F(XcodeSDKModuleTests, TestModuleGetXcodeSDK) {
   const char *yamldata = R"(
@@ -72,4 +121,190 @@
   ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
   ASSERT_EQ(module->GetSourceMappingList().GetSize(), 1u);
 }
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InvalidSDKPath) {
+  // Tests that parsing a CU with an invalid SDK directory name fails.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"1abc@defgh2"
+- AbbrCode:0x
+...
+)";
+
+  YAMLModuleTester t(yamldata);
+  ModuleSP module = t.GetModule();
+  ASSERT_NE(module, nullptr);
+
+  auto path_or_err = PlatformDarwin::ResolveSDKPathFromDebugInfo(*module);
+  EXPECT_FALSE(static_cast(path_or_err));
+  llvm::consumeError(path_or_err.takeError());
+}
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_No_DW_AT_APPLE_sdk) {
+  // Tests that parsing a CU without a DW_AT_APPLE_sdk fails.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_LLVM_sysroot
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"/Library/Developer/CommandLineTools/SDKs/iPhoneOS14.0.Internal.sdk"
+  

[Lldb-commits] [PATCH] D156020: [lldb][PlatformDarwin] Parse SDK path for module compilation from debug-info

2023-07-26 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 544376.
Michael137 added a comment.

- Fix test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156020/new/

https://reviews.llvm.org/D156020

Files:
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
  lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -12,6 +12,8 @@
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/PluginManager.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/Path.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -23,8 +25,55 @@
 class XcodeSDKModuleTests : public testing::Test {
   SubsystemRAII subsystems;
 };
-} // namespace
 
+struct SDKPathParsingTestData {
+  /// Each path will be put into a new CU's
+  /// DW_AT_LLVM_sysroot.
+  std::vector input_sdk_paths;
+
+  /// 'true' if we expect \ref GetSDKPathFromDebugInfo
+  /// to notify us about an SDK mismatch.
+  bool expect_mismatch;
+
+  /// 'true if the test expects the parsed SDK to
+  /// be an internal one.
+  bool expect_internal_sdk;
+
+  /// A substring that the final parsed sdk
+  /// is expected to contain.
+  llvm::StringRef expect_sdk_path_pattern;
+};
+
+struct SDKPathParsingMultiparamTests
+: public XcodeSDKModuleTests,
+  public testing::WithParamInterface {
+  std::vector
+  createCompileUnits(std::vector const &sdk_paths) {
+std::vector compile_units;
+
+for (auto sdk_path : sdk_paths) {
+  compile_units.emplace_back(llvm::formatv(
+  R"(
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:{0}
+- CStr:{1}
+- AbbrCode:0x
+)",
+  llvm::sys::path::filename(sdk_path, llvm::sys::path::Style::posix),
+  sdk_path));
+}
+
+return compile_units;
+  }
+};
+} // namespace
 
 TEST_F(XcodeSDKModuleTests, TestModuleGetXcodeSDK) {
   const char *yamldata = R"(
@@ -72,4 +121,190 @@
   ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
   ASSERT_EQ(module->GetSourceMappingList().GetSize(), 1u);
 }
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InvalidSDKPath) {
+  // Tests that parsing a CU with an invalid SDK directory name fails.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"1abc@defgh2"
+- AbbrCode:0x
+...
+)";
+
+  YAMLModuleTester t(yamldata);
+  ModuleSP module = t.GetModule();
+  ASSERT_NE(module, nullptr);
+
+  auto path_or_err = PlatformDarwin::ResolveSDKPathFromDebugInfo(*module);
+  EXPECT_FALSE(static_cast(path_or_err));
+  llvm::consumeError(path_or_err.takeError());
+}
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_No_DW_AT_APPLE_sdk) {
+  // Tests that parsing a CU without a DW_AT_APPLE_sdk fails.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_LLVM_sysroot
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"/Library/Developer/CommandLineTools/SDKs/iPhoneOS14.0.Internal.sdk"
+- AbbrCode:0x
+...
+)";
+
+  YA

[Lldb-commits] [PATCH] D156020: [lldb][PlatformDarwin] Parse SDK path for module compilation from debug-info

2023-07-26 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 544378.
Michael137 added a comment.

- EXPECT -> ASSERT


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156020/new/

https://reviews.llvm.org/D156020

Files:
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
  lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -12,6 +12,8 @@
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/PluginManager.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/Path.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -23,8 +25,55 @@
 class XcodeSDKModuleTests : public testing::Test {
   SubsystemRAII subsystems;
 };
-} // namespace
 
+struct SDKPathParsingTestData {
+  /// Each path will be put into a new CU's
+  /// DW_AT_LLVM_sysroot.
+  std::vector input_sdk_paths;
+
+  /// 'true' if we expect \ref GetSDKPathFromDebugInfo
+  /// to notify us about an SDK mismatch.
+  bool expect_mismatch;
+
+  /// 'true if the test expects the parsed SDK to
+  /// be an internal one.
+  bool expect_internal_sdk;
+
+  /// A substring that the final parsed sdk
+  /// is expected to contain.
+  llvm::StringRef expect_sdk_path_pattern;
+};
+
+struct SDKPathParsingMultiparamTests
+: public XcodeSDKModuleTests,
+  public testing::WithParamInterface {
+  std::vector
+  createCompileUnits(std::vector const &sdk_paths) {
+std::vector compile_units;
+
+for (auto sdk_path : sdk_paths) {
+  compile_units.emplace_back(llvm::formatv(
+  R"(
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:{0}
+- CStr:{1}
+- AbbrCode:0x
+)",
+  llvm::sys::path::filename(sdk_path, llvm::sys::path::Style::posix),
+  sdk_path));
+}
+
+return compile_units;
+  }
+};
+} // namespace
 
 TEST_F(XcodeSDKModuleTests, TestModuleGetXcodeSDK) {
   const char *yamldata = R"(
@@ -72,4 +121,190 @@
   ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
   ASSERT_EQ(module->GetSourceMappingList().GetSize(), 1u);
 }
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InvalidSDKPath) {
+  // Tests that parsing a CU with an invalid SDK directory name fails.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"1abc@defgh2"
+- AbbrCode:0x
+...
+)";
+
+  YAMLModuleTester t(yamldata);
+  ModuleSP module = t.GetModule();
+  ASSERT_NE(module, nullptr);
+
+  auto path_or_err = PlatformDarwin::ResolveSDKPathFromDebugInfo(*module);
+  EXPECT_FALSE(static_cast(path_or_err));
+  llvm::consumeError(path_or_err.takeError());
+}
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_No_DW_AT_APPLE_sdk) {
+  // Tests that parsing a CU without a DW_AT_APPLE_sdk fails.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_LLVM_sysroot
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"/Library/Developer/CommandLineTools/SDKs/iPhoneOS14.0.Internal.sdk"
+- AbbrCode:0x
+...
+)";

[Lldb-commits] [PATCH] D156020: [lldb][PlatformDarwin] Parse SDK path for module compilation from debug-info

2023-07-26 Thread Michael Buch via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb0b2b6bab4d2: [lldb][PlatformDarwin] Parse SDK path for 
module compilation from debug-info (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156020/new/

https://reviews.llvm.org/D156020

Files:
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
  lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -12,6 +12,8 @@
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/PluginManager.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/Path.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -23,8 +25,55 @@
 class XcodeSDKModuleTests : public testing::Test {
   SubsystemRAII subsystems;
 };
-} // namespace
 
+struct SDKPathParsingTestData {
+  /// Each path will be put into a new CU's
+  /// DW_AT_LLVM_sysroot.
+  std::vector input_sdk_paths;
+
+  /// 'true' if we expect \ref GetSDKPathFromDebugInfo
+  /// to notify us about an SDK mismatch.
+  bool expect_mismatch;
+
+  /// 'true if the test expects the parsed SDK to
+  /// be an internal one.
+  bool expect_internal_sdk;
+
+  /// A substring that the final parsed sdk
+  /// is expected to contain.
+  llvm::StringRef expect_sdk_path_pattern;
+};
+
+struct SDKPathParsingMultiparamTests
+: public XcodeSDKModuleTests,
+  public testing::WithParamInterface {
+  std::vector
+  createCompileUnits(std::vector const &sdk_paths) {
+std::vector compile_units;
+
+for (auto sdk_path : sdk_paths) {
+  compile_units.emplace_back(llvm::formatv(
+  R"(
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:{0}
+- CStr:{1}
+- AbbrCode:0x
+)",
+  llvm::sys::path::filename(sdk_path, llvm::sys::path::Style::posix),
+  sdk_path));
+}
+
+return compile_units;
+  }
+};
+} // namespace
 
 TEST_F(XcodeSDKModuleTests, TestModuleGetXcodeSDK) {
   const char *yamldata = R"(
@@ -72,4 +121,190 @@
   ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
   ASSERT_EQ(module->GetSourceMappingList().GetSize(), 1u);
 }
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InvalidSDKPath) {
+  // Tests that parsing a CU with an invalid SDK directory name fails.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_APPLE_sdk
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"1abc@defgh2"
+- AbbrCode:0x
+...
+)";
+
+  YAMLModuleTester t(yamldata);
+  ModuleSP module = t.GetModule();
+  ASSERT_NE(module, nullptr);
+
+  auto path_or_err = PlatformDarwin::ResolveSDKPathFromDebugInfo(*module);
+  EXPECT_FALSE(static_cast(path_or_err));
+  llvm::consumeError(path_or_err.takeError());
+}
+
+TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_No_DW_AT_APPLE_sdk) {
+  // Tests that parsing a CU without a DW_AT_APPLE_sdk fails.
+
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Attribute:   DW_AT_LLVM_sysroot
+  Form:DW_FORM_string
+  debug_info:
+- Version: 2
+  AddrSize:8
+  AbbrevTableID:   0
+  AbbrOffset:  0x0
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x000C
+- CStr:"/Li

[Lldb-commits] [PATCH] D156447: [lldb] Split CTF parsing and type creation (NFC)

2023-07-27 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h:108
+  uint32_t size, std::vector values)
+  : CTFType(eEnum, uid, name), nelems(nelems), size(size) {
+assert(values.size() == nelems);

did you omit this by accident?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156447/new/

https://reviews.llvm.org/D156447

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156447: [lldb] Split CTF parsing and type creation (NFC)

2023-07-27 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h:108
+  uint32_t size, std::vector values)
+  : CTFType(eEnum, uid, name), nelems(nelems), size(size) {
+assert(values.size() == nelems);

JDevlieghere wrote:
> Michael137 wrote:
> > did you omit this by accident?
> Yes, good eye. I need to see why my test didn't catch this. 
(also to add to the suggestion, probably best to use `this->values.size()` in 
the assert below to avoid a use-after-move; not sure which `values` takes 
precedence)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156447/new/

https://reviews.llvm.org/D156447

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156498: [lldb] Support recursive record types in CTF

2023-07-28 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

Generally LGTM, just some clarifications questions




Comment at: lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp:508
   ctf_record.name.data(), tag_kind, 
eLanguageTypeC);
+  m_compiler_types[record_type.GetOpaqueQualType()] = &ctf_record;
+  Declaration decl;

Just to clarify the lifetimes. This `ctf_record` lives on `m_ast` while the 
`m_compiler_types` on the SymbolFile, so we're guaranteed that the `ctf_record` 
lives long enough?



Comment at: lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp:524-529
+  // We only support resolving record types.
+  assert(ctf_type->kind == CTFType::Kind::eStruct ||
+ ctf_type->kind == CTFType::Kind::eUnion);
 
-  m_ast->StartTagDeclarationDefinition(record_type);
-  for (const CTFRecord::Field &field : ctf_record.fields) {
-if (Type *field_type = ResolveTypeUID(field.type)) {
-  const uint32_t field_size = field_type->GetByteSize(nullptr).value_or(0);
-  TypeSystemClang::AddFieldToRecordType(record_type, field.name,
-field_type->GetFullCompilerType(),
-eAccessPublic, field_size);
+  // Cast to the appropriate CTF type.
+  const CTFRecord *ctf_record = static_cast(ctf_type);

Nit: would it make sense to just add `classof` methods to `CTFType` and use the 
llvm cast facilities?

Feel free to ignore since there's just one instance of such cast afaict


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156498/new/

https://reviews.llvm.org/D156498

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156606: [lldb] Improve memory usage by freeing CTF types (NFC)

2023-07-31 Thread Michael Buch via Phabricator via lldb-commits
Michael137 accepted this revision.
Michael137 added a comment.
This revision is now accepted and ready to land.

LGTM


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156606/new/

https://reviews.llvm.org/D156606

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156774: [lldb] Parse enums while parsing a type

2023-08-01 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

Thanks for addressing this.

Can you add a test? Possibly in `lldb/test/API/lang/cpp/enum_types/`. Or 
`lldb/test/API/lang/cpp/const_static_integral_member/`




Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:3040
 
+case DW_TAG_enumeration_type:
+{

At first glance this seems OK but I'll want to check why the type doesn't get 
resolved when `clang::Sema` asks LLDB for it by name


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156774/new/

https://reviews.llvm.org/D156774

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156774: [lldb] Parse enums while parsing a type

2023-08-01 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:3040
 
+case DW_TAG_enumeration_type:
+{

Michael137 wrote:
> At first glance this seems OK but I'll want to check why the type doesn't get 
> resolved when `clang::Sema` asks LLDB for it by name
Checking locally and will report back


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156774/new/

https://reviews.llvm.org/D156774

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156827: [lldb][test] Skip *-dbg-info-content API tests

2023-08-01 Thread Michael Buch via Phabricator via lldb-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, iana, JDevlieghere.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

These tests started failing on the public build-bots recently
with following error:

  AssertionError: 'error: Couldn't lookup symbols:
__ZNSt3__122__libcpp_verbose_abortEPKcz
  ' is not success

We've seen this previously when the SDKs we used to compile the
`std` module differ from the test program. (see D146714 
, rdar://107052293)

Skip these tests on older MacOS versions for now.

This is possibly related to the recent `std` module changes in D144322 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156827

Files:
  
lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
  
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py


Index: 
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
===
--- 
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
+++ 
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
@@ -12,6 +12,7 @@
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
+@skipIf(macos_version=["<", "14.0"])
 def test(self):
 self.build()
 
Index: 
lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
===
--- 
lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
+++ 
lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
@@ -12,6 +12,7 @@
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
+@skipIf(macos_version=["<", "14.0"])
 def test(self):
 self.build()
 


Index: lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
@@ -12,6 +12,7 @@
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
+@skipIf(macos_version=["<", "14.0"])
 def test(self):
 self.build()
 
Index: lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
@@ -12,6 +12,7 @@
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
+@skipIf(macos_version=["<", "14.0"])
 def test(self):
 self.build()
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156827: [lldb][test] Skip *-dbg-info-content API tests

2023-08-01 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 546226.
Michael137 added a comment.

- Amend commit message


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156827/new/

https://reviews.llvm.org/D156827

Files:
  
lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
  
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py


Index: 
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
===
--- 
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
+++ 
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
@@ -12,6 +12,7 @@
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
+@skipIf(macos_version=["<", "14.0"])
 def test(self):
 self.build()
 
Index: 
lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
===
--- 
lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
+++ 
lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
@@ -12,6 +12,7 @@
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
+@skipIf(macos_version=["<", "14.0"])
 def test(self):
 self.build()
 


Index: lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
@@ -12,6 +12,7 @@
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
+@skipIf(macos_version=["<", "14.0"])
 def test(self):
 self.build()
 
Index: lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
@@ -12,6 +12,7 @@
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
+@skipIf(macos_version=["<", "14.0"])
 def test(self):
 self.build()
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156822: [lldb] Make IR interpretation interruptible

2023-08-01 Thread Michael Buch via Phabricator via lldb-commits
Michael137 accepted this revision.
Michael137 added a comment.
This revision is now accepted and ready to land.

LGTM


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156822/new/

https://reviews.llvm.org/D156822

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156827: [lldb][test] Skip *-dbg-info-content API tests

2023-08-01 Thread Michael Buch via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5ce7831b4023: [lldb][test] Skip *-dbg-info-content API tests 
(authored by Michael137).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156827/new/

https://reviews.llvm.org/D156827

Files:
  
lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
  
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py


Index: 
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
===
--- 
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
+++ 
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
@@ -12,6 +12,7 @@
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
+@skipIf(macos_version=["<", "14.0"])
 def test(self):
 self.build()
 
Index: 
lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
===
--- 
lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
+++ 
lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
@@ -12,6 +12,7 @@
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
+@skipIf(macos_version=["<", "14.0"])
 def test(self):
 self.build()
 


Index: lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
@@ -12,6 +12,7 @@
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
+@skipIf(macos_version=["<", "14.0"])
 def test(self):
 self.build()
 
Index: lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
@@ -12,6 +12,7 @@
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
+@skipIf(macos_version=["<", "14.0"])
 def test(self):
 self.build()
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156774: [lldb] Parse enums while parsing a type

2023-08-02 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:3040
 
+case DW_TAG_enumeration_type:
+{

Michael137 wrote:
> Michael137 wrote:
> > At first glance this seems OK but I'll want to check why the type doesn't 
> > get resolved when `clang::Sema` asks LLDB for it by name
> Checking locally and will report back
Ok, so what happens for `expr Outer::Enum::var` is that LLDB will first resolve 
the `Outer` structure (and all its member fields, but not nested types). When 
clang looks for `Enum`, it wants to find it in a direct lookup into the `Outer` 
DeclContext. But that lookup will fail because we never created the decls for 
the nested type. There is no fallback to the external source in such a case 
unfortunately so LLDB never has the chance to correct this. See the 
`LookupQualifiedName` code path in `Sema::BuildCXXNestedNameSpecifier`.

So I think this proposed approach should be fine. But what I think could be 
better is if we just do the same for `DW_TAG_enumeration_type` and 
`DW_TAG_structure_type` as we do for `DW_TAG_subprogram`.

I.e., simply push back the type into `member_function_dies` (we should rename 
this) and then it will get resolved properly in `CompleteRecordType`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156774/new/

https://reviews.llvm.org/D156774

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156774: [lldb] Parse enums while parsing a type

2023-08-02 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

Could you update the commit message with a description of the failure and 
summary of the fix? And change the title to something like 
`[lldb][DWARFASTParserClang] Resolve nested types when parsing structures`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156774/new/

https://reviews.llvm.org/D156774

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156774: [lldb] Parse enums while parsing a type

2023-08-02 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:3040
 
+case DW_TAG_enumeration_type:
+{

Michael137 wrote:
> Michael137 wrote:
> > Michael137 wrote:
> > > At first glance this seems OK but I'll want to check why the type doesn't 
> > > get resolved when `clang::Sema` asks LLDB for it by name
> > Checking locally and will report back
> Ok, so what happens for `expr Outer::Enum::var` is that LLDB will first 
> resolve the `Outer` structure (and all its member fields, but not nested 
> types). When clang looks for `Enum`, it wants to find it in a direct lookup 
> into the `Outer` DeclContext. But that lookup will fail because we never 
> created the decls for the nested type. There is no fallback to the external 
> source in such a case unfortunately so LLDB never has the chance to correct 
> this. See the `LookupQualifiedName` code path in 
> `Sema::BuildCXXNestedNameSpecifier`.
> 
> So I think this proposed approach should be fine. But what I think could be 
> better is if we just do the same for `DW_TAG_enumeration_type` and 
> `DW_TAG_structure_type` as we do for `DW_TAG_subprogram`.
> 
> I.e., simply push back the type into `member_function_dies` (we should rename 
> this) and then it will get resolved properly in `CompleteRecordType`.
Also `DW_TAG_union_type` while you're here :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156774/new/

https://reviews.llvm.org/D156774

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156774: [lldb][DWARFASTParserClang] Resolve nested types when parsing structures

2023-08-02 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:3040
 
+case DW_TAG_enumeration_type:
+{

Endill wrote:
> Michael137 wrote:
> > Michael137 wrote:
> > > Michael137 wrote:
> > > > Michael137 wrote:
> > > > > At first glance this seems OK but I'll want to check why the type 
> > > > > doesn't get resolved when `clang::Sema` asks LLDB for it by name
> > > > Checking locally and will report back
> > > Ok, so what happens for `expr Outer::Enum::var` is that LLDB will first 
> > > resolve the `Outer` structure (and all its member fields, but not nested 
> > > types). When clang looks for `Enum`, it wants to find it in a direct 
> > > lookup into the `Outer` DeclContext. But that lookup will fail because we 
> > > never created the decls for the nested type. There is no fallback to the 
> > > external source in such a case unfortunately so LLDB never has the chance 
> > > to correct this. See the `LookupQualifiedName` code path in 
> > > `Sema::BuildCXXNestedNameSpecifier`.
> > > 
> > > So I think this proposed approach should be fine. But what I think could 
> > > be better is if we just do the same for `DW_TAG_enumeration_type` and 
> > > `DW_TAG_structure_type` as we do for `DW_TAG_subprogram`.
> > > 
> > > I.e., simply push back the type into `member_function_dies` (we should 
> > > rename this) and then it will get resolved properly in 
> > > `CompleteRecordType`.
> > Also `DW_TAG_union_type` while you're here :)
> I can look into doing things more lazily like `DW_TAG_subprogram`, if you can 
> point me to code paths for this on LLDB side:
> > When clang looks for Enum, it wants to find it in a direct lookup into the 
> > Outer DeclContext. But that lookup will fail because we never created the 
> > decls for the nested type. There is no fallback to the external source in 
> > such a case unfortunately so LLDB never has the chance to correct this.
The `DW_TAG_subprogram` path is just above this one in the switch statement 
(line 3030). Search for `member_function_dies` in this file.

> if you can point me to code paths for this on LLDB side

Clang requests type completion by calling `FindExternalVisibleDeclsByName` 
(which LLDB implements). So if you break in that function you should be able to 
see what LLDB finds when it looks for the outer structure and the enum. But you 
don't necessarily need to do that. If we just fill up the 
`member_function_dies` vector with the nested enum/union/structure types like 
we do for `DW_TAG_subprogram` that is sufficient.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156774/new/

https://reviews.llvm.org/D156774

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D157059: [lldb][PECOFF] Exclude alignment padding when reading section data

2023-08-09 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

Hi, this is failing on swift-ci (runs on x86 bots) with the following error:

  
/Users/ec2-user/jenkins/workspace/oss-lldb-incremental-macos-cmake/build/Ninja-ReleaseAssert+stdlib-Release/lldb-macosx-x86_64/unittests/ObjectFile/PECOFF/./ObjectFilePECOFFTests
 --gtest_filter=SectionSizeTest.NoAlignmentPadding
  --
  YAML:12:5: error: unknown key 'SizeOfRawData'
  SizeOfRawData:   512
  ^
  
/Users/ec2-user/jenkins/workspace/oss-lldb-incremental-macos-cmake/llvm-project/lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp:49:
 Failure
  Value of: llvm::detail::TakeExpected(ExpectedFile)
  Expected: succeeded
Actual: failed  (convertYAML() failed)
  
  
/Users/ec2-user/jenkins/workspace/oss-lldb-incremental-macos-cmake/llvm-project/lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp:49
  Value of: llvm::detail::TakeExpected(ExpectedFile)
  Expected: succeeded
Actual: failed  (convertYAML() failed)

https://ci.swift.org/view/LLDB/job/oss-lldb-incremental-macos-cmake/

Could you take a look please?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157059/new/

https://reviews.llvm.org/D157059

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156774: [lldb][DWARFASTParserClang] Resolve nested types when parsing structures

2023-08-09 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

Are you still planning on moving this forward? Otherwise I could commandeer the 
revision to get this in. I do think it's a useful bug to address


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156774/new/

https://reviews.llvm.org/D156774

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156774: [lldb][DWARFASTParserClang] Resolve nested types when parsing structures

2023-08-09 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

In D156774#4572967 , @Endill wrote:

> In D156774#4572947 , @Michael137 
> wrote:
>
>> Are you still planning on moving this forward? Otherwise I could commandeer 
>> the revision to get this in. I do think it's a useful bug to address
>
> I do. Locally I've been preparing additional changes on top of this patch 
> that expose enums in SBType, so that I can do end-to-end test to ensure this 
> sufficiently addresses my use case.
> On top of that, I'm planning to redo this patch after the example of 
> `DW_TAG_subprogram` per your suggestion.
>
> Unfortunately, I didn't have time last week for this, and now I'm knee deep 
> into triaging old Clang bugs. I'm not finished with that until number of open 
> issues is brought under 20k :)

Sounds good, thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156774/new/

https://reviews.llvm.org/D156774

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D157512: [lldb][PlatformDarwin] Only parse SDK from debug-info if target language is Objective-C

2023-08-09 Thread Michael Buch via Phabricator via lldb-commits
Michael137 created this revision.
Michael137 added a reviewer: aprantl.
Herald added a subscriber: kadircet.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added subscribers: lldb-commits, ilya-biryukov.
Herald added a project: LLDB.

The call to `HostInfoMacOSX::GetSDKRoot` can noticeably slow down the first
expression evaluation in an LLDB session. For C++ expressions we don't
actually ever use the results of the `ClangDeclVendor`, so getting the
flags right isn't necessary. Thus skip SDK parsing logic for C++
targets.

An alternative would be to entirely omit the setup of the
ClangDeclVendor (and other Objective-C machinery) for C++ targets.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157512

Files:
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp


Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
===
--- lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Breakpoint/BreakpointLocation.h"
 #include "lldb/Breakpoint/BreakpointSite.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Target/Language.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Core/PluginManager.h"
@@ -1097,7 +1098,7 @@
 
   FileSpec sysroot_spec;
 
-  if (target) {
+  if (target && Language::LanguageIsObjC(target->GetLanguage())) {
 if (ModuleSP exe_module_sp = target->GetExecutableModule()) {
   auto path_or_err = ResolveSDKPathFromDebugInfo(*exe_module_sp);
   if (path_or_err) {


Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
===
--- lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Breakpoint/BreakpointLocation.h"
 #include "lldb/Breakpoint/BreakpointSite.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Target/Language.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Core/PluginManager.h"
@@ -1097,7 +1098,7 @@
 
   FileSpec sysroot_spec;
 
-  if (target) {
+  if (target && Language::LanguageIsObjC(target->GetLanguage())) {
 if (ModuleSP exe_module_sp = target->GetExecutableModule()) {
   auto path_or_err = ResolveSDKPathFromDebugInfo(*exe_module_sp);
   if (path_or_err) {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D157636: [lldb][test] Remove tests relying on deprecated std::char_traits specializations

2023-08-10 Thread Michael Buch via Phabricator via lldb-commits
Michael137 created this revision.
Michael137 added reviewers: gribozavr2, JDevlieghere.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

(motivated by test failures after D157058 )

With D157058  the base template for 
`std::char_traits` was removed from
libc++. Quoting the release notes:

  The base template for ``std::char_traits`` has been removed. If you are using
  ``std::char_traits`` with types other than ``char``, ``wchar_t``, ``char8_t``,
  ``char16_t``, ``char32_t`` or a custom character type for which you
  specialized ``std::char_traits``, your code will no longer work.

This patch simply removes all such instantiations to make sure the
tests that run against the latest libc++ version pass.

One could try testing the existence of this base template from within
the test source files but this doesn't seem like something we want
support.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157636

Files:
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/TestDataFormatterLibcxxStringView.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/main.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
@@ -9,7 +9,6 @@
 std::string empty("");
 std::string q("hello world");
 std::string Q("quite a long std::strin with lots of info inside it");
-std::basic_string uchar(5, 'a');
 auto &rq = q, &rQ = Q;
 std::string *pq = &q, *pQ = &Q;
 S.assign(L"!"); // Set break point at this line.
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
@@ -61,8 +61,6 @@
 var_pq = self.frame().FindVariable("pq")
 var_pQ = self.frame().FindVariable("pQ")
 
-var_uchar = self.frame().FindVariable("uchar")
-
 self.assertEqual(var_wempty.GetSummary(), 'L""', "wempty summary wrong")
 self.assertEqual(
 var_s.GetSummary(), 'L"hello world! מזל טוב!"', "s summary wrong"
@@ -78,7 +76,6 @@
 '"quite a long std::strin with lots of info inside it"',
 "Q summary wrong",
 )
-self.assertEqual(var_uchar.GetSummary(), '"a"', "u summary wrong")
 self.assertEqual(var_rq.GetSummary(), '"hello world"', "rq summary wrong")
 self.assertEqual(
 var_rQ.GetSummary(),
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/main.cpp
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/main.cpp
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/main.cpp
@@ -92,8 +92,6 @@
   std::u16string_view u16_empty(u"");
   std::u32string_view u32_string(U"🍄🍅🍆🍌");
   std::u32string_view u32_empty(U"");
-  std::basic_string uchar_source(10, 'a');
-  std::basic_string_view uchar(uchar_source.data(), 5);
   std::string_view *null_str = nullptr;
 
   std::string hello = "Hellooo ";
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/TestDataFormatterLibcxxStringView.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/TestDataFormatterLibcxxStringView.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/TestDataFormatterLibcxxStringView.py
@@ -60,15 +60,6 @@
 # Execute the cleanup function during test case tear down.
 self.addTearDownHook(cleanup)
 
-if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(
-[">", "16.0"]
-):
-expected_basic_string = "std::basic_string"
-e

[Lldb-commits] [PATCH] D157636: [lldb][test] Remove tests relying on deprecated std::char_traits specializations

2023-08-10 Thread Michael Buch via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG487ab39a5082: [lldb][test] Remove tests relying on 
deprecated std::char_traits specializations (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157636/new/

https://reviews.llvm.org/D157636

Files:
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/TestDataFormatterLibcxxStringView.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/main.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
@@ -9,7 +9,6 @@
 std::string empty("");
 std::string q("hello world");
 std::string Q("quite a long std::strin with lots of info inside it");
-std::basic_string uchar(5, 'a');
 auto &rq = q, &rQ = Q;
 std::string *pq = &q, *pQ = &Q;
 S.assign(L"!"); // Set break point at this line.
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
@@ -61,8 +61,6 @@
 var_pq = self.frame().FindVariable("pq")
 var_pQ = self.frame().FindVariable("pQ")
 
-var_uchar = self.frame().FindVariable("uchar")
-
 self.assertEqual(var_wempty.GetSummary(), 'L""', "wempty summary wrong")
 self.assertEqual(
 var_s.GetSummary(), 'L"hello world! מזל טוב!"', "s summary wrong"
@@ -78,7 +76,6 @@
 '"quite a long std::strin with lots of info inside it"',
 "Q summary wrong",
 )
-self.assertEqual(var_uchar.GetSummary(), '"a"', "u summary wrong")
 self.assertEqual(var_rq.GetSummary(), '"hello world"', "rq summary wrong")
 self.assertEqual(
 var_rQ.GetSummary(),
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/main.cpp
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/main.cpp
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/main.cpp
@@ -92,8 +92,6 @@
   std::u16string_view u16_empty(u"");
   std::u32string_view u32_string(U"🍄🍅🍆🍌");
   std::u32string_view u32_empty(U"");
-  std::basic_string uchar_source(10, 'a');
-  std::basic_string_view uchar(uchar_source.data(), 5);
   std::string_view *null_str = nullptr;
 
   std::string hello = "Hellooo ";
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/TestDataFormatterLibcxxStringView.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/TestDataFormatterLibcxxStringView.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/TestDataFormatterLibcxxStringView.py
@@ -60,15 +60,6 @@
 # Execute the cleanup function during test case tear down.
 self.addTearDownHook(cleanup)
 
-if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(
-[">", "16.0"]
-):
-expected_basic_string = "std::basic_string"
-expected_basic_string_view = "std::basic_string_view"
-else:
-expected_basic_string = "std::basic_string, std::allocator >"
-expected_basic_string_view = "std::basic_string_view >"
-
 self.expect_var_path("wempty", type="std::wstring_view", summary='L""')
 self.expect_var_path(
 "s", type="std::wstring_view", summary='L"hello world! מזל טוב!"'
@@ -96,12 +87,6 @@
 "u32_string", type="std::u32string_view", summary='U"🍄🍅🍆🍌"'
 )
 self.expect_var_path("u32_empty", type="std::u32string_view", summary='""')
-self.expect_var_path(
-"uchar_source", type=expected_basic_string, summary='"aa"'
-)
-se

[Lldb-commits] [PATCH] D157992: [lldb][CPlusPlus][NFCI] Remove redundant construction of ClangASTImporter

2023-08-15 Thread Michael Buch via Phabricator via lldb-commits
Michael137 created this revision.
Michael137 added a reviewer: aprantl.
Herald added a subscriber: martong.
Herald added a reviewer: a.sidorin.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The usage of this variable was removed in 
`4f14c17df70916913d71914343dd4f6c709e218d`.

This is no longer used inside this file. Since the call to
`GetPersistentExpressionStateForLanguage` has side-effects I marked this
NFCI. But there is no good reason we need this here.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157992

Files:
  lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp


Index: lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
@@ -54,18 +54,6 @@
 if (!clang_ast_context)
   return;
 
-std::shared_ptr clang_ast_importer;
-auto *state = target_sp->GetPersistentExpressionStateForLanguage(
-lldb::eLanguageTypeC_plus_plus);
-if (state) {
-  auto *persistent_vars = llvm::cast(state);
-  clang_ast_importer = persistent_vars->GetClangASTImporter();
-}
-
-if (!clang_ast_importer) {
-  return;
-}
-
 const char *const isa_name("__isa");
 const CompilerType isa_type =
 clang_ast_context->GetBasicType(lldb::eBasicTypeObjCClass);


Index: lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
@@ -54,18 +54,6 @@
 if (!clang_ast_context)
   return;
 
-std::shared_ptr clang_ast_importer;
-auto *state = target_sp->GetPersistentExpressionStateForLanguage(
-lldb::eLanguageTypeC_plus_plus);
-if (state) {
-  auto *persistent_vars = llvm::cast(state);
-  clang_ast_importer = persistent_vars->GetClangASTImporter();
-}
-
-if (!clang_ast_importer) {
-  return;
-}
-
 const char *const isa_name("__isa");
 const CompilerType isa_type =
 clang_ast_context->GetBasicType(lldb::eBasicTypeObjCClass);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D157992: [lldb][CPlusPlus][NFCI] Remove redundant construction of ClangASTImporter

2023-08-15 Thread Michael Buch via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG92d7254a989d: [lldb][CPlusPlus][NFCI] Remove redundant 
construction of ClangASTImporter (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157992/new/

https://reviews.llvm.org/D157992

Files:
  lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp


Index: lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
@@ -54,18 +54,6 @@
 if (!clang_ast_context)
   return;
 
-std::shared_ptr clang_ast_importer;
-auto *state = target_sp->GetPersistentExpressionStateForLanguage(
-lldb::eLanguageTypeC_plus_plus);
-if (state) {
-  auto *persistent_vars = llvm::cast(state);
-  clang_ast_importer = persistent_vars->GetClangASTImporter();
-}
-
-if (!clang_ast_importer) {
-  return;
-}
-
 const char *const isa_name("__isa");
 const CompilerType isa_type =
 clang_ast_context->GetBasicType(lldb::eBasicTypeObjCClass);


Index: lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
@@ -54,18 +54,6 @@
 if (!clang_ast_context)
   return;
 
-std::shared_ptr clang_ast_importer;
-auto *state = target_sp->GetPersistentExpressionStateForLanguage(
-lldb::eLanguageTypeC_plus_plus);
-if (state) {
-  auto *persistent_vars = llvm::cast(state);
-  clang_ast_importer = persistent_vars->GetClangASTImporter();
-}
-
-if (!clang_ast_importer) {
-  return;
-}
-
 const char *const isa_name("__isa");
 const CompilerType isa_type =
 clang_ast_context->GetBasicType(lldb::eBasicTypeObjCClass);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D158172: [lldb][ClangASTImporter][NFC] Remove redundant calls to ASTImporter::Imported

2023-08-17 Thread Michael Buch via Phabricator via lldb-commits
Michael137 created this revision.
Michael137 added a reviewer: aprantl.
Herald added a subscriber: martong.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The `ASTImporter::Imported` base method has been made a no-op in
`26f72a96559f2acd6799c363f1ca88ef3238c601`. So all calls to it from
a base-class are now redundant. The API is now only used to notify
subclasses that an import occurred and not for any other bookkeeping.
That is done in `MapImported` which we call properly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158172

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp


Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -902,7 +902,6 @@
   // We want that 'to' is actually complete after this function so let's
   // tell the ASTImporter that 'to' was imported from 'from'.
   MapImported(from, to);
-  ASTImporter::Imported(from, to);
 
   Log *log = GetLog(LLDBLog::Expressions);
 
@@ -1028,7 +1027,7 @@
   // Some decls shouldn't be tracked here because they were not created by
   // copying 'from' to 'to'. Just exit early for those.
   if (m_decls_to_ignore.count(to))
-return clang::ASTImporter::Imported(from, to);
+return;
 
   // Transfer module ownership information.
   auto *from_source = llvm::dyn_cast_or_null(
@@ -1081,12 +1080,6 @@
 if (!to_context_md->hasOrigin(to) || user_id != LLDB_INVALID_UID)
   to_context_md->setOrigin(to, origin);
 
-ImporterDelegateSP direct_completer =
-m_main.GetDelegate(&to->getASTContext(), origin.ctx);
-
-if (direct_completer.get() != this)
-  direct_completer->ASTImporter::Imported(origin.decl, to);
-
 LLDB_LOG(log,
  "[ClangASTImporter] Propagated origin "
  "(Decl*){0}/(ASTContext*){1} from (ASTContext*){2} to "


Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -902,7 +902,6 @@
   // We want that 'to' is actually complete after this function so let's
   // tell the ASTImporter that 'to' was imported from 'from'.
   MapImported(from, to);
-  ASTImporter::Imported(from, to);
 
   Log *log = GetLog(LLDBLog::Expressions);
 
@@ -1028,7 +1027,7 @@
   // Some decls shouldn't be tracked here because they were not created by
   // copying 'from' to 'to'. Just exit early for those.
   if (m_decls_to_ignore.count(to))
-return clang::ASTImporter::Imported(from, to);
+return;
 
   // Transfer module ownership information.
   auto *from_source = llvm::dyn_cast_or_null(
@@ -1081,12 +1080,6 @@
 if (!to_context_md->hasOrigin(to) || user_id != LLDB_INVALID_UID)
   to_context_md->setOrigin(to, origin);
 
-ImporterDelegateSP direct_completer =
-m_main.GetDelegate(&to->getASTContext(), origin.ctx);
-
-if (direct_completer.get() != this)
-  direct_completer->ASTImporter::Imported(origin.decl, to);
-
 LLDB_LOG(log,
  "[ClangASTImporter] Propagated origin "
  "(Decl*){0}/(ASTContext*){1} from (ASTContext*){2} to "
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D158172: [lldb][ClangASTImporter][NFC] Remove redundant calls to ASTImporter::Imported

2023-08-17 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 551086.
Michael137 added a comment.

- Reword commit message


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158172/new/

https://reviews.llvm.org/D158172

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp


Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -902,7 +902,6 @@
   // We want that 'to' is actually complete after this function so let's
   // tell the ASTImporter that 'to' was imported from 'from'.
   MapImported(from, to);
-  ASTImporter::Imported(from, to);
 
   Log *log = GetLog(LLDBLog::Expressions);
 
@@ -1028,7 +1027,7 @@
   // Some decls shouldn't be tracked here because they were not created by
   // copying 'from' to 'to'. Just exit early for those.
   if (m_decls_to_ignore.count(to))
-return clang::ASTImporter::Imported(from, to);
+return;
 
   // Transfer module ownership information.
   auto *from_source = llvm::dyn_cast_or_null(
@@ -1081,12 +1080,6 @@
 if (!to_context_md->hasOrigin(to) || user_id != LLDB_INVALID_UID)
   to_context_md->setOrigin(to, origin);
 
-ImporterDelegateSP direct_completer =
-m_main.GetDelegate(&to->getASTContext(), origin.ctx);
-
-if (direct_completer.get() != this)
-  direct_completer->ASTImporter::Imported(origin.decl, to);
-
 LLDB_LOG(log,
  "[ClangASTImporter] Propagated origin "
  "(Decl*){0}/(ASTContext*){1} from (ASTContext*){2} to "


Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -902,7 +902,6 @@
   // We want that 'to' is actually complete after this function so let's
   // tell the ASTImporter that 'to' was imported from 'from'.
   MapImported(from, to);
-  ASTImporter::Imported(from, to);
 
   Log *log = GetLog(LLDBLog::Expressions);
 
@@ -1028,7 +1027,7 @@
   // Some decls shouldn't be tracked here because they were not created by
   // copying 'from' to 'to'. Just exit early for those.
   if (m_decls_to_ignore.count(to))
-return clang::ASTImporter::Imported(from, to);
+return;
 
   // Transfer module ownership information.
   auto *from_source = llvm::dyn_cast_or_null(
@@ -1081,12 +1080,6 @@
 if (!to_context_md->hasOrigin(to) || user_id != LLDB_INVALID_UID)
   to_context_md->setOrigin(to, origin);
 
-ImporterDelegateSP direct_completer =
-m_main.GetDelegate(&to->getASTContext(), origin.ctx);
-
-if (direct_completer.get() != this)
-  direct_completer->ASTImporter::Imported(origin.decl, to);
-
 LLDB_LOG(log,
  "[ClangASTImporter] Propagated origin "
  "(Decl*){0}/(ASTContext*){1} from (ASTContext*){2} to "
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D158172: [lldb][ClangASTImporter][NFC] Remove redundant calls to ASTImporter::Imported

2023-08-17 Thread Michael Buch via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9c3f1f42cbed: [lldb][ClangASTImporter][NFC] Remove redundant 
calls to ASTImporter::Imported (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158172/new/

https://reviews.llvm.org/D158172

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp


Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -902,7 +902,6 @@
   // We want that 'to' is actually complete after this function so let's
   // tell the ASTImporter that 'to' was imported from 'from'.
   MapImported(from, to);
-  ASTImporter::Imported(from, to);
 
   Log *log = GetLog(LLDBLog::Expressions);
 
@@ -1028,7 +1027,7 @@
   // Some decls shouldn't be tracked here because they were not created by
   // copying 'from' to 'to'. Just exit early for those.
   if (m_decls_to_ignore.count(to))
-return clang::ASTImporter::Imported(from, to);
+return;
 
   // Transfer module ownership information.
   auto *from_source = llvm::dyn_cast_or_null(
@@ -1081,12 +1080,6 @@
 if (!to_context_md->hasOrigin(to) || user_id != LLDB_INVALID_UID)
   to_context_md->setOrigin(to, origin);
 
-ImporterDelegateSP direct_completer =
-m_main.GetDelegate(&to->getASTContext(), origin.ctx);
-
-if (direct_completer.get() != this)
-  direct_completer->ASTImporter::Imported(origin.decl, to);
-
 LLDB_LOG(log,
  "[ClangASTImporter] Propagated origin "
  "(Decl*){0}/(ASTContext*){1} from (ASTContext*){2} to "


Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -902,7 +902,6 @@
   // We want that 'to' is actually complete after this function so let's
   // tell the ASTImporter that 'to' was imported from 'from'.
   MapImported(from, to);
-  ASTImporter::Imported(from, to);
 
   Log *log = GetLog(LLDBLog::Expressions);
 
@@ -1028,7 +1027,7 @@
   // Some decls shouldn't be tracked here because they were not created by
   // copying 'from' to 'to'. Just exit early for those.
   if (m_decls_to_ignore.count(to))
-return clang::ASTImporter::Imported(from, to);
+return;
 
   // Transfer module ownership information.
   auto *from_source = llvm::dyn_cast_or_null(
@@ -1081,12 +1080,6 @@
 if (!to_context_md->hasOrigin(to) || user_id != LLDB_INVALID_UID)
   to_context_md->setOrigin(to, origin);
 
-ImporterDelegateSP direct_completer =
-m_main.GetDelegate(&to->getASTContext(), origin.ctx);
-
-if (direct_completer.get() != this)
-  direct_completer->ASTImporter::Imported(origin.decl, to);
-
 LLDB_LOG(log,
  "[ClangASTImporter] Propagated origin "
  "(Decl*){0}/(ASTContext*){1} from (ASTContext*){2} to "
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156774: [lldb][DWARFASTParserClang] Resolve nested types when parsing structures

2023-08-20 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

In D156774#4601705 , @Endill wrote:

> I tested this patch together with the following new code:
>
>   uint32_t TypeSystemClang::GetNumMemberEnums(lldb::opaque_compiler_type_t 
> type) {
> using EnumIt = 
> clang::DeclContext::specific_decl_iterator;
> if (!type)
>   return 0;
> clang::QualType qual_type = 
> RemoveWrappingTypes(GetCanonicalQualType(type));
> clang::DeclContext *ctx = qual_type->getAsRecordDecl()->getDeclContext();
> return std::distance(EnumIt(ctx->decls_begin()), 
> EnumIt(ctx->decls_end()));
>   }
>   
>   CompilerType
>   TypeSystemClang::GetMemberEnumAtIndex(lldb::opaque_compiler_type_t type,
> size_t index) {
> using EnumIt = 
> clang::DeclContext::specific_decl_iterator;
> if (!type)
>   return CompilerType();
>   
> clang::QualType qual_type = 
> RemoveWrappingTypes(GetCanonicalQualType(type));
> clang::DeclContext *ctx = qual_type->getAsRecordDecl()->getDeclContext();
> size_t enum_index = 0;
> for (EnumIt enums_it(ctx->decls_begin()), enums_end(ctx->decls_end());
>  enums_it != enums_end;
>  ++enums_it, ++enum_index) {
> if (enum_index == index) {
>   return CompilerType(weak_from_this(), *enums_it);
> }
> }
>   }
>
> I created all the wrappers to make it available in Python. The result was 
> unsatisfactory: this code doesn't even trigger 
> `DWARFASTParserClang::ParseChildMembers` that this patch touches, and return 
> 0 instead of 1. This doesn't change even if I trigger `ParseChildMembers` via 
> other means before asking for a number of member enums in a type.
>
> Code I tested this on:
>
>   using intptr_t = long;
>   using uintptr_t = unsigned long;
>   
>   struct PointerIntPairInfo {
> enum MaskAndShiftConstants : uintptr_t {
>   PointerBitMask =
>   ~(uintptr_t)(((intptr_t)1 << 3) - 1),
> };
>   
> int a{};
>   };
>   
>   static uintptr_t dummy() {
> return PointerIntPairInfo::PointerBitMask;
>   }
>   
>   int main()
>   {
>   PointerIntPairInfo p;
>   __builtin_debugtrap();
>   return p.a + foo();
>   }
>
> If you have any suggestions what I missed or did wrong, please let me know.
>
> I'll continue with this patch nevertheless, but it's clear now that there's 
> still a way to go until I can access that enum without going through slow 
> expression evaluator.

What were your lldb commands when you tested this?

LLDB currently completes types lazily when it thinks it can. Does your new API 
still fail if you run `expr p` prior? (the idea is that that would trigger 
completion of the type and parse dwarf). If we dont ever call 
`GetFullCompilerType` on your type LLDB will never try to pull in the definition


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156774/new/

https://reviews.llvm.org/D156774

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156774: [lldb][DWARFASTParserClang] Resolve nested types when parsing structures

2023-08-20 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

In D156774#4601767 , @Endill wrote:

> In D156774#4601736 , @Michael137 
> wrote:
>
>> What were your lldb commands when you tested this?
>
> `script import lldb; frame = lldb.thread.GetFrameAtIndex(0); 
> print(frame.variables[0].type.GetNumberOfMemberEnums())`
>
>> LLDB currently completes types lazily when it thinks it can. Does your new 
>> API still fail if you run `expr p` prior? (the idea is that that would 
>> trigger completion of the type and parse dwarf). If we dont ever call 
>> `GetFullCompilerType` on your type LLDB will never try to pull in the 
>> definition
>
> No amount of tinkering with `expr` makes `script 
> print(frame.variables[0].type.GetNumberOfMemberEnums())` output a non-zero 
> value.
> I tested this with the changes I uploaded here half an hour ago.



In D156774#4601767 , @Endill wrote:

> In D156774#4601736 , @Michael137 
> wrote:
>
>> What were your lldb commands when you tested this?
>
> `script import lldb; frame = lldb.thread.GetFrameAtIndex(0); 
> print(frame.variables[0].type.GetNumberOfMemberEnums())`
>
>> LLDB currently completes types lazily when it thinks it can. Does your new 
>> API still fail if you run `expr p` prior? (the idea is that that would 
>> trigger completion of the type and parse dwarf). If we dont ever call 
>> `GetFullCompilerType` on your type LLDB will never try to pull in the 
>> definition
>
> No amount of tinkering with `expr` makes `script 
> print(frame.variables[0].type.GetNumberOfMemberEnums())` output a non-zero 
> value.
> I tested this with the changes I uploaded here half an hour ago.

I think you may want to use `GetCompleteQualType` before iterating the 
DeclContext. That will make sure we complete the type by the time we look for 
the enums.

E.g.,:

  clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));  
 
  if (GetCompleteQualType(&getASTContext(), qual_type)) {   
  
const clang::RecordType *record_type =  
   
llvm::cast(qual_type.getTypePtr());  
  
const clang::RecordDecl *record_decl = record_type->getDecl();  
   
assert(record_decl);
   
return std::distance(EnumIt(record_decl->decls_begin()), 
EnumIt(record_decl->decls_end())); 
  } 
   

Will review it more thoroughly on tomorrow though


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156774/new/

https://reviews.llvm.org/D156774

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156774: [lldb][DWARFASTParserClang] Resolve nested types when parsing structures

2023-09-12 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

In D156774#4644503 , @Endill wrote:

> Ping @Michael137

Sorry for the delay, just came back from vacation

The change itself LGTM. Can we add a test though? We do have 
DWARFASTParserClang unittests: 
https://github.com/llvm/llvm-project/blob/main/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp

If the yaml input file becomes tedious to write you could also just an API 
test. E.g., under 
https://github.com/llvm/llvm-project/tree/main/lldb/test/API/lang/cpp

Let me know if you need some pointers in writing the tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156774/new/

https://reviews.llvm.org/D156774

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156774: [lldb][DWARFASTParserClang] Resolve nested types when parsing structures

2023-09-12 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

Also, I assume the extra changes to make the PointerIntPair formatter work will 
be in a follow-up patch?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156774/new/

https://reviews.llvm.org/D156774

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129078: WIP: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-04 Thread Michael Buch via Phabricator via lldb-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, jingham.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: lldb-commits, sstefan1.
Herald added a project: LLDB.

This patch adds support for evaluating expressions which reference
a captured `this` from within the context of a C++ lambda expression.
Currently LLDB doesn't provide Clang with enough information to
determine that we're inside a lambda expression and are allowed to
access variables on a captured `this`; instead Clang simply fails
to parse the expression.

There are two problems to solve here:

1. Make sure `clang::Sema` doesn't reject the expression due to illegal member 
access.
2. Materialize all the necessary captured variables/member variables required 
to evaluate the expression.

To address (1), we currently import the outer structure's AST context
onto `$__lldb_class`, making the `contextClass` and the `NamingClass`
match, a requirement by `clang::Sema::BuildPossibleImplicitMemberExpr`.

To address (2), we inject all captured variables as locals into the
expression source code.

**Testing**

- Added API test


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp

Index: lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
@@ -0,0 +1,99 @@
+#include 
+#include 
+
+namespace {
+int global_var = -5;
+} // namespace
+
+struct Baz {
+  virtual ~Baz() = default;
+
+  virtual int baz_virt() = 0;
+
+  int base_base_var = 12;
+};
+
+struct Bar : public Baz {
+  virtual ~Bar() = default;
+
+  virtual int baz_virt() override {
+base_var = 10;
+return 1;
+  }
+
+  int base_var = 15;
+};
+
+struct Foo : public Bar {
+  int class_var = 9;
+  int shadowed = -137;
+  int *class_ptr;
+
+  virtual ~Foo() = default;
+
+  virtual int baz_virt() override {
+shadowed = -1;
+return 2;
+  }
+
+  void method() {
+int local_var = 137;
+int shadowed;
+class_ptr = &local_var;
+auto lambda = [&shadowed, this, &local_var,
+   local_var_copy = local_var]() mutable {
+  int lambda_local_var = 5;
+  shadowed = 5;
+  class_var = 109;
+  --base_var;
+  --base_base_var;
+  std::puts("break here");
+
+  auto nested_lambda = [this, &lambda_local_var] {
+std::puts("break here");
+lambda_local_var = 0;
+  };
+
+  nested_lambda();
+  --local_var_copy;
+  std::puts("break here");
+
+  struct LocalLambdaClass {
+int lambda_class_local = -12345;
+Foo *outer_ptr;
+
+void inner_method() {
+  auto lambda = [this] {
+std::puts("break here");
+lambda_class_local = -2;
+outer_ptr->class_var *= 2;
+  };
+
+  lambda();
+}
+  };
+
+  LocalLambdaClass l;
+  l.outer_ptr = this;
+  l.inner_method();
+};
+lambda();
+  }
+
+  void non_capturing_method() {
+int local = 5;
+int local2 = 10;
+
+class_var += [=] {
+  std::puts("break here");
+  return local + local2;
+}();
+  }
+};
+
+int main() {
+  Foo f;
+  f.method();
+  f.non_capturing_method();
+  return global_var;
+}
Index: lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
@@ -0,0 +1,123 @@
+""" Test that evaluating expressions from within C++ lambdas works
+Particularly, we test the case of capturing "this" and
+using members of the captured object in expression evaluation
+while we're on a breakpoint inside a lambda.
+"""
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+
+class ExprInsideLambdaTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def expectExprError(self, expr : str, expected : str):
+

[Lldb-commits] [PATCH] D129078: WIP: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-04 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

The is a draft for now, but feel free to comment on the approach. I'm still 
evaluating some other alternatives to this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129078: WIP: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-04 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 442102.
Michael137 added a comment.

- [LLDB][Expression] Allow instantiation of IR Entity from ValueObject
- WIP: [LLDB][ClangExpression] Allow expression evaluation from within C++ 
Lambdas


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp

Index: lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
@@ -0,0 +1,99 @@
+#include 
+#include 
+
+namespace {
+int global_var = -5;
+} // namespace
+
+struct Baz {
+  virtual ~Baz() = default;
+
+  virtual int baz_virt() = 0;
+
+  int base_base_var = 12;
+};
+
+struct Bar : public Baz {
+  virtual ~Bar() = default;
+
+  virtual int baz_virt() override {
+base_var = 10;
+return 1;
+  }
+
+  int base_var = 15;
+};
+
+struct Foo : public Bar {
+  int class_var = 9;
+  int shadowed = -137;
+  int *class_ptr;
+
+  virtual ~Foo() = default;
+
+  virtual int baz_virt() override {
+shadowed = -1;
+return 2;
+  }
+
+  void method() {
+int local_var = 137;
+int shadowed;
+class_ptr = &local_var;
+auto lambda = [&shadowed, this, &local_var,
+   local_var_copy = local_var]() mutable {
+  int lambda_local_var = 5;
+  shadowed = 5;
+  class_var = 109;
+  --base_var;
+  --base_base_var;
+  std::puts("break here");
+
+  auto nested_lambda = [this, &lambda_local_var] {
+std::puts("break here");
+lambda_local_var = 0;
+  };
+
+  nested_lambda();
+  --local_var_copy;
+  std::puts("break here");
+
+  struct LocalLambdaClass {
+int lambda_class_local = -12345;
+Foo *outer_ptr;
+
+void inner_method() {
+  auto lambda = [this] {
+std::puts("break here");
+lambda_class_local = -2;
+outer_ptr->class_var *= 2;
+  };
+
+  lambda();
+}
+  };
+
+  LocalLambdaClass l;
+  l.outer_ptr = this;
+  l.inner_method();
+};
+lambda();
+  }
+
+  void non_capturing_method() {
+int local = 5;
+int local2 = 10;
+
+class_var += [=] {
+  std::puts("break here");
+  return local + local2;
+}();
+  }
+};
+
+int main() {
+  Foo f;
+  f.method();
+  f.non_capturing_method();
+  return global_var;
+}
Index: lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
@@ -0,0 +1,123 @@
+""" Test that evaluating expressions from within C++ lambdas works
+Particularly, we test the case of capturing "this" and
+using members of the captured object in expression evaluation
+while we're on a breakpoint inside a lambda.
+"""
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+
+class ExprInsideLambdaTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def expectExprError(self, expr : str, expected : str):
+frame = self.thread.GetFrameAtIndex(0)
+value = frame.EvaluateExpression(expr)
+errmsg = value.GetError().GetCString()
+self.assertIn(expected, errmsg)
+
+def test_expr_inside_lambda(self):
+"""Test that lldb evaluating expressions inside lambda expressions works correctly."""
+self.build()
+(target, process, self.thread, bkpt) = \
+lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.cpp"))
+
+# Inside 'Foo::method'
+
+# Check access to captured 'this'
+self.expect_expr("class_var", result_type="int", result_value="109")
+self.expect_expr("this->class_var", result_type="int", result_value="109")
+
+# Check that captured shadowed variables take preference over the
+# corresponding member variable
+self.expect_expr("shadowed", result_type="int

[Lldb-commits] [PATCH] D129078: WIP: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-04 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 442104.
Michael137 added a comment.

Correct email config


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/UserExpression.h
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp

Index: lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
@@ -0,0 +1,99 @@
+#include 
+#include 
+
+namespace {
+int global_var = -5;
+} // namespace
+
+struct Baz {
+  virtual ~Baz() = default;
+
+  virtual int baz_virt() = 0;
+
+  int base_base_var = 12;
+};
+
+struct Bar : public Baz {
+  virtual ~Bar() = default;
+
+  virtual int baz_virt() override {
+base_var = 10;
+return 1;
+  }
+
+  int base_var = 15;
+};
+
+struct Foo : public Bar {
+  int class_var = 9;
+  int shadowed = -137;
+  int *class_ptr;
+
+  virtual ~Foo() = default;
+
+  virtual int baz_virt() override {
+shadowed = -1;
+return 2;
+  }
+
+  void method() {
+int local_var = 137;
+int shadowed;
+class_ptr = &local_var;
+auto lambda = [&shadowed, this, &local_var,
+   local_var_copy = local_var]() mutable {
+  int lambda_local_var = 5;
+  shadowed = 5;
+  class_var = 109;
+  --base_var;
+  --base_base_var;
+  std::puts("break here");
+
+  auto nested_lambda = [this, &lambda_local_var] {
+std::puts("break here");
+lambda_local_var = 0;
+  };
+
+  nested_lambda();
+  --local_var_copy;
+  std::puts("break here");
+
+  struct LocalLambdaClass {
+int lambda_class_local = -12345;
+Foo *outer_ptr;
+
+void inner_method() {
+  auto lambda = [this] {
+std::puts("break here");
+lambda_class_local = -2;
+outer_ptr->class_var *= 2;
+  };
+
+  lambda();
+}
+  };
+
+  LocalLambdaClass l;
+  l.outer_ptr = this;
+  l.inner_method();
+};
+lambda();
+  }
+
+  void non_capturing_method() {
+int local = 5;
+int local2 = 10;
+
+class_var += [=] {
+  std::puts("break here");
+  return local + local2;
+}();
+  }
+};
+
+int main() {
+  Foo f;
+  f.method();
+  f.non_capturing_method();
+  return global_var;
+}
Index: lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
@@ -0,0 +1,123 @@
+""" Test that evaluating expressions from within C++ lambdas works
+Particularly, we test the case of capturing "this" and
+using members of the captured object in expression evaluation
+while we're on a breakpoint inside a lambda.
+"""
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+
+class ExprInsideLambdaTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def expectExprError(self, expr : str, expected : str):
+frame = self.thread.GetFrameAtIndex(0)
+value = frame.EvaluateExpression(expr)
+errmsg = value.GetError().GetCString()
+self.assertIn(expected, errmsg)
+
+def test_expr_inside_lambda(self):
+"""Test that lldb evaluating expressions inside lambda expressions works correctly."""
+self.build()
+(target, process, self.thread, bkpt) = \
+lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.cpp"))
+
+# Inside 'Foo::method'
+
+# Check access to captured 'this'
+self.expect_expr("class_var", result_type="int", result_value="109")
+self.expect_expr("this->class_var", result_type="int", result_value="109")
+
+# Check that captured shadowed variables take preference over the
+# corresponding member variable
+self.expect_expr("shadowed", result_type="int", result_value="5")
+self.expect_expr("this->shadowed", result_type="int", result_value="-137")
+
+# Check access to local captures
+self.expect_expr("local_var", result_type="int", result_value="1

[Lldb-commits] [PATCH] D129078: WIP: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-04 Thread Michael Buch via Phabricator via lldb-commits
Michael137 planned changes to this revision.
Michael137 added a comment.

Remove from review queue for now


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D81471: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-06 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added inline comments.



Comment at: 
lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp:249
   //
   // For Lvalues
   //

Minor: Should we update this documentation?



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:2689
+  // TODO: Support float/double static members as well.
+  if (!attrs.const_value_form && !ct.IsIntegerOrEnumerationType(unused))
+return;

Should this be:

```
if (!attrs.const_value_form || !ct.IsIntegerOrEnumerationType(unused))
```
?



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:2696
+   "Failed to add const value to variable {1}: {0}",
+   v->getQualifiedNameAsString());
+return;

Can `v` be `nullptr` here?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81471/new/

https://reviews.llvm.org/D81471

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129078: WIP: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-06 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 442525.
Michael137 added a comment.

- [LLDB][NFC] Create variable for hardcoded alignment/size constants in 
materializer
- [LLDB][Expression] Allow instantiation of IR Entity from ValueObject
- Removed redundant m_object_pointer_type


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp

Index: lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
@@ -0,0 +1,99 @@
+#include 
+#include 
+
+namespace {
+int global_var = -5;
+} // namespace
+
+struct Baz {
+  virtual ~Baz() = default;
+
+  virtual int baz_virt() = 0;
+
+  int base_base_var = 12;
+};
+
+struct Bar : public Baz {
+  virtual ~Bar() = default;
+
+  virtual int baz_virt() override {
+base_var = 10;
+return 1;
+  }
+
+  int base_var = 15;
+};
+
+struct Foo : public Bar {
+  int class_var = 9;
+  int shadowed = -137;
+  int *class_ptr;
+
+  virtual ~Foo() = default;
+
+  virtual int baz_virt() override {
+shadowed = -1;
+return 2;
+  }
+
+  void method() {
+int local_var = 137;
+int shadowed;
+class_ptr = &local_var;
+auto lambda = [&shadowed, this, &local_var,
+   local_var_copy = local_var]() mutable {
+  int lambda_local_var = 5;
+  shadowed = 5;
+  class_var = 109;
+  --base_var;
+  --base_base_var;
+  std::puts("break here");
+
+  auto nested_lambda = [this, &lambda_local_var] {
+std::puts("break here");
+lambda_local_var = 0;
+  };
+
+  nested_lambda();
+  --local_var_copy;
+  std::puts("break here");
+
+  struct LocalLambdaClass {
+int lambda_class_local = -12345;
+Foo *outer_ptr;
+
+void inner_method() {
+  auto lambda = [this] {
+std::puts("break here");
+lambda_class_local = -2;
+outer_ptr->class_var *= 2;
+  };
+
+  lambda();
+}
+  };
+
+  LocalLambdaClass l;
+  l.outer_ptr = this;
+  l.inner_method();
+};
+lambda();
+  }
+
+  void non_capturing_method() {
+int local = 5;
+int local2 = 10;
+
+class_var += [=] {
+  std::puts("break here");
+  return local + local2;
+}();
+  }
+};
+
+int main() {
+  Foo f;
+  f.method();
+  f.non_capturing_method();
+  return global_var;
+}
Index: lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
@@ -0,0 +1,123 @@
+""" Test that evaluating expressions from within C++ lambdas works
+Particularly, we test the case of capturing "this" and
+using members of the captured object in expression evaluation
+while we're on a breakpoint inside a lambda.
+"""
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+
+class ExprInsideLambdaTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def expectExprError(self, expr : str, expected : str):
+frame = self.thread.GetFrameAtIndex(0)
+value = frame.EvaluateExpression(expr)
+errmsg = value.GetError().GetCString()
+self.assertIn(expected, errmsg)
+
+def test_expr_inside_lambda(self):
+"""Test that lldb evaluating expressions inside lambda expressions works correctly."""
+self.build()
+(target, process, self.thread, bkpt) = \
+lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.cpp"))
+
+# Inside 'Foo::method'
+
+# Check access to captured 'this'
+self.expect_expr("class_var", result_type="int", result_value="109")
+self.expect_expr("this->class_var", result_type="int", result_value="109")
+
+# Check that captured shadowed variables take preference over the
+# corresponding member variable
+s

[Lldb-commits] [PATCH] D129078: WIP: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-06 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 442561.
Michael137 added a comment.

- Add `AddOneVariable` overload that takes `ValueObjectSP`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp

Index: lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
@@ -0,0 +1,99 @@
+#include 
+#include 
+
+namespace {
+int global_var = -5;
+} // namespace
+
+struct Baz {
+  virtual ~Baz() = default;
+
+  virtual int baz_virt() = 0;
+
+  int base_base_var = 12;
+};
+
+struct Bar : public Baz {
+  virtual ~Bar() = default;
+
+  virtual int baz_virt() override {
+base_var = 10;
+return 1;
+  }
+
+  int base_var = 15;
+};
+
+struct Foo : public Bar {
+  int class_var = 9;
+  int shadowed = -137;
+  int *class_ptr;
+
+  virtual ~Foo() = default;
+
+  virtual int baz_virt() override {
+shadowed = -1;
+return 2;
+  }
+
+  void method() {
+int local_var = 137;
+int shadowed;
+class_ptr = &local_var;
+auto lambda = [&shadowed, this, &local_var,
+   local_var_copy = local_var]() mutable {
+  int lambda_local_var = 5;
+  shadowed = 5;
+  class_var = 109;
+  --base_var;
+  --base_base_var;
+  std::puts("break here");
+
+  auto nested_lambda = [this, &lambda_local_var] {
+std::puts("break here");
+lambda_local_var = 0;
+  };
+
+  nested_lambda();
+  --local_var_copy;
+  std::puts("break here");
+
+  struct LocalLambdaClass {
+int lambda_class_local = -12345;
+Foo *outer_ptr;
+
+void inner_method() {
+  auto lambda = [this] {
+std::puts("break here");
+lambda_class_local = -2;
+outer_ptr->class_var *= 2;
+  };
+
+  lambda();
+}
+  };
+
+  LocalLambdaClass l;
+  l.outer_ptr = this;
+  l.inner_method();
+};
+lambda();
+  }
+
+  void non_capturing_method() {
+int local = 5;
+int local2 = 10;
+
+class_var += [=] {
+  std::puts("break here");
+  return local + local2;
+}();
+  }
+};
+
+int main() {
+  Foo f;
+  f.method();
+  f.non_capturing_method();
+  return global_var;
+}
Index: lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
@@ -0,0 +1,123 @@
+""" Test that evaluating expressions from within C++ lambdas works
+Particularly, we test the case of capturing "this" and
+using members of the captured object in expression evaluation
+while we're on a breakpoint inside a lambda.
+"""
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+
+class ExprInsideLambdaTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def expectExprError(self, expr : str, expected : str):
+frame = self.thread.GetFrameAtIndex(0)
+value = frame.EvaluateExpression(expr)
+errmsg = value.GetError().GetCString()
+self.assertIn(expected, errmsg)
+
+def test_expr_inside_lambda(self):
+"""Test that lldb evaluating expressions inside lambda expressions works correctly."""
+self.build()
+(target, process, self.thread, bkpt) = \
+lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.cpp"))
+
+# Inside 'Foo::method'
+
+# Check access to captured 'this'
+self.expect_expr("class_var", result_type="int", result_value="109")
+self.expect_expr("this->class_var", result_type="int", result_value="109")
+
+# Check that captured shadowed variables take preference over the
+# corresponding member variable
+self.expect_expr("shadowed", result_type="int", result_value="5")
+self.expect_expr("this->shadowed", result_type="int", result_value

[Lldb-commits] [PATCH] D129078: WIP: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-06 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 442563.
Michael137 added a comment.

- Fixed doc


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp

Index: lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
@@ -0,0 +1,99 @@
+#include 
+#include 
+
+namespace {
+int global_var = -5;
+} // namespace
+
+struct Baz {
+  virtual ~Baz() = default;
+
+  virtual int baz_virt() = 0;
+
+  int base_base_var = 12;
+};
+
+struct Bar : public Baz {
+  virtual ~Bar() = default;
+
+  virtual int baz_virt() override {
+base_var = 10;
+return 1;
+  }
+
+  int base_var = 15;
+};
+
+struct Foo : public Bar {
+  int class_var = 9;
+  int shadowed = -137;
+  int *class_ptr;
+
+  virtual ~Foo() = default;
+
+  virtual int baz_virt() override {
+shadowed = -1;
+return 2;
+  }
+
+  void method() {
+int local_var = 137;
+int shadowed;
+class_ptr = &local_var;
+auto lambda = [&shadowed, this, &local_var,
+   local_var_copy = local_var]() mutable {
+  int lambda_local_var = 5;
+  shadowed = 5;
+  class_var = 109;
+  --base_var;
+  --base_base_var;
+  std::puts("break here");
+
+  auto nested_lambda = [this, &lambda_local_var] {
+std::puts("break here");
+lambda_local_var = 0;
+  };
+
+  nested_lambda();
+  --local_var_copy;
+  std::puts("break here");
+
+  struct LocalLambdaClass {
+int lambda_class_local = -12345;
+Foo *outer_ptr;
+
+void inner_method() {
+  auto lambda = [this] {
+std::puts("break here");
+lambda_class_local = -2;
+outer_ptr->class_var *= 2;
+  };
+
+  lambda();
+}
+  };
+
+  LocalLambdaClass l;
+  l.outer_ptr = this;
+  l.inner_method();
+};
+lambda();
+  }
+
+  void non_capturing_method() {
+int local = 5;
+int local2 = 10;
+
+class_var += [=] {
+  std::puts("break here");
+  return local + local2;
+}();
+  }
+};
+
+int main() {
+  Foo f;
+  f.method();
+  f.non_capturing_method();
+  return global_var;
+}
Index: lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
@@ -0,0 +1,123 @@
+""" Test that evaluating expressions from within C++ lambdas works
+Particularly, we test the case of capturing "this" and
+using members of the captured object in expression evaluation
+while we're on a breakpoint inside a lambda.
+"""
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+
+class ExprInsideLambdaTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def expectExprError(self, expr : str, expected : str):
+frame = self.thread.GetFrameAtIndex(0)
+value = frame.EvaluateExpression(expr)
+errmsg = value.GetError().GetCString()
+self.assertIn(expected, errmsg)
+
+def test_expr_inside_lambda(self):
+"""Test that lldb evaluating expressions inside lambda expressions works correctly."""
+self.build()
+(target, process, self.thread, bkpt) = \
+lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.cpp"))
+
+# Inside 'Foo::method'
+
+# Check access to captured 'this'
+self.expect_expr("class_var", result_type="int", result_value="109")
+self.expect_expr("this->class_var", result_type="int", result_value="109")
+
+# Check that captured shadowed variables take preference over the
+# corresponding member variable
+self.expect_expr("shadowed", result_type="int", result_value="5")
+self.expect_expr("this->shadowed", result_type="int", result_value="-137")
+
+# Check access to local cap

[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-07 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added inline comments.



Comment at: lldb/source/Expression/Materializer.cpp:777
+  lldb::ValueObjectSP
+  GetValueObject(ExecutionContextScope *scope) const override {
+return ValueObjectVariable::Create(scope, m_variable_sp);

jingham wrote:
> Naively it seems like it would be a bad idea to call GetValueObject twice.  
> We don't want independent ValueObjectVariable shared pointers floating around 
> for the same Entity.  Should this maybe do an `if (!m_variable_sp)` first?
`m_variable_sp` is used here to create a new `ValueObjectVariable`. It's a 
precondition that `m_variable_sp != nullptr` (will add that to the function 
documentation). I could add a `m_value_object_var` member that we set if it 
hasn't been set before.



Comment at: lldb/source/Expression/Materializer.cpp:819
+
+  bool LocationExpressionIsValid() const override { return true; }
+

jingham wrote:
> Is this right?  For instance, in the case where the fake "this" Variable in 
> the lambda expression has an invalid expression, all the ValueObjects you try 
> to make (the "real captured this" as well as any other captures that were 
> hanging off the fake "this" would have invalid location expressions.
If the location expression is invalid for the fake "this", would we ever be 
able to get ValueObject's out of it? By the time these Entity objects get 
instantiated we either managed to get ValueObject's from "this" or if we 
didn't, then we wouldn't have added them to the `$__lldb_local_vars` namespace



Comment at: 
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp:1725
+
+  if (ClangExpressionVariable::ParserVars *parser_vars =
+  AddExpressionVariable(context, pt, ut, std::move(valobj))) {

jingham wrote:
> Is there enough advantage to move-ing the incoming valobj as opposed to just 
> copying the shared pointer?  It's a little weird to have API's that consume 
> one of their incoming arguments.  If that really is worth doing, you should 
> note that you've done that.
Not particularly, don't imagine there's a measurable difference. A copy isn't 
necessary so I was trying to avoid it. I guess a clearer way would be to just 
not pass the shared_ptr around, and instead a `ValueObject const&`



Comment at: 
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp:227
+
+  if (auto thisValSP = GetLambdaValueObject(frame)) {
+uint32_t numChildren = thisValSP->GetNumChildren();

jingham wrote:
> It's worth noting that you handle lambda's that capture "this" and lambda's 
> that don't capture "this" differently.  In the former case, we promote all 
> the captures to local variables and ignore the fake this.  In the latter case 
> (because GetLambdaValueObject only returns a valid ValueObjectSP if it has a 
> child called "this"), we keep finding the values by implicit lookup in the 
> fake this instead.
> 
> I don't think that a problem, no need to use the more complex method just for 
> consistency, but you should note that somewhere.
Good point, will add a comment



Comment at: lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h:202
+
+  lldb::addr_t GetCppObjectPointer(StackFrame *frame, ConstString &object_name,
+   Status &err);

jingham wrote:
> Why did you make this take a StackFrame *?  It seems to force some other 
> functions to change from StackFrameSP to StackFrame * but the only place it 
> gets called it has a StackFrameSP, and explicitly calls get to make it a 
> pointer.  That seems awkward.
Was simply trying to avoid a shared_ptr copy where it wasn't necessary. 
Arguably the `GetObjectPointer` API should just take a `StackFrame const&`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-07 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 442954.
Michael137 added a comment.
Herald added a subscriber: mgorny.

- Add more documentation
- Moved `GetLambdaValueObject` into common utility header
- Added defensive check to `EntityVariable::GetValueObject`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp

Index: lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
@@ -0,0 +1,99 @@
+#include 
+#include 
+
+namespace {
+int global_var = -5;
+} // namespace
+
+struct Baz {
+  virtual ~Baz() = default;
+
+  virtual int baz_virt() = 0;
+
+  int base_base_var = 12;
+};
+
+struct Bar : public Baz {
+  virtual ~Bar() = default;
+
+  virtual int baz_virt() override {
+base_var = 10;
+return 1;
+  }
+
+  int base_var = 15;
+};
+
+struct Foo : public Bar {
+  int class_var = 9;
+  int shadowed = -137;
+  int *class_ptr;
+
+  virtual ~Foo() = default;
+
+  virtual int baz_virt() override {
+shadowed = -1;
+return 2;
+  }
+
+  void method() {
+int local_var = 137;
+int shadowed;
+class_ptr = &local_var;
+auto lambda = [&shadowed, this, &local_var,
+   local_var_copy = local_var]() mutable {
+  int lambda_local_var = 5;
+  shadowed = 5;
+  class_var = 109;
+  --base_var;
+  --base_base_var;
+  std::puts("break here");
+
+  auto nested_lambda = [this, &lambda_local_var] {
+std::puts("break here");
+lambda_local_var = 0;
+  };
+
+  nested_lambda();
+  --local_var_copy;
+  std::puts("break here");
+
+  struct LocalLambdaClass {
+int lambda_class_local = -12345;
+Foo *outer_ptr;
+
+void inner_method() {
+  auto lambda = [this] {
+std::puts("break here");
+lambda_class_local = -2;
+outer_ptr->class_var *= 2;
+  };
+
+  lambda();
+}
+  };
+
+  LocalLambdaClass l;
+  l.outer_ptr = this;
+  l.inner_method();
+};
+lambda();
+  }
+
+  void non_capturing_method() {
+int local = 5;
+int local2 = 10;
+
+class_var += [=] {
+  std::puts("break here");
+  return local + local2;
+}();
+  }
+};
+
+int main() {
+  Foo f;
+  f.method();
+  f.non_capturing_method();
+  return global_var;
+}
Index: lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
@@ -0,0 +1,123 @@
+""" Test that evaluating expressions from within C++ lambdas works
+Particularly, we test the case of capturing "this" and
+using members of the captured object in expression evaluation
+while we're on a breakpoint inside a lambda.
+"""
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+
+class ExprInsideLambdaTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def expectExprError(self, expr : str, expected : str):
+frame = self.thread.GetFrameAtIndex(0)
+value = frame.EvaluateExpression(expr)
+errmsg = value.GetError().GetCString()
+self.assertIn(expected, errmsg)
+
+def test_expr_inside_lambda(self):
+"""Test that lldb evaluating expressions inside lambda expressions works correctly."""
+self.build()
+(target, process, self.thread, bkpt) = \
+lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.cpp"))
+
+# Inside 'Foo::method'
+
+# Check access to captured 'this'
+self.expect_expr("class_var", result_type="int", result_value="109")
+self.expect_expr("this->clas

[Lldb-commits] [PATCH] D129364: [LLDB][DataFormatter] Add data formatter for libcxx std::unordered_map iterator

2022-07-08 Thread Michael Buch via Phabricator via lldb-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, jingham.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This patch adds a formatter for libcxx's `std::unordered_map` iterators.
The implementation follows a similar appraoch to the `std::map` iterator
formatter. I was hesistant about coupling the two into a common
implementation since the libcxx layouts might change for one of the
the containers but not the other.

All `std::unordered_map` iterators are covered with this patch:

1. const/non-const key/value iterators
2. const/non-const bucket iterators

Note that, we currently don't have a formatter for `std::unordered_map`.
This patch doesn't change that, we merely add support for its iterators,
because that's what Xcode users requested. One can still see contents
of `std::unordered_map`, whereas with iterators it's less ergonomic.

**Testing**

- Added API test


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129364

Files:
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
@@ -0,0 +1,28 @@
+#include 
+#include 
+#include 
+
+using StringMapT = std::unordered_map;
+
+int main() {
+  StringMapT string_map;
+  {
+auto empty_iter = string_map.begin();
+auto const_empty_iter = string_map.cbegin();
+std::printf("Break here");
+  }
+  string_map["Foo"] = "Bar";
+  string_map["Baz"] = "Qux";
+
+  {
+auto foo = string_map.find("Foo");
+auto invalid = string_map.find("Invalid");
+
+StringMapT::const_iterator const_baz = string_map.find("Baz");
+auto bucket_it = string_map.begin(string_map.bucket("Baz"));
+auto const_bucket_it = string_map.cbegin(string_map.bucket("Baz"));
+std::printf("Break here");
+  }
+
+  return 0;
+}
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
@@ -0,0 +1,53 @@
+"""
+Test formatting of std::unordered_map related structures.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class LibcxxUnorderedMapDataFormatterTestCase(TestBase):
+
+@add_test_categories(['libc++'])
+def test_with_run_command(self):
+"""Test that std::unordered_map related structures are formatted correctly when printed.
+   Currently only tests format of std::unordered_map iterators.
+"""
+self.build()
+(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+self, 'Break here', lldb.SBFileSpec('main.cpp', False))
+
+# Test empty iterators
+self.expect_expr('empty_iter', '')
+self.expect_expr('const_empty_iter', '')
+
+lldbutil.continue_to_breakpoint(process, bkpt)
+
+# Check that key/value is correctly formatted
+self.expect_expr('foo', result_children=[
+ ValueCheck(name='first', summary='"Foo"'),
+ ValueCheck(name='second', summary='"Bar"')
+])
+
+# Check invalid iterator is empty
+self.expect_expr('invalid', '')
+
+# Const key/val iterator
+self.expect_expr('const_baz', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
+
+# Bucket iterators
+# I.e., std::__hash_map_const_iterator>
+# and std::__hash_map_iterator>
+self.expect_expr('bucket_it', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
+
+self.expect_expr('bucket_it', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
==

[Lldb-commits] [PATCH] D129364: [LLDB][DataFormatter] Add data formatter for libcxx std::unordered_map iterator

2022-07-08 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 443212.
Michael137 added a comment.

- Fixed class documentation


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129364/new/

https://reviews.llvm.org/D129364

Files:
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
@@ -0,0 +1,28 @@
+#include 
+#include 
+#include 
+
+using StringMapT = std::unordered_map;
+
+int main() {
+  StringMapT string_map;
+  {
+auto empty_iter = string_map.begin();
+auto const_empty_iter = string_map.cbegin();
+std::printf("Break here");
+  }
+  string_map["Foo"] = "Bar";
+  string_map["Baz"] = "Qux";
+
+  {
+auto foo = string_map.find("Foo");
+auto invalid = string_map.find("Invalid");
+
+StringMapT::const_iterator const_baz = string_map.find("Baz");
+auto bucket_it = string_map.begin(string_map.bucket("Baz"));
+auto const_bucket_it = string_map.cbegin(string_map.bucket("Baz"));
+std::printf("Break here");
+  }
+
+  return 0;
+}
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
@@ -0,0 +1,53 @@
+"""
+Test formatting of std::unordered_map related structures.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class LibcxxUnorderedMapDataFormatterTestCase(TestBase):
+
+@add_test_categories(['libc++'])
+def test_with_run_command(self):
+"""Test that std::unordered_map related structures are formatted correctly when printed.
+   Currently only tests format of std::unordered_map iterators.
+"""
+self.build()
+(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+self, 'Break here', lldb.SBFileSpec('main.cpp', False))
+
+# Test empty iterators
+self.expect_expr('empty_iter', '')
+self.expect_expr('const_empty_iter', '')
+
+lldbutil.continue_to_breakpoint(process, bkpt)
+
+# Check that key/value is correctly formatted
+self.expect_expr('foo', result_children=[
+ ValueCheck(name='first', summary='"Foo"'),
+ ValueCheck(name='second', summary='"Bar"')
+])
+
+# Check invalid iterator is empty
+self.expect_expr('invalid', '')
+
+# Const key/val iterator
+self.expect_expr('const_baz', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
+
+# Bucket iterators
+# I.e., std::__hash_map_const_iterator>
+# and std::__hash_map_iterator>
+self.expect_expr('bucket_it', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
+
+self.expect_expr('bucket_it', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
@@ -0,0 +1,6 @@
+CXX_SOURCES := main.cpp
+
+USE_LIBCPP := 1
+
+CXXFLAGS_EXTRAS := -O0
+include Makefile.rules
Index: lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
===
--- lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
+++ lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
@@ -103,6 +103,56 @@
 LibCxxMapIteratorSyntheticFrontEndCreator(CXXSyntheticChildren *,
   lldb::ValueObjectSP);
 
+/// Formats libcxx's std::unordered_map iterators
+///
+/// In raw form a std::unordered_map::iterator is represented as follows:
+///
+/// (lldb) var it --raw --ptr-depth 1
+/// (std::__1::__hash_map_

[Lldb-commits] [PATCH] D129367: [LLDB][ClangExpression] Remove unused StructVars::m_object_pointer_type

2022-07-08 Thread Michael Buch via Phabricator via lldb-commits
Michael137 created this revision.
Michael137 added reviewers: jingham, aprantl.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This member variable was removed a while ago in
443427357f539f5ac97e664a53aa9e50788abce9. It was previously used in
materialization code paths that have since been removed. Nowadays,
`m_object_pointer_type` gets set but not used anywhere.

This patch simply removes all remaining instances of it and any
supporting code.

**Testing**

- API tests pass


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129367

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h

Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
@@ -353,7 +353,7 @@
   /// The following values contain layout information for the materialized
   /// struct, but are not specific to a single materialization
   struct StructVars {
-StructVars() : m_result_name(), m_object_pointer_type(nullptr, nullptr) {}
+StructVars() : m_result_name() {}
 
 lldb::offset_t m_struct_alignment =
 0;///< The alignment of the struct in bytes.
@@ -364,8 +364,6 @@
/// added since).
 ConstString
 m_result_name; ///< The name of the result variable ($1, for example)
-TypeFromUser m_object_pointer_type; ///< The type of the "this" variable, if
-///one exists
   };
 
   std::unique_ptr m_struct_vars;
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -772,10 +772,6 @@
   return;
 
 AddContextClassType(context, TypeFromUser(m_ctx_obj->GetCompilerType()));
-
-m_struct_vars->m_object_pointer_type =
-TypeFromUser(ctx_obj_ptr->GetCompilerType());
-
 return;
   }
 
@@ -810,18 +806,6 @@
  class_qual_type.getAsString());
 
 AddContextClassType(context, class_user_type);
-
-if (method_decl->isInstance()) {
-  // self is a pointer to the object
-
-  QualType class_pointer_type =
-  method_decl->getASTContext().getPointerType(class_qual_type);
-
-  TypeFromUser self_user_type(class_pointer_type.getAsOpaquePtr(),
-  function_decl_ctx.GetTypeSystem());
-
-  m_struct_vars->m_object_pointer_type = self_user_type;
-}
 return;
   }
 
@@ -852,8 +836,6 @@
  ClangUtil::GetQualType(pointee_type).getAsString());
 
 AddContextClassType(context, pointee_type);
-TypeFromUser this_user_type(this_type->GetFullCompilerType());
-m_struct_vars->m_object_pointer_type = this_user_type;
   }
 }
 
@@ -869,10 +851,6 @@
   return;
 
 AddOneType(context, TypeFromUser(m_ctx_obj->GetCompilerType()));
-
-m_struct_vars->m_object_pointer_type =
-TypeFromUser(ctx_obj_ptr->GetCompilerType());
-
 return;
   }
 
@@ -917,28 +895,6 @@
  ClangUtil::ToString(interface_type));
 
 AddOneType(context, class_user_type);
-
-if (method_decl->isInstanceMethod()) {
-  // self is a pointer to the object
-
-  QualType class_pointer_type =
-  method_decl->getASTContext().getObjCObjectPointerType(
-  QualType(interface_type, 0));
-
-  TypeFromUser self_user_type(class_pointer_type.getAsOpaquePtr(),
-  function_decl_ctx.GetTypeSystem());
-
-  m_struct_vars->m_object_pointer_type = self_user_type;
-} else {
-  // self is a Class pointer
-  QualType class_type = method_decl->getASTContext().getObjCClassType();
-
-  TypeFromUser self_user_type(class_type.getAsOpaquePtr(),
-  function_decl_ctx.GetTypeSystem());
-
-  m_struct_vars->m_object_pointer_type = self_user_type;
-}
-
 return;
   }
   // This branch will get hit if we are executing code in the context of
@@ -981,10 +937,6 @@
   TypeFromUser class_user_type(self_clang_type);
 
   AddOneType(context, class_user_type);
-
-  TypeFromUser self_user_type(self_type->GetFullCompilerType());
-
-  m_struct_vars->m_object_pointer_type = self_user_type;
 }
 
 void ClangExpressionDeclMap::LookupLocalVarNamespace(
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129367: [LLDB][ClangExpression] Remove unused StructVars::m_object_pointer_type

2022-07-08 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

One potential functional change here would be the removal of 
`GetFullCompilerType` in the `$__lldb_objc_class` code path. Could probably 
just put it back since it's not immediately obvious how I'd test it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129367/new/

https://reviews.llvm.org/D129367

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129364: [LLDB][DataFormatter] Add data formatter for libcxx std::unordered_map iterator

2022-07-08 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 443227.
Michael137 added a comment.

- Cleaned up documentation further


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129364/new/

https://reviews.llvm.org/D129364

Files:
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
@@ -0,0 +1,28 @@
+#include 
+#include 
+#include 
+
+using StringMapT = std::unordered_map;
+
+int main() {
+  StringMapT string_map;
+  {
+auto empty_iter = string_map.begin();
+auto const_empty_iter = string_map.cbegin();
+std::printf("Break here");
+  }
+  string_map["Foo"] = "Bar";
+  string_map["Baz"] = "Qux";
+
+  {
+auto foo = string_map.find("Foo");
+auto invalid = string_map.find("Invalid");
+
+StringMapT::const_iterator const_baz = string_map.find("Baz");
+auto bucket_it = string_map.begin(string_map.bucket("Baz"));
+auto const_bucket_it = string_map.cbegin(string_map.bucket("Baz"));
+std::printf("Break here");
+  }
+
+  return 0;
+}
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
@@ -0,0 +1,53 @@
+"""
+Test formatting of std::unordered_map related structures.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class LibcxxUnorderedMapDataFormatterTestCase(TestBase):
+
+@add_test_categories(['libc++'])
+def test_with_run_command(self):
+"""Test that std::unordered_map related structures are formatted correctly when printed.
+   Currently only tests format of std::unordered_map iterators.
+"""
+self.build()
+(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+self, 'Break here', lldb.SBFileSpec('main.cpp', False))
+
+# Test empty iterators
+self.expect_expr('empty_iter', '')
+self.expect_expr('const_empty_iter', '')
+
+lldbutil.continue_to_breakpoint(process, bkpt)
+
+# Check that key/value is correctly formatted
+self.expect_expr('foo', result_children=[
+ ValueCheck(name='first', summary='"Foo"'),
+ ValueCheck(name='second', summary='"Bar"')
+])
+
+# Check invalid iterator is empty
+self.expect_expr('invalid', '')
+
+# Const key/val iterator
+self.expect_expr('const_baz', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
+
+# Bucket iterators
+# I.e., std::__hash_map_const_iterator>
+# and std::__hash_map_iterator>
+self.expect_expr('bucket_it', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
+
+self.expect_expr('bucket_it', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
@@ -0,0 +1,6 @@
+CXX_SOURCES := main.cpp
+
+USE_LIBCPP := 1
+
+CXXFLAGS_EXTRAS := -O0
+include Makefile.rules
Index: lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
===
--- lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
+++ lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
@@ -103,6 +103,56 @@
 LibCxxMapIteratorSyntheticFrontEndCreator(CXXSyntheticChildren *,
   lldb::ValueObjectSP);
 
+/// Formats libcxx's std::unordered_map iterators
+///
+/// In raw form a std::unordered_map::iterator is represented as follows:
+///
+/// (lldb) var it --raw --ptr-depth 1
+/// (std::__1::__ha

[Lldb-commits] [PATCH] D129364: [LLDB][DataFormatter] Add data formatter for libcxx std::unordered_map iterator

2022-07-09 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 443430.
Michael137 added a comment.

- Fixed test case for const bucket iterator


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129364/new/

https://reviews.llvm.org/D129364

Files:
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
@@ -0,0 +1,28 @@
+#include 
+#include 
+#include 
+
+using StringMapT = std::unordered_map;
+
+int main() {
+  StringMapT string_map;
+  {
+auto empty_iter = string_map.begin();
+auto const_empty_iter = string_map.cbegin();
+std::printf("Break here");
+  }
+  string_map["Foo"] = "Bar";
+  string_map["Baz"] = "Qux";
+
+  {
+auto foo = string_map.find("Foo");
+auto invalid = string_map.find("Invalid");
+
+StringMapT::const_iterator const_baz = string_map.find("Baz");
+auto bucket_it = string_map.begin(string_map.bucket("Baz"));
+auto const_bucket_it = string_map.cbegin(string_map.bucket("Baz"));
+std::printf("Break here");
+  }
+
+  return 0;
+}
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
@@ -0,0 +1,53 @@
+"""
+Test formatting of std::unordered_map related structures.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class LibcxxUnorderedMapDataFormatterTestCase(TestBase):
+
+@add_test_categories(['libc++'])
+def test_with_run_command(self):
+"""Test that std::unordered_map related structures are formatted correctly when printed.
+   Currently only tests format of std::unordered_map iterators.
+"""
+self.build()
+(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+self, 'Break here', lldb.SBFileSpec('main.cpp', False))
+
+# Test empty iterators
+self.expect_expr('empty_iter', '')
+self.expect_expr('const_empty_iter', '')
+
+lldbutil.continue_to_breakpoint(process, bkpt)
+
+# Check that key/value is correctly formatted
+self.expect_expr('foo', result_children=[
+ ValueCheck(name='first', summary='"Foo"'),
+ ValueCheck(name='second', summary='"Bar"')
+])
+
+# Check invalid iterator is empty
+self.expect_expr('invalid', '')
+
+# Const key/val iterator
+self.expect_expr('const_baz', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
+
+# Bucket iterators
+# I.e., std::__hash_map_const_iterator>
+# and std::__hash_map_iterator>
+self.expect_expr('bucket_it', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
+
+self.expect_expr('const_bucket_it', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
@@ -0,0 +1,6 @@
+CXX_SOURCES := main.cpp
+
+USE_LIBCPP := 1
+
+CXXFLAGS_EXTRAS := -O0
+include Makefile.rules
Index: lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
===
--- lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
+++ lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
@@ -103,6 +103,56 @@
 LibCxxMapIteratorSyntheticFrontEndCreator(CXXSyntheticChildren *,
   lldb::ValueObjectSP);
 
+/// Formats libcxx's std::unordered_map iterators
+///
+/// In raw form a std::unordered_map::iterator is represented as follows:
+///
+/// (lldb) var it --raw --ptr-depth 1
+/// 

[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-11 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 443574.
Michael137 added a comment.

- Move helper into new namespace


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp

Index: lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
@@ -0,0 +1,99 @@
+#include 
+#include 
+
+namespace {
+int global_var = -5;
+} // namespace
+
+struct Baz {
+  virtual ~Baz() = default;
+
+  virtual int baz_virt() = 0;
+
+  int base_base_var = 12;
+};
+
+struct Bar : public Baz {
+  virtual ~Bar() = default;
+
+  virtual int baz_virt() override {
+base_var = 10;
+return 1;
+  }
+
+  int base_var = 15;
+};
+
+struct Foo : public Bar {
+  int class_var = 9;
+  int shadowed = -137;
+  int *class_ptr;
+
+  virtual ~Foo() = default;
+
+  virtual int baz_virt() override {
+shadowed = -1;
+return 2;
+  }
+
+  void method() {
+int local_var = 137;
+int shadowed;
+class_ptr = &local_var;
+auto lambda = [&shadowed, this, &local_var,
+   local_var_copy = local_var]() mutable {
+  int lambda_local_var = 5;
+  shadowed = 5;
+  class_var = 109;
+  --base_var;
+  --base_base_var;
+  std::puts("break here");
+
+  auto nested_lambda = [this, &lambda_local_var] {
+std::puts("break here");
+lambda_local_var = 0;
+  };
+
+  nested_lambda();
+  --local_var_copy;
+  std::puts("break here");
+
+  struct LocalLambdaClass {
+int lambda_class_local = -12345;
+Foo *outer_ptr;
+
+void inner_method() {
+  auto lambda = [this] {
+std::puts("break here");
+lambda_class_local = -2;
+outer_ptr->class_var *= 2;
+  };
+
+  lambda();
+}
+  };
+
+  LocalLambdaClass l;
+  l.outer_ptr = this;
+  l.inner_method();
+};
+lambda();
+  }
+
+  void non_capturing_method() {
+int local = 5;
+int local2 = 10;
+
+class_var += [=] {
+  std::puts("break here");
+  return local + local2;
+}();
+  }
+};
+
+int main() {
+  Foo f;
+  f.method();
+  f.non_capturing_method();
+  return global_var;
+}
Index: lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
@@ -0,0 +1,123 @@
+""" Test that evaluating expressions from within C++ lambdas works
+Particularly, we test the case of capturing "this" and
+using members of the captured object in expression evaluation
+while we're on a breakpoint inside a lambda.
+"""
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+
+class ExprInsideLambdaTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def expectExprError(self, expr : str, expected : str):
+frame = self.thread.GetFrameAtIndex(0)
+value = frame.EvaluateExpression(expr)
+errmsg = value.GetError().GetCString()
+self.assertIn(expected, errmsg)
+
+def test_expr_inside_lambda(self):
+"""Test that lldb evaluating expressions inside lambda expressions works correctly."""
+self.build()
+(target, process, self.thread, bkpt) = \
+lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.cpp"))
+
+# Inside 'Foo::method'
+
+# Check access to captured 'this'
+self.expect_expr("class_var", result_type="int", result_value="109")
+self.expect_expr("this->class_var", result_type="int", result_value="109")
+
+# Check that captured shadowed variables take preference over the
+# correspond

[Lldb-commits] [PATCH] D81471: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-11 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

with latest changes LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81471/new/

https://reviews.llvm.org/D81471

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-11 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 443707.
Michael137 marked 9 inline comments as done.
Michael137 added a comment.

- Address stylistic/documentation comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp

Index: lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
@@ -0,0 +1,99 @@
+#include 
+#include 
+
+namespace {
+int global_var = -5;
+} // namespace
+
+struct Baz {
+  virtual ~Baz() = default;
+
+  virtual int baz_virt() = 0;
+
+  int base_base_var = 12;
+};
+
+struct Bar : public Baz {
+  virtual ~Bar() = default;
+
+  virtual int baz_virt() override {
+base_var = 10;
+return 1;
+  }
+
+  int base_var = 15;
+};
+
+struct Foo : public Bar {
+  int class_var = 9;
+  int shadowed = -137;
+  int *class_ptr;
+
+  virtual ~Foo() = default;
+
+  virtual int baz_virt() override {
+shadowed = -1;
+return 2;
+  }
+
+  void method() {
+int local_var = 137;
+int shadowed;
+class_ptr = &local_var;
+auto lambda = [&shadowed, this, &local_var,
+   local_var_copy = local_var]() mutable {
+  int lambda_local_var = 5;
+  shadowed = 5;
+  class_var = 109;
+  --base_var;
+  --base_base_var;
+  std::puts("break here");
+
+  auto nested_lambda = [this, &lambda_local_var] {
+std::puts("break here");
+lambda_local_var = 0;
+  };
+
+  nested_lambda();
+  --local_var_copy;
+  std::puts("break here");
+
+  struct LocalLambdaClass {
+int lambda_class_local = -12345;
+Foo *outer_ptr;
+
+void inner_method() {
+  auto lambda = [this] {
+std::puts("break here");
+lambda_class_local = -2;
+outer_ptr->class_var *= 2;
+  };
+
+  lambda();
+}
+  };
+
+  LocalLambdaClass l;
+  l.outer_ptr = this;
+  l.inner_method();
+};
+lambda();
+  }
+
+  void non_capturing_method() {
+int local = 5;
+int local2 = 10;
+
+class_var += [=] {
+  std::puts("break here");
+  return local + local2;
+}();
+  }
+};
+
+int main() {
+  Foo f;
+  f.method();
+  f.non_capturing_method();
+  return global_var;
+}
Index: lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
@@ -0,0 +1,123 @@
+""" Test that evaluating expressions from within C++ lambdas works
+Particularly, we test the case of capturing "this" and
+using members of the captured object in expression evaluation
+while we're on a breakpoint inside a lambda.
+"""
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+
+class ExprInsideLambdaTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def expectExprError(self, expr : str, expected : str):
+frame = self.thread.GetFrameAtIndex(0)
+value = frame.EvaluateExpression(expr)
+errmsg = value.GetError().GetCString()
+self.assertIn(expected, errmsg)
+
+def test_expr_inside_lambda(self):
+"""Test that lldb evaluating expressions inside lambda expressions works correctly."""
+self.build()
+(target, process, self.thread, bkpt) = \
+lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.cpp"))
+
+# Inside 'Foo::method'
+
+# Check access to captured 'this'
+self.expect_expr("class_var", result_type="int", result_value="109")
+self.expect_expr("this->class_var", result_type="int", result_value="109")
+
+# Check that captured shadowed v

[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-11 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added inline comments.



Comment at: lldb/source/Expression/Materializer.cpp:432
+m_size = g_default_var_byte_size;
+m_alignment = g_default_var_alignment;
   }

aprantl wrote:
> FWIW, the refactoring of EntityVariable could have been a separate 
> preparatory NFC patch, then the patch that adds the lambda functionality 
> would be shorter. It's fine either way, but it's usually easier to review two 
> simple comments instead of one complex one :-)
True
I added it as a separate commit to this revision. Wasn't sure whether a 
separate patch was preferred over a separate commit in the same Phabricator 
revision.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-12 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 443861.
Michael137 added a comment.

- `LocationExpressionIsValid` returns false for invalid ValueObjects
- Add asserts to `EntityValueObject` overrides
- Add docs for `AddValueObject`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp

Index: lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
@@ -0,0 +1,99 @@
+#include 
+#include 
+
+namespace {
+int global_var = -5;
+} // namespace
+
+struct Baz {
+  virtual ~Baz() = default;
+
+  virtual int baz_virt() = 0;
+
+  int base_base_var = 12;
+};
+
+struct Bar : public Baz {
+  virtual ~Bar() = default;
+
+  virtual int baz_virt() override {
+base_var = 10;
+return 1;
+  }
+
+  int base_var = 15;
+};
+
+struct Foo : public Bar {
+  int class_var = 9;
+  int shadowed = -137;
+  int *class_ptr;
+
+  virtual ~Foo() = default;
+
+  virtual int baz_virt() override {
+shadowed = -1;
+return 2;
+  }
+
+  void method() {
+int local_var = 137;
+int shadowed;
+class_ptr = &local_var;
+auto lambda = [&shadowed, this, &local_var,
+   local_var_copy = local_var]() mutable {
+  int lambda_local_var = 5;
+  shadowed = 5;
+  class_var = 109;
+  --base_var;
+  --base_base_var;
+  std::puts("break here");
+
+  auto nested_lambda = [this, &lambda_local_var] {
+std::puts("break here");
+lambda_local_var = 0;
+  };
+
+  nested_lambda();
+  --local_var_copy;
+  std::puts("break here");
+
+  struct LocalLambdaClass {
+int lambda_class_local = -12345;
+Foo *outer_ptr;
+
+void inner_method() {
+  auto lambda = [this] {
+std::puts("break here");
+lambda_class_local = -2;
+outer_ptr->class_var *= 2;
+  };
+
+  lambda();
+}
+  };
+
+  LocalLambdaClass l;
+  l.outer_ptr = this;
+  l.inner_method();
+};
+lambda();
+  }
+
+  void non_capturing_method() {
+int local = 5;
+int local2 = 10;
+
+class_var += [=] {
+  std::puts("break here");
+  return local + local2;
+}();
+  }
+};
+
+int main() {
+  Foo f;
+  f.method();
+  f.non_capturing_method();
+  return global_var;
+}
Index: lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
@@ -0,0 +1,123 @@
+""" Test that evaluating expressions from within C++ lambdas works
+Particularly, we test the case of capturing "this" and
+using members of the captured object in expression evaluation
+while we're on a breakpoint inside a lambda.
+"""
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+
+class ExprInsideLambdaTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def expectExprError(self, expr : str, expected : str):
+frame = self.thread.GetFrameAtIndex(0)
+value = frame.EvaluateExpression(expr)
+errmsg = value.GetError().GetCString()
+self.assertIn(expected, errmsg)
+
+def test_expr_inside_lambda(self):
+"""Test that lldb evaluating expressions inside lambda expressions works correctly."""
+self.build()
+(target, process, self.thread, bkpt) = \
+lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.cpp"))
+
+# Inside 'Foo::method'
+
+# Check access to captured 'this'
+self.expect_expr("class_var", result_type="int", result_value="109")
+self.expect_expr("this->class_var", result_type="int", res

[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-12 Thread Michael Buch via Phabricator via lldb-commits
Michael137 marked an inline comment as done.
Michael137 added inline comments.



Comment at: lldb/source/Expression/Materializer.cpp:819
+
+  bool LocationExpressionIsValid() const override { return true; }
+

Michael137 wrote:
> jingham wrote:
> > Is this right?  For instance, in the case where the fake "this" Variable in 
> > the lambda expression has an invalid expression, all the ValueObjects you 
> > try to make (the "real captured this" as well as any other captures that 
> > were hanging off the fake "this" would have invalid location expressions.
> If the location expression is invalid for the fake "this", would we ever be 
> able to get ValueObject's out of it? By the time these Entity objects get 
> instantiated we either managed to get ValueObject's from "this" or if we 
> didn't, then we wouldn't have added them to the `$__lldb_local_vars` namespace
Added a check for ValueObject's error status here.

Manual testing shows we'd catch lack of variable location earlier in 
materialisation


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129364: [LLDB][DataFormatter] Add data formatter for libcxx std::unordered_map iterator

2022-07-12 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 443867.
Michael137 marked 3 inline comments as done.
Michael137 added a comment.

- Address stylistic comments
- Change test name


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129364/new/

https://reviews.llvm.org/D129364

Files:
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
@@ -0,0 +1,28 @@
+#include 
+#include 
+#include 
+
+using StringMapT = std::unordered_map;
+
+int main() {
+  StringMapT string_map;
+  {
+auto empty_iter = string_map.begin();
+auto const_empty_iter = string_map.cbegin();
+std::printf("Break here");
+  }
+  string_map["Foo"] = "Bar";
+  string_map["Baz"] = "Qux";
+
+  {
+auto foo = string_map.find("Foo");
+auto invalid = string_map.find("Invalid");
+
+StringMapT::const_iterator const_baz = string_map.find("Baz");
+auto bucket_it = string_map.begin(string_map.bucket("Baz"));
+auto const_bucket_it = string_map.cbegin(string_map.bucket("Baz"));
+std::printf("Break here");
+  }
+
+  return 0;
+}
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
@@ -0,0 +1,53 @@
+"""
+Test formatting of std::unordered_map related structures.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class LibcxxUnorderedMapDataFormatterTestCase(TestBase):
+
+@add_test_categories(['libc++'])
+def test_iterator_formatters(self):
+"""Test that std::unordered_map related structures are formatted correctly when printed.
+   Currently only tests format of std::unordered_map iterators.
+"""
+self.build()
+(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+self, 'Break here', lldb.SBFileSpec('main.cpp', False))
+
+# Test empty iterators
+self.expect_expr('empty_iter', '')
+self.expect_expr('const_empty_iter', '')
+
+lldbutil.continue_to_breakpoint(process, bkpt)
+
+# Check that key/value is correctly formatted
+self.expect_expr('foo', result_children=[
+ ValueCheck(name='first', summary='"Foo"'),
+ ValueCheck(name='second', summary='"Bar"')
+])
+
+# Check invalid iterator is empty
+self.expect_expr('invalid', '')
+
+# Const key/val iterator
+self.expect_expr('const_baz', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
+
+# Bucket iterators
+# I.e., std::__hash_map_const_iterator>
+# and std::__hash_map_iterator>
+self.expect_expr('bucket_it', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
+
+self.expect_expr('const_bucket_it', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
@@ -0,0 +1,6 @@
+CXX_SOURCES := main.cpp
+
+USE_LIBCPP := 1
+
+CXXFLAGS_EXTRAS := -O0
+include Makefile.rules
Index: lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
===
--- lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
+++ lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
@@ -103,6 +103,56 @@
 LibCxxMapIteratorSyntheticFrontEndCreator(CXXSyntheticChildren *,
   lldb::ValueObjectSP);
 
+/// Formats libcxx's std::unordered_map iterators
+///
+/// In raw form a std::unordered_map::iterator is represented as follow

[Lldb-commits] [PATCH] D129364: [LLDB][DataFormatter] Add data formatter for libcxx std::unordered_map iterator

2022-07-12 Thread Michael Buch via Phabricator via lldb-commits
Michael137 marked an inline comment as done.
Michael137 added inline comments.



Comment at: lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp:411
+   ".__i_.__node_", nullptr, nullptr,
+   ValueObject::GetValueForExpressionPathOptions()
+   .DontCheckDotVsArrowSyntax()

aprantl wrote:
> Does this get more readable if we assign this subexpression to an auto helper 
> variable?
Definitely :)



Comment at: 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py:13
+@add_test_categories(['libc++'])
+def test_with_run_command(self):
+"""Test that std::unordered_map related structures are formatted 
correctly when printed.

aprantl wrote:
> just curious: what does the _with_run_command suffix mean? Or was this copied 
> from another test?
Ah good catch. This was from at the `map` formatter test. Presumably the name 
refers to its usage of `self.runCmd`. I'll change it to something more 
meaningful


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129364/new/

https://reviews.llvm.org/D129364

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129364: [LLDB][DataFormatter] Add data formatter for libcxx std::unordered_map iterator

2022-07-12 Thread Michael Buch via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd1e9d0b27f3a: [LLDB][DataFormatter] Add data formatter for 
libcxx std::unordered_map iterator (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129364/new/

https://reviews.llvm.org/D129364

Files:
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp
@@ -0,0 +1,28 @@
+#include 
+#include 
+#include 
+
+using StringMapT = std::unordered_map;
+
+int main() {
+  StringMapT string_map;
+  {
+auto empty_iter = string_map.begin();
+auto const_empty_iter = string_map.cbegin();
+std::printf("Break here");
+  }
+  string_map["Foo"] = "Bar";
+  string_map["Baz"] = "Qux";
+
+  {
+auto foo = string_map.find("Foo");
+auto invalid = string_map.find("Invalid");
+
+StringMapT::const_iterator const_baz = string_map.find("Baz");
+auto bucket_it = string_map.begin(string_map.bucket("Baz"));
+auto const_bucket_it = string_map.cbegin(string_map.bucket("Baz"));
+std::printf("Break here");
+  }
+
+  return 0;
+}
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
@@ -0,0 +1,53 @@
+"""
+Test formatting of std::unordered_map related structures.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class LibcxxUnorderedMapDataFormatterTestCase(TestBase):
+
+@add_test_categories(['libc++'])
+def test_iterator_formatters(self):
+"""Test that std::unordered_map related structures are formatted correctly when printed.
+   Currently only tests format of std::unordered_map iterators.
+"""
+self.build()
+(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+self, 'Break here', lldb.SBFileSpec('main.cpp', False))
+
+# Test empty iterators
+self.expect_expr('empty_iter', '')
+self.expect_expr('const_empty_iter', '')
+
+lldbutil.continue_to_breakpoint(process, bkpt)
+
+# Check that key/value is correctly formatted
+self.expect_expr('foo', result_children=[
+ ValueCheck(name='first', summary='"Foo"'),
+ ValueCheck(name='second', summary='"Bar"')
+])
+
+# Check invalid iterator is empty
+self.expect_expr('invalid', '')
+
+# Const key/val iterator
+self.expect_expr('const_baz', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
+
+# Bucket iterators
+# I.e., std::__hash_map_const_iterator>
+# and std::__hash_map_iterator>
+self.expect_expr('bucket_it', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
+
+self.expect_expr('const_bucket_it', result_children=[
+ ValueCheck(name='first', summary='"Baz"'),
+ ValueCheck(name='second', summary='"Qux"')
+])
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/Makefile
@@ -0,0 +1,6 @@
+CXX_SOURCES := main.cpp
+
+USE_LIBCPP := 1
+
+CXXFLAGS_EXTRAS := -O0
+include Makefile.rules
Index: lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
===
--- lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
+++ lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
@@ -103,6 +103,56 @@
 LibCxxMapIteratorSyntheticFrontEndCreator(CXXSyntheticChildren *,
   lldb::ValueObjectSP);
 
+/// Formats libcxx's std::unordered_map iterators
+///
+/// In raw form a std::unorde

[Lldb-commits] [PATCH] D129367: [LLDB][ClangExpression] Remove unused StructVars::m_object_pointer_type

2022-07-12 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 443880.
Michael137 added a comment.

- Default constructor for `StructVars`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129367/new/

https://reviews.llvm.org/D129367

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h

Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
@@ -353,7 +353,7 @@
   /// The following values contain layout information for the materialized
   /// struct, but are not specific to a single materialization
   struct StructVars {
-StructVars() : m_result_name(), m_object_pointer_type(nullptr, nullptr) {}
+StructVars() = default;
 
 lldb::offset_t m_struct_alignment =
 0;///< The alignment of the struct in bytes.
@@ -364,8 +364,6 @@
/// added since).
 ConstString
 m_result_name; ///< The name of the result variable ($1, for example)
-TypeFromUser m_object_pointer_type; ///< The type of the "this" variable, if
-///one exists
   };
 
   std::unique_ptr m_struct_vars;
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -772,10 +772,6 @@
   return;
 
 AddContextClassType(context, TypeFromUser(m_ctx_obj->GetCompilerType()));
-
-m_struct_vars->m_object_pointer_type =
-TypeFromUser(ctx_obj_ptr->GetCompilerType());
-
 return;
   }
 
@@ -810,18 +806,6 @@
  class_qual_type.getAsString());
 
 AddContextClassType(context, class_user_type);
-
-if (method_decl->isInstance()) {
-  // self is a pointer to the object
-
-  QualType class_pointer_type =
-  method_decl->getASTContext().getPointerType(class_qual_type);
-
-  TypeFromUser self_user_type(class_pointer_type.getAsOpaquePtr(),
-  function_decl_ctx.GetTypeSystem());
-
-  m_struct_vars->m_object_pointer_type = self_user_type;
-}
 return;
   }
 
@@ -852,8 +836,6 @@
  ClangUtil::GetQualType(pointee_type).getAsString());
 
 AddContextClassType(context, pointee_type);
-TypeFromUser this_user_type(this_type->GetFullCompilerType());
-m_struct_vars->m_object_pointer_type = this_user_type;
   }
 }
 
@@ -869,10 +851,6 @@
   return;
 
 AddOneType(context, TypeFromUser(m_ctx_obj->GetCompilerType()));
-
-m_struct_vars->m_object_pointer_type =
-TypeFromUser(ctx_obj_ptr->GetCompilerType());
-
 return;
   }
 
@@ -917,28 +895,6 @@
  ClangUtil::ToString(interface_type));
 
 AddOneType(context, class_user_type);
-
-if (method_decl->isInstanceMethod()) {
-  // self is a pointer to the object
-
-  QualType class_pointer_type =
-  method_decl->getASTContext().getObjCObjectPointerType(
-  QualType(interface_type, 0));
-
-  TypeFromUser self_user_type(class_pointer_type.getAsOpaquePtr(),
-  function_decl_ctx.GetTypeSystem());
-
-  m_struct_vars->m_object_pointer_type = self_user_type;
-} else {
-  // self is a Class pointer
-  QualType class_type = method_decl->getASTContext().getObjCClassType();
-
-  TypeFromUser self_user_type(class_type.getAsOpaquePtr(),
-  function_decl_ctx.GetTypeSystem());
-
-  m_struct_vars->m_object_pointer_type = self_user_type;
-}
-
 return;
   }
   // This branch will get hit if we are executing code in the context of
@@ -981,10 +937,6 @@
   TypeFromUser class_user_type(self_clang_type);
 
   AddOneType(context, class_user_type);
-
-  TypeFromUser self_user_type(self_type->GetFullCompilerType());
-
-  m_struct_vars->m_object_pointer_type = self_user_type;
 }
 
 void ClangExpressionDeclMap::LookupLocalVarNamespace(
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129367: [LLDB][ClangExpression] Remove unused StructVars::m_object_pointer_type

2022-07-12 Thread Michael Buch via Phabricator via lldb-commits
Michael137 marked an inline comment as done.
Michael137 added inline comments.



Comment at: 
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h:356
   struct StructVars {
-StructVars() : m_result_name(), m_object_pointer_type(nullptr, nullptr) {}
+StructVars() : m_result_name() {}
 

aprantl wrote:
> I suppose the `: m_result_name()` is redundant?
Yup!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129367/new/

https://reviews.llvm.org/D129367

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129367: [LLDB][ClangExpression] Remove unused StructVars::m_object_pointer_type

2022-07-12 Thread Michael Buch via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4d26faa5262e: [LLDB][ClangExpression] Remove unused 
StructVars::m_object_pointer_type (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129367/new/

https://reviews.llvm.org/D129367

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h

Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
@@ -353,7 +353,7 @@
   /// The following values contain layout information for the materialized
   /// struct, but are not specific to a single materialization
   struct StructVars {
-StructVars() : m_result_name(), m_object_pointer_type(nullptr, nullptr) {}
+StructVars() = default;
 
 lldb::offset_t m_struct_alignment =
 0;///< The alignment of the struct in bytes.
@@ -364,8 +364,6 @@
/// added since).
 ConstString
 m_result_name; ///< The name of the result variable ($1, for example)
-TypeFromUser m_object_pointer_type; ///< The type of the "this" variable, if
-///one exists
   };
 
   std::unique_ptr m_struct_vars;
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -772,10 +772,6 @@
   return;
 
 AddContextClassType(context, TypeFromUser(m_ctx_obj->GetCompilerType()));
-
-m_struct_vars->m_object_pointer_type =
-TypeFromUser(ctx_obj_ptr->GetCompilerType());
-
 return;
   }
 
@@ -810,18 +806,6 @@
  class_qual_type.getAsString());
 
 AddContextClassType(context, class_user_type);
-
-if (method_decl->isInstance()) {
-  // self is a pointer to the object
-
-  QualType class_pointer_type =
-  method_decl->getASTContext().getPointerType(class_qual_type);
-
-  TypeFromUser self_user_type(class_pointer_type.getAsOpaquePtr(),
-  function_decl_ctx.GetTypeSystem());
-
-  m_struct_vars->m_object_pointer_type = self_user_type;
-}
 return;
   }
 
@@ -852,8 +836,6 @@
  ClangUtil::GetQualType(pointee_type).getAsString());
 
 AddContextClassType(context, pointee_type);
-TypeFromUser this_user_type(this_type->GetFullCompilerType());
-m_struct_vars->m_object_pointer_type = this_user_type;
   }
 }
 
@@ -869,10 +851,6 @@
   return;
 
 AddOneType(context, TypeFromUser(m_ctx_obj->GetCompilerType()));
-
-m_struct_vars->m_object_pointer_type =
-TypeFromUser(ctx_obj_ptr->GetCompilerType());
-
 return;
   }
 
@@ -917,28 +895,6 @@
  ClangUtil::ToString(interface_type));
 
 AddOneType(context, class_user_type);
-
-if (method_decl->isInstanceMethod()) {
-  // self is a pointer to the object
-
-  QualType class_pointer_type =
-  method_decl->getASTContext().getObjCObjectPointerType(
-  QualType(interface_type, 0));
-
-  TypeFromUser self_user_type(class_pointer_type.getAsOpaquePtr(),
-  function_decl_ctx.GetTypeSystem());
-
-  m_struct_vars->m_object_pointer_type = self_user_type;
-} else {
-  // self is a Class pointer
-  QualType class_type = method_decl->getASTContext().getObjCClassType();
-
-  TypeFromUser self_user_type(class_type.getAsOpaquePtr(),
-  function_decl_ctx.GetTypeSystem());
-
-  m_struct_vars->m_object_pointer_type = self_user_type;
-}
-
 return;
   }
   // This branch will get hit if we are executing code in the context of
@@ -981,10 +937,6 @@
   TypeFromUser class_user_type(self_clang_type);
 
   AddOneType(context, class_user_type);
-
-  TypeFromUser self_user_type(self_type->GetFullCompilerType());
-
-  m_struct_vars->m_object_pointer_type = self_user_type;
 }
 
 void ClangExpressionDeclMap::LookupLocalVarNamespace(
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-13 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 59.
Michael137 marked an inline comment as done.
Michael137 added a comment.

- Address stylistic comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp

Index: lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
@@ -0,0 +1,99 @@
+#include 
+#include 
+
+namespace {
+int global_var = -5;
+} // namespace
+
+struct Baz {
+  virtual ~Baz() = default;
+
+  virtual int baz_virt() = 0;
+
+  int base_base_var = 12;
+};
+
+struct Bar : public Baz {
+  virtual ~Bar() = default;
+
+  virtual int baz_virt() override {
+base_var = 10;
+return 1;
+  }
+
+  int base_var = 15;
+};
+
+struct Foo : public Bar {
+  int class_var = 9;
+  int shadowed = -137;
+  int *class_ptr;
+
+  virtual ~Foo() = default;
+
+  virtual int baz_virt() override {
+shadowed = -1;
+return 2;
+  }
+
+  void method() {
+int local_var = 137;
+int shadowed;
+class_ptr = &local_var;
+auto lambda = [&shadowed, this, &local_var,
+   local_var_copy = local_var]() mutable {
+  int lambda_local_var = 5;
+  shadowed = 5;
+  class_var = 109;
+  --base_var;
+  --base_base_var;
+  std::puts("break here");
+
+  auto nested_lambda = [this, &lambda_local_var] {
+std::puts("break here");
+lambda_local_var = 0;
+  };
+
+  nested_lambda();
+  --local_var_copy;
+  std::puts("break here");
+
+  struct LocalLambdaClass {
+int lambda_class_local = -12345;
+Foo *outer_ptr;
+
+void inner_method() {
+  auto lambda = [this] {
+std::puts("break here");
+lambda_class_local = -2;
+outer_ptr->class_var *= 2;
+  };
+
+  lambda();
+}
+  };
+
+  LocalLambdaClass l;
+  l.outer_ptr = this;
+  l.inner_method();
+};
+lambda();
+  }
+
+  void non_capturing_method() {
+int local = 5;
+int local2 = 10;
+
+class_var += [=] {
+  std::puts("break here");
+  return local + local2;
+}();
+  }
+};
+
+int main() {
+  Foo f;
+  f.method();
+  f.non_capturing_method();
+  return global_var;
+}
Index: lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
===
--- /dev/null
+++ lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
@@ -0,0 +1,123 @@
+""" Test that evaluating expressions from within C++ lambdas works
+Particularly, we test the case of capturing "this" and
+using members of the captured object in expression evaluation
+while we're on a breakpoint inside a lambda.
+"""
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+
+class ExprInsideLambdaTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def expectExprError(self, expr : str, expected : str):
+frame = self.thread.GetFrameAtIndex(0)
+value = frame.EvaluateExpression(expr)
+errmsg = value.GetError().GetCString()
+self.assertIn(expected, errmsg)
+
+def test_expr_inside_lambda(self):
+"""Test that lldb evaluating expressions inside lambda expressions works correctly."""
+self.build()
+(target, process, self.thread, bkpt) = \
+lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.cpp"))
+
+# Inside 'Foo::method'
+
+# Check access to captured 'this'
+self.expect_expr("class_var", result_type="int", result_value="109")
+self.expect_expr("this->class_var", result_type="int", result_value="109")
+
+# Check that captured shadowed variables take 

[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-14 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

After playing around with this some more I found an edge case with conditional 
breakpoints (in fact any place where we reuse an LLVMUserExpression). Modifying 
`lldb/test/API/functionalities/breakpoint/two_hits_one_actual` such that the 
helper method is inside a lambda like so:

  struct Foo {
void usleep_helper(int usec) {
  [this, &usec] {
  // Break here in the helper
  std::this_thread::sleep_for(std::chrono::duration(usec));
  }();
}
  };
  
  void *background_thread(void *arg) {
  (void) arg;
  Foo f;
  for (;;) {
  f.usleep_helper(2);
  }
  }
  
  int main(void) {
std::thread main_thread(background_thread, nullptr);
Foo f;
for (;;) {
  f.usleep_helper(1);
}
  }

Then setting a breakpoint twice, one for `usec == 1` and `usec == 100`, we 
would end up hitting the breakpoint even if `usec == 2` because conditional 
breakpoints re-use Materializer (and thus Entity objects). Since 
`EntityValueObject::GetValueObject` simply returns the ValueObject it was 
instantiated with, the `usec == 1` condition always evaluates to `true`. Have a 
fix for this but verifying whether that really is the best approach.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-15 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 445039.
Michael137 added a comment.

- Add test for conditional breakpoints on lambda captures


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
  lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/Makefile
  
lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
  lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp

Index: lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp
@@ -0,0 +1,32 @@
+#include 
+#include 
+#include 
+
+struct Foo {
+  bool enable = true;
+  uint32_t offset = 0;
+
+  void usleep_helper(uint32_t usec) {
+[this, &usec] {
+  puts("Break here in the helper");
+  std::this_thread::sleep_for(
+  std::chrono::duration(offset + usec));
+}();
+  }
+};
+
+void *background_thread(void *) {
+  Foo f;
+  for (;;) {
+f.usleep_helper(2);
+  }
+}
+
+int main() {
+  std::puts("First break");
+  std::thread main_thread(background_thread, nullptr);
+  Foo f;
+  for (;;) {
+f.usleep_helper(1);
+  }
+}
Index: lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
===
--- /dev/null
+++ lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
@@ -0,0 +1,54 @@
+"""
+Test that if we hit a breakpoint on a lambda capture
+on two threads at the same time we stop only for
+the correct one.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+
+class TestBreakOnLambdaCapture(TestBase):
+
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_break_on_lambda_capture(self):
+self.build()
+self.main_source_file = lldb.SBFileSpec("main.cpp")
+
+(target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(self,
+"First break", self.main_source_file)
+
+# FIXME: This is working around a separate bug. If you hit a breakpoint and
+# run an expression and it is the first expression you've ever run, on
+# Darwin that will involve running the ObjC runtime parsing code, and we'll
+# be in the middle of that when we do PerformAction on the other thread,
+# which will cause the condition expression to fail.  Calling another
+# expression first works around this.
+val_obj = main_thread.frame[0].EvaluateExpression("true")
+self.assertSuccess(val_obj.GetError(), "Ran our expression successfully")
+self.assertEqual(val_obj.value, "true", "Value was true.")
+
+bkpt = target.BreakpointCreateBySourceRegex("Break here in the helper",
+self.main_source_file);
+
+bkpt.SetCondition("enable && usec == 1")
+process.Continue()
+
+# This is hard to test definitively, becuase it requires hitting
+# a breakpoint on multiple threads at the same time.  On Darwin, this
+# will happen pretty much ever time we continue.  What we are really
+# asserting is that we only ever stop on one thread, so we approximate that
+# by continuing 20 times and assert we only ever hit the first thread.  Either
+# this is a platform that only reports one hit at a time, in which case all
+# this code is unused, or we actually didn't hit the other thread.
+
+for idx in range(0, 20):
+process.Continue()
+for thread in 

[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-16 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 445202.
Michael137 added a comment.

- Add ValueObjectProvider so materializer doesn't use incorrect ValueObject 
when re-using UserExpressions


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/include/lldb/lldb-private-types.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
  lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/Makefile
  
lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
  lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp

Index: lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp
@@ -0,0 +1,32 @@
+#include 
+#include 
+#include 
+
+struct Foo {
+  bool enable = true;
+  uint32_t offset = 0;
+
+  void usleep_helper(uint32_t usec) {
+[this, &usec] {
+  puts("Break here in the helper");
+  std::this_thread::sleep_for(
+  std::chrono::duration(offset + usec));
+}();
+  }
+};
+
+void *background_thread(void *) {
+  Foo f;
+  for (;;) {
+f.usleep_helper(2);
+  }
+}
+
+int main() {
+  std::puts("First break");
+  std::thread main_thread(background_thread, nullptr);
+  Foo f;
+  for (;;) {
+f.usleep_helper(1);
+  }
+}
Index: lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
===
--- /dev/null
+++ lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
@@ -0,0 +1,54 @@
+"""
+Test that if we hit a breakpoint on a lambda capture
+on two threads at the same time we stop only for
+the correct one.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+
+class TestBreakOnLambdaCapture(TestBase):
+
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_break_on_lambda_capture(self):
+self.build()
+self.main_source_file = lldb.SBFileSpec("main.cpp")
+
+(target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(self,
+"First break", self.main_source_file)
+
+# FIXME: This is working around a separate bug. If you hit a breakpoint and
+# run an expression and it is the first expression you've ever run, on
+# Darwin that will involve running the ObjC runtime parsing code, and we'll
+# be in the middle of that when we do PerformAction on the other thread,
+# which will cause the condition expression to fail.  Calling another
+# expression first works around this.
+val_obj = main_thread.frame[0].EvaluateExpression("true")
+self.assertSuccess(val_obj.GetError(), "Ran our expression successfully")
+self.assertEqual(val_obj.value, "true", "Value was true.")
+
+bkpt = target.BreakpointCreateBySourceRegex("Break here in the helper",
+self.main_source_file);
+
+bkpt.SetCondition("enable && usec == 1")
+process.Continue()
+
+# This is hard to test definitively, becuase it requires hitting
+# a breakpoint on multiple threads at the same time.  On Darwin, this
+# will happen pretty much ever time we continue.  What we are really
+# asserting is that we only ever stop on one thread, so we approximate that
+# by continuing 20 times and assert we only ever hit the first thread.  Either
+# this is a platform that only reports one hit at a time, in which case all
+# this code is unused, or we actually didn't hit the other thread.
+
+  

[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-16 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 445259.
Michael137 added a comment.

- Remove now redundant m_lldb_value_object


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/include/lldb/lldb-private-types.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
  lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/Makefile
  
lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
  lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp

Index: lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp
@@ -0,0 +1,32 @@
+#include 
+#include 
+#include 
+
+struct Foo {
+  bool enable = true;
+  uint32_t offset = 0;
+
+  void usleep_helper(uint32_t usec) {
+[this, &usec] {
+  puts("Break here in the helper");
+  std::this_thread::sleep_for(
+  std::chrono::duration(offset + usec));
+}();
+  }
+};
+
+void *background_thread(void *) {
+  Foo f;
+  for (;;) {
+f.usleep_helper(2);
+  }
+}
+
+int main() {
+  std::puts("First break");
+  std::thread main_thread(background_thread, nullptr);
+  Foo f;
+  for (;;) {
+f.usleep_helper(1);
+  }
+}
Index: lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
===
--- /dev/null
+++ lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
@@ -0,0 +1,54 @@
+"""
+Test that if we hit a breakpoint on a lambda capture
+on two threads at the same time we stop only for
+the correct one.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+
+class TestBreakOnLambdaCapture(TestBase):
+
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_break_on_lambda_capture(self):
+self.build()
+self.main_source_file = lldb.SBFileSpec("main.cpp")
+
+(target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(self,
+"First break", self.main_source_file)
+
+# FIXME: This is working around a separate bug. If you hit a breakpoint and
+# run an expression and it is the first expression you've ever run, on
+# Darwin that will involve running the ObjC runtime parsing code, and we'll
+# be in the middle of that when we do PerformAction on the other thread,
+# which will cause the condition expression to fail.  Calling another
+# expression first works around this.
+val_obj = main_thread.frame[0].EvaluateExpression("true")
+self.assertSuccess(val_obj.GetError(), "Ran our expression successfully")
+self.assertEqual(val_obj.value, "true", "Value was true.")
+
+bkpt = target.BreakpointCreateBySourceRegex("Break here in the helper",
+self.main_source_file);
+
+bkpt.SetCondition("enable && usec == 1")
+process.Continue()
+
+# This is hard to test definitively, becuase it requires hitting
+# a breakpoint on multiple threads at the same time.  On Darwin, this
+# will happen pretty much ever time we continue.  What we are really
+# asserting is that we only ever stop on one thread, so we approximate that
+# by continuing 20 times and assert we only ever hit the first thread.  Either
+# this is a platform that only reports one hit at a time, in which case all
+# this code is unused, or we actually didn't hit the other thread.
+
+for idx in range(0, 20):
+process.Continue()
+

[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-16 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 445269.
Michael137 added a comment.

- Fix assertion


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/include/lldb/lldb-private-types.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
  lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/Makefile
  
lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
  lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp

Index: lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp
@@ -0,0 +1,32 @@
+#include 
+#include 
+#include 
+
+struct Foo {
+  bool enable = true;
+  uint32_t offset = 0;
+
+  void usleep_helper(uint32_t usec) {
+[this, &usec] {
+  puts("Break here in the helper");
+  std::this_thread::sleep_for(
+  std::chrono::duration(offset + usec));
+}();
+  }
+};
+
+void *background_thread(void *) {
+  Foo f;
+  for (;;) {
+f.usleep_helper(2);
+  }
+}
+
+int main() {
+  std::puts("First break");
+  std::thread main_thread(background_thread, nullptr);
+  Foo f;
+  for (;;) {
+f.usleep_helper(1);
+  }
+}
Index: lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
===
--- /dev/null
+++ lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
@@ -0,0 +1,54 @@
+"""
+Test that if we hit a breakpoint on a lambda capture
+on two threads at the same time we stop only for
+the correct one.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+
+class TestBreakOnLambdaCapture(TestBase):
+
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_break_on_lambda_capture(self):
+self.build()
+self.main_source_file = lldb.SBFileSpec("main.cpp")
+
+(target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(self,
+"First break", self.main_source_file)
+
+# FIXME: This is working around a separate bug. If you hit a breakpoint and
+# run an expression and it is the first expression you've ever run, on
+# Darwin that will involve running the ObjC runtime parsing code, and we'll
+# be in the middle of that when we do PerformAction on the other thread,
+# which will cause the condition expression to fail.  Calling another
+# expression first works around this.
+val_obj = main_thread.frame[0].EvaluateExpression("true")
+self.assertSuccess(val_obj.GetError(), "Ran our expression successfully")
+self.assertEqual(val_obj.value, "true", "Value was true.")
+
+bkpt = target.BreakpointCreateBySourceRegex("Break here in the helper",
+self.main_source_file);
+
+bkpt.SetCondition("enable && usec == 1")
+process.Continue()
+
+# This is hard to test definitively, becuase it requires hitting
+# a breakpoint on multiple threads at the same time.  On Darwin, this
+# will happen pretty much ever time we continue.  What we are really
+# asserting is that we only ever stop on one thread, so we approximate that
+# by continuing 20 times and assert we only ever hit the first thread.  Either
+# this is a platform that only reports one hit at a time, in which case all
+# this code is unused, or we actually didn't hit the other thread.
+
+for idx in range(0, 20):
+process.Continue()
+for thread in p

[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-17 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 445307.
Michael137 added a comment.

- Remove redundant moves


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/include/lldb/lldb-private-types.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
  lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/Makefile
  
lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
  lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp

Index: lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp
@@ -0,0 +1,32 @@
+#include 
+#include 
+#include 
+
+struct Foo {
+  bool enable = true;
+  uint32_t offset = 0;
+
+  void usleep_helper(uint32_t usec) {
+[this, &usec] {
+  puts("Break here in the helper");
+  std::this_thread::sleep_for(
+  std::chrono::duration(offset + usec));
+}();
+  }
+};
+
+void *background_thread(void *) {
+  Foo f;
+  for (;;) {
+f.usleep_helper(2);
+  }
+}
+
+int main() {
+  std::puts("First break");
+  std::thread main_thread(background_thread, nullptr);
+  Foo f;
+  for (;;) {
+f.usleep_helper(1);
+  }
+}
Index: lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
===
--- /dev/null
+++ lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
@@ -0,0 +1,54 @@
+"""
+Test that if we hit a breakpoint on a lambda capture
+on two threads at the same time we stop only for
+the correct one.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+
+class TestBreakOnLambdaCapture(TestBase):
+
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_break_on_lambda_capture(self):
+self.build()
+self.main_source_file = lldb.SBFileSpec("main.cpp")
+
+(target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(self,
+"First break", self.main_source_file)
+
+# FIXME: This is working around a separate bug. If you hit a breakpoint and
+# run an expression and it is the first expression you've ever run, on
+# Darwin that will involve running the ObjC runtime parsing code, and we'll
+# be in the middle of that when we do PerformAction on the other thread,
+# which will cause the condition expression to fail.  Calling another
+# expression first works around this.
+val_obj = main_thread.frame[0].EvaluateExpression("true")
+self.assertSuccess(val_obj.GetError(), "Ran our expression successfully")
+self.assertEqual(val_obj.value, "true", "Value was true.")
+
+bkpt = target.BreakpointCreateBySourceRegex("Break here in the helper",
+self.main_source_file);
+
+bkpt.SetCondition("enable && usec == 1")
+process.Continue()
+
+# This is hard to test definitively, becuase it requires hitting
+# a breakpoint on multiple threads at the same time.  On Darwin, this
+# will happen pretty much ever time we continue.  What we are really
+# asserting is that we only ever stop on one thread, so we approximate that
+# by continuing 20 times and assert we only ever hit the first thread.  Either
+# this is a platform that only reports one hit at a time, in which case all
+# this code is unused, or we actually didn't hit the other thread.
+
+for idx in range(0, 20):
+process.Continue()
+for th

[Lldb-commits] [PATCH] D129962: [LLDB][DataFormatter] Add support for std::__map_const_iterator

2022-07-17 Thread Michael Buch via Phabricator via lldb-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, jingham.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This patch adds support for formatting `std::map::const_iterator`.
It's just a matter of adding `const_` to the existing regex.

**Testing**

- Added test case to existing API tests


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129962

Files:
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp


Index: 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
===
--- 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
+++ 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
@@ -24,7 +24,12 @@
 
 ii[0] = 0; // Set break point at this line.
 ii[1] = 1;
-   thefoo_rw(1);  // Set break point at this line.
+
+intint_map::iterator it = ii.begin();
+intint_map::const_iterator const_it = ii.cbegin();
+std::printf("%d %d", it->second, const_it->second);
+
+thefoo_rw(1); // Set break point at this line.
 ii[2] = 0;
 ii[3] = 1;
thefoo_rw(1);  // Set break point at this line.
Index: 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
===
--- 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
+++ 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
@@ -116,6 +116,16 @@
 substrs=['first =',
  'second ='])
 
+# (Non-)const key/val iterators
+self.expect_expr("it", result_children=[
+ValueCheck(name="first", value="0"),
+ValueCheck(name="second", value="0")
+])
+self.expect_expr("const_it", result_children=[
+ValueCheck(name="first", value="0"),
+ValueCheck(name="second", value="0")
+])
+
 # check that MightHaveChildren() gets it right
 self.assertTrue(
 self.frame().FindVariable("ii").MightHaveChildren(),
Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -909,7 +909,7 @@
   cpp_category_sp,
   lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEndCreator,
   "std::map iterator synthetic children",
-  ConstString("^std::__[[:alnum:]]+::__map_iterator<.+>$"), 
stl_synth_flags,
+  ConstString("^std::__[[:alnum:]]+::__map_(const_)?iterator<.+>$"), 
stl_synth_flags,
   true);
 
   AddCXXSynthetic(


Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
@@ -24,7 +24,12 @@
 
 ii[0] = 0; // Set break point at this line.
 ii[1] = 1;
-	thefoo_rw(1);  // Set break point at this line.
+
+intint_map::iterator it = ii.begin();
+intint_map::const_iterator const_it = ii.cbegin();
+std::printf("%d %d", it->second, const_it->second);
+
+thefoo_rw(1); // Set break point at this line.
 ii[2] = 0;
 ii[3] = 1;
 	thefoo_rw(1);  // Set break point at this line.
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
@@ -116,6 +116,16 @@
 substrs=['first =',
  'second ='])
 
+# (Non-)const key/val iterators
+self.expect_expr("it", result_children=[
+ValueCheck(name="first", value="0"),
+ValueCheck(name="second", value="0")
+])
+self.expect_expr("const_it", result_children=[
+ValueCheck(name="first", value="0"),
+ValueCheck(name="second", value="0")
+])
+
 # check that MightHaveChildren() gets it right
 self.assertTrue(
 self.frame().FindVariable("ii").MightHaveChildren(),
I

[Lldb-commits] [PATCH] D81471: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-20 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

This seems to cause issues when `var->getType() == const 
llvm::APFloatBase::roundingMode`. Triggered assertion `Assertion failed: 
(type->isIntegerType() && "Illegal type in IntegerLiteral"), function 
IntegerLiteral, file Expr.cpp, line 892` when doing the following:

1. `lldb -- ./bin/lldb a.out`
2. `b LookupLocalVariable`
3. step a couple of times until `decl_context` is declared
4. `p decl_context`

It looks ike the `dyn_cast` to `EnumType` fails and thus 
`qt.getUnqualifiedType()` which we pass into `IntegerLiteral::Create` remains 
an EnumType, which breaks the invariant

Investigating further...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81471/new/

https://reviews.llvm.org/D81471

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D130213: [LLDB][ClangExpression] Fix evaluation of types with constant initialized enum typedefs

2022-07-20 Thread Michael Buch via Phabricator via lldb-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, jingham, werat, labath.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

`IntegerLiteral::Create` expects integer types. For that reason
when we parse DWARF into an AST, when we encounter a constant
initialized enum member variable, we try to determine the underlying
integer type before creating the `IntegerLiteral`. However, we
currently don't desugar the type and the `dyn_cast`
fails. In debug builds this triggers following assert:

  Assertion failed: (type->isIntegerType() && "Illegal type in
  IntegerLiteral"), function IntegerLiteral, file Expr.cpp, line 892

This patch turns the `dyn_cast` into a `getAs`
which desguars the enum if necessary, allowing us to get to the
underlying integer type.

**Testing**

- API test
- Manual repro is fixed


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130213

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -1,3 +1,4 @@
+#include 
 #include 
 
 enum Enum {
@@ -69,6 +70,11 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+};
+
 int main() {
   A a;
 
@@ -98,5 +104,8 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+
   return 0; // break here
 }
Index: 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,9 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias", 
result_value="scoped_enum_case2")
+
 # Test taking address.
 if lldbplatformutil.getPlatform() == "windows":
 # On Windows data members without the out-of-class definitions 
still have
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7538,10 +7538,11 @@
  "only integer or enum types supported");
   // If the variable is an enum type, take the underlying integer type as
   // the type of the integer literal.
-  if (const EnumType *enum_type = llvm::dyn_cast(qt.getTypePtr())) {
+  if (const EnumType *enum_type = qt->getAs()) {
 const EnumDecl *enum_decl = enum_type->getDecl();
 qt = enum_decl->getIntegerType();
   }
+
   var->setInit(IntegerLiteral::Create(ast, init_value, qt.getUnqualifiedType(),
   SourceLocation()));
 }


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -1,3 +1,4 @@
+#include 
 #include 
 
 enum Enum {
@@ -69,6 +70,11 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+};
+
 int main() {
   A a;
 
@@ -98,5 +104,8 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+
   return 0; // break here
 }
Index: lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,9 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 sel

[Lldb-commits] [PATCH] D130213: [LLDB][ClangExpression] Fix evaluation of types with constant initialized enum typedefs

2022-07-20 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 446305.
Michael137 added a comment.

- Remove redundant header


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130213/new/

https://reviews.llvm.org/D130213

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,11 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+};
+
 int main() {
   A a;
 
@@ -98,5 +103,8 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+
   return 0; // break here
 }
Index: 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,9 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias", 
result_value="scoped_enum_case2")
+
 # Test taking address.
 if lldbplatformutil.getPlatform() == "windows":
 # On Windows data members without the out-of-class definitions 
still have
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7538,10 +7538,11 @@
  "only integer or enum types supported");
   // If the variable is an enum type, take the underlying integer type as
   // the type of the integer literal.
-  if (const EnumType *enum_type = llvm::dyn_cast(qt.getTypePtr())) {
+  if (const EnumType *enum_type = qt->getAs()) {
 const EnumDecl *enum_decl = enum_type->getDecl();
 qt = enum_decl->getIntegerType();
   }
+
   var->setInit(IntegerLiteral::Create(ast, init_value, qt.getUnqualifiedType(),
   SourceLocation()));
 }


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,11 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+};
+
 int main() {
   A a;
 
@@ -98,5 +103,8 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+
   return 0; // break here
 }
Index: lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,9 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias", result_value="scoped_enum_case2")
+
 # Test taking address.
 if lldbplatformutil.getPlatform() == "windows":
 # On Windows data members without the out-of-class definitions still have
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7538,10 +7538,11 @@
  "only integer or enum types supported");
   // If the variable is an enum type, take the underlying integer type as
   // the type of the integer literal.
-  if (const EnumType *

[Lldb-commits] [PATCH] D81471: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-20 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

Doing this instead:

  if (const EnumType *enum_type = 
llvm::dyn_cast(qt.getTypePtr()->getUnqualifiedDesugaredType())) {

resolves the crash, though unclear if that's the right thing to do

In D81471#3666071 , @Michael137 wrote:

> This seems to cause issues when `var->getType() == const 
> llvm::APFloatBase::roundingMode`.
>
> The following assertion triggered:
>
>   Assertion failed: (type->isIntegerType() && "Illegal type in 
> IntegerLiteral"), function IntegerLiteral, file Expr.cpp, line 892
>
> Reproduces with:
>
> 1. `lldb -- ./bin/lldb a.out`
> 2. `b LookupLocalVariable`
> 3. step a couple of times until `decl_context` is declared
> 4. `p decl_context`
>
> It looks ike the `dyn_cast` to `EnumType` fails and thus 
> `qt.getUnqualifiedType()` which we pass into `IntegerLiteral::Create` remains 
> an EnumType, which breaks the invariant
>
> Investigating further...

Tried to address this in https://reviews.llvm.org/D130213


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81471/new/

https://reviews.llvm.org/D81471

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D130213: [LLDB][ClangExpression] Fix evaluation of types with constant initialized enum typedefs

2022-07-20 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 446315.
Michael137 added a comment.

- Add test case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130213/new/

https://reviews.llvm.org/D130213

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,15 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+
+  using EnumAliasAlias = EnumAlias;
+  static constexpr EnumAliasAlias enum_alias_alias =
+  ScopedEnum::scoped_enum_case1;
+};
+
 int main() {
   A a;
 
@@ -98,5 +107,9 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+  auto enum_alias_alias_val = ClassWithEnumAlias::enum_alias_alias;
+
   return 0; // break here
 }
Index: 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,12 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias",
+ result_value="scoped_enum_case2")
+self.expect_expr("ClassWithEnumAlias::enum_alias_alias",
+ result_value="scoped_enum_case1")
+
 # Test taking address.
 if lldbplatformutil.getPlatform() == "windows":
 # On Windows data members without the out-of-class definitions 
still have
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7538,10 +7538,11 @@
  "only integer or enum types supported");
   // If the variable is an enum type, take the underlying integer type as
   // the type of the integer literal.
-  if (const EnumType *enum_type = llvm::dyn_cast(qt.getTypePtr())) {
+  if (const EnumType *enum_type = qt->getAs()) {
 const EnumDecl *enum_decl = enum_type->getDecl();
 qt = enum_decl->getIntegerType();
   }
+
   var->setInit(IntegerLiteral::Create(ast, init_value, qt.getUnqualifiedType(),
   SourceLocation()));
 }


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,15 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+
+  using EnumAliasAlias = EnumAlias;
+  static constexpr EnumAliasAlias enum_alias_alias =
+  ScopedEnum::scoped_enum_case1;
+};
+
 int main() {
   A a;
 
@@ -98,5 +107,9 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+  auto enum_alias_alias_val = ClassWithEnumAlias::enum_alias_alias;
+
   return 0; // break here
 }
Index: lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,12 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias",
+ result_value="scoped_enum_case2")
+self.expect_expr("ClassWithEnumAlias::enum_alias_alias",
+

[Lldb-commits] [PATCH] D130213: [LLDB][ClangExpression] Fix evaluation of types with constant initialized enum typedefs

2022-07-20 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 446316.
Michael137 added a comment.

- Remove drive-by whitespace change


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130213/new/

https://reviews.llvm.org/D130213

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,15 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+
+  using EnumAliasAlias = EnumAlias;
+  static constexpr EnumAliasAlias enum_alias_alias =
+  ScopedEnum::scoped_enum_case1;
+};
+
 int main() {
   A a;
 
@@ -98,5 +107,9 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+  auto enum_alias_alias_val = ClassWithEnumAlias::enum_alias_alias;
+
   return 0; // break here
 }
Index: 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,12 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias",
+ result_value="scoped_enum_case2")
+self.expect_expr("ClassWithEnumAlias::enum_alias_alias",
+ result_value="scoped_enum_case1")
+
 # Test taking address.
 if lldbplatformutil.getPlatform() == "windows":
 # On Windows data members without the out-of-class definitions 
still have
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7538,7 +7538,7 @@
  "only integer or enum types supported");
   // If the variable is an enum type, take the underlying integer type as
   // the type of the integer literal.
-  if (const EnumType *enum_type = llvm::dyn_cast(qt.getTypePtr())) {
+  if (const EnumType *enum_type = qt->getAs()) {
 const EnumDecl *enum_decl = enum_type->getDecl();
 qt = enum_decl->getIntegerType();
   }


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,15 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+
+  using EnumAliasAlias = EnumAlias;
+  static constexpr EnumAliasAlias enum_alias_alias =
+  ScopedEnum::scoped_enum_case1;
+};
+
 int main() {
   A a;
 
@@ -98,5 +107,9 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+  auto enum_alias_alias_val = ClassWithEnumAlias::enum_alias_alias;
+
   return 0; // break here
 }
Index: lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,12 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias",
+ result_value="scoped_enum_case2")
+self.expect_expr("ClassWithEnumAlias::enum_alias_alias",
+ result_value="scoped_enum_case1")
+
 # Test taking address.
 if lldbplatformutil.getPlatform()

[Lldb-commits] [PATCH] D130213: [LLDB][ClangExpression] Fix evaluation of types with constant initialized enum typedefs

2022-07-21 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 446418.
Michael137 added a comment.

- Reword commit


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130213/new/

https://reviews.llvm.org/D130213

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,15 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+
+  using EnumAliasAlias = EnumAlias;
+  static constexpr EnumAliasAlias enum_alias_alias =
+  ScopedEnum::scoped_enum_case1;
+};
+
 int main() {
   A a;
 
@@ -98,5 +107,9 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+  auto enum_alias_alias_val = ClassWithEnumAlias::enum_alias_alias;
+
   return 0; // break here
 }
Index: 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,12 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias",
+ result_value="scoped_enum_case2")
+self.expect_expr("ClassWithEnumAlias::enum_alias_alias",
+ result_value="scoped_enum_case1")
+
 # Test taking address.
 if lldbplatformutil.getPlatform() == "windows":
 # On Windows data members without the out-of-class definitions 
still have
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7538,7 +7538,7 @@
  "only integer or enum types supported");
   // If the variable is an enum type, take the underlying integer type as
   // the type of the integer literal.
-  if (const EnumType *enum_type = llvm::dyn_cast(qt.getTypePtr())) {
+  if (const EnumType *enum_type = qt->getAs()) {
 const EnumDecl *enum_decl = enum_type->getDecl();
 qt = enum_decl->getIntegerType();
   }


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,15 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+
+  using EnumAliasAlias = EnumAlias;
+  static constexpr EnumAliasAlias enum_alias_alias =
+  ScopedEnum::scoped_enum_case1;
+};
+
 int main() {
   A a;
 
@@ -98,5 +107,9 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+  auto enum_alias_alias_val = ClassWithEnumAlias::enum_alias_alias;
+
   return 0; // break here
 }
Index: lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,12 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias",
+ result_value="scoped_enum_case2")
+self.expect_expr("ClassWithEnumAlias::enum_alias_alias",
+ result_value="scoped_enum_case1")
+
 # Test taking address.
 if lldbplatformutil.getPlatform() == "windows":
 

[Lldb-commits] [PATCH] D130213: [LLDB][ClangExpression] Fix initialization of static enum alias members

2022-07-21 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

In D130213#3668109 , @werat wrote:

> I've tried reproducing the test case with `lldb` built from HEAD on my Linux 
> machine and it seems to work without your patch:
>
>   ❯ cat ~/src/cpp/const.cc 
>   enum class ScopedEnum {
> scoped_enum_case1 = 1,
> scoped_enum_case2 = 2,
>   };
>   
>   struct A {
> using EnumAlias = ScopedEnum;
> static constexpr EnumAlias e = ScopedEnum::scoped_enum_case2;
>   };
>   
>   int main() {
>   auto enum_alias_val = A::e;
>   }
>   
>   ❯ bin/lldb ~/src/cpp/a.out
>   (lldb) target create "/home/werat/src/cpp/a.out"
>   Current executable set to '/home/werat/src/cpp/a.out' (x86_64).
>   (lldb) b main
>   Breakpoint 1: where = a.out`main + 4 at const.cc:12:10, address = 
> 0x00401114
>   (lldb) r
>   Process 2767509 launched: '/home/werat/src/cpp/a.out' (x86_64)
>   Process 2767509 stopped
>   * thread #1, name = 'a.out', stop reason = breakpoint 1.1
>   frame #0: 0x00401114 a.out`main at const.cc:12:10
>  9};
>  10  
>  11   int main() {
>   -> 12   auto enum_alias_val = A::e;
>  13   }
>   (lldb) p A::e
>   (const A::EnumAlias) $0 = scoped_enum_case2
>
> Maybe the test case doesn't actually hit the problem you're trying to address?
>
> ---
>
>   ❯ bin/lldb --version
>   lldb version 15.0.0git (https://github.com/llvm/llvm-project.git revision 
> 2feb99b02c886201c9774f4f24df14299105b321)
> clang revision 2feb99b02c886201c9774f4f24df14299105b321
> llvm revision 2feb99b02c886201c9774f4f24df14299105b321

Hmm odd, on my Darwin machine the test consistently crashes

Let me confirm


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130213/new/

https://reviews.llvm.org/D130213

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D130213: [LLDB][ClangExpression] Fix initialization of static enum alias members

2022-07-21 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

In D130213#3668450 , @aprantl wrote:

> @werat did you build with assertions enabled?
>
> This change looks fine to me, but it might be interesting to see where the 
> discrepancy between the platforms comes from.

Interestingly, @werat's test case crashes for me (without the patch) but only 
if I explicitly create an instance of `struct A`. Otherwise, lldb doesn't find 
`A::e`.

If a class only has constexpr statics, on Darwin we omit the structure type 
from DWARF:

  0x000b: DW_TAG_compile_unit
DW_AT_producer("Apple clang version 14.0.0 
(clang-1400.0.25)")   
DW_AT_language(DW_LANG_C_plus_plus_14)  
 
DW_AT_name("test.cpp")  
 
DW_AT_LLVM_sysroot
("/Library/Developer/CommandLineTools/SDKs/MacOSX12.5.sdk")
DW_AT_APPLE_sdk   ("MacOSX12.5.sdk")
 
DW_AT_stmt_list   (0x) 
DW_AT_comp_dir("/Users/michaelbuch/Git/lldb-build-lambda")  
 
DW_AT_low_pc  (0x00013f9c)  


DW_AT_high_pc (0x00013fb8)  
 
   
  0x0032:   DW_TAG_enumeration_type 
 
  DW_AT_type  (0x004b "int")
 
  DW_AT_enum_class(true)
 
  DW_AT_name  ("ScopedEnum")
 
  DW_AT_byte_size (0x04)   
  DW_AT_decl_file 
("/Users/michaelbuch/Git/lldb-build-lambda/test.cpp")  
  DW_AT_decl_line (1)   
 
   
  0x003e: DW_TAG_enumerator 
 
DW_AT_name("scoped_enum_case1")
DW_AT_const_value (1)   
 

 
  0x0044: DW_TAG_enumerator
DW_AT_name("scoped_enum_case2") 
 
DW_AT_const_value (2)   
 

 
  0x004a: NULL  
 

 
  0x004b:   DW_TAG_base_type
 
  DW_AT_name  ("int")   
 
  DW_AT_encoding  (DW_ATE_signed)   
 
  DW_AT_byte_size (0x04)
 

 
  0x0052:   DW_TAG_subprogram   
 
  DW_AT_low_pc(0x00013f9c) 
  DW_AT_high_pc   (0x00013fb8)  
 
  DW_AT_APPLE_omit_frame_ptr  (true)


  DW_AT_frame_base(DW_OP_reg31 WSP) 
 
  DW_AT_name  ("main")
  DW_AT_decl_file 
("/Users/michaelbuch/Git/lldb-build-lambda/test.cpp")  
  DW_AT_decl_line (13)  
 
  DW_AT_type  (0x004b "int")
  

[Lldb-commits] [PATCH] D130213: [LLDB][ClangExpression] Fix initialization of static enum alias members

2022-07-21 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.



> Though I'm a little confused why the test does find 
> `ClassWithEnumAlias::enum_alias` despite it not being instantiated in `main`

Oh nvm, probably just because clang++ on Darwin invokes dsymutil at the end. 
Whereas in the test suite we don't unless explicitly done


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130213/new/

https://reviews.llvm.org/D130213

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129962: [LLDB][DataFormatter] Add support for std::__map_const_iterator

2022-07-21 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 446464.
Michael137 added a comment.

- Add newline to flush printf buffer


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129962/new/

https://reviews.llvm.org/D129962

Files:
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp


Index: 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
===
--- 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
+++ 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
@@ -24,7 +24,12 @@
 
 ii[0] = 0; // Set break point at this line.
 ii[1] = 1;
-   thefoo_rw(1);  // Set break point at this line.
+
+intint_map::iterator it = ii.begin();
+intint_map::const_iterator const_it = ii.cbegin();
+std::printf("%d %d\n", it->second, const_it->second);
+
+thefoo_rw(1); // Set break point at this line.
 ii[2] = 0;
 ii[3] = 1;
thefoo_rw(1);  // Set break point at this line.
Index: 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
===
--- 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
+++ 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
@@ -116,6 +116,16 @@
 substrs=['first =',
  'second ='])
 
+# (Non-)const key/val iterators
+self.expect_expr("it", result_children=[
+ValueCheck(name="first", value="0"),
+ValueCheck(name="second", value="0")
+])
+self.expect_expr("const_it", result_children=[
+ValueCheck(name="first", value="0"),
+ValueCheck(name="second", value="0")
+])
+
 # check that MightHaveChildren() gets it right
 self.assertTrue(
 self.frame().FindVariable("ii").MightHaveChildren(),
Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -909,7 +909,7 @@
   cpp_category_sp,
   lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEndCreator,
   "std::map iterator synthetic children",
-  ConstString("^std::__[[:alnum:]]+::__map_iterator<.+>$"), 
stl_synth_flags,
+  ConstString("^std::__[[:alnum:]]+::__map_(const_)?iterator<.+>$"), 
stl_synth_flags,
   true);
 
   AddCXXSynthetic(


Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
@@ -24,7 +24,12 @@
 
 ii[0] = 0; // Set break point at this line.
 ii[1] = 1;
-	thefoo_rw(1);  // Set break point at this line.
+
+intint_map::iterator it = ii.begin();
+intint_map::const_iterator const_it = ii.cbegin();
+std::printf("%d %d\n", it->second, const_it->second);
+
+thefoo_rw(1); // Set break point at this line.
 ii[2] = 0;
 ii[3] = 1;
 	thefoo_rw(1);  // Set break point at this line.
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
@@ -116,6 +116,16 @@
 substrs=['first =',
  'second ='])
 
+# (Non-)const key/val iterators
+self.expect_expr("it", result_children=[
+ValueCheck(name="first", value="0"),
+ValueCheck(name="second", value="0")
+])
+self.expect_expr("const_it", result_children=[
+ValueCheck(name="first", value="0"),
+ValueCheck(name="second", value="0")
+])
+
 # check that MightHaveChildren() gets it right
 self.assertTrue(
 self.frame().FindVariable("ii").MightHaveChildren(),
Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ lldb/source/Plugins

[Lldb-commits] [PATCH] D129962: [LLDB][DataFormatter] Add support for std::__map_const_iterator

2022-07-21 Thread Michael Buch via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6703812688b8: [LLDB][DataFormatter] Add support for 
std::__map_const_iterator (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129962/new/

https://reviews.llvm.org/D129962

Files:
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp


Index: 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
===
--- 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
+++ 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
@@ -24,7 +24,12 @@
 
 ii[0] = 0; // Set break point at this line.
 ii[1] = 1;
-   thefoo_rw(1);  // Set break point at this line.
+
+intint_map::iterator it = ii.begin();
+intint_map::const_iterator const_it = ii.cbegin();
+std::printf("%d %d\n", it->second, const_it->second);
+
+thefoo_rw(1); // Set break point at this line.
 ii[2] = 0;
 ii[3] = 1;
thefoo_rw(1);  // Set break point at this line.
Index: 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
===
--- 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
+++ 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
@@ -116,6 +116,16 @@
 substrs=['first =',
  'second ='])
 
+# (Non-)const key/val iterators
+self.expect_expr("it", result_children=[
+ValueCheck(name="first", value="0"),
+ValueCheck(name="second", value="0")
+])
+self.expect_expr("const_it", result_children=[
+ValueCheck(name="first", value="0"),
+ValueCheck(name="second", value="0")
+])
+
 # check that MightHaveChildren() gets it right
 self.assertTrue(
 self.frame().FindVariable("ii").MightHaveChildren(),
Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -909,7 +909,7 @@
   cpp_category_sp,
   lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEndCreator,
   "std::map iterator synthetic children",
-  ConstString("^std::__[[:alnum:]]+::__map_iterator<.+>$"), 
stl_synth_flags,
+  ConstString("^std::__[[:alnum:]]+::__map_(const_)?iterator<.+>$"), 
stl_synth_flags,
   true);
 
   AddCXXSynthetic(


Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
@@ -24,7 +24,12 @@
 
 ii[0] = 0; // Set break point at this line.
 ii[1] = 1;
-	thefoo_rw(1);  // Set break point at this line.
+
+intint_map::iterator it = ii.begin();
+intint_map::const_iterator const_it = ii.cbegin();
+std::printf("%d %d\n", it->second, const_it->second);
+
+thefoo_rw(1); // Set break point at this line.
 ii[2] = 0;
 ii[3] = 1;
 	thefoo_rw(1);  // Set break point at this line.
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
@@ -116,6 +116,16 @@
 substrs=['first =',
  'second ='])
 
+# (Non-)const key/val iterators
+self.expect_expr("it", result_children=[
+ValueCheck(name="first", value="0"),
+ValueCheck(name="second", value="0")
+])
+self.expect_expr("const_it", result_children=[
+ValueCheck(name="first", value="0"),
+ValueCheck(name="second", value="0")
+])
+
 # check that MightHaveChildren() gets it right
 self.assertTrue(
 self.frame().FindVariable("ii").MightHaveChildren(),
Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
==

[Lldb-commits] [PATCH] D130213: [LLDB][ClangExpression] Fix initialization of static enum alias members

2022-07-21 Thread Michael Buch via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG140bcd369b0f: [LLDB][ClangExpression] Fix initialization of 
static enum alias members (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130213/new/

https://reviews.llvm.org/D130213

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,15 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+
+  using EnumAliasAlias = EnumAlias;
+  static constexpr EnumAliasAlias enum_alias_alias =
+  ScopedEnum::scoped_enum_case1;
+};
+
 int main() {
   A a;
 
@@ -98,5 +107,9 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+  auto enum_alias_alias_val = ClassWithEnumAlias::enum_alias_alias;
+
   return 0; // break here
 }
Index: 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,12 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias",
+ result_value="scoped_enum_case2")
+self.expect_expr("ClassWithEnumAlias::enum_alias_alias",
+ result_value="scoped_enum_case1")
+
 # Test taking address.
 if lldbplatformutil.getPlatform() == "windows":
 # On Windows data members without the out-of-class definitions 
still have
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7538,7 +7538,7 @@
  "only integer or enum types supported");
   // If the variable is an enum type, take the underlying integer type as
   // the type of the integer literal.
-  if (const EnumType *enum_type = llvm::dyn_cast(qt.getTypePtr())) {
+  if (const EnumType *enum_type = qt->getAs()) {
 const EnumDecl *enum_decl = enum_type->getDecl();
 qt = enum_decl->getIntegerType();
   }


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,15 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+
+  using EnumAliasAlias = EnumAlias;
+  static constexpr EnumAliasAlias enum_alias_alias =
+  ScopedEnum::scoped_enum_case1;
+};
+
 int main() {
   A a;
 
@@ -98,5 +107,9 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+  auto enum_alias_alias_val = ClassWithEnumAlias::enum_alias_alias;
+
   return 0; // break here
 }
Index: lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,12 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias",
+ result_value="scoped_enum_case2")
+self.expect_expr("ClassWithEnumAlias::enum_alias_alias",
+ result_value="scope

[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-21 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 446723.
Michael137 added a comment.

- Doxgyen format improvements


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

Files:
  lldb/include/lldb/Expression/Materializer.h
  lldb/include/lldb/Expression/UserExpression.h
  lldb/include/lldb/lldb-private-types.h
  lldb/source/Expression/Materializer.cpp
  lldb/source/Expression/UserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/test/API/commands/expression/expr_inside_lambda/Makefile
  lldb/test/API/commands/expression/expr_inside_lambda/TestExprInsideLambdas.py
  lldb/test/API/commands/expression/expr_inside_lambda/main.cpp
  lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/Makefile
  
lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
  lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp

Index: lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/main.cpp
@@ -0,0 +1,32 @@
+#include 
+#include 
+#include 
+
+struct Foo {
+  bool enable = true;
+  uint32_t offset = 0;
+
+  void usleep_helper(uint32_t usec) {
+[this, &usec] {
+  puts("Break here in the helper");
+  std::this_thread::sleep_for(
+  std::chrono::duration(offset + usec));
+}();
+  }
+};
+
+void *background_thread(void *) {
+  Foo f;
+  for (;;) {
+f.usleep_helper(2);
+  }
+}
+
+int main() {
+  std::puts("First break");
+  std::thread main_thread(background_thread, nullptr);
+  Foo f;
+  for (;;) {
+f.usleep_helper(1);
+  }
+}
Index: lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
===
--- /dev/null
+++ lldb/test/API/functionalities/breakpoint/breakpoint_on_lambda_capture/TestBreakOnLambdaCapture.py
@@ -0,0 +1,54 @@
+"""
+Test that if we hit a breakpoint on a lambda capture
+on two threads at the same time we stop only for
+the correct one.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+
+class TestBreakOnLambdaCapture(TestBase):
+
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_break_on_lambda_capture(self):
+self.build()
+self.main_source_file = lldb.SBFileSpec("main.cpp")
+
+(target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(self,
+"First break", self.main_source_file)
+
+# FIXME: This is working around a separate bug. If you hit a breakpoint and
+# run an expression and it is the first expression you've ever run, on
+# Darwin that will involve running the ObjC runtime parsing code, and we'll
+# be in the middle of that when we do PerformAction on the other thread,
+# which will cause the condition expression to fail.  Calling another
+# expression first works around this.
+val_obj = main_thread.frame[0].EvaluateExpression("true")
+self.assertSuccess(val_obj.GetError(), "Ran our expression successfully")
+self.assertEqual(val_obj.value, "true", "Value was true.")
+
+bkpt = target.BreakpointCreateBySourceRegex("Break here in the helper",
+self.main_source_file);
+
+bkpt.SetCondition("enable && usec == 1")
+process.Continue()
+
+# This is hard to test definitively, becuase it requires hitting
+# a breakpoint on multiple threads at the same time.  On Darwin, this
+# will happen pretty much ever time we continue.  What we are really
+# asserting is that we only ever stop on one thread, so we approximate that
+# by continuing 20 times and assert we only ever hit the first thread.  Either
+# this is a platform that only reports one hit at a time, in which case all
+# this code is unused, or we actually didn't hit the other thread.
+
+for idx in range(0, 20):
+process.Continue()
+f

[Lldb-commits] [PATCH] D130561: [LLDB][ClangExpression] Prevent nullptr namespace map access during logging

2022-07-26 Thread Michael Buch via Phabricator via lldb-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, jingham.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Some codepaths lead to `namespace_map == nullptr` when we get to
`ClangASTSource::FindCompleteType`. This occurred while debugging
an lldb session that had `settings set target.import-std-module true`.

In that case, with `LLDBLog::Expressions` logging enabled, we would
dereference a `nullptr` and crash.

This commit moves the logging until after we check for `nullptr`.

**Testing**

- Fixed the specific crash I was seeing while debugging an `lldb` session with 
`import-std-module` enabled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130561

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp


Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -191,12 +191,12 @@
 ClangASTImporter::NamespaceMapSP namespace_map =
 m_ast_importer_sp->GetNamespaceMap(namespace_context);
 
-LLDB_LOGV(log, "  CTD Inspecting namespace map{0} ({1} entries)",
-  namespace_map.get(), namespace_map->size());
-
 if (!namespace_map)
   return nullptr;
 
+LLDB_LOGV(log, "  CTD Inspecting namespace map{0} ({1} entries)",
+  namespace_map.get(), namespace_map->size());
+
 for (const ClangASTImporter::NamespaceMapItem &item : *namespace_map) {
   LLDB_LOG(log, "  CTD Searching namespace {0} in module {1}",
item.second.GetName(), item.first->GetFileSpec().GetFilename());


Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -191,12 +191,12 @@
 ClangASTImporter::NamespaceMapSP namespace_map =
 m_ast_importer_sp->GetNamespaceMap(namespace_context);
 
-LLDB_LOGV(log, "  CTD Inspecting namespace map{0} ({1} entries)",
-  namespace_map.get(), namespace_map->size());
-
 if (!namespace_map)
   return nullptr;
 
+LLDB_LOGV(log, "  CTD Inspecting namespace map{0} ({1} entries)",
+  namespace_map.get(), namespace_map->size());
+
 for (const ClangASTImporter::NamespaceMapItem &item : *namespace_map) {
   LLDB_LOG(log, "  CTD Searching namespace {0} in module {1}",
item.second.GetName(), item.first->GetFileSpec().GetFilename());
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D130561: [LLDB][ClangExpression] Prevent nullptr namespace map access during logging

2022-07-26 Thread Michael Buch via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0a412b3505f4: [LLDB][ClangExpression] Prevent nullptr 
namespace map access during logging (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130561/new/

https://reviews.llvm.org/D130561

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp


Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -191,12 +191,12 @@
 ClangASTImporter::NamespaceMapSP namespace_map =
 m_ast_importer_sp->GetNamespaceMap(namespace_context);
 
-LLDB_LOGV(log, "  CTD Inspecting namespace map{0} ({1} entries)",
-  namespace_map.get(), namespace_map->size());
-
 if (!namespace_map)
   return nullptr;
 
+LLDB_LOGV(log, "  CTD Inspecting namespace map{0} ({1} entries)",
+  namespace_map.get(), namespace_map->size());
+
 for (const ClangASTImporter::NamespaceMapItem &item : *namespace_map) {
   LLDB_LOG(log, "  CTD Searching namespace {0} in module {1}",
item.second.GetName(), item.first->GetFileSpec().GetFilename());


Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -191,12 +191,12 @@
 ClangASTImporter::NamespaceMapSP namespace_map =
 m_ast_importer_sp->GetNamespaceMap(namespace_context);
 
-LLDB_LOGV(log, "  CTD Inspecting namespace map{0} ({1} entries)",
-  namespace_map.get(), namespace_map->size());
-
 if (!namespace_map)
   return nullptr;
 
+LLDB_LOGV(log, "  CTD Inspecting namespace map{0} ({1} entries)",
+  namespace_map.get(), namespace_map->size());
+
 for (const ClangASTImporter::NamespaceMapItem &item : *namespace_map) {
   LLDB_LOG(log, "  CTD Searching namespace {0} in module {1}",
item.second.GetName(), item.first->GetFileSpec().GetFilename());
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129078: [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas

2022-07-27 Thread Michael Buch via Phabricator via lldb-commits
Michael137 closed this revision.
Michael137 added a comment.

Missed the differential link in the commits.

This patch has been merged to main in following commits:

  8184b252cdab2fbe44f766d6de28b29ebe4c8753
  fcf4e252f4d992cade4bdfe5aed10ff96fa40202
  317c8bf84d185c6b4a51a415c0deb7f8af661cb6


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129078/new/

https://reviews.llvm.org/D129078

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D131122: [lldb] Fixed a number of typos

2022-08-03 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

FYI, there's a couple of instances of `sythetic` (instead of `synthetic`) 
around LLDB that could be included in this


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131122/new/

https://reviews.llvm.org/D131122

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


  1   2   3   4   5   6   >