3 * Copyright (C) 2004 ReactOS Team
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.
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.
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.
20 * PROJECT: ReactOS kernel
21 * FILE: ntoskrnl/dbg/kdb_stabs.c
22 * PURPOSE: Stabs functions...
23 * PROGRAMMER: Gregor Anich (blight@blight.eu.org)
28 #include <ddk/ntddk.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>
44 #include <internal/debug.h>
47 #include "kdb_stabs.h"
50 /*! \brief Find a stab entry...
52 * Looks through the stab for an entry which matches the specified criteria.
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.
59 * \returns Pointer to a STAB_ENTRY
60 * \retval NULL No entry found.
63 KdbpStabFindEntry(IN PIMAGE_SYMBOL_INFO SymbolInfo
,
65 IN PVOID RelativeAddress OPTIONAL
,
66 IN PSTAB_ENTRY StartEntry OPTIONAL
)
68 PSTAB_ENTRY StabEntry
, BestStabEntry
= NULL
;
70 ULONG_PTR AddrFound
= 0;
72 StabEntry
= SymbolInfo
->SymbolsBase
;
73 StabsEnd
= (PVOID
)((ULONG_PTR
)SymbolInfo
->SymbolsBase
+ SymbolInfo
->SymbolsLength
);
74 if (StartEntry
!= NULL
)
76 ASSERT((ULONG_PTR
)StartEntry
>= (ULONG_PTR
)StabEntry
);
77 if ((ULONG_PTR
)StartEntry
>= (ULONG_PTR
)StabsEnd
)
79 StabEntry
= StartEntry
;
82 for (; (ULONG_PTR
)StabEntry
< (ULONG_PTR
)StabsEnd
; StabEntry
++)
84 ULONG_PTR SymbolRelativeAddress
;
86 if (StabEntry
->n_type
!= Type
)
89 if (RelativeAddress
!= NULL
)
91 if (StabEntry
->n_value
< (ULONG_PTR
)SymbolInfo
->ImageBase
)
93 if (StabEntry
->n_value
>= ((ULONG_PTR
)SymbolInfo
->ImageBase
+ SymbolInfo
->ImageSize
))
96 SymbolRelativeAddress
= StabEntry
->n_value
- (ULONG_PTR
)SymbolInfo
->ImageBase
;
97 if ((SymbolRelativeAddress
<= (ULONG_PTR
)RelativeAddress
) &&
98 (SymbolRelativeAddress
> AddrFound
))
100 AddrFound
= SymbolRelativeAddress
;
101 BestStabEntry
= StabEntry
;
106 BestStabEntry
= StabEntry
;
111 if (BestStabEntry
== NULL
)
112 DPRINT("StabEntry not found!\n");
114 DPRINT("StabEntry found!\n");
116 return BestStabEntry
;