Traian Florin Şerbănuţă via llvm-dev
2015-Sep-04 16:10 UTC
[llvm-dev] How to get the bit representation of some stored value?
Hello, I'm writing a pass to instrument some code, and I cannot get past something. Basically, I would like to instrument all load and store operations in a program and have their address and value passed to a handler function which takes as argument the address and an integer containing the bit representation of the stored/loaded value (I know the value fits into an integer type, although the value itself might not be of integer type). Is is possible to achieve something like this? I tried several of the casting creation methods, but I found none working. I have this code (from ThreadSanitizer) Value *Addr = cast<StoreInst>(I)->getPointerOperand() StoredValue = cast<StoreInst>(I)->getValueOperand(); Type *OrigTy = cast<PointerType>(Addr->getType())->getElementType(); const uint32_t TypeSize = DL.getTypeStoreSizeInBits(OrigTy); and I've tried things like IRB.CreateIntCast(StoredValue, IRB.getIntNTy(TypeSize), false) or even attempting to first cast it through a pointer type IRB.CreateIntCast(IRB.CreatePointerCast(StoredValue, IRB.getInt8PtrTy()), IRB.getIntNTy(TypeSize), false) but nothing seem to work (mainly assertions failing) Could you please point me into the right direction? Thank you, Traian -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150904/bc6e30ac/attachment.html>
Kostya Serebryany via llvm-dev
2015-Sep-04 17:34 UTC
[llvm-dev] How to get the bit representation of some stored value?
On Fri, Sep 4, 2015 at 9:10 AM, Traian Florin Şerbănuţă < llvm-dev at lists.llvm.org> wrote:> Hello, > > I'm writing a pass to instrument some code, and I cannot get past > something. > > Basically, I would like to instrument all load and store operations in a > program and have their address and value passed to a handler function which > takes as argument the address and an integer containing the bit > representation of the stored/loaded value (I know the value fits into an > integer type, although the value itself might not be of integer type). > > Is is possible to achieve something like this? > I tried several of the casting creation methods, but I found none working. > > I have this code (from ThreadSanitizer) > > Value *Addr = cast<StoreInst>(I)->getPointerOperand() > > StoredValue = cast<StoreInst>(I)->getValueOperand(); > > Type *OrigTy = cast<PointerType>(Addr->getType())->getElementType(); > const uint32_t TypeSize = DL.getTypeStoreSizeInBits(OrigTy); > > and I've tried things like > > IRB.CreateIntCast(StoredValue, IRB.getIntNTy(TypeSize), false) > >I'd suggest you to print the values that you create just before the assertion fires -- it will give you a clue why the assertion in unhappy.> or even attempting to first cast it through a pointer type > > IRB.CreateIntCast(IRB.CreatePointerCast(StoredValue, IRB.getInt8PtrTy()), IRB.getIntNTy(TypeSize), false) > > > but nothing seem to work (mainly assertions failing) > Could you please point me into the right direction? > > Thank you, > Traian > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150904/72cc3a81/attachment.html>