blob: cbceefbff4fcc18dd3ac854973c31515dd95af8a [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"
Petr Machataa2e16c52012-09-21 23:46:24 +020025#include "sysdep.h"
Petr Machataf6ec08a2012-01-06 16:58:54 +010026#include "value.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
Petr Machata929bd572012-12-17 03:20:34 +010030struct fetch_context *arch_fetch_arg_init(enum tof type, struct process *proc,
Petr Machataf6ec08a2012-01-06 16:58:54 +010031 struct arg_type_info *ret_info);
32
Petr Machata929bd572012-12-17 03:20:34 +010033struct fetch_context *arch_fetch_arg_clone(struct process *proc,
Petr Machataf6ec08a2012-01-06 16:58:54 +010034 struct fetch_context *context);
35
36int arch_fetch_arg_next(struct fetch_context *ctx, enum tof type,
Petr Machata929bd572012-12-17 03:20:34 +010037 struct process *proc, struct arg_type_info *info,
Petr Machataf6ec08a2012-01-06 16:58:54 +010038 struct value *valuep);
39
40int arch_fetch_retval(struct fetch_context *ctx, enum tof type,
Petr Machata929bd572012-12-17 03:20:34 +010041 struct process *proc, struct arg_type_info *info,
Petr Machataf6ec08a2012-01-06 16:58:54 +010042 struct value *valuep);
43
44void arch_fetch_arg_done(struct fetch_context *context);
45
Petr Machatae36298a2012-09-13 17:12:41 +020046# ifdef ARCH_HAVE_FETCH_PACK
47int arch_fetch_param_pack_start(struct fetch_context *context,
48 enum param_pack_flavor ppflavor);
49
50void arch_fetch_param_pack_end(struct fetch_context *context);
51# endif
52
Petr Machataf6ec08a2012-01-06 16:58:54 +010053#else
54/* Fall back to gimme_arg. */
55
Petr Machata929bd572012-12-17 03:20:34 +010056long gimme_arg(enum tof type, struct process *proc, int arg_num,
Petr Machataf6ec08a2012-01-06 16:58:54 +010057 struct arg_type_info *info);
58
59struct fetch_context {
60 int argnum;
61};
62
63struct fetch_context *
Petr Machata929bd572012-12-17 03:20:34 +010064arch_fetch_arg_init(enum tof type, struct process *proc,
Petr Machataf6ec08a2012-01-06 16:58:54 +010065 struct arg_type_info *ret_info)
66{
67 return calloc(sizeof(struct fetch_context), 1);
68}
69
70struct fetch_context *
Petr Machata929bd572012-12-17 03:20:34 +010071arch_fetch_arg_clone(struct process *proc, struct fetch_context *context)
Petr Machataf6ec08a2012-01-06 16:58:54 +010072{
73 struct fetch_context *ret = malloc(sizeof(*ret));
74 if (ret == NULL)
75 return NULL;
76 return memcpy(ret, context, sizeof(*ret));
77}
78
79int
80arch_fetch_arg_next(struct fetch_context *context, enum tof type,
Petr Machata929bd572012-12-17 03:20:34 +010081 struct process *proc,
Petr Machataf6ec08a2012-01-06 16:58:54 +010082 struct arg_type_info *info, struct value *valuep)
83{
84 long l = gimme_arg(type, proc, context->argnum++, info);
Petr Machatada442f42012-05-04 02:22:09 +020085 value_set_word(valuep, l);
Petr Machataf6ec08a2012-01-06 16:58:54 +010086 return 0;
87}
88
89int
90arch_fetch_retval(struct fetch_context *context, enum tof type,
Petr Machata929bd572012-12-17 03:20:34 +010091 struct process *proc,
Petr Machataf6ec08a2012-01-06 16:58:54 +010092 struct arg_type_info *info, struct value *valuep)
93{
94 long l = gimme_arg(type, proc, -1, info);
Petr Machatada442f42012-05-04 02:22:09 +020095 value_set_word(valuep, l);
Petr Machataf6ec08a2012-01-06 16:58:54 +010096 return 0;
97}
98
99void
100arch_fetch_arg_done(struct fetch_context *context)
101{
102 free(context);
103}
104#endif
105
Petr Machatae36298a2012-09-13 17:12:41 +0200106#if !defined(ARCH_HAVE_FETCH_ARG) || !defined(ARCH_HAVE_FETCH_PACK)
107int
108arch_fetch_param_pack_start(struct fetch_context *context,
109 enum param_pack_flavor ppflavor)
110{
111 return 0;
112}
113
114void
115arch_fetch_param_pack_end(struct fetch_context *context)
116{
117}
118#endif
119
Petr Machataf6ec08a2012-01-06 16:58:54 +0100120struct fetch_context *
Petr Machata929bd572012-12-17 03:20:34 +0100121fetch_arg_init(enum tof type, struct process *proc,
Petr Machataf6ec08a2012-01-06 16:58:54 +0100122 struct arg_type_info *ret_info)
123{
124 return arch_fetch_arg_init(type, proc, ret_info);
125}
126
127struct fetch_context *
Petr Machata929bd572012-12-17 03:20:34 +0100128fetch_arg_clone(struct process *proc, struct fetch_context *context)
Petr Machataf6ec08a2012-01-06 16:58:54 +0100129{
130 return arch_fetch_arg_clone(proc, context);
131}
132
133int
134fetch_arg_next(struct fetch_context *context, enum tof type,
Petr Machata929bd572012-12-17 03:20:34 +0100135 struct process *proc,
Petr Machataf6ec08a2012-01-06 16:58:54 +0100136 struct arg_type_info *info, struct value *valuep)
137{
138 return arch_fetch_arg_next(context, type, proc, info, valuep);
139}
140
141int
142fetch_retval(struct fetch_context *context, enum tof type,
Petr Machata929bd572012-12-17 03:20:34 +0100143 struct process *proc,
Petr Machataf6ec08a2012-01-06 16:58:54 +0100144 struct arg_type_info *info, struct value *valuep)
145{
146 return arch_fetch_retval(context, type, proc, info, valuep);
147}
148
149void
150fetch_arg_done(struct fetch_context *context)
151{
152 return arch_fetch_arg_done(context);
153}
Petr Machatae36298a2012-09-13 17:12:41 +0200154
155int
156fetch_param_pack_start(struct fetch_context *context,
157 enum param_pack_flavor ppflavor)
158{
159 return arch_fetch_param_pack_start(context, ppflavor);
160}
161
162void
163fetch_param_pack_end(struct fetch_context *context)
164{
165 return arch_fetch_param_pack_end(context);
166}