* gnu-nat.c (gnu_attach): Add process to inferiors table.
[deliverable/binutils-gdb.git] / gdb / nto-procfs.c
CommitLineData
61bb466e
KW
1/* Machine independent support for QNX Neutrino /proc (process file system)
2 for GDB. Written by Colin Burgess at QNX Software Systems Limited.
3
9b254dd1 4 Copyright (C) 2003, 2006, 2007, 2008 Free Software Foundation, Inc.
61bb466e
KW
5
6 Contributed by QNX Software Systems Ltd.
7
8 This file is part of GDB.
9
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
a9762ec7 12 the Free Software Foundation; either version 3 of the License, or
61bb466e
KW
13 (at your option) any later version.
14
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.
19
20 You should have received a copy of the GNU General Public License
a9762ec7 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
61bb466e
KW
22
23#include "defs.h"
24
25#include <fcntl.h>
26#include <spawn.h>
27#include <sys/debug.h>
28#include <sys/procfs.h>
29#include <sys/neutrino.h>
30#include <sys/syspage.h>
5483d879 31#include "gdb_dirent.h"
61bb466e
KW
32#include <sys/netmgr.h>
33
60250e8b 34#include "exceptions.h"
61bb466e
KW
35#include "gdb_string.h"
36#include "gdbcore.h"
37#include "inferior.h"
38#include "target.h"
39#include "objfiles.h"
40#include "gdbthread.h"
41#include "nto-tdep.h"
42#include "command.h"
43#include "regcache.h"
5ea03926 44#include "solib.h"
61bb466e
KW
45
46#define NULL_PID 0
47#define _DEBUG_FLAG_TRACE (_DEBUG_FLAG_TRACE_EXEC|_DEBUG_FLAG_TRACE_RD|\
48 _DEBUG_FLAG_TRACE_WR|_DEBUG_FLAG_TRACE_MODIFY)
49
50static struct target_ops procfs_ops;
51
52int ctl_fd;
53
54static void (*ofunc) ();
55
56static procfs_run run;
57
58static void procfs_open (char *, int);
59
60static int procfs_can_run (void);
61
62static ptid_t procfs_wait (ptid_t, struct target_waitstatus *);
63
14ef7606 64static int procfs_xfer_memory (CORE_ADDR, gdb_byte *, int, int,
61bb466e
KW
65 struct mem_attrib *attrib,
66 struct target_ops *);
67
56be3814 68static void procfs_fetch_registers (struct regcache *, int);
61bb466e
KW
69
70static void notice_signals (void);
71
72static void init_procfs_ops (void);
73
74static ptid_t do_attach (ptid_t ptid);
75
76static int procfs_can_use_hw_breakpoint (int, int, int);
77
61bb466e
KW
78static int procfs_insert_hw_watchpoint (CORE_ADDR addr, int len, int type);
79
80static int procfs_remove_hw_watchpoint (CORE_ADDR addr, int len, int type);
81
82static int procfs_stopped_by_watchpoint (void);
83
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. */
88static char nto_procfs_path[PATH_MAX] = { "/proc" };
89static unsigned nto_procfs_node = ND_LOCAL_NODE;
90
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. */
95static unsigned
d737fd7f 96nto_node (void)
61bb466e
KW
97{
98 unsigned node;
99
d737fd7f 100 if (ND_NODE_CMP (nto_procfs_node, ND_LOCAL_NODE) == 0)
61bb466e
KW
101 return ND_LOCAL_NODE;
102
d737fd7f 103 node = netmgr_strtond (nto_procfs_path, 0);
61bb466e 104 if (node == -1)
8a3fe4f8 105 error (_("Lost the QNX node. Debug session probably over."));
61bb466e
KW
106
107 return (node);
108}
109
d737fd7f
KW
110static enum gdb_osabi
111procfs_is_nto_target (bfd *abfd)
112{
113 return GDB_OSABI_QNXNTO;
114}
115
61bb466e
KW
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
119 default to local. */
120static void
121procfs_open (char *arg, int from_tty)
122{
123 char *nodestr;
124 char *endstr;
125 char buffer[50];
126 int fd, total_size;
127 procfs_sysinfo *sysinfo;
128
d737fd7f
KW
129 nto_is_nto_target = procfs_is_nto_target;
130
61bb466e
KW
131 /* Set the default node used for spawning to this one,
132 and only override it if there is a valid arg. */
133
134 nto_procfs_node = ND_LOCAL_NODE;
135 nodestr = arg ? xstrdup (arg) : arg;
136
137 init_thread_list ();
138
139 if (nodestr)
140 {
141 nto_procfs_node = netmgr_strtond (nodestr, &endstr);
142 if (nto_procfs_node == -1)
143 {
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,
dc5dd1eb 147 errno, safe_strerror (errno));
61bb466e
KW
148 xfree (nodestr);
149 nodestr = NULL;
150 nto_procfs_node = ND_LOCAL_NODE;
151 }
152 else if (*endstr)
153 {
154 if (*(endstr - 1) == '/')
155 *(endstr - 1) = 0;
156 else
157 *endstr = 0;
158 }
159 }
d737fd7f
KW
160 snprintf (nto_procfs_path, PATH_MAX - 1, "%s%s", nodestr ? nodestr : "",
161 "/proc");
61bb466e
KW
162 if (nodestr)
163 xfree (nodestr);
164
165 fd = open (nto_procfs_path, O_RDONLY);
166 if (fd == -1)
167 {
168 printf_filtered ("Error opening %s : %d (%s)\n", nto_procfs_path, errno,
dc5dd1eb 169 safe_strerror (errno));
8a3fe4f8 170 error (_("Invalid procfs arg"));
61bb466e
KW
171 }
172
173 sysinfo = (void *) buffer;
174 if (devctl (fd, DCMD_PROC_SYSINFO, sysinfo, sizeof buffer, 0) != EOK)
175 {
176 printf_filtered ("Error getting size: %d (%s)\n", errno,
dc5dd1eb 177 safe_strerror (errno));
61bb466e 178 close (fd);
8a3fe4f8 179 error (_("Devctl failed."));
61bb466e
KW
180 }
181 else
182 {
183 total_size = sysinfo->total_size;
184 sysinfo = alloca (total_size);
185 if (!sysinfo)
186 {
187 printf_filtered ("Memory error: %d (%s)\n", errno,
dc5dd1eb 188 safe_strerror (errno));
61bb466e 189 close (fd);
8a3fe4f8 190 error (_("alloca failed."));
61bb466e
KW
191 }
192 else
193 {
194 if (devctl (fd, DCMD_PROC_SYSINFO, sysinfo, total_size, 0) != EOK)
195 {
196 printf_filtered ("Error getting sysinfo: %d (%s)\n", errno,
dc5dd1eb 197 safe_strerror (errno));
61bb466e 198 close (fd);
8a3fe4f8 199 error (_("Devctl failed."));
61bb466e
KW
200 }
201 else
202 {
203 if (sysinfo->type !=
1143fffb
UW
204 nto_map_arch_to_cputype (gdbarch_bfd_arch_info
205 (current_gdbarch)->arch_name))
61bb466e
KW
206 {
207 close (fd);
8a3fe4f8 208 error (_("Invalid target CPU."));
61bb466e
KW
209 }
210 }
211 }
212 }
213 close (fd);
214 printf_filtered ("Debugging using %s\n", nto_procfs_path);
215}
216
217static void
218procfs_set_thread (ptid_t ptid)
219{
220 pid_t tid;
221
222 tid = ptid_get_tid (ptid);
223 devctl (ctl_fd, DCMD_PROC_CURTHREAD, &tid, sizeof (tid), 0);
224}
225
226/* Return nonzero if the thread TH is still alive. */
227static int
228procfs_thread_alive (ptid_t ptid)
229{
230 pid_t tid;
231
232 tid = ptid_get_tid (ptid);
233 if (devctl (ctl_fd, DCMD_PROC_CURTHREAD, &tid, sizeof (tid), 0) == EOK)
234 return 1;
235 return 0;
236}
237
238void
239procfs_find_new_threads (void)
240{
241 procfs_status status;
242 pid_t pid;
243 ptid_t ptid;
244
245 if (ctl_fd == -1)
246 return;
247
248 pid = ptid_get_pid (inferior_ptid);
249
250 for (status.tid = 1;; ++status.tid)
251 {
252 if (devctl (ctl_fd, DCMD_PROC_TIDSTATUS, &status, sizeof (status), 0)
253 != EOK && status.tid != 0)
254 break;
255 ptid = ptid_build (pid, 0, status.tid);
256 if (!in_thread_list (ptid))
257 add_thread (ptid);
258 }
259 return;
260}
261
262void
263procfs_pidlist (char *args, int from_tty)
264{
265 DIR *dp = NULL;
266 struct dirent *dirp = NULL;
267 int fd = -1;
268 char buf[512];
269 procfs_info *pidinfo = NULL;
270 procfs_debuginfo *info = NULL;
271 procfs_status *status = NULL;
272 pid_t num_threads = 0;
273 pid_t pid;
274 char name[512];
275
276 dp = opendir (nto_procfs_path);
277 if (dp == NULL)
278 {
dc5dd1eb 279 fprintf_unfiltered (gdb_stderr, "failed to opendir \"%s\" - %d (%s)",
d737fd7f 280 nto_procfs_path, errno, safe_strerror (errno));
61bb466e
KW
281 return;
282 }
283
284 /* Start scan at first pid. */
285 rewinddir (dp);
286
287 do
288 {
289 /* Get the right pid and procfs path for the pid. */
290 do
291 {
292 dirp = readdir (dp);
293 if (dirp == NULL)
294 {
295 closedir (dp);
296 return;
297 }
dc5dd1eb 298 snprintf (buf, 511, "%s/%s/as", nto_procfs_path, dirp->d_name);
61bb466e
KW
299 pid = atoi (dirp->d_name);
300 }
301 while (pid == 0);
302
303 /* Open the procfs path. */
304 fd = open (buf, O_RDONLY);
305 if (fd == -1)
306 {
dc5dd1eb 307 fprintf_unfiltered (gdb_stderr, "failed to open %s - %d (%s)\n",
d737fd7f 308 buf, errno, safe_strerror (errno));
61bb466e
KW
309 closedir (dp);
310 return;
311 }
312
313 pidinfo = (procfs_info *) buf;
314 if (devctl (fd, DCMD_PROC_INFO, pidinfo, sizeof (buf), 0) != EOK)
315 {
dc5dd1eb 316 fprintf_unfiltered (gdb_stderr,
d737fd7f
KW
317 "devctl DCMD_PROC_INFO failed - %d (%s)\n",
318 errno, safe_strerror (errno));
61bb466e
KW
319 break;
320 }
321 num_threads = pidinfo->num_threads;
322
323 info = (procfs_debuginfo *) buf;
324 if (devctl (fd, DCMD_PROC_MAPDEBUG_BASE, info, sizeof (buf), 0) != EOK)
325 strcpy (name, "unavailable");
326 else
327 strcpy (name, info->path);
328
329 /* Collect state info on all the threads. */
330 status = (procfs_status *) buf;
331 for (status->tid = 1; status->tid <= num_threads; status->tid++)
332 {
333 if (devctl (fd, DCMD_PROC_TIDSTATUS, status, sizeof (buf), 0) != EOK
334 && status->tid != 0)
335 break;
336 if (status->tid != 0)
337 printf_filtered ("%s - %d/%d\n", name, pid, status->tid);
338 }
339 close (fd);
340 }
341 while (dirp != NULL);
342
343 close (fd);
344 closedir (dp);
345 return;
346}
347
348void
349procfs_meminfo (char *args, int from_tty)
350{
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;
355
356 struct
357 {
358 procfs_debuginfo info;
359 char buff[_POSIX_PATH_MAX];
360 } map;
361
362 struct info
363 {
364 unsigned addr;
365 unsigned size;
366 unsigned flags;
367 unsigned debug_vaddr;
368 unsigned long long offset;
369 };
370
371 struct printinfo
372 {
373 unsigned long long ino;
374 unsigned dev;
375 struct info text;
376 struct info data;
377 char name[256];
378 } printme;
379
380 /* Get the number of map entrys. */
381 err = devctl (ctl_fd, DCMD_PROC_MAPINFO, NULL, 0, &num);
382 if (err != EOK)
383 {
d737fd7f
KW
384 printf ("failed devctl num mapinfos - %d (%s)\n", err,
385 safe_strerror (err));
61bb466e
KW
386 return;
387 }
388
389 mapinfos = xmalloc (num * sizeof (procfs_mapinfo));
390
391 num_mapinfos = num;
392 mapinfo_p = mapinfos;
393
394 /* Fill the map entrys. */
395 err = devctl (ctl_fd, DCMD_PROC_MAPINFO, mapinfo_p, num
396 * sizeof (procfs_mapinfo), &num);
397 if (err != EOK)
398 {
5483d879 399 printf ("failed devctl mapinfos - %d (%s)\n", err, safe_strerror (err));
61bb466e
KW
400 xfree (mapinfos);
401 return;
402 }
403
404 num = min (num, num_mapinfos);
405
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++)
409 {
410 if (!(mapinfo_p->flags & flags))
411 mapinfo_p->ino = 0;
412
413 if (mapinfo_p->ino == 0) /* Already visited. */
414 continue;
415
416 map.info.vaddr = mapinfo_p->vaddr;
417
418 err = devctl (ctl_fd, DCMD_PROC_MAPDEBUG, &map, sizeof (map), 0);
419 if (err != EOK)
420 continue;
421
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);
431
432 /* Check for matching data. */
433 for (mapinfo_p2 = mapinfos, j = 0; j < num; j++, mapinfo_p2++)
434 {
435 if (mapinfo_p2->vaddr != mapinfo_p->vaddr
436 && mapinfo_p2->ino == mapinfo_p->ino
437 && mapinfo_p2->dev == mapinfo_p->dev)
438 {
439 map.info.vaddr = mapinfo_p2->vaddr;
440 err =
441 devctl (ctl_fd, DCMD_PROC_MAPDEBUG, &map, sizeof (map), 0);
442 if (err != EOK)
443 continue;
444
445 if (strcmp (map.info.path, printme.name))
446 continue;
447
448 /* Lower debug_vaddr is always text, if nessessary, swap. */
449 if ((int) map.info.vaddr < (int) printme.text.debug_vaddr)
450 {
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;
458 }
459 else
460 {
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;
466 }
467 mapinfo_p2->ino = 0;
468 }
469 }
470 mapinfo_p->ino = 0;
471
472 printf_filtered ("%s\n", printme.name);
473 printf_filtered ("\ttext=%08x bytes @ 0x%08x\n", printme.text.size,
474 printme.text.addr);
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)
479 {
480 printf_filtered ("\tdata=%08x bytes @ 0x%08x\n", printme.data.size,
481 printme.data.addr);
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);
485 }
486 printf_filtered ("\tdev=0x%x\n", printme.dev);
487 printf_filtered ("\tino=0x%x\n", (unsigned int) printme.ino);
488 }
489 xfree (mapinfos);
490 return;
491}
492
493/* Print status information about what we're accessing. */
494static void
495procfs_files_info (struct target_ops *ignore)
496{
497 printf_unfiltered ("\tUsing the running image of %s %s via %s.\n",
498 attach_flag ? "attached" : "child",
499 target_pid_to_str (inferior_ptid), nto_procfs_path);
500}
501
502/* Mark our target-struct as eligible for stray "run" and "attach" commands. */
503static int
5483d879 504procfs_can_run (void)
61bb466e
KW
505{
506 return 1;
507}
508
509/* Attach to process PID, then initialize for debugging it. */
510static void
511procfs_attach (char *args, int from_tty)
512{
513 char *exec_file;
514 int pid;
515
516 if (!args)
e2e0b3e5 517 error_no_arg (_("process-id to attach"));
61bb466e
KW
518
519 pid = atoi (args);
520
521 if (pid == getpid ())
8a3fe4f8 522 error (_("Attaching GDB to itself is not a good idea..."));
61bb466e
KW
523
524 if (from_tty)
525 {
526 exec_file = (char *) get_exec_file (0);
527
528 if (exec_file)
529 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file,
530 target_pid_to_str (pid_to_ptid (pid)));
531 else
532 printf_unfiltered ("Attaching to %s\n",
533 target_pid_to_str (pid_to_ptid (pid)));
534
535 gdb_flush (gdb_stdout);
536 }
537 inferior_ptid = do_attach (pid_to_ptid (pid));
7f9f62ba
PA
538 add_inferior (pid);
539
61bb466e 540 push_target (&procfs_ops);
7f9f62ba
PA
541
542 procfs_find_new_threads ();
61bb466e
KW
543}
544
545static void
546procfs_post_attach (pid_t pid)
547{
61bb466e 548 if (exec_bfd)
42e9a5a0 549 solib_create_inferior_hook ();
61bb466e
KW
550}
551
552static ptid_t
553do_attach (ptid_t ptid)
554{
555 procfs_status status;
556 struct sigevent event;
dc5dd1eb 557 char path[PATH_MAX];
61bb466e 558
dc5dd1eb 559 snprintf (path, PATH_MAX - 1, "%s/%d/as", nto_procfs_path, PIDGET (ptid));
61bb466e
KW
560 ctl_fd = open (path, O_RDWR);
561 if (ctl_fd == -1)
8a3fe4f8 562 error (_("Couldn't open proc file %s, error %d (%s)"), path, errno,
dc5dd1eb 563 safe_strerror (errno));
61bb466e 564 if (devctl (ctl_fd, DCMD_PROC_STOP, &status, sizeof (status), 0) != EOK)
8a3fe4f8 565 error (_("Couldn't stop process"));
61bb466e
KW
566
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);
574
575 if (devctl (ctl_fd, DCMD_PROC_STATUS, &status, sizeof (status), 0) == EOK
576 && status.flags & _DEBUG_FLAG_STOPPED)
d737fd7f 577 SignalKill (nto_node (), PIDGET (ptid), 0, SIGCONT, 0, 0);
61bb466e
KW
578 attach_flag = 1;
579 nto_init_solib_absolute_prefix ();
580 return ptid;
581}
582
583/* Ask the user what to do when an interrupt is received. */
584static void
dc5dd1eb 585interrupt_query (void)
61bb466e
KW
586{
587 target_terminal_ours ();
588
589 if (query ("Interrupted while waiting for the program.\n\
590Give up (and stop debugging it)? "))
591 {
592 target_mourn_inferior ();
315a522e 593 deprecated_throw_reason (RETURN_QUIT);
61bb466e
KW
594 }
595
596 target_terminal_inferior ();
597}
598
599/* The user typed ^C twice. */
600static void
601nto_interrupt_twice (int signo)
602{
603 signal (signo, ofunc);
604 interrupt_query ();
605 signal (signo, nto_interrupt_twice);
606}
607
608static void
609nto_interrupt (int signo)
610{
611 /* If this doesn't work, try more severe steps. */
612 signal (signo, nto_interrupt_twice);
613
f9c72d52 614 target_stop (inferior_ptid);
61bb466e
KW
615}
616
617static ptid_t
618procfs_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
619{
620 sigset_t set;
621 siginfo_t info;
622 procfs_status status;
623 static int exit_signo = 0; /* To track signals that cause termination. */
624
625 ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
626
627 if (ptid_equal (inferior_ptid, null_ptid))
628 {
629 ourstatus->kind = TARGET_WAITKIND_STOPPED;
630 ourstatus->value.sig = TARGET_SIGNAL_0;
631 exit_signo = 0;
632 return null_ptid;
633 }
634
635 sigemptyset (&set);
636 sigaddset (&set, SIGUSR1);
637
638 devctl (ctl_fd, DCMD_PROC_STATUS, &status, sizeof (status), 0);
639 while (!(status.flags & _DEBUG_FLAG_ISTOP))
640 {
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);
645 }
646
647 if (status.flags & _DEBUG_FLAG_SSTEP)
648 {
649 ourstatus->kind = TARGET_WAITKIND_STOPPED;
650 ourstatus->value.sig = TARGET_SIGNAL_TRAP;
651 }
652 /* Was it a breakpoint? */
653 else if (status.flags & _DEBUG_FLAG_TRACE)
654 {
655 ourstatus->kind = TARGET_WAITKIND_STOPPED;
656 ourstatus->value.sig = TARGET_SIGNAL_TRAP;
657 }
658 else if (status.flags & _DEBUG_FLAG_ISTOP)
659 {
660 switch (status.why)
661 {
662 case _DEBUG_WHY_SIGNALLED:
663 ourstatus->kind = TARGET_WAITKIND_STOPPED;
664 ourstatus->value.sig =
665 target_signal_from_host (status.info.si_signo);
666 exit_signo = 0;
667 break;
668 case _DEBUG_WHY_FAULTED:
669 ourstatus->kind = TARGET_WAITKIND_STOPPED;
670 if (status.info.si_signo == SIGTRAP)
671 {
672 ourstatus->value.sig = 0;
673 exit_signo = 0;
674 }
675 else
676 {
677 ourstatus->value.sig =
678 target_signal_from_host (status.info.si_signo);
679 exit_signo = ourstatus->value.sig;
680 }
681 break;
682
683 case _DEBUG_WHY_TERMINATED:
684 {
685 int waitval = 0;
686
687 waitpid (PIDGET (inferior_ptid), &waitval, WNOHANG);
688 if (exit_signo)
689 {
690 /* Abnormal death. */
691 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
692 ourstatus->value.sig = exit_signo;
693 }
694 else
695 {
696 /* Normal death. */
697 ourstatus->kind = TARGET_WAITKIND_EXITED;
698 ourstatus->value.integer = WEXITSTATUS (waitval);
699 }
700 exit_signo = 0;
701 break;
702 }
703
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;
708 exit_signo = 0;
709 break;
710 }
711 }
712
a6a7f2a5 713 return ptid_build (status.pid, 0, status.tid);
61bb466e
KW
714}
715
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. */
719static void
56be3814 720procfs_fetch_registers (struct regcache *regcache, int regno)
61bb466e
KW
721{
722 union
723 {
724 procfs_greg greg;
725 procfs_fpreg fpreg;
726 procfs_altreg altreg;
727 }
728 reg;
729 int regsize;
730
731 procfs_set_thread (inferior_ptid);
732 if (devctl (ctl_fd, DCMD_PROC_GETGREG, &reg, sizeof (reg), &regsize) == EOK)
56be3814 733 nto_supply_gregset (regcache, (char *) &reg.greg);
61bb466e
KW
734 if (devctl (ctl_fd, DCMD_PROC_GETFPREG, &reg, sizeof (reg), &regsize)
735 == EOK)
56be3814 736 nto_supply_fpregset (regcache, (char *) &reg.fpreg);
61bb466e
KW
737 if (devctl (ctl_fd, DCMD_PROC_GETALTREG, &reg, sizeof (reg), &regsize)
738 == EOK)
56be3814 739 nto_supply_altregset (regcache, (char *) &reg.altreg);
61bb466e
KW
740}
741
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.
745
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
749 anyway. */
750static int
14ef7606 751procfs_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int dowrite,
61bb466e
KW
752 struct mem_attrib *attrib, struct target_ops *target)
753{
754 int nbytes = 0;
755
756 if (lseek (ctl_fd, (off_t) memaddr, SEEK_SET) == (off_t) memaddr)
757 {
758 if (dowrite)
759 nbytes = write (ctl_fd, myaddr, len);
760 else
761 nbytes = read (ctl_fd, myaddr, len);
762 if (nbytes < 0)
763 nbytes = 0;
764 }
765 return (nbytes);
766}
767
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. */
772static void
773procfs_detach (char *args, int from_tty)
774{
775 int siggnal = 0;
7f9f62ba 776 int pid;
61bb466e
KW
777
778 if (from_tty)
779 {
780 char *exec_file = get_exec_file (0);
781 if (exec_file == 0)
782 exec_file = "";
783 printf_unfiltered ("Detaching from program: %s %s\n",
784 exec_file, target_pid_to_str (inferior_ptid));
785 gdb_flush (gdb_stdout);
786 }
787 if (args)
788 siggnal = atoi (args);
789
790 if (siggnal)
d737fd7f 791 SignalKill (nto_node (), PIDGET (inferior_ptid), 0, siggnal, 0, 0);
61bb466e
KW
792
793 close (ctl_fd);
794 ctl_fd = -1;
7f9f62ba
PA
795
796 pid = ptid_get_pid (inferior_ptid);
61bb466e
KW
797 inferior_ptid = null_ptid;
798 attach_flag = 0;
7f9f62ba
PA
799 detach_inferior (pid);
800 init_thread_list ();
61bb466e
KW
801 unpush_target (&procfs_ops); /* Pop out of handling an inferior. */
802}
803
804static int
805procfs_breakpoint (CORE_ADDR addr, int type, int size)
806{
807 procfs_break brk;
808
809 brk.type = type;
810 brk.addr = addr;
811 brk.size = size;
812 errno = devctl (ctl_fd, DCMD_PROC_BREAK, &brk, sizeof (brk), 0);
813 if (errno != EOK)
814 return 1;
815 return 0;
816}
817
818static int
8181d85f 819procfs_insert_breakpoint (struct bp_target_info *bp_tgt)
61bb466e 820{
8181d85f 821 return procfs_breakpoint (bp_tgt->placed_address, _DEBUG_BREAK_EXEC, 0);
61bb466e
KW
822}
823
824static int
8181d85f 825procfs_remove_breakpoint (struct bp_target_info *bp_tgt)
61bb466e 826{
8181d85f 827 return procfs_breakpoint (bp_tgt->placed_address, _DEBUG_BREAK_EXEC, -1);
61bb466e
KW
828}
829
830static int
8181d85f 831procfs_insert_hw_breakpoint (struct bp_target_info *bp_tgt)
61bb466e 832{
8181d85f
DJ
833 return procfs_breakpoint (bp_tgt->placed_address,
834 _DEBUG_BREAK_EXEC | _DEBUG_BREAK_HW, 0);
61bb466e
KW
835}
836
837static int
8181d85f 838procfs_remove_hw_breakpoint (struct bp_target_info *bp_tgt)
61bb466e 839{
8181d85f
DJ
840 return procfs_breakpoint (bp_tgt->placed_address,
841 _DEBUG_BREAK_EXEC | _DEBUG_BREAK_HW, -1);
61bb466e
KW
842}
843
844static void
845procfs_resume (ptid_t ptid, int step, enum target_signal signo)
846{
847 int signal_to_pass;
848 procfs_status status;
14ef7606 849 sigset_t *run_fault = (sigset_t *) (void *) &run.fault;
61bb466e
KW
850
851 if (ptid_equal (inferior_ptid, null_ptid))
852 return;
853
854 procfs_set_thread (ptid_equal (ptid, minus_one_ptid) ? inferior_ptid :
855 ptid);
856
857 run.flags = _DEBUG_RUN_FAULT | _DEBUG_RUN_TRACE;
858 if (step)
859 run.flags |= _DEBUG_RUN_STEP;
860
14ef7606
AR
861 sigemptyset (run_fault);
862 sigaddset (run_fault, FLTBPT);
863 sigaddset (run_fault, FLTTRACE);
864 sigaddset (run_fault, FLTILL);
865 sigaddset (run_fault, FLTPRIV);
866 sigaddset (run_fault, FLTBOUNDS);
867 sigaddset (run_fault, FLTIOVF);
868 sigaddset (run_fault, FLTIZDIV);
869 sigaddset (run_fault, FLTFPE);
61bb466e 870 /* Peter V will be changing this at some point. */
14ef7606 871 sigaddset (run_fault, FLTPAGE);
61bb466e
KW
872
873 run.flags |= _DEBUG_RUN_ARM;
874
875 sigemptyset (&run.trace);
876 notice_signals ();
877 signal_to_pass = target_signal_to_host (signo);
878
879 if (signal_to_pass)
880 {
881 devctl (ctl_fd, DCMD_PROC_STATUS, &status, sizeof (status), 0);
882 signal_to_pass = target_signal_to_host (signo);
883 if (status.why & (_DEBUG_WHY_SIGNALLED | _DEBUG_WHY_FAULTED))
884 {
885 if (signal_to_pass != status.info.si_signo)
886 {
d737fd7f
KW
887 SignalKill (nto_node (), PIDGET (inferior_ptid), 0,
888 signal_to_pass, 0, 0);
61bb466e
KW
889 run.flags |= _DEBUG_RUN_CLRFLT | _DEBUG_RUN_CLRSIG;
890 }
891 else /* Let it kill the program without telling us. */
892 sigdelset (&run.trace, signal_to_pass);
893 }
894 }
895 else
896 run.flags |= _DEBUG_RUN_CLRSIG | _DEBUG_RUN_CLRFLT;
897
898 errno = devctl (ctl_fd, DCMD_PROC_RUN, &run, sizeof (run), 0);
899 if (errno != EOK)
900 {
901 perror ("run error!\n");
902 return;
903 }
904}
905
906static void
dc5dd1eb 907procfs_mourn_inferior (void)
61bb466e
KW
908{
909 if (!ptid_equal (inferior_ptid, null_ptid))
910 {
d737fd7f 911 SignalKill (nto_node (), PIDGET (inferior_ptid), 0, SIGKILL, 0, 0);
61bb466e
KW
912 close (ctl_fd);
913 }
914 inferior_ptid = null_ptid;
915 init_thread_list ();
916 unpush_target (&procfs_ops);
917 generic_mourn_inferior ();
918 attach_flag = 0;
919}
920
921/* This function breaks up an argument string into an argument
922 vector suitable for passing to execvp().
923 E.g., on "run a b c d" this routine would get as input
924 the string "a b c d", and as output it would fill in argv with
925 the four arguments "a", "b", "c", "d". The only additional
926 functionality is simple quoting. The gdb command:
927 run a "b c d" f
928 will fill in argv with the three args "a", "b c d", "e". */
929static void
930breakup_args (char *scratch, char **argv)
931{
932 char *pp, *cp = scratch;
933 char quoting = 0;
934
935 for (;;)
936 {
937 /* Scan past leading separators. */
938 quoting = 0;
939 while (*cp == ' ' || *cp == '\t' || *cp == '\n')
940 cp++;
941
942 /* Break if at end of string. */
943 if (*cp == '\0')
944 break;
945
946 /* Take an arg. */
947 if (*cp == '"')
948 {
949 cp++;
950 quoting = strchr (cp, '"') ? 1 : 0;
951 }
952
953 *argv++ = cp;
954
955 /* Scan for next arg separator. */
956 pp = cp;
957 if (quoting)
958 cp = strchr (pp, '"');
959 if ((cp == NULL) || (!quoting))
960 cp = strchr (pp, ' ');
961 if (cp == NULL)
962 cp = strchr (pp, '\t');
963 if (cp == NULL)
964 cp = strchr (pp, '\n');
965
966 /* No separators => end of string => break. */
967 if (cp == NULL)
968 {
969 pp = cp;
970 break;
971 }
972
973 /* Replace the separator with a terminator. */
974 *cp++ = '\0';
975 }
976
977 /* Execv requires a null-terminated arg vector. */
978 *argv = NULL;
979}
980
981static void
c27cda74
AC
982procfs_create_inferior (char *exec_file, char *allargs, char **env,
983 int from_tty)
61bb466e
KW
984{
985 struct inheritance inherit;
986 pid_t pid;
987 int flags, errn;
988 char **argv, *args;
3cb3b8df 989 const char *in = "", *out = "", *err = "";
61bb466e
KW
990 int fd, fds[3];
991 sigset_t set;
3cb3b8df 992 const char *inferior_io_terminal = get_inferior_io_terminal ();
61bb466e
KW
993
994 argv = xmalloc (((strlen (allargs) + 1) / (unsigned) 2 + 2) *
995 sizeof (*argv));
996 argv[0] = get_exec_file (1);
997 if (!argv[0])
998 {
999 if (exec_file)
1000 argv[0] = exec_file;
1001 else
1002 return;
1003 }
1004
1005 args = xstrdup (allargs);
1006 breakup_args (args, exec_file ? &argv[1] : &argv[0]);
1007
1008 argv = nto_parse_redirection (argv, &in, &out, &err);
1009
1010 fds[0] = STDIN_FILENO;
1011 fds[1] = STDOUT_FILENO;
1012 fds[2] = STDERR_FILENO;
1013
1014 /* If the user specified I/O via gdb's --tty= arg, use it, but only
1015 if the i/o is not also being specified via redirection. */
1016 if (inferior_io_terminal)
1017 {
1018 if (!in[0])
1019 in = inferior_io_terminal;
1020 if (!out[0])
1021 out = inferior_io_terminal;
1022 if (!err[0])
1023 err = inferior_io_terminal;
1024 }
1025
1026 if (in[0])
1027 {
1028 fd = open (in, O_RDONLY);
1029 if (fd == -1)
1030 perror (in);
1031 else
1032 fds[0] = fd;
1033 }
1034 if (out[0])
1035 {
1036 fd = open (out, O_WRONLY);
1037 if (fd == -1)
1038 perror (out);
1039 else
1040 fds[1] = fd;
1041 }
1042 if (err[0])
1043 {
1044 fd = open (err, O_WRONLY);
1045 if (fd == -1)
1046 perror (err);
1047 else
1048 fds[2] = fd;
1049 }
1050
1051 /* Clear any pending SIGUSR1's but keep the behavior the same. */
1052 signal (SIGUSR1, signal (SIGUSR1, SIG_IGN));
1053
1054 sigemptyset (&set);
1055 sigaddset (&set, SIGUSR1);
1056 sigprocmask (SIG_UNBLOCK, &set, NULL);
1057
1058 memset (&inherit, 0, sizeof (inherit));
1059
1060 if (ND_NODE_CMP (nto_procfs_node, ND_LOCAL_NODE) != 0)
1061 {
d737fd7f 1062 inherit.nd = nto_node ();
61bb466e
KW
1063 inherit.flags |= SPAWN_SETND;
1064 inherit.flags &= ~SPAWN_EXEC;
1065 }
1066 inherit.flags |= SPAWN_SETGROUP | SPAWN_HOLD;
1067 inherit.pgroup = SPAWN_NEWPGROUP;
1068 pid = spawnp (argv[0], 3, fds, &inherit, argv,
1069 ND_NODE_CMP (nto_procfs_node, ND_LOCAL_NODE) == 0 ? env : 0);
1070 xfree (args);
1071
1072 sigprocmask (SIG_BLOCK, &set, NULL);
1073
1074 if (pid == -1)
8a3fe4f8 1075 error (_("Error spawning %s: %d (%s)"), argv[0], errno,
d737fd7f 1076 safe_strerror (errno));
61bb466e
KW
1077
1078 if (fds[0] != STDIN_FILENO)
1079 close (fds[0]);
1080 if (fds[1] != STDOUT_FILENO)
1081 close (fds[1]);
1082 if (fds[2] != STDERR_FILENO)
1083 close (fds[2]);
1084
1085 inferior_ptid = do_attach (pid_to_ptid (pid));
1086
7f9f62ba 1087 add_inferior (pid);
61bb466e 1088 attach_flag = 0;
7f9f62ba 1089
61bb466e
KW
1090 flags = _DEBUG_FLAG_KLC; /* Kill-on-Last-Close flag. */
1091 errn = devctl (ctl_fd, DCMD_PROC_SET_FLAG, &flags, sizeof (flags), 0);
1092 if (errn != EOK)
1093 {
1094 /* FIXME: expected warning? */
1095 /* warning( "Failed to set Kill-on-Last-Close flag: errno = %d(%s)\n",
1096 errn, strerror(errn) ); */
1097 }
1098 push_target (&procfs_ops);
1099 target_terminal_init ();
1100
61bb466e
KW
1101 if (exec_bfd != NULL
1102 || (symfile_objfile != NULL && symfile_objfile->obfd != NULL))
42e9a5a0 1103 solib_create_inferior_hook ();
d737fd7f 1104 stop_soon = 0;
61bb466e
KW
1105}
1106
1107static void
f9c72d52 1108procfs_stop (ptid_t ptid)
61bb466e
KW
1109{
1110 devctl (ctl_fd, DCMD_PROC_STOP, NULL, 0, 0);
1111}
1112
1113static void
dc5dd1eb 1114procfs_kill_inferior (void)
61bb466e
KW
1115{
1116 target_mourn_inferior ();
1117}
1118
1119/* Store register REGNO, or all registers if REGNO == -1, from the contents
1120 of REGISTERS. */
1121static void
316f2060 1122procfs_prepare_to_store (struct regcache *regcache)
61bb466e
KW
1123{
1124}
1125
1126/* Fill buf with regset and return devctl cmd to do the setting. Return
1127 -1 if we fail to get the regset. Store size of regset in regsize. */
1128static int
1129get_regset (int regset, char *buf, int bufsize, int *regsize)
1130{
1131 int dev_get, dev_set;
1132 switch (regset)
1133 {
1134 case NTO_REG_GENERAL:
1135 dev_get = DCMD_PROC_GETGREG;
1136 dev_set = DCMD_PROC_SETGREG;
1137 break;
1138
1139 case NTO_REG_FLOAT:
1140 dev_get = DCMD_PROC_GETFPREG;
1141 dev_set = DCMD_PROC_SETFPREG;
1142 break;
1143
1144 case NTO_REG_ALT:
1145 dev_get = DCMD_PROC_GETALTREG;
1146 dev_set = DCMD_PROC_SETALTREG;
1147 break;
1148
1149 case NTO_REG_SYSTEM:
1150 default:
1151 return -1;
1152 }
1153 if (devctl (ctl_fd, dev_get, &buf, bufsize, regsize) != EOK)
1154 return -1;
1155
1156 return dev_set;
1157}
1158
1159void
56be3814 1160procfs_store_registers (struct regcache *regcache, int regno)
61bb466e
KW
1161{
1162 union
1163 {
1164 procfs_greg greg;
1165 procfs_fpreg fpreg;
1166 procfs_altreg altreg;
1167 }
1168 reg;
1169 unsigned off;
1170 int len, regset, regsize, dev_set, err;
1171 char *data;
1172
1173 if (ptid_equal (inferior_ptid, null_ptid))
1174 return;
1175 procfs_set_thread (inferior_ptid);
1176
1177 if (regno == -1)
1178 {
1179 for (regset = NTO_REG_GENERAL; regset < NTO_REG_END; regset++)
1180 {
1181 dev_set = get_regset (regset, (char *) &reg,
1182 sizeof (reg), &regsize);
1183 if (dev_set == -1)
1184 continue;
1185
56be3814 1186 if (nto_regset_fill (regcache, regset, (char *) &reg) == -1)
61bb466e
KW
1187 continue;
1188
1189 err = devctl (ctl_fd, dev_set, &reg, regsize, 0);
1190 if (err != EOK)
1191 fprintf_unfiltered (gdb_stderr,
1192 "Warning unable to write regset %d: %s\n",
dc5dd1eb 1193 regno, safe_strerror (err));
61bb466e
KW
1194 }
1195 }
1196 else
1197 {
1198 regset = nto_regset_id (regno);
1199 if (regset == -1)
1200 return;
1201
1202 dev_set = get_regset (regset, (char *) &reg, sizeof (reg), &regsize);
1203 if (dev_set == -1)
1204 return;
1205
60441ab9
UW
1206 len = nto_register_area (get_regcache_arch (regcache),
1207 regno, regset, &off);
61bb466e
KW
1208
1209 if (len < 1)
1210 return;
1211
56be3814 1212 regcache_raw_collect (regcache, regno, (char *) &reg + off);
61bb466e
KW
1213
1214 err = devctl (ctl_fd, dev_set, &reg, regsize, 0);
1215 if (err != EOK)
1216 fprintf_unfiltered (gdb_stderr,
1217 "Warning unable to write regset %d: %s\n", regno,
dc5dd1eb 1218 safe_strerror (err));
61bb466e
KW
1219 }
1220}
1221
1222static void
1223notice_signals (void)
1224{
1225 int signo;
1226
1227 for (signo = 1; signo < NSIG; signo++)
1228 {
1229 if (signal_stop_state (target_signal_from_host (signo)) == 0
1230 && signal_print_state (target_signal_from_host (signo)) == 0
1231 && signal_pass_state (target_signal_from_host (signo)) == 1)
1232 sigdelset (&run.trace, signo);
1233 else
1234 sigaddset (&run.trace, signo);
1235 }
1236}
1237
1238/* When the user changes the state of gdb's signal handling via the
1239 "handle" command, this function gets called to see if any change
1240 in the /proc interface is required. It is also called internally
1241 by other /proc interface functions to initialize the state of
1242 the traced signal set. */
1243static void
1244procfs_notice_signals (ptid_t ptid)
1245{
1246 sigemptyset (&run.trace);
1247 notice_signals ();
1248}
1249
1250static struct tidinfo *
1251procfs_thread_info (pid_t pid, short tid)
1252{
1253/* NYI */
1254 return NULL;
1255}
1256
1257char *
1258procfs_pid_to_str (ptid_t ptid)
1259{
1260 static char buf[1024];
1261 int pid, tid, n;
1262 struct tidinfo *tip;
1263
1264 pid = ptid_get_pid (ptid);
1265 tid = ptid_get_tid (ptid);
1266
dc5dd1eb 1267 n = snprintf (buf, 1023, "process %d", pid);
61bb466e
KW
1268
1269#if 0 /* NYI */
1270 tip = procfs_thread_info (pid, tid);
1271 if (tip != NULL)
dc5dd1eb 1272 snprintf (&buf[n], 1023, " (state = 0x%02x)", tip->state);
61bb466e
KW
1273#endif
1274
1275 return buf;
1276}
1277
1278static void
dc5dd1eb 1279init_procfs_ops (void)
61bb466e
KW
1280{
1281 procfs_ops.to_shortname = "procfs";
1282 procfs_ops.to_longname = "QNX Neutrino procfs child process";
1283 procfs_ops.to_doc =
1284 "QNX Neutrino procfs child process (started by the \"run\" command).\n\
1285 target procfs <node>";
1286 procfs_ops.to_open = procfs_open;
1287 procfs_ops.to_attach = procfs_attach;
1288 procfs_ops.to_post_attach = procfs_post_attach;
1289 procfs_ops.to_detach = procfs_detach;
1290 procfs_ops.to_resume = procfs_resume;
1291 procfs_ops.to_wait = procfs_wait;
1292 procfs_ops.to_fetch_registers = procfs_fetch_registers;
1293 procfs_ops.to_store_registers = procfs_store_registers;
1294 procfs_ops.to_prepare_to_store = procfs_prepare_to_store;
c8e73a31 1295 procfs_ops.deprecated_xfer_memory = procfs_xfer_memory;
61bb466e
KW
1296 procfs_ops.to_files_info = procfs_files_info;
1297 procfs_ops.to_insert_breakpoint = procfs_insert_breakpoint;
1298 procfs_ops.to_remove_breakpoint = procfs_remove_breakpoint;
1299 procfs_ops.to_can_use_hw_breakpoint = procfs_can_use_hw_breakpoint;
1300 procfs_ops.to_insert_hw_breakpoint = procfs_insert_hw_breakpoint;
1301 procfs_ops.to_remove_hw_breakpoint = procfs_remove_breakpoint;
1302 procfs_ops.to_insert_watchpoint = procfs_insert_hw_watchpoint;
1303 procfs_ops.to_remove_watchpoint = procfs_remove_hw_watchpoint;
1304 procfs_ops.to_stopped_by_watchpoint = procfs_stopped_by_watchpoint;
1305 procfs_ops.to_terminal_init = terminal_init_inferior;
1306 procfs_ops.to_terminal_inferior = terminal_inferior;
1307 procfs_ops.to_terminal_ours_for_output = terminal_ours_for_output;
1308 procfs_ops.to_terminal_ours = terminal_ours;
1309 procfs_ops.to_terminal_info = child_terminal_info;
1310 procfs_ops.to_kill = procfs_kill_inferior;
1311 procfs_ops.to_create_inferior = procfs_create_inferior;
1312 procfs_ops.to_mourn_inferior = procfs_mourn_inferior;
1313 procfs_ops.to_can_run = procfs_can_run;
1314 procfs_ops.to_notice_signals = procfs_notice_signals;
1315 procfs_ops.to_thread_alive = procfs_thread_alive;
1316 procfs_ops.to_find_new_threads = procfs_find_new_threads;
1317 procfs_ops.to_pid_to_str = procfs_pid_to_str;
1318 procfs_ops.to_stop = procfs_stop;
1319 procfs_ops.to_stratum = process_stratum;
1320 procfs_ops.to_has_all_memory = 1;
1321 procfs_ops.to_has_memory = 1;
1322 procfs_ops.to_has_stack = 1;
1323 procfs_ops.to_has_registers = 1;
1324 procfs_ops.to_has_execution = 1;
1325 procfs_ops.to_magic = OPS_MAGIC;
1326 procfs_ops.to_have_continuable_watchpoint = 1;
1327}
1328
1329#define OSTYPE_NTO 1
1330
1331void
dc5dd1eb 1332_initialize_procfs (void)
61bb466e
KW
1333{
1334 sigset_t set;
1335
1336 init_procfs_ops ();
1337 add_target (&procfs_ops);
1338
1339 /* We use SIGUSR1 to gain control after we block waiting for a process.
1340 We use sigwaitevent to wait. */
1341 sigemptyset (&set);
1342 sigaddset (&set, SIGUSR1);
1343 sigprocmask (SIG_BLOCK, &set, NULL);
1344
1345 /* Set up trace and fault sets, as gdb expects them. */
1346 sigemptyset (&run.trace);
61bb466e
KW
1347
1348 /* Stuff some information. */
1349 nto_cpuinfo_flags = SYSPAGE_ENTRY (cpuinfo)->flags;
1350 nto_cpuinfo_valid = 1;
1351
1bedd215
AC
1352 add_info ("pidlist", procfs_pidlist, _("pidlist"));
1353 add_info ("meminfo", procfs_meminfo, _("memory information"));
d737fd7f
KW
1354
1355 nto_is_nto_target = procfs_is_nto_target;
61bb466e
KW
1356}
1357
1358
1359static int
1360procfs_hw_watchpoint (int addr, int len, int type)
1361{
1362 procfs_break brk;
1363
1364 switch (type)
1365 {
1366 case 1: /* Read. */
1367 brk.type = _DEBUG_BREAK_RD;
1368 break;
1369 case 2: /* Read/Write. */
1370 brk.type = _DEBUG_BREAK_RW;
1371 break;
1372 default: /* Modify. */
1373/* FIXME: brk.type = _DEBUG_BREAK_RWM gives EINVAL for some reason. */
1374 brk.type = _DEBUG_BREAK_RW;
1375 }
1376 brk.type |= _DEBUG_BREAK_HW; /* Always ask for HW. */
1377 brk.addr = addr;
1378 brk.size = len;
1379
1380 errno = devctl (ctl_fd, DCMD_PROC_BREAK, &brk, sizeof (brk), 0);
1381 if (errno != EOK)
1382 {
1383 perror ("Failed to set hardware watchpoint");
1384 return -1;
1385 }
1386 return 0;
1387}
1388
1389static int
1390procfs_can_use_hw_breakpoint (int type, int cnt, int othertype)
1391{
1392 return 1;
1393}
1394
1395static int
1396procfs_remove_hw_watchpoint (CORE_ADDR addr, int len, int type)
1397{
1398 return procfs_hw_watchpoint (addr, -1, type);
1399}
1400
1401static int
1402procfs_insert_hw_watchpoint (CORE_ADDR addr, int len, int type)
1403{
1404 return procfs_hw_watchpoint (addr, len, type);
1405}
1406
1407static int
1408procfs_stopped_by_watchpoint (void)
1409{
1410 return 0;
1411}
This page took 0.576124 seconds and 4 git commands to generate.