Midhun
Midhun

Reputation: 744

How to get the name of the pointer variable if the address is known?

When i run my project it loads up and starts running but crashes after sometime. The log that i get is this:

Attempt to free invalid pointer 0x2df2fc6b9000

Now this is chromium code and i don't know where in this code base is the program going wrong. So i wanted to know if it is possible to get the variable name give the address 0x2df2fc6b9000. Thankyou.

Upvotes: 0

Views: 96

Answers (2)

Marko Mahnič
Marko Mahnič

Reputation: 735

You might find the name of the variable if you run a debug version of your program with symbol information included, in a debugger. The debugger might display the list of symbols on the stack with the appropriate addresses at the point in program where the application crashes. In your case you would have to find a pointer variable with the value contained in the error.

The debugger should also display the line where the error occured. It might be easier to find the error by looking at the code arround this line than searching for the offending variable by content.

Without symbol information included in the program it is impossible to match memory locations to variable names.

Upvotes: 0

R Sahu
R Sahu

Reputation: 206567

You cannot.

For example:

int i = 10;
int* p1 = &i;
int* p2 = p1;

Given &i, there is no way to say the variable is p1 or p2. For all we care, there may not be any p1 or p2 at all.

That error message is a strong indication that your code is using memory incorrectly. You'll have to try to reduce your code to a Minimal, Reproducible Example. You might find the source of the problem in the process of doing that.

Upvotes: 2

Related Questions