[Lldb-commits] [PATCH] D68069: Explicitly set entry point arch when it's thumb

2019-10-01 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

Thanks for adding the lit test.




Comment at: lldb/lit/SymbolFile/dissassemble-entry-point.s:6
+# RUN: %lldb -x -b \
+# RUN:  -o 'settings set disassembly-format "{ 
<${function.concrete-only-addr-offset-no-padding}>}: "' \
+# RUN:  -o 'dis -s 0x8074 -e 0x8080' -- %t | FileCheck %s

Can you delete this? I'm pretty sure the nested quoting is going to cause 
problems when running the test on windows... If you need it, you can use 
regexes `{{.*}}` to match the filename portion in the check lines below.



Comment at: lldb/lit/SymbolFile/dissassemble-entry-point.s:12
+
+.global _Start
+.thumb_func

I don't think this has any effect, as it differs case from the symbol below, so 
you should be able to just delete it.



Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:2719
+auto entry_point_addr = GetEntryPointAddress().GetFileAddress();
+if (entry_point_addr != LLDB_INVALID_ADDRESS && (entry_point_addr & 1)) {
+  auto opcode_addr = entry_point_addr ^ 1;

You've removed the architecture check, but this check here means that the code 
only kicks in for entry points that happen to be at an odd address. That is 
definitely not right. If we're going to go through with making this stuff 
unconditional (and I still think we should) then this condition needs to go 
too. The only thing that needs to check for arm/thumb is the ` 
m_address_class_map[opcode_addr] = AddressClass::eCodeAlternateISA;` line down 
below.

Also, the long comment above needs to be redone to reflect the new reality. I'd 
just give a short comment that we're creating the entry point symbol if there 
isn't one, and that getting the address class right is important for expression 
evaluation on arm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68069



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


[Lldb-commits] [PATCH] D68248: [JSON] Use LLVM's library for encoding JSON

2019-10-01 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a comment.

Yay.

BTW, there's another copy of json serialization code in JSON.cpp 
(JSONValue::Write).


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D68248



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


[Lldb-commits] [lldb] r373312 - [clang][lldb][NFC] Encapsulate ExternalASTMerger::ImporterSource

2019-10-01 Thread Raphael Isemann via lldb-commits
Author: teemperor
Date: Tue Oct  1 02:02:05 2019
New Revision: 373312

URL: http://llvm.org/viewvc/llvm-project?rev=373312&view=rev
Log:
[clang][lldb][NFC] Encapsulate ExternalASTMerger::ImporterSource

NFC preparation work for upcoming ExternalASTMerger patches.

Modified:
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp

lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp?rev=373312&r1=373311&r2=373312&view=diff
==
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp 
(original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp Tue Oct 
 1 02:02:05 2019
@@ -84,9 +84,9 @@ void ClangASTSource::InstallASTContext(c
  &type_system_or_err.get())) {
 lldbassert(module_ast_ctx->getASTContext());
 lldbassert(module_ast_ctx->getFileManager());
-sources.push_back({*module_ast_ctx->getASTContext(),
-   *module_ast_ctx->getFileManager(),
-   module_ast_ctx->GetOriginMap()});
+sources.emplace_back(*module_ast_ctx->getASTContext(),
+ *module_ast_ctx->getFileManager(),
+ module_ast_ctx->GetOriginMap());
   }
 }
 

Modified: 
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp?rev=373312&r1=373311&r2=373312&view=diff
==
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp 
(original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp 
Tue Oct  1 02:02:05 2019
@@ -277,8 +277,8 @@ static clang::QualType ExportAllDeclared
 clang::FileManager &source_file_manager,
 const clang::ExternalASTMerger::OriginMap &source_origin_map,
 clang::FileID file, clang::QualType root) {
-  clang::ExternalASTMerger::ImporterSource importer_source = {
-  source, source_file_manager, source_origin_map};
+  clang::ExternalASTMerger::ImporterSource importer_source(
+  source, source_file_manager, source_origin_map);
   merger.AddSources(importer_source);
   clang::ASTImporter &exporter = merger.ImporterForOrigin(source);
   CompleteAllDeclContexts(exporter, file, root);

Modified: 
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp?rev=373312&r1=373311&r2=373312&view=diff
==
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp 
(original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp 
Tue Oct  1 02:02:05 2019
@@ -573,8 +573,9 @@ ClangModulesDeclVendorImpl::DoGetModule(
 
 clang::ExternalASTMerger::ImporterSource
 ClangModulesDeclVendorImpl::GetImporterSource() {
-  return {m_compiler_instance->getASTContext(),
-  m_compiler_instance->getFileManager(), m_origin_map};
+  return clang::ExternalASTMerger::ImporterSource(
+  m_compiler_instance->getASTContext(),
+  m_compiler_instance->getFileManager(), m_origin_map);
 }
 
 static const char *ModuleImportBufferName = "LLDBModulesMemoryBuffer";

Modified: 
lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp?rev=373312&r1=373311&r2=373312&view=diff
==
--- 
lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
 (original)
+++ 
lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
 Tue Oct  1 02:02:05 2019
@@ -657,8 +657,7 @@ AppleObjCDeclVendor::FindDecls(ConstStri
 
 clang::ExternalASTMerger::ImporterSource
 AppleObjCDeclVendor::GetImporterSource() {
-return {*m_ast_ctx.getASTContext(),
-*m_ast_ctx.getFileManager(),
-m_ast_ctx.GetOriginMap()
-};
+  return clang::ExternalASTMerger::ImporterSource(*m_ast_ctx.getASTContext(),
+  *m_ast_ctx.getFileManager(),
+  m_ast_ctx.GetOriginMap());
 }


___

[Lldb-commits] [PATCH] D67390: [LLDB][ELF] Load both, .symtab and .dynsym sections

2019-10-01 Thread Konrad Wilhelm Kleine via Phabricator via lldb-commits
kwk updated this revision to Diff 222569.
kwk marked 8 inline comments as done.
kwk added a comment.

- Remove verbose output in test
- Fix typo: smymtab -> symtab
- Move compare and hash logic out of base class into derived class as requested


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67390

Files:
  lldb/lit/Modules/ELF/load-from-dynsym-alone.c
  lldb/lit/Modules/ELF/load-symtab-and-dynsym.c
  lldb/lit/Modules/ELF/merge-symbols.yaml
  lldb/lit/Modules/lit.local.cfg
  lldb/lit/helper/toolchain.py
  lldb/source/Plugins/ObjectFile/ELF/ELFHeader.cpp
  lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h

Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -12,6 +12,7 @@
 #include 
 
 #include 
+#include 
 
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Utility/ArchSpec.h"
@@ -55,7 +56,7 @@
 /// This class provides a generic ELF (32/64 bit) reader plugin implementing
 /// the ObjectFile protocol.
 class ObjectFileELF : public lldb_private::ObjectFile {
-public:
+public:  
   // Static Functions
   static void Initialize();
 
@@ -184,6 +185,8 @@
 
   typedef std::map
   FileAddressToAddressClassMap;
+  
+  typedef std::unordered_set UniqueElfSymbolColl;
 
   /// Version of this reader common to all plugins based on this class.
   static const uint32_t m_plugin_version = 1;
@@ -278,7 +281,8 @@
   /// will parse the symbols only once.  Returns the number of symbols parsed.
   unsigned ParseSymbolTable(lldb_private::Symtab *symbol_table,
 lldb::user_id_t start_id,
-lldb_private::Section *symtab);
+lldb_private::Section *symtab,
+UniqueElfSymbolColl &unique_elf_symbols);
 
   /// Helper routine for ParseSymbolTable().
   unsigned ParseSymbols(lldb_private::Symtab *symbol_table,
@@ -286,7 +290,8 @@
 lldb_private::SectionList *section_list,
 const size_t num_symbols,
 const lldb_private::DataExtractor &symtab_data,
-const lldb_private::DataExtractor &strtab_data);
+const lldb_private::DataExtractor &strtab_data,
+UniqueElfSymbolColl &unique_elf_symbols);
 
   /// Scans the relocation entries and adds a set of artificial symbols to the
   /// given symbol table for each PLT slot.  Returns the number of symbols
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -1871,7 +1871,8 @@
  SectionList *section_list,
  const size_t num_symbols,
  const DataExtractor &symtab_data,
- const DataExtractor &strtab_data) {
+ const DataExtractor &strtab_data,
+ UniqueElfSymbolColl &unique_elf_symbols) {
   ELFSymbol symbol;
   lldb::offset_t offset = 0;
 
@@ -2196,20 +2197,28 @@
 symbol_size_valid,  // Symbol size is valid
 has_suffix, // Contains linker annotations?
 flags); // Symbol flags.
-symtab->AddSymbol(dc_symbol);
+
+NamedELFSymbol needle(symbol, ConstString(symbol_ref),
+  symbol_section_sp.get() ? symbol_section_sp->GetName()
+  : ConstString());
+if (unique_elf_symbols.insert(needle).second) {
+  symtab->AddSymbol(dc_symbol);
+}
   }
   return i;
 }
 
-unsigned ObjectFileELF::ParseSymbolTable(Symtab *symbol_table,
- user_id_t start_id,
- lldb_private::Section *symtab) {
+unsigned
+ObjectFileELF::ParseSymbolTable(Symtab *symbol_table, user_id_t start_id,
+lldb_private::Section *symtab,
+UniqueElfSymbolColl &unique_elf_symbols) {
   if (symtab->GetObjectFile() != this) {
 // If the symbol table section is owned by a different object file, have it
 // do the parsing.
 ObjectFileELF *obj_file_elf =
 static_cast(symtab->GetObjectFile());
-return obj_file_elf->ParseSymbolTable(symbol_table, start_id, symtab);
+return obj_file_elf->ParseSymbolTable(symbol_table, start_id, symtab,
+  unique_elf_symbols);
   }
 
   // G

[Lldb-commits] [PATCH] D67390: [LLDB][ELF] Load both, .symtab and .dynsym sections

2019-10-01 Thread Konrad Wilhelm Kleine via Phabricator via lldb-commits
kwk marked an inline comment as done.
kwk added a comment.

@labath can you please check this patch one last time (hopefully)?




Comment at: lldb/source/Plugins/ObjectFile/ELF/ELFHeader.cpp:371-373
+  r.st_name = st_name;
+  return elf::ELFSymbol::operator==(r) &&
+ st_name_string == rhs.st_name_string;

labath wrote:
> kwk wrote:
> > labath wrote:
> > > kwk wrote:
> > > > clayborg wrote:
> > > > > I would almost just manually compare only the things we care about 
> > > > > here. Again, what about st_shndx when comparing a symbol from the 
> > > > > main symbol table and one from the .gnu_debugdata symbol table. Are 
> > > > > those section indexes guaranteed to match? I would think not. 
> > > > @clayborg I explicitly only compare what we care about and therefore 
> > > > always set the name index to  be the same.
> > > I'll echo @clayborg here. This business with copying the ELFSymbol and 
> > > clearing some fields is confusing. Do you even need the 
> > > ELFSymbol::operator== for anything? If not I'd just delete that, and have 
> > > the derived version compare all fields.
> > > 
> > > Also, it would be nice if the operator== and hash function definitions 
> > > were next to each other. Can you just forward declare the std::hash stuff 
> > > in the header, and have the implementation be next to this?
> > > I'll echo @clayborg here. This business with copying the ELFSymbol and 
> > > clearing some fields is confusing.
> > 
> > I've cleared up the documentation now and it is exactly the way I like it. 
> > Every entity deals with it's own business (respects its own fields when 
> > comparing). I find it pretty dirty to compare fields from the base struct 
> > in a derived one. The way I compare fields from the base struct is 
> > minimally invasive.
> > 
> > > Do you even need the ELFSymbol::operator== for anything?
> > 
> > Yes, when you want to compare ELFSymbols. I know that I don't do that 
> > explicitly but I the function only deals with fields from the entity itself 
> > and they don't spill into any derived structure (with the exception of 
> > explicitly ignoring fields).
> > 
> > > If not I'd just delete that, and have the derived version compare all 
> > > fields.
> > 
> > No because I call it explcitly from the derived NamedELFSymbol.
> > 
> > > Also, it would be nice if the operator== and hash function definitions 
> > > were next to each other. Can you just forward declare the std::hash stuff 
> > > in the header, and have the implementation be next to this?
> > 
> > I've found a compromise that is even more appealing to me. The ELFSymbol 
> > and NamedELFSymbol structs now have a `hash` function which contains the 
> > implementation next to the one of `operator==()`. This `hash` is called in 
> > the specialization which remains in the same location as before; the reason 
> > being that I didn't find a way do define something in the `std::` namespace 
> > when I'm in the `elf::` namespace.
> > 
> > 
> > Yes, when you want to compare ELFSymbols. I know that I don't do that 
> > explicitly but I the function only deals with fields from the entity itself 
> > and they don't spill into any derived structure (with the exception of 
> > explicitly ignoring fields).
> Yes, but to me that exception kind of invalidates the whole idea. In order to 
> know which fields you need to ignore, you need the knowledge of what fields 
> are present in the struct (and as the fields are public, that is not a big 
> deal), at which point you can just avoid the whole copying business, and 
> explicitly compare the fields that you care about. Given that this also saves 
> a nontrivial amount of code, I still think it's a better way to go. (Also, 
> defining equality operators on class hierarchies is usually not a good idea 
> even if they "nest" nicely, since they can still produce strange results due 
> to object slicing.)
> 
> > I've found a compromise that is even more appealing to me. The ELFSymbol 
> > and NamedELFSymbol structs now have a hash function which contains the 
> > implementation next to the one of operator==().
> 
> That works for me.
@labath okay, I've remove the logic from `ELFSymbol` and coded everything 
straight away. I guess, that I wanted to be able to extend `ELFSymbol` with n 
number of fields and add them to the `ELFSymbol::operator==()` without touching 
the `NamedELFSymbol::operator==()` as long as the added fields shall not be 
ignored. Makes sense? I guess that you can find arguments for both ways to 
implement it. Anyway, I've coded it the way you want now, I hope.



Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:2205
+needle.st_section_name_string = 
ConstString(symbol_section_sp->GetName());
+if (unique_elf_symbols.find(needle) == unique_elf_symbols.end()) {
+  symtab->AddSymbol(dc_symbol);

labath wrote:
> kwk wrote:
> > labath wrote:
> > > jankratochvil wrote:
> > > 

[Lldb-commits] [PATCH] D68140: [lldb][clang][modern-type-lookup] Use ASTImporterSharedState in ExternalASTMerger

2019-10-01 Thread Gabor Marton via Phabricator via lldb-commits
martong added a comment.

Raphael, thanks for working on this. Overall, the changes look good to me, but 
please see my comment for the constructor.




Comment at: cfe/trunk/lib/AST/ExternalASTMerger.cpp:320
+  SharedState = std::make_shared(
+  *Target.AST.getTranslationUnitDecl());
   AddSources(Sources);

For safety, it would make sense to check that there isn't any ExternalASTSource 
attached to `Target.AST` yet.
(`assert(Target.AST.getExternalSource() == nullptr)` ?)

If that is not the case then the constructor of the ASTImporterSpecificLookup 
(inited from the SharedState ctor) will traverse through the decls and that 
would result in consulting with the existing and already set ExternalSource. 
And that is something that we should avoid because we are right now in the 
middle of setting up the ExternalSource.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D68140



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


[Lldb-commits] [PATCH] D68181: SBDebugger::SetInputFile, SetOutputFile, etc.

2019-10-01 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.

LGTM. thanks.




Comment at: lldb/include/lldb/API/SBFile.h:31-36
   operator bool() const { return IsValid(); }
   bool operator!() const { return !IsValid(); }
 
 private:
   FileSP m_opaque_sp;
+  SBFile(FileSP file_sp) : m_opaque_sp(file_sp) {}

All (including private) SB methods should be defined out of line. Otherwise, 
their implementation becomes a part of the ABI.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68181



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


[Lldb-commits] [PATCH] D67390: [LLDB][ELF] Load both, .symtab and .dynsym sections

2019-10-01 Thread Konrad Wilhelm Kleine via Phabricator via lldb-commits
kwk updated this revision to Diff 222576.
kwk added a comment.

- Correct comment of test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67390

Files:
  lldb/lit/Modules/ELF/load-from-dynsym-alone.c
  lldb/lit/Modules/ELF/load-symtab-and-dynsym.c
  lldb/lit/Modules/ELF/merge-symbols.yaml
  lldb/lit/Modules/lit.local.cfg
  lldb/lit/helper/toolchain.py
  lldb/source/Plugins/ObjectFile/ELF/ELFHeader.cpp
  lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h

Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -12,6 +12,7 @@
 #include 
 
 #include 
+#include 
 
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Utility/ArchSpec.h"
@@ -55,7 +56,7 @@
 /// This class provides a generic ELF (32/64 bit) reader plugin implementing
 /// the ObjectFile protocol.
 class ObjectFileELF : public lldb_private::ObjectFile {
-public:
+public:  
   // Static Functions
   static void Initialize();
 
@@ -184,6 +185,8 @@
 
   typedef std::map
   FileAddressToAddressClassMap;
+  
+  typedef std::unordered_set UniqueElfSymbolColl;
 
   /// Version of this reader common to all plugins based on this class.
   static const uint32_t m_plugin_version = 1;
@@ -278,7 +281,8 @@
   /// will parse the symbols only once.  Returns the number of symbols parsed.
   unsigned ParseSymbolTable(lldb_private::Symtab *symbol_table,
 lldb::user_id_t start_id,
-lldb_private::Section *symtab);
+lldb_private::Section *symtab,
+UniqueElfSymbolColl &unique_elf_symbols);
 
   /// Helper routine for ParseSymbolTable().
   unsigned ParseSymbols(lldb_private::Symtab *symbol_table,
@@ -286,7 +290,8 @@
 lldb_private::SectionList *section_list,
 const size_t num_symbols,
 const lldb_private::DataExtractor &symtab_data,
-const lldb_private::DataExtractor &strtab_data);
+const lldb_private::DataExtractor &strtab_data,
+UniqueElfSymbolColl &unique_elf_symbols);
 
   /// Scans the relocation entries and adds a set of artificial symbols to the
   /// given symbol table for each PLT slot.  Returns the number of symbols
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -1871,7 +1871,8 @@
  SectionList *section_list,
  const size_t num_symbols,
  const DataExtractor &symtab_data,
- const DataExtractor &strtab_data) {
+ const DataExtractor &strtab_data,
+ UniqueElfSymbolColl &unique_elf_symbols) {
   ELFSymbol symbol;
   lldb::offset_t offset = 0;
 
@@ -2196,20 +2197,28 @@
 symbol_size_valid,  // Symbol size is valid
 has_suffix, // Contains linker annotations?
 flags); // Symbol flags.
-symtab->AddSymbol(dc_symbol);
+
+NamedELFSymbol needle(symbol, ConstString(symbol_ref),
+  symbol_section_sp.get() ? symbol_section_sp->GetName()
+  : ConstString());
+if (unique_elf_symbols.insert(needle).second) {
+  symtab->AddSymbol(dc_symbol);
+}
   }
   return i;
 }
 
-unsigned ObjectFileELF::ParseSymbolTable(Symtab *symbol_table,
- user_id_t start_id,
- lldb_private::Section *symtab) {
+unsigned
+ObjectFileELF::ParseSymbolTable(Symtab *symbol_table, user_id_t start_id,
+lldb_private::Section *symtab,
+UniqueElfSymbolColl &unique_elf_symbols) {
   if (symtab->GetObjectFile() != this) {
 // If the symbol table section is owned by a different object file, have it
 // do the parsing.
 ObjectFileELF *obj_file_elf =
 static_cast(symtab->GetObjectFile());
-return obj_file_elf->ParseSymbolTable(symbol_table, start_id, symtab);
+return obj_file_elf->ParseSymbolTable(symbol_table, start_id, symtab,
+  unique_elf_symbols);
   }
 
   // Get section list for this object file.
@@ -2237,7 +2246,7 @@
   size_t num_symbols = symtab_data.GetByteSize() / symtab_hdr->sh_entsize;
 
   retur

[Lldb-commits] [PATCH] D67390: [LLDB][ELF] Load both, .symtab and .dynsym sections

2019-10-01 Thread Konrad Wilhelm Kleine via Phabricator via lldb-commits
kwk updated this revision to Diff 222577.
kwk added a comment.

- Fix comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67390

Files:
  lldb/lit/Modules/ELF/load-from-dynsym-alone.c
  lldb/lit/Modules/ELF/load-symtab-and-dynsym.c
  lldb/lit/Modules/ELF/merge-symbols.yaml
  lldb/lit/Modules/lit.local.cfg
  lldb/lit/helper/toolchain.py
  lldb/source/Plugins/ObjectFile/ELF/ELFHeader.cpp
  lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h

Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -12,6 +12,7 @@
 #include 
 
 #include 
+#include 
 
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Utility/ArchSpec.h"
@@ -55,7 +56,7 @@
 /// This class provides a generic ELF (32/64 bit) reader plugin implementing
 /// the ObjectFile protocol.
 class ObjectFileELF : public lldb_private::ObjectFile {
-public:
+public:  
   // Static Functions
   static void Initialize();
 
@@ -184,6 +185,8 @@
 
   typedef std::map
   FileAddressToAddressClassMap;
+  
+  typedef std::unordered_set UniqueElfSymbolColl;
 
   /// Version of this reader common to all plugins based on this class.
   static const uint32_t m_plugin_version = 1;
@@ -278,7 +281,8 @@
   /// will parse the symbols only once.  Returns the number of symbols parsed.
   unsigned ParseSymbolTable(lldb_private::Symtab *symbol_table,
 lldb::user_id_t start_id,
-lldb_private::Section *symtab);
+lldb_private::Section *symtab,
+UniqueElfSymbolColl &unique_elf_symbols);
 
   /// Helper routine for ParseSymbolTable().
   unsigned ParseSymbols(lldb_private::Symtab *symbol_table,
@@ -286,7 +290,8 @@
 lldb_private::SectionList *section_list,
 const size_t num_symbols,
 const lldb_private::DataExtractor &symtab_data,
-const lldb_private::DataExtractor &strtab_data);
+const lldb_private::DataExtractor &strtab_data,
+UniqueElfSymbolColl &unique_elf_symbols);
 
   /// Scans the relocation entries and adds a set of artificial symbols to the
   /// given symbol table for each PLT slot.  Returns the number of symbols
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -1871,7 +1871,8 @@
  SectionList *section_list,
  const size_t num_symbols,
  const DataExtractor &symtab_data,
- const DataExtractor &strtab_data) {
+ const DataExtractor &strtab_data,
+ UniqueElfSymbolColl &unique_elf_symbols) {
   ELFSymbol symbol;
   lldb::offset_t offset = 0;
 
@@ -2196,20 +2197,28 @@
 symbol_size_valid,  // Symbol size is valid
 has_suffix, // Contains linker annotations?
 flags); // Symbol flags.
-symtab->AddSymbol(dc_symbol);
+
+NamedELFSymbol needle(symbol, ConstString(symbol_ref),
+  symbol_section_sp.get() ? symbol_section_sp->GetName()
+  : ConstString());
+if (unique_elf_symbols.insert(needle).second) {
+  symtab->AddSymbol(dc_symbol);
+}
   }
   return i;
 }
 
-unsigned ObjectFileELF::ParseSymbolTable(Symtab *symbol_table,
- user_id_t start_id,
- lldb_private::Section *symtab) {
+unsigned
+ObjectFileELF::ParseSymbolTable(Symtab *symbol_table, user_id_t start_id,
+lldb_private::Section *symtab,
+UniqueElfSymbolColl &unique_elf_symbols) {
   if (symtab->GetObjectFile() != this) {
 // If the symbol table section is owned by a different object file, have it
 // do the parsing.
 ObjectFileELF *obj_file_elf =
 static_cast(symtab->GetObjectFile());
-return obj_file_elf->ParseSymbolTable(symbol_table, start_id, symtab);
+return obj_file_elf->ParseSymbolTable(symbol_table, start_id, symtab,
+  unique_elf_symbols);
   }
 
   // Get section list for this object file.
@@ -2237,7 +2246,7 @@
   size_t num_symbols = symtab_data.GetByteSize() / symtab_hdr->sh_entsize;
 
   return ParseSymbo

[Lldb-commits] [PATCH] D67390: [LLDB][ELF] Load both, .symtab and .dynsym sections

2019-10-01 Thread Konrad Wilhelm Kleine via Phabricator via lldb-commits
kwk updated this revision to Diff 222584.
kwk added a comment.

- Simplify NamedELFSymbol::hash()


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67390

Files:
  lldb/lit/Modules/ELF/load-from-dynsym-alone.c
  lldb/lit/Modules/ELF/load-symtab-and-dynsym.c
  lldb/lit/Modules/ELF/merge-symbols.yaml
  lldb/lit/Modules/lit.local.cfg
  lldb/lit/helper/toolchain.py
  lldb/source/Plugins/ObjectFile/ELF/ELFHeader.cpp
  lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h

Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -12,6 +12,7 @@
 #include 
 
 #include 
+#include 
 
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Utility/ArchSpec.h"
@@ -55,7 +56,7 @@
 /// This class provides a generic ELF (32/64 bit) reader plugin implementing
 /// the ObjectFile protocol.
 class ObjectFileELF : public lldb_private::ObjectFile {
-public:
+public:  
   // Static Functions
   static void Initialize();
 
@@ -184,6 +185,9 @@
 
   typedef std::map
   FileAddressToAddressClassMap;
+  
+  typedef std::unordered_set UniqueElfSymbolColl;
+  typedef std::shared_ptr UniqueElfSymbolCollSP;
 
   /// Version of this reader common to all plugins based on this class.
   static const uint32_t m_plugin_version = 1;
@@ -278,7 +282,8 @@
   /// will parse the symbols only once.  Returns the number of symbols parsed.
   unsigned ParseSymbolTable(lldb_private::Symtab *symbol_table,
 lldb::user_id_t start_id,
-lldb_private::Section *symtab);
+lldb_private::Section *symtab,
+UniqueElfSymbolCollSP unique_elf_symbols_sp);
 
   /// Helper routine for ParseSymbolTable().
   unsigned ParseSymbols(lldb_private::Symtab *symbol_table,
@@ -286,7 +291,8 @@
 lldb_private::SectionList *section_list,
 const size_t num_symbols,
 const lldb_private::DataExtractor &symtab_data,
-const lldb_private::DataExtractor &strtab_data);
+const lldb_private::DataExtractor &strtab_data,
+UniqueElfSymbolCollSP unique_elf_symbols_sp);
 
   /// Scans the relocation entries and adds a set of artificial symbols to the
   /// given symbol table for each PLT slot.  Returns the number of symbols
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -1871,7 +1871,8 @@
  SectionList *section_list,
  const size_t num_symbols,
  const DataExtractor &symtab_data,
- const DataExtractor &strtab_data) {
+ const DataExtractor &strtab_data,
+ UniqueElfSymbolCollSP unique_elf_symbols_sp) {
   ELFSymbol symbol;
   lldb::offset_t offset = 0;
 
@@ -1912,6 +1913,21 @@
   // pointer
   std::unordered_map section_name_to_section;
 
+  // Ensure there are enough buckets in our unique ELF symbols set.
+  if (!unique_elf_symbols_sp) {
+fprintf(stderr, "\n\nCREATING NEW SYMBOL SET(num_symbols: %lu)\n\n",
+num_symbols);
+unique_elf_symbols_sp.reset(new UniqueElfSymbolColl(num_symbols));
+  } else {
+fprintf(stderr,
+"\n\nEXTENDING OLD SYMBOL SET(num_symbols: %lu + %lu = %lu)\n\n",
+unique_elf_symbols_sp->bucket_count(), num_symbols,
+unique_elf_symbols_sp->bucket_count() + num_symbols);
+std::unique_ptr newColl(new UniqueElfSymbolColl(
+unique_elf_symbols_sp->bucket_count() + num_symbols));
+newColl->swap(*unique_elf_symbols_sp);
+  }
+
   unsigned i;
   for (i = 0; i < num_symbols; ++i) {
 if (!symbol.Parse(symtab_data, &offset))
@@ -2196,20 +2212,28 @@
 symbol_size_valid,  // Symbol size is valid
 has_suffix, // Contains linker annotations?
 flags); // Symbol flags.
-symtab->AddSymbol(dc_symbol);
+
+NamedELFSymbol needle(symbol, ConstString(symbol_ref),
+  symbol_section_sp.get() ? symbol_section_sp->GetName()
+  : ConstString());
+if (unique_elf_symbols_sp->insert(needle).second) {
+  symtab->AddSymbol(dc_symbol);
+}
   }
   return i;
 }
 
-unsigned ObjectFileELF::ParseSymbolTable(Symtab *symbol_table,
- 

[Lldb-commits] [PATCH] D68140: [lldb][clang][modern-type-lookup] Use ASTImporterSharedState in ExternalASTMerger

2019-10-01 Thread Peter Smith via Phabricator via lldb-commits
peter.smith added a comment.

This change has broken a test in the Arm and AArch64 buildbots. 
Specificallyclang/test/Import/cxx-anon-namespace/test.cpp For example 
(http://lab.llvm.org:8011/builders/clang-cmake-armv7-quick/builds/10542/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Atest.cpp)
From comparing the results on X86_64 and AArch64 it looks like the key 
difference is that the AArch64 has an extra NamespaceDecl possibly from 
something implicitly added in Arm and AArch64. I've quoted the output from 
AArch64 and X86_64, note the AArch64 has implicit __SVInt8_t ... like types 
followed by a NamespaceDecl.

Can you take a look? I guess the test could be changed, but I don't know 
whether this change was expected to change anything here?

AArch64

  Command Output (stdout):
  --
  TranslationUnitDecl 0x1fae9ec8 <> 
  |-TypedefDecl 0x1faea920 <>  implicit __int128_t 
'__int128'
  | `-BuiltinType 0x1faea460 '__int128'
  |-TypedefDecl 0x1faea990 <>  implicit __int128_t 
'__int128'
  | `-BuiltinType 0x1faea460 '__int128'
  |-TypedefDecl 0x1faeaa00 <>  implicit __uint128_t 
'unsigned __int128'
  | `-BuiltinType 0x1faea480 'unsigned __int128'
  |-TypedefDecl 0x1faeaa70 <>  implicit __uint128_t 
'unsigned __int128'
  | `-BuiltinType 0x1faea480 'unsigned __int128'
  |-TypedefDecl 0x1faeadf8 <>  implicit 
__NSConstantString '__NSConstantString_tag'
  | `-RecordType 0x1faeab70 '__NSConstantString_tag'
  |   `-CXXRecord 0x1faeaac8 '__NSConstantString_tag'
  |-CXXRecordDecl 0x1fb111a0 <>  implicit 
 struct __NSConstantString_tag definition
  | |-DefinitionData pass_in_registers aggregate standard_layout 
trivially_copyable pod trivial literal
  | | |-DefaultConstructor exists trivial needs_implicit
  | | |-CopyConstructor simple trivial has_const_param needs_implicit 
implicit_has_const_param
  | | |-MoveConstructor exists simple trivial needs_implicit
  | | |-CopyAssignment trivial has_const_param needs_implicit 
implicit_has_const_param
  | | |-MoveAssignment exists simple trivial needs_implicit
  | | `-Destructor simple irrelevant trivial needs_implicit
  | `-TypeVisibilityAttr 0x1fb11270 <> Implicit Default
  |-TypedefDecl 0x1fb11340 <>  implicit 
__NSConstantString '__NSConstantString_tag'
  | `-RecordType 0x1fb11250 '__NSConstantString_tag'
  |   `-CXXRecord 0x1fb111a0 '__NSConstantString_tag'
  |-TypedefDecl 0x1fb113a8 <>  implicit __SVInt8_t 
'__SVInt8_t'
  | `-BuiltinType 0x1faea720 '__SVInt8_t'
  |-TypedefDecl 0x1fb11410 <>  implicit __SVInt8_t 
'__SVInt8_t'
  | `-BuiltinType 0x1faea720 '__SVInt8_t'
  |-TypedefDecl 0x1fb11478 <>  implicit __SVInt16_t 
'__SVInt16_t'
  | `-BuiltinType 0x1faea740 '__SVInt16_t'
  |-TypedefDecl 0x1fb114e0 <>  implicit __SVInt16_t 
'__SVInt16_t'
  | `-BuiltinType 0x1faea740 '__SVInt16_t'
  |-TypedefDecl 0x1fb11548 <>  implicit __SVInt32_t 
'__SVInt32_t'
  | `-BuiltinType 0x1faea760 '__SVInt32_t'
  |-TypedefDecl 0x1fb115b0 <>  implicit __SVInt32_t 
'__SVInt32_t'
  | `-BuiltinType 0x1faea760 '__SVInt32_t'
  |-TypedefDecl 0x1fb11618 <>  implicit __SVInt64_t 
'__SVInt64_t'
  | `-BuiltinType 0x1faea780 '__SVInt64_t'
  |-TypedefDecl 0x1fb11680 <>  implicit __SVInt64_t 
'__SVInt64_t'
  | `-BuiltinType 0x1faea780 '__SVInt64_t'
  |-TypedefDecl 0x1fb116e8 <>  implicit __SVUint8_t 
'__SVUint8_t'
  | `-BuiltinType 0x1faea7a0 '__SVUint8_t'
  |-TypedefDecl 0x1fb11750 <>  implicit __SVUint8_t 
'__SVUint8_t'
  | `-BuiltinType 0x1faea7a0 '__SVUint8_t'
  |-TypedefDecl 0x1fb117b8 <>  implicit 
__SVUint16_t '__SVUint16_t'
  | `-BuiltinType 0x1faea7c0 '__SVUint16_t'
  |-TypedefDecl 0x1fb11820 <>  implicit 
__SVUint16_t '__SVUint16_t'
  | `-BuiltinType 0x1faea7c0 '__SVUint16_t'
  |-TypedefDecl 0x1fb11888 <>  implicit 
__SVUint32_t '__SVUint32_t'
  | `-BuiltinType 0x1faea7e0 '__SVUint32_t'
  |-TypedefDecl 0x1fb118f0 <>  implicit 
__SVUint32_t '__SVUint32_t'
  | `-BuiltinType 0x1faea7e0 '__SVUint32_t'
  |-TypedefDecl 0x1fb11958 <>  implicit 
__SVUint64_t '__SVUint64_t'
  | `-BuiltinType 0x1faea800 '__SVUint64_t'
  |-TypedefDecl 0x1fb119c0 <>  implicit 
__SVUint64_t '__SVUint64_t'
  | `-BuiltinType 0x1faea800 '__SVUint64_t'
  |-TypedefDecl 0x1fb11a28 <>  implicit 
__SVFloat16_t '__SVFloat16_t'
  | `-BuiltinType 0x1faea820 '__SVFloat16_t'
  |-TypedefDecl 0x1fb11a90 <>  implicit 
__SVFloat16_t '__SVFloat16_t'
  | `-BuiltinType 0x1faea820 '__SVFloat16_t'
  |-TypedefDecl 0x1fb11af8 <>  implicit 
__SVFloat32_t '__SVFloat32_t'
  | `-BuiltinType 0x1faea840 '__SVFloat32_t'
  |-TypedefDecl 0x1fb11b60 <>  implicit 
__SVFloat32_t '__SVFloat32_t'
  | `-BuiltinType 0x1faea840 '__SVFloat32_t'
  |-TypedefDecl 0x1fb11bc8 <>  implicit 
__SVFloat64_t '__SVFloat64_t'
  | `-BuiltinType 0x1faea860 '__SVFloat64_t'
  |-TypedefDecl 0x1fb11c30 <>  implicit 
__SVFloat64_t '__SVFloat64_t'
  | `-BuiltinType 0x1faea860 '__SVFloat64_t'
  |-TypedefDecl 0x1fb11c98 <>  implicit __SVBool_t 
'__SVBool_t'
  | `-BuiltinType 0x1faea880 '__SVBool_t'
  |-TypedefDecl 0x1fb11d00 <>  implicit __SVBool_t 
'__SVBool_t'
  | `-BuiltinType 0x

[Lldb-commits] [PATCH] D68188: allow arbitrary python streams to be converted to SBFile

2019-10-01 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

In D68188#1689104 , @lawrence_danna 
wrote:

> In D68188#1687532 , @labath wrote:
>
> > It seems to be that instead of subclassing a fully-functional File class, 
> > it would be better to create an abstract class, that both `File` and the 
> > new python thingy could implement. That would also create a natural place 
> > to write down the FILE* conversion semantics and other stuff we talked 
> > about at lldb-dev. I don't have any opinion as to whether the name `File` 
> > should denote the new abstract class, or the real thing, but it should most 
> > likely be done as a separate patch.
> >
> > What do you think about that?
>
>
> I could do it that way, but I have some reservations about it.In this 
> version the class hierarchy looks like this:
>
> File
>  |
>SimplePythonFile +
> |   |
>   TextPythonFile BinaryPythonFile
>   
>
> If we added an abstract base class, I guess it would look like this:
>
> AbstractFile
>  ||
> File  PythonFile
>  | | | |
>SimplePythonFile  | |
>  | |
> + ---+ |  
> |  |
>   TextPythonFile BinaryPythonFile
>   
>
> Does a more complicated class hierarchy like that really solve a problem or 
> make the code easier to understand?


No that wouldn't make things more understandable, but I think it has helped me 
understand what are you doing here. The usual OO answer to attempts to 
introduce complex class hierarchies is to try to use object composition 
instead. Trying to apply that here gives me the following set of classes.

- `File` (or `AbstractFile` ?) - defines just the abstract interface, documents 
what the interface is
- `NativeFile` (or `File` ?) - implements the File interface via the usual 
`FILE*` and file descriptor routines (one day these may be split into two 
classes too)
- `TextPythonFile` - implements the `File` interface via Python `TextIOBase` 
interface. Does not handle ownership/closing.
- `BinaryPythonFile` - implements the `File` interface via Python `RawIOBase` 
interface. Does not handle ownership/closing.
- `OwnedPythonFile` - implements the `File` interface by delegating to another 
`File` object. Has special handling for the close method.

This way the decision whether to "own" something is decoupled from the decision 
what api do you use to actually write to the file, and I _think_ it would make 
things clearer. What do you make of that? The thing I don't like about the 
current solution is that it leaves you with unused `FILE*` members in the 
Text/BinaryPythonFile classes, and forces the introduction of weird-looking 
`OverridesIO` methods...

(BTW, as this is C++, it allows you to "cheat" and instead of creating another 
File object the delegation can be incorporated into the type system by making 
OwnedPythonFile a template parameterized on the base class. I am fine with both 
solutions though I think I'd prefer the regular class variant.)




Comment at: lldb/include/lldb/API/SBFile.h:16-21
+/* These tags make no difference at the c++ level, but
+ * when the constructors are called from python they control
+ * how python files are converted by SWIG into FileSP */
+struct FileBorrow {};
+struct FileForceScriptingIO {};
+struct FileBorrowAndForceScriptingIO {};

lawrence_danna wrote:
> labath wrote:
> > I don't think we have anything similar to this in any of our SB classes. It 
> > might be better to avoid it. Could the same thing be achieved e.g. with a 
> > static factory function (`static SBFile SBFile::Create(FileSP file_sp, bool 
> > borrow, bool force_scripting_io)`) ?
> I don't think it can be done that way, because we want those bools to control 
> how the python object is translated into a C++ object, so we need a different 
> swig wrapper for each possibility, which means we need a different c++ 
> function to wrap  for each possibility.
> 
> One way around this would be to have SWIG translate the python object into an 
> intermediate object that just takes a reference, and then perform further 
> translation inside the SB layer.But we can't do that either, because 
> scripting support is not part of the base LLDB library, it's a plugin.And 
> in fact Xcode ships two versions of the plugin, one for python2 and one for 
> python3.The SB needs to be agnostic about different versions of python, 
> so it can't do the translation itself.   
Are you sure about that? Swig allows you to define typemaps for sequences of 
values. This example is taken from the swig documentation:
```
%typemap(in) (char *str, int len) {
$1 = PyString_AsString($input);   /* char *str */
$2 = PyString_Size($input);   /* int len   */
}
```
It seems to me tha

[Lldb-commits] [PATCH] D68258: [Windows] Introduce a switch for the `lldb-server` mode on Windows

2019-10-01 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.

Sounds reasonable. Thanks for doing this.


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D68258



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


[Lldb-commits] [PATCH] D67390: [LLDB][ELF] Load both, .symtab and .dynsym sections

2019-10-01 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a comment.

Ok, let's give this one more shot. Thanks for your patience. I do have a couple 
of additional comments inline, but I don't think we need another round of 
review for those.




Comment at: lldb/lit/Modules/ELF/merge-symbols.yaml:22
+# CHECK-NEXT: [ 5] 7 Code 0x0050 0x0008 0x0002 
different_size1
+# CHECK-NEXT: [ 6] 8 Code 0x0050 0x0009 0x0002 
different_size1
+

Please add a `CHECK-EMPTY:` after this line to ensure there are no additional 
symbols here.



Comment at: lldb/source/Plugins/ObjectFile/ELF/ELFHeader.cpp:253-256
+ELFSymbol::ELFSymbol(const ELFSymbol &other)
+: st_value(other.st_value), st_size(other.st_size), st_name(other.st_name),
+  st_info(other.st_info), st_other(other.st_other),
+  st_shndx(other.st_shndx) {}

Is this really needed? It looks like the default compiler-generated copy 
constructor would be sufficient here.



Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:1918-1919
+  if (!unique_elf_symbols_sp) {
+fprintf(stderr, "\n\nCREATING NEW SYMBOL SET(num_symbols: %lu)\n\n",
+num_symbols);
+unique_elf_symbols_sp.reset(new UniqueElfSymbolColl(num_symbols));

delete



Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:2651
 Symtab *ObjectFileELF::GetSymtab() {
+  fprintf(stderr, "GetSymtab()\n");
   ModuleSP module_sp(GetModule());

delete


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67390



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


[Lldb-commits] [lldb] r373329 - [lldb][NFC] Modernize ClangASTContext constructor

2019-10-01 Thread Raphael Isemann via lldb-commits
Author: teemperor
Date: Tue Oct  1 05:28:14 2019
New Revision: 373329

URL: http://llvm.org/viewvc/llvm-project?rev=373329&view=rev
Log:
[lldb][NFC] Modernize ClangASTContext constructor

Now using default initializers and StringRef.

Also formats the member list that we excluded from clang-format
at some point and still hangs around with the old LLDB code style.

Modified:
lldb/trunk/include/lldb/Symbol/ClangASTContext.h
lldb/trunk/source/Symbol/ClangASTContext.cpp

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=373329&r1=373328&r2=373329&view=diff
==
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Tue Oct  1 05:28:14 2019
@@ -52,7 +52,7 @@ public:
   }
 
   // Constructors and Destructors
-  ClangASTContext(const char *triple = nullptr);
+  ClangASTContext(llvm::StringRef triple = "");
 
   ~ClangASTContext() override;
 
@@ -110,7 +110,7 @@ public:
 
   const char *GetTargetTriple();
 
-  void SetTargetTriple(const char *target_triple);
+  void SetTargetTriple(llvm::StringRef target_triple);
 
   void SetArchitecture(const ArchSpec &arch);
 
@@ -978,34 +978,33 @@ protected:
   GetAsTemplateSpecialization(lldb::opaque_compiler_type_t type);
 
   // Classes that inherit from ClangASTContext can see and modify these
-  // clang-format off
-std::string m_target_triple;
-std::unique_ptr  m_ast_up;
-std::unique_ptr m_language_options_up;
-std::unique_ptr m_file_manager_up;
-std::unique_ptr   m_source_manager_up;
-std::unique_ptr   m_diagnostics_engine_up;
-std::unique_ptr  m_diagnostic_consumer_up;
-std::shared_ptr   m_target_options_rp;
-std::unique_ptr  m_target_info_up;
-std::unique_ptr m_identifier_table_up;
-std::unique_ptr   m_selector_table_up;
-std::unique_ptrm_builtins_up;
-std::unique_ptrm_dwarf_ast_parser_up;
-std::unique_ptr   m_pdb_ast_parser_up;
-std::unique_ptr m_scratch_ast_source_up;
-std::unique_ptr   m_mangle_ctx_up;
-CompleteTagDeclCallback m_callback_tag_decl;
-CompleteObjCInterfaceDeclCallback   m_callback_objc_decl;
-void *  m_callback_baton;
-clang::ExternalASTMerger::OriginMap m_origins;
-uint32_tm_pointer_byte_size;
-boolm_ast_owned;
-/// The sema associated that is currently used to build this ASTContext.
-/// May be null if we are already done parsing this ASTContext or the
-/// ASTContext wasn't created by parsing source code.
-clang::Sema *   m_sema = nullptr;
-  // clang-format on
+  std::string m_target_triple;
+  std::unique_ptr m_ast_up;
+  std::unique_ptr m_language_options_up;
+  std::unique_ptr m_file_manager_up;
+  std::unique_ptr m_source_manager_up;
+  std::unique_ptr m_diagnostics_engine_up;
+  std::unique_ptr m_diagnostic_consumer_up;
+  std::shared_ptr m_target_options_rp;
+  std::unique_ptr m_target_info_up;
+  std::unique_ptr m_identifier_table_up;
+  std::unique_ptr m_selector_table_up;
+  std::unique_ptr m_builtins_up;
+  std::unique_ptr m_dwarf_ast_parser_up;
+  std::unique_ptr m_pdb_ast_parser_up;
+  std::unique_ptr m_scratch_ast_source_up;
+  std::unique_ptr m_mangle_ctx_up;
+  CompleteTagDeclCallback m_callback_tag_decl = nullptr;
+  CompleteObjCInterfaceDeclCallback m_callback_objc_decl = nullptr;
+  void *m_callback_baton = nullptr;
+  clang::ExternalASTMerger::OriginMap m_origins;
+  uint32_t m_pointer_byte_size = 0;
+  bool m_ast_owned = false;
+  /// The sema associated that is currently used to build this ASTContext.
+  /// May be null if we are already done parsing this ASTContext or the
+  /// ASTContext wasn't created by parsing source code.
+  clang::Sema *m_sema = nullptr;
+
 private:
   // For ClangASTContext only
   ClangASTContext(const ClangASTContext &);

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=373329&r1=373328&r2=373329&view=diff
==
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Tue Oct  1 05:28:14 2019
@@ -522,14 +522,9 @@ static void ParseLangArgs(LangOptions &O
   Opts.NoInlineDefine = !Opt;
 }
 
-ClangASTContext::ClangASTContext(const char *target_triple)
-: TypeSystem(TypeSystem::eKindClang), m_target_triple(), m_ast_up(),
-  m_language_options_up(), m_s

[Lldb-commits] [lldb] r373330 - [lldb][NFC] Disallow changing the ASTContext of an ClangASTContext after construction.

2019-10-01 Thread Raphael Isemann via lldb-commits
Author: teemperor
Date: Tue Oct  1 05:55:37 2019
New Revision: 373330

URL: http://llvm.org/viewvc/llvm-project?rev=373330&view=rev
Log:
[lldb][NFC] Disallow changing the ASTContext of an ClangASTContext after 
construction.

We have no use case in LLDB where we actually do want to change the ASTContext 
after
it the ClangASTContext has been constructed. All callers of setASTContext are 
just setting
the ASTContext directly after construction, so we might as well make this a 
Constructor
instead of supporting this tricky use case.

Modified:
lldb/trunk/include/lldb/Symbol/ClangASTContext.h
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
lldb/trunk/source/Symbol/ClangASTContext.cpp

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=373330&r1=373329&r2=373330&view=diff
==
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Tue Oct  1 05:55:37 2019
@@ -54,6 +54,12 @@ public:
   // Constructors and Destructors
   ClangASTContext(llvm::StringRef triple = "");
 
+  /// Constructs a ClangASTContext that uses an existing ASTContext internally.
+  /// Useful when having an existing ASTContext created by Clang.
+  ///
+  /// \param existing_ctxt An existing ASTContext.
+  explicit ClangASTContext(clang::ASTContext &existing_ctxt);
+
   ~ClangASTContext() override;
 
   void Finalize() override;
@@ -79,8 +85,6 @@ public:
 
   clang::ASTContext *getASTContext();
 
-  void setASTContext(clang::ASTContext *ast_ctx);
-
   clang::Builtin::Context *getBuiltinContext();
 
   clang::IdentifierTable *getIdentifierTable();

Modified: 
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp?rev=373330&r1=373329&r2=373330&view=diff
==
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
(original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
Tue Oct  1 05:55:37 2019
@@ -585,9 +585,7 @@ ClangExpressionParser::ClangExpressionPa
   m_compiler->createASTContext();
   clang::ASTContext &ast_context = m_compiler->getASTContext();
 
-  m_ast_context.reset(
-  new ClangASTContext(m_compiler->getTargetOpts().Triple.c_str()));
-  m_ast_context->setASTContext(&ast_context);
+  m_ast_context.reset(new ClangASTContext(ast_context));
 
   std::string module_name("$__lldb_module");
 

Modified: 
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp?rev=373330&r1=373329&r2=373330&view=diff
==
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp 
(original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp 
Tue Oct  1 05:55:37 2019
@@ -163,9 +163,7 @@ ClangModulesDeclVendorImpl::ClangModules
   m_parser(std::move(parser)), m_origin_map() {
 
   // Initialize our ClangASTContext.
-  auto target_opts = m_compiler_invocation->getTargetOpts();
-  m_ast_context.reset(new ClangASTContext(target_opts.Triple.c_str()));
-  m_ast_context->setASTContext(&m_compiler_instance->getASTContext());
+  m_ast_context.reset(new 
ClangASTContext(m_compiler_instance->getASTContext()));
 }
 
 void ClangModulesDeclVendorImpl::ReportModuleExportsHelper(

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=373330&r1=373329&r2=373330&view=diff
==
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Tue Oct  1 05:55:37 2019
@@ -528,6 +528,14 @@ ClangASTContext::ClangASTContext(llvm::S
 SetTargetTriple(target_triple);
 }
 
+ClangASTContext::ClangASTContext(ASTContext &existing_ctxt)
+  : TypeSystem(TypeSystem::eKindClang) {
+  SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().str());
+
+  m_ast_up.reset(&existing_ctxt);
+  GetASTMap().Insert(&existing_ctxt, this);
+}
+
 // Destructor
 ClangASTContext::~ClangASTContext() { Finalize(); }
 
@@ -706,15 +714,6 @@ void ClangASTContext::RemoveExternalSour
   }
 }
 
-void ClangASTContext::setASTContext(clang::ASTContext *ast_ctx) {
-  if (!m_ast_owned) {
-m_ast_up.release();
-  }
-  m_ast_owned = false;
-  m_ast_up.reset(ast_ctx);
-  GetASTMap().Insert(ast_ctx, this);
-}
-
 ASTContext *ClangAS

[Lldb-commits] [lldb] r373334 - [lldb][NFC] Remove unused ClangASTContext functions for checking/removing the ExternalASTSource

2019-10-01 Thread Raphael Isemann via lldb-commits
Author: teemperor
Date: Tue Oct  1 06:05:57 2019
New Revision: 373334

URL: http://llvm.org/viewvc/llvm-project?rev=373334&view=rev
Log:
[lldb][NFC] Remove unused ClangASTContext functions for checking/removing the 
ExternalASTSource

Modified:
lldb/trunk/include/lldb/Symbol/ClangASTContext.h
lldb/trunk/source/Symbol/ClangASTContext.cpp

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=373334&r1=37&r2=373334&view=diff
==
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Tue Oct  1 06:05:57 2019
@@ -118,13 +118,9 @@ public:
 
   void SetArchitecture(const ArchSpec &arch);
 
-  bool HasExternalSource();
-
   void SetExternalSource(
   llvm::IntrusiveRefCntPtr &ast_source_up);
 
-  void RemoveExternalSource();
-
   bool GetCompleteDecl(clang::Decl *decl) {
 return ClangASTContext::GetCompleteDecl(getASTContext(), decl);
   }

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=373334&r1=37&r2=373334&view=diff
==
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Tue Oct  1 06:05:57 2019
@@ -688,13 +688,6 @@ void ClangASTContext::SetArchitecture(co
   SetTargetTriple(arch.GetTriple().str());
 }
 
-bool ClangASTContext::HasExternalSource() {
-  ASTContext *ast = getASTContext();
-  if (ast)
-return ast->getExternalSource() != nullptr;
-  return false;
-}
-
 void ClangASTContext::SetExternalSource(
 llvm::IntrusiveRefCntPtr &ast_source_up) {
   ASTContext *ast = getASTContext();
@@ -704,16 +697,6 @@ void ClangASTContext::SetExternalSource(
   }
 }
 
-void ClangASTContext::RemoveExternalSource() {
-  ASTContext *ast = getASTContext();
-
-  if (ast) {
-llvm::IntrusiveRefCntPtr empty_ast_source_up;
-ast->setExternalSource(empty_ast_source_up);
-ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(false);
-  }
-}
-
 ASTContext *ClangASTContext::getASTContext() {
   if (m_ast_up == nullptr) {
 m_ast_owned = true;


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


[Lldb-commits] [lldb] r373337 - [lldb][NFC] Remove unused ClangASTContext::GetHasExternalStorage

2019-10-01 Thread Raphael Isemann via lldb-commits
Author: teemperor
Date: Tue Oct  1 06:25:25 2019
New Revision: 373337

URL: http://llvm.org/viewvc/llvm-project?rev=373337&view=rev
Log:
[lldb][NFC] Remove unused ClangASTContext::GetHasExternalStorage

This code isn't used nor tested.

Modified:
lldb/trunk/include/lldb/Symbol/ClangASTContext.h
lldb/trunk/source/Symbol/ClangASTContext.cpp

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=373337&r1=373336&r2=373337&view=diff
==
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Tue Oct  1 06:25:25 2019
@@ -862,7 +862,6 @@ public:
   static bool SetHasExternalStorage(lldb::opaque_compiler_type_t type,
 bool has_extern);
 
-  static bool GetHasExternalStorage(const CompilerType &type);
   // Tag Declarations
   static bool StartTagDeclarationDefinition(const CompilerType &type);
 

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=373337&r1=373336&r2=373337&view=diff
==
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Tue Oct  1 06:25:25 2019
@@ -8721,74 +8721,6 @@ clang::ObjCMethodDecl *ClangASTContext::
   return objc_method_decl;
 }
 
-bool ClangASTContext::GetHasExternalStorage(const CompilerType &type) {
-  if (ClangUtil::IsClangType(type))
-return false;
-
-  clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
-
-  const clang::Type::TypeClass type_class = qual_type->getTypeClass();
-  switch (type_class) {
-  case clang::Type::Record: {
-clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
-if (cxx_record_decl)
-  return cxx_record_decl->hasExternalLexicalStorage() ||
- cxx_record_decl->hasExternalVisibleStorage();
-  } break;
-
-  case clang::Type::Enum: {
-clang::EnumDecl *enum_decl =
-llvm::cast(qual_type)->getDecl();
-if (enum_decl)
-  return enum_decl->hasExternalLexicalStorage() ||
- enum_decl->hasExternalVisibleStorage();
-  } break;
-
-  case clang::Type::ObjCObject:
-  case clang::Type::ObjCInterface: {
-const clang::ObjCObjectType *objc_class_type =
-llvm::dyn_cast(qual_type.getTypePtr());
-assert(objc_class_type);
-if (objc_class_type) {
-  clang::ObjCInterfaceDecl *class_interface_decl =
-  objc_class_type->getInterface();
-
-  if (class_interface_decl)
-return class_interface_decl->hasExternalLexicalStorage() ||
-   class_interface_decl->hasExternalVisibleStorage();
-}
-  } break;
-
-  case clang::Type::Typedef:
-return GetHasExternalStorage(CompilerType(
-type.GetTypeSystem(), llvm::cast(qual_type)
-  ->getDecl()
-  ->getUnderlyingType()
-  .getAsOpaquePtr()));
-
-  case clang::Type::Auto:
-return GetHasExternalStorage(CompilerType(
-type.GetTypeSystem(), llvm::cast(qual_type)
-  ->getDeducedType()
-  .getAsOpaquePtr()));
-
-  case clang::Type::Elaborated:
-return GetHasExternalStorage(CompilerType(
-type.GetTypeSystem(), llvm::cast(qual_type)
-  ->getNamedType()
-  .getAsOpaquePtr()));
-
-  case clang::Type::Paren:
-return GetHasExternalStorage(CompilerType(
-type.GetTypeSystem(),
-llvm::cast(qual_type)->desugar().getAsOpaquePtr()));
-
-  default:
-break;
-  }
-  return false;
-}
-
 bool ClangASTContext::SetHasExternalStorage(lldb::opaque_compiler_type_t type,
 bool has_extern) {
   if (!type)


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


[Lldb-commits] [PATCH] D67390: [LLDB][ELF] Load both, .symtab and .dynsym sections

2019-10-01 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil added inline comments.



Comment at: lldb/source/Plugins/ObjectFile/ELF/ELFHeader.cpp:383
+  std::hash()(st_name_string.AsCString()),
+  std::hash()(st_section_name_string.AsCString()));
+}

llvm::hash_combine already calls std::hash for each of its parameters.



Comment at: lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h:446
+std::size_t h2 = std::hash()(s.st_name_string.AsCString());
+std::size_t h3 = std::hash()(s.st_section_name_string.AsCString());
+return llvm::hash_combine(h1, h2, h3);

kwk wrote:
> jankratochvil wrote:
> > I find better to rather define `std::hash` (or provide 
> > `ConstString::Hasher` which I do in my DWZ patchset).
> Once your DWZ patchset arrives, please let me know and we can change it.
https://people.redhat.com/jkratoch/ConstStringHasher.patch - Although then the 
whole UniqueElfSymbolColl should be replaced by `std::sort`+`std::unique` of 
`std::vector` you plan in a future patch so the hashing does not matter much.




Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:1925
+unique_elf_symbols_sp->bucket_count(), num_symbols,
+unique_elf_symbols_sp->bucket_count() + num_symbols);
+std::unique_ptr newColl(new UniqueElfSymbolColl(

also delete



Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:2681
+// A unique set of ELF symbols added to the symtab
+UniqueElfSymbolCollSP unique_elf_symbols_sp;
+

For the planned rework of the unification of symbols it could be put (I think) 
to `Symtab::InitAddressIndexes` which already sorts the Symtab anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67390



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


[Lldb-commits] [lldb] r373339 - [lldb][NFC] Mark ClangASTContext constructor as explicit

2019-10-01 Thread Raphael Isemann via lldb-commits
Author: teemperor
Date: Tue Oct  1 06:45:06 2019
New Revision: 373339

URL: http://llvm.org/viewvc/llvm-project?rev=373339&view=rev
Log:
[lldb][NFC] Mark ClangASTContext constructor as explicit

Given that we can implicitly construct a ClangASTContext from any string, we 
should
really mark this as explicit.

Modified:
lldb/trunk/include/lldb/Symbol/ClangASTContext.h

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=373339&r1=373338&r2=373339&view=diff
==
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Tue Oct  1 06:45:06 2019
@@ -52,7 +52,7 @@ public:
   }
 
   // Constructors and Destructors
-  ClangASTContext(llvm::StringRef triple = "");
+  explicit ClangASTContext(llvm::StringRef triple = "");
 
   /// Constructs a ClangASTContext that uses an existing ASTContext internally.
   /// Useful when having an existing ASTContext created by Clang.


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


[Lldb-commits] [PATCH] D68270: DWARFDebugLoc: Add a function to get the address range of an entry

2019-10-01 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.
labath added reviewers: JDevlieghere, dblaikie, probinson.
Herald added a subscriber: aprantl.
Herald added a project: LLVM.

Interpreting a .debug_loclists entry is not completely trivial [citation
needed]. This patch creates a function which can be used by any
libDebugInfo user (thinking of LLDB mainly) to get the range of an
entry.

The debug_loclists parser already contained a partial implementation of
that in the dump function. This implementation is replaced by a call to
the new "getRange" function, and it falls back to printing of raw data
in case we fail to get the address range.

Because LLDB is not fully converted to llvm's debug info parser, I
provide two getRange signatures: one takes a DWARFUnit*, which is used
to resolve .debug_addr references; and one which delegates this job to a
user-supplied callback.

I add a more thorough test of debug_loclists dumping capabilities. In
writing this test, I discovered that we're not able to handle
relocations in the debug_loclists section. However, fixing this was not
completely straight-forward, so I left a TODO, and will address that in
a separate patch.


Repository:
  rL LLVM

https://reviews.llvm.org/D68270

Files:
  include/llvm/BinaryFormat/Dwarf.h
  include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h
  lib/BinaryFormat/Dwarf.cpp
  lib/DebugInfo/DWARF/DWARFDebugLoc.cpp
  test/DebugInfo/X86/fission-ranges.ll
  test/DebugInfo/X86/loclists-dwp.ll
  test/tools/llvm-dwarfdump/X86/debug_loc_dwo.s
  test/tools/llvm-dwarfdump/X86/debug_loclists.s
  test/tools/llvm-dwarfdump/X86/debug_loclists_startx_length.s

Index: test/tools/llvm-dwarfdump/X86/debug_loclists_startx_length.s
===
--- test/tools/llvm-dwarfdump/X86/debug_loclists_startx_length.s
+++ test/tools/llvm-dwarfdump/X86/debug_loclists_startx_length.s
@@ -8,7 +8,7 @@
 # CHECK: .debug_loclists contents:
 # CHECK-NEXT:0x: locations list header: length = 0x000e, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x
 # CHECK-NEXT:0x:
-# CHECK-NEXT:Addr idx 1 (w/ length 16): DW_OP_reg5 RDI
+# CHECK-NEXT:{DW_LLE_startx_length, 0x0001, 0x0010}: DW_OP_reg5 RDI
 
 .section .debug_loclists,"",@progbits
  .long  .Ldebug_loclist_table_end0-.Ldebug_loclist_table_start0
Index: test/tools/llvm-dwarfdump/X86/debug_loclists.s
===
--- /dev/null
+++ test/tools/llvm-dwarfdump/X86/debug_loclists.s
@@ -0,0 +1,122 @@
+# RUN: llvm-mc %s -filetype obj -triple x86_64-pc-linux -o %t
+# RUN: llvm-dwarfdump %t | FileCheck %s
+
+
+# CHECK:  DW_AT_location(0x000c
+# CHECK-NEXT:[0x, 0x0001): DW_OP_reg0 RAX
+# CHECK-NEXT:[0x0001, 0x0002): DW_OP_reg1 RDX
+# CHECK-NEXT:[0x0002, 0x0003): DW_OP_reg2 RCX
+# CHECK-NEXT:[0x0003, 0x0004): DW_OP_reg3 RBX
+# CHECK-NEXT:{DW_LLE_startx_length, 0xdead, 0x0001}: DW_OP_reg4 RSI)
+
+
+.text
+f:  # @f
+.Lf0:
+nop
+.Lf1:
+nop
+.Lf2:
+nop
+.Lf3:
+nop
+.Lf4:
+.Lfend:
+# -- End function
+.section.debug_loclists,"",@progbits
+.long   .Ldebug_loclist_table_end0-.Ldebug_loclist_table_start0 # Length
+.Ldebug_loclist_table_start0:
+.short  5   # Version
+.byte   8   # Address size
+.byte   0   # Segment selector size
+.long   0   # Offset entry count
+.Lloclists_table_base0:
+.Ldebug_loc0:
+.byte   3   # DW_LLE_startx_length
+.uleb128 0  #   start idx
+.uleb128 .Lf1-.Lf0  #   length
+.byte   1   # Loc expr size
+.byte   80  # super-register DW_OP_reg0
+.byte   4   # DW_LLE_offset_pair
+.uleb128 .Lf1-.Lf0  #   starting offset
+.uleb128 .Lf2-.Lf0  #   ending offset
+.byte   1   # Loc expr size
+.byte   81  # super-register DW_OP_reg1
+.byte   8   # DW_LLE_start_length
+# TODO: Make it possible to use .Lf2 here.
+.quad   2   #   starting offset
+.uleb128 .Lf3-.Lf2  #   length
+.byte   1   # Loc expr size
+.byte   82  # super-register DW_OP_reg2
+.byte   6   # DW_LLE_base_address
+# TODO: Make it possible to use .Lf3 here.
+.quad   3   #   base address
+.byte   4

[Lldb-commits] [PATCH] D68270: DWARFDebugLoc: Add a function to get the address range of an entry

2019-10-01 Thread David Blaikie via Phabricator via lldb-commits
dblaikie added inline comments.



Comment at: include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h:93-108
+
+/// Return the half-open range of addresses covered by this entry.
+/// DW_LLE_offset_pair entries are resolved using the given base address,
+/// and the supplied DWARFUnit is used to look up any pooled (debug_addr)
+/// addresses. In case of failure, an error is returned. If we could not 
get
+/// an address range because this is a base address selection entry
+/// (DW_LLE_base_address), then the error is of type IsBaseAddressError, 
and

I think using an error to express base address selection entries probably is a 
bit much.

I think this API would be more suited to a higher level abstraction over the 
whole list, rather than one entry in it. (same way we do with ranges - that API 
has been more fleshed out because of the presence of more users (symbolizers, 
etc) that want to abstract over the different representations (v4, split, v5, 
v5-split) & I think shows a fairly good direction this should go in too)

One possible caveat: it might make more sense to provide either a lazy iterator 
or a callback for entries, rather than (as the ranges API does currently) a 
full in-memory vector of the computed/finalized ranges, for efficiency's sake.

Also - would be super great if we could generalize both the range and loclist 
printing to use some common infrastructure for printing both the half-open 
range in non-verbose form and the verbose printing with underlying forms 
including RLE/LLE encodings, old-style base address selection entries (in v4), 
and also being able to print the section details (like we do for ranges when 
they're printed in the debug_info section, but we don't do it when they're 
printed in the actual debug_ranges/rnglists section... ). I realize this is a 
bit of a big feature request, but figured I'd mention it in case it helps 
inform your design direction/makes sense to address together, etc. (for 
instance, it probably means that a pair of uint64_t is insufficient, since 
we'll want to carry SectionIndex too - and maybe the start/end/section triple 
could be the same data structure (with the same printing support) as used for 
ranges, nested inside the data structure that includes the expression and can 
print that too, etc)



Comment at: lib/DebugInfo/DWARF/DWARFDebugLoc.cpp:220-222
+else
+  return createStringError(inconvertibleErrorCode(),
+   "Reading debug_addr failed");

LLVM style suggests avoiding "else after return" ( 
https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return )


Repository:
  rL LLVM

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

https://reviews.llvm.org/D68270



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


[Lldb-commits] [lldb] r373342 - Update SymbolFilePDB for FindTypes API change.

2019-10-01 Thread Adrian Prantl via lldb-commits
Author: adrian
Date: Tue Oct  1 08:29:33 2019
New Revision: 373342

URL: http://llvm.org/viewvc/llvm-project?rev=373342&view=rev
Log:
Update SymbolFilePDB for FindTypes API change.

This is untested, I don't have access to a Windows machine.

Modified:
lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h

Modified: lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp?rev=373342&r1=373341&r2=373342&view=diff
==
--- lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp Tue Oct  1 
08:29:33 2019
@@ -1441,7 +1441,7 @@ void SymbolFilePDB::AddSymbols(lldb_priv
   symtab.Finalize();
 }
 
-uint32_t SymbolFilePDB::FindTypes(
+void SymbolFilePDB::FindTypes(
 lldb_private::ConstString name,
 const lldb_private::CompilerDeclContext *parent_decl_ctx,
 uint32_t max_matches,
@@ -1449,17 +1449,15 @@ uint32_t SymbolFilePDB::FindTypes(
 lldb_private::TypeMap &types) {
   std::lock_guard guard(GetModuleMutex());
   if (!name)
-return 0;
+return;
   if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
-return 0;
+return;
 
   searched_symbol_files.clear();
   searched_symbol_files.insert(this);
 
   // There is an assumption 'name' is not a regex
   FindTypesByName(name.GetStringRef(), parent_decl_ctx, max_matches, types);
-
-  return types.GetSize();
 }
 
 void SymbolFilePDB::DumpClangAST(Stream &s) {
@@ -1582,11 +1580,9 @@ void SymbolFilePDB::FindTypesByName(
   }
 }
 
-size_t SymbolFilePDB::FindTypes(llvm::ArrayRef pattern,
-LanguageSet languages,
-lldb_private::TypeMap &types) {
-  return 0;
-}
+void SymbolFilePDB::FindTypes(llvm::ArrayRef pattern,
+  LanguageSet languages,
+  lldb_private::TypeMap &types) {}
 
 void SymbolFilePDB::GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol 
&pdb_symbol,
  uint32_t type_mask,
@@ -1638,9 +1634,9 @@ void SymbolFilePDB::GetTypesForPDBSymbol
 GetTypesForPDBSymbol(*symbol_up, type_mask, type_collection);
 }
 
-size_t SymbolFilePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope,
-   TypeClass type_mask,
-   lldb_private::TypeList &type_list) {
+void SymbolFilePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope,
+ TypeClass type_mask,
+ lldb_private::TypeList &type_list) {
   std::lock_guard guard(GetModuleMutex());
   TypeCollection type_collection;
   uint32_t old_size = type_list.GetSize();
@@ -1649,7 +1645,7 @@ size_t SymbolFilePDB::GetTypes(lldb_priv
   if (cu) {
 auto compiland_up = GetPDBCompilandByUID(cu->GetID());
 if (!compiland_up)
-  return 0;
+  return;
 GetTypesForPDBSymbol(*compiland_up, type_mask, type_collection);
   } else {
 for (uint32_t cu_idx = 0; cu_idx < GetNumCompileUnits(); ++cu_idx) {
@@ -1665,7 +1661,6 @@ size_t SymbolFilePDB::GetTypes(lldb_priv
 type->GetForwardCompilerType();
 type_list.Insert(type->shared_from_this());
   }
-  return type_list.GetSize() - old_size;
 }
 
 llvm::Expected

Modified: lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h?rev=373342&r1=373341&r2=373342&view=diff
==
--- lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h Tue Oct  1 
08:29:33 2019
@@ -125,23 +125,23 @@ public:
 
   void AddSymbols(lldb_private::Symtab &symtab) override;
 
-  uint32_t
+  void
   FindTypes(lldb_private::ConstString name,
 const lldb_private::CompilerDeclContext *parent_decl_ctx,
 uint32_t max_matches,
 llvm::DenseSet &searched_symbol_files,
 lldb_private::TypeMap &types) override;
 
-  size_t FindTypes(llvm::ArrayRef pattern,
-   lldb_private::LanguageSet languages,
-   lldb_private::TypeMap &types) override;
+  void FindTypes(llvm::ArrayRef pattern,
+ lldb_private::LanguageSet languages,
+ lldb_private::TypeMap &types) override;
 
   void FindTypesByRegex(const lldb_private::RegularExpression ®ex,
 uint32_t max_matches, lldb_private::TypeMap &types);
 
-  size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
-  lldb::TypeClass type_mask,
-  lldb_private::TypeList &type_list) override;
+  void GetTypes(lldb_private::SymbolContextScope *sc_scope,
+

[Lldb-commits] [PATCH] D68171: Remove unused "append" parameter from FindTypes API

2019-10-01 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.

I made a blind attempt in r373342. Hopefully that should fix it.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D68171



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


[Lldb-commits] [PATCH] D68248: [JSON] Use LLVM's library for encoding JSON

2019-10-01 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.

Cool. I mean both are supposed to be JSON, but are we expecting any fallout 
from a debugserver using the old library vs and lldb using the new one? I 
suppose not..


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D68248



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


[Lldb-commits] [PATCH] D68278: Fix evaluation of nested classes with parent from other CU

2019-10-01 Thread Jaroslav Sevcik via Phabricator via lldb-commits
jarin created this revision.
Herald added subscribers: lldb-commits, JDevlieghere, teemperor.
Herald added a project: LLDB.

This makes sure that we associate DIEs that are imported from other CUs with 
the appropriate decl context.

Without this fix, nested classes can be dumped directly into their CU context 
if their parent was imported from another CU.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D68278

Files:
  
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/Makefile
  
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/TestNestedClassWithParentInAnotherCU.py
  
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/main.cpp
  
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/other.cpp
  
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/shared.h
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -690,6 +690,8 @@
 type_sp = unique_ast_entry_up->m_type_sp;
 if (type_sp) {
   dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
+  LinkDeclContextToDIE(
+  GetCachedClangDeclContextForDIE(unique_ast_entry_up->m_die), die);
   return type_sp;
 }
   }
Index: packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/shared.h
===
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/shared.h
@@ -0,0 +1,17 @@
+struct OuterX {
+  template
+  struct Inner {
+int oX_inner = 42;
+  };
+};
+
+struct OuterY {
+  template
+  struct Inner {
+typename OuterX::Inner oY_inner;
+  };
+};
+
+struct WrapperB;
+
+WrapperB* foo();
Index: packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/other.cpp
===
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/other.cpp
@@ -0,0 +1,10 @@
+#include "shared.h"
+
+struct WrapperB {
+  OuterY y;
+  OuterX x;
+};
+
+WrapperB* foo() {
+  return  new WrapperB();
+}
Index: packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/main.cpp
===
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/main.cpp
@@ -0,0 +1,11 @@
+#include "shared.h"
+
+struct WrapperA {
+  OuterY::Inner y;
+};
+
+int main() {
+  WrapperA a;
+  WrapperB* b = foo();
+  return 0;  // break here
+}
Index: packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/TestNestedClassWithParentInAnotherCU.py
===
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/TestNestedClassWithParentInAnotherCU.py
@@ -0,0 +1,22 @@
+"""
+Test that we can call C++ template fucntions.
+"""
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestNestedClassWithParentInAnotherCU(TestBase):
+mydir = TestBase.compute_mydir(__file__)
+
+def test_nested_class_with_parent_in_another_cu(self):
+self.main_source_file = lldb.SBFileSpec("main.cpp")
+self.build()
+(_, _, thread, _) = lldbutil.run_to_source_breakpoint(self, "// break here", self.main_source_file)
+frame = thread.GetSelectedFrame()
+warmup_result = frame.EvaluateExpression("b")
+self.assertTrue(warmup_result.IsValid())
+expr_result = frame.EvaluateExpression("a.y.oY_inner.oX_inner")
+self.assertTrue(expr_result.IsValid())
+self.assertEqual(expr_result.GetValue(), "42")
Index: packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/Makefile
===
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp other.cpp
+
+include $(LEVEL)/Makefile.rules
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] r373344 - Remove size_t return parameter from FindTypes

2019-10-01 Thread Adrian Prantl via lldb-commits
Author: adrian
Date: Tue Oct  1 08:40:41 2019
New Revision: 373344

URL: http://llvm.org/viewvc/llvm-project?rev=373344&view=rev
Log:
Remove size_t return parameter from FindTypes

In r368345 I accidentally introduced a regression that would
over-report the number of matches found by FindTypes if the
DeclContext Filter was hit.

This patch simply removes the size_t return parameter altogether —
it's not that useful.

rdar://problem/55500457

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

Modified:
lldb/trunk/include/lldb/Core/Module.h
lldb/trunk/include/lldb/Core/ModuleList.h
lldb/trunk/include/lldb/Symbol/SymbolFile.h
lldb/trunk/include/lldb/Symbol/TypeList.h
lldb/trunk/source/API/SBModule.cpp
lldb/trunk/source/API/SBTarget.cpp
lldb/trunk/source/Commands/CommandObjectTarget.cpp
lldb/trunk/source/Core/Module.cpp
lldb/trunk/source/Core/ModuleList.cpp

lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
lldb/trunk/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h
lldb/trunk/source/Symbol/SymbolFile.cpp
lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp

Modified: lldb/trunk/include/lldb/Core/Module.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=373344&r1=373343&r2=373344&view=diff
==
--- lldb/trunk/include/lldb/Core/Module.h (original)
+++ lldb/trunk/include/lldb/Core/Module.h Tue Oct  1 08:40:41 2019
@@ -447,9 +447,7 @@ public:
   /// \param[out] type_list
   /// A type list gets populated with any matches.
   ///
-  /// \return
-  /// The number of matches added to \a type_list.
-  size_t
+  void
   FindTypes(ConstString type_name, bool exact_match, size_t max_matches,
 llvm::DenseSet &searched_symbol_files,
 TypeList &types);
@@ -459,8 +457,8 @@ public:
   /// This behaves like the other FindTypes method but allows to
   /// specify a DeclContext and a language for the type being searched
   /// for.
-  size_t FindTypes(llvm::ArrayRef pattern,
-   LanguageSet languages, TypeMap &types);
+  void FindTypes(llvm::ArrayRef pattern, LanguageSet 
languages,
+ TypeMap &types);
 
   lldb::TypeSP FindFirstType(const SymbolContext &sc,
  ConstString type_name, bool exact_match);
@@ -479,11 +477,9 @@ public:
   /// \param[out] type_list
   /// A type list gets populated with any matches.
   ///
-  /// \return
-  /// The number of matches added to \a type_list.
-  size_t FindTypesInNamespace(ConstString type_name,
-  const CompilerDeclContext *parent_decl_ctx,
-  size_t max_matches, TypeList &type_list);
+  void FindTypesInNamespace(ConstString type_name,
+const CompilerDeclContext *parent_decl_ctx,
+size_t max_matches, TypeList &type_list);
 
   /// Get const accessor for the module architecture.
   ///
@@ -1074,7 +1070,7 @@ protected:
 private:
   Module(); // Only used internally by CreateJITModule ()
 
-  size_t FindTypes_Impl(
+  void FindTypes_Impl(
   ConstString name, const CompilerDeclContext *parent_decl_ctx,
   size_t max_matches,
   llvm::DenseSet &searched_symbol_files,

Modified: lldb/trunk/include/lldb/Core/ModuleList.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ModuleList.h?rev=373344&r1=373343&r2=373344&view=diff
==
--- lldb/trunk/include/lldb/Core/ModuleList.h (original)
+++ lldb/trunk/include/lldb/Core/ModuleList.h Tue Oct  1 08:40:41 2019
@@ -393,12 +393,10 @@ public:
   /// \param[out] type_list
   /// A type list gets populated with any matches.
   ///
-  /// \return
-  /// The number of matches added to \a type_list.
-  size_t FindTypes(Module *search_first, ConstString name,
-   bool name_is_fully_qualified, size_t max_matches,
-   llvm::DenseSet &searched_symbol_files,
-   TypeList &types) const;
+  void FindTypes(Module 

[Lldb-commits] [PATCH] D68169: Remove size_t return parameter from FindTypes

2019-10-01 Thread Phabricator via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373344: Remove size_t return parameter from FindTypes 
(authored by adrian, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68169?vs=222476&id=222631#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68169

Files:
  lldb/trunk/include/lldb/Core/Module.h
  lldb/trunk/include/lldb/Core/ModuleList.h
  lldb/trunk/include/lldb/Symbol/SymbolFile.h
  lldb/trunk/include/lldb/Symbol/TypeList.h
  lldb/trunk/source/API/SBModule.cpp
  lldb/trunk/source/API/SBTarget.cpp
  lldb/trunk/source/Commands/CommandObjectTarget.cpp
  lldb/trunk/source/Core/Module.cpp
  lldb/trunk/source/Core/ModuleList.cpp
  
lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
  lldb/trunk/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
  lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
  lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h
  lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
  lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
  lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
  lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
  lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
  lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h
  lldb/trunk/source/Symbol/SymbolFile.cpp
  lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp

Index: lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
===
--- lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
+++ lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
@@ -355,8 +355,7 @@
   llvm::pdb::IPDBSession &session = symfile->GetPDBSession();
   llvm::DenseSet searched_files;
   TypeMap results;
-  symfile->FindTypes(ConstString("Class"), nullptr, false, 0, searched_files,
- results);
+  symfile->FindTypes(ConstString("Class"), nullptr, 0, searched_files, results);
   EXPECT_EQ(1u, results.GetSize());
   lldb::TypeSP udt_type = results.GetTypeAtIndex(0);
   EXPECT_EQ(ConstString("Class"), udt_type->GetName());
@@ -385,8 +384,7 @@
   llvm::dyn_cast_or_null(&clang_ast_ctx_or_err.get());
   EXPECT_NE(nullptr, clang_ast_ctx);
 
-  symfile->FindTypes(ConstString("Class"), nullptr, false, 0, searched_files,
- results);
+  symfile->FindTypes(ConstString("Class"), nullptr, 0, searched_files, results);
   EXPECT_EQ(1u, results.GetSize());
 
   auto Class = results.GetTypeAtIndex(0);
@@ -404,8 +402,8 @@
   // compiler type for both, but `FindTypes` may return more than one type
   // (with the same compiler type) because the symbols have different IDs.
   auto ClassCompilerDeclCtx = CompilerDeclContext(clang_ast_ctx, ClassDeclCtx);
-  symfile->FindTypes(ConstString("NestedClass"), &ClassCompilerDeclCtx, false,
- 0, searched_files, results);
+  symfile->FindTypes(ConstString("NestedClass"), &ClassCompilerDeclCtx, 0,
+ searched_files, results);
   EXPECT_LE(1u, results.GetSize());
 
   lldb::TypeSP udt_type = results.GetTypeAtIndex(0);
@@ -449,8 +447,8 @@
   auto ns_namespace = symfile->FindNamespace(ConstString("NS"), nullptr);
   EXPECT_TRUE(ns_namespace.IsValid());
 
-  symfile->FindTypes(ConstString("NSClass"), &ns_namespace, false,
- 0, searched_files, results);
+  symfile->FindTypes(ConstString("NSClass"), &ns_namespace, 0, searched_files,
+ results);
   EXPECT_EQ(1u, results.GetSize());
 
   lldb::TypeSP udt_type = results.GetTypeAtIndex(0);
@@ -475,8 +473,7 @@
   const char *EnumsToCheck[] = {"Enum", "ShortEnum"};
   for (auto Enum : EnumsToCheck) {
 TypeMap results;
-symfile->FindTypes(ConstString(Enum), nullptr, false, 0,
-   searched_files, results);
+symfile->FindTypes(ConstString(Enum), nullptr, 0, searched_files, results);
 EXPECT_EQ(1u, results.GetSize());
 lldb::TypeSP enum_type = results.GetTypeAtIndex(0);
 EXPECT_EQ(ConstString(Enum), enum_type->GetName());
@@ -524,8 +521,8 @@
"VariadicFuncPointerTypedef"};
   for (auto Typedef : TypedefsToCheck) {
 TypeMap results;
-symfile->FindTypes(ConstString(Typedef), nullptr, false, 0,
-   searched_files, results);
+symfile->FindTypes(ConstString(Typedef), nullptr, 0, searched_files,
+   results);
 EXPECT_EQ(1u, results.GetSize());
 lldb::TypeSP typedef_type = re

[Lldb-commits] [PATCH] D67390: [LLDB][ELF] Load both, .symtab and .dynsym sections

2019-10-01 Thread Konrad Wilhelm Kleine via Phabricator via lldb-commits
kwk added inline comments.



Comment at: lldb/source/Plugins/ObjectFile/ELF/ELFHeader.cpp:383
+  std::hash()(st_name_string.AsCString()),
+  std::hash()(st_section_name_string.AsCString()));
+}

jankratochvil wrote:
> llvm::hash_combine already calls std::hash for each of its parameters.
Good to know. Thank you.



Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:2651
 Symtab *ObjectFileELF::GetSymtab() {
+  fprintf(stderr, "GetSymtab()\n");
   ModuleSP module_sp(GetModule());

labath wrote:
> delete
Sorry, I noticed this myself as well. Some of the performance experiment 
spilled over in this patch. 



Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:2681
+// A unique set of ELF symbols added to the symtab
+UniqueElfSymbolCollSP unique_elf_symbols_sp;
+

jankratochvil wrote:
> For the planned rework of the unification of symbols it could be put (I 
> think) to `Symtab::InitAddressIndexes` which already sorts the Symtab anyway.
Honestly, for the rework I think about not to use an `std::vector` as you 
proposed but instead create the `std::unordered_set` using a bucket count that 
is equal to the number of symbols in `.symtab` and in `.dynsym`. Then inserts 
to that set will be constant as they are for the vector. But let's see how it 
goes in a followup patch. I have the feeling that if I use the approach you 
suggested, I need to keep a vector *and* a set around. The vector for 
collecting all symbols and the set for doing the unification, no? Anyway, let's 
postpone this. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67390



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


[Lldb-commits] [PATCH] D67390: [LLDB][ELF] Load both, .symtab and .dynsym sections

2019-10-01 Thread Konrad Wilhelm Kleine via Phabricator via lldb-commits
kwk updated this revision to Diff 222634.
kwk marked 10 inline comments as done.
kwk added a comment.

- Check that no additional symbols follow after the expected ones
- Use compiler-generated copy-ctor
- Cleanup from experiment
- Simplify NamedELFSymbol::hash()
- Cleanup


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67390

Files:
  lldb/lit/Modules/ELF/load-from-dynsym-alone.c
  lldb/lit/Modules/ELF/load-symtab-and-dynsym.c
  lldb/lit/Modules/ELF/merge-symbols.yaml
  lldb/lit/Modules/lit.local.cfg
  lldb/lit/helper/toolchain.py
  lldb/source/Plugins/ObjectFile/ELF/ELFHeader.cpp
  lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h

Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -12,6 +12,7 @@
 #include 
 
 #include 
+#include 
 
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Utility/ArchSpec.h"
@@ -184,6 +185,8 @@
 
   typedef std::map
   FileAddressToAddressClassMap;
+  
+  typedef std::unordered_set UniqueElfSymbolColl;
 
   /// Version of this reader common to all plugins based on this class.
   static const uint32_t m_plugin_version = 1;
@@ -278,7 +281,8 @@
   /// will parse the symbols only once.  Returns the number of symbols parsed.
   unsigned ParseSymbolTable(lldb_private::Symtab *symbol_table,
 lldb::user_id_t start_id,
-lldb_private::Section *symtab);
+lldb_private::Section *symtab,
+UniqueElfSymbolColl &unique_elf_symbols);
 
   /// Helper routine for ParseSymbolTable().
   unsigned ParseSymbols(lldb_private::Symtab *symbol_table,
@@ -286,7 +290,8 @@
 lldb_private::SectionList *section_list,
 const size_t num_symbols,
 const lldb_private::DataExtractor &symtab_data,
-const lldb_private::DataExtractor &strtab_data);
+const lldb_private::DataExtractor &strtab_data,
+UniqueElfSymbolColl &unique_elf_symbols);
 
   /// Scans the relocation entries and adds a set of artificial symbols to the
   /// given symbol table for each PLT slot.  Returns the number of symbols
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -1871,7 +1871,8 @@
  SectionList *section_list,
  const size_t num_symbols,
  const DataExtractor &symtab_data,
- const DataExtractor &strtab_data) {
+ const DataExtractor &strtab_data,
+ UniqueElfSymbolColl &unique_elf_symbols) {
   ELFSymbol symbol;
   lldb::offset_t offset = 0;
 
@@ -2196,20 +2197,28 @@
 symbol_size_valid,  // Symbol size is valid
 has_suffix, // Contains linker annotations?
 flags); // Symbol flags.
-symtab->AddSymbol(dc_symbol);
+
+NamedELFSymbol needle(symbol, ConstString(symbol_ref),
+  symbol_section_sp.get() ? symbol_section_sp->GetName()
+  : ConstString());
+if (unique_elf_symbols.insert(needle).second) {
+  symtab->AddSymbol(dc_symbol);
+}
   }
   return i;
 }
 
-unsigned ObjectFileELF::ParseSymbolTable(Symtab *symbol_table,
- user_id_t start_id,
- lldb_private::Section *symtab) {
+unsigned
+ObjectFileELF::ParseSymbolTable(Symtab *symbol_table, user_id_t start_id,
+lldb_private::Section *symtab,
+UniqueElfSymbolColl &unique_elf_symbols) {
   if (symtab->GetObjectFile() != this) {
 // If the symbol table section is owned by a different object file, have it
 // do the parsing.
 ObjectFileELF *obj_file_elf =
 static_cast(symtab->GetObjectFile());
-return obj_file_elf->ParseSymbolTable(symbol_table, start_id, symtab);
+return obj_file_elf->ParseSymbolTable(symbol_table, start_id, symtab,
+  unique_elf_symbols);
   }
 
   // Get section list for this object file.
@@ -2237,7 +2246,7 @@
   size_t num_symbols = symtab_data.GetByteSize() / symtab_hdr->sh_entsize;
 
   return ParseSymbols(symbol_table, start_id, section_list, num_symbols,
-  

[Lldb-commits] [PATCH] D68248: [JSON] Use LLVM's library for encoding JSON

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

In D68248#1688975 , @vsk wrote:

> Sweet! Does this 'automatically' fix the 'llvm-argdumper has issues escaping 
> JSON-ified input' issue we discussed in person?


No, that uses the JSON class that Pavel mentioned. My hope is to remove that 
altogether in favor of the LLVM counterpart.

In D68248#1689855 , @aprantl wrote:

> Cool. I mean both are supposed to be JSON, but are we expecting any fallout 
> from a debugserver using the old library vs and lldb using the new one? I 
> suppose not..


I ran the test suite with the just-built debugserver and didn't notice any 
regressions. If this does come up we should fix the debugserver implementation.


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D68248



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


[Lldb-commits] [PATCH] D68279: [JSON] Use LLVM's library for argdumper

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: vsk, labath, aprantl.
Herald added a subscriber: mgorny.
Herald added a project: LLDB.

This patch replaces the LLDB's JSON implementation with the one from LLVM in 
argdumper.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D68279

Files:
  lldb/tools/argdumper/CMakeLists.txt
  lldb/tools/argdumper/argdumper.cpp


Index: lldb/tools/argdumper/argdumper.cpp
===
--- lldb/tools/argdumper/argdumper.cpp
+++ lldb/tools/argdumper/argdumper.cpp
@@ -6,27 +6,15 @@
 //
 
//===--===//
 
-#include "lldb/Utility/JSON.h"
-#include "lldb/Utility/StreamString.h"
+#include "llvm/Support/JSON.h"
 
-#include 
-
-using namespace lldb_private;
+using namespace llvm;
 
 int main(int argc, char *argv[]) {
-  JSONArray::SP arguments(new JSONArray());
+  json::Array Arguments;
   for (int i = 1; i < argc; i++) {
-arguments->AppendObject(JSONString::SP(new JSONString(argv[i])));
+Arguments.push_back(argv[i]);
   }
-
-  JSONObject::SP object(new JSONObject());
-  object->SetObject("arguments", arguments);
-
-  StreamString ss;
-
-  object->Write(ss);
-
-  std::cout << ss.GetData() << std::endl;
-
+  llvm::outs() << json::Object({{"arguments", std::move(Arguments)}});
   return 0;
 }
Index: lldb/tools/argdumper/CMakeLists.txt
===
--- lldb/tools/argdumper/CMakeLists.txt
+++ lldb/tools/argdumper/CMakeLists.txt
@@ -1,6 +1,6 @@
 add_lldb_tool(lldb-argdumper ADD_TO_FRAMEWORK
   argdumper.cpp
 
-  LINK_LIBS
-lldbUtility
+  LINK_COMPONENTS
+Support
 )


Index: lldb/tools/argdumper/argdumper.cpp
===
--- lldb/tools/argdumper/argdumper.cpp
+++ lldb/tools/argdumper/argdumper.cpp
@@ -6,27 +6,15 @@
 //
 //===--===//
 
-#include "lldb/Utility/JSON.h"
-#include "lldb/Utility/StreamString.h"
+#include "llvm/Support/JSON.h"
 
-#include 
-
-using namespace lldb_private;
+using namespace llvm;
 
 int main(int argc, char *argv[]) {
-  JSONArray::SP arguments(new JSONArray());
+  json::Array Arguments;
   for (int i = 1; i < argc; i++) {
-arguments->AppendObject(JSONString::SP(new JSONString(argv[i])));
+Arguments.push_back(argv[i]);
   }
-
-  JSONObject::SP object(new JSONObject());
-  object->SetObject("arguments", arguments);
-
-  StreamString ss;
-
-  object->Write(ss);
-
-  std::cout << ss.GetData() << std::endl;
-
+  llvm::outs() << json::Object({{"arguments", std::move(Arguments)}});
   return 0;
 }
Index: lldb/tools/argdumper/CMakeLists.txt
===
--- lldb/tools/argdumper/CMakeLists.txt
+++ lldb/tools/argdumper/CMakeLists.txt
@@ -1,6 +1,6 @@
 add_lldb_tool(lldb-argdumper ADD_TO_FRAMEWORK
   argdumper.cpp
 
-  LINK_LIBS
-lldbUtility
+  LINK_COMPONENTS
+Support
 )
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D68278: Fix evaluation of nested classes with parent from other CU

2019-10-01 Thread Pavel Labath via Phabricator via lldb-commits
labath added reviewers: clayborg, JDevlieghere.
labath accepted this revision.
labath added a comment.
This revision is now accepted and ready to land.
Herald added a reviewer: shafik.

Just a bit more context (we were discussing this with Jaroslav offline): 
without this line, the `GetClangDeclContextForDie` method will fail to locate 
the clang decl context for the `OuterA::Inner` class because the class `OuterA` 
has been parsed and linked to the DIE in other.cpp's debug info when the first 
expression was evaluated. I've looked through the code and this fix makes sense 
to me, but I am not super-familiar with this, so I'd appreciate if someone 
could have another look.




Comment at: 
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/Makefile:1-2
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp other.cpp

This level stuff is no longer necessary.


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D68278



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


[Lldb-commits] [lldb] r373353 - Typo (NFC)

2019-10-01 Thread Adrian Prantl via lldb-commits
Author: adrian
Date: Tue Oct  1 10:08:41 2019
New Revision: 373353

URL: http://llvm.org/viewvc/llvm-project?rev=373353&view=rev
Log:
Typo (NFC)

Modified:
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.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=373353&r1=373352&r2=373353&view=diff
==
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
(original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp Tue Oct  
1 10:08:41 2019
@@ -148,7 +148,7 @@ TypeSP DWARFASTParserClang::ParseTypeFro
   die.GetDeclContext(decl_context);
   TypeMap dwo_types;
 
-  // The type in the Clang module must have the same langage as the current CU.
+  // The type in the Clang module must have the same language as the current 
CU.
   LanguageSet languages;
   languages.Insert(die.GetCU()->GetLanguageType());
   dwo_module_sp->GetSymbolFile()->FindTypes(decl_context, languages, 
dwo_types);
@@ -156,8 +156,8 @@ TypeSP DWARFASTParserClang::ParseTypeFro
 if (!IsClangModuleFwdDecl(die))
   return TypeSP();
 
-// Since this this type is defined in one of the Clang modules imported by
-// this symbol file, search all of them.
+// Since this type is defined in one of the Clang modules imported
+// by this symbol file, search all of them.
 auto &sym_file = die.GetCU()->GetSymbolFileDWARF();
 for (const auto &name_module : sym_file.getExternalTypeModules()) {
   if (!name_module.second)


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


[Lldb-commits] [lldb] r373354 - Fix a condition-flip regression introduced in r373344.

2019-10-01 Thread Adrian Prantl via lldb-commits
Author: adrian
Date: Tue Oct  1 10:08:44 2019
New Revision: 373354

URL: http://llvm.org/viewvc/llvm-project?rev=373354&view=rev
Log:
Fix a condition-flip regression introduced in r373344.

Modified:
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.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=373354&r1=373353&r2=373354&view=diff
==
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
(original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp Tue Oct  
1 10:08:44 2019
@@ -152,7 +152,7 @@ TypeSP DWARFASTParserClang::ParseTypeFro
   LanguageSet languages;
   languages.Insert(die.GetCU()->GetLanguageType());
   dwo_module_sp->GetSymbolFile()->FindTypes(decl_context, languages, 
dwo_types);
-  if (dwo_types.GetSize()) {
+  if (dwo_types.Empty()) {
 if (!IsClangModuleFwdDecl(die))
   return TypeSP();
 


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


[Lldb-commits] [lldb] r373352 - Simplify condition (NFC)

2019-10-01 Thread Adrian Prantl via lldb-commits
Author: adrian
Date: Tue Oct  1 10:08:38 2019
New Revision: 373352

URL: http://llvm.org/viewvc/llvm-project?rev=373352&view=rev
Log:
Simplify condition (NFC)

Modified:
lldb/trunk/source/DataFormatters/TypeFormat.cpp

Modified: lldb/trunk/source/DataFormatters/TypeFormat.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/TypeFormat.cpp?rev=373352&r1=373351&r2=373352&view=diff
==
--- lldb/trunk/source/DataFormatters/TypeFormat.cpp (original)
+++ lldb/trunk/source/DataFormatters/TypeFormat.cpp Tue Oct  1 10:08:38 2019
@@ -164,7 +164,7 @@ bool TypeFormatImpl_EnumType::FormatObje
 llvm::DenseSet searched_symbol_files;
 images.FindTypes(nullptr, m_enum_type, false, UINT32_MAX,
  searched_symbol_files, types);
-if (types.GetSize() == 0)
+if (types.Empty())
   return false;
 for (lldb::TypeSP type_sp : types.Types()) {
   if (!type_sp)


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


[Lldb-commits] [lldb] r373355 - Fix a syntax error.

2019-10-01 Thread Adrian Prantl via lldb-commits
Author: adrian
Date: Tue Oct  1 10:10:25 2019
New Revision: 373355

URL: http://llvm.org/viewvc/llvm-project?rev=373355&view=rev
Log:
Fix a syntax error.

Modified:
lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp

Modified: lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp?rev=373355&r1=373354&r2=373355&view=diff
==
--- lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp (original)
+++ lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp Tue Oct  1 
10:10:25 2019
@@ -577,7 +577,7 @@ TEST_F(SymbolFilePDBTests, TestMaxMatche
   uint32_t num_results = results.GetSize();
   for (uint32_t i = 1; i <= iterations; ++i) {
 symfile->FindTypes(name, nullptr, i, searched_files, results);
-uint32_t num_limited_results = results.GetSize() - num_results);
+uint32_t num_limited_results = results.GetSize() - num_results;
 EXPECT_EQ(i, num_limited_results);
 EXPECT_EQ(num_limited_results, results.GetSize());
   }


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


[Lldb-commits] [PATCH] D68282: [JSON] Use LLVM's library for decoding JSON in StructuredData

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, vsk, aprantl.
Herald added a project: LLDB.

This patch replaces the hand-rolled JSON decoding in StructuredData with LLVM's 
JSON library.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D68282

Files:
  lldb/include/lldb/Utility/StructuredData.h
  lldb/source/Utility/StructuredData.cpp

Index: lldb/source/Utility/StructuredData.cpp
===
--- lldb/source/Utility/StructuredData.cpp
+++ lldb/source/Utility/StructuredData.cpp
@@ -9,7 +9,6 @@
 #include "lldb/Utility/StructuredData.h"
 #include "lldb/Utility/DataBuffer.h"
 #include "lldb/Utility/FileSpec.h"
-#include "lldb/Utility/JSON.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/StreamString.h"
 #include "llvm/ADT/STLExtras.h"
@@ -22,10 +21,18 @@
 using namespace lldb_private;
 using namespace llvm;
 
-// Functions that use a JSONParser to parse JSON into StructuredData
-static StructuredData::ObjectSP ParseJSONValue(JSONParser &json_parser);
-static StructuredData::ObjectSP ParseJSONObject(JSONParser &json_parser);
-static StructuredData::ObjectSP ParseJSONArray(JSONParser &json_parser);
+static StructuredData::ObjectSP ParseJSONValue(json::Value &value);
+static StructuredData::ObjectSP ParseJSONObject(json::Object *object);
+static StructuredData::ObjectSP ParseJSONArray(json::Array *array);
+
+StructuredData::ObjectSP StructuredData::ParseJSON(std::string json_text) {
+  llvm::Expected value = json::parse(json_text);
+  if (!value) {
+llvm::consumeError(value.takeError());
+return nullptr;
+  }
+  return ParseJSONValue(*value);
+}
 
 StructuredData::ObjectSP
 StructuredData::ParseJSONFromFile(const FileSpec &input_spec, Status &error) {
@@ -38,112 +45,49 @@
 buffer_or_error.getError().message());
 return return_sp;
   }
-
-  JSONParser json_parser(buffer_or_error.get()->getBuffer());
-  return_sp = ParseJSONValue(json_parser);
-  return return_sp;
+  return ParseJSON(buffer_or_error.get()->getBuffer().str());
 }
 
-static StructuredData::ObjectSP ParseJSONObject(JSONParser &json_parser) {
-  // The "JSONParser::Token::ObjectStart" token should have already been
-  // consumed by the time this function is called
-  auto dict_up = std::make_unique();
+static StructuredData::ObjectSP ParseJSONValue(json::Value &value) {
+  if (json::Object *O = value.getAsObject())
+return ParseJSONObject(O);
 
-  std::string value;
-  std::string key;
-  while (true) {
-JSONParser::Token token = json_parser.GetToken(value);
-
-if (token == JSONParser::Token::String) {
-  key.swap(value);
-  token = json_parser.GetToken(value);
-  if (token == JSONParser::Token::Colon) {
-StructuredData::ObjectSP value_sp = ParseJSONValue(json_parser);
-if (value_sp)
-  dict_up->AddItem(key, value_sp);
-else
-  break;
-  }
-} else if (token == JSONParser::Token::ObjectEnd) {
-  return StructuredData::ObjectSP(dict_up.release());
-} else if (token == JSONParser::Token::Comma) {
-  continue;
-} else {
-  break;
-}
-  }
-  return StructuredData::ObjectSP();
-}
+  if (json::Array *A = value.getAsArray())
+return ParseJSONArray(A);
 
-static StructuredData::ObjectSP ParseJSONArray(JSONParser &json_parser) {
-  // The "JSONParser::Token::ObjectStart" token should have already been
-  // consumed by the time this function is called
-  auto array_up = std::make_unique();
+  std::string s;
+  if (json::fromJSON(value, s))
+return std::make_shared(s);
+
+  bool b;
+  if (json::fromJSON(value, b))
+return std::make_shared(b);
+
+  int64_t i;
+  if (json::fromJSON(value, i))
+return std::make_shared(i);
 
-  std::string value;
-  std::string key;
-  while (true) {
-StructuredData::ObjectSP value_sp = ParseJSONValue(json_parser);
-if (value_sp)
-  array_up->AddItem(value_sp);
-else
-  break;
-
-JSONParser::Token token = json_parser.GetToken(value);
-if (token == JSONParser::Token::Comma) {
-  continue;
-} else if (token == JSONParser::Token::ArrayEnd) {
-  return StructuredData::ObjectSP(array_up.release());
-} else {
-  break;
-}
-  }
   return StructuredData::ObjectSP();
 }
 
-static StructuredData::ObjectSP ParseJSONValue(JSONParser &json_parser) {
-  std::string value;
-  const JSONParser::Token token = json_parser.GetToken(value);
-  switch (token) {
-  case JSONParser::Token::ObjectStart:
-return ParseJSONObject(json_parser);
-
-  case JSONParser::Token::ArrayStart:
-return ParseJSONArray(json_parser);
-
-  case JSONParser::Token::Integer: {
-uint64_t uval;
-if (llvm::to_integer(value, uval, 0))
-  return std::make_shared(uval);
-  } break;
-
-  case JSONParser::Token::Float: {
-double val;
-if (llvm::to_float(value, val))
-  return std::make_shared(val);
-  } break;
-
-  case JSONParser::Token::String:
-

[Lldb-commits] [PATCH] D68282: [JSON] Use LLVM's library for decoding JSON in StructuredData

2019-10-01 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added inline comments.



Comment at: lldb/source/Utility/StructuredData.cpp:48
   }
-
-  JSONParser json_parser(buffer_or_error.get()->getBuffer());
-  return_sp = ParseJSONValue(json_parser);
-  return return_sp;
+  return ParseJSON(buffer_or_error.get()->getBuffer().str());
 }

does this propagate the error into `error`?


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D68282



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


[Lldb-commits] [PATCH] D68282: [JSON] Use LLVM's library for decoding JSON in StructuredData

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere marked an inline comment as done.
JDevlieghere added inline comments.



Comment at: lldb/source/Utility/StructuredData.cpp:48
   }
-
-  JSONParser json_parser(buffer_or_error.get()->getBuffer());
-  return_sp = ParseJSONValue(json_parser);
-  return return_sp;
+  return ParseJSON(buffer_or_error.get()->getBuffer().str());
 }

aprantl wrote:
> does this propagate the error into `error`?
No, `ParseJSON(std::string)` doesn't provide error handling. We probably should 
add that, but that would mean changing all the call sites. I'd prefer to keep 
that separate from the JSON change. 


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D68282



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


[Lldb-commits] [PATCH] D68278: Fix evaluation of nested classes with parent from other CU

2019-10-01 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor requested changes to this revision.
teemperor added a comment.
This revision now requires changes to proceed.

A few short comments what the role of the different classes/members play in the 
test case would be helpful. E.g. "This member/variable/expressions triggers the 
loading of Decl Foo in that CU". I'll take a closer look tomorrow, but on the 
first looks this patch LGTM. Thanks!




Comment at: 
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/TestNestedClassWithParentInAnotherCU.py:2
+"""
+Test that we can call C++ template fucntions.
+"""

That comment is still from the original test case.



Comment at: 
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/other.cpp:9
+WrapperB* foo() {
+  return  new WrapperB();
+}

nit pick: there are two spaces between `return` and `new` (we sadly don't use 
clang-format for tests)


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D68278



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


[Lldb-commits] [lldb] r373359 - [JSON] Use LLVM's library for encoding JSON in StructuredData

2019-10-01 Thread Jonas Devlieghere via lldb-commits
Author: jdevlieghere
Date: Tue Oct  1 10:41:48 2019
New Revision: 373359

URL: http://llvm.org/viewvc/llvm-project?rev=373359&view=rev
Log:
[JSON] Use LLVM's library for encoding JSON in StructuredData

This patch replaces the hand-rolled JSON emission in StructuredData with
LLVM's JSON library.

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

Modified:
lldb/trunk/include/lldb/Core/StructuredDataImpl.h
lldb/trunk/include/lldb/Utility/StructuredData.h
lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
lldb/trunk/source/Utility/StructuredData.cpp
lldb/trunk/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp

Modified: lldb/trunk/include/lldb/Core/StructuredDataImpl.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/StructuredDataImpl.h?rev=373359&r1=373358&r2=373359&view=diff
==
--- lldb/trunk/include/lldb/Core/StructuredDataImpl.h (original)
+++ lldb/trunk/include/lldb/Core/StructuredDataImpl.h Tue Oct  1 10:41:48 2019
@@ -54,7 +54,8 @@ public:
   return error;
 }
 
-m_data_sp->Dump(stream);
+llvm::json::OStream s(stream.AsRawOstream());
+m_data_sp->Serialize(s);
 return error;
   }
 

Modified: lldb/trunk/include/lldb/Utility/StructuredData.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/StructuredData.h?rev=373359&r1=373358&r2=373359&view=diff
==
--- lldb/trunk/include/lldb/Utility/StructuredData.h (original)
+++ lldb/trunk/include/lldb/Utility/StructuredData.h Tue Oct  1 10:41:48 2019
@@ -10,9 +10,11 @@
 #define liblldb_StructuredData_h_
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
 
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/Stream.h"
 #include "lldb/lldb-enumerations.h"
 
 #include 
@@ -28,7 +30,6 @@
 
 namespace lldb_private {
 class Status;
-class Stream;
 }
 
 namespace lldb_private {
@@ -150,7 +151,12 @@ public:
 
 void DumpToStdout(bool pretty_print = true) const;
 
-virtual void Dump(Stream &s, bool pretty_print = true) const = 0;
+virtual void Serialize(llvm::json::OStream &s) const = 0;
+
+void Dump(lldb_private::Stream &s, bool pretty_print = true) const {
+  llvm::json::OStream jso(s.AsRawOstream(), pretty_print ? 2 : 0);
+  Serialize(jso);
+}
 
   private:
 lldb::StructuredDataType m_type;
@@ -269,7 +275,7 @@ public:
 
 void AddItem(ObjectSP item) { m_items.push_back(item); }
 
-void Dump(Stream &s, bool pretty_print = true) const override;
+void Serialize(llvm::json::OStream &s) const override;
 
   protected:
 typedef std::vector collection;
@@ -287,7 +293,7 @@ public:
 
 uint64_t GetValue() { return m_value; }
 
-void Dump(Stream &s, bool pretty_print = true) const override;
+void Serialize(llvm::json::OStream &s) const override;
 
   protected:
 uint64_t m_value;
@@ -304,7 +310,7 @@ public:
 
 double GetValue() { return m_value; }
 
-void Dump(Stream &s, bool pretty_print = true) const override;
+void Serialize(llvm::json::OStream &s) const override;
 
   protected:
 double m_value;
@@ -321,7 +327,7 @@ public:
 
 bool GetValue() { return m_value; }
 
-void Dump(Stream &s, bool pretty_print = true) const override;
+void Serialize(llvm::json::OStream &s) const override;
 
   protected:
 bool m_value;
@@ -337,7 +343,7 @@ public:
 
 llvm::StringRef GetValue() { return m_value; }
 
-void Dump(Stream &s, bool pretty_print = true) const override;
+void Serialize(llvm::json::OStream &s) const override;
 
   protected:
 std::string m_value;
@@ -506,7 +512,7 @@ public:
   AddItem(key, std::make_shared(value));
 }
 
-void Dump(Stream &s, bool pretty_print = true) const override;
+void Serialize(llvm::json::OStream &s) const override;
 
   protected:
 typedef std::map collection;
@@ -521,7 +527,7 @@ public:
 
 bool IsValid() const override { return false; }
 
-void Dump(Stream &s, bool pretty_print = true) const override;
+void Serialize(llvm::json::OStream &s) const override;
   };
 
   class Generic : public Object {
@@ -535,7 +541,7 @@ public:
 
 bool IsValid() const override { return m_object != nullptr; }
 
-void Dump(Stream &s, bool pretty_print = true) const override;
+void Serialize(llvm::json::OStream &s) const override;
 
   private:
 void *m_object;

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=373359&r1=373358&r2=373359&view=diff
=

[Lldb-commits] [lldb] r373360 - [JSON] Use LLVM's library for decoding JSON in StructuredData

2019-10-01 Thread Jonas Devlieghere via lldb-commits
Author: jdevlieghere
Date: Tue Oct  1 10:41:52 2019
New Revision: 373360

URL: http://llvm.org/viewvc/llvm-project?rev=373360&view=rev
Log:
[JSON] Use LLVM's library for decoding JSON in StructuredData

This patch replaces the hand-rolled JSON decoding in StructuredData with
LLVM's JSON library.

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

Modified:
lldb/trunk/include/lldb/Utility/StructuredData.h
lldb/trunk/source/Utility/StructuredData.cpp

Modified: lldb/trunk/include/lldb/Utility/StructuredData.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/StructuredData.h?rev=373360&r1=373359&r2=373360&view=diff
==
--- lldb/trunk/include/lldb/Utility/StructuredData.h (original)
+++ lldb/trunk/include/lldb/Utility/StructuredData.h Tue Oct  1 10:41:52 2019
@@ -548,7 +548,6 @@ public:
   };
 
   static ObjectSP ParseJSON(std::string json_text);
-
   static ObjectSP ParseJSONFromFile(const FileSpec &file, Status &error);
 };
 

Modified: lldb/trunk/source/Utility/StructuredData.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/StructuredData.cpp?rev=373360&r1=373359&r2=373360&view=diff
==
--- lldb/trunk/source/Utility/StructuredData.cpp (original)
+++ lldb/trunk/source/Utility/StructuredData.cpp Tue Oct  1 10:41:52 2019
@@ -9,7 +9,6 @@
 #include "lldb/Utility/StructuredData.h"
 #include "lldb/Utility/DataBuffer.h"
 #include "lldb/Utility/FileSpec.h"
-#include "lldb/Utility/JSON.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/StreamString.h"
 #include "llvm/ADT/STLExtras.h"
@@ -22,10 +21,18 @@
 using namespace lldb_private;
 using namespace llvm;
 
-// Functions that use a JSONParser to parse JSON into StructuredData
-static StructuredData::ObjectSP ParseJSONValue(JSONParser &json_parser);
-static StructuredData::ObjectSP ParseJSONObject(JSONParser &json_parser);
-static StructuredData::ObjectSP ParseJSONArray(JSONParser &json_parser);
+static StructuredData::ObjectSP ParseJSONValue(json::Value &value);
+static StructuredData::ObjectSP ParseJSONObject(json::Object *object);
+static StructuredData::ObjectSP ParseJSONArray(json::Array *array);
+
+StructuredData::ObjectSP StructuredData::ParseJSON(std::string json_text) {
+  llvm::Expected value = json::parse(json_text);
+  if (!value) {
+llvm::consumeError(value.takeError());
+return nullptr;
+  }
+  return ParseJSONValue(*value);
+}
 
 StructuredData::ObjectSP
 StructuredData::ParseJSONFromFile(const FileSpec &input_spec, Status &error) {
@@ -38,112 +45,53 @@ StructuredData::ParseJSONFromFile(const
 buffer_or_error.getError().message());
 return return_sp;
   }
-
-  JSONParser json_parser(buffer_or_error.get()->getBuffer());
-  return_sp = ParseJSONValue(json_parser);
-  return return_sp;
+  return ParseJSON(buffer_or_error.get()->getBuffer().str());
 }
 
-static StructuredData::ObjectSP ParseJSONObject(JSONParser &json_parser) {
-  // The "JSONParser::Token::ObjectStart" token should have already been
-  // consumed by the time this function is called
-  auto dict_up = std::make_unique();
+static StructuredData::ObjectSP ParseJSONValue(json::Value &value) {
+  if (json::Object *O = value.getAsObject())
+return ParseJSONObject(O);
+
+  if (json::Array *A = value.getAsArray())
+return ParseJSONArray(A);
+
+  std::string s;
+  if (json::fromJSON(value, s))
+return std::make_shared(s);
+
+  bool b;
+  if (json::fromJSON(value, b))
+return std::make_shared(b);
+
+  int64_t i;
+  if (json::fromJSON(value, i))
+return std::make_shared(i);
+
+  double d;
+  if (json::fromJSON(value, d))
+return std::make_shared(d);
 
-  std::string value;
-  std::string key;
-  while (true) {
-JSONParser::Token token = json_parser.GetToken(value);
-
-if (token == JSONParser::Token::String) {
-  key.swap(value);
-  token = json_parser.GetToken(value);
-  if (token == JSONParser::Token::Colon) {
-StructuredData::ObjectSP value_sp = ParseJSONValue(json_parser);
-if (value_sp)
-  dict_up->AddItem(key, value_sp);
-else
-  break;
-  }
-} else if (token == JSONParser::Token::ObjectEnd) {
-  return StructuredData::ObjectSP(dict_up.release());
-} else if (token == JSONParser::Token::Comma) {
-  continue;
-} else {
-  break;
-}
-  }
   return StructuredData::ObjectSP();
 }
 
-static StructuredData::ObjectSP ParseJSONArray(JSONParser &json_parser) {
-  // The "JSONParser::Token::ObjectStart" token should have already been
-  // consumed by the time this function is called
-  auto array_up = std::make_unique();
-
-  std::string value;
-  std::string key;
-  while (true) {
-StructuredData::ObjectSP value_sp = ParseJSONValue(json_parser);
-if (value_sp)
-  array_up->AddItem(value_sp);
-else
-  brea

[Lldb-commits] [lldb] r373361 - [JSON] Use LLVM's library for argdumper

2019-10-01 Thread Jonas Devlieghere via lldb-commits
Author: jdevlieghere
Date: Tue Oct  1 10:41:55 2019
New Revision: 373361

URL: http://llvm.org/viewvc/llvm-project?rev=373361&view=rev
Log:
[JSON] Use LLVM's library for argdumper

This patch replaces the LLDB's JSON implementation with the one from
LLVM in argdumper.

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

Modified:
lldb/trunk/tools/argdumper/CMakeLists.txt
lldb/trunk/tools/argdumper/argdumper.cpp

Modified: lldb/trunk/tools/argdumper/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/argdumper/CMakeLists.txt?rev=373361&r1=373360&r2=373361&view=diff
==
--- lldb/trunk/tools/argdumper/CMakeLists.txt (original)
+++ lldb/trunk/tools/argdumper/CMakeLists.txt Tue Oct  1 10:41:55 2019
@@ -1,6 +1,6 @@
 add_lldb_tool(lldb-argdumper ADD_TO_FRAMEWORK
   argdumper.cpp
 
-  LINK_LIBS
-lldbUtility
+  LINK_COMPONENTS
+Support
 )

Modified: lldb/trunk/tools/argdumper/argdumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/argdumper/argdumper.cpp?rev=373361&r1=373360&r2=373361&view=diff
==
--- lldb/trunk/tools/argdumper/argdumper.cpp (original)
+++ lldb/trunk/tools/argdumper/argdumper.cpp Tue Oct  1 10:41:55 2019
@@ -6,27 +6,15 @@
 //
 
//===--===//
 
-#include "lldb/Utility/JSON.h"
-#include "lldb/Utility/StreamString.h"
+#include "llvm/Support/JSON.h"
 
-#include 
-
-using namespace lldb_private;
+using namespace llvm;
 
 int main(int argc, char *argv[]) {
-  JSONArray::SP arguments(new JSONArray());
+  json::Array Arguments;
   for (int i = 1; i < argc; i++) {
-arguments->AppendObject(JSONString::SP(new JSONString(argv[i])));
+Arguments.push_back(argv[i]);
   }
-
-  JSONObject::SP object(new JSONObject());
-  object->SetObject("arguments", arguments);
-
-  StreamString ss;
-
-  object->Write(ss);
-
-  std::cout << ss.GetData() << std::endl;
-
+  llvm::outs() << json::Object({{"arguments", std::move(Arguments)}});
   return 0;
 }


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


[Lldb-commits] [PATCH] D68248: [JSON] Use LLVM's library for encoding JSON

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373359: [JSON] Use LLVM's library for encoding JSON in 
StructuredData (authored by JDevlieghere, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68248?vs=222509&id=222645#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68248

Files:
  lldb/trunk/include/lldb/Core/StructuredDataImpl.h
  lldb/trunk/include/lldb/Utility/StructuredData.h
  lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
  lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
  lldb/trunk/source/Utility/StructuredData.cpp
  lldb/trunk/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp

Index: lldb/trunk/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
===
--- lldb/trunk/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
+++ lldb/trunk/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
@@ -384,9 +384,9 @@
 
   // Since the line is exceeding 80 characters.
   std::string expected_packet1 =
-  R"(jTraceStart:{"buffersize" : 8192,"metabuffersize" : 8192,"params" :)";
+  R"(jTraceStart:{"buffersize":8192,"metabuffersize":8192,"params":)";
   std::string expected_packet2 =
-  R"( {"psb" : 1,"tracetech" : "intel-pt"},"threadid" : 35,"type" : 1})";
+  R"({"psb":1,"tracetech":"intel-pt"},"threadid":35,"type":1})";
   HandlePacket(server, (expected_packet1 + expected_packet2), "1");
   ASSERT_TRUE(error.Success());
   ASSERT_EQ(result.get(), 1u);
@@ -409,8 +409,7 @@
 return client.SendStopTracePacket(trace_id, thread_id);
   });
 
-  const char *expected_packet =
-  R"(jTraceStop:{"threadid" : 35,"traceid" : 3})";
+  const char *expected_packet = R"(jTraceStop:{"threadid":35,"traceid":3})";
   HandlePacket(server, expected_packet, "OK");
   ASSERT_TRUE(result.get().Success());
 
@@ -435,8 +434,8 @@
   });
 
   std::string expected_packet1 =
-  R"(jTraceBufferRead:{"buffersize" : 32,"offset" : 0,"threadid" : 35,)";
-  std::string expected_packet2 = R"("traceid" : 3})";
+  R"(jTraceBufferRead:{"buffersize":32,"offset":0,"threadid":35,)";
+  std::string expected_packet2 = R"("traceid":3})";
   HandlePacket(server, expected_packet1+expected_packet2, "123456");
   ASSERT_TRUE(result.get().Success());
   ASSERT_EQ(buffer.size(), 3u);
@@ -467,8 +466,8 @@
   });
 
   std::string expected_packet1 =
-  R"(jTraceMetaRead:{"buffersize" : 32,"offset" : 0,"threadid" : 35,)";
-  std::string expected_packet2 = R"("traceid" : 3})";
+  R"(jTraceMetaRead:{"buffersize":32,"offset":0,"threadid":35,)";
+  std::string expected_packet2 = R"("traceid":3})";
   HandlePacket(server, expected_packet1+expected_packet2, "123456");
   ASSERT_TRUE(result.get().Success());
   ASSERT_EQ(buffer.size(), 3u);
@@ -497,11 +496,10 @@
   });
 
   const char *expected_packet =
-  R"(jTraceConfigRead:{"threadid" : 35,"traceid" : 3})";
+  R"(jTraceConfigRead:{"threadid":35,"traceid":3})";
   std::string response1 =
-  R"({"buffersize" : 8192,"params" : {"psb" : 1,"tracetech" : "intel-pt"})";
-  std::string response2 =
-  R"(],"metabuffersize" : 8192,"threadid" : 35,"type" : 1}])";
+  R"({"buffersize":8192,"params":{"psb":1,"tracetech":"intel-pt"})";
+  std::string response2 = R"(],"metabuffersize":8192,"threadid":35,"type":1}])";
   HandlePacket(server, expected_packet, response1+response2);
   ASSERT_TRUE(result.get().Success());
   ASSERT_EQ(options.getTraceBufferSize(), 8192u);
Index: lldb/trunk/source/Utility/StructuredData.cpp
===
--- lldb/trunk/source/Utility/StructuredData.cpp
+++ lldb/trunk/source/Utility/StructuredData.cpp
@@ -11,7 +11,6 @@
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/JSON.h"
 #include "lldb/Utility/Status.h"
-#include "lldb/Utility/Stream.h"
 #include "lldb/Utility/StreamString.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -21,6 +20,7 @@
 #include 
 
 using namespace lldb_private;
+using namespace llvm;
 
 // Functions that use a JSONParser to parse JSON into StructuredData
 static StructuredData::ObjectSP ParseJSONValue(JSONParser &json_parser);
@@ -181,98 +181,48 @@
 }
 
 void StructuredData::Object::DumpToStdout(bool pretty_print) const {
-  StreamString stream;
-  Dump(stream, pretty_print);
-  llvm::outs() << stream.GetString();
+  json::OStream stream(llvm::outs(), pretty_print ? 2 : 0);
+  Serialize(stream);
 }
 
-void StructuredData::Array::Dump(Stream &s, bool pretty_print) const {
-  bool first = true;
-  s << "[";
-  if (pretty_print) {
-s << "\n";
-s.IndentMore();
-  }
+void StructuredData::Array:

[Lldb-commits] [PATCH] D68282: [JSON] Use LLVM's library for decoding JSON in StructuredData

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373360: [JSON] Use LLVM's library for decoding JSON in 
StructuredData (authored by JDevlieghere, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68282?vs=222642&id=222646#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68282

Files:
  lldb/trunk/include/lldb/Utility/StructuredData.h
  lldb/trunk/source/Utility/StructuredData.cpp

Index: lldb/trunk/include/lldb/Utility/StructuredData.h
===
--- lldb/trunk/include/lldb/Utility/StructuredData.h
+++ lldb/trunk/include/lldb/Utility/StructuredData.h
@@ -548,7 +548,6 @@
   };
 
   static ObjectSP ParseJSON(std::string json_text);
-
   static ObjectSP ParseJSONFromFile(const FileSpec &file, Status &error);
 };
 
Index: lldb/trunk/source/Utility/StructuredData.cpp
===
--- lldb/trunk/source/Utility/StructuredData.cpp
+++ lldb/trunk/source/Utility/StructuredData.cpp
@@ -9,7 +9,6 @@
 #include "lldb/Utility/StructuredData.h"
 #include "lldb/Utility/DataBuffer.h"
 #include "lldb/Utility/FileSpec.h"
-#include "lldb/Utility/JSON.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/StreamString.h"
 #include "llvm/ADT/STLExtras.h"
@@ -22,10 +21,18 @@
 using namespace lldb_private;
 using namespace llvm;
 
-// Functions that use a JSONParser to parse JSON into StructuredData
-static StructuredData::ObjectSP ParseJSONValue(JSONParser &json_parser);
-static StructuredData::ObjectSP ParseJSONObject(JSONParser &json_parser);
-static StructuredData::ObjectSP ParseJSONArray(JSONParser &json_parser);
+static StructuredData::ObjectSP ParseJSONValue(json::Value &value);
+static StructuredData::ObjectSP ParseJSONObject(json::Object *object);
+static StructuredData::ObjectSP ParseJSONArray(json::Array *array);
+
+StructuredData::ObjectSP StructuredData::ParseJSON(std::string json_text) {
+  llvm::Expected value = json::parse(json_text);
+  if (!value) {
+llvm::consumeError(value.takeError());
+return nullptr;
+  }
+  return ParseJSONValue(*value);
+}
 
 StructuredData::ObjectSP
 StructuredData::ParseJSONFromFile(const FileSpec &input_spec, Status &error) {
@@ -38,112 +45,53 @@
 buffer_or_error.getError().message());
 return return_sp;
   }
-
-  JSONParser json_parser(buffer_or_error.get()->getBuffer());
-  return_sp = ParseJSONValue(json_parser);
-  return return_sp;
+  return ParseJSON(buffer_or_error.get()->getBuffer().str());
 }
 
-static StructuredData::ObjectSP ParseJSONObject(JSONParser &json_parser) {
-  // The "JSONParser::Token::ObjectStart" token should have already been
-  // consumed by the time this function is called
-  auto dict_up = std::make_unique();
+static StructuredData::ObjectSP ParseJSONValue(json::Value &value) {
+  if (json::Object *O = value.getAsObject())
+return ParseJSONObject(O);
 
-  std::string value;
-  std::string key;
-  while (true) {
-JSONParser::Token token = json_parser.GetToken(value);
-
-if (token == JSONParser::Token::String) {
-  key.swap(value);
-  token = json_parser.GetToken(value);
-  if (token == JSONParser::Token::Colon) {
-StructuredData::ObjectSP value_sp = ParseJSONValue(json_parser);
-if (value_sp)
-  dict_up->AddItem(key, value_sp);
-else
-  break;
-  }
-} else if (token == JSONParser::Token::ObjectEnd) {
-  return StructuredData::ObjectSP(dict_up.release());
-} else if (token == JSONParser::Token::Comma) {
-  continue;
-} else {
-  break;
-}
-  }
-  return StructuredData::ObjectSP();
-}
+  if (json::Array *A = value.getAsArray())
+return ParseJSONArray(A);
 
-static StructuredData::ObjectSP ParseJSONArray(JSONParser &json_parser) {
-  // The "JSONParser::Token::ObjectStart" token should have already been
-  // consumed by the time this function is called
-  auto array_up = std::make_unique();
+  std::string s;
+  if (json::fromJSON(value, s))
+return std::make_shared(s);
 
-  std::string value;
-  std::string key;
-  while (true) {
-StructuredData::ObjectSP value_sp = ParseJSONValue(json_parser);
-if (value_sp)
-  array_up->AddItem(value_sp);
-else
-  break;
+  bool b;
+  if (json::fromJSON(value, b))
+return std::make_shared(b);
 
-JSONParser::Token token = json_parser.GetToken(value);
-if (token == JSONParser::Token::Comma) {
-  continue;
-} else if (token == JSONParser::Token::ArrayEnd) {
-  return StructuredData::ObjectSP(array_up.release());
-} else {
-  break;
-}
-  }
-  return StructuredData::ObjectSP();
-}
+  int64_t i;
+  if (json::fromJSON(value, i))
+return std::make_shared(i);
 
-static StructuredData::ObjectSP ParseJSONValue

[Lldb-commits] [PATCH] D68279: [JSON] Use LLVM's library for argdumper

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373361: [JSON] Use LLVM's library for argdumper 
(authored by JDevlieghere, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68279?vs=222639&id=222647#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68279

Files:
  lldb/trunk/tools/argdumper/CMakeLists.txt
  lldb/trunk/tools/argdumper/argdumper.cpp


Index: lldb/trunk/tools/argdumper/CMakeLists.txt
===
--- lldb/trunk/tools/argdumper/CMakeLists.txt
+++ lldb/trunk/tools/argdumper/CMakeLists.txt
@@ -1,6 +1,6 @@
 add_lldb_tool(lldb-argdumper ADD_TO_FRAMEWORK
   argdumper.cpp
 
-  LINK_LIBS
-lldbUtility
+  LINK_COMPONENTS
+Support
 )
Index: lldb/trunk/tools/argdumper/argdumper.cpp
===
--- lldb/trunk/tools/argdumper/argdumper.cpp
+++ lldb/trunk/tools/argdumper/argdumper.cpp
@@ -6,27 +6,15 @@
 //
 
//===--===//
 
-#include "lldb/Utility/JSON.h"
-#include "lldb/Utility/StreamString.h"
+#include "llvm/Support/JSON.h"
 
-#include 
-
-using namespace lldb_private;
+using namespace llvm;
 
 int main(int argc, char *argv[]) {
-  JSONArray::SP arguments(new JSONArray());
+  json::Array Arguments;
   for (int i = 1; i < argc; i++) {
-arguments->AppendObject(JSONString::SP(new JSONString(argv[i])));
+Arguments.push_back(argv[i]);
   }
-
-  JSONObject::SP object(new JSONObject());
-  object->SetObject("arguments", arguments);
-
-  StreamString ss;
-
-  object->Write(ss);
-
-  std::cout << ss.GetData() << std::endl;
-
+  llvm::outs() << json::Object({{"arguments", std::move(Arguments)}});
   return 0;
 }


Index: lldb/trunk/tools/argdumper/CMakeLists.txt
===
--- lldb/trunk/tools/argdumper/CMakeLists.txt
+++ lldb/trunk/tools/argdumper/CMakeLists.txt
@@ -1,6 +1,6 @@
 add_lldb_tool(lldb-argdumper ADD_TO_FRAMEWORK
   argdumper.cpp
 
-  LINK_LIBS
-lldbUtility
+  LINK_COMPONENTS
+Support
 )
Index: lldb/trunk/tools/argdumper/argdumper.cpp
===
--- lldb/trunk/tools/argdumper/argdumper.cpp
+++ lldb/trunk/tools/argdumper/argdumper.cpp
@@ -6,27 +6,15 @@
 //
 //===--===//
 
-#include "lldb/Utility/JSON.h"
-#include "lldb/Utility/StreamString.h"
+#include "llvm/Support/JSON.h"
 
-#include 
-
-using namespace lldb_private;
+using namespace llvm;
 
 int main(int argc, char *argv[]) {
-  JSONArray::SP arguments(new JSONArray());
+  json::Array Arguments;
   for (int i = 1; i < argc; i++) {
-arguments->AppendObject(JSONString::SP(new JSONString(argv[i])));
+Arguments.push_back(argv[i]);
   }
-
-  JSONObject::SP object(new JSONObject());
-  object->SetObject("arguments", arguments);
-
-  StreamString ss;
-
-  object->Write(ss);
-
-  std::cout << ss.GetData() << std::endl;
-
+  llvm::outs() << json::Object({{"arguments", std::move(Arguments)}});
   return 0;
 }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D68278: Fix evaluation of nested classes with parent from other CU

2019-10-01 Thread Shafik Yaghmour via Phabricator via lldb-commits
shafik added a comment.

The fix makes sense to me, I wonder if we have a similar issue w/ namespaces or 
perhaps they are handled differently.


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D68278



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


[Lldb-commits] [PATCH] D68179: [lldb] Fix JSON parser to allow empty arrays

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

Hey, I just want to give you a heads up that I'm in the process to replace 
LLDB's JSON implementation with the one from LLVM. The parts in StructuredData 
are already gone (r373359, r373360) and I'm currently working on the other uses 
in LLDB, except for debugserver which I'm not planning to touch for now.


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

https://reviews.llvm.org/D68179



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


[Lldb-commits] [lldb] r373373 - Make another attempt at fixing SymbolFilePDBTests.

2019-10-01 Thread Adrian Prantl via lldb-commits
Author: adrian
Date: Tue Oct  1 11:15:22 2019
New Revision: 373373

URL: http://llvm.org/viewvc/llvm-project?rev=373373&view=rev
Log:
Make another attempt at fixing SymbolFilePDBTests.

Modified:
lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp

Modified: lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp?rev=373373&r1=373372&r2=373373&view=diff
==
--- lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp (original)
+++ lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp Tue Oct  1 
11:15:22 2019
@@ -580,6 +580,7 @@ TEST_F(SymbolFilePDBTests, TestMaxMatche
 uint32_t num_limited_results = results.GetSize() - num_results;
 EXPECT_EQ(i, num_limited_results);
 EXPECT_EQ(num_limited_results, results.GetSize());
+num_results = num_limited_results;
   }
 }
 


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


[Lldb-commits] [PATCH] D67793: new api class: SBFile

2019-10-01 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna updated this revision to Diff 222661.
lawrence_danna added a comment.

no inlines in the API


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67793

Files:
  lldb/include/lldb/API/LLDB.h
  lldb/include/lldb/API/SBDefines.h
  lldb/include/lldb/API/SBError.h
  lldb/include/lldb/API/SBFile.h
  lldb/include/lldb/Host/File.h
  
lldb/packages/Python/lldbsuite/test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py
  lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
  lldb/scripts/Python/python-typemaps.swig
  lldb/scripts/interface/SBFile.i
  lldb/scripts/lldb.swig
  lldb/source/API/CMakeLists.txt
  lldb/source/API/SBFile.cpp
  lldb/source/API/SBReproducer.cpp
  lldb/source/Host/common/File.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -466,8 +466,6 @@
   void Reset(PyRefType type, PyObject *py_obj) override;
   void Reset(File &file, const char *mode);
 
-  static uint32_t GetOptionsFromMode(llvm::StringRef mode);
-
   lldb::FileUP GetUnderlyingFile() const;
 };
 
Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -949,7 +949,6 @@
 
 PythonFile::PythonFile(File &file, const char *mode) { Reset(file, mode); }
 
-
 PythonFile::PythonFile(PyRefType type, PyObject *o) { Reset(type, o); }
 
 PythonFile::~PythonFile() {}
@@ -1014,22 +1013,6 @@
 #endif
 }
 
-uint32_t PythonFile::GetOptionsFromMode(llvm::StringRef mode) {
-  if (mode.empty())
-return 0;
-
-  return llvm::StringSwitch(mode.str())
-  .Case("r", File::eOpenOptionRead)
-  .Case("w", File::eOpenOptionWrite)
-  .Case("a", File::eOpenOptionWrite | File::eOpenOptionAppend |
- File::eOpenOptionCanCreate)
-  .Case("r+", File::eOpenOptionRead | File::eOpenOptionWrite)
-  .Case("w+", File::eOpenOptionRead | File::eOpenOptionWrite |
-  File::eOpenOptionCanCreate | File::eOpenOptionTruncate)
-  .Case("a+", File::eOpenOptionRead | File::eOpenOptionWrite |
-  File::eOpenOptionAppend | File::eOpenOptionCanCreate)
-  .Default(0);
-}
 
 FileUP PythonFile::GetUnderlyingFile() const {
   if (!IsValid())
@@ -1038,7 +1021,7 @@
   // We don't own the file descriptor returned by this function, make sure the
   // File object knows about that.
   PythonString py_mode = GetAttributeValue("mode").AsType();
-  auto options = PythonFile::GetOptionsFromMode(py_mode.GetString());
+  auto options = File::GetOptionsFromMode(py_mode.GetString());
   auto file = std::make_unique(PyObject_AsFileDescriptor(m_py_obj),
  options, false);
   if (!file->IsValid())
Index: lldb/source/Host/common/File.cpp
===
--- lldb/source/Host/common/File.cpp
+++ lldb/source/Host/common/File.cpp
@@ -68,6 +68,20 @@
   return nullptr;
 }
 
+uint32_t File::GetOptionsFromMode(llvm::StringRef mode) {
+  return llvm::StringSwitch(mode)
+  .Case("r", File::eOpenOptionRead)
+  .Case("w", File::eOpenOptionWrite)
+  .Case("a", File::eOpenOptionWrite | File::eOpenOptionAppend |
+ File::eOpenOptionCanCreate)
+  .Case("r+", File::eOpenOptionRead | File::eOpenOptionWrite)
+  .Case("w+", File::eOpenOptionRead | File::eOpenOptionWrite |
+  File::eOpenOptionCanCreate | File::eOpenOptionTruncate)
+  .Case("a+", File::eOpenOptionRead | File::eOpenOptionWrite |
+  File::eOpenOptionAppend | File::eOpenOptionCanCreate)
+  .Default(0);
+}
+
 int File::kInvalidDescriptor = -1;
 FILE *File::kInvalidStream = nullptr;
 
@@ -143,9 +157,14 @@
 
 Status File::Close() {
   Status error;
-  if (StreamIsValid() && m_own_stream) {
-if (::fclose(m_stream) == EOF)
-  error.SetErrorToErrno();
+  if (StreamIsValid()) {
+if (m_own_stream) {
+  if (::fclose(m_stream) == EOF)
+error.SetErrorToErrno();
+} else {
+  if (::fflush(m_stream) == EOF)
+error.SetErrorToErrno();
+}
   }
 
   if (DescriptorIsValid() && m_own_descriptor) {
Index: lldb/source/API/SBReproducer.cpp
===
--- lldb/source/API/SBReproducer.cpp
+++ lldb/source/API/SBReproducer.cpp
@@ -52,6 +52,7 @@
   RegisterMethods(R);
   RegisterMethods(R);
   RegisterMethods(

[Lldb-commits] [PATCH] D68181: SBDebugger::SetInputFile, SetOutputFile, etc.

2019-10-01 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna updated this revision to Diff 222664.
lawrence_danna marked an inline comment as done.
lawrence_danna added a comment.

no inlines in the API


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68181

Files:
  lldb/include/lldb/API/SBDebugger.h
  lldb/include/lldb/API/SBFile.h
  lldb/include/lldb/Core/Debugger.h
  lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
  lldb/scripts/interface/SBDebugger.i
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBFile.cpp
  lldb/source/Core/Debugger.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp

Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -954,6 +954,8 @@
 PythonFile::~PythonFile() {}
 
 bool PythonFile::Check(PyObject *py_obj) {
+  if (!py_obj)
+return false;
 #if PY_MAJOR_VERSION < 3
   return PyFile_Check(py_obj);
 #else
Index: lldb/source/Core/Debugger.cpp
===
--- lldb/source/Core/Debugger.cpp
+++ lldb/source/Core/Debugger.cpp
@@ -821,31 +821,22 @@
 
 repro::DataRecorder *Debugger::GetInputRecorder() { return m_input_recorder; }
 
-void Debugger::SetInputFileHandle(FILE *fh, bool tranfer_ownership,
-  repro::DataRecorder *recorder) {
+void Debugger::SetInputFile(FileSP file_sp, repro::DataRecorder *recorder) {
+  assert(file_sp && file_sp->IsValid());
   m_input_recorder = recorder;
-
-  m_input_file_sp = std::make_shared(fh, tranfer_ownership);
-  if (!m_input_file_sp->IsValid())
-m_input_file_sp = std::make_shared(stdin, false);
-
+  m_input_file_sp = file_sp;
   // Save away the terminal state if that is relevant, so that we can restore
   // it in RestoreInputState.
   SaveInputTerminalState();
 }
 
-void Debugger::SetOutputFileHandle(FILE *fh, bool tranfer_ownership) {
-  FileSP file_sp = std::make_shared(fh, tranfer_ownership);
-  if (!file_sp->IsValid())
-file_sp = std::make_shared(stdout, false);
+void Debugger::SetOutputFile(FileSP file_sp) {
+  assert(file_sp && file_sp->IsValid());
   m_output_stream_sp = std::make_shared(file_sp);
-
 }
 
-void Debugger::SetErrorFileHandle(FILE *fh, bool tranfer_ownership) {
-  FileSP file_sp = std::make_shared(fh, tranfer_ownership);
-  if (!file_sp->IsValid())
-file_sp = std::make_shared(stderr, false);
+void Debugger::SetErrorFile(FileSP file_sp) {
+  assert(file_sp && file_sp->IsValid());
   m_error_stream_sp = std::make_shared(file_sp);
 }
 
Index: lldb/source/API/SBFile.cpp
===
--- lldb/source/API/SBFile.cpp
+++ lldb/source/API/SBFile.cpp
@@ -16,6 +16,8 @@
 
 SBFile::~SBFile() {}
 
+SBFile::SBFile(FileSP file_sp) : m_opaque_sp(file_sp) {}
+
 SBFile::SBFile() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBFile); }
 
 SBFile::SBFile(FILE *file, bool transfer_ownership) {
Index: lldb/source/API/SBDebugger.cpp
===
--- lldb/source/API/SBDebugger.cpp
+++ lldb/source/API/SBDebugger.cpp
@@ -18,6 +18,7 @@
 #include "lldb/API/SBCommandReturnObject.h"
 #include "lldb/API/SBError.h"
 #include "lldb/API/SBEvent.h"
+#include "lldb/API/SBFile.h"
 #include "lldb/API/SBFrame.h"
 #include "lldb/API/SBListener.h"
 #include "lldb/API/SBProcess.h"
@@ -285,49 +286,96 @@
 m_opaque_sp->GetCommandInterpreter().SkipAppInitFiles(b);
 }
 
-// Shouldn't really be settable after initialization as this could cause lots
-// of problems; don't want users trying to switch modes in the middle of a
-// debugging session.
 void SBDebugger::SetInputFileHandle(FILE *fh, bool transfer_ownership) {
   LLDB_RECORD_METHOD(void, SBDebugger, SetInputFileHandle, (FILE *, bool), fh,
  transfer_ownership);
+  SetInputFile(std::make_shared(fh, transfer_ownership));
+}
 
-  if (!m_opaque_sp)
-return;
+// Shouldn't really be settable after initialization as this could cause lots
+// of problems; don't want users trying to switch modes in the middle of a
+// debugging session.
+SBError SBDebugger::SetInputFile(SBFile file) {
+  LLDB_RECORD_METHOD(SBError, SBDebugger, SetInputFile, (SBFile), file);
+
+  SBError error;
+  if (!m_opaque_sp) {
+error.ref().SetErrorString("invalid debugger");
+return error;
+  }
 
   repro::DataRecorder *recorder = nullptr;
   if (repro::Generator *g = repro::Reproducer::Instance().GetGenerator())
 recorder = g->GetOrCreate().GetNewDataRecorder();
 
+  FileSP file_sp = file.m_opaque_sp;
+
   static std::unique_ptr loader =
   repro::CommandLoader::Create(repro::Reproducer::Instance().GetLoader());
   if (loader) {
-llvm::Optional file = loader->GetNextFile();
-fh = file ? Fi

[Lldb-commits] [PATCH] D68289: [lldb-server/android] Show more processes and package name when necessary

2019-10-01 Thread walter erquinigo via Phabricator via lldb-commits
wallace created this revision.
wallace added reviewers: clayborg, aadsm, labath, xiaobai.
Herald added subscribers: lldb-commits, kristof.beyls, krytarowski, srhines.
Herald added a project: LLDB.

By default `platform process list` only shows the processes of the current user 
that lldb-server can parse.
There are several problems:

- apk programs don't have an executable file. They instead use a package name 
as identifier.
- each apk also runs under a different user. That's how android works
- because of the user permission, some files like /proc//{environ,exe} 
can't be read.

This results in a very small process list.

This is a local run on my machine

  (lldb) platform process list
  2 matching processes were found on "remote-android"
  PIDPARENT USER   TRIPLE   NAME
  == == ==  
  23291  3177  aarch64-unknown-linux-android sh
  23301  23291aarch64-unknown-linux-android lldb-server

However, I have 700 processes running at this time.

By implementing a few fallbacks for android, I've expanded this list to 202, 
filtering out kernel processes, which would presumably appear in this list if 
the device was rooted.

  (lldb) platform process list
  202 matching processes were found on "remote-android"
  PIDPARENT USER   TRIPLE   NAME
  == == ==  
  ...
  12647  3208  aarch64-unknown-linux-android sh
  12649  12647 aarch64-unknown-linux-android lldb-server
  12653  982com.samsung.faceservice
  13185  982com.samsung.vvm
  15899  982com.samsung.android.spay
  16220  982com.sec.spp.push
  17126  982
com.sec.spp.push:RemoteDlcProcess
  19772  983com.android.chrome
  20209  982com.samsung.cmh:CMH
  20380  982
com.google.android.inputmethod.latin
  20879  982
com.samsung.android.oneconnect:Receiver
  21212  983com.tencent.mm
  24459  1 aarch64-unknown-linux-android wpa_supplicant
  25974  982com.samsung.android.contacts
  26293  982
com.samsung.android.messaging
  28714  982com.samsung.android.dialer
  31605  982
com.samsung.android.MtpApplication
  32256  982com.bezobidny

Something to notice is that the architecture is unkonwn for all apks. And 
that's fine, because run-as would be required to gather this information and 
that would make this entire functionality massively slow.

There are still several improvements to make here, like displaying actual user 
names, which I'll try to do in a following diff.

Note: Regarding overall apk debugging support from lldb. I'm planning on having 
lldb spawn lldb-server by itself with the correct user, so that everything 
works well. The initial lldb-server used for connecting to the remote platform 
can be reused for such purpose. Furthermore, eventually lldb could also launch 
that initial lldb-server on its own.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68289

Files:
  lldb/source/Host/linux/Host.cpp
  lldb/source/Utility/FileSpec.cpp

Index: lldb/source/Utility/FileSpec.cpp
===
--- lldb/source/Utility/FileSpec.cpp
+++ lldb/source/Utility/FileSpec.cpp
@@ -127,53 +127,55 @@
 return true;
   for (auto i = path.find_first_of("\\/"); i != llvm::StringRef::npos;
i = path.find_first_of("\\/", i + 1)) {
-const auto next = safeCharAtIndex(path, i+1);
+const auto next = safeCharAtIndex(path, i + 1);
 switch (next) {
+case 0:
+  // path separator char at the end of the string which should be
+  // stripped unless it is the one and only character
+  return i > 0;
+case '/':
+case '\\':
+  // two path separator chars in the middle of a path needs to be
+  // normalized
+  if (i > 0)
+return true;
+  ++i;
+  break;
+
+case '.': {
+  const auto next_next = safeCharAtIndex(path, i + 2);
+  switch (next_next) {
+  default:
+break;
   case 0:
-// path separator char at the end of the string which should be
-// stripped unless it is the one and only character
-return i > 0;
+return true; // ends with "/."
   case '/':
   case '\\':
-// two path separator chars in the middle of a path needs to be
-// normaliz

[Lldb-commits] [PATCH] D68289: [lldb-server/android] Show more processes and package name when necessary

2019-10-01 Thread walter erquinigo via Phabricator via lldb-commits
wallace updated this revision to Diff 222671.
wallace added a comment.

remove file accidentally included


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68289

Files:
  lldb/source/Host/linux/Host.cpp

Index: lldb/source/Host/linux/Host.cpp
===
--- lldb/source/Host/linux/Host.cpp
+++ lldb/source/Host/linux/Host.cpp
@@ -55,7 +55,7 @@
 return false;
 
   llvm::StringRef Rest = BufferOrError.get()->getBuffer();
-  while(!Rest.empty()) {
+  while (!Rest.empty()) {
 llvm::StringRef Line;
 std::tie(Line, Rest) = Rest.split('\n');
 
@@ -144,68 +144,102 @@
   }
 }
 
-static bool GetProcessAndStatInfo(::pid_t pid,
-  ProcessInstanceInfo &process_info,
-  ProcessState &State, ::pid_t &tracerpid) {
-  tracerpid = 0;
-  process_info.Clear();
+static bool GetProcessArgs(::pid_t pid, ProcessInstanceInfo &process_info) {
+  auto BufferOrError = getProcFile(pid, "cmdline");
+  if (!BufferOrError)
+return false;
+  std::unique_ptr Cmdline = std::move(*BufferOrError);
+
+  llvm::StringRef Arg0, Rest;
+  std::tie(Arg0, Rest) = Cmdline->getBuffer().split('\0');
+  process_info.SetArg0(Arg0);
+  while (!Rest.empty()) {
+llvm::StringRef Arg;
+std::tie(Arg, Rest) = Rest.split('\0');
+process_info.GetArguments().AppendArgument(Arg);
+  }
+  return true;
+}
 
+static bool GetExePathArchAndProcessArgs(::pid_t pid,
+ ProcessInstanceInfo &process_info) {
+  GetProcessArgs(pid, process_info);
   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  std::string ExePath(PATH_MAX, '\0');
 
   // We can't use getProcFile here because proc/[pid]/exe is a symbolic link.
   llvm::SmallString<64> ProcExe;
   (llvm::Twine("/proc/") + llvm::Twine(pid) + "/exe").toVector(ProcExe);
-  std::string ExePath(PATH_MAX, '\0');
 
   ssize_t len = readlink(ProcExe.c_str(), &ExePath[0], PATH_MAX);
-  if (len <= 0) {
+  if (len > 0) {
+ExePath.resize(len);
+  } else {
 LLDB_LOG(log, "failed to read link exe link for {0}: {1}", pid,
  Status(errno, eErrorTypePOSIX));
-return false;
+ExePath.resize(0);
+#if defined(__ANDROID__)
+// On android we fallback to Arg0, which commonly is an apk package name.
+if (!process_info.GetArg0().empty()) {
+  ExePath = process_info.GetArg0();
+}
+#endif
   }
-  ExePath.resize(len);
-
+  if (ExePath.empty())
+return false;
   // If the binary has been deleted, the link name has " (deleted)" appended.
   // Remove if there.
-  llvm::StringRef PathRef = ExePath;
+  llvm::StringRef PathRef(ExePath);
   PathRef.consume_back(" (deleted)");
 
+  process_info.GetExecutableFile().SetFile(PathRef, FileSpec::Style::native);
   process_info.SetArchitecture(GetELFProcessCPUType(PathRef));
+  return true;
+}
 
+static bool GetProcessEnviron(::pid_t pid, ProcessInstanceInfo &process_info) {
   // Get the process environment.
   auto BufferOrError = getProcFile(pid, "environ");
-  if (!BufferOrError)
+  if (BufferOrError) {
+std::unique_ptr Environ = std::move(*BufferOrError);
+llvm::StringRef Rest = Environ->getBuffer();
+while (!Rest.empty()) {
+  llvm::StringRef Var;
+  std::tie(Var, Rest) = Rest.split('\0');
+  process_info.GetEnvironment().insert(Var);
+}
+return true;
+  }
+#if defined(__ANDROID__)
+  // It's okay if we can't get the environment on android
+  return true;
+#else
+  return false;
+#endif
+}
+
+static bool GetProcessAndStatInfo(::pid_t pid,
+  ProcessInstanceInfo &process_info,
+  ProcessState &State, ::pid_t &tracerpid) {
+  tracerpid = 0;
+  process_info.Clear();
+
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+
+  process_info.SetProcessID(pid);
+
+  if (!GetExePathArchAndProcessArgs(pid, process_info))
 return false;
-  std::unique_ptr Environ = std::move(*BufferOrError);
+  printf("%d: passed 1\n", pid);
 
-  // Get the command line used to start the process.
-  BufferOrError = getProcFile(pid, "cmdline");
-  if (!BufferOrError)
+  if (!GetProcessEnviron(pid, process_info))
 return false;
-  std::unique_ptr Cmdline = std::move(*BufferOrError);
+  printf("%d: passed 2\n", pid);
 
   // Get User and Group IDs and get tracer pid.
   if (!GetStatusInfo(pid, process_info, State, tracerpid))
 return false;
-
-  process_info.SetProcessID(pid);
-  process_info.GetExecutableFile().SetFile(PathRef, FileSpec::Style::native);
-
-  llvm::StringRef Rest = Environ->getBuffer();
-  while (!Rest.empty()) {
-llvm::StringRef Var;
-std::tie(Var, Rest) = Rest.split('\0');
-process_info.GetEnvironment().insert(Var);
-  }
-
-  llvm::StringRef Arg0;
-  std::tie(Arg0, Rest) = Cmdline->getBuffer().split('\0');
-  process_info.SetArg0(Arg0);
-  while (!Rest.empty()) {
-llvm::

[Lldb-commits] [PATCH] D68289: [lldb-server/android] Show more processes and package name when necessary

2019-10-01 Thread walter erquinigo via Phabricator via lldb-commits
wallace updated this revision to Diff 222673.
wallace added a comment.

- [process list] make the TRIPLE column wider


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68289

Files:
  lldb/source/Host/linux/Host.cpp
  lldb/source/Utility/ProcessInfo.cpp

Index: lldb/source/Utility/ProcessInfo.cpp
===
--- lldb/source/Utility/ProcessInfo.cpp
+++ lldb/source/Utility/ProcessInfo.cpp
@@ -169,13 +169,15 @@
 
   if (verbose) {
 s.Printf("PIDPARENT USER   GROUP  EFF USER   EFF GROUP  TRIPLE "
- "  %s\n",
+ "  %s\n",
  label);
-s.PutCString("== == == == == == "
- " \n");
+s.PutCString(
+"== == == == == == "
+"== \n");
   } else {
-s.Printf("PIDPARENT USER   TRIPLE   %s\n", label);
-s.PutCString("== == ==  "
+s.Printf("PIDPARENT USER   TRIPLE %s\n",
+ label);
+s.PutCString("== == == == "
  "\n");
   }
 }
@@ -216,12 +218,12 @@
 &ProcessInstanceInfo::GetEffectiveGroupID,
 &UserIDResolver::GetGroupName);
 
-  s.Printf("%-24s ", arch_strm.GetData());
+  s.Printf("%-30s ", arch_strm.GetData());
 } else {
   print(&ProcessInstanceInfo::EffectiveUserIDIsValid,
 &ProcessInstanceInfo::GetEffectiveUserID,
 &UserIDResolver::GetUserName);
-  s.Printf("%-24s ", arch_strm.GetData());
+  s.Printf("%-30s ", arch_strm.GetData());
 }
 
 if (verbose || show_args) {
Index: lldb/source/Host/linux/Host.cpp
===
--- lldb/source/Host/linux/Host.cpp
+++ lldb/source/Host/linux/Host.cpp
@@ -55,7 +55,7 @@
 return false;
 
   llvm::StringRef Rest = BufferOrError.get()->getBuffer();
-  while(!Rest.empty()) {
+  while (!Rest.empty()) {
 llvm::StringRef Line;
 std::tie(Line, Rest) = Rest.split('\n');
 
@@ -144,68 +144,102 @@
   }
 }
 
-static bool GetProcessAndStatInfo(::pid_t pid,
-  ProcessInstanceInfo &process_info,
-  ProcessState &State, ::pid_t &tracerpid) {
-  tracerpid = 0;
-  process_info.Clear();
+static bool GetProcessArgs(::pid_t pid, ProcessInstanceInfo &process_info) {
+  auto BufferOrError = getProcFile(pid, "cmdline");
+  if (!BufferOrError)
+return false;
+  std::unique_ptr Cmdline = std::move(*BufferOrError);
+
+  llvm::StringRef Arg0, Rest;
+  std::tie(Arg0, Rest) = Cmdline->getBuffer().split('\0');
+  process_info.SetArg0(Arg0);
+  while (!Rest.empty()) {
+llvm::StringRef Arg;
+std::tie(Arg, Rest) = Rest.split('\0');
+process_info.GetArguments().AppendArgument(Arg);
+  }
+  return true;
+}
 
+static bool GetExePathArchAndProcessArgs(::pid_t pid,
+ ProcessInstanceInfo &process_info) {
+  GetProcessArgs(pid, process_info);
   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  std::string ExePath(PATH_MAX, '\0');
 
   // We can't use getProcFile here because proc/[pid]/exe is a symbolic link.
   llvm::SmallString<64> ProcExe;
   (llvm::Twine("/proc/") + llvm::Twine(pid) + "/exe").toVector(ProcExe);
-  std::string ExePath(PATH_MAX, '\0');
 
   ssize_t len = readlink(ProcExe.c_str(), &ExePath[0], PATH_MAX);
-  if (len <= 0) {
+  if (len > 0) {
+ExePath.resize(len);
+  } else {
 LLDB_LOG(log, "failed to read link exe link for {0}: {1}", pid,
  Status(errno, eErrorTypePOSIX));
-return false;
+ExePath.resize(0);
+#if defined(__ANDROID__)
+// On android we fallback to Arg0, which commonly is an apk package name.
+if (!process_info.GetArg0().empty()) {
+  ExePath = process_info.GetArg0();
+}
+#endif
   }
-  ExePath.resize(len);
-
+  if (ExePath.empty())
+return false;
   // If the binary has been deleted, the link name has " (deleted)" appended.
   // Remove if there.
-  llvm::StringRef PathRef = ExePath;
+  llvm::StringRef PathRef(ExePath);
   PathRef.consume_back(" (deleted)");
 
+  process_info.GetExecutableFile().SetFile(PathRef, FileSpec::Style::native);
   process_info.SetArchitecture(GetELFProcessCPUType(PathRef));
+  return true;
+}
 
+static bool GetProcessEnviron(::pid_t pid, ProcessInstanceInfo &process_info) {
   // Get the process environment.
   auto BufferOrError = getProcFile(pid, "environ");
-  if (!BufferOrError)
+  if (BufferOrError) {
+std::unique_ptr Environ = std::move(*BufferOrError);
+llvm::StringRef Rest = Env

[Lldb-commits] [PATCH] D68289: [lldb-server/android] Show more processes and package name when necessary

2019-10-01 Thread walter erquinigo via Phabricator via lldb-commits
wallace updated this revision to Diff 222674.
wallace added a comment.

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68289

Files:
  lldb/source/Host/linux/Host.cpp

Index: lldb/source/Host/linux/Host.cpp
===
--- lldb/source/Host/linux/Host.cpp
+++ lldb/source/Host/linux/Host.cpp
@@ -55,7 +55,7 @@
 return false;
 
   llvm::StringRef Rest = BufferOrError.get()->getBuffer();
-  while(!Rest.empty()) {
+  while (!Rest.empty()) {
 llvm::StringRef Line;
 std::tie(Line, Rest) = Rest.split('\n');
 
@@ -144,68 +144,102 @@
   }
 }
 
-static bool GetProcessAndStatInfo(::pid_t pid,
-  ProcessInstanceInfo &process_info,
-  ProcessState &State, ::pid_t &tracerpid) {
-  tracerpid = 0;
-  process_info.Clear();
+static bool GetProcessArgs(::pid_t pid, ProcessInstanceInfo &process_info) {
+  auto BufferOrError = getProcFile(pid, "cmdline");
+  if (!BufferOrError)
+return false;
+  std::unique_ptr Cmdline = std::move(*BufferOrError);
+
+  llvm::StringRef Arg0, Rest;
+  std::tie(Arg0, Rest) = Cmdline->getBuffer().split('\0');
+  process_info.SetArg0(Arg0);
+  while (!Rest.empty()) {
+llvm::StringRef Arg;
+std::tie(Arg, Rest) = Rest.split('\0');
+process_info.GetArguments().AppendArgument(Arg);
+  }
+  return true;
+}
 
+static bool GetExePathArchAndProcessArgs(::pid_t pid,
+ ProcessInstanceInfo &process_info) {
+  GetProcessArgs(pid, process_info);
   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  std::string ExePath(PATH_MAX, '\0');
 
   // We can't use getProcFile here because proc/[pid]/exe is a symbolic link.
   llvm::SmallString<64> ProcExe;
   (llvm::Twine("/proc/") + llvm::Twine(pid) + "/exe").toVector(ProcExe);
-  std::string ExePath(PATH_MAX, '\0');
 
   ssize_t len = readlink(ProcExe.c_str(), &ExePath[0], PATH_MAX);
-  if (len <= 0) {
+  if (len > 0) {
+ExePath.resize(len);
+  } else {
 LLDB_LOG(log, "failed to read link exe link for {0}: {1}", pid,
  Status(errno, eErrorTypePOSIX));
-return false;
+ExePath.resize(0);
+#if defined(__ANDROID__)
+// On android we fallback to Arg0, which commonly is an apk package name.
+if (!process_info.GetArg0().empty()) {
+  ExePath = process_info.GetArg0();
+}
+#endif
   }
-  ExePath.resize(len);
-
+  if (ExePath.empty())
+return false;
   // If the binary has been deleted, the link name has " (deleted)" appended.
   // Remove if there.
-  llvm::StringRef PathRef = ExePath;
+  llvm::StringRef PathRef(ExePath);
   PathRef.consume_back(" (deleted)");
 
+  process_info.GetExecutableFile().SetFile(PathRef, FileSpec::Style::native);
   process_info.SetArchitecture(GetELFProcessCPUType(PathRef));
+  return true;
+}
 
+static bool GetProcessEnviron(::pid_t pid, ProcessInstanceInfo &process_info) {
   // Get the process environment.
   auto BufferOrError = getProcFile(pid, "environ");
-  if (!BufferOrError)
+  if (BufferOrError) {
+std::unique_ptr Environ = std::move(*BufferOrError);
+llvm::StringRef Rest = Environ->getBuffer();
+while (!Rest.empty()) {
+  llvm::StringRef Var;
+  std::tie(Var, Rest) = Rest.split('\0');
+  process_info.GetEnvironment().insert(Var);
+}
+return true;
+  }
+#if defined(__ANDROID__)
+  // It's okay if we can't get the environment on android
+  return true;
+#else
+  return false;
+#endif
+}
+
+static bool GetProcessAndStatInfo(::pid_t pid,
+  ProcessInstanceInfo &process_info,
+  ProcessState &State, ::pid_t &tracerpid) {
+  tracerpid = 0;
+  process_info.Clear();
+
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+
+  process_info.SetProcessID(pid);
+
+  if (!GetExePathArchAndProcessArgs(pid, process_info))
 return false;
-  std::unique_ptr Environ = std::move(*BufferOrError);
+  printf("%d: passed 1\n", pid);
 
-  // Get the command line used to start the process.
-  BufferOrError = getProcFile(pid, "cmdline");
-  if (!BufferOrError)
+  if (!GetProcessEnviron(pid, process_info))
 return false;
-  std::unique_ptr Cmdline = std::move(*BufferOrError);
+  printf("%d: passed 2\n", pid);
 
   // Get User and Group IDs and get tracer pid.
   if (!GetStatusInfo(pid, process_info, State, tracerpid))
 return false;
-
-  process_info.SetProcessID(pid);
-  process_info.GetExecutableFile().SetFile(PathRef, FileSpec::Style::native);
-
-  llvm::StringRef Rest = Environ->getBuffer();
-  while (!Rest.empty()) {
-llvm::StringRef Var;
-std::tie(Var, Rest) = Rest.split('\0');
-process_info.GetEnvironment().insert(Var);
-  }
-
-  llvm::StringRef Arg0;
-  std::tie(Arg0, Rest) = Cmdline->getBuffer().split('\0');
-  process_info.SetArg0(Arg0);
-  while (!Rest.empty()) {
-llvm::StringRef Arg;
-std::tie(Arg

[Lldb-commits] [PATCH] D68291: [process list] make the TRIPLE column wider

2019-10-01 Thread walter erquinigo via Phabricator via lldb-commits
wallace created this revision.
wallace added reviewers: clayborg, labath, xiaobai, aadsm.
Herald added subscribers: lldb-commits, kristof.beyls.
Herald added a project: LLDB.

Now that `process list` works better on the android platform, the arch 
aarch64-unknown-linux-android appears quite often.
The existing printed width of the TRIPLE column is not long enough, which 
doesn't look okay.
E.g.

  1561   1016aarch64-unknown-linux-android ip6tables-restore
  1999   1   aarch64-unknown-linux-android tlc_server
  2332   982  com.android.systemui
  2378   983  webview_zygote

Now, after adding 6 spaces, it looks better

  PIDPARENT USER   TRIPLE NAME
  == == == == 

  ...
  1561   1016  aarch64-unknown-linux-android  ip6tables-restore
  1999   1 aarch64-unknown-linux-android  tlc_server
  2332   982  com.android.systemui
  2378   983  webview_zygote
  2448   982  
com.sec.location.nsflp2


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68291

Files:
  lldb/source/Utility/ProcessInfo.cpp


Index: lldb/source/Utility/ProcessInfo.cpp
===
--- lldb/source/Utility/ProcessInfo.cpp
+++ lldb/source/Utility/ProcessInfo.cpp
@@ -169,13 +169,15 @@
 
   if (verbose) {
 s.Printf("PIDPARENT USER   GROUP  EFF USER   EFF GROUP  TRIPLE 
"
- "  %s\n",
+ "  %s\n",
  label);
-s.PutCString("== == == == == == "
- " \n");
+s.PutCString(
+"== == == == == == "
+"== \n");
   } else {
-s.Printf("PIDPARENT USER   TRIPLE   %s\n", label);
-s.PutCString("== == ==  "
+s.Printf("PIDPARENT USER   TRIPLE %s\n",
+ label);
+s.PutCString("== == == == "
  "\n");
   }
 }
@@ -216,12 +218,12 @@
 &ProcessInstanceInfo::GetEffectiveGroupID,
 &UserIDResolver::GetGroupName);
 
-  s.Printf("%-24s ", arch_strm.GetData());
+  s.Printf("%-30s ", arch_strm.GetData());
 } else {
   print(&ProcessInstanceInfo::EffectiveUserIDIsValid,
 &ProcessInstanceInfo::GetEffectiveUserID,
 &UserIDResolver::GetUserName);
-  s.Printf("%-24s ", arch_strm.GetData());
+  s.Printf("%-30s ", arch_strm.GetData());
 }
 
 if (verbose || show_args) {


Index: lldb/source/Utility/ProcessInfo.cpp
===
--- lldb/source/Utility/ProcessInfo.cpp
+++ lldb/source/Utility/ProcessInfo.cpp
@@ -169,13 +169,15 @@
 
   if (verbose) {
 s.Printf("PIDPARENT USER   GROUP  EFF USER   EFF GROUP  TRIPLE "
- "  %s\n",
+ "  %s\n",
  label);
-s.PutCString("== == == == == == "
- " \n");
+s.PutCString(
+"== == == == == == "
+"== \n");
   } else {
-s.Printf("PIDPARENT USER   TRIPLE   %s\n", label);
-s.PutCString("== == ==  "
+s.Printf("PIDPARENT USER   TRIPLE %s\n",
+ label);
+s.PutCString("== == == == "
  "\n");
   }
 }
@@ -216,12 +218,12 @@
 &ProcessInstanceInfo::GetEffectiveGroupID,
 &UserIDResolver::GetGroupName);
 
-  s.Printf("%-24s ", arch_strm.GetData());
+  s.Printf("%-30s ", arch_strm.GetData());
 } else {
   print(&ProcessInstanceInfo::EffectiveUserIDIsValid,
 &ProcessInstanceInfo::GetEffectiveUserID,
 &UserIDResolver::GetUserName);
-  s.Printf("%-24s ", arch_strm.GetData());
+  s.Printf("%-30s ", arch_strm.GetData());
 }
 
 if (verbose || show_args) {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D68069: Explicitly set entry point arch when it's thumb

2019-10-01 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 222680.
aadsm added a comment.

Update tests and fix logic to correctly add the symtab entry.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68069

Files:
  lldb/lit/SymbolFile/dissassemble-entry-point.s
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp

Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -172,3 +172,131 @@
   Uuid.SetFromStringRef("1b8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9", 20);
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
+  /*
+  // nosym-entrypoint-arm-thumb.s
+  .global _Start
+  .thumb_func
+  _start:
+  mov r0, #42
+  mov r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm-thumb.s
+  //   -o nosym-entrypoint-arm-thumb.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm-thumb.o
+  //   -o nosym-entrypoint-arm-thumb -e 0x8075 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8075
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0002
+Content: 2A20012700DF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006020901'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSpec spec{FileSpec(ExpectedFile->name())};
+  spec.GetSymbolFileSpec().SetFile(ExpectedFile->name(),
+   FileSpec::Style::native);
+  auto module_sp = std::make_shared(spec);
+
+  auto entry_point_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
+  ASSERT_TRUE(entry_point_addr.GetOffset() & 1);
+  // Decrease the offsite by 1 to make it into a breakable address since this
+  // is Thumb.
+  entry_point_addr.SetOffset(entry_point_addr.GetOffset() - 1);
+  ASSERT_EQ(entry_point_addr.GetAddressClass(),
+AddressClass::eCodeAlternateISA);
+}
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmAddressClass) {
+  /*
+  // nosym-entrypoint-arm.s
+  .global _Start
+  _start:
+  movs r0, #42
+  movs r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm.s
+  //   -o nosym-entrypoint-arm.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm.o
+  //   -o nosym-entrypoint-arm -e 0x8074 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8074
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0004
+Content: 2A00A0E30170A0E300EF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006010801'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::S

[Lldb-commits] [PATCH] D68293: [android/process list] support showing process arguments

2019-10-01 Thread walter erquinigo via Phabricator via lldb-commits
wallace created this revision.
wallace added reviewers: clayborg, aadsm, labath, xiaobai.
Herald added subscribers: lldb-commits, atanasyan, JDevlieghere, kristof.beyls, 
arichardson, sdardis.
Herald added a project: LLDB.
wallace edited the summary of this revision.

The qfProcessInfo and qsProcessInfo packets currently don't set the processes' 
arguments, however the `platform process list -v` command tries to print it.
In this diff I'm adding the arguments as part of the packet, and now the 
command shows the arguments just like on mac.

On Mac:

  5071  wallace1876110778 wallace1876110778 x86_64-apple-macosx 
 /usr/libexec/secd
  5031  wallace1876110778 wallace1876110778 x86_64-apple-macosx 
 /usr/libexec/secinitd
  5011  wallace1876110778 wallace1876110778 x86_64-apple-macosx 
 /usr/libexec/languageassetd --firstLogin
  4971  wallace1876110778 wallace1876110778 x86_64-apple-macosx 
 /usr/libexec/trustd --agent
  4961  wallace1876110778 wallace1876110778 x86_64-apple-macosx 
 /usr/libexec/lsd
  4941  wallace1876110778 wallace1876110778 x86_64-apple-macosx 
 /System/Library/Frameworks/CoreTelephony.framework/Support/CommCenter -L
  4911  wallace1876110778 wallace1876110778 x86_64-apple-macosx 
 /usr/sbin/distnoted agent
  4891  wallace1876110778 wallace1876110778 x86_64-apple-macosx 
 /usr/libexec/UserEventAgent (Aqua)
  4841  wallace1876110778 wallace1876110778 x86_64-apple-macosx 
 /usr/sbin/cfprefsd agent
  4831  wallace1876110778 wallace1876110778 x86_64-apple-macosx 
 /System/Library/Frameworks/LocalAuthentication.framework/Support/coreauthd

On android:

  1561   1016   root   0 0  
aarch64-unknown-linux-android  /system/bin/ip6tables-restore--noflush -w -v
  1805   9821000   1000  1000   
   android:drmService
  1811   98210189  10189 10189  
   com.qualcomm.embms:remote
  1999   1  1000   1000  1000   
aarch64-unknown-linux-android  /system/bin/tlc_serverCCM
  2332   98210038  10038 10038  
   com.android.systemui
  2378   9831053   1053  1053   
   webview_zygote
  2448   9825013   5013  5013   
   com.sec.location.nsflp2
  2465   98210027  10027 10027  
   com.google.android.gms.persistent


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68293

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp

Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -1176,6 +1176,11 @@
   response.PutCString("name:");
   response.PutStringAsRawHex8(proc_info.GetExecutableFile().GetCString());
   response.PutChar(';');
+  response.PutCString("args:");
+  std::string command_string;
+  proc_info.GetArguments().GetCommandString(command_string);
+  response.PutStringAsRawHex8(command_string.c_str());
+  response.PutChar(';');
   const ArchSpec &proc_arch = proc_info.GetArchitecture();
   if (proc_arch.IsValid()) {
 const llvm::Triple &proc_triple = proc_arch.GetTriple();
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -610,9 +610,9 @@
   if (m_supports_jLoadedDynamicLibrariesInfos == eLazyBoolCalculate) {
 StringExtractorGDBRemote response;
 m_supports_jLoadedDynamicLibrariesInfos = eLazyBoolNo;
-if (SendPacketAndWaitForResponse("jGetLoadedDynamicLibrariesInfos:",
- response,
- false) == PacketResult::Success) {
+if (SendPacketAndWaitForResponse(
+"jGetLoadedDynamicLibrariesInfos:", response, false) ==
+PacketResult::Success) {
   if (response.IsOKResponse()) {
 m_supports_jLoadedDynamicLibrariesInfos = eLazyBoolYes;
   }
@@ -1124,8 +1124,8 @@
   Log *log(ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(GDBR_LOG_PROCESS));
 
   if (force || m_qHostInfo_is_valid == eLazyBoolCalculate) {
-// host info computation can require DNS traffic and shelling out to external proce

[Lldb-commits] [PATCH] D68299: [JSON] Use LLVM's library for encoding JSON in GDBRemoteCommunicationServerLLGS

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, mgorbach, vsk.

This patch replaces the LLDB's JSON implementation with the one from
LLVM in GDBRemoteCommunicationServerLLGS.


https://reviews.llvm.org/D68299

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp

Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -32,7 +32,6 @@
 #include "lldb/Utility/Args.h"
 #include "lldb/Utility/DataBuffer.h"
 #include "lldb/Utility/Endian.h"
-#include "lldb/Utility/JSON.h"
 #include "lldb/Utility/LLDBAssert.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/RegisterValue.h"
@@ -40,6 +39,7 @@
 #include "lldb/Utility/StreamString.h"
 #include "lldb/Utility/UriParser.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/Support/JSON.h"
 #include "llvm/Support/ScopedPrinter.h"
 
 #include "ProcessGDBRemote.h"
@@ -402,19 +402,21 @@
   }
 }
 
-static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread) {
+static llvm::Expected
+GetRegistersAsJSON(NativeThreadProtocol &thread) {
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
 
   NativeRegisterContext& reg_ctx = thread.GetRegisterContext();
 
-  JSONObject::SP register_object_sp = std::make_shared();
+  json::Object register_object;
 
 #ifdef LLDB_JTHREADSINFO_FULL_REGISTER_SET
   // Expedite all registers in the first register set (i.e. should be GPRs)
   // that are not contained in other registers.
   const RegisterSet *reg_set_p = reg_ctx_sp->GetRegisterSet(0);
   if (!reg_set_p)
-return nullptr;
+return llvm::make_error("failed to get registers",
+   llvm::inconvertibleErrorCode());
   for (const uint32_t *reg_num_p = reg_set_p->registers;
*reg_num_p != LLDB_INVALID_REGNUM; ++reg_num_p) {
 uint32_t reg_num = *reg_num_p;
@@ -460,12 +462,10 @@
 WriteRegisterValueInHexFixedWidth(stream, reg_ctx, *reg_info_p,
   ®_value, lldb::eByteOrderBig);
 
-register_object_sp->SetObject(
-llvm::to_string(reg_num),
-std::make_shared(stream.GetString()));
+register_object.try_emplace(llvm::to_string(reg_num), stream.GetString());
   }
 
-  return register_object_sp;
+  return register_object;
 }
 
 static const char *GetStopReasonString(StopReason stop_reason) {
@@ -492,11 +492,11 @@
   return nullptr;
 }
 
-static JSONArray::SP GetJSONThreadsInfo(NativeProcessProtocol &process,
-bool abridged) {
+static llvm::Expected
+GetJSONThreadsInfo(NativeProcessProtocol &process, bool abridged) {
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD));
 
-  JSONArray::SP threads_array_sp = std::make_shared();
+  json::Array threads_array;
 
   // Ensure we can get info on the given thread.
   uint32_t thread_idx = 0;
@@ -510,7 +510,8 @@
 struct ThreadStopInfo tid_stop_info;
 std::string description;
 if (!thread->GetStopReason(tid_stop_info, description))
-  return nullptr;
+  return llvm::make_error(
+  "failed to get stop reason", llvm::inconvertibleErrorCode());
 
 const int signum = tid_stop_info.details.signal.signo;
 if (log) {
@@ -522,50 +523,49 @@
 tid_stop_info.reason, tid_stop_info.details.exception.type);
 }
 
-JSONObject::SP thread_obj_sp = std::make_shared();
-threads_array_sp->AppendObject(thread_obj_sp);
+json::Object thread_obj;
 
 if (!abridged) {
-  if (JSONObject::SP registers_sp = GetRegistersAsJSON(*thread))
-thread_obj_sp->SetObject("registers", registers_sp);
+  if (llvm::Expected registers =
+  GetRegistersAsJSON(*thread)) {
+thread_obj.try_emplace("registers", std::move(*registers));
+  } else {
+return registers.takeError();
+  }
 }
 
-thread_obj_sp->SetObject("tid", std::make_shared(tid));
+thread_obj.try_emplace("tid", static_cast(tid));
+
 if (signum != 0)
-  thread_obj_sp->SetObject("signal", std::make_shared(signum));
+  thread_obj.try_emplace("signal", signum);
 
 const std::string thread_name = thread->GetName();
 if (!thread_name.empty())
-  thread_obj_sp->SetObject("name",
-   std::make_shared(thread_name));
+  thread_obj.try_emplace("name", thread_name);
 
-if (const char *stop_reason_str = GetStopReasonString(tid_stop_info.reason))
-  thread_obj_sp->SetObject("reason",
-   std::make_shared(stop_reason_str));
+const char *stop_reason = GetStopReasonString(tid_stop_info.reason);
+if (stop_reason)
+  thread_obj.try_emplace("reason", stop_reason);
 
 if (!description.empty())
-  thread_obj_sp->

[Lldb-commits] [PATCH] D68301: [JSON] Use LLVM's library for encoding JSON in GDBRemoteCommunicationClient

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, vsk, jasonmolenda, clayborg.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This patch replaces the LLDB's JSON implementation with the one from
LLVM in GDBRemoteCommunicationClient.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D68301

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -23,7 +23,6 @@
 #include "lldb/Target/UnixSignals.h"
 #include "lldb/Utility/Args.h"
 #include "lldb/Utility/DataBufferHeap.h"
-#include "lldb/Utility/JSON.h"
 #include "lldb/Utility/LLDBAssert.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/State.h"
@@ -35,14 +34,16 @@
 #include "lldb/Utility/StringExtractorGDBRemote.h"
 
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/JSON.h"
 
 #if defined(HAVE_LIBCOMPRESSION)
 #include 
 #endif
 
 using namespace lldb;
-using namespace lldb_private;
 using namespace lldb_private::process_gdb_remote;
+using namespace lldb_private;
+using namespace llvm;
 using namespace std::chrono;
 
 // GDBRemoteCommunicationClient constructor
@@ -3612,18 +3613,16 @@
   if (!m_supports_jModulesInfo)
 return llvm::None;
 
-  JSONArray::SP module_array_sp = std::make_shared();
+  json::Array module_array;
   for (const FileSpec &module_file_spec : module_file_specs) {
-JSONObject::SP module_sp = std::make_shared();
-module_array_sp->AppendObject(module_sp);
-module_sp->SetObject(
-"file", std::make_shared(module_file_spec.GetPath(false)));
-module_sp->SetObject("triple",
- std::make_shared(triple.getTriple()));
+module_array.push_back(
+json::Object{{"file", module_file_spec.GetPath(false)},
+ {"triple", triple.getTriple()}});
   }
   StreamString unescaped_payload;
   unescaped_payload.PutCString("jModulesInfo:");
-  module_array_sp->Write(unescaped_payload);
+  unescaped_payload.AsRawOstream() << std::move(module_array);
+
   StreamGDBRemote payload;
   payload.PutEscapedBytes(unescaped_payload.GetString().data(),
   unescaped_payload.GetSize());


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -23,7 +23,6 @@
 #include "lldb/Target/UnixSignals.h"
 #include "lldb/Utility/Args.h"
 #include "lldb/Utility/DataBufferHeap.h"
-#include "lldb/Utility/JSON.h"
 #include "lldb/Utility/LLDBAssert.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/State.h"
@@ -35,14 +34,16 @@
 #include "lldb/Utility/StringExtractorGDBRemote.h"
 
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/JSON.h"
 
 #if defined(HAVE_LIBCOMPRESSION)
 #include 
 #endif
 
 using namespace lldb;
-using namespace lldb_private;
 using namespace lldb_private::process_gdb_remote;
+using namespace lldb_private;
+using namespace llvm;
 using namespace std::chrono;
 
 // GDBRemoteCommunicationClient constructor
@@ -3612,18 +3613,16 @@
   if (!m_supports_jModulesInfo)
 return llvm::None;
 
-  JSONArray::SP module_array_sp = std::make_shared();
+  json::Array module_array;
   for (const FileSpec &module_file_spec : module_file_specs) {
-JSONObject::SP module_sp = std::make_shared();
-module_array_sp->AppendObject(module_sp);
-module_sp->SetObject(
-"file", std::make_shared(module_file_spec.GetPath(false)));
-module_sp->SetObject("triple",
- std::make_shared(triple.getTriple()));
+module_array.push_back(
+json::Object{{"file", module_file_spec.GetPath(false)},
+ {"triple", triple.getTriple()}});
   }
   StreamString unescaped_payload;
   unescaped_payload.PutCString("jModulesInfo:");
-  module_array_sp->Write(unescaped_payload);
+  unescaped_payload.AsRawOstream() << std::move(module_array);
+
   StreamGDBRemote payload;
   payload.PutEscapedBytes(unescaped_payload.GetString().data(),
   unescaped_payload.GetSize());
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D68302: [JSON] Use LLVM's library for encoding JSON in GDBRemoteCommunicationServerPlatform

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, vsk.
Herald added a project: LLDB.

This patch replaces the LLDB's JSON implementation with the one from
LLVM in GDBRemoteCommunicationServerPlatform.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D68302

Files:
  
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp


Index: 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
===
--- 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -18,6 +18,7 @@
 #include 
 
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/JSON.h"
 #include "llvm/Support/Threading.h"
 
 #include "lldb/Host/Config.h"
@@ -28,7 +29,6 @@
 #include "lldb/Target/Platform.h"
 #include "lldb/Target/UnixSignals.h"
 #include "lldb/Utility/GDBRemote.h"
-#include "lldb/Utility/JSON.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/StreamString.h"
 #include "lldb/Utility/StructuredData.h"
@@ -37,8 +37,9 @@
 #include "lldb/Utility/StringExtractorGDBRemote.h"
 
 using namespace lldb;
-using namespace lldb_private;
 using namespace lldb_private::process_gdb_remote;
+using namespace lldb_private;
+using namespace llvm;
 
 // GDBRemoteCommunicationServerPlatform constructor
 GDBRemoteCommunicationServerPlatform::GDBRemoteCommunicationServerPlatform(
@@ -218,19 +219,16 @@
   if (m_pending_gdb_server.pid == LLDB_INVALID_PROCESS_ID)
 return SendErrorResponse(4);
 
-  JSONObject::SP server_sp = std::make_shared();
-  server_sp->SetObject("port",
-   
std::make_shared(m_pending_gdb_server.port));
+  json::Object server{{"port", m_pending_gdb_server.port}};
+
   if (!m_pending_gdb_server.socket_name.empty())
-server_sp->SetObject(
-"socket_name",
-
std::make_shared(m_pending_gdb_server.socket_name.c_str()));
+server.try_emplace("socket_name", m_pending_gdb_server.socket_name);
 
-  JSONArray server_list;
-  server_list.AppendObject(server_sp);
+  json::Array server_list;
+  server_list.push_back(std::move(server));
 
   StreamGDBRemote response;
-  server_list.Write(response);
+  response.AsRawOstream() << std::move(server_list);
 
   StreamGDBRemote escaped_response;
   escaped_response.PutEscapedBytes(response.GetString().data(),


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -18,6 +18,7 @@
 #include 
 
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/JSON.h"
 #include "llvm/Support/Threading.h"
 
 #include "lldb/Host/Config.h"
@@ -28,7 +29,6 @@
 #include "lldb/Target/Platform.h"
 #include "lldb/Target/UnixSignals.h"
 #include "lldb/Utility/GDBRemote.h"
-#include "lldb/Utility/JSON.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/StreamString.h"
 #include "lldb/Utility/StructuredData.h"
@@ -37,8 +37,9 @@
 #include "lldb/Utility/StringExtractorGDBRemote.h"
 
 using namespace lldb;
-using namespace lldb_private;
 using namespace lldb_private::process_gdb_remote;
+using namespace lldb_private;
+using namespace llvm;
 
 // GDBRemoteCommunicationServerPlatform constructor
 GDBRemoteCommunicationServerPlatform::GDBRemoteCommunicationServerPlatform(
@@ -218,19 +219,16 @@
   if (m_pending_gdb_server.pid == LLDB_INVALID_PROCESS_ID)
 return SendErrorResponse(4);
 
-  JSONObject::SP server_sp = std::make_shared();
-  server_sp->SetObject("port",
-   std::make_shared(m_pending_gdb_server.port));
+  json::Object server{{"port", m_pending_gdb_server.port}};
+
   if (!m_pending_gdb_server.socket_name.empty())
-server_sp->SetObject(
-"socket_name",
-std::make_shared(m_pending_gdb_server.socket_name.c_str()));
+server.try_emplace("socket_name", m_pending_gdb_server.socket_name);
 
-  JSONArray server_list;
-  server_list.AppendObject(server_sp);
+  json::Array server_list;
+  server_list.push_back(std::move(server));
 
   StreamGDBRemote response;
-  server_list.Write(response);
+  response.AsRawOstream() << std::move(server_list);
 
   StreamGDBRemote escaped_response;
   escaped_response.PutEscapedBytes(response.GetString().data(),
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D68304: [JSON] Use LLVM's library for encoding JSON in GDBRemoteCommunicationServerCommon

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, aprantl, vsk.
Herald added a project: LLDB.

This patch replaces the LLDB's JSON implementation with the one from
LLVM in GDBRemoteCommunicationServerCommon.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D68304

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp


Index: 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
===
--- 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -30,11 +30,12 @@
 #include "lldb/Target/Platform.h"
 #include "lldb/Utility/Endian.h"
 #include "lldb/Utility/GDBRemote.h"
-#include "lldb/Utility/JSON.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/StreamString.h"
 #include "lldb/Utility/StructuredData.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/Support/JSON.h"
 
 #include "ProcessGDBRemoteLog.h"
 #include "lldb/Utility/StringExtractorGDBRemote.h"
@@ -43,11 +44,11 @@
 #include "lldb/Host/android/HostInfoAndroid.h"
 #endif
 
-#include "llvm/ADT/StringSwitch.h"
 
 using namespace lldb;
-using namespace lldb_private;
 using namespace lldb_private::process_gdb_remote;
+using namespace lldb_private;
+using namespace llvm;
 
 #ifdef __ANDROID__
 const static uint32_t g_default_packet_timeout_sec = 20; // seconds
@@ -1130,7 +1131,7 @@
   if (!packet_array)
 return SendErrorResponse(2);
 
-  JSONArray::SP response_array_sp = std::make_shared();
+  json::Array response_array;
   for (size_t i = 0; i < packet_array->GetSize(); ++i) {
 StructuredData::Dictionary *query =
 packet_array->GetItemAtIndex(i)->GetAsDictionary();
@@ -1148,27 +1149,22 @@
 const auto file_offset = matched_module_spec.GetObjectOffset();
 const auto file_size = matched_module_spec.GetObjectSize();
 const auto uuid_str = matched_module_spec.GetUUID().GetAsString("");
-
 if (uuid_str.empty())
   continue;
-
-JSONObject::SP response = std::make_shared();
-response_array_sp->AppendObject(response);
-response->SetObject("uuid", std::make_shared(uuid_str));
-response->SetObject(
-"triple",
-std::make_shared(
-matched_module_spec.GetArchitecture().GetTriple().getTriple()));
-response->SetObject("file_path",
-std::make_shared(
-matched_module_spec.GetFileSpec().GetPath()));
-response->SetObject("file_offset",
-std::make_shared(file_offset));
-response->SetObject("file_size", std::make_shared(file_size));
+const auto triple_str =
+matched_module_spec.GetArchitecture().GetTriple().getTriple();
+const auto file_path = matched_module_spec.GetFileSpec().GetPath();
+
+json::Object response{{"uuid", uuid_str},
+  {"triple", triple_str},
+  {"file_path", file_path},
+  {"file_offset", static_cast(file_offset)},
+  {"file_size", static_cast(file_size)}};
+response_array.push_back(std::move(response));
   }
 
   StreamString response;
-  response_array_sp->Write(response);
+  response.AsRawOstream() << std::move(response_array);
   StreamGDBRemote escaped_response;
   escaped_response.PutEscapedBytes(response.GetString().data(),
response.GetSize());


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -30,11 +30,12 @@
 #include "lldb/Target/Platform.h"
 #include "lldb/Utility/Endian.h"
 #include "lldb/Utility/GDBRemote.h"
-#include "lldb/Utility/JSON.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/StreamString.h"
 #include "lldb/Utility/StructuredData.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/Support/JSON.h"
 
 #include "ProcessGDBRemoteLog.h"
 #include "lldb/Utility/StringExtractorGDBRemote.h"
@@ -43,11 +44,11 @@
 #include "lldb/Host/android/HostInfoAndroid.h"
 #endif
 
-#include "llvm/ADT/StringSwitch.h"
 
 using namespace lldb;
-using namespace lldb_private;
 using namespace lldb_private::process_gdb_remote;
+using namespace lldb_private;
+using namespace llvm;
 
 #ifdef __ANDROID__
 const static uint32_t g_default_packet_timeout_sec = 20; // seconds
@@ -1130,7 +1131,7 @@
   if (!packet_array)
 return SendErrorResponse(2);
 
-  JSONArray::SP response_array_sp = std::make_shared();
+  json::Array response_array;
   for (size_t i = 0; i < packet_array->GetSize(); ++i) {
 StructuredData::Dictionary *query =
 packet_arra

[Lldb-commits] [PATCH] D68258: [Windows] Introduce a switch for the `lldb-server` mode on Windows

2019-10-01 Thread Adrian McCarthy via Phabricator via lldb-commits
amccarth added a comment.

Why an environment variable rather than a command line option?


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D68258



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


[Lldb-commits] [PATCH] D68305: [JSON] Remove Utility/JSON.{h|cpp}

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, vsk, aprantl, clayborg.
Herald added a subscriber: mgorny.
Herald added a project: LLDB.
JDevlieghere retitled this revision from "[JSON] RemoveUtility/JSON.{h|cpp}" to 
"[JSON] Remove Utility/JSON.{h|cpp}".

This patch is the final step in my quest to get rid of the JSON parser in LLDB. 
Vedant's coverage report [1] shows that it was mostly untested. Furthermore, 
the LLVM implementation has a much nicer API and using it means one less thing 
to maintain for LLDB.

[1] http://lab.llvm.org:8080/coverage/coverage-reports/index.html


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D68305

Files:
  lldb/include/lldb/Utility/JSON.h
  lldb/source/Utility/CMakeLists.txt
  lldb/source/Utility/JSON.cpp
  lldb/unittests/Utility/CMakeLists.txt
  lldb/unittests/Utility/JSONTest.cpp

Index: lldb/unittests/Utility/JSONTest.cpp
===
--- lldb/unittests/Utility/JSONTest.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "gtest/gtest.h"
-
-#include "lldb/Utility/JSON.h"
-#include "lldb/Utility/StreamString.h"
-
-using namespace lldb_private;
-
-TEST(JSONTest, Dictionary) {
-  JSONObject o;
-  o.SetObject("key", std::make_shared("value"));
-
-  StreamString stream;
-  o.Write(stream);
-
-  ASSERT_EQ(stream.GetString(), R"({"key":"value"})");
-}
-
-TEST(JSONTest, Newlines) {
-  JSONObject o;
-  o.SetObject("key", std::make_shared("hello\nworld"));
-
-  StreamString stream;
-  o.Write(stream);
-
-  ASSERT_EQ(stream.GetString(), R"({"key":"hello\nworld"})");
-}
Index: lldb/unittests/Utility/CMakeLists.txt
===
--- lldb/unittests/Utility/CMakeLists.txt
+++ lldb/unittests/Utility/CMakeLists.txt
@@ -11,7 +11,6 @@
   EventTest.cpp
   FileSpecTest.cpp
   FlagsTest.cpp
-  JSONTest.cpp
   ListenerTest.cpp
   LogTest.cpp
   NameMatchesTest.cpp
Index: lldb/source/Utility/JSON.cpp
===
--- lldb/source/Utility/JSON.cpp
+++ /dev/null
@@ -1,550 +0,0 @@
-//===- JSON.cpp -*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "lldb/Utility/JSON.h"
-
-#include "lldb/Utility/Stream.h"
-#include "lldb/Utility/StreamString.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/ErrorHandling.h"
-
-#include 
-#include 
-#include 
-#include 
-
-using namespace lldb_private;
-
-std::string JSONString::json_string_quote_metachars(const std::string &s) {
-  if (s.find_first_of("\\\n\"") == std::string::npos)
-return s;
-
-  std::string output;
-  const size_t s_size = s.size();
-  const char *s_chars = s.c_str();
-  for (size_t i = 0; i < s_size; i++) {
-unsigned char ch = *(s_chars + i);
-if (ch == '"' || ch == '\\' || ch == '\n') {
-  output.push_back('\\');
-  if (ch == '\n') ch = 'n';
-}
-output.push_back(ch);
-  }
-  return output;
-}
-
-JSONString::JSONString() : JSONValue(JSONValue::Kind::String), m_data() {}
-
-JSONString::JSONString(const char *s)
-: JSONValue(JSONValue::Kind::String), m_data(s ? s : "") {}
-
-JSONString::JSONString(const std::string &s)
-: JSONValue(JSONValue::Kind::String), m_data(s) {}
-
-void JSONString::Write(Stream &s) {
-  s.Printf("\"%s\"", json_string_quote_metachars(m_data).c_str());
-}
-
-uint64_t JSONNumber::GetAsUnsigned() const {
-  switch (m_data_type) {
-  case DataType::Unsigned:
-return m_data.m_unsigned;
-  case DataType::Signed:
-return static_cast(m_data.m_signed);
-  case DataType::Double:
-return static_cast(m_data.m_double);
-  }
-  llvm_unreachable("Unhandled data type");
-}
-
-int64_t JSONNumber::GetAsSigned() const {
-  switch (m_data_type) {
-  case DataType::Unsigned:
-return static_cast(m_data.m_unsigned);
-  case DataType::Signed:
-return m_data.m_signed;
-  case DataType::Double:
-return static_cast(m_data.m_double);
-  }
-  llvm_unreachable("Unhandled data type");
-}
-
-double JSONNumber::GetAsDouble() const {
-  switch (m_data_type) {
-  case DataType::Unsigned:
-return static_cast(m_data.m_unsigned);
-  case DataType::Signed:
-return static_cast(m_data.m_signed);
-  case DataType::Double:
-return m_data.m_double;
-  }
-  llvm_unreachable("Unhandled data type");
-}
-
-void JSONNumber::Write(Stream &s) {
-  switch (m_data_type) {
-  case DataType::Unsigned:
-s.Printf("%" PRIu64, m_data.m_unsigned);
-break;
-  case DataType::Signed:
-s.Printf("%" PRId64, m_data.m_signed);
-break;
-  case DataType::Double:
-s.Printf("%g", m_data.m_double);
-break;
-  }
-}
-
-JSONTrue::JSONTrue() : JSONValue(JSONValue::Kind::True) {}
-
-void JSONTru

[Lldb-commits] [lldb] r373399 - [lldb] Fix unused variable warning

2019-10-01 Thread Jordan Rupprecht via lldb-commits
Author: rupprecht
Date: Tue Oct  1 15:04:14 2019
New Revision: 373399

URL: http://llvm.org/viewvc/llvm-project?rev=373399&view=rev
Log:
[lldb] Fix unused variable warning

Modified:
lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp

Modified: lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp?rev=373399&r1=373398&r2=373399&view=diff
==
--- lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp Tue Oct  1 
15:04:14 2019
@@ -1639,7 +1639,6 @@ void SymbolFilePDB::GetTypes(lldb_privat
  lldb_private::TypeList &type_list) {
   std::lock_guard guard(GetModuleMutex());
   TypeCollection type_collection;
-  uint32_t old_size = type_list.GetSize();
   CompileUnit *cu =
   sc_scope ? sc_scope->CalculateSymbolContextCompileUnit() : nullptr;
   if (cu) {


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


[Lldb-commits] [PATCH] D68179: [lldb] Fix JSON parser to allow empty arrays

2019-10-01 Thread Alex Cameron via Phabricator via lldb-commits
tetsuo-cpp added a comment.

In D68179#1690073 , @JDevlieghere 
wrote:

> Hey, I just want to give you a heads up that I'm in the process to replace 
> LLDB's JSON implementation with the one from LLVM. The parts in 
> StructuredData are already gone (r373359, r373360) and I'm currently working 
> on the other uses in LLDB, except for debugserver which I'm not planning to 
> touch for now.


Thanks for letting me know.
Did you want the `debugserver` portion of this change? Or should I just close 
this.


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

https://reviews.llvm.org/D68179



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


Re: [Lldb-commits] [PATCH] D68179: [lldb] Fix JSON parser to allow empty arrays

2019-10-01 Thread Jim Ingham via lldb-commits
debugserver doesn't use llvm classes, it's its own stand-alone thing.  So 
debugserver wasn't included in Jonas' changes.

Jim


> On Oct 1, 2019, at 3:11 PM, Alex Cameron via Phabricator 
>  wrote:
> 
> tetsuo-cpp added a comment.
> 
> In D68179#1690073 , @JDevlieghere 
> wrote:
> 
>> Hey, I just want to give you a heads up that I'm in the process to replace 
>> LLDB's JSON implementation with the one from LLVM. The parts in 
>> StructuredData are already gone (r373359, r373360) and I'm currently working 
>> on the other uses in LLDB, except for debugserver which I'm not planning to 
>> touch for now.
> 
> 
> Thanks for letting me know.
> Did you want the `debugserver` portion of this change? Or should I just close 
> this.
> 
> 
> CHANGES SINCE LAST ACTION
>  https://reviews.llvm.org/D68179/new/
> 
> https://reviews.llvm.org/D68179
> 
> 
> 

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


[Lldb-commits] [lldb] r373409 - Make yet another attempt in restoring SymbolFilePDBTests

2019-10-01 Thread Adrian Prantl via lldb-commits
Author: adrian
Date: Tue Oct  1 17:06:27 2019
New Revision: 373409

URL: http://llvm.org/viewvc/llvm-project?rev=373409&view=rev
Log:
Make yet another attempt in restoring SymbolFilePDBTests

The original test was passing false to the append argument of
FindTypes (the only use of this feature!). This patch now replicates
that by passing a fresh TypeMap into the function where applicable.

Modified:
lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp

Modified: lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp?rev=373409&r1=373408&r2=373409&view=diff
==
--- lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp (original)
+++ lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp Tue Oct  1 
17:06:27 2019
@@ -401,12 +401,14 @@ TEST_F(SymbolFilePDBTests, TestNestedCla
   // and one is global. We process correctly this case and create the same
   // compiler type for both, but `FindTypes` may return more than one type
   // (with the same compiler type) because the symbols have different IDs.
+
+  TypeMap more_results;
   auto ClassCompilerDeclCtx = CompilerDeclContext(clang_ast_ctx, ClassDeclCtx);
   symfile->FindTypes(ConstString("NestedClass"), &ClassCompilerDeclCtx, 0,
- searched_files, results);
-  EXPECT_LE(1u, results.GetSize());
+ searched_files, more_results);
+  EXPECT_LE(1u, more_results.GetSize());
 
-  lldb::TypeSP udt_type = results.GetTypeAtIndex(0);
+  lldb::TypeSP udt_type = more_results.GetTypeAtIndex(0);
   EXPECT_EQ(ConstString("NestedClass"), udt_type->GetName());
 
   CompilerType compiler_type = udt_type->GetForwardCompilerType();
@@ -568,19 +570,17 @@ TEST_F(SymbolFilePDBTests, TestMaxMatche
   TypeMap results;
   const ConstString name("ClassTypedef");
   symfile->FindTypes(name, nullptr, 0, searched_files, results);
-  // Try to limit ourselves from 1 to 10 results, otherwise we could be doing
-  // this thousands of times.
-  // The idea is just to make sure that for a variety of values, the number of
-  // limited results always
-  // comes out to the number we are expecting.
-  uint32_t iterations = std::min(results.GetSize(), 10u);
+  // Try to limit ourselves from 1 to 10 results, otherwise we could
+  // be doing this thousands of times.  The idea is just to make sure
+  // that for a variety of values, the number of limited results
+  // always comes out to the number we are expecting.
   uint32_t num_results = results.GetSize();
+  uint32_t iterations = std::min(num_results, 10u);
   for (uint32_t i = 1; i <= iterations; ++i) {
-symfile->FindTypes(name, nullptr, i, searched_files, results);
-uint32_t num_limited_results = results.GetSize() - num_results;
+TypeMap more_results;
+symfile->FindTypes(name, nullptr, i, searched_files, more_results);
+uint32_t num_limited_results = more_results.GetSize();
 EXPECT_EQ(i, num_limited_results);
-EXPECT_EQ(num_limited_results, results.GetSize());
-num_results = num_limited_results;
   }
 }
 


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


[Lldb-commits] [PATCH] D68312: [gdb-remote] process properly effective uid

2019-10-01 Thread walter erquinigo via Phabricator via lldb-commits
wallace created this revision.
wallace added reviewers: labath, clayborg, aadsm, xiaobai.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Someone wrote SetEffectiveSetEffectiveGroupID instead of SetEffectiveUserID.

After this fix, the android process list can show user names, e.g.

  PIDPARENT USER   GROUP  EFF USER   EFF GROUP  TRIPLE  
 ARGUMENTS
  == == == == == == 
== 
  5291  root   0  root   0  
   /sbin/ueventd


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68312

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -1906,7 +1906,7 @@
   } else if (name.equals("euid")) {
 uint32_t uid = UINT32_MAX;
 value.getAsInteger(0, uid);
-process_info.SetEffectiveGroupID(uid);
+process_info.SetEffectiveUserID(uid);
   } else if (name.equals("gid")) {
 uint32_t gid = UINT32_MAX;
 value.getAsInteger(0, gid);


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -1906,7 +1906,7 @@
   } else if (name.equals("euid")) {
 uint32_t uid = UINT32_MAX;
 value.getAsInteger(0, uid);
-process_info.SetEffectiveGroupID(uid);
+process_info.SetEffectiveUserID(uid);
   } else if (name.equals("gid")) {
 uint32_t gid = UINT32_MAX;
 value.getAsInteger(0, gid);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D68289: [lldb-server/android] Show more processes and package name when necessary

2019-10-01 Thread walter erquinigo via Phabricator via lldb-commits
wallace updated this revision to Diff 222739.
wallace added a comment.

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68289

Files:
  lldb/source/Host/linux/Host.cpp

Index: lldb/source/Host/linux/Host.cpp
===
--- lldb/source/Host/linux/Host.cpp
+++ lldb/source/Host/linux/Host.cpp
@@ -55,7 +55,7 @@
 return false;
 
   llvm::StringRef Rest = BufferOrError.get()->getBuffer();
-  while(!Rest.empty()) {
+  while (!Rest.empty()) {
 llvm::StringRef Line;
 std::tie(Line, Rest) = Rest.split('\n');
 
@@ -144,69 +144,100 @@
   }
 }
 
-static bool GetProcessAndStatInfo(::pid_t pid,
-  ProcessInstanceInfo &process_info,
-  ProcessState &State, ::pid_t &tracerpid) {
-  tracerpid = 0;
-  process_info.Clear();
+static bool GetProcessArgs(::pid_t pid, ProcessInstanceInfo &process_info) {
+  auto BufferOrError = getProcFile(pid, "cmdline");
+  if (!BufferOrError)
+return false;
+  std::unique_ptr Cmdline = std::move(*BufferOrError);
+
+  llvm::StringRef Arg0, Rest;
+  std::tie(Arg0, Rest) = Cmdline->getBuffer().split('\0');
+  process_info.SetArg0(Arg0);
+  while (!Rest.empty()) {
+llvm::StringRef Arg;
+std::tie(Arg, Rest) = Rest.split('\0');
+process_info.GetArguments().AppendArgument(Arg);
+  }
+  return true;
+}
 
+static bool GetExePathArchAndProcessArgs(::pid_t pid,
+ ProcessInstanceInfo &process_info) {
+  GetProcessArgs(pid, process_info);
   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  std::string ExePath(PATH_MAX, '\0');
 
   // We can't use getProcFile here because proc/[pid]/exe is a symbolic link.
   llvm::SmallString<64> ProcExe;
   (llvm::Twine("/proc/") + llvm::Twine(pid) + "/exe").toVector(ProcExe);
-  std::string ExePath(PATH_MAX, '\0');
 
   ssize_t len = readlink(ProcExe.c_str(), &ExePath[0], PATH_MAX);
-  if (len <= 0) {
+  if (len > 0) {
+ExePath.resize(len);
+  } else {
 LLDB_LOG(log, "failed to read link exe link for {0}: {1}", pid,
  Status(errno, eErrorTypePOSIX));
-return false;
+ExePath.resize(0);
+#if defined(__ANDROID__)
+// On android we fallback to Arg0, which commonly is an apk package name.
+if (!process_info.GetArg0().empty()) {
+  ExePath = process_info.GetArg0();
+}
+#endif
   }
-  ExePath.resize(len);
-
+  if (ExePath.empty())
+return false;
   // If the binary has been deleted, the link name has " (deleted)" appended.
   // Remove if there.
-  llvm::StringRef PathRef = ExePath;
+  llvm::StringRef PathRef(ExePath);
   PathRef.consume_back(" (deleted)");
 
+  process_info.GetExecutableFile().SetFile(PathRef, FileSpec::Style::native);
   process_info.SetArchitecture(GetELFProcessCPUType(PathRef));
+  return true;
+}
 
+static bool GetProcessEnviron(::pid_t pid, ProcessInstanceInfo &process_info) {
   // Get the process environment.
   auto BufferOrError = getProcFile(pid, "environ");
-  if (!BufferOrError)
+  if (BufferOrError) {
+std::unique_ptr Environ = std::move(*BufferOrError);
+llvm::StringRef Rest = Environ->getBuffer();
+while (!Rest.empty()) {
+  llvm::StringRef Var;
+  std::tie(Var, Rest) = Rest.split('\0');
+  process_info.GetEnvironment().insert(Var);
+}
+return true;
+  }
+#if defined(__ANDROID__)
+  // It's okay if we can't get the environment on android
+  return true;
+#else
+  return false;
+#endif
+}
+
+static bool GetProcessAndStatInfo(::pid_t pid,
+  ProcessInstanceInfo &process_info,
+  ProcessState &State, ::pid_t &tracerpid) {
+  tracerpid = 0;
+  process_info.Clear();
+
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+
+  process_info.SetProcessID(pid);
+
+  if (!GetExePathArchAndProcessArgs(pid, process_info))
 return false;
-  std::unique_ptr Environ = std::move(*BufferOrError);
 
-  // Get the command line used to start the process.
-  BufferOrError = getProcFile(pid, "cmdline");
-  if (!BufferOrError)
+  if (!GetProcessEnviron(pid, process_info))
 return false;
-  std::unique_ptr Cmdline = std::move(*BufferOrError);
 
   // Get User and Group IDs and get tracer pid.
   if (!GetStatusInfo(pid, process_info, State, tracerpid))
 return false;
 
-  process_info.SetProcessID(pid);
-  process_info.GetExecutableFile().SetFile(PathRef, FileSpec::Style::native);
-
-  llvm::StringRef Rest = Environ->getBuffer();
-  while (!Rest.empty()) {
-llvm::StringRef Var;
-std::tie(Var, Rest) = Rest.split('\0');
-process_info.GetEnvironment().insert(Var);
-  }
-
-  llvm::StringRef Arg0;
-  std::tie(Arg0, Rest) = Cmdline->getBuffer().split('\0');
-  process_info.SetArg0(Arg0);
-  while (!Rest.empty()) {
-llvm::StringRef Arg;
-std::tie(Arg, Rest) = Rest.split('\0');
-process_info.GetArguments().AppendA

[Lldb-commits] [PATCH] D68314: [process info] Remove assert in DoGetGroupName

2019-10-01 Thread walter erquinigo via Phabricator via lldb-commits
wallace created this revision.
wallace added reviewers: clayborg, aadsm, xiaobai, labath.
Herald added subscribers: lldb-commits, kristof.beyls, srhines.
Herald added a project: LLDB.

Disabling this assert prevents lldb-server from crashing, which prevents it 
from finding the user and group names of a given process list.

Before this change, the process list didn't contain names:

  PIDPARENT USER   GROUP  EFF USER   EFF GROUP  TRIPLE  
 ARGUMENTS
  == == == == == == 
== 
  27585  98210098  10098  10098  10098  
   com.LogiaGroup.LogiaDeck
  27623  98210098  10098  10098  10098  
   com.digitalturbine.ignite.suspend.DataUsageRecorderService
  28024  98210199  10199  10199  10199  
   com.google.vr.vrcore
  28061  98310353  10353  10353  10353  
   com.instagram.android:videoplayer
  28121  98210045  10045  10045  10045  
   com.sec.spp.push
  28325  98210247  10247  10247  10247  
   com.facebook.orca
  28714  98210367  10367  10367  10367  
   com.samsung.android.dialer
  29867  3208   2000   2000   2000   2000   
aarch64-unknown-linux-android  /system/bin/sh-c /data/local/tmp/lldb-server 
platform --listen *:5557 --server --log-file /data/local/tmp/logs 
--log-channels gdb-remote all --log-channels lldb all

After this change, the list looks much better

  PIDPARENT USER   GROUP  EFF USER   EFF GROUP  TRIPLE  
 ARGUMENTS
  == == == == == == 
== 
  24459  1  wifi   1010   wifi   1010   
aarch64-unknown-linux-android  
/vendor/bin/hw/wpa_supplicant-O/data/vendor/wifi/wpa/sockets 
-puse_p2p_group_interface=1 -g@android:wpa_wlan0
  25098  982u0_a42 10042  u0_a42 10042  
   com.samsung.android.messaging
  25442  982u0_a65 10065  u0_a65 10065  
   com.samsung.android.mobileservice
  25974  982u0_a9  10009  u0_a9  10009  
   com.samsung.android.contacts
  26377  982radio  1001   radio  1001   
   com.samsung.android.incallui
  26390  983u0_a26 10026  u0_a26 10026  
   com.samsung.android.game.gametools
  26876  983u0_a30610306  u0_a30610306  
   com.tencent.mm:push


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68314

Files:
  lldb/source/Host/posix/HostInfoPosix.cpp


Index: lldb/source/Host/posix/HostInfoPosix.cpp
===
--- lldb/source/Host/posix/HostInfoPosix.cpp
+++ lldb/source/Host/posix/HostInfoPosix.cpp
@@ -7,8 +7,8 @@
 
//===--===//
 
 #include "lldb/Host/posix/HostInfoPosix.h"
-#include "lldb/Utility/UserIDResolver.h"
 #include "lldb/Utility/Log.h"
+#include "lldb/Utility/UserIDResolver.h"
 
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Twine.h"
@@ -93,8 +93,6 @@
 if (group_info_ptr)
   return std::string(group_info_ptr->gr_name);
   }
-#else
-  assert(false && "getgrgid_r() not supported on Android");
 #endif
   return llvm::None;
 }


Index: lldb/source/Host/posix/HostInfoPosix.cpp
===
--- lldb/source/Host/posix/HostInfoPosix.cpp
+++ lldb/source/Host/posix/HostInfoPosix.cpp
@@ -7,8 +7,8 @@
 //===--===//
 
 #include "lldb/Host/posix/HostInfoPosix.h"
-#include "lldb/Utility/UserIDResolver.h"
 #include "lldb/Utility/Log.h"
+#include "lldb/Utility/UserIDResolver.h"
 
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Twine.h"
@@ -93,8 +93,6 @@
 if (group_info_ptr)
   return std::string(group_info_ptr->gr_name);
   }
-#else
-  assert(false && "getgrgid_r() not supported on Android");
 #endif
   return llvm::None;
 }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D68316: [Host] Return the user's shell from GetDefaultShell

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, jingham, friss.

LLDB handles shell expansion by running lldb-argdumper under a shell. 
Currently, this is always `/bin/sh` on POSIX. This potentially leads to 
different behavior between lldb and the user's current shell. Here's an example 
of different expansions between shells:

  $ /bin/bash -c 'echo -config={Options:[{key:foo_key,value:foo_value}]}'
  -config={Options:[key:foo_key]} -config={Options:[value:foo_value]}
  $ /bin/zsh -c 'echo -config={Options:[{key:foo_key,value:foo_value}]}'
  zsh:1: no matches found: -config={Options:[key:foo_key]}
  $ /bin/sh -c 'echo -config={Options:[{key:foo_key,value:foo_value}]}'
  -config={Options:[key:foo_key]} -config={Options:[value:foo_value]}
  $ /usr/local/bin/fish -c 'echo 
-config={Options:[{key:foo_key,value:foo_value}]}'
  -config=Options:[key:foo_key] -config=Options:[value:foo_value]

To reduce surprises, this patch returns the user's current shell. It first 
looks at the `SHELL` environment variable. If that isn't set, it'll ask for the 
user's default shell. Only if that fails, we'll fallback to `/bin/sh`, which 
should always be available.


https://reviews.llvm.org/D68316

Files:
  lldb/lit/Host/Inputs/simple.c
  lldb/lit/Host/TestCustomShell.test
  lldb/source/Host/posix/HostInfoPosix.cpp


Index: lldb/source/Host/posix/HostInfoPosix.cpp
===
--- lldb/source/Host/posix/HostInfoPosix.cpp
+++ lldb/source/Host/posix/HostInfoPosix.cpp
@@ -113,7 +113,13 @@
 
 uint32_t HostInfoPosix::GetEffectiveGroupID() { return getegid(); }
 
-FileSpec HostInfoPosix::GetDefaultShell() { return FileSpec("/bin/sh"); }
+FileSpec HostInfoPosix::GetDefaultShell() {
+  if (const char *v = ::getenv("SHELL"))
+return FileSpec(v);
+  if (const char *v = ::getpwuid(::geteuid())->pw_shell)
+return FileSpec(v);
+  return FileSpec("/bin/sh");
+}
 
 bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) {
   return ComputePathRelativeToLibrary(file_spec, "/bin");
Index: lldb/lit/Host/TestCustomShell.test
===
--- /dev/null
+++ lldb/lit/Host/TestCustomShell.test
@@ -0,0 +1,5 @@
+# UNSUPPORTED: system-windows
+
+# RUN: %clang %S/Inputs/simple.c -g -o %t.out
+# RUN: SHELL=bogus %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s
+# CHECK: error: shell expansion failed
Index: lldb/lit/Host/Inputs/simple.c
===
--- /dev/null
+++ lldb/lit/Host/Inputs/simple.c
@@ -0,0 +1 @@
+int main(int argc, char const *argv[]) { return 0; }


Index: lldb/source/Host/posix/HostInfoPosix.cpp
===
--- lldb/source/Host/posix/HostInfoPosix.cpp
+++ lldb/source/Host/posix/HostInfoPosix.cpp
@@ -113,7 +113,13 @@
 
 uint32_t HostInfoPosix::GetEffectiveGroupID() { return getegid(); }
 
-FileSpec HostInfoPosix::GetDefaultShell() { return FileSpec("/bin/sh"); }
+FileSpec HostInfoPosix::GetDefaultShell() {
+  if (const char *v = ::getenv("SHELL"))
+return FileSpec(v);
+  if (const char *v = ::getpwuid(::geteuid())->pw_shell)
+return FileSpec(v);
+  return FileSpec("/bin/sh");
+}
 
 bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) {
   return ComputePathRelativeToLibrary(file_spec, "/bin");
Index: lldb/lit/Host/TestCustomShell.test
===
--- /dev/null
+++ lldb/lit/Host/TestCustomShell.test
@@ -0,0 +1,5 @@
+# UNSUPPORTED: system-windows
+
+# RUN: %clang %S/Inputs/simple.c -g -o %t.out
+# RUN: SHELL=bogus %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s
+# CHECK: error: shell expansion failed
Index: lldb/lit/Host/Inputs/simple.c
===
--- /dev/null
+++ lldb/lit/Host/Inputs/simple.c
@@ -0,0 +1 @@
+int main(int argc, char const *argv[]) { return 0; }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D68316: [Host] Return the user's shell from GetDefaultShell

2019-10-01 Thread Frederic Riss via Phabricator via lldb-commits
friss added inline comments.



Comment at: lldb/lit/Host/TestCustomShell.test:5
+# RUN: SHELL=bogus %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s
+# CHECK: error: shell expansion failed

Is there a reliable way to check that the expansion we get in lldb matches the 
one in the shell? For example, could we have the program dump its arguments 
once without lldb and match them against the lldb output?

I guess the zsh example that errors out in your description makes this hard?  



Comment at: lldb/source/Host/posix/HostInfoPosix.cpp:119
+return FileSpec(v);
+  if (const char *v = ::getpwuid(::geteuid())->pw_shell)
+return FileSpec(v);

the dereference seems a little careless. getpwuid can fail and return NULL.


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

https://reviews.llvm.org/D68316



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


[Lldb-commits] [PATCH] D68317: factor out an abstract base class for File

2019-10-01 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna created this revision.
lawrence_danna added reviewers: JDevlieghere, jasonmolenda, labath.
Herald added a project: LLDB.
lawrence_danna added a parent revision: D68181: SBDebugger::SetInputFile, 
SetOutputFile, etc..
lawrence_danna added a child revision: D68188: allow arbitrary python streams 
to be converted to SBFile.

This patch factors out File as an abstract base 
class and moves most of its actual functionality into
a subclass called NativeFile.   In the next patch, 
I'm going to be adding subclasses of File that 
don't necessarily have any connection to actual OS files, 
so they will not inherit from NativeFile.

This patch was split out as a prerequisite for
https://reviews.llvm.org/D68188


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68317

Files:
  lldb/include/lldb/Host/File.h
  lldb/scripts/Python/python-typemaps.swig
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBFile.cpp
  lldb/source/Core/Debugger.cpp
  lldb/source/Core/StreamFile.cpp
  lldb/source/Host/common/File.cpp
  lldb/source/Host/common/FileSystem.cpp
  lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  
lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm
  lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Target/Process.cpp
  lldb/unittests/Host/FileTest.cpp

Index: lldb/unittests/Host/FileTest.cpp
===
--- lldb/unittests/Host/FileTest.cpp
+++ lldb/unittests/Host/FileTest.cpp
@@ -31,7 +31,7 @@
   FILE *stream = fdopen(fd, "r");
   ASSERT_TRUE(stream);
 
-  File file(stream, true);
+  NativeFile file(stream, true);
   EXPECT_EQ(file.GetWaitableHandle(), fd);
 }
 
@@ -46,7 +46,7 @@
   llvm::FileRemover remover(name);
   ASSERT_GE(fd, 0);
 
-  File file(fd, File::eOpenOptionWrite, true);
+  NativeFile file(fd, File::eOpenOptionWrite, true);
   ASSERT_TRUE(file.IsValid());
 
   FILE *stream = file.GetStream();
Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -4422,9 +4422,9 @@
 
 protected:
   Process *m_process;
-  File m_read_file;  // Read from this file (usually actual STDIN for LLDB
-  File m_write_file; // Write to this file (usually the master pty for getting
- // io to debuggee)
+  NativeFile m_read_file;  // Read from this file (usually actual STDIN for LLDB
+  NativeFile m_write_file; // Write to this file (usually the master pty for
+   // getting io to debuggee)
   Pipe m_pipe;
   std::atomic m_is_running{false};
 };
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -719,9 +719,9 @@
 
   PythonDictionary &sys_module_dict = GetSysModuleDictionary();
   if (sys_module_dict.IsValid()) {
-File in_file(in, false);
-File out_file(out, false);
-File err_file(err, false);
+NativeFile in_file(in, false);
+NativeFile out_file(out, false);
+NativeFile err_file(err, false);
 
 lldb::FileSP in_sp;
 lldb::StreamFileSP out_sp;
Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -1024,8 +1024,8 @@
   // File object knows about that.
   PythonString py_mode = GetAttributeValue("mode").AsType();
   auto options = File::GetOptionsFromMode(py_mode.GetString());
-  auto file = std::make_unique(PyObject_AsFileDescriptor(m_py_obj),
- options, false);
+  auto file = std::unique_ptr(
+  new NativeFile(PyObject_AsFileDescriptor(m_py_obj), options, false));
   if (!file->IsValid())
 return nullptr;
   return file;
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -546,7 +546,7 @@
   int err = -1;
   int save_errno = 0;
   if (fd >= 0) {
-File file(fd, 0, true);
+NativeFile file(fd, 0, true);
 Status error = file.Close();
 err = 0;
 save_errno = error.GetError();
@@ -577,7 +577,7 @@
 

[Lldb-commits] [PATCH] D68188: allow arbitrary python streams to be converted to SBFile

2019-10-01 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna updated this revision to Diff 222749.
lawrence_danna added a comment.

updated based on an abstract base clase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68188

Files:
  lldb/include/lldb/API/SBFile.h
  lldb/include/lldb/Host/File.h
  lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
  lldb/scripts/Python/python-typemaps.swig
  lldb/scripts/interface/SBFile.i
  lldb/source/API/SBFile.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -84,14 +84,19 @@
 
   PythonObject(const PythonObject &rhs) : m_py_obj(nullptr) { Reset(rhs); }
 
+  PythonObject(PythonObject &&rhs) {
+m_py_obj = rhs.m_py_obj;
+rhs.m_py_obj = nullptr;
+  }
+
   virtual ~PythonObject() { Reset(); }
 
   void Reset() {
 // Avoid calling the virtual method since it's not necessary
 // to actually validate the type of the PyObject if we're
 // just setting to null.
-if (Py_IsInitialized())
-  Py_XDECREF(m_py_obj);
+if (m_py_obj && Py_IsInitialized())
+  Py_DECREF(m_py_obj);
 m_py_obj = nullptr;
   }
 
@@ -467,8 +472,40 @@
   void Reset(File &file, const char *mode);
 
   lldb::FileUP GetUnderlyingFile() const;
+
+  llvm::Expected ConvertToFile(bool borrowed = false);
+  llvm::Expected
+  ConvertToFileForcingUseOfScriptingIOMethods(bool borrowed = false);
+};
+
+class PythonException : public llvm::ErrorInfo {
+private:
+  PyObject *m_exception_type, *m_exception, *m_traceback;
+  PyObject *m_repr_bytes;
+
+public:
+  static char ID;
+  const char *toCString() const;
+  PythonException(const char *caller);
+  void Restore();
+  ~PythonException();
+  void log(llvm::raw_ostream &OS) const override;
+  std::error_code convertToErrorCode() const override;
 };
 
+template  T unwrapOrSetPythonException(llvm::Expected expected) {
+  if (expected) {
+return expected.get();
+  } else {
+llvm::handleAllErrors(
+expected.takeError(), [](PythonException &E) { E.Restore(); },
+[](const llvm::ErrorInfoBase &E) {
+  PyErr_SetString(PyExc_Exception, E.message().c_str());
+});
+return T();
+  }
+}
+
 } // namespace lldb_private
 
 #endif
Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Host/File.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Interpreter/ScriptInterpreter.h"
+#include "lldb/Utility/Log.h"
 #include "lldb/Utility/Stream.h"
 
 #include "llvm/ADT/StringSwitch.h"
@@ -29,6 +30,14 @@
 using namespace lldb_private;
 using namespace lldb;
 
+template  static T Take(PyObject *obj) {
+  return T(PyRefType::Owned, obj);
+}
+
+template  static T Retain(PyObject *obj) {
+  return T(PyRefType::Borrowed, obj);
+}
+
 void StructuredPythonObject::Dump(Stream &s, bool pretty_print) const {
   s << "Python Obj: 0x" << GetValue();
 }
@@ -963,9 +972,7 @@
   // first-class object type anymore.  `PyFile_FromFd` is just a thin wrapper
   // over `io.open()`, which returns some object derived from `io.IOBase`. As a
   // result, the only way to detect a file in Python 3 is to check whether it
-  // inherits from `io.IOBase`.  Since it is possible for non-files to also
-  // inherit from `io.IOBase`, we additionally verify that it has the `fileno`
-  // attribute, which should guarantee that it is backed by the file system.
+  // inherits from `io.IOBase`.
   PythonObject io_module(PyRefType::Owned, PyImport_ImportModule("io"));
   PythonDictionary io_dict(PyRefType::Borrowed,
PyModule_GetDict(io_module.get()));
@@ -975,8 +982,6 @@
 
   if (1 != PyObject_IsSubclass(object_type.get(), io_base_class.get()))
 return false;
-  if (!object_type.HasAttribute("fileno"))
-return false;
 
   return true;
 #endif
@@ -1031,4 +1036,406 @@
   return file;
 }
 
+class GIL {
+public:
+  GIL() { m_state = PyGILState_Ensure(); }
+  ~GIL() { PyGILState_Release(m_state); }
+
+protected:
+  PyGILState_STATE m_state;
+};
+
+const char *PythonException::toCString() const {
+  if (m_repr_bytes) {
+return PyBytes_AS_STRING(m_repr_bytes);
+  } else {
+return "unknown exception";
+  }
+}
+
+PythonException::PythonException(const char *caller) {
+  assert(PyErr_Occurred());
+  m_exception_type = m_exception = m_traceback = m_repr_bytes = NULL;
+  PyErr_Fetch(&m_exception_type, &m_exception, &m_traceback);
+ 

[Lldb-commits] [PATCH] D68188: allow arbitrary python streams to be converted to SBFile

2019-10-01 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna added a comment.

In D68188#1689544 , @labath wrote:

> This way the decision whether to "own" something is decoupled from the 
> decision what api do you use to actually write to the file, and I _think_ it 
> would make things clearer. What do you make of that?


Yea I think that works.  Updated.   I decided to go with the template thingy 
because there's kind of a lot of virtual methods to delegate and it's nice to 
have a list of them in the header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68188



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


[Lldb-commits] [PATCH] D68188: allow arbitrary python streams to be converted to SBFile

2019-10-01 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna updated this revision to Diff 222750.
lawrence_danna added a comment.

rename LLDBPythonFile -> OwnedPythonFile


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68188

Files:
  lldb/include/lldb/API/SBFile.h
  lldb/include/lldb/Host/File.h
  lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
  lldb/scripts/Python/python-typemaps.swig
  lldb/scripts/interface/SBFile.i
  lldb/source/API/SBFile.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -84,14 +84,19 @@
 
   PythonObject(const PythonObject &rhs) : m_py_obj(nullptr) { Reset(rhs); }
 
+  PythonObject(PythonObject &&rhs) {
+m_py_obj = rhs.m_py_obj;
+rhs.m_py_obj = nullptr;
+  }
+
   virtual ~PythonObject() { Reset(); }
 
   void Reset() {
 // Avoid calling the virtual method since it's not necessary
 // to actually validate the type of the PyObject if we're
 // just setting to null.
-if (Py_IsInitialized())
-  Py_XDECREF(m_py_obj);
+if (m_py_obj && Py_IsInitialized())
+  Py_DECREF(m_py_obj);
 m_py_obj = nullptr;
   }
 
@@ -467,8 +472,40 @@
   void Reset(File &file, const char *mode);
 
   lldb::FileUP GetUnderlyingFile() const;
+
+  llvm::Expected ConvertToFile(bool borrowed = false);
+  llvm::Expected
+  ConvertToFileForcingUseOfScriptingIOMethods(bool borrowed = false);
+};
+
+class PythonException : public llvm::ErrorInfo {
+private:
+  PyObject *m_exception_type, *m_exception, *m_traceback;
+  PyObject *m_repr_bytes;
+
+public:
+  static char ID;
+  const char *toCString() const;
+  PythonException(const char *caller);
+  void Restore();
+  ~PythonException();
+  void log(llvm::raw_ostream &OS) const override;
+  std::error_code convertToErrorCode() const override;
 };
 
+template  T unwrapOrSetPythonException(llvm::Expected expected) {
+  if (expected) {
+return expected.get();
+  } else {
+llvm::handleAllErrors(
+expected.takeError(), [](PythonException &E) { E.Restore(); },
+[](const llvm::ErrorInfoBase &E) {
+  PyErr_SetString(PyExc_Exception, E.message().c_str());
+});
+return T();
+  }
+}
+
 } // namespace lldb_private
 
 #endif
Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Host/File.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Interpreter/ScriptInterpreter.h"
+#include "lldb/Utility/Log.h"
 #include "lldb/Utility/Stream.h"
 
 #include "llvm/ADT/StringSwitch.h"
@@ -29,6 +30,14 @@
 using namespace lldb_private;
 using namespace lldb;
 
+template  static T Take(PyObject *obj) {
+  return T(PyRefType::Owned, obj);
+}
+
+template  static T Retain(PyObject *obj) {
+  return T(PyRefType::Borrowed, obj);
+}
+
 void StructuredPythonObject::Dump(Stream &s, bool pretty_print) const {
   s << "Python Obj: 0x" << GetValue();
 }
@@ -963,9 +972,7 @@
   // first-class object type anymore.  `PyFile_FromFd` is just a thin wrapper
   // over `io.open()`, which returns some object derived from `io.IOBase`. As a
   // result, the only way to detect a file in Python 3 is to check whether it
-  // inherits from `io.IOBase`.  Since it is possible for non-files to also
-  // inherit from `io.IOBase`, we additionally verify that it has the `fileno`
-  // attribute, which should guarantee that it is backed by the file system.
+  // inherits from `io.IOBase`.
   PythonObject io_module(PyRefType::Owned, PyImport_ImportModule("io"));
   PythonDictionary io_dict(PyRefType::Borrowed,
PyModule_GetDict(io_module.get()));
@@ -975,8 +982,6 @@
 
   if (1 != PyObject_IsSubclass(object_type.get(), io_base_class.get()))
 return false;
-  if (!object_type.HasAttribute("fileno"))
-return false;
 
   return true;
 #endif
@@ -1031,4 +1036,406 @@
   return file;
 }
 
+class GIL {
+public:
+  GIL() { m_state = PyGILState_Ensure(); }
+  ~GIL() { PyGILState_Release(m_state); }
+
+protected:
+  PyGILState_STATE m_state;
+};
+
+const char *PythonException::toCString() const {
+  if (m_repr_bytes) {
+return PyBytes_AS_STRING(m_repr_bytes);
+  } else {
+return "unknown exception";
+  }
+}
+
+PythonException::PythonException(const char *caller) {
+  assert(PyErr_Occurred());
+  m_exception_type = m_exception = m_traceback = m_repr_bytes = NULL;
+  PyErr_Fetch(&m_exception_type, &m_exception, &m_traceback);
+

[Lldb-commits] [PATCH] D68188: allow arbitrary python streams to be converted to SBFile

2019-10-01 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna updated this revision to Diff 222751.
lawrence_danna added a comment.

style fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68188

Files:
  lldb/include/lldb/API/SBFile.h
  lldb/include/lldb/Host/File.h
  lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
  lldb/scripts/Python/python-typemaps.swig
  lldb/scripts/interface/SBFile.i
  lldb/source/API/SBFile.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -84,14 +84,19 @@
 
   PythonObject(const PythonObject &rhs) : m_py_obj(nullptr) { Reset(rhs); }
 
+  PythonObject(PythonObject &&rhs) {
+m_py_obj = rhs.m_py_obj;
+rhs.m_py_obj = nullptr;
+  }
+
   virtual ~PythonObject() { Reset(); }
 
   void Reset() {
 // Avoid calling the virtual method since it's not necessary
 // to actually validate the type of the PyObject if we're
 // just setting to null.
-if (Py_IsInitialized())
-  Py_XDECREF(m_py_obj);
+if (m_py_obj && Py_IsInitialized())
+  Py_DECREF(m_py_obj);
 m_py_obj = nullptr;
   }
 
@@ -123,7 +128,7 @@
 // an owned reference by incrementing it.  If it is an owned
 // reference (for example the caller allocated it with PyDict_New()
 // then we must *not* increment it.
-if (Py_IsInitialized() && type == PyRefType::Borrowed)
+if (m_py_obj && Py_IsInitialized() && type == PyRefType::Borrowed)
   Py_XINCREF(m_py_obj);
   }
 
@@ -467,8 +472,38 @@
   void Reset(File &file, const char *mode);
 
   lldb::FileUP GetUnderlyingFile() const;
+
+  llvm::Expected ConvertToFile(bool borrowed = false);
+  llvm::Expected
+  ConvertToFileForcingUseOfScriptingIOMethods(bool borrowed = false);
 };
 
+class PythonException : public llvm::ErrorInfo {
+private:
+  PyObject *m_exception_type, *m_exception, *m_traceback;
+  PyObject *m_repr_bytes;
+
+public:
+  static char ID;
+  const char *toCString() const;
+  PythonException(const char *caller);
+  void Restore();
+  ~PythonException();
+  void log(llvm::raw_ostream &OS) const override;
+  std::error_code convertToErrorCode() const override;
+};
+
+template  T unwrapOrSetPythonException(llvm::Expected expected) {
+  if (expected)
+return expected.get();
+  llvm::handleAllErrors(
+  expected.takeError(), [](PythonException &E) { E.Restore(); },
+  [](const llvm::ErrorInfoBase &E) {
+PyErr_SetString(PyExc_Exception, E.message().c_str());
+  });
+  return T();
+}
+
 } // namespace lldb_private
 
 #endif
Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Host/File.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Interpreter/ScriptInterpreter.h"
+#include "lldb/Utility/Log.h"
 #include "lldb/Utility/Stream.h"
 
 #include "llvm/ADT/StringSwitch.h"
@@ -29,6 +30,14 @@
 using namespace lldb_private;
 using namespace lldb;
 
+template  static T Take(PyObject *obj) {
+  return T(PyRefType::Owned, obj);
+}
+
+template  static T Retain(PyObject *obj) {
+  return T(PyRefType::Borrowed, obj);
+}
+
 void StructuredPythonObject::Dump(Stream &s, bool pretty_print) const {
   s << "Python Obj: 0x" << GetValue();
 }
@@ -963,9 +972,7 @@
   // first-class object type anymore.  `PyFile_FromFd` is just a thin wrapper
   // over `io.open()`, which returns some object derived from `io.IOBase`. As a
   // result, the only way to detect a file in Python 3 is to check whether it
-  // inherits from `io.IOBase`.  Since it is possible for non-files to also
-  // inherit from `io.IOBase`, we additionally verify that it has the `fileno`
-  // attribute, which should guarantee that it is backed by the file system.
+  // inherits from `io.IOBase`.
   PythonObject io_module(PyRefType::Owned, PyImport_ImportModule("io"));
   PythonDictionary io_dict(PyRefType::Borrowed,
PyModule_GetDict(io_module.get()));
@@ -975,8 +982,6 @@
 
   if (1 != PyObject_IsSubclass(object_type.get(), io_base_class.get()))
 return false;
-  if (!object_type.HasAttribute("fileno"))
-return false;
 
   return true;
 #endif
@@ -1031,4 +1036,406 @@
   return file;
 }
 
+class GIL {
+public:
+  GIL() { m_state = PyGILState_Ensure(); }
+  ~GIL() { PyGILState_Release(m_state); }
+
+protected:
+  PyGILState_STATE m_state;
+};
+
+const char *PythonException::toCString() const {
+  if (m_repr_bytes) {
+return Py

[Lldb-commits] [PATCH] D68258: [Windows] Introduce a switch for the `lldb-server` mode on Windows

2019-10-01 Thread Aleksandr Urakov via Phabricator via lldb-commits
aleksandr.urakov added a comment.

I've made it in the way similar to Zachary have made for the 
`SymbolFileNativePDB` plugin. An environment variable could be more convenient 
e.g. to run a bunch of tests using the `lldb-test` option.


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D68258



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


[Lldb-commits] [PATCH] D68258: [Windows] Introduce a switch for the `lldb-server` mode on Windows

2019-10-01 Thread Aleksandr Urakov via Phabricator via lldb-commits
aleksandr.urakov added a comment.

In D68258#1690756 , @aleksandr.urakov 
wrote:

> I've made it in the way similar to Zachary have made for the 
> `SymbolFileNativePDB` plugin. An environment variable could be more 
> convenient e.g. to run a bunch of tests using the `lldb-test` option.


I'm sorry, sure I mean the `lldb-server` option.


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D68258



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


[Lldb-commits] [PATCH] D68188: allow arbitrary python streams to be converted to SBFile

2019-10-01 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna updated this revision to Diff 222753.
lawrence_danna added a comment.

use a python helper instead of funny tag structs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68188

Files:
  lldb/include/lldb/API/SBFile.h
  lldb/include/lldb/Host/File.h
  lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
  lldb/scripts/Python/python-typemaps.swig
  lldb/scripts/interface/SBFile.i
  lldb/source/API/SBFile.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -84,14 +84,19 @@
 
   PythonObject(const PythonObject &rhs) : m_py_obj(nullptr) { Reset(rhs); }
 
+  PythonObject(PythonObject &&rhs) {
+m_py_obj = rhs.m_py_obj;
+rhs.m_py_obj = nullptr;
+  }
+
   virtual ~PythonObject() { Reset(); }
 
   void Reset() {
 // Avoid calling the virtual method since it's not necessary
 // to actually validate the type of the PyObject if we're
 // just setting to null.
-if (Py_IsInitialized())
-  Py_XDECREF(m_py_obj);
+if (m_py_obj && Py_IsInitialized())
+  Py_DECREF(m_py_obj);
 m_py_obj = nullptr;
   }
 
@@ -123,7 +128,7 @@
 // an owned reference by incrementing it.  If it is an owned
 // reference (for example the caller allocated it with PyDict_New()
 // then we must *not* increment it.
-if (Py_IsInitialized() && type == PyRefType::Borrowed)
+if (m_py_obj && Py_IsInitialized() && type == PyRefType::Borrowed)
   Py_XINCREF(m_py_obj);
   }
 
@@ -467,8 +472,38 @@
   void Reset(File &file, const char *mode);
 
   lldb::FileUP GetUnderlyingFile() const;
+
+  llvm::Expected ConvertToFile(bool borrowed = false);
+  llvm::Expected
+  ConvertToFileForcingUseOfScriptingIOMethods(bool borrowed = false);
 };
 
+class PythonException : public llvm::ErrorInfo {
+private:
+  PyObject *m_exception_type, *m_exception, *m_traceback;
+  PyObject *m_repr_bytes;
+
+public:
+  static char ID;
+  const char *toCString() const;
+  PythonException(const char *caller);
+  void Restore();
+  ~PythonException();
+  void log(llvm::raw_ostream &OS) const override;
+  std::error_code convertToErrorCode() const override;
+};
+
+template  T unwrapOrSetPythonException(llvm::Expected expected) {
+  if (expected)
+return expected.get();
+  llvm::handleAllErrors(
+  expected.takeError(), [](PythonException &E) { E.Restore(); },
+  [](const llvm::ErrorInfoBase &E) {
+PyErr_SetString(PyExc_Exception, E.message().c_str());
+  });
+  return T();
+}
+
 } // namespace lldb_private
 
 #endif
Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Host/File.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Interpreter/ScriptInterpreter.h"
+#include "lldb/Utility/Log.h"
 #include "lldb/Utility/Stream.h"
 
 #include "llvm/ADT/StringSwitch.h"
@@ -29,6 +30,14 @@
 using namespace lldb_private;
 using namespace lldb;
 
+template  static T Take(PyObject *obj) {
+  return T(PyRefType::Owned, obj);
+}
+
+template  static T Retain(PyObject *obj) {
+  return T(PyRefType::Borrowed, obj);
+}
+
 void StructuredPythonObject::Dump(Stream &s, bool pretty_print) const {
   s << "Python Obj: 0x" << GetValue();
 }
@@ -963,9 +972,7 @@
   // first-class object type anymore.  `PyFile_FromFd` is just a thin wrapper
   // over `io.open()`, which returns some object derived from `io.IOBase`. As a
   // result, the only way to detect a file in Python 3 is to check whether it
-  // inherits from `io.IOBase`.  Since it is possible for non-files to also
-  // inherit from `io.IOBase`, we additionally verify that it has the `fileno`
-  // attribute, which should guarantee that it is backed by the file system.
+  // inherits from `io.IOBase`.
   PythonObject io_module(PyRefType::Owned, PyImport_ImportModule("io"));
   PythonDictionary io_dict(PyRefType::Borrowed,
PyModule_GetDict(io_module.get()));
@@ -975,8 +982,6 @@
 
   if (1 != PyObject_IsSubclass(object_type.get(), io_base_class.get()))
 return false;
-  if (!object_type.HasAttribute("fileno"))
-return false;
 
   return true;
 #endif
@@ -1031,4 +1036,406 @@
   return file;
 }
 
+class GIL {
+public:
+  GIL() { m_state = PyGILState_Ensure(); }
+  ~GIL() { PyGILState_Release(m_state); }
+
+protected:
+  PyGILState_STATE m_state;
+};
+
+const char *PythonException::toCString() const 

[Lldb-commits] [PATCH] D68188: allow arbitrary python streams to be converted to SBFile

2019-10-01 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna marked 2 inline comments as done.
lawrence_danna added inline comments.



Comment at: lldb/include/lldb/API/SBFile.h:16-21
+/* These tags make no difference at the c++ level, but
+ * when the constructors are called from python they control
+ * how python files are converted by SWIG into FileSP */
+struct FileBorrow {};
+struct FileForceScriptingIO {};
+struct FileBorrowAndForceScriptingIO {};

labath wrote:
> lawrence_danna wrote:
> > labath wrote:
> > > I don't think we have anything similar to this in any of our SB classes. 
> > > It might be better to avoid it. Could the same thing be achieved e.g. 
> > > with a static factory function (`static SBFile SBFile::Create(FileSP 
> > > file_sp, bool borrow, bool force_scripting_io)`) ?
> > I don't think it can be done that way, because we want those bools to 
> > control how the python object is translated into a C++ object, so we need a 
> > different swig wrapper for each possibility, which means we need a 
> > different c++ function to wrap  for each possibility.
> > 
> > One way around this would be to have SWIG translate the python object into 
> > an intermediate object that just takes a reference, and then perform 
> > further translation inside the SB layer.But we can't do that either, 
> > because scripting support is not part of the base LLDB library, it's a 
> > plugin.And in fact Xcode ships two versions of the plugin, one for 
> > python2 and one for python3.The SB needs to be agnostic about different 
> > versions of python, so it can't do the translation itself.   
> Are you sure about that? Swig allows you to define typemaps for sequences of 
> values. This example is taken from the swig documentation:
> ```
> %typemap(in) (char *str, int len) {
> $1 = PyString_AsString($input);   /* char *str */
> $2 = PyString_Size($input);   /* int len   */
> }
> ```
> It seems to me that your typemap could switch on the value of the flag at 
> runtime rather than having compile time switching by swig. This way you 
> wouldn't even need a static function, you could just have an additional 
> constructor with two extra bool arguments.
> 
> However, if this is not the preferred syntax for some reason, then we could 
> also have a set of static functions, one for each flag combination, do the 
> conversion that way.
> 
> (BTW, the main reason I am trying to avoid the tag structs is because they 
> are wading into uncharted territory in terms of our SB coding guidelines 
> )
I really do think it can't be done with swig.   You can group multiple 
arguments together on the C++ side, but not on the python side.

I think I did find a reasonable way to deal with it though without uglying up 
the SB headers with those tags.   I added some statics with %extend, and then 
wrapped them with a python-friendly classmethod called Create, with both flags 
as keyword args.

How's that look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68188



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


[Lldb-commits] [PATCH] D68278: Fix evaluation of nested classes with parent from other CU

2019-10-01 Thread Jaroslav Sevcik via Phabricator via lldb-commits
jarin updated this revision to Diff 222756.
jarin added a comment.

I have added some comments to the test (I hope it is not too overboard), 
removed the LEVEL stuff from the Makefile and fixed the formatting.


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

https://reviews.llvm.org/D68278

Files:
  
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/Makefile
  
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/TestNestedClassWithParentInAnotherCU.py
  
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/main.cpp
  
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/other.cpp
  
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/shared.h
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -690,6 +690,8 @@
 type_sp = unique_ast_entry_up->m_type_sp;
 if (type_sp) {
   dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
+  LinkDeclContextToDIE(
+  GetCachedClangDeclContextForDIE(unique_ast_entry_up->m_die), die);
   return type_sp;
 }
   }
Index: packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/shared.h
===
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/shared.h
@@ -0,0 +1,17 @@
+struct OuterX {
+  template
+  struct Inner {
+int oX_inner = 42;
+  };
+};
+
+struct OuterY {
+  template
+  struct Inner {
+typename OuterX::Inner oY_inner;
+  };
+};
+
+struct WrapperB;
+
+WrapperB* foo();
Index: packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/other.cpp
===
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/other.cpp
@@ -0,0 +1,10 @@
+#include "shared.h"
+
+struct WrapperB {
+  OuterY y;
+  OuterX x;
+};
+
+WrapperB* foo() {
+  return new WrapperB();
+}
Index: packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/main.cpp
===
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/main.cpp
@@ -0,0 +1,22 @@
+#include "shared.h"
+
+struct WrapperA {
+  OuterY::Inner y;
+};
+
+int main() {
+  // WrapperA refers to the Inner and Outer class DIEs from this CU.
+  WrapperA a;
+  // WrapperB refers to the Inner and Outer DIEs from the other.cpp CU.
+  // It is important that WrapperB is only foward-declared in shared.h.
+  WrapperB* b = foo();
+
+  // Evaluating 'b' here will parse other.cpp's DIEs for all
+  // the Inner and Outer classes from shared.h.
+  //
+  // Evaluating 'a' here will find and reuse the already-parsed
+  // versions of the Inner and Outer classes. In the associated test
+  // we make sure that we can still resolve all the types properly
+  // by evaluating 'a.y.oY_inner.oX_inner'.
+  return 0;  // break here
+}
Index: packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/TestNestedClassWithParentInAnotherCU.py
===
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/TestNestedClassWithParentInAnotherCU.py
@@ -0,0 +1,29 @@
+"""
+Test that expression evaluator can access members of nested classes even if
+the parents of the nested classes where imported from another compilation unit.
+"""
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestNestedClassWithParentInAnotherCU(TestBase):
+mydir = TestBase.compute_mydir(__file__)
+
+def test_nested_class_with_parent_in_another_cu(self):
+self.main_source_file = lldb.SBFileSpec("main.cpp")
+self.build()
+(_, _, thread, _) = lldbutil.run_to_source_breakpoint(self, "// break here", self.main_source_file)
+frame = thread.GetSelectedFrame()
+# Parse the DIEs of the parent classes and the nested classes from
+# other.cpp's CU.
+warmup_result = frame.EvaluateExpression("b")
+self.assertTrue(warmup_result.IsValid())
+# Inspect fields of the nested classes. This will reuse the types that
+# were parsed during the evaluation above. By accessing a chain of
+# fields, we try to verify that all the DIEs, reused types and
+# declaration contexts were wired properly into lldb's parser's state.
+expr_result = frame.EvaluateExpression("a.y.oY_inner.oX_inner")
+self.assertTrue(expr_

[Lldb-commits] [PATCH] D68278: Fix evaluation of nested classes with parent from other CU

2019-10-01 Thread Jaroslav Sevcik via Phabricator via lldb-commits
jarin updated this revision to Diff 222757.
jarin added a comment.

Fixed a typo.


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

https://reviews.llvm.org/D68278

Files:
  
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/Makefile
  
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/TestNestedClassWithParentInAnotherCU.py
  
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/main.cpp
  
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/other.cpp
  
packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/shared.h
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -690,6 +690,8 @@
 type_sp = unique_ast_entry_up->m_type_sp;
 if (type_sp) {
   dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
+  LinkDeclContextToDIE(
+  GetCachedClangDeclContextForDIE(unique_ast_entry_up->m_die), die);
   return type_sp;
 }
   }
Index: packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/shared.h
===
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/shared.h
@@ -0,0 +1,17 @@
+struct OuterX {
+  template
+  struct Inner {
+int oX_inner = 42;
+  };
+};
+
+struct OuterY {
+  template
+  struct Inner {
+typename OuterX::Inner oY_inner;
+  };
+};
+
+struct WrapperB;
+
+WrapperB* foo();
Index: packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/other.cpp
===
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/other.cpp
@@ -0,0 +1,10 @@
+#include "shared.h"
+
+struct WrapperB {
+  OuterY y;
+  OuterX x;
+};
+
+WrapperB* foo() {
+  return new WrapperB();
+}
Index: packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/main.cpp
===
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/main.cpp
@@ -0,0 +1,22 @@
+#include "shared.h"
+
+struct WrapperA {
+  OuterY::Inner y;
+};
+
+int main() {
+  // WrapperA refers to the Inner and Outer class DIEs from this CU.
+  WrapperA a;
+  // WrapperB refers to the Inner and Outer DIEs from the other.cpp CU.
+  // It is important that WrapperB is only foward-declared in shared.h.
+  WrapperB* b = foo();
+
+  // Evaluating 'b' here will parse other.cpp's DIEs for all
+  // the Inner and Outer classes from shared.h.
+  //
+  // Evaluating 'a' here will find and reuse the already-parsed
+  // versions of the Inner and Outer classes. In the associated test
+  // we make sure that we can still resolve all the types properly
+  // by evaluating 'a.y.oY_inner.oX_inner'.
+  return 0;  // break here
+}
Index: packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/TestNestedClassWithParentInAnotherCU.py
===
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/nested-class-other-compilation-unit/TestNestedClassWithParentInAnotherCU.py
@@ -0,0 +1,29 @@
+"""
+Test that expression evaluator can access members of nested classes even if
+the parents of the nested classes were imported from another compilation unit.
+"""
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestNestedClassWithParentInAnotherCU(TestBase):
+mydir = TestBase.compute_mydir(__file__)
+
+def test_nested_class_with_parent_in_another_cu(self):
+self.main_source_file = lldb.SBFileSpec("main.cpp")
+self.build()
+(_, _, thread, _) = lldbutil.run_to_source_breakpoint(self, "// break here", self.main_source_file)
+frame = thread.GetSelectedFrame()
+# Parse the DIEs of the parent classes and the nested classes from
+# other.cpp's CU.
+warmup_result = frame.EvaluateExpression("b")
+self.assertTrue(warmup_result.IsValid())
+# Inspect fields of the nested classes. This will reuse the types that
+# were parsed during the evaluation above. By accessing a chain of
+# fields, we try to verify that all the DIEs, reused types and
+# declaration contexts were wired properly into lldb's parser's state.
+expr_result = frame.EvaluateExpression("a.y.oY_inner.oX_inner")
+self.assertTrue(expr_result.IsValid())
+self.assertEqual(expr_result.GetValue(), "42")
Index: packages/Python/lldbsuite/test/lang/cpp/nested-c

[Lldb-commits] [PATCH] D68316: [Host] Return the user's shell from GetDefaultShell

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 222759.
JDevlieghere marked an inline comment as done.
JDevlieghere added a comment.

Check pointer returned by `getpwuid`.


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

https://reviews.llvm.org/D68316

Files:
  lldb/lit/Host/Inputs/simple.c
  lldb/lit/Host/TestCustomShell.test
  lldb/source/Host/posix/HostInfoPosix.cpp


Index: lldb/source/Host/posix/HostInfoPosix.cpp
===
--- lldb/source/Host/posix/HostInfoPosix.cpp
+++ lldb/source/Host/posix/HostInfoPosix.cpp
@@ -113,7 +113,14 @@
 
 uint32_t HostInfoPosix::GetEffectiveGroupID() { return getegid(); }
 
-FileSpec HostInfoPosix::GetDefaultShell() { return FileSpec("/bin/sh"); }
+FileSpec HostInfoPosix::GetDefaultShell() {
+  if (const char *v = ::getenv("SHELL"))
+return FileSpec(v);
+  if (const auto *pw = ::getpwuid(::geteuid()))
+if (const char *v = pw->pw_shell)
+  return FileSpec(v);
+  return FileSpec("/bin/sh");
+}
 
 bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) {
   return ComputePathRelativeToLibrary(file_spec, "/bin");
Index: lldb/lit/Host/TestCustomShell.test
===
--- /dev/null
+++ lldb/lit/Host/TestCustomShell.test
@@ -0,0 +1,5 @@
+# UNSUPPORTED: system-windows
+
+# RUN: %clang %S/Inputs/simple.c -g -o %t.out
+# RUN: SHELL=bogus %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s
+# CHECK: error: shell expansion failed
Index: lldb/lit/Host/Inputs/simple.c
===
--- /dev/null
+++ lldb/lit/Host/Inputs/simple.c
@@ -0,0 +1 @@
+int main(int argc, char const *argv[]) { return 0; }


Index: lldb/source/Host/posix/HostInfoPosix.cpp
===
--- lldb/source/Host/posix/HostInfoPosix.cpp
+++ lldb/source/Host/posix/HostInfoPosix.cpp
@@ -113,7 +113,14 @@
 
 uint32_t HostInfoPosix::GetEffectiveGroupID() { return getegid(); }
 
-FileSpec HostInfoPosix::GetDefaultShell() { return FileSpec("/bin/sh"); }
+FileSpec HostInfoPosix::GetDefaultShell() {
+  if (const char *v = ::getenv("SHELL"))
+return FileSpec(v);
+  if (const auto *pw = ::getpwuid(::geteuid()))
+if (const char *v = pw->pw_shell)
+  return FileSpec(v);
+  return FileSpec("/bin/sh");
+}
 
 bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) {
   return ComputePathRelativeToLibrary(file_spec, "/bin");
Index: lldb/lit/Host/TestCustomShell.test
===
--- /dev/null
+++ lldb/lit/Host/TestCustomShell.test
@@ -0,0 +1,5 @@
+# UNSUPPORTED: system-windows
+
+# RUN: %clang %S/Inputs/simple.c -g -o %t.out
+# RUN: SHELL=bogus %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s
+# CHECK: error: shell expansion failed
Index: lldb/lit/Host/Inputs/simple.c
===
--- /dev/null
+++ lldb/lit/Host/Inputs/simple.c
@@ -0,0 +1 @@
+int main(int argc, char const *argv[]) { return 0; }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D68316: [Host] Return the user's shell from GetDefaultShell

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere marked an inline comment as done.
JDevlieghere added inline comments.



Comment at: lldb/lit/Host/TestCustomShell.test:5
+# RUN: SHELL=bogus %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s
+# CHECK: error: shell expansion failed

JDevlieghere wrote:
> friss wrote:
> > Is there a reliable way to check that the expansion we get in lldb matches 
> > the one in the shell? For example, could we have the program dump its 
> > arguments once without lldb and match them against the lldb output?
> > 
> > I guess the zsh example that errors out in your description makes this 
> > hard?  
> You could run lldb-argdumper under lldb and compare the output to running it 
> under different shells. Do you think it's reasonable to assume that at least 
> `/bin/bash` and `/bin/zsh` are available?
Assuming we can find something that expands differently without throwing an 
error in bash and zsh.


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

https://reviews.llvm.org/D68316



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


[Lldb-commits] [PATCH] D68316: [Host] Return the user's shell from GetDefaultShell

2019-10-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/lit/Host/TestCustomShell.test:5
+# RUN: SHELL=bogus %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s
+# CHECK: error: shell expansion failed

friss wrote:
> Is there a reliable way to check that the expansion we get in lldb matches 
> the one in the shell? For example, could we have the program dump its 
> arguments once without lldb and match them against the lldb output?
> 
> I guess the zsh example that errors out in your description makes this hard?  
You could run lldb-argdumper under lldb and compare the output to running it 
under different shells. Do you think it's reasonable to assume that at least 
`/bin/bash` and `/bin/zsh` are available?


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

https://reviews.llvm.org/D68316



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