virtual bool DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); if (!CheckTargetForWatchpointOperations(target, result)) return false; Mutex::Locker locker; target->GetWatchpointList().GetListMutex(locker); const WatchpointList &watchpoints = target->GetWatchpointList(); size_t num_watchpoints = watchpoints.GetSize(); if (num_watchpoints == 0) { result.AppendError("No watchpoints exist to be ignored."); result.SetStatus(eReturnStatusFailed); return false; } if (command.GetArgumentCount() == 0) { target->IgnoreAllWatchpoints(m_options.m_ignore_count); result.AppendMessageWithFormat("All watchpoints ignored. (%lu watchpoints)\n", num_watchpoints); result.SetStatus (eReturnStatusSuccessFinishNoResult); } else { // Particular watchpoints selected; ignore them. std::vector<uint32_t> wp_ids; if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(command, wp_ids)) { result.AppendError("Invalid watchpoints specification."); result.SetStatus(eReturnStatusFailed); return false; } int count = 0; const size_t size = wp_ids.size(); for (size_t i = 0; i < size; ++i) if (target->IgnoreWatchpointByID(wp_ids[i], m_options.m_ignore_count)) ++count; result.AppendMessageWithFormat("%d watchpoints ignored.\n",count); result.SetStatus (eReturnStatusSuccessFinishNoResult); } return result.Succeeded(); }
void CommandInterpreter::ShowVariableHelp (CommandReturnObject &result) { result.AppendMessage ("Below is a list of all the internal debugger variables that are settable:"); for (VariableMap::const_iterator pos = m_variables.begin(); pos != m_variables.end(); ++pos) { StateVariable *var = pos->second.get(); result.AppendMessageWithFormat (" %s -- %s \n", var->GetName(), var->GetHelp()); } }
virtual bool DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); if (!CheckTargetForWatchpointOperations(target, result)) return false; Mutex::Locker locker; target->GetWatchpointList().GetListMutex(locker); const WatchpointList &watchpoints = target->GetWatchpointList(); size_t num_watchpoints = watchpoints.GetSize(); if (num_watchpoints == 0) { result.AppendError("No watchpoints exist to be modified."); result.SetStatus(eReturnStatusFailed); return false; } if (command.GetArgumentCount() == 0) { WatchpointSP wp_sp = target->GetLastCreatedWatchpoint(); wp_sp->SetCondition(m_options.m_condition.c_str()); result.SetStatus (eReturnStatusSuccessFinishNoResult); } else { // Particular watchpoints selected; set condition on them. std::vector<uint32_t> wp_ids; if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, wp_ids)) { result.AppendError("Invalid watchpoints specification."); result.SetStatus(eReturnStatusFailed); return false; } int count = 0; const size_t size = wp_ids.size(); for (size_t i = 0; i < size; ++i) { WatchpointSP wp_sp = watchpoints.FindByID(wp_ids[i]); if (wp_sp) { wp_sp->SetCondition(m_options.m_condition.c_str()); ++count; } } result.AppendMessageWithFormat("%d watchpoints modified.\n",count); result.SetStatus (eReturnStatusSuccessFinishNoResult); } return result.Succeeded(); }
void CommandInterpreter::GetHelp (CommandReturnObject &result) { CommandObject::CommandMap::const_iterator pos; result.AppendMessage("The following is a list of built-in, permanent debugger commands:"); result.AppendMessage(""); std::string longest_word = FindLongestCommandWord (m_command_dict); uint32_t max_len = strlen (longest_word.c_str()); for (pos = m_command_dict.begin(); pos != m_command_dict.end(); ++pos) { OutputFormattedHelpText (result.GetOutputStream(), pos->first.c_str(), "--", pos->second->GetHelp(), max_len); } result.AppendMessage(""); if (m_alias_dict.size() > 0) { result.AppendMessage("The following is a list of your current command abbreviations (see 'alias' for more info):"); result.AppendMessage(""); longest_word = FindLongestCommandWord (m_alias_dict); max_len = strlen (longest_word.c_str()); for (pos = m_alias_dict.begin(); pos != m_alias_dict.end(); ++pos) { StreamString sstr; StreamString translation_and_help; std::string entry_name = pos->first; std::string second_entry = pos->second.get()->GetCommandName(); GetAliasHelp (pos->first.c_str(), pos->second->GetCommandName(), sstr); translation_and_help.Printf ("(%s) %s", sstr.GetData(), pos->second->GetHelp()); OutputFormattedHelpText (result.GetOutputStream(), pos->first.c_str(), "--", translation_and_help.GetData(), max_len); } result.AppendMessage(""); } if (m_user_dict.size() > 0) { result.AppendMessage ("The following is a list of your current user-defined commands:"); result.AppendMessage(""); for (pos = m_user_dict.begin(); pos != m_user_dict.end(); ++pos) { result.AppendMessageWithFormat ("%s -- %s\n", pos->first.c_str(), pos->second->GetHelp()); } result.AppendMessage(""); } result.AppendMessage("For more information on any particular command, try 'help <command-name>'."); }
bool DoExecute(Args &command, CommandReturnObject &result) override { Target *target = GetSelectedOrDummyTarget(); uint32_t i = 0; for (auto &stat : target->GetStatistics()) { result.AppendMessageWithFormat( "%s : %u\n", lldb_private::GetStatDescription(static_cast<lldb_private::StatisticKind>(i)) .c_str(), stat); i += 1; } result.SetStatus(eReturnStatusSuccessFinishResult); return true; }
bool CommandObjectVersion::DoExecute (Args& args, CommandReturnObject &result) { if (args.GetArgumentCount() == 0) { result.AppendMessageWithFormat ("%s\n", lldb_private::GetVersion()); result.SetStatus (eReturnStatusSuccessFinishResult); } else { result.AppendError("the version command takes no arguments."); result.SetStatus (eReturnStatusFailed); } return true; }
bool DoExecute(Args& command, CommandReturnObject &result) override { bool demangled_any = false; bool error_any = false; for (size_t i = 0; i < command.GetArgumentCount(); i++) { auto arg = command.GetArgumentAtIndex(i); if (arg && *arg) { ConstString mangled_cs(arg); // the actual Mangled class should be strict about this, but on the command line // if you're copying mangled names out of 'nm' on Darwin, they will come out with // an extra underscore - be willing to strip this on behalf of the user // This is the moral equivalent of the -_/-n options to c++filt if (mangled_cs.GetStringRef().startswith("__Z")) mangled_cs.SetCString(arg+1); Mangled mangled(mangled_cs, true); if (mangled.GuessLanguage() == lldb::eLanguageTypeC_plus_plus) { ConstString demangled(mangled.GetDisplayDemangledName(lldb::eLanguageTypeC_plus_plus)); demangled_any = true; result.AppendMessageWithFormat("%s ---> %s\n", arg, demangled.GetCString()); } else { error_any = true; result.AppendErrorWithFormat("%s is not a valid C++ mangled name\n", arg); } } } result.SetStatus(error_any ? lldb::eReturnStatusFailed : (demangled_any ? lldb::eReturnStatusSuccessFinishResult : lldb::eReturnStatusSuccessFinishNoResult)); return result.Succeeded(); }
bool DoExecute(Args &command, CommandReturnObject &result) override { bool demangled_any = false; bool error_any = false; for (auto &entry : command.entries()) { if (entry.ref.empty()) continue; // the actual Mangled class should be strict about this, but on the // command line if you're copying mangled names out of 'nm' on Darwin, // they will come out with an extra underscore - be willing to strip // this on behalf of the user. This is the moral equivalent of the -_/-n // options to c++filt auto name = entry.ref; if (name.startswith("__Z")) name = name.drop_front(); Mangled mangled(name, true); if (mangled.GuessLanguage() == lldb::eLanguageTypeC_plus_plus) { ConstString demangled( mangled.GetDisplayDemangledName(lldb::eLanguageTypeC_plus_plus)); demangled_any = true; result.AppendMessageWithFormat("%s ---> %s\n", entry.ref.str().c_str(), demangled.GetCString()); } else { error_any = true; result.AppendErrorWithFormat("%s is not a valid C++ mangled name\n", entry.ref.str().c_str()); } } result.SetStatus( error_any ? lldb::eReturnStatusFailed : (demangled_any ? lldb::eReturnStatusSuccessFinishResult : lldb::eReturnStatusSuccessFinishNoResult)); return result.Succeeded(); }
virtual bool DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); if (target == NULL) { result.AppendError ("Invalid target. No current target or watchpoints."); result.SetStatus (eReturnStatusSuccessFinishNoResult); return true; } if (target->GetProcessSP() && target->GetProcessSP()->IsAlive()) { uint32_t num_supported_hardware_watchpoints; Error error = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints); if (error.Success()) result.AppendMessageWithFormat("Number of supported hardware watchpoints: %u\n", num_supported_hardware_watchpoints); } const WatchpointList &watchpoints = target->GetWatchpointList(); Mutex::Locker locker; target->GetWatchpointList().GetListMutex(locker); size_t num_watchpoints = watchpoints.GetSize(); if (num_watchpoints == 0) { result.AppendMessage("No watchpoints currently set."); result.SetStatus(eReturnStatusSuccessFinishNoResult); return true; } Stream &output_stream = result.GetOutputStream(); if (command.GetArgumentCount() == 0) { // No watchpoint selected; show info about all currently set watchpoints. result.AppendMessage ("Current watchpoints:"); for (size_t i = 0; i < num_watchpoints; ++i) { Watchpoint *wp = watchpoints.GetByIndex(i).get(); AddWatchpointDescription(&output_stream, wp, m_options.m_level); } result.SetStatus(eReturnStatusSuccessFinishNoResult); } else { // Particular watchpoints selected; enable them. std::vector<uint32_t> wp_ids; if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, wp_ids)) { result.AppendError("Invalid watchpoints specification."); result.SetStatus(eReturnStatusFailed); return false; } const size_t size = wp_ids.size(); for (size_t i = 0; i < size; ++i) { Watchpoint *wp = watchpoints.FindByID(wp_ids[i]).get(); if (wp) AddWatchpointDescription(&output_stream, wp, m_options.m_level); result.SetStatus(eReturnStatusSuccessFinishNoResult); } } return result.Succeeded(); }
bool CommandObjectFile::Execute ( CommandInterpreter &interpreter, Args& command, CommandReturnObject &result ) { const char *file_path = command.GetArgumentAtIndex(0); Timer scoped_timer(__PRETTY_FUNCTION__, "(dbg) file '%s'", file_path); const int argc = command.GetArgumentCount(); if (argc == 1) { FileSpec file_spec (file_path); if (! file_spec.Exists()) { result.AppendErrorWithFormat ("File '%s' does not exist.\n", file_path); result.SetStatus (eReturnStatusFailed); return result.Succeeded(); } TargetSP target_sp; ArchSpec arch; if (m_options.m_arch.IsValid()) arch = m_options.m_arch; else { arch = lldb_private::GetDefaultArchitecture (); if (!arch.IsValid()) arch = LLDB_ARCH_DEFAULT; } Debugger &debugger = interpreter.GetDebugger(); Error error = debugger.GetTargetList().CreateTarget (debugger, file_spec, arch, NULL, true, target_sp); if (error.Fail() && !m_options.m_arch.IsValid()) { if (arch == LLDB_ARCH_DEFAULT_32BIT) arch = LLDB_ARCH_DEFAULT_64BIT; else arch = LLDB_ARCH_DEFAULT_32BIT; error = debugger.GetTargetList().CreateTarget (debugger, file_spec, arch, NULL, true, target_sp); } if (target_sp) { debugger.GetTargetList().SetCurrentTarget(target_sp.get()); result.AppendMessageWithFormat ("Current executable set to '%s' (%s).\n", file_path, arch.AsCString()); result.SetStatus (eReturnStatusSuccessFinishNoResult); } else { result.AppendError(error.AsCString()); result.SetStatus (eReturnStatusFailed); } } else { result.AppendErrorWithFormat("'%s' takes exactly one executable path argument.\n", m_cmd_name.c_str()); result.SetStatus (eReturnStatusFailed); } return result.Succeeded(); }
virtual bool DoExecute (Args& args, CommandReturnObject &result) { PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); if (platform_sp) { Error error; if (args.GetArgumentCount() == 0) { if (platform_sp) { Stream &ostrm = result.GetOutputStream(); lldb::pid_t pid = m_options.match_info.GetProcessInfo().GetProcessID(); if (pid != LLDB_INVALID_PROCESS_ID) { ProcessInstanceInfo proc_info; if (platform_sp->GetProcessInfo (pid, proc_info)) { ProcessInstanceInfo::DumpTableHeader (ostrm, platform_sp.get(), m_options.show_args, m_options.verbose); proc_info.DumpAsTableRow(ostrm, platform_sp.get(), m_options.show_args, m_options.verbose); result.SetStatus (eReturnStatusSuccessFinishResult); } else { result.AppendErrorWithFormat ("no process found with pid = %" PRIu64 "\n", pid); result.SetStatus (eReturnStatusFailed); } } else { ProcessInstanceInfoList proc_infos; const uint32_t matches = platform_sp->FindProcesses (m_options.match_info, proc_infos); const char *match_desc = NULL; const char *match_name = m_options.match_info.GetProcessInfo().GetName(); if (match_name && match_name[0]) { switch (m_options.match_info.GetNameMatchType()) { case eNameMatchIgnore: break; case eNameMatchEquals: match_desc = "matched"; break; case eNameMatchContains: match_desc = "contained"; break; case eNameMatchStartsWith: match_desc = "started with"; break; case eNameMatchEndsWith: match_desc = "ended with"; break; case eNameMatchRegularExpression: match_desc = "matched the regular expression"; break; } } if (matches == 0) { if (match_desc) result.AppendErrorWithFormat ("no processes were found that %s \"%s\" on the \"%s\" platform\n", match_desc, match_name, platform_sp->GetShortPluginName()); else result.AppendErrorWithFormat ("no processes were found on the \"%s\" platform\n", platform_sp->GetShortPluginName()); result.SetStatus (eReturnStatusFailed); } else { result.AppendMessageWithFormat ("%u matching process%s found on \"%s\"", matches, matches > 1 ? "es were" : " was", platform_sp->GetName()); if (match_desc) result.AppendMessageWithFormat (" whose name %s \"%s\"", match_desc, match_name); result.AppendMessageWithFormat ("\n"); ProcessInstanceInfo::DumpTableHeader (ostrm, platform_sp.get(), m_options.show_args, m_options.verbose); for (uint32_t i=0; i<matches; ++i) { proc_infos.GetProcessInfoAtIndex(i).DumpAsTableRow(ostrm, platform_sp.get(), m_options.show_args, m_options.verbose); } } } } } else { result.AppendError ("invalid args: process list takes only options\n"); result.SetStatus (eReturnStatusFailed); } } else { result.AppendError ("no platform is selected\n"); result.SetStatus (eReturnStatusFailed); } return result.Succeeded(); }
bool DoExecute (Args& command, CommandReturnObject &result) { const int argc = command.GetArgumentCount(); if (argc != 0) { result.AppendErrorWithFormat("'%s' takes no arguments, only flags.\n", GetCommandName()); result.SetStatus (eReturnStatusFailed); return false; } ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); Target *target = exe_ctx.GetTargetPtr(); if (target == NULL) target = m_interpreter.GetDebugger().GetSelectedTarget().get(); if (target == NULL) { result.AppendError ("invalid target, create a debug target using the 'target create' command"); result.SetStatus (eReturnStatusFailed); return false; } SymbolContextList sc_list; if (!m_options.symbol_name.empty()) { // Displaying the source for a symbol: ConstString name(m_options.symbol_name.c_str()); bool include_symbols = false; bool include_inlines = true; bool append = true; size_t num_matches = 0; if (m_options.modules.size() > 0) { ModuleList matching_modules; for (unsigned i = 0, e = m_options.modules.size(); i != e; i++) { FileSpec module_file_spec(m_options.modules[i].c_str(), false); if (module_file_spec) { ModuleSpec module_spec (module_file_spec); matching_modules.Clear(); target->GetImages().FindModules (module_spec, matching_modules); num_matches += matching_modules.FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); } } } else { num_matches = target->GetImages().FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); } SymbolContext sc; if (num_matches == 0) { result.AppendErrorWithFormat("Could not find function named: \"%s\".\n", m_options.symbol_name.c_str()); result.SetStatus (eReturnStatusFailed); return false; } sc_list.GetContextAtIndex (0, sc); FileSpec start_file; uint32_t start_line; uint32_t end_line; FileSpec end_file; if (sc.function != NULL) { sc.function->GetStartLineSourceInfo (start_file, start_line); if (start_line == 0) { result.AppendErrorWithFormat("Could not find line information for start of function: \"%s\".\n", m_options.symbol_name.c_str()); result.SetStatus (eReturnStatusFailed); return false; } sc.function->GetEndLineSourceInfo (end_file, end_line); } else { result.AppendErrorWithFormat("Could not find function info for: \"%s\".\n", m_options.symbol_name.c_str()); result.SetStatus (eReturnStatusFailed); return false; } if (num_matches > 1) { // This could either be because there are multiple functions of this name, in which case // we'll have to specify this further... Or it could be because there are multiple inlined instances // of one function. So run through the matches and if they all have the same file & line then we can just // list one. bool found_multiple = false; for (size_t i = 1; i < num_matches; i++) { SymbolContext scratch_sc; sc_list.GetContextAtIndex (i, scratch_sc); if (scratch_sc.function != NULL) { FileSpec scratch_file; uint32_t scratch_line; scratch_sc.function->GetStartLineSourceInfo (scratch_file, scratch_line); if (scratch_file != start_file || scratch_line != start_line) { found_multiple = true; break; } } } if (found_multiple) { StreamString s; for (size_t i = 0; i < num_matches; i++) { SymbolContext scratch_sc; sc_list.GetContextAtIndex (i, scratch_sc); if (scratch_sc.function != NULL) { s.Printf("\n%lu: ", i); scratch_sc.function->Dump (&s, true); } } result.AppendErrorWithFormat("Multiple functions found matching: %s: \n%s\n", m_options.symbol_name.c_str(), s.GetData()); result.SetStatus (eReturnStatusFailed); return false; } } // This is a little hacky, but the first line table entry for a function points to the "{" that // starts the function block. It would be nice to actually get the function // declaration in there too. So back up a bit, but not further than what you're going to display. size_t lines_to_back_up = m_options.num_lines >= 10 ? 5 : m_options.num_lines/2; uint32_t line_no; if (start_line <= lines_to_back_up) line_no = 1; else line_no = start_line - lines_to_back_up; // For fun, if the function is shorter than the number of lines we're supposed to display, // only display the function... if (end_line != 0) { if (m_options.num_lines > end_line - line_no) m_options.num_lines = end_line - line_no; } char path_buf[PATH_MAX]; start_file.GetPath(path_buf, sizeof(path_buf)); if (m_options.show_bp_locs) { const bool show_inlines = true; m_breakpoint_locations.Reset (start_file, 0, show_inlines); SearchFilter target_search_filter (exe_ctx.GetTargetSP()); target_search_filter.Search (m_breakpoint_locations); } else m_breakpoint_locations.Clear(); result.AppendMessageWithFormat("File: %s.\n", path_buf); target->GetSourceManager().DisplaySourceLinesWithLineNumbers (start_file, line_no, 0, m_options.num_lines, "", &result.GetOutputStream(), GetBreakpointLocations ()); result.SetStatus (eReturnStatusSuccessFinishResult); return true; } else if (m_options.address != LLDB_INVALID_ADDRESS) { SymbolContext sc; Address so_addr; StreamString error_strm; if (target->GetSectionLoadList().IsEmpty()) { // The target isn't loaded yet, we need to lookup the file address // in all modules const ModuleList &module_list = target->GetImages(); const uint32_t num_modules = module_list.GetSize(); for (uint32_t i=0; i<num_modules; ++i) { ModuleSP module_sp (module_list.GetModuleAtIndex(i)); if (module_sp && module_sp->ResolveFileAddress(m_options.address, so_addr)) { sc.Clear(); if (module_sp->ResolveSymbolContextForAddress (so_addr, eSymbolContextEverything, sc) & eSymbolContextLineEntry) sc_list.Append(sc); } } if (sc_list.GetSize() == 0) { result.AppendErrorWithFormat("no modules have source information for file address 0x%" PRIx64 ".\n", m_options.address); result.SetStatus (eReturnStatusFailed); return false; } } else { // The target has some things loaded, resolve this address to a // compile unit + file + line and display if (target->GetSectionLoadList().ResolveLoadAddress (m_options.address, so_addr)) { ModuleSP module_sp (so_addr.GetModule()); if (module_sp) { sc.Clear(); if (module_sp->ResolveSymbolContextForAddress (so_addr, eSymbolContextEverything, sc) & eSymbolContextLineEntry) { sc_list.Append(sc); } else { so_addr.Dump(&error_strm, NULL, Address::DumpStyleModuleWithFileAddress); result.AppendErrorWithFormat("address resolves to %s, but there is no line table information available for this address.\n", error_strm.GetData()); result.SetStatus (eReturnStatusFailed); return false; } } } if (sc_list.GetSize() == 0) { result.AppendErrorWithFormat("no modules contain load address 0x%" PRIx64 ".\n", m_options.address); result.SetStatus (eReturnStatusFailed); return false; } } uint32_t num_matches = sc_list.GetSize(); for (uint32_t i=0; i<num_matches; ++i) { sc_list.GetContextAtIndex(i, sc); if (sc.comp_unit) { if (m_options.show_bp_locs) { m_breakpoint_locations.Clear(); const bool show_inlines = true; m_breakpoint_locations.Reset (*sc.comp_unit, 0, show_inlines); SearchFilter target_search_filter (target->shared_from_this()); target_search_filter.Search (m_breakpoint_locations); } bool show_fullpaths = true; bool show_module = true; bool show_inlined_frames = true; sc.DumpStopContext(&result.GetOutputStream(), exe_ctx.GetBestExecutionContextScope(), sc.line_entry.range.GetBaseAddress(), show_fullpaths, show_module, show_inlined_frames); result.GetOutputStream().EOL(); size_t lines_to_back_up = m_options.num_lines >= 10 ? 5 : m_options.num_lines/2; target->GetSourceManager().DisplaySourceLinesWithLineNumbers (sc.comp_unit, sc.line_entry.line, lines_to_back_up, m_options.num_lines - lines_to_back_up, "->", &result.GetOutputStream(), GetBreakpointLocations ()); result.SetStatus (eReturnStatusSuccessFinishResult); } } } else if (m_options.file_name.empty()) { // Last valid source manager context, or the current frame if no // valid last context in source manager. // One little trick here, if you type the exact same list command twice in a row, it is // more likely because you typed it once, then typed it again if (m_options.start_line == 0) { if (target->GetSourceManager().DisplayMoreWithLineNumbers (&result.GetOutputStream(), GetBreakpointLocations ())) { result.SetStatus (eReturnStatusSuccessFinishResult); } } else { if (m_options.show_bp_locs) { SourceManager::FileSP last_file_sp (target->GetSourceManager().GetLastFile ()); if (last_file_sp) { const bool show_inlines = true; m_breakpoint_locations.Reset (last_file_sp->GetFileSpec(), 0, show_inlines); SearchFilter target_search_filter (target->shared_from_this()); target_search_filter.Search (m_breakpoint_locations); } } else m_breakpoint_locations.Clear(); if (target->GetSourceManager().DisplaySourceLinesWithLineNumbersUsingLastFile( m_options.start_line, // Line to display 0, // Lines before line to display m_options.num_lines, // Lines after line to display "", // Don't mark "line" &result.GetOutputStream(), GetBreakpointLocations ())) { result.SetStatus (eReturnStatusSuccessFinishResult); } } } else { const char *filename = m_options.file_name.c_str(); bool check_inlines = false; SymbolContextList sc_list; size_t num_matches = 0; if (m_options.modules.size() > 0) { ModuleList matching_modules; for (unsigned i = 0, e = m_options.modules.size(); i != e; i++) { FileSpec module_file_spec(m_options.modules[i].c_str(), false); if (module_file_spec) { ModuleSpec module_spec (module_file_spec); matching_modules.Clear(); target->GetImages().FindModules (module_spec, matching_modules); num_matches += matching_modules.ResolveSymbolContextForFilePath (filename, 0, check_inlines, eSymbolContextModule | eSymbolContextCompUnit, sc_list); } } } else { num_matches = target->GetImages().ResolveSymbolContextForFilePath (filename, 0, check_inlines, eSymbolContextModule | eSymbolContextCompUnit, sc_list); } if (num_matches == 0) { result.AppendErrorWithFormat("Could not find source file \"%s\".\n", m_options.file_name.c_str()); result.SetStatus (eReturnStatusFailed); return false; } if (num_matches > 1) { SymbolContext sc; bool got_multiple = false; FileSpec *test_cu_spec = NULL; for (unsigned i = 0; i < num_matches; i++) { sc_list.GetContextAtIndex(i, sc); if (sc.comp_unit) { if (test_cu_spec) { if (test_cu_spec != static_cast<FileSpec *> (sc.comp_unit)) got_multiple = true; break; } else test_cu_spec = sc.comp_unit; } } if (got_multiple) { result.AppendErrorWithFormat("Multiple source files found matching: \"%s.\"\n", m_options.file_name.c_str()); result.SetStatus (eReturnStatusFailed); return false; } } SymbolContext sc; if (sc_list.GetContextAtIndex(0, sc)) { if (sc.comp_unit) { if (m_options.show_bp_locs) { const bool show_inlines = true; m_breakpoint_locations.Reset (*sc.comp_unit, 0, show_inlines); SearchFilter target_search_filter (target->shared_from_this()); target_search_filter.Search (m_breakpoint_locations); } else m_breakpoint_locations.Clear(); target->GetSourceManager().DisplaySourceLinesWithLineNumbers (sc.comp_unit, m_options.start_line, 0, m_options.num_lines, "", &result.GetOutputStream(), GetBreakpointLocations ()); result.SetStatus (eReturnStatusSuccessFinishResult); } else { result.AppendErrorWithFormat("No comp unit found for: \"%s.\"\n", m_options.file_name.c_str()); result.SetStatus (eReturnStatusFailed); return false; } } } return result.Succeeded(); }
bool CommandObjectApropos::Execute ( Args& args, CommandReturnObject &result ) { const int argc = args.GetArgumentCount (); if (argc == 1) { const char *search_word = args.GetArgumentAtIndex(0); if ((search_word != NULL) && (strlen (search_word) > 0)) { // The bulk of the work must be done inside the Command Interpreter, since the command dictionary // is private. StringList commands_found; StringList commands_help; m_interpreter.FindCommandsForApropos (search_word, commands_found, commands_help); if (commands_found.GetSize() == 0) { result.AppendMessageWithFormat ("No commands found pertaining to '%s'. Try 'help' to see a complete list of debugger commands.\n", search_word); } else { result.AppendMessageWithFormat ("The following commands may relate to '%s':\n", search_word); size_t max_len = 0; for (size_t i = 0; i < commands_found.GetSize(); ++i) { size_t len = strlen (commands_found.GetStringAtIndex (i)); if (len > max_len) max_len = len; } for (size_t i = 0; i < commands_found.GetSize(); ++i) m_interpreter.OutputFormattedHelpText (result.GetOutputStream(), commands_found.GetStringAtIndex(i), "--", commands_help. GetStringAtIndex(i), max_len); } StreamString settings_search_results; lldb::UserSettingsControllerSP root = Debugger::GetSettingsController (); const char *settings_prefix = root->GetLevelName().GetCString(); UserSettingsController::SearchAllSettingsDescriptions (m_interpreter, root, settings_prefix, search_word, settings_search_results); if (settings_search_results.GetSize() > 0) { result.AppendMessageWithFormat ("\nThe following settings variables may relate to '%s': \n\n", search_word); result.AppendMessageWithFormat ("%s", settings_search_results.GetData()); } result.SetStatus (eReturnStatusSuccessFinishNoResult); } else { result.AppendError ("'' is not a valid search word.\n"); result.SetStatus (eReturnStatusFailed); } } else { result.AppendError ("'apropos' must be called with exactly one argument.\n"); result.SetStatus (eReturnStatusFailed); } return result.Succeeded(); }
bool Execute ( Args& args, CommandReturnObject &result ) { const int argc = args.GetArgumentCount(); if (argc != 0) { result.AppendErrorWithFormat("'%s' takes no arguments, only flags.\n", GetCommandName()); result.SetStatus (eReturnStatusFailed); } ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext()); if (!m_options.symbol_name.empty()) { // Displaying the source for a symbol: Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); if (target == NULL) { result.AppendError ("invalid target, set executable file using 'file' command"); result.SetStatus (eReturnStatusFailed); return false; } SymbolContextList sc_list; ConstString name(m_options.symbol_name.c_str()); bool include_symbols = false; bool append = true; size_t num_matches = 0; if (m_options.m_modules.size() > 0) { ModuleList matching_modules; for (unsigned i = 0, e = m_options.m_modules.size(); i != e; i++) { FileSpec module_spec(m_options.m_modules[i].c_str(), false); if (module_spec) { matching_modules.Clear(); target->GetImages().FindModules (&module_spec, NULL, NULL, NULL, matching_modules); num_matches += matching_modules.FindFunctions (name, eFunctionNameTypeBase, include_symbols, append, sc_list); } } } else { num_matches = target->GetImages().FindFunctions (name, eFunctionNameTypeBase, include_symbols, append, sc_list); } SymbolContext sc; if (num_matches == 0) { result.AppendErrorWithFormat("Could not find function named: \"%s\".\n", m_options.symbol_name.c_str()); result.SetStatus (eReturnStatusFailed); return false; } sc_list.GetContextAtIndex (0, sc); FileSpec start_file; uint32_t start_line; uint32_t end_line; FileSpec end_file; if (sc.function != NULL) { sc.function->GetStartLineSourceInfo (start_file, start_line); if (start_line == 0) { result.AppendErrorWithFormat("Could not find line information for start of function: \"%s\".\n", m_options.symbol_name.c_str()); result.SetStatus (eReturnStatusFailed); return false; } sc.function->GetEndLineSourceInfo (end_file, end_line); } else { result.AppendErrorWithFormat("Could not find function info for: \"%s\".\n", m_options.symbol_name.c_str()); result.SetStatus (eReturnStatusFailed); return false; } if (num_matches > 1) { // This could either be because there are multiple functions of this name, in which case // we'll have to specify this further... Or it could be because there are multiple inlined instances // of one function. So run through the matches and if they all have the same file & line then we can just // list one. bool found_multiple = false; for (size_t i = 1; i < num_matches; i++) { SymbolContext scratch_sc; sc_list.GetContextAtIndex (i, scratch_sc); if (scratch_sc.function != NULL) { FileSpec scratch_file; uint32_t scratch_line; scratch_sc.function->GetStartLineSourceInfo (scratch_file, scratch_line); if (scratch_file != start_file || scratch_line != start_line) { found_multiple = true; break; } } } if (found_multiple) { StreamString s; for (size_t i = 0; i < num_matches; i++) { SymbolContext scratch_sc; sc_list.GetContextAtIndex (i, scratch_sc); if (scratch_sc.function != NULL) { s.Printf("\n%d: ", i); scratch_sc.function->Dump (&s, true); } } result.AppendErrorWithFormat("Multiple functions found matching: %s: \n%s\n", m_options.symbol_name.c_str(), s.GetData()); result.SetStatus (eReturnStatusFailed); return false; } } // This is a little hacky, but the first line table entry for a function points to the "{" that // starts the function block. It would be nice to actually get the function // declaration in there too. So back up a bit, but not further than what you're going to display. size_t lines_to_back_up = m_options.num_lines >= 10 ? 5 : m_options.num_lines/2; uint32_t line_no; if (start_line <= lines_to_back_up) line_no = 1; else line_no = start_line - lines_to_back_up; // For fun, if the function is shorter than the number of lines we're supposed to display, // only display the function... if (end_line != 0) { if (m_options.num_lines > end_line - line_no) m_options.num_lines = end_line - line_no; } char path_buf[PATH_MAX+1]; start_file.GetPath(path_buf, PATH_MAX); result.AppendMessageWithFormat("File: %s.\n", path_buf); m_interpreter.GetDebugger().GetSourceManager().DisplaySourceLinesWithLineNumbers (start_file, line_no, 0, m_options.num_lines, "", &result.GetOutputStream()); result.SetStatus (eReturnStatusSuccessFinishResult); return true; } else if (m_options.file_name.empty()) { // Last valid source manager context, or the current frame if no // valid last context in source manager. // One little trick here, if you type the exact same list command twice in a row, it is // more likely because you typed it once, then typed it again if (m_options.start_line == 0) { if (m_interpreter.GetDebugger().GetSourceManager().DisplayMoreWithLineNumbers (&result.GetOutputStream())) { result.SetStatus (eReturnStatusSuccessFinishResult); } } else { if (m_interpreter.GetDebugger().GetSourceManager().DisplaySourceLinesWithLineNumbersUsingLastFile( m_options.start_line, // Line to display 0, // Lines before line to display m_options.num_lines, // Lines after line to display "", // Don't mark "line" &result.GetOutputStream())) { result.SetStatus (eReturnStatusSuccessFinishResult); } } } else { const char *filename = m_options.file_name.c_str(); Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); if (target == NULL) { result.AppendError ("invalid target, set executable file using 'file' command"); result.SetStatus (eReturnStatusFailed); return false; } bool check_inlines = false; SymbolContextList sc_list; size_t num_matches = 0; if (m_options.m_modules.size() > 0) { ModuleList matching_modules; for (unsigned i = 0, e = m_options.m_modules.size(); i != e; i++) { FileSpec module_spec(m_options.m_modules[i].c_str(), false); if (module_spec) { matching_modules.Clear(); target->GetImages().FindModules (&module_spec, NULL, NULL, NULL, matching_modules); num_matches += matching_modules.ResolveSymbolContextForFilePath (filename, 0, check_inlines, eSymbolContextModule | eSymbolContextCompUnit, sc_list); } } } else { num_matches = target->GetImages().ResolveSymbolContextForFilePath (filename, 0, check_inlines, eSymbolContextModule | eSymbolContextCompUnit, sc_list); } if (num_matches == 0) { result.AppendErrorWithFormat("Could not find source file \"%s\".\n", m_options.file_name.c_str()); result.SetStatus (eReturnStatusFailed); return false; } if (num_matches > 1) { SymbolContext sc; bool got_multiple = false; FileSpec *test_cu_spec = NULL; for (unsigned i = 0; i < num_matches; i++) { sc_list.GetContextAtIndex(i, sc); if (sc.comp_unit) { if (test_cu_spec) { if (test_cu_spec != static_cast<FileSpec *> (sc.comp_unit)) got_multiple = true; break; } else test_cu_spec = sc.comp_unit; } } if (got_multiple) { result.AppendErrorWithFormat("Multiple source files found matching: \"%s.\"\n", m_options.file_name.c_str()); result.SetStatus (eReturnStatusFailed); return false; } } SymbolContext sc; if (sc_list.GetContextAtIndex(0, sc)) { if (sc.comp_unit) { m_interpreter.GetDebugger().GetSourceManager().DisplaySourceLinesWithLineNumbers (sc.comp_unit, m_options.start_line, 0, m_options.num_lines, "", &result.GetOutputStream()); result.SetStatus (eReturnStatusSuccessFinishResult); } else { result.AppendErrorWithFormat("No comp unit found for: \"%s.\"\n", m_options.file_name.c_str()); result.SetStatus (eReturnStatusFailed); return false; } } } return result.Succeeded(); }
size_t DisplayFunctionSource (const SymbolContext &sc, SourceInfo &source_info, CommandReturnObject &result) { if (!source_info.IsValid()) { source_info.function = sc.GetFunctionName(); source_info.line_entry = sc.GetFunctionStartLineEntry(); } if (sc.function) { Target *target = m_exe_ctx.GetTargetPtr(); FileSpec start_file; uint32_t start_line; uint32_t end_line; FileSpec end_file; if (sc.block == NULL) { // Not an inlined function sc.function->GetStartLineSourceInfo (start_file, start_line); if (start_line == 0) { result.AppendErrorWithFormat("Could not find line information for start of function: \"%s\".\n", source_info.function.GetCString()); result.SetStatus (eReturnStatusFailed); return 0; } sc.function->GetEndLineSourceInfo (end_file, end_line); } else { // We have an inlined function start_file = source_info.line_entry.file; start_line = source_info.line_entry.line; end_line = start_line + m_options.num_lines; } // This is a little hacky, but the first line table entry for a function points to the "{" that // starts the function block. It would be nice to actually get the function // declaration in there too. So back up a bit, but not further than what you're going to display. uint32_t extra_lines; if (m_options.num_lines >= 10) extra_lines = 5; else extra_lines = m_options.num_lines/2; uint32_t line_no; if (start_line <= extra_lines) line_no = 1; else line_no = start_line - extra_lines; // For fun, if the function is shorter than the number of lines we're supposed to display, // only display the function... if (end_line != 0) { if (m_options.num_lines > end_line - line_no) m_options.num_lines = end_line - line_no + extra_lines; } m_breakpoint_locations.Clear(); if (m_options.show_bp_locs) { const bool show_inlines = true; m_breakpoint_locations.Reset (start_file, 0, show_inlines); SearchFilter target_search_filter (m_exe_ctx.GetTargetSP()); target_search_filter.Search (m_breakpoint_locations); } result.AppendMessageWithFormat("File: %s\n", start_file.GetPath().c_str()); return target->GetSourceManager().DisplaySourceLinesWithLineNumbers (start_file, line_no, 0, m_options.num_lines, "", &result.GetOutputStream(), GetBreakpointLocations ()); } else { result.AppendErrorWithFormat("Could not find function info for: \"%s\".\n", m_options.symbol_name.c_str()); } return 0; }