int IDebugProgram3.GetMemoryBytes(out IDebugMemoryBytes2 ppMemoryBytes) { return(IDebugProgram2.GetMemoryBytes(out ppMemoryBytes)); }
/// <summary> /// Reads from or writes to the debug target at the evaluated expression. /// </summary> /// <param name="program">VS internal program</param> /// <param name="frame">VS internal frame</param> /// <param name="buffer">Buffer to read/write</param> /// <param name="length">Length to read/write</param> /// <param name="read">True to perform read, false to perform write</param> /// <param name="expr">VS debugger expression. Will be casted to void*.</param> /// <returns>True on success, false on failure</returns> private bool MemoryAction(IDebugProgram2 program, IDebugStackFrame2 frame, ref byte[] buffer, uint length, bool read, string expr) { if (!IsDebugging) { ShowError(Resources.NotInDebugContextErrorText); return(false); } // Get the execution context (current frame) to evaluate the context IDebugExpressionContext2 expressionContext; if (frame.GetExpressionContext(out expressionContext) != VSConstants.S_OK || expressionContext == null) { ShowError(Resources.CannotGetExprContextErrorText); return(false); } // Try to parse the expression IDebugExpression2 expression; string error; uint errorCharIndex; if (expressionContext.ParseText(string.Format("(void *)({0})", expr), enum_PARSEFLAGS.PARSE_EXPRESSION, 10, out expression, out error, out errorCharIndex) != VSConstants.S_OK || errorCharIndex > 0) { ShowError(string.Format(Resources.ParseExpressionErrorText, expr, error)); return(false); } // Try to evaluate the expression IDebugProperty2 debugProperty; if (expression.EvaluateSync(enum_EVALFLAGS.EVAL_NOSIDEEFFECTS, uint.MaxValue, null, out debugProperty) != VSConstants.S_OK || debugProperty == null) { ShowError(Resources.ExpressionEvalErrorText); return(false); } // Get memory context of our evaluated expression IDebugMemoryContext2 memoryContext; if (debugProperty.GetMemoryContext(out memoryContext) != VSConstants.S_OK || memoryContext == null) { ShowError(Resources.CannotGetFrameErrorText); return(false); } // Get memory accessor // For some reason debugProperty.GetMemoryBytes does not work so we have to do it this way IDebugMemoryBytes2 memoryBytes; if (program.GetMemoryBytes(out memoryBytes) != VSConstants.S_OK || memoryBytes == null) { ShowError(Resources.CannotGetMemoryErrorText); return(false); } // Using the memory accessor and context, read or write to debugee memory if (read) { uint numread = 0; uint unreadable = 0; memoryBytes.ReadAt(memoryContext, length, buffer, out numread, ref unreadable); if (numread != length || unreadable > 0) { ShowError(string.Format(Resources.ChunkUnreadableErrorText, unreadable, length)); return(false); } } else { memoryBytes.WriteAt(memoryContext, length, buffer); } return(true); }