[Lldb-commits] [lldb] r331172 - Fixup r331049 (FileSpec auto-normalization)

2018-04-30 Thread Pavel Labath via lldb-commits
Author: labath
Date: Mon Apr 30 05:59:14 2018
New Revision: 331172

URL: http://llvm.org/viewvc/llvm-project?rev=331172&view=rev
Log:
Fixup r331049 (FileSpec auto-normalization)

A typo in the patch (using syntax instead of m_syntax) resulted in the
normalization not working properly for windows filespecs when the syntax
was passed as host-native. This did not affect the unit tests, as all of
those pass an explicity syntax, but failed gloriously when running the
full test suite.

I also fix an expectation in an lldb-mi test, which was now failing
because it was expecting a path to be echoed verbatim, but we were now
normalizing it.

As a drive-by, this also fixes the default-in-fully-covered-switch
warning and removes an unused argument from the NeedsNormalization
function.

Modified:

lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/startup_options/TestMiStartupOptions.py
lldb/trunk/source/Utility/FileSpec.cpp

Modified: 
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/startup_options/TestMiStartupOptions.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/startup_options/TestMiStartupOptions.py?rev=331172&r1=331171&r2=331172&view=diff
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/startup_options/TestMiStartupOptions.py
 (original)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/startup_options/TestMiStartupOptions.py
 Mon Apr 30 05:59:14 2018
@@ -117,7 +117,7 @@ class MiStartupOptionsTestCase(lldbmi_te
 """Test that 'lldb-mi --interpreter %s' fails on executable file which 
is specified via unknown path."""
 
 # Prepare path to executable
-path = "unknown_dir/%s" % self.myexe
+path = "unknown_dir" + self.myexe
 
 self.spawnLldbMi(args="%s" % path)
 

Modified: lldb/trunk/source/Utility/FileSpec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/FileSpec.cpp?rev=331172&r1=331171&r2=331172&view=diff
==
--- lldb/trunk/source/Utility/FileSpec.cpp (original)
+++ lldb/trunk/source/Utility/FileSpec.cpp Mon Apr 30 05:59:14 2018
@@ -69,7 +69,6 @@ LLVMPathSyntax(FileSpec::PathSyntax lldb
   return llvm::sys::path::Style::posix;
 case FileSpec::ePathSyntaxWindows:
   return llvm::sys::path::Style::windows;
-default:
 case FileSpec::ePathSyntaxHostNative:
   return llvm::sys::path::Style::native;
   };
@@ -236,14 +235,10 @@ inline char safeCharAtIndex(const llvm::
 /// @param[in] path
 /// A full, partial, or relative path to a file.
 ///
-/// @param[in] syntax
-/// The syntax enumeration for the path in \a path.
-///
 /// @return
 ///   Returns \b true if the path needs to be normalized.
 //--
-bool needsNormalization(const llvm::StringRef &path,
-FileSpec::PathSyntax syntax) {
+bool needsNormalization(const llvm::StringRef &path) {
   if (path.empty())
 return false;
   // We strip off leading "." values so these paths need to be normalized
@@ -338,12 +333,11 @@ void FileSpec::SetFile(llvm::StringRef p
   }
 
   // Normalize the path by removing ".", ".." and other redundant components.
-  if (needsNormalization(llvm::StringRef(resolved.data(), resolved.size()),
- syntax))
-llvm::sys::path::remove_dots(resolved, true, LLVMPathSyntax(syntax));
+  if (needsNormalization(resolved))
+llvm::sys::path::remove_dots(resolved, true, LLVMPathSyntax(m_syntax));
 
   // Normalize back slashes to forward slashes
-  if (syntax == FileSpec::ePathSyntaxWindows)
+  if (m_syntax == FileSpec::ePathSyntaxWindows)
 std::replace(resolved.begin(), resolved.end(), '\\', '/');
 
   llvm::StringRef resolve_path_ref(resolved.c_str());


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


[Lldb-commits] [PATCH] D46144: Reflow paragraphs in comments.

2018-04-30 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a comment.
This revision is now accepted and ready to land.

Looks fine to me, I guess if noone objects, we can land this. Thanks for doing 
this.


https://reviews.llvm.org/D46144



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


[Lldb-commits] [PATCH] D46128: Fix expression parser to not accept any type whose basename matches for a type that must exist at root level

2018-04-30 Thread Pavel Labath via Phabricator via lldb-commits
labath resigned from this revision.
labath added a comment.

Jim seems to have an idea on how the type lookup should work, so I'll defer to 
him.


https://reviews.llvm.org/D46128



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


[Lldb-commits] [PATCH] D44998: ObjectFileELF: Add support for arbitrarily named code sections

2018-04-30 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

I've committed this as r331173. I've had to revert the lldb-test changes, as 
something similar has been implemented already, and I've merged your lldb-test 
test with an existing section types test.


https://reviews.llvm.org/D44998



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


[Lldb-commits] [lldb] r331173 - ObjectFileELF: Add support for arbitrarily named code sections

2018-04-30 Thread Pavel Labath via lldb-commits
Author: labath
Date: Mon Apr 30 06:23:47 2018
New Revision: 331173

URL: http://llvm.org/viewvc/llvm-project?rev=331173&view=rev
Log:
ObjectFileELF: Add support for arbitrarily named code sections

ObjectFileELF assumes that code section has ".text" name. There is an
exception for kalimba toolchain that can use arbitrary names, but other
toolchains also could use arbitrary names for code sections. For
example, corert uses separate section for compiled managed code. As lldb
doesn't recognize such section it leads to problem with breakpoints on
arm, because debugger cannot determine instruction set (arm/thumb) and
uses incorrect breakpoint opcode that breaks program execution.

This change allows debugger to correctly handle such code sections. We
assume that section is a code section if it has SHF_EXECINSTR flag set
and has SHT_PROGBITS type.

Patch by Konstantin Baladurin .
Differential Revision: https://reviews.llvm.org/D44998

Added:
lldb/trunk/lit/Modules/elf-section-types.yaml
  - copied, changed from r331172, 
lldb/trunk/lit/Modules/dwarf-gnu-debugaltlink.yaml
lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/

lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/Makefile

lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/TestBreakpointThumbCodesection.py

lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/main.c
Removed:
lldb/trunk/lit/Modules/dwarf-gnu-debugaltlink.yaml
Modified:
lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Removed: lldb/trunk/lit/Modules/dwarf-gnu-debugaltlink.yaml
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Modules/dwarf-gnu-debugaltlink.yaml?rev=331172&view=auto
==
--- lldb/trunk/lit/Modules/dwarf-gnu-debugaltlink.yaml (original)
+++ lldb/trunk/lit/Modules/dwarf-gnu-debugaltlink.yaml (removed)
@@ -1,25 +0,0 @@
-# RUN: yaml2obj %s > %t
-# RUN: lldb-test module-sections %t | FileCheck %s
-
-# CHECK: Name: .gnu_debugaltlink
-# CHECK-NEXT: Type: dwarf-gnu-debugaltlink
-# CHECK-NEXT: VM size: 0
-# CHECK-NEXT: File size: 8
-
 !ELF
-FileHeader:  
-  Class:   ELFCLASS64
-  Data:ELFDATA2LSB
-  Type:ET_DYN
-  Machine: EM_X86_64
-  Entry:   0x07A0
-Sections:
-  - Name:.debug_info
-Type:SHT_PROGBITS
-AddressAlign:0x0001
-Content: DEADBEEFBAADF00D
-  - Name:.gnu_debugaltlink
-Type:SHT_PROGBITS
-AddressAlign:0x0001
-Content: DEADBEEFBAADF00D
-...

Copied: lldb/trunk/lit/Modules/elf-section-types.yaml (from r331172, 
lldb/trunk/lit/Modules/dwarf-gnu-debugaltlink.yaml)
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Modules/elf-section-types.yaml?p2=lldb/trunk/lit/Modules/elf-section-types.yaml&p1=lldb/trunk/lit/Modules/dwarf-gnu-debugaltlink.yaml&r1=331172&r2=331173&rev=331173&view=diff
==
--- lldb/trunk/lit/Modules/dwarf-gnu-debugaltlink.yaml (original)
+++ lldb/trunk/lit/Modules/elf-section-types.yaml Mon Apr 30 06:23:47 2018
@@ -1,11 +1,17 @@
 # RUN: yaml2obj %s > %t
 # RUN: lldb-test module-sections %t | FileCheck %s
 
+# CHECK: Name: .text
+# CHECK-NEXT: Type: code
+
 # CHECK: Name: .gnu_debugaltlink
 # CHECK-NEXT: Type: dwarf-gnu-debugaltlink
 # CHECK-NEXT: VM size: 0
 # CHECK-NEXT: File size: 8
 
+# CHECK: Name: __codesection
+# CHECK-NEXT: Type: code
+
 --- !ELF
 FileHeader:  
   Class:   ELFCLASS64
@@ -14,6 +20,10 @@ FileHeader:
   Machine: EM_X86_64
   Entry:   0x07A0
 Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Content: DEADBEEFBAADF00D
   - Name:.debug_info
 Type:SHT_PROGBITS
 AddressAlign:0x0001
@@ -22,4 +32,8 @@ Sections:
 Type:SHT_PROGBITS
 AddressAlign:0x0001
 Content: DEADBEEFBAADF00D
+  - Name:__codesection
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Content: DEADBEEFBAADF00D
 ...

Added: 
lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/Makefile
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/Makefile?rev=331173&view=auto
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/Makefile
 (added)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/Makefile
 Mon Apr 30 06:23:47 2018
@@ -0,0 +1,6 @@
+LEVEL = ../../make
+
+C_SOURCES := main.c
+CFLAGS_EXTRAS 

[Lldb-commits] [PATCH] D44998: ObjectFileELF: Add support for arbitrarily named code sections

2018-04-30 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331173: ObjectFileELF: Add support for arbitrarily named 
code sections (authored by labath, committed by ).
Herald added a subscriber: JDevlieghere.

Changed prior to commit:
  https://reviews.llvm.org/D44998?vs=140628&id=144547#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44998

Files:
  lldb/trunk/lit/Modules/dwarf-gnu-debugaltlink.yaml
  lldb/trunk/lit/Modules/elf-section-types.yaml
  
lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/Makefile
  
lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/TestBreakpointThumbCodesection.py
  
lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/main.c
  lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Index: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -1950,6 +1950,16 @@
 sect_type = kalimbaSectionType(m_header, header);
   }
 
+  // In common case ELF code section can have arbitrary name (for example,
+  // we can specify it using section attribute for particular function) so
+  // assume that section is a code section if it has SHF_EXECINSTR flag set
+  // and has SHT_PROGBITS type.
+  if (eSectionTypeOther == sect_type &&
+  llvm::ELF::SHT_PROGBITS == header.sh_type &&
+  (header.sh_flags & SHF_EXECINSTR)) {
+sect_type = eSectionTypeCode;
+  }
+
   const uint32_t target_bytes_size =
   (eSectionTypeData == sect_type || eSectionTypeZeroFill == sect_type)
   ? m_arch_spec.GetDataByteSize()
Index: lldb/trunk/lit/Modules/elf-section-types.yaml
===
--- lldb/trunk/lit/Modules/elf-section-types.yaml
+++ lldb/trunk/lit/Modules/elf-section-types.yaml
@@ -0,0 +1,39 @@
+# RUN: yaml2obj %s > %t
+# RUN: lldb-test module-sections %t | FileCheck %s
+
+# CHECK: Name: .text
+# CHECK-NEXT: Type: code
+
+# CHECK: Name: .gnu_debugaltlink
+# CHECK-NEXT: Type: dwarf-gnu-debugaltlink
+# CHECK-NEXT: VM size: 0
+# CHECK-NEXT: File size: 8
+
+# CHECK: Name: __codesection
+# CHECK-NEXT: Type: code
+
+--- !ELF
+FileHeader:  
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_DYN
+  Machine: EM_X86_64
+  Entry:   0x07A0
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Content: DEADBEEFBAADF00D
+  - Name:.debug_info
+Type:SHT_PROGBITS
+AddressAlign:0x0001
+Content: DEADBEEFBAADF00D
+  - Name:.gnu_debugaltlink
+Type:SHT_PROGBITS
+AddressAlign:0x0001
+Content: DEADBEEFBAADF00D
+  - Name:__codesection
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Content: DEADBEEFBAADF00D
+...
Index: lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/main.c
===
--- lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/main.c
+++ lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/main.c
@@ -0,0 +1,8 @@
+__attribute__((section("__codesection")))
+int f(int a) {
+  return a + 1; // Set break point at this line.
+}
+
+int main() {
+  return f(10);
+}
Index: lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/TestBreakpointThumbCodesection.py
===
--- lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/TestBreakpointThumbCodesection.py
+++ lldb/trunk/packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/TestBreakpointThumbCodesection.py
@@ -0,0 +1,35 @@
+"""
+Test that breakpoints correctly work in an thumb function in an arbitrary
+named codesection.
+"""
+from __future__ import print_function
+
+
+import lldb
+import os
+import time
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestBreakpointThumbCodesection(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@skipIf(archs=no_match(["arm"]))
+def test_breakpoint(self):
+self.build()
+exe = self.getBuildArtifact("a.out")
+line = line_number('main.c', '// Set break point at this line.')
+
+self.runCmd("target create %s" % exe)
+bpid = lldbutil.run_break_set_by_file_and_line(self, "main.c", line)
+
+self.runCmd("run")
+
+self.assertIsNotNone(lldbutil.get_one_thread_stopped_at_breakpoint_i

[Lldb-commits] [PATCH] D40469: DWZ 02/07: Match also DW_TAG_partial_unit when DW_TAG_compile_unit is matched

2018-04-30 Thread Pavel Labath via Phabricator via lldb-commits
labath edited reviewers, added: aprantl, JDevlieghere; removed: labath.
labath added a comment.

Adding some debug info people, as I don't feel qualified to review this.


https://reviews.llvm.org/D40469



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


[Lldb-commits] [lldb] r331180 - llgs tests: Use noack-mode for communication to avoid pr37294

2018-04-30 Thread Pavel Labath via lldb-commits
Author: labath
Date: Mon Apr 30 07:30:02 2018
New Revision: 331180

URL: http://llvm.org/viewvc/llvm-project?rev=331180&view=rev
Log:
llgs tests: Use noack-mode for communication to avoid pr37294

Modified:
lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp
lldb/trunk/unittests/tools/lldb-server/tests/TestClient.h

Modified: lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp?rev=331180&r1=331179&r2=331180&view=diff
==
--- lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp (original)
+++ lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp Mon Apr 30 
07:30:02 2018
@@ -30,8 +30,6 @@ using namespace llgs_tests;
 TestClient::TestClient(std::unique_ptr Conn) {
   SetConnection(Conn.release());
   SetPacketTimeout(std::chrono::seconds(10));
-
-  SendAck(); // Send this as a handshake.
 }
 
 TestClient::~TestClient() {
@@ -41,6 +39,18 @@ TestClient::~TestClient() {
   EXPECT_THAT_ERROR(SendMessage("k"), Succeeded());
 }
 
+Error TestClient::initializeConnection() {
+  if (SendAck() == 0)
+return make_error("Sending initial ACK failed.",
+   inconvertibleErrorCode());
+
+  if (Error E = SendMessage("QStartNoAckMode"))
+return E;
+
+  m_send_acks = false;
+  return Error::success();
+}
+
 Expected> TestClient::launch(StringRef Log) {
   return launch(Log, {});
 }
@@ -97,6 +107,9 @@ Expected> Te
   auto Conn = llvm::make_unique(accept_socket);
   auto Client = std::unique_ptr(new TestClient(std::move(Conn)));
 
+  if (Error E = Client->initializeConnection())
+return std::move(E);
+
   if (!InferiorArgs.empty()) {
 if (Error E = Client->queryProcess())
   return std::move(E);

Modified: lldb/trunk/unittests/tools/lldb-server/tests/TestClient.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/tools/lldb-server/tests/TestClient.h?rev=331180&r1=331179&r2=331180&view=diff
==
--- lldb/trunk/unittests/tools/lldb-server/tests/TestClient.h (original)
+++ lldb/trunk/unittests/tools/lldb-server/tests/TestClient.h Mon Apr 30 
07:30:02 2018
@@ -83,6 +83,7 @@ public:
 private:
   TestClient(std::unique_ptr Conn);
 
+  llvm::Error initializeConnection();
   llvm::Error qProcessInfo();
   llvm::Error qRegisterInfos();
   llvm::Error queryProcess();


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


[Lldb-commits] [PATCH] D46144: Reflow paragraphs in comments.

2018-04-30 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.

👍




Comment at: source/Host/common/MainLoop.cpp:158
   // ppoll(2) is not supported on older all android versions. Also, older
-  // versions android (API <= 19) implemented pselect in a non-atomic way, as a
-  // combination of pthread_sigmask and select. This is not sufficient for us,

Is this intentional or maybe an off-by-one error? The `a` is in the 79th colum, 
which is okay for clang-format. 


https://reviews.llvm.org/D46144



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


[Lldb-commits] [PATCH] D46144: Reflow paragraphs in comments.

2018-04-30 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added inline comments.



Comment at: source/Host/common/MainLoop.cpp:158
   // ppoll(2) is not supported on older all android versions. Also, older
-  // versions android (API <= 19) implemented pselect in a non-atomic way, as a
-  // combination of pthread_sigmask and select. This is not sufficient for us,

JDevlieghere wrote:
> Is this intentional or maybe an off-by-one error? The `a` is in the 79th 
> colum, which is okay for clang-format. 
My script sets the threshold to 78 columns. When you are on an 80-column 
terminal and your editor doesn't indicate whether long lines continue or not 
then not using the last two characters makes it unambiguous whether the `a` is 
the beginning of a new word or whether it stands for itself.
I'll change the threshold to 80 columns to avoid reflowing paragraphs that 
don't need it.


https://reviews.llvm.org/D46144



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


[Lldb-commits] [lldb] r331194 - Match also DW_TAG_partial_unit when DW_TAG_compile_unit is matched

2018-04-30 Thread Jan Kratochvil via lldb-commits
Author: jankratochvil
Date: Mon Apr 30 09:04:32 2018
New Revision: 331194

URL: http://llvm.org/viewvc/llvm-project?rev=331194&view=rev
Log:
Match also DW_TAG_partial_unit when DW_TAG_compile_unit is matched

Code commonly checks if the parent DIE is DW_TAG_compile_unit.
But DW_TAG_partial_unit also acts as DW_TAG_compile_unit for DWZ
as DWZ is using DW_TAG_imported_unit only at the top unit level.

Differential revision: https://reviews.llvm.org/D40469

Modified:
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserOCaml.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp?rev=331194&r1=331193&r2=331194&view=diff
==
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
(original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp Mon Apr 
30 09:04:32 2018
@@ -1925,7 +1925,8 @@ TypeSP DWARFASTParserClang::ParseTypeFro
 dw_tag_t sc_parent_tag = sc_parent_die.Tag();
 
 SymbolContextScope *symbol_context_scope = NULL;
-if (sc_parent_tag == DW_TAG_compile_unit) {
+if (sc_parent_tag == DW_TAG_compile_unit ||
+sc_parent_tag == DW_TAG_partial_unit) {
   symbol_context_scope = sc.comp_unit;
 } else if (sc.function != NULL && sc_parent_die) {
   symbol_context_scope =
@@ -2745,7 +2746,8 @@ Function *DWARFASTParserClang::ParseFunc
   Mangled func_name;
   if (mangled)
 func_name.SetValue(ConstString(mangled), true);
-  else if (die.GetParent().Tag() == DW_TAG_compile_unit &&
+  else if ((die.GetParent().Tag() == DW_TAG_compile_unit ||
+die.GetParent().Tag() == DW_TAG_partial_unit) &&
Language::LanguageIsCPlusPlus(die.GetLanguage()) && name &&
strcmp(name, "main") != 0) {
 // If the mangled name is not present in the DWARF, generate the
@@ -3838,6 +3840,7 @@ DWARFASTParserClang::GetClangDeclContext
 bool try_parsing_type = true;
 switch (die.Tag()) {
 case DW_TAG_compile_unit:
+case DW_TAG_partial_unit:
   decl_ctx = m_ast.GetTranslationUnitDecl();
   try_parsing_type = false;
   break;

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp?rev=331194&r1=331193&r2=331194&view=diff
==
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp Mon Apr 30 
09:04:32 2018
@@ -431,7 +431,8 @@ TypeSP DWARFASTParserGo::ParseTypeFromDW
 dw_tag_t sc_parent_tag = sc_parent_die.Tag();
 
 SymbolContextScope *symbol_context_scope = NULL;
-if (sc_parent_tag == DW_TAG_compile_unit) {
+if (sc_parent_tag == DW_TAG_compile_unit ||
+sc_parent_tag == DW_TAG_partial_unit) {
   symbol_context_scope = sc.comp_unit;
 } else if (sc.function != NULL && sc_parent_die) {
   symbol_context_scope =

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp?rev=331194&r1=331193&r2=331194&view=diff
==
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp Mon Apr 
30 09:04:32 2018
@@ -324,7 +324,8 @@ lldb::TypeSP DWARFASTParserJava::ParseTy
   dw_tag_t sc_parent_tag = sc_parent_die.Tag();
 
   SymbolContextScope *symbol_context_scope = nullptr;
-  if (sc_parent_tag == DW_TAG_compile_unit) {
+  if (sc_parent_tag == DW_TAG_compile_unit ||
+  sc_parent_tag == DW_TAG_partial_unit) {
 symbol_context_scope = sc.comp_unit;
   } else if (sc.function != nullptr && sc_parent_die) {
 symbol_context_scope =

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserOCaml.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserOCaml.cpp?rev=331194&r1=331193&r2=331194&view=diff

[Lldb-commits] [PATCH] D40469: DWZ 02/07: Match also DW_TAG_partial_unit when DW_TAG_compile_unit is matched

2018-04-30 Thread Jan Kratochvil via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331194: Match also DW_TAG_partial_unit when 
DW_TAG_compile_unit is matched (authored by jankratochvil, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D40469?vs=143476&id=144570#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40469

Files:
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserOCaml.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp

Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
@@ -57,6 +57,7 @@
   } break;
 
   case DW_TAG_compile_unit:
+  case DW_TAG_partial_unit:
 done = true;
 break;
   }
Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1925,7 +1925,8 @@
 dw_tag_t sc_parent_tag = sc_parent_die.Tag();
 
 SymbolContextScope *symbol_context_scope = NULL;
-if (sc_parent_tag == DW_TAG_compile_unit) {
+if (sc_parent_tag == DW_TAG_compile_unit ||
+sc_parent_tag == DW_TAG_partial_unit) {
   symbol_context_scope = sc.comp_unit;
 } else if (sc.function != NULL && sc_parent_die) {
   symbol_context_scope =
@@ -2745,7 +2746,8 @@
   Mangled func_name;
   if (mangled)
 func_name.SetValue(ConstString(mangled), true);
-  else if (die.GetParent().Tag() == DW_TAG_compile_unit &&
+  else if ((die.GetParent().Tag() == DW_TAG_compile_unit ||
+die.GetParent().Tag() == DW_TAG_partial_unit) &&
Language::LanguageIsCPlusPlus(die.GetLanguage()) && name &&
strcmp(name, "main") != 0) {
 // If the mangled name is not present in the DWARF, generate the
@@ -3838,6 +3840,7 @@
 bool try_parsing_type = true;
 switch (die.Tag()) {
 case DW_TAG_compile_unit:
+case DW_TAG_partial_unit:
   decl_ctx = m_ast.GetTranslationUnitDecl();
   try_parsing_type = false;
   break;
Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -262,7 +262,7 @@
 
 void DWARFDIE::GetDWOContext(std::vector &context) const {
   const dw_tag_t tag = Tag();
-  if (tag == DW_TAG_compile_unit)
+  if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
 return;
   DWARFDIE parent = GetParent();
   if (parent)
@@ -369,7 +369,7 @@
   const dw_tag_t tag = parent.Tag();
   if (tag == DW_TAG_module)
 top_module_die = parent;
-  else if (tag == DW_TAG_compile_unit)
+  else if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
 break;
 }
 
Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp
@@ -431,7 +431,8 @@
 dw_tag_t sc_parent_tag = sc_parent_die.Tag();
 
 SymbolContextScope *symbol_context_scope = NULL;
-if (sc_parent_tag == DW_TAG_compile_unit) {
+if (sc_parent_tag == DW_TAG_compile_unit ||
+sc_parent_tag == DW_TAG_partial_unit) {
   symbol_context_scope = sc.comp_unit;
 } else if (sc.function != NULL && sc_parent_die) {
   symbol_context_scope =
Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -218,7 +218,8 @@
 m_tag = abbrevDecl->Tag();
 m_has_children = abbrevDecl->HasChildren();
 
-bool isCompileUnitTag = m_tag == DW_TAG_compile_unit;
+bool isCompileUnitTag = (m_tag == DW_TAG_compile_unit ||
+  

[Lldb-commits] [PATCH] D46144: Reflow paragraphs in comments.

2018-04-30 Thread Phabricator via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331197: Reflow paragraphs in comments. (authored by adrian, 
committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46144?vs=144420&id=144575#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46144

Files:
  lldb/trunk/include/lldb/API/SBAddress.h
  lldb/trunk/include/lldb/API/SBBroadcaster.h
  lldb/trunk/include/lldb/API/SBCommandInterpreter.h
  lldb/trunk/include/lldb/API/SBCommandReturnObject.h
  lldb/trunk/include/lldb/API/SBData.h
  lldb/trunk/include/lldb/API/SBExpressionOptions.h
  lldb/trunk/include/lldb/API/SBFrame.h
  lldb/trunk/include/lldb/API/SBInstruction.h
  lldb/trunk/include/lldb/API/SBInstructionList.h
  lldb/trunk/include/lldb/API/SBProcess.h
  lldb/trunk/include/lldb/API/SBStream.h
  lldb/trunk/include/lldb/API/SBSymbol.h
  lldb/trunk/include/lldb/API/SBTarget.h
  lldb/trunk/include/lldb/API/SBValue.h
  lldb/trunk/include/lldb/API/SBValueList.h
  lldb/trunk/include/lldb/Breakpoint/Breakpoint.h
  lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h
  lldb/trunk/include/lldb/Breakpoint/BreakpointLocationCollection.h
  lldb/trunk/include/lldb/Breakpoint/BreakpointLocationList.h
  lldb/trunk/include/lldb/Breakpoint/BreakpointName.h
  lldb/trunk/include/lldb/Breakpoint/BreakpointOptions.h
  lldb/trunk/include/lldb/Breakpoint/BreakpointResolver.h
  lldb/trunk/include/lldb/Breakpoint/BreakpointResolverAddress.h
  lldb/trunk/include/lldb/Breakpoint/BreakpointResolverName.h
  lldb/trunk/include/lldb/Breakpoint/BreakpointSite.h
  lldb/trunk/include/lldb/Breakpoint/StoppointLocation.h
  lldb/trunk/include/lldb/Breakpoint/Watchpoint.h
  lldb/trunk/include/lldb/Breakpoint/WatchpointList.h
  lldb/trunk/include/lldb/Breakpoint/WatchpointOptions.h
  lldb/trunk/include/lldb/Core/Address.h
  lldb/trunk/include/lldb/Core/AddressRange.h
  lldb/trunk/include/lldb/Core/AddressResolverName.h
  lldb/trunk/include/lldb/Core/Broadcaster.h
  lldb/trunk/include/lldb/Core/Debugger.h
  lldb/trunk/include/lldb/Core/Disassembler.h
  lldb/trunk/include/lldb/Core/EmulateInstruction.h
  lldb/trunk/include/lldb/Core/FormatEntity.h
  lldb/trunk/include/lldb/Core/IOHandler.h
  lldb/trunk/include/lldb/Core/MappedHash.h
  lldb/trunk/include/lldb/Core/Module.h
  lldb/trunk/include/lldb/Core/ModuleList.h
  lldb/trunk/include/lldb/Core/ModuleSpec.h
  lldb/trunk/include/lldb/Core/PluginManager.h
  lldb/trunk/include/lldb/Core/RangeMap.h
  lldb/trunk/include/lldb/Core/RegisterValue.h
  lldb/trunk/include/lldb/Core/STLUtils.h
  lldb/trunk/include/lldb/Core/Scalar.h
  lldb/trunk/include/lldb/Core/SearchFilter.h
  lldb/trunk/include/lldb/Core/Section.h
  lldb/trunk/include/lldb/Core/SourceManager.h
  lldb/trunk/include/lldb/Core/StreamBuffer.h
  lldb/trunk/include/lldb/Core/UniqueCStringMap.h
  lldb/trunk/include/lldb/Core/UserSettingsController.h
  lldb/trunk/include/lldb/Core/Value.h
  lldb/trunk/include/lldb/Core/ValueObject.h
  lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h
  lldb/trunk/include/lldb/DataFormatters/DataVisualization.h
  lldb/trunk/include/lldb/DataFormatters/FormatClasses.h
  lldb/trunk/include/lldb/DataFormatters/FormatManager.h
  lldb/trunk/include/lldb/DataFormatters/FormattersContainer.h
  lldb/trunk/include/lldb/DataFormatters/StringPrinter.h
  lldb/trunk/include/lldb/DataFormatters/TypeFormat.h
  lldb/trunk/include/lldb/DataFormatters/TypeSummary.h
  lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h
  lldb/trunk/include/lldb/DataFormatters/TypeValidator.h
  lldb/trunk/include/lldb/DataFormatters/ValueObjectPrinter.h
  lldb/trunk/include/lldb/Expression/ExpressionSourceCode.h
  lldb/trunk/include/lldb/Expression/ExpressionVariable.h
  lldb/trunk/include/lldb/Expression/IRMemoryMap.h
  lldb/trunk/include/lldb/Expression/LLVMUserExpression.h
  lldb/trunk/include/lldb/Expression/UtilityFunction.h
  lldb/trunk/include/lldb/Host/Debug.h
  lldb/trunk/include/lldb/Host/Editline.h
  lldb/trunk/include/lldb/Host/MainLoop.h
  lldb/trunk/include/lldb/Host/MainLoopBase.h
  lldb/trunk/include/lldb/Host/PosixApi.h
  lldb/trunk/include/lldb/Host/Predicate.h
  lldb/trunk/include/lldb/Host/Socket.h
  lldb/trunk/include/lldb/Host/SocketAddress.h
  lldb/trunk/include/lldb/Host/Symbols.h
  lldb/trunk/include/lldb/Host/TaskPool.h
  lldb/trunk/include/lldb/Host/XML.h
  lldb/trunk/include/lldb/Host/common/GetOptInc.h
  lldb/trunk/include/lldb/Host/common/NativeBreakpoint.h
  lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h
  lldb/trunk/include/lldb/Host/common/NativeRegisterContext.h
  lldb/trunk/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h
  lldb/trunk/include/lldb/Interpreter/CommandAlias.h
  lldb/trunk/include/lldb/Interpreter/CommandCompletions.h
  lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
  lldb/trunk/include/lldb/Interpreter/CommandObject.h
  lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h
  lldb/trunk/inclu

[Lldb-commits] [PATCH] D40470: DWZ 03/07: Protect DWARFCompileUnit::m_die_array by a new mutex

2018-04-30 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil updated this revision to Diff 144576.

https://reviews.llvm.org/D40470

Files:
  source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  source/Plugins/SymbolFile/DWARF/DWARFUnit.h


Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.h
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -141,6 +141,8 @@
   void *m_user_data = nullptr;
   // The compile unit debug information entry item
   DWARFDebugInfoEntry::collection m_die_array;
+  // Prevent m_extractdies_mutex lock overhead for most cases.
+  std::atomic_size_t m_die_array_size_atomic { 0 };
   // A table similar to the .debug_aranges table, but this one points to the
   // exact DW_TAG_subprogram DIEs
   std::unique_ptr m_func_aranges_ap;
@@ -160,6 +162,7 @@
   // If this is a dwo compile unit this is the offset of the base compile unit
   // in the main object file
   dw_offset_t m_base_obj_offset = DW_INVALID_OFFSET;
+  std::mutex m_extractdies_mutex;
 
   static void
   IndexPrivate(DWARFUnit *dwarf_cu, const lldb::LanguageType cu_language,
Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -42,9 +42,19 @@
 // done.
 //--
 size_t DWARFUnit::ExtractDIEsIfNeeded(bool cu_die_only) {
-  const size_t initial_die_array_size = m_die_array.size();
-  if ((cu_die_only && initial_die_array_size > 0) || initial_die_array_size > 
1)
-return 0; // Already parsed
+  size_t initial_die_array_size;
+  auto already_parsed = [cu_die_only, &initial_die_array_size, this]() -> bool 
{
+initial_die_array_size = m_die_array_size_atomic;
+return (cu_die_only && initial_die_array_size > 0)
+|| initial_die_array_size > 1;
+  };
+  if (already_parsed())
+return 0;
+  std::lock_guard guard(m_extractdies_mutex);
+  if (already_parsed())
+return 0;
+  std::shared_ptr m_die_array_size_atomic_set(nullptr,
+  [&](void*){ m_die_array_size_atomic = m_die_array.size(); });
 
   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
   Timer scoped_timer(
@@ -307,6 +317,8 @@
 
 void DWARFUnit::ClearDIEs(bool keep_compile_unit_die) {
   if (m_die_array.size() > 1) {
+std::lock_guard guard(m_extractdies_mutex);
+
 // std::vectors never get any smaller when resized to a smaller size,
 // or when clear() or erase() are called, the size will report that it
 // is smaller, but the memory allocated remains intact (call capacity()
@@ -318,8 +330,11 @@
 // Save at least the compile unit DIE
 DWARFDebugInfoEntry::collection tmp_array;
 m_die_array.swap(tmp_array);
-if (keep_compile_unit_die)
+m_die_array_size_atomic = 0;
+if (keep_compile_unit_die) {
   m_die_array.push_back(tmp_array.front());
+  ++m_die_array_size_atomic;
+}
   }
 
   if (m_dwo_symbol_file)


Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.h
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -141,6 +141,8 @@
   void *m_user_data = nullptr;
   // The compile unit debug information entry item
   DWARFDebugInfoEntry::collection m_die_array;
+  // Prevent m_extractdies_mutex lock overhead for most cases.
+  std::atomic_size_t m_die_array_size_atomic { 0 };
   // A table similar to the .debug_aranges table, but this one points to the
   // exact DW_TAG_subprogram DIEs
   std::unique_ptr m_func_aranges_ap;
@@ -160,6 +162,7 @@
   // If this is a dwo compile unit this is the offset of the base compile unit
   // in the main object file
   dw_offset_t m_base_obj_offset = DW_INVALID_OFFSET;
+  std::mutex m_extractdies_mutex;
 
   static void
   IndexPrivate(DWARFUnit *dwarf_cu, const lldb::LanguageType cu_language,
Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -42,9 +42,19 @@
 // done.
 //--
 size_t DWARFUnit::ExtractDIEsIfNeeded(bool cu_die_only) {
-  const size_t initial_die_array_size = m_die_array.size();
-  if ((cu_die_only && initial_die_array_size > 0) || initial_die_array_size > 1)
-return 0; // Already parsed
+  size_t initial_die_array_size;
+  auto already_parsed = [cu_die_only, &initial_die_array_size, this]() -> bool {
+initial_die_array_size = m_die_array_size_atomic;
+return (cu_die_only && initial_die_array_size > 0)
+|| initial_die_array_size > 1;
+  };
+  if (already_parsed())
+return 0;
+  std::lock_guard guard(m_extractdies_mutex);
+  if (already_parsed())
+return 0;
+  std::shared_ptr m_die_arr

[Lldb-commits] [PATCH] D40470: DWZ 03/07: Protect DWARFCompileUnit::m_die_array by a new mutex

2018-04-30 Thread Greg Clayton via Phabricator via lldb-commits
clayborg requested changes to this revision.
clayborg added inline comments.
This revision now requires changes to proceed.



Comment at: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp:56
+return 0;
+  std::shared_ptr m_die_array_size_atomic_set(nullptr,
+  [&](void*){ m_die_array_size_atomic = m_die_array.size(); });

Remove the "m_" prefix on this local variable as that indicates it is a member 
variable. 

Might be better to use CleanUp utility from "lldb/Utility/CleanUp.h" instead of 
a shared pointer to void? Took me a bit to figure out what this was doing. If 
this is a very accepted C++ way to run a function that is scoped that is fine, 
but it seems a little unclear what this was doing initially.



https://reviews.llvm.org/D40470



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


[Lldb-commits] [PATCH] D40470: DWZ 03/07: Protect DWARFCompileUnit::m_die_array by a new mutex

2018-04-30 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil updated this revision to Diff 144589.
jankratochvil added a comment.

Removed the `m_die_array_size_atomic_set` `m_` prefix, used `CleanUp`.


https://reviews.llvm.org/D40470

Files:
  source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  source/Plugins/SymbolFile/DWARF/DWARFUnit.h


Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.h
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -141,6 +141,8 @@
   void *m_user_data = nullptr;
   // The compile unit debug information entry item
   DWARFDebugInfoEntry::collection m_die_array;
+  // Prevent m_extractdies_mutex lock overhead for most cases.
+  std::atomic_size_t m_die_array_size_atomic { 0 };
   // A table similar to the .debug_aranges table, but this one points to the
   // exact DW_TAG_subprogram DIEs
   std::unique_ptr m_func_aranges_ap;
@@ -160,6 +162,7 @@
   // If this is a dwo compile unit this is the offset of the base compile unit
   // in the main object file
   dw_offset_t m_base_obj_offset = DW_INVALID_OFFSET;
+  std::mutex m_extractdies_mutex;
 
   static void
   IndexPrivate(DWARFUnit *dwarf_cu, const lldb::LanguageType cu_language,
Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -15,6 +15,7 @@
 #include "lldb/Symbol/CompileUnit.h"
 #include "lldb/Symbol/LineTable.h"
 #include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/CleanUp.h"
 #include "lldb/Utility/Timer.h"
 
 #include "DWARFDIECollection.h"
@@ -42,9 +43,20 @@
 // done.
 //--
 size_t DWARFUnit::ExtractDIEsIfNeeded(bool cu_die_only) {
-  const size_t initial_die_array_size = m_die_array.size();
-  if ((cu_die_only && initial_die_array_size > 0) || initial_die_array_size > 
1)
-return 0; // Already parsed
+  size_t initial_die_array_size;
+  auto already_parsed = [cu_die_only, &initial_die_array_size, this]() -> bool 
{
+initial_die_array_size = m_die_array_size_atomic;
+return (cu_die_only && initial_die_array_size > 0)
+|| initial_die_array_size > 1;
+  };
+  if (already_parsed())
+return 0;
+  std::lock_guard guard(m_extractdies_mutex);
+  if (already_parsed())
+return 0;
+  CleanUp die_array_size_atomic_set([this](){
+m_die_array_size_atomic = m_die_array.size();
+  });
 
   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
   Timer scoped_timer(
@@ -307,6 +319,8 @@
 
 void DWARFUnit::ClearDIEs(bool keep_compile_unit_die) {
   if (m_die_array.size() > 1) {
+std::lock_guard guard(m_extractdies_mutex);
+
 // std::vectors never get any smaller when resized to a smaller size,
 // or when clear() or erase() are called, the size will report that it
 // is smaller, but the memory allocated remains intact (call capacity()
@@ -318,8 +332,11 @@
 // Save at least the compile unit DIE
 DWARFDebugInfoEntry::collection tmp_array;
 m_die_array.swap(tmp_array);
-if (keep_compile_unit_die)
+m_die_array_size_atomic = 0;
+if (keep_compile_unit_die) {
   m_die_array.push_back(tmp_array.front());
+  ++m_die_array_size_atomic;
+}
   }
 
   if (m_dwo_symbol_file)


Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.h
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -141,6 +141,8 @@
   void *m_user_data = nullptr;
   // The compile unit debug information entry item
   DWARFDebugInfoEntry::collection m_die_array;
+  // Prevent m_extractdies_mutex lock overhead for most cases.
+  std::atomic_size_t m_die_array_size_atomic { 0 };
   // A table similar to the .debug_aranges table, but this one points to the
   // exact DW_TAG_subprogram DIEs
   std::unique_ptr m_func_aranges_ap;
@@ -160,6 +162,7 @@
   // If this is a dwo compile unit this is the offset of the base compile unit
   // in the main object file
   dw_offset_t m_base_obj_offset = DW_INVALID_OFFSET;
+  std::mutex m_extractdies_mutex;
 
   static void
   IndexPrivate(DWARFUnit *dwarf_cu, const lldb::LanguageType cu_language,
Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -15,6 +15,7 @@
 #include "lldb/Symbol/CompileUnit.h"
 #include "lldb/Symbol/LineTable.h"
 #include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/CleanUp.h"
 #include "lldb/Utility/Timer.h"
 
 #include "DWARFDIECollection.h"
@@ -42,9 +43,20 @@
 // done.
 //--
 size_t DWARFUnit::ExtractDIEsIfNeeded(bool cu_die_only) {
-  const size_t initial_die_array_size = m_die_array.siz

[Lldb-commits] [PATCH] D40470: DWZ 03/07: Protect DWARFCompileUnit::m_die_array by a new mutex

2018-04-30 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil marked an inline comment as done.
jankratochvil added inline comments.



Comment at: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp:56
+return 0;
+  std::shared_ptr m_die_array_size_atomic_set(nullptr,
+  [&](void*){ m_die_array_size_atomic = m_die_array.size(); });

clayborg wrote:
> Remove the "m_" prefix on this local variable as that indicates it is a 
> member variable. 
> 
> Might be better to use CleanUp utility from "lldb/Utility/CleanUp.h" instead 
> of a shared pointer to void? Took me a bit to figure out what this was doing. 
> If this is a very accepted C++ way to run a function that is scoped that is 
> fine, but it seems a little unclear what this was doing initially.
> 
Done, done. I have googled the shared_ptr cleanup for this purpose at [[ 
https://stackoverflow.com/questions/36644263/is-there-a-c-standard-class-to-set-a-variable-to-a-value-at-scope-exit
 | StackOverflow ]]. Updated, thanks.



https://reviews.llvm.org/D40470



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


[Lldb-commits] [PATCH] D40470: DWZ 03/07: Protect DWARFCompileUnit::m_die_array by a new mutex

2018-04-30 Thread Greg Clayton via Phabricator via lldb-commits
clayborg requested changes to this revision.
clayborg added inline comments.
This revision now requires changes to proceed.



Comment at: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp:335
 m_die_array.swap(tmp_array);
-if (keep_compile_unit_die)
+m_die_array_size_atomic = 0;
+if (keep_compile_unit_die) {

You can't really play with the m_die_array_size_atomic without locking the 
mutex, which really means  m_die_array_size_atomic is not very useful. Seems 
like there is still a race condition:
- thread 1 calls this function and executes "m_die_array.swap(tmp_array);" but 
not " m_die_array_size_atomic = 0;"
- thread 2 calls DWARFUnit::ExtractDIEsIfNeeded() and calls "already_parsed()" 
which returns true because m_die_array_size_atomic is still some valid value
- thread 1 clears the DIE array and sets m_die_array_size_atomic to zero
- thread 2 has no DIEs when it tries to use them




https://reviews.llvm.org/D40470



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


[Lldb-commits] [PATCH] D46083: Move the persistent variable counter into Target

2018-04-30 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl updated this revision to Diff 144628.
aprantl added a comment.

Thread an is_error flag through for plugins that need it.


https://reviews.llvm.org/D46083

Files:
  include/lldb/Expression/ExpressionVariable.h
  source/Core/ValueObject.cpp
  source/Expression/ExpressionVariable.cpp
  source/Expression/Materializer.cpp
  source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
  source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
  source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
  source/Plugins/ExpressionParser/Go/GoUserExpression.h
  source/Target/ABI.cpp

Index: source/Target/ABI.cpp
===
--- source/Target/ABI.cpp
+++ source/Target/ABI.cpp
@@ -110,8 +110,10 @@
 if (!persistent_expression_state)
   return ValueObjectSP();
 
-ConstString persistent_variable_name(
-persistent_expression_state->GetNextPersistentVariableName(target));
+auto prefix = persistent_expression_state->GetPersistentVariablePrefix();
+ConstString persistent_variable_name =
+persistent_expression_state->GetNextPersistentVariableName(target,
+   prefix);
 
 lldb::ValueObjectSP const_valobj_sp;
 
Index: source/Plugins/ExpressionParser/Go/GoUserExpression.h
===
--- source/Plugins/ExpressionParser/Go/GoUserExpression.h
+++ source/Plugins/ExpressionParser/Go/GoUserExpression.h
@@ -29,8 +29,10 @@
 public:
   GoPersistentExpressionState();
 
-  ConstString GetNextPersistentVariableName(Target &target) override;
-
+  llvm::StringRef
+  GetPersistentVariablePrefix(bool is_error) const override {
+return "$go";
+  }
   void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
 
   lldb::addr_t LookupSymbol(const ConstString &name) override {
Index: source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
===
--- source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
+++ source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
@@ -272,7 +272,8 @@
   PersistentExpressionState *pv =
   target->GetPersistentExpressionStateForLanguage(eLanguageTypeGo);
   if (pv != nullptr) {
-result->SetName(pv->GetNextPersistentVariableName(*target));
+result->SetName(pv->GetNextPersistentVariableName(
+*target, pv->GetPersistentVariablePrefix()));
 pv->AddVariable(result);
   }
   return lldb::eExpressionCompleted;
@@ -650,16 +651,6 @@
 GoPersistentExpressionState::GoPersistentExpressionState()
 : PersistentExpressionState(eKindGo) {}
 
-ConstString
-GoPersistentExpressionState::GetNextPersistentVariableName(Target &target) {
-  char name_cstr[256];
-  // We can't use the same variable format as clang.
-  ::snprintf(name_cstr, sizeof(name_cstr), "$go%u",
- target.GetNextPersistentVariableIndex());
-  ConstString name(name_cstr);
-  return name;
-}
-
 void GoPersistentExpressionState::RemovePersistentVariable(
 lldb::ExpressionVariableSP variable) {
   RemoveVariable(variable);
Index: source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
===
--- source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
@@ -665,7 +665,7 @@
 }
 
 ConstString ClangUserExpression::ResultDelegate::GetName() {
-  return m_persistent_state->GetNextPersistentVariableName(*m_target_sp);
+  return m_persistent_state->GetNextPersistentVariableName(*m_target_sp, "$");
 }
 
 void ClangUserExpression::ResultDelegate::DidDematerialize(
Index: source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
===
--- source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
+++ source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
@@ -54,16 +54,11 @@
   const CompilerType &compiler_type, lldb::ByteOrder byte_order,
   uint32_t addr_byte_size) override;
 
-  //--
-  /// Return the next entry in the sequence of strings "$0", "$1", ... for
-  /// use naming persistent expression convenience variables.
-  ///
-  /// @return
-  /// A string that contains the next persistent variable name.
-  //--
-  ConstString GetNextPersistentVariableName(Target &target) override;
-
   void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
+  llvm::StringRef
+  GetPersistentVariablePrefix(bool is_error) const override {
+return "$";
+  }
 
   void RegisterPersistentDecl(const ConstString &name, clang::NamedDecl *decl);
 
Index: source/Plugins/ExpressionParser/Clang/ClangPe

[Lldb-commits] [PATCH] D46220: Remove premature caching of the global variables list in CompileUnit.

2018-04-30 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.

ping.


https://reviews.llvm.org/D46220



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


[Lldb-commits] [PATCH] D46128: Fix expression parser to not accept any type whose basename matches for a type that must exist at root level

2018-04-30 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl accepted this revision.
aprantl added a comment.
This revision is now accepted and ready to land.

To aid with reviewing I documented LLDB's current behavior. I don't understand 
the implementation well enough to comment on it, but I do think the the new 
behavior is superior over the old one. After this patch LLDB behaves 
deterministic and like the compiler would behave on that line, before it, LLDB 
would do a DWIM thing with unpredictable results. So unless Jim has any 
concerns about the implementation, I would give this a go.




Comment at: 
packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py:48
+self.assertTrue(expr_result.GetError().Fail(),
+"'namespace_only' exists in namespace only")
+

This currently returns

(a::namespace_only) $0 = (a = 123)

which — while convenient — behaves differently from code injected at that point 
in the program.



Comment at: 
packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py:55
+expr_result = frame.EvaluateExpression("*((b::namespace_only *)&i)")
+self.check_value(expr_result, "b", 123)
+

both of these work at the moment.



Comment at: 
packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py:59
+expr_result = frame.EvaluateExpression("*((namespace_and_file *)&i)")
+self.check_value(expr_result, "ff", 123)
+# Make sure we can find the correct type in a namespace "a"

Currently:

```
error: reference to 'namespace_and_file' is ambiguous
candidate found by name lookup is 'namespace_and_file'
candidate found by name lookup is 'a::namespace_and_file'
error: reference to 'namespace_and_file' is ambiguous
candidate found by name lookup is 'namespace_and_file'
candidate found by name lookup is 'a::namespace_and_file'
```

that's a horrible failure mode.



Comment at: 
packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py:67
+"*((b::namespace_and_file *)&i)")
+self.check_value(expr_result, "bb", 123)
+

this works



Comment at: 
packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py:69
+
+# Make sure we don't accedentally accept structures that exist only
+# in namespaces when evaluating expressions with top level types.

accidentally



Comment at: 
packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py:76
+self.assertTrue(expr_result.GetError().Fail(),
+"'in_contains_type' exists in struct only")
+

(lldb) p *((in_contains_type *)&i)
(a::contains_type::in_contains_type) $5 = (aaa = 123)



Comment at: 
packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py:80
+expr_result = frame.EvaluateExpression(
+"*((contains_type::in_contains_type *)&i)")
+self.check_value(expr_result, "fff", 123)

Similar ugly failure:

error: reference to 'contains_type' is ambiguous
candidate found by name lookup is 'contains_type'
candidate found by name lookup is 'a::contains_type'
error: expected expression




Comment at: 
packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py:88
+expr_result = frame.EvaluateExpression(
+"*((b::contains_type::in_contains_type *)&i)")
+self.check_value(expr_result, "bbb", 123)

these work as expected.


https://reviews.llvm.org/D46128



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


[Lldb-commits] [PATCH] D46220: Remove premature caching of the global variables list in CompileUnit.

2018-04-30 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added inline comments.



Comment at: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:4221
   if (variable_list_sp.get() == NULL) {
 variable_list_sp.reset(new VariableList());
   }

So do we cache now somewhere else now that 
"sc.comp_unit->SetVariableList(variable_list_sp);" is removed?


https://reviews.llvm.org/D46220



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


[Lldb-commits] [lldb] r331227 - Fix expression parser to not accept any type whose basename matches for a type that must exist at root level

2018-04-30 Thread Greg Clayton via lldb-commits
Author: gclayton
Date: Mon Apr 30 14:06:30 2018
New Revision: 331227

URL: http://llvm.org/viewvc/llvm-project?rev=331227&view=rev
Log:
Fix expression parser to not accept any type whose basename matches for a type 
that must exist at root level

This patch fixes an issue where we weren't looking for exact matches in the 
expression parser and also fixed the type lookup logic in the Module.cpp. Tests 
added to make sure we don't regress.

Differential Revision: https://reviews.llvm.org/D46128


Added:
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/Makefile

lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/main.cpp
Modified:
lldb/trunk/source/Core/Module.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/Makefile
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/Makefile?rev=331227&view=auto
==
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/Makefile 
(added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/Makefile Mon 
Apr 30 14:06:30 2018
@@ -0,0 +1,3 @@
+LEVEL = ../../../make
+C_SOURCES := main.c
+include $(LEVEL)/Makefile.rules

Added: 
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py?rev=331227&view=auto
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py
 (added)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py
 Mon Apr 30 14:06:30 2018
@@ -0,0 +1,89 @@
+"""
+Test that we can lookup types correctly in the expression parser
+"""
+
+from __future__ import print_function
+
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import decorators
+
+class TestTypeLookup(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def check_value(self, value, ivar_name, ivar_value):
+self.assertTrue(value.GetError().Success(),
+"Invalid valobj: %s" % (
+value.GetError().GetCString()))
+ivar = value.GetChildMemberWithName(ivar_name)
+self.assertTrue(ivar.GetError().Success(),
+"Failed to fetch ivar named '%s'" % (ivar_name))
+self.assertEqual(ivar_value,
+ ivar.GetValueAsSigned(),
+ "Got the right value for ivar")
+
+def test_namespace_only(self):
+"""
+Test that we fail to lookup a struct type that exists only in a
+namespace.
+"""
+self.build()
+self.main_source_file = lldb.SBFileSpec("main.cpp")
+(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+self, "Set a breakpoint here", self.main_source_file)
+
+# Get frame for current thread
+frame = thread.GetSelectedFrame()
+
+# Make sure we don't accidentally accept structures that exist only
+# in namespaces when evaluating expressions with top level types.
+# Prior to the revision that added this test, we would accidentally
+# accept types from namespaces, so this will ensure we don't regress
+# to that behavior again
+expr_result = frame.EvaluateExpression("*((namespace_only *)&i)")
+self.assertTrue(expr_result.GetError().Fail(),
+"'namespace_only' exists in namespace only")
+
+# Make sure we can find the correct type in a namespace "a"
+expr_result = frame.EvaluateExpression("*((a::namespace_only *)&i)")
+self.check_value(expr_result, "a", 123)
+# Make sure we can find the correct type in a namespace "b"
+expr_result = frame.EvaluateExpression("*((b::namespace_only *)&i)")
+self.check_value(expr_result, "b", 123)
+
+# Make sure we can find the correct type in the root namespace
+expr_result = frame.EvaluateExpression("*((namespace_and_file *)&i)")
+self.check_value(expr_result, "ff", 123)
+# Make sure we can find the correct type in a namespace "a"
+expr_result = frame.EvaluateExpression(
+"*((a::namespace_and_file *)&i)")
+self.check_value(expr_result, "aa", 123)
+# Make sure we can find the correct type in a namespace "b"
+expr_result = frame.EvaluateExpression(
+"*((b::namespace_and_file *)&i)")
+self.check_value(expr_result, "bb", 123)
+

[Lldb-commits] [PATCH] D46128: Fix expression parser to not accept any type whose basename matches for a type that must exist at root level

2018-04-30 Thread Phabricator via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331227: Fix expression parser to not accept any type whose 
basename matches for a type… (authored by gclayton, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46128?vs=144133&id=144636#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46128

Files:
  lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/Makefile
  
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py
  lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/main.cpp
  lldb/trunk/source/Core/Module.cpp
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp

Index: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/Makefile
===
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/Makefile
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/Makefile
@@ -0,0 +1,3 @@
+LEVEL = ../../../make
+C_SOURCES := main.c
+include $(LEVEL)/Makefile.rules
Index: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/main.cpp
===
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/main.cpp
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/main.cpp
@@ -0,0 +1,67 @@
+//===-- main.c --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+// In this test, we define struct that exist might exist at the different
+// levels in the code and test that we can properly locate these types with
+// a varienty of different expressions.
+
+namespace a {
+  struct namespace_only {
+int a;
+  };
+  struct namespace_and_file {
+int aa;
+  };
+  struct contains_type {
+struct in_contains_type {
+  int aaa;
+};
+  };
+};
+namespace b {
+  struct namespace_only {
+int b;
+  };
+  struct namespace_and_file {
+int bb;
+  };
+  struct contains_type {
+struct in_contains_type {
+  int bbb;
+};
+  };
+};
+
+struct namespace_and_file {
+  int ff;
+};
+
+struct contains_type {
+  struct in_contains_type {
+int fff;
+  };
+};
+
+
+int main (int argc, char const *argv[]) {
+  a::namespace_only a_namespace_only = { 1 };
+  a::namespace_and_file a_namespace_and_file = { 2 };
+  a::contains_type::in_contains_type a_in_contains_type = { 3 };
+  b::namespace_only b_namespace_only = { 11 };
+  b::namespace_and_file b_namespace_and_file = { 22 };
+  b::contains_type::in_contains_type b_in_contains_type = { 33 };
+  namespace_and_file file_namespace_and_file = { 44 };
+  contains_type::in_contains_type file_in_contains_type = { 55 };
+  int i = 123; // Provide an integer that can be used for casting
+  // Take address of "i" to ensure it is in memory
+  if (&i == &argc) {
+i = -1;
+  }
+  return i == -1; // Set a breakpoint here
+}
Index: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py
===
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py
@@ -0,0 +1,89 @@
+"""
+Test that we can lookup types correctly in the expression parser
+"""
+
+from __future__ import print_function
+
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import decorators
+
+class TestTypeLookup(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def check_value(self, value, ivar_name, ivar_value):
+self.assertTrue(value.GetError().Success(),
+"Invalid valobj: %s" % (
+value.GetError().GetCString()))
+ivar = value.GetChildMemberWithName(ivar_name)
+self.assertTrue(ivar.GetError().Success(),
+"Failed to fetch ivar named '%s'" % (ivar_name))
+self.assertEqual(ivar_value,
+ ivar.GetValueAsSigned(),
+ "Got the right value for ivar")
+
+def test_namespace_only(self):
+"""
+Test that we fail to lookup a struct type that exists only in a
+namespace.
+"""
+self.build()
+self.main_source_file = lldb.SBFileSpec("main.cpp")
+(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+self, "Set a breakpoint here", self.main_source_file)
+
+# Get frame for current thread
+frame = thread.GetSelectedFrame()
+
+# Make sure we don't accid

[Lldb-commits] [PATCH] D46220: Remove premature caching of the global variables list in CompileUnit.

2018-04-30 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added inline comments.



Comment at: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:4221
   if (variable_list_sp.get() == NULL) {
 variable_list_sp.reset(new VariableList());
   }

clayborg wrote:
> So do we cache now somewhere else now that 
> "sc.comp_unit->SetVariableList(variable_list_sp);" is removed?
Yes,  CompileUnit::GetVariableList() grabs the *complete* list of variables via 
(SymbolFileDWARF, ...)::ParseVariablesForContext and that still calls 
sc.comp_unit->SetVariableList(variables); which acts as the caching mechanism.


https://reviews.llvm.org/D46220



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


[Lldb-commits] [PATCH] D43512: DWZ 07/07: Fix for symlinked .build-id/**.debug files

2018-04-30 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil planned changes to this revision.
jankratochvil added a comment.

The testcase needs some updates after recent upstream testsuite changes.


https://reviews.llvm.org/D43512



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


[Lldb-commits] [PATCH] D46220: Remove premature caching of the global variables list in CompileUnit.

2018-04-30 Thread Greg Clayton via Phabricator via lldb-commits
clayborg accepted this revision.
clayborg added a comment.
This revision is now accepted and ready to land.

Sounds good. Looks fine.


https://reviews.llvm.org/D46220



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


[Lldb-commits] [PATCH] D40470: DWZ 03/07: Protect DWARFCompileUnit::m_die_array by a new mutex

2018-04-30 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil updated this revision to Diff 144638.
jankratochvil marked an inline comment as done.

https://reviews.llvm.org/D40470

Files:
  source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  source/Plugins/SymbolFile/DWARF/DWARFUnit.h


Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.h
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -13,6 +13,7 @@
 #include "DWARFDIE.h"
 #include "DWARFDebugInfoEntry.h"
 #include "lldb/lldb-enumerations.h"
+#include "llvm/Support/RWMutex.h"
 
 class DWARFUnit;
 class DWARFCompileUnit;
@@ -160,6 +161,7 @@
   // If this is a dwo compile unit this is the offset of the base compile unit
   // in the main object file
   dw_offset_t m_base_obj_offset = DW_INVALID_OFFSET;
+  llvm::sys::RWMutex m_extractdies_mutex;
 
   static void
   IndexPrivate(DWARFUnit *dwarf_cu, const lldb::LanguageType cu_language,
Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -42,9 +42,20 @@
 // done.
 //--
 size_t DWARFUnit::ExtractDIEsIfNeeded(bool cu_die_only) {
-  const size_t initial_die_array_size = m_die_array.size();
-  if ((cu_die_only && initial_die_array_size > 0) || initial_die_array_size > 
1)
-return 0; // Already parsed
+  size_t initial_die_array_size;
+  auto already_parsed = [cu_die_only, &initial_die_array_size, this]() -> bool 
{
+initial_die_array_size = m_die_array.size();
+return (cu_die_only && initial_die_array_size > 0)
+|| initial_die_array_size > 1;
+  };
+  {
+llvm::sys::ScopedReader lock(m_extractdies_mutex);
+if (already_parsed())
+  return 0;
+  }
+  llvm::sys::ScopedWriter lock(m_extractdies_mutex);
+  if (already_parsed())
+return 0;
 
   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
   Timer scoped_timer(
@@ -307,6 +318,8 @@
 
 void DWARFUnit::ClearDIEs(bool keep_compile_unit_die) {
   if (m_die_array.size() > 1) {
+llvm::sys::ScopedWriter lock(m_extractdies_mutex);
+
 // std::vectors never get any smaller when resized to a smaller size,
 // or when clear() or erase() are called, the size will report that it
 // is smaller, but the memory allocated remains intact (call capacity()


Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.h
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -13,6 +13,7 @@
 #include "DWARFDIE.h"
 #include "DWARFDebugInfoEntry.h"
 #include "lldb/lldb-enumerations.h"
+#include "llvm/Support/RWMutex.h"
 
 class DWARFUnit;
 class DWARFCompileUnit;
@@ -160,6 +161,7 @@
   // If this is a dwo compile unit this is the offset of the base compile unit
   // in the main object file
   dw_offset_t m_base_obj_offset = DW_INVALID_OFFSET;
+  llvm::sys::RWMutex m_extractdies_mutex;
 
   static void
   IndexPrivate(DWARFUnit *dwarf_cu, const lldb::LanguageType cu_language,
Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -42,9 +42,20 @@
 // done.
 //--
 size_t DWARFUnit::ExtractDIEsIfNeeded(bool cu_die_only) {
-  const size_t initial_die_array_size = m_die_array.size();
-  if ((cu_die_only && initial_die_array_size > 0) || initial_die_array_size > 1)
-return 0; // Already parsed
+  size_t initial_die_array_size;
+  auto already_parsed = [cu_die_only, &initial_die_array_size, this]() -> bool {
+initial_die_array_size = m_die_array.size();
+return (cu_die_only && initial_die_array_size > 0)
+|| initial_die_array_size > 1;
+  };
+  {
+llvm::sys::ScopedReader lock(m_extractdies_mutex);
+if (already_parsed())
+  return 0;
+  }
+  llvm::sys::ScopedWriter lock(m_extractdies_mutex);
+  if (already_parsed())
+return 0;
 
   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
   Timer scoped_timer(
@@ -307,6 +318,8 @@
 
 void DWARFUnit::ClearDIEs(bool keep_compile_unit_die) {
   if (m_die_array.size() > 1) {
+llvm::sys::ScopedWriter lock(m_extractdies_mutex);
+
 // std::vectors never get any smaller when resized to a smaller size,
 // or when clear() or erase() are called, the size will report that it
 // is smaller, but the memory allocated remains intact (call capacity()
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D40470: DWZ 03/07: Protect DWARFCompileUnit::m_die_array by a new mutex

2018-04-30 Thread Greg Clayton via Phabricator via lldb-commits
clayborg accepted this revision.
clayborg added a comment.
This revision is now accepted and ready to land.

Much better.


https://reviews.llvm.org/D40470



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


[Lldb-commits] [PATCH] D40470: DWZ 03/07: Protect DWARFCompileUnit::m_die_array by a new mutex

2018-04-30 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil marked an inline comment as done.
jankratochvil added inline comments.



Comment at: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp:335
 m_die_array.swap(tmp_array);
-if (keep_compile_unit_die)
+m_die_array_size_atomic = 0;
+if (keep_compile_unit_die) {

clayborg wrote:
> You can't really play with the m_die_array_size_atomic without locking the 
> mutex, which really means  m_die_array_size_atomic is not very useful. Seems 
> like there is still a race condition:
> - thread 1 calls this function and executes "m_die_array.swap(tmp_array);" 
> but not " m_die_array_size_atomic = 0;"
> - thread 2 calls DWARFUnit::ExtractDIEsIfNeeded() and calls 
> "already_parsed()" which returns true because m_die_array_size_atomic is 
> still some valid value
> - thread 1 clears the DIE array and sets m_die_array_size_atomic to zero
> - thread 2 has no DIEs when it tries to use them
> 
> 
I see I did screw up even that, sorry for that.  I believe there still could be 
an atomic_t speedup but given you are fine with the performance of a mutex I 
have implemented it that way.



https://reviews.llvm.org/D40470



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


[Lldb-commits] [PATCH] D40474: DWZ 05/07: Main functionality

2018-04-30 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil updated this revision to Diff 144639.

https://reviews.llvm.org/D40474

Files:
  include/lldb/Utility/ConstString.h
  include/lldb/Utility/FileSpec.h
  source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
  source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
  source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  source/Plugins/SymbolFile/DWARF/DWARFUnit.h
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  source/Utility/DataEncoder.cpp
  source/Utility/DataExtractor.cpp

Index: source/Utility/DataExtractor.cpp
===
--- source/Utility/DataExtractor.cpp
+++ source/Utility/DataExtractor.cpp
@@ -232,7 +232,8 @@
 if (data != nullptr) {
   const uint8_t *data_bytes = data->GetBytes();
   if (data_bytes != nullptr) {
-assert(m_start >= data_bytes);
+// For DWARFDataExtractor::OffsetData we need to return negative value.
+// assert(m_start >= data_bytes);
 return m_start - data_bytes;
   }
 }
Index: source/Utility/DataEncoder.cpp
===
--- source/Utility/DataEncoder.cpp
+++ source/Utility/DataEncoder.cpp
@@ -81,7 +81,8 @@
 if (data != nullptr) {
   const uint8_t *data_bytes = data->GetBytes();
   if (data_bytes != nullptr) {
-assert(m_start >= data_bytes);
+// For DWARFDataExtractor::OffsetData we need to return negative value.
+// assert(m_start >= data_bytes);
 return m_start - data_bytes;
   }
 }
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -18,10 +18,12 @@
 #include 
 #include 
 #include 
+#include 
 
 // Other libraries and framework includes
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/Support/Threading.h"
+#include "llvm/Support/RWMutex.h"
 
 #include "lldb/Utility/Flags.h"
 
@@ -312,6 +314,13 @@
   // the method returns a pointer to the base compile unit.
   virtual DWARFUnit *GetBaseCompileUnit();
 
+  SymbolFileDWARF *GetDWZSymbolFile() const {
+if (!m_dwz_common_file)
+  return nullptr;
+return m_dwz_common_file->SymbolFile();
+  }
+  bool GetIsDWZ() const { return m_is_dwz; }
+
 protected:
   typedef llvm::DenseMap
   DIEToTypePtr;
@@ -473,6 +482,45 @@
 
   SymbolFileDWARFDwp *GetDwpSymbolFile();
 
+  void InitializeDWZ();
+
+  class DWZCommonFile {
+  public:
+// C++14: Use heterogenous lookup.
+DWZCommonFile(const lldb_private::FileSpec &filespec_ref);
+DWZCommonFile(std::unique_ptr symbol_file,
+lldb::ObjectFileSP obj_file, lldb::ModuleSP module);
+SymbolFileDWARF *SymbolFile() const { return m_symbol_file.get(); }
+
+bool operator==(const DWZCommonFile &rhs) const {
+  return m_filespec_ref == rhs.m_filespec_ref;
+}
+bool operator!=(const DWZCommonFile &rhs) const { return !(*this == rhs); }
+class Hasher {
+public:
+  size_t operator()(const DWZCommonFile &key) const {
+return lldb_private::FileSpec::Hasher()(key.m_filespec_ref);
+  }
+};
+
+size_t m_use_count = 0;
+
+  private:
+std::unique_ptr m_symbol_file;
+lldb::ObjectFileSP m_obj_file;
+lldb::ModuleSP m_module;
+const lldb_private::FileSpec &m_filespec_ref;
+
+DISALLOW_COPY_AND_ASSIGN(DWZCommonFile);
+  };
+  DWZCommonFile *m_dwz_common_file = nullptr;
+  void DWZCommonFileSet(DWZCommonFile *dwz_common_file);
+  void DWZCommonFileClear();
+  static std::unordered_set
+  m_filespec_to_dwzcommonfile;
+  static llvm::sys::RWMutex m_filespec_to_dwzcommonfile_mutex;
+  bool m_is_dwz = false;
+
   lldb::ModuleWP m_debug_map_module_wp;
   SymbolFileDWARFDebugMap *m_debug_map_symfile;
 
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -411,7 +411,9 @@
   m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate), m_ranges(),
   m_unique_ast_type_map() {}
 
-SymbolFileDWARF::~SymbolFileDWARF() {}
+SymbolFileDWARF::~SymbolFileDWARF() {
+  DWZCommonFileClear();
+}
 
 static const ConstString &GetDWARFMachOSegmentName() {
   static ConstString g_dwarf_section_name("__DWARF");
@@ -427,6 +429,7 @@
 }
 
 TypeSystem *SymbolFileDWARF::GetTypeSystemForLanguage(LanguageType language) {
+  lldbassert(!GetIsDWZ());
   SymbolFileDWARFDebugMap *debug_map_sy

[Lldb-commits] [PATCH] D40474: DWZ 05/07: Main functionality

2018-04-30 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil updated this revision to Diff 144640.

https://reviews.llvm.org/D40474

Files:
  include/lldb/Utility/ConstString.h
  include/lldb/Utility/FileSpec.h
  source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
  source/Plugins/SymbolFile/DWARF/DWARFDataExtractor.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
  source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
  source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  source/Plugins/SymbolFile/DWARF/DWARFUnit.h
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  source/Utility/DataEncoder.cpp
  source/Utility/DataExtractor.cpp

Index: source/Utility/DataExtractor.cpp
===
--- source/Utility/DataExtractor.cpp
+++ source/Utility/DataExtractor.cpp
@@ -230,7 +230,8 @@
 if (data != nullptr) {
   const uint8_t *data_bytes = data->GetBytes();
   if (data_bytes != nullptr) {
-assert(m_start >= data_bytes);
+// For DWARFDataExtractor::OffsetData we need to return negative value.
+// assert(m_start >= data_bytes);
 return m_start - data_bytes;
   }
 }
Index: source/Utility/DataEncoder.cpp
===
--- source/Utility/DataEncoder.cpp
+++ source/Utility/DataEncoder.cpp
@@ -79,7 +79,8 @@
 if (data != nullptr) {
   const uint8_t *data_bytes = data->GetBytes();
   if (data_bytes != nullptr) {
-assert(m_start >= data_bytes);
+// For DWARFDataExtractor::OffsetData we need to return negative value.
+// assert(m_start >= data_bytes);
 return m_start - data_bytes;
   }
 }
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -18,10 +18,12 @@
 #include 
 #include 
 #include 
+#include 
 
 // Other libraries and framework includes
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/Support/Threading.h"
+#include "llvm/Support/RWMutex.h"
 
 #include "lldb/Utility/Flags.h"
 
@@ -312,6 +314,13 @@
   // the method returns a pointer to the base compile unit.
   virtual DWARFUnit *GetBaseCompileUnit();
 
+  SymbolFileDWARF *GetDWZSymbolFile() const {
+if (!m_dwz_common_file)
+  return nullptr;
+return m_dwz_common_file->SymbolFile();
+  }
+  bool GetIsDWZ() const { return m_is_dwz; }
+
 protected:
   typedef llvm::DenseMap
   DIEToTypePtr;
@@ -473,6 +482,45 @@
 
   SymbolFileDWARFDwp *GetDwpSymbolFile();
 
+  void InitializeDWZ();
+
+  class DWZCommonFile {
+  public:
+// C++14: Use heterogenous lookup.
+DWZCommonFile(const lldb_private::FileSpec &filespec_ref);
+DWZCommonFile(std::unique_ptr symbol_file,
+lldb::ObjectFileSP obj_file, lldb::ModuleSP module);
+SymbolFileDWARF *SymbolFile() const { return m_symbol_file.get(); }
+
+bool operator==(const DWZCommonFile &rhs) const {
+  return m_filespec_ref == rhs.m_filespec_ref;
+}
+bool operator!=(const DWZCommonFile &rhs) const { return !(*this == rhs); }
+class Hasher {
+public:
+  size_t operator()(const DWZCommonFile &key) const {
+return lldb_private::FileSpec::Hasher()(key.m_filespec_ref);
+  }
+};
+
+size_t m_use_count = 0;
+
+  private:
+std::unique_ptr m_symbol_file;
+lldb::ObjectFileSP m_obj_file;
+lldb::ModuleSP m_module;
+const lldb_private::FileSpec &m_filespec_ref;
+
+DISALLOW_COPY_AND_ASSIGN(DWZCommonFile);
+  };
+  DWZCommonFile *m_dwz_common_file = nullptr;
+  void DWZCommonFileSet(DWZCommonFile *dwz_common_file);
+  void DWZCommonFileClear();
+  static std::unordered_set
+  m_filespec_to_dwzcommonfile;
+  static llvm::sys::RWMutex m_filespec_to_dwzcommonfile_mutex;
+  bool m_is_dwz = false;
+
   lldb::ModuleWP m_debug_map_module_wp;
   SymbolFileDWARFDebugMap *m_debug_map_symfile;
 
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -411,7 +411,9 @@
   m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate), m_ranges(),
   m_unique_ast_type_map() {}
 
-SymbolFileDWARF::~SymbolFileDWARF() {}
+SymbolFileDWARF::~SymbolFileDWARF() {
+  DWZCommonFileClear();
+}
 
 static const ConstString &GetDWARFMachOSegmentName() {
   static ConstString g_dwarf_section_name("__DWARF");
@@ -427,6 +429,7 @@
 }
 
 TypeSystem *SymbolFileDWARF::GetTypeSystemForLanguage(LanguageType language) {
+  lldbassert(!GetIsDWZ());
   SymbolFileDWARFDebugMap *debug_map_sy

[Lldb-commits] [lldb] r331229 - Protect DWARFCompileUnit::m_die_array by a new mutex

2018-04-30 Thread Jan Kratochvil via lldb-commits
Author: jankratochvil
Date: Mon Apr 30 14:37:30 2018
New Revision: 331229

URL: http://llvm.org/viewvc/llvm-project?rev=331229&view=rev
Log:
Protect DWARFCompileUnit::m_die_array by a new mutex

Multiple DW_TAG_compile_unit being indexed in a multithreaded way can request
reading of the same DW_TAG_partial_unit.

Unfortunately one cannot detect DWZ file ahead of time to disable such locking
overhead as DWARFCompileUnit::Extract does not read the first DIE which is the
only place one could find early enough if the DWARF file is using any
DW_TAG_partial_unit.

Differential revision: https://reviews.llvm.org/D40470

Modified:
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp?rev=331229&r1=331228&r2=331229&view=diff
==
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp Mon Apr 30 
14:37:30 2018
@@ -41,9 +41,20 @@ DWARFUnit::~DWARFUnit() {}
 // Parses a compile unit and indexes its DIEs if it hasn't already been done.
 //--
 size_t DWARFUnit::ExtractDIEsIfNeeded(bool cu_die_only) {
-  const size_t initial_die_array_size = m_die_array.size();
-  if ((cu_die_only && initial_die_array_size > 0) || initial_die_array_size > 
1)
-return 0; // Already parsed
+  size_t initial_die_array_size;
+  auto already_parsed = [cu_die_only, &initial_die_array_size, this]() -> bool 
{
+initial_die_array_size = m_die_array.size();
+return (cu_die_only && initial_die_array_size > 0)
+|| initial_die_array_size > 1;
+  };
+  {
+llvm::sys::ScopedReader lock(m_extractdies_mutex);
+if (already_parsed())
+  return 0;
+  }
+  llvm::sys::ScopedWriter lock(m_extractdies_mutex);
+  if (already_parsed())
+return 0;
 
   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
   Timer scoped_timer(
@@ -304,6 +315,8 @@ void DWARFUnit::SetAddrBase(dw_addr_t ad
 
 void DWARFUnit::ClearDIEs(bool keep_compile_unit_die) {
   if (m_die_array.size() > 1) {
+llvm::sys::ScopedWriter lock(m_extractdies_mutex);
+
 // std::vectors never get any smaller when resized to a smaller size, or
 // when clear() or erase() are called, the size will report that it is
 // smaller, but the memory allocated remains intact (call capacity() to see

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h?rev=331229&r1=331228&r2=331229&view=diff
==
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h Mon Apr 30 14:37:30 
2018
@@ -13,6 +13,7 @@
 #include "DWARFDIE.h"
 #include "DWARFDebugInfoEntry.h"
 #include "lldb/lldb-enumerations.h"
+#include "llvm/Support/RWMutex.h"
 
 class DWARFUnit;
 class DWARFCompileUnit;
@@ -160,6 +161,7 @@ protected:
   // If this is a dwo compile unit this is the offset of the base compile unit
   // in the main object file
   dw_offset_t m_base_obj_offset = DW_INVALID_OFFSET;
+  llvm::sys::RWMutex m_extractdies_mutex;
 
   static void
   IndexPrivate(DWARFUnit *dwarf_cu, const lldb::LanguageType cu_language,


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


[Lldb-commits] [PATCH] D40470: DWZ 03/07: Protect DWARFCompileUnit::m_die_array by a new mutex

2018-04-30 Thread Jan Kratochvil via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
jankratochvil marked an inline comment as done.
Closed by commit rL331229: Protect DWARFCompileUnit::m_die_array by a new mutex 
(authored by jankratochvil, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D40470?vs=144638&id=144641#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40470

Files:
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h


Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -13,6 +13,7 @@
 #include "DWARFDIE.h"
 #include "DWARFDebugInfoEntry.h"
 #include "lldb/lldb-enumerations.h"
+#include "llvm/Support/RWMutex.h"
 
 class DWARFUnit;
 class DWARFCompileUnit;
@@ -160,6 +161,7 @@
   // If this is a dwo compile unit this is the offset of the base compile unit
   // in the main object file
   dw_offset_t m_base_obj_offset = DW_INVALID_OFFSET;
+  llvm::sys::RWMutex m_extractdies_mutex;
 
   static void
   IndexPrivate(DWARFUnit *dwarf_cu, const lldb::LanguageType cu_language,
Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -41,9 +41,20 @@
 // Parses a compile unit and indexes its DIEs if it hasn't already been done.
 //--
 size_t DWARFUnit::ExtractDIEsIfNeeded(bool cu_die_only) {
-  const size_t initial_die_array_size = m_die_array.size();
-  if ((cu_die_only && initial_die_array_size > 0) || initial_die_array_size > 
1)
-return 0; // Already parsed
+  size_t initial_die_array_size;
+  auto already_parsed = [cu_die_only, &initial_die_array_size, this]() -> bool 
{
+initial_die_array_size = m_die_array.size();
+return (cu_die_only && initial_die_array_size > 0)
+|| initial_die_array_size > 1;
+  };
+  {
+llvm::sys::ScopedReader lock(m_extractdies_mutex);
+if (already_parsed())
+  return 0;
+  }
+  llvm::sys::ScopedWriter lock(m_extractdies_mutex);
+  if (already_parsed())
+return 0;
 
   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
   Timer scoped_timer(
@@ -304,6 +315,8 @@
 
 void DWARFUnit::ClearDIEs(bool keep_compile_unit_die) {
   if (m_die_array.size() > 1) {
+llvm::sys::ScopedWriter lock(m_extractdies_mutex);
+
 // std::vectors never get any smaller when resized to a smaller size, or
 // when clear() or erase() are called, the size will report that it is
 // smaller, but the memory allocated remains intact (call capacity() to see


Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -13,6 +13,7 @@
 #include "DWARFDIE.h"
 #include "DWARFDebugInfoEntry.h"
 #include "lldb/lldb-enumerations.h"
+#include "llvm/Support/RWMutex.h"
 
 class DWARFUnit;
 class DWARFCompileUnit;
@@ -160,6 +161,7 @@
   // If this is a dwo compile unit this is the offset of the base compile unit
   // in the main object file
   dw_offset_t m_base_obj_offset = DW_INVALID_OFFSET;
+  llvm::sys::RWMutex m_extractdies_mutex;
 
   static void
   IndexPrivate(DWARFUnit *dwarf_cu, const lldb::LanguageType cu_language,
Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -41,9 +41,20 @@
 // Parses a compile unit and indexes its DIEs if it hasn't already been done.
 //--
 size_t DWARFUnit::ExtractDIEsIfNeeded(bool cu_die_only) {
-  const size_t initial_die_array_size = m_die_array.size();
-  if ((cu_die_only && initial_die_array_size > 0) || initial_die_array_size > 1)
-return 0; // Already parsed
+  size_t initial_die_array_size;
+  auto already_parsed = [cu_die_only, &initial_die_array_size, this]() -> bool {
+initial_die_array_size = m_die_array.size();
+return (cu_die_only && initial_die_array_size > 0)
+|| initial_die_array_size > 1;
+  };
+  {
+llvm::sys::ScopedReader lock(m_extractdies_mutex);
+if (already_parsed())
+  return 0;
+  }
+  llvm::sys::ScopedWriter lock(m_extractdies_mutex);
+  if (already_parsed())
+return 0;
 
   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
   Timer scoped_timer(
@@ -304,6 +315,8 @@
 
 void DWARFUnit::ClearDIEs(bool keep_compile_unit_die) {
   if (

[Lldb-commits] [lldb] r331230 - Remove premature caching of the global variables list in CompileUnit.

2018-04-30 Thread Adrian Prantl via lldb-commits
Author: adrian
Date: Mon Apr 30 14:54:02 2018
New Revision: 331230

URL: http://llvm.org/viewvc/llvm-project?rev=331230&view=rev
Log:
Remove premature caching of the global variables list in CompileUnit.

This fixes a bug where

  (lldb) target var g_ptr

would populate the global variables list with exactly one entry
because SymbolFileDWARF::ParseVariables() was invoked with a list of
DIEs pre-filtered by name, such that a subsequent call to

  (lldb) fr var --show-globals

would only list that one variable, because CompileUnit::m_variables
was already initialized, fooling CompileUnit::GetVariableList().

CompileUnit::GetVariableList() grabs the *complete* list of variables
via (SymbolFileDWARF, ...)::ParseVariablesForContext and that still
calls CompileUnit::SetVariableList(variables) which acts as the
caching mechanism.

Differential Revision: https://reviews.llvm.org/D46220

Modified:

lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py
lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/main.c
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Modified: 
lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py?rev=331230&r1=331229&r2=331230&view=diff
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py
 (original)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py
 Mon Apr 30 14:54:02 2018
@@ -39,6 +39,12 @@ class GlobalVariablesTestCase(TestBase):
 environment = self.registerSharedLibrariesWithTarget(
 target, self.shlib_names)
 
+# Test that static initialized variables can be inspected without 
process.
+self.expect("target variable g_ptr", VARIABLES_DISPLAYED_CORRECTLY,
+substrs=['(int *)'])
+self.expect("target variable *g_ptr", VARIABLES_DISPLAYED_CORRECTLY,
+substrs=['42'])
+
 # Now launch the process, and do not stop at entry point.
 process = target.LaunchSimple(
 None, environment, self.get_process_working_directory())
@@ -54,17 +60,21 @@ class GlobalVariablesTestCase(TestBase):
 substrs=[' resolved, hit count = 1'])
 
 # Check that GLOBAL scopes are indicated for the variables.
+self.runCmd("frame variable --show-types --scope --show-globals 
--no-args")
 self.expect(
 "frame variable --show-types --scope --show-globals --no-args",
 VARIABLES_DISPLAYED_CORRECTLY,
 substrs=[
-'GLOBAL: (int) g_file_global_int = 42',
 'STATIC: (const int) g_file_static_int = 2',
+'STATIC: (const char *) g_func_static_cstr',
 'GLOBAL: (const char *) g_file_global_cstr',
 '"g_file_global_cstr"',
+'GLOBAL: (int) g_file_global_int = 42',
+'GLOBAL: (int) g_common_1 = 21',
+'GLOBAL: (int *) g_ptr',
 'STATIC: (const char *) g_file_static_cstr',
-'"g_file_static_cstr"',
-'GLOBAL: (int) g_common_1 = 21'])
+'"g_file_static_cstr"'
+])
 
 # 'frame variable' should support address-of operator.
 self.runCmd("frame variable &g_file_global_int")
@@ -95,3 +105,8 @@ class GlobalVariablesTestCase(TestBase):
 VARIABLES_DISPLAYED_CORRECTLY,
 matching=False,
 substrs=["can't be resolved"])
+
+# Test that the statically initialized variable can also be
+# inspected *with* a process.
+self.expect("target variable *g_ptr", VARIABLES_DISPLAYED_CORRECTLY,
+substrs=['42'])

Modified: 
lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/main.c
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/main.c?rev=331230&r1=331229&r2=331230&view=diff
==
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/main.c 
(original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/main.c 
Mon Apr 30 14:54:02 2018
@@ -13,6 +13,7 @@ int g_file_global_int = 42;
 static const int g_file_static_int = 2;
 const char *g_file_global_cstr = "g_file_global_cstr";
 static const char *g_file_static_cstr = "g_file_static_cstr";
+int *g_ptr = &g_file_global_int;
 
 extern int g_a;
 int main (int argc, char const *argv[])
@@ -20,5 +21,5 @@ int main (int argc, char const *argv[])
 g_common_1 = g_file_global_int / g_file_static_int;
 static const char *g_func_static_cstr = "g_func_static_cstr";
 printf (

[Lldb-commits] [PATCH] D46220: Remove premature caching of the global variables list in CompileUnit.

2018-04-30 Thread Phabricator via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331230: Remove premature caching of the global variables 
list in CompileUnit. (authored by adrian, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46220?vs=144418&id=144642#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46220

Files:
  
lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py
  lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/main.c
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp


Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -4194,7 +4194,6 @@
   variable_list_sp = sc.comp_unit->GetVariableList(false);
   if (variable_list_sp.get() == NULL) {
 variable_list_sp.reset(new VariableList());
-sc.comp_unit->SetVariableList(variable_list_sp);
   }
 } else {
   GetObjectFile()->GetModule()->ReportError(
Index: 
lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py
===
--- 
lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py
+++ 
lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py
@@ -39,6 +39,12 @@
 environment = self.registerSharedLibrariesWithTarget(
 target, self.shlib_names)
 
+# Test that static initialized variables can be inspected without 
process.
+self.expect("target variable g_ptr", VARIABLES_DISPLAYED_CORRECTLY,
+substrs=['(int *)'])
+self.expect("target variable *g_ptr", VARIABLES_DISPLAYED_CORRECTLY,
+substrs=['42'])
+
 # Now launch the process, and do not stop at entry point.
 process = target.LaunchSimple(
 None, environment, self.get_process_working_directory())
@@ -54,17 +60,21 @@
 substrs=[' resolved, hit count = 1'])
 
 # Check that GLOBAL scopes are indicated for the variables.
+self.runCmd("frame variable --show-types --scope --show-globals 
--no-args")
 self.expect(
 "frame variable --show-types --scope --show-globals --no-args",
 VARIABLES_DISPLAYED_CORRECTLY,
 substrs=[
-'GLOBAL: (int) g_file_global_int = 42',
 'STATIC: (const int) g_file_static_int = 2',
+'STATIC: (const char *) g_func_static_cstr',
 'GLOBAL: (const char *) g_file_global_cstr',
 '"g_file_global_cstr"',
+'GLOBAL: (int) g_file_global_int = 42',
+'GLOBAL: (int) g_common_1 = 21',
+'GLOBAL: (int *) g_ptr',
 'STATIC: (const char *) g_file_static_cstr',
-'"g_file_static_cstr"',
-'GLOBAL: (int) g_common_1 = 21'])
+'"g_file_static_cstr"'
+])
 
 # 'frame variable' should support address-of operator.
 self.runCmd("frame variable &g_file_global_int")
@@ -95,3 +105,8 @@
 VARIABLES_DISPLAYED_CORRECTLY,
 matching=False,
 substrs=["can't be resolved"])
+
+# Test that the statically initialized variable can also be
+# inspected *with* a process.
+self.expect("target variable *g_ptr", VARIABLES_DISPLAYED_CORRECTLY,
+substrs=['42'])
Index: lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/main.c
===
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/main.c
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/global_variables/main.c
@@ -13,12 +13,13 @@
 static const int g_file_static_int = 2;
 const char *g_file_global_cstr = "g_file_global_cstr";
 static const char *g_file_static_cstr = "g_file_static_cstr";
+int *g_ptr = &g_file_global_int;
 
 extern int g_a;
 int main (int argc, char const *argv[])
 {
 g_common_1 = g_file_global_int / g_file_static_int;
 static const char *g_func_static_cstr = "g_func_static_cstr";
 printf ("%s %s\n", g_file_global_cstr, g_file_static_cstr);
-return g_file_global_int + g_a + g_common_1; // Set break point at this 
line.   break $source:$line; continue; var -global g_a -global g_global_int
+return g_file_global_int + g_a + g_common_1 + *g_ptr; // Set break point 
at this line.   break $source:$line; continue; var -global g_a -global 
g_global_int
 }


Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===

[Lldb-commits] [PATCH] D46292: Use the UUID from the minidump's CodeView Record for placeholder modules

2018-04-30 Thread Leonard Mosescu via Phabricator via lldb-commits
lemo created this revision.
lemo added reviewers: amccarth, clayborg, labath.
lemo added a project: LLDB.

This change adds support for two types of Minidump CodeView records:

1. PDB70 (reference: 
https://crashpad.chromium.org/doxygen/structcrashpad_1_1CodeViewRecordPDB70.html)

This is by far the most common record type.

2. ELF BuildID (found in Breakpad/Crashpad generated minidumps)

This would set a proper UUID for placeholder modules, in turn enabling an 
accurate match with local module images.


https://reviews.llvm.org/D46292

Files:
  include/lldb/Core/Module.h
  include/lldb/Core/ModuleSpec.h
  
packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py
  source/Commands/CommandObjectTarget.cpp
  source/Core/Module.cpp
  source/Plugins/Process/minidump/MinidumpParser.cpp
  source/Plugins/Process/minidump/MinidumpParser.h
  source/Plugins/Process/minidump/MinidumpTypes.h
  source/Plugins/Process/minidump/ProcessMinidump.cpp

Index: source/Plugins/Process/minidump/ProcessMinidump.cpp
===
--- source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -321,9 +321,10 @@
   m_is_wow64 = true;
 }
 
+const auto uuid = m_minidump_parser.GetModuleUUID(module);
 const auto file_spec =
 FileSpec(name.getValue(), true, GetArchitecture().GetTriple());
-ModuleSpec module_spec = file_spec;
+ModuleSpec module_spec(file_spec, uuid);
 Status error;
 lldb::ModuleSP module_sp = GetTarget().GetSharedModule(module_spec, &error);
 if (!module_sp || error.Fail()) {
@@ -337,6 +338,7 @@
   auto placeholder_module =
   std::make_shared(file_spec, GetArchitecture());
   placeholder_module->CreateImageSection(module, GetTarget());
+  placeholder_module->SetUUID(uuid);
   module_sp = placeholder_module;
   GetTarget().GetImages().Append(module_sp);
 }
Index: source/Plugins/Process/minidump/MinidumpTypes.h
===
--- source/Plugins/Process/minidump/MinidumpTypes.h
+++ source/Plugins/Process/minidump/MinidumpTypes.h
@@ -43,6 +43,21 @@
 
 };
 
+enum class CvSignature : uint32_t {
+  Pdb70 = 0x53445352, // RSDS
+  ElfBuildId = 0x4270454c, // BpEL (Breakpad/Crashpad minidumps)
+};
+
+// Reference:
+// https://crashpad.chromium.org/doxygen/structcrashpad_1_1CodeViewRecordPDB70.html
+struct CvRecordPdb70 {
+  uint8_t Uuid[16];
+  llvm::support::ulittle32_t Age;
+  // char PDBFileName[];
+};
+static_assert(sizeof(CvRecordPdb70) == 20,
+  "sizeof CvRecordPdb70 is not correct!");
+
 // Reference:
 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms680394.aspx
 enum class MinidumpStreamType : uint32_t {
Index: source/Plugins/Process/minidump/MinidumpParser.h
===
--- source/Plugins/Process/minidump/MinidumpParser.h
+++ source/Plugins/Process/minidump/MinidumpParser.h
@@ -17,6 +17,7 @@
 #include "lldb/Utility/ArchSpec.h"
 #include "lldb/Utility/DataBuffer.h"
 #include "lldb/Utility/Status.h"
+#include "lldb/Utility/UUID.h"
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -54,6 +55,8 @@
 
   llvm::Optional GetMinidumpString(uint32_t rva);
 
+  UUID GetModuleUUID(const MinidumpModule* module);
+
   llvm::ArrayRef GetThreads();
 
   llvm::ArrayRef GetThreadContext(const MinidumpThread &td);
Index: source/Plugins/Process/minidump/MinidumpParser.cpp
===
--- source/Plugins/Process/minidump/MinidumpParser.cpp
+++ source/Plugins/Process/minidump/MinidumpParser.cpp
@@ -96,6 +96,40 @@
   return parseMinidumpString(arr_ref);
 }
 
+UUID MinidumpParser::GetModuleUUID(const MinidumpModule *module) {
+  auto cv_record =
+  GetData().slice(module->CV_record.rva, module->CV_record.data_size);
+
+  // Read the CV record signature
+  const llvm::support::ulittle32_t *signature = nullptr;
+  Status error = consumeObject(cv_record, signature);
+  if (error.Fail())
+return UUID();
+
+  const CvSignature cv_signature =
+  static_cast(static_cast(*signature));
+
+  if (cv_signature == CvSignature::Pdb70) {
+// PDB70 record
+const CvRecordPdb70 *pdb70_uuid = nullptr;
+Status error = consumeObject(cv_record, pdb70_uuid);
+if (!error.Fail())
+  return UUID(pdb70_uuid, sizeof(*pdb70_uuid));
+  } else if (cv_signature == CvSignature::ElfBuildId) {
+// ELF BuildID (found in Breakpad/Crashpad generated minidumps)
+//
+// This is variable-length, but usually 20 bytes
+// as the binutils ld default is a SHA-1 hash.
+// (We'll handle only 16 and 20 bytes signatures,
+// matching LLDB support for UUIDs)
+//
+if (cv_record.size() == 16 || cv_record.size() == 20)
+  return UUID(cv_record.data(), cv_record.size());
+  }
+
+  return UUID();
+}
+
 llvm::ArrayRef Minidump

[Lldb-commits] [PATCH] D46083: Move the persistent variable counter into Target

2018-04-30 Thread Jim Ingham via Phabricator via lldb-commits
jingham requested changes to this revision.
jingham added a comment.
This revision now requires changes to proceed.

Except for the inline comment, this is okay.  If we thought hard we might find 
another likely reason why we'd want to use two result prefixes besides a 
language that has an error return side-channel.  But I can't off the top of my 
head, so is_error is fine for now.


https://reviews.llvm.org/D46083



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


[Lldb-commits] [PATCH] D46083: Move the persistent variable counter into Target

2018-04-30 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.

I'm sorry: which inline comment? Did you perhaps forget to hit "Submit"?


https://reviews.llvm.org/D46083



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


[Lldb-commits] [PATCH] D46083: Move the persistent variable counter into Target

2018-04-30 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

Eh, must have. The page really shouldn't let you overall submit if there are 
uncommitted comments, but whatever.  Let's see if I did it right this time..




Comment at: source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp:668
 ConstString ClangUserExpression::ResultDelegate::GetName() {
-  return m_persistent_state->GetNextPersistentVariableName(*m_target_sp);
+  return m_persistent_state->GetNextPersistentVariableName(*m_target_sp, "$");
 }

Don't hard-code "$" here, call GetPersistentVariablePrefix.


https://reviews.llvm.org/D46083



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


[Lldb-commits] [PATCH] D46292: Use the UUID from the minidump's CodeView Record for placeholder modules

2018-04-30 Thread Adrian McCarthy via Phabricator via lldb-commits
amccarth accepted this revision.
amccarth added a comment.
This revision is now accepted and ready to land.

The big picture here is fine.

I see a couple opportunities in the details, but I won't block on them.




Comment at: include/lldb/Core/Module.h:779
+  //--
+  void SetUUID(const lldb_private::UUID &uuid);
+

Was there no SetUUID before because the UUID was considered immutable?  I 
wonder if that's worth keeping.  Is the UUID always known at construction time?



Comment at: source/Core/Module.cpp:341
+  m_uuid = uuid;
+  m_did_parse_uuid = true;
+}

I wonder if the lazy UUID lookup in Module::GetUUID should call this to avoid 
code duplication.  I know it's not a lot of code, but it involves a mutex and 
an atomic flag, so it might be nice to always have this update in just one 
place.



Comment at: source/Plugins/Process/minidump/MinidumpParser.cpp:99
 
+UUID MinidumpParser::GetModuleUUID(const MinidumpModule *module) {
+  auto cv_record =

I wonder if this should return an `Expected`.  The function has multiple 
ways it can fail, in which case the error info is lost and we silently return 
an empty UUID.


https://reviews.llvm.org/D46292



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


[Lldb-commits] [PATCH] D46088: Refactor GetNextPersistentVariableName into a non-virtual method

2018-04-30 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl updated this revision to Diff 144649.
aprantl added a comment.

Address review feedback.


https://reviews.llvm.org/D46088

Files:
  include/lldb/Expression/ExpressionVariable.h
  source/Core/ValueObject.cpp
  source/Expression/ExpressionVariable.cpp
  source/Expression/Materializer.cpp
  source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
  source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
  source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
  source/Plugins/ExpressionParser/Go/GoUserExpression.h
  source/Target/ABI.cpp

Index: source/Target/ABI.cpp
===
--- source/Target/ABI.cpp
+++ source/Target/ABI.cpp
@@ -110,8 +110,10 @@
 if (!persistent_expression_state)
   return ValueObjectSP();
 
-ConstString persistent_variable_name(
-persistent_expression_state->GetNextPersistentVariableName(target));
+auto prefix = persistent_expression_state->GetPersistentVariablePrefix();
+ConstString persistent_variable_name =
+persistent_expression_state->GetNextPersistentVariableName(target,
+   prefix);
 
 lldb::ValueObjectSP const_valobj_sp;
 
Index: source/Plugins/ExpressionParser/Go/GoUserExpression.h
===
--- source/Plugins/ExpressionParser/Go/GoUserExpression.h
+++ source/Plugins/ExpressionParser/Go/GoUserExpression.h
@@ -29,8 +29,10 @@
 public:
   GoPersistentExpressionState();
 
-  ConstString GetNextPersistentVariableName(Target &target) override;
-
+  llvm::StringRef
+  GetPersistentVariablePrefix(bool is_error) const override {
+return "$go";
+  }
   void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
 
   lldb::addr_t LookupSymbol(const ConstString &name) override {
Index: source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
===
--- source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
+++ source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
@@ -272,7 +272,8 @@
   PersistentExpressionState *pv =
   target->GetPersistentExpressionStateForLanguage(eLanguageTypeGo);
   if (pv != nullptr) {
-result->SetName(pv->GetNextPersistentVariableName(*target));
+result->SetName(pv->GetNextPersistentVariableName(
+*target, pv->GetPersistentVariablePrefix()));
 pv->AddVariable(result);
   }
   return lldb::eExpressionCompleted;
@@ -650,16 +651,6 @@
 GoPersistentExpressionState::GoPersistentExpressionState()
 : PersistentExpressionState(eKindGo) {}
 
-ConstString
-GoPersistentExpressionState::GetNextPersistentVariableName(Target &target) {
-  char name_cstr[256];
-  // We can't use the same variable format as clang.
-  ::snprintf(name_cstr, sizeof(name_cstr), "$go%u",
- target.GetNextPersistentVariableIndex());
-  ConstString name(name_cstr);
-  return name;
-}
-
 void GoPersistentExpressionState::RemovePersistentVariable(
 lldb::ExpressionVariableSP variable) {
   RemoveVariable(variable);
Index: source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
===
--- source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
@@ -665,7 +665,9 @@
 }
 
 ConstString ClangUserExpression::ResultDelegate::GetName() {
-  return m_persistent_state->GetNextPersistentVariableName(*m_target_sp);
+  auto prefix = m_persistent_state->GetPersistentVariablePrefix();
+  return m_persistent_state->GetNextPersistentVariableName(*m_target_sp,
+   prefix);
 }
 
 void ClangUserExpression::ResultDelegate::DidDematerialize(
Index: source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
===
--- source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
+++ source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
@@ -54,16 +54,11 @@
   const CompilerType &compiler_type, lldb::ByteOrder byte_order,
   uint32_t addr_byte_size) override;
 
-  //--
-  /// Return the next entry in the sequence of strings "$0", "$1", ... for
-  /// use naming persistent expression convenience variables.
-  ///
-  /// @return
-  /// A string that contains the next persistent variable name.
-  //--
-  ConstString GetNextPersistentVariableName(Target &target) override;
-
   void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
+  llvm::StringRef
+  GetPersistentVariablePrefix(bool is_error) const override {
+return "$";
+  }
 
   void RegisterPersistentDecl(const 

[Lldb-commits] [PATCH] D46088: Refactor GetNextPersistentVariableName into a non-virtual method

2018-04-30 Thread Jim Ingham via Phabricator via lldb-commits
jingham accepted this revision.
jingham added a comment.
This revision is now accepted and ready to land.

That's fine.


https://reviews.llvm.org/D46088



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


[Lldb-commits] [lldb] r331235 - Refactor GetNextPersistentVariableName into a non-virtual method

2018-04-30 Thread Adrian Prantl via lldb-commits
Author: adrian
Date: Mon Apr 30 16:59:17 2018
New Revision: 331235

URL: http://llvm.org/viewvc/llvm-project?rev=331235&view=rev
Log:
Refactor GetNextPersistentVariableName into a non-virtual method
that takes a prefix string. This simplifies the implementation and
allows plugins such as the Swift plugin to supply different prefixes
for return and error variables.

rdar://problem/39299889

Differential Revision: https://reviews.llvm.org/D46088

Modified:
lldb/trunk/include/lldb/Expression/ExpressionVariable.h
lldb/trunk/source/Core/ValueObject.cpp
lldb/trunk/source/Expression/ExpressionVariable.cpp
lldb/trunk/source/Expression/Materializer.cpp

lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h
lldb/trunk/source/Target/ABI.cpp

Modified: lldb/trunk/include/lldb/Expression/ExpressionVariable.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ExpressionVariable.h?rev=331235&r1=331234&r2=331235&view=diff
==
--- lldb/trunk/include/lldb/Expression/ExpressionVariable.h (original)
+++ lldb/trunk/include/lldb/Expression/ExpressionVariable.h Mon Apr 30 16:59:17 
2018
@@ -239,7 +239,12 @@ public:
lldb::ByteOrder byte_order,
uint32_t addr_byte_size) = 0;
 
-  virtual ConstString GetNextPersistentVariableName(Target &target) = 0;
+  /// Return a new persistent variable name with the specified prefix.
+  ConstString GetNextPersistentVariableName(Target &target,
+llvm::StringRef prefix);
+
+  virtual llvm::StringRef
+  GetPersistentVariablePrefix(bool is_error = false) const = 0;
 
   virtual void
   RemovePersistentVariable(lldb::ExpressionVariableSP variable) = 0;

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=331235&r1=331234&r2=331235&view=diff
==
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Mon Apr 30 16:59:17 2018
@@ -3311,7 +3311,9 @@ ValueObjectSP ValueObject::Persist() {
   if (!persistent_state)
 return nullptr;
 
-  ConstString 
name(persistent_state->GetNextPersistentVariableName(*target_sp));
+  auto prefix = persistent_state->GetPersistentVariablePrefix();
+  ConstString name =
+  persistent_state->GetNextPersistentVariableName(*target_sp, prefix);
 
   ValueObjectSP const_result_sp =
   ValueObjectConstResult::Create(target_sp.get(), GetValue(), name);

Modified: lldb/trunk/source/Expression/ExpressionVariable.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ExpressionVariable.cpp?rev=331235&r1=331234&r2=331235&view=diff
==
--- lldb/trunk/source/Expression/ExpressionVariable.cpp (original)
+++ lldb/trunk/source/Expression/ExpressionVariable.cpp Mon Apr 30 16:59:17 2018
@@ -9,6 +9,7 @@
 
 #include "lldb/Expression/ExpressionVariable.h"
 #include "lldb/Expression/IRExecutionUnit.h"
+#include "lldb/Target/Target.h"
 #include "lldb/Utility/Log.h"
 
 using namespace lldb_private;
@@ -80,3 +81,13 @@ void PersistentExpressionState::Register
 }
   }
 }
+
+ConstString PersistentExpressionState::GetNextPersistentVariableName(
+Target &target, llvm::StringRef Prefix) {
+  llvm::SmallString<64> name;
+  {
+llvm::raw_svector_ostream os(name);
+os << Prefix << target.GetNextPersistentVariableIndex();
+  }
+  return ConstString(name);
+}

Modified: lldb/trunk/source/Expression/Materializer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/Materializer.cpp?rev=331235&r1=331234&r2=331235&view=diff
==
--- lldb/trunk/source/Expression/Materializer.cpp (original)
+++ lldb/trunk/source/Expression/Materializer.cpp Mon Apr 30 16:59:17 2018
@@ -891,7 +891,8 @@ public:
 ConstString name =
 m_delegate
 ? m_delegate->GetName()
-: persistent_state->GetNextPersistentVariableName(*target_sp);
+: persistent_state->GetNextPersistentVariableName(
+  *target_sp, persistent_state->GetPersistentVariablePrefix());
 
 lldb::ExpressionVariableSP ret = 
persistent_state->CreatePersistentVariable(
 exe_scope, name, m_type, map.GetByteOrder(), map.GetAddressByteSize());

Modified: 
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
URL: 
http://llvm.org/viewvc/llvm-

[Lldb-commits] [PATCH] D46083: Move the persistent variable counter into Target

2018-04-30 Thread Phabricator via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Revision".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331234: Move the persistent variable counter into Target 
(authored by adrian, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46083?vs=144628&id=144650#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46083

Files:
  lldb/trunk/include/lldb/Expression/ExpressionVariable.h
  lldb/trunk/include/lldb/Target/Target.h
  lldb/trunk/source/Core/ValueObject.cpp
  lldb/trunk/source/Expression/Materializer.cpp
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
  lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
  lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h
  lldb/trunk/source/Target/ABI.cpp

Index: lldb/trunk/include/lldb/Target/Target.h
===
--- lldb/trunk/include/lldb/Target/Target.h
+++ lldb/trunk/include/lldb/Target/Target.h
@@ -1082,6 +1082,11 @@
 
   lldb::ExpressionVariableSP GetPersistentVariable(const ConstString &name);
 
+  /// Return the next available number for numbered persistent variables.
+  unsigned GetNextPersistentVariableIndex() {
+return m_next_persistent_variable_index++;
+  }
+
   lldb::addr_t GetPersistentSymbol(const ConstString &name);
 
   //--
@@ -1271,6 +1276,7 @@
   bool m_valid;
   bool m_suppress_stop_hooks;
   bool m_is_dummy_target;
+  unsigned m_next_persistent_variable_index = 0;
 
   static void ImageSearchPathsChanged(const PathMappingList &path_list,
   void *baton);
Index: lldb/trunk/include/lldb/Expression/ExpressionVariable.h
===
--- lldb/trunk/include/lldb/Expression/ExpressionVariable.h
+++ lldb/trunk/include/lldb/Expression/ExpressionVariable.h
@@ -239,7 +239,7 @@
lldb::ByteOrder byte_order,
uint32_t addr_byte_size) = 0;
 
-  virtual ConstString GetNextPersistentVariableName() = 0;
+  virtual ConstString GetNextPersistentVariableName(Target &target) = 0;
 
   virtual void
   RemovePersistentVariable(lldb::ExpressionVariableSP variable) = 0;
Index: lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h
===
--- lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h
+++ lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h
@@ -29,7 +29,7 @@
 public:
   GoPersistentExpressionState();
 
-  ConstString GetNextPersistentVariableName() override;
+  ConstString GetNextPersistentVariableName(Target &target) override;
 
   void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
 
Index: lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
===
--- lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
+++ lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
@@ -272,7 +272,7 @@
   PersistentExpressionState *pv =
   target->GetPersistentExpressionStateForLanguage(eLanguageTypeGo);
   if (pv != nullptr) {
-result->SetName(pv->GetNextPersistentVariableName());
+result->SetName(pv->GetNextPersistentVariableName(*target));
 pv->AddVariable(result);
   }
   return lldb::eExpressionCompleted;
@@ -650,11 +650,12 @@
 GoPersistentExpressionState::GoPersistentExpressionState()
 : PersistentExpressionState(eKindGo) {}
 
-ConstString GoPersistentExpressionState::GetNextPersistentVariableName() {
+ConstString
+GoPersistentExpressionState::GetNextPersistentVariableName(Target &target) {
   char name_cstr[256];
   // We can't use the same variable format as clang.
   ::snprintf(name_cstr, sizeof(name_cstr), "$go%u",
- m_next_persistent_variable_id++);
+ target.GetNextPersistentVariableIndex());
   ConstString name(name_cstr);
   return name;
 }
Index: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
===
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
@@ -10,6 +10,7 @@
 #include "ClangPersistentVariables.h"
 
 #include "lldb/Core/Value.h"
+#include "lldb/Target/Target.h"
 #include "lldb/Utility/DataExtractor.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/StreamString.h"
@@ -52,10 +53,11 @@
 m_next_persistent_va

[Lldb-commits] [lldb] r331234 - Move the persistent variable counter into Target

2018-04-30 Thread Adrian Prantl via lldb-commits
Author: adrian
Date: Mon Apr 30 16:59:15 2018
New Revision: 331234

URL: http://llvm.org/viewvc/llvm-project?rev=331234&view=rev
Log:
Move the persistent variable counter into Target
so it can be shared across multiple language plugins.

In a multi-language project it is counterintuitive to have a result
variables reuse numbers just because they are using a different
language plugin in LLDB (but not for example, when they are
Objective-C versus C++, since they are both handled by Clang).

This is NFC on llvm.org except for the Go plugin.

rdar://problem/39299889

Differential Revision: https://reviews.llvm.org/D46083

Modified:
lldb/trunk/include/lldb/Expression/ExpressionVariable.h
lldb/trunk/include/lldb/Target/Target.h
lldb/trunk/source/Core/ValueObject.cpp
lldb/trunk/source/Expression/Materializer.cpp

lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h
lldb/trunk/source/Target/ABI.cpp

Modified: lldb/trunk/include/lldb/Expression/ExpressionVariable.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ExpressionVariable.h?rev=331234&r1=331233&r2=331234&view=diff
==
--- lldb/trunk/include/lldb/Expression/ExpressionVariable.h (original)
+++ lldb/trunk/include/lldb/Expression/ExpressionVariable.h Mon Apr 30 16:59:15 
2018
@@ -239,7 +239,7 @@ public:
lldb::ByteOrder byte_order,
uint32_t addr_byte_size) = 0;
 
-  virtual ConstString GetNextPersistentVariableName() = 0;
+  virtual ConstString GetNextPersistentVariableName(Target &target) = 0;
 
   virtual void
   RemovePersistentVariable(lldb::ExpressionVariableSP variable) = 0;

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=331234&r1=331233&r2=331234&view=diff
==
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Mon Apr 30 16:59:15 2018
@@ -1082,6 +1082,11 @@ public:
 
   lldb::ExpressionVariableSP GetPersistentVariable(const ConstString &name);
 
+  /// Return the next available number for numbered persistent variables.
+  unsigned GetNextPersistentVariableIndex() {
+return m_next_persistent_variable_index++;
+  }
+
   lldb::addr_t GetPersistentSymbol(const ConstString &name);
 
   //--
@@ -1271,6 +1276,7 @@ protected:
   bool m_valid;
   bool m_suppress_stop_hooks;
   bool m_is_dummy_target;
+  unsigned m_next_persistent_variable_index = 0;
 
   static void ImageSearchPathsChanged(const PathMappingList &path_list,
   void *baton);

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=331234&r1=331233&r2=331234&view=diff
==
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Mon Apr 30 16:59:15 2018
@@ -3311,7 +3311,7 @@ ValueObjectSP ValueObject::Persist() {
   if (!persistent_state)
 return nullptr;
 
-  ConstString name(persistent_state->GetNextPersistentVariableName());
+  ConstString 
name(persistent_state->GetNextPersistentVariableName(*target_sp));
 
   ValueObjectSP const_result_sp =
   ValueObjectConstResult::Create(target_sp.get(), GetValue(), name);

Modified: lldb/trunk/source/Expression/Materializer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/Materializer.cpp?rev=331234&r1=331233&r2=331234&view=diff
==
--- lldb/trunk/source/Expression/Materializer.cpp (original)
+++ lldb/trunk/source/Expression/Materializer.cpp Mon Apr 30 16:59:15 2018
@@ -888,9 +888,10 @@ public:
   return;
 }
 
-ConstString name = m_delegate
-   ? m_delegate->GetName()
-   : persistent_state->GetNextPersistentVariableName();
+ConstString name =
+m_delegate
+? m_delegate->GetName()
+: persistent_state->GetNextPersistentVariableName(*target_sp);
 
 lldb::ExpressionVariableSP ret = 
persistent_state->CreatePersistentVariable(
 exe_scope, name, m_type, map.GetByteOrder(), map.GetAddressByteSize());

Modified: 
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariabl

[Lldb-commits] [PATCH] D46088: Refactor GetNextPersistentVariableName into a non-virtual method

2018-04-30 Thread Phabricator via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331235: Refactor GetNextPersistentVariableName into a 
non-virtual method (authored by adrian, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46088?vs=144649&id=144651#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46088

Files:
  lldb/trunk/include/lldb/Expression/ExpressionVariable.h
  lldb/trunk/source/Core/ValueObject.cpp
  lldb/trunk/source/Expression/ExpressionVariable.cpp
  lldb/trunk/source/Expression/Materializer.cpp
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
  lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h
  lldb/trunk/source/Target/ABI.cpp

Index: lldb/trunk/include/lldb/Expression/ExpressionVariable.h
===
--- lldb/trunk/include/lldb/Expression/ExpressionVariable.h
+++ lldb/trunk/include/lldb/Expression/ExpressionVariable.h
@@ -239,7 +239,12 @@
lldb::ByteOrder byte_order,
uint32_t addr_byte_size) = 0;
 
-  virtual ConstString GetNextPersistentVariableName(Target &target) = 0;
+  /// Return a new persistent variable name with the specified prefix.
+  ConstString GetNextPersistentVariableName(Target &target,
+llvm::StringRef prefix);
+
+  virtual llvm::StringRef
+  GetPersistentVariablePrefix(bool is_error = false) const = 0;
 
   virtual void
   RemovePersistentVariable(lldb::ExpressionVariableSP variable) = 0;
Index: lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h
===
--- lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h
+++ lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h
@@ -29,8 +29,10 @@
 public:
   GoPersistentExpressionState();
 
-  ConstString GetNextPersistentVariableName(Target &target) override;
-
+  llvm::StringRef
+  GetPersistentVariablePrefix(bool is_error) const override {
+return "$go";
+  }
   void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
 
   lldb::addr_t LookupSymbol(const ConstString &name) override {
Index: lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
===
--- lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
+++ lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
@@ -272,7 +272,8 @@
   PersistentExpressionState *pv =
   target->GetPersistentExpressionStateForLanguage(eLanguageTypeGo);
   if (pv != nullptr) {
-result->SetName(pv->GetNextPersistentVariableName(*target));
+result->SetName(pv->GetNextPersistentVariableName(
+*target, pv->GetPersistentVariablePrefix()));
 pv->AddVariable(result);
   }
   return lldb::eExpressionCompleted;
@@ -650,16 +651,6 @@
 GoPersistentExpressionState::GoPersistentExpressionState()
 : PersistentExpressionState(eKindGo) {}
 
-ConstString
-GoPersistentExpressionState::GetNextPersistentVariableName(Target &target) {
-  char name_cstr[256];
-  // We can't use the same variable format as clang.
-  ::snprintf(name_cstr, sizeof(name_cstr), "$go%u",
- target.GetNextPersistentVariableIndex());
-  ConstString name(name_cstr);
-  return name;
-}
-
 void GoPersistentExpressionState::RemovePersistentVariable(
 lldb::ExpressionVariableSP variable) {
   RemoveVariable(variable);
Index: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
===
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
@@ -54,16 +54,11 @@
   const CompilerType &compiler_type, lldb::ByteOrder byte_order,
   uint32_t addr_byte_size) override;
 
-  //--
-  /// Return the next entry in the sequence of strings "$0", "$1", ... for
-  /// use naming persistent expression convenience variables.
-  ///
-  /// @return
-  /// A string that contains the next persistent variable name.
-  //--
-  ConstString GetNextPersistentVariableName(Target &target) override;
-
   void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
+  llvm::StringRef
+  GetPersistentVariablePrefix(bool is_error) const override {
+return "$";
+  }
 
   void RegisterPersistentDecl(const ConstString &name, clang::NamedDecl *decl);
 
Index: lldb/trunk/source/Plugins/Expr

[Lldb-commits] [lldb] r331236 - Add logging when ArchSpec::SetArchitecture is given a cputype and

2018-04-30 Thread Jason Molenda via lldb-commits
Author: jmolenda
Date: Mon Apr 30 17:05:54 2018
New Revision: 331236

URL: http://llvm.org/viewvc/llvm-project?rev=331236&view=rev
Log:
Add logging when ArchSpec::SetArchitecture is given a cputype and
cpusubtype that don't map to any known core definition.

 

Modified:
lldb/trunk/source/Utility/ArchSpec.cpp

Modified: lldb/trunk/source/Utility/ArchSpec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/ArchSpec.cpp?rev=331236&r1=331235&r2=331236&view=diff
==
--- lldb/trunk/source/Utility/ArchSpec.cpp (original)
+++ lldb/trunk/source/Utility/ArchSpec.cpp Mon Apr 30 17:05:54 2018
@@ -9,6 +9,7 @@
 
 #include "lldb/Utility/ArchSpec.h"
 
+#include "lldb/Utility/Log.h"
 #include "lldb/Utility/NameMatches.h"
 #include "lldb/Utility/Stream.h" // for Stream
 #include "lldb/Utility/StringList.h"
@@ -978,6 +979,10 @@ bool ArchSpec::SetArchitecture(Architect
 if (m_triple.getArch() == llvm::Triple::UnknownArch)
   m_triple.setArch(core_def->machine);
   }
+} else {
+  Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET | 
LIBLLDB_LOG_TARGET | LIBLLDB_LOG_PLATFORM));
+  if (log)
+log->Printf("Unable to find a core definition for cpu 0x%" PRIx32 " 
sub %" PRId32, cpu, sub);
 }
   }
   CoreUpdated(update_triple);


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


Re: [Lldb-commits] [lldb] r331236 - Add logging when ArchSpec::SetArchitecture is given a cputype and

2018-04-30 Thread Davide Italiano via lldb-commits
On Mon, Apr 30, 2018 at 5:05 PM, Jason Molenda via lldb-commits
 wrote:
> Author: jmolenda
> Date: Mon Apr 30 17:05:54 2018
> New Revision: 331236
>
> URL: http://llvm.org/viewvc/llvm-project?rev=331236&view=rev
> Log:
> Add logging when ArchSpec::SetArchitecture is given a cputype and
> cpusubtype that don't map to any known core definition.
>
> 
>
> Modified:
> lldb/trunk/source/Utility/ArchSpec.cpp
>
> Modified: lldb/trunk/source/Utility/ArchSpec.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/ArchSpec.cpp?rev=331236&r1=331235&r2=331236&view=diff
> ==
> --- lldb/trunk/source/Utility/ArchSpec.cpp (original)
> +++ lldb/trunk/source/Utility/ArchSpec.cpp Mon Apr 30 17:05:54 2018
> @@ -9,6 +9,7 @@
>
>  #include "lldb/Utility/ArchSpec.h"
>
> +#include "lldb/Utility/Log.h"
>  #include "lldb/Utility/NameMatches.h"
>  #include "lldb/Utility/Stream.h" // for Stream
>  #include "lldb/Utility/StringList.h"
> @@ -978,6 +979,10 @@ bool ArchSpec::SetArchitecture(Architect
>  if (m_triple.getArch() == llvm::Triple::UnknownArch)
>m_triple.setArch(core_def->machine);
>}
> +} else {
> +  Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET | 
> LIBLLDB_LOG_TARGET | LIBLLDB_LOG_PLATFORM));

Did you mean to add LIBLLDB_LOG_TARGET twice?

Thanks!

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


Re: [Lldb-commits] [lldb] r331236 - Add logging when ArchSpec::SetArchitecture is given a cputype and

2018-04-30 Thread Jason Molenda via lldb-commits


> On Apr 30, 2018, at 5:23 PM, Davide Italiano  wrote:
> 
> On Mon, Apr 30, 2018 at 5:05 PM, Jason Molenda via lldb-commits
>  wrote:
>> 

>> fAnyCategoriesSet(LIBLLDB_LOG_TARGET | LIBLLDB_LOG_TARGET | 
>> LIBLLDB_LOG_PLATFORM));
> 
> Did you mean to add LIBLLDB_LOG_TARGET twice?


No I did not. :) I was changing my mind about what logging channels to include 
and had a little copy & paste mistake.  thanks.
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] r331239 - Log to the process channel, not target twice.

2018-04-30 Thread Jason Molenda via lldb-commits
Author: jmolenda
Date: Mon Apr 30 17:42:17 2018
New Revision: 331239

URL: http://llvm.org/viewvc/llvm-project?rev=331239&view=rev
Log:
Log to the process channel, not target twice.

Modified:
lldb/trunk/source/Utility/ArchSpec.cpp

Modified: lldb/trunk/source/Utility/ArchSpec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/ArchSpec.cpp?rev=331239&r1=331238&r2=331239&view=diff
==
--- lldb/trunk/source/Utility/ArchSpec.cpp (original)
+++ lldb/trunk/source/Utility/ArchSpec.cpp Mon Apr 30 17:42:17 2018
@@ -980,7 +980,7 @@ bool ArchSpec::SetArchitecture(Architect
   m_triple.setArch(core_def->machine);
   }
 } else {
-  Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET | 
LIBLLDB_LOG_TARGET | LIBLLDB_LOG_PLATFORM));
+  Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET | 
LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_PLATFORM));
   if (log)
 log->Printf("Unable to find a core definition for cpu 0x%" PRIx32 " 
sub %" PRId32, cpu, sub);
 }


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


[Lldb-commits] [lldb] r331242 - Fix type_lookup test to make buildbots happy

2018-04-30 Thread Eugene Zemtsov via lldb-commits
Author: eugene
Date: Mon Apr 30 20:06:05 2018
New Revision: 331242

URL: http://llvm.org/viewvc/llvm-project?rev=331242&view=rev
Log:
Fix type_lookup test to make buildbots happy

Added:

lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestCppTypeLookup.py
  - copied, changed from r331239, 
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py
Removed:

lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py
Modified:
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/Makefile
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/main.cpp

Modified: 
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/Makefile
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/Makefile?rev=331242&r1=331241&r2=331242&view=diff
==
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/Makefile 
(original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/Makefile Mon 
Apr 30 20:06:05 2018
@@ -1,3 +1,3 @@
 LEVEL = ../../../make
-C_SOURCES := main.c
+CXX_SOURCES := main.cpp
 include $(LEVEL)/Makefile.rules

Copied: 
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestCppTypeLookup.py
 (from r331239, 
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py)
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestCppTypeLookup.py?p2=lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestCppTypeLookup.py&p1=lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py&r1=331239&r2=331242&rev=331242&view=diff
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py
 (original)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestCppTypeLookup.py
 Mon Apr 30 20:06:05 2018
@@ -10,7 +10,7 @@ import lldbsuite.test.lldbutil as lldbut
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import decorators
 
-class TestTypeLookup(TestBase):
+class TestCppTypeLookup(TestBase):
 
 mydir = TestBase.compute_mydir(__file__)
 

Removed: 
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py?rev=331241&view=auto
==
--- 
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py
 (original)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestTypeLookup.py
 (removed)
@@ -1,89 +0,0 @@
-"""
-Test that we can lookup types correctly in the expression parser
-"""
-
-from __future__ import print_function
-
-
-import lldb
-import lldbsuite.test.lldbutil as lldbutil
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test import decorators
-
-class TestTypeLookup(TestBase):
-
-mydir = TestBase.compute_mydir(__file__)
-
-def check_value(self, value, ivar_name, ivar_value):
-self.assertTrue(value.GetError().Success(),
-"Invalid valobj: %s" % (
-value.GetError().GetCString()))
-ivar = value.GetChildMemberWithName(ivar_name)
-self.assertTrue(ivar.GetError().Success(),
-"Failed to fetch ivar named '%s'" % (ivar_name))
-self.assertEqual(ivar_value,
- ivar.GetValueAsSigned(),
- "Got the right value for ivar")
-
-def test_namespace_only(self):
-"""
-Test that we fail to lookup a struct type that exists only in a
-namespace.
-"""
-self.build()
-self.main_source_file = lldb.SBFileSpec("main.cpp")
-(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
-self, "Set a breakpoint here", self.main_source_file)
-
-# Get frame for current thread
-frame = thread.GetSelectedFrame()
-
-# Make sure we don't accidentally accept structures that exist only
-# in namespaces when evaluating expressions with top level types.
-# Prior to the revision that added this test, we would accidentally
-# accept types from namespaces, so this will ensure we don't regress
-# to that behavior again
-expr_result = frame.EvaluateExpression("*((namespace_only *)&i)")
-self.assertTrue(expr_result.GetError().Fail(),
-"'namespace_only' exists in namespace only")
-
-# Make sure we can find the correct type in a namespace "a"
-expr_result = frame.EvaluateExpression("*((a::namespace_only *)&i)")
-self.check_value(expr_result, "a", 1