Skip to content

Commit b8a1914

Browse files
Fix for issue #72.
1 parent aaeae49 commit b8a1914

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

src/dwarf.cpp

+31-22
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ bool has_flag_attribute(const attribute_sequence& attributes, dw::at name) {
198198

199199
std::size_t die_hash(const die& d, const attribute_sequence& attributes) {
200200
ZoneScoped;
201-
201+
202202
// Ideally, tag would not be part of this hash and all symbols, regardless of tag, would be
203203
// unique. However, that fails in at least one case:
204204
//
@@ -221,11 +221,8 @@ std::size_t die_hash(const die& d, const attribute_sequence& attributes) {
221221
auto tag = d._tag == dw::tag::structure_type ? dw::tag::class_type : d._tag;
222222

223223
// clang-tidy off
224-
return orc::hash_combine(0,
225-
static_cast<std::size_t>(d._arch),
226-
static_cast<std::size_t>(tag),
227-
has_flag_attribute(attributes, dw::at::declaration),
228-
d._path.hash());
224+
return orc::hash_combine(0, static_cast<std::size_t>(d._arch), static_cast<std::size_t>(tag),
225+
has_flag_attribute(attributes, dw::at::declaration), d._path.hash());
229226
// clang-tidy on
230227
};
231228

@@ -575,15 +572,14 @@ pool_string dwarf::implementation::read_debug_str(std::size_t offset) {
575572

576573
++total_s;
577574

578-
thread_local const char* plot_name_k = []{
579-
const char* result = orc::tracy::format_unique("debug_str cache %s", orc::tracy::unique_thread_name());
575+
thread_local const char* plot_name_k = [] {
576+
const char* result =
577+
orc::tracy::format_unique("debug_str cache %s", orc::tracy::unique_thread_name());
580578
TracyPlotConfig(result, tracy::PlotFormatType::Percentage, true, true, 0);
581579
return result;
582580
}();
583581

584-
const auto update_zone = [&]{
585-
tracy::Profiler::PlotData(plot_name_k, hit_s / total_s * 100);
586-
};
582+
const auto update_zone = [&] { tracy::Profiler::PlotData(plot_name_k, hit_s / total_s * 100); };
587583
#endif // ORC_FEATURE(DEBUG_STR_CACHE)
588584

589585
// I tried an implementation that loaded the whole debug_str section into the string pool on
@@ -888,9 +884,7 @@ attribute_value dwarf::implementation::evaluate_exprloc(std::uint32_t expression
888884
// Useful to see what the whole expression is that this routine is about to evaluate.
889885
#if ORC_FEATURE(DEBUG) && 0
890886
std::vector<char> expression(expression_size, 0);
891-
temp_seek(_s, [&]{
892-
_s.read(&expression[0], expression_size);
893-
});
887+
temp_seek(_s, [&] { _s.read(&expression[0], expression_size); });
894888
#endif // ORC_FEATURE(DEBUG)
895889

896890
// clang-format off
@@ -1108,7 +1102,7 @@ attribute_value dwarf::implementation::process_form(const attribute& attr,
11081102

11091103
attribute_value result;
11101104

1111-
const auto handle_reference = [&](std::uint64_t offset){
1105+
const auto handle_reference = [&](std::uint64_t offset) {
11121106
const auto debug_info_offset = _debug_info._offset;
11131107
const auto cu_offset = _cu_address - debug_info_offset;
11141108
// REVISIT (fosterbrereton): Possible overflow
@@ -1190,7 +1184,8 @@ attribute_value dwarf::implementation::process_form(const attribute& attr,
11901184
}
11911185
};
11921186
default: {
1193-
// We have a problem if we are passing over an attribute that is needed to determine ODRVs.
1187+
// We have a problem if we are passing over an attribute that is needed to determine
1188+
// ODRVs.
11941189
assert(nonfatal_attribute(attr._name));
11951190
result.passover();
11961191
auto size = form_length(attr._form, _s);
@@ -1302,8 +1297,9 @@ bool dwarf::implementation::register_sections_done() {
13021297
// the name of the compilation unit unless we explicitly ask for it.
13031298
//
13041299
// DWARF Spec 6.2.4 talking about `directories` (sequence of directory names):
1305-
// The first entry in the sequence is the primary source file whose file name exactly matches
1306-
// that given in the DW_AT_name attribute in the compilation unit debugging information entry.
1300+
// The first entry in the sequence is the primary source file whose file name exactly
1301+
// matches that given in the DW_AT_name attribute in the compilation unit debugging
1302+
// information entry.
13071303
_decl_files.push_back(object_file_ancestry(_ofd_index)._ancestors[0]);
13081304

13091305
// Once we've loaded all the necessary DWARF sections, now we start piecing the details
@@ -1430,10 +1426,8 @@ void dwarf::implementation::process_all_dies() {
14301426

14311427
// Useful for looking up symbols in dwarfdump output.
14321428
#if ORC_FEATURE(DEBUG) && 0
1433-
std::cerr << std::hex << "0x" << (die._debug_info_offset) << std::dec
1434-
<< ": "
1435-
<< to_string(die._tag)
1436-
<< '\n';
1429+
std::cerr << std::hex << "0x" << (die._debug_info_offset) << std::dec << ": "
1430+
<< to_string(die._tag) << '\n';
14371431
#endif // ORC_FEATURE(DEBUG) && 0
14381432

14391433
// code 0 is reserved; it's a null entry, and signifies the end of siblings.
@@ -1522,6 +1516,21 @@ die_pair dwarf::implementation::fetch_one_die(std::size_t debug_info_offset) {
15221516
ZoneScoped;
15231517

15241518
if (!_ready && !register_sections_done()) throw std::runtime_error("dwarf setup failed");
1519+
1520+
// This is a hack for https://github.com/adobe/orc/issues/72. The problem is the file
1521+
// declaration list is contained in a specific `debug_lines` entry, which is driven by the
1522+
// `stmt_list` attribute in the `compilation_unit` die that contains this die we are trying to
1523+
// fetch. (We have observed there can be more than one compilation unit declaration, and thus
1524+
// more than one `debug_lines` entry, per `debug_info`). However, the way ORC tracks die
1525+
// information today, we do not cross reference from the compilation unit die to this one, or
1526+
// give each die its own `debug_lines` offset (which would be the proper solution). The reasons
1527+
// I am avoiding the latter are 1) it adds an extra 32 bits per die, and 2) in all observed
1528+
// instances the `debug_lines` offset for user-defined symbols is 0. So, the hack here to save
1529+
// 32 bits per die is to assume a `debug_lines` offset of 0, read the file list from the
1530+
// `debug_lines` header, and assume it is the right one. If/when a real-world instance is found
1531+
// that breaks this assumption, we can fall back on the more memory-expensive option.
1532+
read_lines(0);
1533+
15251534
auto die_address = _debug_info._offset + debug_info_offset;
15261535
_s.seekg(die_address);
15271536
_cu_address = _debug_info._offset; // not sure if this is correct in all cases

0 commit comments

Comments
 (0)