mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 04:44:59 +00:00

These instances were detected by searching for files that include stdlib.h, but don't match the regex: \\b(_abort|abort|abs|aligned_alloc|arc4random|arc4random_buf|arc4random_ uniform|atexit|atof|atoi|atol|atoll|bsearch|calloc|clearenv|div|div_t|ex it|_Exit|EXIT_FAILURE|EXIT_SUCCESS|free|getenv|getprogname|grantpt|labs| ldiv|ldiv_t|llabs|lldiv|lldiv_t|malloc|malloc_good_size|malloc_size|mble n|mbstowcs|mbtowc|mkdtemp|mkstemp|mkstemps|mktemp|posix_memalign|posix_o penpt|ptsname|ptsname_r|putenv|qsort|qsort_r|rand|RAND_MAX|random|reallo c|realpath|secure_getenv|serenity_dump_malloc_stats|serenity_setenv|sete nv|setprogname|srand|srandom|strtod|strtof|strtol|strtold|strtoll|strtou l|strtoull|system|unlockpt|unsetenv|wcstombs|wctomb)\\b (Without the linebreaks.) This regex is pessimistic, so there might be more files that don't actually use anything from the stdlib. In theory, one might use LibCPP to detect things like this automatically, but let's do this one step after another.
109 lines
3.1 KiB
C++
109 lines
3.1 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include "RemoteProcess.h"
|
|
#include "RemoteObject.h"
|
|
#include "RemoteObjectGraphModel.h"
|
|
#include "RemoteObjectPropertyModel.h"
|
|
|
|
namespace Inspector {
|
|
|
|
RemoteProcess* s_the;
|
|
|
|
RemoteProcess& RemoteProcess::the()
|
|
{
|
|
return *s_the;
|
|
}
|
|
|
|
RemoteProcess::RemoteProcess(pid_t pid)
|
|
: m_pid(pid)
|
|
, m_object_graph_model(RemoteObjectGraphModel::create(*this))
|
|
{
|
|
s_the = this;
|
|
m_client = InspectorServerClient::try_create().release_value_but_fixme_should_propagate_errors();
|
|
}
|
|
|
|
void RemoteProcess::handle_identify_response(JsonObject const& response)
|
|
{
|
|
int pid = response.get("pid"sv).to_int();
|
|
VERIFY(pid == m_pid);
|
|
|
|
m_process_name = response.get("process_name"sv).as_string_or({});
|
|
|
|
if (on_update)
|
|
on_update();
|
|
}
|
|
|
|
void RemoteProcess::handle_get_all_objects_response(JsonObject const& response)
|
|
{
|
|
// FIXME: It would be good if we didn't have to make a local copy of the array value here!
|
|
auto objects = response.get("objects"sv);
|
|
auto& object_array = objects.as_array();
|
|
|
|
NonnullOwnPtrVector<RemoteObject> remote_objects;
|
|
HashMap<FlatPtr, RemoteObject*> objects_by_address;
|
|
|
|
for (auto& value : object_array.values()) {
|
|
VERIFY(value.is_object());
|
|
auto& object = value.as_object();
|
|
auto remote_object = make<RemoteObject>();
|
|
remote_object->address = object.get("address"sv).to_number<FlatPtr>();
|
|
remote_object->parent_address = object.get("parent"sv).to_number<FlatPtr>();
|
|
remote_object->name = object.get("name"sv).to_deprecated_string();
|
|
remote_object->class_name = object.get("class_name"sv).to_deprecated_string();
|
|
remote_object->json = object;
|
|
objects_by_address.set(remote_object->address, remote_object);
|
|
remote_objects.append(move(remote_object));
|
|
}
|
|
|
|
for (size_t i = 0; i < remote_objects.size(); ++i) {
|
|
auto& remote_object = remote_objects.ptr_at(i);
|
|
auto* parent = objects_by_address.get(remote_object->parent_address).value_or(nullptr);
|
|
if (!parent) {
|
|
m_roots.append(move(remote_object));
|
|
} else {
|
|
remote_object->parent = parent;
|
|
parent->children.append(move(remote_object));
|
|
}
|
|
}
|
|
|
|
m_object_graph_model->invalidate();
|
|
|
|
if (on_update)
|
|
on_update();
|
|
}
|
|
|
|
void RemoteProcess::set_inspected_object(FlatPtr address)
|
|
{
|
|
m_client->async_set_inspected_object(m_pid, address);
|
|
}
|
|
|
|
void RemoteProcess::set_property(FlatPtr object, StringView name, JsonValue const& value)
|
|
{
|
|
m_client->async_set_object_property(m_pid, object, name, value.to_deprecated_string());
|
|
}
|
|
|
|
bool RemoteProcess::is_inspectable()
|
|
{
|
|
return m_client->is_inspectable(m_pid);
|
|
}
|
|
|
|
void RemoteProcess::update()
|
|
{
|
|
{
|
|
auto raw_json = m_client->identify(m_pid);
|
|
auto json = JsonValue::from_string(raw_json);
|
|
handle_identify_response(json.value().as_object());
|
|
}
|
|
|
|
{
|
|
auto raw_json = m_client->get_all_objects(m_pid);
|
|
auto json = JsonValue::from_string(raw_json);
|
|
handle_get_all_objects_response(json.value().as_object());
|
|
}
|
|
}
|
|
|
|
}
|