void CLR_RT_DUMP::TYPE( const CLR_RT_TypeDef_Index& cls ) { NATIVE_PROFILE_CLR_DIAGNOSTICS(); char rgBuffer[ 512 ]; LPSTR szBuffer = rgBuffer; size_t iBuffer = MAXSTRLEN(rgBuffer); g_CLR_RT_TypeSystem.BuildTypeName( cls, szBuffer, iBuffer ); rgBuffer[ MAXSTRLEN(rgBuffer) ] = 0; CLR_Debug::Printf( "%s", rgBuffer ); }
void CodeCoverage::Register( FLASH_WORD* dst, const CLR_RT_MethodDef_Index& md ) { char rgBuffer[ 512 ]; LPSTR szBuffer = rgBuffer; size_t iBuffer = MAXSTRLEN(rgBuffer); g_CLR_RT_TypeSystem.BuildMethodName( md, szBuffer, iBuffer ); RegisterFunction( dst, rgBuffer ); }
void CLR_RT_DUMP::FIELD( const CLR_RT_FieldDef_Index& field ) { NATIVE_PROFILE_CLR_DIAGNOSTICS(); char rgBuffer[ 512 ]; LPSTR szBuffer = rgBuffer; size_t iBuffer = MAXSTRLEN(rgBuffer); g_CLR_RT_TypeSystem.BuildFieldName( field, szBuffer, iBuffer ); CLR_Debug::Printf( "%s", rgBuffer ); }
void CLR_RT_DUMP::METHOD( const CLR_RT_MethodDef_Index& method ) { NATIVE_PROFILE_CLR_DIAGNOSTICS(); char rgBuffer[ 512 ]; LPSTR szBuffer = rgBuffer; size_t iBuffer = MAXSTRLEN(rgBuffer); g_CLR_RT_TypeSystem.BuildMethodName( method, szBuffer, iBuffer ); CLR_Debug::Printf( "%s", rgBuffer ); }
int CLR_Debug::PrintfV( const char *format, va_list arg ) { NATIVE_PROFILE_CLR_DIAGNOSTICS(); #if defined(PLATFORM_WINDOWS) char buffer[2048]; #else char buffer[512]; #endif LPSTR szBuffer = buffer; size_t iBuffer = MAXSTRLEN(buffer); bool fRes = CLR_SafeSprintfV( szBuffer, iBuffer, format, arg ); _ASSERTE(fRes); iBuffer = MAXSTRLEN(buffer) - iBuffer; Emit( buffer, (int)iBuffer ); return (int)iBuffer; }
HRESULT Library_corlib_native_System_RuntimeType::GetName( CLR_RT_HeapBlock& arg, bool fFullName, CLR_RT_HeapBlock& res ) { NATIVE_PROFILE_CLR_CORE(); TINYCLR_HEADER(); CLR_RT_TypeDef_Instance td; CLR_UINT32 levels; char rgBuffer[ 256 ]; LPSTR szBuffer; size_t iBuffer; TINYCLR_CHECK_HRESULT(GetTypeDescriptor( arg, td, &levels )); szBuffer = rgBuffer; iBuffer = MAXSTRLEN(rgBuffer); TINYCLR_CHECK_HRESULT(g_CLR_RT_TypeSystem.BuildTypeName( td, szBuffer, iBuffer, fFullName ? CLR_RT_TypeSystem::TYPENAME_FLAGS_FULL : 0, levels )); TINYCLR_SET_AND_LEAVE(CLR_RT_HeapBlock_String::CreateInstance( res, rgBuffer )); TINYCLR_NOCLEANUP(); }
//--// int CLR_GFX_Font::StringOut( LPCSTR str, int maxChars, CLR_INT32 kerning, CLR_GFX_Bitmap* bm, int xPos, int yPos, CLR_UINT32 color ) { NATIVE_PROFILE_CLR_GRAPHICS(); CLR_RT_UnicodeHelper uh; uh.SetInputUTF8( str ); CLR_UINT16 buf[ 3 ]; CLR_UINT32 nTotWidth = 0; CLR_GFX_FontCharacterInfo chr; yPos += m_font.m_metrics.m_offset; while(maxChars-- != 0) { uh.m_outputUTF16 = buf; uh.m_outputUTF16_size = MAXSTRLEN(buf); if(uh.ConvertFromUTF8( 1, false ) == false) break; CLR_UINT16 c = buf[ 0 ]; GetCharInfo( c, chr ); if(chr.isValid) { //It doesn't look like we support kerning?? _ASSERTE(c_DefaultKerning == kerning); int nOffset = ((nTotWidth + (chr.width+1)/2) * kerning / c_DefaultKerning) - (chr.width+1)/2; nTotWidth = nOffset + chr.width; if(bm) { DrawChar( bm, chr, xPos + chr.marginLeft + nOffset, yPos, color ); } } } return xPos + nTotWidth; }
HRESULT ArmEmulator::Execute( CLR_UINT64 steps ) { TINYCLR_HEADER(); // // Prepare Interop detours. // { for(AddressToHandlerMapIter it = m_callInterop.begin(); it != m_callInterop.end(); it++) { ApplyInterop( it->second ); } } m_fStopExecution = false; for(CLR_UINT64 i=0; i<steps; i++) { CLR_UINT32 pc = m_pc; CLR_UINT32 instruction; bool fRes; // // Special case: if we pass by the reset vector, reload the interop breakpoints. // if(pc == 0) { for(AddressToHandlerMapIter it = m_callInterop.begin(); it != m_callInterop.end(); it++) { ApplyInterop( it->second ); } } { if(MemoryLoad( pc, instruction, DATATYPE_U4 ) == false) { CLR_Debug::Printf( "FETCH ABORT at 0x%08x %I64d\r\n", pc, i ); TINYCLR_SET_AND_LEAVE(CLR_E_FAIL) } } #if defined(ARMEMULATOR_MONITOR_CALLS) if(m_fMonitorCalls) { CLR_RT_AddressToSymbolMapIter it; size_t pos = m_callQueue.size(); CLR_UINT32 sp = m_registers[ ArmProcessor::c_register_sp ]; for(size_t pos2=pos; pos2-- > 0; ) { TrackCall& tc = m_callQueue[ pos2 ]; if((tc.m_lr == pc && tc.m_sp == sp) || (tc.m_sp && tc.m_sp < sp)) { while(pos-- > pos2) { TrackCall& tc2 = m_callQueue[ pos ]; tc2.m_te.End( this ); CLR_Debug::Printf( "%*s<<<< CALL %S (%s)\r\n", pos, "", tc2.m_name->c_str(), tc2.m_te.ToString() ); m_callQueue.pop_back(); } pos++; } else { break; } } it = m_symdef_Inverse.find( pc ); if(it != m_symdef_Inverse.end()) { while(true) { if(it->second == L"NoClearZI_ER_RAM") break; if(it->second == L"ClearZI_ER_RAM" ) break; if(it->second == L"ARM_Vectors" ) break; m_callQueue.resize( pos + 1 ); TrackCall& tc = m_callQueue[ pos ]; tc.m_pc = pc; tc.m_lr = m_registers[ ArmProcessor::c_register_lr ]; tc.m_sp = sp; tc.m_name = &it->second; tc.m_te.Start( this ); CLR_Debug::Printf( "%*s>>>> CALL %S\r\n", pos, "", tc.m_name->c_str() ); break; } } } #endif //--//--//--//--//--//--//--//--//--//--//--// if(instruction == c_InteropOpcode) { // // Copy, not reference, the entry can be removed from the map by the interop code. // TrackInterop ti = m_callInterop[ pc ]; if(m_fStopExecution) { break; } if(ti.m_call) { if((this->*(ti.m_call))()) continue; instruction = ti.m_op; } if(m_fStopExecution) { break; } } //--//--//--//--//--//--//--//--//--//--//--// #if defined(ARMEMULATOR_MONITOR_OPCODES) if(m_fMonitorOpcodes) { ArmProcessor::Opcode op; char rgBuf[ 128 ]; op.InitText( rgBuf, MAXSTRLEN(rgBuf), pc ); if(op.Decode( instruction ) == false) { CLR_Debug::Printf( "DECODE ABORT at 0x%08x %I64d\r\n", pc, i ); TINYCLR_SET_AND_LEAVE(CLR_E_FAIL) } fRes = op.CheckConditions( *this ); op.AppendText( "%-9I64d %-9I64d 0x%08x: %08x %c%c%c%c %c ", i, m_clockTicks, pc, instruction, Negative() ? 'N' : '-', Zero() ? 'Z' : '-', Carry() ? 'C' : '-', Overflow() ? 'V' : '-', fRes ? ' ' : '*' ); op.Print(); CLR_Debug::Printf( "%s\r\n", rgBuf ); }
LPCSTR CLR_RT_DUMP::GETERRORMESSAGE( HRESULT hrError ) { NATIVE_PROFILE_CLR_DIAGNOSTICS(); #define CASE_HRESULT_TO_STRING(hr) case hr: return #hr switch(hrError) { CASE_HRESULT_TO_STRING(CLR_E_UNKNOWN_INSTRUCTION); CASE_HRESULT_TO_STRING(CLR_E_UNSUPPORTED_INSTRUCTION); CASE_HRESULT_TO_STRING(CLR_E_STACK_OVERFLOW); CASE_HRESULT_TO_STRING(CLR_E_STACK_UNDERFLOW); CASE_HRESULT_TO_STRING(CLR_E_ENTRY_NOT_FOUND); CASE_HRESULT_TO_STRING(CLR_E_ASSM_WRONG_CHECKSUM); CASE_HRESULT_TO_STRING(CLR_E_ASSM_PATCHING_NOT_SUPPORTED); CASE_HRESULT_TO_STRING(CLR_E_SHUTTING_DOWN); CASE_HRESULT_TO_STRING(CLR_E_OBJECT_DISPOSED); CASE_HRESULT_TO_STRING(CLR_E_WATCHDOG_TIMEOUT); CASE_HRESULT_TO_STRING(CLR_E_NULL_REFERENCE); CASE_HRESULT_TO_STRING(CLR_E_WRONG_TYPE); CASE_HRESULT_TO_STRING(CLR_E_TYPE_UNAVAILABLE); CASE_HRESULT_TO_STRING(CLR_E_INVALID_CAST); CASE_HRESULT_TO_STRING(CLR_E_OUT_OF_RANGE); CASE_HRESULT_TO_STRING(CLR_E_SERIALIZATION_VIOLATION); CASE_HRESULT_TO_STRING(CLR_E_SERIALIZATION_BADSTREAM); CASE_HRESULT_TO_STRING(CLR_E_DIVIDE_BY_ZERO); CASE_HRESULT_TO_STRING(CLR_E_BUSY); CASE_HRESULT_TO_STRING(CLR_E_PROCESS_EXCEPTION); CASE_HRESULT_TO_STRING(CLR_E_THREAD_WAITING); CASE_HRESULT_TO_STRING(CLR_E_LOCK_SYNCHRONIZATION_EXCEPTION); CASE_HRESULT_TO_STRING(CLR_E_APPDOMAIN_EXITED); CASE_HRESULT_TO_STRING(CLR_E_APPDOMAIN_MARSHAL_EXCEPTION); CASE_HRESULT_TO_STRING(CLR_E_UNKNOWN_TYPE); CASE_HRESULT_TO_STRING(CLR_E_ARGUMENT_NULL); CASE_HRESULT_TO_STRING(CLR_E_IO); CASE_HRESULT_TO_STRING(CLR_E_ENTRYPOINT_NOT_FOUND); CASE_HRESULT_TO_STRING(CLR_E_DRIVER_NOT_REGISTERED); CASE_HRESULT_TO_STRING(CLR_E_PIN_UNAVAILABLE); CASE_HRESULT_TO_STRING(CLR_E_PIN_DEAD); CASE_HRESULT_TO_STRING(CLR_E_INVALID_OPERATION); CASE_HRESULT_TO_STRING(CLR_E_WRONG_INTERRUPT_TYPE); CASE_HRESULT_TO_STRING(CLR_E_NO_INTERRUPT); CASE_HRESULT_TO_STRING(CLR_E_DISPATCHER_ACTIVE); CASE_HRESULT_TO_STRING(CLR_E_FILE_IO); CASE_HRESULT_TO_STRING(CLR_E_INVALID_DRIVER); CASE_HRESULT_TO_STRING(CLR_E_FILE_NOT_FOUND); CASE_HRESULT_TO_STRING(CLR_E_DIRECTORY_NOT_FOUND); CASE_HRESULT_TO_STRING(CLR_E_VOLUME_NOT_FOUND); CASE_HRESULT_TO_STRING(CLR_E_PATH_TOO_LONG); CASE_HRESULT_TO_STRING(CLR_E_DIRECTORY_NOT_EMPTY); CASE_HRESULT_TO_STRING(CLR_E_UNAUTHORIZED_ACCESS); CASE_HRESULT_TO_STRING(CLR_E_PATH_ALREADY_EXISTS); CASE_HRESULT_TO_STRING(CLR_E_TOO_MANY_OPEN_HANDLES); CASE_HRESULT_TO_STRING(CLR_E_NOT_SUPPORTED); CASE_HRESULT_TO_STRING(CLR_E_RESCHEDULE); CASE_HRESULT_TO_STRING(CLR_E_OUT_OF_MEMORY); CASE_HRESULT_TO_STRING(CLR_E_RESTART_EXECUTION); CASE_HRESULT_TO_STRING(CLR_E_TIMEOUT); CASE_HRESULT_TO_STRING(CLR_E_FAIL); //--// CASE_HRESULT_TO_STRING(CLR_S_THREAD_EXITED); CASE_HRESULT_TO_STRING(CLR_S_QUANTUM_EXPIRED); CASE_HRESULT_TO_STRING(CLR_S_NO_READY_THREADS); CASE_HRESULT_TO_STRING(CLR_S_NO_THREADS); CASE_HRESULT_TO_STRING(CLR_S_RESTART_EXECUTION); } #undef CASE_HRESULT_TO_STRING static char s_tmp[ 32 ]; hal_snprintf( s_tmp, MAXSTRLEN(s_tmp), "0x%08x", hrError ); return s_tmp; }
void CLR_Debug::Emit( const char *text, int len ) { NATIVE_PROFILE_CLR_DIAGNOSTICS(); static char s_buffer[ 128 ]; static int s_chars = 0; if(len == -1) len = (int)hal_strlen_s( text ); #if defined(PLATFORM_WINDOWS) if(s_redirectedString) { s_redirectedString->append( text, len ); return; } if(s_CLR_RT_fTrace_RedirectOutput.size()) { static HANDLE hFile = INVALID_HANDLE_VALUE; static int lines = 0; static int num = 0; if(hFile == INVALID_HANDLE_VALUE) { std::wstring file = s_CLR_RT_fTrace_RedirectOutput; if(s_CLR_RT_fTrace_RedirectLinesPerFile) { WCHAR rgBuf[ 64 ]; swprintf( rgBuf, ARRAYSIZE(rgBuf), L".%08d", num++ ); file.append( rgBuf ); } hFile = ::CreateFileW( file.c_str(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0 ); lines = 0; } if(hFile != INVALID_HANDLE_VALUE) { DWORD dwWritten; ::WriteFile( hFile, text, (DWORD)len, &dwWritten, NULL ); if(s_CLR_RT_fTrace_RedirectLinesPerFile) { while((text = strchr( text, '\n' )) != NULL) { lines++; text++; if(text[ 0 ] == 0) { if(lines > s_CLR_RT_fTrace_RedirectLinesPerFile) { ::CloseHandle( hFile ); hFile = INVALID_HANDLE_VALUE; } break; } } } return; } } #endif while(len > 0) { int avail = MAXSTRLEN(s_buffer) - s_chars; if(len < avail) avail = len; memcpy( &s_buffer[ s_chars ], text, avail ); s_chars += avail; text += avail; len -= avail; s_buffer[ s_chars ] = 0; if(s_chars > 80 || strchr( s_buffer, '\n' )) { ::Watchdog_ResetCounter(); #if defined(PLATFORM_WINDOWS) || defined(PLATFORM_WINCE) HAL_Windows_Debug_Print( s_buffer ); #endif if(CLR_EE_DBG_IS( Enabled ) && !CLR_EE_DBG_IS( Quiet )) { CLR_EE_DBG_EVENT_BROADCAST( CLR_DBG_Commands::c_Monitor_Message, s_chars, s_buffer, WP_Flags::c_NonCritical | WP_Flags::c_NoCaching ); } if(!CLR_EE_DBG_IS( Enabled ) || HalSystemConfig.DebugTextPort != HalSystemConfig.DebuggerPorts[ 0 ]) { #if !defined(PLATFORM_WINDOWS) && !defined(PLATFORM_WINCE) DebuggerPort_Write( HalSystemConfig.DebugTextPort, s_buffer, s_chars ); // skip null terminator DebuggerPort_Flush( HalSystemConfig.DebugTextPort ); // skip null terminator #endif } s_chars = 0; } } }