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 2003 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 2 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, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
29 #include <sys/debug.h>
30 #include <sys/procfs.h>
31 #include <sys/neutrino.h>
32 #include <sys/syspage.h>
33 #include "gdb_dirent.h"
34 #include <sys/netmgr.h>
36 #include "exceptions.h"
37 #include "gdb_string.h"
42 #include "gdbthread.h"
48 #define _DEBUG_FLAG_TRACE (_DEBUG_FLAG_TRACE_EXEC|_DEBUG_FLAG_TRACE_RD|\
49 _DEBUG_FLAG_TRACE_WR|_DEBUG_FLAG_TRACE_MODIFY)
51 static struct target_ops procfs_ops
;
55 static void (*ofunc
) ();
57 static procfs_run run
;
59 static void procfs_open (char *, int);
61 static int procfs_can_run (void);
63 static ptid_t
procfs_wait (ptid_t
, struct target_waitstatus
*);
65 static int procfs_xfer_memory (CORE_ADDR
, char *, int, int,
66 struct mem_attrib
*attrib
,
69 static void procfs_fetch_registers (int);
71 static void notice_signals (void);
73 static void init_procfs_ops (void);
75 static ptid_t
do_attach (ptid_t ptid
);
77 static int procfs_can_use_hw_breakpoint (int, int, int);
79 static int procfs_insert_hw_breakpoint (CORE_ADDR
, char *);
81 static int procfs_remove_hw_breakpoint (CORE_ADDR addr
, char *);
83 static int procfs_insert_hw_watchpoint (CORE_ADDR addr
, int len
, int type
);
85 static int procfs_remove_hw_watchpoint (CORE_ADDR addr
, int len
, int type
);
87 static int procfs_stopped_by_watchpoint (void);
89 /* These two globals are only ever set in procfs_open(), but are
90 referenced elsewhere. 'nto_procfs_node' is a flag used to say
91 whether we are local, or we should get the current node descriptor
92 for the remote QNX node. */
93 static char nto_procfs_path
[PATH_MAX
] = { "/proc" };
94 static unsigned nto_procfs_node
= ND_LOCAL_NODE
;
96 /* Return the current QNX Node, or error out. This is a simple
97 wrapper for the netmgr_strtond() function. The reason this
98 is required is because QNX node descriptors are transient so
99 we have to re-acquire them every time. */
105 if (ND_NODE_CMP (nto_procfs_node
, ND_LOCAL_NODE
) == 0)
106 return ND_LOCAL_NODE
;
108 node
= netmgr_strtond (nto_procfs_path
, 0);
110 error (_("Lost the QNX node. Debug session probably over."));
115 static enum gdb_osabi
116 procfs_is_nto_target (bfd
*abfd
)
118 return GDB_OSABI_QNXNTO
;
121 /* This is called when we call 'target procfs <arg>' from the (gdb) prompt.
122 For QNX6 (nto), the only valid arg will be a QNX node string,
123 eg: "/net/some_node". If arg is not a valid QNX node, we will
126 procfs_open (char *arg
, int from_tty
)
132 procfs_sysinfo
*sysinfo
;
134 nto_is_nto_target
= procfs_is_nto_target
;
136 /* Set the default node used for spawning to this one,
137 and only override it if there is a valid arg. */
139 nto_procfs_node
= ND_LOCAL_NODE
;
140 nodestr
= arg
? xstrdup (arg
) : arg
;
146 nto_procfs_node
= netmgr_strtond (nodestr
, &endstr
);
147 if (nto_procfs_node
== -1)
149 if (errno
== ENOTSUP
)
150 printf_filtered ("QNX Net Manager not found.\n");
151 printf_filtered ("Invalid QNX node %s: error %d (%s).\n", nodestr
,
152 errno
, safe_strerror (errno
));
155 nto_procfs_node
= ND_LOCAL_NODE
;
159 if (*(endstr
- 1) == '/')
165 snprintf (nto_procfs_path
, PATH_MAX
- 1, "%s%s", nodestr
? nodestr
: "",
170 fd
= open (nto_procfs_path
, O_RDONLY
);
173 printf_filtered ("Error opening %s : %d (%s)\n", nto_procfs_path
, errno
,
174 safe_strerror (errno
));
175 error (_("Invalid procfs arg"));
178 sysinfo
= (void *) buffer
;
179 if (devctl (fd
, DCMD_PROC_SYSINFO
, sysinfo
, sizeof buffer
, 0) != EOK
)
181 printf_filtered ("Error getting size: %d (%s)\n", errno
,
182 safe_strerror (errno
));
184 error (_("Devctl failed."));
188 total_size
= sysinfo
->total_size
;
189 sysinfo
= alloca (total_size
);
192 printf_filtered ("Memory error: %d (%s)\n", errno
,
193 safe_strerror (errno
));
195 error (_("alloca failed."));
199 if (devctl (fd
, DCMD_PROC_SYSINFO
, sysinfo
, total_size
, 0) != EOK
)
201 printf_filtered ("Error getting sysinfo: %d (%s)\n", errno
,
202 safe_strerror (errno
));
204 error (_("Devctl failed."));
209 nto_map_arch_to_cputype (TARGET_ARCHITECTURE
->arch_name
))
212 error (_("Invalid target CPU."));
218 printf_filtered ("Debugging using %s\n", nto_procfs_path
);
222 procfs_set_thread (ptid_t ptid
)
226 tid
= ptid_get_tid (ptid
);
227 devctl (ctl_fd
, DCMD_PROC_CURTHREAD
, &tid
, sizeof (tid
), 0);
230 /* Return nonzero if the thread TH is still alive. */
232 procfs_thread_alive (ptid_t ptid
)
236 tid
= ptid_get_tid (ptid
);
237 if (devctl (ctl_fd
, DCMD_PROC_CURTHREAD
, &tid
, sizeof (tid
), 0) == EOK
)
243 procfs_find_new_threads (void)
245 procfs_status status
;
252 pid
= ptid_get_pid (inferior_ptid
);
254 for (status
.tid
= 1;; ++status
.tid
)
256 if (devctl (ctl_fd
, DCMD_PROC_TIDSTATUS
, &status
, sizeof (status
), 0)
257 != EOK
&& status
.tid
!= 0)
259 ptid
= ptid_build (pid
, 0, status
.tid
);
260 if (!in_thread_list (ptid
))
267 procfs_pidlist (char *args
, int from_tty
)
270 struct dirent
*dirp
= NULL
;
273 procfs_info
*pidinfo
= NULL
;
274 procfs_debuginfo
*info
= NULL
;
275 procfs_status
*status
= NULL
;
276 pid_t num_threads
= 0;
280 dp
= opendir (nto_procfs_path
);
283 fprintf_unfiltered (gdb_stderr
, "failed to opendir \"%s\" - %d (%s)",
284 nto_procfs_path
, errno
, safe_strerror (errno
));
288 /* Start scan at first pid. */
293 /* Get the right pid and procfs path for the pid. */
302 snprintf (buf
, 511, "%s/%s/as", nto_procfs_path
, dirp
->d_name
);
303 pid
= atoi (dirp
->d_name
);
307 /* Open the procfs path. */
308 fd
= open (buf
, O_RDONLY
);
311 fprintf_unfiltered (gdb_stderr
, "failed to open %s - %d (%s)\n",
312 buf
, errno
, safe_strerror (errno
));
317 pidinfo
= (procfs_info
*) buf
;
318 if (devctl (fd
, DCMD_PROC_INFO
, pidinfo
, sizeof (buf
), 0) != EOK
)
320 fprintf_unfiltered (gdb_stderr
,
321 "devctl DCMD_PROC_INFO failed - %d (%s)\n",
322 errno
, safe_strerror (errno
));
325 num_threads
= pidinfo
->num_threads
;
327 info
= (procfs_debuginfo
*) buf
;
328 if (devctl (fd
, DCMD_PROC_MAPDEBUG_BASE
, info
, sizeof (buf
), 0) != EOK
)
329 strcpy (name
, "unavailable");
331 strcpy (name
, info
->path
);
333 /* Collect state info on all the threads. */
334 status
= (procfs_status
*) buf
;
335 for (status
->tid
= 1; status
->tid
<= num_threads
; status
->tid
++)
337 if (devctl (fd
, DCMD_PROC_TIDSTATUS
, status
, sizeof (buf
), 0) != EOK
340 if (status
->tid
!= 0)
341 printf_filtered ("%s - %d/%d\n", name
, pid
, status
->tid
);
345 while (dirp
!= NULL
);
353 procfs_meminfo (char *args
, int from_tty
)
355 procfs_mapinfo
*mapinfos
= NULL
;
356 static int num_mapinfos
= 0;
357 procfs_mapinfo
*mapinfo_p
, *mapinfo_p2
;
358 int flags
= ~0, err
, num
, i
, j
;
362 procfs_debuginfo info
;
363 char buff
[_POSIX_PATH_MAX
];
371 unsigned debug_vaddr
;
372 unsigned long long offset
;
377 unsigned long long ino
;
384 /* Get the number of map entrys. */
385 err
= devctl (ctl_fd
, DCMD_PROC_MAPINFO
, NULL
, 0, &num
);
388 printf ("failed devctl num mapinfos - %d (%s)\n", err
,
389 safe_strerror (err
));
393 mapinfos
= xmalloc (num
* sizeof (procfs_mapinfo
));
396 mapinfo_p
= mapinfos
;
398 /* Fill the map entrys. */
399 err
= devctl (ctl_fd
, DCMD_PROC_MAPINFO
, mapinfo_p
, num
400 * sizeof (procfs_mapinfo
), &num
);
403 printf ("failed devctl mapinfos - %d (%s)\n", err
, safe_strerror (err
));
408 num
= min (num
, num_mapinfos
);
410 /* Run through the list of mapinfos, and store the data and text info
411 so we can print it at the bottom of the loop. */
412 for (mapinfo_p
= mapinfos
, i
= 0; i
< num
; i
++, mapinfo_p
++)
414 if (!(mapinfo_p
->flags
& flags
))
417 if (mapinfo_p
->ino
== 0) /* Already visited. */
420 map
.info
.vaddr
= mapinfo_p
->vaddr
;
422 err
= devctl (ctl_fd
, DCMD_PROC_MAPDEBUG
, &map
, sizeof (map
), 0);
426 memset (&printme
, 0, sizeof printme
);
427 printme
.dev
= mapinfo_p
->dev
;
428 printme
.ino
= mapinfo_p
->ino
;
429 printme
.text
.addr
= mapinfo_p
->vaddr
;
430 printme
.text
.size
= mapinfo_p
->size
;
431 printme
.text
.flags
= mapinfo_p
->flags
;
432 printme
.text
.offset
= mapinfo_p
->offset
;
433 printme
.text
.debug_vaddr
= map
.info
.vaddr
;
434 strcpy (printme
.name
, map
.info
.path
);
436 /* Check for matching data. */
437 for (mapinfo_p2
= mapinfos
, j
= 0; j
< num
; j
++, mapinfo_p2
++)
439 if (mapinfo_p2
->vaddr
!= mapinfo_p
->vaddr
440 && mapinfo_p2
->ino
== mapinfo_p
->ino
441 && mapinfo_p2
->dev
== mapinfo_p
->dev
)
443 map
.info
.vaddr
= mapinfo_p2
->vaddr
;
445 devctl (ctl_fd
, DCMD_PROC_MAPDEBUG
, &map
, sizeof (map
), 0);
449 if (strcmp (map
.info
.path
, printme
.name
))
452 /* Lower debug_vaddr is always text, if nessessary, swap. */
453 if ((int) map
.info
.vaddr
< (int) printme
.text
.debug_vaddr
)
455 memcpy (&(printme
.data
), &(printme
.text
),
456 sizeof (printme
.data
));
457 printme
.text
.addr
= mapinfo_p2
->vaddr
;
458 printme
.text
.size
= mapinfo_p2
->size
;
459 printme
.text
.flags
= mapinfo_p2
->flags
;
460 printme
.text
.offset
= mapinfo_p2
->offset
;
461 printme
.text
.debug_vaddr
= map
.info
.vaddr
;
465 printme
.data
.addr
= mapinfo_p2
->vaddr
;
466 printme
.data
.size
= mapinfo_p2
->size
;
467 printme
.data
.flags
= mapinfo_p2
->flags
;
468 printme
.data
.offset
= mapinfo_p2
->offset
;
469 printme
.data
.debug_vaddr
= map
.info
.vaddr
;
476 printf_filtered ("%s\n", printme
.name
);
477 printf_filtered ("\ttext=%08x bytes @ 0x%08x\n", printme
.text
.size
,
479 printf_filtered ("\t\tflags=%08x\n", printme
.text
.flags
);
480 printf_filtered ("\t\tdebug=%08x\n", printme
.text
.debug_vaddr
);
481 printf_filtered ("\t\toffset=%016llx\n", printme
.text
.offset
);
482 if (printme
.data
.size
)
484 printf_filtered ("\tdata=%08x bytes @ 0x%08x\n", printme
.data
.size
,
486 printf_filtered ("\t\tflags=%08x\n", printme
.data
.flags
);
487 printf_filtered ("\t\tdebug=%08x\n", printme
.data
.debug_vaddr
);
488 printf_filtered ("\t\toffset=%016llx\n", printme
.data
.offset
);
490 printf_filtered ("\tdev=0x%x\n", printme
.dev
);
491 printf_filtered ("\tino=0x%x\n", (unsigned int) printme
.ino
);
497 /* Print status information about what we're accessing. */
499 procfs_files_info (struct target_ops
*ignore
)
501 printf_unfiltered ("\tUsing the running image of %s %s via %s.\n",
502 attach_flag
? "attached" : "child",
503 target_pid_to_str (inferior_ptid
), nto_procfs_path
);
506 /* Mark our target-struct as eligible for stray "run" and "attach" commands. */
508 procfs_can_run (void)
513 /* Attach to process PID, then initialize for debugging it. */
515 procfs_attach (char *args
, int from_tty
)
521 error_no_arg (_("process-id to attach"));
525 if (pid
== getpid ())
526 error (_("Attaching GDB to itself is not a good idea..."));
530 exec_file
= (char *) get_exec_file (0);
533 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file
,
534 target_pid_to_str (pid_to_ptid (pid
)));
536 printf_unfiltered ("Attaching to %s\n",
537 target_pid_to_str (pid_to_ptid (pid
)));
539 gdb_flush (gdb_stdout
);
541 inferior_ptid
= do_attach (pid_to_ptid (pid
));
542 push_target (&procfs_ops
);
546 procfs_post_attach (pid_t pid
)
549 solib_create_inferior_hook ();
553 do_attach (ptid_t ptid
)
555 procfs_status status
;
556 struct sigevent event
;
559 snprintf (path
, PATH_MAX
- 1, "%s/%d/as", nto_procfs_path
, PIDGET (ptid
));
560 ctl_fd
= open (path
, O_RDWR
);
562 error (_("Couldn't open proc file %s, error %d (%s)"), path
, errno
,
563 safe_strerror (errno
));
564 if (devctl (ctl_fd
, DCMD_PROC_STOP
, &status
, sizeof (status
), 0) != EOK
)
565 error (_("Couldn't stop process"));
567 /* Define a sigevent for process stopped notification. */
568 event
.sigev_notify
= SIGEV_SIGNAL_THREAD
;
569 event
.sigev_signo
= SIGUSR1
;
570 event
.sigev_code
= 0;
571 event
.sigev_value
.sival_ptr
= NULL
;
572 event
.sigev_priority
= -1;
573 devctl (ctl_fd
, DCMD_PROC_EVENT
, &event
, sizeof (event
), 0);
575 if (devctl (ctl_fd
, DCMD_PROC_STATUS
, &status
, sizeof (status
), 0) == EOK
576 && status
.flags
& _DEBUG_FLAG_STOPPED
)
577 SignalKill (nto_node (), PIDGET (ptid
), 0, SIGCONT
, 0, 0);
579 nto_init_solib_absolute_prefix ();
583 /* Ask the user what to do when an interrupt is received. */
585 interrupt_query (void)
587 target_terminal_ours ();
589 if (query ("Interrupted while waiting for the program.\n\
590 Give up (and stop debugging it)? "))
592 target_mourn_inferior ();
593 deprecated_throw_reason (RETURN_QUIT
);
596 target_terminal_inferior ();
599 /* The user typed ^C twice. */
601 nto_interrupt_twice (int signo
)
603 signal (signo
, ofunc
);
605 signal (signo
, nto_interrupt_twice
);
609 nto_interrupt (int signo
)
611 /* If this doesn't work, try more severe steps. */
612 signal (signo
, nto_interrupt_twice
);
618 procfs_wait (ptid_t ptid
, struct target_waitstatus
*ourstatus
)
622 procfs_status status
;
623 static int exit_signo
= 0; /* To track signals that cause termination. */
625 ourstatus
->kind
= TARGET_WAITKIND_SPURIOUS
;
627 if (ptid_equal (inferior_ptid
, null_ptid
))
629 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
630 ourstatus
->value
.sig
= TARGET_SIGNAL_0
;
636 sigaddset (&set
, SIGUSR1
);
638 devctl (ctl_fd
, DCMD_PROC_STATUS
, &status
, sizeof (status
), 0);
639 while (!(status
.flags
& _DEBUG_FLAG_ISTOP
))
641 ofunc
= (void (*)()) signal (SIGINT
, nto_interrupt
);
642 sigwaitinfo (&set
, &info
);
643 signal (SIGINT
, ofunc
);
644 devctl (ctl_fd
, DCMD_PROC_STATUS
, &status
, sizeof (status
), 0);
647 if (status
.flags
& _DEBUG_FLAG_SSTEP
)
649 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
650 ourstatus
->value
.sig
= TARGET_SIGNAL_TRAP
;
652 /* Was it a breakpoint? */
653 else if (status
.flags
& _DEBUG_FLAG_TRACE
)
655 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
656 ourstatus
->value
.sig
= TARGET_SIGNAL_TRAP
;
658 else if (status
.flags
& _DEBUG_FLAG_ISTOP
)
662 case _DEBUG_WHY_SIGNALLED
:
663 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
664 ourstatus
->value
.sig
=
665 target_signal_from_host (status
.info
.si_signo
);
668 case _DEBUG_WHY_FAULTED
:
669 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
670 if (status
.info
.si_signo
== SIGTRAP
)
672 ourstatus
->value
.sig
= 0;
677 ourstatus
->value
.sig
=
678 target_signal_from_host (status
.info
.si_signo
);
679 exit_signo
= ourstatus
->value
.sig
;
683 case _DEBUG_WHY_TERMINATED
:
687 waitpid (PIDGET (inferior_ptid
), &waitval
, WNOHANG
);
690 /* Abnormal death. */
691 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
692 ourstatus
->value
.sig
= exit_signo
;
697 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
698 ourstatus
->value
.integer
= WEXITSTATUS (waitval
);
704 case _DEBUG_WHY_REQUESTED
:
705 /* We are assuming a requested stop is due to a SIGINT. */
706 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
707 ourstatus
->value
.sig
= TARGET_SIGNAL_INT
;
713 return inferior_ptid
;
716 /* Read the current values of the inferior's registers, both the
717 general register set and floating point registers (if supported)
718 and update gdb's idea of their current values. */
720 procfs_fetch_registers (int regno
)
726 procfs_altreg altreg
;
731 procfs_set_thread (inferior_ptid
);
732 if (devctl (ctl_fd
, DCMD_PROC_GETGREG
, ®
, sizeof (reg
), ®size
) == EOK
)
733 nto_supply_gregset ((char *) ®
.greg
);
734 if (devctl (ctl_fd
, DCMD_PROC_GETFPREG
, ®
, sizeof (reg
), ®size
)
736 nto_supply_fpregset ((char *) ®
.fpreg
);
737 if (devctl (ctl_fd
, DCMD_PROC_GETALTREG
, ®
, sizeof (reg
), ®size
)
739 nto_supply_altregset ((char *) ®
.altreg
);
742 /* Copy LEN bytes to/from inferior's memory starting at MEMADDR
743 from/to debugger memory starting at MYADDR. Copy from inferior
744 if DOWRITE is zero or to inferior if DOWRITE is nonzero.
746 Returns the length copied, which is either the LEN argument or
747 zero. This xfer function does not do partial moves, since procfs_ops
748 doesn't allow memory operations to cross below us in the target stack
751 procfs_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int dowrite
,
752 struct mem_attrib
*attrib
, struct target_ops
*target
)
756 if (lseek (ctl_fd
, (off_t
) memaddr
, SEEK_SET
) == (off_t
) memaddr
)
759 nbytes
= write (ctl_fd
, myaddr
, len
);
761 nbytes
= read (ctl_fd
, myaddr
, len
);
768 /* Take a program previously attached to and detaches it.
769 The program resumes execution and will no longer stop
770 on signals, etc. We'd better not have left any breakpoints
771 in the program or it'll die when it hits one. */
773 procfs_detach (char *args
, int from_tty
)
779 char *exec_file
= get_exec_file (0);
782 printf_unfiltered ("Detaching from program: %s %s\n",
783 exec_file
, target_pid_to_str (inferior_ptid
));
784 gdb_flush (gdb_stdout
);
787 siggnal
= atoi (args
);
790 SignalKill (nto_node (), PIDGET (inferior_ptid
), 0, siggnal
, 0, 0);
795 inferior_ptid
= null_ptid
;
797 unpush_target (&procfs_ops
); /* Pop out of handling an inferior. */
801 procfs_breakpoint (CORE_ADDR addr
, int type
, int size
)
808 errno
= devctl (ctl_fd
, DCMD_PROC_BREAK
, &brk
, sizeof (brk
), 0);
815 procfs_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
817 return procfs_breakpoint (addr
, _DEBUG_BREAK_EXEC
, 0);
821 procfs_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
823 return procfs_breakpoint (addr
, _DEBUG_BREAK_EXEC
, -1);
827 procfs_insert_hw_breakpoint (CORE_ADDR addr
, char *contents_cache
)
829 return procfs_breakpoint (addr
, _DEBUG_BREAK_EXEC
| _DEBUG_BREAK_HW
, 0);
833 procfs_remove_hw_breakpoint (CORE_ADDR addr
, char *contents_cache
)
835 return procfs_breakpoint (addr
, _DEBUG_BREAK_EXEC
| _DEBUG_BREAK_HW
, -1);
839 procfs_resume (ptid_t ptid
, int step
, enum target_signal signo
)
842 procfs_status status
;
844 if (ptid_equal (inferior_ptid
, null_ptid
))
847 procfs_set_thread (ptid_equal (ptid
, minus_one_ptid
) ? inferior_ptid
:
850 run
.flags
= _DEBUG_RUN_FAULT
| _DEBUG_RUN_TRACE
;
852 run
.flags
|= _DEBUG_RUN_STEP
;
854 sigemptyset ((sigset_t
*) &run
.fault
);
855 sigaddset ((sigset_t
*) &run
.fault
, FLTBPT
);
856 sigaddset ((sigset_t
*) &run
.fault
, FLTTRACE
);
857 sigaddset ((sigset_t
*) &run
.fault
, FLTILL
);
858 sigaddset ((sigset_t
*) &run
.fault
, FLTPRIV
);
859 sigaddset ((sigset_t
*) &run
.fault
, FLTBOUNDS
);
860 sigaddset ((sigset_t
*) &run
.fault
, FLTIOVF
);
861 sigaddset ((sigset_t
*) &run
.fault
, FLTIZDIV
);
862 sigaddset ((sigset_t
*) &run
.fault
, FLTFPE
);
863 /* Peter V will be changing this at some point. */
864 sigaddset ((sigset_t
*) &run
.fault
, FLTPAGE
);
866 run
.flags
|= _DEBUG_RUN_ARM
;
868 sigemptyset (&run
.trace
);
870 signal_to_pass
= target_signal_to_host (signo
);
874 devctl (ctl_fd
, DCMD_PROC_STATUS
, &status
, sizeof (status
), 0);
875 signal_to_pass
= target_signal_to_host (signo
);
876 if (status
.why
& (_DEBUG_WHY_SIGNALLED
| _DEBUG_WHY_FAULTED
))
878 if (signal_to_pass
!= status
.info
.si_signo
)
880 SignalKill (nto_node (), PIDGET (inferior_ptid
), 0,
881 signal_to_pass
, 0, 0);
882 run
.flags
|= _DEBUG_RUN_CLRFLT
| _DEBUG_RUN_CLRSIG
;
884 else /* Let it kill the program without telling us. */
885 sigdelset (&run
.trace
, signal_to_pass
);
889 run
.flags
|= _DEBUG_RUN_CLRSIG
| _DEBUG_RUN_CLRFLT
;
891 errno
= devctl (ctl_fd
, DCMD_PROC_RUN
, &run
, sizeof (run
), 0);
894 perror ("run error!\n");
900 procfs_mourn_inferior (void)
902 if (!ptid_equal (inferior_ptid
, null_ptid
))
904 SignalKill (nto_node (), PIDGET (inferior_ptid
), 0, SIGKILL
, 0, 0);
907 inferior_ptid
= null_ptid
;
909 unpush_target (&procfs_ops
);
910 generic_mourn_inferior ();
914 /* This function breaks up an argument string into an argument
915 vector suitable for passing to execvp().
916 E.g., on "run a b c d" this routine would get as input
917 the string "a b c d", and as output it would fill in argv with
918 the four arguments "a", "b", "c", "d". The only additional
919 functionality is simple quoting. The gdb command:
921 will fill in argv with the three args "a", "b c d", "e". */
923 breakup_args (char *scratch
, char **argv
)
925 char *pp
, *cp
= scratch
;
930 /* Scan past leading separators. */
932 while (*cp
== ' ' || *cp
== '\t' || *cp
== '\n')
935 /* Break if at end of string. */
943 quoting
= strchr (cp
, '"') ? 1 : 0;
948 /* Scan for next arg separator. */
951 cp
= strchr (pp
, '"');
952 if ((cp
== NULL
) || (!quoting
))
953 cp
= strchr (pp
, ' ');
955 cp
= strchr (pp
, '\t');
957 cp
= strchr (pp
, '\n');
959 /* No separators => end of string => break. */
966 /* Replace the separator with a terminator. */
970 /* Execv requires a null-terminated arg vector. */
975 procfs_create_inferior (char *exec_file
, char *allargs
, char **env
,
978 struct inheritance inherit
;
982 const char *in
= "", *out
= "", *err
= "";
985 const char *inferior_io_terminal
= get_inferior_io_terminal ();
987 argv
= xmalloc (((strlen (allargs
) + 1) / (unsigned) 2 + 2) *
989 argv
[0] = get_exec_file (1);
998 args
= xstrdup (allargs
);
999 breakup_args (args
, exec_file
? &argv
[1] : &argv
[0]);
1001 argv
= nto_parse_redirection (argv
, &in
, &out
, &err
);
1003 fds
[0] = STDIN_FILENO
;
1004 fds
[1] = STDOUT_FILENO
;
1005 fds
[2] = STDERR_FILENO
;
1007 /* If the user specified I/O via gdb's --tty= arg, use it, but only
1008 if the i/o is not also being specified via redirection. */
1009 if (inferior_io_terminal
)
1012 in
= inferior_io_terminal
;
1014 out
= inferior_io_terminal
;
1016 err
= inferior_io_terminal
;
1021 fd
= open (in
, O_RDONLY
);
1029 fd
= open (out
, O_WRONLY
);
1037 fd
= open (err
, O_WRONLY
);
1044 /* Clear any pending SIGUSR1's but keep the behavior the same. */
1045 signal (SIGUSR1
, signal (SIGUSR1
, SIG_IGN
));
1048 sigaddset (&set
, SIGUSR1
);
1049 sigprocmask (SIG_UNBLOCK
, &set
, NULL
);
1051 memset (&inherit
, 0, sizeof (inherit
));
1053 if (ND_NODE_CMP (nto_procfs_node
, ND_LOCAL_NODE
) != 0)
1055 inherit
.nd
= nto_node ();
1056 inherit
.flags
|= SPAWN_SETND
;
1057 inherit
.flags
&= ~SPAWN_EXEC
;
1059 inherit
.flags
|= SPAWN_SETGROUP
| SPAWN_HOLD
;
1060 inherit
.pgroup
= SPAWN_NEWPGROUP
;
1061 pid
= spawnp (argv
[0], 3, fds
, &inherit
, argv
,
1062 ND_NODE_CMP (nto_procfs_node
, ND_LOCAL_NODE
) == 0 ? env
: 0);
1065 sigprocmask (SIG_BLOCK
, &set
, NULL
);
1068 error (_("Error spawning %s: %d (%s)"), argv
[0], errno
,
1069 safe_strerror (errno
));
1071 if (fds
[0] != STDIN_FILENO
)
1073 if (fds
[1] != STDOUT_FILENO
)
1075 if (fds
[2] != STDERR_FILENO
)
1078 inferior_ptid
= do_attach (pid_to_ptid (pid
));
1081 flags
= _DEBUG_FLAG_KLC
; /* Kill-on-Last-Close flag. */
1082 errn
= devctl (ctl_fd
, DCMD_PROC_SET_FLAG
, &flags
, sizeof (flags
), 0);
1085 /* FIXME: expected warning? */
1086 /* warning( "Failed to set Kill-on-Last-Close flag: errno = %d(%s)\n",
1087 errn, strerror(errn) ); */
1089 push_target (&procfs_ops
);
1090 target_terminal_init ();
1092 if (exec_bfd
!= NULL
1093 || (symfile_objfile
!= NULL
&& symfile_objfile
->obfd
!= NULL
))
1094 solib_create_inferior_hook ();
1096 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
1102 devctl (ctl_fd
, DCMD_PROC_STOP
, NULL
, 0, 0);
1106 procfs_kill_inferior (void)
1108 target_mourn_inferior ();
1111 /* Store register REGNO, or all registers if REGNO == -1, from the contents
1114 procfs_prepare_to_store (void)
1118 /* Fill buf with regset and return devctl cmd to do the setting. Return
1119 -1 if we fail to get the regset. Store size of regset in regsize. */
1121 get_regset (int regset
, char *buf
, int bufsize
, int *regsize
)
1123 int dev_get
, dev_set
;
1126 case NTO_REG_GENERAL
:
1127 dev_get
= DCMD_PROC_GETGREG
;
1128 dev_set
= DCMD_PROC_SETGREG
;
1132 dev_get
= DCMD_PROC_GETFPREG
;
1133 dev_set
= DCMD_PROC_SETFPREG
;
1137 dev_get
= DCMD_PROC_GETALTREG
;
1138 dev_set
= DCMD_PROC_SETALTREG
;
1141 case NTO_REG_SYSTEM
:
1145 if (devctl (ctl_fd
, dev_get
, &buf
, bufsize
, regsize
) != EOK
)
1152 procfs_store_registers (int regno
)
1158 procfs_altreg altreg
;
1162 int len
, regset
, regsize
, dev_set
, err
;
1165 if (ptid_equal (inferior_ptid
, null_ptid
))
1167 procfs_set_thread (inferior_ptid
);
1171 for (regset
= NTO_REG_GENERAL
; regset
< NTO_REG_END
; regset
++)
1173 dev_set
= get_regset (regset
, (char *) ®
,
1174 sizeof (reg
), ®size
);
1178 if (nto_regset_fill (regset
, (char *) ®
) == -1)
1181 err
= devctl (ctl_fd
, dev_set
, ®
, regsize
, 0);
1183 fprintf_unfiltered (gdb_stderr
,
1184 "Warning unable to write regset %d: %s\n",
1185 regno
, safe_strerror (err
));
1190 regset
= nto_regset_id (regno
);
1194 dev_set
= get_regset (regset
, (char *) ®
, sizeof (reg
), ®size
);
1198 len
= nto_register_area (regno
, regset
, &off
);
1203 regcache_raw_collect (current_regcache
, regno
, (char *) ®
+ off
);
1205 err
= devctl (ctl_fd
, dev_set
, ®
, regsize
, 0);
1207 fprintf_unfiltered (gdb_stderr
,
1208 "Warning unable to write regset %d: %s\n", regno
,
1209 safe_strerror (err
));
1214 notice_signals (void)
1218 for (signo
= 1; signo
< NSIG
; signo
++)
1220 if (signal_stop_state (target_signal_from_host (signo
)) == 0
1221 && signal_print_state (target_signal_from_host (signo
)) == 0
1222 && signal_pass_state (target_signal_from_host (signo
)) == 1)
1223 sigdelset (&run
.trace
, signo
);
1225 sigaddset (&run
.trace
, signo
);
1229 /* When the user changes the state of gdb's signal handling via the
1230 "handle" command, this function gets called to see if any change
1231 in the /proc interface is required. It is also called internally
1232 by other /proc interface functions to initialize the state of
1233 the traced signal set. */
1235 procfs_notice_signals (ptid_t ptid
)
1237 sigemptyset (&run
.trace
);
1241 static struct tidinfo
*
1242 procfs_thread_info (pid_t pid
, short tid
)
1249 procfs_pid_to_str (ptid_t ptid
)
1251 static char buf
[1024];
1253 struct tidinfo
*tip
;
1255 pid
= ptid_get_pid (ptid
);
1256 tid
= ptid_get_tid (ptid
);
1258 n
= snprintf (buf
, 1023, "process %d", pid
);
1261 tip
= procfs_thread_info (pid
, tid
);
1263 snprintf (&buf
[n
], 1023, " (state = 0x%02x)", tip
->state
);
1270 init_procfs_ops (void)
1272 procfs_ops
.to_shortname
= "procfs";
1273 procfs_ops
.to_longname
= "QNX Neutrino procfs child process";
1275 "QNX Neutrino procfs child process (started by the \"run\" command).\n\
1276 target procfs <node>";
1277 procfs_ops
.to_open
= procfs_open
;
1278 procfs_ops
.to_attach
= procfs_attach
;
1279 procfs_ops
.to_post_attach
= procfs_post_attach
;
1280 procfs_ops
.to_detach
= procfs_detach
;
1281 procfs_ops
.to_resume
= procfs_resume
;
1282 procfs_ops
.to_wait
= procfs_wait
;
1283 procfs_ops
.to_fetch_registers
= procfs_fetch_registers
;
1284 procfs_ops
.to_store_registers
= procfs_store_registers
;
1285 procfs_ops
.to_prepare_to_store
= procfs_prepare_to_store
;
1286 procfs_ops
.deprecated_xfer_memory
= procfs_xfer_memory
;
1287 procfs_ops
.to_files_info
= procfs_files_info
;
1288 procfs_ops
.to_insert_breakpoint
= procfs_insert_breakpoint
;
1289 procfs_ops
.to_remove_breakpoint
= procfs_remove_breakpoint
;
1290 procfs_ops
.to_can_use_hw_breakpoint
= procfs_can_use_hw_breakpoint
;
1291 procfs_ops
.to_insert_hw_breakpoint
= procfs_insert_hw_breakpoint
;
1292 procfs_ops
.to_remove_hw_breakpoint
= procfs_remove_breakpoint
;
1293 procfs_ops
.to_insert_watchpoint
= procfs_insert_hw_watchpoint
;
1294 procfs_ops
.to_remove_watchpoint
= procfs_remove_hw_watchpoint
;
1295 procfs_ops
.to_stopped_by_watchpoint
= procfs_stopped_by_watchpoint
;
1296 procfs_ops
.to_terminal_init
= terminal_init_inferior
;
1297 procfs_ops
.to_terminal_inferior
= terminal_inferior
;
1298 procfs_ops
.to_terminal_ours_for_output
= terminal_ours_for_output
;
1299 procfs_ops
.to_terminal_ours
= terminal_ours
;
1300 procfs_ops
.to_terminal_info
= child_terminal_info
;
1301 procfs_ops
.to_kill
= procfs_kill_inferior
;
1302 procfs_ops
.to_create_inferior
= procfs_create_inferior
;
1303 procfs_ops
.to_mourn_inferior
= procfs_mourn_inferior
;
1304 procfs_ops
.to_can_run
= procfs_can_run
;
1305 procfs_ops
.to_notice_signals
= procfs_notice_signals
;
1306 procfs_ops
.to_thread_alive
= procfs_thread_alive
;
1307 procfs_ops
.to_find_new_threads
= procfs_find_new_threads
;
1308 procfs_ops
.to_pid_to_str
= procfs_pid_to_str
;
1309 procfs_ops
.to_stop
= procfs_stop
;
1310 procfs_ops
.to_stratum
= process_stratum
;
1311 procfs_ops
.to_has_all_memory
= 1;
1312 procfs_ops
.to_has_memory
= 1;
1313 procfs_ops
.to_has_stack
= 1;
1314 procfs_ops
.to_has_registers
= 1;
1315 procfs_ops
.to_has_execution
= 1;
1316 procfs_ops
.to_magic
= OPS_MAGIC
;
1317 procfs_ops
.to_have_continuable_watchpoint
= 1;
1320 #define OSTYPE_NTO 1
1323 _initialize_procfs (void)
1328 add_target (&procfs_ops
);
1330 /* We use SIGUSR1 to gain control after we block waiting for a process.
1331 We use sigwaitevent to wait. */
1333 sigaddset (&set
, SIGUSR1
);
1334 sigprocmask (SIG_BLOCK
, &set
, NULL
);
1336 /* Set up trace and fault sets, as gdb expects them. */
1337 sigemptyset (&run
.trace
);
1339 /* Stuff some information. */
1340 nto_cpuinfo_flags
= SYSPAGE_ENTRY (cpuinfo
)->flags
;
1341 nto_cpuinfo_valid
= 1;
1343 add_info ("pidlist", procfs_pidlist
, _("pidlist"));
1344 add_info ("meminfo", procfs_meminfo
, _("memory information"));
1346 nto_is_nto_target
= procfs_is_nto_target
;
1351 procfs_hw_watchpoint (int addr
, int len
, int type
)
1358 brk
.type
= _DEBUG_BREAK_RD
;
1360 case 2: /* Read/Write. */
1361 brk
.type
= _DEBUG_BREAK_RW
;
1363 default: /* Modify. */
1364 /* FIXME: brk.type = _DEBUG_BREAK_RWM gives EINVAL for some reason. */
1365 brk
.type
= _DEBUG_BREAK_RW
;
1367 brk
.type
|= _DEBUG_BREAK_HW
; /* Always ask for HW. */
1371 errno
= devctl (ctl_fd
, DCMD_PROC_BREAK
, &brk
, sizeof (brk
), 0);
1374 perror ("Failed to set hardware watchpoint");
1381 procfs_can_use_hw_breakpoint (int type
, int cnt
, int othertype
)
1387 procfs_remove_hw_watchpoint (CORE_ADDR addr
, int len
, int type
)
1389 return procfs_hw_watchpoint (addr
, -1, type
);
1393 procfs_insert_hw_watchpoint (CORE_ADDR addr
, int len
, int type
)
1395 return procfs_hw_watchpoint (addr
, len
, type
);
1399 procfs_stopped_by_watchpoint (void)