Skip to content

Commit dc14a7a

Browse files
iii-istsquad
authored andcommitted
gdbstub: Report the actual qemu-user pid
Currently qemu-user reports pid 1 to GDB. Resolve the TODO and report the actual PID. Using getpid() relies on the assumption that there is only one GDBProcess. Add an assertion to make sure that future changes don't break it. Reviewed-by: Alex Bennée <[email protected]> Signed-off-by: Ilya Leoshkevich <[email protected]> Message-Id: <[email protected]> Signed-off-by: Alex Bennée <[email protected]> Message-Id: <[email protected]>
1 parent a3fcc11 commit dc14a7a

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

gdbstub/gdbstub.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,16 @@ void gdb_memtox(GString *buf, const char *mem, int len)
202202

203203
static uint32_t gdb_get_cpu_pid(CPUState *cpu)
204204
{
205-
/* TODO: In user mode, we should use the task state PID */
205+
#ifdef CONFIG_USER_ONLY
206+
return getpid();
207+
#else
206208
if (cpu->cluster_index == UNASSIGNED_CLUSTER_INDEX) {
207209
/* Return the default process' PID */
208210
int index = gdbserver_state.process_num - 1;
209211
return gdbserver_state.processes[index].pid;
210212
}
211213
return cpu->cluster_index + 1;
214+
#endif
212215
}
213216

214217
GDBProcess *gdb_get_process(uint32_t pid)
@@ -2137,19 +2140,25 @@ void gdb_read_byte(uint8_t ch)
21372140
void gdb_create_default_process(GDBState *s)
21382141
{
21392142
GDBProcess *process;
2140-
int max_pid = 0;
2143+
int pid;
21412144

2145+
#ifdef CONFIG_USER_ONLY
2146+
assert(gdbserver_state.process_num == 0);
2147+
pid = getpid();
2148+
#else
21422149
if (gdbserver_state.process_num) {
2143-
max_pid = s->processes[s->process_num - 1].pid;
2150+
pid = s->processes[s->process_num - 1].pid;
2151+
} else {
2152+
pid = 0;
21442153
}
2154+
/* We need an available PID slot for this process */
2155+
assert(pid < UINT32_MAX);
2156+
pid++;
2157+
#endif
21452158

21462159
s->processes = g_renew(GDBProcess, s->processes, ++s->process_num);
21472160
process = &s->processes[s->process_num - 1];
2148-
2149-
/* We need an available PID slot for this process */
2150-
assert(max_pid < UINT32_MAX);
2151-
2152-
process->pid = max_pid + 1;
2161+
process->pid = pid;
21532162
process->attached = false;
21542163
process->target_xml[0] = '\0';
21552164
}

0 commit comments

Comments
 (0)