1 /* Machine independent support for QNX Neutrino /proc (process file system)
2 for GDB. Written by Colin Burgess at QNX Software Systems Limited.
4 Copyright (C) 2003, 2006, 2007, 2008 Free Software Foundation, Inc.
6 Contributed by QNX Software Systems Ltd.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include <sys/debug.h>
28 #include <sys/procfs.h>
29 #include <sys/neutrino.h>
30 #include <sys/syspage.h>
31 #include "gdb_dirent.h"
32 #include <sys/netmgr.h>
34 #include "exceptions.h"
35 #include "gdb_string.h"
40 #include "gdbthread.h"
47 #define _DEBUG_FLAG_TRACE (_DEBUG_FLAG_TRACE_EXEC|_DEBUG_FLAG_TRACE_RD|\
48 _DEBUG_FLAG_TRACE_WR|_DEBUG_FLAG_TRACE_MODIFY)
50 static struct target_ops procfs_ops
;
54 static void (*ofunc
) ();
56 static procfs_run run
;
58 static void procfs_open (char *, int);
60 static int procfs_can_run (void);
62 static ptid_t
procfs_wait (ptid_t
, struct target_waitstatus
*);
64 static int procfs_xfer_memory (CORE_ADDR
, gdb_byte
*, int, int,
65 struct mem_attrib
*attrib
,
68 static void procfs_fetch_registers (struct regcache
*, int);
70 static void notice_signals (void);
72 static void init_procfs_ops (void);
74 static ptid_t
do_attach (ptid_t ptid
);
76 static int procfs_can_use_hw_breakpoint (int, int, int);
78 static int procfs_insert_hw_watchpoint (CORE_ADDR addr
, int len
, int type
);
80 static int procfs_remove_hw_watchpoint (CORE_ADDR addr
, int len
, int type
);
82 static int procfs_stopped_by_watchpoint (void);
84 /* These two globals are only ever set in procfs_open(), but are
85 referenced elsewhere. 'nto_procfs_node' is a flag used to say
86 whether we are local, or we should get the current node descriptor
87 for the remote QNX node. */
88 static char nto_procfs_path
[PATH_MAX
] = { "/proc" };
89 static unsigned nto_procfs_node
= ND_LOCAL_NODE
;
91 /* Return the current QNX Node, or error out. This is a simple
92 wrapper for the netmgr_strtond() function. The reason this
93 is required is because QNX node descriptors are transient so
94 we have to re-acquire them every time. */
100 if (ND_NODE_CMP (nto_procfs_node
, ND_LOCAL_NODE
) == 0)
101 return ND_LOCAL_NODE
;
103 node
= netmgr_strtond (nto_procfs_path
, 0);
105 error (_("Lost the QNX node. Debug session probably over."));
110 static enum gdb_osabi
111 procfs_is_nto_target (bfd
*abfd
)
113 return GDB_OSABI_QNXNTO
;
116 /* This is called when we call 'target procfs <arg>' from the (gdb) prompt.
117 For QNX6 (nto), the only valid arg will be a QNX node string,
118 eg: "/net/some_node". If arg is not a valid QNX node, we will
121 procfs_open (char *arg
, int from_tty
)
127 procfs_sysinfo
*sysinfo
;
129 nto_is_nto_target
= procfs_is_nto_target
;
131 /* Set the default node used for spawning to this one,
132 and only override it if there is a valid arg. */
134 nto_procfs_node
= ND_LOCAL_NODE
;
135 nodestr
= arg
? xstrdup (arg
) : arg
;
141 nto_procfs_node
= netmgr_strtond (nodestr
, &endstr
);
142 if (nto_procfs_node
== -1)
144 if (errno
== ENOTSUP
)
145 printf_filtered ("QNX Net Manager not found.\n");
146 printf_filtered ("Invalid QNX node %s: error %d (%s).\n", nodestr
,
147 errno
, safe_strerror (errno
));
150 nto_procfs_node
= ND_LOCAL_NODE
;
154 if (*(endstr
- 1) == '/')
160 snprintf (nto_procfs_path
, PATH_MAX
- 1, "%s%s", nodestr
? nodestr
: "",
165 fd
= open (nto_procfs_path
, O_RDONLY
);
168 printf_filtered ("Error opening %s : %d (%s)\n", nto_procfs_path
, errno
,
169 safe_strerror (errno
));
170 error (_("Invalid procfs arg"));
173 sysinfo
= (void *) buffer
;
174 if (devctl (fd
, DCMD_PROC_SYSINFO
, sysinfo
, sizeof buffer
, 0) != EOK
)
176 printf_filtered ("Error getting size: %d (%s)\n", errno
,
177 safe_strerror (errno
));
179 error (_("Devctl failed."));
183 total_size
= sysinfo
->total_size
;
184 sysinfo
= alloca (total_size
);
187 printf_filtered ("Memory error: %d (%s)\n", errno
,
188 safe_strerror (errno
));
190 error (_("alloca failed."));
194 if (devctl (fd
, DCMD_PROC_SYSINFO
, sysinfo
, total_size
, 0) != EOK
)
196 printf_filtered ("Error getting sysinfo: %d (%s)\n", errno
,
197 safe_strerror (errno
));
199 error (_("Devctl failed."));
204 nto_map_arch_to_cputype (gdbarch_bfd_arch_info
205 (current_gdbarch
)->arch_name
))
208 error (_("Invalid target CPU."));
214 printf_filtered ("Debugging using %s\n", nto_procfs_path
);
218 procfs_set_thread (ptid_t ptid
)
222 tid
= ptid_get_tid (ptid
);
223 devctl (ctl_fd
, DCMD_PROC_CURTHREAD
, &tid
, sizeof (tid
), 0);
226 /* Return nonzero if the thread TH is still alive. */
228 procfs_thread_alive (ptid_t ptid
)
232 tid
= ptid_get_tid (ptid
);
233 if (devctl (ctl_fd
, DCMD_PROC_CURTHREAD
, &tid
, sizeof (tid
), 0) == EOK
)
239 procfs_find_new_threads (void)
241 procfs_status status
;
248 pid
= ptid_get_pid (inferior_ptid
);
250 for (status
.tid
= 1;; ++status
.tid
)
252 if (devctl (ctl_fd
, DCMD_PROC_TIDSTATUS
, &status
, sizeof (status
), 0)
253 != EOK
&& status
.tid
!= 0)
255 ptid
= ptid_build (pid
, 0, status
.tid
);
256 if (!in_thread_list (ptid
))
263 procfs_pidlist (char *args
, int from_tty
)
266 struct dirent
*dirp
= NULL
;
269 procfs_info
*pidinfo
= NULL
;
270 procfs_debuginfo
*info
= NULL
;
271 procfs_status
*status
= NULL
;
272 pid_t num_threads
= 0;
276 dp
= opendir (nto_procfs_path
);
279 fprintf_unfiltered (gdb_stderr
, "failed to opendir \"%s\" - %d (%s)",
280 nto_procfs_path
, errno
, safe_strerror (errno
));
284 /* Start scan at first pid. */
289 /* Get the right pid and procfs path for the pid. */
298 snprintf (buf
, 511, "%s/%s/as", nto_procfs_path
, dirp
->d_name
);
299 pid
= atoi (dirp
->d_name
);
303 /* Open the procfs path. */
304 fd
= open (buf
, O_RDONLY
);
307 fprintf_unfiltered (gdb_stderr
, "failed to open %s - %d (%s)\n",
308 buf
, errno
, safe_strerror (errno
));
313 pidinfo
= (procfs_info
*) buf
;
314 if (devctl (fd
, DCMD_PROC_INFO
, pidinfo
, sizeof (buf
), 0) != EOK
)
316 fprintf_unfiltered (gdb_stderr
,
317 "devctl DCMD_PROC_INFO failed - %d (%s)\n",
318 errno
, safe_strerror (errno
));
321 num_threads
= pidinfo
->num_threads
;
323 info
= (procfs_debuginfo
*) buf
;
324 if (devctl (fd
, DCMD_PROC_MAPDEBUG_BASE
, info
, sizeof (buf
), 0) != EOK
)
325 strcpy (name
, "unavailable");
327 strcpy (name
, info
->path
);
329 /* Collect state info on all the threads. */
330 status
= (procfs_status
*) buf
;
331 for (status
->tid
= 1; status
->tid
<= num_threads
; status
->tid
++)
333 if (devctl (fd
, DCMD_PROC_TIDSTATUS
, status
, sizeof (buf
), 0) != EOK
336 if (status
->tid
!= 0)
337 printf_filtered ("%s - %d/%d\n", name
, pid
, status
->tid
);
341 while (dirp
!= NULL
);
349 procfs_meminfo (char *args
, int from_tty
)
351 procfs_mapinfo
*mapinfos
= NULL
;
352 static int num_mapinfos
= 0;
353 procfs_mapinfo
*mapinfo_p
, *mapinfo_p2
;
354 int flags
= ~0, err
, num
, i
, j
;
358 procfs_debuginfo info
;
359 char buff
[_POSIX_PATH_MAX
];
367 unsigned debug_vaddr
;
368 unsigned long long offset
;
373 unsigned long long ino
;
380 /* Get the number of map entrys. */
381 err
= devctl (ctl_fd
, DCMD_PROC_MAPINFO
, NULL
, 0, &num
);
384 printf ("failed devctl num mapinfos - %d (%s)\n", err
,
385 safe_strerror (err
));
389 mapinfos
= xmalloc (num
* sizeof (procfs_mapinfo
));
392 mapinfo_p
= mapinfos
;
394 /* Fill the map entrys. */
395 err
= devctl (ctl_fd
, DCMD_PROC_MAPINFO
, mapinfo_p
, num
396 * sizeof (procfs_mapinfo
), &num
);
399 printf ("failed devctl mapinfos - %d (%s)\n", err
, safe_strerror (err
));
404 num
= min (num
, num_mapinfos
);
406 /* Run through the list of mapinfos, and store the data and text info
407 so we can print it at the bottom of the loop. */
408 for (mapinfo_p
= mapinfos
, i
= 0; i
< num
; i
++, mapinfo_p
++)
410 if (!(mapinfo_p
->flags
& flags
))
413 if (mapinfo_p
->ino
== 0) /* Already visited. */
416 map
.info
.vaddr
= mapinfo_p
->vaddr
;
418 err
= devctl (ctl_fd
, DCMD_PROC_MAPDEBUG
, &map
, sizeof (map
), 0);
422 memset (&printme
, 0, sizeof printme
);
423 printme
.dev
= mapinfo_p
->dev
;
424 printme
.ino
= mapinfo_p
->ino
;
425 printme
.text
.addr
= mapinfo_p
->vaddr
;
426 printme
.text
.size
= mapinfo_p
->size
;
427 printme
.text
.flags
= mapinfo_p
->flags
;
428 printme
.text
.offset
= mapinfo_p
->offset
;
429 printme
.text
.debug_vaddr
= map
.info
.vaddr
;
430 strcpy (printme
.name
, map
.info
.path
);
432 /* Check for matching data. */
433 for (mapinfo_p2
= mapinfos
, j
= 0; j
< num
; j
++, mapinfo_p2
++)
435 if (mapinfo_p2
->vaddr
!= mapinfo_p
->vaddr
436 && mapinfo_p2
->ino
== mapinfo_p
->ino
437 && mapinfo_p2
->dev
== mapinfo_p
->dev
)
439 map
.info
.vaddr
= mapinfo_p2
->vaddr
;
441 devctl (ctl_fd
, DCMD_PROC_MAPDEBUG
, &map
, sizeof (map
), 0);
445 if (strcmp (map
.info
.path
, printme
.name
))
448 /* Lower debug_vaddr is always text, if nessessary, swap. */
449 if ((int) map
.info
.vaddr
< (int) printme
.text
.debug_vaddr
)
451 memcpy (&(printme
.data
), &(printme
.text
),
452 sizeof (printme
.data
));
453 printme
.text
.addr
= mapinfo_p2
->vaddr
;
454 printme
.text
.size
= mapinfo_p2
->size
;
455 printme
.text
.flags
= mapinfo_p2
->flags
;
456 printme
.text
.offset
= mapinfo_p2
->offset
;
457 printme
.text
.debug_vaddr
= map
.info
.vaddr
;
461 printme
.data
.addr
= mapinfo_p2
->vaddr
;
462 printme
.data
.size
= mapinfo_p2
->size
;
463 printme
.data
.flags
= mapinfo_p2
->flags
;
464 printme
.data
.offset
= mapinfo_p2
->offset
;
465 printme
.data
.debug_vaddr
= map
.info
.vaddr
;
472 printf_filtered ("%s\n", printme
.name
);
473 printf_filtered ("\ttext=%08x bytes @ 0x%08x\n", printme
.text
.size
,
475 printf_filtered ("\t\tflags=%08x\n", printme
.text
.flags
);
476 printf_filtered ("\t\tdebug=%08x\n", printme
.text
.debug_vaddr
);
477 printf_filtered ("\t\toffset=%016llx\n", printme
.text
.offset
);
478 if (printme
.data
.size
)
480 printf_filtered ("\tdata=%08x bytes @ 0x%08x\n", printme
.data
.size
,
482 printf_filtered ("\t\tflags=%08x\n", printme
.data
.flags
);
483 printf_filtered ("\t\tdebug=%08x\n", printme
.data
.debug_vaddr
);
484 printf_filtered ("\t\toffset=%016llx\n", printme
.data
.offset
);
486 printf_filtered ("\tdev=0x%x\n", printme
.dev
);
487 printf_filtered ("\tino=0x%x\n", (unsigned int) printme
.ino
);
493 /* Print status information about what we're accessing. */
495 procfs_files_info (struct target_ops
*ignore
)
497 struct inferior
*inf
= current_inferior ();
499 printf_unfiltered ("\tUsing the running image of %s %s via %s.\n",
500 inf
->attach_flag
? "attached" : "child",
501 target_pid_to_str (inferior_ptid
), nto_procfs_path
);
504 /* Mark our target-struct as eligible for stray "run" and "attach" commands. */
506 procfs_can_run (void)
511 /* Attach to process PID, then initialize for debugging it. */
513 procfs_attach (char *args
, int from_tty
)
517 struct inferior
*inf
;
520 error_no_arg (_("process-id to attach"));
524 if (pid
== getpid ())
525 error (_("Attaching GDB to itself is not a good idea..."));
529 exec_file
= (char *) get_exec_file (0);
532 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file
,
533 target_pid_to_str (pid_to_ptid (pid
)));
535 printf_unfiltered ("Attaching to %s\n",
536 target_pid_to_str (pid_to_ptid (pid
)));
538 gdb_flush (gdb_stdout
);
540 inferior_ptid
= do_attach (pid_to_ptid (pid
));
541 inf
= add_inferior (pid
);
542 inf
->attach_flag
= 1;
544 push_target (&procfs_ops
);
546 procfs_find_new_threads ();
550 procfs_post_attach (pid_t pid
)
553 solib_create_inferior_hook ();
557 do_attach (ptid_t ptid
)
559 procfs_status status
;
560 struct sigevent event
;
563 snprintf (path
, PATH_MAX
- 1, "%s/%d/as", nto_procfs_path
, PIDGET (ptid
));
564 ctl_fd
= open (path
, O_RDWR
);
566 error (_("Couldn't open proc file %s, error %d (%s)"), path
, errno
,
567 safe_strerror (errno
));
568 if (devctl (ctl_fd
, DCMD_PROC_STOP
, &status
, sizeof (status
), 0) != EOK
)
569 error (_("Couldn't stop process"));
571 /* Define a sigevent for process stopped notification. */
572 event
.sigev_notify
= SIGEV_SIGNAL_THREAD
;
573 event
.sigev_signo
= SIGUSR1
;
574 event
.sigev_code
= 0;
575 event
.sigev_value
.sival_ptr
= NULL
;
576 event
.sigev_priority
= -1;
577 devctl (ctl_fd
, DCMD_PROC_EVENT
, &event
, sizeof (event
), 0);
579 if (devctl (ctl_fd
, DCMD_PROC_STATUS
, &status
, sizeof (status
), 0) == EOK
580 && status
.flags
& _DEBUG_FLAG_STOPPED
)
581 SignalKill (nto_node (), PIDGET (ptid
), 0, SIGCONT
, 0, 0);
582 nto_init_solib_absolute_prefix ();
583 return ptid_build (PIDGET (ptid
), 0, status
.tid
);
586 /* Ask the user what to do when an interrupt is received. */
588 interrupt_query (void)
590 target_terminal_ours ();
592 if (query ("Interrupted while waiting for the program.\n\
593 Give up (and stop debugging it)? "))
595 target_mourn_inferior ();
596 deprecated_throw_reason (RETURN_QUIT
);
599 target_terminal_inferior ();
602 /* The user typed ^C twice. */
604 nto_interrupt_twice (int signo
)
606 signal (signo
, ofunc
);
608 signal (signo
, nto_interrupt_twice
);
612 nto_interrupt (int signo
)
614 /* If this doesn't work, try more severe steps. */
615 signal (signo
, nto_interrupt_twice
);
617 target_stop (inferior_ptid
);
621 procfs_wait (ptid_t ptid
, struct target_waitstatus
*ourstatus
)
625 procfs_status status
;
626 static int exit_signo
= 0; /* To track signals that cause termination. */
628 ourstatus
->kind
= TARGET_WAITKIND_SPURIOUS
;
630 if (ptid_equal (inferior_ptid
, null_ptid
))
632 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
633 ourstatus
->value
.sig
= TARGET_SIGNAL_0
;
639 sigaddset (&set
, SIGUSR1
);
641 devctl (ctl_fd
, DCMD_PROC_STATUS
, &status
, sizeof (status
), 0);
642 while (!(status
.flags
& _DEBUG_FLAG_ISTOP
))
644 ofunc
= (void (*)()) signal (SIGINT
, nto_interrupt
);
645 sigwaitinfo (&set
, &info
);
646 signal (SIGINT
, ofunc
);
647 devctl (ctl_fd
, DCMD_PROC_STATUS
, &status
, sizeof (status
), 0);
650 if (status
.flags
& _DEBUG_FLAG_SSTEP
)
652 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
653 ourstatus
->value
.sig
= TARGET_SIGNAL_TRAP
;
655 /* Was it a breakpoint? */
656 else if (status
.flags
& _DEBUG_FLAG_TRACE
)
658 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
659 ourstatus
->value
.sig
= TARGET_SIGNAL_TRAP
;
661 else if (status
.flags
& _DEBUG_FLAG_ISTOP
)
665 case _DEBUG_WHY_SIGNALLED
:
666 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
667 ourstatus
->value
.sig
=
668 target_signal_from_host (status
.info
.si_signo
);
671 case _DEBUG_WHY_FAULTED
:
672 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
673 if (status
.info
.si_signo
== SIGTRAP
)
675 ourstatus
->value
.sig
= 0;
680 ourstatus
->value
.sig
=
681 target_signal_from_host (status
.info
.si_signo
);
682 exit_signo
= ourstatus
->value
.sig
;
686 case _DEBUG_WHY_TERMINATED
:
690 waitpid (PIDGET (inferior_ptid
), &waitval
, WNOHANG
);
693 /* Abnormal death. */
694 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
695 ourstatus
->value
.sig
= exit_signo
;
700 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
701 ourstatus
->value
.integer
= WEXITSTATUS (waitval
);
707 case _DEBUG_WHY_REQUESTED
:
708 /* We are assuming a requested stop is due to a SIGINT. */
709 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
710 ourstatus
->value
.sig
= TARGET_SIGNAL_INT
;
716 return ptid_build (status
.pid
, 0, status
.tid
);
719 /* Read the current values of the inferior's registers, both the
720 general register set and floating point registers (if supported)
721 and update gdb's idea of their current values. */
723 procfs_fetch_registers (struct regcache
*regcache
, int regno
)
729 procfs_altreg altreg
;
734 procfs_set_thread (inferior_ptid
);
735 if (devctl (ctl_fd
, DCMD_PROC_GETGREG
, ®
, sizeof (reg
), ®size
) == EOK
)
736 nto_supply_gregset (regcache
, (char *) ®
.greg
);
737 if (devctl (ctl_fd
, DCMD_PROC_GETFPREG
, ®
, sizeof (reg
), ®size
)
739 nto_supply_fpregset (regcache
, (char *) ®
.fpreg
);
740 if (devctl (ctl_fd
, DCMD_PROC_GETALTREG
, ®
, sizeof (reg
), ®size
)
742 nto_supply_altregset (regcache
, (char *) ®
.altreg
);
745 /* Copy LEN bytes to/from inferior's memory starting at MEMADDR
746 from/to debugger memory starting at MYADDR. Copy from inferior
747 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
749 Returns the length copied, which is either the LEN argument or
750 zero. This xfer function does not do partial moves, since procfs_ops
751 doesn't allow memory operations to cross below us in the target stack
754 procfs_xfer_memory (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
, int dowrite
,
755 struct mem_attrib
*attrib
, struct target_ops
*target
)
759 if (lseek (ctl_fd
, (off_t
) memaddr
, SEEK_SET
) == (off_t
) memaddr
)
762 nbytes
= write (ctl_fd
, myaddr
, len
);
764 nbytes
= read (ctl_fd
, myaddr
, len
);
771 /* Take a program previously attached to and detaches it.
772 The program resumes execution and will no longer stop
773 on signals, etc. We'd better not have left any breakpoints
774 in the program or it'll die when it hits one. */
776 procfs_detach (char *args
, int from_tty
)
783 char *exec_file
= get_exec_file (0);
786 printf_unfiltered ("Detaching from program: %s %s\n",
787 exec_file
, target_pid_to_str (inferior_ptid
));
788 gdb_flush (gdb_stdout
);
791 siggnal
= atoi (args
);
794 SignalKill (nto_node (), PIDGET (inferior_ptid
), 0, siggnal
, 0, 0);
799 pid
= ptid_get_pid (inferior_ptid
);
800 inferior_ptid
= null_ptid
;
801 detach_inferior (pid
);
803 unpush_target (&procfs_ops
); /* Pop out of handling an inferior. */
807 procfs_breakpoint (CORE_ADDR addr
, int type
, int size
)
814 errno
= devctl (ctl_fd
, DCMD_PROC_BREAK
, &brk
, sizeof (brk
), 0);
821 procfs_insert_breakpoint (struct bp_target_info
*bp_tgt
)
823 return procfs_breakpoint (bp_tgt
->placed_address
, _DEBUG_BREAK_EXEC
, 0);
827 procfs_remove_breakpoint (struct bp_target_info
*bp_tgt
)
829 return procfs_breakpoint (bp_tgt
->placed_address
, _DEBUG_BREAK_EXEC
, -1);
833 procfs_insert_hw_breakpoint (struct bp_target_info
*bp_tgt
)
835 return procfs_breakpoint (bp_tgt
->placed_address
,
836 _DEBUG_BREAK_EXEC
| _DEBUG_BREAK_HW
, 0);
840 procfs_remove_hw_breakpoint (struct bp_target_info
*bp_tgt
)
842 return procfs_breakpoint (bp_tgt
->placed_address
,
843 _DEBUG_BREAK_EXEC
| _DEBUG_BREAK_HW
, -1);
847 procfs_resume (ptid_t ptid
, int step
, enum target_signal signo
)
850 procfs_status status
;
851 sigset_t
*run_fault
= (sigset_t
*) (void *) &run
.fault
;
853 if (ptid_equal (inferior_ptid
, null_ptid
))
856 procfs_set_thread (ptid_equal (ptid
, minus_one_ptid
) ? inferior_ptid
:
859 run
.flags
= _DEBUG_RUN_FAULT
| _DEBUG_RUN_TRACE
;
861 run
.flags
|= _DEBUG_RUN_STEP
;
863 sigemptyset (run_fault
);
864 sigaddset (run_fault
, FLTBPT
);
865 sigaddset (run_fault
, FLTTRACE
);
866 sigaddset (run_fault
, FLTILL
);
867 sigaddset (run_fault
, FLTPRIV
);
868 sigaddset (run_fault
, FLTBOUNDS
);
869 sigaddset (run_fault
, FLTIOVF
);
870 sigaddset (run_fault
, FLTIZDIV
);
871 sigaddset (run_fault
, FLTFPE
);
872 /* Peter V will be changing this at some point. */
873 sigaddset (run_fault
, FLTPAGE
);
875 run
.flags
|= _DEBUG_RUN_ARM
;
877 sigemptyset (&run
.trace
);
879 signal_to_pass
= target_signal_to_host (signo
);
883 devctl (ctl_fd
, DCMD_PROC_STATUS
, &status
, sizeof (status
), 0);
884 signal_to_pass
= target_signal_to_host (signo
);
885 if (status
.why
& (_DEBUG_WHY_SIGNALLED
| _DEBUG_WHY_FAULTED
))
887 if (signal_to_pass
!= status
.info
.si_signo
)
889 SignalKill (nto_node (), PIDGET (inferior_ptid
), 0,
890 signal_to_pass
, 0, 0);
891 run
.flags
|= _DEBUG_RUN_CLRFLT
| _DEBUG_RUN_CLRSIG
;
893 else /* Let it kill the program without telling us. */
894 sigdelset (&run
.trace
, signal_to_pass
);
898 run
.flags
|= _DEBUG_RUN_CLRSIG
| _DEBUG_RUN_CLRFLT
;
900 errno
= devctl (ctl_fd
, DCMD_PROC_RUN
, &run
, sizeof (run
), 0);
903 perror ("run error!\n");
909 procfs_mourn_inferior (void)
911 if (!ptid_equal (inferior_ptid
, null_ptid
))
913 SignalKill (nto_node (), PIDGET (inferior_ptid
), 0, SIGKILL
, 0, 0);
916 inferior_ptid
= null_ptid
;
918 unpush_target (&procfs_ops
);
919 generic_mourn_inferior ();
922 /* This function breaks up an argument string into an argument
923 vector suitable for passing to execvp().
924 E.g., on "run a b c d" this routine would get as input
925 the string "a b c d", and as output it would fill in argv with
926 the four arguments "a", "b", "c", "d". The only additional
927 functionality is simple quoting. The gdb command:
929 will fill in argv with the three args "a", "b c d", "e". */
931 breakup_args (char *scratch
, char **argv
)
933 char *pp
, *cp
= scratch
;
938 /* Scan past leading separators. */
940 while (*cp
== ' ' || *cp
== '\t' || *cp
== '\n')
943 /* Break if at end of string. */
951 quoting
= strchr (cp
, '"') ? 1 : 0;
956 /* Scan for next arg separator. */
959 cp
= strchr (pp
, '"');
960 if ((cp
== NULL
) || (!quoting
))
961 cp
= strchr (pp
, ' ');
963 cp
= strchr (pp
, '\t');
965 cp
= strchr (pp
, '\n');
967 /* No separators => end of string => break. */
974 /* Replace the separator with a terminator. */
978 /* Execv requires a null-terminated arg vector. */
983 procfs_create_inferior (char *exec_file
, char *allargs
, char **env
,
986 struct inheritance inherit
;
990 const char *in
= "", *out
= "", *err
= "";
993 const char *inferior_io_terminal
= get_inferior_io_terminal ();
994 struct inferior
*inf
;
996 argv
= xmalloc (((strlen (allargs
) + 1) / (unsigned) 2 + 2) *
998 argv
[0] = get_exec_file (1);
1002 argv
[0] = exec_file
;
1007 args
= xstrdup (allargs
);
1008 breakup_args (args
, exec_file
? &argv
[1] : &argv
[0]);
1010 argv
= nto_parse_redirection (argv
, &in
, &out
, &err
);
1012 fds
[0] = STDIN_FILENO
;
1013 fds
[1] = STDOUT_FILENO
;
1014 fds
[2] = STDERR_FILENO
;
1016 /* If the user specified I/O via gdb's --tty= arg, use it, but only
1017 if the i/o is not also being specified via redirection. */
1018 if (inferior_io_terminal
)
1021 in
= inferior_io_terminal
;
1023 out
= inferior_io_terminal
;
1025 err
= inferior_io_terminal
;
1030 fd
= open (in
, O_RDONLY
);
1038 fd
= open (out
, O_WRONLY
);
1046 fd
= open (err
, O_WRONLY
);
1053 /* Clear any pending SIGUSR1's but keep the behavior the same. */
1054 signal (SIGUSR1
, signal (SIGUSR1
, SIG_IGN
));
1057 sigaddset (&set
, SIGUSR1
);
1058 sigprocmask (SIG_UNBLOCK
, &set
, NULL
);
1060 memset (&inherit
, 0, sizeof (inherit
));
1062 if (ND_NODE_CMP (nto_procfs_node
, ND_LOCAL_NODE
) != 0)
1064 inherit
.nd
= nto_node ();
1065 inherit
.flags
|= SPAWN_SETND
;
1066 inherit
.flags
&= ~SPAWN_EXEC
;
1068 inherit
.flags
|= SPAWN_SETGROUP
| SPAWN_HOLD
;
1069 inherit
.pgroup
= SPAWN_NEWPGROUP
;
1070 pid
= spawnp (argv
[0], 3, fds
, &inherit
, argv
,
1071 ND_NODE_CMP (nto_procfs_node
, ND_LOCAL_NODE
) == 0 ? env
: 0);
1074 sigprocmask (SIG_BLOCK
, &set
, NULL
);
1077 error (_("Error spawning %s: %d (%s)"), argv
[0], errno
,
1078 safe_strerror (errno
));
1080 if (fds
[0] != STDIN_FILENO
)
1082 if (fds
[1] != STDOUT_FILENO
)
1084 if (fds
[2] != STDERR_FILENO
)
1087 inferior_ptid
= do_attach (pid_to_ptid (pid
));
1088 procfs_find_new_threads ();
1090 inf
= add_inferior (pid
);
1091 inf
->attach_flag
= 0;
1093 flags
= _DEBUG_FLAG_KLC
; /* Kill-on-Last-Close flag. */
1094 errn
= devctl (ctl_fd
, DCMD_PROC_SET_FLAG
, &flags
, sizeof (flags
), 0);
1097 /* FIXME: expected warning? */
1098 /* warning( "Failed to set Kill-on-Last-Close flag: errno = %d(%s)\n",
1099 errn, strerror(errn) ); */
1101 push_target (&procfs_ops
);
1102 target_terminal_init ();
1104 if (exec_bfd
!= NULL
1105 || (symfile_objfile
!= NULL
&& symfile_objfile
->obfd
!= NULL
))
1106 solib_create_inferior_hook ();
1110 procfs_stop (ptid_t ptid
)
1112 devctl (ctl_fd
, DCMD_PROC_STOP
, NULL
, 0, 0);
1116 procfs_kill_inferior (void)
1118 target_mourn_inferior ();
1121 /* Store register REGNO, or all registers if REGNO == -1, from the contents
1124 procfs_prepare_to_store (struct regcache
*regcache
)
1128 /* Fill buf with regset and return devctl cmd to do the setting. Return
1129 -1 if we fail to get the regset. Store size of regset in regsize. */
1131 get_regset (int regset
, char *buf
, int bufsize
, int *regsize
)
1133 int dev_get
, dev_set
;
1136 case NTO_REG_GENERAL
:
1137 dev_get
= DCMD_PROC_GETGREG
;
1138 dev_set
= DCMD_PROC_SETGREG
;
1142 dev_get
= DCMD_PROC_GETFPREG
;
1143 dev_set
= DCMD_PROC_SETFPREG
;
1147 dev_get
= DCMD_PROC_GETALTREG
;
1148 dev_set
= DCMD_PROC_SETALTREG
;
1151 case NTO_REG_SYSTEM
:
1155 if (devctl (ctl_fd
, dev_get
, &buf
, bufsize
, regsize
) != EOK
)
1162 procfs_store_registers (struct regcache
*regcache
, int regno
)
1168 procfs_altreg altreg
;
1172 int len
, regset
, regsize
, dev_set
, err
;
1175 if (ptid_equal (inferior_ptid
, null_ptid
))
1177 procfs_set_thread (inferior_ptid
);
1181 for (regset
= NTO_REG_GENERAL
; regset
< NTO_REG_END
; regset
++)
1183 dev_set
= get_regset (regset
, (char *) ®
,
1184 sizeof (reg
), ®size
);
1188 if (nto_regset_fill (regcache
, regset
, (char *) ®
) == -1)
1191 err
= devctl (ctl_fd
, dev_set
, ®
, regsize
, 0);
1193 fprintf_unfiltered (gdb_stderr
,
1194 "Warning unable to write regset %d: %s\n",
1195 regno
, safe_strerror (err
));
1200 regset
= nto_regset_id (regno
);
1204 dev_set
= get_regset (regset
, (char *) ®
, sizeof (reg
), ®size
);
1208 len
= nto_register_area (get_regcache_arch (regcache
),
1209 regno
, regset
, &off
);
1214 regcache_raw_collect (regcache
, regno
, (char *) ®
+ off
);
1216 err
= devctl (ctl_fd
, dev_set
, ®
, regsize
, 0);
1218 fprintf_unfiltered (gdb_stderr
,
1219 "Warning unable to write regset %d: %s\n", regno
,
1220 safe_strerror (err
));
1225 notice_signals (void)
1229 for (signo
= 1; signo
< NSIG
; signo
++)
1231 if (signal_stop_state (target_signal_from_host (signo
)) == 0
1232 && signal_print_state (target_signal_from_host (signo
)) == 0
1233 && signal_pass_state (target_signal_from_host (signo
)) == 1)
1234 sigdelset (&run
.trace
, signo
);
1236 sigaddset (&run
.trace
, signo
);
1240 /* When the user changes the state of gdb's signal handling via the
1241 "handle" command, this function gets called to see if any change
1242 in the /proc interface is required. It is also called internally
1243 by other /proc interface functions to initialize the state of
1244 the traced signal set. */
1246 procfs_notice_signals (ptid_t ptid
)
1248 sigemptyset (&run
.trace
);
1252 static struct tidinfo
*
1253 procfs_thread_info (pid_t pid
, short tid
)
1260 procfs_pid_to_str (ptid_t ptid
)
1262 static char buf
[1024];
1264 struct tidinfo
*tip
;
1266 pid
= ptid_get_pid (ptid
);
1267 tid
= ptid_get_tid (ptid
);
1269 n
= snprintf (buf
, 1023, "process %d", pid
);
1272 tip
= procfs_thread_info (pid
, tid
);
1274 snprintf (&buf
[n
], 1023, " (state = 0x%02x)", tip
->state
);
1281 init_procfs_ops (void)
1283 procfs_ops
.to_shortname
= "procfs";
1284 procfs_ops
.to_longname
= "QNX Neutrino procfs child process";
1286 "QNX Neutrino procfs child process (started by the \"run\" command).\n\
1287 target procfs <node>";
1288 procfs_ops
.to_open
= procfs_open
;
1289 procfs_ops
.to_attach
= procfs_attach
;
1290 procfs_ops
.to_post_attach
= procfs_post_attach
;
1291 procfs_ops
.to_detach
= procfs_detach
;
1292 procfs_ops
.to_resume
= procfs_resume
;
1293 procfs_ops
.to_wait
= procfs_wait
;
1294 procfs_ops
.to_fetch_registers
= procfs_fetch_registers
;
1295 procfs_ops
.to_store_registers
= procfs_store_registers
;
1296 procfs_ops
.to_prepare_to_store
= procfs_prepare_to_store
;
1297 procfs_ops
.deprecated_xfer_memory
= procfs_xfer_memory
;
1298 procfs_ops
.to_files_info
= procfs_files_info
;
1299 procfs_ops
.to_insert_breakpoint
= procfs_insert_breakpoint
;
1300 procfs_ops
.to_remove_breakpoint
= procfs_remove_breakpoint
;
1301 procfs_ops
.to_can_use_hw_breakpoint
= procfs_can_use_hw_breakpoint
;
1302 procfs_ops
.to_insert_hw_breakpoint
= procfs_insert_hw_breakpoint
;
1303 procfs_ops
.to_remove_hw_breakpoint
= procfs_remove_breakpoint
;
1304 procfs_ops
.to_insert_watchpoint
= procfs_insert_hw_watchpoint
;
1305 procfs_ops
.to_remove_watchpoint
= procfs_remove_hw_watchpoint
;
1306 procfs_ops
.to_stopped_by_watchpoint
= procfs_stopped_by_watchpoint
;
1307 procfs_ops
.to_terminal_init
= terminal_init_inferior
;
1308 procfs_ops
.to_terminal_inferior
= terminal_inferior
;
1309 procfs_ops
.to_terminal_ours_for_output
= terminal_ours_for_output
;
1310 procfs_ops
.to_terminal_ours
= terminal_ours
;
1311 procfs_ops
.to_terminal_info
= child_terminal_info
;
1312 procfs_ops
.to_kill
= procfs_kill_inferior
;
1313 procfs_ops
.to_create_inferior
= procfs_create_inferior
;
1314 procfs_ops
.to_mourn_inferior
= procfs_mourn_inferior
;
1315 procfs_ops
.to_can_run
= procfs_can_run
;
1316 procfs_ops
.to_notice_signals
= procfs_notice_signals
;
1317 procfs_ops
.to_thread_alive
= procfs_thread_alive
;
1318 procfs_ops
.to_find_new_threads
= procfs_find_new_threads
;
1319 procfs_ops
.to_pid_to_str
= procfs_pid_to_str
;
1320 procfs_ops
.to_stop
= procfs_stop
;
1321 procfs_ops
.to_stratum
= process_stratum
;
1322 procfs_ops
.to_has_all_memory
= 1;
1323 procfs_ops
.to_has_memory
= 1;
1324 procfs_ops
.to_has_stack
= 1;
1325 procfs_ops
.to_has_registers
= 1;
1326 procfs_ops
.to_has_execution
= 1;
1327 procfs_ops
.to_magic
= OPS_MAGIC
;
1328 procfs_ops
.to_have_continuable_watchpoint
= 1;
1331 #define OSTYPE_NTO 1
1334 _initialize_procfs (void)
1339 add_target (&procfs_ops
);
1341 /* We use SIGUSR1 to gain control after we block waiting for a process.
1342 We use sigwaitevent to wait. */
1344 sigaddset (&set
, SIGUSR1
);
1345 sigprocmask (SIG_BLOCK
, &set
, NULL
);
1347 /* Set up trace and fault sets, as gdb expects them. */
1348 sigemptyset (&run
.trace
);
1350 /* Stuff some information. */
1351 nto_cpuinfo_flags
= SYSPAGE_ENTRY (cpuinfo
)->flags
;
1352 nto_cpuinfo_valid
= 1;
1354 add_info ("pidlist", procfs_pidlist
, _("pidlist"));
1355 add_info ("meminfo", procfs_meminfo
, _("memory information"));
1357 nto_is_nto_target
= procfs_is_nto_target
;
1362 procfs_hw_watchpoint (int addr
, int len
, int type
)
1369 brk
.type
= _DEBUG_BREAK_RD
;
1371 case 2: /* Read/Write. */
1372 brk
.type
= _DEBUG_BREAK_RW
;
1374 default: /* Modify. */
1375 /* FIXME: brk.type = _DEBUG_BREAK_RWM gives EINVAL for some reason. */
1376 brk
.type
= _DEBUG_BREAK_RW
;
1378 brk
.type
|= _DEBUG_BREAK_HW
; /* Always ask for HW. */
1382 errno
= devctl (ctl_fd
, DCMD_PROC_BREAK
, &brk
, sizeof (brk
), 0);
1385 perror ("Failed to set hardware watchpoint");
1392 procfs_can_use_hw_breakpoint (int type
, int cnt
, int othertype
)
1398 procfs_remove_hw_watchpoint (CORE_ADDR addr
, int len
, int type
)
1400 return procfs_hw_watchpoint (addr
, -1, type
);
1404 procfs_insert_hw_watchpoint (CORE_ADDR addr
, int len
, int type
)
1406 return procfs_hw_watchpoint (addr
, len
, type
);
1410 procfs_stopped_by_watchpoint (void)