summaryrefslogtreecommitdiffstats
path: root/lldb/source/Commands/CommandObjectProcess.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2010-11-04 01:54:29 +0000
committerGreg Clayton <gclayton@apple.com>2010-11-04 01:54:29 +0000
commit8f343b09e946cce2ef79461b5a86d987f6a31748 (patch)
tree5e3d5709fe5b7468e9d24fa01ca2be63a81e5be5 /lldb/source/Commands/CommandObjectProcess.cpp
parent10af7c430a426ab649ac000152bc51c3601eb395 (diff)
downloadbcm5719-llvm-8f343b09e946cce2ef79461b5a86d987f6a31748.tar.gz
bcm5719-llvm-8f343b09e946cce2ef79461b5a86d987f6a31748.zip
Added support for loading and unloading shared libraries. This was done by
adding support into lldb_private::Process: virtual uint32_t lldb_private::Process::LoadImage (const FileSpec &image_spec, Error &error); virtual Error lldb_private::Process::UnloadImage (uint32_t image_token); There is a default implementation that should work for both linux and MacOSX. This ability has also been exported through the SBProcess API: uint32_t lldb::SBProcess::LoadImage (lldb::SBFileSpec &image_spec, lldb::SBError &error); lldb::SBError lldb::SBProcess::UnloadImage (uint32_t image_token); Modified the DynamicLoader plug-in interface to require it to be able to tell us if it is currently possible to load/unload a shared library: virtual lldb_private::Error DynamicLoader::CanLoadImage () = 0; This way the dynamic loader plug-ins are allows to veto whether we can currently load a shared library since the dynamic loader might know if it is currenlty loading/unloading shared libraries. It might also know about the current host system and know where to check to make sure runtime or malloc locks are currently being held. Modified the expression parser to have ClangUserExpression::Evaluate() be the one that causes the dynamic checkers to be loaded instead of other code that shouldn't have to worry about it. llvm-svn: 118227
Diffstat (limited to 'lldb/source/Commands/CommandObjectProcess.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectProcess.cpp124
1 files changed, 124 insertions, 0 deletions
diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp
index 8c4ffdd96bb..88fdca3086b 100644
--- a/lldb/source/Commands/CommandObjectProcess.cpp
+++ b/lldb/source/Commands/CommandObjectProcess.cpp
@@ -853,6 +853,128 @@ public:
};
//-------------------------------------------------------------------------
+// CommandObjectProcessLoad
+//-------------------------------------------------------------------------
+
+class CommandObjectProcessLoad : public CommandObject
+{
+public:
+
+ CommandObjectProcessLoad (CommandInterpreter &interpreter) :
+ CommandObject (interpreter,
+ "process load",
+ "Load a shared library into the current process.",
+ "process load <filename> [<filename> ...]",
+ eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
+ {
+ }
+
+ ~CommandObjectProcessLoad ()
+ {
+ }
+
+ bool
+ Execute (Args& command,
+ CommandReturnObject &result)
+ {
+ Process *process = m_interpreter.GetDebugger().GetExecutionContext().process;
+ if (process == NULL)
+ {
+ result.AppendError ("must have a valid process in order to load a shared library");
+ result.SetStatus (eReturnStatusFailed);
+ return false;
+ }
+
+ const uint32_t argc = command.GetArgumentCount();
+
+ for (uint32_t i=0; i<argc; ++i)
+ {
+ Error error;
+ const char *image_path = command.GetArgumentAtIndex(i);
+ FileSpec image_spec (image_path, false);
+ uint32_t image_token = process->LoadImage(image_spec, error);
+ if (image_token != LLDB_INVALID_IMAGE_TOKEN)
+ {
+ result.AppendMessageWithFormat ("Loading \"%s\"...ok\nImage %u loaded.\n", image_path, image_token);
+ result.SetStatus (eReturnStatusSuccessFinishResult);
+ }
+ else
+ {
+ result.AppendErrorWithFormat ("failed to load '%s': %s", image_path, error.AsCString());
+ result.SetStatus (eReturnStatusFailed);
+ }
+ }
+ return result.Succeeded();
+ }
+};
+
+
+//-------------------------------------------------------------------------
+// CommandObjectProcessUnload
+//-------------------------------------------------------------------------
+
+class CommandObjectProcessUnload : public CommandObject
+{
+public:
+
+ CommandObjectProcessUnload (CommandInterpreter &interpreter) :
+ CommandObject (interpreter,
+ "process unload",
+ "Unload a shared library from the current process using the index returned by a previous call to \"process load\".",
+ "process unload <index>",
+ eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
+ {
+ }
+
+ ~CommandObjectProcessUnload ()
+ {
+ }
+
+ bool
+ Execute (Args& command,
+ CommandReturnObject &result)
+ {
+ Process *process = m_interpreter.GetDebugger().GetExecutionContext().process;
+ if (process == NULL)
+ {
+ result.AppendError ("must have a valid process in order to load a shared library");
+ result.SetStatus (eReturnStatusFailed);
+ return false;
+ }
+
+ const uint32_t argc = command.GetArgumentCount();
+
+ for (uint32_t i=0; i<argc; ++i)
+ {
+ const char *image_token_cstr = command.GetArgumentAtIndex(i);
+ uint32_t image_token = Args::StringToUInt32(image_token_cstr, LLDB_INVALID_IMAGE_TOKEN, 0);
+ if (image_token == LLDB_INVALID_IMAGE_TOKEN)
+ {
+ result.AppendErrorWithFormat ("invalid image index argument '%s'", image_token_cstr);
+ result.SetStatus (eReturnStatusFailed);
+ break;
+ }
+ else
+ {
+ Error error (process->UnloadImage(image_token));
+ if (error.Success())
+ {
+ result.AppendMessageWithFormat ("Unloading shared library with index %u...ok\n", image_token);
+ result.SetStatus (eReturnStatusSuccessFinishResult);
+ }
+ else
+ {
+ result.AppendErrorWithFormat ("failed to unload image: %s", error.AsCString());
+ result.SetStatus (eReturnStatusFailed);
+ break;
+ }
+ }
+ }
+ return result.Succeeded();
+ }
+};
+
+//-------------------------------------------------------------------------
// CommandObjectProcessSignal
//-------------------------------------------------------------------------
@@ -1450,6 +1572,8 @@ CommandObjectMultiwordProcess::CommandObjectMultiwordProcess (CommandInterpreter
LoadSubCommand ("launch", CommandObjectSP (new CommandObjectProcessLaunch (interpreter)));
LoadSubCommand ("continue", CommandObjectSP (new CommandObjectProcessContinue (interpreter)));
LoadSubCommand ("detach", CommandObjectSP (new CommandObjectProcessDetach (interpreter)));
+ LoadSubCommand ("load", CommandObjectSP (new CommandObjectProcessLoad (interpreter)));
+ LoadSubCommand ("unload", CommandObjectSP (new CommandObjectProcessUnload (interpreter)));
LoadSubCommand ("signal", CommandObjectSP (new CommandObjectProcessSignal (interpreter)));
LoadSubCommand ("handle", CommandObjectSP (new CommandObjectProcessHandle (interpreter)));
LoadSubCommand ("status", CommandObjectSP (new CommandObjectProcessStatus (interpreter)));
OpenPOWER on IntegriCloud