Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

kDbgSpace.cpp

Go to the documentation of this file.
/* $Id: kDbgSpace.cpp 2 2007-11-16 16:07:14Z bird $ */
/** @file
 * kDbg - The Debug Info Reader, Address Space Manager.
 */

/*
 * Copyright (c) 2006-2007 knut st. osmundsen <bird-kStuff-spam@anduin.net>
 *
 * This file is part of kStuff.
 *
 * kStuff is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * In addition to the permissions in the GNU Lesser General Public
 * License, you are granted unlimited permission to link the compiled
 * version of this file into combinations with other programs, and to
 * distribute those combinations without any restriction coming from
 * the use of this file.
 *
 * kStuff is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with kStuff; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA
 */

/*******************************************************************************
*   Header Files                                                               *
*******************************************************************************/
#include "kDbgInternal.h"
#include <k/kHlpAlloc.h>
#include <k/kHlpString.h>
#include <k/kAvl.h>


/*******************************************************************************
*   Structures and Typedefs                                                    *
*******************************************************************************/
/** Pointer to a name space module. */
00046 typedef struct KDBGSPACEMOD *PKDBGSPACEMOD;

/**
 * Tracks a module segment in the address space.
 *
 * These segments are organized in two trees, by address in the
 * KDBGSPACE::pSegRoot tree and by selector value in the
 * KDBGSPACE::pSegSelRoot tree.
 *
 * While the debug module reader could easily provide us with
 * segment names and it could perhaps be interesting to lookup
 * a segment by its name in some situations, this has been
 * considered too much bother for now. :-)
 */
00060 typedef struct KDBGSPACESEG
{
    /** The module segment index. */
00063     KI32                    iSegment;
    /** The address space module structure this segment belongs to. */
00065     PKDBGSPACEMOD           pSpaceMod;
} KDBGSPACESEG;
typedef KDBGSPACESEG *PKDBGSPACESEG;


/**
 * Track a module in the name space.
 *
 * Each module in the address space can be addressed efficiently
 * by module name. The module name has to be unique.
 */
00076 typedef struct KDBGSPACEMOD
{
    /** The module name hash. */
00079     KU32                    u32Hash;
    /** The length of the module name. */
00081     KU32                    cchName;
    /** The module name. */
00083     char                   *pszName;
    /** The next module in the same bucket. */
00085     PKDBGSPACEMOD           pNext;
    /** Pointer to the debug module reader. */
00087     PKDBGMOD                pMod;
    /** The number of segments. */
00089     KU32                    cSegs;
    /** The segment array. (variable length) */
00091     KDBGSPACESEG            aSegs[1];
} KDBGSPACEMOD;


typedef struct KDBGCACHEDSYM *PKDBGCACHEDSYM;
/**
 * A cached symbol.
 */
00099 typedef struct KDBGCACHEDSYM
{
    /** The symbol name hash. */
00102     KU32                    u32Hash;
    /** The next symbol in the same bucket. */
00104     PKDBGCACHEDSYM          pNext;
    /** The next symbol belonging to the same module as this. */
00106     PKDBGCACHEDSYM          pNextMod;
    /** The cached symbol information. */
00108     KDBGSYMBOL              Sym;
} KDBGCACHEDSYM;


/**
 * A symbol cache.
 */
00115 typedef struct KDBGSYMCACHE
{
    /** The symbol cache magic. (KDBGSYMCACHE_MAGIC) */
00118     KU32                    u32Magic;
    /** The maximum number of symbols.*/
00120     KU32                    cMax;
    /** The current number of symbols.*/
00122     KU32                    cCur;
    /** The number of hash buckets. */
00124     KU32                    cBuckets;
    /** The address lookup tree. */
00126     PKDBGADDRAVL            pAddrTree;
    /** Array of hash buckets.
     * The size is selected according to the cache size. */
00129     PKDBGCACHEDSYM         *paBuckets[1];
} KDBGSYMCACHE;
typedef KDBGSYMCACHE *PKDBGSYMCACHE;


/**
 * A user symbol record.
 *
 * The user symbols are organized in the KDBGSPACE::pUserRoot tree
 * and form an overlay that overrides the debug info retrieved from
 * the KDBGSPACE::pSegRoot tree.
 *
 * In the current implementation the user symbols are unique and
 * one would have to first delete a symbol in order to add another
 * at the same address. This may be changed later, perhaps.
 */
00145 typedef struct KDBGSPACEUSERSYM
{

} KDBGSPACEUSERSYM;
typedef KDBGSPACEUSERSYM *PKDBGSPACEUSERSYM;



/**
 * Address space.
 */
00156 typedef struct KDBGSPACE
{
    /** The addresspace magic. (KDBGSPACE_MAGIC) */
00159     KU32            u32Magic;
    /** User defined address space identifier or data pointer. */
00161     KUPTR           uUser;
    /** The name of the address space. (Optional) */
00163     const char     *pszName;


} KDBGSPACE;
/** Pointer to an address space. */
00168 typedef struct KDBGSPACE *PKDBGSPACE;
/** Pointer to an address space pointer. */
00170 typedef PKDBGSPACE *PPKDBGSPACE;


KDBG_DECL(int) kDbgSpaceCreate(PPDBGSPACE ppSpace, KDBGADDR LowAddr, DBGADDR HighAddr,
                               KUPTR uUser, const char *pszName)
{
    /*
     * Validate input.
     */
    kDbgAssertPtrReturn(ppSpace);
    *ppSpace = NULL;
    kDbgAssertPtrNullReturn(pszName);
    kDbgAssertReturn(LowAddr < HighAddr);

    /*
     * Create and initialize the address space.
     */
    PKDBGSPACE pSpace = (PKDBGSPACE)kHlpAlloc(sizeof(*pSpace));
    if (!pSpace)
        return KERR_NO_MEMORY;
    pSpace->u32Magic = KDBGSPACE_MAGIC;
    pSpace->uUser = uUser;
    pSpace->pszName = pszName;

}

Generated by  Doxygen 1.6.0   Back to index