OpenMPI  0.1.1
MoreAddrToSym.h
1 /*
2  File: MoreAddrToSym.h
3 
4  Contains: Code for mapping addresses to their symbolic names.
5 
6  Written by: DTS
7 
8  Copyright: Copyright (c) 2006 by Apple Computer, Inc., All Rights Reserved.
9 
10  Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
11  ("Apple") in consideration of your agreement to the following terms, and your
12  use, installation, modification or redistribution of this Apple software
13  constitutes acceptance of these terms. If you do not agree with these terms,
14  please do not use, install, modify or redistribute this Apple software.
15 
16  In consideration of your agreement to abide by the following terms, and subject
17  to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs
18  copyrights in this original Apple software (the "Apple Software"), to use,
19  reproduce, modify and redistribute the Apple Software, with or without
20  modifications, in source and/or binary forms; provided that if you redistribute
21  the Apple Software in its entirety and without modifications, you must retain
22  this notice and the following text and disclaimers in all such redistributions of
23  the Apple Software. Neither the name, trademarks, service marks or logos of
24  Apple Computer, Inc. may be used to endorse or promote products derived from the
25  Apple Software without specific prior written permission from Apple. Except as
26  expressly stated in this notice, no other rights or licenses, express or implied,
27  are granted by Apple herein, including but not limited to any patent rights that
28  may be infringed by your derivative works or by other works in which the Apple
29  Software may be incorporated.
30 
31  The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
32  WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
33  WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34  PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
35  COMBINATION WITH YOUR PRODUCTS.
36 
37  IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
38  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
39  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40  ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
41  OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
42  (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
43  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 
45  Change History (most recent first):
46 
47 $Log: MoreAddrToSym.h,v $
48 Revision 1.2 2006/01/22 22:47:15 eskimo1
49 Significant rewrite to account for changes in MoreBacktrace. Still not as functional as I'd like.
50 
51 Revision 1.1 2003/04/04 15:03:00 eskimo1
52 First checked in. This code still has bugs, but I've written enough code that checking in is a good idea.
53 
54 
55 */
56 
57 #pragma once
58 
59 /////////////////////////////////////////////////////////////////
60 
61 // MoreIsBetter Setup
62 
63 #include "MoreSetup.h"
64 
65 // Mac OS Interfaces
66 
67 #include <stdint.h>
68 #include <stdlib.h>
69 
70 /////////////////////////////////////////////////////////////////
71 
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75 
76 // IMPORTANT:
77 // This code is currently broken in two ways:
78 //
79 // o If the binary has debugging symbols, you often get a debugging
80 // symbol rather than a real symbol. I believe this is caused by
81 // handling of N_FUN in the GetFunctionName routine. Furthermore,
82 // I believe that it did work previous but something changed in the
83 // Mach-O headers to break it. This warrants serious investigation.
84 //
85 // You can work around this problem by removing the debug symbols
86 // using:
87 //
88 // $ strip -S YourBinaryName
89 //
90 // o It doesn't handle 64-bit Mach-O binaries. This is a simple
91 // limitation of the code, and it should be relatively easy to fix.
92 //
93 // I intend to fix both of these problems with a future rewrite.
94 // Until then, I've decided to live with them.
95 
96 typedef uint64_t MoreAToSAddr;
97 typedef uint64_t MoreAToSOffset;
98 
99 enum MoreAToSSymbolType {
100  kMoreAToSNoSymbol = 0,
101  kMoreAToSDyldPubliSymbol,
102  kMoreAToSDyldPrivateSymbol
103 };
104 typedef enum MoreAToSSymbolType MoreAToSSymbolType;
105 
107  MoreAToSSymbolType symbolType;
108  const char * symbolName;
109  MoreAToSOffset symbolOffset;
110 };
111 typedef struct MoreAToSSymInfo MoreAToSSymInfo;
112 
113 extern int MoreAToSCreate(size_t count, MoreAToSSymInfo *symbols[]);
114  // Creates a blank MoreAToSSymInfo array with count entries.
115  // You must dispose of it using MoreAToSDestroy.
116  //
117  // symbols must not be NULL
118  // *symbols must be NULL
119  // Returns 0 on success, an errno-style error code otherwise
120  // On success, *symbols will not be NULL
121  // On error, *symbols will be NULL
122 
123 extern void MoreAToSDestroy(size_t count, MoreAToSSymInfo symbols[]);
124  // Destroys a MoreAToSDestroy array (blank or filled in) of
125  // count entries.
126 
127 extern int MoreAToSCopySymbolNamesUsingDyld(
128  size_t count,
129  MoreAToSAddr addresses[],
130  MoreAToSSymInfo symbols[]
131 );
132  // Given count values in the addresses array, works out the symbolic
133  // information for those values and returns it in the symbols array.
134  //
135  // Returns 0 on success, an errno-style error code otherwise
136  //
137  // Note that not being able to map an address to a symbol is not
138  // considered an error. Rather, you get NULL back in the symbolName
139  // field of the corresponding symbols array element.
140 
141 #ifdef __cplusplus
142 }
143 #endif
Definition: MoreAddrToSym.h:106