Skip to content

Commit

Permalink
原样输出sdb
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraYolo committed Feb 6, 2024
1 parent 358c9d0 commit 2407263
Showing 1 changed file with 6 additions and 42 deletions.
48 changes: 6 additions & 42 deletions cloud-admin/SDB/WebSocketDebugger.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection DuplicatedCode */
<?php

/** @noinspection DuplicatedCode */

declare(strict_types=1);
/**
Expand Down Expand Up @@ -80,8 +82,6 @@ final class WebSocketDebugger extends Debugger

protected static ?SslConfig $sslConfig = null;

protected array $map = [];

final public function __construct()
{
parent::__construct();
Expand Down Expand Up @@ -185,6 +185,7 @@ public function start(): void
$this->setLastCommand($in);

// 思考如何处理goto的问题
// 2024-02-06 可以考虑原样输出到前端
_next:

try {
Expand All @@ -204,7 +205,6 @@ public function start(): void
switch ($command) {
case 'ps':
$this->showCoroutines(Coroutine::getAll());
$this->out(Json::encode($this->map));
break;
case 'attach':
case 'co':
Expand Down Expand Up @@ -285,9 +285,7 @@ public function start(): void

if (! $context->stopped) {
if ($context->stop) {
$this->waitStoppedCoroutine(
$coroutine,
);
$this->waitStoppedCoroutine($coroutine);
} else {
throw new DebuggerException('Not in debugging');
}
Expand All @@ -298,10 +296,7 @@ public function start(): void
case 'next':
case 's':
case 'step_in':
if (
$command === 'n'
|| $command === 'next'
) {
if ($command === 'n' || $command === 'next') {
$this->lastTraceDepth = $coroutine->getTraceDepth() - self::getCoroutineTraceDiffLevel($coroutine, 'nextCommand');
}

Expand Down Expand Up @@ -558,8 +553,6 @@ public function out(string $string = '', bool $newline = true): static
}

$this->socket->broadcastWebSocketFrame(Psr7::createWebSocketTextFrame(payloadData: $string));
//todo:map暂时恢复为空数组,减少bug
$this->map = [];

return $this;
}
Expand Down Expand Up @@ -588,33 +581,4 @@ public function detectActiveConnections(): void
sleep(20);
}
}

public function showCoroutines(array $coroutines): static
{
$map = [];
foreach ($coroutines as $coroutine) {
if ($coroutine === Coroutine::getCurrent()) {
continue;
}
$info = self::getSimpleInfoOfCoroutine($coroutine, true);
$info['source_position'] = $this->callSourcePositionHandler($info['source_position']);
$map[] = $info;
}

$this->map = $map;

return $this;
}

protected function showCoroutine(Coroutine $coroutine, bool $newLine = true): static
{
$debugInfo = self::getSimpleInfoOfCoroutine($coroutine, false);
$trace = $this::getTraceOfCoroutine($coroutine);
$this->table([$debugInfo], ! $trace);
if ($trace) {
$this->cr()->showTrace($trace, null, $newLine);
}

return $this;
}
}

0 comments on commit 2407263

Please sign in to comment.