diff options
| author | Adrian Prantl <aprantl@apple.com> | 2018-04-30 16:49:04 +0000 |
|---|---|---|
| committer | Adrian Prantl <aprantl@apple.com> | 2018-04-30 16:49:04 +0000 |
| commit | 05097246f352eca76207c9ebb08656c88bdf751a (patch) | |
| tree | bfc4ec8250a939aaf4ade6fc6c528726183e5367 /lldb/source/Plugins/DynamicLoader/MacOSX-DYLD | |
| parent | add59c052dd6768fd54431e6a3bf045e7f25cb59 (diff) | |
| download | bcm5719-llvm-05097246f352eca76207c9ebb08656c88bdf751a.tar.gz bcm5719-llvm-05097246f352eca76207c9ebb08656c88bdf751a.zip | |
Reflow paragraphs in comments.
This is intended as a clean up after the big clang-format commit
(r280751), which unfortunately resulted in many of the comment
paragraphs in LLDB being very hard to read.
FYI, the script I used was:
import textwrap
import commands
import os
import sys
import re
tmp = "%s.tmp"%sys.argv[1]
out = open(tmp, "w+")
with open(sys.argv[1], "r") as f:
header = ""
text = ""
comment = re.compile(r'^( *//) ([^ ].*)$')
special = re.compile(r'^((([A-Z]+[: ])|([0-9]+ )).*)|(.*;)$')
for line in f:
match = comment.match(line)
if match and not special.match(match.group(2)):
# skip intentionally short comments.
if not text and len(match.group(2)) < 40:
out.write(line)
continue
if text:
text += " " + match.group(2)
else:
header = match.group(1)
text = match.group(2)
continue
if text:
filled = textwrap.wrap(text, width=(78-len(header)),
break_long_words=False)
for l in filled:
out.write(header+" "+l+'\n')
text = ""
out.write(line)
os.rename(tmp, sys.argv[1])
Differential Revision: https://reviews.llvm.org/D46144
llvm-svn: 331197
Diffstat (limited to 'lldb/source/Plugins/DynamicLoader/MacOSX-DYLD')
3 files changed, 182 insertions, 211 deletions
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp index 703b461f6fe..3a43751398d 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp @@ -112,8 +112,8 @@ ModuleSP DynamicLoaderDarwin::FindTargetModuleForImageInfo( if (module_sp && !module_spec.GetUUID().IsValid() && !module_sp->GetUUID().IsValid()) { - // No UUID, we must rely upon the cached module modification - // time and the modification time of the file on disk + // No UUID, we must rely upon the cached module modification time and the + // modification time of the file on disk if (module_sp->GetModificationTime() != FileSystem::GetModificationTime(module_sp->GetFileSpec())) module_sp.reset(); @@ -198,8 +198,7 @@ void DynamicLoaderDarwin::UnloadAllImages() { ModuleSP module_sp = target_modules.GetModuleAtIndexUnlocked(i); // Don't remove dyld - else we'll lose our breakpoint notifying us about - // libraries - // being re-loaded... + // libraries being re-loaded... if (module_sp.get() != nullptr && module_sp.get() != dyld_sp.get()) { UnloadSections(module_sp); unloaded_modules_list.Append(module_sp); @@ -219,8 +218,8 @@ void DynamicLoaderDarwin::UnloadAllImages() { } //---------------------------------------------------------------------- -// Update the load addresses for all segments in MODULE using the -// updated INFO that is passed in. +// Update the load addresses for all segments in MODULE using the updated INFO +// that is passed in. //---------------------------------------------------------------------- bool DynamicLoaderDarwin::UpdateImageLoadAddress(Module *module, ImageInfo &info) { @@ -231,13 +230,12 @@ bool DynamicLoaderDarwin::UpdateImageLoadAddress(Module *module, SectionList *section_list = image_object_file->GetSectionList(); if (section_list) { std::vector<uint32_t> inaccessible_segment_indexes; - // We now know the slide amount, so go through all sections - // and update the load addresses with the correct values. + // We now know the slide amount, so go through all sections and update + // the load addresses with the correct values. const size_t num_segments = info.segments.size(); for (size_t i = 0; i < num_segments; ++i) { - // Only load a segment if it has protections. Things like - // __PAGEZERO don't have any protections, and they shouldn't - // be slid + // Only load a segment if it has protections. Things like __PAGEZERO + // don't have any protections, and they shouldn't be slid SectionSP section_sp( section_list->FindSectionByName(info.segments[i].name)); @@ -249,10 +247,10 @@ bool DynamicLoaderDarwin::UpdateImageLoadAddress(Module *module, static ConstString g_section_name_LINKEDIT("__LINKEDIT"); if (section_sp) { - // __LINKEDIT sections from files in the shared cache - // can overlap so check to see what the segment name is - // and pass "false" so we don't warn of overlapping - // "Section" objects, and "true" for all other sections. + // __LINKEDIT sections from files in the shared cache can overlap + // so check to see what the segment name is and pass "false" so + // we don't warn of overlapping "Section" objects, and "true" for + // all other sections. const bool warn_multiple = section_sp->GetName() != g_section_name_LINKEDIT; @@ -270,13 +268,12 @@ bool DynamicLoaderDarwin::UpdateImageLoadAddress(Module *module, } } - // If the loaded the file (it changed) and we have segments that - // are not readable or writeable, add them to the invalid memory - // region cache for the process. This will typically only be - // the __PAGEZERO segment in the main executable. We might be able - // to apply this more generally to more sections that have no - // protections in the future, but for now we are going to just - // do __PAGEZERO. + // If the loaded the file (it changed) and we have segments that are + // not readable or writeable, add them to the invalid memory region + // cache for the process. This will typically only be the __PAGEZERO + // segment in the main executable. We might be able to apply this more + // generally to more sections that have no protections in the future, + // but for now we are going to just do __PAGEZERO. if (changed && !inaccessible_segment_indexes.empty()) { for (uint32_t i = 0; i < inaccessible_segment_indexes.size(); ++i) { const uint32_t seg_idx = inaccessible_segment_indexes[i]; @@ -344,8 +341,7 @@ bool DynamicLoaderDarwin::UnloadModuleSections(Module *module, } // Given a JSON dictionary (from debugserver, most likely) of binary images -// loaded in the inferior -// process, add the images to the ImageInfo collection. +// loaded in the inferior process, add the images to the ImageInfo collection. bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo( StructuredData::ObjectSP image_details, @@ -412,8 +408,7 @@ bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo( } // Fields that aren't used by DynamicLoaderDarwin so debugserver doesn't - // currently send them - // in the reply. + // currently send them in the reply. if (mh->HasKey("flags")) image_infos[i].header.flags = @@ -454,8 +449,7 @@ bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo( seg->GetValueForKey("maxprot")->GetAsInteger()->GetValue(); // Fields that aren't used by DynamicLoaderDarwin so debugserver doesn't - // currently send them - // in the reply. + // currently send them in the reply. if (seg->HasKey("initprot")) segment.initprot = @@ -481,25 +475,23 @@ bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo( image_infos[i].uuid.SetFromStringRef( image->GetValueForKey("uuid")->GetAsString()->GetValue()); - // All sections listed in the dyld image info structure will all - // either be fixed up already, or they will all be off by a single - // slide amount that is determined by finding the first segment - // that is at file offset zero which also has bytes (a file size - // that is greater than zero) in the object file. + // All sections listed in the dyld image info structure will all either be + // fixed up already, or they will all be off by a single slide amount that + // is determined by finding the first segment that is at file offset zero + // which also has bytes (a file size that is greater than zero) in the + // object file. // Determine the slide amount (if any) const size_t num_sections = image_infos[i].segments.size(); for (size_t k = 0; k < num_sections; ++k) { - // Iterate through the object file sections to find the - // first section that starts of file offset zero and that - // has bytes in the file... + // Iterate through the object file sections to find the first section + // that starts of file offset zero and that has bytes in the file... if ((image_infos[i].segments[k].fileoff == 0 && image_infos[i].segments[k].filesize > 0) || (image_infos[i].segments[k].name == ConstString("__TEXT"))) { image_infos[i].slide = image_infos[i].address - image_infos[i].segments[k].vmaddr; - // We have found the slide amount, so we can exit - // this for loop. + // We have found the slide amount, so we can exit this for loop. break; } } @@ -520,16 +512,15 @@ void DynamicLoaderDarwin::UpdateSpecialBinariesFromNewImageInfos( const size_t image_infos_size = image_infos.size(); for (size_t i = 0; i < image_infos_size; i++) { if (image_infos[i].header.filetype == llvm::MachO::MH_DYLINKER) { - // In a "simulator" process (an x86 process that is ios/tvos/watchos) - // we will have two dyld modules -- a "dyld" that we want to keep track - // of, - // and a "dyld_sim" which we don't need to keep track of here. - // If the target is an x86 system and the OS of the dyld binary is + // In a "simulator" process (an x86 process that is ios/tvos/watchos) we + // will have two dyld modules -- a "dyld" that we want to keep track of, + // and a "dyld_sim" which we don't need to keep track of here. If the + // target is an x86 system and the OS of the dyld binary is // ios/tvos/watchos, then we are looking at dyld_sym. - // debugserver has only recently (late 2016) started sending up the - // os type for each binary it sees -- so if we don't have an os - // type, use a filename check as our next best guess. + // debugserver has only recently (late 2016) started sending up the os + // type for each binary it sees -- so if we don't have an os type, use a + // filename check as our next best guess. if (image_infos[i].os_type == llvm::Triple::OSType::UnknownOS) { if (image_infos[i].file_spec.GetFilename() != g_dyld_sim_filename) { dyld_idx = i; @@ -543,7 +534,8 @@ void DynamicLoaderDarwin::UpdateSpecialBinariesFromNewImageInfos( } } else { - // catch-all for any other environment -- trust that dyld is actually dyld + // catch-all for any other environment -- trust that dyld is actually + // dyld dyld_idx = i; } } else if (image_infos[i].header.filetype == llvm::MachO::MH_EXECUTE) { @@ -669,11 +661,10 @@ bool DynamicLoaderDarwin::AddModulesUsingImageInfos( } } - // UpdateImageLoadAddress will return true if any segments - // change load address. We need to check this so we don't - // mention that all loaded shared libraries are newly loaded - // each time we hit out dyld breakpoint since dyld will list all - // shared libraries each time. + // UpdateImageLoadAddress will return true if any segments change load + // address. We need to check this so we don't mention that all loaded + // shared libraries are newly loaded each time we hit out dyld breakpoint + // since dyld will list all shared libraries each time. if (UpdateImageLoadAddress(image_module_sp.get(), image_infos[idx])) { target_images.AppendIfNeeded(image_module_sp); loaded_module_list.AppendIfNeeded(image_module_sp); @@ -692,12 +683,11 @@ bool DynamicLoaderDarwin::AddModulesUsingImageInfos( //---------------------------------------------------------------------- // On Mac OS X libobjc (the Objective-C runtime) has several critical dispatch -// functions written in hand-written assembly, and also have hand-written unwind -// information in the eh_frame section. Normally we prefer analyzing the -// assembly instructions of a currently executing frame to unwind from that -// frame -- -// but on hand-written functions this profiling can fail. We should use the -// eh_frame instructions for these functions all the time. +// functions written in hand-written assembly, and also have hand-written +// unwind information in the eh_frame section. Normally we prefer analyzing +// the assembly instructions of a currently executing frame to unwind from that +// frame -- but on hand-written functions this profiling can fail. We should +// use the eh_frame instructions for these functions all the time. // // As an aside, it would be better if the eh_frame entries had a flag (or were // extensible so they could have an Apple-specific flag) which indicates that @@ -817,8 +807,8 @@ void DynamicLoaderDarwin::PrivateProcessStateChanged(Process *process, break; case eStateStopped: - // Keep trying find dyld and set our notification breakpoint each time - // we stop until we succeed + // Keep trying find dyld and set our notification breakpoint each time we + // stop until we succeed if (!DidSetNotificationBreakpoint() && m_process->IsAlive()) { if (NeedToDoInitialImageFetch()) DoInitialImageFetch(); @@ -956,8 +946,8 @@ DynamicLoaderDarwin::GetStepThroughTrampolinePlan(Thread &thread, } if (addresses.size() > 0) { - // First check whether any of the addresses point to Indirect symbols, and - // if they do, resolve them: + // First check whether any of the addresses point to Indirect symbols, + // and if they do, resolve them: std::vector<lldb::addr_t> load_addrs; for (Address address : addresses) { Symbol *symbol = address.CalculateSymbolContextSymbol(); @@ -1073,10 +1063,10 @@ DynamicLoaderDarwin::GetThreadLocalData(const lldb::ModuleSP module_sp, const lldb::addr_t pthread_key = data.GetAddress(&offset); const lldb::addr_t tls_offset = data.GetAddress(&offset); if (pthread_key != 0) { - // First check to see if we have already figured out the location - // of TLS data for the pthread_key on a specific thread yet. If we - // have we can re-use it since its location will not change unless - // the process execs. + // First check to see if we have already figured out the location of + // TLS data for the pthread_key on a specific thread yet. If we have we + // can re-use it since its location will not change unless the process + // execs. const tid_t tid = thread_sp->GetID(); auto tid_pos = m_tid_to_tls_map.find(tid); if (tid_pos != m_tid_to_tls_map.end()) { diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp index 66085a23759..8178b5b155d 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp @@ -29,9 +29,9 @@ using namespace lldb; using namespace lldb_private; //---------------------------------------------------------------------- -// Create an instance of this class. This function is filled into -// the plugin info class that gets handed out by the plugin factory and -// allows the lldb to instantiate an instance of this class. +// Create an instance of this class. This function is filled into the plugin +// info class that gets handed out by the plugin factory and allows the lldb to +// instantiate an instance of this class. //---------------------------------------------------------------------- DynamicLoader *DynamicLoaderMacOS::CreateInstance(Process *process, bool force) { @@ -144,17 +144,18 @@ void DynamicLoaderMacOS::ClearNotificationBreakpoint() { } //---------------------------------------------------------------------- -// Try and figure out where dyld is by first asking the Process -// if it knows (which currently calls down in the lldb::Process -// to get the DYLD info (available on SnowLeopard only). If that fails, -// then check in the default addresses. +// Try and figure out where dyld is by first asking the Process if it knows +// (which currently calls down in the lldb::Process to get the DYLD info +// (available on SnowLeopard only). If that fails, then check in the default +// addresses. //---------------------------------------------------------------------- void DynamicLoaderMacOS::DoInitialImageFetch() { Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); - // Remove any binaries we pre-loaded in the Target before launching/attaching. - // If the same binaries are present in the process, we'll get them from the - // shared module cache, we won't need to re-load them from disk. + // Remove any binaries we pre-loaded in the Target before + // launching/attaching. If the same binaries are present in the process, + // we'll get them from the shared module cache, we won't need to re-load them + // from disk. UnloadAllImages(); StructuredData::ObjectSP all_image_info_json_sp( @@ -184,9 +185,9 @@ bool DynamicLoaderMacOS::NeedToDoInitialImageFetch() { return true; } //---------------------------------------------------------------------- // Static callback function that gets called when our DYLD notification -// breakpoint gets hit. We update all of our image infos and then -// let our super class DynamicLoader class decide if we should stop -// or not (based on global preference). +// breakpoint gets hit. We update all of our image infos and then let our super +// class DynamicLoader class decide if we should stop or not (based on global +// preference). //---------------------------------------------------------------------- bool DynamicLoaderMacOS::NotifyBreakpointHit(void *baton, StoppointCallbackContext *context, @@ -194,11 +195,10 @@ bool DynamicLoaderMacOS::NotifyBreakpointHit(void *baton, lldb::user_id_t break_loc_id) { // Let the event know that the images have changed // DYLD passes three arguments to the notification breakpoint. - // Arg1: enum dyld_notify_mode mode - 0 = adding, 1 = removing, 2 = remove all - // Arg2: unsigned long icount - Number of shared libraries - // added/removed - // Arg3: uint64_t mach_headers[] - Array of load addresses of binaries - // added/removed + // Arg1: enum dyld_notify_mode mode - 0 = adding, 1 = removing, 2 = remove + // all Arg2: unsigned long icount - Number of shared libraries + // added/removed Arg3: uint64_t mach_headers[] - Array of load addresses + // of binaries added/removed DynamicLoaderMacOS *dyld_instance = (DynamicLoaderMacOS *)baton; @@ -328,8 +328,8 @@ void DynamicLoaderMacOS::AddBinaries( } } -// Dump the _dyld_all_image_infos members and all current image infos -// that we have parsed to the file handle provided. +// Dump the _dyld_all_image_infos members and all current image infos that we +// have parsed to the file handle provided. //---------------------------------------------------------------------- void DynamicLoaderMacOS::PutToLog(Log *log) const { if (log == NULL) @@ -432,9 +432,9 @@ Status DynamicLoaderMacOS::CanLoadImage() { } } - // Default assumption is that it is OK to load images. - // Only say that we cannot load images if we find the symbol in libdyld and it - // indicates that we cannot. + // Default assumption is that it is OK to load images. Only say that we + // cannot load images if we find the symbol in libdyld and it indicates that + // we cannot. if (symbol_address != LLDB_INVALID_ADDRESS) { { @@ -445,11 +445,11 @@ Status DynamicLoaderMacOS::CanLoadImage() { } } } else { - // If we were unable to find _dyld_global_lock_held in any modules, or it is - // not loaded into memory yet, we may be at process startup (sitting - // at _dyld_start) - so we should not allow dlopen calls. - // But if we found more than one module then we are clearly past _dyld_start - // so in that case we'll default to "it's safe". + // If we were unable to find _dyld_global_lock_held in any modules, or it + // is not loaded into memory yet, we may be at process startup (sitting at + // _dyld_start) - so we should not allow dlopen calls. But if we found more + // than one module then we are clearly past _dyld_start so in that case + // we'll default to "it's safe". if (num_modules <= 1) error.SetErrorString("could not find the dyld library or " "the dyld lock symbol"); @@ -472,7 +472,9 @@ bool DynamicLoaderMacOS::GetSharedCacheInformation( info_dict = info->GetAsDictionary(); } - // {"shared_cache_base_address":140735683125248,"shared_cache_uuid":"DDB8D70C-C9A2-3561-B2C8-BE48A4F33F96","no_shared_cache":false,"shared_cache_private_cache":false} + // {"shared_cache_base_address":140735683125248,"shared_cache_uuid + // ":"DDB8D70C- + // C9A2-3561-B2C8-BE48A4F33F96","no_shared_cache":false,"shared_cache_private_cache":false} if (info_dict && info_dict->HasKey("shared_cache_uuid") && info_dict->HasKey("no_shared_cache") && diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp index e0def58f41c..6cabbef0a25 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -49,9 +49,9 @@ using namespace lldb; using namespace lldb_private; //---------------------------------------------------------------------- -// Create an instance of this class. This function is filled into -// the plugin info class that gets handed out by the plugin factory and -// allows the lldb to instantiate an instance of this class. +// Create an instance of this class. This function is filled into the plugin +// info class that gets handed out by the plugin factory and allows the lldb to +// instantiate an instance of this class. //---------------------------------------------------------------------- DynamicLoader *DynamicLoaderMacOSXDYLD::CreateInstance(Process *process, bool force) { @@ -123,17 +123,18 @@ bool DynamicLoaderMacOSXDYLD::ProcessDidExec() { const addr_t shlib_addr = m_process->GetImageInfoAddress(); if (m_process_image_addr_is_all_images_infos == true && shlib_addr != m_dyld_all_image_infos_addr) { - // The image info address from the process is the 'dyld_all_image_infos' - // address and it has changed. + // The image info address from the process is the + // 'dyld_all_image_infos' address and it has changed. did_exec = true; } else if (m_process_image_addr_is_all_images_infos == false && shlib_addr == m_dyld.address) { - // The image info address from the process is the mach_header - // address for dyld and it has changed. + // The image info address from the process is the mach_header address + // for dyld and it has changed. did_exec = true; } else { // ASLR might be disabled and dyld could have ended up in the same - // location. We should try and detect if we are stopped at '_dyld_start' + // location. We should try and detect if we are stopped at + // '_dyld_start' ThreadSP thread_sp(m_process->GetThreadList().GetThreadAtIndex(0)); if (thread_sp) { lldb::StackFrameSP frame_sp(thread_sp->GetStackFrameAtIndex(0)); @@ -185,16 +186,15 @@ void DynamicLoaderMacOSXDYLD::ClearNotificationBreakpoint() { } //---------------------------------------------------------------------- -// Try and figure out where dyld is by first asking the Process -// if it knows (which currently calls down in the lldb::Process -// to get the DYLD info (available on SnowLeopard only). If that fails, -// then check in the default addresses. +// Try and figure out where dyld is by first asking the Process if it knows +// (which currently calls down in the lldb::Process to get the DYLD info +// (available on SnowLeopard only). If that fails, then check in the default +// addresses. //---------------------------------------------------------------------- void DynamicLoaderMacOSXDYLD::DoInitialImageFetch() { if (m_dyld_all_image_infos_addr == LLDB_INVALID_ADDRESS) { - // Check the image info addr as it might point to the - // mach header for dyld, or it might point to the - // dyld_all_image_infos struct + // Check the image info addr as it might point to the mach header for dyld, + // or it might point to the dyld_all_image_infos struct const addr_t shlib_addr = m_process->GetImageInfoAddress(); if (shlib_addr != LLDB_INVALID_ADDRESS) { ByteOrder byte_order = @@ -255,8 +255,7 @@ void DynamicLoaderMacOSXDYLD::DoInitialImageFetch() { } //---------------------------------------------------------------------- -// Assume that dyld is in memory at ADDR and try to parse it's load -// commands +// Assume that dyld is in memory at ADDR and try to parse it's load commands //---------------------------------------------------------------------- bool DynamicLoaderMacOSXDYLD::ReadDYLDInfoFromMemoryAndSetNotificationCallback( lldb::addr_t addr) { @@ -287,10 +286,10 @@ bool DynamicLoaderMacOSXDYLD::ReadDYLDInfoFromMemoryAndSetNotificationCallback( // Update all image infos InitializeFromAllImageInfos(); - // If we didn't have an executable before, but now we do, then the - // dyld module shared pointer might be unique and we may need to add - // it again (since Target::SetExecutableModule() will clear the - // images). So append the dyld module back to the list if it is + // If we didn't have an executable before, but now we do, then the dyld + // module shared pointer might be unique and we may need to add it again + // (since Target::SetExecutableModule() will clear the images). So append + // the dyld module back to the list if it is /// unique! if (dyld_module_sp) { target.GetImages().AppendIfNeeded(dyld_module_sp); @@ -315,18 +314,18 @@ bool DynamicLoaderMacOSXDYLD::NeedToDoInitialImageFetch() { //---------------------------------------------------------------------- // Static callback function that gets called when our DYLD notification -// breakpoint gets hit. We update all of our image infos and then -// let our super class DynamicLoader class decide if we should stop -// or not (based on global preference). +// breakpoint gets hit. We update all of our image infos and then let our super +// class DynamicLoader class decide if we should stop or not (based on global +// preference). //---------------------------------------------------------------------- bool DynamicLoaderMacOSXDYLD::NotifyBreakpointHit( void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id) { // Let the event know that the images have changed // DYLD passes three arguments to the notification breakpoint. - // Arg1: enum dyld_image_mode mode - 0 = adding, 1 = removing - // Arg2: uint32_t infoCount - Number of shared libraries added - // Arg3: dyld_image_info info[] - Array of structs of the form: + // Arg1: enum dyld_image_mode mode - 0 = adding, 1 = removing Arg2: uint32_t + // infoCount - Number of shared libraries added Arg3: dyld_image_info + // info[] - Array of structs of the form: // const struct mach_header // *imageLoadAddress // const char *imageFilePath @@ -335,11 +334,10 @@ bool DynamicLoaderMacOSXDYLD::NotifyBreakpointHit( DynamicLoaderMacOSXDYLD *dyld_instance = (DynamicLoaderMacOSXDYLD *)baton; // First step is to see if we've already initialized the all image infos. If - // we haven't then this function - // will do so and return true. In the course of initializing the - // all_image_infos it will read the complete - // current state, so we don't need to figure out what has changed from the - // data passed in to us. + // we haven't then this function will do so and return true. In the course + // of initializing the all_image_infos it will read the complete current + // state, so we don't need to figure out what has changed from the data + // passed in to us. ExecutionContext exe_ctx(context->exe_ctx_ref); Process *process = exe_ctx.GetProcessPtr(); @@ -388,11 +386,9 @@ bool DynamicLoaderMacOSXDYLD::NotifyBreakpointHit( argument_values.GetValueAtIndex(1)->GetScalar().UInt(-1); if (image_infos_count != static_cast<uint32_t>(-1)) { // Got the number added, now go through the array of added elements, - // putting out the mach header - // address, and adding the image. - // Note, I'm not putting in logging here, since the AddModules & - // RemoveModules functions do - // all the logging internally. + // putting out the mach header address, and adding the image. Note, + // I'm not putting in logging here, since the AddModules & + // RemoveModules functions do all the logging internally. lldb::addr_t image_infos_addr = argument_values.GetValueAtIndex(2)->GetScalar().ULongLong(); @@ -467,12 +463,12 @@ bool DynamicLoaderMacOSXDYLD::ReadAllImageInfosStructure() { if (m_process->ReadMemory(m_dyld_all_image_infos_addr, buf, 4, error) == 4) { m_dyld_all_image_infos.version = data.GetU32(&offset); - // If anything in the high byte is set, we probably got the byte - // order incorrect (the process might not have it set correctly - // yet due to attaching to a program without a specified file). + // If anything in the high byte is set, we probably got the byte order + // incorrect (the process might not have it set correctly yet due to + // attaching to a program without a specified file). if (m_dyld_all_image_infos.version & 0xff000000) { - // We have guessed the wrong byte order. Swap it and try - // reading the version again. + // We have guessed the wrong byte order. Swap it and try reading the + // version again. if (byte_order == eByteOrderLittle) byte_order = eByteOrderBig; else @@ -508,21 +504,17 @@ bool DynamicLoaderMacOSXDYLD::ReadAllImageInfosStructure() { uint64_t dyld_all_image_infos_addr = data.GetPointer(&offset); // When we started, we were given the actual address of the - // all_image_infos - // struct (probably via TASK_DYLD_INFO) in memory - this address is - // stored in - // m_dyld_all_image_infos_addr and is the most accurate address we have. + // all_image_infos struct (probably via TASK_DYLD_INFO) in memory - + // this address is stored in m_dyld_all_image_infos_addr and is the + // most accurate address we have. // We read the dyld_all_image_infos struct from memory; it contains its - // own address. - // If the address in the struct does not match the actual address, - // the dyld we're looking at has been loaded at a different location - // (slid) from - // where it intended to load. The addresses in the dyld_all_image_infos - // struct - // are the original, non-slid addresses, and need to be adjusted. Most - // importantly - // the address of dyld and the notification address need to be adjusted. + // own address. If the address in the struct does not match the actual + // address, the dyld we're looking at has been loaded at a different + // location (slid) from where it intended to load. The addresses in + // the dyld_all_image_infos struct are the original, non-slid + // addresses, and need to be adjusted. Most importantly the address of + // dyld and the notification address need to be adjusted. if (dyld_all_image_infos_addr != m_dyld_all_image_infos_addr) { uint64_t image_infos_offset = @@ -615,14 +607,13 @@ bool DynamicLoaderMacOSXDYLD::RemoveModulesUsingImageInfosAddress( image_infos[idx].PutToLog(log); } - // Remove this image_infos from the m_all_image_infos. We do the comparison - // by address - // rather than by file spec because we can have many modules with the same - // "file spec" in the - // case that they are modules loaded from memory. + // Remove this image_infos from the m_all_image_infos. We do the + // comparison by address rather than by file spec because we can have many + // modules with the same "file spec" in the case that they are modules + // loaded from memory. // - // Also copy over the uuid from the old entry to the removed entry so we can - // use it to lookup the module in the module list. + // Also copy over the uuid from the old entry to the removed entry so we + // can use it to lookup the module in the module list. ImageInfo::collection::iterator pos, end = m_dyld_image_infos.end(); for (pos = m_dyld_image_infos.begin(); pos != end; pos++) { @@ -630,8 +621,7 @@ bool DynamicLoaderMacOSXDYLD::RemoveModulesUsingImageInfosAddress( image_infos[idx].uuid = (*pos).uuid; // Add the module from this image_info to the "unloaded_module_list". - // We'll remove them all at - // one go later on. + // We'll remove them all at one go later on. ModuleSP unload_image_module_sp( FindTargetModuleForImageInfo(image_infos[idx], false, NULL)); @@ -713,11 +703,10 @@ bool DynamicLoaderMacOSXDYLD::ReadImageInfos( } //---------------------------------------------------------------------- -// If we have found where the "_dyld_all_image_infos" lives in memory, -// read the current info from it, and then update all image load -// addresses (or lack thereof). Only do this if this is the first time -// we're reading the dyld infos. Return true if we actually read anything, -// and false otherwise. +// If we have found where the "_dyld_all_image_infos" lives in memory, read the +// current info from it, and then update all image load addresses (or lack +// thereof). Only do this if this is the first time we're reading the dyld +// infos. Return true if we actually read anything, and false otherwise. //---------------------------------------------------------------------- bool DynamicLoaderMacOSXDYLD::InitializeFromAllImageInfos() { Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); @@ -748,14 +737,11 @@ bool DynamicLoaderMacOSXDYLD::InitializeFromAllImageInfos() { } // Now we have one more bit of business. If there is a library left in the - // images for our target that - // doesn't have a load address, then it must be something that we were - // expecting to load (for instance we - // read a load command for it) but it didn't in fact load - probably because - // DYLD_*_PATH pointed - // to an equivalent version. We don't want it to stay in the target's - // module list or it will confuse - // us, so unload it here. + // images for our target that doesn't have a load address, then it must be + // something that we were expecting to load (for instance we read a load + // command for it) but it didn't in fact load - probably because + // DYLD_*_PATH pointed to an equivalent version. We don't want it to stay + // in the target's module list or it will confuse us, so unload it here. Target &target = m_process->GetTarget(); const ModuleList &target_modules = target.GetImages(); ModuleList not_loaded_modules; @@ -784,8 +770,8 @@ bool DynamicLoaderMacOSXDYLD::InitializeFromAllImageInfos() { } //---------------------------------------------------------------------- -// Read a mach_header at ADDR into HEADER, and also fill in the load -// command data into LOAD_COMMAND_DATA if it is non-NULL. +// Read a mach_header at ADDR into HEADER, and also fill in the load command +// data into LOAD_COMMAND_DATA if it is non-NULL. // // Returns true if we succeed, false if we fail for any reason. //---------------------------------------------------------------------- @@ -840,8 +826,8 @@ bool DynamicLoaderMacOSXDYLD::ReadMachHeader(lldb::addr_t addr, load_cmd_data_sp->GetByteSize(), error); if (load_cmd_bytes_read == header->sizeofcmds) { - // Set the load command data and also set the correct endian - // swap settings and the correct address size + // Set the load command data and also set the correct endian swap + // settings and the correct address size load_command_data->SetData(load_cmd_data_sp, 0, header->sizeofcmds); load_command_data->SetByteOrder(data.GetByteOrder()); load_command_data->SetAddressByteSize(data.GetAddressByteSize()); @@ -867,8 +853,8 @@ uint32_t DynamicLoaderMacOSXDYLD::ParseLoadCommands(const DataExtractor &data, dylib_info.Clear(true); for (cmd_idx = 0; cmd_idx < dylib_info.header.ncmds; cmd_idx++) { - // Clear out any load command specific data from DYLIB_INFO since - // we are about to read it. + // Clear out any load command specific data from DYLIB_INFO since we are + // about to read it. if (data.ValidOffsetForDataOfSize(offset, sizeof(llvm::MachO::load_command))) { @@ -880,8 +866,8 @@ uint32_t DynamicLoaderMacOSXDYLD::ParseLoadCommands(const DataExtractor &data, case llvm::MachO::LC_SEGMENT: { segment.name.SetTrimmedCStringWithLength( (const char *)data.GetData(&offset, 16), 16); - // We are putting 4 uint32_t values 4 uint64_t values so - // we have to use multiple 32 bit gets below. + // We are putting 4 uint32_t values 4 uint64_t values so we have to use + // multiple 32 bit gets below. segment.vmaddr = data.GetU32(&offset); segment.vmsize = data.GetU32(&offset); segment.fileoff = data.GetU32(&offset); @@ -922,24 +908,21 @@ uint32_t DynamicLoaderMacOSXDYLD::ParseLoadCommands(const DataExtractor &data, } } - // All sections listed in the dyld image info structure will all - // either be fixed up already, or they will all be off by a single - // slide amount that is determined by finding the first segment - // that is at file offset zero which also has bytes (a file size - // that is greater than zero) in the object file. + // All sections listed in the dyld image info structure will all either be + // fixed up already, or they will all be off by a single slide amount that is + // determined by finding the first segment that is at file offset zero which + // also has bytes (a file size that is greater than zero) in the object file. // Determine the slide amount (if any) const size_t num_sections = dylib_info.segments.size(); for (size_t i = 0; i < num_sections; ++i) { - // Iterate through the object file sections to find the - // first section that starts of file offset zero and that - // has bytes in the file... + // Iterate through the object file sections to find the first section that + // starts of file offset zero and that has bytes in the file... if ((dylib_info.segments[i].fileoff == 0 && dylib_info.segments[i].filesize > 0) || (dylib_info.segments[i].name == ConstString("__TEXT"))) { dylib_info.slide = dylib_info.address - dylib_info.segments[i].vmaddr; - // We have found the slide amount, so we can exit - // this for loop. + // We have found the slide amount, so we can exit this for loop. break; } } @@ -984,11 +967,11 @@ void DynamicLoaderMacOSXDYLD::UpdateImageInfosHeaderAndLoadCommands( // Don't load dependent images since we are in dyld where we will know // and find out about all images that are loaded. Also when setting the // executable module, it will clear the targets module list, and if we - // have an in memory dyld module, it will get removed from the list - // so we will need to add it back after setting the executable module, - // so we first try and see if we already have a weak pointer to the - // dyld module, make it into a shared pointer, then add the executable, - // then re-add it back to make sure it is always in the list. + // have an in memory dyld module, it will get removed from the list so + // we will need to add it back after setting the executable module, so + // we first try and see if we already have a weak pointer to the dyld + // module, make it into a shared pointer, then add the executable, then + // re-add it back to make sure it is always in the list. ModuleSP dyld_module_sp(GetDYLDModule()); const bool get_dependent_images = false; @@ -1009,8 +992,8 @@ void DynamicLoaderMacOSXDYLD::UpdateImageInfosHeaderAndLoadCommands( } //---------------------------------------------------------------------- -// Dump the _dyld_all_image_infos members and all current image infos -// that we have parsed to the file handle provided. +// Dump the _dyld_all_image_infos members and all current image infos that we +// have parsed to the file handle provided. //---------------------------------------------------------------------- void DynamicLoaderMacOSXDYLD::PutToLog(Log *log) const { if (log == NULL) @@ -1039,10 +1022,9 @@ bool DynamicLoaderMacOSXDYLD::SetNotificationBreakpoint() { if (m_break_id == LLDB_INVALID_BREAK_ID) { if (m_dyld_all_image_infos.notification != LLDB_INVALID_ADDRESS) { Address so_addr; - // Set the notification breakpoint and install a breakpoint - // callback function that will get called each time the - // breakpoint gets hit. We will use this to track when shared - // libraries get loaded/unloaded. + // Set the notification breakpoint and install a breakpoint callback + // function that will get called each time the breakpoint gets hit. We + // will use this to track when shared libraries get loaded/unloaded. bool resolved = m_process->GetTarget().ResolveLoadAddress( m_dyld_all_image_infos.notification, so_addr); if (!resolved) { @@ -1071,9 +1053,9 @@ bool DynamicLoaderMacOSXDYLD::SetNotificationBreakpoint() { Status DynamicLoaderMacOSXDYLD::CanLoadImage() { Status error; - // In order for us to tell if we can load a shared library we verify that - // the dylib_info_addr isn't zero (which means no shared libraries have - // been set yet, or dyld is currently mucking with the shared library list). + // In order for us to tell if we can load a shared library we verify that the + // dylib_info_addr isn't zero (which means no shared libraries have been set + // yet, or dyld is currently mucking with the shared library list). if (ReadAllImageInfosStructure()) { // TODO: also check the _dyld_global_lock_held variable in // libSystem.B.dylib? @@ -1099,13 +1081,10 @@ bool DynamicLoaderMacOSXDYLD::GetSharedCacheInformation( addr_t all_image_infos = m_process->GetImageInfoAddress(); // The address returned by GetImageInfoAddress may be the address of dyld - // (don't want) - // or it may be the address of the dyld_all_image_infos structure (want). - // The first four - // bytes will be either the version field (all_image_infos) or a Mach-O file - // magic constant. - // Version 13 and higher of dyld_all_image_infos is required to get the - // sharedCacheUUID field. + // (don't want) or it may be the address of the dyld_all_image_infos + // structure (want). The first four bytes will be either the version field + // (all_image_infos) or a Mach-O file magic constant. Version 13 and higher + // of dyld_all_image_infos is required to get the sharedCacheUUID field. Status err; uint32_t version_or_magic = |

