mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 02:37:42 +00:00
LibCore+rpcdump: Publish CObject graph to on-demand RPC socket
All programs that have a CEventLoop now allow local socket connections via /tmp/rpc.PID and will dump a serialized JSON array of all the live CObjects in the program onto connecting sockets. Also added a small /bin/rpcdump tool that connects to an RPC socket and produces a raw dump of the JSON that comes out.
This commit is contained in:
parent
2fa2d72761
commit
1febd59f83
3 changed files with 77 additions and 1 deletions
42
Userland/rpcdump.cpp
Normal file
42
Userland/rpcdump.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include <LibCore/CEventLoop.h>
|
||||
#include <LibCore/CLocalSocket.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
printf("usage: %s <pid>\n", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CEventLoop loop;
|
||||
|
||||
int pid = atoi(argv[1]);
|
||||
|
||||
CLocalSocket socket;
|
||||
auto success = socket.connect(CSocketAddress::local(String::format("/tmp/rpc.%d", pid)));
|
||||
if (!success) {
|
||||
fprintf(stderr, "Couldn't connect to PID %d\n", pid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
socket.on_connected = [&] {
|
||||
dbg() << "Connected to PID " << pid;
|
||||
};
|
||||
|
||||
socket.on_ready_to_read = [&] {
|
||||
if (socket.eof()) {
|
||||
dbg() << "Disconnected from PID " << pid;
|
||||
loop.quit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
auto data = socket.read_all();
|
||||
|
||||
for (int i = 0; i < data.size(); ++i)
|
||||
putchar(data[i]);
|
||||
printf("\n");
|
||||
};
|
||||
|
||||
return loop.exec();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue