(How) can I export the call stack when on a breakpoint? - delphi

Is there a way to export the call stack when the code is stopped on a breakpoint?
I have very long ID strings that I need to grab for use in another program (see pic), and retyping from a screen capture is not really an option ;-)
I'm clicking around in the XE2 IDE but can't find anything.
(Workaround: For now I continue stepping through the code after the breakpoint, until I have moved far enough back up the stack that the local variables are available again.)

The call stack debug window supports the usual selection and clipboard shortcuts. So use CTRL+A to select the entire call stack, and CTRL+C to copy to the clipboard. Or you can select a single item and copy with CTRL+C. Or you can select multiple items with CTRL+click and SHIFT+click, and so on.

Related

Uneditable source files and shortcuts changed while debugging

I'm using "Code Gear Delphi 2007", while debugging (Run F9, button with play icon), I can't type any char into source files.
Furthermore, some of default shortcuts (like copy CTRL+C, paste CTRL+V...) are automatically switched to different values:
When the execution is stopped (Program reset CTRL+F2, button with stop icon), all problems disappear.
How could I reset my IDE as it was before these problems?
You have most likely changed the Debugger Options to Map TD32 keystrokes on run and Mark Buffers read-only on run.

Automate the insertion of breakpoints?

Is it possible to automate the insertion of breakpoints? For example, I need to insert a specific (the same) conditional breakpoint at the beginning and exit of every procedure inside a specific unit. To do this manually would be tedious and time-consuming, so I am looking for an automated way to do this.
No. There's no functionality in the IDE to do so.
Based on your comment to the original question, what you're actually trying to do is detect where a global ("public") variable is being changed. The way to do that is to set a Data Breakpoint, which is tripped when the variable is changed, and then view the callstack to see what code was executing last. (You can find this in the help file by searching on "Breakpoints, setting data breakpoints" in the help index for Delphi 2007, or "Breakpoint Properties, Data Breakpoint" in XE4's help (linked above).
Note that both ask for an address to watch, but work with #VariableName as well. (Using a stack (local) variable triggers a dialog that tells you that doing so can make your app unstable and asking you to confirm you want to do so.)
As #DavidHeffernan points out in a comment, a better solution is to make the public field a property with a setter, and then set a normal breakpoint inside that setter.
Breakpoints are stored in the similar named section of the projects DSK file. Set one breakpoint manually in the IDE to find out the correct settings. Then copy and adjust this breakpoint in the DSK file to your needs.
This doesn't solve the problem to find out the correct line numbers though.
Yes *)
A breakpoint can be inserted with assembler code (see How to simulate a Delphi breakpoint in code?):
asm int 3 end;
Automated insertion (and removal) of this code in the places where you need the breakpoint is a trivial task, as tools which perform source code instrumentation (e.g. profilers for Delphi and other languages) show.
I do not say that it is easy, but possible.
*) if you are a programmer ;-)

How keep the debug layout the same as the desktop layout

I try to have a similar layout during editing as well debugging. When running the program my structure and object inspector disappear. I did create my own desktop speedsetting, set the debug desktop to it as well, but as soon as the program runs structure and obejct inspector disappear. How can I prevent that?
A question related to this: the edit menu changes as well. A right click on a procedure name results in a popup menu with the first item being "find declaration". When debugging the first item is "close page". I find the find declaration item a fast way to find some code. Apart from that it is frustrating to lose one's code because you click "no" on the question to save the information (I know, it's my fault but menu's shouldn't change in my opinion).
Thanks,
Arnold
What version of Delphi? Dialogs and menus change between versions (and even between SKUs of the same version).
For the first, open Tools->Options->Environment Options and uncheck Hide designers on run in the Running group box (D2010, XE, and XE2), or Tools->Options->Environment Options and unchecking Hide designers on run in the Compiling and Running group box (D2007).
For the second: The right-click menu is called a context menu, meaning it displays what is appropriate in the context of when it's being shown. It's entirely appropriate for it to change depending on when and how you're using it; that's the way it's supposed to work.
Right-clicking on a .zip file in Windows Explorer is different than right-clicking on a Word .doc file, because they have different options based on context - a zip file has an 'Extract to...' option that the Word document doesn't have, because 'extracting' a Word document doesn't apply. Same applies to right-clicking a .exe file, which has the Run as Administrator option (Win7), as opposed to right-clicking a .pas file, which doesn't offer that option.

Delphi 2007 IDE layout modified after a crash

I loaded a bad PAS/DFM file (long story), which caused a GPF, after which the IDE crashed horribly. Lost my Project-related data (list of open files, etc).
Now, when I start the IDE, it always is in "run" mode. that is, it shows the breakpoints and watches and local variables, even though no program is running. Similarly, the properties are not visible unless I use F11 to bring them up. I've restarted the IDE repeatedly. Interestingly, it still can compile and run a program.
How do I reset the IDE so that it works properly?
Check your layout. It's a combo box on the toolbar. It's probably set to 'Debug Layout' instead of Default or Classic (or something else if you've setup a custom layout.)

Move the Program Counter in Delphi Debugging

In Visual Studio, when you're debugging with breakpoints you can change which line of code will be next to execute by dragging the execution cursor to another line; this lets you skip IF statements and the like.
I was idly wondering if there was a similar feature in Delphi anyone knew about?
I've been having a look around in the CPU window (Delphi 2006) but you only seem to be able to run through the instructions in order, not skip them.
In Delphi XE you can drag the execution cursor to another line as well. Not in the CPU window, but in the editor itself.
In CPU View you can right-click and choose "New EIP (Ctrl + N)" to set the instruction pointer.
In the IDE of 2007 you can also set the execution pointer from the Debug-Contextmenu in the sourcecode.
I've tried it a few times, but its very tricky. Don't try to move the pointer outside any begin-end block or it will bite you in the #ss later

Resources