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(" message size: %ld\n", port->fPort.fMessageSize); 81 kprintf(" buffer: %p\n", port->fPort.fBuffer); 82 return 0; 83 } 84 85 // #pragma mark - 86 87 // AddDebuggerCommands 88 void 89 KernelDebug::AddDebuggerCommands() 90 { 91 if (atomic_add(&sCommandsAdded, 1) > 0) 92 return; 93 PRINT(("KernelDebug::AddDebuggerCommands(): adding debugger commands\n")); 94 add_debugger_command("ufs", DebugUFS, "prints general info about " 95 "userland FS"); 96 add_debugger_command("ufs_portpool", DebugPortPool, 97 "ufs_portpool <port pool pointer> - prints info about a " 98 "userland FS port pool"); 99 add_debugger_command("ufs_port", DebugPort, 100 "ufs_port <port pointer> - prints info about a userland FS port"); 101 } 102 103 // RemoveDebuggerCommands 104 void 105 KernelDebug::RemoveDebuggerCommands() 106 { 107 if (atomic_add(&sCommandsAdded, -1) > 1) 108 return; 109 PRINT(("KernelDebug::RemoveDebuggerCommands(): removing debugger " 110 "commands\n")); 111 remove_debugger_command("ufs_port", DebugPort); 112 remove_debugger_command("ufs_portpool", DebugPortPool); 113 remove_debugger_command("ufs", DebugUFS); 114 } 115 116