Some updates and cleanup

This commit is contained in:
Jeremy 2023-09-19 00:21:00 -04:00
parent a68277fc2b
commit 704cba5e97
No known key found for this signature in database
GPG Key ID: 19AA8270105E8EB4
2 changed files with 22 additions and 20 deletions

View File

@ -132,8 +132,8 @@ namespace cpptrace {
}; };
/* /*
* Object trace with object file information for each frame, any accessible symbol information, and the address in * Object trace with object file information for each frame, any accessible symbol information,
* the object file for the frame's program counter. * and the address in the object file for the frame's program counter.
*/ */
struct object_frame { struct object_frame {
std::string obj_path; std::string obj_path;
@ -187,13 +187,16 @@ namespace cpptrace {
std::string demangle(const std::string& name); std::string demangle(const std::string& name);
// Traced exception class // Traced exception class
// Extending classes should call the exception constructor with a skip value of 1.
class exception : public std::exception { class exception : public std::exception {
explicit exception(uint32_t skip)
public: public:
explicit exception(); explicit exception();
const char* what() const noexcept override; const char* what() const noexcept override;
}; };
class exception_with_message : public exception { class exception_with_message : public exception {
explicit exception_with_message(std::string&& message_arg, uint32_t skip)
public: public:
explicit exception_with_message(std::string&& message_arg); explicit exception_with_message(std::string&& message_arg);
const char* what() const noexcept override; const char* what() const noexcept override;

View File

@ -26,15 +26,14 @@
// TODO // TODO
// Inlined calls // Inlined calls
// Memoizing / lazy loading
// More utils to clean this up, some wrapper for unique_ptr // More utils to clean this up, some wrapper for unique_ptr
// Ensure memory is being cleaned up properly // Ensure memory is being cleaned up properly
// Efficiency tricks
// Implementation cleanup
// Properly get the image base
#define DW_PR_DUx "llx" #if false
#define DW_PR_DUu "llu" #define CPPTRACE_FORCE_NO_INLINE_FOR_PROFILING CPPTRACE_FORCE_NO_INLINE
#else
#define CPPTRACE_FORCE_NO_INLINE_FOR_PROFILING
#endif
namespace cpptrace { namespace cpptrace {
namespace detail { namespace detail {
@ -516,7 +515,7 @@ namespace libdwarf {
std::unordered_map<Dwarf_Off, line_context> line_contexts; std::unordered_map<Dwarf_Off, line_context> line_contexts;
std::unordered_map<Dwarf_Off, std::vector<subprogram_entry>> subprograms_cache; std::unordered_map<Dwarf_Off, std::vector<subprogram_entry>> subprograms_cache;
CPPTRACE_FORCE_NO_INLINE CPPTRACE_FORCE_NO_INLINE_FOR_PROFILING
dwarf_resolver(const std::string& object_path) { dwarf_resolver(const std::string& object_path) {
obj_path = object_path; obj_path = object_path;
#if IS_APPLE #if IS_APPLE
@ -544,7 +543,7 @@ namespace libdwarf {
} }
} }
CPPTRACE_FORCE_NO_INLINE CPPTRACE_FORCE_NO_INLINE_FOR_PROFILING
~dwarf_resolver() { ~dwarf_resolver() {
// TODO: Maybe redundant since dwarf_finish(dbg); will clean up the line stuff anyway but may as well just // TODO: Maybe redundant since dwarf_finish(dbg); will clean up the line stuff anyway but may as well just
// for thoroughness // for thoroughness
@ -653,7 +652,7 @@ namespace libdwarf {
} }
// returns true if this call found the symbol // returns true if this call found the symbol
CPPTRACE_FORCE_NO_INLINE CPPTRACE_FORCE_NO_INLINE_FOR_PROFILING
bool retrieve_symbol_walk( bool retrieve_symbol_walk(
const die_object& die, const die_object& die,
Dwarf_Addr pc, Dwarf_Addr pc,
@ -711,7 +710,7 @@ namespace libdwarf {
return found; return found;
} }
CPPTRACE_FORCE_NO_INLINE CPPTRACE_FORCE_NO_INLINE_FOR_PROFILING
void preprocess_subprograms( void preprocess_subprograms(
const die_object& die, const die_object& die,
Dwarf_Half dwversion, Dwarf_Half dwversion,
@ -752,7 +751,7 @@ namespace libdwarf {
); );
} }
CPPTRACE_FORCE_NO_INLINE CPPTRACE_FORCE_NO_INLINE_FOR_PROFILING
void retrieve_symbol( void retrieve_symbol(
const die_object& cu_die, const die_object& cu_die,
Dwarf_Addr pc, Dwarf_Addr pc,
@ -808,7 +807,7 @@ namespace libdwarf {
dwarf_lineno(line, &lineno, nullptr); dwarf_lineno(line, &lineno, nullptr);
} }
if(dump_dwarf) { if(dump_dwarf) {
printf("%s:%" DW_PR_DUu "\n", linesrc, lineno); printf("%s:%u\n", linesrc, to<unsigned>(lineno));
} }
frame.line = static_cast<uint_least32_t>(lineno); frame.line = static_cast<uint_least32_t>(lineno);
frame.filename = linesrc; frame.filename = linesrc;
@ -818,7 +817,7 @@ namespace libdwarf {
} }
// retrieve_line_info code based on libdwarf-addr2line // retrieve_line_info code based on libdwarf-addr2line
CPPTRACE_FORCE_NO_INLINE CPPTRACE_FORCE_NO_INLINE_FOR_PROFILING
void retrieve_line_info( void retrieve_line_info(
const die_object& die, const die_object& die,
Dwarf_Addr pc, Dwarf_Addr pc,
@ -894,7 +893,7 @@ namespace libdwarf {
} }
} }
CPPTRACE_FORCE_NO_INLINE CPPTRACE_FORCE_NO_INLINE_FOR_PROFILING
void walk_compilation_units(Dwarf_Addr pc, stacktrace_frame& frame) { void walk_compilation_units(Dwarf_Addr pc, stacktrace_frame& frame) {
// 0 passed as the die to the first call of dwarf_siblingof_b immediately after dwarf_next_cu_header_d // 0 passed as the die to the first call of dwarf_siblingof_b immediately after dwarf_next_cu_header_d
// to fetch the cu die // to fetch the cu die
@ -937,7 +936,7 @@ namespace libdwarf {
); );
} }
CPPTRACE_FORCE_NO_INLINE CPPTRACE_FORCE_NO_INLINE_FOR_PROFILING
void walk_dbg(Dwarf_Addr pc, stacktrace_frame& frame) { void walk_dbg(Dwarf_Addr pc, stacktrace_frame& frame) {
// 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;
@ -973,7 +972,7 @@ namespace libdwarf {
} }
} }
CPPTRACE_FORCE_NO_INLINE CPPTRACE_FORCE_NO_INLINE_FOR_PROFILING
void lookup_pc( void lookup_pc(
Dwarf_Addr pc, Dwarf_Addr pc,
stacktrace_frame& frame stacktrace_frame& frame
@ -1013,7 +1012,7 @@ namespace libdwarf {
} }
} }
CPPTRACE_FORCE_NO_INLINE CPPTRACE_FORCE_NO_INLINE_FOR_PROFILING
stacktrace_frame resolve_frame(const object_frame& frame_info) { stacktrace_frame resolve_frame(const object_frame& frame_info) {
stacktrace_frame frame{}; stacktrace_frame frame{};
frame.filename = frame_info.obj_path; frame.filename = frame_info.obj_path;
@ -1036,7 +1035,7 @@ namespace libdwarf {
} }
}; };
CPPTRACE_FORCE_NO_INLINE CPPTRACE_FORCE_NO_INLINE_FOR_PROFILING
std::vector<stacktrace_frame> resolve_frames(const std::vector<object_frame>& frames) { std::vector<stacktrace_frame> resolve_frames(const std::vector<object_frame>& frames) {
std::vector<stacktrace_frame> trace(frames.size(), stacktrace_frame { 0, 0, 0, "", "" }); std::vector<stacktrace_frame> trace(frames.size(), stacktrace_frame { 0, 0, 0, "", "" });
for(const auto& obj_entry : collate_frames(frames, trace)) { for(const auto& obj_entry : collate_frames(frames, trace)) {