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. 19
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Modules/Module.cs
  3. 65
      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
} }
} }
// 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 ICorDebug corDebug;
static ManagedCallback managedCallback; static ManagedCallback managedCallback;
static ManagedCallbackProxy managedCallbackProxy; static ManagedCallbackProxy managedCallbackProxy;
@ -94,7 +80,6 @@ namespace DebuggerLibrary
~NDebugger() //TODO ~NDebugger() //TODO
{ {
//corDebug.Terminate(); //corDebug.Terminate();
Marshal.FreeHGlobal(pString);
} }
static internal void InitDebugger() static internal void InitDebugger()

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

@ -108,12 +108,19 @@ namespace DebuggerLibrary
pModule.GetMetaDataInterface(ref metaDataInterfaceGuid, out pMetaDataInterface); pModule.GetMetaDataInterface(ref metaDataInterfaceGuid, out pMetaDataInterface);
metaDataInterface = (IMetaDataImport) pMetaDataInterface; metaDataInterface = (IMetaDataImport) pMetaDataInterface;
pModule.GetName(NDebugger.pStringLen, uint pStringLenght = 0; // Terminating character included in pStringLenght
out NDebugger.unused, // real string lenght IntPtr pString = IntPtr.Zero;
NDebugger.pString); pModule.GetName(pStringLenght,
fullPath = NDebugger.pStringAsUnicode; 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(); SymBinder symBinder = new SymBinder();

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

@ -51,7 +51,9 @@ namespace DebuggerLibrary
} }
unsafe void Init() unsafe void Init()
{ {
uint pStringLenght = 0; // Terminating character included in pStringLenght
IntPtr pString = IntPtr.Zero;
uint codeRVA; uint codeRVA;
uint implFlags; uint implFlags;
IntPtr pSigBlob; IntPtr pSigBlob;
@ -59,15 +61,31 @@ namespace DebuggerLibrary
module.MetaDataInterface.GetMethodProps( module.MetaDataInterface.GetMethodProps(
(uint)token.GetToken(), (uint)token.GetToken(),
out parentClassToken, out parentClassToken,
NDebugger.pString, pString,
NDebugger.pStringLen, pStringLenght,
out NDebugger.unused, // real string lenght out pStringLenght, // real string lenght
out attributes,
new IntPtr(&pSigBlob),
out sigBlobSize,
out codeRVA,
out implFlags);
// 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, out attributes,
new IntPtr(&pSigBlob), new IntPtr(&pSigBlob),
out sigBlobSize, out sigBlobSize,
out codeRVA, out codeRVA,
out implFlags); out implFlags);
name = NDebugger.pStringAsUnicode;
name = Marshal.PtrToStringUni(pString);
Marshal.FreeHGlobal(pString);
SignatureStream sig = new SignatureStream(pSigBlob, sigBlobSize); SignatureStream sig = new SignatureStream(pSigBlob, sigBlobSize);
@ -303,23 +321,40 @@ namespace DebuggerLibrary
if (paramsFetched == 0) break; if (paramsFetched == 0) break;
ICorDebugValue arg; ICorDebugValue arg;
corILFrame.GetArgument(i, out arg); corILFrame.GetArgument(i, out arg);
uint unused;
uint pStringLenght = 0; // Terminating character included in pStringLenght
IntPtr pString = IntPtr.Zero;
uint argPos, attr, type; uint argPos, attr, type;
Module.MetaDataInterface.GetParamProps( Module.MetaDataInterface.GetParamProps(paramToken,
paramToken, out unused,
out NDebugger.unused,
out argPos, out argPos,
NDebugger.pString, pString,
NDebugger.pStringLen, pStringLenght,
out NDebugger.unused, // real string lenght out pStringLenght, // real string lenght
out attr, out attr,
out type, out type,
IntPtr.Zero, IntPtr.Zero,
out NDebugger.unused); out unused);
// Allocate string buffer
pString = Marshal.AllocHGlobal((int)pStringLenght * 2);
Module.MetaDataInterface.GetParamProps(paramToken,
out unused,
out argPos,
pString,
pStringLenght,
out pStringLenght, // real string lenght
out attr,
out type,
IntPtr.Zero,
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 // local variables

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

@ -17,10 +17,27 @@ namespace DebuggerLibrary
{ {
if (CorType == CorElementType.STRING) if (CorType == CorElementType.STRING)
{ {
((ICorDebugStringValue)corValue).GetString(NDebugger.pStringLen, uint pStringLenght = 1; // Terminating character NOT included in pStringLenght
out NDebugger.unused, IntPtr pString = Marshal.AllocHGlobal(2);
NDebugger.pString);
return NDebugger.pStringAsUnicode; // 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; object retValue;

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

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

Loading…
Cancel
Save