Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame^] | 1 | /* x86-64 specific core note handling. |
| 2 | Copyright (C) 2005 Red Hat, Inc. |
| 3 | Written by Ulrich Drepper <drepper@redhat.com>, 2005. |
| 4 | |
| 5 | This program is Open Source software; you can redistribute it and/or |
| 6 | modify it under the terms of the Open Software License version 1.0 as |
| 7 | published by the Open Source Initiative. |
| 8 | |
| 9 | You should have received a copy of the Open Software License along |
| 10 | with this program; if not, you may obtain a copy of the Open Software |
| 11 | License version 1.0 from http://www.opensource.org/licenses/osl.php or |
| 12 | by writing the Open Source Initiative c/o Lawrence Rosen, Esq., |
| 13 | 3001 King Ranch Road, Ukiah, CA 95482. */ |
| 14 | |
| 15 | #ifdef HAVE_CONFIG_H |
| 16 | # include <config.h> |
| 17 | #endif |
| 18 | |
| 19 | #include <elf.h> |
| 20 | #include <inttypes.h> |
| 21 | #include <stddef.h> |
| 22 | #include <stdio.h> |
| 23 | #include <sys/time.h> |
| 24 | |
| 25 | #include <libebl_x86_64.h> |
| 26 | |
| 27 | |
| 28 | /* We cannot include <sys/procfs.h> since the definition would be for |
| 29 | the host platform and not always x86-64 as required here. */ |
| 30 | struct elf_prstatus |
| 31 | { |
| 32 | struct |
| 33 | { |
| 34 | int32_t si_signo; /* Signal number. */ |
| 35 | int32_t si_code; /* Extra code. */ |
| 36 | int32_t si_errno; /* Errno. */ |
| 37 | } pr_info; /* Info associated with signal. */ |
| 38 | int16_t pr_cursig; /* Current signal. */ |
| 39 | uint64_t pr_sigpend; /* Set of pending signals. */ |
| 40 | uint64_t pr_sighold; /* Set of held signals. */ |
| 41 | int32_t pr_pid; |
| 42 | int32_t pr_ppid; |
| 43 | int32_t pr_pgrp; |
| 44 | int32_t pr_sid; |
| 45 | struct x86_64_timeval |
| 46 | { |
| 47 | int64_t tv_sec; |
| 48 | int32_t tv_usec; |
| 49 | } pr_utime; /* User time. */ |
| 50 | struct x86_64_timeval pr_stime; /* System time. */ |
| 51 | struct x86_64_timeval pr_cutime; /* Cumulative user time. */ |
| 52 | struct x86_64_timeval pr_cstime; /* Cumulative system time. */ |
| 53 | uint64_t pr_reg[27]; /* GP registers. */ |
| 54 | int32_t pr_fpvalid; /* True if math copro being used. */ |
| 55 | }; |
| 56 | |
| 57 | |
| 58 | struct elf_prpsinfo |
| 59 | { |
| 60 | char pr_state; /* Numeric process state. */ |
| 61 | char pr_sname; /* Char for pr_state. */ |
| 62 | char pr_zomb; /* Zombie. */ |
| 63 | char pr_nice; /* Nice val. */ |
| 64 | uint64_t pr_flag; /* Flags. */ |
| 65 | uint32_t pr_uid; |
| 66 | uint32_t pr_gid; |
| 67 | int32_t pr_pid; |
| 68 | int32_t pr_ppid; |
| 69 | int32_t pr_pgrp; |
| 70 | int32_t pr_sid; |
| 71 | /* Lots missing */ |
| 72 | char pr_fname[16]; /* Filename of executable. */ |
| 73 | char pr_psargs[80]; /* Initial part of arg list. */ |
| 74 | }; |
| 75 | |
| 76 | |
| 77 | bool |
| 78 | x86_64_core_note (name, type, descsz, desc) |
| 79 | const char *name __attribute__ ((unused)); |
| 80 | uint32_t type; |
| 81 | uint32_t descsz; |
| 82 | const char *desc; |
| 83 | { |
| 84 | bool result = false; |
| 85 | |
| 86 | switch (type) |
| 87 | { |
| 88 | case NT_PRSTATUS: |
| 89 | if (descsz < sizeof (struct elf_prstatus)) |
| 90 | /* Not enough data. */ |
| 91 | break; |
| 92 | |
| 93 | struct elf_prstatus *stat = (struct elf_prstatus *) desc; |
| 94 | |
| 95 | printf (" SIGINFO: signo: %" PRId32 ", code = %" PRId32 |
| 96 | ", errno = %" PRId32 "\n" |
| 97 | " signal: %" PRId16 ", pending: %#08" PRIx64 ", holding: %#08" |
| 98 | PRIx64 "\n" |
| 99 | " pid: %" PRId32 ", ppid = %" PRId32 ", pgrp = %" PRId32 |
| 100 | ", sid = %" PRId32 "\n" |
| 101 | " utime: %6" PRId64 ".%06" PRId32 |
| 102 | "s, stime: %6" PRId64 ".%06" PRId32 "s\n" |
| 103 | " cutime: %6" PRId64 ".%06" PRId32 |
| 104 | "s, cstime: %6" PRId64 ".%06" PRId32 "s\n" |
| 105 | " rax: %016" PRIx64 " rbx: %016" PRIx64 "\n" |
| 106 | " rcx: %016" PRIx64 " rdx: %016" PRIx64 "\n" |
| 107 | " rsi: %016" PRIx64 " rdi: %016" PRIx64 "\n" |
| 108 | " rbp: %016" PRIx64 " rsp: %016" PRIx64 "\n" |
| 109 | " r8: %016" PRIx64 " r9: %016" PRIx64 "\n" |
| 110 | " r10: %016" PRIx64 " r11: %016" PRIx64 "\n" |
| 111 | " r12: %016" PRIx64 " r13: %016" PRIx64 "\n" |
| 112 | " r14: %016" PRIx64 " r15: %016" PRIx64 "\n" |
| 113 | " rip: %016" PRIx64 " eflags: %08" PRIx64 "\n" |
| 114 | " original rax: %016" PRIx64 "\n" |
| 115 | " cs: %04" PRIx64 " ds: %04" PRIx64 " es: %04" PRIx64 |
| 116 | " ss: %04" PRIx64 "\n" |
| 117 | " fs: %04" PRIx64 " fs_base: %016" PRIx64 |
| 118 | " gs: %04" PRIx64 " gs_base: %016" PRIx64 "\n\n", |
| 119 | stat->pr_info. si_signo, |
| 120 | stat->pr_info. si_code, |
| 121 | stat->pr_info. si_errno, |
| 122 | stat->pr_cursig, |
| 123 | stat->pr_sigpend, stat->pr_sighold, |
| 124 | stat->pr_pid, stat->pr_ppid, stat->pr_pgrp, stat->pr_sid, |
| 125 | stat->pr_utime.tv_sec, stat->pr_utime.tv_usec, |
| 126 | stat->pr_stime.tv_sec, stat->pr_stime.tv_usec, |
| 127 | stat->pr_cutime.tv_sec, stat->pr_cutime.tv_usec, |
| 128 | stat->pr_cstime.tv_sec, stat->pr_cstime.tv_usec, |
| 129 | stat->pr_reg[10], stat->pr_reg[5], stat->pr_reg[11], |
| 130 | stat->pr_reg[12], stat->pr_reg[13], stat->pr_reg[14], |
| 131 | stat->pr_reg[4], stat->pr_reg[10], stat->pr_reg[9], |
| 132 | stat->pr_reg[7], stat->pr_reg[6], stat->pr_reg[5], |
| 133 | stat->pr_reg[3], stat->pr_reg[2], stat->pr_reg[1], |
| 134 | stat->pr_reg[0], stat->pr_reg[16], stat->pr_reg[18], |
| 135 | stat->pr_reg[15], stat->pr_reg[17], stat->pr_reg[23], |
| 136 | stat->pr_reg[24], stat->pr_reg[20], |
| 137 | stat->pr_reg[25], stat->pr_reg[21], |
| 138 | stat->pr_reg[26], stat->pr_reg[22]); |
| 139 | |
| 140 | /* We handled this entry. */ |
| 141 | result = true; |
| 142 | break; |
| 143 | |
| 144 | case NT_PRPSINFO: |
| 145 | if (descsz < sizeof (struct elf_prpsinfo)) |
| 146 | /* Not enough data. */ |
| 147 | break; |
| 148 | |
| 149 | struct elf_prpsinfo *info = (struct elf_prpsinfo *) desc; |
| 150 | |
| 151 | printf (" state: %c (%hhd), zombie: %hhd, nice: %hhd\n" |
| 152 | " flags: %08" PRIx64 " uid: %" PRIu32 " gid: %" PRIu32 "\n" |
| 153 | " pid: %" PRId32 " ppid: %" PRId32 " pgrp: %" PRId32 |
| 154 | " sid: %" PRId32 "\n" |
| 155 | " fname: %.16s\n" |
| 156 | " args: %.80s\n\n", |
| 157 | info->pr_sname, info->pr_state, info->pr_zomb, info->pr_nice, |
| 158 | info->pr_flag, info->pr_uid, info->pr_gid, |
| 159 | info->pr_pid, info->pr_ppid, info->pr_pgrp, info->pr_sid, |
| 160 | info->pr_fname, info->pr_psargs); |
| 161 | |
| 162 | /* We handled this entry. */ |
| 163 | result = true; |
| 164 | break; |
| 165 | |
| 166 | default: |
| 167 | break; |
| 168 | } |
| 169 | |
| 170 | return result; |
| 171 | } |