Index: include/lldb/API/SBThread.h =================================================================== --- include/lldb/API/SBThread.h +++ include/lldb/API/SBThread.h @@ -117,6 +117,9 @@ lldb::SBFileSpec &file_spec, uint32_t line); + SBError + JumpToLine (lldb::SBFileSpec &file_spec, uint32_t line); + void RunToAddress (lldb::addr_t addr); Index: include/lldb/Core/Error.h =================================================================== --- include/lldb/Core/Error.h +++ include/lldb/Core/Error.h @@ -68,7 +68,7 @@ Error (ValueType err, lldb::ErrorType type = lldb::eErrorTypeGeneric); explicit - Error (const char* err_str); + Error (const char *format, ...) __attribute__ ((format (printf, 2, 3))); Error (const Error &rhs); //------------------------------------------------------------------ Index: include/lldb/Core/Module.h =================================================================== --- include/lldb/Core/Module.h +++ include/lldb/Core/Module.h @@ -347,6 +347,32 @@ SymbolContextList& sc_list); //------------------------------------------------------------------ + /// Find addresses by file/line + /// + /// @param[in] target_sp + /// The target the addresses are desired for. + /// + /// @param[in] file + /// Source file to locate. + /// + /// @param[in] line + /// Source line to locate. + /// + /// @param[in] function + /// Optional filter function. Addresses within this function will be + /// added to the 'local' list. All others will be added to the 'extern' list. + /// + /// @param[out] output_local + /// All matching addresses within 'function' + /// + /// @param[out] output_extern + /// All matching addresses not within 'function' + void FindAddressesForLine (const lldb::TargetSP target_sp, + const FileSpec &file, uint32_t line, + Function *function, + std::vector
&output_local, std::vector &output_extern); + + //------------------------------------------------------------------ /// Find global and static variables by name. /// /// @param[in] name Index: include/lldb/Core/ModuleList.h =================================================================== --- include/lldb/Core/ModuleList.h +++ include/lldb/Core/ModuleList.h @@ -439,7 +439,35 @@ bool FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const; - + + + //------------------------------------------------------------------ + /// Find addresses by file/line + /// + /// @param[in] target_sp + /// The target the addresses are desired for. + /// + /// @param[in] file + /// Source file to locate. + /// + /// @param[in] line + /// Source line to locate. + /// + /// @param[in] function + /// Optional filter function. Addresses within this function will be + /// added to the 'local' list. All others will be added to the 'extern' list. + /// + /// @param[out] output_local + /// All matching addresses within 'function' + /// + /// @param[out] output_extern + /// All matching addresses not within 'function' + void FindAddressesForLine (const lldb::TargetSP target_sp, + const FileSpec &file, uint32_t line, + Function *function, + std::vector &output_local, std::vector &output_extern); + + bool Remove (const lldb::ModuleSP &module_sp); Index: include/lldb/Target/RegisterContext.h =================================================================== --- include/lldb/Target/RegisterContext.h +++ include/lldb/Target/RegisterContext.h @@ -129,6 +129,8 @@ bool SetPC (uint64_t pc); + bool SetPC (Address addr); + uint64_t GetSP (uint64_t fail_value = LLDB_INVALID_ADDRESS); Index: include/lldb/Target/Thread.h =================================================================== --- include/lldb/Target/Thread.h +++ include/lldb/Target/Thread.h @@ -377,7 +377,10 @@ Error ReturnFromFrame (lldb::StackFrameSP frame_sp, lldb::ValueObjectSP return_value_sp, bool broadcast = false); - + + Error + JumpToLine (const FileSpec &file, uint32_t line, bool can_leave_function, std::string *warnings = NULL); + virtual lldb::StackFrameSP GetFrameWithStackID (const StackID &stack_id) { Index: scripts/Python/interface/SBThread.i =================================================================== --- scripts/Python/interface/SBThread.i +++ scripts/Python/interface/SBThread.i @@ -136,10 +136,13 @@ StepInstruction(bool step_over); SBError - StepOverUntil (lldb::SBFrame &frame, - lldb::SBFileSpec &file_spec, + StepOverUntil (lldb::SBFrame &frame, + lldb::SBFileSpec &file_spec, uint32_t line); + SBError + JumpToLine (lldb::SBFileSpec &file_spec, uint32_t line); + void RunToAddress (lldb::addr_t addr); Index: source/API/SBThread.cpp =================================================================== --- source/API/SBThread.cpp +++ source/API/SBThread.cpp @@ -910,6 +910,31 @@ } SBError +SBThread::JumpToLine (lldb::SBFileSpec &file_spec, uint32_t line) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + SBError sb_error; + + Mutex::Locker api_locker; + ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); + + if (log) + log->Printf ("SBThread(%p)::JumpToLine (file+line = %s:%u)", exe_ctx.GetThreadPtr(), file_spec->GetPath().c_str(), line); + + if (!exe_ctx.HasThreadScope()) + { + sb_error.SetErrorString("this SBThread object is invalid"); + return sb_error; + } + + Thread *thread = exe_ctx.GetThreadPtr(); + + Error err = thread->JumpToLine (file_spec.get(), line, true); + sb_error.SetError (err); + return sb_error; +} + +SBError SBThread::ReturnFromFrame (SBFrame &frame, SBValue &return_value) { SBError sb_error; Index: source/Commands/CommandObjectThread.cpp =================================================================== --- source/Commands/CommandObjectThread.cpp +++ source/Commands/CommandObjectThread.cpp @@ -1463,6 +1463,208 @@ }; //------------------------------------------------------------------------- +// CommandObjectThreadJump +//------------------------------------------------------------------------- + +class CommandObjectThreadJump : public CommandObjectParsed +{ +public: + class CommandOptions : public Options + { + public: + + CommandOptions (CommandInterpreter &interpreter) : + Options (interpreter) + { + OptionParsingStarting (); + } + + void + OptionParsingStarting () + { + m_filenames.Clear(); + m_line_num = 0; + m_line_offset = 0; + m_load_addr = LLDB_INVALID_ADDRESS; + m_force = false; + } + + virtual + ~CommandOptions () + { + } + + virtual Error + SetOptionValue (uint32_t option_idx, const char *option_arg) + { + bool success; + const int short_option = m_getopt_table[option_idx].val; + Error error; + + switch (short_option) + { + case 'f': + m_filenames.AppendIfUnique (FileSpec(option_arg, false)); + if (m_filenames.GetSize() > 1) + return Error("only one source file expected."); + break; + case 'l': + m_line_num = Args::StringToUInt32 (option_arg, 0, 0, &success); + if (!success || m_line_num == 0) + return Error("invalid line number: '%s'.", option_arg); + break; + case 'b': + m_line_offset = Args::StringToSInt32 (option_arg, 0, 0, &success); + if (!success) + return Error("invalid line offset: '%s'.", option_arg); + break; + case 'a': + { + ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); + m_load_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error); + } + break; + case 'r': + m_force = true; + break; + + default: + return Error("invalid short option character '%c'", short_option); + + } + return error; + } + + const OptionDefinition* + GetDefinitions () + { + return g_option_table; + } + + FileSpecList m_filenames; + uint32_t m_line_num; + int32_t m_line_offset; + lldb::addr_t m_load_addr; + bool m_force; + + static OptionDefinition g_option_table[]; + }; + + virtual + Options * + GetOptions () + { + return &m_options; + } + + CommandObjectThreadJump (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "thread jump", + "Sets the program counter to a new address.", + "thread jump", + eFlagRequiresFrame | + eFlagTryTargetAPILock | + eFlagProcessMustBeLaunched | + eFlagProcessMustBePaused ), + m_options (interpreter) + { + } + + ~CommandObjectThreadJump() + { + } + +protected: + + bool DoExecute (Args& args, CommandReturnObject &result) + { + RegisterContext *reg_ctx = m_exe_ctx.GetRegisterContext(); + StackFrame *frame = m_exe_ctx.GetFramePtr(); + Thread *thread = m_exe_ctx.GetThreadPtr(); + Target *target = m_exe_ctx.GetTargetPtr(); + const SymbolContext &sym_ctx = frame->GetSymbolContext (eSymbolContextLineEntry); + + if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) + { + // Use this address directly. + Address dest = Address(m_options.m_load_addr); + + lldb::addr_t callAddr = dest.GetCallableLoadAddress (target); + if (callAddr == LLDB_INVALID_ADDRESS) + { + result.AppendErrorWithFormat ("Invalid destination address."); + result.SetStatus (eReturnStatusFailed); + return false; + } + + if (!reg_ctx->SetPC (callAddr)) + { + result.AppendErrorWithFormat ("Error changing PC value for thread %d.", thread->GetIndexID()); + result.SetStatus (eReturnStatusFailed); + return false; + } + } + else + { + // Pick either the absolute line, or work out a relative one. + int32_t line = (int32_t)m_options.m_line_num; + if (line == 0) + line = sym_ctx.line_entry.line + m_options.m_line_offset; + + // Try the current file, but override if asked. + FileSpec file = sym_ctx.line_entry.file; + if (m_options.m_filenames.GetSize() == 1) + file = m_options.m_filenames.GetFileSpecAtIndex(0); + + if (!file) + { + result.AppendErrorWithFormat ("No source file available for the current location."); + result.SetStatus (eReturnStatusFailed); + return false; + } + + std::string warnings; + Error err = thread->JumpToLine (file, line, m_options.m_force, &warnings); + + if (err.Fail()) + { + result.SetError (err); + return false; + } + + if (!warnings.empty()) + result.AppendWarning (warnings.c_str()); + } + + result.SetStatus (eReturnStatusSuccessFinishResult); + return true; + } + + CommandOptions m_options; +}; +OptionDefinition +CommandObjectThreadJump::CommandOptions::g_option_table[] = +{ + { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, + "Specifies the source file to jump to."}, + + { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, + "Specifies the line number to jump to."}, + + { LLDB_OPT_SET_2, true, "by", 'b', required_argument, NULL, 0, eArgTypeOffset, + "Jumps by a relative line offset from the current line."}, + + { LLDB_OPT_SET_3, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddressOrExpression, + "Jumps to a specific address."}, + + { LLDB_OPT_SET_1| + LLDB_OPT_SET_2| + LLDB_OPT_SET_3, false, "force",'r', no_argument, NULL, 0, eArgTypeNone,"Allows the PC to leave the current function."}, + + { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } +}; + +//------------------------------------------------------------------------- // CommandObjectMultiwordThread //------------------------------------------------------------------------- @@ -1476,6 +1678,7 @@ LoadSubCommand ("continue", CommandObjectSP (new CommandObjectThreadContinue (interpreter))); LoadSubCommand ("list", CommandObjectSP (new CommandObjectThreadList (interpreter))); LoadSubCommand ("return", CommandObjectSP (new CommandObjectThreadReturn (interpreter))); + LoadSubCommand ("jump", CommandObjectSP (new CommandObjectThreadJump (interpreter))); LoadSubCommand ("select", CommandObjectSP (new CommandObjectThreadSelect (interpreter))); LoadSubCommand ("until", CommandObjectSP (new CommandObjectThreadUntil (interpreter))); LoadSubCommand ("step-in", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( Index: source/Core/Error.cpp =================================================================== --- source/Core/Error.cpp +++ source/Core/Error.cpp @@ -52,12 +52,16 @@ { } -Error::Error (const char* err_str): +Error::Error (const char* format, ...): m_code (0), m_type (eErrorTypeInvalid), m_string () { - SetErrorString(err_str); + va_list args; + va_start (args, format); + SetErrorToGenericError (); + SetErrorStringWithVarArg (format, args); + va_end (args); } //---------------------------------------------------------------------- Index: source/Core/Module.cpp =================================================================== --- source/Core/Module.cpp +++ source/Core/Module.cpp @@ -9,6 +9,7 @@ #include "lldb/lldb-python.h" +#include "lldb/Core/AddressResolverFileLine.h" #include "lldb/Core/Error.h" #include "lldb/Core/Module.h" #include "lldb/Core/DataBuffer.h" @@ -752,6 +753,27 @@ return sc_list.GetSize() - start_size; } +void +Module::FindAddressesForLine (const lldb::TargetSP target_sp, + const FileSpec &file, uint32_t line, + Function *function, + std::vector &output_local, std::vector &output_extern) +{ + SearchFilterByModule filter(target_sp, m_file); + AddressResolverFileLine resolver(file, line, true); + resolver.ResolveAddress (filter); + + for (size_t n=0;n