File: fetch.c

package info (click to toggle)
ltrace 0.7.3-4
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,908 kB
  • ctags: 2,421
  • sloc: ansic: 22,862; sh: 10,956; exp: 1,498; makefile: 375; cpp: 196; awk: 88; asm: 40; perl: 24
file content (166 lines) | stat: -rw-r--r-- 4,272 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 * This file is part of ltrace.
 * Copyright (C) 2011,2012 Petr Machata, Red Hat Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */

#include <stdlib.h>
#include <string.h>

#include "fetch.h"
#include "sysdep.h"
#include "value.h"
#include "type.h"

#ifdef ARCH_HAVE_FETCH_ARG
struct fetch_context *arch_fetch_arg_init(enum tof type, struct Process *proc,
					  struct arg_type_info *ret_info);

struct fetch_context *arch_fetch_arg_clone(struct Process *proc,
					   struct fetch_context *context);

int arch_fetch_arg_next(struct fetch_context *ctx, enum tof type,
			struct Process *proc, struct arg_type_info *info,
			struct value *valuep);

int arch_fetch_retval(struct fetch_context *ctx, enum tof type,
		      struct Process *proc, struct arg_type_info *info,
		      struct value *valuep);

void arch_fetch_arg_done(struct fetch_context *context);

# ifdef ARCH_HAVE_FETCH_PACK
int arch_fetch_param_pack_start(struct fetch_context *context,
				enum param_pack_flavor ppflavor);

void arch_fetch_param_pack_end(struct fetch_context *context);
# endif

#else
/* Fall back to gimme_arg.  */

long gimme_arg(enum tof type, struct Process *proc, int arg_num,
	       struct arg_type_info *info);

struct fetch_context {
	int argnum;
};

struct fetch_context *
arch_fetch_arg_init(enum tof type, struct Process *proc,
		    struct arg_type_info *ret_info)
{
	return calloc(sizeof(struct fetch_context), 1);
}

struct fetch_context *
arch_fetch_arg_clone(struct Process *proc, struct fetch_context *context)
{
	struct fetch_context *ret = malloc(sizeof(*ret));
	if (ret == NULL)
		return NULL;
	return memcpy(ret, context, sizeof(*ret));
}

int
arch_fetch_arg_next(struct fetch_context *context, enum tof type,
		    struct Process *proc,
		    struct arg_type_info *info, struct value *valuep)
{
	long l = gimme_arg(type, proc, context->argnum++, info);
	value_set_word(valuep, l);
	return 0;
}

int
arch_fetch_retval(struct fetch_context *context, enum tof type,
		  struct Process *proc,
		  struct arg_type_info *info, struct value *valuep)
{
	long l = gimme_arg(type, proc, -1, info);
	value_set_word(valuep, l);
	return 0;
}

void
arch_fetch_arg_done(struct fetch_context *context)
{
	free(context);
}
#endif

#if !defined(ARCH_HAVE_FETCH_ARG) || !defined(ARCH_HAVE_FETCH_PACK)
int
arch_fetch_param_pack_start(struct fetch_context *context,
			    enum param_pack_flavor ppflavor)
{
	return 0;
}

void
arch_fetch_param_pack_end(struct fetch_context *context)
{
}
#endif

struct fetch_context *
fetch_arg_init(enum tof type, struct Process *proc,
	       struct arg_type_info *ret_info)
{
	return arch_fetch_arg_init(type, proc, ret_info);
}

struct fetch_context *
fetch_arg_clone(struct Process *proc, struct fetch_context *context)
{
	return arch_fetch_arg_clone(proc, context);
}

int
fetch_arg_next(struct fetch_context *context, enum tof type,
	       struct Process *proc,
	       struct arg_type_info *info, struct value *valuep)
{
	return arch_fetch_arg_next(context, type, proc, info, valuep);
}

int
fetch_retval(struct fetch_context *context, enum tof type,
	     struct Process *proc,
	     struct arg_type_info *info, struct value *valuep)
{
	return arch_fetch_retval(context, type, proc, info, valuep);
}

void
fetch_arg_done(struct fetch_context *context)
{
	return arch_fetch_arg_done(context);
}

int
fetch_param_pack_start(struct fetch_context *context,
		       enum param_pack_flavor ppflavor)
{
	return arch_fetch_param_pack_start(context, ppflavor);
}

void
fetch_param_pack_end(struct fetch_context *context)
{
	return arch_fetch_param_pack_end(context);
}