mostang.com!davidm | 64f2bf7 | 2003-01-28 07:32:15 +0000 | [diff] [blame^] | 1 | '\" t |
| 2 | .\" Manual page created with latex2man on Mon Jan 27 23:19:42 PST 2003 |
| 3 | .\" NOTE: This file is generated, DO NOT EDIT. |
| 4 | .de Vb |
| 5 | .ft CW |
| 6 | .nf |
| 7 | .. |
| 8 | .de Ve |
| 9 | .ft R |
| 10 | |
| 11 | .fi |
| 12 | .. |
| 13 | .TH "LIBUNWIND\-PTRACE" "3" "27 January 2003" "Programming Library " "Programming Library " |
| 14 | .SH NAME |
| 15 | |
| 16 | libunwind\-ptrace \-\- ptrace() support in libunwind |
| 17 | .PP |
| 18 | .SH SYNOPSIS |
| 19 | |
| 20 | .PP |
| 21 | #include <libunwind.h> |
| 22 | .br |
| 23 | .PP |
| 24 | unw_accessors_t |
| 25 | _UPT_accessors; |
| 26 | .br |
| 27 | .PP |
| 28 | void *_UPT_create(pid_t); |
| 29 | .br |
| 30 | void |
| 31 | _UPT_destroy(void *); |
| 32 | .br |
| 33 | .PP |
| 34 | int |
| 35 | _UPT_find_proc_info(unw_addr_space_t, |
| 36 | unw_word_t, |
| 37 | unw_proc_info_t *, |
| 38 | int, |
| 39 | void *); |
| 40 | .br |
| 41 | void |
| 42 | _UPT_put_unwind_info(unw_addr_space_t, |
| 43 | unw_proc_info_t *, |
| 44 | void *); |
| 45 | .br |
| 46 | int |
| 47 | _UPT_get_dyn_info_list_addr(unw_addr_space_t, |
| 48 | unw_word_t *, |
| 49 | void *); |
| 50 | .br |
| 51 | int |
| 52 | _UPT_access_mem(unw_addr_space_t, |
| 53 | unw_word_t, |
| 54 | unw_word_t *, |
| 55 | int, |
| 56 | void *); |
| 57 | .br |
| 58 | int |
| 59 | _UPT_access_reg(unw_addr_space_t, |
| 60 | unw_regnum_t, |
| 61 | unw_word_t *, |
| 62 | int, |
| 63 | void *); |
| 64 | .br |
| 65 | int |
| 66 | _UPT_access_fpreg(unw_addr_space_t, |
| 67 | unw_regnum_t, |
| 68 | unw_fpreg_t *, |
| 69 | int, |
| 70 | void *); |
| 71 | .br |
| 72 | .PP |
| 73 | .SH DESCRIPTION |
| 74 | |
| 75 | .PP |
| 76 | The ptrace(2) |
| 77 | system\-call makes it possible for a process to |
| 78 | gain access to the machine\-state and virtual memory of \fIanother\fP |
| 79 | process. With the right set of call\-back routines, it is therefore |
| 80 | possible to hook up libunwind |
| 81 | to another process via |
| 82 | ptrace(2). |
| 83 | While it\&'s not very difficult to do so directly, |
| 84 | libunwind |
| 85 | further facilitates this task by providing |
| 86 | ready\-to\-use callbacks for this purpose. The routines and variables |
| 87 | implementing this facility use a name\-prefix of _UPT, |
| 88 | which is |
| 89 | stands for ``unwind\-via\-ptrace\&''\&. |
| 90 | .PP |
| 91 | An application that wants to use the _UPT\-facility |
| 92 | first needs |
| 93 | to create a new libunwind |
| 94 | address\-space that represents the |
| 95 | target process. This is done by calling |
| 96 | unw_create_addr_space(). |
| 97 | In many cases, the application |
| 98 | will simply want to pass the address of _UPT_accessors |
| 99 | as the |
| 100 | first argument to this routine. Doing so will ensure that |
| 101 | libunwind |
| 102 | will be able to properly unwind the target process. |
| 103 | However, in special circumstances, an application may prefer to use |
| 104 | only portions of the _UPT\-facility. |
| 105 | For this reason, the |
| 106 | individual callback routines (_UPT_find_proc_info(), |
| 107 | _UPT_put_unwind_info(), |
| 108 | etc.) are also available for direct |
| 109 | use. Of course, the addresses of these routines could also be picked |
| 110 | up from _UPT_accessors, |
| 111 | but doing so would prevent static |
| 112 | initialization. Also, when using _UPT_accessors, |
| 113 | \fIall\fP |
| 114 | the callback routines will be linked into the application, even if |
| 115 | they are never actually called. |
| 116 | .PP |
| 117 | Next, the application can turn on ptrace\-mode on the target process, |
| 118 | either by forking a new process, invoking PTRACE_TRACEME, |
| 119 | and |
| 120 | then starting the target program (via execve(2)), |
| 121 | or by |
| 122 | directly attaching to an already running process (via |
| 123 | PTRACE_ATTACH). |
| 124 | Either way, once the process\-ID (pid) of the |
| 125 | target process is known, a _UPT\-info\-structure |
| 126 | can be created |
| 127 | by calling _UPT_create(), |
| 128 | passing the pid of the target process |
| 129 | as the only argument. The returned void\-pointer then needs to be |
| 130 | passed as the ``argument\&'' pointer (third argument) to |
| 131 | unw_init_remote(). |
| 132 | .PP |
| 133 | When the application is done using libunwind |
| 134 | on the target |
| 135 | process, _UPT_destroy() |
| 136 | needs to be called, passing it the |
| 137 | void\-pointer that was returned by the corresponding call to |
| 138 | _UPT_create(). |
| 139 | This ensures that all memory and other |
| 140 | resources are freed up. |
| 141 | .PP |
| 142 | .SH AVAILABILITY |
| 143 | |
| 144 | .PP |
| 145 | Since ptrace(2) |
| 146 | works within a single machine only, the |
| 147 | _UPT\-facility |
| 148 | by definition is not available in |
| 149 | libunwind\-versions |
| 150 | configured for cross\-unwinding. |
| 151 | .PP |
| 152 | .SH THREAD SAFETY |
| 153 | |
| 154 | .PP |
| 155 | The _UPT\-facility |
| 156 | assumes that a single _UPT\-info |
| 157 | structure is never shared between threads. Because of this, no |
| 158 | explicit locking is used. As long as only one thread uses |
| 159 | a _UPT\-info |
| 160 | structure at any given time, this facility |
| 161 | is thread\-safe. |
| 162 | .PP |
| 163 | .SH RETURN VALUE |
| 164 | |
| 165 | .PP |
| 166 | _UPT_create() |
| 167 | may return a NULL |
| 168 | pointer if it fails |
| 169 | to create the _UPT\-info\-structure |
| 170 | for any reason. For the |
| 171 | current implementation, the only reason this call may fail is when the |
| 172 | system is out of memory. |
| 173 | .PP |
| 174 | .SH SEE ALSO |
| 175 | |
| 176 | .PP |
| 177 | execve(2), |
| 178 | libunwind(3), |
| 179 | ptrace(2) |
| 180 | .PP |
| 181 | .SH AUTHOR |
| 182 | |
| 183 | .PP |
| 184 | David Mosberger\-Tang |
| 185 | .br |
| 186 | Hewlett\-Packard Labs |
| 187 | .br |
| 188 | Palo\-Alto, CA 94304 |
| 189 | .br |
| 190 | Email: \fBdavidm@hpl.hp.com\fP |
| 191 | .br |
| 192 | WWW: \fBhttp://www.hpl.hp.com/research/linux/libunwind/\fP\&. |
| 193 | .\" NOTE: This file is generated, DO NOT EDIT. |