Move to kernel style SPDX license identifiers
[babeltrace.git] / src / plugins / lttng-utils / debug-info / utils.c
CommitLineData
55cd033d 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
55cd033d
JG
3 *
4 * Copyright (c) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 *
0235b0db 6 * Babeltrace - Debug info utilities
55cd033d
JG
7 */
8
91d81473 9#include <string.h>
4f45f9bb 10#include "utils.h"
55cd033d
JG
11
12BT_HIDDEN
13const char *get_filename_from_path(const char *path)
14{
15 size_t i = strlen(path);
16
17 if (i == 0) {
18 goto end;
19 }
20
21 if (path[i - 1] == '/') {
22 /*
23 * Path ends with a trailing slash, no filename to return.
24 * Return the original path.
25 */
26 goto end;
27 }
28
29 while (i-- > 0) {
30 if (path[i] == '/') {
31 path = &path[i + 1];
32 goto end;
33 }
34 }
35end:
36 return path;
37}
ca9f27f3
FD
38
39BT_HIDDEN
40bt_bool is_event_common_ctx_dbg_info_compatible(const bt_field_class *in_field_class,
41 const char *debug_info_field_class_name)
42{
1e6fd1d7
PP
43 const bt_field_class_structure_member *member;
44 const bt_field_class *ip_fc, *vpid_fc;
ca9f27f3
FD
45 bt_bool match = BT_FALSE;
46
47 /*
48 * If the debug info field is already present in the event common
49 * context. Do not try to add it.
50 */
1e6fd1d7
PP
51 member =
52 bt_field_class_structure_borrow_member_by_name_const(
ca9f27f3 53 in_field_class, debug_info_field_class_name);
1e6fd1d7 54 if (member) {
ca9f27f3
FD
55 goto end;
56 }
57
58 /*
59 * Verify that the ip and vpid field are present and of the right field
60 * class.
61 */
1e6fd1d7 62 member = bt_field_class_structure_borrow_member_by_name_const(
ca9f27f3 63 in_field_class, IP_FIELD_NAME);
1e6fd1d7 64 if (!member) {
ca9f27f3
FD
65 goto end;
66 }
67
1e6fd1d7
PP
68 ip_fc = bt_field_class_structure_member_borrow_field_class_const(
69 member);
ca9f27f3
FD
70 if (bt_field_class_get_type(ip_fc) !=
71 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER) {
72 match = BT_FALSE;
73 goto end;
74 }
75
1e6fd1d7 76 member = bt_field_class_structure_borrow_member_by_name_const(
ca9f27f3 77 in_field_class, VPID_FIELD_NAME);
1e6fd1d7 78 if (!member) {
ca9f27f3
FD
79 goto end;
80 }
81
1e6fd1d7
PP
82 vpid_fc = bt_field_class_structure_member_borrow_field_class_const(
83 member);
84
ca9f27f3
FD
85 if (bt_field_class_get_type(vpid_fc) !=
86 BT_FIELD_CLASS_TYPE_SIGNED_INTEGER) {
87 goto end;
88 }
89
90 if (bt_field_class_integer_get_field_value_range(vpid_fc) != 32) {
91 goto end;
92 }
93
94 match = BT_TRUE;
1e6fd1d7 95
ca9f27f3
FD
96end:
97 return match;
98}
This page took 0.069806 seconds and 4 git commands to generate.