Author: abidh Date: Tue Jan 24 17:07:27 2017 New Revision: 292989 URL: http://llvm.org/viewvc/llvm-project?rev=292989&view=rev Log: Provide option to set pc of the file loaded in memory.
Summary: This commit adds an option to set PC to the entry point of the file loaded using "target module load" command. In D28804, Greg asked me to separate this part under a different option. Reviewers: clayborg Reviewed By: clayborg Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D28944 Modified: lldb/trunk/include/lldb/Core/Module.h lldb/trunk/include/lldb/Symbol/ObjectFile.h lldb/trunk/source/Commands/CommandObjectTarget.cpp lldb/trunk/source/Core/Module.cpp lldb/trunk/source/Symbol/ObjectFile.cpp Modified: lldb/trunk/include/lldb/Core/Module.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=292989&r1=292988&r2=292989&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Module.h (original) +++ lldb/trunk/include/lldb/Core/Module.h Tue Jan 24 17:07:27 2017 @@ -974,7 +974,7 @@ public: /// /// @return //------------------------------------------------------------------ - Error LoadInMemory(Target &target); + Error LoadInMemory(Target &target, bool set_pc); //---------------------------------------------------------------------- /// @class LookupInfo Module.h "lldb/Core/Module.h" Modified: lldb/trunk/include/lldb/Symbol/ObjectFile.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ObjectFile.h?rev=292989&r1=292988&r2=292989&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/ObjectFile.h (original) +++ lldb/trunk/include/lldb/Symbol/ObjectFile.h Tue Jan 24 17:07:27 2017 @@ -786,7 +786,7 @@ public: /// /// @return //------------------------------------------------------------------ - virtual Error LoadInMemory(Target &target); + virtual Error LoadInMemory(Target &target, bool set_pc); protected: //------------------------------------------------------------------ Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=292989&r1=292988&r2=292989&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Tue Jan 24 17:07:27 2017 @@ -2568,8 +2568,11 @@ public: m_file_option(LLDB_OPT_SET_1, false, "file", 'f', 0, eArgTypeName, "Fullpath or basename for module to load.", ""), m_load_option(LLDB_OPT_SET_1, false, "load", 'l', - "Write file contents to the memory.", - false, true), + "Write file contents to the memory.", false, true), + m_pc_option(LLDB_OPT_SET_1, false, "--set-pc-to-entry", 'p', + "Set PC to the entry point." + " Only applicable with '--load' option.", + false, true), m_slide_option(LLDB_OPT_SET_1, false, "slide", 's', 0, eArgTypeOffset, "Set the load address for all sections to be the " "virtual address in the file plus the offset.", @@ -2578,6 +2581,7 @@ public: LLDB_OPT_SET_1); m_option_group.Append(&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); m_option_group.Append(&m_load_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); + m_option_group.Append(&m_pc_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); m_option_group.Append(&m_slide_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); m_option_group.Finalize(); } @@ -2590,6 +2594,7 @@ protected: bool DoExecute(Args &args, CommandReturnObject &result) override { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); const bool load = m_load_option.GetOptionValue().GetCurrentValue(); + const bool set_pc = m_pc_option.GetOptionValue().GetCurrentValue(); if (target == nullptr) { result.AppendError("invalid target, create a debug target using the " "'target create' command"); @@ -2742,7 +2747,7 @@ protected: process->Flush(); } if (load) { - Error error = module->LoadInMemory(*target); + Error error = module->LoadInMemory(*target, set_pc); if (error.Fail()) { result.AppendError(error.AsCString()); return false; @@ -2811,6 +2816,7 @@ protected: OptionGroupUUID m_uuid_option_group; OptionGroupString m_file_option; OptionGroupBoolean m_load_option; + OptionGroupBoolean m_pc_option; OptionGroupUInt64 m_slide_option; }; Modified: lldb/trunk/source/Core/Module.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=292989&r1=292988&r2=292989&view=diff ============================================================================== --- lldb/trunk/source/Core/Module.cpp (original) +++ lldb/trunk/source/Core/Module.cpp Tue Jan 24 17:07:27 2017 @@ -1665,6 +1665,6 @@ bool Module::GetIsDynamicLinkEditor() { return false; } -Error Module::LoadInMemory(Target &target) { - return m_objfile_sp->LoadInMemory(target); +Error Module::LoadInMemory(Target &target, bool set_pc) { + return m_objfile_sp->LoadInMemory(target, set_pc); } Modified: lldb/trunk/source/Symbol/ObjectFile.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ObjectFile.cpp?rev=292989&r1=292988&r2=292989&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ObjectFile.cpp (original) +++ lldb/trunk/source/Symbol/ObjectFile.cpp Tue Jan 24 17:07:27 2017 @@ -652,11 +652,13 @@ ConstString ObjectFile::GetNextSynthetic return ConstString(ss.GetString()); } -Error ObjectFile::LoadInMemory(Target &target) { +Error ObjectFile::LoadInMemory(Target &target, bool set_pc) { Error error; ProcessSP process = target.CalculateProcess(); if (!process) return Error("No Process"); + if (set_pc && !GetEntryPointAddress().IsValid()) + return Error("No entry address in object file"); SectionList *section_list = GetSectionList(); if (!section_list) @@ -677,5 +679,12 @@ Error ObjectFile::LoadInMemory(Target &t return error; } } + if (set_pc) { + ThreadList &thread_list = process->GetThreadList(); + ThreadSP curr_thread(thread_list.GetSelectedThread()); + RegisterContextSP reg_context(curr_thread->GetRegisterContext()); + Address file_entry = GetEntryPointAddress(); + reg_context->SetPC(file_entry.GetLoadAddress(&target)); + } return error; } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits