?? dump.cpp
字號:
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
Module Name:
dump.cpp
Abstract:
Device Console
dump information out about a particular device
--*/
#include "devcon.h"
BOOL DumpDeviceWithInfo(HDEVINFO Devs,PSP_DEVINFO_DATA DevInfo,LPCTSTR Info)
/*++
Routine Description:
Write device instance & info to stdout
Arguments:
Devs )_ uniquely identify device
DevInfo )
Return Value:
none
--*/
{
TCHAR devID[MAX_DEVICE_ID_LEN];
LPTSTR desc;
BOOL b = TRUE;
SP_DEVINFO_LIST_DETAIL_DATA devInfoListDetail;
devInfoListDetail.cbSize = sizeof(devInfoListDetail);
if((!SetupDiGetDeviceInfoListDetail(Devs,&devInfoListDetail)) ||
(CM_Get_Device_ID_Ex(DevInfo->DevInst,devID,MAX_DEVICE_ID_LEN,0,devInfoListDetail.RemoteMachineHandle)!=CR_SUCCESS)) {
lstrcpy(devID,TEXT("?"));
b = FALSE;
}
if(Info) {
_tprintf(TEXT("%-60s: %s\n"),devID,Info);
} else {
_tprintf(TEXT("%s\n"),devID);
}
return b;
}
BOOL DumpDevice(HDEVINFO Devs,PSP_DEVINFO_DATA DevInfo)
/*++
Routine Description:
Write device instance & description to stdout
Arguments:
Devs )_ uniquely identify device
DevInfo )
Return Value:
TRUE if success
--*/
{
LPTSTR desc;
BOOL b;
desc = GetDeviceDescription(Devs,DevInfo);
b = DumpDeviceWithInfo(Devs,DevInfo,desc);
if(desc) {
delete [] desc;
}
return b;
}
BOOL DumpDeviceDescr(HDEVINFO Devs,PSP_DEVINFO_DATA DevInfo)
/*++
Routine Description:
Write device description to stdout
Arguments:
Devs )_ uniquely identify device
DevInfo )
Return Value:
TRUE if success
--*/
{
LPTSTR desc;
BOOL b;
desc = GetDeviceDescription(Devs,DevInfo);
if(!desc) {
return FALSE;
}
Padding(1);
FormatToStream(stdout,MSG_DUMP_DESCRIPTION,desc);
delete [] desc;
return TRUE;
}
BOOL DumpDeviceClass(HDEVINFO Devs,PSP_DEVINFO_DATA DevInfo)
/*++
Routine Description:
Write device class information to stdout
Arguments:
Devs )_ uniquely identify device
DevInfo )
Return Value:
TRUE if success
--*/
{
LPTSTR cls;
LPTSTR guid;
Padding(1);
cls = GetDeviceStringProperty(Devs,DevInfo,SPDRP_CLASS);
guid = GetDeviceStringProperty(Devs,DevInfo,SPDRP_CLASSGUID);
if(!cls && !guid) {
FormatToStream(stdout,
MSG_DUMP_NOSETUPCLASS
);
} else {
FormatToStream(stdout,
MSG_DUMP_SETUPCLASS,
guid ? guid : TEXT("{}"),
cls ? cls : TEXT("(?)")
);
}
if(cls) {
delete [] cls;
}
if(guid) {
delete [] guid;
}
return TRUE;
}
BOOL DumpDeviceStatus(HDEVINFO Devs,PSP_DEVINFO_DATA DevInfo)
/*++
Routine Description:
Write device status to stdout
Arguments:
Devs )_ uniquely identify device
DevInfo )
Return Value:
none
--*/
{
SP_DEVINFO_LIST_DETAIL_DATA devInfoListDetail;
ULONG status = 0;
ULONG problem = 0;
BOOL hasInfo = FALSE;
devInfoListDetail.cbSize = sizeof(devInfoListDetail);
if((!SetupDiGetDeviceInfoListDetail(Devs,&devInfoListDetail)) ||
(CM_Get_DevNode_Status_Ex(&status,&problem,DevInfo->DevInst,0,devInfoListDetail.RemoteMachineHandle)!=CR_SUCCESS)) {
return FALSE;
}
//
// handle off the status/problem codes
//
if((status & DN_HAS_PROBLEM) && problem == CM_PROB_DISABLED) {
hasInfo = TRUE;
Padding(1);
FormatToStream(stdout,MSG_DUMP_DISABLED);
return TRUE;
}
if(status & DN_HAS_PROBLEM) {
hasInfo = TRUE;
Padding(1);
FormatToStream(stdout,MSG_DUMP_PROBLEM,problem);
}
if(status & DN_PRIVATE_PROBLEM) {
hasInfo = TRUE;
Padding(1);
FormatToStream(stdout,MSG_DUMP_PRIVATE_PROBLEM);
}
if(status & DN_STARTED) {
Padding(1);
FormatToStream(stdout,MSG_DUMP_STARTED);
} else if (!hasInfo) {
Padding(1);
FormatToStream(stdout,MSG_DUMP_NOTSTARTED);
}
return TRUE;
}
BOOL DumpDeviceResourcesOfType(DEVINST DevInst,HMACHINE MachineHandle,LOG_CONF Config,RESOURCEID ReqResId)
{
RES_DES prevResDes = (RES_DES)Config;
RES_DES resDes = 0;
RESOURCEID resId = ReqResId;
ULONG dataSize;
PBYTE resDesData;
while(CM_Get_Next_Res_Des_Ex(&resDes,prevResDes,ReqResId,&resId,0,MachineHandle)==CR_SUCCESS) {
if(prevResDes != Config) {
CM_Free_Res_Des_Handle(prevResDes);
}
prevResDes = resDes;
if(CM_Get_Res_Des_Data_Size_Ex(&dataSize,resDes,0,MachineHandle)!=CR_SUCCESS) {
continue;
}
resDesData = new BYTE[dataSize];
if(!resDesData) {
continue;
}
if(CM_Get_Res_Des_Data_Ex(resDes,resDesData,dataSize,0,MachineHandle)!=CR_SUCCESS) {
delete [] resDesData;
continue;
}
switch(resId) {
case ResType_Mem: {
PMEM_RESOURCE pMemData = (PMEM_RESOURCE)resDesData;
if(pMemData->MEM_Header.MD_Alloc_End-pMemData->MEM_Header.MD_Alloc_Base+1) {
Padding(2);
_tprintf(TEXT("MEM : %08I64x-%08I64x\n"),pMemData->MEM_Header.MD_Alloc_Base,pMemData->MEM_Header.MD_Alloc_End);
}
break;
}
case ResType_IO: {
PIO_RESOURCE pIoData = (PIO_RESOURCE)resDesData;
if(pIoData->IO_Header.IOD_Alloc_End-pIoData->IO_Header.IOD_Alloc_Base+1) {
Padding(2);
_tprintf(TEXT("IO : %04I64x-%04I64x\n"),pIoData->IO_Header.IOD_Alloc_Base,pIoData->IO_Header.IOD_Alloc_End);
}
break;
}
case ResType_DMA: {
PDMA_RESOURCE pDmaData = (PDMA_RESOURCE)resDesData;
Padding(2);
_tprintf(TEXT("DMA : %u\n"),pDmaData->DMA_Header.DD_Alloc_Chan);
break;
}
case ResType_IRQ: {
PIRQ_RESOURCE pIrqData = (PIRQ_RESOURCE)resDesData;
Padding(2);
_tprintf(TEXT("IRQ : %u\n"),pIrqData->IRQ_Header.IRQD_Alloc_Num);
break;
}
}
delete [] resDesData;
}
if(prevResDes != Config) {
CM_Free_Res_Des_Handle(prevResDes);
}
return TRUE;
}
BOOL DumpDeviceResources(HDEVINFO Devs,PSP_DEVINFO_DATA DevInfo)
/*++
Routine Description:
Dump Resources to stdout
Arguments:
Devs )_ uniquely identify device
DevInfo )
Return Value:
none
--*/
{
SP_DEVINFO_LIST_DETAIL_DATA devInfoListDetail;
ULONG status = 0;
ULONG problem = 0;
LOG_CONF config = 0;
BOOL haveConfig = FALSE;
//
// see what state the device is in
//
devInfoListDetail.cbSize = sizeof(devInfoListDetail);
if((!SetupDiGetDeviceInfoListDetail(Devs,&devInfoListDetail)) ||
(CM_Get_DevNode_Status_Ex(&status,&problem,DevInfo->DevInst,0,devInfoListDetail.RemoteMachineHandle)!=CR_SUCCESS)) {
return FALSE;
}
//
// see if the device is running and what resources it might be using
//
if(!(status & DN_HAS_PROBLEM)) {
//
// If this device is running, does this devinst have a ALLOC log config?
//
if (CM_Get_First_Log_Conf_Ex(&config,
DevInfo->DevInst,
ALLOC_LOG_CONF,
devInfoListDetail.RemoteMachineHandle) == CR_SUCCESS) {
haveConfig = TRUE;
}
}
if(!haveConfig) {
//
// If no config so far, does it have a FORCED log config?
// (note that technically these resources might be used by another device
// but is useful info to show)
//
if (CM_Get_First_Log_Conf_Ex(&config,
DevInfo->DevInst,
FORCED_LOG_CONF,
devInfoListDetail.RemoteMachineHandle) == CR_SUCCESS) {
haveConfig = TRUE;
}
}
if(!haveConfig) {
//
// if there's a hardware-disabled problem, boot-config isn't valid
// otherwise use this if we don't have anything else
//
if(!(status & DN_HAS_PROBLEM) || (problem != CM_PROB_HARDWARE_DISABLED)) {
//
// Does it have a BOOT log config?
//
if (CM_Get_First_Log_Conf_Ex(&config,
DevInfo->DevInst,
BOOT_LOG_CONF,
devInfoListDetail.RemoteMachineHandle) == CR_SUCCESS) {
haveConfig = TRUE;
}
}
}
if(!haveConfig) {
//
// if we don't have any configuration, display an apropriate message
//
Padding(1);
FormatToStream(stdout,(status & DN_STARTED) ? MSG_DUMP_NO_RESOURCES : MSG_DUMP_NO_RESERVED_RESOURCES );
return TRUE;
}
Padding(1);
FormatToStream(stdout,(status & DN_STARTED) ? MSG_DUMP_RESOURCES : MSG_DUMP_RESERVED_RESOURCES );
//
// dump resources
//
DumpDeviceResourcesOfType(DevInfo->DevInst,devInfoListDetail.RemoteMachineHandle,config,ResType_Mem);
DumpDeviceResourcesOfType(DevInfo->DevInst,devInfoListDetail.RemoteMachineHandle,config,ResType_IO);
DumpDeviceResourcesOfType(DevInfo->DevInst,devInfoListDetail.RemoteMachineHandle,config,ResType_DMA);
DumpDeviceResourcesOfType(DevInfo->DevInst,devInfoListDetail.RemoteMachineHandle,config,ResType_IRQ);
//
// release handle
//
CM_Free_Log_Conf_Handle(config);
return TRUE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -