0

For the following statement inside function func(), I'm trying to figure out the variable name (which is 'dictionary' in the example) that points to the malloc'ed memory region.

Void func() {
   uint64_t *   dictionary = (uint64_t *) malloc ( sizeof(uint64_t) * 128 );
}

The instrumented malloc() can record the start address and size of the allocation. However, no knowledge of variable 'dictionary' that will be assigned to, any features from the compilers side can help to solve this problem, without modifying the compiler to instrument such assignment statements?

One way I've been thinking is to use the feature that variable 'dictionary' and function 'malloc' is on one source code line or next to each other, the dwarf provides line information.

Michael
  • 1,505
  • 14
  • 26
user1147800
  • 237
  • 4
  • 14

1 Answers1

0

One thing you can do with Clang and LLVM is emit the code with debug information and then look for malloc calls. These will be assigned to LLVM values, which can be traced (when not compiled with optimizations, that is) to the original C/C++ source code via the debug information metadata.

Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412