[Lldb-commits] [PATCH] D78801: [LLDB] Add class ProcessWasm for WebAssembly debugging

2020-05-01 Thread Paolo Severini via Phabricator via lldb-commits
paolosev added a comment.

> The thing I am resisting is to put all of this stuff in the the 
> ProcessGDBRemote class. Instead of trying to generalize it so that it can 
> handle everything (and generalize to the wrong thing), I very much like the 
> idea of introducing a `WasmProcess` plugin class that handles all wasm stuff. 
> If that class happens to use parts of gdb-remote, then so be it, but it means 
> that it's not a problem for that class to use a dialect of the gdb-remote 
> protocol, which includes as many wasm-specific packets as it needs. Then this 
> class can create it's own implementation of the "Unwind" interface, which 
> will use some WasmProcess-specific apis to undwind, but that will also be ok, 
> since both classes will be wasm-specific.

I think that this would solve a lot of problems. `WasmProcess` could inherit 
from GDBRemoteProcess and could send itself Wasm-specific commands like 
qWasmMem just by calling `GetGDBRemote().SendPacketAndWaitForResponse()` Then 
there would be no changes to ProcessGDBRemote at all.
For walking the call stack I would then keep the current design with the 
Unwind-derived class that sends a command to get the call stack from the stub. 
It’s true that normally it is the client that calculates call stacks, but it 
does so even because it cannot really ask them to the stub, but here we have a 
runtime that can provide this information.

> If dwarf had a notion of address spaces then there'd probably be no need for 
> DW_OP_WASM_location. If the dwarf committee hasn't been able to come up with 
> a unified way to represent address spaces, then I'm not sure we will do 
> better. And we'll still be left with the job of translating dwarf (and other) 
> entries into this other concept.

Yes, it is possible to come up with some representation of a unified address 
space for Wasm locals, globals and stack items (and also code and memory). But 
it's also true that locals, globals and stack items don’t really have a memory 
location. The reason for the introduction of `DW_OP_WASM_location` is indeed 
because there was nothing in DWARF that could well represent these entities. 
While there are certainly other architectures with multiple memory spaces, the 
execution model of WebAssembly is quite peculiar in this aspect, I think.

> The question is whether something similar can be done for the other two 
> cases. I believe it might be possible for the DWARFExpression. We just need 
> to have a way to separate the creation of the dwarf expression data from the 
> process of evaluating it. Right now, both of these things happens in 
> SymbolFileDWARF -- it creates a DWARFExpression object which both holds the 
> data and knows how to evaluate it. But I don't believe SymbolFileDWARF needs 
> the second part. If we could make it so that something else is responsible 
> for creating the evaluator for dwarf expressions, that something could create 
> a WasmDWARFExpression which would know about DW_OP_WASM_location and 
> WasmProcess, and could evaluate it.

Separating the DWARFExpression data and the logic to evaluate it would 
certainly make sense. I think that this must be a general problem: since DWARF 
provides the way to define custom expression location, different architectures 
might define specific DWARF codes that they need to handle, so it would be 
great if we had a `DWARFEvaluator`  that was also pluggable. I don’t know how 
complex would be to refactor DWARFExpression in this way but I can investigate.

> The `GetValueAsData` problem is trickier, particularly as I'm not even sure 
> the current implementation is correct. Are you sure that you really need the 
> _current_ module there? What happens if I use "target variable" to display a 
> variable from a different module? What if I then dereference that variable? 
> If the dereference should happen in the context of the other module, then I 
> guess the "module" should be a property of the value, not of the current 
> execution context. And it sounds like some address space-y thing would help. 
> But that might require teaching a lot of places in lldb about address spaces, 
> in particular that a dereferencing a value in one address space, should 
> produce a value in the same address space (at least for "near" pointer or 
> something).
>  If we should really use the current frame as the context, then I guess we'd 
> need some sort of a interfaces to ask a stack frame to get the value of a 
> "Value".

The fact that the code address space is separated from the memory address space 
is really what makes things complicated. However, we know for sure that every 
time that all memory reads made while evaluating DWARF expressions or variables 
always target the module memory space, never the code space.

I must confess that had not really tested `target variable` so far; I did it 
today and I found that it already //almost// works. What happens is that the 
location of the global variable is calculated with DWA

[Lldb-commits] [lldb] 1bff092 - [lldb/CommandInterpreter] Add CommandInterpreterRunResult (NFC)

2020-05-01 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2020-05-01T11:29:28-07:00
New Revision: 1bff0928f52b3d6602bae085c9590a1d807c2910

URL: 
https://github.com/llvm/llvm-project/commit/1bff0928f52b3d6602bae085c9590a1d807c2910
DIFF: 
https://github.com/llvm/llvm-project/commit/1bff0928f52b3d6602bae085c9590a1d807c2910.diff

LOG: [lldb/CommandInterpreter] Add CommandInterpreterRunResult (NFC)

This patch adds a new class CommandInterpreterRunResult which will be
backing the SBCommandInterpreterRunResult. It keeps track of the number
of errors as well as the result which is an enum, as proposed by Pavel
in D79120. The command interpreter now populates the results directly,
instead of its own member variables.

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

Added: 


Modified: 
lldb/include/lldb/Interpreter/CommandInterpreter.h
lldb/include/lldb/lldb-enumerations.h
lldb/source/API/SBDebugger.cpp
lldb/source/Interpreter/CommandInterpreter.cpp

Removed: 




diff  --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h 
b/lldb/include/lldb/Interpreter/CommandInterpreter.h
index c65075cad966..dbe5c186727a 100644
--- a/lldb/include/lldb/Interpreter/CommandInterpreter.h
+++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h
@@ -26,6 +26,32 @@
 #include 
 
 namespace lldb_private {
+class CommandInterpreter;
+
+class CommandInterpreterRunResult {
+public:
+  CommandInterpreterRunResult()
+  : m_num_errors(0), m_result(lldb::eCommandInterpreterResultSuccess) {}
+
+  uint32_t GetNumErrors() const { return m_num_errors; }
+
+  lldb::CommandInterpreterResult GetResult() const { return m_result; }
+
+  bool IsResult(lldb::CommandInterpreterResult result) {
+return m_result = result;
+  }
+
+protected:
+  friend CommandInterpreter;
+
+  void IncrementNumberOfErrors() { m_num_errors++; }
+
+  void SetResult(lldb::CommandInterpreterResult result) { m_result = result; }
+
+private:
+  int m_num_errors;
+  lldb::CommandInterpreterResult m_result;
+};
 
 class CommandInterpreterRunOptions {
 public:
@@ -442,7 +468,8 @@ class CommandInterpreter : public Broadcaster,
 
   bool IsActive();
 
-  void RunCommandInterpreter(CommandInterpreterRunOptions &options);
+  CommandInterpreterRunResult
+  RunCommandInterpreter(CommandInterpreterRunOptions &options);
 
   void GetLLDBCommandsFromIOHandler(const char *prompt,
 IOHandlerDelegate &delegate,
@@ -489,16 +516,10 @@ class CommandInterpreter : public Broadcaster,
 
   bool GetStopCmdSourceOnError() const;
 
-  uint32_t GetNumErrors() const { return m_num_errors; }
-
-  bool GetQuitRequested() const { return m_quit_requested; }
-
   lldb::IOHandlerSP
   GetIOHandler(bool force_create = false,
CommandInterpreterRunOptions *options = nullptr);
 
-  bool GetStoppedForCrash() const { return m_stopped_for_crash; }
-
   bool GetSpaceReplPrompts() const;
 
 protected:
@@ -589,9 +610,7 @@ class CommandInterpreter : public Broadcaster,
// the user has been 
told
   uint32_t m_command_source_depth;
   std::vector m_command_source_flags;
-  uint32_t m_num_errors;
-  bool m_quit_requested;
-  bool m_stopped_for_crash;
+  CommandInterpreterRunResult m_result;
 
   // The exit code the user has requested when calling the 'quit' command.
   // No value means the user hasn't set a custom exit code so far.

diff  --git a/lldb/include/lldb/lldb-enumerations.h 
b/lldb/include/lldb/lldb-enumerations.h
index 543e454c27c8..e5032a6cd97f 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -1081,6 +1081,20 @@ enum TypeSummaryCapping {
   eTypeSummaryCapped = true,
   eTypeSummaryUncapped = false
 };
+
+/// The result from a command interpreter run.
+enum CommandInterpreterResult {
+  /// Command interpreter finished successfully.
+  eCommandInterpreterResultSuccess,
+  /// Stopped because the corresponding option was set and the inferior
+  /// crashed.
+  eCommandInterpreterResultInferiorCrash,
+  /// Stopped because the corresponding option was set and a command returned
+  /// an error.
+  eCommandInterpreterResultCommandError,
+  /// Stopped because quit was requested.
+  eCommandInterpreterResultQuitRequested,
+};
 } // namespace lldb
 
 #endif // LLDB_LLDB_ENUMERATIONS_H

diff  --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 96b0da55b570..ae087594b57c 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1190,10 +1190,13 @@ void SBDebugger::RunCommandInterpreter(bool 
auto_handle_events,
 options.SetAutoHandleEvents(auto_handle_events);
 options.SetSpawnThread(spawn_thread);
 CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter();
-interp.RunCommandInterpreter(options.ref());
-num_errors = interp.GetNumErrors();
-quit_requested = interp.GetQuitRequested()

[Lldb-commits] [lldb] 232ef38 - [lldb/CommandInterpreter] Fix typo in CommandInterpreterResult::IsResult

2020-05-01 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2020-05-01T12:07:21-07:00
New Revision: 232ef38713b984cc84d2a009e83c1b044f0c06d3

URL: 
https://github.com/llvm/llvm-project/commit/232ef38713b984cc84d2a009e83c1b044f0c06d3
DIFF: 
https://github.com/llvm/llvm-project/commit/232ef38713b984cc84d2a009e83c1b044f0c06d3.diff

LOG: [lldb/CommandInterpreter] Fix typo in CommandInterpreterResult::IsResult

A missing `=` turned a comparison into an assignment.

Added: 


Modified: 
lldb/include/lldb/Interpreter/CommandInterpreter.h
lldb/source/Interpreter/CommandInterpreter.cpp

Removed: 




diff  --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h 
b/lldb/include/lldb/Interpreter/CommandInterpreter.h
index dbe5c186727a..a0a9bcb49969 100644
--- a/lldb/include/lldb/Interpreter/CommandInterpreter.h
+++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h
@@ -38,7 +38,7 @@ class CommandInterpreterRunResult {
   lldb::CommandInterpreterResult GetResult() const { return m_result; }
 
   bool IsResult(lldb::CommandInterpreterResult result) {
-return m_result = result;
+return m_result == result;
   }
 
 protected:

diff  --git a/lldb/source/Interpreter/CommandInterpreter.cpp 
b/lldb/source/Interpreter/CommandInterpreter.cpp
index d765cb7c1a9f..3f727e83f12b 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -116,7 +116,7 @@ CommandInterpreter::CommandInterpreter(Debugger &debugger,
   m_skip_lldbinit_files(false), m_skip_app_init_files(false),
   m_command_io_handler_sp(), m_comment_char('#'),
   m_batch_command_mode(false), m_truncation_warning(eNoTruncation),
-  m_command_source_depth(0) {
+  m_command_source_depth(0), m_result() {
   SetEventName(eBroadcastBitThreadShouldExit, "thread-should-exit");
   SetEventName(eBroadcastBitResetPrompt, "reset-prompt");
   SetEventName(eBroadcastBitQuitCommandReceived, "quit");



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


[Lldb-commits] [lldb] 4c67b11 - [lldb/API] Add SBCommandInterpreterRunResult

2020-05-01 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2020-05-01T13:55:38-07:00
New Revision: 4c67b11918d5cc819ebf965004abbdd7f281a652

URL: 
https://github.com/llvm/llvm-project/commit/4c67b11918d5cc819ebf965004abbdd7f281a652
DIFF: 
https://github.com/llvm/llvm-project/commit/4c67b11918d5cc819ebf965004abbdd7f281a652.diff

LOG: [lldb/API] Add SBCommandInterpreterRunResult

This adds an RunCommandInterpreter overload that returns an instance of
SBCommandInterpreterRunResults. The goal is to avoid having to add more
and more overloads when we need more output arguments.

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

Added: 


Modified: 
lldb/include/lldb/API/SBCommandInterpreterRunOptions.h
lldb/include/lldb/API/SBDebugger.h
lldb/include/lldb/API/SBDefines.h
lldb/source/API/SBCommandInterpreterRunOptions.cpp
lldb/source/API/SBDebugger.cpp
lldb/tools/driver/Driver.cpp

Removed: 




diff  --git a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h 
b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h
index ea23aefb3a01..82d6feedc02e 100644
--- a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h
+++ b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h
@@ -13,6 +13,11 @@
 
 #include "lldb/API/SBDefines.h"
 
+namespace lldb_private {
+class CommandInterpreterRunOptions;
+class CommandInterpreterRunResult;
+} // namespace lldb_private
+
 namespace lldb {
 
 class LLDB_API SBCommandInterpreterRunOptions {
@@ -69,6 +74,29 @@ class LLDB_API SBCommandInterpreterRunOptions {
   m_opaque_up;
 };
 
+class LLDB_API SBCommandInterpreterRunResult {
+  friend class SBDebugger;
+  friend class SBCommandInterpreter;
+
+public:
+  SBCommandInterpreterRunResult();
+  SBCommandInterpreterRunResult(const SBCommandInterpreterRunResult &rhs);
+  ~SBCommandInterpreterRunResult();
+
+  SBCommandInterpreterRunResult &
+  operator=(const SBCommandInterpreterRunResult &rhs);
+
+  int GetNumberOfErrors() const;
+  lldb::CommandInterpreterResult GetResult() const;
+
+private:
+  SBCommandInterpreterRunResult(
+  const lldb_private::CommandInterpreterRunResult &rhs);
+
+  // This is set in the constructor and will always be valid.
+  std::unique_ptr m_opaque_up;
+};
+
 } // namespace lldb
 
 #endif // LLDB_API_SBCOMMANDINTERPRETERRUNOPTIONS_H

diff  --git a/lldb/include/lldb/API/SBDebugger.h 
b/lldb/include/lldb/API/SBDebugger.h
index 6f585540dd34..b3bfa230139c 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -331,6 +331,9 @@ class LLDB_API SBDebugger {
  int &num_errors, bool &quit_requested,
  bool &stopped_for_crash);
 
+  SBCommandInterpreterRunResult
+  RunCommandInterpreter(const SBCommandInterpreterRunOptions &options);
+
   SBError RunREPL(lldb::LanguageType language, const char *repl_options);
 
 private:

diff  --git a/lldb/include/lldb/API/SBDefines.h 
b/lldb/include/lldb/API/SBDefines.h
index 0ddf594e5cb5..a5b639c6dc73 100644
--- a/lldb/include/lldb/API/SBDefines.h
+++ b/lldb/include/lldb/API/SBDefines.h
@@ -28,6 +28,7 @@ class LLDB_API SBBroadcaster;
 class LLDB_API SBCommand;
 class LLDB_API SBCommandInterpreter;
 class LLDB_API SBCommandInterpreterRunOptions;
+class LLDB_API SBCommandInterpreterRunResult;
 class LLDB_API SBCommandPluginInterface;
 class LLDB_API SBCommandReturnObject;
 class LLDB_API SBCommunication;

diff  --git a/lldb/source/API/SBCommandInterpreterRunOptions.cpp 
b/lldb/source/API/SBCommandInterpreterRunOptions.cpp
index 9ff017420c4e..7f880dc4605b 100644
--- a/lldb/source/API/SBCommandInterpreterRunOptions.cpp
+++ b/lldb/source/API/SBCommandInterpreterRunOptions.cpp
@@ -163,6 +163,58 @@ SBCommandInterpreterRunOptions::ref() const {
   return *m_opaque_up;
 }
 
+SBCommandInterpreterRunResult::SBCommandInterpreterRunResult()
+: m_opaque_up(new CommandInterpreterRunResult())
+
+{
+  LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBCommandInterpreterRunResult);
+}
+
+SBCommandInterpreterRunResult::SBCommandInterpreterRunResult(
+const SBCommandInterpreterRunResult &rhs)
+: m_opaque_up(new CommandInterpreterRunResult()) {
+  LLDB_RECORD_CONSTRUCTOR(SBCommandInterpreterRunResult,
+  (const lldb::SBCommandInterpreterRunResult &), rhs);
+
+  *m_opaque_up = *rhs.m_opaque_up;
+}
+
+SBCommandInterpreterRunResult::SBCommandInterpreterRunResult(
+const CommandInterpreterRunResult &rhs)
+: m_opaque_up() {
+  m_opaque_up.reset(new CommandInterpreterRunResult(rhs));
+}
+
+SBCommandInterpreterRunResult::~SBCommandInterpreterRunResult() = default;
+
+SBCommandInterpreterRunResult &SBCommandInterpreterRunResult::operator=(
+const SBCommandInterpreterRunResult &rhs) {
+  LLDB_RECORD_METHOD(lldb::SBCommandInterpreterRunResult &,
+ SBCommandInterpreterRunResult,
+ operator=,(const lldb::SBCommandInterpreterRunResult &),
+  

[Lldb-commits] [lldb] 68f8e02 - [ARM64] Remove dead code.

2020-05-01 Thread Davide Italiano via lldb-commits

Author: Davide Italiano
Date: 2020-05-01T15:04:44-07:00
New Revision: 68f8e0264e297bf7abadb1ca3850949606bdb4f5

URL: 
https://github.com/llvm/llvm-project/commit/68f8e0264e297bf7abadb1ca3850949606bdb4f5
DIFF: 
https://github.com/llvm/llvm-project/commit/68f8e0264e297bf7abadb1ca3850949606bdb4f5.diff

LOG: [ARM64] Remove dead code.

Added: 


Modified: 
lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp 
b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
index f58453909426..74253022a894 100644
--- a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
+++ b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
@@ -785,10 +785,6 @@ bool EmulateInstructionARM64::EmulateLDPSTP(const uint32_t 
opcode) {
 
   RegisterValue data_Rt;
   RegisterValue data_Rt2;
-
-  //if (vector)
-  //CheckFPEnabled(false);
-
   RegisterInfo reg_info_base;
   RegisterInfo reg_info_Rt;
   RegisterInfo reg_info_Rt2;



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


[Lldb-commits] [lldb] 30ddd4c - [ARM64] Remove more dead code. NFC.

2020-05-01 Thread Davide Italiano via lldb-commits

Author: Davide Italiano
Date: 2020-05-01T15:05:42-07:00
New Revision: 30ddd4ce19316fd2a8a50c5bc511433c87ecb95c

URL: 
https://github.com/llvm/llvm-project/commit/30ddd4ce19316fd2a8a50c5bc511433c87ecb95c
DIFF: 
https://github.com/llvm/llvm-project/commit/30ddd4ce19316fd2a8a50c5bc511433c87ecb95c.diff

LOG: [ARM64] Remove more dead code. NFC.

Added: 


Modified: 
lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp 
b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
index 74253022a894..dcf41444e48f 100644
--- a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
+++ b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
@@ -417,20 +417,12 @@ bool 
EmulateInstructionARM64::EvaluateInstruction(uint32_t evaluate_options) {
   if (opcode_data == nullptr)
 return false;
 
-  // printf ("opcode template for 0x%8.8x: %s\n", opcode, opcode_data->name);
   const bool auto_advance_pc =
   evaluate_options & eEmulateInstructionOptionAutoAdvancePC;
   m_ignore_conditions =
   evaluate_options & eEmulateInstructionOptionIgnoreConditions;
 
   bool success = false;
-  //if (m_opcode_cpsr == 0 || m_ignore_conditions == false)
-  //{
-  //m_opcode_cpsr = ReadRegisterUnsigned (eRegisterKindLLDB,
-  //  gpr_cpsr_arm64,
-  //  0,
-  //  &success);
-  //}
 
   // Only return false if we are unable to read the CPSR if we care about
   // conditions



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


[Lldb-commits] [PATCH] D78712: [lldb/Host] Improve error messages on unowned read files

2020-05-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

Looks good to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78712



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


[Lldb-commits] [PATCH] D79251: Fix overloaded operator new cases in TestCppOperators.py which currently work by accident

2020-05-01 Thread Shafik Yaghmour via Phabricator via lldb-commits
shafik created this revision.
shafik added reviewers: teemperor, aprantl, labath.

The overloaded `new operator` in `TestCppOperators.py` are working by accident. 
Currently we have:

  void *operator new(std::size_t size) { C* r = ::new C; r->custom_new = true; 
return r; }
  void *operator new[](std::size_t size) { C* r = 
static_cast(std::malloc(size)); r->custom_new = true; return r; }

Which allocate a C using global new which invokes the constructor on the 
allocated memory, it each one then proceeds to set the member variable 
`custom_new` to `true` and returns the allocated memory.

This is incorrect code b/c the allocation function is supposed to allocate 
memory, while the new expression which invokes this has the responsibility of 
then invoking the constructor (if any) on the newly allocated object e.g.:

  new struct C

So the constructor should be invoked again. IIUC currently because LLDB does 
not create the implicit constructor when parsing the `DWARF` because it is 
artificial, this results in construction being a no-op. If we OTOH explicitly 
default the constructor:

  C() = default;

The test no longer works since the in-class member initializer will be run and 
sets the field back to false:

  bool custom_new = false;

This behavior is a little surprising since I believe Sema should create the 
constructor for us when running the expression but either that is not really 
the case or there is some other piece that is missing.


https://reviews.llvm.org/D79251

Files:
  lldb/test/API/lang/cpp/operators/main.cpp


Index: lldb/test/API/lang/cpp/operators/main.cpp
===
--- lldb/test/API/lang/cpp/operators/main.cpp
+++ lldb/test/API/lang/cpp/operators/main.cpp
@@ -4,8 +4,8 @@
 
 struct B { int dummy = 2324; };
 struct C {
-  void *operator new(std::size_t size) { C* r = ::new C; r->custom_new = true; 
return r; }
-  void *operator new[](std::size_t size) { C* r = 
static_cast(std::malloc(size)); r->custom_new = true; return r; }
+  void *operator new(std::size_t size) { void *p = ::operator new(size); 
side_effect = 3; return p; }
+  void *operator new[](std::size_t size) { void *p = ::operator new(size); 
side_effect = 4; return p; }
   void operator delete(void *p) { std::free(p); side_effect = 1; }
   void operator delete[](void *p) { std::free(p); side_effect = 2; }
 
@@ -171,8 +171,8 @@
   //% self.expect("expr static_cast(c)", endstr=" 12\n")
   //% self.expect("expr c.operatorint()", endstr=" 13\n")
   //% self.expect("expr c.operatornew()", endstr=" 14\n")
-  //% self.expect("expr (new struct C)->custom_new", endstr=" true\n")
-  //% self.expect("expr (new struct C[1])->custom_new", endstr=" true\n")
+  //% self.expect("expr (new struct C); side_effect", endstr=" = 3\n")
+  //% self.expect("expr (new struct C[1]); side_effect", endstr=" = 4\n")
   //% self.expect("expr delete c2; side_effect", endstr=" = 1\n")
   //% self.expect("expr delete[] c3; side_effect", endstr=" = 2\n")
   delete c2;


Index: lldb/test/API/lang/cpp/operators/main.cpp
===
--- lldb/test/API/lang/cpp/operators/main.cpp
+++ lldb/test/API/lang/cpp/operators/main.cpp
@@ -4,8 +4,8 @@
 
 struct B { int dummy = 2324; };
 struct C {
-  void *operator new(std::size_t size) { C* r = ::new C; r->custom_new = true; return r; }
-  void *operator new[](std::size_t size) { C* r = static_cast(std::malloc(size)); r->custom_new = true; return r; }
+  void *operator new(std::size_t size) { void *p = ::operator new(size); side_effect = 3; return p; }
+  void *operator new[](std::size_t size) { void *p = ::operator new(size); side_effect = 4; return p; }
   void operator delete(void *p) { std::free(p); side_effect = 1; }
   void operator delete[](void *p) { std::free(p); side_effect = 2; }
 
@@ -171,8 +171,8 @@
   //% self.expect("expr static_cast(c)", endstr=" 12\n")
   //% self.expect("expr c.operatorint()", endstr=" 13\n")
   //% self.expect("expr c.operatornew()", endstr=" 14\n")
-  //% self.expect("expr (new struct C)->custom_new", endstr=" true\n")
-  //% self.expect("expr (new struct C[1])->custom_new", endstr=" true\n")
+  //% self.expect("expr (new struct C); side_effect", endstr=" = 3\n")
+  //% self.expect("expr (new struct C[1]); side_effect", endstr=" = 4\n")
   //% self.expect("expr delete c2; side_effect", endstr=" = 1\n")
   //% self.expect("expr delete[] c3; side_effect", endstr=" = 2\n")
   delete c2;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D78825: [lldb/Driver] Exit with a non-zero exit code in batch mode when stopping because of an error.

2020-05-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

Greg, you requested changes to this revision, I guess because of the 
dependencies. Anything here you'd like to see changed?


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D78825



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


[Lldb-commits] [PATCH] D77843: [lldb/DataFormatters] Delete GetStringPrinterEscapingHelper

2020-05-01 Thread Shafik Yaghmour via Phabricator via lldb-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

LGTM with minor comments, this is a big set of changes, I would prefer if one 
of the other reviewers also gave it a second look.




Comment at: lldb/source/DataFormatters/StringPrinter.cpp:49
+
+  const uint8_t *GetBytes() const { return &m_data[0]; }
+

just `m_data` it will decay to a pointer. 



Comment at: lldb/source/DataFormatters/StringPrinter.cpp:268
   case GetPrintableElementType::UTF8:
-return [](uint8_t *buffer, uint8_t *buffer_end,
-  uint8_t *&next) -> StringPrinter::StringPrinterBufferPointer {
-  return GetPrintable(StringPrinter::StringElementType::UTF8, buffer,
-  buffer_end, next);
+return [escape_style](uint8_t *buffer, uint8_t *buffer_end,
+  uint8_t *&next) -> DecodedCharBuffer {

It feels like the two lambdas here could be one by also capturing `elem_type`, 
it would make the lambda larger but is that a concern? Not a big deal just 
feels like needlessly duplicate code. 



Comment at: lldb/source/DataFormatters/StringPrinter.cpp:554
+template <>
+bool StringPrinter::ReadBufferAndDumpToStream(
+const ReadBufferAndDumpToStreamOptions &options) {

Super nitpick, can we switch order of the `UTF8` and the `ASCII` specialization 
so that they appear in the same order as the `ReadStringAndDumpToStream` above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77843



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


[Lldb-commits] [PATCH] D77843: [lldb/DataFormatters] Delete GetStringPrinterEscapingHelper

2020-05-01 Thread Vedant Kumar via Phabricator via lldb-commits
vsk updated this revision to Diff 261558.
vsk marked an inline comment as done.
vsk added a comment.

Address review feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77843

Files:
  lldb/include/lldb/DataFormatters/StringPrinter.h
  lldb/include/lldb/Target/Language.h
  lldb/source/DataFormatters/StringPrinter.cpp
  lldb/source/Plugins/Language/ObjC/NSString.cpp
  lldb/source/Target/Language.cpp
  lldb/unittests/DataFormatter/CMakeLists.txt
  lldb/unittests/DataFormatter/StringPrinterTests.cpp

Index: lldb/unittests/DataFormatter/StringPrinterTests.cpp
===
--- /dev/null
+++ lldb/unittests/DataFormatter/StringPrinterTests.cpp
@@ -0,0 +1,159 @@
+//===-- StringPrinterTests.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/DataFormatters/StringPrinter.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Endian.h"
+#include "lldb/Utility/StreamString.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+using lldb_private::formatters::StringPrinter;
+using llvm::Optional;
+using llvm::StringRef;
+
+#define QUOTE(x) std::string("\"" x "\"")
+
+/// Format \p input according to the specified string encoding and special char
+/// escape style.
+template 
+static Optional format(StringRef input,
+StringPrinter::EscapeStyle escape_style) {
+  StreamString out;
+  StringPrinter::ReadBufferAndDumpToStreamOptions opts;
+  opts.SetStream(&out);
+  opts.SetSourceSize(input.size());
+  opts.SetNeedsZeroTermination(true);
+  opts.SetEscapeNonPrintables(true);
+  opts.SetIgnoreMaxLength(false);
+  opts.SetEscapeStyle(escape_style);
+  DataExtractor extractor(input.data(), input.size(),
+  endian::InlHostByteOrder(), sizeof(void *));
+  opts.SetData(extractor);
+  const bool success = StringPrinter::ReadBufferAndDumpToStream(opts);
+  if (!success)
+return llvm::None;
+  return out.GetString().str();
+}
+
+// Test ASCII formatting for C++. This behaves exactly like UTF8 formatting for
+// C++, although that's questionable (see FIXME in StringPrinter.cpp).
+TEST(StringPrinterTests, CxxASCII) {
+  auto fmt = [](StringRef str) {
+return format(
+str, StringPrinter::EscapeStyle::CXX);
+  };
+
+  // Special escapes.
+  EXPECT_EQ(fmt({"\0", 1}), QUOTE(""));
+  EXPECT_EQ(fmt("\a"), QUOTE(R"(\a)"));
+  EXPECT_EQ(fmt("\b"), QUOTE(R"(\b)"));
+  EXPECT_EQ(fmt("\f"), QUOTE(R"(\f)"));
+  EXPECT_EQ(fmt("\n"), QUOTE(R"(\n)"));
+  EXPECT_EQ(fmt("\r"), QUOTE(R"(\r)"));
+  EXPECT_EQ(fmt("\t"), QUOTE(R"(\t)"));
+  EXPECT_EQ(fmt("\v"), QUOTE(R"(\v)"));
+  EXPECT_EQ(fmt("\""), QUOTE(R"(\")"));
+  EXPECT_EQ(fmt("\'"), QUOTE(R"(')"));
+  EXPECT_EQ(fmt("\\"), QUOTE(R"(\\)"));
+
+  // Printable characters.
+  EXPECT_EQ(fmt("'"), QUOTE("'"));
+  EXPECT_EQ(fmt("a"), QUOTE("a"));
+  EXPECT_EQ(fmt("Z"), QUOTE("Z"));
+  EXPECT_EQ(fmt("πŸ₯‘"), QUOTE("πŸ₯‘"));
+
+  // Octal (\nnn), hex (\xnn), extended octal (\u or \U).
+  EXPECT_EQ(fmt("\uD55C"), QUOTE("ν•œ"));
+  EXPECT_EQ(fmt("\U00010348"), QUOTE("𐍈"));
+
+  // FIXME: These strings are all rejected, but shouldn't be AFAICT. LLDB finds
+  // that these are not valid utf8 sequences, but that's OK, the raw values
+  // should still be printed out.
+  EXPECT_NE(fmt("\376"), QUOTE(R"(\xfe)")); // \376 is 254 in decimal.
+  EXPECT_NE(fmt("\xfe"), QUOTE(R"(\xfe)")); // \xfe is 254 in decimal.
+}
+
+// Test UTF8 formatting for C++.
+TEST(StringPrinterTests, CxxUTF8) {
+  auto fmt = [](StringRef str) {
+return format(
+str, StringPrinter::EscapeStyle::CXX);
+  };
+
+  // Special escapes.
+  EXPECT_EQ(fmt({"\0", 1}), QUOTE(""));
+  EXPECT_EQ(fmt("\a"), QUOTE(R"(\a)"));
+  EXPECT_EQ(fmt("\b"), QUOTE(R"(\b)"));
+  EXPECT_EQ(fmt("\f"), QUOTE(R"(\f)"));
+  EXPECT_EQ(fmt("\n"), QUOTE(R"(\n)"));
+  EXPECT_EQ(fmt("\r"), QUOTE(R"(\r)"));
+  EXPECT_EQ(fmt("\t"), QUOTE(R"(\t)"));
+  EXPECT_EQ(fmt("\v"), QUOTE(R"(\v)"));
+  EXPECT_EQ(fmt("\""), QUOTE(R"(\")"));
+  EXPECT_EQ(fmt("\'"), QUOTE(R"(')"));
+  EXPECT_EQ(fmt("\\"), QUOTE(R"(\\)"));
+
+  // Printable characters.
+  EXPECT_EQ(fmt("'"), QUOTE("'"));
+  EXPECT_EQ(fmt("a"), QUOTE("a"));
+  EXPECT_EQ(fmt("Z"), QUOTE("Z"));
+  EXPECT_EQ(fmt("πŸ₯‘"), QUOTE("πŸ₯‘"));
+
+  // Octal (\nnn), hex (\xnn), extended octal (\u or \U).
+  EXPECT_EQ(fmt("\uD55C"), QUOTE("ν•œ"));
+  EXPECT_EQ(fmt("\U00010348"), QUOTE("𐍈"));
+
+  // FIXME: These strings are all rejected

[Lldb-commits] [PATCH] D77843: [lldb/DataFormatters] Delete GetStringPrinterEscapingHelper

2020-05-01 Thread Vedant Kumar via Phabricator via lldb-commits
vsk marked 4 inline comments as done.
vsk added inline comments.



Comment at: lldb/source/DataFormatters/StringPrinter.cpp:268
   case GetPrintableElementType::UTF8:
-return [](uint8_t *buffer, uint8_t *buffer_end,
-  uint8_t *&next) -> StringPrinter::StringPrinterBufferPointer {
-  return GetPrintable(StringPrinter::StringElementType::UTF8, buffer,
-  buffer_end, next);
+return [escape_style](uint8_t *buffer, uint8_t *buffer_end,
+  uint8_t *&next) -> DecodedCharBuffer {

shafik wrote:
> It feels like the two lambdas here could be one by also capturing 
> `elem_type`, it would make the lambda larger but is that a concern? Not a big 
> deal just feels like needlessly duplicate code. 
Sure, these can be folded together.



Comment at: lldb/source/DataFormatters/StringPrinter.cpp:554
+template <>
+bool StringPrinter::ReadBufferAndDumpToStream(
+const ReadBufferAndDumpToStreamOptions &options) {

shafik wrote:
> Super nitpick, can we switch order of the `UTF8` and the `ASCII` 
> specialization so that they appear in the same order as the 
> `ReadStringAndDumpToStream` above.
No, because the ASCII specialization calls the UTF8 specialization, and the 
compiler complains that the use occurs before the definition. I'll just reorder 
the specializations of ReadStringAndDumpToStream so that things match.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77843



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


[Lldb-commits] [PATCH] D79273: Add an explicit API to read the Xcode SDK DWARF attribute from compile units

2020-05-01 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl created this revision.
aprantl added reviewers: friss, jingham, JDevlieghere, davide.
Herald added a reviewer: jdoerfert.
aprantl updated this revision to Diff 261573.
aprantl added a comment.

Delete more code that is made obsolete by the new API.


When debugging from a SymbolMap the creation of CompileUnits for the
individual object files is so lazy that RegisterXcodeSDK() is not invoked at all
before the Swift TypeSystem wants to read it. This patch fixes this by
introducing an explicit SymbolFile::ParseXcodeSDK() call that can be
invoked deterministically before the result is required.

  

rdar://problem/62532151


https://reviews.llvm.org/D79273

Files:
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/source/Core/Module.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
  lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -64,13 +64,13 @@
 
   auto triple = "x86_64-apple-macosx";
   YAMLModuleTester t(yamldata, triple);
-  auto module = t.GetModule();
   auto dwarf_unit_sp = t.GetDwarfUnit();
   auto *dwarf_cu = llvm::cast(dwarf_unit_sp.get());
   ASSERT_TRUE((bool)dwarf_cu);
-  ASSERT_TRUE((bool)dwarf_cu->GetSymbolFileDWARF().GetCompUnitForDWARFCompUnit(
-  *dwarf_cu));
-  XcodeSDK sdk = module->GetXcodeSDK();
+  SymbolFileDWARF &sym_file = dwarf_cu->GetSymbolFileDWARF();
+  CompUnitSP comp_unit = sym_file.GetCompileUnitAtIndex(0);
+  ASSERT_TRUE((bool)comp_unit.get());
+  XcodeSDK sdk = sym_file.ParseXcodeSDK(*comp_unit);
   ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
 }
 #endif
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
@@ -58,6 +58,9 @@
   lldb::LanguageType
   ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
 
+  lldb_private::XcodeSDK
+  ParseXcodeSDK(lldb_private::CompileUnit &comp_unit) override;
+
   size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
 
   bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -628,6 +628,15 @@
   return eLanguageTypeUnknown;
 }
 
+XcodeSDK
+SymbolFileDWARFDebugMap::ParseXcodeSDK(CompileUnit &comp_unit) {
+  std::lock_guard guard(GetModuleMutex());
+  SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
+  if (oso_dwarf)
+return oso_dwarf->ParseXcodeSDK(comp_unit);
+  return {};
+}
+
 size_t SymbolFileDWARFDebugMap::ParseFunctions(CompileUnit &comp_unit) {
   std::lock_guard guard(GetModuleMutex());
   SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -106,6 +106,9 @@
   lldb::LanguageType
   ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
 
+  lldb_private::XcodeSDK
+  ParseXcodeSDK(lldb_private::CompileUnit &comp_unit) override;
+
   size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
 
   bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -664,12 +664,6 @@
 const DWARFBaseDIE cu_die =
 dwarf_cu.GetNonSkeletonUnit().GetUnitDIEOnly();
 if (cu_die) {
-  if (const char *sdk =
-  cu_die.GetAttributeValueAsString(DW_AT_APPLE_sdk, nullptr)) {
-const char *sysroot =
-cu_die.GetAttributeValueAsString(DW_AT_LLVM_sysroot, "");
-module_sp->RegisterXcodeSDK(sdk, sysroot);
-  }
   FileSpec cu_file_spec(cu_die.GetName(), dwarf_cu.GetPathStyle());
   MakeAbsoluteAndRemap(cu_file_spec, dwarf_cu, module_sp);
 
@@ -778,6 +772,22 @@
 return eLanguageTypeUnknown;
 }
 
+XcodeSDK SymbolFileDWARF::ParseXcodeSDK(CompileUnit &comp_unit) {
+  std::lock_guard guard(GetModuleMutex());
+  if (D

[Lldb-commits] [PATCH] D79273: Add an explicit API to read the Xcode SDK DWARF attribute from compile units

2020-05-01 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl updated this revision to Diff 261573.
aprantl added a comment.

Delete more code that is made obsolete by the new API.


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

https://reviews.llvm.org/D79273

Files:
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/source/Core/Module.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
  lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -64,13 +64,13 @@
 
   auto triple = "x86_64-apple-macosx";
   YAMLModuleTester t(yamldata, triple);
-  auto module = t.GetModule();
   auto dwarf_unit_sp = t.GetDwarfUnit();
   auto *dwarf_cu = llvm::cast(dwarf_unit_sp.get());
   ASSERT_TRUE((bool)dwarf_cu);
-  ASSERT_TRUE((bool)dwarf_cu->GetSymbolFileDWARF().GetCompUnitForDWARFCompUnit(
-  *dwarf_cu));
-  XcodeSDK sdk = module->GetXcodeSDK();
+  SymbolFileDWARF &sym_file = dwarf_cu->GetSymbolFileDWARF();
+  CompUnitSP comp_unit = sym_file.GetCompileUnitAtIndex(0);
+  ASSERT_TRUE((bool)comp_unit.get());
+  XcodeSDK sdk = sym_file.ParseXcodeSDK(*comp_unit);
   ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
 }
 #endif
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
@@ -58,6 +58,9 @@
   lldb::LanguageType
   ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
 
+  lldb_private::XcodeSDK
+  ParseXcodeSDK(lldb_private::CompileUnit &comp_unit) override;
+
   size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
 
   bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -628,6 +628,15 @@
   return eLanguageTypeUnknown;
 }
 
+XcodeSDK
+SymbolFileDWARFDebugMap::ParseXcodeSDK(CompileUnit &comp_unit) {
+  std::lock_guard guard(GetModuleMutex());
+  SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
+  if (oso_dwarf)
+return oso_dwarf->ParseXcodeSDK(comp_unit);
+  return {};
+}
+
 size_t SymbolFileDWARFDebugMap::ParseFunctions(CompileUnit &comp_unit) {
   std::lock_guard guard(GetModuleMutex());
   SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -106,6 +106,9 @@
   lldb::LanguageType
   ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
 
+  lldb_private::XcodeSDK
+  ParseXcodeSDK(lldb_private::CompileUnit &comp_unit) override;
+
   size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
 
   bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -664,12 +664,6 @@
 const DWARFBaseDIE cu_die =
 dwarf_cu.GetNonSkeletonUnit().GetUnitDIEOnly();
 if (cu_die) {
-  if (const char *sdk =
-  cu_die.GetAttributeValueAsString(DW_AT_APPLE_sdk, nullptr)) {
-const char *sysroot =
-cu_die.GetAttributeValueAsString(DW_AT_LLVM_sysroot, "");
-module_sp->RegisterXcodeSDK(sdk, sysroot);
-  }
   FileSpec cu_file_spec(cu_die.GetName(), dwarf_cu.GetPathStyle());
   MakeAbsoluteAndRemap(cu_file_spec, dwarf_cu, module_sp);
 
@@ -778,6 +772,22 @@
 return eLanguageTypeUnknown;
 }
 
+XcodeSDK SymbolFileDWARF::ParseXcodeSDK(CompileUnit &comp_unit) {
+  std::lock_guard guard(GetModuleMutex());
+  if (DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit))
+if (ModuleSP module_sp = m_objfile_sp->GetModule())
+  if (const DWARFBaseDIE cu_die =
+  dwarf_cu->GetNonSkeletonUnit().GetUnitDIEOnly())
+if (const char *sdk =
+cu_die.GetAttributeValueAsString(DW_AT_APPLE_sdk, nullptr)) {
+  const char *sysroot =
+  cu_die.GetAttributeValueAsString(DW_AT_LLVM_sysroot, "");
+  modul

[Lldb-commits] [PATCH] D79209: [lldb/CommandInterpreter] Add CommandInterpreterRunResult (NFC)

2020-05-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1bff0928f52b: [lldb/CommandInterpreter] Add 
CommandInterpreterRunResult (NFC) (authored by JDevlieghere).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D79209?vs=261361&id=261583#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79209

Files:
  lldb/include/lldb/Interpreter/CommandInterpreter.h
  lldb/include/lldb/lldb-enumerations.h
  lldb/source/API/SBDebugger.cpp
  lldb/source/Interpreter/CommandInterpreter.cpp

Index: lldb/source/Interpreter/CommandInterpreter.cpp
===
--- lldb/source/Interpreter/CommandInterpreter.cpp
+++ lldb/source/Interpreter/CommandInterpreter.cpp
@@ -116,8 +116,7 @@
   m_skip_lldbinit_files(false), m_skip_app_init_files(false),
   m_command_io_handler_sp(), m_comment_char('#'),
   m_batch_command_mode(false), m_truncation_warning(eNoTruncation),
-  m_command_source_depth(0), m_num_errors(0), m_quit_requested(false),
-  m_stopped_for_crash(false) {
+  m_command_source_depth(0) {
   SetEventName(eBroadcastBitThreadShouldExit, "thread-should-exit");
   SetEventName(eBroadcastBitResetPrompt, "reset-prompt");
   SetEventName(eBroadcastBitQuitCommandReceived, "quit");
@@ -2816,23 +2815,24 @@
 break;
 
   case eReturnStatusFailed:
-m_num_errors++;
+m_result.IncrementNumberOfErrors();
 if (io_handler.GetFlags().Test(eHandleCommandFlagStopOnError))
   io_handler.SetIsDone(true);
 break;
 
   case eReturnStatusQuit:
-m_quit_requested = true;
+m_result.SetResult(lldb::eCommandInterpreterResultQuitRequested);
 io_handler.SetIsDone(true);
 break;
   }
 
   // Finally, if we're going to stop on crash, check that here:
-  if (!m_quit_requested && result.GetDidChangeProcessState() &&
+  if (m_result.IsResult(lldb::eCommandInterpreterResultSuccess) &&
+  result.GetDidChangeProcessState() &&
   io_handler.GetFlags().Test(eHandleCommandFlagStopOnCrash) &&
   DidProcessStopAbnormally()) {
 io_handler.SetIsDone(true);
-m_stopped_for_crash = true;
+m_result.SetResult(lldb::eCommandInterpreterResultInferiorCrash);
   }
 }
 
@@ -2950,13 +2950,13 @@
   return m_command_io_handler_sp;
 }
 
-void CommandInterpreter::RunCommandInterpreter(
+CommandInterpreterRunResult CommandInterpreter::RunCommandInterpreter(
 CommandInterpreterRunOptions &options) {
   // Always re-create the command interpreter when we run it in case any file
   // handles have changed.
   bool force_create = true;
   m_debugger.RunIOHandlerAsync(GetIOHandler(force_create, &options));
-  m_stopped_for_crash = false;
+  m_result = CommandInterpreterRunResult();
 
   if (options.GetAutoHandleEvents())
 m_debugger.StartEventHandlerThread();
@@ -2969,6 +2969,8 @@
 if (options.GetAutoHandleEvents())
   m_debugger.StopEventHandlerThread();
   }
+
+  return m_result;
 }
 
 CommandObject *
Index: lldb/source/API/SBDebugger.cpp
===
--- lldb/source/API/SBDebugger.cpp
+++ lldb/source/API/SBDebugger.cpp
@@ -1190,10 +1190,13 @@
 options.SetAutoHandleEvents(auto_handle_events);
 options.SetSpawnThread(spawn_thread);
 CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter();
-interp.RunCommandInterpreter(options.ref());
-num_errors = interp.GetNumErrors();
-quit_requested = interp.GetQuitRequested();
-stopped_for_crash = interp.GetStoppedForCrash();
+CommandInterpreterRunResult result =
+interp.RunCommandInterpreter(options.ref());
+num_errors = result.GetNumErrors();
+quit_requested =
+result.IsResult(lldb::eCommandInterpreterResultQuitRequested);
+stopped_for_crash =
+result.IsResult(lldb::eCommandInterpreterResultInferiorCrash);
   }
 }
 
Index: lldb/include/lldb/lldb-enumerations.h
===
--- lldb/include/lldb/lldb-enumerations.h
+++ lldb/include/lldb/lldb-enumerations.h
@@ -1081,6 +1081,20 @@
   eTypeSummaryCapped = true,
   eTypeSummaryUncapped = false
 };
+
+/// The result from a command interpreter run.
+enum CommandInterpreterResult {
+  /// Command interpreter finished successfully.
+  eCommandInterpreterResultSuccess,
+  /// Stopped because the corresponding option was set and the inferior
+  /// crashed.
+  eCommandInterpreterResultInferiorCrash,
+  /// Stopped because the corresponding option was set and a command returned
+  /// an error.
+  eCommandInterpreterResultCommandError,
+  /// Stopped because quit was requested.
+  eCommandInterpreterResultQuitRequested,
+};
 } // namespace lldb
 
 #endif // LLDB_LLDB_ENUMERATIONS_H
Index: lldb/include/lldb/Interpreter/CommandInterpreter.h
===
--- lldb/inclu

[Lldb-commits] [PATCH] D79120: [lldb/API] Add RunCommandInterpreter overload that returns SBCommandInterpreterRunResults (NFC)

2020-05-01 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4c67b11918d5: [lldb/API] Add SBCommandInterpreterRunResult 
(authored by JDevlieghere).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D79120?vs=261382&id=261587#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79120

Files:
  lldb/include/lldb/API/SBCommandInterpreterRunOptions.h
  lldb/include/lldb/API/SBDebugger.h
  lldb/include/lldb/API/SBDefines.h
  lldb/source/API/SBCommandInterpreterRunOptions.cpp
  lldb/source/API/SBDebugger.cpp
  lldb/tools/driver/Driver.cpp

Index: lldb/tools/driver/Driver.cpp
===
--- lldb/tools/driver/Driver.cpp
+++ lldb/tools/driver/Driver.cpp
@@ -588,10 +588,7 @@
   const char *commands_data = commands_stream.GetData();
   const size_t commands_size = commands_stream.GetSize();
 
-  // The command file might have requested that we quit, this variable will
-  // track that.
-  bool quit_requested = false;
-  bool stopped_for_crash = false;
+  bool go_interactive = true;
   if ((commands_data != nullptr) && (commands_size != 0u)) {
 FILE *commands_file =
 PrepareCommandsForSourcing(commands_data, commands_size);
@@ -603,23 +600,27 @@
 
 m_debugger.SetInputFileHandle(commands_file, true);
 
-// Set the debugger into Sync mode when running the command file.
-// Otherwise command files
-// that run the target won't run in a sensible way.
+// Set the debugger into Sync mode when running the command file. Otherwise
+// command files that run the target won't run in a sensible way.
 bool old_async = m_debugger.GetAsync();
 m_debugger.SetAsync(false);
-int num_errors = 0;
 
 SBCommandInterpreterRunOptions options;
+options.SetAutoHandleEvents(true);
+options.SetSpawnThread(false);
 options.SetStopOnError(true);
-if (m_option_data.m_batch)
-  options.SetStopOnCrash(true);
-
-m_debugger.RunCommandInterpreter(handle_events, spawn_thread, options,
- num_errors, quit_requested,
- stopped_for_crash);
-
-if (m_option_data.m_batch && stopped_for_crash &&
+options.SetStopOnCrash(m_option_data.m_batch);
+
+SBCommandInterpreterRunResult results =
+m_debugger.RunCommandInterpreter(options);
+if (results.GetResult() == lldb::eCommandInterpreterResultQuitRequested)
+  go_interactive = false;
+if (m_option_data.m_batch &&
+results.GetResult() != lldb::eCommandInterpreterResultInferiorCrash)
+  go_interactive = false;
+
+if (m_option_data.m_batch &&
+results.GetResult() == lldb::eCommandInterpreterResultInferiorCrash &&
 !m_option_data.m_after_crash_commands.empty()) {
   SBStream crash_commands_stream;
   WriteCommandsForSourcing(eCommandPlacementAfterCrash,
@@ -629,30 +630,20 @@
   commands_file =
   PrepareCommandsForSourcing(crash_commands_data, crash_commands_size);
   if (commands_file != nullptr) {
-bool local_quit_requested;
-bool local_stopped_for_crash;
 m_debugger.SetInputFileHandle(commands_file, true);
-
-m_debugger.RunCommandInterpreter(handle_events, spawn_thread, options,
- num_errors, local_quit_requested,
- local_stopped_for_crash);
-if (local_quit_requested)
-  quit_requested = true;
+SBCommandInterpreterRunResult local_results =
+m_debugger.RunCommandInterpreter(options);
+if (local_results.GetResult() ==
+lldb::eCommandInterpreterResultQuitRequested)
+  go_interactive = false;
   }
 }
 m_debugger.SetAsync(old_async);
   }
 
-  // Now set the input file handle to STDIN and run the command
-  // interpreter again in interactive mode or repl mode and let the debugger
-  // take ownership of stdin
-
-  bool go_interactive = true;
-  if (quit_requested)
-go_interactive = false;
-  else if (m_option_data.m_batch && !stopped_for_crash)
-go_interactive = false;
-
+  // Now set the input file handle to STDIN and run the command interpreter
+  // again in interactive mode or repl mode and let the debugger take ownership
+  // of stdin.
   if (go_interactive) {
 m_debugger.SetInputFileHandle(stdin, true);
 
Index: lldb/source/API/SBDebugger.cpp
===
--- lldb/source/API/SBDebugger.cpp
+++ lldb/source/API/SBDebugger.cpp
@@ -1200,6 +1200,22 @@
   }
 }
 
+SBCommandInterpreterRunResult SBDebugger::RunCommandInterpreter(
+const SBCommandInterpreterRunOptions &options) {
+  LLDB_RECORD_METHOD(lldb::SBCommandInterpreterRunResult, SBDebugger,
+ RunCommandInterpreter,
+ (const lldb::SBCommandIn

[Lldb-commits] [PATCH] D79273: Add an explicit API to read the Xcode SDK DWARF attribute from compile units

2020-05-01 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl updated this revision to Diff 261603.

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

https://reviews.llvm.org/D79273

Files:
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/source/Core/Module.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
  lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -64,13 +64,13 @@
 
   auto triple = "x86_64-apple-macosx";
   YAMLModuleTester t(yamldata, triple);
-  auto module = t.GetModule();
   auto dwarf_unit_sp = t.GetDwarfUnit();
   auto *dwarf_cu = llvm::cast(dwarf_unit_sp.get());
   ASSERT_TRUE((bool)dwarf_cu);
-  ASSERT_TRUE((bool)dwarf_cu->GetSymbolFileDWARF().GetCompUnitForDWARFCompUnit(
-  *dwarf_cu));
-  XcodeSDK sdk = module->GetXcodeSDK();
+  SymbolFileDWARF &sym_file = dwarf_cu->GetSymbolFileDWARF();
+  CompUnitSP comp_unit = sym_file.GetCompileUnitAtIndex(0);
+  ASSERT_TRUE((bool)comp_unit.get());
+  XcodeSDK sdk = sym_file.ParseXcodeSDK(*comp_unit);
   ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
 }
 #endif
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
@@ -58,6 +58,9 @@
   lldb::LanguageType
   ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
 
+  lldb_private::XcodeSDK
+  ParseXcodeSDK(lldb_private::CompileUnit &comp_unit) override;
+
   size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
 
   bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -628,6 +628,15 @@
   return eLanguageTypeUnknown;
 }
 
+XcodeSDK
+SymbolFileDWARFDebugMap::ParseXcodeSDK(CompileUnit &comp_unit) {
+  std::lock_guard guard(GetModuleMutex());
+  SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
+  if (oso_dwarf)
+return oso_dwarf->ParseXcodeSDK(comp_unit);
+  return {};
+}
+
 size_t SymbolFileDWARFDebugMap::ParseFunctions(CompileUnit &comp_unit) {
   std::lock_guard guard(GetModuleMutex());
   SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -106,6 +106,9 @@
   lldb::LanguageType
   ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
 
+  lldb_private::XcodeSDK
+  ParseXcodeSDK(lldb_private::CompileUnit &comp_unit) override;
+
   size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
 
   bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -664,12 +664,6 @@
 const DWARFBaseDIE cu_die =
 dwarf_cu.GetNonSkeletonUnit().GetUnitDIEOnly();
 if (cu_die) {
-  if (const char *sdk =
-  cu_die.GetAttributeValueAsString(DW_AT_APPLE_sdk, nullptr)) {
-const char *sysroot =
-cu_die.GetAttributeValueAsString(DW_AT_LLVM_sysroot, "");
-module_sp->RegisterXcodeSDK(sdk, sysroot);
-  }
   FileSpec cu_file_spec(cu_die.GetName(), dwarf_cu.GetPathStyle());
   MakeAbsoluteAndRemap(cu_file_spec, dwarf_cu, module_sp);
 
@@ -778,6 +772,22 @@
 return eLanguageTypeUnknown;
 }
 
+XcodeSDK SymbolFileDWARF::ParseXcodeSDK(CompileUnit &comp_unit) {
+  std::lock_guard guard(GetModuleMutex());
+  if (DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit))
+if (ModuleSP module_sp = m_objfile_sp->GetModule())
+  if (const DWARFBaseDIE cu_die =
+  dwarf_cu->GetNonSkeletonUnit().GetUnitDIEOnly())
+if (const char *sdk =
+cu_die.GetAttributeValueAsString(DW_AT_APPLE_sdk, nullptr)) {
+  const char *sysroot =
+  cu_die.GetAttributeValueAsString(DW_AT_LLVM_sysroot, "");
+  module_sp->RegisterXcodeSDK(sdk, sysroot);
+