VirtualBox

Ignore:
Timestamp:
Jun 23, 2009 12:10:32 AM (15 years ago)
Author:
vboxsync
Message:

IPRT: The rest of the basic RTDbgMod code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/dbg/dbgmod.cpp

    r20800 r20801  
    751751 *          end of the segment.
    752752 *
    753  * @param   pMod        Pointer to the module structure.
    754  * @param   iSeg        The segment number (0-based) or RTDBGSEGIDX_ABS.
    755  * @param   off         The offset into the segment.
    756  * @param   poffDisp    Where to store the distance between the specified address
    757  *                      and the returned symbol. Optional.
    758  * @param   pSymInfo    Where to store the symbol information.
     753 * @param   hDbgMod             The module handle.
     754 * @param   iSeg                The segment number.
     755 * @param   off                 The offset into the segment.
     756 * @param   poffDisp            Where to store the distance between the
     757 *                              specified address and the returned symbol.
     758 *                              Optional.
     759 * @param   pSymInfo            Where to store the symbol information.
    759760 */
    760761RTDECL(int) RTDbgModSymbolByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGSYMBOL pSymInfo)
     
    764765     */
    765766    PRTDBGMODINT pDbgMod = hDbgMod;
    766     RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINT32_MAX);
     767    RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
    767768    AssertPtrNull(poffDisp);
    768769    AssertPtr(pSymInfo);
     
    858859     */
    859860    PRTDBGMODINT pDbgMod = hDbgMod;
    860     RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINT32_MAX);
     861    RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
    861862    AssertPtr(pszSymbol);
    862863    size_t cchSymbol = strlen(pszSymbol);
     
    884885 * @retval  VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
    885886 *          short.
    886  *
    887887 * @retval  VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
     888 *
    888889 * @param   hDbgMod             The module handle.
    889890 * @param   pszSymbol           The symbol name.
     
    915916 *
    916917 * @returns IPRT status code.
     918 * @retval  VERR_NOT_SUPPORTED if the module interpret doesn't support adding
     919 *          custom symbols. This should be consider a normal response.
    917920 * @retval  VERR_INVALID_HANDLE if hDbgMod is invalid.
    918  * @retval  VERR_NOT_SUPPORTED if the module interpret doesn't support adding
    919  *          custom symbols.
    920  * @retval  VERR_DBG_FILE_NAME_OUT_OF_RANGE
    921  * @retval  VERR_DBG_INVALID_RVA
    922  * @retval  VERR_DBG_INVALID_SEGMENT_INDEX
    923  * @retval  VERR_DBG_INVALID_SEGMENT_OFFSET
    924  * @retval  VERR_INVALID_PARAMETER
    925  *
    926  * @param   hDbgMod         The module handle.
    927  * @param   pszFile         The file name.
    928  * @param   uLineNo         The line number.
    929  * @param   iSeg            The segment index.
    930  * @param   off             The segment offset.
    931  * @param   piOrdinal       Where to return the line number ordinal on success.
    932  *                          If the interpreter doesn't do ordinals, this will be
    933  *                          set to UINT32_MAX. Optional.
    934  */
    935 RTDECL(int) RTDbgModLineAdd(RTDBGMOD hDbgMod, const char *pszFile, uint32_t uLineNo, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t *piOrdinal)
     921 * @retval  VERR_DBG_FILE_NAME_OUT_OF_RANGE if the file name is too longer or
     922 *          empty.
     923 * @retval  VERR_DBG_INVALID_RVA if an image relative address is specified and
     924 *          it's not inside any of the segments defined by the module.
     925 * @retval  VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
     926 * @retval  VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
     927 *          end of the segment.
     928 * @retval  VERR_INVALID_PARAMETER if the line number flags sets undefined bits.
     929 *
     930 * @param   hDbgMod             The module handle.
     931 * @param   pszFile             The file name.
     932 * @param   uLineNo             The line number.
     933 * @param   iSeg                The segment index.
     934 * @param   off                 The segment offset.
     935 * @param   piOrdinal           Where to return the line number ordinal on
     936 *                              success. If  the interpreter doesn't do ordinals,
     937 *                              this will be set to UINT32_MAX. Optional.
     938 */
     939RTDECL(int) RTDbgModLineAdd(RTDBGMOD hDbgMod, const char *pszFile, uint32_t uLineNo,
     940                            RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t *piOrdinal)
    936941{
    937942    /*
     
    975980
    976981
    977 RTDECL(int)         RTDbgModLineByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE pLine)
    978 {
    979     return VERR_NOT_IMPLEMENTED;
    980 }
    981 
    982 RTDECL(int)         RTDbgModLineByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE *ppLine)
    983 {
    984     return VERR_NOT_IMPLEMENTED;
    985 }
    986 
     982/**
     983 * Gets the line number count.
     984 *
     985 * This can be used together wtih RTDbgModLineByOrdinal or RTDbgModSymbolByLineA
     986 * to enumerate all the line number information.
     987 *
     988 * @returns The number of line numbers in the module.
     989 *          UINT32_MAX is returned if the module handle is invalid or some other
     990 *          error occurs.
     991 *
     992 * @param   hDbgMod             The module handle.
     993 */
     994RTDECL(uint32_t) RTDbgModLineCount(RTDBGMOD hDbgMod)
     995{
     996    PRTDBGMODINT pDbgMod = hDbgMod;
     997    RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINT32_MAX);
     998    RTDBGMOD_LOCK(pDbgMod);
     999
     1000    uint32_t cLineNumbers = pDbgMod->pDbgVt->pfnLineCount(pDbgMod);
     1001
     1002    RTDBGMOD_UNLOCK(pDbgMod);
     1003    return cLineNumbers;
     1004}
     1005
     1006
     1007/**
     1008 * Queries line number information by ordinal number.
     1009 *
     1010 * This can be used to enumerate the line numbers for the module. Use
     1011 * RTDbgModLineCount() to figure the end of the ordinals.
     1012 *
     1013 * @returns IPRT status code.
     1014 * @retval  VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
     1015 * @retval  VERR_DBG_LINE_NOT_FOUND if there is no line number with that
     1016 *          ordinal.
     1017 * @retval  VERR_INVALID_HANDLE if hDbgMod is invalid.
     1018
     1019 * @param   hDbgMod             The module handle.
     1020 * @param   iOrdinal            The line number ordinal number.
     1021 * @param   pLineInfo           Where to store the information about the line
     1022 *                              number.
     1023 */
     1024RTDECL(int) RTDbgModLineByOrdinal(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo)
     1025{
     1026    PRTDBGMODINT pDbgMod = hDbgMod;
     1027    RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
     1028    RTDBGMOD_LOCK(pDbgMod);
     1029
     1030    int rc = pDbgMod->pDbgVt->pfnLineByOrdinal(pDbgMod, iOrdinal, pLineInfo);
     1031
     1032    RTDBGMOD_UNLOCK(pDbgMod);
     1033    return rc;
     1034}
     1035
     1036
     1037/**
     1038 * Queries line number information by ordinal number.
     1039 *
     1040 * This can be used to enumerate the line numbers for the module. Use
     1041 * RTDbgModLineCount() to figure the end of the ordinals.
     1042 *
     1043 * @returns IPRT status code.
     1044 * @retval  VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
     1045 * @retval  VERR_DBG_LINE_NOT_FOUND if there is no line number with that
     1046 *          ordinal.
     1047 * @retval  VERR_INVALID_HANDLE if hDbgMod is invalid.
     1048 * @retval  VERR_NO_MEMORY if RTDbgLineAlloc fails.
     1049 *
     1050 * @param   hDbgMod             The module handle.
     1051 * @param   iOrdinal            The line number ordinal number.
     1052 * @param   ppLineInfo          Where to store the pointer to the returned line
     1053 *                              number information. Always set. Free with
     1054 *                              RTDbgLineFree.
     1055 */
     1056RTDECL(int) RTDbgModLineByOrdinalA(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE *ppLineInfo)
     1057{
     1058    AssertPtr(ppLineInfo);
     1059    *ppLineInfo = NULL;
     1060
     1061    PRTDBGLINE pLineInfo = RTDbgLineAlloc();
     1062    if (!pLineInfo)
     1063        return VERR_NO_MEMORY;
     1064
     1065    int rc = RTDbgModLineByOrdinal(hDbgMod, iOrdinal, pLineInfo);
     1066
     1067    if (RT_SUCCESS(rc))
     1068        *ppLineInfo = pLineInfo;
     1069    else
     1070        RTDbgLineFree(pLineInfo);
     1071    return rc;
     1072}
     1073
     1074
     1075/**
     1076 * Queries line number information by address.
     1077 *
     1078 * The returned line number is what the debug info interpreter consideres the
     1079 * one most applicable to the specified address. This usually means a line
     1080 * number with an address equal or lower than the requested.
     1081 *
     1082 * @returns IPRT status code.
     1083 * @retval  VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
     1084 * @retval  VERR_DBG_LINE_NOT_FOUND if no suitable line number was found.
     1085 * @retval  VERR_INVALID_HANDLE if hDbgMod is invalid.
     1086 * @retval  VERR_DBG_INVALID_RVA if an image relative address is specified and
     1087 *          it's not inside any of the segments defined by the module.
     1088 * @retval  VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
     1089 * @retval  VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
     1090 *          end of the segment.
     1091 *
     1092 * @param   hDbgMod             The module handle.
     1093 * @param   iSeg                The segment number.
     1094 * @param   off                 The offset into the segment.
     1095 * @param   poffDisp            Where to store the distance between the
     1096 *                              specified address and the returned symbol.
     1097 *                              Optional.
     1098 * @param   pSymInfo            Where to store the symbol information.
     1099 */
     1100RTDECL(int) RTDbgModLineByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE pLineInfo)
     1101{
     1102    /*
     1103     * Validate input.
     1104     */
     1105    PRTDBGMODINT pDbgMod = hDbgMod;
     1106    RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
     1107    RTDBGMOD_LOCK(pDbgMod);
     1108    AssertPtrNull(poffDisp);
     1109    AssertPtr(pLineInfo);
     1110
     1111    RTDBGMOD_LOCK(pDbgMod);
     1112
     1113    /*
     1114     * Convert RVAs.
     1115     */
     1116    if (iSeg == RTDBGSEGIDX_RVA)
     1117    {
     1118        iSeg = pDbgMod->pDbgVt->pfnRvaToSegOff(pDbgMod, off, &off);
     1119        if (iSeg == NIL_RTDBGSEGIDX)
     1120        {
     1121            RTDBGMOD_UNLOCK(pDbgMod);
     1122            return VERR_DBG_INVALID_RVA;
     1123        }
     1124    }
     1125
     1126    int rc = pDbgMod->pDbgVt->pfnLineByAddr(pDbgMod, iSeg, off, poffDisp, pLineInfo);
     1127
     1128    RTDBGMOD_UNLOCK(pDbgMod);
     1129    return rc;
     1130}
     1131
     1132
     1133/**
     1134 * Queries line number information by address.
     1135 *
     1136 * The returned line number is what the debug info interpreter consideres the
     1137 * one most applicable to the specified address. This usually means a line
     1138 * number with an address equal or lower than the requested.
     1139 *
     1140 * @returns IPRT status code.
     1141 * @retval  VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
     1142 * @retval  VERR_DBG_LINE_NOT_FOUND if no suitable line number was found.
     1143 * @retval  VERR_INVALID_HANDLE if hDbgMod is invalid.
     1144 * @retval  VERR_DBG_INVALID_RVA if an image relative address is specified and
     1145 *          it's not inside any of the segments defined by the module.
     1146 * @retval  VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
     1147 * @retval  VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
     1148 *          end of the segment.
     1149 * @retval  VERR_NO_MEMORY if RTDbgLineAlloc fails.
     1150 *
     1151 * @param   hDbgMod             The module handle.
     1152 * @param   iSeg                The segment number.
     1153 * @param   off                 The offset into the segment.
     1154 * @param   poffDisp            Where to store the distance between the
     1155 *                              specified address and the returned symbol.
     1156 *                              Optional.
     1157 * @param   ppLineInfo          Where to store the pointer to the returned line
     1158 *                              number information. Always set. Free with
     1159 *                              RTDbgLineFree.
     1160 */
     1161RTDECL(int) RTDbgModLineByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE *ppLineInfo)
     1162{
     1163    AssertPtr(ppLineInfo);
     1164    *ppLineInfo = NULL;
     1165
     1166    PRTDBGLINE pLineInfo = RTDbgLineAlloc();
     1167    if (!pLineInfo)
     1168        return VERR_NO_MEMORY;
     1169
     1170    int rc = RTDbgModLineByAddr(hDbgMod, iSeg, off, poffDisp, pLineInfo);
     1171
     1172    if (RT_SUCCESS(rc))
     1173        *ppLineInfo = pLineInfo;
     1174    else
     1175        RTDbgLineFree(pLineInfo);
     1176    return rc;
     1177}
     1178
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette