libsysprof-analyze: add build-id to SysprofDocumentMmap

In anticipation of getting PERF_EVENT_MMAP2 events, assume we tack on the
build-id in hex after the filename like "filename\0@build-id\0" so that we
can use it when decoding frames. That will allow us to avoid doing inode
checks (which breaks when moving files between computers anyway) as well
as potentially supporting debuginfod in the future via build-id.
This commit is contained in:
Christian Hergert
2023-05-08 14:25:27 -07:00
parent dc57721699
commit 7c57da2440
2 changed files with 42 additions and 1 deletions

View File

@ -36,6 +36,7 @@ struct _SysprofDocumentMmapClass
enum {
PROP_0,
PROP_BUILD_ID,
PROP_END_ADDRESS,
PROP_FILE,
PROP_FILE_INODE,
@ -78,6 +79,10 @@ sysprof_document_mmap_get_property (GObject *object,
g_value_set_uint64 (value, sysprof_document_mmap_get_file_inode (self));
break;
case PROP_BUILD_ID:
g_value_set_string (value, sysprof_document_mmap_get_build_id (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -115,6 +120,11 @@ sysprof_document_mmap_class_init (SysprofDocumentMmapClass *klass)
0, G_MAXUINT64, 0,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
properties [PROP_BUILD_ID] =
g_param_spec_string ("build-id", NULL, NULL,
NULL,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
}
@ -176,9 +186,38 @@ sysprof_document_mmap_get_file (SysprofDocumentMmap *self)
{
const SysprofCaptureMap *mmap;
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_MMAP (self), 0);
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_MMAP (self), NULL);
mmap = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureMap);
return SYSPROF_DOCUMENT_FRAME_CSTRING (self, mmap->filename);
}
const char *
sysprof_document_mmap_get_build_id (SysprofDocumentMmap *self)
{
const char *file;
const char *build_id;
gsize len;
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_MMAP (self), NULL);
if (!(file = sysprof_document_mmap_get_file (self)))
return NULL;
/* The build-id may be tacked on after the filename if after the
* Nil byte we get '@'. SYSPROF_DOCUMENT_FRAME_CSTRING() will check
* for bounds so we can feed it a position we don't know is part
* of our frame or not. We expect "FILE\0@BUILD_ID_IN_HEX\0".
*/
len = strlen (file);
if (!(build_id = SYSPROF_DOCUMENT_FRAME_CSTRING (self, &file[len+1])))
return NULL;
if (build_id[0] != '@')
return NULL;
return &build_id[1];
}

View File

@ -45,6 +45,8 @@ SYSPROF_AVAILABLE_IN_ALL
guint64 sysprof_document_mmap_get_file_offset (SysprofDocumentMmap *self);
SYSPROF_AVAILABLE_IN_ALL
const char *sysprof_document_mmap_get_file (SysprofDocumentMmap *self);
SYSPROF_AVAILABLE_IN_ALL
const char *sysprof_document_mmap_get_build_id (SysprofDocumentMmap *self);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofDocumentMmap, g_object_unref)