MFC: Enable use of 'tid' for remote targets and use gdb_thread_select()
for 'tid' and 'proc' so they provide UI feedback like the 'thread' command.
This commit is contained in:
parent
048580c5d3
commit
3ba2c57e11
@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <kvm.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <defs.h>
|
||||
#include <frame-unwind.h>
|
||||
@ -212,17 +213,20 @@ kgdb_thr_select(struct kthr *kt)
|
||||
char *
|
||||
kgdb_thr_extra_thread_info(int tid)
|
||||
{
|
||||
char comm[MAXCOMLEN + 1];
|
||||
struct kthr *kt;
|
||||
struct proc *p;
|
||||
static char comm[MAXCOMLEN + 1];
|
||||
static char buf[64];
|
||||
|
||||
kt = kgdb_thr_lookup_tid(tid);
|
||||
if (kt == NULL)
|
||||
return (NULL);
|
||||
return (NULL);
|
||||
snprintf(buf, sizeof(buf), "PID=%d", kt->pid);
|
||||
p = (struct proc *)kt->paddr;
|
||||
if (kvm_read(kvm, (uintptr_t)&p->p_comm[0], &comm, sizeof(comm)) !=
|
||||
sizeof(comm))
|
||||
return (NULL);
|
||||
|
||||
return (comm);
|
||||
return (buf);
|
||||
strlcat(buf, ": ", sizeof(buf));
|
||||
strlcat(buf, comm, sizeof(buf));
|
||||
return (buf);
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <command.h>
|
||||
#include <exec.h>
|
||||
#include <frame-unwind.h>
|
||||
#include <gdb.h>
|
||||
#include <gdbcore.h>
|
||||
#include <gdbthread.h>
|
||||
#include <inferior.h>
|
||||
@ -48,6 +49,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <regcache.h>
|
||||
#include <solib.h>
|
||||
#include <target.h>
|
||||
#include <ui-out.h>
|
||||
|
||||
#include "kgdb.h"
|
||||
|
||||
@ -125,11 +127,11 @@ kgdb_trgt_open(char *filename, int from_tty)
|
||||
init_thread_list();
|
||||
kt = kgdb_thr_init();
|
||||
while (kt != NULL) {
|
||||
ti = add_thread(ptid_build(kt->pid, 0, kt->tid));
|
||||
ti = add_thread(pid_to_ptid(kt->tid));
|
||||
kt = kgdb_thr_next(kt);
|
||||
}
|
||||
if (curkthr != 0)
|
||||
inferior_ptid = ptid_build(curkthr->pid, 0, curkthr->tid);
|
||||
inferior_ptid = pid_to_ptid(curkthr->tid);
|
||||
|
||||
if (ontop) {
|
||||
/* XXX: fetch registers? */
|
||||
@ -187,14 +189,8 @@ kgdb_trgt_detach(char *args, int from_tty)
|
||||
static char *
|
||||
kgdb_trgt_extra_thread_info(struct thread_info *ti)
|
||||
{
|
||||
static char buf[64];
|
||||
char *p, *s;
|
||||
|
||||
p = buf + snprintf(buf, sizeof(buf), "PID=%d", ptid_get_pid(ti->ptid));
|
||||
s = kgdb_thr_extra_thread_info(ptid_get_tid(ti->ptid));
|
||||
if (s != NULL)
|
||||
snprintf(p, sizeof(buf) - (p - buf), ": %s", s);
|
||||
return (buf);
|
||||
return (kgdb_thr_extra_thread_info(ptid_get_pid(ti->ptid)));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -224,14 +220,14 @@ kgdb_trgt_pid_to_str(ptid_t ptid)
|
||||
{
|
||||
static char buf[33];
|
||||
|
||||
snprintf(buf, sizeof(buf), "Thread %ld", ptid_get_tid(ptid));
|
||||
snprintf(buf, sizeof(buf), "Thread %d", ptid_get_pid(ptid));
|
||||
return (buf);
|
||||
}
|
||||
|
||||
static int
|
||||
kgdb_trgt_thread_alive(ptid_t ptid)
|
||||
{
|
||||
return (kgdb_thr_lookup_tid(ptid_get_tid(ptid)) != NULL);
|
||||
return (kgdb_thr_lookup_tid(ptid_get_pid(ptid)) != NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -260,16 +256,16 @@ kgdb_trgt_ignore_breakpoints(CORE_ADDR addr, char *contents)
|
||||
}
|
||||
|
||||
static void
|
||||
kgdb_switch_to_thread(struct kthr *thr)
|
||||
kgdb_switch_to_thread(int tid)
|
||||
{
|
||||
if (thr->tid == ptid_get_tid(inferior_ptid))
|
||||
return;
|
||||
char buf[16];
|
||||
int thread_id;
|
||||
|
||||
inferior_ptid = ptid_build(thr->pid, 0, thr->tid);
|
||||
flush_cached_frames ();
|
||||
registers_changed ();
|
||||
stop_pc = read_pc ();
|
||||
select_frame (get_current_frame ());
|
||||
thread_id = pid_to_thread_id(pid_to_ptid(tid));
|
||||
if (thread_id == 0)
|
||||
error ("invalid tid");
|
||||
snprintf(buf, sizeof(buf), "%d", thread_id);
|
||||
gdb_thread_select(uiout, buf);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -282,7 +278,7 @@ kgdb_set_proc_cmd (char *arg, int from_tty)
|
||||
error_no_arg ("proc address for the new context");
|
||||
|
||||
if (kvm == NULL)
|
||||
error ("no kernel core file");
|
||||
error ("only supported for core file target");
|
||||
|
||||
addr = (CORE_ADDR) parse_and_eval_address (arg);
|
||||
|
||||
@ -295,7 +291,7 @@ kgdb_set_proc_cmd (char *arg, int from_tty)
|
||||
if (thr == NULL)
|
||||
error("invalid proc address");
|
||||
}
|
||||
kgdb_switch_to_thread(thr);
|
||||
kgdb_switch_to_thread(thr->tid);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -307,21 +303,15 @@ kgdb_set_tid_cmd (char *arg, int from_tty)
|
||||
if (!arg)
|
||||
error_no_arg ("TID or thread address for the new context");
|
||||
|
||||
if (kvm == NULL)
|
||||
error ("no kernel core file");
|
||||
|
||||
addr = (CORE_ADDR) parse_and_eval_address (arg);
|
||||
|
||||
if (!INKERNEL (addr)) {
|
||||
thr = kgdb_thr_lookup_tid((int)addr);
|
||||
if (thr == NULL)
|
||||
error ("invalid TID");
|
||||
} else {
|
||||
if (kvm != NULL && INKERNEL (addr)) {
|
||||
thr = kgdb_thr_lookup_taddr(addr);
|
||||
if (thr == NULL)
|
||||
error("invalid thread address");
|
||||
addr = thr->tid;
|
||||
}
|
||||
kgdb_switch_to_thread(thr);
|
||||
kgdb_switch_to_thread(addr);
|
||||
}
|
||||
|
||||
int fbsdcoreops_suppress_target = 1;
|
||||
|
@ -50,7 +50,7 @@ kgdb_trgt_fetch_registers(int regno __unused)
|
||||
struct kthr *kt;
|
||||
struct pcb pcb;
|
||||
|
||||
kt = kgdb_thr_lookup_tid(ptid_get_tid(inferior_ptid));
|
||||
kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid));
|
||||
if (kt == NULL)
|
||||
return;
|
||||
if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) {
|
||||
|
@ -50,7 +50,7 @@ kgdb_trgt_fetch_registers(int regno __unused)
|
||||
struct kthr *kt;
|
||||
struct pcb pcb;
|
||||
|
||||
kt = kgdb_thr_lookup_tid(ptid_get_tid(inferior_ptid));
|
||||
kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid));
|
||||
if (kt == NULL)
|
||||
return;
|
||||
if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) {
|
||||
|
@ -55,7 +55,7 @@ kgdb_trgt_fetch_registers(int regno __unused)
|
||||
struct pcb pcb;
|
||||
int i, reg;
|
||||
|
||||
kt = kgdb_thr_lookup_tid(ptid_get_tid(inferior_ptid));
|
||||
kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid));
|
||||
if (kt == NULL)
|
||||
return;
|
||||
if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) {
|
||||
|
@ -53,7 +53,7 @@ kgdb_trgt_fetch_registers(int regno __unused)
|
||||
struct kthr *kt;
|
||||
struct pcb pcb;
|
||||
|
||||
kt = kgdb_thr_lookup_tid(ptid_get_tid(inferior_ptid));
|
||||
kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid));
|
||||
if (kt == NULL)
|
||||
return;
|
||||
if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) {
|
||||
@ -118,7 +118,7 @@ kgdb_trgt_fetch_tss(void)
|
||||
struct segment_descriptor sd;
|
||||
uintptr_t addr, cpu0prvpage, tss;
|
||||
|
||||
kt = kgdb_thr_lookup_tid(ptid_get_tid(inferior_ptid));
|
||||
kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid));
|
||||
if (kt == NULL || kt->cpu == NOCPU)
|
||||
return (0);
|
||||
|
||||
|
@ -52,7 +52,7 @@ kgdb_trgt_fetch_registers(int regno __unused)
|
||||
struct pcb pcb;
|
||||
uint64_t r;
|
||||
|
||||
kt = kgdb_thr_lookup_tid(ptid_get_tid(inferior_ptid));
|
||||
kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid));
|
||||
if (kt == NULL)
|
||||
return;
|
||||
if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) {
|
||||
|
@ -52,7 +52,7 @@ kgdb_trgt_fetch_registers(int regno __unused)
|
||||
struct kthr *kt;
|
||||
struct pcb pcb;
|
||||
|
||||
kt = kgdb_thr_lookup_tid(ptid_get_tid(inferior_ptid));
|
||||
kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid));
|
||||
if (kt == NULL)
|
||||
return;
|
||||
if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user