Replaced some un-ergonomic unique_ptr use with make_unique, switched some unique_ptr<T[]> use to just std::vector<T>, and added some RAII protection to dbghelp symbol resolution TI_FINDCHILDREN_PARAMS management
This commit is contained in:
parent
3a4da8ccf0
commit
9b02fc6f74
@ -642,12 +642,12 @@ namespace detail {
|
|||||||
return common;
|
return common;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<std::unique_ptr<char[]>, internal_error> mach_o::load_string_table(std::uint32_t offset, std::uint32_t byte_count) const {
|
Result<std::vector<char>, internal_error> mach_o::load_string_table(std::uint32_t offset, std::uint32_t byte_count) const {
|
||||||
std::unique_ptr<char[]> buffer(new char[byte_count + 1]);
|
std::vector<char> buffer(byte_count + 1);
|
||||||
if(std::fseek(file, load_base + offset, SEEK_SET) != 0) {
|
if(std::fseek(file, load_base + offset, SEEK_SET) != 0) {
|
||||||
return internal_error("fseek error while loading mach-o symbol table");
|
return internal_error("fseek error while loading mach-o symbol table");
|
||||||
}
|
}
|
||||||
if(std::fread(buffer.get(), sizeof(char), byte_count, file) != byte_count) {
|
if(std::fread(buffer.data(), sizeof(char), byte_count, file) != byte_count) {
|
||||||
return internal_error("fread error while loading mach-o symbol table");
|
return internal_error("fread error while loading mach-o symbol table");
|
||||||
}
|
}
|
||||||
buffer[byte_count] = 0; // just out of an abundance of caution
|
buffer[byte_count] = 0; // just out of an abundance of caution
|
||||||
|
|||||||
@ -63,7 +63,7 @@ namespace detail {
|
|||||||
|
|
||||||
struct symtab_info_data {
|
struct symtab_info_data {
|
||||||
symtab_command symtab;
|
symtab_command symtab;
|
||||||
std::unique_ptr<char[]> stringtab;
|
std::vector<char> stringtab;
|
||||||
Result<const char*, internal_error> get_string(std::size_t index) const;
|
Result<const char*, internal_error> get_string(std::size_t index) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ namespace detail {
|
|||||||
template<std::size_t Bits>
|
template<std::size_t Bits>
|
||||||
Result<nlist_64, internal_error> load_symtab_entry(std::uint32_t symbol_base, std::size_t index) const;
|
Result<nlist_64, internal_error> load_symtab_entry(std::uint32_t symbol_base, std::size_t index) const;
|
||||||
|
|
||||||
Result<std::unique_ptr<char[]>, internal_error> load_string_table(std::uint32_t offset, std::uint32_t byte_count) const;
|
Result<std::vector<char>, internal_error> load_string_table(std::uint32_t offset, std::uint32_t byte_count) const;
|
||||||
|
|
||||||
bool should_swap() const;
|
bool should_swap() const;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -34,7 +34,7 @@ namespace libdwarf {
|
|||||||
if(!resolver) {
|
if(!resolver) {
|
||||||
// this seems silly but it's an attempt to not repeatedly try to initialize new dwarf_resolvers if
|
// this seems silly but it's an attempt to not repeatedly try to initialize new dwarf_resolvers if
|
||||||
// exceptions are thrown, e.g. if the path doesn't exist
|
// exceptions are thrown, e.g. if the path doesn't exist
|
||||||
resolver = std::unique_ptr<null_resolver>(new null_resolver);
|
resolver = detail::make_unique<null_resolver>();
|
||||||
resolver = make_dwarf_resolver(object_path);
|
resolver = make_dwarf_resolver(object_path);
|
||||||
}
|
}
|
||||||
return resolver;
|
return resolver;
|
||||||
@ -198,7 +198,7 @@ namespace libdwarf {
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<symbol_resolver> make_debug_map_resolver(const std::string& object_path) {
|
std::unique_ptr<symbol_resolver> make_debug_map_resolver(const std::string& object_path) {
|
||||||
return std::unique_ptr<debug_map_resolver>(new debug_map_resolver(object_path));
|
return detail::make_unique<debug_map_resolver>(object_path);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@ -932,12 +932,7 @@ namespace libdwarf {
|
|||||||
if(it == split_full_cu_resolvers.end()) {
|
if(it == split_full_cu_resolvers.end()) {
|
||||||
it = split_full_cu_resolvers.emplace(
|
it = split_full_cu_resolvers.emplace(
|
||||||
off,
|
off,
|
||||||
std::unique_ptr<dwarf_resolver>(
|
detail::make_unique<dwarf_resolver>(path, skeleton_info{cu_die.clone(), dwversion, *this})
|
||||||
new dwarf_resolver(
|
|
||||||
path,
|
|
||||||
skeleton_info{cu_die.clone(), dwversion, *this}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
).first;
|
).first;
|
||||||
}
|
}
|
||||||
res = it->second->resolve_frame(object_frame_info);
|
res = it->second->resolve_frame(object_frame_info);
|
||||||
@ -1015,7 +1010,7 @@ namespace libdwarf {
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<symbol_resolver> make_dwarf_resolver(const std::string& object_path) {
|
std::unique_ptr<symbol_resolver> make_dwarf_resolver(const std::string& object_path) {
|
||||||
return std::unique_ptr<dwarf_resolver>(new dwarf_resolver(object_path));
|
return detail::make_unique<dwarf_resolver>(object_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include "binary/object.hpp"
|
#include "binary/object.hpp"
|
||||||
#include "utils/common.hpp"
|
#include "utils/common.hpp"
|
||||||
#include "utils/error.hpp"
|
#include "utils/error.hpp"
|
||||||
|
#include "utils/utils.hpp"
|
||||||
#include "options.hpp"
|
#include "options.hpp"
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
@ -239,6 +240,9 @@ namespace dbghelp {
|
|||||||
std::size_t sz = sizeof(TI_FINDCHILDREN_PARAMS) +
|
std::size_t sz = sizeof(TI_FINDCHILDREN_PARAMS) +
|
||||||
(n_children) * sizeof(TI_FINDCHILDREN_PARAMS::ChildId[0]);
|
(n_children) * sizeof(TI_FINDCHILDREN_PARAMS::ChildId[0]);
|
||||||
TI_FINDCHILDREN_PARAMS* children = (TI_FINDCHILDREN_PARAMS*) new char[sz];
|
TI_FINDCHILDREN_PARAMS* children = (TI_FINDCHILDREN_PARAMS*) new char[sz];
|
||||||
|
auto guard = scope_exit([&] {
|
||||||
|
delete[] (char*) children;
|
||||||
|
});
|
||||||
children->Start = 0;
|
children->Start = 0;
|
||||||
children->Count = n_children;
|
children->Count = n_children;
|
||||||
if(
|
if(
|
||||||
@ -264,7 +268,6 @@ namespace dbghelp {
|
|||||||
extent += (i == 0 ? "" : ", ") + resolve_type(children->ChildId[i], proc, modbase);
|
extent += (i == 0 ? "" : ", ") + resolve_type(children->ChildId[i], proc, modbase);
|
||||||
}
|
}
|
||||||
extent += ")";
|
extent += ")";
|
||||||
delete[] (char*) children;
|
|
||||||
return {return_type.base, extent + return_type.extent};
|
return {return_type.base, extent + return_type.extent};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user