Update the address of the Free Software Foundation.
[wine] / dlls / ntdll / debugbuffer.c
1 /*
2  * NtDll debug buffer functions
3  *
4  * Copyright 2004 Raphael Junqueira
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "ntstatus.h"
29 #define WIN32_NO_STATUS
30 #include "windef.h"
31 #include "winnt.h"
32 #include "winternl.h"
33 #include "ntdll_misc.h"
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(debug_buffer);
37
38 static void dump_DEBUG_MODULE_INFORMATION(PDEBUG_MODULE_INFORMATION iBuf)
39 {
40   TRACE( "MODULE_INFORMATION:%p\n", iBuf );
41   if (NULL == iBuf) return ;
42   TRACE( "Base:%ld\n", iBuf->Base );
43   TRACE( "Size:%ld\n", iBuf->Size );
44   TRACE( "Flags:%ld\n", iBuf->Flags );
45 }
46
47 static void dump_DEBUG_HEAP_INFORMATION(PDEBUG_HEAP_INFORMATION iBuf)
48 {
49   TRACE( "HEAP_INFORMATION:%p\n", iBuf );
50   if (NULL == iBuf) return ;
51   TRACE( "Base:%ld\n", iBuf->Base );
52   TRACE( "Flags:%ld\n", iBuf->Flags );
53 }
54
55 static void dump_DEBUG_LOCK_INFORMATION(PDEBUG_LOCK_INFORMATION iBuf)
56 {
57   TRACE( "LOCK_INFORMATION:%p\n", iBuf );
58
59   if (NULL == iBuf) return ;
60
61   TRACE( "Address:%p\n", iBuf->Address );
62   TRACE( "Type:%d\n", iBuf->Type );
63   TRACE( "CreatorBackTraceIndex:%d\n", iBuf->CreatorBackTraceIndex );
64   TRACE( "OwnerThreadId:%ld\n", iBuf->OwnerThreadId );
65   TRACE( "ActiveCount:%ld\n", iBuf->ActiveCount );
66   TRACE( "ContentionCount:%ld\n", iBuf->ContentionCount );
67   TRACE( "EntryCount:%ld\n", iBuf->EntryCount );
68   TRACE( "RecursionCount:%ld\n", iBuf->RecursionCount );
69   TRACE( "NumberOfSharedWaiters:%ld\n", iBuf->NumberOfSharedWaiters );
70   TRACE( "NumberOfExclusiveWaiters:%ld\n", iBuf->NumberOfExclusiveWaiters );
71 }
72
73 static void dump_DEBUG_BUFFER(PDEBUG_BUFFER iBuf)
74 {
75   if (NULL == iBuf) return ;
76   TRACE( "SectionHandle:%p\n", iBuf->SectionHandle);
77   TRACE( "SectionBase:%p\n", iBuf->SectionBase);
78   TRACE( "RemoteSectionBase:%p\n", iBuf->RemoteSectionBase);
79   TRACE( "SectionBaseDelta:%ld\n", iBuf->SectionBaseDelta);
80   TRACE( "EventPairHandle:%p\n", iBuf->EventPairHandle);
81   TRACE( "RemoteThreadHandle:%p\n", iBuf->RemoteThreadHandle);
82   TRACE( "InfoClassMask:%lx\n", iBuf->InfoClassMask);
83   TRACE( "SizeOfInfo:%ld\n", iBuf->SizeOfInfo);
84   TRACE( "AllocatedSize:%ld\n", iBuf->AllocatedSize);
85   TRACE( "SectionSize:%ld\n", iBuf->SectionSize);
86   TRACE( "BackTraceInfo:%p\n", iBuf->BackTraceInformation);
87   dump_DEBUG_MODULE_INFORMATION(iBuf->ModuleInformation);
88   dump_DEBUG_HEAP_INFORMATION(iBuf->HeapInformation);
89   dump_DEBUG_LOCK_INFORMATION(iBuf->LockInformation);
90 }
91
92 PDEBUG_BUFFER WINAPI RtlCreateQueryDebugBuffer(IN ULONG iSize, IN BOOLEAN iEventPair) 
93 {
94    PDEBUG_BUFFER oBuf = NULL;
95    FIXME("(%ld, %d): stub\n", iSize, iEventPair);
96    if (iSize < sizeof(DEBUG_BUFFER)) {
97      iSize = sizeof(DEBUG_BUFFER);
98    }
99    oBuf = (PDEBUG_BUFFER) RtlAllocateHeap(GetProcessHeap(), 0, iSize);
100    memset(oBuf, 0, iSize);
101    FIXME("(%ld, %d): returning %p\n", iSize, iEventPair, oBuf);
102    return oBuf;
103 }
104
105 NTSTATUS WINAPI RtlDestroyQueryDebugBuffer(IN PDEBUG_BUFFER iBuf) 
106 {
107    NTSTATUS nts = STATUS_SUCCESS;
108    FIXME("(%p): stub\n", iBuf);
109    if (NULL != iBuf) {
110      RtlFreeHeap(GetProcessHeap(), 0, iBuf->ModuleInformation);
111      RtlFreeHeap(GetProcessHeap(), 0, iBuf->HeapInformation);
112      RtlFreeHeap(GetProcessHeap(), 0, iBuf->LockInformation);
113      RtlFreeHeap(GetProcessHeap(), 0, iBuf);
114    }
115    return nts;
116 }
117
118 NTSTATUS WINAPI RtlQueryProcessDebugInformation(IN ULONG iProcessId, IN ULONG iDebugInfoMask, IN OUT PDEBUG_BUFFER iBuf) 
119 {
120    NTSTATUS nts = STATUS_SUCCESS;
121    FIXME("(%ld, %lx, %p): stub\n", iProcessId, iDebugInfoMask, iBuf);
122    iBuf->InfoClassMask = iDebugInfoMask;
123    
124    if (iDebugInfoMask & PDI_MODULES) {
125      PDEBUG_MODULE_INFORMATION info = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(DEBUG_MODULE_INFORMATION));
126      memset(info, 0, sizeof(DEBUG_MODULE_INFORMATION));
127      iBuf->ModuleInformation = info;
128    }
129    if (iDebugInfoMask & PDI_HEAPS) {
130      PDEBUG_HEAP_INFORMATION info = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(DEBUG_HEAP_INFORMATION));
131      memset(info, 0, sizeof(DEBUG_HEAP_INFORMATION));
132      if (iDebugInfoMask & PDI_HEAP_TAGS) {
133      }
134      if (iDebugInfoMask & PDI_HEAP_BLOCKS) {
135      }
136      iBuf->HeapInformation = info;
137    }
138    if (iDebugInfoMask & PDI_LOCKS) {
139      PDEBUG_LOCK_INFORMATION info = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(DEBUG_LOCK_INFORMATION));
140      memset(info, 0, sizeof(DEBUG_LOCK_INFORMATION));
141      iBuf->LockInformation = info;
142    }
143    TRACE("returns:%p\n", iBuf);
144    dump_DEBUG_BUFFER(iBuf);
145    return nts;
146 }