Browse Source

Removed length limitation on unmanaged strings

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@172 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 21 years ago
parent
commit
a25838f546
  1. 15
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs
  2. 17
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Modules/Module.cs
  3. 59
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs
  4. 25
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/BuiltInVariable.cs
  5. 92
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectVariable.cs

15
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs

@ -26,20 +26,6 @@ namespace DebuggerLibrary @@ -26,20 +26,6 @@ namespace DebuggerLibrary
}
}
// Some variables that are used to get strings
// They are used all over the library and
// they are here so I don't have to decare them every time I need them
static internal uint unused;
static internal IntPtr unusedPtr = IntPtr.Zero;
internal const int pStringLen = 65536;
static internal IntPtr pString = Marshal.AllocHGlobal(pStringLen*2);
static internal string pStringAsUnicode {
get {
return Marshal.PtrToStringUni(pString);
}
}
static ICorDebug corDebug;
static ManagedCallback managedCallback;
static ManagedCallbackProxy managedCallbackProxy;
@ -94,7 +80,6 @@ namespace DebuggerLibrary @@ -94,7 +80,6 @@ namespace DebuggerLibrary
~NDebugger() //TODO
{
//corDebug.Terminate();
Marshal.FreeHGlobal(pString);
}
static internal void InitDebugger()

17
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Modules/Module.cs

@ -109,11 +109,18 @@ namespace DebuggerLibrary @@ -109,11 +109,18 @@ namespace DebuggerLibrary
metaDataInterface = (IMetaDataImport) pMetaDataInterface;
pModule.GetName(NDebugger.pStringLen,
out NDebugger.unused, // real string lenght
NDebugger.pString);
fullPath = NDebugger.pStringAsUnicode;
uint pStringLenght = 0; // Terminating character included in pStringLenght
IntPtr pString = IntPtr.Zero;
pModule.GetName(pStringLenght,
out pStringLenght, // real string lenght
pString);
// Allocate string buffer
pString = Marshal.AllocHGlobal((int)pStringLenght * 2);
pModule.GetName(pStringLenght,
out pStringLenght, // real string lenght
pString);
fullPath = Marshal.PtrToStringUni(pString);
Marshal.FreeHGlobal(pString);
SymBinder symBinder = new SymBinder();

59
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs

@ -52,6 +52,8 @@ namespace DebuggerLibrary @@ -52,6 +52,8 @@ namespace DebuggerLibrary
unsafe void Init()
{
uint pStringLenght = 0; // Terminating character included in pStringLenght
IntPtr pString = IntPtr.Zero;
uint codeRVA;
uint implFlags;
IntPtr pSigBlob;
@ -59,15 +61,31 @@ namespace DebuggerLibrary @@ -59,15 +61,31 @@ namespace DebuggerLibrary
module.MetaDataInterface.GetMethodProps(
(uint)token.GetToken(),
out parentClassToken,
NDebugger.pString,
NDebugger.pStringLen,
out NDebugger.unused, // real string lenght
pString,
pStringLenght,
out pStringLenght, // real string lenght
out attributes,
new IntPtr(&pSigBlob),
out sigBlobSize,
out codeRVA,
out implFlags);
name = NDebugger.pStringAsUnicode;
// Allocate string buffer
pString = Marshal.AllocHGlobal((int)pStringLenght * 2);
module.MetaDataInterface.GetMethodProps(
(uint)token.GetToken(),
out parentClassToken,
pString,
pStringLenght,
out pStringLenght, // real string lenght
out attributes,
new IntPtr(&pSigBlob),
out sigBlobSize,
out codeRVA,
out implFlags);
name = Marshal.PtrToStringUni(pString);
Marshal.FreeHGlobal(pString);
SignatureStream sig = new SignatureStream(pSigBlob, sigBlobSize);
@ -305,21 +323,38 @@ namespace DebuggerLibrary @@ -305,21 +323,38 @@ namespace DebuggerLibrary
ICorDebugValue arg;
corILFrame.GetArgument(i, out arg);
uint unused;
uint pStringLenght = 0; // Terminating character included in pStringLenght
IntPtr pString = IntPtr.Zero;
uint argPos, attr, type;
Module.MetaDataInterface.GetParamProps(
paramToken,
out NDebugger.unused,
Module.MetaDataInterface.GetParamProps(paramToken,
out unused,
out argPos,
pString,
pStringLenght,
out pStringLenght, // real string lenght
out attr,
out type,
IntPtr.Zero,
out unused);
// Allocate string buffer
pString = Marshal.AllocHGlobal((int)pStringLenght * 2);
Module.MetaDataInterface.GetParamProps(paramToken,
out unused,
out argPos,
NDebugger.pString,
NDebugger.pStringLen,
out NDebugger.unused, // real string lenght
pString,
pStringLenght,
out pStringLenght, // real string lenght
out attr,
out type,
IntPtr.Zero,
out NDebugger.unused);
out unused);
string name = Marshal.PtrToStringUni(pString);
Marshal.FreeHGlobal(pString);
collection.Add(VariableFactory.CreateVariable(arg, NDebugger.pStringAsUnicode));
collection.Add(VariableFactory.CreateVariable(arg, name));
}
// local variables

25
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/BuiltInVariable.cs

@ -17,10 +17,27 @@ namespace DebuggerLibrary @@ -17,10 +17,27 @@ namespace DebuggerLibrary
{
if (CorType == CorElementType.STRING)
{
((ICorDebugStringValue)corValue).GetString(NDebugger.pStringLen,
out NDebugger.unused,
NDebugger.pString);
return NDebugger.pStringAsUnicode;
uint pStringLenght = 1; // Terminating character NOT included in pStringLenght
IntPtr pString = Marshal.AllocHGlobal(2);
// For some reason this function does not accept IntPtr.Zero
((ICorDebugStringValue)corValue).GetString(pStringLenght,
out pStringLenght,
pString);
// Re-allocate string buffer
Marshal.FreeHGlobal(pString);
// Termination null is not included in pStringLenght
pStringLenght++;
pString = Marshal.AllocHGlobal((int)pStringLenght * 2);
((ICorDebugStringValue)corValue).GetString(pStringLenght,
out pStringLenght,
pString);
string text = Marshal.PtrToStringUni(pString);
Marshal.FreeHGlobal(pString);
return text;
}
object retValue;

92
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectVariable.cs

@ -18,10 +18,11 @@ namespace DebuggerLibrary @@ -18,10 +18,11 @@ namespace DebuggerLibrary
ICorDebugClass corClass;
ICorDebugModule corModule;
IMetaDataImport metaData;
uint classToken;
uint superCallsToken;
ICorDebugModule corModuleSuperclass;
ObjectVariable baseClass;
uint classToken;
uint superCallsToken;
uint typeDefFlags;
string type;
public override object Value {
@ -55,13 +56,27 @@ namespace DebuggerLibrary @@ -55,13 +56,27 @@ namespace DebuggerLibrary
corClass.GetModule(out corModule);
metaData = new Module(corModule).MetaDataInterface; //TODO
uint pStringLenght = 0; // Terminating character included in pStringLenght
IntPtr pString = IntPtr.Zero;
// Get length of string 'type'
metaData.GetTypeDefProps(classToken,
NDebugger.pString,
NDebugger.pStringLen,
out NDebugger.unused, // real string lenght
out NDebugger.unused,
pString,
pStringLenght,
out pStringLenght,
out typeDefFlags,
out superCallsToken);
type = NDebugger.pStringAsUnicode;
// Allocate string buffer
pString = Marshal.AllocHGlobal((int)pStringLenght * 2);
// Get properties
metaData.GetTypeDefProps(classToken,
pString,
pStringLenght,
out pStringLenght,
out typeDefFlags,
out superCallsToken);
type = Marshal.PtrToStringUni(pString);
Marshal.FreeHGlobal(pString);
corModuleSuperclass = corModule;
}
@ -82,19 +97,39 @@ namespace DebuggerLibrary @@ -82,19 +97,39 @@ namespace DebuggerLibrary
break;
}
uint unused;
IntPtr unusedPtr = IntPtr.Zero;
uint pStringLenght = 0; // Terminating character included in pStringLenght
IntPtr pString = IntPtr.Zero;
uint attrib;
metaData.GetFieldProps(fieldToken,
out NDebugger.unused,
NDebugger.pString,
NDebugger.pStringLen,
out NDebugger.unused, // real string lenght
out unused,
pString,
pStringLenght,
out pStringLenght, // real string lenght
out attrib,
IntPtr.Zero,
out NDebugger.unused,
out NDebugger.unused,
out NDebugger.unusedPtr,
out NDebugger.unused);
string name = NDebugger.pStringAsUnicode;
IntPtr.Zero,
out unused,
out unused,
out unusedPtr,
out unused);
// Allocate string buffer
pString = Marshal.AllocHGlobal((int)pStringLenght * 2);
metaData.GetFieldProps(fieldToken,
out unused,
pString,
pStringLenght,
out pStringLenght, // real string lenght
out attrib,
IntPtr.Zero,
out unused,
out unused,
out unusedPtr,
out unused);
string name = Marshal.PtrToStringUni(pString);
Marshal.FreeHGlobal(pString);
ICorDebugValue innerValue;
if ((attrib & (uint)ClassFieldAttribute.fdStatic)!=0)
@ -137,12 +172,25 @@ namespace DebuggerLibrary @@ -137,12 +172,25 @@ namespace DebuggerLibrary
// If referencing to external assembly
if ((superCallsToken & 0x01000000) != 0)
{
uint unused;
uint pStringLenght = 0; // Terminating character included in pStringLenght
IntPtr pString = IntPtr.Zero;
metaData.GetTypeRefProps(superCallsToken,
out NDebugger.unused,
NDebugger.pString,
NDebugger.pStringLen,
out NDebugger.unused); // real string lenght
fullTypeName = NDebugger.pStringAsUnicode;
out unused,
pString,
pStringLenght,
out pStringLenght); // real string lenght
// Allocate string buffer
pString = Marshal.AllocHGlobal((int)pStringLenght * 2);
metaData.GetTypeRefProps(superCallsToken,
out unused,
pString,
pStringLenght,
out pStringLenght); // real string lenght
fullTypeName = Marshal.PtrToStringUni(pString);
Marshal.FreeHGlobal(pString);
superCallsToken = 0;
foreach (Module m in NDebugger.Instance.Modules)

Loading…
Cancel
Save