Exemplo n.º 1
0
 void VMThread::setNameFrom(const char* name)
 {
     size_t nameLength = VMPI_strlen(name);
     char* buf = new char[nameLength + 1];
     VMPI_strncpy(buf, name, nameLength + 1);
     m_name = buf;
 }
Exemplo n.º 2
0
static int setenv_with_putenv(const char *name, const char *value)
{
    if(NULL != VMPI_strchr(name, '='))
    {
        errno = EINVAL;
        return -1;
    }
    else
    {
        size_t  nameLen     =   VMPI_strlen(name);
        size_t  valueLen    =   VMPI_strlen(value);
        size_t  required    =   1 + nameLen + 1 + valueLen;
        char    buffer_[101];
        char    *buffer     =   (ARRAY_SIZE(buffer_) < required)
                                    ? (char*)malloc(required * sizeof(char))
                                    : &buffer_[0];

        if(NULL == buffer)
        {
            errno = ENOMEM;
            return -1;
        }
        else
        {
            int r;
            (void)VMPI_strncpy(&buffer[0], name, nameLen);
            buffer[nameLen] = '=';
            buffer[nameLen + 1] = '\0';
            (void)VMPI_strncpy(&buffer[nameLen + 1], value, valueLen);
            buffer[nameLen + 1 + valueLen] = '\0';

            r = _putenv(&buffer[0]);

            if(buffer != &buffer_[0])
            {
                VMPI_free(buffer);
            }

            return r;
        }
    }
}
Exemplo n.º 3
0
 char* string2char(AvmCore* core, Stringp str)
 {
     if (!str->length()) return 0;
     StringNullTerminatedUTF8 s(core->gc, str);
     const char* cstr = s.c_str();
     size_t max = VMPI_strlen(cstr);
     char* to = (char*)malloc((max+1)*sizeof(char));
     VMPI_strncpy(to,cstr,max);
     to[max]='\0';
     return to;
 }
Exemplo n.º 4
0
static char* f (double d)
{
    static char s[80];
    char* p;
    sprintf_s (s, sizeof(s), "%lf", d);
    p = s+VMPI_strlen(s)-1;
    while (*p == '0') {
        *p = '\0';
        p--;
        if (p == s) break;
    }
    if (*p == '.') *p = '\0';
    return s;
}
Exemplo n.º 5
0
    bool AVMPI_getFileAndLineInfoFromPC(uintptr_t pc, char *filenameBuffer, size_t bufferSize, uint32_t* lineNumber)
    {
#ifdef UNDER_CE
        (void)pc;
        (void)lineNumber;
        (void)filenameBuffer;
        (void)bufferSize;

        return false;
#else
        if(!InitDbgHelp())
            return false;

        // gleaned from IMAGEHLP_SYMBOL64 docs
        IMAGEHLP_SYMBOL64 *pSym = (IMAGEHLP_SYMBOL64 *) alloca(sizeof(IMAGEHLP_SYMBOL64) + MaxNameLength);
        pSym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
        pSym->MaxNameLength = MaxNameLength;

        DWORD64 offsetFromSymbol;
        if(!g_DbgHelpDll.m_SymGetSymFromAddr64 ||
            !(*g_DbgHelpDll.m_SymGetSymFromAddr64)(GetCurrentProcess(), pc, &offsetFromSymbol, pSym)) {
                return false;
        }

        // get line
        IMAGEHLP_LINE64 line;
        VMPI_memset(&line, 0, sizeof(IMAGEHLP_LINE64));
        line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
        DWORD offsetFromLine;
        if(!g_DbgHelpDll.m_SymGetLineFromAddr64 ||
            !(*g_DbgHelpDll.m_SymGetLineFromAddr64)(GetCurrentProcess(), pc, &offsetFromLine, &line)) {
                return false;
        }


        // success!
        char *fileName = line.FileName + VMPI_strlen(line.FileName);

        // skip everything up to last slash
        while(fileName > line.FileName && *fileName != '\\')
            fileName--;
        fileName++;

        StringCchPrintfA(filenameBuffer, bufferSize, "%s", fileName);
        *lineNumber = line.LineNumber;

        return true;
#endif // UNDER_CE
    }
Exemplo n.º 6
0
        void WinPlatform::initializeLogging(const char* filename)
        {
        #if defined (UNDER_CE)
            int filenameLen = VMPI_strlen(filename);

            TCHAR* logname = new TCHAR[filenameLen+1];

            mbstowcs(logname, filename, filenameLen+1);

            _wfreopen(logname, L"w", stdout);

            delete [] logname;
        #else
            FILE *f = freopen(filename, "w", stdout);
            if (!f)
                AvmLog("freopen %s failed.\n",filename);
        #endif /* UNDER_CE */
        }
Exemplo n.º 7
0
    void RegAlloc::formatRegisters(char* s, Fragment *frag)
    {
        if (!frag || !frag->lirbuf)
            return;
        LirNameMap *names = frag->lirbuf->names;
        for (Register r = FirstReg; r <= LastReg; r = nextreg(r))
        {
            LIns *ins = getActive(r);
            if (!ins)
                continue;
            NanoAssertMsg(!isFree(r), "Coding error; register is both free and active! " );

            if (ins->isop(LIR_param) && ins->paramKind()==1 && r == Assembler::savedRegs[ins->paramArg()]) {
                // dont print callee-saved regs that arent used
                continue;
            }

            s += VMPI_strlen(s);
            const char* rname = ins->isQuad() ? fpn(r) : gpn(r);
            VMPI_sprintf(s, " %s(%s)", rname, names->formatRef(ins));
        }
    }
Exemplo n.º 8
0
	void DebugCLI::enterDebugger()
	{	
		setCurrentSource( (core->callStack) ? (core->callStack->filename()) : 0 );

		for (;;) {
			printIP();
			
			core->console << "(asdb) ";
			Platform::GetInstance()->getUserInput(commandLine, kMaxCommandLine);

			commandLine[VMPI_strlen(commandLine)-1] = 0;
			
			if (!commandLine[0]) {
				VMPI_strcpy(commandLine, lastCommand);
			} else {
				VMPI_strcpy(lastCommand, commandLine);
			}
				
			currentToken = commandLine;
		
			char *command = nextToken();
			int cmd = commandFor(command);

			switch (cmd) {
			case -1:
				// ambiguous, we already printed error message
				break;
			case CMD_INFO:
				info();
				break;
			case CMD_BREAK:
				breakpoint(nextToken());
				break;
			case CMD_DELETE:
				deleteBreakpoint(nextToken());
				break;
			case CMD_LIST:
				list(nextToken());
				break;
			case CMD_UNKNOWN:
				core->console << "Unknown command.\n";
				break;
			case CMD_QUIT:
				Platform::GetInstance()->exit(0);
				break;
			case CMD_CONTINUE:
				return;
			case CMD_PRINT:
				print(nextToken());
				break;
			case CMD_NEXT:
				stepOver();
				return;
			case INFO_STACK_CMD:
				bt();
				break;
			case CMD_FINISH:
				stepOut();
				return;
			case CMD_STEP:
				stepInto();
				return;
			case CMD_SET:
				set();
				break;
			default:
				core->console << "Command not implemented.\n";
				break;
			}
		}
	}
Exemplo n.º 9
0
	/**
	 * Attempt to match given the given string against our set of commands
	 * @return the command code that was hit.
	 */
	int DebugCLI::determineCommand(DebugCLI::StringIntArray cmdList[],
								   const char *input,
								   int defCmd)
	{
        if (!input) return INFO_UNKNOWN_CMD;
        
		int inputLen = (int)VMPI_strlen(input);
		
		// first check for a comment
		if (input[0] == '#') {
			return CMD_COMMENT;
		}

		int match = -1;
		bool ambiguous = false;
		
		for (int i=0; cmdList[i].text; i++) {
			if (!VMPI_strncmp(input, cmdList[i].text, inputLen)) {
				if (match != -1) {
					ambiguous = true;
					break;
				}
				match = i;
			}
		}

		/**
		 * 3 cases:
		 *  - No hits, return unknown and let our caller
		 *    dump the error.
		 *  - We match unambiguously or we have 1 or more matches
		 *    and the input is a single character. We then take the
		 *    first hit as our command.
		 *  - If we have multiple hits then we dump a 'ambiguous' message
		 *    and puke quietly.
		 */
		if (match == -1) {
			// no command match return unknown
			return defCmd;
		}
		// only 1 match or our input is 1 character or first match is exact
		else if (!ambiguous || inputLen == 1 || !VMPI_strcmp(cmdList[match].text, input)) {
			return cmdList[match].id;
		}
		else {
			// matches more than one command dump message and go
			core->console << "Ambiguous command '" << input << "': ";
			bool first = true;
			for (int i=0; cmdList[i].text; i++) {
				if (!VMPI_strncmp(cmdList[i].text, input, inputLen)) {
					if (!first) {
						core->console << ", ";
					} else {
						first = false;
					}
					core->console << cmdList[i].text;
				}
			}
			core->console << ".\n";
			return -1;
		}
	}