ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

find.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 <precomp.h>
00039 
00040 #define NDEBUG
00041 #include <debug.h>
00042 
00043 BOOLEAN
00044 RosSymGetAddressInformation
00045 (PROSSYM_INFO RosSymInfo,
00046  ULONG_PTR RelativeAddress,
00047  PROSSYM_LINEINFO RosSymLineInfo)
00048 {
00049     ROSSYM_REGISTERS registers;
00050     DwarfParam params[sizeof(RosSymLineInfo->Parameters)/sizeof(RosSymLineInfo->Parameters[0])];
00051     DwarfSym proc = { };
00052     int i;
00053     int res = dwarfpctoline
00054         (RosSymInfo, 
00055          &proc,
00056          RelativeAddress + RosSymInfo->pe->imagebase, 
00057          &RosSymLineInfo->FileName,
00058          &RosSymLineInfo->FunctionName,
00059          &RosSymLineInfo->LineNumber);
00060     if (res == -1) {
00061         werrstr("Could not get basic function info");
00062         return FALSE;
00063     }
00064 
00065     if (!(RosSymLineInfo->Flags & ROSSYM_LINEINFO_HAS_REGISTERS))
00066         return TRUE;
00067 
00068     registers = RosSymLineInfo->Registers;
00069 
00070     DwarfExpr cfa = { };
00071     ulong cfaLocation;
00072     if (dwarfregunwind
00073         (RosSymInfo, 
00074          RelativeAddress + RosSymInfo->pe->imagebase, 
00075          proc.attrs.framebase.c, 
00076          &cfa,
00077          &registers) == -1) {
00078         werrstr("Can't get cfa location for %s", RosSymLineInfo->FunctionName);
00079         return TRUE;
00080     }
00081 
00082     res = dwarfgetparams
00083         (RosSymInfo,
00084          &proc,
00085          RelativeAddress + RosSymInfo->pe->imagebase,
00086          sizeof(params)/sizeof(params[0]),
00087          params);
00088 
00089     if (res == -1) {
00090         werrstr("%s: could not get params at all", RosSymLineInfo->FunctionName);
00091         RosSymLineInfo->NumParams = 0;
00092         return TRUE;
00093     }
00094 
00095     werrstr("%s: res %d", RosSymLineInfo->FunctionName, res);
00096     RosSymLineInfo->NumParams = res;
00097 
00098     res = dwarfcomputecfa(RosSymInfo, &cfa, &registers, &cfaLocation);
00099     if (res == -1) {
00100         werrstr("%s: could not get our own cfa", RosSymLineInfo->FunctionName);
00101         return TRUE;
00102     }
00103 
00104     for (i = 0; i < RosSymLineInfo->NumParams; i++) {
00105         werrstr("Getting arg %s, unit %x, type %x", 
00106                 params[i].name, params[i].unit, params[i].type);
00107         res = dwarfargvalue
00108             (RosSymInfo, 
00109              &proc, 
00110              RelativeAddress + RosSymInfo->pe->imagebase,
00111              cfaLocation,
00112              &registers,
00113              &params[i]);
00114         if (res == -1) { RosSymLineInfo->NumParams = i; return TRUE; }
00115         werrstr("%s: %x", params[i].name, params[i].value);
00116         RosSymLineInfo->Parameters[i].ValueName = malloc(strlen(params[i].name)+1);
00117         strcpy(RosSymLineInfo->Parameters[i].ValueName, params[i].name);
00118         free(params[i].name);
00119         RosSymLineInfo->Parameters[i].Value = params[i].value;
00120     }
00121 
00122     return TRUE;
00123 }
00124 
00125 VOID
00126 RosSymFreeAggregate(PROSSYM_AGGREGATE Aggregate)
00127 {
00128     int i;
00129     for (i = 0; i < Aggregate->NumElements; i++) {
00130         free(Aggregate->Elements[i].Name);
00131         free(Aggregate->Elements[i].Type);
00132     }
00133     free(Aggregate->Elements);
00134 }
00135 
00136 BOOLEAN
00137 RosSymAggregate(PROSSYM_INFO RosSymInfo, PCHAR Type, PROSSYM_AGGREGATE Aggregate)
00138 {
00139     char *tchar;
00140     ulong unit, typeoff = 0;
00141     DwarfSym type = { };
00142     // Get the first unit
00143     if (dwarfaddrtounit(RosSymInfo, RosSymInfo->pe->codestart + RosSymInfo->pe->imagebase, &unit) == -1)
00144         return FALSE;
00145 
00146     if (Type[0] == '#') {
00147         for (tchar = Type + 1; *tchar; tchar++) {
00148             typeoff *= 10;
00149             typeoff += *tchar - '0';
00150         }
00151         if (dwarfseeksym(RosSymInfo, unit, typeoff, &type) == -1)
00152             return FALSE;
00153     } else if (dwarflookupnameinunit(RosSymInfo, unit, Type, &type) != 0 ||
00154         (type.attrs.tag != TagStructType && type.attrs.tag != TagUnionType))
00155         return FALSE;
00156     
00157     DwarfSym element = { }, inner = { };
00158     int count = 0;
00159     
00160     werrstr("type %s (want %s) type %x\n", type.attrs.name, Type, type.attrs.type);
00161     
00162     if (type.attrs.have.type) {
00163         if (dwarfseeksym(RosSymInfo, unit, type.attrs.type, &inner) == -1)
00164             return FALSE;
00165         type = inner;
00166     }
00167     
00168     werrstr("finding members %d\n", type.attrs.haskids);
00169     while (dwarfnextsymat(RosSymInfo, &type, &element) != -1) {
00170         if (element.attrs.have.name)
00171             werrstr("%x %s\n", element.attrs.tag, element.attrs.name);
00172         if (element.attrs.tag == TagMember) count++;
00173     }
00174     
00175     werrstr("%d members\n", count);
00176     
00177     if (!count) return FALSE;
00178     memset(&element, 0, sizeof(element));
00179     Aggregate->NumElements = count;
00180     Aggregate->Elements = malloc(sizeof(ROSSYM_AGGREGATE_MEMBER) * count);
00181     count = 0;
00182     werrstr("Enumerating %s\n", Type);
00183     while (dwarfnextsymat(RosSymInfo, &type, &element) != -1) {
00184         memset(&Aggregate->Elements[count], 0, sizeof(*Aggregate->Elements));
00185         if (element.attrs.tag == TagMember) {
00186             if (element.attrs.have.name) {
00187                 Aggregate->Elements[count].Name = malloc(strlen(element.attrs.name) + 1);
00188                 strcpy(Aggregate->Elements[count].Name, element.attrs.name);
00189             }
00190             Aggregate->Elements[count].TypeId = element.attrs.type;
00191             // Seek our range in loc
00192             DwarfBuf locbuf;
00193             DwarfBuf instream = { };
00194             
00195             locbuf.d = RosSymInfo;
00196             locbuf.addrsize = RosSymInfo->addrsize;
00197 
00198             if (element.attrs.have.datamemberloc) {
00199                 instream = locbuf;
00200                 instream.p = element.attrs.datamemberloc.b.data;
00201                 instream.ep = element.attrs.datamemberloc.b.data + element.attrs.datamemberloc.b.len;
00202                 werrstr("datamemberloc type %x %p:%x\n", 
00203                         element.attrs.have.datamemberloc,
00204                         element.attrs.datamemberloc.b.data, element.attrs.datamemberloc.b.len);
00205             }
00206 
00207             if (dwarfgetarg(RosSymInfo, element.attrs.name, &instream, 0, NULL, &Aggregate->Elements[count].BaseOffset) == -1)
00208                 Aggregate->Elements[count].BaseOffset = -1;
00209             werrstr("tag %x name %s base %x type %x\n", 
00210                     element.attrs.tag, element.attrs.name, 
00211                     Aggregate->Elements[count].BaseOffset,
00212                     Aggregate->Elements[count].TypeId);
00213             count++;
00214         }
00215     }
00216     for (count = 0; count < Aggregate->NumElements; count++) {
00217         memset(&type, 0, sizeof(type));
00218         memset(&inner, 0, sizeof(inner));
00219         werrstr("seeking type %x (%s) from %s\n", 
00220                 Aggregate->Elements[count].TypeId,
00221                 Aggregate->Elements[count].Type,
00222                 Aggregate->Elements[count].Name);
00223         dwarfseeksym(RosSymInfo, unit, Aggregate->Elements[count].TypeId, &type);
00224         while (type.attrs.have.type && type.attrs.tag != TagPointerType) {
00225             if (dwarfseeksym(RosSymInfo, unit, type.attrs.type, &inner) == -1)
00226                 return FALSE;
00227             type = inner;
00228         }
00229         //dwarfdumpsym(RosSymInfo, &type);
00230         if (type.attrs.have.name) {
00231             Aggregate->Elements[count].Type = malloc(strlen(type.attrs.name) + 1);
00232             strcpy(Aggregate->Elements[count].Type, type.attrs.name);
00233         } else {
00234             char strbuf[128] = {'#'}, *bufptr = strbuf + 1;
00235             ulong idcopy = Aggregate->Elements[count].TypeId;
00236             ulong mult = 1;
00237             while (mult * 10 < idcopy) mult *= 10;
00238             while (mult > 0) {
00239                 *bufptr++ = '0' + ((idcopy / mult) % 10);
00240                 mult /= 10;
00241             }
00242             Aggregate->Elements[count].Type = malloc(strlen(strbuf) + 1);
00243             strcpy(Aggregate->Elements[count].Type, strbuf);
00244         }
00245         if (type.attrs.tag == TagPointerType)
00246             Aggregate->Elements[count].Size = RosSymInfo->addrsize;
00247         else
00248             Aggregate->Elements[count].Size = type.attrs.bytesize;
00249         if (type.attrs.have.bitsize)
00250             Aggregate->Elements[count].Bits = type.attrs.bitsize;
00251         if (type.attrs.have.bitoffset)
00252             Aggregate->Elements[count].FirstBit = type.attrs.bitoffset;
00253     }
00254     return TRUE;
00255 }
00256 
00257 /* EOF */

Generated on Mon May 28 2012 04:16:34 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.