gdb command file scripting: wait for breakpoint supported? - scripting

Im debugging quite a complex program with lots of queues, each having a relatively short timeout period set.
I cannot debug reliable in gdb's 'manual' command line mode, because timeouts are triggered when I type commands to slowly.
I don't like the idea of extending all the queue's timeouts, as this would make things really messy. (This sounds like the design itself is arguable, I know...)
I'd really like to use the gdb 'scripting' feature, but I haven't found a good tutorial for this.
Could anyone tell me if this is possible in a gdb "command file" script:
init some things (easy)
set a breakpoint
run programm
have the next command in script executed once the breakpoint is hit
So basically my question is: can I wait for a breakpoint inside a gdb command file script?

Answering my own question: I had success using hooks. My command file looks like this:
[initialization code]
define hook-stop
[commands to be executed at breakpoint]
end
set breakpoint pending on
b my_breakpoint_function
r

Related

ABAP debugger: How do i get to the start of execution of my program without using a breakpoint

Whenever I run my program on a ABAP debugger -without setting a breakpoint- it starts executing the program from the SAP ABAP programs running under my program and I have to keep pressing F5/F6 to get to start of my code. This wastes my time.
How do I let ABAP debugger know I want to start right from the start of my own code, and I do not want to debug SAP code.
There are two options:
You might want to raise a SAPnet issue since this might be considered a bug in the processing of the statement BREAK-POINT ... AT NEXT APPLICATION STATEMENT
You might want to take a look at Layer Aware Debugging, which does come in handy for other situations as well.
If you use SE38 to start your ABAP-Program there you find a DEBUGGING-Button.

How to pause, resume and stop a Sikuli program?

Suppose I am running a Sikuli program and I want to pause the program at a particular point and then after sometime I want to resume the program from that point where I paused, without affecting the process. And then I want to stop the process and exit from it. The point where I stopped till that it should be saved. Is it possible in Sikuli? If yes, then how?
Press Alt+Shift+c to kill a running Sikuli script.
No, Sikuli has no built-in capability to manage this for you. However, you can write all of these capabilities into your script or otherwise get them.
Pausing an resuming is most easily done on the Unix command-line, where you can use control-z to suspend a program and fg to resume it. Windows has similar capabilities. Look for "suspend and resume process " to find some ways of doing this (there are many).
Exiting from a program and then being able to re-start the program and have it resume (roughly) where it left off is called "checkpointing". The checkpointing packages I know of are intended for distributed computing and would probably be overkill for what you're doing, but you could take a look at the Wikipedia entry for suggestions. I suspect that implementing it yourself will be the easiest way to go.
For help with either of these topics, I recommend starting a new question specifying the language you're using (Jython or Java) and the operating system (Unix or Windows). The questions and answers to these aren't related to Sikuli.
For pause, you can use wait commands; if you want to resume, you need to have flags that you set at the beginning of the script, and change accordingly to what you want to wait for.
For closing the script; you can use the Type command wherever you want the script to quit; which is the equivalent of pressing CMD-Shift-C when using the IDE
type('c', KeyModifier.CMD + KeyModifier.SHIFT)
Hope this helps

How to run a shell command in cocoa and get output?

After repeated searching I have not found an elegant solution to this issue: how to run a shell command in obj-c and get it's output. I have read many questions regarding this, but they all fail to answer my question.
Some get the exit value ( Get result from shell script objective-c ) others only run the command ( Cocoa/ Objective-C Shell Command Line Execution ), and finally others have me write the output to a file ( Execute a terminal command from a Cocoa app ).
I really would like to avoid writing/reading a file as it not a very clean solution.
Is there no way to read the output directly in obj-c? If so how?
The code from "doshellscript" from the first link (Get result from shell script objective-c) actually does return an NSString with the output of the command. If it's not working for you, maybe the command is outputting over stderr rather than stdin? Have you tried this yet? The standard mechanism for running commands in Cocoa is NSTask, so definitely at least start there.
Look at the class PRHTask. It is a replacement of NSTask, with completion blocks. https://bitbucket.org/boredzo/prhtask
Extract from the header:
First, rather than having to set your own pipe for standard output and error, you can tell the task to accumulate the output for you, and retrieve it when the task completes.
Second, when the process exits, rather than posting an NSNotification, a PRHTask will call either of two blocks that you provide. You can set them both to the same block if you want.
If your task needs admin privileges, you might want to look at STPrivilegedTask.

How does the pstack command work?

I am curious to find how does the pstack command prints the stack trace of all the threads running under the PID?
It has to be someway different than the way gdb does since the process runs inside the gdb environment, but pstack is executed after the execution of the process.
It's the same general idea as gdb. pstack uses ptrace, which allows an external process to attach to a known pid and print out the information (stack is known via the current registers).
If you want to know exactly how it's done, look for information about ptrace.
Also, processes don't really run "inside the gdb". You can attach gdb to a running process without much trouble by running gdb executable pid.
pstack print similar output as cat /proc/"pid"/tasks/*/stack so it most likely that it read the procfs rather than using the ptrace.

GDB dies because of NSZombieEnabled

I was having some problems with memory (exc-bad-access) in Objective-C, XCode, for iPhone, so I searched a little bit and found about the (awesome) NSZombieEnabled. Everyone outhere is just explaining how cool this is ... but it doesn't work for me :/
I followed the following 'tutorial': http://www.cocoadev.com/index.pl?DebuggingAutorelease
I double clicked on the executable under the executable tab (left panel) and I added NSZombieEnabled=YES to the environmental variables
I also added a bunch of other options (like malloc history, some custom ~/.gdbinit that I found on the web, etc) but this didn't solve the problem
So basically when I launch (in debug mode) GDB sais
"Undefined command: "NSZombieEnabled". Try "help".
And it basically stops (in the status bar it says - error in GDB - terminating).
The problem is most likely in your ~/.gdbinit file in that the error you have provided indicates that gdb was trying -- and failing -- to parse a command.
In .gdbinit, the command should look like:
set env NSZombieEnabled=YES
To help further, you'd need to drop your .gdbinit in the question. However, there is rarely a need to use a .gdbinit file (for all but advanced debugging). I'd suggest deleting it.
For autorelease debugging, use Instruments....