aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectTarget.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2021-01-07 20:12:01 -0800
committerJonas Devlieghere <jonas@devlieghere.com>2021-01-07 21:06:36 -0800
commitf2e05855deb39125a30a67b63a5e524792805768 (patch)
treea3cecec41089e326cc0b9e91c88f01b2aa51ad80 /lldb/source/Commands/CommandObjectTarget.cpp
parentb934160aaa36be42d5b868704157f30339e7d855 (diff)
downloadllvm-f2e05855deb39125a30a67b63a5e524792805768.zip
llvm-f2e05855deb39125a30a67b63a5e524792805768.tar.gz
llvm-f2e05855deb39125a30a67b63a5e524792805768.tar.bz2
[lldb] Access the ModuleList through iterators where possible (NFC)
Replace uses of GetModuleAtIndexUnlocked and GetModulePointerAtIndexUnlocked with the ModuleIterable and ModuleIterableNoLocking where applicable. Differential revision: https://reviews.llvm.org/D94271
Diffstat (limited to 'lldb/source/Commands/CommandObjectTarget.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectTarget.cpp162
1 files changed, 73 insertions, 89 deletions
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 4bce4e7..1cb2138 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1399,31 +1399,30 @@ static void DumpBasename(Stream &strm, const FileSpec *file_spec_ptr,
}
static size_t DumpModuleObjfileHeaders(Stream &strm, ModuleList &module_list) {
- size_t num_dumped = 0;
std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
const size_t num_modules = module_list.GetSize();
- if (num_modules > 0) {
- strm.Printf("Dumping headers for %" PRIu64 " module(s).\n",
- static_cast<uint64_t>(num_modules));
- strm.IndentMore();
- for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
- Module *module = module_list.GetModulePointerAtIndexUnlocked(image_idx);
- if (module) {
- if (num_dumped++ > 0) {
- strm.EOL();
- strm.EOL();
- }
- ObjectFile *objfile = module->GetObjectFile();
- if (objfile)
- objfile->Dump(&strm);
- else {
- strm.Format("No object file for module: {0:F}\n",
- module->GetFileSpec());
- }
+ if (num_modules == 0)
+ return 0;
+
+ size_t num_dumped = 0;
+ strm.Format("Dumping headers for {0} module(s).\n", num_modules);
+ strm.IndentMore();
+ for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
+ if (module_sp) {
+ if (num_dumped++ > 0) {
+ strm.EOL();
+ strm.EOL();
+ }
+ ObjectFile *objfile = module_sp->GetObjectFile();
+ if (objfile)
+ objfile->Dump(&strm);
+ else {
+ strm.Format("No object file for module: {0:F}\n",
+ module_sp->GetFileSpec());
}
}
- strm.IndentLess();
}
+ strm.IndentLess();
return num_dumped;
}
@@ -2025,14 +2024,13 @@ protected:
if (command.GetArgumentCount() == 0) {
// Dump all sections for all modules images
- std::lock_guard<std::recursive_mutex> guard(
- target->GetImages().GetMutex());
- const size_t num_modules = target->GetImages().GetSize();
+ const ModuleList &module_list = target->GetImages();
+ std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
+ const size_t num_modules = module_list.GetSize();
if (num_modules > 0) {
- result.GetOutputStream().Printf("Dumping symbol table for %" PRIu64
- " modules.\n",
- (uint64_t)num_modules);
- for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
+ result.GetOutputStream().Format(
+ "Dumping symbol table for {0} modules.\n", num_modules);
+ for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
if (num_dumped > 0) {
result.GetOutputStream().EOL();
result.GetOutputStream().EOL();
@@ -2040,10 +2038,9 @@ protected:
if (m_interpreter.WasInterrupted())
break;
num_dumped++;
- DumpModuleSymtab(
- m_interpreter, result.GetOutputStream(),
- target->GetImages().GetModulePointerAtIndexUnlocked(image_idx),
- m_options.m_sort_order, name_preference);
+ DumpModuleSymtab(m_interpreter, result.GetOutputStream(),
+ module_sp.get(), m_options.m_sort_order,
+ name_preference);
}
} else {
result.AppendError("the target has no associated executable images");
@@ -2060,9 +2057,8 @@ protected:
const size_t num_matches =
FindModulesByName(target, arg_cstr, module_list, true);
if (num_matches > 0) {
- for (size_t i = 0; i < num_matches; ++i) {
- Module *module = module_list.GetModulePointerAtIndex(i);
- if (module) {
+ for (ModuleSP module_sp : module_list.Modules()) {
+ if (module_sp) {
if (num_dumped > 0) {
result.GetOutputStream().EOL();
result.GetOutputStream().EOL();
@@ -2070,8 +2066,9 @@ protected:
if (m_interpreter.WasInterrupted())
break;
num_dumped++;
- DumpModuleSymtab(m_interpreter, result.GetOutputStream(), module,
- m_options.m_sort_order, name_preference);
+ DumpModuleSymtab(m_interpreter, result.GetOutputStream(),
+ module_sp.get(), m_options.m_sort_order,
+ name_preference);
}
}
} else
@@ -2120,23 +2117,22 @@ protected:
if (command.GetArgumentCount() == 0) {
// Dump all sections for all modules images
const size_t num_modules = target->GetImages().GetSize();
- if (num_modules > 0) {
- result.GetOutputStream().Printf("Dumping sections for %" PRIu64
- " modules.\n",
- (uint64_t)num_modules);
- for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
- if (m_interpreter.WasInterrupted())
- break;
- num_dumped++;
- DumpModuleSections(
- m_interpreter, result.GetOutputStream(),
- target->GetImages().GetModulePointerAtIndex(image_idx));
- }
- } else {
+ if (num_modules == 0) {
result.AppendError("the target has no associated executable images");
result.SetStatus(eReturnStatusFailed);
return false;
}
+
+ result.GetOutputStream().Format("Dumping sections for {0} modules.\n",
+ num_modules);
+ for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
+ if (m_interpreter.WasInterrupted())
+ break;
+ num_dumped++;
+ DumpModuleSections(
+ m_interpreter, result.GetOutputStream(),
+ target->GetImages().GetModulePointerAtIndex(image_idx));
+ }
} else {
// Dump specified images (by basename or fullpath)
const char *arg_cstr;
@@ -2198,7 +2194,8 @@ protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
Target *target = &GetSelectedTarget();
- const size_t num_modules = target->GetImages().GetSize();
+ const ModuleList &module_list = target->GetImages();
+ const size_t num_modules = module_list.GetSize();
if (num_modules == 0) {
result.AppendError("the target has no associated executable images");
result.SetStatus(eReturnStatusFailed);
@@ -2207,14 +2204,12 @@ protected:
if (command.GetArgumentCount() == 0) {
// Dump all ASTs for all modules images
- result.GetOutputStream().Printf("Dumping clang ast for %" PRIu64
- " modules.\n",
- (uint64_t)num_modules);
- for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
+ result.GetOutputStream().Format("Dumping clang ast for {0} modules.\n",
+ num_modules);
+ for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
if (m_interpreter.WasInterrupted())
break;
- Module *m = target->GetImages().GetModulePointerAtIndex(image_idx);
- if (SymbolFile *sf = m->GetSymbolFile())
+ if (SymbolFile *sf = module_sp->GetSymbolFile())
sf->DumpClangAST(result.GetOutputStream());
}
result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -2279,23 +2274,19 @@ protected:
const ModuleList &target_modules = target->GetImages();
std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
const size_t num_modules = target_modules.GetSize();
- if (num_modules > 0) {
- result.GetOutputStream().Printf("Dumping debug symbols for %" PRIu64
- " modules.\n",
- (uint64_t)num_modules);
- for (uint32_t image_idx = 0; image_idx < num_modules; ++image_idx) {
- if (m_interpreter.WasInterrupted())
- break;
- if (DumpModuleSymbolFile(
- result.GetOutputStream(),
- target_modules.GetModulePointerAtIndexUnlocked(image_idx)))
- num_dumped++;
- }
- } else {
+ if (num_modules == 0) {
result.AppendError("the target has no associated executable images");
result.SetStatus(eReturnStatusFailed);
return false;
}
+ result.GetOutputStream().Format(
+ "Dumping debug symbols for {0} modules.\n", num_modules);
+ for (ModuleSP module_sp : target_modules.ModulesNoLocking()) {
+ if (m_interpreter.WasInterrupted())
+ break;
+ if (DumpModuleSymbolFile(result.GetOutputStream(), module_sp.get()))
+ num_dumped++;
+ }
} else {
// Dump specified images (by basename or fullpath)
const char *arg_cstr;
@@ -2373,15 +2364,13 @@ protected:
const ModuleList &target_modules = target->GetImages();
std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
- const size_t num_modules = target_modules.GetSize();
- if (num_modules > 0) {
+ if (target_modules.GetSize() > 0) {
uint32_t num_dumped = 0;
- for (uint32_t i = 0; i < num_modules; ++i) {
+ for (ModuleSP module_sp : target_modules.ModulesNoLocking()) {
if (m_interpreter.WasInterrupted())
break;
if (DumpCompileUnitLineTable(
- m_interpreter, result.GetOutputStream(),
- target_modules.GetModulePointerAtIndexUnlocked(i),
+ m_interpreter, result.GetOutputStream(), module_sp.get(),
file_spec,
m_options.m_verbose ? eDescriptionLevelFull
: eDescriptionLevelBrief))
@@ -3903,25 +3892,20 @@ protected:
const ModuleList &target_modules = target->GetImages();
std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
- const size_t num_modules = target_modules.GetSize();
- if (num_modules > 0) {
- for (i = 0; i < num_modules && !syntax_error; ++i) {
- Module *module_pointer =
- target_modules.GetModulePointerAtIndexUnlocked(i);
-
- if (module_pointer != current_module.get() &&
- LookupInModule(m_interpreter,
- target_modules.GetModulePointerAtIndexUnlocked(i),
- result, syntax_error)) {
- result.GetOutputStream().EOL();
- num_successful_lookups++;
- }
- }
- } else {
+ if (target_modules.GetSize() == 0) {
result.AppendError("the target has no associated executable images");
result.SetStatus(eReturnStatusFailed);
return false;
}
+
+ for (ModuleSP module_sp : target_modules.ModulesNoLocking()) {
+ if (module_sp != current_module &&
+ LookupInModule(m_interpreter, module_sp.get(), result,
+ syntax_error)) {
+ result.GetOutputStream().EOL();
+ num_successful_lookups++;
+ }
+ }
} else {
// Dump specified images (by basename or fullpath)
const char *arg_cstr;