Skip to content

Commit

Permalink
Move base modules as root, misc changes, prep rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Nov 7, 2024
1 parent c9edab3 commit 7b70d76
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 78 deletions.
23 changes: 6 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Aliceserver is implemented using an Object-Oriented Programming model.
The debugger server provides types and structures that the adapters and
debuggers must interpret.

Aliceserver does not yet support multi-session.

## Transports

Each transport classes inherit `transport.base.ITransport`.
Expand Down Expand Up @@ -94,22 +96,13 @@ This chapter reuses terminology from DAP, such as _Integer_ meaning, strictly
speaking, a 32-bit integer number (`int`), and _Number_ meaning a 64-bit
double-precision floating-point number (IEEE 754 `double`).

DAP is capable of initiating multiple debugging sessions, also known as a
multi-session configuration

Aliceserver does not yet support multi-session.

### Connection Details

By default, single-session mode is used. A client may request to initiate a new
debugging session by emiting the `startDebugging` request, which turns the server
configuration into a multi-session mode. Request management is performed by clients
tracking request IDs themselves.

In either modes, the client spawns the server and uses the standard streams (stdio)
to communicate with the server.
DAP has two connection models: Single-session and multi-session.
- Single-session: Using standard I/O (stdio), a single adapter instance is started.
- Multi-session: Using TCP/IP, every new connection initiates a new adapter instance.

Messages are encoded as HTTP messages.
Messages are encoded as HTTP messages using the UTF-8 encoding.

Currently, there is only one header field, `Content-Length`, that determines the
length of the message (payload). This field is read as an Integer.
Expand Down Expand Up @@ -137,8 +130,6 @@ Both client and server maintain their own sequence number, starting at 1.
NOTE: lldb-vscode starts their seq number at 0, while not as per specification,
it poses no difference to its usage.

Multi-session mode is not currently supported.

### Supported Requests

Implementation-specific details:
Expand Down Expand Up @@ -220,8 +211,6 @@ Command support:
[Machine Interface](https://sourceware.org/gdb/current/onlinedocs/gdb.html/GDB_002fMI.html)
is a line-oriented protocol introduced in GDB 5.1.

To my knowledge, MI is not capable of multi-session.

### Connection Details

In a typical setting, MI uses the standard streams to communicate with the child
Expand Down
12 changes: 4 additions & 8 deletions source/adapter/dap.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ import std.json;
import std.string : chompPrefix;
import std.conv : text;
import std.utf : validate;
import adapter.base, adapter.types;
import adapters, types, debuggers;
import util.json;
import ddlogger;

// TODO: Block requests until initialize request and response
// And initialize can only been sent once

// NOTE: DAP notes
// - Client only sends Requests.
// - Server responses to requests with Reponses or Errors.
Expand All @@ -34,13 +37,6 @@ import ddlogger;
// server> (Optional) Replies configurationDone
// client> Sends an attach or spawn request

// NOTE: Multi-session
//
// It is possible to have a "newSession" request type from a DAP
// "StartDebuggingRequest" request.
// Then, server can call something like "addSession" once it supports
// multi-sessions.

private
string eventStoppedReasonString(AdapterEventStoppedReason reason)
{
Expand Down
55 changes: 46 additions & 9 deletions source/adapter/mi.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
/// License: BSD-3-Clause-Clear
module adapter.mi;

import adapter.base, adapter.types;
import adapters, types;
import debuggers : IDebugger;
import config;
import logging;
import server : AdapterType, targetExec, targetExecArgs;
Expand Down Expand Up @@ -126,7 +127,7 @@ unittest
final class MIAdapter : Adapter
{
private enum {
RETURN, /// Request is ready to be returned
SEND, /// Request is ready to be returned
SKIP, /// Skip request
}

Expand Down Expand Up @@ -171,20 +172,20 @@ final class MIAdapter : Adapter
commands["exec"] =
(string[] args) {
request.type = AdapterRequestType.run;
return RETURN;
return SEND;
};
// Resume process execution from a stopped state.
commands["exec-continue"] =
commands["continue"] =
(string[] args) {
request.type = AdapterRequestType.continue_;
return RETURN;
return SEND;
};
// Terminate process.
commands["exec-abort"] =
(string[] args) {
request.type = AdapterRequestType.terminate;
return RETURN;
return SEND;
};
// attach PID
// Attach debugger to process by its ID.
Expand All @@ -207,7 +208,7 @@ final class MIAdapter : Adapter

request.type = AdapterRequestType.attach;
request.attachOptions.run = true;
return RETURN;
return SEND;
};
// -gdb-detach [ pid | gid ]
// Detach debugger from process, keeping its execution alive.
Expand All @@ -216,14 +217,14 @@ final class MIAdapter : Adapter
commands["detach"] =
(string[] args) {
request.type = AdapterRequestType.detach;
return RETURN;
return SEND;
};
// -target-disconnect
// Disconnect from remote target.
commands["target-disconnect"] =
(string[] args) {
request.type = AdapterRequestType.detach;
return RETURN;
return SEND;
};
// target TYPE [OPTIONS]
// Set target parameters.
Expand Down Expand Up @@ -296,6 +297,42 @@ final class MIAdapter : Adapter
reply(AdapterReply());
return SKIP;
};
// -thread-info [TID]
// Get a list of thread and information associated with each thread.
// Or only a single thread.
// Example:
// -thread-info
// ^done,threads=[
// {id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
// frame={level="0",addr="0xffffe410",func="__kernel_vsyscall",
// args=[]},state="running"},
// {id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
// frame={level="0",addr="0x0804891f",func="foo",
// args=[{name="i",value="10"}],
// file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"},
// state="running"}],
// current-thread-id="1"
// https://sourceware.org/gdb/current/onlinedocs/gdb.html/GDB_002fMI-Thread-Information.html
// Thread Information:
// - id: The global numeric id assigned to the thread by GDB.
// - target-id: The target-specific string identifying the thread.
// - details: Additional information about the thread provided by the target.
// It is supposed to be human-readable and not interpreted by the frontend.
// This field is optional.
// - name: The name of the thread.
// If the user specified a name using the thread name command, then
// this name is given. Otherwise, if GDB can extract the thread name
// from the target, then that name is given. If GDB cannot find the
// thread name, then this field is omitted.
// - state: The execution state of the thread, either ‘stopped’ or ‘running’,
// depending on whether the thread is presently running.
// - frame: Frame information
// - core: The value of this field is an integer number of the processor
// core the thread was last seen on. This field is optional.
commands["thread-info"] =
(string[] args) {
assert(false, "todo");
};
// show [INFO]
// Show information about session.
// Without an argument, GDB shows everything as stream output and
Expand Down Expand Up @@ -366,7 +403,7 @@ final class MIAdapter : Adapter
// NOTE: gdb-mi when attached does not terminate.
// Therefore, the preference is not to terminate.
request.closeOptions.terminate = false;
return RETURN;
return SEND;
};

send(gdbPrompt); // Ready!
Expand Down
3 changes: 0 additions & 3 deletions source/adapter/package.d

This file was deleted.

8 changes: 4 additions & 4 deletions source/adapter/base.d → source/adapters.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
/// Authors: dd86k <[email protected]>
/// Copyright: dd86k <[email protected]>
/// License: BSD-3-Clause-Clear
module adapter.base;
module adapters;

public import transport.base : ITransport;
import adapter.types;
public import transports : ITransport;
import types;
import debuggers;
import core.thread : Thread;
import std.datetime : Duration, dur;
import ddlogger;
Expand All @@ -18,7 +19,6 @@ abstract class Adapter
{
this(ITransport t)
{
assert(t);
transport = t;
}

Expand Down
4 changes: 2 additions & 2 deletions source/debugger/alicedbg.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module debugger.alicedbg;

import std.string : toStringz, fromStringz;
import logging;
import debugger.base;
import adapter.types;
import debuggers;
import types;
import adbg.debugger;
import adbg.process.exception;
import adbg.process.frame;
Expand Down
8 changes: 0 additions & 8 deletions source/debugger/package.d

This file was deleted.

11 changes: 9 additions & 2 deletions source/debugger/base.d → source/debuggers.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
/// Authors: dd86k <[email protected]>
/// Copyright: dd86k <[email protected]>
/// License: BSD-3-Clause-Clear
module debugger.base;
module debuggers;

import adapter.types : AdapterEvent;
import types;

struct ThreadInfo
{
int id;
string name;
}

struct FrameInfo
{
ulong address;
string functionName;
int line;
}

interface IDebugger
{
/// Launch a new process with the debugger.
Expand Down
18 changes: 12 additions & 6 deletions source/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import std.stdio;
import std.getopt;
import core.stdc.stdlib : exit;
import config, server, logging;
import adapter, debugger, transport;
import adapters, adapter.mi, adapter.dap;
import transports, transport.stdio, transport.httpstdio;
import debuggers, debugger.alicedbg;
import adbg.platform : ADBG_VERSION;

// TODO: Attach available adapter types
Expand Down Expand Up @@ -39,21 +41,25 @@ void main(string[] args)
GetoptResult gres = void;
try
{
//TODO: --list-capabilities: List DAP or GDB/MI capabilities
// TODO: --list-capabilities: List DAP or GDB/MI capabilities
// TODO: --tcp-port=NUMBER
gres = getopt(args,
"a|adapter",`Set adapter to use`, (string _, string value) {
switch (value) {
case "dap":
osettings.adapterType = AdapterType.dap;
osettings.adapter.type = AdapterType.dap;
break;
case "mi":
osettings.adapterType = AdapterType.mi;
osettings.adapter.type = AdapterType.mi;
break;
default:
write("Invalid adapter. Available adapters listed below.\n\n");
cliListAdapters();
}
},
/*"d|debugger",``, (string _, string value) {
},*/
"list-adapters", `List available adapters`, &cliListAdapters,
"log", `Logger: Enable logging to stderr`, &osettings.logStderr,
"logfile", `Logger: Enable logging to file path`, &osettings.logFile,
Expand Down Expand Up @@ -106,12 +112,12 @@ void main(string[] args)

// Select main adapter with transport
Adapter adapter = void;
final switch (osettings.adapterType) with (AdapterType) {
final switch (osettings.adapter.type) with (AdapterType) {
case dap:
adapter = new DAPAdapter(new HTTPStdioTransport());
break;
case mi, mi2, mi3, mi4:
adapter = new MIAdapter(new StdioTransport(), miVersion(osettings.adapterType));
adapter = new MIAdapter(new StdioTransport(), miVersion(osettings.adapter.type));
break;
}

Expand Down
Loading

0 comments on commit 7b70d76

Please sign in to comment.