Debian Codegraph @

src/libsysprof/tests/test-list-address-layout.c

raw
1 /* test-list-address-layout.c
2 *
3 * Copyright 2023 Christian Hergert <[email protected]>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21 #include <sysprof.h>
22
23 #include "sysprof-document-private.h"
24
25 int
26 main (int argc,
27 char *argv[])
28 {
29 g_autoptr(SysprofDocumentLoader) loader = NULL;
30 g_autoptr(SysprofDocument) document = NULL;
31 g_autoptr(GListModel) processes = NULL;
32 g_autoptr(GError) error = NULL;
33 guint n_items;
34 int pid;
35
36 if (argc < 3)
37 {
38 g_printerr ("usage: %s CAPTURE_FILE PID\n", argv[0]);
39 return 1;
40 }
41
42 pid = atoi (argv[2]);
43 loader = sysprof_document_loader_new (argv[1]);
44 sysprof_document_loader_set_symbolizer (loader, sysprof_no_symbolizer_get ());
45
46 if (!(document = sysprof_document_loader_load (loader, NULL, &error)))
47 {
48 g_printerr ("Failed to open capture: %s\n", error->message);
49 return 1;
50 }
51
52 processes = sysprof_document_list_processes (document);
53 n_items = g_list_model_get_n_items (processes);
54
55 for (guint i = 0; i < n_items; i++)
56 {
57 g_autoptr(SysprofDocumentProcess) process = g_list_model_get_item (processes, i);
58
59 if (sysprof_document_frame_get_pid (SYSPROF_DOCUMENT_FRAME (process)) == pid)
60 {
61 g_autoptr(GListModel) memory_maps = sysprof_document_process_list_memory_maps (process);
62 guint n_maps = g_list_model_get_n_items (memory_maps);
63
64 for (guint j = 0; j < n_maps; j++)
65 {
66 g_autoptr(SysprofDocumentMmap) map = g_list_model_get_item (memory_maps, j);
67
68 g_print (" [0x%"G_GINT64_MODIFIER"x:0x%"G_GINT64_MODIFIER"x] %s <+0x%"G_GINT64_MODIFIER"x>\n",
69 sysprof_document_mmap_get_start_address (map),
70 sysprof_document_mmap_get_end_address (map),
71 sysprof_document_mmap_get_file (map),
72 sysprof_document_mmap_get_file_offset (map));
73 }
74
75 break;
76 }
77 }
78
79 return 0;
80 }