Skip to content

Commit

Permalink
process: Simplify list functions, remove older functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Sep 17, 2024
1 parent ca40101 commit 2e9c3b7
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 434 deletions.
2 changes: 1 addition & 1 deletion common/errormgmt.d
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void crashed(adbg_process_t *proc, adbg_exception_t *ex) {
printf(
"Exception : %s\n"~
"PID : %d\n",
adbg_exception_name(ex), adbg_process_get_pid(proc));
adbg_exception_name(ex), adbg_process_pid(proc));

//TODO: Get thread context

Expand Down
49 changes: 11 additions & 38 deletions debugger/shell.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import common.cli : opt_syntax;
import common.utils;
import term;

// Enable new process name, although it is currently broken on Windows
//version = UseNewProcessName

extern (C):

///
Expand Down Expand Up @@ -1091,48 +1088,24 @@ int command_rescan(int argc, const(char) **argv) {
}

int command_plist(int argc, const(char) **argv) {
// Disabled until adbg_process_get_name works on Windows
version (UseNewProcessName) {
size_t count = void;
int *plist = adbg_process_list(&count, 0);
if (plist == null)
void* proclist = adbg_process_list_new();
if (proclist == null)
return ShellError.alicedbg;

puts("PID Name");
enum BUFFERSIZE = 2048;
char[BUFFERSIZE] buffer = void;

version (Trace)
trace("count=%zd", count);

puts("PID Name");
foreach (int pid; plist[0..count]) {
printf("%10d ", pid);
if (adbg_process_get_name(pid, buffer.ptr, BUFFERSIZE, true)) {
puts(buffer.ptr);
continue;
}
if (adbg_process_get_name(pid, buffer.ptr, BUFFERSIZE, false)) {
puts(buffer.ptr);
adbg_process_t *proc = void;
for (size_t i; (proc = adbg_process_list_get(proclist, i)) != null; ++i) {
printf("%10d ", adbg_process_pid(proc));
if (adbg_process_path(proc, buffer.ptr, BUFFERSIZE)) {
version (Trace) trace("error: %s", adbg_error_message());
else putchar('\n');
continue;
}
version (Trace)
trace("error: %s", adbg_error_message());
putchar('\n');
puts(buffer.ptr);
}

free(plist);
} else {
adbg_process_list_t list = void;
if (adbg_process_enumerate(&list, 0)) {
return ShellError.alicedbg;
}

puts("PID Name");
foreach (adbg_process_t proc; list.processes[0..list.count]) {
printf("%10d %s\n", proc.pid, proc.name.ptr);
}
}

adbg_process_list_close(proclist);
return 0;
}

Expand Down
3 changes: 1 addition & 2 deletions src/adbg/error.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import adbg.include.capstone : csh, cs_errno, cs_strerror;
// adbg_ensure_params(lvalue, "name")
// - returns string if null found
// - automatically set error code
// adbg_oops_p(AdbgError, void*)
// - returns null
// adbg_oops_ptr(AdbgError, void*) to return null
//TODO: Localize error messages as option (including system ones, when able)

extern (C):
Expand Down
20 changes: 20 additions & 0 deletions src/adbg/include/windows/winbase.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// Extra definitions for winbase.h.
///
/// Authors: dd86k <dd@dax.moe>
/// Copyright: © dd86k <dd@dax.moe>
/// License: BSD-3-Clause-Clear
module adbg.include.windows.winbase;

version (Windows):

public import core.sys.windows.winbase;
public import core.sys.windows.winnt; // For types

// Vista and up
extern (Windows)
BOOL QueryFullProcessImageNameA(
HANDLE hProcess, // [in]
DWORD dwFlags, // [in]
LPSTR lpExeName, // [out]
PDWORD lpdwSize // [in, out
);
2 changes: 2 additions & 0 deletions src/adbg/include/windows/winnt.d
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ version (Windows):

public import core.sys.windows.winnt;

enum PROCESS_QUERY_LIMITED_INFORMATION = 0x1000;

align(16) struct M128A {
ulong Low;
long High;
Expand Down
Loading

0 comments on commit 2e9c3b7

Please sign in to comment.