2 * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com>
5 * Portions of this software were developed by SRI International and the
6 * University of Cambridge Computer Laboratory under DARPA/AFRL contract
7 * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.
9 * Portions of this software were developed by the University of Cambridge
10 * Computer Laboratory as part of the CTSRD Project, with support from the
11 * UK Higher Education Innovation Fund (HEIF).
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <sys/types.h>
40 #include <thread_db.h>
42 #include "libpthread_db.h"
45 pt_reg_to_ucontext(const struct reg *r, ucontext_t *uc)
49 mc = &uc->uc_mcontext;
51 memcpy(mc->mc_gpregs.gp_t, r->t, sizeof(mc->mc_gpregs.gp_t));
52 memcpy(mc->mc_gpregs.gp_s, r->s, sizeof(mc->mc_gpregs.gp_s));
53 memcpy(mc->mc_gpregs.gp_a, r->a, sizeof(mc->mc_gpregs.gp_a));
54 mc->mc_gpregs.gp_ra = r->ra;
55 mc->mc_gpregs.gp_sp = r->sp;
56 mc->mc_gpregs.gp_gp = r->gp;
57 mc->mc_gpregs.gp_tp = r->tp;
58 mc->mc_gpregs.gp_sepc = r->sepc;
59 mc->mc_gpregs.gp_sstatus = r->sstatus;
63 pt_ucontext_to_reg(const ucontext_t *uc, struct reg *r)
67 mc = &uc->uc_mcontext;
69 memcpy(r->t, mc->mc_gpregs.gp_t, sizeof(mc->mc_gpregs.gp_t));
70 memcpy(r->s, mc->mc_gpregs.gp_s, sizeof(mc->mc_gpregs.gp_s));
71 memcpy(r->a, mc->mc_gpregs.gp_a, sizeof(mc->mc_gpregs.gp_a));
72 r->ra = mc->mc_gpregs.gp_ra;
73 r->sp = mc->mc_gpregs.gp_sp;
74 r->gp = mc->mc_gpregs.gp_gp;
75 r->tp = mc->mc_gpregs.gp_tp;
76 r->sepc = mc->mc_gpregs.gp_sepc;
77 r->sstatus = mc->mc_gpregs.gp_sstatus;
81 pt_fpreg_to_ucontext(const struct fpreg *r __unused, ucontext_t *uc __unused)
83 mcontext_t *mc = &uc->uc_mcontext;
85 memcpy(&mc->mc_fpregs, r, sizeof(*r));
86 mc->mc_flags |= _MC_FP_VALID;
90 pt_ucontext_to_fpreg(const ucontext_t *uc __unused, struct fpreg *r __unused)
92 const mcontext_t *mc = &uc->uc_mcontext;
94 if (mc->mc_flags & _MC_FP_VALID)
95 memcpy(r, &mc->mc_fpregs, sizeof(*r));
97 memset(r, 0, sizeof(*r));
106 pt_reg_sstep(struct reg *reg __unused, int step __unused)