:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / ntoskrnl / dbg / rdebug.c
1 /*
2  *  ReactOS kernel
3  *  Copyright (C) 1998, 1999, 2000, 2001 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 /* $Id$
20  *
21  * COPYRIGHT:       See COPYING in the top level directory
22  * PROJECT:         ReactOS kernel
23  * FILE:            ntoskrnl/dbg/rdebug.c
24  * PURPOSE:         Runtime debugging support
25  * PROGRAMMER:      Casper S. Hornstrup (chorns@users.sourceforge.net)
26  * UPDATE HISTORY:
27  *      01-05-2001  CSH  Created
28  */
29
30 /* INCLUDES *****************************************************************/
31
32 #include <ddk/ntddk.h>
33
34 #define NDEBUG
35 #include <debug.h>
36
37 /* GLOBALS ******************************************************************/
38
39 typedef struct _RDEBUG_ENTRY {
40   LIST_ENTRY ListEntry;
41   CHAR Filename[MAX_PATH];
42 } RDEBUG_ENTRY, *PRDEBUG_ENTRY;
43
44 LIST_ENTRY RDebugListHead;
45 BOOLEAN RDebugInitialized = FALSE;
46
47 /* FUNCTIONS ****************************************************************/
48
49 PRDEBUG_ENTRY
50 DbgpFind(PCH Filename)
51 {
52   PLIST_ENTRY Current;
53   PRDEBUG_ENTRY Entry;
54
55   Current = RDebugListHead.Flink;
56   while (Current != &RDebugListHead)
57     {
58       Entry = CONTAINING_RECORD(Current, RDEBUG_ENTRY, ListEntry);
59
60       if (strcmp(Filename, Entry->Filename) == 0)
61         {
62           return Entry;
63         }
64       Current = Current->Flink;
65     }
66
67   return(NULL);
68 }
69
70 VOID
71 DbgRDebugInit(VOID)
72 {
73   if (RDebugInitialized)
74     return;
75
76   InitializeListHead(&RDebugListHead);
77   RDebugInitialized = TRUE;
78 }
79
80 VOID
81 DbgShowFiles(VOID)
82 {
83   PLIST_ENTRY Current;
84   PRDEBUG_ENTRY Entry;
85   ULONG Count;
86
87   if (!RDebugInitialized)
88     return;
89
90   Count = 0;
91   Current = RDebugListHead.Flink;
92   while (Current != &RDebugListHead)
93     {
94       Entry = CONTAINING_RECORD(Current, RDEBUG_ENTRY, ListEntry);
95
96       DbgPrint("  %s\n", Entry->Filename);
97       Count++;
98
99       Current = Current->Flink;
100     }
101
102   if (Count == 1)
103     {
104       DbgPrint("  1 file listed\n");
105     }
106   else
107     {
108       DbgPrint("  %d files listed\n", Count);
109     }
110 }
111
112 VOID
113 DbgEnableFile(PCH Filename)
114 {
115   PRDEBUG_ENTRY Entry;
116
117   if (!RDebugInitialized)
118     return;
119
120   if (!DbgpFind(Filename))
121     {
122       Entry = ExAllocatePool(NonPagedPool, sizeof(RDEBUG_ENTRY));
123       assert(Entry);
124       RtlMoveMemory(Entry->Filename, Filename, strlen(Filename) + 1);
125       InsertTailList(&RDebugListHead, &Entry->ListEntry);
126     }
127 }
128
129 VOID
130 DbgDisableFile(PCH Filename)
131 {
132   PRDEBUG_ENTRY Entry;
133
134   if (!RDebugInitialized)
135     return;
136
137   Entry = DbgpFind(Filename);
138   
139   if (Entry)
140     {
141       RemoveEntryList(&Entry->ListEntry);
142     }
143 }
144
145 BOOLEAN
146 DbgShouldPrint(PCH Filename)
147 {
148   if (!RDebugInitialized)
149     return FALSE;
150
151   return(DbgpFind(Filename) != NULL);
152 }
153
154 /* EOF */