@@ -29,10 +29,36 @@ using namespace std::chrono;
29
29
30
30
LLDB_PLUGIN_DEFINE (PlatformAndroid)
31
31
32
- static uint32_t g_initialize_count = 0;
33
- static const unsigned int g_android_default_cache_size =
32
+ namespace {
33
+
34
+ #define LLDB_PROPERTIES_android
35
+ #include " PlatformAndroidProperties.inc"
36
+
37
+ enum {
38
+ #define LLDB_PROPERTIES_android
39
+ #include " PlatformAndroidPropertiesEnum.inc"
40
+ };
41
+
42
+ class PluginProperties : public Properties {
43
+ public:
44
+ PluginProperties () {
45
+ m_collection_sp = std::make_shared<OptionValueProperties>(
46
+ ConstString (PlatformAndroid::GetPluginNameStatic (false )));
47
+ m_collection_sp->Initialize (g_android_properties);
48
+ }
49
+ };
50
+
51
+ static PluginProperties &GetGlobalProperties () {
52
+ static PluginProperties g_settings;
53
+ return g_settings;
54
+ }
55
+
56
+ uint32_t g_initialize_count = 0 ;
57
+ const unsigned int g_android_default_cache_size =
34
58
2048 ; // Fits inside 4k adb packet.
35
59
60
+ } // end of anonymous namespace
61
+
36
62
void PlatformAndroid::Initialize () {
37
63
PlatformLinux::Initialize ();
38
64
@@ -45,7 +71,7 @@ void PlatformAndroid::Initialize() {
45
71
PluginManager::RegisterPlugin (
46
72
PlatformAndroid::GetPluginNameStatic (false ),
47
73
PlatformAndroid::GetPluginDescriptionStatic (false ),
48
- PlatformAndroid::CreateInstance);
74
+ PlatformAndroid::CreateInstance, PlatformAndroid::DebuggerInitialize );
49
75
}
50
76
}
51
77
@@ -128,6 +154,16 @@ PlatformSP PlatformAndroid::CreateInstance(bool force, const ArchSpec *arch) {
128
154
return PlatformSP ();
129
155
}
130
156
157
+ void PlatformAndroid::DebuggerInitialize (Debugger &debugger) {
158
+ if (!PluginManager::GetSettingForPlatformPlugin (
159
+ debugger, ConstString (GetPluginNameStatic (false )))) {
160
+ PluginManager::CreateSettingForPlatformPlugin (
161
+ debugger, GetGlobalProperties ().GetValueProperties (),
162
+ " Properties for the Android platform plugin." ,
163
+ /* is_global_property=*/ true );
164
+ }
165
+ }
166
+
131
167
PlatformAndroid::PlatformAndroid (bool is_host)
132
168
: PlatformLinux(is_host), m_sdk_version(0 ) {}
133
169
@@ -206,7 +242,8 @@ Status PlatformAndroid::GetFile(const FileSpec &source,
206
242
return error;
207
243
208
244
char cmd[PATH_MAX];
209
- snprintf (cmd, sizeof (cmd), " cat '%s'" , source_file.c_str ());
245
+ snprintf (cmd, sizeof (cmd), " %scat '%s'" , GetRunAs ().c_str (),
246
+ source_file.c_str ());
210
247
211
248
return adb->ShellToFile (cmd, minutes (1 ), destination);
212
249
}
@@ -260,9 +297,9 @@ Status PlatformAndroid::DownloadModuleSlice(const FileSpec &src_file_spec,
260
297
// Use 'shell dd' to download the file slice with the offset and size.
261
298
char cmd[PATH_MAX];
262
299
snprintf (cmd, sizeof (cmd),
263
- " dd if='%s' iflag=skip_bytes,count_bytes "
300
+ " %sdd if='%s' iflag=skip_bytes,count_bytes "
264
301
" skip=%" PRIu64 " count=%" PRIu64 " status=none" ,
265
- source_file.c_str (), src_offset, src_size);
302
+ GetRunAs (). c_str (), source_file.c_str (), src_offset, src_size);
266
303
267
304
return adb->ShellToFile (cmd, minutes (1 ), dst_file_spec);
268
305
}
@@ -410,6 +447,27 @@ PlatformAndroid::AdbClientUP PlatformAndroid::GetAdbClient(Status &error) {
410
447
return adb;
411
448
}
412
449
450
+ llvm::StringRef PlatformAndroid::GetPropertyPackageName () {
451
+ return GetGlobalProperties ().GetPropertyAtIndexAs <llvm::StringRef>(
452
+ ePropertyPlatformPackageName, " " );
453
+ }
454
+
455
+ std::string PlatformAndroid::GetRunAs () {
456
+ llvm::StringRef run_as = GetPropertyPackageName ();
457
+ if (!run_as.empty ()) {
458
+ // When LLDB fails to pull file from a package directory due to security
459
+ // constraint, user needs to set the package name to
460
+ // 'platform.plugin.remote-android.package-name' property in order to run
461
+ // shell commands as the package user using 'run-as' (e.g. to get file with
462
+ // 'cat' and 'dd').
463
+ // https://cs.android.com/android/platform/superproject/+/master:
464
+ // system/core/run-as/run-as.cpp;l=39-61;
465
+ // drc=4a77a84a55522a3b122f9c63ef0d0b8a6a131627
466
+ return std::string (" run-as '" ) + run_as.str () + " ' " ;
467
+ }
468
+ return run_as.str ();
469
+ }
470
+
413
471
AdbClient::SyncService *PlatformAndroid::GetSyncService (Status &error) {
414
472
if (m_adb_sync_svc && m_adb_sync_svc->IsConnected ())
415
473
return m_adb_sync_svc.get ();
0 commit comments