Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfind.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS kernel 00004 * FILE: lib/rossym/find.c 00005 * PURPOSE: Find symbol info for an address 00006 * 00007 * PROGRAMMERS: Ge van Geldorp (gvg@reactos.com) 00008 */ 00009 /* 00010 * Parts of this file based on work Copyright (c) 1990, 1993 00011 * The Regents of the University of California. All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without 00014 * modification, are permitted provided that the following conditions 00015 * are met: 00016 * 1. Redistributions of source code must retain the above copyright 00017 * notice, this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright 00019 * notice, this list of conditions and the following disclaimer in the 00020 * documentation and/or other materials provided with the distribution. 00021 * 4. Neither the name of the University nor the names of its contributors 00022 * may be used to endorse or promote products derived from this software 00023 * without specific prior written permission. 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00026 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00028 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00029 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00030 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00031 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00032 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00033 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00034 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00035 * SUCH DAMAGE. 00036 */ 00037 00038 #include <ntddk.h> 00039 #include <reactos/rossym.h> 00040 #include "rossympriv.h" 00041 00042 #define NDEBUG 00043 #include <debug.h> 00044 00045 static PROSSYM_ENTRY 00046 FindEntry(IN PROSSYM_INFO RosSymInfo, IN ULONG_PTR RelativeAddress) 00047 { 00048 /* 00049 * Perform a binary search. 00050 * 00051 * The code below is a bit sneaky. After a comparison fails, we 00052 * divide the work in half by moving either left or right. If lim 00053 * is odd, moving left simply involves halving lim: e.g., when lim 00054 * is 5 we look at item 2, so we change lim to 2 so that we will 00055 * look at items 0 & 1. If lim is even, the same applies. If lim 00056 * is odd, moving right again involes halving lim, this time moving 00057 * the base up one item past p: e.g., when lim is 5 we change base 00058 * to item 3 and make lim 2 so that we will look at items 3 and 4. 00059 * If lim is even, however, we have to shrink it by one before 00060 * halving: e.g., when lim is 4, we still looked at item 2, so we 00061 * have to make lim 3, then halve, obtaining 1, so that we will only 00062 * look at item 3. 00063 */ 00064 PROSSYM_ENTRY Base = RosSymInfo->Symbols; 00065 ULONG Lim; 00066 PROSSYM_ENTRY Mid, Low; 00067 00068 if (RelativeAddress < Base->Address) 00069 { 00070 return NULL; 00071 } 00072 00073 Low = Base; 00074 for (Lim = RosSymInfo->SymbolsCount; Lim != 0; Lim >>= 1) 00075 { 00076 Mid = Base + (Lim >> 1); 00077 if (RelativeAddress == Mid->Address) 00078 { 00079 return Mid; 00080 } 00081 if (Mid->Address < RelativeAddress) /* key > mid: move right */ 00082 { 00083 Low = Mid; 00084 Base = Mid + 1; 00085 Lim--; 00086 } /* else move left */ 00087 } 00088 00089 return Low; 00090 } 00091 00092 00093 BOOLEAN 00094 RosSymGetAddressInformation(PROSSYM_INFO RosSymInfo, 00095 ULONG_PTR RelativeAddress, 00096 ULONG *LineNumber, 00097 char *FileName, 00098 char *FunctionName) 00099 { 00100 PROSSYM_ENTRY RosSymEntry; 00101 00102 DPRINT("RelativeAddress = 0x%08x\n", RelativeAddress); 00103 00104 if (RosSymInfo->Symbols == NULL || RosSymInfo->SymbolsCount == 0 || 00105 RosSymInfo->Strings == NULL || RosSymInfo->StringsLength == 0) 00106 { 00107 DPRINT1("Uninitialized RosSymInfo\n"); 00108 return FALSE; 00109 } 00110 00111 ASSERT(LineNumber || FileName || FunctionName); 00112 00113 /* find symbol entry for function */ 00114 RosSymEntry = FindEntry(RosSymInfo, RelativeAddress); 00115 00116 if (NULL == RosSymEntry) 00117 { 00118 DPRINT("None of the requested information was found!\n"); 00119 return FALSE; 00120 } 00121 00122 if (LineNumber != NULL) 00123 { 00124 *LineNumber = RosSymEntry->SourceLine; 00125 } 00126 if (FileName != NULL) 00127 { 00128 PCSTR Name = ""; 00129 if (RosSymEntry->FileOffset != 0) 00130 { 00131 Name = (PCHAR) RosSymInfo->Strings + RosSymEntry->FileOffset; 00132 } 00133 strcpy(FileName, Name); 00134 } 00135 if (FunctionName != NULL) 00136 { 00137 PCSTR Name = ""; 00138 if (RosSymEntry->FunctionOffset != 0) 00139 { 00140 Name = (PCHAR) RosSymInfo->Strings + RosSymEntry->FunctionOffset; 00141 } 00142 strcpy(FunctionName, Name); 00143 } 00144 00145 return TRUE; 00146 } 00147 00148 /* EOF */ Generated on Sun May 27 2012 04:16:31 for ReactOS by
1.7.6.1
|