4

If you inspect an interface pointer in Delphi's Evaluate/Modify pop-up (Ctrl-F7) it will say something resembling this:

Pointer($656E84) as IConnectionPoint

My question is, where does the debugger get the "as IConnectionPoint" or whatever from, iow

a) How does it know what type of interface the pointer is referencing; and

b) Where (and by what process) does the debugger get the text of its description, e.g. IConnectionPoint?

I was wondering whether the debugger manages these things by somehow querying the interface the pointer is holding. But, IInterface (which is what the debugger reports an IUnknown as) only has QueryInterface, _AddRef and _Release methods and I can't seehow the info could be obtained from any of those. Equally, I can't see how the debugger could derive the info from the "history" of the pointer, because the object its referencing need not have been created in the Delphi app in the first place.

2
  • 2
    Is it not just as simple as the debugger knowing the variable is declared to have type X, and knowing it has value Y, so displaying "Pointer(Y) as X"? Commented Apr 2, 2016 at 14:11
  • 1
    Can you post the code that declares the interface pointer that's giving you the behavior you observe? I'm suspecting (just as @Rob) that the debugger can simply know from the compiled symbols how the variable was declared. Commented Apr 2, 2016 at 14:13

1 Answer 1

5

How does it know what type of interface the pointer is referencing?

The debugger has access to debugging info.

Where (and by what process) does the debugger get the text of its description?

From a separate file created by the compiler (usually a .map file).
The compiler can also include the debug info in the exe itself. This is why a debug exe is much bigger than a release exe.

Variables are defined in the (included) map file/resource.
The debug info also links the assembly code to lines in the source file.
This is how the debugger knows which source line you are executing; it knows the address the CPU is at and looks up that address in the .map file to find the line number and name source file.

You can ask the linker (the process that puts together all the dcu and other files into an exe) to either include the debug info in the exe or create a separate .map file.
Project-> options -> Linking

enter image description here

You can alter the debug settings in the project -> Options... -> Compiling dialog.

enter image description here

[does] the debugger [...] query the interface the pointer is holding?

The debugger does not call your code to determine the types of variables at runtime. In fact it does not call any of your code unless you specifically tell it do so.
If it did that would be bad, because of possible side effects.

Evaluating your code
If you want the debugger to call your code you can force it to do so by using the Evaluate/modify option or the watch list.

Evaluate/modify
Evaluate is a once off evaluation.

enter image description here

Watches
Choose: debug -> add watch at cursor. The Watch tracks your expression as you step through the code. You can edit the expressions in the watch list by right-clicking on the watch item and choosing edit watch...
Here you can also force the debugger to call your functions.

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Calling code is exactly what the Evaluate/Modify dialog is for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.