- Change use of glibc's malloc() to glib's g_new0() to follow the rest of
the project.
- Change use of glibc string functions to their glib equivalent.
- Remove uses of GNU extension of conditional expressions with omitted
operands as it would only be useful if the evaluation of the condition
had side effects which it doesn't. Let's prefer code simplicity.
[0]: https://gcc.gnu.org/onlinedocs/gcc-4.2.4/gcc/Conditionals.html
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
- bin->debug_info_dir = strdup(debug_info_dir);
+ bin->debug_info_dir = g_strdup(debug_info_dir);
if (!bin->debug_info_dir) {
goto error;
}
if (!bin->debug_info_dir) {
goto error;
}
dwarf_end(bin->dwarf_info);
dwarf_end(bin->dwarf_info);
- free(bin->debug_info_dir);
- free(bin->elf_path);
- free(bin->dwarf_path);
+ g_free(bin->debug_info_dir);
+ g_free(bin->elf_path);
+ g_free(bin->dwarf_path);
- free(bin->dbg_link_filename);
+ g_free(bin->dbg_link_filename);
- bin->dbg_link_filename = strdup(filename);
+ bin->dbg_link_filename = g_strdup(filename);
if (!bin->dbg_link_filename) {
goto error;
}
if (!bin->dbg_link_filename) {
goto error;
}
- bin->dwarf_path = strdup(path);
+ bin->dwarf_path = g_strdup(path);
if (!bin->dwarf_path) {
goto error;
}
if (!bin->dwarf_path) {
goto error;
}
- dbg_dir = bin->debug_info_dir ? : DEFAULT_DEBUG_DIR;
+ dbg_dir = bin->debug_info_dir ? bin->debug_info_dir : DEFAULT_DEBUG_DIR;
/* 2 characters per byte printed in hex, +1 for '/' and +1 for '\0' */
build_id_file_len = (2 * bin->build_id_len) + 1 +
strlen(BUILD_ID_SUFFIX) + 1;
/* 2 characters per byte printed in hex, +1 for '/' and +1 for '\0' */
build_id_file_len = (2 * bin->build_id_len) + 1 +
strlen(BUILD_ID_SUFFIX) + 1;
- build_id_file = malloc(build_id_file_len);
+ build_id_file = g_new0(gchar, build_id_file_len);
if (!build_id_file) {
goto error;
}
if (!build_id_file) {
goto error;
}
- snprintf(build_id_file, 4, "%02x/", bin->build_id[0]);
+ g_snprintf(build_id_file, 4, "%02x/", bin->build_id[0]);
for (i = 1; i < bin->build_id_len; ++i) {
int path_idx = 3 + 2 * (i - 1);
for (i = 1; i < bin->build_id_len; ++i) {
int path_idx = 3 + 2 * (i - 1);
- snprintf(&build_id_file[path_idx], 3, "%02x", bin->build_id[i]);
+ g_snprintf(&build_id_file[path_idx], 3, "%02x", bin->build_id[i]);
- strcat(build_id_file, BUILD_ID_SUFFIX);
+ g_strconcat(build_id_file, BUILD_ID_SUFFIX, NULL);
path = g_build_path("/", dbg_dir, BUILD_ID_SUBDIR, build_id_file, NULL);
if (!path) {
path = g_build_path("/", dbg_dir, BUILD_ID_SUBDIR, build_id_file, NULL);
if (!path) {
int bin_info_set_dwarf_info_debug_link(struct bin_info *bin)
{
int ret = 0;
int bin_info_set_dwarf_info_debug_link(struct bin_info *bin)
{
int ret = 0;
- const char *dbg_dir = NULL;
- char *dir_name = NULL, *bin_dir = NULL, *path = NULL;
- size_t max_path_len = 0;
+ const gchar *dbg_dir = NULL;
+ gchar *bin_dir = NULL, *dir_name = NULL, *path = NULL;
if (!bin || !bin->dbg_link_filename) {
goto error;
}
if (!bin || !bin->dbg_link_filename) {
goto error;
}
- dbg_dir = bin->debug_info_dir ? : DEFAULT_DEBUG_DIR;
-
+ dbg_dir = bin->debug_info_dir ? bin->debug_info_dir : DEFAULT_DEBUG_DIR;
dir_name = g_path_get_dirname(bin->elf_path);
if (!dir_name) {
goto error;
}
dir_name = g_path_get_dirname(bin->elf_path);
if (!dir_name) {
goto error;
}
- /* bin_dir is just dir_name with a trailing slash */
- bin_dir = g_new0(char, strlen(dir_name) + 2);
- if (!bin_dir) {
- goto error;
- }
-
- strcpy(bin_dir, dir_name);
- strcat(bin_dir, "/");
-
- max_path_len = strlen(dbg_dir) + strlen(bin_dir) +
- strlen(DEBUG_SUBDIR) + strlen(bin->dbg_link_filename)
- + 1;
- path = g_new0(char, max_path_len);
- if (!path) {
- goto error;
- }
+ bin_dir = g_strconcat(dir_name, "/", NULL);
/* First look in the executable's dir */
/* First look in the executable's dir */
- strcpy(path, bin_dir);
- strcat(path, bin->dbg_link_filename);
+ path = g_strconcat(bin_dir, bin->dbg_link_filename, NULL);
if (is_valid_debug_file(path, bin->dbg_link_crc)) {
goto found;
}
/* If not found, look in .debug subdir */
if (is_valid_debug_file(path, bin->dbg_link_crc)) {
goto found;
}
/* If not found, look in .debug subdir */
- strcpy(path, bin_dir);
- strcat(path, DEBUG_SUBDIR);
- strcat(path, bin->dbg_link_filename);
+ g_free(path);
+ path = g_strconcat(bin_dir, DEBUG_SUBDIR, bin->dbg_link_filename, NULL);
if (is_valid_debug_file(path, bin->dbg_link_crc)) {
goto found;
}
/* Lastly, look under the global debug directory */
if (is_valid_debug_file(path, bin->dbg_link_crc)) {
goto found;
}
/* Lastly, look under the global debug directory */
- strcpy(path, dbg_dir);
- strcat(path, bin_dir);
- strcat(path, bin->dbg_link_filename);
+ path = g_strconcat(dbg_dir, bin_dir, bin->dbg_link_filename, NULL);
if (is_valid_debug_file(path, bin->dbg_link_crc)) {
goto found;
}
if (is_valid_debug_file(path, bin->dbg_link_crc)) {
goto found;
}
end:
g_free(dir_name);
g_free(path);
end:
g_free(dir_name);
g_free(path);
int bin_info_append_offset_str(const char *base_str, uint64_t low_addr,
uint64_t high_addr, char **result)
{
int bin_info_append_offset_str(const char *base_str, uint64_t low_addr,
uint64_t high_addr, char **result)
{
uint64_t offset;
char *_result = NULL;
uint64_t offset;
char *_result = NULL;
- char offset_str[ADDR_STR_LEN];
if (!base_str || !result) {
goto error;
if (!base_str || !result) {
goto error;
offset = high_addr - low_addr;
offset = high_addr - low_addr;
- _result = malloc(strlen(base_str) + ADDR_STR_LEN);
+ _result = g_strdup_printf("%s+%#0" PRIx64, base_str, offset);
if (!_result) {
goto error;
}
if (!_result) {
goto error;
}
-
- ret = snprintf(offset_str, ADDR_STR_LEN, "+%#0" PRIx64, offset);
- if (ret < 0) {
- goto error;
- }
- strcpy(_result, base_str);
- strcat(_result, offset_str);
*result = _result;
return 0;
*result = _result;
return 0;
BT_HIDDEN
int bin_info_get_bin_loc(struct bin_info *bin, uint64_t addr, char **bin_loc)
{
BT_HIDDEN
int bin_info_get_bin_loc(struct bin_info *bin, uint64_t addr, char **bin_loc)
{
- int ret = 0;
- char *_bin_loc = NULL;
+ gchar *_bin_loc = NULL;
if (!bin || !bin_loc) {
goto error;
if (!bin || !bin_loc) {
goto error;
if (bin->is_pic) {
addr -= bin->low_addr;
if (bin->is_pic) {
addr -= bin->low_addr;
- ret = asprintf(&_bin_loc, "+%#0" PRIx64, addr);
+ _bin_loc = g_strdup_printf("+%#0" PRIx64, addr);
- ret = asprintf(&_bin_loc, "@%#0" PRIx64, addr);
+ _bin_loc = g_strdup_printf("@%#0" PRIx64, addr);
- if (ret == -1 || !_bin_loc) {
}
_src_loc->line_no = line_no;
}
_src_loc->line_no = line_no;
- _src_loc->filename = strdup(filename);
+ _src_loc->filename = g_strdup(filename);
}
bt_dwarf_die_destroy(die);
}
bt_dwarf_die_destroy(die);
/* Size of exec address space. */
uint64_t memsz;
/* Paths to ELF and DWARF files. */
/* Size of exec address space. */
uint64_t memsz;
/* Paths to ELF and DWARF files. */
- char *elf_path;
- char *dwarf_path;
+ gchar *elf_path;
+ gchar *dwarf_path;
/* libelf and libdw objects representing the files. */
Elf *elf_file;
Dwarf *dwarf_info;
/* libelf and libdw objects representing the files. */
Elf *elf_file;
Dwarf *dwarf_info;
size_t build_id_len;
/* Optional debug link info. */
size_t build_id_len;
/* Optional debug link info. */
- char *dbg_link_filename;
+ gchar *dbg_link_filename;
uint32_t dbg_link_crc;
/* FDs to ELF and DWARF files. */
int elf_fd;
int dwarf_fd;
/* Configuration. */
uint32_t dbg_link_crc;
/* FDs to ELF and DWARF files. */
int elf_fd;
int dwarf_fd;
/* Configuration. */
/* Denotes whether the executable is position independent code. */
bool is_pic:1;
/* denotes whether the build id in the trace matches to one on disk. */
/* Denotes whether the executable is position independent code. */
bool is_pic:1;
/* denotes whether the build id in the trace matches to one on disk. */
struct source_location {
uint64_t line_no;
struct source_location {
uint64_t line_no;
#define PATH_FIELD_NAME "path"
struct debug_info_component {
#define PATH_FIELD_NAME "path"
struct debug_info_component {
- char *arg_debug_info_field_name;
- const char *arg_debug_dir;
- bool arg_full_path;
- const char *arg_target_prefix;
+ gchar *arg_debug_dir;
+ gchar *arg_debug_info_field_name;
+ gchar *arg_target_prefix;
+ bt_bool arg_full_path;
};
struct debug_info_msg_iter {
};
struct debug_info_msg_iter {
struct debug_info_source {
/* Strings are owned by debug_info_source. */
struct debug_info_source {
/* Strings are owned by debug_info_source. */
/*
* Store the line number as a string so that the allocation and
* conversion to string is only done once.
*/
/*
* Store the line number as a string so that the allocation and
* conversion to string is only done once.
*/
- char *line_no;
- char *src_path;
+ gchar *line_no;
+ gchar *src_path;
/* short_src_path points inside src_path, no need to free. */
/* short_src_path points inside src_path, no need to free. */
- const char *short_src_path;
- char *bin_path;
+ const gchar *short_src_path;
+ gchar *bin_path;
/* short_bin_path points inside bin_path, no need to free. */
/* short_bin_path points inside bin_path, no need to free. */
- const char *short_bin_path;
+ const gchar *short_bin_path;
/*
* Location within the binary. Either absolute (@0x1234) or
* relative (+0x4321).
*/
/*
* Location within the binary. Either absolute (@0x1234) or
* relative (+0x4321).
*/
};
struct proc_debug_info_sources {
};
struct proc_debug_info_sources {
- free(debug_info_src->func);
- free(debug_info_src->line_no);
- free(debug_info_src->src_path);
- free(debug_info_src->bin_path);
- free(debug_info_src->bin_loc);
+ g_free(debug_info_src->func);
+ g_free(debug_info_src->line_no);
+ g_free(debug_info_src->src_path);
+ g_free(debug_info_src->bin_path);
+ g_free(debug_info_src->bin_loc);
g_free(debug_info_src);
}
g_free(debug_info_src);
}
- ret = asprintf(&debug_info_src->line_no, "%"PRId64, src_loc->line_no);
- if (ret == -1) {
+ debug_info_src->line_no =
+ g_strdup_printf("%"PRId64, src_loc->line_no);
+ if (!debug_info_src->line_no) {
BT_LOGD("Error occured when setting line_no field.");
goto error;
}
if (src_loc->filename) {
BT_LOGD("Error occured when setting line_no field.");
goto error;
}
if (src_loc->filename) {
- debug_info_src->src_path = strdup(src_loc->filename);
+ debug_info_src->src_path = g_strdup(src_loc->filename);
if (!debug_info_src->src_path) {
goto error;
}
if (!debug_info_src->src_path) {
goto error;
}
- debug_info_src->bin_path = strdup(bin->elf_path);
+ debug_info_src->bin_path = g_strdup(bin->elf_path);
if (!debug_info_src->bin_path) {
goto error;
}
if (!debug_info_src->bin_path) {
goto error;
}
static
void destroy_debug_info_comp(struct debug_info_component *debug_info)
{
static
void destroy_debug_info_comp(struct debug_info_component *debug_info)
{
- free(debug_info->arg_debug_info_field_name);
+ if (!debug_info) {
+ return;
+ }
+
+ g_free(debug_info->arg_debug_dir);
+ g_free(debug_info->arg_debug_info_field_name);
+ g_free(debug_info->arg_target_prefix);
struct debug_info *debug_info;
uint64_t vpid;
int64_t ip;
struct debug_info *debug_info;
uint64_t vpid;
int64_t ip;
- char *debug_info_field_name =
+ gchar *debug_info_field_name =
debug_it->debug_info_component->arg_debug_info_field_name;
in_common_ctx_field = bt_event_borrow_common_context_field_const(
debug_it->debug_info_component->arg_debug_info_field_name;
in_common_ctx_field = bt_event_borrow_common_context_field_const(
value = bt_value_map_borrow_entry_value_const(params,
"debug-info-field-name");
if (value) {
value = bt_value_map_borrow_entry_value_const(params,
"debug-info-field-name");
if (value) {
- const char *debug_info_field_name;
-
- debug_info_field_name = bt_value_string_get(value);
debug_info_component->arg_debug_info_field_name =
debug_info_component->arg_debug_info_field_name =
- strdup(debug_info_field_name);
+ g_strdup(bt_value_string_get(value));
} else {
debug_info_component->arg_debug_info_field_name =
} else {
debug_info_component->arg_debug_info_field_name =
- malloc(strlen(DEFAULT_DEBUG_INFO_FIELD_NAME) + 1);
- if (!debug_info_component->arg_debug_info_field_name) {
- ret = BT_SELF_COMPONENT_STATUS_NOMEM;
- BT_LOGE_STR("Missing field name.");
- goto end;
- }
- sprintf(debug_info_component->arg_debug_info_field_name,
- DEFAULT_DEBUG_INFO_FIELD_NAME);
- }
- if (ret) {
- goto end;
+ g_strdup(DEFAULT_DEBUG_INFO_FIELD_NAME);
}
value = bt_value_map_borrow_entry_value_const(params, "debug-info-dir");
if (value) {
}
value = bt_value_map_borrow_entry_value_const(params, "debug-info-dir");
if (value) {
- debug_info_component->arg_debug_dir = bt_value_string_get(value);
+ debug_info_component->arg_debug_dir =
+ g_strdup(bt_value_string_get(value));
+ } else {
+ debug_info_component->arg_debug_dir = NULL;
value = bt_value_map_borrow_entry_value_const(params, "target-prefix");
if (value) {
debug_info_component->arg_target_prefix =
value = bt_value_map_borrow_entry_value_const(params, "target-prefix");
if (value) {
debug_info_component->arg_target_prefix =
- bt_value_string_get(value);
+ g_strdup(bt_value_string_get(value));
+ } else {
+ debug_info_component->arg_target_prefix = NULL;
}
value = bt_value_map_borrow_entry_value_const(params, "full-path");
if (value) {
debug_info_component->arg_full_path = bt_value_bool_get(value);
}
value = bt_value_map_borrow_entry_value_const(params, "full-path");
if (value) {
debug_info_component->arg_full_path = bt_value_bool_get(value);
+ } else {
+ debug_info_component->arg_full_path = BT_FALSE;
struct bt_self_component_port_input *input_port;
bt_self_component_port_input_message_iterator *upstream_iterator;
struct debug_info_msg_iter *debug_info_msg_iter;
struct bt_self_component_port_input *input_port;
bt_self_component_port_input_message_iterator *upstream_iterator;
struct debug_info_msg_iter *debug_info_msg_iter;
+ gchar *debug_info_field_name;
/* Borrow the upstream input port. */
input_port = bt_self_component_filter_borrow_input_port_by_name(
/* Borrow the upstream input port. */
input_port = bt_self_component_filter_borrow_input_port_by_name(
+ /* Create hashtable to will contain debug info mapping. */
debug_info_msg_iter->debug_info_map = g_hash_table_new_full(
g_direct_hash, g_direct_equal,
(GDestroyNotify) NULL,
debug_info_msg_iter->debug_info_map = g_hash_table_new_full(
g_direct_hash, g_direct_equal,
(GDestroyNotify) NULL,
bt_self_component_filter_as_self_component(
self_comp));
bt_self_component_filter_as_self_component(
self_comp));
+ debug_info_field_name =
+ debug_info_msg_iter->debug_info_component->arg_debug_info_field_name;
+
debug_info_msg_iter->ir_maps = trace_ir_maps_create(
bt_self_component_filter_as_self_component(self_comp),
debug_info_msg_iter->ir_maps = trace_ir_maps_create(
bt_self_component_filter_as_self_component(self_comp),
- debug_info_msg_iter->debug_info_component->arg_debug_info_field_name);
+ debug_info_field_name);
if (!debug_info_msg_iter->ir_maps) {
g_hash_table_destroy(debug_info_msg_iter->debug_info_map);
g_free(debug_info_msg_iter);
if (!debug_info_msg_iter->ir_maps) {
g_hash_table_destroy(debug_info_msg_iter->debug_info_map);
g_free(debug_info_msg_iter);
+ *name = g_strdup(_name);
if (!*name) {
goto error;
}
if (!*name) {
goto error;
}
- *filename = strdup(_filename);
+ *filename = g_strdup(_filename);
bt_dwarf_die_destroy(cu_die);
g_free(file_attr);
bt_dwarf_die_destroy(cu_die);
g_free(file_attr);