@@ -1399,31 +1399,30 @@ static void DumpBasename(Stream &strm, const FileSpec *file_spec_ptr,
1399
1399
}
1400
1400
1401
1401
static size_t DumpModuleObjfileHeaders (Stream &strm, ModuleList &module_list) {
1402
- size_t num_dumped = 0 ;
1403
1402
std::lock_guard<std::recursive_mutex> guard (module_list.GetMutex ());
1404
1403
const size_t num_modules = module_list.GetSize ();
1405
- if (num_modules > 0 ) {
1406
- strm. Printf ( " Dumping headers for % " PRIu64 " module(s). \n " ,
1407
- static_cast < uint64_t >(num_modules));
1408
- strm. IndentMore () ;
1409
- for ( size_t image_idx = 0 ; image_idx < num_modules; ++image_idx) {
1410
- Module * module = module_list. GetModulePointerAtIndexUnlocked (image_idx );
1411
- if ( module ) {
1412
- if (num_dumped++ > 0 ) {
1413
- strm. EOL ();
1414
- strm.EOL ();
1415
- }
1416
- ObjectFile *objfile = module -> GetObjectFile ();
1417
- if (objfile)
1418
- objfile-> Dump (&strm);
1419
- else {
1420
- strm. Format ( " No object file for module: {0:F} \n " ,
1421
- module -> GetFileSpec ());
1422
- }
1404
+ if (num_modules == 0 )
1405
+ return 0 ;
1406
+
1407
+ size_t num_dumped = 0 ;
1408
+ strm. Format ( " Dumping headers for {0} module(s). \n " , num_modules);
1409
+ strm. IndentMore ( );
1410
+ for (ModuleSP module_sp : module_list. ModulesNoLocking () ) {
1411
+ if (module_sp ) {
1412
+ if (num_dumped++ > 0 ) {
1413
+ strm.EOL ();
1414
+ strm. EOL ();
1415
+ }
1416
+ ObjectFile *objfile = module_sp-> GetObjectFile ();
1417
+ if (objfile)
1418
+ objfile-> Dump (&strm);
1419
+ else {
1420
+ strm. Format ( " No object file for module: {0:F} \n " ,
1421
+ module_sp-> GetFileSpec ());
1423
1422
}
1424
1423
}
1425
- strm.IndentLess ();
1426
1424
}
1425
+ strm.IndentLess ();
1427
1426
return num_dumped;
1428
1427
}
1429
1428
@@ -2025,25 +2024,23 @@ class CommandObjectTargetModulesDumpSymtab
2025
2024
2026
2025
if (command.GetArgumentCount () == 0 ) {
2027
2026
// Dump all sections for all modules images
2028
- std::lock_guard<std::recursive_mutex> guard (
2029
- target-> GetImages () .GetMutex ());
2030
- const size_t num_modules = target-> GetImages () .GetSize ();
2027
+ const ModuleList &module_list = target-> GetImages ();
2028
+ std::lock_guard<std::recursive_mutex> guard (module_list .GetMutex ());
2029
+ const size_t num_modules = module_list .GetSize ();
2031
2030
if (num_modules > 0 ) {
2032
- result.GetOutputStream ().Printf (" Dumping symbol table for %" PRIu64
2033
- " modules.\n " ,
2034
- (uint64_t )num_modules);
2035
- for (size_t image_idx = 0 ; image_idx < num_modules; ++image_idx) {
2031
+ result.GetOutputStream ().Format (
2032
+ " Dumping symbol table for {0} modules.\n " , num_modules);
2033
+ for (ModuleSP module_sp : module_list.ModulesNoLocking ()) {
2036
2034
if (num_dumped > 0 ) {
2037
2035
result.GetOutputStream ().EOL ();
2038
2036
result.GetOutputStream ().EOL ();
2039
2037
}
2040
2038
if (m_interpreter.WasInterrupted ())
2041
2039
break ;
2042
2040
num_dumped++;
2043
- DumpModuleSymtab (
2044
- m_interpreter, result.GetOutputStream (),
2045
- target->GetImages ().GetModulePointerAtIndexUnlocked (image_idx),
2046
- m_options.m_sort_order , name_preference);
2041
+ DumpModuleSymtab (m_interpreter, result.GetOutputStream (),
2042
+ module_sp.get (), m_options.m_sort_order ,
2043
+ name_preference);
2047
2044
}
2048
2045
} else {
2049
2046
result.AppendError (" the target has no associated executable images" );
@@ -2060,18 +2057,18 @@ class CommandObjectTargetModulesDumpSymtab
2060
2057
const size_t num_matches =
2061
2058
FindModulesByName (target, arg_cstr, module_list, true );
2062
2059
if (num_matches > 0 ) {
2063
- for (size_t i = 0 ; i < num_matches; ++i) {
2064
- Module *module = module_list.GetModulePointerAtIndex (i);
2065
- if (module ) {
2060
+ for (ModuleSP module_sp : module_list.Modules ()) {
2061
+ if (module_sp) {
2066
2062
if (num_dumped > 0 ) {
2067
2063
result.GetOutputStream ().EOL ();
2068
2064
result.GetOutputStream ().EOL ();
2069
2065
}
2070
2066
if (m_interpreter.WasInterrupted ())
2071
2067
break ;
2072
2068
num_dumped++;
2073
- DumpModuleSymtab (m_interpreter, result.GetOutputStream (), module ,
2074
- m_options.m_sort_order , name_preference);
2069
+ DumpModuleSymtab (m_interpreter, result.GetOutputStream (),
2070
+ module_sp.get (), m_options.m_sort_order ,
2071
+ name_preference);
2075
2072
}
2076
2073
}
2077
2074
} else
@@ -2120,23 +2117,22 @@ class CommandObjectTargetModulesDumpSections
2120
2117
if (command.GetArgumentCount () == 0 ) {
2121
2118
// Dump all sections for all modules images
2122
2119
const size_t num_modules = target->GetImages ().GetSize ();
2123
- if (num_modules > 0 ) {
2124
- result.GetOutputStream ().Printf (" Dumping sections for %" PRIu64
2125
- " modules.\n " ,
2126
- (uint64_t )num_modules);
2127
- for (size_t image_idx = 0 ; image_idx < num_modules; ++image_idx) {
2128
- if (m_interpreter.WasInterrupted ())
2129
- break ;
2130
- num_dumped++;
2131
- DumpModuleSections (
2132
- m_interpreter, result.GetOutputStream (),
2133
- target->GetImages ().GetModulePointerAtIndex (image_idx));
2134
- }
2135
- } else {
2120
+ if (num_modules == 0 ) {
2136
2121
result.AppendError (" the target has no associated executable images" );
2137
2122
result.SetStatus (eReturnStatusFailed);
2138
2123
return false ;
2139
2124
}
2125
+
2126
+ result.GetOutputStream ().Format (" Dumping sections for {0} modules.\n " ,
2127
+ num_modules);
2128
+ for (size_t image_idx = 0 ; image_idx < num_modules; ++image_idx) {
2129
+ if (m_interpreter.WasInterrupted ())
2130
+ break ;
2131
+ num_dumped++;
2132
+ DumpModuleSections (
2133
+ m_interpreter, result.GetOutputStream (),
2134
+ target->GetImages ().GetModulePointerAtIndex (image_idx));
2135
+ }
2140
2136
} else {
2141
2137
// Dump specified images (by basename or fullpath)
2142
2138
const char *arg_cstr;
@@ -2198,7 +2194,8 @@ class CommandObjectTargetModulesDumpClangAST
2198
2194
bool DoExecute (Args &command, CommandReturnObject &result) override {
2199
2195
Target *target = &GetSelectedTarget ();
2200
2196
2201
- const size_t num_modules = target->GetImages ().GetSize ();
2197
+ const ModuleList &module_list = target->GetImages ();
2198
+ const size_t num_modules = module_list.GetSize ();
2202
2199
if (num_modules == 0 ) {
2203
2200
result.AppendError (" the target has no associated executable images" );
2204
2201
result.SetStatus (eReturnStatusFailed);
@@ -2207,14 +2204,12 @@ class CommandObjectTargetModulesDumpClangAST
2207
2204
2208
2205
if (command.GetArgumentCount () == 0 ) {
2209
2206
// Dump all ASTs for all modules images
2210
- result.GetOutputStream ().Printf (" Dumping clang ast for %" PRIu64
2211
- " modules.\n " ,
2212
- (uint64_t )num_modules);
2213
- for (size_t image_idx = 0 ; image_idx < num_modules; ++image_idx) {
2207
+ result.GetOutputStream ().Format (" Dumping clang ast for {0} modules.\n " ,
2208
+ num_modules);
2209
+ for (ModuleSP module_sp : module_list.ModulesNoLocking ()) {
2214
2210
if (m_interpreter.WasInterrupted ())
2215
2211
break ;
2216
- Module *m = target->GetImages ().GetModulePointerAtIndex (image_idx);
2217
- if (SymbolFile *sf = m->GetSymbolFile ())
2212
+ if (SymbolFile *sf = module_sp->GetSymbolFile ())
2218
2213
sf->DumpClangAST (result.GetOutputStream ());
2219
2214
}
2220
2215
result.SetStatus (eReturnStatusSuccessFinishResult);
@@ -2279,23 +2274,19 @@ class CommandObjectTargetModulesDumpSymfile
2279
2274
const ModuleList &target_modules = target->GetImages ();
2280
2275
std::lock_guard<std::recursive_mutex> guard (target_modules.GetMutex ());
2281
2276
const size_t num_modules = target_modules.GetSize ();
2282
- if (num_modules > 0 ) {
2283
- result.GetOutputStream ().Printf (" Dumping debug symbols for %" PRIu64
2284
- " modules.\n " ,
2285
- (uint64_t )num_modules);
2286
- for (uint32_t image_idx = 0 ; image_idx < num_modules; ++image_idx) {
2287
- if (m_interpreter.WasInterrupted ())
2288
- break ;
2289
- if (DumpModuleSymbolFile (
2290
- result.GetOutputStream (),
2291
- target_modules.GetModulePointerAtIndexUnlocked (image_idx)))
2292
- num_dumped++;
2293
- }
2294
- } else {
2277
+ if (num_modules == 0 ) {
2295
2278
result.AppendError (" the target has no associated executable images" );
2296
2279
result.SetStatus (eReturnStatusFailed);
2297
2280
return false ;
2298
2281
}
2282
+ result.GetOutputStream ().Format (
2283
+ " Dumping debug symbols for {0} modules.\n " , num_modules);
2284
+ for (ModuleSP module_sp : target_modules.ModulesNoLocking ()) {
2285
+ if (m_interpreter.WasInterrupted ())
2286
+ break ;
2287
+ if (DumpModuleSymbolFile (result.GetOutputStream (), module_sp.get ()))
2288
+ num_dumped++;
2289
+ }
2299
2290
} else {
2300
2291
// Dump specified images (by basename or fullpath)
2301
2292
const char *arg_cstr;
@@ -2373,15 +2364,13 @@ class CommandObjectTargetModulesDumpLineTable
2373
2364
2374
2365
const ModuleList &target_modules = target->GetImages ();
2375
2366
std::lock_guard<std::recursive_mutex> guard (target_modules.GetMutex ());
2376
- const size_t num_modules = target_modules.GetSize ();
2377
- if (num_modules > 0 ) {
2367
+ if (target_modules.GetSize () > 0 ) {
2378
2368
uint32_t num_dumped = 0 ;
2379
- for (uint32_t i = 0 ; i < num_modules; ++i ) {
2369
+ for (ModuleSP module_sp : target_modules. ModulesNoLocking () ) {
2380
2370
if (m_interpreter.WasInterrupted ())
2381
2371
break ;
2382
2372
if (DumpCompileUnitLineTable (
2383
- m_interpreter, result.GetOutputStream (),
2384
- target_modules.GetModulePointerAtIndexUnlocked (i),
2373
+ m_interpreter, result.GetOutputStream (), module_sp.get (),
2385
2374
file_spec,
2386
2375
m_options.m_verbose ? eDescriptionLevelFull
2387
2376
: eDescriptionLevelBrief))
@@ -3903,25 +3892,20 @@ class CommandObjectTargetModulesLookup : public CommandObjectParsed {
3903
3892
3904
3893
const ModuleList &target_modules = target->GetImages ();
3905
3894
std::lock_guard<std::recursive_mutex> guard (target_modules.GetMutex ());
3906
- const size_t num_modules = target_modules.GetSize ();
3907
- if (num_modules > 0 ) {
3908
- for (i = 0 ; i < num_modules && !syntax_error; ++i) {
3909
- Module *module_pointer =
3910
- target_modules.GetModulePointerAtIndexUnlocked (i);
3911
-
3912
- if (module_pointer != current_module.get () &&
3913
- LookupInModule (m_interpreter,
3914
- target_modules.GetModulePointerAtIndexUnlocked (i),
3915
- result, syntax_error)) {
3916
- result.GetOutputStream ().EOL ();
3917
- num_successful_lookups++;
3918
- }
3919
- }
3920
- } else {
3895
+ if (target_modules.GetSize () == 0 ) {
3921
3896
result.AppendError (" the target has no associated executable images" );
3922
3897
result.SetStatus (eReturnStatusFailed);
3923
3898
return false ;
3924
3899
}
3900
+
3901
+ for (ModuleSP module_sp : target_modules.ModulesNoLocking ()) {
3902
+ if (module_sp != current_module &&
3903
+ LookupInModule (m_interpreter, module_sp.get (), result,
3904
+ syntax_error)) {
3905
+ result.GetOutputStream ().EOL ();
3906
+ num_successful_lookups++;
3907
+ }
3908
+ }
3925
3909
} else {
3926
3910
// Dump specified images (by basename or fullpath)
3927
3911
const char *arg_cstr;
0 commit comments