blob: bce949f0d894f29ae8d155c3e31dc8ec3add72c1 [file] [log] [blame]
Petr Machataf6ec08a2012-01-06 16:58:54 +01001/*
2 * This file is part of ltrace.
3 * Copyright (C) 2011,2012 Petr Machata, Red Hat Inc.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 */
20
21#include <stdlib.h>
22#include <string.h>
Petr Machata98d319e2012-05-04 02:22:47 +020023
Petr Machataf6ec08a2012-01-06 16:58:54 +010024#include "fetch.h"
25#include "value.h"
26#include "arch.h"
Petr Machata98d319e2012-05-04 02:22:47 +020027#include "type.h"
Petr Machataf6ec08a2012-01-06 16:58:54 +010028
29#ifdef ARCH_HAVE_FETCH_ARG
30struct fetch_context *arch_fetch_arg_init(enum tof type, struct Process *proc,
31 struct arg_type_info *ret_info);
32
33struct fetch_context *arch_fetch_arg_clone(struct Process *proc,
34 struct fetch_context *context);
35
36int arch_fetch_arg_next(struct fetch_context *ctx, enum tof type,
37 struct Process *proc, struct arg_type_info *info,
38 struct value *valuep);
39
40int arch_fetch_retval(struct fetch_context *ctx, enum tof type,
41 struct Process *proc, struct arg_type_info *info,
42 struct value *valuep);
43
44void arch_fetch_arg_done(struct fetch_context *context);
45
46#else
47/* Fall back to gimme_arg. */
48
49long gimme_arg(enum tof type, struct Process *proc, int arg_num,
50 struct arg_type_info *info);
51
52struct fetch_context {
53 int argnum;
54};
55
56struct fetch_context *
57arch_fetch_arg_init(enum tof type, struct Process *proc,
58 struct arg_type_info *ret_info)
59{
60 return calloc(sizeof(struct fetch_context), 1);
61}
62
63struct fetch_context *
64arch_fetch_arg_clone(struct Process *proc, struct fetch_context *context)
65{
66 struct fetch_context *ret = malloc(sizeof(*ret));
67 if (ret == NULL)
68 return NULL;
69 return memcpy(ret, context, sizeof(*ret));
70}
71
72int
73arch_fetch_arg_next(struct fetch_context *context, enum tof type,
74 struct Process *proc,
75 struct arg_type_info *info, struct value *valuep)
76{
77 long l = gimme_arg(type, proc, context->argnum++, info);
Petr Machatada442f42012-05-04 02:22:09 +020078 value_set_word(valuep, l);
Petr Machataf6ec08a2012-01-06 16:58:54 +010079 return 0;
80}
81
82int
83arch_fetch_retval(struct fetch_context *context, enum tof type,
84 struct Process *proc,
85 struct arg_type_info *info, struct value *valuep)
86{
87 long l = gimme_arg(type, proc, -1, info);
Petr Machatada442f42012-05-04 02:22:09 +020088 value_set_word(valuep, l);
Petr Machataf6ec08a2012-01-06 16:58:54 +010089 return 0;
90}
91
92void
93arch_fetch_arg_done(struct fetch_context *context)
94{
95 free(context);
96}
97#endif
98
99struct fetch_context *
100fetch_arg_init(enum tof type, struct Process *proc,
101 struct arg_type_info *ret_info)
102{
103 return arch_fetch_arg_init(type, proc, ret_info);
104}
105
106struct fetch_context *
107fetch_arg_clone(struct Process *proc, struct fetch_context *context)
108{
109 return arch_fetch_arg_clone(proc, context);
110}
111
112int
113fetch_arg_next(struct fetch_context *context, enum tof type,
114 struct Process *proc,
115 struct arg_type_info *info, struct value *valuep)
116{
117 return arch_fetch_arg_next(context, type, proc, info, valuep);
118}
119
120int
121fetch_retval(struct fetch_context *context, enum tof type,
122 struct Process *proc,
123 struct arg_type_info *info, struct value *valuep)
124{
125 return arch_fetch_retval(context, type, proc, info, valuep);
126}
127
128void
129fetch_arg_done(struct fetch_context *context)
130{
131 return arch_fetch_arg_done(context);
132}