Add a another packet to the gdb-remote protocol,
jGetLoadedDynamicLibrariesInfos.  This packet is similar to
qXfer:libraries:read except that lldb supplies the number of solibs
that should be reported about, and the start address for the list
of them.  At the initial process launch we'll read the full list
of solibs linked by the process -- at this point we could be using
qXfer:libraries:read -- but on subsequence solib-loaded notifications,
we'll be fetching a smaller number of solibs, often only one or two.

A typical Mac/iOS GUI app may have a couple hundred different 
solibs loaded  - doing all of the loads via memory reads takes 
a couple of megabytes of traffic between lldb and debugserver.
Having debugserver summarize the load addresses of all the solibs
and sending it in JSON requires a couple of hundred kilobytes
of traffic.  It's a significant performance improvement when 
communicating over a slower channel.

This patch leaves all of the logic for loading the libraries
in DynamicLoaderMacOSXDYLD -- it only call over ot ProcesGDBRemote
to get the JSON result.

If the jGetLoadedDynamicLibrariesInfos packet is not implemented,
the normal technique of using memory read packets to get all of
the details from the target will be used.

<rdar://problem/21007465>

llvm-svn: 241964
diff --git a/lldb/docs/lldb-gdb-remote.txt b/lldb/docs/lldb-gdb-remote.txt
index d8f22fe..78c5b32 100644
--- a/lldb/docs/lldb-gdb-remote.txt
+++ b/lldb/docs/lldb-gdb-remote.txt
@@ -1447,3 +1447,86 @@
 //       libcompression implements "LZMA level 6", the default compression for the
 //       open source LZMA implementation.
 //----------------------------------------------------------------------
+
+//----------------------------------------------------------------------
+// "jGetLoadedDynamicLibrariesInfos"
+//
+// BRIEF
+//  This packet asks the remote debug stub to send the details about libraries
+//  being added/removed from the process as a performance optimization.
+//
+//  LLDB SENDS: jGetLoadedDynamicLibrariesInfos:{"image_count":1,"image_list_address":140734800075128}
+//  STUB REPLIES: ${"images":[{"load_address":4294967296,"mod_date":0,"pathname":"/tmp/a.out","uuid":"02CF262C-ED6F-3965-9E14-63538B465CFF","mach_header":{"magic":4277009103,"cputype":16777223,"cpusubtype":18446744071562067971,"filetype":2},"segments":{"name":"__PAGEZERO","vmaddr":0,"vmsize":4294967296,"fileoff":0,"filesize":0,"maxprot":0},{"name":"__TEXT","vmaddr":4294967296,"vmsize":4096,"fileoff":0,"filesize":4096,"maxprot":7},{"name":"__LINKEDIT","vmaddr":4294971392,"vmsize":4096,"fileoff":4096,"filesize":152,"maxprot":7}}]}#00
+//
+//  Or pretty-printed,
+//
+//  STUB REPLIES: ${"images":
+//                  [
+//                      {"load_address":4294967296,
+//                       "mod_date":0,
+//                       "pathname":"/tmp/a.out",
+//                       "uuid":"02CF262C-ED6F-3965-9E14-63538B465CFF",
+//                       "mach_header":
+//                          {"magic":4277009103,
+//                           "cputype":16777223,
+//                           "cpusubtype":18446744071562067971,
+//                           "filetype":2
+//                           },
+//                       "segments":
+//                        [
+//                          {"name":"__PAGEZERO",
+//                           "vmaddr":0,
+//                           "vmsize":4294967296,
+//                           "fileoff":0,
+//                           "filesize":0,
+//                           "maxprot":0
+//                          },
+//                          {"name":"__TEXT",
+//                           "vmaddr":4294967296,
+//                           "vmsize":4096,
+//                           "fileoff":0,
+//                           "filesize":4096,
+//                           "maxprot":7
+//                          },
+//                          {"name":"__LINKEDIT",
+//                           "vmaddr":4294971392,
+//                           "vmsize":4096,
+//                           "fileoff":4096,
+//                           "filesize":152,
+//                           "maxprot":7
+//                          }
+//                        ]
+//                      }
+//                  ]
+//              }
+//
+//
+// This is similar to the qXfer:libraries:read packet, and it could
+// be argued that it should be merged into that packet.  A separate
+// packet was created primarily because lldb needs to specify the
+// number of images to be read and the address from which the initial
+// information is read.  Also the XML DTD would need to be extended
+// quite a bit to provide all the information that the DynamicLoaderMacOSX
+// would need to work correctly on this platform.
+//
+// On Mac OS X / iOS, when libraries are added or removed, a stub
+// function is called which lldb puts a breakpoint on.  The arguments
+// to the stub function include the number of libraries being added
+// or removed and the address where the list of libraries can be
+// found.  The information at this address is the load address of the
+// library, the filename, and the mod date of the library if available.
+// DynamicLoaderMacOSX then parses the load commands in the Mach-O header
+// at the load address before it can decide what action to take.
+//
+// The purpose of this packet is to eliminate all of the memory reads needed
+// to read the Mach-O header and load commands for these libraries.
+// On a typical GUI app, there can be a couple hundred shared libraries 
+// which results in megabytes of read packets.  That same information can
+// be returned in a couple hundred kilobytes in JSON format from the remote
+// debugserver.
+//
+//
+// PRIORITY TO IMPLEMENT
+//  Low.  If this packet is absent, lldb will read the Mach-O headers/load
+//  commands out of memory.
+//----------------------------------------------------------------------