Is it me or lldb for mac os x (replacing gdb) does not allow you to pipe a file into the stdin, to be used by the process being debugged?
reading the instructions there is no reference to it.
I've gone through and installed gnu gdb, but would like to take advantage of what I suppose is improved lldb capability?
(lldb) process launch -i <file>
Should do the trick. Note you can't say:
(lldb) run -i <file>
since run is an alias for process launch -- so all its arguments are passed to the process being launched.
There's a general "help" facility that can show you more about all the lldb commands.
(lldb) help process launch
would have shown you this option.
Related
I'm debugging an interactive, command-line program with lldb. The program presents its own prompt to the user (in a manner similar to fdisk).
My question is, how do I escape, or get back to, the lldb prompt while I'm executing the program?
Here's how I go about launching the program and getting to the point that I'm inquiring about:
bash$ lldb progname progarg1
(lldb) target create "progname"
Current executable set to 'progname' (x86_64).
(lldb) settings set -- target.run-args "progarg1"
(lldb) process launch
Process launched Process 29286 launched: '/home/chb/progdir/progname' (x86_64)
progname>help
Commands are:
buy: use schmeckles to buy a plumbus
lube: rub with the fleeb
...
progname>
After entering the program's command loop, how do I get back to lldb to issue other, lldb-related commands?
Hitting Control-C on your keyboard interrupts the program and lldb takes control.
I am newbie to UNIX programs. I have encountered a situation wherein I have to issue commands to gdb from my C program. I have a C program which invokes another C program by forking a new child process. I need to debug this child C program and hence, I used system command to call gdb process on this C program. But I get a gdb prompt which I do not want. I want to issue commands to the gdb from my parent C program. Is there a way to issue commands to gdb from a C program ?
Please reply.
Thanks a lot.
Esash
If you need to debug the child process, you don't necessarily need to invoke the child with GDB when you fork+exec. As long as you have the PID of the child process, you can use the "attach" command in GDB to attach to the running child process. Basically, you would start GDB like:
$ gdb
(gdb) attach pid-of-child
In the above, replace pid-of-child with the PID of the child process, and there you go, you can debug the child process from interactive GDB, without the parent process needing to deal with GDB at all.
There are several ways to "drive" GDB programmatically.
If you just want to issue one command, e.g. to find out why the child crashed, you can do something like this:
gdb --batch -ex where /path/to/child <pid-of-child>
If there are more commands then you are willing to put on command line, you could write them to a temporary file, and ask gdb to execute them:
gdb --batch -x /path/to/commandfile /path/to/child <pid-of-child>
Neither of the above allows you to perform programmatic (if ... then do-something-in-gdb else do-something-else-in-gdb) control.
For that you may want to either exercise GDB's machine interface (MI), or use the embedded Python interpreter.
Theres also the follow on fork gdb option. This will attach to the child process immediately.
set follow-fork-mode mode
so,
set follow-fork-mode child
I've been trying to open a new terminal window from my application and execute a command on this second window as specified by the user. I've built some debugging software and I would like to execute the user's program on a separate window so my debugging output doesn't get intermixed with the programs output.
I am using fork() and exec(). The command I am executing is gnome-terminal -e 'the program to be executed'.
I have 2 questions:
Calling gnome-terminal means the user has to be running a gnome graphical environment. Is there a more cross-platform command to use (I am only interested in Linux machines though)?
After the command finishes executing the second terminal also finishes executing and closes. Is there any way to pause it, or just let it continue normal operation by waiting for input?
You probably want something like xterm -hold.
1) gnome-terminal should work reasonably also without the whole gnome environonment, anyway the old plain "xterm" is enough.
2) you can execute a short bash script that launch your program and at the end reads a line:
bash -c 'my program ... ; read a'
(or also 'xterm -e ...')
To run a c program you do something like this
bash> gcc test.c -o test
and then
bash> ./test
How can i do to make test.c execute a terminal in another window??
xterm -e "./test"
This will execute 'test' in a new xterm window. Assuming Linux of course.
You can fork a new process and use system() function. This will work on most of Linux distributions. Just check the terminal properties to know the command to execute a new terminal. "gnome-terminal" works for me(Ubuntu, Redhat).
int main()
{
if(!fork())// child process
system("gnome-terminal");
else
{
//do rest of the things here in parent process......
}
}
After fork(), a new terminal window will open as a separate process.
Depends on which system you're on and which terminal you have in mind, but here's how to do it if you're on gnome (ubuntu for instance)
gnome-terminal -x sh -c "./test"
If you don't want the window to close immediately after ./test finishes, you do
gnome-terminal -x sh -c "./test; cat"
You want to open a window for a new terminal, or what do you want to do?
Your question isn't really clear.
If you want to run some commands, you need to cope with sys calls to launch a new process.
On Windows there's the system() function, but I'm not sure it exists on Linux or other posix systems.
Based on your use of the word terminal im guessing you are using osx.
You can use applescript to get the behavior:
tell application "Terminal"
activate
do script with command "cd _directory_; ./test"
end tell
If you want the program to launch a window, have the program call popen to launch the command [or write to a temporary file and launch the script]
In general i see the process's pid which is running in the background and start dbx on that process using the command dbx -a <pid>
similarly how could i do it using gdb?
In addition to the previous you can directly use
gdb -p <pid>
There are two ways.
From the command line, include the pid as an argument after the executable name:
gdb /path/to/prog PID
From within gdb, you can use the attach command:
gdb /path/to/prog
gdb> attach PID
While the specifying on the command line is more concise, there is a slight risk that if you have a core file that has a name that is the same as the pid (i.e. for pid 2345, the core file would have to be named "2345") then gdb will open the core file. Admittedly, the chance of this happening is minuscule.
From the gdb man page:
You can, instead, specify a process ID as a second argument, if you want to debug a running process:
gdb program 1234