cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[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
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 16
55cd033d
JG
17const 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 }
39end:
40 return path;
41}
ca9f27f3 42
5b5c3486 43bool is_event_common_ctx_dbg_info_compatible(const bt_field_class *in_field_class,
ca9f27f3
FD
44 const char *debug_info_field_class_name)
45{
1e6fd1d7
PP
46 const bt_field_class_structure_member *member;
47 const bt_field_class *ip_fc, *vpid_fc;
5b5c3486 48 bool match = false;
ca9f27f3
FD
49
50 /*
51 * If the debug info field is already present in the event common
52 * context. Do not try to add it.
53 */
5b5c3486 54 member = bt_field_class_structure_borrow_member_by_name_const(
cbb6e805 55 in_field_class, debug_info_field_class_name);
1e6fd1d7 56 if (member) {
ca9f27f3
FD
57 goto end;
58 }
59
60 /*
61 * Verify that the ip and vpid field are present and of the right field
62 * class.
63 */
1e6fd1d7 64 member = bt_field_class_structure_borrow_member_by_name_const(
cbb6e805 65 in_field_class, IP_FIELD_NAME);
1e6fd1d7 66 if (!member) {
ca9f27f3
FD
67 goto end;
68 }
69
1e6fd1d7
PP
70 ip_fc = bt_field_class_structure_member_borrow_field_class_const(
71 member);
ca9f27f3
FD
72 if (bt_field_class_get_type(ip_fc) !=
73 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER) {
ca9f27f3
FD
74 goto end;
75 }
76
1e6fd1d7 77 member = bt_field_class_structure_borrow_member_by_name_const(
cbb6e805 78 in_field_class, VPID_FIELD_NAME);
1e6fd1d7 79 if (!member) {
ca9f27f3
FD
80 goto end;
81 }
82
1e6fd1d7
PP
83 vpid_fc = bt_field_class_structure_member_borrow_field_class_const(
84 member);
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
5b5c3486 94 match = true;
1e6fd1d7 95
ca9f27f3
FD
96end:
97 return match;
98}
This page took 0.105681 seconds and 5 git commands to generate.