[Lldb-commits] [PATCH] D35760: Expose active and available platform lists via SBDebugger API

2017-07-22 Thread Vadim Macagon via Phabricator via lldb-commits
enlight updated this revision to Diff 107789.
enlight added a comment.

Update 
packages/Python/lldbsuite/test/python_api/default-constructor/sb_debugger.py


Repository:
  rL LLVM

https://reviews.llvm.org/D35760

Files:
  include/lldb/API/SBDebugger.h
  include/lldb/API/SBStructuredData.h
  packages/Python/lldbsuite/test/functionalities/platform/TestPlatformPython.py
  packages/Python/lldbsuite/test/python_api/default-constructor/sb_debugger.py
  scripts/interface/SBDebugger.i
  source/API/SBDebugger.cpp

Index: source/API/SBDebugger.cpp
===
--- source/API/SBDebugger.cpp
+++ source/API/SBDebugger.cpp
@@ -26,6 +26,7 @@
 #include "lldb/API/SBSourceManager.h"
 #include "lldb/API/SBStream.h"
 #include "lldb/API/SBStringList.h"
+#include "lldb/API/SBStructuredData.h"
 #include "lldb/API/SBTarget.h"
 #include "lldb/API/SBThread.h"
 #include "lldb/API/SBTypeCategory.h"
@@ -37,8 +38,10 @@
 #include "lldb/API/SystemInitializerFull.h"
 
 #include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Core/State.h"
 #include "lldb/Core/StreamFile.h"
+#include "lldb/Core/StructuredDataImpl.h"
 #include "lldb/DataFormatters/DataVisualization.h"
 #include "lldb/Initialization/SystemLifetimeManager.h"
 #include "lldb/Interpreter/Args.h"
@@ -774,6 +777,67 @@
 sb_platform.GetName());
 }
 
+uint32_t SBDebugger::GetNumPlatforms() {
+  if (m_opaque_sp) {
+// No need to lock, the platform list is thread safe
+return m_opaque_sp->GetPlatformList().GetSize();
+  }
+  return 0;
+}
+
+SBPlatform SBDebugger::GetPlatformAtIndex(uint32_t idx) {
+  SBPlatform sb_platform;
+  if (m_opaque_sp) {
+// No need to lock, the platform list is thread safe
+sb_platform.SetSP(m_opaque_sp->GetPlatformList().GetAtIndex(idx));
+  }
+  return sb_platform;
+}
+
+uint32_t SBDebugger::GetNumAvailablePlatforms() {
+  uint32_t idx = 0;
+  while (true) {
+if (!PluginManager::GetPlatformPluginNameAtIndex(idx)) {
+  break;
+}
+++idx;
+  }
+  // +1 for the host platform, which should always appear first in the list.
+  return idx + 1;
+}
+
+SBStructuredData SBDebugger::GetAvailablePlatformAtIndex(uint32_t idx) {
+  SBStructuredData data;
+  auto platform_dict = llvm::make_unique();
+  llvm::StringRef name_str("name"), desc_str("description");
+
+  if (idx == 0) {
+PlatformSP host_platform_sp(Platform::GetHostPlatform());
+platform_dict->AddStringItem(
+name_str, host_platform_sp->GetPluginName().GetStringRef());
+platform_dict->AddStringItem(
+desc_str, llvm::StringRef(host_platform_sp->GetDescription()));
+  } else if (idx > 0) {
+const char *plugin_name =
+PluginManager::GetPlatformPluginNameAtIndex(idx - 1);
+if (!plugin_name) {
+  return data;
+}
+platform_dict->AddStringItem(name_str, llvm::StringRef(plugin_name));
+
+const char *plugin_desc =
+PluginManager::GetPlatformPluginDescriptionAtIndex(idx - 1);
+if (!plugin_desc) {
+  return data;
+}
+platform_dict->AddStringItem(desc_str, llvm::StringRef(plugin_desc));
+  }
+
+  data.m_impl_up->SetObjectSP(
+  StructuredData::ObjectSP(platform_dict.release()));
+  return data;
+}
+
 void SBDebugger::DispatchInput(void *baton, const void *data, size_t data_len) {
   DispatchInput(data, data_len);
 }
Index: scripts/interface/SBDebugger.i
===
--- scripts/interface/SBDebugger.i
+++ scripts/interface/SBDebugger.i
@@ -247,6 +247,30 @@
 void
 SetSelectedPlatform(lldb::SBPlatform &platform);
 
+%feature("docstring",
+"Get the number of currently active platforms."
+) GetNumPlatforms;
+uint32_t
+GetNumPlatforms ();
+
+%feature("docstring",
+"Get one of the currently active platforms."
+) GetPlatformAtIndex;
+lldb::SBPlatform
+GetPlatformAtIndex (uint32_t idx);
+
+%feature("docstring",
+"Get the number of available platforms."
+) GetNumAvailablePlatforms;
+uint32_t
+GetNumAvailablePlatforms ();
+
+%feature("docstring",
+"Get the name and description of one of the available platforms."
+) GetAvailablePlatformAtIndex;
+lldb::SBStructuredData
+GetAvailablePlatformAtIndex (uint32_t idx);
+
 lldb::SBSourceManager
 GetSourceManager ();
 
Index: packages/Python/lldbsuite/test/python_api/default-constructor/sb_debugger.py
===
--- packages/Python/lldbsuite/test/python_api/default-constructor/sb_debugger.py
+++ packages/Python/lldbsuite/test/python_api/default-constructor/sb_debugger.py
@@ -30,6 +30,10 @@
 obj.FindTargetWithFileAndArch("a.out", "arm")
 obj.GetNumTargets()
 obj.GetSelectedTarget()
+obj.GetNumPlatforms()
+obj.GetPlatformAtIndex(0x)
+obj.GetNumAvailablePlatforms()
+obj.GetAvailablePlatformAtIndex(0x)
 obj.GetSourceManager()

[Lldb-commits] [PATCH] D35760: Expose active and available platform lists via SBDebugger API

2017-07-22 Thread Jim Ingham via Phabricator via lldb-commits
jingham requested changes to this revision.
jingham added a comment.
This revision now requires changes to proceed.

This seems fine.  I have a little quibble with the name, inline, and a testing 
suggestion.




Comment at: 
packages/Python/lldbsuite/test/functionalities/platform/TestPlatformPython.py:32-33
+# the platform list.
+self.dbg.SetCurrentPlatform('remote-linux')
+remote_platform = self.dbg.GetSelectedPlatform()
+self.assertTrue(remote_platform.IsValid())

Instead of relying on there always being a remote-linux platform, couldn't you 
just grab a platform from the Available Platform list make sure it isn't the 
host platform, and add that?  


Repository:
  rL LLVM

https://reviews.llvm.org/D35760



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


Re: [Lldb-commits] [PATCH] D35740: Fix PR33875 by distinguishing between DWO and clang modules

2017-07-22 Thread David Blaikie via lldb-commits
On Fri, Jul 21, 2017 at 6:14 PM Jim Ingham  wrote:

> Not at present, but you presumably know more about this than I do.  Part
> of the point of Greg's extracting the DWARF parser from lldb and making it
> into it's own library in llvm was precisely so that somebody could then
> write a simple wrapper tool that would poke it with not necessarily
> complete but interesting canned bits of DWARF and see that it does the
> right thing.  I thought you were involved with the reviews for that work?


Yep yep - though not necessarily clear on the bigger picture goals in terms
of which components were going where in the long term.


>   I was not paying attention to the details of that effort as DWARF
> parsing's not really my thing.
>
> Anyway, the extraction of the DWARF parser was Greg's last act before
> leaving Apple, and the project stalled at that point.  I don't imagine he
> could have gotten that code into llvm without some testing, so the kind of
> test you are thinking of should be done using whatever mechanism you guys
> devised for the new llvm dwarf parser.


Adrian - any chance something like the DwarfGenerator stuff in LLVM could
be used to test this code?


> Of course, it's less interesting to test the llvm version of the DWARF
> parser if lldb's not using it, so for that to be directly relevant here
> that piece of work would need to be done.
>

Perhaps - or reusing the same testing approach without that. Though I think
this particular failure/fix was in a higher/lower different layer than the
pure parsing stuff in LLVM, but I could be wrong - there's sufficient
divergence it's not obvious from a few class names, etc, to tell how much
overlap (& where) there is.


>
> Jim
>
>
>
> > On Jul 21, 2017, at 5:51 PM, David Blaikie  wrote:
> >
> >
> >
> > On Fri, Jul 21, 2017 at 4:05 PM Greg Clayton via Phabricator <
> revi...@reviews.llvm.org> wrote:
> > clayborg accepted this revision.
> > clayborg added a comment.
> >
> > Looks like there already is a test case that was failing as Jim
> mentioned. Accepting based on that.
> >
> > Ah, I was thinking more a test that would've failed when LLDB regressed
> (regardless of whether Clang was still producing this DWARF or not) - does
> LLDB have tests like that? (either binary, asm, or some other terse way of
> writing DWARF directly to test "does LLDB do the right thing with this
> DWARF" sort of tests?)
> >
> >
> >
> > https://reviews.llvm.org/D35740
> >
> >
> >
>
>
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D33213: Use socketpair on all Unix platforms

2017-07-22 Thread Demi Marie Obenour via Phabricator via lldb-commits
DemiMarie updated this revision to Diff 107805.
DemiMarie added a comment.

Fix connection when there is no host:port


https://reviews.llvm.org/D33213

Files:
  source/Host/posix/ConnectionFileDescriptorPosix.cpp
  tools/lldb-server/lldb-gdbserver.cpp

Index: tools/lldb-server/lldb-gdbserver.cpp
===
--- tools/lldb-server/lldb-gdbserver.cpp
+++ tools/lldb-server/lldb-gdbserver.cpp
@@ -106,6 +106,7 @@
// than llgs listening for a connection from address on port.
 {"setsid", no_argument, NULL,
  'S'}, // Call setsid() to make llgs run in its own session.
+{"fd", required_argument, NULL, 'F'},
 {NULL, 0, NULL, 0}};
 
 //--
@@ -132,13 +133,13 @@
   "[--log-file log-file-name] "
   "[--log-channels log-channel-list] "
   "[--setsid] "
+  "[--fd file-descriptor]"
   "[--named-pipe named-pipe-path] "
   "[--native-regs] "
   "[--attach pid] "
   "[[HOST]:PORT] "
   "[-- PROGRAM ARG1 ARG2 ...]\n",
   progname, subcommand);
-  exit(0);
 }
 
 void handle_attach_to_pid(GDBRemoteCommunicationServerLLGS &gdb_server,
@@ -232,10 +233,31 @@
  GDBRemoteCommunicationServerLLGS &gdb_server,
  bool reverse_connect, const char *const host_and_port,
  const char *const progname, const char *const subcommand,
- const char *const named_pipe_path, int unnamed_pipe_fd) {
+ const char *const named_pipe_path, int unnamed_pipe_fd,
+ int connection_fd) {
   Status error;
 
-  if (host_and_port && host_and_port[0]) {
+  std::unique_ptr connection_up;
+  if (connection_fd != -1) {
+// Build the connection string.
+char connection_url[512];
+snprintf(connection_url, sizeof(connection_url), "fd://%d", connection_fd);
+
+// Create the connection.
+connection_up.reset(new ConnectionFileDescriptor);
+auto connection_result = connection_up->Connect(connection_url, &error);
+if (connection_result != eConnectionStatusSuccess) {
+  fprintf(stderr, "error: failed to connect to client at '%s' "
+  "(connection status: %d)",
+  connection_url, static_cast(connection_result));
+  exit(-1);
+}
+if (error.Fail()) {
+  fprintf(stderr, "error: failed to connect to client at '%s': %s",
+  connection_url, error.AsCString());
+  exit(-1);
+}
+  } else if (host_and_port && host_and_port[0]) {
 // Parse out host and port.
 std::string final_host_and_port;
 std::string connection_host;
@@ -255,7 +277,6 @@
   connection_portno = StringConvert::ToUInt32(connection_port.c_str(), 0);
 }
 
-std::unique_ptr connection_up;
 
 if (reverse_connect) {
   // llgs will connect to the gdb-remote client.
@@ -328,14 +349,14 @@
   }
   connection_up.reset(conn);
 }
-error = gdb_server.InitializeConnection(std::move(connection_up));
-if (error.Fail()) {
-  fprintf(stderr, "Failed to initialize connection: %s\n",
-  error.AsCString());
-  exit(-1);
-}
-printf("Connection established.\n");
   }
+  error = gdb_server.InitializeConnection(std::move(connection_up));
+  if (error.Fail()) {
+fprintf(stderr, "Failed to initialize connection: %s\n",
+error.AsCString());
+exit(-1);
+  }
+  printf("Connection established.\n");
 }
 
 //--
@@ -364,6 +385,7 @@
   log_channels; // e.g. "lldb process threads:gdb-remote default:linux all"
   int unnamed_pipe_fd = -1;
   bool reverse_connect = false;
+  int connection_fd;
 
   // ProcessLaunchInfo launch_info;
   ProcessAttachInfo attach_info;
@@ -413,6 +435,10 @@
   reverse_connect = true;
   break;
 
+case 'F':
+  connection_fd = StringConvert::ToUInt32(optarg, -1);
+  break;
+
 #ifndef _WIN32
 case 'S':
   // Put llgs into a new session. Terminals group processes
@@ -472,7 +498,8 @@
   argc -= optind;
   argv += optind;
 
-  if (argc == 0) {
+  if (argc == 0 && connection_fd == -1) {
+fputs("No arguments\n", stderr);
 display_usage(progname, subcommand);
 exit(255);
   }
@@ -501,7 +528,7 @@
 
   ConnectToRemote(mainloop, gdb_server, reverse_connect, host_and_port,
   progname, subcommand, named_pipe_path.c_str(),
-  unnamed_pipe_fd);
+  unnamed_pipe_fd, connection_fd);
 
   if (!gdb_server.IsConnected()) {
 fprintf(stderr, "no connection information provided, unable to run\n");
Index: source/Host/posix/ConnectionFileDescriptorPosix.cpp
===
--- source/Host/posix/ConnectionFileDescriptorPosix.cpp
+++

[Lldb-commits] [PATCH] D33213: Use socketpair on all Unix platforms

2017-07-22 Thread Demi Marie Obenour via Phabricator via lldb-commits
DemiMarie updated this revision to Diff 107806.
DemiMarie added a comment.

Get rid of silly and bogus #error


https://reviews.llvm.org/D33213

Files:
  tools/lldb-server/lldb-gdbserver.cpp

Index: tools/lldb-server/lldb-gdbserver.cpp
===
--- tools/lldb-server/lldb-gdbserver.cpp
+++ tools/lldb-server/lldb-gdbserver.cpp
@@ -106,6 +106,7 @@
// than llgs listening for a connection from address on port.
 {"setsid", no_argument, NULL,
  'S'}, // Call setsid() to make llgs run in its own session.
+{"fd", required_argument, NULL, 'F'},
 {NULL, 0, NULL, 0}};
 
 //--
@@ -132,13 +133,13 @@
   "[--log-file log-file-name] "
   "[--log-channels log-channel-list] "
   "[--setsid] "
+  "[--fd file-descriptor]"
   "[--named-pipe named-pipe-path] "
   "[--native-regs] "
   "[--attach pid] "
   "[[HOST]:PORT] "
   "[-- PROGRAM ARG1 ARG2 ...]\n",
   progname, subcommand);
-  exit(0);
 }
 
 void handle_attach_to_pid(GDBRemoteCommunicationServerLLGS &gdb_server,
@@ -232,10 +233,31 @@
  GDBRemoteCommunicationServerLLGS &gdb_server,
  bool reverse_connect, const char *const host_and_port,
  const char *const progname, const char *const subcommand,
- const char *const named_pipe_path, int unnamed_pipe_fd) {
+ const char *const named_pipe_path, int unnamed_pipe_fd,
+ int connection_fd) {
   Status error;
 
-  if (host_and_port && host_and_port[0]) {
+  std::unique_ptr connection_up;
+  if (connection_fd != -1) {
+// Build the connection string.
+char connection_url[512];
+snprintf(connection_url, sizeof(connection_url), "fd://%d", connection_fd);
+
+// Create the connection.
+connection_up.reset(new ConnectionFileDescriptor);
+auto connection_result = connection_up->Connect(connection_url, &error);
+if (connection_result != eConnectionStatusSuccess) {
+  fprintf(stderr, "error: failed to connect to client at '%s' "
+  "(connection status: %d)",
+  connection_url, static_cast(connection_result));
+  exit(-1);
+}
+if (error.Fail()) {
+  fprintf(stderr, "error: failed to connect to client at '%s': %s",
+  connection_url, error.AsCString());
+  exit(-1);
+}
+  } else if (host_and_port && host_and_port[0]) {
 // Parse out host and port.
 std::string final_host_and_port;
 std::string connection_host;
@@ -255,7 +277,6 @@
   connection_portno = StringConvert::ToUInt32(connection_port.c_str(), 0);
 }
 
-std::unique_ptr connection_up;
 
 if (reverse_connect) {
   // llgs will connect to the gdb-remote client.
@@ -328,14 +349,14 @@
   }
   connection_up.reset(conn);
 }
-error = gdb_server.InitializeConnection(std::move(connection_up));
-if (error.Fail()) {
-  fprintf(stderr, "Failed to initialize connection: %s\n",
-  error.AsCString());
-  exit(-1);
-}
-printf("Connection established.\n");
   }
+  error = gdb_server.InitializeConnection(std::move(connection_up));
+  if (error.Fail()) {
+fprintf(stderr, "Failed to initialize connection: %s\n",
+error.AsCString());
+exit(-1);
+  }
+  printf("Connection established.\n");
 }
 
 //--
@@ -364,6 +385,7 @@
   log_channels; // e.g. "lldb process threads:gdb-remote default:linux all"
   int unnamed_pipe_fd = -1;
   bool reverse_connect = false;
+  int connection_fd;
 
   // ProcessLaunchInfo launch_info;
   ProcessAttachInfo attach_info;
@@ -413,6 +435,10 @@
   reverse_connect = true;
   break;
 
+case 'F':
+  connection_fd = StringConvert::ToUInt32(optarg, -1);
+  break;
+
 #ifndef _WIN32
 case 'S':
   // Put llgs into a new session. Terminals group processes
@@ -472,7 +498,8 @@
   argc -= optind;
   argv += optind;
 
-  if (argc == 0) {
+  if (argc == 0 && connection_fd == -1) {
+fputs("No arguments\n", stderr);
 display_usage(progname, subcommand);
 exit(255);
   }
@@ -501,7 +528,7 @@
 
   ConnectToRemote(mainloop, gdb_server, reverse_connect, host_and_port,
   progname, subcommand, named_pipe_path.c_str(),
-  unnamed_pipe_fd);
+  unnamed_pipe_fd, connection_fd);
 
   if (!gdb_server.IsConnected()) {
 fprintf(stderr, "no connection information provided, unable to run\n");
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits