Skip to content

Commit

Permalink
i#1569 AArch64: Print instruction if encoding fails. (#2315)
Browse files Browse the repository at this point in the history

As the parser for AArch64 is not complete yet dumping instructions that could
not be encoded makes it easier to diagnose encoding problems.

* Use SYSLOG_INTERNAL_ERROR to dump disassembled instruction.
  • Loading branch information
fhahn committed Mar 30, 2017
1 parent 3e18d73 commit 2ea03bb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 0 additions & 3 deletions core/arch/aarch64/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

#include "codec.h"

#define ENCFAIL (uint)0 /* a value that is not a valid instruction */

/* Decode immediate argument of bitwise operations.
* Returns zero if the encoding is invalid.
Expand Down Expand Up @@ -2592,7 +2591,5 @@ uint encode_common(byte *pc, instr_t *i)
ASSERT(instr_num_srcs(i) >= 1 && opnd_is_immed_int(instr_get_src(i, 0)));
return opnd_get_immed_int(instr_get_src(i, 0));
}
/* We were unable to encode this instruction. */
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#1569 */
return enc;
}
2 changes: 2 additions & 0 deletions core/arch/aarch64/codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#ifndef CODEC_H
#define CODEC_H 1

#define ENCFAIL (uint)0 /* a value that is not a valid instruction */

byte *decode_common(dcontext_t *dcontext, byte *pc, byte *orig_pc, instr_t *instr);
uint encode_common(byte *pc, instr_t *i);

Expand Down
11 changes: 11 additions & 0 deletions core/arch/aarch64/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ instr_encode_arch(dcontext_t *dcontext, instr_t *instr, byte *copy_pc, byte *fin
CLIENT_ASSERT(instr_operands_valid(instr), "instr_encode error: operands invalid");

*(uint *)copy_pc = encode_common(final_pc, instr);
if (*(uint *)copy_pc == ENCFAIL) {
/* We were unable to encode this instruction. */
IF_DEBUG({
char disas_instr[MAX_INSTR_DIS_SZ];
instr_disassemble_to_buffer(dcontext, instr, disas_instr,
MAX_INSTR_DIS_SZ);
SYSLOG_INTERNAL_ERROR("Internal Error: Failed to encode instruction:"
" '%s'\n", disas_instr);
});
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#1569 */
}
return copy_pc + 4;
}

Expand Down

3 comments on commit 2ea03bb

@derekbruening
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the bottom of the commit message was not fully edited on the squash-and-merge

@fhahn
Copy link
Contributor Author

@fhahn fhahn commented on 2ea03bb Mar 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry about that. I think the textbox in the UI was quite small and I missed the text at the end. I will be more careful next time.

@derekbruening
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As our wiki talks about it is resizable. Somone could file a github issue on the default size.

Please sign in to comment.