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 | ||
5b5c3486 | 9 | #include <stdbool.h> |
91d81473 | 10 | #include <string.h> |
b4d8674c FD |
11 | |
12 | #include <babeltrace2/babeltrace.h> | |
13 | ||
14 | #include "debug-info.h" | |
4f45f9bb | 15 | #include "utils.h" |
55cd033d JG |
16 | |
17 | BT_HIDDEN | |
18 | const char *get_filename_from_path(const char *path) | |
19 | { | |
20 | size_t i = strlen(path); | |
21 | ||
22 | if (i == 0) { | |
23 | goto end; | |
24 | } | |
25 | ||
26 | if (path[i - 1] == '/') { | |
27 | /* | |
28 | * Path ends with a trailing slash, no filename to return. | |
29 | * Return the original path. | |
30 | */ | |
31 | goto end; | |
32 | } | |
33 | ||
34 | while (i-- > 0) { | |
35 | if (path[i] == '/') { | |
36 | path = &path[i + 1]; | |
37 | goto end; | |
38 | } | |
39 | } | |
40 | end: | |
41 | return path; | |
42 | } | |
ca9f27f3 FD |
43 | |
44 | BT_HIDDEN | |
5b5c3486 | 45 | bool is_event_common_ctx_dbg_info_compatible(const bt_field_class *in_field_class, |
ca9f27f3 FD |
46 | const char *debug_info_field_class_name) |
47 | { | |
1e6fd1d7 PP |
48 | const bt_field_class_structure_member *member; |
49 | const bt_field_class *ip_fc, *vpid_fc; | |
5b5c3486 | 50 | bool match = false; |
ca9f27f3 FD |
51 | |
52 | /* | |
53 | * If the debug info field is already present in the event common | |
54 | * context. Do not try to add it. | |
55 | */ | |
5b5c3486 | 56 | member = bt_field_class_structure_borrow_member_by_name_const( |
cbb6e805 | 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( |
cbb6e805 | 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) { | |
ca9f27f3 FD |
76 | goto end; |
77 | } | |
78 | ||
1e6fd1d7 | 79 | member = bt_field_class_structure_borrow_member_by_name_const( |
cbb6e805 | 80 | in_field_class, VPID_FIELD_NAME); |
1e6fd1d7 | 81 | if (!member) { |
ca9f27f3 FD |
82 | goto end; |
83 | } | |
84 | ||
1e6fd1d7 PP |
85 | vpid_fc = bt_field_class_structure_member_borrow_field_class_const( |
86 | member); | |
ca9f27f3 FD |
87 | if (bt_field_class_get_type(vpid_fc) != |
88 | BT_FIELD_CLASS_TYPE_SIGNED_INTEGER) { | |
89 | goto end; | |
90 | } | |
91 | ||
92 | if (bt_field_class_integer_get_field_value_range(vpid_fc) != 32) { | |
93 | goto end; | |
94 | } | |
95 | ||
5b5c3486 | 96 | match = true; |
1e6fd1d7 | 97 | |
ca9f27f3 FD |
98 | end: |
99 | return match; | |
100 | } |