Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement paged request of assemblies available in the target #1554

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 106 additions & 13 deletions src/CLR/Debugger/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,11 +1119,13 @@ static void GetClrReleaseInfo(CLR_DBG_Commands::Debugging_Execution_QueryCLRCapa
}
}

static bool GetInteropNativeAssemblies( uint8_t* &data, int* size)
static bool GetInteropNativeAssemblies( uint8_t* &data, int* size, uint32_t startIndex, uint32_t count )
{
uint32_t index = 0;

extern const CLR_RT_NativeAssemblyData *g_CLR_InteropAssembliesNativeData[];

int nativeAssembliesCount = 0;
uint32_t nativeAssembliesCount = 0;
CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails* interopNativeAssemblies = NULL;

// because the Interop assemblies list is assembled during the build we have to count how many are there before allocating memory for the array
Expand All @@ -1135,32 +1137,94 @@ static bool GetInteropNativeAssemblies( uint8_t* &data, int* size)
}
}

interopNativeAssemblies = (CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails*)platform_malloc(sizeof(CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails) * nativeAssembliesCount);
// sanity checks on the requested size
// - if 0, adjust to the assemblies count to make the execution backwards compatible
// - trim if over the available assembly count
// (max possible page size is 255)
if( count == 0 ||
count > 255 ||
(count + startIndex) > nativeAssembliesCount)
{
// adjust to the assemblies count to make the execution backwards compatible
count = nativeAssembliesCount - startIndex;
}

// alloc buffer to hold the requested number of assemblies
interopNativeAssemblies = (CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails*)platform_malloc(sizeof(CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails) * count);

// check for malloc failure
if(interopNativeAssemblies == NULL)
{
return false;
}

// clear memory
memset(
interopNativeAssemblies,
0,
sizeof(CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails) * count);

// fill the array
for ( int i = 0; i < nativeAssembliesCount; i++ )
for ( uint32_t i = 0; i < nativeAssembliesCount; i++ )
{
if (g_CLR_InteropAssembliesNativeData[i] != NULL)
{
interopNativeAssemblies[i].CheckSum = g_CLR_InteropAssembliesNativeData[i]->m_checkSum;
hal_strcpy_s((char*)interopNativeAssemblies[i].AssemblyName, ARRAYSIZE(interopNativeAssemblies[i].AssemblyName), g_CLR_InteropAssembliesNativeData[i]->m_szAssemblyName);
// we have an assembly at this position
// check if it's on the requested range
if( i >= startIndex &&
i <= (startIndex + count))
{
interopNativeAssemblies[index].CheckSum = g_CLR_InteropAssembliesNativeData[i]->m_checkSum;
hal_strcpy_s((char*)interopNativeAssemblies[index].AssemblyName, ARRAYSIZE(interopNativeAssemblies[index].AssemblyName), g_CLR_InteropAssembliesNativeData[i]->m_szAssemblyName);

NFVersion::Init(interopNativeAssemblies[i].Version,
g_CLR_InteropAssembliesNativeData[i]->m_Version.iMajorVersion, g_CLR_InteropAssembliesNativeData[i]->m_Version.iMinorVersion,
g_CLR_InteropAssembliesNativeData[i]->m_Version.iBuildNumber, g_CLR_InteropAssembliesNativeData[i]->m_Version.iRevisionNumber
);
NFVersion::Init(interopNativeAssemblies[index].Version,
g_CLR_InteropAssembliesNativeData[i]->m_Version.iMajorVersion, g_CLR_InteropAssembliesNativeData[i]->m_Version.iMinorVersion,
g_CLR_InteropAssembliesNativeData[i]->m_Version.iBuildNumber, g_CLR_InteropAssembliesNativeData[i]->m_Version.iRevisionNumber
);

index++;
}
}
}

data = (uint8_t*)interopNativeAssemblies;

*size = (sizeof(CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails) * nativeAssembliesCount);
*size = (sizeof(CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails) * count);

return true;
}

static bool GetInteropNativeAssembliesCount( uint8_t* &data, int* size )
{
extern const CLR_RT_NativeAssemblyData *g_CLR_InteropAssembliesNativeData[];

uint16_t nativeAssembliesCount = 0;

// because the Interop assemblies list is assembled during the build we have to count how many are there
for ( int i = 0; g_CLR_InteropAssembliesNativeData[i]; i++ )
{
if (g_CLR_InteropAssembliesNativeData[i] != NULL)
{
nativeAssembliesCount++;
}
}

// alloc buffer to hold the count of available assemblies
data = (uint8_t*)platform_malloc(sizeof(uint16_t));

// check for malloc failure
if(data == NULL)
{
return false;
}

// clear buffer
memset(data, 0, sizeof(uint16_t));

// copy the assemblies count
memcpy(data, (uint8_t*)&nativeAssembliesCount, sizeof(nativeAssembliesCount));

*size = sizeof(nativeAssembliesCount);

return true;
}
Expand All @@ -1180,6 +1244,8 @@ bool CLR_DBG_Debugger::Debugging_Execution_QueryCLRCapabilities( WP_Message* msg
int size = 0;
bool fSuccess = true;
bool freeAllocFlag = false;
uint32_t startIndex = 0;
uint32_t count = 0xFF;

// set the compiler info string here
#if defined(__GNUC__)
Expand All @@ -1192,7 +1258,10 @@ bool CLR_DBG_Debugger::Debugging_Execution_QueryCLRCapabilities( WP_Message* msg

memset(&reply, 0, sizeof(reply));

switch(cmd->m_cmd)
// need to mask the command to get only the lower byte with the command code
uint32_t cmdCode = 0x000000FF & cmd->m_cmd;

switch(cmdCode)
{
case CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags:

Expand Down Expand Up @@ -1304,7 +1373,31 @@ bool CLR_DBG_Debugger::Debugging_Execution_QueryCLRCapabilities( WP_Message* msg
break;

case CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_InteropNativeAssemblies:
if(GetInteropNativeAssemblies(data, &size) == true)

// the start index and count are encoded on the MSBytes of the command, like this: 0xCCSSxxxx
// SS: index of the 1st assembly to list
// CC: how many assemblies to add to the list

// getting the upper bytes (to save on the rotate operations)
startIndex = (cmd->m_cmd >> 16);
// get the count from the above
count = startIndex >> 8;
// now fix the start index by masking the count byte
startIndex &= 0x000000FF;

if(GetInteropNativeAssemblies(data, &size, startIndex, count) == true)
{
// signal need to free memory
freeAllocFlag = true;
}
else
{
fSuccess = false;
}
break;

case CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_InteropNativeAssembliesCount:
if(GetInteropNativeAssembliesCount(data, &size) == true)
{
// signal need to free memory
freeAllocFlag = true;
Expand Down
16 changes: 10 additions & 6 deletions src/CLR/Include/nanoCLR_Debugging.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,18 @@ struct CLR_DBG_Commands
unsigned char m_hash [ 128 ];
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// !!! KEEP IN SYNC WITH nanoFramework.Tools.Debugger.WireProtocol.Commands.Debugging_Execution_QueryCLRCapabilities (in managed code) !!! //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct Debugging_Execution_QueryCLRCapabilities
{
static const CLR_UINT32 c_CapabilityFlags = 1;
static const CLR_UINT32 c_CapabilityVersion = 3;
static const CLR_UINT32 c_HalSystemInfo = 5;
static const CLR_UINT32 c_ClrInfo = 6;
static const CLR_UINT32 c_TargetReleaseInfo = 7;
static const CLR_UINT32 c_InteropNativeAssemblies = 8;
static const CLR_UINT32 c_CapabilityFlags = 1;
static const CLR_UINT32 c_CapabilityVersion = 3;
static const CLR_UINT32 c_HalSystemInfo = 5;
static const CLR_UINT32 c_ClrInfo = 6;
static const CLR_UINT32 c_TargetReleaseInfo = 7;
static const CLR_UINT32 c_InteropNativeAssemblies = 8;
static const CLR_UINT32 c_InteropNativeAssembliesCount = 9;

static const CLR_UINT32 c_CapabilityFlags_FloatingPoint = 0x00000001;
static const CLR_UINT32 c_CapabilityFlags_SourceLevelDebugging = 0x00000002;
Expand Down