keystone icon indicating copy to clipboard operation
keystone copied to clipboard

Give line numbers with errors

Open darkf opened this issue 7 years ago • 4 comments

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.

darkf avatar Jul 29 '16 13:07 darkf

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

aquynh avatar Jul 29 '16 13:07 aquynh

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

keyboardsmoke avatar Mar 16 '19 20:03 keyboardsmoke

@aquynh This does not seem to work anymore? Now stat_count is 0 when parsing fails.

learn-more avatar Jun 30 '21 21:06 learn-more

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?

vrbadev avatar Feb 17 '23 12:02 vrbadev