Commit | Line | Data |
---|---|---|
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> |
b4d8674c FD |
10 | |
11 | #include <babeltrace2/babeltrace.h> | |
12 | ||
13 | #include "debug-info.h" | |
4f45f9bb | 14 | #include "utils.h" |
55cd033d JG |
15 | |
16 | BT_HIDDEN | |
17 | const char *get_filename_from_path(const char *path) | |
18 | { | |
19 | size_t i = strlen(path); | |
20 | ||
21 | if (i == 0) { | |
22 | goto end; | |
23 | } | |
24 | ||
25 | if (path[i - 1] == '/') { | |
26 | /* | |
27 | * Path ends with a trailing slash, no filename to return. | |
28 | * Return the original path. | |
29 | */ | |
30 | goto end; | |
31 | } | |
32 | ||
33 | while (i-- > 0) { | |
34 | if (path[i] == '/') { | |
35 | path = &path[i + 1]; | |
36 | goto end; | |
37 | } | |
38 | } | |
39 | end: | |
40 | return path; | |
41 | } | |
ca9f27f3 FD |
42 | |
43 | BT_HIDDEN | |
44 | bt_bool is_event_common_ctx_dbg_info_compatible(const bt_field_class *in_field_class, | |
45 | const char *debug_info_field_class_name) | |
46 | { | |
1e6fd1d7 PP |
47 | const bt_field_class_structure_member *member; |
48 | const bt_field_class *ip_fc, *vpid_fc; | |
ca9f27f3 FD |
49 | bt_bool match = BT_FALSE; |
50 | ||
51 | /* | |
52 | * If the debug info field is already present in the event common | |
53 | * context. Do not try to add it. | |
54 | */ | |
1e6fd1d7 PP |
55 | member = |
56 | bt_field_class_structure_borrow_member_by_name_const( | |
ca9f27f3 | 57 | in_field_class, debug_info_field_class_name); |
1e6fd1d7 | 58 | if (member) { |
ca9f27f3 FD |
59 | goto end; |
60 | } | |
61 | ||
62 | /* | |
63 | * Verify that the ip and vpid field are present and of the right field | |
64 | * class. | |
65 | */ | |
1e6fd1d7 | 66 | member = bt_field_class_structure_borrow_member_by_name_const( |
ca9f27f3 | 67 | in_field_class, IP_FIELD_NAME); |
1e6fd1d7 | 68 | if (!member) { |
ca9f27f3 FD |
69 | goto end; |
70 | } | |
71 | ||
1e6fd1d7 PP |
72 | ip_fc = bt_field_class_structure_member_borrow_field_class_const( |
73 | member); | |
ca9f27f3 FD |
74 | if (bt_field_class_get_type(ip_fc) != |
75 | BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER) { | |
76 | match = BT_FALSE; | |
77 | goto end; | |
78 | } | |
79 | ||
1e6fd1d7 | 80 | member = bt_field_class_structure_borrow_member_by_name_const( |
ca9f27f3 | 81 | in_field_class, VPID_FIELD_NAME); |
1e6fd1d7 | 82 | if (!member) { |
ca9f27f3 FD |
83 | goto end; |
84 | } | |
85 | ||
1e6fd1d7 PP |
86 | vpid_fc = bt_field_class_structure_member_borrow_field_class_const( |
87 | member); | |
88 | ||
ca9f27f3 FD |
89 | if (bt_field_class_get_type(vpid_fc) != |
90 | BT_FIELD_CLASS_TYPE_SIGNED_INTEGER) { | |
91 | goto end; | |
92 | } | |
93 | ||
94 | if (bt_field_class_integer_get_field_value_range(vpid_fc) != 32) { | |
95 | goto end; | |
96 | } | |
97 | ||
98 | match = BT_TRUE; | |
1e6fd1d7 | 99 | |
ca9f27f3 FD |
100 | end: |
101 | return match; | |
102 | } |