Format array like objects.

This commit is contained in:
Deukhoofd 2021-10-03 10:52:29 +02:00
parent a1f3d3a1b8
commit 5f0ad86489
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
5 changed files with 42 additions and 1819 deletions

BIN
Heady

Binary file not shown.

View File

@ -1,24 +0,0 @@
import socket
import sys
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect the socket to the port where the server is listening
server_address = ('localhost', 8684)
print(sys.stderr, 'connecting to %s port %s' % server_address)
sock.connect(server_address)
def send(msg):
b = bytes(msg, "utf-8")
sock.send(bytes("Content-Length: " + str(len(b)) + "\r\n\r\n", "ascii"))
sock.send(b)
send('{"seq": 1, "type": "request", "command": "setBreakpoints", "arguments": {'
'"source": {"path": "TestScript"},'
'"breakpoints": [{ "line": 14} ]'
'} }')
while True:
msg = sock.recv(128)
print(msg.decode("utf-8"))

File diff suppressed because it is too large Load Diff

View File

@ -164,6 +164,23 @@ DebugAdapterProtocol::Variable ASVariableFormatter::GetAsDAPVariable(asIScriptEn
}
return DebugAdapterProtocol::Variable::FromPointer(name, typeData->GetName(), stringified, reference);
}
template <typename T, int (asIScriptContext::*SetArg)(asUINT, T), T (asIScriptContext::*GetLength)()>
void ASVariableFormatter::FormatArrayLike(std::vector<DebugAdapterProtocol::Variable>& vars, asIScriptEngine* engine,
asIScriptContext* ctx, void* address, AngelscriptDebugger* debugger,
asIScriptFunction* indexFunc) {
auto length = (ctx->*GetLength)();
for (T i = 0; i < length; ++i) {
assert(ctx->Prepare(indexFunc) >= 0);
ctx->SetObject(address);
(ctx->*SetArg)(0, i);
ctx->Execute();
auto name = std::to_string(i);
vars.push_back(GetAsDAPVariable(engine, ctx, debugger, name, indexFunc->GetReturnTypeId(),
ctx->GetAddressOfReturnValue()));
}
}
void ASVariableFormatter::GetChildDAPVariables(std::vector<DebugAdapterProtocol::Variable>& vars,
asIScriptEngine* engine, asIScriptContext* ctx,
AngelscriptDebugger* debugger, int type, void* address) {
@ -205,4 +222,25 @@ void ASVariableFormatter::GetChildDAPVariables(std::vector<DebugAdapterProtocol:
}
}
}
auto indexFunc = typeData->GetMethodByName("get_opIndex", true);
if (indexFunc != nullptr && indexFunc->GetParamCount() == 1) {
auto lengthFunc = typeData->GetMethodByName("get_Length", true);
int t;
indexFunc->GetParam(0, &t);
if (lengthFunc != nullptr && lengthFunc->GetParamCount() == 0 && lengthFunc->GetReturnTypeId() == t) {
assert(ctx->Prepare(lengthFunc) >= 0);
ctx->SetObject(address);
ctx->Execute();
if (t == asTYPEID_UINT64) {
FormatArrayLike<uint64_t, &asIScriptContext::SetArgQWord, &asIScriptContext::GetReturnQWord>(
vars, engine, ctx, address, debugger, indexFunc);
}
else if (t == asTYPEID_INT32){
FormatArrayLike<uint32_t, &asIScriptContext::SetArgDWord, &asIScriptContext::GetReturnDWord>(
vars, engine, ctx, address, debugger, indexFunc);
}
}
// vars.push_back(DebugAdapterProtocol::Variable("has_indexer", "true", "string", {}));
}
}

View File

@ -11,6 +11,10 @@ public:
static DebugAdapterProtocol::Variable GetAsDAPVariable(asIScriptEngine* engine, asIScriptContext* ctx,
AngelscriptDebugger* debugger, const std::string& name, int,
void*);
template <typename T, int (asIScriptContext::*SetArg)(asUINT, T), T (asIScriptContext::*GetLength)()>
static void FormatArrayLike(std::vector<DebugAdapterProtocol::Variable>& vars, asIScriptEngine* engine,
asIScriptContext* ctx, void* address, AngelscriptDebugger* debugger,
asIScriptFunction* indexFunc);
static void GetChildDAPVariables(std::vector<DebugAdapterProtocol::Variable>&, asIScriptEngine* engine,
asIScriptContext* ctx, AngelscriptDebugger* debugger, int, void*);
};