xref: /haiku/src/add-ons/kernel/file_systems/userlandfs/kernel_add_on/KernelDebug.cpp (revision c90684742e7361651849be4116d0e5de3a817194)
1 // KernelDebug.cpp
2 
3 #include "KernelDebug.h"
4 
5 #include <KernelExport.h>
6 
7 #include "Debug.h"
8 #include "FileSystem.h"
9 #include "FileSystemInitializer.h"
10 #include "RequestPort.h"
11 #include "RequestPortPool.h"
12 #include "UserlandFS.h"
13 #include "Volume.h"
14 
15 static vint32 sCommandsAdded = 0;
16 
17 // DebugUFS
18 int
19 KernelDebug::DebugUFS(int argc, char** argv)
20 {
21 	typedef HashMap<String, FileSystemInitializer*> KDebugFSMap;
22 	UserlandFS* userlandFS = UserlandFS::GetUserlandFS();
23 	KDebugFSMap& fileSystems = userlandFS->fFileSystems->GetUnsynchronizedMap();
24 
25 	for (KDebugFSMap::Iterator it = fileSystems.GetIterator();
26 		 it.HasNext();) {
27 		KDebugFSMap::Entry entry = it.Next();
28 		FileSystemInitializer* fsInitializer = entry.value;
29 		FileSystem* fs = fsInitializer->GetFileSystem();
30 		kprintf("file system %p: %s\n", fs, (fs ? fs->GetName() : NULL));
31 		if (fs) {
32 			kprintf("  port pool %p\n", fs->GetPortPool());
33 			int32 volumeCount = fs->fVolumes.Count();
34 			for (int32 i = 0; i < volumeCount; i++) {
35 				Volume* volume = fs->fVolumes.ElementAt(i);
36 				kprintf("  volume %p: %ld\n", volume, volume->GetID());
37 			}
38 		}
39 	}
40 	return 0;
41 }
42 
43 // DebugPortPool
44 int
45 KernelDebug::DebugPortPool(int argc, char** argv)
46 {
47 	if (argc < 2) {
48 		kprintf("usage: ufs_portpool <port pool pointer>\n");
49 		return 0;
50 	}
51 	RequestPortPool *portPool = (RequestPortPool*)parse_expression(argv[1]);
52 	kprintf("free ports:\n");
53 	for (int32 i = 0; i < portPool->fFreePorts; i++) {
54 		kprintf("  port %p\n", portPool->fPorts[i].port);
55 	}
56 	kprintf("used ports:\n");
57 	for (int32 i = portPool->fFreePorts; i < portPool->fPortCount; i++) {
58 		kprintf("  port %p, owner: %ld, count: %ld\n", portPool->fPorts[i].port,
59 			portPool->fPorts[i].owner, portPool->fPorts[i].count);
60 	}
61 	return 0;
62 }
63 
64 // DebugPort
65 int
66 KernelDebug::DebugPort(int argc, char** argv)
67 {
68 	if (argc < 2) {
69 		kprintf("usage: ufs_port <port pointer>\n");
70 		return 0;
71 	}
72 	RequestPort *port = (RequestPort*)parse_expression(argv[1]);
73 	kprintf("port %p:\n", port);
74 	kprintf("  status      : %lx\n", port->fPort.fInitStatus);
75 	kprintf("  is owner    : %d\n", port->fPort.fOwner);
76 	kprintf("  owner port:   %ld\n", port->fPort.fInfo.owner_port);
77 	kprintf("  client port:  %ld\n", port->fPort.fInfo.client_port);
78 	kprintf("  size:         %ld\n", port->fPort.fInfo.size);
79 	kprintf("  capacity:     %ld\n", port->fPort.fCapacity);
80 	kprintf("  buffer:       %p\n", port->fPort.fBuffer);
81 	return 0;
82 }
83 
84 // #pragma mark -
85 
86 // AddDebuggerCommands
87 void
88 KernelDebug::AddDebuggerCommands()
89 {
90 	if (atomic_add(&sCommandsAdded, 1) > 0)
91 		return;
92 	PRINT(("KernelDebug::AddDebuggerCommands(): adding debugger commands\n"));
93 	add_debugger_command("ufs", DebugUFS, "prints general info about "
94 		"userland FS");
95 	add_debugger_command("ufs_portpool", DebugPortPool,
96 		"ufs_portpool <port pool pointer> - prints info about a "
97 		"userland FS port pool");
98 	add_debugger_command("ufs_port", DebugPort,
99 		"ufs_port <port pointer> - prints info about a userland FS port");
100 }
101 
102 // RemoveDebuggerCommands
103 void
104 KernelDebug::RemoveDebuggerCommands()
105 {
106 	if (atomic_add(&sCommandsAdded, -1) > 1)
107 		return;
108 	PRINT(("KernelDebug::RemoveDebuggerCommands(): removing debugger "
109 		"commands\n"));
110 	remove_debugger_command("ufs_port", DebugPort);
111 	remove_debugger_command("ufs_portpool", DebugPortPool);
112 	remove_debugger_command("ufs", DebugUFS);
113 }
114 
115