diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2024-08-02 09:51:47 -0700 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2024-08-02 09:53:34 -0700 |
commit | c6ce324fa7fb2438b945fa1205b2a23138327e83 (patch) | |
tree | 45ef37185b480db2daf44fbc0e572bf5634ee8e9 /lldb/source/Commands/CommandObjectSource.cpp | |
parent | 1c1b8c20c2d58b6a307e6fdc6db271e81ee8d603 (diff) | |
download | llvm-c6ce324fa7fb2438b945fa1205b2a23138327e83.zip llvm-c6ce324fa7fb2438b945fa1205b2a23138327e83.tar.gz llvm-c6ce324fa7fb2438b945fa1205b2a23138327e83.tar.bz2 |
[lldb] Eliminate more Targer* in favor of Target& in CommandObjects (NFC)
The majority of the replaced Target pointers were already used
unconditionally and the few that were shouldn't even be NULL.
Diffstat (limited to 'lldb/source/Commands/CommandObjectSource.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectSource.cpp | 96 |
1 files changed, 44 insertions, 52 deletions
diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp index f54b712..98907c4 100644 --- a/lldb/source/Commands/CommandObjectSource.cpp +++ b/lldb/source/Commands/CommandObjectSource.cpp @@ -142,7 +142,7 @@ protected: uint32_t start_line = m_options.start_line; uint32_t end_line = m_options.end_line; uint32_t num_lines = m_options.num_lines; - Target *target = m_exe_ctx.GetTargetPtr(); + Target &target = GetTarget(); uint32_t num_matches = 0; // Dump all the line entries for the file in the list. @@ -177,7 +177,7 @@ protected: } // Dump the line entry. line_entry.GetDescription(&strm, lldb::eDescriptionLevelBrief, cu, - target, /*show_address_only=*/false); + &target, /*show_address_only=*/false); strm << "\n"; last_module_file_name = module_file_name; num_matches++; @@ -197,7 +197,7 @@ protected: uint32_t start_line = m_options.start_line; uint32_t end_line = m_options.end_line; uint32_t num_lines = m_options.num_lines; - Target *target = m_exe_ctx.GetTargetPtr(); + Target &target = GetTarget(); uint32_t num_matches = 0; assert(module); @@ -250,7 +250,7 @@ protected: cu_header_printed = true; } line_entry.GetDescription(&strm, lldb::eDescriptionLevelBrief, cu, - target, /*show_address_only=*/false); + &target, /*show_address_only=*/false); strm << "\n"; // Anymore after this one? @@ -301,8 +301,8 @@ protected: Address so_addr; size_t num_matches = 0; assert(module_list.GetSize() > 0); - Target *target = m_exe_ctx.GetTargetPtr(); - if (target->GetSectionLoadList().IsEmpty()) { + Target &target = GetTarget(); + if (target.GetSectionLoadList().IsEmpty()) { // The target isn't loaded yet, we need to lookup the file address in all // modules. Note: the module list option does not apply to addresses. const size_t num_modules = module_list.GetSize(); @@ -328,7 +328,7 @@ protected: } else { // The target has some things loaded, resolve this address to a compile // unit + file + line and display - if (target->GetSectionLoadList().ResolveLoadAddress(addr, so_addr)) { + if (target.GetSectionLoadList().ResolveLoadAddress(addr, so_addr)) { ModuleSP module_sp(so_addr.GetModule()); // Check to make sure this module is in our list. if (module_sp && module_list.GetIndexForModule(module_sp.get()) != @@ -370,8 +370,8 @@ protected: SymbolContextList sc_list_funcs; ConstString name(m_options.symbol_name.c_str()); SymbolContextList sc_list_lines; - Target *target = m_exe_ctx.GetTargetPtr(); - uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); + Target &target = GetTarget(); + uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize(); ModuleFunctionSearchOptions function_options; function_options.include_symbols = false; @@ -380,7 +380,7 @@ protected: // Note: module_list can't be const& because FindFunctionSymbols isn't // const. ModuleList module_list = - (m_module_list.GetSize() > 0) ? m_module_list : target->GetImages(); + (m_module_list.GetSize() > 0) ? m_module_list : target.GetImages(); module_list.FindFunctions(name, eFunctionNameTypeAuto, function_options, sc_list_funcs); size_t num_matches = sc_list_funcs.GetSize(); @@ -419,7 +419,7 @@ protected: // sc_list_lines. const Address &base_address = range.GetBaseAddress(); const addr_t size = range.GetByteSize(); - lldb::addr_t start_addr = base_address.GetLoadAddress(target); + lldb::addr_t start_addr = base_address.GetLoadAddress(&target); if (start_addr == LLDB_INVALID_ADDRESS) start_addr = base_address.GetFileAddress(); lldb::addr_t end_addr = start_addr + size; @@ -459,11 +459,11 @@ protected: // Dump the line entries found for the address specified in the option. bool DumpLinesForAddress(CommandReturnObject &result) { - Target *target = m_exe_ctx.GetTargetPtr(); + Target &target = GetTarget(); SymbolContextList sc_list; StreamString error_strm; - if (!GetSymbolContextsForAddress(target->GetImages(), m_options.address, + if (!GetSymbolContextsForAddress(target.GetImages(), m_options.address, sc_list, error_strm)) { result.AppendErrorWithFormat("%s.\n", error_strm.GetData()); return false; @@ -484,9 +484,9 @@ protected: bool DumpLinesForFile(CommandReturnObject &result) { FileSpec file_spec(m_options.file_name); const char *filename = m_options.file_name.c_str(); - Target *target = m_exe_ctx.GetTargetPtr(); + Target &target = GetTarget(); const ModuleList &module_list = - (m_module_list.GetSize() > 0) ? m_module_list : target->GetImages(); + (m_module_list.GetSize() > 0) ? m_module_list : target.GetImages(); bool displayed_something = false; const size_t num_modules = module_list.GetSize(); @@ -533,17 +533,9 @@ protected: } void DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = m_exe_ctx.GetTargetPtr(); - if (target == nullptr) { - target = GetDebugger().GetSelectedTarget().get(); - if (target == nullptr) { - result.AppendError("invalid target, create a debug target using the " - "'target create' command."); - return; - } - } + Target &target = GetTarget(); - uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); + uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize(); result.GetOutputStream().SetAddressByteSize(addr_byte_size); result.GetErrorStream().SetAddressByteSize(addr_byte_size); @@ -554,7 +546,7 @@ protected: FileSpec module_file_spec(m_options.modules[i]); if (module_file_spec) { ModuleSpec module_spec(module_file_spec); - target->GetImages().FindModules(module_spec, m_module_list); + target.GetImages().FindModules(module_spec, m_module_list); if (m_module_list.IsEmpty()) result.AppendWarningWithFormat("No module found for '%s'.\n", m_options.modules[i].c_str()); @@ -564,7 +556,7 @@ protected: result.AppendError("No modules match the input."); return; } - } else if (target->GetImages().GetSize() == 0) { + } else if (target.GetImages().GetSize() == 0) { result.AppendError("The target has no associated executable images."); return; } @@ -784,7 +776,7 @@ protected: } if (sc.function) { - Target *target = m_exe_ctx.GetTargetPtr(); + Target &target = GetTarget(); FileSpec start_file; uint32_t start_line; @@ -844,7 +836,7 @@ protected: start_file.GetPath().c_str()); // We don't care about the column here. const uint32_t column = 0; - return target->GetSourceManager().DisplaySourceLinesWithLineNumbers( + return target.GetSourceManager().DisplaySourceLinesWithLineNumbers( start_file, line_no, column, 0, m_options.num_lines, "", &result.GetOutputStream(), GetBreakpointLocations()); } else { @@ -862,7 +854,7 @@ protected: // these somewhere, there should probably be a module-filter-list that can be // passed to the various ModuleList::Find* calls, which would either be a // vector of string names or a ModuleSpecList. - void FindMatchingFunctions(Target *target, ConstString name, + void FindMatchingFunctions(Target &target, ConstString name, SymbolContextList &sc_list) { // Displaying the source for a symbol: if (m_options.num_lines == 0) @@ -880,19 +872,19 @@ protected: if (module_file_spec) { ModuleSpec module_spec(module_file_spec); matching_modules.Clear(); - target->GetImages().FindModules(module_spec, matching_modules); + target.GetImages().FindModules(module_spec, matching_modules); matching_modules.FindFunctions(name, eFunctionNameTypeAuto, function_options, sc_list); } } } else { - target->GetImages().FindFunctions(name, eFunctionNameTypeAuto, - function_options, sc_list); + target.GetImages().FindFunctions(name, eFunctionNameTypeAuto, + function_options, sc_list); } } - void FindMatchingFunctionSymbols(Target *target, ConstString name, + void FindMatchingFunctionSymbols(Target &target, ConstString name, SymbolContextList &sc_list) { const size_t num_modules = m_options.modules.size(); if (num_modules > 0) { @@ -902,19 +894,19 @@ protected: if (module_file_spec) { ModuleSpec module_spec(module_file_spec); matching_modules.Clear(); - target->GetImages().FindModules(module_spec, matching_modules); + target.GetImages().FindModules(module_spec, matching_modules); matching_modules.FindFunctionSymbols(name, eFunctionNameTypeAuto, sc_list); } } } else { - target->GetImages().FindFunctionSymbols(name, eFunctionNameTypeAuto, - sc_list); + target.GetImages().FindFunctionSymbols(name, eFunctionNameTypeAuto, + sc_list); } } void DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = m_exe_ctx.GetTargetPtr(); + Target &target = GetTarget(); if (!m_options.symbol_name.empty()) { SymbolContextList sc_list; @@ -967,10 +959,10 @@ protected: StreamString error_strm; SymbolContextList sc_list; - if (target->GetSectionLoadList().IsEmpty()) { + 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 ModuleList &module_list = target.GetImages(); const size_t num_modules = module_list.GetSize(); for (size_t i = 0; i < num_modules; ++i) { ModuleSP module_sp(module_list.GetModuleAtIndex(i)); @@ -995,8 +987,8 @@ protected: } 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)) { + if (target.GetSectionLoadList().ResolveLoadAddress(m_options.address, + so_addr)) { ModuleSP module_sp(so_addr.GetModule()); if (module_sp) { SymbolContext sc; @@ -1032,7 +1024,7 @@ protected: m_breakpoint_locations.Reset(sc.comp_unit->GetPrimaryFile(), 0, show_inlines); SearchFilterForUnconstrainedSearches target_search_filter( - target->shared_from_this()); + target.shared_from_this()); target_search_filter.Search(m_breakpoint_locations); } @@ -1058,7 +1050,7 @@ protected: (GetDebugger().GetStopShowColumn() != eStopShowColumnNone) ? sc.line_entry.column : 0; - target->GetSourceManager().DisplaySourceLinesWithLineNumbers( + target.GetSourceManager().DisplaySourceLinesWithLineNumbers( sc.comp_unit->GetPrimaryFile(), sc.line_entry.line, column, lines_to_back_up, m_options.num_lines - lines_to_back_up, "->", &result.GetOutputStream(), GetBreakpointLocations()); @@ -1071,7 +1063,7 @@ protected: // 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( + if (target.GetSourceManager().DisplayMoreWithLineNumbers( &result.GetOutputStream(), m_options.num_lines, m_options.reverse, GetBreakpointLocations())) { result.SetStatus(eReturnStatusSuccessFinishResult); @@ -1082,20 +1074,20 @@ protected: if (m_options.show_bp_locs) { SourceManager::FileSP last_file_sp( - target->GetSourceManager().GetLastFile()); + target.GetSourceManager().GetLastFile()); if (last_file_sp) { const bool show_inlines = true; m_breakpoint_locations.Reset(last_file_sp->GetFileSpec(), 0, show_inlines); SearchFilterForUnconstrainedSearches target_search_filter( - target->shared_from_this()); + target.shared_from_this()); target_search_filter.Search(m_breakpoint_locations); } } else m_breakpoint_locations.Clear(); const uint32_t column = 0; - if (target->GetSourceManager() + if (target.GetSourceManager() .DisplaySourceLinesWithLineNumbersUsingLastFile( m_options.start_line, // Line to display m_options.num_lines, // Lines after line to @@ -1120,7 +1112,7 @@ protected: if (module_file_spec) { ModuleSpec module_spec(module_file_spec); matching_modules.Clear(); - target->GetImages().FindModules(module_spec, matching_modules); + target.GetImages().FindModules(module_spec, matching_modules); num_matches += matching_modules.ResolveSymbolContextForFilePath( filename, 0, check_inlines, SymbolContextItem(eSymbolContextModule | @@ -1129,7 +1121,7 @@ protected: } } } else { - num_matches = target->GetImages().ResolveSymbolContextForFilePath( + num_matches = target.GetImages().ResolveSymbolContextForFilePath( filename, 0, check_inlines, eSymbolContextModule | eSymbolContextCompUnit, sc_list); } @@ -1170,7 +1162,7 @@ protected: m_breakpoint_locations.Reset(sc.comp_unit->GetPrimaryFile(), 0, show_inlines); SearchFilterForUnconstrainedSearches target_search_filter( - target->shared_from_this()); + target.shared_from_this()); target_search_filter.Search(m_breakpoint_locations); } else m_breakpoint_locations.Clear(); @@ -1178,7 +1170,7 @@ protected: if (m_options.num_lines == 0) m_options.num_lines = 10; const uint32_t column = 0; - target->GetSourceManager().DisplaySourceLinesWithLineNumbers( + target.GetSourceManager().DisplaySourceLinesWithLineNumbers( sc.comp_unit->GetPrimaryFile(), m_options.start_line, column, 0, m_options.num_lines, "", &result.GetOutputStream(), GetBreakpointLocations()); |