LLDB  mainline
PlatformPOSIX.cpp
Go to the documentation of this file.
1 //===-- PlatformPOSIX.cpp -------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "PlatformPOSIX.h"
10 
12 #include "lldb/Core/Debugger.h"
13 #include "lldb/Core/Module.h"
14 #include "lldb/Core/ValueObject.h"
19 #include "lldb/Host/File.h"
20 #include "lldb/Host/FileCache.h"
21 #include "lldb/Host/FileSystem.h"
22 #include "lldb/Host/Host.h"
23 #include "lldb/Host/HostInfo.h"
27 #include "lldb/Target/Process.h"
28 #include "lldb/Target/Thread.h"
30 #include "lldb/Utility/FileSpec.h"
31 #include "lldb/Utility/Log.h"
33 #include "llvm/ADT/ScopeExit.h"
34 
35 using namespace lldb;
36 using namespace lldb_private;
37 
38 /// Default Constructor
40  : RemoteAwarePlatform(is_host), // This is the local host platform
41  m_option_group_platform_rsync(new OptionGroupPlatformRSync()),
42  m_option_group_platform_ssh(new OptionGroupPlatformSSH()),
43  m_option_group_platform_caching(new OptionGroupPlatformCaching()) {}
44 
45 /// Destructor.
46 ///
47 /// The destructor is virtual since this class is designed to be
48 /// inherited from by the plug-in instance.
50 
52  lldb_private::CommandInterpreter &interpreter) {
53  auto iter = m_options.find(&interpreter), end = m_options.end();
54  if (iter == end) {
55  std::unique_ptr<lldb_private::OptionGroupOptions> options(
56  new OptionGroupOptions());
57  options->Append(m_option_group_platform_rsync.get());
58  options->Append(m_option_group_platform_ssh.get());
59  options->Append(m_option_group_platform_caching.get());
60  m_options[&interpreter] = std::move(options);
61  }
62 
63  return m_options.at(&interpreter).get();
64 }
65 
66 static uint32_t chown_file(Platform *platform, const char *path,
67  uint32_t uid = UINT32_MAX,
68  uint32_t gid = UINT32_MAX) {
69  if (!platform || !path || *path == 0)
70  return UINT32_MAX;
71 
72  if (uid == UINT32_MAX && gid == UINT32_MAX)
73  return 0; // pretend I did chown correctly - actually I just didn't care
74 
75  StreamString command;
76  command.PutCString("chown ");
77  if (uid != UINT32_MAX)
78  command.Printf("%d", uid);
79  if (gid != UINT32_MAX)
80  command.Printf(":%d", gid);
81  command.Printf("%s", path);
82  int status;
83  platform->RunShellCommand(command.GetData(), FileSpec(), &status, nullptr,
84  nullptr, std::chrono::seconds(10));
85  return status;
86 }
87 
90  const lldb_private::FileSpec &destination, uint32_t uid,
91  uint32_t gid) {
93 
94  if (IsHost()) {
95  if (source == destination)
96  return Status();
97  // cp src dst
98  // chown uid:gid dst
99  std::string src_path(source.GetPath());
100  if (src_path.empty())
101  return Status("unable to get file path for source");
102  std::string dst_path(destination.GetPath());
103  if (dst_path.empty())
104  return Status("unable to get file path for destination");
105  StreamString command;
106  command.Printf("cp %s %s", src_path.c_str(), dst_path.c_str());
107  int status;
108  RunShellCommand(command.GetData(), FileSpec(), &status, nullptr, nullptr,
109  std::chrono::seconds(10));
110  if (status != 0)
111  return Status("unable to perform copy");
112  if (uid == UINT32_MAX && gid == UINT32_MAX)
113  return Status();
114  if (chown_file(this, dst_path.c_str(), uid, gid) != 0)
115  return Status("unable to perform chown");
116  return Status();
117  } else if (m_remote_platform_sp) {
118  if (GetSupportsRSync()) {
119  std::string src_path(source.GetPath());
120  if (src_path.empty())
121  return Status("unable to get file path for source");
122  std::string dst_path(destination.GetPath());
123  if (dst_path.empty())
124  return Status("unable to get file path for destination");
125  StreamString command;
126  if (GetIgnoresRemoteHostname()) {
127  if (!GetRSyncPrefix())
128  command.Printf("rsync %s %s %s", GetRSyncOpts(), src_path.c_str(),
129  dst_path.c_str());
130  else
131  command.Printf("rsync %s %s %s%s", GetRSyncOpts(), src_path.c_str(),
132  GetRSyncPrefix(), dst_path.c_str());
133  } else
134  command.Printf("rsync %s %s %s:%s", GetRSyncOpts(), src_path.c_str(),
135  GetHostname(), dst_path.c_str());
136  LLDB_LOGF(log, "[PutFile] Running command: %s\n", command.GetData());
137  int retcode;
138  Host::RunShellCommand(command.GetData(), FileSpec(), &retcode, nullptr,
139  nullptr, std::chrono::minutes(1));
140  if (retcode == 0) {
141  // Don't chown a local file for a remote system
142  // if (chown_file(this,dst_path.c_str(),uid,gid) != 0)
143  // return Status("unable to perform chown");
144  return Status();
145  }
146  // if we are still here rsync has failed - let's try the slow way before
147  // giving up
148  }
149  }
150  return Platform::PutFile(source, destination, uid, gid);
151 }
152 
154  const lldb_private::FileSpec &source, // remote file path
155  const lldb_private::FileSpec &destination) // local file path
156 {
158 
159  // Check the args, first.
160  std::string src_path(source.GetPath());
161  if (src_path.empty())
162  return Status("unable to get file path for source");
163  std::string dst_path(destination.GetPath());
164  if (dst_path.empty())
165  return Status("unable to get file path for destination");
166  if (IsHost()) {
167  if (source == destination)
168  return Status("local scenario->source and destination are the same file "
169  "path: no operation performed");
170  // cp src dst
171  StreamString cp_command;
172  cp_command.Printf("cp %s %s", src_path.c_str(), dst_path.c_str());
173  int status;
174  RunShellCommand(cp_command.GetData(), FileSpec(), &status, nullptr, nullptr,
175  std::chrono::seconds(10));
176  if (status != 0)
177  return Status("unable to perform copy");
178  return Status();
179  } else if (m_remote_platform_sp) {
180  if (GetSupportsRSync()) {
181  StreamString command;
182  if (GetIgnoresRemoteHostname()) {
183  if (!GetRSyncPrefix())
184  command.Printf("rsync %s %s %s", GetRSyncOpts(), src_path.c_str(),
185  dst_path.c_str());
186  else
187  command.Printf("rsync %s %s%s %s", GetRSyncOpts(), GetRSyncPrefix(),
188  src_path.c_str(), dst_path.c_str());
189  } else
190  command.Printf("rsync %s %s:%s %s", GetRSyncOpts(),
191  m_remote_platform_sp->GetHostname(), src_path.c_str(),
192  dst_path.c_str());
193  LLDB_LOGF(log, "[GetFile] Running command: %s\n", command.GetData());
194  int retcode;
195  Host::RunShellCommand(command.GetData(), FileSpec(), &retcode, nullptr,
196  nullptr, std::chrono::minutes(1));
197  if (retcode == 0)
198  return Status();
199  // If we are here, rsync has failed - let's try the slow way before
200  // giving up
201  }
202  // open src and dst
203  // read/write, read/write, read/write, ...
204  // close src
205  // close dst
206  LLDB_LOGF(log, "[GetFile] Using block by block transfer....\n");
207  Status error;
208  user_id_t fd_src = OpenFile(source, File::eOpenOptionRead,
209  lldb::eFilePermissionsFileDefault, error);
210 
211  if (fd_src == UINT64_MAX)
212  return Status("unable to open source file");
213 
214  uint32_t permissions = 0;
215  error = GetFilePermissions(source, permissions);
216 
217  if (permissions == 0)
218  permissions = lldb::eFilePermissionsFileDefault;
219 
220  user_id_t fd_dst = FileCache::GetInstance().OpenFile(
221  destination, File::eOpenOptionCanCreate | File::eOpenOptionWrite |
222  File::eOpenOptionTruncate,
223  permissions, error);
224 
225  if (fd_dst == UINT64_MAX) {
226  if (error.Success())
227  error.SetErrorString("unable to open destination file");
228  }
229 
230  if (error.Success()) {
231  lldb::DataBufferSP buffer_sp(new DataBufferHeap(1024, 0));
232  uint64_t offset = 0;
233  error.Clear();
234  while (error.Success()) {
235  const uint64_t n_read = ReadFile(fd_src, offset, buffer_sp->GetBytes(),
236  buffer_sp->GetByteSize(), error);
237  if (error.Fail())
238  break;
239  if (n_read == 0)
240  break;
241  if (FileCache::GetInstance().WriteFile(fd_dst, offset,
242  buffer_sp->GetBytes(), n_read,
243  error) != n_read) {
244  if (!error.Fail())
245  error.SetErrorString("unable to write to destination file");
246  break;
247  }
248  offset += n_read;
249  }
250  }
251  // Ignore the close error of src.
252  if (fd_src != UINT64_MAX)
253  CloseFile(fd_src, error);
254  // And close the dst file descriptot.
255  if (fd_dst != UINT64_MAX &&
256  !FileCache::GetInstance().CloseFile(fd_dst, error)) {
257  if (!error.Fail())
258  error.SetErrorString("unable to close destination file");
259  }
260  return error;
261  }
262  return Platform::GetFile(source, destination);
263 }
264 
266  StreamString stream;
267  if (GetSupportsRSync()) {
268  stream.PutCString("rsync");
269  if ((GetRSyncOpts() && *GetRSyncOpts()) ||
271  stream.Printf(", options: ");
272  if (GetRSyncOpts() && *GetRSyncOpts())
273  stream.Printf("'%s' ", GetRSyncOpts());
274  stream.Printf(", prefix: ");
275  if (GetRSyncPrefix() && *GetRSyncPrefix())
276  stream.Printf("'%s' ", GetRSyncPrefix());
278  stream.Printf("ignore remote-hostname ");
279  }
280  }
281  if (GetSupportsSSH()) {
282  stream.PutCString("ssh");
283  if (GetSSHOpts() && *GetSSHOpts())
284  stream.Printf(", options: '%s' ", GetSSHOpts());
285  }
287  stream.Printf("cache dir: %s", GetLocalCacheDirectory());
288  if (stream.GetSize())
289  return std::string(stream.GetString());
290  else
291  return "";
292 }
293 
294 const lldb::UnixSignalsSP &PlatformPOSIX::GetRemoteUnixSignals() {
296  return m_remote_platform_sp->GetRemoteUnixSignals();
297  return Platform::GetRemoteUnixSignals();
298 }
299 
301  Status error;
302  if (IsHost()) {
303  error.SetErrorStringWithFormat(
304  "can't connect to the host platform '%s', always connected",
305  GetPluginName().GetCString());
306  } else {
309  Platform::Create(ConstString("remote-gdb-server"), error);
310 
311  if (m_remote_platform_sp && error.Success())
312  error = m_remote_platform_sp->ConnectRemote(args);
313  else
314  error.SetErrorString("failed to create a 'remote-gdb-server' platform");
315 
316  if (error.Fail())
317  m_remote_platform_sp.reset();
318  }
319 
320  if (error.Success() && m_remote_platform_sp) {
321  if (m_option_group_platform_rsync.get() &&
324  if (m_option_group_platform_rsync->m_rsync) {
325  SetSupportsRSync(true);
326  SetRSyncOpts(m_option_group_platform_rsync->m_rsync_opts.c_str());
327  SetRSyncPrefix(m_option_group_platform_rsync->m_rsync_prefix.c_str());
329  m_option_group_platform_rsync->m_ignores_remote_hostname);
330  }
331  if (m_option_group_platform_ssh->m_ssh) {
332  SetSupportsSSH(true);
333  SetSSHOpts(m_option_group_platform_ssh->m_ssh_opts.c_str());
334  }
336  m_option_group_platform_caching->m_cache_dir.c_str());
337  }
338  }
339 
340  return error;
341 }
342 
344  Status error;
345 
346  if (IsHost()) {
347  error.SetErrorStringWithFormat(
348  "can't disconnect from the host platform '%s', always connected",
349  GetPluginName().GetCString());
350  } else {
352  error = m_remote_platform_sp->DisconnectRemote();
353  else
354  error.SetErrorString("the platform is not currently connected");
355  }
356  return error;
357 }
358 
359 lldb::ProcessSP PlatformPOSIX::Attach(ProcessAttachInfo &attach_info,
360  Debugger &debugger, Target *target,
361  Status &error) {
362  lldb::ProcessSP process_sp;
364 
365  if (IsHost()) {
366  if (target == nullptr) {
367  TargetSP new_target_sp;
368 
369  error = debugger.GetTargetList().CreateTarget(
370  debugger, "", "", eLoadDependentsNo, nullptr, new_target_sp);
371  target = new_target_sp.get();
372  LLDB_LOGF(log, "PlatformPOSIX::%s created new target", __FUNCTION__);
373  } else {
374  error.Clear();
375  LLDB_LOGF(log, "PlatformPOSIX::%s target already existed, setting target",
376  __FUNCTION__);
377  }
378 
379  if (target && error.Success()) {
380  if (log) {
381  ModuleSP exe_module_sp = target->GetExecutableModule();
382  LLDB_LOGF(log, "PlatformPOSIX::%s set selected target to %p %s",
383  __FUNCTION__, (void *)target,
384  exe_module_sp ? exe_module_sp->GetFileSpec().GetPath().c_str()
385  : "<null>");
386  }
387 
388  process_sp =
389  target->CreateProcess(attach_info.GetListenerForProcess(debugger),
390  "gdb-remote", nullptr, true);
391 
392  if (process_sp) {
393  ListenerSP listener_sp = attach_info.GetHijackListener();
394  if (listener_sp == nullptr) {
395  listener_sp =
396  Listener::MakeListener("lldb.PlatformPOSIX.attach.hijack");
397  attach_info.SetHijackListener(listener_sp);
398  }
399  process_sp->HijackProcessEvents(listener_sp);
400  error = process_sp->Attach(attach_info);
401  }
402  }
403  } else {
405  process_sp =
406  m_remote_platform_sp->Attach(attach_info, debugger, target, error);
407  else
408  error.SetErrorString("the platform is not currently connected");
409  }
410  return process_sp;
411 }
412 
413 lldb::ProcessSP
415  Target *target, // Can be NULL, if NULL create a new
416  // target, else use existing one
417  Status &error) {
419  LLDB_LOG(log, "target {0}", target);
420 
421  ProcessSP process_sp;
422 
423  if (!IsHost()) {
425  process_sp = m_remote_platform_sp->DebugProcess(launch_info, debugger,
426  target, error);
427  else
428  error.SetErrorString("the platform is not currently connected");
429  return process_sp;
430  }
431 
432  //
433  // For local debugging, we'll insist on having ProcessGDBRemote create the
434  // process.
435  //
436 
437  // Make sure we stop at the entry point
438  launch_info.GetFlags().Set(eLaunchFlagDebug);
439 
440  // We always launch the process we are going to debug in a separate process
441  // group, since then we can handle ^C interrupts ourselves w/o having to
442  // worry about the target getting them as well.
443  launch_info.SetLaunchInSeparateProcessGroup(true);
444 
445  // Ensure we have a target.
446  if (target == nullptr) {
447  LLDB_LOG(log, "creating new target");
448  TargetSP new_target_sp;
449  error = debugger.GetTargetList().CreateTarget(
450  debugger, "", "", eLoadDependentsNo, nullptr, new_target_sp);
451  if (error.Fail()) {
452  LLDB_LOG(log, "failed to create new target: {0}", error);
453  return process_sp;
454  }
455 
456  target = new_target_sp.get();
457  if (!target) {
458  error.SetErrorString("CreateTarget() returned nullptr");
459  LLDB_LOG(log, "error: {0}", error);
460  return process_sp;
461  }
462  }
463 
464  // Now create the gdb-remote process.
465  LLDB_LOG(log, "having target create process with gdb-remote plugin");
466  process_sp =
467  target->CreateProcess(launch_info.GetListener(), "gdb-remote", nullptr,
468  true);
469 
470  if (!process_sp) {
471  error.SetErrorString("CreateProcess() failed for gdb-remote process");
472  LLDB_LOG(log, "error: {0}", error);
473  return process_sp;
474  }
475 
476  LLDB_LOG(log, "successfully created process");
477  // Adjust launch for a hijacker.
478  ListenerSP listener_sp;
479  if (!launch_info.GetHijackListener()) {
480  LLDB_LOG(log, "setting up hijacker");
481  listener_sp =
482  Listener::MakeListener("lldb.PlatformLinux.DebugProcess.hijack");
483  launch_info.SetHijackListener(listener_sp);
484  process_sp->HijackProcessEvents(listener_sp);
485  }
486 
487  // Log file actions.
488  if (log) {
489  LLDB_LOG(log, "launching process with the following file actions:");
490  StreamString stream;
491  size_t i = 0;
492  const FileAction *file_action;
493  while ((file_action = launch_info.GetFileActionAtIndex(i++)) != nullptr) {
494  file_action->Dump(stream);
495  LLDB_LOG(log, "{0}", stream.GetData());
496  stream.Clear();
497  }
498  }
499 
500  // Do the launch.
501  error = process_sp->Launch(launch_info);
502  if (error.Success()) {
503  // Handle the hijacking of process events.
504  if (listener_sp) {
505  const StateType state = process_sp->WaitForProcessToStop(
506  llvm::None, nullptr, false, listener_sp);
507 
508  LLDB_LOG(log, "pid {0} state {0}", process_sp->GetID(), state);
509  }
510 
511  // Hook up process PTY if we have one (which we should for local debugging
512  // with llgs).
513  int pty_fd = launch_info.GetPTY().ReleasePrimaryFileDescriptor();
514  if (pty_fd != PseudoTerminal::invalid_fd) {
515  process_sp->SetSTDIOFileDescriptor(pty_fd);
516  LLDB_LOG(log, "hooked up STDIO pty to process");
517  } else
518  LLDB_LOG(log, "not using process STDIO pty");
519  } else {
520  LLDB_LOG(log, "{0}", error);
521  // FIXME figure out appropriate cleanup here. Do we delete the target? Do
522  // we delete the process? Does our caller do that?
523  }
524 
525  return process_sp;
526 }
527 
529  m_trap_handlers.push_back(ConstString("_sigtramp"));
530 }
531 
533  lldb_private::Process *process, const char *expr_cstr,
534  llvm::StringRef expr_prefix, lldb::ValueObjectSP &result_valobj_sp) {
535  DynamicLoader *loader = process->GetDynamicLoader();
536  if (loader) {
537  Status error = loader->CanLoadImage();
538  if (error.Fail())
539  return error;
540  }
541 
542  ThreadSP thread_sp(process->GetThreadList().GetExpressionExecutionThread());
543  if (!thread_sp)
544  return Status("Selected thread isn't valid");
545 
546  StackFrameSP frame_sp(thread_sp->GetStackFrameAtIndex(0));
547  if (!frame_sp)
548  return Status("Frame 0 isn't valid");
549 
550  ExecutionContext exe_ctx;
551  frame_sp->CalculateExecutionContext(exe_ctx);
552  EvaluateExpressionOptions expr_options;
553  expr_options.SetUnwindOnError(true);
554  expr_options.SetIgnoreBreakpoints(true);
557  expr_options.SetTrapExceptions(false); // dlopen can't throw exceptions, so
558  // don't do the work to trap them.
559  expr_options.SetTimeout(process->GetUtilityExpressionTimeout());
560 
561  Status expr_error;
562  ExpressionResults result =
563  UserExpression::Evaluate(exe_ctx, expr_options, expr_cstr, expr_prefix,
564  result_valobj_sp, expr_error);
565  if (result != eExpressionCompleted)
566  return expr_error;
567 
568  if (result_valobj_sp->GetError().Fail())
569  return result_valobj_sp->GetError();
570  return Status();
571 }
572 
573 std::unique_ptr<UtilityFunction>
575  Status &error) {
576  // Remember to prepend this with the prefix from
577  // GetLibdlFunctionDeclarations. The returned values are all in
578  // __lldb_dlopen_result for consistency. The wrapper returns a void * but
579  // doesn't use it because UtilityFunctions don't work with void returns at
580  // present.
581  //
582  // Use lazy binding so as to not make dlopen()'s success conditional on
583  // forcing every symbol in the library.
584  //
585  // In general, the debugger should allow programs to load & run with
586  // libraries as far as they can, instead of defaulting to being super-picky
587  // about unavailable symbols.
588  //
589  // The value "1" appears to imply lazy binding (RTLD_LAZY) on both Darwin
590  // and other POSIX OSes.
591  static const char *dlopen_wrapper_code = R"(
592  const int RTLD_LAZY = 1;
593 
594  struct __lldb_dlopen_result {
595  void *image_ptr;
596  const char *error_str;
597  };
598 
599  extern void *memcpy(void *, const void *, size_t size);
600  extern size_t strlen(const char *);
601 
602 
603  void * __lldb_dlopen_wrapper (const char *name,
604  const char *path_strings,
605  char *buffer,
606  __lldb_dlopen_result *result_ptr)
607  {
608  // This is the case where the name is the full path:
609  if (!path_strings) {
610  result_ptr->image_ptr = dlopen(name, RTLD_LAZY);
611  if (result_ptr->image_ptr)
612  result_ptr->error_str = nullptr;
613  return nullptr;
614  }
615 
616  // This is the case where we have a list of paths:
617  size_t name_len = strlen(name);
618  while (path_strings && path_strings[0] != '\0') {
619  size_t path_len = strlen(path_strings);
620  memcpy((void *) buffer, (void *) path_strings, path_len);
621  buffer[path_len] = '/';
622  char *target_ptr = buffer+path_len+1;
623  memcpy((void *) target_ptr, (void *) name, name_len + 1);
624  result_ptr->image_ptr = dlopen(buffer, RTLD_LAZY);
625  if (result_ptr->image_ptr) {
626  result_ptr->error_str = nullptr;
627  break;
628  }
629  result_ptr->error_str = dlerror();
630  path_strings = path_strings + path_len + 1;
631  }
632  return nullptr;
633  }
634  )";
635 
636  static const char *dlopen_wrapper_name = "__lldb_dlopen_wrapper";
637  Process *process = exe_ctx.GetProcessSP().get();
638  // Insert the dlopen shim defines into our generic expression:
640  expr.append(dlopen_wrapper_code);
641  Status utility_error;
642  DiagnosticManager diagnostics;
643 
644  auto utility_fn_or_error = process->GetTarget().CreateUtilityFunction(
645  std::move(expr), dlopen_wrapper_name, eLanguageTypeObjC, exe_ctx);
646  if (!utility_fn_or_error) {
647  std::string error_str = llvm::toString(utility_fn_or_error.takeError());
648  error.SetErrorStringWithFormat("dlopen error: could not create utility"
649  "function: %s",
650  error_str.c_str());
651  return nullptr;
652  }
653  std::unique_ptr<UtilityFunction> dlopen_utility_func_up =
654  std::move(*utility_fn_or_error);
655 
656  Value value;
657  ValueList arguments;
658  FunctionCaller *do_dlopen_function = nullptr;
659 
660  // Fetch the clang types we will need:
661  TypeSystemClang *ast =
662  ScratchTypeSystemClang::GetForTarget(process->GetTarget());
663  if (!ast)
664  return nullptr;
665 
666  CompilerType clang_void_pointer_type
668  CompilerType clang_char_pointer_type
670 
671  // We are passing four arguments, the basename, the list of places to look,
672  // a buffer big enough for all the path + name combos, and
673  // a pointer to the storage we've made for the result:
674  value.SetValueType(Value::ValueType::Scalar);
675  value.SetCompilerType(clang_void_pointer_type);
676  arguments.PushValue(value);
677  value.SetCompilerType(clang_char_pointer_type);
678  arguments.PushValue(value);
679  arguments.PushValue(value);
680  arguments.PushValue(value);
681 
682  do_dlopen_function = dlopen_utility_func_up->MakeFunctionCaller(
683  clang_void_pointer_type, arguments, exe_ctx.GetThreadSP(), utility_error);
684  if (utility_error.Fail()) {
685  error.SetErrorStringWithFormat("dlopen error: could not make function"
686  "caller: %s", utility_error.AsCString());
687  return nullptr;
688  }
689 
690  do_dlopen_function = dlopen_utility_func_up->GetFunctionCaller();
691  if (!do_dlopen_function) {
692  error.SetErrorString("dlopen error: could not get function caller.");
693  return nullptr;
694  }
695 
696  // We made a good utility function, so cache it in the process:
697  return dlopen_utility_func_up;
698 }
699 
701  const lldb_private::FileSpec &remote_file,
702  const std::vector<std::string> *paths,
704  lldb_private::FileSpec *loaded_image) {
705  if (loaded_image)
706  loaded_image->Clear();
707 
708  std::string path;
709  path = remote_file.GetPath();
710 
711  ThreadSP thread_sp = process->GetThreadList().GetExpressionExecutionThread();
712  if (!thread_sp) {
713  error.SetErrorString("dlopen error: no thread available to call dlopen.");
715  }
716 
717  DiagnosticManager diagnostics;
718 
719  ExecutionContext exe_ctx;
720  thread_sp->CalculateExecutionContext(exe_ctx);
721 
722  Status utility_error;
723  UtilityFunction *dlopen_utility_func;
724  ValueList arguments;
725  FunctionCaller *do_dlopen_function = nullptr;
726 
727  // The UtilityFunction is held in the Process. Platforms don't track the
728  // lifespan of the Targets that use them, we can't put this in the Platform.
729  dlopen_utility_func = process->GetLoadImageUtilityFunction(
730  this, [&]() -> std::unique_ptr<UtilityFunction> {
731  return MakeLoadImageUtilityFunction(exe_ctx, error);
732  });
733  // If we couldn't make it, the error will be in error, so we can exit here.
734  if (!dlopen_utility_func)
736 
737  do_dlopen_function = dlopen_utility_func->GetFunctionCaller();
738  if (!do_dlopen_function) {
739  error.SetErrorString("dlopen error: could not get function caller.");
741  }
742  arguments = do_dlopen_function->GetArgumentValues();
743 
744  // Now insert the path we are searching for and the result structure into the
745  // target.
746  uint32_t permissions = ePermissionsReadable|ePermissionsWritable;
747  size_t path_len = path.size() + 1;
748  lldb::addr_t path_addr = process->AllocateMemory(path_len,
749  permissions,
750  utility_error);
751  if (path_addr == LLDB_INVALID_ADDRESS) {
752  error.SetErrorStringWithFormat("dlopen error: could not allocate memory"
753  "for path: %s", utility_error.AsCString());
755  }
756 
757  // Make sure we deallocate the input string memory:
758  auto path_cleanup = llvm::make_scope_exit([process, path_addr] {
759  // Deallocate the buffer.
760  process->DeallocateMemory(path_addr);
761  });
762 
763  process->WriteMemory(path_addr, path.c_str(), path_len, utility_error);
764  if (utility_error.Fail()) {
765  error.SetErrorStringWithFormat("dlopen error: could not write path string:"
766  " %s", utility_error.AsCString());
768  }
769 
770  // Make space for our return structure. It is two pointers big: the token
771  // and the error string.
772  const uint32_t addr_size = process->GetAddressByteSize();
773  lldb::addr_t return_addr = process->CallocateMemory(2*addr_size,
774  permissions,
775  utility_error);
776  if (utility_error.Fail()) {
777  error.SetErrorStringWithFormat("dlopen error: could not allocate memory"
778  "for path: %s", utility_error.AsCString());
780  }
781 
782  // Make sure we deallocate the result structure memory
783  auto return_cleanup = llvm::make_scope_exit([process, return_addr] {
784  // Deallocate the buffer
785  process->DeallocateMemory(return_addr);
786  });
787 
788  // This will be the address of the storage for paths, if we are using them,
789  // or nullptr to signal we aren't.
790  lldb::addr_t path_array_addr = 0x0;
791  llvm::Optional<llvm::detail::scope_exit<std::function<void()>>>
792  path_array_cleanup;
793 
794  // This is the address to a buffer large enough to hold the largest path
795  // conjoined with the library name we're passing in. This is a convenience
796  // to avoid having to call malloc in the dlopen function.
797  lldb::addr_t buffer_addr = 0x0;
798  llvm::Optional<llvm::detail::scope_exit<std::function<void()>>>
799  buffer_cleanup;
800 
801  // Set the values into our args and write them to the target:
802  if (paths != nullptr) {
803  // First insert the paths into the target. This is expected to be a
804  // continuous buffer with the strings laid out null terminated and
805  // end to end with an empty string terminating the buffer.
806  // We also compute the buffer's required size as we go.
807  size_t buffer_size = 0;
808  std::string path_array;
809  for (auto path : *paths) {
810  // Don't insert empty paths, they will make us abort the path
811  // search prematurely.
812  if (path.empty())
813  continue;
814  size_t path_size = path.size();
815  path_array.append(path);
816  path_array.push_back('\0');
817  if (path_size > buffer_size)
818  buffer_size = path_size;
819  }
820  path_array.push_back('\0');
821 
822  path_array_addr = process->AllocateMemory(path_array.size(),
823  permissions,
824  utility_error);
825  if (path_array_addr == LLDB_INVALID_ADDRESS) {
826  error.SetErrorStringWithFormat("dlopen error: could not allocate memory"
827  "for path array: %s",
828  utility_error.AsCString());
830  }
831 
832  // Make sure we deallocate the paths array.
833  path_array_cleanup.emplace([process, path_array_addr]() {
834  // Deallocate the path array.
835  process->DeallocateMemory(path_array_addr);
836  });
837 
838  process->WriteMemory(path_array_addr, path_array.data(),
839  path_array.size(), utility_error);
840 
841  if (utility_error.Fail()) {
842  error.SetErrorStringWithFormat("dlopen error: could not write path array:"
843  " %s", utility_error.AsCString());
845  }
846  // Now make spaces in the target for the buffer. We need to add one for
847  // the '/' that the utility function will insert and one for the '\0':
848  buffer_size += path.size() + 2;
849 
850  buffer_addr = process->AllocateMemory(buffer_size,
851  permissions,
852  utility_error);
853  if (buffer_addr == LLDB_INVALID_ADDRESS) {
854  error.SetErrorStringWithFormat("dlopen error: could not allocate memory"
855  "for buffer: %s",
856  utility_error.AsCString());
858  }
859 
860  // Make sure we deallocate the buffer memory:
861  buffer_cleanup.emplace([process, buffer_addr]() {
862  // Deallocate the buffer.
863  process->DeallocateMemory(buffer_addr);
864  });
865  }
866 
867  arguments.GetValueAtIndex(0)->GetScalar() = path_addr;
868  arguments.GetValueAtIndex(1)->GetScalar() = path_array_addr;
869  arguments.GetValueAtIndex(2)->GetScalar() = buffer_addr;
870  arguments.GetValueAtIndex(3)->GetScalar() = return_addr;
871 
872  lldb::addr_t func_args_addr = LLDB_INVALID_ADDRESS;
873 
874  diagnostics.Clear();
875  if (!do_dlopen_function->WriteFunctionArguments(exe_ctx,
876  func_args_addr,
877  arguments,
878  diagnostics)) {
879  error.SetErrorStringWithFormat("dlopen error: could not write function "
880  "arguments: %s",
881  diagnostics.GetString().c_str());
883  }
884 
885  // Make sure we clean up the args structure. We can't reuse it because the
886  // Platform lives longer than the process and the Platforms don't get a
887  // signal to clean up cached data when a process goes away.
888  auto args_cleanup =
889  llvm::make_scope_exit([do_dlopen_function, &exe_ctx, func_args_addr] {
890  do_dlopen_function->DeallocateFunctionResults(exe_ctx, func_args_addr);
891  });
892 
893  // Now run the caller:
896  options.SetLanguage(eLanguageTypeC_plus_plus);
897  options.SetIgnoreBreakpoints(true);
898  options.SetUnwindOnError(true);
899  options.SetTrapExceptions(false); // dlopen can't throw exceptions, so
900  // don't do the work to trap them.
901  options.SetTimeout(process->GetUtilityExpressionTimeout());
902  options.SetIsForUtilityExpr(true);
903 
904  Value return_value;
905  // Fetch the clang types we will need:
906  TypeSystemClang *ast =
907  ScratchTypeSystemClang::GetForTarget(process->GetTarget());
908  if (!ast) {
909  error.SetErrorString("dlopen error: Unable to get TypeSystemClang");
911  }
912 
913  CompilerType clang_void_pointer_type
915 
916  return_value.SetCompilerType(clang_void_pointer_type);
917 
918  ExpressionResults results = do_dlopen_function->ExecuteFunction(
919  exe_ctx, &func_args_addr, options, diagnostics, return_value);
920  if (results != eExpressionCompleted) {
921  error.SetErrorStringWithFormat("dlopen error: failed executing "
922  "dlopen wrapper function: %s",
923  diagnostics.GetString().c_str());
925  }
926 
927  // Read the dlopen token from the return area:
928  lldb::addr_t token = process->ReadPointerFromMemory(return_addr,
929  utility_error);
930  if (utility_error.Fail()) {
931  error.SetErrorStringWithFormat("dlopen error: could not read the return "
932  "struct: %s", utility_error.AsCString());
934  }
935 
936  // The dlopen succeeded!
937  if (token != 0x0) {
938  if (loaded_image && buffer_addr != 0x0)
939  {
940  // Capture the image which was loaded. We leave it in the buffer on
941  // exit from the dlopen function, so we can just read it from there:
942  std::string name_string;
943  process->ReadCStringFromMemory(buffer_addr, name_string, utility_error);
944  if (utility_error.Success())
945  loaded_image->SetFile(name_string, llvm::sys::path::Style::posix);
946  }
947  return process->AddImageToken(token);
948  }
949 
950  // We got an error, lets read in the error string:
951  std::string dlopen_error_str;
952  lldb::addr_t error_addr
953  = process->ReadPointerFromMemory(return_addr + addr_size, utility_error);
954  if (utility_error.Fail()) {
955  error.SetErrorStringWithFormat("dlopen error: could not read error string: "
956  "%s", utility_error.AsCString());
958  }
959 
960  size_t num_chars = process->ReadCStringFromMemory(error_addr + addr_size,
961  dlopen_error_str,
962  utility_error);
963  if (utility_error.Success() && num_chars > 0)
964  error.SetErrorStringWithFormat("dlopen error: %s",
965  dlopen_error_str.c_str());
966  else
967  error.SetErrorStringWithFormat("dlopen failed for unknown reasons.");
968 
970 }
971 
973  uint32_t image_token) {
974  const addr_t image_addr = process->GetImagePtrFromToken(image_token);
975  if (image_addr == LLDB_INVALID_ADDRESS)
976  return Status("Invalid image token");
977 
978  StreamString expr;
979  expr.Printf("dlclose((void *)0x%" PRIx64 ")", image_addr);
980  llvm::StringRef prefix = GetLibdlFunctionDeclarations(process);
981  lldb::ValueObjectSP result_valobj_sp;
982  Status error = EvaluateLibdlExpression(process, expr.GetData(), prefix,
983  result_valobj_sp);
984  if (error.Fail())
985  return error;
986 
987  if (result_valobj_sp->GetError().Fail())
988  return result_valobj_sp->GetError();
989 
990  Scalar scalar;
991  if (result_valobj_sp->ResolveValue(scalar)) {
992  if (scalar.UInt(1))
993  return Status("expression failed: \"%s\"", expr.GetData());
994  process->ResetImageToken(image_token);
995  }
996  return Status();
997 }
998 
999 llvm::StringRef
1001  return R"(
1002  extern "C" void* dlopen(const char*, int);
1003  extern "C" void* dlsym(void*, const char*);
1004  extern "C" int dlclose(void*);
1005  extern "C" char* dlerror(void);
1006  )";
1007 }
1008 
1010  if (basename.IsEmpty())
1011  return basename;
1012 
1013  StreamString stream;
1014  stream.Printf("lib%s.so", basename.GetCString());
1015  return ConstString(stream.GetString());
1016 }
lldb_private::UtilityFunction::GetFunctionCaller
FunctionCaller * GetFunctionCaller()
Definition: UtilityFunction.h:111
lldb_private::RemoteAwarePlatform::CloseFile
bool CloseFile(lldb::user_id_t fd, Status &error) override
Definition: RemoteAwarePlatform.cpp:228
lldb_private::ExecutionContext
Definition: ExecutionContext.h:291
lldb_private::ExecutionContext::GetThreadSP
const lldb::ThreadSP & GetThreadSP() const
Get accessor to get the thread shared pointer.
Definition: ExecutionContext.h:463
lldb_private::Process::AllocateMemory
lldb::addr_t AllocateMemory(size_t size, uint32_t permissions, Status &error)
The public interface to allocating memory in the process.
Definition: Process.cpp:2273
lldb_private::Process::DeallocateMemory
Status DeallocateMemory(lldb::addr_t ptr)
The public interface to deallocating memory in the process.
Definition: Process.cpp:2344
FileSystem.h
chown_file
static uint32_t chown_file(Platform *platform, const char *path, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX)
Definition: PlatformPOSIX.cpp:66
FunctionCaller.h
lldb_private::OptionGroupPlatformRSync
Definition: Platform.h:1023
lldb_private::EvaluateExpressionOptions::SetTimeout
void SetTimeout(const Timeout< std::micro > &timeout)
Definition: Target.h:323
lldb_private::EvaluateExpressionOptions::SetLanguage
void SetLanguage(lldb::LanguageType language)
Definition: Target.h:283
arm64_dwarf::x0
@ x0
Definition: ARM64_DWARF_Registers.h:17
lldb_private::Value
Definition: Value.h:38
lldb_private::Platform::SetLocalCacheDirectory
virtual void SetLocalCacheDirectory(const char *local)
Definition: Platform.cpp:1362
lldb_private::Value::SetValueType
void SetValueType(ValueType value_type)
Definition: Value.h:89
Host.h
lldb_private::RemoteAwarePlatform::OpenFile
lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags, uint32_t mode, Status &error) override
Definition: RemoteAwarePlatform.cpp:218
lldb::ExpressionResults
ExpressionResults
The results of expression evaluation.
Definition: lldb-enumerations.h:270
ProcessLaunchInfo.h
lldb_private::ValueList::GetValueAtIndex
Value * GetValueAtIndex(size_t idx)
Definition: Value.cpp:682
lldb_private::ProcessProperties::GetUtilityExpressionTimeout
std::chrono::seconds GetUtilityExpressionTimeout() const
Definition: Process.cpp:292
lldb_private::Scalar
Definition: Scalar.h:34
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
lldb_private::RemoteAwarePlatform::GetFilePermissions
Status GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions) override
Definition: RemoteAwarePlatform.cpp:202
lldb_private::Process
Definition: Process.h:343
lldb_private::Target::GetExecutableModule
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition: Target.cpp:1353
lldb_private::EvaluateExpressionOptions::SetExecutionPolicy
void SetExecutionPolicy(ExecutionPolicy policy=eExecutionPolicyAlways)
Definition: Target.h:277
FileCache.h
lldb_private::OptionGroupOptions
Definition: Options.h:255
lldb_private::Platform::GetLocalCacheDirectory
virtual const char * GetLocalCacheDirectory()
Definition: Platform.cpp:1366
Module.h
lldb_private::DynamicLoader::CanLoadImage
virtual Status CanLoadImage()=0
Ask if it is ok to try and load or unload an shared library (image).
lldb_private::Process::GetThreadList
ThreadList & GetThreadList()
Definition: Process.h:2047
lldb_private::Process::GetTarget
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1196
lldb_private::EvaluateExpressionOptions::SetTrapExceptions
void SetTrapExceptions(bool b)
Definition: Target.h:359
lldb_private::EvaluateExpressionOptions
Definition: Target.h:255
lldb_private::Platform::GetRSyncOpts
virtual const char * GetRSyncOpts()
Definition: Platform.h:593
LIBLLDB_LOG_PLATFORM
#define LIBLLDB_LOG_PLATFORM
Definition: Logging.h:39
UserExpression.h
lldb_private::Platform::m_trap_handlers
std::vector< ConstString > m_trap_handlers
Definition: Platform.h:905
lldb_private::ValueList
Definition: Value.h:157
lldb::eBasicTypeChar
@ eBasicTypeChar
Definition: lldb-enumerations.h:743
lldb_private::ProcessLaunchInfo::GetFlags
Flags & GetFlags()
Definition: ProcessLaunchInfo.h:64
PlatformPOSIX::GetRemoteUnixSignals
const lldb::UnixSignalsSP & GetRemoteUnixSignals() override
Definition: PlatformPOSIX.cpp:294
lldb_private::Process::ReadCStringFromMemory
size_t ReadCStringFromMemory(lldb::addr_t vm_addr, char *cstr, size_t cstr_max_len, Status &error)
Read a NULL terminated C string from memory.
Definition: Process.cpp:2006
lldb_private::Args
Definition: Args.h:33
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::Platform::SetSupportsSSH
virtual void SetSupportsSSH(bool flag)
Definition: Platform.h:605
lldb_private::eExecutionPolicyAlways
@ eExecutionPolicyAlways
Definition: lldb-private-enumerations.h:147
lldb_private::OptionGroupPlatformCaching
Definition: Platform.h:1075
lldb_private::Process::WriteMemory
size_t WriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size, Status &error)
Write memory to a process.
Definition: Process.cpp:2134
Debugger.h
lldb_private::Target
Definition: Target.h:447
lldb_private::ProcessLaunchInfo::SetHijackListener
void SetHijackListener(const lldb::ListenerSP &listener_sp)
Definition: ProcessLaunchInfo.h:136
lldb_private::Target::CreateProcess
const lldb::ProcessSP & CreateProcess(lldb::ListenerSP listener_sp, llvm::StringRef plugin_name, const FileSpec *crash_file, bool can_connect)
Definition: Target.cpp:200
lldb_private::FileAction
Definition: FileAction.h:17
PlatformPOSIX::GetFile
lldb_private::Status GetFile(const lldb_private::FileSpec &source, const lldb_private::FileSpec &destination) override
Definition: PlatformPOSIX.cpp:153
lldb_private::Process::CallocateMemory
lldb::addr_t CallocateMemory(size_t size, uint32_t permissions, Status &error)
The public interface to allocating memory in the process, this also clears the allocated memory.
Definition: Process.cpp:2296
lldb_private::StreamString::GetString
llvm::StringRef GetString() const
Definition: StreamString.cpp:51
lldb_private::DiagnosticManager::GetString
std::string GetString(char separator='\n')
Definition: DiagnosticManager.cpp:47
Process.h
lldb_private::Platform::GetSSHOpts
virtual const char * GetSSHOpts()
Definition: Platform.h:607
lldb_private::ProcessAttachInfo::GetListenerForProcess
lldb::ListenerSP GetListenerForProcess(Debugger &debugger)
Definition: Process.cpp:2714
lldb_private::Platform::RunShellCommand
virtual lldb_private::Status RunShellCommand(llvm::StringRef command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, const Timeout< std::micro > &timeout)
Definition: Platform.cpp:1318
lldb_private::Value::SetCompilerType
void SetCompilerType(const CompilerType &compiler_type)
Definition: Value.cpp:257
lldb_private::FunctionCaller::DeallocateFunctionResults
void DeallocateFunctionResults(ExecutionContext &exe_ctx, lldb::addr_t args_addr)
Deallocate the arguments structure.
Definition: FunctionCaller.cpp:302
lldb_private::Value::GetScalar
const Scalar & GetScalar() const
Definition: Value.h:112
PlatformPOSIX::PutFile
lldb_private::Status PutFile(const lldb_private::FileSpec &source, const lldb_private::FileSpec &destination, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX) override
Definition: PlatformPOSIX.cpp:89
lldb_private::FileSpec
Definition: FileSpec.h:56
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::Status::Success
bool Success() const
Test for success condition.
Definition: Status.cpp:288
lldb_private::StreamString::GetSize
size_t GetSize() const
Definition: StreamString.cpp:38
lldb_private::ValueList::PushValue
void PushValue(const Value &value)
Definition: Value.cpp:678
PlatformPOSIX::m_option_group_platform_ssh
std::unique_ptr< lldb_private::OptionGroupPlatformSSH > m_option_group_platform_ssh
Definition: PlatformPOSIX.h:80
PlatformPOSIX::EvaluateLibdlExpression
lldb_private::Status EvaluateLibdlExpression(lldb_private::Process *process, const char *expr_cstr, llvm::StringRef expr_prefix, lldb::ValueObjectSP &result_valobj_sp)
Definition: PlatformPOSIX.cpp:532
PlatformPOSIX::DoLoadImage
uint32_t DoLoadImage(lldb_private::Process *process, const lldb_private::FileSpec &remote_file, const std::vector< std::string > *paths, lldb_private::Status &error, lldb_private::FileSpec *loaded_image) override
Definition: PlatformPOSIX.cpp:700
lldb_private::FunctionCaller::WriteFunctionArguments
bool WriteFunctionArguments(ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref, DiagnosticManager &diagnostic_manager)
Insert the default function argument struct.
Definition: FunctionCaller.cpp:115
lldb_private::breakpad::toString
llvm::StringRef toString(Record::Kind K)
Definition: BreakpadRecords.cpp:483
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
Log.h
PlatformPOSIX::ConnectRemote
lldb_private::Status ConnectRemote(lldb_private::Args &args) override
Definition: PlatformPOSIX.cpp:300
TypeSystemClang.h
lldb_private::ConstString::IsEmpty
bool IsEmpty() const
Test for empty string.
Definition: ConstString.h:304
lldb_private::eLoadDependentsNo
@ eLoadDependentsNo
Definition: Target.h:65
lldb_private::Status::GetError
ValueType GetError() const
Access the error value.
Definition: Status.cpp:175
lldb_private::RemoteAwarePlatform::ReadFile
uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, uint64_t dst_len, Status &error) override
Definition: RemoteAwarePlatform.cpp:236
PlatformPOSIX::PlatformPOSIX
PlatformPOSIX(bool is_host)
Default Constructor.
Definition: PlatformPOSIX.cpp:39
PlatformPOSIX::DisconnectRemote
lldb_private::Status DisconnectRemote() override
Definition: PlatformPOSIX.cpp:343
PlatformPOSIX::GetFullNameForDylib
lldb_private::ConstString GetFullNameForDylib(lldb_private::ConstString basename) override
Definition: PlatformPOSIX.cpp:1009
lldb_private::OptionGroupPlatformSSH
Definition: Platform.h:1050
lldb_private::Status::Fail
bool Fail() const
Test for error condition.
Definition: Status.cpp:182
lldb_private::StreamString::Clear
void Clear()
Definition: StreamString.cpp:31
lldb_private::StreamString::GetData
const char * GetData() const
Definition: StreamString.h:43
lldb::eExpressionCompleted
@ eExpressionCompleted
Definition: lldb-enumerations.h:271
lldb_private::RemoteAwarePlatform::m_remote_platform_sp
lldb::PlatformSP m_remote_platform_sp
Definition: RemoteAwarePlatform.h:104
StreamString.h
lldb_private::FileAction::Dump
void Dump(Stream &stream) const
Definition: FileAction.cpp:71
lldb_private::FunctionCaller::GetArgumentValues
ValueList GetArgumentValues() const
Definition: FunctionCaller.h:286
lldb_private::Platform::SetSSHOpts
virtual void SetSSHOpts(const char *opts)
Definition: Platform.h:609
PlatformPOSIX::GetConnectionOptions
lldb_private::OptionGroupOptions * GetConnectionOptions(lldb_private::CommandInterpreter &interpreter) override
Definition: PlatformPOSIX.cpp:51
lldb_private::Target::CreateUtilityFunction
llvm::Expected< std::unique_ptr< UtilityFunction > > CreateUtilityFunction(std::string expression, std::string name, lldb::LanguageType language, ExecutionContext &exe_ctx)
Creates and installs a UtilityFunction for the given language.
Definition: Target.cpp:2323
lldb_private::Process::GetAddressByteSize
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3307
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::Platform::GetSupportsRSync
virtual bool GetSupportsRSync()
Definition: Platform.h:589
lldb_private::Scalar::UInt
unsigned int UInt(unsigned int fail_value=0) const
Definition: Scalar.cpp:320
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
PlatformPOSIX::m_options
std::map< lldb_private::CommandInterpreter *, std::unique_ptr< lldb_private::OptionGroupOptions > > m_options
Definition: PlatformPOSIX.h:86
lldb_private::TargetList::CreateTarget
Status CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path, llvm::StringRef triple_str, LoadDependentFiles get_dependent_modules, const OptionGroupPlatform *platform_options, lldb::TargetSP &target_sp)
Create a new Target.
lldb_private::ProcessLaunchInfo::GetFileActionAtIndex
const FileAction * GetFileActionAtIndex(size_t idx) const
Definition: ProcessLaunchInfo.cpp:111
PlatformPOSIX::m_option_group_platform_caching
std::unique_ptr< lldb_private::OptionGroupPlatformCaching > m_option_group_platform_caching
Definition: PlatformPOSIX.h:82
lldb_private::CommandInterpreter
Definition: CommandInterpreter.h:221
lldb_private::ProcessLaunchInfo::GetListener
lldb::ListenerSP GetListener() const
Definition: ProcessLaunchInfo.h:128
lldb_private::DynamicLoader
Definition: DynamicLoader.h:52
lldb::eBasicTypeVoid
@ eBasicTypeVoid
Definition: lldb-enumerations.h:742
lldb_private::Platform::GetSupportsSSH
virtual bool GetSupportsSSH()
Definition: Platform.h:603
lldb_private::ProcessAttachInfo::SetHijackListener
void SetHijackListener(const lldb::ListenerSP &listener_sp)
Definition: Process.h:183
lldb_private::Debugger
Definition: Debugger.h:70
HostInfo.h
lldb_private::Process::GetDynamicLoader
virtual DynamicLoader * GetDynamicLoader()
Get the dynamic loader plug-in for this process.
Definition: Process.cpp:2616
lldb::eLanguageTypeObjC
@ eLanguageTypeObjC
Objective-C.
Definition: lldb-enumerations.h:453
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:38
lldb_private::EvaluateExpressionOptions::SetUnwindOnError
void SetUnwindOnError(bool unwind=false)
Definition: Target.h:302
Thread.h
lldb_private::ProcessLaunchInfo::SetLaunchInSeparateProcessGroup
void SetLaunchInSeparateProcessGroup(bool separate)
Definition: ProcessLaunchInfo.cpp:152
lldb_private::ProcessLaunchInfo::GetPTY
PseudoTerminal & GetPTY()
Definition: ProcessLaunchInfo.h:125
ValueObject.h
lldb_private::ProcessAttachInfo
Definition: Process.h:113
lldb_private::Platform::SetSupportsRSync
virtual void SetSupportsRSync(bool flag)
Definition: Platform.h:591
lldb_private::Debugger::GetTargetList
TargetList & GetTargetList()
Get accessor for the target list.
Definition: Debugger.h:223
UtilityFunction.h
lldb_private::Platform::GetIgnoresRemoteHostname
virtual bool GetIgnoresRemoteHostname()
Definition: Platform.h:611
PlatformPOSIX::UnloadImage
lldb_private::Status UnloadImage(lldb_private::Process *process, uint32_t image_token) override
Definition: PlatformPOSIX.cpp:972
lldb_private::Platform::IsRemote
bool IsRemote() const
Definition: Platform.h:446
lldb_private::FileSpec::Clear
void Clear()
Clears the object state.
Definition: FileSpec.cpp:261
lldb_private::EvaluateExpressionOptions::SetIgnoreBreakpoints
void SetIgnoreBreakpoints(bool ignore=false)
Definition: Target.h:306
lldb_private::ExecutionContext::GetProcessSP
const lldb::ProcessSP & GetProcessSP() const
Get accessor to get the process shared pointer.
Definition: ExecutionContext.h:458
PlatformPOSIX::MakeLoadImageUtilityFunction
std::unique_ptr< lldb_private::UtilityFunction > MakeLoadImageUtilityFunction(lldb_private::ExecutionContext &exe_ctx, lldb_private::Status &error)
Definition: PlatformPOSIX.cpp:574
lldb_private::Status
Definition: Status.h:44
lldb_private::CompilerType::GetPointerType
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
Definition: CompilerType.cpp:407
lldb_private::PseudoTerminal::ReleasePrimaryFileDescriptor
int ReleasePrimaryFileDescriptor()
Release the primary file descriptor.
Definition: PseudoTerminal.cpp:185
PlatformPOSIX::GetLibdlFunctionDeclarations
virtual llvm::StringRef GetLibdlFunctionDeclarations(lldb_private::Process *process)
Definition: PlatformPOSIX.cpp:1000
lldb_private::RemoteAwarePlatform::WriteFile
uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src, uint64_t src_len, Status &error) override
Definition: RemoteAwarePlatform.cpp:246
lldb_private::Platform::SetRSyncOpts
virtual void SetRSyncOpts(const char *opts)
Definition: Platform.h:595
uint32_t
PlatformPOSIX::m_option_group_platform_rsync
std::unique_ptr< lldb_private::OptionGroupPlatformRSync > m_option_group_platform_rsync
Definition: PlatformPOSIX.h:78
LLDB_INVALID_IMAGE_TOKEN
#define LLDB_INVALID_IMAGE_TOKEN
Definition: lldb-defines.h:88
lldb_private::Platform::SetRSyncPrefix
virtual void SetRSyncPrefix(const char *prefix)
Definition: Platform.h:599
lldb_private::Process::AddImageToken
size_t AddImageToken(lldb::addr_t image_ptr)
Definition: Process.cpp:5794
lldb_private::Platform::GetRSyncPrefix
virtual const char * GetRSyncPrefix()
Definition: Platform.h:597
lldb_private::DiagnosticManager
Definition: DiagnosticManager.h:93
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
PlatformPOSIX::~PlatformPOSIX
~PlatformPOSIX() override
Destructor.
Definition: PlatformPOSIX.cpp:49
lldb_private::ProcessLaunchInfo::GetHijackListener
lldb::ListenerSP GetHijackListener() const
Definition: ProcessLaunchInfo.h:134
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
lldb_private::ConstString::GetCString
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:242
lldb_private::Platform
Definition: Platform.h:72
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
DiagnosticManager.h
lldb_private::DiagnosticManager::Clear
void Clear()
Definition: DiagnosticManager.h:95
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::FunctionCaller::ExecuteFunction
lldb::ExpressionResults ExecuteFunction(ExecutionContext &exe_ctx, lldb::addr_t *args_addr_ptr, const EvaluateExpressionOptions &options, DiagnosticManager &diagnostic_manager, Value &results)
Run the function this FunctionCaller was created with.
Definition: FunctionCaller.cpp:313
lldb_private::Process::GetImagePtrFromToken
lldb::addr_t GetImagePtrFromToken(size_t token) const
Definition: Process.cpp:5799
lldb_private::TypeSystemClang::GetBasicType
CompilerType GetBasicType(lldb::BasicType type)
Definition: TypeSystemClang.cpp:940
FileSpec.h
PlatformPOSIX.h
lldb_private::Flags::Set
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
Definition: Flags.h:73
lldb_private::TypeSystemClang
A TypeSystem implementation based on Clang.
Definition: TypeSystemClang.h:106
PlatformPOSIX::GetPlatformSpecificConnectionInformation
std::string GetPlatformSpecificConnectionInformation() override
Definition: PlatformPOSIX.cpp:265
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
PlatformPOSIX::DebugProcess
lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info, lldb_private::Debugger &debugger, lldb_private::Target *target, lldb_private::Status &error) override
Subclasses do not need to implement this function as it uses the Platform::LaunchProcess() followed b...
Definition: PlatformPOSIX.cpp:414
lldb_private::Log
Definition: Log.h:49
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
PlatformPOSIX::Attach
lldb::ProcessSP Attach(lldb_private::ProcessAttachInfo &attach_info, lldb_private::Debugger &debugger, lldb_private::Target *target, lldb_private::Status &error) override
Attach to an existing process using a process ID.
Definition: PlatformPOSIX.cpp:359
lldb_private::FileSpec::SetFile
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition: FileSpec.cpp:174
lldb_private::PluginInterface::GetPluginName
virtual ConstString GetPluginName()=0
lldb_private::Process::ReadPointerFromMemory
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
Definition: Process.cpp:2098
lldb_private::GetLogIfAnyCategoriesSet
Log * GetLogIfAnyCategoriesSet(uint32_t mask)
Definition: Logging.cpp:62
lldb_private::Platform::IsHost
bool IsHost() const
Definition: Platform.h:442
lldb_private::Platform::SetIgnoresRemoteHostname
virtual void SetIgnoresRemoteHostname(bool flag)
Definition: Platform.h:613
lldb_private::FileSpec::GetPath
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:348
lldb_private::ProcessAttachInfo::GetHijackListener
lldb::ListenerSP GetHijackListener() const
Definition: Process.h:181
lldb_private::Process::GetLoadImageUtilityFunction
UtilityFunction * GetLoadImageUtilityFunction(Platform *platform, llvm::function_ref< std::unique_ptr< UtilityFunction >()> factory)
Get the cached UtilityFunction that assists in loading binary images into the process.
Definition: Process.cpp:6007
PlatformPOSIX::CalculateTrapHandlerSymbolNames
void CalculateTrapHandlerSymbolNames() override
Ask the Platform subclass to fill in the list of trap handler names.
Definition: PlatformPOSIX.cpp:528
DynamicLoader.h
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
lldb_private::RemoteAwarePlatform
A base class for platforms which automatically want to be able to forward operations to a remote plat...
Definition: RemoteAwarePlatform.h:18
lldb
Definition: SBAddress.h:15
lldb_private::ThreadList::GetExpressionExecutionThread
lldb::ThreadSP GetExpressionExecutionThread()
Definition: ThreadList.cpp:59
File.h
ExecutionContext.h
lldb_private::RemoteAwarePlatform::GetHostname
const char * GetHostname() override
Definition: RemoteAwarePlatform.cpp:355
DataBufferHeap.h
UINT64_MAX
#define UINT64_MAX
Definition: lldb-defines.h:35
lldb_private::UtilityFunction
Definition: UtilityFunction.h:30
lldb_private::RemoteAwarePlatform::RunShellCommand
Status RunShellCommand(llvm::StringRef command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, const Timeout< std::micro > &timeout) override
Definition: RemoteAwarePlatform.cpp:173
lldb_private::Status::AsCString
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:131
lldb_private::FunctionCaller
Definition: FunctionCaller.h:56
lldb_private::Process::ResetImageToken
void ResetImageToken(size_t token)
Definition: Process.cpp:5805
lldb::eLanguageTypeC_plus_plus
@ eLanguageTypeC_plus_plus
ISO C++:1998.
Definition: lldb-enumerations.h:441