- Timestamp:
- Dec 22, 2010 5:30:04 PM (14 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageDebugVM.cpp
r35242 r35306 44 44 45 45 /** 46 * Handles the info sub-command. 47 * 48 * @returns Suitable exit code. 49 * @param a The handler arguments. 50 * @param pDebugger Pointer to the debugger interface. 51 */ 52 static RTEXITCODE handleDebugVM_Info(HandlerArg *a, IMachineDebugger *pDebugger) 53 { 54 if (a->argc < 3 || a->argc > 4) 55 return errorSyntax(USAGE_DEBUGVM, "The inject sub-command takes at one or two arguments"); 56 57 com::Bstr bstrName(a->argv[2]); 58 com::Bstr bstrArgs(a->argv[3]); 59 com::Bstr bstrInfo; 60 CHECK_ERROR2_RET(pDebugger, Info(bstrName.raw(), bstrArgs.raw(), bstrInfo.asOutParam()), RTEXITCODE_FAILURE); 61 RTPrintf("%ls", bstrInfo.raw()); 62 return RTEXITCODE_SUCCESS; 63 } 64 65 /** 46 66 * Handles the inject sub-command. 47 67 * … … 116 136 com::Bstr bstrCompression(pszCompression); 117 137 CHECK_ERROR2_RET(pDebugger, DumpGuestCore(bstrFilename.raw(), bstrCompression.raw()), RTEXITCODE_FAILURE); 138 return RTEXITCODE_SUCCESS; 139 } 140 141 /** 142 * Handles the os sub-command. 143 * 144 * @returns Suitable exit code. 145 * @param a The handler arguments. 146 * @param pDebugger Pointer to the debugger interface. 147 */ 148 static RTEXITCODE handleDebugVM_OSDetect(HandlerArg *a, IMachineDebugger *pDebugger) 149 { 150 if (a->argc != 2) 151 return errorSyntax(USAGE_DEBUGVM, "The osdetect sub-command does not take any arguments"); 152 153 com::Bstr bstrName; 154 CHECK_ERROR2_RET(pDebugger, DetectOS(bstrName.asOutParam()), RTEXITCODE_FAILURE); 155 RTPrintf("Detected: %ls\n", bstrName.raw()); 156 return RTEXITCODE_SUCCESS; 157 } 158 159 /** 160 * Handles the os sub-command. 161 * 162 * @returns Suitable exit code. 163 * @param a The handler arguments. 164 * @param pDebugger Pointer to the debugger interface. 165 */ 166 static RTEXITCODE handleDebugVM_OSInfo(HandlerArg *a, IMachineDebugger *pDebugger) 167 { 168 if (a->argc != 2) 169 return errorSyntax(USAGE_DEBUGVM, "The osinfo sub-command does not take any arguments"); 170 171 com::Bstr bstrName; 172 CHECK_ERROR2_RET(pDebugger, COMGETTER(OSName)(bstrName.asOutParam()), RTEXITCODE_FAILURE); 173 com::Bstr bstrVersion; 174 CHECK_ERROR2_RET(pDebugger, COMGETTER(OSVersion)(bstrVersion.asOutParam()), RTEXITCODE_FAILURE); 175 RTPrintf("Name: %ls\n", bstrName.raw()); 176 RTPrintf("Version: %ls\n", bstrVersion.raw()); 118 177 return RTEXITCODE_SUCCESS; 119 178 } … … 224 283 if (!strcmp(pszSubCmd, "dumpguestcore")) 225 284 rcExit = handleDebugVM_DumpVMCore(pArgs, ptrDebugger); 285 else if (!strcmp(pszSubCmd, "info")) 286 rcExit = handleDebugVM_Info(pArgs, ptrDebugger); 226 287 else if (!strcmp(pszSubCmd, "injectnmi")) 227 288 rcExit = handleDebugVM_InjectNMI(pArgs, ptrDebugger); 289 else if (!strcmp(pszSubCmd, "osdetect")) 290 rcExit = handleDebugVM_OSDetect(pArgs, ptrDebugger); 291 else if (!strcmp(pszSubCmd, "osinfo")) 292 rcExit = handleDebugVM_OSInfo(pArgs, ptrDebugger); 228 293 else if (!strcmp(pszSubCmd, "statistics")) 229 294 rcExit = handleDebugVM_Statistics(pArgs, ptrDebugger); -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r35194 r35306 612 612 "VBoxManage debugvm <uuid>|<name>\n" 613 613 " dumpguestcore --filename <name> |\n" 614 " info <item> [args] |\n" 614 615 " injectnmi |\n" 616 " osdetect |\n" 617 " osinfo |\n" 615 618 " statistics [--reset] [--pattern <pattern>]\n" 616 619 " [--descriptions]\n" -
trunk/src/VBox/Main/MachineDebuggerImpl.cpp
r35250 r35306 1 1 /* $Id$ */ 2 3 2 /** @file 4 * 5 * VirtualBox COM class implementation 3 * VBox IMachineDebugger COM class implementation. 6 4 */ 7 5 8 6 /* 9 * Copyright (C) 2006-20 08Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 10 8 * 11 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 546 544 STDMETHODIMP MachineDebugger::COMGETTER(OSName)(BSTR *a_pbstrName) 547 545 { 548 ReturnComNotImplemented(); 546 LogFlowThisFunc(("\n")); 547 CheckComArgNotNull(a_pbstrName); 548 AutoCaller autoCaller(this); 549 HRESULT hrc = autoCaller.rc(); 550 if (SUCCEEDED(hrc)) 551 { 552 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 553 Console::SafeVMPtr ptrVM(mParent); 554 hrc = ptrVM.rc(); 555 if (SUCCEEDED(hrc)) 556 { 557 /* 558 * Do the job and try convert the name. 559 */ 560 char szName[64]; 561 int vrc = DBGFR3OSQueryNameAndVersion(ptrVM.raw(), szName, sizeof(szName), NULL, 0); 562 if (RT_SUCCESS(vrc)) 563 { 564 try 565 { 566 Bstr bstrName(szName); 567 bstrName.detachTo(a_pbstrName); 568 } 569 catch (std::bad_alloc) 570 { 571 hrc = E_OUTOFMEMORY; 572 } 573 } 574 else 575 hrc = setError(VBOX_E_VM_ERROR, tr("DBGFR3OSQueryNameAndVersion failed with %Rrc"), vrc); 576 } 577 } 578 return hrc; 549 579 } 550 580 551 581 STDMETHODIMP MachineDebugger::COMGETTER(OSVersion)(BSTR *a_pbstrVersion) 552 582 { 553 ReturnComNotImplemented(); 583 LogFlowThisFunc(("\n")); 584 CheckComArgNotNull(a_pbstrVersion); 585 AutoCaller autoCaller(this); 586 HRESULT hrc = autoCaller.rc(); 587 if (SUCCEEDED(hrc)) 588 { 589 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 590 Console::SafeVMPtr ptrVM(mParent); 591 hrc = ptrVM.rc(); 592 if (SUCCEEDED(hrc)) 593 { 594 /* 595 * Do the job and try convert the name. 596 */ 597 char szVersion[256]; 598 int vrc = DBGFR3OSQueryNameAndVersion(ptrVM.raw(), NULL, 0, szVersion, sizeof(szVersion)); 599 if (RT_SUCCESS(vrc)) 600 { 601 try 602 { 603 Bstr bstrVersion(szVersion); 604 bstrVersion.detachTo(a_pbstrVersion); 605 } 606 catch (std::bad_alloc) 607 { 608 hrc = E_OUTOFMEMORY; 609 } 610 } 611 else 612 hrc = setError(VBOX_E_VM_ERROR, tr("DBGFR3OSQueryNameAndVersion failed with %Rrc"), vrc); 613 } 614 } 615 return hrc; 554 616 } 555 617 … … 708 770 } 709 771 772 /** 773 * Debug info string buffer formatter. 774 */ 775 typedef struct MACHINEDEBUGGERINOFHLP 776 { 777 /** The core info helper structure. */ 778 DBGFINFOHLP Core; 779 /** Pointer to the buffer. */ 780 char *pszBuf; 781 /** The size of the buffer. */ 782 size_t cbBuf; 783 /** The offset into the buffer */ 784 size_t offBuf; 785 /** Indicates an out-of-memory condition. */ 786 bool fOutOfMemory; 787 } MACHINEDEBUGGERINOFHLP; 788 /** Pointer to a Debug info string buffer formatter. */ 789 typedef MACHINEDEBUGGERINOFHLP *PMACHINEDEBUGGERINOFHLP; 790 791 792 /** 793 * @callback_method_impl{FNRTSTROUTPUT} 794 */ 795 static DECLCALLBACK(size_t) MachineDebuggerInfoOutput(void *pvArg, const char *pachChars, size_t cbChars) 796 { 797 PMACHINEDEBUGGERINOFHLP pHlp = (PMACHINEDEBUGGERINOFHLP)pvArg; 798 799 /* 800 * Grow the buffer if required. 801 */ 802 size_t const cbRequired = cbChars + pHlp->offBuf + 1; 803 if (cbRequired > pHlp->cbBuf) 804 { 805 if (RT_UNLIKELY(pHlp->fOutOfMemory)) 806 return 0; 807 808 size_t cbBufNew = pHlp->cbBuf * 2; 809 if (cbRequired > cbBufNew) 810 cbBufNew = RT_ALIGN_Z(cbRequired, 256); 811 void *pvBufNew = RTMemRealloc(pHlp->pszBuf, cbBufNew); 812 if (RT_UNLIKELY(!pvBufNew)) 813 { 814 pHlp->fOutOfMemory = true; 815 RTMemFree(pHlp->pszBuf); 816 pHlp->pszBuf = NULL; 817 pHlp->cbBuf = 0; 818 pHlp->offBuf = 0; 819 return 0; 820 } 821 822 pHlp->pszBuf = (char *)pvBufNew; 823 pHlp->cbBuf = cbBufNew; 824 } 825 826 /* 827 * Copy the bytes into the buffer and terminate it. 828 */ 829 memcpy(&pHlp->pszBuf[pHlp->offBuf], pachChars, cbChars); 830 pHlp->offBuf += cbChars; 831 pHlp->pszBuf[pHlp->offBuf] = '\0'; 832 Assert(pHlp->offBuf < pHlp->cbBuf); 833 return cbChars; 834 } 835 836 /** 837 * @interface_method_impl{DBGFINFOHLP, pfnPrintfV} 838 */ 839 static DECLCALLBACK(void) MachineDebuggerInfoPrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list va) 840 { 841 RTStrFormatV(MachineDebuggerInfoOutput, (void *)pHlp, NULL, NULL, pszFormat, va); 842 } 843 844 /** 845 * @interface_method_impl{DBGFINFOHLP, pfnPrintf} 846 */ 847 static DECLCALLBACK(void) MachineDebuggerInfoPrintf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...) 848 { 849 va_list va; 850 va_start(va, pszFormat); 851 MachineDebuggerInfoPrintfV(pHlp, pszFormat, va); 852 va_end(va); 853 } 854 855 /** 856 * Initializes the debug info string buffer formatter 857 * 858 * @param pHlp The help structure to init. 859 */ 860 static void MachineDebuggerInfoInit(PMACHINEDEBUGGERINOFHLP pHlp) 861 { 862 pHlp->Core.pfnPrintf = MachineDebuggerInfoPrintf; 863 pHlp->Core.pfnPrintfV = MachineDebuggerInfoPrintfV; 864 pHlp->pszBuf = NULL; 865 pHlp->cbBuf = 0; 866 pHlp->offBuf = 0; 867 pHlp->fOutOfMemory = false; 868 } 869 870 /** 871 * Deletes the debug info string buffer formatter. 872 * @param pHlp The helper structure to delete. 873 */ 874 static void MachineDebuggerInfoDelete(PMACHINEDEBUGGERINOFHLP pHlp) 875 { 876 RTMemFree(pHlp->pszBuf); 877 pHlp->pszBuf = NULL; 878 } 879 710 880 STDMETHODIMP MachineDebugger::Info(IN_BSTR a_bstrName, IN_BSTR a_bstrArgs, BSTR *a_pbstrInfo) 711 881 { 712 ReturnComNotImplemented(); 882 LogFlowThisFunc(("\n")); 883 884 /* 885 * Validate and convert input. 886 */ 887 CheckComArgStrNotEmptyOrNull(a_bstrName); 888 Utf8Str strName, strArgs; 889 try 890 { 891 strName = a_bstrName; 892 strArgs = a_bstrArgs; 893 } 894 catch (std::bad_alloc) 895 { 896 return E_OUTOFMEMORY; 897 } 898 899 /* 900 * Do the autocaller and lock bits. 901 */ 902 AutoCaller autoCaller(this); 903 HRESULT hrc = autoCaller.rc(); 904 if (SUCCEEDED(hrc)) 905 { 906 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 907 Console::SafeVMPtr ptrVM(mParent); 908 hrc = ptrVM.rc(); 909 if (SUCCEEDED(hrc)) 910 { 911 /* 912 * Create a helper and call DBGFR3Info. 913 */ 914 MACHINEDEBUGGERINOFHLP Hlp; 915 MachineDebuggerInfoInit(&Hlp); 916 int vrc = DBGFR3Info(ptrVM.raw(), strName.c_str(), strArgs.c_str(), &Hlp.Core); 917 if (RT_SUCCESS(vrc)) 918 { 919 if (!Hlp.fOutOfMemory) 920 { 921 /* 922 * Convert the info string, watching out for allocation errors. 923 */ 924 try 925 { 926 Bstr bstrInfo(Hlp.pszBuf); 927 bstrInfo.detachTo(a_pbstrInfo); 928 } 929 catch (std::bad_alloc) 930 { 931 hrc = E_OUTOFMEMORY; 932 } 933 } 934 else 935 hrc = E_OUTOFMEMORY; 936 } 937 else 938 hrc = setError(VBOX_E_VM_ERROR, tr("DBGFR3Info failed with %Rrc"), vrc); 939 MachineDebuggerInfoDelete(&Hlp); 940 } 941 } 942 return hrc; 713 943 } 714 944 … … 773 1003 STDMETHODIMP MachineDebugger::DetectOS(BSTR *a_pbstrName) 774 1004 { 775 ReturnComNotImplemented(); 1005 LogFlowThisFunc(("\n")); 1006 CheckComArgNotNull(a_pbstrName); 1007 1008 /* 1009 * Do the autocaller and lock bits. 1010 */ 1011 AutoCaller autoCaller(this); 1012 HRESULT hrc = autoCaller.rc(); 1013 if (SUCCEEDED(hrc)) 1014 { 1015 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1016 Console::SafeVMPtr ptrVM(mParent); 1017 hrc = ptrVM.rc(); 1018 if (SUCCEEDED(hrc)) 1019 { 1020 /* 1021 * Do the job and try convert the name. 1022 */ 1023 /** @todo automatically load the DBGC plugins or this is a waste of time. */ 1024 char szName[64]; 1025 int vrc = DBGFR3OSDetect(ptrVM.raw(), szName, sizeof(szName)); 1026 if (RT_SUCCESS(vrc) && vrc != VINF_DBGF_OS_NOT_DETCTED) 1027 { 1028 try 1029 { 1030 Bstr bstrName(szName); 1031 bstrName.detachTo(a_pbstrName); 1032 } 1033 catch (std::bad_alloc) 1034 { 1035 hrc = E_OUTOFMEMORY; 1036 } 1037 } 1038 else 1039 hrc = setError(VBOX_E_VM_ERROR, tr("DBGFR3OSDetect failed with %Rrc"), vrc); 1040 } 1041 } 1042 return hrc; 776 1043 } 777 1044
Note:
See TracChangeset
for help on using the changeset viewer.