Merge branch 'jr/sonar-fixes' into main
This commit is contained in:
commit
a9964f3a5e
@ -51,7 +51,7 @@ namespace cpptrace {
|
|||||||
namespace detail {
|
namespace detail {
|
||||||
// Placed here instead of utils because it's used by error.hpp and utils.hpp
|
// Placed here instead of utils because it's used by error.hpp and utils.hpp
|
||||||
template<typename... T> std::string stringf(T... args) {
|
template<typename... T> std::string stringf(T... args) {
|
||||||
int length = snprintf(0, 0, args...);
|
int length = snprintf(nullptr, 0, args...);
|
||||||
if(length < 0) {
|
if(length < 0) {
|
||||||
throw std::logic_error("invalid arguments to stringf");
|
throw std::logic_error("invalid arguments to stringf");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ namespace libdwarf {
|
|||||||
static_assert(std::is_pointer<Dwarf_Die>::value, "Dwarf_Die not a pointer");
|
static_assert(std::is_pointer<Dwarf_Die>::value, "Dwarf_Die not a pointer");
|
||||||
static_assert(std::is_pointer<Dwarf_Debug>::value, "Dwarf_Debug not a pointer");
|
static_assert(std::is_pointer<Dwarf_Debug>::value, "Dwarf_Debug not a pointer");
|
||||||
|
|
||||||
void handle_dwarf_error(Dwarf_Debug dbg, Dwarf_Error error) {
|
[[noreturn]] void handle_dwarf_error(Dwarf_Debug dbg, Dwarf_Error error) {
|
||||||
int ev = dwarf_errno(error);
|
int ev = dwarf_errno(error);
|
||||||
char* msg = dwarf_errmsg(error);
|
char* msg = dwarf_errmsg(error);
|
||||||
dwarf_dealloc_error(dbg, error);
|
dwarf_dealloc_error(dbg, error);
|
||||||
@ -46,7 +46,7 @@ namespace libdwarf {
|
|||||||
>::type = 0
|
>::type = 0
|
||||||
>
|
>
|
||||||
int wrap(int (*f)(Args...), Args2&&... args) const {
|
int wrap(int (*f)(Args...), Args2&&... args) const {
|
||||||
Dwarf_Error error = 0;
|
Dwarf_Error error = nullptr;
|
||||||
int ret = f(std::forward<Args2>(args)..., &error);
|
int ret = f(std::forward<Args2>(args)..., &error);
|
||||||
if(ret == DW_DLV_ERROR) {
|
if(ret == DW_DLV_ERROR) {
|
||||||
handle_dwarf_error(dbg, error);
|
handle_dwarf_error(dbg, error);
|
||||||
@ -85,7 +85,7 @@ namespace libdwarf {
|
|||||||
die_object clone() const {
|
die_object clone() const {
|
||||||
Dwarf_Off global_offset = get_global_offset();
|
Dwarf_Off global_offset = get_global_offset();
|
||||||
Dwarf_Bool is_info = dwarf_get_die_infotypes_flag(die);
|
Dwarf_Bool is_info = dwarf_get_die_infotypes_flag(die);
|
||||||
Dwarf_Die die_copy = 0;
|
Dwarf_Die die_copy = nullptr;
|
||||||
VERIFY(wrap(dwarf_offdie_b, dbg, global_offset, is_info, &die_copy) == DW_DLV_OK);
|
VERIFY(wrap(dwarf_offdie_b, dbg, global_offset, is_info, &die_copy) == DW_DLV_OK);
|
||||||
return {dbg, die_copy};
|
return {dbg, die_copy};
|
||||||
}
|
}
|
||||||
@ -96,19 +96,19 @@ namespace libdwarf {
|
|||||||
if(ret == DW_DLV_OK) {
|
if(ret == DW_DLV_OK) {
|
||||||
return die_object(dbg, child);
|
return die_object(dbg, child);
|
||||||
} else if(ret == DW_DLV_NO_ENTRY) {
|
} else if(ret == DW_DLV_NO_ENTRY) {
|
||||||
return die_object(dbg, 0);
|
return die_object(dbg, nullptr);
|
||||||
} else {
|
} else {
|
||||||
PANIC();
|
PANIC();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
die_object get_sibling() const {
|
die_object get_sibling() const {
|
||||||
Dwarf_Die sibling = 0;
|
Dwarf_Die sibling = nullptr;
|
||||||
int ret = wrap(dwarf_siblingof_b, dbg, die, true, &sibling);
|
int ret = wrap(dwarf_siblingof_b, dbg, die, true, &sibling);
|
||||||
if(ret == DW_DLV_OK) {
|
if(ret == DW_DLV_OK) {
|
||||||
return die_object(dbg, sibling);
|
return die_object(dbg, sibling);
|
||||||
} else if(ret == DW_DLV_NO_ENTRY) {
|
} else if(ret == DW_DLV_NO_ENTRY) {
|
||||||
return die_object(dbg, 0);
|
return die_object(dbg, nullptr);
|
||||||
} else {
|
} else {
|
||||||
PANIC();
|
PANIC();
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ namespace libdwarf {
|
|||||||
VERIFY(wrap(dwarf_formref, attr, &off, &is_info) == DW_DLV_OK);
|
VERIFY(wrap(dwarf_formref, attr, &off, &is_info) == DW_DLV_OK);
|
||||||
Dwarf_Off global_offset = 0;
|
Dwarf_Off global_offset = 0;
|
||||||
VERIFY(wrap(dwarf_convert_to_global_offset, attr, off, &global_offset) == DW_DLV_OK);
|
VERIFY(wrap(dwarf_convert_to_global_offset, attr, off, &global_offset) == DW_DLV_OK);
|
||||||
Dwarf_Die target = 0;
|
Dwarf_Die target = nullptr;
|
||||||
VERIFY(wrap(dwarf_offdie_b, dbg, global_offset, is_info, &target) == DW_DLV_OK);
|
VERIFY(wrap(dwarf_offdie_b, dbg, global_offset, is_info, &target) == DW_DLV_OK);
|
||||||
return die_object(dbg, target);
|
return die_object(dbg, target);
|
||||||
}
|
}
|
||||||
@ -202,7 +202,7 @@ namespace libdwarf {
|
|||||||
Dwarf_Off off;
|
Dwarf_Off off;
|
||||||
VERIFY(wrap(dwarf_global_formref, attr, &off) == DW_DLV_OK);
|
VERIFY(wrap(dwarf_global_formref, attr, &off) == DW_DLV_OK);
|
||||||
int is_info = dwarf_get_die_infotypes_flag(die);
|
int is_info = dwarf_get_die_infotypes_flag(die);
|
||||||
Dwarf_Die target = 0;
|
Dwarf_Die target = nullptr;
|
||||||
VERIFY(wrap(dwarf_offdie_b, dbg, off, is_info, &target) == DW_DLV_OK);
|
VERIFY(wrap(dwarf_offdie_b, dbg, off, is_info, &target) == DW_DLV_OK);
|
||||||
return die_object(dbg, target);
|
return die_object(dbg, target);
|
||||||
}
|
}
|
||||||
@ -210,7 +210,7 @@ namespace libdwarf {
|
|||||||
{
|
{
|
||||||
Dwarf_Sig8 signature;
|
Dwarf_Sig8 signature;
|
||||||
VERIFY(wrap(dwarf_formsig8, attr, &signature) == DW_DLV_OK);
|
VERIFY(wrap(dwarf_formsig8, attr, &signature) == DW_DLV_OK);
|
||||||
Dwarf_Die target = 0;
|
Dwarf_Die target = nullptr;
|
||||||
Dwarf_Bool targ_is_info = false;
|
Dwarf_Bool targ_is_info = false;
|
||||||
VERIFY(wrap(dwarf_find_die_given_sig8, dbg, &signature, &target, &targ_is_info) == DW_DLV_OK);
|
VERIFY(wrap(dwarf_find_die_given_sig8, dbg, &signature, &target, &targ_is_info) == DW_DLV_OK);
|
||||||
return die_object(dbg, target);
|
return die_object(dbg, target);
|
||||||
@ -234,7 +234,7 @@ namespace libdwarf {
|
|||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
void dwarf5_ranges(F callback) const {
|
void dwarf5_ranges(F callback) const {
|
||||||
Dwarf_Attribute attr = 0;
|
Dwarf_Attribute attr = nullptr;
|
||||||
if(wrap(dwarf_attr, die, DW_AT_ranges, &attr) != DW_DLV_OK) {
|
if(wrap(dwarf_attr, die, DW_AT_ranges, &attr) != DW_DLV_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -243,7 +243,7 @@ namespace libdwarf {
|
|||||||
Dwarf_Half form = 0;
|
Dwarf_Half form = 0;
|
||||||
VERIFY(wrap(dwarf_whatform, attr, &form) == DW_DLV_OK);
|
VERIFY(wrap(dwarf_whatform, attr, &form) == DW_DLV_OK);
|
||||||
// get .debug_rnglists info
|
// get .debug_rnglists info
|
||||||
Dwarf_Rnglists_Head head = 0;
|
Dwarf_Rnglists_Head head = nullptr;
|
||||||
Dwarf_Unsigned rnglists_entries = 0;
|
Dwarf_Unsigned rnglists_entries = 0;
|
||||||
Dwarf_Unsigned dw_global_offset_of_rle_set = 0;
|
Dwarf_Unsigned dw_global_offset_of_rle_set = 0;
|
||||||
int res = wrap(
|
int res = wrap(
|
||||||
@ -312,7 +312,7 @@ namespace libdwarf {
|
|||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
void dwarf4_ranges(Dwarf_Addr lowpc, F callback) const {
|
void dwarf4_ranges(Dwarf_Addr lowpc, F callback) const {
|
||||||
Dwarf_Attribute attr = 0;
|
Dwarf_Attribute attr = nullptr;
|
||||||
if(wrap(dwarf_attr, die, DW_AT_ranges, &attr) != DW_DLV_OK) {
|
if(wrap(dwarf_attr, die, DW_AT_ranges, &attr) != DW_DLV_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -325,7 +325,7 @@ namespace libdwarf {
|
|||||||
if(lowpc != std::numeric_limits<Dwarf_Addr>::max()) {
|
if(lowpc != std::numeric_limits<Dwarf_Addr>::max()) {
|
||||||
baseaddr = lowpc;
|
baseaddr = lowpc;
|
||||||
}
|
}
|
||||||
Dwarf_Ranges* ranges = 0;
|
Dwarf_Ranges* ranges = nullptr;
|
||||||
Dwarf_Signed count = 0;
|
Dwarf_Signed count = 0;
|
||||||
VERIFY(
|
VERIFY(
|
||||||
wrap(
|
wrap(
|
||||||
@ -430,7 +430,7 @@ namespace libdwarf {
|
|||||||
// returns true if traversal should continue
|
// returns true if traversal should continue
|
||||||
bool walk_die_list(
|
bool walk_die_list(
|
||||||
const die_object& die,
|
const die_object& die,
|
||||||
std::function<bool(const die_object&)> fn
|
const std::function<bool(const die_object&)>& fn
|
||||||
) {
|
) {
|
||||||
// TODO: Refactor so there is only one fn call
|
// TODO: Refactor so there is only one fn call
|
||||||
bool continue_traversal = true;
|
bool continue_traversal = true;
|
||||||
@ -453,7 +453,7 @@ namespace libdwarf {
|
|||||||
// returns true if traversal should continue
|
// returns true if traversal should continue
|
||||||
bool walk_die_list_recursive(
|
bool walk_die_list_recursive(
|
||||||
const die_object& die,
|
const die_object& die,
|
||||||
std::function<bool(const die_object&)> fn
|
const std::function<bool(const die_object&)>& fn
|
||||||
) {
|
) {
|
||||||
return walk_die_list(
|
return walk_die_list(
|
||||||
die,
|
die,
|
||||||
|
|||||||
@ -47,7 +47,7 @@ namespace detail {
|
|||||||
constexpr const char* assert_actions[] = {"assertion", "verification", "panic"};
|
constexpr const char* assert_actions[] = {"assertion", "verification", "panic"};
|
||||||
constexpr const char* assert_names[] = {"ASSERT", "VERIFY", "PANIC"};
|
constexpr const char* assert_names[] = {"ASSERT", "VERIFY", "PANIC"};
|
||||||
|
|
||||||
inline void assert_fail(
|
[[noreturn]] inline void assert_fail(
|
||||||
assert_type type,
|
assert_type type,
|
||||||
const char* expression,
|
const char* expression,
|
||||||
const char* signature,
|
const char* signature,
|
||||||
|
|||||||
@ -95,7 +95,7 @@ namespace libdwarf {
|
|||||||
>::type = 0
|
>::type = 0
|
||||||
>
|
>
|
||||||
int wrap(int (*f)(Args...), Args2&&... args) const {
|
int wrap(int (*f)(Args...), Args2&&... args) const {
|
||||||
Dwarf_Error error = 0;
|
Dwarf_Error error = nullptr;
|
||||||
int ret = f(std::forward<Args2>(args)..., &error);
|
int ret = f(std::forward<Args2>(args)..., &error);
|
||||||
if(ret == DW_DLV_ERROR) {
|
if(ret == DW_DLV_ERROR) {
|
||||||
handle_dwarf_error(dbg, error);
|
handle_dwarf_error(dbg, error);
|
||||||
@ -211,7 +211,7 @@ namespace libdwarf {
|
|||||||
|
|
||||||
// walk all CU's in a dbg, callback is called on each die and should return true to
|
// walk all CU's in a dbg, callback is called on each die and should return true to
|
||||||
// continue traversal
|
// continue traversal
|
||||||
void walk_compilation_units(std::function<bool(const die_object&)> fn) {
|
void walk_compilation_units(const std::function<bool(const die_object&)>& fn) {
|
||||||
// libdwarf keeps track of where it is in the file, dwarf_next_cu_header_d is statefull
|
// libdwarf keeps track of where it is in the file, dwarf_next_cu_header_d is statefull
|
||||||
Dwarf_Unsigned next_cu_header;
|
Dwarf_Unsigned next_cu_header;
|
||||||
Dwarf_Half header_cu_type;
|
Dwarf_Half header_cu_type;
|
||||||
@ -467,7 +467,7 @@ namespace libdwarf {
|
|||||||
VERIFY(ret == DW_DLV_OK);
|
VERIFY(ret == DW_DLV_OK);
|
||||||
line_contexts.insert({off, {version, line_context}});
|
line_contexts.insert({off, {version, line_context}});
|
||||||
}
|
}
|
||||||
Dwarf_Line* line_buffer = 0;
|
Dwarf_Line* line_buffer = nullptr;
|
||||||
Dwarf_Signed line_count = 0;
|
Dwarf_Signed line_count = 0;
|
||||||
Dwarf_Line* linebuf_actuals = nullptr;
|
Dwarf_Line* linebuf_actuals = nullptr;
|
||||||
Dwarf_Signed linecount_actuals = 0;
|
Dwarf_Signed linecount_actuals = 0;
|
||||||
@ -482,7 +482,7 @@ namespace libdwarf {
|
|||||||
) == DW_DLV_OK
|
) == DW_DLV_OK
|
||||||
);
|
);
|
||||||
Dwarf_Addr last_lineaddr = 0;
|
Dwarf_Addr last_lineaddr = 0;
|
||||||
Dwarf_Line last_line = 0;
|
Dwarf_Line last_line = nullptr;
|
||||||
for(int i = 0; i < line_count; i++) {
|
for(int i = 0; i < line_count; i++) {
|
||||||
Dwarf_Line line = line_buffer[i];
|
Dwarf_Line line = line_buffer[i];
|
||||||
Dwarf_Addr lineaddr = 0;
|
Dwarf_Addr lineaddr = 0;
|
||||||
@ -519,7 +519,7 @@ namespace libdwarf {
|
|||||||
VERIFY(wrap(dwarf_lineendsequence, line, &is_line_end) == DW_DLV_OK);
|
VERIFY(wrap(dwarf_lineendsequence, line, &is_line_end) == DW_DLV_OK);
|
||||||
if(is_line_end) {
|
if(is_line_end) {
|
||||||
last_lineaddr = 0;
|
last_lineaddr = 0;
|
||||||
last_line = 0;
|
last_line = nullptr;
|
||||||
} else {
|
} else {
|
||||||
last_lineaddr = lineaddr;
|
last_lineaddr = lineaddr;
|
||||||
last_line = line;
|
last_line = line;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user