| 1 | /* $Id: kDbgSymbol.cpp 3550 2007-08-26 01:13:35Z bird $ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | * kDbg - The Debug Info Reader, Symbols.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | /*
|
|---|
| 7 | * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
|
|---|
| 8 | *
|
|---|
| 9 | * This file is part of kStuff.
|
|---|
| 10 | *
|
|---|
| 11 | * kStuff is free software; you can redistribute it and/or
|
|---|
| 12 | * modify it under the terms of the GNU Lesser General Public
|
|---|
| 13 | * License as published by the Free Software Foundation; either
|
|---|
| 14 | * version 2.1 of the License, or (at your option) any later version.
|
|---|
| 15 | *
|
|---|
| 16 | * kStuff is distributed in the hope that it will be useful,
|
|---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 19 | * Lesser General Public License for more details.
|
|---|
| 20 | *
|
|---|
| 21 | * You should have received a copy of the GNU Lesser General Public
|
|---|
| 22 | * License along with kStuff; if not, write to the Free Software
|
|---|
| 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|---|
| 24 | *
|
|---|
| 25 | */
|
|---|
| 26 |
|
|---|
| 27 | /*******************************************************************************
|
|---|
| 28 | * Header Files *
|
|---|
| 29 | *******************************************************************************/
|
|---|
| 30 | #include "kDbgInternal.h"
|
|---|
| 31 | #include <k/kHlpAlloc.h>
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 | /**
|
|---|
| 35 | * Duplicates a symbol.
|
|---|
| 36 | *
|
|---|
| 37 | * To save heap space, the returned symbol will not own more heap space than
|
|---|
| 38 | * it strictly need to. So, it's not possible to append stuff to the symbol
|
|---|
| 39 | * or anything of that kind.
|
|---|
| 40 | *
|
|---|
| 41 | * @returns Pointer to the duplicate.
|
|---|
| 42 | * This must be freed using kDbgSymbolFree().
|
|---|
| 43 | * @param pSymbol The symbol to be duplicated.
|
|---|
| 44 | */
|
|---|
| 45 | KDBG_DECL(PKDBGSYMBOL) kDbgSymbolDup(PCKDBGSYMBOL pSymbol)
|
|---|
| 46 | {
|
|---|
| 47 | kDbgAssertPtrReturn(pSymbol, NULL);
|
|---|
| 48 | KSIZE cb = K_OFFSETOF(KDBGSYMBOL, szName[pSymbol->cchName + 1]);
|
|---|
| 49 | PKDBGSYMBOL pNewSymbol = (PKDBGSYMBOL)kHlpDup(pSymbol, cb);
|
|---|
| 50 | if (pNewSymbol)
|
|---|
| 51 | pNewSymbol->cbSelf = cb;
|
|---|
| 52 | return pNewSymbol;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | /**
|
|---|
| 57 | * Frees a symbol obtained from the kDbg API.
|
|---|
| 58 | *
|
|---|
| 59 | * @returns 0 on success.
|
|---|
| 60 | * @returns KERR_INVALID_POINTER if pSymbol isn't a valid pointer.
|
|---|
| 61 | *
|
|---|
| 62 | * @param pSymbol The symbol to be freed. The null pointer is ignored.
|
|---|
| 63 | */
|
|---|
| 64 | KDBG_DECL(int) kDbgSymbolFree(PKDBGSYMBOL pSymbol)
|
|---|
| 65 | {
|
|---|
| 66 | if (!pSymbol)
|
|---|
| 67 | {
|
|---|
| 68 | kDbgAssertPtrReturn(pSymbol, KERR_INVALID_POINTER);
|
|---|
| 69 | pSymbol->cbSelf = 0;
|
|---|
| 70 | kHlpFree(pSymbol);
|
|---|
| 71 | }
|
|---|
| 72 | return 0;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|