File: sp-symbol-resolver.c

package info (click to toggle)
sysprof 3.30.2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,616 kB
  • sloc: ansic: 20,056; xml: 96; cpp: 23; sh: 18; makefile: 9
file content (140 lines) | stat: -rw-r--r-- 4,708 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* sp-symbol-resolver.c
 *
 * Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "symbols/sp-symbol-resolver.h"

G_DEFINE_INTERFACE (SpSymbolResolver, sp_symbol_resolver, G_TYPE_OBJECT)

static gchar *
sp_symbol_resolver_real_resolve (SpSymbolResolver *self,
                                 guint64           time,
                                 GPid              pid,
                                 SpCaptureAddress  address,
                                 GQuark           *tag)
{
  *tag = 0;
  return NULL;
}

static gchar *
sp_symbol_resolver_real_resolve_with_context (SpSymbolResolver *self,
                                              guint64           time,
                                              GPid              pid,
                                              SpAddressContext  context,
                                              SpCaptureAddress  address,
                                              GQuark           *tag)
{
  *tag = 0;

  if (SP_SYMBOL_RESOLVER_GET_IFACE (self)->resolve)
    return SP_SYMBOL_RESOLVER_GET_IFACE (self)->resolve (self, time, pid, address, tag);

  return NULL;
}

static void
sp_symbol_resolver_default_init (SpSymbolResolverInterface *iface)
{
  iface->resolve = sp_symbol_resolver_real_resolve;
  iface->resolve_with_context = sp_symbol_resolver_real_resolve_with_context;
}

void
sp_symbol_resolver_load (SpSymbolResolver *self,
                         SpCaptureReader  *reader)
{
  g_return_if_fail (SP_IS_SYMBOL_RESOLVER (self));
  g_return_if_fail (reader != NULL);

  if (SP_SYMBOL_RESOLVER_GET_IFACE (self)->load)
    SP_SYMBOL_RESOLVER_GET_IFACE (self)->load (self, reader);
}

/**
 * sp_symbol_resolver_resolve:
 * @self: A #SpSymbolResolver
 * @time: The time of the sample
 * @pid: The process generating the sample
 * @address: the sample address
 * @tag: (out): A tag for the symbol.
 *
 * Gets the symbol name for @address that was part of process @pid
 * at @time. Optionally, you can set @tag to a quark describing the
 * symbol. This can be used to provide a bit more information when
 * rendering the treeview. You might choose to describe the library
 * such as "GObject" or "GTK+" or "Linux" for the kernel.
 *
 * Returns: (nullable) (transfer full): A newly allocated string, or %NULL.
 */
gchar *
sp_symbol_resolver_resolve (SpSymbolResolver *self,
                            guint64           time,
                            GPid              pid,
                            SpCaptureAddress  address,
                            GQuark           *tag)
{
  GQuark dummy;

  g_return_val_if_fail (SP_IS_SYMBOL_RESOLVER (self), NULL);

  if (tag == NULL)
    tag = &dummy;

  *tag = 0;

  if (SP_SYMBOL_RESOLVER_GET_IFACE (self)->resolve)
    return SP_SYMBOL_RESOLVER_GET_IFACE (self)->resolve (self, time, pid, address, tag);

  return NULL;
}

/**
 * sp_symbol_resolver_resolve_with_context:
 * @self: A #SpSymbolResolver
 * @time: The time of the sample
 * @pid: The process generating the sample
 * @context: the address context
 * @address: the sample address
 * @tag: (out): A tag for the symbol.
 *
 * This function is like sp_symbol_resolver_resolve() but allows
 * access to the address context, which might be necessary to
 * determine the difference between user space and kernel space
 * addresses.
 *
 * Returns: (nullable) (transfer full): A newly allocated string, or %NULL.
 */
gchar *
sp_symbol_resolver_resolve_with_context (SpSymbolResolver *self,
                                         guint64           time,
                                         GPid              pid,
                                         SpAddressContext  context,
                                         SpCaptureAddress  address,
                                         GQuark           *tag)
{
  GQuark dummy;

  g_return_val_if_fail (SP_IS_SYMBOL_RESOLVER (self), NULL);

  if (tag == NULL)
    tag = &dummy;

  *tag = 0;

  return SP_SYMBOL_RESOLVER_GET_IFACE (self)->resolve_with_context (self, time, pid, context, address, tag);
}