| 1 | /* Machine independent support for SVR4 /proc (process file system) for GDB. |
| 2 | Copyright (C) 1991 Free Software Foundation, Inc. |
| 3 | Written by Fred Fish at Cygnus Support. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 20 | |
| 21 | |
| 22 | /* N O T E S |
| 23 | |
| 24 | For information on the details of using /proc consult section proc(4) |
| 25 | in the UNIX System V Release 4 System Administrator's Reference Manual. |
| 26 | |
| 27 | The general register and floating point register sets are manipulated by |
| 28 | separate ioctl's. This file makes the assumption that if FP0_REGNUM is |
| 29 | defined, then support for the floating point register set is desired, |
| 30 | regardless of whether or not the actual target has floating point hardware. |
| 31 | |
| 32 | */ |
| 33 | |
| 34 | |
| 35 | #include "defs.h" |
| 36 | |
| 37 | #ifdef USE_PROC_FS /* Entire file goes away if not using /proc */ |
| 38 | |
| 39 | #include <time.h> |
| 40 | #include <sys/procfs.h> |
| 41 | #include <fcntl.h> |
| 42 | #include <errno.h> |
| 43 | |
| 44 | #include "inferior.h" |
| 45 | #include "target.h" |
| 46 | |
| 47 | #define MAX_SYSCALLS 256 /* Maximum number of syscalls for table */ |
| 48 | |
| 49 | #ifndef PROC_NAME_FMT |
| 50 | #define PROC_NAME_FMT "/proc/%05d" |
| 51 | #endif |
| 52 | |
| 53 | #if 1 /* FIXME: Gross and ugly hack to resolve coredep.c global */ |
| 54 | CORE_ADDR kernel_u_addr; |
| 55 | #endif |
| 56 | |
| 57 | #ifdef BROKEN_SIGINFO_H /* Workaround broken SGS <sys/siginfo.h> */ |
| 58 | #undef si_pid |
| 59 | #define si_pid _data._proc.pid |
| 60 | #undef si_uid |
| 61 | #define si_uid _data._proc._pdata._kill.uid |
| 62 | #endif /* BROKEN_SIGINFO_H */ |
| 63 | |
| 64 | /* All access to the inferior, either one started by gdb or one that has |
| 65 | been attached to, is controlled by an instance of a procinfo structure, |
| 66 | defined below. Since gdb currently only handles one inferior at a time, |
| 67 | the procinfo structure for the inferior is statically allocated and |
| 68 | only one exists at any given time. There is a separate procinfo |
| 69 | structure for use by the "info proc" command, so that we can print |
| 70 | useful information about any random process without interfering with |
| 71 | the inferior's procinfo information. */ |
| 72 | |
| 73 | struct procinfo { |
| 74 | int valid; /* Nonzero if pid, fd, & pathname are valid */ |
| 75 | int pid; /* Process ID of inferior */ |
| 76 | int fd; /* File descriptor for /proc entry */ |
| 77 | char *pathname; /* Pathname to /proc entry */ |
| 78 | int was_stopped; /* Nonzero if was stopped prior to attach */ |
| 79 | int nopass_next_sigstop; /* Don't pass a sigstop on next resume */ |
| 80 | prrun_t prrun; /* Control state when it is run */ |
| 81 | prstatus_t prstatus; /* Current process status info */ |
| 82 | gregset_t gregset; /* General register set */ |
| 83 | fpregset_t fpregset; /* Floating point register set */ |
| 84 | fltset_t fltset; /* Current traced hardware fault set */ |
| 85 | sigset_t trace; /* Current traced signal set */ |
| 86 | sysset_t exitset; /* Current traced system call exit set */ |
| 87 | sysset_t entryset; /* Current traced system call entry set */ |
| 88 | fltset_t saved_fltset; /* Saved traced hardware fault set */ |
| 89 | sigset_t saved_trace; /* Saved traced signal set */ |
| 90 | sigset_t saved_sighold; /* Saved held signal set */ |
| 91 | sysset_t saved_exitset; /* Saved traced system call exit set */ |
| 92 | sysset_t saved_entryset; /* Saved traced system call entry set */ |
| 93 | }; |
| 94 | |
| 95 | static struct procinfo pi; /* Inferior's process information */ |
| 96 | |
| 97 | /* Much of the information used in the /proc interface, particularly for |
| 98 | printing status information, is kept as tables of structures of the |
| 99 | following form. These tables can be used to map numeric values to |
| 100 | their symbolic names and to a string that describes their specific use. */ |
| 101 | |
| 102 | struct trans { |
| 103 | int value; /* The numeric value */ |
| 104 | char *name; /* The equivalent symbolic value */ |
| 105 | char *desc; /* Short description of value */ |
| 106 | }; |
| 107 | |
| 108 | /* Translate bits in the pr_flags member of the prstatus structure, into the |
| 109 | names and desc information. */ |
| 110 | |
| 111 | static struct trans pr_flag_table[] = |
| 112 | { |
| 113 | #if defined (PR_STOPPED) |
| 114 | PR_STOPPED, "PR_STOPPED", "Process is stopped", |
| 115 | #endif |
| 116 | #if defined (PR_ISTOP) |
| 117 | PR_ISTOP, "PR_ISTOP", "Stopped on an event of interest", |
| 118 | #endif |
| 119 | #if defined (PR_DSTOP) |
| 120 | PR_DSTOP, "PR_DSTOP", "A stop directive is in effect", |
| 121 | #endif |
| 122 | #if defined (PR_ASLEEP) |
| 123 | PR_ASLEEP, "PR_ASLEEP", "Sleeping in an interruptible system call", |
| 124 | #endif |
| 125 | #if defined (PR_FORK) |
| 126 | PR_FORK, "PR_FORK", "Inherit-on-fork is in effect", |
| 127 | #endif |
| 128 | #if defined (PR_RLC) |
| 129 | PR_RLC, "PR_RLC", "Run-on-last-close is in effect", |
| 130 | #endif |
| 131 | #if defined (PR_PTRACE) |
| 132 | PR_PTRACE, "PR_PTRACE", "Process is being controlled by ptrace", |
| 133 | #endif |
| 134 | #if defined (PR_PCINVAL) |
| 135 | PR_PCINVAL, "PR_PCINVAL", "PC refers to an invalid virtual address", |
| 136 | #endif |
| 137 | #if defined (PR_ISSYS) |
| 138 | PR_ISSYS, "PR_ISSYS", "Is a system process", |
| 139 | #endif |
| 140 | #if defined (PR_STEP) |
| 141 | PR_STEP, "PR_STEP", "Process has single step pending", |
| 142 | #endif |
| 143 | #if defined (PR_KLC) |
| 144 | PR_KLC, "PR_KLC", "Kill-on-last-close is in effect", |
| 145 | #endif |
| 146 | #if defined (PR_ASYNC) |
| 147 | PR_ASYNC, "PR_ASYNC", "Asynchronous stop is in effect", |
| 148 | #endif |
| 149 | #if defined (PR_PCOMPAT) |
| 150 | PR_PCOMPAT, "PR_PCOMPAT", "Ptrace compatibility mode in effect", |
| 151 | #endif |
| 152 | 0, NULL, NULL |
| 153 | }; |
| 154 | |
| 155 | /* Translate values in the pr_why field of the prstatus struct. */ |
| 156 | |
| 157 | static struct trans pr_why_table[] = |
| 158 | { |
| 159 | #if defined (PR_REQUESTED) |
| 160 | PR_REQUESTED, "PR_REQUESTED", "Directed to stop via PIOCSTOP/PIOCWSTOP", |
| 161 | #endif |
| 162 | #if defined (PR_SIGNALLED) |
| 163 | PR_SIGNALLED, "PR_SIGNALLED", "Receipt of a traced signal", |
| 164 | #endif |
| 165 | #if defined (PR_FAULTED) |
| 166 | PR_FAULTED, "PR_FAULTED", "Incurred a traced hardware fault", |
| 167 | #endif |
| 168 | #if defined (PR_SYSENTRY) |
| 169 | PR_SYSENTRY, "PR_SYSENTRY", "Entry to a traced system call", |
| 170 | #endif |
| 171 | #if defined (PR_SYSEXIT) |
| 172 | PR_SYSEXIT, "PR_SYSEXIT", "Exit from a traced system call", |
| 173 | #endif |
| 174 | #if defined (PR_JOBCONTROL) |
| 175 | PR_JOBCONTROL, "PR_JOBCONTROL", "Default job control stop signal action", |
| 176 | #endif |
| 177 | #if defined (PR_SUSPENDED) |
| 178 | PR_SUSPENDED, "PR_SUSPENDED", "Process suspended", |
| 179 | #endif |
| 180 | 0, NULL, NULL |
| 181 | }; |
| 182 | |
| 183 | /* Hardware fault translation table. */ |
| 184 | |
| 185 | static struct trans faults_table[] = |
| 186 | { |
| 187 | #if defined (FLTILL) |
| 188 | FLTILL, "FLTILL", "Illegal instruction", |
| 189 | #endif |
| 190 | #if defined (FLTPRIV) |
| 191 | FLTPRIV, "FLTPRIV", "Privileged instruction", |
| 192 | #endif |
| 193 | #if defined (FLTBPT) |
| 194 | FLTBPT, "FLTBPT", "Breakpoint trap", |
| 195 | #endif |
| 196 | #if defined (FLTTRACE) |
| 197 | FLTTRACE, "FLTTRACE", "Trace trap", |
| 198 | #endif |
| 199 | #if defined (FLTACCESS) |
| 200 | FLTACCESS, "FLTACCESS", "Memory access fault", |
| 201 | #endif |
| 202 | #if defined (FLTBOUNDS) |
| 203 | FLTBOUNDS, "FLTBOUNDS", "Memory bounds violation", |
| 204 | #endif |
| 205 | #if defined (FLTIOVF) |
| 206 | FLTIOVF, "FLTIOVF", "Integer overflow", |
| 207 | #endif |
| 208 | #if defined (FLTIZDIV) |
| 209 | FLTIZDIV, "FLTIZDIV", "Integer zero divide", |
| 210 | #endif |
| 211 | #if defined (FLTFPE) |
| 212 | FLTFPE, "FLTFPE", "Floating-point exception", |
| 213 | #endif |
| 214 | #if defined (FLTSTACK) |
| 215 | FLTSTACK, "FLTSTACK", "Unrecoverable stack fault", |
| 216 | #endif |
| 217 | #if defined (FLTPAGE) |
| 218 | FLTPAGE, "FLTPAGE", "Recoverable page fault", |
| 219 | #endif |
| 220 | 0, NULL, NULL |
| 221 | }; |
| 222 | |
| 223 | /* Translation table for signal generation information. See UNIX System |
| 224 | V Release 4 Programmer's Reference Manual, siginfo(5). */ |
| 225 | |
| 226 | static struct sigcode { |
| 227 | int signo; |
| 228 | int code; |
| 229 | char *codename; |
| 230 | char *desc; |
| 231 | } siginfo_table[] = { |
| 232 | #if defined (SIGILL) && defined (ILL_ILLOPC) |
| 233 | SIGILL, ILL_ILLOPC, "ILL_ILLOPC", "Illegal opcode", |
| 234 | #endif |
| 235 | #if defined (SIGILL) && defined (ILL_ILLOPN) |
| 236 | SIGILL, ILL_ILLOPN, "ILL_ILLOPN", "Illegal operand", |
| 237 | #endif |
| 238 | #if defined (SIGILL) && defined (ILL_ILLADR) |
| 239 | SIGILL, ILL_ILLADR, "ILL_ILLADR", "Illegal addressing mode", |
| 240 | #endif |
| 241 | #if defined (SIGILL) && defined (ILL_ILLTRP) |
| 242 | SIGILL, ILL_ILLTRP, "ILL_ILLTRP", "Illegal trap", |
| 243 | #endif |
| 244 | #if defined (SIGILL) && defined (ILL_PRVOPC) |
| 245 | SIGILL, ILL_PRVOPC, "ILL_PRVOPC", "Privileged opcode", |
| 246 | #endif |
| 247 | #if defined (SIGILL) && defined (ILL_PRVREG) |
| 248 | SIGILL, ILL_PRVREG, "ILL_PRVREG", "Privileged register", |
| 249 | #endif |
| 250 | #if defined (SIGILL) && defined (ILL_COPROC) |
| 251 | SIGILL, ILL_COPROC, "ILL_COPROC", "Coprocessor error", |
| 252 | #endif |
| 253 | #if defined (SIGILL) && defined (ILL_BADSTK) |
| 254 | SIGILL, ILL_BADSTK, "ILL_BADSTK", "Internal stack error", |
| 255 | #endif |
| 256 | #if defined (SIGFPE) && defined (FPE_INTDIV) |
| 257 | SIGFPE, FPE_INTDIV, "FPE_INTDIV", "Integer divide by zero", |
| 258 | #endif |
| 259 | #if defined (SIGFPE) && defined (FPE_INTOVF) |
| 260 | SIGFPE, FPE_INTOVF, "FPE_INTOVF", "Integer overflow", |
| 261 | #endif |
| 262 | #if defined (SIGFPE) && defined (FPE_FLTDIV) |
| 263 | SIGFPE, FPE_FLTDIV, "FPE_FLTDIV", "Floating point divide by zero", |
| 264 | #endif |
| 265 | #if defined (SIGFPE) && defined (FPE_FLTOVF) |
| 266 | SIGFPE, FPE_FLTOVF, "FPE_FLTOVF", "Floating point overflow", |
| 267 | #endif |
| 268 | #if defined (SIGFPE) && defined (FPE_FLTUND) |
| 269 | SIGFPE, FPE_FLTUND, "FPE_FLTUND", "Floating point underflow", |
| 270 | #endif |
| 271 | #if defined (SIGFPE) && defined (FPE_FLTRES) |
| 272 | SIGFPE, FPE_FLTRES, "FPE_FLTRES", "Floating point inexact result", |
| 273 | #endif |
| 274 | #if defined (SIGFPE) && defined (FPE_FLTINV) |
| 275 | SIGFPE, FPE_FLTINV, "FPE_FLTINV", "Invalid floating point operation", |
| 276 | #endif |
| 277 | #if defined (SIGFPE) && defined (FPE_FLTSUB) |
| 278 | SIGFPE, FPE_FLTSUB, "FPE_FLTSUB", "Subscript out of range", |
| 279 | #endif |
| 280 | #if defined (SIGSEGV) && defined (SEGV_MAPERR) |
| 281 | SIGSEGV, SEGV_MAPERR, "SEGV_MAPERR", "Address not mapped to object", |
| 282 | #endif |
| 283 | #if defined (SIGSEGV) && defined (SEGV_ACCERR) |
| 284 | SIGSEGV, SEGV_ACCERR, "SEGV_ACCERR", "Invalid permissions for object", |
| 285 | #endif |
| 286 | #if defined (SIGBUS) && defined (BUS_ADRALN) |
| 287 | SIGBUS, BUS_ADRALN, "BUS_ADRALN", "Invalid address alignment", |
| 288 | #endif |
| 289 | #if defined (SIGBUS) && defined (BUS_ADRERR) |
| 290 | SIGBUS, BUS_ADRERR, "BUS_ADRERR", "Non-existent physical address", |
| 291 | #endif |
| 292 | #if defined (SIGBUS) && defined (BUS_OBJERR) |
| 293 | SIGBUS, BUS_OBJERR, "BUS_OBJERR", "Object specific hardware error", |
| 294 | #endif |
| 295 | #if defined (SIGTRAP) && defined (TRAP_BRKPT) |
| 296 | SIGTRAP, TRAP_BRKPT, "TRAP_BRKPT", "Process breakpoint", |
| 297 | #endif |
| 298 | #if defined (SIGTRAP) && defined (TRAP_TRACE) |
| 299 | SIGTRAP, TRAP_TRACE, "TRAP_TRACE", "Process trace trap", |
| 300 | #endif |
| 301 | #if defined (SIGCLD) && defined (CLD_EXITED) |
| 302 | SIGCLD, CLD_EXITED, "CLD_EXITED", "Child has exited", |
| 303 | #endif |
| 304 | #if defined (SIGCLD) && defined (CLD_KILLED) |
| 305 | SIGCLD, CLD_KILLED, "CLD_KILLED", "Child was killed", |
| 306 | #endif |
| 307 | #if defined (SIGCLD) && defined (CLD_DUMPED) |
| 308 | SIGCLD, CLD_DUMPED, "CLD_DUMPED", "Child has terminated abnormally", |
| 309 | #endif |
| 310 | #if defined (SIGCLD) && defined (CLD_TRAPPED) |
| 311 | SIGCLD, CLD_TRAPPED, "CLD_TRAPPED", "Traced child has trapped", |
| 312 | #endif |
| 313 | #if defined (SIGCLD) && defined (CLD_STOPPED) |
| 314 | SIGCLD, CLD_STOPPED, "CLD_STOPPED", "Child has stopped", |
| 315 | #endif |
| 316 | #if defined (SIGCLD) && defined (CLD_CONTINUED) |
| 317 | SIGCLD, CLD_CONTINUED, "CLD_CONTINUED", "Stopped child had continued", |
| 318 | #endif |
| 319 | #if defined (SIGPOLL) && defined (POLL_IN) |
| 320 | SIGPOLL, POLL_IN, "POLL_IN", "Input input available", |
| 321 | #endif |
| 322 | #if defined (SIGPOLL) && defined (POLL_OUT) |
| 323 | SIGPOLL, POLL_OUT, "POLL_OUT", "Output buffers available", |
| 324 | #endif |
| 325 | #if defined (SIGPOLL) && defined (POLL_MSG) |
| 326 | SIGPOLL, POLL_MSG, "POLL_MSG", "Input message available", |
| 327 | #endif |
| 328 | #if defined (SIGPOLL) && defined (POLL_ERR) |
| 329 | SIGPOLL, POLL_ERR, "POLL_ERR", "I/O error", |
| 330 | #endif |
| 331 | #if defined (SIGPOLL) && defined (POLL_PRI) |
| 332 | SIGPOLL, POLL_PRI, "POLL_PRI", "High priority input available", |
| 333 | #endif |
| 334 | #if defined (SIGPOLL) && defined (POLL_HUP) |
| 335 | SIGPOLL, POLL_HUP, "POLL_HUP", "Device disconnected", |
| 336 | #endif |
| 337 | 0, 0, NULL, NULL |
| 338 | }; |
| 339 | |
| 340 | static char *syscall_table[MAX_SYSCALLS]; |
| 341 | |
| 342 | /* Prototypes for local functions */ |
| 343 | |
| 344 | static void |
| 345 | set_proc_siginfo PARAMS ((struct procinfo *, int)); |
| 346 | |
| 347 | static void |
| 348 | init_syscall_table PARAMS ((void)); |
| 349 | |
| 350 | static char * |
| 351 | syscallname PARAMS ((int)); |
| 352 | |
| 353 | static char * |
| 354 | signalname PARAMS ((int)); |
| 355 | |
| 356 | static char * |
| 357 | errnoname PARAMS ((int)); |
| 358 | |
| 359 | static int |
| 360 | proc_address_to_fd PARAMS ((CORE_ADDR, int)); |
| 361 | |
| 362 | static int |
| 363 | open_proc_file PARAMS ((int, struct procinfo *)); |
| 364 | |
| 365 | static void |
| 366 | close_proc_file PARAMS ((struct procinfo *)); |
| 367 | |
| 368 | static void |
| 369 | unconditionally_kill_inferior PARAMS ((void)); |
| 370 | |
| 371 | static void |
| 372 | proc_init_failed PARAMS ((char *)); |
| 373 | |
| 374 | static void |
| 375 | info_proc PARAMS ((char *, int)); |
| 376 | |
| 377 | static void |
| 378 | info_proc_flags PARAMS ((struct procinfo *, int)); |
| 379 | |
| 380 | static void |
| 381 | info_proc_stop PARAMS ((struct procinfo *, int)); |
| 382 | |
| 383 | static void |
| 384 | info_proc_siginfo PARAMS ((struct procinfo *, int)); |
| 385 | |
| 386 | static void |
| 387 | info_proc_syscalls PARAMS ((struct procinfo *, int)); |
| 388 | |
| 389 | static void |
| 390 | info_proc_mappings PARAMS ((struct procinfo *, int)); |
| 391 | |
| 392 | static void |
| 393 | info_proc_signals PARAMS ((struct procinfo *, int)); |
| 394 | |
| 395 | static void |
| 396 | info_proc_faults PARAMS ((struct procinfo *, int)); |
| 397 | |
| 398 | static char * |
| 399 | mappingflags PARAMS ((long)); |
| 400 | |
| 401 | static char * |
| 402 | lookupname PARAMS ((struct trans *, unsigned int, char *)); |
| 403 | |
| 404 | static char * |
| 405 | lookupdesc PARAMS ((struct trans *, unsigned int)); |
| 406 | |
| 407 | /* External function prototypes that can't be easily included in any |
| 408 | header file because the args are typedefs in system include files. */ |
| 409 | |
| 410 | extern void |
| 411 | supply_gregset PARAMS ((gregset_t *)); |
| 412 | |
| 413 | extern void |
| 414 | fill_gregset PARAMS ((gregset_t *, int)); |
| 415 | |
| 416 | extern void |
| 417 | supply_fpregset PARAMS ((fpregset_t *)); |
| 418 | |
| 419 | extern void |
| 420 | fill_fpregset PARAMS ((fpregset_t *, int)); |
| 421 | |
| 422 | /* |
| 423 | |
| 424 | LOCAL FUNCTION |
| 425 | |
| 426 | lookupdesc -- translate a value to a summary desc string |
| 427 | |
| 428 | SYNOPSIS |
| 429 | |
| 430 | static char *lookupdesc (struct trans *transp, unsigned int val); |
| 431 | |
| 432 | DESCRIPTION |
| 433 | |
| 434 | Given a pointer to a translation table and a value to be translated, |
| 435 | lookup the desc string and return it. |
| 436 | */ |
| 437 | |
| 438 | static char * |
| 439 | lookupdesc (transp, val) |
| 440 | struct trans *transp; |
| 441 | unsigned int val; |
| 442 | { |
| 443 | char *desc; |
| 444 | |
| 445 | for (desc = NULL; transp -> name != NULL; transp++) |
| 446 | { |
| 447 | if (transp -> value == val) |
| 448 | { |
| 449 | desc = transp -> desc; |
| 450 | break; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | /* Didn't find a translation for the specified value, set a default one. */ |
| 455 | |
| 456 | if (desc == NULL) |
| 457 | { |
| 458 | desc = "Unknown"; |
| 459 | } |
| 460 | return (desc); |
| 461 | } |
| 462 | |
| 463 | /* |
| 464 | |
| 465 | LOCAL FUNCTION |
| 466 | |
| 467 | lookupname -- translate a value to symbolic name |
| 468 | |
| 469 | SYNOPSIS |
| 470 | |
| 471 | static char *lookupname (struct trans *transp, unsigned int val, |
| 472 | char *prefix); |
| 473 | |
| 474 | DESCRIPTION |
| 475 | |
| 476 | Given a pointer to a translation table, a value to be translated, |
| 477 | and a default prefix to return if the value can't be translated, |
| 478 | match the value with one of the translation table entries and |
| 479 | return a pointer to the symbolic name. |
| 480 | |
| 481 | If no match is found it just returns the value as a printable string, |
| 482 | with the given prefix. The previous such value, if any, is freed |
| 483 | at this time. |
| 484 | */ |
| 485 | |
| 486 | static char * |
| 487 | lookupname (transp, val, prefix) |
| 488 | struct trans *transp; |
| 489 | unsigned int val; |
| 490 | char *prefix; |
| 491 | { |
| 492 | static char *locbuf; |
| 493 | char *name; |
| 494 | |
| 495 | for (name = NULL; transp -> name != NULL; transp++) |
| 496 | { |
| 497 | if (transp -> value == val) |
| 498 | { |
| 499 | name = transp -> name; |
| 500 | break; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | /* Didn't find a translation for the specified value, build a default |
| 505 | one using the specified prefix and return it. The lifetime of |
| 506 | the value is only until the next one is needed. */ |
| 507 | |
| 508 | if (name == NULL) |
| 509 | { |
| 510 | if (locbuf != NULL) |
| 511 | { |
| 512 | free (locbuf); |
| 513 | } |
| 514 | locbuf = xmalloc (strlen (prefix) + 16); |
| 515 | (void) sprintf (locbuf, "%s %u", prefix, val); |
| 516 | name = locbuf; |
| 517 | } |
| 518 | return (name); |
| 519 | } |
| 520 | |
| 521 | static char * |
| 522 | sigcodename (sip) |
| 523 | siginfo_t *sip; |
| 524 | { |
| 525 | struct sigcode *scp; |
| 526 | char *name = NULL; |
| 527 | static char locbuf[32]; |
| 528 | |
| 529 | for (scp = siginfo_table; scp -> codename != NULL; scp++) |
| 530 | { |
| 531 | if ((scp -> signo == sip -> si_signo) && |
| 532 | (scp -> code == sip -> si_code)) |
| 533 | { |
| 534 | name = scp -> codename; |
| 535 | break; |
| 536 | } |
| 537 | } |
| 538 | if (name == NULL) |
| 539 | { |
| 540 | (void) sprintf (locbuf, "sigcode %u", sip -> si_signo); |
| 541 | name = locbuf; |
| 542 | } |
| 543 | return (name); |
| 544 | } |
| 545 | |
| 546 | static char *sigcodedesc (sip) |
| 547 | siginfo_t *sip; |
| 548 | { |
| 549 | struct sigcode *scp; |
| 550 | char *desc = NULL; |
| 551 | |
| 552 | for (scp = siginfo_table; scp -> codename != NULL; scp++) |
| 553 | { |
| 554 | if ((scp -> signo == sip -> si_signo) && |
| 555 | (scp -> code == sip -> si_code)) |
| 556 | { |
| 557 | desc = scp -> desc; |
| 558 | break; |
| 559 | } |
| 560 | } |
| 561 | if (desc == NULL) |
| 562 | { |
| 563 | desc = "Unrecognized signal or trap use"; |
| 564 | } |
| 565 | return (desc); |
| 566 | } |
| 567 | |
| 568 | /* |
| 569 | |
| 570 | LOCAL FUNCTION |
| 571 | |
| 572 | syscallname - translate a system call number into a system call name |
| 573 | |
| 574 | SYNOPSIS |
| 575 | |
| 576 | char *syscallname (int syscallnum) |
| 577 | |
| 578 | DESCRIPTION |
| 579 | |
| 580 | Given a system call number, translate it into the printable name |
| 581 | of a system call, or into "syscall <num>" if it is an unknown |
| 582 | number. |
| 583 | */ |
| 584 | |
| 585 | static char * |
| 586 | syscallname (syscallnum) |
| 587 | int syscallnum; |
| 588 | { |
| 589 | static char locbuf[32]; |
| 590 | char *rtnval; |
| 591 | |
| 592 | if (syscallnum >= 0 && syscallnum < MAX_SYSCALLS) |
| 593 | { |
| 594 | rtnval = syscall_table[syscallnum]; |
| 595 | } |
| 596 | else |
| 597 | { |
| 598 | (void) sprintf (locbuf, "syscall %u", syscallnum); |
| 599 | rtnval = locbuf; |
| 600 | } |
| 601 | return (rtnval); |
| 602 | } |
| 603 | |
| 604 | /* |
| 605 | |
| 606 | LOCAL FUNCTION |
| 607 | |
| 608 | init_syscall_table - initialize syscall translation table |
| 609 | |
| 610 | SYNOPSIS |
| 611 | |
| 612 | void init_syscall_table (void) |
| 613 | |
| 614 | DESCRIPTION |
| 615 | |
| 616 | Dynamically initialize the translation table to convert system |
| 617 | call numbers into printable system call names. Done once per |
| 618 | gdb run, on initialization. |
| 619 | |
| 620 | NOTES |
| 621 | |
| 622 | This is awfully ugly, but preprocessor tricks to make it prettier |
| 623 | tend to be nonportable. |
| 624 | */ |
| 625 | |
| 626 | static void |
| 627 | init_syscall_table () |
| 628 | { |
| 629 | int syscallnum; |
| 630 | |
| 631 | #if defined (SYS_exit) |
| 632 | syscall_table[SYS_exit] = "exit"; |
| 633 | #endif |
| 634 | #if defined (SYS_fork) |
| 635 | syscall_table[SYS_fork] = "fork"; |
| 636 | #endif |
| 637 | #if defined (SYS_read) |
| 638 | syscall_table[SYS_read] = "read"; |
| 639 | #endif |
| 640 | #if defined (SYS_write) |
| 641 | syscall_table[SYS_write] = "write"; |
| 642 | #endif |
| 643 | #if defined (SYS_open) |
| 644 | syscall_table[SYS_open] = "open"; |
| 645 | #endif |
| 646 | #if defined (SYS_close) |
| 647 | syscall_table[SYS_close] = "close"; |
| 648 | #endif |
| 649 | #if defined (SYS_wait) |
| 650 | syscall_table[SYS_wait] = "wait"; |
| 651 | #endif |
| 652 | #if defined (SYS_creat) |
| 653 | syscall_table[SYS_creat] = "creat"; |
| 654 | #endif |
| 655 | #if defined (SYS_link) |
| 656 | syscall_table[SYS_link] = "link"; |
| 657 | #endif |
| 658 | #if defined (SYS_unlink) |
| 659 | syscall_table[SYS_unlink] = "unlink"; |
| 660 | #endif |
| 661 | #if defined (SYS_exec) |
| 662 | syscall_table[SYS_exec] = "exec"; |
| 663 | #endif |
| 664 | #if defined (SYS_execv) |
| 665 | syscall_table[SYS_execv] = "execv"; |
| 666 | #endif |
| 667 | #if defined (SYS_execve) |
| 668 | syscall_table[SYS_execve] = "execve"; |
| 669 | #endif |
| 670 | #if defined (SYS_chdir) |
| 671 | syscall_table[SYS_chdir] = "chdir"; |
| 672 | #endif |
| 673 | #if defined (SYS_time) |
| 674 | syscall_table[SYS_time] = "time"; |
| 675 | #endif |
| 676 | #if defined (SYS_mknod) |
| 677 | syscall_table[SYS_mknod] = "mknod"; |
| 678 | #endif |
| 679 | #if defined (SYS_chmod) |
| 680 | syscall_table[SYS_chmod] = "chmod"; |
| 681 | #endif |
| 682 | #if defined (SYS_chown) |
| 683 | syscall_table[SYS_chown] = "chown"; |
| 684 | #endif |
| 685 | #if defined (SYS_brk) |
| 686 | syscall_table[SYS_brk] = "brk"; |
| 687 | #endif |
| 688 | #if defined (SYS_stat) |
| 689 | syscall_table[SYS_stat] = "stat"; |
| 690 | #endif |
| 691 | #if defined (SYS_lseek) |
| 692 | syscall_table[SYS_lseek] = "lseek"; |
| 693 | #endif |
| 694 | #if defined (SYS_getpid) |
| 695 | syscall_table[SYS_getpid] = "getpid"; |
| 696 | #endif |
| 697 | #if defined (SYS_mount) |
| 698 | syscall_table[SYS_mount] = "mount"; |
| 699 | #endif |
| 700 | #if defined (SYS_umount) |
| 701 | syscall_table[SYS_umount] = "umount"; |
| 702 | #endif |
| 703 | #if defined (SYS_setuid) |
| 704 | syscall_table[SYS_setuid] = "setuid"; |
| 705 | #endif |
| 706 | #if defined (SYS_getuid) |
| 707 | syscall_table[SYS_getuid] = "getuid"; |
| 708 | #endif |
| 709 | #if defined (SYS_stime) |
| 710 | syscall_table[SYS_stime] = "stime"; |
| 711 | #endif |
| 712 | #if defined (SYS_ptrace) |
| 713 | syscall_table[SYS_ptrace] = "ptrace"; |
| 714 | #endif |
| 715 | #if defined (SYS_alarm) |
| 716 | syscall_table[SYS_alarm] = "alarm"; |
| 717 | #endif |
| 718 | #if defined (SYS_fstat) |
| 719 | syscall_table[SYS_fstat] = "fstat"; |
| 720 | #endif |
| 721 | #if defined (SYS_pause) |
| 722 | syscall_table[SYS_pause] = "pause"; |
| 723 | #endif |
| 724 | #if defined (SYS_utime) |
| 725 | syscall_table[SYS_utime] = "utime"; |
| 726 | #endif |
| 727 | #if defined (SYS_stty) |
| 728 | syscall_table[SYS_stty] = "stty"; |
| 729 | #endif |
| 730 | #if defined (SYS_gtty) |
| 731 | syscall_table[SYS_gtty] = "gtty"; |
| 732 | #endif |
| 733 | #if defined (SYS_access) |
| 734 | syscall_table[SYS_access] = "access"; |
| 735 | #endif |
| 736 | #if defined (SYS_nice) |
| 737 | syscall_table[SYS_nice] = "nice"; |
| 738 | #endif |
| 739 | #if defined (SYS_statfs) |
| 740 | syscall_table[SYS_statfs] = "statfs"; |
| 741 | #endif |
| 742 | #if defined (SYS_sync) |
| 743 | syscall_table[SYS_sync] = "sync"; |
| 744 | #endif |
| 745 | #if defined (SYS_kill) |
| 746 | syscall_table[SYS_kill] = "kill"; |
| 747 | #endif |
| 748 | #if defined (SYS_fstatfs) |
| 749 | syscall_table[SYS_fstatfs] = "fstatfs"; |
| 750 | #endif |
| 751 | #if defined (SYS_pgrpsys) |
| 752 | syscall_table[SYS_pgrpsys] = "pgrpsys"; |
| 753 | #endif |
| 754 | #if defined (SYS_xenix) |
| 755 | syscall_table[SYS_xenix] = "xenix"; |
| 756 | #endif |
| 757 | #if defined (SYS_dup) |
| 758 | syscall_table[SYS_dup] = "dup"; |
| 759 | #endif |
| 760 | #if defined (SYS_pipe) |
| 761 | syscall_table[SYS_pipe] = "pipe"; |
| 762 | #endif |
| 763 | #if defined (SYS_times) |
| 764 | syscall_table[SYS_times] = "times"; |
| 765 | #endif |
| 766 | #if defined (SYS_profil) |
| 767 | syscall_table[SYS_profil] = "profil"; |
| 768 | #endif |
| 769 | #if defined (SYS_plock) |
| 770 | syscall_table[SYS_plock] = "plock"; |
| 771 | #endif |
| 772 | #if defined (SYS_setgid) |
| 773 | syscall_table[SYS_setgid] = "setgid"; |
| 774 | #endif |
| 775 | #if defined (SYS_getgid) |
| 776 | syscall_table[SYS_getgid] = "getgid"; |
| 777 | #endif |
| 778 | #if defined (SYS_signal) |
| 779 | syscall_table[SYS_signal] = "signal"; |
| 780 | #endif |
| 781 | #if defined (SYS_msgsys) |
| 782 | syscall_table[SYS_msgsys] = "msgsys"; |
| 783 | #endif |
| 784 | #if defined (SYS_sys3b) |
| 785 | syscall_table[SYS_sys3b] = "sys3b"; |
| 786 | #endif |
| 787 | #if defined (SYS_acct) |
| 788 | syscall_table[SYS_acct] = "acct"; |
| 789 | #endif |
| 790 | #if defined (SYS_shmsys) |
| 791 | syscall_table[SYS_shmsys] = "shmsys"; |
| 792 | #endif |
| 793 | #if defined (SYS_semsys) |
| 794 | syscall_table[SYS_semsys] = "semsys"; |
| 795 | #endif |
| 796 | #if defined (SYS_ioctl) |
| 797 | syscall_table[SYS_ioctl] = "ioctl"; |
| 798 | #endif |
| 799 | #if defined (SYS_uadmin) |
| 800 | syscall_table[SYS_uadmin] = "uadmin"; |
| 801 | #endif |
| 802 | #if defined (SYS_utssys) |
| 803 | syscall_table[SYS_utssys] = "utssys"; |
| 804 | #endif |
| 805 | #if defined (SYS_fsync) |
| 806 | syscall_table[SYS_fsync] = "fsync"; |
| 807 | #endif |
| 808 | #if defined (SYS_umask) |
| 809 | syscall_table[SYS_umask] = "umask"; |
| 810 | #endif |
| 811 | #if defined (SYS_chroot) |
| 812 | syscall_table[SYS_chroot] = "chroot"; |
| 813 | #endif |
| 814 | #if defined (SYS_fcntl) |
| 815 | syscall_table[SYS_fcntl] = "fcntl"; |
| 816 | #endif |
| 817 | #if defined (SYS_ulimit) |
| 818 | syscall_table[SYS_ulimit] = "ulimit"; |
| 819 | #endif |
| 820 | #if defined (SYS_rfsys) |
| 821 | syscall_table[SYS_rfsys] = "rfsys"; |
| 822 | #endif |
| 823 | #if defined (SYS_rmdir) |
| 824 | syscall_table[SYS_rmdir] = "rmdir"; |
| 825 | #endif |
| 826 | #if defined (SYS_mkdir) |
| 827 | syscall_table[SYS_mkdir] = "mkdir"; |
| 828 | #endif |
| 829 | #if defined (SYS_getdents) |
| 830 | syscall_table[SYS_getdents] = "getdents"; |
| 831 | #endif |
| 832 | #if defined (SYS_sysfs) |
| 833 | syscall_table[SYS_sysfs] = "sysfs"; |
| 834 | #endif |
| 835 | #if defined (SYS_getmsg) |
| 836 | syscall_table[SYS_getmsg] = "getmsg"; |
| 837 | #endif |
| 838 | #if defined (SYS_putmsg) |
| 839 | syscall_table[SYS_putmsg] = "putmsg"; |
| 840 | #endif |
| 841 | #if defined (SYS_poll) |
| 842 | syscall_table[SYS_poll] = "poll"; |
| 843 | #endif |
| 844 | #if defined (SYS_lstat) |
| 845 | syscall_table[SYS_lstat] = "lstat"; |
| 846 | #endif |
| 847 | #if defined (SYS_symlink) |
| 848 | syscall_table[SYS_symlink] = "symlink"; |
| 849 | #endif |
| 850 | #if defined (SYS_readlink) |
| 851 | syscall_table[SYS_readlink] = "readlink"; |
| 852 | #endif |
| 853 | #if defined (SYS_setgroups) |
| 854 | syscall_table[SYS_setgroups] = "setgroups"; |
| 855 | #endif |
| 856 | #if defined (SYS_getgroups) |
| 857 | syscall_table[SYS_getgroups] = "getgroups"; |
| 858 | #endif |
| 859 | #if defined (SYS_fchmod) |
| 860 | syscall_table[SYS_fchmod] = "fchmod"; |
| 861 | #endif |
| 862 | #if defined (SYS_fchown) |
| 863 | syscall_table[SYS_fchown] = "fchown"; |
| 864 | #endif |
| 865 | #if defined (SYS_sigprocmask) |
| 866 | syscall_table[SYS_sigprocmask] = "sigprocmask"; |
| 867 | #endif |
| 868 | #if defined (SYS_sigsuspend) |
| 869 | syscall_table[SYS_sigsuspend] = "sigsuspend"; |
| 870 | #endif |
| 871 | #if defined (SYS_sigaltstack) |
| 872 | syscall_table[SYS_sigaltstack] = "sigaltstack"; |
| 873 | #endif |
| 874 | #if defined (SYS_sigaction) |
| 875 | syscall_table[SYS_sigaction] = "sigaction"; |
| 876 | #endif |
| 877 | #if defined (SYS_sigpending) |
| 878 | syscall_table[SYS_sigpending] = "sigpending"; |
| 879 | #endif |
| 880 | #if defined (SYS_context) |
| 881 | syscall_table[SYS_context] = "context"; |
| 882 | #endif |
| 883 | #if defined (SYS_evsys) |
| 884 | syscall_table[SYS_evsys] = "evsys"; |
| 885 | #endif |
| 886 | #if defined (SYS_evtrapret) |
| 887 | syscall_table[SYS_evtrapret] = "evtrapret"; |
| 888 | #endif |
| 889 | #if defined (SYS_statvfs) |
| 890 | syscall_table[SYS_statvfs] = "statvfs"; |
| 891 | #endif |
| 892 | #if defined (SYS_fstatvfs) |
| 893 | syscall_table[SYS_fstatvfs] = "fstatvfs"; |
| 894 | #endif |
| 895 | #if defined (SYS_nfssys) |
| 896 | syscall_table[SYS_nfssys] = "nfssys"; |
| 897 | #endif |
| 898 | #if defined (SYS_waitsys) |
| 899 | syscall_table[SYS_waitsys] = "waitsys"; |
| 900 | #endif |
| 901 | #if defined (SYS_sigsendsys) |
| 902 | syscall_table[SYS_sigsendsys] = "sigsendsys"; |
| 903 | #endif |
| 904 | #if defined (SYS_hrtsys) |
| 905 | syscall_table[SYS_hrtsys] = "hrtsys"; |
| 906 | #endif |
| 907 | #if defined (SYS_acancel) |
| 908 | syscall_table[SYS_acancel] = "acancel"; |
| 909 | #endif |
| 910 | #if defined (SYS_async) |
| 911 | syscall_table[SYS_async] = "async"; |
| 912 | #endif |
| 913 | #if defined (SYS_priocntlsys) |
| 914 | syscall_table[SYS_priocntlsys] = "priocntlsys"; |
| 915 | #endif |
| 916 | #if defined (SYS_pathconf) |
| 917 | syscall_table[SYS_pathconf] = "pathconf"; |
| 918 | #endif |
| 919 | #if defined (SYS_mincore) |
| 920 | syscall_table[SYS_mincore] = "mincore"; |
| 921 | #endif |
| 922 | #if defined (SYS_mmap) |
| 923 | syscall_table[SYS_mmap] = "mmap"; |
| 924 | #endif |
| 925 | #if defined (SYS_mprotect) |
| 926 | syscall_table[SYS_mprotect] = "mprotect"; |
| 927 | #endif |
| 928 | #if defined (SYS_munmap) |
| 929 | syscall_table[SYS_munmap] = "munmap"; |
| 930 | #endif |
| 931 | #if defined (SYS_fpathconf) |
| 932 | syscall_table[SYS_fpathconf] = "fpathconf"; |
| 933 | #endif |
| 934 | #if defined (SYS_vfork) |
| 935 | syscall_table[SYS_vfork] = "vfork"; |
| 936 | #endif |
| 937 | #if defined (SYS_fchdir) |
| 938 | syscall_table[SYS_fchdir] = "fchdir"; |
| 939 | #endif |
| 940 | #if defined (SYS_readv) |
| 941 | syscall_table[SYS_readv] = "readv"; |
| 942 | #endif |
| 943 | #if defined (SYS_writev) |
| 944 | syscall_table[SYS_writev] = "writev"; |
| 945 | #endif |
| 946 | #if defined (SYS_xstat) |
| 947 | syscall_table[SYS_xstat] = "xstat"; |
| 948 | #endif |
| 949 | #if defined (SYS_lxstat) |
| 950 | syscall_table[SYS_lxstat] = "lxstat"; |
| 951 | #endif |
| 952 | #if defined (SYS_fxstat) |
| 953 | syscall_table[SYS_fxstat] = "fxstat"; |
| 954 | #endif |
| 955 | #if defined (SYS_xmknod) |
| 956 | syscall_table[SYS_xmknod] = "xmknod"; |
| 957 | #endif |
| 958 | #if defined (SYS_clocal) |
| 959 | syscall_table[SYS_clocal] = "clocal"; |
| 960 | #endif |
| 961 | #if defined (SYS_setrlimit) |
| 962 | syscall_table[SYS_setrlimit] = "setrlimit"; |
| 963 | #endif |
| 964 | #if defined (SYS_getrlimit) |
| 965 | syscall_table[SYS_getrlimit] = "getrlimit"; |
| 966 | #endif |
| 967 | #if defined (SYS_lchown) |
| 968 | syscall_table[SYS_lchown] = "lchown"; |
| 969 | #endif |
| 970 | #if defined (SYS_memcntl) |
| 971 | syscall_table[SYS_memcntl] = "memcntl"; |
| 972 | #endif |
| 973 | #if defined (SYS_getpmsg) |
| 974 | syscall_table[SYS_getpmsg] = "getpmsg"; |
| 975 | #endif |
| 976 | #if defined (SYS_putpmsg) |
| 977 | syscall_table[SYS_putpmsg] = "putpmsg"; |
| 978 | #endif |
| 979 | #if defined (SYS_rename) |
| 980 | syscall_table[SYS_rename] = "rename"; |
| 981 | #endif |
| 982 | #if defined (SYS_uname) |
| 983 | syscall_table[SYS_uname] = "uname"; |
| 984 | #endif |
| 985 | #if defined (SYS_setegid) |
| 986 | syscall_table[SYS_setegid] = "setegid"; |
| 987 | #endif |
| 988 | #if defined (SYS_sysconfig) |
| 989 | syscall_table[SYS_sysconfig] = "sysconfig"; |
| 990 | #endif |
| 991 | #if defined (SYS_adjtime) |
| 992 | syscall_table[SYS_adjtime] = "adjtime"; |
| 993 | #endif |
| 994 | #if defined (SYS_systeminfo) |
| 995 | syscall_table[SYS_systeminfo] = "systeminfo"; |
| 996 | #endif |
| 997 | #if defined (SYS_seteuid) |
| 998 | syscall_table[SYS_seteuid] = "seteuid"; |
| 999 | #endif |
| 1000 | } |
| 1001 | |
| 1002 | /* |
| 1003 | |
| 1004 | GLOBAL FUNCTION |
| 1005 | |
| 1006 | ptrace -- override library version to force errors for /proc version |
| 1007 | |
| 1008 | SYNOPSIS |
| 1009 | |
| 1010 | int ptrace (int request, int pid, PTRACE_ARG3_TYPE arg3, int arg4) |
| 1011 | |
| 1012 | DESCRIPTION |
| 1013 | |
| 1014 | When gdb is configured to use /proc, it should not be calling |
| 1015 | or otherwise attempting to use ptrace. In order to catch errors |
| 1016 | where use of /proc is configured, but some routine is still calling |
| 1017 | ptrace, we provide a local version of a function with that name |
| 1018 | that does nothing but issue an error message. |
| 1019 | */ |
| 1020 | |
| 1021 | int |
| 1022 | ptrace (request, pid, arg3, arg4) |
| 1023 | int request; |
| 1024 | int pid; |
| 1025 | PTRACE_ARG3_TYPE arg3; |
| 1026 | int arg4; |
| 1027 | { |
| 1028 | error ("internal error - there is a call to ptrace() somewhere"); |
| 1029 | /*NOTREACHED*/ |
| 1030 | } |
| 1031 | |
| 1032 | /* |
| 1033 | |
| 1034 | GLOBAL FUNCTION |
| 1035 | |
| 1036 | kill_inferior_fast -- kill inferior while gdb is exiting |
| 1037 | |
| 1038 | SYNOPSIS |
| 1039 | |
| 1040 | void kill_inferior_fast (void) |
| 1041 | |
| 1042 | DESCRIPTION |
| 1043 | |
| 1044 | This is used when GDB is exiting. It gives less chance of error. |
| 1045 | |
| 1046 | NOTES |
| 1047 | |
| 1048 | Don't attempt to kill attached inferiors since we may be called |
| 1049 | when gdb is in the process of aborting, and killing the attached |
| 1050 | inferior may be very anti-social. This is particularly true if we |
| 1051 | were attached just so we could use the /proc facilities to get |
| 1052 | detailed information about it's status. |
| 1053 | |
| 1054 | */ |
| 1055 | |
| 1056 | void |
| 1057 | kill_inferior_fast () |
| 1058 | { |
| 1059 | if (inferior_pid != 0 && !attach_flag) |
| 1060 | { |
| 1061 | unconditionally_kill_inferior (); |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | /* |
| 1066 | |
| 1067 | GLOBAL FUNCTION |
| 1068 | |
| 1069 | kill_inferior - kill any currently inferior |
| 1070 | |
| 1071 | SYNOPSIS |
| 1072 | |
| 1073 | void kill_inferior (void) |
| 1074 | |
| 1075 | DESCRIPTION |
| 1076 | |
| 1077 | Kill any current inferior. |
| 1078 | |
| 1079 | NOTES |
| 1080 | |
| 1081 | Kills even attached inferiors. Presumably the user has already |
| 1082 | been prompted that the inferior is an attached one rather than |
| 1083 | one started by gdb. (FIXME?) |
| 1084 | |
| 1085 | */ |
| 1086 | |
| 1087 | void |
| 1088 | kill_inferior () |
| 1089 | { |
| 1090 | if (inferior_pid != 0) |
| 1091 | { |
| 1092 | unconditionally_kill_inferior (); |
| 1093 | target_mourn_inferior (); |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | /* |
| 1098 | |
| 1099 | LOCAL FUNCTION |
| 1100 | |
| 1101 | unconditionally_kill_inferior - terminate the inferior |
| 1102 | |
| 1103 | SYNOPSIS |
| 1104 | |
| 1105 | static void unconditionally_kill_inferior (void) |
| 1106 | |
| 1107 | DESCRIPTION |
| 1108 | |
| 1109 | Kill the current inferior. Should not be called until it |
| 1110 | is at least tested that there is an inferior. |
| 1111 | |
| 1112 | NOTE |
| 1113 | |
| 1114 | A possibly useful enhancement would be to first try sending |
| 1115 | the inferior a terminate signal, politely asking it to commit |
| 1116 | suicide, before we murder it. |
| 1117 | |
| 1118 | */ |
| 1119 | |
| 1120 | static void |
| 1121 | unconditionally_kill_inferior () |
| 1122 | { |
| 1123 | int signo; |
| 1124 | |
| 1125 | signo = SIGKILL; |
| 1126 | (void) ioctl (pi.fd, PIOCKILL, &signo); |
| 1127 | close_proc_file (&pi); |
| 1128 | wait ((int *) 0); |
| 1129 | } |
| 1130 | |
| 1131 | /* |
| 1132 | |
| 1133 | GLOBAL FUNCTION |
| 1134 | |
| 1135 | child_xfer_memory -- copy data to or from inferior memory space |
| 1136 | |
| 1137 | SYNOPSIS |
| 1138 | |
| 1139 | int child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, |
| 1140 | int dowrite, struct target_ops target) |
| 1141 | |
| 1142 | DESCRIPTION |
| 1143 | |
| 1144 | Copy LEN bytes to/from inferior's memory starting at MEMADDR |
| 1145 | from/to debugger memory starting at MYADDR. Copy from inferior |
| 1146 | if DOWRITE is zero or to inferior if DOWRITE is nonzero. |
| 1147 | |
| 1148 | Returns the length copied, which is either the LEN argument or |
| 1149 | zero. This xfer function does not do partial moves, since child_ops |
| 1150 | doesn't allow memory operations to cross below us in the target stack |
| 1151 | anyway. |
| 1152 | |
| 1153 | NOTES |
| 1154 | |
| 1155 | The /proc interface makes this an almost trivial task. |
| 1156 | */ |
| 1157 | |
| 1158 | |
| 1159 | int |
| 1160 | child_xfer_memory (memaddr, myaddr, len, dowrite, target) |
| 1161 | CORE_ADDR memaddr; |
| 1162 | char *myaddr; |
| 1163 | int len; |
| 1164 | int dowrite; |
| 1165 | struct target_ops *target; /* ignored */ |
| 1166 | { |
| 1167 | int nbytes = 0; |
| 1168 | |
| 1169 | if (lseek (pi.fd, (off_t) memaddr, 0) == (off_t) memaddr) |
| 1170 | { |
| 1171 | if (dowrite) |
| 1172 | { |
| 1173 | nbytes = write (pi.fd, myaddr, len); |
| 1174 | } |
| 1175 | else |
| 1176 | { |
| 1177 | nbytes = read (pi.fd, myaddr, len); |
| 1178 | } |
| 1179 | if (nbytes < 0) |
| 1180 | { |
| 1181 | nbytes = 0; |
| 1182 | } |
| 1183 | } |
| 1184 | return (nbytes); |
| 1185 | } |
| 1186 | |
| 1187 | /* |
| 1188 | |
| 1189 | GLOBAL FUNCTION |
| 1190 | |
| 1191 | store_inferior_registers -- copy register values back to inferior |
| 1192 | |
| 1193 | SYNOPSIS |
| 1194 | |
| 1195 | void store_inferior_registers (int regno) |
| 1196 | |
| 1197 | DESCRIPTION |
| 1198 | |
| 1199 | Store our current register values back into the inferior. If |
| 1200 | REGNO is -1 then store all the register, otherwise store just |
| 1201 | the value specified by REGNO. |
| 1202 | |
| 1203 | NOTES |
| 1204 | |
| 1205 | If we are storing only a single register, we first have to get all |
| 1206 | the current values from the process, overwrite the desired register |
| 1207 | in the gregset with the one we want from gdb's registers, and then |
| 1208 | send the whole set back to the process. For writing all the |
| 1209 | registers, all we have to do is generate the gregset and send it to |
| 1210 | the process. |
| 1211 | |
| 1212 | Also note that the process has to be stopped on an event of interest |
| 1213 | for this to work, which basically means that it has to have been |
| 1214 | run under the control of one of the other /proc ioctl calls and not |
| 1215 | ptrace. Since we don't use ptrace anyway, we don't worry about this |
| 1216 | fine point, but it is worth noting for future reference. |
| 1217 | |
| 1218 | Gdb is confused about what this function is supposed to return. |
| 1219 | Some versions return a value, others return nothing. Some are |
| 1220 | declared to return a value and actually return nothing. Gdb ignores |
| 1221 | anything returned. (FIXME) |
| 1222 | |
| 1223 | */ |
| 1224 | |
| 1225 | void |
| 1226 | store_inferior_registers (regno) |
| 1227 | int regno; |
| 1228 | { |
| 1229 | if (regno != -1) |
| 1230 | { |
| 1231 | (void) ioctl (pi.fd, PIOCGREG, &pi.gregset); |
| 1232 | } |
| 1233 | fill_gregset (&pi.gregset, regno); |
| 1234 | (void) ioctl (pi.fd, PIOCSREG, &pi.gregset); |
| 1235 | |
| 1236 | #if defined (FP0_REGNUM) |
| 1237 | |
| 1238 | /* Now repeat everything using the floating point register set, if the |
| 1239 | target has floating point hardware. Since we ignore the returned value, |
| 1240 | we'll never know whether it worked or not anyway. */ |
| 1241 | |
| 1242 | if (regno != -1) |
| 1243 | { |
| 1244 | (void) ioctl (pi.fd, PIOCGFPREG, &pi.fpregset); |
| 1245 | } |
| 1246 | fill_fpregset (&pi.fpregset, regno); |
| 1247 | (void) ioctl (pi.fd, PIOCSFPREG, &pi.fpregset); |
| 1248 | |
| 1249 | #endif /* FP0_REGNUM */ |
| 1250 | |
| 1251 | } |
| 1252 | |
| 1253 | /* |
| 1254 | |
| 1255 | GLOBAL FUNCTION |
| 1256 | |
| 1257 | inferior_proc_init - initialize access to a /proc entry |
| 1258 | |
| 1259 | SYNOPSIS |
| 1260 | |
| 1261 | void inferior_proc_init (int pid) |
| 1262 | |
| 1263 | DESCRIPTION |
| 1264 | |
| 1265 | When gdb starts an inferior, this function is called in the parent |
| 1266 | process immediately after the fork. It waits for the child to stop |
| 1267 | on the return from the exec system call (the child itself takes care |
| 1268 | of ensuring that this is set up), then sets up the set of signals |
| 1269 | and faults that are to be traced. |
| 1270 | |
| 1271 | NOTES |
| 1272 | |
| 1273 | If proc_init_failed ever gets called, control returns to the command |
| 1274 | processing loop via the standard error handling code. |
| 1275 | |
| 1276 | */ |
| 1277 | |
| 1278 | void |
| 1279 | inferior_proc_init (pid) |
| 1280 | int pid; |
| 1281 | { |
| 1282 | if (!open_proc_file (pid, &pi)) |
| 1283 | { |
| 1284 | proc_init_failed ("can't open process file"); |
| 1285 | } |
| 1286 | else |
| 1287 | { |
| 1288 | (void) memset ((char *) &pi.prrun, 0, sizeof (pi.prrun)); |
| 1289 | prfillset (&pi.prrun.pr_trace); |
| 1290 | proc_signal_handling_change (); |
| 1291 | prfillset (&pi.prrun.pr_fault); |
| 1292 | prdelset (&pi.prrun.pr_fault, FLTPAGE); |
| 1293 | if (ioctl (pi.fd, PIOCWSTOP, &pi.prstatus) < 0) |
| 1294 | { |
| 1295 | proc_init_failed ("PIOCWSTOP failed"); |
| 1296 | } |
| 1297 | else if (ioctl (pi.fd, PIOCSFAULT, &pi.prrun.pr_fault) < 0) |
| 1298 | { |
| 1299 | proc_init_failed ("PIOCSFAULT failed"); |
| 1300 | } |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | /* |
| 1305 | |
| 1306 | GLOBAL FUNCTION |
| 1307 | |
| 1308 | proc_signal_handling_change |
| 1309 | |
| 1310 | SYNOPSIS |
| 1311 | |
| 1312 | void proc_signal_handling_change (void); |
| 1313 | |
| 1314 | DESCRIPTION |
| 1315 | |
| 1316 | When the user changes the state of gdb's signal handling via the |
| 1317 | "handle" command, this function gets called to see if any change |
| 1318 | in the /proc interface is required. It is also called internally |
| 1319 | by other /proc interface functions to initialize the state of |
| 1320 | the traced signal set. |
| 1321 | |
| 1322 | One thing it does is that signals for which the state is "nostop", |
| 1323 | "noprint", and "pass", have their trace bits reset in the pr_trace |
| 1324 | field, so that they are no longer traced. This allows them to be |
| 1325 | delivered directly to the inferior without the debugger ever being |
| 1326 | involved. |
| 1327 | */ |
| 1328 | |
| 1329 | void |
| 1330 | proc_signal_handling_change () |
| 1331 | { |
| 1332 | int signo; |
| 1333 | |
| 1334 | if (pi.valid) |
| 1335 | { |
| 1336 | for (signo = 0; signo < NSIG; signo++) |
| 1337 | { |
| 1338 | if (signal_stop_state (signo) == 0 && |
| 1339 | signal_print_state (signo) == 0 && |
| 1340 | signal_pass_state (signo) == 1) |
| 1341 | { |
| 1342 | prdelset (&pi.prrun.pr_trace, signo); |
| 1343 | } |
| 1344 | else |
| 1345 | { |
| 1346 | praddset (&pi.prrun.pr_trace, signo); |
| 1347 | } |
| 1348 | } |
| 1349 | if (ioctl (pi.fd, PIOCSTRACE, &pi.prrun.pr_trace)) |
| 1350 | { |
| 1351 | print_sys_errmsg ("PIOCSTRACE failed", errno); |
| 1352 | } |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | /* |
| 1357 | |
| 1358 | GLOBAL FUNCTION |
| 1359 | |
| 1360 | proc_set_exec_trap -- arrange for exec'd child to halt at startup |
| 1361 | |
| 1362 | SYNOPSIS |
| 1363 | |
| 1364 | void proc_set_exec_trap (void) |
| 1365 | |
| 1366 | DESCRIPTION |
| 1367 | |
| 1368 | This function is called in the child process when starting up |
| 1369 | an inferior, prior to doing the exec of the actual inferior. |
| 1370 | It sets the child process's exitset to make exit from the exec |
| 1371 | system call an event of interest to stop on, and then simply |
| 1372 | returns. The child does the exec, the system call returns, and |
| 1373 | the child stops at the first instruction, ready for the gdb |
| 1374 | parent process to take control of it. |
| 1375 | |
| 1376 | NOTE |
| 1377 | |
| 1378 | We need to use all local variables since the child may be sharing |
| 1379 | it's data space with the parent, if vfork was used rather than |
| 1380 | fork. |
| 1381 | |
| 1382 | Also note that we want to turn off the inherit-on-fork flag in |
| 1383 | the child process so that any grand-children start with all |
| 1384 | tracing flags cleared. |
| 1385 | */ |
| 1386 | |
| 1387 | void |
| 1388 | proc_set_exec_trap () |
| 1389 | { |
| 1390 | sysset_t exitset; |
| 1391 | auto char procname[32]; |
| 1392 | int fd; |
| 1393 | |
| 1394 | (void) sprintf (procname, PROC_NAME_FMT, getpid ()); |
| 1395 | if ((fd = open (procname, O_RDWR)) < 0) |
| 1396 | { |
| 1397 | perror (procname); |
| 1398 | fflush (stderr); |
| 1399 | _exit (127); |
| 1400 | } |
| 1401 | premptyset (&exitset); |
| 1402 | |
| 1403 | /* GW: Rationale... |
| 1404 | Not all systems with /proc have all the exec* syscalls with the same |
| 1405 | names. On the SGI, for example, there is no SYS_exec, but there |
| 1406 | *is* a SYS_execv. So, we try to account for that. */ |
| 1407 | |
| 1408 | #ifdef SYS_exec |
| 1409 | praddset (&exitset, SYS_exec); |
| 1410 | #endif |
| 1411 | #ifdef SYS_execve |
| 1412 | praddset (&exitset, SYS_execve); |
| 1413 | #endif |
| 1414 | #ifdef SYS_execv |
| 1415 | praddset(&exitset, SYS_execv); |
| 1416 | #endif |
| 1417 | |
| 1418 | if (ioctl (fd, PIOCSEXIT, &exitset) < 0) |
| 1419 | { |
| 1420 | perror (procname); |
| 1421 | fflush (stderr); |
| 1422 | _exit (127); |
| 1423 | } |
| 1424 | |
| 1425 | /* Turn off inherit-on-fork flag so that all grand-children of gdb |
| 1426 | start with tracing flags cleared. */ |
| 1427 | |
| 1428 | #if defined (PIOCRESET) /* New method */ |
| 1429 | { |
| 1430 | long pr_flags; |
| 1431 | pr_flags = PR_FORK; |
| 1432 | (void) ioctl (fd, PIOCRESET, &pr_flags); |
| 1433 | } |
| 1434 | #else |
| 1435 | #if defined (PIOCRFORK) /* Original method */ |
| 1436 | (void) ioctl (fd, PIOCRFORK, NULL); |
| 1437 | #endif |
| 1438 | #endif |
| 1439 | } |
| 1440 | |
| 1441 | /* |
| 1442 | |
| 1443 | GLOBAL FUNCTION |
| 1444 | |
| 1445 | proc_iterate_over_mappings -- call function for every mapped space |
| 1446 | |
| 1447 | SYNOPSIS |
| 1448 | |
| 1449 | int proc_iterate_over_mappings (int (*func)()) |
| 1450 | |
| 1451 | DESCRIPTION |
| 1452 | |
| 1453 | Given a pointer to a function, call that function for every |
| 1454 | mapped address space, passing it an open file descriptor for |
| 1455 | the file corresponding to that mapped address space (if any) |
| 1456 | and the base address of the mapped space. Quit when we hit |
| 1457 | the end of the mappings or the function returns nonzero. |
| 1458 | */ |
| 1459 | |
| 1460 | int |
| 1461 | proc_iterate_over_mappings (func) |
| 1462 | int (*func) PARAMS ((int, CORE_ADDR)); |
| 1463 | { |
| 1464 | int nmap; |
| 1465 | int fd; |
| 1466 | int funcstat = 0; |
| 1467 | struct prmap *prmaps; |
| 1468 | struct prmap *prmap; |
| 1469 | CORE_ADDR baseaddr = 0; |
| 1470 | |
| 1471 | if (pi.valid && (ioctl (pi.fd, PIOCNMAP, &nmap) == 0)) |
| 1472 | { |
| 1473 | prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps)); |
| 1474 | if (ioctl (pi.fd, PIOCMAP, prmaps) == 0) |
| 1475 | { |
| 1476 | for (prmap = prmaps; prmap -> pr_size && funcstat == 0; ++prmap) |
| 1477 | { |
| 1478 | fd = proc_address_to_fd ((CORE_ADDR) prmap -> pr_vaddr, 0); |
| 1479 | funcstat = (*func) (fd, (CORE_ADDR) prmap -> pr_vaddr); |
| 1480 | close (fd); |
| 1481 | } |
| 1482 | } |
| 1483 | } |
| 1484 | return (funcstat); |
| 1485 | } |
| 1486 | |
| 1487 | /* |
| 1488 | |
| 1489 | GLOBAL FUNCTION |
| 1490 | |
| 1491 | proc_base_address -- find base address for segment containing address |
| 1492 | |
| 1493 | SYNOPSIS |
| 1494 | |
| 1495 | CORE_ADDR proc_base_address (CORE_ADDR addr) |
| 1496 | |
| 1497 | DESCRIPTION |
| 1498 | |
| 1499 | Given an address of a location in the inferior, find and return |
| 1500 | the base address of the mapped segment containing that address. |
| 1501 | |
| 1502 | This is used for example, by the shared library support code, |
| 1503 | where we have the pc value for some location in the shared library |
| 1504 | where we are stopped, and need to know the base address of the |
| 1505 | segment containing that address. |
| 1506 | */ |
| 1507 | |
| 1508 | |
| 1509 | #if 0 /* Currently unused */ |
| 1510 | |
| 1511 | CORE_ADDR |
| 1512 | proc_base_address (addr) |
| 1513 | CORE_ADDR addr; |
| 1514 | { |
| 1515 | int nmap; |
| 1516 | struct prmap *prmaps; |
| 1517 | struct prmap *prmap; |
| 1518 | CORE_ADDR baseaddr = 0; |
| 1519 | |
| 1520 | if (pi.valid && (ioctl (pi.fd, PIOCNMAP, &nmap) == 0)) |
| 1521 | { |
| 1522 | prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps)); |
| 1523 | if (ioctl (pi.fd, PIOCMAP, prmaps) == 0) |
| 1524 | { |
| 1525 | for (prmap = prmaps; prmap -> pr_size; ++prmap) |
| 1526 | { |
| 1527 | if ((prmap -> pr_vaddr <= (caddr_t) addr) && |
| 1528 | (prmap -> pr_vaddr + prmap -> pr_size > (caddr_t) addr)) |
| 1529 | { |
| 1530 | baseaddr = (CORE_ADDR) prmap -> pr_vaddr; |
| 1531 | break; |
| 1532 | } |
| 1533 | } |
| 1534 | } |
| 1535 | } |
| 1536 | return (baseaddr); |
| 1537 | } |
| 1538 | |
| 1539 | #endif /* 0 */ |
| 1540 | |
| 1541 | /* |
| 1542 | |
| 1543 | LOCAL FUNCTION |
| 1544 | |
| 1545 | proc_address_to_fd -- return open fd for file mapped to address |
| 1546 | |
| 1547 | SYNOPSIS |
| 1548 | |
| 1549 | int proc_address_to_fd (CORE_ADDR addr, complain) |
| 1550 | |
| 1551 | DESCRIPTION |
| 1552 | |
| 1553 | Given an address in the current inferior's address space, use the |
| 1554 | /proc interface to find an open file descriptor for the file that |
| 1555 | this address was mapped in from. Return -1 if there is no current |
| 1556 | inferior. Print a warning message if there is an inferior but |
| 1557 | the address corresponds to no file (IE a bogus address). |
| 1558 | |
| 1559 | */ |
| 1560 | |
| 1561 | static int |
| 1562 | proc_address_to_fd (addr, complain) |
| 1563 | CORE_ADDR addr; |
| 1564 | int complain; |
| 1565 | { |
| 1566 | int fd = -1; |
| 1567 | |
| 1568 | if (pi.valid) |
| 1569 | { |
| 1570 | if ((fd = ioctl (pi.fd, PIOCOPENM, (caddr_t *) &addr)) < 0) |
| 1571 | { |
| 1572 | if (complain) |
| 1573 | { |
| 1574 | print_sys_errmsg (pi.pathname, errno); |
| 1575 | warning ("can't find mapped file for address 0x%x", addr); |
| 1576 | } |
| 1577 | } |
| 1578 | } |
| 1579 | return (fd); |
| 1580 | } |
| 1581 | |
| 1582 | |
| 1583 | #ifdef ATTACH_DETACH |
| 1584 | |
| 1585 | /* |
| 1586 | |
| 1587 | GLOBAL FUNCTION |
| 1588 | |
| 1589 | attach -- attach to an already existing process |
| 1590 | |
| 1591 | SYNOPSIS |
| 1592 | |
| 1593 | int attach (int pid) |
| 1594 | |
| 1595 | DESCRIPTION |
| 1596 | |
| 1597 | Attach to an already existing process with the specified process |
| 1598 | id. If the process is not already stopped, query whether to |
| 1599 | stop it or not. |
| 1600 | |
| 1601 | NOTES |
| 1602 | |
| 1603 | The option of stopping at attach time is specific to the /proc |
| 1604 | versions of gdb. Versions using ptrace force the attachee |
| 1605 | to stop. |
| 1606 | |
| 1607 | */ |
| 1608 | |
| 1609 | int |
| 1610 | attach (pid) |
| 1611 | int pid; |
| 1612 | { |
| 1613 | if (!open_proc_file (pid, &pi)) |
| 1614 | { |
| 1615 | perror_with_name (pi.pathname); |
| 1616 | /* NOTREACHED */ |
| 1617 | } |
| 1618 | |
| 1619 | /* Get current status of process and if it is not already stopped, |
| 1620 | then stop it. Remember whether or not it was stopped when we first |
| 1621 | examined it. */ |
| 1622 | |
| 1623 | if (ioctl (pi.fd, PIOCSTATUS, &pi.prstatus) < 0) |
| 1624 | { |
| 1625 | print_sys_errmsg (pi.pathname, errno); |
| 1626 | close_proc_file (&pi); |
| 1627 | error ("PIOCSTATUS failed"); |
| 1628 | } |
| 1629 | if (pi.prstatus.pr_flags & (PR_STOPPED | PR_ISTOP)) |
| 1630 | { |
| 1631 | pi.was_stopped = 1; |
| 1632 | } |
| 1633 | else |
| 1634 | { |
| 1635 | pi.was_stopped = 0; |
| 1636 | if (query ("Process is currently running, stop it? ")) |
| 1637 | { |
| 1638 | if (ioctl (pi.fd, PIOCSTOP, &pi.prstatus) < 0) |
| 1639 | { |
| 1640 | print_sys_errmsg (pi.pathname, errno); |
| 1641 | close_proc_file (&pi); |
| 1642 | error ("PIOCSTOP failed"); |
| 1643 | } |
| 1644 | pi.nopass_next_sigstop = 1; |
| 1645 | } |
| 1646 | else |
| 1647 | { |
| 1648 | printf ("Ok, gdb will wait for process %u to stop.\n", pid); |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | /* Remember some things about the inferior that we will, or might, change |
| 1653 | so that we can restore them when we detach. */ |
| 1654 | |
| 1655 | (void) ioctl (pi.fd, PIOCGTRACE, &pi.saved_trace); |
| 1656 | (void) ioctl (pi.fd, PIOCGHOLD, &pi.saved_sighold); |
| 1657 | (void) ioctl (pi.fd, PIOCGFAULT, &pi.saved_fltset); |
| 1658 | (void) ioctl (pi.fd, PIOCGENTRY, &pi.saved_entryset); |
| 1659 | (void) ioctl (pi.fd, PIOCGEXIT, &pi.saved_exitset); |
| 1660 | |
| 1661 | /* Set up trace and fault sets, as gdb expects them. */ |
| 1662 | |
| 1663 | (void) memset (&pi.prrun, 0, sizeof (pi.prrun)); |
| 1664 | prfillset (&pi.prrun.pr_trace); |
| 1665 | proc_signal_handling_change (); |
| 1666 | prfillset (&pi.prrun.pr_fault); |
| 1667 | prdelset (&pi.prrun.pr_fault, FLTPAGE); |
| 1668 | if (ioctl (pi.fd, PIOCSFAULT, &pi.prrun.pr_fault)) |
| 1669 | { |
| 1670 | print_sys_errmsg ("PIOCSFAULT failed", errno); |
| 1671 | } |
| 1672 | if (ioctl (pi.fd, PIOCSTRACE, &pi.prrun.pr_trace)) |
| 1673 | { |
| 1674 | print_sys_errmsg ("PIOCSTRACE failed", errno); |
| 1675 | } |
| 1676 | attach_flag = 1; |
| 1677 | return (pid); |
| 1678 | } |
| 1679 | |
| 1680 | /* |
| 1681 | |
| 1682 | GLOBAL FUNCTION |
| 1683 | |
| 1684 | detach -- detach from an attached-to process |
| 1685 | |
| 1686 | SYNOPSIS |
| 1687 | |
| 1688 | void detach (int signal) |
| 1689 | |
| 1690 | DESCRIPTION |
| 1691 | |
| 1692 | Detach from the current attachee. |
| 1693 | |
| 1694 | If signal is non-zero, the attachee is started running again and sent |
| 1695 | the specified signal. |
| 1696 | |
| 1697 | If signal is zero and the attachee was not already stopped when we |
| 1698 | attached to it, then we make it runnable again when we detach. |
| 1699 | |
| 1700 | Otherwise, we query whether or not to make the attachee runnable |
| 1701 | again, since we may simply want to leave it in the state it was in |
| 1702 | when we attached. |
| 1703 | |
| 1704 | We report any problems, but do not consider them errors, since we |
| 1705 | MUST detach even if some things don't seem to go right. This may not |
| 1706 | be the ideal situation. (FIXME). |
| 1707 | */ |
| 1708 | |
| 1709 | void |
| 1710 | detach (signal) |
| 1711 | int signal; |
| 1712 | { |
| 1713 | if (signal) |
| 1714 | { |
| 1715 | set_proc_siginfo (&pi, signal); |
| 1716 | } |
| 1717 | if (ioctl (pi.fd, PIOCSEXIT, &pi.saved_exitset) < 0) |
| 1718 | { |
| 1719 | print_sys_errmsg (pi.pathname, errno); |
| 1720 | printf ("PIOCSEXIT failed.\n"); |
| 1721 | } |
| 1722 | if (ioctl (pi.fd, PIOCSENTRY, &pi.saved_entryset) < 0) |
| 1723 | { |
| 1724 | print_sys_errmsg (pi.pathname, errno); |
| 1725 | printf ("PIOCSENTRY failed.\n"); |
| 1726 | } |
| 1727 | if (ioctl (pi.fd, PIOCSTRACE, &pi.saved_trace) < 0) |
| 1728 | { |
| 1729 | print_sys_errmsg (pi.pathname, errno); |
| 1730 | printf ("PIOCSTRACE failed.\n"); |
| 1731 | } |
| 1732 | if (ioctl (pi.fd, PIOCSHOLD, &pi.saved_sighold) < 0) |
| 1733 | { |
| 1734 | print_sys_errmsg (pi.pathname, errno); |
| 1735 | printf ("PIOSCHOLD failed.\n"); |
| 1736 | } |
| 1737 | if (ioctl (pi.fd, PIOCSFAULT, &pi.saved_fltset) < 0) |
| 1738 | { |
| 1739 | print_sys_errmsg (pi.pathname, errno); |
| 1740 | printf ("PIOCSFAULT failed.\n"); |
| 1741 | } |
| 1742 | if (ioctl (pi.fd, PIOCSTATUS, &pi.prstatus) < 0) |
| 1743 | { |
| 1744 | print_sys_errmsg (pi.pathname, errno); |
| 1745 | printf ("PIOCSTATUS failed.\n"); |
| 1746 | } |
| 1747 | else |
| 1748 | { |
| 1749 | if (signal || (pi.prstatus.pr_flags & (PR_STOPPED | PR_ISTOP))) |
| 1750 | { |
| 1751 | if (signal || !pi.was_stopped || |
| 1752 | query ("Was stopped when attached, make it runnable again? ")) |
| 1753 | { |
| 1754 | (void) memset (&pi.prrun, 0, sizeof (pi.prrun)); |
| 1755 | pi.prrun.pr_flags = PRCFAULT; |
| 1756 | if (ioctl (pi.fd, PIOCRUN, &pi.prrun)) |
| 1757 | { |
| 1758 | print_sys_errmsg (pi.pathname, errno); |
| 1759 | printf ("PIOCRUN failed.\n"); |
| 1760 | } |
| 1761 | } |
| 1762 | } |
| 1763 | } |
| 1764 | close_proc_file (&pi); |
| 1765 | attach_flag = 0; |
| 1766 | } |
| 1767 | |
| 1768 | #endif /* ATTACH_DETACH */ |
| 1769 | |
| 1770 | /* |
| 1771 | |
| 1772 | GLOBAL FUNCTION |
| 1773 | |
| 1774 | proc_wait -- emulate wait() as much as possible |
| 1775 | |
| 1776 | SYNOPSIS |
| 1777 | |
| 1778 | int proc_wait (int *statloc) |
| 1779 | |
| 1780 | DESCRIPTION |
| 1781 | |
| 1782 | Try to emulate wait() as much as possible. Not sure why we can't |
| 1783 | just use wait(), but it seems to have problems when applied to a |
| 1784 | process being controlled with the /proc interface. |
| 1785 | |
| 1786 | NOTES |
| 1787 | |
| 1788 | We have a race problem here with no obvious solution. We need to let |
| 1789 | the inferior run until it stops on an event of interest, which means |
| 1790 | that we need to use the PIOCWSTOP ioctl. However, we cannot use this |
| 1791 | ioctl if the process is already stopped on something that is not an |
| 1792 | event of interest, or the call will hang indefinitely. Thus we first |
| 1793 | use PIOCSTATUS to see if the process is not stopped. If not, then we |
| 1794 | use PIOCWSTOP. But during the window between the two, if the process |
| 1795 | stops for any reason that is not an event of interest (such as a job |
| 1796 | control signal) then gdb will hang. One possible workaround is to set |
| 1797 | an alarm to wake up every minute of so and check to see if the process |
| 1798 | is still running, and if so, then reissue the PIOCWSTOP. But this is |
| 1799 | a real kludge, so has not been implemented. FIXME: investigate |
| 1800 | alternatives. |
| 1801 | |
| 1802 | FIXME: Investigate why wait() seems to have problems with programs |
| 1803 | being control by /proc routines. |
| 1804 | |
| 1805 | */ |
| 1806 | |
| 1807 | int |
| 1808 | proc_wait (statloc) |
| 1809 | int *statloc; |
| 1810 | { |
| 1811 | short what; |
| 1812 | short why; |
| 1813 | int statval = 0; |
| 1814 | int checkerr = 0; |
| 1815 | int rtnval = -1; |
| 1816 | |
| 1817 | if (ioctl (pi.fd, PIOCSTATUS, &pi.prstatus) < 0) |
| 1818 | { |
| 1819 | checkerr++; |
| 1820 | } |
| 1821 | else if (!(pi.prstatus.pr_flags & (PR_STOPPED | PR_ISTOP))) |
| 1822 | { |
| 1823 | if (ioctl (pi.fd, PIOCWSTOP, &pi.prstatus) < 0) |
| 1824 | { |
| 1825 | checkerr++; |
| 1826 | } |
| 1827 | } |
| 1828 | if (checkerr) |
| 1829 | { |
| 1830 | if (errno == ENOENT) |
| 1831 | { |
| 1832 | rtnval = wait (&statval); |
| 1833 | if (rtnval != inferior_pid) |
| 1834 | { |
| 1835 | error ("PIOCWSTOP, wait failed, returned %d", rtnval); |
| 1836 | /* NOTREACHED */ |
| 1837 | } |
| 1838 | } |
| 1839 | else |
| 1840 | { |
| 1841 | print_sys_errmsg (pi.pathname, errno); |
| 1842 | error ("PIOCSTATUS or PIOCWSTOP failed."); |
| 1843 | /* NOTREACHED */ |
| 1844 | } |
| 1845 | } |
| 1846 | else if (pi.prstatus.pr_flags & (PR_STOPPED | PR_ISTOP)) |
| 1847 | { |
| 1848 | rtnval = pi.prstatus.pr_pid; |
| 1849 | why = pi.prstatus.pr_why; |
| 1850 | what = pi.prstatus.pr_what; |
| 1851 | if (why == PR_SIGNALLED) |
| 1852 | { |
| 1853 | statval = (what << 8) | 0177; |
| 1854 | } |
| 1855 | else if ((why == PR_SYSEXIT) |
| 1856 | && |
| 1857 | ( |
| 1858 | #ifdef SYS_exec |
| 1859 | what == SYS_exec |
| 1860 | #else |
| 1861 | 0 == 0 |
| 1862 | #endif |
| 1863 | #ifdef SYS_execve |
| 1864 | || what == SYS_execve |
| 1865 | #endif |
| 1866 | #ifdef SYS_execv |
| 1867 | || what == SYS_execv |
| 1868 | #endif |
| 1869 | )) |
| 1870 | { |
| 1871 | statval = (SIGTRAP << 8) | 0177; |
| 1872 | } |
| 1873 | else if (why == PR_REQUESTED) |
| 1874 | { |
| 1875 | statval = (SIGSTOP << 8) | 0177; |
| 1876 | } |
| 1877 | else if (why == PR_JOBCONTROL) |
| 1878 | { |
| 1879 | statval = (what << 8) | 0177; |
| 1880 | } |
| 1881 | else if (why == PR_FAULTED) |
| 1882 | { |
| 1883 | switch (what) |
| 1884 | { |
| 1885 | case FLTPRIV: |
| 1886 | case FLTILL: |
| 1887 | statval = (SIGILL << 8) | 0177; |
| 1888 | break; |
| 1889 | case FLTBPT: |
| 1890 | case FLTTRACE: |
| 1891 | statval = (SIGTRAP << 8) | 0177; |
| 1892 | break; |
| 1893 | case FLTSTACK: |
| 1894 | case FLTACCESS: |
| 1895 | case FLTBOUNDS: |
| 1896 | statval = (SIGSEGV << 8) | 0177; |
| 1897 | break; |
| 1898 | case FLTIOVF: |
| 1899 | case FLTIZDIV: |
| 1900 | case FLTFPE: |
| 1901 | statval = (SIGFPE << 8) | 0177; |
| 1902 | break; |
| 1903 | case FLTPAGE: /* Recoverable page fault */ |
| 1904 | default: |
| 1905 | rtnval = -1; |
| 1906 | error ("PIOCWSTOP, unknown why %d, what %d", why, what); |
| 1907 | /* NOTREACHED */ |
| 1908 | } |
| 1909 | } |
| 1910 | else |
| 1911 | { |
| 1912 | rtnval = -1; |
| 1913 | error ("PIOCWSTOP, unknown why %d, what %d", why, what); |
| 1914 | /* NOTREACHED */ |
| 1915 | } |
| 1916 | } |
| 1917 | else |
| 1918 | { |
| 1919 | error ("PIOCWSTOP, stopped for unknown/unhandled reason, flags %#x", |
| 1920 | pi.prstatus.pr_flags); |
| 1921 | /* NOTREACHED */ |
| 1922 | } |
| 1923 | if (statloc) |
| 1924 | { |
| 1925 | *statloc = statval; |
| 1926 | } |
| 1927 | return (rtnval); |
| 1928 | } |
| 1929 | |
| 1930 | /* |
| 1931 | |
| 1932 | LOCAL FUNCTION |
| 1933 | |
| 1934 | set_proc_siginfo - set a process's current signal info |
| 1935 | |
| 1936 | SYNOPSIS |
| 1937 | |
| 1938 | void set_proc_siginfo (struct procinfo *pip, int signo); |
| 1939 | |
| 1940 | DESCRIPTION |
| 1941 | |
| 1942 | Given a pointer to a process info struct in PIP and a signal number |
| 1943 | in SIGNO, set the process's current signal and its associated signal |
| 1944 | information. The signal will be delivered to the process immediately |
| 1945 | after execution is resumed, even if it is being held. In addition, |
| 1946 | this particular delivery will not cause another PR_SIGNALLED stop |
| 1947 | even if the signal is being traced. |
| 1948 | |
| 1949 | If we are not delivering the same signal that the prstatus siginfo |
| 1950 | struct contains information about, then synthesize a siginfo struct |
| 1951 | to match the signal we are doing to deliver, make it of the type |
| 1952 | "generated by a user process", and send this synthesized copy. When |
| 1953 | used to set the inferior's signal state, this will be required if we |
| 1954 | are not currently stopped because of a traced signal, or if we decide |
| 1955 | to continue with a different signal. |
| 1956 | |
| 1957 | Note that when continuing the inferior from a stop due to receipt |
| 1958 | of a traced signal, we either have set PRCSIG to clear the existing |
| 1959 | signal, or we have to call this function to do a PIOCSSIG with either |
| 1960 | the existing siginfo struct from pr_info, or one we have synthesized |
| 1961 | appropriately for the signal we want to deliver. Otherwise if the |
| 1962 | signal is still being traced, the inferior will immediately stop |
| 1963 | again. |
| 1964 | |
| 1965 | See siginfo(5) for more details. |
| 1966 | */ |
| 1967 | |
| 1968 | static void |
| 1969 | set_proc_siginfo (pip, signo) |
| 1970 | struct procinfo *pip; |
| 1971 | int signo; |
| 1972 | { |
| 1973 | struct siginfo newsiginfo; |
| 1974 | struct siginfo *sip; |
| 1975 | |
| 1976 | if (pip -> valid) |
| 1977 | { |
| 1978 | if (signo == pip -> prstatus.pr_info.si_signo) |
| 1979 | { |
| 1980 | sip = &pip -> prstatus.pr_info; |
| 1981 | } |
| 1982 | else |
| 1983 | { |
| 1984 | (void) memset ((char *) &newsiginfo, 0, sizeof (newsiginfo)); |
| 1985 | sip = &newsiginfo; |
| 1986 | sip -> si_signo = signo; |
| 1987 | sip -> si_code = 0; |
| 1988 | sip -> si_errno = 0; |
| 1989 | sip -> si_pid = getpid (); |
| 1990 | sip -> si_uid = getuid (); |
| 1991 | } |
| 1992 | if (ioctl (pip -> fd, PIOCSSIG, sip) < 0) |
| 1993 | { |
| 1994 | print_sys_errmsg (pip -> pathname, errno); |
| 1995 | warning ("PIOCSSIG failed"); |
| 1996 | } |
| 1997 | } |
| 1998 | } |
| 1999 | |
| 2000 | /* |
| 2001 | |
| 2002 | GLOBAL FUNCTION |
| 2003 | |
| 2004 | child_resume -- resume execution of the inferior process |
| 2005 | |
| 2006 | SYNOPSIS |
| 2007 | |
| 2008 | void child_resume (int step, int signo) |
| 2009 | |
| 2010 | DESCRIPTION |
| 2011 | |
| 2012 | Resume execution of the inferior process. If STEP is nozero, then |
| 2013 | just single step it. If SIGNAL is nonzero, restart it with that |
| 2014 | signal activated. |
| 2015 | |
| 2016 | NOTE |
| 2017 | |
| 2018 | It may not be absolutely necessary to specify the PC value for |
| 2019 | restarting, but to be safe we use the value that gdb considers |
| 2020 | to be current. One case where this might be necessary is if the |
| 2021 | user explicitly changes the PC value that gdb considers to be |
| 2022 | current. FIXME: Investigate if this is necessary or not. |
| 2023 | |
| 2024 | When attaching to a child process, if we forced it to stop with |
| 2025 | a PIOCSTOP, then we will have set the nopass_next_sigstop flag. |
| 2026 | Upon resuming the first time after such a stop, we explicitly |
| 2027 | inhibit sending it another SIGSTOP, which would be the normal |
| 2028 | result of default signal handling. One potential drawback to |
| 2029 | this is that we will also ignore any attempt to by the user |
| 2030 | to explicitly continue after the attach with a SIGSTOP. Ultimately |
| 2031 | this problem should be dealt with by making the routines that |
| 2032 | deal with the inferior a little smarter, and possibly even allow |
| 2033 | an inferior to continue running at the same time as gdb. (FIXME?) |
| 2034 | */ |
| 2035 | |
| 2036 | void |
| 2037 | child_resume (step, signo) |
| 2038 | int step; |
| 2039 | int signo; |
| 2040 | { |
| 2041 | errno = 0; |
| 2042 | pi.prrun.pr_flags = PRSTRACE | PRSFAULT | PRCFAULT; |
| 2043 | |
| 2044 | #ifdef PRSVADDR_BROKEN |
| 2045 | /* Can't do this under Solaris running on a Sparc, as there seems to be no |
| 2046 | place to put nPC. In fact, if you use this, nPC seems to be set to some |
| 2047 | random garbage. We have to rely on the fact that PC and nPC have been |
| 2048 | written previously via PIOCSREG during a register flush. */ |
| 2049 | |
| 2050 | pi.prrun.pr_vaddr = (caddr_t) *(int *) ®isters[REGISTER_BYTE (PC_REGNUM)]; |
| 2051 | pi.prrun.pr_flags != PRSVADDR; |
| 2052 | #endif |
| 2053 | |
| 2054 | if (signo && !(signo == SIGSTOP && pi.nopass_next_sigstop)) |
| 2055 | { |
| 2056 | set_proc_siginfo (&pi, signo); |
| 2057 | } |
| 2058 | else |
| 2059 | { |
| 2060 | pi.prrun.pr_flags |= PRCSIG; |
| 2061 | } |
| 2062 | pi.nopass_next_sigstop = 0; |
| 2063 | if (step) |
| 2064 | { |
| 2065 | pi.prrun.pr_flags |= PRSTEP; |
| 2066 | } |
| 2067 | if (ioctl (pi.fd, PIOCRUN, &pi.prrun) != 0) |
| 2068 | { |
| 2069 | perror_with_name (pi.pathname); |
| 2070 | /* NOTREACHED */ |
| 2071 | } |
| 2072 | } |
| 2073 | |
| 2074 | /* |
| 2075 | |
| 2076 | GLOBAL FUNCTION |
| 2077 | |
| 2078 | fetch_inferior_registers -- fetch current registers from inferior |
| 2079 | |
| 2080 | SYNOPSIS |
| 2081 | |
| 2082 | void fetch_inferior_registers (int regno) |
| 2083 | |
| 2084 | DESCRIPTION |
| 2085 | |
| 2086 | Read the current values of the inferior's registers, both the |
| 2087 | general register set and floating point registers (if supported) |
| 2088 | and update gdb's idea of their current values. |
| 2089 | |
| 2090 | */ |
| 2091 | |
| 2092 | void |
| 2093 | fetch_inferior_registers (regno) |
| 2094 | int regno; |
| 2095 | { |
| 2096 | if (ioctl (pi.fd, PIOCGREG, &pi.gregset) != -1) |
| 2097 | { |
| 2098 | supply_gregset (&pi.gregset); |
| 2099 | } |
| 2100 | #if defined (FP0_REGNUM) |
| 2101 | if (ioctl (pi.fd, PIOCGFPREG, &pi.fpregset) != -1) |
| 2102 | { |
| 2103 | supply_fpregset (&pi.fpregset); |
| 2104 | } |
| 2105 | #endif |
| 2106 | } |
| 2107 | |
| 2108 | /* |
| 2109 | |
| 2110 | GLOBAL FUNCTION |
| 2111 | |
| 2112 | fetch_core_registers -- fetch current registers from core file data |
| 2113 | |
| 2114 | SYNOPSIS |
| 2115 | |
| 2116 | void fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, |
| 2117 | int which, unsigned in reg_addr) |
| 2118 | |
| 2119 | DESCRIPTION |
| 2120 | |
| 2121 | Read the values of either the general register set (WHICH equals 0) |
| 2122 | or the floating point register set (WHICH equals 2) from the core |
| 2123 | file data (pointed to by CORE_REG_SECT), and update gdb's idea of |
| 2124 | their current values. The CORE_REG_SIZE parameter is ignored. |
| 2125 | |
| 2126 | NOTES |
| 2127 | |
| 2128 | Use the indicated sizes to validate the gregset and fpregset |
| 2129 | structures. |
| 2130 | */ |
| 2131 | |
| 2132 | void |
| 2133 | fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr) |
| 2134 | char *core_reg_sect; |
| 2135 | unsigned core_reg_size; |
| 2136 | int which; |
| 2137 | unsigned int reg_addr; /* Unused in this version */ |
| 2138 | { |
| 2139 | |
| 2140 | if (which == 0) |
| 2141 | { |
| 2142 | if (core_reg_size != sizeof (pi.gregset)) |
| 2143 | { |
| 2144 | warning ("wrong size gregset struct in core file"); |
| 2145 | } |
| 2146 | else |
| 2147 | { |
| 2148 | (void) memcpy ((char *) &pi.gregset, core_reg_sect, |
| 2149 | sizeof (pi.gregset)); |
| 2150 | supply_gregset (&pi.gregset); |
| 2151 | } |
| 2152 | } |
| 2153 | else if (which == 2) |
| 2154 | { |
| 2155 | if (core_reg_size != sizeof (pi.fpregset)) |
| 2156 | { |
| 2157 | warning ("wrong size fpregset struct in core file"); |
| 2158 | } |
| 2159 | else |
| 2160 | { |
| 2161 | (void) memcpy ((char *) &pi.fpregset, core_reg_sect, |
| 2162 | sizeof (pi.fpregset)); |
| 2163 | #if defined (FP0_REGNUM) |
| 2164 | supply_fpregset (&pi.fpregset); |
| 2165 | #endif |
| 2166 | } |
| 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | /* |
| 2171 | |
| 2172 | LOCAL FUNCTION |
| 2173 | |
| 2174 | proc_init_failed - called whenever /proc access initialization fails |
| 2175 | |
| 2176 | SYNOPSIS |
| 2177 | |
| 2178 | static void proc_init_failed (char *why) |
| 2179 | |
| 2180 | DESCRIPTION |
| 2181 | |
| 2182 | This function is called whenever initialization of access to a /proc |
| 2183 | entry fails. It prints a suitable error message, does some cleanup, |
| 2184 | and then invokes the standard error processing routine which dumps |
| 2185 | us back into the command loop. |
| 2186 | */ |
| 2187 | |
| 2188 | static void |
| 2189 | proc_init_failed (why) |
| 2190 | char *why; |
| 2191 | { |
| 2192 | print_sys_errmsg (pi.pathname, errno); |
| 2193 | (void) kill (pi.pid, SIGKILL); |
| 2194 | close_proc_file (&pi); |
| 2195 | error (why); |
| 2196 | /* NOTREACHED */ |
| 2197 | } |
| 2198 | |
| 2199 | /* |
| 2200 | |
| 2201 | LOCAL FUNCTION |
| 2202 | |
| 2203 | close_proc_file - close any currently open /proc entry |
| 2204 | |
| 2205 | SYNOPSIS |
| 2206 | |
| 2207 | static void close_proc_file (struct procinfo *pip) |
| 2208 | |
| 2209 | DESCRIPTION |
| 2210 | |
| 2211 | Close any currently open /proc entry and mark the process information |
| 2212 | entry as invalid. In order to ensure that we don't try to reuse any |
| 2213 | stale information, the pid, fd, and pathnames are explicitly |
| 2214 | invalidated, which may be overkill. |
| 2215 | |
| 2216 | */ |
| 2217 | |
| 2218 | static void |
| 2219 | close_proc_file (pip) |
| 2220 | struct procinfo *pip; |
| 2221 | { |
| 2222 | pip -> pid = 0; |
| 2223 | if (pip -> valid) |
| 2224 | { |
| 2225 | (void) close (pip -> fd); |
| 2226 | } |
| 2227 | pip -> fd = -1; |
| 2228 | if (pip -> pathname) |
| 2229 | { |
| 2230 | free (pip -> pathname); |
| 2231 | pip -> pathname = NULL; |
| 2232 | } |
| 2233 | pip -> valid = 0; |
| 2234 | } |
| 2235 | |
| 2236 | /* |
| 2237 | |
| 2238 | LOCAL FUNCTION |
| 2239 | |
| 2240 | open_proc_file - open a /proc entry for a given process id |
| 2241 | |
| 2242 | SYNOPSIS |
| 2243 | |
| 2244 | static int open_proc_file (pid, struct procinfo *pip) |
| 2245 | |
| 2246 | DESCRIPTION |
| 2247 | |
| 2248 | Given a process id, close the existing open /proc entry (if any) |
| 2249 | and open one for the new process id. Once it is open, then |
| 2250 | mark the local process information structure as valid, which |
| 2251 | guarantees that the pid, fd, and pathname fields match an open |
| 2252 | /proc entry. Returns zero if the open fails, nonzero otherwise. |
| 2253 | |
| 2254 | Note that the pathname is left intact, even when the open fails, |
| 2255 | so that callers can use it to construct meaningful error messages |
| 2256 | rather than just "file open failed". |
| 2257 | */ |
| 2258 | |
| 2259 | static int |
| 2260 | open_proc_file (pid, pip) |
| 2261 | int pid; |
| 2262 | struct procinfo *pip; |
| 2263 | { |
| 2264 | pip -> valid = 0; |
| 2265 | if (pip -> valid) |
| 2266 | { |
| 2267 | (void) close (pip -> fd); |
| 2268 | } |
| 2269 | if (pip -> pathname == NULL) |
| 2270 | { |
| 2271 | pip -> pathname = xmalloc (32); |
| 2272 | } |
| 2273 | sprintf (pip -> pathname, PROC_NAME_FMT, pid); |
| 2274 | if ((pip -> fd = open (pip -> pathname, O_RDWR)) >= 0) |
| 2275 | { |
| 2276 | pip -> valid = 1; |
| 2277 | pip -> pid = pid; |
| 2278 | } |
| 2279 | return (pip -> valid); |
| 2280 | } |
| 2281 | |
| 2282 | static char * |
| 2283 | mappingflags (flags) |
| 2284 | long flags; |
| 2285 | { |
| 2286 | static char asciiflags[8]; |
| 2287 | |
| 2288 | strcpy (asciiflags, "-------"); |
| 2289 | #if defined (MA_PHYS) |
| 2290 | if (flags & MA_PHYS) asciiflags[0] = 'd'; |
| 2291 | #endif |
| 2292 | if (flags & MA_STACK) asciiflags[1] = 's'; |
| 2293 | if (flags & MA_BREAK) asciiflags[2] = 'b'; |
| 2294 | if (flags & MA_SHARED) asciiflags[3] = 's'; |
| 2295 | if (flags & MA_READ) asciiflags[4] = 'r'; |
| 2296 | if (flags & MA_WRITE) asciiflags[5] = 'w'; |
| 2297 | if (flags & MA_EXEC) asciiflags[6] = 'x'; |
| 2298 | return (asciiflags); |
| 2299 | } |
| 2300 | |
| 2301 | static void |
| 2302 | info_proc_flags (pip, summary) |
| 2303 | struct procinfo *pip; |
| 2304 | int summary; |
| 2305 | { |
| 2306 | struct trans *transp; |
| 2307 | |
| 2308 | printf_filtered ("%-32s", "Process status flags:"); |
| 2309 | if (!summary) |
| 2310 | { |
| 2311 | printf_filtered ("\n\n"); |
| 2312 | } |
| 2313 | for (transp = pr_flag_table; transp -> name != NULL; transp++) |
| 2314 | { |
| 2315 | if (pip -> prstatus.pr_flags & transp -> value) |
| 2316 | { |
| 2317 | if (summary) |
| 2318 | { |
| 2319 | printf_filtered ("%s ", transp -> name); |
| 2320 | } |
| 2321 | else |
| 2322 | { |
| 2323 | printf_filtered ("\t%-16s %s.\n", transp -> name, transp -> desc); |
| 2324 | } |
| 2325 | } |
| 2326 | } |
| 2327 | printf_filtered ("\n"); |
| 2328 | } |
| 2329 | |
| 2330 | static void |
| 2331 | info_proc_stop (pip, summary) |
| 2332 | struct procinfo *pip; |
| 2333 | int summary; |
| 2334 | { |
| 2335 | struct trans *transp; |
| 2336 | int why; |
| 2337 | int what; |
| 2338 | |
| 2339 | why = pip -> prstatus.pr_why; |
| 2340 | what = pip -> prstatus.pr_what; |
| 2341 | |
| 2342 | if (pip -> prstatus.pr_flags & PR_STOPPED) |
| 2343 | { |
| 2344 | printf_filtered ("%-32s", "Reason for stopping:"); |
| 2345 | if (!summary) |
| 2346 | { |
| 2347 | printf_filtered ("\n\n"); |
| 2348 | } |
| 2349 | for (transp = pr_why_table; transp -> name != NULL; transp++) |
| 2350 | { |
| 2351 | if (why == transp -> value) |
| 2352 | { |
| 2353 | if (summary) |
| 2354 | { |
| 2355 | printf_filtered ("%s ", transp -> name); |
| 2356 | } |
| 2357 | else |
| 2358 | { |
| 2359 | printf_filtered ("\t%-16s %s.\n", |
| 2360 | transp -> name, transp -> desc); |
| 2361 | } |
| 2362 | break; |
| 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | /* Use the pr_why field to determine what the pr_what field means, and |
| 2367 | print more information. */ |
| 2368 | |
| 2369 | switch (why) |
| 2370 | { |
| 2371 | case PR_REQUESTED: |
| 2372 | /* pr_what is unused for this case */ |
| 2373 | break; |
| 2374 | case PR_JOBCONTROL: |
| 2375 | case PR_SIGNALLED: |
| 2376 | if (summary) |
| 2377 | { |
| 2378 | printf_filtered ("%s ", signalname (what)); |
| 2379 | } |
| 2380 | else |
| 2381 | { |
| 2382 | printf_filtered ("\t%-16s %s.\n", signalname (what), |
| 2383 | safe_strsignal (what)); |
| 2384 | } |
| 2385 | break; |
| 2386 | case PR_SYSENTRY: |
| 2387 | if (summary) |
| 2388 | { |
| 2389 | printf_filtered ("%s ", syscallname (what)); |
| 2390 | } |
| 2391 | else |
| 2392 | { |
| 2393 | printf_filtered ("\t%-16s %s.\n", syscallname (what), |
| 2394 | "Entered this system call"); |
| 2395 | } |
| 2396 | break; |
| 2397 | case PR_SYSEXIT: |
| 2398 | if (summary) |
| 2399 | { |
| 2400 | printf_filtered ("%s ", syscallname (what)); |
| 2401 | } |
| 2402 | else |
| 2403 | { |
| 2404 | printf_filtered ("\t%-16s %s.\n", syscallname (what), |
| 2405 | "Returned from this system call"); |
| 2406 | } |
| 2407 | break; |
| 2408 | case PR_FAULTED: |
| 2409 | if (summary) |
| 2410 | { |
| 2411 | printf_filtered ("%s ", |
| 2412 | lookupname (faults_table, what, "fault")); |
| 2413 | } |
| 2414 | else |
| 2415 | { |
| 2416 | printf_filtered ("\t%-16s %s.\n", |
| 2417 | lookupname (faults_table, what, "fault"), |
| 2418 | lookupdesc (faults_table, what)); |
| 2419 | } |
| 2420 | break; |
| 2421 | } |
| 2422 | printf_filtered ("\n"); |
| 2423 | } |
| 2424 | } |
| 2425 | |
| 2426 | static void |
| 2427 | info_proc_siginfo (pip, summary) |
| 2428 | struct procinfo *pip; |
| 2429 | int summary; |
| 2430 | { |
| 2431 | struct siginfo *sip; |
| 2432 | |
| 2433 | if ((pip -> prstatus.pr_flags & PR_STOPPED) && |
| 2434 | (pip -> prstatus.pr_why == PR_SIGNALLED || |
| 2435 | pip -> prstatus.pr_why == PR_FAULTED)) |
| 2436 | { |
| 2437 | printf_filtered ("%-32s", "Additional signal/fault info:"); |
| 2438 | sip = &pip -> prstatus.pr_info; |
| 2439 | if (summary) |
| 2440 | { |
| 2441 | printf_filtered ("%s ", signalname (sip -> si_signo)); |
| 2442 | if (sip -> si_errno > 0) |
| 2443 | { |
| 2444 | printf_filtered ("%s ", errnoname (sip -> si_errno)); |
| 2445 | } |
| 2446 | if (sip -> si_code <= 0) |
| 2447 | { |
| 2448 | printf_filtered ("sent by pid %d, uid %d ", sip -> si_pid, |
| 2449 | sip -> si_uid); |
| 2450 | } |
| 2451 | else |
| 2452 | { |
| 2453 | printf_filtered ("%s ", sigcodename (sip)); |
| 2454 | if ((sip -> si_signo == SIGILL) || |
| 2455 | (sip -> si_signo == SIGFPE) || |
| 2456 | (sip -> si_signo == SIGSEGV) || |
| 2457 | (sip -> si_signo == SIGBUS)) |
| 2458 | { |
| 2459 | printf_filtered ("addr=%#x ", sip -> si_addr); |
| 2460 | } |
| 2461 | else if ((sip -> si_signo == SIGCHLD)) |
| 2462 | { |
| 2463 | printf_filtered ("child pid %u, status %u ", |
| 2464 | sip -> si_pid, |
| 2465 | sip -> si_status); |
| 2466 | } |
| 2467 | else if ((sip -> si_signo == SIGPOLL)) |
| 2468 | { |
| 2469 | printf_filtered ("band %u ", sip -> si_band); |
| 2470 | } |
| 2471 | } |
| 2472 | } |
| 2473 | else |
| 2474 | { |
| 2475 | printf_filtered ("\n\n"); |
| 2476 | printf_filtered ("\t%-16s %s.\n", signalname (sip -> si_signo), |
| 2477 | safe_strsignal (sip -> si_signo)); |
| 2478 | if (sip -> si_errno > 0) |
| 2479 | { |
| 2480 | printf_filtered ("\t%-16s %s.\n", |
| 2481 | errnoname (sip -> si_errno), |
| 2482 | safe_strerror (sip -> si_errno)); |
| 2483 | } |
| 2484 | if (sip -> si_code <= 0) |
| 2485 | { |
| 2486 | printf_filtered ("\t%-16u %s\n", sip -> si_pid, |
| 2487 | "PID of process sending signal"); |
| 2488 | printf_filtered ("\t%-16u %s\n", sip -> si_uid, |
| 2489 | "UID of process sending signal"); |
| 2490 | } |
| 2491 | else |
| 2492 | { |
| 2493 | printf_filtered ("\t%-16s %s.\n", sigcodename (sip), |
| 2494 | sigcodedesc (sip)); |
| 2495 | if ((sip -> si_signo == SIGILL) || |
| 2496 | (sip -> si_signo == SIGFPE)) |
| 2497 | { |
| 2498 | printf_filtered ("\t%-16#x %s.\n", sip -> si_addr, |
| 2499 | "Address of faulting instruction"); |
| 2500 | } |
| 2501 | else if ((sip -> si_signo == SIGSEGV) || |
| 2502 | (sip -> si_signo == SIGBUS)) |
| 2503 | { |
| 2504 | printf_filtered ("\t%-16#x %s.\n", sip -> si_addr, |
| 2505 | "Address of faulting memory reference"); |
| 2506 | } |
| 2507 | else if ((sip -> si_signo == SIGCHLD)) |
| 2508 | { |
| 2509 | printf_filtered ("\t%-16u %s.\n", sip -> si_pid, |
| 2510 | "Child process ID"); |
| 2511 | printf_filtered ("\t%-16u %s.\n", sip -> si_status, |
| 2512 | "Child process exit value or signal"); |
| 2513 | } |
| 2514 | else if ((sip -> si_signo == SIGPOLL)) |
| 2515 | { |
| 2516 | printf_filtered ("\t%-16u %s.\n", sip -> si_band, |
| 2517 | "Band event for POLL_{IN,OUT,MSG}"); |
| 2518 | } |
| 2519 | } |
| 2520 | } |
| 2521 | printf_filtered ("\n"); |
| 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | static void |
| 2526 | info_proc_syscalls (pip, summary) |
| 2527 | struct procinfo *pip; |
| 2528 | int summary; |
| 2529 | { |
| 2530 | int syscallnum; |
| 2531 | |
| 2532 | if (!summary) |
| 2533 | { |
| 2534 | |
| 2535 | #if 0 /* FIXME: Needs to use gdb-wide configured info about system calls. */ |
| 2536 | if (pip -> prstatus.pr_flags & PR_ASLEEP) |
| 2537 | { |
| 2538 | int syscallnum = pip -> prstatus.pr_reg[R_D0]; |
| 2539 | if (summary) |
| 2540 | { |
| 2541 | printf_filtered ("%-32s", "Sleeping in system call:"); |
| 2542 | printf_filtered ("%s", syscallname (syscallnum)); |
| 2543 | } |
| 2544 | else |
| 2545 | { |
| 2546 | printf_filtered ("Sleeping in system call '%s'.\n", |
| 2547 | syscallname (syscallnum)); |
| 2548 | } |
| 2549 | } |
| 2550 | #endif |
| 2551 | |
| 2552 | if (ioctl (pip -> fd, PIOCGENTRY, &pip -> entryset) < 0) |
| 2553 | { |
| 2554 | print_sys_errmsg (pip -> pathname, errno); |
| 2555 | error ("PIOCGENTRY failed"); |
| 2556 | } |
| 2557 | |
| 2558 | if (ioctl (pip -> fd, PIOCGEXIT, &pip -> exitset) < 0) |
| 2559 | { |
| 2560 | print_sys_errmsg (pip -> pathname, errno); |
| 2561 | error ("PIOCGEXIT failed"); |
| 2562 | } |
| 2563 | |
| 2564 | printf_filtered ("System call tracing information:\n\n"); |
| 2565 | |
| 2566 | printf_filtered ("\t%-12s %-8s %-8s\n", |
| 2567 | "System call", |
| 2568 | "Entry", |
| 2569 | "Exit"); |
| 2570 | for (syscallnum = 0; syscallnum < MAX_SYSCALLS; syscallnum++) |
| 2571 | { |
| 2572 | QUIT; |
| 2573 | if (syscall_table[syscallnum] != NULL) |
| 2574 | { |
| 2575 | printf_filtered ("\t%-12s ", syscall_table[syscallnum]); |
| 2576 | printf_filtered ("%-8s ", |
| 2577 | prismember (&pip -> entryset, syscallnum) |
| 2578 | ? "on" : "off"); |
| 2579 | printf_filtered ("%-8s ", |
| 2580 | prismember (&pip -> exitset, syscallnum) |
| 2581 | ? "on" : "off"); |
| 2582 | printf_filtered ("\n"); |
| 2583 | } |
| 2584 | } |
| 2585 | printf_filtered ("\n"); |
| 2586 | } |
| 2587 | } |
| 2588 | |
| 2589 | static char * |
| 2590 | signalname (signo) |
| 2591 | int signo; |
| 2592 | { |
| 2593 | char *name; |
| 2594 | static char locbuf[32]; |
| 2595 | |
| 2596 | name = strsigno (signo); |
| 2597 | if (name == NULL) |
| 2598 | { |
| 2599 | sprintf (locbuf, "Signal %d", signo); |
| 2600 | } |
| 2601 | else |
| 2602 | { |
| 2603 | sprintf (locbuf, "%s (%d)", name, signo); |
| 2604 | } |
| 2605 | return (locbuf); |
| 2606 | } |
| 2607 | |
| 2608 | static char * |
| 2609 | errnoname (errnum) |
| 2610 | int errnum; |
| 2611 | { |
| 2612 | char *name; |
| 2613 | static char locbuf[32]; |
| 2614 | |
| 2615 | name = strerrno (errnum); |
| 2616 | if (name == NULL) |
| 2617 | { |
| 2618 | sprintf (locbuf, "Errno %d", errnum); |
| 2619 | } |
| 2620 | else |
| 2621 | { |
| 2622 | sprintf (locbuf, "%s (%d)", name, errnum); |
| 2623 | } |
| 2624 | return (locbuf); |
| 2625 | } |
| 2626 | |
| 2627 | static void |
| 2628 | info_proc_signals (pip, summary) |
| 2629 | struct procinfo *pip; |
| 2630 | int summary; |
| 2631 | { |
| 2632 | int signo; |
| 2633 | |
| 2634 | if (!summary) |
| 2635 | { |
| 2636 | if (ioctl (pip -> fd, PIOCGTRACE, &pip -> trace) < 0) |
| 2637 | { |
| 2638 | print_sys_errmsg (pip -> pathname, errno); |
| 2639 | error ("PIOCGTRACE failed"); |
| 2640 | } |
| 2641 | |
| 2642 | printf_filtered ("Disposition of signals:\n\n"); |
| 2643 | printf_filtered ("\t%-15s %-8s %-8s %-8s %s\n\n", |
| 2644 | "Signal", "Trace", "Hold", "Pending", "Description"); |
| 2645 | for (signo = 0; signo < NSIG; signo++) |
| 2646 | { |
| 2647 | QUIT; |
| 2648 | printf_filtered ("\t%-15s ", signalname (signo)); |
| 2649 | printf_filtered ("%-8s ", |
| 2650 | prismember (&pip -> trace, signo) |
| 2651 | ? "on" : "off"); |
| 2652 | printf_filtered ("%-8s ", |
| 2653 | prismember (&pip -> prstatus.pr_sighold, signo) |
| 2654 | ? "on" : "off"); |
| 2655 | printf_filtered ("%-8s ", |
| 2656 | prismember (&pip -> prstatus.pr_sigpend, signo) |
| 2657 | ? "yes" : "no"); |
| 2658 | printf_filtered (" %s\n", safe_strsignal (signo)); |
| 2659 | } |
| 2660 | printf_filtered ("\n"); |
| 2661 | } |
| 2662 | } |
| 2663 | |
| 2664 | static void |
| 2665 | info_proc_faults (pip, summary) |
| 2666 | struct procinfo *pip; |
| 2667 | int summary; |
| 2668 | { |
| 2669 | struct trans *transp; |
| 2670 | |
| 2671 | if (!summary) |
| 2672 | { |
| 2673 | if (ioctl (pip -> fd, PIOCGFAULT, &pip -> fltset) < 0) |
| 2674 | { |
| 2675 | print_sys_errmsg (pip -> pathname, errno); |
| 2676 | error ("PIOCGFAULT failed"); |
| 2677 | } |
| 2678 | |
| 2679 | printf_filtered ("Current traced hardware fault set:\n\n"); |
| 2680 | printf_filtered ("\t%-12s %-8s\n", "Fault", "Trace"); |
| 2681 | |
| 2682 | for (transp = faults_table; transp -> name != NULL; transp++) |
| 2683 | { |
| 2684 | QUIT; |
| 2685 | printf_filtered ("\t%-12s ", transp -> name); |
| 2686 | printf_filtered ("%-8s", prismember (&pip -> fltset, transp -> value) |
| 2687 | ? "on" : "off"); |
| 2688 | printf_filtered ("\n"); |
| 2689 | } |
| 2690 | printf_filtered ("\n"); |
| 2691 | } |
| 2692 | } |
| 2693 | |
| 2694 | static void |
| 2695 | info_proc_mappings (pip, summary) |
| 2696 | struct procinfo *pip; |
| 2697 | int summary; |
| 2698 | { |
| 2699 | int nmap; |
| 2700 | struct prmap *prmaps; |
| 2701 | struct prmap *prmap; |
| 2702 | |
| 2703 | if (!summary) |
| 2704 | { |
| 2705 | printf_filtered ("Mapped address spaces:\n\n"); |
| 2706 | printf_filtered ("\t%10s %10s %10s %10s %7s\n", |
| 2707 | "Start Addr", |
| 2708 | " End Addr", |
| 2709 | " Size", |
| 2710 | " Offset", |
| 2711 | "Flags"); |
| 2712 | if (ioctl (pip -> fd, PIOCNMAP, &nmap) == 0) |
| 2713 | { |
| 2714 | prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps)); |
| 2715 | if (ioctl (pip -> fd, PIOCMAP, prmaps) == 0) |
| 2716 | { |
| 2717 | for (prmap = prmaps; prmap -> pr_size; ++prmap) |
| 2718 | { |
| 2719 | printf_filtered ("\t%#10x %#10x %#10x %#10x %7s\n", |
| 2720 | prmap -> pr_vaddr, |
| 2721 | prmap -> pr_vaddr + prmap -> pr_size - 1, |
| 2722 | prmap -> pr_size, |
| 2723 | prmap -> pr_off, |
| 2724 | mappingflags (prmap -> pr_mflags)); |
| 2725 | } |
| 2726 | } |
| 2727 | } |
| 2728 | printf_filtered ("\n"); |
| 2729 | } |
| 2730 | } |
| 2731 | |
| 2732 | /* |
| 2733 | |
| 2734 | LOCAL FUNCTION |
| 2735 | |
| 2736 | info_proc -- implement the "info proc" command |
| 2737 | |
| 2738 | SYNOPSIS |
| 2739 | |
| 2740 | void info_proc (char *args, int from_tty) |
| 2741 | |
| 2742 | DESCRIPTION |
| 2743 | |
| 2744 | Implement gdb's "info proc" command by using the /proc interface |
| 2745 | to print status information about any currently running process. |
| 2746 | |
| 2747 | Examples of the use of "info proc" are: |
| 2748 | |
| 2749 | info proc (prints summary info for current inferior) |
| 2750 | info proc 123 (prints summary info for process with pid 123) |
| 2751 | info proc mappings (prints address mappings) |
| 2752 | info proc times (prints process/children times) |
| 2753 | info proc id (prints pid, ppid, gid, sid, etc) |
| 2754 | info proc status (prints general process state info) |
| 2755 | info proc signals (prints info about signal handling) |
| 2756 | info proc all (prints all info) |
| 2757 | |
| 2758 | */ |
| 2759 | |
| 2760 | static void |
| 2761 | info_proc (args, from_tty) |
| 2762 | char *args; |
| 2763 | int from_tty; |
| 2764 | { |
| 2765 | int pid; |
| 2766 | struct procinfo pii; |
| 2767 | struct procinfo *pip; |
| 2768 | struct cleanup *old_chain; |
| 2769 | char *nexttok; |
| 2770 | char **argv; |
| 2771 | int argsize; |
| 2772 | int summary = 1; |
| 2773 | int flags = 0; |
| 2774 | int syscalls = 0; |
| 2775 | int signals = 0; |
| 2776 | int faults = 0; |
| 2777 | int mappings = 0; |
| 2778 | int times = 0; |
| 2779 | int id = 0; |
| 2780 | int status = 0; |
| 2781 | int all = 0; |
| 2782 | |
| 2783 | old_chain = make_cleanup (null_cleanup, 0); |
| 2784 | |
| 2785 | /* Default to using the current inferior if no pid specified */ |
| 2786 | |
| 2787 | pip = π |
| 2788 | |
| 2789 | if (args != NULL) |
| 2790 | { |
| 2791 | if ((argv = buildargv (args)) == NULL) |
| 2792 | { |
| 2793 | nomem (0); |
| 2794 | } |
| 2795 | make_cleanup (freeargv, (char *) argv); |
| 2796 | |
| 2797 | while (*argv != NULL) |
| 2798 | { |
| 2799 | argsize = strlen (*argv); |
| 2800 | if (argsize >= 1 && strncmp (*argv, "all", argsize) == 0) |
| 2801 | { |
| 2802 | summary = 0; |
| 2803 | all = 1; |
| 2804 | } |
| 2805 | else if (argsize >= 2 && strncmp (*argv, "faults", argsize) == 0) |
| 2806 | { |
| 2807 | summary = 0; |
| 2808 | faults = 1; |
| 2809 | } |
| 2810 | else if (argsize >= 2 && strncmp (*argv, "flags", argsize) == 0) |
| 2811 | { |
| 2812 | summary = 0; |
| 2813 | flags = 1; |
| 2814 | } |
| 2815 | else if (argsize >= 1 && strncmp (*argv, "id", argsize) == 0) |
| 2816 | { |
| 2817 | summary = 0; |
| 2818 | id = 1; |
| 2819 | } |
| 2820 | else if (argsize >= 1 && strncmp (*argv, "mappings", argsize) == 0) |
| 2821 | { |
| 2822 | summary = 0; |
| 2823 | mappings = 1; |
| 2824 | } |
| 2825 | else if (argsize >= 2 && strncmp (*argv, "signals", argsize) == 0) |
| 2826 | { |
| 2827 | summary = 0; |
| 2828 | signals = 1; |
| 2829 | } |
| 2830 | else if (argsize >= 2 && strncmp (*argv, "status", argsize) == 0) |
| 2831 | { |
| 2832 | summary = 0; |
| 2833 | status = 1; |
| 2834 | } |
| 2835 | else if (argsize >= 2 && strncmp (*argv, "syscalls", argsize) == 0) |
| 2836 | { |
| 2837 | summary = 0; |
| 2838 | syscalls = 1; |
| 2839 | } |
| 2840 | else if (argsize >= 1 && strncmp (*argv, "times", argsize) == 0) |
| 2841 | { |
| 2842 | summary = 0; |
| 2843 | times = 1; |
| 2844 | } |
| 2845 | else if ((pii.pid = atoi (*argv)) > 0) |
| 2846 | { |
| 2847 | pid = pii.pid; |
| 2848 | pip = &pii; |
| 2849 | (void) memset (&pii, 0, sizeof (pii)); |
| 2850 | if (!open_proc_file (pid, pip)) |
| 2851 | { |
| 2852 | perror_with_name (pip -> pathname); |
| 2853 | /* NOTREACHED */ |
| 2854 | } |
| 2855 | make_cleanup (close_proc_file, pip); |
| 2856 | } |
| 2857 | else if (**argv != '\000') |
| 2858 | { |
| 2859 | error ("Unrecognized or ambiguous keyword `%s'.", *argv); |
| 2860 | } |
| 2861 | argv++; |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | /* If we don't have a valid open process at this point, then we have no |
| 2866 | inferior or didn't specify a specific pid. */ |
| 2867 | |
| 2868 | if (!pip -> valid) |
| 2869 | { |
| 2870 | error ("No process. Run an inferior or specify an explicit pid."); |
| 2871 | } |
| 2872 | if (ioctl (pip -> fd, PIOCSTATUS, &(pip -> prstatus)) < 0) |
| 2873 | { |
| 2874 | print_sys_errmsg (pip -> pathname, errno); |
| 2875 | error ("PIOCSTATUS failed"); |
| 2876 | } |
| 2877 | |
| 2878 | /* Print verbose information of the requested type(s), or just a summary |
| 2879 | of the information for all types. */ |
| 2880 | |
| 2881 | printf_filtered ("\nInformation for %s:\n\n", pip -> pathname); |
| 2882 | if (summary || all || flags) |
| 2883 | { |
| 2884 | info_proc_flags (pip, summary); |
| 2885 | } |
| 2886 | if (summary || all) |
| 2887 | { |
| 2888 | info_proc_stop (pip, summary); |
| 2889 | } |
| 2890 | if (summary || all || signals || faults) |
| 2891 | { |
| 2892 | info_proc_siginfo (pip, summary); |
| 2893 | } |
| 2894 | if (summary || all || syscalls) |
| 2895 | { |
| 2896 | info_proc_syscalls (pip, summary); |
| 2897 | } |
| 2898 | if (summary || all || mappings) |
| 2899 | { |
| 2900 | info_proc_mappings (pip, summary); |
| 2901 | } |
| 2902 | if (summary || all || signals) |
| 2903 | { |
| 2904 | info_proc_signals (pip, summary); |
| 2905 | } |
| 2906 | if (summary || all || faults) |
| 2907 | { |
| 2908 | info_proc_faults (pip, summary); |
| 2909 | } |
| 2910 | printf_filtered ("\n"); |
| 2911 | |
| 2912 | /* All done, deal with closing any temporary process info structure, |
| 2913 | freeing temporary memory , etc. */ |
| 2914 | |
| 2915 | do_cleanups (old_chain); |
| 2916 | } |
| 2917 | |
| 2918 | /* |
| 2919 | |
| 2920 | GLOBAL FUNCTION |
| 2921 | |
| 2922 | _initialize_proc_fs -- initialize the process file system stuff |
| 2923 | |
| 2924 | SYNOPSIS |
| 2925 | |
| 2926 | void _initialize_proc_fs (void) |
| 2927 | |
| 2928 | DESCRIPTION |
| 2929 | |
| 2930 | Do required initializations during gdb startup for using the |
| 2931 | /proc file system interface. |
| 2932 | |
| 2933 | */ |
| 2934 | |
| 2935 | static char *proc_desc = |
| 2936 | "Show process status information using /proc entry.\n\ |
| 2937 | Specify process id or use current inferior by default.\n\ |
| 2938 | Specify keywords for detailed information; default is summary.\n\ |
| 2939 | Keywords are: `all', `faults', `flags', `id', `mappings', `signals',\n\ |
| 2940 | `status', `syscalls', and `times'.\n\ |
| 2941 | Unambiguous abbreviations may be used."; |
| 2942 | |
| 2943 | void |
| 2944 | _initialize_proc_fs () |
| 2945 | { |
| 2946 | add_info ("proc", info_proc, proc_desc); |
| 2947 | init_syscall_table (); |
| 2948 | } |
| 2949 | |
| 2950 | #endif /* USE_PROC_FS */ |