Skip to content

Commit

Permalink
thread: detach from process struct
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Oct 25, 2024
1 parent cd4af31 commit 22984ba
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 156 deletions.
14 changes: 6 additions & 8 deletions debugger/shell.d
Original file line number Diff line number Diff line change
Expand Up @@ -1134,15 +1134,16 @@ int command_thread(int argc, const(char) **argv) {
// then prompt can be (adbg [thread 12345])

adbg_thread_t *thread = void;
void *thrlist = adbg_thread_list_new(process);
if (thrlist == null)
return ShellError.alicedbg;
scope(exit) adbg_thread_list_close(thrlist);

const(char) *action = argv[1];
// thread list - get a list of threads
if (strcmp(action, "list") == 0) {
if (adbg_thread_list_update(process))
return ShellError.alicedbg;

printf("Threads:");
for (size_t i; (thread = adbg_thread_list_by_index(process, i)) != null; ++i) {
for (size_t i; (thread = adbg_thread_list_get(process, i)) != null; ++i) {
if (i) putchar(',');
printf(" %lld", adbg_thread_id(thread));
}
Expand All @@ -1155,15 +1156,12 @@ int command_thread(int argc, const(char) **argv) {
return ShellError.missingArgument;

// Select thread
thread = adbg_thread_list_by_id(process, atoi(argv[1]));
thread = adbg_thread_list_by_id(thrlist, atoi(argv[1]));
if (thread == null)
return ShellError.alicedbg;

action = argv[2];
if (strcmp(action, "registers") == 0 || strcmp(action, "regs") == 0) {
// Update its context
adbg_thread_context_update(process, thread);

int id;
adbg_register_t *register = void;
while ((register = adbg_register_by_id(thread, id++)) != null) {
Expand Down
24 changes: 13 additions & 11 deletions examples/simple.d
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,21 @@ void event_exception(adbg_process_t *proc, void *udata, adbg_exception_t *except
Ldone:
}

// If available, print register data
/*
adbg_thread_t *thread = adbg_thread_list_by_id(proc, tid);
if (thread && adbg_thread_context_update(proc, thread) == 0) {
int rid;
adbg_register_t *reg = void;
while ((reg = adbg_register_by_id(thread, rid++)) != null) {
char[20] hex = void;
adbg_register_format(hex.ptr, 20, reg, AdbgRegisterFormat.hex);
printf(` %s=0x%s`, adbg_register_name(reg), hex.ptr);
// If available, print register data for thread
void *thrlist = adbg_thread_list_new(proc);
if (thrlist) {
adbg_thread_t *thread = adbg_thread_list_by_id(thrlist, tid);
if (thread && adbg_thread_context_update(proc, thread) == 0) {
int rid;
adbg_register_t *reg = void;
while ((reg = adbg_register_by_id(thread, rid++)) != null) {
char[20] hex = void;
adbg_register_format(hex.ptr, 20, reg, AdbgRegisterFormat.hex);
printf(` %s=0x%s`, adbg_register_name(reg), hex.ptr);
}
}
adbg_thread_list_close(thrlist);
}
*/

putchar('\n');

Expand Down
7 changes: 2 additions & 5 deletions src/adbg/process/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ version (linux) {
AdbgProcessState state;
/// Process' creation source.
AdbgCreation creation;
/// List of threads.
list_t *thread_list;
/// List of breakpoints.
list_t *breakpoint_list;
// List of breakpoints.
//list_t *breakpoint_list;

// HACK: Debugger event handlers
void function(adbg_process_t*, void *udata, adbg_exception_t *ex) event_exception;
Expand All @@ -109,7 +107,6 @@ void adbg_process_free(adbg_process_t *proc) {
version (Posix) {
if (proc.orig_argv) free(proc.orig_argv);
}
adbg_list_free(proc.thread_list);
free(proc);
}

Expand Down
Loading

0 comments on commit 22984ba

Please sign in to comment.