Skip to content

Commit

Permalink
Updated code implementation of reports about the debugger.
Browse files Browse the repository at this point in the history
  • Loading branch information
ax-6 committed Jul 7, 2024
1 parent 13b23e0 commit c4e4015
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 56 deletions.
4 changes: 2 additions & 2 deletions aq/aq.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
int main(int argc, char *argv[]) {
// TODO(Aqvm): Finish this function after completing AQVM development.
if (Aqvm_InitVm() != 0) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
2, "Aqmain_InitVmError", "Initializing Aqvm met error.", NULL});
AqvmRuntimeDebugger_OutputReport(2, "Aqmain_InitVmError",
"Initializing Aqvm met error.", NULL);
return -1;
}
return 0;
Expand Down
82 changes: 36 additions & 46 deletions aqvm/memory/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,51 @@
int AqvmMemory_CheckMemoryConditions() {
int warning_count = 0;
if (sizeof(aqint) != 4) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
AqvmRuntimeDebugger_OutputReport(
1, "AqvmMemoryCheckMemoryConditions_IntLengthWarning",
"The length requirement for the int type does not conform to the type "
"definition.",
NULL});
NULL);
++warning_count;
}
if (sizeof(aqlong) != 8) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
AqvmRuntimeDebugger_OutputReport(
1, "AqvmMemoryCheckMemoryConditions_LongLengthWarning",
"The length requirement for the long type does not conform to the type "
"definition.",
NULL});
NULL);
++warning_count;
}
if (sizeof(aqfloat) != 4) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
AqvmRuntimeDebugger_OutputReport(
1, "AqvmMemoryCheckMemoryConditions_FloatLengthWarning",
"The length requirement for the float type does not conform to the "
"type definition.",
NULL});
NULL);
++warning_count;
}
if (sizeof(aqdouble) != 4) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
AqvmRuntimeDebugger_OutputReport(
1, "AqvmMemoryCheckMemoryConditions_DoubleLengthWarning",
"The length requirement for the double type does not conform to the "
"type definition.",
NULL});
NULL);
++warning_count;
}
if (sizeof(aqchar) != 1) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
AqvmRuntimeDebugger_OutputReport(
1, "AqvmMemoryCheckMemoryConditions_CharLengthWarning",
"The length requirement for the char type does not conform to the type "
"definition.",
NULL});
NULL);
++warning_count;
}
if (sizeof(aqbool) != 1) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
AqvmRuntimeDebugger_OutputReport(
1, "AqvmMemoryCheckMemoryConditions_BoolLengthWarning",
"The length requirement for the bool type does not conform to the type "
"definition.",
NULL});
NULL);
++warning_count;
}

Expand All @@ -71,9 +71,9 @@ struct AqvmMemory_Memory* AqvmMemory_CreateMemory(void* data, void* type,
struct AqvmMemory_Memory* memory_ptr =
(struct AqvmMemory_Memory*)malloc(sizeof(struct AqvmMemory_Memory));
if (memory_ptr == NULL) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
AqvmRuntimeDebugger_OutputReport(
2, "AqvmMemoryCreateMemory_MemoryAllocationFailure",
"Failed to allocate memory.", NULL});
"Failed to allocate memory.", NULL);
return NULL;
}

Expand All @@ -91,30 +91,26 @@ void AqvmMemory_FreeMemory(struct AqvmMemory_Memory* memory_ptr) {
int AqvmMemory_SetType(const struct AqvmMemory_Memory* memory, size_t index,
uint8_t type) {
if (memory == NULL) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
1, "AqvmMemorySetType_NullMemoryPointer", "The memory pointer is NULL.",
NULL});
AqvmRuntimeDebugger_OutputReport(1, "AqvmMemorySetType_NullMemoryPointer",
"The memory pointer is NULL.", NULL);
return -1;
}

if (memory->type == NULL) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
1, "AqvmMemorySetType_NullTypePointer", "The type pointer is NULL.",
NULL});
AqvmRuntimeDebugger_OutputReport(1, "AqvmMemorySetType_NullTypePointer",
"The type pointer is NULL.", NULL);
return -2;
}

if (index > memory->size) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
1, "AqvmMemorySetType_OutOfMemoryRange",
"The index is out of memory range.", NULL});
AqvmRuntimeDebugger_OutputReport(1, "AqvmMemorySetType_OutOfMemoryRange",
"The index is out of memory range.", NULL);
return -3;
}

if (type > 0x0F) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
1, "AqvmMemorySetType_OutOfTypeRange", "The type is out of range.",
NULL});
AqvmRuntimeDebugger_OutputReport(1, "AqvmMemorySetType_OutOfTypeRange",
"The type is out of range.", NULL);
return -4;
}

Expand All @@ -129,23 +125,20 @@ int AqvmMemory_SetType(const struct AqvmMemory_Memory* memory, size_t index,

uint8_t AqvmMemory_GetType(struct AqvmMemory_Memory* memory, size_t index) {
if (memory == NULL) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
1, "AqvmMemoryGetType_NullMemoryPointer", "The memory pointer is NULL.",
NULL});
AqvmRuntimeDebugger_OutputReport(1, "AqvmMemoryGetType_NullMemoryPointer",
"The memory pointer is NULL.", NULL);
return 0x11;
}

if (memory->type == NULL) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
1, "AqvmMemoryGetType_NullTypePointer", "The type pointer is NULL.",
NULL});
AqvmRuntimeDebugger_OutputReport(1, "AqvmMemoryGetType_NullTypePointer",
"The type pointer is NULL.", NULL);
return 0x12;
}

if (index > memory->size) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
1, "AqvmMemoryGetType_OutOfMemoryRange",
"The index is out of memory range.", NULL});
AqvmRuntimeDebugger_OutputReport(1, "AqvmMemoryGetType_OutOfMemoryRange",
"The index is out of memory range.", NULL);
return 0x13;
}

Expand All @@ -159,29 +152,26 @@ uint8_t AqvmMemory_GetType(struct AqvmMemory_Memory* memory, size_t index) {
int AqvmMemory_WriteData(struct AqvmMemory_Memory* memory, size_t index,
void* data_ptr, size_t size) {
if (memory == NULL) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
1, "AqvmMemoryWriteData_NullMemoryPointer",
"The memory pointer is NULL.", NULL});
AqvmRuntimeDebugger_OutputReport(1, "AqvmMemoryWriteData_NullMemoryPointer",
"The memory pointer is NULL.", NULL);
return -1;
}

if (memory->type == NULL) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
1, "AqvmMemoryWriteData_NullTypePointer", "The type pointer is NULL.",
NULL});
AqvmRuntimeDebugger_OutputReport(1, "AqvmMemoryWriteData_NullTypePointer",
"The type pointer is NULL.", NULL);
return -2;
}

if (index > memory->size) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
1, "AqvmMemoryWriteData_OutOfMemoryRange",
"The index is out of memory range.", NULL});
AqvmRuntimeDebugger_OutputReport(1, "AqvmMemoryWriteData_OutOfMemoryRange",
"The index is out of memory range.", NULL);
return -3;
}

if (data_ptr == NULL) {
AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){
1, "AqvmMemoryWriteData_NullDataPointer", "The data pointer is NULL.", NULL});
AqvmRuntimeDebugger_OutputReport(1, "AqvmMemoryWriteData_NullDataPointer",
"The data pointer is NULL.", NULL);
return -4;
}

Expand Down
22 changes: 14 additions & 8 deletions aqvm/runtime/debugger/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ struct AqvmRuntimeDebugger_DebugReport {

// Outputs |report| with time, errno and so on to printing to the console or
// other devices and writing to a log file. No return.
// NOTICE: The output is json format.
void AqvmRuntimeDebugger_OutputReport(
struct AqvmRuntimeDebugger_DebugReport report);
// |type| is the type of the report. In |type|, 0 is INFO, 1 is WARNING, and 2
// is ERROR. |type|, |code|, and |message| are necessary and shouldn't be set to
// NULL in common. |other_info| is a pointer to the other information and it can
// be set to NULL if it is not needed.
// NOTICE: If you need to use it, please use json format. The output is json
// format.
void AqvmRuntimeDebugger_OutputReport(uint8_t type, const char* code,
const char* message,
const char* other_info);

// INTERNAL USE ONLY.
// Gets the current time in a string format based on ISO 8601 standard and
Expand All @@ -34,11 +40,11 @@ void AqvmRuntimeDebugger_OutputReport(
void AqvmRuntimeDebugger_GetCurrentTime(char* return_time);

// INTERNAL USE ONLY.
// Formats |report| and returns type string accroding to the type in |report|.
// If code, message, or other_info are NULL, They will be set to the string
// "NULL".
// If |code|, |message|, or |other_info| is NULL, It will be set to the string
// "NULL". Returns type string accroding to the |type|.
// NOTICE: The output is json format.
const char* AqvmRuntimeDebugger_FormatReport(
struct AqvmRuntimeDebugger_DebugReport* report);
const char* AqvmRuntimeDebugger_FormatReport(uint8_t type, const char* code,
const char* message,
const char* other_info);

#endif

0 comments on commit c4e4015

Please sign in to comment.