[Lldb-commits] [PATCH] D62934: [LanguageRuntime] Introdce LLVM-style casts

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

Implementing `classof` via an enum is the simplest and most common solution, 
but it is not the only thing possible. The central enum thingy is fine when all 
the subclasses are also defined centrally, but for a more distributed scenario 
like this one, it begins to smell, as now the `LanguageRuntime` class suddenly 
needs to be aware of all of its subclasses.

A way to implement that without the all-encompassing enum would be via 
something like:

  struct Runtime: {
  virtual bool isA(const void *ClassID) const { return ClassID == &ID; }
  static char ID;
  };
  
  ...
  
  struct DerivedRuntime: ParentRuntime {
  bool isA(const void *ClassID) const override { return ClassID == &ID || 
ParentRuntime::isA(ClassID); }
  
  static bool classof(const Runtime *R) { return R->isA(&ID); }
  static char ID;
  };

It takes a while to wrap your head around this, but what it basically does is 
use pointer equality instead of enum comparisons. Then, if you have a multi 
level hierarchy (like we have here), it uses the virtual `isA` function to 
check for subclasses instead of doing a range comparison: The desired target 
class type is captured in the `classof` call. Then the `|| Parent::isA` chain 
builds up a list of actual classes that this object is an instance of. If the 
captured type is found in this list, then the cast can proceed. You can see 
this in action in `llvm/Support/Error.h` (though the ErrorInfo class does not 
implement the `classof` method, because it wants to do casting differently.)

This is a bit more complex set up, but I think the overall result is worth it.


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

https://reviews.llvm.org/D62934



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


[Lldb-commits] [PATCH] D62943: DWARF: Simplify SymbolFileDWARF::GetDWARFCompileUnit

2019-06-06 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.
labath added reviewers: clayborg, JDevlieghere.
Herald added subscribers: jdoerfert, aprantl.

The DWARFCompileUnit is set as the "user data" of the lldb compile unit
directly in the constructor (see ParseCompileUnit).

This means that instead of going through unit indexes, we can just fetch
the DWARF unit directly from there.


https://reviews.llvm.org/D62943

Files:
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp


Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -608,15 +608,7 @@
   if (!comp_unit)
 return nullptr;
 
-  DWARFDebugInfo *info = DebugInfo();
-  if (info) {
-// The compile unit ID is the index of the DWARF unit.
-DWARFUnit *dwarf_cu = info->GetUnitAtIndex(comp_unit->GetID());
-if (dwarf_cu && dwarf_cu->GetUserData() == nullptr)
-  dwarf_cu->SetUserData(comp_unit);
-return dwarf_cu;
-  }
-  return nullptr;
+  return static_cast(comp_unit->GetUserData());
 }
 
 DWARFDebugRangesBase *SymbolFileDWARF::GetDebugRanges() {


Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -608,15 +608,7 @@
   if (!comp_unit)
 return nullptr;
 
-  DWARFDebugInfo *info = DebugInfo();
-  if (info) {
-// The compile unit ID is the index of the DWARF unit.
-DWARFUnit *dwarf_cu = info->GetUnitAtIndex(comp_unit->GetID());
-if (dwarf_cu && dwarf_cu->GetUserData() == nullptr)
-  dwarf_cu->SetUserData(comp_unit);
-return dwarf_cu;
-  }
-  return nullptr;
+  return static_cast(comp_unit->GetUserData());
 }
 
 DWARFDebugRangesBase *SymbolFileDWARF::GetDebugRanges() {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D62948: lit/Register: Avoid stdio in register write tests

2019-06-06 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.
labath added reviewers: mgorny, jgorbe.

The linux kernel doesn't guarantee that the data written to a pty will
instantly be available for reading on the other side. So what sometimes
happens here is that the inferior dumps all register values and exits,
lldb registers the exit, goes to read the inferior stdio, but the data
is not there.

Depending on how the machine is configured, the frequency of this
occurring can range from "almost never" to "pretty much always". This
patch side-steps the issue by redirecting the inferior output to a file.
Files have better synchronization properties (plenty of applications
depend on those), and this fixes the flakyness of these tests on
affected machines.


https://reviews.llvm.org/D62948

Files:
  lit/Register/x86-64-gp-write.test
  lit/Register/x86-64-write.test
  lit/Register/x86-64-ymm-write.test
  lit/Register/x86-gp-write.test
  lit/Register/x86-mm-xmm-write.test
  lit/Register/x86-ymm-write.test

Index: lit/Register/x86-ymm-write.test
===
--- lit/Register/x86-ymm-write.test
+++ lit/Register/x86-ymm-write.test
@@ -1,8 +1,10 @@
 # XFAIL: system-windows
-# REQUIRES: native && target-x86 && native-cpu-avx
-# RUN: %clangxx %p/Inputs/x86-ymm-write.cpp -o %t
+# REQUIRES: native && (target-x86 || target-x86_64) && native-cpu-avx
+# RUN: %clangxx -m32 %p/Inputs/x86-ymm-write.cpp -o %t
+# RUN: cd %T
 # RUN: %lldb -b -s %s %t | FileCheck %s
-process launch
+# RUN: FileCheck %s --check-prefix=INF ___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D62948: lit/Register: Avoid stdio in register write tests

2019-06-06 Thread Michał Górny via Phabricator via lldb-commits
mgorny added inline comments.



Comment at: lit/Register/x86-64-gp-write.test:6
 # RUN: %lldb -b -s %s %t | FileCheck %s
-process launch
+# RUN: FileCheck %s --check-prefix=INF https://reviews.llvm.org/D62948/new/

https://reviews.llvm.org/D62948



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


[Lldb-commits] [PATCH] D62948: lit/Register: Avoid stdio in register write tests

2019-06-06 Thread Pavel Labath via Phabricator via lldb-commits
labath marked an inline comment as done.
labath added inline comments.



Comment at: lit/Register/x86-64-gp-write.test:6
 # RUN: %lldb -b -s %s %t | FileCheck %s
-process launch
+# RUN: FileCheck %s --check-prefix=INF  Any reason not to use `%T` directly in paths rather than changing working 
> directory? I suppose either way is fine but I have a bad feeling that this 
> could be confusing in the long run.
%T doesn't work inside "process launch"


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

https://reviews.llvm.org/D62948



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


[Lldb-commits] [PATCH] D62948: lit/Register: Avoid stdio in register write tests

2019-06-06 Thread Michał Górny via Phabricator via lldb-commits
mgorny added a comment.

I'm sorry but could you also change other write tests (zmm?) to match.




Comment at: lit/Register/x86-64-gp-write.test:6
 # RUN: %lldb -b -s %s %t | FileCheck %s
-process launch
+# RUN: FileCheck %s --check-prefix=INF  mgorny wrote:
> > Any reason not to use `%T` directly in paths rather than changing working 
> > directory? I suppose either way is fine but I have a bad feeling that this 
> > could be confusing in the long run.
> %T doesn't work inside "process launch"
Right, makes sense.


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

https://reviews.llvm.org/D62948



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


[Lldb-commits] [PATCH] D62931: [lldb-server] Add setting to force 'g' packet use

2019-06-06 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

In D62931#1531965 , @labath wrote:

> Personally, I'm wondering whether we even need a setting for this. Running 
> the speed test command locally (i.e. the lowest latency we can possibly get), 
> I get results like:
>
>   (lldb) process plugin packet speed-test --count 10 --max-receive 2048
>   Testing sending 10 packets of various sizes:
>   ...
>   qSpeedTest(send=  4, recv=  0) in 0.788656771 s for 126797.88 
> packets/s (0.007886 ms per packet) with standard deviation of 0.001604 ms
>   qSpeedTest(send=  4, recv=  4) in 0.770005465 s for 129869.21 
> packets/s (0.007700 ms per packet) with standard deviation of 0.002120 ms
>   qSpeedTest(send=  4, recv=  8) in 0.895460367 s for 111674.40 
> packets/s (0.008954 ms per packet) with standard deviation of 0.002048 ms
>   qSpeedTest(send=  4, recv= 16) in 0.910367966 s for 109845.70 
> packets/s (0.009103 ms per packet) with standard deviation of 0.001886 ms
>   qSpeedTest(send=  4, recv= 32) in 0.889442623 s for 112429.96 
> packets/s (0.008894 ms per packet) with standard deviation of 0.001705 ms
>   qSpeedTest(send=  4, recv= 64) in 0.945124865 s for 105806.12 
> packets/s (0.009451 ms per packet) with standard deviation of 0.002349 ms
>   qSpeedTest(send=  4, recv=128) in 0.759995580 s for 131579.72 
> packets/s (0.007599 ms per packet) with standard deviation of 0.002971 ms
>   qSpeedTest(send=  4, recv=256) in 0.847535312 s for 117989.19 
> packets/s (0.008475 ms per packet) with standard deviation of 0.002629 ms
>   qSpeedTest(send=  4, recv=512) in 1.022377729 s for  97811.21 
> packets/s (0.010223 ms per packet) with standard deviation of 0.003248 ms
>   qSpeedTest(send=  4, recv=   1024) in 1.436389208 s for  69619.02 
> packets/s (0.014363 ms per packet) with standard deviation of 0.000688 ms
>   qSpeedTest(send=  4, recv=   2048) in 1.910557270 s for  52340.75 
> packets/s (0.019105 ms per packet) with standard deviation of 0.001194 ms
>   ...
>
>
> Now, if we assume that the `p` resonse is about 16 bytes long, and `g` 
> response is 2048, we find that the `g` packet is worth approximately two `p` 
> packets. And this is a local link, where it pretty much doesn't matter what 
> we do, as we're pumping 50k packets per second even in the slowest case. On 
> links with a non-negligible latency, the difference between the two packets 
> should be even smaller (though it might be nice to verify that).
>
> Combining this with the fact that we normally expedite all general purpose 
> registers (and so there won't be *any* packets if one is only reading those), 
> I would say that enabling this unconditionally is a pretty safe thing to do.
>
> Greg, Jason, what do you think?


There are so many various GDB remote servers and it is hard to say what will 
work for most people. Might be worth testing this with the setting set to true 
and false on a complex program single step on mac, linux and android and 
verifying that stepping speeds don't regress at all. Android tends to have 
hundreds of threads which usually makes it the slowest of all when stepping. If 
we don't see regressions, then I am fine with no setting. Every scenario I know 
of benefits from fewer packets with larger content (macOS, watchOS, linux, 
android) so I am fine just enabling it. Maybe it would be good to check what 
GDB does by default as it might tell us, via comments, why they don't use it if 
they did run into issues.

So I am ok with no setting as long as perf doesn't regress on complex steps and 
as long as GDB uses 'g' packets by default.




Comment at: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp:124
+ "The file that provides the description for remote target registers."},
+{"try-to-use-g-packet", OptionValue::eTypeBoolean, true, 0, nullptr, {},
+ "Specify if the server should try to use 'g' packets."}};

I would change the setting to just be "use-g-packet".


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D62931



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


[Lldb-commits] [PATCH] D62948: lit/Register: Avoid stdio in register write tests

2019-06-06 Thread Pavel Labath via Phabricator via lldb-commits
labath updated this revision to Diff 203370.
labath added a comment.

Update other tests too. I also forgot to mention that this enables the 32-bit
tests to run on 64-bit platforms too by explicitly compiling for 32-bit (-m32).


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

https://reviews.llvm.org/D62948

Files:
  lit/Register/x86-64-gp-write.test
  lit/Register/x86-64-write.test
  lit/Register/x86-64-xmm16-write.test
  lit/Register/x86-64-ymm-write.test
  lit/Register/x86-64-ymm16-write.test
  lit/Register/x86-64-zmm-write.test
  lit/Register/x86-gp-write.test
  lit/Register/x86-mm-xmm-write.test
  lit/Register/x86-ymm-write.test
  lit/Register/x86-zmm-write.test

Index: lit/Register/x86-zmm-write.test
===
--- lit/Register/x86-zmm-write.test
+++ lit/Register/x86-zmm-write.test
@@ -4,8 +4,10 @@
 # XFAIL: system-windows
 # REQUIRES: native && target-x86 && native-cpu-avx512f
 # RUN: %clangxx %p/Inputs/x86-zmm-write.cpp -o %t
+# RUN: cd %T
 # RUN: %lldb -b -s %s %t | FileCheck %s
-process launch
+# RUN: FileCheck %s --check-prefix INF ___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D62948: lit/Register: Avoid stdio in register write tests

2019-06-06 Thread Michał Górny via Phabricator via lldb-commits
mgorny added a comment.

In D62948#1532531 , @labath wrote:

> Update other tests too. I also forgot to mention that this enables the 32-bit
>  tests to run on 64-bit platforms too by explicitly compiling for 32-bit 
> (-m32).


I'm not sure if this is a good idea. I was thinking about it originally but I 
suspected it might cause failures on non-multilib systems.


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

https://reviews.llvm.org/D62948



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


[Lldb-commits] [PATCH] D62948: lit/Register: Avoid stdio in register write tests

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

In D62948#1532549 , @mgorny wrote:

> In D62948#1532531 , @labath wrote:
>
> > Update other tests too. I also forgot to mention that this enables the 
> > 32-bit
> >  tests to run on 64-bit platforms too by explicitly compiling for 32-bit 
> > (-m32).
>
>
> I'm not sure if this is a good idea. I was thinking about it originally but I 
> suspected it might cause failures on non-multilib systems.


Yeah, you're right. I'll revert that part. I did it mainly so I could test my 
changes there, though it would be nice to have these test run generally too, as 
these days I expect most people who debug 32-bit apps will be using a 64-bit 
debugger. I guess we'll one day need a "can-run-32-bit-code" feature, though 
I'm not sure how to go about implementing that. in cmake?


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

https://reviews.llvm.org/D62948



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


[Lldb-commits] [PATCH] D62948: lit/Register: Avoid stdio in register write tests

2019-06-06 Thread Pavel Labath via Phabricator via lldb-commits
labath updated this revision to Diff 203378.
labath added a comment.

revert the 32-on-64-bit part


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

https://reviews.llvm.org/D62948

Files:
  lit/Register/x86-64-gp-write.test
  lit/Register/x86-64-write.test
  lit/Register/x86-64-xmm16-write.test
  lit/Register/x86-64-ymm-write.test
  lit/Register/x86-64-ymm16-write.test
  lit/Register/x86-64-zmm-write.test
  lit/Register/x86-gp-write.test
  lit/Register/x86-mm-xmm-write.test
  lit/Register/x86-ymm-write.test
  lit/Register/x86-zmm-write.test

Index: lit/Register/x86-zmm-write.test
===
--- lit/Register/x86-zmm-write.test
+++ lit/Register/x86-zmm-write.test
@@ -4,8 +4,10 @@
 # XFAIL: system-windows
 # REQUIRES: native && target-x86 && native-cpu-avx512f
 # RUN: %clangxx %p/Inputs/x86-zmm-write.cpp -o %t
+# RUN: cd %T
 # RUN: %lldb -b -s %s %t | FileCheck %s
-process launch
+# RUN: FileCheck %s --check-prefix INF ___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D62948: lit/Register: Avoid stdio in register write tests

2019-06-06 Thread Michał Górny via Phabricator via lldb-commits
mgorny accepted this revision.
mgorny added a comment.
This revision is now accepted and ready to land.

LGTM, thanks.

I also hacked `-m32` for local testing. I generally agree this is a good thing 
to do but I don't really know how to reliably determine support for this. My 
main concern were C++ stdlib problems (which can be trivially worked around) 
but we also need to know whether the system has needed crt, libc… and kernel 
support for running 32-bit apps. Sounds like the only reliable way would be to 
crash-test this.


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

https://reviews.llvm.org/D62948



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


[Lldb-commits] [PATCH] D62501: Implement GetSharedLibraryInfoAddress

2019-06-06 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

Interesting, I actually don't think there's much to gain from turning this into 
an utility. Creating a NativeProcessELF makes sense to me (I already did it and 
have all the tests up and running as well) and putting it into POSIX also makes 
sense to me based on what you said.

The big motivation I can see with an utility would be to share the logic 
between client and server but in this particular situation I don't think that's 
an advantage. 
If you look at DYLDRendezvous we don't read the image info address there, this 
is done by the process, which in turn will actually use gdb server to get this 
data otherwise it will use the structures it already has parsed (the image 
section etc.) to access this.

The other part is to read the libraries' linked list. If we used a common 
function for this it would force us to create an interface to read memory 
making both client and server go for a common denominator that might not be 
optimal for neither of them.
I'm usually a bit wary of trying to generalize so much because of this. For 
example, today on the server we do a single read for the entire link_map 
structure and on the client we perform 5 ReadPointers.
Fwiw, I did think about this at the beginning (just like I did for the 
AuxVector, but that one is different because it's just parsing a block of data) 
and that was the reason why I didn't pursue it.

Having said this, I am a bit biased just because I've already implemented the 
NativeProcessELF solution and have very little cycles left to work on this (was 
hoping to land this week :D), but I do believe that having this on 
NativeProcess* will be better.

PS: I like your 2) point and it makes sense to me as well but I think that 
would be outside the scope of this stack of diffs (I'd be happy to work on this 
in the future).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62501



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


[Lldb-commits] [PATCH] D62501: Implement GetSharedLibraryInfoAddress

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

Ok, makes sense, I'm happy that you've considered the dynamic loader sharing 
tradeoffs already. Let's go with the NativeProcessELF thingy then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62501



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


[Lldb-commits] [PATCH] D62934: [LanguageRuntime] Introdce LLVM-style casts

2019-06-06 Thread Alex Langford via Phabricator via lldb-commits
xiaobai updated this revision to Diff 203420.
xiaobai added a comment.

Implement labath's suggestion


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

https://reviews.llvm.org/D62934

Files:
  include/lldb/Target/CPPLanguageRuntime.h
  include/lldb/Target/LanguageRuntime.h
  include/lldb/Target/ObjCLanguageRuntime.h
  source/Plugins/Language/ObjC/CF.cpp
  source/Plugins/Language/ObjC/Cocoa.cpp
  source/Plugins/Language/ObjC/NSArray.cpp
  source/Plugins/Language/ObjC/NSDictionary.cpp
  source/Plugins/Language/ObjC/NSError.cpp
  source/Plugins/Language/ObjC/NSException.cpp
  source/Plugins/Language/ObjC/NSIndexPath.cpp
  source/Plugins/Language/ObjC/NSSet.cpp
  source/Plugins/Language/ObjC/NSString.cpp
  
source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
  
source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h
  source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
  source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h
  source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
  source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h
  source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
  
source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
  
source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h
  source/Target/CPPLanguageRuntime.cpp
  source/Target/LanguageRuntime.cpp
  source/Target/ObjCLanguageRuntime.cpp
  source/Target/Process.cpp

Index: source/Target/Process.cpp
===
--- source/Target/Process.cpp
+++ source/Target/Process.cpp
@@ -1602,10 +1602,7 @@
   std::lock_guard guard(m_language_runtimes_mutex);
   LanguageRuntime *runtime =
   GetLanguageRuntime(eLanguageTypeObjC, retry_if_null);
-  if (!runtime)
-return nullptr;
-
-  return static_cast(runtime);
+  return llvm::cast_or_null(runtime);
 }
 
 bool Process::IsPossibleDynamicValue(ValueObject &in_value) {
Index: source/Target/ObjCLanguageRuntime.cpp
===
--- source/Target/ObjCLanguageRuntime.cpp
+++ source/Target/ObjCLanguageRuntime.cpp
@@ -28,6 +28,8 @@
 using namespace lldb;
 using namespace lldb_private;
 
+char ObjCLanguageRuntime::ID = 0;
+
 // Destructor
 ObjCLanguageRuntime::~ObjCLanguageRuntime() {}
 
Index: source/Target/LanguageRuntime.cpp
===
--- source/Target/LanguageRuntime.cpp
+++ source/Target/LanguageRuntime.cpp
@@ -17,6 +17,8 @@
 using namespace lldb;
 using namespace lldb_private;
 
+char LanguageRuntime::ID = 0;
+
 ExceptionSearchFilter::ExceptionSearchFilter(const lldb::TargetSP &target_sp,
  lldb::LanguageType language,
  bool update_module_list)
Index: source/Target/CPPLanguageRuntime.cpp
===
--- source/Target/CPPLanguageRuntime.cpp
+++ source/Target/CPPLanguageRuntime.cpp
@@ -35,6 +35,8 @@
 
 static ConstString g_this = ConstString("this");
 
+char CPPLanguageRuntime::ID = 0;
+
 // Destructor
 CPPLanguageRuntime::~CPPLanguageRuntime() {}
 
Index: source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h
===
--- source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h
+++ source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h
@@ -314,6 +314,16 @@
 
   static lldb_private::ConstString GetPluginNameStatic();
 
+  static char ID;
+
+  bool isA(const void *ClassID) const override {
+return ClassID == &ID || CPPLanguageRuntime::isA(ClassID);
+  }
+
+  static bool classof(const LanguageRuntime *runtime) {
+return runtime->isA(&ID);
+  }
+
   static bool IsRenderScriptModule(const lldb::ModuleSP &module_sp);
 
   static ModuleKind GetModuleKind(const lldb::ModuleSP &module_sp);
Index: source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
===
--- source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
+++ source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
@@ -48,6 +48,8 @@
 
 #define FMT_COORD "(%" PRIu32 ", %" PRIu32 ", %" PRIu32 ")"
 
+char RenderScriptRuntime::ID = 0;
+
 namespace {
 
 // The empirical_type adds a basic level of validation to arbitrary data
@@ -1123,9 +1125,9 @@
   RuntimeHook *hook = (RuntimeHook *)baton;
   ExecutionContext exe_ctx(ctx->exe_ctx_ref);
 
-  RenderScriptRuntime *lang_rt =
-  (RenderScriptRuntime *)exe_ctx.GetProcessP

[Lldb-commits] [PATCH] D62948: lit/Register: Avoid stdio in register write tests

2019-06-06 Thread Jorge Gorbe Moya via Phabricator via lldb-commits
jgorbe added a comment.

About %T not working for "process launch", what about something like `RUN: 
%lldb -b --one-line-before-file "process launch --stdout %T/x86-zmm-write.out" 
-s %s %t` and then FileCheck-ing?


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

https://reviews.llvm.org/D62948



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


[Lldb-commits] [PATCH] D62980: [lldb] Replace "127.0.0.1" with "localhost" in GDBRemoteCommunication.cpp

2019-06-06 Thread Jorge Gorbe Moya via Phabricator via lldb-commits
jgorbe created this revision.
jgorbe added reviewers: clayborg, labath.

127.0.0.1 doesn't work in machines configured with IPv6-only networking.


https://reviews.llvm.org/D62980

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


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -1078,7 +1078,7 @@
   } else {
 // No host and port given, so lets listen on our end and make the
 // debugserver connect to us..
-error = StartListenThread("127.0.0.1", 0);
+error = StartListenThread("localhost", 0);
 if (error.Fail()) {
   if (log)
 log->Printf("GDBRemoteCommunication::%s() unable to start listen "
@@ -1093,7 +1093,7 @@
 uint16_t port_ = 
connection->GetListeningPort(std::chrono::seconds(10));
 if (port_ > 0) {
   char port_cstr[32];
-  snprintf(port_cstr, sizeof(port_cstr), "127.0.0.1:%i", port_);
+  snprintf(port_cstr, sizeof(port_cstr), "localhost:%i", port_);
   // Send the host and port down that debugserver and specify an option
   // so that it connects back to the port we are listening to in this
   // process
@@ -1102,7 +1102,7 @@
   if (port)
 *port = port_;
 } else {
-  error.SetErrorString("failed to bind to port 0 on 127.0.0.1");
+  error.SetErrorString("failed to bind to port 0 on localhost");
   if (log)
 log->Printf("GDBRemoteCommunication::%s() failed: %s", 
__FUNCTION__,
 error.AsCString());
@@ -1269,7 +1269,7 @@
   const int backlog = 5;
   TCPSocket listen_socket(true, child_processes_inherit);
   if (llvm::Error error =
-  listen_socket.Listen("127.0.0.1:0", backlog).ToError())
+  listen_socket.Listen("localhost:0", backlog).ToError())
 return error;
 
   Socket *accept_socket;
@@ -1278,7 +1278,7 @@
 
   llvm::SmallString<32> remote_addr;
   llvm::raw_svector_ostream(remote_addr)
-  << "connect://127.0.0.1:" << listen_socket.GetLocalPortNumber();
+  << "connect://localhost:" << listen_socket.GetLocalPortNumber();
 
   std::unique_ptr conn_up(
   new ConnectionFileDescriptor());


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -1078,7 +1078,7 @@
   } else {
 // No host and port given, so lets listen on our end and make the
 // debugserver connect to us..
-error = StartListenThread("127.0.0.1", 0);
+error = StartListenThread("localhost", 0);
 if (error.Fail()) {
   if (log)
 log->Printf("GDBRemoteCommunication::%s() unable to start listen "
@@ -1093,7 +1093,7 @@
 uint16_t port_ = connection->GetListeningPort(std::chrono::seconds(10));
 if (port_ > 0) {
   char port_cstr[32];
-  snprintf(port_cstr, sizeof(port_cstr), "127.0.0.1:%i", port_);
+  snprintf(port_cstr, sizeof(port_cstr), "localhost:%i", port_);
   // Send the host and port down that debugserver and specify an option
   // so that it connects back to the port we are listening to in this
   // process
@@ -1102,7 +1102,7 @@
   if (port)
 *port = port_;
 } else {
-  error.SetErrorString("failed to bind to port 0 on 127.0.0.1");
+  error.SetErrorString("failed to bind to port 0 on localhost");
   if (log)
 log->Printf("GDBRemoteCommunication::%s() failed: %s", __FUNCTION__,
 error.AsCString());
@@ -1269,7 +1269,7 @@
   const int backlog = 5;
   TCPSocket listen_socket(true, child_processes_inherit);
   if (llvm::Error error =
-  listen_socket.Listen("127.0.0.1:0", backlog).ToError())
+  listen_socket.Listen("localhost:0", backlog).ToError())
 return error;
 
   Socket *accept_socket;
@@ -1278,7 +1278,7 @@
 
   llvm::SmallString<32> remote_addr;
   llvm::raw_svector_ostream(remote_addr)
-  << "connect://127.0.0.1:" << listen_socket.GetLocalPortNumber();
+  << "connect://localhost:" << listen_socket.GetLocalPortNumber();
 
   std::unique_ptr conn_up(
   new ConnectionFileDescriptor());
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D62980: [lldb] Replace "127.0.0.1" with "localhost" in GDBRemoteCommunication.cpp

2019-06-06 Thread Jorge Gorbe Moya via Phabricator via lldb-commits
jgorbe added a comment.

Hm, I just realized I'm undoing https://reviews.llvm.org/D58883.

I'll withdraw this patch and upload it again once I'm sure I'm taking that into 
account.


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

https://reviews.llvm.org/D62980



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


[Lldb-commits] [PATCH] D62812: [llvm] [CodeView] Move Triple::ArchType → CPUType mapping from LLDB

2019-06-06 Thread Michael Trent via Phabricator via lldb-commits
mtrent added a reviewer: friss.
mtrent added a comment.

I am not familiar with lldb or with the DebugView library, so I am pulling in 
Fred Riss for this review. Thanks!


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

https://reviews.llvm.org/D62812



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


[Lldb-commits] [PATCH] D62501: Implement GetSharedLibraryInfoAddress

2019-06-06 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 203476.
aadsm added a comment.
Herald added a subscriber: emaste.

This creates a NativeProcessELF to deal with ELF specific things. The 
NativeProcessLinux now extends this one.
Added a test case for the GetAuxValue and GetELFImageInfoAddress. I refactored 
NativeProcessTestUtils to reuse that code.
I also addressed other comments on the review.

Note about the tests: I only have one test for the GetELFImageInfoAddress that 
follows the 32bit version and also makes sure we correctly read the load bias. 
Tbh I'm not sure if this is enough but should be easy to add more cases now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62501

Files:
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
  lldb/source/Plugins/Process/POSIX/CMakeLists.txt
  lldb/source/Plugins/Process/POSIX/NativeProcessELF.cpp
  lldb/source/Plugins/Process/POSIX/NativeProcessELF.h
  lldb/unittests/Host/NativeProcessProtocolTest.cpp
  lldb/unittests/Host/NativeProcessTestUtils.h
  lldb/unittests/Process/CMakeLists.txt
  lldb/unittests/Process/POSIX/CMakeLists.txt
  lldb/unittests/Process/POSIX/NativeProcessELFTest.cpp

Index: lldb/unittests/Process/POSIX/NativeProcessELFTest.cpp
===
--- /dev/null
+++ lldb/unittests/Process/POSIX/NativeProcessELFTest.cpp
@@ -0,0 +1,133 @@
+//===-- NativeProcessELFTest.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 "../../Host/NativeProcessTestUtils.h"
+
+#include "Plugins/Process/POSIX/NativeProcessELF.h"
+#include "Plugins/Process/Utility/AuxVector.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataEncoder.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+
+using namespace lldb_private;
+using namespace lldb;
+using namespace testing;
+
+namespace {
+class MockProcessELF : public MockProcess {
+public:
+  using MockProcess::MockProcess;
+  using NativeProcessELF::GetAuxValue;
+  using NativeProcessELF::GetELFImageInfoAddress;
+};
+
+std::unique_ptr CreateAuxvData(
+MockProcessELF &process,
+std::vector> auxv_data) {
+  auto addr_size = process.GetAddressByteSize();
+  DataBufferSP buffer_sp(
+  new DataBufferHeap(auxv_data.size() * addr_size * 2, 0));
+  DataEncoder encoder(buffer_sp, process.GetByteOrder(), addr_size);
+  uint32_t offset = 0;
+  for (auto &pair : auxv_data) {
+offset = encoder.PutAddress(offset, pair.first);
+offset = encoder.PutAddress(offset, pair.second);
+  }
+  llvm::StringRef stringref((const char *)buffer_sp->GetBytes(),
+buffer_sp->GetByteSize());
+  return llvm::MemoryBuffer::getMemBufferCopy(stringref, "");
+}
+} // namespace
+
+TEST(NativeProcessELFTest, GetAuxValue) {
+  NiceMock DummyDelegate;
+  MockProcessELF process(DummyDelegate, ArchSpec("i386-pc-linux"));
+
+  uint32_t phdr_addr = 0x42;
+  auto auxv_buffer = CreateAuxvData(
+  process, {std::make_pair(AuxVector::AUXV_AT_PHDR, phdr_addr)});
+  EXPECT_CALL(process, GetAuxvData())
+  .WillOnce(Return(ByMove(std::move(auxv_buffer;
+
+  llvm::Optional maybe_phdr_addr =
+  process.GetAuxValue(AuxVector::AUXV_AT_PHDR);
+  ASSERT_NE(llvm::None, maybe_phdr_addr);
+  ASSERT_EQ(phdr_addr, *maybe_phdr_addr);
+}
+
+TEST(NativeProcessELFTest, GetELFImageInfoAddress) {
+  NiceMock DummyDelegate;
+  MockProcessELF process(DummyDelegate, ArchSpec("i386-pc-linux"));
+
+  uint32_t load_base = 0x1000;
+  uint32_t info_addr = 0x3741;
+  uint32_t phdr_addr = load_base + sizeof(llvm::ELF::Elf32_Ehdr);
+
+  auto auxv_buffer = CreateAuxvData(
+  process,
+  {std::make_pair(AuxVector::AUXV_AT_PHDR, phdr_addr),
+   std::make_pair(AuxVector::AUXV_AT_PHENT, sizeof(llvm::ELF::Elf32_Phdr)),
+   std::make_pair(AuxVector::AUXV_AT_PHNUM, 2)});
+  EXPECT_CALL(process, GetAuxvData())
+  .WillOnce(Return(ByMove(std::move(auxv_buffer;
+
+  // We're going to set up a fake memory with 2 program headers and 1 entry in
+  // the dynamic section.
+  // For simplicity sake they will be consecutive in memory:
+  // ++
+  // | PT_PHDR|
+  // ++
+  // | PT_DYNAMIC |
+  // ++
+  // | DT_DEBUG   |
+  // ++
+  uint8_t mem_data[2 * sizeof(llvm::ELF::Elf32_Phdr) +
+   sizeof(llvm::ELF::Elf32_Dyn)];
+  DataEncoder mem_encoder((void *)&mem_data[0], sizeof(mem_data),
+  process.GetByteOrd

[Lldb-commits] [PATCH] D62502: Implement xfer:libraries-svr4:read packet

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

No longer depend on libxml2 to quote the attribute value


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62502

Files:
  lldb/include/lldb/Host/XML.h
  lldb/include/lldb/Host/common/NativeProcessProtocol.h
  lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
  lldb/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/Makefile
  
lldb/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/TestGdbRemoteLibrariesSvr4Support.py
  lldb/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/main.cpp
  
lldb/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_a.cpp
  
lldb/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_a.mk
  
lldb/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_b_quote.cpp
  
lldb/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_b_quote.mk
  lldb/source/Host/common/XML.cpp
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  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
@@ -25,6 +25,7 @@
 #include "lldb/Host/Host.h"
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Host/PosixApi.h"
+#include "lldb/Host/XML.h"
 #include "lldb/Host/common/NativeProcessProtocol.h"
 #include "lldb/Host/common/NativeRegisterContext.h"
 #include "lldb/Host/common/NativeThreadProtocol.h"
@@ -2765,6 +2766,24 @@
 return std::move(*buffer_or_error);
   }
 
+  if (object == "libraries-svr4") {
+auto library_list = m_debugged_process_up->GetLoadedSVR4Libraries();
+if (!library_list)
+  return library_list.takeError();
+
+StreamString response;
+response.Printf("");
+for (auto const &library : *library_list) {
+  response.Printf("", library.ld_addr);
+}
+response.Printf("");
+return MemoryBuffer::getMemBufferCopy(response.GetString(), __FUNCTION__);
+  }
+
   return llvm::make_error(
   "Xfer object not supported");
 }
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
@@ -826,6 +826,9 @@
   response.PutCString(";QPassSignals+");
   response.PutCString(";qXfer:auxv:read+");
 #endif
+#if defined(__linux__)
+  response.PutCString(";qXfer:libraries-svr4:read+");
+#endif
 
   return SendPacketNoLock(response.GetString());
 }
Index: lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
===
--- lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
+++ lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
@@ -76,6 +76,9 @@
 
   Status DeallocateMemory(lldb::addr_t addr) override;
 
+  llvm::Expected>
+  GetLoadedSVR4Libraries() override;
+
   size_t UpdateThreads() override;
 
   const ArchSpec &GetArchitecture() const override { return m_arch; }
@@ -127,6 +130,10 @@
   llvm::Expected>
   GetSoftwareBreakpointTrapOpcode(size_t size_hint) override;
 
+  template 
+  Status ReadSVR4LibraryInfo(lldb::addr_t link_map_addr, SVR4LibraryInfo &info,
+ lldb::addr_t &next);
+
 private:
   MainLoop::SignalHandleUP m_sigchld_handle;
   ArchSpec m_arch;
Index: lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
===
--- lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -2078,3 +2078,74 @@
 
   return error;
 }
+
+template 
+Status NativeProcessLinux::ReadSVR4LibraryInfo(lldb::addr_t link_map_addr,
+   SVR4LibraryInfo &info,
+   lldb::addr_t &next) {
+  ELFLinkMap link_map;
+  size_t bytes_read;
+  auto error =
+  ReadMemory(link_map_addr, &link_map, sizeof(link_map), bytes_read);
+  if (!error.Success())
+return error;
+
+  char name_buffer[PATH_MAX];
+  error = ReadMemory(link_map.l_name, &name_buffer, sizeof(name_buffer),
+ bytes_read);
+  if (!error.Success())
+return error;
+  name_buffer[PATH_MAX - 1] = '\0';
+  info.name = std::string(name_buffer);
+  info.link_map = link_map_addr;
+  info.base_addr = link_map.l_a

[Lldb-commits] [PATCH] D62502: Implement xfer:libraries-svr4:read packet

2019-06-06 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

@labath that's a really good point. I've talked with @clayborg  and @xiaobai 
about this and we decided it would be fine to do it manually as well so I added 
a `XMLEncodeAttributeValue` function to make it happen. I'm not 100% sure about 
its implementation.. Should I use a StreamString instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62502



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


[Lldb-commits] [PATCH] D62797: [Expression] Add PersistentExpressionState::GetCompilerTypeFromPersistentDecl

2019-06-06 Thread Alex Langford via Phabricator via lldb-commits
xiaobai updated this revision to Diff 203483.
xiaobai added a comment.

Renamed `clang_ast_type` to `compiler_type` to be more general.
Allow for disambiguating by language with the flag `-x` or `--language`.


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

https://reviews.llvm.org/D62797

Files:
  include/lldb/Expression/ExpressionVariable.h
  
packages/Python/lldbsuite/test/expression_command/persistent_types/TestPersistentTypes.py
  source/Commands/CMakeLists.txt
  source/Commands/CommandObjectMemory.cpp
  source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
  source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h

Index: source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
===
--- source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
+++ source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
@@ -50,6 +50,9 @@
 return "$";
   }
 
+  llvm::Optional
+  GetCompilerTypeFromPersistentDecl(ConstString type_name) override;
+
   void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl);
 
   clang::NamedDecl *GetPersistentDecl(ConstString name);
Index: source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
===
--- source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
@@ -9,6 +9,7 @@
 #include "ClangPersistentVariables.h"
 
 #include "lldb/Core/Value.h"
+#include "lldb/Symbol/ClangASTContext.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Utility/DataExtractor.h"
 #include "lldb/Utility/Log.h"
@@ -52,6 +53,21 @@
 m_next_persistent_variable_id--;
 }
 
+llvm::Optional
+ClangPersistentVariables::GetCompilerTypeFromPersistentDecl(
+ConstString type_name) {
+  CompilerType compiler_type;
+  if (clang::TypeDecl *tdecl = llvm::dyn_cast_or_null(
+  GetPersistentDecl(type_name))) {
+compiler_type.SetCompilerType(
+ClangASTContext::GetASTContext(&tdecl->getASTContext()),
+reinterpret_cast(
+const_cast(tdecl->getTypeForDecl(;
+return compiler_type;
+  }
+  return llvm::None;
+}
+
 void ClangPersistentVariables::RegisterPersistentDecl(ConstString name,
   clang::NamedDecl *decl) {
   m_persistent_decls.insert(
Index: source/Commands/CommandObjectMemory.cpp
===
--- source/Commands/CommandObjectMemory.cpp
+++ source/Commands/CommandObjectMemory.cpp
@@ -6,16 +6,14 @@
 //
 //===--===//
 
-#include "clang/AST/Decl.h"
-
 #include "CommandObjectMemory.h"
-#include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/DumpDataExtractor.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/Section.h"
 #include "lldb/Core/ValueObjectMemory.h"
 #include "lldb/DataFormatters/ValueObjectPrinter.h"
+#include "lldb/Expression/ExpressionVariable.h"
 #include "lldb/Host/OptionParser.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
@@ -23,15 +21,17 @@
 #include "lldb/Interpreter/OptionGroupFormat.h"
 #include "lldb/Interpreter/OptionGroupOutputFile.h"
 #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
+#include "lldb/Interpreter/OptionValueLanguage.h"
 #include "lldb/Interpreter/OptionValueString.h"
 #include "lldb/Interpreter/Options.h"
-#include "lldb/Symbol/ClangASTContext.h"
 #include "lldb/Symbol/SymbolFile.h"
 #include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/Language.h"
 #include "lldb/Target/MemoryHistory.h"
 #include "lldb/Target/MemoryRegionInfo.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
 #include "lldb/Target/Thread.h"
 #include "lldb/Utility/Args.h"
 #include "lldb/Utility/DataBufferHeap.h"
@@ -51,7 +51,9 @@
   {LLDB_OPT_SET_1, false, "num-per-line", 'l', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeNumberPerLine, "The number of items per line to display." },
   {LLDB_OPT_SET_2, false, "binary",   'b', OptionParser::eNoArgument,   nullptr, {}, 0, eArgTypeNone,  "If true, memory will be saved as binary. If false, the memory is saved save as an ASCII dump that "
 "uses the format, size, count and number per line settings." },
-  {LLDB_OPT_SET_3, true , "type", 't', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeNone,  "The name of a type to view memory as." },
+  {LLDB_OPT_SET_3 |
+   LLDB_OPT_SET_4, true , "type", 't', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeName,  "The name of a t