[LLVMdev] How to read memory data througn adress of unsigned long

Reid Kleckner reid.kleckner at gmail.com
Fri Mar 25 22:13:25 PDT 2011


On Fri, Mar 25, 2011 at 8:53 PM, Michael.Kang <blackfin.kang at gmail.com> wrote:
> I have a value of long type and like to get the data at the adress in the value:
>
> #################
> unsigned long v = 0xc0008000
> Value* addr = ConstantInt::get(getIntegerType(64), v)
> ####################
>
> Then I try to use LoadInstr to get a load instruction of ir as the following:
> ############################
>  Value* data = new LoadInst(addr, "", false, bb);
> encounter segmentation fault.
> ########################
>

Perhaps you should use a debug build of LLVM so you get an assert
message instead of a segfault.  Here you're trying to load from an
integer without first casting it to a pointer, which you do next.

> I also try to use IntToPtrInstr to do some transform as the following:
> ################################
>      Type const *intptr_type =
> cpu->dyncom_engine->exec_engine->getTargetData()->getIntPtrType(_CTX());
>       Value* ptr = new IntToPtrInst(v, intptr_type, "", bb);
>       Value* data = new LoadInst(ptr, "", false, bb);
>  ########################################
>  still encounter segmentation fault
>
> Any person can give me some hints for my case? Thanks in advance. I
> have tried a long time  with different ways.

Not sure why, but using a debug build would be helpful and using
IRBuilder would help make your code less error-prone.

Reid




More information about the llvm-dev mailing list