From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V18pq-0006Ju-K5 for qemu-devel@nongnu.org; Mon, 22 Jul 2013 01:39:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V18by-0005ev-GN for qemu-devel@nongnu.org; Mon, 22 Jul 2013 01:24:44 -0400 Received: from mail-lb0-x22c.google.com ([2a00:1450:4010:c04::22c]:43435) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V18by-0005eb-6f for qemu-devel@nongnu.org; Mon, 22 Jul 2013 01:24:42 -0400 Received: by mail-lb0-f172.google.com with SMTP id v20so4954829lbc.3 for ; Sun, 21 Jul 2013 22:24:41 -0700 (PDT) From: Max Filippov Date: Mon, 22 Jul 2013 09:24:27 +0400 Message-Id: <1374470667-14586-1-git-send-email-jcmvbkbc@gmail.com> Subject: [Qemu-devel] [PATCH] gdbstub: fix sThreadInfo handler List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Max Filippov After the commit 182735e cpu: Make first_cpu and next_cpu CPUState we can no longer blindly use cpu->next_cpu->env_ptr to get CPUArchState of the next CPU, as the next_cpu is NULL in the last CPU. This fixes segfault caused by gdb command 'info threads'. Signed-off-by: Max Filippov --- gdbstub.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 0ee82a9..deb8159 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -2406,10 +2406,11 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) } else if (strcmp(p,"sThreadInfo") == 0) { report_cpuinfo: if (s->query_cpu) { + CPUState *cpu = ENV_GET_CPU(s->query_cpu); snprintf(buf, sizeof(buf), "m%x", - cpu_index(ENV_GET_CPU(s->query_cpu))); + cpu_index(cpu)); put_packet(s, buf); - s->query_cpu = ENV_GET_CPU(s->query_cpu)->next_cpu->env_ptr; + s->query_cpu = cpu->next_cpu ? cpu->next_cpu->env_ptr : NULL; } else put_packet(s, "l"); break; -- 1.7.7.6