home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dd2.zip / DDB.H < prev    next >
Text File  |  1995-01-14  |  13KB  |  445 lines

  1.  
  2.  
  3. typedef struct _DDBUF {
  4.    ULONG     ulPid;
  5.    ULONG     ulTid;
  6.    LONG      lCmd;
  7.    LONG      lValue;
  8.    ULONG     ulAddr;
  9.    ULONG     ulBuffer;
  10.    ULONG     ulLen;
  11.    ULONG     ulIndex;
  12.    ULONG     ulMTE;
  13.    ULONG     ulEAX;
  14.    ULONG     ulECX;
  15.    ULONG     ulEDX;
  16.    ULONG     ulEBX;
  17.    ULONG     ulESP;
  18.    ULONG     ulEBP;
  19.    ULONG     ulESI;
  20.    ULONG     ulEDI;
  21.    ULONG     ulEFlags;
  22.    ULONG     ulEIP;
  23.    ULONG     ulCSLim;
  24.    ULONG     ulCSBase;
  25.    UCHAR     ucCSAcc;
  26.    UCHAR     ucCSAtr;
  27.    USHORT    usCS;
  28.    ULONG     ulDSLim;
  29.    ULONG     ulDSBase;
  30.    UCHAR     ucDSAcc;
  31.    UCHAR     ucDSAtr;
  32.    USHORT    usDS;
  33.    ULONG     ulESLim;
  34.    ULONG     ulESBase;
  35.    UCHAR     ucESAcc;
  36.    UCHAR     ucESAtr;
  37.    USHORT    usES;
  38.    ULONG     ulFSLim;
  39.    ULONG     ulFSBase;
  40.    UCHAR     ucFSAcc;
  41.    UCHAR     ucFSAtr;
  42.    USHORT    usFS;
  43.    ULONG     ulGSLim;
  44.    ULONG     ulGSBase;
  45.    UCHAR     ucGSAcc;
  46.    UCHAR     ucGSAtr;
  47.    USHORT    usGS;
  48.    ULONG     ulSSLim;
  49.    ULONG     ulSSBase;
  50.    UCHAR     ucSSAcc;
  51.    UCHAR     ucSSAtr;
  52.    USHORT    usSS;
  53. } DDBUF;
  54. typedef DDBUF *PDDBUF;
  55.  
  56.  
  57. /*
  58.  For a description of the parameters and returns for each DosDebug command, select a
  59.  command:
  60.  
  61.  
  62.  Command Number and Name      Description
  63.  ───────────────────────      ───────────
  64.  
  65.  0    DBG_C_Null              Null
  66.  1    DBG_C_ReadMem           Read Word
  67.  1    DBG_C_ReadMem_I         Read Word
  68.  2    DBG_C_ReadMem_D         Read Word (same as 1)
  69.  3    DBG_C_ReadReg           Read Register Set
  70.  4    DBG_C_WriteMem          Write Word
  71.  4    DBG_C_WriteMem_I        Write Word
  72.  5    DBG_C_WriteMem_D        Write Word (same as 4)
  73.  6    DBG_C_WriteReg          Write Register Set
  74.  7    DBG_C_Go                Go
  75.  8    DBG_C_Term              Terminate
  76.  9    DBG_C_SStep             Single Step
  77.  10   DBG_C_Stop              Stop
  78.  11   DBG_C_Freeze            Freeze Thread
  79.  12   DBG_C_Resume            Resume Thread
  80.  13   DBG_C_NumToAddr         Object Number to Address
  81.  14   DBG_C_ReadCoRegs        Read Coprocessor Registers
  82.  15   DBG_C_WriteCoRegs       Write Coprocessor Registers
  83.  16   Reserved                Reserved
  84.  17   DBG_C_ThrdStat          Get Thread Status
  85.  18   DBG_C_MapROAlias        Map Read-Only Alias
  86.  19   DBG_C_MapRWAlias        Map Read-Write Alias
  87.  20   DBG_C_UnMapAlias        Unmap Alias
  88.  21   DBG_C_Connect           Connect to Debuggee
  89.  22   DBG_C_ReadMemBuf        Read Memory Buffer
  90.  23   DBG_C_WriteMemBuf       Write Memory Buffer
  91.  24   DBG_C_SetWatch          Set Watchpoint
  92.  25   DBG_C_ClearWatch        Clear Watchpoint
  93.  26   DBG_C_RangeStep         Range Step
  94.  27   DBG_C_Continue          Continue
  95.  28   DBG_C_AddrToObject      Get Memory Object Information
  96.  29   DBG_C_XchngOpcode       Exchange Opcode
  97.  30   DBG_C_LinToSel          Translate Linear Address to
  98.                                 Segment:Offset
  99.  31   DBG_C_SelToLin          Translate Segment:Offset to
  100.                                 Linear Address
  101.  
  102.  Not all fields must be defined for every DosDebug command.  The same field can have
  103.  a different meaning in different DosDebug commands.  For each command, fields in the
  104.  Debug Buffer structure that are not listed are not useful for that command, but may be
  105.  modified by DosDebug as required.
  106.  
  107.  Error cases for commands are not listed.  The listed return values from commands are
  108.  valid only if the DBG_N_Success notification is given.
  109. */
  110.  
  111. #define DBG_C_Null           0
  112. #define DBG_C_ReadMem        1
  113. #define DBG_C_ReadMem_I      1
  114. #define DBG_C_ReadMem_D      2
  115. #define DBG_C_ReadReg        3
  116. #define DBG_C_WriteMem       4
  117. #define DBG_C_WriteMem_I     4
  118. #define DBG_C_WriteMem_D     5
  119. #define DBG_C_WriteReg       6
  120. #define DBG_C_Go             7
  121. #define DBG_C_Term           8
  122. #define DBG_C_SStep          9
  123. #define DBG_C_Stop           10
  124. #define DBG_C_Freeze         11
  125. #define DBG_C_Resume         12
  126. #define DBG_C_NumToAddr      13
  127. #define DBG_C_ReadCoRegs     14
  128. #define DBG_C_WriteCoRegs    15
  129. #define Reserved             16
  130. #define DBG_C_ThrdStat       17
  131. #define DBG_C_MapROAlias     18
  132. #define DBG_C_MapRWAlias     19
  133. #define DBG_C_UnMapAlias     20
  134. #define DBG_C_Connect        21
  135. #define DBG_C_ReadMemBuf     22
  136. #define DBG_C_WriteMemBuf    23
  137. #define DBG_C_SetWatch       24
  138. #define DBG_C_ClearWatch     25
  139. #define DBG_C_RangeStep      26
  140. #define DBG_C_Continue       27
  141. #define DBG_C_AddrToObject   28
  142. #define DBG_C_XchngOpcode    29
  143. #define DBG_C_LinToSel       30
  144. #define DBG_C_SelToLin       31
  145.  
  146.  
  147. #define DBG_O_OBJMTE       0x10000000
  148.  
  149. PSZ aszDebugCommand[] =
  150. {
  151.   "DBG_C_Null",
  152. //  "DBG_C_ReadMem",
  153.   "DBG_C_ReadMem_I",
  154.   "DBG_C_ReadMem_D",
  155.   "DBG_C_ReadReg",
  156. //  "DBG_C_WriteMem",
  157.   "DBG_C_WriteMem_I",
  158.   "DBG_C_WriteMem_D",
  159.   "DBG_C_WriteReg",
  160.   "DBG_C_Go",
  161.   "DBG_C_Term",
  162.   "DBG_C_SStep",
  163.   "DBG_C_Stop",
  164.   "DBG_C_Freeze",
  165.   "DBG_C_Resume",
  166.   "DBG_C_NumToAddr",
  167.   "DBG_C_ReadCoRegs",
  168.   "DBG_C_WriteCoRegs",
  169.   "Reserved",
  170.   "DBG_C_ThrdStat",
  171.   "DBG_C_MapROAlias",
  172.   "DBG_C_MapRWAlias",
  173.   "DBG_C_UnMapAlias",
  174.   "DBG_C_Connect",
  175.   "DBG_C_ReadMemBuf",
  176.   "DBG_C_WriteMemBuf",
  177.   "DBG_C_SetWatch",
  178.   "DBG_C_ClearWatch",
  179.   "DBG_C_RangeStep",
  180.   "DBG_C_Continue",
  181.   "DBG_C_AddrToObject",
  182.   "DBG_C_XchngOpcode",
  183.   "DBG_C_LinToSel",
  184.   "DBG_C_SelToLin"
  185. };
  186.  
  187. /*
  188. PCHAR szDebugCommand(LONG lCmd)
  189. {
  190.    if (lCmd > -1 && lCmd < 32) {
  191.       return aszDebugCommand[lCmd];
  192.    } else {
  193.       return "DBG_C_ Invalid";
  194.  
  195.    }
  196. }
  197. */
  198.  
  199. PCHAR szDebugComm(LONG lCmd)
  200. {
  201.  
  202.    if (lCmd > -1 && lCmd < 32) {
  203.       return &aszDebugCommand[lCmd][6];
  204.    } else {
  205.       return "Invalid szDebugCommand";
  206.  
  207.    }
  208. }
  209.  
  210. PSZ aszProcTerm [] = {
  211.    "TC_EXIT",
  212.    "TC_HARDERROR",
  213.    "TC_TRAP",
  214.    "TC_KILLPROCESS",
  215.    "TC_EXCEPTION"
  216. };
  217.  
  218. PCHAR szProcTerm(ULONG lCmd)
  219. {
  220.    return aszProcTerm[lCmd];
  221. }
  222.  
  223.  
  224.  
  225.  
  226. /*
  227.  For a description of the data returned with each notification, select a notification:
  228.  
  229.  
  230.  Notification
  231.  Number and Name               Description
  232.  ───────────────               ───────────
  233.     Successful command completion
  234.     Error detected during command
  235.     Process termination -
  236.       DosExitList done
  237.     Exception detected
  238.     Module loaded
  239.     Coprocessor not in use error
  240.     Thread termination -
  241.       not in DosExitList
  242.     Async Stop detected
  243.     New Process started
  244.     Alias needs to be freed
  245.     Watchpoint hit
  246.     Thread creation
  247.     Module freed
  248.     Range Step detected
  249.  
  250.  Note:  References to "IP" in the data return descriptions refer to the instruction pointer
  251.         address.  This is the 32-bit equivalent of the CS:EIP instruction pointer,
  252.         regardless of the CS selector.  This is also known as a linearized instruction
  253.         pointer.
  254.  
  255.  
  256.  Some notifications (such as DBG_N_ModuleLoad and DBG_N_Watchpoint) may require
  257.  multiple returns to the debugger.  These additional pending notifications will be returned
  258.  before the process being debugged can execute any more user code, and will be
  259.  returned on the Go, SStep, or Stop commands.
  260.  
  261.  Note that more notifications might be pending at any time, so a debugger should be
  262.  ready to handle any notification at any time that a Go, SStep, or Stop command is
  263.  issued.
  264.  
  265.  If DosDebug returns ERROR_INTERRUPT after a command, the next notification might
  266.  have been lost.  If the process being debugged was executing code at that time (via a
  267.  Go, SStep, or RangeStep command), it will be stopped automatically.  To prevent this,
  268.  DosDebug should not be used by thread 1 while signals are being used, or the
  269.  debugger should issue DosEnterMustComplete before issuing the command.
  270. */
  271.  
  272.  
  273.  
  274. #define  DBG_N_SUCCESS        0
  275. #define  DBG_N_ERROR         -1L
  276. #define  TRC_C_SIG_ret       -2
  277. #define  TRC_C_TBT_ret       -3
  278. #define  TRC_C_BPT_ret       -4
  279. #define  TRC_C_NMI_ret       -5
  280. #define  DBG_N_ProcTerm      -6L
  281.  
  282. #define  DBG_N_Exception     -7L
  283. #define  DBG_N_ModuleLoad    -8L
  284. #define  DBG_N_CoError       -9L
  285. #define  DBG_N_ThreadTerm   -10L
  286.  
  287. #define  DBG_N_AsyncStop    -11L
  288. #define  DBG_N_NewProc      -12L
  289. #define  DBG_N_AliasFree    -13L
  290. #define  DBG_N_Watchpoint   -14L
  291. #define  DBG_N_ThreadCreate -15L
  292. #define  DBG_N_ModuleFree   -16L
  293. #define  DBG_N_RangeStep    -17L
  294.  
  295.  
  296.  
  297. PSZ  aszDebugNotification[] =
  298. {
  299.    "DBG_N_SUCCESS     \0 Successful command completion",
  300. //   "DBG_N_ERROR       \0 %s returns rc %08lX (%lu)",
  301.    "DBG_N_ERROR       \0 ",
  302.    "TRC_C_SIG_ret     \0 ?",
  303.    "TRC_C_TBT_ret     \0 ?",
  304.    "TRC_C_BPT_ret     \0 ?",
  305.    "TRC_C_NMI_ret     \0 ?",
  306.    "DBG_N_ProcTerm    \0 %-4i %-12s ExitList done",
  307.  
  308.    "DBG_N_Exception   \0\n           %s %08lX",
  309.    "DBG_N_ModuleLoad  \0 %-4lu %s",
  310.    "DBG_N_CoError     \0 Coprocessor not in use error",
  311.    "DBG_N_ThreadTerm  \0 %-4i not in DosExitList",
  312.  
  313.    "DBG_N_AsyncStop   \0 Async Stop detected",
  314.    "DBG_N_NewProc     \0 New Process started",
  315.    "DBG_N_AliasFree   \0 Alias needs to be freed",
  316.    "DBG_N_Watchpoint  \0 Watchpoint hit",
  317.    "DBG_N_ThreadCreate\0 ",
  318.    "DBG_N_ModuleFree  \0 %-4lu %s",
  319.    "DBG_N_RangeStep   \0 Range Step detected"
  320. };
  321.  
  322. PSZ szDebugNotification(LONG lCmd)
  323. {
  324.    if (lCmd < 1 && lCmd > -17) {
  325.       return aszDebugNotification[-lCmd];
  326.    } else {
  327.       return "DBG_N_ Invalid";
  328.    }
  329. }
  330.  
  331. PSZ szDebugNotific(LONG lCmd)
  332. {
  333.    if (lCmd < 1 && lCmd > -17) {
  334.       return &aszDebugNotification[-lCmd][19];
  335.    } else {
  336.       return "DBG_N_ Invalid";
  337.    }
  338. }
  339.  
  340.  
  341. #define  DBG_X_PRE_FIRST_CHANCE 0x00000000
  342. #define  DBG_X_FIRST_CHANCE     0x00000001
  343. #define  DBG_X_LAST_CHANCE      0x00000002
  344. #define  DBG_X_STACK_INVALID    0x00000003
  345.  
  346. PSZ  aszExceptValue[] =
  347. {
  348.    " PRE_FIRST_CHANCE",
  349.    " FIRST_CHANCE",
  350.    " LAST_CHANCE ",
  351.    " STACK_INVALID"
  352. };
  353.  
  354. PSZ szExceptValue(LONG lCmd)
  355. {
  356.    if (lCmd > -1 && lCmd < 4) {
  357.       return aszExceptValue[lCmd];
  358.    } else {
  359.       return "DBG_X_INVALID";
  360.    }
  361. }
  362.  
  363. PSZ szException(ULONG lXcpt)
  364. {
  365.    PSZ psz;
  366.  
  367.         if ( XCPT_GUARD_PAGE_VIOLATION    ==   lXcpt)
  368.       psz = "XCPT_GUARD_PAGE_VIOLATION";
  369.    else if ( XCPT_UNABLE_TO_GROW_STACK    ==   lXcpt)
  370.       psz = "XCPT_UNABLE_TO_GROW_STACK";
  371.    else if ( XCPT_DATATYPE_MISALIGNMENT   ==   lXcpt)
  372.       psz = "XCPT_DATATYPE_MISALIGNMENT";
  373.    else if ( XCPT_BREAKPOINT              ==   lXcpt)
  374.       psz = "XCPT_BREAKPOINT";
  375.    else if ( XCPT_SINGLE_STEP             ==   lXcpt)
  376.       psz = "XCPT_SINGLE_STEP";
  377.    else if ( XCPT_ACCESS_VIOLATION        ==   lXcpt)
  378.       psz = "XCPT_ACCESS_VIOLATION";
  379.    else if ( XCPT_ILLEGAL_INSTRUCTION     ==   lXcpt)
  380.       psz = "XCPT_ILLEGAL_INSTRUCTION";
  381.    else if ( XCPT_FLOAT_DENORMAL_OPERAND  ==   lXcpt)
  382.       psz = "XCPT_FLOAT_DENORMAL_OPERAND";
  383.    else if ( XCPT_FLOAT_DIVIDE_BY_ZERO    ==   lXcpt)
  384.       psz = "XCPT_FLOAT_DIVIDE_BY_ZERO";
  385.    else if ( XCPT_FLOAT_INEXACT_RESULT    ==   lXcpt)
  386.       psz = "XCPT_FLOAT_INEXACT_RESULT";
  387.    else if ( XCPT_FLOAT_INVALID_OPERATION ==   lXcpt)
  388.       psz = "XCPT_FLOAT_INVALID_OPERATION";
  389.    else if ( XCPT_FLOAT_OVERFLOW          ==   lXcpt)
  390.       psz = "XCPT_FLOAT_OVERFLOW";
  391.    else if ( XCPT_FLOAT_STACK_CHECK       ==   lXcpt)
  392.       psz = "XCPT_FLOAT_STACK_CHECK";
  393.    else if ( XCPT_FLOAT_UNDERFLOW         ==   lXcpt)
  394.       psz = "XCPT_FLOAT_UNDERFLOW";
  395.    else if ( XCPT_INTEGER_DIVIDE_BY_ZERO  ==   lXcpt)
  396.       psz = "XCPT_INTEGER_DIVIDE_BY_ZERO";
  397.    else if ( XCPT_INTEGER_OVERFLOW        ==   lXcpt)
  398.       psz = "XCPT_INTEGER_OVERFLOW";
  399.    else if ( XCPT_PRIVILEGED_INSTRUCTION  ==   lXcpt)
  400.       psz = "XCPT_PRIVILEGED_INSTRUCTION";
  401.    else if ( XCPT_IN_PAGE_ERROR           ==   lXcpt)
  402.       psz = "XCPT_IN_PAGE_ERROR";
  403.    else if ( XCPT_PROCESS_TERMINATE       ==   lXcpt)
  404.       psz = "XCPT_PROCESS_TERMINATE";
  405.    else if ( XCPT_ASYNC_PROCESS_TERMINATE ==   lXcpt)
  406.       psz = "XCPT_ASYNC_PROCESS_TERMINATE";
  407.    else if ( XCPT_NONCONTINUABLE_EXCEPTION==   lXcpt)
  408.       psz = "XCPT_NONCONTINUABLE_EXCEPTION";
  409.    else if ( XCPT_INVALID_DISPOSITION     ==   lXcpt)
  410.       psz = "XCPT_INVALID_DISPOSITION";
  411.    else if ( XCPT_INVALID_LOCK_SEQUENCE   ==   lXcpt)
  412.       psz = "XCPT_INVALID_LOCK_SEQUENCE";
  413.    else if ( XCPT_ARRAY_BOUNDS_EXCEEDED   ==   lXcpt)
  414.       psz = "XCPT_ARRAY_BOUNDS_EXCEEDED";
  415.    else if ( XCPT_B1NPX_ERRATA_02         ==   lXcpt)
  416.       psz = "XCPT_B1NPX_ERRATA_02";
  417.    else if ( XCPT_UNWIND                  ==   lXcpt)
  418.       psz = "XCPT_UNWIND";
  419.    else if ( XCPT_BAD_STACK               ==   lXcpt)
  420.       psz = "XCPT_BAD_STACK";
  421.    else if ( XCPT_INVALID_UNWIND_TARGET   ==   lXcpt)
  422.       psz = "XCPT_INVALID_UNWIND_TARGET";
  423.    else if ( XCPT_SIGNAL                  ==   lXcpt)
  424.       psz = "XCPT_SIGNAL";
  425.    else
  426.       psz = "XCPT_UNKNOWN";
  427.  
  428.    return psz;
  429. }
  430.  
  431.  
  432.  
  433.  
  434. /*
  435.     DosDebug returns the following values:
  436.  
  437.     0        NO_ERROR
  438.     87       ERROR_INVALID_PARAMETER
  439.     95       ERROR_INTERRUPT
  440.     115      ERROR_PROTECTION_VIOLATION
  441.  
  442. */
  443.  
  444.  
  445.