Skip to content

Commit 0820a07

Browse files
rth7680stsquad
authored andcommitted
gdbstub: Adjust gdb_do_syscall to only use uint32_t and uint64_t
Pass %x as uint32_t and %lx as uint64_t; pass the address of %s as uint64_t and the length as uint32_t. Add casts in semihosting/syscalls.c from target_ulong to uint64_t; add casts from int to uint32_t for clarity. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20230303025805.625589-28-richard.henderson@linaro.org>
1 parent 2f70f2d commit 0820a07

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

gdbstub/syscalls.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...)
110110
*(p++) = 'F';
111111
while (*fmt) {
112112
if (*fmt == '%') {
113-
target_ulong addr;
114113
uint64_t i64;
114+
uint32_t i32;
115115

116116
fmt++;
117117
switch (*fmt++) {
118118
case 'x':
119-
addr = va_arg(va, target_ulong);
120-
p += snprintf(p, p_end - p, TARGET_FMT_lx, addr);
119+
i32 = va_arg(va, uint32_t);
120+
p += snprintf(p, p_end - p, "%" PRIx32, i32);
121121
break;
122122
case 'l':
123123
if (*(fmt++) != 'x') {
@@ -127,9 +127,9 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...)
127127
p += snprintf(p, p_end - p, "%" PRIx64, i64);
128128
break;
129129
case 's':
130-
addr = va_arg(va, target_ulong);
131-
p += snprintf(p, p_end - p, TARGET_FMT_lx "/%x",
132-
addr, va_arg(va, int));
130+
i64 = va_arg(va, uint64_t);
131+
i32 = va_arg(va, uint32_t);
132+
p += snprintf(p, p_end - p, "%" PRIx64 "/%x" PRIx32, i64, i32);
133133
break;
134134
default:
135135
bad_format:

semihosting/syscalls.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,46 +139,48 @@ static void gdb_open(CPUState *cs, gdb_syscall_complete_cb complete,
139139

140140
gdb_open_complete = complete;
141141
gdb_do_syscall(gdb_open_cb, "open,%s,%x,%x",
142-
fname, len, (target_ulong)gdb_flags, (target_ulong)mode);
142+
(uint64_t)fname, (uint32_t)len,
143+
(uint32_t)gdb_flags, (uint32_t)mode);
143144
}
144145

145146
static void gdb_close(CPUState *cs, gdb_syscall_complete_cb complete,
146147
GuestFD *gf)
147148
{
148-
gdb_do_syscall(complete, "close,%x", (target_ulong)gf->hostfd);
149+
gdb_do_syscall(complete, "close,%x", (uint32_t)gf->hostfd);
149150
}
150151

151152
static void gdb_read(CPUState *cs, gdb_syscall_complete_cb complete,
152153
GuestFD *gf, target_ulong buf, target_ulong len)
153154
{
154-
gdb_do_syscall(complete, "read,%x,%x,%x",
155-
(target_ulong)gf->hostfd, buf, len);
155+
gdb_do_syscall(complete, "read,%x,%lx,%lx",
156+
(uint32_t)gf->hostfd, (uint64_t)buf, (uint64_t)len);
156157
}
157158

158159
static void gdb_write(CPUState *cs, gdb_syscall_complete_cb complete,
159160
GuestFD *gf, target_ulong buf, target_ulong len)
160161
{
161-
gdb_do_syscall(complete, "write,%x,%x,%x",
162-
(target_ulong)gf->hostfd, buf, len);
162+
gdb_do_syscall(complete, "write,%x,%lx,%lx",
163+
(uint32_t)gf->hostfd, (uint64_t)buf, (uint64_t)len);
163164
}
164165

165166
static void gdb_lseek(CPUState *cs, gdb_syscall_complete_cb complete,
166167
GuestFD *gf, int64_t off, int gdb_whence)
167168
{
168169
gdb_do_syscall(complete, "lseek,%x,%lx,%x",
169-
(target_ulong)gf->hostfd, off, (target_ulong)gdb_whence);
170+
(uint32_t)gf->hostfd, off, (uint32_t)gdb_whence);
170171
}
171172

172173
static void gdb_isatty(CPUState *cs, gdb_syscall_complete_cb complete,
173174
GuestFD *gf)
174175
{
175-
gdb_do_syscall(complete, "isatty,%x", (target_ulong)gf->hostfd);
176+
gdb_do_syscall(complete, "isatty,%x", (uint32_t)gf->hostfd);
176177
}
177178

178179
static void gdb_fstat(CPUState *cs, gdb_syscall_complete_cb complete,
179180
GuestFD *gf, target_ulong addr)
180181
{
181-
gdb_do_syscall(complete, "fstat,%x,%x", (target_ulong)gf->hostfd, addr);
182+
gdb_do_syscall(complete, "fstat,%x,%lx",
183+
(uint32_t)gf->hostfd, (uint64_t)addr);
182184
}
183185

184186
static void gdb_stat(CPUState *cs, gdb_syscall_complete_cb complete,
@@ -191,7 +193,8 @@ static void gdb_stat(CPUState *cs, gdb_syscall_complete_cb complete,
191193
return;
192194
}
193195

194-
gdb_do_syscall(complete, "stat,%s,%x", fname, len, addr);
196+
gdb_do_syscall(complete, "stat,%s,%lx",
197+
(uint64_t)fname, (uint32_t)len, (uint64_t)addr);
195198
}
196199

197200
static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete,
@@ -203,7 +206,7 @@ static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete,
203206
return;
204207
}
205208

206-
gdb_do_syscall(complete, "unlink,%s", fname, len);
209+
gdb_do_syscall(complete, "unlink,%s", (uint64_t)fname, (uint32_t)len);
207210
}
208211

209212
static void gdb_rename(CPUState *cs, gdb_syscall_complete_cb complete,
@@ -223,7 +226,9 @@ static void gdb_rename(CPUState *cs, gdb_syscall_complete_cb complete,
223226
return;
224227
}
225228

226-
gdb_do_syscall(complete, "rename,%s,%s", oname, olen, nname, nlen);
229+
gdb_do_syscall(complete, "rename,%s,%s",
230+
(uint64_t)oname, (uint32_t)olen,
231+
(uint64_t)nname, (uint32_t)nlen);
227232
}
228233

229234
static void gdb_system(CPUState *cs, gdb_syscall_complete_cb complete,
@@ -235,13 +240,14 @@ static void gdb_system(CPUState *cs, gdb_syscall_complete_cb complete,
235240
return;
236241
}
237242

238-
gdb_do_syscall(complete, "system,%s", cmd, len);
243+
gdb_do_syscall(complete, "system,%s", (uint64_t)cmd, (uint32_t)len);
239244
}
240245

241246
static void gdb_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete,
242247
target_ulong tv_addr, target_ulong tz_addr)
243248
{
244-
gdb_do_syscall(complete, "gettimeofday,%x,%x", tv_addr, tz_addr);
249+
gdb_do_syscall(complete, "gettimeofday,%lx,%lx",
250+
(uint64_t)tv_addr, (uint64_t)tz_addr);
245251
}
246252

247253
/*

0 commit comments

Comments
 (0)