Use upper-case ASSERT macros.
[reactos.git] / reactos / ntoskrnl / dbg / kdb_stabs.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /*
20 * PROJECT: ReactOS kernel
21 * FILE: ntoskrnl/dbg/kdb_stabs.c
22 * PURPOSE: Stabs functions...
23 * PROGRAMMER: Gregor Anich (blight@blight.eu.org)
24 * REVISION HISTORY:
25 * 2004/06/27: Created
26 */
27
28 #include <ddk/ntddk.h>
29 #include <roscfg.h>
30 #include <internal/ntoskrnl.h>
31 #include <internal/ke.h>
32 #include <internal/i386/segment.h>
33 #include <internal/i386/mm.h>
34 #include <internal/module.h>
35 #include <internal/mm.h>
36 #include <internal/ps.h>
37 #include <internal/trap.h>
38 #include <ntdll/ldr.h>
39 #include <internal/safe.h>
40 #include <internal/kd.h>
41 #include <rosrtl/string.h>
42
43 #define NDEBUG
44 #include <internal/debug.h>
45
46 #include "kdb.h"
47 #include "kdb_stabs.h"
48
49
50 /*! \brief Find a stab entry...
51 *
52 * Looks through the stab for an entry which matches the specified criteria.
53 *
54 * \param SymbolInfo Pointer to the symbol info.
55 * \param Type Type of stab entry to look for.
56 * \param RelativeAddress Relative address of stab to look for.
57 * \param StartEntry Starting stab entry.
58 *
59 * \returns Pointer to a STAB_ENTRY
60 * \retval NULL No entry found.
61 */
62 PSTAB_ENTRY
63 KdbpStabFindEntry(IN PIMAGE_SYMBOL_INFO SymbolInfo,
64 IN CHAR Type,
65 IN PVOID RelativeAddress OPTIONAL,
66 IN PSTAB_ENTRY StartEntry OPTIONAL)
67 {
68 PSTAB_ENTRY StabEntry, BestStabEntry = NULL;
69 PVOID StabsEnd;
70 ULONG_PTR AddrFound = 0;
71
72 StabEntry = SymbolInfo->SymbolsBase;
73 StabsEnd = (PVOID)((ULONG_PTR)SymbolInfo->SymbolsBase + SymbolInfo->SymbolsLength);
74 if (StartEntry != NULL)
75 {
76 ASSERT((ULONG_PTR)StartEntry >= (ULONG_PTR)StabEntry);
77 if ((ULONG_PTR)StartEntry >= (ULONG_PTR)StabsEnd)
78 return NULL;
79 StabEntry = StartEntry;
80 }
81
82 for (; (ULONG_PTR)StabEntry < (ULONG_PTR)StabsEnd; StabEntry++)
83 {
84 ULONG_PTR SymbolRelativeAddress;
85
86 if (StabEntry->n_type != Type)
87 continue;
88
89 if (RelativeAddress != NULL)
90 {
91 if (StabEntry->n_value < (ULONG_PTR)SymbolInfo->ImageBase)
92 continue;
93 if (StabEntry->n_value >= ((ULONG_PTR)SymbolInfo->ImageBase + SymbolInfo->ImageSize))
94 continue;
95
96 SymbolRelativeAddress = StabEntry->n_value - (ULONG_PTR)SymbolInfo->ImageBase;
97 if ((SymbolRelativeAddress <= (ULONG_PTR)RelativeAddress) &&
98 (SymbolRelativeAddress > AddrFound))
99 {
100 AddrFound = SymbolRelativeAddress;
101 BestStabEntry = StabEntry;
102 }
103 }
104 else
105 {
106 BestStabEntry = StabEntry;
107 break;
108 }
109 }
110
111 if (BestStabEntry == NULL)
112 DPRINT("StabEntry not found!\n");
113 else
114 DPRINT("StabEntry found!\n");
115
116 return BestStabEntry;
117 }
118