Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: MIT
*/

#include <assert.h>
#include <coldtrace/config.h>
#include <coldtrace/utils.h>
#include <dice/log.h>
Expand All @@ -27,12 +26,19 @@ DICE_MODULE_INIT({
}
coldtrace_set_path(var);

if (ensure_dir_exists(var) != 0)
abort();
if (ensure_dir_exists(var) != 0) {
log_fatal(
"COLDTRACE_PATH '%s' already exists, choose a non-existing "
"directory",
var);
}

if (getenv("COLDTRACE_DISABLE_CLEANUP") == NULL)
if (ensure_dir_empty(var) != 0)
abort();
if (ensure_dir_empty(var) != 0) {
log_fatal(
"COLDTRACE_PATH '%s' is not empty, the directory must be empty",
var);
}

var = getenv("COLDTRACE_MAX_FILES");
if (var) {
Expand Down
9 changes: 6 additions & 3 deletions src/entries.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (C) 2025 Huawei Technologies Co., Ltd.
* SPDX-License-Identifier: MIT
*/
#include <assert.h>
#include <coldtrace/entries.h>
#include <dice/log.h>
#include <stdbool.h>
Expand Down Expand Up @@ -60,7 +59,9 @@ coldtrace_entry_parse_type(const void *buf)
uint64_t ptr = ((uint64_t *)buf)[0];
coldtrace_entry_type type =
(coldtrace_entry_type)(ptr & TYPE_MASK & ~ZERO_FLAG);
assert(is_type_valid(type));
if (!is_type_valid(type)) {
log_fatal("Invalid entry type (at %s:%d)", __FILE__, __LINE__);
}
return type;
}

Expand Down Expand Up @@ -202,6 +203,8 @@ static const size_t space_map_[] = {
size_t
coldtrace_entry_fixed_size(coldtrace_entry_type type)
{
assert(is_type_valid(type));
if (!is_type_valid(type)) {
log_fatal("Invalid entry type (at %s:%d)", __FILE__, __LINE__);
}
return space_map_[type & ~ZERO_FLAG];
}
10 changes: 8 additions & 2 deletions src/procmaps.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,16 @@ copy_maps_and_mapped_files_(void)
log_info("copy procmaps");

if (copy_proc_maps_(coldtrace_get_path()) != 0) {
abort();
log_fatal(
"Failed to copy /proc/self/maps to '%s', cannot generate coldtrace "
"dump",
coldtrace_get_path());
}
if (copy_mapped_files_(coldtrace_get_path()) != 0) {
abort();
log_fatal(
"Failed to copy mapped files to '%s', coldtrace dump will be "
"incomplete",
coldtrace_get_path());
}
}

Expand Down
1 change: 0 additions & 1 deletion src/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ coldtrace_thread_stack_pop(struct metadata *md)
{
struct coldtrace_thread *th = get_coldtrace_thread(md);
if (!th->stack.empty()) {
assert(!th->stack.empty());
th->stack.pop_back();
th->stack_bottom =
std::min(th->stack_bottom, (uint32_t)th->stack.size());
Expand Down
15 changes: 11 additions & 4 deletions src/writer.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <assert.h>
#include <coldtrace/config.h>
#include <coldtrace/version.h>
#include <coldtrace/writer.h>
Expand Down Expand Up @@ -50,7 +49,9 @@ STATIC_ASSERT(sizeof(struct writer_impl) == sizeof(struct coldtrace_writer),
static void
get_trace_(struct writer_impl *impl)
{
assert(impl->initd);
if (!impl->initd) {
log_fatal("Writer not initialized (at %s:%d)", __FILE__, __LINE__);
}
if (impl->buffer) {
return;
}
Expand Down Expand Up @@ -156,8 +157,14 @@ DICE_HIDE void
coldtrace_writer_init(struct coldtrace_writer *ct, metadata_t *md)
{
// Ensure the size of implementation matches the public size
assert(sizeof(struct writer_impl) == sizeof(struct coldtrace_writer));
assert(md != NULL);
if (sizeof(struct writer_impl) != sizeof(struct coldtrace_writer)) {
log_fatal(
"Size mismatch between writer_impl %zu and coldtrace_writer %zu",
sizeof(struct writer_impl), sizeof(struct coldtrace_writer));
}
if (md == NULL) {
log_fatal("No metadata provided (at %s:%d)", __FILE__, __LINE__);
}
struct writer_impl *impl;
impl = (struct writer_impl *)ct;
impl->initd = true;
Expand Down
1 change: 0 additions & 1 deletion test/simple_malloc_test.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <assert.h>
#include <stdlib.h>

// NOLINTBEGIN
Expand Down
1 change: 0 additions & 1 deletion test/simple_mmap_test.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <assert.h>
#include <stdlib.h>
#include <sys/mman.h>

Expand Down
1 change: 0 additions & 1 deletion test/trace_lock_unlock.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <assert.h>
#include <dice/log.h>
#include <pthread.h>
#include <stdbool.h>
Expand Down
1 change: 0 additions & 1 deletion test/trace_write_var.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "trace_checker.h"

#include <assert.h>
#include <dice/log.h>
#include <pthread.h>
#include <stdbool.h>
Expand Down