Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "RemoteObject.h"
28#include "RemoteObjectGraphModel.h"
29#include "RemoteObjectPropertyModel.h"
30#include "RemoteProcess.h"
31#include <LibGUI/Application.h>
32#include <LibGUI/BoxLayout.h>
33#include <LibGUI/Splitter.h>
34#include <LibGUI/TableView.h>
35#include <LibGUI/TreeView.h>
36#include <LibGUI/Window.h>
37#include <stdio.h>
38
39[[noreturn]] static void print_usage_and_exit()
40{
41 printf("usage: Inspector <pid>\n");
42 exit(0);
43}
44
45int main(int argc, char** argv)
46{
47 if (argc != 2)
48 print_usage_and_exit();
49
50 bool ok;
51 pid_t pid = String(argv[1]).to_int(ok);
52 if (!ok)
53 print_usage_and_exit();
54
55 GUI::Application app(argc, argv);
56
57 auto window = GUI::Window::construct();
58 window->set_title("Inspector");
59 window->set_rect(150, 150, 300, 500);
60
61 auto widget = GUI::Widget::construct();
62 window->set_main_widget(widget);
63 widget->set_fill_with_background_color(true);
64 widget->set_layout(make<GUI::VerticalBoxLayout>());
65
66 auto splitter = widget->add<GUI::HorizontalSplitter>();
67
68 RemoteProcess remote_process(pid);
69
70 remote_process.on_update = [&] {
71 if (!remote_process.process_name().is_null())
72 window->set_title(String::format("Inspector: %s (%d)", remote_process.process_name().characters(), remote_process.pid()));
73 };
74
75 auto tree_view = splitter->add<GUI::TreeView>();
76 tree_view->set_model(remote_process.object_graph_model());
77 tree_view->set_activates_on_selection(true);
78
79 auto properties_table_view = splitter->add<GUI::TableView>();
80 properties_table_view->set_size_columns_to_fit_content(true);
81
82 tree_view->on_activation = [&](auto& index) {
83 auto* remote_object = static_cast<RemoteObject*>(index.internal_data());
84 properties_table_view->set_model(remote_object->property_model());
85 };
86
87 window->show();
88 remote_process.update();
89 return app.exec();
90}