Expose diagnostic messages in formatters
This commit is contained in:
parent
ef3edc7762
commit
5438b93efd
|
|
@ -28,6 +28,17 @@ const char *amduat_format_pel_store_error_name(
|
|||
const char *amduat_format_pel_kernel_kind_name(
|
||||
amduat_pel_kernel_op_kind_t kind);
|
||||
|
||||
bool amduat_format_diagnostics_text(
|
||||
FILE *stream,
|
||||
const char *prefix,
|
||||
const amduat_pel_diagnostic_entry_t *diags,
|
||||
size_t diags_len);
|
||||
|
||||
bool amduat_format_diagnostics_json(
|
||||
FILE *stream,
|
||||
const amduat_pel_diagnostic_entry_t *diags,
|
||||
size_t diags_len);
|
||||
|
||||
bool amduat_format_pel_program(FILE *stream,
|
||||
const amduat_pel_program_t *program,
|
||||
amduat_format_output_t format);
|
||||
|
|
|
|||
|
|
@ -108,7 +108,25 @@ static char *amduat_format_hex_encode(amduat_octets_t bytes) {
|
|||
return hex;
|
||||
}
|
||||
|
||||
static bool amduat_format_diagnostics_text(
|
||||
static bool amduat_is_printable_ascii(amduat_octets_t bytes) {
|
||||
size_t i;
|
||||
|
||||
if (bytes.len == 0) {
|
||||
return true;
|
||||
}
|
||||
if (bytes.data == NULL) {
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < bytes.len; ++i) {
|
||||
uint8_t c = bytes.data[i];
|
||||
if (c < 0x20u || c > 0x7eu) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool amduat_format_diagnostics_text(
|
||||
FILE *stream,
|
||||
const char *prefix,
|
||||
const amduat_pel_diagnostic_entry_t *diags,
|
||||
|
|
@ -130,12 +148,17 @@ static bool amduat_format_diagnostics_text(
|
|||
fprintf(stream, "%sdiagnostic[%zu].code=%u\n", prefix, i, diags[i].code);
|
||||
fprintf(stream, "%sdiagnostic[%zu].message_hex=%s\n",
|
||||
prefix, i, msg_hex);
|
||||
if (amduat_is_printable_ascii(diags[i].message)) {
|
||||
fprintf(stream, "%sdiagnostic[%zu].message=%.*s\n",
|
||||
prefix, i, (int)diags[i].message.len,
|
||||
(const char *)diags[i].message.data);
|
||||
}
|
||||
free(msg_hex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool amduat_format_diagnostics_json(
|
||||
bool amduat_format_diagnostics_json(
|
||||
FILE *stream,
|
||||
const amduat_pel_diagnostic_entry_t *diags,
|
||||
size_t diags_len) {
|
||||
|
|
@ -156,6 +179,13 @@ static bool amduat_format_diagnostics_json(
|
|||
free(msg_hex);
|
||||
return false;
|
||||
}
|
||||
if (amduat_is_printable_ascii(diags[i].message)) {
|
||||
fputs(",\"message\":", stream);
|
||||
if (!amduat_format_json_escape(stream, diags[i].message)) {
|
||||
free(msg_hex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
fputs("}", stream);
|
||||
free(msg_hex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -878,6 +878,15 @@ static int amduat_pel_cli_cmd_exec(int argc,
|
|||
(unsigned int)result.summary.kind);
|
||||
fprintf(out_stream, "status_code=%u\n",
|
||||
(unsigned int)result.summary.status_code);
|
||||
fprintf(out_stream, "diagnostics_len=%zu\n", result.diagnostics_len);
|
||||
if (!amduat_format_diagnostics_text(out_stream,
|
||||
"",
|
||||
result.diagnostics,
|
||||
result.diagnostics_len)) {
|
||||
fprintf(stderr, "error: failed to format diagnostics\n");
|
||||
exit_code = AMDUAT_PEL_CLI_EXIT_CODEC;
|
||||
goto exec_cleanup;
|
||||
}
|
||||
fprintf(out_stream, "outputs_len=%zu\n", outputs_len);
|
||||
for (i = 0; i < (int)outputs_len; ++i) {
|
||||
fprintf(out_stream, "output_path[%d]=%s/output-%d\n",
|
||||
|
|
@ -899,6 +908,14 @@ static int amduat_pel_cli_cmd_exec(int argc,
|
|||
result.summary.kind))));
|
||||
fprintf(out_stream, ",\"error_kind_code\":%u",
|
||||
(unsigned int)result.summary.kind);
|
||||
fputs(",\"diagnostics\":", out_stream);
|
||||
if (!amduat_format_diagnostics_json(out_stream,
|
||||
result.diagnostics,
|
||||
result.diagnostics_len)) {
|
||||
fprintf(stderr, "error: failed to format diagnostics\n");
|
||||
exit_code = AMDUAT_PEL_CLI_EXIT_CODEC;
|
||||
goto exec_cleanup;
|
||||
}
|
||||
fputs(",\"output_paths\":[", out_stream);
|
||||
for (i = 0; i < (int)outputs_len; ++i) {
|
||||
if (i != 0) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue