Changeset 21111 in vbox for trunk/src/VBox/VMM/DBGFAddrSpace.cpp
- Timestamp:
- Jul 1, 2009 1:04:06 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/DBGFAddrSpace.cpp
r21108 r21111 825 825 } 826 826 827 828 /** 829 * Adds the module name to the symbol name. 830 * 831 * @param pSymbol The symbol info (in/out). 832 * @param hMod The module handle. 833 */ 834 static void dbgfR3AsSymbolJoinNames(PRTDBGSYMBOL pSymbol, RTDBGMOD hMod) 835 { 836 /* Figure the lengths, adjust them if the result is too long. */ 837 const char *pszModName = RTDbgModName(hMod); 838 size_t cchModName = strlen(pszModName); 839 size_t cchSymbol = strlen(pSymbol->szName); 840 if (cchModName + 1 + cchSymbol >= sizeof(pSymbol->szName)) 841 { 842 if (cchModName >= sizeof(pSymbol->szName) / 4) 843 cchModName = sizeof(pSymbol->szName) / 4; 844 if (cchModName + 1 + cchSymbol >= sizeof(pSymbol->szName)) 845 cchSymbol = sizeof(pSymbol->szName) - cchModName - 2; 846 Assert(cchModName + 1 + cchSymbol < sizeof(pSymbol->szName)); 847 } 848 849 /* Do the moving and copying. */ 850 memmove(&pSymbol->szName[cchModName + 1], &pSymbol->szName[0], cchSymbol + 1); 851 memcpy(&pSymbol->szName[0], pszModName, cchModName); 852 pSymbol->szName[cchModName] = '!'; 853 } 854 855 856 /** Temporary symbol conversion function. */ 857 static void dbgfR3AsSymbolConvert(PRTDBGSYMBOL pSymbol, PCDBGFSYMBOL pDbgfSym) 858 { 859 pSymbol->offSeg = pSymbol->Value = pDbgfSym->Value; 860 pSymbol->cb = pDbgfSym->cb; 861 pSymbol->iSeg = 0; 862 pSymbol->fFlags = 0; 863 pSymbol->iOrdinal = UINT32_MAX; 864 strcpy(pSymbol->szName, pDbgfSym->szName); 865 } 866 867 868 /** 869 * Query a symbol by address. 870 * 871 * The returned symbol is the one we consider closes to the specified address. 872 * 873 * @returns VBox status code. See RTDbgAsSymbolByAddr. 874 * 875 * @param pVM The VM handle. 876 * @param hDbgAs The address space handle. 877 * @param pAddress The address to lookup. 878 * @param poffDisp Where to return the distance between the 879 * returned symbol and pAddress. Optional. 880 * @param pSymbol Where to return the symbol information. 881 * The returned symbol name will be prefixed by 882 * the module name as far as space allows. 883 * @param phMod Where to return the module handle. Optional. 884 */ 885 VMMR3DECL(int) DBGFR3AsSymbolByAddr(PVM pVM, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress, 886 PRTGCINTPTR poffDisp, PRTDBGSYMBOL pSymbol, PRTDBGMOD phMod) 887 { 888 /* 889 * Implement the special address space aliases the lazy way. 890 */ 891 if (hDbgAs == DBGF_AS_RC_AND_GC_GLOBAL) 892 { 893 int rc = DBGFR3AsSymbolByAddr(pVM, DBGF_AS_RC, pAddress, poffDisp, pSymbol, phMod); 894 if (RT_FAILURE(rc)) 895 rc = DBGFR3AsSymbolByAddr(pVM, DBGF_AS_GLOBAL, pAddress, poffDisp, pSymbol, phMod); 896 return rc; 897 } 898 899 /* 900 * Input validation. 901 */ 902 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 903 AssertReturn(DBGFR3AddrIsValid(pVM, pAddress), VERR_INVALID_PARAMETER); 904 AssertPtrNullReturn(poffDisp, VERR_INVALID_POINTER); 905 AssertPtrReturn(pSymbol, VERR_INVALID_POINTER); 906 AssertPtrNullReturn(phMod, VERR_INVALID_POINTER); 907 if (poffDisp) 908 *poffDisp = 0; 909 if (phMod) 910 *phMod = NIL_RTDBGMOD; 911 RTDBGAS hRealAS = DBGFR3AsResolveAndRetain(pVM, hDbgAs); 912 if (hRealAS == NIL_RTDBGAS) 913 return VERR_INVALID_HANDLE; 914 915 /* 916 * Do the lookup. 917 */ 918 RTDBGMOD hMod; 919 int rc = RTDbgAsSymbolByAddr(hRealAS, pAddress->FlatPtr, poffDisp, pSymbol, &hMod); 920 if (RT_SUCCESS(rc)) 921 { 922 dbgfR3AsSymbolJoinNames(pSymbol, hMod); 923 if (!phMod) 924 RTDbgModRelease(hMod); 925 } 926 /* Temporary conversion. */ 927 else if (hDbgAs == DBGF_AS_GLOBAL) 928 { 929 DBGFSYMBOL DbgfSym; 930 rc = DBGFR3SymbolByAddr(pVM, pAddress->FlatPtr, poffDisp, &DbgfSym); 931 if (RT_SUCCESS(rc)) 932 dbgfR3AsSymbolConvert(pSymbol, &DbgfSym); 933 } 934 935 return rc; 936 } 937 938 939 /** 940 * Query a symbol by name. 941 * 942 * The symbol can be prefixed by a module name pattern to scope the search. The 943 * pattern is a simple string pattern with '*' and '?' as wild chars. See 944 * RTStrSimplePatternMatch(). 945 * 946 * @returns VBox status code. See RTDbgAsSymbolByAddr. 947 * 948 * @param pVM The VM handle. 949 * @param hDbgAs The address space handle. 950 * @param pszSymbol The symbol to search for, maybe prefixed by a 951 * module pattern. 952 * @param pSymbol Where to return the symbol information. 953 * The returned symbol name will be prefixed by 954 * the module name as far as space allows. 955 * @param phMod Where to return the module handle. Optional. 956 */ 957 VMMR3DECL(int) DBGFR3AsSymbolByName(PVM pVM, RTDBGAS hDbgAs, const char *pszSymbol, 958 PRTDBGSYMBOL pSymbol, PRTDBGMOD phMod) 959 { 960 /* 961 * Implement the special address space aliases the lazy way. 962 */ 963 if (hDbgAs == DBGF_AS_RC_AND_GC_GLOBAL) 964 { 965 int rc = DBGFR3AsSymbolByName(pVM, DBGF_AS_RC, pszSymbol, pSymbol, phMod); 966 if (RT_FAILURE(rc)) 967 rc = DBGFR3AsSymbolByName(pVM, DBGF_AS_GLOBAL, pszSymbol, pSymbol, phMod); 968 return rc; 969 } 970 971 /* 972 * Input validation. 973 */ 974 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 975 AssertPtrReturn(pSymbol, VERR_INVALID_POINTER); 976 AssertPtrNullReturn(phMod, VERR_INVALID_POINTER); 977 if (phMod) 978 *phMod = NIL_RTDBGMOD; 979 RTDBGAS hRealAS = DBGFR3AsResolveAndRetain(pVM, hDbgAs); 980 if (hRealAS == NIL_RTDBGAS) 981 return VERR_INVALID_HANDLE; 982 983 984 /* 985 * Do the lookup. 986 */ 987 RTDBGMOD hMod; 988 int rc = RTDbgAsSymbolByName(hRealAS, pszSymbol, pSymbol, &hMod); 989 if (RT_SUCCESS(rc)) 990 { 991 dbgfR3AsSymbolJoinNames(pSymbol, hMod); 992 if (!phMod) 993 RTDbgModRelease(hMod); 994 } 995 /* Temporary conversion. */ 996 else if (hDbgAs == DBGF_AS_GLOBAL) 997 { 998 DBGFSYMBOL DbgfSym; 999 rc = DBGFR3SymbolByName(pVM, pszSymbol, &DbgfSym); 1000 if (RT_SUCCESS(rc)) 1001 dbgfR3AsSymbolConvert(pSymbol, &DbgfSym); 1002 } 1003 1004 return rc; 1005 } 1006
Note:
See TracChangeset
for help on using the changeset viewer.