Skip to content

Commit e0f8f57

Browse files
author
Daniel Malea
committed
merge lldb-platform-work branch (and assorted fixes) into trunk
Summary: This merge brings in the improved 'platform' command that knows how to interface with remote machines; that is, query OS/kernel information, push and pull files, run shell commands, etc... and implementation for the new communication packets that back that interface, at least on Darwin based operating systems via the POSIXPlatform class. Linux support is coming soon. Verified the test suite runs cleanly on Linux (x86_64), build OK on Mac OS X Mountain Lion. Additional improvements (not in the source SVN branch 'lldb-platform-work'): - cmake build scripts for lldb-platform - cleanup test suite - documentation stub for qPlatform_RunCommand - use log class instead of printf() directly - reverted work-in-progress-looking changes from test/types/TestAbstract.py that work towards running the test suite remotely. - add new logging category 'platform' Reviewers: Matt Kopec, Greg Clayton Review: http://llvm-reviews.chandlerc.com/D1493 llvm-svn: 189295
1 parent 6b16b43 commit e0f8f57

File tree

85 files changed

+6025
-493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+6025
-493
lines changed

lldb/docs/lldb-gdb-remote.txt

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,20 @@ invalidate-regs
420420
modifying the CPSR register can cause the r8 - r14 and cpsr value to
421421
change depending on if the mode has changed.
422422

423+
//----------------------------------------------------------------------
424+
// "qPlatform_RunCommand"
425+
//
426+
// BRIEF
427+
// Run a command in a shell on the connected remote machine.
428+
//
429+
// PRIORITY TO IMPLEMENT
430+
// TODO
431+
//----------------------------------------------------------------------
432+
433+
send packet: TODO (see GDBRemoteCommunicationClient::RunShellCommand)
434+
read packet: TODO (see GDBRemoteCommunicationServer::Handle_qPlatform_RunCommand)
435+
436+
423437
//----------------------------------------------------------------------
424438
// "qHostInfo"
425439
//
@@ -848,3 +862,123 @@ for this region.
848862
// your debug session more reliable and informative.
849863
//----------------------------------------------------------------------
850864

865+
866+
//----------------------------------------------------------------------
867+
// PLATFORM EXTENSION - for use as a GDB remote platform
868+
//----------------------------------------------------------------------
869+
// "qfProcessInfo"
870+
// "qsProcessInfo"
871+
//
872+
// BRIEF
873+
// Get the first process info (qfProcessInfo) or subsequent processs
874+
// info (qsProcessInfo) for one or more processes on the remote
875+
// platform. The first call gets the first match and subsequent calls
876+
// to qsProcessInfo gets the subsequent matches. Return an error EXX,
877+
// where XX are two hex digits, when no more matches are available.
878+
//
879+
// PRIORITY TO IMPLEMENT
880+
// Required. The qfProcessInfo packet can be followed by a ':' and
881+
// some key value pairs. The key value pairs in the command are:
882+
//
883+
// KEY VALUE DESCRIPTION
884+
// =========== ======== ================================================
885+
// "name" ascii-hex An ASCII hex string that contains the name of
886+
// the process that will be matched.
887+
// "name_match" enum One of: "equals", "starts_with", "ends_with",
888+
// "contains" or "regex"
889+
// "pid" integer A string value containing the decimal process ID
890+
// "parent_pid" integer A string value containing the decimal parent
891+
// process ID
892+
// "uid" integer A string value containing the decimal user ID
893+
// "gid" integer A string value containing the decimal group ID
894+
// "euid" integer A string value containing the decimal effective user ID
895+
// "egid" integer A string value containing the decimal effective group ID
896+
// "all_users" bool A boolean value that specifies if processes should
897+
// be listed for all users, not just the user that the
898+
// platform is running as
899+
// "triple" ascii-hex An ASCII hex target triple string ("x86_64",
900+
// "x86_64-apple-macosx", "armv7-apple-ios")
901+
//
902+
// The response consists of key/value pairs where the key is separated from the
903+
// values with colons and each pair is terminated with a semi colon. For a list
904+
// of the key/value pairs in the response see the "qProcessInfoPID" packet
905+
// documentation.
906+
//
907+
// Sample packet/response:
908+
// send packet: $qfProcessInfo#00
909+
// read packet: $pid:60001;ppid:59948;uid:7746;gid:11;euid:7746;egid:11;name:6c6c6462;triple:7838365f36342d6170706c652d6d61636f7378;#00
910+
// send packet: $qsProcessInfo#00
911+
// read packet: $pid:59992;ppid:192;uid:7746;gid:11;euid:7746;egid:11;name:6d64776f726b6572;triple:7838365f36342d6170706c652d6d61636f7378;#00
912+
// send packet: $qsProcessInfo#00
913+
// read packet: $E04#00
914+
//----------------------------------------------------------------------
915+
916+
917+
//----------------------------------------------------------------------
918+
// PLATFORM EXTENSION - for use as a GDB remote platform
919+
//----------------------------------------------------------------------
920+
// "qLaunchGDBServer"
921+
//
922+
// BRIEF
923+
// Have the remote platform launch a GDB server.
924+
//
925+
// PRIORITY TO IMPLEMENT
926+
// Required. The qLaunchGDBServer packet must be followed by a ':' and
927+
// some key value pairs. The key value pairs in the command are:
928+
//
929+
// KEY VALUE DESCRIPTION
930+
// =========== ======== ================================================
931+
// "port" integer A string value containing the decimal port ID or
932+
// zero if the port should be bound and returned
933+
//
934+
// "host" integer The host that connections should be limited to
935+
// when the GDB server is connected to.
936+
//
937+
// The response consists of key/value pairs where the key is separated from the
938+
// values with colons and each pair is terminated with a semi colon.
939+
//
940+
// Sample packet/response:
941+
// send packet: $qLaunchGDBServer:port:0;host:lldb.apple.com;#00
942+
// read packet: $pid:60025;port:50776;#00
943+
//
944+
// The "pid" key/value pair is only specified if the remote platform launched
945+
// a separate process for the GDB remote server and can be omitted if no
946+
// process was separately launched.
947+
//
948+
// The "port" key/value pair in the response lets clients know what port number
949+
// to attach to in case zero was specified as the "port" in the sent command.
950+
//----------------------------------------------------------------------
951+
952+
953+
//----------------------------------------------------------------------
954+
// PLATFORM EXTENSION - for use as a GDB remote platform
955+
//----------------------------------------------------------------------
956+
// "qProcessInfoPID:PID"
957+
//
958+
// BRIEF
959+
// Have the remote platform get detailed information on a process by
960+
// ID. PID is specified as a decimal integer.
961+
//
962+
// PRIORITY TO IMPLEMENT
963+
// Optional.
964+
//
965+
// The response consists of key/value pairs where the key is separated from the
966+
// values with colons and each pair is terminated with a semi colon.
967+
//
968+
// The key value pairs in the response are:
969+
//
970+
// KEY VALUE DESCRIPTION
971+
// =========== ======== ================================================
972+
// "pid" integer Process ID as a decimal integer string
973+
// "ppid" integer Parent process ID as a decimal integer string
974+
// "uid" integer A string value containing the decimal user ID
975+
// "gid" integer A string value containing the decimal group ID
976+
// "euid" integer A string value containing the decimal effective user ID
977+
// "egid" integer A string value containing the decimal effective group ID
978+
// "name" ascii-hex An ASCII hex string that contains the name of the process
979+
// "triple" ascii-hex A target triple ("x86_64-apple-macosx", "armv7-apple-ios")
980+
//
981+
// Sample packet/response:
982+
// send packet: $qProcessInfoPID:60050#00
983+
// read packet: $pid:60050;ppid:59948;uid:7746;gid:11;euid:7746;egid:11;name:6c6c6462;triple:7838365f36342d6170706c652d6d61636f7378;#00
984+
//----------------------------------------------------------------------
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//===-- StreamGDBRemote.h ----------------------------------------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef liblldb_StreamGDBRemote_h_
11+
#define liblldb_StreamGDBRemote_h_
12+
13+
// C Includes
14+
// C++ Includes
15+
16+
// Other libraries and framework includes
17+
// Project includes
18+
19+
#include "lldb/Core/StreamString.h"
20+
21+
namespace lldb_private {
22+
23+
class StreamGDBRemote : public StreamString
24+
{
25+
public:
26+
StreamGDBRemote ();
27+
28+
StreamGDBRemote (uint32_t flags,
29+
uint32_t addr_size,
30+
lldb::ByteOrder byte_order);
31+
32+
virtual
33+
~StreamGDBRemote ();
34+
35+
//------------------------------------------------------------------
36+
/// Output a block of data to the stream performing GDB-remote escaping.
37+
///
38+
/// @param[in] s
39+
/// A block of data.
40+
///
41+
/// @param[in] src_len
42+
/// The amount of data to write.
43+
///
44+
/// @return
45+
/// Number of bytes written.
46+
//------------------------------------------------------------------
47+
int
48+
PutEscapedBytes (const void* s,
49+
size_t src_len);
50+
};
51+
52+
} // namespace lldb_private
53+
54+
#endif // liblldb_StreamGDBRemote_h_

lldb/include/lldb/Host/File.h

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,20 @@ class File
4141
eOpenOptionCanCreateNewOnly = (1u << 6) // Can create file only if it doesn't already exist
4242
};
4343

44+
static mode_t
45+
ConvertOpenOptionsForPOSIXOpen (uint32_t open_options);
46+
4447
enum Permissions
4548
{
46-
ePermissionsUserRead = (1u << 0),
47-
ePermissionsUserWrite = (1u << 1),
48-
ePermissionsUserExecute = (1u << 2),
49-
ePermissionsGroupRead = (1u << 3),
49+
ePermissionsUserRead = (1u << 8),
50+
ePermissionsUserWrite = (1u << 7),
51+
ePermissionsUserExecute = (1u << 6),
52+
ePermissionsGroupRead = (1u << 5),
5053
ePermissionsGroupWrite = (1u << 4),
51-
ePermissionsGroupExecute = (1u << 5),
52-
ePermissionsWorldRead = (1u << 6),
53-
ePermissionsWorldWrite = (1u << 7),
54-
ePermissionsWorldExecute = (1u << 8),
54+
ePermissionsGroupExecute = (1u << 3),
55+
ePermissionsWorldRead = (1u << 2),
56+
ePermissionsWorldWrite = (1u << 1),
57+
ePermissionsWorldExecute = (1u << 0),
5558

5659
ePermissionsUserRW = (ePermissionsUserRead | ePermissionsUserWrite | 0 ),
5760
ePermissionsUserRX = (ePermissionsUserRead | 0 | ePermissionsUserExecute ),
@@ -117,6 +120,27 @@ class File
117120
uint32_t options,
118121
uint32_t permissions = ePermissionsDefault);
119122

123+
//------------------------------------------------------------------
124+
/// Constructor with FileSpec.
125+
///
126+
/// Takes a FileSpec pointing to a file which can be just a filename, or a full
127+
/// path. If \a path is not NULL or empty, this function will call
128+
/// File::Open (const char *path, uint32_t options, uint32_t permissions).
129+
///
130+
/// @param[in] path
131+
/// The FileSpec for this file.
132+
///
133+
/// @param[in] options
134+
/// Options to use when opening (see File::OpenOptions)
135+
///
136+
/// @param[in] permissions
137+
/// Options to use when opening (see File::Permissions)
138+
///
139+
/// @see File::Open (const char *path, uint32_t options, uint32_t permissions)
140+
//------------------------------------------------------------------
141+
File (const FileSpec& filespec,
142+
uint32_t options,
143+
uint32_t permissions = ePermissionsDefault);
120144

121145
File (int fd, bool tranfer_ownership) :
122146
m_descriptor (fd),
@@ -451,6 +475,19 @@ class File
451475
//------------------------------------------------------------------
452476
Error
453477
Sync ();
478+
479+
//------------------------------------------------------------------
480+
/// Get the permissions for a this file.
481+
///
482+
/// @return
483+
/// Bits logical OR'ed together from the permission bits defined
484+
/// in lldb_private::File::Permissions.
485+
//------------------------------------------------------------------
486+
uint32_t
487+
GetPermissions(Error &error) const;
488+
489+
static uint32_t
490+
GetPermissions (const char *path, Error &error);
454491

455492
//------------------------------------------------------------------
456493
/// Output printf formatted output to the stream.

lldb/include/lldb/Host/FileSpec.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,21 @@ class FileSpec
624624
static size_t
625625
Resolve (const char *src_path, char *dst_path, size_t dst_len);
626626

627+
FileSpec
628+
CopyByAppendingPathComponent (const char *new_path) const;
629+
630+
FileSpec
631+
CopyByRemovingLastPathComponent () const;
632+
633+
void
634+
AppendPathComponent (const char *new_path);
635+
636+
void
637+
RemoveLastPathComponent ();
638+
639+
const char*
640+
GetLastPathComponent () const;
641+
627642
//------------------------------------------------------------------
628643
/// Resolves the user name at the beginning of \a src_path, and writes the output
629644
/// to \a dst_path. Note, \a src_path can contain other path components after the

lldb/include/lldb/Host/Host.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "lldb/lldb-private.h"
2020
#include "lldb/Core/StringList.h"
21+
#include "lldb/Host/File.h"
2122

2223
namespace lldb_private {
2324

@@ -508,6 +509,45 @@ class Host
508509
DynamicLibraryGetSymbol (void *dynamic_library_handle,
509510
const char *symbol_name,
510511
Error &error);
512+
513+
static uint32_t
514+
MakeDirectory (const char* path, mode_t mode);
515+
516+
static lldb::user_id_t
517+
OpenFile (const FileSpec& file_spec,
518+
uint32_t flags,
519+
mode_t mode,
520+
Error &error);
521+
522+
static bool
523+
CloseFile (lldb::user_id_t fd,
524+
Error &error);
525+
526+
static uint64_t
527+
WriteFile (lldb::user_id_t fd,
528+
uint64_t offset,
529+
const void* src,
530+
uint64_t src_len,
531+
Error &error);
532+
533+
static uint64_t
534+
ReadFile (lldb::user_id_t fd,
535+
uint64_t offset,
536+
void* dst,
537+
uint64_t dst_len,
538+
Error &error);
539+
540+
static lldb::user_id_t
541+
GetFileSize (const FileSpec& file_spec);
542+
543+
static bool
544+
GetFileExists (const FileSpec& file_spec);
545+
546+
static bool
547+
CalculateMD5 (const FileSpec& file_spec,
548+
uint64_t &low,
549+
uint64_t &high);
550+
511551
};
512552

513553
} // namespace lldb_private

lldb/include/lldb/Interpreter/Options.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ class Options
448448
void
449449
Finalize ();
450450

451+
bool
452+
DidFinalize ()
453+
{
454+
return m_did_finalize;
455+
}
456+
451457
virtual Error
452458
SetOptionValue (uint32_t option_idx,
453459
const char *option_arg);
@@ -464,6 +470,10 @@ class Options
464470
assert (m_did_finalize);
465471
return &m_option_defs[0];
466472
}
473+
474+
const OptionGroup*
475+
GetGroupWithOption (char short_opt);
476+
467477
struct OptionInfo
468478
{
469479
OptionInfo (OptionGroup* g, uint32_t i) :

lldb/include/lldb/Interpreter/ScriptInterpreter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class ScriptInterpreter
112112
typedef void* (*SWIGPythonGetChildAtIndex) (void *implementor, uint32_t idx);
113113
typedef int (*SWIGPythonGetIndexOfChildWithName) (void *implementor, const char* child_name);
114114
typedef void* (*SWIGPythonCastPyObjectToSBValue) (void* data);
115+
typedef lldb::ValueObjectSP (*SWIGPythonGetValueObjectSPFromSBValue) (void* data);
115116
typedef bool (*SWIGPythonUpdateSynthProviderInstance) (void* data);
116117
typedef bool (*SWIGPythonMightHaveChildrenSynthProviderInstance) (void* data);
117118

0 commit comments

Comments
 (0)