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