Bug 586358: make imacpc flagged. (r=lw)
[mozilla-central.git] / tools / leaky / ShowLibs.cpp
blob88fe49a60ca94be4e375cedba46e3de9d4516779
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is mozilla.org code.
16 * The Initial Developer of the Original Code is Kipp E.B. Hickman.
17 * Portions created by the Initial Developer are Copyright (C) 1999
18 * the Initial Developer. All Rights Reserved.
20 * Contributor(s):
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 2 or later (the "GPL"), or
24 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25 * in which case the provisions of the GPL or the LGPL are applicable instead
26 * of those above. If you wish to allow use of your version of this file only
27 * under the terms of either the GPL or the LGPL, and not to allow others to
28 * use your version of this file under the terms of the MPL, indicate your
29 * decision by deleting the provisions above and replace them with the notice
30 * and other provisions required by the GPL or the LGPL. If you do not delete
31 * the provisions above, a recipient may use your version of this file under
32 * the terms of any one of the MPL, the GPL or the LGPL.
34 * ***** END LICENSE BLOCK ***** */
36 #include <stdio.h>
37 #include <dlfcn.h>
39 #ifdef linux
40 #include <link.h>
41 #endif
43 // A simple test program that dumps out the loaded shared
44 // libraries. This is essential for leaky to work properly when shared
45 // libraries are used.
46 static void ShowLibs(struct r_debug* rd)
48 link_map* map = rd->r_map;
49 while (NULL != map) {
50 printf("addr=%08x name=%s prev=%p next=%p\n", map->l_addr, map->l_name,
51 map->l_prev, map->l_next);
52 map = map->l_next;
56 int main(int argc, char** argv)
58 void* h = dlopen("/usr/X11R6/lib/libX11.so", RTLD_LAZY);
59 #ifdef linux
60 printf("Direct r_debug libs:\n");
61 ShowLibs(&_r_debug);
63 printf("_DYNAMICE r_debug libs:\n");
64 ElfW(Dyn)* dp;
65 for (dp = _DYNAMIC; dp->d_tag != DT_NULL; dp++) {
66 if (dp->d_tag == DT_DEBUG) {
67 struct r_debug* rd = (struct r_debug*) dp->d_un.d_ptr;
68 ShowLibs(rd);
71 #endif
72 return 0;