1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2004-2009 Apple Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
22 * @APPLE_LICENSE_HEADER_END@
29 #include <mach-o/loader.h>
33 #include "mach-o/dyld_gdb.h"
34 #include "mach-o/dyld_images.h"
35 #include "ImageLoader.h"
38 static std::vector
<dyld_image_info
> sImageInfos
;
40 void addImagesToAllImages(uint32_t infoCount
, const dyld_image_info info
[])
42 // make initial size large enought that we probably won't need to re-alloc it
43 if ( sImageInfos
.size() == 0 )
44 sImageInfos
.reserve(INITIAL_IMAGE_COUNT
);
46 // set infoArray to NULL to denote it is in-use
47 dyld_all_image_infos
.infoArray
= NULL
;
49 // append all new images
50 for (uint32_t i
=0; i
< infoCount
; ++i
)
51 sImageInfos
.push_back(info
[i
]);
52 dyld_all_image_infos
.infoArrayCount
= sImageInfos
.size();
54 // set infoArray back to base address of vector
55 dyld_all_image_infos
.infoArray
= &sImageInfos
[0];
57 // tell gdb that about the new images
58 dyld_all_image_infos
.notification(dyld_image_adding
, infoCount
, info
);
61 void removeImageFromAllImages(const struct mach_header
* loadAddress
)
63 dyld_image_info goingAway
;
65 // set infoArray to NULL to denote it is in-use
66 dyld_all_image_infos
.infoArray
= NULL
;
68 // remove image from infoArray
69 for (std::vector
<dyld_image_info
>::iterator it
=sImageInfos
.begin(); it
!= sImageInfos
.end(); it
++) {
70 if ( it
->imageLoadAddress
== loadAddress
) {
72 sImageInfos
.erase(it
);
76 dyld_all_image_infos
.infoArrayCount
= sImageInfos
.size();
78 // set infoArray back to base address of vector
79 dyld_all_image_infos
.infoArray
= &sImageInfos
[0];
81 // tell gdb that about the new images
82 dyld_all_image_infos
.notification(dyld_image_removing
, 1, &goingAway
);
86 static void gdb_image_notifier(enum dyld_image_mode mode
, uint32_t infoCount
, const dyld_image_info info
[])
89 // gdb sets a break point here to catch notifications
90 //dyld::log("dyld: gdb_image_notifier(%s, %d, ...)\n", mode ? "dyld_image_removing" : "dyld_image_adding", infoCount);
91 //for (uint32_t i=0; i < infoCount; ++i)
92 // dyld::log("dyld: %d loading at %p %s\n", i, info[i].imageLoadAddress, info[i].imageFilePath);
93 //for (uint32_t i=0; i < dyld_all_image_infos.infoArrayCount; ++i)
94 // dyld::log("dyld: %d loading at %p %s\n", i, dyld_all_image_infos.infoArray[i].imageLoadAddress, dyld_all_image_infos.infoArray[i].imageFilePath);
97 void setAlImageInfosHalt(const char* message
, uintptr_t flags
)
99 dyld_all_image_infos
.errorMessage
= message
;
100 dyld_all_image_infos
.terminationFlags
= flags
;
104 extern void* __dso_handle
;
106 #define XSTR(s) STR(s)
108 struct dyld_all_image_infos dyld_all_image_infos
__attribute__ ((section ("__DATA,__all_image_info")))
109 = { 7, 0, NULL
, &gdb_image_notifier
, false, false, (const mach_header
*)&__dso_handle
, NULL
,
110 XSTR(DYLD_VERSION
) , NULL
, 0, 0 };
112 struct dyld_shared_cache_ranges dyld_shared_cache_ranges
;