Forum > Beginners

[Solved] Get variable name of the address pointed to by pointer possible?

(1/1)

Ten_Mile_Hike:
Hello All,

I'm just playing around. I'm NOT trying to incorporate this into an actual program.
It is elementary to find the "VALUE" of a variable using a pointer

My question is:  Can Laz/FPC, or inline ASM be made to reveal that the variable "NAME" not the "VALUE" pointed to by the pointer; in the case below
can I somehow return the string "My_var" from a query of some type?

  SCENARIO
  1. Suppose you have declared                            My_var: Integer;
  2. Then created a pointer "My_Ptr" pointing to      My_var

Salamat
DBM

jamie:

--- Quote from: Ten_Mile_Hike on June 05, 2024, 11:38:43 pm ---Hello All,

I'm just playing around. I'm NOT trying to incorporate this into an actual program.
It is elementary to find the "VALUE" of a variable using a pointer

My question is:  Can Laz/FPC, or inline ASM be made to reveal that the variable "NAME" not the "VALUE" pointed to by the pointer; in the case below
can I somehow return the string "My_var" from a query of some type?

  SCENARIO
  1. Suppose you have declared                            My_var: Integer;
  2. Then created a pointer "My_Ptr" pointing to      My_var

Salamat
DBM

--- End quote ---

No. This is a real compile language..

You can, however, compare the address value with known variables of their address values.


Also, for Class and such, there is runtime info to some degree.


440bx:
There is one case where it is possible to obtain the variable name the pointer points to and that is when the executable is compiled with debugging information.

In that case, by inspecting the debugging symbols it is possible to find the address and the identifier (name) associated with that address.

The important thing to always keep in mind is that the ability depends on debugging information being present otherwise the executable does not contain the necessary information to map an address to an identifier/name.

Just FYI, debuggers as a matter of course, do the opposite of that.  The name/identifier is mapped to an address and whatever is at that address is the value of that name/identifier.    A debugger can and, probably does whenever necessary, do the opposite, i.e, go from address to name.

HTH.

Martin_fr:
If it is a variable, then the name (other than in the debug info) will not be in the exe. The compiler will have replaced it by the address it had gotten for it, and so once everything used that address the name was irrelevant.

However, if it is not a variable, but a published field/property of an object (class) then the compiler will create RTTI for that property.
If you have the address of such a field, and if you then also have the class, then you can iterate over the published fields, and find the one with the matching address. And you can then get the name of it. (That is how a form is loaded from lfm, only that here the lookup is by name, and the address (or setter if it is a property) is then used to write the loaded value to.

Navigation

[0] Message Index

Go to full version