Debian Codegraph @

src/libsysprof/sysprof-symbol-private.h

raw
1 /*
2 * sysprof-symbol-private.h
3 *
4 * Copyright 2023 Christian Hergert <[email protected]>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * SPDX-License-Identifier: GPL-3.0-or-later
20 */
21
22 #pragma once
23
24 #include "sysprof-symbol.h"
25
26 G_BEGIN_DECLS
27
28 struct _SysprofSymbol
29 {
30 GObject parent_instance;
31
32 guint hash;
33 guint simple_hash;
34
35 GRefString *name;
36 GRefString *binary_path;
37 GRefString *binary_nick;
38
39 SysprofAddress begin_address;
40 SysprofAddress end_address;
41
42 guint kind : 3;
43 guint is_fallback : 1;
44 guint is_kernel_process : 1;
45 };
46
47 SysprofSymbol *_sysprof_symbol_new (GRefString *name,
48 GRefString *binary_path,
49 GRefString *binary_nick,
50 SysprofAddress begin_address,
51 SysprofAddress end_address,
52 SysprofSymbolKind kind);
53
54 static inline SysprofSymbol *
55 _sysprof_symbol_copy (SysprofSymbol *self)
56 {
57 SysprofSymbol *copy;
58
59 copy = _sysprof_symbol_new (self->name ? g_ref_string_acquire (self->name) : NULL,
60 self->binary_path ? g_ref_string_acquire (self->binary_path) : NULL,
61 self->binary_nick ? g_ref_string_acquire (self->binary_nick) : NULL,
62 self->begin_address,
63 self->end_address,
64 self->kind);
65
66 return copy;
67 }
68
69 static inline gboolean
70 _sysprof_symbol_equal (const SysprofSymbol *a,
71 const SysprofSymbol *b)
72 {
73 if (a == b)
74 return TRUE;
75
76 if (a->simple_hash != b->simple_hash)
77 return FALSE;
78
79 if (a->kind != b->kind)
80 return FALSE;
81
82 if (a->hash != b->hash)
83 {
84 /* Special case symbols w/o binary_path which can happen
85 * when we have symbols decoded from a bundled symbols.
86 */
87 if (a->binary_path == NULL || b->binary_path == NULL)
88 return TRUE;
89
90 return FALSE;
91 }
92
93 return strcmp (a->name, b->name) == 0;
94 }
95
96 static inline gboolean
97 _sysprof_symbol_is_context_switch (SysprofSymbol *symbol)
98 {
99 return symbol->kind == SYSPROF_SYMBOL_KIND_CONTEXT_SWITCH;
100 }
101
102 static inline gboolean
103 _sysprof_symbol_is_system_library (SysprofSymbol *symbol)
104 {
105 switch (symbol->kind)
106 {
107 case SYSPROF_SYMBOL_KIND_ROOT:
108 case SYSPROF_SYMBOL_KIND_PROCESS:
109 case SYSPROF_SYMBOL_KIND_THREAD:
110 case SYSPROF_SYMBOL_KIND_CONTEXT_SWITCH:
111 case SYSPROF_SYMBOL_KIND_UNWINDABLE:
112 default:
113 return FALSE;
114
115 case SYSPROF_SYMBOL_KIND_KERNEL:
116 return TRUE;
117
118 case SYSPROF_SYMBOL_KIND_USER:
119 if (symbol->binary_nick != NULL)
120 return TRUE;
121
122 if (symbol->binary_path != NULL)
123 return !!strstr (symbol->binary_path, "/usr/");
124
125 return FALSE;
126 }
127 }
128
129 G_END_DECLS