vm: remove some mixed use of stdio/iostream. when monotonic timer decreases, log old and new values
parent
352e263de6
commit
14de58b73c
10
vm/debug.cpp
10
vm/debug.cpp
|
@ -377,9 +377,10 @@ void factor_vm::factorbug()
|
|||
char cmd[1024];
|
||||
|
||||
std::cout << "READY\n";
|
||||
fflush(stdout);
|
||||
std::cout.flush();
|
||||
|
||||
if(scanf("%1000s",cmd) <= 0)
|
||||
std::cin >> std::setw(1024) >> cmd >> std::setw(0);
|
||||
if(!std::cin.good())
|
||||
{
|
||||
if(!seen_command)
|
||||
{
|
||||
|
@ -402,7 +403,10 @@ void factor_vm::factorbug()
|
|||
if(strcmp(cmd,"d") == 0)
|
||||
{
|
||||
cell addr = read_cell_hex();
|
||||
if(scanf(" ") < 0) break;
|
||||
if (std::cin.peek() == ' ')
|
||||
std::cin.ignore();
|
||||
|
||||
if(!std::cin.good()) break;
|
||||
cell count = read_cell_hex();
|
||||
dump_memory(addr,addr+count);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <wchar.h>
|
||||
|
||||
/* C++ headers */
|
||||
#include <algorithm>
|
||||
|
@ -27,6 +28,7 @@
|
|||
#include <set>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
#define FACTOR_STRINGIZE(x) #x
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ void early_init(void)
|
|||
Gestalt(gestaltSystemVersion,&version);
|
||||
if(version < 0x1050)
|
||||
{
|
||||
printf("Factor requires Mac OS X 10.5 or later.\n");
|
||||
std::cout << "Factor requires Mac OS X 10.5 or later.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,8 +27,6 @@ typedef char symbol_char;
|
|||
#define FTELL ftello
|
||||
#define FSEEK fseeko
|
||||
|
||||
#define CELL_HEX_FORMAT "%lx"
|
||||
|
||||
#define OPEN_READ(path) fopen(path,"rb")
|
||||
#define OPEN_WRITE(path) fopen(path,"wb")
|
||||
|
||||
|
|
|
@ -57,7 +57,10 @@ BOOL factor_vm::windows_stat(vm_char *path)
|
|||
|
||||
void factor_vm::windows_image_path(vm_char *full_path, vm_char *temp_path, unsigned int length)
|
||||
{
|
||||
SNWPRINTF(temp_path, length-1, L"%s.image", full_path);
|
||||
wcsncpy(temp_path, full_path, length - 1);
|
||||
unsigned full_path_len = wcslen(full_path);
|
||||
if (full_path_len < length - 1)
|
||||
wcsncat(temp_path, L".image", length - full_path_len - 1);
|
||||
temp_path[length - 1] = 0;
|
||||
}
|
||||
|
||||
|
@ -74,7 +77,10 @@ const vm_char *factor_vm::default_image_path()
|
|||
if((ptr = wcsrchr(full_path, '.')))
|
||||
*ptr = 0;
|
||||
|
||||
SNWPRINTF(temp_path, MAX_UNICODE_PATH-1, L"%s.image", full_path);
|
||||
wcsncpy(temp_path, full_path, MAX_UNICODE_PATH - 1);
|
||||
unsigned full_path_len = wcslen(full_path);
|
||||
if (full_path_len < length - 1)
|
||||
wcsncat(temp_path, L".image", MAX_UNICODE_PATH - full_path_len - 1);
|
||||
temp_path[MAX_UNICODE_PATH - 1] = 0;
|
||||
|
||||
return safe_strdup(temp_path);
|
||||
|
|
|
@ -23,18 +23,10 @@ typedef wchar_t vm_char;
|
|||
#define FTELL ftell
|
||||
#define FSEEK fseek
|
||||
#define SNPRINTF _snprintf
|
||||
#define SNWPRINTF _snwprintf
|
||||
#else
|
||||
#define FTELL ftello64
|
||||
#define FSEEK fseeko64
|
||||
#define SNPRINTF snprintf
|
||||
#define SNWPRINTF snwprintf
|
||||
#endif
|
||||
|
||||
#ifdef WIN64
|
||||
#define CELL_HEX_FORMAT "%Ix"
|
||||
#else
|
||||
#define CELL_HEX_FORMAT "%lx"
|
||||
#endif
|
||||
|
||||
#define OPEN_READ(path) _wfopen((path),L"rb")
|
||||
|
|
|
@ -11,7 +11,13 @@ void factor_vm::primitive_exit()
|
|||
void factor_vm::primitive_nano_count()
|
||||
{
|
||||
u64 nanos = nano_count();
|
||||
if(nanos < last_nano_count) critical_error("Monotonic counter decreased",0);
|
||||
if(nanos < last_nano_count) {
|
||||
std::cout << "Monotonic counter decreased from 0x";
|
||||
std::cout << std::hex << last_nano_count;
|
||||
std::cout << " to 0x" << nanos << "." << std::dec << "\n";
|
||||
std::cout << "Please report this error.\n";
|
||||
current_vm()->factorbug();
|
||||
}
|
||||
last_nano_count = nanos;
|
||||
ctx->push(from_unsigned_8(nanos));
|
||||
}
|
||||
|
|
|
@ -14,7 +14,8 @@ vm_char *safe_strdup(const vm_char *str)
|
|||
cell read_cell_hex()
|
||||
{
|
||||
cell cell;
|
||||
if(scanf(CELL_HEX_FORMAT,&cell) < 0) exit(1);
|
||||
std::cin >> std::hex >> cell >> std::dec;
|
||||
if(!std::cin.good()) exit(1);
|
||||
return cell;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue