home *** CD-ROM | disk | FTP | other *** search
- From: jmn@hpfcso.FC.HP.COM (John Newman)
- Date: Thu, 3 Sep 1992 23:17:43 GMT
- Subject: Re: attaching xdb to a running process...
- Message-ID: <7371287@hpfcso.FC.HP.COM>
- Organization: Hewlett-Packard, Fort Collins, CO, USA
- Path: sparky!uunet!usc!sdd.hp.com!hp-cv!hp-pcd!hpfcso!jmn
- Newsgroups: comp.sys.hp
- References: <3739@tivoli.UUCP>
- Lines: 182
-
-
- > I suspect that I just dont know enough about xdb to see what it needs to
- > do to get a process started, but the only manual Ive seen is a really good
- > users manual,
-
- Thanks.
-
- > and this is a little beyond that.
- >
- > If anyone knows more about xdb and what signals it uses to start/stop a
- > process once it has gotten it with ptrace, please let me know.
-
- Xdb uses ptrace, not a signal, to (re)start process. The only signal
- xdb uses itself is SIGTRAP.
-
- ---
-
- I played around with your example program, and got it to work by doing
- this:
-
- 1. put in an short signal handler for SIGUSR1 (any innocuous signal
- will do here).
-
- 2. Set up the handler in exec_debugger(), before the fork.
-
- I needed the handler in order to get back out of the pause().
- But, here's the key:
-
- 3. Once the debugger is attached, I used the following commands:
-
- >b
- This sets a breakpoint at the return addr from
- the call to pause(). This gives control back to
- the debugger (user) when the pause() returns.
-
- >p $signal = 16
- >C
- This passes the SIGUSR1 to the process and completes
- the pause().
-
- If you use 's' instead of 'C' here, you end up at the 1st stmt
- in the signal handler.
-
- Check out the discussion of $signal and Continue (capital 'C') in TFM.
-
- You can avoid manually doing this every time with a playback file.
- Put the above 3 commands into a file, and list it with -p in your
- call to exec:
-
- execlp( ... , "-p", "playback", proc, NULL);
-
- NOTE: Using the 'C' with a breakpoint works great on PA-RISC if archive
- libs are used (compiled with -Wl,-a,archive on HP-UX 8.0x). If a shared libc
- (libc.sl) is used, then you'll need to give an explicit location to the
- 'b' command. This is a limitation having to do with shared-libs,
- stack unwinding, and attaching while in the kernel. I'll leave the
- grody details out of this discussion.
-
- Using the 's' to step into the signal-handler works okay regardless.
-
- BTW, Chan's suggestion to use "while(i) ;" will work find too. Just
- put something like this into the playback: p i=0; s
-
- ___
- / / John Newman
- HEWLETT/hp/PACKARD Colorado Language Lab
- /__/ jmn@hpfcrt.fc.hp.com
-
- --------- --------- --------- --------- --------- --------- --------- -----
- This response does not represent the official position of, or statement by,
- the Hewlett-Packard Company. The above data is provided for informational
- purposes only. It is supplied without warranty of any kind.
-
- #---------------------------------- cut here ------------------
- # This is a shell archive. Remove anything before this line,
- # then unpack it by saving it in a file and typing "sh file".
- #
- # This archive contains:
- # prog.c playback
- #
-
- LANG=""; export LANG
- PATH=/bin:/usr/bin:$PATH; export PATH
-
- echo x - prog.c
- cat >prog.c <<'@EOF'
-
- /*
- * Compile with: cc -g -Aa -Wl,-a,archive
- */
- #define _POSIX_SOURCE
- #include <sys/stdsyms.h>
- #include <sys/signal.h>
- #include <stdio.h>
-
- main(int argc, char *argv[])
- {
-
- int pid, pid1, pid2, i;
- int exitcode;
-
- printf("in main program\n");
-
- pid = fork();
-
- if (pid != 0) { /* parent */
- waitpid(pid, &exitcode, 0);
- exit(0);
- }
-
- /*
- * here is the child
- */
-
- printf(" in the child\n");
-
- pid1 = fork();
-
- if (pid1 != 0) { /* parent */
- pid2 = getpid();
- printf(" in the first child (debugger parent) %d\n", pid2);
-
- exec_debugger(argv[0], pid2);
-
- pause();
-
- printf("starting the loop\n");
- for (i=1; i < 100; i++) {
- printf("I is %d\n",i);
- }
- exit(1);
- }
- }
-
- void catch (int sig, unsigned long code, struct sigcontext *scp)
- {
- if (sig == SIGUSR1)
- (void) signal (SIGUSR1,SIG_IGN);
-
- return ;
- }
-
- exec_debugger(char *proc, int pid)
- {
- char pidstr[20];
- char *display;
- extern char *getenv(char *);
-
- if ((display = getenv("DISPLAY")) == (char *)NULL || !*display) {
- display = "local:0";
- }
-
- (void) signal(SIGUSR1,(void (*) ())catch);
-
- sprintf(pidstr,"%d",pid);
- printf("starting the debugger %s\n", pidstr);
-
- if (fork() == 0) {
- execlp("/usr/bin/X11/hpterm", "/usr/bin/X11/hpterm", "-display",
- display, "-e", "/usr/bin/xdb", "-P", pidstr,
- #ifdef USE_PLAYBK
- "-p", "playback",
- #endif
- proc, NULL);
- exit(2);
- }
- }
-
- @EOF
-
- chmod 666 prog.c
-
- echo x - playback
- cat >playback <<'@EOF'
- b
- p $signal = 16
- C
- @EOF
-
- chmod 666 playback
-
- exit 0
-