keystone
keystone copied to clipboard
Give line numbers with errors
Seeing KS_ERR_ASM_MNEMONICFAIL
and KS_ERR_ASM_INVALIDOPERAND
is not particularly helpful if I don't know which mnemonic/operand is causing such a fuss: both which mnemonic/operand is invalid, and ideally a line number would be very helpful in tracking down errors.
In this case, you can find the statement causing error from "stat_count" arg of ks_asm(). This is documented in include/keystone/keystone.h
Don't mean to bump this, but stat_count isn't very useful compared to line/col.
I made some changes to a local copy of keystone to allow capturing of line and column number,
SMLoc locError = Lexer.getTok().getEndLoc();
std::pair<unsigned, unsigned> lac = SrcMgr.getLineAndColumn(locError, CurBuffer);
KsLine = lac.first;
KsCol = lac.second;
very few changes were made to achieve this, i could prepare a PR if you'd like
@aquynh This does not seem to work anymore? Now stat_count is 0 when parsing fails.
Same issue here... the ks_asm
method in Python throws exception with constantly count = 0
, so it is impossible to trace back the ASM line where the error occurs. Any way to solve this?