valgrind无法识别覆盆子Pi中的memcmp指令

Gre*_*rek 13 c valgrind raspberry-pi raspbian

我在Valgrind测试我的应用程序,我无法理解为什么它会在这里抛出无法识别的指令错误:

unsigned char *temp=SearchStartPtr;
unsigned char *NrStartPos=NULL;
unsigned char *Param=(unsigned char*)ParamName; //this is originally *char with "PAR#" inside

if(0==memcmp(temp,Param,4)) 
        {
        NrStartPos=temp;
        break;
        }       
Run Code Online (Sandbox Code Playgroud)

Valgrind抛出这个并退出我的应用程序.

disInstr(arm): unhandled instruction: 0xF1010200
cond=15(0xF) 27:20=16(0x10) 4:4=0 3:0=0(0x0)
==7679== valgrind: Unrecognised instruction at address 0x4843588.
==7679==    at 0x4843588: ??? (in /usr/lib/arm-linux-gnueabihf/libcofi_rpi.so)
Your program just tried to execute an instruction that Valgrind
==7679== did not recognise.  There are two possible reasons for this.
==7679== 1. Your program has a bug and erroneously jumped to a non-code
==7679==    location.  If you are running Memcheck and you just saw a
==7679==    warning about a bad jump, it's probably your program's fault.
==7679== 2. The instruction is legitimate but Valgrind doesn't handle it,
==7679==    i.e. it's Valgrind's fault.  If you think this is the case or
==7679==    you are not sure, please let us know and we'll try to fix it.
==7679== Either way, Valgrind will now raise a SIGILL signal which will
==7679== probably kill your program.
==7679== 
==7679== Process terminating with default action of signal 4 (SIGILL)
==7679==  Illegal opcode at address 0x4843588
==7679==    at 0x4843588: ??? (in /usr/lib/arm-linux-gnueabihf/libcofi_rpi.so)
Run Code Online (Sandbox Code Playgroud)

通常代码工作正常(但我不知道它是否没有一些内存泄漏).

我确定问题是memcmp指令,但我不明白是什么问题.

在代码的早期,我有另一条指令做了同样的事情,但我可以在检查之前评论它:

  memcmp(ReadPtr,ToWritePtr,sizeof(struct termios)
Run Code Online (Sandbox Code Playgroud)

Nig*_*per 16

似乎这是Val上的Valgrind的一个已知问题.

总结Raspbian中memcmp的库存版本使用当前Valgrind根本无法处理的汇编指令.不幸的是,对于Valgrind来说,这个特别的指令显然很难支持,所以它不太可能发生 - 在Valgrind跟踪器中引发了一个错误但是已经关闭为WONTFIX.

关于我可以看到解决这个问题的唯一方法是替换你自己的memcmp版本,并希望它不会编译成包含有问题的指令.

  • 好吧,它比那更容易./usr/lib/arm-linux-gnueabihf/libcofi_rpi.so本身是预加载的.所以只需在树莓上编辑/etc/ld.so.preload,并注释掉该行,它应该为您提供glibc中的memcmp (12认同)
  • 我通过简单地删除`raspi-copies-and-fills`包修复了这个问题. (3认同)
  • Nigel你应该在你的答案中添加最后一条评论,因为它提供了一个非常简单的解决方法 (2认同)