Loading...
src/dyld_gdb.cpp dyld-640.2 dyld-210.2.3
--- dyld/dyld-640.2/src/dyld_gdb.cpp
+++ dyld/dyld-210.2.3/src/dyld_gdb.cpp
@@ -32,12 +32,7 @@
 
 #include "mach-o/dyld_gdb.h"
 #include "mach-o/dyld_images.h"
-#include "mach-o/dyld_process_info.h"
-#include "Tracing.h"
 #include "ImageLoader.h"
-#include "dyld.h"
-
-extern "C" 	void _dyld_debugger_notification(enum dyld_notify_mode mode, unsigned long count, uint64_t machHeaders[]);
 
 #if __IPHONE_OS_VERSION_MIN_REQUIRED
 	#define INITIAL_UUID_IMAGE_COUNT 4
@@ -45,33 +40,8 @@
 	#define INITIAL_UUID_IMAGE_COUNT 32
 #endif
 
-VECTOR_NEVER_DESTRUCTED(dyld_image_info);
-VECTOR_NEVER_DESTRUCTED(dyld_uuid_info);
-
 static std::vector<dyld_image_info> sImageInfos;
 static std::vector<dyld_uuid_info>  sImageUUIDs;
-
-size_t allImagesCount()
-{
-	return sImageInfos.size();
-}
-
-const mach_header* allImagesIndexedMachHeader(uint32_t index)
-{
-	if ( index < sImageInfos.size() )
-		return sImageInfos[index].imageLoadAddress;
-	else
-		return NULL;
-}
-
-const char* allImagesIndexedPath(uint32_t index)
-{
-	if ( index < sImageInfos.size() )
-		return sImageInfos[index].imageFilePath;
-	else
-		return NULL;
-}
-
 
 void addImagesToAllImages(uint32_t infoCount, const dyld_image_info info[])
 {
@@ -81,49 +51,26 @@
 	if ( sImageUUIDs.capacity() == 0 )
 		sImageUUIDs.reserve(4);
 	// set infoArray to NULL to denote it is in-use
-	dyld::gProcessInfo->infoArray = NULL;
+	dyld_all_image_infos.infoArray = NULL;
 	
 	// append all new images
 	for (uint32_t i=0; i < infoCount; ++i)
 		sImageInfos.push_back(info[i]);
-	dyld::gProcessInfo->infoArrayCount = (uint32_t)sImageInfos.size();
-	dyld::gProcessInfo->infoArrayChangeTimestamp = mach_absolute_time();
-
+	dyld_all_image_infos.infoArrayCount = sImageInfos.size();
+	
 	// set infoArray back to base address of vector (other process can now read)
-	dyld::gProcessInfo->infoArray = &sImageInfos[0];
+	dyld_all_image_infos.infoArray = &sImageInfos[0];
 }
 
-#if TARGET_IPHONE_SIMULATOR
-// called once in dyld_sim start up to copy image list from host dyld to sImageInfos
-void syncProcessInfo()
-{
-	// may want to set version field of gProcessInfo if it might be different than host
-	if ( sImageInfos.size() == 0 ) {
-		sImageInfos.reserve(INITIAL_IMAGE_COUNT);
-		if ( dyld::gProcessInfo->infoArray != NULL ) {
-			for (uint32_t i=0; i < dyld::gProcessInfo->infoArrayCount; ++i) {
-				sImageInfos.push_back(dyld::gProcessInfo->infoArray[i]);
-			}
-			dyld::gProcessInfo->infoArray = &sImageInfos[0];
-			dyld::gProcessInfo->infoArrayCount = (uint32_t)sImageInfos.size();
-		}
-	}
-	dyld::gProcessInfo->notification(dyld_image_info_change, 0, NULL);
-}
-#endif
 
 const char* notifyGDB(enum dyld_image_states state, uint32_t infoCount, const dyld_image_info info[])
 {
 	// tell gdb that about the new images
-	uint64_t t0 = mach_absolute_time();
-	dyld::gProcessInfo->notification(dyld_image_adding, infoCount, info);
-	uint64_t t1 = mach_absolute_time();
-	ImageLoader::fgTotalDebuggerPausedTime += (t1-t0);
-
+	dyld_all_image_infos.notification(dyld_image_adding, infoCount, info);
 	// <rdar://problem/7739489> record initial count of images  
 	// so CrashReporter can note which images were dynamically loaded
-	if ( dyld::gProcessInfo->initialImageCount == 0 )
-		dyld::gProcessInfo->initialImageCount = dyld::gProcessInfo->infoArrayCount;
+	if ( dyld_all_image_infos.initialImageCount == 0 )
+		dyld_all_image_infos.initialImageCount = infoCount;
 	return NULL;
 }
 
@@ -132,14 +79,14 @@
 void addNonSharedCacheImageUUID(const dyld_uuid_info& info)
 {
 	// set uuidArray to NULL to denote it is in-use
-	dyld::gProcessInfo->uuidArray = NULL;
+	dyld_all_image_infos.uuidArray = NULL;
 	
 	// append all new images
 	sImageUUIDs.push_back(info);
-	dyld::gProcessInfo->uuidArrayCount = sImageUUIDs.size();
+	dyld_all_image_infos.uuidArrayCount = sImageUUIDs.size();
 	
 	// set uuidArray back to base address of vector (other process can now read)
-	dyld::gProcessInfo->uuidArray = &sImageUUIDs[0];
+	dyld_all_image_infos.uuidArray = &sImageUUIDs[0];
 }
 
 void removeImageFromAllImages(const struct mach_header* loadAddress)
@@ -147,7 +94,7 @@
 	dyld_image_info goingAway;
 	
 	// set infoArray to NULL to denote it is in-use
-	dyld::gProcessInfo->infoArray = NULL;
+	dyld_all_image_infos.infoArray = NULL;
 	
 	// remove image from infoArray
 	for (std::vector<dyld_image_info>::iterator it=sImageInfos.begin(); it != sImageInfos.end(); it++) {
@@ -157,14 +104,14 @@
 			break;
 		}
 	}
-	dyld::gProcessInfo->infoArrayCount = (uint32_t)sImageInfos.size();
+	dyld_all_image_infos.infoArrayCount = sImageInfos.size();
 	
 	// set infoArray back to base address of vector
-	dyld::gProcessInfo->infoArray = &sImageInfos[0];
+	dyld_all_image_infos.infoArray = &sImageInfos[0];
 
 
 	// set uuidArrayCount to NULL to denote it is in-use
-	dyld::gProcessInfo->uuidArray = NULL;
+	dyld_all_image_infos.uuidArray = NULL;
 	
 	// remove image from infoArray
 	for (std::vector<dyld_uuid_info>::iterator it=sImageUUIDs.begin(); it != sImageUUIDs.end(); it++) {
@@ -173,73 +120,50 @@
 			break;
 		}
 	}
-	dyld::gProcessInfo->uuidArrayCount = sImageUUIDs.size();
-	dyld::gProcessInfo->infoArrayChangeTimestamp = mach_absolute_time();
-
+	dyld_all_image_infos.uuidArrayCount = sImageUUIDs.size();
+	
 	// set infoArray back to base address of vector
-	dyld::gProcessInfo->uuidArray = &sImageUUIDs[0];
+	dyld_all_image_infos.uuidArray = &sImageUUIDs[0];
 
 	// tell gdb that about the new images
-	dyld::gProcessInfo->notification(dyld_image_removing, 1, &goingAway);
+	dyld_all_image_infos.notification(dyld_image_removing, 1, &goingAway);
+}
+
+#if __arm__
+// work around for:  <rdar://problem/6530727> gdb-1109: notifier in dyld does not work if it is in thumb
+extern "C" void gdb_image_notifier(enum dyld_image_mode mode, uint32_t infoCount, const dyld_image_info info[]);
+#else
+static void gdb_image_notifier(enum dyld_image_mode mode, uint32_t infoCount, const dyld_image_info info[])
+{
+	// do nothing
+	// gdb sets a break point here to catch notifications
+	//dyld::log("dyld: gdb_image_notifier(%s, %d, ...)\n", mode ? "dyld_image_removing" : "dyld_image_adding", infoCount);
+	//for (uint32_t i=0; i < infoCount; ++i)
+	//	dyld::log("dyld: %d loading at %p %s\n", i, info[i].imageLoadAddress, info[i].imageFilePath);
+	//for (uint32_t i=0; i < dyld_all_image_infos.infoArrayCount; ++i)
+	//	dyld::log("dyld: %d loading at %p %s\n", i, dyld_all_image_infos.infoArray[i].imageLoadAddress, dyld_all_image_infos.infoArray[i].imageFilePath);
+}
+#endif
+
+void setAlImageInfosHalt(const char* message, uintptr_t flags)
+{
+	dyld_all_image_infos.errorMessage = message;
+	dyld_all_image_infos.terminationFlags = flags;
 }
 
 
-#if TARGET_IPHONE_SIMULATOR
-	namespace dyld {
-		struct dyld_all_image_infos* gProcessInfo = NULL;
-	}
-#else
+extern void* __dso_handle;
+#define STR(s) # s
+#define XSTR(s) STR(s)
 
-	static void gdb_image_notifier(enum dyld_image_mode mode, uint32_t infoCount, const dyld_image_info info[])
-	{
-		dyld3::ScopedTimer(DBG_DYLD_GDB_IMAGE_NOTIFIER, 0, 0, 0);
-		uint64_t machHeaders[infoCount];
-		for (uint32_t i=0; i < infoCount; ++i) {
-			machHeaders[i] = (uintptr_t)(info[i].imageLoadAddress);
-		}
-		switch ( mode ) {
-			 case dyld_image_adding:
-				_dyld_debugger_notification(dyld_notify_adding, infoCount, machHeaders);
-				break;
-			 case dyld_image_removing:
-				_dyld_debugger_notification(dyld_notify_removing, infoCount, machHeaders);
-				break;
-			default:
-				break;
-		}
-		// do nothing
-		// gdb sets a break point here to catch notifications
-		//dyld::log("dyld: gdb_image_notifier(%s, %d, ...)\n", mode ? "dyld_image_removing" : "dyld_image_adding", infoCount);
-		//for (uint32_t i=0; i < infoCount; ++i)
-		//	dyld::log("dyld: %d loading at %p %s\n", i, info[i].imageLoadAddress, info[i].imageFilePath);
-		//for (uint32_t i=0; i < dyld::gProcessInfo->infoArrayCount; ++i)
-		//	dyld::log("dyld: %d loading at %p %s\n", i, dyld::gProcessInfo->infoArray[i].imageLoadAddress, dyld::gProcessInfo->infoArray[i].imageFilePath);
-	}
+struct dyld_all_image_infos  dyld_all_image_infos __attribute__ ((section ("__DATA,__all_image_info"))) 
+							= { 
+								12, 0, NULL, &gdb_image_notifier, false, false, (const mach_header*)&__dso_handle, NULL, 
+								XSTR(DYLD_VERSION), NULL, 0, NULL, 0, 0, NULL, &dyld_all_image_infos, 
+								0, dyld_error_kind_none, NULL, NULL, NULL, 0
+								};
 
-	// only used with accelerator tables and ASan which images need to be re-loaded
-	void resetAllImages()
-	{
-		sImageInfos.clear();
-		sImageUUIDs.clear();
-		_dyld_debugger_notification(dyld_notify_remove_all, 0, NULL);
-	}
+struct dyld_shared_cache_ranges dyld_shared_cache_ranges;
 
-	extern void* __dso_handle;
-	#define STR(s) # s
-	#define XSTR(s) STR(s)
 
-	struct dyld_all_image_infos  dyld_all_image_infos __attribute__ ((section ("__DATA,__all_image_info"))) 
-								= { 
-									15, 0, {NULL}, &gdb_image_notifier, false, false, (const mach_header*)&__dso_handle, NULL,
-									XSTR(DYLD_VERSION), NULL, 0, NULL, 0, 0, NULL, &dyld_all_image_infos,
-									0, 0, NULL, NULL, NULL, 0, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
-									0, {0}, "/usr/lib/dyld", {0}, {0}
-									};
-
-	struct dyld_shared_cache_ranges dyld_shared_cache_ranges;
-
-	namespace dyld {
-		struct dyld_all_image_infos* gProcessInfo = &dyld_all_image_infos;
-	}
-#endif